openbot 0.2.14 → 0.3.1

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 (84) hide show
  1. package/dist/agents/openbot/index.js +76 -0
  2. package/dist/agents/openbot/middleware/approval.js +132 -0
  3. package/dist/agents/openbot/runtime.js +289 -0
  4. package/dist/agents/openbot/system-prompt.js +32 -0
  5. package/dist/agents/openbot/tools/delegation.js +78 -0
  6. package/dist/agents/openbot/tools/mcp.js +99 -0
  7. package/dist/agents/openbot/tools/shell.js +91 -0
  8. package/dist/agents/openbot/tools/storage.js +75 -0
  9. package/dist/agents/openbot/tools/ui.js +176 -0
  10. package/dist/agents/system.js +20 -93
  11. package/dist/app/cli.js +1 -1
  12. package/dist/app/config.js +4 -1
  13. package/dist/app/server.js +15 -8
  14. package/dist/bus/agent-package.js +1 -0
  15. package/dist/bus/plugin.js +1 -0
  16. package/dist/bus/services.js +711 -0
  17. package/dist/bus/types.js +1 -0
  18. package/dist/harness/context.js +250 -0
  19. package/dist/harness/event-normalizer.js +59 -0
  20. package/dist/harness/orchestrator.js +27 -227
  21. package/dist/harness/process.js +25 -3
  22. package/dist/harness/queue-processor.js +227 -0
  23. package/dist/harness/runtime-factory.js +103 -0
  24. package/dist/plugins/ai-sdk/index.js +37 -0
  25. package/dist/plugins/ai-sdk/runtime.js +402 -0
  26. package/dist/plugins/ai-sdk/system-prompt.js +3 -0
  27. package/dist/plugins/ai-sdk.js +277 -87
  28. package/dist/plugins/approval/index.js +159 -0
  29. package/dist/plugins/approval.js +163 -0
  30. package/dist/plugins/delegation/index.js +79 -0
  31. package/dist/plugins/delegation.js +67 -11
  32. package/dist/plugins/mcp/index.js +108 -0
  33. package/dist/plugins/memory/index.js +71 -0
  34. package/dist/plugins/shell/index.js +99 -0
  35. package/dist/plugins/shell.js +123 -0
  36. package/dist/plugins/storage-tools/index.js +85 -0
  37. package/dist/plugins/storage.js +240 -5
  38. package/dist/plugins/ui/index.js +184 -0
  39. package/dist/plugins/ui.js +185 -21
  40. package/dist/registry/agents.js +138 -0
  41. package/dist/registry/plugins.js +93 -50
  42. package/dist/services/agent-packages.js +103 -0
  43. package/dist/services/memory.js +152 -0
  44. package/dist/services/plugins.js +98 -0
  45. package/dist/services/storage.js +366 -94
  46. package/docs/agents.md +52 -65
  47. package/docs/architecture.md +1 -1
  48. package/docs/plugins.md +70 -58
  49. package/docs/templates/AGENT.example.md +57 -0
  50. package/package.json +8 -7
  51. package/src/app/cli.ts +1 -1
  52. package/src/app/config.ts +14 -4
  53. package/src/app/server.ts +23 -10
  54. package/src/app/types.ts +445 -16
  55. package/src/assets/icon.svg +4 -1
  56. package/src/bus/plugin.ts +67 -0
  57. package/src/bus/services.ts +786 -0
  58. package/src/bus/types.ts +160 -0
  59. package/src/harness/context.ts +293 -0
  60. package/src/harness/event-normalizer.ts +82 -0
  61. package/src/harness/orchestrator.ts +35 -273
  62. package/src/harness/process.ts +28 -4
  63. package/src/harness/queue-processor.ts +309 -0
  64. package/src/harness/runtime-factory.ts +125 -0
  65. package/src/plugins/ai-sdk/index.ts +44 -0
  66. package/src/plugins/ai-sdk/runtime.ts +484 -0
  67. package/src/plugins/ai-sdk/system-prompt.ts +4 -0
  68. package/src/plugins/approval/index.ts +228 -0
  69. package/src/plugins/delegation/index.ts +94 -0
  70. package/src/plugins/mcp/index.ts +128 -0
  71. package/src/plugins/memory/index.ts +85 -0
  72. package/src/plugins/shell/index.ts +123 -0
  73. package/src/plugins/storage-tools/index.ts +101 -0
  74. package/src/plugins/ui/index.ts +227 -0
  75. package/src/registry/plugins.ts +108 -55
  76. package/src/services/memory.ts +213 -0
  77. package/src/services/plugins.ts +133 -0
  78. package/src/services/storage.ts +472 -137
  79. package/src/agents/system.ts +0 -112
  80. package/src/plugins/ai-sdk.ts +0 -197
  81. package/src/plugins/delegation.ts +0 -60
  82. package/src/plugins/mcp.ts +0 -154
  83. package/src/plugins/storage.ts +0 -725
  84. package/src/plugins/ui.ts +0 -57
