Skip to content

Commit 3cb80a6

Browse files
olimorriscleong14
authored andcommitted
refactor(tools)!: add queue and streamline implementation (olimorris#965)
1 parent 038c98b commit 3cb80a6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+4332
-1254
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,5 +112,7 @@ buffer
112112
- [Aerial.nvim](https://github.com/stevearc/aerial.nvim) for the Tree-sitter parsing which inspired the symbols Slash
113113
Command
114114
- [Saghen](https://github.com/Saghen) for the fantastic docs inspiration from [blink.cmp](https://github.com/Saghen/blink.cmp)
115+
- [Catwell](https://github.com/catwell) for the [queue](https://github.com/catwell/cw-lua/blob/master/deque/deque.lua)
116+
inspiration that I use to stack agents and tools
115117

116118
<!-- panvimdoc-ignore-end -->

codecompanion-workspace.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,42 @@
140140
"url": "https://raw.githubusercontent.com/olimorris/codecompanion.nvim/refs/heads/main/lua/codecompanion/strategies/inline/init.lua"
141141
}
142142
]
143+
},
144+
{
145+
"name": "Tools",
146+
"system_prompt": "In the CodeCompanion plugin, tools can be leveraged by an LLM to execute lua functions or shell commands on the users machine. By responding with XML, CodeCompanion will pass the response, call the corresponding tool. This feature has been implemented via the agent/init.lua file, which passes all of the tools and adds them to a queue. Then those tools are run consecutively by the executor/init.lua file.",
147+
"opts": {
148+
"remove_config_system_prompt": true
149+
},
150+
"vars": {
151+
"base_dir": "lua/codecompanion/strategies/chat/agents"
152+
},
153+
"files": [
154+
{
155+
"description": "This is the entry point for the agent. If XML is detected in an LLM's response then this file is triggered which in turns add tools to a queue before calling the executor",
156+
"path": "${base_dir}/init.lua"
157+
},
158+
{
159+
"description": "The executor file then runs the tools in the queue, whether they're functions or commands:",
160+
"path": "${base_dir}/executor/init.lua"
161+
},
162+
{
163+
"description": "This is how function tools are run:",
164+
"path": "${base_dir}/executor/func.lua"
165+
},
166+
{
167+
"description": "This is how command tools are run:",
168+
"path": "${base_dir}/executor/cmd.lua"
169+
},
170+
{
171+
"description": "This is the queue implementation",
172+
"path": "${base_dir}/executor/queue.lua"
173+
},
174+
{
175+
"description": "This is how the queue object can look. This is an example of a function tool, a command tool, followed by a function tool:",
176+
"path": "tests/stubs/queue.txt"
177+
}
178+
]
143179
}
144180
]
145181
}

doc/.vitepress/config.mjs

Lines changed: 105 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { defineConfig } from "vitepress";
22
import { execSync } from "node:child_process";
3+
import { withMermaid } from "vitepress-plugin-mermaid";
34

45
const inProd = process.env.NODE_ENV === "production";
56

@@ -28,103 +29,113 @@ const headers = inProd ? [baseHeaders, umamiScript] : baseHeaders;
2829
const siteUrl = "https://codecompanion.olimorris.dev";
2930

