@pjmendonca/devflow 1.9.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/CHANGELOG.md +526 -0
- package/LICENSE +21 -0
- package/README.md +620 -0
- package/bin/devflow-checkpoint.js +10 -0
- package/bin/devflow-collab.js +10 -0
- package/bin/devflow-cost.js +10 -0
- package/bin/devflow-create-persona.js +10 -0
- package/bin/devflow-init.js +10 -0
- package/bin/devflow-memory.js +10 -0
- package/bin/devflow-new-doc.js +10 -0
- package/bin/devflow-personalize.js +10 -0
- package/bin/devflow-setup-checkpoint.js +10 -0
- package/bin/devflow-story.js +10 -0
- package/bin/devflow-tech-debt.js +10 -0
- package/bin/devflow-validate-overrides.js +10 -0
- package/bin/devflow-validate.js +10 -0
- package/bin/devflow-version.js +10 -0
- package/lib/constants.js +30 -0
- package/lib/exec-python.js +78 -0
- package/lib/python-check.js +178 -0
- package/package.json +64 -0
- package/tooling/.automation/agents/architect.md +135 -0
- package/tooling/.automation/agents/ba.md +70 -0
- package/tooling/.automation/agents/dev.md +79 -0
- package/tooling/.automation/agents/maintainer.md +97 -0
- package/tooling/.automation/agents/pm.md +116 -0
- package/tooling/.automation/agents/reviewer.md +141 -0
- package/tooling/.automation/agents/sm.md +61 -0
- package/tooling/.automation/agents/writer.md +193 -0
- package/tooling/.automation/config.ps1.template +61 -0
- package/tooling/.automation/config.sh.template +48 -0
- package/tooling/.automation/memory/.gitkeep +6 -0
- package/tooling/.automation/memory/knowledge/kg_integration-test.json +94 -0
- package/tooling/.automation/memory/knowledge/kg_test-story.json +300 -0
- package/tooling/.automation/memory/shared/shared_integration-test.json +30 -0
- package/tooling/.automation/memory/shared/shared_test-story.json +78 -0
- package/tooling/.automation/overrides/templates/README.md +113 -0
- package/tooling/.automation/overrides/templates/architect/README.md +27 -0
- package/tooling/.automation/overrides/templates/architect/cloud-native.yaml +92 -0
- package/tooling/.automation/overrides/templates/architect/enterprise-architect.yaml +85 -0
- package/tooling/.automation/overrides/templates/architect/pragmatic-minimalist.yaml +88 -0
- package/tooling/.automation/overrides/templates/ba/README.md +27 -0
- package/tooling/.automation/overrides/templates/ba/agile-storyteller.yaml +86 -0
- package/tooling/.automation/overrides/templates/ba/domain-expert.yaml +91 -0
- package/tooling/.automation/overrides/templates/ba/requirements-engineer.yaml +89 -0
- package/tooling/.automation/overrides/templates/dev/README.md +32 -0
- package/tooling/.automation/overrides/templates/dev/junior-mentored.yaml +39 -0
- package/tooling/.automation/overrides/templates/dev/performance-engineer.yaml +43 -0
- package/tooling/.automation/overrides/templates/dev/rapid-prototyper.yaml +52 -0
- package/tooling/.automation/overrides/templates/dev/security-focused.yaml +43 -0
- package/tooling/.automation/overrides/templates/dev/senior-fullstack.yaml +39 -0
- package/tooling/.automation/overrides/templates/maintainer/README.md +27 -0
- package/tooling/.automation/overrides/templates/maintainer/devops-maintainer.yaml +113 -0
- package/tooling/.automation/overrides/templates/maintainer/legacy-steward.yaml +94 -0
- package/tooling/.automation/overrides/templates/maintainer/oss-maintainer.yaml +94 -0
- package/tooling/.automation/overrides/templates/pm/README.md +27 -0
- package/tooling/.automation/overrides/templates/pm/agile-pm.yaml +91 -0
- package/tooling/.automation/overrides/templates/pm/hybrid-delivery.yaml +87 -0
- package/tooling/.automation/overrides/templates/pm/traditional-pm.yaml +91 -0
- package/tooling/.automation/overrides/templates/reviewer/README.md +11 -0
- package/tooling/.automation/overrides/templates/reviewer/mentoring-reviewer.yaml +45 -0
- package/tooling/.automation/overrides/templates/reviewer/quick-sanity.yaml +50 -0
- package/tooling/.automation/overrides/templates/reviewer/thorough-critic.yaml +48 -0
- package/tooling/.automation/overrides/templates/sm/README.md +11 -0
- package/tooling/.automation/overrides/templates/sm/agile-coach.yaml +52 -0
- package/tooling/.automation/overrides/templates/sm/startup-pm.yaml +50 -0
- package/tooling/.automation/overrides/templates/sm/technical-lead.yaml +47 -0
- package/tooling/.automation/overrides/templates/user-profile.template.yaml +62 -0
- package/tooling/.automation/overrides/templates/writer/README.md +27 -0
- package/tooling/.automation/overrides/templates/writer/api-documentarian.yaml +99 -0
- package/tooling/.automation/overrides/templates/writer/docs-as-code.yaml +108 -0
- package/tooling/.automation/overrides/templates/writer/user-guide-author.yaml +100 -0
- package/tooling/completions/DevflowCompletion.ps1 +213 -0
- package/tooling/completions/_run-story +116 -0
- package/tooling/completions/run-story-completion.bash +136 -0
- package/tooling/docs/DOC-STANDARD.md +717 -0
- package/tooling/docs/sprint-status.yaml.template +24 -0
- package/tooling/docs/templates/bug-report.md +234 -0
- package/tooling/docs/templates/migration-spec.md +274 -0
- package/tooling/docs/templates/refactor-spec.md +86 -0
- package/tooling/docs/templates/tech-debt.md +86 -0
- package/tooling/scripts/context_checkpoint.py +556 -0
- package/tooling/scripts/cost_dashboard.py +617 -0
- package/tooling/scripts/create-persona.py +690 -0
- package/tooling/scripts/create-persona.sh +435 -0
- package/tooling/scripts/init-project-workflow.ps1 +651 -0
- package/tooling/scripts/init-project-workflow.py +70 -0
- package/tooling/scripts/init-project-workflow.sh +746 -0
- package/tooling/scripts/lib/__init__.py +35 -0
- package/tooling/scripts/lib/agent_handoff.py +526 -0
- package/tooling/scripts/lib/agent_router.py +698 -0
- package/tooling/scripts/lib/checkpoint-integration.ps1 +245 -0
- package/tooling/scripts/lib/checkpoint-integration.sh +191 -0
- package/tooling/scripts/lib/claude-cli.ps1 +952 -0
- package/tooling/scripts/lib/claude-cli.sh +1293 -0
- package/tooling/scripts/lib/cost_config.py +222 -0
- package/tooling/scripts/lib/cost_display.py +443 -0
- package/tooling/scripts/lib/cost_tracker.py +710 -0
- package/tooling/scripts/lib/currency_converter.py +328 -0
- package/tooling/scripts/lib/errors.py +438 -0
- package/tooling/scripts/lib/override-loader.sh +286 -0
- package/tooling/scripts/lib/pair_programming.py +589 -0
- package/tooling/scripts/lib/shared_memory.py +637 -0
- package/tooling/scripts/lib/swarm_orchestrator.py +689 -0
- package/tooling/scripts/memory_summarize.py +324 -0
- package/tooling/scripts/new-doc.ps1 +405 -0
- package/tooling/scripts/new-doc.py +93 -0
- package/tooling/scripts/new-doc.sh +534 -0
- package/tooling/scripts/personalize_agent.py +385 -0
- package/tooling/scripts/rollback-migration.sh +540 -0
- package/tooling/scripts/run-collab.ps1 +251 -0
- package/tooling/scripts/run-collab.py +605 -0
- package/tooling/scripts/run-collab.sh +110 -0
- package/tooling/scripts/run-story.ps1 +490 -0
- package/tooling/scripts/run-story.py +387 -0
- package/tooling/scripts/run-story.sh +467 -0
- package/tooling/scripts/setup-checkpoint-service.ps1 +219 -0
- package/tooling/scripts/setup-checkpoint-service.py +87 -0
- package/tooling/scripts/setup-checkpoint-service.sh +236 -0
- package/tooling/scripts/tech-debt-tracker.py +608 -0
- package/tooling/scripts/update_version.py +244 -0
- package/tooling/scripts/validate-overrides.py +511 -0
- package/tooling/scripts/validate-overrides.sh +432 -0
- package/tooling/scripts/validate_setup.py +539 -0
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
<#
|
|
2
|
+
.SYNOPSIS
|
|
3
|
+
Checkpoint Integration Library for Windows
|
|
4
|
+
|
|
5
|
+
.DESCRIPTION
|
|
6
|
+
Functions to integrate context checkpointing into existing automation workflows.
|
|
7
|
+
PowerShell equivalent of checkpoint-integration.sh for Windows compatibility.
|
|
8
|
+
|
|
9
|
+
.NOTES
|
|
10
|
+
Version: 1.0.0
|
|
11
|
+
Requires: PowerShell 5.1+, Python 3.9+
|
|
12
|
+
#>
|
|
13
|
+
|
|
14
|
+
#Requires -Version 5.1
|
|
15
|
+
|
|
16
|
+
# Script paths
|
|
17
|
+
$script:ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
18
|
+
$script:ProjectRoot = (Get-Item "$script:ScriptDir\..\..\.." -ErrorAction SilentlyContinue).FullName
|
|
19
|
+
if (-not $script:ProjectRoot) {
|
|
20
|
+
$script:ProjectRoot = (Get-Location).Path
|
|
21
|
+
}
|
|
22
|
+
$script:CheckpointScript = Join-Path $script:ProjectRoot "tooling\scripts\context_checkpoint.py"
|
|
23
|
+
$script:CheckpointDir = Join-Path $script:ProjectRoot "tooling\.automation\checkpoints"
|
|
24
|
+
|
|
25
|
+
#region Checkpoint Monitor Functions
|
|
26
|
+
|
|
27
|
+
function Start-CheckpointMonitor {
|
|
28
|
+
<#
|
|
29
|
+
.SYNOPSIS
|
|
30
|
+
Start checkpoint monitor in background
|
|
31
|
+
#>
|
|
32
|
+
param(
|
|
33
|
+
[Parameter(Mandatory=$true)]
|
|
34
|
+
[string]$LogFile,
|
|
35
|
+
|
|
36
|
+
[string]$SessionId = "auto"
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
if (-not (Test-Path $script:CheckpointScript)) {
|
|
40
|
+
Write-Host "!! Checkpoint script not found, skipping monitoring" -ForegroundColor Yellow
|
|
41
|
+
return $null
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
Write-Host "[i] Starting context checkpoint monitor..." -ForegroundColor Blue
|
|
45
|
+
Write-Host " Watching: $LogFile" -ForegroundColor Gray
|
|
46
|
+
|
|
47
|
+
# Start monitor as background job
|
|
48
|
+
$job = Start-Job -ScriptBlock {
|
|
49
|
+
param($script, $logFile, $sessionId)
|
|
50
|
+
python $script --watch-log $logFile --session-id $sessionId
|
|
51
|
+
} -ArgumentList $script:CheckpointScript, $LogFile, $SessionId
|
|
52
|
+
|
|
53
|
+
# Save PID to file
|
|
54
|
+
$pidFile = "$LogFile.checkpoint.pid"
|
|
55
|
+
$job.Id | Out-File -FilePath $pidFile -Force
|
|
56
|
+
|
|
57
|
+
Write-Host "[OK] Checkpoint monitor started (Job ID: $($job.Id))" -ForegroundColor Green
|
|
58
|
+
return $job.Id
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function Stop-CheckpointMonitor {
|
|
62
|
+
<#
|
|
63
|
+
.SYNOPSIS
|
|
64
|
+
Stop checkpoint monitor by PID file
|
|
65
|
+
#>
|
|
66
|
+
param(
|
|
67
|
+
[Parameter(Mandatory=$true)]
|
|
68
|
+
[string]$LogFile
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
$pidFile = "$LogFile.checkpoint.pid"
|
|
72
|
+
|
|
73
|
+
if (Test-Path $pidFile) {
|
|
74
|
+
$jobId = Get-Content $pidFile -Raw
|
|
75
|
+
$jobId = $jobId.Trim()
|
|
76
|
+
|
|
77
|
+
$job = Get-Job -Id $jobId -ErrorAction SilentlyContinue
|
|
78
|
+
if ($job) {
|
|
79
|
+
Write-Host "[i] Stopping checkpoint monitor (Job ID: $jobId)" -ForegroundColor Blue
|
|
80
|
+
Stop-Job -Id $jobId -ErrorAction SilentlyContinue
|
|
81
|
+
Remove-Job -Id $jobId -Force -ErrorAction SilentlyContinue
|
|
82
|
+
Write-Host "[OK] Checkpoint monitor stopped" -ForegroundColor Green
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
Remove-Item $pidFile -Force -ErrorAction SilentlyContinue
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
#endregion
|
|
90
|
+
|
|
91
|
+
#region Checkpoint Management Functions
|
|
92
|
+
|
|
93
|
+
function New-StoryCheckpoint {
|
|
94
|
+
<#
|
|
95
|
+
.SYNOPSIS
|
|
96
|
+
Create manual checkpoint with context
|
|
97
|
+
#>
|
|
98
|
+
param(
|
|
99
|
+
[Parameter(Mandatory=$true)]
|
|
100
|
+
[string]$StoryKey,
|
|
101
|
+
|
|
102
|
+
[string]$Reason = "manual"
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
Write-Host "[i] Creating checkpoint for story: $StoryKey" -ForegroundColor Blue
|
|
106
|
+
|
|
107
|
+
$result = python $script:CheckpointScript --checkpoint --session-id $StoryKey 2>&1
|
|
108
|
+
Write-Host $result
|
|
109
|
+
|
|
110
|
+
return $LASTEXITCODE
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function Test-HasCheckpoint {
|
|
114
|
+
<#
|
|
115
|
+
.SYNOPSIS
|
|
116
|
+
Check if checkpoint exists for story
|
|
117
|
+
#>
|
|
118
|
+
param(
|
|
119
|
+
[Parameter(Mandatory=$true)]
|
|
120
|
+
[string]$StoryKey
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
$checkpoints = Get-ChildItem -Path $script:CheckpointDir -Filter "*$StoryKey*.json" -ErrorAction SilentlyContinue
|
|
124
|
+
|
|
125
|
+
return ($null -ne $checkpoints -and $checkpoints.Count -gt 0)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function Get-LatestCheckpoint {
|
|
129
|
+
<#
|
|
130
|
+
.SYNOPSIS
|
|
131
|
+
Get latest checkpoint for story
|
|
132
|
+
#>
|
|
133
|
+
param(
|
|
134
|
+
[Parameter(Mandatory=$true)]
|
|
135
|
+
[string]$StoryKey
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
$checkpoints = Get-ChildItem -Path $script:CheckpointDir -Filter "*$StoryKey*.json" -ErrorAction SilentlyContinue |
|
|
139
|
+
Sort-Object LastWriteTime -Descending |
|
|
140
|
+
Select-Object -First 1
|
|
141
|
+
|
|
142
|
+
if ($checkpoints) {
|
|
143
|
+
return $checkpoints.FullName
|
|
144
|
+
}
|
|
145
|
+
return $null
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function Resume-FromCheckpoint {
|
|
149
|
+
<#
|
|
150
|
+
.SYNOPSIS
|
|
151
|
+
Resume from latest checkpoint
|
|
152
|
+
#>
|
|
153
|
+
param(
|
|
154
|
+
[Parameter(Mandatory=$true)]
|
|
155
|
+
[string]$StoryKey
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
$checkpointFile = Get-LatestCheckpoint -StoryKey $StoryKey
|
|
159
|
+
|
|
160
|
+
if (-not $checkpointFile) {
|
|
161
|
+
Write-Host "X No checkpoint found for story: $StoryKey" -ForegroundColor Red
|
|
162
|
+
return 1
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
$checkpointId = [System.IO.Path]::GetFileNameWithoutExtension($checkpointFile)
|
|
166
|
+
|
|
167
|
+
Write-Host "[i] Resuming from checkpoint: $checkpointId" -ForegroundColor Blue
|
|
168
|
+
|
|
169
|
+
python $script:CheckpointScript --resume $checkpointId
|
|
170
|
+
|
|
171
|
+
return $LASTEXITCODE
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function Remove-OldCheckpoints {
|
|
175
|
+
<#
|
|
176
|
+
.SYNOPSIS
|
|
177
|
+
Clean up old checkpoints (keep last N)
|
|
178
|
+
#>
|
|
179
|
+
param(
|
|
180
|
+
[int]$KeepCount = 10
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
Write-Host "[i] Cleaning up old checkpoints (keeping last $KeepCount)..." -ForegroundColor Blue
|
|
184
|
+
|
|
185
|
+
$checkpoints = Get-ChildItem -Path $script:CheckpointDir -Filter "checkpoint_*.json" -ErrorAction SilentlyContinue |
|
|
186
|
+
Sort-Object LastWriteTime -Descending
|
|
187
|
+
|
|
188
|
+
if (-not $checkpoints -or $checkpoints.Count -le $KeepCount) {
|
|
189
|
+
Write-Host "[OK] No cleanup needed ($($checkpoints.Count) checkpoints)" -ForegroundColor Green
|
|
190
|
+
return
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
$toDelete = $checkpoints | Select-Object -Skip $KeepCount
|
|
194
|
+
$deleteCount = $toDelete.Count
|
|
195
|
+
|
|
196
|
+
foreach ($file in $toDelete) {
|
|
197
|
+
$summaryFile = $file.FullName -replace '\.json$', '_summary.md'
|
|
198
|
+
Remove-Item $file.FullName -Force -ErrorAction SilentlyContinue
|
|
199
|
+
Remove-Item $summaryFile -Force -ErrorAction SilentlyContinue
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
Write-Host "[OK] Deleted $deleteCount old checkpoints" -ForegroundColor Green
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
#endregion
|
|
206
|
+
|
|
207
|
+
#region Logging Functions
|
|
208
|
+
|
|
209
|
+
function Write-CheckpointInfo {
|
|
210
|
+
<#
|
|
211
|
+
.SYNOPSIS
|
|
212
|
+
Add checkpoint info to log
|
|
213
|
+
#>
|
|
214
|
+
param(
|
|
215
|
+
[Parameter(Mandatory=$true)]
|
|
216
|
+
[string]$LogFile
|
|
217
|
+
)
|
|
218
|
+
|
|
219
|
+
$info = @"
|
|
220
|
+
|
|
221
|
+
===============================================================
|
|
222
|
+
CONTEXT CHECKPOINT MONITORING ACTIVE
|
|
223
|
+
===============================================================
|
|
224
|
+
|
|
225
|
+
Thresholds:
|
|
226
|
+
* Warning: 75% - Log notification
|
|
227
|
+
!! Critical: 85% - Auto-checkpoint created
|
|
228
|
+
XX Emergency: 95% - Force checkpoint + alert
|
|
229
|
+
|
|
230
|
+
Checkpoint directory: $script:CheckpointDir
|
|
231
|
+
|
|
232
|
+
To manually checkpoint: python tooling\scripts\context_checkpoint.py --checkpoint
|
|
233
|
+
To list checkpoints: python tooling\scripts\context_checkpoint.py --list
|
|
234
|
+
|
|
235
|
+
===============================================================
|
|
236
|
+
|
|
237
|
+
"@
|
|
238
|
+
|
|
239
|
+
Add-Content -Path $LogFile -Value $info
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
#endregion
|
|
243
|
+
|
|
244
|
+
# Export functions
|
|
245
|
+
Export-ModuleMember -Function * -ErrorAction SilentlyContinue
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
################################################################################
|
|
3
|
+
# Checkpoint Integration Library
|
|
4
|
+
#
|
|
5
|
+
# Functions to integrate context checkpointing into existing automation workflows
|
|
6
|
+
################################################################################
|
|
7
|
+
|
|
8
|
+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
9
|
+
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
|
10
|
+
CHECKPOINT_SCRIPT="$PROJECT_ROOT/tooling/scripts/context_checkpoint.py"
|
|
11
|
+
CHECKPOINT_DIR="$PROJECT_ROOT/tooling/.automation/checkpoints"
|
|
12
|
+
|
|
13
|
+
################################################################################
|
|
14
|
+
# Start checkpoint monitor in background
|
|
15
|
+
################################################################################
|
|
16
|
+
start_checkpoint_monitor() {
|
|
17
|
+
local log_file="$1"
|
|
18
|
+
local session_id="${2:-auto}"
|
|
19
|
+
|
|
20
|
+
if [[ ! -f "$CHECKPOINT_SCRIPT" ]]; then
|
|
21
|
+
echo "โ ๏ธ Checkpoint script not found, skipping monitoring"
|
|
22
|
+
return 1
|
|
23
|
+
fi
|
|
24
|
+
|
|
25
|
+
echo "๐ Starting context checkpoint monitor..."
|
|
26
|
+
echo " Watching: $log_file"
|
|
27
|
+
|
|
28
|
+
# Start monitor in background
|
|
29
|
+
python3 "$CHECKPOINT_SCRIPT" \
|
|
30
|
+
--watch-log "$log_file" \
|
|
31
|
+
--session-id "$session_id" \
|
|
32
|
+
2>&1 > /dev/null &
|
|
33
|
+
|
|
34
|
+
local monitor_pid=$!
|
|
35
|
+
echo "$monitor_pid" > "${log_file}.checkpoint.pid"
|
|
36
|
+
|
|
37
|
+
echo "โ
Checkpoint monitor started (PID: $monitor_pid)"
|
|
38
|
+
return 0
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
################################################################################
|
|
42
|
+
# Stop checkpoint monitor
|
|
43
|
+
################################################################################
|
|
44
|
+
stop_checkpoint_monitor() {
|
|
45
|
+
local log_file="$1"
|
|
46
|
+
local pid_file="${log_file}.checkpoint.pid"
|
|
47
|
+
|
|
48
|
+
if [[ -f "$pid_file" ]]; then
|
|
49
|
+
local pid=$(cat "$pid_file")
|
|
50
|
+
if kill -0 "$pid" 2>/dev/null; then
|
|
51
|
+
echo "๐ Stopping checkpoint monitor (PID: $pid)"
|
|
52
|
+
kill "$pid" 2>/dev/null || true
|
|
53
|
+
rm -f "$pid_file"
|
|
54
|
+
echo "โ
Checkpoint monitor stopped"
|
|
55
|
+
else
|
|
56
|
+
rm -f "$pid_file"
|
|
57
|
+
fi
|
|
58
|
+
fi
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
################################################################################
|
|
62
|
+
# Create manual checkpoint with context
|
|
63
|
+
################################################################################
|
|
64
|
+
create_story_checkpoint() {
|
|
65
|
+
local story_key="$1"
|
|
66
|
+
local reason="${2:-manual}"
|
|
67
|
+
|
|
68
|
+
echo "๐พ Creating checkpoint for story: $story_key"
|
|
69
|
+
|
|
70
|
+
python3 "$CHECKPOINT_SCRIPT" \
|
|
71
|
+
--checkpoint \
|
|
72
|
+
--session-id "$story_key" \
|
|
73
|
+
2>&1
|
|
74
|
+
|
|
75
|
+
return $?
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
################################################################################
|
|
79
|
+
# Check if checkpoint exists for story
|
|
80
|
+
################################################################################
|
|
81
|
+
has_checkpoint() {
|
|
82
|
+
local story_key="$1"
|
|
83
|
+
|
|
84
|
+
local checkpoints=$(find "$CHECKPOINT_DIR" -name "*${story_key}*.json" 2>/dev/null)
|
|
85
|
+
|
|
86
|
+
if [[ -n "$checkpoints" ]]; then
|
|
87
|
+
return 0
|
|
88
|
+
else
|
|
89
|
+
return 1
|
|
90
|
+
fi
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
################################################################################
|
|
94
|
+
# Get latest checkpoint for story
|
|
95
|
+
################################################################################
|
|
96
|
+
get_latest_checkpoint() {
|
|
97
|
+
local story_key="$1"
|
|
98
|
+
|
|
99
|
+
find "$CHECKPOINT_DIR" -name "*${story_key}*.json" 2>/dev/null | \
|
|
100
|
+
sort -r | \
|
|
101
|
+
head -1
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
################################################################################
|
|
105
|
+
# Resume from latest checkpoint
|
|
106
|
+
################################################################################
|
|
107
|
+
resume_from_checkpoint() {
|
|
108
|
+
local story_key="$1"
|
|
109
|
+
|
|
110
|
+
local checkpoint_file=$(get_latest_checkpoint "$story_key")
|
|
111
|
+
|
|
112
|
+
if [[ -z "$checkpoint_file" ]]; then
|
|
113
|
+
echo "โ No checkpoint found for story: $story_key"
|
|
114
|
+
return 1
|
|
115
|
+
fi
|
|
116
|
+
|
|
117
|
+
local checkpoint_id=$(basename "$checkpoint_file" .json)
|
|
118
|
+
|
|
119
|
+
echo "๐ Resuming from checkpoint: $checkpoint_id"
|
|
120
|
+
|
|
121
|
+
python3 "$CHECKPOINT_SCRIPT" \
|
|
122
|
+
--resume "$checkpoint_id"
|
|
123
|
+
|
|
124
|
+
return $?
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
################################################################################
|
|
128
|
+
# Clean up old checkpoints (keep last N)
|
|
129
|
+
################################################################################
|
|
130
|
+
cleanup_old_checkpoints() {
|
|
131
|
+
local keep_count="${1:-10}"
|
|
132
|
+
|
|
133
|
+
echo "๐งน Cleaning up old checkpoints (keeping last $keep_count)..."
|
|
134
|
+
|
|
135
|
+
local checkpoints=$(find "$CHECKPOINT_DIR" -name "checkpoint_*.json" | sort -r)
|
|
136
|
+
local total=$(echo "$checkpoints" | wc -l | tr -d ' ')
|
|
137
|
+
|
|
138
|
+
if [[ $total -le $keep_count ]]; then
|
|
139
|
+
echo "โ
No cleanup needed ($total checkpoints)"
|
|
140
|
+
return 0
|
|
141
|
+
fi
|
|
142
|
+
|
|
143
|
+
local to_delete=$(echo "$checkpoints" | tail -n +$((keep_count + 1)))
|
|
144
|
+
local delete_count=$(echo "$to_delete" | wc -l | tr -d ' ')
|
|
145
|
+
|
|
146
|
+
echo "$to_delete" | while read -r file; do
|
|
147
|
+
local summary_file="${file%.json}_summary.md"
|
|
148
|
+
rm -f "$file" "$summary_file"
|
|
149
|
+
done
|
|
150
|
+
|
|
151
|
+
echo "โ
Deleted $delete_count old checkpoints"
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
################################################################################
|
|
155
|
+
# Add checkpoint info to log
|
|
156
|
+
################################################################################
|
|
157
|
+
log_checkpoint_info() {
|
|
158
|
+
local log_file="$1"
|
|
159
|
+
|
|
160
|
+
cat >> "$log_file" <<EOF
|
|
161
|
+
|
|
162
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
163
|
+
CONTEXT CHECKPOINT MONITORING ACTIVE
|
|
164
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
165
|
+
|
|
166
|
+
Thresholds:
|
|
167
|
+
โก Warning: 75% - Log notification
|
|
168
|
+
โ ๏ธ Critical: 85% - Auto-checkpoint created
|
|
169
|
+
๐จ Emergency: 95% - Force checkpoint + alert
|
|
170
|
+
|
|
171
|
+
Checkpoint directory: $CHECKPOINT_DIR
|
|
172
|
+
|
|
173
|
+
To manually checkpoint: ./tooling/scripts/checkpoint --checkpoint
|
|
174
|
+
To list checkpoints: ./tooling/scripts/checkpoint --list
|
|
175
|
+
|
|
176
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
177
|
+
|
|
178
|
+
EOF
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
################################################################################
|
|
182
|
+
# Export functions
|
|
183
|
+
################################################################################
|
|
184
|
+
export -f start_checkpoint_monitor
|
|
185
|
+
export -f stop_checkpoint_monitor
|
|
186
|
+
export -f create_story_checkpoint
|
|
187
|
+
export -f has_checkpoint
|
|
188
|
+
export -f get_latest_checkpoint
|
|
189
|
+
export -f resume_from_checkpoint
|
|
190
|
+
export -f cleanup_old_checkpoints
|
|
191
|
+
export -f log_checkpoint_info
|