gemstack-ai 1.2.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.
Files changed (37) hide show
  1. package/.gemstack/state.json +11 -10
  2. package/CHANGELOG.md +97 -0
  3. package/README.md +89 -9
  4. package/RELEASE_NOTES.md +77 -0
  5. package/{gemstack-ai-1.2.0.tgz → gemstack-ai-1.4.0.tgz} +0 -0
  6. package/handoff.md +14 -12
  7. package/package.json +2 -2
  8. package/specs/008-cost-provider-safety-gates/.gemstack.json +5 -0
  9. package/specs/008-cost-provider-safety-gates/closure.json +59 -0
  10. package/specs/008-cost-provider-safety-gates/plan.md +456 -0
  11. package/specs/008-cost-provider-safety-gates/spec.md +633 -0
  12. package/specs/008-cost-provider-safety-gates/tasks.md +635 -0
  13. package/specs/009-context-capsule/closure.json +59 -0
  14. package/specs/009-context-capsule/context-capsule.json +428 -0
  15. package/specs/009-context-capsule/plan.md +663 -0
  16. package/specs/009-context-capsule/spec.md +913 -0
  17. package/specs/009-context-capsule/tasks.md +720 -0
  18. package/specs/010-agent-swarm-visual-qa/.gemstack.json +5 -0
  19. package/specs/010-agent-swarm-visual-qa/closure.json +59 -0
  20. package/specs/010-agent-swarm-visual-qa/plan.md +759 -0
  21. package/specs/010-agent-swarm-visual-qa/spec.md +842 -0
  22. package/specs/010-agent-swarm-visual-qa/swarm.json +49 -0
  23. package/specs/010-agent-swarm-visual-qa/tasks.md +873 -0
  24. package/specs/010-agent-swarm-visual-qa/visual-qa.json +41 -0
  25. package/src/cli.js +10 -0
  26. package/src/commands/context.js +95 -0
  27. package/src/commands/swarm.js +111 -0
  28. package/src/commands/verify.js +92 -0
  29. package/src/commands/visual.js +82 -0
  30. package/src/lib/closure-context.js +18 -1
  31. package/src/lib/context-capsule.js +594 -0
  32. package/src/lib/cost-ledger.js +355 -0
  33. package/src/lib/provider-boundary.js +186 -0
  34. package/src/lib/provider-registry.js +265 -0
  35. package/src/lib/safety-gates.js +277 -0
  36. package/src/lib/swarm.js +639 -0
  37. package/src/lib/visual-qa.js +499 -0
