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.
- package/.gemstack/state.json +11 -10
- package/CHANGELOG.md +97 -0
- package/README.md +89 -9
- package/RELEASE_NOTES.md +77 -0
- package/{gemstack-ai-1.2.0.tgz → gemstack-ai-1.4.0.tgz} +0 -0
- package/handoff.md +14 -12
- package/package.json +2 -2
- package/specs/008-cost-provider-safety-gates/.gemstack.json +5 -0
- package/specs/008-cost-provider-safety-gates/closure.json +59 -0
- package/specs/008-cost-provider-safety-gates/plan.md +456 -0
- package/specs/008-cost-provider-safety-gates/spec.md +633 -0
- package/specs/008-cost-provider-safety-gates/tasks.md +635 -0
- package/specs/009-context-capsule/closure.json +59 -0
- package/specs/009-context-capsule/context-capsule.json +428 -0
- package/specs/009-context-capsule/plan.md +663 -0
- package/specs/009-context-capsule/spec.md +913 -0
- package/specs/009-context-capsule/tasks.md +720 -0
- 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 +10 -0
- package/src/commands/context.js +95 -0
- package/src/commands/swarm.js +111 -0
- package/src/commands/verify.js +92 -0
- package/src/commands/visual.js +82 -0
- package/src/lib/closure-context.js +18 -1
- package/src/lib/context-capsule.js +594 -0
- package/src/lib/cost-ledger.js +355 -0
- package/src/lib/provider-boundary.js +186 -0
- package/src/lib/provider-registry.js +265 -0
- package/src/lib/safety-gates.js +277 -0
- package/src/lib/swarm.js +639 -0
- package/src/lib/visual-qa.js +499 -0
|
@@ -0,0 +1,913 @@
|
|
|
1
|
+
# Especificación de Funcionalidad: Context Capsule / Context Compression (Upgrade D)
|
|
2
|
+
|
|
3
|
+
**Feature Branch**: `009-context-capsule`
|
|
4
|
+
**Feature Directory**: `specs/009-context-capsule/`
|
|
5
|
+
**Lifecycle Status**: `SPEC_COMPLETE`
|
|
6
|
+
**Stop Reason**: `SPEC_COMPLETE_AWAITING_REVIEW`
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## 1. Problem Statement
|
|
11
|
+
|
|
12
|
+
Large AI-assisted software engineering projects accumulate vast amounts of architectural, planning, task, and evidence context across multiple working sessions. This context spans accepted specifications, technical plans, task execution states, frozen architecture contracts, safety invariants, test closure evidence, and active constraints.
|
|
13
|
+
|
|
14
|
+
When engineering work continues in:
|
|
15
|
+
- A new AI chat session or fresh context window,
|
|
16
|
+
- An autonomous subagent or parallel coding worker,
|
|
17
|
+
- A different developer machine, OS, or fresh git clone,
|
|
18
|
+
- Another LLM model family or IDE toolchain,
|
|
19
|
+
|
|
20
|
+
replaying the entire historical conversation, raw test transcripts, or exhaustive repository diffs is impractical, cost-prohibitive, and context-polluting. Under current workflows, this context gap creates severe operational risks:
|
|
21
|
+
1. **Architectural Drift**: New sessions inadvertently alter settled design choices or reimplement existing subsystems.
|
|
22
|
+
2. **Invariant Amnesia**: Critical safety constraints (such as fail-closed cost policies, offline verification purity, and zero-dependency core) are forgotten or diluted.
|
|
23
|
+
3. **Re-Opening Closed Decisions**: Sessions spend tokens and time debating questions already decided in prior specifications.
|
|
24
|
+
4. **Frozen Contract Violations**: New code modifies interfaces protected by Upgrade A consistency checks without knowing they are frozen.
|
|
25
|
+
5. **Nondeterministic Memory Contamination**: Relying on free-form chat transcripts or ambient developer notes injects conversational ambiguity into formal requirements.
|
|
26
|
+
6. **Secret & Privacy Leakage**: Blindly aggregating project context risks ingesting local `.env` secrets, API keys, or machine-specific absolute paths.
|
|
27
|
+
7. **Oversized Context Payloads**: Ingesting raw logs, git history, or complete file trees exhausts model token limits and degrades reasoning quality.
|
|
28
|
+
|
|
29
|
+
Gemstack requires a canonical, deterministic, and auditable mechanism to extract a compact continuation artifact—the **Context Capsule**—derived strictly from authoritative repository state.
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## 2. Goals & Non-Goals
|
|
34
|
+
|
|
35
|
+
### Goals
|
|
36
|
+
- **Deterministic Continuation Context**: Define a canonical machine-readable artifact (`context-capsule.json`) representing the exact minimal context required for a new agent or developer to continue project work safely.
|
|
37
|
+
- **Semantic Constraint Losslessness**: Compress context by stripping historical debate, conversational narrative, and redundant prose while preserving 100% of behavior-affecting constraints, invariants, frozen contracts, acceptance criteria, and active tasks.
|
|
38
|
+
- **Strict Derived-Artifact Model**: Enforce that the capsule is mechanically derived from authoritative sources. The capsule NEVER supersedes or replaces `spec.md`, `plan.md`, `tasks.md`, or `closure.json`.
|
|
39
|
+
- **Closed Work Summarization**: Condense completed upgrades (Upgrade A, B, C) into compact structural records with authoritative pointers rather than reproducing their exhaustive implementation history.
|
|
40
|
+
- **Strict Offline & Zero-Dependency Operation**: Generate and validate capsules using native Node.js standard library built-ins exclusively, requiring zero external npm packages, zero cloud services, and zero network calls.
|
|
41
|
+
- **Verification Purity (`VERIFY = VALIDATE`)**: Ensure `gemstack verify` inspects capsule schema, provenance, and freshness in read-only mode, never mutating or regenerating the capsule during verification.
|
|
42
|
+
- **Fail-Closed Freshness & Provenance**: Mechanically detect when authoritative sources have drifted, marking stale capsules explicitly and proving the origin of every retained fact.
|
|
43
|
+
- **Bounded Size Budget**: Establish deterministic size limits and priority ordering to guarantee compact context payloads without silent truncation of safety invariants.
|
|
44
|
+
- **Secret Prohibition**: Enforce non-waivable rejection of credential patterns, API keys, and environment secret values within capsule artifacts.
|
|
45
|
+
|
|
46
|
+
### Non-Goals
|
|
47
|
+
- Gemstack is **NOT** a vector database, embedding store, or semantic search service.
|
|
48
|
+
- Gemstack does **NOT** build a general-purpose agent memory server or multi-session chat archive.
|
|
49
|
+
- Gemstack does **NOT** perform lossy heuristic AI summarization as its canonical machine representation.
|
|
50
|
+
- Gemstack does **NOT** autonomously declare project closure through the capsule.
|
|
51
|
+
- Gemstack does **NOT** implement agent swarm orchestration, visual QA, screenshot review, or browser automation under Upgrade D.
|
|
52
|
+
- Gemstack does **NOT** replace or duplicate git version control or repository file trees.
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## 3. Core Architectural Principles & Invariants
|
|
57
|
+
|
|
58
|
+
```text
|
|
59
|
+
================================================================================
|
|
60
|
+
UPGRADE D CANONICAL SAFETY INVARIANTS
|
|
61
|
+
================================================================================
|
|
62
|
+
1. context capsule = derived continuation context
|
|
63
|
+
2. context capsule ≠ canonical project authority
|
|
64
|
+
3. less text ≠ less constraint
|
|
65
|
+
4. authoritative artifact > derived capsule (source always wins)
|
|
66
|
+
5. chat transcript ≠ project authority
|
|
67
|
+
6. verification ≠ capsule regeneration (VERIFY = VALIDATE)
|
|
68
|
+
7. closed decision ≠ open question
|
|
69
|
+
8. deferred work ≠ forgotten scope
|
|
70
|
+
9. offline purity = zero network / zero paid API calls
|
|
71
|
+
10. size pressure overflow = FAIL-CLOSED (no silent invariant drops)
|
|
72
|
+
================================================================================
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Central Invariant 1: Derived Continuation Context
|
|
76
|
+
The Context Capsule is a compiled projection of truth, never the source of truth:
|
|
77
|
+
```text
|
|
78
|
+
Authoritative Sources (spec.md, plan.md, tasks.md, contracts, closure.json)
|
|
79
|
+
│
|
|
80
|
+
▼ (Deterministic Generation)
|
|
81
|
+
Context Capsule (context-capsule.json)
|
|
82
|
+
│
|
|
83
|
+
▼ (Continuation Context)
|
|
84
|
+
New AI Session / Developer Workflow
|
|
85
|
+
```
|
|
86
|
+
If any contradiction exists between `context-capsule.json` and an authoritative artifact, the **authoritative artifact unconditionally prevails**.
|
|
87
|
+
|
|
88
|
+
### Central Invariant 2: Semantic Constraint Losslessness
|
|
89
|
+
Compression means omitting redundant explanation, conversational padding, and transient execution traces. It **never** permits omitting, softening, or generalizing a normative requirement (`MUST`, `MUST NOT`, `REQUIRED`, `FORBIDDEN`).
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## 4. Bootstrap Architecture Contracts
|
|
94
|
+
|
|
95
|
+
This specification declares its frozen architectural contracts under the Upgrade A `FrozenContractRegistry`:
|
|
96
|
+
|
|
97
|
+
```gemstack-contracts
|
|
98
|
+
[
|
|
99
|
+
{
|
|
100
|
+
"id": "zero-dependency-core",
|
|
101
|
+
"type": "BOOLEAN_INVARIANT",
|
|
102
|
+
"value": true,
|
|
103
|
+
"description": "Upgrade D implementation must introduce zero external production npm dependencies, using Node.js built-ins exclusively."
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
"id": "capsule-is-derived-not-authority",
|
|
107
|
+
"type": "BOOLEAN_INVARIANT",
|
|
108
|
+
"value": true,
|
|
109
|
+
"description": "The context capsule is strictly a derived projection; authoritative artifacts always override capsule content in case of divergence."
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
"id": "compression-preserves-semantic-constraints",
|
|
113
|
+
"type": "BOOLEAN_INVARIANT",
|
|
114
|
+
"value": true,
|
|
115
|
+
"description": "Context compression must never drop, weaken, or generalize normative MUST/MUST NOT behavioral constraints or frozen contracts."
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
"id": "verify-never-regenerates-capsule",
|
|
119
|
+
"type": "BOOLEAN_INVARIANT",
|
|
120
|
+
"value": true,
|
|
121
|
+
"description": "gemstack verify must operate in read-only mode, validating capsule freshness without silently regenerating or mutating files on disk."
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
"id": "capsule-secrets-forbidden",
|
|
125
|
+
"type": "BOOLEAN_INVARIANT",
|
|
126
|
+
"value": true,
|
|
127
|
+
"description": "Context capsules must never contain credential tokens, private keys, API secrets, or ambient environment variable values."
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
"id": "capsule-offline-deterministic",
|
|
131
|
+
"type": "BOOLEAN_INVARIANT",
|
|
132
|
+
"value": true,
|
|
133
|
+
"description": "Canonical context capsule generation and validation must execute completely offline with deterministic output given identical inputs."
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
"id": "capsule-size-budget-fail-closed",
|
|
137
|
+
"type": "BOOLEAN_INVARIANT",
|
|
138
|
+
"value": true,
|
|
139
|
+
"description": "Exceeding the maximum capsule byte budget must fail closed with an explicit finding rather than silently dropping constraints."
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
"id": "legacy-capsule-compatibility",
|
|
143
|
+
"type": "BOOLEAN_INVARIANT",
|
|
144
|
+
"value": true,
|
|
145
|
+
"description": "Existing repositories and features lacking context capsules operate cleanly with informational notices and zero false blockers."
|
|
146
|
+
}
|
|
147
|
+
]
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## 5. Canonical Terminology
|
|
153
|
+
|
|
154
|
+
| Term | Canonical Meaning |
|
|
155
|
+
| :--- | :--- |
|
|
156
|
+
| **`ContextCapsule`** | The canonical, versioned, machine-readable JSON artifact (`context-capsule.json`) containing the minimal authoritative state needed to continue engineering work. |
|
|
157
|
+
| **`ContinuationContext`** | The structured payload consumed by a new agent, model, or human developer to resume a project without conversational history replay. |
|
|
158
|
+
| **`AuthoritativeSource`** | A primary, version-controlled project artifact (`spec.md`, `plan.md`, `tasks.md`, `state.json`, `closure.json`) whose contents define normative reality. |
|
|
159
|
+
| **`SemanticCompression`** | The deterministic process of eliminating structural redundancy, conversational narrative, and historical churn while retaining 100% of behavioral constraints. |
|
|
160
|
+
| **`ProvenanceDigest`** | A deterministic cryptographic record mapping every section and constraint in the capsule to the exact SHA-256 hash of its source artifact. |
|
|
161
|
+
| **`SourceSetHash`** | The aggregate SHA-256 digest of all authoritative input artifacts evaluated during capsule generation. |
|
|
162
|
+
| **`CapsuleFreshness`** | The Boolean condition indicating that the capsule's recorded `source_set_hash` exactly matches the current live state of authoritative sources. |
|
|
163
|
+
| **`SizeBudget`** | A deterministic byte boundary (default target: 32 KB, hard limit: 64 KB) guaranteeing bounded context ingestion without silent constraint omission. |
|
|
164
|
+
| **`DerivedNarrative`** | An optional human-readable markdown rendering (`context-capsule.md`) compiled strictly from the canonical JSON artifact. |
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
## 6. Authority Model & Source-of-Truth Hierarchy
|
|
169
|
+
|
|
170
|
+
Upgrade D establishes a non-circular, strictly ordered hierarchy of project authority:
|
|
171
|
+
|
|
172
|
+
```text
|
|
173
|
+
+-------------------------------------------------------------------------------+
|
|
174
|
+
| AUTHORITY HIERARCHY |
|
|
175
|
+
+-------------------------------------------------------------------------------+
|
|
176
|
+
| Level 1: Specification (spec.md) --> Canonical Requirements |
|
|
177
|
+
| Level 2: Technical Plan (plan.md) --> Architecture & Gate Bindings|
|
|
178
|
+
| Level 3: Task Execution List (tasks.md) --> Traceability & Tasks State |
|
|
179
|
+
| Level 4: Project State (.gemstack/state.json) --> Lifecycle Phase & Hashes |
|
|
180
|
+
| Level 5: Closure Evidence (closure.json) --> Mechanical Proof (Not Auth) |
|
|
181
|
+
| Level 6: Implementation Source Files --> Runtime Behavior |
|
|
182
|
+
| Level 7: Context Capsule (context-capsule.json)--> DERIVED CONTINUATION ONLY |
|
|
183
|
+
+-------------------------------------------------------------------------------+
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### Precedence Rule
|
|
187
|
+
If a field in `context-capsule.json` asserts that a task is complete, but `tasks.md` indicates it is incomplete, **`tasks.md` governs**.
|
|
188
|
+
If the capsule omits a safety invariant declared in `spec.md`, **`spec.md` governs**.
|
|
189
|
+
Downstream tooling MUST NOT use the capsule to override or amend any Level 1–6 artifact.
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
## 7. Context Capsule Artifact Model
|
|
194
|
+
|
|
195
|
+
### 7.1 Location and Granularity
|
|
196
|
+
- **Active Feature Capsule**: Stored at `specs/<feature>/context-capsule.json`.
|
|
197
|
+
- **Project Root Capsule**: When all active specs are shipped, an aggregated root capsule may optionally reside at `.gemstack/context-capsule.json`.
|
|
198
|
+
- **Naming Rule**: Exactly one canonical machine artifact per active feature directory: `context-capsule.json`.
|
|
199
|
+
- **Human-Readable Companion**: A derived markdown file `specs/<feature>/context-capsule.md` may be generated purely as a read-only convenience for developers. It carries no independent authority.
|
|
200
|
+
|
|
201
|
+
### 7.2 Manual Mutation Protection
|
|
202
|
+
If a user or external script edits `context-capsule.json` directly:
|
|
203
|
+
1. The internal content digest will mismatch or the recorded `source_set_hash` will fail reconciliation against source files.
|
|
204
|
+
2. `gemstack verify` flags the anomaly as `CONTEXT_CAPSULE_STALE` or `CONTEXT_CAPSULE_INVALID`.
|
|
205
|
+
3. The capsule is regenerated exclusively through the explicit generation command.
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
## 8. Canonical Input Sources & Exclusions
|
|
210
|
+
|
|
211
|
+
### Permitted Authoritative Inputs
|
|
212
|
+
The capsule compiler ingests strictly the following artifacts:
|
|
213
|
+
1. **Active Spec**: `specs/<feature>/spec.md` (requirements, `gemstack-contracts`, `gemstack-test-matrix`).
|
|
214
|
+
2. **Active Plan**: `specs/<feature>/plan.md` (architectural boundaries, `gemstack-test-bindings`, `gemstack-closure-gates`).
|
|
215
|
+
3. **Active Tasks**: `specs/<feature>/tasks.md` (task statuses `T001`..`Tn`, validation flags, file targets).
|
|
216
|
+
4. **Project Lifecycle State**: `.gemstack/state.json` (current phase, active spec, phase hashes).
|
|
217
|
+
5. **Closure Evidence (if present)**: `specs/<feature>/closure.json` (status, verified test counts, gate results).
|
|
218
|
+
6. **Cost Ledger (if present)**: `cost-ledger.json` (provider types, cost classifications, currencies).
|
|
219
|
+
7. **Shipped Historical Features**: Digest summary of completed features from `.gemstack/state.json` (`last_completed_feature`).
|
|
220
|
+
|
|
221
|
+
### Strictly Excluded Inputs
|
|
222
|
+
The compiler MUST NOT ingest:
|
|
223
|
+
- Chat logs, IDE prompts, or conversational transcripts.
|
|
224
|
+
- Entire git commit histories, patch logs, or git blame records.
|
|
225
|
+
- Raw test runner standard output or verbose TAP traces (closure summary is used instead).
|
|
226
|
+
- Full source code trees or large module copies (file paths and interface signatures only).
|
|
227
|
+
- Temporary files, build outputs, or `node_modules`.
|
|
228
|
+
- Local configuration secrets, `.env` files, or shell credential variables.
|
|
229
|
+
|
|
230
|
+
---
|
|
231
|
+
|
|
232
|
+
## 9. Source-of-Truth Matrix
|
|
233
|
+
|
|
234
|
+
| Concept | Primary Authoritative Source | Secondary Source | Capsule Status |
|
|
235
|
+
| :--- | :--- | :--- | :--- |
|
|
236
|
+
| **Requirements & Invariants** | `spec.md` | N/A | Derived summary |
|
|
237
|
+
| **Architecture & Bindings** | `plan.md` | N/A | Derived summary |
|
|
238
|
+
| **Tasks & Completion Status** | `tasks.md` | N/A | Derived array |
|
|
239
|
+
| **Frozen Contracts** | `spec.md` / `plan.md` blocks | `.gemstack/state.json` | Derived IDs & hashes |
|
|
240
|
+
| **Acceptance Matrix** | `spec.md` (`gemstack-test-matrix`) | N/A | Derived ID list |
|
|
241
|
+
| **Closure Status & Evidence** | `closure.json` | N/A | Derived status |
|
|
242
|
+
| **Lifecycle Phase & State** | `.gemstack/state.json` | N/A | Derived field |
|
|
243
|
+
| **Provider & Cost Policies** | `cost-ledger.json` | `spec.md` | Derived classification |
|
|
244
|
+
| **Historical Upgrades** | Shipped spec directories | `.gemstack/state.json` | Compressed reference |
|
|
245
|
+
|
|
246
|
+
---
|
|
247
|
+
|
|
248
|
+
## 10. Context Capsule JSON Schema
|
|
249
|
+
|
|
250
|
+
The canonical artifact `context-capsule.json` conforms to version 1 of the Gemstack Context Capsule Schema:
|
|
251
|
+
|
|
252
|
+
```json
|
|
253
|
+
{
|
|
254
|
+
"$schema": "https://gemstack.dev/schemas/context-capsule-v1.json",
|
|
255
|
+
"schema_version": 1,
|
|
256
|
+
"generated_at": "2026-09-11T18:00:00.000Z",
|
|
257
|
+
"generator": {
|
|
258
|
+
"name": "gemstack",
|
|
259
|
+
"version": "1.2.0"
|
|
260
|
+
},
|
|
261
|
+
"provenance": {
|
|
262
|
+
"source_set_hash": "a1b2c3d4e5f6...",
|
|
263
|
+
"sources": [
|
|
264
|
+
{
|
|
265
|
+
"path": "specs/009-context-capsule/spec.md",
|
|
266
|
+
"hash": "e3b0c44298fc...",
|
|
267
|
+
"role": "SPECIFICATION"
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
"path": "specs/009-context-capsule/plan.md",
|
|
271
|
+
"hash": "f2ca1bb6c7e9...",
|
|
272
|
+
"role": "PLAN"
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
"path": "specs/009-context-capsule/tasks.md",
|
|
276
|
+
"hash": "38b060a751ac...",
|
|
277
|
+
"role": "TASKS"
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
"path": ".gemstack/state.json",
|
|
281
|
+
"hash": "7d9b5e82104f...",
|
|
282
|
+
"role": "LIFECYCLE_STATE"
|
|
283
|
+
}
|
|
284
|
+
]
|
|
285
|
+
},
|
|
286
|
+
"project": {
|
|
287
|
+
"name": "gemstack-ai",
|
|
288
|
+
"active_feature": "specs/009-context-capsule",
|
|
289
|
+
"current_phase": "specification",
|
|
290
|
+
"lifecycle_status": "SPEC_COMPLETE",
|
|
291
|
+
"next_permitted_phase": "PLAN"
|
|
292
|
+
},
|
|
293
|
+
"historical_context": [
|
|
294
|
+
{
|
|
295
|
+
"feature": "specs/006-architecture-consistency-engine",
|
|
296
|
+
"status": "CLOSED",
|
|
297
|
+
"key_guarantees": ["Frozen contracts", "Deterministic hashing", "Anti-loop findings"]
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
"feature": "specs/007-mechanical-test-matrix-closure-evidence",
|
|
301
|
+
"status": "CLOSED",
|
|
302
|
+
"key_guarantees": ["Mechanical test matrix", "VERIFY = VALIDATE", "closure.json evidence"]
|
|
303
|
+
},
|
|
304
|
+
{
|
|
305
|
+
"feature": "specs/008-cost-provider-safety-gates",
|
|
306
|
+
"status": "CLOSED",
|
|
307
|
+
"key_guarantees": ["NO PROOF = NO EXECUTION", "Fail-closed gates", "Zero network verify"]
|
|
308
|
+
}
|
|
309
|
+
],
|
|
310
|
+
"architecture_summary": {
|
|
311
|
+
"core_purpose": "Deterministic context compression and safe continuation for AI-assisted engineering.",
|
|
312
|
+
"critical_boundaries": [
|
|
313
|
+
"Capsule is strictly derived, never authoritative",
|
|
314
|
+
"Semantic constraint losslessness: MUST/MUST NOT survive compression",
|
|
315
|
+
"Verification is read-only and never regenerates capsules"
|
|
316
|
+
]
|
|
317
|
+
},
|
|
318
|
+
"canonical_invariants": [
|
|
319
|
+
{
|
|
320
|
+
"id": "INV-001",
|
|
321
|
+
"rule": "CONTEXT CAPSULE = DERIVED CONTINUATION CONTEXT, NOT CANONICAL AUTHORITY",
|
|
322
|
+
"normative": "MUST",
|
|
323
|
+
"source_ref": "spec.md#3"
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
"id": "INV-002",
|
|
327
|
+
"rule": "Compression must preserve 100% of behavior-affecting constraints and frozen contracts",
|
|
328
|
+
"normative": "MUST",
|
|
329
|
+
"source_ref": "spec.md#3"
|
|
330
|
+
},
|
|
331
|
+
{
|
|
332
|
+
"id": "INV-003",
|
|
333
|
+
"rule": "gemstack verify must never regenerate or mutate context-capsule.json",
|
|
334
|
+
"normative": "MUST_NOT",
|
|
335
|
+
"source_ref": "spec.md#3"
|
|
336
|
+
}
|
|
337
|
+
],
|
|
338
|
+
"frozen_contracts": [
|
|
339
|
+
{
|
|
340
|
+
"id": "zero-dependency-core",
|
|
341
|
+
"type": "BOOLEAN_INVARIANT",
|
|
342
|
+
"value": true
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
"id": "capsule-is-derived-not-authority",
|
|
346
|
+
"type": "BOOLEAN_INVARIANT",
|
|
347
|
+
"value": true
|
|
348
|
+
}
|
|
349
|
+
],
|
|
350
|
+
"acceptance_matrix": {
|
|
351
|
+
"total_required": 20,
|
|
352
|
+
"signature": "b4c8a2e190df...",
|
|
353
|
+
"canonical_ids": [
|
|
354
|
+
"TEST-CONTEXT-A01",
|
|
355
|
+
"TEST-CONTEXT-A02",
|
|
356
|
+
"TEST-CONTEXT-H01"
|
|
357
|
+
]
|
|
358
|
+
},
|
|
359
|
+
"tasks_state": {
|
|
360
|
+
"total": 20,
|
|
361
|
+
"completed": 0,
|
|
362
|
+
"in_progress": null,
|
|
363
|
+
"active_task_ids": ["T001", "T002"]
|
|
364
|
+
},
|
|
365
|
+
"relevant_files": [
|
|
366
|
+
"src/lib/context-capsule.js",
|
|
367
|
+
"tests/context-capsule.test.js"
|
|
368
|
+
],
|
|
369
|
+
"deferred_items": [
|
|
370
|
+
"Autonomous cross-repo capsule federations (out of scope)",
|
|
371
|
+
"LLM narrative fine-tuning (non-authoritative)"
|
|
372
|
+
],
|
|
373
|
+
"unresolved_blockers": []
|
|
374
|
+
}
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
---
|
|
378
|
+
|
|
379
|
+
## 11. Required Semantic Content
|
|
380
|
+
|
|
381
|
+
To guarantee that a downstream agent receives complete continuation guidance, the capsule MUST contain:
|
|
382
|
+
1. **Provenance & Source Digest**: Full array of source artifact paths and SHA-256 hashes.
|
|
383
|
+
2. **Project Lifecycle Snapshot**: Name, active spec, current phase, lifecycle status, next permitted phase.
|
|
384
|
+
3. **Closed Upgrades Summary**: 1-to-2 line summaries of prior closed features and their permanent invariants.
|
|
385
|
+
4. **Canonical Invariants**: All `MUST` and `MUST NOT` constraints with source cross-references.
|
|
386
|
+
5. **Frozen Contracts**: Canonical contract IDs, types, and values from active specs.
|
|
387
|
+
6. **Acceptance Matrix Summary**: Total required tests, acceptance signature, and canonical ID list.
|
|
388
|
+
7. **Task Inventory State**: Task counts, completion numbers, active task IDs.
|
|
389
|
+
8. **Relevant File Surface**: Explicit list of implementation and test files mapped in the plan.
|
|
390
|
+
9. **Explicit Deferred Scope**: What is deliberately delayed to prevent accidental re-implementation.
|
|
391
|
+
10. **Active Blockers Only**: Genuinely unresolved architectural questions or blocking issues (empty if none).
|
|
392
|
+
|
|
393
|
+
---
|
|
394
|
+
|
|
395
|
+
## 12. Semantic Compression vs Textual Losslessness
|
|
396
|
+
|
|
397
|
+
Context compression in Gemstack operates on the principle of **Semantic Constraint Losslessness**:
|
|
398
|
+
- **Discarded Without Loss**:
|
|
399
|
+
- Conversational preamble, rhetorical explanations, and tutorials.
|
|
400
|
+
- Multi-paragraph problem background already resolved in prior features.
|
|
401
|
+
- Historical alternative approaches discarded during planning.
|
|
402
|
+
- Intermediate test runner debug traces and raw stdout dumps.
|
|
403
|
+
- **Preserved with Mathematical Exactness**:
|
|
404
|
+
- Exact canonical identifiers (`TEST-CONTEXT-A01`, `T001`, `zero-dependency-core`).
|
|
405
|
+
- Strict normative rules containing `MUST`, `MUST NOT`, `REQUIRED`, `FORBIDDEN`.
|
|
406
|
+
- Machine-readable enums, boolean invariants, and cryptographic hashes.
|
|
407
|
+
- Exact file paths for implementation and test surfaces.
|
|
408
|
+
|
|
409
|
+
---
|
|
410
|
+
|
|
411
|
+
## 13. Closed Work Summarization vs Active Work Context
|
|
412
|
+
|
|
413
|
+
| Dimension | Active Feature (`specs/current/`) | Shipped / Closed Features |
|
|
414
|
+
| :--- | :--- | :--- |
|
|
415
|
+
| **Detail Level** | Granular tasks, exact canonical IDs, active files | High-level summary, key guarantees, status token |
|
|
416
|
+
| **Tasks State** | Itemized `T001`..`Tn` status and dependencies | Total task count only (e.g. `20/20 COMPLETE`) |
|
|
417
|
+
| **Acceptance Matrix**| Complete canonical test list and pass criteria | Count of passed tests and acceptance signature |
|
|
418
|
+
| **Invariants** | Full verbatim normative statements | Persistent architectural rules inherited by repo |
|
|
419
|
+
| **Primary Goal** | Direct execution and validation | Guard against architectural regressions |
|
|
420
|
+
|
|
421
|
+
---
|
|
422
|
+
|
|
423
|
+
## 14. Explicit Deferred Items vs Forgotten Scope
|
|
424
|
+
|
|
425
|
+
A recurring failure mode in AI-assisted coding is treating a deliberate deferral as forgotten work. The Context Capsule preserves an explicit `deferred_items` array:
|
|
426
|
+
- Entries are categorized as:
|
|
427
|
+
1. `UPGRADE_DEFERRED`: Explicitly allocated to a future phase (e.g. Upgrade E).
|
|
428
|
+
2. `NON_GOAL`: Explicitly out of scope for the framework.
|
|
429
|
+
- Any downstream agent consuming the capsule is explicitly forbidden from generating implementation tasks for items listed in `deferred_items`.
|
|
430
|
+
|
|
431
|
+
---
|
|
432
|
+
|
|
433
|
+
## 15. Provenance & Source Fingerprinting Model
|
|
434
|
+
|
|
435
|
+
To prove provenance, every Context Capsule embeds a `provenance` block:
|
|
436
|
+
```json
|
|
437
|
+
{
|
|
438
|
+
"source_set_hash": "<canonical SHA-256>",
|
|
439
|
+
"sources": [
|
|
440
|
+
{ "path": "specs/<feat>/spec.md", "hash": "<sha256>", "role": "SPECIFICATION" },
|
|
441
|
+
{ "path": "specs/<feat>/plan.md", "hash": "<sha256>", "role": "PLAN" },
|
|
442
|
+
{ "path": "specs/<feat>/tasks.md", "hash": "<sha256>", "role": "TASKS" },
|
|
443
|
+
{ "path": ".gemstack/state.json", "hash": "<sha256>", "role": "LIFECYCLE_STATE" }
|
|
444
|
+
]
|
|
445
|
+
}
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
### Provenance Verification Rule
|
|
449
|
+
`source_set_hash` is computed by hashing the UTF-16 code-unit sorted JSON serialization of all normalized `{ path, hash }` pairs.
|
|
450
|
+
During verification, `gemstack verify` re-computes current file hashes on disk. If any current hash differs from the recorded source hash, the capsule is immediately declared **STALE**.
|
|
451
|
+
|
|
452
|
+
---
|
|
453
|
+
|
|
454
|
+
## 16. Deterministic Hashing & Serialization
|
|
455
|
+
|
|
456
|
+
To ensure that two runs over identical repository states produce byte-for-byte identical capsules:
|
|
457
|
+
1. **Key Sorting**: All JSON object keys are sorted recursively by UTF-16 code units (`(a < b ? -1 : (a > b ? 1 : 0))`).
|
|
458
|
+
2. **Array Normalization**: Array items with natural keys (`sources`, `canonical_invariants`, `frozen_contracts`, `canonical_ids`) are sorted deterministically by their primary identifier.
|
|
459
|
+
3. **Line Endings**: Formatted with standard POSIX newline (`\n`) indentation of 2 spaces.
|
|
460
|
+
4. **Volatile Field Exclusion**: Generation timestamps (`generated_at`) are excluded from semantic hash calculations.
|
|
461
|
+
5. **Path Normalization**: All paths are POSIX-normalized repository-relative strings without drive letters (`C:`) or backslashes (`\\`).
|
|
462
|
+
|
|
463
|
+
---
|
|
464
|
+
|
|
465
|
+
## 17. Freshness Lifecycle & Invalidation Rules
|
|
466
|
+
|
|
467
|
+
```text
|
|
468
|
+
[ Authoritative Sources Mutated ] ────► [ Source Set Hash Mismatch ]
|
|
469
|
+
│
|
|
470
|
+
▼
|
|
471
|
+
[ Capsule Becomes STALE ]
|
|
472
|
+
│
|
|
473
|
+
▼
|
|
474
|
+
[ Verification Emits Error ]
|
|
475
|
+
│
|
|
476
|
+
▼
|
|
477
|
+
[ Explicit "gemstack context generate" Required ]
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
A capsule is invalidated and becomes `STALE` if:
|
|
481
|
+
1. `spec.md` is edited or amended.
|
|
482
|
+
2. `plan.md` architectural bindings change.
|
|
483
|
+
3. `tasks.md` task list or completion checkboxes are updated.
|
|
484
|
+
4. `.gemstack/state.json` lifecycle phase or active spec transitions.
|
|
485
|
+
5. `closure.json` is regenerated or collected.
|
|
486
|
+
|
|
487
|
+
---
|
|
488
|
+
|
|
489
|
+
## 18. Capsule Validity States
|
|
490
|
+
|
|
491
|
+
| State | Definition | Verification Behavior |
|
|
492
|
+
| :--- | :--- | :--- |
|
|
493
|
+
| **`VALID`** | Schema matches, all source hashes match disk, size within budget, zero secrets. | Passes with exit code 0. |
|
|
494
|
+
| **`STALE`** | One or more authoritative source hashes on disk differ from `provenance.sources`. | Emits `CONTEXT_CAPSULE_STALE` blocker. |
|
|
495
|
+
| **`INVALID`** | JSON malformed, schema version unsupported, or required invariant missing. | Emits `CONTEXT_CAPSULE_INVALID` blocker. |
|
|
496
|
+
| **`MISSING`** | Capsule artifact not found in an active feature requiring continuation context. | Emits `CONTEXT_CAPSULE_MISSING` (warning in dev, blocker at ship). |
|
|
497
|
+
|
|
498
|
+
---
|
|
499
|
+
|
|
500
|
+
## 19. Size Budget, Thresholds & Overflow Behavior
|
|
501
|
+
|
|
502
|
+
### Size Parameters
|
|
503
|
+
- **Target Budget**: `≤ 32,768 bytes` (32 KB) serialized JSON.
|
|
504
|
+
- **Hard Upper Limit**: `65,536 bytes` (64 KB).
|
|
505
|
+
|
|
506
|
+
### Deterministic Priority Model Under Pressure
|
|
507
|
+
If content exceeds the target budget, non-normative sections are condensed according to strict priority order:
|
|
508
|
+
1. **Priority 1 (IMMUTABLE - NEVER CONDENSED)**:
|
|
509
|
+
- Authority model & source references.
|
|
510
|
+
- Core safety invariants and `MUST` / `MUST NOT` constraints.
|
|
511
|
+
- Frozen architecture contracts.
|
|
512
|
+
- Current lifecycle phase and status.
|
|
513
|
+
2. **Priority 2 (STRUCTURAL SUMMARY)**:
|
|
514
|
+
- Acceptance IDs (condense descriptions, keep exact IDs).
|
|
515
|
+
- Task inventory (keep counts and active IDs, omit completed descriptions).
|
|
516
|
+
- Implementation file list.
|
|
517
|
+
3. **Priority 3 (TRUNCATION PERMITTED)**:
|
|
518
|
+
- Historical feature narratives (reduce to ID and status token).
|
|
519
|
+
- Optional human notes.
|
|
520
|
+
|
|
521
|
+
### Overflow Fail-Closed Rule
|
|
522
|
+
If Priority 1 and Priority 2 contents alone exceed the hard limit of 64 KB, the generator **MUST NOT** drop constraints. It halts with error:
|
|
523
|
+
`CONTEXT_CAPSULE_TOO_LARGE: Critical invariants exceed capsule size budget (65536 bytes).`
|
|
524
|
+
|
|
525
|
+
---
|
|
526
|
+
|
|
527
|
+
## 20. Secrets & Privacy Protection Boundary
|
|
528
|
+
|
|
529
|
+
Context capsules must never leak credentials:
|
|
530
|
+
- **Forbidden Properties**: Same strict list as Upgrade C: `apiKey`, `api_key`, `token`, `accessToken`, `access_token`, `secret`, `clientSecret`, `password`, `credentials`.
|
|
531
|
+
- **Forbidden Patterns**: Regex detection for API keys (`sk-...`, `ghp_...`, `AIza...`, private keys).
|
|
532
|
+
- **Environment Exclusions**: Never inspect or serialize `.env` file contents into the capsule.
|
|
533
|
+
- **Fail-Closed Rejection**: Detecting any secret pattern emits non-waivable blocker `CONTEXT_CAPSULE_SECRET_DETECTED`.
|
|
534
|
+
|
|
535
|
+
---
|
|
536
|
+
|
|
537
|
+
## 21. Generation Semantics
|
|
538
|
+
|
|
539
|
+
### Explicit Generation Operation
|
|
540
|
+
Capsules are generated exclusively via an explicit command (e.g. `gemstack context generate`):
|
|
541
|
+
1. Loads active `spec.md`, `plan.md`, `tasks.md`, and `.gemstack/state.json`.
|
|
542
|
+
2. Evaluates and extracts structured invariants, contracts, acceptance IDs, and tasks.
|
|
543
|
+
3. Computes exact SHA-256 hashes of all ingested files.
|
|
544
|
+
4. Constructs canonical JSON object and validates against schema.
|
|
545
|
+
5. Scans generated object for forbidden secret patterns.
|
|
546
|
+
6. Enforces size budget limits.
|
|
547
|
+
7. Writes `context-capsule.json` atomically.
|
|
548
|
+
|
|
549
|
+
### Non-Interference
|
|
550
|
+
The generation command:
|
|
551
|
+
- Does NOT mutate `spec.md`, `plan.md`, or `tasks.md`.
|
|
552
|
+
- Does NOT change project lifecycle phases.
|
|
553
|
+
- Does NOT execute test suites or make network calls.
|
|
554
|
+
|
|
555
|
+
---
|
|
556
|
+
|
|
557
|
+
## 22. Verification Semantics (`VERIFY = VALIDATE`)
|
|
558
|
+
|
|
559
|
+
In strict accordance with Upgrade B and C invariants:
|
|
560
|
+
- `gemstack verify` evaluates existing `context-capsule.json` in **READ-ONLY** mode.
|
|
561
|
+
- `gemstack verify` **NEVER**:
|
|
562
|
+
1. Regenerates `context-capsule.json`.
|
|
563
|
+
2. Updates source hashes to mask file drift.
|
|
564
|
+
3. Executes remote AI calls to summarize missing text.
|
|
565
|
+
4. Writes or mutates any file on disk.
|
|
566
|
+
|
|
567
|
+
---
|
|
568
|
+
|
|
569
|
+
## 23. Consumer Trust & Continuation Workflow
|
|
570
|
+
|
|
571
|
+
Downstream AI agents and tools must adhere to the following consumer protocol:
|
|
572
|
+
|
|
573
|
+
```text
|
|
574
|
+
[ Start Continuation Session ]
|
|
575
|
+
│
|
|
576
|
+
▼
|
|
577
|
+
1. Does context-capsule.json exist and pass verify?
|
|
578
|
+
├─► (NO / STALE) ──► DO NOT TRUST CAPSULE.
|
|
579
|
+
│ Read authoritative spec.md, plan.md, tasks.md directly.
|
|
580
|
+
│
|
|
581
|
+
└─► (YES: VALID) ──► Load context-capsule.json into memory.
|
|
582
|
+
│
|
|
583
|
+
▼
|
|
584
|
+
2. Check "current_phase" and "next_permitted_phase".
|
|
585
|
+
Adhere strictly to permitted actions (e.g. do not implement if in PLAN phase).
|
|
586
|
+
│
|
|
587
|
+
▼
|
|
588
|
+
3. Enforce all "canonical_invariants" and "frozen_contracts".
|
|
589
|
+
Never propose designs contradicting listed invariants.
|
|
590
|
+
│
|
|
591
|
+
▼
|
|
592
|
+
4. If deep implementation details are needed, consult "relevant_files"
|
|
593
|
+
or reference "source_ref" pointers directly.
|
|
594
|
+
```
|
|
595
|
+
|
|
596
|
+
---
|
|
597
|
+
|
|
598
|
+
## 24. LLM Involvement Policy & Offline Guarantees
|
|
599
|
+
|
|
600
|
+
- **Canonical Machine Artifact**: `context-capsule.json` is generated **100% algorithmically** via deterministic parsing of structured Gemstack markdown blocks and JSON state files. It requires **zero LLM invocation**.
|
|
601
|
+
- **Offline Guarantee**: Generation and verification execute 100% offline without internet access, external APIs, or local model daemons.
|
|
602
|
+
- **Optional Narrative Helper**: If an optional human-readable prose summary is requested via an AI adapter:
|
|
603
|
+
- It MUST pass through Upgrade C `ProviderCapabilityGate` and `BillableActionGate`.
|
|
604
|
+
- It is saved strictly as an advisory companion (`context-capsule.md`).
|
|
605
|
+
- It carries zero verification authority.
|
|
606
|
+
|
|
607
|
+
---
|
|
608
|
+
|
|
609
|
+
## 25. Planned CLI Surface (Specification Only)
|
|
610
|
+
|
|
611
|
+
*Note: This section defines the target interface for future planning and implementation. No CLI code is created during this SPEC phase.*
|
|
612
|
+
|
|
613
|
+
```text
|
|
614
|
+
gemstack context generate [--target <dir>] [--feature <path>]
|
|
615
|
+
--> Compiles authoritative sources into context-capsule.json atomically.
|
|
616
|
+
|
|
617
|
+
gemstack context show [--target <dir>] [--json]
|
|
618
|
+
--> Displays structured continuation summary or raw JSON.
|
|
619
|
+
|
|
620
|
+
gemstack context verify [--target <dir>]
|
|
621
|
+
--> Performs read-only validation of capsule schema, provenance, and freshness.
|
|
622
|
+
```
|
|
623
|
+
|
|
624
|
+
Integration into existing commands:
|
|
625
|
+
- `gemstack verify`: Automatically audits `context-capsule.json` freshness and integrity in Stage 5/6.
|
|
626
|
+
|
|
627
|
+
---
|
|
628
|
+
|
|
629
|
+
## 26. Legacy Compatibility & Progressive Adoption
|
|
630
|
+
|
|
631
|
+
- **Legacy Mode**: Projects lacking `context-capsule.json` log an informational notice:
|
|
632
|
+
`[INFO] [LEGACY] No se detectó context-capsule.json (Modo Legacy Context-Free).`
|
|
633
|
+
- **Zero Blocker Guarantee**: An unconfigured or legacy repository without capsules exits `gemstack verify` with code 0 and 0 errors.
|
|
634
|
+
- **Feature Opt-In**: A feature explicitly declaring Upgrade D contracts enforces capsule freshness at closure verification.
|
|
635
|
+
|
|
636
|
+
---
|
|
637
|
+
|
|
638
|
+
## 27. Relationship with Prior Upgrades
|
|
639
|
+
|
|
640
|
+
- **Upgrade A (Architecture Consistency Engine)**:
|
|
641
|
+
- Upgrade D uses `src/lib/hasher.js` for deterministic SHA-256 computation.
|
|
642
|
+
- Upgrade D findings use `src/lib/findings.js` for 64-char lowercase fingerprints.
|
|
643
|
+
- Frozen contracts from Upgrade A remain byte-for-byte untouched and are summarized in the capsule.
|
|
644
|
+
- **Upgrade B (Mechanical Test Matrix & Closure Evidence)**:
|
|
645
|
+
- Upgrade D preserves `VERIFY = VALIDATE`.
|
|
646
|
+
- Capsule freshness is checked during verification, but `closure.json` remains the sole evidence artifact for test closure.
|
|
647
|
+
- `context-capsule.json` is added to `resolveRelevantFiles` in closure context.
|
|
648
|
+
- **Upgrade C (Cost & Provider Safety Gates)**:
|
|
649
|
+
- Capsule generation is 100% offline and deterministic.
|
|
650
|
+
- If optional future AI summarization is invoked, it is strictly governed by `BillableActionGate` and `ProviderCapabilityGate`.
|
|
651
|
+
- Zero commercial provider calls permitted during verification or canonical generation.
|
|
652
|
+
|
|
653
|
+
---
|
|
654
|
+
|
|
655
|
+
## 28. Canonical Findings Taxonomy (Upgrade D)
|
|
656
|
+
|
|
657
|
+
All findings follow the canonical uppercase format with 64-character lowercase SHA-256 fingerprints:
|
|
658
|
+
|
|
659
|
+
| Finding Code | Severity | Description | Waivable via Exception? |
|
|
660
|
+
| :--- | :--- | :--- | :--- |
|
|
661
|
+
| **`CONTEXT_CAPSULE_MISSING`** | WARNING / BLOCKER | Capsule absent when required for closure. | **NO** |
|
|
662
|
+
| **`CONTEXT_CAPSULE_INVALID`** | BLOCKER | Schema validation or JSON parsing failed. | **NO** |
|
|
663
|
+
| **`CONTEXT_CAPSULE_STALE`** | BLOCKER | Authoritative sources modified since generation. | **NO** |
|
|
664
|
+
| **`CONTEXT_CAPSULE_SOURCE_MISMATCH`** | BLOCKER | Ingested file hash does not match disk hash. | **NO** |
|
|
665
|
+
| **`CONTEXT_CAPSULE_SECRET_DETECTED`** | BLOCKER | Forbidden credential key or secret pattern found. | **NO** |
|
|
666
|
+
| **`CONTEXT_CAPSULE_INVARIANT_DROPPED`** | BLOCKER | Normative MUST/MUST NOT constraint missing. | **NO** |
|
|
667
|
+
| **`CONTEXT_CAPSULE_TOO_LARGE`** | BLOCKER | Content exceeds hard size limit (64 KB). | **NO** |
|
|
668
|
+
| **`CONTEXT_CAPSULE_AUTHORITY_CONFLICT`** | BLOCKER | Capsule asserts state conflicting with source. | **NO** |
|
|
669
|
+
|
|
670
|
+
---
|
|
671
|
+
|
|
672
|
+
## 29. Accepted Exceptions Policy
|
|
673
|
+
|
|
674
|
+
Context capsules represent compiled truth. Suppressing a stale, conflicting, or secret-bearing capsule with an exception would create false architectural certainty.
|
|
675
|
+
Therefore:
|
|
676
|
+
- **Zero Waivable Blocker Policy**: Findings indicating authority conflicts, secret leakage, or stale sources are **STRICTLY NON-WAIVABLE**.
|
|
677
|
+
- The only permissible remediation for a `STALE` or `INVALID` capsule is explicit regeneration from authoritative sources.
|
|
678
|
+
|
|
679
|
+
---
|
|
680
|
+
|
|
681
|
+
## 30. Comprehensive Threat Model & Adversarial Vectors
|
|
682
|
+
|
|
683
|
+
| Threat Vector | Vulnerability Description | Mitigation Architecture |
|
|
684
|
+
| :--- | :--- | :--- |
|
|
685
|
+
| **1. Phantom Task Closure** | Capsule claims a task is complete that `tasks.md` shows unchecked. | Consumer trust rule: Authoritative artifact unconditionally wins; verification detects state mismatch. |
|
|
686
|
+
| **2. Stale Context Drift** | Agent resumes work using capsule generated before major spec refactor. | Provenance digest check compares live SHA-256 hashes on disk; flags `CONTEXT_CAPSULE_STALE`. |
|
|
687
|
+
| **3. Manual Capsule Spoofing** | Developer manually edits capsule to bypass a frozen contract. | Verification compares capsule contracts against source contract blocks; emits `CONTEXT_CAPSULE_AUTHORITY_CONFLICT`. |
|
|
688
|
+
| **4. Silent Invariant Truncation** | Generator drops safety rules to satisfy a byte budget. | Hard failure `CONTEXT_CAPSULE_TOO_LARGE` triggered if Priority 1 constraints exceed budget. |
|
|
689
|
+
| **5. Ambient Secret Exfiltration** | Generator scans `.env` and embeds active tokens into capsule. | Strict input whitelist excludes `.env`; regex scanner rejects secret fields fail-closed. |
|
|
690
|
+
| **6. Verification Side-Effect** | Verify command silently rewrites capsule during CI check. | Verify runs pure read-only checks; zero file writes or mutations permitted. |
|
|
691
|
+
| **7. Conversational Contamination** | Agent prompts or chat transcripts ingested as formal authority. | Strict exclusion of chat logs; only structured markdown and JSON state files ingested. |
|
|
692
|
+
| **8. Machine-Specific Coupling** | Capsule embeds local Windows paths (`C:\\CODES\\...`) breaking Linux CI. | Path normalizer converts all references to POSIX repository-relative paths. |
|
|
693
|
+
| **9. Closed Work Amnesia** | Agent reopens closed Upgrade A architecture discussion. | Closed feature records explicitly enumerate frozen status and permanent invariants. |
|
|
694
|
+
| **10. Deferred Work Misinterpretation**| Agent assumes deferred item is a bug or missing requirement. | `deferred_items` explicitly distinguishes deliberate delay from active tasks. |
|
|
695
|
+
|
|
696
|
+
---
|
|
697
|
+
|
|
698
|
+
## 31. Canonical Acceptance Matrix (TEST-CONTEXT-A01 through TEST-CONTEXT-H01)
|
|
699
|
+
|
|
700
|
+
Upgrade D establishes 20 canonical acceptance test requirements:
|
|
701
|
+
|
|
702
|
+
```gemstack-test-matrix
|
|
703
|
+
[
|
|
704
|
+
{
|
|
705
|
+
"id": "TEST-CONTEXT-A01",
|
|
706
|
+
"category": "DETERMINISM",
|
|
707
|
+
"layer": "UNIT",
|
|
708
|
+
"description": "Generates byte-for-byte identical context-capsule.json across repeated runs on identical repository state.",
|
|
709
|
+
"pass_criteria": "SHA-256 content hashes of two independent generations match 100%.",
|
|
710
|
+
"gate": "REQUIRED"
|
|
711
|
+
},
|
|
712
|
+
{
|
|
713
|
+
"id": "TEST-CONTEXT-A02",
|
|
714
|
+
"category": "DETERMINISM",
|
|
715
|
+
"layer": "UNIT",
|
|
716
|
+
"description": "Enforces strict UTF-16 code-unit key ordering across all JSON objects in generated capsule.",
|
|
717
|
+
"pass_criteria": "Serialized keys match code-unit sorted order deterministically.",
|
|
718
|
+
"gate": "REQUIRED"
|
|
719
|
+
},
|
|
720
|
+
{
|
|
721
|
+
"id": "TEST-CONTEXT-A03",
|
|
722
|
+
"category": "DETERMINISM",
|
|
723
|
+
"layer": "UNIT",
|
|
724
|
+
"description": "Excludes volatile execution timestamps from semantic content hash computation.",
|
|
725
|
+
"pass_criteria": "Modifying generated_at does not alter semantic provenance hash.",
|
|
726
|
+
"gate": "REQUIRED"
|
|
727
|
+
},
|
|
728
|
+
{
|
|
729
|
+
"id": "TEST-CONTEXT-A04",
|
|
730
|
+
"category": "DETERMINISM",
|
|
731
|
+
"layer": "UNIT",
|
|
732
|
+
"description": "Normalizes all file paths to POSIX repository-relative strings without drive letters.",
|
|
733
|
+
"pass_criteria": "No backslashes or absolute drive prefixes present in path properties.",
|
|
734
|
+
"gate": "REQUIRED"
|
|
735
|
+
},
|
|
736
|
+
{
|
|
737
|
+
"id": "TEST-CONTEXT-B01",
|
|
738
|
+
"category": "AUTHORITY",
|
|
739
|
+
"layer": "UNIT",
|
|
740
|
+
"description": "Rejects capsule assertion when it conflicts with authoritative spec.md or plan.md content.",
|
|
741
|
+
"pass_criteria": "Emits CONTEXT_CAPSULE_AUTHORITY_CONFLICT when capsule diverges from source.",
|
|
742
|
+
"gate": "REQUIRED"
|
|
743
|
+
},
|
|
744
|
+
{
|
|
745
|
+
"id": "TEST-CONTEXT-B02",
|
|
746
|
+
"category": "AUTHORITY",
|
|
747
|
+
"layer": "UNIT",
|
|
748
|
+
"description": "Enforces that authoritative artifacts unconditionally override capsule claims in consumer resolver.",
|
|
749
|
+
"pass_criteria": "Resolver returns source artifact value when conflict is detected.",
|
|
750
|
+
"gate": "REQUIRED"
|
|
751
|
+
},
|
|
752
|
+
{
|
|
753
|
+
"id": "TEST-CONTEXT-B03",
|
|
754
|
+
"category": "AUTHORITY",
|
|
755
|
+
"layer": "UNIT",
|
|
756
|
+
"description": "Rejects manually edited capsule whose content hash does not reconcile with source digest.",
|
|
757
|
+
"pass_criteria": "Emits CONTEXT_CAPSULE_STALE upon manual tampering.",
|
|
758
|
+
"gate": "REQUIRED"
|
|
759
|
+
},
|
|
760
|
+
{
|
|
761
|
+
"id": "TEST-CONTEXT-B04",
|
|
762
|
+
"category": "AUTHORITY",
|
|
763
|
+
"layer": "UNIT",
|
|
764
|
+
"description": "Proves chat transcripts and conversational logs are never ingested into capsule sources.",
|
|
765
|
+
"pass_criteria": "Source list contains exclusively structured markdown and JSON state files.",
|
|
766
|
+
"gate": "REQUIRED"
|
|
767
|
+
},
|
|
768
|
+
{
|
|
769
|
+
"id": "TEST-CONTEXT-C01",
|
|
770
|
+
"category": "FRESHNESS",
|
|
771
|
+
"layer": "INTEGRATION",
|
|
772
|
+
"description": "Detects modification of spec.md and marks capsule STALE immediately.",
|
|
773
|
+
"pass_criteria": "Verification fails with CONTEXT_CAPSULE_STALE after touching spec.md.",
|
|
774
|
+
"gate": "REQUIRED"
|
|
775
|
+
},
|
|
776
|
+
{
|
|
777
|
+
"id": "TEST-CONTEXT-C02",
|
|
778
|
+
"category": "FRESHNESS",
|
|
779
|
+
"layer": "INTEGRATION",
|
|
780
|
+
"description": "Detects task status mutation in tasks.md and invalidates capsule freshness.",
|
|
781
|
+
"pass_criteria": "Verification fails with CONTEXT_CAPSULE_STALE after checking a task box.",
|
|
782
|
+
"gate": "REQUIRED"
|
|
783
|
+
},
|
|
784
|
+
{
|
|
785
|
+
"id": "TEST-CONTEXT-C03",
|
|
786
|
+
"category": "FRESHNESS",
|
|
787
|
+
"layer": "UNIT",
|
|
788
|
+
"description": "Preserves VALID status when all authoritative sources match recorded source_set_hash.",
|
|
789
|
+
"pass_criteria": "Verification passes with status VALID when files are untouched.",
|
|
790
|
+
"gate": "REQUIRED"
|
|
791
|
+
},
|
|
792
|
+
{
|
|
793
|
+
"id": "TEST-CONTEXT-D01",
|
|
794
|
+
"category": "CONSTRAINTS",
|
|
795
|
+
"layer": "UNIT",
|
|
796
|
+
"description": "Preserves 100% of MUST and MUST NOT normative constraints from spec.md in canonical_invariants.",
|
|
797
|
+
"pass_criteria": "All normative statements from spec.md exist in capsule without omission.",
|
|
798
|
+
"gate": "REQUIRED"
|
|
799
|
+
},
|
|
800
|
+
{
|
|
801
|
+
"id": "TEST-CONTEXT-D02",
|
|
802
|
+
"category": "CONSTRAINTS",
|
|
803
|
+
"layer": "UNIT",
|
|
804
|
+
"description": "Preserves frozen contracts and closure acceptance IDs across context compression.",
|
|
805
|
+
"pass_criteria": "Exact contract IDs and acceptance signature match source blocks 100%.",
|
|
806
|
+
"gate": "REQUIRED"
|
|
807
|
+
},
|
|
808
|
+
{
|
|
809
|
+
"id": "TEST-CONTEXT-E01",
|
|
810
|
+
"category": "SECURITY",
|
|
811
|
+
"layer": "UNIT",
|
|
812
|
+
"description": "Rejects capsule generation if forbidden credential property is detected.",
|
|
813
|
+
"pass_criteria": "Emits CONTEXT_CAPSULE_SECRET_DETECTED and halts generation fail-closed.",
|
|
814
|
+
"gate": "REQUIRED"
|
|
815
|
+
},
|
|
816
|
+
{
|
|
817
|
+
"id": "TEST-CONTEXT-E02",
|
|
818
|
+
"category": "SECURITY",
|
|
819
|
+
"layer": "UNIT",
|
|
820
|
+
"description": "Rejects capsule containing API key value patterns (sk-..., ghp_..., Bearer tokens).",
|
|
821
|
+
"pass_criteria": "Emits CONTEXT_CAPSULE_SECRET_DETECTED on synthetic token values.",
|
|
822
|
+
"gate": "REQUIRED"
|
|
823
|
+
},
|
|
824
|
+
{
|
|
825
|
+
"id": "TEST-CONTEXT-E03",
|
|
826
|
+
"category": "SECURITY",
|
|
827
|
+
"layer": "UNIT",
|
|
828
|
+
"description": "Proves local .env files and process environment secrets are excluded from capsule inputs.",
|
|
829
|
+
"pass_criteria": "Capsule contains zero references or values from .env files.",
|
|
830
|
+
"gate": "REQUIRED"
|
|
831
|
+
},
|
|
832
|
+
{
|
|
833
|
+
"id": "TEST-CONTEXT-F01",
|
|
834
|
+
"category": "VERIFICATION_PURITY",
|
|
835
|
+
"layer": "INTEGRATION",
|
|
836
|
+
"description": "Proves gemstack verify evaluates context capsule in read-only mode with zero file mutations.",
|
|
837
|
+
"pass_criteria": "File hash tree before and after verify matches 100% (0 bytes modified).",
|
|
838
|
+
"gate": "REQUIRED"
|
|
839
|
+
},
|
|
840
|
+
{
|
|
841
|
+
"id": "TEST-CONTEXT-F02",
|
|
842
|
+
"category": "VERIFICATION_PURITY",
|
|
843
|
+
"layer": "INTEGRATION",
|
|
844
|
+
"description": "Proves context capsule verification executes completely offline with zero network requests.",
|
|
845
|
+
"pass_criteria": "Verification passes exit 0 with all network sockets mocked to throw.",
|
|
846
|
+
"gate": "REQUIRED"
|
|
847
|
+
},
|
|
848
|
+
{
|
|
849
|
+
"id": "TEST-CONTEXT-G01",
|
|
850
|
+
"category": "SIZE_SAFETY",
|
|
851
|
+
"layer": "UNIT",
|
|
852
|
+
"description": "Fails closed with CONTEXT_CAPSULE_TOO_LARGE if critical invariants exceed hard budget.",
|
|
853
|
+
"pass_criteria": "Halts with explicit error rather than silently omitting safety rules.",
|
|
854
|
+
"gate": "REQUIRED"
|
|
855
|
+
},
|
|
856
|
+
{
|
|
857
|
+
"id": "TEST-CONTEXT-H01",
|
|
858
|
+
"category": "LEGACY",
|
|
859
|
+
"layer": "UNIT",
|
|
860
|
+
"description": "Preserves backward compatibility for legacy projects lacking context capsules.",
|
|
861
|
+
"pass_criteria": "Verify passes with exit code 0 and informational legacy notice.",
|
|
862
|
+
"gate": "REQUIRED"
|
|
863
|
+
}
|
|
864
|
+
]
|
|
865
|
+
```
|
|
866
|
+
|
|
867
|
+
---
|
|
868
|
+
|
|
869
|
+
## 32. Future Test Strategy (Design Only)
|
|
870
|
+
|
|
871
|
+
*Note: Tests are NOT implemented during this specification phase. This strategy defines the mechanical requirements for future implementation.*
|
|
872
|
+
|
|
873
|
+
1. **Determinism Suite (`tests/context-determinism.test.js`)**:
|
|
874
|
+
- Executes generation twice over identical mock repositories; verifies SHA-256 match.
|
|
875
|
+
- Tests key sorting, code-unit ordering, and path normalization across Windows/Linux.
|
|
876
|
+
2. **Authority & Provenance Suite (`tests/context-authority.test.js`)**:
|
|
877
|
+
- Injects falsified task completions into capsule; asserts resolver rejects them in favor of `tasks.md`.
|
|
878
|
+
- Tests source hash verification and tampering detection.
|
|
879
|
+
3. **Freshness & Mutation Suite (`tests/context-freshness.test.js`)**:
|
|
880
|
+
- Modifies `spec.md`, `plan.md`, or `tasks.md`; asserts verify transitions capsule to `STALE`.
|
|
881
|
+
4. **Constraint Losslessness Suite (`tests/context-constraints.test.js`)**:
|
|
882
|
+
- Asserts 100% extraction of `MUST` and `MUST NOT` statements into `canonical_invariants`.
|
|
883
|
+
- Verifies frozen contracts and test matrix signatures are fully preserved.
|
|
884
|
+
5. **Security & Secrets Suite (`tests/context-secrets.test.js`)**:
|
|
885
|
+
- Injects dummy API keys and `.env` variables; asserts fail-closed rejection.
|
|
886
|
+
6. **Verification Purity Suite (`tests/context-purity.test.js`)**:
|
|
887
|
+
- Intercepts network sockets during verify; proves zero network traffic and zero file mutations.
|
|
888
|
+
|
|
889
|
+
---
|
|
890
|
+
|
|
891
|
+
## 33. Migration Considerations
|
|
892
|
+
|
|
893
|
+
- **No Breaking Changes**: Existing Gemstack projects initialized under v1.0, v1.1, or v1.2 continue without modification.
|
|
894
|
+
- **Progressive Upgrade**: When a project initiates Upgrade D, `gemstack context generate` creates `context-capsule.json` in the active feature directory.
|
|
895
|
+
- **Sidecar Compatibility**: Capsule metadata does not interfere with Upgrade A feature sidecars (`.gemstack/state.json`).
|
|
896
|
+
|
|
897
|
+
---
|
|
898
|
+
|
|
899
|
+
## 34. Explicit Deferred Items
|
|
900
|
+
|
|
901
|
+
The following concepts are explicitly deferred and out of scope for Upgrade D:
|
|
902
|
+
1. **Multi-Repository Federation**: Cross-repo capsule aggregation (strictly reserved for future ecosystem upgrades).
|
|
903
|
+
2. **Vector Database / Embedding Storage**: RAG platforms and semantic vector stores (non-goal).
|
|
904
|
+
3. **Autonomous Agent Swarms**: Multi-agent orchestration, swarm coordinators, and subagent work queues (non-goal).
|
|
905
|
+
4. **Visual QA / Browser Capture**: Automated screenshot diffing or browser automation (non-goal).
|
|
906
|
+
5. **Package Version Bump / Release**: Version bumping and npm publishing (handled strictly post-closure).
|
|
907
|
+
|
|
908
|
+
---
|
|
909
|
+
|
|
910
|
+
## 35. Open Questions
|
|
911
|
+
|
|
912
|
+
**NONE.**
|
|
913
|
+
Repository inspection and architectural invariants provide unambiguous answers for all design choices. The Context Capsule is strictly derived, fully deterministic, offline, constraint-lossless, and fail-closed.
|