Initial commit

This commit is contained in:
Zhongwei Li
2025-11-29 17:55:18 +08:00
commit f33f21dd79
19 changed files with 3530 additions and 0 deletions

View File

@@ -0,0 +1,486 @@
# Session Management Command Reference
Complete reference for all session management commands.
## Session Lifecycle Commands
### `start` - Start New Session
```bash
python scripts/session.py start <branch-name> [options]
```
**Options:**
- `--objective "text"` - Set primary objective for this session
- `--resume` - Resume if session already exists on this branch
**Examples:**
```bash
# Start new feature
python scripts/session.py start feature/user-auth --objective "Implement JWT authentication"
# Start with resume fallback
python scripts/session.py start feature/payments --resume
```
**Behavior:**
1. Creates/checks out git branch
2. Initializes session directory (`.git/sessions/<branch>/`)
3. Loads project context from `.session/`
4. Generates agent brief
5. Displays user brief with status
---
### `resume` - Resume Existing Session
```bash
python scripts/session.py resume [branch-name]
```
**Arguments:**
- `branch-name` (optional) - Specific branch to resume; defaults to current
**Examples:**
```bash
# Resume current branch
python scripts/session.py resume
# Resume specific branch
python scripts/session.py resume feature/oauth-integration
```
**Behavior:**
1. Checks out specified branch (if provided)
2. Loads session context
3. Analyzes git history since last session
4. Generates comprehensive brief
5. Displays current status
---
### `checkpoint` - Create Checkpoint
```bash
python scripts/session.py checkpoint [options]
```
**Options:**
- `--label "text"` - Checkpoint label for easy reference
- `--message "text"` - Git commit message
- `--decision "text"` - Record architectural decision
**Examples:**
```bash
# Simple checkpoint
python scripts/session.py checkpoint --label "oauth-complete"
# With decision
python scripts/session.py checkpoint \
--label "auth-interface" \
--decision "Using interface segregation for auth providers"
# With custom message
python scripts/session.py checkpoint \
--label "tests-passing" \
--message "feat(auth): Add comprehensive test suite"
```
**Behavior:**
1. Captures current git state
2. Analyzes code changes
3. Updates progress toward objectives
4. Creates enhanced git commit with metadata
5. Saves checkpoint metadata
---
### `end` - End Session
```bash
python scripts/session.py end [options]
```
**Options:**
- `--handoff` - Generate handoff document (default: true)
- `--merge-to <branch>` - Merge to target branch after ending
- `--summary` - Generate session summary (default: true)
**Examples:**
```bash
# End with handoff
python scripts/session.py end
# End and merge
python scripts/session.py end --merge-to main
# End without handoff
python scripts/session.py end --no-handoff
```
**Behavior:**
1. Final comprehensive state capture
2. Calculates session metrics
3. Generates handoff document
4. Archives session data
5. Optional: merges to target branch
6. Displays accomplishments summary
---
### `switch` - Switch Sessions
```bash
python scripts/session.py switch <branch-name>
```
**Arguments:**
- `branch-name` - Target session/branch to switch to
**Examples:**
```bash
# Switch to hotfix
python scripts/session.py switch hotfix/critical-bug
# Back to feature
python scripts/session.py switch feature/main-work
```
**Behavior:**
1. Saves current session state
2. Checks out target branch
3. Loads target session context
4. Displays quick brief
5. Highlights differences
---
## Context Query Commands
### `status` - Session Status
```bash
python scripts/session.py status [options]
```
**Options:**
- `--verbose` - Include detailed information
- `--objectives` - Show only objectives
- `--blockers` - Show only blockers
**Examples:**
```bash
# Quick status
python scripts/session.py status
# Detailed status
python scripts/session.py status --verbose
# Just objectives
python scripts/session.py status --objectives
```
**Output includes:**
- Current objectives and progress
- Active blockers
- Recent changes summary
- Time in session
- Quality metrics (if available)
- Next recommended actions
---
### `history` - Session History
```bash
python scripts/session.py history [options]
```
**Options:**
- `--count N` - Number of sessions to show (default: 10)
- `--metrics` - Include velocity and quality metrics
- `--since <date>` - Filter by date (YYYY-MM-DD format)
**Examples:**
```bash
# Last 10 sessions
python scripts/session.py history
# Last 5 with metrics
python scripts/session.py history --count 5 --metrics
# Since specific date
python scripts/session.py history --since 2025-10-01
```
**Output includes:**
- Session timeline
- Objectives completed per session
- Velocity trends (if --metrics)
- Quality progression (if --metrics)
---
## Management Commands
### `objectives` - Manage Objectives
```bash
python scripts/session.py objectives <action> [options]
```
**Actions:**
- `add "text"` - Add new objective
- `complete <id>` - Mark objective complete
- `list` - Show all objectives
**Examples:**
```bash
# Add objective
python scripts/session.py objectives add "Implement webhook handlers"
# Complete objective
python scripts/session.py objectives complete obj-1
# List objectives
python scripts/session.py objectives list
```
---
### `blockers` - Manage Blockers
```bash
python scripts/session.py blockers <action> [options]
```
**Actions:**
- `add "text"` - Add new blocker
- `resolve <id>` - Mark blocker resolved
- `list` - Show all blockers
**Examples:**
```bash
# Add blocker
python scripts/session.py blockers add "Waiting on API keys"
# Resolve blocker
python scripts/session.py blockers resolve blk-1
# List blockers
python scripts/session.py blockers list
```
---
### `decisions` - Log Decisions
```bash
python scripts/session.py decisions <action> [options]
```
**Actions:**
- `add "text"` - Record architectural decision
- `list` - Show decision log
**Options (for add):**
- `--rationale "text"` - Decision rationale
- `--alternatives "text"` - Alternatives considered
**Examples:**
```bash
# Record decision
python scripts/session.py decisions add "Using JWT over sessions" \
--rationale "Stateless auth for microservices"
# With alternatives
python scripts/session.py decisions add "Repository pattern for data access" \
--rationale "Separates domain from persistence" \
--alternatives "Active Record: Too coupled to database"
# List decisions
python scripts/session.py decisions list
```
---
## Analysis Commands
### `analyze` - Session Analysis
```bash
python scripts/session.py analyze [options]
```
**Options:**
- `--velocity` - Calculate velocity metrics
- `--patterns` - Detect coding patterns
- `--recommendations` - Generate recommendations
**Examples:**
```bash
# Basic analysis
python scripts/session.py analyze
# With velocity
python scripts/session.py analyze --velocity
# Full analysis
python scripts/session.py analyze --velocity --patterns --recommendations
```
**Output includes:**
- Session health score
- Pattern compliance
- Code quality trends
- Velocity calculations (if --velocity)
- Recommended actions (if --recommendations)
---
### `compare` - Compare Sessions
```bash
python scripts/session.py compare <session-id> [options]
```
**Options:**
- `--changes` - Show code changes
- `--metrics` - Compare metrics
**Examples:**
```bash
# Compare with previous session
python scripts/session.py compare session-2025-10-30
# With detailed changes
python scripts/session.py compare session-2025-10-30 --changes
```
---
### `report` - Generate Reports
```bash
python scripts/session.py report [options]
```
**Options:**
- `--weekly` - Weekly summary
- `--project` - Complete project summary
- `--format <type>` - Output format (markdown, json, html)
**Examples:**
```bash
# Weekly report
python scripts/session.py report --weekly
# Project summary
python scripts/session.py report --project --format markdown
```
---
## Common Workflows
### Starting Your Day
```bash
# Resume where you left off
python scripts/session.py resume
# Check what needs to be done
python scripts/session.py status
```
### During Development
```bash
# Checkpoint at milestones
python scripts/session.py checkpoint --label "api-implemented"
# Record important decisions
python scripts/session.py decisions add "Using Redis for caching" \
--rationale "Fast, simple, proven for this use case"
# Track blockers
python scripts/session.py blockers add "Need database credentials"
```
### Ending Your Day
```bash
# End with comprehensive handoff
python scripts/session.py end
# Or end and merge
python scripts/session.py end --merge-to main
```
### Context Switching
```bash
# Urgent issue
python scripts/session.py switch hotfix/prod-issue
# Back to feature work
python scripts/session.py switch feature/current-work
```
---
## Exit Codes
All commands return standard exit codes:
- `0` - Success
- `1` - Error (check output for details)
---
## Environment Variables
Session management respects these environment variables:
- `SESSION_CONFIG` - Path to custom config file
- `SESSION_VERBOSE` - Enable verbose output (true/false)
- `GIT_DIR` - Custom git directory location
---
## Integration with Git
Session management integrates with git through:
**Git Hooks:**
- `post-checkout` - Auto-load session on branch switch
- `prepare-commit-msg` - Inject session metadata
- `post-commit` - Update progress tracking
**Git Configuration:**
- Uses `user.name` and `user.email` for session attribution
- Respects `.gitignore` for file tracking
- Works with all git workflows (merge, rebase, etc.)
---
## Tips & Tricks
**Aliases:**
Add to your shell profile for quick access:
```bash
alias ss='python scripts/session.py status'
alias sc='python scripts/session.py checkpoint'
alias se='python scripts/session.py end'
```
**Quick Checkpoints:**
```bash
# Label-only checkpoint (uses current time as message)
python scripts/session.py checkpoint --label "milestone"
```
**Verbose Troubleshooting:**
```bash
# Any command can use --verbose for detailed output
python scripts/session.py status --verbose
```