@@ -0,0 +1,720 @@
1
+ # Tareas de Implementación: Context Capsule / Context Compression (Upgrade D)
2
+
3
+ **Feature Branch**: `009-context-capsule`
4
+ **Feature Directory**: `specs/009-context-capsule/`
5
+ **Spec**: [`specs/009-context-capsule/spec.md`](file:///c:/CODES/Gemstack/specs/009-context-capsule/spec.md)
6
+ **Plan**: [`specs/009-context-capsule/plan.md`](file:///c:/CODES/Gemstack/specs/009-context-capsule/plan.md)
7
+ **Lifecycle Status**: `TASKS_COMPLETE`
8
+ **Stop Reason**: `TASKS_COMPLETE_AWAITING_REVIEW`
9
+
10
+ ---
11
+
12
+ ## Contratos Congelados Heredados & Bootstrap (`gemstack-contracts`)
13
+
14
+ ```gemstack-contracts
15
+ [
16
+ {
17
+ "id": "zero-dependency-core",
18
+ "type": "BOOLEAN_INVARIANT",
19
+ "value": true,
20
+ "description": "Upgrade D implementation must introduce zero external production npm dependencies, using Node.js built-ins exclusively."
21
+ },
22
+ {
23
+ "id": "capsule-is-derived-not-authority",
24
+ "type": "BOOLEAN_INVARIANT",
25
+ "value": true,
26
+ "description": "The context capsule is strictly a derived projection; authoritative artifacts always override capsule content in case of divergence."
27
+ },
28
+ {
29
+ "id": "compression-preserves-semantic-constraints",
30
+ "type": "BOOLEAN_INVARIANT",
31
+ "value": true,
32
+ "description": "Context compression must never drop, weaken, or generalize normative MUST/MUST NOT behavioral constraints or frozen contracts."
33
+ },
34
+ {
35
+ "id": "verify-never-regenerates-capsule",
36
+ "type": "BOOLEAN_INVARIANT",
37
+ "value": true,
38
+ "description": "gemstack verify must operate in read-only mode, validating capsule freshness without silently regenerating or mutating files on disk."
39
+ },
40
+ {
41
+ "id": "capsule-secrets-forbidden",
42
+ "type": "BOOLEAN_INVARIANT",
43
+ "value": true,
44
+ "description": "Context capsules must never contain credential tokens, private keys, API secrets, or ambient environment variable values."
45
+ },
46
+ {
47
+ "id": "capsule-offline-deterministic",
48
+ "type": "BOOLEAN_INVARIANT",
49
+ "value": true,
50
+ "description": "Canonical context capsule generation and validation must execute completely offline with deterministic output given identical inputs."
51
+ },
52
+ {
53
+ "id": "capsule-size-budget-fail-closed",
54
+ "type": "BOOLEAN_INVARIANT",
55
+ "value": true,
56
+ "description": "Exceeding the maximum capsule byte budget must fail closed with an explicit finding rather than silently dropping constraints."
57
+ },
58
+ {
59
+ "id": "legacy-capsule-compatibility",
60
+ "type": "BOOLEAN_INVARIANT",
61
+ "value": true,
62
+ "description": "Existing repositories and features lacking context capsules operate cleanly with informational notices and zero false blockers."
63
+ }
64
+ ]
65
+ ```
66
+
67
+ ---
68
+
69
+ ## Task Execution Rules & Safety Invariants
70
+
71
+ 1. **Central Invariant**: `CONTEXT CAPSULE = DERIVED CONTINUATION CONTEXT, NOT CANONICAL PROJECT AUTHORITY`.
72
+ 2. **Precedence Hierarchy**: Authoritative artifacts (`spec.md`, `plan.md`, `tasks.md`, `contracts`, `closure.json`) unconditionally govern over `context-capsule.json`.
73
+ 3. **Semantic Constraint Losslessness**: `LESS TEXT ≠ LESS CONSTRAINT`. All `MUST` and `MUST NOT` normative statements and frozen contracts are preserved verbatim in structured format.
74
+ 4. **Chat Transcript Exclusion**: `chat transcript ≠ project authority`. Conversational memory and raw git logs are strictly excluded from capsule inputs.
75
+ 5. **Verification Purity (`VERIFY = VALIDATE`)**: `gemstack verify` inspects schema, provenance, and freshness in read-only mode. It **NEVER** regenerates or mutates capsules on disk.
76
+ 6. **Zero External Runtime Dependencies**: Standard Node.js library exclusively (`node:fs`, `node:path`, `node:crypto`). Zero new npm production dependencies.
77
+ 7. **Fail-Closed Size Budget**: Exceeding the 64 KB hard limit halts fail-closed with `CONTEXT_CAPSULE_TOO_LARGE` rather than silently dropping rules.
78
+ 8. **Secrets Barrier**: Credential properties and token patterns are strictly blocked fail-closed with `CONTEXT_CAPSULE_SECRET_DETECTED`.
79
+
80
+ ---
81
+
82
+ ## Dependency Graph (5 Phased Waves)
83
+
84
+ ```mermaid
85
+ graph TD
86
+ subgraph "Phase 1: Foundation — Serialization, Schema & Secrets Guard"
87
+ UD_T001["T001: Zero-Dependency Core Enforcement"] --> UD_T002["T002: Canonical JSON Serializer & Deterministic Sorting"]
88
+ UD_T002 --> UD_T003["T003: Secret Defense Scanner & Forbidden Pattern Boundary"]
89
+ UD_T003 --> UD_T004["T004: Size Budget Counter & Priority Condensation Engine"]
90
+ end
91
+
92
+ subgraph "Phase 2: Source Resolution, Provenance & Constraint Compression"
93
+ UD_T002 --> UD_T005["T005: Authoritative Source Resolver & Source-Set Hasher"]
94
+ UD_T005 --> UD_T006["T006: Chat Transcript & Non-Authoritative Data Exclusion"]
95
+ UD_T005 --> UD_T007["T007: Normative Constraint Extractor (MUST/MUST NOT)"]
96
+ UD_T007 --> UD_T008["T008: Frozen Contracts & Acceptance Signature Compression"]
97
+ UD_T008 --> UD_T009["T009: Closed Upgrades & Explicit Deferred Scope Summarizer"]
98
+ end
99
+
100
+ subgraph "Phase 3: Generator & Validator Engines"
101
+ UD_T004 --> UD_T010["T010: Atomic Context Capsule Generator"]
102
+ UD_T009 --> UD_T010
103
+ UD_T010 --> UD_T011["T011: Read-Only Freshness & Provenance Validator"]
104
+ UD_T011 --> UD_T012["T012: Authority Conflict & Tampering Detection Engine"]
105
+ UD_T011 --> UD_T013["T013: Constraint Omission & Invariant Loss Detector"]
106
+ end
107
+
108
+ subgraph "Phase 4: CLI Surface & Verify Read-Only Integration"
109
+ UD_T010 --> UD_T014["T014: CLI Command: gemstack context generate"]
110
+ UD_T011 --> UD_T015["T015: CLI Commands: gemstack context show & context verify"]
111
+ UD_T014 --> UD_T016["T016: CLI Router Registration (src/cli.js)"]
112
+ UD_T015 --> UD_T016
113
+ UD_T011 --> UD_T017["T017: gemstack verify Stage 5.2 Read-Only Audit Integration"]
114
+ UD_T017 --> UD_T018["T018: Closure Context Relevant Files Resolution Update"]
115
+ end
116
+
117
+ subgraph "Phase 5: Legacy, Acceptance & Closure Readiness"
118
+ UD_T017 --> UD_T019["T019: Legacy Compatibility & Unconfigured Repo Bypass"]
119
+ UD_T017 --> UD_T020["T020: Upgrade D Findings & Non-Waivable Exception Binding"]
120
+ UD_T018 --> UD_T021["T021: Verification Purity & Zero-Network Mechanical Proof"]
121
+ UD_T019 --> UD_T022["T022: Package Script Test Registration & Regression Check"]
122
+ UD_T020 --> UD_T022
123
+ UD_T021 --> UD_T022
124
+ UD_T022 --> UD_T023["T023: Frozen Contract Invariant & Full CI Verification"]
125
+ UD_T023 --> UD_T024["T024: Upgrade D Dogfooding & Closure Readiness Confirmation"]
126
+ end
127
+ ```
128
+
129
+ ---
130
+
131
+ ## Tasks Inventory
132
+
133
+ ### Phase 1 — Foundation: Serialization, Schema & Secrets Guard
134
+
135
+ - [x] **T001: Enforce zero-dependency core architecture for Upgrade D**
136
+ <!-- gemstack:validation_required=true -->
137
+ <!-- gemstack:tests=TEST-CONTEXT-F02 -->
138
+ <!-- gemstack:files=package.json,src/lib/context-capsule.js -->
139
+ <!-- gemstack:depends= -->
140
+ *Objective*: Ensure Upgrade D relies strictly on Node.js built-ins (`node:fs`, `node:path`, `node:crypto`) and existing Gemstack zero-dependency helpers.
141
+ *Files*:
142
+ - NEW: `src/lib/context-capsule.js`
143
+ *Prerequisites*: NONE
144
+ *Implementation requirements*:
145
+ - Initialize `src/lib/context-capsule.js` with standard library imports only.
146
+ - Assert zero additions to `dependencies` in `package.json`.
147
+ *Must NOT*: Add any external npm production dependencies.
148
+ *Tests*: `tests/context-purity.test.js`
149
+ *Acceptance IDs*: `TEST-CONTEXT-F02`
150
+ *Bootstrap Contracts*: `zero-dependency-core`
151
+ *Completion criteria*: `package.json` contains 0 runtime dependencies; scripts run purely on Node.js standard library.
152
+ *Evidence*: `check-package-contents.js` and tests passing without extra packages.
153
+
154
+ - [x] **T002: Implement canonical JSON serializer with stable UTF-16 sorting and normalization**
155
+ <!-- gemstack:validation_required=true -->
156
+ <!-- gemstack:tests=TEST-CONTEXT-A01,TEST-CONTEXT-A02,TEST-CONTEXT-A03,TEST-CONTEXT-A04 -->
157
+ <!-- gemstack:files=src/lib/context-capsule.js,tests/context-determinism.test.js -->
158
+ <!-- gemstack:depends=T001 -->
159
+ *Objective*: Create deterministic JSON serialization utility ensuring byte-for-byte identical output across platforms.
160
+ *Files*:
161
+ - MODIFY: `src/lib/context-capsule.js`
162
+ - NEW: `tests/context-determinism.test.js`
163
+ *Prerequisites*: `T001`
164
+ *Implementation requirements*:
165
+ - Implement `serializeCanonicalJson(data)` in `src/lib/context-capsule.js`.
166
+ - Sort object keys recursively by UTF-16 code units (`(a < b ? -1 : (a > b ? 1 : 0))`).
167
+ - Sort array elements with identifiers deterministically (`sources`, `canonical_invariants`, `frozen_contracts`, `canonical_ids`).
168
+ - Normalize paths to POSIX repository-relative forward slashes using `hasher.normalizePath`.
169
+ - Exclude volatile timestamps (`generated_at`) from semantic content hash computations.
170
+ - Output with 2-space indentation and POSIX newline (`\n`).
171
+ *Must NOT*: Allow platform-dependent key order or Windows backslashes (`\`) in paths.
172
+ *Tests*: `tests/context-determinism.test.js`
173
+ *Acceptance IDs*: `TEST-CONTEXT-A01`, `TEST-CONTEXT-A02`, `TEST-CONTEXT-A03`, `TEST-CONTEXT-A04`
174
+ *Bootstrap Contracts*: `capsule-offline-deterministic`
175
+ *Completion criteria*: Repeated generation from identical inputs yields byte-identical output (100% SHA-256 match).
176
+ *Evidence*: `tests/context-determinism.test.js` passes.
177
+
178
+ - [x] **T003: Implement secrets scanner and forbidden credential boundary**
179
+ <!-- gemstack:validation_required=true -->
180
+ <!-- gemstack:tests=TEST-CONTEXT-E01,TEST-CONTEXT-E02,TEST-CONTEXT-E03 -->
181
+ <!-- gemstack:files=src/lib/context-capsule.js,tests/context-secrets.test.js -->
182
+ <!-- gemstack:depends=T002 -->
183
+ *Objective*: Prevent credentials, private keys, API secrets, and `.env` variables from being ingested into context capsules.
184
+ *Files*:
185
+ - MODIFY: `src/lib/context-capsule.js`
186
+ - NEW: `tests/context-secrets.test.js`
187
+ *Prerequisites*: `T002`
188
+ *Implementation requirements*:
189
+ - Implement `assertSecretsForbidden(capsuleObj)` in `src/lib/context-capsule.js`.
190
+ - Check property keys against forbidden list: `apiKey`, `api_key`, `token`, `accessToken`, `access_token`, `secret`, `clientSecret`, `password`, `credentials`.
191
+ - Scan string values against token patterns: AWS (`AKIA...`), GitHub (`ghp_...`), OpenAI (`sk-...`), Google (`AIza...`), Bearer tokens, private key headers (`-----BEGIN ... PRIVATE KEY-----`).
192
+ - Throw `CONTEXT_CAPSULE_SECRET_DETECTED` fail-closed on match without exposing secret text in message.
193
+ - Assert that `.env` files are never opened or ingested.
194
+ *Must NOT*: Log or embed detected secret values into error findings or fingerprints.
195
+ *Tests*: `tests/context-secrets.test.js`
196
+ *Acceptance IDs*: `TEST-CONTEXT-E01`, `TEST-CONTEXT-E02`, `TEST-CONTEXT-E03`
197
+ *Bootstrap Contracts*: `capsule-secrets-forbidden`
198
+ *Completion criteria*: Synthetic secret patterns trigger fail-closed halt with `CONTEXT_CAPSULE_SECRET_DETECTED`.
199
+ *Evidence*: `tests/context-secrets.test.js` passes all synthetic credential injection cases.
200
+
201
+ - [x] **T004: Implement size budget counter, priority condensation, and fail-closed overflow**
202
+ <!-- gemstack:validation_required=true -->
203
+ <!-- gemstack:tests=TEST-CONTEXT-G01 -->
204
+ <!-- gemstack:files=src/lib/context-capsule.js,tests/context-size-budget.test.js -->
205
+ <!-- gemstack:depends=T003 -->
206
+ *Objective*: Enforce deterministic size budget (32 KB target, 64 KB hard limit) without silent constraint dropping.
207
+ *Files*:
208
+ - MODIFY: `src/lib/context-capsule.js`
209
+ - NEW: `tests/context-size-budget.test.js`
210
+ *Prerequisites*: `T003`
211
+ *Implementation requirements*:
212
+ - Implement `enforceSizeBudget(capsuleObj)` in `src/lib/context-capsule.js`.
213
+ - Target budget: `32,768 bytes`; Hard limit: `65,536 bytes`.
214
+ - If serialized size exceeds 32 KB, condense non-normative Priority 3 and Priority 2 fields deterministically.
215
+ - Priority 1 (Authority model, safety invariants, contracts, lifecycle state) is NEVER dropped.
216
+ - If serialized size exceeds 64 KB, throw fail-closed error `CONTEXT_CAPSULE_TOO_LARGE`.
217
+ *Must NOT*: Silently drop or truncate any normative `MUST`/`MUST NOT` rule or frozen contract.
218
+ *Tests*: `tests/context-size-budget.test.js`
219
+ *Acceptance IDs*: `TEST-CONTEXT-G01`
220
+ *Bootstrap Contracts*: `capsule-size-budget-fail-closed`
221
+ *Completion criteria*: Exceeding 64 KB halts with `CONTEXT_CAPSULE_TOO_LARGE` fail-closed.
222
+ *Evidence*: `tests/context-size-budget.test.js` passes.
223
+
224
+ ---
225
+
226
+ ### Phase 2 — Source Resolution, Provenance & Constraint Compression
227
+
228
+ - [x] **T005: Implement authoritative source resolver and source-set hasher**
229
+ <!-- gemstack:validation_required=true -->
230
+ <!-- gemstack:tests=TEST-CONTEXT-C03 -->
231
+ <!-- gemstack:files=src/lib/context-capsule.js,tests/context-freshness.test.js -->
232
+ <!-- gemstack:depends=T002 -->
233
+ *Objective*: Resolve authoritative project files according to lifecycle phase and compute cryptographic provenance digest.
234
+ *Files*:
235
+ - MODIFY: `src/lib/context-capsule.js`
236
+ - NEW: `tests/context-freshness.test.js`
237
+ *Prerequisites*: `T002`
238
+ *Implementation requirements*:
239
+ - Implement `resolveAuthoritativeSources(rootPath, featureDir, currentPhase)`.
240
+ - Ingest strictly: `spec.md`, `plan.md`, `tasks.md`, `.gemstack/state.json`, `closure.json` (if present), `cost-ledger.json` (if present).
241
+ - Compute individual SHA-256 hashes via `hasher.hashFile`.
242
+ - Compute aggregate `source_set_hash` by hashing the UTF-16 code-unit sorted JSON of `{ path, hash }` records.
243
+ *Must NOT*: Ingest chat transcripts, git commit logs, raw test runner output, or source tree dumps.
244
+ *Tests*: `tests/context-freshness.test.js`
245
+ *Acceptance IDs*: `TEST-CONTEXT-C03`
246
+ *Bootstrap Contracts*: `capsule-is-derived-not-authority`
247
+ *Completion criteria*: Correct `source_set_hash` computed over normalized input sources.
248
+ *Evidence*: Provenance digest verification in unit tests.
249
+
250
+ - [x] **T006: Enforce strict exclusion of chat transcripts and conversational logs**
251
+ <!-- gemstack:validation_required=true -->
252
+ <!-- gemstack:tests=TEST-CONTEXT-B04 -->
253
+ <!-- gemstack:files=src/lib/context-capsule.js,tests/context-authority.test.js -->
254
+ <!-- gemstack:depends=T005 -->
255
+ *Objective*: Guarantee that conversational transcripts and ambient developer notes carry zero authority.
256
+ *Files*:
257
+ - MODIFY: `src/lib/context-capsule.js`
258
+ - NEW: `tests/context-authority.test.js`
259
+ *Prerequisites*: `T005`
260
+ *Implementation requirements*:
261
+ - Restrict capsule source whitelist to structured markdown and JSON files.
262
+ - Verify generator ignores conversation logs, prompt history, and IDE session state.
263
+ *Must NOT*: Ingest `.gemini/antigravity` transcript logs or ambient chat archives.
264
+ *Tests*: `tests/context-authority.test.js`
265
+ *Acceptance IDs*: `TEST-CONTEXT-B04`
266
+ *Bootstrap Contracts*: `capsule-is-derived-not-authority`
267
+ *Completion criteria*: Capsule sources list contains 0 conversational or transcript files.
268
+ *Evidence*: `TEST-CONTEXT-B04` passes.
269
+
270
+ - [x] **T007: Implement normative constraint extractor (MUST / MUST NOT)**
271
+ <!-- gemstack:validation_required=true -->
272
+ <!-- gemstack:tests=TEST-CONTEXT-D01 -->
273
+ <!-- gemstack:files=src/lib/context-capsule.js,tests/context-constraints.test.js -->
274
+ <!-- gemstack:depends=T005 -->
275
+ *Objective*: Extract 100% of normative behavioral rules from `spec.md` into `canonical_invariants`.
276
+ *Files*:
277
+ - MODIFY: `src/lib/context-capsule.js`
278
+ - NEW: `tests/context-constraints.test.js`
279
+ *Prerequisites*: `T005`
280
+ *Implementation requirements*:
281
+ - Implement `extractNormativeConstraints(specContent)` in `src/lib/context-capsule.js`.
282
+ - Scan markdown for statements containing `MUST`, `MUST NOT`, `REQUIRED`, `FORBIDDEN`.
283
+ - Assign deterministic IDs (`INV-001`, `INV-002`, ...), tag with normative modality (`MUST` vs `MUST_NOT`), and preserve source line/section reference.
284
+ - Omit rhetorical prose, tutorials, and historical background.
285
+ *Must NOT*: Soften, summarize, or generalize normative requirements.
286
+ *Tests*: `tests/context-constraints.test.js`
287
+ *Acceptance IDs*: `TEST-CONTEXT-D01`
288
+ *Bootstrap Contracts*: `compression-preserves-semantic-constraints`
289
+ *Completion criteria*: 100% of normative constraints from source spec are retained in `canonical_invariants`.
290
+ *Evidence*: `TEST-CONTEXT-D01` passes.
291
+
292
+ - [x] **T008: Implement frozen contracts and acceptance signature compressor**
293
+ <!-- gemstack:validation_required=true -->
294
+ <!-- gemstack:tests=TEST-CONTEXT-D02 -->
295
+ <!-- gemstack:files=src/lib/context-capsule.js,tests/context-constraints.test.js -->
296
+ <!-- gemstack:depends=T007 -->
297
+ *Objective*: Preserve active frozen contracts and test matrix signatures across compression.
298
+ *Files*:
299
+ - MODIFY: `src/lib/context-capsule.js`
300
+ - MODIFY: `tests/context-constraints.test.js`
301
+ *Prerequisites*: `T007`
302
+ *Implementation requirements*:
303
+ - Re-use `extractContractsBlock` from `src/lib/contracts.js` to extract contract IDs and types.
304
+ - Re-use `extractTestMatrixBlock` and `computeAcceptanceSignature` from `src/lib/test-matrix.js` to extract canonical IDs and signature.
305
+ - Re-use `parseTaskMetadata` from `src/lib/closure-context.js` to extract task summary counts.
306
+ *Must NOT*: Modify existing contract structures or drop acceptance IDs.
307
+ *Tests*: `tests/context-constraints.test.js`
308
+ *Acceptance IDs*: `TEST-CONTEXT-D02`
309
+ *Bootstrap Contracts*: `compression-preserves-semantic-constraints`
310
+ *Completion criteria*: Contract IDs and acceptance signature match source blocks 100%.
311
+ *Evidence*: `TEST-CONTEXT-D02` passes.
312
+
313
+ - [x] **T009: Implement closed upgrades and explicit deferred scope summarizer**
314
+ <!-- gemstack:validation_required=true -->
315
+ <!-- gemstack:tests=TEST-CONTEXT-D01,TEST-CONTEXT-D02 -->
316
+ <!-- gemstack:files=src/lib/context-capsule.js,tests/context-constraints.test.js -->
317
+ <!-- gemstack:depends=T008 -->
318
+ *Objective*: Condense completed upgrades and record explicit deferred items to prevent architectural drift.
319
+ *Files*:
320
+ - MODIFY: `src/lib/context-capsule.js`
321
+ - MODIFY: `tests/context-constraints.test.js`
322
+ *Prerequisites*: `T008`
323
+ *Implementation requirements*:
324
+ - Summarize shipped features (`006`, `007`, `008`) into compact records with key guarantees.
325
+ - Extract `deferred_items` from `spec.md` to prevent downstream agents from assuming omitted scope is forgotten.
326
+ - Record `unresolved_blockers` (empty array if none).
327
+ *Must NOT*: Represent settled decisions as open questions.
328
+ *Tests*: `tests/context-constraints.test.js`
329
+ *Acceptance IDs*: `TEST-CONTEXT-D01`, `TEST-CONTEXT-D02`
330
+ *Bootstrap Contracts*: `compression-preserves-semantic-constraints`
331
+ *Completion criteria*: Closed features and explicit deferrals are structured cleanly without narrative bloat.
332
+ *Evidence*: Test assertions verifying structured representation of historical context.
333
+
334
+ ---
335
+
336
+ ### Phase 3 — Generator & Validator Engines
337
+
338
+ - [x] **T010: Implement atomic context capsule generator**
339
+ <!-- gemstack:validation_required=true -->
340
+ <!-- gemstack:tests=TEST-CONTEXT-A01 -->
341
+ <!-- gemstack:files=src/lib/context-capsule.js,tests/context-determinism.test.js -->
342
+ <!-- gemstack:depends=T004,T009 -->
343
+ *Objective*: Orchestrate full generation pipeline and write `context-capsule.json` atomically.
344
+ *Files*:
345
+ - MODIFY: `src/lib/context-capsule.js`
346
+ - MODIFY: `tests/context-determinism.test.js`
347
+ *Prerequisites*: `T004`, `T009`
348
+ *Implementation requirements*:
349
+ - Implement `generateContextCapsule(rootPath, featureDir, options)`.
350
+ - Assemble canonical JSON payload from source resolver, constraint extractor, contracts, and matrix.
351
+ - Run secrets audit and size budget checks before serialization.
352
+ - Write atomically via temporary file with Windows-safe retry (reusing `writeJsonAtomic` pattern).
353
+ *Must NOT*: Leave partial or corrupted files on disk if generation fails.
354
+ *Tests*: `tests/context-determinism.test.js`
355
+ *Acceptance IDs*: `TEST-CONTEXT-A01`
356
+ *Bootstrap Contracts*: `capsule-offline-deterministic`
357
+ *Completion criteria*: Generates valid `context-capsule.json` atomically with matching hash.
358
+ *Evidence*: File generated and verified byte-for-byte in tests.
359
+
360
+ - [x] **T011: Implement read-only freshness and provenance validator**
361
+ <!-- gemstack:validation_required=true -->
362
+ <!-- gemstack:tests=TEST-CONTEXT-C01,TEST-CONTEXT-C02,TEST-CONTEXT-C03 -->
363
+ <!-- gemstack:files=src/lib/context-capsule.js,tests/context-freshness.test.js -->
364
+ <!-- gemstack:depends=T010 -->
365
+ *Objective*: Create read-only validator evaluating capsule schema, provenance hashes, and source freshness.
366
+ *Files*:
367
+ - MODIFY: `src/lib/context-capsule.js`
368
+ - MODIFY: `tests/context-freshness.test.js`
369
+ *Prerequisites*: `T010`
370
+ *Implementation requirements*:
371
+ - Implement `validateContextCapsule(rootPath, featureDir)` returning `{ valid, state, findings }`.
372
+ - States: `VALID`, `STALE`, `INVALID`, `MISSING`.
373
+ - Re-compute live SHA-256 hashes of recorded source files; if any hash differs, mark `STALE` with `CONTEXT_CAPSULE_STALE`.
374
+ - Ensure zero file writes, modifications, or touch operations occur during validation.
375
+ *Must NOT*: Regenerate or mutate the capsule when staleness is detected.
376
+ *Tests*: `tests/context-freshness.test.js`
377
+ *Acceptance IDs*: `TEST-CONTEXT-C01`, `TEST-CONTEXT-C02`, `TEST-CONTEXT-C03`
378
+ *Bootstrap Contracts*: `verify-never-regenerates-capsule`
379
+ *Completion criteria*: Touching `spec.md` or checking a box in `tasks.md` causes validator to return `STALE`.
380
+ *Evidence*: `TEST-CONTEXT-C01` and `TEST-CONTEXT-C02` pass.
381
+
382
+ - [x] **T012: Implement authority conflict and tampering detection engine**
383
+ <!-- gemstack:validation_required=true -->
384
+ <!-- gemstack:tests=TEST-CONTEXT-B01,TEST-CONTEXT-B02,TEST-CONTEXT-B03 -->
385
+ <!-- gemstack:files=src/lib/context-capsule.js,tests/context-authority.test.js -->
386
+ <!-- gemstack:depends=T011 -->
387
+ *Objective*: Reject capsules asserting claims contrary to authoritative source files and enforce source precedence.
388
+ *Files*:
389
+ - MODIFY: `src/lib/context-capsule.js`
390
+ - MODIFY: `tests/context-authority.test.js`
391
+ *Prerequisites*: `T011`
392
+ *Implementation requirements*:
393
+ - Detect manual tampering with task status, contracts, or source hashes.
394
+ - Emit `CONTEXT_CAPSULE_AUTHORITY_CONFLICT` if capsule claims diverge from source.
395
+ - Implement consumer resolver helper proving source artifact unconditionally wins.
396
+ *Must NOT*: Allow manual capsule edits to override authoritative specifications or plans.
397
+ *Tests*: `tests/context-authority.test.js`
398
+ *Acceptance IDs*: `TEST-CONTEXT-B01`, `TEST-CONTEXT-B02`, `TEST-CONTEXT-B03`
399
+ *Bootstrap Contracts*: `capsule-is-derived-not-authority`
400
+ *Completion criteria*: Tampered capsule is rejected; resolver returns source artifact value.
401
+ *Evidence*: `TEST-CONTEXT-B01`, `B02`, and `B03` pass.
402
+
403
+ - [x] **T013: Implement invariant omission and constraint loss detector**
404
+ <!-- gemstack:validation_required=true -->
405
+ <!-- gemstack:tests=TEST-CONTEXT-D01 -->
406
+ <!-- gemstack:files=src/lib/context-capsule.js,tests/context-constraints.test.js -->
407
+ <!-- gemstack:depends=T011 -->
408
+ *Objective*: Ensure validation fails if a required normative invariant is omitted from the capsule.
409
+ *Files*:
410
+ - MODIFY: `src/lib/context-capsule.js`
411
+ - MODIFY: `tests/context-constraints.test.js`
412
+ *Prerequisites*: `T011`
413
+ *Implementation requirements*:
414
+ - Compare `canonical_invariants` in capsule against live spec extraction.
415
+ - Emit blocker `CONTEXT_CAPSULE_INVARIANT_DROPPED` if any normative rule is missing.
416
+ *Must NOT*: Pass validation solely on matching source hashes if semantic coverage is incomplete.
417
+ *Tests*: `tests/context-constraints.test.js`
418
+ *Acceptance IDs*: `TEST-CONTEXT-D01`
419
+ *Bootstrap Contracts*: `compression-preserves-semantic-constraints`
420
+ *Completion criteria*: Capsule with a stripped invariant fails validation with `CONTEXT_CAPSULE_INVARIANT_DROPPED`.
421
+ *Evidence*: Adversarial invariant omission test passes.
422
+
423
+ ---
424
+
425
+ ### Phase 4 — CLI Surface & Verify Read-Only Integration
426
+
427
+ - [x] **T014: Implement CLI command: gemstack context generate**
428
+ <!-- gemstack:validation_required=true -->
429
+ <!-- gemstack:tests=TEST-CONTEXT-A01 -->
430
+ <!-- gemstack:files=src/commands/context.js -->
431
+ <!-- gemstack:depends=T010 -->
432
+ *Objective*: Create CLI command to explicitly compile authoritative sources into `context-capsule.json`.
433
+ *Files*:
434
+ - NEW: `src/commands/context.js`
435
+ *Prerequisites*: `T010`
436
+ *Implementation requirements*:
437
+ - Parse `--target` and `--feature` flags.
438
+ - Invoke `generateContextCapsule` and report generation summary (size, source count, invariant count).
439
+ - Exit code 0 on success; exit code 1 on validation/size/secret failure.
440
+ *Must NOT*: Mutate source markdown files or invoke remote AI APIs.
441
+ *Tests*: `tests/context-determinism.test.js`
442
+ *Acceptance IDs*: `TEST-CONTEXT-A01`
443
+ *Bootstrap Contracts*: `capsule-offline-deterministic`
444
+ *Completion criteria*: Running `gemstack context generate` produces valid capsule file on disk.
445
+ *Evidence*: CLI invocation test passes.
446
+
447
+ - [x] **T015: Implement CLI commands: gemstack context show and context verify**
448
+ <!-- gemstack:validation_required=true -->
449
+ <!-- gemstack:tests=TEST-CONTEXT-C03 -->
450
+ <!-- gemstack:files=src/commands/context.js -->
451
+ <!-- gemstack:depends=T014 -->
452
+ *Objective*: Provide read-only inspection and standalone validation commands for context capsules.
453
+ *Files*:
454
+ - MODIFY: `src/commands/context.js`
455
+ *Prerequisites*: `T014`
456
+ *Implementation requirements*:
457
+ - `show`: Display formatted summary or raw JSON (`--json`). Strictly read-only.
458
+ - `verify`: Invoke `validateContextCapsule` and report status (`VALID`, `STALE`, `INVALID`, `MISSING`).
459
+ *Must NOT*: Regenerate capsule during `show` or `verify` operations.
460
+ *Tests*: `tests/context-freshness.test.js`
461
+ *Acceptance IDs*: `TEST-CONTEXT-C03`
462
+ *Bootstrap Contracts*: `verify-never-regenerates-capsule`
463
+ *Completion criteria*: Commands inspect and validate capsules without touching filesystem.
464
+ *Evidence*: Unit/CLI tests confirming zero side effects.
465
+
466
+ - [x] **T016: Register context command routing and help text in src/cli.js**
467
+ <!-- gemstack:validation_required=true -->
468
+ <!-- gemstack:tests=TEST-CONTEXT-A01 -->
469
+ <!-- gemstack:files=src/cli.js -->
470
+ <!-- gemstack:depends=T015 -->
471
+ *Objective*: Integrate `context` command into main Gemstack CLI router.
472
+ *Files*:
473
+ - MODIFY: `src/cli.js`
474
+ *Prerequisites*: `T015`
475
+ *Implementation requirements*:
476
+ - Add `context` command to help text and switch statement.
477
+ - Route subcommands (`generate`, `show`, `verify`) to `src/commands/context.js`.
478
+ *Must NOT*: Alter routing or behavior of existing commands (`verify`, `collect`, `ship`).
479
+ *Tests*: `tests/context-determinism.test.js`
480
+ *Acceptance IDs*: `TEST-CONTEXT-A01`
481
+ *Completion criteria*: `gemstack context` is recognized and callable via CLI.
482
+ *Evidence*: CLI help output includes `context`.
483
+
484
+ - [x] **T017: Integrate Stage 5.2 Context Capsule read-only audit into src/commands/verify.js**
485
+ <!-- gemstack:validation_required=true -->
486
+ <!-- gemstack:tests=TEST-CONTEXT-F01,TEST-CONTEXT-H01 -->
487
+ <!-- gemstack:files=src/commands/verify.js -->
488
+ <!-- gemstack:depends=T011 -->
489
+ *Objective*: Embed read-only Context Capsule audit into `gemstack verify` without mutating disk.
490
+ *Files*:
491
+ - MODIFY: `src/commands/verify.js`
492
+ *Prerequisites*: `T011`
493
+ *Implementation requirements*:
494
+ - Add Stage 5.2 in `src/commands/verify.js` auditing `active_spec` capsule.
495
+ - Check schema validity and freshness.
496
+ - Emit blocker findings if `STALE`, `INVALID`, `TOO_LARGE`, or `SECRET_DETECTED`.
497
+ - Log informational legacy notice if capsule absent in legacy feature.
498
+ *Must NOT*: Write, touch, or regenerate `context-capsule.json` during verify.
499
+ *Tests*: `tests/context-purity.test.js`, `tests/context-legacy.test.js`
500
+ *Acceptance IDs*: `TEST-CONTEXT-F01`, `TEST-CONTEXT-H01`
501
+ *Bootstrap Contracts*: `verify-never-regenerates-capsule`
502
+ *Completion criteria*: `gemstack verify` reports capsule state; 0 file modifications occur.
503
+ *Evidence*: `TEST-CONTEXT-F01` passes.
504
+
505
+ - [x] **T018: Include context-capsule.json in RelevantClosureFiles resolution**
506
+ <!-- gemstack:validation_required=true -->
507
+ <!-- gemstack:tests=TEST-CONTEXT-F01 -->
508
+ <!-- gemstack:files=src/lib/closure-context.js -->
509
+ <!-- gemstack:depends=T017 -->
510
+ *Objective*: Ensure `context-capsule.json` is factored into closure context hash when present.
511
+ *Files*:
512
+ - MODIFY: `src/lib/closure-context.js`
513
+ *Prerequisites*: `T017`
514
+ *Implementation requirements*:
515
+ - In `resolveRelevantFiles`, check if `context-capsule.json` exists in active feature directory; add to relevant files set if present.
516
+ *Must NOT*: Require `context-capsule.json` in legacy features that do not declare Upgrade D contracts.
517
+ *Tests*: `tests/context-purity.test.js`
518
+ *Acceptance IDs*: `TEST-CONTEXT-F01`
519
+ *Completion criteria*: `resolveRelevantFiles` returns `context-capsule.json` when present on disk.
520
+ *Evidence*: Unit test verifying relevant files output.
521
+
522
+ ---
523
+
524
+ ### Phase 5 — Legacy, Acceptance & Closure Readiness
525
+
526
+ - [x] **T019: Implement progressive legacy mode compatibility**
527
+ <!-- gemstack:validation_required=true -->
528
+ <!-- gemstack:tests=TEST-CONTEXT-H01 -->
529
+ <!-- gemstack:files=src/lib/context-capsule.js,src/commands/verify.js,tests/context-legacy.test.js -->
530
+ <!-- gemstack:depends=T017 -->
531
+ *Objective*: Ensure legacy projects lacking context capsules operate cleanly with zero false blockers.
532
+ *Files*:
533
+ - MODIFY: `src/commands/verify.js`
534
+ - NEW: `tests/context-legacy.test.js`
535
+ *Prerequisites*: `T017`
536
+ *Implementation requirements*:
537
+ - In legacy features (lacking Upgrade D contracts), missing capsule emits informational notice only:
538
+ `[INFO] [LEGACY] No se detectó context-capsule.json (Modo Legacy Context-Free).`
539
+ - `gemstack verify` exits with code 0 and 0 errors on legacy repositories.
540
+ *Must NOT*: Block legacy projects or historical features.
541
+ *Tests*: `tests/context-legacy.test.js`
542
+ *Acceptance IDs*: `TEST-CONTEXT-H01`
543
+ *Bootstrap Contracts*: `legacy-capsule-compatibility`
544
+ *Completion criteria*: Legacy fixture passes `gemstack verify` with exit code 0.
545
+ *Evidence*: `TEST-CONTEXT-H01` passes.
546
+
547
+ - [x] **T020: Bind Upgrade D findings to findings engine with non-waivable exceptions policy**
548
+ <!-- gemstack:validation_required=true -->
549
+ <!-- gemstack:tests=TEST-CONTEXT-B01,TEST-CONTEXT-E01 -->
550
+ <!-- gemstack:files=src/lib/context-capsule.js,src/lib/findings.js -->
551
+ <!-- gemstack:depends=T017 -->
552
+ *Objective*: Standardize findings codes and enforce non-waivable policy for capsule safety blockers.
553
+ *Files*:
554
+ - MODIFY: `src/lib/context-capsule.js`
555
+ *Prerequisites*: `T017`
556
+ *Implementation requirements*:
557
+ - Generate canonical 64-char lowercase hex fingerprints via `computeFindingFingerprint`.
558
+ - Enforce that `CONTEXT_CAPSULE_STALE`, `CONTEXT_CAPSULE_INVALID`, `CONTEXT_CAPSULE_SECRET_DETECTED`, `CONTEXT_CAPSULE_TOO_LARGE`, and `CONTEXT_CAPSULE_AUTHORITY_CONFLICT` are strictly non-waivable.
559
+ *Must NOT*: Permit waiving stale, secret-bearing, or conflicting capsules with exceptions.
560
+ *Tests*: `tests/context-authority.test.js`, `tests/context-secrets.test.js`
561
+ *Acceptance IDs*: `TEST-CONTEXT-B01`, `TEST-CONTEXT-E01`
562
+ *Completion criteria*: Safety blockers cannot be suppressed by `.gemstack.json` exceptions.
563
+ *Evidence*: Findings test assertions confirming rejection of waivers.
564
+
565
+ - [x] **T021: Verify verification purity and zero-network mechanical proof**
566
+ <!-- gemstack:validation_required=true -->
567
+ <!-- gemstack:tests=TEST-CONTEXT-F01,TEST-CONTEXT-F02 -->
568
+ <!-- gemstack:files=tests/context-purity.test.js -->
569
+ <!-- gemstack:depends=T017 -->
570
+ *Objective*: Mechanically prove that verify performs zero file mutations and zero network socket queries.
571
+ *Files*:
572
+ - NEW: `tests/context-purity.test.js`
573
+ *Prerequisites*: `T017`
574
+ *Implementation requirements*:
575
+ - Test 1: Snapshot filesystem before and after `gemstack verify`; verify 100% hash tree match (0 bytes modified).
576
+ - Test 2: Mock Node's `net.Socket` and `http/https.request` to throw; assert verify exits 0 without network attempts.
577
+ *Must NOT*: Allow any background socket or file touch in verify.
578
+ *Tests*: `tests/context-purity.test.js`
579
+ *Acceptance IDs*: `TEST-CONTEXT-F01`, `TEST-CONTEXT-F02`
580
+ *Bootstrap Contracts*: `verify-never-regenerates-capsule`, `capsule-offline-deterministic`
581
+ *Completion criteria*: `TEST-CONTEXT-F01` and `TEST-CONTEXT-F02` pass.
582
+ *Evidence*: Both purity assertions pass.
583
+
584
+ - [x] **T022: Register 8 new test suites in package.json and verify complete regression pass**
585
+ <!-- gemstack:validation_required=true -->
586
+ <!-- gemstack:tests=TEST-CONTEXT-A01 -->
587
+ <!-- gemstack:files=package.json -->
588
+ <!-- gemstack:depends=T019,T020,T021 -->
589
+ *Objective*: Add all 8 new test files to `npm test` and assert 0 regressions across all historical suites.
590
+ *Files*:
591
+ - MODIFY: `package.json`
592
+ *Prerequisites*: `T019`, `T020`, `T021`
593
+ *Implementation requirements*:
594
+ - Append 8 test files to `scripts.test` in `package.json`:
595
+ `tests/context-determinism.test.js`, `tests/context-authority.test.js`, `tests/context-freshness.test.js`, `tests/context-constraints.test.js`, `tests/context-secrets.test.js`, `tests/context-purity.test.js`, `tests/context-size-budget.test.js`, `tests/context-legacy.test.js`.
596
+ - Run `npm test` and assert 100% pass across all 25 test suites.
597
+ *Must NOT*: Introduce silent error masks (`2>nul`) or break existing test runners.
598
+ *Tests*: All 25 suites
599
+ *Acceptance IDs*: `TEST-CONTEXT-A01`..`TEST-CONTEXT-H01`
600
+ *Completion criteria*: Full test suite passes with 0 failures.
601
+ *Evidence*: `npm test` output showing all suites green.
602
+
603
+ - [x] **T023: Verify frozen contract invariants and execute complete CI validation suite**
604
+ <!-- gemstack:validation_required=true -->
605
+ <!-- gemstack:tests=TEST-CONTEXT-A01 -->
606
+ <!-- gemstack:files=package.json -->
607
+ <!-- gemstack:depends=T022 -->
608
+ *Objective*: Mechanically prove that zero frozen contracts were affected and run full project CI.
609
+ *Files*:
610
+ - UNCHANGED
611
+ *Prerequisites*: `T022`
612
+ *Implementation requirements*:
613
+ - Re-verify Upgrade A contracts (`zero-dependency-core`, `upgrade-a-contract-types`, etc.).
614
+ - Re-verify Upgrade B closure mechanics and Upgrade C provider safety gates.
615
+ - Run `npm run ci:all` (frontmatter, mojibake, package contents, smoke).
616
+ *Must NOT*: Alter or weaken any frozen contract.
617
+ *Tests*: `npm run ci:all`
618
+ *Acceptance IDs*: `TEST-CONTEXT-A01`..`TEST-CONTEXT-H01`
619
+ *Completion criteria*: `ci:all` exits 0 with 0 errors.
620
+ *Evidence*: Terminal output showing clean CI execution.
621
+
622
+ - [x] **T024: Perform Upgrade D dogfooding and confirm closure readiness**
623
+ <!-- gemstack:validation_required=true -->
624
+ <!-- gemstack:tests=TEST-CONTEXT-A01..TEST-CONTEXT-H01 -->
625
+ <!-- gemstack:files=specs/009-context-capsule/context-capsule.json -->
626
+ <!-- gemstack:depends=T023 -->
627
+ *Objective*: Generate dogfooding `specs/009-context-capsule/context-capsule.json` and verify closure readiness without closing feature.
628
+ *Files*:
629
+ - NEW: `specs/009-context-capsule/context-capsule.json`
630
+ *Prerequisites*: `T023`
631
+ *Implementation requirements*:
632
+ - Run `gemstack context generate` for `specs/009-context-capsule`.
633
+ - Validate capsule passes `gemstack verify` in Stage 5.2.
634
+ - Confirm 20/20 acceptance tests pass, 8/8 bootstrap contracts covered, 0 blockers.
635
+ *Must NOT*: Mark Upgrade D closed or transition status to SHIPPED.
636
+ *Tests*: Full acceptance matrix
637
+ *Acceptance IDs*: `TEST-CONTEXT-A01`..`TEST-CONTEXT-H01`
638
+ *Completion criteria*: Capsule generated, valid, and verified. State remains `IMPLEMENTED — NOT YET CLOSED`.
639
+ *Evidence*: Dogfooding capsule on disk and clean audit report.
640
+
641
+ ---
642
+
643
+ ## Canonical Acceptance Traceability Matrix (20/20 Mapped)
644
+
645
+ | Acceptance ID | Category | Layer | Task ID(s) | Target Test File | Mechanical Proof |
646
+ | :--- | :--- | :--- | :--- | :--- | :--- |
647
+ | `TEST-CONTEXT-A01` | DETERMINISM | UNIT | `T002`, `T010`, `T014` | `tests/context-determinism.test.js` | 2 independent runs yield identical SHA-256 |
648
+ | `TEST-CONTEXT-A02` | DETERMINISM | UNIT | `T002` | `tests/context-determinism.test.js` | Object keys match UTF-16 code-unit sorted order |
649
+ | `TEST-CONTEXT-A03` | DETERMINISM | UNIT | `T002` | `tests/context-determinism.test.js` | Modifying `generated_at` leaves content hash intact |
650
+ | `TEST-CONTEXT-A04` | DETERMINISM | UNIT | `T002` | `tests/context-determinism.test.js` | Path strings contain zero backslashes or drive prefixes |
651
+ | `TEST-CONTEXT-B01` | AUTHORITY | UNIT | `T012`, `T020` | `tests/context-authority.test.js` | Divergent capsule emits `CONTEXT_CAPSULE_AUTHORITY_CONFLICT` |
652
+ | `TEST-CONTEXT-B02` | AUTHORITY | UNIT | `T012` | `tests/context-authority.test.js` | Consumer resolver returns source value on conflict |
653
+ | `TEST-CONTEXT-B03` | AUTHORITY | UNIT | `T012` | `tests/context-authority.test.js` | Tampered capsule content hash emits `CONTEXT_CAPSULE_STALE` |
654
+ | `TEST-CONTEXT-B04` | AUTHORITY | UNIT | `T006` | `tests/context-authority.test.js` | Capsule sources list contains zero transcript files |
655
+ | `TEST-CONTEXT-C01` | FRESHNESS | INTEGRATION | `T011` | `tests/context-freshness.test.js` | Mutating `spec.md` causes verify to fail with `STALE` |
656
+ | `TEST-CONTEXT-C02` | FRESHNESS | INTEGRATION | `T011` | `tests/context-freshness.test.js` | Checking task in `tasks.md` causes verify to fail with `STALE` |
657
+ | `TEST-CONTEXT-C03` | FRESHNESS | UNIT | `T005`, `T011`, `T015` | `tests/context-freshness.test.js` | Untouched sources pass verification with `VALID` |
658
+ | `TEST-CONTEXT-D01` | CONSTRAINTS | UNIT | `T007`, `T009`, `T013` | `tests/context-constraints.test.js` | 100% of MUST/MUST NOT rules extracted into capsule |
659
+ | `TEST-CONTEXT-D02` | CONSTRAINTS | UNIT | `T008`, `T009` | `tests/context-constraints.test.js` | Contract IDs and acceptance signature preserved exactly |
660
+ | `TEST-CONTEXT-E01` | SECURITY | UNIT | `T003`, `T020` | `tests/context-secrets.test.js` | Forbidden credential key triggers fail-closed halt |
661
+ | `TEST-CONTEXT-E02` | SECURITY | UNIT | `T003` | `tests/context-secrets.test.js` | Injected token patterns (`sk-...`, `AIza...`) rejected |
662
+ | `TEST-CONTEXT-E03` | SECURITY | UNIT | `T003` | `tests/context-secrets.test.js` | Capsule contains zero references or values from `.env` |
663
+ | `TEST-CONTEXT-F01` | VERIFICATION_PURITY | INTEGRATION | `T017`, `T018`, `T021` | `tests/context-purity.test.js` | File hash tree before and after verify matches 100% |
664
+ | `TEST-CONTEXT-F02` | VERIFICATION_PURITY | INTEGRATION | `T001`, `T021` | `tests/context-purity.test.js` | Verify passes with all network sockets throwing mocks |
665
+ | `TEST-CONTEXT-G01` | SIZE_SAFETY | UNIT | `T004` | `tests/context-size-budget.test.js` | Exceeding 64 KB fails closed with `CONTEXT_CAPSULE_TOO_LARGE` |
666
+ | `TEST-CONTEXT-H01` | LEGACY | UNIT | `T017`, `T019` | `tests/context-legacy.test.js` | Unconfigured repo passes verify with exit code 0 and info note |
667
+
668
+ ---
669
+
670
+ ## Bootstrap Contracts Traceability (8/8 Mapped)
671
+
672
+ | Bootstrap Contract | Task ID(s) | Implementation Surface | Test File | Mechanical Proof |
673
+ | :--- | :--- | :--- | :--- | :--- |
674
+ | `zero-dependency-core` | `T001` | `package.json`, `src/lib/context-capsule.js` | `tests/context-purity.test.js` | 0 runtime deps in `package.json`; stdlib only |
675
+ | `capsule-is-derived-not-authority` | `T005`, `T006`, `T012` | `src/lib/context-capsule.js` | `tests/context-authority.test.js` | Authoritative source unconditionally overrides capsule |
676
+ | `compression-preserves-semantic-constraints` | `T007`, `T008`, `T009`, `T013` | `src/lib/context-capsule.js` | `tests/context-constraints.test.js` | 100% of MUST/MUST NOT rules and contracts retained |
677
+ | `verify-never-regenerates-capsule` | `T011`, `T015`, `T017`, `T021` | `src/commands/verify.js` | `tests/context-purity.test.js` | Zero disk writes; filesystem hash before/after matches |
678
+ | `capsule-secrets-forbidden` | `T003`, `T020` | `src/lib/context-capsule.js` | `tests/context-secrets.test.js` | Fail-closed halt on secret property or regex pattern |
679
+ | `capsule-offline-deterministic` | `T002`, `T010`, `T014`, `T021` | `src/lib/context-capsule.js` | `tests/context-determinism.test.js` | Repeated generation yields byte-identical SHA-256 |
680
+ | `capsule-size-budget-fail-closed` | `T004` | `src/lib/context-capsule.js` | `tests/context-size-budget.test.js` | Content > 64 KB halts with `CONTEXT_CAPSULE_TOO_LARGE` |
681
+ | `legacy-capsule-compatibility` | `T017`, `T019` | `src/commands/verify.js` | `tests/context-legacy.test.js` | Legacy repo passes verify with exit code 0 |
682
+
683
+ ---
684
+
685
+ ## Adversarial Coverage Matrix (22 Vector Scenarios)
686
+
687
+ | # | Adversarial Scenario | Task ID | Target Test File | Expected Outcome |
688
+ | :--- | :--- | :--- | :--- | :--- |
689
+ | 1 | Capsule overrides source task completion claim | `T012` | `tests/context-authority.test.js` | Source `tasks.md` unconditionally wins; conflict flagged |
690
+ | 2 | Authoritative source mutated after capsule generation | `T011` | `tests/context-freshness.test.js` | Verify flags `CONTEXT_CAPSULE_STALE` blocker |
691
+ | 3 | Manual alteration of source hash inside capsule JSON | `T012` | `tests/context-authority.test.js` | Re-hash reconciles against disk; flags `STALE` |
692
+ | 4 | Manual deletion of a required normative invariant | `T013` | `tests/context-constraints.test.js` | Flags `CONTEXT_CAPSULE_INVARIANT_DROPPED` blocker |
693
+ | 5 | Closed upgrade represented as open question | `T009` | `tests/context-constraints.test.js` | Replaced with closed status token and key guarantees |
694
+ | 6 | Explicit deferred work omitted or treated as forgotten | `T009` | `tests/context-constraints.test.js` | Retained verbatim in `deferred_items` array |
695
+ | 7 | Secret-shaped property injected (`apiKey: "xyz"`) | `T003` | `tests/context-secrets.test.js` | Halts with `CONTEXT_CAPSULE_SECRET_DETECTED` |
696
+ | 8 | Synthetic token value injected (`sk-live123...`) | `T003` | `tests/context-secrets.test.js` | Regex scanner fails closed; zero secret in error |
697
+ | 9 | Private key block injected (`BEGIN RSA PRIVATE KEY`) | `T003` | `tests/context-secrets.test.js` | Scanner halts generation fail-closed |
698
+ | 10 | Local `.env` file present in project root | `T003` | `tests/context-secrets.test.js` | Whitelist ignores `.env`; zero content in capsule |
699
+ | 11 | Filesystem traversal returns unordered keys | `T002` | `tests/context-determinism.test.js` | Strict UTF-16 code-unit sort produces identical bytes |
700
+ | 12 | Absolute machine drive paths (`C:\CODES\...`) injected | `T002` | `tests/context-determinism.test.js` | Normalized to POSIX repository-relative forward slashes |
701
+ | 13 | Environment variable permutation between runs | `T002` | `tests/context-determinism.test.js` | Content hash completely unaffected by environment |
702
+ | 14 | Execution timestamp varies across generation runs | `T002` | `tests/context-determinism.test.js` | `generated_at` excluded from semantic content hash |
703
+ | 15 | Priority 1 constraints exceed 64 KB hard limit | `T004` | `tests/context-size-budget.test.js` | Halts with `CONTEXT_CAPSULE_TOO_LARGE` fail-closed |
704
+ | 16 | Attempt to silently truncate invariants to fit budget | `T004` | `tests/context-size-budget.test.js` | Truncation forbidden; generator halts with error |
705
+ | 17 | `gemstack verify` executed against stale capsule | `T017` | `tests/context-purity.test.js` | Verify reports STALE; NEVER rewrites capsule file |
706
+ | 18 | `gemstack verify` executed against valid capsule | `T021` | `tests/context-purity.test.js` | Filesystem hash tree before/after matches 100% |
707
+ | 19 | Network socket connection attempted during verify | `T021` | `tests/context-purity.test.js` | Throwing socket mock asserts zero network traffic |
708
+ | 20 | Chat transcript file injected into directory | `T006` | `tests/context-authority.test.js` | Generator strictly excludes transcript from sources |
709
+ | 21 | Unsupported schema version (`schema_version: 99`) | `T011` | `tests/context-freshness.test.js` | Flags `CONTEXT_CAPSULE_INVALID` blocker |
710
+ | 22 | Failure during atomic write before rename completes | `T010` | `tests/context-determinism.test.js` | Temp file unlinked; original destination preserved |
711
+
712
+ ---
713
+
714
+ ## Explicit Deferred Items
715
+
716
+ - Cross-repository capsule federation (non-goal).
717
+ - Semantic vector embeddings or vector database indexing (non-goal).
718
+ - Autonomous agent swarms and multi-worker work queues (non-goal).
719
+ - Visual QA and automated browser screenshot diffing (non-goal).
720
+ - Package version bumping and npm publishing (handled strictly post-closure).