feat(storage): implement storage manager for centralized management and cleanup

- Added a new Storage Manager component to handle storage statistics, project cleanup, and configuration for CCW centralized storage.
- Introduced functions to calculate directory sizes, get project storage stats, and clean specific or all storage.
- Enhanced SQLiteStore with a public API for executing queries securely.
- Updated tests to utilize the new execute_query method and validate storage management functionalities.
- Improved performance by implementing connection pooling with idle timeout management in SQLiteStore.
- Added new fields (token_count, symbol_type) to the symbols table and adjusted related insertions.
- Enhanced error handling and logging for storage operations.
This commit is contained in:
catlog22
2025-12-15 17:39:38 +08:00
parent ee0886fc48
commit 97640a517a
36 changed files with 2108 additions and 841 deletions

View File

@@ -80,9 +80,21 @@ const bugSlug = bug_description.toLowerCase().replace(/[^a-z0-9]+/g, '-').substr
const dateStr = getUtc8ISOString().substring(0, 10) // Format: 2025-11-29
const sessionId = `${bugSlug}-${dateStr}` // e.g., "user-avatar-upload-fails-2025-11-29"
const sessionFolder = `.workflow/.lite-fix/${sessionId}`
bash(`mkdir -p ${sessionFolder} && test -d ${sessionFolder} && echo "SUCCESS: ${sessionFolder}" || echo "FAILED: ${sessionFolder}"`)
// Initialize session via session_manager tool
const initResult = await ccw_tool_exec('session_manager', {
operation: 'init',
session_id: sessionId,
location: 'lite-fix',
metadata: {
description: bug_description,
severity: severity, // Set after severity assessment
created_at: getUtc8ISOString()
}
})
const sessionFolder = initResult.result.path
console.log(`Session initialized: ${sessionId} at ${sessionFolder}`)
```
**Diagnosis Decision Logic**:

View File

@@ -80,9 +80,21 @@ const taskSlug = task_description.toLowerCase().replace(/[^a-z0-9]+/g, '-').subs
const dateStr = getUtc8ISOString().substring(0, 10) // Format: 2025-11-29
const sessionId = `${taskSlug}-${dateStr}` // e.g., "implement-jwt-refresh-2025-11-29"
const sessionFolder = `.workflow/.lite-plan/${sessionId}`
bash(`mkdir -p ${sessionFolder} && test -d ${sessionFolder} && echo "SUCCESS: ${sessionFolder}" || echo "FAILED: ${sessionFolder}"`)
// Initialize session via session_manager tool
const initResult = await ccw_tool_exec('session_manager', {
operation: 'init',
session_id: sessionId,
location: 'lite-plan',
metadata: {
description: task_description,
complexity: complexity, // Set after complexity assessment
created_at: getUtc8ISOString()
}
})
const sessionFolder = initResult.result.path
console.log(`Session initialized: ${sessionId} at ${sessionFolder}`)
```
**Exploration Decision Logic**:

View File

@@ -81,6 +81,26 @@ ccw cli exec "<PROMPT>" --tool <gemini|qwen|codex> --mode <analysis|write|auto>
| `write` | Create/Modify/Delete | Documentation, code creation, file modifications | Requires `--mode write` |
| `auto` | Full operations | Feature implementation, bug fixes, autonomous development | Codex only, requires `--mode auto` |
### Mode Protocol References (MANDATORY)
**⚠️ REQUIRED**: Every CLI execution MUST include the corresponding mode protocol in RULES:
| Mode | Protocol (REQUIRED) |
|------|---------------------|
| `analysis` | `$(cat ~/.claude/workflows/cli-templates/protocols/analysis-protocol.md)` |
| `write/auto` | `$(cat ~/.claude/workflows/cli-templates/protocols/write-protocol.md)` |
**RULES Format** (protocol MUST be included):
```bash
# Analysis mode - MUST include analysis-protocol.md
RULES: $(cat ~/.claude/workflows/cli-templates/protocols/analysis-protocol.md) $(cat ~/.claude/workflows/cli-templates/prompts/analysis/...) | constraints
# Write/Auto mode - MUST include write-protocol.md
RULES: $(cat ~/.claude/workflows/cli-templates/protocols/write-protocol.md) $(cat ~/.claude/workflows/cli-templates/prompts/development/...) | constraints
```
**Validation**: CLI execution without mode protocol reference is INVALID
### Gemini & Qwen
**Via CCW**: `ccw cli exec "<prompt>" --tool gemini` or `--tool qwen`

