atabey-shared 0.0.37 → 0.1.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.
- package/README.md +64 -25
- package/dist/agent-identity.d.ts +1 -0
- package/dist/agent-identity.js +2 -0
- package/dist/agent-identity.js.map +1 -0
- package/dist/api-catalog.d.ts +1 -0
- package/dist/api-catalog.js +2 -0
- package/dist/api-catalog.js.map +1 -0
- package/dist/audit-chain.d.ts +1 -51
- package/dist/audit-chain.js +1 -84
- package/dist/audit-chain.js.map +1 -1
- package/dist/audit.d.ts +1 -113
- package/dist/audit.js +1 -284
- package/dist/audit.js.map +1 -1
- package/dist/constants.d.ts +1 -152
- package/dist/constants.js +1 -215
- package/dist/constants.js.map +1 -1
- package/dist/database.d.ts +1 -5
- package/dist/database.js +1 -12
- package/dist/database.js.map +1 -1
- package/dist/errors.d.ts +1 -46
- package/dist/errors.js +1 -68
- package/dist/errors.js.map +1 -1
- package/dist/file-lock.d.ts +1 -88
- package/dist/file-lock.js +1 -250
- package/dist/file-lock.js.map +1 -1
- package/dist/fs.d.ts +1 -9
- package/dist/fs.js +1 -53
- package/dist/fs.js.map +1 -1
- package/dist/index.d.ts +2 -22
- package/dist/index.js +2 -22
- package/dist/index.js.map +1 -1
- package/dist/job-queue.d.ts +1 -53
- package/dist/job-queue.js +1 -126
- package/dist/job-queue.js.map +1 -1
- package/dist/lock.d.ts +1 -82
- package/dist/lock.js +1 -158
- package/dist/lock.js.map +1 -1
- package/dist/logger.d.ts +1 -30
- package/dist/logger.js +1 -126
- package/dist/logger.js.map +1 -1
- package/dist/memory-prune.d.ts +1 -0
- package/dist/memory-prune.js +2 -0
- package/dist/memory-prune.js.map +1 -0
- package/dist/migrations.d.ts +1 -0
- package/dist/migrations.js +2 -0
- package/dist/migrations.js.map +1 -0
- package/dist/modules/agent/agent-identity.d.ts +34 -0
- package/dist/modules/agent/agent-identity.js +77 -0
- package/dist/modules/agent/agent-identity.js.map +1 -0
- package/dist/modules/agent/api-catalog.d.ts +57 -0
- package/dist/modules/agent/api-catalog.js +254 -0
- package/dist/modules/agent/api-catalog.js.map +1 -0
- package/dist/modules/agent/index.d.ts +3 -0
- package/dist/modules/agent/index.js +4 -0
- package/dist/modules/agent/index.js.map +1 -0
- package/dist/modules/agent/tokenizer.d.ts +54 -0
- package/dist/modules/agent/tokenizer.js +272 -0
- package/dist/modules/agent/tokenizer.js.map +1 -0
- package/dist/modules/concurrency/file-lock.d.ts +93 -0
- package/dist/modules/concurrency/file-lock.js +240 -0
- package/dist/modules/concurrency/file-lock.js.map +1 -0
- package/dist/modules/concurrency/index.d.ts +6 -0
- package/dist/modules/concurrency/index.js +7 -0
- package/dist/modules/concurrency/index.js.map +1 -0
- package/dist/modules/concurrency/job-queue.d.ts +76 -0
- package/dist/modules/concurrency/job-queue.js +200 -0
- package/dist/modules/concurrency/job-queue.js.map +1 -0
- package/dist/modules/concurrency/lock.d.ts +82 -0
- package/dist/modules/concurrency/lock.js +159 -0
- package/dist/modules/concurrency/lock.js.map +1 -0
- package/dist/modules/concurrency/resilience.d.ts +84 -0
- package/dist/modules/concurrency/resilience.js +217 -0
- package/dist/modules/concurrency/resilience.js.map +1 -0
- package/dist/modules/concurrency/worker-pool.d.ts +52 -0
- package/dist/modules/concurrency/worker-pool.js +229 -0
- package/dist/modules/concurrency/worker-pool.js.map +1 -0
- package/dist/modules/concurrency/worker-thread.d.ts +21 -0
- package/dist/modules/concurrency/worker-thread.js +67 -0
- package/dist/modules/concurrency/worker-thread.js.map +1 -0
- package/dist/modules/index.d.ts +14 -0
- package/dist/modules/index.js +15 -0
- package/dist/modules/index.js.map +1 -0
- package/dist/modules/observability/audit-chain.d.ts +80 -0
- package/dist/modules/observability/audit-chain.js +262 -0
- package/dist/modules/observability/audit-chain.js.map +1 -0
- package/dist/modules/observability/audit.d.ts +121 -0
- package/dist/modules/observability/audit.js +322 -0
- package/dist/modules/observability/audit.js.map +1 -0
- package/dist/modules/observability/index.d.ts +4 -0
- package/dist/modules/observability/index.js +5 -0
- package/dist/modules/observability/index.js.map +1 -0
- package/dist/modules/observability/logger.d.ts +31 -0
- package/dist/modules/observability/logger.js +153 -0
- package/dist/modules/observability/logger.js.map +1 -0
- package/dist/modules/observability/otel.d.ts +39 -0
- package/dist/modules/observability/otel.js +93 -0
- package/dist/modules/observability/otel.js.map +1 -0
- package/dist/modules/primitives/constants.d.ts +150 -0
- package/dist/modules/primitives/constants.js +212 -0
- package/dist/modules/primitives/constants.js.map +1 -0
- package/dist/modules/primitives/errors.d.ts +46 -0
- package/dist/modules/primitives/errors.js +69 -0
- package/dist/modules/primitives/errors.js.map +1 -0
- package/dist/modules/primitives/fs.d.ts +9 -0
- package/dist/modules/primitives/fs.js +54 -0
- package/dist/modules/primitives/fs.js.map +1 -0
- package/dist/modules/primitives/index.d.ts +7 -0
- package/dist/modules/primitives/index.js +8 -0
- package/dist/modules/primitives/index.js.map +1 -0
- package/dist/modules/primitives/outbound-http.d.ts +32 -0
- package/dist/modules/primitives/outbound-http.js +88 -0
- package/dist/modules/primitives/outbound-http.js.map +1 -0
- package/dist/modules/primitives/string.d.ts +1 -0
- package/dist/modules/primitives/string.js +30 -0
- package/dist/modules/primitives/string.js.map +1 -0
- package/dist/modules/primitives/time.d.ts +5 -0
- package/dist/modules/primitives/time.js +35 -0
- package/dist/modules/primitives/time.js.map +1 -0
- package/dist/modules/primitives/types.d.ts +27 -0
- package/dist/modules/primitives/types.js +17 -0
- package/dist/modules/primitives/types.js.map +1 -0
- package/dist/modules/sandbox/index.d.ts +3 -0
- package/dist/modules/sandbox/index.js +4 -0
- package/dist/modules/sandbox/index.js.map +1 -0
- package/dist/modules/sandbox/sandbox-fs.d.ts +28 -0
- package/dist/modules/sandbox/sandbox-fs.js +143 -0
- package/dist/modules/sandbox/sandbox-fs.js.map +1 -0
- package/dist/modules/sandbox/sandbox-runtime.d.ts +78 -0
- package/dist/modules/sandbox/sandbox-runtime.js +282 -0
- package/dist/modules/sandbox/sandbox-runtime.js.map +1 -0
- package/dist/modules/sandbox/sandbox.d.ts +54 -0
- package/dist/modules/sandbox/sandbox.js +179 -0
- package/dist/modules/sandbox/sandbox.js.map +1 -0
- package/dist/modules/security/index.d.ts +5 -0
- package/dist/modules/security/index.js +6 -0
- package/dist/modules/security/index.js.map +1 -0
- package/dist/modules/security/pii.d.ts +70 -0
- package/dist/modules/security/pii.js +276 -0
- package/dist/modules/security/pii.js.map +1 -0
- package/dist/modules/security/policy-gate.d.ts +42 -0
- package/dist/modules/security/policy-gate.js +172 -0
- package/dist/modules/security/policy-gate.js.map +1 -0
- package/dist/modules/security/retention.d.ts +68 -0
- package/dist/modules/security/retention.js +218 -0
- package/dist/modules/security/retention.js.map +1 -0
- package/dist/modules/security/secrets.d.ts +99 -0
- package/dist/modules/security/secrets.js +371 -0
- package/dist/modules/security/secrets.js.map +1 -0
- package/dist/modules/security/tls.d.ts +87 -0
- package/dist/modules/security/tls.js +154 -0
- package/dist/modules/security/tls.js.map +1 -0
- package/dist/modules/storage/database.d.ts +6 -0
- package/dist/modules/storage/database.js +16 -0
- package/dist/modules/storage/database.js.map +1 -0
- package/dist/modules/storage/index.d.ts +4 -0
- package/dist/modules/storage/index.js +5 -0
- package/dist/modules/storage/index.js.map +1 -0
- package/dist/modules/storage/memory-prune.d.ts +18 -0
- package/dist/modules/storage/memory-prune.js +48 -0
- package/dist/modules/storage/memory-prune.js.map +1 -0
- package/dist/modules/storage/migrations.d.ts +69 -0
- package/dist/modules/storage/migrations.js +394 -0
- package/dist/modules/storage/migrations.js.map +1 -0
- package/dist/modules/storage/storage.d.ts +341 -0
- package/dist/modules/storage/storage.js +1004 -0
- package/dist/modules/storage/storage.js.map +1 -0
- package/dist/otel.d.ts +1 -0
- package/dist/otel.js +2 -0
- package/dist/otel.js.map +1 -0
- package/dist/outbound-http.d.ts +1 -0
- package/dist/outbound-http.js +2 -0
- package/dist/outbound-http.js.map +1 -0
- package/dist/pii.d.ts +1 -69
- package/dist/pii.js +1 -219
- package/dist/pii.js.map +1 -1
- package/dist/policy-gate.d.ts +1 -42
- package/dist/policy-gate.js +1 -147
- package/dist/policy-gate.js.map +1 -1
- package/dist/resilience.d.ts +1 -84
- package/dist/resilience.js +1 -216
- package/dist/resilience.js.map +1 -1
- package/dist/retention.d.ts +1 -63
- package/dist/retention.js +1 -170
- package/dist/retention.js.map +1 -1
- package/dist/sandbox-fs.d.ts +1 -28
- package/dist/sandbox-fs.js +1 -149
- package/dist/sandbox-fs.js.map +1 -1
- package/dist/sandbox-runtime.d.ts +1 -85
- package/dist/sandbox-runtime.js +1 -249
- package/dist/sandbox-runtime.js.map +1 -1
- package/dist/sandbox.d.ts +1 -54
- package/dist/sandbox.js +1 -178
- package/dist/sandbox.js.map +1 -1
- package/dist/secrets.d.ts +1 -0
- package/dist/secrets.js +2 -0
- package/dist/secrets.js.map +1 -0
- package/dist/storage.d.ts +1 -274
- package/dist/storage.js +1 -723
- package/dist/storage.js.map +1 -1
- package/dist/string.d.ts +1 -1
- package/dist/string.js +1 -29
- package/dist/string.js.map +1 -1
- package/dist/time.d.ts +1 -5
- package/dist/time.js +1 -30
- package/dist/time.js.map +1 -1
- package/dist/tls.d.ts +1 -0
- package/dist/tls.js +2 -0
- package/dist/tls.js.map +1 -0
- package/dist/tokenizer.d.ts +1 -0
- package/dist/tokenizer.js +2 -0
- package/dist/tokenizer.js.map +1 -0
- package/dist/types.d.ts +1 -27
- package/dist/types.js +1 -16
- package/dist/types.js.map +1 -1
- package/dist/worker-pool.d.ts +1 -52
- package/dist/worker-pool.js +1 -209
- package/dist/worker-pool.js.map +1 -1
- package/dist/worker-thread.d.ts +1 -21
- package/dist/worker-thread.js +1 -66
- package/dist/worker-thread.js.map +1 -1
- package/package.json +51 -29
package/dist/sandbox.js
CHANGED
|
@@ -1,179 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
* OS-level subprocess isolation via uid/gid (no Docker required).
|
|
3
|
-
*
|
|
4
|
-
* On Unix, child_process.spawn accepts `uid` and `gid`. When configured,
|
|
5
|
-
* agent-triggered shell commands run as a restricted system user so that
|
|
6
|
-
* even a hallucinated destructive command hits EACCES / Permission Denied
|
|
7
|
-
* on protected paths.
|
|
8
|
-
*
|
|
9
|
-
* Windows: uid/gid are ignored; isolation is a no-op (allow-list still applies).
|
|
10
|
-
*
|
|
11
|
-
* Configuration (any of):
|
|
12
|
-
* ATABEY_SANDBOX_UID=501
|
|
13
|
-
* ATABEY_SANDBOX_GID=20
|
|
14
|
-
* ATABEY_SANDBOX_USER=atabey-sandbox (resolved via `id -u` / `id -g` when possible)
|
|
15
|
-
* ATABEY_SANDBOX_ENABLED=true|false (default: true when uid/gid resolvable)
|
|
16
|
-
*/
|
|
17
|
-
import { spawn } from "child_process";
|
|
18
|
-
import { execFileSync } from "child_process";
|
|
19
|
-
import os from "os";
|
|
20
|
-
let cachedIdentity = null;
|
|
21
|
-
function parseUint(value) {
|
|
22
|
-
if (value === undefined || value === "")
|
|
23
|
-
return undefined;
|
|
24
|
-
const n = Number.parseInt(value, 10);
|
|
25
|
-
if (!Number.isFinite(n) || n < 0)
|
|
26
|
-
return undefined;
|
|
27
|
-
return n;
|
|
28
|
-
}
|
|
29
|
-
function resolveUserIds(username) {
|
|
30
|
-
if (process.platform === "win32")
|
|
31
|
-
return {};
|
|
32
|
-
try {
|
|
33
|
-
const uidRaw = execFileSync("id", ["-u", username], {
|
|
34
|
-
encoding: "utf8",
|
|
35
|
-
timeout: 2000,
|
|
36
|
-
stdio: ["ignore", "pipe", "ignore"],
|
|
37
|
-
}).trim();
|
|
38
|
-
const gidRaw = execFileSync("id", ["-g", username], {
|
|
39
|
-
encoding: "utf8",
|
|
40
|
-
timeout: 2000,
|
|
41
|
-
stdio: ["ignore", "pipe", "ignore"],
|
|
42
|
-
}).trim();
|
|
43
|
-
return {
|
|
44
|
-
uid: parseUint(uidRaw),
|
|
45
|
-
gid: parseUint(gidRaw),
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
catch {
|
|
49
|
-
return {};
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Resolve sandbox identity from env (cached).
|
|
54
|
-
* Call `clearSandboxIdentityCache()` in tests after env changes.
|
|
55
|
-
*/
|
|
56
|
-
export function resolveSandboxIdentity() {
|
|
57
|
-
if (cachedIdentity)
|
|
58
|
-
return cachedIdentity;
|
|
59
|
-
if (process.platform === "win32") {
|
|
60
|
-
cachedIdentity = {
|
|
61
|
-
enabled: false,
|
|
62
|
-
reason: "uid/gid isolation is not available on Windows",
|
|
63
|
-
};
|
|
64
|
-
return cachedIdentity;
|
|
65
|
-
}
|
|
66
|
-
const explicitOff = process.env.ATABEY_SANDBOX_ENABLED === "false" ||
|
|
67
|
-
process.env.ATABEY_SANDBOX_ENABLED === "0";
|
|
68
|
-
if (explicitOff) {
|
|
69
|
-
cachedIdentity = { enabled: false, reason: "ATABEY_SANDBOX_ENABLED=false" };
|
|
70
|
-
return cachedIdentity;
|
|
71
|
-
}
|
|
72
|
-
let uid = parseUint(process.env.ATABEY_SANDBOX_UID);
|
|
73
|
-
let gid = parseUint(process.env.ATABEY_SANDBOX_GID);
|
|
74
|
-
const user = process.env.ATABEY_SANDBOX_USER?.trim() || undefined;
|
|
75
|
-
if (user && (uid === undefined || gid === undefined)) {
|
|
76
|
-
const resolved = resolveUserIds(user);
|
|
77
|
-
uid = uid ?? resolved.uid;
|
|
78
|
-
gid = gid ?? resolved.gid;
|
|
79
|
-
}
|
|
80
|
-
// Never drop privileges to root (0) — that would be a no-op or worse
|
|
81
|
-
if (uid === 0) {
|
|
82
|
-
cachedIdentity = {
|
|
83
|
-
enabled: false,
|
|
84
|
-
reason: "ATABEY_SANDBOX_UID=0 (root) is refused",
|
|
85
|
-
uid,
|
|
86
|
-
gid,
|
|
87
|
-
user,
|
|
88
|
-
};
|
|
89
|
-
return cachedIdentity;
|
|
90
|
-
}
|
|
91
|
-
if (uid === undefined) {
|
|
92
|
-
// Optional: if current process is already non-root and no sandbox user
|
|
93
|
-
// configured, we leave sandbox disabled rather than inventing a user.
|
|
94
|
-
cachedIdentity = {
|
|
95
|
-
enabled: false,
|
|
96
|
-
reason: "No ATABEY_SANDBOX_UID / ATABEY_SANDBOX_USER configured — shell runs as current user",
|
|
97
|
-
user,
|
|
98
|
-
};
|
|
99
|
-
return cachedIdentity;
|
|
100
|
-
}
|
|
101
|
-
// Dropping privileges only works if we are root (or have CAP_SETUID).
|
|
102
|
-
// If we are a normal user with a different target uid, spawn will fail —
|
|
103
|
-
// detect and warn via reason, still pass options (caller sees Permission error).
|
|
104
|
-
const canSetUid = typeof process.getuid === "function" && process.getuid() === 0;
|
|
105
|
-
if (!canSetUid && typeof process.getuid === "function" && process.getuid() !== uid) {
|
|
106
|
-
cachedIdentity = {
|
|
107
|
-
enabled: false,
|
|
108
|
-
uid,
|
|
109
|
-
gid,
|
|
110
|
-
user,
|
|
111
|
-
reason: `Sandbox uid=${uid} requested but process uid=${process.getuid()} is not root; ` +
|
|
112
|
-
`setuid will fail. Run MCP as root with a dedicated sandbox user, or unset sandbox env.`,
|
|
113
|
-
};
|
|
114
|
-
return cachedIdentity;
|
|
115
|
-
}
|
|
116
|
-
cachedIdentity = {
|
|
117
|
-
enabled: true,
|
|
118
|
-
uid,
|
|
119
|
-
gid,
|
|
120
|
-
user,
|
|
121
|
-
};
|
|
122
|
-
return cachedIdentity;
|
|
123
|
-
}
|
|
124
|
-
export function clearSandboxIdentityCache() {
|
|
125
|
-
cachedIdentity = null;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Build spawn options with uid/gid when sandbox is active.
|
|
129
|
-
*/
|
|
130
|
-
export function applySandboxToSpawnOptions(options = {}) {
|
|
131
|
-
const { disableSandbox, ...rest } = options;
|
|
132
|
-
if (disableSandbox)
|
|
133
|
-
return { ...rest };
|
|
134
|
-
const identity = resolveSandboxIdentity();
|
|
135
|
-
if (!identity.enabled || identity.uid === undefined) {
|
|
136
|
-
return { ...rest };
|
|
137
|
-
}
|
|
138
|
-
return {
|
|
139
|
-
...rest,
|
|
140
|
-
uid: identity.uid,
|
|
141
|
-
...(identity.gid !== undefined ? { gid: identity.gid } : {}),
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* spawn() wrapper that applies OS sandbox identity when configured.
|
|
146
|
-
*/
|
|
147
|
-
export function sandboxSpawn(command, args, options = {}) {
|
|
148
|
-
const opts = applySandboxToSpawnOptions(options);
|
|
149
|
-
return spawn(command, args, opts);
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Human-readable status for dashboard / CLI diagnostics.
|
|
153
|
-
*/
|
|
154
|
-
export function getSandboxStatus() {
|
|
155
|
-
return {
|
|
156
|
-
platform: process.platform,
|
|
157
|
-
identity: resolveSandboxIdentity(),
|
|
158
|
-
processUid: typeof process.getuid === "function" ? process.getuid() : null,
|
|
159
|
-
processGid: typeof process.getgid === "function" ? process.getgid() : null,
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
/** Default restricted paths agents should not touch even with shell allow-list. */
|
|
163
|
-
export const SANDBOX_PROTECTED_HINTS = [
|
|
164
|
-
"/etc",
|
|
165
|
-
"/usr",
|
|
166
|
-
"/bin",
|
|
167
|
-
"/sbin",
|
|
168
|
-
"/System",
|
|
169
|
-
pathHomeDotSsh(),
|
|
170
|
-
];
|
|
171
|
-
function pathHomeDotSsh() {
|
|
172
|
-
try {
|
|
173
|
-
return `${os.homedir()}/.ssh`;
|
|
174
|
-
}
|
|
175
|
-
catch {
|
|
176
|
-
return "~/.ssh";
|
|
177
|
-
}
|
|
178
|
-
}
|
|
1
|
+
export * from "./modules/sandbox/sandbox.js";
|
|
179
2
|
//# sourceMappingURL=sandbox.js.map
|
package/dist/sandbox.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sandbox.js","sourceRoot":"","sources":["../src/sandbox.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"sandbox.js","sourceRoot":"","sources":["../src/sandbox.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./modules/security/secrets.js";
|
package/dist/secrets.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secrets.js","sourceRoot":"","sources":["../src/secrets.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC"}
|
package/dist/storage.d.ts
CHANGED
|
@@ -1,274 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { AgentID, LogID, MessageID, TaskID, TraceID } from "./types.js";
|
|
3
|
-
export interface AgentRow {
|
|
4
|
-
name: AgentID;
|
|
5
|
-
state: string;
|
|
6
|
-
task: string;
|
|
7
|
-
last_updated: string;
|
|
8
|
-
}
|
|
9
|
-
export interface MessageRow {
|
|
10
|
-
id?: MessageID;
|
|
11
|
-
timestamp: string;
|
|
12
|
-
from: AgentID;
|
|
13
|
-
to: AgentID;
|
|
14
|
-
category: string;
|
|
15
|
-
content: string;
|
|
16
|
-
traceId: TraceID;
|
|
17
|
-
parentId?: TaskID;
|
|
18
|
-
status: string;
|
|
19
|
-
priority: string;
|
|
20
|
-
requiresApproval: boolean;
|
|
21
|
-
}
|
|
22
|
-
export interface TaskRow {
|
|
23
|
-
id: TaskID;
|
|
24
|
-
traceId: TraceID;
|
|
25
|
-
description: string;
|
|
26
|
-
agent: AgentID;
|
|
27
|
-
status: string;
|
|
28
|
-
priority: string;
|
|
29
|
-
dependencies: string[];
|
|
30
|
-
createdAt?: string;
|
|
31
|
-
}
|
|
32
|
-
export interface LogRow {
|
|
33
|
-
id?: LogID;
|
|
34
|
-
timestamp: string;
|
|
35
|
-
agent: AgentID;
|
|
36
|
-
action: string;
|
|
37
|
-
trace_id?: TraceID;
|
|
38
|
-
status: string;
|
|
39
|
-
summary: string;
|
|
40
|
-
findings?: string;
|
|
41
|
-
prev_hash?: string;
|
|
42
|
-
hash?: string;
|
|
43
|
-
}
|
|
44
|
-
export interface CostDbRow {
|
|
45
|
-
id: number;
|
|
46
|
-
provider: string;
|
|
47
|
-
model: string;
|
|
48
|
-
input_tokens: number;
|
|
49
|
-
output_tokens: number;
|
|
50
|
-
cost: number;
|
|
51
|
-
timestamp: string;
|
|
52
|
-
trace_id: string | null;
|
|
53
|
-
}
|
|
54
|
-
export interface MessageDbRow {
|
|
55
|
-
id: number;
|
|
56
|
-
timestamp: string;
|
|
57
|
-
sender: string;
|
|
58
|
-
receiver: string;
|
|
59
|
-
category: string;
|
|
60
|
-
content: string;
|
|
61
|
-
trace_id: string;
|
|
62
|
-
parent_id: string | null;
|
|
63
|
-
status: string;
|
|
64
|
-
priority: string;
|
|
65
|
-
requires_approval: number;
|
|
66
|
-
}
|
|
67
|
-
export interface TaskDbRow {
|
|
68
|
-
id: string;
|
|
69
|
-
trace_id: string;
|
|
70
|
-
description: string;
|
|
71
|
-
agent: string;
|
|
72
|
-
status: string;
|
|
73
|
-
priority: string;
|
|
74
|
-
dependencies: string;
|
|
75
|
-
created_at: string;
|
|
76
|
-
}
|
|
77
|
-
export interface LogDbRow {
|
|
78
|
-
id: number;
|
|
79
|
-
timestamp: string;
|
|
80
|
-
agent: string;
|
|
81
|
-
action: string;
|
|
82
|
-
trace_id: string | null;
|
|
83
|
-
status: string;
|
|
84
|
-
summary: string;
|
|
85
|
-
findings: string | null;
|
|
86
|
-
prev_hash: string | null;
|
|
87
|
-
hash: string | null;
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Resolves the framework directory (.atabey) intelligently by ascending the directory tree,
|
|
91
|
-
* preventing subpackages and test runners from spraying databases in random subfolders.
|
|
92
|
-
*/
|
|
93
|
-
export declare function resolveFrameworkDir(): string;
|
|
94
|
-
/**
|
|
95
|
-
* [DB] Canonical Atabey Storage Engine (Single Source of Truth)
|
|
96
|
-
* Central SQLite database for enterprise-scale multi-agent state management.
|
|
97
|
-
*/
|
|
98
|
-
export declare class AtabeyStorage {
|
|
99
|
-
private static db;
|
|
100
|
-
static getDB(): Database.Database;
|
|
101
|
-
private static initializeSchema;
|
|
102
|
-
static getKnowledgeList(): Array<{
|
|
103
|
-
filename: string;
|
|
104
|
-
updated_at: string;
|
|
105
|
-
}>;
|
|
106
|
-
static getKnowledgeFile(filename: string): {
|
|
107
|
-
filename: string;
|
|
108
|
-
content: string;
|
|
109
|
-
updated_at: string;
|
|
110
|
-
} | null;
|
|
111
|
-
static saveKnowledgeFile(filename: string, content: string): void;
|
|
112
|
-
static deleteKnowledgeFile(filename: string): boolean;
|
|
113
|
-
static hasUsers(): boolean;
|
|
114
|
-
static getUsers(): Array<{
|
|
115
|
-
name: string;
|
|
116
|
-
token: string;
|
|
117
|
-
role: string;
|
|
118
|
-
}>;
|
|
119
|
-
static getUserByToken(token: string): {
|
|
120
|
-
name: string;
|
|
121
|
-
role: string;
|
|
122
|
-
} | null;
|
|
123
|
-
static createUser(name: string, token: string, role: string): void;
|
|
124
|
-
static deleteUser(name: string): boolean;
|
|
125
|
-
static createAgent(name: string, description: string, skills: string): void;
|
|
126
|
-
static deleteAgent(name: string): boolean;
|
|
127
|
-
static updateAgentDetails(name: string, description: string, state: string, task: string, skills: string): void;
|
|
128
|
-
static onMessageSaved: ((msg: {
|
|
129
|
-
traceId: string;
|
|
130
|
-
category: string;
|
|
131
|
-
}) => void) | null;
|
|
132
|
-
static onMessageStatusUpdated: ((id: number, status: string) => void) | null;
|
|
133
|
-
static saveLog(log: {
|
|
134
|
-
agent: string;
|
|
135
|
-
action: string;
|
|
136
|
-
trace_id?: string;
|
|
137
|
-
status: string;
|
|
138
|
-
summary: string;
|
|
139
|
-
findings?: string;
|
|
140
|
-
}): number;
|
|
141
|
-
static verifyLogIntegrity(): {
|
|
142
|
-
valid: boolean;
|
|
143
|
-
checked?: number;
|
|
144
|
-
failedLogId?: number;
|
|
145
|
-
reason?: string;
|
|
146
|
-
tip?: string;
|
|
147
|
-
};
|
|
148
|
-
static saveCost(cost: {
|
|
149
|
-
provider: string;
|
|
150
|
-
model: string;
|
|
151
|
-
inputTokens: number;
|
|
152
|
-
outputTokens: number;
|
|
153
|
-
cost: number;
|
|
154
|
-
timestamp: string;
|
|
155
|
-
traceId?: string;
|
|
156
|
-
}): void;
|
|
157
|
-
static getAllCosts(): Array<{
|
|
158
|
-
provider: string;
|
|
159
|
-
model: string;
|
|
160
|
-
inputTokens: number;
|
|
161
|
-
outputTokens: number;
|
|
162
|
-
cost: number;
|
|
163
|
-
timestamp: string;
|
|
164
|
-
traceId?: string;
|
|
165
|
-
}>;
|
|
166
|
-
static updateAgentStatus(name: string, state: string, task: string, lastUpdated?: string): void;
|
|
167
|
-
static getAllAgents(): AgentRow[];
|
|
168
|
-
static saveMessage(msg: MessageRow): void;
|
|
169
|
-
static getPendingMessages(): MessageRow[];
|
|
170
|
-
static updateMessageStatus(id: number, status: string): void;
|
|
171
|
-
static saveTask(task: TaskRow): void;
|
|
172
|
-
static getTasks(traceId?: TraceID): TaskRow[];
|
|
173
|
-
static getLogs(agentName?: string): LogRow[];
|
|
174
|
-
static setMetadata(key: string, value: string): void;
|
|
175
|
-
static getMetadata(key: string): string | null;
|
|
176
|
-
static saveLoopCooldown(agent: string, cooldownUntil: number, detail: string | null, cooldownCount?: number): void;
|
|
177
|
-
static getLoopCooldown(agent: string): {
|
|
178
|
-
agent: string;
|
|
179
|
-
cooldownUntil: number;
|
|
180
|
-
detail: string | null;
|
|
181
|
-
cooldownCount: number;
|
|
182
|
-
} | null;
|
|
183
|
-
static clearLoopCooldown(agent: string): boolean;
|
|
184
|
-
static clearAllLoopCooldowns(): void;
|
|
185
|
-
static listActiveLoopCooldowns(): Array<{
|
|
186
|
-
agent: string;
|
|
187
|
-
cooldownUntil: number;
|
|
188
|
-
detail: string | null;
|
|
189
|
-
cooldownCount: number;
|
|
190
|
-
}>;
|
|
191
|
-
static purgeExpiredLoopCooldowns(): number;
|
|
192
|
-
static saveApproval(app: {
|
|
193
|
-
traceId: string;
|
|
194
|
-
toolName: string;
|
|
195
|
-
agent: string;
|
|
196
|
-
riskScore: number;
|
|
197
|
-
riskLevel: string;
|
|
198
|
-
reason: string;
|
|
199
|
-
args: Record<string, unknown>;
|
|
200
|
-
createdAt: number;
|
|
201
|
-
expiresAt: number;
|
|
202
|
-
status?: "PENDING" | "APPROVED" | "REJECTED" | "EXPIRED";
|
|
203
|
-
passcode?: string;
|
|
204
|
-
}): void;
|
|
205
|
-
static saveApprovalRequest(request: {
|
|
206
|
-
traceId: string;
|
|
207
|
-
toolName: string;
|
|
208
|
-
agent: string;
|
|
209
|
-
riskScore: number;
|
|
210
|
-
riskLevel: string;
|
|
211
|
-
reason: string;
|
|
212
|
-
args: Record<string, unknown>;
|
|
213
|
-
createdAt: number;
|
|
214
|
-
expiresAt: number;
|
|
215
|
-
status?: "PENDING" | "APPROVED" | "REJECTED" | "EXPIRED";
|
|
216
|
-
passcode?: string;
|
|
217
|
-
}): void;
|
|
218
|
-
static getApproval(traceId: string): {
|
|
219
|
-
traceId: string;
|
|
220
|
-
toolName: string;
|
|
221
|
-
agent: string;
|
|
222
|
-
riskScore: number;
|
|
223
|
-
riskLevel: string;
|
|
224
|
-
reason: string;
|
|
225
|
-
args: Record<string, unknown>;
|
|
226
|
-
createdAt: number;
|
|
227
|
-
expiresAt: number;
|
|
228
|
-
status: "PENDING" | "APPROVED" | "REJECTED" | "EXPIRED";
|
|
229
|
-
passcode?: string;
|
|
230
|
-
} | null;
|
|
231
|
-
static getPendingApprovals(): Array<{
|
|
232
|
-
traceId: string;
|
|
233
|
-
toolName: string;
|
|
234
|
-
agent: string;
|
|
235
|
-
riskScore: number;
|
|
236
|
-
riskLevel: string;
|
|
237
|
-
reason: string;
|
|
238
|
-
args: Record<string, unknown>;
|
|
239
|
-
createdAt: number;
|
|
240
|
-
expiresAt: number;
|
|
241
|
-
status: "PENDING" | "APPROVED" | "REJECTED" | "EXPIRED";
|
|
242
|
-
passcode?: string;
|
|
243
|
-
}>;
|
|
244
|
-
static updateApprovalStatus(traceId: string, status: string): void;
|
|
245
|
-
static clearAllApprovals(): void;
|
|
246
|
-
static saveDiscipline(agent: string, stats: {
|
|
247
|
-
totalCalls: number;
|
|
248
|
-
violations: number;
|
|
249
|
-
lastViolation: string | null;
|
|
250
|
-
cooldownUntil: number;
|
|
251
|
-
}): void;
|
|
252
|
-
static getDiscipline(agent: string): {
|
|
253
|
-
agent: string;
|
|
254
|
-
totalCalls: number;
|
|
255
|
-
violations: number;
|
|
256
|
-
lastViolation: string | null;
|
|
257
|
-
cooldownUntil: number;
|
|
258
|
-
} | null;
|
|
259
|
-
static getAllDiscipline(): Array<{
|
|
260
|
-
agent: string;
|
|
261
|
-
totalCalls: number;
|
|
262
|
-
violations: number;
|
|
263
|
-
lastViolation: string | null;
|
|
264
|
-
cooldownUntil: number;
|
|
265
|
-
}>;
|
|
266
|
-
static clearAllDiscipline(): void;
|
|
267
|
-
static checkIntegrity(): {
|
|
268
|
-
ok: boolean;
|
|
269
|
-
message: string;
|
|
270
|
-
};
|
|
271
|
-
static reset(): void;
|
|
272
|
-
}
|
|
273
|
-
/** Canonical alias */
|
|
274
|
-
export declare const Storage: typeof AtabeyStorage;
|
|
1
|
+
export * from "./modules/storage/storage.js";
|