@shareai-lab/kode-sdk 2.7.1 → 2.7.2
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/dist/core/agent/breakpoint-manager.js +36 -0
- package/dist/core/agent/message-queue.js +57 -0
- package/dist/core/agent/permission-manager.js +32 -0
- package/dist/core/agent/todo-manager.js +91 -0
- package/dist/core/agent/tool-runner.js +45 -0
- package/dist/core/agent.js +2035 -0
- package/dist/core/config.js +2 -0
- package/dist/core/context-manager.js +241 -0
- package/dist/core/errors.js +49 -0
- package/dist/core/events.js +329 -0
- package/dist/core/file-pool.d.ts +2 -0
- package/dist/core/file-pool.js +125 -0
- package/dist/core/hooks.js +71 -0
- package/dist/core/permission-modes.js +61 -0
- package/dist/core/pool.js +301 -0
- package/dist/core/room.js +57 -0
- package/dist/core/scheduler.js +58 -0
- package/dist/core/skills/index.js +20 -0
- package/dist/core/skills/management-manager.js +557 -0
- package/dist/core/skills/manager.js +243 -0
- package/dist/core/skills/operation-queue.js +113 -0
- package/dist/core/skills/sandbox-file-manager.js +183 -0
- package/dist/core/skills/types.js +9 -0
- package/dist/core/skills/xml-generator.js +70 -0
- package/dist/core/template.js +35 -0
- package/dist/core/time-bridge.js +100 -0
- package/dist/core/todo.js +89 -0
- package/dist/core/types.js +3 -0
- package/dist/index.js +148 -60461
- package/dist/infra/db/postgres/postgres-store.js +1073 -0
- package/dist/infra/db/sqlite/sqlite-store.js +800 -0
- package/dist/infra/e2b/e2b-fs.js +128 -0
- package/dist/infra/e2b/e2b-sandbox.js +156 -0
- package/dist/infra/e2b/e2b-template.js +105 -0
- package/dist/infra/e2b/index.js +9 -0
- package/dist/infra/e2b/types.js +2 -0
- package/dist/infra/provider.js +67 -0
- package/dist/infra/providers/anthropic.js +308 -0
- package/dist/infra/providers/core/errors.js +353 -0
- package/dist/infra/providers/core/fork.js +418 -0
- package/dist/infra/providers/core/index.js +76 -0
- package/dist/infra/providers/core/logger.js +191 -0
- package/dist/infra/providers/core/retry.js +189 -0
- package/dist/infra/providers/core/usage.js +376 -0
- package/dist/infra/providers/gemini.js +493 -0
- package/dist/infra/providers/index.js +83 -0
- package/dist/infra/providers/openai.js +662 -0
- package/dist/infra/providers/types.js +20 -0
- package/dist/infra/providers/utils.js +400 -0
- package/dist/infra/sandbox-factory.js +30 -0
- package/dist/infra/sandbox.js +243 -0
- package/dist/infra/store/factory.js +80 -0
- package/dist/infra/store/index.js +26 -0
- package/dist/infra/store/json-store.js +606 -0
- package/dist/infra/store/types.js +2 -0
- package/dist/infra/store.js +29 -0
- package/dist/tools/bash_kill/index.js +35 -0
- package/dist/tools/bash_kill/prompt.js +14 -0
- package/dist/tools/bash_logs/index.js +40 -0
- package/dist/tools/bash_logs/prompt.js +14 -0
- package/dist/tools/bash_run/index.js +61 -0
- package/dist/tools/bash_run/prompt.js +18 -0
- package/dist/tools/builtin.js +26 -0
- package/dist/tools/define.js +214 -0
- package/dist/tools/fs_edit/index.js +62 -0
- package/dist/tools/fs_edit/prompt.js +15 -0
- package/dist/tools/fs_glob/index.js +40 -0
- package/dist/tools/fs_glob/prompt.js +15 -0
- package/dist/tools/fs_grep/index.js +66 -0
- package/dist/tools/fs_grep/prompt.js +16 -0
- package/dist/tools/fs_multi_edit/index.js +106 -0
- package/dist/tools/fs_multi_edit/prompt.js +16 -0
- package/dist/tools/fs_read/index.js +40 -0
- package/dist/tools/fs_read/prompt.js +16 -0
- package/dist/tools/fs_write/index.js +40 -0
- package/dist/tools/fs_write/prompt.js +15 -0
- package/dist/tools/index.js +61 -0
- package/dist/tools/mcp.js +185 -0
- package/dist/tools/registry.js +26 -0
- package/dist/tools/scripts.js +205 -0
- package/dist/tools/skills.js +115 -0
- package/dist/tools/task_run/index.js +58 -0
- package/dist/tools/task_run/prompt.js +25 -0
- package/dist/tools/todo_read/index.js +29 -0
- package/dist/tools/todo_read/prompt.js +18 -0
- package/dist/tools/todo_write/index.js +42 -0
- package/dist/tools/todo_write/prompt.js +23 -0
- package/dist/tools/tool.js +211 -0
- package/dist/tools/toolkit.js +98 -0
- package/dist/tools/type-inference.js +207 -0
- package/dist/utils/agent-id.js +28 -0
- package/dist/utils/logger.js +44 -0
- package/dist/utils/session-id.js +64 -0
- package/package.json +7 -38
- package/dist/index.js.map +0 -7
- package/dist/index.mjs +0 -60385
- package/dist/index.mjs.map +0 -7
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TimeBridge = void 0;
|
|
4
|
+
class TimeBridge {
|
|
5
|
+
constructor(opts) {
|
|
6
|
+
this.timers = new Map();
|
|
7
|
+
this.scheduler = opts.scheduler;
|
|
8
|
+
this.driftTolerance = opts.driftToleranceMs ?? 5000;
|
|
9
|
+
this.logger = opts.logger;
|
|
10
|
+
}
|
|
11
|
+
everyMinutes(minutes, callback) {
|
|
12
|
+
if (!Number.isFinite(minutes) || minutes <= 0) {
|
|
13
|
+
throw new Error('everyMinutes: interval must be positive');
|
|
14
|
+
}
|
|
15
|
+
const interval = minutes * 60 * 1000;
|
|
16
|
+
const id = this.generateId('minutes');
|
|
17
|
+
const scheduleNext = () => {
|
|
18
|
+
const due = Date.now() + interval;
|
|
19
|
+
const handle = setTimeout(() => tick(due), interval);
|
|
20
|
+
entry.cancel = () => clearTimeout(handle);
|
|
21
|
+
};
|
|
22
|
+
const spec = `every:${minutes}m`;
|
|
23
|
+
const tick = (due) => {
|
|
24
|
+
this.scheduler.enqueue(async () => {
|
|
25
|
+
const drift = Math.abs(Date.now() - due);
|
|
26
|
+
if (drift > this.driftTolerance) {
|
|
27
|
+
this.logger?.('timebridge:drift', { id, drift, expectedInterval: interval });
|
|
28
|
+
}
|
|
29
|
+
await callback();
|
|
30
|
+
this.scheduler.notifyExternalTrigger({ taskId: id, spec, kind: 'time' });
|
|
31
|
+
});
|
|
32
|
+
scheduleNext();
|
|
33
|
+
};
|
|
34
|
+
const entry = {
|
|
35
|
+
id,
|
|
36
|
+
cancel: () => undefined,
|
|
37
|
+
};
|
|
38
|
+
this.timers.set(id, entry);
|
|
39
|
+
scheduleNext();
|
|
40
|
+
return id;
|
|
41
|
+
}
|
|
42
|
+
cron(expr, callback) {
|
|
43
|
+
const parts = expr.trim().split(/\s+/);
|
|
44
|
+
if (parts.length !== 5) {
|
|
45
|
+
throw new Error(`Unsupported cron expression: ${expr}`);
|
|
46
|
+
}
|
|
47
|
+
const minute = Number(parts[0]);
|
|
48
|
+
const hour = Number(parts[1]);
|
|
49
|
+
if (!Number.isInteger(minute) || !Number.isInteger(hour)) {
|
|
50
|
+
throw new Error(`Cron expression must be numeric minutes/hours: ${expr}`);
|
|
51
|
+
}
|
|
52
|
+
const id = this.generateId('cron');
|
|
53
|
+
const scheduleNext = () => {
|
|
54
|
+
const now = new Date();
|
|
55
|
+
const next = new Date(now.getFullYear(), now.getMonth(), now.getDate(), hour, minute, 0, 0);
|
|
56
|
+
if (next <= now) {
|
|
57
|
+
next.setDate(next.getDate() + 1);
|
|
58
|
+
}
|
|
59
|
+
const due = next.getTime();
|
|
60
|
+
const delay = Math.max(0, due - Date.now());
|
|
61
|
+
const handle = setTimeout(() => tick(due), delay);
|
|
62
|
+
entry.cancel = () => clearTimeout(handle);
|
|
63
|
+
};
|
|
64
|
+
const tick = (due) => {
|
|
65
|
+
this.scheduler.enqueue(async () => {
|
|
66
|
+
const drift = Math.abs(Date.now() - due);
|
|
67
|
+
if (drift > this.driftTolerance) {
|
|
68
|
+
this.logger?.('timebridge:drift', { id, drift, spec: expr });
|
|
69
|
+
}
|
|
70
|
+
await callback();
|
|
71
|
+
this.scheduler.notifyExternalTrigger({ taskId: id, spec: expr, kind: 'cron' });
|
|
72
|
+
});
|
|
73
|
+
scheduleNext();
|
|
74
|
+
};
|
|
75
|
+
const entry = {
|
|
76
|
+
id,
|
|
77
|
+
cancel: () => undefined,
|
|
78
|
+
};
|
|
79
|
+
this.timers.set(id, entry);
|
|
80
|
+
scheduleNext();
|
|
81
|
+
return id;
|
|
82
|
+
}
|
|
83
|
+
stop(timerId) {
|
|
84
|
+
const entry = this.timers.get(timerId);
|
|
85
|
+
if (!entry)
|
|
86
|
+
return;
|
|
87
|
+
entry.cancel();
|
|
88
|
+
this.timers.delete(timerId);
|
|
89
|
+
}
|
|
90
|
+
dispose() {
|
|
91
|
+
for (const entry of this.timers.values()) {
|
|
92
|
+
entry.cancel();
|
|
93
|
+
}
|
|
94
|
+
this.timers.clear();
|
|
95
|
+
}
|
|
96
|
+
generateId(prefix) {
|
|
97
|
+
return `${prefix}-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.TimeBridge = TimeBridge;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TodoService = void 0;
|
|
4
|
+
const MAX_IN_PROGRESS = 1;
|
|
5
|
+
class TodoService {
|
|
6
|
+
constructor(store, agentId) {
|
|
7
|
+
this.store = store;
|
|
8
|
+
this.agentId = agentId;
|
|
9
|
+
this.snapshot = { todos: [], version: 1, updatedAt: Date.now() };
|
|
10
|
+
}
|
|
11
|
+
async load() {
|
|
12
|
+
const existing = await this.store.loadTodos?.(this.agentId);
|
|
13
|
+
if (existing) {
|
|
14
|
+
this.snapshot = existing;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
list() {
|
|
18
|
+
return [...this.snapshot.todos];
|
|
19
|
+
}
|
|
20
|
+
async setTodos(todos) {
|
|
21
|
+
const normalized = todos.map((todo) => this.normalize(todo));
|
|
22
|
+
this.validateTodos(normalized);
|
|
23
|
+
this.snapshot = {
|
|
24
|
+
todos: normalized.map((todo) => ({ ...todo, updatedAt: Date.now() })),
|
|
25
|
+
version: this.snapshot.version + 1,
|
|
26
|
+
updatedAt: Date.now(),
|
|
27
|
+
};
|
|
28
|
+
await this.persist();
|
|
29
|
+
}
|
|
30
|
+
async update(todo) {
|
|
31
|
+
const existing = this.snapshot.todos.find((t) => t.id === todo.id);
|
|
32
|
+
if (!existing) {
|
|
33
|
+
throw new Error(`Todo not found: ${todo.id}`);
|
|
34
|
+
}
|
|
35
|
+
const normalized = this.normalize({ ...existing, ...todo });
|
|
36
|
+
const updated = { ...existing, ...normalized, updatedAt: Date.now() };
|
|
37
|
+
const next = this.snapshot.todos.map((t) => (t.id === todo.id ? updated : t));
|
|
38
|
+
this.validateTodos(next);
|
|
39
|
+
this.snapshot.todos = next;
|
|
40
|
+
this.snapshot.version += 1;
|
|
41
|
+
this.snapshot.updatedAt = Date.now();
|
|
42
|
+
await this.persist();
|
|
43
|
+
}
|
|
44
|
+
async delete(id) {
|
|
45
|
+
const next = this.snapshot.todos.filter((t) => t.id !== id);
|
|
46
|
+
this.snapshot.todos = next;
|
|
47
|
+
this.snapshot.version += 1;
|
|
48
|
+
this.snapshot.updatedAt = Date.now();
|
|
49
|
+
await this.persist();
|
|
50
|
+
}
|
|
51
|
+
validateTodos(todos) {
|
|
52
|
+
const ids = new Set();
|
|
53
|
+
let inProgress = 0;
|
|
54
|
+
for (const todo of todos) {
|
|
55
|
+
if (!todo.id)
|
|
56
|
+
throw new Error('Todo id is required');
|
|
57
|
+
if (ids.has(todo.id)) {
|
|
58
|
+
throw new Error(`Duplicate todo id: ${todo.id}`);
|
|
59
|
+
}
|
|
60
|
+
ids.add(todo.id);
|
|
61
|
+
if (todo.status === 'in_progress')
|
|
62
|
+
inProgress += 1;
|
|
63
|
+
if (!todo.title?.trim()) {
|
|
64
|
+
throw new Error(`Todo ${todo.id} must have a title`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (inProgress > MAX_IN_PROGRESS) {
|
|
68
|
+
throw new Error('Only one todo can be in progress');
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async persist() {
|
|
72
|
+
if (!this.store.saveTodos)
|
|
73
|
+
return;
|
|
74
|
+
await this.store.saveTodos(this.agentId, this.snapshot);
|
|
75
|
+
}
|
|
76
|
+
normalize(todo) {
|
|
77
|
+
const now = Date.now();
|
|
78
|
+
return {
|
|
79
|
+
id: todo.id,
|
|
80
|
+
title: todo.title,
|
|
81
|
+
status: todo.status,
|
|
82
|
+
assignee: todo.assignee,
|
|
83
|
+
notes: todo.notes,
|
|
84
|
+
createdAt: todo.createdAt ?? now,
|
|
85
|
+
updatedAt: todo.updatedAt ?? now,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
exports.TodoService = TodoService;
|