atabey-shared 0.1.0-beta.0 → 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.
Files changed (221) hide show
  1. package/README.md +63 -24
  2. package/dist/agent-identity.d.ts +1 -34
  3. package/dist/agent-identity.js +1 -76
  4. package/dist/agent-identity.js.map +1 -1
  5. package/dist/api-catalog.d.ts +1 -57
  6. package/dist/api-catalog.js +1 -253
  7. package/dist/api-catalog.js.map +1 -1
  8. package/dist/audit-chain.d.ts +1 -80
  9. package/dist/audit-chain.js +1 -261
  10. package/dist/audit-chain.js.map +1 -1
  11. package/dist/audit.d.ts +1 -121
  12. package/dist/audit.js +1 -321
  13. package/dist/audit.js.map +1 -1
  14. package/dist/constants.d.ts +1 -153
  15. package/dist/constants.js +1 -214
  16. package/dist/constants.js.map +1 -1
  17. package/dist/database.d.ts +1 -5
  18. package/dist/database.js +1 -12
  19. package/dist/database.js.map +1 -1
  20. package/dist/errors.d.ts +1 -46
  21. package/dist/errors.js +1 -68
  22. package/dist/errors.js.map +1 -1
  23. package/dist/file-lock.d.ts +1 -93
  24. package/dist/file-lock.js +1 -239
  25. package/dist/file-lock.js.map +1 -1
  26. package/dist/fs.d.ts +1 -9
  27. package/dist/fs.js +1 -53
  28. package/dist/fs.js.map +1 -1
  29. package/dist/index.d.ts +2 -31
  30. package/dist/index.js +2 -31
  31. package/dist/index.js.map +1 -1
  32. package/dist/job-queue.d.ts +1 -53
  33. package/dist/job-queue.js +1 -126
  34. package/dist/job-queue.js.map +1 -1
  35. package/dist/lock.d.ts +1 -82
  36. package/dist/lock.js +1 -158
  37. package/dist/lock.js.map +1 -1
  38. package/dist/logger.d.ts +1 -31
  39. package/dist/logger.js +1 -152
  40. package/dist/logger.js.map +1 -1
  41. package/dist/memory-prune.d.ts +1 -18
  42. package/dist/memory-prune.js +1 -47
  43. package/dist/memory-prune.js.map +1 -1
  44. package/dist/migrations.d.ts +1 -69
  45. package/dist/migrations.js +1 -374
  46. package/dist/migrations.js.map +1 -1
  47. package/dist/modules/agent/agent-identity.d.ts +34 -0
  48. package/dist/modules/agent/agent-identity.js +77 -0
  49. package/dist/modules/agent/agent-identity.js.map +1 -0
  50. package/dist/modules/agent/api-catalog.d.ts +57 -0
  51. package/dist/modules/agent/api-catalog.js +254 -0
  52. package/dist/modules/agent/api-catalog.js.map +1 -0
  53. package/dist/modules/agent/index.d.ts +3 -0
  54. package/dist/modules/agent/index.js +4 -0
  55. package/dist/modules/agent/index.js.map +1 -0
  56. package/dist/modules/agent/tokenizer.d.ts +54 -0
  57. package/dist/modules/agent/tokenizer.js +272 -0
  58. package/dist/modules/agent/tokenizer.js.map +1 -0
  59. package/dist/modules/concurrency/file-lock.d.ts +93 -0
  60. package/dist/modules/concurrency/file-lock.js +240 -0
  61. package/dist/modules/concurrency/file-lock.js.map +1 -0
  62. package/dist/modules/concurrency/index.d.ts +6 -0
  63. package/dist/modules/concurrency/index.js +7 -0
  64. package/dist/modules/concurrency/index.js.map +1 -0
  65. package/dist/modules/concurrency/job-queue.d.ts +76 -0
  66. package/dist/modules/concurrency/job-queue.js +200 -0
  67. package/dist/modules/concurrency/job-queue.js.map +1 -0
  68. package/dist/modules/concurrency/lock.d.ts +82 -0
  69. package/dist/modules/concurrency/lock.js +159 -0
  70. package/dist/modules/concurrency/lock.js.map +1 -0
  71. package/dist/modules/concurrency/resilience.d.ts +84 -0
  72. package/dist/modules/concurrency/resilience.js +217 -0
  73. package/dist/modules/concurrency/resilience.js.map +1 -0
  74. package/dist/modules/concurrency/worker-pool.d.ts +52 -0
  75. package/dist/modules/concurrency/worker-pool.js +229 -0
  76. package/dist/modules/concurrency/worker-pool.js.map +1 -0
  77. package/dist/modules/concurrency/worker-thread.d.ts +21 -0
  78. package/dist/modules/concurrency/worker-thread.js +67 -0
  79. package/dist/modules/concurrency/worker-thread.js.map +1 -0
  80. package/dist/modules/index.d.ts +14 -0
  81. package/dist/modules/index.js +15 -0
  82. package/dist/modules/index.js.map +1 -0
  83. package/dist/modules/observability/audit-chain.d.ts +80 -0
  84. package/dist/modules/observability/audit-chain.js +262 -0
  85. package/dist/modules/observability/audit-chain.js.map +1 -0
  86. package/dist/modules/observability/audit.d.ts +121 -0
  87. package/dist/modules/observability/audit.js +322 -0
  88. package/dist/modules/observability/audit.js.map +1 -0
  89. package/dist/modules/observability/index.d.ts +4 -0
  90. package/dist/modules/observability/index.js +5 -0
  91. package/dist/modules/observability/index.js.map +1 -0
  92. package/dist/modules/observability/logger.d.ts +31 -0
  93. package/dist/modules/observability/logger.js +153 -0
  94. package/dist/modules/observability/logger.js.map +1 -0
  95. package/dist/modules/observability/otel.d.ts +39 -0
  96. package/dist/modules/observability/otel.js +93 -0
  97. package/dist/modules/observability/otel.js.map +1 -0
  98. package/dist/modules/primitives/constants.d.ts +150 -0
  99. package/dist/modules/primitives/constants.js +212 -0
  100. package/dist/modules/primitives/constants.js.map +1 -0
  101. package/dist/modules/primitives/errors.d.ts +46 -0
  102. package/dist/modules/primitives/errors.js +69 -0
  103. package/dist/modules/primitives/errors.js.map +1 -0
  104. package/dist/modules/primitives/fs.d.ts +9 -0
  105. package/dist/modules/primitives/fs.js +54 -0
  106. package/dist/modules/primitives/fs.js.map +1 -0
  107. package/dist/modules/primitives/index.d.ts +7 -0
  108. package/dist/modules/primitives/index.js +8 -0
  109. package/dist/modules/primitives/index.js.map +1 -0
  110. package/dist/modules/primitives/outbound-http.d.ts +32 -0
  111. package/dist/modules/primitives/outbound-http.js +88 -0
  112. package/dist/modules/primitives/outbound-http.js.map +1 -0
  113. package/dist/modules/primitives/string.d.ts +1 -0
  114. package/dist/modules/primitives/string.js +30 -0
  115. package/dist/modules/primitives/string.js.map +1 -0
  116. package/dist/modules/primitives/time.d.ts +5 -0
  117. package/dist/modules/primitives/time.js +35 -0
  118. package/dist/modules/primitives/time.js.map +1 -0
  119. package/dist/modules/primitives/types.d.ts +27 -0
  120. package/dist/modules/primitives/types.js +17 -0
  121. package/dist/modules/primitives/types.js.map +1 -0
  122. package/dist/modules/sandbox/index.d.ts +3 -0
  123. package/dist/modules/sandbox/index.js +4 -0
  124. package/dist/modules/sandbox/index.js.map +1 -0
  125. package/dist/modules/sandbox/sandbox-fs.d.ts +28 -0
  126. package/dist/modules/sandbox/sandbox-fs.js +143 -0
  127. package/dist/modules/sandbox/sandbox-fs.js.map +1 -0
  128. package/dist/modules/sandbox/sandbox-runtime.d.ts +78 -0
  129. package/dist/modules/sandbox/sandbox-runtime.js +282 -0
  130. package/dist/modules/sandbox/sandbox-runtime.js.map +1 -0
  131. package/dist/modules/sandbox/sandbox.d.ts +54 -0
  132. package/dist/modules/sandbox/sandbox.js +179 -0
  133. package/dist/modules/sandbox/sandbox.js.map +1 -0
  134. package/dist/modules/security/index.d.ts +5 -0
  135. package/dist/modules/security/index.js +6 -0
  136. package/dist/modules/security/index.js.map +1 -0
  137. package/dist/modules/security/pii.d.ts +70 -0
  138. package/dist/modules/security/pii.js +276 -0
  139. package/dist/modules/security/pii.js.map +1 -0
  140. package/dist/modules/security/policy-gate.d.ts +42 -0
  141. package/dist/modules/security/policy-gate.js +172 -0
  142. package/dist/modules/security/policy-gate.js.map +1 -0
  143. package/dist/modules/security/retention.d.ts +68 -0
  144. package/dist/modules/security/retention.js +218 -0
  145. package/dist/modules/security/retention.js.map +1 -0
  146. package/dist/modules/security/secrets.d.ts +99 -0
  147. package/dist/modules/security/secrets.js +371 -0
  148. package/dist/modules/security/secrets.js.map +1 -0
  149. package/dist/modules/security/tls.d.ts +87 -0
  150. package/dist/modules/security/tls.js +154 -0
  151. package/dist/modules/security/tls.js.map +1 -0
  152. package/dist/modules/storage/database.d.ts +6 -0
  153. package/dist/modules/storage/database.js +16 -0
  154. package/dist/modules/storage/database.js.map +1 -0
  155. package/dist/modules/storage/index.d.ts +4 -0
  156. package/dist/modules/storage/index.js +5 -0
  157. package/dist/modules/storage/index.js.map +1 -0
  158. package/dist/modules/storage/memory-prune.d.ts +18 -0
  159. package/dist/modules/storage/memory-prune.js +48 -0
  160. package/dist/modules/storage/memory-prune.js.map +1 -0
  161. package/dist/modules/storage/migrations.d.ts +69 -0
  162. package/dist/modules/storage/migrations.js +394 -0
  163. package/dist/modules/storage/migrations.js.map +1 -0
  164. package/dist/modules/storage/storage.d.ts +341 -0
  165. package/dist/modules/storage/storage.js +1004 -0
  166. package/dist/modules/storage/storage.js.map +1 -0
  167. package/dist/otel.d.ts +1 -39
  168. package/dist/otel.js +1 -92
  169. package/dist/otel.js.map +1 -1
  170. package/dist/outbound-http.d.ts +1 -32
  171. package/dist/outbound-http.js +1 -87
  172. package/dist/outbound-http.js.map +1 -1
  173. package/dist/pii.d.ts +1 -70
  174. package/dist/pii.js +1 -275
  175. package/dist/pii.js.map +1 -1
  176. package/dist/policy-gate.d.ts +1 -42
  177. package/dist/policy-gate.js +1 -171
  178. package/dist/policy-gate.js.map +1 -1
  179. package/dist/resilience.d.ts +1 -84
  180. package/dist/resilience.js +1 -216
  181. package/dist/resilience.js.map +1 -1
  182. package/dist/retention.d.ts +1 -68
  183. package/dist/retention.js +1 -217
  184. package/dist/retention.js.map +1 -1
  185. package/dist/sandbox-fs.d.ts +1 -28
  186. package/dist/sandbox-fs.js +1 -142
  187. package/dist/sandbox-fs.js.map +1 -1
  188. package/dist/sandbox-runtime.d.ts +1 -78
  189. package/dist/sandbox-runtime.js +1 -281
  190. package/dist/sandbox-runtime.js.map +1 -1
  191. package/dist/sandbox.d.ts +1 -54
  192. package/dist/sandbox.js +1 -178
  193. package/dist/sandbox.js.map +1 -1
  194. package/dist/secrets.d.ts +1 -99
  195. package/dist/secrets.js +1 -370
  196. package/dist/secrets.js.map +1 -1
  197. package/dist/storage.d.ts +1 -341
  198. package/dist/storage.js +1 -1003
  199. package/dist/storage.js.map +1 -1
  200. package/dist/string.d.ts +1 -1
  201. package/dist/string.js +1 -29
  202. package/dist/string.js.map +1 -1
  203. package/dist/time.d.ts +1 -5
  204. package/dist/time.js +1 -34
  205. package/dist/time.js.map +1 -1
  206. package/dist/tls.d.ts +1 -87
  207. package/dist/tls.js +1 -153
  208. package/dist/tls.js.map +1 -1
  209. package/dist/tokenizer.d.ts +1 -54
  210. package/dist/tokenizer.js +1 -271
  211. package/dist/tokenizer.js.map +1 -1
  212. package/dist/types.d.ts +1 -27
  213. package/dist/types.js +1 -16
  214. package/dist/types.js.map +1 -1
  215. package/dist/worker-pool.d.ts +1 -52
  216. package/dist/worker-pool.js +1 -228
  217. package/dist/worker-pool.js.map +1 -1
  218. package/dist/worker-thread.d.ts +1 -21
  219. package/dist/worker-thread.js +1 -66
  220. package/dist/worker-thread.js.map +1 -1
  221. package/package.json +44 -34
