@useorgx/openclaw-plugin 0.4.9 → 0.7.2
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/README.md +77 -11
- package/dashboard/dist/assets/6mILZQ2a.js +1 -0
- package/dashboard/dist/assets/6mILZQ2a.js.br +0 -0
- package/dashboard/dist/assets/6mILZQ2a.js.gz +0 -0
- package/dashboard/dist/assets/8dksYiq4.js +2 -0
- package/dashboard/dist/assets/8dksYiq4.js.br +0 -0
- package/dashboard/dist/assets/8dksYiq4.js.gz +0 -0
- package/dashboard/dist/assets/B5zYRHc3.js +1 -0
- package/dashboard/dist/assets/B5zYRHc3.js.br +0 -0
- package/dashboard/dist/assets/B5zYRHc3.js.gz +0 -0
- package/dashboard/dist/assets/B6wPWJ35.js +1 -0
- package/dashboard/dist/assets/B6wPWJ35.js.br +0 -0
- package/dashboard/dist/assets/B6wPWJ35.js.gz +0 -0
- package/dashboard/dist/assets/BJgZIVUQ.js +53 -0
- package/dashboard/dist/assets/BJgZIVUQ.js.br +0 -0
- package/dashboard/dist/assets/BJgZIVUQ.js.gz +0 -0
- package/dashboard/dist/assets/BWEwjt1W.js +1 -0
- package/dashboard/dist/assets/BWEwjt1W.js.br +0 -0
- package/dashboard/dist/assets/BWEwjt1W.js.gz +0 -0
- package/dashboard/dist/assets/BgOYB78t.js +4 -0
- package/dashboard/dist/assets/BgOYB78t.js.br +0 -0
- package/dashboard/dist/assets/BgOYB78t.js.gz +0 -0
- package/dashboard/dist/assets/BzRbDCAD.css +1 -0
- package/dashboard/dist/assets/BzRbDCAD.css.br +0 -0
- package/dashboard/dist/assets/BzRbDCAD.css.gz +0 -0
- package/dashboard/dist/assets/C-KIc3Wc.js.br +0 -0
- package/dashboard/dist/assets/C-KIc3Wc.js.gz +0 -0
- package/dashboard/dist/assets/C8uM3AX8.js +1 -0
- package/dashboard/dist/assets/C8uM3AX8.js.br +0 -0
- package/dashboard/dist/assets/C8uM3AX8.js.gz +0 -0
- package/dashboard/dist/assets/C9jy61eu.js +212 -0
- package/dashboard/dist/assets/C9jy61eu.js.br +0 -0
- package/dashboard/dist/assets/C9jy61eu.js.gz +0 -0
- package/dashboard/dist/assets/CC63EwFD.js +1 -0
- package/dashboard/dist/assets/CC63EwFD.js.br +0 -0
- package/dashboard/dist/assets/CC63EwFD.js.gz +0 -0
- package/dashboard/dist/assets/CL_wXqR7.js +1 -0
- package/dashboard/dist/assets/CL_wXqR7.js.br +0 -0
- package/dashboard/dist/assets/CL_wXqR7.js.gz +0 -0
- package/dashboard/dist/assets/CZaT3ob_.js +1 -0
- package/dashboard/dist/assets/CZaT3ob_.js.br +0 -0
- package/dashboard/dist/assets/CZaT3ob_.js.gz +0 -0
- package/dashboard/dist/assets/CgaottFX.js +1 -0
- package/dashboard/dist/assets/CgaottFX.js.br +0 -0
- package/dashboard/dist/assets/CgaottFX.js.gz +0 -0
- package/dashboard/dist/assets/{CpJsfbXo.js → CxQ08qFN.js} +2 -2
- package/dashboard/dist/assets/CxQ08qFN.js.br +0 -0
- package/dashboard/dist/assets/CxQ08qFN.js.gz +0 -0
- package/dashboard/dist/assets/CzCxAZlW.js +1 -0
- package/dashboard/dist/assets/CzCxAZlW.js.br +0 -0
- package/dashboard/dist/assets/CzCxAZlW.js.gz +0 -0
- package/dashboard/dist/assets/D3iMTYEj.js +1 -0
- package/dashboard/dist/assets/D3iMTYEj.js.br +0 -0
- package/dashboard/dist/assets/D3iMTYEj.js.gz +0 -0
- package/dashboard/dist/assets/D8JNX8kq.js +2 -0
- package/dashboard/dist/assets/D8JNX8kq.js.br +0 -0
- package/dashboard/dist/assets/D8JNX8kq.js.gz +0 -0
- package/dashboard/dist/assets/DnA8dpj6.js +1 -0
- package/dashboard/dist/assets/DnA8dpj6.js.br +0 -0
- package/dashboard/dist/assets/DnA8dpj6.js.gz +0 -0
- package/dashboard/dist/assets/IUexzymk.js +1 -0
- package/dashboard/dist/assets/IUexzymk.js.br +0 -0
- package/dashboard/dist/assets/IUexzymk.js.gz +0 -0
- package/dashboard/dist/assets/cNrhgGc1.js +8 -0
- package/dashboard/dist/assets/cNrhgGc1.js.br +0 -0
- package/dashboard/dist/assets/cNrhgGc1.js.gz +0 -0
- package/dashboard/dist/assets/ic2FaMnh.js +1 -0
- package/dashboard/dist/assets/ic2FaMnh.js.br +0 -0
- package/dashboard/dist/assets/ic2FaMnh.js.gz +0 -0
- package/dashboard/dist/assets/qm8xLgv-.css +1 -0
- package/dashboard/dist/assets/qm8xLgv-.css.br +0 -0
- package/dashboard/dist/assets/qm8xLgv-.css.gz +0 -0
- package/dashboard/dist/assets/rttbDbEx.js +1 -0
- package/dashboard/dist/assets/rttbDbEx.js.br +0 -0
- package/dashboard/dist/assets/rttbDbEx.js.gz +0 -0
- package/dashboard/dist/brand/anthropic-mark.svg.br +0 -0
- package/dashboard/dist/brand/anthropic-mark.svg.gz +0 -0
- package/dashboard/dist/brand/openai-mark.svg.br +0 -0
- package/dashboard/dist/brand/openai-mark.svg.gz +0 -0
- package/dashboard/dist/brand/openclaw-mark.svg.br +0 -0
- package/dashboard/dist/brand/openclaw-mark.svg.gz +0 -0
- package/dashboard/dist/brand/xandy-orchestrator.png +0 -0
- package/dashboard/dist/index.html +7 -5
- package/dashboard/dist/index.html.br +0 -0
- package/dashboard/dist/index.html.gz +0 -0
- package/dist/activity-actor-fields.js +26 -4
- package/dist/activity-store.js +34 -8
- package/dist/agent-context-store.js +79 -17
- package/dist/agent-run-store.js +44 -3
- package/dist/agent-suite.d.ts +9 -0
- package/dist/agent-suite.js +149 -9
- package/dist/artifacts/artifact-domain-schemas.d.ts +66 -0
- package/dist/artifacts/artifact-domain-schemas.js +357 -0
- package/dist/artifacts/register-artifact.d.ts +4 -3
- package/dist/artifacts/register-artifact.js +170 -57
- package/dist/chat-store.d.ts +157 -0
- package/dist/chat-store.js +586 -0
- package/dist/cli/orgx.js +11 -0
- package/dist/contracts/client.d.ts +43 -3
- package/dist/contracts/client.js +159 -30
- package/dist/contracts/practice-exercise-schema.d.ts +216 -0
- package/dist/contracts/practice-exercise-schema.js +314 -0
- package/dist/contracts/retro-schema.d.ts +81 -0
- package/dist/contracts/retro-schema.js +80 -0
- package/dist/contracts/shared-types.d.ts +159 -0
- package/dist/contracts/shared-types.js +199 -1
- package/dist/contracts/skill-pack-schema.d.ts +192 -0
- package/dist/contracts/skill-pack-schema.js +180 -0
- package/dist/contracts/types.d.ts +247 -2
- package/dist/entities/auto-assignment.js +43 -17
- package/dist/event-sanitization.d.ts +11 -0
- package/dist/event-sanitization.js +113 -0
- package/dist/gateway-watchdog.d.ts +5 -0
- package/dist/gateway-watchdog.js +50 -0
- package/dist/hooks/post-reporting-event.mjs +1 -5
- package/dist/http/helpers/activity-headline.js +13 -132
- package/dist/http/helpers/auto-continue-engine.d.ts +198 -10
- package/dist/http/helpers/auto-continue-engine.js +3145 -186
- package/dist/http/helpers/autopilot-operations.d.ts +19 -0
- package/dist/http/helpers/autopilot-operations.js +182 -31
- package/dist/http/helpers/autopilot-runtime.d.ts +1 -0
- package/dist/http/helpers/autopilot-runtime.js +328 -25
- package/dist/http/helpers/autopilot-slice-utils.d.ts +18 -0
- package/dist/http/helpers/autopilot-slice-utils.js +514 -93
- package/dist/http/helpers/decision-mapper.d.ts +40 -0
- package/dist/http/helpers/decision-mapper.js +223 -7
- package/dist/http/helpers/dispatch-lifecycle.d.ts +19 -2
- package/dist/http/helpers/dispatch-lifecycle.js +242 -37
- package/dist/http/helpers/kickoff-context.js +104 -0
- package/dist/http/helpers/llm-client.d.ts +47 -0
- package/dist/http/helpers/llm-client.js +256 -0
- package/dist/http/helpers/mission-control.d.ts +102 -3
- package/dist/http/helpers/mission-control.js +498 -9
- package/dist/http/helpers/sentinel-catalog.d.ts +23 -0
- package/dist/http/helpers/sentinel-catalog.js +193 -0
- package/dist/http/helpers/session-classification.d.ts +9 -0
- package/dist/http/helpers/session-classification.js +564 -0
- package/dist/http/helpers/slice-experience-v2.d.ts +137 -0
- package/dist/http/helpers/slice-experience-v2.js +677 -0
- package/dist/http/helpers/slice-run-projections.d.ts +72 -0
- package/dist/http/helpers/slice-run-projections.js +877 -0
- package/dist/http/helpers/triage-mapper.d.ts +43 -0
- package/dist/http/helpers/triage-mapper.js +549 -0
- package/dist/http/helpers/value-utils.js +7 -2
- package/dist/http/helpers/workspace-scope.d.ts +15 -0
- package/dist/http/helpers/workspace-scope.js +170 -0
- package/dist/http/index.js +1420 -105
- package/dist/http/routes/agent-suite.d.ts +9 -0
- package/dist/http/routes/agent-suite.js +294 -8
- package/dist/http/routes/agents-catalog.js +64 -19
- package/dist/http/routes/chat.d.ts +19 -0
- package/dist/http/routes/chat.js +522 -0
- package/dist/http/routes/decision-actions.d.ts +8 -1
- package/dist/http/routes/decision-actions.js +42 -5
- package/dist/http/routes/dispatch-gateway-envelope.d.ts +25 -0
- package/dist/http/routes/dispatch-gateway-envelope.js +26 -0
- package/dist/http/routes/entities.d.ts +16 -0
- package/dist/http/routes/entities.js +232 -6
- package/dist/http/routes/live-legacy.d.ts +5 -0
- package/dist/http/routes/live-legacy.js +23 -509
- package/dist/http/routes/live-misc.d.ts +12 -0
- package/dist/http/routes/live-misc.js +251 -31
- package/dist/http/routes/live-snapshot.d.ts +49 -2
- package/dist/http/routes/live-snapshot.js +653 -23
- package/dist/http/routes/live-terminal.d.ts +11 -0
- package/dist/http/routes/live-terminal.js +154 -0
- package/dist/http/routes/live-triage.d.ts +61 -0
- package/dist/http/routes/live-triage.js +192 -0
- package/dist/http/routes/mission-control-actions.d.ts +49 -1
- package/dist/http/routes/mission-control-actions.js +1246 -84
- package/dist/http/routes/mission-control-read.d.ts +48 -3
- package/dist/http/routes/mission-control-read.js +1658 -20
- package/dist/http/routes/realtime-orchestrator.d.ts +10 -0
- package/dist/http/routes/realtime-orchestrator.js +74 -0
- package/dist/http/routes/run-control.d.ts +5 -2
- package/dist/http/routes/run-control.js +10 -0
- package/dist/http/routes/sentinels-catalog.d.ts +7 -0
- package/dist/http/routes/sentinels-catalog.js +24 -0
- package/dist/http/routes/summary.js +10 -3
- package/dist/http/routes/usage.d.ts +24 -0
- package/dist/http/routes/usage.js +362 -0
- package/dist/http/routes/work-artifacts.js +28 -9
- package/dist/index.js +165 -27
- package/dist/local-openclaw.js +29 -6
- package/dist/mcp-client-setup.js +3 -3
- package/dist/mcp-http-handler.d.ts +3 -0
- package/dist/mcp-http-handler.js +34 -60
- package/dist/next-up-queue-store.d.ts +16 -1
- package/dist/next-up-queue-store.js +89 -7
- package/dist/outbox.d.ts +5 -0
- package/dist/outbox.js +113 -9
- package/dist/paths.js +36 -5
- package/dist/reporting/rollups.d.ts +41 -0
- package/dist/reporting/rollups.js +113 -0
- package/dist/retro/domain-templates.d.ts +45 -0
- package/dist/retro/domain-templates.js +297 -0
- package/dist/retro/quality-rubric.d.ts +33 -0
- package/dist/retro/quality-rubric.js +213 -0
- package/dist/runtime-cleanup.d.ts +18 -0
- package/dist/runtime-cleanup.js +87 -0
- package/dist/services/background.d.ts +11 -0
- package/dist/services/background.js +22 -0
- package/dist/services/experiment-randomization.d.ts +21 -0
- package/dist/services/experiment-randomization.js +63 -0
- package/dist/skill-pack-state.d.ts +36 -5
- package/dist/skill-pack-state.js +273 -29
- package/dist/sync/local-agent-telemetry.d.ts +13 -0
- package/dist/sync/local-agent-telemetry.js +128 -0
- package/dist/sync/outbox-replay.js +131 -24
- package/dist/team-context-store.d.ts +23 -0
- package/dist/team-context-store.js +116 -0
- package/dist/telemetry/posthog.js +4 -2
- package/dist/tools/core-tools.d.ts +10 -14
- package/dist/tools/core-tools.js +1289 -24
- package/dist/types.d.ts +2 -0
- package/dist/types.js +2 -0
- package/dist/worker-supervisor.js +23 -0
- package/package.json +20 -6
- package/dashboard/dist/assets/B3ziCA02.js +0 -8
- package/dashboard/dist/assets/B5NEElEI.css +0 -1
- package/dashboard/dist/assets/BhapSNAs.js +0 -215
- package/dashboard/dist/assets/iFdvE7lx.js +0 -1
- package/dashboard/dist/assets/jRJsmpYM.js +0 -1
- package/dashboard/dist/assets/sAhvFnpk.js +0 -4
|
@@ -0,0 +1,877 @@
|
|
|
1
|
+
const TERMINAL_STATES = new Set([
|
|
2
|
+
"completed",
|
|
3
|
+
"needs_review",
|
|
4
|
+
"failed",
|
|
5
|
+
"archived",
|
|
6
|
+
]);
|
|
7
|
+
const RUN_LIKE_STATUS = new Set(["dispatching", "running"]);
|
|
8
|
+
function asRecord(value) {
|
|
9
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
10
|
+
return null;
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
function normalizeText(value) {
|
|
14
|
+
if (typeof value !== "string")
|
|
15
|
+
return null;
|
|
16
|
+
const trimmed = value.trim();
|
|
17
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
18
|
+
}
|
|
19
|
+
function toIso(value) {
|
|
20
|
+
if (!value)
|
|
21
|
+
return null;
|
|
22
|
+
const epoch = Date.parse(value);
|
|
23
|
+
if (!Number.isFinite(epoch))
|
|
24
|
+
return null;
|
|
25
|
+
return new Date(epoch).toISOString();
|
|
26
|
+
}
|
|
27
|
+
function toEpoch(value) {
|
|
28
|
+
if (!value)
|
|
29
|
+
return 0;
|
|
30
|
+
const parsed = Date.parse(value);
|
|
31
|
+
return Number.isFinite(parsed) ? parsed : 0;
|
|
32
|
+
}
|
|
33
|
+
function metadataString(metadata, keys) {
|
|
34
|
+
if (!metadata)
|
|
35
|
+
return null;
|
|
36
|
+
for (const key of keys) {
|
|
37
|
+
const value = normalizeText(metadata[key]);
|
|
38
|
+
if (value)
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
function metadataNumber(metadata, keys) {
|
|
44
|
+
if (!metadata)
|
|
45
|
+
return null;
|
|
46
|
+
for (const key of keys) {
|
|
47
|
+
const raw = metadata[key];
|
|
48
|
+
if (typeof raw === "number" && Number.isFinite(raw))
|
|
49
|
+
return raw;
|
|
50
|
+
if (typeof raw === "string") {
|
|
51
|
+
const parsed = Number(raw);
|
|
52
|
+
if (Number.isFinite(parsed))
|
|
53
|
+
return parsed;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
function metadataBoolean(metadata, keys) {
|
|
59
|
+
if (!metadata)
|
|
60
|
+
return null;
|
|
61
|
+
for (const key of keys) {
|
|
62
|
+
const raw = metadata[key];
|
|
63
|
+
if (typeof raw === "boolean")
|
|
64
|
+
return raw;
|
|
65
|
+
if (typeof raw === "string") {
|
|
66
|
+
const normalized = raw.trim().toLowerCase();
|
|
67
|
+
if (normalized === "true")
|
|
68
|
+
return true;
|
|
69
|
+
if (normalized === "false")
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
function metadataStringArray(metadata, keys) {
|
|
76
|
+
if (!metadata)
|
|
77
|
+
return [];
|
|
78
|
+
for (const key of keys) {
|
|
79
|
+
const raw = metadata[key];
|
|
80
|
+
if (Array.isArray(raw)) {
|
|
81
|
+
return dedupeStrings(raw
|
|
82
|
+
.map((entry) => normalizeText(entry))
|
|
83
|
+
.filter((entry) => Boolean(entry)));
|
|
84
|
+
}
|
|
85
|
+
if (typeof raw === "string") {
|
|
86
|
+
return dedupeStrings(raw
|
|
87
|
+
.split(/[\n,;]+/g)
|
|
88
|
+
.map((entry) => entry.trim())
|
|
89
|
+
.filter(Boolean));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return [];
|
|
93
|
+
}
|
|
94
|
+
function dedupeStrings(values) {
|
|
95
|
+
const seen = new Set();
|
|
96
|
+
const output = [];
|
|
97
|
+
for (const value of values) {
|
|
98
|
+
const normalized = value.trim();
|
|
99
|
+
if (!normalized)
|
|
100
|
+
continue;
|
|
101
|
+
const key = normalized.toLowerCase();
|
|
102
|
+
if (seen.has(key))
|
|
103
|
+
continue;
|
|
104
|
+
seen.add(key);
|
|
105
|
+
output.push(normalized);
|
|
106
|
+
}
|
|
107
|
+
return output;
|
|
108
|
+
}
|
|
109
|
+
function mergeScopedIds(existing, scalar, additions) {
|
|
110
|
+
const merged = dedupeStrings([
|
|
111
|
+
...(Array.isArray(existing) ? existing : []),
|
|
112
|
+
...(scalar ? [scalar] : []),
|
|
113
|
+
...additions,
|
|
114
|
+
]);
|
|
115
|
+
return merged;
|
|
116
|
+
}
|
|
117
|
+
function resolveEventName(metadata) {
|
|
118
|
+
const fromMeta = metadataString(metadata, ["event"]);
|
|
119
|
+
if (fromMeta)
|
|
120
|
+
return fromMeta.toLowerCase();
|
|
121
|
+
return "";
|
|
122
|
+
}
|
|
123
|
+
function resolveSliceRunId(item, metadata) {
|
|
124
|
+
const direct = metadataString(metadata, [
|
|
125
|
+
"slice_run_id",
|
|
126
|
+
"sliceRunId",
|
|
127
|
+
"active_run_id",
|
|
128
|
+
"activeRunId",
|
|
129
|
+
"run_id",
|
|
130
|
+
"runId",
|
|
131
|
+
"correlation_id",
|
|
132
|
+
"correlationId",
|
|
133
|
+
]);
|
|
134
|
+
if (direct)
|
|
135
|
+
return direct;
|
|
136
|
+
if (item.runId && item.runId.trim().length > 0)
|
|
137
|
+
return item.runId.trim();
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
function resolveDecisionSliceRunId(decision, metadata) {
|
|
141
|
+
return (metadataString(metadata, ["slice_run_id", "sliceRunId", "run_id", "runId", "correlation_id", "correlationId"]) ??
|
|
142
|
+
normalizeText(decision.runId) ??
|
|
143
|
+
normalizeText(decision.run_id) ??
|
|
144
|
+
normalizeText(decision.correlationId) ??
|
|
145
|
+
normalizeText(decision.correlation_id) ??
|
|
146
|
+
null);
|
|
147
|
+
}
|
|
148
|
+
function resolveCorrelationId(item, metadata) {
|
|
149
|
+
return (metadataString(metadata, ["correlation_id", "correlationId"]) ??
|
|
150
|
+
metadataString(metadata, ["run_id", "runId"]) ??
|
|
151
|
+
item.runId ??
|
|
152
|
+
null);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Determines whether an activity item is relevant to slice run projections.
|
|
156
|
+
* Every LiveActivityType variant MUST be handled explicitly to prevent
|
|
157
|
+
* silent gaps (like the run_completed bug where accepts were ignored).
|
|
158
|
+
*/
|
|
159
|
+
function resolveRelevantActivity(item, event, metadata, knownSliceIds) {
|
|
160
|
+
// Event-name based relevance (metadata.event prefix matches)
|
|
161
|
+
if (event.startsWith("autopilot_slice_"))
|
|
162
|
+
return true;
|
|
163
|
+
if (event.startsWith("auto_continue_spawn_guard_"))
|
|
164
|
+
return true;
|
|
165
|
+
if (event === "next_up_manual_dispatch_started")
|
|
166
|
+
return true;
|
|
167
|
+
if (event === "auto_continue_stopped")
|
|
168
|
+
return true;
|
|
169
|
+
// Type-based relevance — exhaustive over LiveActivityType
|
|
170
|
+
const type = item.type;
|
|
171
|
+
switch (type) {
|
|
172
|
+
case "artifact_created": {
|
|
173
|
+
const source = metadataString(metadata, ["source"]);
|
|
174
|
+
if ((source ?? "").toLowerCase() === "autopilot_slice")
|
|
175
|
+
return true;
|
|
176
|
+
const runId = resolveSliceRunId(item, metadata);
|
|
177
|
+
return Boolean(runId && knownSliceIds.has(runId));
|
|
178
|
+
}
|
|
179
|
+
case "decision_requested":
|
|
180
|
+
case "decision_resolved":
|
|
181
|
+
case "run_completed":
|
|
182
|
+
case "run_failed":
|
|
183
|
+
case "run_started":
|
|
184
|
+
case "delegation":
|
|
185
|
+
case "milestone_completed":
|
|
186
|
+
case "blocker_created": {
|
|
187
|
+
const runId = resolveSliceRunId(item, metadata);
|
|
188
|
+
return Boolean(runId && knownSliceIds.has(runId));
|
|
189
|
+
}
|
|
190
|
+
case "handoff_requested":
|
|
191
|
+
case "handoff_claimed":
|
|
192
|
+
case "handoff_fulfilled":
|
|
193
|
+
// Handoff types are not relevant to slice projections today
|
|
194
|
+
return false;
|
|
195
|
+
default: {
|
|
196
|
+
// Exhaustiveness guard: if a new LiveActivityType is added and not
|
|
197
|
+
// handled above, this will be a compile error.
|
|
198
|
+
const _exhaustive = type;
|
|
199
|
+
void _exhaustive;
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
function defaultExplainer(status) {
|
|
205
|
+
switch (status) {
|
|
206
|
+
case "queued":
|
|
207
|
+
return "Queued and waiting to dispatch.";
|
|
208
|
+
case "dispatching":
|
|
209
|
+
return "Dispatch acknowledged. Waiting for runtime start.";
|
|
210
|
+
case "running":
|
|
211
|
+
return "Work is actively executing.";
|
|
212
|
+
case "awaiting_input":
|
|
213
|
+
return "Needs your input to proceed.";
|
|
214
|
+
case "completed":
|
|
215
|
+
return "Completed with verified output artifacts.";
|
|
216
|
+
case "needs_review":
|
|
217
|
+
return "Completed signal received without verifiable output.";
|
|
218
|
+
case "failed":
|
|
219
|
+
return "Execution failed before producing a valid result.";
|
|
220
|
+
case "archived":
|
|
221
|
+
return "Archived due to missing execution evidence.";
|
|
222
|
+
default:
|
|
223
|
+
return "Status unavailable.";
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
function defaultPrimaryAction(status) {
|
|
227
|
+
switch (status) {
|
|
228
|
+
case "completed":
|
|
229
|
+
return "open_artifact";
|
|
230
|
+
case "awaiting_input":
|
|
231
|
+
return "resolve_decision";
|
|
232
|
+
case "needs_review":
|
|
233
|
+
return "review_output";
|
|
234
|
+
case "failed":
|
|
235
|
+
return "retry_slice";
|
|
236
|
+
default:
|
|
237
|
+
return "none";
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
function createProjection(sliceRunId) {
|
|
241
|
+
return {
|
|
242
|
+
id: sliceRunId,
|
|
243
|
+
sliceRunId,
|
|
244
|
+
runId: sliceRunId,
|
|
245
|
+
initiativeId: null,
|
|
246
|
+
initiativeIds: [],
|
|
247
|
+
workstreamId: null,
|
|
248
|
+
workstreamIds: [],
|
|
249
|
+
iwmtId: null,
|
|
250
|
+
iwmtIds: [],
|
|
251
|
+
workstreamTitle: null,
|
|
252
|
+
taskIds: [],
|
|
253
|
+
milestoneIds: [],
|
|
254
|
+
status: "queued",
|
|
255
|
+
statusExplainer: defaultExplainer("queued"),
|
|
256
|
+
primaryAction: defaultPrimaryAction("queued"),
|
|
257
|
+
hasArtifact: false,
|
|
258
|
+
artifactCount: 0,
|
|
259
|
+
artifacts: [],
|
|
260
|
+
decisionCount: 0,
|
|
261
|
+
blockingDecisionCount: 0,
|
|
262
|
+
decisionOptions: [],
|
|
263
|
+
sourceClient: null,
|
|
264
|
+
runtimeState: null,
|
|
265
|
+
startedAt: null,
|
|
266
|
+
updatedAt: null,
|
|
267
|
+
completedAt: null,
|
|
268
|
+
failedAt: null,
|
|
269
|
+
archivedAt: null,
|
|
270
|
+
lastEventAt: null,
|
|
271
|
+
lastEventSummary: null,
|
|
272
|
+
correlationId: null,
|
|
273
|
+
confidence: "low",
|
|
274
|
+
_terminal: false,
|
|
275
|
+
_statusUpdatedEpoch: 0,
|
|
276
|
+
_updatedEpoch: 0,
|
|
277
|
+
_artifactIds: new Set(),
|
|
278
|
+
_hasExplicitCompletion: false,
|
|
279
|
+
_peakReportedArtifacts: 0,
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
function upsertProjection(map, sliceRunId) {
|
|
283
|
+
const existing = map.get(sliceRunId);
|
|
284
|
+
if (existing)
|
|
285
|
+
return existing;
|
|
286
|
+
const created = createProjection(sliceRunId);
|
|
287
|
+
map.set(sliceRunId, created);
|
|
288
|
+
return created;
|
|
289
|
+
}
|
|
290
|
+
function setStatus(input) {
|
|
291
|
+
const atEpoch = toEpoch(input.atIso);
|
|
292
|
+
const nextTerminal = TERMINAL_STATES.has(input.status);
|
|
293
|
+
const currentTerminal = input.projection._terminal;
|
|
294
|
+
if (currentTerminal && !nextTerminal && !input.force) {
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
if (!input.force && atEpoch > 0 && atEpoch < input.projection._statusUpdatedEpoch) {
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
input.projection.status = input.status;
|
|
301
|
+
input.projection._statusUpdatedEpoch = atEpoch;
|
|
302
|
+
input.projection._terminal = nextTerminal;
|
|
303
|
+
if (input.explainer && input.explainer.trim().length > 0) {
|
|
304
|
+
input.projection.statusExplainer = input.explainer.trim();
|
|
305
|
+
}
|
|
306
|
+
else if (!input.projection.statusExplainer || input.projection.statusExplainer.trim().length === 0) {
|
|
307
|
+
input.projection.statusExplainer = defaultExplainer(input.status);
|
|
308
|
+
}
|
|
309
|
+
input.projection.primaryAction = defaultPrimaryAction(input.status);
|
|
310
|
+
if (input.status === "completed") {
|
|
311
|
+
input.projection.completedAt = input.atIso ?? input.projection.completedAt;
|
|
312
|
+
input.projection.failedAt = null;
|
|
313
|
+
input.projection.archivedAt = null;
|
|
314
|
+
}
|
|
315
|
+
if (input.status === "failed") {
|
|
316
|
+
input.projection.failedAt = input.atIso ?? input.projection.failedAt;
|
|
317
|
+
}
|
|
318
|
+
if (input.status === "archived") {
|
|
319
|
+
input.projection.archivedAt = input.atIso ?? input.projection.archivedAt;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
function updateProjectionContext(projection, item, metadata) {
|
|
323
|
+
const initiativeIdFromMetadata = metadataString(metadata, [
|
|
324
|
+
"initiative_id",
|
|
325
|
+
"initiativeId",
|
|
326
|
+
]);
|
|
327
|
+
const initiativeIds = mergeScopedIds(projection.initiativeIds, projection.initiativeId, [
|
|
328
|
+
...(item.initiativeId ? [item.initiativeId] : []),
|
|
329
|
+
...metadataStringArray(metadata, ["initiative_ids", "initiativeIds"]),
|
|
330
|
+
...(initiativeIdFromMetadata ? [initiativeIdFromMetadata] : []),
|
|
331
|
+
].filter((entry) => typeof entry === "string" && entry.trim().length > 0));
|
|
332
|
+
projection.initiativeIds = initiativeIds;
|
|
333
|
+
projection.initiativeId = projection.initiativeId ?? initiativeIds[0] ?? null;
|
|
334
|
+
const workstreamIdFromMetadata = metadataString(metadata, [
|
|
335
|
+
"workstream_id",
|
|
336
|
+
"workstreamId",
|
|
337
|
+
]);
|
|
338
|
+
const workstreamIds = mergeScopedIds(projection.workstreamIds, projection.workstreamId, [
|
|
339
|
+
...metadataStringArray(metadata, ["workstream_ids", "workstreamIds"]),
|
|
340
|
+
...(workstreamIdFromMetadata ? [workstreamIdFromMetadata] : []),
|
|
341
|
+
].filter((entry) => typeof entry === "string" && entry.trim().length > 0));
|
|
342
|
+
projection.workstreamIds = workstreamIds;
|
|
343
|
+
projection.workstreamId = projection.workstreamId ?? workstreamIds[0] ?? null;
|
|
344
|
+
const iwmtIdFromMetadata = metadataString(metadata, ["iwmt_id", "iwmtId"]);
|
|
345
|
+
const iwmtIds = mergeScopedIds(projection.iwmtIds, projection.iwmtId, [
|
|
346
|
+
...metadataStringArray(metadata, ["iwmt_ids", "iwmtIds"]),
|
|
347
|
+
...(iwmtIdFromMetadata ? [iwmtIdFromMetadata] : []),
|
|
348
|
+
].filter((entry) => typeof entry === "string" && entry.trim().length > 0));
|
|
349
|
+
projection.iwmtIds = iwmtIds;
|
|
350
|
+
projection.iwmtId = projection.iwmtId ?? iwmtIds[0] ?? null;
|
|
351
|
+
projection.workstreamTitle =
|
|
352
|
+
projection.workstreamTitle ??
|
|
353
|
+
metadataString(metadata, ["workstream_title", "workstreamTitle"]);
|
|
354
|
+
const taskIds = metadataStringArray(metadata, ["task_ids", "taskIds", "active_task_ids", "activeTaskIds"]);
|
|
355
|
+
if (taskIds.length > 0) {
|
|
356
|
+
projection.taskIds = dedupeStrings([...projection.taskIds, ...taskIds]);
|
|
357
|
+
}
|
|
358
|
+
const milestoneIds = metadataStringArray(metadata, ["milestone_ids", "milestoneIds"]);
|
|
359
|
+
if (milestoneIds.length > 0) {
|
|
360
|
+
projection.milestoneIds = dedupeStrings([...projection.milestoneIds, ...milestoneIds]);
|
|
361
|
+
}
|
|
362
|
+
projection.correlationId = projection.correlationId ?? resolveCorrelationId(item, metadata);
|
|
363
|
+
projection.sourceClient =
|
|
364
|
+
projection.sourceClient ??
|
|
365
|
+
metadataString(metadata, ["source_client", "sourceClient", "runtime_source"]);
|
|
366
|
+
const eventAt = toIso(item.timestamp);
|
|
367
|
+
const eventEpoch = toEpoch(eventAt);
|
|
368
|
+
if (eventEpoch >= projection._updatedEpoch) {
|
|
369
|
+
projection._updatedEpoch = eventEpoch;
|
|
370
|
+
projection.updatedAt = eventAt;
|
|
371
|
+
projection.lastEventAt = eventAt;
|
|
372
|
+
projection.lastEventSummary =
|
|
373
|
+
(item.summary && item.summary.trim().length > 0
|
|
374
|
+
? item.summary.trim()
|
|
375
|
+
: item.description && item.description.trim().length > 0
|
|
376
|
+
? item.description.trim()
|
|
377
|
+
: item.title) ?? projection.lastEventSummary;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
function maybeAddArtifact(projection, item, metadata) {
|
|
381
|
+
const artifactId = metadataString(metadata, ["artifact_id", "artifactId"]);
|
|
382
|
+
const dedupeKey = artifactId ?? `${item.id}:artifact`;
|
|
383
|
+
if (projection._artifactIds.has(dedupeKey))
|
|
384
|
+
return;
|
|
385
|
+
projection._artifactIds.add(dedupeKey);
|
|
386
|
+
const artifact = {
|
|
387
|
+
id: artifactId,
|
|
388
|
+
type: metadataString(metadata, ["artifact_type", "artifactType"]),
|
|
389
|
+
title: (item.title ?? "Artifact").trim() || "Artifact",
|
|
390
|
+
url: metadataString(metadata, ["url", "artifact_url", "artifactUrl"]),
|
|
391
|
+
createdAt: toIso(item.timestamp),
|
|
392
|
+
};
|
|
393
|
+
projection.artifacts = projection.artifacts.concat(artifact).slice(-20);
|
|
394
|
+
projection.artifactCount = projection._artifactIds.size;
|
|
395
|
+
projection.hasArtifact = projection.artifactCount > 0;
|
|
396
|
+
if (projection.status === "needs_review") {
|
|
397
|
+
setStatus({
|
|
398
|
+
projection,
|
|
399
|
+
status: "completed",
|
|
400
|
+
atIso: artifact.createdAt,
|
|
401
|
+
explainer: "Artifact evidence was recorded after completion.",
|
|
402
|
+
force: true,
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
function mergeDecisionOptions(projection, optionsRaw) {
|
|
407
|
+
if (!Array.isArray(optionsRaw))
|
|
408
|
+
return;
|
|
409
|
+
const next = [];
|
|
410
|
+
for (const option of optionsRaw) {
|
|
411
|
+
const record = asRecord(option);
|
|
412
|
+
if (!record)
|
|
413
|
+
continue;
|
|
414
|
+
const id = normalizeText(record.id) ?? normalizeText(record.option_id) ?? null;
|
|
415
|
+
const label = normalizeText(record.label);
|
|
416
|
+
if (!id || !label)
|
|
417
|
+
continue;
|
|
418
|
+
next.push({
|
|
419
|
+
id,
|
|
420
|
+
label,
|
|
421
|
+
description: normalizeText(record.description),
|
|
422
|
+
impliedStatus: normalizeText(record.impliedStatus ?? record.implied_status),
|
|
423
|
+
requiresNote: metadataBoolean(record, ["requiresNote", "requires_note"]) ?? false,
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
if (next.length === 0)
|
|
427
|
+
return;
|
|
428
|
+
const merged = new Map();
|
|
429
|
+
for (const option of projection.decisionOptions)
|
|
430
|
+
merged.set(option.id, option);
|
|
431
|
+
for (const option of next)
|
|
432
|
+
merged.set(option.id, option);
|
|
433
|
+
projection.decisionOptions = Array.from(merged.values()).slice(0, 8);
|
|
434
|
+
}
|
|
435
|
+
function applySessionFallback(projection, session) {
|
|
436
|
+
const status = (session.status ?? "").trim().toLowerCase();
|
|
437
|
+
const updatedAt = toIso(session.updatedAt ?? session.lastEventAt ?? session.startedAt);
|
|
438
|
+
projection.initiativeIds = mergeScopedIds(projection.initiativeIds, projection.initiativeId, session.initiativeId ? [session.initiativeId] : []);
|
|
439
|
+
projection.workstreamIds = mergeScopedIds(projection.workstreamIds, projection.workstreamId, session.workstreamId ? [session.workstreamId] : []);
|
|
440
|
+
projection.initiativeId = projection.initiativeId ?? projection.initiativeIds[0] ?? null;
|
|
441
|
+
projection.workstreamId = projection.workstreamId ?? projection.workstreamIds[0] ?? null;
|
|
442
|
+
if (RUN_LIKE_STATUS.has(projection.status)) {
|
|
443
|
+
if (!projection.workstreamId && session.workstreamId)
|
|
444
|
+
projection.workstreamId = session.workstreamId;
|
|
445
|
+
if (!projection.workstreamTitle && session.title)
|
|
446
|
+
projection.workstreamTitle = session.title;
|
|
447
|
+
if (!projection.initiativeId && session.initiativeId)
|
|
448
|
+
projection.initiativeId = session.initiativeId;
|
|
449
|
+
}
|
|
450
|
+
if (status === "failed") {
|
|
451
|
+
setStatus({
|
|
452
|
+
projection,
|
|
453
|
+
status: "failed",
|
|
454
|
+
atIso: updatedAt,
|
|
455
|
+
explainer: session.lastEventSummary ?? null,
|
|
456
|
+
force: true,
|
|
457
|
+
});
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
if (status === "blocked") {
|
|
461
|
+
setStatus({
|
|
462
|
+
projection,
|
|
463
|
+
status: "awaiting_input",
|
|
464
|
+
atIso: updatedAt,
|
|
465
|
+
explainer: session.blockerReason ?? session.lastEventSummary ?? null,
|
|
466
|
+
force: projection.status !== "completed",
|
|
467
|
+
});
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
if (status === "completed" && projection.status !== "completed" && projection.hasArtifact) {
|
|
471
|
+
setStatus({
|
|
472
|
+
projection,
|
|
473
|
+
status: "completed",
|
|
474
|
+
atIso: updatedAt,
|
|
475
|
+
explainer: session.lastEventSummary ?? null,
|
|
476
|
+
force: true,
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
export function buildSliceRunProjections(input) {
|
|
481
|
+
const projections = new Map();
|
|
482
|
+
const knownSliceIds = new Set();
|
|
483
|
+
for (const item of input.activity) {
|
|
484
|
+
const metadata = asRecord(item.metadata);
|
|
485
|
+
const event = resolveEventName(metadata);
|
|
486
|
+
const sliceRunId = resolveSliceRunId(item, metadata);
|
|
487
|
+
if (!sliceRunId)
|
|
488
|
+
continue;
|
|
489
|
+
if (event.startsWith("autopilot_slice_") || event.startsWith("auto_continue_spawn_guard_") || event === "next_up_manual_dispatch_started") {
|
|
490
|
+
knownSliceIds.add(sliceRunId);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
const ordered = [...input.activity].sort((a, b) => toEpoch(a.timestamp) - toEpoch(b.timestamp));
|
|
494
|
+
for (const item of ordered) {
|
|
495
|
+
const metadata = asRecord(item.metadata);
|
|
496
|
+
const event = resolveEventName(metadata);
|
|
497
|
+
const sliceRunId = resolveSliceRunId(item, metadata);
|
|
498
|
+
if (!sliceRunId)
|
|
499
|
+
continue;
|
|
500
|
+
if (!resolveRelevantActivity(item, event, metadata, knownSliceIds)) {
|
|
501
|
+
continue;
|
|
502
|
+
}
|
|
503
|
+
const projection = upsertProjection(projections, sliceRunId);
|
|
504
|
+
updateProjectionContext(projection, item, metadata);
|
|
505
|
+
const atIso = toIso(item.timestamp);
|
|
506
|
+
if (item.type === "artifact_created") {
|
|
507
|
+
maybeAddArtifact(projection, item, metadata);
|
|
508
|
+
if (projection.status !== "failed" && projection.status !== "archived") {
|
|
509
|
+
setStatus({
|
|
510
|
+
projection,
|
|
511
|
+
status: "completed",
|
|
512
|
+
atIso,
|
|
513
|
+
explainer: "Artifact generated and attached.",
|
|
514
|
+
force: projection.status !== "completed",
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
continue;
|
|
518
|
+
}
|
|
519
|
+
if (event === "autopilot_slice_dispatched" || event === "next_up_manual_dispatch_started") {
|
|
520
|
+
setStatus({ projection, status: "dispatching", atIso, explainer: item.summary ?? null });
|
|
521
|
+
projection.startedAt = projection.startedAt ?? atIso;
|
|
522
|
+
continue;
|
|
523
|
+
}
|
|
524
|
+
if (event === "autopilot_slice_started" || event === "autopilot_slice_heartbeat") {
|
|
525
|
+
setStatus({ projection, status: "running", atIso, explainer: item.summary ?? null });
|
|
526
|
+
projection.startedAt = projection.startedAt ?? atIso;
|
|
527
|
+
continue;
|
|
528
|
+
}
|
|
529
|
+
if (event === "autopilot_slice_mcp_handshake_failed" ||
|
|
530
|
+
event === "autopilot_slice_timeout" ||
|
|
531
|
+
event === "autopilot_slice_log_stall" ||
|
|
532
|
+
event === "auto_continue_spawn_guard_blocked") {
|
|
533
|
+
setStatus({
|
|
534
|
+
projection,
|
|
535
|
+
status: "awaiting_input",
|
|
536
|
+
atIso,
|
|
537
|
+
explainer: item.summary ?? item.description ?? "Needs intervention to continue.",
|
|
538
|
+
force: true,
|
|
539
|
+
});
|
|
540
|
+
continue;
|
|
541
|
+
}
|
|
542
|
+
if (event === "autopilot_slice_finished" || event === "autopilot_slice_result") {
|
|
543
|
+
const parsedStatus = (metadataString(metadata, ["parsed_status", "status"]) ?? "").toLowerCase();
|
|
544
|
+
const reportedArtifacts = Math.max(0, Math.floor(metadataNumber(metadata, ["artifacts"]) ?? 0));
|
|
545
|
+
projection._peakReportedArtifacts = Math.max(projection._peakReportedArtifacts, reportedArtifacts);
|
|
546
|
+
projection.decisionCount = Math.max(projection.decisionCount, Math.max(0, Math.floor(metadataNumber(metadata, ["decisions"]) ?? 0)));
|
|
547
|
+
projection.blockingDecisionCount = Math.max(projection.blockingDecisionCount, Math.max(0, Math.floor(metadataNumber(metadata, ["blocking_decisions"]) ?? 0)));
|
|
548
|
+
if (parsedStatus === "error") {
|
|
549
|
+
setStatus({
|
|
550
|
+
projection,
|
|
551
|
+
status: "failed",
|
|
552
|
+
atIso,
|
|
553
|
+
explainer: item.summary ?? item.description ?? item.title,
|
|
554
|
+
force: true,
|
|
555
|
+
});
|
|
556
|
+
continue;
|
|
557
|
+
}
|
|
558
|
+
if (parsedStatus === "blocked" || parsedStatus === "needs_decision") {
|
|
559
|
+
setStatus({
|
|
560
|
+
projection,
|
|
561
|
+
status: "awaiting_input",
|
|
562
|
+
atIso,
|
|
563
|
+
explainer: item.summary ?? item.description ?? "Needs decision before it can continue.",
|
|
564
|
+
force: true,
|
|
565
|
+
});
|
|
566
|
+
continue;
|
|
567
|
+
}
|
|
568
|
+
const effectiveArtifactCount = Math.max(projection.artifactCount, reportedArtifacts);
|
|
569
|
+
if (effectiveArtifactCount > 0) {
|
|
570
|
+
projection.artifactCount = effectiveArtifactCount;
|
|
571
|
+
projection.hasArtifact = true;
|
|
572
|
+
setStatus({
|
|
573
|
+
projection,
|
|
574
|
+
status: "completed",
|
|
575
|
+
atIso,
|
|
576
|
+
explainer: item.summary ?? defaultExplainer("completed"),
|
|
577
|
+
force: true,
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
else {
|
|
581
|
+
setStatus({
|
|
582
|
+
projection,
|
|
583
|
+
status: "needs_review",
|
|
584
|
+
atIso,
|
|
585
|
+
explainer: item.summary ??
|
|
586
|
+
"Reported completion without artifact evidence. Review output before closing.",
|
|
587
|
+
force: true,
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
continue;
|
|
591
|
+
}
|
|
592
|
+
if (event === "auto_continue_stopped") {
|
|
593
|
+
const stopReason = (metadataString(metadata, ["stop_reason", "stopReason"]) ?? "").toLowerCase();
|
|
594
|
+
if (stopReason === "error") {
|
|
595
|
+
setStatus({
|
|
596
|
+
projection,
|
|
597
|
+
status: "failed",
|
|
598
|
+
atIso,
|
|
599
|
+
explainer: item.summary ?? item.description ?? defaultExplainer("failed"),
|
|
600
|
+
force: true,
|
|
601
|
+
});
|
|
602
|
+
}
|
|
603
|
+
else if (stopReason === "blocked" || stopReason === "budget_exhausted") {
|
|
604
|
+
setStatus({
|
|
605
|
+
projection,
|
|
606
|
+
status: "awaiting_input",
|
|
607
|
+
atIso,
|
|
608
|
+
explainer: item.summary ?? item.description ?? defaultExplainer("awaiting_input"),
|
|
609
|
+
force: true,
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
else if (stopReason === "completed") {
|
|
613
|
+
if (projection.hasArtifact) {
|
|
614
|
+
setStatus({
|
|
615
|
+
projection,
|
|
616
|
+
status: "completed",
|
|
617
|
+
atIso,
|
|
618
|
+
explainer: item.summary ?? defaultExplainer("completed"),
|
|
619
|
+
force: true,
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
else {
|
|
623
|
+
setStatus({
|
|
624
|
+
projection,
|
|
625
|
+
status: "needs_review",
|
|
626
|
+
atIso,
|
|
627
|
+
explainer: item.summary ?? defaultExplainer("needs_review"),
|
|
628
|
+
force: true,
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
continue;
|
|
633
|
+
}
|
|
634
|
+
if (item.type === "run_completed") {
|
|
635
|
+
projection._hasExplicitCompletion = true;
|
|
636
|
+
setStatus({
|
|
637
|
+
projection,
|
|
638
|
+
status: "completed",
|
|
639
|
+
atIso,
|
|
640
|
+
explainer: item.summary ?? item.description ?? "Accepted and marked complete.",
|
|
641
|
+
force: true,
|
|
642
|
+
});
|
|
643
|
+
continue;
|
|
644
|
+
}
|
|
645
|
+
if (item.type === "run_failed") {
|
|
646
|
+
setStatus({
|
|
647
|
+
projection,
|
|
648
|
+
status: "failed",
|
|
649
|
+
atIso,
|
|
650
|
+
explainer: item.summary ?? item.description ?? item.title,
|
|
651
|
+
force: true,
|
|
652
|
+
});
|
|
653
|
+
continue;
|
|
654
|
+
}
|
|
655
|
+
if (item.type === "decision_requested") {
|
|
656
|
+
setStatus({
|
|
657
|
+
projection,
|
|
658
|
+
status: "awaiting_input",
|
|
659
|
+
atIso,
|
|
660
|
+
explainer: item.summary ?? item.description ?? "Awaiting decision.",
|
|
661
|
+
});
|
|
662
|
+
continue;
|
|
663
|
+
}
|
|
664
|
+
if (item.type === "decision_resolved") {
|
|
665
|
+
// Decision resolved may unblock a slice — revert to running if currently awaiting
|
|
666
|
+
if (projection.status === "awaiting_input") {
|
|
667
|
+
setStatus({
|
|
668
|
+
projection,
|
|
669
|
+
status: "running",
|
|
670
|
+
atIso,
|
|
671
|
+
explainer: item.summary ?? "Decision resolved. Resuming.",
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
continue;
|
|
675
|
+
}
|
|
676
|
+
if (item.type === "milestone_completed") {
|
|
677
|
+
// Milestone completions update context but don't change slice status
|
|
678
|
+
continue;
|
|
679
|
+
}
|
|
680
|
+
if (item.type === "blocker_created") {
|
|
681
|
+
setStatus({
|
|
682
|
+
projection,
|
|
683
|
+
status: "awaiting_input",
|
|
684
|
+
atIso,
|
|
685
|
+
explainer: item.summary ?? item.description ?? "Blocker raised.",
|
|
686
|
+
});
|
|
687
|
+
continue;
|
|
688
|
+
}
|
|
689
|
+
if (item.type === "run_started" || item.type === "delegation") {
|
|
690
|
+
setStatus({
|
|
691
|
+
projection,
|
|
692
|
+
status: "running",
|
|
693
|
+
atIso,
|
|
694
|
+
explainer: item.summary ?? item.description ?? defaultExplainer("running"),
|
|
695
|
+
});
|
|
696
|
+
projection.startedAt = projection.startedAt ?? atIso;
|
|
697
|
+
continue;
|
|
698
|
+
}
|
|
699
|
+
// Handoff types — no slice status change
|
|
700
|
+
if (item.type === "handoff_requested" ||
|
|
701
|
+
item.type === "handoff_claimed" ||
|
|
702
|
+
item.type === "handoff_fulfilled") {
|
|
703
|
+
continue;
|
|
704
|
+
}
|
|
705
|
+
// Exhaustiveness guard: compile error if a new LiveActivityType is
|
|
706
|
+
// added without being handled in this loop.
|
|
707
|
+
const _exhaustiveType = item.type;
|
|
708
|
+
void _exhaustiveType;
|
|
709
|
+
}
|
|
710
|
+
for (const decision of input.decisions) {
|
|
711
|
+
const decisionRecord = asRecord(decision);
|
|
712
|
+
const metadata = asRecord(decisionRecord?.metadata);
|
|
713
|
+
const sliceRunId = decisionRecord
|
|
714
|
+
? resolveDecisionSliceRunId(decisionRecord, metadata)
|
|
715
|
+
: null;
|
|
716
|
+
if (!sliceRunId)
|
|
717
|
+
continue;
|
|
718
|
+
const projection = projections.get(sliceRunId);
|
|
719
|
+
if (!projection)
|
|
720
|
+
continue;
|
|
721
|
+
const status = (normalizeText(decisionRecord?.status) ?? "pending").toLowerCase();
|
|
722
|
+
if (status === "approved" || status === "declined" || status === "cancelled" || status === "resolved") {
|
|
723
|
+
continue;
|
|
724
|
+
}
|
|
725
|
+
projection.decisionCount += 1;
|
|
726
|
+
const isBlocking = metadataBoolean(metadata, ["blocking"]) !== false;
|
|
727
|
+
if (isBlocking)
|
|
728
|
+
projection.blockingDecisionCount += 1;
|
|
729
|
+
mergeDecisionOptions(projection, decisionRecord?.options ?? null);
|
|
730
|
+
const updatedAt = toIso(normalizeText(decisionRecord?.updatedAt)) ??
|
|
731
|
+
toIso(normalizeText(decisionRecord?.requestedAt)) ??
|
|
732
|
+
projection.updatedAt;
|
|
733
|
+
setStatus({
|
|
734
|
+
projection,
|
|
735
|
+
status: "awaiting_input",
|
|
736
|
+
atIso: updatedAt,
|
|
737
|
+
explainer: normalizeText(decisionRecord?.title) ?? "Pending decision requires input.",
|
|
738
|
+
force: projection.status !== "failed",
|
|
739
|
+
});
|
|
740
|
+
}
|
|
741
|
+
for (const session of input.sessions) {
|
|
742
|
+
const runId = normalizeText(session.runId);
|
|
743
|
+
if (!runId)
|
|
744
|
+
continue;
|
|
745
|
+
const projection = projections.get(runId);
|
|
746
|
+
if (!projection)
|
|
747
|
+
continue;
|
|
748
|
+
applySessionFallback(projection, session);
|
|
749
|
+
}
|
|
750
|
+
for (const runtime of input.runtimeInstances) {
|
|
751
|
+
const runId = normalizeText(runtime.runId ?? runtime.correlationId);
|
|
752
|
+
if (!runId)
|
|
753
|
+
continue;
|
|
754
|
+
const projection = projections.get(runId);
|
|
755
|
+
if (!projection)
|
|
756
|
+
continue;
|
|
757
|
+
projection.initiativeIds = mergeScopedIds(projection.initiativeIds, projection.initiativeId, runtime.initiativeId ? [runtime.initiativeId] : []);
|
|
758
|
+
projection.workstreamIds = mergeScopedIds(projection.workstreamIds, projection.workstreamId, runtime.workstreamId ? [runtime.workstreamId] : []);
|
|
759
|
+
projection.initiativeId = projection.initiativeId ?? projection.initiativeIds[0] ?? null;
|
|
760
|
+
projection.workstreamId = projection.workstreamId ?? projection.workstreamIds[0] ?? null;
|
|
761
|
+
projection.runtimeState = runtime.state;
|
|
762
|
+
if (runtime.state === "error" && projection.status !== "failed") {
|
|
763
|
+
setStatus({
|
|
764
|
+
projection,
|
|
765
|
+
status: "failed",
|
|
766
|
+
atIso: runtime.lastEventAt,
|
|
767
|
+
explainer: runtime.lastMessage ?? defaultExplainer("failed"),
|
|
768
|
+
force: true,
|
|
769
|
+
});
|
|
770
|
+
}
|
|
771
|
+
if (runtime.state === "active" && (projection.status === "dispatching" || projection.status === "queued")) {
|
|
772
|
+
setStatus({
|
|
773
|
+
projection,
|
|
774
|
+
status: "running",
|
|
775
|
+
atIso: runtime.lastHeartbeatAt ?? runtime.lastEventAt,
|
|
776
|
+
explainer: projection.lastEventSummary ?? defaultExplainer("running"),
|
|
777
|
+
});
|
|
778
|
+
projection.startedAt = projection.startedAt ?? toIso(runtime.lastEventAt);
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
const nowEpoch = Date.now();
|
|
782
|
+
const output = [];
|
|
783
|
+
for (const projection of projections.values()) {
|
|
784
|
+
if (projection.status === "completed" &&
|
|
785
|
+
!projection.hasArtifact &&
|
|
786
|
+
!projection._hasExplicitCompletion &&
|
|
787
|
+
projection._peakReportedArtifacts === 0) {
|
|
788
|
+
setStatus({
|
|
789
|
+
projection,
|
|
790
|
+
status: "needs_review",
|
|
791
|
+
atIso: projection.updatedAt,
|
|
792
|
+
explainer: "Completed without artifacts; review before closing.",
|
|
793
|
+
force: true,
|
|
794
|
+
});
|
|
795
|
+
}
|
|
796
|
+
if ((projection.status === "queued" || projection.status === "dispatching" || projection.status === "running") &&
|
|
797
|
+
projection.runtimeState === "stale" &&
|
|
798
|
+
projection.artifactCount === 0) {
|
|
799
|
+
const ageMs = nowEpoch - toEpoch(projection.lastEventAt ?? projection.updatedAt);
|
|
800
|
+
if (ageMs >= 6 * 60 * 60 * 1000) {
|
|
801
|
+
setStatus({
|
|
802
|
+
projection,
|
|
803
|
+
status: "archived",
|
|
804
|
+
atIso: projection.updatedAt,
|
|
805
|
+
explainer: "No execution evidence found recently. Archived automatically.",
|
|
806
|
+
force: true,
|
|
807
|
+
});
|
|
808
|
+
}
|
|
809
|
+
else if (projection.status === "running") {
|
|
810
|
+
projection.confidence = "medium";
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
if (!projection.statusExplainer) {
|
|
814
|
+
projection.statusExplainer = defaultExplainer(projection.status);
|
|
815
|
+
}
|
|
816
|
+
if (projection.status === "completed" && projection.hasArtifact) {
|
|
817
|
+
projection.primaryAction = "open_artifact";
|
|
818
|
+
projection.confidence = "high";
|
|
819
|
+
}
|
|
820
|
+
else if (projection.status === "awaiting_input") {
|
|
821
|
+
projection.primaryAction = "resolve_decision";
|
|
822
|
+
projection.confidence = "high";
|
|
823
|
+
}
|
|
824
|
+
else if (projection.status === "failed") {
|
|
825
|
+
projection.primaryAction = "retry_slice";
|
|
826
|
+
projection.confidence = "high";
|
|
827
|
+
}
|
|
828
|
+
else if (projection.status === "needs_review") {
|
|
829
|
+
projection.primaryAction = "review_output";
|
|
830
|
+
projection.confidence = projection.hasArtifact ? "high" : "medium";
|
|
831
|
+
}
|
|
832
|
+
else if (projection.status === "running" || projection.status === "dispatching") {
|
|
833
|
+
projection.confidence = projection.runtimeState === "active" ? "high" : "medium";
|
|
834
|
+
}
|
|
835
|
+
output.push({
|
|
836
|
+
id: projection.id,
|
|
837
|
+
sliceRunId: projection.sliceRunId,
|
|
838
|
+
runId: projection.runId,
|
|
839
|
+
initiativeId: projection.initiativeId,
|
|
840
|
+
initiativeIds: projection.initiativeIds,
|
|
841
|
+
workstreamId: projection.workstreamId,
|
|
842
|
+
workstreamIds: projection.workstreamIds,
|
|
843
|
+
iwmtId: projection.iwmtId,
|
|
844
|
+
iwmtIds: projection.iwmtIds,
|
|
845
|
+
workstreamTitle: projection.workstreamTitle,
|
|
846
|
+
taskIds: projection.taskIds,
|
|
847
|
+
milestoneIds: projection.milestoneIds,
|
|
848
|
+
status: projection.status,
|
|
849
|
+
statusExplainer: projection.statusExplainer,
|
|
850
|
+
primaryAction: projection.primaryAction,
|
|
851
|
+
hasArtifact: projection.hasArtifact,
|
|
852
|
+
artifactCount: projection.artifactCount,
|
|
853
|
+
artifacts: projection.artifacts,
|
|
854
|
+
decisionCount: projection.decisionCount,
|
|
855
|
+
blockingDecisionCount: projection.blockingDecisionCount,
|
|
856
|
+
decisionOptions: projection.decisionOptions,
|
|
857
|
+
sourceClient: projection.sourceClient,
|
|
858
|
+
runtimeState: projection.runtimeState,
|
|
859
|
+
startedAt: projection.startedAt,
|
|
860
|
+
updatedAt: projection.updatedAt,
|
|
861
|
+
completedAt: projection.completedAt,
|
|
862
|
+
failedAt: projection.failedAt,
|
|
863
|
+
archivedAt: projection.archivedAt,
|
|
864
|
+
lastEventAt: projection.lastEventAt,
|
|
865
|
+
lastEventSummary: projection.lastEventSummary,
|
|
866
|
+
correlationId: projection.correlationId,
|
|
867
|
+
confidence: projection.confidence,
|
|
868
|
+
});
|
|
869
|
+
}
|
|
870
|
+
output.sort((a, b) => {
|
|
871
|
+
const updatedDelta = toEpoch(b.updatedAt ?? b.lastEventAt) - toEpoch(a.updatedAt ?? a.lastEventAt);
|
|
872
|
+
if (updatedDelta !== 0)
|
|
873
|
+
return updatedDelta;
|
|
874
|
+
return a.sliceRunId.localeCompare(b.sliceRunId);
|
|
875
|
+
});
|
|
876
|
+
return output;
|
|
877
|
+
}
|