@askexenow/exe-os 0.9.7 → 0.9.8
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/bin/backfill-conversations.js +754 -79
- package/dist/bin/backfill-responses.js +752 -77
- package/dist/bin/backfill-vectors.js +752 -77
- package/dist/bin/cleanup-stale-review-tasks.js +657 -35
- package/dist/bin/cli.js +1388 -605
- package/dist/bin/exe-agent-config.js +123 -95
- package/dist/bin/exe-agent.js +41 -25
- package/dist/bin/exe-assign.js +732 -57
- package/dist/bin/exe-boot.js +784 -153
- package/dist/bin/exe-call.js +209 -138
- package/dist/bin/exe-cloud.js +35 -12
- package/dist/bin/exe-dispatch.js +692 -70
- package/dist/bin/exe-doctor.js +648 -26
- package/dist/bin/exe-export-behaviors.js +650 -20
- package/dist/bin/exe-forget.js +635 -13
- package/dist/bin/exe-gateway.js +1053 -271
- package/dist/bin/exe-heartbeat.js +665 -43
- package/dist/bin/exe-kill.js +646 -16
- package/dist/bin/exe-launch-agent.js +887 -97
- package/dist/bin/exe-link.js +658 -43
- package/dist/bin/exe-new-employee.js +378 -177
- package/dist/bin/exe-pending-messages.js +656 -34
- package/dist/bin/exe-pending-notifications.js +635 -13
- package/dist/bin/exe-pending-reviews.js +659 -37
- package/dist/bin/exe-rename.js +645 -30
- package/dist/bin/exe-review.js +635 -13
- package/dist/bin/exe-search.js +771 -88
- package/dist/bin/exe-session-cleanup.js +834 -150
- package/dist/bin/exe-settings.js +127 -91
- package/dist/bin/exe-start-codex.js +729 -94
- package/dist/bin/exe-start-opencode.js +717 -82
- package/dist/bin/exe-status.js +657 -35
- package/dist/bin/exe-team.js +635 -13
- package/dist/bin/git-sweep.js +720 -89
- package/dist/bin/graph-backfill.js +643 -13
- package/dist/bin/graph-export.js +646 -16
- package/dist/bin/install.js +596 -193
- package/dist/bin/scan-tasks.js +724 -93
- package/dist/bin/setup.js +1038 -210
- package/dist/bin/shard-migrate.js +645 -15
- package/dist/bin/wiki-sync.js +646 -16
- package/dist/gateway/index.js +1027 -245
- package/dist/hooks/bug-report-worker.js +891 -170
- package/dist/hooks/commit-complete.js +718 -87
- package/dist/hooks/error-recall.js +776 -93
- package/dist/hooks/exe-heartbeat-hook.js +85 -71
- package/dist/hooks/ingest-worker.js +840 -156
- package/dist/hooks/ingest.js +90 -73
- package/dist/hooks/instructions-loaded.js +669 -38
- package/dist/hooks/notification.js +661 -30
- package/dist/hooks/post-compact.js +674 -43
- package/dist/hooks/pre-compact.js +718 -87
- package/dist/hooks/pre-tool-use.js +872 -125
- package/dist/hooks/prompt-ingest-worker.js +758 -83
- package/dist/hooks/prompt-submit.js +1060 -319
- package/dist/hooks/response-ingest-worker.js +758 -83
- package/dist/hooks/session-end.js +721 -90
- package/dist/hooks/session-start.js +1031 -207
- package/dist/hooks/stop.js +680 -49
- package/dist/hooks/subagent-stop.js +674 -43
- package/dist/hooks/summary-worker.js +816 -132
- package/dist/index.js +1015 -232
- package/dist/lib/cloud-sync.js +663 -48
- package/dist/lib/consolidation.js +26 -3
- package/dist/lib/database.js +626 -18
- package/dist/lib/db.js +2261 -0
- package/dist/lib/device-registry.js +640 -25
- package/dist/lib/embedder.js +96 -43
- package/dist/lib/employee-templates.js +16 -0
- package/dist/lib/employees.js +259 -83
- package/dist/lib/exe-daemon-client.js +101 -63
- package/dist/lib/exe-daemon.js +894 -162
- package/dist/lib/hybrid-search.js +771 -88
- package/dist/lib/identity.js +27 -7
- package/dist/lib/messaging.js +55 -28
- package/dist/lib/reminders.js +21 -1
- package/dist/lib/schedules.js +636 -14
- package/dist/lib/skill-learning.js +21 -1
- package/dist/lib/store.js +643 -13
- package/dist/lib/task-router.js +82 -71
- package/dist/lib/tasks.js +98 -71
- package/dist/lib/tmux-routing.js +87 -60
- package/dist/lib/token-spend.js +26 -6
- package/dist/mcp/server.js +1784 -458
- package/dist/mcp/tools/complete-reminder.js +21 -1
- package/dist/mcp/tools/create-reminder.js +21 -1
- package/dist/mcp/tools/create-task.js +290 -164
- package/dist/mcp/tools/deactivate-behavior.js +24 -4
- package/dist/mcp/tools/list-reminders.js +21 -1
- package/dist/mcp/tools/list-tasks.js +195 -38
- package/dist/mcp/tools/send-message.js +58 -31
- package/dist/mcp/tools/update-task.js +75 -48
- package/dist/runtime/index.js +720 -89
- package/dist/tui/App.js +853 -123
- package/package.json +3 -2
|
@@ -306,7 +306,7 @@ function loadEmployeesSync(employeesPath = EMPLOYEES_PATH) {
|
|
|
306
306
|
function getEmployee(employees, name) {
|
|
307
307
|
return employees.find((e) => e.name.toLowerCase() === name.toLowerCase());
|
|
308
308
|
}
|
|
309
|
-
var EMPLOYEES_PATH, DEFAULT_COORDINATOR_TEMPLATE_NAME, COORDINATOR_ROLE;
|
|
309
|
+
var EMPLOYEES_PATH, DEFAULT_COORDINATOR_TEMPLATE_NAME, COORDINATOR_ROLE, IDENTITY_DIR;
|
|
310
310
|
var init_employees = __esm({
|
|
311
311
|
"src/lib/employees.ts"() {
|
|
312
312
|
"use strict";
|
|
@@ -314,6 +314,7 @@ var init_employees = __esm({
|
|
|
314
314
|
EMPLOYEES_PATH = path2.join(EXE_AI_DIR, "exe-employees.json");
|
|
315
315
|
DEFAULT_COORDINATOR_TEMPLATE_NAME = "exe";
|
|
316
316
|
COORDINATOR_ROLE = "COO";
|
|
317
|
+
IDENTITY_DIR = path2.join(EXE_AI_DIR, "identity");
|
|
317
318
|
}
|
|
318
319
|
});
|
|
319
320
|
|
|
@@ -577,13 +578,597 @@ var init_db_retry = __esm({
|
|
|
577
578
|
}
|
|
578
579
|
});
|
|
579
580
|
|
|
581
|
+
// src/lib/database-adapter.ts
|
|
582
|
+
import os5 from "os";
|
|
583
|
+
import path7 from "path";
|
|
584
|
+
import { createRequire } from "module";
|
|
585
|
+
import { pathToFileURL } from "url";
|
|
586
|
+
function quotedIdentifier(identifier) {
|
|
587
|
+
return `"${identifier.replace(/"/g, '""')}"`;
|
|
588
|
+
}
|
|
589
|
+
function unqualifiedTableName(name) {
|
|
590
|
+
const raw = name.trim().replace(/^"|"$/g, "");
|
|
591
|
+
const parts = raw.split(".");
|
|
592
|
+
return parts[parts.length - 1].replace(/^"|"$/g, "").toLowerCase();
|
|
593
|
+
}
|
|
594
|
+
function stripTrailingSemicolon(sql) {
|
|
595
|
+
return sql.trim().replace(/;+\s*$/u, "");
|
|
596
|
+
}
|
|
597
|
+
function appendClause(sql, clause) {
|
|
598
|
+
const trimmed = stripTrailingSemicolon(sql);
|
|
599
|
+
const returningMatch = /\sRETURNING\b[\s\S]*$/iu.exec(trimmed);
|
|
600
|
+
if (!returningMatch) {
|
|
601
|
+
return `${trimmed}${clause}`;
|
|
602
|
+
}
|
|
603
|
+
const idx = returningMatch.index;
|
|
604
|
+
return `${trimmed.slice(0, idx)}${clause}${trimmed.slice(idx)}`;
|
|
605
|
+
}
|
|
606
|
+
function normalizeStatement(stmt) {
|
|
607
|
+
if (typeof stmt === "string") {
|
|
608
|
+
return { kind: "positional", sql: stmt, args: [] };
|
|
609
|
+
}
|
|
610
|
+
const sql = stmt.sql;
|
|
611
|
+
if (Array.isArray(stmt.args) || stmt.args === void 0) {
|
|
612
|
+
return { kind: "positional", sql, args: stmt.args ?? [] };
|
|
613
|
+
}
|
|
614
|
+
return { kind: "named", sql, args: stmt.args };
|
|
615
|
+
}
|
|
616
|
+
function rewriteBooleanLiterals(sql) {
|
|
617
|
+
let out = sql;
|
|
618
|
+
for (const column of BOOLEAN_COLUMN_NAMES) {
|
|
619
|
+
const scoped = `((?:\\b[a-z_][a-z0-9_]*\\.)?${column})`;
|
|
620
|
+
out = out.replace(new RegExp(`${scoped}\\s*=\\s*0\\b`, "giu"), "$1 = FALSE");
|
|
621
|
+
out = out.replace(new RegExp(`${scoped}\\s*=\\s*1\\b`, "giu"), "$1 = TRUE");
|
|
622
|
+
out = out.replace(new RegExp(`${scoped}\\s*!=\\s*0\\b`, "giu"), "$1 != FALSE");
|
|
623
|
+
out = out.replace(new RegExp(`${scoped}\\s*!=\\s*1\\b`, "giu"), "$1 != TRUE");
|
|
624
|
+
out = out.replace(new RegExp(`${scoped}\\s*<>\\s*0\\b`, "giu"), "$1 <> FALSE");
|
|
625
|
+
out = out.replace(new RegExp(`${scoped}\\s*<>\\s*1\\b`, "giu"), "$1 <> TRUE");
|
|
626
|
+
}
|
|
627
|
+
return out;
|
|
628
|
+
}
|
|
629
|
+
function rewriteInsertOrIgnore(sql) {
|
|
630
|
+
if (!/^\s*INSERT\s+OR\s+IGNORE\s+INTO\b/iu.test(sql)) {
|
|
631
|
+
return sql;
|
|
632
|
+
}
|
|
633
|
+
const replaced = sql.replace(/^\s*INSERT\s+OR\s+IGNORE\s+INTO\b/iu, "INSERT INTO");
|
|
634
|
+
return /\bON\s+CONFLICT\b/iu.test(replaced) ? replaced : appendClause(replaced, " ON CONFLICT DO NOTHING");
|
|
635
|
+
}
|
|
636
|
+
function rewriteInsertOrReplace(sql) {
|
|
637
|
+
const match = /^\s*INSERT\s+OR\s+REPLACE\s+INTO\s+([A-Za-z0-9_."]+)\s*\(([^)]+)\)([\s\S]*)$/iu.exec(sql);
|
|
638
|
+
if (!match) {
|
|
639
|
+
return sql;
|
|
640
|
+
}
|
|
641
|
+
const rawTable = match[1];
|
|
642
|
+
const rawColumns = match[2];
|
|
643
|
+
const remainder = match[3];
|
|
644
|
+
const tableName = unqualifiedTableName(rawTable);
|
|
645
|
+
const conflictKeys = UPSERT_KEYS[tableName];
|
|
646
|
+
if (!conflictKeys?.length) {
|
|
647
|
+
return sql;
|
|
648
|
+
}
|
|
649
|
+
const columns = rawColumns.split(",").map((col) => col.trim().replace(/^"|"$/g, ""));
|
|
650
|
+
const updateColumns = columns.filter((col) => !conflictKeys.includes(col));
|
|
651
|
+
const conflictTarget = conflictKeys.map(quotedIdentifier).join(", ");
|
|
652
|
+
const updateClause = updateColumns.length === 0 ? " DO NOTHING" : ` DO UPDATE SET ${updateColumns.map((col) => `${quotedIdentifier(col)} = EXCLUDED.${quotedIdentifier(col)}`).join(", ")}`;
|
|
653
|
+
return `INSERT INTO ${rawTable} (${rawColumns})${appendClause(remainder, ` ON CONFLICT (${conflictTarget})${updateClause}`)}`;
|
|
654
|
+
}
|
|
655
|
+
function rewriteSql(sql) {
|
|
656
|
+
let out = sql;
|
|
657
|
+
out = out.replace(/\bdatetime\(\s*['"]now['"]\s*\)/giu, "CURRENT_TIMESTAMP");
|
|
658
|
+
out = out.replace(/\bvector32\s*\(\s*\?\s*\)/giu, "?");
|
|
659
|
+
out = rewriteBooleanLiterals(out);
|
|
660
|
+
out = rewriteInsertOrReplace(out);
|
|
661
|
+
out = rewriteInsertOrIgnore(out);
|
|
662
|
+
return stripTrailingSemicolon(out);
|
|
663
|
+
}
|
|
664
|
+
function toBoolean(value) {
|
|
665
|
+
if (value === null || value === void 0) return value;
|
|
666
|
+
if (typeof value === "boolean") return value;
|
|
667
|
+
if (typeof value === "number") return value !== 0;
|
|
668
|
+
if (typeof value === "bigint") return value !== 0n;
|
|
669
|
+
if (typeof value === "string") {
|
|
670
|
+
const normalized = value.trim().toLowerCase();
|
|
671
|
+
if (normalized === "0" || normalized === "false") return false;
|
|
672
|
+
if (normalized === "1" || normalized === "true") return true;
|
|
673
|
+
}
|
|
674
|
+
return Boolean(value);
|
|
675
|
+
}
|
|
676
|
+
function countQuestionMarks(sql, end) {
|
|
677
|
+
let count = 0;
|
|
678
|
+
let inSingle = false;
|
|
679
|
+
let inDouble = false;
|
|
680
|
+
let inLineComment = false;
|
|
681
|
+
let inBlockComment = false;
|
|
682
|
+
for (let i = 0; i < end; i++) {
|
|
683
|
+
const ch = sql[i];
|
|
684
|
+
const next = sql[i + 1];
|
|
685
|
+
if (inLineComment) {
|
|
686
|
+
if (ch === "\n") inLineComment = false;
|
|
687
|
+
continue;
|
|
688
|
+
}
|
|
689
|
+
if (inBlockComment) {
|
|
690
|
+
if (ch === "*" && next === "/") {
|
|
691
|
+
inBlockComment = false;
|
|
692
|
+
i += 1;
|
|
693
|
+
}
|
|
694
|
+
continue;
|
|
695
|
+
}
|
|
696
|
+
if (!inSingle && !inDouble && ch === "-" && next === "-") {
|
|
697
|
+
inLineComment = true;
|
|
698
|
+
i += 1;
|
|
699
|
+
continue;
|
|
700
|
+
}
|
|
701
|
+
if (!inSingle && !inDouble && ch === "/" && next === "*") {
|
|
702
|
+
inBlockComment = true;
|
|
703
|
+
i += 1;
|
|
704
|
+
continue;
|
|
705
|
+
}
|
|
706
|
+
if (!inDouble && ch === "'" && sql[i - 1] !== "\\") {
|
|
707
|
+
inSingle = !inSingle;
|
|
708
|
+
continue;
|
|
709
|
+
}
|
|
710
|
+
if (!inSingle && ch === '"' && sql[i - 1] !== "\\") {
|
|
711
|
+
inDouble = !inDouble;
|
|
712
|
+
continue;
|
|
713
|
+
}
|
|
714
|
+
if (!inSingle && !inDouble && ch === "?") {
|
|
715
|
+
count += 1;
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
return count;
|
|
719
|
+
}
|
|
720
|
+
function findBooleanPlaceholderIndexes(sql) {
|
|
721
|
+
const indexes = /* @__PURE__ */ new Set();
|
|
722
|
+
for (const column of BOOLEAN_COLUMN_NAMES) {
|
|
723
|
+
const pattern = new RegExp(`(?:\\b[a-z_][a-z0-9_]*\\.)?${column}\\s*=\\s*\\?`, "giu");
|
|
724
|
+
for (const match of sql.matchAll(pattern)) {
|
|
725
|
+
const matchText = match[0];
|
|
726
|
+
const qIndex = match.index + matchText.lastIndexOf("?");
|
|
727
|
+
indexes.add(countQuestionMarks(sql, qIndex + 1));
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
return indexes;
|
|
731
|
+
}
|
|
732
|
+
function coerceInsertBooleanArgs(sql, args) {
|
|
733
|
+
const match = /^\s*INSERT(?:\s+OR\s+(?:IGNORE|REPLACE))?\s+INTO\s+([A-Za-z0-9_."]+)\s*\(([^)]+)\)/iu.exec(sql);
|
|
734
|
+
if (!match) return;
|
|
735
|
+
const rawTable = match[1];
|
|
736
|
+
const rawColumns = match[2];
|
|
737
|
+
const boolColumns = BOOLEAN_COLUMNS_BY_TABLE[unqualifiedTableName(rawTable)];
|
|
738
|
+
if (!boolColumns?.size) return;
|
|
739
|
+
const columns = rawColumns.split(",").map((col) => col.trim().replace(/^"|"$/g, ""));
|
|
740
|
+
for (const [index, column] of columns.entries()) {
|
|
741
|
+
if (boolColumns.has(column) && index < args.length) {
|
|
742
|
+
args[index] = toBoolean(args[index]);
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
function coerceUpdateBooleanArgs(sql, args) {
|
|
747
|
+
const match = /^\s*UPDATE\s+([A-Za-z0-9_."]+)\s+SET\s+([\s\S]+?)(?:\s+WHERE\b|$)/iu.exec(sql);
|
|
748
|
+
if (!match) return;
|
|
749
|
+
const rawTable = match[1];
|
|
750
|
+
const setClause = match[2];
|
|
751
|
+
const boolColumns = BOOLEAN_COLUMNS_BY_TABLE[unqualifiedTableName(rawTable)];
|
|
752
|
+
if (!boolColumns?.size) return;
|
|
753
|
+
const assignments = setClause.split(",");
|
|
754
|
+
let placeholderIndex = 0;
|
|
755
|
+
for (const assignment of assignments) {
|
|
756
|
+
if (!assignment.includes("?")) continue;
|
|
757
|
+
placeholderIndex += 1;
|
|
758
|
+
const colMatch = /^\s*(?:[A-Za-z_][A-Za-z0-9_]*\.)?([A-Za-z_][A-Za-z0-9_]*)\s*=\s*\?/iu.exec(assignment);
|
|
759
|
+
if (colMatch && boolColumns.has(colMatch[1])) {
|
|
760
|
+
args[placeholderIndex - 1] = toBoolean(args[placeholderIndex - 1]);
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
function coerceBooleanArgs(sql, args) {
|
|
765
|
+
const nextArgs = [...args];
|
|
766
|
+
coerceInsertBooleanArgs(sql, nextArgs);
|
|
767
|
+
coerceUpdateBooleanArgs(sql, nextArgs);
|
|
768
|
+
const placeholderIndexes = findBooleanPlaceholderIndexes(sql);
|
|
769
|
+
for (const index of placeholderIndexes) {
|
|
770
|
+
if (index > 0 && index <= nextArgs.length) {
|
|
771
|
+
nextArgs[index - 1] = toBoolean(nextArgs[index - 1]);
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
return nextArgs;
|
|
775
|
+
}
|
|
776
|
+
function convertQuestionMarksToDollarParams(sql) {
|
|
777
|
+
let out = "";
|
|
778
|
+
let placeholder = 0;
|
|
779
|
+
let inSingle = false;
|
|
780
|
+
let inDouble = false;
|
|
781
|
+
let inLineComment = false;
|
|
782
|
+
let inBlockComment = false;
|
|
783
|
+
for (let i = 0; i < sql.length; i++) {
|
|
784
|
+
const ch = sql[i];
|
|
785
|
+
const next = sql[i + 1];
|
|
786
|
+
if (inLineComment) {
|
|
787
|
+
out += ch;
|
|
788
|
+
if (ch === "\n") inLineComment = false;
|
|
789
|
+
continue;
|
|
790
|
+
}
|
|
791
|
+
if (inBlockComment) {
|
|
792
|
+
out += ch;
|
|
793
|
+
if (ch === "*" && next === "/") {
|
|
794
|
+
out += next;
|
|
795
|
+
inBlockComment = false;
|
|
796
|
+
i += 1;
|
|
797
|
+
}
|
|
798
|
+
continue;
|
|
799
|
+
}
|
|
800
|
+
if (!inSingle && !inDouble && ch === "-" && next === "-") {
|
|
801
|
+
out += ch + next;
|
|
802
|
+
inLineComment = true;
|
|
803
|
+
i += 1;
|
|
804
|
+
continue;
|
|
805
|
+
}
|
|
806
|
+
if (!inSingle && !inDouble && ch === "/" && next === "*") {
|
|
807
|
+
out += ch + next;
|
|
808
|
+
inBlockComment = true;
|
|
809
|
+
i += 1;
|
|
810
|
+
continue;
|
|
811
|
+
}
|
|
812
|
+
if (!inDouble && ch === "'" && sql[i - 1] !== "\\") {
|
|
813
|
+
inSingle = !inSingle;
|
|
814
|
+
out += ch;
|
|
815
|
+
continue;
|
|
816
|
+
}
|
|
817
|
+
if (!inSingle && ch === '"' && sql[i - 1] !== "\\") {
|
|
818
|
+
inDouble = !inDouble;
|
|
819
|
+
out += ch;
|
|
820
|
+
continue;
|
|
821
|
+
}
|
|
822
|
+
if (!inSingle && !inDouble && ch === "?") {
|
|
823
|
+
placeholder += 1;
|
|
824
|
+
out += `$${placeholder}`;
|
|
825
|
+
continue;
|
|
826
|
+
}
|
|
827
|
+
out += ch;
|
|
828
|
+
}
|
|
829
|
+
return out;
|
|
830
|
+
}
|
|
831
|
+
function translateStatementForPostgres(stmt) {
|
|
832
|
+
const normalized = normalizeStatement(stmt);
|
|
833
|
+
if (normalized.kind === "named") {
|
|
834
|
+
throw new Error("Named SQL parameters are not supported by the Prisma adapter.");
|
|
835
|
+
}
|
|
836
|
+
const rewrittenSql = rewriteSql(normalized.sql);
|
|
837
|
+
const coercedArgs = coerceBooleanArgs(rewrittenSql, normalized.args);
|
|
838
|
+
return {
|
|
839
|
+
sql: convertQuestionMarksToDollarParams(rewrittenSql),
|
|
840
|
+
args: coercedArgs
|
|
841
|
+
};
|
|
842
|
+
}
|
|
843
|
+
function shouldBypassPostgres(stmt) {
|
|
844
|
+
const normalized = normalizeStatement(stmt);
|
|
845
|
+
if (normalized.kind === "named") {
|
|
846
|
+
return true;
|
|
847
|
+
}
|
|
848
|
+
return IMMEDIATE_FALLBACK_PATTERNS.some((pattern) => pattern.test(normalized.sql));
|
|
849
|
+
}
|
|
850
|
+
function shouldFallbackOnError(error) {
|
|
851
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
852
|
+
return /42P01|42883|42601|does not exist|syntax error|not supported|Named SQL parameters are not supported/iu.test(message);
|
|
853
|
+
}
|
|
854
|
+
function isReadQuery(sql) {
|
|
855
|
+
const trimmed = sql.trimStart();
|
|
856
|
+
return /^(SELECT|WITH|SHOW|EXPLAIN|VALUES)\b/iu.test(trimmed) || /\bRETURNING\b/iu.test(trimmed);
|
|
857
|
+
}
|
|
858
|
+
function buildRow(row, columns) {
|
|
859
|
+
const values = columns.map((column) => row[column]);
|
|
860
|
+
return Object.assign(values, row);
|
|
861
|
+
}
|
|
862
|
+
function buildResultSet(rows, rowsAffected = 0) {
|
|
863
|
+
const columns = rows[0] ? Object.keys(rows[0]) : [];
|
|
864
|
+
const resultRows = rows.map((row) => buildRow(row, columns));
|
|
865
|
+
return {
|
|
866
|
+
columns,
|
|
867
|
+
columnTypes: columns.map(() => ""),
|
|
868
|
+
rows: resultRows,
|
|
869
|
+
rowsAffected,
|
|
870
|
+
lastInsertRowid: void 0,
|
|
871
|
+
toJSON() {
|
|
872
|
+
return {
|
|
873
|
+
columns,
|
|
874
|
+
columnTypes: columns.map(() => ""),
|
|
875
|
+
rows,
|
|
876
|
+
rowsAffected,
|
|
877
|
+
lastInsertRowid: void 0
|
|
878
|
+
};
|
|
879
|
+
}
|
|
880
|
+
};
|
|
881
|
+
}
|
|
882
|
+
async function loadPrismaClient() {
|
|
883
|
+
if (!prismaClientPromise) {
|
|
884
|
+
prismaClientPromise = (async () => {
|
|
885
|
+
const explicitPath = process.env.EXE_OS_PRISMA_CLIENT_PATH;
|
|
886
|
+
if (explicitPath) {
|
|
887
|
+
const module2 = await import(pathToFileURL(explicitPath).href);
|
|
888
|
+
const PrismaClient2 = module2.PrismaClient ?? module2.default?.PrismaClient;
|
|
889
|
+
if (!PrismaClient2) {
|
|
890
|
+
throw new Error(`No PrismaClient export found at ${explicitPath}`);
|
|
891
|
+
}
|
|
892
|
+
return new PrismaClient2();
|
|
893
|
+
}
|
|
894
|
+
const exeDbRoot = process.env.EXE_DB_ROOT ?? path7.join(os5.homedir(), "exe-db");
|
|
895
|
+
const requireFromExeDb = createRequire(path7.join(exeDbRoot, "package.json"));
|
|
896
|
+
const prismaEntry = requireFromExeDb.resolve("@prisma/client");
|
|
897
|
+
const module = await import(pathToFileURL(prismaEntry).href);
|
|
898
|
+
const PrismaClient = module.PrismaClient ?? module.default?.PrismaClient;
|
|
899
|
+
if (!PrismaClient) {
|
|
900
|
+
throw new Error(`No PrismaClient export found in ${prismaEntry}`);
|
|
901
|
+
}
|
|
902
|
+
return new PrismaClient();
|
|
903
|
+
})();
|
|
904
|
+
}
|
|
905
|
+
return prismaClientPromise;
|
|
906
|
+
}
|
|
907
|
+
async function ensureCompatibilityViews(prisma) {
|
|
908
|
+
if (!compatibilityBootstrapPromise) {
|
|
909
|
+
compatibilityBootstrapPromise = (async () => {
|
|
910
|
+
for (const mapping of VIEW_MAPPINGS) {
|
|
911
|
+
const relation = mapping.source.replace(/"/g, "");
|
|
912
|
+
const rows = await prisma.$queryRawUnsafe(
|
|
913
|
+
"SELECT to_regclass($1) AS regclass",
|
|
914
|
+
relation
|
|
915
|
+
);
|
|
916
|
+
if (!rows[0]?.regclass) {
|
|
917
|
+
continue;
|
|
918
|
+
}
|
|
919
|
+
await prisma.$executeRawUnsafe(
|
|
920
|
+
`CREATE OR REPLACE VIEW public.${quotedIdentifier(mapping.view)} AS SELECT * FROM ${mapping.source}`
|
|
921
|
+
);
|
|
922
|
+
}
|
|
923
|
+
})();
|
|
924
|
+
}
|
|
925
|
+
return compatibilityBootstrapPromise;
|
|
926
|
+
}
|
|
927
|
+
async function executeOnPrisma(executor, stmt) {
|
|
928
|
+
const translated = translateStatementForPostgres(stmt);
|
|
929
|
+
if (isReadQuery(translated.sql)) {
|
|
930
|
+
const rows = await executor.$queryRawUnsafe(
|
|
931
|
+
translated.sql,
|
|
932
|
+
...translated.args
|
|
933
|
+
);
|
|
934
|
+
return buildResultSet(rows, /\bRETURNING\b/iu.test(translated.sql) ? rows.length : 0);
|
|
935
|
+
}
|
|
936
|
+
const rowsAffected = await executor.$executeRawUnsafe(translated.sql, ...translated.args);
|
|
937
|
+
return buildResultSet([], rowsAffected);
|
|
938
|
+
}
|
|
939
|
+
function splitSqlStatements(sql) {
|
|
940
|
+
const parts = [];
|
|
941
|
+
let current = "";
|
|
942
|
+
let inSingle = false;
|
|
943
|
+
let inDouble = false;
|
|
944
|
+
let inLineComment = false;
|
|
945
|
+
let inBlockComment = false;
|
|
946
|
+
for (let i = 0; i < sql.length; i++) {
|
|
947
|
+
const ch = sql[i];
|
|
948
|
+
const next = sql[i + 1];
|
|
949
|
+
if (inLineComment) {
|
|
950
|
+
current += ch;
|
|
951
|
+
if (ch === "\n") inLineComment = false;
|
|
952
|
+
continue;
|
|
953
|
+
}
|
|
954
|
+
if (inBlockComment) {
|
|
955
|
+
current += ch;
|
|
956
|
+
if (ch === "*" && next === "/") {
|
|
957
|
+
current += next;
|
|
958
|
+
inBlockComment = false;
|
|
959
|
+
i += 1;
|
|
960
|
+
}
|
|
961
|
+
continue;
|
|
962
|
+
}
|
|
963
|
+
if (!inSingle && !inDouble && ch === "-" && next === "-") {
|
|
964
|
+
current += ch + next;
|
|
965
|
+
inLineComment = true;
|
|
966
|
+
i += 1;
|
|
967
|
+
continue;
|
|
968
|
+
}
|
|
969
|
+
if (!inSingle && !inDouble && ch === "/" && next === "*") {
|
|
970
|
+
current += ch + next;
|
|
971
|
+
inBlockComment = true;
|
|
972
|
+
i += 1;
|
|
973
|
+
continue;
|
|
974
|
+
}
|
|
975
|
+
if (!inDouble && ch === "'" && sql[i - 1] !== "\\") {
|
|
976
|
+
inSingle = !inSingle;
|
|
977
|
+
current += ch;
|
|
978
|
+
continue;
|
|
979
|
+
}
|
|
980
|
+
if (!inSingle && ch === '"' && sql[i - 1] !== "\\") {
|
|
981
|
+
inDouble = !inDouble;
|
|
982
|
+
current += ch;
|
|
983
|
+
continue;
|
|
984
|
+
}
|
|
985
|
+
if (!inSingle && !inDouble && ch === ";") {
|
|
986
|
+
if (current.trim()) {
|
|
987
|
+
parts.push(current.trim());
|
|
988
|
+
}
|
|
989
|
+
current = "";
|
|
990
|
+
continue;
|
|
991
|
+
}
|
|
992
|
+
current += ch;
|
|
993
|
+
}
|
|
994
|
+
if (current.trim()) {
|
|
995
|
+
parts.push(current.trim());
|
|
996
|
+
}
|
|
997
|
+
return parts;
|
|
998
|
+
}
|
|
999
|
+
async function createPrismaDbAdapter(fallbackClient) {
|
|
1000
|
+
const prisma = await loadPrismaClient();
|
|
1001
|
+
await ensureCompatibilityViews(prisma);
|
|
1002
|
+
let closed = false;
|
|
1003
|
+
let adapter;
|
|
1004
|
+
const fallbackExecute = async (stmt, error) => {
|
|
1005
|
+
if (!fallbackClient) {
|
|
1006
|
+
if (error) throw error;
|
|
1007
|
+
throw new Error("No fallback SQLite client is available for this Prisma-routed query.");
|
|
1008
|
+
}
|
|
1009
|
+
if (error) {
|
|
1010
|
+
process.stderr.write(
|
|
1011
|
+
`[database-adapter] Falling back to SQLite: ${error instanceof Error ? error.message : String(error)}
|
|
1012
|
+
`
|
|
1013
|
+
);
|
|
1014
|
+
}
|
|
1015
|
+
return fallbackClient.execute(stmt);
|
|
1016
|
+
};
|
|
1017
|
+
adapter = {
|
|
1018
|
+
async execute(stmt) {
|
|
1019
|
+
if (shouldBypassPostgres(stmt)) {
|
|
1020
|
+
return fallbackExecute(stmt);
|
|
1021
|
+
}
|
|
1022
|
+
try {
|
|
1023
|
+
return await executeOnPrisma(prisma, stmt);
|
|
1024
|
+
} catch (error) {
|
|
1025
|
+
if (shouldFallbackOnError(error)) {
|
|
1026
|
+
return fallbackExecute(stmt, error);
|
|
1027
|
+
}
|
|
1028
|
+
throw error;
|
|
1029
|
+
}
|
|
1030
|
+
},
|
|
1031
|
+
async batch(stmts, mode) {
|
|
1032
|
+
if (stmts.some((stmt) => shouldBypassPostgres(stmt))) {
|
|
1033
|
+
if (!fallbackClient) {
|
|
1034
|
+
throw new Error("Cannot batch unsupported SQLite-only statements without a fallback client.");
|
|
1035
|
+
}
|
|
1036
|
+
return fallbackClient.batch(stmts, mode);
|
|
1037
|
+
}
|
|
1038
|
+
try {
|
|
1039
|
+
if (prisma.$transaction) {
|
|
1040
|
+
return await prisma.$transaction(async (tx) => {
|
|
1041
|
+
const results2 = [];
|
|
1042
|
+
for (const stmt of stmts) {
|
|
1043
|
+
results2.push(await executeOnPrisma(tx, stmt));
|
|
1044
|
+
}
|
|
1045
|
+
return results2;
|
|
1046
|
+
});
|
|
1047
|
+
}
|
|
1048
|
+
const results = [];
|
|
1049
|
+
for (const stmt of stmts) {
|
|
1050
|
+
results.push(await executeOnPrisma(prisma, stmt));
|
|
1051
|
+
}
|
|
1052
|
+
return results;
|
|
1053
|
+
} catch (error) {
|
|
1054
|
+
if (fallbackClient && shouldFallbackOnError(error)) {
|
|
1055
|
+
process.stderr.write(
|
|
1056
|
+
`[database-adapter] Falling back batch to SQLite: ${error instanceof Error ? error.message : String(error)}
|
|
1057
|
+
`
|
|
1058
|
+
);
|
|
1059
|
+
return fallbackClient.batch(stmts, mode);
|
|
1060
|
+
}
|
|
1061
|
+
throw error;
|
|
1062
|
+
}
|
|
1063
|
+
},
|
|
1064
|
+
async migrate(stmts) {
|
|
1065
|
+
if (fallbackClient) {
|
|
1066
|
+
return fallbackClient.migrate(stmts);
|
|
1067
|
+
}
|
|
1068
|
+
return adapter.batch(stmts, "deferred");
|
|
1069
|
+
},
|
|
1070
|
+
async transaction(mode) {
|
|
1071
|
+
if (!fallbackClient) {
|
|
1072
|
+
throw new Error("Interactive transactions are only supported on the SQLite fallback client.");
|
|
1073
|
+
}
|
|
1074
|
+
return fallbackClient.transaction(mode);
|
|
1075
|
+
},
|
|
1076
|
+
async executeMultiple(sql) {
|
|
1077
|
+
if (fallbackClient && shouldBypassPostgres(sql)) {
|
|
1078
|
+
return fallbackClient.executeMultiple(sql);
|
|
1079
|
+
}
|
|
1080
|
+
for (const statement of splitSqlStatements(sql)) {
|
|
1081
|
+
await adapter.execute(statement);
|
|
1082
|
+
}
|
|
1083
|
+
},
|
|
1084
|
+
async sync() {
|
|
1085
|
+
if (fallbackClient) {
|
|
1086
|
+
return fallbackClient.sync();
|
|
1087
|
+
}
|
|
1088
|
+
return { frame_no: 0, frames_synced: 0 };
|
|
1089
|
+
},
|
|
1090
|
+
close() {
|
|
1091
|
+
closed = true;
|
|
1092
|
+
prismaClientPromise = null;
|
|
1093
|
+
compatibilityBootstrapPromise = null;
|
|
1094
|
+
void prisma.$disconnect?.();
|
|
1095
|
+
},
|
|
1096
|
+
get closed() {
|
|
1097
|
+
return closed;
|
|
1098
|
+
},
|
|
1099
|
+
get protocol() {
|
|
1100
|
+
return "prisma-postgres";
|
|
1101
|
+
}
|
|
1102
|
+
};
|
|
1103
|
+
return adapter;
|
|
1104
|
+
}
|
|
1105
|
+
var VIEW_MAPPINGS, UPSERT_KEYS, BOOLEAN_COLUMNS_BY_TABLE, BOOLEAN_COLUMN_NAMES, IMMEDIATE_FALLBACK_PATTERNS, prismaClientPromise, compatibilityBootstrapPromise;
|
|
1106
|
+
var init_database_adapter = __esm({
|
|
1107
|
+
"src/lib/database-adapter.ts"() {
|
|
1108
|
+
"use strict";
|
|
1109
|
+
VIEW_MAPPINGS = [
|
|
1110
|
+
{ view: "memories", source: "memory.memory_records" },
|
|
1111
|
+
{ view: "tasks", source: "memory.tasks" },
|
|
1112
|
+
{ view: "behaviors", source: "memory.behaviors" },
|
|
1113
|
+
{ view: "entities", source: "memory.entities" },
|
|
1114
|
+
{ view: "relationships", source: "memory.relationships" },
|
|
1115
|
+
{ view: "entity_memories", source: "memory.entity_memories" },
|
|
1116
|
+
{ view: "entity_aliases", source: "memory.entity_aliases" },
|
|
1117
|
+
{ view: "notifications", source: "memory.notifications" },
|
|
1118
|
+
{ view: "messages", source: "memory.messages" },
|
|
1119
|
+
{ view: "users", source: "wiki.users" },
|
|
1120
|
+
{ view: "workspaces", source: "wiki.workspaces" },
|
|
1121
|
+
{ view: "workspace_users", source: "wiki.workspace_users" },
|
|
1122
|
+
{ view: "documents", source: "wiki.workspace_documents" },
|
|
1123
|
+
{ view: "chats", source: "wiki.workspace_chats" }
|
|
1124
|
+
];
|
|
1125
|
+
UPSERT_KEYS = {
|
|
1126
|
+
memories: ["id"],
|
|
1127
|
+
tasks: ["id"],
|
|
1128
|
+
behaviors: ["id"],
|
|
1129
|
+
entities: ["id"],
|
|
1130
|
+
relationships: ["id"],
|
|
1131
|
+
entity_aliases: ["alias"],
|
|
1132
|
+
notifications: ["id"],
|
|
1133
|
+
messages: ["id"],
|
|
1134
|
+
users: ["id"],
|
|
1135
|
+
workspaces: ["id"],
|
|
1136
|
+
workspace_users: ["id"],
|
|
1137
|
+
documents: ["id"],
|
|
1138
|
+
chats: ["id"]
|
|
1139
|
+
};
|
|
1140
|
+
BOOLEAN_COLUMNS_BY_TABLE = {
|
|
1141
|
+
memories: /* @__PURE__ */ new Set(["has_error", "draft"]),
|
|
1142
|
+
behaviors: /* @__PURE__ */ new Set(["active"]),
|
|
1143
|
+
notifications: /* @__PURE__ */ new Set(["read"]),
|
|
1144
|
+
users: /* @__PURE__ */ new Set(["has_personal_memory"])
|
|
1145
|
+
};
|
|
1146
|
+
BOOLEAN_COLUMN_NAMES = new Set(
|
|
1147
|
+
Object.values(BOOLEAN_COLUMNS_BY_TABLE).flatMap((cols) => [...cols])
|
|
1148
|
+
);
|
|
1149
|
+
IMMEDIATE_FALLBACK_PATTERNS = [
|
|
1150
|
+
/\bPRAGMA\b/i,
|
|
1151
|
+
/\bsqlite_master\b/i,
|
|
1152
|
+
/(?:^|[.\s])(?:memories|conversations|entities)_fts\b/i,
|
|
1153
|
+
/\bMATCH\b/i,
|
|
1154
|
+
/\bvector_distance_cos\s*\(/i,
|
|
1155
|
+
/\bjson_extract\s*\(/i,
|
|
1156
|
+
/\bjulianday\s*\(/i,
|
|
1157
|
+
/\bstrftime\s*\(/i,
|
|
1158
|
+
/\blast_insert_rowid\s*\(/i
|
|
1159
|
+
];
|
|
1160
|
+
prismaClientPromise = null;
|
|
1161
|
+
compatibilityBootstrapPromise = null;
|
|
1162
|
+
}
|
|
1163
|
+
});
|
|
1164
|
+
|
|
580
1165
|
// src/lib/exe-daemon-client.ts
|
|
581
1166
|
import net from "net";
|
|
582
|
-
import
|
|
1167
|
+
import os6 from "os";
|
|
583
1168
|
import { spawn } from "child_process";
|
|
584
1169
|
import { randomUUID } from "crypto";
|
|
585
1170
|
import { existsSync as existsSync5, unlinkSync as unlinkSync3, readFileSync as readFileSync6, openSync, closeSync, statSync } from "fs";
|
|
586
|
-
import
|
|
1171
|
+
import path8 from "path";
|
|
587
1172
|
import { fileURLToPath } from "url";
|
|
588
1173
|
function handleData(chunk) {
|
|
589
1174
|
_buffer += chunk.toString();
|
|
@@ -634,17 +1219,17 @@ function cleanupStaleFiles() {
|
|
|
634
1219
|
}
|
|
635
1220
|
}
|
|
636
1221
|
function findPackageRoot() {
|
|
637
|
-
let dir =
|
|
638
|
-
const { root } =
|
|
1222
|
+
let dir = path8.dirname(fileURLToPath(import.meta.url));
|
|
1223
|
+
const { root } = path8.parse(dir);
|
|
639
1224
|
while (dir !== root) {
|
|
640
|
-
if (existsSync5(
|
|
641
|
-
dir =
|
|
1225
|
+
if (existsSync5(path8.join(dir, "package.json"))) return dir;
|
|
1226
|
+
dir = path8.dirname(dir);
|
|
642
1227
|
}
|
|
643
1228
|
return null;
|
|
644
1229
|
}
|
|
645
1230
|
function spawnDaemon() {
|
|
646
|
-
const freeGB =
|
|
647
|
-
const totalGB =
|
|
1231
|
+
const freeGB = os6.freemem() / (1024 * 1024 * 1024);
|
|
1232
|
+
const totalGB = os6.totalmem() / (1024 * 1024 * 1024);
|
|
648
1233
|
if (totalGB <= 8) {
|
|
649
1234
|
process.stderr.write(
|
|
650
1235
|
`[exed-client] SKIP: ${totalGB.toFixed(0)}GB system \u2014 embedding daemon disabled. Using keyword search only. Minimum 16GB recommended for vector search.
|
|
@@ -664,7 +1249,7 @@ function spawnDaemon() {
|
|
|
664
1249
|
process.stderr.write("[exed-client] WARN: cannot find package root\n");
|
|
665
1250
|
return;
|
|
666
1251
|
}
|
|
667
|
-
const daemonPath =
|
|
1252
|
+
const daemonPath = path8.join(pkgRoot, "dist", "lib", "exe-daemon.js");
|
|
668
1253
|
if (!existsSync5(daemonPath)) {
|
|
669
1254
|
process.stderr.write(`[exed-client] WARN: daemon script not found at ${daemonPath}
|
|
670
1255
|
`);
|
|
@@ -673,7 +1258,7 @@ function spawnDaemon() {
|
|
|
673
1258
|
const resolvedPath = daemonPath;
|
|
674
1259
|
process.stderr.write(`[exed-client] Spawning daemon: ${resolvedPath}
|
|
675
1260
|
`);
|
|
676
|
-
const logPath =
|
|
1261
|
+
const logPath = path8.join(path8.dirname(SOCKET_PATH), "exed.log");
|
|
677
1262
|
let stderrFd = "ignore";
|
|
678
1263
|
try {
|
|
679
1264
|
stderrFd = openSync(logPath, "a");
|
|
@@ -820,9 +1405,9 @@ var init_exe_daemon_client = __esm({
|
|
|
820
1405
|
"src/lib/exe-daemon-client.ts"() {
|
|
821
1406
|
"use strict";
|
|
822
1407
|
init_config();
|
|
823
|
-
SOCKET_PATH = process.env.EXE_DAEMON_SOCK ?? process.env.EXE_EMBED_SOCK ??
|
|
824
|
-
PID_PATH = process.env.EXE_DAEMON_PID ?? process.env.EXE_EMBED_PID ??
|
|
825
|
-
SPAWN_LOCK_PATH =
|
|
1408
|
+
SOCKET_PATH = process.env.EXE_DAEMON_SOCK ?? process.env.EXE_EMBED_SOCK ?? path8.join(EXE_AI_DIR, "exed.sock");
|
|
1409
|
+
PID_PATH = process.env.EXE_DAEMON_PID ?? process.env.EXE_EMBED_PID ?? path8.join(EXE_AI_DIR, "exed.pid");
|
|
1410
|
+
SPAWN_LOCK_PATH = path8.join(EXE_AI_DIR, "exed-spawn.lock");
|
|
826
1411
|
SPAWN_LOCK_STALE_MS = 3e4;
|
|
827
1412
|
CONNECT_TIMEOUT_MS = 15e3;
|
|
828
1413
|
REQUEST_TIMEOUT_MS = 3e4;
|
|
@@ -904,7 +1489,7 @@ __export(db_daemon_client_exports, {
|
|
|
904
1489
|
createDaemonDbClient: () => createDaemonDbClient,
|
|
905
1490
|
initDaemonDbClient: () => initDaemonDbClient
|
|
906
1491
|
});
|
|
907
|
-
function
|
|
1492
|
+
function normalizeStatement2(stmt) {
|
|
908
1493
|
if (typeof stmt === "string") {
|
|
909
1494
|
return { sql: stmt, args: [] };
|
|
910
1495
|
}
|
|
@@ -928,7 +1513,7 @@ function createDaemonDbClient(fallbackClient) {
|
|
|
928
1513
|
if (!_useDaemon || !isClientConnected()) {
|
|
929
1514
|
return fallbackClient.execute(stmt);
|
|
930
1515
|
}
|
|
931
|
-
const { sql, args } =
|
|
1516
|
+
const { sql, args } = normalizeStatement2(stmt);
|
|
932
1517
|
const response = await sendDaemonRequest({
|
|
933
1518
|
type: "db-execute",
|
|
934
1519
|
sql,
|
|
@@ -953,7 +1538,7 @@ function createDaemonDbClient(fallbackClient) {
|
|
|
953
1538
|
if (!_useDaemon || !isClientConnected()) {
|
|
954
1539
|
return fallbackClient.batch(stmts, mode);
|
|
955
1540
|
}
|
|
956
|
-
const statements = stmts.map(
|
|
1541
|
+
const statements = stmts.map(normalizeStatement2);
|
|
957
1542
|
const response = await sendDaemonRequest({
|
|
958
1543
|
type: "db-batch",
|
|
959
1544
|
statements,
|
|
@@ -1048,6 +1633,18 @@ __export(database_exports, {
|
|
|
1048
1633
|
});
|
|
1049
1634
|
import { createClient } from "@libsql/client";
|
|
1050
1635
|
async function initDatabase(config) {
|
|
1636
|
+
if (_walCheckpointTimer) {
|
|
1637
|
+
clearInterval(_walCheckpointTimer);
|
|
1638
|
+
_walCheckpointTimer = null;
|
|
1639
|
+
}
|
|
1640
|
+
if (_daemonClient) {
|
|
1641
|
+
_daemonClient.close();
|
|
1642
|
+
_daemonClient = null;
|
|
1643
|
+
}
|
|
1644
|
+
if (_adapterClient && _adapterClient !== _resilientClient) {
|
|
1645
|
+
_adapterClient.close();
|
|
1646
|
+
}
|
|
1647
|
+
_adapterClient = null;
|
|
1051
1648
|
if (_client) {
|
|
1052
1649
|
_client.close();
|
|
1053
1650
|
_client = null;
|
|
@@ -1061,6 +1658,7 @@ async function initDatabase(config) {
|
|
|
1061
1658
|
}
|
|
1062
1659
|
_client = createClient(opts);
|
|
1063
1660
|
_resilientClient = wrapWithRetry(_client);
|
|
1661
|
+
_adapterClient = _resilientClient;
|
|
1064
1662
|
_client.execute("PRAGMA busy_timeout = 30000").catch(() => {
|
|
1065
1663
|
});
|
|
1066
1664
|
_client.execute("PRAGMA journal_mode = WAL").catch(() => {
|
|
@@ -1071,14 +1669,20 @@ async function initDatabase(config) {
|
|
|
1071
1669
|
});
|
|
1072
1670
|
}, 3e4);
|
|
1073
1671
|
_walCheckpointTimer.unref();
|
|
1672
|
+
if (process.env.DATABASE_URL) {
|
|
1673
|
+
_adapterClient = await createPrismaDbAdapter(_resilientClient);
|
|
1674
|
+
}
|
|
1074
1675
|
}
|
|
1075
1676
|
function isInitialized() {
|
|
1076
|
-
return _client !== null;
|
|
1677
|
+
return _adapterClient !== null || _client !== null;
|
|
1077
1678
|
}
|
|
1078
1679
|
function getClient() {
|
|
1079
|
-
if (!
|
|
1680
|
+
if (!_adapterClient) {
|
|
1080
1681
|
throw new Error("Database client not initialized. Call initDatabase() first.");
|
|
1081
1682
|
}
|
|
1683
|
+
if (process.env.DATABASE_URL) {
|
|
1684
|
+
return _adapterClient;
|
|
1685
|
+
}
|
|
1082
1686
|
if (process.env.EXE_IS_DAEMON === "1") {
|
|
1083
1687
|
return _resilientClient;
|
|
1084
1688
|
}
|
|
@@ -1088,6 +1692,7 @@ function getClient() {
|
|
|
1088
1692
|
return _resilientClient;
|
|
1089
1693
|
}
|
|
1090
1694
|
async function initDaemonClient() {
|
|
1695
|
+
if (process.env.DATABASE_URL) return;
|
|
1091
1696
|
if (process.env.EXE_IS_DAEMON === "1") return;
|
|
1092
1697
|
if (!_resilientClient) return;
|
|
1093
1698
|
try {
|
|
@@ -2032,26 +2637,36 @@ async function ensureSchema() {
|
|
|
2032
2637
|
}
|
|
2033
2638
|
}
|
|
2034
2639
|
async function disposeDatabase() {
|
|
2640
|
+
if (_walCheckpointTimer) {
|
|
2641
|
+
clearInterval(_walCheckpointTimer);
|
|
2642
|
+
_walCheckpointTimer = null;
|
|
2643
|
+
}
|
|
2035
2644
|
if (_daemonClient) {
|
|
2036
2645
|
_daemonClient.close();
|
|
2037
2646
|
_daemonClient = null;
|
|
2038
2647
|
}
|
|
2648
|
+
if (_adapterClient && _adapterClient !== _resilientClient) {
|
|
2649
|
+
_adapterClient.close();
|
|
2650
|
+
}
|
|
2651
|
+
_adapterClient = null;
|
|
2039
2652
|
if (_client) {
|
|
2040
2653
|
_client.close();
|
|
2041
2654
|
_client = null;
|
|
2042
2655
|
_resilientClient = null;
|
|
2043
2656
|
}
|
|
2044
2657
|
}
|
|
2045
|
-
var _client, _resilientClient, _walCheckpointTimer, _daemonClient, initTurso, disposeTurso;
|
|
2658
|
+
var _client, _resilientClient, _walCheckpointTimer, _daemonClient, _adapterClient, initTurso, disposeTurso;
|
|
2046
2659
|
var init_database = __esm({
|
|
2047
2660
|
"src/lib/database.ts"() {
|
|
2048
2661
|
"use strict";
|
|
2049
2662
|
init_db_retry();
|
|
2050
2663
|
init_employees();
|
|
2664
|
+
init_database_adapter();
|
|
2051
2665
|
_client = null;
|
|
2052
2666
|
_resilientClient = null;
|
|
2053
2667
|
_walCheckpointTimer = null;
|
|
2054
2668
|
_daemonClient = null;
|
|
2669
|
+
_adapterClient = null;
|
|
2055
2670
|
initTurso = initDatabase;
|
|
2056
2671
|
disposeTurso = disposeDatabase;
|
|
2057
2672
|
}
|
|
@@ -2060,22 +2675,22 @@ var init_database = __esm({
|
|
|
2060
2675
|
// src/lib/license.ts
|
|
2061
2676
|
import { readFileSync as readFileSync7, writeFileSync as writeFileSync5, existsSync as existsSync6, mkdirSync as mkdirSync4 } from "fs";
|
|
2062
2677
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
2063
|
-
import
|
|
2678
|
+
import path9 from "path";
|
|
2064
2679
|
import { jwtVerify, importSPKI } from "jose";
|
|
2065
2680
|
var LICENSE_PATH, CACHE_PATH, DEVICE_ID_PATH;
|
|
2066
2681
|
var init_license = __esm({
|
|
2067
2682
|
"src/lib/license.ts"() {
|
|
2068
2683
|
"use strict";
|
|
2069
2684
|
init_config();
|
|
2070
|
-
LICENSE_PATH =
|
|
2071
|
-
CACHE_PATH =
|
|
2072
|
-
DEVICE_ID_PATH =
|
|
2685
|
+
LICENSE_PATH = path9.join(EXE_AI_DIR, "license.key");
|
|
2686
|
+
CACHE_PATH = path9.join(EXE_AI_DIR, "license-cache.json");
|
|
2687
|
+
DEVICE_ID_PATH = path9.join(EXE_AI_DIR, "device-id");
|
|
2073
2688
|
}
|
|
2074
2689
|
});
|
|
2075
2690
|
|
|
2076
2691
|
// src/lib/plan-limits.ts
|
|
2077
2692
|
import { readFileSync as readFileSync8, existsSync as existsSync7 } from "fs";
|
|
2078
|
-
import
|
|
2693
|
+
import path10 from "path";
|
|
2079
2694
|
var CACHE_PATH2;
|
|
2080
2695
|
var init_plan_limits = __esm({
|
|
2081
2696
|
"src/lib/plan-limits.ts"() {
|
|
@@ -2084,14 +2699,14 @@ var init_plan_limits = __esm({
|
|
|
2084
2699
|
init_employees();
|
|
2085
2700
|
init_license();
|
|
2086
2701
|
init_config();
|
|
2087
|
-
CACHE_PATH2 =
|
|
2702
|
+
CACHE_PATH2 = path10.join(EXE_AI_DIR, "license-cache.json");
|
|
2088
2703
|
}
|
|
2089
2704
|
});
|
|
2090
2705
|
|
|
2091
2706
|
// src/lib/tmux-routing.ts
|
|
2092
2707
|
import { readFileSync as readFileSync9, writeFileSync as writeFileSync6, mkdirSync as mkdirSync5, existsSync as existsSync8, appendFileSync, readdirSync as readdirSync2 } from "fs";
|
|
2093
|
-
import
|
|
2094
|
-
import
|
|
2708
|
+
import path11 from "path";
|
|
2709
|
+
import os7 from "os";
|
|
2095
2710
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
2096
2711
|
function getMySession() {
|
|
2097
2712
|
return getTransport().getMySession();
|
|
@@ -2104,7 +2719,7 @@ function extractRootExe(name) {
|
|
|
2104
2719
|
}
|
|
2105
2720
|
function getParentExe(sessionKey) {
|
|
2106
2721
|
try {
|
|
2107
|
-
const data = JSON.parse(readFileSync9(
|
|
2722
|
+
const data = JSON.parse(readFileSync9(path11.join(SESSION_CACHE, `parent-exe-${sessionKey}.json`), "utf8"));
|
|
2108
2723
|
return data.parentExe || null;
|
|
2109
2724
|
} catch {
|
|
2110
2725
|
return null;
|
|
@@ -2147,10 +2762,10 @@ var init_tmux_routing = __esm({
|
|
|
2147
2762
|
init_intercom_queue();
|
|
2148
2763
|
init_plan_limits();
|
|
2149
2764
|
init_employees();
|
|
2150
|
-
SPAWN_LOCK_DIR =
|
|
2151
|
-
SESSION_CACHE =
|
|
2152
|
-
INTERCOM_LOG2 =
|
|
2153
|
-
DEBOUNCE_FILE =
|
|
2765
|
+
SPAWN_LOCK_DIR = path11.join(os7.homedir(), ".exe-os", "spawn-locks");
|
|
2766
|
+
SESSION_CACHE = path11.join(os7.homedir(), ".exe-os", "session-cache");
|
|
2767
|
+
INTERCOM_LOG2 = path11.join(os7.homedir(), ".exe-os", "intercom.log");
|
|
2768
|
+
DEBOUNCE_FILE = path11.join(SESSION_CACHE, "intercom-debounce.json");
|
|
2154
2769
|
DEBOUNCE_CLEANUP_AGE_MS = 5 * 60 * 1e3;
|
|
2155
2770
|
}
|
|
2156
2771
|
});
|
|
@@ -2191,13 +2806,13 @@ var init_memory = __esm({
|
|
|
2191
2806
|
// src/lib/keychain.ts
|
|
2192
2807
|
import { readFile as readFile3, writeFile as writeFile3, unlink, mkdir as mkdir3, chmod as chmod2 } from "fs/promises";
|
|
2193
2808
|
import { existsSync as existsSync9 } from "fs";
|
|
2194
|
-
import
|
|
2195
|
-
import
|
|
2809
|
+
import path12 from "path";
|
|
2810
|
+
import os8 from "os";
|
|
2196
2811
|
function getKeyDir() {
|
|
2197
|
-
return process.env.EXE_OS_DIR ?? process.env.EXE_MEM_DIR ??
|
|
2812
|
+
return process.env.EXE_OS_DIR ?? process.env.EXE_MEM_DIR ?? path12.join(os8.homedir(), ".exe-os");
|
|
2198
2813
|
}
|
|
2199
2814
|
function getKeyPath() {
|
|
2200
|
-
return
|
|
2815
|
+
return path12.join(getKeyDir(), "master.key");
|
|
2201
2816
|
}
|
|
2202
2817
|
async function tryKeytar() {
|
|
2203
2818
|
try {
|
|
@@ -2220,7 +2835,7 @@ async function getMasterKey() {
|
|
|
2220
2835
|
const keyPath = getKeyPath();
|
|
2221
2836
|
if (!existsSync9(keyPath)) {
|
|
2222
2837
|
process.stderr.write(
|
|
2223
|
-
`[keychain] Key not found at ${keyPath} (HOME=${
|
|
2838
|
+
`[keychain] Key not found at ${keyPath} (HOME=${os8.homedir()}, EXE_OS_DIR=${process.env.EXE_OS_DIR ?? "unset"})
|
|
2224
2839
|
`
|
|
2225
2840
|
);
|
|
2226
2841
|
return null;
|
|
@@ -2313,7 +2928,7 @@ __export(shard_manager_exports, {
|
|
|
2313
2928
|
listShards: () => listShards,
|
|
2314
2929
|
shardExists: () => shardExists
|
|
2315
2930
|
});
|
|
2316
|
-
import
|
|
2931
|
+
import path13 from "path";
|
|
2317
2932
|
import { existsSync as existsSync10, mkdirSync as mkdirSync6, readdirSync as readdirSync3 } from "fs";
|
|
2318
2933
|
import { createClient as createClient2 } from "@libsql/client";
|
|
2319
2934
|
function initShardManager(encryptionKey) {
|
|
@@ -2339,7 +2954,7 @@ function getShardClient(projectName) {
|
|
|
2339
2954
|
}
|
|
2340
2955
|
const cached = _shards.get(safeName);
|
|
2341
2956
|
if (cached) return cached;
|
|
2342
|
-
const dbPath =
|
|
2957
|
+
const dbPath = path13.join(SHARDS_DIR, `${safeName}.db`);
|
|
2343
2958
|
const client = createClient2({
|
|
2344
2959
|
url: `file:${dbPath}`,
|
|
2345
2960
|
encryptionKey: _encryptionKey
|
|
@@ -2349,7 +2964,7 @@ function getShardClient(projectName) {
|
|
|
2349
2964
|
}
|
|
2350
2965
|
function shardExists(projectName) {
|
|
2351
2966
|
const safeName = projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
2352
|
-
return existsSync10(
|
|
2967
|
+
return existsSync10(path13.join(SHARDS_DIR, `${safeName}.db`));
|
|
2353
2968
|
}
|
|
2354
2969
|
function listShards() {
|
|
2355
2970
|
if (!existsSync10(SHARDS_DIR)) return [];
|
|
@@ -2426,7 +3041,23 @@ async function ensureShardSchema(client) {
|
|
|
2426
3041
|
// MS-11: draft staging, MS-6a: memory_type, MS-7: trajectory
|
|
2427
3042
|
"ALTER TABLE memories ADD COLUMN draft INTEGER DEFAULT 0",
|
|
2428
3043
|
"ALTER TABLE memories ADD COLUMN memory_type TEXT DEFAULT 'raw'",
|
|
2429
|
-
"ALTER TABLE memories ADD COLUMN trajectory TEXT"
|
|
3044
|
+
"ALTER TABLE memories ADD COLUMN trajectory TEXT",
|
|
3045
|
+
// Metadata enrichment columns (must match database.ts)
|
|
3046
|
+
"ALTER TABLE memories ADD COLUMN intent TEXT",
|
|
3047
|
+
"ALTER TABLE memories ADD COLUMN outcome TEXT",
|
|
3048
|
+
"ALTER TABLE memories ADD COLUMN domain TEXT",
|
|
3049
|
+
"ALTER TABLE memories ADD COLUMN referenced_entities TEXT",
|
|
3050
|
+
"ALTER TABLE memories ADD COLUMN retrieval_count INTEGER DEFAULT 0",
|
|
3051
|
+
"ALTER TABLE memories ADD COLUMN chain_position TEXT",
|
|
3052
|
+
"ALTER TABLE memories ADD COLUMN review_status TEXT",
|
|
3053
|
+
"ALTER TABLE memories ADD COLUMN context_window_pct INTEGER",
|
|
3054
|
+
"ALTER TABLE memories ADD COLUMN file_paths TEXT",
|
|
3055
|
+
"ALTER TABLE memories ADD COLUMN commit_hash TEXT",
|
|
3056
|
+
"ALTER TABLE memories ADD COLUMN duration_ms INTEGER",
|
|
3057
|
+
"ALTER TABLE memories ADD COLUMN token_cost REAL",
|
|
3058
|
+
"ALTER TABLE memories ADD COLUMN audience TEXT",
|
|
3059
|
+
"ALTER TABLE memories ADD COLUMN language_type TEXT",
|
|
3060
|
+
"ALTER TABLE memories ADD COLUMN parent_memory_id TEXT"
|
|
2430
3061
|
]) {
|
|
2431
3062
|
try {
|
|
2432
3063
|
await client.execute(col);
|
|
@@ -2538,7 +3169,7 @@ var init_shard_manager = __esm({
|
|
|
2538
3169
|
"src/lib/shard-manager.ts"() {
|
|
2539
3170
|
"use strict";
|
|
2540
3171
|
init_config();
|
|
2541
|
-
SHARDS_DIR =
|
|
3172
|
+
SHARDS_DIR = path13.join(EXE_AI_DIR, "shards");
|
|
2542
3173
|
_shards = /* @__PURE__ */ new Map();
|
|
2543
3174
|
_encryptionKey = null;
|
|
2544
3175
|
_shardingEnabled = false;
|