View File

@@ -0,0 +1,228 @@
# Configuration Reference
Complete reference for `.session/config.yaml` configuration options.
## Session Configuration
```yaml
session:
auto_track: true
auto_checkpoint: false
checkpoint_interval: 30m
handoff_on_end: true
archive_after_days: 30
```
### `auto_track`
**Type:** boolean
**Default:** `true`
**Description:** Automatically track file changes during session
### `auto_checkpoint`
**Type:** boolean
**Default:** `false`
**Description:** Create automatic checkpoints at intervals
### `checkpoint_interval`
**Type:** string
**Default:** `30m`
**Description:** Interval for automatic checkpoints (30m, 1h, etc.)
### `handoff_on_end`
**Type:** boolean
**Default:** `true`
**Description:** Generate handoff document when ending session
### `archive_after_days`
**Type:** integer
**Default:** `30`
**Description:** Archive completed sessions after N days
---
## Context Configuration
```yaml
context:
architecture: hexagonal
patterns:
- ports-and-adapters
- repository-pattern
conventions:
- type-hints-required
- docstrings-required
```
### `architecture`
**Type:** string
**Options:** `hexagonal`, `layered`, `microservices`, `mvc`, `clean`, `ddd`
**Description:** Primary architecture pattern for the project
### `patterns`
**Type:** list of strings
**Description:** Code patterns to detect and enforce
**Common values:**
- `ports-and-adapters`
- `repository-pattern`
- `dependency-injection`
- `factory-pattern`
- `cqrs`
- `event-sourcing`
### `conventions`
**Type:** list of strings
**Description:** Project conventions
**Common values:**
- `type-hints-required`
- `docstrings-required`
- `snake-case`
- `pep8-compliant`
- `test-coverage-required`
---
## Tracking Configuration
```yaml
tracking:
watch_patterns:
- "src/**/*.py"
- "tests/**/*.py"
ignore_patterns:
- "**/__pycache__/**"
- "**/node_modules/**"
annotations:
- "TODO:"
- "FIXME:"
- "DECISION:"
```
### `watch_patterns`
**Type:** list of glob patterns
**Description:** Files to watch for changes
### `ignore_patterns`
**Type:** list of glob patterns
**Description:** Files to ignore
### `annotations`
**Type:** list of strings
**Description:** Code annotations to track
---
## Quality Configuration
```yaml
quality:
coverage_threshold: 85
new_code_coverage_threshold: 90
require_tests: true
block_merge_on_quality: true
```
### `coverage_threshold`
**Type:** integer (0-100)
**Default:** `85`
**Description:** Minimum overall test coverage percentage
### `new_code_coverage_threshold`
**Type:** integer (0-100)
**Default:** `90`
**Description:** Minimum coverage for new code
### `require_tests`
**Type:** boolean
**Default:** `true`
**Description:** Require tests for new features
### `block_merge_on_quality`
**Type:** boolean
**Default:** `true`
**Description:** Prevent merge if quality thresholds not met
---
## Display Configuration
```yaml
display:
color: true
verbose: false
emoji: true
date_format: "%Y-%m-%d %H:%M"
```
### `color`
**Type:** boolean
**Default:** `true`
**Description:** Use colored terminal output
### `verbose`
**Type:** boolean
**Default:** `false`
**Description:** Enable verbose output by default
### `emoji`
**Type:** boolean
**Default:** `true`
**Description:** Use emoji in output
### `date_format`
**Type:** string
**Default:** `"%Y-%m-%d %H:%M"`
**Description:** Date/time format string (Python strftime format)
---
## Complete Example
```yaml
# Session Management Configuration
session:
auto_track: true
auto_checkpoint: false
checkpoint_interval: 30m
handoff_on_end: true
archive_after_days: 30
context:
architecture: hexagonal
patterns:
- ports-and-adapters
- repository-pattern
- dependency-injection
conventions:
- type-hints-required
- docstrings-required
- snake-case
- max-line-length-100
tracking:
watch_patterns:
- "src/**/*.py"
- "tests/**/*.py"
- "docs/**/*.md"
ignore_patterns:
- "**/__pycache__/**"
- "**/.venv/**"
- "**/dist/**"
annotations:
- "TODO:"
- "FIXME:"
- "DECISION:"
- "BLOCKER:"
quality:
coverage_threshold: 85
new_code_coverage_threshold: 90
require_tests: true
block_merge_on_quality: true
display:
color: true
verbose: false
emoji: true
date_format: "%Y-%m-%d %H:%M"
```

