cray-code 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +316 -0
- package/dist/Tool.d.ts +217 -0
- package/dist/Tool.d.ts.map +1 -0
- package/dist/Tool.js +89 -0
- package/dist/Tool.js.map +1 -0
- package/dist/branding/logo.d.ts +8 -0
- package/dist/branding/logo.d.ts.map +1 -0
- package/dist/branding/logo.js +26 -0
- package/dist/branding/logo.js.map +1 -0
- package/dist/branding/theme.d.ts +27 -0
- package/dist/branding/theme.d.ts.map +1 -0
- package/dist/branding/theme.js +28 -0
- package/dist/branding/theme.js.map +1 -0
- package/dist/commands/registry.d.ts +32 -0
- package/dist/commands/registry.d.ts.map +1 -0
- package/dist/commands/registry.js +759 -0
- package/dist/commands/registry.js.map +1 -0
- package/dist/components/MessageView.d.ts +12 -0
- package/dist/components/MessageView.d.ts.map +1 -0
- package/dist/components/MessageView.js +35 -0
- package/dist/components/MessageView.js.map +1 -0
- package/dist/components/PermissionPrompt.d.ts +11 -0
- package/dist/components/PermissionPrompt.d.ts.map +1 -0
- package/dist/components/PermissionPrompt.js +6 -0
- package/dist/components/PermissionPrompt.js.map +1 -0
- package/dist/components/PluginManager.d.ts +27 -0
- package/dist/components/PluginManager.d.ts.map +1 -0
- package/dist/components/PluginManager.js +391 -0
- package/dist/components/PluginManager.js.map +1 -0
- package/dist/components/ThinkingBlock.d.ts +27 -0
- package/dist/components/ThinkingBlock.d.ts.map +1 -0
- package/dist/components/ThinkingBlock.js +29 -0
- package/dist/components/ThinkingBlock.js.map +1 -0
- package/dist/components/ToolCallBlock.d.ts +14 -0
- package/dist/components/ToolCallBlock.d.ts.map +1 -0
- package/dist/components/ToolCallBlock.js +83 -0
- package/dist/components/ToolCallBlock.js.map +1 -0
- package/dist/components/TrustDialog.d.ts +20 -0
- package/dist/components/TrustDialog.d.ts.map +1 -0
- package/dist/components/TrustDialog.js +80 -0
- package/dist/components/TrustDialog.js.map +1 -0
- package/dist/context.d.ts +25 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +268 -0
- package/dist/context.js.map +1 -0
- package/dist/cray.d.ts +114 -0
- package/dist/cray.d.ts.map +1 -0
- package/dist/cray.js +338 -0
- package/dist/cray.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +122 -0
- package/dist/index.js.map +1 -0
- package/dist/plugins/registry.d.ts +106 -0
- package/dist/plugins/registry.d.ts.map +1 -0
- package/dist/plugins/registry.js +695 -0
- package/dist/plugins/registry.js.map +1 -0
- package/dist/query.d.ts +31 -0
- package/dist/query.d.ts.map +1 -0
- package/dist/query.js +637 -0
- package/dist/query.js.map +1 -0
- package/dist/queryStream.d.ts +36 -0
- package/dist/queryStream.d.ts.map +1 -0
- package/dist/queryStream.js +704 -0
- package/dist/queryStream.js.map +1 -0
- package/dist/screens/ReplScreen.d.ts +22 -0
- package/dist/screens/ReplScreen.d.ts.map +1 -0
- package/dist/screens/ReplScreen.js +763 -0
- package/dist/screens/ReplScreen.js.map +1 -0
- package/dist/services/agentRunner.d.ts +39 -0
- package/dist/services/agentRunner.d.ts.map +1 -0
- package/dist/services/agentRunner.js +115 -0
- package/dist/services/agentRunner.js.map +1 -0
- package/dist/services/compact.d.ts +34 -0
- package/dist/services/compact.d.ts.map +1 -0
- package/dist/services/compact.js +179 -0
- package/dist/services/compact.js.map +1 -0
- package/dist/services/loadPluginCommands.d.ts +55 -0
- package/dist/services/loadPluginCommands.d.ts.map +1 -0
- package/dist/services/loadPluginCommands.js +219 -0
- package/dist/services/loadPluginCommands.js.map +1 -0
- package/dist/services/mcp/index.d.ts +3 -0
- package/dist/services/mcp/index.d.ts.map +1 -0
- package/dist/services/mcp/index.js +3 -0
- package/dist/services/mcp/index.js.map +1 -0
- package/dist/services/mcp/manager.d.ts +24 -0
- package/dist/services/mcp/manager.d.ts.map +1 -0
- package/dist/services/mcp/manager.js +138 -0
- package/dist/services/mcp/manager.js.map +1 -0
- package/dist/services/mcp/types.d.ts +52 -0
- package/dist/services/mcp/types.d.ts.map +1 -0
- package/dist/services/mcp/types.js +5 -0
- package/dist/services/mcp/types.js.map +1 -0
- package/dist/services/memory.d.ts +38 -0
- package/dist/services/memory.d.ts.map +1 -0
- package/dist/services/memory.js +181 -0
- package/dist/services/memory.js.map +1 -0
- package/dist/services/permissionPrompt.d.ts +38 -0
- package/dist/services/permissionPrompt.d.ts.map +1 -0
- package/dist/services/permissionPrompt.js +83 -0
- package/dist/services/permissionPrompt.js.map +1 -0
- package/dist/services/permissions.d.ts +15 -0
- package/dist/services/permissions.d.ts.map +1 -0
- package/dist/services/permissions.js +237 -0
- package/dist/services/permissions.js.map +1 -0
- package/dist/services/sessionStorage.d.ts +51 -0
- package/dist/services/sessionStorage.d.ts.map +1 -0
- package/dist/services/sessionStorage.js +266 -0
- package/dist/services/sessionStorage.js.map +1 -0
- package/dist/setup.d.ts +22 -0
- package/dist/setup.d.ts.map +1 -0
- package/dist/setup.js +160 -0
- package/dist/setup.js.map +1 -0
- package/dist/skills/bundledSkills.d.ts +18 -0
- package/dist/skills/bundledSkills.d.ts.map +1 -0
- package/dist/skills/bundledSkills.js +277 -0
- package/dist/skills/bundledSkills.js.map +1 -0
- package/dist/skills/index.d.ts +4 -0
- package/dist/skills/index.d.ts.map +1 -0
- package/dist/skills/index.js +3 -0
- package/dist/skills/index.js.map +1 -0
- package/dist/skills/loadSkillsDir.d.ts +45 -0
- package/dist/skills/loadSkillsDir.d.ts.map +1 -0
- package/dist/skills/loadSkillsDir.js +233 -0
- package/dist/skills/loadSkillsDir.js.map +1 -0
- package/dist/state/AppState.d.ts +70 -0
- package/dist/state/AppState.d.ts.map +1 -0
- package/dist/state/AppState.js +106 -0
- package/dist/state/AppState.js.map +1 -0
- package/dist/tools/AgentTool.d.ts +62 -0
- package/dist/tools/AgentTool.d.ts.map +1 -0
- package/dist/tools/AgentTool.js +133 -0
- package/dist/tools/AgentTool.js.map +1 -0
- package/dist/tools/AskUserQuestionTool.d.ts +60 -0
- package/dist/tools/AskUserQuestionTool.d.ts.map +1 -0
- package/dist/tools/AskUserQuestionTool.js +52 -0
- package/dist/tools/AskUserQuestionTool.js.map +1 -0
- package/dist/tools/BashTool.d.ts +33 -0
- package/dist/tools/BashTool.d.ts.map +1 -0
- package/dist/tools/BashTool.js +211 -0
- package/dist/tools/BashTool.js.map +1 -0
- package/dist/tools/EditTool.d.ts +24 -0
- package/dist/tools/EditTool.d.ts.map +1 -0
- package/dist/tools/EditTool.js +102 -0
- package/dist/tools/EditTool.js.map +1 -0
- package/dist/tools/GlobTool.d.ts +17 -0
- package/dist/tools/GlobTool.d.ts.map +1 -0
- package/dist/tools/GlobTool.js +65 -0
- package/dist/tools/GlobTool.js.map +1 -0
- package/dist/tools/GrepTool.d.ts +30 -0
- package/dist/tools/GrepTool.d.ts.map +1 -0
- package/dist/tools/GrepTool.js +140 -0
- package/dist/tools/GrepTool.js.map +1 -0
- package/dist/tools/MCPTool.d.ts +24 -0
- package/dist/tools/MCPTool.d.ts.map +1 -0
- package/dist/tools/MCPTool.js +67 -0
- package/dist/tools/MCPTool.js.map +1 -0
- package/dist/tools/NotebookEditTool.d.ts +28 -0
- package/dist/tools/NotebookEditTool.d.ts.map +1 -0
- package/dist/tools/NotebookEditTool.js +213 -0
- package/dist/tools/NotebookEditTool.js.map +1 -0
- package/dist/tools/NotebookReadTool.d.ts +19 -0
- package/dist/tools/NotebookReadTool.d.ts.map +1 -0
- package/dist/tools/NotebookReadTool.js +191 -0
- package/dist/tools/NotebookReadTool.js.map +1 -0
- package/dist/tools/PlanTools.d.ts +17 -0
- package/dist/tools/PlanTools.d.ts.map +1 -0
- package/dist/tools/PlanTools.js +65 -0
- package/dist/tools/PlanTools.js.map +1 -0
- package/dist/tools/ReadTool.d.ts +21 -0
- package/dist/tools/ReadTool.d.ts.map +1 -0
- package/dist/tools/ReadTool.js +202 -0
- package/dist/tools/ReadTool.js.map +1 -0
- package/dist/tools/SkillTool.d.ts +32 -0
- package/dist/tools/SkillTool.d.ts.map +1 -0
- package/dist/tools/SkillTool.js +217 -0
- package/dist/tools/SkillTool.js.map +1 -0
- package/dist/tools/TodoWriteTool.d.ts +35 -0
- package/dist/tools/TodoWriteTool.d.ts.map +1 -0
- package/dist/tools/TodoWriteTool.js +58 -0
- package/dist/tools/TodoWriteTool.js.map +1 -0
- package/dist/tools/WebFetchTool.d.ts +17 -0
- package/dist/tools/WebFetchTool.d.ts.map +1 -0
- package/dist/tools/WebFetchTool.js +97 -0
- package/dist/tools/WebFetchTool.js.map +1 -0
- package/dist/tools/WebSearchTool.d.ts +18 -0
- package/dist/tools/WebSearchTool.d.ts.map +1 -0
- package/dist/tools/WebSearchTool.js +76 -0
- package/dist/tools/WebSearchTool.js.map +1 -0
- package/dist/tools/WriteTool.d.ts +17 -0
- package/dist/tools/WriteTool.d.ts.map +1 -0
- package/dist/tools/WriteTool.js +84 -0
- package/dist/tools/WriteTool.js.map +1 -0
- package/dist/tools/index.d.ts +21 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +20 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools.d.ts +34 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +102 -0
- package/dist/tools.js.map +1 -0
- package/dist/types/events.d.ts +85 -0
- package/dist/types/events.d.ts.map +1 -0
- package/dist/types/events.js +12 -0
- package/dist/types/events.js.map +1 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +4 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/message.d.ts +71 -0
- package/dist/types/message.d.ts.map +1 -0
- package/dist/types/message.js +5 -0
- package/dist/types/message.js.map +1 -0
- package/dist/types/permission.d.ts +56 -0
- package/dist/types/permission.d.ts.map +1 -0
- package/dist/types/permission.js +46 -0
- package/dist/types/permission.js.map +1 -0
- package/dist/types/processUserInput.d.ts +18 -0
- package/dist/types/processUserInput.d.ts.map +1 -0
- package/dist/types/processUserInput.js +8 -0
- package/dist/types/processUserInput.js.map +1 -0
- package/dist/types/tool.d.ts +32 -0
- package/dist/types/tool.d.ts.map +1 -0
- package/dist/types/tool.js +5 -0
- package/dist/types/tool.js.map +1 -0
- package/dist/utils/compactBoundary.d.ts +11 -0
- package/dist/utils/compactBoundary.d.ts.map +1 -0
- package/dist/utils/compactBoundary.js +26 -0
- package/dist/utils/compactBoundary.js.map +1 -0
- package/dist/utils/configStore.d.ts +41 -0
- package/dist/utils/configStore.d.ts.map +1 -0
- package/dist/utils/configStore.js +111 -0
- package/dist/utils/configStore.js.map +1 -0
- package/dist/utils/forkedAgent.d.ts +40 -0
- package/dist/utils/forkedAgent.d.ts.map +1 -0
- package/dist/utils/forkedAgent.js +231 -0
- package/dist/utils/forkedAgent.js.map +1 -0
- package/dist/utils/messages.d.ts +14 -0
- package/dist/utils/messages.d.ts.map +1 -0
- package/dist/utils/messages.js +29 -0
- package/dist/utils/messages.js.map +1 -0
- package/dist/utils/sandbox.d.ts +22 -0
- package/dist/utils/sandbox.d.ts.map +1 -0
- package/dist/utils/sandbox.js +59 -0
- package/dist/utils/sandbox.js.map +1 -0
- package/dist/utils/sideQuestion.d.ts +29 -0
- package/dist/utils/sideQuestion.d.ts.map +1 -0
- package/dist/utils/sideQuestion.js +81 -0
- package/dist/utils/sideQuestion.js.map +1 -0
- package/install.ps1 +86 -0
- package/install.sh +92 -0
- package/package.json +68 -0
package/README.md
ADDED
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
# 🦀 Cray Code
|
|
2
|
+
|
|
3
|
+
> **A powerful, extensible AI agent framework for the terminal** — MCP, Skills, Sub-agents, and multi-provider LLM support.
|
|
4
|
+
|
|
5
|
+
Cray Code is an AI coding assistant framework inspired by [Claude Code](https://claude.ai/code)'s architecture. It provides a unified tool interface, full [Model Context Protocol (MCP)](https://modelcontextprotocol.io) integration, a flexible skills system, sub-agent orchestration, and plugin extensibility — all running in a beautiful React/Ink terminal UI.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
| Feature | Description |
|
|
12
|
+
|---|---|
|
|
13
|
+
| **🧠 Multi-Provider** | Anthropic, OpenAI, Ollama, OpenRouter, DeepSeek, or any OpenAI-compatible API |
|
|
14
|
+
| **🔧 Unified Tool System** | All operations (file I/O, shell, MCP, agent, skill) share a single, uniform interface |
|
|
15
|
+
| **🔌 MCP Integration** | Full [Model Context Protocol](https://modelcontextprotocol.io) support — stdio, SSE, WebSocket transports |
|
|
16
|
+
| **📜 Skills System** | Bundled + disk-based skills with tool restrictions, model overrides, and `/skill` invocation |
|
|
17
|
+
| **👾 Sub-Agent Support** | Spawn specialized child agents with constrained tool access, receive structured results |
|
|
18
|
+
| **🧩 Plugin Architecture** | Extensible plugin system for commands, skills, MCP servers, and lifecycle hooks |
|
|
19
|
+
| **💻 Rich Terminal UI** | Real-time thinking display, tool call visualization, React/Ink-based REPL |
|
|
20
|
+
| **💾 Session Management** | Session persistence, resumption, and automatic context compaction |
|
|
21
|
+
| **🔐 Permission System** | Four modes: `default`, `acceptEdits`, `bypass`, `plan` — fine-grained tool-level control |
|
|
22
|
+
| **⚡ Stream & Async** | Async generator event loop, streaming LLM responses, concurrent background agents |
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Quick Start
|
|
27
|
+
|
|
28
|
+
### Prerequisites
|
|
29
|
+
|
|
30
|
+
- **Node.js** >= 18.0.0
|
|
31
|
+
- **npm** (comes with Node.js)
|
|
32
|
+
|
|
33
|
+
### Install
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
# Install globally via npm
|
|
37
|
+
npm install -g cray-code
|
|
38
|
+
|
|
39
|
+
# Or install from the repo
|
|
40
|
+
git clone https://github.com/WYH/cray-code.git
|
|
41
|
+
cd cray-code
|
|
42
|
+
npm install
|
|
43
|
+
npm run build
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### First Run
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
# Run the setup wizard (required first time)
|
|
50
|
+
cray --setup
|
|
51
|
+
|
|
52
|
+
# Start interactive session
|
|
53
|
+
cray
|
|
54
|
+
|
|
55
|
+
# Start with an initial prompt
|
|
56
|
+
cray "Review the current codebase"
|
|
57
|
+
|
|
58
|
+
# Run in a specific directory
|
|
59
|
+
cray --dir /path/to/project
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## Usage
|
|
65
|
+
|
|
66
|
+
### CLI Options
|
|
67
|
+
|
|
68
|
+
| Option | Description |
|
|
69
|
+
|---|---|
|
|
70
|
+
| `[prompt]` | First message to send, then stay interactive |
|
|
71
|
+
| `-m, --model <model>` | Override the configured model |
|
|
72
|
+
| `-d, --dir <directory>` | Working directory |
|
|
73
|
+
| `-p, --permission <mode>` | Permission mode: `default`, `acceptEdits`, `bypass`, `plan` |
|
|
74
|
+
| `-v, --verbose` | Enable verbose logging |
|
|
75
|
+
| `--max-turns <number>` | Max agent loop turns (default: 25) |
|
|
76
|
+
| `--resume <sessionId>` | Resume a previous conversation |
|
|
77
|
+
| `--setup` | Re-run the setup wizard |
|
|
78
|
+
| `--show-welcome` | Display the welcome banner and exit |
|
|
79
|
+
| `--list-sessions` | List saved sessions and exit |
|
|
80
|
+
|
|
81
|
+
### Commands (Slash Commands)
|
|
82
|
+
|
|
83
|
+
Inside the interactive REPL, use `/` commands:
|
|
84
|
+
|
|
85
|
+
```
|
|
86
|
+
/help Show available commands
|
|
87
|
+
/model Change the active model
|
|
88
|
+
/config View or change configuration
|
|
89
|
+
/setup Re-run the setup wizard
|
|
90
|
+
/sessions List and manage sessions
|
|
91
|
+
/clear Clear the conversation
|
|
92
|
+
/exit Exit Cray Code
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Programmatic API
|
|
96
|
+
|
|
97
|
+
Use Cray Code as a library in your own projects:
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
import CrayCode from 'cray-code';
|
|
101
|
+
|
|
102
|
+
const cray = new CrayCode({
|
|
103
|
+
cwd: process.cwd(),
|
|
104
|
+
provider: 'anthropic',
|
|
105
|
+
model: 'claude-sonnet-4-6',
|
|
106
|
+
apiKey: process.env.ANTHROPIC_API_KEY,
|
|
107
|
+
permissionMode: 'default',
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
await cray.initialize();
|
|
111
|
+
|
|
112
|
+
const result = await cray.processMessage('Review this code');
|
|
113
|
+
console.log(result.finalResponse);
|
|
114
|
+
|
|
115
|
+
await cray.shutdown();
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## Architecture
|
|
121
|
+
|
|
122
|
+
```
|
|
123
|
+
┌──────────────────────────────────────────────────────┐
|
|
124
|
+
│ CrayCode Class │
|
|
125
|
+
│ (Orchestrator — EventEmitter-based) │
|
|
126
|
+
├──────────────────────────────────────────────────────┤
|
|
127
|
+
│ │ │
|
|
128
|
+
│ ┌──────────────────┼──────────────────┐ │
|
|
129
|
+
│ ▼ ▼ ▼ │
|
|
130
|
+
│ ┌──────┐ ┌──────────────┐ ┌──────────┐ │
|
|
131
|
+
│ │ Tool │ │ Query Loop │ │ Skills │ │
|
|
132
|
+
│ │ Pool │ │ (agent │ │ System │ │
|
|
133
|
+
│ │ │ │ loop) │ │ │ │
|
|
134
|
+
│ └──┬───┘ └──────┬───────┘ └────┬─────┘ │
|
|
135
|
+
│ │ │ │ │
|
|
136
|
+
│ ▼ ▼ ▼ │
|
|
137
|
+
│ ┌──────────────────────────────────────────┐ │
|
|
138
|
+
│ │ Provider Layer │ │
|
|
139
|
+
│ │ Anthropic │ OpenAI │ Ollama │ OpenRouter │ │
|
|
140
|
+
│ │ DeepSeek │ Custom │ │
|
|
141
|
+
│ └──────────────────────────────────────────┘ │
|
|
142
|
+
│ │ │
|
|
143
|
+
│ ┌──────────────────┼──────────────────┐ │
|
|
144
|
+
│ ▼ ▼ ▼ │
|
|
145
|
+
│ ┌────────┐ ┌──────────────┐ ┌────────────┐ │
|
|
146
|
+
│ │ MCP │ │ Plugins │ │ React/Ink │ │
|
|
147
|
+
│ │Servers │ │ │ │ Terminal │ │
|
|
148
|
+
│ └────────┘ └──────────────┘ │ UI │ │
|
|
149
|
+
│ └────────────┘ │
|
|
150
|
+
└──────────────────────────────────────────────────────┘
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Core Components
|
|
154
|
+
|
|
155
|
+
#### Tool System (`Tool.ts`)
|
|
156
|
+
Every tool follows the same interface — file operations, shell commands, MCP calls, skills, and sub-agents all conform to `ToolDef<Input, Output>`. This uniform design means the LLM interacts with all capabilities through a single, predictable pattern.
|
|
157
|
+
|
|
158
|
+
#### Query Loop (`query.ts`)
|
|
159
|
+
The core agent loop uses an async generator pattern that yields typed `QueryEvent`s. The React/Ink UI consumes these events via `for-await` and renders real-time updates — thinking, tool calls, results, and errors.
|
|
160
|
+
|
|
161
|
+
#### MCP Integration
|
|
162
|
+
Full [Model Context Protocol](https://modelcontextprotocol.io) support via `@modelcontextprotocol/sdk`. Connect external tools dynamically — databases, APIs, file systems, and more — through stdio, SSE, or WebSocket transports.
|
|
163
|
+
|
|
164
|
+
#### Skills System
|
|
165
|
+
Skills are markdown files with frontmatter that define how the model should behave. They can restrict tools, override models, inject context, or spawn sub-agents. Skills are loaded from:
|
|
166
|
+
- **Bundled** — built-in skills shipped with Cray Code
|
|
167
|
+
- **Disk** — user-created skills in the project directory
|
|
168
|
+
- **Plugin** — skills contributed by plugins
|
|
169
|
+
|
|
170
|
+
#### Sub-Agent Support
|
|
171
|
+
The `AgentTool` spawns child agents with constrained tool access, preventing infinite recursion while enabling complex parallel workflows. Sub-agents run in isolation with their own context and return structured results.
|
|
172
|
+
|
|
173
|
+
#### Plugin Architecture
|
|
174
|
+
Plugins extend Cray Code with custom commands, skills, MCP servers, and lifecycle hooks (`sessionStart`, `sessionEnd`). The plugin registry discovers and loads plugins at startup.
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
## Configuration
|
|
179
|
+
|
|
180
|
+
Configuration is stored in `~/.cray/settings.json`:
|
|
181
|
+
|
|
182
|
+
```json
|
|
183
|
+
{
|
|
184
|
+
"provider": "anthropic",
|
|
185
|
+
"model": "claude-sonnet-4-6",
|
|
186
|
+
"apiKey": "sk-...",
|
|
187
|
+
"baseUrl": "",
|
|
188
|
+
"setupComplete": true,
|
|
189
|
+
"permissionMode": "default",
|
|
190
|
+
"maxTurns": 25,
|
|
191
|
+
"verbose": false
|
|
192
|
+
}
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
Environment variables:
|
|
196
|
+
- `CRAY_API_KEY` — API key (overrides config)
|
|
197
|
+
- `CRAY_MODEL` — Default model (overrides config)
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
## Provider Support
|
|
202
|
+
|
|
203
|
+
| Provider | Type | API Key Required |
|
|
204
|
+
|---|---|---|
|
|
205
|
+
| [Anthropic](https://anthropic.com) | Native | Yes |
|
|
206
|
+
| [OpenAI](https://openai.com) | OpenAI-compatible | Yes |
|
|
207
|
+
| [Ollama](https://ollama.ai) | OpenAI-compatible | No |
|
|
208
|
+
| [OpenRouter](https://openrouter.ai) | OpenAI-compatible | Yes |
|
|
209
|
+
| [DeepSeek](https://deepseek.com) | OpenAI-compatible | Yes |
|
|
210
|
+
| Custom | OpenAI-compatible | Configurable |
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
## Development
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
# Install dependencies
|
|
218
|
+
npm install
|
|
219
|
+
|
|
220
|
+
# Build TypeScript
|
|
221
|
+
npm run build
|
|
222
|
+
|
|
223
|
+
# Development mode (with hot-reload via tsx)
|
|
224
|
+
npm run dev
|
|
225
|
+
|
|
226
|
+
# Run tests
|
|
227
|
+
node run_test.mjs
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### Project Structure
|
|
231
|
+
|
|
232
|
+
```
|
|
233
|
+
cray-code/
|
|
234
|
+
├── src/
|
|
235
|
+
│ ├── index.ts # CLI entry point & REPL
|
|
236
|
+
│ ├── cray.ts # Main orchestrator class
|
|
237
|
+
│ ├── Tool.ts # Core tool abstraction
|
|
238
|
+
│ ├── tools.ts # Tool registry & assembly
|
|
239
|
+
│ ├── query.ts # Agent loop (LLM calls + tool execution)
|
|
240
|
+
│ ├── queryStream.ts # Streaming variant
|
|
241
|
+
│ ├── context.ts # Tool context builder
|
|
242
|
+
│ ├── setup.ts # First-run setup wizard
|
|
243
|
+
│ ├── tools/ # Built-in tool implementations
|
|
244
|
+
│ ├── services/ # MCP, session, config, compaction services
|
|
245
|
+
│ ├── commands/ # Slash command system
|
|
246
|
+
│ ├── skills/ # Skills system (bundled + disk)
|
|
247
|
+
│ ├── plugins/ # Plugin discovery & registry
|
|
248
|
+
│ ├── screens/ # React/Ink terminal screens
|
|
249
|
+
│ ├── types/ # TypeScript type definitions
|
|
250
|
+
│ └── branding/ # Logo & theme
|
|
251
|
+
├── dist/ # Compiled output
|
|
252
|
+
├── install.sh # Unix installer
|
|
253
|
+
├── install.ps1 # Windows installer
|
|
254
|
+
├── package.json
|
|
255
|
+
└── tsconfig.json
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
### Building & Publishing
|
|
259
|
+
|
|
260
|
+
```bash
|
|
261
|
+
# Build for production
|
|
262
|
+
npm run build
|
|
263
|
+
|
|
264
|
+
# Create npm tarball
|
|
265
|
+
npm run pack:tarball
|
|
266
|
+
|
|
267
|
+
# Create tarball and install locally
|
|
268
|
+
npm run pack:install-local
|
|
269
|
+
|
|
270
|
+
# Publish to npm
|
|
271
|
+
npm publish
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
---
|
|
275
|
+
|
|
276
|
+
## Skills
|
|
277
|
+
|
|
278
|
+
Skills are markdown-based instructions that guide the AI's behavior. They support:
|
|
279
|
+
|
|
280
|
+
- **Tool restrictions** — limit the AI to specific tools
|
|
281
|
+
- **Model overrides** — use a different model for specific tasks
|
|
282
|
+
- **Context injection** — inject content inline or fork a sub-agent
|
|
283
|
+
- **User invocation** — invoke via `/skill-name` in the REPL
|
|
284
|
+
- **Argument substitution** — `{{arg}}` templates in skill content
|
|
285
|
+
|
|
286
|
+
### Creating a Skill
|
|
287
|
+
|
|
288
|
+
Create a `SKILL.md` file with frontmatter:
|
|
289
|
+
|
|
290
|
+
```markdown
|
|
291
|
+
---
|
|
292
|
+
name: my-skill
|
|
293
|
+
description: Does something useful
|
|
294
|
+
allowedTools: [read, write, bash]
|
|
295
|
+
model: claude-sonnet-4-6
|
|
296
|
+
---
|
|
297
|
+
|
|
298
|
+
Follow these instructions when this skill is active:
|
|
299
|
+
1. Read the relevant files
|
|
300
|
+
2. Analyze the problem
|
|
301
|
+
3. Apply the fix
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
---
|
|
305
|
+
|
|
306
|
+
## License
|
|
307
|
+
|
|
308
|
+
MIT — see [LICENSE](LICENSE) for details.
|
|
309
|
+
|
|
310
|
+
---
|
|
311
|
+
|
|
312
|
+
## Acknowledgements
|
|
313
|
+
|
|
314
|
+
- Inspired by [Claude Code](https://claude.ai/code) by Anthropic
|
|
315
|
+
- Built on [Model Context Protocol](https://modelcontextprotocol.io)
|
|
316
|
+
- Terminal UI powered by [React](https://react.dev) & [Ink](https://github.com/vadimdemedes/ink)
|
package/dist/Tool.d.ts
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool.ts — Core Tool Abstraction for Cray Code
|
|
3
|
+
*
|
|
4
|
+
* Every tool in Cray Code follows the same interface, making them uniformly
|
|
5
|
+
* usable by LLMs. This is the central design pattern inherited from Claude Code.
|
|
6
|
+
*
|
|
7
|
+
* Key design principles:
|
|
8
|
+
* 1. Unified interface — all tools (files, shell, MCP, agent, skill) conform
|
|
9
|
+
* 2. Schema-driven — Zod schemas for input validation + JSON Schema for LLM
|
|
10
|
+
* 3. Permission-aware — every tool declares its permission requirements
|
|
11
|
+
* 4. Progress-reporting — long-running tools can stream progress
|
|
12
|
+
* 5. Composable — tools can be wrapped (MCPTool wraps external tools)
|
|
13
|
+
*/
|
|
14
|
+
import type { z } from 'zod';
|
|
15
|
+
import type { Message, ToolResultContent } from './types/message.js';
|
|
16
|
+
import type { PermissionResult, ToolPermissionContext } from './types/permission.js';
|
|
17
|
+
import type { ToolProgressData } from './types/tool.js';
|
|
18
|
+
/**
|
|
19
|
+
* Context provided to every tool invocation.
|
|
20
|
+
* Contains everything a tool needs to execute: state, permissions, I/O.
|
|
21
|
+
*/
|
|
22
|
+
export interface ToolUseContext {
|
|
23
|
+
/** Working directory for filesystem operations */
|
|
24
|
+
cwd: string;
|
|
25
|
+
/** Current permission mode and rules */
|
|
26
|
+
permissionContext: ToolPermissionContext;
|
|
27
|
+
/** Abort signal for cancellation */
|
|
28
|
+
abortSignal: AbortSignal;
|
|
29
|
+
/** Available MCP server connections */
|
|
30
|
+
mcpClients: Map<string, MCPClientInfo>;
|
|
31
|
+
/** Available skills */
|
|
32
|
+
availableSkills: SkillInfo[];
|
|
33
|
+
/** Available agent definitions */
|
|
34
|
+
agentDefinitions: AgentDefinitionInfo[];
|
|
35
|
+
/** System prompt for context awareness */
|
|
36
|
+
systemPromptParts: string[];
|
|
37
|
+
/** Current message history */
|
|
38
|
+
messages: Message[];
|
|
39
|
+
/** Current model configuration */
|
|
40
|
+
modelConfig: ModelConfig;
|
|
41
|
+
/** Write a progress message to the output */
|
|
42
|
+
writeProgress(data: ToolProgressData): void;
|
|
43
|
+
/** Log a message for debugging */
|
|
44
|
+
logDebug(message: string): void;
|
|
45
|
+
}
|
|
46
|
+
export interface MCPClientInfo {
|
|
47
|
+
serverName: string;
|
|
48
|
+
tools: MCPToolInfo[];
|
|
49
|
+
resources: MCPResourceInfo[];
|
|
50
|
+
connected: boolean;
|
|
51
|
+
}
|
|
52
|
+
export interface MCPToolInfo {
|
|
53
|
+
name: string;
|
|
54
|
+
description: string;
|
|
55
|
+
inputSchema: Record<string, unknown>;
|
|
56
|
+
}
|
|
57
|
+
export interface MCPResourceInfo {
|
|
58
|
+
uri: string;
|
|
59
|
+
name: string;
|
|
60
|
+
description?: string;
|
|
61
|
+
mimeType?: string;
|
|
62
|
+
}
|
|
63
|
+
export interface SkillInfo {
|
|
64
|
+
/** Skill name (e.g., 'code-review', 'brainstorming') */
|
|
65
|
+
name: string;
|
|
66
|
+
/** Human-readable description */
|
|
67
|
+
description: string;
|
|
68
|
+
/** When the model should consider using this skill (injected into system prompt) */
|
|
69
|
+
whenToUse?: string;
|
|
70
|
+
/** The full SKILL.md body content (after frontmatter parsing) */
|
|
71
|
+
content?: string;
|
|
72
|
+
/** Optional base directory for skill reference files */
|
|
73
|
+
baseDir?: string;
|
|
74
|
+
/** Tools this skill is restricted to (empty = all tools) */
|
|
75
|
+
allowedTools?: string[];
|
|
76
|
+
/** Model override for this skill */
|
|
77
|
+
model?: string;
|
|
78
|
+
/** Execution context: 'inline' injects content into conversation, 'fork' spawns a sub-agent */
|
|
79
|
+
context?: 'inline' | 'fork';
|
|
80
|
+
/** Whether the user can invoke this skill via /name */
|
|
81
|
+
userInvocable?: boolean;
|
|
82
|
+
/** Whether the model is blocked from invoking this skill */
|
|
83
|
+
disableModelInvocation?: boolean;
|
|
84
|
+
/** Hint shown next to the command in help listings */
|
|
85
|
+
argumentHint?: string;
|
|
86
|
+
/** Argument names for ${arg} substitution in skill content */
|
|
87
|
+
argNames?: string[];
|
|
88
|
+
/** Source of the skill (bundled, disk, plugin) */
|
|
89
|
+
source?: 'bundled' | 'disk' | 'plugin';
|
|
90
|
+
}
|
|
91
|
+
export interface AgentDefinitionInfo {
|
|
92
|
+
name: string;
|
|
93
|
+
description: string;
|
|
94
|
+
allowedTools: string[];
|
|
95
|
+
model?: string;
|
|
96
|
+
}
|
|
97
|
+
export interface ModelConfig {
|
|
98
|
+
provider: string;
|
|
99
|
+
model: string;
|
|
100
|
+
maxTokens: number;
|
|
101
|
+
thinkingEnabled: boolean;
|
|
102
|
+
apiKey: string;
|
|
103
|
+
baseUrl: string;
|
|
104
|
+
}
|
|
105
|
+
export interface ToolResult<T = unknown> {
|
|
106
|
+
/** Core result data */
|
|
107
|
+
data: T;
|
|
108
|
+
/** Optional string representation for the LLM */
|
|
109
|
+
content?: string;
|
|
110
|
+
/** Whether an error occurred */
|
|
111
|
+
isError?: boolean;
|
|
112
|
+
/** If the result was truncated */
|
|
113
|
+
truncated?: boolean;
|
|
114
|
+
/** Title for display */
|
|
115
|
+
title?: string;
|
|
116
|
+
/** Rendered UI content */
|
|
117
|
+
render?: ToolResultRender;
|
|
118
|
+
/**
|
|
119
|
+
* New messages to inject into the conversation.
|
|
120
|
+
* SkillTool uses this to inject skill content; AgentTool uses this for
|
|
121
|
+
* sub-agent results that should persist in the conversation.
|
|
122
|
+
*/
|
|
123
|
+
newMessages?: Message[];
|
|
124
|
+
/**
|
|
125
|
+
* Modify the tool-use context for subsequent turns.
|
|
126
|
+
* SkillTool uses this to restrict allowed tools and apply model overrides.
|
|
127
|
+
*/
|
|
128
|
+
contextModifier?(ctx: ToolUseContext): ToolUseContext;
|
|
129
|
+
}
|
|
130
|
+
export interface ToolResultRender {
|
|
131
|
+
type: 'text' | 'diff' | 'list' | 'card' | 'custom';
|
|
132
|
+
content: string;
|
|
133
|
+
language?: string;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Abstract tool definition. Concrete tools extend this.
|
|
137
|
+
*
|
|
138
|
+
* Type parameters:
|
|
139
|
+
* - Input: Zod schema type for the tool's input
|
|
140
|
+
* - Output: The type of data the tool returns
|
|
141
|
+
*/
|
|
142
|
+
export interface ToolDef<Input extends z.ZodTypeAny, Output = unknown> {
|
|
143
|
+
/** Unique tool name (e.g., 'read', 'bash', 'agent') */
|
|
144
|
+
name: string;
|
|
145
|
+
/** Alternative names */
|
|
146
|
+
aliases?: string[];
|
|
147
|
+
/** Search hint for tool search */
|
|
148
|
+
searchHint?: string;
|
|
149
|
+
/** Zod schema for input validation */
|
|
150
|
+
inputSchema: Input;
|
|
151
|
+
/** JSON Schema version for LLM consumption */
|
|
152
|
+
inputJSONSchema?: Record<string, unknown>;
|
|
153
|
+
/** Zod schema for output validation */
|
|
154
|
+
outputSchema?: z.ZodTypeAny;
|
|
155
|
+
/** Human-readable description */
|
|
156
|
+
description(input: z.infer<Input>): string | Promise<string>;
|
|
157
|
+
/** System prompt addition describing this tool */
|
|
158
|
+
prompt?(): string | Promise<string>;
|
|
159
|
+
/** User-facing name for display */
|
|
160
|
+
userFacingName(input: z.infer<Input>): string;
|
|
161
|
+
/** Is this tool currently enabled? */
|
|
162
|
+
isEnabled?(): boolean;
|
|
163
|
+
/** Is this tool read-only? (no side effects) */
|
|
164
|
+
isReadOnly?(input: z.infer<Input>): boolean;
|
|
165
|
+
/** Is this tool safe for concurrent use? */
|
|
166
|
+
isConcurrencySafe?(): boolean;
|
|
167
|
+
/** Is this tool destructive? (triggers extra warning) */
|
|
168
|
+
isDestructive?(input: z.infer<Input>): boolean;
|
|
169
|
+
/** Maximum result size in characters before truncation */
|
|
170
|
+
maxResultSizeChars?: number;
|
|
171
|
+
/** Core execution function */
|
|
172
|
+
call(input: z.infer<Input>, context: ToolUseContext): Promise<ToolResult<Output>>;
|
|
173
|
+
/** Permission check - called before execution */
|
|
174
|
+
checkPermissions?(input: z.infer<Input>, context: ToolUseContext): Promise<PermissionResult>;
|
|
175
|
+
/** Validate input before execution (return true or error message) */
|
|
176
|
+
validateInput?(input: z.infer<Input>, context: ToolUseContext): Promise<{
|
|
177
|
+
result: true;
|
|
178
|
+
} | {
|
|
179
|
+
result: false;
|
|
180
|
+
message: string;
|
|
181
|
+
}>;
|
|
182
|
+
/** Render tool use message in UI */
|
|
183
|
+
renderToolUseMessage?(input: z.infer<Input>, context: ToolUseContext): string;
|
|
184
|
+
/** Render tool result in UI */
|
|
185
|
+
renderToolResultMessage?(input: z.infer<Input>, result: ToolResult<Output>, context: ToolUseContext): string;
|
|
186
|
+
/** Format result for the LLM as content blocks */
|
|
187
|
+
mapToolResultToContentBlocks?(result: ToolResult<Output>, toolUseId: string): ToolResultContent[];
|
|
188
|
+
/** MCP info for tools proxied through MCP */
|
|
189
|
+
mcpInfo?: {
|
|
190
|
+
serverName: string;
|
|
191
|
+
toolName: string;
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Build a tool from a definition. This is the standard factory function.
|
|
196
|
+
* Wraps common logic: permission checks, input validation, result formatting.
|
|
197
|
+
*/
|
|
198
|
+
export declare function buildTool<Input extends z.ZodTypeAny, Output = unknown>(overrides: Partial<ToolDef<Input, Output>> & {
|
|
199
|
+
name: string;
|
|
200
|
+
inputSchema: Input;
|
|
201
|
+
}): ToolDef<Input, Output>;
|
|
202
|
+
/** Check if a tool name matches the given name or aliases */
|
|
203
|
+
export declare function toolMatchesName(tool: ToolDef<any, any>, name: string): boolean;
|
|
204
|
+
/** Find a tool by name in a tool collection */
|
|
205
|
+
export declare function findTool(tools: ToolDef<any, any>[], name: string): ToolDef<any, any> | undefined;
|
|
206
|
+
export interface AssembleToolPoolInput {
|
|
207
|
+
builtinTools: ToolDef<any, any>[];
|
|
208
|
+
mcpTools: ToolDef<any, any>[];
|
|
209
|
+
permissionContext: ToolPermissionContext;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Assemble the final tool pool from built-in tools + MCP tools.
|
|
213
|
+
* Built-in tools take precedence; MCP tools fill gaps.
|
|
214
|
+
* Permission rules filter the final result.
|
|
215
|
+
*/
|
|
216
|
+
export declare function assembleToolPool(input: AssembleToolPoolInput): ToolDef<any, any>[];
|
|
217
|
+
//# sourceMappingURL=Tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Tool.d.ts","sourceRoot":"","sources":["../src/Tool.ts"],"names":[],"mappings":"AAAA;;;;;;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AG,EAAE,GAAG,CAAC,EAAE,CAAC;IAC9B,iBAAiB,EAAE,qBAAqB,CAAC;CAC1C;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,GAAG,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAmBlF"}
|
package/dist/Tool.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool.ts — Core Tool Abstraction for Cray Code
|
|
3
|
+
*
|
|
4
|
+
* Every tool in Cray Code follows the same interface, making them uniformly
|
|
5
|
+
* usable by LLMs. This is the central design pattern inherited from Claude Code.
|
|
6
|
+
*
|
|
7
|
+
* Key design principles:
|
|
8
|
+
* 1. Unified interface — all tools (files, shell, MCP, agent, skill) conform
|
|
9
|
+
* 2. Schema-driven — Zod schemas for input validation + JSON Schema for LLM
|
|
10
|
+
* 3. Permission-aware — every tool declares its permission requirements
|
|
11
|
+
* 4. Progress-reporting — long-running tools can stream progress
|
|
12
|
+
* 5. Composable — tools can be wrapped (MCPTool wraps external tools)
|
|
13
|
+
*/
|
|
14
|
+
// ─── Tool Builder ────────────────────────────────────────────────────────
|
|
15
|
+
/**
|
|
16
|
+
* Build a tool from a definition. This is the standard factory function.
|
|
17
|
+
* Wraps common logic: permission checks, input validation, result formatting.
|
|
18
|
+
*/
|
|
19
|
+
export function buildTool(overrides) {
|
|
20
|
+
const defaults = {
|
|
21
|
+
maxResultSizeChars: 100_000,
|
|
22
|
+
isEnabled: () => true,
|
|
23
|
+
isConcurrencySafe: () => true,
|
|
24
|
+
isReadOnly: () => false,
|
|
25
|
+
isDestructive: () => false,
|
|
26
|
+
aliases: [],
|
|
27
|
+
async description(_input) {
|
|
28
|
+
return overrides.name;
|
|
29
|
+
},
|
|
30
|
+
userFacingName(_input) {
|
|
31
|
+
return overrides.name;
|
|
32
|
+
},
|
|
33
|
+
async checkPermissions() {
|
|
34
|
+
return { behavior: 'allow' };
|
|
35
|
+
},
|
|
36
|
+
mapToolResultToContentBlocks(result, toolUseId) {
|
|
37
|
+
const content = result.content ?? JSON.stringify(result.data, null, 2);
|
|
38
|
+
return [
|
|
39
|
+
{
|
|
40
|
+
type: 'tool_result',
|
|
41
|
+
tool_use_id: toolUseId,
|
|
42
|
+
content,
|
|
43
|
+
is_error: result.isError,
|
|
44
|
+
},
|
|
45
|
+
];
|
|
46
|
+
},
|
|
47
|
+
renderToolUseMessage(input) {
|
|
48
|
+
return `${overrides.name}(${JSON.stringify(input)})`;
|
|
49
|
+
},
|
|
50
|
+
renderToolResultMessage(_input, result) {
|
|
51
|
+
if (result.isError)
|
|
52
|
+
return `Error: ${result.content}`;
|
|
53
|
+
if (result.truncated)
|
|
54
|
+
return `${result.content}\n... [truncated]`;
|
|
55
|
+
return result.content ?? 'Done.';
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
return { ...defaults, ...overrides };
|
|
59
|
+
}
|
|
60
|
+
// ─── Tool Matching ───────────────────────────────────────────────────────
|
|
61
|
+
/** Check if a tool name matches the given name or aliases */
|
|
62
|
+
export function toolMatchesName(tool, name) {
|
|
63
|
+
if (tool.name === name)
|
|
64
|
+
return true;
|
|
65
|
+
return tool.aliases?.includes(name) ?? false;
|
|
66
|
+
}
|
|
67
|
+
/** Find a tool by name in a tool collection */
|
|
68
|
+
export function findTool(tools, name) {
|
|
69
|
+
return tools.find((t) => toolMatchesName(t, name));
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Assemble the final tool pool from built-in tools + MCP tools.
|
|
73
|
+
* Built-in tools take precedence; MCP tools fill gaps.
|
|
74
|
+
* Permission rules filter the final result.
|
|
75
|
+
*/
|
|
76
|
+
export function assembleToolPool(input) {
|
|
77
|
+
const { builtinTools, mcpTools, permissionContext } = input;
|
|
78
|
+
const builtinNames = new Set(builtinTools.map((t) => t.name));
|
|
79
|
+
const filteredMCP = mcpTools.filter((t) => !builtinNames.has(t.name));
|
|
80
|
+
let pool = [...builtinTools, ...filteredMCP];
|
|
81
|
+
// Apply deny rules
|
|
82
|
+
const denyNames = new Set(permissionContext.alwaysDenyRules
|
|
83
|
+
.filter((r) => r.behavior === 'deny')
|
|
84
|
+
.map((r) => r.toolName));
|
|
85
|
+
pool = pool.filter((t) => !denyNames.has(t.name));
|
|
86
|
+
pool = pool.filter((t) => t.isEnabled?.() ?? true);
|
|
87
|
+
return pool;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=Tool.js.map
|
package/dist/Tool.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Tool.js","sourceRoot":"","sources":["../src/Tool.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AA0PH,4EAA4E;AAE5E;;;GAGG;AACH,MAAM,UAAU,SAAS,CACvB,SAAiF;IAEjF,MAAM,QAAQ,GAAoC;QAChD,kBAAkB,EAAE,OAAO;QAC3B,SAAS,EAAE,GAAG,EAAE,CAAC,IAAI;QACrB,iBAAiB,EAAE,GAAG,EAAE,CAAC,IAAI;QAC7B,UAAU,EAAE,GAAG,EAAE,CAAC,KAAK;QACvB,aAAa,EAAE,GAAG,EAAE,CAAC,KAAK;QAC1B,OAAO,EAAE,EAAE;QACX,KAAK,CAAC,WAAW,CAAC,MAAsB;YACtC,OAAO,SAAS,CAAC,IAAI,CAAC;QACxB,CAAC;QACD,cAAc,CAAC,MAAsB;YACnC,OAAO,SAAS,CAAC,IAAI,CAAC;QACxB,CAAC;QACD,KAAK,CAAC,gBAAgB;YACpB,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;QAC/B,CAAC;QACD,4BAA4B,CAAC,MAAM,EAAE,SAAS;YAC5C,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;YACvE,OAAO;gBACL;oBACE,IAAI,EAAE,aAAsB;oBAC5B,WAAW,EAAE,S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AI,CAAC,CAAC,CAAC;IAC9D,MAAM,WAAW,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IAEtE,IAAI,IAAI,GAAG,CAAC,GAAG,YAAY,EAAE,GAAG,WAAW,CAAC,CAAC;IAE7C,mBAAmB;IACnB,MAAM,SAAS,GAAG,IAAI,GAAG,CACvB,iBAAiB,CAAC,eAAe;SAC9B,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,MAAM,CAAC;SACpC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAC1B,CAAC;IAEF,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IAClD,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,EAAE,IAAI,IAAI,CAAC,CAAC;IAEnD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cray Code ASCII logo for terminal display.
|
|
3
|
+
*/
|
|
4
|
+
export declare const CRAY_LOGO = "\n \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2557\n \u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u255A\u2588\u2588\u2557 \u2588\u2588\u2554\u255D\n \u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D \u255A\u2588\u2588\u2588\u2588\u2554\u255D\n \u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557 \u255A\u2588\u2588\u2554\u255D\n \u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551\n \u255A\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D\n";
|
|
5
|
+
export declare const CRAY_LOGO_SMALL = "\n \u2597\u2584\u2584\u2596\u2597\u2584\u2584\u2584\u2596\u2597\u2596 \u2597\u2596\n \u2597\u2596 \u2597\u2584\u2584\u2584\u2596 \u259D\u259A\u259E\u2598\n \u2597\u2596 \u2597\u2596\u2597\u2596\n \u259D\u259A\u2584\u2584\u2596 \u2597\u2596\u2597\u2596\u2597\u2596\n";
|
|
6
|
+
export declare const CRAY_TAGLINE = "Cray Code - Your AI Agent Framework";
|
|
7
|
+
export declare const WELCOME_MESSAGE = "\n\n \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2557\n \u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u255A\u2588\u2588\u2557 \u2588\u2588\u2554\u255D\n \u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D \u255A\u2588\u2588\u2588\u2588\u2554\u255D\n \u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557 \u255A\u2588\u2588\u2554\u255D\n \u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551\n \u255A\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D\n\n Cray Code - Your AI Agent Framework\n\n Powerful AI agent with MCP, Skills, and Sub-agent support.\n Type /help to see available commands.\n";
|
|
8
|
+
//# sourceMappingURL=logo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logo.d.ts","sourceRoot":"","sources":["../../src/branding/logo.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,eAAO,MAAM,SAAS,m9BAOrB,CAAC;AAEF,eAAO,MAAM,eAAe,2RAK3B,CAAC;AAEF,eAAO,MAAM,YAAY,wCAAwC,CAAC;AAElE,eAAO,MAAM,eAAe,umCAM3B,CAAC"}
|