@orchestrator-claude/cli 1.4.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.
Files changed (176) hide show
  1. package/README.md +74 -0
  2. package/dist/api-client/OrchestratorAPIClient.d.ts +111 -0
  3. package/dist/api-client/OrchestratorAPIClient.d.ts.map +1 -0
  4. package/dist/api-client/OrchestratorAPIClient.js +176 -0
  5. package/dist/api-client/OrchestratorAPIClient.js.map +1 -0
  6. package/dist/api-client/index.d.ts +11 -0
  7. package/dist/api-client/index.d.ts.map +1 -0
  8. package/dist/api-client/index.js +10 -0
  9. package/dist/api-client/index.js.map +1 -0
  10. package/dist/api-client/retry.d.ts +29 -0
  11. package/dist/api-client/retry.d.ts.map +1 -0
  12. package/dist/api-client/retry.js +85 -0
  13. package/dist/api-client/retry.js.map +1 -0
  14. package/dist/api-client/types.d.ts +148 -0
  15. package/dist/api-client/types.d.ts.map +1 -0
  16. package/dist/api-client/types.js +10 -0
  17. package/dist/api-client/types.js.map +1 -0
  18. package/dist/commands/AgentsCommand.d.ts +74 -0
  19. package/dist/commands/AgentsCommand.d.ts.map +1 -0
  20. package/dist/commands/AgentsCommand.js +170 -0
  21. package/dist/commands/AgentsCommand.js.map +1 -0
  22. package/dist/commands/InitCommand.d.ts +63 -0
  23. package/dist/commands/InitCommand.d.ts.map +1 -0
  24. package/dist/commands/InitCommand.js +150 -0
  25. package/dist/commands/InitCommand.js.map +1 -0
  26. package/dist/commands/MigrateCommand.d.ts +93 -0
  27. package/dist/commands/MigrateCommand.d.ts.map +1 -0
  28. package/dist/commands/MigrateCommand.js +260 -0
  29. package/dist/commands/MigrateCommand.js.map +1 -0
  30. package/dist/commands/StatusCommand.d.ts +61 -0
  31. package/dist/commands/StatusCommand.d.ts.map +1 -0
  32. package/dist/commands/StatusCommand.js +142 -0
  33. package/dist/commands/StatusCommand.js.map +1 -0
  34. package/dist/commands/TemplatesCommand.d.ts +69 -0
  35. package/dist/commands/TemplatesCommand.d.ts.map +1 -0
  36. package/dist/commands/TemplatesCommand.js +147 -0
  37. package/dist/commands/TemplatesCommand.js.map +1 -0
  38. package/dist/commands/WorkflowCommand.d.ts +82 -0
  39. package/dist/commands/WorkflowCommand.d.ts.map +1 -0
  40. package/dist/commands/WorkflowCommand.js +203 -0
  41. package/dist/commands/WorkflowCommand.js.map +1 -0
  42. package/dist/config/CLIConfig.d.ts +66 -0
  43. package/dist/config/CLIConfig.d.ts.map +1 -0
  44. package/dist/config/CLIConfig.js +60 -0
  45. package/dist/config/CLIConfig.js.map +1 -0
  46. package/dist/formatters/OutputFormatter.d.ts +102 -0
  47. package/dist/formatters/OutputFormatter.d.ts.map +1 -0
  48. package/dist/formatters/OutputFormatter.js +182 -0
  49. package/dist/formatters/OutputFormatter.js.map +1 -0
  50. package/dist/index.d.ts +15 -0
  51. package/dist/index.d.ts.map +1 -0
  52. package/dist/index.js +249 -0
  53. package/dist/index.js.map +1 -0
  54. package/dist/templates/.gitkeep +0 -0
  55. package/dist/templates/TemplateEngine.d.ts +90 -0
  56. package/dist/templates/TemplateEngine.d.ts.map +1 -0
  57. package/dist/templates/TemplateEngine.js +149 -0
  58. package/dist/templates/TemplateEngine.js.map +1 -0
  59. package/dist/templates/base/CLAUDE.md.hbs +362 -0
  60. package/dist/templates/base/claude/agents/implementer.md +446 -0
  61. package/dist/templates/base/claude/agents/orchestrator.md +155 -0
  62. package/dist/templates/base/claude/agents/planner.md +348 -0
  63. package/dist/templates/base/claude/agents/researcher.md +390 -0
  64. package/dist/templates/base/claude/agents/reviewer.md +444 -0
  65. package/dist/templates/base/claude/agents/specifier.md +331 -0
  66. package/dist/templates/base/claude/agents/task-generator.md +382 -0
  67. package/dist/templates/base/claude/hooks/post-artifact-generate.sh +39 -0
  68. package/dist/templates/base/claude/hooks/post-implement-validate.sh +139 -0
  69. package/dist/templates/base/claude/hooks/post-phase-checkpoint.sh +322 -0
  70. package/dist/templates/base/claude/hooks/pre-agent-invoke.sh +34 -0
  71. package/dist/templates/base/claude/hooks/pre-phase-advance.sh +40 -0
  72. package/dist/templates/base/claude/hooks/track-agent-invocation.sh +230 -0
  73. package/dist/templates/base/claude/orchestrator-config.json +141 -0
  74. package/dist/templates/base/claude/settings.json +80 -0
  75. package/dist/templates/base/claude/skills/artifact-validator/SKILL.md +226 -0
  76. package/dist/templates/base/claude/skills/docs-guardian/SKILL.md +230 -0
  77. package/dist/templates/base/claude/skills/kb-lookup/SKILL.md +257 -0
  78. package/dist/templates/base/claude/skills/phase-gate-evaluator/SKILL.md +274 -0
  79. package/dist/templates/base/claude/skills/workflow-status/SKILL.md +322 -0
  80. package/dist/templates/base/docker-compose.yml.hbs +20 -0
  81. package/dist/templates/base/mcp.json.hbs +37 -0
  82. package/dist/templates/base/orchestrator/.state/.gitkeep +0 -0
  83. package/dist/templates/base/orchestrator-index.json.hbs +37 -0
  84. package/dist/templates/base/package.json.hbs +40 -0
  85. package/dist/templates/default/.orchestrator/orchestrator-index.json +19 -0
  86. package/dist/templates/default/README.md +58 -0
  87. package/dist/templates/default/docker-compose.yml +24 -0
  88. package/dist/templates/default/template.json +10 -0
  89. package/dist/templates/projects/api/files/index.ts.hbs +30 -0
  90. package/dist/templates/projects/api/files/server.ts.hbs +63 -0
  91. package/dist/templates/projects/api/files/tsconfig.json.hbs +27 -0
  92. package/dist/templates/projects/api/files/vitest.config.ts.hbs +28 -0
  93. package/dist/templates/projects/api/template.config.json +238 -0
  94. package/dist/templates/projects/api/template.config.ts +149 -0
  95. package/dist/templates/projects/cli/files/cli.ts.hbs +50 -0
  96. package/dist/templates/projects/cli/files/index.ts.hbs +8 -0
  97. package/dist/templates/projects/cli/files/tsconfig.json.hbs +27 -0
  98. package/dist/templates/projects/cli/files/vitest.config.ts.hbs +28 -0
  99. package/dist/templates/projects/cli/template.config.json +213 -0
  100. package/dist/templates/projects/cli/template.config.ts +126 -0
  101. package/dist/templates/projects/frontend/files/App.tsx.hbs +31 -0
  102. package/dist/templates/projects/frontend/files/index.html.hbs +13 -0
  103. package/dist/templates/projects/frontend/files/main.tsx.hbs +22 -0
  104. package/dist/templates/projects/frontend/files/tsconfig.json.hbs +34 -0
  105. package/dist/templates/projects/frontend/files/tsconfig.node.json.hbs +10 -0
  106. package/dist/templates/projects/frontend/files/vite.config.ts.hbs +19 -0
  107. package/dist/templates/projects/frontend/files/vitest.config.ts.hbs +36 -0
  108. package/dist/templates/projects/frontend/template.config.json +241 -0
  109. package/dist/templates/projects/frontend/template.config.ts +153 -0
  110. package/dist/templates/projects/minimal/files/claude-settings.json.hbs +20 -0
  111. package/dist/templates/projects/minimal/files/env.example.hbs +17 -0
  112. package/dist/templates/projects/minimal/files/gitignore.hbs +41 -0
  113. package/dist/templates/projects/minimal/files/index.ts.hbs +13 -0
  114. package/dist/templates/projects/minimal/files/tsconfig.json.hbs +27 -0
  115. package/dist/templates/projects/minimal/template.config.json +185 -0
  116. package/dist/templates/projects/minimal/template.config.ts +88 -0
  117. package/package.json +37 -0
  118. package/templates/.gitkeep +0 -0
  119. package/templates/base/CLAUDE.md.hbs +362 -0
  120. package/templates/base/claude/agents/implementer.md +446 -0
  121. package/templates/base/claude/agents/orchestrator.md +155 -0
  122. package/templates/base/claude/agents/planner.md +348 -0
  123. package/templates/base/claude/agents/researcher.md +390 -0
  124. package/templates/base/claude/agents/reviewer.md +444 -0
  125. package/templates/base/claude/agents/specifier.md +331 -0
  126. package/templates/base/claude/agents/task-generator.md +382 -0
  127. package/templates/base/claude/hooks/post-artifact-generate.sh +39 -0
  128. package/templates/base/claude/hooks/post-implement-validate.sh +139 -0
  129. package/templates/base/claude/hooks/post-phase-checkpoint.sh +322 -0
  130. package/templates/base/claude/hooks/pre-agent-invoke.sh +34 -0
  131. package/templates/base/claude/hooks/pre-phase-advance.sh +40 -0
  132. package/templates/base/claude/hooks/track-agent-invocation.sh +230 -0
  133. package/templates/base/claude/orchestrator-config.json +141 -0
  134. package/templates/base/claude/settings.json +80 -0
  135. package/templates/base/claude/skills/artifact-validator/SKILL.md +226 -0
  136. package/templates/base/claude/skills/docs-guardian/SKILL.md +230 -0
  137. package/templates/base/claude/skills/kb-lookup/SKILL.md +257 -0
  138. package/templates/base/claude/skills/phase-gate-evaluator/SKILL.md +274 -0
  139. package/templates/base/claude/skills/workflow-status/SKILL.md +322 -0
  140. package/templates/base/docker-compose.yml.hbs +20 -0
  141. package/templates/base/mcp.json.hbs +37 -0
  142. package/templates/base/orchestrator/.state/.gitkeep +0 -0
  143. package/templates/base/orchestrator-index.json.hbs +37 -0
  144. package/templates/base/package.json.hbs +40 -0
  145. package/templates/default/.orchestrator/orchestrator-index.json +19 -0
  146. package/templates/default/README.md +58 -0
  147. package/templates/default/docker-compose.yml +24 -0
  148. package/templates/default/template.json +10 -0
  149. package/templates/projects/api/files/index.ts.hbs +30 -0
  150. package/templates/projects/api/files/server.ts.hbs +63 -0
  151. package/templates/projects/api/files/tsconfig.json.hbs +27 -0
  152. package/templates/projects/api/files/vitest.config.ts.hbs +28 -0
  153. package/templates/projects/api/template.config.json +238 -0
  154. package/templates/projects/api/template.config.ts +149 -0
  155. package/templates/projects/cli/files/cli.ts.hbs +50 -0
  156. package/templates/projects/cli/files/index.ts.hbs +8 -0
  157. package/templates/projects/cli/files/tsconfig.json.hbs +27 -0
  158. package/templates/projects/cli/files/vitest.config.ts.hbs +28 -0
  159. package/templates/projects/cli/template.config.json +213 -0
  160. package/templates/projects/cli/template.config.ts +126 -0
  161. package/templates/projects/frontend/files/App.tsx.hbs +31 -0
  162. package/templates/projects/frontend/files/index.html.hbs +13 -0
  163. package/templates/projects/frontend/files/main.tsx.hbs +22 -0
  164. package/templates/projects/frontend/files/tsconfig.json.hbs +34 -0
  165. package/templates/projects/frontend/files/tsconfig.node.json.hbs +10 -0
  166. package/templates/projects/frontend/files/vite.config.ts.hbs +19 -0
  167. package/templates/projects/frontend/files/vitest.config.ts.hbs +36 -0
  168. package/templates/projects/frontend/template.config.json +241 -0
  169. package/templates/projects/frontend/template.config.ts +153 -0
  170. package/templates/projects/minimal/files/claude-settings.json.hbs +20 -0
  171. package/templates/projects/minimal/files/env.example.hbs +17 -0
  172. package/templates/projects/minimal/files/gitignore.hbs +41 -0
  173. package/templates/projects/minimal/files/index.ts.hbs +13 -0
  174. package/templates/projects/minimal/files/tsconfig.json.hbs +27 -0
  175. package/templates/projects/minimal/template.config.json +185 -0
  176. package/templates/projects/minimal/template.config.ts +88 -0
