@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
package/dist/runtime/index.js
CHANGED
|
@@ -255,7 +255,7 @@ function isMultiInstance(agentName, employees) {
|
|
|
255
255
|
if (!emp) return false;
|
|
256
256
|
return MULTI_INSTANCE_ROLES.has(emp.role.toLowerCase());
|
|
257
257
|
}
|
|
258
|
-
var EMPLOYEES_PATH, DEFAULT_COORDINATOR_TEMPLATE_NAME, COORDINATOR_ROLE, MULTI_INSTANCE_ROLES;
|
|
258
|
+
var EMPLOYEES_PATH, DEFAULT_COORDINATOR_TEMPLATE_NAME, COORDINATOR_ROLE, MULTI_INSTANCE_ROLES, IDENTITY_DIR;
|
|
259
259
|
var init_employees = __esm({
|
|
260
260
|
"src/lib/employees.ts"() {
|
|
261
261
|
"use strict";
|
|
@@ -264,6 +264,7 @@ var init_employees = __esm({
|
|
|
264
264
|
DEFAULT_COORDINATOR_TEMPLATE_NAME = "exe";
|
|
265
265
|
COORDINATOR_ROLE = "COO";
|
|
266
266
|
MULTI_INSTANCE_ROLES = /* @__PURE__ */ new Set(["principal engineer", "content production specialist", "staff code reviewer"]);
|
|
267
|
+
IDENTITY_DIR = path3.join(EXE_AI_DIR, "identity");
|
|
267
268
|
}
|
|
268
269
|
});
|
|
269
270
|
|
|
@@ -827,13 +828,597 @@ var init_db_retry = __esm({
|
|
|
827
828
|
}
|
|
828
829
|
});
|
|
829
830
|
|
|
831
|
+
// src/lib/database-adapter.ts
|
|
832
|
+
import os6 from "os";
|
|
833
|
+
import path7 from "path";
|
|
834
|
+
import { createRequire } from "module";
|
|
835
|
+
import { pathToFileURL } from "url";
|
|
836
|
+
function quotedIdentifier(identifier) {
|
|
837
|
+
return `"${identifier.replace(/"/g, '""')}"`;
|
|
838
|
+
}
|
|
839
|
+
function unqualifiedTableName(name) {
|
|
840
|
+
const raw = name.trim().replace(/^"|"$/g, "");
|
|
841
|
+
const parts = raw.split(".");
|
|
842
|
+
return parts[parts.length - 1].replace(/^"|"$/g, "").toLowerCase();
|
|
843
|
+
}
|
|
844
|
+
function stripTrailingSemicolon(sql) {
|
|
845
|
+
return sql.trim().replace(/;+\s*$/u, "");
|
|
846
|
+
}
|
|
847
|
+
function appendClause(sql, clause) {
|
|
848
|
+
const trimmed = stripTrailingSemicolon(sql);
|
|
849
|
+
const returningMatch = /\sRETURNING\b[\s\S]*$/iu.exec(trimmed);
|
|
850
|
+
if (!returningMatch) {
|
|
851
|
+
return `${trimmed}${clause}`;
|
|
852
|
+
}
|
|
853
|
+
const idx = returningMatch.index;
|
|
854
|
+
return `${trimmed.slice(0, idx)}${clause}${trimmed.slice(idx)}`;
|
|
855
|
+
}
|
|
856
|
+
function normalizeStatement(stmt) {
|
|
857
|
+
if (typeof stmt === "string") {
|
|
858
|
+
return { kind: "positional", sql: stmt, args: [] };
|
|
859
|
+
}
|
|
860
|
+
const sql = stmt.sql;
|
|
861
|
+
if (Array.isArray(stmt.args) || stmt.args === void 0) {
|
|
862
|
+
return { kind: "positional", sql, args: stmt.args ?? [] };
|
|
863
|
+
}
|
|
864
|
+
return { kind: "named", sql, args: stmt.args };
|
|
865
|
+
}
|
|
866
|
+
function rewriteBooleanLiterals(sql) {
|
|
867
|
+
let out = sql;
|
|
868
|
+
for (const column of BOOLEAN_COLUMN_NAMES) {
|
|
869
|
+
const scoped = `((?:\\b[a-z_][a-z0-9_]*\\.)?${column})`;
|
|
870
|
+
out = out.replace(new RegExp(`${scoped}\\s*=\\s*0\\b`, "giu"), "$1 = FALSE");
|
|
871
|
+
out = out.replace(new RegExp(`${scoped}\\s*=\\s*1\\b`, "giu"), "$1 = TRUE");
|
|
872
|
+
out = out.replace(new RegExp(`${scoped}\\s*!=\\s*0\\b`, "giu"), "$1 != FALSE");
|
|
873
|
+
out = out.replace(new RegExp(`${scoped}\\s*!=\\s*1\\b`, "giu"), "$1 != TRUE");
|
|
874
|
+
out = out.replace(new RegExp(`${scoped}\\s*<>\\s*0\\b`, "giu"), "$1 <> FALSE");
|
|
875
|
+
out = out.replace(new RegExp(`${scoped}\\s*<>\\s*1\\b`, "giu"), "$1 <> TRUE");
|
|
876
|
+
}
|
|
877
|
+
return out;
|
|
878
|
+
}
|
|
879
|
+
function rewriteInsertOrIgnore(sql) {
|
|
880
|
+
if (!/^\s*INSERT\s+OR\s+IGNORE\s+INTO\b/iu.test(sql)) {
|
|
881
|
+
return sql;
|
|
882
|
+
}
|
|
883
|
+
const replaced = sql.replace(/^\s*INSERT\s+OR\s+IGNORE\s+INTO\b/iu, "INSERT INTO");
|
|
884
|
+
return /\bON\s+CONFLICT\b/iu.test(replaced) ? replaced : appendClause(replaced, " ON CONFLICT DO NOTHING");
|
|
885
|
+
}
|
|
886
|
+
function rewriteInsertOrReplace(sql) {
|
|
887
|
+
const match = /^\s*INSERT\s+OR\s+REPLACE\s+INTO\s+([A-Za-z0-9_."]+)\s*\(([^)]+)\)([\s\S]*)$/iu.exec(sql);
|
|
888
|
+
if (!match) {
|
|
889
|
+
return sql;
|
|
890
|
+
}
|
|
891
|
+
const rawTable = match[1];
|
|
892
|
+
const rawColumns = match[2];
|
|
893
|
+
const remainder = match[3];
|
|
894
|
+
const tableName = unqualifiedTableName(rawTable);
|
|
895
|
+
const conflictKeys = UPSERT_KEYS[tableName];
|
|
896
|
+
if (!conflictKeys?.length) {
|
|
897
|
+
return sql;
|
|
898
|
+
}
|
|
899
|
+
const columns = rawColumns.split(",").map((col) => col.trim().replace(/^"|"$/g, ""));
|
|
900
|
+
const updateColumns = columns.filter((col) => !conflictKeys.includes(col));
|
|
901
|
+
const conflictTarget = conflictKeys.map(quotedIdentifier).join(", ");
|
|
902
|
+
const updateClause = updateColumns.length === 0 ? " DO NOTHING" : ` DO UPDATE SET ${updateColumns.map((col) => `${quotedIdentifier(col)} = EXCLUDED.${quotedIdentifier(col)}`).join(", ")}`;
|
|
903
|
+
return `INSERT INTO ${rawTable} (${rawColumns})${appendClause(remainder, ` ON CONFLICT (${conflictTarget})${updateClause}`)}`;
|
|
904
|
+
}
|
|
905
|
+
function rewriteSql(sql) {
|
|
906
|
+
let out = sql;
|
|
907
|
+
out = out.replace(/\bdatetime\(\s*['"]now['"]\s*\)/giu, "CURRENT_TIMESTAMP");
|
|
908
|
+
out = out.replace(/\bvector32\s*\(\s*\?\s*\)/giu, "?");
|
|
909
|
+
out = rewriteBooleanLiterals(out);
|
|
910
|
+
out = rewriteInsertOrReplace(out);
|
|
911
|
+
out = rewriteInsertOrIgnore(out);
|
|
912
|
+
return stripTrailingSemicolon(out);
|
|
913
|
+
}
|
|
914
|
+
function toBoolean(value) {
|
|
915
|
+
if (value === null || value === void 0) return value;
|
|
916
|
+
if (typeof value === "boolean") return value;
|
|
917
|
+
if (typeof value === "number") return value !== 0;
|
|
918
|
+
if (typeof value === "bigint") return value !== 0n;
|
|
919
|
+
if (typeof value === "string") {
|
|
920
|
+
const normalized = value.trim().toLowerCase();
|
|
921
|
+
if (normalized === "0" || normalized === "false") return false;
|
|
922
|
+
if (normalized === "1" || normalized === "true") return true;
|
|
923
|
+
}
|
|
924
|
+
return Boolean(value);
|
|
925
|
+
}
|
|
926
|
+
function countQuestionMarks(sql, end) {
|
|
927
|
+
let count = 0;
|
|
928
|
+
let inSingle = false;
|
|
929
|
+
let inDouble = false;
|
|
930
|
+
let inLineComment = false;
|
|
931
|
+
let inBlockComment = false;
|
|
932
|
+
for (let i = 0; i < end; i++) {
|
|
933
|
+
const ch = sql[i];
|
|
934
|
+
const next = sql[i + 1];
|
|
935
|
+
if (inLineComment) {
|
|
936
|
+
if (ch === "\n") inLineComment = false;
|
|
937
|
+
continue;
|
|
938
|
+
}
|
|
939
|
+
if (inBlockComment) {
|
|
940
|
+
if (ch === "*" && next === "/") {
|
|
941
|
+
inBlockComment = false;
|
|
942
|
+
i += 1;
|
|
943
|
+
}
|
|
944
|
+
continue;
|
|
945
|
+
}
|
|
946
|
+
if (!inSingle && !inDouble && ch === "-" && next === "-") {
|
|
947
|
+
inLineComment = true;
|
|
948
|
+
i += 1;
|
|
949
|
+
continue;
|
|
950
|
+
}
|
|
951
|
+
if (!inSingle && !inDouble && ch === "/" && next === "*") {
|
|
952
|
+
inBlockComment = true;
|
|
953
|
+
i += 1;
|
|
954
|
+
continue;
|
|
955
|
+
}
|
|
956
|
+
if (!inDouble && ch === "'" && sql[i - 1] !== "\\") {
|
|
957
|
+
inSingle = !inSingle;
|
|
958
|
+
continue;
|
|
959
|
+
}
|
|
960
|
+
if (!inSingle && ch === '"' && sql[i - 1] !== "\\") {
|
|
961
|
+
inDouble = !inDouble;
|
|
962
|
+
continue;
|
|
963
|
+
}
|
|
964
|
+
if (!inSingle && !inDouble && ch === "?") {
|
|
965
|
+
count += 1;
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
return count;
|
|
969
|
+
}
|
|
970
|
+
function findBooleanPlaceholderIndexes(sql) {
|
|
971
|
+
const indexes = /* @__PURE__ */ new Set();
|
|
972
|
+
for (const column of BOOLEAN_COLUMN_NAMES) {
|
|
973
|
+
const pattern = new RegExp(`(?:\\b[a-z_][a-z0-9_]*\\.)?${column}\\s*=\\s*\\?`, "giu");
|
|
974
|
+
for (const match of sql.matchAll(pattern)) {
|
|
975
|
+
const matchText = match[0];
|
|
976
|
+
const qIndex = match.index + matchText.lastIndexOf("?");
|
|
977
|
+
indexes.add(countQuestionMarks(sql, qIndex + 1));
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
return indexes;
|
|
981
|
+
}
|
|
982
|
+
function coerceInsertBooleanArgs(sql, args) {
|
|
983
|
+
const match = /^\s*INSERT(?:\s+OR\s+(?:IGNORE|REPLACE))?\s+INTO\s+([A-Za-z0-9_."]+)\s*\(([^)]+)\)/iu.exec(sql);
|
|
984
|
+
if (!match) return;
|
|
985
|
+
const rawTable = match[1];
|
|
986
|
+
const rawColumns = match[2];
|
|
987
|
+
const boolColumns = BOOLEAN_COLUMNS_BY_TABLE[unqualifiedTableName(rawTable)];
|
|
988
|
+
if (!boolColumns?.size) return;
|
|
989
|
+
const columns = rawColumns.split(",").map((col) => col.trim().replace(/^"|"$/g, ""));
|
|
990
|
+
for (const [index, column] of columns.entries()) {
|
|
991
|
+
if (boolColumns.has(column) && index < args.length) {
|
|
992
|
+
args[index] = toBoolean(args[index]);
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
function coerceUpdateBooleanArgs(sql, args) {
|
|
997
|
+
const match = /^\s*UPDATE\s+([A-Za-z0-9_."]+)\s+SET\s+([\s\S]+?)(?:\s+WHERE\b|$)/iu.exec(sql);
|
|
998
|
+
if (!match) return;
|
|
999
|
+
const rawTable = match[1];
|
|
1000
|
+
const setClause = match[2];
|
|
1001
|
+
const boolColumns = BOOLEAN_COLUMNS_BY_TABLE[unqualifiedTableName(rawTable)];
|
|
1002
|
+
if (!boolColumns?.size) return;
|
|
1003
|
+
const assignments = setClause.split(",");
|
|
1004
|
+
let placeholderIndex = 0;
|
|
1005
|
+
for (const assignment of assignments) {
|
|
1006
|
+
if (!assignment.includes("?")) continue;
|
|
1007
|
+
placeholderIndex += 1;
|
|
1008
|
+
const colMatch = /^\s*(?:[A-Za-z_][A-Za-z0-9_]*\.)?([A-Za-z_][A-Za-z0-9_]*)\s*=\s*\?/iu.exec(assignment);
|
|
1009
|
+
if (colMatch && boolColumns.has(colMatch[1])) {
|
|
1010
|
+
args[placeholderIndex - 1] = toBoolean(args[placeholderIndex - 1]);
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
function coerceBooleanArgs(sql, args) {
|
|
1015
|
+
const nextArgs = [...args];
|
|
1016
|
+
coerceInsertBooleanArgs(sql, nextArgs);
|
|
1017
|
+
coerceUpdateBooleanArgs(sql, nextArgs);
|
|
1018
|
+
const placeholderIndexes = findBooleanPlaceholderIndexes(sql);
|
|
1019
|
+
for (const index of placeholderIndexes) {
|
|
1020
|
+
if (index > 0 && index <= nextArgs.length) {
|
|
1021
|
+
nextArgs[index - 1] = toBoolean(nextArgs[index - 1]);
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
return nextArgs;
|
|
1025
|
+
}
|
|
1026
|
+
function convertQuestionMarksToDollarParams(sql) {
|
|
1027
|
+
let out = "";
|
|
1028
|
+
let placeholder = 0;
|
|
1029
|
+
let inSingle = false;
|
|
1030
|
+
let inDouble = false;
|
|
1031
|
+
let inLineComment = false;
|
|
1032
|
+
let inBlockComment = false;
|
|
1033
|
+
for (let i = 0; i < sql.length; i++) {
|
|
1034
|
+
const ch = sql[i];
|
|
1035
|
+
const next = sql[i + 1];
|
|
1036
|
+
if (inLineComment) {
|
|
1037
|
+
out += ch;
|
|
1038
|
+
if (ch === "\n") inLineComment = false;
|
|
1039
|
+
continue;
|
|
1040
|
+
}
|
|
1041
|
+
if (inBlockComment) {
|
|
1042
|
+
out += ch;
|
|
1043
|
+
if (ch === "*" && next === "/") {
|
|
1044
|
+
out += next;
|
|
1045
|
+
inBlockComment = false;
|
|
1046
|
+
i += 1;
|
|
1047
|
+
}
|
|
1048
|
+
continue;
|
|
1049
|
+
}
|
|
1050
|
+
if (!inSingle && !inDouble && ch === "-" && next === "-") {
|
|
1051
|
+
out += ch + next;
|
|
1052
|
+
inLineComment = true;
|
|
1053
|
+
i += 1;
|
|
1054
|
+
continue;
|
|
1055
|
+
}
|
|
1056
|
+
if (!inSingle && !inDouble && ch === "/" && next === "*") {
|
|
1057
|
+
out += ch + next;
|
|
1058
|
+
inBlockComment = true;
|
|
1059
|
+
i += 1;
|
|
1060
|
+
continue;
|
|
1061
|
+
}
|
|
1062
|
+
if (!inDouble && ch === "'" && sql[i - 1] !== "\\") {
|
|
1063
|
+
inSingle = !inSingle;
|
|
1064
|
+
out += ch;
|
|
1065
|
+
continue;
|
|
1066
|
+
}
|
|
1067
|
+
if (!inSingle && ch === '"' && sql[i - 1] !== "\\") {
|
|
1068
|
+
inDouble = !inDouble;
|
|
1069
|
+
out += ch;
|
|
1070
|
+
continue;
|
|
1071
|
+
}
|
|
1072
|
+
if (!inSingle && !inDouble && ch === "?") {
|
|
1073
|
+
placeholder += 1;
|
|
1074
|
+
out += `$${placeholder}`;
|
|
1075
|
+
continue;
|
|
1076
|
+
}
|
|
1077
|
+
out += ch;
|
|
1078
|
+
}
|
|
1079
|
+
return out;
|
|
1080
|
+
}
|
|
1081
|
+
function translateStatementForPostgres(stmt) {
|
|
1082
|
+
const normalized = normalizeStatement(stmt);
|
|
1083
|
+
if (normalized.kind === "named") {
|
|
1084
|
+
throw new Error("Named SQL parameters are not supported by the Prisma adapter.");
|
|
1085
|
+
}
|
|
1086
|
+
const rewrittenSql = rewriteSql(normalized.sql);
|
|
1087
|
+
const coercedArgs = coerceBooleanArgs(rewrittenSql, normalized.args);
|
|
1088
|
+
return {
|
|
1089
|
+
sql: convertQuestionMarksToDollarParams(rewrittenSql),
|
|
1090
|
+
args: coercedArgs
|
|
1091
|
+
};
|
|
1092
|
+
}
|
|
1093
|
+
function shouldBypassPostgres(stmt) {
|
|
1094
|
+
const normalized = normalizeStatement(stmt);
|
|
1095
|
+
if (normalized.kind === "named") {
|
|
1096
|
+
return true;
|
|
1097
|
+
}
|
|
1098
|
+
return IMMEDIATE_FALLBACK_PATTERNS.some((pattern) => pattern.test(normalized.sql));
|
|
1099
|
+
}
|
|
1100
|
+
function shouldFallbackOnError(error) {
|
|
1101
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1102
|
+
return /42P01|42883|42601|does not exist|syntax error|not supported|Named SQL parameters are not supported/iu.test(message);
|
|
1103
|
+
}
|
|
1104
|
+
function isReadQuery(sql) {
|
|
1105
|
+
const trimmed = sql.trimStart();
|
|
1106
|
+
return /^(SELECT|WITH|SHOW|EXPLAIN|VALUES)\b/iu.test(trimmed) || /\bRETURNING\b/iu.test(trimmed);
|
|
1107
|
+
}
|
|
1108
|
+
function buildRow(row, columns) {
|
|
1109
|
+
const values = columns.map((column) => row[column]);
|
|
1110
|
+
return Object.assign(values, row);
|
|
1111
|
+
}
|
|
1112
|
+
function buildResultSet(rows, rowsAffected = 0) {
|
|
1113
|
+
const columns = rows[0] ? Object.keys(rows[0]) : [];
|
|
1114
|
+
const resultRows = rows.map((row) => buildRow(row, columns));
|
|
1115
|
+
return {
|
|
1116
|
+
columns,
|
|
1117
|
+
columnTypes: columns.map(() => ""),
|
|
1118
|
+
rows: resultRows,
|
|
1119
|
+
rowsAffected,
|
|
1120
|
+
lastInsertRowid: void 0,
|
|
1121
|
+
toJSON() {
|
|
1122
|
+
return {
|
|
1123
|
+
columns,
|
|
1124
|
+
columnTypes: columns.map(() => ""),
|
|
1125
|
+
rows,
|
|
1126
|
+
rowsAffected,
|
|
1127
|
+
lastInsertRowid: void 0
|
|
1128
|
+
};
|
|
1129
|
+
}
|
|
1130
|
+
};
|
|
1131
|
+
}
|
|
1132
|
+
async function loadPrismaClient() {
|
|
1133
|
+
if (!prismaClientPromise) {
|
|
1134
|
+
prismaClientPromise = (async () => {
|
|
1135
|
+
const explicitPath = process.env.EXE_OS_PRISMA_CLIENT_PATH;
|
|
1136
|
+
if (explicitPath) {
|
|
1137
|
+
const module2 = await import(pathToFileURL(explicitPath).href);
|
|
1138
|
+
const PrismaClient2 = module2.PrismaClient ?? module2.default?.PrismaClient;
|
|
1139
|
+
if (!PrismaClient2) {
|
|
1140
|
+
throw new Error(`No PrismaClient export found at ${explicitPath}`);
|
|
1141
|
+
}
|
|
1142
|
+
return new PrismaClient2();
|
|
1143
|
+
}
|
|
1144
|
+
const exeDbRoot = process.env.EXE_DB_ROOT ?? path7.join(os6.homedir(), "exe-db");
|
|
1145
|
+
const requireFromExeDb = createRequire(path7.join(exeDbRoot, "package.json"));
|
|
1146
|
+
const prismaEntry = requireFromExeDb.resolve("@prisma/client");
|
|
1147
|
+
const module = await import(pathToFileURL(prismaEntry).href);
|
|
1148
|
+
const PrismaClient = module.PrismaClient ?? module.default?.PrismaClient;
|
|
1149
|
+
if (!PrismaClient) {
|
|
1150
|
+
throw new Error(`No PrismaClient export found in ${prismaEntry}`);
|
|
1151
|
+
}
|
|
1152
|
+
return new PrismaClient();
|
|
1153
|
+
})();
|
|
1154
|
+
}
|
|
1155
|
+
return prismaClientPromise;
|
|
1156
|
+
}
|
|
1157
|
+
async function ensureCompatibilityViews(prisma) {
|
|
1158
|
+
if (!compatibilityBootstrapPromise) {
|
|
1159
|
+
compatibilityBootstrapPromise = (async () => {
|
|
1160
|
+
for (const mapping of VIEW_MAPPINGS) {
|
|
1161
|
+
const relation = mapping.source.replace(/"/g, "");
|
|
1162
|
+
const rows = await prisma.$queryRawUnsafe(
|
|
1163
|
+
"SELECT to_regclass($1) AS regclass",
|
|
1164
|
+
relation
|
|
1165
|
+
);
|
|
1166
|
+
if (!rows[0]?.regclass) {
|
|
1167
|
+
continue;
|
|
1168
|
+
}
|
|
1169
|
+
await prisma.$executeRawUnsafe(
|
|
1170
|
+
`CREATE OR REPLACE VIEW public.${quotedIdentifier(mapping.view)} AS SELECT * FROM ${mapping.source}`
|
|
1171
|
+
);
|
|
1172
|
+
}
|
|
1173
|
+
})();
|
|
1174
|
+
}
|
|
1175
|
+
return compatibilityBootstrapPromise;
|
|
1176
|
+
}
|
|
1177
|
+
async function executeOnPrisma(executor, stmt) {
|
|
1178
|
+
const translated = translateStatementForPostgres(stmt);
|
|
1179
|
+
if (isReadQuery(translated.sql)) {
|
|
1180
|
+
const rows = await executor.$queryRawUnsafe(
|
|
1181
|
+
translated.sql,
|
|
1182
|
+
...translated.args
|
|
1183
|
+
);
|
|
1184
|
+
return buildResultSet(rows, /\bRETURNING\b/iu.test(translated.sql) ? rows.length : 0);
|
|
1185
|
+
}
|
|
1186
|
+
const rowsAffected = await executor.$executeRawUnsafe(translated.sql, ...translated.args);
|
|
1187
|
+
return buildResultSet([], rowsAffected);
|
|
1188
|
+
}
|
|
1189
|
+
function splitSqlStatements(sql) {
|
|
1190
|
+
const parts = [];
|
|
1191
|
+
let current = "";
|
|
1192
|
+
let inSingle = false;
|
|
1193
|
+
let inDouble = false;
|
|
1194
|
+
let inLineComment = false;
|
|
1195
|
+
let inBlockComment = false;
|
|
1196
|
+
for (let i = 0; i < sql.length; i++) {
|
|
1197
|
+
const ch = sql[i];
|
|
1198
|
+
const next = sql[i + 1];
|
|
1199
|
+
if (inLineComment) {
|
|
1200
|
+
current += ch;
|
|
1201
|
+
if (ch === "\n") inLineComment = false;
|
|
1202
|
+
continue;
|
|
1203
|
+
}
|
|
1204
|
+
if (inBlockComment) {
|
|
1205
|
+
current += ch;
|
|
1206
|
+
if (ch === "*" && next === "/") {
|
|
1207
|
+
current += next;
|
|
1208
|
+
inBlockComment = false;
|
|
1209
|
+
i += 1;
|
|
1210
|
+
}
|
|
1211
|
+
continue;
|
|
1212
|
+
}
|
|
1213
|
+
if (!inSingle && !inDouble && ch === "-" && next === "-") {
|
|
1214
|
+
current += ch + next;
|
|
1215
|
+
inLineComment = true;
|
|
1216
|
+
i += 1;
|
|
1217
|
+
continue;
|
|
1218
|
+
}
|
|
1219
|
+
if (!inSingle && !inDouble && ch === "/" && next === "*") {
|
|
1220
|
+
current += ch + next;
|
|
1221
|
+
inBlockComment = true;
|
|
1222
|
+
i += 1;
|
|
1223
|
+
continue;
|
|
1224
|
+
}
|
|
1225
|
+
if (!inDouble && ch === "'" && sql[i - 1] !== "\\") {
|
|
1226
|
+
inSingle = !inSingle;
|
|
1227
|
+
current += ch;
|
|
1228
|
+
continue;
|
|
1229
|
+
}
|
|
1230
|
+
if (!inSingle && ch === '"' && sql[i - 1] !== "\\") {
|
|
1231
|
+
inDouble = !inDouble;
|
|
1232
|
+
current += ch;
|
|
1233
|
+
continue;
|
|
1234
|
+
}
|
|
1235
|
+
if (!inSingle && !inDouble && ch === ";") {
|
|
1236
|
+
if (current.trim()) {
|
|
1237
|
+
parts.push(current.trim());
|
|
1238
|
+
}
|
|
1239
|
+
current = "";
|
|
1240
|
+
continue;
|
|
1241
|
+
}
|
|
1242
|
+
current += ch;
|
|
1243
|
+
}
|
|
1244
|
+
if (current.trim()) {
|
|
1245
|
+
parts.push(current.trim());
|
|
1246
|
+
}
|
|
1247
|
+
return parts;
|
|
1248
|
+
}
|
|
1249
|
+
async function createPrismaDbAdapter(fallbackClient) {
|
|
1250
|
+
const prisma = await loadPrismaClient();
|
|
1251
|
+
await ensureCompatibilityViews(prisma);
|
|
1252
|
+
let closed = false;
|
|
1253
|
+
let adapter;
|
|
1254
|
+
const fallbackExecute = async (stmt, error) => {
|
|
1255
|
+
if (!fallbackClient) {
|
|
1256
|
+
if (error) throw error;
|
|
1257
|
+
throw new Error("No fallback SQLite client is available for this Prisma-routed query.");
|
|
1258
|
+
}
|
|
1259
|
+
if (error) {
|
|
1260
|
+
process.stderr.write(
|
|
1261
|
+
`[database-adapter] Falling back to SQLite: ${error instanceof Error ? error.message : String(error)}
|
|
1262
|
+
`
|
|
1263
|
+
);
|
|
1264
|
+
}
|
|
1265
|
+
return fallbackClient.execute(stmt);
|
|
1266
|
+
};
|
|
1267
|
+
adapter = {
|
|
1268
|
+
async execute(stmt) {
|
|
1269
|
+
if (shouldBypassPostgres(stmt)) {
|
|
1270
|
+
return fallbackExecute(stmt);
|
|
1271
|
+
}
|
|
1272
|
+
try {
|
|
1273
|
+
return await executeOnPrisma(prisma, stmt);
|
|
1274
|
+
} catch (error) {
|
|
1275
|
+
if (shouldFallbackOnError(error)) {
|
|
1276
|
+
return fallbackExecute(stmt, error);
|
|
1277
|
+
}
|
|
1278
|
+
throw error;
|
|
1279
|
+
}
|
|
1280
|
+
},
|
|
1281
|
+
async batch(stmts, mode) {
|
|
1282
|
+
if (stmts.some((stmt) => shouldBypassPostgres(stmt))) {
|
|
1283
|
+
if (!fallbackClient) {
|
|
1284
|
+
throw new Error("Cannot batch unsupported SQLite-only statements without a fallback client.");
|
|
1285
|
+
}
|
|
1286
|
+
return fallbackClient.batch(stmts, mode);
|
|
1287
|
+
}
|
|
1288
|
+
try {
|
|
1289
|
+
if (prisma.$transaction) {
|
|
1290
|
+
return await prisma.$transaction(async (tx) => {
|
|
1291
|
+
const results2 = [];
|
|
1292
|
+
for (const stmt of stmts) {
|
|
1293
|
+
results2.push(await executeOnPrisma(tx, stmt));
|
|
1294
|
+
}
|
|
1295
|
+
return results2;
|
|
1296
|
+
});
|
|
1297
|
+
}
|
|
1298
|
+
const results = [];
|
|
1299
|
+
for (const stmt of stmts) {
|
|
1300
|
+
results.push(await executeOnPrisma(prisma, stmt));
|
|
1301
|
+
}
|
|
1302
|
+
return results;
|
|
1303
|
+
} catch (error) {
|
|
1304
|
+
if (fallbackClient && shouldFallbackOnError(error)) {
|
|
1305
|
+
process.stderr.write(
|
|
1306
|
+
`[database-adapter] Falling back batch to SQLite: ${error instanceof Error ? error.message : String(error)}
|
|
1307
|
+
`
|
|
1308
|
+
);
|
|
1309
|
+
return fallbackClient.batch(stmts, mode);
|
|
1310
|
+
}
|
|
1311
|
+
throw error;
|
|
1312
|
+
}
|
|
1313
|
+
},
|
|
1314
|
+
async migrate(stmts) {
|
|
1315
|
+
if (fallbackClient) {
|
|
1316
|
+
return fallbackClient.migrate(stmts);
|
|
1317
|
+
}
|
|
1318
|
+
return adapter.batch(stmts, "deferred");
|
|
1319
|
+
},
|
|
1320
|
+
async transaction(mode) {
|
|
1321
|
+
if (!fallbackClient) {
|
|
1322
|
+
throw new Error("Interactive transactions are only supported on the SQLite fallback client.");
|
|
1323
|
+
}
|
|
1324
|
+
return fallbackClient.transaction(mode);
|
|
1325
|
+
},
|
|
1326
|
+
async executeMultiple(sql) {
|
|
1327
|
+
if (fallbackClient && shouldBypassPostgres(sql)) {
|
|
1328
|
+
return fallbackClient.executeMultiple(sql);
|
|
1329
|
+
}
|
|
1330
|
+
for (const statement of splitSqlStatements(sql)) {
|
|
1331
|
+
await adapter.execute(statement);
|
|
1332
|
+
}
|
|
1333
|
+
},
|
|
1334
|
+
async sync() {
|
|
1335
|
+
if (fallbackClient) {
|
|
1336
|
+
return fallbackClient.sync();
|
|
1337
|
+
}
|
|
1338
|
+
return { frame_no: 0, frames_synced: 0 };
|
|
1339
|
+
},
|
|
1340
|
+
close() {
|
|
1341
|
+
closed = true;
|
|
1342
|
+
prismaClientPromise = null;
|
|
1343
|
+
compatibilityBootstrapPromise = null;
|
|
1344
|
+
void prisma.$disconnect?.();
|
|
1345
|
+
},
|
|
1346
|
+
get closed() {
|
|
1347
|
+
return closed;
|
|
1348
|
+
},
|
|
1349
|
+
get protocol() {
|
|
1350
|
+
return "prisma-postgres";
|
|
1351
|
+
}
|
|
1352
|
+
};
|
|
1353
|
+
return adapter;
|
|
1354
|
+
}
|
|
1355
|
+
var VIEW_MAPPINGS, UPSERT_KEYS, BOOLEAN_COLUMNS_BY_TABLE, BOOLEAN_COLUMN_NAMES, IMMEDIATE_FALLBACK_PATTERNS, prismaClientPromise, compatibilityBootstrapPromise;
|
|
1356
|
+
var init_database_adapter = __esm({
|
|
1357
|
+
"src/lib/database-adapter.ts"() {
|
|
1358
|
+
"use strict";
|
|
1359
|
+
VIEW_MAPPINGS = [
|
|
1360
|
+
{ view: "memories", source: "memory.memory_records" },
|
|
1361
|
+
{ view: "tasks", source: "memory.tasks" },
|
|
1362
|
+
{ view: "behaviors", source: "memory.behaviors" },
|
|
1363
|
+
{ view: "entities", source: "memory.entities" },
|
|
1364
|
+
{ view: "relationships", source: "memory.relationships" },
|
|
1365
|
+
{ view: "entity_memories", source: "memory.entity_memories" },
|
|
1366
|
+
{ view: "entity_aliases", source: "memory.entity_aliases" },
|
|
1367
|
+
{ view: "notifications", source: "memory.notifications" },
|
|
1368
|
+
{ view: "messages", source: "memory.messages" },
|
|
1369
|
+
{ view: "users", source: "wiki.users" },
|
|
1370
|
+
{ view: "workspaces", source: "wiki.workspaces" },
|
|
1371
|
+
{ view: "workspace_users", source: "wiki.workspace_users" },
|
|
1372
|
+
{ view: "documents", source: "wiki.workspace_documents" },
|
|
1373
|
+
{ view: "chats", source: "wiki.workspace_chats" }
|
|
1374
|
+
];
|
|
1375
|
+
UPSERT_KEYS = {
|
|
1376
|
+
memories: ["id"],
|
|
1377
|
+
tasks: ["id"],
|
|
1378
|
+
behaviors: ["id"],
|
|
1379
|
+
entities: ["id"],
|
|
1380
|
+
relationships: ["id"],
|
|
1381
|
+
entity_aliases: ["alias"],
|
|
1382
|
+
notifications: ["id"],
|
|
1383
|
+
messages: ["id"],
|
|
1384
|
+
users: ["id"],
|
|
1385
|
+
workspaces: ["id"],
|
|
1386
|
+
workspace_users: ["id"],
|
|
1387
|
+
documents: ["id"],
|
|
1388
|
+
chats: ["id"]
|
|
1389
|
+
};
|
|
1390
|
+
BOOLEAN_COLUMNS_BY_TABLE = {
|
|
1391
|
+
memories: /* @__PURE__ */ new Set(["has_error", "draft"]),
|
|
1392
|
+
behaviors: /* @__PURE__ */ new Set(["active"]),
|
|
1393
|
+
notifications: /* @__PURE__ */ new Set(["read"]),
|
|
1394
|
+
users: /* @__PURE__ */ new Set(["has_personal_memory"])
|
|
1395
|
+
};
|
|
1396
|
+
BOOLEAN_COLUMN_NAMES = new Set(
|
|
1397
|
+
Object.values(BOOLEAN_COLUMNS_BY_TABLE).flatMap((cols) => [...cols])
|
|
1398
|
+
);
|
|
1399
|
+
IMMEDIATE_FALLBACK_PATTERNS = [
|
|
1400
|
+
/\bPRAGMA\b/i,
|
|
1401
|
+
/\bsqlite_master\b/i,
|
|
1402
|
+
/(?:^|[.\s])(?:memories|conversations|entities)_fts\b/i,
|
|
1403
|
+
/\bMATCH\b/i,
|
|
1404
|
+
/\bvector_distance_cos\s*\(/i,
|
|
1405
|
+
/\bjson_extract\s*\(/i,
|
|
1406
|
+
/\bjulianday\s*\(/i,
|
|
1407
|
+
/\bstrftime\s*\(/i,
|
|
1408
|
+
/\blast_insert_rowid\s*\(/i
|
|
1409
|
+
];
|
|
1410
|
+
prismaClientPromise = null;
|
|
1411
|
+
compatibilityBootstrapPromise = null;
|
|
1412
|
+
}
|
|
1413
|
+
});
|
|
1414
|
+
|
|
830
1415
|
// src/lib/exe-daemon-client.ts
|
|
831
1416
|
import net from "net";
|
|
832
|
-
import
|
|
1417
|
+
import os7 from "os";
|
|
833
1418
|
import { spawn } from "child_process";
|
|
834
1419
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
835
1420
|
import { existsSync as existsSync6, unlinkSync as unlinkSync2, readFileSync as readFileSync6, openSync, closeSync, statSync } from "fs";
|
|
836
|
-
import
|
|
1421
|
+
import path8 from "path";
|
|
837
1422
|
import { fileURLToPath } from "url";
|
|
838
1423
|
function handleData(chunk) {
|
|
839
1424
|
_buffer += chunk.toString();
|
|
@@ -884,17 +1469,17 @@ function cleanupStaleFiles() {
|
|
|
884
1469
|
}
|
|
885
1470
|
}
|
|
886
1471
|
function findPackageRoot() {
|
|
887
|
-
let dir =
|
|
888
|
-
const { root } =
|
|
1472
|
+
let dir = path8.dirname(fileURLToPath(import.meta.url));
|
|
1473
|
+
const { root } = path8.parse(dir);
|
|
889
1474
|
while (dir !== root) {
|
|
890
|
-
if (existsSync6(
|
|
891
|
-
dir =
|
|
1475
|
+
if (existsSync6(path8.join(dir, "package.json"))) return dir;
|
|
1476
|
+
dir = path8.dirname(dir);
|
|
892
1477
|
}
|
|
893
1478
|
return null;
|
|
894
1479
|
}
|
|
895
1480
|
function spawnDaemon() {
|
|
896
|
-
const freeGB =
|
|
897
|
-
const totalGB =
|
|
1481
|
+
const freeGB = os7.freemem() / (1024 * 1024 * 1024);
|
|
1482
|
+
const totalGB = os7.totalmem() / (1024 * 1024 * 1024);
|
|
898
1483
|
if (totalGB <= 8) {
|
|
899
1484
|
process.stderr.write(
|
|
900
1485
|
`[exed-client] SKIP: ${totalGB.toFixed(0)}GB system \u2014 embedding daemon disabled. Using keyword search only. Minimum 16GB recommended for vector search.
|
|
@@ -914,7 +1499,7 @@ function spawnDaemon() {
|
|
|
914
1499
|
process.stderr.write("[exed-client] WARN: cannot find package root\n");
|
|
915
1500
|
return;
|
|
916
1501
|
}
|
|
917
|
-
const daemonPath =
|
|
1502
|
+
const daemonPath = path8.join(pkgRoot, "dist", "lib", "exe-daemon.js");
|
|
918
1503
|
if (!existsSync6(daemonPath)) {
|
|
919
1504
|
process.stderr.write(`[exed-client] WARN: daemon script not found at ${daemonPath}
|
|
920
1505
|
`);
|
|
@@ -923,7 +1508,7 @@ function spawnDaemon() {
|
|
|
923
1508
|
const resolvedPath = daemonPath;
|
|
924
1509
|
process.stderr.write(`[exed-client] Spawning daemon: ${resolvedPath}
|
|
925
1510
|
`);
|
|
926
|
-
const logPath =
|
|
1511
|
+
const logPath = path8.join(path8.dirname(SOCKET_PATH), "exed.log");
|
|
927
1512
|
let stderrFd = "ignore";
|
|
928
1513
|
try {
|
|
929
1514
|
stderrFd = openSync(logPath, "a");
|
|
@@ -1070,9 +1655,9 @@ var init_exe_daemon_client = __esm({
|
|
|
1070
1655
|
"src/lib/exe-daemon-client.ts"() {
|
|
1071
1656
|
"use strict";
|
|
1072
1657
|
init_config();
|
|
1073
|
-
SOCKET_PATH = process.env.EXE_DAEMON_SOCK ?? process.env.EXE_EMBED_SOCK ??
|
|
1074
|
-
PID_PATH = process.env.EXE_DAEMON_PID ?? process.env.EXE_EMBED_PID ??
|
|
1075
|
-
SPAWN_LOCK_PATH =
|
|
1658
|
+
SOCKET_PATH = process.env.EXE_DAEMON_SOCK ?? process.env.EXE_EMBED_SOCK ?? path8.join(EXE_AI_DIR, "exed.sock");
|
|
1659
|
+
PID_PATH = process.env.EXE_DAEMON_PID ?? process.env.EXE_EMBED_PID ?? path8.join(EXE_AI_DIR, "exed.pid");
|
|
1660
|
+
SPAWN_LOCK_PATH = path8.join(EXE_AI_DIR, "exed-spawn.lock");
|
|
1076
1661
|
SPAWN_LOCK_STALE_MS = 3e4;
|
|
1077
1662
|
CONNECT_TIMEOUT_MS = 15e3;
|
|
1078
1663
|
REQUEST_TIMEOUT_MS = 3e4;
|
|
@@ -1154,7 +1739,7 @@ __export(db_daemon_client_exports, {
|
|
|
1154
1739
|
createDaemonDbClient: () => createDaemonDbClient,
|
|
1155
1740
|
initDaemonDbClient: () => initDaemonDbClient
|
|
1156
1741
|
});
|
|
1157
|
-
function
|
|
1742
|
+
function normalizeStatement2(stmt) {
|
|
1158
1743
|
if (typeof stmt === "string") {
|
|
1159
1744
|
return { sql: stmt, args: [] };
|
|
1160
1745
|
}
|
|
@@ -1178,7 +1763,7 @@ function createDaemonDbClient(fallbackClient) {
|
|
|
1178
1763
|
if (!_useDaemon || !isClientConnected()) {
|
|
1179
1764
|
return fallbackClient.execute(stmt);
|
|
1180
1765
|
}
|
|
1181
|
-
const { sql, args } =
|
|
1766
|
+
const { sql, args } = normalizeStatement2(stmt);
|
|
1182
1767
|
const response = await sendDaemonRequest({
|
|
1183
1768
|
type: "db-execute",
|
|
1184
1769
|
sql,
|
|
@@ -1203,7 +1788,7 @@ function createDaemonDbClient(fallbackClient) {
|
|
|
1203
1788
|
if (!_useDaemon || !isClientConnected()) {
|
|
1204
1789
|
return fallbackClient.batch(stmts, mode);
|
|
1205
1790
|
}
|
|
1206
|
-
const statements = stmts.map(
|
|
1791
|
+
const statements = stmts.map(normalizeStatement2);
|
|
1207
1792
|
const response = await sendDaemonRequest({
|
|
1208
1793
|
type: "db-batch",
|
|
1209
1794
|
statements,
|
|
@@ -1298,6 +1883,18 @@ __export(database_exports, {
|
|
|
1298
1883
|
});
|
|
1299
1884
|
import { createClient } from "@libsql/client";
|
|
1300
1885
|
async function initDatabase(config) {
|
|
1886
|
+
if (_walCheckpointTimer) {
|
|
1887
|
+
clearInterval(_walCheckpointTimer);
|
|
1888
|
+
_walCheckpointTimer = null;
|
|
1889
|
+
}
|
|
1890
|
+
if (_daemonClient) {
|
|
1891
|
+
_daemonClient.close();
|
|
1892
|
+
_daemonClient = null;
|
|
1893
|
+
}
|
|
1894
|
+
if (_adapterClient && _adapterClient !== _resilientClient) {
|
|
1895
|
+
_adapterClient.close();
|
|
1896
|
+
}
|
|
1897
|
+
_adapterClient = null;
|
|
1301
1898
|
if (_client) {
|
|
1302
1899
|
_client.close();
|
|
1303
1900
|
_client = null;
|
|
@@ -1311,6 +1908,7 @@ async function initDatabase(config) {
|
|
|
1311
1908
|
}
|
|
1312
1909
|
_client = createClient(opts);
|
|
1313
1910
|
_resilientClient = wrapWithRetry(_client);
|
|
1911
|
+
_adapterClient = _resilientClient;
|
|
1314
1912
|
_client.execute("PRAGMA busy_timeout = 30000").catch(() => {
|
|
1315
1913
|
});
|
|
1316
1914
|
_client.execute("PRAGMA journal_mode = WAL").catch(() => {
|
|
@@ -1321,14 +1919,20 @@ async function initDatabase(config) {
|
|
|
1321
1919
|
});
|
|
1322
1920
|
}, 3e4);
|
|
1323
1921
|
_walCheckpointTimer.unref();
|
|
1922
|
+
if (process.env.DATABASE_URL) {
|
|
1923
|
+
_adapterClient = await createPrismaDbAdapter(_resilientClient);
|
|
1924
|
+
}
|
|
1324
1925
|
}
|
|
1325
1926
|
function isInitialized() {
|
|
1326
|
-
return _client !== null;
|
|
1927
|
+
return _adapterClient !== null || _client !== null;
|
|
1327
1928
|
}
|
|
1328
1929
|
function getClient() {
|
|
1329
|
-
if (!
|
|
1930
|
+
if (!_adapterClient) {
|
|
1330
1931
|
throw new Error("Database client not initialized. Call initDatabase() first.");
|
|
1331
1932
|
}
|
|
1933
|
+
if (process.env.DATABASE_URL) {
|
|
1934
|
+
return _adapterClient;
|
|
1935
|
+
}
|
|
1332
1936
|
if (process.env.EXE_IS_DAEMON === "1") {
|
|
1333
1937
|
return _resilientClient;
|
|
1334
1938
|
}
|
|
@@ -1338,6 +1942,7 @@ function getClient() {
|
|
|
1338
1942
|
return _resilientClient;
|
|
1339
1943
|
}
|
|
1340
1944
|
async function initDaemonClient() {
|
|
1945
|
+
if (process.env.DATABASE_URL) return;
|
|
1341
1946
|
if (process.env.EXE_IS_DAEMON === "1") return;
|
|
1342
1947
|
if (!_resilientClient) return;
|
|
1343
1948
|
try {
|
|
@@ -2282,26 +2887,36 @@ async function ensureSchema() {
|
|
|
2282
2887
|
}
|
|
2283
2888
|
}
|
|
2284
2889
|
async function disposeDatabase() {
|
|
2890
|
+
if (_walCheckpointTimer) {
|
|
2891
|
+
clearInterval(_walCheckpointTimer);
|
|
2892
|
+
_walCheckpointTimer = null;
|
|
2893
|
+
}
|
|
2285
2894
|
if (_daemonClient) {
|
|
2286
2895
|
_daemonClient.close();
|
|
2287
2896
|
_daemonClient = null;
|
|
2288
2897
|
}
|
|
2898
|
+
if (_adapterClient && _adapterClient !== _resilientClient) {
|
|
2899
|
+
_adapterClient.close();
|
|
2900
|
+
}
|
|
2901
|
+
_adapterClient = null;
|
|
2289
2902
|
if (_client) {
|
|
2290
2903
|
_client.close();
|
|
2291
2904
|
_client = null;
|
|
2292
2905
|
_resilientClient = null;
|
|
2293
2906
|
}
|
|
2294
2907
|
}
|
|
2295
|
-
var _client, _resilientClient, _walCheckpointTimer, _daemonClient, initTurso, disposeTurso;
|
|
2908
|
+
var _client, _resilientClient, _walCheckpointTimer, _daemonClient, _adapterClient, initTurso, disposeTurso;
|
|
2296
2909
|
var init_database = __esm({
|
|
2297
2910
|
"src/lib/database.ts"() {
|
|
2298
2911
|
"use strict";
|
|
2299
2912
|
init_db_retry();
|
|
2300
2913
|
init_employees();
|
|
2914
|
+
init_database_adapter();
|
|
2301
2915
|
_client = null;
|
|
2302
2916
|
_resilientClient = null;
|
|
2303
2917
|
_walCheckpointTimer = null;
|
|
2304
2918
|
_daemonClient = null;
|
|
2919
|
+
_adapterClient = null;
|
|
2305
2920
|
initTurso = initDatabase;
|
|
2306
2921
|
disposeTurso = disposeDatabase;
|
|
2307
2922
|
}
|
|
@@ -2310,16 +2925,16 @@ var init_database = __esm({
|
|
|
2310
2925
|
// src/lib/license.ts
|
|
2311
2926
|
import { readFileSync as readFileSync7, writeFileSync as writeFileSync5, existsSync as existsSync7, mkdirSync as mkdirSync4 } from "fs";
|
|
2312
2927
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
2313
|
-
import
|
|
2928
|
+
import path9 from "path";
|
|
2314
2929
|
import { jwtVerify, importSPKI } from "jose";
|
|
2315
2930
|
var LICENSE_PATH, CACHE_PATH, DEVICE_ID_PATH, PLAN_LIMITS;
|
|
2316
2931
|
var init_license = __esm({
|
|
2317
2932
|
"src/lib/license.ts"() {
|
|
2318
2933
|
"use strict";
|
|
2319
2934
|
init_config();
|
|
2320
|
-
LICENSE_PATH =
|
|
2321
|
-
CACHE_PATH =
|
|
2322
|
-
DEVICE_ID_PATH =
|
|
2935
|
+
LICENSE_PATH = path9.join(EXE_AI_DIR, "license.key");
|
|
2936
|
+
CACHE_PATH = path9.join(EXE_AI_DIR, "license-cache.json");
|
|
2937
|
+
DEVICE_ID_PATH = path9.join(EXE_AI_DIR, "device-id");
|
|
2323
2938
|
PLAN_LIMITS = {
|
|
2324
2939
|
free: { devices: 1, employees: 1, memories: 5e3 },
|
|
2325
2940
|
pro: { devices: 3, employees: 5, memories: 1e5 },
|
|
@@ -2332,7 +2947,7 @@ var init_license = __esm({
|
|
|
2332
2947
|
|
|
2333
2948
|
// src/lib/plan-limits.ts
|
|
2334
2949
|
import { readFileSync as readFileSync8, existsSync as existsSync8 } from "fs";
|
|
2335
|
-
import
|
|
2950
|
+
import path10 from "path";
|
|
2336
2951
|
function getLicenseSync() {
|
|
2337
2952
|
try {
|
|
2338
2953
|
if (!existsSync8(CACHE_PATH2)) return freeLicense();
|
|
@@ -2404,14 +3019,14 @@ var init_plan_limits = __esm({
|
|
|
2404
3019
|
this.name = "PlanLimitError";
|
|
2405
3020
|
}
|
|
2406
3021
|
};
|
|
2407
|
-
CACHE_PATH2 =
|
|
3022
|
+
CACHE_PATH2 = path10.join(EXE_AI_DIR, "license-cache.json");
|
|
2408
3023
|
}
|
|
2409
3024
|
});
|
|
2410
3025
|
|
|
2411
3026
|
// src/lib/notifications.ts
|
|
2412
3027
|
import crypto from "crypto";
|
|
2413
|
-
import
|
|
2414
|
-
import
|
|
3028
|
+
import path11 from "path";
|
|
3029
|
+
import os8 from "os";
|
|
2415
3030
|
import {
|
|
2416
3031
|
readFileSync as readFileSync9,
|
|
2417
3032
|
readdirSync,
|
|
@@ -2580,8 +3195,8 @@ var init_state_bus = __esm({
|
|
|
2580
3195
|
|
|
2581
3196
|
// src/lib/tasks-crud.ts
|
|
2582
3197
|
import crypto3 from "crypto";
|
|
2583
|
-
import
|
|
2584
|
-
import
|
|
3198
|
+
import path12 from "path";
|
|
3199
|
+
import os9 from "os";
|
|
2585
3200
|
import { execSync as execSync5 } from "child_process";
|
|
2586
3201
|
import { mkdir as mkdir3, writeFile as writeFile3, appendFile } from "fs/promises";
|
|
2587
3202
|
import { existsSync as existsSync10, readFileSync as readFileSync10 } from "fs";
|
|
@@ -2759,8 +3374,8 @@ ${laneWarning}` : laneWarning;
|
|
|
2759
3374
|
}
|
|
2760
3375
|
if (input.baseDir) {
|
|
2761
3376
|
try {
|
|
2762
|
-
await mkdir3(
|
|
2763
|
-
await mkdir3(
|
|
3377
|
+
await mkdir3(path12.join(input.baseDir, "exe", "output"), { recursive: true });
|
|
3378
|
+
await mkdir3(path12.join(input.baseDir, "exe", "research"), { recursive: true });
|
|
2764
3379
|
await ensureArchitectureDoc(input.baseDir, input.projectName);
|
|
2765
3380
|
await ensureGitignoreExe(input.baseDir);
|
|
2766
3381
|
} catch {
|
|
@@ -2796,9 +3411,9 @@ ${laneWarning}` : laneWarning;
|
|
|
2796
3411
|
});
|
|
2797
3412
|
if (input.baseDir) {
|
|
2798
3413
|
try {
|
|
2799
|
-
const EXE_OS_DIR =
|
|
2800
|
-
const mdPath =
|
|
2801
|
-
const mdDir =
|
|
3414
|
+
const EXE_OS_DIR = path12.join(os9.homedir(), ".exe-os");
|
|
3415
|
+
const mdPath = path12.join(EXE_OS_DIR, taskFile);
|
|
3416
|
+
const mdDir = path12.dirname(mdPath);
|
|
2802
3417
|
if (!existsSync10(mdDir)) await mkdir3(mdDir, { recursive: true });
|
|
2803
3418
|
const reviewer = input.reviewer ?? input.assignedBy;
|
|
2804
3419
|
const mdContent = `# ${input.title}
|
|
@@ -3099,7 +3714,7 @@ async function deleteTaskCore(taskId, _baseDir) {
|
|
|
3099
3714
|
return { taskFile, assignedTo, assignedBy, taskSlug };
|
|
3100
3715
|
}
|
|
3101
3716
|
async function ensureArchitectureDoc(baseDir, projectName) {
|
|
3102
|
-
const archPath =
|
|
3717
|
+
const archPath = path12.join(baseDir, "exe", "ARCHITECTURE.md");
|
|
3103
3718
|
try {
|
|
3104
3719
|
if (existsSync10(archPath)) return;
|
|
3105
3720
|
const template = [
|
|
@@ -3134,7 +3749,7 @@ async function ensureArchitectureDoc(baseDir, projectName) {
|
|
|
3134
3749
|
}
|
|
3135
3750
|
}
|
|
3136
3751
|
async function ensureGitignoreExe(baseDir) {
|
|
3137
|
-
const gitignorePath =
|
|
3752
|
+
const gitignorePath = path12.join(baseDir, ".gitignore");
|
|
3138
3753
|
try {
|
|
3139
3754
|
if (existsSync10(gitignorePath)) {
|
|
3140
3755
|
const content = readFileSync10(gitignorePath, "utf-8");
|
|
@@ -3168,13 +3783,13 @@ var init_tasks_crud = __esm({
|
|
|
3168
3783
|
});
|
|
3169
3784
|
|
|
3170
3785
|
// src/lib/tasks-review.ts
|
|
3171
|
-
import
|
|
3786
|
+
import path13 from "path";
|
|
3172
3787
|
import { existsSync as existsSync11, readdirSync as readdirSync2, unlinkSync as unlinkSync4 } from "fs";
|
|
3173
3788
|
async function countPendingReviews(sessionScope) {
|
|
3174
3789
|
const client = getClient();
|
|
3175
3790
|
if (sessionScope) {
|
|
3176
3791
|
const result2 = await client.execute({
|
|
3177
|
-
sql: "SELECT COUNT(*) as cnt FROM tasks WHERE status = 'needs_review' AND
|
|
3792
|
+
sql: "SELECT COUNT(*) as cnt FROM tasks WHERE status = 'needs_review' AND session_scope = ?",
|
|
3178
3793
|
args: [sessionScope]
|
|
3179
3794
|
});
|
|
3180
3795
|
return Number(result2.rows[0]?.cnt) || 0;
|
|
@@ -3350,11 +3965,11 @@ async function cleanupReviewFile(row, taskFile, _baseDir) {
|
|
|
3350
3965
|
);
|
|
3351
3966
|
}
|
|
3352
3967
|
try {
|
|
3353
|
-
const cacheDir =
|
|
3968
|
+
const cacheDir = path13.join(EXE_AI_DIR, "session-cache");
|
|
3354
3969
|
if (existsSync11(cacheDir)) {
|
|
3355
3970
|
for (const f of readdirSync2(cacheDir)) {
|
|
3356
3971
|
if (f.startsWith("review-notified-")) {
|
|
3357
|
-
unlinkSync4(
|
|
3972
|
+
unlinkSync4(path13.join(cacheDir, f));
|
|
3358
3973
|
}
|
|
3359
3974
|
}
|
|
3360
3975
|
}
|
|
@@ -3375,7 +3990,7 @@ var init_tasks_review = __esm({
|
|
|
3375
3990
|
});
|
|
3376
3991
|
|
|
3377
3992
|
// src/lib/tasks-chain.ts
|
|
3378
|
-
import
|
|
3993
|
+
import path14 from "path";
|
|
3379
3994
|
import { readFile as readFile3, writeFile as writeFile4 } from "fs/promises";
|
|
3380
3995
|
async function cascadeUnblock(taskId, baseDir, now) {
|
|
3381
3996
|
const client = getClient();
|
|
@@ -3392,7 +4007,7 @@ async function cascadeUnblock(taskId, baseDir, now) {
|
|
|
3392
4007
|
});
|
|
3393
4008
|
for (const ur of unblockedRows.rows) {
|
|
3394
4009
|
try {
|
|
3395
|
-
const ubFile =
|
|
4010
|
+
const ubFile = path14.join(baseDir, String(ur.task_file));
|
|
3396
4011
|
let ubContent = await readFile3(ubFile, "utf-8");
|
|
3397
4012
|
ubContent = ubContent.replace(/\*\*Status:\*\* blocked/, "**Status:** open");
|
|
3398
4013
|
ubContent = ubContent.replace(/\n\*\*Blocked by:\*\*.*\n/, "\n");
|
|
@@ -3461,7 +4076,7 @@ var init_tasks_chain = __esm({
|
|
|
3461
4076
|
|
|
3462
4077
|
// src/lib/project-name.ts
|
|
3463
4078
|
import { execSync as execSync6 } from "child_process";
|
|
3464
|
-
import
|
|
4079
|
+
import path15 from "path";
|
|
3465
4080
|
function getProjectName(cwd) {
|
|
3466
4081
|
const dir = cwd ?? process.cwd();
|
|
3467
4082
|
if (_cached2 && _cachedCwd === dir) return _cached2;
|
|
@@ -3474,7 +4089,7 @@ function getProjectName(cwd) {
|
|
|
3474
4089
|
timeout: 2e3,
|
|
3475
4090
|
stdio: ["pipe", "pipe", "pipe"]
|
|
3476
4091
|
}).trim();
|
|
3477
|
-
repoRoot =
|
|
4092
|
+
repoRoot = path15.dirname(gitCommonDir);
|
|
3478
4093
|
} catch {
|
|
3479
4094
|
repoRoot = execSync6("git rev-parse --show-toplevel", {
|
|
3480
4095
|
cwd: dir,
|
|
@@ -3483,11 +4098,11 @@ function getProjectName(cwd) {
|
|
|
3483
4098
|
stdio: ["pipe", "pipe", "pipe"]
|
|
3484
4099
|
}).trim();
|
|
3485
4100
|
}
|
|
3486
|
-
_cached2 =
|
|
4101
|
+
_cached2 = path15.basename(repoRoot);
|
|
3487
4102
|
_cachedCwd = dir;
|
|
3488
4103
|
return _cached2;
|
|
3489
4104
|
} catch {
|
|
3490
|
-
_cached2 =
|
|
4105
|
+
_cached2 = path15.basename(dir);
|
|
3491
4106
|
_cachedCwd = dir;
|
|
3492
4107
|
return _cached2;
|
|
3493
4108
|
}
|
|
@@ -4022,7 +4637,7 @@ __export(tasks_exports, {
|
|
|
4022
4637
|
updateTaskStatus: () => updateTaskStatus,
|
|
4023
4638
|
writeCheckpoint: () => writeCheckpoint
|
|
4024
4639
|
});
|
|
4025
|
-
import
|
|
4640
|
+
import path16 from "path";
|
|
4026
4641
|
import { writeFileSync as writeFileSync6, mkdirSync as mkdirSync5, unlinkSync as unlinkSync5 } from "fs";
|
|
4027
4642
|
async function createTask(input) {
|
|
4028
4643
|
const result = await createTaskCore(input);
|
|
@@ -4042,8 +4657,8 @@ async function updateTask(input) {
|
|
|
4042
4657
|
const { row, taskFile, now, taskId } = await updateTaskStatus(input);
|
|
4043
4658
|
try {
|
|
4044
4659
|
const agent = String(row.assigned_to);
|
|
4045
|
-
const cacheDir =
|
|
4046
|
-
const cachePath =
|
|
4660
|
+
const cacheDir = path16.join(EXE_AI_DIR, "session-cache");
|
|
4661
|
+
const cachePath = path16.join(cacheDir, `current-task-${agent}.json`);
|
|
4047
4662
|
if (input.status === "in_progress") {
|
|
4048
4663
|
mkdirSync5(cacheDir, { recursive: true });
|
|
4049
4664
|
writeFileSync6(cachePath, JSON.stringify({ taskId, title: String(row.title) }));
|
|
@@ -4514,12 +5129,12 @@ __export(tmux_routing_exports, {
|
|
|
4514
5129
|
});
|
|
4515
5130
|
import { execFileSync as execFileSync2, execSync as execSync7 } from "child_process";
|
|
4516
5131
|
import { readFileSync as readFileSync11, writeFileSync as writeFileSync7, mkdirSync as mkdirSync6, existsSync as existsSync12, appendFileSync, readdirSync as readdirSync3 } from "fs";
|
|
4517
|
-
import
|
|
4518
|
-
import
|
|
5132
|
+
import path17 from "path";
|
|
5133
|
+
import os10 from "os";
|
|
4519
5134
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
4520
5135
|
import { unlinkSync as unlinkSync6 } from "fs";
|
|
4521
5136
|
function spawnLockPath(sessionName) {
|
|
4522
|
-
return
|
|
5137
|
+
return path17.join(SPAWN_LOCK_DIR, `${sessionName}.lock`);
|
|
4523
5138
|
}
|
|
4524
5139
|
function isProcessAlive(pid) {
|
|
4525
5140
|
try {
|
|
@@ -4556,8 +5171,8 @@ function releaseSpawnLock2(sessionName) {
|
|
|
4556
5171
|
function resolveBehaviorsExporterScript() {
|
|
4557
5172
|
try {
|
|
4558
5173
|
const thisFile = fileURLToPath2(import.meta.url);
|
|
4559
|
-
const scriptPath =
|
|
4560
|
-
|
|
5174
|
+
const scriptPath = path17.join(
|
|
5175
|
+
path17.dirname(thisFile),
|
|
4561
5176
|
"..",
|
|
4562
5177
|
"bin",
|
|
4563
5178
|
"exe-export-behaviors.js"
|
|
@@ -4632,7 +5247,7 @@ function registerParentExe(sessionKey, parentExe, dispatchedBy) {
|
|
|
4632
5247
|
mkdirSync6(SESSION_CACHE, { recursive: true });
|
|
4633
5248
|
}
|
|
4634
5249
|
const rootExe = extractRootExe(parentExe) ?? parentExe;
|
|
4635
|
-
const filePath =
|
|
5250
|
+
const filePath = path17.join(SESSION_CACHE, `parent-exe-${sessionKey}.json`);
|
|
4636
5251
|
writeFileSync7(filePath, JSON.stringify({
|
|
4637
5252
|
parentExe: rootExe,
|
|
4638
5253
|
dispatchedBy: dispatchedBy || rootExe,
|
|
@@ -4641,7 +5256,7 @@ function registerParentExe(sessionKey, parentExe, dispatchedBy) {
|
|
|
4641
5256
|
}
|
|
4642
5257
|
function getParentExe(sessionKey) {
|
|
4643
5258
|
try {
|
|
4644
|
-
const data = JSON.parse(readFileSync11(
|
|
5259
|
+
const data = JSON.parse(readFileSync11(path17.join(SESSION_CACHE, `parent-exe-${sessionKey}.json`), "utf8"));
|
|
4645
5260
|
return data.parentExe || null;
|
|
4646
5261
|
} catch {
|
|
4647
5262
|
return null;
|
|
@@ -4650,7 +5265,7 @@ function getParentExe(sessionKey) {
|
|
|
4650
5265
|
function getDispatchedBy(sessionKey) {
|
|
4651
5266
|
try {
|
|
4652
5267
|
const data = JSON.parse(readFileSync11(
|
|
4653
|
-
|
|
5268
|
+
path17.join(SESSION_CACHE, `parent-exe-${sessionKey}.json`),
|
|
4654
5269
|
"utf8"
|
|
4655
5270
|
));
|
|
4656
5271
|
return data.dispatchedBy ?? data.parentExe ?? null;
|
|
@@ -4836,7 +5451,7 @@ function sendIntercom(targetSession) {
|
|
|
4836
5451
|
try {
|
|
4837
5452
|
const rawAgent = targetSession.split("-")[0] ?? targetSession;
|
|
4838
5453
|
const agent = baseAgentName(rawAgent);
|
|
4839
|
-
const markerPath =
|
|
5454
|
+
const markerPath = path17.join(SESSION_CACHE, `current-task-${agent}.json`);
|
|
4840
5455
|
if (existsSync12(markerPath)) {
|
|
4841
5456
|
logIntercom(`SKIP \u2192 ${targetSession} (has in_progress task marker \u2014 will auto-chain)`);
|
|
4842
5457
|
return "debounced";
|
|
@@ -4846,7 +5461,7 @@ function sendIntercom(targetSession) {
|
|
|
4846
5461
|
try {
|
|
4847
5462
|
const rawAgent = targetSession.split("-")[0] ?? targetSession;
|
|
4848
5463
|
const agent = baseAgentName(rawAgent);
|
|
4849
|
-
const taskDir =
|
|
5464
|
+
const taskDir = path17.join(process.cwd(), "exe", agent);
|
|
4850
5465
|
if (existsSync12(taskDir)) {
|
|
4851
5466
|
const files = readdirSync3(taskDir).filter(
|
|
4852
5467
|
(f) => f.endsWith(".md") && f !== "DONE.txt"
|
|
@@ -4980,8 +5595,8 @@ function spawnEmployee(employeeName, exeSession, projectDir, opts) {
|
|
|
4980
5595
|
const transport = getTransport();
|
|
4981
5596
|
const sessionName = employeeSessionName(employeeName, exeSession, opts?.instance);
|
|
4982
5597
|
const instanceLabel = opts?.instance != null && opts.instance > 0 ? `${employeeName}${opts.instance}` : employeeName;
|
|
4983
|
-
const logDir =
|
|
4984
|
-
const logFile =
|
|
5598
|
+
const logDir = path17.join(os10.homedir(), ".exe-os", "session-logs");
|
|
5599
|
+
const logFile = path17.join(logDir, `${instanceLabel}-${Date.now()}.log`);
|
|
4985
5600
|
if (!existsSync12(logDir)) {
|
|
4986
5601
|
mkdirSync6(logDir, { recursive: true });
|
|
4987
5602
|
}
|
|
@@ -4989,14 +5604,14 @@ function spawnEmployee(employeeName, exeSession, projectDir, opts) {
|
|
|
4989
5604
|
let cleanupSuffix = "";
|
|
4990
5605
|
try {
|
|
4991
5606
|
const thisFile = fileURLToPath2(import.meta.url);
|
|
4992
|
-
const cleanupScript =
|
|
5607
|
+
const cleanupScript = path17.join(path17.dirname(thisFile), "..", "bin", "exe-session-cleanup.js");
|
|
4993
5608
|
if (existsSync12(cleanupScript)) {
|
|
4994
5609
|
cleanupSuffix = `; ${process.execPath} "${cleanupScript}" "${employeeName}" "${exeSession}"`;
|
|
4995
5610
|
}
|
|
4996
5611
|
} catch {
|
|
4997
5612
|
}
|
|
4998
5613
|
try {
|
|
4999
|
-
const claudeJsonPath =
|
|
5614
|
+
const claudeJsonPath = path17.join(os10.homedir(), ".claude.json");
|
|
5000
5615
|
let claudeJson = {};
|
|
5001
5616
|
try {
|
|
5002
5617
|
claudeJson = JSON.parse(readFileSync11(claudeJsonPath, "utf8"));
|
|
@@ -5011,10 +5626,10 @@ function spawnEmployee(employeeName, exeSession, projectDir, opts) {
|
|
|
5011
5626
|
} catch {
|
|
5012
5627
|
}
|
|
5013
5628
|
try {
|
|
5014
|
-
const settingsDir =
|
|
5629
|
+
const settingsDir = path17.join(os10.homedir(), ".claude", "projects");
|
|
5015
5630
|
const normalizedKey = (opts?.cwd ?? projectDir).replace(/\//g, "-").replace(/^-/, "");
|
|
5016
|
-
const projSettingsDir =
|
|
5017
|
-
const settingsPath =
|
|
5631
|
+
const projSettingsDir = path17.join(settingsDir, normalizedKey);
|
|
5632
|
+
const settingsPath = path17.join(projSettingsDir, "settings.json");
|
|
5018
5633
|
let settings = {};
|
|
5019
5634
|
try {
|
|
5020
5635
|
settings = JSON.parse(readFileSync11(settingsPath, "utf8"));
|
|
@@ -5061,8 +5676,8 @@ function spawnEmployee(employeeName, exeSession, projectDir, opts) {
|
|
|
5061
5676
|
let behaviorsFlag = "";
|
|
5062
5677
|
let legacyFallbackWarned = false;
|
|
5063
5678
|
if (!useExeAgent && !useBinSymlink) {
|
|
5064
|
-
const identityPath =
|
|
5065
|
-
|
|
5679
|
+
const identityPath = path17.join(
|
|
5680
|
+
os10.homedir(),
|
|
5066
5681
|
".exe-os",
|
|
5067
5682
|
"identity",
|
|
5068
5683
|
`${employeeName}.md`
|
|
@@ -5077,7 +5692,7 @@ function spawnEmployee(employeeName, exeSession, projectDir, opts) {
|
|
|
5077
5692
|
}
|
|
5078
5693
|
const behaviorsFile = exportBehaviorsSync(
|
|
5079
5694
|
employeeName,
|
|
5080
|
-
|
|
5695
|
+
path17.basename(spawnCwd),
|
|
5081
5696
|
sessionName
|
|
5082
5697
|
);
|
|
5083
5698
|
if (behaviorsFile) {
|
|
@@ -5092,9 +5707,9 @@ function spawnEmployee(employeeName, exeSession, projectDir, opts) {
|
|
|
5092
5707
|
}
|
|
5093
5708
|
let sessionContextFlag = "";
|
|
5094
5709
|
try {
|
|
5095
|
-
const ctxDir =
|
|
5710
|
+
const ctxDir = path17.join(os10.homedir(), ".exe-os", "session-cache");
|
|
5096
5711
|
mkdirSync6(ctxDir, { recursive: true });
|
|
5097
|
-
const ctxFile =
|
|
5712
|
+
const ctxFile = path17.join(ctxDir, `session-context-${sessionName}.md`);
|
|
5098
5713
|
const ctxContent = [
|
|
5099
5714
|
`## Session Context`,
|
|
5100
5715
|
`You are running in tmux session: ${sessionName}.`,
|
|
@@ -5178,7 +5793,7 @@ function spawnEmployee(employeeName, exeSession, projectDir, opts) {
|
|
|
5178
5793
|
transport.pipeLog(sessionName, logFile);
|
|
5179
5794
|
try {
|
|
5180
5795
|
const mySession = getMySession();
|
|
5181
|
-
const dispatchInfo =
|
|
5796
|
+
const dispatchInfo = path17.join(SESSION_CACHE, `dispatch-info-${sessionName}.json`);
|
|
5182
5797
|
writeFileSync7(dispatchInfo, JSON.stringify({
|
|
5183
5798
|
dispatchedBy: mySession,
|
|
5184
5799
|
rootExe: exeSession,
|
|
@@ -5253,15 +5868,15 @@ var init_tmux_routing = __esm({
|
|
|
5253
5868
|
init_intercom_queue();
|
|
5254
5869
|
init_plan_limits();
|
|
5255
5870
|
init_employees();
|
|
5256
|
-
SPAWN_LOCK_DIR =
|
|
5257
|
-
SESSION_CACHE =
|
|
5871
|
+
SPAWN_LOCK_DIR = path17.join(os10.homedir(), ".exe-os", "spawn-locks");
|
|
5872
|
+
SESSION_CACHE = path17.join(os10.homedir(), ".exe-os", "session-cache");
|
|
5258
5873
|
BEHAVIORS_EXPORT_TIMEOUT_MS = 1e4;
|
|
5259
5874
|
VALID_SESSION_NAME = /^[a-z]+\d*-[a-zA-Z0-9_]+$/;
|
|
5260
5875
|
VERIFY_PANE_LINES = 200;
|
|
5261
5876
|
INTERCOM_DEBOUNCE_MS = 3e4;
|
|
5262
5877
|
CODEX_DEBOUNCE_MS = 12e4;
|
|
5263
|
-
INTERCOM_LOG2 =
|
|
5264
|
-
DEBOUNCE_FILE =
|
|
5878
|
+
INTERCOM_LOG2 = path17.join(os10.homedir(), ".exe-os", "intercom.log");
|
|
5879
|
+
DEBOUNCE_FILE = path17.join(SESSION_CACHE, "intercom-debounce.json");
|
|
5265
5880
|
DEBOUNCE_CLEANUP_AGE_MS = 5 * 60 * 1e3;
|
|
5266
5881
|
BUSY_PATTERN = /[✻✽✶✳·].*…|Running…|• Working|• Ran |• Explored|• Called|esc to interrupt/;
|
|
5267
5882
|
}
|
|
@@ -5279,13 +5894,13 @@ var init_memory = __esm({
|
|
|
5279
5894
|
// src/lib/keychain.ts
|
|
5280
5895
|
import { readFile as readFile4, writeFile as writeFile5, unlink, mkdir as mkdir4, chmod as chmod2 } from "fs/promises";
|
|
5281
5896
|
import { existsSync as existsSync13 } from "fs";
|
|
5282
|
-
import
|
|
5283
|
-
import
|
|
5897
|
+
import path18 from "path";
|
|
5898
|
+
import os11 from "os";
|
|
5284
5899
|
function getKeyDir() {
|
|
5285
|
-
return process.env.EXE_OS_DIR ?? process.env.EXE_MEM_DIR ??
|
|
5900
|
+
return process.env.EXE_OS_DIR ?? process.env.EXE_MEM_DIR ?? path18.join(os11.homedir(), ".exe-os");
|
|
5286
5901
|
}
|
|
5287
5902
|
function getKeyPath() {
|
|
5288
|
-
return
|
|
5903
|
+
return path18.join(getKeyDir(), "master.key");
|
|
5289
5904
|
}
|
|
5290
5905
|
async function tryKeytar() {
|
|
5291
5906
|
try {
|
|
@@ -5308,7 +5923,7 @@ async function getMasterKey() {
|
|
|
5308
5923
|
const keyPath = getKeyPath();
|
|
5309
5924
|
if (!existsSync13(keyPath)) {
|
|
5310
5925
|
process.stderr.write(
|
|
5311
|
-
`[keychain] Key not found at ${keyPath} (HOME=${
|
|
5926
|
+
`[keychain] Key not found at ${keyPath} (HOME=${os11.homedir()}, EXE_OS_DIR=${process.env.EXE_OS_DIR ?? "unset"})
|
|
5312
5927
|
`
|
|
5313
5928
|
);
|
|
5314
5929
|
return null;
|
|
@@ -5346,7 +5961,7 @@ __export(shard_manager_exports, {
|
|
|
5346
5961
|
listShards: () => listShards,
|
|
5347
5962
|
shardExists: () => shardExists
|
|
5348
5963
|
});
|
|
5349
|
-
import
|
|
5964
|
+
import path19 from "path";
|
|
5350
5965
|
import { existsSync as existsSync14, mkdirSync as mkdirSync7, readdirSync as readdirSync4 } from "fs";
|
|
5351
5966
|
import { createClient as createClient2 } from "@libsql/client";
|
|
5352
5967
|
function initShardManager(encryptionKey) {
|
|
@@ -5372,7 +5987,7 @@ function getShardClient(projectName) {
|
|
|
5372
5987
|
}
|
|
5373
5988
|
const cached = _shards.get(safeName);
|
|
5374
5989
|
if (cached) return cached;
|
|
5375
|
-
const dbPath =
|
|
5990
|
+
const dbPath = path19.join(SHARDS_DIR, `${safeName}.db`);
|
|
5376
5991
|
const client = createClient2({
|
|
5377
5992
|
url: `file:${dbPath}`,
|
|
5378
5993
|
encryptionKey: _encryptionKey
|
|
@@ -5382,7 +5997,7 @@ function getShardClient(projectName) {
|
|
|
5382
5997
|
}
|
|
5383
5998
|
function shardExists(projectName) {
|
|
5384
5999
|
const safeName = projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
5385
|
-
return existsSync14(
|
|
6000
|
+
return existsSync14(path19.join(SHARDS_DIR, `${safeName}.db`));
|
|
5386
6001
|
}
|
|
5387
6002
|
function listShards() {
|
|
5388
6003
|
if (!existsSync14(SHARDS_DIR)) return [];
|
|
@@ -5459,7 +6074,23 @@ async function ensureShardSchema(client) {
|
|
|
5459
6074
|
// MS-11: draft staging, MS-6a: memory_type, MS-7: trajectory
|
|
5460
6075
|
"ALTER TABLE memories ADD COLUMN draft INTEGER DEFAULT 0",
|
|
5461
6076
|
"ALTER TABLE memories ADD COLUMN memory_type TEXT DEFAULT 'raw'",
|
|
5462
|
-
"ALTER TABLE memories ADD COLUMN trajectory TEXT"
|
|
6077
|
+
"ALTER TABLE memories ADD COLUMN trajectory TEXT",
|
|
6078
|
+
// Metadata enrichment columns (must match database.ts)
|
|
6079
|
+
"ALTER TABLE memories ADD COLUMN intent TEXT",
|
|
6080
|
+
"ALTER TABLE memories ADD COLUMN outcome TEXT",
|
|
6081
|
+
"ALTER TABLE memories ADD COLUMN domain TEXT",
|
|
6082
|
+
"ALTER TABLE memories ADD COLUMN referenced_entities TEXT",
|
|
6083
|
+
"ALTER TABLE memories ADD COLUMN retrieval_count INTEGER DEFAULT 0",
|
|
6084
|
+
"ALTER TABLE memories ADD COLUMN chain_position TEXT",
|
|
6085
|
+
"ALTER TABLE memories ADD COLUMN review_status TEXT",
|
|
6086
|
+
"ALTER TABLE memories ADD COLUMN context_window_pct INTEGER",
|
|
6087
|
+
"ALTER TABLE memories ADD COLUMN file_paths TEXT",
|
|
6088
|
+
"ALTER TABLE memories ADD COLUMN commit_hash TEXT",
|
|
6089
|
+
"ALTER TABLE memories ADD COLUMN duration_ms INTEGER",
|
|
6090
|
+
"ALTER TABLE memories ADD COLUMN token_cost REAL",
|
|
6091
|
+
"ALTER TABLE memories ADD COLUMN audience TEXT",
|
|
6092
|
+
"ALTER TABLE memories ADD COLUMN language_type TEXT",
|
|
6093
|
+
"ALTER TABLE memories ADD COLUMN parent_memory_id TEXT"
|
|
5463
6094
|
]) {
|
|
5464
6095
|
try {
|
|
5465
6096
|
await client.execute(col);
|
|
@@ -5571,7 +6202,7 @@ var init_shard_manager = __esm({
|
|
|
5571
6202
|
"src/lib/shard-manager.ts"() {
|
|
5572
6203
|
"use strict";
|
|
5573
6204
|
init_config();
|
|
5574
|
-
SHARDS_DIR =
|
|
6205
|
+
SHARDS_DIR = path19.join(EXE_AI_DIR, "shards");
|
|
5575
6206
|
_shards = /* @__PURE__ */ new Map();
|
|
5576
6207
|
_encryptionKey = null;
|
|
5577
6208
|
_shardingEnabled = false;
|
|
@@ -6435,9 +7066,9 @@ function extractBash(input, response) {
|
|
|
6435
7066
|
}
|
|
6436
7067
|
function extractGrep(input, response) {
|
|
6437
7068
|
const pattern = String(input.pattern ?? "");
|
|
6438
|
-
const
|
|
7069
|
+
const path20 = input.path ? String(input.path) : "";
|
|
6439
7070
|
const output = String(response.text ?? response.content ?? JSON.stringify(response).slice(0, MAX_OUTPUT));
|
|
6440
|
-
return `Searched for "${pattern}"${
|
|
7071
|
+
return `Searched for "${pattern}"${path20 ? ` in ${path20}` : ""}
|
|
6441
7072
|
${output.slice(0, MAX_OUTPUT)}`;
|
|
6442
7073
|
}
|
|
6443
7074
|
function extractGlob(input, response) {
|