@shareai-lab/kode-sdk 1.0.0-beta.8 → 2.7.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 (193) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +115 -273
  3. package/README.zh-CN.md +114 -0
  4. package/dist/core/agent/breakpoint-manager.d.ts +16 -0
  5. package/dist/core/agent/breakpoint-manager.js +36 -0
  6. package/dist/core/agent/message-queue.d.ts +26 -0
  7. package/dist/core/agent/message-queue.js +57 -0
  8. package/dist/core/agent/permission-manager.d.ts +9 -0
  9. package/dist/core/agent/permission-manager.js +32 -0
  10. package/dist/core/agent/todo-manager.d.ts +26 -0
  11. package/dist/core/agent/todo-manager.js +91 -0
  12. package/dist/core/agent/tool-runner.d.ts +9 -0
  13. package/dist/core/agent/tool-runner.js +45 -0
  14. package/dist/core/agent.d.ts +228 -62
  15. package/dist/core/agent.js +1890 -615
  16. package/dist/core/config.d.ts +10 -0
  17. package/dist/core/config.js +2 -0
  18. package/dist/core/context-manager.d.ts +82 -0
  19. package/dist/core/context-manager.js +241 -0
  20. package/dist/core/errors.d.ts +22 -0
  21. package/dist/core/errors.js +49 -0
  22. package/dist/core/events.d.ts +41 -10
  23. package/dist/core/events.js +270 -68
  24. package/dist/core/file-pool.d.ts +41 -0
  25. package/dist/core/file-pool.js +102 -0
  26. package/dist/core/hooks.d.ts +3 -3
  27. package/dist/core/hooks.js +1 -1
  28. package/dist/core/permission-modes.d.ts +31 -0
  29. package/dist/core/permission-modes.js +61 -0
  30. package/dist/core/pool.d.ts +56 -13
  31. package/dist/core/pool.js +244 -34
  32. package/dist/core/room.d.ts +2 -2
  33. package/dist/core/room.js +10 -10
  34. package/dist/core/scheduler.d.ts +30 -23
  35. package/dist/core/scheduler.js +42 -168
  36. package/dist/core/skills/index.d.ts +10 -0
  37. package/dist/core/skills/index.js +20 -0
  38. package/dist/core/skills/management-manager.d.ts +130 -0
  39. package/dist/core/skills/management-manager.js +557 -0
  40. package/dist/core/skills/manager.d.ts +47 -0
  41. package/dist/core/skills/manager.js +243 -0
  42. package/dist/core/skills/operation-queue.d.ts +87 -0
  43. package/dist/core/skills/operation-queue.js +113 -0
  44. package/dist/core/skills/sandbox-file-manager.d.ts +82 -0
  45. package/dist/core/skills/sandbox-file-manager.js +183 -0
  46. package/dist/core/skills/types.d.ts +120 -0
  47. package/dist/core/skills/types.js +9 -0
  48. package/dist/core/skills/xml-generator.d.ts +13 -0
  49. package/dist/core/skills/xml-generator.js +70 -0
  50. package/dist/core/template.d.ts +57 -0
  51. package/dist/core/template.js +35 -0
  52. package/dist/core/time-bridge.d.ts +18 -0
  53. package/dist/core/time-bridge.js +100 -0
  54. package/dist/core/todo.d.ts +34 -0
  55. package/dist/core/todo.js +89 -0
  56. package/dist/core/types.d.ts +311 -114
  57. package/dist/core/types.js +1 -12
  58. package/dist/index.d.ts +47 -9
  59. package/dist/index.js +108 -15
  60. package/dist/infra/db/postgres/postgres-store.d.ts +97 -0
  61. package/dist/infra/db/postgres/postgres-store.js +1073 -0
  62. package/dist/infra/db/sqlite/sqlite-store.d.ts +84 -0
  63. package/dist/infra/db/sqlite/sqlite-store.js +800 -0
  64. package/dist/infra/e2b/e2b-fs.d.ts +29 -0
  65. package/dist/infra/e2b/e2b-fs.js +128 -0
  66. package/dist/infra/e2b/e2b-sandbox.d.ts +37 -0
  67. package/dist/infra/e2b/e2b-sandbox.js +156 -0
  68. package/dist/infra/e2b/e2b-template.d.ts +24 -0
  69. package/dist/infra/e2b/e2b-template.js +105 -0
  70. package/dist/infra/e2b/index.d.ts +4 -0
  71. package/dist/infra/e2b/index.js +9 -0
  72. package/dist/infra/e2b/types.d.ts +46 -0
  73. package/dist/infra/e2b/types.js +2 -0
  74. package/dist/infra/provider.d.ts +17 -58
  75. package/dist/infra/provider.js +65 -116
  76. package/dist/infra/providers/anthropic.d.ts +42 -0
  77. package/dist/infra/providers/anthropic.js +308 -0
  78. package/dist/infra/providers/core/errors.d.ts +230 -0
  79. package/dist/infra/providers/core/errors.js +353 -0
  80. package/dist/infra/providers/core/fork.d.ts +106 -0
  81. package/dist/infra/providers/core/fork.js +418 -0
  82. package/dist/infra/providers/core/index.d.ts +10 -0
  83. package/dist/infra/providers/core/index.js +76 -0
  84. package/dist/infra/providers/core/logger.d.ts +186 -0
  85. package/dist/infra/providers/core/logger.js +191 -0
  86. package/dist/infra/providers/core/retry.d.ts +62 -0
  87. package/dist/infra/providers/core/retry.js +189 -0
  88. package/dist/infra/providers/core/usage.d.ts +151 -0
  89. package/dist/infra/providers/core/usage.js +376 -0
  90. package/dist/infra/providers/gemini.d.ts +49 -0
  91. package/dist/infra/providers/gemini.js +493 -0
  92. package/dist/infra/providers/index.d.ts +25 -0
  93. package/dist/infra/providers/index.js +83 -0
  94. package/dist/infra/providers/openai.d.ts +123 -0
  95. package/dist/infra/providers/openai.js +662 -0
  96. package/dist/infra/providers/types.d.ts +334 -0
  97. package/dist/infra/providers/types.js +20 -0
  98. package/dist/infra/providers/utils.d.ts +53 -0
  99. package/dist/infra/providers/utils.js +400 -0
  100. package/dist/infra/sandbox-factory.d.ts +13 -0
  101. package/dist/infra/sandbox-factory.js +30 -0
  102. package/dist/infra/sandbox.d.ts +35 -6
  103. package/dist/infra/sandbox.js +174 -8
  104. package/dist/infra/store/factory.d.ts +45 -0
  105. package/dist/infra/store/factory.js +80 -0
  106. package/dist/infra/store/index.d.ts +3 -0
  107. package/dist/infra/store/index.js +26 -0
  108. package/dist/infra/store/json-store.d.ts +67 -0
  109. package/dist/infra/store/json-store.js +606 -0
  110. package/dist/infra/store/types.d.ts +342 -0
  111. package/dist/infra/store/types.js +2 -0
  112. package/dist/infra/store.d.ts +12 -32
  113. package/dist/infra/store.js +27 -130
  114. package/dist/tools/bash_kill/index.d.ts +1 -0
  115. package/dist/tools/bash_kill/index.js +35 -0
  116. package/dist/tools/bash_kill/prompt.d.ts +2 -0
  117. package/dist/tools/bash_kill/prompt.js +14 -0
  118. package/dist/tools/bash_logs/index.d.ts +1 -0
  119. package/dist/tools/bash_logs/index.js +40 -0
  120. package/dist/tools/bash_logs/prompt.d.ts +2 -0
  121. package/dist/tools/bash_logs/prompt.js +14 -0
  122. package/dist/tools/bash_run/index.d.ts +16 -0
  123. package/dist/tools/bash_run/index.js +61 -0
  124. package/dist/tools/bash_run/prompt.d.ts +2 -0
  125. package/dist/tools/bash_run/prompt.js +18 -0
  126. package/dist/tools/builtin.d.ts +7 -13
  127. package/dist/tools/builtin.js +19 -90
  128. package/dist/tools/define.d.ts +101 -0
  129. package/dist/tools/define.js +214 -0
  130. package/dist/tools/fs_edit/index.d.ts +1 -0
  131. package/dist/tools/fs_edit/index.js +62 -0
  132. package/dist/tools/fs_edit/prompt.d.ts +2 -0
  133. package/dist/tools/fs_edit/prompt.js +15 -0
  134. package/dist/tools/fs_glob/index.d.ts +1 -0
  135. package/dist/tools/fs_glob/index.js +40 -0
  136. package/dist/tools/fs_glob/prompt.d.ts +2 -0
  137. package/dist/tools/fs_glob/prompt.js +15 -0
  138. package/dist/tools/fs_grep/index.d.ts +1 -0
  139. package/dist/tools/fs_grep/index.js +66 -0
  140. package/dist/tools/fs_grep/prompt.d.ts +2 -0
  141. package/dist/tools/fs_grep/prompt.js +16 -0
  142. package/dist/tools/fs_multi_edit/index.d.ts +1 -0
  143. package/dist/tools/fs_multi_edit/index.js +106 -0
  144. package/dist/tools/fs_multi_edit/prompt.d.ts +2 -0
  145. package/dist/tools/fs_multi_edit/prompt.js +16 -0
  146. package/dist/tools/fs_read/index.d.ts +1 -0
  147. package/dist/tools/fs_read/index.js +40 -0
  148. package/dist/tools/fs_read/prompt.d.ts +2 -0
  149. package/dist/tools/fs_read/prompt.js +16 -0
  150. package/dist/tools/fs_write/index.d.ts +1 -0
  151. package/dist/tools/fs_write/index.js +40 -0
  152. package/dist/tools/fs_write/prompt.d.ts +2 -0
  153. package/dist/tools/fs_write/prompt.js +15 -0
  154. package/dist/tools/index.d.ts +11 -0
  155. package/dist/tools/index.js +61 -0
  156. package/dist/tools/mcp.d.ts +69 -0
  157. package/dist/tools/mcp.js +185 -0
  158. package/dist/tools/registry.d.ts +29 -0
  159. package/dist/tools/registry.js +26 -0
  160. package/dist/tools/scripts.d.ts +22 -0
  161. package/dist/tools/scripts.js +205 -0
  162. package/dist/tools/skills.d.ts +20 -0
  163. package/dist/tools/skills.js +115 -0
  164. package/dist/tools/task_run/index.d.ts +7 -0
  165. package/dist/tools/task_run/index.js +58 -0
  166. package/dist/tools/task_run/prompt.d.ts +5 -0
  167. package/dist/tools/task_run/prompt.js +25 -0
  168. package/dist/tools/todo_read/index.d.ts +1 -0
  169. package/dist/tools/todo_read/index.js +29 -0
  170. package/dist/tools/todo_read/prompt.d.ts +2 -0
  171. package/dist/tools/todo_read/prompt.js +18 -0
  172. package/dist/tools/todo_write/index.d.ts +1 -0
  173. package/dist/tools/todo_write/index.js +42 -0
  174. package/dist/tools/todo_write/prompt.d.ts +2 -0
  175. package/dist/tools/todo_write/prompt.js +23 -0
  176. package/dist/tools/tool.d.ts +43 -0
  177. package/dist/tools/tool.js +211 -0
  178. package/dist/tools/toolkit.d.ts +69 -0
  179. package/dist/tools/toolkit.js +98 -0
  180. package/dist/tools/type-inference.d.ts +127 -0
  181. package/dist/tools/type-inference.js +207 -0
  182. package/dist/utils/agent-id.d.ts +1 -0
  183. package/dist/utils/agent-id.js +28 -0
  184. package/dist/utils/logger.d.ts +15 -0
  185. package/dist/utils/logger.js +44 -0
  186. package/dist/utils/session-id.js +16 -16
  187. package/package.json +35 -11
  188. package/dist/tools/bash.d.ts +0 -63
  189. package/dist/tools/bash.js +0 -92
  190. package/dist/tools/fs.d.ts +0 -96
  191. package/dist/tools/fs.js +0 -100
  192. package/dist/tools/task.d.ts +0 -38
  193. package/dist/tools/task.js +0 -45