View File

@@ -0,0 +1,264 @@
# Session Handoff Template
This template shows the structure and content of session handoff documents generated by `session.py end --handoff`.
---
# Session Handoff: [Feature/Branch Name]
**Session ID**: [branch-name]-[date]
**Branch**: [branch-name]
**Date**: [YYYY-MM-DD HH:MM UTC]
**Duration**: [X hours Y minutes]
**Commit**: [SHA] "[commit message]"
---
## 🎯 Session Objective
**Primary Goal**: [Primary objective description]
**Success Criteria**:
- [x] [Completed criterion 1]
- [x] [Completed criterion 2]
- [ ] [Incomplete criterion]
**Achievement**: [✅ Complete / 🚧 Partial / ❌ Not met]
---
## ✅ Completed Work
### Features Implemented
**1. [Feature Name]** (Commit: [SHA])
- [Implementation detail 1]
- [Implementation detail 2]
- [Implementation detail 3]
**2. [Feature Name]** (Commit: [SHA])
- [Implementation detail 1]
- [Implementation detail 2]
### Tests Added
**Unit Tests**: [N] new tests
- `test_[module].py`: [N] tests
- `test_[module].py`: [N] tests
**Integration Tests**: [N] new tests
- [Description of integration tests]
**Coverage**: [XX.X]% → [YY.Y]% **(+Z.Z%)**
### Documentation
- [Documentation item 1]
- [Documentation item 2]
- [Documentation item 3]
---
## 🚧 Work In Progress
**[Feature/Task Name]**
- Current state: [X]% complete
- Remaining work: [Description]
- Next steps: [Action items]
---
## 🚫 Blockers
### Blocker 1: [Blocker Name]
**Issue**: [Issue ID if applicable]
**Status**: [Active / Resolved]
**Duration**: [Time blocked]
**Resolution**: [How resolved or path to resolution]
**Impact**: [Impact description]
### Blocker 2: [Blocker Name]
**Status**: [Active]
**Blocking**: [What is blocked]
**Next Steps**: [What needs to happen]
---
## 📋 Decisions Made
### D-[DATE]-1: [Decision Title]
**Context**: [Why this decision was needed]
**Decision**: [What was decided]
**Rationale**: [Why this approach was chosen]
**Alternatives Considered**:
- [Alternative 1]: [Why not chosen]
- [Alternative 2]: [Why not chosen]
**Impact**:
- [Impact item 1]
- [Impact item 2]
**Consequences**:
- [Consequence 1]
- [Consequence 2]
---
## 🏗️ Architecture & Patterns
### Patterns Applied
**[Pattern Name]**
- [How pattern was applied]
- [Benefits realized]
- [Considerations]
### Pattern Compliance
**Compliance Score**: [XX]%
**Violations** (if any):
- `[file]:[line]`: [Violation description] - [Status]
**Improvements**:
- [Improvement made 1]
- [Improvement made 2]
---
## 📊 Session Metrics
### Time Breakdown
- **Active Coding**: [X hours Y minutes]
- **Testing**: [X hours Y minutes]
- **Documentation**: [X minutes]
- **Blocked Time**: [X hours] ([Reason])
### Code Changes
- **Files Modified**: [N]
- **Files Added**: [N]
- **Lines Added**: [N]
- **Lines Removed**: [N]
- **Net Change**: [+/-N] lines
### Commits
- **Total Commits**: [N]
- **Feature Commits**: [N]
- **Test Commits**: [N]
- **Documentation Commits**: [N]
### Quality Metrics
- **Tests Added**: [N]
- **Tests Passing**: [N] ([X]%)
- **Coverage**: [XX.X]% (+[Z.Z]%, [above/below] threshold)
- **Build Status**: [✅ Passing / ❌ Failing]
- **Linter Warnings**: [N]
---
## 📁 Key Files
### Core Implementation
- `[path/to/file]` - [Description]
- `[path/to/file]` - [Description]
### Tests
- `[path/to/test]` - [Description]
- `[path/to/test]` - [Description]
### Documentation
- `[path/to/doc]` - [Description]
---
## ⚠️ Important Notes
### For Next Developer
**Critical Points**:
1. [Critical point 1]
2. [Critical point 2]
**Testing**:
- [Testing consideration 1]
- [Testing consideration 2]
**Deployment**:
- [Deployment consideration 1]
- [Deployment consideration 2]
---
## 🔄 Next Steps (If Continuing)
1. [Next action item 1]
2. [Next action item 2]
3. [Next action item 3]
**Estimated**: [Time estimate]
**Potential Enhancements** (Future work):
- [Enhancement 1]
- [Enhancement 2]
---
## 🎓 Learnings & Insights
### What Went Well
- [Success 1]
- [Success 2]
### Challenges Overcome
- [Challenge 1]: [How overcome]
- [Challenge 2]: [How overcome]
### What Could Be Improved
- [Improvement opportunity 1]
- [Improvement opportunity 2]
### Recommendations for Similar Work
- [Recommendation 1]
- [Recommendation 2]
---
## 📊 Session Summary
**Objective Achievement**: [✅ 100% / 🚧 XX% / ❌ Not met]
**Quality Score**: [A+ / A / B / C / D]
**Velocity**: [N] lines/hour (net code)
**Decision Points**: [N] architectural decisions recorded
**Blockers**: [N] encountered, [N] resolved
**Overall Assessment**: [Brief assessment]
---
## 🔗 Related Resources
- **Pull Request**: #[N]
- **Issue Tracker**: [Issue IDs]
- **Build**: [Build link] ([Status])
- **Documentation**: [Doc links]
---
## 📝 Handoff Checklist
- [ ] All code committed and pushed
- [ ] Tests passing
- [ ] Coverage above threshold
- [ ] Documentation updated
- [ ] Decisions recorded
- [ ] Branch merged (if applicable)
- [ ] Issues updated
- [ ] Session metrics recorded
**Status**: [✅ Ready / 🚧 Pending / ❌ Incomplete]
---
**Generated by Session Manager**
**Session Archive**: `.git/sessions/history/[session-id].json`