package/dist/file-lock.js CHANGED
@@ -1,240 +1,2 @@
1
- /**
2
- * Atomic File-Based Locking — OS-level exclusive create via open('wx').
3
- *
4
- * Replaces check-then-act lock races. No Redis/Redlock required.
5
- *
6
- * Pattern:
7
- * resource → .atabey/locks/<relative>.lock (created with O_EXCL / 'wx')
8
- * holder writes JSON metadata after exclusive create
9
- * release unlinks the lock file
10
- *
11
- * Stale locks (TTL exceeded) are reclaimed atomically when possible.
12
- */
13
- import fs from "fs";
14
- import os from "os";
15
- import path from "path";
16
- export class AtomicFileLock {
17
- locksDir;
18
- projectRoot;
19
- ttlMs;
20
- retryMs;
21
- timeoutMs;
22
- constructor(options = {}) {
23
- this.projectRoot = options.projectRoot ?? process.cwd();
24
- this.locksDir = options.locksDir
25
- ? path.resolve(options.locksDir)
26
- : path.join(this.projectRoot, ".atabey", "locks");
27
- this.ttlMs = options.ttlMs ?? 5 * 60 * 1000;
28
- this.retryMs = options.retryMs ?? 50;
29
- this.timeoutMs = options.timeoutMs ?? 10_000;
30
- }
31
- /** Absolute path of the lock file for a resource. */
32
- getLockPath(resource) {
33
- const abs = path.isAbsolute(resource)
34
- ? resource
35
- : path.resolve(this.projectRoot, resource);
36
- let relative = path.relative(this.projectRoot, abs);
37
- if (relative === ".." || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {
38
- // Outside project root — hash path to avoid escaping locks dir
39
- relative = `_ext/${Buffer.from(abs).toString("base64url")}`;
40
- }
41
- // Normalize separators for cross-platform lock paths
42
- relative = relative.split(path.sep).join("/");
43
- return path.join(this.locksDir, `${relative}.lock`);
44
- }
45
- /**
46
- * Try to acquire a lock once (non-blocking).
47
- * Uses atomic exclusive file create (`wx` = O_CREAT | O_EXCL | O_WRONLY).
48
- */
49
- tryAcquire(resource, ownerId, reason, _reclaimDepth = 0) {
50
- const lockPath = this.getLockPath(resource);
51
- fs.mkdirSync(path.dirname(lockPath), { recursive: true });
52
- // Reclaim stale lock first (best-effort, still atomic on create)
53
- this.reclaimIfStale(lockPath);
54
- const now = Date.now();
55
- const meta = {
56
- ownerId,
57
- resource,
58
- acquiredAt: new Date(now).toISOString(),
59
- expiresAt: new Date(now + this.ttlMs).toISOString(),
60
- reason,
61
- pid: process.pid,
62
- hostname: os.hostname(),
63
- };
64
- try {
65
- // Atomic exclusive create WITH content in one syscall sequence
66
- // (writeFileSync + flag 'wx' = O_CREAT|O_EXCL|O_WRONLY): there is no
67
- // window where the lock file exists empty for a reader to misread.
68
- fs.writeFileSync(lockPath, JSON.stringify(meta, null, 2), { encoding: "utf8", flag: "wx" });
69
- return { acquired: true, meta };
70
- }
71
- catch (err) {
72
- const code = err.code;
73
- if (code === "EEXIST") {
74
- // Another process holds it. Reclaim only if corrupt/empty or expired.
75
- const heldBy = this.readMeta(lockPath) ?? undefined;
76
- if ((!heldBy || this.isExpired(heldBy)) && _reclaimDepth < 1) {
77
- this.forceRemove(lockPath, heldBy ?? null);
78
- return this.tryAcquire(resource, ownerId, reason, _reclaimDepth + 1);
79
- }
80
- return { acquired: false, heldBy };
81
- }
82
- throw err;
83
- }
84
- }
85
- /**
86
- * Acquire with async retry until timeout.
87
- */
88
- async acquireAsync(resource, ownerId, options) {
89
- const timeoutMs = options?.timeoutMs ?? this.timeoutMs;
90
- const retryMs = options?.retryMs ?? this.retryMs;
91
- const start = Date.now();
92
- while (true) {
93
- const result = this.tryAcquire(resource, ownerId, options?.reason);
94
- if (result.acquired && result.meta) {
95
- return result.meta;
96
- }
97
- if (Date.now() - start >= timeoutMs) {
98
- const holder = result.heldBy?.ownerId ?? "unknown";
99
- throw new Error(`[AtomicFileLock] Timeout acquiring lock for "${resource}" after ${timeoutMs}ms (held by ${holder})`);
100
- }
101
- await sleep(retryMs);
102
- }
103
- }
104
- /**
105
- * Release lock only if owned by ownerId (or force=true).
106
- */
107
- release(resource, ownerId, force = false) {
108
- const lockPath = this.getLockPath(resource);
109
- if (!fs.existsSync(lockPath))
110
- return true;
111
- const meta = this.readMeta(lockPath);
112
- if (!meta) {
113
- // Corrupt/empty lock — safe to drop (atomic create means a real
114
- // holder always has readable meta).
115
- this.forceRemove(lockPath, null);
116
- return true;
117
- }
118
- if (!force && meta.ownerId !== ownerId) {
119
- return false;
120
- }
121
- this.forceRemove(lockPath, meta);
122
- return true;
123
- }
124
- isLocked(resource) {
125
- const lockPath = this.getLockPath(resource);
126
- if (!fs.existsSync(lockPath))
127
- return null;
128
- const meta = this.readMeta(lockPath);
129
- if (!meta)
130
- return null;
131
- if (this.isExpired(meta)) {
132
- this.forceRemove(lockPath, meta);
133
- return null;
134
- }
135
- return meta;
136
- }
137
- /**
138
- * Run `fn` while holding the lock.
139
- * ALWAYS releases in `finally` even if `fn` throws (disk full, parse errors, etc.).
140
- * Without this, a leftover `.lock` file would deadlock every subsequent writer until TTL.
141
- *
142
- * Prefer this API over bare acquire/release for any mutating work.
143
- */
144
- async withLock(resource, ownerId, fn, options) {
145
- await this.acquireAsync(resource, ownerId, options);
146
- try {
147
- return await fn();
148
- }
149
- finally {
150
- // Never let release errors mask the original failure or leave a lock.
151
- try {
152
- this.release(resource, ownerId);
153
- }
154
- catch {
155
- this.forceRemove(this.getLockPath(resource), null);
156
- }
157
- // Belt-and-suspenders: if our lock is somehow still present, force drop it.
158
- const stillHeld = this.isLocked(resource);
159
- if (stillHeld && stillHeld.ownerId === ownerId) {
160
- this.forceRemove(this.getLockPath(resource), stillHeld);
161
- }
162
- }
163
- }
164
- /**
165
- * Synchronous withLock — same try/finally release guarantee.
166
- */
167
- withLockSync(resource, ownerId, fn, options) {
168
- const result = this.tryAcquire(resource, ownerId, options?.reason);
169
- if (!result.acquired) {
170
- const holder = result.heldBy?.ownerId ?? "unknown";
171
- throw new Error(`[AtomicFileLock] Could not acquire lock for "${resource}" (held by ${holder})`);
172
- }
173
- try {
174
- return fn();
175
- }
176
- finally {
177
- try {
178
- this.release(resource, ownerId);
179
- }
180
- catch {
181
- this.forceRemove(this.getLockPath(resource), null);
182
- }
183
- const stillHeld = this.isLocked(resource);
184
- if (stillHeld && stillHeld.ownerId === ownerId) {
185
- this.forceRemove(this.getLockPath(resource), stillHeld);
186
- }
187
- }
188
- }
189
- reclaimIfStale(lockPath) {
190
- if (!fs.existsSync(lockPath))
191
- return;
192
- if (this.isReclaimable(lockPath)) {
193
- this.forceRemove(lockPath, this.readMeta(lockPath));
194
- }
195
- }
196
- /**
197
- * True when an existing lock file may be safely stolen: unparseable/empty
198
- * (corrupt, e.g. crashed mid-write) or past its TTL.
199
- */
200
- isReclaimable(lockPath) {
201
- const meta = this.readMeta(lockPath);
202
- if (!meta)
203
- return true;
204
- return this.isExpired(meta);
205
- }
206
- isExpired(meta) {
207
- const exp = Date.parse(meta.expiresAt);
208
- if (Number.isNaN(exp)) {
209
- // Fallback: acquiredAt + ttl
210
- const acq = Date.parse(meta.acquiredAt);
211
- return Number.isNaN(acq) ? true : Date.now() - acq > this.ttlMs;
212
- }
213
- return Date.now() > exp;
214
- }
215
- readMeta(lockPath) {
216
- try {
217
- const raw = fs.readFileSync(lockPath, "utf8");
218
- return JSON.parse(raw);
219
- }
220
- catch {
221
- return null;
222
- }
223
- }
224
- forceRemove(lockPath, _meta) {
225
- try {
226
- fs.unlinkSync(lockPath);
227
- }
228
- catch {
229
- // ignore ENOENT races
230
- }
231
- }
232
- }
233
- function sleep(ms) {
234
- return new Promise((r) => setTimeout(r, ms));
235
- }
236
- /** Convenience: lock under project `.atabey/locks`. */
237
- export function createProjectFileLock(projectRoot, options) {
238
- return new AtomicFileLock({ ...options, projectRoot });
239
- }
1
+ export * from "./modules/concurrency/file-lock.js";
240
2
  //# sourceMappingURL=file-lock.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"file-lock.js","sourceRoot":"","sources":["../src/file-lock.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAyBxB,MAAM,OAAO,cAAc;IACN,QAAQ,CAAS;IACjB,WAAW,CAAS;IACpB,KAAK,CAAS;IACd,OAAO,CAAS;IAChB,SAAS,CAAS;IAEnC,YAAY,UAA2B,EAAE;QACrC,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;QACxD,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ;YAC5B,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC;YAChC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;QACtD,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;QAC5C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC;QACrC,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,MAAM,CAAC;IACjD,CAAC;IAED,qDAAqD;IAC9C,WAAW,CAAC,QAAgB;QAC/B,MAAM,GAAG,GAAG,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC;YACjC,CAAC,CAAC,QAAQ;YACV,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC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AAS,KAAK,CAAC,EAAU;IACrB,OAAO,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AACjD,CAAC;AAED,uDAAuD;AACvD,MAAM,UAAU,qBAAqB,CAAC,WAAmB,EAAE,OAA8C;IACrG,OAAO,IAAI,cAAc,CAAC,EAAE,GAAG,OAAO,EAAE,WAAW,EAAE,CAAC,CAAC;AAC3D,CAAC"}
1
+ {"version":3,"file":"file-lock.js","sourceRoot":"","sources":["../src/file-lock.ts"],"names":[],"mappings":"AAAA,cAAc,oCAAoC,CAAC"}
package/dist/fs.d.ts CHANGED
@@ -1,9 +1 @@
1
- export declare function ensureDir(dirPath: string, dryRun?: boolean): void;
2
- /**
3
- * Writes content to a file atomically by using a temporary file.
4
- * This prevents data corruption during unexpected system failures.
5
- */
6
- export declare function writeTextFile(filePath: string, content: string, dryRun?: boolean): void;
7
- export declare function appendFile(filePath: string, content: string, dryRun?: boolean): void;
8
- export declare function writeJsonFile(filePath: string, value: unknown, dryRun?: boolean): void;
9
- export declare function runCommandQuiet(command: string, args: string[], cwd: string): void;
1
+ export * from "./modules/primitives/fs.js";
package/dist/fs.js CHANGED
@@ -1,54 +1,2 @@
1
- import { execFileSync } from "child_process";
2
- import fs from "fs";
3
- import path from "path";
4
- import { logger } from "./logger.js";
5
- export function ensureDir(dirPath, dryRun = false) {
6
- if (!fs.existsSync(dirPath)) {
7
- if (dryRun) {
8
- logger.info(`[DRY RUN] Would create directory: ${dirPath}`);
9
- }
10
- else {
11
- fs.mkdirSync(dirPath, { recursive: true });
12
- }
13
- }
14
- }
15
- /**
16
- * Writes content to a file atomically by using a temporary file.
17
- * This prevents data corruption during unexpected system failures.
18
- */
19
- export function writeTextFile(filePath, content, dryRun = false) {
20
- if (dryRun) {
21
- logger.info(`[DRY RUN] Would write file: ${filePath}`);
22
- return;
23
- }
24
- const dir = path.dirname(filePath);
25
- ensureDir(dir);
26
- const tempPath = `${filePath}.${Math.random().toString(36).slice(2, 9)}.tmp`;
27
- const finalContent = content.endsWith("\n") ? content : `${content}\n`;
28
- try {
29
- fs.writeFileSync(tempPath, finalContent, "utf8");
30
- fs.renameSync(tempPath, filePath);
31
- }
32
- catch (err) {
33
- if (fs.existsSync(tempPath))
34
- fs.unlinkSync(tempPath);
35
- throw err;
36
- }
37
- }
38
- export function appendFile(filePath, content, dryRun = false) {
39
- if (dryRun) {
40
- logger.info(`[DRY RUN] Would append to file: ${filePath}`);
41
- return;
42
- }
43
- ensureDir(path.dirname(filePath));
44
- // Atomic append: oku → ekle → atomic yaz
45
- const existing = fs.existsSync(filePath) ? fs.readFileSync(filePath, "utf8") : "";
46
- writeTextFile(filePath, existing + content);
47
- }
48
- export function writeJsonFile(filePath, value, dryRun = false) {
49
- writeTextFile(filePath, JSON.stringify(value, null, 2), dryRun);
50
- }
51
- export function runCommandQuiet(command, args, cwd) {
52
- execFileSync(command, args, { cwd, stdio: "ignore" });
53
- }
1
+ export * from "./modules/primitives/fs.js";
54
2
  //# sourceMappingURL=fs.js.map
package/dist/fs.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"fs.js","sourceRoot":"","sources":["../src/fs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,MAAM,UAAU,SAAS,CAAC,OAAe,EAAE,MAAM,GAAG,KAAK;IACrD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QAC1B,IAAI,MAAM,EAAE,CAAC;YACT,MAAM,CAAC,IAAI,CAAC,qCAAqC,OAAO,EAAE,CAAC,CAAC;QAChE,CAAC;aAAM,CAAC;YACJ,EAAE,CAAC,SAAS,CAAC,OAAO,EAAE,EA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AAQ,CAAC,CAAC,CAAC;IAClC,yCAAyC;IACzC,MAAM,QAAQ,GAAG,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAClF,aAAa,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,CAAC;AAChD,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,QAAgB,EAAE,KAAc,EAAE,MAAM,GAAG,KAAK;IAC1E,aAAa,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AACpE,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,OAAe,EAAE,IAAc,EAAE,GAAW;IACxE,YAAY,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;AAC1D,CAAC"}
1
+ {"version":3,"file":"fs.js","sourceRoot":"","sources":["../src/fs.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,31 +1,2 @@
1
- export * from "./database.js";
2
- export * from "./pii.js";
3
- export * from "./lock.js";
4
- export * from "./audit.js";
5
- export * from "./audit-chain.js";
6
- export * from "./logger.js";
7
- export * from "./retention.js";
8
- export * from "./errors.js";
9
- export * from "./constants.js";
10
- export * from "./string.js";
11
- export * from "./types.js";
12
- export * from "./fs.js";
13
- export * from "./job-queue.js";
14
- export * from "./worker-pool.js";
15
- export * from "./file-lock.js";
16
- export * from "./sandbox.js";
17
- export * from "./sandbox-runtime.js";
18
- export * from "./sandbox-fs.js";
19
- export * from "./resilience.js";
20
- export * from "./policy-gate.js";
21
- export * from "./storage.js";
22
- export * from "./time.js";
23
- export * from "./secrets.js";
24
- export * from "./tokenizer.js";
25
- export * from "./migrations.js";
26
- export * from "./tls.js";
27
- export * from "./outbound-http.js";
28
- export * from "./api-catalog.js";
29
- export * from "./agent-identity.js";
30
- export * from "./memory-prune.js";
31
- export * from "./otel.js";
1
+ export * from "./modules/index.js";
2
+ export * as Modules from "./modules/index.js";
package/dist/index.js CHANGED
@@ -1,32 +1,3 @@
1
- export * from "./database.js";
2
- export * from "./pii.js";
3
- export * from "./lock.js";
4
- export * from "./audit.js";
5
- export * from "./audit-chain.js";
6
- export * from "./logger.js";
7
- export * from "./retention.js";
8
- export * from "./errors.js";
9
- export * from "./constants.js";
10
- export * from "./string.js";
11
- export * from "./types.js";
12
- export * from "./fs.js";
13
- export * from "./job-queue.js";
14
- export * from "./worker-pool.js";
15
- export * from "./file-lock.js";
16
- export * from "./sandbox.js";
17
- export * from "./sandbox-runtime.js";
18
- export * from "./sandbox-fs.js";
19
- export * from "./resilience.js";
20
- export * from "./policy-gate.js";
21
- export * from "./storage.js";
22
- export * from "./time.js";
23
- export * from "./secrets.js";
24
- export * from "./tokenizer.js";
25
- export * from "./migrations.js";
26
- export * from "./tls.js";
27
- export * from "./outbound-http.js";
28
- export * from "./api-catalog.js";
29
- export * from "./agent-identity.js";
30
- export * from "./memory-prune.js";
31
- export * from "./otel.js";
1
+ export * from "./modules/index.js";
2
+ export * as Modules from "./modules/index.js";
32
3
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,WAAW,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,OAAO,KAAK,OAAO,MAAM,oBAAoB,CAAC"}
@@ -1,53 +1 @@
1
- /**
2
- * In-Memory Job Queue — concurrency-limited async work dispatcher.
3
- *
4
- * Prevents unbounded parallel LLM / agent work from ballooning memory
5
- * or starving the main event loop. No Redis / BullMQ required.
6
- *
7
- * Jobs run on the calling process (async functions). Pair with WorkerPool
8
- * when true thread isolation is needed for CPU-bound work.
9
- */
10
- export interface JobQueueOptions {
11
- /** Max concurrent running jobs. Default: os.cpus().length (min 1, max 16). */
12
- maxConcurrency?: number;
13
- /** Optional name for diagnostics. */
14
- name?: string;
15
- /** Called when a job fails (after the promise rejects to the caller). */
16
- onError?: (error: unknown, jobId: number) => void;
17
- }
18
- export interface JobQueueStats {
19
- name: string;
20
- maxConcurrency: number;
21
- running: number;
22
- pending: number;
23
- completed: number;
24
- failed: number;
25
- }
26
- export declare class InMemoryJobQueue {
27
- private readonly maxConcurrency;
28
- private readonly name;
29
- private readonly onError?;
30
- private readonly pending;
31
- private running;
32
- private nextId;
33
- private completed;
34
- private failed;
35
- private closed;
36
- constructor(options?: JobQueueOptions);
37
- /**
38
- * Enqueue an async job. Resolves/rejects with the job result.
39
- * Back-pressures via wait in the queue — does not spawn unbounded work.
40
- */
41
- enqueue<T>(fn: () => Promise<T>): Promise<T>;
42
- /** Current queue diagnostics. */
43
- getStats(): JobQueueStats;
44
- /** Reject pending jobs and stop accepting new ones. In-flight jobs finish. */
45
- close(reason?: string): void;
46
- /** Wait until running + pending reach zero (or timeout). */
47
- drain(timeoutMs?: number): Promise<void>;
48
- private pump;
49
- private execute;
50
- }
51
- export declare function getAgentJobQueue(options?: JobQueueOptions): InMemoryJobQueue;
52
- /** Test helper — reset singleton. */
53
- export declare function resetAgentJobQueue(): void;
1
+ export * from "./modules/concurrency/job-queue.js";
package/dist/job-queue.js CHANGED
@@ -1,127 +1,2 @@
1
- /**
2
- * In-Memory Job Queue — concurrency-limited async work dispatcher.
3
- *
4
- * Prevents unbounded parallel LLM / agent work from ballooning memory
5
- * or starving the main event loop. No Redis / BullMQ required.
6
- *
7
- * Jobs run on the calling process (async functions). Pair with WorkerPool
8
- * when true thread isolation is needed for CPU-bound work.
9
- */
10
- import os from "os";
11
- export class InMemoryJobQueue {
12
- maxConcurrency;
13
- name;
14
- onError;
15
- pending = [];
16
- running = 0;
17
- nextId = 1;
18
- completed = 0;
19
- failed = 0;
20
- closed = false;
21
- constructor(options = {}) {
22
- const cpus = Math.max(1, os.cpus()?.length || 1);
23
- const requested = options.maxConcurrency ?? cpus;
24
- this.maxConcurrency = Math.max(1, Math.min(requested, 16));
25
- this.name = options.name ?? "default";
26
- this.onError = options.onError;
27
- }
28
- /**
29
- * Enqueue an async job. Resolves/rejects with the job result.
30
- * Back-pressures via wait in the queue — does not spawn unbounded work.
31
- */
32
- enqueue(fn) {
33
- if (this.closed) {
34
- return Promise.reject(new Error(`[JobQueue:${this.name}] Queue is closed; cannot accept new jobs.`));
35
- }
36
- return new Promise((resolve, reject) => {
37
- const item = {
38
- id: this.nextId++,
39
- run: fn,
40
- resolve,
41
- reject,
42
- };
43
- this.pending.push(item);
44
- this.pump();
45
- });
46
- }
47
- /** Current queue diagnostics. */
48
- getStats() {
49
- return {
50
- name: this.name,
51
- maxConcurrency: this.maxConcurrency,
52
- running: this.running,
53
- pending: this.pending.length,
54
- completed: this.completed,
55
- failed: this.failed,
56
- };
57
- }
58
- /** Reject pending jobs and stop accepting new ones. In-flight jobs finish. */
59
- close(reason = "Queue closed") {
60
- this.closed = true;
61
- while (this.pending.length > 0) {
62
- const item = this.pending.shift();
63
- item?.reject(new Error(`[JobQueue:${this.name}] ${reason}`));
64
- }
65
- }
66
- /** Wait until running + pending reach zero (or timeout). */
67
- async drain(timeoutMs = 30_000) {
68
- const start = Date.now();
69
- while (this.running > 0 || this.pending.length > 0) {
70
- if (Date.now() - start > timeoutMs) {
71
- throw new Error(`[JobQueue:${this.name}] drain timed out after ${timeoutMs}ms`);
72
- }
73
- await new Promise((r) => setTimeout(r, 10));
74
- }
75
- }
76
- pump() {
77
- while (this.running < this.maxConcurrency && this.pending.length > 0) {
78
- const item = this.pending.shift();
79
- if (!item)
80
- break;
81
- this.running++;
82
- void this.execute(item);
83
- }
84
- }
85
- async execute(item) {
86
- try {
87
- const result = await item.run();
88
- this.completed++;
89
- item.resolve(result);
90
- }
91
- catch (error) {
92
- this.failed++;
93
- try {
94
- this.onError?.(error, item.id);
95
- }
96
- catch {
97
- // ignore listener errors
98
- }
99
- item.reject(error);
100
- }
101
- finally {
102
- this.running--;
103
- this.pump();
104
- }
105
- }
106
- }
107
- /** Shared singleton for agent orchestration (lazy). */
108
- let agentJobQueue = null;
109
- export function getAgentJobQueue(options) {
110
- if (!agentJobQueue) {
111
- const fromEnv = process.env.ATABEY_JOB_CONCURRENCY
112
- ? parseInt(process.env.ATABEY_JOB_CONCURRENCY, 10)
113
- : undefined;
114
- agentJobQueue = new InMemoryJobQueue({
115
- name: "agent",
116
- maxConcurrency: options?.maxConcurrency ?? (Number.isFinite(fromEnv) ? fromEnv : undefined),
117
- onError: options?.onError,
118
- });
119
- }
120
- return agentJobQueue;
121
- }
122
- /** Test helper — reset singleton. */
123
- export function resetAgentJobQueue() {
124
- agentJobQueue?.close("reset");
125
- agentJobQueue = null;
126
- }
1
+ export * from "./modules/concurrency/job-queue.js";
127
2
  //# sourceMappingURL=job-queue.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"job-queue.js","sourceRoot":"","sources":["../src/job-queue.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,MAAM,IAAI,CAAC;AA2BpB,MAAM,OAAO,gBAAgB;IACR,cAAc,CAAS;IACvB,IAAI,CAAS;IACb,OAAO,CAA2C;IAClD,OAAO,GAA8B,EAAE,CAAC;IACjD,OAAO,GAAG,CAAC,CAAC;IACZ,MAAM,GAAG,CAAC,CAAC;IACX,SAAS,GAAG,CAAC,CAAC;IACd,MAAM,GAAG,CAAC,CAAC;IACX,MAAM,GAAG,KAAK,CAAC;IAEvB,YAAY,UAA2B,EAAE;QACrC,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE,MAAM,IAAI,CAAC,CAAC,CAAC;QACjD,MAAM,SAAS,GAAG,OAAO,CAAC,cAAc,IAAI,IAAI,CAAC;QACjD,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,CAAC;QAC3D,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,SAAS,CAAC;QACtC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IACnC,CAAC;IAED;;;OAGG;IACI,OAAO,CAAI,EAAoB;QAClC,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YACd,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,aAAa,IAAI,CAAC,IA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