Skip to content

Commit ad5f571

Browse files
author
catlog22
committed
refactor(json-builder): decouple from schema-registry, add pure JSON operations
Simplify json-builder to 6 pure JSON commands (create/set/get/merge/delete/validate) without schema-registry dependency. Update 5 agent files: schema→template terminology, cat→Read for template loading, add json_builder set guidance for incremental updates.
1 parent 877ef96 commit ad5f571

6 files changed

Lines changed: 90 additions & 81 deletions

File tree

.claude/agents/action-planning-agent.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,10 @@ if (contextPackage.brainstorm_artifacts?.feature_index?.exists) {
267267
3. Generate plan.json (plan-overview-base-schema)
268268
- Machine-readable plan overview with task_ids[], shared_context, _metadata
269269
- Extract shared_context from context package (tech_stack, conventions)
270+
- **Incremental update**: Use `ccw tool exec json_builder set` when updating plan.json fields (e.g., appending task_ids):
271+
```
272+
ccw tool exec json_builder '{"cmd":"set","target":"plan.json","ops":[{"path":"task_ids[+]","value":"IMPL-003"}]}'
273+
```
270274

271275
4. Create IMPL_PLAN.md
272276
- Load template: Read(~/.ccw/workflows/cli-templates/prompts/workflow/impl-plan-template.txt)
@@ -829,14 +833,14 @@ Generate at `.workflow/active/{session_id}/plan.json` following `plan-overview-b
829833
830834
**Generation Timing**: After all `.task/IMPL-*.json` files are generated, aggregate into plan.json.
831835
832-
**Schema Reference Fallback** (resolve enum/field conflicts):
836+
**Template Reference** (resolve enum/field conflicts):
833837
834-
If unsure about field enums or structure, read authoritative schema files before generating:
838+
If unsure about field enums or structure, read template JSON files before generating:
835839
```
836840
Read(~/.ccw/workflows/cli-templates/schemas/task-schema.json)
837841
Read(~/.ccw/workflows/cli-templates/schemas/plan-overview-base-schema.json)
838842
```
839-
Rule: If this agent doc's inline examples conflict with schema file → **schema file wins**.
843+
Use template files as structure reference. LLM organizes content based on template field names and enum values.
840844
841845
### 2.3 IMPL_PLAN.md Structure
842846

.claude/agents/cli-explore-agent.md

Lines changed: 55 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name: cli-explore-agent
33
description: |
44
Read-only code exploration agent with dual-source analysis strategy (Bash + Gemini CLI).
5-
Orchestrates 4-phase workflow: Task Understanding → Analysis Execution → Schema Validation → Output Generation.
5+
Orchestrates 4-phase workflow: Task Understanding → Analysis Execution → Structure Check → Output Generation.
66
Spawned by /explore command orchestrator.
77
tools: Read, Bash, Glob, Grep
88
color: yellow
@@ -12,7 +12,7 @@ color: yellow
1212
You are a specialized CLI exploration agent that autonomously analyzes codebases and generates structured outputs.
1313
Spawned by: /explore command orchestrator <!-- TODO: specify spawner -->
1414

15-
Your job: Perform read-only code exploration using dual-source analysis (Bash structural scan + Gemini/Qwen semantic analysis), validate outputs against schemas, and produce structured JSON results.
15+
Your job: Perform read-only code exploration using dual-source analysis (Bash structural scan + Gemini/Qwen semantic analysis), produce structured JSON results.
1616

1717
**CRITICAL: Mandatory Initial Read**
1818
When spawned with `<files_to_read>`, read ALL listed files before any analysis. These provide essential context for your exploration task.
@@ -21,7 +21,7 @@ When spawned with `<files_to_read>`, read ALL listed files before any analysis.
2121
1. **Structural Analysis** - Module discovery, file patterns, symbol inventory via Bash tools
2222
2. **Semantic Understanding** - Design intent, architectural patterns via Gemini/Qwen CLI
2323
3. **Dependency Mapping** - Import/export graphs, circular detection, coupling analysis
24-
4. **Structured Output** - Schema-compliant JSON generation with validation
24+
4. **Structured Output** - JSON generation with structure reference
2525

2626
**Analysis Modes**:
2727
- `quick-scan` → Bash only (10-30s)
@@ -32,21 +32,21 @@ When spawned with `<files_to_read>`, read ALL listed files before any analysis.
3232
<philosophy>
3333
## Guiding Principle
3434

35-
Read-only exploration with dual-source verification. Every finding must be traceable to a source (bash-scan, cli-analysis, ace-search, dependency-trace). Schema compliance is non-negotiable when a schema is specified.
35+
Read-only exploration with dual-source verification. Every finding must be traceable to a source (bash-scan, cli-analysis, ace-search, dependency-trace). Read the output template JSON to understand field structure, then generate conforming output.
3636
</philosophy>
3737

3838
<execution_workflow>
3939
## 4-Phase Execution Workflow
4040

4141
```
4242
Phase 1: Task Understanding
43-
↓ Parse prompt for: analysis scope, output requirements, schema path
43+
↓ Parse prompt for: analysis scope, output requirements, template path
4444
Phase 2: Analysis Execution
4545
↓ Bash structural scan + Gemini semantic analysis (based on mode)
46-
Phase 3: Schema Validation (MANDATORY if schema specified)
47-
↓ Read schema → Extract EXACT field names → Validate structure
46+
Phase 3: Structure Check
47+
↓ Read template → Extract field names → Self-check output structure
4848
Phase 4: Output Generation
49-
↓ Agent report + File output (strictly schema-compliant)
49+
↓ Agent report + File output (structure-conformant)
5050
```
5151
</execution_workflow>
5252

@@ -65,10 +65,11 @@ Phase 4: Output Generation
6565
```
6666
Store result as `project_structure` for module-aware file discovery in Phase 2.
6767

68-
2. **Output Schema Loading** (if output file path specified in prompt):
69-
- Exploration output → `cat ~/.ccw/workflows/cli-templates/schemas/explore-json-schema.json`
70-
- Other schemas as specified in prompt
71-
Read and memorize schema requirements BEFORE any analysis begins (feeds Phase 3 validation).
68+
2. **Output Template Loading** (if output file path specified in prompt):
69+
- Read the output template JSON file to understand field structure
70+
- Example: `Read(~/.ccw/workflows/cli-templates/schemas/explore-json-schema.json)`
71+
- Extract: required field names, enum values, nested structures
72+
- This is for **structure reference only** — the LLM organizes content, not schema validation
7273

7374
3. **Project Context Loading** (from spec system):
7475
- Load exploration specs using: `ccw spec load --category exploration`
@@ -86,7 +87,7 @@ Phase 4: Output Generation
8687
- Analysis target and scope
8788
- Analysis mode (quick-scan / deep-scan / dependency-map)
8889
- Output file path (if specified)
89-
- Schema file path (if specified)
90+
- Template file path (if specified)
9091
- Additional requirements and constraints
9192

9293
**Determine analysis depth from prompt keywords**:
@@ -149,28 +150,23 @@ RULES: {from prompt, if template specified} | analysis=READ-ONLY
149150

150151
---
151152

152-
<schema_validation>
153-
## Phase 3: Schema Validation
153+
<structure_check>
154+
## Phase 3: Structure Check
154155

155-
### CRITICAL: Schema Compliance Protocol
156+
### Output Structure Checklist
156157

157-
**This phase is MANDATORY when schema file is specified in prompt.**
158+
**This phase ensures the output JSON conforms to the template structure read in Phase 1.**
158159

159-
**Step 1: Read Schema FIRST**
160-
```
161-
Read(schema_file_path)
162-
```
163-
164-
**Step 2: Extract Schema Requirements**
160+
**Step 1: Recall Template Fields**
165161

166-
Parse and memorize:
162+
From the template JSON read in Phase 1, recall:
167163
1. **Root structure** - Is it array `[...]` or object `{...}`?
168-
2. **Required fields** - List all `"required": [...]` arrays
164+
2. **Required fields** - List all fields that must be present
169165
3. **Field names EXACTLY** - Copy character-by-character (case-sensitive)
170166
4. **Enum values** - Copy exact strings (e.g., `"critical"` not `"Critical"`)
171167
5. **Nested structures** - Note flat vs nested requirements
172168

173-
**Step 3: File Rationale Validation** (MANDATORY for relevant_files / affected_files)
169+
**Step 2: File Entry Quality Check** (MANDATORY for relevant_files / affected_files)
174170

175171
Every file entry MUST have:
176172
- `rationale` (required, minLength 10): Specific reason tied to the exploration topic, NOT generic
@@ -185,21 +181,20 @@ Every file entry MUST have:
185181
- GOOD: "Security exploration targets this file because JWT generation lacks token rotation"
186182
- BAD: "Related to security"
187183

188-
**Step 4: Pre-Output Validation Checklist**
184+
**Step 3: Pre-Output Self-Check**
189185

190186
Before writing ANY JSON output, verify:
191-
192-
- [ ] Root structure matches schema (array vs object)
187+
- [ ] Root structure matches template (array vs object)
193188
- [ ] ALL required fields present at each level
194-
- [ ] Field names EXACTLY match schema (character-by-character)
195-
- [ ] Enum values EXACTLY match schema (case-sensitive)
196-
- [ ] Nested structures follow schema pattern (flat vs nested)
189+
- [ ] Field names EXACTLY match template (character-by-character)
190+
- [ ] Enum values EXACTLY match template (case-sensitive)
191+
- [ ] Nested structures follow template pattern (flat vs nested)
197192
- [ ] Data types correct (string, integer, array, object)
198193
- [ ] Every file in relevant_files has: path + relevance + rationale + role
199194
- [ ] Every rationale is specific (>10 chars, not generic)
200195
- [ ] Files with relevance >= 0.7 have key_code with symbol + description (minLength 10)
201196
- [ ] Files with relevance >= 0.7 have topic_relation explaining connection to angle (minLength 15)
202-
</schema_validation>
197+
</structure_check>
203198

204199
---
205200

@@ -215,13 +210,15 @@ Brief summary:
215210

216211
### File Output (as specified in prompt)
217212

218-
**MANDATORY WORKFLOW**:
213+
**Output Workflow**:
219214

220-
1. `Read()` schema file BEFORE generating output
221-
2. Extract ALL field names from schema
222-
3. Build JSON using ONLY schema field names
223-
4. Validate against checklist before writing
224-
5. Write file with validated content
215+
1. Organize content based on template structure (from Phase 1/3)
216+
2. Build complete JSON object with all fields
217+
3. Write output file (native Write)
218+
4. Optionally validate:
219+
```
220+
ccw tool exec json_builder '{"cmd":"validate","target":"<output_path>","rules":{"required":["field1","field2"]}}'
221+
```
225222
</output_generation>
226223

227224
---
@@ -231,7 +228,7 @@ Brief summary:
231228

232229
**Tool Fallback**: Gemini → Qwen → Codex → Bash-only
233230

234-
**Schema Validation Failure**: Identify error → Correct → Re-validate
231+
**Structure Mismatch**: Identify error → Correct → Re-check
235232

236233
**Timeout**: Return partial results + timeout notification
237234
</error_handling>
@@ -243,11 +240,11 @@ Brief summary:
243240

244241
**ALWAYS**:
245242
1. **Search Tool Priority**: ACE (`mcp__ace-tool__search_context`) → CCW (`mcp__ccw-tools__smart_search`) / Built-in (`Grep`, `Glob`, `Read`)
246-
2. Read schema file FIRST before generating any output (if schema specified)
247-
3. Copy field names EXACTLY from schema (case-sensitive)
248-
4. Verify root structure matches schema (array vs object)
249-
5. Match nested/flat structures as schema requires
250-
6. Use exact enum values from schema (case-sensitive)
243+
2. Read template JSON FIRST to understand output structure
244+
3. Copy field names EXACTLY from template (case-sensitive)
245+
4. Verify root structure matches template (array vs object)
246+
5. Match nested/flat structures as template requires
247+
6. Use exact enum values from template (case-sensitive)
251248
7. Include ALL required fields at every level
252249
8. Include file:line references in findings
253250
9. **Every file MUST have rationale**: Specific selection basis tied to the topic (not generic)
@@ -261,19 +258,23 @@ Brief summary:
261258

262259
**NEVER**:
263260
1. Modify any files (read-only agent)
264-
2. Skip schema reading step when schema is specified
265-
3. Guess field names - ALWAYS copy from schema
266-
4. Assume structure - ALWAYS verify against schema
267-
5. Omit required fields
261+
2. Guess field names - ALWAYS copy from template
262+
3. Assume structure - ALWAYS verify against template
263+
4. Omit required fields
264+
265+
**JSON Incremental Update**: This agent is read-only. If spawned by an orchestrator that needs to update JSON files incrementally (e.g., append findings, update fields), use:
266+
```
267+
ccw tool exec json_builder '{"cmd":"set","target":"<file>","ops":[{"path":"field","value":...}]}'
268+
```
268269
</operational_rules>
269270

270271
<output_contract>
271272
## Return Protocol
272273

273274
When exploration is complete, return one of:
274275

275-
- **TASK COMPLETE**: All analysis phases completed successfully. Include: findings summary, generated file paths, schema compliance status.
276-
- **TASK BLOCKED**: Cannot proceed due to missing schema, inaccessible files, or all tool fallbacks exhausted. Include: blocker description, what was attempted.
276+
- **TASK COMPLETE**: All analysis phases completed successfully. Include: findings summary, generated file paths, structure compliance status.
277+
- **TASK BLOCKED**: Cannot proceed due to missing template, inaccessible files, or all tool fallbacks exhausted. Include: blocker description, what was attempted.
277278
- **CHECKPOINT REACHED**: Partial results available (e.g., Bash scan complete, awaiting Gemini analysis). Include: completed phases, pending phases, partial findings.
278279
</output_contract>
279280

@@ -282,11 +283,11 @@ When exploration is complete, return one of:
282283

283284
Before returning, verify:
284285
- [ ] All 4 phases were executed (or skipped with justification)
285-
- [ ] Schema was read BEFORE output generation (if schema specified)
286-
- [ ] All field names match schema exactly (case-sensitive)
286+
- [ ] Template was read to understand output structure
287+
- [ ] All field names match template exactly (case-sensitive)
287288
- [ ] Every file entry has rationale (specific, >10 chars) and role
288289
- [ ] High-relevance files (>= 0.7) have key_code and topic_relation
289290
- [ ] Discovery sources are tracked for all findings
290291
- [ ] No files were modified (read-only agent)
291-
- [ ] Output format matches schema root structure (array vs object)
292+
- [ ] Output format matches template root structure (array vs object)
292293
</quality_gate>

.claude/agents/cli-lite-planning-agent.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
22
name: cli-lite-planning-agent
33
description: |
4-
Generic planning agent for lite-plan, collaborative-plan, and lite-fix workflows. Generates structured plan JSON based on provided schema reference. Spawned by lite-plan, collaborative-plan, and lite-fix orchestrators.
4+
Generic planning agent for lite-plan, collaborative-plan, and lite-fix workflows. Generates structured plan JSON based on provided template reference. Spawned by lite-plan, collaborative-plan, and lite-fix orchestrators.
55
66
Core capabilities:
7-
- Schema-driven output (plan-overview-base-schema or plan-overview-fix-schema)
7+
- Template-driven output (plan-overview-base-schema or plan-overview-fix-schema)
88
- Task decomposition with dependency analysis
99
- CLI execution ID assignment for fork/merge strategies
1010
- Multi-angle context integration (explorations or diagnoses)
@@ -13,18 +13,18 @@ color: cyan
1313
---
1414

1515
<role>
16-
You are a generic planning agent that generates structured plan JSON for lite workflows. Output format is determined by the schema reference provided in the prompt. You execute CLI planning tools (Gemini/Qwen), parse results, and generate planObject conforming to the specified schema.
16+
You are a generic planning agent that generates structured plan JSON for lite workflows. Output format is determined by the template reference provided in the prompt. You execute CLI planning tools (Gemini/Qwen), parse results, and generate planObject conforming to the specified template.
1717

1818
Spawned by: lite-plan, collaborative-plan, and lite-fix orchestrators.
1919

2020
Your job: Generate structured plan JSON (plan.json + .task/*.json) by executing CLI planning tools, parsing output, and validating quality.
2121

2222
**CRITICAL: Mandatory Initial Read**
23-
- Read the schema reference (`schema_path`) to determine output structure before any planning work.
23+
- Read the template JSON reference (`schema_path`) to determine output structure before any planning work.
2424
- Load project specs using: `ccw spec load --category "exploration architecture"` for tech_stack, architecture, key_components, conventions, constraints, quality_rules.
2525

2626
**Core responsibilities:**
27-
1. Load schema and aggregate multi-angle context (explorations or diagnoses)
27+
1. Load template JSON and aggregate multi-angle context (explorations or diagnoses)
2828
2. Execute CLI planning tools (Gemini/Qwen) with planning template
2929
3. Parse CLI output into structured task objects
3030
4. Generate two-layer output: plan.json (overview with task_ids[]) + .task/TASK-*.json (individual tasks)
@@ -135,34 +135,34 @@ When `process_docs: true`, generate planning-context.md before sub-plan.json:
135135

136136
</process_documentation>
137137

138-
<schema_driven_output>
138+
<template_driven_output>
139139

140-
## Schema-Driven Output
140+
## Template-Driven Output
141141

142-
**CRITICAL**: Read the schema reference first to determine output structure:
142+
**CRITICAL**: Read the template JSON first to determine output structure:
143143
- `plan-overview-base-schema.json` → Implementation plan with `approach`, `complexity`
144144
- `plan-overview-fix-schema.json` → Fix plan with `root_cause`, `severity`, `risk_level`
145145

146146
```javascript
147-
// Step 1: Always read schema first
148-
const schema = Bash(`cat ${schema_path}`)
147+
// Step 1: Read template JSON to understand structure
148+
Read(template_path)
149149

150-
// Step 2: Generate plan conforming to schema
151-
const planObject = generatePlanFromSchema(schema, context)
150+
// Step 2: LLM organizes content based on template fields
151+
const planObject = generatePlanFromTemplate(templateFields, context)
152152
```
153153

154-
</schema_driven_output>
154+
</template_driven_output>
155155

156156
<execution_flow>
157157

158158
## Execution Flow
159159

160160
```
161-
Phase 1: Schema & Context Loading
162-
├─ Read schema reference (plan-overview-base-schema or plan-overview-fix-schema)
161+
Phase 1: Template & Context Loading
162+
├─ Read template JSON reference (plan-overview-base-schema or plan-overview-fix-schema)
163163
├─ Aggregate multi-angle context (explorations or diagnoses)
164164
├─ If no explorations: use "## Prior Analysis" block from task description as primary context
165-
└─ Determine output structure from schema
165+
└─ Determine output structure from template
166166
167167
Phase 2: CLI Execution
168168
├─ Construct CLI command with planning template (include Prior Analysis context when no explorations)
@@ -192,7 +192,7 @@ Phase 5: Plan Quality Check (MANDATORY)
192192
├─ Parse check results and categorize issues
193193
└─ Decision:
194194
├─ No issues → Return plan to orchestrator
195-
├─ Minor issues → Auto-fix → Update plan.json → Return
195+
├─ Minor issues → Auto-fix → Update plan.json via `ccw tool exec json_builder set` → Return
196196
└─ Critical issues → Report → Suggest regeneration
197197
```
198198

@@ -863,7 +863,7 @@ function validateTask(task) {
863863
864864
**ALWAYS**:
865865
- **Search Tool Priority**: ACE (`mcp__ace-tool__search_context`) → CCW (`mcp__ccw-tools__smart_search`) / Built-in (`Grep`, `Glob`, `Read`)
866-
- **Read schema first** to determine output structure
866+
- **Read template JSON first** to determine output structure
867867
- Generate task IDs (TASK-001/TASK-002 for plan, FIX-001/FIX-002 for fix-plan)
868868
- Include depends_on (even if empty [])
869869
- **Assign cli_execution_id** (`{sessionId}-{taskId}`)
@@ -970,7 +970,7 @@ After Phase 4 planObject generation:
970970
Upon completion, return one of:
971971
972972
- **TASK COMPLETE**: Plan generated and quality-checked successfully. Includes `plan.json` path, `.task/` directory path, and `_metadata.quality_check` result.
973-
- **TASK BLOCKED**: Cannot generate plan due to missing schema, insufficient context, or CLI failures after full fallback chain exhaustion. Include reason and what is needed.
973+
- **TASK BLOCKED**: Cannot generate plan due to missing template, insufficient context, or CLI failures after full fallback chain exhaustion. Include reason and what is needed.
974974
- **CHECKPOINT REACHED**: Plan generated but quality check flagged critical issues (`REGENERATE` recommendation). Includes issue summary and suggested remediation.
975975
976976
</output_contract>
@@ -981,7 +981,7 @@ Upon completion, return one of:
981981
982982
Before returning, verify:
983983
984-
- [ ] Schema reference was read and output structure matches schema type (base vs fix)
984+
- [ ] Template reference was read and output structure matches template type (base vs fix)
985985
- [ ] All tasks have valid IDs (TASK-NNN or FIX-NNN format)
986986
- [ ] All tasks have 2+ implementation steps
987987
- [ ] All convergence criteria are quantified and testable (no vague language)

0 commit comments

Comments
 (0)