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.
- package/README.md +63 -24
- package/dist/agent-identity.d.ts +1 -34
- package/dist/agent-identity.js +1 -76
- package/dist/agent-identity.js.map +1 -1
- package/dist/api-catalog.d.ts +1 -57
- package/dist/api-catalog.js +1 -253
- package/dist/api-catalog.js.map +1 -1
- package/dist/audit-chain.d.ts +1 -80
- package/dist/audit-chain.js +1 -261
- package/dist/audit-chain.js.map +1 -1
- package/dist/audit.d.ts +1 -121
- package/dist/audit.js +1 -321
- package/dist/audit.js.map +1 -1
- package/dist/constants.d.ts +1 -153
- package/dist/constants.js +1 -214
- 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 -93
- package/dist/file-lock.js +1 -239
- 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 -31
- package/dist/index.js +2 -31
- 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 -31
- package/dist/logger.js +1 -152
- package/dist/logger.js.map +1 -1
- package/dist/memory-prune.d.ts +1 -18
- package/dist/memory-prune.js +1 -47
- package/dist/memory-prune.js.map +1 -1
- package/dist/migrations.d.ts +1 -69
- package/dist/migrations.js +1 -374
- package/dist/migrations.js.map +1 -1
- 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 -39
- package/dist/otel.js +1 -92
- package/dist/otel.js.map +1 -1
- package/dist/outbound-http.d.ts +1 -32
- package/dist/outbound-http.js +1 -87
- package/dist/outbound-http.js.map +1 -1
- package/dist/pii.d.ts +1 -70
- package/dist/pii.js +1 -275
- package/dist/pii.js.map +1 -1
- package/dist/policy-gate.d.ts +1 -42
- package/dist/policy-gate.js +1 -171
- 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 -68
- package/dist/retention.js +1 -217
- package/dist/retention.js.map +1 -1
- package/dist/sandbox-fs.d.ts +1 -28
- package/dist/sandbox-fs.js +1 -142
- package/dist/sandbox-fs.js.map +1 -1
- package/dist/sandbox-runtime.d.ts +1 -78
- package/dist/sandbox-runtime.js +1 -281
- 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 -99
- package/dist/secrets.js +1 -370
- package/dist/secrets.js.map +1 -1
- package/dist/storage.d.ts +1 -341
- package/dist/storage.js +1 -1003
- 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 -34
- package/dist/time.js.map +1 -1
- package/dist/tls.d.ts +1 -87
- package/dist/tls.js +1 -153
- package/dist/tls.js.map +1 -1
- package/dist/tokenizer.d.ts +1 -54
- package/dist/tokenizer.js +1 -271
- package/dist/tokenizer.js.map +1 -1
- 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 -228
- 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 +44 -34
package/dist/lock.d.ts
CHANGED
|
@@ -1,82 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* [LOCK] Multi-user Distributed Lock Mechanism
|
|
3
|
-
*
|
|
4
|
-
* Git-based lock system. Enables team members to work on the same
|
|
5
|
-
* files/resources without conflicts.
|
|
6
|
-
*
|
|
7
|
-
* Usage:
|
|
8
|
-
* const lock = new DistributedLock("database/schema.sql");
|
|
9
|
-
* if (lock.acquire("user-123", 60000)) {
|
|
10
|
-
* // Apply changes
|
|
11
|
-
* lock.release("user-123");
|
|
12
|
-
* }
|
|
13
|
-
*/
|
|
14
|
-
export type LockStatus = "LOCKED" | "AVAILABLE" | "STALE" | "EXPIRED";
|
|
15
|
-
export interface LockInfo {
|
|
16
|
-
resource: string;
|
|
17
|
-
ownerId: string;
|
|
18
|
-
ownerName: string;
|
|
19
|
-
acquiredAt: string;
|
|
20
|
-
expiresAt: string;
|
|
21
|
-
reason: string;
|
|
22
|
-
traceId?: string;
|
|
23
|
-
}
|
|
24
|
-
export declare class DistributedLock {
|
|
25
|
-
private static TABLE;
|
|
26
|
-
/**
|
|
27
|
-
* Initialize the locks table (run once at startup).
|
|
28
|
-
*/
|
|
29
|
-
static initialize(): void;
|
|
30
|
-
/**
|
|
31
|
-
* Attempts to acquire a lock on a resource.
|
|
32
|
-
*
|
|
33
|
-
* @param resource - Lock resource name (e.g., "apps/backend/src/types/user.ts")
|
|
34
|
-
* @param ownerId - Unique owner identifier (e.g., "yusuf", "ci-bot-01")
|
|
35
|
-
* @param options - Optional parameters
|
|
36
|
-
* @returns true if lock acquired, false if already locked
|
|
37
|
-
*/
|
|
38
|
-
static acquire(resource: string, ownerId: string, options?: {
|
|
39
|
-
ownerName?: string;
|
|
40
|
-
ttlMs?: number;
|
|
41
|
-
reason?: string;
|
|
42
|
-
traceId?: string;
|
|
43
|
-
force?: boolean;
|
|
44
|
-
}): boolean;
|
|
45
|
-
/**
|
|
46
|
-
* Releases a lock. Only the lock owner can release.
|
|
47
|
-
*
|
|
48
|
-
* @param resource - Lock resource name
|
|
49
|
-
* @param ownerId - Owner identifier for verification
|
|
50
|
-
* @returns true if released successfully
|
|
51
|
-
*/
|
|
52
|
-
static release(resource: string, ownerId: string): boolean;
|
|
53
|
-
/**
|
|
54
|
-
* Checks if a resource is locked.
|
|
55
|
-
*/
|
|
56
|
-
static isLocked(resource: string): boolean;
|
|
57
|
-
/**
|
|
58
|
-
* Gets lock information for a resource.
|
|
59
|
-
*/
|
|
60
|
-
static getLock(resource: string): LockInfo | null;
|
|
61
|
-
/**
|
|
62
|
-
* Lists all active locks.
|
|
63
|
-
*/
|
|
64
|
-
static listActiveLocks(): LockInfo[];
|
|
65
|
-
/**
|
|
66
|
-
* Lists all locks owned by a specific owner.
|
|
67
|
-
*/
|
|
68
|
-
static listOwnerLocks(ownerId: string): LockInfo[];
|
|
69
|
-
/**
|
|
70
|
-
* Releases all locks owned by a specific owner (e.g., on disconnect).
|
|
71
|
-
*/
|
|
72
|
-
static releaseAllByOwner(ownerId: string): number;
|
|
73
|
-
/**
|
|
74
|
-
* Releases all expired/stale locks.
|
|
75
|
-
*/
|
|
76
|
-
private static releaseStaleLocks;
|
|
77
|
-
/**
|
|
78
|
-
* Generates a unique owner ID for the current user/machine.
|
|
79
|
-
* Uses git config user.name or hostname as fallback.
|
|
80
|
-
*/
|
|
81
|
-
static getLocalOwnerId(): string;
|
|
82
|
-
}
|
|
1
|
+
export * from "./modules/concurrency/lock.js";
|
package/dist/lock.js
CHANGED
|
@@ -1,159 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
* [LOCK] Multi-user Distributed Lock Mechanism
|
|
3
|
-
*
|
|
4
|
-
* Git-based lock system. Enables team members to work on the same
|
|
5
|
-
* files/resources without conflicts.
|
|
6
|
-
*
|
|
7
|
-
* Usage:
|
|
8
|
-
* const lock = new DistributedLock("database/schema.sql");
|
|
9
|
-
* if (lock.acquire("user-123", 60000)) {
|
|
10
|
-
* // Apply changes
|
|
11
|
-
* lock.release("user-123");
|
|
12
|
-
* }
|
|
13
|
-
*/
|
|
14
|
-
import { execSync } from "child_process";
|
|
15
|
-
import os from "os";
|
|
16
|
-
import { databaseHolder } from "./database.js";
|
|
17
|
-
export class DistributedLock {
|
|
18
|
-
static TABLE = "distributed_locks";
|
|
19
|
-
/**
|
|
20
|
-
* Initialize the locks table (run once at startup).
|
|
21
|
-
*/
|
|
22
|
-
static initialize() {
|
|
23
|
-
const db = databaseHolder.getDB();
|
|
24
|
-
db.exec(`
|
|
25
|
-
CREATE TABLE IF NOT EXISTS ${this.TABLE} (
|
|
26
|
-
resource TEXT PRIMARY KEY,
|
|
27
|
-
ownerId TEXT NOT NULL,
|
|
28
|
-
ownerName TEXT NOT NULL,
|
|
29
|
-
acquiredAt TEXT NOT NULL,
|
|
30
|
-
expiresAt TEXT NOT NULL,
|
|
31
|
-
reason TEXT,
|
|
32
|
-
traceId TEXT
|
|
33
|
-
)
|
|
34
|
-
`);
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Attempts to acquire a lock on a resource.
|
|
38
|
-
*
|
|
39
|
-
* @param resource - Lock resource name (e.g., "apps/backend/src/types/user.ts")
|
|
40
|
-
* @param ownerId - Unique owner identifier (e.g., "yusuf", "ci-bot-01")
|
|
41
|
-
* @param options - Optional parameters
|
|
42
|
-
* @returns true if lock acquired, false if already locked
|
|
43
|
-
*/
|
|
44
|
-
static acquire(resource, ownerId, options = {}) {
|
|
45
|
-
const db = databaseHolder.getDB();
|
|
46
|
-
const now = new Date();
|
|
47
|
-
const expiresAt = new Date(now.getTime() + (options.ttlMs || 60000)).toISOString();
|
|
48
|
-
const ownerName = options.ownerName || ownerId;
|
|
49
|
-
const reason = options.reason || "No reason provided";
|
|
50
|
-
// Clean up stale locks first
|
|
51
|
-
this.releaseStaleLocks();
|
|
52
|
-
// If force=true, override existing lock directly using INSERT OR REPLACE
|
|
53
|
-
if (options.force) {
|
|
54
|
-
db.prepare(`
|
|
55
|
-
INSERT OR REPLACE INTO ${this.TABLE} (resource, ownerId, ownerName, acquiredAt, expiresAt, reason, traceId)
|
|
56
|
-
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
57
|
-
`).run(resource, ownerId, ownerName, now.toISOString(), expiresAt, reason, options.traceId || null);
|
|
58
|
-
return true;
|
|
59
|
-
}
|
|
60
|
-
// Acquire new lock atomically using INSERT OR IGNORE.
|
|
61
|
-
// If the resource is already locked, changes will be 0.
|
|
62
|
-
const result = db.prepare(`
|
|
63
|
-
INSERT OR IGNORE INTO ${this.TABLE} (resource, ownerId, ownerName, acquiredAt, expiresAt, reason, traceId)
|
|
64
|
-
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
65
|
-
`).run(resource, ownerId, ownerName, now.toISOString(), expiresAt, reason, options.traceId || null);
|
|
66
|
-
return result.changes > 0;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Releases a lock. Only the lock owner can release.
|
|
70
|
-
*
|
|
71
|
-
* @param resource - Lock resource name
|
|
72
|
-
* @param ownerId - Owner identifier for verification
|
|
73
|
-
* @returns true if released successfully
|
|
74
|
-
*/
|
|
75
|
-
static release(resource, ownerId) {
|
|
76
|
-
const db = databaseHolder.getDB();
|
|
77
|
-
const result = db.prepare(`DELETE FROM ${this.TABLE} WHERE resource = ? AND ownerId = ?`).run(resource, ownerId);
|
|
78
|
-
return result.changes > 0;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Checks if a resource is locked.
|
|
82
|
-
*/
|
|
83
|
-
static isLocked(resource) {
|
|
84
|
-
const db = databaseHolder.getDB();
|
|
85
|
-
const nowIso = new Date().toISOString();
|
|
86
|
-
const lock = db.prepare(`SELECT * FROM ${this.TABLE} WHERE resource = ? AND expiresAt > ?`).get(resource, nowIso);
|
|
87
|
-
return !!lock;
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Gets lock information for a resource.
|
|
91
|
-
*/
|
|
92
|
-
static getLock(resource) {
|
|
93
|
-
const db = databaseHolder.getDB();
|
|
94
|
-
this.releaseStaleLocks();
|
|
95
|
-
const lock = db.prepare(`SELECT * FROM ${this.TABLE} WHERE resource = ?`).get(resource);
|
|
96
|
-
return lock || null;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Lists all active locks.
|
|
100
|
-
*/
|
|
101
|
-
static listActiveLocks() {
|
|
102
|
-
const db = databaseHolder.getDB();
|
|
103
|
-
this.releaseStaleLocks();
|
|
104
|
-
const nowIso = new Date().toISOString();
|
|
105
|
-
return db.prepare(`SELECT * FROM ${this.TABLE} WHERE expiresAt > ? ORDER BY acquiredAt DESC`).all(nowIso);
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Lists all locks owned by a specific owner.
|
|
109
|
-
*/
|
|
110
|
-
static listOwnerLocks(ownerId) {
|
|
111
|
-
const db = databaseHolder.getDB();
|
|
112
|
-
return db.prepare(`SELECT * FROM ${this.TABLE} WHERE ownerId = ? ORDER BY acquiredAt DESC`).all(ownerId);
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Releases all locks owned by a specific owner (e.g., on disconnect).
|
|
116
|
-
*/
|
|
117
|
-
static releaseAllByOwner(ownerId) {
|
|
118
|
-
const db = databaseHolder.getDB();
|
|
119
|
-
const result = db.prepare(`DELETE FROM ${this.TABLE} WHERE ownerId = ?`).run(ownerId);
|
|
120
|
-
return result.changes;
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Releases all expired/stale locks.
|
|
124
|
-
*/
|
|
125
|
-
static releaseStaleLocks() {
|
|
126
|
-
const db = databaseHolder.getDB();
|
|
127
|
-
const nowIso = new Date().toISOString();
|
|
128
|
-
const result = db.prepare(`DELETE FROM ${this.TABLE} WHERE expiresAt < ?`).run(nowIso);
|
|
129
|
-
return result.changes;
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Generates a unique owner ID for the current user/machine.
|
|
133
|
-
* Uses git config user.name or hostname as fallback.
|
|
134
|
-
*/
|
|
135
|
-
static getLocalOwnerId() {
|
|
136
|
-
// Try git config
|
|
137
|
-
try {
|
|
138
|
-
const name = execSync("git config user.name", { encoding: "utf8" }).trim();
|
|
139
|
-
if (name)
|
|
140
|
-
return name;
|
|
141
|
-
}
|
|
142
|
-
catch {
|
|
143
|
-
// Fallback
|
|
144
|
-
}
|
|
145
|
-
// Try environment
|
|
146
|
-
if (process.env.USER)
|
|
147
|
-
return process.env.USER;
|
|
148
|
-
if (process.env.USERNAME)
|
|
149
|
-
return process.env.USERNAME;
|
|
150
|
-
// Fallback to hostname
|
|
151
|
-
try {
|
|
152
|
-
return os.hostname();
|
|
153
|
-
}
|
|
154
|
-
catch {
|
|
155
|
-
return "unknown-user";
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
1
|
+
export * from "./modules/concurrency/lock.js";
|
|
159
2
|
//# sourceMappingURL=lock.js.map
|
package/dist/lock.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lock.js","sourceRoot":"","sources":["../src/lock.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"lock.js","sourceRoot":"","sources":["../src/lock.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC"}
|
package/dist/logger.d.ts
CHANGED
|
@@ -1,31 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
DEBUG = 0,
|
|
3
|
-
INFO = 1,
|
|
4
|
-
WARN = 2,
|
|
5
|
-
ERROR = 3,
|
|
6
|
-
FATAL = 4
|
|
7
|
-
}
|
|
8
|
-
export interface LoggerConfig {
|
|
9
|
-
minLevel: LogLevel;
|
|
10
|
-
enableColors: boolean;
|
|
11
|
-
jsonFormat: boolean;
|
|
12
|
-
logFile?: string;
|
|
13
|
-
enablePiiMasking: boolean;
|
|
14
|
-
piiWarning: boolean;
|
|
15
|
-
useStderr?: boolean;
|
|
16
|
-
}
|
|
17
|
-
export declare class EnterpriseLogger {
|
|
18
|
-
private config;
|
|
19
|
-
private static instance;
|
|
20
|
-
private constructor();
|
|
21
|
-
static getInstance(): EnterpriseLogger;
|
|
22
|
-
configure(config: Partial<LoggerConfig>): void;
|
|
23
|
-
private formatMessage;
|
|
24
|
-
private log;
|
|
25
|
-
debug(message: string, meta?: unknown): void;
|
|
26
|
-
info(message: string, meta?: unknown): void;
|
|
27
|
-
warn(message: string, meta?: unknown): void;
|
|
28
|
-
error(message: string, meta?: unknown): void;
|
|
29
|
-
fatal(message: string, meta?: unknown): void;
|
|
30
|
-
}
|
|
31
|
-
export declare const logger: EnterpriseLogger;
|
|
1
|
+
export * from "./modules/observability/logger.js";
|
package/dist/logger.js
CHANGED
|
@@ -1,153 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import path from "path";
|
|
3
|
-
import { appendFile, ensureDir } from "./fs.js";
|
|
4
|
-
import { containsPII, maskObject, maskText } from "./pii.js";
|
|
5
|
-
/** JSON.stringify that tolerates circular references instead of throwing. */
|
|
6
|
-
function safeStringify(value) {
|
|
7
|
-
const seen = new WeakSet();
|
|
8
|
-
try {
|
|
9
|
-
return JSON.stringify(value, (_key, v) => {
|
|
10
|
-
if (typeof v === "object" && v !== null) {
|
|
11
|
-
if (typeof Buffer !== "undefined" && Buffer.isBuffer(v))
|
|
12
|
-
return `<Buffer ${v.length} bytes>`;
|
|
13
|
-
if (v instanceof Uint8Array)
|
|
14
|
-
return `<bytes ${v.length}>`;
|
|
15
|
-
if (seen.has(v))
|
|
16
|
-
return "[Circular]";
|
|
17
|
-
seen.add(v);
|
|
18
|
-
}
|
|
19
|
-
return v;
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
catch {
|
|
23
|
-
return "[Unserializable]";
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
export var LogLevel;
|
|
27
|
-
(function (LogLevel) {
|
|
28
|
-
LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
|
|
29
|
-
LogLevel[LogLevel["INFO"] = 1] = "INFO";
|
|
30
|
-
LogLevel[LogLevel["WARN"] = 2] = "WARN";
|
|
31
|
-
LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
|
|
32
|
-
LogLevel[LogLevel["FATAL"] = 4] = "FATAL";
|
|
33
|
-
})(LogLevel || (LogLevel = {}));
|
|
34
|
-
export class EnterpriseLogger {
|
|
35
|
-
config;
|
|
36
|
-
static instance;
|
|
37
|
-
constructor() {
|
|
38
|
-
const isProd = process.env.NODE_ENV === "production";
|
|
39
|
-
const isStdio = process.env.MCP_TRANSPORT === "stdio";
|
|
40
|
-
this.config = {
|
|
41
|
-
minLevel: isProd ? LogLevel.INFO : LogLevel.DEBUG,
|
|
42
|
-
enableColors: !isProd && !isStdio,
|
|
43
|
-
jsonFormat: isProd,
|
|
44
|
-
enablePiiMasking: true, // KVKK: PII masking ON by default
|
|
45
|
-
piiWarning: true,
|
|
46
|
-
useStderr: isStdio,
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
static getInstance() {
|
|
50
|
-
if (!EnterpriseLogger.instance) {
|
|
51
|
-
EnterpriseLogger.instance = new EnterpriseLogger();
|
|
52
|
-
}
|
|
53
|
-
return EnterpriseLogger.instance;
|
|
54
|
-
}
|
|
55
|
-
configure(config) {
|
|
56
|
-
this.config = { ...this.config, ...config };
|
|
57
|
-
if (this.config.logFile) {
|
|
58
|
-
try {
|
|
59
|
-
ensureDir(path.dirname(this.config.logFile));
|
|
60
|
-
}
|
|
61
|
-
catch (err) {
|
|
62
|
-
// Directly write to stderr — using console here would be circular
|
|
63
|
-
process.stderr.write(`[Logger] Failed to create log directory: ${err}\n`);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
formatMessage(level, message, meta) {
|
|
68
|
-
const timestamp = new Date().toISOString();
|
|
69
|
-
const pid = process.pid;
|
|
70
|
-
// [KVKK] PII masking — mask sensitive data before logging
|
|
71
|
-
const safeMessage = this.config.enablePiiMasking ? maskText(message) : message;
|
|
72
|
-
const safeMeta = this.config.enablePiiMasking && meta ? maskObject(meta) : meta;
|
|
73
|
-
// [KVKK] Warn if PII detected in production (safe against circular meta)
|
|
74
|
-
if (this.config.piiWarning && (containsPII(message) || (meta !== undefined && containsPII(safeStringify(meta))))) {
|
|
75
|
-
// Only pollute stderr in non-JSON mode so structured streams stay clean.
|
|
76
|
-
if (!this.config.jsonFormat) {
|
|
77
|
-
process.stderr.write(`[PII WARNING] Potential PII detected in log at ${timestamp}\n`);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
if (this.config.jsonFormat) {
|
|
81
|
-
return safeStringify({
|
|
82
|
-
timestamp,
|
|
83
|
-
level: LogLevel[level],
|
|
84
|
-
pid,
|
|
85
|
-
message: safeMessage,
|
|
86
|
-
meta: safeMeta,
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
const levelName = LogLevel[level].padEnd(5);
|
|
90
|
-
let coloredLevel = levelName;
|
|
91
|
-
if (this.config.enableColors) {
|
|
92
|
-
switch (level) {
|
|
93
|
-
case LogLevel.DEBUG:
|
|
94
|
-
coloredLevel = chalk.blue(levelName);
|
|
95
|
-
break;
|
|
96
|
-
case LogLevel.INFO:
|
|
97
|
-
coloredLevel = chalk.green(levelName);
|
|
98
|
-
break;
|
|
99
|
-
case LogLevel.WARN:
|
|
100
|
-
coloredLevel = chalk.yellow(levelName);
|
|
101
|
-
break;
|
|
102
|
-
case LogLevel.ERROR:
|
|
103
|
-
coloredLevel = chalk.red(levelName);
|
|
104
|
-
break;
|
|
105
|
-
case LogLevel.FATAL:
|
|
106
|
-
coloredLevel = chalk.bgRed.white.bold(levelName);
|
|
107
|
-
break;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
const metaStr = safeMeta ? ` | Meta: ${JSON.stringify(safeMeta)}` : "";
|
|
111
|
-
return `[${timestamp}] [PID:${pid}] [${coloredLevel}]: ${safeMessage}${metaStr}`;
|
|
112
|
-
}
|
|
113
|
-
log(level, message, meta) {
|
|
114
|
-
if (level < this.config.minLevel)
|
|
115
|
-
return;
|
|
116
|
-
const formatted = this.formatMessage(level, message, meta);
|
|
117
|
-
// Route to stderr for ERROR/FATAL, or when useStderr / MCP stdio transport is active.
|
|
118
|
-
// Using process.write directly here is intentional — this IS the logger.
|
|
119
|
-
if (this.config.useStderr || process.env.MCP_TRANSPORT === "stdio" || level >= LogLevel.ERROR) {
|
|
120
|
-
process.stderr.write(formatted + "\n");
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
process.stdout.write(formatted + "\n");
|
|
124
|
-
}
|
|
125
|
-
// Output to file if configured
|
|
126
|
-
if (this.config.logFile) {
|
|
127
|
-
try {
|
|
128
|
-
appendFile(this.config.logFile, formatted + "\n");
|
|
129
|
-
}
|
|
130
|
-
catch (err) {
|
|
131
|
-
// Directly write to stderr — using console here would be circular
|
|
132
|
-
process.stderr.write(`[Logger] Failed to write to log file: ${err}\n`);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
debug(message, meta) {
|
|
137
|
-
this.log(LogLevel.DEBUG, message, meta);
|
|
138
|
-
}
|
|
139
|
-
info(message, meta) {
|
|
140
|
-
this.log(LogLevel.INFO, message, meta);
|
|
141
|
-
}
|
|
142
|
-
warn(message, meta) {
|
|
143
|
-
this.log(LogLevel.WARN, message, meta);
|
|
144
|
-
}
|
|
145
|
-
error(message, meta) {
|
|
146
|
-
this.log(LogLevel.ERROR, message, meta);
|
|
147
|
-
}
|
|
148
|
-
fatal(message, meta) {
|
|
149
|
-
this.log(LogLevel.FATAL, message, meta);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
export const logger = EnterpriseLogger.getInstance();
|
|
1
|
+
export * from "./modules/observability/logger.js";
|
|
153
2
|
//# sourceMappingURL=logger.js.map
|
package/dist/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,cAAc,mCAAmC,CAAC"}
|
package/dist/memory-prune.d.ts
CHANGED
|
@@ -1,18 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Specialty memory pruning — deduplication + cap + summary.
|
|
3
|
-
*
|
|
4
|
-
* `updateSpecialtyMemory` appends raw markdown lessons forever, which bloats
|
|
5
|
-
* prompts and accumulates contradictions. This pure function deduplicates
|
|
6
|
-
* identical lessons (ignoring the timestamp) and caps the retained count,
|
|
7
|
-
* leaving a summary marker for pruned entries.
|
|
8
|
-
*/
|
|
9
|
-
export interface PruneResult {
|
|
10
|
-
content: string;
|
|
11
|
-
removed: number;
|
|
12
|
-
kept: number;
|
|
13
|
-
}
|
|
14
|
-
export interface PruneOptions {
|
|
15
|
-
/** Maximum number of lessons retained (newest kept). Default: 100. */
|
|
16
|
-
maxLessons?: number;
|
|
17
|
-
}
|
|
18
|
-
export declare function pruneSpecialtyMarkdown(content: string, options?: PruneOptions): PruneResult;
|
|
1
|
+
export * from "./modules/storage/memory-prune.js";
|
package/dist/memory-prune.js
CHANGED
|
@@ -1,48 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
* Specialty memory pruning — deduplication + cap + summary.
|
|
3
|
-
*
|
|
4
|
-
* `updateSpecialtyMemory` appends raw markdown lessons forever, which bloats
|
|
5
|
-
* prompts and accumulates contradictions. This pure function deduplicates
|
|
6
|
-
* identical lessons (ignoring the timestamp) and caps the retained count,
|
|
7
|
-
* leaving a summary marker for pruned entries.
|
|
8
|
-
*/
|
|
9
|
-
const LESSON_PREFIX = /^\s*-\s+\*\*\[/;
|
|
10
|
-
const TIMESTAMP = /\[[^\]]*\]/g;
|
|
11
|
-
export function pruneSpecialtyMarkdown(content, options = {}) {
|
|
12
|
-
const maxLessons = options.maxLessons ?? 100;
|
|
13
|
-
if (!content)
|
|
14
|
-
return { content: content ?? "", removed: 0, kept: 0 };
|
|
15
|
-
const lines = content.split(/\r?\n/);
|
|
16
|
-
const header = [];
|
|
17
|
-
const lessons = [];
|
|
18
|
-
const seen = new Set();
|
|
19
|
-
let removed = 0;
|
|
20
|
-
for (const line of lines) {
|
|
21
|
-
if (LESSON_PREFIX.test(line)) {
|
|
22
|
-
const key = line.replace(TIMESTAMP, "").trim().toLowerCase();
|
|
23
|
-
if (seen.has(key)) {
|
|
24
|
-
removed++;
|
|
25
|
-
continue;
|
|
26
|
-
}
|
|
27
|
-
seen.add(key);
|
|
28
|
-
lessons.push(line);
|
|
29
|
-
}
|
|
30
|
-
else if (line.trim() === "" && lessons.length > 0) {
|
|
31
|
-
// collapse blank lines between lessons
|
|
32
|
-
continue;
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
header.push(line);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
let kept = lessons;
|
|
39
|
-
if (lessons.length > maxLessons) {
|
|
40
|
-
const dropped = lessons.length - maxLessons;
|
|
41
|
-
removed += dropped;
|
|
42
|
-
kept = lessons.slice(-maxLessons);
|
|
43
|
-
header.push(`- _[memory-prune] ${dropped} older lesson(s) pruned to control prompt size._`);
|
|
44
|
-
}
|
|
45
|
-
const body = [...header, ...kept].join("\n").replace(/\n{3,}/g, "\n\n").trimEnd();
|
|
46
|
-
return { content: body ? `${body}\n` : "", removed, kept: kept.length };
|
|
47
|
-
}
|
|
1
|
+
export * from "./modules/storage/memory-prune.js";
|
|
48
2
|
//# sourceMappingURL=memory-prune.js.map
|
package/dist/memory-prune.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory-prune.js","sourceRoot":"","sources":["../src/memory-prune.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"memory-prune.js","sourceRoot":"","sources":["../src/memory-prune.ts"],"names":[],"mappings":"AAAA,cAAc,mCAAmC,CAAC"}
|
package/dist/migrations.d.ts
CHANGED
|
@@ -1,69 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* SQLite Schema Migration Runner, Startup Integrity Check & Online Backup/Restore (Phase 1.5)
|
|
3
|
-
*
|
|
4
|
-
* Provides:
|
|
5
|
-
* 1. Versioned, checksummed schema migrations (`schema_migrations` table).
|
|
6
|
-
* 2. Startup integrity verification (`PRAGMA quick_check` / `PRAGMA integrity_check`).
|
|
7
|
-
* 3. Atomic online backup (`VACUUM INTO` + `.sha256` manifest) and verified restore.
|
|
8
|
-
*/
|
|
9
|
-
import Database from "better-sqlite3";
|
|
10
|
-
export interface SchemaMigration {
|
|
11
|
-
version: number;
|
|
12
|
-
name: string;
|
|
13
|
-
sql: string;
|
|
14
|
-
}
|
|
15
|
-
export interface AppliedMigration {
|
|
16
|
-
version: number;
|
|
17
|
-
name: string;
|
|
18
|
-
checksum: string;
|
|
19
|
-
applied_at: string;
|
|
20
|
-
}
|
|
21
|
-
export interface IntegrityCheckResult {
|
|
22
|
-
ok: boolean;
|
|
23
|
-
messages: string[];
|
|
24
|
-
foreignKeyViolations: number;
|
|
25
|
-
}
|
|
26
|
-
export interface BackupResult {
|
|
27
|
-
backupPath: string;
|
|
28
|
-
sha256: string;
|
|
29
|
-
sizeBytes: number;
|
|
30
|
-
createdAt: string;
|
|
31
|
-
schemaVersion: number;
|
|
32
|
-
}
|
|
33
|
-
export declare const BUILTIN_MIGRATIONS: SchemaMigration[];
|
|
34
|
-
/**
|
|
35
|
-
* Run all pending schema migrations transactionally and return applied version numbers.
|
|
36
|
-
*/
|
|
37
|
-
export declare function runPendingMigrations(db: Database.Database, migrations?: SchemaMigration[]): {
|
|
38
|
-
applied: number[];
|
|
39
|
-
currentVersion: number;
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* Return applied and pending migrations for diagnostics/CLI.
|
|
43
|
-
*/
|
|
44
|
-
export declare function getMigrationStatus(db: Database.Database, migrations?: SchemaMigration[]): {
|
|
45
|
-
currentVersion: number;
|
|
46
|
-
applied: AppliedMigration[];
|
|
47
|
-
pending: Array<{
|
|
48
|
-
version: number;
|
|
49
|
-
name: string;
|
|
50
|
-
}>;
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* Run SQLite integrity_check / quick_check and foreign_key_check.
|
|
54
|
-
*/
|
|
55
|
-
export declare function verifyDatabaseIntegrity(db: Database.Database, mode?: "quick" | "full"): IntegrityCheckResult;
|
|
56
|
-
/**
|
|
57
|
-
* Perform a consistent online backup using SQLite `VACUUM INTO` and write a `.sha256` sidecar.
|
|
58
|
-
*/
|
|
59
|
-
export declare function backupDatabase(db: Database.Database, destinationPath: string): BackupResult;
|
|
60
|
-
/**
|
|
61
|
-
* Verify a backup file (checksum sidecar + SQLite integrity_check) and atomically restore it.
|
|
62
|
-
*/
|
|
63
|
-
export declare function restoreDatabase(backupPath: string, targetDbPath: string, options?: {
|
|
64
|
-
verifyChecksum?: boolean;
|
|
65
|
-
}): {
|
|
66
|
-
restoredPath: string;
|
|
67
|
-
sha256: string;
|
|
68
|
-
schemaVersion: number;
|
|
69
|
-
};
|
|
1
|
+
export * from "./modules/storage/migrations.js";
|