antigravity-ai-kit 3.1.1 → 3.2.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 (43) hide show
  1. package/.agent/agents/planner.md +205 -62
  2. package/.agent/contexts/plan-quality-log.md +30 -0
  3. package/.agent/engine/loading-rules.json +37 -3
  4. package/.agent/hooks/hooks.json +10 -0
  5. package/.agent/manifest.json +4 -3
  6. package/.agent/skills/plan-validation/SKILL.md +192 -0
  7. package/.agent/skills/plan-writing/SKILL.md +47 -8
  8. package/.agent/skills/plan-writing/domain-enhancers.md +114 -0
  9. package/.agent/skills/plan-writing/plan-retrospective.md +116 -0
  10. package/.agent/skills/plan-writing/plan-schema.md +119 -0
  11. package/.agent/workflows/plan.md +49 -5
  12. package/README.md +30 -29
  13. package/bin/ag-kit.js +26 -5
  14. package/lib/agent-registry.js +17 -3
  15. package/lib/agent-reputation.js +3 -11
  16. package/lib/circuit-breaker.js +195 -0
  17. package/lib/cli-commands.js +88 -1
  18. package/lib/config-validator.js +274 -0
  19. package/lib/conflict-detector.js +29 -22
  20. package/lib/constants.js +35 -0
  21. package/lib/engineering-manager.js +9 -27
  22. package/lib/error-budget.js +105 -29
  23. package/lib/hook-system.js +8 -4
  24. package/lib/identity.js +22 -27
  25. package/lib/io.js +74 -0
  26. package/lib/loading-engine.js +248 -35
  27. package/lib/logger.js +118 -0
  28. package/lib/marketplace.js +43 -20
  29. package/lib/plugin-system.js +55 -31
  30. package/lib/plugin-verifier.js +197 -0
  31. package/lib/rate-limiter.js +113 -0
  32. package/lib/security-scanner.js +1 -4
  33. package/lib/self-healing.js +58 -24
  34. package/lib/session-manager.js +51 -48
  35. package/lib/skill-sandbox.js +1 -1
  36. package/lib/task-governance.js +10 -11
  37. package/lib/task-model.js +42 -27
  38. package/lib/updater.js +1 -1
  39. package/lib/verify.js +4 -4
  40. package/lib/workflow-engine.js +88 -68
  41. package/lib/workflow-events.js +166 -0
  42. package/lib/workflow-persistence.js +19 -19
  43. package/package.json +2 -2
@@ -1,9 +1,9 @@
1
1
  ---
2
2
  description: Create implementation plan. Invokes planner agent for structured task breakdown.
3
- version: 2.1.0
3
+ version: 2.2.0
4
4
  sdlc-phase: plan
5
5
  agents: [planner]
6
- skills: [plan-writing, brainstorming]
6
+ skills: [plan-writing, brainstorming, plan-validation]
7
7
  commit-types: [docs]
8
8
  ---
9
9
 
@@ -55,14 +55,33 @@ commit-types: [docs]
55
55
  - Note dependencies and integration points
56
56
 
57
57
  3. **Create Plan**
58
- - Break down the task into small, focused steps
58
+ - The loading engine provides `matchedDomains` and `mandatoryRules` — pass these to the planner agent
59
+ - Consult all mandatory rules (security, testing, coding-style, documentation, git-workflow) using the Rule Extraction Algorithm
60
+ - Classify task size: Trivial (1-2 files), Medium (3-10 files), Large (10+ files)
61
+ - Break down the task into right-sized steps with exact file paths (see plan-writing SKILL.md Principle 1)
59
62
  - Assign verification criteria to each step
60
63
  - Order tasks logically (dependencies first)
64
+ - Include cross-cutting concerns (security, testing, documentation) — ALWAYS, for ALL task sizes
65
+ - For Medium/Large tasks: invoke specialist synthesis (security-reviewer, tdd-guide, architect) per the Specialist Invocation Protocol
66
+ - Include domain-specific sections based on `matchedDomains` (see `domain-enhancers.md`)
61
67
  - Identify which agents are needed for multi-domain tasks
62
68
  - Save plan to `docs/PLAN-{task-slug}.md`
63
69
 
