@defai.digital/ax-cli 2.3.0 → 2.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 (104) hide show
  1. package/.ax-cli/CUSTOM.md +111 -89
  2. package/.ax-cli/index.json +4 -3
  3. package/README.md +43 -16
  4. package/config/prompts.yaml +9 -0
  5. package/config/settings.yaml +2 -0
  6. package/dist/agent/llm-agent.d.ts +17 -0
  7. package/dist/agent/llm-agent.js +151 -52
  8. package/dist/agent/llm-agent.js.map +1 -1
  9. package/dist/commands/init/wizard.d.ts +66 -0
  10. package/dist/commands/init/wizard.js +310 -0
  11. package/dist/commands/init/wizard.js.map +1 -0
  12. package/dist/commands/init.js +146 -26
  13. package/dist/commands/init.js.map +1 -1
  14. package/dist/commands/mcp.js +3 -2
  15. package/dist/commands/mcp.js.map +1 -1
  16. package/dist/commands/memory.d.ts +5 -0
  17. package/dist/commands/memory.js +257 -0
  18. package/dist/commands/memory.js.map +1 -0
  19. package/dist/commands/setup.js +1 -1
  20. package/dist/commands/setup.js.map +1 -1
  21. package/dist/commands/templates.d.ts +5 -0
  22. package/dist/commands/templates.js +244 -0
  23. package/dist/commands/templates.js.map +1 -0
  24. package/dist/commands/update.js +9 -2
  25. package/dist/commands/update.js.map +1 -1
  26. package/dist/commands/usage.js +1 -1
  27. package/dist/commands/usage.js.map +1 -1
  28. package/dist/constants.d.ts +2 -0
  29. package/dist/constants.js +2 -0
  30. package/dist/constants.js.map +1 -1
  31. package/dist/hooks/use-input-handler.js +49 -12
  32. package/dist/hooks/use-input-handler.js.map +1 -1
  33. package/dist/index.js +143 -16
  34. package/dist/index.js.map +1 -1
  35. package/dist/llm/client.d.ts +5 -0
  36. package/dist/llm/client.js +43 -37
  37. package/dist/llm/client.js.map +1 -1
  38. package/dist/schemas/index.d.ts +69 -0
  39. package/dist/schemas/index.js +29 -0
  40. package/dist/schemas/index.js.map +1 -1
  41. package/dist/schemas/yaml-schemas.d.ts +10 -0
  42. package/dist/schemas/yaml-schemas.js +2 -0
  43. package/dist/schemas/yaml-schemas.js.map +1 -1
  44. package/dist/tools/search.js +7 -1
  45. package/dist/tools/search.js.map +1 -1
  46. package/dist/tools/text-editor.js +24 -14
  47. package/dist/tools/text-editor.js.map +1 -1
  48. package/dist/tools/todo-tool.js +62 -21
  49. package/dist/tools/todo-tool.js.map +1 -1
  50. package/dist/types/template.d.ts +53 -0
  51. package/dist/types/template.js +5 -0
  52. package/dist/types/template.js.map +1 -0
  53. package/dist/ui/components/command-suggestions.js +2 -2
  54. package/dist/ui/components/command-suggestions.js.map +1 -1
  55. package/dist/utils/cache.d.ts +1 -0
  56. package/dist/utils/cache.js +39 -5
  57. package/dist/utils/cache.js.map +1 -1
  58. package/dist/utils/config-loader.d.ts +2 -0
  59. package/dist/utils/config-loader.js +2 -1
  60. package/dist/utils/config-loader.js.map +1 -1
  61. package/dist/utils/confirmation-service.js +6 -3
  62. package/dist/utils/confirmation-service.js.map +1 -1
  63. package/dist/utils/error-handler.d.ts +5 -0
  64. package/dist/utils/error-handler.js +9 -3
  65. package/dist/utils/error-handler.js.map +1 -1
  66. package/dist/utils/init-previewer.d.ts +56 -0
  67. package/dist/utils/init-previewer.js +217 -0
  68. package/dist/utils/init-previewer.js.map +1 -0
  69. package/dist/utils/init-validator.d.ts +61 -0
  70. package/dist/utils/init-validator.js +248 -0
  71. package/dist/utils/init-validator.js.map +1 -0
  72. package/dist/utils/llm-optimized-instruction-generator.d.ts +31 -0
  73. package/dist/utils/llm-optimized-instruction-generator.js +296 -0
  74. package/dist/utils/llm-optimized-instruction-generator.js.map +1 -0
  75. package/dist/utils/onboarding-manager.d.ts +45 -0
  76. package/dist/utils/onboarding-manager.js +130 -0
  77. package/dist/utils/onboarding-manager.js.map +1 -0
  78. package/dist/utils/path-utils.d.ts +83 -0
  79. package/dist/utils/path-utils.js +122 -0
  80. package/dist/utils/path-utils.js.map +1 -0
  81. package/dist/utils/progress-tracker.d.ts +51 -0
  82. package/dist/utils/progress-tracker.js +152 -0
  83. package/dist/utils/progress-tracker.js.map +1 -0
  84. package/dist/utils/project-analyzer.js +8 -14
  85. package/dist/utils/project-analyzer.js.map +1 -1
  86. package/dist/utils/settings-manager.d.ts +3 -3
  87. package/dist/utils/settings-manager.js +6 -13
  88. package/dist/utils/settings-manager.js.map +1 -1
  89. package/dist/utils/string-utils.d.ts +19 -0
  90. package/dist/utils/string-utils.js +28 -0
  91. package/dist/utils/string-utils.js.map +1 -0
  92. package/dist/utils/template-manager.d.ts +54 -0
  93. package/dist/utils/template-manager.js +421 -0
  94. package/dist/utils/template-manager.js.map +1 -0
  95. package/dist/utils/text-utils.js +3 -1
  96. package/dist/utils/text-utils.js.map +1 -1
  97. package/package.json +2 -1
  98. package/vitest.config.ts +6 -0
  99. package/dist/utils/model-config.d.ts +0 -28
  100. package/dist/utils/model-config.js +0 -43
  101. package/dist/utils/model-config.js.map +0 -1
  102. package/dist/utils/tool-helpers.d.ts +0 -25
  103. package/dist/utils/tool-helpers.js +0 -53
  104. package/dist/utils/tool-helpers.js.map +0 -1
