@useorgx/openclaw-plugin 0.4.8 → 0.7.0

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 (284) hide show
  1. package/README.md +35 -0
  2. package/dashboard/dist/assets/BJgZIVUQ.js +53 -0
  3. package/dashboard/dist/assets/BJgZIVUQ.js.br +0 -0
  4. package/dashboard/dist/assets/BJgZIVUQ.js.gz +0 -0
  5. package/dashboard/dist/assets/BXWDRGm-.js +1 -0
  6. package/dashboard/dist/assets/BXWDRGm-.js.br +0 -0
  7. package/dashboard/dist/assets/BXWDRGm-.js.gz +0 -0
  8. package/dashboard/dist/assets/BgOYB78t.js +4 -0
  9. package/dashboard/dist/assets/BgOYB78t.js.br +0 -0
  10. package/dashboard/dist/assets/BgOYB78t.js.gz +0 -0
  11. package/dashboard/dist/assets/C-KIc3Wc.js.br +0 -0
  12. package/dashboard/dist/assets/C-KIc3Wc.js.gz +0 -0
  13. package/dashboard/dist/assets/CE38zU4U.js +1 -0
  14. package/dashboard/dist/assets/CE38zU4U.js.br +0 -0
  15. package/dashboard/dist/assets/CE38zU4U.js.gz +0 -0
  16. package/dashboard/dist/assets/CFGKRAzG.js +1 -0
  17. package/dashboard/dist/assets/CFGKRAzG.js.br +0 -0
  18. package/dashboard/dist/assets/CFGKRAzG.js.gz +0 -0
  19. package/dashboard/dist/assets/CGGR2GZh.js +1 -0
  20. package/dashboard/dist/assets/CGGR2GZh.js.br +0 -0
  21. package/dashboard/dist/assets/CGGR2GZh.js.gz +0 -0
  22. package/dashboard/dist/assets/CL_wXqR7.js +1 -0
  23. package/dashboard/dist/assets/CL_wXqR7.js.br +0 -0
  24. package/dashboard/dist/assets/CL_wXqR7.js.gz +0 -0
  25. package/dashboard/dist/assets/CPFiTmlw.js +8 -0
  26. package/dashboard/dist/assets/CPFiTmlw.js.br +0 -0
  27. package/dashboard/dist/assets/CPFiTmlw.js.gz +0 -0
  28. package/dashboard/dist/assets/CZZTvkQZ.js +1 -0
  29. package/dashboard/dist/assets/CZZTvkQZ.js.br +0 -0
  30. package/dashboard/dist/assets/CZZTvkQZ.js.gz +0 -0
  31. package/dashboard/dist/assets/{CpJsfbXo.js → CxQ08qFN.js} +2 -2
  32. package/dashboard/dist/assets/CxQ08qFN.js.br +0 -0
  33. package/dashboard/dist/assets/CxQ08qFN.js.gz +0 -0
  34. package/dashboard/dist/assets/D-bf6hEI.js +213 -0
  35. package/dashboard/dist/assets/D-bf6hEI.js.br +0 -0
  36. package/dashboard/dist/assets/D-bf6hEI.js.gz +0 -0
  37. package/dashboard/dist/assets/DG6y9wJI.js +2 -0
  38. package/dashboard/dist/assets/DG6y9wJI.js.br +0 -0
  39. package/dashboard/dist/assets/DG6y9wJI.js.gz +0 -0
  40. package/dashboard/dist/assets/DNxKz-GV.js +1 -0
  41. package/dashboard/dist/assets/DNxKz-GV.js.br +0 -0
  42. package/dashboard/dist/assets/DNxKz-GV.js.gz +0 -0
  43. package/dashboard/dist/assets/DW_rKUic.js +11 -0
  44. package/dashboard/dist/assets/DW_rKUic.js.br +0 -0
  45. package/dashboard/dist/assets/DW_rKUic.js.gz +0 -0
  46. package/dashboard/dist/assets/DbNoijHm.js +1 -0
  47. package/dashboard/dist/assets/DbNoijHm.js.br +0 -0
  48. package/dashboard/dist/assets/DbNoijHm.js.gz +0 -0
  49. package/dashboard/dist/assets/DjcdE6jC.js +2 -0
  50. package/dashboard/dist/assets/DjcdE6jC.js.br +0 -0
  51. package/dashboard/dist/assets/DjcdE6jC.js.gz +0 -0
  52. package/dashboard/dist/assets/FZYuCDnt.js +1 -0
  53. package/dashboard/dist/assets/FZYuCDnt.js.br +0 -0
  54. package/dashboard/dist/assets/FZYuCDnt.js.gz +0 -0
  55. package/dashboard/dist/assets/PAUiij_z.js +1 -0
  56. package/dashboard/dist/assets/PAUiij_z.js.br +0 -0
  57. package/dashboard/dist/assets/PAUiij_z.js.gz +0 -0
  58. package/dashboard/dist/assets/cNrhgGc1.js +8 -0
  59. package/dashboard/dist/assets/cNrhgGc1.js.br +0 -0
  60. package/dashboard/dist/assets/cNrhgGc1.js.gz +0 -0
  61. package/dashboard/dist/assets/h5biQs2I.css +1 -0
  62. package/dashboard/dist/assets/h5biQs2I.css.br +0 -0
  63. package/dashboard/dist/assets/h5biQs2I.css.gz +0 -0
  64. package/dashboard/dist/assets/ic2FaMnh.js +1 -0
  65. package/dashboard/dist/assets/ic2FaMnh.js.br +0 -0
  66. package/dashboard/dist/assets/ic2FaMnh.js.gz +0 -0
  67. package/dashboard/dist/assets/nByHNHoW.js +1 -0
  68. package/dashboard/dist/assets/nByHNHoW.js.br +0 -0
  69. package/dashboard/dist/assets/nByHNHoW.js.gz +0 -0
  70. package/dashboard/dist/assets/qm8xLgv-.css +1 -0
  71. package/dashboard/dist/assets/qm8xLgv-.css.br +0 -0
  72. package/dashboard/dist/assets/qm8xLgv-.css.gz +0 -0
  73. package/dashboard/dist/assets/tS9mbYZi.js +1 -0
  74. package/dashboard/dist/assets/tS9mbYZi.js.br +0 -0
  75. package/dashboard/dist/assets/tS9mbYZi.js.gz +0 -0
  76. package/dashboard/dist/brand/anthropic-mark.svg.br +0 -0
  77. package/dashboard/dist/brand/anthropic-mark.svg.gz +0 -0
  78. package/dashboard/dist/brand/openai-mark.svg.br +0 -0
  79. package/dashboard/dist/brand/openai-mark.svg.gz +0 -0
  80. package/dashboard/dist/brand/openclaw-mark.svg.br +0 -0
  81. package/dashboard/dist/brand/openclaw-mark.svg.gz +0 -0
  82. package/dashboard/dist/brand/xandy-orchestrator.png +0 -0
  83. package/dashboard/dist/index.html +7 -5
  84. package/dashboard/dist/index.html.br +0 -0
  85. package/dashboard/dist/index.html.gz +0 -0
  86. package/dist/activity-actor-fields.js +26 -4
  87. package/dist/activity-store.js +38 -26
  88. package/dist/agent-context-store.js +84 -42
  89. package/dist/agent-run-store.js +49 -28
  90. package/dist/agent-suite.d.ts +9 -0
  91. package/dist/agent-suite.js +150 -17
  92. package/dist/artifacts/artifact-domain-schemas.d.ts +66 -0
  93. package/dist/artifacts/artifact-domain-schemas.js +357 -0
  94. package/dist/artifacts/register-artifact.d.ts +4 -3
  95. package/dist/artifacts/register-artifact.js +170 -57
  96. package/dist/auth/flows.d.ts +47 -0
  97. package/dist/auth/flows.js +169 -0
  98. package/dist/auth-store.js +6 -26
  99. package/dist/byok-store.js +5 -19
  100. package/dist/chat-store.d.ts +157 -0
  101. package/dist/chat-store.js +586 -0
  102. package/dist/cli/orgx.d.ts +66 -0
  103. package/dist/cli/orgx.js +102 -0
  104. package/dist/config/refresh.d.ts +32 -0
  105. package/dist/config/refresh.js +55 -0
  106. package/dist/config/resolution.d.ts +37 -0
  107. package/dist/config/resolution.js +178 -0
  108. package/dist/contracts/client.d.ts +43 -3
  109. package/dist/contracts/client.js +159 -30
  110. package/dist/contracts/retro-schema.d.ts +81 -0
  111. package/dist/contracts/retro-schema.js +80 -0
  112. package/dist/contracts/shared-types.d.ts +306 -0
  113. package/dist/contracts/shared-types.js +179 -0
  114. package/dist/contracts/skill-pack-schema.d.ts +192 -0
  115. package/dist/contracts/skill-pack-schema.js +180 -0
  116. package/dist/contracts/types.d.ts +224 -132
  117. package/dist/contracts/types.js +5 -0
  118. package/dist/entities/auto-assignment.d.ts +36 -0
  119. package/dist/entities/auto-assignment.js +141 -0
  120. package/dist/entity-comment-store.js +5 -25
  121. package/dist/event-sanitization.d.ts +11 -0
  122. package/dist/event-sanitization.js +113 -0
  123. package/dist/fs-utils.js +13 -1
  124. package/dist/gateway-watchdog.d.ts +5 -0
  125. package/dist/gateway-watchdog.js +50 -0
  126. package/dist/hash-utils.d.ts +2 -0
  127. package/dist/hash-utils.js +12 -0
  128. package/dist/hooks/post-reporting-event.mjs +1 -5
  129. package/dist/http/helpers/activity-headline.d.ts +10 -0
  130. package/dist/http/helpers/activity-headline.js +73 -0
  131. package/dist/http/helpers/artifact-fallback.d.ts +13 -0
  132. package/dist/http/helpers/artifact-fallback.js +148 -0
  133. package/dist/http/helpers/auto-continue-engine.d.ts +486 -0
  134. package/dist/http/helpers/auto-continue-engine.js +3563 -0
  135. package/dist/http/helpers/autopilot-operations.d.ts +176 -0
  136. package/dist/http/helpers/autopilot-operations.js +554 -0
  137. package/dist/http/helpers/autopilot-runtime.d.ts +43 -0
  138. package/dist/http/helpers/autopilot-runtime.js +607 -0
  139. package/dist/http/helpers/autopilot-slice-utils.d.ts +56 -0
  140. package/dist/http/helpers/autopilot-slice-utils.js +899 -0
  141. package/dist/http/helpers/decision-mapper.d.ts +52 -0
  142. package/dist/http/helpers/decision-mapper.js +260 -0
  143. package/dist/http/helpers/dispatch-lifecycle.d.ts +119 -0
  144. package/dist/http/helpers/dispatch-lifecycle.js +809 -0
  145. package/dist/http/helpers/hash-utils.d.ts +1 -0
  146. package/dist/http/helpers/hash-utils.js +1 -0
  147. package/dist/http/helpers/kickoff-context.d.ts +12 -0
  148. package/dist/http/helpers/kickoff-context.js +228 -0
  149. package/dist/http/helpers/llm-client.d.ts +47 -0
  150. package/dist/http/helpers/llm-client.js +256 -0
  151. package/dist/http/helpers/mission-control.d.ts +193 -0
  152. package/dist/http/helpers/mission-control.js +1383 -0
  153. package/dist/http/helpers/openclaw-cli.d.ts +37 -0
  154. package/dist/http/helpers/openclaw-cli.js +283 -0
  155. package/dist/http/helpers/runtime-sse.d.ts +20 -0
  156. package/dist/http/helpers/runtime-sse.js +110 -0
  157. package/dist/http/helpers/sentinel-catalog.d.ts +23 -0
  158. package/dist/http/helpers/sentinel-catalog.js +193 -0
  159. package/dist/http/helpers/session-classification.d.ts +9 -0
  160. package/dist/http/helpers/session-classification.js +564 -0
  161. package/dist/http/helpers/slice-experience-v2.d.ts +137 -0
  162. package/dist/http/helpers/slice-experience-v2.js +677 -0
  163. package/dist/http/helpers/slice-run-projections.d.ts +72 -0
  164. package/dist/http/helpers/slice-run-projections.js +860 -0
  165. package/dist/http/helpers/triage-mapper.d.ts +43 -0
  166. package/dist/http/helpers/triage-mapper.js +549 -0
  167. package/dist/http/helpers/value-utils.d.ts +6 -0
  168. package/dist/http/helpers/value-utils.js +72 -0
  169. package/dist/http/helpers/workspace-scope.d.ts +15 -0
  170. package/dist/http/helpers/workspace-scope.js +170 -0
  171. package/dist/http/index.d.ts +88 -0
  172. package/dist/http/index.js +3610 -0
  173. package/dist/http/router.d.ts +23 -0
  174. package/dist/http/router.js +23 -0
  175. package/dist/http/routes/agent-control.d.ts +79 -0
  176. package/dist/http/routes/agent-control.js +684 -0
  177. package/dist/http/routes/agent-suite.d.ts +38 -0
  178. package/dist/http/routes/agent-suite.js +397 -0
  179. package/dist/http/routes/agents-catalog.d.ts +40 -0
  180. package/dist/http/routes/agents-catalog.js +128 -0
  181. package/dist/http/routes/billing.d.ts +23 -0
  182. package/dist/http/routes/billing.js +55 -0
  183. package/dist/http/routes/chat.d.ts +19 -0
  184. package/dist/http/routes/chat.js +522 -0
  185. package/dist/http/routes/debug.d.ts +14 -0
  186. package/dist/http/routes/debug.js +21 -0
  187. package/dist/http/routes/decision-actions.d.ts +20 -0
  188. package/dist/http/routes/decision-actions.js +103 -0
  189. package/dist/http/routes/delegation.d.ts +19 -0
  190. package/dist/http/routes/delegation.js +32 -0
  191. package/dist/http/routes/dispatch-gateway-envelope.d.ts +25 -0
  192. package/dist/http/routes/dispatch-gateway-envelope.js +26 -0
  193. package/dist/http/routes/entities.d.ts +63 -0
  194. package/dist/http/routes/entities.js +440 -0
  195. package/dist/http/routes/entity-dynamic.d.ts +25 -0
  196. package/dist/http/routes/entity-dynamic.js +191 -0
  197. package/dist/http/routes/health.d.ts +22 -0
  198. package/dist/http/routes/health.js +49 -0
  199. package/dist/http/routes/live-legacy.d.ts +115 -0
  200. package/dist/http/routes/live-legacy.js +112 -0
  201. package/dist/http/routes/live-misc.d.ts +81 -0
  202. package/dist/http/routes/live-misc.js +426 -0
  203. package/dist/http/routes/live-snapshot.d.ts +136 -0
  204. package/dist/http/routes/live-snapshot.js +916 -0
  205. package/dist/http/routes/live-terminal.d.ts +11 -0
  206. package/dist/http/routes/live-terminal.js +261 -0
  207. package/dist/http/routes/live-triage.d.ts +61 -0
  208. package/dist/http/routes/live-triage.js +248 -0
  209. package/dist/http/routes/mission-control-actions.d.ts +131 -0
  210. package/dist/http/routes/mission-control-actions.js +1791 -0
  211. package/dist/http/routes/mission-control-read.d.ts +73 -0
  212. package/dist/http/routes/mission-control-read.js +1640 -0
  213. package/dist/http/routes/onboarding.d.ts +34 -0
  214. package/dist/http/routes/onboarding.js +101 -0
  215. package/dist/http/routes/realtime-orchestrator.d.ts +10 -0
  216. package/dist/http/routes/realtime-orchestrator.js +74 -0
  217. package/dist/http/routes/run-control.d.ts +27 -0
  218. package/dist/http/routes/run-control.js +96 -0
  219. package/dist/http/routes/runtime-hooks.d.ts +69 -0
  220. package/dist/http/routes/runtime-hooks.js +437 -0
  221. package/dist/http/routes/sentinels-catalog.d.ts +7 -0
  222. package/dist/http/routes/sentinels-catalog.js +24 -0
  223. package/dist/http/routes/settings-byok.d.ts +23 -0
  224. package/dist/http/routes/settings-byok.js +163 -0
  225. package/dist/http/routes/summary.d.ts +18 -0
  226. package/dist/http/routes/summary.js +49 -0
  227. package/dist/http/routes/usage.d.ts +24 -0
  228. package/dist/http/routes/usage.js +362 -0
  229. package/dist/http/routes/work-artifacts.d.ts +9 -0
  230. package/dist/http/routes/work-artifacts.js +55 -0
  231. package/dist/http/shared-state.d.ts +16 -0
  232. package/dist/http/shared-state.js +1 -0
  233. package/dist/http-handler.d.ts +1 -88
  234. package/dist/http-handler.js +1 -10605
  235. package/dist/index.js +287 -2284
  236. package/dist/json-utils.d.ts +1 -0
  237. package/dist/json-utils.js +8 -0
  238. package/dist/local-openclaw.js +29 -6
  239. package/dist/mcp-client-setup.js +3 -3
  240. package/dist/mcp-http-handler.js +33 -59
  241. package/dist/next-up-queue-store.d.ts +16 -1
  242. package/dist/next-up-queue-store.js +93 -25
  243. package/dist/outbox.d.ts +5 -0
  244. package/dist/outbox.js +113 -9
  245. package/dist/paths.js +24 -5
  246. package/dist/reporting/rollups.d.ts +53 -0
  247. package/dist/reporting/rollups.js +148 -0
  248. package/dist/retro/domain-templates.d.ts +45 -0
  249. package/dist/retro/domain-templates.js +297 -0
  250. package/dist/retro/quality-rubric.d.ts +33 -0
  251. package/dist/retro/quality-rubric.js +213 -0
  252. package/dist/runtime-cleanup.d.ts +18 -0
  253. package/dist/runtime-cleanup.js +87 -0
  254. package/dist/runtime-instance-store.js +5 -31
  255. package/dist/services/background.d.ts +34 -0
  256. package/dist/services/background.js +45 -0
  257. package/dist/services/experiment-randomization.d.ts +21 -0
  258. package/dist/services/experiment-randomization.js +63 -0
  259. package/dist/services/instrumentation.d.ts +29 -0
  260. package/dist/services/instrumentation.js +136 -0
  261. package/dist/skill-pack-state.d.ts +36 -5
  262. package/dist/skill-pack-state.js +273 -29
  263. package/dist/snapshot-store.js +5 -25
  264. package/dist/stores/json-store.d.ts +11 -0
  265. package/dist/stores/json-store.js +42 -0
  266. package/dist/sync/local-agent-telemetry.d.ts +13 -0
  267. package/dist/sync/local-agent-telemetry.js +128 -0
  268. package/dist/sync/outbox-replay.d.ts +55 -0
  269. package/dist/sync/outbox-replay.js +621 -0
  270. package/dist/team-context-store.d.ts +23 -0
  271. package/dist/team-context-store.js +116 -0
  272. package/dist/telemetry/posthog.js +4 -2
  273. package/dist/tools/core-tools.d.ts +72 -0
  274. package/dist/tools/core-tools.js +2270 -0
  275. package/dist/types.d.ts +2 -0
  276. package/dist/types.js +2 -0
  277. package/dist/worker-supervisor.js +23 -0
  278. package/package.json +14 -4
  279. package/dashboard/dist/assets/B3ziCA02.js +0 -8
  280. package/dashboard/dist/assets/BNeJ0kpF.js +0 -1
  281. package/dashboard/dist/assets/BzkiMPmM.js +0 -215
  282. package/dashboard/dist/assets/CUV9IHHi.js +0 -1
  283. package/dashboard/dist/assets/Ie7d9Iq2.css +0 -1
  284. package/dashboard/dist/assets/sAhvFnpk.js +0 -4
