
Knowledge Graph
Handle missing or corrupt knowledge-graph JSON safely when spec-to-tasks or codebase analysis agents read and update project context.
Overview
knowledge-graph is an agent skill most often used in Build (also Validate scope, Operate iterate) that defines error-handling and empty-state behavior for developer-kit Knowledge Graph JSON operations.
Install
npx skills add https://github.com/giuseppe-trisciuoglio/developer-kit --skill knowledge-graphWhat is this skill?
- File-not-found path returns an empty KG with metadata, codebase_context, patterns, components, APIs, and integration_poi
- Invalid JSON raises a corruption error and prompts whether to recreate from codebase analysis
- Documents when empty KG is normal: first spec-to-tasks run, deleted file, or wrong path
- Standard empty structure version `1.0` with null spec metadata until first update
- User-impact guidance: missing file is non-blocking; corrupt file requires explicit recovery choice
- Empty KG schema version 1.0
- 2 documented error types: file not found and invalid JSON
Adoption & trust: 821 installs on skills.sh; 271 GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
Your spec-to-tasks agent crashes or clobber context when the knowledge graph path is wrong, the file never existed, or on-disk JSON is truncated.
Who is it for?
Builders using Giuseppe Trisciuoglio’s developer-kit KG + spec-to-tasks flow who want predictable agent behavior on first run and after manual edits.
Skip if: Repos without a knowledge-graph file convention or teams that do not use spec-driven task generation.
When should I use this skill?
When implementing or debugging Knowledge Graph read/update paths in developer-kit workflows (spec-to-tasks, codebase analysis).
What do I get? / Deliverables
Agents either bootstrap a versioned empty graph and proceed or halt with a recoverable corruption prompt so analysis can rebuild context before updating tasks.
- Empty KG bootstrap JSON on first access
- Explicit corruption errors with user-facing recreate option
- Consistent metadata and component slots for downstream task generation
Recommended Skills
Journey fit
Spans multiple journey phases - primary shelf plus alternate fits below.
First appears in Build agent-tooling because KG files back feature specs and task breakdown—but error rules apply whenever those pipelines run. Defines operational behavior for the developer-kit knowledge graph artifact agents consume, not application runtime APIs.
Where it fits
First spec-to-tasks run with no KG file yet—agent seeds empty metadata and continues scoping.
Updating components and APIs arrays after implementing a new service layer.
Refreshing integration_points before breaking a feature into ordered agent tasks.
Detecting hand-edited corrupt JSON and asking whether to rebuild from codebase analysis.
How it compares
Use these explicit empty and corrupt-file rules instead of ad-hoc try/except that returns partial graphs without version metadata.
Common Questions / FAQ
Who is knowledge-graph for?
Indie developers and agent operators running developer-kit knowledge graphs to bridge codebase analysis, specs, and generated tasks.
When should I use knowledge-graph?
During Validate scoping and Build agent-tooling when initializing or updating KG JSON, and during Operate iteration when a graph file may have been deleted or hand-edited corruptly.
Is knowledge-graph safe to install?
It describes filesystem read/write behavior for KG JSON; review the Security Audits panel on this Prism page and back up `kg` files before allowing agents to recreate from analysis.
SKILL.md
READMESKILL.md - Knowledge Graph
# Error Handling - Knowledge Graph Comprehensive error handling strategies and behaviors for Knowledge Graph operations. ## Error Types ### 1. File Not Found **Scenario:** KG file doesn't exist at expected path. **Behavior:** - Return empty KG structure - Message: "No existing knowledge graph, will create new" - Action: Continue with empty KG, will be created on first update **Empty KG Structure:** ```json { "metadata": { "spec_id": null, "feature_name": null, "created_at": null, "updated_at": null, "version": "1.0", "analysis_sources": [] }, "codebase_context": { "project_structure": {}, "technology_stack": [] }, "patterns": { "architectural": [], "conventions": [] }, "components": { "controllers": [], "services": [], "repositories": [], "entities": [], "dtos": [] }, "provides": [], "apis": { "internal": [], "external": [] }, "integration_points": [] } ``` **When this occurs:** - First time running spec-to-tasks for a spec - KG was deleted - Incorrect path provided **User impact:** None (normal operation) --- ### 2. Invalid JSON **Scenario:** KG file exists but contains invalid JSON. **Behavior:** - Raise error - Message: "Knowledge graph corrupted at {path}" - Action: Ask user: "Recreate from codebase analysis?" **Detection:** ```python try: kg_data = json.load(kg_file) except json.JSONDecodeError as e: raise KnowledgeGraphError( f"Knowledge graph corrupted at {path}: {str(e)}" ) ``` **Recovery options:** 1. Recreate from codebase analysis 2. Restore from backup (if available) 3. Manual repair (advanced users) **User impact:** High (cannot use existing KG) --- ### 3. Merge Conflicts **Scenario:** Concurrent updates to KG cause merge conflicts. **Behavior:** - Preserve existing values, add new with timestamps - Message: "Merged X new findings into existing knowledge graph" **Merge Strategy:** - **Arrays**: Append new items (check for duplicates by ID) - **Objects**: Deep merge, preserve existing keys - **Metadata**: Always update timestamps and sources **Example merge:** ```python def merge_kg(existing, updates): # Arrays: append if not duplicate for key in ['patterns', 'components', 'apis']: for item in updates[key]: if item not in existing[key]: existing[key].append(item) # Objects: deep merge for key in ['codebase_context']: existing[key].update(updates[key]) # Metadata: always update existing['metadata']['updated_at'] = datetime.now().isoformat() return existing ``` **Detection:** - Duplicate IDs in arrays - Conflicting values for same key **Prevention:** - Use atomic file writes - Add source tracking to updates - Use optimistic locking --- ### 4. Write Failure **Scenario:** Cannot write KG file (permissions, disk full, etc.). **Behavior:** - Log error, continue without caching - Message: "Cannot write knowledge graph, continuing without cache" **Detection:** ```python try: with open(kg_path, 'w') as f: json.dump(kg_data, f, indent=2) except (IOError, OSError) as e: logger.error(f"Cannot write knowledge graph: {str(e)}") # Continue without caching return None ``` **Impact:** - No caching benefits - Must re-explore codebase next time - Performance degradation **Recovery:** - Fix permissions - Free disk space - Retry write operation --- ### 5. Path Validation Errors **Scenario:** Invalid path provided for KG operations. **Behavior:** - Raise error - Message: "Invalid knowledge graph path: {path}" **Validation rules:** - Path must start with `docs/specs/` - Path must not contain `..` (parent directory) - Path must be within project root **Example:** ```python def validate_kg_path(path): # Must start with docs/specs/ if not path.startswith("docs/specs/"): raise ValueError(f"Invalid KG path: {path}") # No path traversal if ".." in path: raise ValueErro