agentcorp-broker 0.1.0-alpha.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 (71) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/CONTRIBUTING.md +20 -0
  3. package/LICENSE +201 -0
  4. package/README.md +250 -0
  5. package/SECURITY.md +23 -0
  6. package/dist/audit.d.ts +25 -0
  7. package/dist/audit.js +203 -0
  8. package/dist/audit.js.map +1 -0
  9. package/dist/broker.d.ts +103 -0
  10. package/dist/broker.js +805 -0
  11. package/dist/broker.js.map +1 -0
  12. package/dist/cli.d.ts +2 -0
  13. package/dist/cli.js +712 -0
  14. package/dist/cli.js.map +1 -0
  15. package/dist/config.d.ts +3 -0
  16. package/dist/config.js +41 -0
  17. package/dist/config.js.map +1 -0
  18. package/dist/console/console.css +794 -0
  19. package/dist/console/console.js +802 -0
  20. package/dist/console/index.html +309 -0
  21. package/dist/credentials.d.ts +16 -0
  22. package/dist/credentials.js +72 -0
  23. package/dist/credentials.js.map +1 -0
  24. package/dist/database.d.ts +119 -0
  25. package/dist/database.js +1356 -0
  26. package/dist/database.js.map +1 -0
  27. package/dist/diagnostics.d.ts +44 -0
  28. package/dist/diagnostics.js +357 -0
  29. package/dist/diagnostics.js.map +1 -0
  30. package/dist/errors.d.ts +5 -0
  31. package/dist/errors.js +14 -0
  32. package/dist/errors.js.map +1 -0
  33. package/dist/index.d.ts +23 -0
  34. package/dist/index.js +15 -0
  35. package/dist/index.js.map +1 -0
  36. package/dist/mcp.d.ts +3 -0
  37. package/dist/mcp.js +215 -0
  38. package/dist/mcp.js.map +1 -0
  39. package/dist/migrations.d.ts +13 -0
  40. package/dist/migrations.js +266 -0
  41. package/dist/migrations.js.map +1 -0
  42. package/dist/policy.d.ts +22 -0
  43. package/dist/policy.js +33 -0
  44. package/dist/policy.js.map +1 -0
  45. package/dist/server.d.ts +49 -0
  46. package/dist/server.js +529 -0
  47. package/dist/server.js.map +1 -0
  48. package/dist/stdio-adapter.d.ts +230 -0
  49. package/dist/stdio-adapter.js +406 -0
  50. package/dist/stdio-adapter.js.map +1 -0
  51. package/dist/tui.d.ts +26 -0
  52. package/dist/tui.js +291 -0
  53. package/dist/tui.js.map +1 -0
  54. package/dist/types.d.ts +355 -0
  55. package/dist/types.js +85 -0
  56. package/dist/types.js.map +1 -0
  57. package/docs/ARCHITECTURE.md +119 -0
  58. package/docs/README.md +37 -0
  59. package/docs/RELEASING.md +228 -0
  60. package/docs/ROADMAP.md +112 -0
  61. package/docs/cli-reference.md +133 -0
  62. package/docs/dogfooding-report.md +83 -0
  63. package/docs/getting-started.md +228 -0
  64. package/docs/guides/antigravity-setup.md +84 -0
  65. package/docs/guides/claude-cursor-setup.md +76 -0
  66. package/docs/guides/codex-setup.md +75 -0
  67. package/docs/guides/human-console.md +177 -0
  68. package/docs/mcp-tools-reference.md +235 -0
  69. package/docs/policy-guide.md +105 -0
  70. package/examples/org.toml +65 -0
  71. package/package.json +68 -0
