grok-dev 1.0.0-rc1

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 (112) hide show
  1. package/.cursor/rules/development-workflow.mdc +66 -0
  2. package/.cursor/rules/project-overview.mdc +66 -0
  3. package/.cursor/rules/react-ink-components.mdc +45 -0
  4. package/.cursor/rules/tools-and-agent.mdc +62 -0
  5. package/.cursor/rules/typescript-conventions.mdc +54 -0
  6. package/.grok/settings.json +3 -0
  7. package/.husky/pre-commit +1 -0
  8. package/LICENSE +21 -0
  9. package/README.md +526 -0
  10. package/biome.json +51 -0
  11. package/dist/agent/agent.d.ts +62 -0
  12. package/dist/agent/agent.js +701 -0
  13. package/dist/agent/agent.js.map +1 -0
  14. package/dist/agent/delegations.d.ts +42 -0
  15. package/dist/agent/delegations.js +273 -0
  16. package/dist/agent/delegations.js.map +1 -0
  17. package/dist/grok/client.d.ts +12 -0
  18. package/dist/grok/client.js +37 -0
  19. package/dist/grok/client.js.map +1 -0
  20. package/dist/grok/models.d.ts +5 -0
  21. package/dist/grok/models.js +73 -0
  22. package/dist/grok/models.js.map +1 -0
  23. package/dist/grok/tools.d.ts +12 -0
  24. package/dist/grok/tools.js +230 -0
  25. package/dist/grok/tools.js.map +1 -0
  26. package/dist/index.d.ts +2 -0
  27. package/dist/index.js +192 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/storage/db.d.ts +18 -0
  30. package/dist/storage/db.js +71 -0
  31. package/dist/storage/db.js.map +1 -0
  32. package/dist/storage/index.d.ts +4 -0
  33. package/dist/storage/index.js +5 -0
  34. package/dist/storage/index.js.map +1 -0
  35. package/dist/storage/migrations.d.ts +2 -0
  36. package/dist/storage/migrations.js +92 -0
  37. package/dist/storage/migrations.js.map +1 -0
  38. package/dist/storage/sessions.d.ts +15 -0
  39. package/dist/storage/sessions.js +135 -0
  40. package/dist/storage/sessions.js.map +1 -0
  41. package/dist/storage/transcript.d.ts +6 -0
  42. package/dist/storage/transcript.js +261 -0
  43. package/dist/storage/transcript.js.map +1 -0
  44. package/dist/storage/usage.d.ts +9 -0
  45. package/dist/storage/usage.js +58 -0
  46. package/dist/storage/usage.js.map +1 -0
  47. package/dist/storage/workspaces.d.ts +9 -0
  48. package/dist/storage/workspaces.js +60 -0
  49. package/dist/storage/workspaces.js.map +1 -0
  50. package/dist/telegram/bridge.d.ts +39 -0
  51. package/dist/telegram/bridge.js +164 -0
  52. package/dist/telegram/bridge.js.map +1 -0
  53. package/dist/telegram/index.d.ts +3 -0
  54. package/dist/telegram/index.js +4 -0
  55. package/dist/telegram/index.js.map +1 -0
  56. package/dist/telegram/limits.d.ts +3 -0
  57. package/dist/telegram/limits.js +12 -0
  58. package/dist/telegram/limits.js.map +1 -0
  59. package/dist/telegram/pairing.d.ts +9 -0
  60. package/dist/telegram/pairing.js +30 -0
  61. package/dist/telegram/pairing.js.map +1 -0
  62. package/dist/telegram/preview-stream.d.ts +22 -0
  63. package/dist/telegram/preview-stream.js +181 -0
  64. package/dist/telegram/preview-stream.js.map +1 -0
  65. package/dist/telegram/turn-coordinator.d.ts +7 -0
  66. package/dist/telegram/turn-coordinator.js +14 -0
  67. package/dist/telegram/turn-coordinator.js.map +1 -0
  68. package/dist/telegram/typing-refresh.d.ts +3 -0
  69. package/dist/telegram/typing-refresh.js +12 -0
  70. package/dist/telegram/typing-refresh.js.map +1 -0
  71. package/dist/tools/bash.d.ts +27 -0
  72. package/dist/tools/bash.js +261 -0
  73. package/dist/tools/bash.js.map +1 -0
  74. package/dist/tools/file.d.ts +15 -0
  75. package/dist/tools/file.js +94 -0
  76. package/dist/tools/file.js.map +1 -0
  77. package/dist/types/index.d.ts +151 -0
  78. package/dist/types/index.js +6 -0
  79. package/dist/types/index.js.map +1 -0
  80. package/dist/ui/app.d.ts +15 -0
  81. package/dist/ui/app.js +1720 -0
  82. package/dist/ui/app.js.map +1 -0
  83. package/dist/ui/markdown.d.ts +5 -0
  84. package/dist/ui/markdown.js +38 -0
  85. package/dist/ui/markdown.js.map +1 -0
  86. package/dist/ui/plan.d.ts +24 -0
  87. package/dist/ui/plan.js +122 -0
  88. package/dist/ui/plan.js.map +1 -0
  89. package/dist/ui/terminal-selection-text.d.ts +23 -0
  90. package/dist/ui/terminal-selection-text.js +59 -0
  91. package/dist/ui/terminal-selection-text.js.map +1 -0
  92. package/dist/ui/theme.d.ts +53 -0
  93. package/dist/ui/theme.js +53 -0
  94. package/dist/ui/theme.js.map +1 -0
  95. package/dist/utils/git-root.d.ts +1 -0
  96. package/dist/utils/git-root.js +16 -0
  97. package/dist/utils/git-root.js.map +1 -0
  98. package/dist/utils/host-clipboard.d.ts +4 -0
  99. package/dist/utils/host-clipboard.js +32 -0
  100. package/dist/utils/host-clipboard.js.map +1 -0
  101. package/dist/utils/instructions.d.ts +1 -0
  102. package/dist/utils/instructions.js +73 -0
  103. package/dist/utils/instructions.js.map +1 -0
  104. package/dist/utils/settings.d.ts +33 -0
  105. package/dist/utils/settings.js +88 -0
  106. package/dist/utils/settings.js.map +1 -0
  107. package/dist/utils/skills.d.ts +17 -0
  108. package/dist/utils/skills.js +161 -0
  109. package/dist/utils/skills.js.map +1 -0
  110. package/package.json +67 -0
  111. package/skills-lock.json +10 -0
  112. package/tmp/large_class.py +633 -0
