@kernel.chat/kbot 1.3.1 → 2.3.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.
Files changed (176) hide show
  1. package/README.md +94 -0
  2. package/dist/agent.d.ts +9 -0
  3. package/dist/agent.d.ts.map +1 -1
  4. package/dist/agent.js +576 -119
  5. package/dist/agent.js.map +1 -1
  6. package/dist/auth.d.ts +20 -35
  7. package/dist/auth.d.ts.map +1 -1
  8. package/dist/auth.js +224 -66
  9. package/dist/auth.js.map +1 -1
  10. package/dist/auth.test.d.ts +2 -0
  11. package/dist/auth.test.d.ts.map +1 -0
  12. package/dist/auth.test.js +89 -0
  13. package/dist/auth.test.js.map +1 -0
  14. package/dist/build-targets.d.ts +37 -0
  15. package/dist/build-targets.d.ts.map +1 -0
  16. package/dist/build-targets.js +507 -0
  17. package/dist/build-targets.js.map +1 -0
  18. package/dist/cli.js +1210 -130
  19. package/dist/cli.js.map +1 -1
  20. package/dist/context.d.ts +2 -0
  21. package/dist/context.d.ts.map +1 -1
  22. package/dist/context.js +72 -22
  23. package/dist/context.js.map +1 -1
  24. package/dist/hooks.d.ts +27 -0
  25. package/dist/hooks.d.ts.map +1 -0
  26. package/dist/hooks.js +145 -0
  27. package/dist/hooks.js.map +1 -0
  28. package/dist/ide/acp-server.d.ts +6 -0
  29. package/dist/ide/acp-server.d.ts.map +1 -0
  30. package/dist/ide/acp-server.js +319 -0
  31. package/dist/ide/acp-server.js.map +1 -0
  32. package/dist/ide/bridge.d.ts +128 -0
  33. package/dist/ide/bridge.d.ts.map +1 -0
  34. package/dist/ide/bridge.js +185 -0
  35. package/dist/ide/bridge.js.map +1 -0
  36. package/dist/ide/index.d.ts +5 -0
  37. package/dist/ide/index.d.ts.map +1 -0
  38. package/dist/ide/index.js +11 -0
  39. package/dist/ide/index.js.map +1 -0
  40. package/dist/ide/lsp-bridge.d.ts +27 -0
  41. package/dist/ide/lsp-bridge.d.ts.map +1 -0
  42. package/dist/ide/lsp-bridge.js +267 -0
  43. package/dist/ide/lsp-bridge.js.map +1 -0
  44. package/dist/ide/mcp-server.d.ts +7 -0
  45. package/dist/ide/mcp-server.d.ts.map +1 -0
  46. package/dist/ide/mcp-server.js +451 -0
  47. package/dist/ide/mcp-server.js.map +1 -0
  48. package/dist/learning.d.ts +179 -0
  49. package/dist/learning.d.ts.map +1 -0
  50. package/dist/learning.js +829 -0
  51. package/dist/learning.js.map +1 -0
  52. package/dist/learning.test.d.ts +2 -0
  53. package/dist/learning.test.d.ts.map +1 -0
  54. package/dist/learning.test.js +115 -0
  55. package/dist/learning.test.js.map +1 -0
  56. package/dist/matrix.d.ts +49 -0
  57. package/dist/matrix.d.ts.map +1 -0
  58. package/dist/matrix.js +302 -0
  59. package/dist/matrix.js.map +1 -0
  60. package/dist/memory.d.ts +11 -0
  61. package/dist/memory.d.ts.map +1 -1
  62. package/dist/memory.js +54 -2
  63. package/dist/memory.js.map +1 -1
  64. package/dist/multimodal.d.ts +57 -0
  65. package/dist/multimodal.d.ts.map +1 -0
  66. package/dist/multimodal.js +206 -0
  67. package/dist/multimodal.js.map +1 -0
  68. package/dist/permissions.d.ts +21 -0
  69. package/dist/permissions.d.ts.map +1 -0
  70. package/dist/permissions.js +122 -0
  71. package/dist/permissions.js.map +1 -0
  72. package/dist/planner.d.ts +54 -0
  73. package/dist/planner.d.ts.map +1 -0
  74. package/dist/planner.js +298 -0
  75. package/dist/planner.js.map +1 -0
  76. package/dist/plugins.d.ts +30 -0
  77. package/dist/plugins.d.ts.map +1 -0
  78. package/dist/plugins.js +135 -0
  79. package/dist/plugins.js.map +1 -0
  80. package/dist/sessions.d.ts +38 -0
  81. package/dist/sessions.d.ts.map +1 -0
  82. package/dist/sessions.js +177 -0
  83. package/dist/sessions.js.map +1 -0
  84. package/dist/streaming.d.ts +88 -0
  85. package/dist/streaming.d.ts.map +1 -0
  86. package/dist/streaming.js +317 -0
  87. package/dist/streaming.js.map +1 -0
  88. package/dist/tools/background.d.ts +2 -0
  89. package/dist/tools/background.d.ts.map +1 -0
  90. package/dist/tools/background.js +163 -0
  91. package/dist/tools/background.js.map +1 -0
  92. package/dist/tools/bash.d.ts.map +1 -1
  93. package/dist/tools/bash.js +26 -1
  94. package/dist/tools/bash.js.map +1 -1
  95. package/dist/tools/browser.js +7 -7
  96. package/dist/tools/browser.js.map +1 -1
  97. package/dist/tools/build-matrix.d.ts +2 -0
  98. package/dist/tools/build-matrix.d.ts.map +1 -0
  99. package/dist/tools/build-matrix.js +463 -0
  100. package/dist/tools/build-matrix.js.map +1 -0
  101. package/dist/tools/computer.js +5 -5
  102. package/dist/tools/computer.js.map +1 -1
  103. package/dist/tools/fetch.d.ts +2 -0
  104. package/dist/tools/fetch.d.ts.map +1 -0
  105. package/dist/tools/fetch.js +106 -0
  106. package/dist/tools/fetch.js.map +1 -0
  107. package/dist/tools/files.d.ts.map +1 -1
  108. package/dist/tools/files.js +112 -6
  109. package/dist/tools/files.js.map +1 -1
  110. package/dist/tools/git.js +3 -3
  111. package/dist/tools/git.js.map +1 -1
  112. package/dist/tools/github.d.ts +2 -0
  113. package/dist/tools/github.d.ts.map +1 -0
  114. package/dist/tools/github.js +196 -0
  115. package/dist/tools/github.js.map +1 -0
  116. package/dist/tools/index.d.ts +29 -5
  117. package/dist/tools/index.d.ts.map +1 -1
  118. package/dist/tools/index.js +136 -20
  119. package/dist/tools/index.js.map +1 -1
  120. package/dist/tools/index.test.d.ts +2 -0
  121. package/dist/tools/index.test.d.ts.map +1 -0
  122. package/dist/tools/index.test.js +162 -0
  123. package/dist/tools/index.test.js.map +1 -0
  124. package/dist/tools/matrix.d.ts +2 -0
  125. package/dist/tools/matrix.d.ts.map +1 -0
  126. package/dist/tools/matrix.js +79 -0
  127. package/dist/tools/matrix.js.map +1 -0
  128. package/dist/tools/mcp-client.d.ts +2 -0
  129. package/dist/tools/mcp-client.d.ts.map +1 -0
  130. package/dist/tools/mcp-client.js +295 -0
  131. package/dist/tools/mcp-client.js.map +1 -0
  132. package/dist/tools/notebook.d.ts +2 -0
  133. package/dist/tools/notebook.d.ts.map +1 -0
  134. package/dist/tools/notebook.js +207 -0
  135. package/dist/tools/notebook.js.map +1 -0
  136. package/dist/tools/openclaw.d.ts +2 -0
  137. package/dist/tools/openclaw.d.ts.map +1 -0
  138. package/dist/tools/openclaw.js +187 -0
  139. package/dist/tools/openclaw.js.map +1 -0
  140. package/dist/tools/parallel.d.ts +2 -0
  141. package/dist/tools/parallel.d.ts.map +1 -0
  142. package/dist/tools/parallel.js +60 -0
  143. package/dist/tools/parallel.js.map +1 -0
  144. package/dist/tools/sandbox.d.ts +2 -0
  145. package/dist/tools/sandbox.d.ts.map +1 -0
  146. package/dist/tools/sandbox.js +352 -0
  147. package/dist/tools/sandbox.js.map +1 -0
  148. package/dist/tools/search.d.ts.map +1 -1
  149. package/dist/tools/search.js +135 -28
  150. package/dist/tools/search.js.map +1 -1
  151. package/dist/tools/subagent.d.ts +4 -0
  152. package/dist/tools/subagent.d.ts.map +1 -0
  153. package/dist/tools/subagent.js +260 -0
  154. package/dist/tools/subagent.js.map +1 -0
  155. package/dist/tools/tasks.d.ts +14 -0
  156. package/dist/tools/tasks.d.ts.map +1 -0
  157. package/dist/tools/tasks.js +210 -0
  158. package/dist/tools/tasks.js.map +1 -0
  159. package/dist/tools/worktree.d.ts +2 -0
  160. package/dist/tools/worktree.d.ts.map +1 -0
  161. package/dist/tools/worktree.js +223 -0
  162. package/dist/tools/worktree.js.map +1 -0
  163. package/dist/tui.d.ts +73 -0
  164. package/dist/tui.d.ts.map +1 -0
  165. package/dist/tui.js +257 -0
  166. package/dist/tui.js.map +1 -0
  167. package/dist/ui.d.ts +11 -19
  168. package/dist/ui.d.ts.map +1 -1
  169. package/dist/ui.js +143 -171
  170. package/dist/ui.js.map +1 -1
  171. package/dist/updater.d.ts +3 -0
  172. package/dist/updater.d.ts.map +1 -0
  173. package/dist/updater.js +70 -0
  174. package/dist/updater.js.map +1 -0
  175. package/install.sh +5 -7
  176. package/package.json +8 -4