@@ -0,0 +1,309 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>AgentCorp — Human Approval & Coordination Console</title>
7
+ <link rel="preconnect" href="https://fonts.googleapis.com">
8
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
9
+ <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
10
+ <link rel="stylesheet" href="/console.css">
11
+ </head>
12
+ <body>
13
+ <div class="app-layout">
14
+ <!-- Sidebar -->
15
+ <aside class="sidebar">
16
+ <div class="brand">
17
+ <div class="brand-logo">
18
+ <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
19
+ <rect x="2" y="3" width="20" height="14" rx="2"></rect>
20
+ <line x1="8" y1="21" x2="16" y2="21"></line>
21
+ <line x1="12" y1="17" x2="12" y2="21"></line>
22
+ </svg>
23
+ </div>
24
+ <div class="brand-text">
25
+ <span class="brand-title">AgentCorp</span>
26
+ <span class="brand-badge">Broker v0.1</span>
27
+ </div>
28
+ </div>
29
+
30
+ <nav class="nav-menu">
31
+ <button class="nav-item active" data-tab="approvals" id="nav-approvals">
32
+ <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
33
+ <path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"></path>
34
+ </svg>
35
+ <span>Pending Approvals</span>
36
+ <span class="badge badge-amber" id="approvals-badge">0</span>
37
+ </button>
38
+
39
+ <button class="nav-item" data-tab="tasks" id="nav-tasks">
40
+ <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
41
+ <path d="M9 11l3 3L22 4"></path>
42
+ <path d="M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"></path>
43
+ </svg>
44
+ <span>Tasks & Threads</span>
45
+ <span class="badge" id="tasks-badge">0</span>
46
+ </button>
47
+
48
+ <button class="nav-item" data-tab="inboxes" id="nav-inboxes">
49
+ <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
50
+ <polyline points="22 12 16 12 14 15 10 15 8 12 2 12"></polyline>
51
+ <path d="M5.45 5.11L2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z"></path>
52
+ </svg>
53
+ <span>Role Inboxes</span>
54
+ </button>
55
+
56
+ <button class="nav-item" data-tab="artifacts" id="nav-artifacts">
57
+ <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
58
+ <path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path>
59
+ <polyline points="14 2 14 8 20 8"></polyline>
60
+ <line x1="16" y1="13" x2="8" y2="13"></line>
61
+ <line x1="16" y1="17" x2="8" y2="17"></line>
62
+ <polyline points="10 9 9 9 8 9"></polyline>
63
+ </svg>
64
+ <span>Artifacts Store</span>
65
+ </button>
66
+
67
+ <button class="nav-item" data-tab="policies" id="nav-policies">
68
+ <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
69
+ <circle cx="12" cy="12" r="3"></circle>
70
+ <path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"></path>
71
+ </svg>
72
+ <span>Policy Engine</span>
73
+ </button>
74
+ </nav>
75
+
76
+ <div class="sidebar-footer">
77
+ <div class="company-card">
78
+ <span class="company-label">Organization</span>
79
+ <span class="company-name" id="company-name">Loading...</span>
80
+ </div>
81
+ <button class="btn btn-secondary btn-sm w-full" id="export-audit-btn">
82
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
83
+ <path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path>
84
+ <polyline points="7 10 12 15 17 10"></polyline>
85
+ <line x1="12" y1="15" x2="12" y2="3"></line>
86
+ </svg>
87
+ <span>Export Audit Log</span>
88
+ </button>
89
+ </div>
90
+ </aside>
91
+
92
+ <!-- Main Content Area -->
93
+ <main class="main-content">
94
+ <!-- Top Header -->
95
+ <header class="top-bar">
96
+ <div class="search-box">
97
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
98
+ <circle cx="11" cy="11" r="8"></circle>
99
+ <line x1="21" y1="21" x2="16.65" y2="16.65"></line>
100
+ </svg>
101
+ <input type="text" id="search-input" placeholder="Search tasks, messages, risk tags... (Press / to focus)" />
102
+ </div>
103
+
104
+ <div class="header-status">
105
+ <div class="connection-status" id="connection-status">
106
+ <span class="status-dot disconnected" id="sse-indicator"></span>
107
+ <span id="sse-status-text">Connecting...</span>
108
+ </div>
109
+
110
+ <div class="presence-bar" id="header-presence-bar" style="display: flex; gap: 6px; align-items: center;"></div>
111
+
112
+ <button class="btn btn-ghost btn-sm" id="auth-modal-btn">
113
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
114
+ <rect x="3" y="11" width="18" height="11" rx="2" ry="2"></rect>
115
+ <path d="M7 11V7a5 5 0 0 1 10 0v4"></path>
116
+ </svg>
117
+ <span id="auth-status-label">Admin Token</span>
118
+ </button>
119
+ </div>
120
+ </header>
121
+
122
+ <!-- View Containers -->
123
+ <div class="content-viewport">
124
+ <!-- 1. Approvals View -->
125
+ <section class="tab-pane active" id="view-approvals">
126
+ <div class="pane-header">
127
+ <div>
128
+ <h1 class="pane-title">Pending Approvals</h1>
129
+ <p class="pane-subtitle">Inspect, approve, modify, or reject agent messages and state transitions.</p>
130
+ </div>
131
+ <button class="btn btn-secondary btn-sm" id="refresh-approvals-btn">Refresh</button>
132
+ </div>
133
+
134
+ <div class="cards-grid" id="approvals-container">
135
+ <div class="empty-state">
136
+ <svg width="40" height="40" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
137
+ <path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"></path>
138
+ <polyline points="22 4 12 14.01 9 11.01"></polyline>
139
+ </svg>
140
+ <h3>All clear! No pending approvals</h3>
141
+ <p>Autonomous agent traffic is flowing or awaiting new tasks.</p>
142
+ </div>
143
+ </div>
144
+ </section>
145
+
146
+ <!-- 2. Tasks & Threads View -->
147
+ <section class="tab-pane" id="view-tasks">
148
+ <div class="pane-header">
149
+ <div>
150
+ <h1 class="pane-title">Tasks & Message Threads</h1>
151
+ <p class="pane-subtitle">Live status and message conversation history between agents.</p>
152
+ </div>
153
+ </div>
154
+
155
+ <div class="tasks-layout">
156
+ <div class="tasks-list" id="tasks-list-container">
157
+ <!-- Rendered task cards -->
158
+ </div>
159
+ <div class="thread-viewer" id="thread-viewer-container">
160
+ <div class="thread-empty">Select a task on the left to inspect its complete message thread.</div>
161
+ </div>
162
+ </div>
163
+ </section>
164
+
165
+ <!-- 3. Inboxes View -->
166
+ <section class="tab-pane" id="view-inboxes">
167
+ <div class="pane-header">
168
+ <div>
169
+ <h1 class="pane-title">Role Inboxes</h1>
170
+ <p class="pane-subtitle">Delivered and acknowledged messages for each connected role.</p>
171
+ </div>
172
+ <div class="role-selector-group" id="role-inbox-pills">
173
+ <!-- Role selector buttons -->
174
+ </div>
175
+ </div>
176
+
177
+ <div class="inbox-messages" id="inbox-messages-container">
178
+ <!-- Messages list -->
179
+ </div>
180
+ </section>
181
+
182
+ <!-- 4. Artifacts View -->
183
+ <section class="tab-pane" id="view-artifacts">
184
+ <div class="pane-header">
185
+ <div>
186
+ <h1 class="pane-title">Artifacts Store</h1>
187
+ <p class="pane-subtitle">Access-controlled code diffs, logs, specs, and outputs produced by agents.</p>
188
+ </div>
189
+ </div>
190
+
191
+ <div class="artifacts-table-container">
192
+ <table class="data-table" id="artifacts-table">
193
+ <thead>
194
+ <tr>
195
+ <th>Artifact ID</th>
196
+ <th>Name</th>
197
+ <th>Type</th>
198
+ <th>Produced By</th>
199
+ <th>Visibility</th>
200
+ <th>Hash</th>
201
+ <th>Actions</th>
202
+ </tr>
203
+ </thead>
204
+ <tbody id="artifacts-table-body">
205
+ <!-- Rows -->
206
+ </tbody>
207
+ </table>
208
+ </div>
209
+ </section>
210
+
211
+ <!-- 5. Policies View -->
212
+ <section class="tab-pane" id="view-policies">
213
+ <div class="pane-header">
214
+ <div>
215
+ <h1 class="pane-title">Approval Policy Rules</h1>
216
+ <p class="pane-subtitle">Rules governing auto-approval vs human gating evaluated in priority order.</p>
217
+ </div>
218
+ <button class="btn btn-primary btn-sm" id="create-policy-btn">+ New Rule</button>
219
+ </div>
220
+
221
+ <div class="policies-grid" id="policies-container">
222
+ <!-- Rendered policy cards -->
223
+ </div>
224
+ </section>
225
+ </div>
226
+ </main>
227
+ </div>
228
+
229
+ <!-- Diff & Edit Modal -->
230
+ <div class="modal-backdrop" id="diff-modal" style="display: none;">
231
+ <div class="modal-dialog modal-lg">
232
+ <div class="modal-header">
233
+ <div>
234
+ <h2 class="modal-title">Edit & Approve Message</h2>
235
+ <p class="modal-subtitle" id="diff-modal-subtitle">Inspect payload changes before releasing to recipient.</p>
236
+ </div>
237
+ <button class="modal-close" id="diff-modal-close">&times;</button>
238
+ </div>
239
+
240
+ <div class="diff-container">
241
+ <div class="diff-pane">
242
+ <div class="diff-pane-header">Original Payload (Agent Proposal)</div>
243
+ <pre class="diff-code" id="diff-original-code"></pre>
244
+ </div>
245
+ <div class="diff-pane">
246
+ <div class="diff-pane-header">
247
+ <span>Revised Payload (Human Edited)</span>
248
+ <span class="badge badge-cyan" id="diff-valid-badge">Valid JSON</span>
249
+ </div>
250
+ <textarea class="diff-editor" id="diff-editor-input" spellcheck="false"></textarea>
251
+ </div>
252
+ </div>
253
+
254
+ <div class="modal-body-note">
255
+ <label for="diff-decision-note">Decision Note (Optional):</label>
256
+ <input type="text" id="diff-decision-note" class="form-input" placeholder="e.g. Adjusted database connection pool limit" />
257
+ </div>
258
+
259
+ <div class="modal-footer">
260
+ <button class="btn btn-secondary" id="diff-cancel-btn">Cancel</button>
261
+ <button class="btn btn-primary" id="diff-submit-approve-btn">Approve With Modification</button>
262
+ </div>
263
+ </div>
264
+ </div>
265
+
266
+ <!-- Rejection Modal -->
267
+ <div class="modal-backdrop" id="reject-modal" style="display: none;">
268
+ <div class="modal-dialog">
269
+ <div class="modal-header">
270
+ <h2 class="modal-title">Reject Item</h2>
271
+ <button class="modal-close" id="reject-modal-close">&times;</button>
272
+ </div>
273
+ <div class="modal-body">
274
+ <p>Are you sure you want to reject this pending item? The sending agent will record the rejection.</p>
275
+ <label for="reject-note-input">Rejection Reason / Guidance:</label>
276
+ <textarea id="reject-note-input" class="form-textarea" placeholder="e.g. Plan exceeds risk tolerance for deployment on main."></textarea>
277
+ </div>
278
+ <div class="modal-footer">
279
+ <button class="btn btn-secondary" id="reject-cancel-btn">Cancel</button>
280
+ <button class="btn btn-danger" id="reject-confirm-btn">Confirm Rejection</button>
281
+ </div>
282
+ </div>
283
+ </div>
284
+
285
+ <!-- Admin Token Config Modal -->
286
+ <div class="modal-backdrop" id="auth-modal" style="display: none;">
287
+ <div class="modal-dialog">
288
+ <div class="modal-header">
289
+ <h2 class="modal-title">Admin Authentication</h2>
290
+ <button class="modal-close" id="auth-modal-close">&times;</button>
291
+ </div>
292
+ <div class="modal-body">
293
+ <p>Enter the admin token generated in <code>.agentcorp/credentials.json</code> to access approvals and policy controls.</p>
294
+ <label for="admin-token-input">Admin Bearer Token:</label>
295
+ <input type="password" id="admin-token-input" class="form-input" placeholder="admin_..." />
296
+ </div>
297
+ <div class="modal-footer">
298
+ <button class="btn btn-secondary" id="auth-cancel-btn">Cancel</button>
299
+ <button class="btn btn-primary" id="auth-save-btn">Save Token</button>
300
+ </div>
301
+ </div>
302
+ </div>
303
+
304
+ <!-- Toast Container -->
305
+ <div class="toast-container" id="toast-container"></div>
306
+
307
+ <script src="/console.js"></script>
308
+ </body>
309
+ </html>
@@ -0,0 +1,16 @@
1
+ import type { OrgConfig } from "./types.js";
2
+ export interface CredentialsFile {
3
+ adminToken: string;
4
+ roleTokens: Record<string, string>;
5
+ createdAt: string;
6
+ updatedAt: string;
7
+ }
8
+ export declare function generateToken(prefix?: string): string;
9
+ export declare function loadCredentials(filePath?: string): CredentialsFile | null;
10
+ export declare function ensureCredentials(config: OrgConfig, filePath?: string): CredentialsFile;
11
+ export declare function resolveCallerFromToken(token: string, credentials: CredentialsFile): {
12
+ type: "admin";
13
+ } | {
14
+ type: "role";
15
+ roleId: string;
16
+ } | null;
@@ -0,0 +1,72 @@
1
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
+ import { dirname, resolve } from "node:path";
3
+ import { randomBytes } from "node:crypto";
4
+ import { AgentCorpError } from "./errors.js";
5
+ export function generateToken(prefix = "ac") {
6
+ return `${prefix}_${randomBytes(24).toString("hex")}`;
7
+ }
8
+ export function loadCredentials(filePath = ".agentcorp/credentials.json") {
9
+ const absolutePath = resolve(filePath);
10
+ if (!existsSync(absolutePath)) {
11
+ return null;
12
+ }
13
+ try {
14
+ const raw = readFileSync(absolutePath, "utf8");
15
+ const parsed = JSON.parse(raw);
16
+ if (!parsed.adminToken || typeof parsed.roleTokens !== "object") {
17
+ throw new Error("Invalid credentials file format");
18
+ }
19
+ return parsed;
20
+ }
21
+ catch (error) {
22
+ throw new AgentCorpError("INVALID_CREDENTIALS", `Could not read credentials at ${absolutePath}: ${String(error)}`);
23
+ }
24
+ }
25
+ export function ensureCredentials(config, filePath = ".agentcorp/credentials.json") {
26
+ const absolutePath = resolve(filePath);
27
+ const now = new Date().toISOString();
28
+ let existing = null;
29
+ if (existsSync(absolutePath)) {
30
+ existing = loadCredentials(absolutePath);
31
+ }
32
+ const roleTokens = { ...(existing?.roleTokens ?? {}) };
33
+ let modified = false;
34
+ for (const role of config.roles) {
35
+ if (!roleTokens[role.id]) {
36
+ roleTokens[role.id] = generateToken(`role_${role.id}`);
37
+ modified = true;
38
+ }
39
+ }
40
+ const adminToken = existing?.adminToken ?? generateToken("admin");
41
+ if (!existing || existing.adminToken !== adminToken) {
42
+ modified = true;
43
+ }
44
+ const credentials = {
45
+ adminToken,
46
+ roleTokens,
47
+ createdAt: existing?.createdAt ?? now,
48
+ updatedAt: modified ? now : (existing?.updatedAt ?? now),
49
+ };
50
+ if (!existing || modified) {
51
+ mkdirSync(dirname(absolutePath), { recursive: true });
52
+ writeFileSync(absolutePath, JSON.stringify(credentials, null, 2), {
53
+ encoding: "utf8",
54
+ mode: 0o600,
55
+ });
56
+ }
57
+ return credentials;
58
+ }
59
+ export function resolveCallerFromToken(token, credentials) {
60
+ if (!token)
61
+ return null;
62
+ if (token === credentials.adminToken) {
63
+ return { type: "admin" };
64
+ }
65
+ for (const [roleId, roleToken] of Object.entries(credentials.roleTokens)) {
66
+ if (token === roleToken) {
67
+ return { type: "role", roleId };
68
+ }
69
+ }
70
+ return null;
71
+ }
72
+ //# sourceMappingURL=credentials.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credentials.js","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAU7C,MAAM,UAAU,aAAa,CAAC,MAAM,GAAG,IAAI;IACzC,OAAO,GAAG,MAAM,IAAI,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,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CAAC;IACD,KAAK,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,UAAU,CAAC,EAAE,CAAC;QACzE,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;QAClC,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,119 @@
1
+ import { DatabaseSync } from "node:sqlite";
2
+ import type { ArtifactRecord, AuditArtifactRecord, AuditExportOptions, AuditTaskRecord, IdempotencyRecord, InitialPolicy, MaintenanceLogRecord, MessageRecord, PaginatedResult, PaginationOptions, PendingApproval, PolicyRule, PruneOptions, PruneResult, RolePresence, TaskRecord } from "./types.js";
3
+ export declare const DEFAULT_PAGE_LIMIT = 50;
4
+ export declare const MAX_PAGE_LIMIT = 200;
5
+ export declare const DEFAULT_AUDIT_LIMIT = 500;
6
+ export declare const MAX_AUDIT_LIMIT = 5000;
7
+ export declare const MAX_MAINTENANCE_LOG_ENTRIES = 1000;
8
+ export interface DatabaseOptions {
9
+ defaultPageSize?: number | undefined;
10
+ maxPageSize?: number | undefined;
11
+ }
12
+ export declare function encodeCursor(timestamp: string, id: string): string;
13
+ export declare function decodeCursor(cursor?: string): {
14
+ timestamp?: string | undefined;
15
+ id?: string | undefined;
16
+ } | null;
17
+ export declare function parseLimit(limit?: number, defaultLimit?: number, maxLimit?: number): number;
18
+ type Row = Record<string, unknown>;
19
+ export declare class AgentCorpDatabase {
20
+ readonly db: DatabaseSync;
21
+ readonly defaultPageSize: number;
22
+ readonly maxPageSize: number;
23
+ constructor(path?: string, options?: DatabaseOptions);
24
+ resolveLimit(limit?: number): number;
25
+ close(): void;
26
+ private transactionDepth;
27
+ transaction<T>(operation: () => T): T;
28
+ getSchemaVersion(): number;
29
+ private migrate;
30
+ countPolicies(): number;
31
+ insertPolicy(rule: PolicyRule): void;
32
+ upsertPolicy(rule: PolicyRule): void;
33
+ getPolicy(policyId: string): PolicyRule | undefined;
34
+ setPolicyEnabled(policyId: string, enabled: boolean, updatedAt: string): void;
35
+ listPolicies(): PolicyRule[];
36
+ bindRole(roleId: string, agentId: string, capabilities: string[], connectedAt: string): void;
37
+ touchRolePresence(roleId: string, timestamp?: string): void;
38
+ listRolePresence(): RolePresence[];
39
+ saveIdempotency(record: IdempotencyRecord): void;
40
+ getIdempotency(key: string, roleId: string): IdempotencyRecord | undefined;
41
+ insertTask(task: TaskRecord): void;
42
+ getTask(taskId: string): TaskRecord | undefined;
43
+ listTasksForRolePaginated(roleId: string, options?: PaginationOptions): PaginatedResult<TaskRecord>;
44
+ listTasksForRole(roleId: string, options?: PaginationOptions): TaskRecord[];
45
+ updateTaskStatus(taskId: string, status: string, updatedAt: string): void;
46
+ insertTransition(transition: {
47
+ id: string;
48
+ taskId: string;
49
+ fromStatus: string;
50
+ toStatus: string;
51
+ requestedBy: string;
52
+ status: string;
53
+ createdAt: string;
54
+ }): void;
55
+ getTransition(id: string): Row | undefined;
56
+ resolveTransition(id: string, status: string, resolvedAt: string): void;
57
+ hasPendingTransition(taskId: string, toStatus: string, requestedBy: string): boolean;
58
+ insertMessage(message: MessageRecord): void;
59
+ getMessage(messageId: string): MessageRecord | undefined;
60
+ listInboxPaginated(roleId: string, options?: PaginationOptions): PaginatedResult<MessageRecord>;
61
+ listInbox(roleId: string, options?: PaginationOptions): MessageRecord[];
62
+ listThreadPaginated(taskId: string, roleId: string, options?: PaginationOptions): PaginatedResult<MessageRecord>;
63
+ listThread(taskId: string, roleId: string, options?: PaginationOptions): MessageRecord[];
64
+ updateMessage(messageId: string, status: string, resolvedAt: string | null, payload?: unknown): void;
65
+ insertMessageEvent(event: {
66
+ id: string;
67
+ messageId: string;
68
+ status: string;
69
+ actor: string;
70
+ note: string | null;
71
+ createdAt: string;
72
+ }): void;
73
+ insertArtifact(artifact: ArtifactRecord): void;
74
+ getArtifact(artifactId: string, includeContent?: boolean): ArtifactRecord | undefined;
75
+ listArtifactsPaginated(taskId: string | null, options?: PaginationOptions): PaginatedResult<ArtifactRecord>;
76
+ listArtifacts(taskId: string | null, options?: PaginationOptions): ArtifactRecord[];
77
+ insertApproval(approval: PendingApproval): void;
78
+ getApproval(approvalId: string): PendingApproval | undefined;
79
+ listPendingApprovalsPaginated(options?: PaginationOptions): PaginatedResult<PendingApproval>;
80
+ listPendingApprovals(options?: PaginationOptions): PendingApproval[];
81
+ resolveApproval(approvalId: string, status: "approved" | "rejected", decidedAt: string, note: string | null, editedPayload?: unknown): void;
82
+ listAllTasksPaginated(options?: PaginationOptions): PaginatedResult<TaskRecord>;
83
+ listAllTasks(options?: PaginationOptions): TaskRecord[];
84
+ listAllMessagesPaginated(options?: PaginationOptions): PaginatedResult<MessageRecord>;
85
+ listAllMessages(options?: PaginationOptions): MessageRecord[];
86
+ listAllApprovalsPaginated(options?: PaginationOptions): PaginatedResult<PendingApproval>;
87
+ listAllApprovals(options?: PaginationOptions): PendingApproval[];
88
+ listAllRoleBindings(): Array<{
89
+ roleId: string;
90
+ agentId: string;
91
+ capabilities: string[];
92
+ connectedAt: string;
93
+ }>;
94
+ pruneHistory(options: PruneOptions): PruneResult;
95
+ checkpointAndCompact(): {
96
+ checkpoint: string;
97
+ busy: boolean;
98
+ logPages: number;
99
+ checkpointedPages: number;
100
+ vacuumed: boolean;
101
+ };
102
+ checkIntegrity(): boolean;
103
+ insertMaintenanceLog(record: MaintenanceLogRecord, maxEntries?: number): void;
104
+ listMaintenanceLogs(limit?: number): MaintenanceLogRecord[];
105
+ countTasks(): number;
106
+ countMessages(): number;
107
+ countApprovals(): number;
108
+ countArtifacts(): number;
109
+ countAuditTasks(options?: AuditExportOptions): number;
110
+ countAuditMessages(options?: AuditExportOptions): number;
111
+ countAuditApprovals(options?: AuditExportOptions): number;
112
+ countAuditArtifacts(options?: AuditExportOptions): number;
113
+ getAuditTasks(options?: AuditExportOptions): AuditTaskRecord[];
114
+ getAuditMessages(options?: AuditExportOptions): MessageRecord[];
115
+ getAuditApprovals(options?: AuditExportOptions): PendingApproval[];
116
+ getAuditArtifacts(options?: AuditExportOptions): AuditArtifactRecord[];
117
+ }
118
+ export declare function policyFromConfig(rule: InitialPolicy, id: string, timestamp: string): PolicyRule;
119
+ export {};