package/.ax-cli/CUSTOM.md CHANGED
@@ -1,97 +1,119 @@
1
- # Custom Instructions for AX CLI
1
+ # @defai.digital/ax-cli - Quick Reference
2
2
 
3
- **Project**: @defai.digital/ax-cli v1.1.0
4
- **Type**: cli
5
- **Language**: TypeScript
6
- **Stack**: React, Vitest, Zod, Commander, Ink, ESM, TypeScript
3
+ **Type:** cli | **Lang:** TypeScript | **Ver:** v2.3.1
4
+ **Stack:** React, Vitest, Zod, Commander, Ink, ESM, TypeScript
7
5
 
8
- Generated: 11/19/2025, 2:45:34 AM
6
+ ---
9
7
 
10
- ## Project Context
8
+ ## 🎯 Critical Rules
11
9
 
12
- - **Entry Point**: `dist/index.js`
13
- - **Package Manager**: npm
14
- - **Module System**: ESM
15
- - **CLI Tool**: This is a command-line interface application
10
+ 1. **ESM Imports:** Always use `.js` extension: `import { x } from './y.js'`
11
+ 2. **Validation:** Use zod for all external inputs
12
+ 3. **Types:** Explicit return types required on all functions
13
+ 4. **Testing:** 80%+ coverage, test error paths
14
+ 5. **Modules:** Use `import/export` (not `require/module.exports`)
16
15
 
17
- ## Code Conventions
16
+ ---
17
+
18
+ ## 📋 Project Overview
19
+
20
+ **Entry:** `dist/index.js` | **PM:** npm | **Module:** ESM
21
+
22
+
23
+ **Directories:**
24
+ - `src/` - Source code
25
+ - `tests/` - Tests
26
+ - `src/tools/` - Tools
27
+ - `src/commands/` - Commands
28
+ - `src/utils/` - Utilities
29
+
30
+ ---
31
+
32
+ ## 🔧 Code Patterns
18
33
 
19
34
  ### TypeScript
