@askexenow/exe-os 0.9.300 → 0.9.301

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.
Files changed (244) hide show
  1. package/deploy/compose/erp-nginx/nginx.conf +6 -3
  2. package/dist/active-agent-UNJO6AJ2.js +27 -0
  3. package/dist/active-agent-Y5LSIMVC.js +28 -0
  4. package/dist/agentic-ontology-QEV7GI3T.js +25 -0
  5. package/dist/backfill-metadata-RQZ4BN7G.js +600 -0
  6. package/dist/behaviors-A3L5CWMK.js +46 -0
  7. package/dist/bin/agentic-ontology-backfill.js +5 -5
  8. package/dist/bin/agentic-reflection-backfill.js +6 -6
  9. package/dist/bin/agentic-semantic-label.js +5 -5
  10. package/dist/bin/backfill-conversations.js +4 -4
  11. package/dist/bin/backfill-responses.js +4 -4
  12. package/dist/bin/backfill-vectors.js +5 -5
  13. package/dist/bin/bulk-sync-postgres.js +7 -7
  14. package/dist/bin/cc-doctor.js +4 -4
  15. package/dist/bin/cleanup-stale-review-tasks.js +9 -9
  16. package/dist/bin/cli.js +15 -15
  17. package/dist/bin/exe-agent-config.js +2 -2
  18. package/dist/bin/exe-agent.js +4 -4
  19. package/dist/bin/exe-assign.js +5 -5
  20. package/dist/bin/exe-boot.js +23 -18
  21. package/dist/bin/exe-call.js +4 -4
  22. package/dist/bin/exe-cloud.js +7 -7
  23. package/dist/bin/exe-dispatch.js +9 -9
  24. package/dist/bin/exe-doctor.js +2 -2
  25. package/dist/bin/exe-export-behaviors.js +7 -7
  26. package/dist/bin/exe-forget.js +6 -6
  27. package/dist/bin/exe-gateway.js +7 -7
  28. package/dist/bin/exe-healthcheck.js +4 -4
  29. package/dist/bin/exe-heartbeat.js +9 -9
  30. package/dist/bin/exe-kill.js +12 -12
  31. package/dist/bin/exe-launch-agent.js +16 -16
  32. package/dist/bin/exe-new-employee.js +6 -6
  33. package/dist/bin/exe-pending-messages.js +10 -10
  34. package/dist/bin/exe-pending-notifications.js +9 -9
  35. package/dist/bin/exe-pending-reviews.js +9 -9
  36. package/dist/bin/exe-rename.js +4 -4
  37. package/dist/bin/exe-review.js +11 -11
  38. package/dist/bin/exe-search.js +5 -5
  39. package/dist/bin/exe-session-cleanup.js +14 -14
  40. package/dist/bin/exe-settings.js +7 -7
  41. package/dist/bin/exe-start-codex.js +11 -11
  42. package/dist/bin/exe-start-opencode.js +8 -8
  43. package/dist/bin/exe-status.js +10 -10
  44. package/dist/bin/exe-team.js +3 -3
  45. package/dist/bin/exe-watchdog.js +3 -3
  46. package/dist/bin/git-sweep.js +10 -10
  47. package/dist/bin/graph-backfill.js +4 -4
  48. package/dist/bin/graph-export.js +5 -5
  49. package/dist/bin/import-history.js +7 -7
  50. package/dist/bin/install.js +6 -6
  51. package/dist/bin/intercom-check.js +4 -4
  52. package/dist/bin/mcp-sessions.js +2 -2
  53. package/dist/bin/orchestration-metrics.js +4 -4
  54. package/dist/bin/postgres-agentic-reflection-backfill.js +2 -2
  55. package/dist/bin/postgres-agentic-semantic-backfill.js +1 -1
  56. package/dist/bin/scan-tasks.js +9 -9
  57. package/dist/bin/setup.js +1 -1
  58. package/dist/bin/shard-migrate.js +4 -4
  59. package/dist/capability-cards-VTGDTOZ4.js +89 -0
  60. package/dist/capacity-monitor-G2MAJPRP.js +51 -0
  61. package/dist/catchup-brief-VBGEJQRS.js +175 -0
  62. package/dist/chunk-24JVDLQJ.js +345 -0
  63. package/dist/chunk-2T3OYZMR.js +1158 -0
  64. package/dist/chunk-3ABY3QDX.js +199 -0
  65. package/dist/chunk-3G3ECFB5.js +668 -0
  66. package/dist/chunk-3LHOFGHT.js +280 -0
  67. package/dist/chunk-3RA62PNQ.js +58 -0
  68. package/dist/chunk-3XRS5AVV.js +567 -0
  69. package/dist/chunk-3YK7X5FD.js +1186 -0
  70. package/dist/chunk-4L6PVYFE.js +54 -0
  71. package/dist/chunk-4O67LBMK.js +377 -0
  72. package/dist/chunk-4OIU3N6U.js +167 -0
  73. package/dist/chunk-5SYYMNPE.js +30 -0
  74. package/dist/chunk-5TO5PH7O.js +304 -0
  75. package/dist/chunk-5XD2Y463.js +402 -0
  76. package/dist/chunk-63AENHJC.js +123 -0
  77. package/dist/chunk-673IFJYB.js +731 -0
  78. package/dist/chunk-7AWH47AR.js +448 -0
  79. package/dist/chunk-7P4B6AEP.js +227 -0
  80. package/dist/chunk-7VHOALNC.js +244 -0
  81. package/dist/chunk-ASJHCAVL.js +38 -0
  82. package/dist/chunk-DICIFTCS.js +150 -0
  83. package/dist/chunk-DIFI5JDC.js +76 -0
  84. package/dist/chunk-DPOIJ5SM.js +284 -0
  85. package/dist/chunk-FAZNXNA5.js +33 -0
  86. package/dist/chunk-FCHG5RC4.js +197 -0
  87. package/dist/chunk-FFKSPZO2.js +157 -0
  88. package/dist/chunk-FNHYH5U6.js +331 -0
  89. package/dist/chunk-FWPDAQ6Q.js +1350 -0
  90. package/dist/chunk-FZB73QOI.js +210 -0
  91. package/dist/chunk-GJBR6QLD.js +630 -0
  92. package/dist/chunk-GRSYAHKI.js +535 -0
  93. package/dist/chunk-J5HFRVNW.js +362 -0
  94. package/dist/chunk-J6SD7LT2.js +171 -0
  95. package/dist/chunk-JURL2S27.js +128 -0
  96. package/dist/chunk-KPUYYOFS.js +122 -0
  97. package/dist/chunk-LAFARYU5.js +456 -0
  98. package/dist/chunk-LSDXEHKL.js +381 -0
  99. package/dist/chunk-MS2EOZJQ.js +290 -0
  100. package/dist/chunk-MUIMJGSQ.js +128 -0
  101. package/dist/chunk-NJMPNYBS.js +427 -0
  102. package/dist/chunk-OJACH2JF.js +128 -0
  103. package/dist/chunk-OO4IFABD.js +382 -0
  104. package/dist/chunk-Q65NCNL4.js +1352 -0
  105. package/dist/chunk-QIGS2LRT.js +735 -0
  106. package/dist/chunk-S73ZAJ2S.js +262 -0
  107. package/dist/chunk-SJ4UF7YK.js +1094 -0
  108. package/dist/chunk-SOZ7D77I.js +204 -0
  109. package/dist/chunk-TDX2LK2M.js +240 -0
  110. package/dist/chunk-U5RKGLV6.js +50 -0
  111. package/dist/chunk-UFGTHBHP.js +127 -0
  112. package/dist/chunk-ULCYWCPI.js +1079 -0
  113. package/dist/chunk-V6LOEOXG.js +3372 -0
  114. package/dist/chunk-VAZOVAW4.js +2162 -0
  115. package/dist/chunk-VEUQVKKT.js +185 -0
  116. package/dist/chunk-VIDDJ5RF.js +214 -0
  117. package/dist/chunk-VNB4ROYG.js +348 -0
  118. package/dist/chunk-VWUQFZFB.js +395 -0
  119. package/dist/chunk-W77GRCNA.js +85 -0
  120. package/dist/chunk-WVMG4ZRH.js +14597 -0
  121. package/dist/chunk-WYVOTRRZ.js +129 -0
  122. package/dist/chunk-XQQ7D4I4.js +85 -0
  123. package/dist/chunk-YHJPTIPR.js +836 -0
  124. package/dist/chunk-YLKS7KKC.js +2145 -0
  125. package/dist/chunk-YU3KEVCO.js +333 -0
  126. package/dist/chunk-ZDPU3JTF.js +221 -0
  127. package/dist/chunk-ZDY4LYAJ.js +81 -0
  128. package/dist/chunk-ZG33AACD.js +70 -0
  129. package/dist/chunk-ZKHPZ6KN.js +181 -0
  130. package/dist/chunk-ZO2TM5N5.js +97 -0
  131. package/dist/chunk-ZSUACDQC.js +4388 -0
  132. package/dist/co-activation-XM25BLZM.js +74 -0
  133. package/dist/co-occurrence-CKEMDPWO.js +95 -0
  134. package/dist/core-memory-ZDA76EU3.js +110 -0
  135. package/dist/crdt-sync-BJKZB6T6.js +33 -0
  136. package/dist/crm-webhook-E5PAFAUN.js +10 -0
  137. package/dist/cto-delegation-gate-EMY6ZZ2F.js +280 -0
  138. package/dist/daemon-orchestration-Y5Y6YNE3.js +143 -0
  139. package/dist/db-backup-HFJ53IBU.js +43 -0
  140. package/dist/doc-graph-extractor-ID45AQ2P.js +133 -0
  141. package/dist/dreaming-N6B7KBIE.js +34 -0
  142. package/dist/exe-drift-CPUEAPIU.js +70 -0
  143. package/dist/exe-export-4RTGDV53.js +77 -0
  144. package/dist/exe-import-AZMIF34Z.js +80 -0
  145. package/dist/exe-key-LJV23AJI.js +673 -0
  146. package/dist/exe-snapshot-ZOZBW7V6.js +338 -0
  147. package/dist/fast-db-init-ATRZGHOL.js +7 -0
  148. package/dist/gateway/index.js +8 -8
  149. package/dist/git-staleness-XNOKI4D3.js +112 -0
  150. package/dist/git-task-sweep-3MO4OVND.js +42 -0
  151. package/dist/global-procedures-EBAPPWGZ.js +22 -0
  152. package/dist/graph-auto-extract-VJOUQBPK.js +183 -0
  153. package/dist/hooks/bug-report-worker.js +11 -11
  154. package/dist/hooks/codex-stop-task-finalizer.js +11 -11
  155. package/dist/hooks/commit-complete.js +11 -11
  156. package/dist/hooks/error-recall.js +6 -6
  157. package/dist/hooks/exe-heartbeat-hook.js +3 -3
  158. package/dist/hooks/ingest.js +6 -6
  159. package/dist/hooks/instructions-loaded.js +4 -4
  160. package/dist/hooks/manifest.json +19 -19
  161. package/dist/hooks/notification.js +4 -4
  162. package/dist/hooks/post-compact.js +11 -11
  163. package/dist/hooks/post-tool-combined.js +5 -5
  164. package/dist/hooks/pre-compact.js +12 -12
  165. package/dist/hooks/pre-tool-use.js +14 -14
  166. package/dist/hooks/prompt-submit.js +26 -24
  167. package/dist/hooks/session-end.js +15 -15
  168. package/dist/hooks/session-start.js +12 -12
  169. package/dist/hooks/stop.js +14 -14
  170. package/dist/hooks/subagent-stop.js +10 -10
  171. package/dist/hooks/summary-worker.js +14 -14
  172. package/dist/index.js +17 -17
  173. package/dist/installer-37KFNAWE.js +344 -0
  174. package/dist/installer-F55NR4E2.js +298 -0
  175. package/dist/installer-KOYBUS4J.js +40 -0
  176. package/dist/lib/cloud-sync.js +7 -7
  177. package/dist/lib/consolidation.js +5 -5
  178. package/dist/lib/database.js +2 -2
  179. package/dist/lib/db.js +2 -2
  180. package/dist/lib/employee-templates.js +4 -4
  181. package/dist/lib/employees.js +2 -2
  182. package/dist/lib/exe-daemon.js +40 -40
  183. package/dist/lib/hybrid-search.js +5 -5
  184. package/dist/lib/identity.js +2 -2
  185. package/dist/lib/messaging.js +9 -9
  186. package/dist/lib/reminders.js +3 -3
  187. package/dist/lib/schedules.js +5 -5
  188. package/dist/lib/session-registry.js +4 -4
  189. package/dist/lib/skill-learning.js +6 -6
  190. package/dist/lib/store.js +4 -4
  191. package/dist/lib/task-router.js +3 -3
  192. package/dist/lib/tasks.js +10 -10
  193. package/dist/lib/tmux-routing.js +8 -8
  194. package/dist/lib/token-spend.js +3 -3
  195. package/dist/mcp/register-tools.js +54 -54
  196. package/dist/mcp/server.js +55 -55
  197. package/dist/mcp/tools/complete-reminder.js +4 -4
  198. package/dist/mcp/tools/create-reminder.js +4 -4
  199. package/dist/mcp/tools/create-task.js +12 -12
  200. package/dist/mcp/tools/deactivate-behavior.js +7 -7
  201. package/dist/mcp/tools/list-reminders.js +4 -4
  202. package/dist/mcp/tools/list-tasks.js +12 -12
  203. package/dist/mcp/tools/send-message.js +11 -11
  204. package/dist/mcp/tools/update-task.js +11 -11
  205. package/dist/mcp-http-config-7KJZI7UD.js +31 -0
  206. package/dist/memory-cards-ZIT7ZKL5.js +180 -0
  207. package/dist/memory-graph-extractor-LY2VORZT.js +22 -0
  208. package/dist/memory-poisoning-defense-SEM25TY5.js +224 -0
  209. package/dist/memory-reflection-J2W7CJ7C.js +244 -0
  210. package/dist/notifications-RLMSI4YE.js +47 -0
  211. package/dist/orchestration-events-TGQYA72K.js +27 -0
  212. package/dist/orchestrator-JQD5G3CW.js +35 -0
  213. package/dist/pipeline-router-3Q3YBYSM.js +15 -0
  214. package/dist/plan-limits-YGXTYCW4.js +28 -0
  215. package/dist/project-boot-TDOZKKDR.js +299 -0
  216. package/dist/projection-worker-TMKUSVGD.js +1084 -0
  217. package/dist/prospective-memory-CNJDBNWF.js +232 -0
  218. package/dist/reranker-YQIRNGDM.js +19 -0
  219. package/dist/retrieval-health-M5BVB7EV.js +12 -0
  220. package/dist/review-polling-ZMB3OBPC.js +126 -0
  221. package/dist/runtime/index.js +11 -11
  222. package/dist/session-events-UTMCKDIN.js +38 -0
  223. package/dist/session-kill-telemetry-FRQA5MVD.js +31 -0
  224. package/dist/session-scope-2BD6QLNI.js +88 -0
  225. package/dist/setup-wizard-W64I6SHC.js +12 -0
  226. package/dist/skill-refinement-FXCXTUS2.js +159 -0
  227. package/dist/steward-gate-JDR3SLH3.js +15 -0
  228. package/dist/task-enforcement-WCEA4FZI.js +506 -0
  229. package/dist/task-scope-L5GDL2AV.js +37 -0
  230. package/dist/tasks-crud-S36AFYYM.js +79 -0
  231. package/dist/tasks-notify-W2W2BJRB.js +40 -0
  232. package/dist/tasks-review-34WV7BX2.js +49 -0
  233. package/dist/telemetry-upload-3CSVO3J7.js +741 -0
  234. package/dist/token-budget-ZG2MQ5GD.js +86 -0
  235. package/dist/tool-telemetry-ODL4F2CW.js +17 -0
  236. package/dist/tui/App.js +16 -16
  237. package/dist/tui-data-Z5UF7KEI.js +260 -0
  238. package/dist/wiki-acl-SZFHCEC4.js +111 -0
  239. package/dist/worker-gate-OOO6BWZ6.js +21 -0
  240. package/dist/workflow-engine-QY3IFFR2.js +28 -0
  241. package/dist/worktree-CNOQZBNT.js +28 -0
  242. package/dist/worktree-sweep-SE7ITXC4.js +21 -0
  243. package/package.json +1 -1
  244. package/release-notes.json +88 -88