@@ -0,0 +1,152 @@
1
+ import fs from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import crypto from 'node:crypto';
4
+ import { DEFAULT_BASE_DIR, loadConfig, resolvePath } from '../app/config.js';
5
+ const DEFAULT_LIMIT = 50;
6
+ const MAX_LIMIT = 500;
7
+ const getMemoryDir = () => {
8
+ const config = loadConfig();
9
+ return path.join(resolvePath(config.baseDir || DEFAULT_BASE_DIR), 'memory');
10
+ };
11
+ const getLogPath = () => path.join(getMemoryDir(), 'log.jsonl');
12
+ const ensureDir = async () => {
13
+ await fs.mkdir(getMemoryDir(), { recursive: true });
14
+ };
15
+ const readLog = async () => {
16
+ try {
17
+ const raw = await fs.readFile(getLogPath(), 'utf-8');
18
+ return raw
19
+ .split(/\r?\n/)
20
+ .map((line) => line.trim())
21
+ .filter(Boolean)
22
+ .map((line) => {
23
+ try {
24
+ return JSON.parse(line);
25
+ }
26
+ catch {
27
+ return null;
28
+ }
29
+ })
30
+ .filter((e) => !!e);
31
+ }
32
+ catch (e) {
33
+ if (e?.code === 'ENOENT')
34
+ return [];
35
+ throw e;
36
+ }
37
+ };
38
+ const replay = (entries) => {
39
+ const out = new Map();
40
+ for (const entry of entries) {
41
+ if (entry.op === 'add') {
42
+ out.set(entry.record.id, entry.record);
43
+ }
44
+ else if (entry.op === 'delete') {
45
+ out.delete(entry.id);
46
+ }
47
+ else if (entry.op === 'update') {
48
+ const existing = out.get(entry.id);
49
+ if (!existing)
50
+ continue;
51
+ out.set(entry.id, {
52
+ ...existing,
53
+ ...entry.patch,
54
+ id: existing.id,
55
+ updatedAt: entry.at,
56
+ });
57
+ }
58
+ }
59
+ return out;
60
+ };
61
+ const appendEntry = async (entry) => {
62
+ await ensureDir();
63
+ await fs.appendFile(getLogPath(), `${JSON.stringify(entry)}\n`, 'utf-8');
64
+ };
65
+ const matchesQuery = (record, query, tag) => {
66
+ if (tag) {
67
+ if (!record.tags || !record.tags.includes(tag))
68
+ return false;
69
+ }
70
+ if (query) {
71
+ const q = query.toLowerCase();
72
+ if (!record.content.toLowerCase().includes(q))
73
+ return false;
74
+ }
75
+ return true;
76
+ };
77
+ export const memoryService = {
78
+ appendMemory: async (args) => {
79
+ const now = new Date().toISOString();
80
+ const record = {
81
+ id: crypto.randomUUID(),
82
+ scope: args.scope,
83
+ content: args.content,
84
+ tags: args.tags?.length ? args.tags : undefined,
85
+ createdAt: now,
86
+ updatedAt: now,
87
+ };
88
+ await appendEntry({ op: 'add', record });
89
+ return record;
90
+ },
91
+ updateMemory: async (args) => {
92
+ const entries = await readLog();
93
+ const map = replay(entries);
94
+ if (!map.has(args.id))
95
+ return false;
96
+ const at = new Date().toISOString();
97
+ const patch = {};
98
+ if (args.content !== undefined)
99
+ patch.content = args.content;
100
+ if (args.tags !== undefined)
101
+ patch.tags = args.tags.length ? args.tags : undefined;
102
+ if (Object.keys(patch).length === 0)
103
+ return true;
104
+ await appendEntry({ op: 'update', id: args.id, patch, at });
105
+ return true;
106
+ },
107
+ deleteMemory: async (args) => {
108
+ const entries = await readLog();
109
+ const map = replay(entries);
110
+ if (!map.has(args.id))
111
+ return false;
112
+ await appendEntry({ op: 'delete', id: args.id, at: new Date().toISOString() });
113
+ return true;
114
+ },
115
+ listMemories: async (args = {}) => {
116
+ const entries = await readLog();
117
+ const map = replay(entries);
118
+ const limit = Math.min(Math.max(args.limit ?? DEFAULT_LIMIT, 1), MAX_LIMIT);
119
+ const scopeSet = (() => {
120
+ if (args.scope)
121
+ return new Set([args.scope]);
122
+ if (args.scopes && args.scopes.length > 0)
123
+ return new Set(args.scopes);
124
+ return null;
125
+ })();
126
+ const filtered = [];
127
+ for (const record of map.values()) {
128
+ if (scopeSet && !scopeSet.has(record.scope))
129
+ continue;
130
+ if (!matchesQuery(record, args.query, args.tag))
131
+ continue;
132
+ filtered.push(record);
133
+ }
134
+ filtered.sort((a, b) => (a.updatedAt < b.updatedAt ? 1 : -1));
135
+ return filtered.slice(0, limit);
136
+ },
137
+ /**
138
+ * Compact the log into a single `add` per surviving record. Cheap to call
139
+ * occasionally; not required for correctness.
140
+ */
141
+ compact: async () => {
142
+ const entries = await readLog();
143
+ const map = replay(entries);
144
+ const surviving = Array.from(map.values());
145
+ await ensureDir();
146
+ const tmp = `${getLogPath()}.tmp`;
147
+ const body = surviving.map((record) => JSON.stringify({ op: 'add', record })).join('\n');
148
+ await fs.writeFile(tmp, body ? `${body}\n` : '', 'utf-8');
149
+ await fs.rename(tmp, getLogPath());
150
+ return surviving.length;
151
+ },
152
+ };
@@ -0,0 +1,98 @@
1
+ import fs from 'node:fs/promises';
2
+ import { existsSync } from 'node:fs';
3
+ import path from 'node:path';
4
+ import { exec } from 'node:child_process';
5
+ import { promisify } from 'node:util';
6
+ import { DEFAULT_PLUGINS_DIR, DEFAULT_BASE_DIR, loadConfig, resolvePath, } from '../app/config.js';
7
+ import { invalidatePlugin } from '../registry/plugins.js';
8
+ const execAsync = promisify(exec);
9
+ const getPluginsDir = () => {
10
+ const config = loadConfig();
11
+ const baseDir = resolvePath(config.baseDir || DEFAULT_BASE_DIR);
12
+ return path.join(baseDir, DEFAULT_PLUGINS_DIR);
13
+ };
14
+ /**
15
+ * Lifecycle for community-built plugins distributed via npm.
16
+ * Each plugin is installed to `<plugins>/<npm-name>/` and is identified
17
+ * everywhere (AGENT.md `plugins[].id`, registry, runtime resolution) by its
18
+ * npm name. Scoped packages (`@scope/foo`) live under `<plugins>/@scope/foo/`.
19
+ */
20
+ export const pluginService = {
21
+ isInstalled: async (packageName) => {
22
+ const finalPath = path.join(getPluginsDir(), packageName);
23
+ return existsSync(path.join(finalPath, 'dist', 'index.js'));
24
+ },
25
+ install: async ({ packageName, version }) => {
26
+ const pluginsDir = getPluginsDir();
27
+ await fs.mkdir(pluginsDir, { recursive: true });
28
+ const finalPath = path.join(pluginsDir, packageName);
29
+ if (existsSync(path.join(finalPath, 'package.json'))) {
30
+ try {
31
+ const pkgJson = JSON.parse(await fs.readFile(path.join(finalPath, 'package.json'), 'utf-8'));
32
+ if (!version || pkgJson.version === version) {
33
+ console.log(`[plugins] ${packageName}${version ? `@${version}` : ''} is already installed.`);
34
+ return { name: pkgJson.name, version: pkgJson.version };
35
+ }
36
+ }
37
+ catch {
38
+ // corrupted; reinstall below
39
+ }
40
+ }
41
+ const target = version ? `${packageName}@${version}` : packageName;
42
+ console.log(`[plugins] Installing ${target} to ${pluginsDir}...`);
43
+ const tempDir = path.join(pluginsDir, '.tmp_' + Date.now());
44
+ try {
45
+ await fs.mkdir(tempDir, { recursive: true });
46
+ await execAsync(`npm install ${target} --no-save --prefix "${tempDir}"`);
47
+ const installedPath = path.join(tempDir, 'node_modules', packageName);
48
+ if (!existsSync(installedPath)) {
49
+ throw new Error(`npm did not produce ${installedPath}`);
50
+ }
51
+ await fs.mkdir(path.dirname(finalPath), { recursive: true });
52
+ await fs.rm(finalPath, { recursive: true, force: true });
53
+ await fs.rename(installedPath, finalPath);
54
+ console.log(`[plugins] Running npm install in ${finalPath}...`);
55
+ try {
56
+ await execAsync(`npm install`, { cwd: finalPath });
57
+ console.log(`[plugins] npm install completed in ${finalPath}`);
58
+ }
59
+ catch (e) {
60
+ console.warn(`[plugins] Failed to run npm install in ${finalPath}:`, e);
61
+ }
62
+ const pkgJson = JSON.parse(await fs.readFile(path.join(finalPath, 'package.json'), 'utf-8'));
63
+ invalidatePlugin(packageName);
64
+ return { name: pkgJson.name, version: pkgJson.version };
65
+ }
66
+ catch (error) {
67
+ console.error(`[plugins] Failed to install ${packageName}:`, error);
68
+ throw new Error(`Failed to install plugin ${packageName}: ${error.message}`);
69
+ }
70
+ finally {
71
+ await fs.rm(tempDir, { recursive: true, force: true }).catch(() => { });
72
+ }
73
+ },
74
+ uninstall: async (packageName) => {
75
+ const pluginsDir = getPluginsDir();
76
+ const pluginPath = path.join(pluginsDir, packageName);
77
+ try {
78
+ await fs.rm(pluginPath, { recursive: true, force: true });
79
+ invalidatePlugin(packageName);
80
+ console.log(`[plugins] Uninstalled plugin ${packageName}`);
81
+ if (packageName.startsWith('@')) {
82
+ const scopeDir = path.dirname(pluginPath);
83
+ try {
84
+ const remaining = await fs.readdir(scopeDir);
85
+ if (remaining.length === 0)
86
+ await fs.rmdir(scopeDir);
87
+ }
88
+ catch {
89
+ // ignore
90
+ }
91
+ }
92
+ }
93
+ catch (error) {
94
+ console.error(`[plugins] Failed to uninstall ${packageName}:`, error);
95
+ throw new Error(`Failed to uninstall plugin ${packageName}: ${error.message}`);
96
+ }
97
+ },
98
+ };