View File

@@ -0,0 +1,112 @@
# Analysis Mode Protocol
## Mode Definition
**Mode**: `analysis` (READ-ONLY)
**Tools**: Gemini, Qwen (default mode)
## Operation Boundaries
### ALLOWED Operations
- **READ**: All CONTEXT files and analyze content
- **ANALYZE**: Code patterns, architecture, dependencies
- **GENERATE**: Text output, insights, recommendations
- **DOCUMENT**: Analysis results in output response only
### FORBIDDEN Operations
- **NO FILE CREATION**: Cannot create any files on disk
- **NO FILE MODIFICATION**: Cannot modify existing files
- **NO FILE DELETION**: Cannot delete any files
- **NO DIRECTORY OPERATIONS**: Cannot create/modify directories
**CRITICAL**: Absolutely NO file system operations - OUTPUT ONLY
## Execution Flow
1. **Parse** all 6 fields (PURPOSE, TASK, MODE, CONTEXT, EXPECTED, RULES)
2. **Read** and analyze CONTEXT files thoroughly
3. **Identify** patterns, issues, and dependencies
4. **Generate** insights and recommendations
5. **Output** structured analysis (text response only)
6. **Validate** EXPECTED deliverables met
## Core Requirements
**ALWAYS**:
- Analyze ALL CONTEXT files completely
- Apply RULES (templates + constraints) exactly
- Provide code evidence with `file:line` references
- List all related/analyzed files at output beginning
- Match EXPECTED deliverables precisely
**NEVER**:
- Assume behavior without code verification
- Ignore CONTEXT file patterns
- Skip RULES or templates
- Make unsubstantiated claims
- Create/modify/delete any files
## RULES Processing
- Parse RULES field to extract template content and constraints
- Recognize `|` as separator: `template content | additional constraints`
- Apply ALL template guidelines as mandatory
- Treat rule violations as task failures
## Error Handling
**File Not Found**: Report missing files, continue with available, note in output
**Invalid CONTEXT Pattern**: Report invalid pattern, request correction, do not guess
## Quality Standards
- **Thoroughness**: Analyze ALL files, check cross-file patterns, quantify metrics
- **Evidence-Based**: Quote code with `file:line`, link patterns, support claims with examples
- **Actionable**: Clear recommendations, prioritized by impact, incremental changes
---
## Output Format
### Format Priority
**If template defines output format** → Follow template format EXACTLY
**If template has no format** → Use default format below
### Default Analysis Output
```markdown
# Analysis: [TASK Title]
## Related Files
- `path/to/file1.ext` - [Brief description of relevance]
- `path/to/file2.ext` - [Brief description of relevance]
## Summary
[2-3 sentence overview]
## Key Findings
1. [Finding] - path/to/file:123
2. [Finding] - path/to/file:456
## Detailed Analysis
[Evidence-based analysis with code quotes]
## Recommendations
1. [Actionable recommendation]
2. [Actionable recommendation]
```
### Code References
**Format**: `path/to/file:line_number`
**Example**: `src/auth/jwt.ts:45` - Authentication uses deprecated algorithm
### Quality Checklist
- [ ] All CONTEXT files analyzed
- [ ] Code evidence with `file:line` references
- [ ] Specific, actionable recommendations
- [ ] No unsubstantiated claims
- [ ] EXPECTED deliverables met

View File

