gemstack-ai 1.3.0 → 1.4.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/.gemstack/state.json +6 -6
- package/CHANGELOG.md +54 -0
- package/README.md +66 -9
- package/RELEASE_NOTES.md +40 -0
- package/{gemstack-ai-1.3.0.tgz → gemstack-ai-1.4.0.tgz} +0 -0
- package/package.json +2 -2
- package/specs/009-context-capsule/context-capsule.json +4 -4
- package/specs/010-agent-swarm-visual-qa/.gemstack.json +5 -0
- package/specs/010-agent-swarm-visual-qa/closure.json +59 -0
- package/specs/010-agent-swarm-visual-qa/plan.md +759 -0
- package/specs/010-agent-swarm-visual-qa/spec.md +842 -0
- package/specs/010-agent-swarm-visual-qa/swarm.json +49 -0
- package/specs/010-agent-swarm-visual-qa/tasks.md +873 -0
- package/specs/010-agent-swarm-visual-qa/visual-qa.json +41 -0
- package/src/cli.js +8 -0
- package/src/commands/context.js +1 -1
- package/src/commands/swarm.js +111 -0
- package/src/commands/verify.js +38 -0
- package/src/commands/visual.js +82 -0
- package/src/lib/closure-context.js +9 -1
- package/src/lib/swarm.js +639 -0
- package/src/lib/visual-qa.js +499 -0
|
@@ -0,0 +1,759 @@
|
|
|
1
|
+
# Plan de Implementación: Agent Swarm & Visual QA (Upgrade E)
|
|
2
|
+
|
|
3
|
+
**Feature Branch**: `010-agent-swarm-visual-qa`
|
|
4
|
+
**Feature Directory**: `specs/010-agent-swarm-visual-qa/`
|
|
5
|
+
**Spec**: [`specs/010-agent-swarm-visual-qa/spec.md`](file:///c:/CODES/Gemstack/specs/010-agent-swarm-visual-qa/spec.md)
|
|
6
|
+
**Lifecycle Status**: `PLAN_COMPLETE`
|
|
7
|
+
**Stop Reason**: `PLAN_COMPLETE_AWAITING_REVIEW`
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## 1. Architecture Mapping & Context
|
|
12
|
+
|
|
13
|
+
Upgrade E establishes a deterministic, auditable, offline-verifiable architecture for coordinating multi-agent engineering swarms and validating visual user interface outcomes without compromising Gemstack's fundamental authority model.
|
|
14
|
+
|
|
15
|
+
It directly builds upon the cumulative guarantees of:
|
|
16
|
+
- **Upgrade A (Architecture Consistency Engine)**: Deterministic cryptographic hashing (`src/lib/hasher.js`), canonical contracts (`src/lib/contracts.js`), findings and fingerprints (`src/lib/findings.js`), and atomic state persistence (`src/lib/state.js`).
|
|
17
|
+
- **Upgrade B (Mechanical Test Matrix & Closure Evidence)**: Test matrix validation, acceptance signatures (`src/lib/test-matrix.js`), closure context resolution (`src/lib/closure-context.js`), and strict `VERIFY = VALIDATE` read-only evaluation.
|
|
18
|
+
- **Upgrade C (Cost & Provider Safety Gates)**: Provider capability evaluation (`ProviderCapabilityGate`), fail-closed billable action authorization (`BillableActionGate`), cost ledger validation (`src/lib/cost-ledger.js`), and secret pattern prohibition.
|
|
19
|
+
- **Upgrade D (Context Capsule & Compression)**: Lossless continuation context compression (`context-capsule.json`), provenance hashing, and role-based context projection.
|
|
20
|
+
|
|
21
|
+
### Architectural Flow:
|
|
22
|
+
```text
|
|
23
|
+
[spec.md / tasks.md ([P] tasks) / context-capsule.json]
|
|
24
|
+
│
|
|
25
|
+
▼
|
|
26
|
+
+----------------------------------+
|
|
27
|
+
| Swarm Orchestration Subsystem |
|
|
28
|
+
| - Partition Planner (Disjoint) |
|
|
29
|
+
| - Role & Task Ownership |
|
|
30
|
+
| - Author != Reviewer Gate |
|
|
31
|
+
| - Context Projection Engine |
|
|
32
|
+
| - Upgrade C Safety Interceptor |
|
|
33
|
+
+-----------------+----------------+
|
|
34
|
+
│
|
|
35
|
+
▼
|
|
36
|
+
[swarm.json (Manifest)]
|
|
37
|
+
│
|
|
38
|
+
▼ (Worker Evidence Submission)
|
|
39
|
+
+----------------------------------+
|
|
40
|
+
| Visual QA Subsystem |
|
|
41
|
+
| - Scenario & Viewport Matrix |
|
|
42
|
+
| - Neutral Dynamic Masking |
|
|
43
|
+
| - Offline Baseline Digest Hash |
|
|
44
|
+
| - Explicit Promotion Barrier |
|
|
45
|
+
+-----------------+----------------+
|
|
46
|
+
│
|
|
47
|
+
▼
|
|
48
|
+
[visual-qa.json (Manifest)]
|
|
49
|
+
│
|
|
50
|
+
▼
|
|
51
|
+
+----------------------------------+
|
|
52
|
+
| Read-Only Verification Engine |
|
|
53
|
+
| gemstack verify (Stages 5.3/5.4) |
|
|
54
|
+
| - Zero process spawns |
|
|
55
|
+
| - Zero live browser invocations |
|
|
56
|
+
| - Zero file mutations |
|
|
57
|
+
+----------------------------------+
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Central Authority Model & Invariants:
|
|
61
|
+
1. `SPEC / PLAN / TASKS / FROZEN CONTRACTS = SOLE AUTHORITY`.
|
|
62
|
+
2. `AGENT OUTPUT = PROPOSED WORK`.
|
|
63
|
+
3. `VISUAL EVIDENCE = EVIDENCE`.
|
|
64
|
+
4. `AUTHOR != REVIEWER` (Separation of duties is non-waivable).
|
|
65
|
+
5. `EXCLUSIVE_TASK_WRITE_OWNERSHIP` (Disjoint write-set partitions per concurrent wave; zero overlapping writes).
|
|
66
|
+
6. `VERIFY = VALIDATE` (Verification inspects manifests and evidence offline in read-only mode).
|
|
67
|
+
7. `ZERO RUNTIME DEPENDENCIES` (Node.js standard library built-ins exclusively; runtime dependency delta = 0).
|
|
68
|
+
8. `BASELINE EXPLICIT UPDATE ONLY` (Baselines are never auto-updated or healed during verification).
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## 2. Exact Repository Change Map
|
|
73
|
+
|
|
74
|
+
### NEW Production Modules:
|
|
75
|
+
- `src/lib/swarm.js`: Core swarm partition planner, write-scope validator, review independence gate, and context projection resolver.
|
|
76
|
+
- `src/lib/visual-qa.js`: Core visual QA scenario validator, deterministic viewport resolver, dynamic masking rules, and offline baseline hash comparator.
|
|
77
|
+
- `src/commands/swarm.js`: CLI command handler for `gemstack swarm [plan|validate]`.
|
|
78
|
+
- `src/commands/visual.js`: CLI command handler for `gemstack vqa [validate|promote]`.
|
|
79
|
+
|
|
80
|
+
### NEW Test Suites (20 Canonical Acceptance Tests across 5 suites):
|
|
81
|
+
- `tests/swarm-partitioning.test.js` (`TEST-SWARM-A01`, `TEST-SWARM-A02`)
|
|
82
|
+
- `tests/swarm-review.test.js` (`TEST-SWARM-B01`, `TEST-SWARM-B02`, `TEST-SWARM-C01`, `TEST-SWARM-C02`, `TEST-SWARM-D01`, `TEST-SWARM-D02`, `TEST-SWARM-E01`, `TEST-SWARM-E02`)
|
|
83
|
+
- `tests/visual-manifest.test.js` (`TEST-VISUAL-A01`, `TEST-VISUAL-A02`, `TEST-VISUAL-B01`, `TEST-VISUAL-B02`)
|
|
84
|
+
- `tests/visual-diff.test.js` (`TEST-VISUAL-C01`, `TEST-VISUAL-C02`, `TEST-VISUAL-D01`, `TEST-VISUAL-D02`)
|
|
85
|
+
- `tests/swarm-visual-purity.test.js` (`TEST-VISUAL-E01`, `TEST-VISUAL-E02`)
|
|
86
|
+
|
|
87
|
+
### MODIFIED Existing Modules:
|
|
88
|
+
- `src/cli.js`: Register `swarm` and `vqa` commands in parser and help text.
|
|
89
|
+
- `src/commands/verify.js`: Add Stage 5.3 (Swarm Manifest & Partition Audit) and Stage 5.4 (Visual QA Evidence & Baseline Audit) in pure read-only mode.
|
|
90
|
+
- `src/lib/closure-context.js`: Include `swarm.json` and `visual-qa.json` in implementation context tracking when present.
|
|
91
|
+
- `package.json`: Register the 5 new test suites into `npm test` script. Zero runtime and zero dev dependencies added.
|
|
92
|
+
|
|
93
|
+
### UNCHANGED / FROZEN Files:
|
|
94
|
+
- `src/lib/contracts.js` (Upgrade A frozen contract mechanics)
|
|
95
|
+
- `src/lib/hasher.js` (Upgrade A deterministic hasher)
|
|
96
|
+
- `src/lib/findings.js` (Upgrade A findings framework)
|
|
97
|
+
- `src/lib/cost-ledger.js` & `src/lib/provider/` (Upgrade C cost and provider safety gates)
|
|
98
|
+
- `src/lib/context-capsule.js` (Upgrade D continuation context capsule)
|
|
99
|
+
- `specs/006-architecture-consistency/` (Upgrade A)
|
|
100
|
+
- `specs/007-mechanical-test-matrix/` (Upgrade B)
|
|
101
|
+
- `specs/008-cost-provider-safety-gates/` (Upgrade C)
|
|
102
|
+
- `specs/009-context-capsule/` (Upgrade D)
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## 3. Canonical Artifact Decisions
|
|
107
|
+
|
|
108
|
+
The canonical Upgrade E artifacts are feature-scoped, living in the active feature directory:
|
|
109
|
+
- `specs/<active-spec>/swarm.json`: Swarm plan, wave partitions, task assignments, and review attestations.
|
|
110
|
+
- `specs/<active-spec>/visual-qa.json`: Visual test scenarios, viewport matrix, selector masks, and baseline hashes.
|
|
111
|
+
- `specs/<active-spec>/baselines/`: Canonical approved reference images (.png) tracked via SHA-256 hashes in `visual-qa.json`.
|
|
112
|
+
|
|
113
|
+
| Property | `swarm.json` | `visual-qa.json` |
|
|
114
|
+
| :--- | :--- | :--- |
|
|
115
|
+
| **Authority Status** | Derived coordination & evidence manifest | Derived scenario & visual evidence manifest |
|
|
116
|
+
| **Generation Method** | `gemstack swarm plan` (from `tasks.md`) | Manual declaration or `gemstack vqa init` |
|
|
117
|
+
| **Validation Method** | `gemstack swarm validate` & `gemstack verify` (5.3) | `gemstack vqa validate` & `gemstack verify` (5.4) |
|
|
118
|
+
| **Freshness Inputs** | `tasks.md` hash, `context-capsule.json` hash | Live screenshot hashes, `spec.md` acceptance IDs |
|
|
119
|
+
| **Mutation Rules** | Updated on wave transitions / review signs | Updated only on explicit promotion (`vqa promote`) |
|
|
120
|
+
| **Package Exclusion**| Excluded from npm tarball (specs dir excluded) | Excluded from npm tarball (specs dir excluded) |
|
|
121
|
+
| **Closure Relation** | Verified evidence attached to `closure.json` | Verified evidence attached to `closure.json` |
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
## 4. Swarm Core Architecture (`src/lib/swarm.js`)
|
|
126
|
+
|
|
127
|
+
`src/lib/swarm.js` is a zero-runtime-dependency pure Node.js module responsible for:
|
|
128
|
+
1. **Manifest Parsing & Validation**: Validating `swarm.json` against schema v1.0.0.
|
|
129
|
+
2. **Partition & Concurrency Planning**: Compiling `tasks.md` parallel tasks (`[P]`) into concurrent waves where write sets are strictly disjoint.
|
|
130
|
+
3. **Write-Set Guarding**: Ensuring no two concurrent tasks claim overlapping file paths.
|
|
131
|
+
4. **Separation of Duties Gate**: Asserting `author != reviewer` across all reviewed tasks.
|
|
132
|
+
5. **Context Projection**: Compiling minimal, task-scoped context projections derived from `context-capsule.json`.
|
|
133
|
+
6. **Provider Policy Linking**: Ensuring worker billable actions reference Upgrade C capability and cost gates.
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## 5. Swarm Manifest Schema (v1.0.0)
|
|
138
|
+
|
|
139
|
+
```json
|
|
140
|
+
{
|
|
141
|
+
"$schema": "https://gemstack.dev/schemas/v1/swarm.json",
|
|
142
|
+
"version": "1.0.0",
|
|
143
|
+
"feature_id": "010-agent-swarm-visual-qa",
|
|
144
|
+
"source_capsule_hash": "64-char lowercase hex SHA-256",
|
|
145
|
+
"max_workers": 4,
|
|
146
|
+
"waves": [
|
|
147
|
+
{
|
|
148
|
+
"wave_index": 1,
|
|
149
|
+
"status": "COMPLETED",
|
|
150
|
+
"tasks": [
|
|
151
|
+
{
|
|
152
|
+
"task_id": "TASK-SWARM-01",
|
|
153
|
+
"description": "Implement swarm partition validator",
|
|
154
|
+
"assigned_role": "implementer",
|
|
155
|
+
"worker_id": "worker-impl-alpha",
|
|
156
|
+
"write_set": [
|
|
157
|
+
"src/lib/swarm.js"
|
|
158
|
+
],
|
|
159
|
+
"read_set": [
|
|
160
|
+
"specs/010-agent-swarm-visual-qa/spec.md"
|
|
161
|
+
],
|
|
162
|
+
"status": "COMPLETED",
|
|
163
|
+
"review": {
|
|
164
|
+
"reviewer_role": "reviewer",
|
|
165
|
+
"reviewer_id": "worker-rev-beta",
|
|
166
|
+
"status": "APPROVED",
|
|
167
|
+
"reviewed_commit_hash": "a1b2c3d4e5f6...",
|
|
168
|
+
"review_timestamp": "2026-09-11T19:00:00Z",
|
|
169
|
+
"attestation": "All criteria verified; write-set strictly adhered to."
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
]
|
|
173
|
+
}
|
|
174
|
+
]
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
## 6. Worker Identity Model
|
|
181
|
+
|
|
182
|
+
Worker identities must be deterministic, explicit, and auditable strings:
|
|
183
|
+
- **Format**: `worker-<role>-<explicit-suffix>` (e.g., `worker-impl-alpha`, `worker-rev-beta`, `lead-engineer`).
|
|
184
|
+
- **Forbidden Identifiers**: Dynamic machine hostnames, transient process IDs, random unseeded UUIDs, or LLM model strings (`gpt-4o`, `gemini-1.5-pro`).
|
|
185
|
+
- **Uniqueness**: Each active worker within a concurrent wave must possess a distinct, stable identifier to guarantee unambiguous ownership and review auditing.
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
## 7. Mechanical Role Model
|
|
190
|
+
|
|
191
|
+
Upgrade E defines four mechanical roles with strict operational capabilities:
|
|
192
|
+
|
|
193
|
+
| Role | Permitted Write Scope | Permitted Tooling | Review Authority |
|
|
194
|
+
| :--- | :--- | :--- | :--- |
|
|
195
|
+
| **`implementer`** | Declared task `write_set` only | Code edit, local test run | Cannot review or approve tasks |
|
|
196
|
+
| **`reviewer`** | Read-only across repository | Read, diff, test execution | Can approve tasks where `author != reviewer` |
|
|
197
|
+
| **`security-auditor`** | Read-only across repository | Read, secret scan, gate check | Can approve security/provider safety gates |
|
|
198
|
+
| **`coordinator`** | `swarm.json` only | Read `tasks.md`, plan schedule | Can organize waves; cannot review code |
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
## 8. Task Ownership & Exclusive Write Boundaries
|
|
203
|
+
|
|
204
|
+
### Task Ownership:
|
|
205
|
+
- Every entry in `swarm.json` must reference a valid, existing `task_id` declared in the feature's `tasks.md`.
|
|
206
|
+
- Unknown, orphaned, or unassigned tasks fail closed with `SWARM_TASK_ORPHANED`.
|
|
207
|
+
|
|
208
|
+
### Exclusive Write Boundaries:
|
|
209
|
+
- For any concurrent wave ( W ), and any two tasks ( T_1, T_2 in W ):
|
|
210
|
+
$$\text{write\_set}(T_1) \cap \text{write\_set}(T_2) = \emptyset$$
|
|
211
|
+
- If an overlap is detected during scheduling, the planner serializes ( T_2 ) into wave ( W+1 ) and records `SWARM_WRITE_COLLISION_PREVENTED`.
|
|
212
|
+
- If an overlap occurs in an executed manifest, validation fails closed with `SWARM_WRITE_COLLISION`.
|
|
213
|
+
|
|
214
|
+
---
|
|
215
|
+
|
|
216
|
+
## 9. Write-Scope Validation
|
|
217
|
+
|
|
218
|
+
Write-scope validation is performed by comparing worker git diffs or file mutation records against declared `write_set`:
|
|
219
|
+
1. Paths in `write_set` must be POSIX-normalized relative paths.
|
|
220
|
+
2. Parent directory traversal (`../`), root escapes, and protected paths (`.git/`, `package.json`, `specs/*`) are strictly forbidden unless explicitly authorized in the task specification.
|
|
221
|
+
3. If files outside `write_set` are modified, validation fails closed with `SWARM_WRITE_SET_VIOLATION`.
|
|
222
|
+
|
|
223
|
+
---
|
|
224
|
+
|
|
225
|
+
## 10. Dependency Graph & Wave Scheduling
|
|
226
|
+
|
|
227
|
+
Swarm scheduling preserves task dependency semantics from `tasks.md`:
|
|
228
|
+
- Prerequisite tasks marked in `tasks.md` must be placed in strictly earlier waves ((\text{wave}(T_{\text{dep}}) < \text{wave}(T))).
|
|
229
|
+
- Blocked prerequisites prevent subsequent wave execution.
|
|
230
|
+
- Cycle detection executes during `gemstack swarm plan`, rejecting circular dependencies with `SWARM_DEPENDENCY_CYCLE`.
|
|
231
|
+
|
|
232
|
+
---
|
|
233
|
+
|
|
234
|
+
## 11. Context Projection & Freshness (Upgrade D Integration)
|
|
235
|
+
|
|
236
|
+
Workers receive task-scoped context projections deterministically compiled from `context-capsule.json`:
|
|
237
|
+
1. **Projection Payload**: Contains feature metadata, target task description, relevant frozen contracts, explicit write set, and acceptance IDs.
|
|
238
|
+
2. **Provenance Pinned**: Each projection embeds `source_capsule_hash`.
|
|
239
|
+
3. **Freshness Invalidation**: If the live hash of `context-capsule.json` does not match `source_capsule_hash`, the projection is marked stale and fails verification with `SWARM_CONTEXT_STALE`.
|
|
240
|
+
4. **Chat History Exclusion**: Raw prompts, chat logs, and conversation transcripts are strictly excluded from worker payloads.
|
|
241
|
+
|
|
242
|
+
---
|
|
243
|
+
|
|
244
|
+
## 12. Worker Output Evidence & Completion Proof
|
|
245
|
+
|
|
246
|
+
A task is not complete merely because an agent claims it is. Proof requires:
|
|
247
|
+
1. **Structured Completion Claim**: Worker records files modified, tests executed, and exit codes.
|
|
248
|
+
2. **Review Attestation**: An independent reviewer role verifies code and tests, recording `status: APPROVED`, reviewer ID, timestamp, and review commit hash.
|
|
249
|
+
3. **Mechanical Test Proof**: Acceptance test IDs mapped to the task pass cleanly in CI.
|
|
250
|
+
4. **Closure Reconciled**: Only tasks satisfying all three criteria can be marked `[x]` in `tasks.md` and verified by `gemstack verify`.
|
|
251
|
+
|
|
252
|
+
---
|
|
253
|
+
|
|
254
|
+
## 13. Review Independence Gate (`AUTHOR != REVIEWER`)
|
|
255
|
+
|
|
256
|
+
Separation of duties is mechanically enforced on every task review:
|
|
257
|
+
$$\text{worker\_id}(\text{implementer}) \neq \text{reviewer\_id}(\text{reviewer})$$
|
|
258
|
+
- If the reviewer ID matches the author/implementer ID, validation immediately halts fail-closed with `SWARM_SELF_REVIEW_DETECTED`.
|
|
259
|
+
- Changing roles within the same session does not bypass the gate; worker identity strings are compared directly.
|
|
260
|
+
- Reviews must be signed by an authorized `reviewer` or `security-auditor` role.
|
|
261
|
+
|
|
262
|
+
---
|
|
263
|
+
|
|
264
|
+
## 14. Reviewer & Visual QA Write Policy
|
|
265
|
+
|
|
266
|
+
- **Reviewer Write Policy**: Reviewers operate in strictly read-only mode across the codebase. A review failure must return structured correction findings to the coordinator. Reviewers are forbidden from "fixing while reviewing" to prevent unreviewed self-commits.
|
|
267
|
+
- **Visual QA Write Policy**: Visual QA workers operate in read-only mode for application code; write access is strictly limited to generated visual evidence directories (`specs/<feature>/evidence/`).
|
|
268
|
+
|
|
269
|
+
---
|
|
270
|
+
|
|
271
|
+
## 15. Attempt History & Retry Model
|
|
272
|
+
|
|
273
|
+
To prevent unbounded retries and trace debugging efforts:
|
|
274
|
+
- Failed tasks record an `attempt_count` and structured `failure_reason` in the task review block.
|
|
275
|
+
- Maximum attempts per task: 3. Exceeding 3 attempts marks the task `BLOCKED_AWAITING_HUMAN`.
|
|
276
|
+
- History is kept minimal and structured, avoiding large log dumps.
|
|
277
|
+
|
|
278
|
+
---
|
|
279
|
+
|
|
280
|
+
## 16. Worker Limits & Anti-Spawning Policy
|
|
281
|
+
|
|
282
|
+
- **Static Declaration**: Total concurrent workers is bounded by `max_workers` declared in `swarm.json` (default: 4, hard cap: 8).
|
|
283
|
+
- **Anti-Spawning Policy**: Worker agents are strictly forbidden from spawning child workers, subagents, or dynamic background jobs. Manifest validation rejects undeclared child worker claims.
|
|
284
|
+
|
|
285
|
+
---
|
|
286
|
+
|
|
287
|
+
## 17. Provider Safety & Budget Integration (Upgrade C)
|
|
288
|
+
|
|
289
|
+
- **Provider Gate Linking**: Every model invocation in a swarm workflow must reference a declared provider policy.
|
|
290
|
+
- **Billable Action Interception**: External model calls pass through `ProviderCapabilityGate` and `BillableActionGate`.
|
|
291
|
+
- **Aggregate Budget Cap**: Swarm waves declare token limits. If cumulative wave usage exceeds the allocated feature token budget, execution halts fail-closed with `SWARM_COST_LIMIT_EXCEEDED`.
|
|
292
|
+
|
|
293
|
+
---
|
|
294
|
+
|
|
295
|
+
## 18. Visual QA Core Architecture (`src/lib/visual-qa.js`)
|
|
296
|
+
|
|
297
|
+
`src/lib/visual-qa.js` is a zero-runtime-dependency pure Node.js module responsible for:
|
|
298
|
+
1. **Manifest Validation**: Parsing `visual-qa.json` against schema v1.0.0.
|
|
299
|
+
2. **Scenario & Viewport Conformance**: Validating deterministic viewport dimensions, scale factors, and color schemes.
|
|
300
|
+
3. **Dynamic Region Masking**: Applying solid neutral masks (`#808080`) over dynamic selectors (timestamps, counters, avatars) prior to diffing.
|
|
301
|
+
4. **Offline Baseline Comparison**: Verifying baseline image files against pinned SHA-256 hashes and calculating pixel/DOM diff metrics.
|
|
302
|
+
5. **Explicit Baseline Promotion Barrier**: Enforcing that baselines are never auto-updated during test runs.
|
|
303
|
+
|
|
304
|
+
---
|
|
305
|
+
|
|
306
|
+
## 19. Visual QA Manifest Schema (v1.0.0)
|
|
307
|
+
|
|
308
|
+
```json
|
|
309
|
+
{
|
|
310
|
+
"$schema": "https://gemstack.dev/schemas/v1/visual-qa.json",
|
|
311
|
+
"version": "1.0.0",
|
|
312
|
+
"feature_id": "010-agent-swarm-visual-qa",
|
|
313
|
+
"target_base_url": "http://localhost:3000",
|
|
314
|
+
"scenarios": [
|
|
315
|
+
{
|
|
316
|
+
"scenario_id": "VQA-LOGIN-001",
|
|
317
|
+
"description": "Login screen renders correctly on mobile viewport",
|
|
318
|
+
"route": "/login",
|
|
319
|
+
"acceptance_ids": [
|
|
320
|
+
"TEST-VISUAL-A01"
|
|
321
|
+
],
|
|
322
|
+
"viewport": {
|
|
323
|
+
"name": "mobile-portrait",
|
|
324
|
+
"width": 375,
|
|
325
|
+
"height": 667,
|
|
326
|
+
"device_scale_factor": 2,
|
|
327
|
+
"color_scheme": "light"
|
|
328
|
+
},
|
|
329
|
+
"selectors": {
|
|
330
|
+
"root": "#login-card",
|
|
331
|
+
"mask": [
|
|
332
|
+
".dynamic-timestamp",
|
|
333
|
+
".live-avatar"
|
|
334
|
+
]
|
|
335
|
+
},
|
|
336
|
+
"tolerances": {
|
|
337
|
+
"max_diff_percentage": 0.00,
|
|
338
|
+
"anti_aliasing_threshold": 0.1
|
|
339
|
+
},
|
|
340
|
+
"baseline": {
|
|
341
|
+
"image_path": "specs/010-agent-swarm-visual-qa/baselines/vqa-login-001-mobile.png",
|
|
342
|
+
"image_sha256": "8f4e2b...",
|
|
343
|
+
"dom_hash": "c5d6e7...",
|
|
344
|
+
"approved_by": "human-lead",
|
|
345
|
+
"approved_at": "2026-09-11T18:00:00Z"
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
]
|
|
349
|
+
}
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
---
|
|
353
|
+
|
|
354
|
+
## 20. Viewport Model & Deterministic Profiles
|
|
355
|
+
|
|
356
|
+
| Profile Name | Width (px) | Height (px) | Device Scale Factor | Intended Platform |
|
|
357
|
+
| :--- | :--- | :--- | :--- | :--- |
|
|
358
|
+
| **`desktop-standard`** | 1920 | 1080 | 1 | Full HD Desktop / CI |
|
|
359
|
+
| **`desktop-compact`** | 1280 | 800 | 1 | Compact Laptop Display |
|
|
360
|
+
| **`tablet-portrait`** | 768 | 1024 | 2 | Tablet Portrait Display |
|
|
361
|
+
| **`mobile-portrait`** | 375 | 667 | 2 | Mobile Smartphone Display |
|
|
362
|
+
|
|
363
|
+
Dimensions must be positive integers. Any omitted or invalid viewport parameter fails with `VQA_INVALID_VIEWPORT`.
|
|
364
|
+
|
|
365
|
+
---
|
|
366
|
+
|
|
367
|
+
## 21. Dynamic Region Masking & Anti-Flake Protections
|
|
368
|
+
|
|
369
|
+
1. **Deterministic Solid Masking**: Elements matching selectors declared in `selectors.mask` are covered with a neutral gray fill (`#808080`) before computing evidence digests.
|
|
370
|
+
2. **Animation & Caret Disabling**: Scenarios mandate zero CSS transitions and hidden carets during capture.
|
|
371
|
+
3. **Anti-Aliasing Tolerance**: Diffs within configurable color-distance thresholds (`anti_aliasing_threshold`) are filtered to prevent subpixel font smoothing false positives across Windows, Linux, and macOS.
|
|
372
|
+
4. **Credential Auto-Masking**: Password inputs (`input[type="password"]`) and `data-sensitive="true"` elements are automatically masked fail-closed.
|
|
373
|
+
|
|
374
|
+
---
|
|
375
|
+
|
|
376
|
+
## 22. Baseline Lifecycle Management (`baseline-explicit-update-only`)
|
|
377
|
+
|
|
378
|
+
- **Strict Immutability**: Verification and test execution NEVER overwrite baseline images.
|
|
379
|
+
- **Explicit Promotion Command**: A baseline can only be updated or initialized via the explicit CLI command:
|
|
380
|
+
`gemstack vqa promote <scenario-id>`
|
|
381
|
+
- **Tampering Detection**: If a baseline image on disk deviates from the recorded `image_sha256` in `visual-qa.json`, verification halts fail-closed with `VQA_BASELINE_TAMPERED`.
|
|
382
|
+
|
|
383
|
+
---
|
|
384
|
+
|
|
385
|
+
## 23. Visual Diffing & Failure Classification
|
|
386
|
+
|
|
387
|
+
Results are classified deterministically:
|
|
388
|
+
- **`PASS`**: Live screenshot SHA-256 matches baseline `image_sha256` 100%, or non-masked pixel diff is within `max_diff_percentage`.
|
|
389
|
+
- **`VISUAL_REGRESSION`**: Unmasked pixels differ beyond threshold.
|
|
390
|
+
- **`BASELINE_MISSING`**: Declared scenario lacks an approved baseline image.
|
|
391
|
+
- **`BASELINE_TAMPERED`**: Baseline image hash on disk differs from recorded manifest hash.
|
|
392
|
+
- **`EVIDENCE_MISSING`**: No live evidence submitted for declared scenario.
|
|
393
|
+
- **`MASK_FAILURE`**: Mandatory sensitive selector failed to resolve in DOM.
|
|
394
|
+
|
|
395
|
+
---
|
|
396
|
+
|
|
397
|
+
## 24. External Capture Adapter Contract
|
|
398
|
+
|
|
399
|
+
Because browser capture is decoupled from Gemstack core, external runners (Playwright scripts, Puppeteer adapters, or MCP tools) interface via a clean JSON evidence contract:
|
|
400
|
+
- **Input Contract**: External runner reads `visual-qa.json` scenario definitions.
|
|
401
|
+
- **Output Contract**: External runner writes screenshot PNG and DOM snapshot to `specs/<feature>/evidence/<scenario-id>.png` and records execution metadata.
|
|
402
|
+
- **Core Role**: Core Gemstack inspects, hashes, masks, diffs, and validates the evidence offline. Core never spawns browser processes.
|
|
403
|
+
|
|
404
|
+
---
|
|
405
|
+
|
|
406
|
+
## 25. CLI & Developer Ergonomics (`src/commands/swarm.js` & `src/commands/visual.js`)
|
|
407
|
+
|
|
408
|
+
```text
|
|
409
|
+
gemstack swarm plan [--json] Compile tasks.md [P] tasks into deterministic swarm.json waves
|
|
410
|
+
gemstack swarm validate [--json] Validate write-set partitions and review attestations
|
|
411
|
+
gemstack vqa validate [--json] Validate visual-qa.json schema, baselines, and evidence offline
|
|
412
|
+
gemstack vqa promote <scenario-id> Promote live evidence to approved canonical baseline
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
Both commands support `--json` for CI consumption and run strictly read-only validation operations (except `promote`, which is explicitly mutating).
|
|
416
|
+
|
|
417
|
+
---
|
|
418
|
+
|
|
419
|
+
## 26. Verification Engine Integration (`gemstack verify`)
|
|
420
|
+
|
|
421
|
+
`gemstack verify` adds two read-only audit stages:
|
|
422
|
+
|
|
423
|
+
### Stage 5.3: Swarm Coordination Audit (Read-Only)
|
|
424
|
+
- Validates `swarm.json` schema and task wave partitions.
|
|
425
|
+
- Verifies all concurrent tasks have mutually disjoint write sets.
|
|
426
|
+
- Enforces `author != reviewer` across all approved reviews.
|
|
427
|
+
- Checks context projection freshness against active `context-capsule.json`.
|
|
428
|
+
- Operates in legacy mode if `swarm.json` is absent (exit 0).
|
|
429
|
+
|
|
430
|
+
### Stage 5.4: Visual QA Evidence Audit (Read-Only)
|
|
431
|
+
- Validates `visual-qa.json` schema and scenario viewport definitions.
|
|
432
|
+
- Verifies all baseline images exist and match recorded SHA-256 hashes.
|
|
433
|
+
- Inspects submitted evidence completeness for required scenarios.
|
|
434
|
+
- Ensures zero file mutations and zero browser launches occur during verify.
|
|
435
|
+
- Operates in legacy mode if `visual-qa.json` is absent (exit 0).
|
|
436
|
+
|
|
437
|
+
---
|
|
438
|
+
|
|
439
|
+
## 27. Closure Integration (`gemstack ship`)
|
|
440
|
+
|
|
441
|
+
- Swarm and Visual QA evidence link directly into Upgrade B closure machinery via `closure.json`.
|
|
442
|
+
- `gemstack ship` verifies that:
|
|
443
|
+
- All swarm tasks in active waves are `COMPLETED` and independently `APPROVED`.
|
|
444
|
+
- All visual QA scenarios have passing evidence matching baselines.
|
|
445
|
+
- Zero unreviewed changes, write collisions, or visual regressions remain.
|
|
446
|
+
- Swarm and Visual QA artifacts remain strictly evidence; they do not alter closure invariants or supersede specifications.
|
|
447
|
+
|
|
448
|
+
---
|
|
449
|
+
|
|
450
|
+
## 28. Legacy & Multi-Mode Compatibility
|
|
451
|
+
|
|
452
|
+
- **Legacy Mode**: Repositories or features without `swarm.json` and `visual-qa.json` run cleanly with informational notices and exit code 0.
|
|
453
|
+
- **Backend / Headless Mode**: Projects with no UI components declare no visual scenarios; visual audit is cleanly skipped.
|
|
454
|
+
- **Single-Agent Mode**: Tasks executed sequentially without parallel swarms omit `swarm.json` without penalty.
|
|
455
|
+
|
|
456
|
+
---
|
|
457
|
+
|
|
458
|
+
## 29. Bootstrap Contracts Mapping (10 / 10 Mapped)
|
|
459
|
+
|
|
460
|
+
| Contract ID | Implementation Surface | Validator Function | Emitted Finding | Acceptance Test |
|
|
461
|
+
| :--- | :--- | :--- | :--- | :--- |
|
|
462
|
+
| **`swarm-authority-subordinate`** | `src/lib/swarm.js` | `validateSwarmAuthority()` | `SWARM_AUTHORITY_CONFLICT` | `TEST-SWARM-A01` |
|
|
463
|
+
| **`author-not-reviewer`** | `src/lib/swarm.js` | `validateReviewSeparation()` | `SWARM_SELF_REVIEW_DETECTED`| `TEST-SWARM-B01` |
|
|
464
|
+
| **`exclusive-task-write-ownership`**| `src/lib/swarm.js` | `validateWritePartitions()` | `SWARM_WRITE_COLLISION` | `TEST-SWARM-A02` |
|
|
465
|
+
| **`swarm-provider-safety-gated`** | `src/lib/swarm.js` | `validateProviderSafety()` | `SWARM_PROVIDER_UNAUTHORIZED`| `TEST-SWARM-C01` |
|
|
466
|
+
| **`swarm-context-projected`** | `src/lib/swarm.js` | `validateContextProjection()`| `SWARM_CONTEXT_STALE` | `TEST-SWARM-D01` |
|
|
467
|
+
| **`visual-evidence-subordinate`** | `src/lib/visual-qa.js` | `validateEvidenceSubordination()`| `VQA_AUTHORITY_CONFLICT` | `TEST-VISUAL-A01` |
|
|
468
|
+
| **`deterministic-viewports`** | `src/lib/visual-qa.js` | `validateViewports()` | `VQA_INVALID_VIEWPORT` | `TEST-VISUAL-A02` |
|
|
469
|
+
| **`baseline-explicit-update-only`**| `src/lib/visual-qa.js` | `validateBaselineImmutability()`| `VQA_BASELINE_TAMPERED` | `TEST-VISUAL-B01` |
|
|
470
|
+
| **`verify-swarm-visual-offline`** | `src/commands/verify.js`| `verify()` (Stages 5.3/5.4) | `VERIFY_NETWORK_DETECTED` | `TEST-SWARM-E01` / `TEST-VISUAL-E01` |
|
|
471
|
+
| **`legacy-swarm-visual-compatibility`**| `src/commands/verify.js`| `verify()` legacy fallback | None (passes exit 0) | `TEST-SWARM-E02` / `TEST-VISUAL-E02` |
|
|
472
|
+
|
|
473
|
+
---
|
|
474
|
+
|
|
475
|
+
## 30. Canonical Acceptance Matrix Mapping (20 / 20 Mapped)
|
|
476
|
+
|
|
477
|
+
| Acceptance ID | Category | Implementation Surface | Test File | Mechanical Proof |
|
|
478
|
+
| :--- | :--- | :--- | :--- | :--- |
|
|
479
|
+
| **`TEST-SWARM-A01`** | Partitioning | `src/lib/swarm.js` | `tests/swarm-partitioning.test.js` | Disjoint write sets schedule into same concurrent wave |
|
|
480
|
+
| **`TEST-SWARM-A02`** | Partitioning | `src/lib/swarm.js` | `tests/swarm-partitioning.test.js` | Overlapping write sets serialize into sequential waves |
|
|
481
|
+
| **`TEST-SWARM-B01`** | Separation of Duties | `src/lib/swarm.js` | `tests/swarm-review.test.js` | `author == reviewer` fails closed with self-review error |
|
|
482
|
+
| **`TEST-SWARM-B02`** | Separation of Duties | `src/lib/swarm.js` | `tests/swarm-review.test.js` | Distinct reviewer role validates review attestation |
|
|
483
|
+
| **`TEST-SWARM-C01`** | Gate Integration | `src/lib/swarm.js` | `tests/swarm-review.test.js` | Intercepts undeclared provider call via ProviderCapabilityGate |
|
|
484
|
+
| **`TEST-SWARM-C02`** | Gate Integration | `src/lib/swarm.js` | `tests/swarm-review.test.js` | Cumulative wave token usage halts on budget breach |
|
|
485
|
+
| **`TEST-SWARM-D01`** | Context Projection | `src/lib/swarm.js` | `tests/swarm-review.test.js` | Projection hash matches active context-capsule digest |
|
|
486
|
+
| **`TEST-SWARM-D02`** | Context Projection | `src/lib/swarm.js` | `tests/swarm-review.test.js` | Ingestion of raw chat transcripts is rejected |
|
|
487
|
+
| **`TEST-SWARM-E01`** | Verify Purity | `src/commands/verify.js`| `tests/swarm-visual-purity.test.js`| `verify` runs with 0 file mutations and 0 process spawns |
|
|
488
|
+
| **`TEST-SWARM-E02`** | Legacy Compatibility | `src/commands/verify.js`| `tests/swarm-visual-purity.test.js`| Absent `swarm.json` exits 0 in legacy mode |
|
|
489
|
+
| **`TEST-VISUAL-A01`** | Visual Manifest | `src/lib/visual-qa.js` | `tests/visual-manifest.test.js` | Rejects manifest missing route, viewport, or baseline |
|
|
490
|
+
| **`TEST-VISUAL-A02`** | Visual Manifest | `src/lib/visual-qa.js` | `tests/visual-manifest.test.js` | Rejects invalid or negative viewport dimensions |
|
|
491
|
+
| **`TEST-VISUAL-B01`** | Baseline Safety | `src/lib/visual-qa.js` | `tests/visual-manifest.test.js` | Modified baseline image on disk triggers tampered error |
|
|
492
|
+
| **`TEST-VISUAL-B02`** | Baseline Safety | `src/lib/visual-qa.js` | `tests/visual-manifest.test.js` | Baseline file hashes remain unchanged after test run |
|
|
493
|
+
| **`TEST-VISUAL-C01`** | Regression Detection | `src/lib/visual-qa.js` | `tests/visual-diff.test.js` | Screenshot deviating beyond threshold triggers regression |
|
|
494
|
+
| **`TEST-VISUAL-C02`** | Regression Detection | `src/lib/visual-qa.js` | `tests/visual-diff.test.js` | Matching SHA-256 image hashes pass immediately |
|
|
495
|
+
| **`TEST-VISUAL-D01`** | Masking Protection | `src/lib/visual-qa.js` | `tests/visual-diff.test.js` | Dynamic text variation in masked selector does not fail |
|
|
496
|
+
| **`TEST-VISUAL-D02`** | Masking Protection | `src/lib/visual-qa.js` | `tests/visual-diff.test.js` | Password input fields are masked automatically |
|
|
497
|
+
| **`TEST-VISUAL-E01`** | Verify Purity | `src/commands/verify.js`| `tests/swarm-visual-purity.test.js`| Verification passes offline with mocked network/process |
|
|
498
|
+
| **`TEST-VISUAL-E02`** | Legacy Compatibility | `src/commands/verify.js`| `tests/swarm-visual-purity.test.js`| Absent `visual-qa.json` exits 0 in legacy mode |
|
|
499
|
+
|
|
500
|
+
### Mechanical Test Bindings (`gemstack-test-bindings`)
|
|
501
|
+
|
|
502
|
+
```gemstack-test-bindings
|
|
503
|
+
[
|
|
504
|
+
{
|
|
505
|
+
"test_id": "TEST-SWARM-A01",
|
|
506
|
+
"runner": "node:test",
|
|
507
|
+
"file": "tests/swarm-partitioning.test.js"
|
|
508
|
+
},
|
|
509
|
+
{
|
|
510
|
+
"test_id": "TEST-SWARM-A02",
|
|
511
|
+
"runner": "node:test",
|
|
512
|
+
"file": "tests/swarm-partitioning.test.js"
|
|
513
|
+
},
|
|
514
|
+
{
|
|
515
|
+
"test_id": "TEST-SWARM-B01",
|
|
516
|
+
"runner": "node:test",
|
|
517
|
+
"file": "tests/swarm-review.test.js"
|
|
518
|
+
},
|
|
519
|
+
{
|
|
520
|
+
"test_id": "TEST-SWARM-B02",
|
|
521
|
+
"runner": "node:test",
|
|
522
|
+
"file": "tests/swarm-review.test.js"
|
|
523
|
+
},
|
|
524
|
+
{
|
|
525
|
+
"test_id": "TEST-SWARM-C01",
|
|
526
|
+
"runner": "node:test",
|
|
527
|
+
"file": "tests/swarm-review.test.js"
|
|
528
|
+
},
|
|
529
|
+
{
|
|
530
|
+
"test_id": "TEST-SWARM-C02",
|
|
531
|
+
"runner": "node:test",
|
|
532
|
+
"file": "tests/swarm-review.test.js"
|
|
533
|
+
},
|
|
534
|
+
{
|
|
535
|
+
"test_id": "TEST-SWARM-D01",
|
|
536
|
+
"runner": "node:test",
|
|
537
|
+
"file": "tests/swarm-review.test.js"
|
|
538
|
+
},
|
|
539
|
+
{
|
|
540
|
+
"test_id": "TEST-SWARM-D02",
|
|
541
|
+
"runner": "node:test",
|
|
542
|
+
"file": "tests/swarm-review.test.js"
|
|
543
|
+
},
|
|
544
|
+
{
|
|
545
|
+
"test_id": "TEST-SWARM-E01",
|
|
546
|
+
"runner": "node:test",
|
|
547
|
+
"file": "tests/swarm-visual-purity.test.js"
|
|
548
|
+
},
|
|
549
|
+
{
|
|
550
|
+
"test_id": "TEST-SWARM-E02",
|
|
551
|
+
"runner": "node:test",
|
|
552
|
+
"file": "tests/swarm-visual-purity.test.js"
|
|
553
|
+
},
|
|
554
|
+
{
|
|
555
|
+
"test_id": "TEST-VISUAL-A01",
|
|
556
|
+
"runner": "node:test",
|
|
557
|
+
"file": "tests/visual-manifest.test.js"
|
|
558
|
+
},
|
|
559
|
+
{
|
|
560
|
+
"test_id": "TEST-VISUAL-A02",
|
|
561
|
+
"runner": "node:test",
|
|
562
|
+
"file": "tests/visual-manifest.test.js"
|
|
563
|
+
},
|
|
564
|
+
{
|
|
565
|
+
"test_id": "TEST-VISUAL-B01",
|
|
566
|
+
"runner": "node:test",
|
|
567
|
+
"file": "tests/visual-manifest.test.js"
|
|
568
|
+
},
|
|
569
|
+
{
|
|
570
|
+
"test_id": "TEST-VISUAL-B02",
|
|
571
|
+
"runner": "node:test",
|
|
572
|
+
"file": "tests/visual-manifest.test.js"
|
|
573
|
+
},
|
|
574
|
+
{
|
|
575
|
+
"test_id": "TEST-VISUAL-C01",
|
|
576
|
+
"runner": "node:test",
|
|
577
|
+
"file": "tests/visual-diff.test.js"
|
|
578
|
+
},
|
|
579
|
+
{
|
|
580
|
+
"test_id": "TEST-VISUAL-C02",
|
|
581
|
+
"runner": "node:test",
|
|
582
|
+
"file": "tests/visual-diff.test.js"
|
|
583
|
+
},
|
|
584
|
+
{
|
|
585
|
+
"test_id": "TEST-VISUAL-D01",
|
|
586
|
+
"runner": "node:test",
|
|
587
|
+
"file": "tests/visual-diff.test.js"
|
|
588
|
+
},
|
|
589
|
+
{
|
|
590
|
+
"test_id": "TEST-VISUAL-D02",
|
|
591
|
+
"runner": "node:test",
|
|
592
|
+
"file": "tests/visual-diff.test.js"
|
|
593
|
+
},
|
|
594
|
+
{
|
|
595
|
+
"test_id": "TEST-VISUAL-E01",
|
|
596
|
+
"runner": "node:test",
|
|
597
|
+
"file": "tests/swarm-visual-purity.test.js"
|
|
598
|
+
},
|
|
599
|
+
{
|
|
600
|
+
"test_id": "TEST-VISUAL-E02",
|
|
601
|
+
"runner": "node:test",
|
|
602
|
+
"file": "tests/swarm-visual-purity.test.js"
|
|
603
|
+
}
|
|
604
|
+
]
|
|
605
|
+
```
|
|
606
|
+
|
|
607
|
+
### Project Closure Gates (`gemstack-closure-gates`)
|
|
608
|
+
|
|
609
|
+
```gemstack-closure-gates
|
|
610
|
+
[
|
|
611
|
+
{
|
|
612
|
+
"id": "project-tests",
|
|
613
|
+
"type": "PACKAGE_SCRIPT",
|
|
614
|
+
"script": "test",
|
|
615
|
+
"requirement": "REQUIRED",
|
|
616
|
+
"waivable": false
|
|
617
|
+
},
|
|
618
|
+
{
|
|
619
|
+
"id": "gate-ci-frontmatter",
|
|
620
|
+
"type": "PACKAGE_SCRIPT",
|
|
621
|
+
"script": "ci:frontmatter",
|
|
622
|
+
"requirement": "REQUIRED",
|
|
623
|
+
"waivable": false
|
|
624
|
+
},
|
|
625
|
+
{
|
|
626
|
+
"id": "gate-ci-mojibake",
|
|
627
|
+
"type": "PACKAGE_SCRIPT",
|
|
628
|
+
"script": "ci:mojibake",
|
|
629
|
+
"requirement": "REQUIRED",
|
|
630
|
+
"waivable": false
|
|
631
|
+
}
|
|
632
|
+
]
|
|
633
|
+
```
|
|
634
|
+
|
|
635
|
+
---
|
|
636
|
+
|
|
637
|
+
## 31. Comprehensive Threat Model Mapping
|
|
638
|
+
|
|
639
|
+
| Threat Vector | Preventive Validation Surface | Emitted Finding | Mechanical Test |
|
|
640
|
+
| :--- | :--- | :--- | :--- |
|
|
641
|
+
| **1. Write Collision** | `validateWritePartitions()` | `SWARM_WRITE_COLLISION` | `TEST-SWARM-A02` |
|
|
642
|
+
| **2. Self-Review Bypass** | `validateReviewSeparation()` | `SWARM_SELF_REVIEW_DETECTED` | `TEST-SWARM-B01` |
|
|
643
|
+
| **3. Token Runaway** | `validateProviderSafety()` | `SWARM_COST_LIMIT_EXCEEDED` | `TEST-SWARM-C02` |
|
|
644
|
+
| **4. Context Drift / Stale Projection** | `validateContextProjection()` | `SWARM_CONTEXT_STALE` | `TEST-SWARM-D01` |
|
|
645
|
+
| **5. Subagent Recursive Spawning** | `validateWorkerLimits()` | `SWARM_RECURSIVE_SPAWN_DENIED`| `TEST-SWARM-A01` |
|
|
646
|
+
| **6. Silent Baseline Overwrite** | `validateBaselineImmutability()`| `VQA_BASELINE_TAMPERED` | `TEST-VISUAL-B02` |
|
|
647
|
+
| **7. Flaky Subpixel Font Diffs** | `anti_aliasing_threshold` & masks| `VQA_VISUAL_REGRESSION` | `TEST-VISUAL-D01` |
|
|
648
|
+
| **8. Credential Leak in Screenshot**| Auto-masking password fields | `VQA_MASK_FAILURE` | `TEST-VISUAL-D02` |
|
|
649
|
+
| **9. Verify Browser Hang in CI** | Read-only offline manifest check | `VERIFY_NETWORK_DETECTED` | `TEST-VISUAL-E01` |
|
|
650
|
+
| **10. Spec Overwrite by Visual QA**| Authority hierarchy check | `VQA_AUTHORITY_CONFLICT` | `TEST-VISUAL-A01` |
|
|
651
|
+
|
|
652
|
+
---
|
|
653
|
+
|
|
654
|
+
## 32. Implementation Phases
|
|
655
|
+
|
|
656
|
+
```text
|
|
657
|
+
================================================================================
|
|
658
|
+
UPGRADE E IMPLEMENTATION PHASES
|
|
659
|
+
================================================================================
|
|
660
|
+
|
|
661
|
+
Phase 1 — Swarm Core Contracts & Partition Planner
|
|
662
|
+
- Implement src/lib/swarm.js (parsing, wave scheduling, disjoint write sets).
|
|
663
|
+
- Register bootstrap contracts and findings.
|
|
664
|
+
- Tests: tests/swarm-partitioning.test.js (TEST-SWARM-A01, TEST-SWARM-A02).
|
|
665
|
+
|
|
666
|
+
Phase 2 — Review Independence, Safety Gates & Context Projection
|
|
667
|
+
- Implement author != reviewer gate, Upgrade C interceptor, and Upgrade D projection.
|
|
668
|
+
- Tests: tests/swarm-review.test.js (TEST-SWARM-B01..B02, C01..C02, D01..D02, E01..E02).
|
|
669
|
+
|
|
670
|
+
Phase 3 — Visual QA Manifest, Viewports & Baseline Safety
|
|
671
|
+
- Implement src/lib/visual-qa.js (schema validation, viewport profiles, baseline SHA-256).
|
|
672
|
+
- Tests: tests/visual-manifest.test.js (TEST-VISUAL-A01..A02, B01..B02).
|
|
673
|
+
|
|
674
|
+
Phase 4 — Visual Regression Detection, Masking & CLI Ergonomics
|
|
675
|
+
- Implement diff engine, neutral selector masking, password auto-masking.
|
|
676
|
+
- Implement src/commands/swarm.js and src/commands/visual.js; register in src/cli.js.
|
|
677
|
+
- Tests: tests/visual-diff.test.js (TEST-VISUAL-C01..C02, D01..D02).
|
|
678
|
+
|
|
679
|
+
Phase 5 — Verify Purity Integration, Closure Machinery & Hardening
|
|
680
|
+
- Integrate Stage 5.3 and 5.4 in src/commands/verify.js.
|
|
681
|
+
- Update src/lib/closure-context.js.
|
|
682
|
+
- Register 5 test suites in package.json test script.
|
|
683
|
+
- Tests: tests/swarm-visual-purity.test.js (TEST-VISUAL-E01, TEST-VISUAL-E02).
|
|
684
|
+
- Full suite run (npm test, ci:all).
|
|
685
|
+
|
|
686
|
+
================================================================================
|
|
687
|
+
```
|
|
688
|
+
|
|
689
|
+
---
|
|
690
|
+
|
|
691
|
+
## 33. Dependency Graph
|
|
692
|
+
|
|
693
|
+
```text
|
|
694
|
+
Schema Definitions & Canonical Types
|
|
695
|
+
│
|
|
696
|
+
▼
|
|
697
|
+
Swarm Partition & Write-Set Planner (src/lib/swarm.js)
|
|
698
|
+
│
|
|
699
|
+
▼
|
|
700
|
+
Review Independence & Context Projection Engine
|
|
701
|
+
│
|
|
702
|
+
▼
|
|
703
|
+
Visual QA Manifest & Viewport Matrix (src/lib/visual-qa.js)
|
|
704
|
+
│
|
|
705
|
+
▼
|
|
706
|
+
Offline Baseline Hasher & Neutral Masking Comparator
|
|
707
|
+
│
|
|
708
|
+
▼
|
|
709
|
+
CLI Command Handlers (src/commands/swarm.js, src/commands/visual.js)
|
|
710
|
+
│
|
|
711
|
+
┌────────┴────────┐
|
|
712
|
+
▼ ▼
|
|
713
|
+
CLI Registration Verify Engine Integration (Stages 5.3/5.4)
|
|
714
|
+
(src/cli.js) (src/commands/verify.js)
|
|
715
|
+
│ │
|
|
716
|
+
└────────┬────────┘
|
|
717
|
+
▼
|
|
718
|
+
Canonical Acceptance Test Suites (20 Tests / 5 Files)
|
|
719
|
+
│
|
|
720
|
+
▼
|
|
721
|
+
Closure Evidence Integration & Final CI Validation
|
|
722
|
+
```
|
|
723
|
+
|
|
724
|
+
---
|
|
725
|
+
|
|
726
|
+
## 34. Risk Register
|
|
727
|
+
|
|
728
|
+
| Risk | Impact | Mitigation Strategy | Mechanical Proof |
|
|
729
|
+
| :--- | :--- | :--- | :--- |
|
|
730
|
+
| **Authority Inversion** | Agent outputs overwrite spec | Invariant 1: Spec is supreme; verify rejects unbacked changes | `TEST-SWARM-A01` |
|
|
731
|
+
| **Write Collision** | Lost work / corrupted files | Disjoint write set validation per wave fail-closed | `TEST-SWARM-A02` |
|
|
732
|
+
| **Self-Review Bypass** | Flawed code merged uninspected| Non-waivable `author != reviewer` identity comparison | `TEST-SWARM-B01` |
|
|
733
|
+
| **Token Runaway** | Financial waste | Interception by Upgrade C BillableActionGate | `TEST-SWARM-C02` |
|
|
734
|
+
| **Stale Context** | Invariant amnesia | Pinned capsule SHA-256 hash comparison against disk | `TEST-SWARM-D01` |
|
|
735
|
+
| **Silent Baseline Mutate**| Regressions masked as passes | `gemstack verify` runs pure read-only; image hashes pinned | `TEST-VISUAL-B02` |
|
|
736
|
+
| **Secret Leak in Capture**| Credentials committed | Mandatory automatic masking on password/auth fields | `TEST-VISUAL-D02` |
|
|
737
|
+
| **CI Browser Hang** | Blocked pipelines | Verify evaluates manifests/evidence offline without browsers | `TEST-VISUAL-E01` |
|
|
738
|
+
| **Legacy Breakage** | Existing projects fail | Missing manifests trigger graceful legacy mode (exit 0) | `TEST-SWARM-E02` / `TEST-VISUAL-E02` |
|
|
739
|
+
|
|
740
|
+
---
|
|
741
|
+
|
|
742
|
+
## 35. Frozen Contract Review
|
|
743
|
+
|
|
744
|
+
- **Upgrade A Contracts**: Zero conflicts. Reuses `hasher.js`, `contracts.js`, and `findings.js` without altering interfaces.
|
|
745
|
+
- **Upgrade B Semantics**: Zero conflicts. `VERIFY = VALIDATE` preserved; `closure.json` evidence collection remains intact.
|
|
746
|
+
- **Upgrade C Safety**: Zero conflicts. `ProviderCapabilityGate` and `BillableActionGate` are integrated and respected.
|
|
747
|
+
- **Upgrade D Context**: Zero conflicts. Swarm context derives strictly from `context-capsule.json` without re-implementation.
|
|
748
|
+
- **Frozen Contracts Affected**: **`NONE`**.
|
|
749
|
+
|
|
750
|
+
---
|
|
751
|
+
|
|
752
|
+
## 36. Explicit Deferred Items
|
|
753
|
+
|
|
754
|
+
The following items are explicitly deferred from Upgrade E:
|
|
755
|
+
1. **Live Multi-Process Supervisor / Agent Daemon**: Background process clusters or socket servers (non-goal).
|
|
756
|
+
2. **Bundled Headless Browser Binaries**: Heavy Chromium/Playwright binaries inside npm package dependencies (non-goal).
|
|
757
|
+
3. **Fuzzy AI Aesthetic Grading**: Subjective LLM opinions on UI aesthetics or beauty (non-goal).
|
|
758
|
+
4. **Distributed Swarm Consensus**: Multi-node network consensus protocols (out of scope).
|
|
759
|
+
5. **Package Version Bump / Release**: Version bumping and npm publishing (strictly deferred to release phase).
|