@askexenow/exe-os 0.9.296 → 0.9.298
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/deploy/compose/.env.customer.example +6 -1
- package/deploy/compose/.env.example +6 -1
- package/deploy/compose/docker-compose.yml +24 -5
- package/deploy/compose/generate-env.ts +20 -2
- package/deploy/compose/setup.sh +10 -1
- package/deploy/stack-manifests/v0.9.json +1 -1
- package/dist/active-agent-3JXJQ2GZ.js +27 -0
- package/dist/active-agent-XK54VI3S.js +28 -0
- package/dist/agentic-ontology-BPJOT2H2.js +25 -0
- package/dist/backfill-metadata-OTLLYTX4.js +600 -0
- package/dist/behaviors-BGEUHF7D.js +46 -0
- package/dist/bin/agentic-ontology-backfill.js +5 -5
- package/dist/bin/agentic-reflection-backfill.js +6 -6
- package/dist/bin/agentic-semantic-label.js +5 -5
- package/dist/bin/backfill-conversations.js +4 -4
- package/dist/bin/backfill-responses.js +4 -4
- package/dist/bin/backfill-vectors.js +5 -5
- package/dist/bin/bulk-sync-postgres.js +7 -7
- package/dist/bin/cc-doctor.js +5 -4
- package/dist/bin/cleanup-stale-review-tasks.js +9 -9
- package/dist/bin/cli.js +15 -15
- package/dist/bin/exe-agent-config.js +2 -2
- package/dist/bin/exe-agent.js +13 -13
- package/dist/bin/exe-assign.js +5 -5
- package/dist/bin/exe-boot.js +32 -17
- package/dist/bin/exe-call.js +4 -4
- package/dist/bin/exe-cloud.js +7 -7
- package/dist/bin/exe-dispatch.js +9 -9
- package/dist/bin/exe-doctor.js +2 -2
- package/dist/bin/exe-export-behaviors.js +7 -7
- package/dist/bin/exe-forget.js +6 -6
- package/dist/bin/exe-gateway.js +7 -7
- package/dist/bin/exe-healthcheck.js +5 -4
- package/dist/bin/exe-heartbeat.js +9 -9
- package/dist/bin/exe-kill.js +12 -12
- package/dist/bin/exe-launch-agent.js +25 -16
- package/dist/bin/exe-new-employee.js +6 -6
- package/dist/bin/exe-pending-messages.js +10 -10
- package/dist/bin/exe-pending-notifications.js +9 -9
- package/dist/bin/exe-pending-reviews.js +9 -9
- package/dist/bin/exe-rename.js +4 -4
- package/dist/bin/exe-review.js +11 -11
- package/dist/bin/exe-search.js +5 -5
- package/dist/bin/exe-session-cleanup.js +14 -14
- package/dist/bin/exe-settings.js +8 -8
- package/dist/bin/exe-start-codex.js +11 -11
- package/dist/bin/exe-start-opencode.js +8 -8
- package/dist/bin/exe-status.js +10 -10
- package/dist/bin/exe-team.js +3 -3
- package/dist/bin/git-sweep.js +10 -10
- package/dist/bin/graph-backfill.js +4 -4
- package/dist/bin/graph-export.js +5 -5
- package/dist/bin/import-history.js +7 -7
- package/dist/bin/install-launchd.js +10 -124
- package/dist/bin/install.js +21 -12
- package/dist/bin/intercom-check.js +4 -4
- package/dist/bin/mcp-sessions.js +2 -2
- package/dist/bin/orchestration-metrics.js +4 -4
- package/dist/bin/postgres-agentic-reflection-backfill.js +2 -2
- package/dist/bin/postgres-agentic-semantic-backfill.js +1 -1
- package/dist/bin/scan-tasks.js +9 -9
- package/dist/bin/setup.js +1 -1
- package/dist/bin/shard-migrate.js +4 -4
- package/dist/bin/stack-update.js +27 -3
- package/dist/capability-cards-KR7BOS2H.js +89 -0
- package/dist/capacity-monitor-CQFYTU45.js +51 -0
- package/dist/catchup-brief-HNT2CYJQ.js +175 -0
- package/dist/cc-binary-detect-4B25R3TO.js +15 -0
- package/dist/chunk-2DQIQXHX.js +204 -0
- package/dist/chunk-2DWYR2LJ.js +395 -0
- package/dist/chunk-2MSLUPJA.js +70 -0
- package/dist/chunk-2P5KBHJH.js +362 -0
- package/dist/chunk-2QGG6GG3.js +4388 -0
- package/dist/chunk-2XR6OX3M.js +181 -0
- package/dist/chunk-3REXR56D.js +98 -0
- package/dist/chunk-4FEZF2HJ.js +184 -0
- package/dist/chunk-54PQ35JV.js +244 -0
- package/dist/chunk-5ALR7GCX.js +33 -0
- package/dist/chunk-5GJ5MHC3.js +1094 -0
- package/dist/chunk-5IIJUSVD.js +240 -0
- package/dist/chunk-5XM7CTLK.js +199 -0
- package/dist/chunk-6GQMQJE2.js +331 -0
- package/dist/chunk-7C4K7HSF.js +262 -0
- package/dist/chunk-AAFTYJ5R.js +185 -0
- package/dist/chunk-ANIZN35L.js +284 -0
- package/dist/chunk-AOXVDJ7W.js +150 -0
- package/dist/chunk-AR3HN5SA.js +76 -0
- package/dist/chunk-BFFM7FF4.js +214 -0
- package/dist/chunk-CVJYNRYF.js +50 -0
- package/dist/chunk-CXEY5CE2.js +81 -0
- package/dist/chunk-CY4IRJ2I.js +381 -0
- package/dist/chunk-DBNTPP7Q.js +1079 -0
- package/dist/chunk-DTLYO26W.js +402 -0
- package/dist/chunk-EESPF5VS.js +1350 -0
- package/dist/chunk-EN4D3BCA.js +2135 -0
- package/dist/chunk-EYDBWKYI.js +304 -0
- package/dist/chunk-FCSS3YHS.js +348 -0
- package/dist/chunk-G4VSF4DA.js +630 -0
- package/dist/chunk-GEF6EHCW.js +197 -0
- package/dist/chunk-GXDV35ZN.js +735 -0
- package/dist/chunk-HJWT6TFU.js +97 -0
- package/dist/chunk-HQD3IPZA.js +14597 -0
- package/dist/chunk-I3IW6AAX.js +3342 -0
- package/dist/chunk-I4JYP7CK.js +535 -0
- package/dist/chunk-J2VWNIYC.js +167 -0
- package/dist/chunk-JK5OLEM6.js +227 -0
- package/dist/chunk-JVMP77TZ.js +1186 -0
- package/dist/chunk-KJ5DAVIP.js +122 -0
- package/dist/chunk-KPP2AYJV.js +333 -0
- package/dist/chunk-L2WWAOQF.js +455 -0
- package/dist/chunk-L3STXXCO.js +731 -0
- package/dist/chunk-LMX434DW.js +38 -0
- package/dist/chunk-LP4NNUZN.js +58 -0
- package/dist/chunk-MN7Q23PF.js +157 -0
- package/dist/chunk-O4QLYWMC.js +668 -0
- package/dist/chunk-OP5W524C.js +85 -0
- package/dist/chunk-OQ336FHE.js +836 -0
- package/dist/chunk-P7WAPK6X.js +54 -0
- package/dist/chunk-PLM4JJHE.js +128 -0
- package/dist/chunk-POTMDICN.js +1352 -0
- package/dist/chunk-POZYABJT.js +567 -0
- package/dist/chunk-PQG2IQNN.js +280 -0
- package/dist/chunk-PUGKVPCC.js +210 -0
- package/dist/chunk-QE6AI57N.js +1158 -0
- package/dist/chunk-QNCZDDVW.js +448 -0
- package/dist/chunk-QZIYE2QV.js +456 -0
- package/dist/chunk-RXOHALES.js +345 -0
- package/dist/chunk-SGUSCL3H.js +129 -0
- package/dist/chunk-SWOGQD57.js +85 -0
- package/dist/chunk-SZLIO4SL.js +128 -0
- package/dist/chunk-T2USDSC2.js +221 -0
- package/dist/chunk-UKE7MZVO.js +382 -0
- package/dist/chunk-VSRJPOZD.js +290 -0
- package/dist/chunk-WCQ3Y5LB.js +2162 -0
- package/dist/chunk-WHBT6M3P.js +30 -0
- package/dist/chunk-WR6ANODF.js +57 -0
- package/dist/chunk-X7ADWEZ7.js +171 -0
- package/dist/chunk-Y4QZXMCD.js +123 -0
- package/dist/chunk-Y4WA4CUW.js +377 -0
- package/dist/chunk-YUOUHUAJ.js +127 -0
- package/dist/chunk-YXC3OWWW.js +128 -0
- package/dist/co-activation-EN7HT734.js +74 -0
- package/dist/co-occurrence-TRPHUCSC.js +95 -0
- package/dist/core-memory-TVMGLIJ7.js +110 -0
- package/dist/crdt-sync-WOMERQIS.js +33 -0
- package/dist/crm-webhook-Q5Z74FDJ.js +10 -0
- package/dist/cto-delegation-gate-NEMNMLXB.js +280 -0
- package/dist/daemon-orchestration-RYDUCL24.js +143 -0
- package/dist/db-backup-Z3E3LHZK.js +43 -0
- package/dist/doc-graph-extractor-TSCKGSB5.js +133 -0
- package/dist/dreaming-42LRG6AO.js +34 -0
- package/dist/exe-drift-SJ6OTCQV.js +70 -0
- package/dist/exe-export-SRDDONTU.js +77 -0
- package/dist/exe-import-PWHXRFLN.js +80 -0
- package/dist/exe-key-GH6ITI5C.js +673 -0
- package/dist/exe-snapshot-RVLH5PJZ.js +338 -0
- package/dist/fast-db-init-CM4XPET2.js +7 -0
- package/dist/gateway/index.js +14 -14
- package/dist/git-staleness-7EFCUGT2.js +112 -0
- package/dist/git-task-sweep-6DR24G3Y.js +42 -0
- package/dist/global-procedures-NXLOLU7Y.js +22 -0
- package/dist/graph-auto-extract-5F3PLBCK.js +183 -0
- package/dist/hooks/bug-report-worker.js +11 -11
- package/dist/hooks/codex-stop-task-finalizer.js +11 -11
- package/dist/hooks/commit-complete.js +11 -11
- package/dist/hooks/error-recall.js +10 -7
- package/dist/hooks/exe-heartbeat-hook.js +3 -3
- package/dist/hooks/ingest.js +6 -6
- package/dist/hooks/instructions-loaded.js +4 -4
- package/dist/hooks/manifest.json +19 -19
- package/dist/hooks/notification.js +4 -4
- package/dist/hooks/post-compact.js +10 -10
- package/dist/hooks/post-tool-combined.js +5 -5
- package/dist/hooks/pre-compact.js +11 -11
- package/dist/hooks/pre-tool-use.js +14 -14
- package/dist/hooks/prompt-submit.js +26 -22
- package/dist/hooks/session-end.js +15 -15
- package/dist/hooks/session-start.js +12 -12
- package/dist/hooks/stop.js +14 -14
- package/dist/hooks/subagent-stop.js +10 -10
- package/dist/hooks/summary-worker.js +14 -14
- package/dist/index.js +19 -19
- package/dist/installer-5WBAZKSI.js +344 -0
- package/dist/installer-ENK2QYTC.js +298 -0
- package/dist/installer-TUO7KCRN.js +40 -0
- package/dist/lib/cloud-sync.js +7 -7
- package/dist/lib/consolidation.js +5 -5
- package/dist/lib/database.js +4 -2
- package/dist/lib/db-read-worker-client.js +121 -0
- package/dist/lib/db-read-worker.js +73 -0
- package/dist/lib/db.js +4 -2
- package/dist/lib/employee-templates.js +4 -4
- package/dist/lib/employees.js +2 -2
- package/dist/lib/exe-daemon.js +110 -87
- package/dist/lib/hybrid-search.js +5 -5
- package/dist/lib/identity.js +2 -2
- package/dist/lib/messaging.js +9 -9
- package/dist/lib/reminders.js +3 -3
- package/dist/lib/schedules.js +5 -5
- package/dist/lib/session-registry.js +4 -4
- package/dist/lib/skill-learning.js +6 -6
- package/dist/lib/store.js +4 -4
- package/dist/lib/task-router.js +3 -3
- package/dist/lib/tasks.js +10 -10
- package/dist/lib/tmux-routing.js +8 -8
- package/dist/lib/token-spend.js +3 -3
- package/dist/mcp/register-tools.js +56 -55
- package/dist/mcp/server.js +58 -57
- package/dist/mcp/tools/complete-reminder.js +4 -4
- package/dist/mcp/tools/create-reminder.js +4 -4
- package/dist/mcp/tools/create-task.js +12 -12
- package/dist/mcp/tools/deactivate-behavior.js +7 -7
- package/dist/mcp/tools/list-reminders.js +4 -4
- package/dist/mcp/tools/list-tasks.js +12 -12
- package/dist/mcp/tools/send-message.js +11 -11
- package/dist/mcp/tools/update-task.js +11 -11
- package/dist/mcp-http-config-FA6LWCTD.js +31 -0
- package/dist/memory-cards-4QRWCJ54.js +180 -0
- package/dist/memory-graph-extractor-HCS4XTQK.js +22 -0
- package/dist/memory-poisoning-defense-7I4LY4VL.js +224 -0
- package/dist/memory-reflection-ZSSO6RFR.js +244 -0
- package/dist/notifications-VQJCTOMC.js +47 -0
- package/dist/orchestration-events-UFRQWTRS.js +27 -0
- package/dist/orchestrator-ZSSTRMDC.js +35 -0
- package/dist/pipeline-router-U7WWUVKV.js +15 -0
- package/dist/plan-limits-KVFTHSQU.js +28 -0
- package/dist/project-boot-KOGUVIQ4.js +299 -0
- package/dist/projection-worker-OMUSXRHO.js +1084 -0
- package/dist/prospective-memory-PC72YWLY.js +232 -0
- package/dist/reranker-E3MOR2MC.js +19 -0
- package/dist/retrieval-health-OEHPZH65.js +12 -0
- package/dist/review-polling-4GWZSSSQ.js +126 -0
- package/dist/runtime/index.js +11 -11
- package/dist/session-events-A3L5KUHB.js +38 -0
- package/dist/session-kill-telemetry-UFJY57N2.js +31 -0
- package/dist/session-scope-5MT6U7CR.js +88 -0
- package/dist/setup-wizard-NZE2I7M5.js +12 -0
- package/dist/skill-refinement-Q6USTB35.js +159 -0
- package/dist/steward-gate-XOYAMKNY.js +15 -0
- package/dist/task-enforcement-MQ4TKLAN.js +506 -0
- package/dist/task-scope-AWFGZWPM.js +37 -0
- package/dist/tasks-crud-LMPAYXKS.js +79 -0
- package/dist/tasks-notify-6DZOY3MH.js +40 -0
- package/dist/tasks-review-TMBMXNUJ.js +49 -0
- package/dist/telemetry-upload-C2PKRA26.js +741 -0
- package/dist/token-budget-HOOQPFKR.js +86 -0
- package/dist/tool-telemetry-EJVBIKOS.js +17 -0
- package/dist/tui/App.js +16 -16
- package/dist/tui-data-6HIDQFN7.js +260 -0
- package/dist/wiki-acl-DOBVII5N.js +111 -0
- package/dist/worker-gate-ZH5PK25Z.js +21 -0
- package/dist/workflow-engine-SGU6WUWF.js +28 -0
- package/dist/worktree-NRQVJ2M4.js +28 -0
- package/dist/worktree-sweep-FBEHEPZO.js +21 -0
- package/package.json +1 -1
- package/release-notes.json +88 -88
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getActiveAgent
|
|
3
|
+
} from "./chunk-AAFTYJ5R.js";
|
|
4
|
+
import {
|
|
5
|
+
listTasks
|
|
6
|
+
} from "./chunk-2QGG6GG3.js";
|
|
7
|
+
import {
|
|
8
|
+
getAgentContext
|
|
9
|
+
} from "./chunk-GJV3WDWM.js";
|
|
10
|
+
import {
|
|
11
|
+
isCoordinatorName
|
|
12
|
+
} from "./chunk-I3IW6AAX.js";
|
|
13
|
+
|
|
14
|
+
// src/mcp/tools/list-tasks.ts
|
|
15
|
+
import { z } from "zod";
|
|
16
|
+
function registerListTasks(server) {
|
|
17
|
+
server.registerTool(
|
|
18
|
+
"list_tasks",
|
|
19
|
+
{
|
|
20
|
+
title: "List Tasks",
|
|
21
|
+
description: "Query tasks by assignee, status, project, or priority. Defaults to current project. Pass project_name='all' for all projects. When querying your own tasks, project filter is skipped automatically.",
|
|
22
|
+
inputSchema: {
|
|
23
|
+
assigned_to: z.string().optional().describe("Filter by employee name"),
|
|
24
|
+
status: z.enum(["open", "in_progress", "done", "needs_review", "blocked", "cancelled", "closed"]).optional().describe("Filter by status. Default: active tasks only (excludes closed/cancelled)"),
|
|
25
|
+
project_name: z.string().optional().describe("Project name. Defaults to current project. Pass 'all' for all projects."),
|
|
26
|
+
priority: z.enum(["p0", "p1", "p2"]).optional().describe("Filter by priority"),
|
|
27
|
+
cross_session: z.boolean().optional().describe("When true, return tasks from ALL coordinator sessions (read-only). Default: false.")
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
async ({ assigned_to, status, project_name, priority, cross_session }) => {
|
|
31
|
+
try {
|
|
32
|
+
const { agentId } = getActiveAgent();
|
|
33
|
+
const isReviewQueue = status === "needs_review";
|
|
34
|
+
const shouldDefaultToOwnQueue = !assigned_to && !isReviewQueue && !isCoordinatorName(agentId);
|
|
35
|
+
const effectiveAssignedTo = assigned_to ?? (shouldDefaultToOwnQueue ? agentId : void 0);
|
|
36
|
+
const effectiveReviewer = !assigned_to && isReviewQueue ? agentId : void 0;
|
|
37
|
+
const isOwnQuery = effectiveAssignedTo === agentId;
|
|
38
|
+
const callerSession = getAgentContext()?.sessionHint || process.env.EXE_SESSION_NAME || process.env.EXE_SESSION || null;
|
|
39
|
+
const resolvedProject = project_name && project_name !== "all" ? project_name : null;
|
|
40
|
+
const effectiveCrossSession = cross_session === true;
|
|
41
|
+
const identityAmbiguous = !callerSession && (agentId === "default" || !agentId);
|
|
42
|
+
let tasks = await listTasks({
|
|
43
|
+
assignedTo: effectiveAssignedTo,
|
|
44
|
+
reviewer: effectiveReviewer,
|
|
45
|
+
status,
|
|
46
|
+
projectName: resolvedProject,
|
|
47
|
+
priority,
|
|
48
|
+
crossSession: effectiveCrossSession,
|
|
49
|
+
isOwnQuery: !!isOwnQuery,
|
|
50
|
+
callerSession
|
|
51
|
+
});
|
|
52
|
+
let recoveredCrossSession = false;
|
|
53
|
+
if (tasks.length === 0 && identityAmbiguous && !effectiveCrossSession) {
|
|
54
|
+
const crossTasks = await listTasks({
|
|
55
|
+
// Drop the own-queue assignee default — identity is unreliable here.
|
|
56
|
+
assignedTo: assigned_to,
|
|
57
|
+
reviewer: effectiveReviewer,
|
|
58
|
+
status,
|
|
59
|
+
projectName: resolvedProject,
|
|
60
|
+
priority,
|
|
61
|
+
crossSession: true,
|
|
62
|
+
isOwnQuery: false,
|
|
63
|
+
callerSession: null
|
|
64
|
+
});
|
|
65
|
+
if (crossTasks.length > 0) {
|
|
66
|
+
tasks = crossTasks;
|
|
67
|
+
recoveredCrossSession = true;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (tasks.length === 0) {
|
|
71
|
+
if (identityAmbiguous) {
|
|
72
|
+
return {
|
|
73
|
+
content: [
|
|
74
|
+
{
|
|
75
|
+
type: "text",
|
|
76
|
+
text: "Could not resolve your session identity (multiple coordinator sessions are live and no per-session MCP header was provided). Task scoping is unreliable, and a cross-session read also returned no rows. If you expect tasks to exist, retry with cross_session=true and an explicit project_name='all', or configure a per-session MCP header (X-Exe-Session). Treat this as 'unknown', NOT 'empty'."
|
|
77
|
+
}
|
|
78
|
+
],
|
|
79
|
+
isError: true
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
content: [{ type: "text", text: "No tasks found." }]
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
const lines = tasks.map((t) => {
|
|
87
|
+
const cpIndicator = t.checkpointCount && t.checkpointCount > 0 ? ` [cp:${t.checkpointCount}]` : "";
|
|
88
|
+
let budgetNote = "";
|
|
89
|
+
if (t.budgetTokens !== null) {
|
|
90
|
+
const pct = Math.round(t.tokensUsed / t.budgetTokens * 100);
|
|
91
|
+
budgetNote = ` [${t.tokensUsed}/${t.budgetTokens} tokens, ${pct}%]`;
|
|
92
|
+
}
|
|
93
|
+
const shortId = t.id.slice(0, 8);
|
|
94
|
+
const showSession = cross_session || recoveredCrossSession;
|
|
95
|
+
const sessionNote = showSession && t.sessionScope ? ` [session:${t.sessionScope}]` : "";
|
|
96
|
+
return `- [${t.priority.toUpperCase()}] ${t.title} (${t.projectName}) \u2014 ${t.status}${cpIndicator}${budgetNote}${sessionNote} \u2192 ${t.assignedTo} [id:${shortId}]`;
|
|
97
|
+
});
|
|
98
|
+
const header = recoveredCrossSession ? `WARNING: session identity was ambiguous (multiple coordinator sessions, no per-session MCP header) \u2014 showing tasks ACROSS ALL sessions. Configure a per-session X-Exe-Session header for scoped results.
|
|
99
|
+
${tasks.length} task(s) (cross-session):` : `${tasks.length} task(s):`;
|
|
100
|
+
return {
|
|
101
|
+
content: [
|
|
102
|
+
{
|
|
103
|
+
type: "text",
|
|
104
|
+
text: `${header}
|
|
105
|
+
${lines.join("\n")}`
|
|
106
|
+
}
|
|
107
|
+
]
|
|
108
|
+
};
|
|
109
|
+
} catch (err) {
|
|
110
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
111
|
+
return {
|
|
112
|
+
content: [{ type: "text", text: `Failed to list tasks: ${msg}` }],
|
|
113
|
+
isError: true
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export {
|
|
121
|
+
registerListTasks
|
|
122
|
+
};
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
import {
|
|
2
|
+
executeAction,
|
|
3
|
+
substituteTemplate
|
|
4
|
+
} from "./chunk-UKE7MZVO.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
|
+
};
|