20
- - Use explicit type annotations for function parameters and returns
21
- - Prefer `const` and `let` over `var`
22
- - Use strict mode (strict type checking enabled)
23
- - **CRITICAL**: Always use `.js` extension in import statements (ESM requirement)
24
- - Example: `import { foo } from "./bar.js"` (NOT "./bar" or "./bar.ts")
25
-
26
- ### ES Modules
27
- - Use `import/export` syntax (not `require/module.exports`)
28
- - Top-level await is supported
29
-
30
- ### Validation
31
- - Use **zod** for runtime validation
32
- - Validate all external inputs (API requests, file reads, user input)
33
- - Use `.safeParse()` for error handling
34
-
35
- ## File Structure
36
-
37
- - **Source Code**: `src/`
38
- - **Tests**: `tests/`
39
- - **Tools**: `src/tools/`
40
-
41
- ### Typical Structure
42
- - Commands: `src/commands/`
43
- - Utilities: `src/utils/`
44
- - Types: `src/types/`
45
-
46
- ### Key Files
47
- - `package.json`: Node.js package configuration
48
- - `tsconfig.json`: TypeScript configuration
49
- - `vitest.config.ts`: Vitest test configuration
50
- - `.eslintrc.js`: ESLint configuration
51
- - `README.md`: Project documentation
52
- - `CLAUDE.md`: Claude-specific instructions
53
-
54
- ## Development Workflow
55
-
56
- ### Before Making Changes
57
- 1. Read relevant files with `view_file` to understand current implementation
58
- 2. Use `search` to find related code or patterns
59
- 3. Check existing tests to understand expected behavior
60
-
61
- ### Making Changes
62
- 1. **NEVER** use `create_file` on existing files - use `str_replace_editor` instead
63
- 2. Make focused, atomic changes
64
- 3. Preserve existing code style and patterns
65
- 4. Update related tests when modifying functionality
66
-
67
- ### After Changes
68
- 1. Run linter: `eslint . --ext .js,.jsx,.ts,.tsx`
69
- 2. Run tests: `vitest run`
70
- 3. Build: `tsc`
71
-
72
- ## Testing Guidelines
73
-
74
- ### Vitest
75
- - Use `describe`, `it`, `expect` for test structure
76
- - Place tests in `tests/` directory or `*.test.ts` files
77
- - Test edge cases: empty inputs, null/undefined, boundary conditions
78
- - Include Unicode and special character tests where relevant
79
-
80
- ### Coverage Requirements
81
- - Aim for high test coverage (80%+ for new code)
82
- - Always test error paths and edge cases
83
- - Test both success and failure scenarios
84
-
85
- ## Available Scripts
86
-
87
- - **Development**: `bun run src/index.ts`
88
- - **Build**: `tsc`
89
- - **Test**: `vitest run`
90
- - **Lint**: `eslint . --ext .js,.jsx,.ts,.tsx`
91
-
92
- ### Quick Commands
35
+
36
+ **DO:**
37
+ ```typescript
38
+ // Explicit types
39
+ function process(x: string): Promise<Result> { }
40
+
41
+ // ESM imports with .js extension
42
+ import { foo } from './bar.js';
43
+ ```
44
+
45
+ **DON'T:**
46
+ ```typescript
47
+ // No any types
48
+ function process(x: any) { } //
49
+
50
+ // Missing .js extension
51
+ import { foo } from './bar'; // ❌
52
+ ```
53
+
54
+ ### Validation (zod)
55
+
56
+ **DO:**
57
+ ```typescript
58
+ const result = schema.safeParse(data);
59
+ if (!result.success) {
60
+ return { success: false, error: result.error };
61
+ }
62
+ ```
63
+
64
+ ### CLI Commands
65
+ Commands should:
66
+ - Accept options via flags (`-f, --flag <value>`)
67
+ - Validate input before execution
68
+ - Provide clear error messages
69
+ - Return exit codes (0 = success, 1+ = error)
70
+
71
+ ---
72
+
73
+ ## 🔄 Workflow
74
+
75
+ **Before:**
76
+ - Read files to understand implementation
77
+ - Search for related patterns
78
+ - Review tests for expected behavior
79
+
80
+ **Changes:**
81
+ - Edit existing files (never recreate)
82
+ - Keep changes focused and atomic
83
+ - Preserve code style
84
+ - Update tests when changing functionality
85
+
86
+ **After:**
87
+ 1. Lint: `eslint . --ext .js,.jsx,.ts,.tsx`
88
+ 2. Test: `vitest run`
89
+ 3. Build: `npm run build:schemas && tsc`
90
+
91
+ **Quick Commands:**
93
92
  ```bash
94
- npm run dev # Start development
95
- npm test # Run tests
96
- npm run build # Build for production
97
- ```
93
+ npm run dev # Development
94
+ npm test # Run tests
95
+ npm run build # Production build
96
+ ```
97
+
98
+ ---
99
+
100
+ ## 🐛 Troubleshooting
101
+
102
+ ### "Module not found" errors
103
+ **Solution:** Add `.js` extension to imports (ESM requirement)
104
+ ```typescript
105
+ // ✅ Correct
106
+ import { x } from './y.js';
107
+
108
+ // ❌ Wrong
109
+ import { x } from './y'; // Missing .js
110
+ ```
111
+
112
+ ### zod validation errors
113
+ **Solution:** Use `.safeParse()` for detailed error messages. Check schema matches data structure.
114
+
115
+ ### Tests fail locally but pass in CI
116
+ **Solution:** Check Node version, clear node_modules, check environment-specific code
117
+
118
+ ### TypeScript compilation errors
119
+ **Solution:** Check `tsconfig.json` settings, ensure all types are imported, verify `moduleResolution`
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "projectName": "@defai.digital/ax-cli",
3
- "version": "1.1.0",
3
+ "version": "2.3.1",
4
4
  "primaryLanguage": "TypeScript",
5
5
  "techStack": [
6
6
  "React",
@@ -16,6 +16,7 @@
16
16
  "directories": {
17
17
  "source": "src",
18
18
  "tests": "tests",
19
+ "config": "config",
19
20
  "tools": "src/tools"
20
21
  },
21
22
  "keyFiles": [
@@ -33,11 +34,11 @@
33
34
  "validation": "zod"
34
35
  },
35
36
  "scripts": {
36
- "build": "tsc",
37
+ "build": "npm run build:schemas && tsc",
37
38
  "test": "vitest run",
38
39
  "lint": "eslint . --ext .js,.jsx,.ts,.tsx",
39
40
  "dev": "bun run src/index.ts"
40
41
  },
41
42
  "packageManager": "npm",
42
- "lastAnalyzed": "2025-11-19T07:45:34.457Z"
43
+ "lastAnalyzed": "2025-11-19T22:52:24.501Z"
43
44
  }
package/README.md CHANGED
@@ -6,9 +6,9 @@
6
6
  [![TypeScript](https://img.shields.io/badge/TypeScript-5.9%2B-blue?style=flat-square&logo=typescript)](https://www.typescriptlang.org/)
7
7
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](https://opensource.org/licenses/MIT)
8
8
 
9
- [![macOS](https://img.shields.io/badge/macOS-26-000000?style=flat-square&logo=apple)](https://www.apple.com/macos/)
10
- [![Windows](https://img.shields.io/badge/Windows-11-0078D6?style=flat-square&logo=windows)](https://www.microsoft.com/windows/)
11
- [![Ubuntu](https://img.shields.io/badge/Ubuntu-24.04-E95420?style=flat-square&logo=ubuntu)](https://ubuntu.com/)
9
+ [![macOS](https://img.shields.io/badge/macOS-26-blue?style=flat-square&logo=apple)](https://www.apple.com/macos/)
10
+ [![Windows](https://img.shields.io/badge/Windows-11-blue?style=flat-square&logo=windows)](https://www.microsoft.com/windows/)
11
+ [![Ubuntu](https://img.shields.io/badge/Ubuntu-24.04-blue?style=flat-square&logo=ubuntu)](https://ubuntu.com/)
12
12
 
13
13
  ![AX CLI Logo](.github/assets/ax-cli.png)
14
14
 
@@ -29,9 +29,6 @@ ax-cli init
29
29
 
30
30
  # Start interactive mode
31
31
  ax-cli
32
-
33
- # Run headless command
34
- ax-cli -p "list all TypeScript files"
35
32
  ```
