icopilot 2.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.
- package/CHANGELOG.md +250 -0
- package/LICENSE +21 -0
- package/README.md +214 -0
- package/bin/icopilot.js +6 -0
- package/dist/acp/router.js +123 -0
- package/dist/acp/schema.js +53 -0
- package/dist/agents/aggregator.js +187 -0
- package/dist/agents/custom-agents.js +97 -0
- package/dist/agents/goal-driven.js +411 -0
- package/dist/agents/multi-repo.js +350 -0
- package/dist/agents/parallel-runner.js +181 -0
- package/dist/agents/router.js +144 -0
- package/dist/agents/self-heal.js +481 -0
- package/dist/agents/tdd-agent.js +278 -0
- package/dist/api/github-models.js +158 -0
- package/dist/bridge/ide-bridge.js +479 -0
- package/dist/cloud/routine-executor.js +34 -0
- package/dist/cloud/routine-scheduler.js +67 -0
- package/dist/cloud/routine-storage.js +297 -0
- package/dist/commands/acp-cmd.js +143 -0
- package/dist/commands/actions-cmd.js +624 -0
- package/dist/commands/agent-cmd.js +144 -0
- package/dist/commands/alias-cmd.js +132 -0
- package/dist/commands/bookmark-cmd.js +77 -0
- package/dist/commands/changelog-cmd.js +99 -0
- package/dist/commands/changes-cmd.js +120 -0
- package/dist/commands/clipboard-cmd.js +217 -0
- package/dist/commands/cloud-routine-cmd.js +265 -0
- package/dist/commands/codegen-cmd.js +544 -0
- package/dist/commands/compare-cmd.js +116 -0
- package/dist/commands/context-cmd.js +247 -0
- package/dist/commands/context-viz-cmd.js +43 -0
- package/dist/commands/conventions-cmd.js +116 -0
- package/dist/commands/cost-cmd.js +51 -0
- package/dist/commands/deps-cmd.js +294 -0
- package/dist/commands/diagram-cmd.js +658 -0
- package/dist/commands/diff-review-cmd.js +92 -0
- package/dist/commands/doc-cmd.js +412 -0
- package/dist/commands/doctor-cmd.js +152 -0
- package/dist/commands/editor-cmd.js +49 -0
- package/dist/commands/env-cmd.js +86 -0
- package/dist/commands/explain-cmd.js +78 -0
- package/dist/commands/explain-shell-cmd.js +22 -0
- package/dist/commands/explore-cmd.js +231 -0
- package/dist/commands/feedback-cmd.js +98 -0
- package/dist/commands/fix-cmd.js +17 -0
- package/dist/commands/generate-cmd.js +38 -0
- package/dist/commands/git-extra.js +197 -0
- package/dist/commands/git-log-cmd.js +98 -0
- package/dist/commands/git-undo-cmd.js +137 -0
- package/dist/commands/git.js +155 -0
- package/dist/commands/history-cmd.js +122 -0
- package/dist/commands/index-cmd.js +65 -0
- package/dist/commands/init-cmd.js +73 -0
- package/dist/commands/lint-cmd.js +133 -0
- package/dist/commands/memory-cmd.js +98 -0
- package/dist/commands/metrics-cmd.js +97 -0
- package/dist/commands/mode-prefix.js +30 -0
- package/dist/commands/multi-cmd.js +44 -0
- package/dist/commands/notify-cmd.js +204 -0
- package/dist/commands/profile-cmd.js +101 -0
- package/dist/commands/prompts.js +17 -0
- package/dist/commands/rag-cmd.js +60 -0
- package/dist/commands/readme-cmd.js +564 -0
- package/dist/commands/reasoning-cmd.js +34 -0
- package/dist/commands/refactor-cmd.js +96 -0
- package/dist/commands/release-cmd.js +450 -0
- package/dist/commands/repo-cmd.js +195 -0
- package/dist/commands/route-cmd.js +21 -0
- package/dist/commands/schedule-cmd.js +109 -0
- package/dist/commands/search-cmd.js +47 -0
- package/dist/commands/security-cmd.js +156 -0
- package/dist/commands/settings-cmd.js +238 -0
- package/dist/commands/skill-cmd.js +338 -0
- package/dist/commands/slash.js +2721 -0
- package/dist/commands/snippets-cmd.js +83 -0
- package/dist/commands/space-cmd.js +92 -0
- package/dist/commands/stash-cmd.js +156 -0
- package/dist/commands/stats-cmd.js +36 -0
- package/dist/commands/style-cmd.js +85 -0
- package/dist/commands/suggest-cmd.js +40 -0
- package/dist/commands/summary-cmd.js +138 -0
- package/dist/commands/task-cmd.js +58 -0
- package/dist/commands/team-memory-cmd.js +97 -0
- package/dist/commands/template-cmd.js +475 -0
- package/dist/commands/test-cmd.js +146 -0
- package/dist/commands/todo-cmd.js +172 -0
- package/dist/commands/tokens-cmd.js +277 -0
- package/dist/commands/trigger-cmd.js +147 -0
- package/dist/commands/undo-cmd.js +18 -0
- package/dist/commands/voice-cmd.js +89 -0
- package/dist/commands/watch-cmd.js +110 -0
- package/dist/commands/web-cmd.js +183 -0
- package/dist/commands/worktree-cmd.js +119 -0
- package/dist/config-profile.js +66 -0
- package/dist/config.js +288 -0
- package/dist/context/compactor.js +53 -0
- package/dist/context/dep-context.js +329 -0
- package/dist/context/file-refs.js +54 -0
- package/dist/context/git-context.js +229 -0
- package/dist/context/image-input.js +66 -0
- package/dist/context/memory.js +55 -0
- package/dist/context/persistent-memory.js +104 -0
- package/dist/context/pinned.js +96 -0
- package/dist/context/priority.js +150 -0
- package/dist/context/read-only.js +48 -0
- package/dist/context/smart-files.js +286 -0
- package/dist/context/team-memory.js +156 -0
- package/dist/extensions/loader.js +149 -0
- package/dist/extensions/marketplace.js +49 -0
- package/dist/extensions/slack-provider.js +181 -0
- package/dist/extensions/team.js +56 -0
- package/dist/extensions/teams-provider.js +222 -0
- package/dist/extensions/voice.js +18 -0
- package/dist/hooks/lifecycle.js +215 -0
- package/dist/hooks/precommit.js +463 -0
- package/dist/index/embeddings.js +23 -0
- package/dist/index/indexer.js +86 -0
- package/dist/index/retrieve.js +20 -0
- package/dist/index/store.js +95 -0
- package/dist/index.js +286 -0
- package/dist/intelligence/dead-code.js +457 -0
- package/dist/intelligence/error-watch.js +263 -0
- package/dist/intelligence/navigation.js +141 -0
- package/dist/intelligence/stack-trace.js +210 -0
- package/dist/intelligence/symbol-index.js +410 -0
- package/dist/knowledge/auto-memory.js +412 -0
- package/dist/knowledge/conventions.js +475 -0
- package/dist/knowledge/corrections.js +213 -0
- package/dist/knowledge/rag.js +450 -0
- package/dist/knowledge/style-learner.js +324 -0
- package/dist/logger.js +35 -0
- package/dist/mcp/client.js +144 -0
- package/dist/mcp/config.js +24 -0
- package/dist/mcp/index.js +89 -0
- package/dist/modes/auto-compact.js +20 -0
- package/dist/modes/autopilot.js +157 -0
- package/dist/modes/background.js +82 -0
- package/dist/modes/interactive.js +187 -0
- package/dist/modes/oneshot.js +36 -0
- package/dist/modes/tui.js +265 -0
- package/dist/modes/turn.js +342 -0
- package/dist/notifications/manager.js +107 -0
- package/dist/plugins/marketplace.js +244 -0
- package/dist/providers/custom-provider.js +298 -0
- package/dist/providers/local-model.js +121 -0
- package/dist/routing/profiles.js +44 -0
- package/dist/routing/router.js +18 -0
- package/dist/sandbox/container.js +151 -0
- package/dist/security/audit.js +237 -0
- package/dist/security/content-filter.js +449 -0
- package/dist/security/proxy.js +301 -0
- package/dist/security/retention.js +281 -0
- package/dist/security/roles.js +252 -0
- package/dist/server/api-server.js +679 -0
- package/dist/session/bookmarks.js +72 -0
- package/dist/session/cloud-session.js +291 -0
- package/dist/session/handoff.js +405 -0
- package/dist/session/manager.js +35 -0
- package/dist/session/session.js +296 -0
- package/dist/session/share.js +313 -0
- package/dist/session/undo-journal.js +91 -0
- package/dist/snippets/store.js +60 -0
- package/dist/spaces/space-config.js +156 -0
- package/dist/spaces/space.js +220 -0
- package/dist/stats/store.js +101 -0
- package/dist/tools/apply-patch.js +134 -0
- package/dist/tools/auto-check.js +218 -0
- package/dist/tools/diff-edit.js +150 -0
- package/dist/tools/diff-prompt.js +36 -0
- package/dist/tools/edit-file.js +66 -0
- package/dist/tools/file-ops.js +205 -0
- package/dist/tools/glob.js +17 -0
- package/dist/tools/grep.js +56 -0
- package/dist/tools/image.js +194 -0
- package/dist/tools/list-directory.js +228 -0
- package/dist/tools/memory.js +17 -0
- package/dist/tools/multi-edit.js +299 -0
- package/dist/tools/policy.js +95 -0
- package/dist/tools/registry.js +484 -0
- package/dist/tools/retry.js +74 -0
- package/dist/tools/run-in-terminal.js +162 -0
- package/dist/tools/safety.js +64 -0
- package/dist/tools/sandbox.js +15 -0
- package/dist/tools/search-symbols.js +212 -0
- package/dist/tools/shell.js +118 -0
- package/dist/tools/web.js +167 -0
- package/dist/ui/prompt.js +37 -0
- package/dist/ui/render.js +96 -0
- package/dist/ui/screen.js +13 -0
- package/dist/ui/theme.js +56 -0
- package/dist/util/browser.js +34 -0
- package/dist/util/completion.js +350 -0
- package/dist/util/cost.js +28 -0
- package/dist/util/keybindings.js +113 -0
- package/dist/util/lazy.js +26 -0
- package/dist/util/perf.js +25 -0
- package/dist/util/token-worker.js +11 -0
- package/dist/util/tokens.js +50 -0
- package/dist/workflows/builtins.js +128 -0
- package/dist/workflows/engine.js +496 -0
- package/dist/workflows/file-trigger.js +197 -0
- package/package.json +79 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [2.1.0] — 2026-06-28
|
|
9
|
+
|
|
10
|
+
### Added — v2.1 Competitive Parity
|
|
11
|
+
- **Image input** — vision model detection, base64 encoding, screenshot context (`src/context/image-input.ts`)
|
|
12
|
+
- **Git undo** — AI commit tracking with `git reset --soft` and safety guards (`src/commands/git-undo-cmd.ts`)
|
|
13
|
+
- **Web scraping** — `/web <url> [focus]` with HTML→markdown conversion (`src/commands/web-cmd.ts`)
|
|
14
|
+
- **Lifecycle hooks** — 10 event types with preToolUse deny/modify via JSON stdin/stdout (`src/hooks/lifecycle.ts`)
|
|
15
|
+
- **Diff-based editing** — SEARCH/REPLACE blocks with fuzzy matching and `/edit-format` (`src/tools/diff-edit.ts`)
|
|
16
|
+
- **External editor** — `$VISUAL`/`$EDITOR` detection with `.md` temp files (`src/commands/editor-cmd.ts`)
|
|
17
|
+
- **Reasoning control** — `/reasoning` and `/think-tokens` with API wiring (`src/commands/reasoning-cmd.ts`)
|
|
18
|
+
- **Auto-lint & auto-test** — run linter/tests after AI edits with auto-fix loop (`src/tools/auto-check.ts`)
|
|
19
|
+
- **Per-message mode switching** — `/ask`, `/code`, `/architect` per-turn prefixes (`src/commands/mode-prefix.ts`)
|
|
20
|
+
- **Mid-session diff** — `/changes` with per-turn git snapshots (`src/commands/changes-cmd.ts`)
|
|
21
|
+
- **Runtime settings** — `/settings KEY VALUE` with `~/.icopilotrc.json` persistence (`src/commands/settings-cmd.ts`)
|
|
22
|
+
- **User feedback** — `/feedback` with offline storage and optional GitHub issue (`src/commands/feedback-cmd.ts`)
|
|
23
|
+
- **Context visualization** — visual `/context` usage view + `/usage` alias (`src/commands/context-viz-cmd.ts`)
|
|
24
|
+
- **Auto-memory** — AI self-learning with 28-day retention and `/memory auto` (`src/knowledge/auto-memory.ts`)
|
|
25
|
+
- **Scheduled prompts** — `/every` and `/after` for recurring/delayed tasks (`src/commands/schedule-cmd.ts`)
|
|
26
|
+
- **Read-only files** — `/read-only` with file protection (`src/commands/schedule-cmd.ts`)
|
|
27
|
+
- **Clipboard operations** — `/paste`, `/copy-context`, `/run` with output injection (`src/commands/clipboard-cmd.ts`)
|
|
28
|
+
|
|
29
|
+
### Fixed
|
|
30
|
+
- Wiring issues: `/dead-code` handler, `--perf-trace` flag, completion deduplication, aggregator integration
|
|
31
|
+
- Slash test assertion for `/copy-context` return shape
|
|
32
|
+
|
|
33
|
+
## [2.0.0] — 2026-06-27
|
|
34
|
+
|
|
35
|
+
### Added — v1.4 Multi-Agent Orchestration
|
|
36
|
+
- Parallel agent runner with concurrent sub-agent execution
|
|
37
|
+
- Agent result aggregation with merged multi-agent output
|
|
38
|
+
- Custom agent definitions via `.icopilot/agents/*.yaml`
|
|
39
|
+
- Agent routing with automatic delegation by query type
|
|
40
|
+
- `run_in_terminal` tool for interactive PTY command execution
|
|
41
|
+
- `list_directory` tool for structured directory listing
|
|
42
|
+
- `search_symbols` tool for AST-aware symbol search
|
|
43
|
+
- Tool retry logic with automatic retry on transient failures
|
|
44
|
+
|
|
45
|
+
### Added — v1.5 Copilot Spaces & Teams
|
|
46
|
+
- Project spaces with isolated context sandboxes per project/branch
|
|
47
|
+
- Session handoff for exporting state to another developer
|
|
48
|
+
- Shared team memory via `.icopilot/team-memory.md`
|
|
49
|
+
- Smart file selection with model-driven relevant file picking
|
|
50
|
+
- Git-aware context auto-including recently modified files
|
|
51
|
+
- Dependency-aware context following imports to include related files
|
|
52
|
+
- Context priority scoring with relevance-ranked sources
|
|
53
|
+
|
|
54
|
+
### Added — v1.6 IDE-Grade Intelligence
|
|
55
|
+
- Symbol index for project-wide function/class/type table
|
|
56
|
+
- Cross-file navigation (go-to-definition, find-references)
|
|
57
|
+
- Multi-file atomic edits reviewed holistically
|
|
58
|
+
- Code generation with automatic test file creation
|
|
59
|
+
- Live error watching with auto-suggested fixes
|
|
60
|
+
- Stack trace analysis for AI-powered root cause diagnosis
|
|
61
|
+
- Dead code detection identifying unused exports/functions
|
|
62
|
+
|
|
63
|
+
### Added — v1.7 Workflow Automation
|
|
64
|
+
- Workflow engine with `.icopilot/workflows/*.yaml` definitions
|
|
65
|
+
- Built-in workflows (review-and-commit, test-fix-loop, release-prep)
|
|
66
|
+
- GitHub Actions helper generating workflow YAML from natural language
|
|
67
|
+
- Pre-commit hook with `/review` + `/security` before commit
|
|
68
|
+
- File watch triggers running workflows on change
|
|
69
|
+
- Release automation (version bump → changelog → tag → publish)
|
|
70
|
+
|
|
71
|
+
### Added — v1.8 Knowledge & Learning
|
|
72
|
+
- Project RAG with chunked document indexing and retrieval
|
|
73
|
+
- `/doc` command for generating JSDoc/docstring
|
|
74
|
+
- README generation from project analysis
|
|
75
|
+
- Architecture diagram generation (mermaid from code)
|
|
76
|
+
- Style learning adapting to user's coding patterns
|
|
77
|
+
- Correction memory remembering user corrections
|
|
78
|
+
- Project conventions learning and enforcement
|
|
79
|
+
|
|
80
|
+
### Added — v1.9 Enterprise & Security
|
|
81
|
+
- Role-based tool access restricting by user role
|
|
82
|
+
- Audit logging with full trail of tool executions
|
|
83
|
+
- Proxy support (HTTP/HTTPS/SOCKS5)
|
|
84
|
+
- Air-gapped mode with local models (Ollama, vLLM)
|
|
85
|
+
- Content filtering preventing PII in prompts
|
|
86
|
+
- Retention policies with auto-delete after N days
|
|
87
|
+
|
|
88
|
+
### Added — v2.0 The Complete Agentic OS
|
|
89
|
+
- Goal-driven development (describe feature → implement end-to-end)
|
|
90
|
+
- Self-healing builds (detect failure → diagnose → fix → retry)
|
|
91
|
+
- TDD agent (write tests first, implement until green)
|
|
92
|
+
- Multi-repo orchestration coordinating across repositories
|
|
93
|
+
- Plugin marketplace (`icopilot install <plugin>`)
|
|
94
|
+
- Custom model providers (any OpenAI-compatible endpoint)
|
|
95
|
+
- IDE bridge for bidirectional VS Code / Neovim communication
|
|
96
|
+
- API server mode exposing as HTTP API (`--serve`)
|
|
97
|
+
- Container sandbox for Docker-based isolated execution
|
|
98
|
+
- Cloud sessions for remote access from any terminal
|
|
99
|
+
|
|
100
|
+
## [1.3.0] — 2026-06-27
|
|
101
|
+
|
|
102
|
+
### Added — Agent Runtime & Extensibility
|
|
103
|
+
- Agent system prompt framework with persona + tool binding
|
|
104
|
+
- Background agent tasks with `&` suffix syntax
|
|
105
|
+
- Agent memory (persistent knowledge across sessions)
|
|
106
|
+
- Custom slash-command plugins via `.icopilot/plugins/`
|
|
107
|
+
- Streaming tool output with real-time display
|
|
108
|
+
- Tool composition (pipe output of one tool into another)
|
|
109
|
+
- Multi-model routing (different models per task type)
|
|
110
|
+
- Context-aware model switching
|
|
111
|
+
- Agent self-reflection and correction loop
|
|
112
|
+
- Conversation branching (fork conversation, explore alternatives)
|
|
113
|
+
- Undo/redo for file edits
|
|
114
|
+
- Checkpoint/restore for session state
|
|
115
|
+
- Interactive conflict resolution for file edits
|
|
116
|
+
- Rate-limit-aware request scheduling
|
|
117
|
+
- Token-budget auto-split for long conversations
|
|
118
|
+
- Project-wide semantic search
|
|
119
|
+
|
|
120
|
+
## [Unreleased]
|
|
121
|
+
|
|
122
|
+
## [2.2.0] - 2026-06-29
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
### Added — v0.2 Quality & DX
|
|
126
|
+
|
|
127
|
+
- **Tests** — Vitest suite covering `context/file-refs`, `session`, `tools/file-ops`,
|
|
128
|
+
`commands/slash`, and API retry smoke behavior (18 tests).
|
|
129
|
+
- **Lint + Format** — ESLint (typescript-eslint) with Prettier integration; new
|
|
130
|
+
`npm run lint`, `lint:fix`, `format`, `format:check`, `typecheck`, `coverage`
|
|
131
|
+
scripts.
|
|
132
|
+
- **CI** — GitHub Actions matrix for Node 18 / 20 / 22 on Ubuntu + Windows.
|
|
133
|
+
- **Structured logging** — `src/logger.ts` with `--verbose` / `ICOPILOT_DEBUG=1` and
|
|
134
|
+
automatic redaction of `ghp_*`, `gho_*`, `Bearer …`, and `"token":"…"` patterns.
|
|
135
|
+
- **Friendly errors** — classified messages for missing `GITHUB_TOKEN`, network
|
|
136
|
+
failures, 401/403 auth, and unknown models.
|
|
137
|
+
- **Config file** — `~/.icopilotrc.json` merged with env vars and CLI flags (see
|
|
138
|
+
`docs/config.md`).
|
|
139
|
+
- **Theming** — auto-detect `NO_COLOR`, `CI`, non-TTY; `--theme light|dark|none`
|
|
140
|
+
and `ICOPILOT_THEME=`.
|
|
141
|
+
- **Windows polish** — prompt prefix falls back to ASCII outside Windows Terminal;
|
|
142
|
+
CI coverage for Windows.
|
|
143
|
+
|
|
144
|
+
### Added — v0.3 Tooling & Agentic Power
|
|
145
|
+
|
|
146
|
+
- **`apply_patch` tool** — model emits a unified diff; user picks hunks via an
|
|
147
|
+
interactive checkbox before any file is touched.
|
|
148
|
+
- **Multi-file write transactions** — `proposeWriteBatch` shows a combined diff
|
|
149
|
+
preview and rolls back on partial failure.
|
|
150
|
+
- **`grep` and `glob` read-only tools** — model can search the repo without
|
|
151
|
+
shelling out.
|
|
152
|
+
- **`--sandbox`** opt-in mode restricts shell + write tools to the working
|
|
153
|
+
directory.
|
|
154
|
+
- **Policy file** — `.icopilot/policy.json` / `~/.icopilot/policy.json` with
|
|
155
|
+
`allowShell`, `denyShell`, `allowWrite`, `denyWrite` patterns.
|
|
156
|
+
- **Always-allow memory** — per-session "remember this command/path" to avoid
|
|
157
|
+
re-prompting for trusted operations.
|
|
158
|
+
|
|
159
|
+
### Added — v0.4 Extensibility (MCP)
|
|
160
|
+
|
|
161
|
+
- **MCP client** — minimal stdio JSON-RPC client (`src/mcp/client.ts`) with
|
|
162
|
+
LSP-style framing fallback and per-request timeout.
|
|
163
|
+
- **MCP loader** — `~/.icopilot/mcp.json` + project-local `.mcp.json` discovered
|
|
164
|
+
and merged; project values win on conflict.
|
|
165
|
+
- **Tool namespacing** — exposed MCP tools are surfaced as
|
|
166
|
+
`mcp__<server>__<tool>` to avoid collisions with built-ins.
|
|
167
|
+
- See `docs/mcp.md`.
|
|
168
|
+
|
|
169
|
+
### Added — v0.5 Sessions & Memory
|
|
170
|
+
|
|
171
|
+
- **`/sessions`** — interactive picker to list and resume any saved session.
|
|
172
|
+
- **`/export [md|json] [path]`** — write the current conversation as Markdown or
|
|
173
|
+
JSON.
|
|
174
|
+
- **Per-project memory** — `.icopilot/memory.md` and `~/.icopilot/memory.md`
|
|
175
|
+
auto-injected into the system prompt.
|
|
176
|
+
- **Rolling auto-summarize** — `Session.shouldAutoSummarize()` helper for hitting
|
|
177
|
+
the soft budget threshold.
|
|
178
|
+
- See `docs/sessions.md`.
|
|
179
|
+
|
|
180
|
+
### Added — v0.6 Git & Collaboration
|
|
181
|
+
|
|
182
|
+
- **`/review`** — review staged changes; model surfaces bugs, security, perf.
|
|
183
|
+
- **`/issue [title]`** — draft a GitHub issue from the current context; copies to
|
|
184
|
+
clipboard when available and offers `gh issue create`.
|
|
185
|
+
- **`/branch <topic>`** — generate a conventional branch name and `git checkout
|
|
186
|
+
-b` after confirmation.
|
|
187
|
+
|
|
188
|
+
### Changed
|
|
189
|
+
|
|
190
|
+
- Tool registry now lazily loads MCP servers on first use and merges their tool
|
|
191
|
+
schemas with the built-ins.
|
|
192
|
+
- File-write and shell tools enforce policy + sandbox before prompting the user.
|
|
193
|
+
|
|
194
|
+
### Notes — deferred / exploratory
|
|
195
|
+
|
|
196
|
+
The remaining `roadmap.md` items have shipped as **extension points** rather
|
|
197
|
+
than full implementations — see `docs/future.md`:
|
|
198
|
+
|
|
199
|
+
- Voice input — `SpeechProvider` interface (`src/extensions/voice.ts`)
|
|
200
|
+
- Team mode — `TeamTransport` interface (`src/extensions/team.ts`)
|
|
201
|
+
- Plugin marketplace — `PluginCatalog` interface and `LocalPluginCatalog`
|
|
202
|
+
default (`src/extensions/marketplace.ts`)
|
|
203
|
+
|
|
204
|
+
Third-party packages can register real implementations without forking
|
|
205
|
+
iCopilot.
|
|
206
|
+
|
|
207
|
+
### Added — v0.7 Performance
|
|
208
|
+
|
|
209
|
+
- Lazy `marked` / `marked-terminal` / `gpt-tokenizer` imports — they no longer
|
|
210
|
+
load until the first markdown render or token count.
|
|
211
|
+
- `StreamSink` highlights fenced code blocks incrementally during streaming.
|
|
212
|
+
- Worker-thread token counting for inputs ≥ 200 KB.
|
|
213
|
+
- `npm run perf:cold-start` benchmark script; documented baselines in
|
|
214
|
+
`docs/performance.md`. The original `< 150 ms` cold-start goal was revised
|
|
215
|
+
to a measurable `< 800 ms` on Linux Node 20.
|
|
216
|
+
|
|
217
|
+
### Added — v1.0 Release engineering
|
|
218
|
+
|
|
219
|
+
- `docs/api.md` freezes the public surface with stability tiers.
|
|
220
|
+
- `docs/index.md`, `docs/recipes.md` (14 recipes), `docs/release.md`.
|
|
221
|
+
- `scripts/release.mjs` + `scripts/changelog.mjs` automate version bump,
|
|
222
|
+
changelog rotation, commit, and tag.
|
|
223
|
+
- `.github/workflows/release.yml` publishes to npm with `--provenance` on tag
|
|
224
|
+
push and creates a GitHub Release from the changelog.
|
|
225
|
+
- `tests/smoke/cli.smoke.test.ts` + `scripts/smoke.mjs` validate `--help`,
|
|
226
|
+
`--version`, and missing-token error paths.
|
|
227
|
+
- LICENSE (MIT), `.npmignore`, and `package.json#files` allowlist.
|
|
228
|
+
- Real SVG screenshots in README (`scripts/screenshots.mjs`).
|
|
229
|
+
|
|
230
|
+
### Added — Beyond 1.0
|
|
231
|
+
|
|
232
|
+
- Opt-in `--tui` mode (`src/modes/tui.ts`, no extra deps).
|
|
233
|
+
- `/route get|set|list` multi-model routing with `cheap` / `balanced` /
|
|
234
|
+
`strong` / `fixed` profiles.
|
|
235
|
+
- `/index build|status|search` workspace embeddings index using GitHub Models
|
|
236
|
+
embeddings.
|
|
237
|
+
|
|
238
|
+
### Notes — deferred / exploratory
|
|
239
|
+
|
|
240
|
+
The following items from `roadmap.md` are intentionally shipped as
|
|
241
|
+
**extension points** rather than full reference implementations. Plug a real
|
|
242
|
+
implementation in by registering against the interface — see
|
|
243
|
+
`docs/future.md`:
|
|
244
|
+
|
|
245
|
+
- Voice input — `SpeechProvider` (`src/extensions/voice.ts`)
|
|
246
|
+
- Team mode over WebRTC — `TeamTransport` (`src/extensions/team.ts`)
|
|
247
|
+
- Plugin marketplace — `PluginCatalog` (`src/extensions/marketplace.ts`)
|
|
248
|
+
|
|
249
|
+
Cold-start: original `< 150 ms` goal revised to `< 800 ms` on Linux Node 20
|
|
250
|
+
based on measured baselines (Windows median ≈ 2.1 s, Linux median ≈ 350 ms).
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 iCopilot contributors
|
|
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 notice 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.
|
package/README.md
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
# iCopilot
|
|
2
|
+
|
|
3
|
+
A terminal-native, agentic CLI assistant — fully replicating and enhancing
|
|
4
|
+
the modern GitHub Copilot CLI experience, powered exclusively by the
|
|
5
|
+
**GitHub Models API**.
|
|
6
|
+
|
|
7
|
+
**Version 2.0** — The Complete Agentic OS.
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
<img src="./docs/screenshots/repl.svg" alt="iCopilot REPL with streaming response, shell proposal, and file write" width="820">
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
### Core Experience
|
|
16
|
+
- 🗣️ **Interactive REPL** with live, streaming markdown responses
|
|
17
|
+
- 🧭 **Plan Mode** — produces step lists for review before any change
|
|
18
|
+
- ⚡ **One-shot mode** — `icopilot -p "..."` for scripting / piping
|
|
19
|
+
- 📎 **`@file` references** auto-inject file contents into context
|
|
20
|
+
- 🛠️ **Agentic tools** — shell + file edits gated by `[Y/n]` confirmation
|
|
21
|
+
- 🧠 **Token budget** tracker with auto-suggest `/compact`
|
|
22
|
+
- 💾 **Session persistence** — resume via `/sessions`
|
|
23
|
+
- 🪶 **Graceful SIGINT** — Ctrl-C aborts a stream, never the app
|
|
24
|
+
- 🔁 **HTTP 429 backoff** with cooldown banners
|
|
25
|
+
|
|
26
|
+
### Multi-Agent Orchestration (v1.4)
|
|
27
|
+
- 🤖 **Parallel agent runner** — concurrent sub-agent execution with `&` syntax
|
|
28
|
+
- 🧩 **Custom agent definitions** — `.icopilot/agents/*.yaml`
|
|
29
|
+
- 🎯 **Agent routing** — automatic delegation by query type
|
|
30
|
+
- 🔄 **Tool retry logic** — automatic retry on transient failures
|
|
31
|
+
|
|
32
|
+
### Copilot Spaces & Teams (v1.5)
|
|
33
|
+
- 📦 **Project spaces** — isolated context sandboxes per project/branch
|
|
34
|
+
- 🤝 **Session handoff** — export state for another developer
|
|
35
|
+
- 🧠 **Team memory** — shared `.icopilot/team-memory.md`
|
|
36
|
+
- 📂 **Smart file selection** — model-driven relevant file picking
|
|
37
|
+
- 🌿 **Git-aware context** — auto-include recently modified files
|
|
38
|
+
|
|
39
|
+
### IDE-Grade Intelligence (v1.6)
|
|
40
|
+
- 🔍 **Symbol index** — project-wide function/class/type table
|
|
41
|
+
- 🧭 **Cross-file navigation** — go-to-definition, find-references
|
|
42
|
+
- ✏️ **Multi-file atomic edits** — N-file changes reviewed holistically
|
|
43
|
+
- 🧪 **Code generation with tests** — auto-generate test file for new modules
|
|
44
|
+
- 👁️ **Live error watching** — monitor build output, auto-suggest fixes
|
|
45
|
+
- 🕵️ **Stack trace analysis** — AI-powered root cause diagnosis
|
|
46
|
+
|
|
47
|
+
### Workflow Automation (v1.7)
|
|
48
|
+
- ⚙️ **Workflow engine** — `.icopilot/workflows/*.yaml` with conditionals and loops
|
|
49
|
+
- 🚀 **GitHub Actions helper** — generate CI YAML from natural language
|
|
50
|
+
- 🪝 **Pre-commit hook** — `/review` + `/security` before commit
|
|
51
|
+
- 📁 **File watch triggers** — run workflow on file change
|
|
52
|
+
- 📦 **Release automation** — version bump → changelog → tag → publish
|
|
53
|
+
|
|
54
|
+
### Knowledge & Learning (v1.8)
|
|
55
|
+
- 📚 **Project RAG** — chunk and index all docs for retrieval
|
|
56
|
+
- 📝 **Doc generation** — JSDoc/docstring from code
|
|
57
|
+
- 📖 **README generation** — scaffold from project analysis
|
|
58
|
+
- 🏗️ **Architecture diagrams** — mermaid from code relationships
|
|
59
|
+
- 🎨 **Style learning** — adapt to user's coding patterns
|
|
60
|
+
- 💡 **Correction memory** — remember and apply user corrections
|
|
61
|
+
- 📏 **Project conventions** — learn and enforce patterns
|
|
62
|
+
|
|
63
|
+
### Enterprise & Security (v1.9)
|
|
64
|
+
- 🔐 **Role-based access** — restrict tools by user role
|
|
65
|
+
- 📋 **Audit logging** — full trail of all tool executions
|
|
66
|
+
- 🌐 **Proxy support** — HTTP/HTTPS/SOCKS5
|
|
67
|
+
- 🏠 **Air-gapped mode** — local models (Ollama, vLLM)
|
|
68
|
+
- 🛡️ **Content filtering** — prevent PII in prompts
|
|
69
|
+
- 🗑️ **Retention policies** — auto-delete after N days
|
|
70
|
+
|
|
71
|
+
### The Complete Agentic OS (v2.0)
|
|
72
|
+
- 🎯 **Goal-driven development** — describe feature → implement end-to-end
|
|
73
|
+
- 🔧 **Self-healing builds** — detect failure → diagnose → fix → retry
|
|
74
|
+
- 🧪 **TDD agent** — write tests first, implement until green
|
|
75
|
+
- 🌐 **Multi-repo orchestration** — coordinate across repositories
|
|
76
|
+
- 🏪 **Plugin marketplace** — `icopilot install <plugin>`
|
|
77
|
+
- 🔌 **Custom model providers** — any OpenAI-compatible endpoint
|
|
78
|
+
- 🖥️ **IDE bridge** — bidirectional VS Code / Neovim communication
|
|
79
|
+
- 🌍 **API server mode** — expose as HTTP API (`--serve`)
|
|
80
|
+
- 🐳 **Container sandbox** — Docker-based isolated execution
|
|
81
|
+
- ☁️ **Cloud sessions** — run in cloud, access from any terminal
|
|
82
|
+
|
|
83
|
+
### Slash Commands
|
|
84
|
+
|
|
85
|
+
```
|
|
86
|
+
/help /clear /model /cwd /diff /context /compact /sessions /export
|
|
87
|
+
/commit /pr /review /issue /branch /plan /lint /test /security
|
|
88
|
+
/agent /space /workflow /actions /release /doc /readme /diagram
|
|
89
|
+
/rag /conventions /corrections /audit /proxy /provider /goal /heal
|
|
90
|
+
/tdd /repo /serve /exit
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Install
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
npm install
|
|
97
|
+
npm run build
|
|
98
|
+
npm link # exposes `icopilot` / `icli` globally
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Auth
|
|
102
|
+
|
|
103
|
+
Set a GitHub PAT with `models:read`:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
# bash / zsh
|
|
107
|
+
export GITHUB_TOKEN=ghp_xxx...
|
|
108
|
+
|
|
109
|
+
# PowerShell
|
|
110
|
+
$env:GITHUB_TOKEN = "ghp_xxx..."
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Optional:
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
ICOPILOT_MODEL=gpt-4o # default model
|
|
117
|
+
ICOPILOT_ENDPOINT=https://models.inference.ai.azure.com
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Usage
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
icopilot # interactive REPL
|
|
124
|
+
icopilot -p "Explain @src/index.ts" # one-shot
|
|
125
|
+
icopilot --model gpt-4o # pin model
|
|
126
|
+
icopilot --plan # start in plan mode
|
|
127
|
+
icopilot --sandbox # restrict tools to cwd
|
|
128
|
+
icopilot --local # use local model (Ollama)
|
|
129
|
+
icopilot --provider my-provider # custom model provider
|
|
130
|
+
icopilot --serve 3000 # start as HTTP API server
|
|
131
|
+
icopilot --verbose --log-level debug # structured logs to stderr
|
|
132
|
+
icopilot --theme light # light / dark / none
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
<p align="center">
|
|
136
|
+
<img src="./docs/screenshots/help.svg" alt="icopilot --help" width="820">
|
|
137
|
+
</p>
|
|
138
|
+
|
|
139
|
+
See [`docs/config.md`](./docs/config.md) for the full config-file format,
|
|
140
|
+
[`docs/sessions.md`](./docs/sessions.md) for session/memory usage, and
|
|
141
|
+
[`docs/mcp.md`](./docs/mcp.md) for MCP server integration.
|
|
142
|
+
|
|
143
|
+
Inside the REPL:
|
|
144
|
+
|
|
145
|
+
```
|
|
146
|
+
> /help
|
|
147
|
+
> /model gpt-4o-mini
|
|
148
|
+
> Refactor @src/api/github-models.ts to add caching
|
|
149
|
+
> /goal "Add user authentication"
|
|
150
|
+
> /heal
|
|
151
|
+
> /tdd "Create a rate limiter"
|
|
152
|
+
> /review
|
|
153
|
+
> /commit
|
|
154
|
+
> /pr
|
|
155
|
+
> /sessions
|
|
156
|
+
> /export md
|
|
157
|
+
> /exit
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### When something goes wrong
|
|
161
|
+
|
|
162
|
+
Errors are classified and re-rendered with actionable hints. For example,
|
|
163
|
+
running without a token:
|
|
164
|
+
|
|
165
|
+
<p align="center">
|
|
166
|
+
<img src="./docs/screenshots/missing-token.svg" alt="Friendly missing-token error" width="820">
|
|
167
|
+
</p>
|
|
168
|
+
|
|
169
|
+
### Version
|
|
170
|
+
|
|
171
|
+
<p align="center">
|
|
172
|
+
<img src="./docs/screenshots/version.svg" alt="icopilot --version" width="520">
|
|
173
|
+
</p>
|
|
174
|
+
|
|
175
|
+
> **About the screenshots.** They are deterministic SVG renderings of the
|
|
176
|
+
> actual binary's output (ANSI colors preserved). Regenerate them after any
|
|
177
|
+
> UX change with `npm run screenshots`.
|
|
178
|
+
|
|
179
|
+
## Architecture
|
|
180
|
+
|
|
181
|
+
```
|
|
182
|
+
src/
|
|
183
|
+
├── index.ts # entry / CLI flag parsing
|
|
184
|
+
├── config.ts # env + rc-file + runtime config
|
|
185
|
+
├── logger.ts # structured logging + secret redaction
|
|
186
|
+
├── api/github-models.ts # OpenAI-SDK client → GitHub Models
|
|
187
|
+
├── session/ # history, persistence, multi-session, cloud sessions, handoff
|
|
188
|
+
├── context/ # @file parser, /compact, project memory, smart files, git/dep context
|
|
189
|
+
├── tools/ # shell, file ops, apply_patch, grep, glob, multi-edit, retry, policy
|
|
190
|
+
├── mcp/ # Model Context Protocol client + loader
|
|
191
|
+
├── commands/ # slash dispatcher, git autopilot, 40+ commands
|
|
192
|
+
├── agents/ # parallel runner, router, goal-driven, TDD, self-heal, multi-repo
|
|
193
|
+
├── intelligence/ # symbol index, navigation, error watch, stack trace, dead code
|
|
194
|
+
├── workflows/ # engine, file triggers, built-in workflows
|
|
195
|
+
├── knowledge/ # RAG, style learner, corrections, conventions
|
|
196
|
+
├── security/ # RBAC, audit, content filter, retention, proxy
|
|
197
|
+
├── providers/ # custom model providers, local models
|
|
198
|
+
├── plugins/ # marketplace, plugin loader
|
|
199
|
+
├── server/ # HTTP API server mode
|
|
200
|
+
├── bridge/ # IDE bridge (VS Code, Neovim)
|
|
201
|
+
├── sandbox/ # container-based execution
|
|
202
|
+
├── spaces/ # project spaces, space config
|
|
203
|
+
├── hooks/ # precommit, git hooks
|
|
204
|
+
├── ui/ # streaming markdown render, theme, prompt
|
|
205
|
+
└── modes/ # interactive / plan / oneshot
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
See [`roadmap.md`](./roadmap.md) for the version plan, [`TODO.md`](./TODO.md)
|
|
209
|
+
for the implementation checklist, and [`CHANGELOG.md`](./CHANGELOG.md) for
|
|
210
|
+
release notes.
|
|
211
|
+
|
|
212
|
+
## License
|
|
213
|
+
|
|
214
|
+
MIT
|
package/bin/icopilot.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { TOOL_SCHEMAS, dispatchTool } from '../tools/registry.js';
|
|
2
|
+
import { JSON_RPC_ERROR_CODES, createJsonRpcError, createJsonRpcResponse, isValidMethodName, parseMethodNamespace, validateJsonRpcRequest, } from './schema.js';
|
|
3
|
+
const VERSION = '2.2.0';
|
|
4
|
+
export class AcpRouter {
|
|
5
|
+
version;
|
|
6
|
+
onLog;
|
|
7
|
+
constructor(options) {
|
|
8
|
+
this.version = options?.version ?? VERSION;
|
|
9
|
+
this.onLog = options?.onLog ?? (() => { });
|
|
10
|
+
}
|
|
11
|
+
async handle(request) {
|
|
12
|
+
const validation = validateJsonRpcRequest(request);
|
|
13
|
+
if (!validation.valid) {
|
|
14
|
+
this.onLog('warn', 'Invalid JSON-RPC request', validation.error);
|
|
15
|
+
return createJsonRpcError(JSON_RPC_ERROR_CODES.INVALID_REQUEST, validation.error ?? 'Invalid request');
|
|
16
|
+
}
|
|
17
|
+
const req = request;
|
|
18
|
+
if (!isValidMethodName(req.method)) {
|
|
19
|
+
this.onLog('warn', 'Invalid method name', { method: req.method });
|
|
20
|
+
return createJsonRpcError(JSON_RPC_ERROR_CODES.METHOD_NOT_FOUND, 'Invalid method name', undefined, req.id);
|
|
21
|
+
}
|
|
22
|
+
this.onLog('debug', 'ACP request', { method: req.method, id: req.id });
|
|
23
|
+
try {
|
|
24
|
+
const { namespace, action } = parseMethodNamespace(req.method);
|
|
25
|
+
switch (namespace) {
|
|
26
|
+
case 'tools':
|
|
27
|
+
return await this.handleToolsMethod(action, req);
|
|
28
|
+
case 'tool':
|
|
29
|
+
return await this.handleToolMethod(action, req);
|
|
30
|
+
case 'capabilities':
|
|
31
|
+
return await this.handleCapabilitiesMethod(action, req);
|
|
32
|
+
default:
|
|
33
|
+
this.onLog('warn', 'Unknown method namespace', { namespace, method: req.method });
|
|
34
|
+
return createJsonRpcError(JSON_RPC_ERROR_CODES.METHOD_NOT_FOUND, `Unknown method: ${req.method}`, undefined, req.id);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
this.onLog('error', 'Error handling ACP request', {
|
|
39
|
+
method: req.method,
|
|
40
|
+
error: error instanceof Error ? error.message : String(error),
|
|
41
|
+
});
|
|
42
|
+
return createJsonRpcError(JSON_RPC_ERROR_CODES.INTERNAL_ERROR, error instanceof Error ? error.message : 'Internal server error', undefined, req.id);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async handleToolsMethod(action, req) {
|
|
46
|
+
if (action === 'list') {
|
|
47
|
+
const tools = this.getAvailableTools();
|
|
48
|
+
this.onLog('debug', 'Listed tools', { count: tools.length });
|
|
49
|
+
return createJsonRpcResponse(tools, req.id);
|
|
50
|
+
}
|
|
51
|
+
this.onLog('warn', 'Unknown tools method', { action });
|
|
52
|
+
return createJsonRpcError(JSON_RPC_ERROR_CODES.METHOD_NOT_FOUND, `Unknown method: tools/${action}`, undefined, req.id);
|
|
53
|
+
}
|
|
54
|
+
async handleToolMethod(action, req) {
|
|
55
|
+
if (action === 'call') {
|
|
56
|
+
return await this.callTool(req);
|
|
57
|
+
}
|
|
58
|
+
this.onLog('warn', 'Unknown tool method', { action });
|
|
59
|
+
return createJsonRpcError(JSON_RPC_ERROR_CODES.METHOD_NOT_FOUND, `Unknown method: tool/${action}`, undefined, req.id);
|
|
60
|
+
}
|
|
61
|
+
async handleCapabilitiesMethod(action, req) {
|
|
62
|
+
if (action === 'get') {
|
|
63
|
+
const capabilities = this.getCapabilities();
|
|
64
|
+
this.onLog('debug', 'Retrieved capabilities', {
|
|
65
|
+
version: capabilities.version,
|
|
66
|
+
methods: capabilities.supportedMethods.length,
|
|
67
|
+
});
|
|
68
|
+
return createJsonRpcResponse(capabilities, req.id);
|
|
69
|
+
}
|
|
70
|
+
this.onLog('warn', 'Unknown capabilities method', { action });
|
|
71
|
+
return createJsonRpcError(JSON_RPC_ERROR_CODES.METHOD_NOT_FOUND, `Unknown method: capabilities/${action}`, undefined, req.id);
|
|
72
|
+
}
|
|
73
|
+
getAvailableTools() {
|
|
74
|
+
return TOOL_SCHEMAS.filter((tool) => tool.type === 'function').map((tool) => {
|
|
75
|
+
const func = tool.function;
|
|
76
|
+
return {
|
|
77
|
+
name: func.name,
|
|
78
|
+
description: func.description,
|
|
79
|
+
inputSchema: {
|
|
80
|
+
type: 'object',
|
|
81
|
+
properties: func.parameters?.properties ?? {},
|
|
82
|
+
required: func.parameters?.required ?? [],
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
async callTool(req) {
|
|
88
|
+
const params = req.params;
|
|
89
|
+
if (!params || typeof params !== 'object') {
|
|
90
|
+
this.onLog('warn', 'Invalid tool call params', { id: req.id });
|
|
91
|
+
return createJsonRpcError(JSON_RPC_ERROR_CODES.INVALID_PARAMS, 'params must be an object with toolName and args', undefined, req.id);
|
|
92
|
+
}
|
|
93
|
+
const toolName = params.toolName;
|
|
94
|
+
const toolArgs = params.args;
|
|
95
|
+
if (typeof toolName !== 'string' || !toolName) {
|
|
96
|
+
this.onLog('warn', 'Missing or invalid toolName', { id: req.id });
|
|
97
|
+
return createJsonRpcError(JSON_RPC_ERROR_CODES.INVALID_PARAMS, 'toolName must be a non-empty string', undefined, req.id);
|
|
98
|
+
}
|
|
99
|
+
if (!toolArgs || typeof toolArgs !== 'object') {
|
|
100
|
+
this.onLog('warn', 'Missing or invalid tool args', { toolName, id: req.id });
|
|
101
|
+
return createJsonRpcError(JSON_RPC_ERROR_CODES.INVALID_PARAMS, 'args must be an object', undefined, req.id);
|
|
102
|
+
}
|
|
103
|
+
this.onLog('debug', 'Calling tool', { toolName, id: req.id });
|
|
104
|
+
try {
|
|
105
|
+
const result = await dispatchTool(toolName, toolArgs);
|
|
106
|
+
this.onLog('debug', 'Tool call succeeded', { toolName });
|
|
107
|
+
return createJsonRpcResponse({ toolName, result }, req.id);
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
111
|
+
this.onLog('warn', 'Tool call failed', { toolName, error: errorMsg });
|
|
112
|
+
return createJsonRpcError(JSON_RPC_ERROR_CODES.INTERNAL_ERROR, `Tool execution failed: ${errorMsg}`, { toolName, error: errorMsg }, req.id);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
getCapabilities() {
|
|
116
|
+
return {
|
|
117
|
+
version: this.version,
|
|
118
|
+
protocolVersion: '1.0',
|
|
119
|
+
supportedMethods: ['tools/list', 'tool/call', 'capabilities/get'],
|
|
120
|
+
name: 'iCopilot ACP Server',
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export const JSON_RPC_ERROR_CODES = {
|
|
2
|
+
PARSE_ERROR: -32700,
|
|
3
|
+
INVALID_REQUEST: -32600,
|
|
4
|
+
METHOD_NOT_FOUND: -32601,
|
|
5
|
+
INVALID_PARAMS: -32602,
|
|
6
|
+
INTERNAL_ERROR: -32603,
|
|
7
|
+
SERVER_ERROR_START: -32099,
|
|
8
|
+
SERVER_ERROR_END: -32000,
|
|
9
|
+
NOT_AUTHORIZED: -32001,
|
|
10
|
+
};
|
|
11
|
+
export function validateJsonRpcRequest(data) {
|
|
12
|
+
if (typeof data !== 'object' || data === null) {
|
|
13
|
+
return { valid: false, error: 'Request must be an object' };
|
|
14
|
+
}
|
|
15
|
+
const req = data;
|
|
16
|
+
if (req.jsonrpc !== '2.0') {
|
|
17
|
+
return { valid: false, error: 'jsonrpc must be "2.0"' };
|
|
18
|
+
}
|
|
19
|
+
if (typeof req.method !== 'string' || !req.method) {
|
|
20
|
+
return { valid: false, error: 'method must be a non-empty string' };
|
|
21
|
+
}
|
|
22
|
+
if (req.id !== undefined &&
|
|
23
|
+
typeof req.id !== 'string' &&
|
|
24
|
+
typeof req.id !== 'number' &&
|
|
25
|
+
req.id !== null) {
|
|
26
|
+
return { valid: false, error: 'id must be a string, number, or null' };
|
|
27
|
+
}
|
|
28
|
+
return { valid: true };
|
|
29
|
+
}
|
|
30
|
+
export function createJsonRpcResponse(result, id) {
|
|
31
|
+
return {
|
|
32
|
+
jsonrpc: '2.0',
|
|
33
|
+
result,
|
|
34
|
+
id,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export function createJsonRpcError(code, message, data, id) {
|
|
38
|
+
return {
|
|
39
|
+
jsonrpc: '2.0',
|
|
40
|
+
error: { code, message, data },
|
|
41
|
+
id,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export function isValidMethodName(method) {
|
|
45
|
+
return /^[a-zA-Z0-9_/-]+$/.test(method) && method.length > 0 && method.length <= 128;
|
|
46
|
+
}
|
|
47
|
+
export function parseMethodNamespace(method) {
|
|
48
|
+
const parts = method.split('/');
|
|
49
|
+
if (parts.length === 2) {
|
|
50
|
+
return { namespace: parts[0], action: parts[1] };
|
|
51
|
+
}
|
|
52
|
+
return { namespace: '', action: method };
|
|
53
|
+
}
|