@useorgx/openclaw-plugin 0.4.9 → 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 (222) 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 +34 -8
  88. package/dist/agent-context-store.js +79 -17
  89. package/dist/agent-run-store.js +44 -3
  90. package/dist/agent-suite.d.ts +9 -0
  91. package/dist/agent-suite.js +149 -9
  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/chat-store.d.ts +157 -0
  97. package/dist/chat-store.js +586 -0
  98. package/dist/cli/orgx.js +11 -0
  99. package/dist/contracts/client.d.ts +43 -3
  100. package/dist/contracts/client.js +159 -30
  101. package/dist/contracts/retro-schema.d.ts +81 -0
  102. package/dist/contracts/retro-schema.js +80 -0
  103. package/dist/contracts/shared-types.d.ts +159 -0
  104. package/dist/contracts/shared-types.js +177 -1
  105. package/dist/contracts/skill-pack-schema.d.ts +192 -0
  106. package/dist/contracts/skill-pack-schema.js +180 -0
  107. package/dist/contracts/types.d.ts +227 -2
  108. package/dist/entities/auto-assignment.js +43 -17
  109. package/dist/event-sanitization.d.ts +11 -0
  110. package/dist/event-sanitization.js +113 -0
  111. package/dist/fs-utils.js +13 -1
  112. package/dist/gateway-watchdog.d.ts +5 -0
  113. package/dist/gateway-watchdog.js +50 -0
  114. package/dist/hooks/post-reporting-event.mjs +1 -5
  115. package/dist/http/helpers/activity-headline.js +13 -132
  116. package/dist/http/helpers/auto-continue-engine.d.ts +198 -10
  117. package/dist/http/helpers/auto-continue-engine.js +2531 -186
  118. package/dist/http/helpers/autopilot-operations.d.ts +19 -0
  119. package/dist/http/helpers/autopilot-operations.js +182 -31
  120. package/dist/http/helpers/autopilot-runtime.d.ts +1 -0
  121. package/dist/http/helpers/autopilot-runtime.js +308 -20
  122. package/dist/http/helpers/autopilot-slice-utils.d.ts +18 -0
  123. package/dist/http/helpers/autopilot-slice-utils.js +516 -93
  124. package/dist/http/helpers/decision-mapper.d.ts +40 -0
  125. package/dist/http/helpers/decision-mapper.js +223 -7
  126. package/dist/http/helpers/dispatch-lifecycle.d.ts +19 -2
  127. package/dist/http/helpers/dispatch-lifecycle.js +242 -37
  128. package/dist/http/helpers/kickoff-context.js +74 -0
  129. package/dist/http/helpers/llm-client.d.ts +47 -0
  130. package/dist/http/helpers/llm-client.js +256 -0
  131. package/dist/http/helpers/mission-control.d.ts +102 -3
  132. package/dist/http/helpers/mission-control.js +498 -9
  133. package/dist/http/helpers/sentinel-catalog.d.ts +23 -0
  134. package/dist/http/helpers/sentinel-catalog.js +193 -0
  135. package/dist/http/helpers/session-classification.d.ts +9 -0
  136. package/dist/http/helpers/session-classification.js +564 -0
  137. package/dist/http/helpers/slice-experience-v2.d.ts +137 -0
  138. package/dist/http/helpers/slice-experience-v2.js +677 -0
  139. package/dist/http/helpers/slice-run-projections.d.ts +72 -0
  140. package/dist/http/helpers/slice-run-projections.js +860 -0
  141. package/dist/http/helpers/triage-mapper.d.ts +43 -0
  142. package/dist/http/helpers/triage-mapper.js +549 -0
  143. package/dist/http/helpers/value-utils.js +7 -2
  144. package/dist/http/helpers/workspace-scope.d.ts +15 -0
  145. package/dist/http/helpers/workspace-scope.js +170 -0
  146. package/dist/http/index.js +1354 -97
  147. package/dist/http/routes/agent-suite.d.ts +9 -0
  148. package/dist/http/routes/agent-suite.js +207 -8
  149. package/dist/http/routes/agents-catalog.js +64 -19
  150. package/dist/http/routes/chat.d.ts +19 -0
  151. package/dist/http/routes/chat.js +522 -0
  152. package/dist/http/routes/decision-actions.d.ts +8 -1
  153. package/dist/http/routes/decision-actions.js +42 -5
  154. package/dist/http/routes/dispatch-gateway-envelope.d.ts +25 -0
  155. package/dist/http/routes/dispatch-gateway-envelope.js +26 -0
  156. package/dist/http/routes/entities.d.ts +16 -0
  157. package/dist/http/routes/entities.js +294 -6
  158. package/dist/http/routes/live-legacy.d.ts +5 -0
  159. package/dist/http/routes/live-legacy.js +23 -509
  160. package/dist/http/routes/live-misc.d.ts +12 -0
  161. package/dist/http/routes/live-misc.js +251 -31
  162. package/dist/http/routes/live-snapshot.d.ts +48 -2
  163. package/dist/http/routes/live-snapshot.js +638 -19
  164. package/dist/http/routes/live-terminal.d.ts +11 -0
  165. package/dist/http/routes/live-terminal.js +261 -0
  166. package/dist/http/routes/live-triage.d.ts +61 -0
  167. package/dist/http/routes/live-triage.js +248 -0
  168. package/dist/http/routes/mission-control-actions.d.ts +49 -1
  169. package/dist/http/routes/mission-control-actions.js +1334 -84
  170. package/dist/http/routes/mission-control-read.d.ts +48 -3
  171. package/dist/http/routes/mission-control-read.js +1593 -20
  172. package/dist/http/routes/realtime-orchestrator.d.ts +10 -0
  173. package/dist/http/routes/realtime-orchestrator.js +74 -0
  174. package/dist/http/routes/run-control.d.ts +5 -2
  175. package/dist/http/routes/run-control.js +10 -0
  176. package/dist/http/routes/sentinels-catalog.d.ts +7 -0
  177. package/dist/http/routes/sentinels-catalog.js +24 -0
  178. package/dist/http/routes/summary.js +10 -3
  179. package/dist/http/routes/usage.d.ts +24 -0
  180. package/dist/http/routes/usage.js +362 -0
  181. package/dist/http/routes/work-artifacts.js +28 -9
  182. package/dist/index.js +165 -27
  183. package/dist/local-openclaw.js +29 -6
  184. package/dist/mcp-client-setup.js +3 -3
  185. package/dist/mcp-http-handler.js +33 -59
  186. package/dist/next-up-queue-store.d.ts +16 -1
  187. package/dist/next-up-queue-store.js +89 -7
  188. package/dist/outbox.d.ts +5 -0
  189. package/dist/outbox.js +113 -9
  190. package/dist/paths.js +24 -5
  191. package/dist/reporting/rollups.d.ts +53 -0
  192. package/dist/reporting/rollups.js +148 -0
  193. package/dist/retro/domain-templates.d.ts +45 -0
  194. package/dist/retro/domain-templates.js +297 -0
  195. package/dist/retro/quality-rubric.d.ts +33 -0
  196. package/dist/retro/quality-rubric.js +213 -0
  197. package/dist/runtime-cleanup.d.ts +18 -0
  198. package/dist/runtime-cleanup.js +87 -0
  199. package/dist/services/background.d.ts +11 -0
  200. package/dist/services/background.js +22 -0
  201. package/dist/services/experiment-randomization.d.ts +21 -0
  202. package/dist/services/experiment-randomization.js +63 -0
  203. package/dist/skill-pack-state.d.ts +36 -5
  204. package/dist/skill-pack-state.js +273 -29
  205. package/dist/sync/local-agent-telemetry.d.ts +13 -0
  206. package/dist/sync/local-agent-telemetry.js +128 -0
  207. package/dist/sync/outbox-replay.js +131 -24
  208. package/dist/team-context-store.d.ts +23 -0
  209. package/dist/team-context-store.js +116 -0
  210. package/dist/telemetry/posthog.js +4 -2
  211. package/dist/tools/core-tools.d.ts +10 -14
  212. package/dist/tools/core-tools.js +1289 -24
  213. package/dist/types.d.ts +2 -0
  214. package/dist/types.js +2 -0
  215. package/dist/worker-supervisor.js +23 -0
  216. package/package.json +14 -4
  217. package/dashboard/dist/assets/B3ziCA02.js +0 -8
  218. package/dashboard/dist/assets/B5NEElEI.css +0 -1
  219. package/dashboard/dist/assets/BhapSNAs.js +0 -215
  220. package/dashboard/dist/assets/iFdvE7lx.js +0 -1
  221. package/dashboard/dist/assets/jRJsmpYM.js +0 -1
  222. package/dashboard/dist/assets/sAhvFnpk.js +0 -4