36
33
 
37
34
  ## ✨ Features
@@ -93,16 +90,6 @@ AX CLI officially supports the following platforms:
93
90
  npm install -g @defai.digital/ax-cli
94
91
  ```
95
92
 
96
- ### Local Development
97
-
98
- ```bash
99
- git clone https://github.com/defai-digital/ax-cli.git
100
- cd ax-cli
101
- npm install
102
- npm run build
103
- npm link
104
- ```
105
-
106
93
  [Installation Guide →](docs/installation.md)
107
94
 
108
95
  ## ⚙️ Configuration
@@ -156,6 +143,46 @@ ax-cli -p "write tests for utils/" --max-tool-rounds 50
156
143
  ax-cli -p "refactor" --model glm-4.6
157
144
  ```
158
145
 
146
+ ### 🔌 VSCode Integration (NEW!)
147
+
148
+ AX CLI integrates seamlessly with Visual Studio Code via tasks and keyboard shortcuts:
149
+
150
+ ```bash
151
+ # Analyze current file
152
+ ax-cli --prompt "Analyze this file" --file src/index.ts --json --vscode
153
+
154
+ # Explain selected code
155
+ ax-cli --prompt "Explain this code" --selection "function foo() {...}" --json --vscode
156
+
157
+ # Review git changes
158
+ ax-cli --prompt "Review my changes" --git-diff --json --vscode
159
+
160
+ # Analyze specific line range
161
+ ax-cli --prompt "Optimize this section" --file app.ts --line-range 50-100 --json
162
+ ```
163
+
164
+ **Quick Setup:**
165
+ ```bash
166
+ # Copy VSCode templates to your project
167
+ cd your-project
168
+ mkdir -p .vscode
169
+ cp node_modules/@defai.digital/ax-cli/templates/vscode/*.json .vscode/
170
+
171
+ # Start using with Cmd+Shift+P → "Tasks: Run Task" → Select AX task
172
+ ```
173
+
174
+ **Pre-configured Tasks:**
175
+ - 🔍 Analyze Current File
176
+ - 📝 Explain Selection
177
+ - 🔄 Review Git Changes
178
+ - 🧪 Generate Tests
179
+ - 📚 Document Code
180
+ - ♻️ Refactor Selection
181
+ - 🐛 Find Bugs
182
+ - ⚡ Optimize Performance
183
+
184
+ [VSCode Integration Guide →](docs/vscode-integration-guide.md)
185
+
159
186
  ### Project Initialization