@@ -0,0 +1,298 @@
1
+ // K:BOT Autonomous Planner — Plan-then-Execute for complex tasks
2
+ //
3
+ // This is the core missing piece vs Claude Code. When given a complex task,
4
+ // K:BOT should:
5
+ // 1. EXPLORE — read files, understand the codebase
6
+ // 2. PLAN — decompose into steps, identify files to change
7
+ // 3. CONFIRM — show the plan to the user for approval
8
+ // 4. EXECUTE — run each step, verify, self-correct
9
+ // 5. VERIFY — type-check, test, confirm everything works
10
+ //
11
+ // The planner uses the AI to generate a structured plan, then drives
12
+ // execution through the existing tool registry.
13
+ import { runAgent } from './agent.js';
14
+ import { executeTool, getTool } from './tools/index.js';
15
+ import { gatherContext, formatContextForPrompt } from './context.js';
16
+ import { createSpinner, printInfo, printSuccess, printError, printWarn } from './ui.js';
17
+ import chalk from 'chalk';
18
+ const AMETHYST = chalk.hex('#6B5B95');
19
+ // ── Plan Generation ──
20
+ const PLAN_SYSTEM_PROMPT = `You are an autonomous coding agent planning a task. You must output a structured JSON plan.
21
+
22
+ Given the user's task and project context, produce a plan with this exact JSON structure:
23
+ {
24
+ "summary": "One-sentence summary of what will be done",
25
+ "steps": [
26
+ {
27
+ "id": 1,
28
+ "description": "Human-readable description of this step",
29
+ "tool": "tool_name",
30
+ "args": { "key": "value" },
31
+ "reads": ["file1.ts"],
32
+ "writes": ["file2.ts"],
33
+ "dependsOn": []
34
+ }
35
+ ],
36
+ "filesInScope": ["list of all files that need to be read or modified"]
37
+ }
38
+
39
+ Available tools: read_file, write_file, edit_file, multi_file_write, bash, glob, grep, git_status, git_diff, git_commit, git_push, web_search, research, url_fetch, parallel_execute, sandbox_run, build_run, notebook_edit
40
+
41
+ Rules:
42
+ - Start with read_file/glob/grep steps to understand the codebase BEFORE making changes
43
+ - Group independent operations that can run in parallel
44
+ - Always verify changes with a type-check or test step at the end
45
+ - For file edits, use edit_file with old_string/new_string (not full rewrites unless creating new files)
46
+ - Include error recovery — if a step might fail, note what to do
47
+ - Keep plans concise — 5-20 steps for most tasks
48
+ - Output ONLY valid JSON, no markdown wrapping`;
49
+ /**
50
+ * Generate a plan for a complex task.
51
+ * Uses the AI to analyze the task and produce structured steps.
52
+ */
53
+ export async function generatePlan(task, agentOpts) {
54
+ const context = gatherContext();
55
+ const contextStr = formatContextForPrompt(context);
56
+ const planPrompt = `${PLAN_SYSTEM_PROMPT}
57
+
58
+ Project context:
59
+ ${contextStr}
60
+
61
+ Task: ${task}
62
+
63
+ Output your plan as JSON:`;
64
+ // Use the agent to generate the plan (it has access to tools for exploration)
65
+ const response = await runAgent(planPrompt, {
66
+ ...agentOpts,
67
+ agent: 'coder', // Use coder agent for planning
68
+ });
69
+ // Parse the JSON plan from the response
70
+ let planData;
71
+ try {
72
+ // Extract JSON from response (might be wrapped in markdown)
73
+ const jsonMatch = response.content.match(/\{[\s\S]*\}/);
74
+ if (!jsonMatch)
75
+ throw new Error('No JSON found in plan response');
76
+ planData = JSON.parse(jsonMatch[0]);
77
+ }
78
+ catch {
79
+ // If AI didn't return valid JSON, create a simple single-step plan
80
+ planData = {
81
+ summary: `Execute: ${task}`,
82
+ steps: [{
83
+ id: 1,
84
+ description: task,
85
+ reads: [],
86
+ writes: [],
87
+ dependsOn: [],
88
+ }],
89
+ filesInScope: [],
90
+ };
91
+ }
92
+ return {
93
+ task,
94
+ summary: planData.summary,
95
+ steps: planData.steps.map((s, i) => ({
96
+ ...s,
97
+ id: s.id || i + 1,
98
+ status: 'pending',
99
+ })),
100
+ filesInScope: planData.filesInScope || [],
101
+ estimatedToolCalls: planData.steps.length,
102
+ status: 'awaiting_approval',
103
+ createdAt: new Date().toISOString(),
104
+ };
105
+ }
106
+ /**
107
+ * Display a plan to the user for approval.
108
+ */
109
+ export function displayPlan(plan) {
110
+ console.log();
111
+ console.log(` ${AMETHYST('◆ Plan')}: ${plan.summary}`);
112
+ console.log(` ${chalk.dim('─'.repeat(50))}`);
113
+ console.log();
114
+ for (const step of plan.steps) {
115
+ const deps = step.dependsOn && step.dependsOn.length > 0
116
+ ? chalk.dim(` (after #${step.dependsOn.join(', #')})`)
117
+ : '';
118
+ const tool = step.tool ? chalk.cyan(` [${step.tool}]`) : '';
119
+ console.log(` ${chalk.dim(`${step.id}.`)} ${step.description}${tool}${deps}`);
120
+ if (step.writes && step.writes.length > 0) {
121
+ console.log(` ${chalk.dim('writes:')} ${step.writes.join(', ')}`);
122
+ }
123
+ }
124
+ console.log();
125
+ console.log(` ${chalk.dim(`${plan.steps.length} steps · ${plan.filesInScope.length} files in scope`)}`);
126
+ console.log();
127
+ }
128
+ /**
129
+ * Execute a plan step by step.
130
+ * Supports parallel execution for independent steps.
131
+ */
132
+ export async function executePlan(plan, agentOpts, onStepComplete) {
133
+ plan.status = 'executing';
134
+ // Group steps by dependency layers for parallel execution
135
+ const executed = new Set();
136
+ while (executed.size < plan.steps.length) {
137
+ // Find all steps whose dependencies are met
138
+ const ready = plan.steps.filter(step => {
139
+ if (executed.has(step.id))
140
+ return false;
141
+ if (step.status === 'skipped') {
142
+ executed.add(step.id);
143
+ return false;
144
+ }
145
+ const deps = step.dependsOn || [];
146
+ return deps.every(depId => {
147
+ const dep = plan.steps.find(s => s.id === depId);
148
+ return dep && (dep.status === 'done' || executed.has(depId));
149
+ });
150
+ });
151
+ if (ready.length === 0) {
152
+ // Remaining steps have unmet deps
153
+ for (const step of plan.steps) {
154
+ if (!executed.has(step.id) && step.status === 'pending') {
155
+ step.status = 'skipped';
156
+ step.error = 'Unmet dependencies (earlier steps failed)';
157
+ executed.add(step.id);
158
+ }
159
+ }
160
+ break;
161
+ }
162
+ if (ready.length > 1) {
163
+ printInfo(`Running ${ready.length} steps in parallel...`);
164
+ }
165
+ // Execute ready steps in parallel
166
+ await Promise.all(ready.map(async (step) => {
167
+ step.status = 'running';
168
+ const spinner = createSpinner(`Step ${step.id}: ${step.description}`);
169
+ spinner.start();
170
+ try {
171
+ if (step.tool && step.args) {
172
+ const call = {
173
+ id: `plan_${plan.createdAt}_step_${step.id}`,
174
+ name: step.tool,
175
+ arguments: step.args,
176
+ };
177
+ const result = await executeTool(call);
178
+ step.result = result.result;
179
+ step.status = result.error ? 'failed' : 'done';
180
+ if (result.error)
181
+ step.error = result.result;
182
+ }
183
+ else {
184
+ const response = await runAgent(`You are executing step ${step.id} of a plan. The step is: "${step.description}"\n\nExecute this step now using your tools. Be precise and verify your work.`, agentOpts);
185
+ step.result = response.content;
186
+ step.status = 'done';
187
+ }
188
+ spinner.stop();
189
+ if (step.status === 'done') {
190
+ printSuccess(`Step ${step.id}: ${step.description}`);
191
+ }
192
+ else {
193
+ printError(`Step ${step.id} failed: ${step.error}`);
194
+ }
195
+ }
196
+ catch (err) {
197
+ spinner.stop();
198
+ step.status = 'failed';
199
+ step.error = err instanceof Error ? err.message : String(err);
200
+ printError(`Step ${step.id} failed: ${step.error}`);
201
+ // Self-correction
202
+ printWarn('Attempting self-correction...');
203
+ try {
204
+ const fixResponse = await runAgent(`Step ${step.id} ("${step.description}") failed with error:\n${step.error}\n\nAnalyze the error and try a different approach.`, agentOpts);
205
+ step.result = fixResponse.content;
206
+ step.status = 'done';
207
+ step.error = undefined;
208
+ printSuccess(`Step ${step.id}: recovered via self-correction`);
209
+ }
210
+ catch {
211
+ printError(`Self-correction also failed. Continuing.`);
212
+ }
213
+ }
214
+ executed.add(step.id);
215
+ onStepComplete?.(step);
216
+ }));
217
+ }
218
+ // Final status
219
+ const failed = plan.steps.filter(s => s.status === 'failed');
220
+ const done = plan.steps.filter(s => s.status === 'done');
221
+ plan.status = failed.length === 0 ? 'completed' : 'failed';
222
+ console.log();
223
+ if (plan.status === 'completed') {
224
+ printSuccess(`Plan complete: ${done.length}/${plan.steps.length} steps succeeded`);
225
+ }
226
+ else {
227
+ printWarn(`Plan finished with errors: ${done.length} done, ${failed.length} failed`);
228
+ }
229
+ return plan;
230
+ }
231
+ /**
232
+ * Full autonomous flow: Plan → Confirm → Execute → Verify
233
+ * This is the top-level entry point for complex tasks.
234
+ */
235
+ export async function autonomousExecute(task, agentOpts, options) {
236
+ // Phase 1: Generate plan
237
+ printInfo('Analyzing task and generating plan...');
238
+ const plan = await generatePlan(task, agentOpts);
239
+ // Phase 2: Show plan and get approval
240
+ displayPlan(plan);
241
+ if (!options?.autoApprove) {
242
+ if (options?.onApproval) {
243
+ const approved = await options.onApproval(plan);
244
+ if (!approved) {
245
+ plan.status = 'failed';
246
+ printInfo('Plan rejected by user.');
247
+ return plan;
248
+ }
249
+ }
250
+ // If no approval callback, proceed (interactive mode handles this in CLI)
251
+ }
252
+ // Phase 3: Execute
253
+ const result = await executePlan(plan, agentOpts);
254
+ // Phase 4: Verify (type-check if applicable)
255
+ if (result.status === 'completed') {
256
+ const context = gatherContext();
257
+ if (context.language === 'TypeScript' || context.language === 'JavaScript') {
258
+ printInfo('Running verification...');
259
+ const verifyTool = getTool('bash');
260
+ if (verifyTool) {
261
+ try {
262
+ const verifyResult = await verifyTool.execute({ command: 'npx tsc --noEmit 2>&1 | head -20' });
263
+ if (verifyResult.includes('error TS')) {
264
+ printWarn('Type errors detected after plan execution:');
265
+ printInfo(verifyResult.split('\n').slice(0, 5).join('\n'));
266
+ }
267
+ else {
268
+ printSuccess('Verification passed — no type errors');
269
+ }
270
+ }
271
+ catch { /* non-fatal */ }
272
+ }
273
+ }
274
+ }
275
+ return result;
276
+ }
277
+ /**
278
+ * Format a plan summary for display after completion
279
+ */
280
+ export function formatPlanSummary(plan) {
281
+ const done = plan.steps.filter(s => s.status === 'done').length;
282
+ const failed = plan.steps.filter(s => s.status === 'failed').length;
283
+ const skipped = plan.steps.filter(s => s.status === 'skipped').length;
284
+ const lines = [
285
+ `Plan: ${plan.summary}`,
286
+ `Status: ${plan.status}`,
287
+ `Steps: ${done} done, ${failed} failed, ${skipped} skipped (${plan.steps.length} total)`,
288
+ '',
289
+ ];
290
+ for (const step of plan.steps) {
291
+ const icon = { done: '✓', failed: '✗', skipped: '○', pending: '·', running: '●' }[step.status];
292
+ lines.push(` ${icon} ${step.id}. ${step.description} [${step.status}]`);
293
+ if (step.error)
294
+ lines.push(` Error: ${step.error}`);
295
+ }
296
+ return lines.join('\n');
297
+ }
298
+ //# sourceMappingURL=planner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"planner.js","sourceRoot":"","sources":["../src/planner.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,EAAE;AACF,4EAA4E;AAC5E,gBAAgB;AAChB,qDAAqD;AACrD,6DAA6D;AAC7D,wDAAwD;AACxD,qDAAqD;AACrD,2DAA2D;AAC3D,EAAE;AACF,qEAAqE;AACrE,gDAAgD;AAEhD,OAAO,EAAE,QAAQ,EAAyC,MAAM,YAAY,CAAA;AAC5E,OAAO,EAAE,WAAW,EAAE,OAAO,EAAiB,MAAM,kBAAkB,CAAA;AACtE,OAAO,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAA;AAEpE,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AACvF,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,MAAM,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;AA8BrC,wBAAwB;AAExB,MAAM,kBAAkB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;+CA4BoB,CAAA;AAE/C;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,IAAY,EACZ,SAAuB;IAEvB,MAAM,OAAO,GAAG,aAAa,EAAE,CAAA;IAC/B,MAAM,UAAU,GAAG,sBAAsB,CAAC,OAAO,CAAC,CAAA;IAElD,MAAM,UAAU,GAAG,GAAG,kBAAkB;;;EAGxC,UAAU;;QAEJ,IAAI;;0BAEc,CAAA;IAExB,8EAA8E;IAC9E,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,UAAU,EAAE;QAC1C,GAAG,SAAS;QACZ,KAAK,EAAE,OAAO,EAAE,+BAA+B;KAChD,CAAC,CAAA;IAEF,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AAC,IAAI,CAAC,KAAK,IAAI,IAAI,IAAI,CAAC,EAAE,KAAK,IAAI,CAAC,WAAW,KAAK,IAAI,CAAC,MAAM,GAAG,CAAC,CAAA;QACxE,IAAI,IAAI,CAAC,KAAK;YAAE,KAAK,CAAC,IAAI,CAAC,eAAe,IAAI,CAAC,KAAK,EAAE,CAAC,CAAA;IACzD,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACzB,CAAC"}
@@ -0,0 +1,30 @@
1
+ export interface PluginDefinition {
2
+ name: string;
3
+ description: string;
4
+ parameters: Record<string, {
5
+ type: string;
6
+ description: string;
7
+ required?: boolean;
8
+ default?: unknown;
9
+ }>;
10
+ execute: (args: Record<string, unknown>) => Promise<string>;
11
+ tier?: 'free' | 'pro' | 'growth' | 'enterprise';
12
+ }
13
+ export interface PluginManifest {
14
+ name: string;
15
+ file: string;
16
+ toolCount: number;
17
+ loadedAt: string;
18
+ error?: string;
19
+ }
20
+ /** Ensure the plugins directory exists */
21
+ export declare function ensurePluginsDir(): string;
22
+ /** Load all plugins from ~/.kbot/plugins/ */
23
+ export declare function loadPlugins(verbose?: boolean): Promise<PluginManifest[]>;
24
+ /** List loaded plugins */
25
+ export declare function getLoadedPlugins(): PluginManifest[];
26
+ /** Format plugin list for display */
27
+ export declare function formatPluginList(): string;
28
+ /** Create a scaffold plugin file */
29
+ export declare function scaffoldPlugin(name: string): string;
30
+ //# sourceMappingURL=plugins.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugins.d.ts","sourceRoot":"","sources":["../src/plugins.ts"],"names":[],"mappings":"AAsBA,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE;QACzB,IAAI,EAAE,MAAM,CAAA;QACZ,WAAW,EAAE,MAAM,CAAA;QACnB,QAAQ,CAAC,EAAE,OAAO,CAAA;QAClB,OAAO,CAAC,EAAE,OAAO,CAAA;KAClB,CAAC,CAAA;IACF,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;IAC3D,IAAI,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,YAAY,CAAA;CAChD;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAID,0CAA0C;AAC1C,wBAAgB,gBAAgB,IAAI,MAAM,CAKzC;AAED,6CAA6C;AAC7C,wBAAsB,WAAW,CAAC,OAAO,UAAQ,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CA0D5E;AAED,0BAA0B;AAC1B,wBAAgB,gBAAgB,IAAI,cAAc,EAAE,CAEnD;AAED,qCAAqC;AACrC,wBAAgB,gBAAgB,IAAI,MAAM,CAyBzC;AAED,oCAAoC;AACpC,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CA8BnD"}
@@ -0,0 +1,135 @@
1
+ // K:BOT Plugin System — Drop-in tool extensions
2
+ //
3
+ // Users place .ts/.js files in ~/.kbot/plugins/ and they auto-register as tools.
4
+ // Each plugin exports a default PluginDefinition or an array of them.
5
+ //
6
+ // Example plugin (~/.kbot/plugins/hello.js):
7
+ // export default {
8
+ // name: 'hello',
9
+ // description: 'Say hello',
10
+ // parameters: { name: { type: 'string', description: 'Who to greet', required: true } },
11
+ // execute: async (args) => `Hello, ${args.name}!`,
12
+ // }
13
+ import { existsSync, readdirSync, mkdirSync, writeFileSync } from 'node:fs';
14
+ import { join } from 'node:path';
15
+ import { homedir } from 'node:os';
16
+ import { pathToFileURL } from 'node:url';
17
+ import { registerTool } from './tools/index.js';
18
+ const PLUGINS_DIR = join(homedir(), '.kbot', 'plugins');
19
+ const PLUGIN_EXTENSIONS = ['.js', '.mjs'];
20
+ const loadedPlugins = [];
21
+ /** Ensure the plugins directory exists */
22
+ export function ensurePluginsDir() {
23
+ if (!existsSync(PLUGINS_DIR)) {
24
+ mkdirSync(PLUGINS_DIR, { recursive: true });
25
+ }
26
+ return PLUGINS_DIR;
27
+ }
28
+ /** Load all plugins from ~/.kbot/plugins/ */
29
+ export async function loadPlugins(verbose = false) {
30
+ ensurePluginsDir();
31
+ const files = readdirSync(PLUGINS_DIR).filter(f => PLUGIN_EXTENSIONS.some(ext => f.endsWith(ext)));
32
+ if (files.length === 0)
33
+ return [];
34
+ for (const file of files) {
35
+ const filePath = join(PLUGINS_DIR, file);
36
+ const manifest = {
37
+ name: file.replace(/\.[^.]+$/, ''),
38
+ file,
39
+ toolCount: 0,
40
+ loadedAt: new Date().toISOString(),
41
+ };
42
+ try {
43
+ const fileUrl = pathToFileURL(filePath).href;
44
+ const mod = await import(fileUrl);
45
+ const definitions = [];
46
+ if (mod.default) {
47
+ if (Array.isArray(mod.default)) {
48
+ definitions.push(...mod.default);
49
+ }
50
+ else {
51
+ definitions.push(mod.default);
52
+ }
53
+ }
54
+ if (mod.tools && Array.isArray(mod.tools)) {
55
+ definitions.push(...mod.tools);
56
+ }
57
+ for (const def of definitions) {
58
+ if (!def.name || !def.execute)
59
+ continue;
60
+ const tool = {
61
+ name: `plugin_${def.name}`,
62
+ description: `[Plugin] ${def.description || def.name}`,
63
+ parameters: def.parameters || {},
64
+ tier: def.tier || 'free',
65
+ execute: def.execute,
66
+ };
67
+ registerTool(tool);
68
+ manifest.toolCount++;
69
+ }
70
+ }
71
+ catch (err) {
72
+ manifest.error = err instanceof Error ? err.message : String(err);
73
+ }
74
+ loadedPlugins.push(manifest);
75
+ }
76
+ return loadedPlugins;
77
+ }
78
+ /** List loaded plugins */
79
+ export function getLoadedPlugins() {
80
+ return loadedPlugins;
81
+ }
82
+ /** Format plugin list for display */
83
+ export function formatPluginList() {
84
+ if (loadedPlugins.length === 0) {
85
+ return [
86
+ 'No plugins loaded.',
87
+ '',
88
+ `Plugin directory: ${PLUGINS_DIR}`,
89
+ '',
90
+ 'Create a plugin:',
91
+ ` kbot /plugins create my-tool`,
92
+ '',
93
+ 'Or manually create a .js file in the plugins directory.',
94
+ ].join('\n');
95
+ }
96
+ const lines = [
97
+ `${loadedPlugins.length} plugin(s) loaded from ${PLUGINS_DIR}`,
98
+ '',
99
+ ];
100
+ for (const p of loadedPlugins) {
101
+ const status = p.error ? ` ✗ ${p.name} — ${p.error}` : ` ✓ ${p.name} (${p.toolCount} tools)`;
102
+ lines.push(status);
103
+ }
104
+ return lines.join('\n');
105
+ }
106
+ /** Create a scaffold plugin file */
107
+ export function scaffoldPlugin(name) {
108
+ ensurePluginsDir();
109
+ const filePath = join(PLUGINS_DIR, `${name}.js`);
110
+ if (existsSync(filePath)) {
111
+ return `Plugin already exists: ${filePath}`;
112
+ }
113
+ const content = `// K:BOT Plugin: ${name}
114
+ // This file is auto-loaded when kbot starts.
115
+
116
+ export default {
117
+ name: '${name}',
118
+ description: 'Description of what this tool does',
119
+ parameters: {
120
+ input: {
121
+ type: 'string',
122
+ description: 'The input to process',
123
+ required: true,
124
+ },
125
+ },
126
+ async execute(args) {
127
+ const input = String(args.input)
128
+ return \`Processed: \${input}\`
129
+ },
130
+ }
131
+ `;
132
+ writeFileSync(filePath, content, 'utf-8');
133
+ return `Plugin created: ${filePath}`;
134
+ }
135
+ //# sourceMappingURL=plugins.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugins.js","sourceRoot":"","sources":["../src/plugins.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,EAAE;AACF,iFAAiF;AACjF,sEAAsE;AACtE,EAAE;AACF,6CAA6C;AAC7C,qBAAqB;AACrB,qBAAqB;AACrB,gCAAgC;AAChC,6FAA6F;AAC7F,uDAAuD;AACvD,MAAM;AAEN,OAAO,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EAAE,CAAA;IAClB,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,EAAE,GAAG,IAAI,KAAK,CAAC,CAAA;IAEhD,IAAI,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QACzB,OAAO,0BAA0B,QAAQ,EAAE,CAAA;IAC7C,CAAC;IAED,MAAM,OAAO,GAAG,oBAAoB,IAAI;;;;WAI/B,IAAI;;;;;;;;;;;;;;CAcd,CAAA;IAEC,aAAa,CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IACzC,OAAO,mBAAmB,QAAQ,EAAE,CAAA;AACtC,CAAC"}
@@ -0,0 +1,38 @@
1
+ import { type ConversationTurn } from './memory.js';
2
+ export interface Session {
3
+ /** Unique session ID */
4
+ id: string;
5
+ /** Human-readable name */
6
+ name: string;
7
+ /** When the session was created */
8
+ created: string;
9
+ /** When it was last updated */
10
+ updated: string;
11
+ /** Working directory when session was created */
12
+ cwd: string;
13
+ /** Number of turns in the conversation */
14
+ turnCount: number;
15
+ /** First user message (for preview) */
16
+ preview: string;
17
+ /** The conversation history */
18
+ history: ConversationTurn[];
19
+ /** Agent that was active */
20
+ agent?: string;
21
+ /** Any context notes */
22
+ notes?: string;
23
+ }
24
+ /** Save the current conversation as a session */
25
+ export declare function saveSession(name?: string, agent?: string): Session;
26
+ /** Load a session by ID or name */
27
+ export declare function loadSession(idOrName: string): Session | null;
28
+ /** List all saved sessions, newest first */
29
+ export declare function listSessions(): Session[];
30
+ /** Delete a session */
31
+ export declare function deleteSession(idOrName: string): boolean;
32
+ /** Update an existing session with current history */
33
+ export declare function updateSession(id: string, agent?: string): Session | null;
34
+ /** Get the most recent session for auto-resume */
35
+ export declare function getLastSession(): Session | null;
36
+ /** Format session list for display */
37
+ export declare function formatSessionList(sessions: Session[]): string;
38
+ //# sourceMappingURL=sessions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sessions.d.ts","sourceRoot":"","sources":["../src/sessions.ts"],"names":[],"m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