@hasna/assistants 1.1.51 → 1.1.52
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/dist/index.js +1112 -1019
- package/dist/index.js.map +12 -13
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1472,7 +1472,119 @@ var init_schema = __esm(() => {
|
|
|
1472
1472
|
created_at TEXT NOT NULL
|
|
1473
1473
|
)`,
|
|
1474
1474
|
`CREATE INDEX IF NOT EXISTS idx_guardrail_evaluations_session ON guardrail_evaluations(session_id)`,
|
|
1475
|
-
`CREATE INDEX IF NOT EXISTS idx_guardrail_evaluations_rule ON guardrail_evaluations(rule_id)
|
|
1475
|
+
`CREATE INDEX IF NOT EXISTS idx_guardrail_evaluations_rule ON guardrail_evaluations(rule_id)`,
|
|
1476
|
+
`CREATE TABLE IF NOT EXISTS assistants_config (
|
|
1477
|
+
id TEXT PRIMARY KEY,
|
|
1478
|
+
name TEXT NOT NULL,
|
|
1479
|
+
model TEXT,
|
|
1480
|
+
system_prompt TEXT,
|
|
1481
|
+
settings TEXT NOT NULL DEFAULT '{}',
|
|
1482
|
+
identity_id TEXT,
|
|
1483
|
+
created_at INTEGER NOT NULL,
|
|
1484
|
+
updated_at INTEGER NOT NULL
|
|
1485
|
+
)`,
|
|
1486
|
+
`CREATE TABLE IF NOT EXISTS assistants_active (
|
|
1487
|
+
key TEXT PRIMARY KEY DEFAULT 'active',
|
|
1488
|
+
assistant_id TEXT NOT NULL
|
|
1489
|
+
)`,
|
|
1490
|
+
`CREATE TABLE IF NOT EXISTS assistant_sessions (
|
|
1491
|
+
id TEXT PRIMARY KEY,
|
|
1492
|
+
assistant_id TEXT NOT NULL,
|
|
1493
|
+
cwd TEXT,
|
|
1494
|
+
started_at INTEGER NOT NULL,
|
|
1495
|
+
updated_at INTEGER NOT NULL,
|
|
1496
|
+
status TEXT NOT NULL DEFAULT 'active',
|
|
1497
|
+
metadata TEXT
|
|
1498
|
+
)`,
|
|
1499
|
+
`CREATE INDEX IF NOT EXISTS idx_assistant_sessions_assistant ON assistant_sessions(assistant_id)`,
|
|
1500
|
+
`CREATE TABLE IF NOT EXISTS people (
|
|
1501
|
+
id TEXT PRIMARY KEY,
|
|
1502
|
+
name TEXT NOT NULL,
|
|
1503
|
+
email TEXT,
|
|
1504
|
+
phone TEXT,
|
|
1505
|
+
role TEXT,
|
|
1506
|
+
notes TEXT,
|
|
1507
|
+
avatar_url TEXT,
|
|
1508
|
+
metadata TEXT,
|
|
1509
|
+
created_at INTEGER NOT NULL,
|
|
1510
|
+
updated_at INTEGER NOT NULL
|
|
1511
|
+
)`,
|
|
1512
|
+
`CREATE TABLE IF NOT EXISTS people_active (
|
|
1513
|
+
key TEXT PRIMARY KEY DEFAULT 'active',
|
|
1514
|
+
person_id TEXT NOT NULL
|
|
1515
|
+
)`,
|
|
1516
|
+
`CREATE TABLE IF NOT EXISTS verification_sessions (
|
|
1517
|
+
id TEXT PRIMARY KEY,
|
|
1518
|
+
session_id TEXT NOT NULL,
|
|
1519
|
+
assistant_id TEXT,
|
|
1520
|
+
goal TEXT NOT NULL,
|
|
1521
|
+
status TEXT NOT NULL DEFAULT 'pending',
|
|
1522
|
+
result TEXT,
|
|
1523
|
+
created_at TEXT NOT NULL,
|
|
1524
|
+
completed_at TEXT,
|
|
1525
|
+
data TEXT
|
|
1526
|
+
)`,
|
|
1527
|
+
`CREATE INDEX IF NOT EXISTS idx_verification_sessions_session ON verification_sessions(session_id)`,
|
|
1528
|
+
`CREATE TABLE IF NOT EXISTS workspaces (
|
|
1529
|
+
id TEXT PRIMARY KEY,
|
|
1530
|
+
name TEXT NOT NULL,
|
|
1531
|
+
description TEXT,
|
|
1532
|
+
creator_id TEXT NOT NULL,
|
|
1533
|
+
creator_name TEXT NOT NULL,
|
|
1534
|
+
status TEXT NOT NULL DEFAULT 'active',
|
|
1535
|
+
participants TEXT NOT NULL DEFAULT '[]',
|
|
1536
|
+
created_at TEXT NOT NULL,
|
|
1537
|
+
updated_at TEXT NOT NULL
|
|
1538
|
+
)`,
|
|
1539
|
+
`CREATE TABLE IF NOT EXISTS workspaces_active (
|
|
1540
|
+
assistant_id TEXT PRIMARY KEY,
|
|
1541
|
+
workspace_id TEXT NOT NULL
|
|
1542
|
+
)`,
|
|
1543
|
+
`CREATE TABLE IF NOT EXISTS budget_usage (
|
|
1544
|
+
scope TEXT NOT NULL,
|
|
1545
|
+
scope_id TEXT NOT NULL,
|
|
1546
|
+
input_tokens INTEGER NOT NULL DEFAULT 0,
|
|
1547
|
+
output_tokens INTEGER NOT NULL DEFAULT 0,
|
|
1548
|
+
total_tokens INTEGER NOT NULL DEFAULT 0,
|
|
1549
|
+
api_calls INTEGER NOT NULL DEFAULT 0,
|
|
1550
|
+
tool_calls INTEGER NOT NULL DEFAULT 0,
|
|
1551
|
+
estimated_cost_usd REAL NOT NULL DEFAULT 0,
|
|
1552
|
+
updated_at TEXT NOT NULL,
|
|
1553
|
+
PRIMARY KEY (scope, scope_id)
|
|
1554
|
+
)`,
|
|
1555
|
+
`CREATE TABLE IF NOT EXISTS registered_assistants (
|
|
1556
|
+
id TEXT PRIMARY KEY,
|
|
1557
|
+
name TEXT NOT NULL,
|
|
1558
|
+
type TEXT NOT NULL DEFAULT 'general',
|
|
1559
|
+
description TEXT,
|
|
1560
|
+
model TEXT,
|
|
1561
|
+
status TEXT NOT NULL DEFAULT 'active',
|
|
1562
|
+
state TEXT NOT NULL DEFAULT 'idle',
|
|
1563
|
+
capabilities TEXT,
|
|
1564
|
+
tags TEXT,
|
|
1565
|
+
parent_id TEXT,
|
|
1566
|
+
created_at TEXT NOT NULL,
|
|
1567
|
+
updated_at TEXT NOT NULL,
|
|
1568
|
+
last_active_at TEXT,
|
|
1569
|
+
metadata TEXT
|
|
1570
|
+
)`,
|
|
1571
|
+
`CREATE INDEX IF NOT EXISTS idx_registered_assistants_type ON registered_assistants(type)`,
|
|
1572
|
+
`CREATE INDEX IF NOT EXISTS idx_registered_assistants_status ON registered_assistants(status)`,
|
|
1573
|
+
`CREATE TABLE IF NOT EXISTS heartbeat_history (
|
|
1574
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
1575
|
+
session_id TEXT NOT NULL,
|
|
1576
|
+
status TEXT NOT NULL,
|
|
1577
|
+
energy INTEGER,
|
|
1578
|
+
context_tokens INTEGER,
|
|
1579
|
+
action TEXT,
|
|
1580
|
+
timestamp TEXT NOT NULL
|
|
1581
|
+
)`,
|
|
1582
|
+
`CREATE INDEX IF NOT EXISTS idx_heartbeat_history_session ON heartbeat_history(session_id, timestamp DESC)`,
|
|
1583
|
+
`CREATE TABLE IF NOT EXISTS connector_cache (
|
|
1584
|
+
key TEXT PRIMARY KEY,
|
|
1585
|
+
data TEXT NOT NULL,
|
|
1586
|
+
cached_at TEXT NOT NULL
|
|
1587
|
+
)`
|
|
1476
1588
|
];
|
|
1477
1589
|
});
|
|
1478
1590
|
|
|
@@ -20345,80 +20457,105 @@ var init_energy = __esm(() => {
|
|
|
20345
20457
|
});
|
|
20346
20458
|
|
|
20347
20459
|
// packages/core/src/heartbeat/history.ts
|
|
20348
|
-
|
|
20349
|
-
|
|
20350
|
-
|
|
20351
|
-
function
|
|
20352
|
-
if (
|
|
20353
|
-
|
|
20460
|
+
function getDb() {
|
|
20461
|
+
return getDatabase();
|
|
20462
|
+
}
|
|
20463
|
+
function rowToHeartbeat(row) {
|
|
20464
|
+
if (row.action) {
|
|
20465
|
+
try {
|
|
20466
|
+
const parsed = JSON.parse(row.action);
|
|
20467
|
+
if (parsed.sessionId)
|
|
20468
|
+
return parsed;
|
|
20469
|
+
} catch {}
|
|
20354
20470
|
}
|
|
20355
|
-
return
|
|
20471
|
+
return {
|
|
20472
|
+
sessionId: row.session_id,
|
|
20473
|
+
timestamp: row.timestamp,
|
|
20474
|
+
state: row.status,
|
|
20475
|
+
lastActivity: row.timestamp,
|
|
20476
|
+
stats: {
|
|
20477
|
+
messagesProcessed: 0,
|
|
20478
|
+
toolCallsExecuted: 0,
|
|
20479
|
+
errorsEncountered: 0,
|
|
20480
|
+
uptimeSeconds: 0
|
|
20481
|
+
}
|
|
20482
|
+
};
|
|
20356
20483
|
}
|
|
20357
|
-
function resolveHeartbeatPersistPath(sessionId, persistPath,
|
|
20484
|
+
function resolveHeartbeatPersistPath(sessionId, persistPath, _baseDir) {
|
|
20358
20485
|
if (persistPath) {
|
|
20359
|
-
|
|
20486
|
+
if (persistPath.includes("{sessionId}")) {
|
|
20487
|
+
return persistPath.replace("{sessionId}", sessionId);
|
|
20488
|
+
}
|
|
20489
|
+
return persistPath;
|
|
20360
20490
|
}
|
|
20361
|
-
return
|
|
20491
|
+
return `<db>:heartbeat_history:${sessionId}`;
|
|
20362
20492
|
}
|
|
20363
|
-
function resolveHeartbeatHistoryPath(sessionId, historyPath,
|
|
20493
|
+
function resolveHeartbeatHistoryPath(sessionId, historyPath, _baseDir) {
|
|
20364
20494
|
if (historyPath) {
|
|
20365
|
-
|
|
20495
|
+
if (historyPath.includes("{sessionId}")) {
|
|
20496
|
+
return historyPath.replace("{sessionId}", sessionId);
|
|
20497
|
+
}
|
|
20498
|
+
return historyPath;
|
|
20366
20499
|
}
|
|
20367
|
-
return
|
|
20500
|
+
return `<db>:heartbeat_history:${sessionId}`;
|
|
20368
20501
|
}
|
|
20369
|
-
function listHeartbeatHistorySessions(
|
|
20370
|
-
|
|
20371
|
-
|
|
20502
|
+
function listHeartbeatHistorySessions(_baseDir, db) {
|
|
20503
|
+
try {
|
|
20504
|
+
const conn = db || getDb();
|
|
20505
|
+
const rows = conn.query("SELECT DISTINCT session_id FROM heartbeat_history").all();
|
|
20506
|
+
return rows.map((r) => r.session_id);
|
|
20507
|
+
} catch {
|
|
20372
20508
|
return [];
|
|
20373
|
-
|
|
20509
|
+
}
|
|
20374
20510
|
}
|
|
20375
|
-
async function appendHeartbeatHistory(historyPath, heartbeat) {
|
|
20511
|
+
async function appendHeartbeatHistory(historyPath, heartbeat, db) {
|
|
20376
20512
|
try {
|
|
20377
|
-
|
|
20378
|
-
|
|
20379
|
-
|
|
20513
|
+
const conn = db || getDb();
|
|
20514
|
+
conn.prepare(`INSERT INTO heartbeat_history (session_id, status, energy, context_tokens, action, timestamp)
|
|
20515
|
+
VALUES (?, ?, ?, ?, ?, ?)`).run(heartbeat.sessionId, heartbeat.state, null, null, JSON.stringify(heartbeat), heartbeat.timestamp);
|
|
20380
20516
|
} catch {}
|
|
20381
20517
|
}
|
|
20382
|
-
|
|
20518
|
+
function extractSessionId(historyPath) {
|
|
20519
|
+
if (historyPath.startsWith("<db>:heartbeat_history:")) {
|
|
20520
|
+
return historyPath.replace("<db>:heartbeat_history:", "");
|
|
20521
|
+
}
|
|
20522
|
+
const match = historyPath.match(/[/\\]([^/\\]+?)\.jsonl?$/);
|
|
20523
|
+
if (match) {
|
|
20524
|
+
return match[1];
|
|
20525
|
+
}
|
|
20526
|
+
return null;
|
|
20527
|
+
}
|
|
20528
|
+
async function readHeartbeatHistory(historyPath, options = {}, db) {
|
|
20383
20529
|
try {
|
|
20384
|
-
const
|
|
20385
|
-
const
|
|
20386
|
-
`).filter(Boolean);
|
|
20387
|
-
const parsed = [];
|
|
20388
|
-
for (const line of lines) {
|
|
20389
|
-
try {
|
|
20390
|
-
parsed.push(JSON.parse(line));
|
|
20391
|
-
} catch {}
|
|
20392
|
-
}
|
|
20530
|
+
const conn = db || getDb();
|
|
20531
|
+
const sessionId = extractSessionId(historyPath);
|
|
20393
20532
|
const order = options.order ?? "desc";
|
|
20394
|
-
const
|
|
20395
|
-
|
|
20396
|
-
|
|
20533
|
+
const orderSql = order === "desc" ? "DESC" : "ASC";
|
|
20534
|
+
const limitSql = options.limit && options.limit > 0 ? `LIMIT ${options.limit}` : "";
|
|
20535
|
+
let rows;
|
|
20536
|
+
if (sessionId) {
|
|
20537
|
+
rows = conn.query(`SELECT * FROM heartbeat_history WHERE session_id = ? ORDER BY timestamp ${orderSql} ${limitSql}`).all(sessionId);
|
|
20538
|
+
} else {
|
|
20539
|
+
rows = conn.query(`SELECT * FROM heartbeat_history ORDER BY timestamp ${orderSql} ${limitSql}`).all();
|
|
20397
20540
|
}
|
|
20398
|
-
return
|
|
20541
|
+
return rows.map(rowToHeartbeat);
|
|
20399
20542
|
} catch {
|
|
20400
20543
|
return [];
|
|
20401
20544
|
}
|
|
20402
20545
|
}
|
|
20403
|
-
async function readHeartbeatHistoryBySession(sessionId, options = {}) {
|
|
20404
|
-
const historyPath = resolveHeartbeatHistoryPath(sessionId, options.historyPath
|
|
20405
|
-
return readHeartbeatHistory(historyPath, { limit: options.limit, order: options.order });
|
|
20546
|
+
async function readHeartbeatHistoryBySession(sessionId, options = {}, db) {
|
|
20547
|
+
const historyPath = resolveHeartbeatHistoryPath(sessionId, options.historyPath);
|
|
20548
|
+
return readHeartbeatHistory(historyPath, { limit: options.limit, order: options.order }, db);
|
|
20406
20549
|
}
|
|
20407
|
-
async function readLatestHeartbeat(persistPath, historyPath) {
|
|
20408
|
-
|
|
20409
|
-
|
|
20410
|
-
|
|
20411
|
-
|
|
20412
|
-
|
|
20413
|
-
try {
|
|
20414
|
-
const content = await readFile2(persistPath, "utf-8");
|
|
20415
|
-
return JSON.parse(content);
|
|
20416
|
-
} catch {
|
|
20417
|
-
return null;
|
|
20418
|
-
}
|
|
20550
|
+
async function readLatestHeartbeat(persistPath, historyPath, db) {
|
|
20551
|
+
const path2 = historyPath || persistPath;
|
|
20552
|
+
const history = await readHeartbeatHistory(path2, { limit: 1, order: "desc" }, db);
|
|
20553
|
+
if (history.length > 0)
|
|
20554
|
+
return history[0];
|
|
20555
|
+
return null;
|
|
20419
20556
|
}
|
|
20420
20557
|
var init_history = __esm(async () => {
|
|
20421
|
-
await
|
|
20558
|
+
await init_database();
|
|
20422
20559
|
});
|
|
20423
20560
|
|
|
20424
20561
|
// packages/core/src/tools/heartbeat.ts
|
|
@@ -20530,7 +20667,7 @@ var init_heartbeat = __esm(async () => {
|
|
|
20530
20667
|
});
|
|
20531
20668
|
|
|
20532
20669
|
// packages/core/src/projects/store.ts
|
|
20533
|
-
function
|
|
20670
|
+
function getDb2() {
|
|
20534
20671
|
return getDatabase();
|
|
20535
20672
|
}
|
|
20536
20673
|
function rowToProject(row) {
|
|
@@ -20548,11 +20685,11 @@ function normalizeName(name) {
|
|
|
20548
20685
|
return name.trim().toLowerCase();
|
|
20549
20686
|
}
|
|
20550
20687
|
async function listProjects(cwd) {
|
|
20551
|
-
const rows =
|
|
20688
|
+
const rows = getDb2().query("SELECT * FROM projects WHERE project_path = ? ORDER BY updated_at DESC").all(cwd);
|
|
20552
20689
|
return rows.map(rowToProject);
|
|
20553
20690
|
}
|
|
20554
20691
|
async function readProject(cwd, id) {
|
|
20555
|
-
const row =
|
|
20692
|
+
const row = getDb2().query("SELECT * FROM projects WHERE id = ?").get(id);
|
|
20556
20693
|
if (!row)
|
|
20557
20694
|
return null;
|
|
20558
20695
|
return rowToProject(row);
|
|
@@ -20563,11 +20700,11 @@ async function findProjectByName(cwd, name) {
|
|
|
20563
20700
|
return projects.find((project) => normalizeName(project.name) === normalized) || null;
|
|
20564
20701
|
}
|
|
20565
20702
|
async function saveProject(cwd, project) {
|
|
20566
|
-
|
|
20703
|
+
getDb2().prepare(`INSERT OR REPLACE INTO projects (id, project_path, name, description, context, plans, created_at, updated_at)
|
|
20567
20704
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`).run(project.id, cwd, project.name, project.description ?? null, JSON.stringify(project.context), JSON.stringify(project.plans), project.createdAt, project.updatedAt);
|
|
20568
20705
|
}
|
|
20569
20706
|
async function deleteProject(cwd, id) {
|
|
20570
|
-
const result =
|
|
20707
|
+
const result = getDb2().prepare("DELETE FROM projects WHERE id = ?").run(id);
|
|
20571
20708
|
return result.changes > 0;
|
|
20572
20709
|
}
|
|
20573
20710
|
async function createProject(cwd, name, description) {
|
|
@@ -20669,9 +20806,9 @@ function isWithinPath(target, base) {
|
|
|
20669
20806
|
var init_paths = () => {};
|
|
20670
20807
|
|
|
20671
20808
|
// packages/core/src/projects/context.ts
|
|
20672
|
-
import { readFile as
|
|
20809
|
+
import { readFile as readFile2 } from "fs/promises";
|
|
20673
20810
|
import { homedir as homedir6 } from "os";
|
|
20674
|
-
import { resolve as resolve2, join as
|
|
20811
|
+
import { resolve as resolve2, join as join10 } from "path";
|
|
20675
20812
|
function singleLine(value) {
|
|
20676
20813
|
return value.replace(/[\r\n]+/g, " ").trim();
|
|
20677
20814
|
}
|
|
@@ -20689,7 +20826,7 @@ function normalizeEntryLabel(entry) {
|
|
|
20689
20826
|
}
|
|
20690
20827
|
async function renderFileEntry(entry, options) {
|
|
20691
20828
|
const rawPath = entry.value.trim();
|
|
20692
|
-
const expandedPath = rawPath === "~" ? homedir6() : rawPath.startsWith("~/") ?
|
|
20829
|
+
const expandedPath = rawPath === "~" ? homedir6() : rawPath.startsWith("~/") ? join10(homedir6(), rawPath.slice(2)) : rawPath;
|
|
20693
20830
|
const resolved = resolve2(options.cwd, expandedPath);
|
|
20694
20831
|
const validation = await validatePath(resolved, { allowedPaths: [options.cwd] });
|
|
20695
20832
|
if (!validation.valid) {
|
|
@@ -20697,7 +20834,7 @@ async function renderFileEntry(entry, options) {
|
|
|
20697
20834
|
}
|
|
20698
20835
|
let content = "";
|
|
20699
20836
|
try {
|
|
20700
|
-
const data = await
|
|
20837
|
+
const data = await readFile2(validation.resolved, "utf-8");
|
|
20701
20838
|
const limit2 = options.maxFileBytes ?? DEFAULT_MAX_FILE_BYTES;
|
|
20702
20839
|
if (data.length > limit2) {
|
|
20703
20840
|
content = `${data.slice(0, limit2)}
|
|
@@ -21214,8 +21351,8 @@ var init_security = __esm(() => {
|
|
|
21214
21351
|
});
|
|
21215
21352
|
|
|
21216
21353
|
// packages/core/src/logger.ts
|
|
21217
|
-
import { existsSync as
|
|
21218
|
-
import { join as
|
|
21354
|
+
import { existsSync as existsSync8, mkdirSync as mkdirSync5, appendFileSync, readdirSync as readdirSync4, readFileSync as readFileSync5, writeFileSync as writeFileSync3 } from "fs";
|
|
21355
|
+
import { join as join11 } from "path";
|
|
21219
21356
|
function isValidId(id) {
|
|
21220
21357
|
return typeof id === "string" && id.length > 0 && SAFE_ID_PATTERN2.test(id);
|
|
21221
21358
|
}
|
|
@@ -21226,14 +21363,14 @@ class Logger {
|
|
|
21226
21363
|
sessionId;
|
|
21227
21364
|
constructor(sessionId, basePath) {
|
|
21228
21365
|
this.sessionId = sessionId;
|
|
21229
|
-
this.logDir =
|
|
21366
|
+
this.logDir = join11(basePath || getConfigDir(), "logs");
|
|
21230
21367
|
this.ensureDir(this.logDir);
|
|
21231
21368
|
const date = new Date().toISOString().split("T")[0];
|
|
21232
|
-
this.logFile =
|
|
21369
|
+
this.logFile = join11(this.logDir, `${date}.log`);
|
|
21233
21370
|
}
|
|
21234
21371
|
ensureDir(dir) {
|
|
21235
|
-
if (!
|
|
21236
|
-
|
|
21372
|
+
if (!existsSync8(dir)) {
|
|
21373
|
+
mkdirSync5(dir, { recursive: true });
|
|
21237
21374
|
}
|
|
21238
21375
|
}
|
|
21239
21376
|
write(level, message, data) {
|
|
@@ -21265,12 +21402,12 @@ class Logger {
|
|
|
21265
21402
|
this.write("error", message, data);
|
|
21266
21403
|
}
|
|
21267
21404
|
static readEntries(options) {
|
|
21268
|
-
const logDir =
|
|
21269
|
-
if (!
|
|
21405
|
+
const logDir = join11(options?.basePath || getConfigDir(), "logs");
|
|
21406
|
+
if (!existsSync8(logDir))
|
|
21270
21407
|
return [];
|
|
21271
21408
|
const levelOrder = { debug: 0, info: 1, warn: 2, error: 3 };
|
|
21272
21409
|
const minLevel = options?.level ? levelOrder[options.level] : 0;
|
|
21273
|
-
const files =
|
|
21410
|
+
const files = readdirSync4(logDir).filter((f) => /^\d{4}-\d{2}-\d{2}\.log$/.test(f)).sort((a, b) => b.localeCompare(a));
|
|
21274
21411
|
const entries = [];
|
|
21275
21412
|
for (const file of files) {
|
|
21276
21413
|
if (options?.since) {
|
|
@@ -21280,7 +21417,7 @@ class Logger {
|
|
|
21280
21417
|
break;
|
|
21281
21418
|
}
|
|
21282
21419
|
try {
|
|
21283
|
-
const content = readFileSync5(
|
|
21420
|
+
const content = readFileSync5(join11(logDir, file), "utf-8");
|
|
21284
21421
|
const lines = content.trim().split(`
|
|
21285
21422
|
`).filter(Boolean);
|
|
21286
21423
|
for (const line of lines) {
|
|
@@ -21303,10 +21440,10 @@ class Logger {
|
|
|
21303
21440
|
return entries.slice(offset, offset + limit2);
|
|
21304
21441
|
}
|
|
21305
21442
|
static listLogDates(basePath) {
|
|
21306
|
-
const logDir =
|
|
21307
|
-
if (!
|
|
21443
|
+
const logDir = join11(basePath || getConfigDir(), "logs");
|
|
21444
|
+
if (!existsSync8(logDir))
|
|
21308
21445
|
return [];
|
|
21309
|
-
return
|
|
21446
|
+
return readdirSync4(logDir).filter((f) => /^\d{4}-\d{2}-\d{2}\.log$/.test(f)).map((f) => f.replace(".log", "")).sort((a, b) => b.localeCompare(a));
|
|
21310
21447
|
}
|
|
21311
21448
|
}
|
|
21312
21449
|
|
|
@@ -21321,13 +21458,13 @@ class SessionStorage {
|
|
|
21321
21458
|
this.sessionId = sessionId;
|
|
21322
21459
|
const root = basePath || getConfigDir();
|
|
21323
21460
|
const safeAssistantId = isValidId(assistantId) ? assistantId : null;
|
|
21324
|
-
this.sessionsDir = safeAssistantId ?
|
|
21461
|
+
this.sessionsDir = safeAssistantId ? join11(root, "assistants", safeAssistantId, "sessions") : join11(root, "sessions");
|
|
21325
21462
|
this.ensureDir(this.sessionsDir);
|
|
21326
|
-
this.sessionFile =
|
|
21463
|
+
this.sessionFile = join11(this.sessionsDir, `${sessionId}.json`);
|
|
21327
21464
|
}
|
|
21328
21465
|
ensureDir(dir) {
|
|
21329
|
-
if (!
|
|
21330
|
-
|
|
21466
|
+
if (!existsSync8(dir)) {
|
|
21467
|
+
mkdirSync5(dir, { recursive: true });
|
|
21331
21468
|
}
|
|
21332
21469
|
}
|
|
21333
21470
|
save(data) {
|
|
@@ -21340,7 +21477,7 @@ class SessionStorage {
|
|
|
21340
21477
|
}
|
|
21341
21478
|
load() {
|
|
21342
21479
|
try {
|
|
21343
|
-
if (!
|
|
21480
|
+
if (!existsSync8(this.sessionFile))
|
|
21344
21481
|
return null;
|
|
21345
21482
|
return JSON.parse(readFileSync5(this.sessionFile, "utf-8"));
|
|
21346
21483
|
} catch {
|
|
@@ -21350,8 +21487,8 @@ class SessionStorage {
|
|
|
21350
21487
|
static getActiveAssistantId(basePath) {
|
|
21351
21488
|
try {
|
|
21352
21489
|
const root = basePath || getConfigDir();
|
|
21353
|
-
const activePath =
|
|
21354
|
-
if (!
|
|
21490
|
+
const activePath = join11(root, "active.json");
|
|
21491
|
+
if (!existsSync8(activePath))
|
|
21355
21492
|
return null;
|
|
21356
21493
|
const raw = readFileSync5(activePath, "utf-8");
|
|
21357
21494
|
const data = JSON.parse(raw);
|
|
@@ -21372,23 +21509,23 @@ class SessionStorage {
|
|
|
21372
21509
|
const safeAssistantId = isValidId(assistantId) ? assistantId : null;
|
|
21373
21510
|
const resolvedId = safeAssistantId ?? SessionStorage.getActiveAssistantId(basePath);
|
|
21374
21511
|
if (resolvedId && isValidId(resolvedId)) {
|
|
21375
|
-
const assistantDir =
|
|
21376
|
-
if (
|
|
21512
|
+
const assistantDir = join11(root, "assistants", resolvedId, "sessions");
|
|
21513
|
+
if (existsSync8(assistantDir)) {
|
|
21377
21514
|
return { dir: assistantDir, assistantId: resolvedId };
|
|
21378
21515
|
}
|
|
21379
21516
|
}
|
|
21380
|
-
return { dir:
|
|
21517
|
+
return { dir: join11(root, "sessions"), assistantId: null };
|
|
21381
21518
|
}
|
|
21382
21519
|
static readSessionsFromDir(sessionsDir, assistantId) {
|
|
21383
|
-
if (!
|
|
21520
|
+
if (!existsSync8(sessionsDir))
|
|
21384
21521
|
return [];
|
|
21385
21522
|
const sessions = [];
|
|
21386
|
-
const files =
|
|
21523
|
+
const files = readdirSync4(sessionsDir);
|
|
21387
21524
|
for (const file of files) {
|
|
21388
21525
|
if (!file.endsWith(".json"))
|
|
21389
21526
|
continue;
|
|
21390
21527
|
try {
|
|
21391
|
-
const filePath =
|
|
21528
|
+
const filePath = join11(sessionsDir, file);
|
|
21392
21529
|
const content = JSON.parse(readFileSync5(filePath, "utf-8"));
|
|
21393
21530
|
sessions.push({
|
|
21394
21531
|
id: file.replace(".json", ""),
|
|
@@ -21410,17 +21547,17 @@ class SessionStorage {
|
|
|
21410
21547
|
static listAllSessions(basePath) {
|
|
21411
21548
|
const root = basePath || getConfigDir();
|
|
21412
21549
|
const sessions = [];
|
|
21413
|
-
const rootSessionsDir =
|
|
21550
|
+
const rootSessionsDir = join11(root, "sessions");
|
|
21414
21551
|
sessions.push(...SessionStorage.readSessionsFromDir(rootSessionsDir, null));
|
|
21415
|
-
const assistantsDir =
|
|
21416
|
-
if (
|
|
21417
|
-
const entries =
|
|
21552
|
+
const assistantsDir = join11(root, "assistants");
|
|
21553
|
+
if (existsSync8(assistantsDir)) {
|
|
21554
|
+
const entries = readdirSync4(assistantsDir, { withFileTypes: true });
|
|
21418
21555
|
for (const entry of entries) {
|
|
21419
21556
|
if (!entry.isDirectory())
|
|
21420
21557
|
continue;
|
|
21421
21558
|
if (!isValidId(entry.name))
|
|
21422
21559
|
continue;
|
|
21423
|
-
const assistantSessionsDir =
|
|
21560
|
+
const assistantSessionsDir = join11(assistantsDir, entry.name, "sessions");
|
|
21424
21561
|
sessions.push(...SessionStorage.readSessionsFromDir(assistantSessionsDir, entry.name));
|
|
21425
21562
|
}
|
|
21426
21563
|
}
|
|
@@ -21435,9 +21572,9 @@ class SessionStorage {
|
|
|
21435
21572
|
return null;
|
|
21436
21573
|
}
|
|
21437
21574
|
const sessionsDir = SessionStorage.resolveSessionsDir(assistantId, basePath);
|
|
21438
|
-
const sessionFile =
|
|
21575
|
+
const sessionFile = join11(sessionsDir, `${sessionId}.json`);
|
|
21439
21576
|
try {
|
|
21440
|
-
if (!
|
|
21577
|
+
if (!existsSync8(sessionFile))
|
|
21441
21578
|
return null;
|
|
21442
21579
|
return JSON.parse(readFileSync5(sessionFile, "utf-8"));
|
|
21443
21580
|
} catch {
|
|
@@ -21449,19 +21586,19 @@ function initAssistantsDir(basePath) {
|
|
|
21449
21586
|
const baseDir = basePath || getConfigDir();
|
|
21450
21587
|
const dirs = [
|
|
21451
21588
|
baseDir,
|
|
21452
|
-
|
|
21453
|
-
|
|
21454
|
-
|
|
21455
|
-
|
|
21456
|
-
|
|
21457
|
-
|
|
21458
|
-
|
|
21459
|
-
|
|
21460
|
-
|
|
21589
|
+
join11(baseDir, "logs"),
|
|
21590
|
+
join11(baseDir, "assistants"),
|
|
21591
|
+
join11(baseDir, "shared", "skills"),
|
|
21592
|
+
join11(baseDir, "commands"),
|
|
21593
|
+
join11(baseDir, "temp"),
|
|
21594
|
+
join11(baseDir, "heartbeats"),
|
|
21595
|
+
join11(baseDir, "state"),
|
|
21596
|
+
join11(baseDir, "energy"),
|
|
21597
|
+
join11(baseDir, "migration")
|
|
21461
21598
|
];
|
|
21462
21599
|
for (const dir of dirs) {
|
|
21463
|
-
if (!
|
|
21464
|
-
|
|
21600
|
+
if (!existsSync8(dir)) {
|
|
21601
|
+
mkdirSync5(dir, { recursive: true });
|
|
21465
21602
|
}
|
|
21466
21603
|
}
|
|
21467
21604
|
}
|
|
@@ -21472,20 +21609,20 @@ var init_logger2 = __esm(async () => {
|
|
|
21472
21609
|
});
|
|
21473
21610
|
|
|
21474
21611
|
// packages/core/src/hooks/logger.ts
|
|
21475
|
-
import { join as
|
|
21476
|
-
import { existsSync as
|
|
21612
|
+
import { join as join12 } from "path";
|
|
21613
|
+
import { existsSync as existsSync9, mkdirSync as mkdirSync6, appendFileSync as appendFileSync2, readFileSync as readFileSync6, writeFileSync as writeFileSync4 } from "fs";
|
|
21477
21614
|
function getLogPath() {
|
|
21478
|
-
return
|
|
21615
|
+
return join12(getConfigDir(), "logs", "hooks.jsonl");
|
|
21479
21616
|
}
|
|
21480
21617
|
function ensureLogsDir() {
|
|
21481
|
-
const logsDir =
|
|
21482
|
-
if (!
|
|
21483
|
-
|
|
21618
|
+
const logsDir = join12(getConfigDir(), "logs");
|
|
21619
|
+
if (!existsSync9(logsDir)) {
|
|
21620
|
+
mkdirSync6(logsDir, { recursive: true });
|
|
21484
21621
|
}
|
|
21485
21622
|
}
|
|
21486
21623
|
function rotateIfNeeded() {
|
|
21487
21624
|
const logPath = getLogPath();
|
|
21488
|
-
if (!
|
|
21625
|
+
if (!existsSync9(logPath))
|
|
21489
21626
|
return;
|
|
21490
21627
|
try {
|
|
21491
21628
|
const content = readFileSync6(logPath, "utf-8");
|
|
@@ -21543,7 +21680,7 @@ class HookLogger {
|
|
|
21543
21680
|
}
|
|
21544
21681
|
static getHistory(limit2 = 50, hookId) {
|
|
21545
21682
|
const logPath = getLogPath();
|
|
21546
|
-
if (!
|
|
21683
|
+
if (!existsSync9(logPath))
|
|
21547
21684
|
return [];
|
|
21548
21685
|
try {
|
|
21549
21686
|
const content = readFileSync6(logPath, "utf-8");
|
|
@@ -21565,7 +21702,7 @@ class HookLogger {
|
|
|
21565
21702
|
}
|
|
21566
21703
|
static clearHistory() {
|
|
21567
21704
|
const logPath = getLogPath();
|
|
21568
|
-
if (
|
|
21705
|
+
if (existsSync9(logPath)) {
|
|
21569
21706
|
writeFileSync4(logPath, "", "utf-8");
|
|
21570
21707
|
}
|
|
21571
21708
|
}
|
|
@@ -21947,22 +22084,47 @@ var init_logs = __esm(async () => {
|
|
|
21947
22084
|
});
|
|
21948
22085
|
|
|
21949
22086
|
// packages/core/src/sessions/verification.ts
|
|
21950
|
-
|
|
21951
|
-
|
|
22087
|
+
function getDb3() {
|
|
22088
|
+
return getDatabase();
|
|
22089
|
+
}
|
|
22090
|
+
function rowToSession(row) {
|
|
22091
|
+
try {
|
|
22092
|
+
if (row.data) {
|
|
22093
|
+
return JSON.parse(row.data);
|
|
22094
|
+
}
|
|
22095
|
+
const goals = row.goal ? JSON.parse(row.goal) : [];
|
|
22096
|
+
const result = row.result || "fail";
|
|
22097
|
+
return {
|
|
22098
|
+
id: row.id,
|
|
22099
|
+
parentSessionId: row.session_id,
|
|
22100
|
+
type: "scope-verification",
|
|
22101
|
+
result,
|
|
22102
|
+
goals,
|
|
22103
|
+
reason: "",
|
|
22104
|
+
suggestions: [],
|
|
22105
|
+
verificationResult: {
|
|
22106
|
+
goalsMet: result === "pass",
|
|
22107
|
+
reason: "",
|
|
22108
|
+
suggestions: []
|
|
22109
|
+
},
|
|
22110
|
+
createdAt: row.created_at
|
|
22111
|
+
};
|
|
22112
|
+
} catch {
|
|
22113
|
+
return null;
|
|
22114
|
+
}
|
|
22115
|
+
}
|
|
21952
22116
|
|
|
21953
22117
|
class VerificationSessionStore {
|
|
21954
|
-
basePath;
|
|
21955
22118
|
maxSessions;
|
|
21956
22119
|
lastTimestamp;
|
|
21957
|
-
|
|
21958
|
-
|
|
22120
|
+
db;
|
|
22121
|
+
constructor(dbOrBasePath, maxSessions = 100) {
|
|
21959
22122
|
this.maxSessions = maxSessions;
|
|
21960
22123
|
this.lastTimestamp = 0;
|
|
21961
|
-
|
|
21962
|
-
|
|
21963
|
-
|
|
21964
|
-
|
|
21965
|
-
mkdirSync8(this.basePath, { recursive: true });
|
|
22124
|
+
if (dbOrBasePath && typeof dbOrBasePath === "object" && "exec" in dbOrBasePath) {
|
|
22125
|
+
this.db = dbOrBasePath;
|
|
22126
|
+
} else {
|
|
22127
|
+
this.db = getDb3();
|
|
21966
22128
|
}
|
|
21967
22129
|
}
|
|
21968
22130
|
create(parentSessionId, goals, verificationResult) {
|
|
@@ -21987,50 +22149,34 @@ class VerificationSessionStore {
|
|
|
21987
22149
|
return session;
|
|
21988
22150
|
}
|
|
21989
22151
|
save(session) {
|
|
21990
|
-
|
|
21991
|
-
|
|
22152
|
+
this.db.prepare(`INSERT OR REPLACE INTO verification_sessions (id, session_id, assistant_id, goal, status, result, created_at, completed_at, data)
|
|
22153
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(session.id, session.parentSessionId, null, JSON.stringify(session.goals), session.result === "pass" ? "passed" : session.result === "fail" ? "failed" : session.result, session.result, session.createdAt, null, JSON.stringify(session));
|
|
21992
22154
|
}
|
|
21993
22155
|
get(id) {
|
|
21994
|
-
const
|
|
21995
|
-
if (!
|
|
21996
|
-
return null;
|
|
21997
|
-
}
|
|
21998
|
-
try {
|
|
21999
|
-
const content = readFileSync7(filePath, "utf-8");
|
|
22000
|
-
return JSON.parse(content);
|
|
22001
|
-
} catch {
|
|
22156
|
+
const row = this.db.query("SELECT * FROM verification_sessions WHERE id = ?").get(id);
|
|
22157
|
+
if (!row)
|
|
22002
22158
|
return null;
|
|
22003
|
-
|
|
22159
|
+
return rowToSession(row);
|
|
22004
22160
|
}
|
|
22005
22161
|
getByParentSession(parentSessionId) {
|
|
22162
|
+
const rows = this.db.query("SELECT * FROM verification_sessions WHERE session_id = ? ORDER BY created_at DESC").all(parentSessionId);
|
|
22006
22163
|
const sessions = [];
|
|
22007
|
-
const
|
|
22008
|
-
|
|
22009
|
-
|
|
22010
|
-
|
|
22011
|
-
const session = JSON.parse(content);
|
|
22012
|
-
if (session.parentSessionId === parentSessionId) {
|
|
22013
|
-
sessions.push(session);
|
|
22014
|
-
}
|
|
22015
|
-
} catch {
|
|
22016
|
-
continue;
|
|
22017
|
-
}
|
|
22164
|
+
for (const row of rows) {
|
|
22165
|
+
const session = rowToSession(row);
|
|
22166
|
+
if (session)
|
|
22167
|
+
sessions.push(session);
|
|
22018
22168
|
}
|
|
22019
|
-
return sessions
|
|
22169
|
+
return sessions;
|
|
22020
22170
|
}
|
|
22021
22171
|
listRecent(limit2 = 10) {
|
|
22172
|
+
const rows = this.db.query("SELECT * FROM verification_sessions ORDER BY created_at DESC LIMIT ?").all(limit2);
|
|
22022
22173
|
const sessions = [];
|
|
22023
|
-
const
|
|
22024
|
-
|
|
22025
|
-
|
|
22026
|
-
const content = readFileSync7(join14(this.basePath, file), "utf-8");
|
|
22027
|
-
const session = JSON.parse(content);
|
|
22174
|
+
for (const row of rows) {
|
|
22175
|
+
const session = rowToSession(row);
|
|
22176
|
+
if (session)
|
|
22028
22177
|
sessions.push(session);
|
|
22029
|
-
} catch {
|
|
22030
|
-
continue;
|
|
22031
|
-
}
|
|
22032
22178
|
}
|
|
22033
|
-
return sessions
|
|
22179
|
+
return sessions;
|
|
22034
22180
|
}
|
|
22035
22181
|
updateResult(id, result) {
|
|
22036
22182
|
const session = this.get(id);
|
|
@@ -22039,53 +22185,22 @@ class VerificationSessionStore {
|
|
|
22039
22185
|
session.result = result;
|
|
22040
22186
|
this.save(session);
|
|
22041
22187
|
}
|
|
22042
|
-
listFiles() {
|
|
22043
|
-
if (!existsSync11(this.basePath)) {
|
|
22044
|
-
return [];
|
|
22045
|
-
}
|
|
22046
|
-
return readdirSync6(this.basePath).filter((f) => f.endsWith(".json"));
|
|
22047
|
-
}
|
|
22048
22188
|
pruneOldSessions() {
|
|
22049
|
-
const
|
|
22050
|
-
|
|
22189
|
+
const countRow = this.db.query("SELECT COUNT(*) as cnt FROM verification_sessions").get();
|
|
22190
|
+
const count = countRow?.cnt || 0;
|
|
22191
|
+
if (count <= this.maxSessions)
|
|
22051
22192
|
return;
|
|
22052
|
-
|
|
22053
|
-
|
|
22054
|
-
|
|
22055
|
-
try {
|
|
22056
|
-
const content = readFileSync7(join14(this.basePath, file), "utf-8");
|
|
22057
|
-
const session = JSON.parse(content);
|
|
22058
|
-
sessions.push({
|
|
22059
|
-
file,
|
|
22060
|
-
timestamp: new Date(session.createdAt).getTime()
|
|
22061
|
-
});
|
|
22062
|
-
} catch {
|
|
22063
|
-
continue;
|
|
22064
|
-
}
|
|
22065
|
-
}
|
|
22066
|
-
sessions.sort((a, b) => a.timestamp - b.timestamp);
|
|
22067
|
-
const toRemove = sessions.slice(0, sessions.length - this.maxSessions);
|
|
22068
|
-
for (const item of toRemove) {
|
|
22069
|
-
try {
|
|
22070
|
-
unlinkSync2(join14(this.basePath, item.file));
|
|
22071
|
-
} catch {
|
|
22072
|
-
continue;
|
|
22073
|
-
}
|
|
22074
|
-
}
|
|
22193
|
+
this.db.prepare(`DELETE FROM verification_sessions WHERE id IN (
|
|
22194
|
+
SELECT id FROM verification_sessions ORDER BY created_at ASC LIMIT ?
|
|
22195
|
+
)`).run(count - this.maxSessions);
|
|
22075
22196
|
}
|
|
22076
22197
|
clear() {
|
|
22077
|
-
|
|
22078
|
-
for (const file of files) {
|
|
22079
|
-
try {
|
|
22080
|
-
unlinkSync2(join14(this.basePath, file));
|
|
22081
|
-
} catch {
|
|
22082
|
-
continue;
|
|
22083
|
-
}
|
|
22084
|
-
}
|
|
22198
|
+
this.db.prepare("DELETE FROM verification_sessions").run();
|
|
22085
22199
|
}
|
|
22086
22200
|
}
|
|
22087
|
-
var init_verification = __esm(() => {
|
|
22201
|
+
var init_verification = __esm(async () => {
|
|
22088
22202
|
init_src2();
|
|
22203
|
+
await init_database();
|
|
22089
22204
|
});
|
|
22090
22205
|
|
|
22091
22206
|
// packages/core/src/hooks/loader.ts
|
|
@@ -22226,7 +22341,7 @@ var init_background = __esm(() => {
|
|
|
22226
22341
|
});
|
|
22227
22342
|
|
|
22228
22343
|
// packages/core/src/hooks/executor.ts
|
|
22229
|
-
import { existsSync as
|
|
22344
|
+
import { existsSync as existsSync10 } from "fs";
|
|
22230
22345
|
function killSpawnedProcess(proc) {
|
|
22231
22346
|
proc.kill();
|
|
22232
22347
|
}
|
|
@@ -22357,7 +22472,7 @@ class HookExecutor {
|
|
|
22357
22472
|
}
|
|
22358
22473
|
try {
|
|
22359
22474
|
const runtime = getRuntime();
|
|
22360
|
-
const cwd = input.cwd &&
|
|
22475
|
+
const cwd = input.cwd && existsSync10(input.cwd) ? input.cwd : process.cwd();
|
|
22361
22476
|
const isWindows = process.platform === "win32";
|
|
22362
22477
|
const shellBinary = isWindows ? "cmd" : runtime.which("bash") || "sh";
|
|
22363
22478
|
const shellArgs = isWindows ? ["/c", hook.command] : ["-lc", hook.command];
|
|
@@ -22410,7 +22525,7 @@ class HookExecutor {
|
|
|
22410
22525
|
return null;
|
|
22411
22526
|
try {
|
|
22412
22527
|
const runtime = getRuntime();
|
|
22413
|
-
const cwd = input.cwd &&
|
|
22528
|
+
const cwd = input.cwd && existsSync10(input.cwd) ? input.cwd : process.cwd();
|
|
22414
22529
|
const isWindows = process.platform === "win32";
|
|
22415
22530
|
const shellBinary = isWindows ? "cmd" : runtime.which("bash") || "sh";
|
|
22416
22531
|
const shellArgs = isWindows ? ["/c", hook.command] : ["-lc", hook.command];
|
|
@@ -22991,13 +23106,15 @@ Respond with ONLY valid JSON in this exact format:
|
|
|
22991
23106
|
}`;
|
|
22992
23107
|
var init_scope_verification = __esm(async () => {
|
|
22993
23108
|
init_src2();
|
|
22994
|
-
|
|
22995
|
-
|
|
23109
|
+
await __promiseAll([
|
|
23110
|
+
init_verification(),
|
|
23111
|
+
init_config()
|
|
23112
|
+
]);
|
|
22996
23113
|
});
|
|
22997
23114
|
|
|
22998
23115
|
// packages/core/src/hooks/store.ts
|
|
22999
|
-
import { readFileSync as
|
|
23000
|
-
import { join as
|
|
23116
|
+
import { readFileSync as readFileSync7, writeFileSync as writeFileSync5, existsSync as existsSync11, mkdirSync as mkdirSync7 } from "fs";
|
|
23117
|
+
import { join as join13, dirname as dirname6 } from "path";
|
|
23001
23118
|
import { createHash as createHash2 } from "crypto";
|
|
23002
23119
|
function generateHookId2(event, hook) {
|
|
23003
23120
|
const content = hook.command || hook.prompt || "";
|
|
@@ -23026,20 +23143,20 @@ class HookStore {
|
|
|
23026
23143
|
getFilePath(location) {
|
|
23027
23144
|
switch (location) {
|
|
23028
23145
|
case "user":
|
|
23029
|
-
return
|
|
23146
|
+
return join13(this.baseDir || getConfigDir(), "hooks.json");
|
|
23030
23147
|
case "project":
|
|
23031
|
-
return
|
|
23148
|
+
return join13(this.cwd, ".assistants", "hooks.json");
|
|
23032
23149
|
case "local":
|
|
23033
|
-
return
|
|
23150
|
+
return join13(this.cwd, ".assistants", "hooks.local.json");
|
|
23034
23151
|
}
|
|
23035
23152
|
}
|
|
23036
23153
|
loadFrom(location) {
|
|
23037
23154
|
const filePath = this.getFilePath(location);
|
|
23038
|
-
if (!
|
|
23155
|
+
if (!existsSync11(filePath)) {
|
|
23039
23156
|
return {};
|
|
23040
23157
|
}
|
|
23041
23158
|
try {
|
|
23042
|
-
const content =
|
|
23159
|
+
const content = readFileSync7(filePath, "utf-8");
|
|
23043
23160
|
const data = JSON.parse(content);
|
|
23044
23161
|
const config = data.hooks || data;
|
|
23045
23162
|
ensureHookIds(config);
|
|
@@ -23050,12 +23167,12 @@ class HookStore {
|
|
|
23050
23167
|
}
|
|
23051
23168
|
save(location, config) {
|
|
23052
23169
|
const filePath = this.getFilePath(location);
|
|
23053
|
-
const dir =
|
|
23054
|
-
if (!
|
|
23055
|
-
|
|
23170
|
+
const dir = dirname6(filePath);
|
|
23171
|
+
if (!existsSync11(dir)) {
|
|
23172
|
+
mkdirSync7(dir, { recursive: true });
|
|
23056
23173
|
}
|
|
23057
23174
|
ensureHookIds(config);
|
|
23058
|
-
|
|
23175
|
+
writeFileSync5(filePath, JSON.stringify({ hooks: config }, null, 2), "utf-8");
|
|
23059
23176
|
}
|
|
23060
23177
|
loadAll() {
|
|
23061
23178
|
const userHooks = this.loadFrom("user");
|
|
@@ -23194,7 +23311,7 @@ var init_store2 = __esm(async () => {
|
|
|
23194
23311
|
});
|
|
23195
23312
|
|
|
23196
23313
|
// packages/core/src/hooks/tester.ts
|
|
23197
|
-
import { existsSync as
|
|
23314
|
+
import { existsSync as existsSync12 } from "fs";
|
|
23198
23315
|
|
|
23199
23316
|
class HookTester {
|
|
23200
23317
|
cwd;
|
|
@@ -23258,7 +23375,7 @@ class HookTester {
|
|
|
23258
23375
|
}
|
|
23259
23376
|
async executeCommand(command, input, timeout) {
|
|
23260
23377
|
const runtime = getRuntime();
|
|
23261
|
-
const cwd = input.cwd &&
|
|
23378
|
+
const cwd = input.cwd && existsSync12(input.cwd) ? input.cwd : process.cwd();
|
|
23262
23379
|
const isWindows = process.platform === "win32";
|
|
23263
23380
|
const shellBinary = isWindows ? "cmd" : runtime.which("bash") || "sh";
|
|
23264
23381
|
const shellArgs = isWindows ? ["/c", command] : ["-lc", command];
|
|
@@ -23759,8 +23876,8 @@ function registerVerificationTools(registry, context) {
|
|
|
23759
23876
|
}
|
|
23760
23877
|
var verificationListTool, verificationGetTool, verificationStatusTool, verificationEnableTool, verificationDisableTool, verificationTools;
|
|
23761
23878
|
var init_verification2 = __esm(async () => {
|
|
23762
|
-
init_verification();
|
|
23763
23879
|
await __promiseAll([
|
|
23880
|
+
init_verification(),
|
|
23764
23881
|
init_hooks(),
|
|
23765
23882
|
init_config()
|
|
23766
23883
|
]);
|
|
@@ -24679,12 +24796,12 @@ var init_path_validator = __esm(() => {
|
|
|
24679
24796
|
});
|
|
24680
24797
|
|
|
24681
24798
|
// packages/core/src/tools/filesystem.ts
|
|
24682
|
-
import { join as
|
|
24799
|
+
import { join as join14, resolve as resolve4, dirname as dirname7, sep } from "path";
|
|
24683
24800
|
import { homedir as homedir8 } from "os";
|
|
24684
24801
|
import { mkdir as mkdir4 } from "fs/promises";
|
|
24685
24802
|
function getScriptsFolder(cwd, sessionId) {
|
|
24686
24803
|
const resolvedSessionId = sessionId || currentSessionId;
|
|
24687
|
-
return
|
|
24804
|
+
return join14(getProjectDataDir(cwd), "scripts", resolvedSessionId);
|
|
24688
24805
|
}
|
|
24689
24806
|
function isInScriptsFolder(path2, cwd, sessionId) {
|
|
24690
24807
|
const scriptsFolder = resolve4(getScriptsFolder(cwd, sessionId));
|
|
@@ -24947,7 +25064,7 @@ var init_filesystem = __esm(async () => {
|
|
|
24947
25064
|
});
|
|
24948
25065
|
}
|
|
24949
25066
|
const sanitizedFilename = filename.replace(/\.\.[/\\]/g, "").replace(/\.\./g, "").replace(/^[/\\]+/, "");
|
|
24950
|
-
const path2 =
|
|
25067
|
+
const path2 = join14(scriptsFolder, sanitizedFilename);
|
|
24951
25068
|
if (!isInScriptsFolder(path2, baseCwd, input.sessionId)) {
|
|
24952
25069
|
throw new ToolExecutionError(`Cannot write outside scripts folder. Files are saved to ${scriptsFolder}`, {
|
|
24953
25070
|
toolName: "write",
|
|
@@ -24990,7 +25107,7 @@ var init_filesystem = __esm(async () => {
|
|
|
24990
25107
|
retryable: false
|
|
24991
25108
|
});
|
|
24992
25109
|
}
|
|
24993
|
-
const dir =
|
|
25110
|
+
const dir = dirname7(validated.resolved);
|
|
24994
25111
|
await mkdir4(dir, { recursive: true });
|
|
24995
25112
|
const runtime = getRuntime();
|
|
24996
25113
|
await runtime.write(validated.resolved, content);
|
|
@@ -25198,7 +25315,7 @@ var init_filesystem = __esm(async () => {
|
|
|
25198
25315
|
if (file.includes(".Trash") || file.includes(".Spotlight-V100") || file.includes(".fseventsd")) {
|
|
25199
25316
|
continue;
|
|
25200
25317
|
}
|
|
25201
|
-
const filePath =
|
|
25318
|
+
const filePath = join14(validated.resolved, file);
|
|
25202
25319
|
try {
|
|
25203
25320
|
const content = await runtime.file(filePath).text();
|
|
25204
25321
|
const lines = content.split(`
|
|
@@ -26128,8 +26245,8 @@ ${responseBody || "(empty response)"}`;
|
|
|
26128
26245
|
});
|
|
26129
26246
|
|
|
26130
26247
|
// packages/core/src/tools/feedback.ts
|
|
26131
|
-
import { join as
|
|
26132
|
-
import { mkdirSync as
|
|
26248
|
+
import { join as join15 } from "path";
|
|
26249
|
+
import { mkdirSync as mkdirSync8, writeFileSync as writeFileSync6 } from "fs";
|
|
26133
26250
|
function normalizeTags(value) {
|
|
26134
26251
|
if (Array.isArray(value)) {
|
|
26135
26252
|
const tags = value.map((t) => String(t).trim()).filter(Boolean);
|
|
@@ -26143,13 +26260,13 @@ function normalizeTags(value) {
|
|
|
26143
26260
|
}
|
|
26144
26261
|
function resolveFeedbackDir(cwd) {
|
|
26145
26262
|
const baseCwd = cwd && cwd.trim().length > 0 ? cwd : process.cwd();
|
|
26146
|
-
return
|
|
26263
|
+
return join15(getProjectDataDir(baseCwd), "feedback");
|
|
26147
26264
|
}
|
|
26148
26265
|
function saveFeedbackEntry(entry, cwd) {
|
|
26149
26266
|
const feedbackDir = resolveFeedbackDir(cwd);
|
|
26150
|
-
|
|
26151
|
-
const path2 =
|
|
26152
|
-
|
|
26267
|
+
mkdirSync8(feedbackDir, { recursive: true });
|
|
26268
|
+
const path2 = join15(feedbackDir, `${entry.id}.json`);
|
|
26269
|
+
writeFileSync6(path2, JSON.stringify(entry, null, 2));
|
|
26153
26270
|
return { path: path2 };
|
|
26154
26271
|
}
|
|
26155
26272
|
function buildEntry(input, overrides) {
|
|
@@ -26248,7 +26365,7 @@ Path: ${path2}`;
|
|
|
26248
26365
|
});
|
|
26249
26366
|
|
|
26250
26367
|
// packages/core/src/scheduler/store.ts
|
|
26251
|
-
function
|
|
26368
|
+
function getDb4() {
|
|
26252
26369
|
return getDatabase();
|
|
26253
26370
|
}
|
|
26254
26371
|
function rowToSchedule(row) {
|
|
@@ -26269,7 +26386,7 @@ function rowToSchedule(row) {
|
|
|
26269
26386
|
};
|
|
26270
26387
|
}
|
|
26271
26388
|
async function listSchedules(cwd, options) {
|
|
26272
|
-
const rows =
|
|
26389
|
+
const rows = getDb4().query("SELECT * FROM schedules WHERE project_path = ?").all(cwd);
|
|
26273
26390
|
const schedules = rows.map(rowToSchedule);
|
|
26274
26391
|
if (options?.sessionId && !options?.global) {
|
|
26275
26392
|
return schedules.filter((s) => s.sessionId === options.sessionId || !s.sessionId);
|
|
@@ -26279,17 +26396,17 @@ async function listSchedules(cwd, options) {
|
|
|
26279
26396
|
async function saveSchedule(cwd, schedule) {
|
|
26280
26397
|
const scheduleJson = JSON.stringify(schedule.schedule);
|
|
26281
26398
|
const data = JSON.stringify(schedule);
|
|
26282
|
-
|
|
26399
|
+
getDb4().prepare(`INSERT OR REPLACE INTO schedules (id, project_path, command, schedule, status, session_id, next_run_at, last_run_at, run_count, max_runs, created_at, updated_at, data)
|
|
26283
26400
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(schedule.id, cwd, schedule.command, scheduleJson, schedule.status, schedule.sessionId ?? null, schedule.nextRunAt ?? null, schedule.lastRunAt ?? null, 0, null, String(schedule.createdAt), String(schedule.updatedAt), data);
|
|
26284
26401
|
}
|
|
26285
26402
|
async function getSchedule(cwd, id) {
|
|
26286
|
-
const row =
|
|
26403
|
+
const row = getDb4().query("SELECT * FROM schedules WHERE id = ?").get(id);
|
|
26287
26404
|
if (!row)
|
|
26288
26405
|
return null;
|
|
26289
26406
|
return rowToSchedule(row);
|
|
26290
26407
|
}
|
|
26291
26408
|
async function deleteSchedule(cwd, id) {
|
|
26292
|
-
const result =
|
|
26409
|
+
const result = getDb4().prepare("DELETE FROM schedules WHERE id = ?").run(id);
|
|
26293
26410
|
return result.changes > 0;
|
|
26294
26411
|
}
|
|
26295
26412
|
function computeNextRun2(schedule, fromTime) {
|
|
@@ -26340,11 +26457,11 @@ function computeIntervalNextRun(schedule, fromTime) {
|
|
|
26340
26457
|
return fromTime + intervalMs;
|
|
26341
26458
|
}
|
|
26342
26459
|
async function getDueSchedules(cwd, nowTime) {
|
|
26343
|
-
const rows =
|
|
26460
|
+
const rows = getDb4().query("SELECT * FROM schedules WHERE project_path = ? AND status = 'active' AND next_run_at IS NOT NULL AND next_run_at <= ?").all(cwd, nowTime);
|
|
26344
26461
|
return rows.map(rowToSchedule).filter((s) => Number.isFinite(s.nextRunAt));
|
|
26345
26462
|
}
|
|
26346
26463
|
async function updateSchedule(cwd, id, updater, _options) {
|
|
26347
|
-
const d =
|
|
26464
|
+
const d = getDb4();
|
|
26348
26465
|
return d.transaction(() => {
|
|
26349
26466
|
const row = d.query("SELECT * FROM schedules WHERE id = ?").get(id);
|
|
26350
26467
|
if (!row)
|
|
@@ -26704,9 +26821,9 @@ var init_scheduler = __esm(async () => {
|
|
|
26704
26821
|
});
|
|
26705
26822
|
|
|
26706
26823
|
// packages/core/src/tools/image.ts
|
|
26707
|
-
import { existsSync as
|
|
26824
|
+
import { existsSync as existsSync13, writeFileSync as writeFileSync7 } from "fs";
|
|
26708
26825
|
import { tmpdir } from "os";
|
|
26709
|
-
import { join as
|
|
26826
|
+
import { join as join16, basename as basename3 } from "path";
|
|
26710
26827
|
|
|
26711
26828
|
class ImageTools {
|
|
26712
26829
|
static registerAll(registry) {
|
|
@@ -26801,8 +26918,8 @@ var init_image = __esm(() => {
|
|
|
26801
26918
|
offset += chunk.length;
|
|
26802
26919
|
}
|
|
26803
26920
|
const ext = contentType.split("/")[1]?.split(";")[0] || "png";
|
|
26804
|
-
const tempFile =
|
|
26805
|
-
|
|
26921
|
+
const tempFile = join16(tmpdir(), `assistants-image-${generateId()}.${ext}`);
|
|
26922
|
+
writeFileSync7(tempFile, buffer);
|
|
26806
26923
|
localPath = tempFile;
|
|
26807
26924
|
} catch (error2) {
|
|
26808
26925
|
if (error2 instanceof Error && error2.name === "AbortError") {
|
|
@@ -26811,7 +26928,7 @@ var init_image = __esm(() => {
|
|
|
26811
26928
|
return `Error: Failed to fetch image: ${error2 instanceof Error ? error2.message : String(error2)}`;
|
|
26812
26929
|
}
|
|
26813
26930
|
}
|
|
26814
|
-
if (!
|
|
26931
|
+
if (!existsSync13(localPath)) {
|
|
26815
26932
|
return `Error: Image file not found: ${localPath}`;
|
|
26816
26933
|
}
|
|
26817
26934
|
return JSON.stringify({
|
|
@@ -26826,18 +26943,18 @@ var init_image = __esm(() => {
|
|
|
26826
26943
|
});
|
|
26827
26944
|
|
|
26828
26945
|
// packages/core/src/voice/utils.ts
|
|
26829
|
-
import { existsSync as
|
|
26946
|
+
import { existsSync as existsSync14, readFileSync as readFileSync8 } from "fs";
|
|
26830
26947
|
import { homedir as homedir9 } from "os";
|
|
26831
|
-
import { join as
|
|
26948
|
+
import { join as join17 } from "path";
|
|
26832
26949
|
import { spawnSync } from "child_process";
|
|
26833
26950
|
function loadApiKeyFromSecrets2(key) {
|
|
26834
26951
|
const envHome = process.env.HOME || process.env.USERPROFILE;
|
|
26835
26952
|
const homeDir = envHome && envHome.trim().length > 0 ? envHome : homedir9();
|
|
26836
|
-
const secretsPath =
|
|
26837
|
-
if (!
|
|
26953
|
+
const secretsPath = join17(homeDir, ".secrets");
|
|
26954
|
+
if (!existsSync14(secretsPath))
|
|
26838
26955
|
return;
|
|
26839
26956
|
try {
|
|
26840
|
-
const content =
|
|
26957
|
+
const content = readFileSync8(secretsPath, "utf-8");
|
|
26841
26958
|
const match = content.match(new RegExp(`export\\s+${key}\\s*=\\s*['"]?([^'"\\n]+)['"]?`));
|
|
26842
26959
|
return match?.[1];
|
|
26843
26960
|
} catch {
|
|
@@ -27289,7 +27406,7 @@ ${result.text}`;
|
|
|
27289
27406
|
});
|
|
27290
27407
|
|
|
27291
27408
|
// packages/core/src/skills/create.ts
|
|
27292
|
-
import { join as
|
|
27409
|
+
import { join as join18, dirname as dirname8 } from "path";
|
|
27293
27410
|
import { homedir as homedir11 } from "os";
|
|
27294
27411
|
import { mkdir as mkdir5, stat, writeFile as writeFile2, rm } from "fs/promises";
|
|
27295
27412
|
function slugify(input) {
|
|
@@ -27347,9 +27464,9 @@ function buildDefaultContent() {
|
|
|
27347
27464
|
}
|
|
27348
27465
|
function resolveSkillRoot(scope, cwd) {
|
|
27349
27466
|
if (scope === "global") {
|
|
27350
|
-
return
|
|
27467
|
+
return join18(homedir11(), ".skill");
|
|
27351
27468
|
}
|
|
27352
|
-
return
|
|
27469
|
+
return join18(cwd, ".skill");
|
|
27353
27470
|
}
|
|
27354
27471
|
async function pathExists(path2) {
|
|
27355
27472
|
try {
|
|
@@ -27360,15 +27477,15 @@ async function pathExists(path2) {
|
|
|
27360
27477
|
}
|
|
27361
27478
|
}
|
|
27362
27479
|
async function deleteSkill(filePath) {
|
|
27363
|
-
const skillDir =
|
|
27480
|
+
const skillDir = dirname8(filePath);
|
|
27364
27481
|
await rm(skillDir, { recursive: true });
|
|
27365
27482
|
}
|
|
27366
27483
|
async function createSkill(options) {
|
|
27367
27484
|
const scope = options.scope ?? "project";
|
|
27368
27485
|
const { skillName, dirName } = normalizeName2(options.name);
|
|
27369
27486
|
const root = resolveSkillRoot(scope, options.cwd);
|
|
27370
|
-
const directory =
|
|
27371
|
-
const filePath =
|
|
27487
|
+
const directory = join18(root, dirName);
|
|
27488
|
+
const filePath = join18(directory, "SKILL.md");
|
|
27372
27489
|
if (!options.overwrite && await pathExists(filePath)) {
|
|
27373
27490
|
throw new Error(`Skill already exists at ${filePath}`);
|
|
27374
27491
|
}
|
|
@@ -27390,7 +27507,7 @@ ${content}
|
|
|
27390
27507
|
var init_create = () => {};
|
|
27391
27508
|
|
|
27392
27509
|
// packages/core/src/skills/executor.ts
|
|
27393
|
-
import { dirname as
|
|
27510
|
+
import { dirname as dirname9 } from "path";
|
|
27394
27511
|
|
|
27395
27512
|
class SkillExecutor {
|
|
27396
27513
|
constructor() {}
|
|
@@ -27411,7 +27528,7 @@ ARGUMENTS: ${args.join(" ")}`;
|
|
|
27411
27528
|
if (matches.length === 0) {
|
|
27412
27529
|
return content;
|
|
27413
27530
|
}
|
|
27414
|
-
const skillDir =
|
|
27531
|
+
const skillDir = dirname9(skillFilePath);
|
|
27415
27532
|
let result = content;
|
|
27416
27533
|
const runtime = getRuntime();
|
|
27417
27534
|
for (const match of matches) {
|
|
@@ -27448,25 +27565,25 @@ var init_executor2 = __esm(async () => {
|
|
|
27448
27565
|
});
|
|
27449
27566
|
|
|
27450
27567
|
// packages/core/src/skills/installer.ts
|
|
27451
|
-
import { join as
|
|
27568
|
+
import { join as join19 } from "path";
|
|
27452
27569
|
import { homedir as homedir12 } from "os";
|
|
27453
|
-
import { mkdir as mkdir6, readFile as
|
|
27570
|
+
import { mkdir as mkdir6, readFile as readFile3, writeFile as writeFile3, stat as stat2 } from "fs/promises";
|
|
27454
27571
|
function resolveSkillRoot2(scope, cwd) {
|
|
27455
27572
|
if (scope === "global") {
|
|
27456
|
-
return
|
|
27573
|
+
return join19(homedir12(), ".skill");
|
|
27457
27574
|
}
|
|
27458
|
-
return
|
|
27575
|
+
return join19(cwd || process.cwd(), ".skill");
|
|
27459
27576
|
}
|
|
27460
27577
|
async function ensurePackageJson(dir) {
|
|
27461
27578
|
await mkdir6(dir, { recursive: true });
|
|
27462
|
-
const pkgPath =
|
|
27579
|
+
const pkgPath = join19(dir, "package.json");
|
|
27463
27580
|
try {
|
|
27464
27581
|
await stat2(pkgPath);
|
|
27465
27582
|
} catch {
|
|
27466
27583
|
await writeFile3(pkgPath, JSON.stringify({ name: "assistants-skills", private: true, dependencies: {} }, null, 2) + `
|
|
27467
27584
|
`);
|
|
27468
27585
|
}
|
|
27469
|
-
const gitignorePath =
|
|
27586
|
+
const gitignorePath = join19(dir, ".gitignore");
|
|
27470
27587
|
try {
|
|
27471
27588
|
await stat2(gitignorePath);
|
|
27472
27589
|
} catch {
|
|
@@ -27489,10 +27606,10 @@ async function install(options) {
|
|
|
27489
27606
|
const stderr = result.stderr.toString().trim();
|
|
27490
27607
|
throw new Error(`Failed to install ${packageName}: ${stderr || "unknown error"}`);
|
|
27491
27608
|
}
|
|
27492
|
-
const skillDir =
|
|
27609
|
+
const skillDir = join19(root, "node_modules", "@hasnaxyz", `skill-${rawName}`);
|
|
27493
27610
|
let version = "unknown";
|
|
27494
27611
|
try {
|
|
27495
|
-
const pkgJson = JSON.parse(await
|
|
27612
|
+
const pkgJson = JSON.parse(await readFile3(join19(skillDir, "package.json"), "utf-8"));
|
|
27496
27613
|
version = pkgJson.version || "unknown";
|
|
27497
27614
|
} catch {}
|
|
27498
27615
|
return { name: rawName, packageName, version, skillDir };
|
|
@@ -27515,9 +27632,9 @@ async function uninstall(name, scope, cwd) {
|
|
|
27515
27632
|
async function listInstalled(scope, cwd) {
|
|
27516
27633
|
const resolvedScope = scope ?? "project";
|
|
27517
27634
|
const root = resolveSkillRoot2(resolvedScope, cwd);
|
|
27518
|
-
const pkgPath =
|
|
27635
|
+
const pkgPath = join19(root, "package.json");
|
|
27519
27636
|
try {
|
|
27520
|
-
const pkgJson = JSON.parse(await
|
|
27637
|
+
const pkgJson = JSON.parse(await readFile3(pkgPath, "utf-8"));
|
|
27521
27638
|
const deps = pkgJson.dependencies || {};
|
|
27522
27639
|
const results = [];
|
|
27523
27640
|
for (const [name, version] of Object.entries(deps)) {
|
|
@@ -33573,9 +33690,9 @@ var require_out4 = __commonJS((exports, module) => {
|
|
|
33573
33690
|
});
|
|
33574
33691
|
|
|
33575
33692
|
// packages/core/src/skills/loader.ts
|
|
33576
|
-
import { join as
|
|
33693
|
+
import { join as join20, basename as basename4, dirname as dirname10 } from "path";
|
|
33577
33694
|
import { homedir as homedir13 } from "os";
|
|
33578
|
-
import { readFile as
|
|
33695
|
+
import { readFile as readFile4, stat as stat3 } from "fs/promises";
|
|
33579
33696
|
|
|
33580
33697
|
class SkillLoader {
|
|
33581
33698
|
skills = new Map;
|
|
@@ -33583,8 +33700,8 @@ class SkillLoader {
|
|
|
33583
33700
|
const includeContent = options.includeContent ?? true;
|
|
33584
33701
|
const envHome = process.env.HOME || process.env.USERPROFILE;
|
|
33585
33702
|
const userHome = envHome && envHome.trim().length > 0 ? envHome : homedir13();
|
|
33586
|
-
const globalRoot =
|
|
33587
|
-
const projectRoot =
|
|
33703
|
+
const globalRoot = join20(userHome, ".skill");
|
|
33704
|
+
const projectRoot = join20(projectDir, ".skill");
|
|
33588
33705
|
await this.loadNpmSkills(globalRoot, { includeContent });
|
|
33589
33706
|
await this.loadLocalSkills(globalRoot, { includeContent });
|
|
33590
33707
|
await this.loadNpmSkills(projectRoot, { includeContent });
|
|
@@ -33593,7 +33710,7 @@ class SkillLoader {
|
|
|
33593
33710
|
async loadNpmSkills(skillRoot, options) {
|
|
33594
33711
|
const includeContent = options.includeContent ?? true;
|
|
33595
33712
|
try {
|
|
33596
|
-
const nmDir =
|
|
33713
|
+
const nmDir = join20(skillRoot, "node_modules", "@hasnaxyz");
|
|
33597
33714
|
try {
|
|
33598
33715
|
const stats = await stat3(nmDir);
|
|
33599
33716
|
if (!stats.isDirectory())
|
|
@@ -33604,10 +33721,10 @@ class SkillLoader {
|
|
|
33604
33721
|
const files = await import_fast_glob.default("skill-*/SKILL.md", { cwd: nmDir });
|
|
33605
33722
|
const tasks = [];
|
|
33606
33723
|
for (const file of files) {
|
|
33607
|
-
const fullPath =
|
|
33724
|
+
const fullPath = join20(nmDir, file);
|
|
33608
33725
|
const dirName = file.split(/[\\/]/)[0];
|
|
33609
33726
|
const packageName = `@hasnaxyz/${dirName}`;
|
|
33610
|
-
const pkgJsonPath =
|
|
33727
|
+
const pkgJsonPath = join20(nmDir, dirName, "package.json");
|
|
33611
33728
|
tasks.push(this.loadNpmSkillFile(fullPath, pkgJsonPath, packageName, { includeContent }));
|
|
33612
33729
|
}
|
|
33613
33730
|
await Promise.all(tasks);
|
|
@@ -33616,7 +33733,7 @@ class SkillLoader {
|
|
|
33616
33733
|
async loadNpmSkillFile(filePath, pkgJsonPath, packageName, options) {
|
|
33617
33734
|
let version;
|
|
33618
33735
|
try {
|
|
33619
|
-
const pkgJson = JSON.parse(await
|
|
33736
|
+
const pkgJson = JSON.parse(await readFile4(pkgJsonPath, "utf-8"));
|
|
33620
33737
|
version = pkgJson.version;
|
|
33621
33738
|
} catch {}
|
|
33622
33739
|
return this.loadSkillFile(filePath, options, {
|
|
@@ -33641,7 +33758,7 @@ class SkillLoader {
|
|
|
33641
33758
|
});
|
|
33642
33759
|
const tasks = [];
|
|
33643
33760
|
for (const file of files) {
|
|
33644
|
-
tasks.push(this.loadSkillFile(
|
|
33761
|
+
tasks.push(this.loadSkillFile(join20(skillRoot, file), { includeContent }, { source: "local" }));
|
|
33645
33762
|
}
|
|
33646
33763
|
await Promise.all(tasks);
|
|
33647
33764
|
} catch {}
|
|
@@ -33659,13 +33776,13 @@ class SkillLoader {
|
|
|
33659
33776
|
const filesToLoad = [];
|
|
33660
33777
|
const skillPrefixFiles = await import_fast_glob.default("skill-*/SKILL.md", { cwd: dir });
|
|
33661
33778
|
for (const file of skillPrefixFiles) {
|
|
33662
|
-
filesToLoad.push(
|
|
33779
|
+
filesToLoad.push(join20(dir, file));
|
|
33663
33780
|
}
|
|
33664
33781
|
const regularFiles = await import_fast_glob.default("*/SKILL.md", { cwd: dir });
|
|
33665
33782
|
for (const file of regularFiles) {
|
|
33666
33783
|
const dirName = file.split(/[\\/]/)[0];
|
|
33667
33784
|
if (!dirName.startsWith("skill-")) {
|
|
33668
|
-
filesToLoad.push(
|
|
33785
|
+
filesToLoad.push(join20(dir, file));
|
|
33669
33786
|
}
|
|
33670
33787
|
}
|
|
33671
33788
|
const loadTasks = [];
|
|
@@ -33677,10 +33794,10 @@ class SkillLoader {
|
|
|
33677
33794
|
}
|
|
33678
33795
|
async loadSkillFile(filePath, options = {}, extra) {
|
|
33679
33796
|
try {
|
|
33680
|
-
const content = await
|
|
33797
|
+
const content = await readFile4(filePath, "utf-8");
|
|
33681
33798
|
const { frontmatter, content: markdownContent } = parseFrontmatter(content);
|
|
33682
33799
|
const includeContent = options.includeContent ?? true;
|
|
33683
|
-
const dirName = basename4(
|
|
33800
|
+
const dirName = basename4(dirname10(filePath));
|
|
33684
33801
|
const name = frontmatter.name || dirName;
|
|
33685
33802
|
let description = frontmatter.description || "";
|
|
33686
33803
|
if (!description && markdownContent) {
|
|
@@ -33789,8 +33906,8 @@ var init_loader2 = __esm(() => {
|
|
|
33789
33906
|
import_fast_glob = __toESM(require_out4(), 1);
|
|
33790
33907
|
});
|
|
33791
33908
|
// packages/core/src/commands/loader.ts
|
|
33792
|
-
import { existsSync as
|
|
33793
|
-
import { join as
|
|
33909
|
+
import { existsSync as existsSync15, readdirSync as readdirSync5, statSync as statSync3 } from "fs";
|
|
33910
|
+
import { join as join21, basename as basename5, extname as extname2 } from "path";
|
|
33794
33911
|
import { homedir as homedir14 } from "os";
|
|
33795
33912
|
|
|
33796
33913
|
class CommandLoader {
|
|
@@ -33803,17 +33920,17 @@ class CommandLoader {
|
|
|
33803
33920
|
this.commands.clear();
|
|
33804
33921
|
const envHome = process.env.HOME || process.env.USERPROFILE;
|
|
33805
33922
|
const homeDir = envHome && envHome.trim().length > 0 ? envHome : homedir14();
|
|
33806
|
-
const globalDir =
|
|
33923
|
+
const globalDir = join21(homeDir, ".assistants", "commands");
|
|
33807
33924
|
await this.loadFromDirectory(globalDir, "global");
|
|
33808
|
-
const projectDir =
|
|
33925
|
+
const projectDir = join21(this.cwd, ".assistants", "commands");
|
|
33809
33926
|
await this.loadFromDirectory(projectDir, "project");
|
|
33810
33927
|
}
|
|
33811
33928
|
async loadFromDirectory(dir, source, prefix = "") {
|
|
33812
|
-
if (!
|
|
33929
|
+
if (!existsSync15(dir))
|
|
33813
33930
|
return;
|
|
33814
|
-
const entries =
|
|
33931
|
+
const entries = readdirSync5(dir);
|
|
33815
33932
|
for (const entry of entries) {
|
|
33816
|
-
const fullPath =
|
|
33933
|
+
const fullPath = join21(dir, entry);
|
|
33817
33934
|
const stat4 = statSync3(fullPath);
|
|
33818
33935
|
if (stat4.isDirectory()) {
|
|
33819
33936
|
const newPrefix = prefix ? `${prefix}:${entry}` : entry;
|
|
@@ -34179,7 +34296,7 @@ function formatAbsoluteTime(timestamp) {
|
|
|
34179
34296
|
return new Date(timestamp).toLocaleString();
|
|
34180
34297
|
}
|
|
34181
34298
|
// packages/core/src/jobs/job-store.ts
|
|
34182
|
-
function
|
|
34299
|
+
function getDb5() {
|
|
34183
34300
|
return getDatabase();
|
|
34184
34301
|
}
|
|
34185
34302
|
function jobToRow(job) {
|
|
@@ -34221,12 +34338,12 @@ function rowToJob(row) {
|
|
|
34221
34338
|
}
|
|
34222
34339
|
async function saveJob(job) {
|
|
34223
34340
|
const params = jobToRow(job);
|
|
34224
|
-
|
|
34341
|
+
getDb5().prepare(`INSERT OR REPLACE INTO jobs (id, session_id, connector_name, action, status, input, output, error, timeout_ms, created_at, started_at, completed_at)
|
|
34225
34342
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(...params);
|
|
34226
34343
|
}
|
|
34227
34344
|
async function readJob(id) {
|
|
34228
34345
|
try {
|
|
34229
|
-
const row =
|
|
34346
|
+
const row = getDb5().query("SELECT * FROM jobs WHERE id = ?").get(id);
|
|
34230
34347
|
if (!row)
|
|
34231
34348
|
return null;
|
|
34232
34349
|
return rowToJob(row);
|
|
@@ -34236,7 +34353,7 @@ async function readJob(id) {
|
|
|
34236
34353
|
}
|
|
34237
34354
|
async function deleteJob(id) {
|
|
34238
34355
|
try {
|
|
34239
|
-
const result =
|
|
34356
|
+
const result = getDb5().prepare("DELETE FROM jobs WHERE id = ?").run(id);
|
|
34240
34357
|
return result.changes > 0;
|
|
34241
34358
|
} catch {
|
|
34242
34359
|
return false;
|
|
@@ -34244,7 +34361,7 @@ async function deleteJob(id) {
|
|
|
34244
34361
|
}
|
|
34245
34362
|
async function listJobs() {
|
|
34246
34363
|
try {
|
|
34247
|
-
const rows =
|
|
34364
|
+
const rows = getDb5().query("SELECT * FROM jobs ORDER BY created_at DESC").all();
|
|
34248
34365
|
return rows.map(rowToJob);
|
|
34249
34366
|
} catch {
|
|
34250
34367
|
return [];
|
|
@@ -34252,7 +34369,7 @@ async function listJobs() {
|
|
|
34252
34369
|
}
|
|
34253
34370
|
async function listJobsForSession(sessionId) {
|
|
34254
34371
|
try {
|
|
34255
|
-
const rows =
|
|
34372
|
+
const rows = getDb5().query("SELECT * FROM jobs WHERE session_id = ? ORDER BY created_at DESC").all(sessionId);
|
|
34256
34373
|
return rows.map(rowToJob);
|
|
34257
34374
|
} catch {
|
|
34258
34375
|
return [];
|
|
@@ -34260,7 +34377,7 @@ async function listJobsForSession(sessionId) {
|
|
|
34260
34377
|
}
|
|
34261
34378
|
async function listJobsByStatus(status) {
|
|
34262
34379
|
try {
|
|
34263
|
-
const rows =
|
|
34380
|
+
const rows = getDb5().query("SELECT * FROM jobs WHERE status = ? ORDER BY created_at DESC").all(status);
|
|
34264
34381
|
return rows.map(rowToJob);
|
|
34265
34382
|
} catch {
|
|
34266
34383
|
return [];
|
|
@@ -34879,7 +34996,7 @@ var init_types3 = __esm(() => {
|
|
|
34879
34996
|
});
|
|
34880
34997
|
|
|
34881
34998
|
// packages/core/src/tasks/store.ts
|
|
34882
|
-
function
|
|
34999
|
+
function getDb6() {
|
|
34883
35000
|
return getDatabase();
|
|
34884
35001
|
}
|
|
34885
35002
|
function rowToTask(row) {
|
|
@@ -34943,7 +35060,7 @@ async function loadTaskStore(cwd) {
|
|
|
34943
35060
|
}
|
|
34944
35061
|
async function saveTaskStore(_cwd, _data) {}
|
|
34945
35062
|
async function getTasks(cwd) {
|
|
34946
|
-
const rows =
|
|
35063
|
+
const rows = getDb6().query("SELECT * FROM tasks WHERE project_path = ? ORDER BY created_at").all(cwd);
|
|
34947
35064
|
const tasks = rows.map(rowToTask);
|
|
34948
35065
|
const knownIds = new Set(tasks.map((t) => t.id));
|
|
34949
35066
|
for (const task of tasks) {
|
|
@@ -34959,7 +35076,7 @@ async function getTasks(cwd) {
|
|
|
34959
35076
|
return tasks;
|
|
34960
35077
|
}
|
|
34961
35078
|
async function getTask(cwd, id) {
|
|
34962
|
-
const row =
|
|
35079
|
+
const row = getDb6().query("SELECT * FROM tasks WHERE project_path = ? AND id = ?").get(cwd, id);
|
|
34963
35080
|
return row ? rowToTask(row) : null;
|
|
34964
35081
|
}
|
|
34965
35082
|
async function resolveTaskId(cwd, idOrPrefix, filter) {
|
|
@@ -34973,7 +35090,7 @@ async function resolveTaskId(cwd, idOrPrefix, filter) {
|
|
|
34973
35090
|
return { task: matches.length === 1 ? matches[0] : null, matches };
|
|
34974
35091
|
}
|
|
34975
35092
|
async function addTask(cwd, options, priority = "normal", projectId) {
|
|
34976
|
-
const d =
|
|
35093
|
+
const d = getDb6();
|
|
34977
35094
|
return d.transaction(() => {
|
|
34978
35095
|
const now2 = Date.now();
|
|
34979
35096
|
const opts = typeof options === "string" ? { description: options, priority, projectId } : options;
|
|
@@ -35042,7 +35159,7 @@ async function addTask(cwd, options, priority = "normal", projectId) {
|
|
|
35042
35159
|
});
|
|
35043
35160
|
}
|
|
35044
35161
|
async function updateTask(cwd, id, updates) {
|
|
35045
|
-
const d =
|
|
35162
|
+
const d = getDb6();
|
|
35046
35163
|
const row = d.query("SELECT * FROM tasks WHERE project_path = ? AND id = ?").get(cwd, id);
|
|
35047
35164
|
if (!row)
|
|
35048
35165
|
return null;
|
|
@@ -35080,7 +35197,7 @@ async function updateTask(cwd, id, updates) {
|
|
|
35080
35197
|
return updated ? rowToTask(updated) : null;
|
|
35081
35198
|
}
|
|
35082
35199
|
async function deleteTask(cwd, id) {
|
|
35083
|
-
const d =
|
|
35200
|
+
const d = getDb6();
|
|
35084
35201
|
return d.transaction(() => {
|
|
35085
35202
|
const row = d.query("SELECT * FROM tasks WHERE project_path = ? AND id = ?").get(cwd, id);
|
|
35086
35203
|
if (!row)
|
|
@@ -35107,7 +35224,7 @@ async function deleteTask(cwd, id) {
|
|
|
35107
35224
|
});
|
|
35108
35225
|
}
|
|
35109
35226
|
async function clearPendingTasks(cwd) {
|
|
35110
|
-
const d =
|
|
35227
|
+
const d = getDb6();
|
|
35111
35228
|
return d.transaction(() => {
|
|
35112
35229
|
const pending = d.query("SELECT id FROM tasks WHERE project_path = ? AND status = 'pending'").all(cwd);
|
|
35113
35230
|
if (pending.length === 0)
|
|
@@ -35132,7 +35249,7 @@ async function clearPendingTasks(cwd) {
|
|
|
35132
35249
|
});
|
|
35133
35250
|
}
|
|
35134
35251
|
async function clearCompletedTasks(cwd) {
|
|
35135
|
-
const d =
|
|
35252
|
+
const d = getDb6();
|
|
35136
35253
|
return d.transaction(() => {
|
|
35137
35254
|
const completed = d.query("SELECT id FROM tasks WHERE project_path = ? AND (status = 'completed' OR status = 'failed')").all(cwd);
|
|
35138
35255
|
if (completed.length === 0)
|
|
@@ -35178,18 +35295,18 @@ async function getNextTask(cwd) {
|
|
|
35178
35295
|
return pending[0];
|
|
35179
35296
|
}
|
|
35180
35297
|
async function isPaused(cwd) {
|
|
35181
|
-
const row =
|
|
35298
|
+
const row = getDb6().query("SELECT paused FROM task_queue_settings WHERE project_path = ?").get(cwd);
|
|
35182
35299
|
return row ? row.paused === 1 : false;
|
|
35183
35300
|
}
|
|
35184
35301
|
async function setPaused(cwd, paused) {
|
|
35185
|
-
|
|
35302
|
+
getDb6().prepare("INSERT OR REPLACE INTO task_queue_settings (project_path, paused, auto_run) VALUES (?, ?, COALESCE((SELECT auto_run FROM task_queue_settings WHERE project_path = ?), 1))").run(cwd, paused ? 1 : 0, cwd);
|
|
35186
35303
|
}
|
|
35187
35304
|
async function isAutoRun(cwd) {
|
|
35188
|
-
const row =
|
|
35305
|
+
const row = getDb6().query("SELECT auto_run FROM task_queue_settings WHERE project_path = ?").get(cwd);
|
|
35189
35306
|
return row ? row.auto_run === 1 : true;
|
|
35190
35307
|
}
|
|
35191
35308
|
async function setAutoRun(cwd, autoRun) {
|
|
35192
|
-
|
|
35309
|
+
getDb6().prepare("INSERT OR REPLACE INTO task_queue_settings (project_path, paused, auto_run) VALUES (?, COALESCE((SELECT paused FROM task_queue_settings WHERE project_path = ?), 0), ?)").run(cwd, cwd, autoRun ? 1 : 0);
|
|
35193
35310
|
}
|
|
35194
35311
|
async function startTask(cwd, id) {
|
|
35195
35312
|
return updateTask(cwd, id, {
|
|
@@ -35212,7 +35329,7 @@ async function failTask(cwd, id, error2) {
|
|
|
35212
35329
|
});
|
|
35213
35330
|
}
|
|
35214
35331
|
async function getTaskCounts(cwd) {
|
|
35215
|
-
const rows =
|
|
35332
|
+
const rows = getDb6().query("SELECT status, COUNT(*) as cnt FROM tasks WHERE project_path = ? GROUP BY status").all(cwd);
|
|
35216
35333
|
const counts = {
|
|
35217
35334
|
pending: 0,
|
|
35218
35335
|
in_progress: 0,
|
|
@@ -35225,16 +35342,16 @@ async function getTaskCounts(cwd) {
|
|
|
35225
35342
|
return counts;
|
|
35226
35343
|
}
|
|
35227
35344
|
async function getRecurringTasks(cwd) {
|
|
35228
|
-
const rows =
|
|
35345
|
+
const rows = getDb6().query("SELECT * FROM tasks WHERE project_path = ? AND is_recurring_template = 1").all(cwd);
|
|
35229
35346
|
return rows.map(rowToTask);
|
|
35230
35347
|
}
|
|
35231
35348
|
async function getDueRecurringTasks(cwd) {
|
|
35232
35349
|
const now2 = Date.now();
|
|
35233
|
-
const rows =
|
|
35350
|
+
const rows = getDb6().query("SELECT * FROM tasks WHERE project_path = ? AND is_recurring_template = 1 AND next_run_at IS NOT NULL AND next_run_at <= ?").all(cwd, now2);
|
|
35234
35351
|
return rows.map(rowToTask);
|
|
35235
35352
|
}
|
|
35236
35353
|
async function createRecurringInstance(cwd, templateId) {
|
|
35237
|
-
const d =
|
|
35354
|
+
const d = getDb6();
|
|
35238
35355
|
return d.transaction(() => {
|
|
35239
35356
|
const row = d.query("SELECT * FROM tasks WHERE project_path = ? AND id = ? AND is_recurring_template = 1").get(cwd, templateId);
|
|
35240
35357
|
if (!row || !row.recurrence)
|
|
@@ -35281,7 +35398,7 @@ async function processDueRecurringTasks(cwd) {
|
|
|
35281
35398
|
return createdInstances;
|
|
35282
35399
|
}
|
|
35283
35400
|
async function cancelRecurringTask(cwd, id) {
|
|
35284
|
-
const d =
|
|
35401
|
+
const d = getDb6();
|
|
35285
35402
|
return d.transaction(() => {
|
|
35286
35403
|
const row = d.query("SELECT * FROM tasks WHERE project_path = ? AND id = ? AND is_recurring_template = 1").get(cwd, id);
|
|
35287
35404
|
if (!row)
|
|
@@ -35734,8 +35851,8 @@ var init_evaluator = __esm(() => {
|
|
|
35734
35851
|
});
|
|
35735
35852
|
|
|
35736
35853
|
// packages/core/src/guardrails/store.ts
|
|
35737
|
-
import { readFileSync as
|
|
35738
|
-
import { join as
|
|
35854
|
+
import { readFileSync as readFileSync9, writeFileSync as writeFileSync8, existsSync as existsSync16, mkdirSync as mkdirSync9 } from "fs";
|
|
35855
|
+
import { join as join22, dirname as dirname11 } from "path";
|
|
35739
35856
|
import { createHash as createHash3 } from "crypto";
|
|
35740
35857
|
function generatePolicyId(name, scope) {
|
|
35741
35858
|
const hash = createHash3("sha256").update(`${name}-${scope}-${Date.now()}`).digest("hex").slice(0, 8);
|
|
@@ -35759,20 +35876,20 @@ class GuardrailsStore {
|
|
|
35759
35876
|
getFilePath(location) {
|
|
35760
35877
|
switch (location) {
|
|
35761
35878
|
case "user":
|
|
35762
|
-
return
|
|
35879
|
+
return join22(this.baseDir || getConfigDir(), "guardrails.json");
|
|
35763
35880
|
case "project":
|
|
35764
|
-
return
|
|
35881
|
+
return join22(this.cwd, ".assistants", "guardrails.json");
|
|
35765
35882
|
case "local":
|
|
35766
|
-
return
|
|
35883
|
+
return join22(this.cwd, ".assistants", "guardrails.local.json");
|
|
35767
35884
|
}
|
|
35768
35885
|
}
|
|
35769
35886
|
loadFrom(location) {
|
|
35770
35887
|
const filePath = this.getFilePath(location);
|
|
35771
|
-
if (!
|
|
35888
|
+
if (!existsSync16(filePath)) {
|
|
35772
35889
|
return null;
|
|
35773
35890
|
}
|
|
35774
35891
|
try {
|
|
35775
|
-
const content =
|
|
35892
|
+
const content = readFileSync9(filePath, "utf-8");
|
|
35776
35893
|
const data = JSON.parse(content);
|
|
35777
35894
|
const config = data.guardrails || data;
|
|
35778
35895
|
ensurePolicyIds(config);
|
|
@@ -35783,12 +35900,12 @@ class GuardrailsStore {
|
|
|
35783
35900
|
}
|
|
35784
35901
|
save(location, config) {
|
|
35785
35902
|
const filePath = this.getFilePath(location);
|
|
35786
|
-
const dir =
|
|
35787
|
-
if (!
|
|
35788
|
-
|
|
35903
|
+
const dir = dirname11(filePath);
|
|
35904
|
+
if (!existsSync16(dir)) {
|
|
35905
|
+
mkdirSync9(dir, { recursive: true });
|
|
35789
35906
|
}
|
|
35790
35907
|
ensurePolicyIds(config);
|
|
35791
|
-
|
|
35908
|
+
writeFileSync8(filePath, JSON.stringify({ guardrails: config }, null, 2), "utf-8");
|
|
35792
35909
|
}
|
|
35793
35910
|
loadAll() {
|
|
35794
35911
|
const userConfig = this.loadFrom("user");
|
|
@@ -65188,8 +65305,8 @@ var require_core3 = __commonJS((exports) => {
|
|
|
65188
65305
|
function many1(p) {
|
|
65189
65306
|
return ab(p, many(p), (head, tail) => [head, ...tail]);
|
|
65190
65307
|
}
|
|
65191
|
-
function ab(pa, pb,
|
|
65192
|
-
return (data, i) => mapOuter(pa(data, i), (ma) => mapInner(pb(data, ma.position), (vb, j) =>
|
|
65308
|
+
function ab(pa, pb, join23) {
|
|
65309
|
+
return (data, i) => mapOuter(pa(data, i), (ma) => mapInner(pb(data, ma.position), (vb, j) => join23(ma.value, vb, data, i, j)));
|
|
65193
65310
|
}
|
|
65194
65311
|
function left(pa, pb) {
|
|
65195
65312
|
return ab(pa, pb, (va) => va);
|
|
@@ -65197,8 +65314,8 @@ var require_core3 = __commonJS((exports) => {
|
|
|
65197
65314
|
function right(pa, pb) {
|
|
65198
65315
|
return ab(pa, pb, (va, vb) => vb);
|
|
65199
65316
|
}
|
|
65200
|
-
function abc(pa, pb, pc,
|
|
65201
|
-
return (data, i) => mapOuter(pa(data, i), (ma) => mapOuter(pb(data, ma.position), (mb) => mapInner(pc(data, mb.position), (vc, j) =>
|
|
65317
|
+
function abc(pa, pb, pc, join23) {
|
|
65318
|
+
return (data, i) => mapOuter(pa(data, i), (ma) => mapOuter(pb(data, ma.position), (mb) => mapInner(pc(data, mb.position), (vc, j) => join23(ma.value, mb.value, vc, data, i, j))));
|
|
65202
65319
|
}
|
|
65203
65320
|
function middle(pa, pb, pc) {
|
|
65204
65321
|
return abc(pa, pb, pc, (ra, rb) => rb);
|
|
@@ -73911,82 +74028,89 @@ var init_email_parser = __esm(() => {
|
|
|
73911
74028
|
import_mailparser = __toESM(require_mailparser(), 1);
|
|
73912
74029
|
});
|
|
73913
74030
|
|
|
73914
|
-
// packages/core/src/utils/atomic-write.ts
|
|
73915
|
-
import { writeFileSync as writeFileSync10, renameSync, unlinkSync as unlinkSync4 } from "fs";
|
|
73916
|
-
function atomicWriteFileSync(path2, data) {
|
|
73917
|
-
const tmpPath = `${path2}.${process.pid}.tmp`;
|
|
73918
|
-
try {
|
|
73919
|
-
writeFileSync10(tmpPath, data);
|
|
73920
|
-
renameSync(tmpPath, path2);
|
|
73921
|
-
} catch (error2) {
|
|
73922
|
-
try {
|
|
73923
|
-
unlinkSync4(tmpPath);
|
|
73924
|
-
} catch {}
|
|
73925
|
-
throw error2;
|
|
73926
|
-
}
|
|
73927
|
-
}
|
|
73928
|
-
var init_atomic_write = () => {};
|
|
73929
|
-
|
|
73930
74031
|
// packages/core/src/workspace/shared.ts
|
|
73931
|
-
import { join as
|
|
74032
|
+
import { join as join23 } from "path";
|
|
73932
74033
|
import {
|
|
73933
|
-
existsSync as
|
|
73934
|
-
mkdirSync as
|
|
73935
|
-
readFileSync as readFileSync11,
|
|
73936
|
-
readdirSync as readdirSync8,
|
|
74034
|
+
existsSync as existsSync17,
|
|
74035
|
+
mkdirSync as mkdirSync10,
|
|
73937
74036
|
rmSync,
|
|
73938
|
-
renameSync
|
|
74037
|
+
renameSync,
|
|
74038
|
+
readdirSync as readdirSync6
|
|
73939
74039
|
} from "fs";
|
|
74040
|
+
function getDb7() {
|
|
74041
|
+
return getDatabase();
|
|
74042
|
+
}
|
|
74043
|
+
function rowToWorkspace(row) {
|
|
74044
|
+
let participants = [];
|
|
74045
|
+
try {
|
|
74046
|
+
participants = JSON.parse(row.participants);
|
|
74047
|
+
} catch {
|
|
74048
|
+
participants = [];
|
|
74049
|
+
}
|
|
74050
|
+
return {
|
|
74051
|
+
id: row.id,
|
|
74052
|
+
name: row.name,
|
|
74053
|
+
description: row.description || undefined,
|
|
74054
|
+
createdAt: new Date(row.created_at).getTime(),
|
|
74055
|
+
updatedAt: new Date(row.updated_at).getTime(),
|
|
74056
|
+
createdBy: row.creator_id,
|
|
74057
|
+
participants,
|
|
74058
|
+
status: row.status
|
|
74059
|
+
};
|
|
74060
|
+
}
|
|
73940
74061
|
|
|
73941
74062
|
class SharedWorkspaceManager {
|
|
73942
74063
|
basePath;
|
|
73943
|
-
|
|
73944
|
-
|
|
74064
|
+
db;
|
|
74065
|
+
constructor(basePath, db) {
|
|
74066
|
+
this.basePath = basePath || join23(getConfigDir(), "workspaces");
|
|
74067
|
+
this.db = db || getDb7();
|
|
73945
74068
|
this.ensureDir();
|
|
73946
74069
|
this.migrateAgentsToAssistants();
|
|
73947
74070
|
}
|
|
73948
74071
|
ensureDir() {
|
|
73949
|
-
if (!
|
|
73950
|
-
|
|
74072
|
+
if (!existsSync17(this.basePath)) {
|
|
74073
|
+
mkdirSync10(this.basePath, { recursive: true });
|
|
73951
74074
|
}
|
|
73952
74075
|
}
|
|
73953
74076
|
migrateAgentsToAssistants() {
|
|
73954
74077
|
try {
|
|
73955
|
-
const dirs =
|
|
74078
|
+
const dirs = readdirSync6(this.basePath, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => d.name);
|
|
73956
74079
|
for (const dir of dirs) {
|
|
73957
|
-
const wsPath =
|
|
73958
|
-
const oldAgentsDir =
|
|
73959
|
-
const newAssistantsDir =
|
|
73960
|
-
if (
|
|
73961
|
-
|
|
74080
|
+
const wsPath = join23(this.basePath, dir);
|
|
74081
|
+
const oldAgentsDir = join23(wsPath, "agents");
|
|
74082
|
+
const newAssistantsDir = join23(wsPath, "assistants");
|
|
74083
|
+
if (existsSync17(oldAgentsDir) && !existsSync17(newAssistantsDir)) {
|
|
74084
|
+
renameSync(oldAgentsDir, newAssistantsDir);
|
|
73962
74085
|
}
|
|
73963
74086
|
}
|
|
73964
74087
|
} catch {}
|
|
73965
74088
|
}
|
|
73966
74089
|
getWorkspacePath(id) {
|
|
73967
|
-
return
|
|
73968
|
-
}
|
|
73969
|
-
getMetadataPath(id) {
|
|
73970
|
-
return join25(this.getWorkspacePath(id), "workspace.json");
|
|
74090
|
+
return join23(this.basePath, id);
|
|
73971
74091
|
}
|
|
73972
74092
|
create(name, createdBy, participants, description) {
|
|
73973
74093
|
const id = `ws_${generateId().slice(0, 8)}`;
|
|
74094
|
+
const now2 = Date.now();
|
|
74095
|
+
const nowIso = new Date(now2).toISOString();
|
|
74096
|
+
const allParticipants = [...new Set([createdBy, ...participants])];
|
|
73974
74097
|
const workspace = {
|
|
73975
74098
|
id,
|
|
73976
74099
|
name,
|
|
73977
74100
|
description,
|
|
73978
|
-
createdAt:
|
|
73979
|
-
updatedAt:
|
|
74101
|
+
createdAt: now2,
|
|
74102
|
+
updatedAt: now2,
|
|
73980
74103
|
createdBy,
|
|
73981
|
-
participants:
|
|
74104
|
+
participants: allParticipants,
|
|
73982
74105
|
status: "active"
|
|
73983
74106
|
};
|
|
73984
74107
|
const wsPath = this.getWorkspacePath(id);
|
|
73985
|
-
|
|
73986
|
-
for (const assistantId of
|
|
73987
|
-
|
|
74108
|
+
mkdirSync10(join23(wsPath, "shared"), { recursive: true });
|
|
74109
|
+
for (const assistantId of allParticipants) {
|
|
74110
|
+
mkdirSync10(join23(wsPath, "assistants", assistantId), { recursive: true });
|
|
73988
74111
|
}
|
|
73989
|
-
|
|
74112
|
+
this.db.prepare(`INSERT INTO workspaces (id, name, description, creator_id, creator_name, status, participants, created_at, updated_at)
|
|
74113
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(id, name, description || null, createdBy, createdBy, "active", JSON.stringify(allParticipants), nowIso, nowIso);
|
|
73990
74114
|
return workspace;
|
|
73991
74115
|
}
|
|
73992
74116
|
join(workspaceId, assistantId) {
|
|
@@ -73997,49 +74121,32 @@ class SharedWorkspaceManager {
|
|
|
73997
74121
|
if (!workspace.participants.includes(assistantId)) {
|
|
73998
74122
|
workspace.participants.push(assistantId);
|
|
73999
74123
|
workspace.updatedAt = Date.now();
|
|
74000
|
-
|
|
74124
|
+
this.db.prepare("UPDATE workspaces SET participants = ?, updated_at = ? WHERE id = ?").run(JSON.stringify(workspace.participants), new Date(workspace.updatedAt).toISOString(), workspaceId);
|
|
74001
74125
|
}
|
|
74002
|
-
const assistantDir =
|
|
74003
|
-
if (!
|
|
74004
|
-
|
|
74126
|
+
const assistantDir = join23(this.getWorkspacePath(workspaceId), "assistants", assistantId);
|
|
74127
|
+
if (!existsSync17(assistantDir)) {
|
|
74128
|
+
mkdirSync10(assistantDir, { recursive: true });
|
|
74005
74129
|
}
|
|
74006
74130
|
}
|
|
74007
74131
|
get(workspaceId) {
|
|
74008
|
-
|
|
74009
|
-
|
|
74010
|
-
if (!existsSync19(metadataPath))
|
|
74011
|
-
return null;
|
|
74012
|
-
return JSON.parse(readFileSync11(metadataPath, "utf-8"));
|
|
74013
|
-
} catch {
|
|
74132
|
+
const row = this.db.query("SELECT * FROM workspaces WHERE id = ?").get(workspaceId);
|
|
74133
|
+
if (!row)
|
|
74014
74134
|
return null;
|
|
74015
|
-
|
|
74135
|
+
return rowToWorkspace(row);
|
|
74016
74136
|
}
|
|
74017
74137
|
getPath(workspaceId) {
|
|
74018
74138
|
return this.getWorkspacePath(workspaceId);
|
|
74019
74139
|
}
|
|
74020
74140
|
getSharedPath(workspaceId) {
|
|
74021
|
-
return
|
|
74141
|
+
return join23(this.getWorkspacePath(workspaceId), "shared");
|
|
74022
74142
|
}
|
|
74023
74143
|
getAssistantPath(workspaceId, assistantId) {
|
|
74024
|
-
return
|
|
74144
|
+
return join23(this.getWorkspacePath(workspaceId), "assistants", assistantId);
|
|
74025
74145
|
}
|
|
74026
74146
|
list(includeArchived = false) {
|
|
74027
|
-
|
|
74028
|
-
|
|
74029
|
-
|
|
74030
|
-
const workspaces = [];
|
|
74031
|
-
for (const dir of dirs) {
|
|
74032
|
-
const workspace = this.get(dir);
|
|
74033
|
-
if (workspace) {
|
|
74034
|
-
if (includeArchived || workspace.status === "active") {
|
|
74035
|
-
workspaces.push(workspace);
|
|
74036
|
-
}
|
|
74037
|
-
}
|
|
74038
|
-
}
|
|
74039
|
-
return workspaces.sort((a, b) => b.updatedAt - a.updatedAt);
|
|
74040
|
-
} catch {
|
|
74041
|
-
return [];
|
|
74042
|
-
}
|
|
74147
|
+
const query = includeArchived ? "SELECT * FROM workspaces ORDER BY updated_at DESC" : "SELECT * FROM workspaces WHERE status = 'active' ORDER BY updated_at DESC";
|
|
74148
|
+
const rows = this.db.query(query).all();
|
|
74149
|
+
return rows.map(rowToWorkspace);
|
|
74043
74150
|
}
|
|
74044
74151
|
listForAgent(assistantId) {
|
|
74045
74152
|
return this.list().filter((ws) => ws.participants.includes(assistantId));
|
|
@@ -74047,44 +74154,42 @@ class SharedWorkspaceManager {
|
|
|
74047
74154
|
archive(workspaceId) {
|
|
74048
74155
|
const workspace = this.get(workspaceId);
|
|
74049
74156
|
if (workspace) {
|
|
74050
|
-
|
|
74051
|
-
workspace.updatedAt = Date.now();
|
|
74052
|
-
atomicWriteFileSync(this.getMetadataPath(workspaceId), JSON.stringify(workspace, null, 2));
|
|
74157
|
+
this.db.prepare("UPDATE workspaces SET status = 'archived', updated_at = ? WHERE id = ?").run(new Date().toISOString(), workspaceId);
|
|
74053
74158
|
}
|
|
74054
74159
|
}
|
|
74055
74160
|
delete(workspaceId) {
|
|
74161
|
+
this.db.prepare("DELETE FROM workspaces WHERE id = ?").run(workspaceId);
|
|
74056
74162
|
const wsPath = this.getWorkspacePath(workspaceId);
|
|
74057
|
-
if (
|
|
74163
|
+
if (existsSync17(wsPath)) {
|
|
74058
74164
|
rmSync(wsPath, { recursive: true, force: true });
|
|
74059
74165
|
}
|
|
74060
74166
|
}
|
|
74061
74167
|
}
|
|
74062
74168
|
var init_shared2 = __esm(async () => {
|
|
74063
74169
|
init_src2();
|
|
74064
|
-
|
|
74065
|
-
|
|
74170
|
+
await __promiseAll([
|
|
74171
|
+
init_config(),
|
|
74172
|
+
init_database()
|
|
74173
|
+
]);
|
|
74066
74174
|
});
|
|
74067
74175
|
|
|
74068
74176
|
// packages/core/src/workspace/active.ts
|
|
74069
|
-
import { join as
|
|
74070
|
-
import { existsSync as
|
|
74177
|
+
import { join as join24 } from "path";
|
|
74178
|
+
import { existsSync as existsSync18, mkdirSync as mkdirSync11 } from "fs";
|
|
74179
|
+
function getDb8() {
|
|
74180
|
+
return getDatabase();
|
|
74181
|
+
}
|
|
74071
74182
|
function isValidId2(id) {
|
|
74072
74183
|
return typeof id === "string" && id.length > 0 && SAFE_ID_PATTERN3.test(id);
|
|
74073
74184
|
}
|
|
74074
74185
|
function getWorkspaceRoot(baseDir) {
|
|
74075
|
-
return
|
|
74186
|
+
return join24(baseDir ?? getConfigDir(), "workspaces");
|
|
74076
74187
|
}
|
|
74077
|
-
function
|
|
74078
|
-
return join26(getWorkspaceRoot(baseDir), "active.json");
|
|
74079
|
-
}
|
|
74080
|
-
function getActiveWorkspaceId(baseDir) {
|
|
74188
|
+
function getActiveWorkspaceId(baseDir, db) {
|
|
74081
74189
|
try {
|
|
74082
|
-
const
|
|
74083
|
-
|
|
74084
|
-
|
|
74085
|
-
const raw = readFileSync12(activePath, "utf-8");
|
|
74086
|
-
const data = JSON.parse(raw);
|
|
74087
|
-
const id = data.id ?? null;
|
|
74190
|
+
const conn = db || getDb8();
|
|
74191
|
+
const row = conn.query("SELECT workspace_id FROM workspaces_active WHERE assistant_id = '__global__'").get();
|
|
74192
|
+
const id = row?.workspace_id ?? null;
|
|
74088
74193
|
if (id && !isValidId2(id)) {
|
|
74089
74194
|
return null;
|
|
74090
74195
|
}
|
|
@@ -74093,29 +74198,27 @@ function getActiveWorkspaceId(baseDir) {
|
|
|
74093
74198
|
return null;
|
|
74094
74199
|
}
|
|
74095
74200
|
}
|
|
74096
|
-
function setActiveWorkspaceId(id, baseDir) {
|
|
74201
|
+
function setActiveWorkspaceId(id, baseDir, db) {
|
|
74097
74202
|
if (id && !isValidId2(id)) {
|
|
74098
74203
|
throw new Error(`Invalid workspace id: "${id}"`);
|
|
74099
74204
|
}
|
|
74100
|
-
const
|
|
74101
|
-
if (
|
|
74102
|
-
|
|
74205
|
+
const conn = db || getDb8();
|
|
74206
|
+
if (id) {
|
|
74207
|
+
conn.prepare("INSERT OR REPLACE INTO workspaces_active (assistant_id, workspace_id) VALUES ('__global__', ?)").run(id);
|
|
74208
|
+
} else {
|
|
74209
|
+
conn.prepare("DELETE FROM workspaces_active WHERE assistant_id = '__global__'").run();
|
|
74103
74210
|
}
|
|
74104
|
-
const activePath = getActiveWorkspacePath(baseDir);
|
|
74105
|
-
try {
|
|
74106
|
-
writeFileSync12(activePath, JSON.stringify({ id: id ?? null }, null, 2), "utf-8");
|
|
74107
|
-
} catch {}
|
|
74108
74211
|
}
|
|
74109
74212
|
function getWorkspaceDataDir(workspaceId, baseDir) {
|
|
74110
74213
|
if (!isValidId2(workspaceId)) {
|
|
74111
74214
|
throw new Error(`Invalid workspace id: "${workspaceId}"`);
|
|
74112
74215
|
}
|
|
74113
|
-
return
|
|
74216
|
+
return join24(getWorkspaceRoot(baseDir), workspaceId, ".assistants");
|
|
74114
74217
|
}
|
|
74115
74218
|
function ensureWorkspaceDataDir(workspaceId, baseDir) {
|
|
74116
74219
|
const dir = getWorkspaceDataDir(workspaceId, baseDir);
|
|
74117
|
-
if (!
|
|
74118
|
-
|
|
74220
|
+
if (!existsSync18(dir)) {
|
|
74221
|
+
mkdirSync11(dir, { recursive: true });
|
|
74119
74222
|
}
|
|
74120
74223
|
initAssistantsDir(dir);
|
|
74121
74224
|
return dir;
|
|
@@ -74131,7 +74234,8 @@ var SAFE_ID_PATTERN3;
|
|
|
74131
74234
|
var init_active = __esm(async () => {
|
|
74132
74235
|
await __promiseAll([
|
|
74133
74236
|
init_config(),
|
|
74134
|
-
init_logger2()
|
|
74237
|
+
init_logger2(),
|
|
74238
|
+
init_database()
|
|
74135
74239
|
]);
|
|
74136
74240
|
SAFE_ID_PATTERN3 = /^[a-zA-Z0-9_-]+$/;
|
|
74137
74241
|
});
|
|
@@ -74195,9 +74299,9 @@ var init_defaults2 = __esm(() => {
|
|
|
74195
74299
|
});
|
|
74196
74300
|
|
|
74197
74301
|
// packages/core/src/budget/tracker.ts
|
|
74198
|
-
|
|
74199
|
-
|
|
74200
|
-
|
|
74302
|
+
function getDb9() {
|
|
74303
|
+
return getDatabase();
|
|
74304
|
+
}
|
|
74201
74305
|
function createEmptyUsage() {
|
|
74202
74306
|
const now2 = new Date().toISOString();
|
|
74203
74307
|
return {
|
|
@@ -74220,85 +74324,92 @@ class BudgetTracker {
|
|
|
74220
74324
|
projectUsages = new Map;
|
|
74221
74325
|
sessionId;
|
|
74222
74326
|
activeProjectId = null;
|
|
74223
|
-
|
|
74327
|
+
db = null;
|
|
74328
|
+
constructor(sessionId, config, db) {
|
|
74224
74329
|
this.sessionId = sessionId;
|
|
74225
74330
|
this.config = { ...DEFAULT_BUDGET_CONFIG, ...config };
|
|
74226
74331
|
this.sessionUsage = createEmptyUsage();
|
|
74227
74332
|
this.swarmUsage = createEmptyUsage();
|
|
74228
74333
|
if (this.config.persist) {
|
|
74334
|
+
try {
|
|
74335
|
+
this.db = db || getDb9();
|
|
74336
|
+
} catch {}
|
|
74337
|
+
}
|
|
74338
|
+
if (this.config.persist && this.db) {
|
|
74229
74339
|
this.loadState();
|
|
74230
74340
|
}
|
|
74231
74341
|
}
|
|
74232
|
-
getStatePath() {
|
|
74233
|
-
const envHome = process.env.HOME || process.env.USERPROFILE || homedir15();
|
|
74234
|
-
return join27(envHome, ".assistants", "budget", `${this.sessionId}.json`);
|
|
74235
|
-
}
|
|
74236
|
-
getProjectStatePath(projectId) {
|
|
74237
|
-
const envHome = process.env.HOME || process.env.USERPROFILE || homedir15();
|
|
74238
|
-
return join27(envHome, ".assistants", "budget", `project-${projectId}.json`);
|
|
74239
|
-
}
|
|
74240
74342
|
loadState() {
|
|
74343
|
+
if (!this.db)
|
|
74344
|
+
return;
|
|
74241
74345
|
try {
|
|
74242
|
-
const
|
|
74243
|
-
if (
|
|
74244
|
-
|
|
74245
|
-
|
|
74246
|
-
|
|
74247
|
-
|
|
74248
|
-
|
|
74249
|
-
|
|
74250
|
-
|
|
74251
|
-
|
|
74252
|
-
|
|
74346
|
+
const sessionRow = this.db.query("SELECT * FROM budget_usage WHERE scope = 'session' AND scope_id = ?").get(this.sessionId);
|
|
74347
|
+
if (sessionRow) {
|
|
74348
|
+
this.sessionUsage = {
|
|
74349
|
+
...this.sessionUsage,
|
|
74350
|
+
inputTokens: sessionRow.input_tokens,
|
|
74351
|
+
outputTokens: sessionRow.output_tokens,
|
|
74352
|
+
totalTokens: sessionRow.total_tokens,
|
|
74353
|
+
llmCalls: sessionRow.api_calls,
|
|
74354
|
+
toolCalls: sessionRow.tool_calls,
|
|
74355
|
+
lastUpdatedAt: sessionRow.updated_at
|
|
74356
|
+
};
|
|
74253
74357
|
}
|
|
74254
|
-
|
|
74255
|
-
|
|
74256
|
-
|
|
74257
|
-
|
|
74358
|
+
const swarmRow = this.db.query("SELECT * FROM budget_usage WHERE scope = 'swarm' AND scope_id = ?").get(this.sessionId);
|
|
74359
|
+
if (swarmRow) {
|
|
74360
|
+
this.swarmUsage = {
|
|
74361
|
+
...this.swarmUsage,
|
|
74362
|
+
inputTokens: swarmRow.input_tokens,
|
|
74363
|
+
outputTokens: swarmRow.output_tokens,
|
|
74364
|
+
totalTokens: swarmRow.total_tokens,
|
|
74365
|
+
llmCalls: swarmRow.api_calls,
|
|
74366
|
+
toolCalls: swarmRow.tool_calls,
|
|
74367
|
+
lastUpdatedAt: swarmRow.updated_at
|
|
74368
|
+
};
|
|
74369
|
+
}
|
|
74370
|
+
const assistantRows = this.db.query("SELECT * FROM budget_usage WHERE scope = 'assistant' AND scope_id LIKE ?").all(`${this.sessionId}:%`);
|
|
74371
|
+
for (const row of assistantRows) {
|
|
74372
|
+
const assistantId = row.scope_id.replace(`${this.sessionId}:`, "");
|
|
74373
|
+
this.assistantUsages.set(assistantId, {
|
|
74374
|
+
...createEmptyUsage(),
|
|
74375
|
+
inputTokens: row.input_tokens,
|
|
74376
|
+
outputTokens: row.output_tokens,
|
|
74377
|
+
totalTokens: row.total_tokens,
|
|
74378
|
+
llmCalls: row.api_calls,
|
|
74379
|
+
toolCalls: row.tool_calls,
|
|
74380
|
+
lastUpdatedAt: row.updated_at
|
|
74381
|
+
});
|
|
74382
|
+
}
|
|
74383
|
+
const projectRows = this.db.query("SELECT * FROM budget_usage WHERE scope = 'project'").all();
|
|
74384
|
+
for (const row of projectRows) {
|
|
74385
|
+
this.projectUsages.set(row.scope_id, {
|
|
74386
|
+
...createEmptyUsage(),
|
|
74387
|
+
inputTokens: row.input_tokens,
|
|
74388
|
+
outputTokens: row.output_tokens,
|
|
74389
|
+
totalTokens: row.total_tokens,
|
|
74390
|
+
llmCalls: row.api_calls,
|
|
74391
|
+
toolCalls: row.tool_calls,
|
|
74392
|
+
lastUpdatedAt: row.updated_at
|
|
74393
|
+
});
|
|
74258
74394
|
}
|
|
74259
74395
|
} catch {}
|
|
74260
74396
|
}
|
|
74261
|
-
|
|
74262
|
-
|
|
74263
|
-
const statePath = this.getProjectStatePath(projectId);
|
|
74264
|
-
if (!existsSync21(statePath))
|
|
74265
|
-
return createEmptyUsage();
|
|
74266
|
-
const data = JSON.parse(readFileSync13(statePath, "utf-8"));
|
|
74267
|
-
return data;
|
|
74268
|
-
} catch {
|
|
74269
|
-
return createEmptyUsage();
|
|
74270
|
-
}
|
|
74271
|
-
}
|
|
74272
|
-
saveProjectState(projectId, usage) {
|
|
74273
|
-
if (!this.config.persist)
|
|
74397
|
+
saveUsageRow(scope, scopeId, usage) {
|
|
74398
|
+
if (!this.db || !this.config.persist)
|
|
74274
74399
|
return;
|
|
74275
74400
|
try {
|
|
74276
|
-
|
|
74277
|
-
|
|
74278
|
-
if (!existsSync21(stateDir)) {
|
|
74279
|
-
mkdirSync14(stateDir, { recursive: true });
|
|
74280
|
-
}
|
|
74281
|
-
atomicWriteFileSync(statePath, JSON.stringify(usage, null, 2));
|
|
74401
|
+
this.db.prepare(`INSERT OR REPLACE INTO budget_usage (scope, scope_id, input_tokens, output_tokens, total_tokens, api_calls, tool_calls, estimated_cost_usd, updated_at)
|
|
74402
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(scope, scopeId, usage.inputTokens, usage.outputTokens, usage.totalTokens, usage.llmCalls, usage.toolCalls, 0, usage.lastUpdatedAt);
|
|
74282
74403
|
} catch {}
|
|
74283
74404
|
}
|
|
74284
74405
|
saveState() {
|
|
74285
|
-
if (!this.config.persist)
|
|
74406
|
+
if (!this.db || !this.config.persist)
|
|
74286
74407
|
return;
|
|
74287
|
-
|
|
74288
|
-
|
|
74289
|
-
|
|
74290
|
-
|
|
74291
|
-
|
|
74292
|
-
}
|
|
74293
|
-
const state = {
|
|
74294
|
-
version: PERSISTENCE_VERSION,
|
|
74295
|
-
session: this.sessionUsage,
|
|
74296
|
-
assistants: Object.fromEntries(this.assistantUsages),
|
|
74297
|
-
swarm: this.swarmUsage,
|
|
74298
|
-
projects: Object.fromEntries(this.projectUsages)
|
|
74299
|
-
};
|
|
74300
|
-
atomicWriteFileSync(statePath, JSON.stringify(state, null, 2));
|
|
74301
|
-
} catch {}
|
|
74408
|
+
this.saveUsageRow("session", this.sessionId, this.sessionUsage);
|
|
74409
|
+
this.saveUsageRow("swarm", this.sessionId, this.swarmUsage);
|
|
74410
|
+
}
|
|
74411
|
+
saveProjectState(projectId, usage) {
|
|
74412
|
+
this.saveUsageRow("project", projectId, usage);
|
|
74302
74413
|
}
|
|
74303
74414
|
isEnabled() {
|
|
74304
74415
|
return this.config.enabled ?? false;
|
|
@@ -74309,8 +74420,24 @@ class BudgetTracker {
|
|
|
74309
74420
|
setActiveProject(projectId) {
|
|
74310
74421
|
this.activeProjectId = projectId;
|
|
74311
74422
|
if (projectId && !this.projectUsages.has(projectId)) {
|
|
74312
|
-
|
|
74313
|
-
|
|
74423
|
+
if (this.db && this.config.persist) {
|
|
74424
|
+
const row = this.db.query("SELECT * FROM budget_usage WHERE scope = 'project' AND scope_id = ?").get(projectId);
|
|
74425
|
+
if (row) {
|
|
74426
|
+
this.projectUsages.set(projectId, {
|
|
74427
|
+
...createEmptyUsage(),
|
|
74428
|
+
inputTokens: row.input_tokens,
|
|
74429
|
+
outputTokens: row.output_tokens,
|
|
74430
|
+
totalTokens: row.total_tokens,
|
|
74431
|
+
llmCalls: row.api_calls,
|
|
74432
|
+
toolCalls: row.tool_calls,
|
|
74433
|
+
lastUpdatedAt: row.updated_at
|
|
74434
|
+
});
|
|
74435
|
+
} else {
|
|
74436
|
+
this.projectUsages.set(projectId, createEmptyUsage());
|
|
74437
|
+
}
|
|
74438
|
+
} else {
|
|
74439
|
+
this.projectUsages.set(projectId, createEmptyUsage());
|
|
74440
|
+
}
|
|
74314
74441
|
}
|
|
74315
74442
|
}
|
|
74316
74443
|
getActiveProject() {
|
|
@@ -74409,7 +74536,7 @@ class BudgetTracker {
|
|
|
74409
74536
|
};
|
|
74410
74537
|
if (scope === "assistant" && idOrAssistant) {
|
|
74411
74538
|
const assistantUsage = this.assistantUsages.get(idOrAssistant) || createEmptyUsage();
|
|
74412
|
-
|
|
74539
|
+
const updatedAssistant = {
|
|
74413
74540
|
...assistantUsage,
|
|
74414
74541
|
inputTokens: assistantUsage.inputTokens + (update.inputTokens || 0),
|
|
74415
74542
|
outputTokens: assistantUsage.outputTokens + (update.outputTokens || 0),
|
|
@@ -74418,7 +74545,9 @@ class BudgetTracker {
|
|
|
74418
74545
|
toolCalls: assistantUsage.toolCalls + (update.toolCalls || 0),
|
|
74419
74546
|
durationMs: assistantUsage.durationMs + (update.durationMs || 0),
|
|
74420
74547
|
lastUpdatedAt: now2
|
|
74421
|
-
}
|
|
74548
|
+
};
|
|
74549
|
+
this.assistantUsages.set(idOrAssistant, updatedAssistant);
|
|
74550
|
+
this.saveUsageRow("assistant", `${this.sessionId}:${idOrAssistant}`, updatedAssistant);
|
|
74422
74551
|
}
|
|
74423
74552
|
if (scope === "swarm") {
|
|
74424
74553
|
this.swarmUsage = {
|
|
@@ -74618,10 +74747,9 @@ class BudgetTracker {
|
|
|
74618
74747
|
`);
|
|
74619
74748
|
}
|
|
74620
74749
|
}
|
|
74621
|
-
var
|
|
74622
|
-
var init_tracker = __esm(() => {
|
|
74750
|
+
var init_tracker = __esm(async () => {
|
|
74623
74751
|
init_defaults2();
|
|
74624
|
-
|
|
74752
|
+
await init_database();
|
|
74625
74753
|
});
|
|
74626
74754
|
|
|
74627
74755
|
// packages/core/src/budget/tools.ts
|
|
@@ -74882,10 +75010,10 @@ __export(exports_budget, {
|
|
|
74882
75010
|
DEFAULT_ASSISTANT_LIMITS: () => DEFAULT_ASSISTANT_LIMITS,
|
|
74883
75011
|
BudgetTracker: () => BudgetTracker
|
|
74884
75012
|
});
|
|
74885
|
-
var init_budget = __esm(() => {
|
|
74886
|
-
init_tracker();
|
|
75013
|
+
var init_budget = __esm(async () => {
|
|
74887
75014
|
init_defaults2();
|
|
74888
75015
|
init_tools4();
|
|
75016
|
+
await init_tracker();
|
|
74889
75017
|
});
|
|
74890
75018
|
|
|
74891
75019
|
// packages/core/src/registry/types.ts
|
|
@@ -74904,9 +75032,9 @@ var init_types4 = __esm(() => {
|
|
|
74904
75032
|
});
|
|
74905
75033
|
|
|
74906
75034
|
// packages/core/src/registry/store.ts
|
|
74907
|
-
|
|
74908
|
-
|
|
74909
|
-
|
|
75035
|
+
function getDb10() {
|
|
75036
|
+
return getDatabase();
|
|
75037
|
+
}
|
|
74910
75038
|
function generateAssistantId() {
|
|
74911
75039
|
return `assistant_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
|
|
74912
75040
|
}
|
|
@@ -75028,51 +75156,65 @@ class RegistryStore {
|
|
|
75028
75156
|
config;
|
|
75029
75157
|
cleanupTimer = null;
|
|
75030
75158
|
startedAt;
|
|
75031
|
-
|
|
75159
|
+
db = null;
|
|
75160
|
+
constructor(config, db) {
|
|
75032
75161
|
this.config = { ...DEFAULT_REGISTRY_CONFIG, ...config };
|
|
75033
75162
|
this.startedAt = Date.now();
|
|
75034
|
-
if (
|
|
75035
|
-
this.
|
|
75163
|
+
if (db) {
|
|
75164
|
+
this.db = db;
|
|
75165
|
+
} else if (this.config.storage === "database" || this.config.storage === "file") {
|
|
75166
|
+
try {
|
|
75167
|
+
this.db = getDb10();
|
|
75168
|
+
} catch {}
|
|
75169
|
+
}
|
|
75170
|
+
if (this.db) {
|
|
75171
|
+
this.loadFromDb();
|
|
75036
75172
|
}
|
|
75037
75173
|
if (this.config.autoDeregister) {
|
|
75038
75174
|
this.startCleanup();
|
|
75039
75175
|
}
|
|
75040
75176
|
}
|
|
75041
|
-
|
|
75042
|
-
if (this.
|
|
75043
|
-
return
|
|
75044
|
-
|
|
75045
|
-
|
|
75046
|
-
|
|
75177
|
+
loadFromDb() {
|
|
75178
|
+
if (!this.db)
|
|
75179
|
+
return;
|
|
75180
|
+
try {
|
|
75181
|
+
const rows = this.db.query("SELECT * FROM registered_assistants").all();
|
|
75182
|
+
for (const row of rows) {
|
|
75183
|
+
try {
|
|
75184
|
+
if (row.metadata) {
|
|
75185
|
+
const assistant = JSON.parse(row.metadata);
|
|
75186
|
+
this.assistants.set(assistant.id, assistant);
|
|
75187
|
+
}
|
|
75188
|
+
} catch {}
|
|
75189
|
+
}
|
|
75190
|
+
} catch {}
|
|
75047
75191
|
}
|
|
75048
|
-
|
|
75192
|
+
saveToDb() {
|
|
75193
|
+
if (!this.db)
|
|
75194
|
+
return;
|
|
75049
75195
|
try {
|
|
75050
|
-
const
|
|
75051
|
-
|
|
75052
|
-
return;
|
|
75053
|
-
const data = JSON.parse(readFileSync14(path2, "utf-8"));
|
|
75054
|
-
if (Array.isArray(data.assistants)) {
|
|
75055
|
-
for (const assistant of data.assistants) {
|
|
75056
|
-
this.assistants.set(assistant.id, assistant);
|
|
75057
|
-
}
|
|
75196
|
+
for (const assistant of this.assistants.values()) {
|
|
75197
|
+
this.persistAssistant(assistant);
|
|
75058
75198
|
}
|
|
75059
75199
|
} catch {}
|
|
75060
75200
|
}
|
|
75061
|
-
|
|
75062
|
-
if (this.
|
|
75201
|
+
persistAssistant(assistant) {
|
|
75202
|
+
if (!this.db)
|
|
75063
75203
|
return;
|
|
75064
75204
|
try {
|
|
75065
|
-
const
|
|
75066
|
-
const
|
|
75067
|
-
|
|
75068
|
-
|
|
75069
|
-
|
|
75070
|
-
|
|
75071
|
-
|
|
75072
|
-
|
|
75073
|
-
|
|
75074
|
-
|
|
75075
|
-
|
|
75205
|
+
const capabilitiesStr = JSON.stringify(assistant.capabilities);
|
|
75206
|
+
const tagsStr = JSON.stringify(assistant.capabilities.tags);
|
|
75207
|
+
const metadataStr = JSON.stringify(assistant);
|
|
75208
|
+
this.db.prepare(`INSERT OR REPLACE INTO registered_assistants
|
|
75209
|
+
(id, name, type, description, model, status, state, capabilities, tags, parent_id, created_at, updated_at, last_active_at, metadata)
|
|
75210
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(assistant.id, assistant.name, assistant.type, assistant.description || null, null, assistant.heartbeat.isStale ? "stale" : "active", assistant.status.state, capabilitiesStr, tagsStr, assistant.parentId || null, assistant.registeredAt, assistant.updatedAt, assistant.heartbeat.lastHeartbeat, metadataStr);
|
|
75211
|
+
} catch {}
|
|
75212
|
+
}
|
|
75213
|
+
removeFromDb(id) {
|
|
75214
|
+
if (!this.db)
|
|
75215
|
+
return;
|
|
75216
|
+
try {
|
|
75217
|
+
this.db.prepare("DELETE FROM registered_assistants WHERE id = ?").run(id);
|
|
75076
75218
|
} catch {}
|
|
75077
75219
|
}
|
|
75078
75220
|
startCleanup() {
|
|
@@ -75096,14 +75238,15 @@ class RegistryStore {
|
|
|
75096
75238
|
const age = now2 - lastHeartbeat;
|
|
75097
75239
|
if (age > staleThreshold) {
|
|
75098
75240
|
this.assistants.delete(id);
|
|
75241
|
+
this.removeFromDb(id);
|
|
75099
75242
|
} else if (age > this.config.heartbeatStaleThreshold) {
|
|
75100
75243
|
assistant.heartbeat.isStale = true;
|
|
75101
75244
|
assistant.heartbeat.missedCount = Math.floor(age / this.config.heartbeatStaleThreshold);
|
|
75102
75245
|
assistant.status.state = "offline";
|
|
75103
75246
|
assistant.updatedAt = new Date().toISOString();
|
|
75247
|
+
this.persistAssistant(assistant);
|
|
75104
75248
|
}
|
|
75105
75249
|
}
|
|
75106
|
-
this.saveToFile();
|
|
75107
75250
|
}
|
|
75108
75251
|
register(registration) {
|
|
75109
75252
|
if (this.assistants.size >= this.config.maxAssistants) {
|
|
@@ -75118,10 +75261,11 @@ class RegistryStore {
|
|
|
75118
75261
|
if (parent) {
|
|
75119
75262
|
parent.childIds.push(assistant.id);
|
|
75120
75263
|
parent.updatedAt = new Date().toISOString();
|
|
75264
|
+
this.persistAssistant(parent);
|
|
75121
75265
|
}
|
|
75122
75266
|
}
|
|
75123
75267
|
this.assistants.set(assistant.id, assistant);
|
|
75124
|
-
this.
|
|
75268
|
+
this.persistAssistant(assistant);
|
|
75125
75269
|
return assistant;
|
|
75126
75270
|
}
|
|
75127
75271
|
get(id) {
|
|
@@ -75161,7 +75305,7 @@ class RegistryStore {
|
|
|
75161
75305
|
};
|
|
75162
75306
|
}
|
|
75163
75307
|
assistant.updatedAt = now2;
|
|
75164
|
-
this.
|
|
75308
|
+
this.persistAssistant(assistant);
|
|
75165
75309
|
return assistant;
|
|
75166
75310
|
}
|
|
75167
75311
|
heartbeat(id) {
|
|
@@ -75187,13 +75331,14 @@ class RegistryStore {
|
|
|
75187
75331
|
if (parent) {
|
|
75188
75332
|
parent.childIds = parent.childIds.filter((cid) => cid !== id);
|
|
75189
75333
|
parent.updatedAt = new Date().toISOString();
|
|
75334
|
+
this.persistAssistant(parent);
|
|
75190
75335
|
}
|
|
75191
75336
|
}
|
|
75192
75337
|
for (const childId of assistant.childIds) {
|
|
75193
75338
|
this.deregister(childId);
|
|
75194
75339
|
}
|
|
75195
75340
|
this.assistants.delete(id);
|
|
75196
|
-
this.
|
|
75341
|
+
this.removeFromDb(id);
|
|
75197
75342
|
return true;
|
|
75198
75343
|
}
|
|
75199
75344
|
query(query) {
|
|
@@ -75290,11 +75435,16 @@ class RegistryStore {
|
|
|
75290
75435
|
}
|
|
75291
75436
|
clear() {
|
|
75292
75437
|
this.assistants.clear();
|
|
75293
|
-
this.
|
|
75438
|
+
if (this.db) {
|
|
75439
|
+
try {
|
|
75440
|
+
this.db.prepare("DELETE FROM registered_assistants").run();
|
|
75441
|
+
} catch {}
|
|
75442
|
+
}
|
|
75294
75443
|
}
|
|
75295
75444
|
}
|
|
75296
|
-
var init_store6 = __esm(() => {
|
|
75445
|
+
var init_store6 = __esm(async () => {
|
|
75297
75446
|
init_types4();
|
|
75447
|
+
await init_database();
|
|
75298
75448
|
});
|
|
75299
75449
|
|
|
75300
75450
|
// packages/core/src/registry/service.ts
|
|
@@ -75465,9 +75615,9 @@ function resetGlobalRegistry() {
|
|
|
75465
75615
|
}
|
|
75466
75616
|
}
|
|
75467
75617
|
var globalRegistry = null;
|
|
75468
|
-
var init_service = __esm(() => {
|
|
75618
|
+
var init_service = __esm(async () => {
|
|
75469
75619
|
init_types4();
|
|
75470
|
-
init_store6();
|
|
75620
|
+
await init_store6();
|
|
75471
75621
|
});
|
|
75472
75622
|
|
|
75473
75623
|
// packages/core/src/registry/index.ts
|
|
@@ -75479,9 +75629,11 @@ __export(exports_registry, {
|
|
|
75479
75629
|
DEFAULT_REGISTRY_CONFIG: () => DEFAULT_REGISTRY_CONFIG,
|
|
75480
75630
|
AssistantRegistryService: () => AssistantRegistryService
|
|
75481
75631
|
});
|
|
75482
|
-
var init_registry2 = __esm(() => {
|
|
75483
|
-
|
|
75484
|
-
|
|
75632
|
+
var init_registry2 = __esm(async () => {
|
|
75633
|
+
await __promiseAll([
|
|
75634
|
+
init_store6(),
|
|
75635
|
+
init_service()
|
|
75636
|
+
]);
|
|
75485
75637
|
init_types4();
|
|
75486
75638
|
});
|
|
75487
75639
|
|
|
@@ -79857,9 +80009,9 @@ var init_swarm = __esm(() => {
|
|
|
79857
80009
|
});
|
|
79858
80010
|
|
|
79859
80011
|
// packages/core/src/commands/builtin.ts
|
|
79860
|
-
import { join as
|
|
79861
|
-
import { homedir as
|
|
79862
|
-
import { existsSync as
|
|
80012
|
+
import { join as join25 } from "path";
|
|
80013
|
+
import { homedir as homedir15, platform as platform2, release, arch as arch2 } from "os";
|
|
80014
|
+
import { existsSync as existsSync19, mkdirSync as mkdirSync12, writeFileSync as writeFileSync9 } from "fs";
|
|
79863
80015
|
function resolveAuthTimeout(resolve6) {
|
|
79864
80016
|
resolve6({ exitCode: 1, stdout: { toString: () => "{}" } });
|
|
79865
80017
|
}
|
|
@@ -86330,9 +86482,9 @@ Format the summary as a brief bullet-point list. This summary will replace the c
|
|
|
86330
86482
|
if (action === "show" || action === "paths") {
|
|
86331
86483
|
const storageDir = context.getStorageDir?.() || getConfigDir();
|
|
86332
86484
|
const configPaths = [
|
|
86333
|
-
|
|
86334
|
-
|
|
86335
|
-
|
|
86485
|
+
join25(context.cwd, ".assistants", "config.json"),
|
|
86486
|
+
join25(context.cwd, ".assistants", "config.local.json"),
|
|
86487
|
+
join25(storageDir, "config.json")
|
|
86336
86488
|
];
|
|
86337
86489
|
let message = `
|
|
86338
86490
|
**Configuration**
|
|
@@ -86341,21 +86493,21 @@ Format the summary as a brief bullet-point list. This summary will replace the c
|
|
|
86341
86493
|
message += `**Config File Locations:**
|
|
86342
86494
|
`;
|
|
86343
86495
|
for (const path2 of configPaths) {
|
|
86344
|
-
const exists =
|
|
86496
|
+
const exists = existsSync19(path2);
|
|
86345
86497
|
message += ` ${exists ? "\u2713" : "\u25CB"} ${path2}
|
|
86346
86498
|
`;
|
|
86347
86499
|
}
|
|
86348
86500
|
const envHome = process.env.HOME || process.env.USERPROFILE;
|
|
86349
|
-
const homeDir = envHome && envHome.trim().length > 0 ? envHome :
|
|
86501
|
+
const homeDir = envHome && envHome.trim().length > 0 ? envHome : homedir15();
|
|
86350
86502
|
message += `
|
|
86351
86503
|
**Commands Directories:**
|
|
86352
86504
|
`;
|
|
86353
|
-
message += ` - Project: ${
|
|
86505
|
+
message += ` - Project: ${join25(context.cwd, ".assistants", "commands")}
|
|
86354
86506
|
`;
|
|
86355
|
-
message += ` - User/Workspace: ${
|
|
86507
|
+
message += ` - User/Workspace: ${join25(storageDir, "commands")}
|
|
86356
86508
|
`;
|
|
86357
|
-
if (storageDir !==
|
|
86358
|
-
message += ` - Global fallback: ${
|
|
86509
|
+
if (storageDir !== join25(homeDir, ".assistants")) {
|
|
86510
|
+
message += ` - Global fallback: ${join25(homeDir, ".assistants", "commands")}
|
|
86359
86511
|
`;
|
|
86360
86512
|
}
|
|
86361
86513
|
context.emit("text", message);
|
|
@@ -86376,7 +86528,7 @@ Format the summary as a brief bullet-point list. This summary will replace the c
|
|
|
86376
86528
|
selfHandled: true,
|
|
86377
86529
|
content: "",
|
|
86378
86530
|
handler: async (args, context) => {
|
|
86379
|
-
const { BudgetTracker: BudgetTracker2 } = await
|
|
86531
|
+
const { BudgetTracker: BudgetTracker2 } = await init_budget().then(() => exports_budget);
|
|
86380
86532
|
const rawArgs = args.trim();
|
|
86381
86533
|
const [actionToken = "", ...actionParts] = rawArgs.length > 0 ? rawArgs.split(/\s+/) : [];
|
|
86382
86534
|
const action = actionToken.toLowerCase();
|
|
@@ -86802,7 +86954,7 @@ On exceeded: ${config.onExceeded || "warn"}
|
|
|
86802
86954
|
selfHandled: true,
|
|
86803
86955
|
content: "",
|
|
86804
86956
|
handler: async (args, context) => {
|
|
86805
|
-
const { getGlobalRegistry: getGlobalRegistry2 } = await
|
|
86957
|
+
const { getGlobalRegistry: getGlobalRegistry2 } = await init_registry2().then(() => exports_registry);
|
|
86806
86958
|
const action = args.trim().toLowerCase();
|
|
86807
86959
|
const registry = getGlobalRegistry2();
|
|
86808
86960
|
if (action === "help") {
|
|
@@ -87271,8 +87423,8 @@ ${error2 instanceof Error ? error2.message : String(error2)}
|
|
|
87271
87423
|
selfHandled: true,
|
|
87272
87424
|
content: "",
|
|
87273
87425
|
handler: async (args, context) => {
|
|
87274
|
-
const commandsDir =
|
|
87275
|
-
|
|
87426
|
+
const commandsDir = join25(context.cwd, ".assistants", "commands");
|
|
87427
|
+
mkdirSync12(commandsDir, { recursive: true });
|
|
87276
87428
|
const exampleCommand = `---
|
|
87277
87429
|
name: reflect
|
|
87278
87430
|
description: Reflect on the conversation and suggest next steps
|
|
@@ -87287,9 +87439,9 @@ Please summarize the last interaction and suggest 2-3 next steps.
|
|
|
87287
87439
|
- Focus on clarity
|
|
87288
87440
|
- Ask a follow-up question if needed
|
|
87289
87441
|
`;
|
|
87290
|
-
const examplePath =
|
|
87291
|
-
if (!
|
|
87292
|
-
|
|
87442
|
+
const examplePath = join25(commandsDir, "reflect.md");
|
|
87443
|
+
if (!existsSync19(examplePath)) {
|
|
87444
|
+
writeFileSync9(examplePath, exampleCommand);
|
|
87293
87445
|
}
|
|
87294
87446
|
let message = `
|
|
87295
87447
|
**Initialized assistants**
|
|
@@ -88018,11 +88170,11 @@ Memory Statistics
|
|
|
88018
88170
|
return { handled: true };
|
|
88019
88171
|
}
|
|
88020
88172
|
if (action === "export") {
|
|
88021
|
-
const filePath = rest[0] ||
|
|
88173
|
+
const filePath = rest[0] || join25(context.getStorageDir?.() || getConfigDir(), "memories-export.json");
|
|
88022
88174
|
const memories = await manager.export();
|
|
88023
88175
|
try {
|
|
88024
88176
|
const content = JSON.stringify(memories, null, 2);
|
|
88025
|
-
|
|
88177
|
+
writeFileSync9(filePath, content, "utf-8");
|
|
88026
88178
|
context.emit("text", `Exported ${memories.length} memories to: ${filePath}
|
|
88027
88179
|
`);
|
|
88028
88180
|
} catch (error2) {
|
|
@@ -88236,7 +88388,7 @@ Importing ${validMemories.length} valid entries (skipping ${errors.length} inval
|
|
|
88236
88388
|
const heartbeatConfig = context.getHeartbeatConfig?.() ?? null;
|
|
88237
88389
|
const historyPathTemplate = heartbeatConfig?.historyPath;
|
|
88238
88390
|
const storageDir = context.getStorageDir?.();
|
|
88239
|
-
const runsDir = storageDir ?
|
|
88391
|
+
const runsDir = storageDir ? join25(storageDir, "heartbeats", "runs") : undefined;
|
|
88240
88392
|
if (!cleanedArgs || cleanedArgs === "ui") {
|
|
88241
88393
|
context.emit("done");
|
|
88242
88394
|
return { handled: true, showPanel: "heartbeat" };
|
|
@@ -88938,11 +89090,10 @@ Not a git repository or git not available.
|
|
|
88938
89090
|
context.setProjectContext(projectContext);
|
|
88939
89091
|
}
|
|
88940
89092
|
}
|
|
88941
|
-
var VERSION2 = "1.1.
|
|
89093
|
+
var VERSION2 = "1.1.52";
|
|
88942
89094
|
var init_builtin = __esm(async () => {
|
|
88943
89095
|
init_src2();
|
|
88944
89096
|
init_context3();
|
|
88945
|
-
init_verification();
|
|
88946
89097
|
init_create();
|
|
88947
89098
|
init_installer();
|
|
88948
89099
|
init_templates();
|
|
@@ -88954,6 +89105,7 @@ var init_builtin = __esm(async () => {
|
|
|
88954
89105
|
init_store3(),
|
|
88955
89106
|
init_history(),
|
|
88956
89107
|
init_store(),
|
|
89108
|
+
init_verification(),
|
|
88957
89109
|
init_hooks(),
|
|
88958
89110
|
init_jobs2(),
|
|
88959
89111
|
init_tasks()
|
|
@@ -93877,9 +94029,9 @@ var init_client3 = __esm(() => {
|
|
|
93877
94029
|
});
|
|
93878
94030
|
|
|
93879
94031
|
// packages/core/src/heartbeat/manager.ts
|
|
93880
|
-
import { dirname as
|
|
93881
|
-
import { mkdirSync as
|
|
93882
|
-
import { readFile as
|
|
94032
|
+
import { dirname as dirname12 } from "path";
|
|
94033
|
+
import { mkdirSync as mkdirSync13 } from "fs";
|
|
94034
|
+
import { readFile as readFile5, writeFile as writeFile4 } from "fs/promises";
|
|
93883
94035
|
|
|
93884
94036
|
class HeartbeatManager {
|
|
93885
94037
|
config;
|
|
@@ -93900,8 +94052,8 @@ class HeartbeatManager {
|
|
|
93900
94052
|
errorsEncountered: 0,
|
|
93901
94053
|
uptimeSeconds: 0
|
|
93902
94054
|
};
|
|
93903
|
-
const dir =
|
|
93904
|
-
|
|
94055
|
+
const dir = dirname12(config.persistPath);
|
|
94056
|
+
mkdirSync13(dir, { recursive: true });
|
|
93905
94057
|
}
|
|
93906
94058
|
start(sessionId) {
|
|
93907
94059
|
if (this.intervalId)
|
|
@@ -93989,7 +94141,7 @@ class HeartbeatManager {
|
|
|
93989
94141
|
}
|
|
93990
94142
|
static async checkStale(path3, thresholdMs) {
|
|
93991
94143
|
try {
|
|
93992
|
-
const content = await
|
|
94144
|
+
const content = await readFile5(path3, "utf-8");
|
|
93993
94145
|
const heartbeat = JSON.parse(content);
|
|
93994
94146
|
const age = Date.now() - new Date(heartbeat.timestamp).getTime();
|
|
93995
94147
|
return { isStale: age > thresholdMs, lastHeartbeat: heartbeat };
|
|
@@ -94082,34 +94234,34 @@ var init_recovery = __esm(async () => {
|
|
|
94082
94234
|
});
|
|
94083
94235
|
|
|
94084
94236
|
// packages/core/src/heartbeat/finder.ts
|
|
94085
|
-
import { existsSync as
|
|
94086
|
-
import { join as
|
|
94237
|
+
import { existsSync as existsSync20, readdirSync as readdirSync7, readFileSync as readFileSync10 } from "fs";
|
|
94238
|
+
import { join as join26 } from "path";
|
|
94087
94239
|
function findRecoverableSessions(staleThresholdMs = 120000, maxAgeMs = 24 * 60 * 60 * 1000, baseDir) {
|
|
94088
94240
|
const configDir = baseDir ?? getConfigDir();
|
|
94089
|
-
const heartbeatsDir =
|
|
94090
|
-
const stateDir =
|
|
94091
|
-
const sessionsDir =
|
|
94241
|
+
const heartbeatsDir = join26(configDir, "heartbeats");
|
|
94242
|
+
const stateDir = join26(configDir, "state");
|
|
94243
|
+
const sessionsDir = join26(configDir, "sessions");
|
|
94092
94244
|
const recoverableSessions = [];
|
|
94093
|
-
if (!
|
|
94245
|
+
if (!existsSync20(heartbeatsDir)) {
|
|
94094
94246
|
return recoverableSessions;
|
|
94095
94247
|
}
|
|
94096
94248
|
const now2 = Date.now();
|
|
94097
|
-
const heartbeatFiles =
|
|
94249
|
+
const heartbeatFiles = readdirSync7(heartbeatsDir).filter((f) => f.endsWith(".json"));
|
|
94098
94250
|
for (const file of heartbeatFiles) {
|
|
94099
94251
|
const sessionId = file.replace(".json", "");
|
|
94100
|
-
const heartbeatPath =
|
|
94101
|
-
const statePath =
|
|
94102
|
-
const sessionPath =
|
|
94252
|
+
const heartbeatPath = join26(heartbeatsDir, file);
|
|
94253
|
+
const statePath = join26(stateDir, `${sessionId}.json`);
|
|
94254
|
+
const sessionPath = join26(sessionsDir, `${sessionId}.json`);
|
|
94103
94255
|
try {
|
|
94104
|
-
const heartbeatContent =
|
|
94256
|
+
const heartbeatContent = readFileSync10(heartbeatPath, "utf-8");
|
|
94105
94257
|
const heartbeat = JSON.parse(heartbeatContent);
|
|
94106
94258
|
const heartbeatAge = now2 - new Date(heartbeat.timestamp).getTime();
|
|
94107
94259
|
if (heartbeatAge < staleThresholdMs) {
|
|
94108
94260
|
continue;
|
|
94109
94261
|
}
|
|
94110
94262
|
let state = null;
|
|
94111
|
-
if (
|
|
94112
|
-
const stateContent =
|
|
94263
|
+
if (existsSync20(statePath)) {
|
|
94264
|
+
const stateContent = readFileSync10(statePath, "utf-8");
|
|
94113
94265
|
state = JSON.parse(stateContent);
|
|
94114
94266
|
}
|
|
94115
94267
|
if (state) {
|
|
@@ -94120,9 +94272,9 @@ function findRecoverableSessions(staleThresholdMs = 120000, maxAgeMs = 24 * 60 *
|
|
|
94120
94272
|
}
|
|
94121
94273
|
let messageCount = 0;
|
|
94122
94274
|
let cwd = state?.context?.cwd || process.cwd();
|
|
94123
|
-
if (
|
|
94275
|
+
if (existsSync20(sessionPath)) {
|
|
94124
94276
|
try {
|
|
94125
|
-
const sessionContent =
|
|
94277
|
+
const sessionContent = readFileSync10(sessionPath, "utf-8");
|
|
94126
94278
|
const sessionData = JSON.parse(sessionContent);
|
|
94127
94279
|
messageCount = sessionData.messages?.length || 0;
|
|
94128
94280
|
cwd = sessionData.cwd || cwd;
|
|
@@ -94154,17 +94306,17 @@ function findRecoverableSessions(staleThresholdMs = 120000, maxAgeMs = 24 * 60 *
|
|
|
94154
94306
|
}
|
|
94155
94307
|
function clearRecoveryState(sessionId, baseDir) {
|
|
94156
94308
|
const configDir = baseDir ?? getConfigDir();
|
|
94157
|
-
const heartbeatPath =
|
|
94158
|
-
const statePath =
|
|
94159
|
-
const { unlinkSync:
|
|
94309
|
+
const heartbeatPath = join26(configDir, "heartbeats", `${sessionId}.json`);
|
|
94310
|
+
const statePath = join26(configDir, "state", `${sessionId}.json`);
|
|
94311
|
+
const { unlinkSync: unlinkSync3 } = __require("fs");
|
|
94160
94312
|
try {
|
|
94161
|
-
if (
|
|
94162
|
-
|
|
94313
|
+
if (existsSync20(heartbeatPath)) {
|
|
94314
|
+
unlinkSync3(heartbeatPath);
|
|
94163
94315
|
}
|
|
94164
94316
|
} catch {}
|
|
94165
94317
|
try {
|
|
94166
|
-
if (
|
|
94167
|
-
|
|
94318
|
+
if (existsSync20(statePath)) {
|
|
94319
|
+
unlinkSync3(statePath);
|
|
94168
94320
|
}
|
|
94169
94321
|
} catch {}
|
|
94170
94322
|
}
|
|
@@ -94292,15 +94444,15 @@ var init_watchdog = __esm(async () => {
|
|
|
94292
94444
|
});
|
|
94293
94445
|
|
|
94294
94446
|
// packages/core/src/heartbeat/install-skills.ts
|
|
94295
|
-
import { join as
|
|
94296
|
-
import { homedir as
|
|
94447
|
+
import { join as join27 } from "path";
|
|
94448
|
+
import { homedir as homedir16 } from "os";
|
|
94297
94449
|
async function writeSkillIfNeeded(dir, skillName, content) {
|
|
94298
|
-
const { mkdir: mkdir7, writeFile: writeFile5, readFile:
|
|
94299
|
-
const skillDir =
|
|
94300
|
-
const skillFile =
|
|
94450
|
+
const { mkdir: mkdir7, writeFile: writeFile5, readFile: readFile6 } = await import("fs/promises");
|
|
94451
|
+
const skillDir = join27(dir, `skill-${skillName}`);
|
|
94452
|
+
const skillFile = join27(skillDir, "SKILL.md");
|
|
94301
94453
|
await mkdir7(skillDir, { recursive: true });
|
|
94302
94454
|
try {
|
|
94303
|
-
const existing = await
|
|
94455
|
+
const existing = await readFile6(skillFile, "utf-8");
|
|
94304
94456
|
if (existing === content) {
|
|
94305
94457
|
return false;
|
|
94306
94458
|
}
|
|
@@ -94316,8 +94468,8 @@ async function writeSkillIfNeeded(dir, skillName, content) {
|
|
|
94316
94468
|
}
|
|
94317
94469
|
}
|
|
94318
94470
|
async function installHeartbeatSkills() {
|
|
94319
|
-
const baseDir = process.env.ASSISTANTS_DIR ||
|
|
94320
|
-
const sharedSkillsDir =
|
|
94471
|
+
const baseDir = process.env.ASSISTANTS_DIR || join27(homedir16(), ".assistants");
|
|
94472
|
+
const sharedSkillsDir = join27(baseDir, "shared", "skills");
|
|
94321
94473
|
const installed = [];
|
|
94322
94474
|
const results = await Promise.all([
|
|
94323
94475
|
writeSkillIfNeeded(sharedSkillsDir, "main-loop", MAIN_LOOP_SKILL),
|
|
@@ -94678,8 +94830,8 @@ var init_llm_response = __esm(() => {
|
|
|
94678
94830
|
// packages/core/src/voice/tts.ts
|
|
94679
94831
|
import { spawnSync as spawnSync2 } from "child_process";
|
|
94680
94832
|
import { tmpdir as tmpdir2 } from "os";
|
|
94681
|
-
import { join as
|
|
94682
|
-
import { readFileSync as
|
|
94833
|
+
import { join as join28 } from "path";
|
|
94834
|
+
import { readFileSync as readFileSync11, unlinkSync as unlinkSync3 } from "fs";
|
|
94683
94835
|
|
|
94684
94836
|
class ElevenLabsTTS {
|
|
94685
94837
|
apiKey;
|
|
@@ -94783,7 +94935,7 @@ class SystemTTS {
|
|
|
94783
94935
|
if (!say) {
|
|
94784
94936
|
throw new Error('System TTS not available: missing "say" command.');
|
|
94785
94937
|
}
|
|
94786
|
-
const output =
|
|
94938
|
+
const output = join28(tmpdir2(), `assistants-tts-${Date.now()}-${Math.random().toString(36).slice(2, 8)}.aiff`);
|
|
94787
94939
|
const args = [];
|
|
94788
94940
|
if (this.voiceId) {
|
|
94789
94941
|
args.push("-v", this.voiceId);
|
|
@@ -94796,8 +94948,8 @@ class SystemTTS {
|
|
|
94796
94948
|
if (result.status !== 0) {
|
|
94797
94949
|
throw new Error(`System TTS failed: ${result.stderr || "unknown error"}`);
|
|
94798
94950
|
}
|
|
94799
|
-
const audio =
|
|
94800
|
-
|
|
94951
|
+
const audio = readFileSync11(output);
|
|
94952
|
+
unlinkSync3(output);
|
|
94801
94953
|
return {
|
|
94802
94954
|
audio: audio.buffer.slice(audio.byteOffset, audio.byteOffset + audio.byteLength),
|
|
94803
94955
|
format: "aiff"
|
|
@@ -94805,7 +94957,7 @@ class SystemTTS {
|
|
|
94805
94957
|
}
|
|
94806
94958
|
const espeak = findExecutable("espeak") || findExecutable("espeak-ng");
|
|
94807
94959
|
if (espeak) {
|
|
94808
|
-
const output =
|
|
94960
|
+
const output = join28(tmpdir2(), `assistants-tts-${Date.now()}-${Math.random().toString(36).slice(2, 8)}.wav`);
|
|
94809
94961
|
const args = ["-w", output];
|
|
94810
94962
|
if (this.voiceId) {
|
|
94811
94963
|
args.push("-v", this.voiceId);
|
|
@@ -94818,8 +94970,8 @@ class SystemTTS {
|
|
|
94818
94970
|
if (result.status !== 0) {
|
|
94819
94971
|
throw new Error(`System TTS failed: ${result.stderr || "unknown error"}`);
|
|
94820
94972
|
}
|
|
94821
|
-
const audio =
|
|
94822
|
-
|
|
94973
|
+
const audio = readFileSync11(output);
|
|
94974
|
+
unlinkSync3(output);
|
|
94823
94975
|
return {
|
|
94824
94976
|
audio: audio.buffer.slice(audio.byteOffset, audio.byteOffset + audio.byteLength),
|
|
94825
94977
|
format: "wav"
|
|
@@ -94835,16 +94987,16 @@ var init_tts = __esm(() => {
|
|
|
94835
94987
|
// packages/core/src/voice/player.ts
|
|
94836
94988
|
import { spawn as spawn2 } from "child_process";
|
|
94837
94989
|
import { tmpdir as tmpdir3 } from "os";
|
|
94838
|
-
import { join as
|
|
94839
|
-
import { unlink as unlink2, writeFileSync as
|
|
94990
|
+
import { join as join29 } from "path";
|
|
94991
|
+
import { unlink as unlink2, writeFileSync as writeFileSync10, appendFileSync as appendFileSync3 } from "fs";
|
|
94840
94992
|
|
|
94841
94993
|
class AudioPlayer {
|
|
94842
94994
|
currentProcess = null;
|
|
94843
94995
|
playing = false;
|
|
94844
94996
|
async play(audio, options = {}) {
|
|
94845
94997
|
const format = options.format ?? "mp3";
|
|
94846
|
-
const tempFile =
|
|
94847
|
-
|
|
94998
|
+
const tempFile = join29(tmpdir3(), `assistants-audio-${Date.now()}-${Math.random().toString(36).slice(2, 8)}.${format}`);
|
|
94999
|
+
writeFileSync10(tempFile, Buffer.from(audio));
|
|
94848
95000
|
const player = this.resolvePlayer(format);
|
|
94849
95001
|
if (!player) {
|
|
94850
95002
|
throw new Error("No supported audio player found. Install afplay, ffplay, mpg123, or aplay.");
|
|
@@ -94871,8 +95023,8 @@ class AudioPlayer {
|
|
|
94871
95023
|
}
|
|
94872
95024
|
async playStream(chunks, options = {}) {
|
|
94873
95025
|
const format = options.format ?? "mp3";
|
|
94874
|
-
const tempFile =
|
|
94875
|
-
|
|
95026
|
+
const tempFile = join29(tmpdir3(), `assistants-stream-${Date.now()}-${Math.random().toString(36).slice(2, 8)}.${format}`);
|
|
95027
|
+
writeFileSync10(tempFile, Buffer.alloc(0));
|
|
94876
95028
|
for await (const chunk of chunks) {
|
|
94877
95029
|
appendFileSync3(tempFile, Buffer.from(chunk));
|
|
94878
95030
|
}
|
|
@@ -94940,8 +95092,8 @@ var init_player = __esm(() => {
|
|
|
94940
95092
|
// packages/core/src/voice/recorder.ts
|
|
94941
95093
|
import { spawn as spawn3 } from "child_process";
|
|
94942
95094
|
import { tmpdir as tmpdir4 } from "os";
|
|
94943
|
-
import { join as
|
|
94944
|
-
import { readFileSync as
|
|
95095
|
+
import { join as join30 } from "path";
|
|
95096
|
+
import { readFileSync as readFileSync12, existsSync as existsSync21, unlink as unlink3 } from "fs";
|
|
94945
95097
|
|
|
94946
95098
|
class AudioRecorder {
|
|
94947
95099
|
currentProcess = null;
|
|
@@ -94954,7 +95106,7 @@ class AudioRecorder {
|
|
|
94954
95106
|
const duration = options.durationSeconds ?? 5;
|
|
94955
95107
|
const sampleRate = options.sampleRate ?? 16000;
|
|
94956
95108
|
const channels = options.channels ?? 1;
|
|
94957
|
-
const output =
|
|
95109
|
+
const output = join30(tmpdir4(), `assistants-record-${Date.now()}.wav`);
|
|
94958
95110
|
this.currentOutputPath = output;
|
|
94959
95111
|
this.stoppedIntentionally = false;
|
|
94960
95112
|
const recorder = this.resolveRecorder(sampleRate, channels, duration, output);
|
|
@@ -94976,11 +95128,11 @@ class AudioRecorder {
|
|
|
94976
95128
|
reject(error3);
|
|
94977
95129
|
});
|
|
94978
95130
|
});
|
|
94979
|
-
if (!
|
|
95131
|
+
if (!existsSync21(output)) {
|
|
94980
95132
|
this.currentOutputPath = null;
|
|
94981
95133
|
return new ArrayBuffer(0);
|
|
94982
95134
|
}
|
|
94983
|
-
const data =
|
|
95135
|
+
const data = readFileSync12(output);
|
|
94984
95136
|
unlink3(output, () => {});
|
|
94985
95137
|
this.currentOutputPath = null;
|
|
94986
95138
|
return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
|
|
@@ -94992,7 +95144,7 @@ class AudioRecorder {
|
|
|
94992
95144
|
const sampleRate = options.sampleRate ?? 16000;
|
|
94993
95145
|
const channels = options.channels ?? 1;
|
|
94994
95146
|
const maxDuration = options.durationSeconds ?? 30;
|
|
94995
|
-
const output =
|
|
95147
|
+
const output = join30(tmpdir4(), `assistants-record-${Date.now()}.wav`);
|
|
94996
95148
|
this.currentOutputPath = output;
|
|
94997
95149
|
this.stoppedIntentionally = false;
|
|
94998
95150
|
const recorder = this.resolveVadRecorder(sampleRate, channels, maxDuration, output);
|
|
@@ -95014,11 +95166,11 @@ class AudioRecorder {
|
|
|
95014
95166
|
reject(error3);
|
|
95015
95167
|
});
|
|
95016
95168
|
});
|
|
95017
|
-
if (!
|
|
95169
|
+
if (!existsSync21(output)) {
|
|
95018
95170
|
this.currentOutputPath = null;
|
|
95019
95171
|
return new ArrayBuffer(0);
|
|
95020
95172
|
}
|
|
95021
|
-
const data =
|
|
95173
|
+
const data = readFileSync12(output);
|
|
95022
95174
|
unlink3(output, () => {});
|
|
95023
95175
|
this.currentOutputPath = null;
|
|
95024
95176
|
return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
|
|
@@ -95402,9 +95554,9 @@ var init_manager4 = __esm(() => {
|
|
|
95402
95554
|
init_recorder();
|
|
95403
95555
|
});
|
|
95404
95556
|
// packages/core/src/identity/identity-manager.ts
|
|
95405
|
-
import { existsSync as
|
|
95406
|
-
import { mkdir as mkdir7, readFile as
|
|
95407
|
-
import { join as
|
|
95557
|
+
import { existsSync as existsSync22 } from "fs";
|
|
95558
|
+
import { mkdir as mkdir7, readFile as readFile6, writeFile as writeFile5, rm as rm2 } from "fs/promises";
|
|
95559
|
+
import { join as join31 } from "path";
|
|
95408
95560
|
function isValidId3(id) {
|
|
95409
95561
|
return typeof id === "string" && id.length > 0 && SAFE_ID_PATTERN4.test(id);
|
|
95410
95562
|
}
|
|
@@ -95425,20 +95577,20 @@ class IdentityManager {
|
|
|
95425
95577
|
this.basePath = basePath;
|
|
95426
95578
|
}
|
|
95427
95579
|
get identitiesRoot() {
|
|
95428
|
-
return
|
|
95580
|
+
return join31(this.basePath, "assistants", this.assistantId, "identities");
|
|
95429
95581
|
}
|
|
95430
95582
|
get indexPath() {
|
|
95431
|
-
return
|
|
95583
|
+
return join31(this.identitiesRoot, "index.json");
|
|
95432
95584
|
}
|
|
95433
95585
|
get activePath() {
|
|
95434
|
-
return
|
|
95586
|
+
return join31(this.identitiesRoot, "active.json");
|
|
95435
95587
|
}
|
|
95436
95588
|
identityPath(id) {
|
|
95437
95589
|
validateId(id, "identityId");
|
|
95438
|
-
return
|
|
95590
|
+
return join31(this.identitiesRoot, `${id}.json`);
|
|
95439
95591
|
}
|
|
95440
95592
|
assistantConfigPath() {
|
|
95441
|
-
return
|
|
95593
|
+
return join31(this.basePath, "assistants", this.assistantId, "config.json");
|
|
95442
95594
|
}
|
|
95443
95595
|
async initialize() {
|
|
95444
95596
|
await mkdir7(this.identitiesRoot, { recursive: true });
|
|
@@ -95564,11 +95716,11 @@ class IdentityManager {
|
|
|
95564
95716
|
`);
|
|
95565
95717
|
}
|
|
95566
95718
|
async readIndex() {
|
|
95567
|
-
if (!
|
|
95719
|
+
if (!existsSync22(this.indexPath)) {
|
|
95568
95720
|
return { identities: [] };
|
|
95569
95721
|
}
|
|
95570
95722
|
try {
|
|
95571
|
-
const raw = await
|
|
95723
|
+
const raw = await readFile6(this.indexPath, "utf-8");
|
|
95572
95724
|
const data = JSON.parse(raw);
|
|
95573
95725
|
const identities = Array.isArray(data.identities) ? data.identities : [];
|
|
95574
95726
|
return { identities: identities.filter(isValidId3) };
|
|
@@ -95590,10 +95742,10 @@ class IdentityManager {
|
|
|
95590
95742
|
}
|
|
95591
95743
|
async readIdentity(id) {
|
|
95592
95744
|
const path3 = this.identityPath(id);
|
|
95593
|
-
if (!
|
|
95745
|
+
if (!existsSync22(path3))
|
|
95594
95746
|
return null;
|
|
95595
95747
|
try {
|
|
95596
|
-
const raw = await
|
|
95748
|
+
const raw = await readFile6(path3, "utf-8");
|
|
95597
95749
|
return JSON.parse(raw);
|
|
95598
95750
|
} catch {
|
|
95599
95751
|
return null;
|
|
@@ -95604,10 +95756,10 @@ class IdentityManager {
|
|
|
95604
95756
|
await writeFile5(this.identityPath(identity.id), JSON.stringify(identity, null, 2));
|
|
95605
95757
|
}
|
|
95606
95758
|
async readActive() {
|
|
95607
|
-
if (!
|
|
95759
|
+
if (!existsSync22(this.activePath))
|
|
95608
95760
|
return null;
|
|
95609
95761
|
try {
|
|
95610
|
-
const raw = await
|
|
95762
|
+
const raw = await readFile6(this.activePath, "utf-8");
|
|
95611
95763
|
const data = JSON.parse(raw);
|
|
95612
95764
|
const id = data.id || null;
|
|
95613
95765
|
if (id && !isValidId3(id)) {
|
|
@@ -95623,10 +95775,10 @@ class IdentityManager {
|
|
|
95623
95775
|
await writeFile5(this.activePath, JSON.stringify({ id }, null, 2));
|
|
95624
95776
|
}
|
|
95625
95777
|
async loadAssistant() {
|
|
95626
|
-
if (!
|
|
95778
|
+
if (!existsSync22(this.assistantConfigPath()))
|
|
95627
95779
|
return null;
|
|
95628
95780
|
try {
|
|
95629
|
-
const raw = await
|
|
95781
|
+
const raw = await readFile6(this.assistantConfigPath(), "utf-8");
|
|
95630
95782
|
return JSON.parse(raw);
|
|
95631
95783
|
} catch {
|
|
95632
95784
|
return null;
|
|
@@ -95659,49 +95811,81 @@ var init_identity_manager = __esm(() => {
|
|
|
95659
95811
|
});
|
|
95660
95812
|
|
|
95661
95813
|
// packages/core/src/identity/assistant-manager.ts
|
|
95662
|
-
|
|
95663
|
-
|
|
95664
|
-
import { join as join36 } from "path";
|
|
95665
|
-
function isValidId4(id) {
|
|
95666
|
-
return typeof id === "string" && id.length > 0 && SAFE_ID_PATTERN5.test(id);
|
|
95814
|
+
function getDb11() {
|
|
95815
|
+
return getDatabase();
|
|
95667
95816
|
}
|
|
95668
|
-
function
|
|
95669
|
-
|
|
95670
|
-
|
|
95671
|
-
|
|
95817
|
+
function rowToAssistant(row) {
|
|
95818
|
+
const raw = JSON.parse(row.settings);
|
|
95819
|
+
const avatar = raw.__avatar;
|
|
95820
|
+
const description = raw.__description;
|
|
95821
|
+
const color = raw.__color;
|
|
95822
|
+
const isSystem = raw.__isSystem;
|
|
95823
|
+
delete raw.__avatar;
|
|
95824
|
+
delete raw.__description;
|
|
95825
|
+
delete raw.__color;
|
|
95826
|
+
delete raw.__isSystem;
|
|
95827
|
+
const settings = raw;
|
|
95828
|
+
const assistant = {
|
|
95829
|
+
id: row.id,
|
|
95830
|
+
name: row.name,
|
|
95831
|
+
settings,
|
|
95832
|
+
createdAt: new Date(row.created_at).toISOString(),
|
|
95833
|
+
updatedAt: new Date(row.updated_at).toISOString()
|
|
95834
|
+
};
|
|
95835
|
+
if (row.identity_id)
|
|
95836
|
+
assistant.defaultIdentityId = row.identity_id;
|
|
95837
|
+
if (avatar)
|
|
95838
|
+
assistant.avatar = avatar;
|
|
95839
|
+
if (description)
|
|
95840
|
+
assistant.description = description;
|
|
95841
|
+
if (color)
|
|
95842
|
+
assistant.color = color;
|
|
95843
|
+
if (isSystem)
|
|
95844
|
+
assistant.isSystem = true;
|
|
95845
|
+
return assistant;
|
|
95846
|
+
}
|
|
95847
|
+
function assistantToRow(assistant) {
|
|
95848
|
+
const settingsObj = { ...assistant.settings };
|
|
95849
|
+
if (assistant.avatar)
|
|
95850
|
+
settingsObj.__avatar = assistant.avatar;
|
|
95851
|
+
if (assistant.description)
|
|
95852
|
+
settingsObj.__description = assistant.description;
|
|
95853
|
+
if (assistant.color)
|
|
95854
|
+
settingsObj.__color = assistant.color;
|
|
95855
|
+
if (assistant.isSystem)
|
|
95856
|
+
settingsObj.__isSystem = true;
|
|
95857
|
+
return {
|
|
95858
|
+
id: assistant.id,
|
|
95859
|
+
name: assistant.name,
|
|
95860
|
+
model: assistant.settings.model || null,
|
|
95861
|
+
system_prompt: assistant.settings.systemPromptAddition || null,
|
|
95862
|
+
settings: JSON.stringify(settingsObj),
|
|
95863
|
+
identity_id: assistant.defaultIdentityId || null,
|
|
95864
|
+
created_at: new Date(assistant.createdAt).getTime(),
|
|
95865
|
+
updated_at: new Date(assistant.updatedAt).getTime()
|
|
95866
|
+
};
|
|
95672
95867
|
}
|
|
95673
95868
|
|
|
95674
95869
|
class AssistantManager {
|
|
95675
95870
|
basePath;
|
|
95676
95871
|
assistants = new Map;
|
|
95677
95872
|
activeId = null;
|
|
95678
|
-
|
|
95873
|
+
db;
|
|
95874
|
+
constructor(basePath, db) {
|
|
95679
95875
|
this.basePath = basePath;
|
|
95680
|
-
|
|
95681
|
-
get assistantsRoot() {
|
|
95682
|
-
return join36(this.basePath, "assistants");
|
|
95683
|
-
}
|
|
95684
|
-
get indexPath() {
|
|
95685
|
-
return join36(this.assistantsRoot, "index.json");
|
|
95686
|
-
}
|
|
95687
|
-
get activePath() {
|
|
95688
|
-
return join36(this.basePath, "active.json");
|
|
95689
|
-
}
|
|
95690
|
-
assistantConfigPath(id) {
|
|
95691
|
-
validateId2(id, "assistantId");
|
|
95692
|
-
return join36(this.assistantsRoot, id, "config.json");
|
|
95876
|
+
this.db = db || getDb11();
|
|
95693
95877
|
}
|
|
95694
95878
|
async initialize() {
|
|
95695
|
-
|
|
95696
|
-
const
|
|
95697
|
-
|
|
95698
|
-
|
|
95699
|
-
|
|
95700
|
-
|
|
95701
|
-
}
|
|
95879
|
+
const rows = this.db.query("SELECT * FROM assistants_config").all();
|
|
95880
|
+
for (const row of rows) {
|
|
95881
|
+
try {
|
|
95882
|
+
const assistant = rowToAssistant(row);
|
|
95883
|
+
this.assistants.set(assistant.id, assistant);
|
|
95884
|
+
} catch {}
|
|
95702
95885
|
}
|
|
95703
95886
|
await this.seedSystemAssistants();
|
|
95704
|
-
this.
|
|
95887
|
+
const activeRow = this.db.query("SELECT assistant_id FROM assistants_active WHERE key = 'active'").get();
|
|
95888
|
+
this.activeId = activeRow?.assistant_id || null;
|
|
95705
95889
|
if (!this.activeId || !this.assistants.has(this.activeId)) {
|
|
95706
95890
|
await this.setActive(DEFAULT_SYSTEM_ASSISTANT_ID);
|
|
95707
95891
|
}
|
|
@@ -95719,14 +95903,13 @@ class AssistantManager {
|
|
|
95719
95903
|
createdAt: now2,
|
|
95720
95904
|
updatedAt: now2
|
|
95721
95905
|
};
|
|
95722
|
-
|
|
95906
|
+
this.persistAssistant(assistant);
|
|
95723
95907
|
this.assistants.set(id, assistant);
|
|
95724
|
-
await this.appendToIndex(id);
|
|
95725
95908
|
await this.setActive(id);
|
|
95726
95909
|
return assistant;
|
|
95727
95910
|
}
|
|
95728
95911
|
async updateAssistant(id, updates) {
|
|
95729
|
-
const existing = this.assistants.get(id)
|
|
95912
|
+
const existing = this.assistants.get(id);
|
|
95730
95913
|
if (!existing) {
|
|
95731
95914
|
throw new Error(`Assistant ${id} not found`);
|
|
95732
95915
|
}
|
|
@@ -95736,12 +95919,11 @@ class AssistantManager {
|
|
|
95736
95919
|
settings: { ...existing.settings, ...updates.settings || {} },
|
|
95737
95920
|
updatedAt: new Date().toISOString()
|
|
95738
95921
|
};
|
|
95739
|
-
|
|
95922
|
+
this.persistAssistant(updated);
|
|
95740
95923
|
this.assistants.set(id, updated);
|
|
95741
95924
|
return updated;
|
|
95742
95925
|
}
|
|
95743
95926
|
async deleteAssistant(id) {
|
|
95744
|
-
validateId2(id, "assistantId");
|
|
95745
95927
|
if (!this.assistants.has(id)) {
|
|
95746
95928
|
throw new Error(`Assistant ${id} not found`);
|
|
95747
95929
|
}
|
|
@@ -95749,16 +95931,15 @@ class AssistantManager {
|
|
|
95749
95931
|
if (assistant?.isSystem || isSystemAssistantId(id)) {
|
|
95750
95932
|
throw new Error(`Cannot delete system assistant "${assistant?.name || id}". System assistants are built-in and cannot be removed.`);
|
|
95751
95933
|
}
|
|
95752
|
-
|
|
95934
|
+
this.db.prepare("DELETE FROM assistants_config WHERE id = ?").run(id);
|
|
95753
95935
|
this.assistants.delete(id);
|
|
95754
|
-
await this.removeFromIndex(id);
|
|
95755
95936
|
if (this.activeId === id) {
|
|
95756
95937
|
const next = this.listAssistants()[0];
|
|
95757
95938
|
await this.setActive(next?.id || null);
|
|
95758
95939
|
}
|
|
95759
95940
|
}
|
|
95760
95941
|
async switchAssistant(id) {
|
|
95761
|
-
const assistant = this.assistants.get(id)
|
|
95942
|
+
const assistant = this.assistants.get(id);
|
|
95762
95943
|
if (!assistant) {
|
|
95763
95944
|
throw new Error(`Assistant ${id} not found`);
|
|
95764
95945
|
}
|
|
@@ -95784,91 +95965,42 @@ class AssistantManager {
|
|
|
95784
95965
|
for (const def of definitions) {
|
|
95785
95966
|
if (!this.assistants.has(def.id)) {
|
|
95786
95967
|
const assistant = buildSystemAssistant(def);
|
|
95787
|
-
|
|
95968
|
+
this.persistAssistant(assistant);
|
|
95788
95969
|
this.assistants.set(def.id, assistant);
|
|
95789
|
-
await this.appendToIndex(def.id);
|
|
95790
95970
|
}
|
|
95791
95971
|
}
|
|
95792
95972
|
}
|
|
95793
|
-
|
|
95794
|
-
|
|
95795
|
-
|
|
95796
|
-
|
|
95797
|
-
try {
|
|
95798
|
-
const raw = await readFile8(this.indexPath, "utf-8");
|
|
95799
|
-
const data = JSON.parse(raw);
|
|
95800
|
-
const assistants = Array.isArray(data.assistants) ? data.assistants : [];
|
|
95801
|
-
return { assistants: assistants.filter(isValidId4) };
|
|
95802
|
-
} catch {
|
|
95803
|
-
return { assistants: [] };
|
|
95804
|
-
}
|
|
95805
|
-
}
|
|
95806
|
-
async appendToIndex(id) {
|
|
95807
|
-
const index = await this.readIndex();
|
|
95808
|
-
if (!index.assistants.includes(id)) {
|
|
95809
|
-
index.assistants.push(id);
|
|
95810
|
-
}
|
|
95811
|
-
await writeFile6(this.indexPath, JSON.stringify(index, null, 2));
|
|
95812
|
-
}
|
|
95813
|
-
async removeFromIndex(id) {
|
|
95814
|
-
const index = await this.readIndex();
|
|
95815
|
-
index.assistants = index.assistants.filter((assistantId) => assistantId !== id);
|
|
95816
|
-
await writeFile6(this.indexPath, JSON.stringify(index, null, 2));
|
|
95817
|
-
}
|
|
95818
|
-
async readAssistant(id) {
|
|
95819
|
-
const configPath = this.assistantConfigPath(id);
|
|
95820
|
-
if (!existsSync27(configPath))
|
|
95821
|
-
return null;
|
|
95822
|
-
try {
|
|
95823
|
-
const raw = await readFile8(configPath, "utf-8");
|
|
95824
|
-
return JSON.parse(raw);
|
|
95825
|
-
} catch {
|
|
95826
|
-
return null;
|
|
95827
|
-
}
|
|
95828
|
-
}
|
|
95829
|
-
async persistAssistant(assistant) {
|
|
95830
|
-
validateId2(assistant.id, "assistantId");
|
|
95831
|
-
const dir = join36(this.assistantsRoot, assistant.id);
|
|
95832
|
-
await mkdir8(dir, { recursive: true });
|
|
95833
|
-
await writeFile6(this.assistantConfigPath(assistant.id), JSON.stringify(assistant, null, 2));
|
|
95834
|
-
}
|
|
95835
|
-
async readActive() {
|
|
95836
|
-
if (!existsSync27(this.activePath))
|
|
95837
|
-
return null;
|
|
95838
|
-
try {
|
|
95839
|
-
const raw = await readFile8(this.activePath, "utf-8");
|
|
95840
|
-
const data = JSON.parse(raw);
|
|
95841
|
-
const id = data.id || null;
|
|
95842
|
-
if (id && !isValidId4(id)) {
|
|
95843
|
-
return null;
|
|
95844
|
-
}
|
|
95845
|
-
return id;
|
|
95846
|
-
} catch {
|
|
95847
|
-
return null;
|
|
95848
|
-
}
|
|
95973
|
+
persistAssistant(assistant) {
|
|
95974
|
+
const row = assistantToRow(assistant);
|
|
95975
|
+
this.db.prepare(`INSERT OR REPLACE INTO assistants_config (id, name, model, system_prompt, settings, identity_id, created_at, updated_at)
|
|
95976
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`).run(row.id, row.name, row.model, row.system_prompt, row.settings, row.identity_id, row.created_at, row.updated_at);
|
|
95849
95977
|
}
|
|
95850
95978
|
async setActive(id) {
|
|
95851
95979
|
this.activeId = id;
|
|
95852
|
-
|
|
95980
|
+
if (id) {
|
|
95981
|
+
this.db.prepare("INSERT OR REPLACE INTO assistants_active (key, assistant_id) VALUES ('active', ?)").run(id);
|
|
95982
|
+
} else {
|
|
95983
|
+
this.db.prepare("DELETE FROM assistants_active WHERE key = 'active'").run();
|
|
95984
|
+
}
|
|
95853
95985
|
}
|
|
95854
95986
|
}
|
|
95855
|
-
var
|
|
95856
|
-
var init_assistant_manager = __esm(() => {
|
|
95987
|
+
var DEFAULT_SETTINGS;
|
|
95988
|
+
var init_assistant_manager = __esm(async () => {
|
|
95857
95989
|
init_src2();
|
|
95858
95990
|
init_identity_manager();
|
|
95859
95991
|
init_system_assistants();
|
|
95860
|
-
|
|
95992
|
+
await init_database();
|
|
95861
95993
|
DEFAULT_SETTINGS = {
|
|
95862
95994
|
model: "claude-opus-4-5"
|
|
95863
95995
|
};
|
|
95864
95996
|
});
|
|
95865
95997
|
|
|
95866
95998
|
// packages/core/src/identity/index.ts
|
|
95867
|
-
var init_identity2 = __esm(() => {
|
|
95868
|
-
init_assistant_manager();
|
|
95999
|
+
var init_identity2 = __esm(async () => {
|
|
95869
96000
|
init_identity_manager();
|
|
95870
96001
|
init_templates();
|
|
95871
96002
|
init_system_assistants();
|
|
96003
|
+
await init_assistant_manager();
|
|
95872
96004
|
});
|
|
95873
96005
|
|
|
95874
96006
|
// node_modules/.pnpm/@smithy+types@4.12.0/node_modules/@smithy/types/dist-cjs/index.js
|
|
@@ -110901,7 +111033,7 @@ var require_readFile = __commonJS((exports) => {
|
|
|
110901
111033
|
var promises_1 = __require("fs/promises");
|
|
110902
111034
|
exports.filePromises = {};
|
|
110903
111035
|
exports.fileIntercept = {};
|
|
110904
|
-
var
|
|
111036
|
+
var readFile7 = (path3, options) => {
|
|
110905
111037
|
if (exports.fileIntercept[path3] !== undefined) {
|
|
110906
111038
|
return exports.fileIntercept[path3];
|
|
110907
111039
|
}
|
|
@@ -110910,7 +111042,7 @@ var require_readFile = __commonJS((exports) => {
|
|
|
110910
111042
|
}
|
|
110911
111043
|
return exports.filePromises[path3];
|
|
110912
111044
|
};
|
|
110913
|
-
exports.readFile =
|
|
111045
|
+
exports.readFile = readFile7;
|
|
110914
111046
|
});
|
|
110915
111047
|
|
|
110916
111048
|
// node_modules/.pnpm/@smithy+shared-ini-file-loader@4.4.3/node_modules/@smithy/shared-ini-file-loader/dist-cjs/index.js
|
|
@@ -110920,7 +111052,7 @@ var require_dist_cjs35 = __commonJS((exports) => {
|
|
|
110920
111052
|
var getSSOTokenFromFile = require_getSSOTokenFromFile();
|
|
110921
111053
|
var path3 = __require("path");
|
|
110922
111054
|
var types11 = require_dist_cjs();
|
|
110923
|
-
var
|
|
111055
|
+
var readFile7 = require_readFile();
|
|
110924
111056
|
var ENV_PROFILE = "AWS_PROFILE";
|
|
110925
111057
|
var DEFAULT_PROFILE2 = "default";
|
|
110926
111058
|
var getProfileName = (init) => init.profile || process.env[ENV_PROFILE] || DEFAULT_PROFILE2;
|
|
@@ -111004,10 +111136,10 @@ var require_dist_cjs35 = __commonJS((exports) => {
|
|
|
111004
111136
|
resolvedConfigFilepath = path3.join(homeDir, configFilepath.slice(2));
|
|
111005
111137
|
}
|
|
111006
111138
|
const parsedFiles = await Promise.all([
|
|
111007
|
-
|
|
111139
|
+
readFile7.readFile(resolvedConfigFilepath, {
|
|
111008
111140
|
ignoreCache: init.ignoreCache
|
|
111009
111141
|
}).then(parseIni).then(getConfigData).catch(swallowError$1),
|
|
111010
|
-
|
|
111142
|
+
readFile7.readFile(resolvedFilepath, {
|
|
111011
111143
|
ignoreCache: init.ignoreCache
|
|
111012
111144
|
}).then(parseIni).catch(swallowError$1)
|
|
111013
111145
|
]);
|
|
@@ -111018,7 +111150,7 @@ var require_dist_cjs35 = __commonJS((exports) => {
|
|
|
111018
111150
|
};
|
|
111019
111151
|
var getSsoSessionData = (data) => Object.entries(data).filter(([key]) => key.startsWith(types11.IniSectionType.SSO_SESSION + CONFIG_PREFIX_SEPARATOR)).reduce((acc, [key, value]) => ({ ...acc, [key.substring(key.indexOf(CONFIG_PREFIX_SEPARATOR) + 1)]: value }), {});
|
|
111020
111152
|
var swallowError = () => ({});
|
|
111021
|
-
var loadSsoSessionData = async (init = {}) =>
|
|
111153
|
+
var loadSsoSessionData = async (init = {}) => readFile7.readFile(init.configFilepath ?? getConfigFilepath()).then(parseIni).then(getSsoSessionData).catch(swallowError);
|
|
111022
111154
|
var mergeConfigFiles = (...files) => {
|
|
111023
111155
|
const merged = {};
|
|
111024
111156
|
for (const file of files) {
|
|
@@ -111038,10 +111170,10 @@ var require_dist_cjs35 = __commonJS((exports) => {
|
|
|
111038
111170
|
};
|
|
111039
111171
|
var externalDataInterceptor = {
|
|
111040
111172
|
getFileRecord() {
|
|
111041
|
-
return
|
|
111173
|
+
return readFile7.fileIntercept;
|
|
111042
111174
|
},
|
|
111043
111175
|
interceptFile(path4, contents) {
|
|
111044
|
-
|
|
111176
|
+
readFile7.fileIntercept[path4] = Promise.resolve(contents);
|
|
111045
111177
|
},
|
|
111046
111178
|
getTokenRecord() {
|
|
111047
111179
|
return getSSOTokenFromFile.tokenIntercept;
|
|
@@ -111059,7 +111191,7 @@ var require_dist_cjs35 = __commonJS((exports) => {
|
|
|
111059
111191
|
Object.defineProperty(exports, "readFile", {
|
|
111060
111192
|
enumerable: true,
|
|
111061
111193
|
get: function() {
|
|
111062
|
-
return
|
|
111194
|
+
return readFile7.readFile;
|
|
111063
111195
|
}
|
|
111064
111196
|
});
|
|
111065
111197
|
exports.CONFIG_PREFIX_SEPARATOR = CONFIG_PREFIX_SEPARATOR;
|
|
@@ -120701,14 +120833,14 @@ var init_validateTokenKey = __esm(() => {
|
|
|
120701
120833
|
|
|
120702
120834
|
// node_modules/.pnpm/@aws-sdk+token-providers@3.985.0/node_modules/@aws-sdk/token-providers/dist-es/writeSSOTokenToFile.js
|
|
120703
120835
|
import { promises as fsPromises } from "fs";
|
|
120704
|
-
var import_shared_ini_file_loader,
|
|
120836
|
+
var import_shared_ini_file_loader, writeFile6, writeSSOTokenToFile = (id, ssoToken) => {
|
|
120705
120837
|
const tokenFilepath = import_shared_ini_file_loader.getSSOTokenFilepath(id);
|
|
120706
120838
|
const tokenString = JSON.stringify(ssoToken, null, 2);
|
|
120707
|
-
return
|
|
120839
|
+
return writeFile6(tokenFilepath, tokenString);
|
|
120708
120840
|
};
|
|
120709
120841
|
var init_writeSSOTokenToFile = __esm(() => {
|
|
120710
120842
|
import_shared_ini_file_loader = __toESM(require_dist_cjs35(), 1);
|
|
120711
|
-
({ writeFile:
|
|
120843
|
+
({ writeFile: writeFile6 } = fsPromises);
|
|
120712
120844
|
});
|
|
120713
120845
|
|
|
120714
120846
|
// node_modules/.pnpm/@aws-sdk+token-providers@3.985.0/node_modules/@aws-sdk/token-providers/dist-es/fromSso.js
|
|
@@ -123344,8 +123476,8 @@ var require_signin = __commonJS((exports) => {
|
|
|
123344
123476
|
// node_modules/.pnpm/@aws-sdk+credential-provider-login@3.972.5/node_modules/@aws-sdk/credential-provider-login/dist-es/LoginCredentialsFetcher.js
|
|
123345
123477
|
import { createHash as createHash4, createPrivateKey, createPublicKey, sign } from "crypto";
|
|
123346
123478
|
import { promises as fs2 } from "fs";
|
|
123347
|
-
import { homedir as
|
|
123348
|
-
import { dirname as
|
|
123479
|
+
import { homedir as homedir17 } from "os";
|
|
123480
|
+
import { dirname as dirname13, join as join32 } from "path";
|
|
123349
123481
|
var import_property_provider18, import_protocol_http11, import_shared_ini_file_loader6, LoginCredentialsFetcher;
|
|
123350
123482
|
var init_LoginCredentialsFetcher = __esm(() => {
|
|
123351
123483
|
import_property_provider18 = __toESM(require_dist_cjs17(), 1);
|
|
@@ -123498,17 +123630,17 @@ var init_LoginCredentialsFetcher = __esm(() => {
|
|
|
123498
123630
|
}
|
|
123499
123631
|
async saveToken(token) {
|
|
123500
123632
|
const tokenFilePath = this.getTokenFilePath();
|
|
123501
|
-
const directory =
|
|
123633
|
+
const directory = dirname13(tokenFilePath);
|
|
123502
123634
|
try {
|
|
123503
123635
|
await fs2.mkdir(directory, { recursive: true });
|
|
123504
123636
|
} catch (error3) {}
|
|
123505
123637
|
await fs2.writeFile(tokenFilePath, JSON.stringify(token, null, 2), "utf8");
|
|
123506
123638
|
}
|
|
123507
123639
|
getTokenFilePath() {
|
|
123508
|
-
const directory = process.env.AWS_LOGIN_CACHE_DIRECTORY ??
|
|
123640
|
+
const directory = process.env.AWS_LOGIN_CACHE_DIRECTORY ?? join32(homedir17(), ".aws", "login", "cache");
|
|
123509
123641
|
const loginSessionBytes = Buffer.from(this.loginSession, "utf8");
|
|
123510
123642
|
const loginSessionSha256 = createHash4("sha256").update(loginSessionBytes).digest("hex");
|
|
123511
|
-
return
|
|
123643
|
+
return join32(directory, `${loginSessionSha256}.json`);
|
|
123512
123644
|
}
|
|
123513
123645
|
derToRawSignature(derSignature) {
|
|
123514
123646
|
let offset = 2;
|
|
@@ -123814,7 +123946,7 @@ var fromWebToken = (init) => async (awsIdentityProperties) => {
|
|
|
123814
123946
|
};
|
|
123815
123947
|
|
|
123816
123948
|
// node_modules/.pnpm/@aws-sdk+credential-provider-web-identity@3.972.5/node_modules/@aws-sdk/credential-provider-web-identity/dist-es/fromTokenFile.js
|
|
123817
|
-
import { readFileSync as
|
|
123949
|
+
import { readFileSync as readFileSync13 } from "fs";
|
|
123818
123950
|
var import_client17, import_property_provider21, import_shared_ini_file_loader10, ENV_TOKEN_FILE = "AWS_WEB_IDENTITY_TOKEN_FILE", ENV_ROLE_ARN = "AWS_ROLE_ARN", ENV_ROLE_SESSION_NAME = "AWS_ROLE_SESSION_NAME", fromTokenFile = (init = {}) => async (awsIdentityProperties) => {
|
|
123819
123951
|
init.logger?.debug("@aws-sdk/credential-provider-web-identity - fromTokenFile");
|
|
123820
123952
|
const webIdentityTokenFile = init?.webIdentityTokenFile ?? process.env[ENV_TOKEN_FILE];
|
|
@@ -123827,7 +123959,7 @@ var import_client17, import_property_provider21, import_shared_ini_file_loader10
|
|
|
123827
123959
|
}
|
|
123828
123960
|
const credentials = await fromWebToken({
|
|
123829
123961
|
...init,
|
|
123830
|
-
webIdentityToken: import_shared_ini_file_loader10.externalDataInterceptor?.getTokenRecord?.()[webIdentityTokenFile] ??
|
|
123962
|
+
webIdentityToken: import_shared_ini_file_loader10.externalDataInterceptor?.getTokenRecord?.()[webIdentityTokenFile] ?? readFileSync13(webIdentityTokenFile, { encoding: "ascii" }),
|
|
123831
123963
|
roleArn,
|
|
123832
123964
|
roleSessionName
|
|
123833
123965
|
})(awsIdentityProperties);
|
|
@@ -128163,8 +128295,8 @@ var init_s3_client = __esm(() => {
|
|
|
128163
128295
|
});
|
|
128164
128296
|
|
|
128165
128297
|
// packages/core/src/inbox/storage/local-cache.ts
|
|
128166
|
-
import { join as
|
|
128167
|
-
import { mkdir as
|
|
128298
|
+
import { join as join33, basename as basename6 } from "path";
|
|
128299
|
+
import { mkdir as mkdir8, readFile as readFile8, writeFile as writeFile7, rm as rm3, readdir, stat as stat4 } from "fs/promises";
|
|
128168
128300
|
import { createHash as createHash5 } from "crypto";
|
|
128169
128301
|
function isValidAssistantId(id) {
|
|
128170
128302
|
return typeof id === "string" && id.length > 0 && STRICT_ID_PATTERN.test(id);
|
|
@@ -128189,7 +128321,7 @@ function sanitizeFilename(filename) {
|
|
|
128189
128321
|
const base = basename6(filename);
|
|
128190
128322
|
return base.replace(/[/\\]/g, "_");
|
|
128191
128323
|
}
|
|
128192
|
-
function
|
|
128324
|
+
function getDb12(injected) {
|
|
128193
128325
|
if (injected)
|
|
128194
128326
|
return injected;
|
|
128195
128327
|
return getDatabase();
|
|
@@ -128204,15 +128336,15 @@ class LocalInboxCache {
|
|
|
128204
128336
|
validateAssistantId(options.assistantId);
|
|
128205
128337
|
this.assistantId = options.assistantId;
|
|
128206
128338
|
this.basePath = options.basePath;
|
|
128207
|
-
this.cacheDir =
|
|
128339
|
+
this.cacheDir = join33(this.basePath, this.assistantId);
|
|
128208
128340
|
this.injectedDb = options.db;
|
|
128209
128341
|
}
|
|
128210
128342
|
db() {
|
|
128211
|
-
return
|
|
128343
|
+
return getDb12(this.injectedDb);
|
|
128212
128344
|
}
|
|
128213
128345
|
async ensureDirectories() {
|
|
128214
|
-
await
|
|
128215
|
-
await
|
|
128346
|
+
await mkdir8(join33(this.cacheDir, "emails"), { recursive: true });
|
|
128347
|
+
await mkdir8(join33(this.cacheDir, "attachments"), { recursive: true });
|
|
128216
128348
|
}
|
|
128217
128349
|
async loadIndex() {
|
|
128218
128350
|
const rows = this.db().query("SELECT * FROM inbox_cache WHERE assistant_id = ? ORDER BY date DESC").all(this.assistantId);
|
|
@@ -128240,8 +128372,8 @@ class LocalInboxCache {
|
|
|
128240
128372
|
throw new Error(`Failed to create safe filename for email ID: "${email.id}"`);
|
|
128241
128373
|
}
|
|
128242
128374
|
await this.ensureDirectories();
|
|
128243
|
-
const emailPath =
|
|
128244
|
-
await
|
|
128375
|
+
const emailPath = join33(this.cacheDir, "emails", `${filename}.json`);
|
|
128376
|
+
await writeFile7(emailPath, JSON.stringify(email, null, 2));
|
|
128245
128377
|
const existing = this.db().query("SELECT * FROM inbox_cache WHERE id = ? AND assistant_id = ?").get(email.id, this.assistantId);
|
|
128246
128378
|
if (existing) {
|
|
128247
128379
|
const useFilename = existing.filename || filename;
|
|
@@ -128259,8 +128391,8 @@ class LocalInboxCache {
|
|
|
128259
128391
|
if (!isValidMappedFilename(filename))
|
|
128260
128392
|
return null;
|
|
128261
128393
|
try {
|
|
128262
|
-
const emailPath =
|
|
128263
|
-
const content = await
|
|
128394
|
+
const emailPath = join33(this.cacheDir, "emails", `${filename}.json`);
|
|
128395
|
+
const content = await readFile8(emailPath, "utf-8");
|
|
128264
128396
|
return JSON.parse(content);
|
|
128265
128397
|
} catch {
|
|
128266
128398
|
return null;
|
|
@@ -128311,10 +128443,10 @@ class LocalInboxCache {
|
|
|
128311
128443
|
if (!safeFilename) {
|
|
128312
128444
|
throw new Error("Invalid attachment filename");
|
|
128313
128445
|
}
|
|
128314
|
-
const attachmentDir =
|
|
128315
|
-
await
|
|
128316
|
-
const attachmentPath =
|
|
128317
|
-
await
|
|
128446
|
+
const attachmentDir = join33(this.cacheDir, "attachments", emailFilename);
|
|
128447
|
+
await mkdir8(attachmentDir, { recursive: true });
|
|
128448
|
+
const attachmentPath = join33(attachmentDir, safeFilename);
|
|
128449
|
+
await writeFile7(attachmentPath, content);
|
|
128318
128450
|
return attachmentPath;
|
|
128319
128451
|
}
|
|
128320
128452
|
async getAttachmentPath(emailId, filename) {
|
|
@@ -128327,7 +128459,7 @@ class LocalInboxCache {
|
|
|
128327
128459
|
return null;
|
|
128328
128460
|
}
|
|
128329
128461
|
try {
|
|
128330
|
-
const attachmentPath =
|
|
128462
|
+
const attachmentPath = join33(this.cacheDir, "attachments", emailFilename, safeFilename);
|
|
128331
128463
|
await stat4(attachmentPath);
|
|
128332
128464
|
return attachmentPath;
|
|
128333
128465
|
} catch {
|
|
@@ -128350,10 +128482,10 @@ class LocalInboxCache {
|
|
|
128350
128482
|
const filename = row.filename || emailIdToFilename(row.id);
|
|
128351
128483
|
if (isValidMappedFilename(filename)) {
|
|
128352
128484
|
try {
|
|
128353
|
-
await
|
|
128485
|
+
await rm3(join33(this.cacheDir, "emails", `${filename}.json`));
|
|
128354
128486
|
} catch {}
|
|
128355
128487
|
try {
|
|
128356
|
-
await
|
|
128488
|
+
await rm3(join33(this.cacheDir, "attachments", filename), { recursive: true });
|
|
128357
128489
|
} catch {}
|
|
128358
128490
|
}
|
|
128359
128491
|
}
|
|
@@ -128365,20 +128497,20 @@ class LocalInboxCache {
|
|
|
128365
128497
|
async getCacheSize() {
|
|
128366
128498
|
let totalSize = 0;
|
|
128367
128499
|
try {
|
|
128368
|
-
const emailsDir =
|
|
128500
|
+
const emailsDir = join33(this.cacheDir, "emails");
|
|
128369
128501
|
const files = await readdir(emailsDir);
|
|
128370
128502
|
for (const file of files) {
|
|
128371
|
-
const fileStat = await stat4(
|
|
128503
|
+
const fileStat = await stat4(join33(emailsDir, file));
|
|
128372
128504
|
totalSize += fileStat.size;
|
|
128373
128505
|
}
|
|
128374
128506
|
} catch {}
|
|
128375
128507
|
try {
|
|
128376
|
-
const attachmentsDir =
|
|
128508
|
+
const attachmentsDir = join33(this.cacheDir, "attachments");
|
|
128377
128509
|
const dirs = await readdir(attachmentsDir);
|
|
128378
128510
|
for (const dir of dirs) {
|
|
128379
|
-
const files = await readdir(
|
|
128511
|
+
const files = await readdir(join33(attachmentsDir, dir));
|
|
128380
128512
|
for (const file of files) {
|
|
128381
|
-
const fileStat = await stat4(
|
|
128513
|
+
const fileStat = await stat4(join33(attachmentsDir, dir, file));
|
|
128382
128514
|
totalSize += fileStat.size;
|
|
128383
128515
|
}
|
|
128384
128516
|
}
|
|
@@ -128387,7 +128519,7 @@ class LocalInboxCache {
|
|
|
128387
128519
|
}
|
|
128388
128520
|
async clear() {
|
|
128389
128521
|
try {
|
|
128390
|
-
await
|
|
128522
|
+
await rm3(this.cacheDir, { recursive: true });
|
|
128391
128523
|
} catch {}
|
|
128392
128524
|
this.db().prepare("DELETE FROM inbox_cache WHERE assistant_id = ?").run(this.assistantId);
|
|
128393
128525
|
this.db().prepare("DELETE FROM inbox_sync WHERE assistant_id = ?").run(this.assistantId);
|
|
@@ -146615,8 +146747,8 @@ function many(p4) {
|
|
|
146615
146747
|
function many1(p4) {
|
|
146616
146748
|
return ab2(p4, many(p4), (head, tail) => [head, ...tail]);
|
|
146617
146749
|
}
|
|
146618
|
-
function ab2(pa, pb,
|
|
146619
|
-
return (data, i4) => mapOuter(pa(data, i4), (ma) => mapInner(pb(data, ma.position), (vb, j4) =>
|
|
146750
|
+
function ab2(pa, pb, join34) {
|
|
146751
|
+
return (data, i4) => mapOuter(pa(data, i4), (ma) => mapInner(pb(data, ma.position), (vb, j4) => join34(ma.value, vb, data, i4, j4)));
|
|
146620
146752
|
}
|
|
146621
146753
|
function left(pa, pb) {
|
|
146622
146754
|
return ab2(pa, pb, (va) => va);
|
|
@@ -146624,8 +146756,8 @@ function left(pa, pb) {
|
|
|
146624
146756
|
function right(pa, pb) {
|
|
146625
146757
|
return ab2(pa, pb, (va, vb) => vb);
|
|
146626
146758
|
}
|
|
146627
|
-
function abc(pa, pb, pc,
|
|
146628
|
-
return (data, i4) => mapOuter(pa(data, i4), (ma) => mapOuter(pb(data, ma.position), (mb) => mapInner(pc(data, mb.position), (vc, j4) =>
|
|
146759
|
+
function abc(pa, pb, pc, join34) {
|
|
146760
|
+
return (data, i4) => mapOuter(pa(data, i4), (ma) => mapOuter(pb(data, ma.position), (mb) => mapInner(pc(data, mb.position), (vc, j4) => join34(ma.value, mb.value, vc, data, i4, j4))));
|
|
146629
146761
|
}
|
|
146630
146762
|
function middle(pa, pb, pc) {
|
|
146631
146763
|
return abc(pa, pb, pc, (ra, rb) => rb);
|
|
@@ -170212,7 +170344,7 @@ var init_providers = __esm(() => {
|
|
|
170212
170344
|
});
|
|
170213
170345
|
|
|
170214
170346
|
// packages/core/src/inbox/inbox-manager.ts
|
|
170215
|
-
import { join as
|
|
170347
|
+
import { join as join34 } from "path";
|
|
170216
170348
|
|
|
170217
170349
|
class InboxManager {
|
|
170218
170350
|
assistantId;
|
|
@@ -170386,7 +170518,7 @@ class InboxManager {
|
|
|
170386
170518
|
}
|
|
170387
170519
|
}
|
|
170388
170520
|
function createInboxManager(assistantId, assistantName, config, configDir) {
|
|
170389
|
-
const basePath =
|
|
170521
|
+
const basePath = join34(configDir, "messages");
|
|
170390
170522
|
return new InboxManager({
|
|
170391
170523
|
assistantId,
|
|
170392
170524
|
assistantName,
|
|
@@ -172677,7 +172809,7 @@ var init_secrets_client = __esm(() => {
|
|
|
172677
172809
|
});
|
|
172678
172810
|
|
|
172679
172811
|
// packages/core/src/wallet/storage/local-client.ts
|
|
172680
|
-
function
|
|
172812
|
+
function getDb13(injected) {
|
|
172681
172813
|
if (injected)
|
|
172682
172814
|
return injected;
|
|
172683
172815
|
return getDatabase();
|
|
@@ -172689,7 +172821,7 @@ class LocalWalletClient {
|
|
|
172689
172821
|
this.injectedDb = options.db;
|
|
172690
172822
|
}
|
|
172691
172823
|
db() {
|
|
172692
|
-
return
|
|
172824
|
+
return getDb13(this.injectedDb);
|
|
172693
172825
|
}
|
|
172694
172826
|
async listCards(assistantId) {
|
|
172695
172827
|
const rows = this.db().query("SELECT * FROM wallet_cards WHERE assistant_id = ? ORDER BY created_at DESC").all(assistantId);
|
|
@@ -173537,7 +173669,7 @@ var init_secrets_client2 = __esm(() => {
|
|
|
173537
173669
|
});
|
|
173538
173670
|
|
|
173539
173671
|
// packages/core/src/secrets/storage/local-client.ts
|
|
173540
|
-
function
|
|
173672
|
+
function getDb14(injected) {
|
|
173541
173673
|
if (injected)
|
|
173542
173674
|
return injected;
|
|
173543
173675
|
return getDatabase();
|
|
@@ -173549,7 +173681,7 @@ class LocalSecretsClient {
|
|
|
173549
173681
|
this.injectedDb = options.db;
|
|
173550
173682
|
}
|
|
173551
173683
|
db() {
|
|
173552
|
-
return
|
|
173684
|
+
return getDb14(this.injectedDb);
|
|
173553
173685
|
}
|
|
173554
173686
|
async listSecrets(scope, assistantId) {
|
|
173555
173687
|
const items = [];
|
|
@@ -174114,7 +174246,7 @@ var init_secrets = __esm(async () => {
|
|
|
174114
174246
|
function getMessagesBasePath() {
|
|
174115
174247
|
return "";
|
|
174116
174248
|
}
|
|
174117
|
-
function
|
|
174249
|
+
function getDb15(injected) {
|
|
174118
174250
|
if (injected)
|
|
174119
174251
|
return injected;
|
|
174120
174252
|
return getDatabase();
|
|
@@ -174163,7 +174295,7 @@ class LocalMessagesStorage {
|
|
|
174163
174295
|
this.injectedDb = options.db;
|
|
174164
174296
|
}
|
|
174165
174297
|
db() {
|
|
174166
|
-
return
|
|
174298
|
+
return getDb15(this.injectedDb);
|
|
174167
174299
|
}
|
|
174168
174300
|
async ensureDirectories(_assistantId) {}
|
|
174169
174301
|
async loadRegistry() {
|
|
@@ -174410,8 +174542,8 @@ var init_local_storage = __esm(async () => {
|
|
|
174410
174542
|
});
|
|
174411
174543
|
|
|
174412
174544
|
// packages/core/src/messages/watcher.ts
|
|
174413
|
-
import { watch, existsSync as
|
|
174414
|
-
import { join as
|
|
174545
|
+
import { watch, existsSync as existsSync23, readdirSync as readdirSync8 } from "fs";
|
|
174546
|
+
import { join as join35 } from "path";
|
|
174415
174547
|
|
|
174416
174548
|
class InboxWatcher {
|
|
174417
174549
|
assistantId;
|
|
@@ -174423,14 +174555,14 @@ class InboxWatcher {
|
|
|
174423
174555
|
constructor(assistantId, basePath) {
|
|
174424
174556
|
this.assistantId = assistantId;
|
|
174425
174557
|
const base = basePath || getMessagesBasePath();
|
|
174426
|
-
this.inboxPath =
|
|
174558
|
+
this.inboxPath = join35(base, assistantId, "messages");
|
|
174427
174559
|
}
|
|
174428
174560
|
start() {
|
|
174429
174561
|
if (this.running)
|
|
174430
174562
|
return;
|
|
174431
174563
|
this.running = true;
|
|
174432
174564
|
this.snapshotExisting();
|
|
174433
|
-
if (!
|
|
174565
|
+
if (!existsSync23(this.inboxPath)) {
|
|
174434
174566
|
this.pollForDirectory();
|
|
174435
174567
|
return;
|
|
174436
174568
|
}
|
|
@@ -174455,8 +174587,8 @@ class InboxWatcher {
|
|
|
174455
174587
|
}
|
|
174456
174588
|
snapshotExisting() {
|
|
174457
174589
|
try {
|
|
174458
|
-
if (
|
|
174459
|
-
const files =
|
|
174590
|
+
if (existsSync23(this.inboxPath)) {
|
|
174591
|
+
const files = readdirSync8(this.inboxPath);
|
|
174460
174592
|
for (const file of files) {
|
|
174461
174593
|
if (file.endsWith(".json")) {
|
|
174462
174594
|
this.knownFiles.add(file);
|
|
@@ -174498,7 +174630,7 @@ class InboxWatcher {
|
|
|
174498
174630
|
clearInterval(interval);
|
|
174499
174631
|
return;
|
|
174500
174632
|
}
|
|
174501
|
-
if (
|
|
174633
|
+
if (existsSync23(this.inboxPath)) {
|
|
174502
174634
|
clearInterval(interval);
|
|
174503
174635
|
this.snapshotExisting();
|
|
174504
174636
|
this.startWatching();
|
|
@@ -175203,7 +175335,7 @@ var init_messages5 = __esm(async () => {
|
|
|
175203
175335
|
function getWebhooksBasePath() {
|
|
175204
175336
|
return "";
|
|
175205
175337
|
}
|
|
175206
|
-
function
|
|
175338
|
+
function getDb16(injected) {
|
|
175207
175339
|
if (injected)
|
|
175208
175340
|
return injected;
|
|
175209
175341
|
return getDatabase();
|
|
@@ -175266,7 +175398,7 @@ class LocalWebhookStorage {
|
|
|
175266
175398
|
this.injectedDb = options.db;
|
|
175267
175399
|
}
|
|
175268
175400
|
db() {
|
|
175269
|
-
return
|
|
175401
|
+
return getDb16(this.injectedDb);
|
|
175270
175402
|
}
|
|
175271
175403
|
async ensureDirectories(_webhookId) {}
|
|
175272
175404
|
async loadIndex() {
|
|
@@ -175400,8 +175532,8 @@ var init_local_storage2 = __esm(async () => {
|
|
|
175400
175532
|
});
|
|
175401
175533
|
|
|
175402
175534
|
// packages/core/src/webhooks/watcher.ts
|
|
175403
|
-
import { watch as watch2, existsSync as
|
|
175404
|
-
import { join as
|
|
175535
|
+
import { watch as watch2, existsSync as existsSync24, readdirSync as readdirSync9 } from "fs";
|
|
175536
|
+
import { join as join36 } from "path";
|
|
175405
175537
|
|
|
175406
175538
|
class WebhookEventWatcher {
|
|
175407
175539
|
basePath;
|
|
@@ -175413,13 +175545,13 @@ class WebhookEventWatcher {
|
|
|
175413
175545
|
directoryWatcher = null;
|
|
175414
175546
|
constructor(basePath) {
|
|
175415
175547
|
this.basePath = basePath || getWebhooksBasePath();
|
|
175416
|
-
this.eventsPath =
|
|
175548
|
+
this.eventsPath = join36(this.basePath, "events");
|
|
175417
175549
|
}
|
|
175418
175550
|
start() {
|
|
175419
175551
|
if (this.running)
|
|
175420
175552
|
return;
|
|
175421
175553
|
this.running = true;
|
|
175422
|
-
if (!
|
|
175554
|
+
if (!existsSync24(this.eventsPath)) {
|
|
175423
175555
|
this.pollForDirectory();
|
|
175424
175556
|
return;
|
|
175425
175557
|
}
|
|
@@ -175452,8 +175584,8 @@ class WebhookEventWatcher {
|
|
|
175452
175584
|
this.directoryWatcher = watch2(this.eventsPath, (eventType, filename) => {
|
|
175453
175585
|
if (!filename || eventType !== "rename")
|
|
175454
175586
|
return;
|
|
175455
|
-
const dirPath =
|
|
175456
|
-
if (
|
|
175587
|
+
const dirPath = join36(this.eventsPath, filename);
|
|
175588
|
+
if (existsSync24(dirPath) && !this.watchers.has(filename)) {
|
|
175457
175589
|
this.watchWebhookDir(filename);
|
|
175458
175590
|
}
|
|
175459
175591
|
});
|
|
@@ -175469,7 +175601,7 @@ class WebhookEventWatcher {
|
|
|
175469
175601
|
});
|
|
175470
175602
|
} catch {}
|
|
175471
175603
|
try {
|
|
175472
|
-
const dirs =
|
|
175604
|
+
const dirs = readdirSync9(this.eventsPath);
|
|
175473
175605
|
for (const dir of dirs) {
|
|
175474
175606
|
this.watchWebhookDir(dir);
|
|
175475
175607
|
}
|
|
@@ -175478,12 +175610,12 @@ class WebhookEventWatcher {
|
|
|
175478
175610
|
watchWebhookDir(webhookId) {
|
|
175479
175611
|
if (this.watchers.has(webhookId))
|
|
175480
175612
|
return;
|
|
175481
|
-
const dirPath =
|
|
175482
|
-
if (!
|
|
175613
|
+
const dirPath = join36(this.eventsPath, webhookId);
|
|
175614
|
+
if (!existsSync24(dirPath))
|
|
175483
175615
|
return;
|
|
175484
175616
|
const known = new Set;
|
|
175485
175617
|
try {
|
|
175486
|
-
const files =
|
|
175618
|
+
const files = readdirSync9(dirPath);
|
|
175487
175619
|
for (const file of files) {
|
|
175488
175620
|
if (file.endsWith(".json") && file !== "index.json") {
|
|
175489
175621
|
known.add(file);
|
|
@@ -175523,7 +175655,7 @@ class WebhookEventWatcher {
|
|
|
175523
175655
|
clearInterval(interval);
|
|
175524
175656
|
return;
|
|
175525
175657
|
}
|
|
175526
|
-
if (
|
|
175658
|
+
if (existsSync24(this.eventsPath)) {
|
|
175527
175659
|
clearInterval(interval);
|
|
175528
175660
|
this.startWatchingAll();
|
|
175529
175661
|
}
|
|
@@ -176845,17 +176977,17 @@ import { spawn as spawn4 } from "child_process";
|
|
|
176845
176977
|
import { createInterface } from "readline";
|
|
176846
176978
|
import * as fs4 from "fs";
|
|
176847
176979
|
import { stat as statPromise, open as open2 } from "fs/promises";
|
|
176848
|
-
import { join as
|
|
176849
|
-
import { homedir as
|
|
176850
|
-
import { dirname as
|
|
176980
|
+
import { join as join37 } from "path";
|
|
176981
|
+
import { homedir as homedir18 } from "os";
|
|
176982
|
+
import { dirname as dirname14, join as join210 } from "path";
|
|
176851
176983
|
import { cwd } from "process";
|
|
176852
176984
|
import { realpathSync as realpathSync2 } from "fs";
|
|
176853
176985
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
176854
176986
|
import { randomUUID as randomUUID22 } from "crypto";
|
|
176855
|
-
import { appendFileSync as appendFileSync22, existsSync as
|
|
176856
|
-
import { join as
|
|
176987
|
+
import { appendFileSync as appendFileSync22, existsSync as existsSync26, mkdirSync as mkdirSync22 } from "fs";
|
|
176988
|
+
import { join as join38 } from "path";
|
|
176857
176989
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
176858
|
-
import { join as
|
|
176990
|
+
import { join as join42 } from "path";
|
|
176859
176991
|
import { fileURLToPath } from "url";
|
|
176860
176992
|
function createAbortController(maxListeners = DEFAULT_MAX_LISTENERS) {
|
|
176861
176993
|
const controller = new AbortController;
|
|
@@ -177130,7 +177262,7 @@ function shouldShowDebugMessage(message, filter) {
|
|
|
177130
177262
|
return shouldShowDebugCategories(categories, filter);
|
|
177131
177263
|
}
|
|
177132
177264
|
function getClaudeConfigHomeDir() {
|
|
177133
|
-
return process.env.CLAUDE_CONFIG_DIR ??
|
|
177265
|
+
return process.env.CLAUDE_CONFIG_DIR ?? join37(homedir18(), ".claude");
|
|
177134
177266
|
}
|
|
177135
177267
|
function isEnvTruthy(envVar) {
|
|
177136
177268
|
if (!envVar)
|
|
@@ -177345,8 +177477,8 @@ function getDebugWriter() {
|
|
|
177345
177477
|
debugWriter = createBufferedWriter({
|
|
177346
177478
|
writeFn: (content) => {
|
|
177347
177479
|
const path3 = getDebugLogPath();
|
|
177348
|
-
if (!getFsImplementation().existsSync(
|
|
177349
|
-
getFsImplementation().mkdirSync(
|
|
177480
|
+
if (!getFsImplementation().existsSync(dirname14(path3))) {
|
|
177481
|
+
getFsImplementation().mkdirSync(dirname14(path3));
|
|
177350
177482
|
}
|
|
177351
177483
|
getFsImplementation().appendFileSync(path3, content);
|
|
177352
177484
|
updateLatestDebugLogSymlink();
|
|
@@ -177407,9 +177539,9 @@ function getOrCreateDebugFile() {
|
|
|
177407
177539
|
if (!process.env.DEBUG_CLAUDE_AGENT_SDK) {
|
|
177408
177540
|
return null;
|
|
177409
177541
|
}
|
|
177410
|
-
const debugDir =
|
|
177411
|
-
debugFilePath =
|
|
177412
|
-
if (!
|
|
177542
|
+
const debugDir = join38(getClaudeConfigHomeDir(), "debug");
|
|
177543
|
+
debugFilePath = join38(debugDir, `sdk-${randomUUID22()}.txt`);
|
|
177544
|
+
if (!existsSync26(debugDir)) {
|
|
177413
177545
|
mkdirSync22(debugDir, { recursive: true });
|
|
177414
177546
|
}
|
|
177415
177547
|
process.stderr.write(`SDK debug logs: ${debugFilePath}
|
|
@@ -190767,7 +190899,7 @@ var init_sdk2 = __esm(() => {
|
|
|
190767
190899
|
}
|
|
190768
190900
|
try {
|
|
190769
190901
|
const debugLogPath = getDebugLogPath();
|
|
190770
|
-
const debugLogsDir =
|
|
190902
|
+
const debugLogsDir = dirname14(debugLogPath);
|
|
190771
190903
|
const latestSymlinkPath = join210(debugLogsDir, "latest");
|
|
190772
190904
|
if (!getFsImplementation().existsSync(debugLogsDir)) {
|
|
190773
190905
|
getFsImplementation().mkdirSync(debugLogsDir);
|
|
@@ -191465,8 +191597,8 @@ var init_sdk2 = __esm(() => {
|
|
|
191465
191597
|
let pathToClaudeCodeExecutable = options.pathToClaudeCodeExecutable;
|
|
191466
191598
|
if (!pathToClaudeCodeExecutable) {
|
|
191467
191599
|
const filename = fileURLToPath(import.meta.url);
|
|
191468
|
-
const dirname22 =
|
|
191469
|
-
pathToClaudeCodeExecutable =
|
|
191600
|
+
const dirname22 = join42(filename, "..");
|
|
191601
|
+
pathToClaudeCodeExecutable = join42(dirname22, "cli.js");
|
|
191470
191602
|
}
|
|
191471
191603
|
const processEnv = { ...options.env ?? process.env };
|
|
191472
191604
|
if (!processEnv.CLAUDE_CODE_ENTRYPOINT) {
|
|
@@ -199677,45 +199809,50 @@ var init_channels = __esm(async () => {
|
|
|
199677
199809
|
});
|
|
199678
199810
|
|
|
199679
199811
|
// packages/core/src/people/store.ts
|
|
199680
|
-
|
|
199681
|
-
|
|
199682
|
-
import { join as join44 } from "path";
|
|
199683
|
-
function isValidId5(id) {
|
|
199684
|
-
return typeof id === "string" && id.length > 0 && SAFE_ID_PATTERN6.test(id);
|
|
199812
|
+
function getDb17() {
|
|
199813
|
+
return getDatabase();
|
|
199685
199814
|
}
|
|
199686
|
-
function
|
|
199687
|
-
|
|
199688
|
-
|
|
199815
|
+
function rowToPerson(row) {
|
|
199816
|
+
const person = {
|
|
199817
|
+
id: row.id,
|
|
199818
|
+
name: row.name,
|
|
199819
|
+
status: "active",
|
|
199820
|
+
createdAt: new Date(row.created_at).toISOString(),
|
|
199821
|
+
updatedAt: new Date(row.updated_at).toISOString()
|
|
199822
|
+
};
|
|
199823
|
+
if (row.email)
|
|
199824
|
+
person.email = row.email;
|
|
199825
|
+
if (row.avatar_url)
|
|
199826
|
+
person.avatar = row.avatar_url;
|
|
199827
|
+
if (row.metadata) {
|
|
199828
|
+
try {
|
|
199829
|
+
const meta = JSON.parse(row.metadata);
|
|
199830
|
+
if (meta.status)
|
|
199831
|
+
person.status = meta.status;
|
|
199832
|
+
if (meta.defaultIdentityId)
|
|
199833
|
+
person.defaultIdentityId = meta.defaultIdentityId;
|
|
199834
|
+
} catch {}
|
|
199689
199835
|
}
|
|
199836
|
+
return person;
|
|
199690
199837
|
}
|
|
199691
199838
|
|
|
199692
199839
|
class PeopleStore {
|
|
199693
|
-
basePath;
|
|
199694
199840
|
people = new Map;
|
|
199695
199841
|
activeId = null;
|
|
199696
|
-
|
|
199697
|
-
|
|
199698
|
-
|
|
199699
|
-
get indexPath() {
|
|
199700
|
-
return join44(this.basePath, "index.json");
|
|
199701
|
-
}
|
|
199702
|
-
get activePath() {
|
|
199703
|
-
return join44(this.basePath, "active.json");
|
|
199704
|
-
}
|
|
199705
|
-
personConfigPath(id) {
|
|
199706
|
-
validateId3(id);
|
|
199707
|
-
return join44(this.basePath, id, "config.json");
|
|
199842
|
+
db;
|
|
199843
|
+
constructor(db) {
|
|
199844
|
+
this.db = db || getDb17();
|
|
199708
199845
|
}
|
|
199709
199846
|
async initialize() {
|
|
199710
|
-
|
|
199711
|
-
const
|
|
199712
|
-
|
|
199713
|
-
|
|
199714
|
-
|
|
199715
|
-
|
|
199716
|
-
}
|
|
199847
|
+
const rows = this.db.query("SELECT * FROM people").all();
|
|
199848
|
+
for (const row of rows) {
|
|
199849
|
+
try {
|
|
199850
|
+
const person = rowToPerson(row);
|
|
199851
|
+
this.people.set(person.id, person);
|
|
199852
|
+
} catch {}
|
|
199717
199853
|
}
|
|
199718
|
-
this.
|
|
199854
|
+
const activeRow = this.db.query("SELECT person_id FROM people_active WHERE key = 'active'").get();
|
|
199855
|
+
this.activeId = activeRow?.person_id || null;
|
|
199719
199856
|
}
|
|
199720
199857
|
async create(name2, email2, avatar) {
|
|
199721
199858
|
const id = `person_${generateId().slice(0, 12)}`;
|
|
@@ -199729,9 +199866,8 @@ class PeopleStore {
|
|
|
199729
199866
|
createdAt: now2,
|
|
199730
199867
|
updatedAt: now2
|
|
199731
199868
|
};
|
|
199732
|
-
|
|
199869
|
+
this.persistPerson(person);
|
|
199733
199870
|
this.people.set(id, person);
|
|
199734
|
-
await this.appendToIndex(id);
|
|
199735
199871
|
return person;
|
|
199736
199872
|
}
|
|
199737
199873
|
async update(id, updates) {
|
|
@@ -199746,18 +199882,13 @@ class PeopleStore {
|
|
|
199746
199882
|
createdAt: existing.createdAt,
|
|
199747
199883
|
updatedAt: new Date().toISOString()
|
|
199748
199884
|
};
|
|
199749
|
-
|
|
199885
|
+
this.persistPerson(updated);
|
|
199750
199886
|
this.people.set(id, updated);
|
|
199751
199887
|
return updated;
|
|
199752
199888
|
}
|
|
199753
199889
|
async delete(id) {
|
|
199754
|
-
|
|
199755
|
-
const dir = join44(this.basePath, id);
|
|
199756
|
-
if (existsSync31(dir)) {
|
|
199757
|
-
await rm5(dir, { recursive: true });
|
|
199758
|
-
}
|
|
199890
|
+
this.db.prepare("DELETE FROM people WHERE id = ?").run(id);
|
|
199759
199891
|
this.people.delete(id);
|
|
199760
|
-
await this.removeFromIndex(id);
|
|
199761
199892
|
if (this.activeId === id) {
|
|
199762
199893
|
await this.setActive(null);
|
|
199763
199894
|
}
|
|
@@ -199802,66 +199933,28 @@ class PeopleStore {
|
|
|
199802
199933
|
}
|
|
199803
199934
|
}
|
|
199804
199935
|
this.activeId = id;
|
|
199805
|
-
|
|
199806
|
-
|
|
199807
|
-
}
|
|
199808
|
-
|
|
199809
|
-
async readIndex() {
|
|
199810
|
-
try {
|
|
199811
|
-
if (existsSync31(this.indexPath)) {
|
|
199812
|
-
const data = await readFile11(this.indexPath, "utf-8");
|
|
199813
|
-
return JSON.parse(data);
|
|
199814
|
-
}
|
|
199815
|
-
} catch {}
|
|
199816
|
-
return { people: [] };
|
|
199817
|
-
}
|
|
199818
|
-
async writeIndex(index) {
|
|
199819
|
-
await writeFile9(this.indexPath, JSON.stringify(index, null, 2));
|
|
199820
|
-
}
|
|
199821
|
-
async appendToIndex(id) {
|
|
199822
|
-
const index = await this.readIndex();
|
|
199823
|
-
if (!index.people.includes(id)) {
|
|
199824
|
-
index.people.push(id);
|
|
199825
|
-
await this.writeIndex(index);
|
|
199936
|
+
if (id) {
|
|
199937
|
+
this.db.prepare("INSERT OR REPLACE INTO people_active (key, person_id) VALUES ('active', ?)").run(id);
|
|
199938
|
+
} else {
|
|
199939
|
+
this.db.prepare("DELETE FROM people_active WHERE key = 'active'").run();
|
|
199826
199940
|
}
|
|
199827
199941
|
}
|
|
199828
|
-
|
|
199829
|
-
const
|
|
199830
|
-
|
|
199831
|
-
|
|
199832
|
-
|
|
199833
|
-
|
|
199834
|
-
|
|
199835
|
-
|
|
199836
|
-
|
|
199837
|
-
|
|
199838
|
-
|
|
199839
|
-
}
|
|
199840
|
-
} catch {}
|
|
199841
|
-
return null;
|
|
199842
|
-
}
|
|
199843
|
-
async readPerson(id) {
|
|
199844
|
-
try {
|
|
199845
|
-
validateId3(id);
|
|
199846
|
-
const configPath = this.personConfigPath(id);
|
|
199847
|
-
if (existsSync31(configPath)) {
|
|
199848
|
-
const data = await readFile11(configPath, "utf-8");
|
|
199849
|
-
return JSON.parse(data);
|
|
199850
|
-
}
|
|
199851
|
-
} catch {}
|
|
199852
|
-
return null;
|
|
199853
|
-
}
|
|
199854
|
-
async persist(person) {
|
|
199855
|
-
const dir = join44(this.basePath, person.id);
|
|
199856
|
-
await mkdir10(dir, { recursive: true });
|
|
199857
|
-
await writeFile9(this.personConfigPath(person.id), JSON.stringify(person, null, 2));
|
|
199942
|
+
persistPerson(person) {
|
|
199943
|
+
const nowMs = new Date(person.updatedAt).getTime();
|
|
199944
|
+
const createdMs = new Date(person.createdAt).getTime();
|
|
199945
|
+
const metadata = {};
|
|
199946
|
+
if (person.status !== "active")
|
|
199947
|
+
metadata.status = person.status;
|
|
199948
|
+
if (person.defaultIdentityId)
|
|
199949
|
+
metadata.defaultIdentityId = person.defaultIdentityId;
|
|
199950
|
+
const metadataStr = Object.keys(metadata).length > 0 ? JSON.stringify(metadata) : null;
|
|
199951
|
+
this.db.prepare(`INSERT OR REPLACE INTO people (id, name, email, phone, role, notes, avatar_url, metadata, created_at, updated_at)
|
|
199952
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(person.id, person.name, person.email || null, null, null, null, person.avatar || null, metadataStr, createdMs, nowMs);
|
|
199858
199953
|
}
|
|
199859
199954
|
}
|
|
199860
|
-
var SAFE_ID_PATTERN6;
|
|
199861
199955
|
var init_store8 = __esm(async () => {
|
|
199862
199956
|
init_src2();
|
|
199863
|
-
await
|
|
199864
|
-
SAFE_ID_PATTERN6 = /^[a-zA-Z0-9_-]+$/;
|
|
199957
|
+
await init_database();
|
|
199865
199958
|
});
|
|
199866
199959
|
|
|
199867
199960
|
// packages/core/src/people/manager.ts
|
|
@@ -204403,7 +204496,7 @@ var init_contacts = __esm(async () => {
|
|
|
204403
204496
|
});
|
|
204404
204497
|
|
|
204405
204498
|
// packages/core/src/sessions/store.ts
|
|
204406
|
-
function
|
|
204499
|
+
function rowToSession2(row) {
|
|
204407
204500
|
return {
|
|
204408
204501
|
id: row.id,
|
|
204409
204502
|
cwd: row.cwd,
|
|
@@ -204429,7 +204522,7 @@ class SessionStore {
|
|
|
204429
204522
|
load(id) {
|
|
204430
204523
|
try {
|
|
204431
204524
|
const row = this.db.query("SELECT * FROM persisted_sessions WHERE id = ?").get(id);
|
|
204432
|
-
return row ?
|
|
204525
|
+
return row ? rowToSession2(row) : null;
|
|
204433
204526
|
} catch {
|
|
204434
204527
|
return null;
|
|
204435
204528
|
}
|
|
@@ -204437,7 +204530,7 @@ class SessionStore {
|
|
|
204437
204530
|
list() {
|
|
204438
204531
|
try {
|
|
204439
204532
|
const rows = this.db.query("SELECT * FROM persisted_sessions ORDER BY updated_at DESC").all();
|
|
204440
|
-
return rows.map(
|
|
204533
|
+
return rows.map(rowToSession2);
|
|
204441
204534
|
} catch {
|
|
204442
204535
|
return [];
|
|
204443
204536
|
}
|
|
@@ -204450,7 +204543,7 @@ class SessionStore {
|
|
|
204450
204543
|
listRecoverable() {
|
|
204451
204544
|
try {
|
|
204452
204545
|
const rows = this.db.query(`SELECT * FROM persisted_sessions WHERE status != 'closed' ORDER BY updated_at DESC`).all();
|
|
204453
|
-
return rows.map(
|
|
204546
|
+
return rows.map(rowToSession2);
|
|
204454
204547
|
} catch {
|
|
204455
204548
|
return [];
|
|
204456
204549
|
}
|
|
@@ -205032,9 +205125,9 @@ var init_tools15 = __esm(() => {
|
|
|
205032
205125
|
|
|
205033
205126
|
// packages/core/src/sessions/index.ts
|
|
205034
205127
|
var init_sessions3 = __esm(async () => {
|
|
205035
|
-
init_verification();
|
|
205036
205128
|
init_tools15();
|
|
205037
205129
|
await __promiseAll([
|
|
205130
|
+
init_verification(),
|
|
205038
205131
|
init_store12(),
|
|
205039
205132
|
init_registry3()
|
|
205040
205133
|
]);
|
|
@@ -206112,7 +206205,7 @@ function createSelfAwarenessToolExecutors(context) {
|
|
|
206112
206205
|
workspace_map: async (input) => {
|
|
206113
206206
|
const { readdir: readdir2, stat: stat5, access } = await import("fs/promises");
|
|
206114
206207
|
const { execSync } = await import("child_process");
|
|
206115
|
-
const { join:
|
|
206208
|
+
const { join: join39, basename: basename7 } = await import("path");
|
|
206116
206209
|
const depth = input.depth ?? 3;
|
|
206117
206210
|
const includeGitStatus = input.include_git_status !== false;
|
|
206118
206211
|
const includeRecentFiles = input.include_recent_files !== false;
|
|
@@ -206158,7 +206251,7 @@ function createSelfAwarenessToolExecutors(context) {
|
|
|
206158
206251
|
break;
|
|
206159
206252
|
}
|
|
206160
206253
|
if (entry.isDirectory()) {
|
|
206161
|
-
const children2 = await buildTree(
|
|
206254
|
+
const children2 = await buildTree(join39(dir, entry.name), currentDepth + 1);
|
|
206162
206255
|
nodes.push({
|
|
206163
206256
|
name: entry.name,
|
|
206164
206257
|
type: "directory",
|
|
@@ -206184,7 +206277,7 @@ function createSelfAwarenessToolExecutors(context) {
|
|
|
206184
206277
|
};
|
|
206185
206278
|
if (includeGitStatus) {
|
|
206186
206279
|
try {
|
|
206187
|
-
await access(
|
|
206280
|
+
await access(join39(cwd2, ".git"));
|
|
206188
206281
|
gitStatus.isRepo = true;
|
|
206189
206282
|
try {
|
|
206190
206283
|
const branch = execSync("git branch --show-current", { cwd: cwd2, encoding: "utf-8" }).trim();
|
|
@@ -206215,7 +206308,7 @@ function createSelfAwarenessToolExecutors(context) {
|
|
|
206215
206308
|
for (const entry of entries) {
|
|
206216
206309
|
if (shouldIgnore(entry.name))
|
|
206217
206310
|
continue;
|
|
206218
|
-
const fullPath =
|
|
206311
|
+
const fullPath = join39(dir, entry.name);
|
|
206219
206312
|
const relPath = relativePath ? `${relativePath}/${entry.name}` : entry.name;
|
|
206220
206313
|
if (entry.isFile()) {
|
|
206221
206314
|
try {
|
|
@@ -206249,12 +206342,12 @@ function createSelfAwarenessToolExecutors(context) {
|
|
|
206249
206342
|
let projectName = basename7(cwd2);
|
|
206250
206343
|
for (const indicator of projectIndicators) {
|
|
206251
206344
|
try {
|
|
206252
|
-
await access(
|
|
206345
|
+
await access(join39(cwd2, indicator.file));
|
|
206253
206346
|
projectType = indicator.type;
|
|
206254
206347
|
if (indicator.file === "package.json") {
|
|
206255
206348
|
try {
|
|
206256
|
-
const { readFile:
|
|
206257
|
-
const pkg = JSON.parse(await
|
|
206349
|
+
const { readFile: readFile9 } = await import("fs/promises");
|
|
206350
|
+
const pkg = JSON.parse(await readFile9(join39(cwd2, indicator.file), "utf-8"));
|
|
206258
206351
|
projectName = pkg.name || projectName;
|
|
206259
206352
|
} catch {}
|
|
206260
206353
|
}
|
|
@@ -211036,7 +211129,7 @@ var init_capabilities2 = __esm(async () => {
|
|
|
211036
211129
|
});
|
|
211037
211130
|
|
|
211038
211131
|
// packages/core/src/agent/loop.ts
|
|
211039
|
-
import { join as
|
|
211132
|
+
import { join as join39 } from "path";
|
|
211040
211133
|
function parseErrorCode(message) {
|
|
211041
211134
|
const index = message.indexOf(":");
|
|
211042
211135
|
if (index === -1)
|
|
@@ -211068,7 +211161,6 @@ var init_loop = __esm(async () => {
|
|
|
211068
211161
|
init_limits();
|
|
211069
211162
|
init_llm_response();
|
|
211070
211163
|
init_manager4();
|
|
211071
|
-
init_identity2();
|
|
211072
211164
|
init_self_awareness();
|
|
211073
211165
|
init_memory2();
|
|
211074
211166
|
init_agents();
|
|
@@ -211078,8 +211170,6 @@ var init_loop = __esm(async () => {
|
|
|
211078
211170
|
init_swarm2();
|
|
211079
211171
|
init_coordinator();
|
|
211080
211172
|
init_subagent_manager();
|
|
211081
|
-
init_budget();
|
|
211082
|
-
init_registry2();
|
|
211083
211173
|
await __promiseAll([
|
|
211084
211174
|
init_registry(),
|
|
211085
211175
|
init_connector(),
|
|
@@ -211108,6 +211198,7 @@ var init_loop = __esm(async () => {
|
|
|
211108
211198
|
init_energy2(),
|
|
211109
211199
|
init_store3(),
|
|
211110
211200
|
init_auto_refresh(),
|
|
211201
|
+
init_identity2(),
|
|
211111
211202
|
init_inbox(),
|
|
211112
211203
|
init_wallet(),
|
|
211113
211204
|
init_secrets(),
|
|
@@ -211123,7 +211214,9 @@ var init_loop = __esm(async () => {
|
|
|
211123
211214
|
init_projects(),
|
|
211124
211215
|
init_tasks2(),
|
|
211125
211216
|
init_memory3(),
|
|
211217
|
+
init_budget(),
|
|
211126
211218
|
init_guardrails(),
|
|
211219
|
+
init_registry2(),
|
|
211127
211220
|
init_capabilities2()
|
|
211128
211221
|
]);
|
|
211129
211222
|
AssistantLoop = class AssistantLoop {
|
|
@@ -213752,8 +213845,8 @@ Current state: ${voiceState.enabled ? "enabled" : "disabled"}, STT: ${voiceState
|
|
|
213752
213845
|
return null;
|
|
213753
213846
|
const intervalMs = Math.max(1000, config2.heartbeat?.intervalMs ?? 15000);
|
|
213754
213847
|
const staleThresholdMs = Math.max(intervalMs * 2, config2.heartbeat?.staleThresholdMs ?? 120000);
|
|
213755
|
-
const persistPath = config2.heartbeat?.persistPath ??
|
|
213756
|
-
const historyPath = config2.heartbeat?.historyPath ??
|
|
213848
|
+
const persistPath = config2.heartbeat?.persistPath ?? join39(this.storageDir, "heartbeats", `${this.sessionId}.json`);
|
|
213849
|
+
const historyPath = config2.heartbeat?.historyPath ?? join39(this.storageDir, "heartbeats", "runs", `${this.sessionId}.jsonl`);
|
|
213757
213850
|
return {
|
|
213758
213851
|
intervalMs,
|
|
213759
213852
|
staleThresholdMs,
|
|
@@ -214134,9 +214227,9 @@ class StatsTracker {
|
|
|
214134
214227
|
}
|
|
214135
214228
|
|
|
214136
214229
|
// packages/core/src/tools/connector-index.ts
|
|
214137
|
-
import { join as
|
|
214138
|
-
import { homedir as
|
|
214139
|
-
import { existsSync as
|
|
214230
|
+
import { join as join41, dirname as dirname15 } from "path";
|
|
214231
|
+
import { homedir as homedir19 } from "os";
|
|
214232
|
+
import { existsSync as existsSync27, mkdirSync as mkdirSync15, writeFileSync as writeFileSync11, readFileSync as readFileSync15 } from "fs";
|
|
214140
214233
|
var TAG_KEYWORDS, INDEX_VERSION = 1, INDEX_TTL_MS, ConnectorIndex;
|
|
214141
214234
|
var init_connector_index = __esm(() => {
|
|
214142
214235
|
TAG_KEYWORDS = {
|
|
@@ -214170,18 +214263,18 @@ var init_connector_index = __esm(() => {
|
|
|
214170
214263
|
}
|
|
214171
214264
|
getHomeDir() {
|
|
214172
214265
|
const envHome = process.env.HOME || process.env.USERPROFILE;
|
|
214173
|
-
return envHome && envHome.trim().length > 0 ? envHome :
|
|
214266
|
+
return envHome && envHome.trim().length > 0 ? envHome : homedir19();
|
|
214174
214267
|
}
|
|
214175
214268
|
getCachePath() {
|
|
214176
|
-
return
|
|
214269
|
+
return join41(this.getHomeDir(), ".assistants", "cache", "connector-index.json");
|
|
214177
214270
|
}
|
|
214178
214271
|
loadDiskCache() {
|
|
214179
214272
|
ConnectorIndex.indexLoaded = true;
|
|
214180
214273
|
try {
|
|
214181
214274
|
const cachePath = this.getCachePath();
|
|
214182
|
-
if (!
|
|
214275
|
+
if (!existsSync27(cachePath))
|
|
214183
214276
|
return;
|
|
214184
|
-
const data = JSON.parse(
|
|
214277
|
+
const data = JSON.parse(readFileSync15(cachePath, "utf-8"));
|
|
214185
214278
|
if (data.version !== INDEX_VERSION)
|
|
214186
214279
|
return;
|
|
214187
214280
|
if (Date.now() - data.timestamp > INDEX_TTL_MS)
|
|
@@ -214195,16 +214288,16 @@ var init_connector_index = __esm(() => {
|
|
|
214195
214288
|
saveDiskCache() {
|
|
214196
214289
|
try {
|
|
214197
214290
|
const cachePath = this.getCachePath();
|
|
214198
|
-
const cacheDir =
|
|
214199
|
-
if (!
|
|
214200
|
-
|
|
214291
|
+
const cacheDir = dirname15(cachePath);
|
|
214292
|
+
if (!existsSync27(cacheDir)) {
|
|
214293
|
+
mkdirSync15(cacheDir, { recursive: true });
|
|
214201
214294
|
}
|
|
214202
214295
|
const data = {
|
|
214203
214296
|
version: INDEX_VERSION,
|
|
214204
214297
|
timestamp: Date.now(),
|
|
214205
214298
|
entries: Object.fromEntries(this.entries)
|
|
214206
214299
|
};
|
|
214207
|
-
|
|
214300
|
+
writeFileSync11(cachePath, JSON.stringify(data));
|
|
214208
214301
|
ConnectorIndex.indexCache = new Map(this.entries);
|
|
214209
214302
|
} catch {}
|
|
214210
214303
|
}
|
|
@@ -214776,17 +214869,17 @@ var init_interviews = __esm(async () => {
|
|
|
214776
214869
|
});
|
|
214777
214870
|
|
|
214778
214871
|
// packages/core/src/memory/sessions.ts
|
|
214779
|
-
import { join as
|
|
214780
|
-
import { existsSync as
|
|
214872
|
+
import { join as join43, dirname as dirname16 } from "path";
|
|
214873
|
+
import { existsSync as existsSync29, mkdirSync as mkdirSync16 } from "fs";
|
|
214781
214874
|
|
|
214782
214875
|
class SessionManager {
|
|
214783
214876
|
db;
|
|
214784
214877
|
constructor(dbPath, assistantId) {
|
|
214785
214878
|
const baseDir = getConfigDir();
|
|
214786
|
-
const path4 = dbPath || (assistantId ?
|
|
214787
|
-
const dir =
|
|
214788
|
-
if (!
|
|
214789
|
-
|
|
214879
|
+
const path4 = dbPath || (assistantId ? join43(baseDir, "assistants", assistantId, "memory.db") : join43(baseDir, "memory.db"));
|
|
214880
|
+
const dir = dirname16(path4);
|
|
214881
|
+
if (!existsSync29(dir)) {
|
|
214882
|
+
mkdirSync16(dir, { recursive: true });
|
|
214790
214883
|
}
|
|
214791
214884
|
const runtime = getRuntime();
|
|
214792
214885
|
this.db = runtime.openDatabase(path4);
|
|
@@ -214899,9 +214992,9 @@ var init_sessions4 = __esm(async () => {
|
|
|
214899
214992
|
]);
|
|
214900
214993
|
});
|
|
214901
214994
|
// packages/core/src/migration/validators.ts
|
|
214902
|
-
import { existsSync as
|
|
214995
|
+
import { existsSync as existsSync30 } from "fs";
|
|
214903
214996
|
function assertNoExistingTarget(targetPath) {
|
|
214904
|
-
if (
|
|
214997
|
+
if (existsSync30(targetPath)) {
|
|
214905
214998
|
throw new Error(`Target already exists at ${targetPath}`);
|
|
214906
214999
|
}
|
|
214907
215000
|
}
|
|
@@ -214919,7 +215012,7 @@ var init_scheduler2 = __esm(async () => {
|
|
|
214919
215012
|
});
|
|
214920
215013
|
|
|
214921
215014
|
// packages/core/src/history/storage.ts
|
|
214922
|
-
function
|
|
215015
|
+
function getDb18() {
|
|
214923
215016
|
return getDatabase();
|
|
214924
215017
|
}
|
|
214925
215018
|
function getHistoryPath() {
|
|
@@ -214927,7 +215020,7 @@ function getHistoryPath() {
|
|
|
214927
215020
|
}
|
|
214928
215021
|
async function loadHistory() {
|
|
214929
215022
|
try {
|
|
214930
|
-
const rows =
|
|
215023
|
+
const rows = getDb18().query(`SELECT command FROM command_history ORDER BY created_at ASC, id ASC LIMIT ${MAX_HISTORY_SIZE}`).all();
|
|
214931
215024
|
return rows.map((r6) => r6.command);
|
|
214932
215025
|
} catch {
|
|
214933
215026
|
return [];
|
|
@@ -214935,7 +215028,7 @@ async function loadHistory() {
|
|
|
214935
215028
|
}
|
|
214936
215029
|
async function saveHistory(history) {
|
|
214937
215030
|
try {
|
|
214938
|
-
const conn =
|
|
215031
|
+
const conn = getDb18();
|
|
214939
215032
|
const trimmed = history.slice(-MAX_HISTORY_SIZE);
|
|
214940
215033
|
conn.transaction(() => {
|
|
214941
215034
|
conn.exec("DELETE FROM command_history");
|
|
@@ -214951,7 +215044,7 @@ async function appendToHistory(command) {
|
|
|
214951
215044
|
if (!command.trim())
|
|
214952
215045
|
return;
|
|
214953
215046
|
try {
|
|
214954
|
-
const conn =
|
|
215047
|
+
const conn = getDb18();
|
|
214955
215048
|
conn.prepare("INSERT INTO command_history (command, created_at) VALUES (?, ?)").run(command, Date.now());
|
|
214956
215049
|
const countRow = conn.query("SELECT COUNT(*) as cnt FROM command_history").get();
|
|
214957
215050
|
if (countRow && countRow.cnt > MAX_HISTORY_SIZE) {
|
|
@@ -215778,12 +215871,10 @@ var init_src3 = __esm(async () => {
|
|
|
215778
215871
|
init_loader();
|
|
215779
215872
|
init_native();
|
|
215780
215873
|
init_scope_context();
|
|
215781
|
-
init_verification();
|
|
215782
215874
|
init_injector();
|
|
215783
215875
|
init_types11();
|
|
215784
215876
|
init_memory2();
|
|
215785
215877
|
init_voice();
|
|
215786
|
-
init_budget();
|
|
215787
215878
|
init_manager4();
|
|
215788
215879
|
init_player();
|
|
215789
215880
|
init_recorder();
|
|
@@ -215820,10 +215911,12 @@ var init_src3 = __esm(async () => {
|
|
|
215820
215911
|
init_store2(),
|
|
215821
215912
|
init_tester(),
|
|
215822
215913
|
init_logger3(),
|
|
215914
|
+
init_verification(),
|
|
215823
215915
|
init_interviews(),
|
|
215824
215916
|
init_store13(),
|
|
215825
215917
|
init_sessions4(),
|
|
215826
215918
|
init_global_memory(),
|
|
215919
|
+
init_budget(),
|
|
215827
215920
|
init_config(),
|
|
215828
215921
|
init_client4(),
|
|
215829
215922
|
init_registry3(),
|
|
@@ -233654,14 +233747,14 @@ var require_filesystem = __commonJS((exports, module) => {
|
|
|
233654
233747
|
var LDD_PATH = "/usr/bin/ldd";
|
|
233655
233748
|
var SELF_PATH = "/proc/self/exe";
|
|
233656
233749
|
var MAX_LENGTH = 2048;
|
|
233657
|
-
var
|
|
233750
|
+
var readFileSync17 = (path4) => {
|
|
233658
233751
|
const fd = fs7.openSync(path4, "r");
|
|
233659
233752
|
const buffer = Buffer.alloc(MAX_LENGTH);
|
|
233660
233753
|
const bytesRead = fs7.readSync(fd, buffer, 0, MAX_LENGTH, 0);
|
|
233661
233754
|
fs7.close(fd, () => {});
|
|
233662
233755
|
return buffer.subarray(0, bytesRead);
|
|
233663
233756
|
};
|
|
233664
|
-
var
|
|
233757
|
+
var readFile9 = (path4) => new Promise((resolve6, reject) => {
|
|
233665
233758
|
fs7.open(path4, "r", (err, fd) => {
|
|
233666
233759
|
if (err) {
|
|
233667
233760
|
reject(err);
|
|
@@ -233677,8 +233770,8 @@ var require_filesystem = __commonJS((exports, module) => {
|
|
|
233677
233770
|
module.exports = {
|
|
233678
233771
|
LDD_PATH,
|
|
233679
233772
|
SELF_PATH,
|
|
233680
|
-
readFileSync:
|
|
233681
|
-
readFile:
|
|
233773
|
+
readFileSync: readFileSync17,
|
|
233774
|
+
readFile: readFile9
|
|
233682
233775
|
};
|
|
233683
233776
|
});
|
|
233684
233777
|
|
|
@@ -233720,7 +233813,7 @@ var require_elf = __commonJS((exports, module) => {
|
|
|
233720
233813
|
var require_detect_libc = __commonJS((exports, module) => {
|
|
233721
233814
|
var childProcess = __require("child_process");
|
|
233722
233815
|
var { isLinux: isLinux2, getReport } = require_process();
|
|
233723
|
-
var { LDD_PATH, SELF_PATH, readFile:
|
|
233816
|
+
var { LDD_PATH, SELF_PATH, readFile: readFile9, readFileSync: readFileSync17 } = require_filesystem();
|
|
233724
233817
|
var { interpreterPath } = require_elf();
|
|
233725
233818
|
var cachedFamilyInterpreter;
|
|
233726
233819
|
var cachedFamilyFilesystem;
|
|
@@ -233800,7 +233893,7 @@ var require_detect_libc = __commonJS((exports, module) => {
|
|
|
233800
233893
|
}
|
|
233801
233894
|
cachedFamilyFilesystem = null;
|
|
233802
233895
|
try {
|
|
233803
|
-
const lddContent = await
|
|
233896
|
+
const lddContent = await readFile9(LDD_PATH);
|
|
233804
233897
|
cachedFamilyFilesystem = getFamilyFromLddContent(lddContent);
|
|
233805
233898
|
} catch (e6) {}
|
|
233806
233899
|
return cachedFamilyFilesystem;
|
|
@@ -233811,7 +233904,7 @@ var require_detect_libc = __commonJS((exports, module) => {
|
|
|
233811
233904
|
}
|
|
233812
233905
|
cachedFamilyFilesystem = null;
|
|
233813
233906
|
try {
|
|
233814
|
-
const lddContent =
|
|
233907
|
+
const lddContent = readFileSync17(LDD_PATH);
|
|
233815
233908
|
cachedFamilyFilesystem = getFamilyFromLddContent(lddContent);
|
|
233816
233909
|
} catch (e6) {}
|
|
233817
233910
|
return cachedFamilyFilesystem;
|
|
@@ -233822,7 +233915,7 @@ var require_detect_libc = __commonJS((exports, module) => {
|
|
|
233822
233915
|
}
|
|
233823
233916
|
cachedFamilyInterpreter = null;
|
|
233824
233917
|
try {
|
|
233825
|
-
const selfContent = await
|
|
233918
|
+
const selfContent = await readFile9(SELF_PATH);
|
|
233826
233919
|
const path4 = interpreterPath(selfContent);
|
|
233827
233920
|
cachedFamilyInterpreter = familyFromInterpreterPath(path4);
|
|
233828
233921
|
} catch (e6) {}
|
|
@@ -233834,7 +233927,7 @@ var require_detect_libc = __commonJS((exports, module) => {
|
|
|
233834
233927
|
}
|
|
233835
233928
|
cachedFamilyInterpreter = null;
|
|
233836
233929
|
try {
|
|
233837
|
-
const selfContent =
|
|
233930
|
+
const selfContent = readFileSync17(SELF_PATH);
|
|
233838
233931
|
const path4 = interpreterPath(selfContent);
|
|
233839
233932
|
cachedFamilyInterpreter = familyFromInterpreterPath(path4);
|
|
233840
233933
|
} catch (e6) {}
|
|
@@ -233882,7 +233975,7 @@ var require_detect_libc = __commonJS((exports, module) => {
|
|
|
233882
233975
|
}
|
|
233883
233976
|
cachedVersionFilesystem = null;
|
|
233884
233977
|
try {
|
|
233885
|
-
const lddContent = await
|
|
233978
|
+
const lddContent = await readFile9(LDD_PATH);
|
|
233886
233979
|
const versionMatch = lddContent.match(RE_GLIBC_VERSION);
|
|
233887
233980
|
if (versionMatch) {
|
|
233888
233981
|
cachedVersionFilesystem = versionMatch[1];
|
|
@@ -233896,7 +233989,7 @@ var require_detect_libc = __commonJS((exports, module) => {
|
|
|
233896
233989
|
}
|
|
233897
233990
|
cachedVersionFilesystem = null;
|
|
233898
233991
|
try {
|
|
233899
|
-
const lddContent =
|
|
233992
|
+
const lddContent = readFileSync17(LDD_PATH);
|
|
233900
233993
|
const versionMatch = lddContent.match(RE_GLIBC_VERSION);
|
|
233901
233994
|
if (versionMatch) {
|
|
233902
233995
|
cachedVersionFilesystem = versionMatch[1];
|
|
@@ -241851,13 +241944,13 @@ async function appPath(appName) {
|
|
|
241851
241944
|
throw new TypeError("Please supply an app name or bundle identifier");
|
|
241852
241945
|
}
|
|
241853
241946
|
try {
|
|
241854
|
-
const { stdout } = await import_execa.default("./main", [appName], { cwd:
|
|
241947
|
+
const { stdout } = await import_execa.default("./main", [appName], { cwd: dirname17 });
|
|
241855
241948
|
return stdout;
|
|
241856
241949
|
} catch (error4) {
|
|
241857
241950
|
throw improveError(error4);
|
|
241858
241951
|
}
|
|
241859
241952
|
}
|
|
241860
|
-
var import_execa,
|
|
241953
|
+
var import_execa, dirname17, improveError = (error4) => {
|
|
241861
241954
|
if (error4.exitCode === 2) {
|
|
241862
241955
|
error4.message = "Couldn't find the app";
|
|
241863
241956
|
}
|
|
@@ -241865,7 +241958,7 @@ var import_execa, dirname20, improveError = (error4) => {
|
|
|
241865
241958
|
};
|
|
241866
241959
|
var init_app_path = __esm(() => {
|
|
241867
241960
|
import_execa = __toESM(require_execa(), 1);
|
|
241868
|
-
|
|
241961
|
+
dirname17 = path4.dirname(fileURLToPath5(import.meta.url));
|
|
241869
241962
|
appPath.sync = (appName) => {
|
|
241870
241963
|
if (process.platform !== "darwin") {
|
|
241871
241964
|
throw new Error("macOS only");
|
|
@@ -241874,7 +241967,7 @@ var init_app_path = __esm(() => {
|
|
|
241874
241967
|
throw new TypeError("Please supply an app name or bundle identifier");
|
|
241875
241968
|
}
|
|
241876
241969
|
try {
|
|
241877
|
-
return import_execa.default.sync("./main", [appName], { cwd:
|
|
241970
|
+
return import_execa.default.sync("./main", [appName], { cwd: dirname17 }).stdout;
|
|
241878
241971
|
} catch (error4) {
|
|
241879
241972
|
throw improveError(error4);
|
|
241880
241973
|
}
|
|
@@ -255193,8 +255286,8 @@ await __promiseAll([
|
|
|
255193
255286
|
]);
|
|
255194
255287
|
var import_react84 = __toESM(require_react(), 1);
|
|
255195
255288
|
import { spawn as spawn6 } from "child_process";
|
|
255196
|
-
import { join as
|
|
255197
|
-
import { homedir as
|
|
255289
|
+
import { join as join46 } from "path";
|
|
255290
|
+
import { homedir as homedir20 } from "os";
|
|
255198
255291
|
|
|
255199
255292
|
// packages/terminal/src/components/Input.tsx
|
|
255200
255293
|
await init_build2();
|
|
@@ -285892,8 +285985,8 @@ await init_src3();
|
|
|
285892
285985
|
// packages/terminal/src/lib/budgets.ts
|
|
285893
285986
|
init_src2();
|
|
285894
285987
|
await init_src3();
|
|
285895
|
-
import { join as
|
|
285896
|
-
import { mkdir as
|
|
285988
|
+
import { join as join45 } from "path";
|
|
285989
|
+
import { mkdir as mkdir9, readFile as readFile9, writeFile as writeFile8 } from "fs/promises";
|
|
285897
285990
|
var PROFILES_FILE = "budgets.json";
|
|
285898
285991
|
var SESSION_MAP_FILE = "budget-sessions.json";
|
|
285899
285992
|
var DEFAULT_PROFILE_ID = "default";
|
|
@@ -285901,22 +285994,22 @@ function cloneConfig2(config2) {
|
|
|
285901
285994
|
return JSON.parse(JSON.stringify(config2 || DEFAULT_BUDGET_CONFIG));
|
|
285902
285995
|
}
|
|
285903
285996
|
async function ensureDir(baseDir) {
|
|
285904
|
-
await
|
|
285997
|
+
await mkdir9(baseDir, { recursive: true });
|
|
285905
285998
|
}
|
|
285906
285999
|
async function readJsonFile(path6) {
|
|
285907
286000
|
try {
|
|
285908
|
-
const raw = await
|
|
286001
|
+
const raw = await readFile9(path6, "utf-8");
|
|
285909
286002
|
return JSON.parse(raw);
|
|
285910
286003
|
} catch {
|
|
285911
286004
|
return null;
|
|
285912
286005
|
}
|
|
285913
286006
|
}
|
|
285914
286007
|
async function writeJsonFile(path6, data) {
|
|
285915
|
-
await
|
|
286008
|
+
await writeFile8(path6, JSON.stringify(data, null, 2), "utf-8");
|
|
285916
286009
|
}
|
|
285917
286010
|
async function loadBudgetProfiles(baseDir, seedConfig) {
|
|
285918
286011
|
await ensureDir(baseDir);
|
|
285919
|
-
const path6 =
|
|
286012
|
+
const path6 = join45(baseDir, PROFILES_FILE);
|
|
285920
286013
|
const data = await readJsonFile(path6);
|
|
285921
286014
|
const profiles = Array.isArray(data?.profiles) ? data.profiles : [];
|
|
285922
286015
|
if (profiles.length === 0) {
|
|
@@ -285936,7 +286029,7 @@ async function loadBudgetProfiles(baseDir, seedConfig) {
|
|
|
285936
286029
|
}
|
|
285937
286030
|
async function saveBudgetProfiles(baseDir, profiles) {
|
|
285938
286031
|
await ensureDir(baseDir);
|
|
285939
|
-
const path6 =
|
|
286032
|
+
const path6 = join45(baseDir, PROFILES_FILE);
|
|
285940
286033
|
await writeJsonFile(path6, { profiles });
|
|
285941
286034
|
}
|
|
285942
286035
|
async function createBudgetProfile(baseDir, name2, config2, description) {
|
|
@@ -285974,13 +286067,13 @@ async function deleteBudgetProfile(baseDir, id) {
|
|
|
285974
286067
|
}
|
|
285975
286068
|
async function loadSessionBudgetMap(baseDir) {
|
|
285976
286069
|
await ensureDir(baseDir);
|
|
285977
|
-
const path6 =
|
|
286070
|
+
const path6 = join45(baseDir, SESSION_MAP_FILE);
|
|
285978
286071
|
const data = await readJsonFile(path6);
|
|
285979
286072
|
return data || {};
|
|
285980
286073
|
}
|
|
285981
286074
|
async function saveSessionBudgetMap(baseDir, map2) {
|
|
285982
286075
|
await ensureDir(baseDir);
|
|
285983
|
-
const path6 =
|
|
286076
|
+
const path6 = join45(baseDir, SESSION_MAP_FILE);
|
|
285984
286077
|
await writeJsonFile(path6, map2);
|
|
285985
286078
|
}
|
|
285986
286079
|
|
|
@@ -287491,12 +287584,12 @@ function App2({ cwd: cwd3, version: version5 }) {
|
|
|
287491
287584
|
try {
|
|
287492
287585
|
const config2 = await loadConfig(cwd3, workspaceBaseDir);
|
|
287493
287586
|
setCurrentConfig(config2);
|
|
287494
|
-
const { readFile:
|
|
287587
|
+
const { readFile: readFile10, access } = await import("fs/promises");
|
|
287495
287588
|
const configBaseDir = workspaceBaseDir || getConfigDir();
|
|
287496
287589
|
const userPath = `${configBaseDir}/config.json`;
|
|
287497
287590
|
try {
|
|
287498
287591
|
await access(userPath);
|
|
287499
|
-
const content = await
|
|
287592
|
+
const content = await readFile10(userPath, "utf-8");
|
|
287500
287593
|
setUserConfig(JSON.parse(content));
|
|
287501
287594
|
} catch {
|
|
287502
287595
|
setUserConfig(null);
|
|
@@ -287504,7 +287597,7 @@ function App2({ cwd: cwd3, version: version5 }) {
|
|
|
287504
287597
|
const projectPath = `${getProjectConfigDir(cwd3)}/config.json`;
|
|
287505
287598
|
try {
|
|
287506
287599
|
await access(projectPath);
|
|
287507
|
-
const content = await
|
|
287600
|
+
const content = await readFile10(projectPath, "utf-8");
|
|
287508
287601
|
setProjectConfig(JSON.parse(content));
|
|
287509
287602
|
} catch {
|
|
287510
287603
|
setProjectConfig(null);
|
|
@@ -287512,7 +287605,7 @@ function App2({ cwd: cwd3, version: version5 }) {
|
|
|
287512
287605
|
const localPath = `${getProjectConfigDir(cwd3)}/config.local.json`;
|
|
287513
287606
|
try {
|
|
287514
287607
|
await access(localPath);
|
|
287515
|
-
const content = await
|
|
287608
|
+
const content = await readFile10(localPath, "utf-8");
|
|
287516
287609
|
setLocalConfig(JSON.parse(content));
|
|
287517
287610
|
} catch {
|
|
287518
287611
|
setLocalConfig(null);
|
|
@@ -287599,46 +287692,46 @@ function App2({ cwd: cwd3, version: version5 }) {
|
|
|
287599
287692
|
});
|
|
287600
287693
|
}, [recoverableSessions, createSessionFromRecovery, workspaceBaseDir]);
|
|
287601
287694
|
const handleOnboardingComplete = import_react84.useCallback(async (result) => {
|
|
287602
|
-
const { existsSync:
|
|
287603
|
-
const secretsPath =
|
|
287695
|
+
const { existsSync: existsSync28, mkdirSync: mkdirSync17, readFileSync: readFileSync17, writeFileSync: writeFileSync12, appendFileSync: appendFileSync5 } = await import("fs");
|
|
287696
|
+
const secretsPath = join46(homedir20(), ".secrets");
|
|
287604
287697
|
const providerInfo = getProviderInfo(result.provider);
|
|
287605
287698
|
const envName = providerInfo?.apiKeyEnv || "ANTHROPIC_API_KEY";
|
|
287606
287699
|
const keyExport = `export ${envName}="${result.apiKey}"`;
|
|
287607
|
-
if (
|
|
287608
|
-
const content =
|
|
287700
|
+
if (existsSync28(secretsPath)) {
|
|
287701
|
+
const content = readFileSync17(secretsPath, "utf-8");
|
|
287609
287702
|
if (content.includes(envName)) {
|
|
287610
287703
|
const updated = content.replace(new RegExp(`^export ${envName}=.*$`, "m"), keyExport);
|
|
287611
|
-
|
|
287704
|
+
writeFileSync12(secretsPath, updated, "utf-8");
|
|
287612
287705
|
} else {
|
|
287613
287706
|
appendFileSync5(secretsPath, `
|
|
287614
287707
|
` + keyExport + `
|
|
287615
287708
|
`, "utf-8");
|
|
287616
287709
|
}
|
|
287617
287710
|
} else {
|
|
287618
|
-
|
|
287711
|
+
writeFileSync12(secretsPath, keyExport + `
|
|
287619
287712
|
`, { mode: 384 });
|
|
287620
287713
|
}
|
|
287621
287714
|
for (const [name2, key] of Object.entries(result.connectorKeys)) {
|
|
287622
287715
|
const envName2 = `${name2.toUpperCase()}_API_KEY`;
|
|
287623
287716
|
const connKeyExport = `export ${envName2}="${key}"`;
|
|
287624
|
-
const content =
|
|
287717
|
+
const content = readFileSync17(secretsPath, "utf-8");
|
|
287625
287718
|
if (content.includes(envName2)) {
|
|
287626
287719
|
const updated = content.replace(new RegExp(`^export ${envName2}=.*$`, "m"), connKeyExport);
|
|
287627
|
-
|
|
287720
|
+
writeFileSync12(secretsPath, updated, "utf-8");
|
|
287628
287721
|
} else {
|
|
287629
287722
|
appendFileSync5(secretsPath, connKeyExport + `
|
|
287630
287723
|
`, "utf-8");
|
|
287631
287724
|
}
|
|
287632
287725
|
}
|
|
287633
287726
|
const configDir = workspaceBaseDir || getConfigDir();
|
|
287634
|
-
if (!
|
|
287635
|
-
|
|
287727
|
+
if (!existsSync28(configDir)) {
|
|
287728
|
+
mkdirSync17(configDir, { recursive: true });
|
|
287636
287729
|
}
|
|
287637
|
-
const configPath =
|
|
287730
|
+
const configPath = join46(configDir, "config.json");
|
|
287638
287731
|
let existingConfig = {};
|
|
287639
|
-
if (
|
|
287732
|
+
if (existsSync28(configPath)) {
|
|
287640
287733
|
try {
|
|
287641
|
-
existingConfig = JSON.parse(
|
|
287734
|
+
existingConfig = JSON.parse(readFileSync17(configPath, "utf-8"));
|
|
287642
287735
|
} catch {}
|
|
287643
287736
|
}
|
|
287644
287737
|
const newConfig = {
|
|
@@ -287651,7 +287744,7 @@ function App2({ cwd: cwd3, version: version5 }) {
|
|
|
287651
287744
|
},
|
|
287652
287745
|
connectors: result.connectors.length > 0 ? result.connectors : undefined
|
|
287653
287746
|
};
|
|
287654
|
-
|
|
287747
|
+
writeFileSync12(configPath, JSON.stringify(newConfig, null, 2), "utf-8");
|
|
287655
287748
|
await loadConfigFiles();
|
|
287656
287749
|
process.env[envName] = result.apiKey;
|
|
287657
287750
|
setShowOnboardingPanel(false);
|
|
@@ -287680,14 +287773,14 @@ function App2({ cwd: cwd3, version: version5 }) {
|
|
|
287680
287773
|
return;
|
|
287681
287774
|
}
|
|
287682
287775
|
try {
|
|
287683
|
-
const configPath =
|
|
287684
|
-
const { existsSync:
|
|
287776
|
+
const configPath = join46(workspaceBaseDir || getConfigDir(), "config.json");
|
|
287777
|
+
const { existsSync: existsSync28, readFileSync: readFileSync17 } = await import("fs");
|
|
287685
287778
|
let needsOnboarding = false;
|
|
287686
|
-
if (!
|
|
287779
|
+
if (!existsSync28(configPath)) {
|
|
287687
287780
|
needsOnboarding = true;
|
|
287688
287781
|
} else {
|
|
287689
287782
|
try {
|
|
287690
|
-
const raw =
|
|
287783
|
+
const raw = readFileSync17(configPath, "utf-8");
|
|
287691
287784
|
const parsed = JSON.parse(raw);
|
|
287692
287785
|
if (!parsed.onboardingCompleted) {
|
|
287693
287786
|
needsOnboarding = true;
|
|
@@ -289849,8 +289942,8 @@ When done, report the result.`);
|
|
|
289849
289942
|
}
|
|
289850
289943
|
if (showConfigPanel && currentConfig) {
|
|
289851
289944
|
const handleConfigSave = async (location, updates) => {
|
|
289852
|
-
const { writeFile:
|
|
289853
|
-
const { dirname:
|
|
289945
|
+
const { writeFile: writeFile9, mkdir: mkdir10 } = await import("fs/promises");
|
|
289946
|
+
const { dirname: dirname18 } = await import("path");
|
|
289854
289947
|
let configPath;
|
|
289855
289948
|
let existingConfig;
|
|
289856
289949
|
switch (location) {
|
|
@@ -289868,8 +289961,8 @@ When done, report the result.`);
|
|
|
289868
289961
|
break;
|
|
289869
289962
|
}
|
|
289870
289963
|
const newConfig = deepMerge(existingConfig || {}, updates);
|
|
289871
|
-
await
|
|
289872
|
-
await
|
|
289964
|
+
await mkdir10(dirname18(configPath), { recursive: true });
|
|
289965
|
+
await writeFile9(configPath, JSON.stringify(newConfig, null, 2));
|
|
289873
289966
|
await loadConfigFiles();
|
|
289874
289967
|
};
|
|
289875
289968
|
return /* @__PURE__ */ jsx_dev_runtime51.jsxDEV(Box_default, {
|
|
@@ -290800,7 +290893,7 @@ Interactive Mode:
|
|
|
290800
290893
|
// packages/terminal/src/index.tsx
|
|
290801
290894
|
var jsx_dev_runtime52 = __toESM(require_jsx_dev_runtime(), 1);
|
|
290802
290895
|
setRuntime(bunRuntime);
|
|
290803
|
-
var VERSION4 = "1.1.
|
|
290896
|
+
var VERSION4 = "1.1.52";
|
|
290804
290897
|
var SYNC_START = "\x1B[?2026h";
|
|
290805
290898
|
var SYNC_END = "\x1B[?2026l";
|
|
290806
290899
|
function enableSynchronizedOutput() {
|
|
@@ -290919,4 +291012,4 @@ export {
|
|
|
290919
291012
|
main
|
|
290920
291013
|
};
|
|
290921
291014
|
|
|
290922
|
-
//# debugId=
|
|
291015
|
+
//# debugId=51954E8A8CA1CA3F64756E2164756E21
|