160
187
 
161
188
  ```bash
@@ -12,6 +12,7 @@ system_prompt:
12
12
  - "Precision: Make exact, targeted changes - never broad strokes"
13
13
  - "Self-Correction: Validate your work and fix issues immediately"
14
14
  - "Minimal Verbosity: Show results, not commentary"
15
+ - "Smart Tool Usage: Answer simple questions directly. Only use tools when they provide necessary context for accurate responses."
15
16
 
16
17
  tools_header: "Available Tools:"
17
18
 
@@ -84,6 +85,12 @@ system_prompt:
84
85
  - Configuration files (package.json, tsconfig.json)
85
86
  - Then specific modules as needed
86
87
 
88
+ 4. CRITICAL - Complete the task:
89
+ - Gather information ONCE, then act on it
90
+ - Don't repeat the same exploration tools
91
+ - After getting tool results, USE them to complete the user's request
92
+ - Example: If asked for line count and you found files, COUNT them - don't search again
93
+
87
94
  file_operations:
88
95
  title: "FILE OPERATION SAFETY"
89
96
  steps:
@@ -108,6 +115,8 @@ system_prompt:
108
115
  - "Explain complex decisions only when necessary"
109
116
  - "Errors: state problem → show fix → done"
110
117
  - "Success: confirm completion → show key changes"
118
+ - "Simple questions: Answer directly without unnecessary tool calls"
119
+ - "If you find yourself calling the same tool multiple times with no progress, STOP and provide a direct answer"
111
120
 
112
121
  confirmation_behavior:
113
122
  title: "USER CONFIRMATION FLOW"
@@ -5,6 +5,7 @@ agent:
5
5
  max_tool_rounds: 400
6
6
  default_timeout: 360000 # 6 minutes in milliseconds
7
7
  default_max_tokens: 8192
8
+ max_recent_tool_calls: 20 # Keep only last 20 unique tool calls
8
9
 
9
10
  file:
10
11
  max_file_size: 1048576 # 1MB in bytes
@@ -29,6 +30,7 @@ token:
29
30
  default_model: gpt-4
30
31
  default_encoding: cl100k_base
31
32
  cache_max_size: 1000
33
+ chars_per_token_estimate: 4 # Rough approximation for token estimation
32
34
 
33
35
  cache:
34
36
  default_max_size: 1000
@@ -40,11 +40,28 @@ export declare class LLMAgent extends EventEmitter {
40
40
  private contextManager;
41
41
  private abortController;
42
42
  private maxToolRounds;
43
+ private recentToolCalls;
43
44
  constructor(apiKey: string, baseURL?: string, model?: string, maxToolRounds?: number);
44
45
  private initializeMCP;
45
46
  private isGrokModel;
47
+ /**
48
+ * Detect if a tool call is repetitive (likely causing a loop)
49
+ * Returns true if the same tool with similar arguments was called multiple times recently
50
+ */
51
+ private isRepetitiveToolCall;
52
+ /**
53
+ * Reset the tool call tracking (called at start of new user message)
54
+ */
55
+ private resetToolCallTracking;
46
56
  private shouldUseSearchFor;
47
57
  processUserMessage(message: string): Promise<ChatEntry[]>;
58
+ /**
59
+ * Recursively merge streaming delta into accumulated message
60
+ */
61
+ private reduceStreamDelta;
62
+ /**
63
+ * Accumulate streaming message chunks
64
+ */
48
65
  private messageReducer;
49
66
  /**
50
67
  * Prepare user message and apply context management