@hasna/assistants 1.1.51 → 1.1.53
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 +1107 -1058
- package/dist/index.js.map +16 -17
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -616,8 +616,6 @@ async function ensureConfigDir(sessionId, baseDir) {
|
|
|
616
616
|
const dirs = [
|
|
617
617
|
mkdir2(configDir, { recursive: true }),
|
|
618
618
|
mkdir2(join(configDir, "logs"), { recursive: true }),
|
|
619
|
-
mkdir2(join(configDir, "assistants"), { recursive: true }),
|
|
620
|
-
mkdir2(join(configDir, "migration"), { recursive: true }),
|
|
621
619
|
mkdir2(join(configDir, "temp"), { recursive: true }),
|
|
622
620
|
mkdir2(join(configDir, "messages"), { recursive: true }),
|
|
623
621
|
mkdir2(join(configDir, "backups"), { recursive: true })
|
|
@@ -1472,7 +1470,119 @@ var init_schema = __esm(() => {
|
|
|
1472
1470
|
created_at TEXT NOT NULL
|
|
1473
1471
|
)`,
|
|
1474
1472
|
`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)
|
|
1473
|
+
`CREATE INDEX IF NOT EXISTS idx_guardrail_evaluations_rule ON guardrail_evaluations(rule_id)`,
|
|
1474
|
+
`CREATE TABLE IF NOT EXISTS assistants_config (
|
|
1475
|
+
id TEXT PRIMARY KEY,
|
|
1476
|
+
name TEXT NOT NULL,
|
|
1477
|
+
model TEXT,
|
|
1478
|
+
system_prompt TEXT,
|
|
1479
|
+
settings TEXT NOT NULL DEFAULT '{}',
|
|
1480
|
+
identity_id TEXT,
|
|
1481
|
+
created_at INTEGER NOT NULL,
|
|
1482
|
+
updated_at INTEGER NOT NULL
|
|
1483
|
+
)`,
|
|
1484
|
+
`CREATE TABLE IF NOT EXISTS assistants_active (
|
|
1485
|
+
key TEXT PRIMARY KEY DEFAULT 'active',
|
|
1486
|
+
assistant_id TEXT NOT NULL
|
|
1487
|
+
)`,
|
|
1488
|
+
`CREATE TABLE IF NOT EXISTS assistant_sessions (
|
|
1489
|
+
id TEXT PRIMARY KEY,
|
|
1490
|
+
assistant_id TEXT NOT NULL,
|
|
1491
|
+
cwd TEXT,
|
|
1492
|
+
started_at INTEGER NOT NULL,
|
|
1493
|
+
updated_at INTEGER NOT NULL,
|
|
1494
|
+
status TEXT NOT NULL DEFAULT 'active',
|
|
1495
|
+
metadata TEXT
|
|
1496
|
+
)`,
|
|
1497
|
+
`CREATE INDEX IF NOT EXISTS idx_assistant_sessions_assistant ON assistant_sessions(assistant_id)`,
|
|
1498
|
+
`CREATE TABLE IF NOT EXISTS people (
|
|
1499
|
+
id TEXT PRIMARY KEY,
|
|
1500
|
+
name TEXT NOT NULL,
|
|
1501
|
+
email TEXT,
|
|
1502
|
+
phone TEXT,
|
|
1503
|
+
role TEXT,
|
|
1504
|
+
notes TEXT,
|
|
1505
|
+
avatar_url TEXT,
|
|
1506
|
+
metadata TEXT,
|
|
1507
|
+
created_at INTEGER NOT NULL,
|
|
1508
|
+
updated_at INTEGER NOT NULL
|
|
1509
|
+
)`,
|
|
1510
|
+
`CREATE TABLE IF NOT EXISTS people_active (
|
|
1511
|
+
key TEXT PRIMARY KEY DEFAULT 'active',
|
|
1512
|
+
person_id TEXT NOT NULL
|
|
1513
|
+
)`,
|
|
1514
|
+
`CREATE TABLE IF NOT EXISTS verification_sessions (
|
|
1515
|
+
id TEXT PRIMARY KEY,
|
|
1516
|
+
session_id TEXT NOT NULL,
|
|
1517
|
+
assistant_id TEXT,
|
|
1518
|
+
goal TEXT NOT NULL,
|
|
1519
|
+
status TEXT NOT NULL DEFAULT 'pending',
|
|
1520
|
+
result TEXT,
|
|
1521
|
+
created_at TEXT NOT NULL,
|
|
1522
|
+
completed_at TEXT,
|
|
1523
|
+
data TEXT
|
|
1524
|
+
)`,
|
|
1525
|
+
`CREATE INDEX IF NOT EXISTS idx_verification_sessions_session ON verification_sessions(session_id)`,
|
|
1526
|
+
`CREATE TABLE IF NOT EXISTS workspaces (
|
|
1527
|
+
id TEXT PRIMARY KEY,
|
|
1528
|
+
name TEXT NOT NULL,
|
|
1529
|
+
description TEXT,
|
|
1530
|
+
creator_id TEXT NOT NULL,
|
|
1531
|
+
creator_name TEXT NOT NULL,
|
|
1532
|
+
status TEXT NOT NULL DEFAULT 'active',
|
|
1533
|
+
participants TEXT NOT NULL DEFAULT '[]',
|
|
1534
|
+
created_at TEXT NOT NULL,
|
|
1535
|
+
updated_at TEXT NOT NULL
|
|
1536
|
+
)`,
|
|
1537
|
+
`CREATE TABLE IF NOT EXISTS workspaces_active (
|
|
1538
|
+
assistant_id TEXT PRIMARY KEY,
|
|
1539
|
+
workspace_id TEXT NOT NULL
|
|
1540
|
+
)`,
|
|
1541
|
+
`CREATE TABLE IF NOT EXISTS budget_usage (
|
|
1542
|
+
scope TEXT NOT NULL,
|
|
1543
|
+
scope_id TEXT NOT NULL,
|
|
1544
|
+
input_tokens INTEGER NOT NULL DEFAULT 0,
|
|
1545
|
+
output_tokens INTEGER NOT NULL DEFAULT 0,
|
|
1546
|
+
total_tokens INTEGER NOT NULL DEFAULT 0,
|
|
1547
|
+
api_calls INTEGER NOT NULL DEFAULT 0,
|
|
1548
|
+
tool_calls INTEGER NOT NULL DEFAULT 0,
|
|
1549
|
+
estimated_cost_usd REAL NOT NULL DEFAULT 0,
|
|
1550
|
+
updated_at TEXT NOT NULL,
|
|
1551
|
+
PRIMARY KEY (scope, scope_id)
|
|
1552
|
+
)`,
|
|
1553
|
+
`CREATE TABLE IF NOT EXISTS registered_assistants (
|
|
1554
|
+
id TEXT PRIMARY KEY,
|
|
1555
|
+
name TEXT NOT NULL,
|
|
1556
|
+
type TEXT NOT NULL DEFAULT 'general',
|
|
1557
|
+
description TEXT,
|
|
1558
|
+
model TEXT,
|
|
1559
|
+
status TEXT NOT NULL DEFAULT 'active',
|
|
1560
|
+
state TEXT NOT NULL DEFAULT 'idle',
|
|
1561
|
+
capabilities TEXT,
|
|
1562
|
+
tags TEXT,
|
|
1563
|
+
parent_id TEXT,
|
|
1564
|
+
created_at TEXT NOT NULL,
|
|
1565
|
+
updated_at TEXT NOT NULL,
|
|
1566
|
+
last_active_at TEXT,
|
|
1567
|
+
metadata TEXT
|
|
1568
|
+
)`,
|
|
1569
|
+
`CREATE INDEX IF NOT EXISTS idx_registered_assistants_type ON registered_assistants(type)`,
|
|
1570
|
+
`CREATE INDEX IF NOT EXISTS idx_registered_assistants_status ON registered_assistants(status)`,
|
|
1571
|
+
`CREATE TABLE IF NOT EXISTS heartbeat_history (
|
|
1572
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
1573
|
+
session_id TEXT NOT NULL,
|
|
1574
|
+
status TEXT NOT NULL,
|
|
1575
|
+
energy INTEGER,
|
|
1576
|
+
context_tokens INTEGER,
|
|
1577
|
+
action TEXT,
|
|
1578
|
+
timestamp TEXT NOT NULL
|
|
1579
|
+
)`,
|
|
1580
|
+
`CREATE INDEX IF NOT EXISTS idx_heartbeat_history_session ON heartbeat_history(session_id, timestamp DESC)`,
|
|
1581
|
+
`CREATE TABLE IF NOT EXISTS connector_cache (
|
|
1582
|
+
key TEXT PRIMARY KEY,
|
|
1583
|
+
data TEXT NOT NULL,
|
|
1584
|
+
cached_at TEXT NOT NULL
|
|
1585
|
+
)`
|
|
1476
1586
|
];
|
|
1477
1587
|
});
|
|
1478
1588
|
|
|
@@ -20345,80 +20455,105 @@ var init_energy = __esm(() => {
|
|
|
20345
20455
|
});
|
|
20346
20456
|
|
|
20347
20457
|
// packages/core/src/heartbeat/history.ts
|
|
20348
|
-
|
|
20349
|
-
|
|
20350
|
-
|
|
20351
|
-
function
|
|
20352
|
-
if (
|
|
20353
|
-
|
|
20458
|
+
function getDb() {
|
|
20459
|
+
return getDatabase();
|
|
20460
|
+
}
|
|
20461
|
+
function rowToHeartbeat(row) {
|
|
20462
|
+
if (row.action) {
|
|
20463
|
+
try {
|
|
20464
|
+
const parsed = JSON.parse(row.action);
|
|
20465
|
+
if (parsed.sessionId)
|
|
20466
|
+
return parsed;
|
|
20467
|
+
} catch {}
|
|
20354
20468
|
}
|
|
20355
|
-
return
|
|
20469
|
+
return {
|
|
20470
|
+
sessionId: row.session_id,
|
|
20471
|
+
timestamp: row.timestamp,
|
|
20472
|
+
state: row.status,
|
|
20473
|
+
lastActivity: row.timestamp,
|
|
20474
|
+
stats: {
|
|
20475
|
+
messagesProcessed: 0,
|
|
20476
|
+
toolCallsExecuted: 0,
|
|
20477
|
+
errorsEncountered: 0,
|
|
20478
|
+
uptimeSeconds: 0
|
|
20479
|
+
}
|
|
20480
|
+
};
|
|
20356
20481
|
}
|
|
20357
|
-
function resolveHeartbeatPersistPath(sessionId, persistPath,
|
|
20482
|
+
function resolveHeartbeatPersistPath(sessionId, persistPath, _baseDir) {
|
|
20358
20483
|
if (persistPath) {
|
|
20359
|
-
|
|
20484
|
+
if (persistPath.includes("{sessionId}")) {
|
|
20485
|
+
return persistPath.replace("{sessionId}", sessionId);
|
|
20486
|
+
}
|
|
20487
|
+
return persistPath;
|
|
20360
20488
|
}
|
|
20361
|
-
return
|
|
20489
|
+
return `<db>:heartbeat_history:${sessionId}`;
|
|
20362
20490
|
}
|
|
20363
|
-
function resolveHeartbeatHistoryPath(sessionId, historyPath,
|
|
20491
|
+
function resolveHeartbeatHistoryPath(sessionId, historyPath, _baseDir) {
|
|
20364
20492
|
if (historyPath) {
|
|
20365
|
-
|
|
20493
|
+
if (historyPath.includes("{sessionId}")) {
|
|
20494
|
+
return historyPath.replace("{sessionId}", sessionId);
|
|
20495
|
+
}
|
|
20496
|
+
return historyPath;
|
|
20366
20497
|
}
|
|
20367
|
-
return
|
|
20498
|
+
return `<db>:heartbeat_history:${sessionId}`;
|
|
20368
20499
|
}
|
|
20369
|
-
function listHeartbeatHistorySessions(
|
|
20370
|
-
|
|
20371
|
-
|
|
20500
|
+
function listHeartbeatHistorySessions(_baseDir, db) {
|
|
20501
|
+
try {
|
|
20502
|
+
const conn = db || getDb();
|
|
20503
|
+
const rows = conn.query("SELECT DISTINCT session_id FROM heartbeat_history").all();
|
|
20504
|
+
return rows.map((r) => r.session_id);
|
|
20505
|
+
} catch {
|
|
20372
20506
|
return [];
|
|
20373
|
-
|
|
20507
|
+
}
|
|
20374
20508
|
}
|
|
20375
|
-
async function appendHeartbeatHistory(historyPath, heartbeat) {
|
|
20509
|
+
async function appendHeartbeatHistory(historyPath, heartbeat, db) {
|
|
20376
20510
|
try {
|
|
20377
|
-
|
|
20378
|
-
|
|
20379
|
-
|
|
20511
|
+
const conn = db || getDb();
|
|
20512
|
+
conn.prepare(`INSERT INTO heartbeat_history (session_id, status, energy, context_tokens, action, timestamp)
|
|
20513
|
+
VALUES (?, ?, ?, ?, ?, ?)`).run(heartbeat.sessionId, heartbeat.state, null, null, JSON.stringify(heartbeat), heartbeat.timestamp);
|
|
20380
20514
|
} catch {}
|
|
20381
20515
|
}
|
|
20382
|
-
|
|
20516
|
+
function extractSessionId(historyPath) {
|
|
20517
|
+
if (historyPath.startsWith("<db>:heartbeat_history:")) {
|
|
20518
|
+
return historyPath.replace("<db>:heartbeat_history:", "");
|
|
20519
|
+
}
|
|
20520
|
+
const match = historyPath.match(/[/\\]([^/\\]+?)\.jsonl?$/);
|
|
20521
|
+
if (match) {
|
|
20522
|
+
return match[1];
|
|
20523
|
+
}
|
|
20524
|
+
return null;
|
|
20525
|
+
}
|
|
20526
|
+
async function readHeartbeatHistory(historyPath, options = {}, db) {
|
|
20383
20527
|
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
|
-
}
|
|
20528
|
+
const conn = db || getDb();
|
|
20529
|
+
const sessionId = extractSessionId(historyPath);
|
|
20393
20530
|
const order = options.order ?? "desc";
|
|
20394
|
-
const
|
|
20395
|
-
|
|
20396
|
-
|
|
20531
|
+
const orderSql = order === "desc" ? "DESC" : "ASC";
|
|
20532
|
+
const limitSql = options.limit && options.limit > 0 ? `LIMIT ${options.limit}` : "";
|
|
20533
|
+
let rows;
|
|
20534
|
+
if (sessionId) {
|
|
20535
|
+
rows = conn.query(`SELECT * FROM heartbeat_history WHERE session_id = ? ORDER BY timestamp ${orderSql} ${limitSql}`).all(sessionId);
|
|
20536
|
+
} else {
|
|
20537
|
+
rows = conn.query(`SELECT * FROM heartbeat_history ORDER BY timestamp ${orderSql} ${limitSql}`).all();
|
|
20397
20538
|
}
|
|
20398
|
-
return
|
|
20539
|
+
return rows.map(rowToHeartbeat);
|
|
20399
20540
|
} catch {
|
|
20400
20541
|
return [];
|
|
20401
20542
|
}
|
|
20402
20543
|
}
|
|
20403
|
-
async function readHeartbeatHistoryBySession(sessionId, options = {}) {
|
|
20404
|
-
const historyPath = resolveHeartbeatHistoryPath(sessionId, options.historyPath
|
|
20405
|
-
return readHeartbeatHistory(historyPath, { limit: options.limit, order: options.order });
|
|
20544
|
+
async function readHeartbeatHistoryBySession(sessionId, options = {}, db) {
|
|
20545
|
+
const historyPath = resolveHeartbeatHistoryPath(sessionId, options.historyPath);
|
|
20546
|
+
return readHeartbeatHistory(historyPath, { limit: options.limit, order: options.order }, db);
|
|
20406
20547
|
}
|
|
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
|
-
}
|
|
20548
|
+
async function readLatestHeartbeat(persistPath, historyPath, db) {
|
|
20549
|
+
const path2 = historyPath || persistPath;
|
|
20550
|
+
const history = await readHeartbeatHistory(path2, { limit: 1, order: "desc" }, db);
|
|
20551
|
+
if (history.length > 0)
|
|
20552
|
+
return history[0];
|
|
20553
|
+
return null;
|
|
20419
20554
|
}
|
|
20420
20555
|
var init_history = __esm(async () => {
|
|
20421
|
-
await
|
|
20556
|
+
await init_database();
|
|
20422
20557
|
});
|
|
20423
20558
|
|
|
20424
20559
|
// packages/core/src/tools/heartbeat.ts
|
|
@@ -20530,7 +20665,7 @@ var init_heartbeat = __esm(async () => {
|
|
|
20530
20665
|
});
|
|
20531
20666
|
|
|
20532
20667
|
// packages/core/src/projects/store.ts
|
|
20533
|
-
function
|
|
20668
|
+
function getDb2() {
|
|
20534
20669
|
return getDatabase();
|
|
20535
20670
|
}
|
|
20536
20671
|
function rowToProject(row) {
|
|
@@ -20548,11 +20683,11 @@ function normalizeName(name) {
|
|
|
20548
20683
|
return name.trim().toLowerCase();
|
|
20549
20684
|
}
|
|
20550
20685
|
async function listProjects(cwd) {
|
|
20551
|
-
const rows =
|
|
20686
|
+
const rows = getDb2().query("SELECT * FROM projects WHERE project_path = ? ORDER BY updated_at DESC").all(cwd);
|
|
20552
20687
|
return rows.map(rowToProject);
|
|
20553
20688
|
}
|
|
20554
20689
|
async function readProject(cwd, id) {
|
|
20555
|
-
const row =
|
|
20690
|
+
const row = getDb2().query("SELECT * FROM projects WHERE id = ?").get(id);
|
|
20556
20691
|
if (!row)
|
|
20557
20692
|
return null;
|
|
20558
20693
|
return rowToProject(row);
|
|
@@ -20563,11 +20698,11 @@ async function findProjectByName(cwd, name) {
|
|
|
20563
20698
|
return projects.find((project) => normalizeName(project.name) === normalized) || null;
|
|
20564
20699
|
}
|
|
20565
20700
|
async function saveProject(cwd, project) {
|
|
20566
|
-
|
|
20701
|
+
getDb2().prepare(`INSERT OR REPLACE INTO projects (id, project_path, name, description, context, plans, created_at, updated_at)
|
|
20567
20702
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`).run(project.id, cwd, project.name, project.description ?? null, JSON.stringify(project.context), JSON.stringify(project.plans), project.createdAt, project.updatedAt);
|
|
20568
20703
|
}
|
|
20569
20704
|
async function deleteProject(cwd, id) {
|
|
20570
|
-
const result =
|
|
20705
|
+
const result = getDb2().prepare("DELETE FROM projects WHERE id = ?").run(id);
|
|
20571
20706
|
return result.changes > 0;
|
|
20572
20707
|
}
|
|
20573
20708
|
async function createProject(cwd, name, description) {
|
|
@@ -20669,9 +20804,9 @@ function isWithinPath(target, base) {
|
|
|
20669
20804
|
var init_paths = () => {};
|
|
20670
20805
|
|
|
20671
20806
|
// packages/core/src/projects/context.ts
|
|
20672
|
-
import { readFile as
|
|
20807
|
+
import { readFile as readFile2 } from "fs/promises";
|
|
20673
20808
|
import { homedir as homedir6 } from "os";
|
|
20674
|
-
import { resolve as resolve2, join as
|
|
20809
|
+
import { resolve as resolve2, join as join10 } from "path";
|
|
20675
20810
|
function singleLine(value) {
|
|
20676
20811
|
return value.replace(/[\r\n]+/g, " ").trim();
|
|
20677
20812
|
}
|
|
@@ -20689,7 +20824,7 @@ function normalizeEntryLabel(entry) {
|
|
|
20689
20824
|
}
|
|
20690
20825
|
async function renderFileEntry(entry, options) {
|
|
20691
20826
|
const rawPath = entry.value.trim();
|
|
20692
|
-
const expandedPath = rawPath === "~" ? homedir6() : rawPath.startsWith("~/") ?
|
|
20827
|
+
const expandedPath = rawPath === "~" ? homedir6() : rawPath.startsWith("~/") ? join10(homedir6(), rawPath.slice(2)) : rawPath;
|
|
20693
20828
|
const resolved = resolve2(options.cwd, expandedPath);
|
|
20694
20829
|
const validation = await validatePath(resolved, { allowedPaths: [options.cwd] });
|
|
20695
20830
|
if (!validation.valid) {
|
|
@@ -20697,7 +20832,7 @@ async function renderFileEntry(entry, options) {
|
|
|
20697
20832
|
}
|
|
20698
20833
|
let content = "";
|
|
20699
20834
|
try {
|
|
20700
|
-
const data = await
|
|
20835
|
+
const data = await readFile2(validation.resolved, "utf-8");
|
|
20701
20836
|
const limit2 = options.maxFileBytes ?? DEFAULT_MAX_FILE_BYTES;
|
|
20702
20837
|
if (data.length > limit2) {
|
|
20703
20838
|
content = `${data.slice(0, limit2)}
|
|
@@ -21214,8 +21349,8 @@ var init_security = __esm(() => {
|
|
|
21214
21349
|
});
|
|
21215
21350
|
|
|
21216
21351
|
// packages/core/src/logger.ts
|
|
21217
|
-
import { existsSync as
|
|
21218
|
-
import { join as
|
|
21352
|
+
import { existsSync as existsSync8, mkdirSync as mkdirSync5, appendFileSync, readdirSync as readdirSync4, readFileSync as readFileSync5, writeFileSync as writeFileSync3 } from "fs";
|
|
21353
|
+
import { join as join11 } from "path";
|
|
21219
21354
|
function isValidId(id) {
|
|
21220
21355
|
return typeof id === "string" && id.length > 0 && SAFE_ID_PATTERN2.test(id);
|
|
21221
21356
|
}
|
|
@@ -21226,14 +21361,14 @@ class Logger {
|
|
|
21226
21361
|
sessionId;
|
|
21227
21362
|
constructor(sessionId, basePath) {
|
|
21228
21363
|
this.sessionId = sessionId;
|
|
21229
|
-
this.logDir =
|
|
21364
|
+
this.logDir = join11(basePath || getConfigDir(), "logs");
|
|
21230
21365
|
this.ensureDir(this.logDir);
|
|
21231
21366
|
const date = new Date().toISOString().split("T")[0];
|
|
21232
|
-
this.logFile =
|
|
21367
|
+
this.logFile = join11(this.logDir, `${date}.log`);
|
|
21233
21368
|
}
|
|
21234
21369
|
ensureDir(dir) {
|
|
21235
|
-
if (!
|
|
21236
|
-
|
|
21370
|
+
if (!existsSync8(dir)) {
|
|
21371
|
+
mkdirSync5(dir, { recursive: true });
|
|
21237
21372
|
}
|
|
21238
21373
|
}
|
|
21239
21374
|
write(level, message, data) {
|
|
@@ -21265,12 +21400,12 @@ class Logger {
|
|
|
21265
21400
|
this.write("error", message, data);
|
|
21266
21401
|
}
|
|
21267
21402
|
static readEntries(options) {
|
|
21268
|
-
const logDir =
|
|
21269
|
-
if (!
|
|
21403
|
+
const logDir = join11(options?.basePath || getConfigDir(), "logs");
|
|
21404
|
+
if (!existsSync8(logDir))
|
|
21270
21405
|
return [];
|
|
21271
21406
|
const levelOrder = { debug: 0, info: 1, warn: 2, error: 3 };
|
|
21272
21407
|
const minLevel = options?.level ? levelOrder[options.level] : 0;
|
|
21273
|
-
const files =
|
|
21408
|
+
const files = readdirSync4(logDir).filter((f) => /^\d{4}-\d{2}-\d{2}\.log$/.test(f)).sort((a, b) => b.localeCompare(a));
|
|
21274
21409
|
const entries = [];
|
|
21275
21410
|
for (const file of files) {
|
|
21276
21411
|
if (options?.since) {
|
|
@@ -21280,7 +21415,7 @@ class Logger {
|
|
|
21280
21415
|
break;
|
|
21281
21416
|
}
|
|
21282
21417
|
try {
|
|
21283
|
-
const content = readFileSync5(
|
|
21418
|
+
const content = readFileSync5(join11(logDir, file), "utf-8");
|
|
21284
21419
|
const lines = content.trim().split(`
|
|
21285
21420
|
`).filter(Boolean);
|
|
21286
21421
|
for (const line of lines) {
|
|
@@ -21303,10 +21438,10 @@ class Logger {
|
|
|
21303
21438
|
return entries.slice(offset, offset + limit2);
|
|
21304
21439
|
}
|
|
21305
21440
|
static listLogDates(basePath) {
|
|
21306
|
-
const logDir =
|
|
21307
|
-
if (!
|
|
21441
|
+
const logDir = join11(basePath || getConfigDir(), "logs");
|
|
21442
|
+
if (!existsSync8(logDir))
|
|
21308
21443
|
return [];
|
|
21309
|
-
return
|
|
21444
|
+
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
21445
|
}
|
|
21311
21446
|
}
|
|
21312
21447
|
|
|
@@ -21321,13 +21456,13 @@ class SessionStorage {
|
|
|
21321
21456
|
this.sessionId = sessionId;
|
|
21322
21457
|
const root = basePath || getConfigDir();
|
|
21323
21458
|
const safeAssistantId = isValidId(assistantId) ? assistantId : null;
|
|
21324
|
-
this.sessionsDir = safeAssistantId ?
|
|
21459
|
+
this.sessionsDir = safeAssistantId ? join11(root, "assistants", safeAssistantId, "sessions") : join11(root, "sessions");
|
|
21325
21460
|
this.ensureDir(this.sessionsDir);
|
|
21326
|
-
this.sessionFile =
|
|
21461
|
+
this.sessionFile = join11(this.sessionsDir, `${sessionId}.json`);
|
|
21327
21462
|
}
|
|
21328
21463
|
ensureDir(dir) {
|
|
21329
|
-
if (!
|
|
21330
|
-
|
|
21464
|
+
if (!existsSync8(dir)) {
|
|
21465
|
+
mkdirSync5(dir, { recursive: true });
|
|
21331
21466
|
}
|
|
21332
21467
|
}
|
|
21333
21468
|
save(data) {
|
|
@@ -21340,7 +21475,7 @@ class SessionStorage {
|
|
|
21340
21475
|
}
|
|
21341
21476
|
load() {
|
|
21342
21477
|
try {
|
|
21343
|
-
if (!
|
|
21478
|
+
if (!existsSync8(this.sessionFile))
|
|
21344
21479
|
return null;
|
|
21345
21480
|
return JSON.parse(readFileSync5(this.sessionFile, "utf-8"));
|
|
21346
21481
|
} catch {
|
|
@@ -21350,8 +21485,8 @@ class SessionStorage {
|
|
|
21350
21485
|
static getActiveAssistantId(basePath) {
|
|
21351
21486
|
try {
|
|
21352
21487
|
const root = basePath || getConfigDir();
|
|
21353
|
-
const activePath =
|
|
21354
|
-
if (!
|
|
21488
|
+
const activePath = join11(root, "active.json");
|
|
21489
|
+
if (!existsSync8(activePath))
|
|
21355
21490
|
return null;
|
|
21356
21491
|
const raw = readFileSync5(activePath, "utf-8");
|
|
21357
21492
|
const data = JSON.parse(raw);
|
|
@@ -21372,23 +21507,23 @@ class SessionStorage {
|
|
|
21372
21507
|
const safeAssistantId = isValidId(assistantId) ? assistantId : null;
|
|
21373
21508
|
const resolvedId = safeAssistantId ?? SessionStorage.getActiveAssistantId(basePath);
|
|
21374
21509
|
if (resolvedId && isValidId(resolvedId)) {
|
|
21375
|
-
const assistantDir =
|
|
21376
|
-
if (
|
|
21510
|
+
const assistantDir = join11(root, "assistants", resolvedId, "sessions");
|
|
21511
|
+
if (existsSync8(assistantDir)) {
|
|
21377
21512
|
return { dir: assistantDir, assistantId: resolvedId };
|
|
21378
21513
|
}
|
|
21379
21514
|
}
|
|
21380
|
-
return { dir:
|
|
21515
|
+
return { dir: join11(root, "sessions"), assistantId: null };
|
|
21381
21516
|
}
|
|
21382
21517
|
static readSessionsFromDir(sessionsDir, assistantId) {
|
|
21383
|
-
if (!
|
|
21518
|
+
if (!existsSync8(sessionsDir))
|
|
21384
21519
|
return [];
|
|
21385
21520
|
const sessions = [];
|
|
21386
|
-
const files =
|
|
21521
|
+
const files = readdirSync4(sessionsDir);
|
|
21387
21522
|
for (const file of files) {
|
|
21388
21523
|
if (!file.endsWith(".json"))
|
|
21389
21524
|
continue;
|
|
21390
21525
|
try {
|
|
21391
|
-
const filePath =
|
|
21526
|
+
const filePath = join11(sessionsDir, file);
|
|
21392
21527
|
const content = JSON.parse(readFileSync5(filePath, "utf-8"));
|
|
21393
21528
|
sessions.push({
|
|
21394
21529
|
id: file.replace(".json", ""),
|
|
@@ -21410,17 +21545,17 @@ class SessionStorage {
|
|
|
21410
21545
|
static listAllSessions(basePath) {
|
|
21411
21546
|
const root = basePath || getConfigDir();
|
|
21412
21547
|
const sessions = [];
|
|
21413
|
-
const rootSessionsDir =
|
|
21548
|
+
const rootSessionsDir = join11(root, "sessions");
|
|
21414
21549
|
sessions.push(...SessionStorage.readSessionsFromDir(rootSessionsDir, null));
|
|
21415
|
-
const assistantsDir =
|
|
21416
|
-
if (
|
|
21417
|
-
const entries =
|
|
21550
|
+
const assistantsDir = join11(root, "assistants");
|
|
21551
|
+
if (existsSync8(assistantsDir)) {
|
|
21552
|
+
const entries = readdirSync4(assistantsDir, { withFileTypes: true });
|
|
21418
21553
|
for (const entry of entries) {
|
|
21419
21554
|
if (!entry.isDirectory())
|
|
21420
21555
|
continue;
|
|
21421
21556
|
if (!isValidId(entry.name))
|
|
21422
21557
|
continue;
|
|
21423
|
-
const assistantSessionsDir =
|
|
21558
|
+
const assistantSessionsDir = join11(assistantsDir, entry.name, "sessions");
|
|
21424
21559
|
sessions.push(...SessionStorage.readSessionsFromDir(assistantSessionsDir, entry.name));
|
|
21425
21560
|
}
|
|
21426
21561
|
}
|
|
@@ -21435,9 +21570,9 @@ class SessionStorage {
|
|
|
21435
21570
|
return null;
|
|
21436
21571
|
}
|
|
21437
21572
|
const sessionsDir = SessionStorage.resolveSessionsDir(assistantId, basePath);
|
|
21438
|
-
const sessionFile =
|
|
21573
|
+
const sessionFile = join11(sessionsDir, `${sessionId}.json`);
|
|
21439
21574
|
try {
|
|
21440
|
-
if (!
|
|
21575
|
+
if (!existsSync8(sessionFile))
|
|
21441
21576
|
return null;
|
|
21442
21577
|
return JSON.parse(readFileSync5(sessionFile, "utf-8"));
|
|
21443
21578
|
} catch {
|
|
@@ -21449,19 +21584,14 @@ function initAssistantsDir(basePath) {
|
|
|
21449
21584
|
const baseDir = basePath || getConfigDir();
|
|
21450
21585
|
const dirs = [
|
|
21451
21586
|
baseDir,
|
|
21452
|
-
|
|
21453
|
-
|
|
21454
|
-
|
|
21455
|
-
|
|
21456
|
-
join12(baseDir, "temp"),
|
|
21457
|
-
join12(baseDir, "heartbeats"),
|
|
21458
|
-
join12(baseDir, "state"),
|
|
21459
|
-
join12(baseDir, "energy"),
|
|
21460
|
-
join12(baseDir, "migration")
|
|
21587
|
+
join11(baseDir, "logs"),
|
|
21588
|
+
join11(baseDir, "temp"),
|
|
21589
|
+
join11(baseDir, "messages"),
|
|
21590
|
+
join11(baseDir, "backups")
|
|
21461
21591
|
];
|
|
21462
21592
|
for (const dir of dirs) {
|
|
21463
|
-
if (!
|
|
21464
|
-
|
|
21593
|
+
if (!existsSync8(dir)) {
|
|
21594
|
+
mkdirSync5(dir, { recursive: true });
|
|
21465
21595
|
}
|
|
21466
21596
|
}
|
|
21467
21597
|
}
|
|
@@ -21472,20 +21602,20 @@ var init_logger2 = __esm(async () => {
|
|
|
21472
21602
|
});
|
|
21473
21603
|
|
|
21474
21604
|
// packages/core/src/hooks/logger.ts
|
|
21475
|
-
import { join as
|
|
21476
|
-
import { existsSync as
|
|
21605
|
+
import { join as join12 } from "path";
|
|
21606
|
+
import { existsSync as existsSync9, mkdirSync as mkdirSync6, appendFileSync as appendFileSync2, readFileSync as readFileSync6, writeFileSync as writeFileSync4 } from "fs";
|
|
21477
21607
|
function getLogPath() {
|
|
21478
|
-
return
|
|
21608
|
+
return join12(getConfigDir(), "logs", "hooks.jsonl");
|
|
21479
21609
|
}
|
|
21480
21610
|
function ensureLogsDir() {
|
|
21481
|
-
const logsDir =
|
|
21482
|
-
if (!
|
|
21483
|
-
|
|
21611
|
+
const logsDir = join12(getConfigDir(), "logs");
|
|
21612
|
+
if (!existsSync9(logsDir)) {
|
|
21613
|
+
mkdirSync6(logsDir, { recursive: true });
|
|
21484
21614
|
}
|
|
21485
21615
|
}
|
|
21486
21616
|
function rotateIfNeeded() {
|
|
21487
21617
|
const logPath = getLogPath();
|
|
21488
|
-
if (!
|
|
21618
|
+
if (!existsSync9(logPath))
|
|
21489
21619
|
return;
|
|
21490
21620
|
try {
|
|
21491
21621
|
const content = readFileSync6(logPath, "utf-8");
|
|
@@ -21543,7 +21673,7 @@ class HookLogger {
|
|
|
21543
21673
|
}
|
|
21544
21674
|
static getHistory(limit2 = 50, hookId) {
|
|
21545
21675
|
const logPath = getLogPath();
|
|
21546
|
-
if (!
|
|
21676
|
+
if (!existsSync9(logPath))
|
|
21547
21677
|
return [];
|
|
21548
21678
|
try {
|
|
21549
21679
|
const content = readFileSync6(logPath, "utf-8");
|
|
@@ -21565,7 +21695,7 @@ class HookLogger {
|
|
|
21565
21695
|
}
|
|
21566
21696
|
static clearHistory() {
|
|
21567
21697
|
const logPath = getLogPath();
|
|
21568
|
-
if (
|
|
21698
|
+
if (existsSync9(logPath)) {
|
|
21569
21699
|
writeFileSync4(logPath, "", "utf-8");
|
|
21570
21700
|
}
|
|
21571
21701
|
}
|
|
@@ -21947,22 +22077,48 @@ var init_logs = __esm(async () => {
|
|
|
21947
22077
|
});
|
|
21948
22078
|
|
|
21949
22079
|
// packages/core/src/sessions/verification.ts
|
|
21950
|
-
|
|
21951
|
-
|
|
22080
|
+
function getDb3() {
|
|
22081
|
+
return getDatabase();
|
|
22082
|
+
}
|
|
22083
|
+
function rowToSession(row) {
|
|
22084
|
+
try {
|
|
22085
|
+
if (row.data) {
|
|
22086
|
+
return JSON.parse(row.data);
|
|
22087
|
+
}
|
|
22088
|
+
const goals = row.goal ? JSON.parse(row.goal) : [];
|
|
22089
|
+
const result = row.result || "fail";
|
|
22090
|
+
return {
|
|
22091
|
+
id: row.id,
|
|
22092
|
+
parentSessionId: row.session_id,
|
|
22093
|
+
type: "scope-verification",
|
|
22094
|
+
result,
|
|
22095
|
+
goals,
|
|
22096
|
+
reason: "",
|
|
22097
|
+
suggestions: [],
|
|
22098
|
+
verificationResult: {
|
|
22099
|
+
goalsMet: result === "pass",
|
|
22100
|
+
goalsAnalysis: [],
|
|
22101
|
+
reason: "",
|
|
22102
|
+
suggestions: []
|
|
22103
|
+
},
|
|
22104
|
+
createdAt: row.created_at
|
|
22105
|
+
};
|
|
22106
|
+
} catch {
|
|
22107
|
+
return null;
|
|
22108
|
+
}
|
|
22109
|
+
}
|
|
21952
22110
|
|
|
21953
22111
|
class VerificationSessionStore {
|
|
21954
|
-
basePath;
|
|
21955
22112
|
maxSessions;
|
|
21956
22113
|
lastTimestamp;
|
|
21957
|
-
|
|
21958
|
-
|
|
22114
|
+
db;
|
|
22115
|
+
constructor(dbOrBasePath, maxSessions = 100) {
|
|
21959
22116
|
this.maxSessions = maxSessions;
|
|
21960
22117
|
this.lastTimestamp = 0;
|
|
21961
|
-
|
|
21962
|
-
|
|
21963
|
-
|
|
21964
|
-
|
|
21965
|
-
mkdirSync8(this.basePath, { recursive: true });
|
|
22118
|
+
if (dbOrBasePath && typeof dbOrBasePath === "object" && "exec" in dbOrBasePath) {
|
|
22119
|
+
this.db = dbOrBasePath;
|
|
22120
|
+
} else {
|
|
22121
|
+
this.db = getDb3();
|
|
21966
22122
|
}
|
|
21967
22123
|
}
|
|
21968
22124
|
create(parentSessionId, goals, verificationResult) {
|
|
@@ -21987,50 +22143,34 @@ class VerificationSessionStore {
|
|
|
21987
22143
|
return session;
|
|
21988
22144
|
}
|
|
21989
22145
|
save(session) {
|
|
21990
|
-
|
|
21991
|
-
|
|
22146
|
+
this.db.prepare(`INSERT OR REPLACE INTO verification_sessions (id, session_id, assistant_id, goal, status, result, created_at, completed_at, data)
|
|
22147
|
+
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
22148
|
}
|
|
21993
22149
|
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 {
|
|
22150
|
+
const row = this.db.query("SELECT * FROM verification_sessions WHERE id = ?").get(id);
|
|
22151
|
+
if (!row)
|
|
22002
22152
|
return null;
|
|
22003
|
-
|
|
22153
|
+
return rowToSession(row);
|
|
22004
22154
|
}
|
|
22005
22155
|
getByParentSession(parentSessionId) {
|
|
22156
|
+
const rows = this.db.query("SELECT * FROM verification_sessions WHERE session_id = ? ORDER BY created_at DESC").all(parentSessionId);
|
|
22006
22157
|
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
|
-
}
|
|
22158
|
+
for (const row of rows) {
|
|
22159
|
+
const session = rowToSession(row);
|
|
22160
|
+
if (session)
|
|
22161
|
+
sessions.push(session);
|
|
22018
22162
|
}
|
|
22019
|
-
return sessions
|
|
22163
|
+
return sessions;
|
|
22020
22164
|
}
|
|
22021
22165
|
listRecent(limit2 = 10) {
|
|
22166
|
+
const rows = this.db.query("SELECT * FROM verification_sessions ORDER BY created_at DESC LIMIT ?").all(limit2);
|
|
22022
22167
|
const sessions = [];
|
|
22023
|
-
const
|
|
22024
|
-
|
|
22025
|
-
|
|
22026
|
-
const content = readFileSync7(join14(this.basePath, file), "utf-8");
|
|
22027
|
-
const session = JSON.parse(content);
|
|
22168
|
+
for (const row of rows) {
|
|
22169
|
+
const session = rowToSession(row);
|
|
22170
|
+
if (session)
|
|
22028
22171
|
sessions.push(session);
|
|
22029
|
-
} catch {
|
|
22030
|
-
continue;
|
|
22031
|
-
}
|
|
22032
22172
|
}
|
|
22033
|
-
return sessions
|
|
22173
|
+
return sessions;
|
|
22034
22174
|
}
|
|
22035
22175
|
updateResult(id, result) {
|
|
22036
22176
|
const session = this.get(id);
|
|
@@ -22039,53 +22179,22 @@ class VerificationSessionStore {
|
|
|
22039
22179
|
session.result = result;
|
|
22040
22180
|
this.save(session);
|
|
22041
22181
|
}
|
|
22042
|
-
listFiles() {
|
|
22043
|
-
if (!existsSync11(this.basePath)) {
|
|
22044
|
-
return [];
|
|
22045
|
-
}
|
|
22046
|
-
return readdirSync6(this.basePath).filter((f) => f.endsWith(".json"));
|
|
22047
|
-
}
|
|
22048
22182
|
pruneOldSessions() {
|
|
22049
|
-
const
|
|
22050
|
-
|
|
22183
|
+
const countRow = this.db.query("SELECT COUNT(*) as cnt FROM verification_sessions").get();
|
|
22184
|
+
const count = countRow?.cnt || 0;
|
|
22185
|
+
if (count <= this.maxSessions)
|
|
22051
22186
|
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
|
-
}
|
|
22187
|
+
this.db.prepare(`DELETE FROM verification_sessions WHERE id IN (
|
|
22188
|
+
SELECT id FROM verification_sessions ORDER BY created_at ASC LIMIT ?
|
|
22189
|
+
)`).run(count - this.maxSessions);
|
|
22075
22190
|
}
|
|
22076
22191
|
clear() {
|
|
22077
|
-
|
|
22078
|
-
for (const file of files) {
|
|
22079
|
-
try {
|
|
22080
|
-
unlinkSync2(join14(this.basePath, file));
|
|
22081
|
-
} catch {
|
|
22082
|
-
continue;
|
|
22083
|
-
}
|
|
22084
|
-
}
|
|
22192
|
+
this.db.prepare("DELETE FROM verification_sessions").run();
|
|
22085
22193
|
}
|
|
22086
22194
|
}
|
|
22087
|
-
var init_verification = __esm(() => {
|
|
22195
|
+
var init_verification = __esm(async () => {
|
|
22088
22196
|
init_src2();
|
|
22197
|
+
await init_database();
|
|
22089
22198
|
});
|
|
22090
22199
|
|
|
22091
22200
|
// packages/core/src/hooks/loader.ts
|
|
@@ -22226,7 +22335,7 @@ var init_background = __esm(() => {
|
|
|
22226
22335
|
});
|
|
22227
22336
|
|
|
22228
22337
|
// packages/core/src/hooks/executor.ts
|
|
22229
|
-
import { existsSync as
|
|
22338
|
+
import { existsSync as existsSync10 } from "fs";
|
|
22230
22339
|
function killSpawnedProcess(proc) {
|
|
22231
22340
|
proc.kill();
|
|
22232
22341
|
}
|
|
@@ -22357,7 +22466,7 @@ class HookExecutor {
|
|
|
22357
22466
|
}
|
|
22358
22467
|
try {
|
|
22359
22468
|
const runtime = getRuntime();
|
|
22360
|
-
const cwd = input.cwd &&
|
|
22469
|
+
const cwd = input.cwd && existsSync10(input.cwd) ? input.cwd : process.cwd();
|
|
22361
22470
|
const isWindows = process.platform === "win32";
|
|
22362
22471
|
const shellBinary = isWindows ? "cmd" : runtime.which("bash") || "sh";
|
|
22363
22472
|
const shellArgs = isWindows ? ["/c", hook.command] : ["-lc", hook.command];
|
|
@@ -22410,7 +22519,7 @@ class HookExecutor {
|
|
|
22410
22519
|
return null;
|
|
22411
22520
|
try {
|
|
22412
22521
|
const runtime = getRuntime();
|
|
22413
|
-
const cwd = input.cwd &&
|
|
22522
|
+
const cwd = input.cwd && existsSync10(input.cwd) ? input.cwd : process.cwd();
|
|
22414
22523
|
const isWindows = process.platform === "win32";
|
|
22415
22524
|
const shellBinary = isWindows ? "cmd" : runtime.which("bash") || "sh";
|
|
22416
22525
|
const shellArgs = isWindows ? ["/c", hook.command] : ["-lc", hook.command];
|
|
@@ -22991,13 +23100,15 @@ Respond with ONLY valid JSON in this exact format:
|
|
|
22991
23100
|
}`;
|
|
22992
23101
|
var init_scope_verification = __esm(async () => {
|
|
22993
23102
|
init_src2();
|
|
22994
|
-
|
|
22995
|
-
|
|
23103
|
+
await __promiseAll([
|
|
23104
|
+
init_verification(),
|
|
23105
|
+
init_config()
|
|
23106
|
+
]);
|
|
22996
23107
|
});
|
|
22997
23108
|
|
|
22998
23109
|
// packages/core/src/hooks/store.ts
|
|
22999
|
-
import { readFileSync as
|
|
23000
|
-
import { join as
|
|
23110
|
+
import { readFileSync as readFileSync7, writeFileSync as writeFileSync5, existsSync as existsSync11, mkdirSync as mkdirSync7 } from "fs";
|
|
23111
|
+
import { join as join13, dirname as dirname6 } from "path";
|
|
23001
23112
|
import { createHash as createHash2 } from "crypto";
|
|
23002
23113
|
function generateHookId2(event, hook) {
|
|
23003
23114
|
const content = hook.command || hook.prompt || "";
|
|
@@ -23026,20 +23137,20 @@ class HookStore {
|
|
|
23026
23137
|
getFilePath(location) {
|
|
23027
23138
|
switch (location) {
|
|
23028
23139
|
case "user":
|
|
23029
|
-
return
|
|
23140
|
+
return join13(this.baseDir || getConfigDir(), "hooks.json");
|
|
23030
23141
|
case "project":
|
|
23031
|
-
return
|
|
23142
|
+
return join13(this.cwd, ".assistants", "hooks.json");
|
|
23032
23143
|
case "local":
|
|
23033
|
-
return
|
|
23144
|
+
return join13(this.cwd, ".assistants", "hooks.local.json");
|
|
23034
23145
|
}
|
|
23035
23146
|
}
|
|
23036
23147
|
loadFrom(location) {
|
|
23037
23148
|
const filePath = this.getFilePath(location);
|
|
23038
|
-
if (!
|
|
23149
|
+
if (!existsSync11(filePath)) {
|
|
23039
23150
|
return {};
|
|
23040
23151
|
}
|
|
23041
23152
|
try {
|
|
23042
|
-
const content =
|
|
23153
|
+
const content = readFileSync7(filePath, "utf-8");
|
|
23043
23154
|
const data = JSON.parse(content);
|
|
23044
23155
|
const config = data.hooks || data;
|
|
23045
23156
|
ensureHookIds(config);
|
|
@@ -23050,12 +23161,12 @@ class HookStore {
|
|
|
23050
23161
|
}
|
|
23051
23162
|
save(location, config) {
|
|
23052
23163
|
const filePath = this.getFilePath(location);
|
|
23053
|
-
const dir =
|
|
23054
|
-
if (!
|
|
23055
|
-
|
|
23164
|
+
const dir = dirname6(filePath);
|
|
23165
|
+
if (!existsSync11(dir)) {
|
|
23166
|
+
mkdirSync7(dir, { recursive: true });
|
|
23056
23167
|
}
|
|
23057
23168
|
ensureHookIds(config);
|
|
23058
|
-
|
|
23169
|
+
writeFileSync5(filePath, JSON.stringify({ hooks: config }, null, 2), "utf-8");
|
|
23059
23170
|
}
|
|
23060
23171
|
loadAll() {
|
|
23061
23172
|
const userHooks = this.loadFrom("user");
|
|
@@ -23194,7 +23305,7 @@ var init_store2 = __esm(async () => {
|
|
|
23194
23305
|
});
|
|
23195
23306
|
|
|
23196
23307
|
// packages/core/src/hooks/tester.ts
|
|
23197
|
-
import { existsSync as
|
|
23308
|
+
import { existsSync as existsSync12 } from "fs";
|
|
23198
23309
|
|
|
23199
23310
|
class HookTester {
|
|
23200
23311
|
cwd;
|
|
@@ -23258,7 +23369,7 @@ class HookTester {
|
|
|
23258
23369
|
}
|
|
23259
23370
|
async executeCommand(command, input, timeout) {
|
|
23260
23371
|
const runtime = getRuntime();
|
|
23261
|
-
const cwd = input.cwd &&
|
|
23372
|
+
const cwd = input.cwd && existsSync12(input.cwd) ? input.cwd : process.cwd();
|
|
23262
23373
|
const isWindows = process.platform === "win32";
|
|
23263
23374
|
const shellBinary = isWindows ? "cmd" : runtime.which("bash") || "sh";
|
|
23264
23375
|
const shellArgs = isWindows ? ["/c", command] : ["-lc", command];
|
|
@@ -23759,8 +23870,8 @@ function registerVerificationTools(registry, context) {
|
|
|
23759
23870
|
}
|
|
23760
23871
|
var verificationListTool, verificationGetTool, verificationStatusTool, verificationEnableTool, verificationDisableTool, verificationTools;
|
|
23761
23872
|
var init_verification2 = __esm(async () => {
|
|
23762
|
-
init_verification();
|
|
23763
23873
|
await __promiseAll([
|
|
23874
|
+
init_verification(),
|
|
23764
23875
|
init_hooks(),
|
|
23765
23876
|
init_config()
|
|
23766
23877
|
]);
|
|
@@ -24679,12 +24790,12 @@ var init_path_validator = __esm(() => {
|
|
|
24679
24790
|
});
|
|
24680
24791
|
|
|
24681
24792
|
// packages/core/src/tools/filesystem.ts
|
|
24682
|
-
import { join as
|
|
24793
|
+
import { join as join14, resolve as resolve4, dirname as dirname7, sep } from "path";
|
|
24683
24794
|
import { homedir as homedir8 } from "os";
|
|
24684
24795
|
import { mkdir as mkdir4 } from "fs/promises";
|
|
24685
24796
|
function getScriptsFolder(cwd, sessionId) {
|
|
24686
24797
|
const resolvedSessionId = sessionId || currentSessionId;
|
|
24687
|
-
return
|
|
24798
|
+
return join14(getProjectDataDir(cwd), "scripts", resolvedSessionId);
|
|
24688
24799
|
}
|
|
24689
24800
|
function isInScriptsFolder(path2, cwd, sessionId) {
|
|
24690
24801
|
const scriptsFolder = resolve4(getScriptsFolder(cwd, sessionId));
|
|
@@ -24947,7 +25058,7 @@ var init_filesystem = __esm(async () => {
|
|
|
24947
25058
|
});
|
|
24948
25059
|
}
|
|
24949
25060
|
const sanitizedFilename = filename.replace(/\.\.[/\\]/g, "").replace(/\.\./g, "").replace(/^[/\\]+/, "");
|
|
24950
|
-
const path2 =
|
|
25061
|
+
const path2 = join14(scriptsFolder, sanitizedFilename);
|
|
24951
25062
|
if (!isInScriptsFolder(path2, baseCwd, input.sessionId)) {
|
|
24952
25063
|
throw new ToolExecutionError(`Cannot write outside scripts folder. Files are saved to ${scriptsFolder}`, {
|
|
24953
25064
|
toolName: "write",
|
|
@@ -24990,7 +25101,7 @@ var init_filesystem = __esm(async () => {
|
|
|
24990
25101
|
retryable: false
|
|
24991
25102
|
});
|
|
24992
25103
|
}
|
|
24993
|
-
const dir =
|
|
25104
|
+
const dir = dirname7(validated.resolved);
|
|
24994
25105
|
await mkdir4(dir, { recursive: true });
|
|
24995
25106
|
const runtime = getRuntime();
|
|
24996
25107
|
await runtime.write(validated.resolved, content);
|
|
@@ -25198,7 +25309,7 @@ var init_filesystem = __esm(async () => {
|
|
|
25198
25309
|
if (file.includes(".Trash") || file.includes(".Spotlight-V100") || file.includes(".fseventsd")) {
|
|
25199
25310
|
continue;
|
|
25200
25311
|
}
|
|
25201
|
-
const filePath =
|
|
25312
|
+
const filePath = join14(validated.resolved, file);
|
|
25202
25313
|
try {
|
|
25203
25314
|
const content = await runtime.file(filePath).text();
|
|
25204
25315
|
const lines = content.split(`
|
|
@@ -26128,8 +26239,8 @@ ${responseBody || "(empty response)"}`;
|
|
|
26128
26239
|
});
|
|
26129
26240
|
|
|
26130
26241
|
// packages/core/src/tools/feedback.ts
|
|
26131
|
-
import { join as
|
|
26132
|
-
import { mkdirSync as
|
|
26242
|
+
import { join as join15 } from "path";
|
|
26243
|
+
import { mkdirSync as mkdirSync8, writeFileSync as writeFileSync6 } from "fs";
|
|
26133
26244
|
function normalizeTags(value) {
|
|
26134
26245
|
if (Array.isArray(value)) {
|
|
26135
26246
|
const tags = value.map((t) => String(t).trim()).filter(Boolean);
|
|
@@ -26143,13 +26254,13 @@ function normalizeTags(value) {
|
|
|
26143
26254
|
}
|
|
26144
26255
|
function resolveFeedbackDir(cwd) {
|
|
26145
26256
|
const baseCwd = cwd && cwd.trim().length > 0 ? cwd : process.cwd();
|
|
26146
|
-
return
|
|
26257
|
+
return join15(getProjectDataDir(baseCwd), "feedback");
|
|
26147
26258
|
}
|
|
26148
26259
|
function saveFeedbackEntry(entry, cwd) {
|
|
26149
26260
|
const feedbackDir = resolveFeedbackDir(cwd);
|
|
26150
|
-
|
|
26151
|
-
const path2 =
|
|
26152
|
-
|
|
26261
|
+
mkdirSync8(feedbackDir, { recursive: true });
|
|
26262
|
+
const path2 = join15(feedbackDir, `${entry.id}.json`);
|
|
26263
|
+
writeFileSync6(path2, JSON.stringify(entry, null, 2));
|
|
26153
26264
|
return { path: path2 };
|
|
26154
26265
|
}
|
|
26155
26266
|
function buildEntry(input, overrides) {
|
|
@@ -26248,7 +26359,7 @@ Path: ${path2}`;
|
|
|
26248
26359
|
});
|
|
26249
26360
|
|
|
26250
26361
|
// packages/core/src/scheduler/store.ts
|
|
26251
|
-
function
|
|
26362
|
+
function getDb4() {
|
|
26252
26363
|
return getDatabase();
|
|
26253
26364
|
}
|
|
26254
26365
|
function rowToSchedule(row) {
|
|
@@ -26269,7 +26380,7 @@ function rowToSchedule(row) {
|
|
|
26269
26380
|
};
|
|
26270
26381
|
}
|
|
26271
26382
|
async function listSchedules(cwd, options) {
|
|
26272
|
-
const rows =
|
|
26383
|
+
const rows = getDb4().query("SELECT * FROM schedules WHERE project_path = ?").all(cwd);
|
|
26273
26384
|
const schedules = rows.map(rowToSchedule);
|
|
26274
26385
|
if (options?.sessionId && !options?.global) {
|
|
26275
26386
|
return schedules.filter((s) => s.sessionId === options.sessionId || !s.sessionId);
|
|
@@ -26279,17 +26390,17 @@ async function listSchedules(cwd, options) {
|
|
|
26279
26390
|
async function saveSchedule(cwd, schedule) {
|
|
26280
26391
|
const scheduleJson = JSON.stringify(schedule.schedule);
|
|
26281
26392
|
const data = JSON.stringify(schedule);
|
|
26282
|
-
|
|
26393
|
+
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
26394
|
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
26395
|
}
|
|
26285
26396
|
async function getSchedule(cwd, id) {
|
|
26286
|
-
const row =
|
|
26397
|
+
const row = getDb4().query("SELECT * FROM schedules WHERE id = ?").get(id);
|
|
26287
26398
|
if (!row)
|
|
26288
26399
|
return null;
|
|
26289
26400
|
return rowToSchedule(row);
|
|
26290
26401
|
}
|
|
26291
26402
|
async function deleteSchedule(cwd, id) {
|
|
26292
|
-
const result =
|
|
26403
|
+
const result = getDb4().prepare("DELETE FROM schedules WHERE id = ?").run(id);
|
|
26293
26404
|
return result.changes > 0;
|
|
26294
26405
|
}
|
|
26295
26406
|
function computeNextRun2(schedule, fromTime) {
|
|
@@ -26340,11 +26451,11 @@ function computeIntervalNextRun(schedule, fromTime) {
|
|
|
26340
26451
|
return fromTime + intervalMs;
|
|
26341
26452
|
}
|
|
26342
26453
|
async function getDueSchedules(cwd, nowTime) {
|
|
26343
|
-
const rows =
|
|
26454
|
+
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
26455
|
return rows.map(rowToSchedule).filter((s) => Number.isFinite(s.nextRunAt));
|
|
26345
26456
|
}
|
|
26346
26457
|
async function updateSchedule(cwd, id, updater, _options) {
|
|
26347
|
-
const d =
|
|
26458
|
+
const d = getDb4();
|
|
26348
26459
|
return d.transaction(() => {
|
|
26349
26460
|
const row = d.query("SELECT * FROM schedules WHERE id = ?").get(id);
|
|
26350
26461
|
if (!row)
|
|
@@ -26704,9 +26815,9 @@ var init_scheduler = __esm(async () => {
|
|
|
26704
26815
|
});
|
|
26705
26816
|
|
|
26706
26817
|
// packages/core/src/tools/image.ts
|
|
26707
|
-
import { existsSync as
|
|
26818
|
+
import { existsSync as existsSync13, writeFileSync as writeFileSync7 } from "fs";
|
|
26708
26819
|
import { tmpdir } from "os";
|
|
26709
|
-
import { join as
|
|
26820
|
+
import { join as join16, basename as basename3 } from "path";
|
|
26710
26821
|
|
|
26711
26822
|
class ImageTools {
|
|
26712
26823
|
static registerAll(registry) {
|
|
@@ -26801,8 +26912,8 @@ var init_image = __esm(() => {
|
|
|
26801
26912
|
offset += chunk.length;
|
|
26802
26913
|
}
|
|
26803
26914
|
const ext = contentType.split("/")[1]?.split(";")[0] || "png";
|
|
26804
|
-
const tempFile =
|
|
26805
|
-
|
|
26915
|
+
const tempFile = join16(tmpdir(), `assistants-image-${generateId()}.${ext}`);
|
|
26916
|
+
writeFileSync7(tempFile, buffer);
|
|
26806
26917
|
localPath = tempFile;
|
|
26807
26918
|
} catch (error2) {
|
|
26808
26919
|
if (error2 instanceof Error && error2.name === "AbortError") {
|
|
@@ -26811,7 +26922,7 @@ var init_image = __esm(() => {
|
|
|
26811
26922
|
return `Error: Failed to fetch image: ${error2 instanceof Error ? error2.message : String(error2)}`;
|
|
26812
26923
|
}
|
|
26813
26924
|
}
|
|
26814
|
-
if (!
|
|
26925
|
+
if (!existsSync13(localPath)) {
|
|
26815
26926
|
return `Error: Image file not found: ${localPath}`;
|
|
26816
26927
|
}
|
|
26817
26928
|
return JSON.stringify({
|
|
@@ -26826,18 +26937,18 @@ var init_image = __esm(() => {
|
|
|
26826
26937
|
});
|
|
26827
26938
|
|
|
26828
26939
|
// packages/core/src/voice/utils.ts
|
|
26829
|
-
import { existsSync as
|
|
26940
|
+
import { existsSync as existsSync14, readFileSync as readFileSync8 } from "fs";
|
|
26830
26941
|
import { homedir as homedir9 } from "os";
|
|
26831
|
-
import { join as
|
|
26942
|
+
import { join as join17 } from "path";
|
|
26832
26943
|
import { spawnSync } from "child_process";
|
|
26833
26944
|
function loadApiKeyFromSecrets2(key) {
|
|
26834
26945
|
const envHome = process.env.HOME || process.env.USERPROFILE;
|
|
26835
26946
|
const homeDir = envHome && envHome.trim().length > 0 ? envHome : homedir9();
|
|
26836
|
-
const secretsPath =
|
|
26837
|
-
if (!
|
|
26947
|
+
const secretsPath = join17(homeDir, ".secrets");
|
|
26948
|
+
if (!existsSync14(secretsPath))
|
|
26838
26949
|
return;
|
|
26839
26950
|
try {
|
|
26840
|
-
const content =
|
|
26951
|
+
const content = readFileSync8(secretsPath, "utf-8");
|
|
26841
26952
|
const match = content.match(new RegExp(`export\\s+${key}\\s*=\\s*['"]?([^'"\\n]+)['"]?`));
|
|
26842
26953
|
return match?.[1];
|
|
26843
26954
|
} catch {
|
|
@@ -27289,7 +27400,7 @@ ${result.text}`;
|
|
|
27289
27400
|
});
|
|
27290
27401
|
|
|
27291
27402
|
// packages/core/src/skills/create.ts
|
|
27292
|
-
import { join as
|
|
27403
|
+
import { join as join18, dirname as dirname8 } from "path";
|
|
27293
27404
|
import { homedir as homedir11 } from "os";
|
|
27294
27405
|
import { mkdir as mkdir5, stat, writeFile as writeFile2, rm } from "fs/promises";
|
|
27295
27406
|
function slugify(input) {
|
|
@@ -27347,9 +27458,9 @@ function buildDefaultContent() {
|
|
|
27347
27458
|
}
|
|
27348
27459
|
function resolveSkillRoot(scope, cwd) {
|
|
27349
27460
|
if (scope === "global") {
|
|
27350
|
-
return
|
|
27461
|
+
return join18(homedir11(), ".skill");
|
|
27351
27462
|
}
|
|
27352
|
-
return
|
|
27463
|
+
return join18(cwd, ".skill");
|
|
27353
27464
|
}
|
|
27354
27465
|
async function pathExists(path2) {
|
|
27355
27466
|
try {
|
|
@@ -27360,15 +27471,15 @@ async function pathExists(path2) {
|
|
|
27360
27471
|
}
|
|
27361
27472
|
}
|
|
27362
27473
|
async function deleteSkill(filePath) {
|
|
27363
|
-
const skillDir =
|
|
27474
|
+
const skillDir = dirname8(filePath);
|
|
27364
27475
|
await rm(skillDir, { recursive: true });
|
|
27365
27476
|
}
|
|
27366
27477
|
async function createSkill(options) {
|
|
27367
27478
|
const scope = options.scope ?? "project";
|
|
27368
27479
|
const { skillName, dirName } = normalizeName2(options.name);
|
|
27369
27480
|
const root = resolveSkillRoot(scope, options.cwd);
|
|
27370
|
-
const directory =
|
|
27371
|
-
const filePath =
|
|
27481
|
+
const directory = join18(root, dirName);
|
|
27482
|
+
const filePath = join18(directory, "SKILL.md");
|
|
27372
27483
|
if (!options.overwrite && await pathExists(filePath)) {
|
|
27373
27484
|
throw new Error(`Skill already exists at ${filePath}`);
|
|
27374
27485
|
}
|
|
@@ -27390,7 +27501,7 @@ ${content}
|
|
|
27390
27501
|
var init_create = () => {};
|
|
27391
27502
|
|
|
27392
27503
|
// packages/core/src/skills/executor.ts
|
|
27393
|
-
import { dirname as
|
|
27504
|
+
import { dirname as dirname9 } from "path";
|
|
27394
27505
|
|
|
27395
27506
|
class SkillExecutor {
|
|
27396
27507
|
constructor() {}
|
|
@@ -27411,7 +27522,7 @@ ARGUMENTS: ${args.join(" ")}`;
|
|
|
27411
27522
|
if (matches.length === 0) {
|
|
27412
27523
|
return content;
|
|
27413
27524
|
}
|
|
27414
|
-
const skillDir =
|
|
27525
|
+
const skillDir = dirname9(skillFilePath);
|
|
27415
27526
|
let result = content;
|
|
27416
27527
|
const runtime = getRuntime();
|
|
27417
27528
|
for (const match of matches) {
|
|
@@ -27448,25 +27559,25 @@ var init_executor2 = __esm(async () => {
|
|
|
27448
27559
|
});
|
|
27449
27560
|
|
|
27450
27561
|
// packages/core/src/skills/installer.ts
|
|
27451
|
-
import { join as
|
|
27562
|
+
import { join as join19 } from "path";
|
|
27452
27563
|
import { homedir as homedir12 } from "os";
|
|
27453
|
-
import { mkdir as mkdir6, readFile as
|
|
27564
|
+
import { mkdir as mkdir6, readFile as readFile3, writeFile as writeFile3, stat as stat2 } from "fs/promises";
|
|
27454
27565
|
function resolveSkillRoot2(scope, cwd) {
|
|
27455
27566
|
if (scope === "global") {
|
|
27456
|
-
return
|
|
27567
|
+
return join19(homedir12(), ".skill");
|
|
27457
27568
|
}
|
|
27458
|
-
return
|
|
27569
|
+
return join19(cwd || process.cwd(), ".skill");
|
|
27459
27570
|
}
|
|
27460
27571
|
async function ensurePackageJson(dir) {
|
|
27461
27572
|
await mkdir6(dir, { recursive: true });
|
|
27462
|
-
const pkgPath =
|
|
27573
|
+
const pkgPath = join19(dir, "package.json");
|
|
27463
27574
|
try {
|
|
27464
27575
|
await stat2(pkgPath);
|
|
27465
27576
|
} catch {
|
|
27466
27577
|
await writeFile3(pkgPath, JSON.stringify({ name: "assistants-skills", private: true, dependencies: {} }, null, 2) + `
|
|
27467
27578
|
`);
|
|
27468
27579
|
}
|
|
27469
|
-
const gitignorePath =
|
|
27580
|
+
const gitignorePath = join19(dir, ".gitignore");
|
|
27470
27581
|
try {
|
|
27471
27582
|
await stat2(gitignorePath);
|
|
27472
27583
|
} catch {
|
|
@@ -27489,10 +27600,10 @@ async function install(options) {
|
|
|
27489
27600
|
const stderr = result.stderr.toString().trim();
|
|
27490
27601
|
throw new Error(`Failed to install ${packageName}: ${stderr || "unknown error"}`);
|
|
27491
27602
|
}
|
|
27492
|
-
const skillDir =
|
|
27603
|
+
const skillDir = join19(root, "node_modules", "@hasnaxyz", `skill-${rawName}`);
|
|
27493
27604
|
let version = "unknown";
|
|
27494
27605
|
try {
|
|
27495
|
-
const pkgJson = JSON.parse(await
|
|
27606
|
+
const pkgJson = JSON.parse(await readFile3(join19(skillDir, "package.json"), "utf-8"));
|
|
27496
27607
|
version = pkgJson.version || "unknown";
|
|
27497
27608
|
} catch {}
|
|
27498
27609
|
return { name: rawName, packageName, version, skillDir };
|
|
@@ -27515,9 +27626,9 @@ async function uninstall(name, scope, cwd) {
|
|
|
27515
27626
|
async function listInstalled(scope, cwd) {
|
|
27516
27627
|
const resolvedScope = scope ?? "project";
|
|
27517
27628
|
const root = resolveSkillRoot2(resolvedScope, cwd);
|
|
27518
|
-
const pkgPath =
|
|
27629
|
+
const pkgPath = join19(root, "package.json");
|
|
27519
27630
|
try {
|
|
27520
|
-
const pkgJson = JSON.parse(await
|
|
27631
|
+
const pkgJson = JSON.parse(await readFile3(pkgPath, "utf-8"));
|
|
27521
27632
|
const deps = pkgJson.dependencies || {};
|
|
27522
27633
|
const results = [];
|
|
27523
27634
|
for (const [name, version] of Object.entries(deps)) {
|
|
@@ -33573,9 +33684,9 @@ var require_out4 = __commonJS((exports, module) => {
|
|
|
33573
33684
|
});
|
|
33574
33685
|
|
|
33575
33686
|
// packages/core/src/skills/loader.ts
|
|
33576
|
-
import { join as
|
|
33687
|
+
import { join as join20, basename as basename4, dirname as dirname10 } from "path";
|
|
33577
33688
|
import { homedir as homedir13 } from "os";
|
|
33578
|
-
import { readFile as
|
|
33689
|
+
import { readFile as readFile4, stat as stat3 } from "fs/promises";
|
|
33579
33690
|
|
|
33580
33691
|
class SkillLoader {
|
|
33581
33692
|
skills = new Map;
|
|
@@ -33583,8 +33694,8 @@ class SkillLoader {
|
|
|
33583
33694
|
const includeContent = options.includeContent ?? true;
|
|
33584
33695
|
const envHome = process.env.HOME || process.env.USERPROFILE;
|
|
33585
33696
|
const userHome = envHome && envHome.trim().length > 0 ? envHome : homedir13();
|
|
33586
|
-
const globalRoot =
|
|
33587
|
-
const projectRoot =
|
|
33697
|
+
const globalRoot = join20(userHome, ".skill");
|
|
33698
|
+
const projectRoot = join20(projectDir, ".skill");
|
|
33588
33699
|
await this.loadNpmSkills(globalRoot, { includeContent });
|
|
33589
33700
|
await this.loadLocalSkills(globalRoot, { includeContent });
|
|
33590
33701
|
await this.loadNpmSkills(projectRoot, { includeContent });
|
|
@@ -33593,7 +33704,7 @@ class SkillLoader {
|
|
|
33593
33704
|
async loadNpmSkills(skillRoot, options) {
|
|
33594
33705
|
const includeContent = options.includeContent ?? true;
|
|
33595
33706
|
try {
|
|
33596
|
-
const nmDir =
|
|
33707
|
+
const nmDir = join20(skillRoot, "node_modules", "@hasnaxyz");
|
|
33597
33708
|
try {
|
|
33598
33709
|
const stats = await stat3(nmDir);
|
|
33599
33710
|
if (!stats.isDirectory())
|
|
@@ -33604,10 +33715,10 @@ class SkillLoader {
|
|
|
33604
33715
|
const files = await import_fast_glob.default("skill-*/SKILL.md", { cwd: nmDir });
|
|
33605
33716
|
const tasks = [];
|
|
33606
33717
|
for (const file of files) {
|
|
33607
|
-
const fullPath =
|
|
33718
|
+
const fullPath = join20(nmDir, file);
|
|
33608
33719
|
const dirName = file.split(/[\\/]/)[0];
|
|
33609
33720
|
const packageName = `@hasnaxyz/${dirName}`;
|
|
33610
|
-
const pkgJsonPath =
|
|
33721
|
+
const pkgJsonPath = join20(nmDir, dirName, "package.json");
|
|
33611
33722
|
tasks.push(this.loadNpmSkillFile(fullPath, pkgJsonPath, packageName, { includeContent }));
|
|
33612
33723
|
}
|
|
33613
33724
|
await Promise.all(tasks);
|
|
@@ -33616,7 +33727,7 @@ class SkillLoader {
|
|
|
33616
33727
|
async loadNpmSkillFile(filePath, pkgJsonPath, packageName, options) {
|
|
33617
33728
|
let version;
|
|
33618
33729
|
try {
|
|
33619
|
-
const pkgJson = JSON.parse(await
|
|
33730
|
+
const pkgJson = JSON.parse(await readFile4(pkgJsonPath, "utf-8"));
|
|
33620
33731
|
version = pkgJson.version;
|
|
33621
33732
|
} catch {}
|
|
33622
33733
|
return this.loadSkillFile(filePath, options, {
|
|
@@ -33641,7 +33752,7 @@ class SkillLoader {
|
|
|
33641
33752
|
});
|
|
33642
33753
|
const tasks = [];
|
|
33643
33754
|
for (const file of files) {
|
|
33644
|
-
tasks.push(this.loadSkillFile(
|
|
33755
|
+
tasks.push(this.loadSkillFile(join20(skillRoot, file), { includeContent }, { source: "local" }));
|
|
33645
33756
|
}
|
|
33646
33757
|
await Promise.all(tasks);
|
|
33647
33758
|
} catch {}
|
|
@@ -33659,13 +33770,13 @@ class SkillLoader {
|
|
|
33659
33770
|
const filesToLoad = [];
|
|
33660
33771
|
const skillPrefixFiles = await import_fast_glob.default("skill-*/SKILL.md", { cwd: dir });
|
|
33661
33772
|
for (const file of skillPrefixFiles) {
|
|
33662
|
-
filesToLoad.push(
|
|
33773
|
+
filesToLoad.push(join20(dir, file));
|
|
33663
33774
|
}
|
|
33664
33775
|
const regularFiles = await import_fast_glob.default("*/SKILL.md", { cwd: dir });
|
|
33665
33776
|
for (const file of regularFiles) {
|
|
33666
33777
|
const dirName = file.split(/[\\/]/)[0];
|
|
33667
33778
|
if (!dirName.startsWith("skill-")) {
|
|
33668
|
-
filesToLoad.push(
|
|
33779
|
+
filesToLoad.push(join20(dir, file));
|
|
33669
33780
|
}
|
|
33670
33781
|
}
|
|
33671
33782
|
const loadTasks = [];
|
|
@@ -33677,10 +33788,10 @@ class SkillLoader {
|
|
|
33677
33788
|
}
|
|
33678
33789
|
async loadSkillFile(filePath, options = {}, extra) {
|
|
33679
33790
|
try {
|
|
33680
|
-
const content = await
|
|
33791
|
+
const content = await readFile4(filePath, "utf-8");
|
|
33681
33792
|
const { frontmatter, content: markdownContent } = parseFrontmatter(content);
|
|
33682
33793
|
const includeContent = options.includeContent ?? true;
|
|
33683
|
-
const dirName = basename4(
|
|
33794
|
+
const dirName = basename4(dirname10(filePath));
|
|
33684
33795
|
const name = frontmatter.name || dirName;
|
|
33685
33796
|
let description = frontmatter.description || "";
|
|
33686
33797
|
if (!description && markdownContent) {
|
|
@@ -33789,8 +33900,8 @@ var init_loader2 = __esm(() => {
|
|
|
33789
33900
|
import_fast_glob = __toESM(require_out4(), 1);
|
|
33790
33901
|
});
|
|
33791
33902
|
// packages/core/src/commands/loader.ts
|
|
33792
|
-
import { existsSync as
|
|
33793
|
-
import { join as
|
|
33903
|
+
import { existsSync as existsSync15, readdirSync as readdirSync5, statSync as statSync3 } from "fs";
|
|
33904
|
+
import { join as join21, basename as basename5, extname as extname2 } from "path";
|
|
33794
33905
|
import { homedir as homedir14 } from "os";
|
|
33795
33906
|
|
|
33796
33907
|
class CommandLoader {
|
|
@@ -33803,17 +33914,17 @@ class CommandLoader {
|
|
|
33803
33914
|
this.commands.clear();
|
|
33804
33915
|
const envHome = process.env.HOME || process.env.USERPROFILE;
|
|
33805
33916
|
const homeDir = envHome && envHome.trim().length > 0 ? envHome : homedir14();
|
|
33806
|
-
const globalDir =
|
|
33917
|
+
const globalDir = join21(homeDir, ".assistants", "commands");
|
|
33807
33918
|
await this.loadFromDirectory(globalDir, "global");
|
|
33808
|
-
const projectDir =
|
|
33919
|
+
const projectDir = join21(this.cwd, ".assistants", "commands");
|
|
33809
33920
|
await this.loadFromDirectory(projectDir, "project");
|
|
33810
33921
|
}
|
|
33811
33922
|
async loadFromDirectory(dir, source, prefix = "") {
|
|
33812
|
-
if (!
|
|
33923
|
+
if (!existsSync15(dir))
|
|
33813
33924
|
return;
|
|
33814
|
-
const entries =
|
|
33925
|
+
const entries = readdirSync5(dir);
|
|
33815
33926
|
for (const entry of entries) {
|
|
33816
|
-
const fullPath =
|
|
33927
|
+
const fullPath = join21(dir, entry);
|
|
33817
33928
|
const stat4 = statSync3(fullPath);
|
|
33818
33929
|
if (stat4.isDirectory()) {
|
|
33819
33930
|
const newPrefix = prefix ? `${prefix}:${entry}` : entry;
|
|
@@ -34179,7 +34290,7 @@ function formatAbsoluteTime(timestamp) {
|
|
|
34179
34290
|
return new Date(timestamp).toLocaleString();
|
|
34180
34291
|
}
|
|
34181
34292
|
// packages/core/src/jobs/job-store.ts
|
|
34182
|
-
function
|
|
34293
|
+
function getDb5() {
|
|
34183
34294
|
return getDatabase();
|
|
34184
34295
|
}
|
|
34185
34296
|
function jobToRow(job) {
|
|
@@ -34221,12 +34332,12 @@ function rowToJob(row) {
|
|
|
34221
34332
|
}
|
|
34222
34333
|
async function saveJob(job) {
|
|
34223
34334
|
const params = jobToRow(job);
|
|
34224
|
-
|
|
34335
|
+
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
34336
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(...params);
|
|
34226
34337
|
}
|
|
34227
34338
|
async function readJob(id) {
|
|
34228
34339
|
try {
|
|
34229
|
-
const row =
|
|
34340
|
+
const row = getDb5().query("SELECT * FROM jobs WHERE id = ?").get(id);
|
|
34230
34341
|
if (!row)
|
|
34231
34342
|
return null;
|
|
34232
34343
|
return rowToJob(row);
|
|
@@ -34236,7 +34347,7 @@ async function readJob(id) {
|
|
|
34236
34347
|
}
|
|
34237
34348
|
async function deleteJob(id) {
|
|
34238
34349
|
try {
|
|
34239
|
-
const result =
|
|
34350
|
+
const result = getDb5().prepare("DELETE FROM jobs WHERE id = ?").run(id);
|
|
34240
34351
|
return result.changes > 0;
|
|
34241
34352
|
} catch {
|
|
34242
34353
|
return false;
|
|
@@ -34244,7 +34355,7 @@ async function deleteJob(id) {
|
|
|
34244
34355
|
}
|
|
34245
34356
|
async function listJobs() {
|
|
34246
34357
|
try {
|
|
34247
|
-
const rows =
|
|
34358
|
+
const rows = getDb5().query("SELECT * FROM jobs ORDER BY created_at DESC").all();
|
|
34248
34359
|
return rows.map(rowToJob);
|
|
34249
34360
|
} catch {
|
|
34250
34361
|
return [];
|
|
@@ -34252,7 +34363,7 @@ async function listJobs() {
|
|
|
34252
34363
|
}
|
|
34253
34364
|
async function listJobsForSession(sessionId) {
|
|
34254
34365
|
try {
|
|
34255
|
-
const rows =
|
|
34366
|
+
const rows = getDb5().query("SELECT * FROM jobs WHERE session_id = ? ORDER BY created_at DESC").all(sessionId);
|
|
34256
34367
|
return rows.map(rowToJob);
|
|
34257
34368
|
} catch {
|
|
34258
34369
|
return [];
|
|
@@ -34260,7 +34371,7 @@ async function listJobsForSession(sessionId) {
|
|
|
34260
34371
|
}
|
|
34261
34372
|
async function listJobsByStatus(status) {
|
|
34262
34373
|
try {
|
|
34263
|
-
const rows =
|
|
34374
|
+
const rows = getDb5().query("SELECT * FROM jobs WHERE status = ? ORDER BY created_at DESC").all(status);
|
|
34264
34375
|
return rows.map(rowToJob);
|
|
34265
34376
|
} catch {
|
|
34266
34377
|
return [];
|
|
@@ -34879,7 +34990,7 @@ var init_types3 = __esm(() => {
|
|
|
34879
34990
|
});
|
|
34880
34991
|
|
|
34881
34992
|
// packages/core/src/tasks/store.ts
|
|
34882
|
-
function
|
|
34993
|
+
function getDb6() {
|
|
34883
34994
|
return getDatabase();
|
|
34884
34995
|
}
|
|
34885
34996
|
function rowToTask(row) {
|
|
@@ -34943,7 +35054,7 @@ async function loadTaskStore(cwd) {
|
|
|
34943
35054
|
}
|
|
34944
35055
|
async function saveTaskStore(_cwd, _data) {}
|
|
34945
35056
|
async function getTasks(cwd) {
|
|
34946
|
-
const rows =
|
|
35057
|
+
const rows = getDb6().query("SELECT * FROM tasks WHERE project_path = ? ORDER BY created_at").all(cwd);
|
|
34947
35058
|
const tasks = rows.map(rowToTask);
|
|
34948
35059
|
const knownIds = new Set(tasks.map((t) => t.id));
|
|
34949
35060
|
for (const task of tasks) {
|
|
@@ -34959,7 +35070,7 @@ async function getTasks(cwd) {
|
|
|
34959
35070
|
return tasks;
|
|
34960
35071
|
}
|
|
34961
35072
|
async function getTask(cwd, id) {
|
|
34962
|
-
const row =
|
|
35073
|
+
const row = getDb6().query("SELECT * FROM tasks WHERE project_path = ? AND id = ?").get(cwd, id);
|
|
34963
35074
|
return row ? rowToTask(row) : null;
|
|
34964
35075
|
}
|
|
34965
35076
|
async function resolveTaskId(cwd, idOrPrefix, filter) {
|
|
@@ -34973,7 +35084,7 @@ async function resolveTaskId(cwd, idOrPrefix, filter) {
|
|
|
34973
35084
|
return { task: matches.length === 1 ? matches[0] : null, matches };
|
|
34974
35085
|
}
|
|
34975
35086
|
async function addTask(cwd, options, priority = "normal", projectId) {
|
|
34976
|
-
const d =
|
|
35087
|
+
const d = getDb6();
|
|
34977
35088
|
return d.transaction(() => {
|
|
34978
35089
|
const now2 = Date.now();
|
|
34979
35090
|
const opts = typeof options === "string" ? { description: options, priority, projectId } : options;
|
|
@@ -35042,7 +35153,7 @@ async function addTask(cwd, options, priority = "normal", projectId) {
|
|
|
35042
35153
|
});
|
|
35043
35154
|
}
|
|
35044
35155
|
async function updateTask(cwd, id, updates) {
|
|
35045
|
-
const d =
|
|
35156
|
+
const d = getDb6();
|
|
35046
35157
|
const row = d.query("SELECT * FROM tasks WHERE project_path = ? AND id = ?").get(cwd, id);
|
|
35047
35158
|
if (!row)
|
|
35048
35159
|
return null;
|
|
@@ -35080,7 +35191,7 @@ async function updateTask(cwd, id, updates) {
|
|
|
35080
35191
|
return updated ? rowToTask(updated) : null;
|
|
35081
35192
|
}
|
|
35082
35193
|
async function deleteTask(cwd, id) {
|
|
35083
|
-
const d =
|
|
35194
|
+
const d = getDb6();
|
|
35084
35195
|
return d.transaction(() => {
|
|
35085
35196
|
const row = d.query("SELECT * FROM tasks WHERE project_path = ? AND id = ?").get(cwd, id);
|
|
35086
35197
|
if (!row)
|
|
@@ -35107,7 +35218,7 @@ async function deleteTask(cwd, id) {
|
|
|
35107
35218
|
});
|
|
35108
35219
|
}
|
|
35109
35220
|
async function clearPendingTasks(cwd) {
|
|
35110
|
-
const d =
|
|
35221
|
+
const d = getDb6();
|
|
35111
35222
|
return d.transaction(() => {
|
|
35112
35223
|
const pending = d.query("SELECT id FROM tasks WHERE project_path = ? AND status = 'pending'").all(cwd);
|
|
35113
35224
|
if (pending.length === 0)
|
|
@@ -35132,7 +35243,7 @@ async function clearPendingTasks(cwd) {
|
|
|
35132
35243
|
});
|
|
35133
35244
|
}
|
|
35134
35245
|
async function clearCompletedTasks(cwd) {
|
|
35135
|
-
const d =
|
|
35246
|
+
const d = getDb6();
|
|
35136
35247
|
return d.transaction(() => {
|
|
35137
35248
|
const completed = d.query("SELECT id FROM tasks WHERE project_path = ? AND (status = 'completed' OR status = 'failed')").all(cwd);
|
|
35138
35249
|
if (completed.length === 0)
|
|
@@ -35178,18 +35289,18 @@ async function getNextTask(cwd) {
|
|
|
35178
35289
|
return pending[0];
|
|
35179
35290
|
}
|
|
35180
35291
|
async function isPaused(cwd) {
|
|
35181
|
-
const row =
|
|
35292
|
+
const row = getDb6().query("SELECT paused FROM task_queue_settings WHERE project_path = ?").get(cwd);
|
|
35182
35293
|
return row ? row.paused === 1 : false;
|
|
35183
35294
|
}
|
|
35184
35295
|
async function setPaused(cwd, paused) {
|
|
35185
|
-
|
|
35296
|
+
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
35297
|
}
|
|
35187
35298
|
async function isAutoRun(cwd) {
|
|
35188
|
-
const row =
|
|
35299
|
+
const row = getDb6().query("SELECT auto_run FROM task_queue_settings WHERE project_path = ?").get(cwd);
|
|
35189
35300
|
return row ? row.auto_run === 1 : true;
|
|
35190
35301
|
}
|
|
35191
35302
|
async function setAutoRun(cwd, autoRun) {
|
|
35192
|
-
|
|
35303
|
+
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
35304
|
}
|
|
35194
35305
|
async function startTask(cwd, id) {
|
|
35195
35306
|
return updateTask(cwd, id, {
|
|
@@ -35212,7 +35323,7 @@ async function failTask(cwd, id, error2) {
|
|
|
35212
35323
|
});
|
|
35213
35324
|
}
|
|
35214
35325
|
async function getTaskCounts(cwd) {
|
|
35215
|
-
const rows =
|
|
35326
|
+
const rows = getDb6().query("SELECT status, COUNT(*) as cnt FROM tasks WHERE project_path = ? GROUP BY status").all(cwd);
|
|
35216
35327
|
const counts = {
|
|
35217
35328
|
pending: 0,
|
|
35218
35329
|
in_progress: 0,
|
|
@@ -35225,16 +35336,16 @@ async function getTaskCounts(cwd) {
|
|
|
35225
35336
|
return counts;
|
|
35226
35337
|
}
|
|
35227
35338
|
async function getRecurringTasks(cwd) {
|
|
35228
|
-
const rows =
|
|
35339
|
+
const rows = getDb6().query("SELECT * FROM tasks WHERE project_path = ? AND is_recurring_template = 1").all(cwd);
|
|
35229
35340
|
return rows.map(rowToTask);
|
|
35230
35341
|
}
|
|
35231
35342
|
async function getDueRecurringTasks(cwd) {
|
|
35232
35343
|
const now2 = Date.now();
|
|
35233
|
-
const rows =
|
|
35344
|
+
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
35345
|
return rows.map(rowToTask);
|
|
35235
35346
|
}
|
|
35236
35347
|
async function createRecurringInstance(cwd, templateId) {
|
|
35237
|
-
const d =
|
|
35348
|
+
const d = getDb6();
|
|
35238
35349
|
return d.transaction(() => {
|
|
35239
35350
|
const row = d.query("SELECT * FROM tasks WHERE project_path = ? AND id = ? AND is_recurring_template = 1").get(cwd, templateId);
|
|
35240
35351
|
if (!row || !row.recurrence)
|
|
@@ -35281,7 +35392,7 @@ async function processDueRecurringTasks(cwd) {
|
|
|
35281
35392
|
return createdInstances;
|
|
35282
35393
|
}
|
|
35283
35394
|
async function cancelRecurringTask(cwd, id) {
|
|
35284
|
-
const d =
|
|
35395
|
+
const d = getDb6();
|
|
35285
35396
|
return d.transaction(() => {
|
|
35286
35397
|
const row = d.query("SELECT * FROM tasks WHERE project_path = ? AND id = ? AND is_recurring_template = 1").get(cwd, id);
|
|
35287
35398
|
if (!row)
|
|
@@ -35734,8 +35845,8 @@ var init_evaluator = __esm(() => {
|
|
|
35734
35845
|
});
|
|
35735
35846
|
|
|
35736
35847
|
// packages/core/src/guardrails/store.ts
|
|
35737
|
-
import { readFileSync as
|
|
35738
|
-
import { join as
|
|
35848
|
+
import { readFileSync as readFileSync9, writeFileSync as writeFileSync8, existsSync as existsSync16, mkdirSync as mkdirSync9 } from "fs";
|
|
35849
|
+
import { join as join22, dirname as dirname11 } from "path";
|
|
35739
35850
|
import { createHash as createHash3 } from "crypto";
|
|
35740
35851
|
function generatePolicyId(name, scope) {
|
|
35741
35852
|
const hash = createHash3("sha256").update(`${name}-${scope}-${Date.now()}`).digest("hex").slice(0, 8);
|
|
@@ -35759,20 +35870,20 @@ class GuardrailsStore {
|
|
|
35759
35870
|
getFilePath(location) {
|
|
35760
35871
|
switch (location) {
|
|
35761
35872
|
case "user":
|
|
35762
|
-
return
|
|
35873
|
+
return join22(this.baseDir || getConfigDir(), "guardrails.json");
|
|
35763
35874
|
case "project":
|
|
35764
|
-
return
|
|
35875
|
+
return join22(this.cwd, ".assistants", "guardrails.json");
|
|
35765
35876
|
case "local":
|
|
35766
|
-
return
|
|
35877
|
+
return join22(this.cwd, ".assistants", "guardrails.local.json");
|
|
35767
35878
|
}
|
|
35768
35879
|
}
|
|
35769
35880
|
loadFrom(location) {
|
|
35770
35881
|
const filePath = this.getFilePath(location);
|
|
35771
|
-
if (!
|
|
35882
|
+
if (!existsSync16(filePath)) {
|
|
35772
35883
|
return null;
|
|
35773
35884
|
}
|
|
35774
35885
|
try {
|
|
35775
|
-
const content =
|
|
35886
|
+
const content = readFileSync9(filePath, "utf-8");
|
|
35776
35887
|
const data = JSON.parse(content);
|
|
35777
35888
|
const config = data.guardrails || data;
|
|
35778
35889
|
ensurePolicyIds(config);
|
|
@@ -35783,12 +35894,12 @@ class GuardrailsStore {
|
|
|
35783
35894
|
}
|
|
35784
35895
|
save(location, config) {
|
|
35785
35896
|
const filePath = this.getFilePath(location);
|
|
35786
|
-
const dir =
|
|
35787
|
-
if (!
|
|
35788
|
-
|
|
35897
|
+
const dir = dirname11(filePath);
|
|
35898
|
+
if (!existsSync16(dir)) {
|
|
35899
|
+
mkdirSync9(dir, { recursive: true });
|
|
35789
35900
|
}
|
|
35790
35901
|
ensurePolicyIds(config);
|
|
35791
|
-
|
|
35902
|
+
writeFileSync8(filePath, JSON.stringify({ guardrails: config }, null, 2), "utf-8");
|
|
35792
35903
|
}
|
|
35793
35904
|
loadAll() {
|
|
35794
35905
|
const userConfig = this.loadFrom("user");
|
|
@@ -65188,8 +65299,8 @@ var require_core3 = __commonJS((exports) => {
|
|
|
65188
65299
|
function many1(p) {
|
|
65189
65300
|
return ab(p, many(p), (head, tail) => [head, ...tail]);
|
|
65190
65301
|
}
|
|
65191
|
-
function ab(pa, pb,
|
|
65192
|
-
return (data, i) => mapOuter(pa(data, i), (ma) => mapInner(pb(data, ma.position), (vb, j) =>
|
|
65302
|
+
function ab(pa, pb, join23) {
|
|
65303
|
+
return (data, i) => mapOuter(pa(data, i), (ma) => mapInner(pb(data, ma.position), (vb, j) => join23(ma.value, vb, data, i, j)));
|
|
65193
65304
|
}
|
|
65194
65305
|
function left(pa, pb) {
|
|
65195
65306
|
return ab(pa, pb, (va) => va);
|
|
@@ -65197,8 +65308,8 @@ var require_core3 = __commonJS((exports) => {
|
|
|
65197
65308
|
function right(pa, pb) {
|
|
65198
65309
|
return ab(pa, pb, (va, vb) => vb);
|
|
65199
65310
|
}
|
|
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) =>
|
|
65311
|
+
function abc(pa, pb, pc, join23) {
|
|
65312
|
+
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
65313
|
}
|
|
65203
65314
|
function middle(pa, pb, pc) {
|
|
65204
65315
|
return abc(pa, pb, pc, (ra, rb) => rb);
|
|
@@ -73911,82 +74022,89 @@ var init_email_parser = __esm(() => {
|
|
|
73911
74022
|
import_mailparser = __toESM(require_mailparser(), 1);
|
|
73912
74023
|
});
|
|
73913
74024
|
|
|
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
74025
|
// packages/core/src/workspace/shared.ts
|
|
73931
|
-
import { join as
|
|
74026
|
+
import { join as join23 } from "path";
|
|
73932
74027
|
import {
|
|
73933
|
-
existsSync as
|
|
73934
|
-
mkdirSync as
|
|
73935
|
-
readFileSync as readFileSync11,
|
|
73936
|
-
readdirSync as readdirSync8,
|
|
74028
|
+
existsSync as existsSync17,
|
|
74029
|
+
mkdirSync as mkdirSync10,
|
|
73937
74030
|
rmSync,
|
|
73938
|
-
renameSync
|
|
74031
|
+
renameSync,
|
|
74032
|
+
readdirSync as readdirSync6
|
|
73939
74033
|
} from "fs";
|
|
74034
|
+
function getDb7() {
|
|
74035
|
+
return getDatabase();
|
|
74036
|
+
}
|
|
74037
|
+
function rowToWorkspace(row) {
|
|
74038
|
+
let participants = [];
|
|
74039
|
+
try {
|
|
74040
|
+
participants = JSON.parse(row.participants);
|
|
74041
|
+
} catch {
|
|
74042
|
+
participants = [];
|
|
74043
|
+
}
|
|
74044
|
+
return {
|
|
74045
|
+
id: row.id,
|
|
74046
|
+
name: row.name,
|
|
74047
|
+
description: row.description || undefined,
|
|
74048
|
+
createdAt: new Date(row.created_at).getTime(),
|
|
74049
|
+
updatedAt: new Date(row.updated_at).getTime(),
|
|
74050
|
+
createdBy: row.creator_id,
|
|
74051
|
+
participants,
|
|
74052
|
+
status: row.status
|
|
74053
|
+
};
|
|
74054
|
+
}
|
|
73940
74055
|
|
|
73941
74056
|
class SharedWorkspaceManager {
|
|
73942
74057
|
basePath;
|
|
73943
|
-
|
|
73944
|
-
|
|
74058
|
+
db;
|
|
74059
|
+
constructor(basePath, db) {
|
|
74060
|
+
this.basePath = basePath || join23(getConfigDir(), "workspaces");
|
|
74061
|
+
this.db = db || getDb7();
|
|
73945
74062
|
this.ensureDir();
|
|
73946
74063
|
this.migrateAgentsToAssistants();
|
|
73947
74064
|
}
|
|
73948
74065
|
ensureDir() {
|
|
73949
|
-
if (!
|
|
73950
|
-
|
|
74066
|
+
if (!existsSync17(this.basePath)) {
|
|
74067
|
+
mkdirSync10(this.basePath, { recursive: true });
|
|
73951
74068
|
}
|
|
73952
74069
|
}
|
|
73953
74070
|
migrateAgentsToAssistants() {
|
|
73954
74071
|
try {
|
|
73955
|
-
const dirs =
|
|
74072
|
+
const dirs = readdirSync6(this.basePath, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => d.name);
|
|
73956
74073
|
for (const dir of dirs) {
|
|
73957
|
-
const wsPath =
|
|
73958
|
-
const oldAgentsDir =
|
|
73959
|
-
const newAssistantsDir =
|
|
73960
|
-
if (
|
|
73961
|
-
|
|
74074
|
+
const wsPath = join23(this.basePath, dir);
|
|
74075
|
+
const oldAgentsDir = join23(wsPath, "agents");
|
|
74076
|
+
const newAssistantsDir = join23(wsPath, "assistants");
|
|
74077
|
+
if (existsSync17(oldAgentsDir) && !existsSync17(newAssistantsDir)) {
|
|
74078
|
+
renameSync(oldAgentsDir, newAssistantsDir);
|
|
73962
74079
|
}
|
|
73963
74080
|
}
|
|
73964
74081
|
} catch {}
|
|
73965
74082
|
}
|
|
73966
74083
|
getWorkspacePath(id) {
|
|
73967
|
-
return
|
|
73968
|
-
}
|
|
73969
|
-
getMetadataPath(id) {
|
|
73970
|
-
return join25(this.getWorkspacePath(id), "workspace.json");
|
|
74084
|
+
return join23(this.basePath, id);
|
|
73971
74085
|
}
|
|
73972
74086
|
create(name, createdBy, participants, description) {
|
|
73973
74087
|
const id = `ws_${generateId().slice(0, 8)}`;
|
|
74088
|
+
const now2 = Date.now();
|
|
74089
|
+
const nowIso = new Date(now2).toISOString();
|
|
74090
|
+
const allParticipants = [...new Set([createdBy, ...participants])];
|
|
73974
74091
|
const workspace = {
|
|
73975
74092
|
id,
|
|
73976
74093
|
name,
|
|
73977
74094
|
description,
|
|
73978
|
-
createdAt:
|
|
73979
|
-
updatedAt:
|
|
74095
|
+
createdAt: now2,
|
|
74096
|
+
updatedAt: now2,
|
|
73980
74097
|
createdBy,
|
|
73981
|
-
participants:
|
|
74098
|
+
participants: allParticipants,
|
|
73982
74099
|
status: "active"
|
|
73983
74100
|
};
|
|
73984
74101
|
const wsPath = this.getWorkspacePath(id);
|
|
73985
|
-
|
|
73986
|
-
for (const assistantId of
|
|
73987
|
-
|
|
74102
|
+
mkdirSync10(join23(wsPath, "shared"), { recursive: true });
|
|
74103
|
+
for (const assistantId of allParticipants) {
|
|
74104
|
+
mkdirSync10(join23(wsPath, "assistants", assistantId), { recursive: true });
|
|
73988
74105
|
}
|
|
73989
|
-
|
|
74106
|
+
this.db.prepare(`INSERT INTO workspaces (id, name, description, creator_id, creator_name, status, participants, created_at, updated_at)
|
|
74107
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(id, name, description || null, createdBy, createdBy, "active", JSON.stringify(allParticipants), nowIso, nowIso);
|
|
73990
74108
|
return workspace;
|
|
73991
74109
|
}
|
|
73992
74110
|
join(workspaceId, assistantId) {
|
|
@@ -73997,49 +74115,32 @@ class SharedWorkspaceManager {
|
|
|
73997
74115
|
if (!workspace.participants.includes(assistantId)) {
|
|
73998
74116
|
workspace.participants.push(assistantId);
|
|
73999
74117
|
workspace.updatedAt = Date.now();
|
|
74000
|
-
|
|
74118
|
+
this.db.prepare("UPDATE workspaces SET participants = ?, updated_at = ? WHERE id = ?").run(JSON.stringify(workspace.participants), new Date(workspace.updatedAt).toISOString(), workspaceId);
|
|
74001
74119
|
}
|
|
74002
|
-
const assistantDir =
|
|
74003
|
-
if (!
|
|
74004
|
-
|
|
74120
|
+
const assistantDir = join23(this.getWorkspacePath(workspaceId), "assistants", assistantId);
|
|
74121
|
+
if (!existsSync17(assistantDir)) {
|
|
74122
|
+
mkdirSync10(assistantDir, { recursive: true });
|
|
74005
74123
|
}
|
|
74006
74124
|
}
|
|
74007
74125
|
get(workspaceId) {
|
|
74008
|
-
|
|
74009
|
-
|
|
74010
|
-
if (!existsSync19(metadataPath))
|
|
74011
|
-
return null;
|
|
74012
|
-
return JSON.parse(readFileSync11(metadataPath, "utf-8"));
|
|
74013
|
-
} catch {
|
|
74126
|
+
const row = this.db.query("SELECT * FROM workspaces WHERE id = ?").get(workspaceId);
|
|
74127
|
+
if (!row)
|
|
74014
74128
|
return null;
|
|
74015
|
-
|
|
74129
|
+
return rowToWorkspace(row);
|
|
74016
74130
|
}
|
|
74017
74131
|
getPath(workspaceId) {
|
|
74018
74132
|
return this.getWorkspacePath(workspaceId);
|
|
74019
74133
|
}
|
|
74020
74134
|
getSharedPath(workspaceId) {
|
|
74021
|
-
return
|
|
74135
|
+
return join23(this.getWorkspacePath(workspaceId), "shared");
|
|
74022
74136
|
}
|
|
74023
74137
|
getAssistantPath(workspaceId, assistantId) {
|
|
74024
|
-
return
|
|
74138
|
+
return join23(this.getWorkspacePath(workspaceId), "assistants", assistantId);
|
|
74025
74139
|
}
|
|
74026
74140
|
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
|
-
}
|
|
74141
|
+
const query = includeArchived ? "SELECT * FROM workspaces ORDER BY updated_at DESC" : "SELECT * FROM workspaces WHERE status = 'active' ORDER BY updated_at DESC";
|
|
74142
|
+
const rows = this.db.query(query).all();
|
|
74143
|
+
return rows.map(rowToWorkspace);
|
|
74043
74144
|
}
|
|
74044
74145
|
listForAgent(assistantId) {
|
|
74045
74146
|
return this.list().filter((ws) => ws.participants.includes(assistantId));
|
|
@@ -74047,44 +74148,42 @@ class SharedWorkspaceManager {
|
|
|
74047
74148
|
archive(workspaceId) {
|
|
74048
74149
|
const workspace = this.get(workspaceId);
|
|
74049
74150
|
if (workspace) {
|
|
74050
|
-
|
|
74051
|
-
workspace.updatedAt = Date.now();
|
|
74052
|
-
atomicWriteFileSync(this.getMetadataPath(workspaceId), JSON.stringify(workspace, null, 2));
|
|
74151
|
+
this.db.prepare("UPDATE workspaces SET status = 'archived', updated_at = ? WHERE id = ?").run(new Date().toISOString(), workspaceId);
|
|
74053
74152
|
}
|
|
74054
74153
|
}
|
|
74055
74154
|
delete(workspaceId) {
|
|
74155
|
+
this.db.prepare("DELETE FROM workspaces WHERE id = ?").run(workspaceId);
|
|
74056
74156
|
const wsPath = this.getWorkspacePath(workspaceId);
|
|
74057
|
-
if (
|
|
74157
|
+
if (existsSync17(wsPath)) {
|
|
74058
74158
|
rmSync(wsPath, { recursive: true, force: true });
|
|
74059
74159
|
}
|
|
74060
74160
|
}
|
|
74061
74161
|
}
|
|
74062
74162
|
var init_shared2 = __esm(async () => {
|
|
74063
74163
|
init_src2();
|
|
74064
|
-
|
|
74065
|
-
|
|
74164
|
+
await __promiseAll([
|
|
74165
|
+
init_config(),
|
|
74166
|
+
init_database()
|
|
74167
|
+
]);
|
|
74066
74168
|
});
|
|
74067
74169
|
|
|
74068
74170
|
// packages/core/src/workspace/active.ts
|
|
74069
|
-
import { join as
|
|
74070
|
-
import { existsSync as
|
|
74171
|
+
import { join as join24 } from "path";
|
|
74172
|
+
import { existsSync as existsSync18, mkdirSync as mkdirSync11 } from "fs";
|
|
74173
|
+
function getDb8() {
|
|
74174
|
+
return getDatabase();
|
|
74175
|
+
}
|
|
74071
74176
|
function isValidId2(id) {
|
|
74072
74177
|
return typeof id === "string" && id.length > 0 && SAFE_ID_PATTERN3.test(id);
|
|
74073
74178
|
}
|
|
74074
74179
|
function getWorkspaceRoot(baseDir) {
|
|
74075
|
-
return
|
|
74076
|
-
}
|
|
74077
|
-
function getActiveWorkspacePath(baseDir) {
|
|
74078
|
-
return join26(getWorkspaceRoot(baseDir), "active.json");
|
|
74180
|
+
return join24(baseDir ?? getConfigDir(), "workspaces");
|
|
74079
74181
|
}
|
|
74080
|
-
function getActiveWorkspaceId(baseDir) {
|
|
74182
|
+
function getActiveWorkspaceId(baseDir, db) {
|
|
74081
74183
|
try {
|
|
74082
|
-
const
|
|
74083
|
-
|
|
74084
|
-
|
|
74085
|
-
const raw = readFileSync12(activePath, "utf-8");
|
|
74086
|
-
const data = JSON.parse(raw);
|
|
74087
|
-
const id = data.id ?? null;
|
|
74184
|
+
const conn = db || getDb8();
|
|
74185
|
+
const row = conn.query("SELECT workspace_id FROM workspaces_active WHERE assistant_id = '__global__'").get();
|
|
74186
|
+
const id = row?.workspace_id ?? null;
|
|
74088
74187
|
if (id && !isValidId2(id)) {
|
|
74089
74188
|
return null;
|
|
74090
74189
|
}
|
|
@@ -74093,29 +74192,27 @@ function getActiveWorkspaceId(baseDir) {
|
|
|
74093
74192
|
return null;
|
|
74094
74193
|
}
|
|
74095
74194
|
}
|
|
74096
|
-
function setActiveWorkspaceId(id, baseDir) {
|
|
74195
|
+
function setActiveWorkspaceId(id, baseDir, db) {
|
|
74097
74196
|
if (id && !isValidId2(id)) {
|
|
74098
74197
|
throw new Error(`Invalid workspace id: "${id}"`);
|
|
74099
74198
|
}
|
|
74100
|
-
const
|
|
74101
|
-
if (
|
|
74102
|
-
|
|
74199
|
+
const conn = db || getDb8();
|
|
74200
|
+
if (id) {
|
|
74201
|
+
conn.prepare("INSERT OR REPLACE INTO workspaces_active (assistant_id, workspace_id) VALUES ('__global__', ?)").run(id);
|
|
74202
|
+
} else {
|
|
74203
|
+
conn.prepare("DELETE FROM workspaces_active WHERE assistant_id = '__global__'").run();
|
|
74103
74204
|
}
|
|
74104
|
-
const activePath = getActiveWorkspacePath(baseDir);
|
|
74105
|
-
try {
|
|
74106
|
-
writeFileSync12(activePath, JSON.stringify({ id: id ?? null }, null, 2), "utf-8");
|
|
74107
|
-
} catch {}
|
|
74108
74205
|
}
|
|
74109
74206
|
function getWorkspaceDataDir(workspaceId, baseDir) {
|
|
74110
74207
|
if (!isValidId2(workspaceId)) {
|
|
74111
74208
|
throw new Error(`Invalid workspace id: "${workspaceId}"`);
|
|
74112
74209
|
}
|
|
74113
|
-
return
|
|
74210
|
+
return join24(getWorkspaceRoot(baseDir), workspaceId, ".assistants");
|
|
74114
74211
|
}
|
|
74115
74212
|
function ensureWorkspaceDataDir(workspaceId, baseDir) {
|
|
74116
74213
|
const dir = getWorkspaceDataDir(workspaceId, baseDir);
|
|
74117
|
-
if (!
|
|
74118
|
-
|
|
74214
|
+
if (!existsSync18(dir)) {
|
|
74215
|
+
mkdirSync11(dir, { recursive: true });
|
|
74119
74216
|
}
|
|
74120
74217
|
initAssistantsDir(dir);
|
|
74121
74218
|
return dir;
|
|
@@ -74131,7 +74228,8 @@ var SAFE_ID_PATTERN3;
|
|
|
74131
74228
|
var init_active = __esm(async () => {
|
|
74132
74229
|
await __promiseAll([
|
|
74133
74230
|
init_config(),
|
|
74134
|
-
init_logger2()
|
|
74231
|
+
init_logger2(),
|
|
74232
|
+
init_database()
|
|
74135
74233
|
]);
|
|
74136
74234
|
SAFE_ID_PATTERN3 = /^[a-zA-Z0-9_-]+$/;
|
|
74137
74235
|
});
|
|
@@ -74195,9 +74293,9 @@ var init_defaults2 = __esm(() => {
|
|
|
74195
74293
|
});
|
|
74196
74294
|
|
|
74197
74295
|
// packages/core/src/budget/tracker.ts
|
|
74198
|
-
|
|
74199
|
-
|
|
74200
|
-
|
|
74296
|
+
function getDb9() {
|
|
74297
|
+
return getDatabase();
|
|
74298
|
+
}
|
|
74201
74299
|
function createEmptyUsage() {
|
|
74202
74300
|
const now2 = new Date().toISOString();
|
|
74203
74301
|
return {
|
|
@@ -74220,85 +74318,92 @@ class BudgetTracker {
|
|
|
74220
74318
|
projectUsages = new Map;
|
|
74221
74319
|
sessionId;
|
|
74222
74320
|
activeProjectId = null;
|
|
74223
|
-
|
|
74321
|
+
db = null;
|
|
74322
|
+
constructor(sessionId, config, db) {
|
|
74224
74323
|
this.sessionId = sessionId;
|
|
74225
74324
|
this.config = { ...DEFAULT_BUDGET_CONFIG, ...config };
|
|
74226
74325
|
this.sessionUsage = createEmptyUsage();
|
|
74227
74326
|
this.swarmUsage = createEmptyUsage();
|
|
74228
74327
|
if (this.config.persist) {
|
|
74328
|
+
try {
|
|
74329
|
+
this.db = db || getDb9();
|
|
74330
|
+
} catch {}
|
|
74331
|
+
}
|
|
74332
|
+
if (this.config.persist && this.db) {
|
|
74229
74333
|
this.loadState();
|
|
74230
74334
|
}
|
|
74231
74335
|
}
|
|
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
74336
|
loadState() {
|
|
74337
|
+
if (!this.db)
|
|
74338
|
+
return;
|
|
74241
74339
|
try {
|
|
74242
|
-
const
|
|
74243
|
-
if (
|
|
74244
|
-
|
|
74245
|
-
|
|
74246
|
-
|
|
74247
|
-
|
|
74248
|
-
|
|
74249
|
-
|
|
74250
|
-
|
|
74251
|
-
|
|
74252
|
-
|
|
74340
|
+
const sessionRow = this.db.query("SELECT * FROM budget_usage WHERE scope = 'session' AND scope_id = ?").get(this.sessionId);
|
|
74341
|
+
if (sessionRow) {
|
|
74342
|
+
this.sessionUsage = {
|
|
74343
|
+
...this.sessionUsage,
|
|
74344
|
+
inputTokens: sessionRow.input_tokens,
|
|
74345
|
+
outputTokens: sessionRow.output_tokens,
|
|
74346
|
+
totalTokens: sessionRow.total_tokens,
|
|
74347
|
+
llmCalls: sessionRow.api_calls,
|
|
74348
|
+
toolCalls: sessionRow.tool_calls,
|
|
74349
|
+
lastUpdatedAt: sessionRow.updated_at
|
|
74350
|
+
};
|
|
74253
74351
|
}
|
|
74254
|
-
|
|
74255
|
-
|
|
74256
|
-
|
|
74257
|
-
|
|
74352
|
+
const swarmRow = this.db.query("SELECT * FROM budget_usage WHERE scope = 'swarm' AND scope_id = ?").get(this.sessionId);
|
|
74353
|
+
if (swarmRow) {
|
|
74354
|
+
this.swarmUsage = {
|
|
74355
|
+
...this.swarmUsage,
|
|
74356
|
+
inputTokens: swarmRow.input_tokens,
|
|
74357
|
+
outputTokens: swarmRow.output_tokens,
|
|
74358
|
+
totalTokens: swarmRow.total_tokens,
|
|
74359
|
+
llmCalls: swarmRow.api_calls,
|
|
74360
|
+
toolCalls: swarmRow.tool_calls,
|
|
74361
|
+
lastUpdatedAt: swarmRow.updated_at
|
|
74362
|
+
};
|
|
74363
|
+
}
|
|
74364
|
+
const assistantRows = this.db.query("SELECT * FROM budget_usage WHERE scope = 'assistant' AND scope_id LIKE ?").all(`${this.sessionId}:%`);
|
|
74365
|
+
for (const row of assistantRows) {
|
|
74366
|
+
const assistantId = row.scope_id.replace(`${this.sessionId}:`, "");
|
|
74367
|
+
this.assistantUsages.set(assistantId, {
|
|
74368
|
+
...createEmptyUsage(),
|
|
74369
|
+
inputTokens: row.input_tokens,
|
|
74370
|
+
outputTokens: row.output_tokens,
|
|
74371
|
+
totalTokens: row.total_tokens,
|
|
74372
|
+
llmCalls: row.api_calls,
|
|
74373
|
+
toolCalls: row.tool_calls,
|
|
74374
|
+
lastUpdatedAt: row.updated_at
|
|
74375
|
+
});
|
|
74376
|
+
}
|
|
74377
|
+
const projectRows = this.db.query("SELECT * FROM budget_usage WHERE scope = 'project'").all();
|
|
74378
|
+
for (const row of projectRows) {
|
|
74379
|
+
this.projectUsages.set(row.scope_id, {
|
|
74380
|
+
...createEmptyUsage(),
|
|
74381
|
+
inputTokens: row.input_tokens,
|
|
74382
|
+
outputTokens: row.output_tokens,
|
|
74383
|
+
totalTokens: row.total_tokens,
|
|
74384
|
+
llmCalls: row.api_calls,
|
|
74385
|
+
toolCalls: row.tool_calls,
|
|
74386
|
+
lastUpdatedAt: row.updated_at
|
|
74387
|
+
});
|
|
74258
74388
|
}
|
|
74259
74389
|
} catch {}
|
|
74260
74390
|
}
|
|
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)
|
|
74391
|
+
saveUsageRow(scope, scopeId, usage) {
|
|
74392
|
+
if (!this.db || !this.config.persist)
|
|
74274
74393
|
return;
|
|
74275
74394
|
try {
|
|
74276
|
-
|
|
74277
|
-
|
|
74278
|
-
if (!existsSync21(stateDir)) {
|
|
74279
|
-
mkdirSync14(stateDir, { recursive: true });
|
|
74280
|
-
}
|
|
74281
|
-
atomicWriteFileSync(statePath, JSON.stringify(usage, null, 2));
|
|
74395
|
+
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)
|
|
74396
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(scope, scopeId, usage.inputTokens, usage.outputTokens, usage.totalTokens, usage.llmCalls, usage.toolCalls, 0, usage.lastUpdatedAt);
|
|
74282
74397
|
} catch {}
|
|
74283
74398
|
}
|
|
74284
74399
|
saveState() {
|
|
74285
|
-
if (!this.config.persist)
|
|
74400
|
+
if (!this.db || !this.config.persist)
|
|
74286
74401
|
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 {}
|
|
74402
|
+
this.saveUsageRow("session", this.sessionId, this.sessionUsage);
|
|
74403
|
+
this.saveUsageRow("swarm", this.sessionId, this.swarmUsage);
|
|
74404
|
+
}
|
|
74405
|
+
saveProjectState(projectId, usage) {
|
|
74406
|
+
this.saveUsageRow("project", projectId, usage);
|
|
74302
74407
|
}
|
|
74303
74408
|
isEnabled() {
|
|
74304
74409
|
return this.config.enabled ?? false;
|
|
@@ -74309,8 +74414,24 @@ class BudgetTracker {
|
|
|
74309
74414
|
setActiveProject(projectId) {
|
|
74310
74415
|
this.activeProjectId = projectId;
|
|
74311
74416
|
if (projectId && !this.projectUsages.has(projectId)) {
|
|
74312
|
-
|
|
74313
|
-
|
|
74417
|
+
if (this.db && this.config.persist) {
|
|
74418
|
+
const row = this.db.query("SELECT * FROM budget_usage WHERE scope = 'project' AND scope_id = ?").get(projectId);
|
|
74419
|
+
if (row) {
|
|
74420
|
+
this.projectUsages.set(projectId, {
|
|
74421
|
+
...createEmptyUsage(),
|
|
74422
|
+
inputTokens: row.input_tokens,
|
|
74423
|
+
outputTokens: row.output_tokens,
|
|
74424
|
+
totalTokens: row.total_tokens,
|
|
74425
|
+
llmCalls: row.api_calls,
|
|
74426
|
+
toolCalls: row.tool_calls,
|
|
74427
|
+
lastUpdatedAt: row.updated_at
|
|
74428
|
+
});
|
|
74429
|
+
} else {
|
|
74430
|
+
this.projectUsages.set(projectId, createEmptyUsage());
|
|
74431
|
+
}
|
|
74432
|
+
} else {
|
|
74433
|
+
this.projectUsages.set(projectId, createEmptyUsage());
|
|
74434
|
+
}
|
|
74314
74435
|
}
|
|
74315
74436
|
}
|
|
74316
74437
|
getActiveProject() {
|
|
@@ -74409,7 +74530,7 @@ class BudgetTracker {
|
|
|
74409
74530
|
};
|
|
74410
74531
|
if (scope === "assistant" && idOrAssistant) {
|
|
74411
74532
|
const assistantUsage = this.assistantUsages.get(idOrAssistant) || createEmptyUsage();
|
|
74412
|
-
|
|
74533
|
+
const updatedAssistant = {
|
|
74413
74534
|
...assistantUsage,
|
|
74414
74535
|
inputTokens: assistantUsage.inputTokens + (update.inputTokens || 0),
|
|
74415
74536
|
outputTokens: assistantUsage.outputTokens + (update.outputTokens || 0),
|
|
@@ -74418,7 +74539,9 @@ class BudgetTracker {
|
|
|
74418
74539
|
toolCalls: assistantUsage.toolCalls + (update.toolCalls || 0),
|
|
74419
74540
|
durationMs: assistantUsage.durationMs + (update.durationMs || 0),
|
|
74420
74541
|
lastUpdatedAt: now2
|
|
74421
|
-
}
|
|
74542
|
+
};
|
|
74543
|
+
this.assistantUsages.set(idOrAssistant, updatedAssistant);
|
|
74544
|
+
this.saveUsageRow("assistant", `${this.sessionId}:${idOrAssistant}`, updatedAssistant);
|
|
74422
74545
|
}
|
|
74423
74546
|
if (scope === "swarm") {
|
|
74424
74547
|
this.swarmUsage = {
|
|
@@ -74618,10 +74741,9 @@ class BudgetTracker {
|
|
|
74618
74741
|
`);
|
|
74619
74742
|
}
|
|
74620
74743
|
}
|
|
74621
|
-
var
|
|
74622
|
-
var init_tracker = __esm(() => {
|
|
74744
|
+
var init_tracker = __esm(async () => {
|
|
74623
74745
|
init_defaults2();
|
|
74624
|
-
|
|
74746
|
+
await init_database();
|
|
74625
74747
|
});
|
|
74626
74748
|
|
|
74627
74749
|
// packages/core/src/budget/tools.ts
|
|
@@ -74882,10 +75004,10 @@ __export(exports_budget, {
|
|
|
74882
75004
|
DEFAULT_ASSISTANT_LIMITS: () => DEFAULT_ASSISTANT_LIMITS,
|
|
74883
75005
|
BudgetTracker: () => BudgetTracker
|
|
74884
75006
|
});
|
|
74885
|
-
var init_budget = __esm(() => {
|
|
74886
|
-
init_tracker();
|
|
75007
|
+
var init_budget = __esm(async () => {
|
|
74887
75008
|
init_defaults2();
|
|
74888
75009
|
init_tools4();
|
|
75010
|
+
await init_tracker();
|
|
74889
75011
|
});
|
|
74890
75012
|
|
|
74891
75013
|
// packages/core/src/registry/types.ts
|
|
@@ -74904,9 +75026,9 @@ var init_types4 = __esm(() => {
|
|
|
74904
75026
|
});
|
|
74905
75027
|
|
|
74906
75028
|
// packages/core/src/registry/store.ts
|
|
74907
|
-
|
|
74908
|
-
|
|
74909
|
-
|
|
75029
|
+
function getDb10() {
|
|
75030
|
+
return getDatabase();
|
|
75031
|
+
}
|
|
74910
75032
|
function generateAssistantId() {
|
|
74911
75033
|
return `assistant_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
|
|
74912
75034
|
}
|
|
@@ -75028,51 +75150,65 @@ class RegistryStore {
|
|
|
75028
75150
|
config;
|
|
75029
75151
|
cleanupTimer = null;
|
|
75030
75152
|
startedAt;
|
|
75031
|
-
|
|
75153
|
+
db = null;
|
|
75154
|
+
constructor(config, db) {
|
|
75032
75155
|
this.config = { ...DEFAULT_REGISTRY_CONFIG, ...config };
|
|
75033
75156
|
this.startedAt = Date.now();
|
|
75034
|
-
if (
|
|
75035
|
-
this.
|
|
75157
|
+
if (db) {
|
|
75158
|
+
this.db = db;
|
|
75159
|
+
} else if (this.config.storage === "database" || this.config.storage === "file") {
|
|
75160
|
+
try {
|
|
75161
|
+
this.db = getDb10();
|
|
75162
|
+
} catch {}
|
|
75163
|
+
}
|
|
75164
|
+
if (this.db) {
|
|
75165
|
+
this.loadFromDb();
|
|
75036
75166
|
}
|
|
75037
75167
|
if (this.config.autoDeregister) {
|
|
75038
75168
|
this.startCleanup();
|
|
75039
75169
|
}
|
|
75040
75170
|
}
|
|
75041
|
-
|
|
75042
|
-
if (this.
|
|
75043
|
-
return
|
|
75044
|
-
|
|
75045
|
-
|
|
75046
|
-
|
|
75171
|
+
loadFromDb() {
|
|
75172
|
+
if (!this.db)
|
|
75173
|
+
return;
|
|
75174
|
+
try {
|
|
75175
|
+
const rows = this.db.query("SELECT * FROM registered_assistants").all();
|
|
75176
|
+
for (const row of rows) {
|
|
75177
|
+
try {
|
|
75178
|
+
if (row.metadata) {
|
|
75179
|
+
const assistant = JSON.parse(row.metadata);
|
|
75180
|
+
this.assistants.set(assistant.id, assistant);
|
|
75181
|
+
}
|
|
75182
|
+
} catch {}
|
|
75183
|
+
}
|
|
75184
|
+
} catch {}
|
|
75047
75185
|
}
|
|
75048
|
-
|
|
75186
|
+
saveToDb() {
|
|
75187
|
+
if (!this.db)
|
|
75188
|
+
return;
|
|
75049
75189
|
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
|
-
}
|
|
75190
|
+
for (const assistant of this.assistants.values()) {
|
|
75191
|
+
this.persistAssistant(assistant);
|
|
75058
75192
|
}
|
|
75059
75193
|
} catch {}
|
|
75060
75194
|
}
|
|
75061
|
-
|
|
75062
|
-
if (this.
|
|
75195
|
+
persistAssistant(assistant) {
|
|
75196
|
+
if (!this.db)
|
|
75063
75197
|
return;
|
|
75064
75198
|
try {
|
|
75065
|
-
const
|
|
75066
|
-
const
|
|
75067
|
-
|
|
75068
|
-
|
|
75069
|
-
|
|
75070
|
-
|
|
75071
|
-
|
|
75072
|
-
|
|
75073
|
-
|
|
75074
|
-
|
|
75075
|
-
|
|
75199
|
+
const capabilitiesStr = JSON.stringify(assistant.capabilities);
|
|
75200
|
+
const tagsStr = JSON.stringify(assistant.capabilities.tags);
|
|
75201
|
+
const metadataStr = JSON.stringify(assistant);
|
|
75202
|
+
this.db.prepare(`INSERT OR REPLACE INTO registered_assistants
|
|
75203
|
+
(id, name, type, description, model, status, state, capabilities, tags, parent_id, created_at, updated_at, last_active_at, metadata)
|
|
75204
|
+
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);
|
|
75205
|
+
} catch {}
|
|
75206
|
+
}
|
|
75207
|
+
removeFromDb(id) {
|
|
75208
|
+
if (!this.db)
|
|
75209
|
+
return;
|
|
75210
|
+
try {
|
|
75211
|
+
this.db.prepare("DELETE FROM registered_assistants WHERE id = ?").run(id);
|
|
75076
75212
|
} catch {}
|
|
75077
75213
|
}
|
|
75078
75214
|
startCleanup() {
|
|
@@ -75096,14 +75232,15 @@ class RegistryStore {
|
|
|
75096
75232
|
const age = now2 - lastHeartbeat;
|
|
75097
75233
|
if (age > staleThreshold) {
|
|
75098
75234
|
this.assistants.delete(id);
|
|
75235
|
+
this.removeFromDb(id);
|
|
75099
75236
|
} else if (age > this.config.heartbeatStaleThreshold) {
|
|
75100
75237
|
assistant.heartbeat.isStale = true;
|
|
75101
75238
|
assistant.heartbeat.missedCount = Math.floor(age / this.config.heartbeatStaleThreshold);
|
|
75102
75239
|
assistant.status.state = "offline";
|
|
75103
75240
|
assistant.updatedAt = new Date().toISOString();
|
|
75241
|
+
this.persistAssistant(assistant);
|
|
75104
75242
|
}
|
|
75105
75243
|
}
|
|
75106
|
-
this.saveToFile();
|
|
75107
75244
|
}
|
|
75108
75245
|
register(registration) {
|
|
75109
75246
|
if (this.assistants.size >= this.config.maxAssistants) {
|
|
@@ -75118,10 +75255,11 @@ class RegistryStore {
|
|
|
75118
75255
|
if (parent) {
|
|
75119
75256
|
parent.childIds.push(assistant.id);
|
|
75120
75257
|
parent.updatedAt = new Date().toISOString();
|
|
75258
|
+
this.persistAssistant(parent);
|
|
75121
75259
|
}
|
|
75122
75260
|
}
|
|
75123
75261
|
this.assistants.set(assistant.id, assistant);
|
|
75124
|
-
this.
|
|
75262
|
+
this.persistAssistant(assistant);
|
|
75125
75263
|
return assistant;
|
|
75126
75264
|
}
|
|
75127
75265
|
get(id) {
|
|
@@ -75161,7 +75299,7 @@ class RegistryStore {
|
|
|
75161
75299
|
};
|
|
75162
75300
|
}
|
|
75163
75301
|
assistant.updatedAt = now2;
|
|
75164
|
-
this.
|
|
75302
|
+
this.persistAssistant(assistant);
|
|
75165
75303
|
return assistant;
|
|
75166
75304
|
}
|
|
75167
75305
|
heartbeat(id) {
|
|
@@ -75187,13 +75325,14 @@ class RegistryStore {
|
|
|
75187
75325
|
if (parent) {
|
|
75188
75326
|
parent.childIds = parent.childIds.filter((cid) => cid !== id);
|
|
75189
75327
|
parent.updatedAt = new Date().toISOString();
|
|
75328
|
+
this.persistAssistant(parent);
|
|
75190
75329
|
}
|
|
75191
75330
|
}
|
|
75192
75331
|
for (const childId of assistant.childIds) {
|
|
75193
75332
|
this.deregister(childId);
|
|
75194
75333
|
}
|
|
75195
75334
|
this.assistants.delete(id);
|
|
75196
|
-
this.
|
|
75335
|
+
this.removeFromDb(id);
|
|
75197
75336
|
return true;
|
|
75198
75337
|
}
|
|
75199
75338
|
query(query) {
|
|
@@ -75290,11 +75429,16 @@ class RegistryStore {
|
|
|
75290
75429
|
}
|
|
75291
75430
|
clear() {
|
|
75292
75431
|
this.assistants.clear();
|
|
75293
|
-
this.
|
|
75432
|
+
if (this.db) {
|
|
75433
|
+
try {
|
|
75434
|
+
this.db.prepare("DELETE FROM registered_assistants").run();
|
|
75435
|
+
} catch {}
|
|
75436
|
+
}
|
|
75294
75437
|
}
|
|
75295
75438
|
}
|
|
75296
|
-
var init_store6 = __esm(() => {
|
|
75439
|
+
var init_store6 = __esm(async () => {
|
|
75297
75440
|
init_types4();
|
|
75441
|
+
await init_database();
|
|
75298
75442
|
});
|
|
75299
75443
|
|
|
75300
75444
|
// packages/core/src/registry/service.ts
|
|
@@ -75465,9 +75609,9 @@ function resetGlobalRegistry() {
|
|
|
75465
75609
|
}
|
|
75466
75610
|
}
|
|
75467
75611
|
var globalRegistry = null;
|
|
75468
|
-
var init_service = __esm(() => {
|
|
75612
|
+
var init_service = __esm(async () => {
|
|
75469
75613
|
init_types4();
|
|
75470
|
-
init_store6();
|
|
75614
|
+
await init_store6();
|
|
75471
75615
|
});
|
|
75472
75616
|
|
|
75473
75617
|
// packages/core/src/registry/index.ts
|
|
@@ -75479,9 +75623,11 @@ __export(exports_registry, {
|
|
|
75479
75623
|
DEFAULT_REGISTRY_CONFIG: () => DEFAULT_REGISTRY_CONFIG,
|
|
75480
75624
|
AssistantRegistryService: () => AssistantRegistryService
|
|
75481
75625
|
});
|
|
75482
|
-
var init_registry2 = __esm(() => {
|
|
75483
|
-
|
|
75484
|
-
|
|
75626
|
+
var init_registry2 = __esm(async () => {
|
|
75627
|
+
await __promiseAll([
|
|
75628
|
+
init_store6(),
|
|
75629
|
+
init_service()
|
|
75630
|
+
]);
|
|
75485
75631
|
init_types4();
|
|
75486
75632
|
});
|
|
75487
75633
|
|
|
@@ -79857,9 +80003,9 @@ var init_swarm = __esm(() => {
|
|
|
79857
80003
|
});
|
|
79858
80004
|
|
|
79859
80005
|
// packages/core/src/commands/builtin.ts
|
|
79860
|
-
import { join as
|
|
79861
|
-
import { homedir as
|
|
79862
|
-
import { existsSync as
|
|
80006
|
+
import { join as join25 } from "path";
|
|
80007
|
+
import { homedir as homedir15, platform as platform2, release, arch as arch2 } from "os";
|
|
80008
|
+
import { existsSync as existsSync19, mkdirSync as mkdirSync12, writeFileSync as writeFileSync9 } from "fs";
|
|
79863
80009
|
function resolveAuthTimeout(resolve6) {
|
|
79864
80010
|
resolve6({ exitCode: 1, stdout: { toString: () => "{}" } });
|
|
79865
80011
|
}
|
|
@@ -86330,9 +86476,9 @@ Format the summary as a brief bullet-point list. This summary will replace the c
|
|
|
86330
86476
|
if (action === "show" || action === "paths") {
|
|
86331
86477
|
const storageDir = context.getStorageDir?.() || getConfigDir();
|
|
86332
86478
|
const configPaths = [
|
|
86333
|
-
|
|
86334
|
-
|
|
86335
|
-
|
|
86479
|
+
join25(context.cwd, ".assistants", "config.json"),
|
|
86480
|
+
join25(context.cwd, ".assistants", "config.local.json"),
|
|
86481
|
+
join25(storageDir, "config.json")
|
|
86336
86482
|
];
|
|
86337
86483
|
let message = `
|
|
86338
86484
|
**Configuration**
|
|
@@ -86341,21 +86487,21 @@ Format the summary as a brief bullet-point list. This summary will replace the c
|
|
|
86341
86487
|
message += `**Config File Locations:**
|
|
86342
86488
|
`;
|
|
86343
86489
|
for (const path2 of configPaths) {
|
|
86344
|
-
const exists =
|
|
86490
|
+
const exists = existsSync19(path2);
|
|
86345
86491
|
message += ` ${exists ? "\u2713" : "\u25CB"} ${path2}
|
|
86346
86492
|
`;
|
|
86347
86493
|
}
|
|
86348
86494
|
const envHome = process.env.HOME || process.env.USERPROFILE;
|
|
86349
|
-
const homeDir = envHome && envHome.trim().length > 0 ? envHome :
|
|
86495
|
+
const homeDir = envHome && envHome.trim().length > 0 ? envHome : homedir15();
|
|
86350
86496
|
message += `
|
|
86351
86497
|
**Commands Directories:**
|
|
86352
86498
|
`;
|
|
86353
|
-
message += ` - Project: ${
|
|
86499
|
+
message += ` - Project: ${join25(context.cwd, ".assistants", "commands")}
|
|
86354
86500
|
`;
|
|
86355
|
-
message += ` - User/Workspace: ${
|
|
86501
|
+
message += ` - User/Workspace: ${join25(storageDir, "commands")}
|
|
86356
86502
|
`;
|
|
86357
|
-
if (storageDir !==
|
|
86358
|
-
message += ` - Global fallback: ${
|
|
86503
|
+
if (storageDir !== join25(homeDir, ".assistants")) {
|
|
86504
|
+
message += ` - Global fallback: ${join25(homeDir, ".assistants", "commands")}
|
|
86359
86505
|
`;
|
|
86360
86506
|
}
|
|
86361
86507
|
context.emit("text", message);
|
|
@@ -86376,7 +86522,7 @@ Format the summary as a brief bullet-point list. This summary will replace the c
|
|
|
86376
86522
|
selfHandled: true,
|
|
86377
86523
|
content: "",
|
|
86378
86524
|
handler: async (args, context) => {
|
|
86379
|
-
const { BudgetTracker: BudgetTracker2 } = await
|
|
86525
|
+
const { BudgetTracker: BudgetTracker2 } = await init_budget().then(() => exports_budget);
|
|
86380
86526
|
const rawArgs = args.trim();
|
|
86381
86527
|
const [actionToken = "", ...actionParts] = rawArgs.length > 0 ? rawArgs.split(/\s+/) : [];
|
|
86382
86528
|
const action = actionToken.toLowerCase();
|
|
@@ -86802,7 +86948,7 @@ On exceeded: ${config.onExceeded || "warn"}
|
|
|
86802
86948
|
selfHandled: true,
|
|
86803
86949
|
content: "",
|
|
86804
86950
|
handler: async (args, context) => {
|
|
86805
|
-
const { getGlobalRegistry: getGlobalRegistry2 } = await
|
|
86951
|
+
const { getGlobalRegistry: getGlobalRegistry2 } = await init_registry2().then(() => exports_registry);
|
|
86806
86952
|
const action = args.trim().toLowerCase();
|
|
86807
86953
|
const registry = getGlobalRegistry2();
|
|
86808
86954
|
if (action === "help") {
|
|
@@ -87271,8 +87417,8 @@ ${error2 instanceof Error ? error2.message : String(error2)}
|
|
|
87271
87417
|
selfHandled: true,
|
|
87272
87418
|
content: "",
|
|
87273
87419
|
handler: async (args, context) => {
|
|
87274
|
-
const commandsDir =
|
|
87275
|
-
|
|
87420
|
+
const commandsDir = join25(context.cwd, ".assistants", "commands");
|
|
87421
|
+
mkdirSync12(commandsDir, { recursive: true });
|
|
87276
87422
|
const exampleCommand = `---
|
|
87277
87423
|
name: reflect
|
|
87278
87424
|
description: Reflect on the conversation and suggest next steps
|
|
@@ -87287,9 +87433,9 @@ Please summarize the last interaction and suggest 2-3 next steps.
|
|
|
87287
87433
|
- Focus on clarity
|
|
87288
87434
|
- Ask a follow-up question if needed
|
|
87289
87435
|
`;
|
|
87290
|
-
const examplePath =
|
|
87291
|
-
if (!
|
|
87292
|
-
|
|
87436
|
+
const examplePath = join25(commandsDir, "reflect.md");
|
|
87437
|
+
if (!existsSync19(examplePath)) {
|
|
87438
|
+
writeFileSync9(examplePath, exampleCommand);
|
|
87293
87439
|
}
|
|
87294
87440
|
let message = `
|
|
87295
87441
|
**Initialized assistants**
|
|
@@ -88018,11 +88164,11 @@ Memory Statistics
|
|
|
88018
88164
|
return { handled: true };
|
|
88019
88165
|
}
|
|
88020
88166
|
if (action === "export") {
|
|
88021
|
-
const filePath = rest[0] ||
|
|
88167
|
+
const filePath = rest[0] || join25(context.getStorageDir?.() || getConfigDir(), "memories-export.json");
|
|
88022
88168
|
const memories = await manager.export();
|
|
88023
88169
|
try {
|
|
88024
88170
|
const content = JSON.stringify(memories, null, 2);
|
|
88025
|
-
|
|
88171
|
+
writeFileSync9(filePath, content, "utf-8");
|
|
88026
88172
|
context.emit("text", `Exported ${memories.length} memories to: ${filePath}
|
|
88027
88173
|
`);
|
|
88028
88174
|
} catch (error2) {
|
|
@@ -88236,7 +88382,7 @@ Importing ${validMemories.length} valid entries (skipping ${errors.length} inval
|
|
|
88236
88382
|
const heartbeatConfig = context.getHeartbeatConfig?.() ?? null;
|
|
88237
88383
|
const historyPathTemplate = heartbeatConfig?.historyPath;
|
|
88238
88384
|
const storageDir = context.getStorageDir?.();
|
|
88239
|
-
const runsDir = storageDir ?
|
|
88385
|
+
const runsDir = storageDir ? join25(storageDir, "heartbeats", "runs") : undefined;
|
|
88240
88386
|
if (!cleanedArgs || cleanedArgs === "ui") {
|
|
88241
88387
|
context.emit("done");
|
|
88242
88388
|
return { handled: true, showPanel: "heartbeat" };
|
|
@@ -88938,11 +89084,10 @@ Not a git repository or git not available.
|
|
|
88938
89084
|
context.setProjectContext(projectContext);
|
|
88939
89085
|
}
|
|
88940
89086
|
}
|
|
88941
|
-
var VERSION2 = "1.1.
|
|
89087
|
+
var VERSION2 = "1.1.53";
|
|
88942
89088
|
var init_builtin = __esm(async () => {
|
|
88943
89089
|
init_src2();
|
|
88944
89090
|
init_context3();
|
|
88945
|
-
init_verification();
|
|
88946
89091
|
init_create();
|
|
88947
89092
|
init_installer();
|
|
88948
89093
|
init_templates();
|
|
@@ -88954,6 +89099,7 @@ var init_builtin = __esm(async () => {
|
|
|
88954
89099
|
init_store3(),
|
|
88955
89100
|
init_history(),
|
|
88956
89101
|
init_store(),
|
|
89102
|
+
init_verification(),
|
|
88957
89103
|
init_hooks(),
|
|
88958
89104
|
init_jobs2(),
|
|
88959
89105
|
init_tasks()
|
|
@@ -93877,9 +94023,9 @@ var init_client3 = __esm(() => {
|
|
|
93877
94023
|
});
|
|
93878
94024
|
|
|
93879
94025
|
// packages/core/src/heartbeat/manager.ts
|
|
93880
|
-
import { dirname as
|
|
93881
|
-
import { mkdirSync as
|
|
93882
|
-
import { readFile as
|
|
94026
|
+
import { dirname as dirname12 } from "path";
|
|
94027
|
+
import { mkdirSync as mkdirSync13 } from "fs";
|
|
94028
|
+
import { readFile as readFile5, writeFile as writeFile4 } from "fs/promises";
|
|
93883
94029
|
|
|
93884
94030
|
class HeartbeatManager {
|
|
93885
94031
|
config;
|
|
@@ -93900,8 +94046,8 @@ class HeartbeatManager {
|
|
|
93900
94046
|
errorsEncountered: 0,
|
|
93901
94047
|
uptimeSeconds: 0
|
|
93902
94048
|
};
|
|
93903
|
-
const dir =
|
|
93904
|
-
|
|
94049
|
+
const dir = dirname12(config.persistPath);
|
|
94050
|
+
mkdirSync13(dir, { recursive: true });
|
|
93905
94051
|
}
|
|
93906
94052
|
start(sessionId) {
|
|
93907
94053
|
if (this.intervalId)
|
|
@@ -93989,7 +94135,7 @@ class HeartbeatManager {
|
|
|
93989
94135
|
}
|
|
93990
94136
|
static async checkStale(path3, thresholdMs) {
|
|
93991
94137
|
try {
|
|
93992
|
-
const content = await
|
|
94138
|
+
const content = await readFile5(path3, "utf-8");
|
|
93993
94139
|
const heartbeat = JSON.parse(content);
|
|
93994
94140
|
const age = Date.now() - new Date(heartbeat.timestamp).getTime();
|
|
93995
94141
|
return { isStale: age > thresholdMs, lastHeartbeat: heartbeat };
|
|
@@ -94082,65 +94228,38 @@ var init_recovery = __esm(async () => {
|
|
|
94082
94228
|
});
|
|
94083
94229
|
|
|
94084
94230
|
// packages/core/src/heartbeat/finder.ts
|
|
94085
|
-
import { existsSync as existsSync24, readdirSync as readdirSync9, readFileSync as readFileSync15 } from "fs";
|
|
94086
|
-
import { join as join30 } from "path";
|
|
94087
94231
|
function findRecoverableSessions(staleThresholdMs = 120000, maxAgeMs = 24 * 60 * 60 * 1000, baseDir) {
|
|
94088
|
-
const configDir = baseDir ?? getConfigDir();
|
|
94089
|
-
const heartbeatsDir = join30(configDir, "heartbeats");
|
|
94090
|
-
const stateDir = join30(configDir, "state");
|
|
94091
|
-
const sessionsDir = join30(configDir, "sessions");
|
|
94092
94232
|
const recoverableSessions = [];
|
|
94093
|
-
|
|
94233
|
+
let db;
|
|
94234
|
+
try {
|
|
94235
|
+
db = getDatabase();
|
|
94236
|
+
} catch {
|
|
94094
94237
|
return recoverableSessions;
|
|
94095
94238
|
}
|
|
94096
94239
|
const now2 = Date.now();
|
|
94097
|
-
const
|
|
94098
|
-
|
|
94099
|
-
|
|
94100
|
-
const heartbeatPath = join30(heartbeatsDir, file);
|
|
94101
|
-
const statePath = join30(stateDir, `${sessionId}.json`);
|
|
94102
|
-
const sessionPath = join30(sessionsDir, `${sessionId}.json`);
|
|
94240
|
+
const cutoffIso = new Date(now2 - maxAgeMs).toISOString();
|
|
94241
|
+
const rows = db.query("SELECT session_id, heartbeat, context, timestamp FROM heartbeat_state WHERE timestamp > ?").all(cutoffIso);
|
|
94242
|
+
for (const row of rows) {
|
|
94103
94243
|
try {
|
|
94104
|
-
const
|
|
94105
|
-
const
|
|
94244
|
+
const heartbeat = JSON.parse(row.heartbeat);
|
|
94245
|
+
const context = JSON.parse(row.context);
|
|
94106
94246
|
const heartbeatAge = now2 - new Date(heartbeat.timestamp).getTime();
|
|
94107
94247
|
if (heartbeatAge < staleThresholdMs) {
|
|
94108
94248
|
continue;
|
|
94109
94249
|
}
|
|
94110
|
-
|
|
94111
|
-
|
|
94112
|
-
|
|
94113
|
-
|
|
94114
|
-
|
|
94115
|
-
|
|
94116
|
-
const stateAge = now2 - new Date(state.timestamp).getTime();
|
|
94117
|
-
if (stateAge > maxAgeMs) {
|
|
94118
|
-
continue;
|
|
94119
|
-
}
|
|
94120
|
-
}
|
|
94250
|
+
const state = {
|
|
94251
|
+
sessionId: row.session_id,
|
|
94252
|
+
heartbeat,
|
|
94253
|
+
context,
|
|
94254
|
+
timestamp: row.timestamp
|
|
94255
|
+
};
|
|
94121
94256
|
let messageCount = 0;
|
|
94122
|
-
|
|
94123
|
-
if (existsSync24(sessionPath)) {
|
|
94124
|
-
try {
|
|
94125
|
-
const sessionContent = readFileSync15(sessionPath, "utf-8");
|
|
94126
|
-
const sessionData = JSON.parse(sessionContent);
|
|
94127
|
-
messageCount = sessionData.messages?.length || 0;
|
|
94128
|
-
cwd = sessionData.cwd || cwd;
|
|
94129
|
-
} catch {}
|
|
94130
|
-
}
|
|
94131
|
-
if (!state && messageCount === 0) {
|
|
94132
|
-
continue;
|
|
94133
|
-
}
|
|
94257
|
+
const cwd = context.cwd || process.cwd();
|
|
94134
94258
|
recoverableSessions.push({
|
|
94135
|
-
sessionId,
|
|
94259
|
+
sessionId: row.session_id,
|
|
94136
94260
|
heartbeat,
|
|
94137
|
-
state
|
|
94138
|
-
|
|
94139
|
-
heartbeat,
|
|
94140
|
-
context: { cwd },
|
|
94141
|
-
timestamp: heartbeat.timestamp
|
|
94142
|
-
},
|
|
94143
|
-
sessionPath,
|
|
94261
|
+
state,
|
|
94262
|
+
sessionPath: "",
|
|
94144
94263
|
cwd,
|
|
94145
94264
|
lastActivity: new Date(heartbeat.lastActivity || heartbeat.timestamp),
|
|
94146
94265
|
messageCount
|
|
@@ -94153,23 +94272,13 @@ function findRecoverableSessions(staleThresholdMs = 120000, maxAgeMs = 24 * 60 *
|
|
|
94153
94272
|
return recoverableSessions;
|
|
94154
94273
|
}
|
|
94155
94274
|
function clearRecoveryState(sessionId, baseDir) {
|
|
94156
|
-
const configDir = baseDir ?? getConfigDir();
|
|
94157
|
-
const heartbeatPath = join30(configDir, "heartbeats", `${sessionId}.json`);
|
|
94158
|
-
const statePath = join30(configDir, "state", `${sessionId}.json`);
|
|
94159
|
-
const { unlinkSync: unlinkSync5 } = __require("fs");
|
|
94160
|
-
try {
|
|
94161
|
-
if (existsSync24(heartbeatPath)) {
|
|
94162
|
-
unlinkSync5(heartbeatPath);
|
|
94163
|
-
}
|
|
94164
|
-
} catch {}
|
|
94165
94275
|
try {
|
|
94166
|
-
|
|
94167
|
-
|
|
94168
|
-
}
|
|
94276
|
+
const db = getDatabase();
|
|
94277
|
+
db.prepare("DELETE FROM heartbeat_state WHERE session_id = ?").run(sessionId);
|
|
94169
94278
|
} catch {}
|
|
94170
94279
|
}
|
|
94171
94280
|
var init_finder = __esm(async () => {
|
|
94172
|
-
await
|
|
94281
|
+
await init_database();
|
|
94173
94282
|
});
|
|
94174
94283
|
|
|
94175
94284
|
// packages/core/src/heartbeat/conventions.ts
|
|
@@ -94292,15 +94401,15 @@ var init_watchdog = __esm(async () => {
|
|
|
94292
94401
|
});
|
|
94293
94402
|
|
|
94294
94403
|
// packages/core/src/heartbeat/install-skills.ts
|
|
94295
|
-
import { join as
|
|
94296
|
-
import { homedir as
|
|
94404
|
+
import { join as join26 } from "path";
|
|
94405
|
+
import { homedir as homedir16 } from "os";
|
|
94297
94406
|
async function writeSkillIfNeeded(dir, skillName, content) {
|
|
94298
|
-
const { mkdir: mkdir7, writeFile: writeFile5, readFile:
|
|
94299
|
-
const skillDir =
|
|
94300
|
-
const skillFile =
|
|
94407
|
+
const { mkdir: mkdir7, writeFile: writeFile5, readFile: readFile6 } = await import("fs/promises");
|
|
94408
|
+
const skillDir = join26(dir, `skill-${skillName}`);
|
|
94409
|
+
const skillFile = join26(skillDir, "SKILL.md");
|
|
94301
94410
|
await mkdir7(skillDir, { recursive: true });
|
|
94302
94411
|
try {
|
|
94303
|
-
const existing = await
|
|
94412
|
+
const existing = await readFile6(skillFile, "utf-8");
|
|
94304
94413
|
if (existing === content) {
|
|
94305
94414
|
return false;
|
|
94306
94415
|
}
|
|
@@ -94316,8 +94425,8 @@ async function writeSkillIfNeeded(dir, skillName, content) {
|
|
|
94316
94425
|
}
|
|
94317
94426
|
}
|
|
94318
94427
|
async function installHeartbeatSkills() {
|
|
94319
|
-
const baseDir = process.env.ASSISTANTS_DIR ||
|
|
94320
|
-
const sharedSkillsDir =
|
|
94428
|
+
const baseDir = process.env.ASSISTANTS_DIR || join26(homedir16(), ".assistants");
|
|
94429
|
+
const sharedSkillsDir = join26(baseDir, "shared", "skills");
|
|
94321
94430
|
const installed = [];
|
|
94322
94431
|
const results = await Promise.all([
|
|
94323
94432
|
writeSkillIfNeeded(sharedSkillsDir, "main-loop", MAIN_LOOP_SKILL),
|
|
@@ -94678,8 +94787,8 @@ var init_llm_response = __esm(() => {
|
|
|
94678
94787
|
// packages/core/src/voice/tts.ts
|
|
94679
94788
|
import { spawnSync as spawnSync2 } from "child_process";
|
|
94680
94789
|
import { tmpdir as tmpdir2 } from "os";
|
|
94681
|
-
import { join as
|
|
94682
|
-
import { readFileSync as
|
|
94790
|
+
import { join as join27 } from "path";
|
|
94791
|
+
import { readFileSync as readFileSync10, unlinkSync as unlinkSync3 } from "fs";
|
|
94683
94792
|
|
|
94684
94793
|
class ElevenLabsTTS {
|
|
94685
94794
|
apiKey;
|
|
@@ -94783,7 +94892,7 @@ class SystemTTS {
|
|
|
94783
94892
|
if (!say) {
|
|
94784
94893
|
throw new Error('System TTS not available: missing "say" command.');
|
|
94785
94894
|
}
|
|
94786
|
-
const output =
|
|
94895
|
+
const output = join27(tmpdir2(), `assistants-tts-${Date.now()}-${Math.random().toString(36).slice(2, 8)}.aiff`);
|
|
94787
94896
|
const args = [];
|
|
94788
94897
|
if (this.voiceId) {
|
|
94789
94898
|
args.push("-v", this.voiceId);
|
|
@@ -94796,8 +94905,8 @@ class SystemTTS {
|
|
|
94796
94905
|
if (result.status !== 0) {
|
|
94797
94906
|
throw new Error(`System TTS failed: ${result.stderr || "unknown error"}`);
|
|
94798
94907
|
}
|
|
94799
|
-
const audio =
|
|
94800
|
-
|
|
94908
|
+
const audio = readFileSync10(output);
|
|
94909
|
+
unlinkSync3(output);
|
|
94801
94910
|
return {
|
|
94802
94911
|
audio: audio.buffer.slice(audio.byteOffset, audio.byteOffset + audio.byteLength),
|
|
94803
94912
|
format: "aiff"
|
|
@@ -94805,7 +94914,7 @@ class SystemTTS {
|
|
|
94805
94914
|
}
|
|
94806
94915
|
const espeak = findExecutable("espeak") || findExecutable("espeak-ng");
|
|
94807
94916
|
if (espeak) {
|
|
94808
|
-
const output =
|
|
94917
|
+
const output = join27(tmpdir2(), `assistants-tts-${Date.now()}-${Math.random().toString(36).slice(2, 8)}.wav`);
|
|
94809
94918
|
const args = ["-w", output];
|
|
94810
94919
|
if (this.voiceId) {
|
|
94811
94920
|
args.push("-v", this.voiceId);
|
|
@@ -94818,8 +94927,8 @@ class SystemTTS {
|
|
|
94818
94927
|
if (result.status !== 0) {
|
|
94819
94928
|
throw new Error(`System TTS failed: ${result.stderr || "unknown error"}`);
|
|
94820
94929
|
}
|
|
94821
|
-
const audio =
|
|
94822
|
-
|
|
94930
|
+
const audio = readFileSync10(output);
|
|
94931
|
+
unlinkSync3(output);
|
|
94823
94932
|
return {
|
|
94824
94933
|
audio: audio.buffer.slice(audio.byteOffset, audio.byteOffset + audio.byteLength),
|
|
94825
94934
|
format: "wav"
|
|
@@ -94835,16 +94944,16 @@ var init_tts = __esm(() => {
|
|
|
94835
94944
|
// packages/core/src/voice/player.ts
|
|
94836
94945
|
import { spawn as spawn2 } from "child_process";
|
|
94837
94946
|
import { tmpdir as tmpdir3 } from "os";
|
|
94838
|
-
import { join as
|
|
94839
|
-
import { unlink as unlink2, writeFileSync as
|
|
94947
|
+
import { join as join28 } from "path";
|
|
94948
|
+
import { unlink as unlink2, writeFileSync as writeFileSync10, appendFileSync as appendFileSync3 } from "fs";
|
|
94840
94949
|
|
|
94841
94950
|
class AudioPlayer {
|
|
94842
94951
|
currentProcess = null;
|
|
94843
94952
|
playing = false;
|
|
94844
94953
|
async play(audio, options = {}) {
|
|
94845
94954
|
const format = options.format ?? "mp3";
|
|
94846
|
-
const tempFile =
|
|
94847
|
-
|
|
94955
|
+
const tempFile = join28(tmpdir3(), `assistants-audio-${Date.now()}-${Math.random().toString(36).slice(2, 8)}.${format}`);
|
|
94956
|
+
writeFileSync10(tempFile, Buffer.from(audio));
|
|
94848
94957
|
const player = this.resolvePlayer(format);
|
|
94849
94958
|
if (!player) {
|
|
94850
94959
|
throw new Error("No supported audio player found. Install afplay, ffplay, mpg123, or aplay.");
|
|
@@ -94871,8 +94980,8 @@ class AudioPlayer {
|
|
|
94871
94980
|
}
|
|
94872
94981
|
async playStream(chunks, options = {}) {
|
|
94873
94982
|
const format = options.format ?? "mp3";
|
|
94874
|
-
const tempFile =
|
|
94875
|
-
|
|
94983
|
+
const tempFile = join28(tmpdir3(), `assistants-stream-${Date.now()}-${Math.random().toString(36).slice(2, 8)}.${format}`);
|
|
94984
|
+
writeFileSync10(tempFile, Buffer.alloc(0));
|
|
94876
94985
|
for await (const chunk of chunks) {
|
|
94877
94986
|
appendFileSync3(tempFile, Buffer.from(chunk));
|
|
94878
94987
|
}
|
|
@@ -94940,8 +95049,8 @@ var init_player = __esm(() => {
|
|
|
94940
95049
|
// packages/core/src/voice/recorder.ts
|
|
94941
95050
|
import { spawn as spawn3 } from "child_process";
|
|
94942
95051
|
import { tmpdir as tmpdir4 } from "os";
|
|
94943
|
-
import { join as
|
|
94944
|
-
import { readFileSync as
|
|
95052
|
+
import { join as join29 } from "path";
|
|
95053
|
+
import { readFileSync as readFileSync11, existsSync as existsSync20, unlink as unlink3 } from "fs";
|
|
94945
95054
|
|
|
94946
95055
|
class AudioRecorder {
|
|
94947
95056
|
currentProcess = null;
|
|
@@ -94954,7 +95063,7 @@ class AudioRecorder {
|
|
|
94954
95063
|
const duration = options.durationSeconds ?? 5;
|
|
94955
95064
|
const sampleRate = options.sampleRate ?? 16000;
|
|
94956
95065
|
const channels = options.channels ?? 1;
|
|
94957
|
-
const output =
|
|
95066
|
+
const output = join29(tmpdir4(), `assistants-record-${Date.now()}.wav`);
|
|
94958
95067
|
this.currentOutputPath = output;
|
|
94959
95068
|
this.stoppedIntentionally = false;
|
|
94960
95069
|
const recorder = this.resolveRecorder(sampleRate, channels, duration, output);
|
|
@@ -94976,11 +95085,11 @@ class AudioRecorder {
|
|
|
94976
95085
|
reject(error3);
|
|
94977
95086
|
});
|
|
94978
95087
|
});
|
|
94979
|
-
if (!
|
|
95088
|
+
if (!existsSync20(output)) {
|
|
94980
95089
|
this.currentOutputPath = null;
|
|
94981
95090
|
return new ArrayBuffer(0);
|
|
94982
95091
|
}
|
|
94983
|
-
const data =
|
|
95092
|
+
const data = readFileSync11(output);
|
|
94984
95093
|
unlink3(output, () => {});
|
|
94985
95094
|
this.currentOutputPath = null;
|
|
94986
95095
|
return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
|
|
@@ -94992,7 +95101,7 @@ class AudioRecorder {
|
|
|
94992
95101
|
const sampleRate = options.sampleRate ?? 16000;
|
|
94993
95102
|
const channels = options.channels ?? 1;
|
|
94994
95103
|
const maxDuration = options.durationSeconds ?? 30;
|
|
94995
|
-
const output =
|
|
95104
|
+
const output = join29(tmpdir4(), `assistants-record-${Date.now()}.wav`);
|
|
94996
95105
|
this.currentOutputPath = output;
|
|
94997
95106
|
this.stoppedIntentionally = false;
|
|
94998
95107
|
const recorder = this.resolveVadRecorder(sampleRate, channels, maxDuration, output);
|
|
@@ -95014,11 +95123,11 @@ class AudioRecorder {
|
|
|
95014
95123
|
reject(error3);
|
|
95015
95124
|
});
|
|
95016
95125
|
});
|
|
95017
|
-
if (!
|
|
95126
|
+
if (!existsSync20(output)) {
|
|
95018
95127
|
this.currentOutputPath = null;
|
|
95019
95128
|
return new ArrayBuffer(0);
|
|
95020
95129
|
}
|
|
95021
|
-
const data =
|
|
95130
|
+
const data = readFileSync11(output);
|
|
95022
95131
|
unlink3(output, () => {});
|
|
95023
95132
|
this.currentOutputPath = null;
|
|
95024
95133
|
return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
|
|
@@ -95402,9 +95511,9 @@ var init_manager4 = __esm(() => {
|
|
|
95402
95511
|
init_recorder();
|
|
95403
95512
|
});
|
|
95404
95513
|
// packages/core/src/identity/identity-manager.ts
|
|
95405
|
-
import { existsSync as
|
|
95406
|
-
import { mkdir as mkdir7, readFile as
|
|
95407
|
-
import { join as
|
|
95514
|
+
import { existsSync as existsSync21 } from "fs";
|
|
95515
|
+
import { mkdir as mkdir7, readFile as readFile6, writeFile as writeFile5, rm as rm2 } from "fs/promises";
|
|
95516
|
+
import { join as join30 } from "path";
|
|
95408
95517
|
function isValidId3(id) {
|
|
95409
95518
|
return typeof id === "string" && id.length > 0 && SAFE_ID_PATTERN4.test(id);
|
|
95410
95519
|
}
|
|
@@ -95425,20 +95534,20 @@ class IdentityManager {
|
|
|
95425
95534
|
this.basePath = basePath;
|
|
95426
95535
|
}
|
|
95427
95536
|
get identitiesRoot() {
|
|
95428
|
-
return
|
|
95537
|
+
return join30(this.basePath, "assistants", this.assistantId, "identities");
|
|
95429
95538
|
}
|
|
95430
95539
|
get indexPath() {
|
|
95431
|
-
return
|
|
95540
|
+
return join30(this.identitiesRoot, "index.json");
|
|
95432
95541
|
}
|
|
95433
95542
|
get activePath() {
|
|
95434
|
-
return
|
|
95543
|
+
return join30(this.identitiesRoot, "active.json");
|
|
95435
95544
|
}
|
|
95436
95545
|
identityPath(id) {
|
|
95437
95546
|
validateId(id, "identityId");
|
|
95438
|
-
return
|
|
95547
|
+
return join30(this.identitiesRoot, `${id}.json`);
|
|
95439
95548
|
}
|
|
95440
95549
|
assistantConfigPath() {
|
|
95441
|
-
return
|
|
95550
|
+
return join30(this.basePath, "assistants", this.assistantId, "config.json");
|
|
95442
95551
|
}
|
|
95443
95552
|
async initialize() {
|
|
95444
95553
|
await mkdir7(this.identitiesRoot, { recursive: true });
|
|
@@ -95564,11 +95673,11 @@ class IdentityManager {
|
|
|
95564
95673
|
`);
|
|
95565
95674
|
}
|
|
95566
95675
|
async readIndex() {
|
|
95567
|
-
if (!
|
|
95676
|
+
if (!existsSync21(this.indexPath)) {
|
|
95568
95677
|
return { identities: [] };
|
|
95569
95678
|
}
|
|
95570
95679
|
try {
|
|
95571
|
-
const raw = await
|
|
95680
|
+
const raw = await readFile6(this.indexPath, "utf-8");
|
|
95572
95681
|
const data = JSON.parse(raw);
|
|
95573
95682
|
const identities = Array.isArray(data.identities) ? data.identities : [];
|
|
95574
95683
|
return { identities: identities.filter(isValidId3) };
|
|
@@ -95590,10 +95699,10 @@ class IdentityManager {
|
|
|
95590
95699
|
}
|
|
95591
95700
|
async readIdentity(id) {
|
|
95592
95701
|
const path3 = this.identityPath(id);
|
|
95593
|
-
if (!
|
|
95702
|
+
if (!existsSync21(path3))
|
|
95594
95703
|
return null;
|
|
95595
95704
|
try {
|
|
95596
|
-
const raw = await
|
|
95705
|
+
const raw = await readFile6(path3, "utf-8");
|
|
95597
95706
|
return JSON.parse(raw);
|
|
95598
95707
|
} catch {
|
|
95599
95708
|
return null;
|
|
@@ -95604,10 +95713,10 @@ class IdentityManager {
|
|
|
95604
95713
|
await writeFile5(this.identityPath(identity.id), JSON.stringify(identity, null, 2));
|
|
95605
95714
|
}
|
|
95606
95715
|
async readActive() {
|
|
95607
|
-
if (!
|
|
95716
|
+
if (!existsSync21(this.activePath))
|
|
95608
95717
|
return null;
|
|
95609
95718
|
try {
|
|
95610
|
-
const raw = await
|
|
95719
|
+
const raw = await readFile6(this.activePath, "utf-8");
|
|
95611
95720
|
const data = JSON.parse(raw);
|
|
95612
95721
|
const id = data.id || null;
|
|
95613
95722
|
if (id && !isValidId3(id)) {
|
|
@@ -95623,10 +95732,10 @@ class IdentityManager {
|
|
|
95623
95732
|
await writeFile5(this.activePath, JSON.stringify({ id }, null, 2));
|
|
95624
95733
|
}
|
|
95625
95734
|
async loadAssistant() {
|
|
95626
|
-
if (!
|
|
95735
|
+
if (!existsSync21(this.assistantConfigPath()))
|
|
95627
95736
|
return null;
|
|
95628
95737
|
try {
|
|
95629
|
-
const raw = await
|
|
95738
|
+
const raw = await readFile6(this.assistantConfigPath(), "utf-8");
|
|
95630
95739
|
return JSON.parse(raw);
|
|
95631
95740
|
} catch {
|
|
95632
95741
|
return null;
|
|
@@ -95659,49 +95768,81 @@ var init_identity_manager = __esm(() => {
|
|
|
95659
95768
|
});
|
|
95660
95769
|
|
|
95661
95770
|
// 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);
|
|
95771
|
+
function getDb11() {
|
|
95772
|
+
return getDatabase();
|
|
95667
95773
|
}
|
|
95668
|
-
function
|
|
95669
|
-
|
|
95670
|
-
|
|
95671
|
-
|
|
95774
|
+
function rowToAssistant(row) {
|
|
95775
|
+
const raw = JSON.parse(row.settings);
|
|
95776
|
+
const avatar = raw.__avatar;
|
|
95777
|
+
const description = raw.__description;
|
|
95778
|
+
const color = raw.__color;
|
|
95779
|
+
const isSystem = raw.__isSystem;
|
|
95780
|
+
delete raw.__avatar;
|
|
95781
|
+
delete raw.__description;
|
|
95782
|
+
delete raw.__color;
|
|
95783
|
+
delete raw.__isSystem;
|
|
95784
|
+
const settings = raw;
|
|
95785
|
+
const assistant = {
|
|
95786
|
+
id: row.id,
|
|
95787
|
+
name: row.name,
|
|
95788
|
+
settings,
|
|
95789
|
+
createdAt: new Date(row.created_at).toISOString(),
|
|
95790
|
+
updatedAt: new Date(row.updated_at).toISOString()
|
|
95791
|
+
};
|
|
95792
|
+
if (row.identity_id)
|
|
95793
|
+
assistant.defaultIdentityId = row.identity_id;
|
|
95794
|
+
if (avatar)
|
|
95795
|
+
assistant.avatar = avatar;
|
|
95796
|
+
if (description)
|
|
95797
|
+
assistant.description = description;
|
|
95798
|
+
if (color)
|
|
95799
|
+
assistant.color = color;
|
|
95800
|
+
if (isSystem)
|
|
95801
|
+
assistant.isSystem = true;
|
|
95802
|
+
return assistant;
|
|
95803
|
+
}
|
|
95804
|
+
function assistantToRow(assistant) {
|
|
95805
|
+
const settingsObj = { ...assistant.settings };
|
|
95806
|
+
if (assistant.avatar)
|
|
95807
|
+
settingsObj.__avatar = assistant.avatar;
|
|
95808
|
+
if (assistant.description)
|
|
95809
|
+
settingsObj.__description = assistant.description;
|
|
95810
|
+
if (assistant.color)
|
|
95811
|
+
settingsObj.__color = assistant.color;
|
|
95812
|
+
if (assistant.isSystem)
|
|
95813
|
+
settingsObj.__isSystem = true;
|
|
95814
|
+
return {
|
|
95815
|
+
id: assistant.id,
|
|
95816
|
+
name: assistant.name,
|
|
95817
|
+
model: assistant.settings.model || null,
|
|
95818
|
+
system_prompt: assistant.settings.systemPromptAddition || null,
|
|
95819
|
+
settings: JSON.stringify(settingsObj),
|
|
95820
|
+
identity_id: assistant.defaultIdentityId || null,
|
|
95821
|
+
created_at: new Date(assistant.createdAt).getTime(),
|
|
95822
|
+
updated_at: new Date(assistant.updatedAt).getTime()
|
|
95823
|
+
};
|
|
95672
95824
|
}
|
|
95673
95825
|
|
|
95674
95826
|
class AssistantManager {
|
|
95675
95827
|
basePath;
|
|
95676
95828
|
assistants = new Map;
|
|
95677
95829
|
activeId = null;
|
|
95678
|
-
|
|
95830
|
+
db;
|
|
95831
|
+
constructor(basePath, db) {
|
|
95679
95832
|
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");
|
|
95833
|
+
this.db = db || getDb11();
|
|
95693
95834
|
}
|
|
95694
95835
|
async initialize() {
|
|
95695
|
-
|
|
95696
|
-
const
|
|
95697
|
-
|
|
95698
|
-
|
|
95699
|
-
|
|
95700
|
-
|
|
95701
|
-
}
|
|
95836
|
+
const rows = this.db.query("SELECT * FROM assistants_config").all();
|
|
95837
|
+
for (const row of rows) {
|
|
95838
|
+
try {
|
|
95839
|
+
const assistant = rowToAssistant(row);
|
|
95840
|
+
this.assistants.set(assistant.id, assistant);
|
|
95841
|
+
} catch {}
|
|
95702
95842
|
}
|
|
95703
95843
|
await this.seedSystemAssistants();
|
|
95704
|
-
this.
|
|
95844
|
+
const activeRow = this.db.query("SELECT assistant_id FROM assistants_active WHERE key = 'active'").get();
|
|
95845
|
+
this.activeId = activeRow?.assistant_id || null;
|
|
95705
95846
|
if (!this.activeId || !this.assistants.has(this.activeId)) {
|
|
95706
95847
|
await this.setActive(DEFAULT_SYSTEM_ASSISTANT_ID);
|
|
95707
95848
|
}
|
|
@@ -95719,14 +95860,13 @@ class AssistantManager {
|
|
|
95719
95860
|
createdAt: now2,
|
|
95720
95861
|
updatedAt: now2
|
|
95721
95862
|
};
|
|
95722
|
-
|
|
95863
|
+
this.persistAssistant(assistant);
|
|
95723
95864
|
this.assistants.set(id, assistant);
|
|
95724
|
-
await this.appendToIndex(id);
|
|
95725
95865
|
await this.setActive(id);
|
|
95726
95866
|
return assistant;
|
|
95727
95867
|
}
|
|
95728
95868
|
async updateAssistant(id, updates) {
|
|
95729
|
-
const existing = this.assistants.get(id)
|
|
95869
|
+
const existing = this.assistants.get(id);
|
|
95730
95870
|
if (!existing) {
|
|
95731
95871
|
throw new Error(`Assistant ${id} not found`);
|
|
95732
95872
|
}
|
|
@@ -95736,12 +95876,11 @@ class AssistantManager {
|
|
|
95736
95876
|
settings: { ...existing.settings, ...updates.settings || {} },
|
|
95737
95877
|
updatedAt: new Date().toISOString()
|
|
95738
95878
|
};
|
|
95739
|
-
|
|
95879
|
+
this.persistAssistant(updated);
|
|
95740
95880
|
this.assistants.set(id, updated);
|
|
95741
95881
|
return updated;
|
|
95742
95882
|
}
|
|
95743
95883
|
async deleteAssistant(id) {
|
|
95744
|
-
validateId2(id, "assistantId");
|
|
95745
95884
|
if (!this.assistants.has(id)) {
|
|
95746
95885
|
throw new Error(`Assistant ${id} not found`);
|
|
95747
95886
|
}
|
|
@@ -95749,16 +95888,15 @@ class AssistantManager {
|
|
|
95749
95888
|
if (assistant?.isSystem || isSystemAssistantId(id)) {
|
|
95750
95889
|
throw new Error(`Cannot delete system assistant "${assistant?.name || id}". System assistants are built-in and cannot be removed.`);
|
|
95751
95890
|
}
|
|
95752
|
-
|
|
95891
|
+
this.db.prepare("DELETE FROM assistants_config WHERE id = ?").run(id);
|
|
95753
95892
|
this.assistants.delete(id);
|
|
95754
|
-
await this.removeFromIndex(id);
|
|
95755
95893
|
if (this.activeId === id) {
|
|
95756
95894
|
const next = this.listAssistants()[0];
|
|
95757
95895
|
await this.setActive(next?.id || null);
|
|
95758
95896
|
}
|
|
95759
95897
|
}
|
|
95760
95898
|
async switchAssistant(id) {
|
|
95761
|
-
const assistant = this.assistants.get(id)
|
|
95899
|
+
const assistant = this.assistants.get(id);
|
|
95762
95900
|
if (!assistant) {
|
|
95763
95901
|
throw new Error(`Assistant ${id} not found`);
|
|
95764
95902
|
}
|
|
@@ -95784,91 +95922,42 @@ class AssistantManager {
|
|
|
95784
95922
|
for (const def of definitions) {
|
|
95785
95923
|
if (!this.assistants.has(def.id)) {
|
|
95786
95924
|
const assistant = buildSystemAssistant(def);
|
|
95787
|
-
|
|
95925
|
+
this.persistAssistant(assistant);
|
|
95788
95926
|
this.assistants.set(def.id, assistant);
|
|
95789
|
-
await this.appendToIndex(def.id);
|
|
95790
95927
|
}
|
|
95791
95928
|
}
|
|
95792
95929
|
}
|
|
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
|
-
}
|
|
95930
|
+
persistAssistant(assistant) {
|
|
95931
|
+
const row = assistantToRow(assistant);
|
|
95932
|
+
this.db.prepare(`INSERT OR REPLACE INTO assistants_config (id, name, model, system_prompt, settings, identity_id, created_at, updated_at)
|
|
95933
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`).run(row.id, row.name, row.model, row.system_prompt, row.settings, row.identity_id, row.created_at, row.updated_at);
|
|
95849
95934
|
}
|
|
95850
95935
|
async setActive(id) {
|
|
95851
95936
|
this.activeId = id;
|
|
95852
|
-
|
|
95937
|
+
if (id) {
|
|
95938
|
+
this.db.prepare("INSERT OR REPLACE INTO assistants_active (key, assistant_id) VALUES ('active', ?)").run(id);
|
|
95939
|
+
} else {
|
|
95940
|
+
this.db.prepare("DELETE FROM assistants_active WHERE key = 'active'").run();
|
|
95941
|
+
}
|
|
95853
95942
|
}
|
|
95854
95943
|
}
|
|
95855
|
-
var
|
|
95856
|
-
var init_assistant_manager = __esm(() => {
|
|
95944
|
+
var DEFAULT_SETTINGS;
|
|
95945
|
+
var init_assistant_manager = __esm(async () => {
|
|
95857
95946
|
init_src2();
|
|
95858
95947
|
init_identity_manager();
|
|
95859
95948
|
init_system_assistants();
|
|
95860
|
-
|
|
95949
|
+
await init_database();
|
|
95861
95950
|
DEFAULT_SETTINGS = {
|
|
95862
95951
|
model: "claude-opus-4-5"
|
|
95863
95952
|
};
|
|
95864
95953
|
});
|
|
95865
95954
|
|
|
95866
95955
|
// packages/core/src/identity/index.ts
|
|
95867
|
-
var init_identity2 = __esm(() => {
|
|
95868
|
-
init_assistant_manager();
|
|
95956
|
+
var init_identity2 = __esm(async () => {
|
|
95869
95957
|
init_identity_manager();
|
|
95870
95958
|
init_templates();
|
|
95871
95959
|
init_system_assistants();
|
|
95960
|
+
await init_assistant_manager();
|
|
95872
95961
|
});
|
|
95873
95962
|
|
|
95874
95963
|
// node_modules/.pnpm/@smithy+types@4.12.0/node_modules/@smithy/types/dist-cjs/index.js
|
|
@@ -110901,7 +110990,7 @@ var require_readFile = __commonJS((exports) => {
|
|
|
110901
110990
|
var promises_1 = __require("fs/promises");
|
|
110902
110991
|
exports.filePromises = {};
|
|
110903
110992
|
exports.fileIntercept = {};
|
|
110904
|
-
var
|
|
110993
|
+
var readFile7 = (path3, options) => {
|
|
110905
110994
|
if (exports.fileIntercept[path3] !== undefined) {
|
|
110906
110995
|
return exports.fileIntercept[path3];
|
|
110907
110996
|
}
|
|
@@ -110910,7 +110999,7 @@ var require_readFile = __commonJS((exports) => {
|
|
|
110910
110999
|
}
|
|
110911
111000
|
return exports.filePromises[path3];
|
|
110912
111001
|
};
|
|
110913
|
-
exports.readFile =
|
|
111002
|
+
exports.readFile = readFile7;
|
|
110914
111003
|
});
|
|
110915
111004
|
|
|
110916
111005
|
// node_modules/.pnpm/@smithy+shared-ini-file-loader@4.4.3/node_modules/@smithy/shared-ini-file-loader/dist-cjs/index.js
|
|
@@ -110920,7 +111009,7 @@ var require_dist_cjs35 = __commonJS((exports) => {
|
|
|
110920
111009
|
var getSSOTokenFromFile = require_getSSOTokenFromFile();
|
|
110921
111010
|
var path3 = __require("path");
|
|
110922
111011
|
var types11 = require_dist_cjs();
|
|
110923
|
-
var
|
|
111012
|
+
var readFile7 = require_readFile();
|
|
110924
111013
|
var ENV_PROFILE = "AWS_PROFILE";
|
|
110925
111014
|
var DEFAULT_PROFILE2 = "default";
|
|
110926
111015
|
var getProfileName = (init) => init.profile || process.env[ENV_PROFILE] || DEFAULT_PROFILE2;
|
|
@@ -111004,10 +111093,10 @@ var require_dist_cjs35 = __commonJS((exports) => {
|
|
|
111004
111093
|
resolvedConfigFilepath = path3.join(homeDir, configFilepath.slice(2));
|
|
111005
111094
|
}
|
|
111006
111095
|
const parsedFiles = await Promise.all([
|
|
111007
|
-
|
|
111096
|
+
readFile7.readFile(resolvedConfigFilepath, {
|
|
111008
111097
|
ignoreCache: init.ignoreCache
|
|
111009
111098
|
}).then(parseIni).then(getConfigData).catch(swallowError$1),
|
|
111010
|
-
|
|
111099
|
+
readFile7.readFile(resolvedFilepath, {
|
|
111011
111100
|
ignoreCache: init.ignoreCache
|
|
111012
111101
|
}).then(parseIni).catch(swallowError$1)
|
|
111013
111102
|
]);
|
|
@@ -111018,7 +111107,7 @@ var require_dist_cjs35 = __commonJS((exports) => {
|
|
|
111018
111107
|
};
|
|
111019
111108
|
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
111109
|
var swallowError = () => ({});
|
|
111021
|
-
var loadSsoSessionData = async (init = {}) =>
|
|
111110
|
+
var loadSsoSessionData = async (init = {}) => readFile7.readFile(init.configFilepath ?? getConfigFilepath()).then(parseIni).then(getSsoSessionData).catch(swallowError);
|
|
111022
111111
|
var mergeConfigFiles = (...files) => {
|
|
111023
111112
|
const merged = {};
|
|
111024
111113
|
for (const file of files) {
|
|
@@ -111038,10 +111127,10 @@ var require_dist_cjs35 = __commonJS((exports) => {
|
|
|
111038
111127
|
};
|
|
111039
111128
|
var externalDataInterceptor = {
|
|
111040
111129
|
getFileRecord() {
|
|
111041
|
-
return
|
|
111130
|
+
return readFile7.fileIntercept;
|
|
111042
111131
|
},
|
|
111043
111132
|
interceptFile(path4, contents) {
|
|
111044
|
-
|
|
111133
|
+
readFile7.fileIntercept[path4] = Promise.resolve(contents);
|
|
111045
111134
|
},
|
|
111046
111135
|
getTokenRecord() {
|
|
111047
111136
|
return getSSOTokenFromFile.tokenIntercept;
|
|
@@ -111059,7 +111148,7 @@ var require_dist_cjs35 = __commonJS((exports) => {
|
|
|
111059
111148
|
Object.defineProperty(exports, "readFile", {
|
|
111060
111149
|
enumerable: true,
|
|
111061
111150
|
get: function() {
|
|
111062
|
-
return
|
|
111151
|
+
return readFile7.readFile;
|
|
111063
111152
|
}
|
|
111064
111153
|
});
|
|
111065
111154
|
exports.CONFIG_PREFIX_SEPARATOR = CONFIG_PREFIX_SEPARATOR;
|
|
@@ -120701,14 +120790,14 @@ var init_validateTokenKey = __esm(() => {
|
|
|
120701
120790
|
|
|
120702
120791
|
// node_modules/.pnpm/@aws-sdk+token-providers@3.985.0/node_modules/@aws-sdk/token-providers/dist-es/writeSSOTokenToFile.js
|
|
120703
120792
|
import { promises as fsPromises } from "fs";
|
|
120704
|
-
var import_shared_ini_file_loader,
|
|
120793
|
+
var import_shared_ini_file_loader, writeFile6, writeSSOTokenToFile = (id, ssoToken) => {
|
|
120705
120794
|
const tokenFilepath = import_shared_ini_file_loader.getSSOTokenFilepath(id);
|
|
120706
120795
|
const tokenString = JSON.stringify(ssoToken, null, 2);
|
|
120707
|
-
return
|
|
120796
|
+
return writeFile6(tokenFilepath, tokenString);
|
|
120708
120797
|
};
|
|
120709
120798
|
var init_writeSSOTokenToFile = __esm(() => {
|
|
120710
120799
|
import_shared_ini_file_loader = __toESM(require_dist_cjs35(), 1);
|
|
120711
|
-
({ writeFile:
|
|
120800
|
+
({ writeFile: writeFile6 } = fsPromises);
|
|
120712
120801
|
});
|
|
120713
120802
|
|
|
120714
120803
|
// node_modules/.pnpm/@aws-sdk+token-providers@3.985.0/node_modules/@aws-sdk/token-providers/dist-es/fromSso.js
|
|
@@ -123344,8 +123433,8 @@ var require_signin = __commonJS((exports) => {
|
|
|
123344
123433
|
// node_modules/.pnpm/@aws-sdk+credential-provider-login@3.972.5/node_modules/@aws-sdk/credential-provider-login/dist-es/LoginCredentialsFetcher.js
|
|
123345
123434
|
import { createHash as createHash4, createPrivateKey, createPublicKey, sign } from "crypto";
|
|
123346
123435
|
import { promises as fs2 } from "fs";
|
|
123347
|
-
import { homedir as
|
|
123348
|
-
import { dirname as
|
|
123436
|
+
import { homedir as homedir17 } from "os";
|
|
123437
|
+
import { dirname as dirname13, join as join31 } from "path";
|
|
123349
123438
|
var import_property_provider18, import_protocol_http11, import_shared_ini_file_loader6, LoginCredentialsFetcher;
|
|
123350
123439
|
var init_LoginCredentialsFetcher = __esm(() => {
|
|
123351
123440
|
import_property_provider18 = __toESM(require_dist_cjs17(), 1);
|
|
@@ -123498,17 +123587,17 @@ var init_LoginCredentialsFetcher = __esm(() => {
|
|
|
123498
123587
|
}
|
|
123499
123588
|
async saveToken(token) {
|
|
123500
123589
|
const tokenFilePath = this.getTokenFilePath();
|
|
123501
|
-
const directory =
|
|
123590
|
+
const directory = dirname13(tokenFilePath);
|
|
123502
123591
|
try {
|
|
123503
123592
|
await fs2.mkdir(directory, { recursive: true });
|
|
123504
123593
|
} catch (error3) {}
|
|
123505
123594
|
await fs2.writeFile(tokenFilePath, JSON.stringify(token, null, 2), "utf8");
|
|
123506
123595
|
}
|
|
123507
123596
|
getTokenFilePath() {
|
|
123508
|
-
const directory = process.env.AWS_LOGIN_CACHE_DIRECTORY ??
|
|
123597
|
+
const directory = process.env.AWS_LOGIN_CACHE_DIRECTORY ?? join31(homedir17(), ".aws", "login", "cache");
|
|
123509
123598
|
const loginSessionBytes = Buffer.from(this.loginSession, "utf8");
|
|
123510
123599
|
const loginSessionSha256 = createHash4("sha256").update(loginSessionBytes).digest("hex");
|
|
123511
|
-
return
|
|
123600
|
+
return join31(directory, `${loginSessionSha256}.json`);
|
|
123512
123601
|
}
|
|
123513
123602
|
derToRawSignature(derSignature) {
|
|
123514
123603
|
let offset = 2;
|
|
@@ -123814,7 +123903,7 @@ var fromWebToken = (init) => async (awsIdentityProperties) => {
|
|
|
123814
123903
|
};
|
|
123815
123904
|
|
|
123816
123905
|
// 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
|
|
123906
|
+
import { readFileSync as readFileSync12 } from "fs";
|
|
123818
123907
|
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
123908
|
init.logger?.debug("@aws-sdk/credential-provider-web-identity - fromTokenFile");
|
|
123820
123909
|
const webIdentityTokenFile = init?.webIdentityTokenFile ?? process.env[ENV_TOKEN_FILE];
|
|
@@ -123827,7 +123916,7 @@ var import_client17, import_property_provider21, import_shared_ini_file_loader10
|
|
|
123827
123916
|
}
|
|
123828
123917
|
const credentials = await fromWebToken({
|
|
123829
123918
|
...init,
|
|
123830
|
-
webIdentityToken: import_shared_ini_file_loader10.externalDataInterceptor?.getTokenRecord?.()[webIdentityTokenFile] ??
|
|
123919
|
+
webIdentityToken: import_shared_ini_file_loader10.externalDataInterceptor?.getTokenRecord?.()[webIdentityTokenFile] ?? readFileSync12(webIdentityTokenFile, { encoding: "ascii" }),
|
|
123831
123920
|
roleArn,
|
|
123832
123921
|
roleSessionName
|
|
123833
123922
|
})(awsIdentityProperties);
|
|
@@ -128163,8 +128252,8 @@ var init_s3_client = __esm(() => {
|
|
|
128163
128252
|
});
|
|
128164
128253
|
|
|
128165
128254
|
// packages/core/src/inbox/storage/local-cache.ts
|
|
128166
|
-
import { join as
|
|
128167
|
-
import { mkdir as
|
|
128255
|
+
import { join as join32, basename as basename6 } from "path";
|
|
128256
|
+
import { mkdir as mkdir8, readFile as readFile8, writeFile as writeFile7, rm as rm3, readdir, stat as stat4 } from "fs/promises";
|
|
128168
128257
|
import { createHash as createHash5 } from "crypto";
|
|
128169
128258
|
function isValidAssistantId(id) {
|
|
128170
128259
|
return typeof id === "string" && id.length > 0 && STRICT_ID_PATTERN.test(id);
|
|
@@ -128189,7 +128278,7 @@ function sanitizeFilename(filename) {
|
|
|
128189
128278
|
const base = basename6(filename);
|
|
128190
128279
|
return base.replace(/[/\\]/g, "_");
|
|
128191
128280
|
}
|
|
128192
|
-
function
|
|
128281
|
+
function getDb12(injected) {
|
|
128193
128282
|
if (injected)
|
|
128194
128283
|
return injected;
|
|
128195
128284
|
return getDatabase();
|
|
@@ -128204,15 +128293,15 @@ class LocalInboxCache {
|
|
|
128204
128293
|
validateAssistantId(options.assistantId);
|
|
128205
128294
|
this.assistantId = options.assistantId;
|
|
128206
128295
|
this.basePath = options.basePath;
|
|
128207
|
-
this.cacheDir =
|
|
128296
|
+
this.cacheDir = join32(this.basePath, this.assistantId);
|
|
128208
128297
|
this.injectedDb = options.db;
|
|
128209
128298
|
}
|
|
128210
128299
|
db() {
|
|
128211
|
-
return
|
|
128300
|
+
return getDb12(this.injectedDb);
|
|
128212
128301
|
}
|
|
128213
128302
|
async ensureDirectories() {
|
|
128214
|
-
await
|
|
128215
|
-
await
|
|
128303
|
+
await mkdir8(join32(this.cacheDir, "emails"), { recursive: true });
|
|
128304
|
+
await mkdir8(join32(this.cacheDir, "attachments"), { recursive: true });
|
|
128216
128305
|
}
|
|
128217
128306
|
async loadIndex() {
|
|
128218
128307
|
const rows = this.db().query("SELECT * FROM inbox_cache WHERE assistant_id = ? ORDER BY date DESC").all(this.assistantId);
|
|
@@ -128240,8 +128329,8 @@ class LocalInboxCache {
|
|
|
128240
128329
|
throw new Error(`Failed to create safe filename for email ID: "${email.id}"`);
|
|
128241
128330
|
}
|
|
128242
128331
|
await this.ensureDirectories();
|
|
128243
|
-
const emailPath =
|
|
128244
|
-
await
|
|
128332
|
+
const emailPath = join32(this.cacheDir, "emails", `${filename}.json`);
|
|
128333
|
+
await writeFile7(emailPath, JSON.stringify(email, null, 2));
|
|
128245
128334
|
const existing = this.db().query("SELECT * FROM inbox_cache WHERE id = ? AND assistant_id = ?").get(email.id, this.assistantId);
|
|
128246
128335
|
if (existing) {
|
|
128247
128336
|
const useFilename = existing.filename || filename;
|
|
@@ -128259,8 +128348,8 @@ class LocalInboxCache {
|
|
|
128259
128348
|
if (!isValidMappedFilename(filename))
|
|
128260
128349
|
return null;
|
|
128261
128350
|
try {
|
|
128262
|
-
const emailPath =
|
|
128263
|
-
const content = await
|
|
128351
|
+
const emailPath = join32(this.cacheDir, "emails", `${filename}.json`);
|
|
128352
|
+
const content = await readFile8(emailPath, "utf-8");
|
|
128264
128353
|
return JSON.parse(content);
|
|
128265
128354
|
} catch {
|
|
128266
128355
|
return null;
|
|
@@ -128311,10 +128400,10 @@ class LocalInboxCache {
|
|
|
128311
128400
|
if (!safeFilename) {
|
|
128312
128401
|
throw new Error("Invalid attachment filename");
|
|
128313
128402
|
}
|
|
128314
|
-
const attachmentDir =
|
|
128315
|
-
await
|
|
128316
|
-
const attachmentPath =
|
|
128317
|
-
await
|
|
128403
|
+
const attachmentDir = join32(this.cacheDir, "attachments", emailFilename);
|
|
128404
|
+
await mkdir8(attachmentDir, { recursive: true });
|
|
128405
|
+
const attachmentPath = join32(attachmentDir, safeFilename);
|
|
128406
|
+
await writeFile7(attachmentPath, content);
|
|
128318
128407
|
return attachmentPath;
|
|
128319
128408
|
}
|
|
128320
128409
|
async getAttachmentPath(emailId, filename) {
|
|
@@ -128327,7 +128416,7 @@ class LocalInboxCache {
|
|
|
128327
128416
|
return null;
|
|
128328
128417
|
}
|
|
128329
128418
|
try {
|
|
128330
|
-
const attachmentPath =
|
|
128419
|
+
const attachmentPath = join32(this.cacheDir, "attachments", emailFilename, safeFilename);
|
|
128331
128420
|
await stat4(attachmentPath);
|
|
128332
128421
|
return attachmentPath;
|
|
128333
128422
|
} catch {
|
|
@@ -128350,10 +128439,10 @@ class LocalInboxCache {
|
|
|
128350
128439
|
const filename = row.filename || emailIdToFilename(row.id);
|
|
128351
128440
|
if (isValidMappedFilename(filename)) {
|
|
128352
128441
|
try {
|
|
128353
|
-
await
|
|
128442
|
+
await rm3(join32(this.cacheDir, "emails", `${filename}.json`));
|
|
128354
128443
|
} catch {}
|
|
128355
128444
|
try {
|
|
128356
|
-
await
|
|
128445
|
+
await rm3(join32(this.cacheDir, "attachments", filename), { recursive: true });
|
|
128357
128446
|
} catch {}
|
|
128358
128447
|
}
|
|
128359
128448
|
}
|
|
@@ -128365,20 +128454,20 @@ class LocalInboxCache {
|
|
|
128365
128454
|
async getCacheSize() {
|
|
128366
128455
|
let totalSize = 0;
|
|
128367
128456
|
try {
|
|
128368
|
-
const emailsDir =
|
|
128457
|
+
const emailsDir = join32(this.cacheDir, "emails");
|
|
128369
128458
|
const files = await readdir(emailsDir);
|
|
128370
128459
|
for (const file of files) {
|
|
128371
|
-
const fileStat = await stat4(
|
|
128460
|
+
const fileStat = await stat4(join32(emailsDir, file));
|
|
128372
128461
|
totalSize += fileStat.size;
|
|
128373
128462
|
}
|
|
128374
128463
|
} catch {}
|
|
128375
128464
|
try {
|
|
128376
|
-
const attachmentsDir =
|
|
128465
|
+
const attachmentsDir = join32(this.cacheDir, "attachments");
|
|
128377
128466
|
const dirs = await readdir(attachmentsDir);
|
|
128378
128467
|
for (const dir of dirs) {
|
|
128379
|
-
const files = await readdir(
|
|
128468
|
+
const files = await readdir(join32(attachmentsDir, dir));
|
|
128380
128469
|
for (const file of files) {
|
|
128381
|
-
const fileStat = await stat4(
|
|
128470
|
+
const fileStat = await stat4(join32(attachmentsDir, dir, file));
|
|
128382
128471
|
totalSize += fileStat.size;
|
|
128383
128472
|
}
|
|
128384
128473
|
}
|
|
@@ -128387,7 +128476,7 @@ class LocalInboxCache {
|
|
|
128387
128476
|
}
|
|
128388
128477
|
async clear() {
|
|
128389
128478
|
try {
|
|
128390
|
-
await
|
|
128479
|
+
await rm3(this.cacheDir, { recursive: true });
|
|
128391
128480
|
} catch {}
|
|
128392
128481
|
this.db().prepare("DELETE FROM inbox_cache WHERE assistant_id = ?").run(this.assistantId);
|
|
128393
128482
|
this.db().prepare("DELETE FROM inbox_sync WHERE assistant_id = ?").run(this.assistantId);
|
|
@@ -146615,8 +146704,8 @@ function many(p4) {
|
|
|
146615
146704
|
function many1(p4) {
|
|
146616
146705
|
return ab2(p4, many(p4), (head, tail) => [head, ...tail]);
|
|
146617
146706
|
}
|
|
146618
|
-
function ab2(pa, pb,
|
|
146619
|
-
return (data, i4) => mapOuter(pa(data, i4), (ma) => mapInner(pb(data, ma.position), (vb, j4) =>
|
|
146707
|
+
function ab2(pa, pb, join33) {
|
|
146708
|
+
return (data, i4) => mapOuter(pa(data, i4), (ma) => mapInner(pb(data, ma.position), (vb, j4) => join33(ma.value, vb, data, i4, j4)));
|
|
146620
146709
|
}
|
|
146621
146710
|
function left(pa, pb) {
|
|
146622
146711
|
return ab2(pa, pb, (va) => va);
|
|
@@ -146624,8 +146713,8 @@ function left(pa, pb) {
|
|
|
146624
146713
|
function right(pa, pb) {
|
|
146625
146714
|
return ab2(pa, pb, (va, vb) => vb);
|
|
146626
146715
|
}
|
|
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) =>
|
|
146716
|
+
function abc(pa, pb, pc, join33) {
|
|
146717
|
+
return (data, i4) => mapOuter(pa(data, i4), (ma) => mapOuter(pb(data, ma.position), (mb) => mapInner(pc(data, mb.position), (vc, j4) => join33(ma.value, mb.value, vc, data, i4, j4))));
|
|
146629
146718
|
}
|
|
146630
146719
|
function middle(pa, pb, pc) {
|
|
146631
146720
|
return abc(pa, pb, pc, (ra, rb) => rb);
|
|
@@ -170212,7 +170301,7 @@ var init_providers = __esm(() => {
|
|
|
170212
170301
|
});
|
|
170213
170302
|
|
|
170214
170303
|
// packages/core/src/inbox/inbox-manager.ts
|
|
170215
|
-
import { join as
|
|
170304
|
+
import { join as join33 } from "path";
|
|
170216
170305
|
|
|
170217
170306
|
class InboxManager {
|
|
170218
170307
|
assistantId;
|
|
@@ -170386,7 +170475,7 @@ class InboxManager {
|
|
|
170386
170475
|
}
|
|
170387
170476
|
}
|
|
170388
170477
|
function createInboxManager(assistantId, assistantName, config, configDir) {
|
|
170389
|
-
const basePath =
|
|
170478
|
+
const basePath = join33(configDir, "messages");
|
|
170390
170479
|
return new InboxManager({
|
|
170391
170480
|
assistantId,
|
|
170392
170481
|
assistantName,
|
|
@@ -172677,7 +172766,7 @@ var init_secrets_client = __esm(() => {
|
|
|
172677
172766
|
});
|
|
172678
172767
|
|
|
172679
172768
|
// packages/core/src/wallet/storage/local-client.ts
|
|
172680
|
-
function
|
|
172769
|
+
function getDb13(injected) {
|
|
172681
172770
|
if (injected)
|
|
172682
172771
|
return injected;
|
|
172683
172772
|
return getDatabase();
|
|
@@ -172689,7 +172778,7 @@ class LocalWalletClient {
|
|
|
172689
172778
|
this.injectedDb = options.db;
|
|
172690
172779
|
}
|
|
172691
172780
|
db() {
|
|
172692
|
-
return
|
|
172781
|
+
return getDb13(this.injectedDb);
|
|
172693
172782
|
}
|
|
172694
172783
|
async listCards(assistantId) {
|
|
172695
172784
|
const rows = this.db().query("SELECT * FROM wallet_cards WHERE assistant_id = ? ORDER BY created_at DESC").all(assistantId);
|
|
@@ -173537,7 +173626,7 @@ var init_secrets_client2 = __esm(() => {
|
|
|
173537
173626
|
});
|
|
173538
173627
|
|
|
173539
173628
|
// packages/core/src/secrets/storage/local-client.ts
|
|
173540
|
-
function
|
|
173629
|
+
function getDb14(injected) {
|
|
173541
173630
|
if (injected)
|
|
173542
173631
|
return injected;
|
|
173543
173632
|
return getDatabase();
|
|
@@ -173549,7 +173638,7 @@ class LocalSecretsClient {
|
|
|
173549
173638
|
this.injectedDb = options.db;
|
|
173550
173639
|
}
|
|
173551
173640
|
db() {
|
|
173552
|
-
return
|
|
173641
|
+
return getDb14(this.injectedDb);
|
|
173553
173642
|
}
|
|
173554
173643
|
async listSecrets(scope, assistantId) {
|
|
173555
173644
|
const items = [];
|
|
@@ -174114,7 +174203,7 @@ var init_secrets = __esm(async () => {
|
|
|
174114
174203
|
function getMessagesBasePath() {
|
|
174115
174204
|
return "";
|
|
174116
174205
|
}
|
|
174117
|
-
function
|
|
174206
|
+
function getDb15(injected) {
|
|
174118
174207
|
if (injected)
|
|
174119
174208
|
return injected;
|
|
174120
174209
|
return getDatabase();
|
|
@@ -174163,7 +174252,7 @@ class LocalMessagesStorage {
|
|
|
174163
174252
|
this.injectedDb = options.db;
|
|
174164
174253
|
}
|
|
174165
174254
|
db() {
|
|
174166
|
-
return
|
|
174255
|
+
return getDb15(this.injectedDb);
|
|
174167
174256
|
}
|
|
174168
174257
|
async ensureDirectories(_assistantId) {}
|
|
174169
174258
|
async loadRegistry() {
|
|
@@ -174410,8 +174499,8 @@ var init_local_storage = __esm(async () => {
|
|
|
174410
174499
|
});
|
|
174411
174500
|
|
|
174412
174501
|
// packages/core/src/messages/watcher.ts
|
|
174413
|
-
import { watch, existsSync as
|
|
174414
|
-
import { join as
|
|
174502
|
+
import { watch, existsSync as existsSync22, readdirSync as readdirSync7 } from "fs";
|
|
174503
|
+
import { join as join34 } from "path";
|
|
174415
174504
|
|
|
174416
174505
|
class InboxWatcher {
|
|
174417
174506
|
assistantId;
|
|
@@ -174423,14 +174512,14 @@ class InboxWatcher {
|
|
|
174423
174512
|
constructor(assistantId, basePath) {
|
|
174424
174513
|
this.assistantId = assistantId;
|
|
174425
174514
|
const base = basePath || getMessagesBasePath();
|
|
174426
|
-
this.inboxPath =
|
|
174515
|
+
this.inboxPath = join34(base, assistantId, "messages");
|
|
174427
174516
|
}
|
|
174428
174517
|
start() {
|
|
174429
174518
|
if (this.running)
|
|
174430
174519
|
return;
|
|
174431
174520
|
this.running = true;
|
|
174432
174521
|
this.snapshotExisting();
|
|
174433
|
-
if (!
|
|
174522
|
+
if (!existsSync22(this.inboxPath)) {
|
|
174434
174523
|
this.pollForDirectory();
|
|
174435
174524
|
return;
|
|
174436
174525
|
}
|
|
@@ -174455,8 +174544,8 @@ class InboxWatcher {
|
|
|
174455
174544
|
}
|
|
174456
174545
|
snapshotExisting() {
|
|
174457
174546
|
try {
|
|
174458
|
-
if (
|
|
174459
|
-
const files =
|
|
174547
|
+
if (existsSync22(this.inboxPath)) {
|
|
174548
|
+
const files = readdirSync7(this.inboxPath);
|
|
174460
174549
|
for (const file of files) {
|
|
174461
174550
|
if (file.endsWith(".json")) {
|
|
174462
174551
|
this.knownFiles.add(file);
|
|
@@ -174498,7 +174587,7 @@ class InboxWatcher {
|
|
|
174498
174587
|
clearInterval(interval);
|
|
174499
174588
|
return;
|
|
174500
174589
|
}
|
|
174501
|
-
if (
|
|
174590
|
+
if (existsSync22(this.inboxPath)) {
|
|
174502
174591
|
clearInterval(interval);
|
|
174503
174592
|
this.snapshotExisting();
|
|
174504
174593
|
this.startWatching();
|
|
@@ -175203,7 +175292,7 @@ var init_messages5 = __esm(async () => {
|
|
|
175203
175292
|
function getWebhooksBasePath() {
|
|
175204
175293
|
return "";
|
|
175205
175294
|
}
|
|
175206
|
-
function
|
|
175295
|
+
function getDb16(injected) {
|
|
175207
175296
|
if (injected)
|
|
175208
175297
|
return injected;
|
|
175209
175298
|
return getDatabase();
|
|
@@ -175266,7 +175355,7 @@ class LocalWebhookStorage {
|
|
|
175266
175355
|
this.injectedDb = options.db;
|
|
175267
175356
|
}
|
|
175268
175357
|
db() {
|
|
175269
|
-
return
|
|
175358
|
+
return getDb16(this.injectedDb);
|
|
175270
175359
|
}
|
|
175271
175360
|
async ensureDirectories(_webhookId) {}
|
|
175272
175361
|
async loadIndex() {
|
|
@@ -175400,8 +175489,8 @@ var init_local_storage2 = __esm(async () => {
|
|
|
175400
175489
|
});
|
|
175401
175490
|
|
|
175402
175491
|
// packages/core/src/webhooks/watcher.ts
|
|
175403
|
-
import { watch as watch2, existsSync as
|
|
175404
|
-
import { join as
|
|
175492
|
+
import { watch as watch2, existsSync as existsSync23, readdirSync as readdirSync8 } from "fs";
|
|
175493
|
+
import { join as join35 } from "path";
|
|
175405
175494
|
|
|
175406
175495
|
class WebhookEventWatcher {
|
|
175407
175496
|
basePath;
|
|
@@ -175413,13 +175502,13 @@ class WebhookEventWatcher {
|
|
|
175413
175502
|
directoryWatcher = null;
|
|
175414
175503
|
constructor(basePath) {
|
|
175415
175504
|
this.basePath = basePath || getWebhooksBasePath();
|
|
175416
|
-
this.eventsPath =
|
|
175505
|
+
this.eventsPath = join35(this.basePath, "events");
|
|
175417
175506
|
}
|
|
175418
175507
|
start() {
|
|
175419
175508
|
if (this.running)
|
|
175420
175509
|
return;
|
|
175421
175510
|
this.running = true;
|
|
175422
|
-
if (!
|
|
175511
|
+
if (!existsSync23(this.eventsPath)) {
|
|
175423
175512
|
this.pollForDirectory();
|
|
175424
175513
|
return;
|
|
175425
175514
|
}
|
|
@@ -175452,8 +175541,8 @@ class WebhookEventWatcher {
|
|
|
175452
175541
|
this.directoryWatcher = watch2(this.eventsPath, (eventType, filename) => {
|
|
175453
175542
|
if (!filename || eventType !== "rename")
|
|
175454
175543
|
return;
|
|
175455
|
-
const dirPath =
|
|
175456
|
-
if (
|
|
175544
|
+
const dirPath = join35(this.eventsPath, filename);
|
|
175545
|
+
if (existsSync23(dirPath) && !this.watchers.has(filename)) {
|
|
175457
175546
|
this.watchWebhookDir(filename);
|
|
175458
175547
|
}
|
|
175459
175548
|
});
|
|
@@ -175469,7 +175558,7 @@ class WebhookEventWatcher {
|
|
|
175469
175558
|
});
|
|
175470
175559
|
} catch {}
|
|
175471
175560
|
try {
|
|
175472
|
-
const dirs =
|
|
175561
|
+
const dirs = readdirSync8(this.eventsPath);
|
|
175473
175562
|
for (const dir of dirs) {
|
|
175474
175563
|
this.watchWebhookDir(dir);
|
|
175475
175564
|
}
|
|
@@ -175478,12 +175567,12 @@ class WebhookEventWatcher {
|
|
|
175478
175567
|
watchWebhookDir(webhookId) {
|
|
175479
175568
|
if (this.watchers.has(webhookId))
|
|
175480
175569
|
return;
|
|
175481
|
-
const dirPath =
|
|
175482
|
-
if (!
|
|
175570
|
+
const dirPath = join35(this.eventsPath, webhookId);
|
|
175571
|
+
if (!existsSync23(dirPath))
|
|
175483
175572
|
return;
|
|
175484
175573
|
const known = new Set;
|
|
175485
175574
|
try {
|
|
175486
|
-
const files =
|
|
175575
|
+
const files = readdirSync8(dirPath);
|
|
175487
175576
|
for (const file of files) {
|
|
175488
175577
|
if (file.endsWith(".json") && file !== "index.json") {
|
|
175489
175578
|
known.add(file);
|
|
@@ -175523,7 +175612,7 @@ class WebhookEventWatcher {
|
|
|
175523
175612
|
clearInterval(interval);
|
|
175524
175613
|
return;
|
|
175525
175614
|
}
|
|
175526
|
-
if (
|
|
175615
|
+
if (existsSync23(this.eventsPath)) {
|
|
175527
175616
|
clearInterval(interval);
|
|
175528
175617
|
this.startWatchingAll();
|
|
175529
175618
|
}
|
|
@@ -176845,17 +176934,17 @@ import { spawn as spawn4 } from "child_process";
|
|
|
176845
176934
|
import { createInterface } from "readline";
|
|
176846
176935
|
import * as fs4 from "fs";
|
|
176847
176936
|
import { stat as statPromise, open as open2 } from "fs/promises";
|
|
176848
|
-
import { join as
|
|
176849
|
-
import { homedir as
|
|
176850
|
-
import { dirname as
|
|
176937
|
+
import { join as join36 } from "path";
|
|
176938
|
+
import { homedir as homedir18 } from "os";
|
|
176939
|
+
import { dirname as dirname14, join as join210 } from "path";
|
|
176851
176940
|
import { cwd } from "process";
|
|
176852
176941
|
import { realpathSync as realpathSync2 } from "fs";
|
|
176853
176942
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
176854
176943
|
import { randomUUID as randomUUID22 } from "crypto";
|
|
176855
|
-
import { appendFileSync as appendFileSync22, existsSync as
|
|
176856
|
-
import { join as
|
|
176944
|
+
import { appendFileSync as appendFileSync22, existsSync as existsSync25, mkdirSync as mkdirSync22 } from "fs";
|
|
176945
|
+
import { join as join37 } from "path";
|
|
176857
176946
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
176858
|
-
import { join as
|
|
176947
|
+
import { join as join42 } from "path";
|
|
176859
176948
|
import { fileURLToPath } from "url";
|
|
176860
176949
|
function createAbortController(maxListeners = DEFAULT_MAX_LISTENERS) {
|
|
176861
176950
|
const controller = new AbortController;
|
|
@@ -177130,7 +177219,7 @@ function shouldShowDebugMessage(message, filter) {
|
|
|
177130
177219
|
return shouldShowDebugCategories(categories, filter);
|
|
177131
177220
|
}
|
|
177132
177221
|
function getClaudeConfigHomeDir() {
|
|
177133
|
-
return process.env.CLAUDE_CONFIG_DIR ??
|
|
177222
|
+
return process.env.CLAUDE_CONFIG_DIR ?? join36(homedir18(), ".claude");
|
|
177134
177223
|
}
|
|
177135
177224
|
function isEnvTruthy(envVar) {
|
|
177136
177225
|
if (!envVar)
|
|
@@ -177345,8 +177434,8 @@ function getDebugWriter() {
|
|
|
177345
177434
|
debugWriter = createBufferedWriter({
|
|
177346
177435
|
writeFn: (content) => {
|
|
177347
177436
|
const path3 = getDebugLogPath();
|
|
177348
|
-
if (!getFsImplementation().existsSync(
|
|
177349
|
-
getFsImplementation().mkdirSync(
|
|
177437
|
+
if (!getFsImplementation().existsSync(dirname14(path3))) {
|
|
177438
|
+
getFsImplementation().mkdirSync(dirname14(path3));
|
|
177350
177439
|
}
|
|
177351
177440
|
getFsImplementation().appendFileSync(path3, content);
|
|
177352
177441
|
updateLatestDebugLogSymlink();
|
|
@@ -177407,9 +177496,9 @@ function getOrCreateDebugFile() {
|
|
|
177407
177496
|
if (!process.env.DEBUG_CLAUDE_AGENT_SDK) {
|
|
177408
177497
|
return null;
|
|
177409
177498
|
}
|
|
177410
|
-
const debugDir =
|
|
177411
|
-
debugFilePath =
|
|
177412
|
-
if (!
|
|
177499
|
+
const debugDir = join37(getClaudeConfigHomeDir(), "debug");
|
|
177500
|
+
debugFilePath = join37(debugDir, `sdk-${randomUUID22()}.txt`);
|
|
177501
|
+
if (!existsSync25(debugDir)) {
|
|
177413
177502
|
mkdirSync22(debugDir, { recursive: true });
|
|
177414
177503
|
}
|
|
177415
177504
|
process.stderr.write(`SDK debug logs: ${debugFilePath}
|
|
@@ -190767,7 +190856,7 @@ var init_sdk2 = __esm(() => {
|
|
|
190767
190856
|
}
|
|
190768
190857
|
try {
|
|
190769
190858
|
const debugLogPath = getDebugLogPath();
|
|
190770
|
-
const debugLogsDir =
|
|
190859
|
+
const debugLogsDir = dirname14(debugLogPath);
|
|
190771
190860
|
const latestSymlinkPath = join210(debugLogsDir, "latest");
|
|
190772
190861
|
if (!getFsImplementation().existsSync(debugLogsDir)) {
|
|
190773
190862
|
getFsImplementation().mkdirSync(debugLogsDir);
|
|
@@ -191465,8 +191554,8 @@ var init_sdk2 = __esm(() => {
|
|
|
191465
191554
|
let pathToClaudeCodeExecutable = options.pathToClaudeCodeExecutable;
|
|
191466
191555
|
if (!pathToClaudeCodeExecutable) {
|
|
191467
191556
|
const filename = fileURLToPath(import.meta.url);
|
|
191468
|
-
const dirname22 =
|
|
191469
|
-
pathToClaudeCodeExecutable =
|
|
191557
|
+
const dirname22 = join42(filename, "..");
|
|
191558
|
+
pathToClaudeCodeExecutable = join42(dirname22, "cli.js");
|
|
191470
191559
|
}
|
|
191471
191560
|
const processEnv = { ...options.env ?? process.env };
|
|
191472
191561
|
if (!processEnv.CLAUDE_CODE_ENTRYPOINT) {
|
|
@@ -199677,45 +199766,50 @@ var init_channels = __esm(async () => {
|
|
|
199677
199766
|
});
|
|
199678
199767
|
|
|
199679
199768
|
// 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);
|
|
199769
|
+
function getDb17() {
|
|
199770
|
+
return getDatabase();
|
|
199685
199771
|
}
|
|
199686
|
-
function
|
|
199687
|
-
|
|
199688
|
-
|
|
199772
|
+
function rowToPerson(row) {
|
|
199773
|
+
const person = {
|
|
199774
|
+
id: row.id,
|
|
199775
|
+
name: row.name,
|
|
199776
|
+
status: "active",
|
|
199777
|
+
createdAt: new Date(row.created_at).toISOString(),
|
|
199778
|
+
updatedAt: new Date(row.updated_at).toISOString()
|
|
199779
|
+
};
|
|
199780
|
+
if (row.email)
|
|
199781
|
+
person.email = row.email;
|
|
199782
|
+
if (row.avatar_url)
|
|
199783
|
+
person.avatar = row.avatar_url;
|
|
199784
|
+
if (row.metadata) {
|
|
199785
|
+
try {
|
|
199786
|
+
const meta = JSON.parse(row.metadata);
|
|
199787
|
+
if (meta.status)
|
|
199788
|
+
person.status = meta.status;
|
|
199789
|
+
if (meta.defaultIdentityId)
|
|
199790
|
+
person.defaultIdentityId = meta.defaultIdentityId;
|
|
199791
|
+
} catch {}
|
|
199689
199792
|
}
|
|
199793
|
+
return person;
|
|
199690
199794
|
}
|
|
199691
199795
|
|
|
199692
199796
|
class PeopleStore {
|
|
199693
|
-
basePath;
|
|
199694
199797
|
people = new Map;
|
|
199695
199798
|
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");
|
|
199799
|
+
db;
|
|
199800
|
+
constructor(db) {
|
|
199801
|
+
this.db = db || getDb17();
|
|
199708
199802
|
}
|
|
199709
199803
|
async initialize() {
|
|
199710
|
-
|
|
199711
|
-
const
|
|
199712
|
-
|
|
199713
|
-
|
|
199714
|
-
|
|
199715
|
-
|
|
199716
|
-
}
|
|
199804
|
+
const rows = this.db.query("SELECT * FROM people").all();
|
|
199805
|
+
for (const row of rows) {
|
|
199806
|
+
try {
|
|
199807
|
+
const person = rowToPerson(row);
|
|
199808
|
+
this.people.set(person.id, person);
|
|
199809
|
+
} catch {}
|
|
199717
199810
|
}
|
|
199718
|
-
this.
|
|
199811
|
+
const activeRow = this.db.query("SELECT person_id FROM people_active WHERE key = 'active'").get();
|
|
199812
|
+
this.activeId = activeRow?.person_id || null;
|
|
199719
199813
|
}
|
|
199720
199814
|
async create(name2, email2, avatar) {
|
|
199721
199815
|
const id = `person_${generateId().slice(0, 12)}`;
|
|
@@ -199729,9 +199823,8 @@ class PeopleStore {
|
|
|
199729
199823
|
createdAt: now2,
|
|
199730
199824
|
updatedAt: now2
|
|
199731
199825
|
};
|
|
199732
|
-
|
|
199826
|
+
this.persistPerson(person);
|
|
199733
199827
|
this.people.set(id, person);
|
|
199734
|
-
await this.appendToIndex(id);
|
|
199735
199828
|
return person;
|
|
199736
199829
|
}
|
|
199737
199830
|
async update(id, updates) {
|
|
@@ -199746,18 +199839,13 @@ class PeopleStore {
|
|
|
199746
199839
|
createdAt: existing.createdAt,
|
|
199747
199840
|
updatedAt: new Date().toISOString()
|
|
199748
199841
|
};
|
|
199749
|
-
|
|
199842
|
+
this.persistPerson(updated);
|
|
199750
199843
|
this.people.set(id, updated);
|
|
199751
199844
|
return updated;
|
|
199752
199845
|
}
|
|
199753
199846
|
async delete(id) {
|
|
199754
|
-
|
|
199755
|
-
const dir = join44(this.basePath, id);
|
|
199756
|
-
if (existsSync31(dir)) {
|
|
199757
|
-
await rm5(dir, { recursive: true });
|
|
199758
|
-
}
|
|
199847
|
+
this.db.prepare("DELETE FROM people WHERE id = ?").run(id);
|
|
199759
199848
|
this.people.delete(id);
|
|
199760
|
-
await this.removeFromIndex(id);
|
|
199761
199849
|
if (this.activeId === id) {
|
|
199762
199850
|
await this.setActive(null);
|
|
199763
199851
|
}
|
|
@@ -199802,66 +199890,28 @@ class PeopleStore {
|
|
|
199802
199890
|
}
|
|
199803
199891
|
}
|
|
199804
199892
|
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);
|
|
199893
|
+
if (id) {
|
|
199894
|
+
this.db.prepare("INSERT OR REPLACE INTO people_active (key, person_id) VALUES ('active', ?)").run(id);
|
|
199895
|
+
} else {
|
|
199896
|
+
this.db.prepare("DELETE FROM people_active WHERE key = 'active'").run();
|
|
199826
199897
|
}
|
|
199827
199898
|
}
|
|
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));
|
|
199899
|
+
persistPerson(person) {
|
|
199900
|
+
const nowMs = new Date(person.updatedAt).getTime();
|
|
199901
|
+
const createdMs = new Date(person.createdAt).getTime();
|
|
199902
|
+
const metadata = {};
|
|
199903
|
+
if (person.status !== "active")
|
|
199904
|
+
metadata.status = person.status;
|
|
199905
|
+
if (person.defaultIdentityId)
|
|
199906
|
+
metadata.defaultIdentityId = person.defaultIdentityId;
|
|
199907
|
+
const metadataStr = Object.keys(metadata).length > 0 ? JSON.stringify(metadata) : null;
|
|
199908
|
+
this.db.prepare(`INSERT OR REPLACE INTO people (id, name, email, phone, role, notes, avatar_url, metadata, created_at, updated_at)
|
|
199909
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(person.id, person.name, person.email || null, null, null, null, person.avatar || null, metadataStr, createdMs, nowMs);
|
|
199858
199910
|
}
|
|
199859
199911
|
}
|
|
199860
|
-
var SAFE_ID_PATTERN6;
|
|
199861
199912
|
var init_store8 = __esm(async () => {
|
|
199862
199913
|
init_src2();
|
|
199863
|
-
await
|
|
199864
|
-
SAFE_ID_PATTERN6 = /^[a-zA-Z0-9_-]+$/;
|
|
199914
|
+
await init_database();
|
|
199865
199915
|
});
|
|
199866
199916
|
|
|
199867
199917
|
// packages/core/src/people/manager.ts
|
|
@@ -204403,7 +204453,7 @@ var init_contacts = __esm(async () => {
|
|
|
204403
204453
|
});
|
|
204404
204454
|
|
|
204405
204455
|
// packages/core/src/sessions/store.ts
|
|
204406
|
-
function
|
|
204456
|
+
function rowToSession2(row) {
|
|
204407
204457
|
return {
|
|
204408
204458
|
id: row.id,
|
|
204409
204459
|
cwd: row.cwd,
|
|
@@ -204429,7 +204479,7 @@ class SessionStore {
|
|
|
204429
204479
|
load(id) {
|
|
204430
204480
|
try {
|
|
204431
204481
|
const row = this.db.query("SELECT * FROM persisted_sessions WHERE id = ?").get(id);
|
|
204432
|
-
return row ?
|
|
204482
|
+
return row ? rowToSession2(row) : null;
|
|
204433
204483
|
} catch {
|
|
204434
204484
|
return null;
|
|
204435
204485
|
}
|
|
@@ -204437,7 +204487,7 @@ class SessionStore {
|
|
|
204437
204487
|
list() {
|
|
204438
204488
|
try {
|
|
204439
204489
|
const rows = this.db.query("SELECT * FROM persisted_sessions ORDER BY updated_at DESC").all();
|
|
204440
|
-
return rows.map(
|
|
204490
|
+
return rows.map(rowToSession2);
|
|
204441
204491
|
} catch {
|
|
204442
204492
|
return [];
|
|
204443
204493
|
}
|
|
@@ -204450,7 +204500,7 @@ class SessionStore {
|
|
|
204450
204500
|
listRecoverable() {
|
|
204451
204501
|
try {
|
|
204452
204502
|
const rows = this.db.query(`SELECT * FROM persisted_sessions WHERE status != 'closed' ORDER BY updated_at DESC`).all();
|
|
204453
|
-
return rows.map(
|
|
204503
|
+
return rows.map(rowToSession2);
|
|
204454
204504
|
} catch {
|
|
204455
204505
|
return [];
|
|
204456
204506
|
}
|
|
@@ -205032,9 +205082,9 @@ var init_tools15 = __esm(() => {
|
|
|
205032
205082
|
|
|
205033
205083
|
// packages/core/src/sessions/index.ts
|
|
205034
205084
|
var init_sessions3 = __esm(async () => {
|
|
205035
|
-
init_verification();
|
|
205036
205085
|
init_tools15();
|
|
205037
205086
|
await __promiseAll([
|
|
205087
|
+
init_verification(),
|
|
205038
205088
|
init_store12(),
|
|
205039
205089
|
init_registry3()
|
|
205040
205090
|
]);
|
|
@@ -206112,7 +206162,7 @@ function createSelfAwarenessToolExecutors(context) {
|
|
|
206112
206162
|
workspace_map: async (input) => {
|
|
206113
206163
|
const { readdir: readdir2, stat: stat5, access } = await import("fs/promises");
|
|
206114
206164
|
const { execSync } = await import("child_process");
|
|
206115
|
-
const { join:
|
|
206165
|
+
const { join: join38, basename: basename7 } = await import("path");
|
|
206116
206166
|
const depth = input.depth ?? 3;
|
|
206117
206167
|
const includeGitStatus = input.include_git_status !== false;
|
|
206118
206168
|
const includeRecentFiles = input.include_recent_files !== false;
|
|
@@ -206158,7 +206208,7 @@ function createSelfAwarenessToolExecutors(context) {
|
|
|
206158
206208
|
break;
|
|
206159
206209
|
}
|
|
206160
206210
|
if (entry.isDirectory()) {
|
|
206161
|
-
const children2 = await buildTree(
|
|
206211
|
+
const children2 = await buildTree(join38(dir, entry.name), currentDepth + 1);
|
|
206162
206212
|
nodes.push({
|
|
206163
206213
|
name: entry.name,
|
|
206164
206214
|
type: "directory",
|
|
@@ -206184,7 +206234,7 @@ function createSelfAwarenessToolExecutors(context) {
|
|
|
206184
206234
|
};
|
|
206185
206235
|
if (includeGitStatus) {
|
|
206186
206236
|
try {
|
|
206187
|
-
await access(
|
|
206237
|
+
await access(join38(cwd2, ".git"));
|
|
206188
206238
|
gitStatus.isRepo = true;
|
|
206189
206239
|
try {
|
|
206190
206240
|
const branch = execSync("git branch --show-current", { cwd: cwd2, encoding: "utf-8" }).trim();
|
|
@@ -206215,7 +206265,7 @@ function createSelfAwarenessToolExecutors(context) {
|
|
|
206215
206265
|
for (const entry of entries) {
|
|
206216
206266
|
if (shouldIgnore(entry.name))
|
|
206217
206267
|
continue;
|
|
206218
|
-
const fullPath =
|
|
206268
|
+
const fullPath = join38(dir, entry.name);
|
|
206219
206269
|
const relPath = relativePath ? `${relativePath}/${entry.name}` : entry.name;
|
|
206220
206270
|
if (entry.isFile()) {
|
|
206221
206271
|
try {
|
|
@@ -206249,12 +206299,12 @@ function createSelfAwarenessToolExecutors(context) {
|
|
|
206249
206299
|
let projectName = basename7(cwd2);
|
|
206250
206300
|
for (const indicator of projectIndicators) {
|
|
206251
206301
|
try {
|
|
206252
|
-
await access(
|
|
206302
|
+
await access(join38(cwd2, indicator.file));
|
|
206253
206303
|
projectType = indicator.type;
|
|
206254
206304
|
if (indicator.file === "package.json") {
|
|
206255
206305
|
try {
|
|
206256
|
-
const { readFile:
|
|
206257
|
-
const pkg = JSON.parse(await
|
|
206306
|
+
const { readFile: readFile9 } = await import("fs/promises");
|
|
206307
|
+
const pkg = JSON.parse(await readFile9(join38(cwd2, indicator.file), "utf-8"));
|
|
206258
206308
|
projectName = pkg.name || projectName;
|
|
206259
206309
|
} catch {}
|
|
206260
206310
|
}
|
|
@@ -211036,7 +211086,6 @@ var init_capabilities2 = __esm(async () => {
|
|
|
211036
211086
|
});
|
|
211037
211087
|
|
|
211038
211088
|
// packages/core/src/agent/loop.ts
|
|
211039
|
-
import { join as join46 } from "path";
|
|
211040
211089
|
function parseErrorCode(message) {
|
|
211041
211090
|
const index = message.indexOf(":");
|
|
211042
211091
|
if (index === -1)
|
|
@@ -211068,7 +211117,6 @@ var init_loop = __esm(async () => {
|
|
|
211068
211117
|
init_limits();
|
|
211069
211118
|
init_llm_response();
|
|
211070
211119
|
init_manager4();
|
|
211071
|
-
init_identity2();
|
|
211072
211120
|
init_self_awareness();
|
|
211073
211121
|
init_memory2();
|
|
211074
211122
|
init_agents();
|
|
@@ -211078,8 +211126,6 @@ var init_loop = __esm(async () => {
|
|
|
211078
211126
|
init_swarm2();
|
|
211079
211127
|
init_coordinator();
|
|
211080
211128
|
init_subagent_manager();
|
|
211081
|
-
init_budget();
|
|
211082
|
-
init_registry2();
|
|
211083
211129
|
await __promiseAll([
|
|
211084
211130
|
init_registry(),
|
|
211085
211131
|
init_connector(),
|
|
@@ -211108,6 +211154,7 @@ var init_loop = __esm(async () => {
|
|
|
211108
211154
|
init_energy2(),
|
|
211109
211155
|
init_store3(),
|
|
211110
211156
|
init_auto_refresh(),
|
|
211157
|
+
init_identity2(),
|
|
211111
211158
|
init_inbox(),
|
|
211112
211159
|
init_wallet(),
|
|
211113
211160
|
init_secrets(),
|
|
@@ -211123,7 +211170,9 @@ var init_loop = __esm(async () => {
|
|
|
211123
211170
|
init_projects(),
|
|
211124
211171
|
init_tasks2(),
|
|
211125
211172
|
init_memory3(),
|
|
211173
|
+
init_budget(),
|
|
211126
211174
|
init_guardrails(),
|
|
211175
|
+
init_registry2(),
|
|
211127
211176
|
init_capabilities2()
|
|
211128
211177
|
]);
|
|
211129
211178
|
AssistantLoop = class AssistantLoop {
|
|
@@ -213752,8 +213801,8 @@ Current state: ${voiceState.enabled ? "enabled" : "disabled"}, STT: ${voiceState
|
|
|
213752
213801
|
return null;
|
|
213753
213802
|
const intervalMs = Math.max(1000, config2.heartbeat?.intervalMs ?? 15000);
|
|
213754
213803
|
const staleThresholdMs = Math.max(intervalMs * 2, config2.heartbeat?.staleThresholdMs ?? 120000);
|
|
213755
|
-
const persistPath = config2.heartbeat?.persistPath ??
|
|
213756
|
-
const historyPath = config2.heartbeat?.historyPath ??
|
|
213804
|
+
const persistPath = config2.heartbeat?.persistPath ?? `<db>:heartbeat_state:${this.sessionId}`;
|
|
213805
|
+
const historyPath = config2.heartbeat?.historyPath ?? `<db>:heartbeat_history:${this.sessionId}`;
|
|
213757
213806
|
return {
|
|
213758
213807
|
intervalMs,
|
|
213759
213808
|
staleThresholdMs,
|
|
@@ -214134,9 +214183,9 @@ class StatsTracker {
|
|
|
214134
214183
|
}
|
|
214135
214184
|
|
|
214136
214185
|
// packages/core/src/tools/connector-index.ts
|
|
214137
|
-
import { join as
|
|
214138
|
-
import { homedir as
|
|
214139
|
-
import { existsSync as
|
|
214186
|
+
import { join as join38, dirname as dirname15 } from "path";
|
|
214187
|
+
import { homedir as homedir19 } from "os";
|
|
214188
|
+
import { existsSync as existsSync26, mkdirSync as mkdirSync15, writeFileSync as writeFileSync11, readFileSync as readFileSync14 } from "fs";
|
|
214140
214189
|
var TAG_KEYWORDS, INDEX_VERSION = 1, INDEX_TTL_MS, ConnectorIndex;
|
|
214141
214190
|
var init_connector_index = __esm(() => {
|
|
214142
214191
|
TAG_KEYWORDS = {
|
|
@@ -214170,18 +214219,18 @@ var init_connector_index = __esm(() => {
|
|
|
214170
214219
|
}
|
|
214171
214220
|
getHomeDir() {
|
|
214172
214221
|
const envHome = process.env.HOME || process.env.USERPROFILE;
|
|
214173
|
-
return envHome && envHome.trim().length > 0 ? envHome :
|
|
214222
|
+
return envHome && envHome.trim().length > 0 ? envHome : homedir19();
|
|
214174
214223
|
}
|
|
214175
214224
|
getCachePath() {
|
|
214176
|
-
return
|
|
214225
|
+
return join38(this.getHomeDir(), ".assistants", "cache", "connector-index.json");
|
|
214177
214226
|
}
|
|
214178
214227
|
loadDiskCache() {
|
|
214179
214228
|
ConnectorIndex.indexLoaded = true;
|
|
214180
214229
|
try {
|
|
214181
214230
|
const cachePath = this.getCachePath();
|
|
214182
|
-
if (!
|
|
214231
|
+
if (!existsSync26(cachePath))
|
|
214183
214232
|
return;
|
|
214184
|
-
const data = JSON.parse(
|
|
214233
|
+
const data = JSON.parse(readFileSync14(cachePath, "utf-8"));
|
|
214185
214234
|
if (data.version !== INDEX_VERSION)
|
|
214186
214235
|
return;
|
|
214187
214236
|
if (Date.now() - data.timestamp > INDEX_TTL_MS)
|
|
@@ -214195,16 +214244,16 @@ var init_connector_index = __esm(() => {
|
|
|
214195
214244
|
saveDiskCache() {
|
|
214196
214245
|
try {
|
|
214197
214246
|
const cachePath = this.getCachePath();
|
|
214198
|
-
const cacheDir =
|
|
214199
|
-
if (!
|
|
214200
|
-
|
|
214247
|
+
const cacheDir = dirname15(cachePath);
|
|
214248
|
+
if (!existsSync26(cacheDir)) {
|
|
214249
|
+
mkdirSync15(cacheDir, { recursive: true });
|
|
214201
214250
|
}
|
|
214202
214251
|
const data = {
|
|
214203
214252
|
version: INDEX_VERSION,
|
|
214204
214253
|
timestamp: Date.now(),
|
|
214205
214254
|
entries: Object.fromEntries(this.entries)
|
|
214206
214255
|
};
|
|
214207
|
-
|
|
214256
|
+
writeFileSync11(cachePath, JSON.stringify(data));
|
|
214208
214257
|
ConnectorIndex.indexCache = new Map(this.entries);
|
|
214209
214258
|
} catch {}
|
|
214210
214259
|
}
|
|
@@ -214776,17 +214825,17 @@ var init_interviews = __esm(async () => {
|
|
|
214776
214825
|
});
|
|
214777
214826
|
|
|
214778
214827
|
// packages/core/src/memory/sessions.ts
|
|
214779
|
-
import { join as
|
|
214780
|
-
import { existsSync as
|
|
214828
|
+
import { join as join40, dirname as dirname16 } from "path";
|
|
214829
|
+
import { existsSync as existsSync28, mkdirSync as mkdirSync16 } from "fs";
|
|
214781
214830
|
|
|
214782
214831
|
class SessionManager {
|
|
214783
214832
|
db;
|
|
214784
214833
|
constructor(dbPath, assistantId) {
|
|
214785
214834
|
const baseDir = getConfigDir();
|
|
214786
|
-
const path4 = dbPath || (assistantId ?
|
|
214787
|
-
const dir =
|
|
214788
|
-
if (!
|
|
214789
|
-
|
|
214835
|
+
const path4 = dbPath || (assistantId ? join40(baseDir, "assistants", assistantId, "memory.db") : join40(baseDir, "memory.db"));
|
|
214836
|
+
const dir = dirname16(path4);
|
|
214837
|
+
if (!existsSync28(dir)) {
|
|
214838
|
+
mkdirSync16(dir, { recursive: true });
|
|
214790
214839
|
}
|
|
214791
214840
|
const runtime = getRuntime();
|
|
214792
214841
|
this.db = runtime.openDatabase(path4);
|
|
@@ -214899,9 +214948,9 @@ var init_sessions4 = __esm(async () => {
|
|
|
214899
214948
|
]);
|
|
214900
214949
|
});
|
|
214901
214950
|
// packages/core/src/migration/validators.ts
|
|
214902
|
-
import { existsSync as
|
|
214951
|
+
import { existsSync as existsSync29 } from "fs";
|
|
214903
214952
|
function assertNoExistingTarget(targetPath) {
|
|
214904
|
-
if (
|
|
214953
|
+
if (existsSync29(targetPath)) {
|
|
214905
214954
|
throw new Error(`Target already exists at ${targetPath}`);
|
|
214906
214955
|
}
|
|
214907
214956
|
}
|
|
@@ -214919,7 +214968,7 @@ var init_scheduler2 = __esm(async () => {
|
|
|
214919
214968
|
});
|
|
214920
214969
|
|
|
214921
214970
|
// packages/core/src/history/storage.ts
|
|
214922
|
-
function
|
|
214971
|
+
function getDb18() {
|
|
214923
214972
|
return getDatabase();
|
|
214924
214973
|
}
|
|
214925
214974
|
function getHistoryPath() {
|
|
@@ -214927,7 +214976,7 @@ function getHistoryPath() {
|
|
|
214927
214976
|
}
|
|
214928
214977
|
async function loadHistory() {
|
|
214929
214978
|
try {
|
|
214930
|
-
const rows =
|
|
214979
|
+
const rows = getDb18().query(`SELECT command FROM command_history ORDER BY created_at ASC, id ASC LIMIT ${MAX_HISTORY_SIZE}`).all();
|
|
214931
214980
|
return rows.map((r6) => r6.command);
|
|
214932
214981
|
} catch {
|
|
214933
214982
|
return [];
|
|
@@ -214935,7 +214984,7 @@ async function loadHistory() {
|
|
|
214935
214984
|
}
|
|
214936
214985
|
async function saveHistory(history) {
|
|
214937
214986
|
try {
|
|
214938
|
-
const conn =
|
|
214987
|
+
const conn = getDb18();
|
|
214939
214988
|
const trimmed = history.slice(-MAX_HISTORY_SIZE);
|
|
214940
214989
|
conn.transaction(() => {
|
|
214941
214990
|
conn.exec("DELETE FROM command_history");
|
|
@@ -214951,7 +215000,7 @@ async function appendToHistory(command) {
|
|
|
214951
215000
|
if (!command.trim())
|
|
214952
215001
|
return;
|
|
214953
215002
|
try {
|
|
214954
|
-
const conn =
|
|
215003
|
+
const conn = getDb18();
|
|
214955
215004
|
conn.prepare("INSERT INTO command_history (command, created_at) VALUES (?, ?)").run(command, Date.now());
|
|
214956
215005
|
const countRow = conn.query("SELECT COUNT(*) as cnt FROM command_history").get();
|
|
214957
215006
|
if (countRow && countRow.cnt > MAX_HISTORY_SIZE) {
|
|
@@ -215778,12 +215827,10 @@ var init_src3 = __esm(async () => {
|
|
|
215778
215827
|
init_loader();
|
|
215779
215828
|
init_native();
|
|
215780
215829
|
init_scope_context();
|
|
215781
|
-
init_verification();
|
|
215782
215830
|
init_injector();
|
|
215783
215831
|
init_types11();
|
|
215784
215832
|
init_memory2();
|
|
215785
215833
|
init_voice();
|
|
215786
|
-
init_budget();
|
|
215787
215834
|
init_manager4();
|
|
215788
215835
|
init_player();
|
|
215789
215836
|
init_recorder();
|
|
@@ -215820,10 +215867,12 @@ var init_src3 = __esm(async () => {
|
|
|
215820
215867
|
init_store2(),
|
|
215821
215868
|
init_tester(),
|
|
215822
215869
|
init_logger3(),
|
|
215870
|
+
init_verification(),
|
|
215823
215871
|
init_interviews(),
|
|
215824
215872
|
init_store13(),
|
|
215825
215873
|
init_sessions4(),
|
|
215826
215874
|
init_global_memory(),
|
|
215875
|
+
init_budget(),
|
|
215827
215876
|
init_config(),
|
|
215828
215877
|
init_client4(),
|
|
215829
215878
|
init_registry3(),
|
|
@@ -233654,14 +233703,14 @@ var require_filesystem = __commonJS((exports, module) => {
|
|
|
233654
233703
|
var LDD_PATH = "/usr/bin/ldd";
|
|
233655
233704
|
var SELF_PATH = "/proc/self/exe";
|
|
233656
233705
|
var MAX_LENGTH = 2048;
|
|
233657
|
-
var
|
|
233706
|
+
var readFileSync16 = (path4) => {
|
|
233658
233707
|
const fd = fs7.openSync(path4, "r");
|
|
233659
233708
|
const buffer = Buffer.alloc(MAX_LENGTH);
|
|
233660
233709
|
const bytesRead = fs7.readSync(fd, buffer, 0, MAX_LENGTH, 0);
|
|
233661
233710
|
fs7.close(fd, () => {});
|
|
233662
233711
|
return buffer.subarray(0, bytesRead);
|
|
233663
233712
|
};
|
|
233664
|
-
var
|
|
233713
|
+
var readFile9 = (path4) => new Promise((resolve6, reject) => {
|
|
233665
233714
|
fs7.open(path4, "r", (err, fd) => {
|
|
233666
233715
|
if (err) {
|
|
233667
233716
|
reject(err);
|
|
@@ -233677,8 +233726,8 @@ var require_filesystem = __commonJS((exports, module) => {
|
|
|
233677
233726
|
module.exports = {
|
|
233678
233727
|
LDD_PATH,
|
|
233679
233728
|
SELF_PATH,
|
|
233680
|
-
readFileSync:
|
|
233681
|
-
readFile:
|
|
233729
|
+
readFileSync: readFileSync16,
|
|
233730
|
+
readFile: readFile9
|
|
233682
233731
|
};
|
|
233683
233732
|
});
|
|
233684
233733
|
|
|
@@ -233720,7 +233769,7 @@ var require_elf = __commonJS((exports, module) => {
|
|
|
233720
233769
|
var require_detect_libc = __commonJS((exports, module) => {
|
|
233721
233770
|
var childProcess = __require("child_process");
|
|
233722
233771
|
var { isLinux: isLinux2, getReport } = require_process();
|
|
233723
|
-
var { LDD_PATH, SELF_PATH, readFile:
|
|
233772
|
+
var { LDD_PATH, SELF_PATH, readFile: readFile9, readFileSync: readFileSync16 } = require_filesystem();
|
|
233724
233773
|
var { interpreterPath } = require_elf();
|
|
233725
233774
|
var cachedFamilyInterpreter;
|
|
233726
233775
|
var cachedFamilyFilesystem;
|
|
@@ -233800,7 +233849,7 @@ var require_detect_libc = __commonJS((exports, module) => {
|
|
|
233800
233849
|
}
|
|
233801
233850
|
cachedFamilyFilesystem = null;
|
|
233802
233851
|
try {
|
|
233803
|
-
const lddContent = await
|
|
233852
|
+
const lddContent = await readFile9(LDD_PATH);
|
|
233804
233853
|
cachedFamilyFilesystem = getFamilyFromLddContent(lddContent);
|
|
233805
233854
|
} catch (e6) {}
|
|
233806
233855
|
return cachedFamilyFilesystem;
|
|
@@ -233811,7 +233860,7 @@ var require_detect_libc = __commonJS((exports, module) => {
|
|
|
233811
233860
|
}
|
|
233812
233861
|
cachedFamilyFilesystem = null;
|
|
233813
233862
|
try {
|
|
233814
|
-
const lddContent =
|
|
233863
|
+
const lddContent = readFileSync16(LDD_PATH);
|
|
233815
233864
|
cachedFamilyFilesystem = getFamilyFromLddContent(lddContent);
|
|
233816
233865
|
} catch (e6) {}
|
|
233817
233866
|
return cachedFamilyFilesystem;
|
|
@@ -233822,7 +233871,7 @@ var require_detect_libc = __commonJS((exports, module) => {
|
|
|
233822
233871
|
}
|
|
233823
233872
|
cachedFamilyInterpreter = null;
|
|
233824
233873
|
try {
|
|
233825
|
-
const selfContent = await
|
|
233874
|
+
const selfContent = await readFile9(SELF_PATH);
|
|
233826
233875
|
const path4 = interpreterPath(selfContent);
|
|
233827
233876
|
cachedFamilyInterpreter = familyFromInterpreterPath(path4);
|
|
233828
233877
|
} catch (e6) {}
|
|
@@ -233834,7 +233883,7 @@ var require_detect_libc = __commonJS((exports, module) => {
|
|
|
233834
233883
|
}
|
|
233835
233884
|
cachedFamilyInterpreter = null;
|
|
233836
233885
|
try {
|
|
233837
|
-
const selfContent =
|
|
233886
|
+
const selfContent = readFileSync16(SELF_PATH);
|
|
233838
233887
|
const path4 = interpreterPath(selfContent);
|
|
233839
233888
|
cachedFamilyInterpreter = familyFromInterpreterPath(path4);
|
|
233840
233889
|
} catch (e6) {}
|
|
@@ -233882,7 +233931,7 @@ var require_detect_libc = __commonJS((exports, module) => {
|
|
|
233882
233931
|
}
|
|
233883
233932
|
cachedVersionFilesystem = null;
|
|
233884
233933
|
try {
|
|
233885
|
-
const lddContent = await
|
|
233934
|
+
const lddContent = await readFile9(LDD_PATH);
|
|
233886
233935
|
const versionMatch = lddContent.match(RE_GLIBC_VERSION);
|
|
233887
233936
|
if (versionMatch) {
|
|
233888
233937
|
cachedVersionFilesystem = versionMatch[1];
|
|
@@ -233896,7 +233945,7 @@ var require_detect_libc = __commonJS((exports, module) => {
|
|
|
233896
233945
|
}
|
|
233897
233946
|
cachedVersionFilesystem = null;
|
|
233898
233947
|
try {
|
|
233899
|
-
const lddContent =
|
|
233948
|
+
const lddContent = readFileSync16(LDD_PATH);
|
|
233900
233949
|
const versionMatch = lddContent.match(RE_GLIBC_VERSION);
|
|
233901
233950
|
if (versionMatch) {
|
|
233902
233951
|
cachedVersionFilesystem = versionMatch[1];
|
|
@@ -241851,13 +241900,13 @@ async function appPath(appName) {
|
|
|
241851
241900
|
throw new TypeError("Please supply an app name or bundle identifier");
|
|
241852
241901
|
}
|
|
241853
241902
|
try {
|
|
241854
|
-
const { stdout } = await import_execa.default("./main", [appName], { cwd:
|
|
241903
|
+
const { stdout } = await import_execa.default("./main", [appName], { cwd: dirname17 });
|
|
241855
241904
|
return stdout;
|
|
241856
241905
|
} catch (error4) {
|
|
241857
241906
|
throw improveError(error4);
|
|
241858
241907
|
}
|
|
241859
241908
|
}
|
|
241860
|
-
var import_execa,
|
|
241909
|
+
var import_execa, dirname17, improveError = (error4) => {
|
|
241861
241910
|
if (error4.exitCode === 2) {
|
|
241862
241911
|
error4.message = "Couldn't find the app";
|
|
241863
241912
|
}
|
|
@@ -241865,7 +241914,7 @@ var import_execa, dirname20, improveError = (error4) => {
|
|
|
241865
241914
|
};
|
|
241866
241915
|
var init_app_path = __esm(() => {
|
|
241867
241916
|
import_execa = __toESM(require_execa(), 1);
|
|
241868
|
-
|
|
241917
|
+
dirname17 = path4.dirname(fileURLToPath5(import.meta.url));
|
|
241869
241918
|
appPath.sync = (appName) => {
|
|
241870
241919
|
if (process.platform !== "darwin") {
|
|
241871
241920
|
throw new Error("macOS only");
|
|
@@ -241874,7 +241923,7 @@ var init_app_path = __esm(() => {
|
|
|
241874
241923
|
throw new TypeError("Please supply an app name or bundle identifier");
|
|
241875
241924
|
}
|
|
241876
241925
|
try {
|
|
241877
|
-
return import_execa.default.sync("./main", [appName], { cwd:
|
|
241926
|
+
return import_execa.default.sync("./main", [appName], { cwd: dirname17 }).stdout;
|
|
241878
241927
|
} catch (error4) {
|
|
241879
241928
|
throw improveError(error4);
|
|
241880
241929
|
}
|
|
@@ -255193,8 +255242,8 @@ await __promiseAll([
|
|
|
255193
255242
|
]);
|
|
255194
255243
|
var import_react84 = __toESM(require_react(), 1);
|
|
255195
255244
|
import { spawn as spawn6 } from "child_process";
|
|
255196
|
-
import { join as
|
|
255197
|
-
import { homedir as
|
|
255245
|
+
import { join as join43 } from "path";
|
|
255246
|
+
import { homedir as homedir20 } from "os";
|
|
255198
255247
|
|
|
255199
255248
|
// packages/terminal/src/components/Input.tsx
|
|
255200
255249
|
await init_build2();
|
|
@@ -285892,8 +285941,8 @@ await init_src3();
|
|
|
285892
285941
|
// packages/terminal/src/lib/budgets.ts
|
|
285893
285942
|
init_src2();
|
|
285894
285943
|
await init_src3();
|
|
285895
|
-
import { join as
|
|
285896
|
-
import { mkdir as
|
|
285944
|
+
import { join as join41 } from "path";
|
|
285945
|
+
import { mkdir as mkdir9, readFile as readFile9, writeFile as writeFile8 } from "fs/promises";
|
|
285897
285946
|
var PROFILES_FILE = "budgets.json";
|
|
285898
285947
|
var SESSION_MAP_FILE = "budget-sessions.json";
|
|
285899
285948
|
var DEFAULT_PROFILE_ID = "default";
|
|
@@ -285901,22 +285950,22 @@ function cloneConfig2(config2) {
|
|
|
285901
285950
|
return JSON.parse(JSON.stringify(config2 || DEFAULT_BUDGET_CONFIG));
|
|
285902
285951
|
}
|
|
285903
285952
|
async function ensureDir(baseDir) {
|
|
285904
|
-
await
|
|
285953
|
+
await mkdir9(baseDir, { recursive: true });
|
|
285905
285954
|
}
|
|
285906
285955
|
async function readJsonFile(path6) {
|
|
285907
285956
|
try {
|
|
285908
|
-
const raw = await
|
|
285957
|
+
const raw = await readFile9(path6, "utf-8");
|
|
285909
285958
|
return JSON.parse(raw);
|
|
285910
285959
|
} catch {
|
|
285911
285960
|
return null;
|
|
285912
285961
|
}
|
|
285913
285962
|
}
|
|
285914
285963
|
async function writeJsonFile(path6, data) {
|
|
285915
|
-
await
|
|
285964
|
+
await writeFile8(path6, JSON.stringify(data, null, 2), "utf-8");
|
|
285916
285965
|
}
|
|
285917
285966
|
async function loadBudgetProfiles(baseDir, seedConfig) {
|
|
285918
285967
|
await ensureDir(baseDir);
|
|
285919
|
-
const path6 =
|
|
285968
|
+
const path6 = join41(baseDir, PROFILES_FILE);
|
|
285920
285969
|
const data = await readJsonFile(path6);
|
|
285921
285970
|
const profiles = Array.isArray(data?.profiles) ? data.profiles : [];
|
|
285922
285971
|
if (profiles.length === 0) {
|
|
@@ -285936,7 +285985,7 @@ async function loadBudgetProfiles(baseDir, seedConfig) {
|
|
|
285936
285985
|
}
|
|
285937
285986
|
async function saveBudgetProfiles(baseDir, profiles) {
|
|
285938
285987
|
await ensureDir(baseDir);
|
|
285939
|
-
const path6 =
|
|
285988
|
+
const path6 = join41(baseDir, PROFILES_FILE);
|
|
285940
285989
|
await writeJsonFile(path6, { profiles });
|
|
285941
285990
|
}
|
|
285942
285991
|
async function createBudgetProfile(baseDir, name2, config2, description) {
|
|
@@ -285974,13 +286023,13 @@ async function deleteBudgetProfile(baseDir, id) {
|
|
|
285974
286023
|
}
|
|
285975
286024
|
async function loadSessionBudgetMap(baseDir) {
|
|
285976
286025
|
await ensureDir(baseDir);
|
|
285977
|
-
const path6 =
|
|
286026
|
+
const path6 = join41(baseDir, SESSION_MAP_FILE);
|
|
285978
286027
|
const data = await readJsonFile(path6);
|
|
285979
286028
|
return data || {};
|
|
285980
286029
|
}
|
|
285981
286030
|
async function saveSessionBudgetMap(baseDir, map2) {
|
|
285982
286031
|
await ensureDir(baseDir);
|
|
285983
|
-
const path6 =
|
|
286032
|
+
const path6 = join41(baseDir, SESSION_MAP_FILE);
|
|
285984
286033
|
await writeJsonFile(path6, map2);
|
|
285985
286034
|
}
|
|
285986
286035
|
|
|
@@ -287491,12 +287540,12 @@ function App2({ cwd: cwd3, version: version5 }) {
|
|
|
287491
287540
|
try {
|
|
287492
287541
|
const config2 = await loadConfig(cwd3, workspaceBaseDir);
|
|
287493
287542
|
setCurrentConfig(config2);
|
|
287494
|
-
const { readFile:
|
|
287543
|
+
const { readFile: readFile10, access } = await import("fs/promises");
|
|
287495
287544
|
const configBaseDir = workspaceBaseDir || getConfigDir();
|
|
287496
287545
|
const userPath = `${configBaseDir}/config.json`;
|
|
287497
287546
|
try {
|
|
287498
287547
|
await access(userPath);
|
|
287499
|
-
const content = await
|
|
287548
|
+
const content = await readFile10(userPath, "utf-8");
|
|
287500
287549
|
setUserConfig(JSON.parse(content));
|
|
287501
287550
|
} catch {
|
|
287502
287551
|
setUserConfig(null);
|
|
@@ -287504,7 +287553,7 @@ function App2({ cwd: cwd3, version: version5 }) {
|
|
|
287504
287553
|
const projectPath = `${getProjectConfigDir(cwd3)}/config.json`;
|
|
287505
287554
|
try {
|
|
287506
287555
|
await access(projectPath);
|
|
287507
|
-
const content = await
|
|
287556
|
+
const content = await readFile10(projectPath, "utf-8");
|
|
287508
287557
|
setProjectConfig(JSON.parse(content));
|
|
287509
287558
|
} catch {
|
|
287510
287559
|
setProjectConfig(null);
|
|
@@ -287512,7 +287561,7 @@ function App2({ cwd: cwd3, version: version5 }) {
|
|
|
287512
287561
|
const localPath = `${getProjectConfigDir(cwd3)}/config.local.json`;
|
|
287513
287562
|
try {
|
|
287514
287563
|
await access(localPath);
|
|
287515
|
-
const content = await
|
|
287564
|
+
const content = await readFile10(localPath, "utf-8");
|
|
287516
287565
|
setLocalConfig(JSON.parse(content));
|
|
287517
287566
|
} catch {
|
|
287518
287567
|
setLocalConfig(null);
|
|
@@ -287599,46 +287648,46 @@ function App2({ cwd: cwd3, version: version5 }) {
|
|
|
287599
287648
|
});
|
|
287600
287649
|
}, [recoverableSessions, createSessionFromRecovery, workspaceBaseDir]);
|
|
287601
287650
|
const handleOnboardingComplete = import_react84.useCallback(async (result) => {
|
|
287602
|
-
const { existsSync:
|
|
287603
|
-
const secretsPath =
|
|
287651
|
+
const { existsSync: existsSync27, mkdirSync: mkdirSync17, readFileSync: readFileSync16, writeFileSync: writeFileSync12, appendFileSync: appendFileSync5 } = await import("fs");
|
|
287652
|
+
const secretsPath = join43(homedir20(), ".secrets");
|
|
287604
287653
|
const providerInfo = getProviderInfo(result.provider);
|
|
287605
287654
|
const envName = providerInfo?.apiKeyEnv || "ANTHROPIC_API_KEY";
|
|
287606
287655
|
const keyExport = `export ${envName}="${result.apiKey}"`;
|
|
287607
|
-
if (
|
|
287608
|
-
const content =
|
|
287656
|
+
if (existsSync27(secretsPath)) {
|
|
287657
|
+
const content = readFileSync16(secretsPath, "utf-8");
|
|
287609
287658
|
if (content.includes(envName)) {
|
|
287610
287659
|
const updated = content.replace(new RegExp(`^export ${envName}=.*$`, "m"), keyExport);
|
|
287611
|
-
|
|
287660
|
+
writeFileSync12(secretsPath, updated, "utf-8");
|
|
287612
287661
|
} else {
|
|
287613
287662
|
appendFileSync5(secretsPath, `
|
|
287614
287663
|
` + keyExport + `
|
|
287615
287664
|
`, "utf-8");
|
|
287616
287665
|
}
|
|
287617
287666
|
} else {
|
|
287618
|
-
|
|
287667
|
+
writeFileSync12(secretsPath, keyExport + `
|
|
287619
287668
|
`, { mode: 384 });
|
|
287620
287669
|
}
|
|
287621
287670
|
for (const [name2, key] of Object.entries(result.connectorKeys)) {
|
|
287622
287671
|
const envName2 = `${name2.toUpperCase()}_API_KEY`;
|
|
287623
287672
|
const connKeyExport = `export ${envName2}="${key}"`;
|
|
287624
|
-
const content =
|
|
287673
|
+
const content = readFileSync16(secretsPath, "utf-8");
|
|
287625
287674
|
if (content.includes(envName2)) {
|
|
287626
287675
|
const updated = content.replace(new RegExp(`^export ${envName2}=.*$`, "m"), connKeyExport);
|
|
287627
|
-
|
|
287676
|
+
writeFileSync12(secretsPath, updated, "utf-8");
|
|
287628
287677
|
} else {
|
|
287629
287678
|
appendFileSync5(secretsPath, connKeyExport + `
|
|
287630
287679
|
`, "utf-8");
|
|
287631
287680
|
}
|
|
287632
287681
|
}
|
|
287633
287682
|
const configDir = workspaceBaseDir || getConfigDir();
|
|
287634
|
-
if (!
|
|
287635
|
-
|
|
287683
|
+
if (!existsSync27(configDir)) {
|
|
287684
|
+
mkdirSync17(configDir, { recursive: true });
|
|
287636
287685
|
}
|
|
287637
|
-
const configPath =
|
|
287686
|
+
const configPath = join43(configDir, "config.json");
|
|
287638
287687
|
let existingConfig = {};
|
|
287639
|
-
if (
|
|
287688
|
+
if (existsSync27(configPath)) {
|
|
287640
287689
|
try {
|
|
287641
|
-
existingConfig = JSON.parse(
|
|
287690
|
+
existingConfig = JSON.parse(readFileSync16(configPath, "utf-8"));
|
|
287642
287691
|
} catch {}
|
|
287643
287692
|
}
|
|
287644
287693
|
const newConfig = {
|
|
@@ -287651,7 +287700,7 @@ function App2({ cwd: cwd3, version: version5 }) {
|
|
|
287651
287700
|
},
|
|
287652
287701
|
connectors: result.connectors.length > 0 ? result.connectors : undefined
|
|
287653
287702
|
};
|
|
287654
|
-
|
|
287703
|
+
writeFileSync12(configPath, JSON.stringify(newConfig, null, 2), "utf-8");
|
|
287655
287704
|
await loadConfigFiles();
|
|
287656
287705
|
process.env[envName] = result.apiKey;
|
|
287657
287706
|
setShowOnboardingPanel(false);
|
|
@@ -287680,14 +287729,14 @@ function App2({ cwd: cwd3, version: version5 }) {
|
|
|
287680
287729
|
return;
|
|
287681
287730
|
}
|
|
287682
287731
|
try {
|
|
287683
|
-
const configPath =
|
|
287684
|
-
const { existsSync:
|
|
287732
|
+
const configPath = join43(workspaceBaseDir || getConfigDir(), "config.json");
|
|
287733
|
+
const { existsSync: existsSync27, readFileSync: readFileSync16 } = await import("fs");
|
|
287685
287734
|
let needsOnboarding = false;
|
|
287686
|
-
if (!
|
|
287735
|
+
if (!existsSync27(configPath)) {
|
|
287687
287736
|
needsOnboarding = true;
|
|
287688
287737
|
} else {
|
|
287689
287738
|
try {
|
|
287690
|
-
const raw =
|
|
287739
|
+
const raw = readFileSync16(configPath, "utf-8");
|
|
287691
287740
|
const parsed = JSON.parse(raw);
|
|
287692
287741
|
if (!parsed.onboardingCompleted) {
|
|
287693
287742
|
needsOnboarding = true;
|
|
@@ -289849,8 +289898,8 @@ When done, report the result.`);
|
|
|
289849
289898
|
}
|
|
289850
289899
|
if (showConfigPanel && currentConfig) {
|
|
289851
289900
|
const handleConfigSave = async (location, updates) => {
|
|
289852
|
-
const { writeFile:
|
|
289853
|
-
const { dirname:
|
|
289901
|
+
const { writeFile: writeFile9, mkdir: mkdir10 } = await import("fs/promises");
|
|
289902
|
+
const { dirname: dirname18 } = await import("path");
|
|
289854
289903
|
let configPath;
|
|
289855
289904
|
let existingConfig;
|
|
289856
289905
|
switch (location) {
|
|
@@ -289868,8 +289917,8 @@ When done, report the result.`);
|
|
|
289868
289917
|
break;
|
|
289869
289918
|
}
|
|
289870
289919
|
const newConfig = deepMerge(existingConfig || {}, updates);
|
|
289871
|
-
await
|
|
289872
|
-
await
|
|
289920
|
+
await mkdir10(dirname18(configPath), { recursive: true });
|
|
289921
|
+
await writeFile9(configPath, JSON.stringify(newConfig, null, 2));
|
|
289873
289922
|
await loadConfigFiles();
|
|
289874
289923
|
};
|
|
289875
289924
|
return /* @__PURE__ */ jsx_dev_runtime51.jsxDEV(Box_default, {
|
|
@@ -290800,7 +290849,7 @@ Interactive Mode:
|
|
|
290800
290849
|
// packages/terminal/src/index.tsx
|
|
290801
290850
|
var jsx_dev_runtime52 = __toESM(require_jsx_dev_runtime(), 1);
|
|
290802
290851
|
setRuntime(bunRuntime);
|
|
290803
|
-
var VERSION4 = "1.1.
|
|
290852
|
+
var VERSION4 = "1.1.53";
|
|
290804
290853
|
var SYNC_START = "\x1B[?2026h";
|
|
290805
290854
|
var SYNC_END = "\x1B[?2026l";
|
|
290806
290855
|
function enableSynchronizedOutput() {
|
|
@@ -290919,4 +290968,4 @@ export {
|
|
|
290919
290968
|
main
|
|
290920
290969
|
};
|
|
290921
290970
|
|
|
290922
|
-
//# debugId=
|
|
290971
|
+
//# debugId=2C44C31995AA98B064756E2164756E21
|