@@ -0,0 +1,554 @@
1
+ import { appendToOutbox } from "../../outbox.js";
2
+ import { registerArtifact } from "../../artifacts/register-artifact.js";
3
+ export function createAutopilotOperations(deps) {
4
+ async function registerArtifactSafe(input) {
5
+ const now = new Date().toISOString();
6
+ const name = typeof input.artifact.name === "string" && input.artifact.name.trim().length > 0
7
+ ? input.artifact.name.trim()
8
+ : "";
9
+ if (!name)
10
+ return { ok: false, id: null };
11
+ const artifactType = typeof input.artifact.artifact_type === "string" && input.artifact.artifact_type.trim().length > 0
12
+ ? input.artifact.artifact_type.trim()
13
+ : "other";
14
+ const confidenceScore = typeof input.artifact.confidence_score === "number" &&
15
+ Number.isFinite(input.artifact.confidence_score) &&
16
+ input.artifact.confidence_score >= 0 &&
17
+ input.artifact.confidence_score <= 1
18
+ ? input.artifact.confidence_score
19
+ : null;
20
+ const artifactId = deps.randomUUID();
21
+ const milestoneId = (typeof input.artifact.milestone_id === "string" &&
22
+ input.artifact.milestone_id.trim().length > 0
23
+ ? input.artifact.milestone_id.trim()
24
+ : null) ??
25
+ (typeof input.fallbackMilestoneId === "string" &&
26
+ input.fallbackMilestoneId.trim().length > 0
27
+ ? input.fallbackMilestoneId.trim()
28
+ : null);
29
+ const taskIds = (Array.isArray(input.artifact.task_ids) && input.artifact.task_ids.length > 0
30
+ ? input.artifact.task_ids
31
+ : Array.isArray(input.fallbackTaskIds)
32
+ ? input.fallbackTaskIds
33
+ : [])
34
+ .filter((taskId) => typeof taskId === "string")
35
+ .map((taskId) => taskId.trim())
36
+ .filter(Boolean);
37
+ const verificationSteps = Array.isArray(input.artifact.verification_steps)
38
+ ? input.artifact.verification_steps
39
+ .filter((step) => typeof step === "string")
40
+ .map((step) => step.trim())
41
+ .filter(Boolean)
42
+ : [];
43
+ const descriptionParts = [];
44
+ if (typeof input.artifact.description === "string" && input.artifact.description.trim()) {
45
+ descriptionParts.push(input.artifact.description.trim());
46
+ }
47
+ if (verificationSteps.length > 0) {
48
+ descriptionParts.push(`Verification:\n${verificationSteps.map((step) => `- ${step}`).join("\n")}`);
49
+ }
50
+ const description = descriptionParts.length > 0 ? descriptionParts.join("\n\n") : undefined;
51
+ const hasUuidAgent = typeof input.agentId === "string" &&
52
+ /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(input.agentId);
53
+ const createdByType = hasUuidAgent ? "agent" : "human";
54
+ const createdById = hasUuidAgent ? input.agentId : null;
55
+ try {
56
+ const entityType = milestoneId ? "milestone" : "initiative";
57
+ const entityId = milestoneId ?? input.initiativeId;
58
+ const result = await registerArtifact(deps.client, deps.client.getBaseUrl(), {
59
+ artifact_id: artifactId,
60
+ entity_type: entityType,
61
+ entity_id: entityId,
62
+ name,
63
+ artifact_type: artifactType,
64
+ confidence_score: confidenceScore,
65
+ created_by_type: createdByType,
66
+ created_by_id: createdById,
67
+ description,
68
+ external_url: input.artifact.url ?? null,
69
+ preview_markdown: null,
70
+ status: "draft",
71
+ metadata: {
72
+ source: "autopilot_slice",
73
+ artifact_id: artifactId,
74
+ run_id: input.runId,
75
+ initiative_id: input.initiativeId,
76
+ workstream_id: input.workstreamId,
77
+ milestone_id: milestoneId,
78
+ task_ids: taskIds.length > 0 ? taskIds : null,
79
+ confidence_score: confidenceScore,
80
+ },
81
+ // Make persistence validation opt-in to avoid adding latency to every slice by default.
82
+ validate_persistence: process.env.ORGX_VALIDATE_ARTIFACT_PERSISTENCE === "1",
83
+ });
84
+ if (result.ok) {
85
+ try {
86
+ await deps.emitActivitySafe({
87
+ initiativeId: input.initiativeId,
88
+ runId: input.runId,
89
+ correlationId: input.runId,
90
+ phase: "handoff",
91
+ level: "info",
92
+ message: `Artifact registered: ${name}`,
93
+ progressPct: 100,
94
+ metadata: {
95
+ event: "artifact_registered",
96
+ artifact_id: result.artifact_id ?? artifactId,
97
+ artifact_type: artifactType,
98
+ confidence_score: confidenceScore,
99
+ initiative_id: input.initiativeId,
100
+ workstream_id: input.workstreamId,
101
+ milestone_id: milestoneId,
102
+ task_ids: taskIds,
103
+ agent_id: input.agentId,
104
+ agent_name: input.agentName ?? null,
105
+ executor_agent_id: input.agentId,
106
+ executor_agent_name: input.agentName ?? null,
107
+ source_run_id: input.runId,
108
+ ...(input.isMockWorker ? { mock: true } : {}),
109
+ },
110
+ });
111
+ }
112
+ catch {
113
+ // best effort
114
+ }
115
+ }
116
+ return { ok: result.ok, id: result.artifact_id };
117
+ }
118
+ catch (err) {
119
+ try {
120
+ await appendToOutbox(input.initiativeId, {
121
+ id: deps.randomUUID(),
122
+ type: "artifact",
123
+ timestamp: now,
124
+ payload: {
125
+ artifact_id: artifactId,
126
+ entity_type: milestoneId ? "milestone" : "initiative",
127
+ entity_id: milestoneId ?? input.initiativeId,
128
+ name,
129
+ artifact_type: artifactType,
130
+ confidence_score: confidenceScore,
131
+ created_by_type: createdByType,
132
+ created_by_id: createdById,
133
+ description,
134
+ url: input.artifact.url ?? undefined,
135
+ run_id: input.runId,
136
+ },
137
+ activityItem: {
138
+ id: deps.randomUUID(),
139
+ type: "artifact_created",
140
+ title: name,
141
+ description: description ?? null,
142
+ agentId: input.agentId,
143
+ agentName: input.agentName ?? null,
144
+ requesterAgentId: input.agentId,
145
+ requesterAgentName: input.agentName ?? null,
146
+ executorAgentId: input.agentId,
147
+ executorAgentName: input.agentName ?? null,
148
+ runId: input.runId,
149
+ initiativeId: input.initiativeId,
150
+ timestamp: now,
151
+ phase: "handoff",
152
+ summary: input.artifact.url ?? null,
153
+ metadata: {
154
+ source: "openclaw_local_fallback",
155
+ event: "autopilot_slice_artifact_buffered",
156
+ artifact_type: artifactType,
157
+ confidence_score: confidenceScore,
158
+ artifact_id: artifactId,
159
+ url: input.artifact.url ?? null,
160
+ error: deps.safeErrorMessage(err),
161
+ ...(input.isMockWorker ? { mock: true } : {}),
162
+ },
163
+ },
164
+ });
165
+ }
166
+ catch {
167
+ // best effort
168
+ }
169
+ return { ok: false, id: null };
170
+ }
171
+ }
172
+ async function applyAgentStatusUpdatesSafe(input) {
173
+ const normalizeTaskStatus = (raw) => {
174
+ const normalized = raw.trim().toLowerCase().replace(/\s+/g, "_");
175
+ if (!normalized)
176
+ return null;
177
+ if (normalized === "done")
178
+ return "done";
179
+ if (normalized === "todo")
180
+ return "todo";
181
+ if (normalized === "blocked")
182
+ return "blocked";
183
+ if (normalized === "in_progress")
184
+ return "in_progress";
185
+ // Common synonyms from LMs.
186
+ if (normalized === "completed" || normalized === "complete" || normalized === "finished") {
187
+ return "done";
188
+ }
189
+ if (normalized === "inprogress" || normalized === "running" || normalized === "working") {
190
+ return "in_progress";
191
+ }
192
+ if (normalized === "not_started" || normalized === "planned" || normalized === "pending") {
193
+ return "todo";
194
+ }
195
+ return null;
196
+ };
197
+ const normalizeMilestoneStatus = (raw) => {
198
+ const normalized = raw.trim().toLowerCase().replace(/\s+/g, "_");
199
+ if (!normalized)
200
+ return null;
201
+ if (normalized === "planned")
202
+ return "planned";
203
+ if (normalized === "in_progress")
204
+ return "in_progress";
205
+ if (normalized === "completed")
206
+ return "completed";
207
+ if (normalized === "at_risk")
208
+ return "at_risk";
209
+ if (normalized === "cancelled")
210
+ return "cancelled";
211
+ // Common synonyms from LMs.
212
+ if (normalized === "done" || normalized === "complete" || normalized === "finished") {
213
+ return "completed";
214
+ }
215
+ if (normalized === "inprogress" || normalized === "running" || normalized === "working") {
216
+ return "in_progress";
217
+ }
218
+ if (normalized === "todo" || normalized === "not_started" || normalized === "pending") {
219
+ return "planned";
220
+ }
221
+ if (normalized === "blocked" || normalized === "stuck") {
222
+ return "at_risk";
223
+ }
224
+ return null;
225
+ };
226
+ const operations = [];
227
+ const normalizedTaskUpdates = [];
228
+ const normalizedMilestoneUpdates = [];
229
+ for (const update of input.taskUpdates) {
230
+ const taskId = (update?.task_id ?? "").trim();
231
+ const status = normalizeTaskStatus(update?.status ?? "");
232
+ if (!taskId || !status)
233
+ continue;
234
+ normalizedTaskUpdates.push({
235
+ taskId,
236
+ status,
237
+ reason: typeof update?.reason === "string" && update.reason.trim().length > 0 ? update.reason.trim() : null,
238
+ });
239
+ operations.push({ op: "task.update", task_id: taskId, status });
240
+ }
241
+ for (const update of input.milestoneUpdates) {
242
+ const milestoneId = (update?.milestone_id ?? "").trim();
243
+ const status = normalizeMilestoneStatus(update?.status ?? "");
244
+ if (!milestoneId || !status)
245
+ continue;
246
+ normalizedMilestoneUpdates.push({
247
+ milestoneId,
248
+ status,
249
+ reason: typeof update?.reason === "string" && update.reason.trim().length > 0
250
+ ? update.reason.trim()
251
+ : null,
252
+ });
253
+ operations.push({ op: "milestone.update", milestone_id: milestoneId, status });
254
+ }
255
+ if (operations.length === 0) {
256
+ return {
257
+ applied: 0,
258
+ buffered: false,
259
+ taskUpdates: [],
260
+ milestoneUpdates: [],
261
+ };
262
+ }
263
+ const normalizedAgentId = typeof input.agentId === "string" && input.agentId.trim().length > 0
264
+ ? input.agentId.trim()
265
+ : null;
266
+ const normalizedAgentName = typeof input.agentName === "string" && input.agentName.trim().length > 0
267
+ ? input.agentName.trim()
268
+ : null;
269
+ const runIdForApply = input.runId?.trim() ?? "";
270
+ const correlationIdForApply = input.correlationId?.trim() ?? "";
271
+ const applyPayloadBase = {
272
+ initiative_id: input.initiativeId,
273
+ source_client: "openclaw",
274
+ idempotency_key: deps.idempotencyKey([
275
+ "openclaw",
276
+ "autopilot",
277
+ "slice_status",
278
+ input.initiativeId,
279
+ input.correlationId,
280
+ ]),
281
+ operations: operations,
282
+ };
283
+ try {
284
+ await deps.client.applyChangeset({
285
+ ...applyPayloadBase,
286
+ run_id: runIdForApply || undefined,
287
+ correlation_id: correlationIdForApply || undefined,
288
+ });
289
+ return {
290
+ applied: operations.length,
291
+ buffered: false,
292
+ taskUpdates: normalizedTaskUpdates,
293
+ milestoneUpdates: normalizedMilestoneUpdates,
294
+ };
295
+ }
296
+ catch (err) {
297
+ const errMsg = deps.safeErrorMessage(err);
298
+ // Common local-path case: run_id is only known locally. Retry with
299
+ // correlation_id-only semantics so OrgX can attach deterministically.
300
+ if (runIdForApply &&
301
+ /^404\b/.test(errMsg) &&
302
+ /\brun\b/i.test(errMsg) &&
303
+ /not found/i.test(errMsg)) {
304
+ try {
305
+ await deps.client.applyChangeset({
306
+ ...applyPayloadBase,
307
+ run_id: undefined,
308
+ correlation_id: correlationIdForApply || `openclaw_run_${runIdForApply.replace(/-/g, "").slice(0, 24)}`,
309
+ });
310
+ return {
311
+ applied: operations.length,
312
+ buffered: false,
313
+ taskUpdates: normalizedTaskUpdates,
314
+ milestoneUpdates: normalizedMilestoneUpdates,
315
+ };
316
+ }
317
+ catch {
318
+ // Fall through to local outbox buffering.
319
+ }
320
+ }
321
+ const timestamp = new Date().toISOString();
322
+ try {
323
+ await appendToOutbox(input.initiativeId, {
324
+ id: deps.randomUUID(),
325
+ type: "changeset",
326
+ timestamp,
327
+ payload: {
328
+ initiative_id: input.initiativeId,
329
+ correlation_id: input.correlationId,
330
+ source_client: "openclaw",
331
+ idempotency_key: deps.idempotencyKey([
332
+ "openclaw",
333
+ "autopilot",
334
+ "slice_status",
335
+ input.initiativeId,
336
+ input.correlationId,
337
+ "outbox",
338
+ ]),
339
+ operations,
340
+ },
341
+ activityItem: {
342
+ id: deps.randomUUID(),
343
+ type: "run_started",
344
+ title: `Buffered status updates for slice ${input.runId}`,
345
+ description: null,
346
+ agentId: normalizedAgentId,
347
+ agentName: normalizedAgentName,
348
+ requesterAgentId: normalizedAgentId,
349
+ requesterAgentName: normalizedAgentName,
350
+ executorAgentId: normalizedAgentId,
351
+ executorAgentName: normalizedAgentName,
352
+ runId: input.runId,
353
+ initiativeId: input.initiativeId,
354
+ timestamp,
355
+ phase: "review",
356
+ summary: `Will apply ${operations.length} status update(s) when connected.`,
357
+ metadata: {
358
+ source: "openclaw_local_fallback",
359
+ event: "autopilot_slice_status_updates_buffered",
360
+ error: errMsg,
361
+ run_id: input.runId,
362
+ correlation_id: input.correlationId,
363
+ output_path: typeof input.outputPath === "string" && input.outputPath.trim().length > 0
364
+ ? input.outputPath.trim()
365
+ : null,
366
+ log_path: typeof input.logPath === "string" && input.logPath.trim().length > 0
367
+ ? input.logPath.trim()
368
+ : null,
369
+ task_update_count: normalizedTaskUpdates.length,
370
+ milestone_update_count: normalizedMilestoneUpdates.length,
371
+ task_updates: normalizedTaskUpdates.map((entry) => ({
372
+ task_id: entry.taskId,
373
+ status: entry.status,
374
+ reason: entry.reason,
375
+ })),
376
+ milestone_updates: normalizedMilestoneUpdates.map((entry) => ({
377
+ milestone_id: entry.milestoneId,
378
+ status: entry.status,
379
+ reason: entry.reason,
380
+ })),
381
+ ...(normalizedAgentId ? { agent_id: normalizedAgentId } : {}),
382
+ ...(normalizedAgentName ? { agent_name: normalizedAgentName } : {}),
383
+ ...(input.isMockWorker ? { mock: true } : {}),
384
+ },
385
+ },
386
+ });
387
+ }
388
+ catch {
389
+ // best effort
390
+ }
391
+ return {
392
+ applied: operations.length,
393
+ buffered: true,
394
+ taskUpdates: normalizedTaskUpdates,
395
+ milestoneUpdates: normalizedMilestoneUpdates,
396
+ };
397
+ }
398
+ }
399
+ async function resolveAgentDisplayName(agentId, fallbackName) {
400
+ const normalizedAgentId = agentId.trim();
401
+ if (!normalizedAgentId)
402
+ return null;
403
+ const normalizedFallback = typeof fallbackName === "string" && fallbackName.trim().length > 0
404
+ ? fallbackName.trim()
405
+ : null;
406
+ return normalizedFallback ?? normalizedAgentId;
407
+ }
408
+ async function dispatchFallbackWorkstreamTurn(input) {
409
+ const now = new Date().toISOString();
410
+ const sessionId = deps.randomUUID();
411
+ const taskId = input.taskId?.trim() || null;
412
+ const taskTitle = input.taskTitle?.trim() || null;
413
+ const policyResolution = await deps.resolveDispatchExecutionPolicy({
414
+ initiativeId: input.initiativeId,
415
+ initiativeTitle: input.initiativeTitle,
416
+ workstreamId: input.workstreamId,
417
+ workstreamTitle: input.workstreamTitle,
418
+ taskId,
419
+ taskTitle,
420
+ message: "Continue this workstream from the latest context. Identify and execute the next concrete task.",
421
+ });
422
+ const executionPolicy = policyResolution.executionPolicy;
423
+ const resolvedWorkstreamTitle = policyResolution.workstreamTitle ?? input.workstreamTitle;
424
+ const resolvedTaskTitle = policyResolution.taskTitle ?? taskTitle;
425
+ const guard = await deps.enforceSpawnGuardForDispatch({
426
+ sourceEventPrefix: "next_up_fallback",
427
+ initiativeId: input.initiativeId,
428
+ correlationId: sessionId,
429
+ runId: sessionId,
430
+ executionPolicy,
431
+ agentId: input.agentId,
432
+ taskId,
433
+ taskTitle: resolvedTaskTitle,
434
+ workstreamId: input.workstreamId,
435
+ workstreamTitle: resolvedWorkstreamTitle,
436
+ });
437
+ if (!guard.allowed) {
438
+ return {
439
+ sessionId: null,
440
+ pid: null,
441
+ blockedReason: guard.blockedReason,
442
+ retryable: guard.retryable,
443
+ executionPolicy,
444
+ spawnGuardResult: guard.spawnGuardResult,
445
+ };
446
+ }
447
+ const baseMessage = [
448
+ `Initiative: ${input.initiativeTitle}`,
449
+ `Workstream: ${resolvedWorkstreamTitle}`,
450
+ taskId ? `Task: ${resolvedTaskTitle ?? taskId}` : null,
451
+ "",
452
+ "Continue this workstream from the latest context.",
453
+ "Identify and execute the next concrete task, then provide a concise progress summary.",
454
+ ]
455
+ .filter((line) => Boolean(line))
456
+ .join("\n");
457
+ const message = deps.buildPolicyEnforcedMessage({
458
+ baseMessage,
459
+ executionPolicy,
460
+ spawnGuardResult: guard.spawnGuardResult,
461
+ });
462
+ if (taskId) {
463
+ try {
464
+ await deps.client.updateEntity("task", taskId, { status: "in_progress" });
465
+ }
466
+ catch {
467
+ // best effort
468
+ }
469
+ try {
470
+ await deps.syncParentRollupsForTask({
471
+ initiativeId: input.initiativeId,
472
+ taskId,
473
+ workstreamId: input.workstreamId,
474
+ correlationId: sessionId,
475
+ });
476
+ }
477
+ catch {
478
+ // best effort
479
+ }
480
+ }
481
+ await deps.emitActivitySafe({
482
+ initiativeId: input.initiativeId,
483
+ runId: sessionId,
484
+ correlationId: sessionId,
485
+ phase: "execution",
486
+ level: "info",
487
+ message: `Next Up dispatched ${resolvedWorkstreamTitle}.`,
488
+ metadata: {
489
+ event: "next_up_manual_dispatch_started",
490
+ agent_id: input.agentId,
491
+ agent_name: input.agentName ?? input.agentId,
492
+ requested_by_agent_id: input.agentId,
493
+ requested_by_agent_name: input.agentName ?? input.agentId,
494
+ session_id: sessionId,
495
+ workstream_id: input.workstreamId,
496
+ workstream_title: resolvedWorkstreamTitle,
497
+ task_id: taskId,
498
+ task_title: resolvedTaskTitle,
499
+ domain: executionPolicy.domain,
500
+ required_skills: executionPolicy.requiredSkills,
501
+ spawn_guard_model_tier: deps.extractSpawnGuardModelTier(guard.spawnGuardResult),
502
+ fallback: true,
503
+ },
504
+ });
505
+ deps.upsertAgentContext({
506
+ agentId: input.agentId,
507
+ initiativeId: input.initiativeId,
508
+ initiativeTitle: input.initiativeTitle,
509
+ workstreamId: input.workstreamId,
510
+ taskId,
511
+ });
512
+ deps.upsertRunContext({
513
+ runId: sessionId,
514
+ agentId: input.agentId,
515
+ initiativeId: input.initiativeId,
516
+ initiativeTitle: input.initiativeTitle,
517
+ workstreamId: input.workstreamId,
518
+ taskId,
519
+ });
520
+ const spawned = deps.spawnAgentTurn({
521
+ agentId: input.agentId,
522
+ sessionId,
523
+ message,
524
+ });
525
+ deps.upsertAgentRun({
526
+ runId: sessionId,
527
+ agentId: input.agentId,
528
+ pid: spawned.pid,
529
+ message,
530
+ provider: null,
531
+ model: null,
532
+ initiativeId: input.initiativeId,
533
+ initiativeTitle: input.initiativeTitle,
534
+ workstreamId: input.workstreamId,
535
+ taskId,
536
+ startedAt: now,
537
+ status: "running",
538
+ });
539
+ return {
540
+ sessionId,
541
+ pid: spawned.pid,
542
+ blockedReason: null,
543
+ retryable: false,
544
+ executionPolicy,
545
+ spawnGuardResult: guard.spawnGuardResult,
546
+ };
547
+ }
548
+ return {
549
+ registerArtifactSafe,
550
+ applyAgentStatusUpdatesSafe,
551
+ resolveAgentDisplayName,
552
+ dispatchFallbackWorkstreamTurn,
553
+ };
554
+ }
@@ -0,0 +1,43 @@
1
+ import { type ChildProcess } from "node:child_process";
2
+ import type { RuntimeHookPayload, RuntimeInstanceRecord } from "../../runtime-instance-store.js";
3
+ import type { RuntimeSourceClient } from "../../runtime-instance-store.js";
4
+ import type { CodexBinInfo } from "./autopilot-slice-utils.js";
5
+ type CreateAutopilotRuntimeDeps = {
6
+ filename: string;
7
+ autoContinueSliceChildren: Map<string, ChildProcess>;
8
+ resolveByokEnvOverrides: () => Record<string, string | undefined>;
9
+ safeErrorMessage: (err: unknown) => string;
10
+ resolveCodexBinInfo: () => CodexBinInfo;
11
+ upsertRuntimeInstanceFromHook: (payload: RuntimeHookPayload) => RuntimeInstanceRecord;
12
+ broadcastRuntimeSse: (event: string, payload: RuntimeInstanceRecord) => void;
13
+ clearSnapshotResponseCache: () => void;
14
+ };
15
+ export declare function createAutopilotRuntime(deps: CreateAutopilotRuntimeDeps): {
16
+ spawnCodexSliceWorker: (input: {
17
+ runId: string;
18
+ prompt: string;
19
+ cwd: string;
20
+ logPath: string;
21
+ outputPath: string;
22
+ outputSchemaPath?: string;
23
+ env: Record<string, string | undefined>;
24
+ }) => {
25
+ pid: number | null;
26
+ };
27
+ writeRuntimeEvent: (input: {
28
+ sourceClient: RuntimeSourceClient;
29
+ event: RuntimeHookPayload["event"];
30
+ runId: string;
31
+ initiativeId: string;
32
+ workstreamId: string | null;
33
+ taskId: string | null;
34
+ agentId: string | null;
35
+ agentName: string | null;
36
+ phase: string | null;
37
+ message?: string | null;
38
+ progressPct?: number | null;
39
+ metadata?: Record<string, unknown> | null;
40
+ timestamp?: string | null;
41
+ }) => RuntimeInstanceRecord;
42
+ };
43
+ export {};