3031
// https://vitepress.dev/reference/site-config
31-
export default defineConfig({
32-
title: "CodeCompanion",
33-
description: "AI-powered coding, seamlessly in Neovim",
34-
head: headers,
35-
sitemap: { hostname: siteUrl },
36-
themeConfig: {
37-
logo: "https://github.com/user-attachments/assets/825fc040-9bc8-4743-be2a-71e257f8a7be",
38-
nav: [
39-
{
40-
text: `${version}`,
41-
items: [
42-
{
43-
text: "Changelog",
44-
link: "https://github.com/olimorris/codecompanion.nvim/blob/main/CHANGELOG.md",
45-
},
46-
{
47-
text: "Contributing",
48-
link: "https://github.com/olimorris/codecompanion.nvim/blob/main/.github/contributing.md",
49-
},
50-
],
51-
},
52-
],
32+
export default withMermaid(
33+
defineConfig({
34+
mermaid: {
35+
securityLevel: "loose", // Allows more flexibility
36+
theme: "base", // Use base theme to allow CSS variables to take effect
37+
},
38+
// optionally set additional config for plugin itself with MermaidPluginConfig
39+
title: "CodeCompanion",
40+
description: "AI-powered coding, seamlessly in Neovim",
41+
head: headers,
42+
sitemap: { hostname: siteUrl },
43+
themeConfig: {
44+
logo: "https://github.com/user-attachments/assets/825fc040-9bc8-4743-be2a-71e257f8a7be",
45+
nav: [
46+
{
47+
text: `${version}`,
48+
items: [
49+
{
50+
text: "Changelog",
51+
link: "https://github.com/olimorris/codecompanion.nvim/blob/main/CHANGELOG.md",
52+
},
53+
{
54+
text: "Contributing",
55+
link: "https://github.com/olimorris/codecompanion.nvim/blob/main/.github/contributing.md",
56+
},
57+
],
58+
},
59+
],
5360

54-
sidebar: [
55-
{ text: "Introduction", link: "/" },
56-
{ text: "Installation", link: "/installation" },
57-
{ text: "Getting Started", link: "/getting-started" },
58-
{
59-
text: "Configuration",
60-
collapsed: true,
61-
items: [
62-
{ text: "Introduction", link: "/configuration/introduction" },
63-
{ text: "Action Palette", link: "/configuration/action-palette" },
64-
{ text: "Adapters", link: "/configuration/adapters" },
65-
{ text: "Chat Buffer", link: "/configuration/chat-buffer" },
66-
{ text: "Inline Assistant", link: "/configuration/inline-assistant" },
67-
{ text: "Prompt Library", link: "/configuration/prompt-library" },
68-
{ text: "System Prompt", link: "/configuration/system-prompt" },
69-
{ text: "Others", link: "/configuration/others" },
70-
],
71-
},
72-
{
73-
text: "Usage",
74-
collapsed: false,
75-
items: [
76-
{ text: "Introduction", link: "/usage/introduction" },
77-
{ text: "Action Palette", link: "/usage/action-palette" },
78-
{
79-
text: "Chat Buffer",
80-
link: "/usage/chat-buffer/",
81-
collapsed: true,
82-
items: [
83-
{ text: "Agents/Tools", link: "/usage/chat-buffer/agents" },
84-
{
85-
text: "Slash Commands",
86-
link: "/usage/chat-buffer/slash-commands",
87-
},
88-
{ text: "Variables", link: "/usage/chat-buffer/variables" },
89-
],
90-
},
91-
{ text: "Events", link: "/usage/events" },
92-
{ text: "Inline Assistant", link: "/usage/inline-assistant" },
93-
{ text: "User Interface", link: "/usage/ui" },
94-
{ text: "Workflows", link: "/usage/workflows" },
95-
],
61+
sidebar: [
62+
{ text: "Introduction", link: "/" },
63+
{ text: "Installation", link: "/installation" },
64+
{ text: "Getting Started", link: "/getting-started" },
65+
{
66+
text: "Configuration",
67+
collapsed: true,
68+
items: [
69+
{ text: "Introduction", link: "/configuration/introduction" },
70+
{ text: "Action Palette", link: "/configuration/action-palette" },
71+
{ text: "Adapters", link: "/configuration/adapters" },
72+
{ text: "Chat Buffer", link: "/configuration/chat-buffer" },
73+
{
74+
text: "Inline Assistant",
75+
link: "/configuration/inline-assistant",
76+
},
77+
{ text: "Prompt Library", link: "/configuration/prompt-library" },
78+
{ text: "System Prompt", link: "/configuration/system-prompt" },
79+
{ text: "Others", link: "/configuration/others" },
80+
],
81+
},
82+
{
83+
text: "Usage",
84+
collapsed: false,
85+
items: [
86+
{ text: "Introduction", link: "/usage/introduction" },
87+
{ text: "Action Palette", link: "/usage/action-palette" },
88+
{
89+
text: "Chat Buffer",
90+
link: "/usage/chat-buffer/",
91+
collapsed: true,
92+
items: [
93+
{ text: "Agents/Tools", link: "/usage/chat-buffer/agents" },
94+
{
95+
text: "Slash Commands",
96+
link: "/usage/chat-buffer/slash-commands",
97+
},
98+
{ text: "Variables", link: "/usage/chat-buffer/variables" },
99+
],
100+
},
101+
{ text: "Events", link: "/usage/events" },
102+
{ text: "Inline Assistant", link: "/usage/inline-assistant" },
103+
{ text: "User Interface", link: "/usage/ui" },
104+
{ text: "Workflows", link: "/usage/workflows" },
105+
],
106+
},
107+
{
108+
text: "Extending the Plugin",
109+
collapsed: false,
110+
items: [
111+
{ text: "Creating Adapters", link: "/extending/adapters" },
112+
{ text: "Creating Prompts", link: "/extending/prompts" },
113+
{ text: "Creating Tools", link: "/extending/tools" },
114+
{ text: "Creating Workflows", link: "/extending/workflows" },
115+
{ text: "Creating Workspaces", link: "/extending/workspace" },
116+
],
117+
},
118+
],
119+
120+
editLink: {
121+
pattern:
122+
"https://github.com/olimorris/codecompanion.nvim/edit/main/doc/:path",
123+
text: "Edit this page on GitHub",
96124
},
97-
{
98-
text: "Extending the Plugin",
99-
collapsed: false,
100-
items: [
101-
{ text: "Creating Adapters", link: "/extending/adapters" },
102-
{ text: "Creating Prompts", link: "/extending/prompts" },
103-
{ text: "Creating Tools", link: "/extending/tools" },
104-
{ text: "Creating Workflows", link: "/extending/workflows" },
105-
{ text: "Creating Workspaces", link: "/extending/workspace" },
106-
],
125+
126+
footer: {
127+
message: "Released under the MIT License.",
128+
copyright: "Copyright © 2024-present Oli Morris",
107129
},
108-
],
109130

110-
editLink: {
111-
pattern:
112-
"https://github.com/olimorris/codecompanion.nvim/edit/main/doc/:path",
113-
text: "Edit this page on GitHub",
114-
},
131+
socialLinks: [
132+
{
133+
icon: "github",
134+
link: "https://github.com/olimorris/codecompanion.nvim",
135+
},
136+
],
115137

116-
footer: {
117-
message: "Released under the MIT License.",
118-
copyright: "Copyright © 2024-present Oli Morris",
138+
search: { provider: "local" },
119139
},
120-
121-
socialLinks: [
122-
{
123-
icon: "github",
124-
link: "https://github.com/olimorris/codecompanion.nvim",
125-
},
126-
],
127-
128-
search: { provider: "local" },
129-
},
130-
});
140+
}),
141+
);

doc/.vitepress/theme/vaporwave.css

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,81 @@
9191
/* Override base background for dark mode */
9292
--vw-base-bg-mixer: 20%;
9393
}
94+
95+
/* Mermaid */
96+
.mermaid * {
97+
font-family: var(--vp-font-family-base) !important;
98+
font-weight: var(--vp-font-weight-regular, 400) !important;
99+
}
100+
101+
.mermaid .noteText,
102+
.mermaid .loopText {
103+
font-size: 0.9em !important;
104+
}
105+
106+
.mermaid .note {
107+
fill: color-mix(in srgb, var(--vw-purple) 40%, var(--vw-base-bg)) !important;
108+
stroke: var(--vw-purple) !important;
109+
}
110+
111+
.mermaid .actor {
112+
fill: color-mix(in srgb, var(--vw-blue) 20%, var(--vw-base-bg)) !important;
113+
stroke: var(--vw-blue) !important;
114+
font-weight: var(--vp-font-weight-medium, 500) !important;
115+
}
116+
117+
.mermaid text.actor > tspan {
118+
fill: var(--vw-base-fg) !important;
119+
stroke: none !important;
120+
font-weight: var(--vp-font-weight-medium, 500) !important;
121+
}
122+
123+
.mermaid .messageText {
124+
fill: var(--vw-base-fg) !important;
125+
stroke: none !important;
126+
}
127+
128+
.mermaid .messageLine0,
129+
.mermaid .messageLine1 {
130+
stroke: var(--vw-green) !important;
131+
}
132+
133+
.mermaid .sequenceNumber {
134+
fill: var(--vw-base-bg) !important;
135+
}
136+
137+
.mermaid .loopLine {
138+
stroke: var(--vw-yellow) !important;
139+
}
140+
141+
.mermaid .loopText > tspan {
142+
fill: var(--vw-base-fg) !important;
143+
stroke: none !important;
144+
}
145+
146+
.mermaid .labelBox {
147+
fill: color-mix(in srgb, var(--vw-yellow) 20%, var(--vw-base-bg)) !important;
148+
stroke: var(--vw-yellow) !important;
149+
}
150+
151+
.mermaid .labelText {
152+
fill: var(--vw-base-fg) !important;
153+
}
154+
155+
.mermaid line.divider {
156+
stroke: var(--vw-purple) !important;
157+
}
158+
159+
.mermaid .noteText > tspan {
160+
fill: var(--vw-base-fg) !important;
161+
stroke: none !important;
162+
font-weight: var(--vp-font-weight-regular, 400) !important;
163+
}
164+
165+
/* Adds styling for the activation boxes */
166+
.mermaid .activation0,
167+
.mermaid .activation1,
168+
.mermaid .activation2 {
169+
fill: color-mix(in srgb, var(--vw-green) 20%, var(--vw-base-bg)) !important;
170+
stroke: var(--vw-green) !important;
171+
}

0 commit comments

Comments
 (0)