70
+ // turbo
71
+ 3.5. **Validate Plan Quality**
72
+ - The planner performs self-validation using the `plan-validation` skill checklist:
73
+ 1. Classify task size from file count and effort estimate
74
+ 2. Schema compliance: verify all required Tier sections are present and populated
75
+ 3. Cross-cutting verification: Security, Testing, Documentation sections are non-empty (or explicit "N/A — [reason]")
76
+ 4. Specificity audit: every implementation step includes a file path
77
+ 5. Score the plan against the rubric in `plan-schema.md`
78
+ 6. Apply domain scoring: +2 bonus per matched domain with enhancer, -2 penalty per missing
79
+ - **Verdict**: Score >= 70% of tier max → PASS (present to user with score)
80
+ - **Revision**: Score < 70% → identify gaps, revise, re-validate (max 2 cycles, then present with warnings)
81
+ - The quality score is displayed alongside the plan for transparency
82
+
64
83
  4. **Present for Approval**
65
- - Show the plan summary to the user
84
+ - Show the plan summary to the user with quality score
66
85
  - Wait for explicit approval before any implementation
67
86
 
68
87
  ---
@@ -122,20 +141,42 @@ Approve to start implementation with `/create` or `/enhance`.
122
141
 
123
142
  **REQUIRED:**
124
143
  - At least 3 clarifying questions before planning
144
+ - Mandatory rule consultation before plan creation
125
145
  - Verification criteria for every task
146
+ - Cross-cutting concerns (security, testing, documentation) in every plan
147
+ - Plan validation against quality schema before presentation
126
148
  - User approval before implementation begins
127
149
  - Plan file saved in `docs/` with dynamic name
128
150
 
129
151
  ---
130
152
 
153
+ ## Post-Implementation Retrospective
154
+
155
+ After the planned task is fully implemented and verified (reaches VERIFY phase), the `plan-complete` hook triggers a retrospective:
156
+
157
+ 1. **Trigger**: Workflow state transitions to VERIFY (or user runs `/retrospective` on a completed plan)
158
+ 2. **Data Source**: Compare `docs/PLAN-{slug}.md` against `git diff --name-only` from plan start
159
+ 3. **Execution**: Run the plan-retrospective protocol (`.agent/skills/plan-writing/plan-retrospective.md`)
160
+ 4. **Output**: Append one row to `.agent/contexts/plan-quality-log.md`
161
+ 5. **Feedback Loop**: Planner reads the quality log at planning time (Step 1, Requirements Analysis) to adjust estimates, predict surprise files, and weight risk categories
162
+
163
+ This is non-blocking (severity: medium, onFailure: log). If skipped, no impact on current work, but future plan accuracy degrades.
164
+
165
+ ---
166
+
131
167
  ## Completion Criteria
132
168
 
133
169
  - [ ] Clarifying questions asked and answered
134
170
  - [ ] Codebase explored for relevant context
135
- - [ ] Plan created with verifiable tasks
171
+ - [ ] Mandatory rules consulted (security, testing, coding-style, documentation)
172
+ - [ ] Plan created with verifiable tasks and exact file paths
173
+ - [ ] Cross-cutting concerns addressed (security, testing, documentation)
174
+ - [ ] Plan validated against quality schema (score >= 70% of tier max)
175
+ - [ ] Domain-specific sections included for all matched domains
136
176
  - [ ] Plan saved to `docs/PLAN-{slug}.md`
137
177
  - [ ] User has reviewed and approved the plan
138
178
  - [ ] After approval: proceed to `/create` or `/enhance` for implementation
179
+ - [ ] After implementation: retrospective logged to `plan-quality-log.md` (via plan-complete hook)
139
180
 
140
181
  ---
141
182
 
@@ -144,4 +185,7 @@ Approve to start implementation with `/create` or `/enhance`.
144
185
  - **Previous**: `/brainstorm` (explore options) · `/quality-gate` (validate approach)
145
186
  - **Next**: `/create` (scaffold new features) · `/enhance` (iterative development)
146
187
  - **Skill**: `.agent/skills/plan-writing/SKILL.md`
188
+ - **Schema**: `.agent/skills/plan-writing/plan-schema.md`
189
+ - **Domains**: `.agent/skills/plan-writing/domain-enhancers.md`
190
+ - **Validation**: `.agent/skills/plan-validation/SKILL.md`
147
191
  - **Agent**: `planner` agent (see `.agent/agents/planner.md`)
package/README.md CHANGED
@@ -1,13 +1,13 @@
1
1
  # 🚀 Antigravity AI Kit
2
2
 