@@ -1,92 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BashKill = exports.BashLogs = exports.BashRun = void 0;
4
- const processes = new Map();
5
- class BashRun {
6
- constructor() {
7
- this.name = 'bash_run';
8
- this.description = 'Execute a bash command';
9
- this.input_schema = {
10
- type: 'object',
11
- properties: {
12
- cmd: { type: 'string', description: 'Command to execute' },
13
- timeout_ms: { type: 'number', description: 'Timeout in milliseconds (default: 120000)' },
14
- background: { type: 'boolean', description: 'Run in background and return shell_id' },
15
- },
16
- required: ['cmd'],
17
- };
18
- }
19
- async exec(args, ctx) {
20
- if (args.background) {
21
- const id = `shell-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
22
- const promise = ctx.sandbox.exec(args.cmd, { timeoutMs: args.timeout_ms });
23
- const proc = {
24
- id,
25
- cmd: args.cmd,
26
- startTime: Date.now(),
27
- promise,
28
- stdout: '',
29
- stderr: '',
30
- };
31
- processes.set(id, proc);
32
- promise.then((result) => {
33
- proc.code = result.code;
34
- proc.stdout = result.stdout;
35
- proc.stderr = result.stderr;
36
- });
37
- return `Background shell started: ${id}`;
38
- }
39
- else {
40
- const result = await ctx.sandbox.exec(args.cmd, { timeoutMs: args.timeout_ms });
41
- const output = [result.stdout, result.stderr].filter(Boolean).join('\n').trim();
42
- return output || '(no output)';
43
- }
44
- }
45
- }
46
- exports.BashRun = BashRun;
47
- class BashLogs {
48
- constructor() {
49
- this.name = 'bash_logs';
50
- this.description = 'Get output from a background bash shell';
51
- this.input_schema = {
52
- type: 'object',
53
- properties: {
54
- shell_id: { type: 'string', description: 'Shell ID from bash_run' },
55
- },
56
- required: ['shell_id'],
57
- };
58
- }
59
- async exec(args, ctx) {
60
- const proc = processes.get(args.shell_id);
61
- if (!proc) {
62
- throw new Error(`Shell not found: ${args.shell_id}`);
63
- }
64
- const isRunning = proc.code === undefined;
65
- const status = isRunning ? 'running' : `completed (exit code ${proc.code})`;
66
- const output = [proc.stdout, proc.stderr].filter(Boolean).join('\n').trim();
67
- return `Shell ${args.shell_id}: ${status}\n${output || '(no output yet)'}`;
68
- }
69
- }
70
- exports.BashLogs = BashLogs;
71
- class BashKill {
72
- constructor() {
73
- this.name = 'bash_kill';
74
- this.description = 'Kill a background bash shell';
75
- this.input_schema = {
76
- type: 'object',
77
- properties: {
78
- shell_id: { type: 'string', description: 'Shell ID from Bash.Run' },
79
- },
80
- required: ['shell_id'],
81
- };
82
- }
83
- async exec(args, ctx) {
84
- const proc = processes.get(args.shell_id);
85
- if (!proc) {
86
- throw new Error(`Shell not found: ${args.shell_id}`);
87
- }
88
- processes.delete(args.shell_id);
89
- return `Killed shell ${args.shell_id}`;
90
- }
91
- }
92
- exports.BashKill = BashKill;
@@ -1,96 +0,0 @@
1
- import { ToolContext, ToolOutcome, HookDecision, PostHookResult } from '../core/types';
2
- import { Hooks } from '../core/hooks';
3
- export interface Tool {
4
- name: string;
5
- description: string;
6
- input_schema: any;
7
- exec(args: any, ctx: ToolContext): Promise<any>;
8
- hooks?: Hooks;
9
- permissionDetails?: (call: any, ctx: ToolContext) => any;
10
- }
11
- export declare class FsRead implements Tool {
12
- name: string;
13
- description: string;
14
- input_schema: {
15
- type: string;
16
- properties: {
17
- file: {
18
- type: string;
19
- description: string;
20
- };
21
- offset: {
22
- type: string;
23
- description: string;
24
- };
25
- limit: {
26
- type: string;
27
- description: string;
28
- };
29
- };
30
- required: string[];
31
- };
32
- exec(args: {
33
- file: string;
34
- offset?: number;
35
- limit?: number;
36
- }, ctx: ToolContext): Promise<any>;
37
- }
38
- export declare class FsWrite implements Tool {
39
- name: string;
40
- description: string;
41
- input_schema: {
42
- type: string;
43
- properties: {
44
- file: {
45
- type: string;
46
- description: string;
47
- };
48
- content: {
49
- type: string;
50
- description: string;
51
- };
52
- };
53
- required: string[];
54
- };
55
- exec(args: {
56
- file: string;
57
- content: string;
58
- }, ctx: ToolContext): Promise<any>;
59
- }
60
- export declare class FsEdit implements Tool {
61
- name: string;
62
- description: string;
63
- input_schema: {
64
- type: string;
65
- properties: {
66
- file: {
67
- type: string;
68
- description: string;
69
- };
70
- old_string: {
71
- type: string;
72
- description: string;
73
- };
74
- new_string: {
75
- type: string;
76
- description: string;
77
- };
78
- replace_all: {
79
- type: string;
80
- description: string;
81
- };
82
- };
83
- required: string[];
84
- };
85
- exec(args: {
86
- file: string;
87
- old_string: string;
88
- new_string: string;
89
- replace_all?: boolean;
90
- }, ctx: ToolContext): Promise<any>;
91
- }
92
- export declare function toolTune(tool: Tool, hooks: {
93
- preToolUse?: (call: any, ctx: ToolContext) => HookDecision | Promise<HookDecision>;
94
- postToolUse?: (outcome: ToolOutcome, ctx: ToolContext) => PostHookResult | Promise<PostHookResult>;
95
- permissionDetails?: (call: any, ctx: ToolContext) => any;
96
- }): Tool;
package/dist/tools/fs.js DELETED
@@ -1,100 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FsEdit = exports.FsWrite = exports.FsRead = void 0;
4
- exports.toolTune = toolTune;
5
- class FsRead {
6
- constructor() {
7
- this.name = 'fs_read';
8
- this.description = 'Read contents from a file';
9
- this.input_schema = {
10
- type: 'object',
11
- properties: {
12
- file: { type: 'string', description: 'Path to file' },
13
- offset: { type: 'number', description: 'Line offset (optional)' },
14
- limit: { type: 'number', description: 'Max lines to read (optional)' },
15
- },
16
- required: ['file'],
17
- };
18
- }
19
- async exec(args, ctx) {
20
- const content = await ctx.sandbox.fs.read(args.file);
21
- const lines = content.split('\n');
22
- const offset = args.offset || 0;
23
- const limit = args.limit || lines.length;
24
- const selected = lines.slice(offset, offset + limit);
25
- return selected.join('\n');
26
- }
27
- }
28
- exports.FsRead = FsRead;
29
- class FsWrite {
30
- constructor() {
31
- this.name = 'fs_write';
32
- this.description = 'Write contents to a file (creates or overwrites)';
33
- this.input_schema = {
34
- type: 'object',
35
- properties: {
36
- file: { type: 'string', description: 'Path to file' },
37
- content: { type: 'string', description: 'Content to write' },
38
- },
39
- required: ['file', 'content'],
40
- };
41
- }
42
- async exec(args, ctx) {
43
- await ctx.sandbox.fs.write(args.file, args.content);
44
- const bytes = Buffer.byteLength(args.content, 'utf8');
45
- return `Wrote ${bytes} bytes to ${args.file}`;
46
- }
47
- }
48
- exports.FsWrite = FsWrite;
49
- class FsEdit {
50
- constructor() {
51
- this.name = 'fs_edit';
52
- this.description = 'Edit a file by replacing old_string with new_string';
53
- this.input_schema = {
54
- type: 'object',
55
- properties: {
56
- file: { type: 'string', description: 'Path to file' },
57
- old_string: { type: 'string', description: 'String to replace' },
58
- new_string: { type: 'string', description: 'Replacement string' },
59
- replace_all: { type: 'boolean', description: 'Replace all occurrences (default: false)' },
60
- },
61
- required: ['file', 'old_string', 'new_string'],
62
- };
63
- }
64
- async exec(args, ctx) {
65
- const content = await ctx.sandbox.fs.read(args.file);
66
- if (args.replace_all) {
67
- const updated = content.split(args.old_string).join(args.new_string);
68
- await ctx.sandbox.fs.write(args.file, updated);
69
- const count = content.split(args.old_string).length - 1;
70
- return `Replaced ${count} occurrence(s) in ${args.file}`;
71
- }
72
- else {
73
- const occurrences = content.split(args.old_string).length - 1;
74
- if (occurrences === 0) {
75
- throw new Error(`old_string not found in ${args.file}`);
76
- }
77
- if (occurrences > 1) {
78
- throw new Error(`old_string appears ${occurrences} times; use replace_all=true or provide unique string`);
79
- }
80
- const updated = content.replace(args.old_string, args.new_string);
81
- await ctx.sandbox.fs.write(args.file, updated);
82
- return `Replaced 1 occurrence in ${args.file}`;
83
- }
84
- }
85
- }
86
- exports.FsEdit = FsEdit;
87
- function toolTune(tool, hooks) {
88
- return {
89
- name: tool.name,
90
- description: tool.description,
91
- input_schema: tool.input_schema,
92
- exec: tool.exec.bind(tool),
93
- hooks: {
94
- ...tool.hooks,
95
- preToolUse: hooks.preToolUse,
96
- postToolUse: hooks.postToolUse,
97
- },
98
- permissionDetails: hooks.permissionDetails || tool.permissionDetails,
99
- };
100
- }
@@ -1,38 +0,0 @@
1
- import { ToolContext } from '../core/types';
2
- import { Tool } from './fs';
3
- export interface AgentTemplate {
4
- id: string;
5
- system?: string;
6
- tools?: Tool[];
7
- whenToUse?: string;
8
- }
9
- export declare class TaskRun implements Tool {
10
- private subAgents;
11
- name: string;
12
- description: string;
13
- input_schema: {
14
- type: string;
15
- properties: {
16
- task: {
17
- type: string;
18
- description: string;
19
- };
20
- with: {
21
- type: string;
22
- description: string;
23
- };
24
- context: {
25
- type: string;
26
- description: string;
27
- };
28
- };
29
- required: string[];
30
- };
31
- constructor(subAgents: AgentTemplate[]);
32
- exec(args: {
33
- task: string;
34
- with?: string;
35
- context?: string;
36
- }, ctx: ToolContext): Promise<any>;
37
- private selectTemplate;
38
- }
@@ -1,45 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TaskRun = void 0;
4
- class TaskRun {
5
- constructor(subAgents) {
6
- this.subAgents = subAgents;
7
- this.name = 'task_run';
8
- this.description = 'Delegate a task to a sub-agent';
9
- this.input_schema = {
10
- type: 'object',
11
- properties: {
12
- task: { type: 'string', description: 'Task description for the sub-agent' },
13
- with: { type: 'string', description: 'Template ID to use (optional, will auto-select if omitted)' },
14
- context: { type: 'string', description: 'Additional context (optional)' },
15
- },
16
- required: ['task'],
17
- };
18
- }
19
- async exec(args, ctx) {
20
- // This will be implemented when Agent class is ready
21
- // For now, return a placeholder
22
- const template = args.with
23
- ? this.subAgents.find((t) => t.id === args.with)
24
- : this.selectTemplate(args.task);
25
- if (!template) {
26
- throw new Error(`Template not found: ${args.with || 'auto'}`);
27
- }
28
- return {
29
- status: 'delegated',
30
- template: template.id,
31
- task: args.task,
32
- note: 'Sub-agent execution will be implemented in Agent class',
33
- };
34
- }
35
- selectTemplate(task) {
36
- // Simple heuristic selection based on whenToUse hints
37
- for (const template of this.subAgents) {
38
- if (template.whenToUse && task.toLowerCase().includes(template.whenToUse.toLowerCase())) {
39
- return template;
40
- }
41
- }
42
- return this.subAgents[0];
43
- }
44
- }
45
- exports.TaskRun = TaskRun;