@@ -0,0 +1,201 @@
# Write Mode Protocol
## Mode Definition
**Mode**: `write` (FILE OPERATIONS) / `auto` (FULL OPERATIONS)
**Tools**: Codex (auto), Gemini/Qwen (write)
## Operation Boundaries
### MODE: write
- **READ**: All CONTEXT files and analyze content
- **CREATE**: New files (documentation, code, configuration)
- **MODIFY**: Existing files (update content, refactor code)
- **DELETE**: Files when explicitly required
**Restrictions**: Follow project conventions, cannot break existing functionality
### MODE: auto (Codex only)
- All `write` mode operations
- Run tests and builds
- Commit code incrementally
- Full autonomous development
**Constraint**: Must test every change
## Execution Flow
### MODE: write
1. **Parse** all 6 fields (PURPOSE, TASK, MODE, CONTEXT, EXPECTED, RULES)
2. **Read** CONTEXT files, find 3+ similar patterns
3. **Plan** implementation following RULES
4. **Execute** requested file operations
5. **Validate** changes
6. **Report** file changes
### MODE: auto
1. **Parse** all 6 fields
2. **Analyze** CONTEXT files - find 3+ similar patterns
3. **Plan** implementation following RULES
4. **Generate** code with tests
5. **Run** tests continuously
6. **Commit** working code incrementally
7. **Validate** EXPECTED deliverables
8. **Report** results
## Core Requirements
**ALWAYS**:
- Study CONTEXT files - find 3+ similar patterns before implementing
- Apply RULES exactly
- Test continuously (auto mode)
- Commit incrementally (auto mode)
- Match project style exactly
- List all created/modified files at output beginning
**NEVER**:
- Make assumptions without code verification
- Ignore existing patterns
- Skip tests (auto mode)
- Use clever tricks over boring solutions
- Break backward compatibility
- Exceed 3 failed attempts without stopping
## Multi-Task Execution (Resume)
**First subtask**: Standard execution flow
**Subsequent subtasks** (via `resume`):
- Recall context from previous subtasks
- Build on previous work
- Maintain consistency
- Test integration
- Report context for next subtask
## Error Handling
**Three-Attempt Rule**: On 3rd failure, stop and report what attempted, what failed, root cause
| Error Type | Response |
|------------|----------|
| Syntax/Type | Review → Fix → Re-run tests |
| Runtime | Analyze stack → Add handling → Test |
| Test Failure | Debug → Review setup → Fix |
| Build Failure | Check messages → Fix incrementally |
---
## Output Format
### Format Priority
**If template defines output format** → Follow template format EXACTLY
**If template has no format** → Use default format below
### Single Task Implementation
```markdown
# Implementation: [TASK Title]
## Changes
- Created: `path/to/file1.ext` (X lines)
- Modified: `path/to/file2.ext` (+Y/-Z lines)
- Deleted: `path/to/file3.ext`
## Summary
[2-3 sentence overview]
## Key Decisions
1. [Decision] - Rationale and reference to similar pattern
2. [Decision] - path/to/reference:line
## Implementation Details
[Evidence-based description with code references]
## Testing
- Tests written: X new tests
- Tests passing: Y/Z tests
## Validation
✅ Tests: X passing
✅ Build: Success
## Next Steps
[Recommendations if any]
```
### Multi-Task (First Subtask)
```markdown
# Subtask 1/N: [TASK Title]
## Changes
[List of file changes]
## Implementation
[Details with code references]
## Testing
✅ Tests: X passing
## Context for Next Subtask
- Key decisions: [established patterns]
- Files created: [paths and purposes]
- Integration points: [where next subtask should connect]
```
### Multi-Task (Subsequent Subtasks)
```markdown
# Subtask N/M: [TASK Title]
## Changes
[List of file changes]
## Integration Notes
✅ Compatible with previous subtask
✅ Maintains established patterns
## Implementation
[Details with code references]
## Testing
✅ Tests: X passing
## Context for Next Subtask
[If not final, provide context]
```
### Partial Completion
```markdown
# Task Status: Partially Completed
## Completed
- [What worked]
- Files: `path/to/completed.ext`
## Blocked
- **Issue**: [What failed]
- **Root Cause**: [Analysis]
- **Attempted**: [Solutions tried - attempt X of 3]
## Required
[What's needed to proceed]
## Recommendation
[Suggested next steps]
```
### Code References
**Format**: `path/to/file:line_number`
**Example**: `src/auth/jwt.ts:45` - Implemented following pattern from `src/auth/session.ts:78`
### Quality Checklist
- [ ] All tests pass
- [ ] Build succeeds
- [ ] All EXPECTED deliverables met
- [ ] Code follows existing patterns
- [ ] File changes listed at beginning