3
- ![version](https://img.shields.io/badge/version-3.1.0-blue)
3
+ ![version](https://img.shields.io/badge/version-3.2.0-blue)
4
4
  ![license](https://img.shields.io/badge/license-MIT-green)
5
5
  ![AI Agents](https://img.shields.io/badge/AI%20Agents-19-purple)
6
- ![Skills](https://img.shields.io/badge/Skills-31-orange)
6
+ ![Skills](https://img.shields.io/badge/Skills-32-orange)
7
7
  ![Commands](https://img.shields.io/badge/Commands-31-red)
8
8
  ![Workflows](https://img.shields.io/badge/Workflows-14-teal)
9
- ![Runtime Modules](https://img.shields.io/badge/Runtime%20Modules-21-blueviolet)
10
- ![Tests](https://img.shields.io/badge/Tests-261%20passing-brightgreen)
9
+ ![Runtime Modules](https://img.shields.io/badge/Runtime%20Modules-29-blueviolet)
10
+ ![Tests](https://img.shields.io/badge/Tests-327%20passing-brightgreen)
11
11
  ![Checklists](https://img.shields.io/badge/Checklists-3-yellow)
12
12
 
13
13
  <p align="center">
@@ -15,7 +15,7 @@
15
15
  </p>
16
16
 
17
17
  <p align="center">
18
- Antigravity AI Kit is a <b>Trust-Grade AI development framework</b> with a <b>21-module runtime engine</b>, <b>19 specialized agents</b>, <b>31 commands</b>, <b>31 skills</b>, and <b>14 workflows</b> — all backed by <b>261 tests</b> and governance-first principles.
18
+ Antigravity AI Kit is a <b>Trust-Grade AI development framework</b> with a <b>29-module runtime engine</b>, <b>19 specialized agents</b>, <b>31 commands</b>, <b>32 skills</b>, and <b>14 workflows</b> — all backed by <b>327 tests</b> and governance-first principles.
19
19
  </p>
20
20
 
21
21
  <p align="center">
@@ -38,8 +38,8 @@
38
38
  - [Architecture](#%EF%B8%8F-architecture-overview)
39
39
  - [Agents](#-agents-19)
40
40
  - [Commands](#%EF%B8%8F-commands-31)
41
- - [Skills](#%EF%B8%8F-skills-31)
42
- - [Runtime Engine](#%EF%B8%8F-runtime-engine-21-modules)
41
+ - [Skills](#%EF%B8%8F-skills-32)
42
+ - [Runtime Engine](#%EF%B8%8F-runtime-engine-29-modules)
43
43
  - [Workflows](#-workflows-14)
44
44
  - [Operating Constraints](#%EF%B8%8F-operating-constraints)
45
45
  - [Session Management](#-session-management)
@@ -56,14 +56,14 @@
56
56
  | Feature | Count | Description |
57
57
  | :---------------- | :---- | :--------------------------------------------------------------------- |
58
58
  | 🤖 **AI Agents** | 19 | Specialized roles (Mobile, DevOps, Database, Security, Performance...) |
59
- | 🛠️ **Skills** | 31 | Domain knowledge modules (API, Testing, MCP, Architecture, Docker...) |
59
+ | 🛠️ **Skills** | 32 | Domain knowledge modules (API, Testing, MCP, Architecture, Docker...) |
60
60
  | ⌨️ **Commands** | 31 | Slash commands for every development workflow |
61
61
  | 🔄 **Workflows** | 14 | Process templates (/create, /debug, /deploy, /test...) |
62
- | ⚙️ **Runtime** | 21 | Runtime engine modules (governance, reputation, self-healing...) |
62
+ | ⚙️ **Runtime** | 29 | Runtime engine modules (governance, reputation, self-healing...) |
63
63
  | ✅ **Checklists** | 3 | Quality gates (session-start, session-end, pre-commit) |
64
64
  | ⚖️ **Rules** | 8 | Modular governance constraints (coding, security, testing, git, docs, sprint) |
65
- | 🔗 **Hooks** | 6 | Event-driven automation (runtime + git-hook enforcement) |
66
- | 🧪 **Tests** | 261 | Unit, structural, and security tests (25 test files) |
65
+ | 🔗 **Hooks** | 7 | Event-driven automation (runtime + git-hook enforcement) |
66
+ | 🧪 **Tests** | 327 | Unit, structural, integration, and security tests (32 test files) |
67
67
 
68
68
  ---
69
69
 
@@ -71,7 +71,7 @@
71
71
 
72
72
  - **🔒 Trust-Grade Governance**: `/explore → /plan → /work → /review` — Each iteration builds context
73
73
  - **🤖 Multi-Agent System**: 19 specialized agents that collaborate (Mobile Developer, DevOps, Database Architect, Sprint Orchestrator...)
74
- - **⚙️ Runtime Engine**: 21 modules enforcing workflow transitions, task governance, agent reputation, self-healing, and marketplace
74
+ - **⚙️ Runtime Engine**: 29 modules enforcing workflow transitions, task governance, agent reputation, self-healing, and marketplace
75
75
  - **📦 Context as Artifact**: Persistent markdown files for plans, specs, and decisions
76
76
  - **🔄 Continuous Learning**: PAAL cycle extracts patterns from every session
77
77
  - **🛡️ Security First**: Built-in secret detection, vulnerability scanning, and compliance checks
@@ -150,7 +150,7 @@ ag-kit scan # Security scan
150
150
  │ │ TDD Specialist │ │ DB, DevOps │ │ Knowledge │ │
151
151
  │ └────────┬─────────┘ └────────┬─────────┘ └────────┬─────────┘ │
152
152
  ├───────────┼─────────────────────┼─────────────────────┼────────────┤
153
- │ ▼ SKILL LAYER (31) ▼ │
153
+ │ ▼ SKILL LAYER (32) ▼ │
154
154
  │ ┌──────────────────┐ ┌──────────────────┐ ┌──────────────────┐ │
155
155
  │ │ Orchestration │ │ Operational │ │ Domain Skills │ │
156
156
  │ │ Routing, Modes │ │ Verification │ │ API, Testing │ │
@@ -160,10 +160,10 @@ ag-kit scan # Security scan
160
160
  │ ▼ GOVERNANCE LAYER ▼ │
161
161
  │ ┌──────────────────┐ ┌──────────────────┐ ┌──────────────────┐ │
162
162
  │ │ rules/ (8) │ │ hooks.json │ │ manifest.json │ │
163
- │ │ Governance │ │ 6 Event Hooks │ │ Integrity Check │ │
163
+ │ │ Governance │ │ 7 Event Hooks │ │ Integrity Check │ │
164
164
  │ └──────────────────┘ └──────────────────┘ └──────────────────┘ │
165
165
  ├─────────────────────────────────────────────────────────────────────┤
166
- │ RUNTIME ENGINE (21 modules) │
166
+ │ RUNTIME ENGINE (29 modules) │
167
167
  │ workflow-engine · session-manager · task-governance │
168
168
  │ agent-reputation · self-healing · marketplace · + 15 more │
169
169
  └─────────────────────────────────────────────────────────────────────┘
@@ -186,7 +186,7 @@ EXPLORE → PLAN → IMPLEMENT → VERIFY → REVIEW → DEPLOY
186
186
  | **REVIEW** | Code review (human or Copilot) | Review approved |
187
187
  | **DEPLOY** | Production deployment | Deployment checklist complete |
188
188
 
189
- **Intelligent Routing**: The kit analyzes your request keywords and automatically loads the right agents and skills (max 4 agents + 6 skills per session to stay within context budgets).
189
+ **Intelligent Routing**: The kit analyzes your request keywords (including implicit security triggers like "login", "payment", "upload") and automatically loads the right agents and skills (max 4 agents + 8 skills per session to stay within context budgets). Planning workflows use protected budget enforcement — mandatory skills survive trimming even when over budget.
190
190
 
191
191
  ---
192
192
 
@@ -226,7 +226,7 @@ EXPLORE → PLAN → IMPLEMENT → VERIFY → REVIEW → DEPLOY
226
226
 
227
227
  | Agent | Role | Triggers |
228
228
  | :----------------------- | :-------------------------------- | :---------------------------- |
229
- | **Planner** | Task breakdown, Socratic analysis | plan, breakdown, requirements |
229
+ | **Planner** | Multi-agent plan synthesis, tiered quality schema, specialist coordination | plan, breakdown, requirements |
230
230
  | **Sprint Orchestrator** | Sprint planning, velocity | sprint, roadmap, velocity |
231
231
  | **Reliability Engineer** | SRE, production readiness | reliability, SLA, monitoring |
232
232
 
@@ -302,7 +302,7 @@ EXPLORE → PLAN → IMPLEMENT → VERIFY → REVIEW → DEPLOY
302
302
 
303
303
  ---
304
304
 
305
- ## 🛠️ Skills (31)
305
+ ## 🛠️ Skills (32)
306
306
 
307
307
  ### Operational Skills (5)
308
308
 
@@ -341,7 +341,7 @@ EXPLORE → PLAN → IMPLEMENT → VERIFY → REVIEW → DEPLOY
341
341
  | `git-workflow` | Branching, commits |
342
342
  | `i18n-localization` | Internationalization patterns |
343
343
 
344
- ### Development Skills (9)
344
+ ### Development Skills (10)
345
345
 
346
346
  | Skill | Purpose |
347
347
  | :---------------------- | :---------------------- |
@@ -351,15 +351,16 @@ EXPLORE → PLAN → IMPLEMENT → VERIFY → REVIEW → DEPLOY
351
351
  | `deployment-procedures` | CI/CD, rollback |
352
352
  | `performance-profiling` | Core Web Vitals |
353
353
  | `brainstorming` | Socratic discovery |
354
- | `plan-writing` | Structured planning |
354
+ | `plan-writing` | Structured planning with tiered quality schema |
355
+ | `plan-validation` | Quality gate with completeness scoring |
355
356
  | `shell-conventions` | PowerShell/Bash conventions |
356
357
  | `ui-ux-pro-max` | Premium UI/UX design system |
357
358
 
358
359
  ---
359
360
 
360
- ## ⚙️ Runtime Engine (21 Modules)
361
+ ## ⚙️ Runtime Engine (29 Modules)
361
362
 
362
- Antigravity AI Kit v3.1.0 includes a **full runtime engine** built across 4 phases — all using Node.js built-ins with zero external dependencies.
363
+ Antigravity AI Kit v3.2.0 includes a **full runtime engine** built across 4 phases — all using Node.js built-ins with zero external dependencies.
363
364
 
364
365
  ### Phase 1 — Foundation Hardening
365
366
 
@@ -377,7 +378,7 @@ Antigravity AI Kit v3.1.0 includes a **full runtime engine** built across 4 phas
377
378
  |:---|:---|
378
379
  | `workflow-persistence` | Persistent state + checkpoints |
379
380
  | `agent-registry` | Agent contract validation |
380
- | `loading-engine` | Keyword matching + context budget |
381
+ | `loading-engine` | Keyword matching + implicit triggers + context budget |
381
382
  | `hook-system` | Event-driven lifecycle hooks |
382
383
  | `task-model` | Task CRUD with status tracking |
383
384
 
@@ -614,16 +615,16 @@ antigravity-ai-kit/
614
615
  ├── .agent/ # Core AI Kit
615
616
  │ ├── agents/ # 19 specialized agents
616
617
  │ ├── commands/ # 31 slash commands
617
- │ ├── skills/ # 31 capability modules
618
+ │ ├── skills/ # 32 capability modules
618
619
  │ ├── workflows/ # 14 process templates
619
620
  │ ├── engine/ # Autonomy Engine (state machine, loading rules, configs)
620
- │ ├── hooks/ # 6 event hooks (runtime + git-hook)
621
+ │ ├── hooks/ # 7 event hooks (runtime + git-hook)
621
622
  │ ├── rules/ # 8 modular governance rules
622
623
  │ ├── checklists/ # Verification checklists (3)
623
624
  │ ├── templates/ # ADR, feature-request, bug-report templates
624
625
  │ ├── decisions/ # Architecture Decision Records
625
626
  │ └── manifest.json # Machine-readable capability registry
626
- ├── lib/ # Runtime Engine (21 modules)
627
+ ├── lib/ # Runtime Engine (29 modules)
627
628
  │ ├── workflow-engine.js # State machine enforcement
628
629
  │ ├── task-governance.js # Locking, audit trail, decision timeline
629
630
  │ ├── agent-reputation.js # Score tracking & rankings
@@ -632,8 +633,8 @@ antigravity-ai-kit/
632
633
  │ └── + 16 more modules # Identity, plugins, hooks, registry...
633
634
  ├── bin/ # CLI (ag-kit)
634
635
  ├── create-antigravity-app/ # Project scaffolder (separate npm package)
635
- ├── tests/ # Test suites (261 tests, 25 files)
636
- │ ├── unit/ # 21 module tests
636
+ ├── tests/ # Test suites (327 tests, 32 files)
637
+ │ ├── unit/ # Module tests (loading-engine, self-healing, plugins...)
637
638
  │ ├── structural/ # Inventory + schema validation
638
639
  │ └── security/ # Injection scan + leakage detection
639
640
  ├── docs/ # MkDocs documentation site
@@ -710,7 +711,7 @@ Want to use Antigravity AI Kit in your project? The **[Contributor Guide](https:
710
711
  - Context-driven development from [Google Conductor](https://developers.googleblog.com/en/conductor-introducing-context-driven-development-for-gemini-cli/)
711
712
  - Hook concepts from [everything-claude-code](https://github.com/affaan-m/everything-claude-code)
712
713
 
713
- _Antigravity AI Kit v3.1.0 extends these foundations with a 21-module runtime engine, Trust-Grade governance, session management, and 100+ capabilities._
714
+ _Antigravity AI Kit v3.2.0 extends these foundations with a 29-module runtime engine, Trust-Grade governance, session management, and 100+ capabilities._
714
715
 
715
716
  ---
716
717
 
package/bin/ag-kit.js CHANGED
@@ -14,7 +14,7 @@
14
14
  const fs = require('fs');
15
15
  const path = require('path');
16
16
 
17
- const VERSION = '3.0.0';
17
+ const VERSION = require('../package.json').version;
18
18
  const AGENT_FOLDER = '.agent';
19
19
 
20
20
  // ANSI colors
@@ -71,6 +71,7 @@ ${colors.bright}Usage:${colors.reset}
71
71
  ag-kit market info <name> Get marketplace plugin details
72
72
  ag-kit market install <n> Install from marketplace
73
73
  ag-kit heal [--file <f>] Detect and diagnose CI failures
74
+ ag-kit health Run aggregated health check
74
75
  ag-kit --help Show this help message
75
76
  ag-kit --version Show version
76
77
 
@@ -524,16 +525,28 @@ const options = {
524
525
  file: null,
525
526
  };
526
527
 
527
- // Parse --path option
528
+ // Parse --path option with traversal protection (H-7: use path.resolve boundary check)
528
529
  const pathIndex = args.indexOf('--path');
529
530
  if (pathIndex !== -1 && args[pathIndex + 1]) {
530
- options.path = args[pathIndex + 1];
531
+ const resolvedPath = path.resolve(args[pathIndex + 1]);
532
+ const cwd = process.cwd();
533
+ if (!resolvedPath.startsWith(cwd + path.sep) && resolvedPath !== cwd) {
534
+ log('Error: --path must resolve within current working directory', 'red');
535
+ process.exit(1);
536
+ }
537
+ options.path = resolvedPath;
531
538
  }
532
539
 
533
- // Parse --file option
540
+ // Parse --file option with traversal protection (H-7: use path.resolve boundary check)
534
541
  const fileIndex = args.indexOf('--file');
535
542
  if (fileIndex !== -1 && args[fileIndex + 1]) {
536
- options.file = args[fileIndex + 1];
543
+ const resolvedFile = path.resolve(args[fileIndex + 1]);
544
+ const cwdForFile = process.cwd();
545
+ if (!resolvedFile.startsWith(cwdForFile + path.sep) && resolvedFile !== cwdForFile) {
546
+ log('Error: --file must resolve within current working directory', 'red');
547
+ process.exit(1);
548
+ }
549
+ options.file = resolvedFile;
537
550
  }
538
551
 
539
552
  // Execute command
@@ -567,6 +580,14 @@ switch (command) {
567
580
  cliCmd.healCommand(process.cwd(), { file: options.file, apply: options.apply });
568
581
  break;
569
582
  }
583
+ case 'health': {
584
+ const cliHealth = require('../lib/cli-commands');
585
+ const result = cliHealth.healthCommand(process.cwd());
586
+ if (!result.healthy) {
587
+ process.exit(1);
588
+ }
589
+ break;
590
+ }
570
591
  case '--version':
571
592
  case '-v':
572
593
  console.log(VERSION);
@@ -14,7 +14,7 @@
14
14
  const fs = require('fs');
15
15
  const path = require('path');
16
16
 
17
- const AGENT_DIR = '.agent';
17
+ const { AGENT_DIR } = require('./constants');
18
18
  const AGENTS_SUBDIR = 'agents';
19
19
  const MANIFEST_FILE = 'manifest.json';
20
20
 
@@ -153,7 +153,14 @@ function validateAgent(agentName, projectRoot) {
153
153
  */
154
154
  function validateAllAgents(projectRoot) {
155
155
  const manifestPath = path.join(projectRoot, AGENT_DIR, MANIFEST_FILE);
156
- const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf-8'));
156
+
157
+ let manifest;
158
+ try {
159
+ manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf-8'));
160
+ } catch {
161
+ return { total: 0, valid: 0, invalid: 0, agents: [] };
162
+ }
163
+
157
164
  const agents = manifest.capabilities?.agents?.items || [];
158
165
 
159
166
  const results = agents.map((agent) => validateAgent(agent.name, projectRoot));
@@ -175,7 +182,14 @@ function validateAllAgents(projectRoot) {
175
182
  */
176
183
  function loadRegistry(projectRoot) {
177
184
  const manifestPath = path.join(projectRoot, AGENT_DIR, MANIFEST_FILE);
178
- const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf-8'));
185
+
186
+ let manifest;
187
+ try {
188
+ manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf-8'));
189
+ } catch {
190
+ return { agents: [], totalCount: 0 };
191
+ }
192
+
179
193
  const agents = manifest.capabilities?.agents?.items || [];
180
194
 
181
195
  return {
@@ -15,8 +15,8 @@ const fs = require('fs');
15
15
  const path = require('path');
16
16
  const crypto = require('crypto');
17
17
 
18
- const AGENT_DIR = '.agent';
19
- const ENGINE_DIR = 'engine';
18
+ const { AGENT_DIR, ENGINE_DIR } = require('./constants');
19
+ const { writeJsonAtomic } = require('./io');
20
20
  const REPUTATION_FILE = 'reputation.json';
21
21
 
22
22
  /** Score bounds */
@@ -95,15 +95,7 @@ function loadReputationData(projectRoot) {
95
95
  */
96
96
  function writeReputationData(projectRoot, data) {
97
97
  const filePath = resolveReputationPath(projectRoot);
98
- const dir = path.dirname(filePath);
99
-
100
- if (!fs.existsSync(dir)) {
101
- fs.mkdirSync(dir, { recursive: true });
102
- }
103
-
104
- const tempPath = `${filePath}.tmp`;
105
- fs.writeFileSync(tempPath, JSON.stringify(data, null, 2) + '\n', 'utf-8');
106
- fs.renameSync(tempPath, filePath);
98
+ writeJsonAtomic(filePath, data);
107
99
  }
108
100
 
109
101
  /**
@@ -0,0 +1,195 @@
1
+ /**
2
+ * Antigravity AI Kit — Circuit Breaker
3
+ *
4
+ * Implements the circuit breaker pattern for protecting external
5
+ * operations (git clones, network requests) from cascading failures.
6
+ *
7
+ * States: CLOSED (normal) → OPEN (failing) → HALF_OPEN (testing recovery)
8
+ *
9
+ * @module lib/circuit-breaker
10
+ * @author Emre Dursun
11
+ * @since v3.2.0
12
+ */
13
+
14
+ 'use strict';
15
+
16
+ /** @typedef {'CLOSED' | 'OPEN' | 'HALF_OPEN'} CircuitState */
17
+
18
+ /**
19
+ * @typedef {object} CircuitBreakerOptions
20
+ * @property {number} [failureThreshold=3] - Failures before opening circuit
21
+ * @property {number} [resetTimeoutMs=60000] - Time before attempting recovery (ms)
22
+ * @property {number} [halfOpenMaxAttempts=1] - Max attempts in half-open state
23
+ */
24
+
25
+ /**
26
+ * @typedef {object} CircuitBreakerState
27
+ * @property {CircuitState} state - Current circuit state
28
+ * @property {number} failureCount - Consecutive failure count
29
+ * @property {number} successCount - Consecutive success count in half-open
30
+ * @property {number | null} lastFailureTime - Timestamp of last failure
31
+ * @property {number} totalFailures - Lifetime failure count
32
+ * @property {number} totalSuccesses - Lifetime success count
33
+ */
34
+
35
+ /**
36
+ * Creates a new circuit breaker instance.
37
+ *
38
+ * @param {string} name - Circuit breaker name for identification
39
+ * @param {CircuitBreakerOptions} [options] - Configuration options
40
+ * @returns {{ execute: Function, getState: Function, reset: Function }}
41
+ */
42
+ function createCircuitBreaker(name, options = {}) {
43
+ const failureThreshold = options.failureThreshold || 3;
44
+ const resetTimeoutMs = options.resetTimeoutMs || 60000;
45
+ const halfOpenMaxAttempts = options.halfOpenMaxAttempts || 1;
46
+
47
+ /** @type {CircuitBreakerState} */
48
+ const state = {
49
+ state: 'CLOSED',
50
+ failureCount: 0,
51
+ successCount: 0,
52
+ lastFailureTime: null,
53
+ totalFailures: 0,
54
+ totalSuccesses: 0,
55
+ };
56
+
57
+ /**
58
+ * Checks if the circuit should transition from OPEN to HALF_OPEN.
59
+ *
60
+ * @returns {boolean}
61
+ */
62
+ function shouldAttemptReset() {
63
+ if (state.state !== 'OPEN' || state.lastFailureTime === null) {
64
+ return false;
65
+ }
66
+ return (Date.now() - state.lastFailureTime) >= resetTimeoutMs;
67
+ }
68
+
69
+ /**
70
+ * Records a successful operation.
71
+ *
72
+ * @returns {void}
73
+ */
74
+ function onSuccess() {
75
+ state.totalSuccesses += 1;
76
+
77
+ if (state.state === 'HALF_OPEN') {
78
+ state.successCount += 1;
79
+ if (state.successCount >= halfOpenMaxAttempts) {
80
+ state.state = 'CLOSED';
81
+ state.failureCount = 0;
82
+ state.successCount = 0;
83
+ state.lastFailureTime = null;
84
+ }
85
+ } else {
86
+ state.failureCount = 0;
87
+ }
88
+ }
89
+
90
+ /**
91
+ * Records a failed operation.
92
+ *
93
+ * @returns {void}
94
+ */
95
+ function onFailure() {
96
+ state.totalFailures += 1;
97
+ state.failureCount += 1;
98
+ state.lastFailureTime = Date.now();
99
+
100
+ if (state.state === 'HALF_OPEN') {
101
+ state.state = 'OPEN';
102
+ state.successCount = 0;
103
+ } else if (state.failureCount >= failureThreshold) {
104
+ state.state = 'OPEN';
105
+ }
106
+ }
107
+
108
+ /**
109
+ * Executes an operation through the circuit breaker.
110
+ *
111
+ * @param {Function} operation - Async or sync operation to execute
112
+ * @returns {*} Result of the operation
113
+ * @throws {Error} If circuit is open or operation fails
114
+ */
115
+ function execute(operation) {
116
+ if (state.state === 'OPEN') {
117
+ if (shouldAttemptReset()) {
118
+ state.state = 'HALF_OPEN';
119
+ state.successCount = 0;
120
+ } else {
121
+ throw new Error(
122
+ `Circuit breaker "${name}" is OPEN — operation rejected. ` +
123
+ `${state.failureCount} consecutive failures. ` +
124
+ `Will retry after ${Math.ceil((resetTimeoutMs - (Date.now() - state.lastFailureTime)) / 1000)}s.`
125
+ );
126
+ }
127
+ }
128
+
129
+ try {
130
+ const result = operation();
131
+ onSuccess();
132
+ return result;
133
+ } catch (error) {
134
+ onFailure();
135
+ throw error;
136
+ }
137
+ }
138
+
139
+ /**
140
+ * Executes an asynchronous operation through the circuit breaker.
141
+ * Properly tracks Promise resolution/rejection for state management.
142
+ *
143
+ * @param {Function} operation - Async operation to execute (must return a Promise)
144
+ * @returns {Promise<*>} Result of the operation
145
+ * @throws {Error} If circuit is open or operation fails
146
+ */
147
+ async function executeAsync(operation) {
148
+ if (state.state === 'OPEN') {
149
+ if (shouldAttemptReset()) {
150
+ state.state = 'HALF_OPEN';
151
+ state.successCount = 0;
152
+ } else {
153
+ throw new Error(
154
+ `Circuit breaker "${name}" is OPEN — operation rejected. ` +
155
+ `${state.failureCount} consecutive failures. ` +
156
+ `Will retry after ${Math.ceil((resetTimeoutMs - (Date.now() - state.lastFailureTime)) / 1000)}s.`
157
+ );
158
+ }
159
+ }
160
+
161
+ try {
162
+ const result = await operation();
163
+ onSuccess();
164
+ return result;
165
+ } catch (error) {
166
+ onFailure();
167
+ throw error;
168
+ }
169
+ }
170
+
171
+ /**
172
+ * Returns a snapshot of the circuit breaker state.
173
+ *
174
+ * @returns {CircuitBreakerState & { name: string }}
175
+ */
176
+ function getState() {
177
+ return { name, ...state };
178
+ }
179
+
180
+ /**
181
+ * Resets the circuit breaker to CLOSED state.
182
+ *
183
+ * @returns {void}
184
+ */
185
+ function reset() {
186
+ state.state = 'CLOSED';
187
+ state.failureCount = 0;
188
+ state.successCount = 0;
189
+ state.lastFailureTime = null;
190
+ }
191
+
192
+ return { execute, executeAsync, getState, reset };
193
+ }
194
+
195
+ module.exports = { createCircuitBreaker };