@@ -0,0 +1,66 @@
1
+ ---
2
+ description: Development workflow and common commands
3
+ globs: "**/*"
4
+ alwaysApply: true
5
+ ---
6
+
7
+ # Development Workflow
8
+
9
+ ## Prerequisites
10
+
11
+ - Bun 1.0+ (required)
12
+
13
+ ## Common Commands
14
+
15
+ ```bash
16
+ # Install dependencies
17
+ bun install
18
+
19
+ # Development (runs from source with Bun)
20
+ bun run dev
21
+
22
+ # Build (compile TypeScript to dist/)
23
+ bun run build
24
+
25
+ # Type checking (no emit)
26
+ bun run typecheck
27
+
28
+ # Linting
29
+ bun run lint
30
+
31
+ # Format (check / write)
32
+ bun run format
33
+ bun run format:fix
34
+
35
+ # Run the built CLI
36
+ bun run start
37
+ ```
38
+
39
+ ## Environment Variables
40
+
41
+ | Variable | Required | Description |
42
+ |----|----|----|
43
+ | `GROK_API_KEY` | Yes | API key for xAI Grok |
44
+ | `GROK_BASE_URL` | No | Custom API endpoint (default: `https://api.x.ai/v1`) |
45
+ | `GROK_MODEL` | No | Model override (default: `grok-4-1-fast`) |
46
+ | `GROK_MAX_TOKENS` | No | Max tokens per response (default: 16384) |
47
+
48
+ Copy `.env.example` to `.env` and fill in your values.
49
+
50
+ ## Git hooks
51
+
52
+ After `bun install`, **Husky** installs a **pre-commit** hook that runs **`lint-staged`**: Biome **format + lint** (`check --write`) on staged `*.{ts,tsx,js,mjs,cjs,json}` files. Fixes are written to disk and re-staged automatically when possible.
53
+
54
+ ## Before Submitting Changes
55
+
56
+ 1. Run `bun run typecheck` — CI enforces this on every PR.
57
+ 2. Run `bun run lint` — fix any Biome issues (or let pre-commit apply safe fixes).
58
+ 3. Ensure no secrets or `.env` files are committed.
59
+ 4. Follow the PR template in `.github/pull_request_template.md`.
60
+
61
+ ## Project Structure Conventions
62
+
63
+ - Source code lives in `src/`, compiled output in `dist/` (gitignored).
64
+ - The CLI entry point is `src/index.ts` which uses Commander.js for argument parsing.
65
+ - UI is built with OpenTUI React (`@opentui/react`).
66
+ - Only tool is bash — all file operations happen through shell commands.
@@ -0,0 +1,66 @@
1
+ ---
2
+ description: Project overview and architecture reference
3
+ globs: "**/*"
4
+ alwaysApply: true
5
+ ---
6
+
7
+ # Grok CLI — Project Overview
8
+
9
+ Grok CLI (`@vibe-kit/grok-cli`) is an open-source AI coding agent powered by Grok that brings AI assistance directly into the terminal.
10
+
11
+ ## Tech Stack
12
+
13
+ - **Language**: TypeScript (ES2022, ESNext modules)
14
+ - **Runtime**: Bun (primary)
15
+ - **UI Framework**: React with [OpenTUI](https://github.com/anomalyco/opentui) for terminal rendering
16
+ - **Build**: `tsc` (TypeScript compiler)
17
+ - **Package Manager**: Bun
18
+ - **API Client**: OpenAI SDK (for OpenAI-compatible xAI API)
19
+ - **Tools**: Bash-only (all file operations via shell commands)
20
+ - **Search**: X Search API + Web Search via xAI Responses API
21
+
22
+ ## Architecture
23
+
24
+ ```
25
+ src/
26
+ ├── index.ts # CLI entry point (Commander.js + OpenTUI)
27
+ ├── agent/
28
+ │ └── agent.ts # Agent — orchestrates client, bash tool, search
29
+ ├── grok/
30
+ │ ├── client.ts # Grok API client (Chat Completions + Responses API)
31
+ │ ├── models.ts # Model definitions and metadata
32
+ │ └── tools.ts # Tool schemas (bash, search_web, search_x)
33
+ ├── tools/
34
+ │ └── bash.ts # Bash command execution
35
+ ├── ui/
36
+ │ └── app.tsx # OpenTUI React terminal UI
37
+ ├── utils/
38
+ │ ├── settings.ts # User and project settings
39
+ │ ├── git-root.ts # Resolve git repository root for AGENTS.md discovery
40
+ │ └── instructions.ts # AGENTS.md (ecosystem) + .grok/GROK.md
41
+ └── types/
42
+ └── index.ts # Shared TypeScript types
43
+ ```
44
+
45
+ ## Key Patterns
46
+
47
+ - **Agent loop**: `Agent.processMessage()` is an async generator that yields `StreamChunk` objects — the LLM responds, tools execute, results feed back until no more tool calls remain.
48
+ - **Bash-only tools**: The agent uses bash for everything (file editing, searching, git, builds, etc.).
49
+ - **X Search & Web Search**: Integrated via the xAI Responses API for real-time information.
50
+ - **Settings hierarchy**: Environment variables → User-level (`~/.grok/user-settings.json`) → Project-level (`.grok/settings.json`).
51
+ - **Custom instructions**: `~/.grok/AGENTS.md`, then `AGENTS.override.md` / `AGENTS.md` per directory from git root through the workspace cwd (Codex-style merge), then `.grok/GROK.md` or `~/.grok/GROK.md` last.
52
+ - **ESM only**: The project uses `"type": "module"` — all imports use `.js` extensions for compiled output.
53
+
54
+ ## Latest Grok Models
55
+
56
+ - grok-4-0709 (flagship reasoning)
57
+ - grok-4.20-beta-0309 (multi-agent, 2M context)
58
+ - grok-4-fast (fast reasoning, 2M context)
59
+ - grok-4-1-fast (latest fast, 2M context)
60
+ - grok-code-fast-1 (code optimized)
61
+ - grok-3, grok-3-mini
62
+
63
+ ## CI/CD
64
+
65
+ - **typecheck.yml**: Runs `tsc --noEmit` on push/PR to `main`/`develop`.
66
+ - **security.yml**: Runs `npm audit` and TruffleHog secret scanning.
@@ -0,0 +1,45 @@
1
+ ---
2
+ description: Guidelines for React components using Ink for terminal UI
3
+ globs: "src/ui/**/*.tsx,src/hooks/**/*.ts"
4
+ alwaysApply: false
5
+ ---
6
+
7
+ # React + Ink Terminal UI
8
+
9
+ ## Framework
10
+
11
+ This project uses [Ink](https://github.com/vadimdemedes/ink) v4 to render React components in the terminal. Ink provides `<Box>`, `<Text>`, and other primitives instead of HTML elements.
12
+
13
+ ## Component Patterns
14
+
15
+ - Use **functional components** with hooks — no class components.
16
+ - JSX is compiled with `"jsx": "react"` (classic transform), so `import React from "react"` is required in every `.tsx` file.
17
+ - Components are in `src/ui/components/` and follow kebab-case naming (`chat-interface.tsx`, `diff-renderer.tsx`).
18
+
19
+ ## Key Components
20
+
21
+ | Component | Purpose |
22
+ |-----------|---------|
23
+ | `ChatInterface` | Main chat loop, orchestrates agent interaction |
24
+ | `ChatHistory` | Renders conversation entries |
25
+ | `ChatInput` | User text input with key bindings |
26
+ | `DiffRenderer` | Displays file diffs |
27
+ | `ModelSelection` | Model picker UI |
28
+ | `LoadingSpinner` | Animated loading indicator |
29
+ | `ConfirmationDialog` | User confirmation prompts for tool operations |
30
+ | `McpStatus` | MCP server connection status |
31
+ | `CommandSuggestions` | Autocomplete suggestions |
32
+ | `ApiKeyInput` | API key entry prompt |
33
+
34
+ ## Ink-Specific Guidelines
35
+
36
+ - Use `<Box>` for layout (flexbox model) and `<Text>` for styled text.
37
+ - Use Ink's `useInput` hook for keyboard handling.
38
+ - Use `chalk` for color utilities in `src/ui/utils/colors.ts`.
39
+ - Markdown rendering for chat output uses `marked` + `marked-terminal`.
40
+ - The app is rendered via `render(React.createElement(ChatInterface, { agent, initialMessage }))` in the entry point.
41
+
42
+ ## Hooks
43
+
44
+ - Custom hooks live in `src/hooks/`.
45
+ - Follow the `use` prefix convention (`useInput`, `useChat`, etc.).
@@ -0,0 +1,62 @@
1
+ ---
2
+ description: Guidelines for the agent system and tool implementations
3
+ globs: "src/agent/**/*.ts,src/tools/**/*.ts,src/grok/**/*.ts"
4
+ alwaysApply: false
5
+ ---
6
+
7
+ # Agent & Tools System
8
+
9
+ ## Agent
10
+
11
+ `Agent` (in `src/agent/agent.ts`) is the core orchestrator. It manages:
12
+
13
+ - The Grok API client (`GrokClient`)
14
+ - Bash tool for all shell operations
15
+ - Web search and X search via the Responses API
16
+ - Chat history and message accumulation
17
+ - Abort/cancellation support
18
+
19
+ ### Agent Loop
20
+
21
+ The agent uses an iterative tool-call pattern via `processMessage` (async generator):
22
+
23
+ 1. Send messages to the LLM via Chat Completions API (streaming).
24
+ 2. If the response contains `tool_calls`, execute each tool.
25
+ 3. Append tool results to the message history.
26
+ 4. Repeat until no tool calls remain or `maxToolRounds` is reached.
27
+ 5. Yield `StreamChunk` objects for real-time UI updates.
28
+
29
+ ## Tool Interface
30
+
31
+ All tools return a `ToolResult`:
32
+
33
+ ```typescript
34
+ interface ToolResult {
35
+ success: boolean;
36
+ output?: string;
37
+ error?: string;
38
+ }
39
+ ```
40
+
41
+ Tools should never throw — wrap errors in `{ success: false, error: "..." }`.
42
+
43
+ ## Built-in Tools
44
+
45
+ | Tool | File | Purpose |
46
+ |------|------|---------|
47
+ | `BashTool` | `src/tools/bash.ts` | Execute any shell command |
48
+ | `search_web` | via `GrokClient.searchWeb()` | Web search using Responses API |
49
+ | `search_x` | via `GrokClient.searchX()` | X/Twitter search using Responses API |
50
+
51
+ ## Grok Client
52
+
53
+ `GrokClient` (in `src/grok/client.ts`) handles two API endpoints:
54
+
55
+ - **Chat Completions** (`/v1/chat/completions`): Main agent loop with streaming and tool calling
56
+ - **Responses API** (`/v1/responses`): X Search and Web Search with server-side tools
57
+
58
+ ## Adding a New Tool
59
+
60
+ 1. Add the tool schema to `src/grok/tools.ts` (in the `TOOLS` array).
61
+ 2. Add the execution case in `Agent.executeTool()`.
62
+ 3. Update the system prompt in `Agent` to document the tool.
@@ -0,0 +1,54 @@
1
+ ---
2
+ description: TypeScript coding conventions and style guidelines
3
+ globs: "**/*.ts,**/*.tsx"
4
+ alwaysApply: false
5
+ ---
6
+
7
+ # TypeScript Conventions
8
+
9
+ ## Module System
10
+
11
+ - This is an ESM project (`"type": "module"` in package.json).
12
+ - Always use ES module `import`/`export` syntax — never `require()`.
13
+ - When importing local modules, include the `.js` extension (TypeScript compiles `.ts` → `.js`):
14
+ ```typescript
15
+ import { GrokAgent } from "./agent/grok-agent.js";
16
+ ```
17
+
18
+ ## TypeScript Configuration
19
+
20
+ - Target: ES2022, Module: ESNext, JSX: react
21
+ - `strict: false` and `noImplicitAny: false` — the codebase does not enforce strict mode.
22
+ - `moduleResolution: "Bundler"` is used.
23
+ - Source files live in `src/`, compiled output goes to `dist/`.
24
+
25
+ ## Type Practices
26
+
27
+ - Prefer explicit interfaces for public API boundaries (e.g. `ChatEntry`, `ToolResult`, `GrokToolCall`).
28
+ - Use `type` imports when importing only types:
29
+ ```typescript
30
+ import type { ChatCompletionMessageParam } from "openai/resources/chat";
31
+ ```
32
+ - `any` is acceptable where strict typing would add friction, but prefer narrower types when practical.
33
+ - Shared types belong in `src/types/index.ts`.
34
+
35
+ ## Naming Conventions
36
+
37
+ - **Files**: kebab-case (`grok-agent.ts`, `chat-interface.tsx`, `settings-manager.ts`).
38
+ - **Classes**: PascalCase (`GrokAgent`, `TextEditorTool`, `BashTool`).
39
+ - **Interfaces/Types**: PascalCase (`ChatEntry`, `ToolResult`, `StreamingChunk`).
40
+ - **Functions/variables**: camelCase (`processUserMessage`, `loadApiKey`).
41
+ - **Constants**: camelCase or UPPER_SNAKE_CASE for true constants (`GROK_TOOLS`).
42
+
43
+ ## Error Handling
44
+
45
+ - Catch errors as `error: any` and access `.message` for display.
46
+ - Tool execution methods return `ToolResult` objects (`{ success, output?, error? }`) rather than throwing.
47
+ - Use `process.exit(1)` for fatal CLI errors.
48
+
49
+ ## ESLint Rules
50
+
51
+ - `@typescript-eslint/no-unused-vars`: error
52
+ - `@typescript-eslint/no-explicit-any`: warn
53
+
54
+ Run `bun run lint` to check and `bun run typecheck` to verify types.
@@ -0,0 +1,3 @@
1
+ {
2
+ "model": "grok-code-fast-1"
3
+ }
@@ -0,0 +1 @@
1
+ bun run pre-commit
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) [year] [copyright holders]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission statement shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.