Core Package
@cdoing/core — The foundation layer containing tools, permissions, sandbox, context providers, indexing, and all core infrastructure.
Overview
The core package is the dependency-free foundation of the entire system. It has no internal package dependencies and exports everything needed by the ai, cli, and vscode-extension packages.
packages/core/src/
├── index.ts # All exports
├── tools/ # 21 built-in tools
│ ├── registry.ts # Central tool registry
│ ├── file-read.ts # File reading (text, images, PDFs)
│ ├── file-write.ts # File creation/overwrite
│ ├── file-edit.ts # Find-and-replace editing
│ ├── multi-edit.ts # Atomic batch edits
│ ├── file-delete.ts # Permission-controlled deletion
│ ├── file-run.ts # Auto-detect & run 14 languages
│ ├── shell-exec.ts # Shell command execution
│ ├── glob-search.ts # File pattern matching
│ ├── grep-search.ts # Content search with regex
│ ├── list-dir.ts # Directory listing
│ ├── view-repo-map.ts # Repository tree view
│ ├── view-diff.ts # Git diff viewer
│ ├── web-fetch.ts # URL content fetching
│ ├── web-search.ts # DuckDuckGo search
│ ├── codebase-search.ts # FTS5 + vector search
│ └── system-info.ts # Runtime info query
├── permissions/ # Permission engine
│ └── index.ts # PermissionManager (738 lines)
├── sandbox/ # Filesystem & network sandbox
│ ├── manager.ts # Orchestrator
│ ├── filesystem.ts # Path checking
│ ├── network.ts # Domain allowlisting
│ └── types.ts # Configuration types
├── context-providers/ # 10 @ mention providers
│ ├── registry.ts # Provider registry
│ ├── git.ts # @git context
│ ├── diff.ts # @diff context
│ └── folder.ts # @folder context
├── indexing/ # Codebase indexing
│ ├── indexer.ts # Main orchestration
│ ├── database.ts # SQLite schema + queries
│ ├── chunker.ts # Code-aware chunking
│ └── types.ts # TypeScript interfaces
├── hooks/ # Pre/post tool hooks
│ └── index.ts
├── rules/ # Project rules
│ └── manager.ts
├── plan/ # Plan mode (read-only)
│ └── manager.ts
├── mcp/ # Model Context Protocol
│ └── manager.ts
├── effort/ # Effort level control
│ └── index.ts
├── agents/ # Multi-agent coordination
│ └── coordinator.ts
└── utils/ # Utilities
├── path-safety.ts # Resolve paths safely
├── path-matching.ts # Glob pattern matching
├── shell-paths.ts # Extract paths from commands
├── search-match.ts # Find + replace, unified diff
├── gitignore.ts # .gitignore loader
├── project-config.ts # Config file loader
├── memory.ts # Conversation memory store
└── todo.ts # Task tracking store
Tool Registry
All 21 tools are managed by the central ToolRegistry which provides:
- register(tool) — Register a new tool instance
- get(name) — Retrieve a tool by name
- getAll() — Get all registered tools
- execute(name, params) — Run a tool with parameters
- getDefinitions() — Get JSON Schema definitions for LLM binding
Each tool implements the BaseTool interface with a ToolDefinition (name, description, parameters as JSON Schema) and an execute() method.
Context Providers
Context providers allow users to inject additional information into the conversation using @mentions:
| Provider | Trigger | Description |
|---|
| Terminal | @terminal | Last terminal command output |
| Tree | @tree [path] [depth] | Workspace file tree |
| URL | @url <url> | Fetch and attach web page content |
| Codebase | @codebase <query> | Full-text + semantic search |
| Open Files | @open | All open editor files (VS Code only) |
| Problems | @problems | File diagnostics/errors (VS Code only) |
| Clipboard | @clipboard | Clipboard contents |
| File | @file <path> | Include a specific file |
| Git | @git | Git context (commits, branch info) |
| Diff | @diff | Current working changes |
Indexing System
The indexing system provides intelligent code search using SQLite FTS5 for full-text search and optional vector embeddings for semantic search.
How Indexing Works
1
File Scanning
Scans the workspace respecting .gitignore. Skips node_modules, .git, dist, build, and files over 1MB. Supports 40+ file extensions.
2
Incremental Updates (SHA-256)
Content hashing detects changes. New files are chunked and indexed, modified files are re-indexed, unchanged files are skipped.
3
Code-Aware Chunking
Code files are split at function/class boundaries. Markdown splits at headers. Basic files split at ~17 lines (~384 tokens per chunk).
4
Search Pipeline
FTS5 search (BM25 ranking with 10x path boost) provides 35% of results. Vector embedding search provides 65%. Results are deduplicated by path + line.
Database Schema
-- File chunks with line ranges
CREATE TABLE chunks (
id INTEGER PRIMARY KEY,
path TEXT NOT NULL,
content TEXT NOT NULL,
startLine INTEGER,
endLine INTEGER,
hash TEXT NOT NULL
);
-- FTS5 virtual table (trigram tokenizer, BM25)
CREATE VIRTUAL TABLE fts USING fts5(
path, content, tokenize='trigram'
);
-- Vector embeddings (JSON storage)
CREATE TABLE embeddings (
chunk_id INTEGER REFERENCES chunks(id),
vector TEXT NOT NULL -- JSON array
);
-- Incremental index tracking
CREATE TABLE index_catalog (
path TEXT PRIMARY KEY,
hash TEXT NOT NULL,
indexed_at TEXT
);
Utilities
| Utility | Purpose |
|---|
| path-safety.ts | Resolve paths safely, prevent directory traversal escape |
| path-matching.ts | Glob pattern matching for permission rules |
| shell-paths.ts | Extract file paths from shell commands for permission checking |
| search-match.ts | Find-and-replace engine with unified diff support |
| gitignore.ts | Parse and apply .gitignore patterns |
| project-config.ts | Load project configuration files |
| memory.ts | Persistent conversation memory storage |
| todo.ts | Task tracking with status management |
External Dependencies
Minimal Dependencies
The core package deliberately keeps its external dependency count low:
better-sqlite3 (database),
chalk (colors),
glob (file patterns),
minimatch (glob matching).