@@ -3,6 +3,7 @@ import type { upsertAgentRun as upsertAgentRunType } from "../../agent-run-store
3
3
  type AutopilotSliceArtifact = {
4
4
  name: string;
5
5
  artifact_type?: string | null;
6
+ confidence_score?: number | null;
6
7
  description?: string | null;
7
8
  url?: string | null;
8
9
  verification_steps?: string[] | null;
@@ -109,7 +110,10 @@ export declare function createAutopilotOperations(deps: CreateAutopilotOperation
109
110
  agentId: string;
110
111
  agentName?: string | null;
111
112
  workstreamId: string;
113
+ fallbackMilestoneId?: string | null;
114
+ fallbackTaskIds?: string[] | null;
112
115
  artifact: AutopilotSliceArtifact;
116
+ isMockWorker?: boolean;
113
117
  }) => Promise<{
114
118
  ok: boolean;
115
119
  id: string | null;
@@ -118,6 +122,10 @@ export declare function createAutopilotOperations(deps: CreateAutopilotOperation
118
122
  initiativeId: string;
119
123
  runId: string;
120
124
  correlationId: string;
125
+ agentId?: string | null;
126
+ agentName?: string | null;
127
+ outputPath?: string | null;
128
+ logPath?: string | null;
121
129
  taskUpdates: Array<{
122
130
  task_id: string;
123
131
  status: string;
@@ -128,9 +136,20 @@ export declare function createAutopilotOperations(deps: CreateAutopilotOperation
128
136
  status: string;
129
137
  reason?: string | null;
130
138
  }>;
139
+ isMockWorker?: boolean;
131
140
  }) => Promise<{
132
141
  applied: number;
133
142
  buffered: boolean;
143
+ taskUpdates: Array<{
144
+ taskId: string;
145
+ status: string;
146
+ reason: string | null;
147
+ }>;
148
+ milestoneUpdates: Array<{
149
+ milestoneId: string;
150
+ status: string;
151
+ reason: string | null;
152
+ }>;
134
153
  }>;
135
154
  resolveAgentDisplayName: (agentId: string, fallbackName?: string | null) => Promise<string | null>;
136
155
  dispatchFallbackWorkstreamTurn: (input: {
@@ -3,11 +3,37 @@ import { registerArtifact } from "../../artifacts/register-artifact.js";
3
3
  export function createAutopilotOperations(deps) {
4
4
  async function registerArtifactSafe(input) {
5
5
  const now = new Date().toISOString();
6
- const name = (input.artifact.name ?? "").trim();
6
+ const name = typeof input.artifact.name === "string" && input.artifact.name.trim().length > 0
7
+ ? input.artifact.name.trim()
8
+ : "";
7
9
  if (!name)
8
10
  return { ok: false, id: null };
9
- const artifactType = (input.artifact.artifact_type ?? "other").trim() || "other";
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;
10
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);
11
37
  const verificationSteps = Array.isArray(input.artifact.verification_steps)
12
38
  ? input.artifact.verification_steps
13
39
  .filter((step) => typeof step === "string")
@@ -27,14 +53,15 @@ export function createAutopilotOperations(deps) {
27
53
  const createdByType = hasUuidAgent ? "agent" : "human";
28
54
  const createdById = hasUuidAgent ? input.agentId : null;
29
55
  try {
30
- const entityType = input.artifact.milestone_id ? "milestone" : "initiative";
31
- const entityId = input.artifact.milestone_id ? input.artifact.milestone_id : input.initiativeId;
56
+ const entityType = milestoneId ? "milestone" : "initiative";
57
+ const entityId = milestoneId ?? input.initiativeId;
32
58
  const result = await registerArtifact(deps.client, deps.client.getBaseUrl(), {
33
59
  artifact_id: artifactId,
34
60
  entity_type: entityType,
35
61
  entity_id: entityId,
36
62
  name,
37
63
  artifact_type: artifactType,
64
+ confidence_score: confidenceScore,
38
65
  created_by_type: createdByType,
39
66
  created_by_id: createdById,
40
67
  description,
@@ -47,12 +74,45 @@ export function createAutopilotOperations(deps) {
47
74
  run_id: input.runId,
48
75
  initiative_id: input.initiativeId,
49
76
  workstream_id: input.workstreamId,
50
- milestone_id: input.artifact.milestone_id ?? null,
51
- task_ids: input.artifact.task_ids ?? null,
77
+ milestone_id: milestoneId,
78
+ task_ids: taskIds.length > 0 ? taskIds : null,
79
+ confidence_score: confidenceScore,
52
80
  },
53
81
  // Make persistence validation opt-in to avoid adding latency to every slice by default.
54
82
  validate_persistence: process.env.ORGX_VALIDATE_ARTIFACT_PERSISTENCE === "1",
55
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
+ }
56
116
  return { ok: result.ok, id: result.artifact_id };
57
117
  }
58
118
  catch (err) {
@@ -63,10 +123,11 @@ export function createAutopilotOperations(deps) {
63
123
  timestamp: now,
64
124
  payload: {
65
125
  artifact_id: artifactId,
66
- entity_type: input.artifact.milestone_id ? "milestone" : "initiative",
67
- entity_id: input.artifact.milestone_id ?? input.initiativeId,
126
+ entity_type: milestoneId ? "milestone" : "initiative",
127
+ entity_id: milestoneId ?? input.initiativeId,
68
128
  name,
69
129
  artifact_type: artifactType,
130
+ confidence_score: confidenceScore,
70
131
  created_by_type: createdByType,
71
132
  created_by_id: createdById,
72
133
  description,
@@ -93,9 +154,11 @@ export function createAutopilotOperations(deps) {
93
154
  source: "openclaw_local_fallback",
94
155
  event: "autopilot_slice_artifact_buffered",
95
156
  artifact_type: artifactType,
157
+ confidence_score: confidenceScore,
96
158
  artifact_id: artifactId,
97
159
  url: input.artifact.url ?? null,
98
160
  error: deps.safeErrorMessage(err),
161
+ ...(input.isMockWorker ? { mock: true } : {}),
99
162
  },
100
163
  },
101
164
  });
@@ -161,11 +224,18 @@ export function createAutopilotOperations(deps) {
161
224
  return null;
162
225
  };
163
226
  const operations = [];
227
+ const normalizedTaskUpdates = [];
228
+ const normalizedMilestoneUpdates = [];
164
229
  for (const update of input.taskUpdates) {
165
230
  const taskId = (update?.task_id ?? "").trim();
166
231
  const status = normalizeTaskStatus(update?.status ?? "");
167
232
  if (!taskId || !status)
168
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
+ });
169
239
  operations.push({ op: "task.update", task_id: taskId, status });
170
240
  }
171
241
  for (const update of input.milestoneUpdates) {
@@ -173,28 +243,81 @@ export function createAutopilotOperations(deps) {
173
243
  const status = normalizeMilestoneStatus(update?.status ?? "");
174
244
  if (!milestoneId || !status)
175
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
+ });
176
253
  operations.push({ op: "milestone.update", milestone_id: milestoneId, status });
177
254
  }
178
- if (operations.length === 0)
179
- return { applied: 0, buffered: false };
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
+ };
180
283
  try {
181
284
  await deps.client.applyChangeset({
182
- initiative_id: input.initiativeId,
183
- run_id: input.runId,
184
- correlation_id: input.correlationId,
185
- source_client: "openclaw",
186
- idempotency_key: deps.idempotencyKey([
187
- "openclaw",
188
- "autopilot",
189
- "slice_status",
190
- input.initiativeId,
191
- input.correlationId,
192
- ]),
193
- operations: operations,
285
+ ...applyPayloadBase,
286
+ run_id: runIdForApply || undefined,
287
+ correlation_id: correlationIdForApply || undefined,
194
288
  });
195
- return { applied: operations.length, buffered: false };
289
+ return {
290
+ applied: operations.length,
291
+ buffered: false,
292
+ taskUpdates: normalizedTaskUpdates,
293
+ milestoneUpdates: normalizedMilestoneUpdates,
294
+ };
196
295
  }
197
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
+ }
198
321
  const timestamp = new Date().toISOString();
199
322
  try {
200
323
  await appendToOutbox(input.initiativeId, {
@@ -220,12 +343,12 @@ export function createAutopilotOperations(deps) {
220
343
  type: "run_started",
221
344
  title: `Buffered status updates for slice ${input.runId}`,
222
345
  description: null,
223
- agentId: null,
224
- agentName: null,
225
- requesterAgentId: null,
226
- requesterAgentName: null,
227
- executorAgentId: null,
228
- executorAgentName: null,
346
+ agentId: normalizedAgentId,
347
+ agentName: normalizedAgentName,
348
+ requesterAgentId: normalizedAgentId,
349
+ requesterAgentName: normalizedAgentName,
350
+ executorAgentId: normalizedAgentId,
351
+ executorAgentName: normalizedAgentName,
229
352
  runId: input.runId,
230
353
  initiativeId: input.initiativeId,
231
354
  timestamp,
@@ -234,7 +357,30 @@ export function createAutopilotOperations(deps) {
234
357
  metadata: {
235
358
  source: "openclaw_local_fallback",
236
359
  event: "autopilot_slice_status_updates_buffered",
237
- error: deps.safeErrorMessage(err),
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 } : {}),
238
384
  },
239
385
  },
240
386
  });
@@ -242,7 +388,12 @@ export function createAutopilotOperations(deps) {
242
388
  catch {
243
389
  // best effort
244
390
  }
245
- return { applied: operations.length, buffered: true };
391
+ return {
392
+ applied: operations.length,
393
+ buffered: true,
394
+ taskUpdates: normalizedTaskUpdates,
395
+ milestoneUpdates: normalizedMilestoneUpdates,
396
+ };
246
397
  }
247
398
  }
248
399
  async function resolveAgentDisplayName(agentId, fallbackName) {
@@ -19,6 +19,7 @@ export declare function createAutopilotRuntime(deps: CreateAutopilotRuntimeDeps)
19
19
  cwd: string;
20
20
  logPath: string;
21
21
  outputPath: string;
22
+ outputSchemaPath?: string;
22
23
  env: Record<string, string | undefined>;
23
24
  }) => {
24
25
  pid: number | null;