@@ -0,0 +1,333 @@
1
+ import {
2
+ executeAction,
3
+ substituteTemplate
4
+ } from "./chunk-OO4IFABD.js";
5
+
6
+ // src/automation/workflow-engine.ts
7
+ import { randomUUID } from "crypto";
8
+ var _definitions = /* @__PURE__ */ new Map();
9
+ var _instances = /* @__PURE__ */ new Map();
10
+ function createWorkflowDefinition(input) {
11
+ const def = {
12
+ id: randomUUID().slice(0, 12),
13
+ ...input,
14
+ created_at: (/* @__PURE__ */ new Date()).toISOString()
15
+ };
16
+ def.steps = def.steps.map((s, i) => ({ ...s, index: s.index || i + 1 }));
17
+ _definitions.set(def.id, def);
18
+ return def;
19
+ }
20
+ function getWorkflowDefinition(id) {
21
+ return _definitions.get(id);
22
+ }
23
+ function listWorkflowDefinitions() {
24
+ return [..._definitions.values()];
25
+ }
26
+ function buildTemplateContext(instance) {
27
+ const ctx = { ...instance.context };
28
+ const stepMap = {};
29
+ for (const sr of instance.step_results) {
30
+ stepMap[String(sr.step_index)] = {
31
+ status: sr.status,
32
+ result: sr.result,
33
+ error: sr.error
34
+ };
35
+ }
36
+ ctx.step = stepMap;
37
+ return ctx;
38
+ }
39
+ function resolveActionParams(action, context) {
40
+ const resolved = {};
41
+ for (const [key, val] of Object.entries(action.params)) {
42
+ resolved[key] = substituteTemplate(val, context);
43
+ }
44
+ return { ...action, params: resolved };
45
+ }
46
+ function startWorkflow(definitionId, context = {}) {
47
+ const def = _definitions.get(definitionId);
48
+ if (!def) throw new Error(`Workflow definition "${definitionId}" not found`);
49
+ const instance = {
50
+ id: randomUUID().slice(0, 12),
51
+ definition_id: definitionId,
52
+ status: "running",
53
+ current_step: 1,
54
+ step_results: [],
55
+ context,
56
+ created_at: (/* @__PURE__ */ new Date()).toISOString(),
57
+ updated_at: (/* @__PURE__ */ new Date()).toISOString()
58
+ };
59
+ _instances.set(instance.id, instance);
60
+ return instance;
61
+ }
62
+ function getWorkflowInstance(id) {
63
+ return _instances.get(id);
64
+ }
65
+ function listWorkflowInstances(status) {
66
+ const all = [..._instances.values()];
67
+ return status ? all.filter((i) => i.status === status) : all;
68
+ }
69
+ async function advanceWorkflow(instanceId) {
70
+ const instance = _instances.get(instanceId);
71
+ if (!instance) throw new Error(`Workflow instance "${instanceId}" not found`);
72
+ if (instance.status !== "running") {
73
+ throw new Error(`Workflow "${instanceId}" is ${instance.status}, cannot advance`);
74
+ }
75
+ const def = _definitions.get(instance.definition_id);
76
+ if (!def) throw new Error(`Workflow definition "${instance.definition_id}" not found`);
77
+ const step = def.steps.find((s) => s.index === instance.current_step);
78
+ if (!step) {
79
+ instance.status = "completed";
80
+ instance.updated_at = (/* @__PURE__ */ new Date()).toISOString();
81
+ return instance;
82
+ }
83
+ const templateCtx = buildTemplateContext(instance);
84
+ const stepResult = {
85
+ step_index: step.index,
86
+ status: "success",
87
+ started_at: (/* @__PURE__ */ new Date()).toISOString()
88
+ };
89
+ switch (step.type) {
90
+ case "execute_action": {
91
+ const action = step.action ?? buildActionFromConnector(step);
92
+ if (!action) {
93
+ stepResult.status = "failed";
94
+ stepResult.error = "No action defined for execute_action step";
95
+ break;
96
+ }
97
+ const resolvedAction = resolveActionParams(action, templateCtx);
98
+ const result = await executeAction(resolvedAction, templateCtx);
99
+ stepResult.status = result.success ? "success" : "failed";
100
+ stepResult.result = result;
101
+ stepResult.error = result.error;
102
+ if (!result.success) {
103
+ instance.status = "failed";
104
+ }
105
+ break;
106
+ }
107
+ case "wait_for_approval": {
108
+ const { createTask } = await import("./lib/tasks.js");
109
+ const { getCoordinatorName } = await import("./lib/employees.js");
110
+ const message = step.approval_message ? substituteTemplate(step.approval_message, templateCtx) : `Workflow "${def.name}" step ${step.index} ("${step.name}") requires approval.`;
111
+ const task = await createTask({
112
+ title: `[Workflow Approval] ${def.name}: ${step.name}`,
113
+ assignedTo: getCoordinatorName(),
114
+ assignedBy: "workflow-engine",
115
+ projectName: "exe-os",
116
+ priority: "p1",
117
+ context: `${message}
118
+
119
+ **Workflow:** ${def.name} (${instance.id})
120
+ **Step:** ${step.index} \u2014 ${step.name}
121
+
122
+ To approve: call approve_workflow_step with instance_id="${instance.id}"
123
+ To reject: call approve_workflow_step with instance_id="${instance.id}" approved=false`,
124
+ baseDir: process.cwd()
125
+ });
126
+ instance.approval_task_id = task.id;
127
+ instance.status = "waiting_approval";
128
+ stepResult.status = "pending_approval";
129
+ break;
130
+ }
131
+ case "conditional": {
132
+ if (!step.condition) {
133
+ stepResult.status = "failed";
134
+ stepResult.error = "No condition defined for conditional step";
135
+ break;
136
+ }
137
+ const resolvedExpr = substituteTemplate(step.condition.expression, templateCtx);
138
+ const conditionMet = evaluateSimpleExpression(resolvedExpr);
139
+ stepResult.result = { expression: resolvedExpr, met: conditionMet };
140
+ if (conditionMet && step.condition.then_step) {
141
+ instance.current_step = step.condition.then_step;
142
+ stepResult.completed_at = (/* @__PURE__ */ new Date()).toISOString();
143
+ instance.step_results.push(stepResult);
144
+ instance.updated_at = (/* @__PURE__ */ new Date()).toISOString();
145
+ return instance;
146
+ } else if (!conditionMet && step.condition.else_step) {
147
+ instance.current_step = step.condition.else_step;
148
+ stepResult.completed_at = (/* @__PURE__ */ new Date()).toISOString();
149
+ instance.step_results.push(stepResult);
150
+ instance.updated_at = (/* @__PURE__ */ new Date()).toISOString();
151
+ return instance;
152
+ }
153
+ break;
154
+ }
155
+ }
156
+ stepResult.completed_at = (/* @__PURE__ */ new Date()).toISOString();
157
+ instance.step_results.push(stepResult);
158
+ if (instance.status === "running") {
159
+ const nextStep = def.steps.find((s) => s.index > step.index);
160
+ if (nextStep) {
161
+ instance.current_step = nextStep.index;
162
+ } else {
163
+ instance.status = "completed";
164
+ }
165
+ }
166
+ instance.updated_at = (/* @__PURE__ */ new Date()).toISOString();
167
+ return instance;
168
+ }
169
+ async function runWorkflow(instanceId) {
170
+ let instance = _instances.get(instanceId);
171
+ if (!instance) throw new Error(`Workflow instance "${instanceId}" not found`);
172
+ while (instance.status === "running") {
173
+ instance = await advanceWorkflow(instanceId);
174
+ }
175
+ return instance;
176
+ }
177
+ async function approveWorkflowStep(instanceId, approved = true) {
178
+ const instance = _instances.get(instanceId);
179
+ if (!instance) throw new Error(`Workflow instance "${instanceId}" not found`);
180
+ if (instance.status !== "waiting_approval") {
181
+ throw new Error(`Workflow "${instanceId}" is not waiting for approval (status: ${instance.status})`);
182
+ }
183
+ const pendingResult = instance.step_results.find(
184
+ (sr) => sr.step_index === instance.current_step && sr.status === "pending_approval"
185
+ );
186
+ if (pendingResult) {
187
+ pendingResult.status = approved ? "approved" : "failed";
188
+ pendingResult.completed_at = (/* @__PURE__ */ new Date()).toISOString();
189
+ pendingResult.result = { approved };
190
+ }
191
+ if (!approved) {
192
+ instance.status = "cancelled";
193
+ instance.updated_at = (/* @__PURE__ */ new Date()).toISOString();
194
+ return instance;
195
+ }
196
+ const def = _definitions.get(instance.definition_id);
197
+ if (!def) throw new Error(`Workflow definition "${instance.definition_id}" not found`);
198
+ const currentStep = def.steps.find((s) => s.index === instance.current_step);
199
+ const nextStep = currentStep ? def.steps.find((s) => s.index > currentStep.index) : void 0;
200
+ if (nextStep) {
201
+ instance.current_step = nextStep.index;
202
+ instance.status = "running";
203
+ } else {
204
+ instance.status = "completed";
205
+ }
206
+ instance.approval_task_id = void 0;
207
+ instance.updated_at = (/* @__PURE__ */ new Date()).toISOString();
208
+ if (instance.status === "running") {
209
+ return runWorkflow(instanceId);
210
+ }
211
+ return instance;
212
+ }
213
+ function buildActionFromConnector(step) {
214
+ if (!step.connector || !step.operation) return null;
215
+ const params = {};
216
+ if (step.payload) {
217
+ for (const [k, v] of Object.entries(step.payload)) {
218
+ params[k] = String(v);
219
+ }
220
+ }
221
+ params._connector = step.connector;
222
+ params._operation = step.operation;
223
+ return {
224
+ type: "mcp_tool",
225
+ params
226
+ };
227
+ }
228
+ function evaluateSimpleExpression(expr) {
229
+ const operators = ["==", "!=", ">=", "<=", ">", "<"];
230
+ for (const op of operators) {
231
+ const idx = expr.indexOf(op);
232
+ if (idx === -1) continue;
233
+ const left = expr.slice(0, idx).trim();
234
+ const right = expr.slice(idx + op.length).trim();
235
+ switch (op) {
236
+ case "==":
237
+ return left === right;
238
+ case "!=":
239
+ return left !== right;
240
+ case ">":
241
+ return Number(left) > Number(right);
242
+ case "<":
243
+ return Number(left) < Number(right);
244
+ case ">=":
245
+ return Number(left) >= Number(right);
246
+ case "<=":
247
+ return Number(left) <= Number(right);
248
+ }
249
+ }
250
+ return expr.trim() !== "" && expr.trim() !== "false" && expr.trim() !== "0";
251
+ }
252
+ async function persistWorkflows() {
253
+ try {
254
+ const { getClient } = await import("./lib/database.js");
255
+ const client = getClient();
256
+ for (const def of _definitions.values()) {
257
+ await client.execute({
258
+ sql: `INSERT OR REPLACE INTO workflow_definitions (id, name, description, steps, trigger_event, created_at)
259
+ VALUES (?, ?, ?, ?, ?, ?)`,
260
+ args: [def.id, def.name, def.description ?? null, JSON.stringify(def.steps), def.trigger_event ?? null, def.created_at]
261
+ });
262
+ }
263
+ for (const inst of _instances.values()) {
264
+ await client.execute({
265
+ sql: `INSERT OR REPLACE INTO workflow_instances
266
+ (id, definition_id, status, current_step, step_results, context, approval_task_id, created_at, updated_at)
267
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`,
268
+ args: [
269
+ inst.id,
270
+ inst.definition_id,
271
+ inst.status,
272
+ inst.current_step,
273
+ JSON.stringify(inst.step_results),
274
+ JSON.stringify(inst.context),
275
+ inst.approval_task_id ?? null,
276
+ inst.created_at,
277
+ inst.updated_at
278
+ ]
279
+ });
280
+ }
281
+ } catch (e) {
282
+ process.stderr.write(`[workflow-engine] persist failed: ${e instanceof Error ? e.message : String(e)}
283
+ `);
284
+ }
285
+ }
286
+ async function loadWorkflows() {
287
+ try {
288
+ const { getClient } = await import("./lib/database.js");
289
+ const client = getClient();
290
+ const defs = await client.execute("SELECT * FROM workflow_definitions");
291
+ for (const row of defs.rows) {
292
+ const def = {
293
+ id: String(row.id),
294
+ name: String(row.name),
295
+ description: String(row.description),
296
+ steps: JSON.parse(String(row.steps)),
297
+ trigger_event: String(row.trigger_event),
298
+ created_at: String(row.created_at)
299
+ };
300
+ _definitions.set(def.id, def);
301
+ }
302
+ const insts = await client.execute("SELECT * FROM workflow_instances WHERE status NOT IN ('completed', 'cancelled')");
303
+ for (const row of insts.rows) {
304
+ const inst = {
305
+ id: String(row.id),
306
+ definition_id: String(row.definition_id),
307
+ status: String(row.status),
308
+ current_step: Number(row.current_step),
309
+ step_results: JSON.parse(String(row.step_results)),
310
+ context: JSON.parse(String(row.context)),
311
+ approval_task_id: row.approval_task_id ? String(row.approval_task_id) : void 0,
312
+ created_at: String(row.created_at),
313
+ updated_at: String(row.updated_at)
314
+ };
315
+ _instances.set(inst.id, inst);
316
+ }
317
+ } catch {
318
+ }
319
+ }
320
+
321
+ export {
322
+ createWorkflowDefinition,
323
+ getWorkflowDefinition,
324
+ listWorkflowDefinitions,
325
+ startWorkflow,
326
+ getWorkflowInstance,
327
+ listWorkflowInstances,
328
+ advanceWorkflow,
329
+ runWorkflow,
330
+ approveWorkflowStep,
331
+ persistWorkflows,
332
+ loadWorkflows
333
+ };
@@ -0,0 +1,221 @@
1
+ // src/lib/crdt-sync.ts
2
+ import * as Y from "yjs";
3
+ import { readFileSync, writeFileSync, existsSync, mkdirSync, unlinkSync } from "fs";
4
+ import path from "path";
5
+ import { homedir } from "os";
6
+ var DEFAULT_STATE_PATH = path.join(homedir(), ".exe-os", "crdt-state.bin");
7
+ var _statePathOverride = null;
8
+ function getStatePath() {
9
+ return _statePathOverride ?? DEFAULT_STATE_PATH;
10
+ }
11
+ function _setStatePath(p) {
12
+ _statePathOverride = p;
13
+ }
14
+ var doc = null;
15
+ function initCrdtDoc() {
16
+ if (doc) return doc;
17
+ doc = new Y.Doc();
18
+ const sp = getStatePath();
19
+ if (existsSync(sp)) {
20
+ try {
21
+ const state = readFileSync(sp);
22
+ Y.applyUpdate(doc, new Uint8Array(state));
23
+ } catch {
24
+ console.warn("[crdt-sync] WARN: corrupted state file, rebuilding from DB");
25
+ try {
26
+ unlinkSync(sp);
27
+ } catch {
28
+ }
29
+ rebuildFromDb().catch((err) => {
30
+ console.warn("[crdt-sync] rebuild from DB failed:", err);
31
+ });
32
+ }
33
+ }
34
+ doc.on("update", () => {
35
+ persistState();
36
+ });
37
+ return doc;
38
+ }
39
+ function getMemoriesMap() {
40
+ const d = initCrdtDoc();
41
+ return d.getMap("memories");
42
+ }
43
+ function getBehaviorsMap() {
44
+ const d = initCrdtDoc();
45
+ return d.getMap("behaviors");
46
+ }
47
+ function applyRemoteUpdate(update) {
48
+ const d = initCrdtDoc();
49
+ Y.applyUpdate(d, update);
50
+ }
51
+ function getFullState() {
52
+ const d = initCrdtDoc();
53
+ return Y.encodeStateAsUpdate(d);
54
+ }
55
+ function getDiffUpdate(remoteStateVector) {
56
+ const d = initCrdtDoc();
57
+ return Y.encodeStateAsUpdate(d, remoteStateVector);
58
+ }
59
+ function getStateVector() {
60
+ const d = initCrdtDoc();
61
+ return Y.encodeStateVector(d);
62
+ }
63
+ function importExistingMemories(memories) {
64
+ const map = getMemoriesMap();
65
+ const d = initCrdtDoc();
66
+ let imported = 0;
67
+ d.transact(() => {
68
+ for (const mem of memories) {
69
+ if (!mem.id) continue;
70
+ if (map.has(mem.id)) continue;
71
+ const entry = new Y.Map();
72
+ entry.set("id", mem.id);
73
+ entry.set("agent_id", mem.agent_id ?? null);
74
+ entry.set("agent_role", mem.agent_role ?? null);
75
+ entry.set("session_id", mem.session_id ?? null);
76
+ entry.set("timestamp", mem.timestamp ?? null);
77
+ entry.set("tool_name", mem.tool_name ?? null);
78
+ entry.set("project_name", mem.project_name ?? null);
79
+ entry.set("has_error", mem.has_error ?? 0);
80
+ entry.set("raw_text", mem.raw_text ?? "");
81
+ entry.set("version", mem.version ?? 0);
82
+ entry.set("author_device_id", mem.author_device_id ?? null);
83
+ entry.set("scope", mem.scope ?? "business");
84
+ map.set(mem.id, entry);
85
+ imported++;
86
+ }
87
+ });
88
+ return imported;
89
+ }
90
+ function importExistingBehaviors(behaviors) {
91
+ const map = getBehaviorsMap();
92
+ const d = initCrdtDoc();
93
+ let imported = 0;
94
+ d.transact(() => {
95
+ for (const beh of behaviors) {
96
+ if (!beh.id) continue;
97
+ if (map.has(beh.id)) continue;
98
+ const entry = new Y.Map();
99
+ entry.set("id", beh.id);
100
+ entry.set("agent_id", beh.agent_id ?? null);
101
+ entry.set("project_name", beh.project_name ?? null);
102
+ entry.set("domain", beh.domain ?? null);
103
+ entry.set("content", beh.content ?? null);
104
+ entry.set("active", beh.active ?? 1);
105
+ entry.set("priority", beh.priority ?? "p1");
106
+ entry.set("created_at", beh.created_at ?? null);
107
+ entry.set("updated_at", beh.updated_at ?? null);
108
+ map.set(beh.id, entry);
109
+ imported++;
110
+ }
111
+ });
112
+ return imported;
113
+ }
114
+ function readAllMemories() {
115
+ const map = getMemoriesMap();
116
+ const records = [];
117
+ map.forEach((entry, id) => {
118
+ records.push({
119
+ id,
120
+ agent_id: entry.get("agent_id"),
121
+ agent_role: entry.get("agent_role"),
122
+ session_id: entry.get("session_id"),
123
+ timestamp: entry.get("timestamp"),
124
+ tool_name: entry.get("tool_name"),
125
+ project_name: entry.get("project_name"),
126
+ has_error: entry.get("has_error"),
127
+ raw_text: entry.get("raw_text"),
128
+ version: entry.get("version"),
129
+ author_device_id: entry.get("author_device_id"),
130
+ scope: entry.get("scope"),
131
+ session_scope: entry.get("session_scope")
132
+ });
133
+ });
134
+ return records;
135
+ }
136
+ function readAllBehaviors() {
137
+ const map = getBehaviorsMap();
138
+ const records = [];
139
+ map.forEach((entry, id) => {
140
+ records.push({
141
+ id,
142
+ agent_id: entry.get("agent_id"),
143
+ project_name: entry.get("project_name"),
144
+ domain: entry.get("domain"),
145
+ content: entry.get("content"),
146
+ active: entry.get("active"),
147
+ priority: entry.get("priority"),
148
+ created_at: entry.get("created_at"),
149
+ updated_at: entry.get("updated_at")
150
+ });
151
+ });
152
+ return records;
153
+ }
154
+ function onUpdate(callback) {
155
+ const d = initCrdtDoc();
156
+ const handler = (update) => callback(update);
157
+ d.on("update", handler);
158
+ return () => d.off("update", handler);
159
+ }
160
+ function persistState() {
161
+ if (!doc) return;
162
+ try {
163
+ const sp = getStatePath();
164
+ const dir = path.dirname(sp);
165
+ if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
166
+ const state = Y.encodeStateAsUpdate(doc);
167
+ writeFileSync(sp, Buffer.from(state));
168
+ } catch {
169
+ }
170
+ }
171
+ function isCrdtSyncEnabled() {
172
+ return process.env.EXE_CRDT_SYNC === "1";
173
+ }
174
+ async function rebuildFromDb() {
175
+ const { getClient } = await import("./lib/database.js");
176
+ const client = getClient();
177
+ const result = await client.execute(
178
+ "SELECT id, agent_id, agent_role, session_id, timestamp, tool_name, project_name, has_error, raw_text, version, author_device_id, scope, session_scope FROM memories"
179
+ );
180
+ const memories = result.rows.map((row) => ({
181
+ id: String(row.id),
182
+ agent_id: row.agent_id,
183
+ agent_role: row.agent_role,
184
+ session_id: row.session_id,
185
+ timestamp: row.timestamp,
186
+ tool_name: row.tool_name,
187
+ project_name: row.project_name,
188
+ has_error: row.has_error,
189
+ raw_text: row.raw_text,
190
+ version: row.version,
191
+ author_device_id: row.author_device_id,
192
+ scope: row.scope,
193
+ session_scope: row.session_scope
194
+ }));
195
+ const count = importExistingMemories(memories);
196
+ persistState();
197
+ return count;
198
+ }
199
+ function destroyCrdtDoc() {
200
+ if (doc) {
201
+ doc.destroy();
202
+ doc = null;
203
+ }
204
+ }
205
+
206
+ export {
207
+ _setStatePath,
208
+ initCrdtDoc,
209
+ applyRemoteUpdate,
210
+ getFullState,
211
+ getDiffUpdate,
212
+ getStateVector,
213
+ importExistingMemories,
214
+ importExistingBehaviors,
215
+ readAllMemories,
216
+ readAllBehaviors,
217
+ onUpdate,
218
+ isCrdtSyncEnabled,
219
+ rebuildFromDb,
220
+ destroyCrdtDoc
221
+ };
@@ -0,0 +1,81 @@
1
+ // src/bin/fast-db-init.ts
2
+ async function fastDbInit() {
3
+ const { isInitialized, getClient, setExternalClient } = await import("./lib/database.js");
4
+ if (isInitialized()) {
5
+ return getClient();
6
+ }
7
+ const forceDirect = process.env.EXE_DB_DIRECT === "1" || process.env.EXE_DB_READONLY === "1" || process.env.EXE_SKIP_DAEMON === "1";
8
+ if (!forceDirect) {
9
+ try {
10
+ const { connectEmbedDaemon, sendDaemonRequest, isClientConnected, disconnectClient } = await import("./lib/exe-daemon-client.js");
11
+ const { deserializeResultSet } = await import("./daemon-protocol-XW2OLNBS.js");
12
+ await Promise.race([
13
+ connectEmbedDaemon(),
14
+ new Promise((_, reject) => setTimeout(() => reject(new Error("Daemon socket timeout (2s)")), 2e3))
15
+ ]);
16
+ if (isClientConnected()) {
17
+ const daemonClient = {
18
+ async execute(stmt) {
19
+ const sql = typeof stmt === "string" ? stmt : stmt.sql;
20
+ const args = typeof stmt === "string" ? [] : Array.isArray(stmt.args) ? stmt.args : [];
21
+ const resp = await sendDaemonRequest({ type: "db-execute", sql, args });
22
+ if (resp.error) throw new Error(String(resp.error));
23
+ if (resp.db) return deserializeResultSet(resp.db);
24
+ throw new Error("Unexpected daemon response");
25
+ },
26
+ async batch(stmts, mode) {
27
+ const statements = stmts.map((s) => {
28
+ const sql = typeof s === "string" ? s : s.sql;
29
+ const args = typeof s === "string" ? [] : Array.isArray(s.args) ? s.args : [];
30
+ return { sql, args };
31
+ });
32
+ const resp = await sendDaemonRequest({ type: "db-batch", statements, mode: mode ?? "deferred" });
33
+ if (resp.error) throw new Error(String(resp.error));
34
+ const batchResults = resp["db-batch"];
35
+ if (batchResults) return batchResults.map(deserializeResultSet);
36
+ throw new Error("Unexpected daemon batch response");
37
+ },
38
+ async transaction(_mode) {
39
+ throw new Error("Transactions not supported via daemon socket");
40
+ },
41
+ async executeMultiple(_sql) {
42
+ throw new Error("executeMultiple not supported via daemon socket");
43
+ },
44
+ async migrate(_stmts) {
45
+ throw new Error("migrate not supported via daemon socket");
46
+ },
47
+ sync() {
48
+ return Promise.resolve(void 0);
49
+ },
50
+ close() {
51
+ },
52
+ get closed() {
53
+ return false;
54
+ },
55
+ get protocol() {
56
+ return "file";
57
+ }
58
+ };
59
+ try {
60
+ await daemonClient.execute("SELECT 1");
61
+ } catch {
62
+ try {
63
+ disconnectClient();
64
+ } catch {
65
+ }
66
+ throw new Error("Daemon socket validation failed");
67
+ }
68
+ setExternalClient(daemonClient);
69
+ return daemonClient;
70
+ }
71
+ } catch {
72
+ }
73
+ }
74
+ const { initStore } = await import("./lib/store.js");
75
+ await initStore({ lightweight: true });
76
+ return getClient();
77
+ }
78
+
79
+ export {
80
+ fastDbInit
81
+ };
@@ -0,0 +1,70 @@
1
+ import {
2
+ loadEmployees
3
+ } from "./chunk-V6LOEOXG.js";
4
+
5
+ // src/lib/agent-symlinks.ts
6
+ import os from "os";
7
+ import path from "path";
8
+ import {
9
+ existsSync,
10
+ lstatSync,
11
+ mkdirSync,
12
+ readlinkSync,
13
+ symlinkSync
14
+ } from "fs";
15
+ function claudeAgentsDir(homeDir) {
16
+ return path.join(homeDir, ".claude", "agents");
17
+ }
18
+ function identitySourcePath(homeDir, agentId) {
19
+ return path.join(homeDir, ".exe-os", "identity", `${agentId}.md`);
20
+ }
21
+ function claudeAgentLinkPath(homeDir, agentId) {
22
+ return path.join(claudeAgentsDir(homeDir), `${agentId}.md`);
23
+ }
24
+ function ensureAgentSymlink(agentId, homeDir = os.homedir()) {
25
+ const target = identitySourcePath(homeDir, agentId);
26
+ const link = claudeAgentLinkPath(homeDir, agentId);
27
+ mkdirSync(claudeAgentsDir(homeDir), { recursive: true });
28
+ if (existsSync(link)) {
29
+ let stat;
30
+ try {
31
+ stat = lstatSync(link);
32
+ } catch {
33
+ return { agentId, action: "conflict", target, link, conflict: "stat_failed" };
34
+ }
35
+ if (!stat.isSymbolicLink()) {
36
+ return { agentId, action: "conflict", target, link, conflict: "regular_file" };
37
+ }
38
+ let currentTarget;
39
+ try {
40
+ currentTarget = readlinkSync(link);
41
+ } catch {
42
+ return { agentId, action: "conflict", target, link, conflict: "readlink_failed" };
43
+ }
44
+ if (currentTarget === target) {
45
+ return { agentId, action: "already_correct", target, link };
46
+ }
47
+ return { agentId, action: "conflict", target, link, conflict: `points_to:${currentTarget}` };
48
+ }
49
+ try {
50
+ symlinkSync(target, link);
51
+ } catch (err) {
52
+ return {
53
+ agentId,
54
+ action: "conflict",
55
+ target,
56
+ link,
57
+ conflict: err instanceof Error ? err.message : String(err)
58
+ };
59
+ }
60
+ return { agentId, action: "created", target, link };
61
+ }
62
+ async function ensureAllAgentSymlinks(homeDir = os.homedir()) {
63
+ const employees = await loadEmployees();
64
+ return employees.map((emp) => ensureAgentSymlink(emp.name, homeDir));
65
+ }
66
+
67
+ export {
68
+ ensureAgentSymlink,
69
+ ensureAllAgentSymlinks
70
+ };