@@ -0,0 +1,39 @@
1
+ #!/bin/bash
2
+ # Post-Artifact Generate Hook
3
+ # Executado apos geracao de um artefato
4
+ # Valida artefato, atualiza indice, cria checkpoint
5
+
6
+ set -e
7
+
8
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9
+ PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
10
+
11
+ # Recebe evento via stdin ou argumento
12
+ if [ -n "$1" ]; then
13
+ EVENT="$1"
14
+ else
15
+ EVENT=$(cat)
16
+ fi
17
+
18
+ # Verifica se temos o handler compilado
19
+ HANDLER="$PROJECT_ROOT/dist/hook.js"
20
+
21
+ if [ ! -f "$HANDLER" ]; then
22
+ echo '{"success": false, "error": "Hook handler not compiled. Run npm run build first."}' >&2
23
+ exit 1
24
+ fi
25
+
26
+ # Executa o handler TypeScript
27
+ echo "$EVENT" | node "$HANDLER" post-artifact
28
+
29
+ EXIT_CODE=$?
30
+
31
+ # Log do resultado
32
+ if [ $EXIT_CODE -eq 0 ]; then
33
+ echo "[post-artifact-generate] Artifact processed successfully" >&2
34
+ else
35
+ echo "[post-artifact-generate] Warning: Artifact processing had issues" >&2
36
+ fi
37
+
38
+ # Este hook nao bloqueia, apenas avisa
39
+ exit 0
@@ -0,0 +1,139 @@
1
+ #!/bin/bash
2
+ # Post-Implement Validation Hook
3
+ # Validates orchestrator-index.json consistency after IMPLEMENT phase
4
+ # Detects possible delegation bypass where code was written directly
5
+ # instead of through the implementer subagent
6
+ #
7
+ # Exit codes:
8
+ # 0 = Validation passed or skipped (jq not available)
9
+ # 1 = Warning detected (possible delegation bypass)
10
+ #
11
+ # Author: Orchestrator System
12
+ # Version: 1.0.0
13
+
14
+ set -e
15
+
16
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
17
+ PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
18
+ INDEX_FILE="$PROJECT_ROOT/.orchestrator/orchestrator-index.json"
19
+
20
+ # Colors for output
21
+ RED='\033[0;31m'
22
+ YELLOW='\033[1;33m'
23
+ GREEN='\033[0;32m'
24
+ CYAN='\033[0;36m'
25
+ NC='\033[0m' # No Color
26
+
27
+ log_info() {
28
+ echo -e "${GREEN}[post-implement-validate]${NC} $1" >&2
29
+ }
30
+
31
+ log_warn() {
32
+ echo -e "${YELLOW}[post-implement-validate] WARNING:${NC} $1" >&2
33
+ }
34
+
35
+ log_error() {
36
+ echo -e "${RED}[post-implement-validate] ERROR:${NC} $1" >&2
37
+ }
38
+
39
+ log_debug() {
40
+ if [ "${DEBUG:-false}" = "true" ]; then
41
+ echo -e "${CYAN}[post-implement-validate] DEBUG:${NC} $1" >&2
42
+ fi
43
+ }
44
+
45
+ # Check if jq is available
46
+ if ! command -v jq &> /dev/null; then
47
+ log_warn "jq not found, skipping validation (install jq for full validation)"
48
+ exit 0
49
+ fi
50
+
51
+ # Check if orchestrator-index.json exists
52
+ if [ ! -f "$INDEX_FILE" ]; then
53
+ log_debug "orchestrator-index.json not found at $INDEX_FILE, skipping validation"
54
+ exit 0
55
+ fi
56
+
57
+ # Read statistics from orchestrator-index.json
58
+ TASKS_COMPLETED=$(jq -r '.statistics.tasksCompleted // 0' "$INDEX_FILE" 2>/dev/null || echo "0")
59
+ TASKS_PENDING=$(jq -r '.statistics.tasksPending // 0' "$INDEX_FILE" 2>/dev/null || echo "0")
60
+ CURRENT_PHASE=$(jq -r '.activeWorkflow.currentPhase // "unknown"' "$INDEX_FILE" 2>/dev/null || echo "unknown")
61
+ STATUS=$(jq -r '.activeWorkflow.status // "unknown"' "$INDEX_FILE" 2>/dev/null || echo "unknown")
62
+
63
+ # Count TypeScript files in src/ (if directory exists)
64
+ TS_FILES_COUNT=0
65
+ if [ -d "$PROJECT_ROOT/src" ]; then
66
+ TS_FILES_COUNT=$(find "$PROJECT_ROOT/src" -name "*.ts" 2>/dev/null | wc -l | tr -d ' ' || echo "0")
67
+ fi
68
+
69
+ # Count test files
70
+ TEST_FILES_COUNT=0
71
+ if [ -d "$PROJECT_ROOT/tests" ]; then
72
+ TEST_FILES_COUNT=$(find "$PROJECT_ROOT/tests" -name "*.spec.ts" -o -name "*.test.ts" 2>/dev/null | wc -l | tr -d ' ' || echo "0")
73
+ fi
74
+
75
+ log_info "Validating IMPLEMENT phase consistency..."
76
+ log_info " Current Phase: $CURRENT_PHASE"
77
+ log_info " Status: $STATUS"
78
+ log_info " Tasks Completed: $TASKS_COMPLETED"
79
+ log_info " Tasks Pending: $TASKS_PENDING"
80
+ log_info " TypeScript Files: $TS_FILES_COUNT"
81
+ log_info " Test Files: $TEST_FILES_COUNT"
82
+
83
+ # Detection logic
84
+ WARNINGS=0
85
+ MESSAGES=()
86
+
87
+ # Check 1: Few tasks completed but many pending (primary indicator)
88
+ if [ "$TASKS_COMPLETED" -le 1 ] && [ "$TASKS_PENDING" -gt 5 ]; then
89
+ MESSAGES+=("Only $TASKS_COMPLETED task(s) completed but $TASKS_PENDING pending.")
90
+ MESSAGES+=("This suggests the implementer agent may not have been properly invoked.")
91
+ WARNINGS=$((WARNINGS + 1))
92
+ fi
93
+
94
+ # Check 2: Many source files but few tasks completed
95
+ if [ "$TS_FILES_COUNT" -gt 10 ] && [ "$TASKS_COMPLETED" -lt 5 ]; then
96
+ MESSAGES+=("Found $TS_FILES_COUNT TypeScript files but only $TASKS_COMPLETED tasks completed.")
97
+ MESSAGES+=("Code may have been generated without proper task tracking.")
98
+ WARNINGS=$((WARNINGS + 1))
99
+ fi
100
+
101
+ # Check 3: Status still "ready_for_implementation" after code exists
102
+ if [ "$STATUS" = "ready_for_implementation" ] && [ "$TS_FILES_COUNT" -gt 5 ]; then
103
+ MESSAGES+=("Status is still 'ready_for_implementation' but $TS_FILES_COUNT code files exist.")
104
+ MESSAGES+=("Workflow state may not have been updated correctly.")
105
+ WARNINGS=$((WARNINGS + 1))
106
+ fi
107
+
108
+ # Check 4: Source files exist but no test files (TDD violation)
109
+ if [ "$TS_FILES_COUNT" -gt 5 ] && [ "$TEST_FILES_COUNT" -eq 0 ]; then
110
+ MESSAGES+=("Found $TS_FILES_COUNT source files but no test files.")
111
+ MESSAGES+=("TDD methodology may not have been followed.")
112
+ WARNINGS=$((WARNINGS + 1))
113
+ fi
114
+
115
+ # Summary
116
+ if [ "$WARNINGS" -gt 0 ]; then
117
+ echo "" >&2
118
+ log_warn "============================================"
119
+ log_warn "Detected $WARNINGS potential issue(s):"
120
+ log_warn "============================================"
121
+ for msg in "${MESSAGES[@]}"; do
122
+ log_warn " - $msg"
123
+ done
124
+ echo "" >&2
125
+ log_warn "Possible causes:"
126
+ log_warn " 1. Implementer agent was not invoked via Task tool"
127
+ log_warn " 2. Code was written directly instead of through delegation"
128
+ log_warn " 3. orchestrator-index.json was not updated during implementation"
129
+ echo "" >&2
130
+ log_warn "Recommended actions:"
131
+ log_warn " 1. Review CLAUDE.md section: MANDATORY: IMPLEMENT Phase Delegation"
132
+ log_warn " 2. Ensure Task tool is used with subagent_type='implementer'"
133
+ log_warn " 3. Update orchestrator-index.json with correct task progress"
134
+ echo "" >&2
135
+ exit 1
136
+ else
137
+ log_info "Validation passed. No issues detected."
138
+ exit 0
139
+ fi
@@ -0,0 +1,322 @@
1
+ #!/bin/bash
2
+ # Post-Phase Checkpoint Hook
3
+ # Automatically creates git checkpoints when workflow phases complete
4
+ #
5
+ # Triggered by: PostToolUse on Task tool (after agent completes)
6
+ # Behavior: Detects phase transitions and creates git commits
7
+ #
8
+ # Requirements:
9
+ # - jq (for JSON parsing)
10
+ # - git (for checkpoint commits)
11
+ #
12
+ # Debug mode: ORCH_CHECKPOINT_DEBUG=1 to enable verbose logging
13
+
14
+ set -e
15
+
16
+ # Configuration
17
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
18
+ PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
19
+ INDEX_FILE="$PROJECT_ROOT/.orchestrator/orchestrator-index.json"
20
+ STATE_DIR="$PROJECT_ROOT/.orchestrator/.state"
21
+ LOG_FILE="$STATE_DIR/checkpoint-hook.log"
22
+ LAST_PHASE_FILE="$STATE_DIR/last-checkpointed-phase"
23
+
24
+ # Ensure state directory exists
25
+ mkdir -p "$STATE_DIR"
26
+
27
+ # Debug mode
28
+ DEBUG="${ORCH_CHECKPOINT_DEBUG:-0}"
29
+
30
+ # Logging functions
31
+ log_debug() {
32
+ if [ "$DEBUG" = "1" ]; then
33
+ echo "[$(date -u +%Y-%m-%dT%H:%M:%SZ)] [DEBUG] $1" >> "$LOG_FILE"
34
+ echo "[DEBUG] $1" >&2
35
+ fi
36
+ }
37
+
38
+ log_info() {
39
+ echo "[$(date -u +%Y-%m-%dT%H:%M:%SZ)] [INFO] $1" >> "$LOG_FILE"
40
+ if [ "$DEBUG" = "1" ]; then
41
+ echo "[INFO] $1" >&2
42
+ fi
43
+ }
44
+
45
+ log_warn() {
46
+ echo "[$(date -u +%Y-%m-%dT%H:%M:%SZ)] [WARN] $1" >> "$LOG_FILE"
47
+ echo "[WARN] $1" >&2
48
+ }
49
+
50
+ log_error() {
51
+ echo "[$(date -u +%Y-%m-%dT%H:%M:%SZ)] [ERROR] $1" >> "$LOG_FILE"
52
+ echo "[ERROR] $1" >&2
53
+ }
54
+
55
+ # Check prerequisites
56
+ check_prerequisites() {
57
+ # Check jq
58
+ if ! command -v jq &> /dev/null; then
59
+ log_error "jq is not installed. Checkpoints disabled."
60
+ return 1
61
+ fi
62
+
63
+ # Check git
64
+ if ! command -v git &> /dev/null; then
65
+ log_error "git is not installed. Checkpoints disabled."
66
+ return 1
67
+ fi
68
+
69
+ # Check if we're in a git repo
70
+ if ! git -C "$PROJECT_ROOT" rev-parse --is-inside-work-tree &> /dev/null; then
71
+ log_warn "Not a git repository. Checkpoints disabled."
72
+ return 1
73
+ fi
74
+
75
+ # Check index file
76
+ if [ ! -f "$INDEX_FILE" ]; then
77
+ log_debug "No orchestrator-index.json found. Skipping."
78
+ return 1
79
+ fi
80
+
81
+ return 0
82
+ }
83
+
84
+ # Get current phase from orchestrator-index.json
85
+ get_current_phase() {
86
+ local phase
87
+ phase=$(jq -r '.activeWorkflow.currentPhase // empty' "$INDEX_FILE" 2>/dev/null)
88
+ echo "$phase"
89
+ }
90
+
91
+ # Get workflow ID
92
+ get_workflow_id() {
93
+ local wf_id
94
+ wf_id=$(jq -r '.activeWorkflow.id // empty' "$INDEX_FILE" 2>/dev/null)
95
+ echo "$wf_id"
96
+ }
97
+
98
+ # Get workflow status
99
+ get_workflow_status() {
100
+ local status
101
+ status=$(jq -r '.activeWorkflow.status // empty' "$INDEX_FILE" 2>/dev/null)
102
+ echo "$status"
103
+ }
104
+
105
+ # Get last checkpointed phase from checkpoints array (one with commitHash)
106
+ get_last_checkpointed_phase() {
107
+ local phase
108
+ # Find the most recent checkpoint that has a commitHash (indicating it was git-committed)
109
+ phase=$(jq -r '
110
+ [.checkpoints[] | select(.commitHash != null and .commitHash != "")]
111
+ | sort_by(.createdAt)
112
+ | last
113
+ | .phase // empty
114
+ ' "$INDEX_FILE" 2>/dev/null)
115
+ echo "$phase"
116
+ }
117
+
118
+ # Determine completed phase based on current phase
119
+ # When we see currentPhase = PLAN, it means SPECIFY just completed
120
+ get_completed_phase() {
121
+ local current_phase="$1"
122
+ local workflow_status="$2"
123
+
124
+ case "$workflow_status" in
125
+ "completed")
126
+ echo "IMPLEMENT"
127
+ return
128
+ ;;
129
+ esac
130
+
131
+ case "$current_phase" in
132
+ "PLAN")
133
+ echo "SPECIFY"
134
+ ;;
135
+ "TASKS")
136
+ echo "PLAN"
137
+ ;;
138
+ "IMPLEMENT")
139
+ echo "TASKS"
140
+ ;;
141
+ *)
142
+ echo ""
143
+ ;;
144
+ esac
145
+ }
146
+
147
+ # Create git checkpoint
148
+ create_git_checkpoint() {
149
+ local phase="$1"
150
+ local commit_hash=""
151
+
152
+ log_info "Creating git checkpoint for phase: $phase"
153
+
154
+ # Stage all changes
155
+ git -C "$PROJECT_ROOT" add -A 2>/dev/null || {
156
+ log_warn "Failed to stage changes"
157
+ return 1
158
+ }
159
+
160
+ # Check if there are staged changes
161
+ if git -C "$PROJECT_ROOT" diff --cached --quiet 2>/dev/null; then
162
+ log_info "No changes to commit for phase: $phase"
163
+ echo ""
164
+ return 0
165
+ fi
166
+
167
+ # Create commit with standard message
168
+ local commit_msg="[orchestrator] ${phase}: Auto-checkpoint after ${phase} phase"
169
+
170
+ if git -C "$PROJECT_ROOT" commit -m "$commit_msg" --no-verify 2>/dev/null; then
171
+ commit_hash=$(git -C "$PROJECT_ROOT" rev-parse HEAD 2>/dev/null)
172
+ log_info "Checkpoint commit created: $commit_hash"
173
+ echo "$commit_hash"
174
+ else
175
+ log_warn "Failed to create commit"
176
+ echo ""
177
+ return 1
178
+ fi
179
+ }
180
+
181
+ # Update orchestrator-index.json with checkpoint
182
+ update_orchestrator_index() {
183
+ local workflow_id="$1"
184
+ local phase="$2"
185
+ local commit_hash="$3"
186
+ local created_at
187
+
188
+ created_at=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
189
+ local checkpoint_id="cp_${workflow_id}_$(date +%s)"
190
+ local description="Auto-checkpoint after ${phase} phase"
191
+
192
+ log_debug "Updating index with checkpoint: $checkpoint_id"
193
+
194
+ # Create temp file for atomic update
195
+ local temp_file="${INDEX_FILE}.tmp.$$"
196
+
197
+ # Use jq to add checkpoint and update statistics
198
+ if jq --arg id "$checkpoint_id" \
199
+ --arg wfId "$workflow_id" \
200
+ --arg phase "$phase" \
201
+ --arg hash "$commit_hash" \
202
+ --arg date "$created_at" \
203
+ --arg desc "$description" '
204
+ # Add checkpoint to array
205
+ .checkpoints += [{
206
+ id: $id,
207
+ workflowId: $wfId,
208
+ phase: $phase,
209
+ commitHash: $hash,
210
+ createdAt: $date,
211
+ description: $desc
212
+ }] |
213
+ # Update statistics
214
+ .statistics.totalCheckpoints = (.checkpoints | length) |
215
+ .statistics.lastActivity = $date
216
+ ' "$INDEX_FILE" > "$temp_file" 2>/dev/null; then
217
+
218
+ # Validate JSON
219
+ if jq empty "$temp_file" 2>/dev/null; then
220
+ mv "$temp_file" "$INDEX_FILE"
221
+ log_info "Index updated with checkpoint: $checkpoint_id"
222
+ return 0
223
+ else
224
+ log_error "Generated invalid JSON"
225
+ rm -f "$temp_file"
226
+ return 1
227
+ fi
228
+ else
229
+ log_error "Failed to update index with jq"
230
+ rm -f "$temp_file"
231
+ return 1
232
+ fi
233
+ }
234
+
235
+ # Save last checkpointed phase
236
+ save_last_phase() {
237
+ local phase="$1"
238
+ echo "$phase" > "$LAST_PHASE_FILE"
239
+ }
240
+
241
+ # Get saved last phase (from state file, not index)
242
+ get_saved_last_phase() {
243
+ if [ -f "$LAST_PHASE_FILE" ]; then
244
+ cat "$LAST_PHASE_FILE"
245
+ else
246
+ echo ""
247
+ fi
248
+ }
249
+
250
+ # Main execution
251
+ main() {
252
+ log_debug "Hook triggered"
253
+
254
+ # Check prerequisites
255
+ if ! check_prerequisites; then
256
+ log_debug "Prerequisites not met, exiting"
257
+ exit 0 # Don't fail the hook
258
+ fi
259
+
260
+ # Get current state
261
+ local current_phase
262
+ current_phase=$(get_current_phase)
263
+
264
+ if [ -z "$current_phase" ]; then
265
+ log_debug "No active workflow phase found"
266
+ exit 0
267
+ fi
268
+
269
+ local workflow_id
270
+ workflow_id=$(get_workflow_id)
271
+
272
+ local workflow_status
273
+ workflow_status=$(get_workflow_status)
274
+
275
+ log_debug "Current phase: $current_phase, Status: $workflow_status, Workflow: $workflow_id"
276
+
277
+ # Determine which phase just completed
278
+ local completed_phase
279
+ completed_phase=$(get_completed_phase "$current_phase" "$workflow_status")
280
+
281
+ if [ -z "$completed_phase" ]; then
282
+ log_debug "No completed phase detected from current phase: $current_phase"
283
+ exit 0
284
+ fi
285
+
286
+ # Check if we already checkpointed this phase
287
+ local last_checkpointed
288
+ last_checkpointed=$(get_last_checkpointed_phase)
289
+
290
+ local saved_last_phase
291
+ saved_last_phase=$(get_saved_last_phase)
292
+
293
+ log_debug "Completed phase: $completed_phase, Last checkpointed: $last_checkpointed, Saved: $saved_last_phase"
294
+
295
+ # Skip if already checkpointed
296
+ if [ "$completed_phase" = "$last_checkpointed" ] || [ "$completed_phase" = "$saved_last_phase" ]; then
297
+ log_debug "Phase $completed_phase already checkpointed, skipping"
298
+ exit 0
299
+ fi
300
+
301
+ # Create checkpoint
302
+ local commit_hash
303
+ commit_hash=$(create_git_checkpoint "$completed_phase")
304
+
305
+ # Update index (even if no commit, to track the checkpoint)
306
+ if [ -n "$commit_hash" ]; then
307
+ if update_orchestrator_index "$workflow_id" "$completed_phase" "$commit_hash"; then
308
+ save_last_phase "$completed_phase"
309
+ log_info "Checkpoint complete for phase: $completed_phase (commit: $commit_hash)"
310
+ else
311
+ log_error "Failed to update index for phase: $completed_phase"
312
+ fi
313
+ else
314
+ log_info "No changes to checkpoint for phase: $completed_phase"
315
+ save_last_phase "$completed_phase"
316
+ fi
317
+
318
+ exit 0
319
+ }
320
+
321
+ # Run main function
322
+ main "$@"
@@ -0,0 +1,34 @@
1
+ #!/bin/bash
2
+ # Pre-Agent Invoke Hook
3
+ # Executado antes de invocar um subagent
4
+ # Valida contexto e injeta informacoes da KB
5
+
6
+ set -e
7
+
8
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9
+ PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
10
+
11
+ # Recebe evento via stdin ou argumento
12
+ if [ -n "$1" ]; then
13
+ EVENT="$1"
14
+ else
15
+ EVENT=$(cat)
16
+ fi
17
+
18
+ # Verifica se temos o handler compilado
19
+ HANDLER="$PROJECT_ROOT/dist/hook.js"
20
+
21
+ if [ ! -f "$HANDLER" ]; then
22
+ echo '{"success": false, "error": "Hook handler not compiled. Run npm run build first."}' >&2
23
+ exit 1
24
+ fi
25
+
26
+ # Executa o handler TypeScript
27
+ echo "$EVENT" | node "$HANDLER" pre-agent-invoke
28
+
29
+ EXIT_CODE=$?
30
+
31
+ # Exit code determina se agente pode prosseguir
32
+ # 0 = permitido
33
+ # 1 = bloqueado
34
+ exit $EXIT_CODE
@@ -0,0 +1,40 @@
1
+ #!/bin/bash
2
+ # Pre-Phase Advance Hook
3
+ # Executado antes de avancar para proxima fase
4
+ # Avalia gate e cria checkpoint
5
+
6
+ set -e
7
+
8
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9
+ PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
10
+
11
+ # Recebe evento via stdin ou argumento
12
+ if [ -n "$1" ]; then
13
+ EVENT="$1"
14
+ else
15
+ EVENT=$(cat)
16
+ fi
17
+
18
+ # Verifica se temos o handler compilado
19
+ HANDLER="$PROJECT_ROOT/dist/hook.js"
20
+
21
+ if [ ! -f "$HANDLER" ]; then
22
+ echo '{"success": false, "error": "Hook handler not compiled. Run npm run build first."}' >&2
23
+ exit 1
24
+ fi
25
+
26
+ # Executa o handler TypeScript
27
+ echo "$EVENT" | node "$HANDLER" pre-phase-advance
28
+
29
+ EXIT_CODE=$?
30
+
31
+ # Exit code determina se fase pode avancar
32
+ # 0 = gate passou, pode avancar
33
+ # 1 = gate falhou, bloqueado
34
+ if [ $EXIT_CODE -eq 0 ]; then
35
+ echo "[pre-phase-advance] Gate passed, advancing phase" >&2
36
+ else
37
+ echo "[pre-phase-advance] Gate failed, phase advance blocked" >&2
38
+ fi
39
+
40
+ exit $EXIT_CODE