@atolis-hq/wake 0.4.108 → 0.4.110

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.
@@ -12,6 +12,8 @@ export declare function createAnalyticsReports(journal: EventJournal, now: () =>
12
12
  }>;
13
13
  summary(windowId: ReportWindowId, signal?: AbortSignal): Promise<{
14
14
  data: {
15
+ acceptedChildResults: number;
16
+ correctiveActivations: number;
15
17
  workItemsDone: number;
16
18
  medianEndToEndDurationMs: number | null;
17
19
  runs: number;
@@ -1,6 +1,6 @@
1
1
  import { createRunBreakdownReport, createRunDurationReport, createRunOutcomesReport, createRunUsageReport, queryRunAnalytics, } from '../execution/index.js';
2
2
  import { reportWindow } from '../kernel/index.js';
3
- import { createWorkThroughputReport, queryWorkCompletionSummary } from '../orchestration/index.js';
3
+ import { DeliveryActivityMeasure, createDeliveryActivityReport, createWorkThroughputReport, queryDeliveryActivity, queryWorkCompletionSummary, readCompletionFacts, } from '../orchestration/index.js';
4
4
  import { createRunRepositoryLookup } from './run-repository-lookup.js';
5
5
  import { sampledMeta } from './surface-api-metadata.js';
6
6
  export function createAnalyticsReports(journal, now, resolveIdentity) {
@@ -9,6 +9,7 @@ export function createAnalyticsReports(journal, now, resolveIdentity) {
9
9
  createRunBreakdownReport(journal, createRunRepositoryLookup(journal, resolveIdentity)),
10
10
  createRunUsageReport(journal),
11
11
  createWorkThroughputReport(journal),
12
+ createDeliveryActivityReport(journal),
12
13
  createRunDurationReport(journal),
13
14
  ];
14
15
  return {
@@ -32,12 +33,21 @@ export function createAnalyticsReports(journal, now, resolveIdentity) {
32
33
  window: reportWindow(windowId, collectedAt),
33
34
  ...(signal === undefined ? {} : { signal }),
34
35
  };
35
- const [runs, work] = await Promise.all([
36
+ // Root completion facts are read once and shared by both work-derived summaries.
37
+ const completion = await readCompletionFacts(journal, query);
38
+ const [runs, work, delivery] = await Promise.all([
36
39
  queryRunAnalytics(journal, query),
37
- queryWorkCompletionSummary(journal, query),
40
+ queryWorkCompletionSummary(journal, query, completion),
41
+ queryDeliveryActivity(journal, query, completion),
38
42
  ]);
39
43
  return {
40
- data: { window: query.window, ...runs.summary, ...work },
44
+ data: {
45
+ window: query.window,
46
+ ...runs.summary,
47
+ ...work,
48
+ acceptedChildResults: delivery.totals[DeliveryActivityMeasure.AcceptedChildResults] ?? 0,
49
+ correctiveActivations: delivery.totals[DeliveryActivityMeasure.CorrectiveActivations] ?? 0,
50
+ },
41
51
  meta: sampledMeta(collectedAt),
42
52
  };
43
53
  },
@@ -1,4 +1,5 @@
1
- import { presentResource, toWorkItemKey } from '../surfaces/index.js';
1
+ import { DelegationOutputKind, WorkflowArtifactOutputKind } from '../orchestration/index.js';
2
+ import { presentResource, toWorkItemKey, } from '../surfaces/index.js';
2
3
  export async function presentDelivery(root, work) {
3
4
  if (root.orchestration?.deliveryTree === undefined)
4
5
  return {};
@@ -6,14 +7,18 @@ export async function presentDelivery(root, work) {
6
7
  if (cohorts.length === 0 && work.delegation === undefined)
7
8
  return {};
8
9
  const delivery = await root.work.deliverySnapshot();
9
- const qa = await deliveryQaFor(root, work);
10
+ const parent = await primaryWorkflowFor(root, work);
11
+ const state = parent === undefined
12
+ ? undefined
13
+ : await root.orchestration.deliveryStateFor(parent.workflowInstanceId);
14
+ const attention = await presentAttention(root, parent);
15
+ const qa = state === undefined ? undefined : presentQa(state);
16
+ const selected = new Set(state?.selection?.entries.map((entry) => `${entry.childWorkItemId}/${entry.output.name}`));
17
+ const stale = staleOutputs(state, cohorts);
18
+ const staleKeys = new Set(stale.map((entry) => `${entry.workItemKey}/${entry.outputName}`));
10
19
  return {
11
20
  delegation: {
12
- ...(qa === undefined ? {} : { qa }),
13
- rootWorkItemKey: toWorkItemKey(work.delegation?.rootWorkItemId ?? work.workItemId),
14
- ...(work.delegation === undefined
15
- ? {}
16
- : { parentWorkItemKey: toWorkItemKey(work.delegation.parentWorkItemId) }),
21
+ ...presentHeader(work, cohorts, attention, qa === undefined ? undefined : { ...qa, staleOutputs: stale }),
17
22
  children: await Promise.all(cohorts.flatMap((cohort) => cohort.children.map(async (child) => {
18
23
  const availability = delivery.availability(child.workItemId);
19
24
  const resources = await Promise.all((await root.resources.correlationsForWork(child.workItemId)).map((entry) => root.resources.get(entry.resourceId)));
@@ -24,6 +29,10 @@ export async function presentDelivery(root, work) {
24
29
  workflowName: child.workflowName,
25
30
  status: child.workflow?.status ?? 'registration-pending',
26
31
  cohortId: cohort.cohortId,
32
+ ...(child.prerequisiteBlocker === undefined
33
+ ? {}
34
+ : { prerequisiteBlocker: child.prerequisiteBlocker }),
35
+ ...presentPlacement(child, selected, staleKeys),
27
36
  ...((availability.reason ?? child.prerequisiteBlocker ?? child.workflow?.blockReason)
28
37
  ? {
29
38
  blockReason: (availability.reason ??
@@ -39,53 +48,131 @@ export async function presentDelivery(root, work) {
39
48
  },
40
49
  };
41
50
  }
42
- async function deliveryQaFor(root, work) {
43
- const parent = (await root.orchestration.listAll()).find((view) => view.workItemId === work.workItemId && view.parentWorkflowInstanceId === undefined);
44
- const state = parent === undefined
45
- ? undefined
46
- : await root.orchestration.deliveryStateFor(parent.workflowInstanceId);
47
- return state === undefined
48
- ? undefined
49
- : {
50
- ...(state.integration === null
51
- ? {}
52
- : {
53
- integration: {
54
- complete: state.integration.complete,
55
- summary: state.integration.summary,
56
- targets: state.integration.targets.map((target) => ({
57
- workItemKey: toWorkItemKey(target.ownerWorkItemId),
58
- outputName: target.output.outputName,
59
- state: target.state,
60
- layer: target.layer,
61
- baseMovement: target.baseMovement,
62
- evidenceAffected: target.evidenceAffected,
63
- ...(target.maintenance === undefined ? {} : { maintenance: target.maintenance }),
64
- ...(target.detail === undefined ? {} : { detail: target.detail }),
65
- })),
66
- maintenance: state.maintenance.map((item) => ({
67
- maintenanceId: item.maintenanceId,
68
- workItemKey: toWorkItemKey(item.target.childWorkItemId),
69
- outputName: item.target.outputName,
70
- kind: item.kind,
71
- previousRevision: item.previous.revision,
72
- currentRevision: item.current.revision,
73
- producerRunId: item.producer.runId,
74
- })),
51
+ function presentHeader(work, cohorts, attention, qa) {
52
+ return {
53
+ ...(qa === undefined ? {} : { qa }),
54
+ ...(attention === undefined ? {} : { attention }),
55
+ cohorts: cohorts.map((cohort) => ({
56
+ cohortId: cohort.cohortId,
57
+ settled: cohort.settled,
58
+ ...(cohort.failureReason === undefined ? {} : { failureReason: cohort.failureReason }),
59
+ })),
60
+ rootWorkItemKey: toWorkItemKey(work.delegation?.rootWorkItemId ?? work.workItemId),
61
+ ...(work.delegation === undefined
62
+ ? {}
63
+ : { parentWorkItemKey: toWorkItemKey(work.delegation.parentWorkItemId) }),
64
+ };
65
+ }
66
+ /** Stale keys are `cohort/assignment/output`; the reason is the one the selection rules apply. */
67
+ function staleOutputs(state, cohorts) {
68
+ const owners = new Map(cohorts.flatMap((cohort) => cohort.children.map((child) => [`${cohort.cohortId}/${child.assignmentId}`, child])));
69
+ return (state?.stale ?? []).flatMap((key) => {
70
+ const [cohortId, assignmentId, ...name] = key.split('/');
71
+ const owner = owners.get(`${cohortId}/${assignmentId}`);
72
+ return owner === undefined
73
+ ? []
74
+ : [
75
+ {
76
+ workItemKey: toWorkItemKey(owner.workItemId),
77
+ outputName: name.join('/'),
78
+ reason: 'Built on an output that has since been replaced; it must be refreshed or reselected',
79
+ },
80
+ ];
81
+ });
82
+ }
83
+ function presentPlacement(child, selected, staleKeys) {
84
+ return {
85
+ ...(child.workflow === null ? {} : { currentStage: child.workflow.currentStage }),
86
+ ...(child.repository === undefined
87
+ ? {}
88
+ : {
89
+ repository: {
90
+ resourceId: child.repository.resourceId,
91
+ pullRequestBase: child.repository.pullRequestBase,
92
+ },
93
+ }),
94
+ prerequisites: (child.prerequisiteWorkItemIds ?? []).map(toWorkItemKey),
95
+ ...(child.replaces === undefined ? {} : { replaces: child.replaces }),
96
+ outputs: child.outputs.map((output) => ({
97
+ ...('repository' in output && output.repository !== undefined
98
+ ? {
99
+ repository: {
100
+ resourceId: output.repository.resourceId,
101
+ pullRequestBase: output.repository.pullRequestBase,
75
102
  },
76
- }),
77
- selectionRevision: state.selectionRevision,
78
- ...(state.candidate === null ? {} : { candidateId: state.candidate.candidateId }),
79
- repositories: state.candidate?.repositories.map((entry) => ({
80
- resourceId: entry.resourceId,
81
- revision: entry.revision,
82
- })) ?? [],
83
- stale: state.stale,
84
- ...(state.qa === null ? {} : { verdict: state.qa.verdict }),
85
- effective: state.qaEffective,
86
- canComplete: state.completion.complete,
87
- ...(state.completion.reason === undefined ? {} : { reason: state.completion.reason }),
88
- exhausted: state.repair.exhausted,
89
- findings: state.repair.unresolvedFindings,
90
- };
103
+ }
104
+ : {}),
105
+ name: output.name,
106
+ kind: 'kind' in output ? DelegationOutputKind.Change : WorkflowArtifactOutputKind,
107
+ required: output.required !== false,
108
+ selected: selected.has(`${child.workItemId}/${output.name}`),
109
+ stale: staleKeys.has(`${toWorkItemKey(child.workItemId)}/${output.name}`),
110
+ })),
111
+ };
112
+ }
113
+ async function primaryWorkflowFor(root, work) {
114
+ return (await root.orchestration.listAll()).find((view) => view.workItemId === work.workItemId && view.parentWorkflowInstanceId === undefined);
115
+ }
116
+ /** The parent's open attention request and the replies already accepted for it. */
117
+ async function presentAttention(root, parent) {
118
+ if (parent?.delegationAttention === undefined)
119
+ return undefined;
120
+ const open = await root.orchestration.openDelegationAttention(parent.workflowInstanceId, parent.delegationAttention.activationId);
121
+ if (open === null)
122
+ return undefined;
123
+ return {
124
+ cohortId: open.cohortId,
125
+ revision: open.revision,
126
+ blockers: open.blockers.map((blocker) => ({
127
+ blockerId: blocker.blockerId,
128
+ workItemKey: toWorkItemKey(blocker.childWorkItemId),
129
+ kind: blocker.kind,
130
+ reason: blocker.reason,
131
+ answered: open.responses.some((reply) => reply.blockerId === blocker.blockerId),
132
+ })),
133
+ };
134
+ }
135
+ function presentQa(state) {
136
+ return {
137
+ ...(state.integration === null
138
+ ? {}
139
+ : {
140
+ integration: {
141
+ complete: state.integration.complete,
142
+ summary: state.integration.summary,
143
+ targets: state.integration.targets.map((target) => ({
144
+ workItemKey: toWorkItemKey(target.ownerWorkItemId),
145
+ outputName: target.output.outputName,
146
+ state: target.state,
147
+ layer: target.layer,
148
+ baseMovement: target.baseMovement,
149
+ evidenceAffected: target.evidenceAffected,
150
+ ...(target.maintenance === undefined ? {} : { maintenance: target.maintenance }),
151
+ ...(target.detail === undefined ? {} : { detail: target.detail }),
152
+ })),
153
+ maintenance: state.maintenance.map((item) => ({
154
+ maintenanceId: item.maintenanceId,
155
+ workItemKey: toWorkItemKey(item.target.childWorkItemId),
156
+ outputName: item.target.outputName,
157
+ kind: item.kind,
158
+ previousRevision: item.previous.revision,
159
+ currentRevision: item.current.revision,
160
+ producerRunId: item.producer.runId,
161
+ })),
162
+ },
163
+ }),
164
+ selectionRevision: state.selectionRevision,
165
+ ...(state.candidate === null ? {} : { candidateId: state.candidate.candidateId }),
166
+ repositories: state.candidate?.repositories.map((entry) => ({
167
+ resourceId: entry.resourceId,
168
+ revision: entry.revision,
169
+ })) ?? [],
170
+ stale: state.stale,
171
+ ...(state.qa === null ? {} : { verdict: state.qa.verdict }),
172
+ effective: state.qaEffective,
173
+ canComplete: state.completion.complete,
174
+ ...(state.completion.reason === undefined ? {} : { reason: state.completion.reason }),
175
+ exhausted: state.repair.exhausted,
176
+ findings: state.repair.unresolvedFindings,
177
+ };
91
178
  }
@@ -124,6 +124,6 @@ export function resolveWakeVersion(options = {}) {
124
124
  return `g${headHash.slice(0, 7)}`;
125
125
  return '0.1.0-dev';
126
126
  }
127
- export const wakeVersion = "v0.4.108";
127
+ export const wakeVersion = "v0.4.110";
128
128
  /** The registry-installable version used by packaged sandbox images. */
129
129
  export const wakePackageVersion = packageVersion(defaultRepoRoot) ?? wakeVersion;
@@ -20,6 +20,9 @@ export function createClaudeRunner(options = {}) {
20
20
  supportsEphemeralMcp: true,
21
21
  });
22
22
  }
23
+ // `claude -p` stays alive until a pending wakeup fires, even past its background-wait cap.
24
+ // A finished run would hang until Wake's idle timeout kills it and discards the result.
25
+ const claudeDisallowedTools = ['ScheduleWakeup'];
23
26
  export function claudeCommandArgs(request, passthroughArgs = [], defaults = {}) {
24
27
  const model = request.model ?? defaults.model;
25
28
  const effort = request.effort ?? defaults.effort;
@@ -36,6 +39,8 @@ export function claudeCommandArgs(request, passthroughArgs = [], defaults = {})
36
39
  ...(request.allowedTools.length === 0
37
40
  ? []
38
41
  : ['--allowedTools', claudeAllowedTools(request).join(' ')]),
42
+ '--disallowedTools',
43
+ claudeDisallowedTools.join(' '),
39
44
  ...(request.mcpServers === undefined || request.mcpServers.length === 0
40
45
  ? []
41
46
  : ['--mcp-config', JSON.stringify(claudeMcpConfig(request)), '--strict-mcp-config']),
@@ -0,0 +1,13 @@
1
+ import { type EventJournal } from '@atolis-hq/eventing';
2
+ import { type ReportDefinition, type ReportQuery, type TimeSeriesReport } from '../../kernel/index.js';
3
+ import { type CompletionFacts } from './work-completion-summary.js';
4
+ export declare const DeliveryActivityReportId: {
5
+ readonly Activity: "delivery-activity";
6
+ };
7
+ export declare const DeliveryActivityMeasure: {
8
+ readonly RootDeliveries: "root-deliveries";
9
+ readonly AcceptedChildResults: "accepted-child-results";
10
+ readonly CorrectiveActivations: "corrective-activations";
11
+ };
12
+ export declare function createDeliveryActivityReport(journal: EventJournal): ReportDefinition;
13
+ export declare function queryDeliveryActivity(journal: EventJournal, query: ReportQuery, shared?: CompletionFacts): Promise<TimeSeriesReport>;
@@ -0,0 +1,127 @@
1
+ import { scanJournal, yieldScan } from '@atolis-hq/eventing';
2
+ import { ExecutionEventType, selectRunExecutionEvent } from '../../execution/index.js';
3
+ import { defineClosedVocabulary, } from '../../kernel/index.js';
4
+ import { selectOrchestrationEvent } from '../contracts/event-decoder.js';
5
+ import { OrchestrationEventType } from '../contracts/events.js';
6
+ import { readCompletionFacts } from './work-completion-summary.js';
7
+ export const DeliveryActivityReportId = defineClosedVocabulary({
8
+ Activity: 'delivery-activity',
9
+ });
10
+ export const DeliveryActivityMeasure = defineClosedVocabulary({
11
+ RootDeliveries: 'root-deliveries',
12
+ AcceptedChildResults: 'accepted-child-results',
13
+ CorrectiveActivations: 'corrective-activations',
14
+ });
15
+ const descriptor = { id: DeliveryActivityReportId.Activity, title: 'Delivery activity' };
16
+ const series = [
17
+ { id: DeliveryActivityMeasure.RootDeliveries, title: 'Root deliveries', unit: 'work items' },
18
+ {
19
+ id: DeliveryActivityMeasure.AcceptedChildResults,
20
+ title: 'Accepted child results',
21
+ unit: 'results',
22
+ },
23
+ {
24
+ id: DeliveryActivityMeasure.CorrectiveActivations,
25
+ title: 'Corrective activations',
26
+ unit: 'activations',
27
+ },
28
+ ];
29
+ export function createDeliveryActivityReport(journal) {
30
+ return { ...descriptor, query: (query) => queryDeliveryActivity(journal, query) };
31
+ }
32
+ function acceptDeliveryFact(facts, event) {
33
+ const run = selectRunExecutionEvent(event);
34
+ if (run !== null) {
35
+ if (run.event.eventType === ExecutionEventType.RunPreparationStarted ||
36
+ run.event.eventType === ExecutionEventType.RunStarted)
37
+ facts.runs.push({
38
+ activationId: run.event.payload.activationId,
39
+ workflowInstanceId: run.event.payload.workflowInstanceId,
40
+ startedAt: Date.parse(run.event.payload.startedAt),
41
+ });
42
+ return;
43
+ }
44
+ const owned = selectOrchestrationEvent(event);
45
+ if (owned === null)
46
+ return;
47
+ switch (owned.event.eventType) {
48
+ case OrchestrationEventType.DelegationReserved:
49
+ for (const child of owned.event.payload.children)
50
+ if (child.replaces !== undefined)
51
+ facts.correctiveInstances.add(child.workflowInstanceId);
52
+ return;
53
+ case OrchestrationEventType.DeliveryMaintenanceRecorded:
54
+ facts.correctiveActivations.add(owned.event.payload.producer.activationId);
55
+ return;
56
+ case OrchestrationEventType.DelegationResultSelected: {
57
+ const key = `${owned.event.payload.cohortId}/${owned.event.payload.childWorkItemId}`;
58
+ if (!facts.resultTimes.has(key))
59
+ facts.resultTimes.set(key, Date.parse(owned.event.occurredAt));
60
+ return;
61
+ }
62
+ default:
63
+ return;
64
+ }
65
+ }
66
+ /** Retries of one activation are separate Run attempts; the earliest start places the activation. */
67
+ function correctiveStarts(facts) {
68
+ for (const run of facts.runs)
69
+ if (facts.correctiveInstances.has(run.workflowInstanceId))
70
+ facts.correctiveActivations.add(run.activationId);
71
+ const firstStart = new Map();
72
+ for (const run of facts.runs) {
73
+ if (!facts.correctiveActivations.has(run.activationId) || !Number.isFinite(run.startedAt))
74
+ continue;
75
+ const known = firstStart.get(run.activationId);
76
+ if (known === undefined || run.startedAt < known)
77
+ firstStart.set(run.activationId, run.startedAt);
78
+ }
79
+ return firstStart;
80
+ }
81
+ export async function queryDeliveryActivity(journal, query, shared) {
82
+ const roots = shared ?? (await readCompletionFacts(journal, query));
83
+ const facts = {
84
+ resultTimes: new Map(),
85
+ correctiveInstances: new Set(),
86
+ correctiveActivations: new Set(),
87
+ runs: [],
88
+ };
89
+ for await (const event of scanJournal(journal, query.signal))
90
+ acceptDeliveryFact(facts, event);
91
+ const firstStart = correctiveStarts(facts);
92
+ const resultTimes = facts.resultTimes;
93
+ const from = Date.parse(query.window.from), to = Date.parse(query.window.to);
94
+ const first = Math.floor(from / query.window.bucketMs) * query.window.bucketMs;
95
+ const buckets = [];
96
+ for (let start = first; start < to; start += query.window.bucketMs)
97
+ buckets.push({
98
+ from: new Date(start).toISOString(),
99
+ to: new Date(start + query.window.bucketMs).toISOString(),
100
+ values: Object.fromEntries(series.map(({ id }) => [id, 0])),
101
+ });
102
+ const totals = Object.fromEntries(series.map(({ id }) => [id, 0]));
103
+ let processed = 0;
104
+ const add = (measure, at) => {
105
+ if (!(at >= from && at < to))
106
+ return;
107
+ totals[measure]++;
108
+ buckets[Math.floor((at - first) / query.window.bucketMs)].values[measure]++;
109
+ };
110
+ for (const at of roots.completed.values()) {
111
+ if (processed++ % 100 === 0)
112
+ await yieldScan(query.signal);
113
+ add(DeliveryActivityMeasure.RootDeliveries, at);
114
+ }
115
+ for (const at of resultTimes.values())
116
+ add(DeliveryActivityMeasure.AcceptedChildResults, at);
117
+ for (const at of firstStart.values())
118
+ add(DeliveryActivityMeasure.CorrectiveActivations, at);
119
+ const report = {
120
+ report: descriptor,
121
+ window: query.window,
122
+ series,
123
+ totals,
124
+ buckets,
125
+ };
126
+ return report;
127
+ }
@@ -1,9 +1,18 @@
1
1
  import { type EventJournal } from '@atolis-hq/eventing';
2
2
  import { type ReportDefinition, type ReportQuery, type TimeSeriesReport } from '../../kernel/index.js';
3
- export declare function queryWorkCompletionSummary(journal: EventJournal, query: ReportQuery): Promise<{
3
+ export interface CompletionFacts {
4
+ readonly created: Map<string, number>;
5
+ readonly titles: Map<string, string>;
6
+ readonly instances: Map<string, string>;
7
+ readonly completed: Map<string, number>;
8
+ /** Registered delegated descendants: their completion is a child result, not a delivered root. */
9
+ readonly delegated: Set<string>;
10
+ }
11
+ export declare function queryWorkCompletionSummary(journal: EventJournal, query: ReportQuery, shared?: CompletionFacts): Promise<{
4
12
  workItemsDone: number;
5
13
  medianEndToEndDurationMs: number | null;
6
14
  }>;
15
+ export declare function readCompletionFacts(journal: EventJournal, query: ReportQuery): Promise<CompletionFacts>;
7
16
  export declare const WorkReportId: {
8
17
  readonly Throughput: "work-item-throughput";
9
18
  };
@@ -3,8 +3,8 @@ import { defineClosedVocabulary, median, } from '../../kernel/index.js';
3
3
  import { selectWorkEvent, WorkEventType } from '../../work/index.js';
4
4
  import { selectWorkflowOrchestrationEvent } from '../contracts/event-decoder.js';
5
5
  import { OrchestrationEventType } from '../contracts/events.js';
6
- export async function queryWorkCompletionSummary(journal, query) {
7
- const facts = await readCompletionFacts(journal, query);
6
+ export async function queryWorkCompletionSummary(journal, query, shared) {
7
+ const facts = shared ?? (await readCompletionFacts(journal, query));
8
8
  const from = Date.parse(query.window.from), to = Date.parse(query.window.to);
9
9
  let workItemsDone = 0, processed = 0;
10
10
  const durations = [];
@@ -28,13 +28,16 @@ function acceptFact(facts, event) {
28
28
  if (work?.event.eventType === WorkEventType.ItemCreated) {
29
29
  facts.created.set(work.stream.id, Date.parse(work.event.occurredAt));
30
30
  facts.titles.set(work.stream.id, work.event.payload.objective);
31
+ if (work.event.payload.delegation !== undefined)
32
+ facts.delegated.add(work.stream.id);
31
33
  }
32
34
  const workflow = selectWorkflowOrchestrationEvent(event);
33
35
  if (workflow === null)
34
36
  return;
35
37
  switch (workflow.event.eventType) {
36
38
  case OrchestrationEventType.InstanceStarted:
37
- if (!('parentWorkflowInstanceId' in workflow.event.payload))
39
+ if (!('parentWorkflowInstanceId' in workflow.event.payload) &&
40
+ !facts.delegated.has(workflow.event.payload.workItemId))
38
41
  facts.instances.set(workflow.stream.id, workflow.event.payload.workItemId);
39
42
  return;
40
43
  case OrchestrationEventType.InstanceCompleted: {
@@ -47,12 +50,13 @@ function acceptFact(facts, event) {
47
50
  return;
48
51
  }
49
52
  }
50
- async function readCompletionFacts(journal, query) {
53
+ export async function readCompletionFacts(journal, query) {
51
54
  const facts = {
52
55
  created: new Map(),
53
56
  titles: new Map(),
54
57
  instances: new Map(),
55
58
  completed: new Map(),
59
+ delegated: new Set(),
56
60
  };
57
61
  for await (const event of scanJournal(journal, query.signal))
58
62
  acceptFact(facts, event);
@@ -30,6 +30,7 @@ export * from './domain/dispatch-priority.js';
30
30
  export * from './domain/interpreter.js';
31
31
  export * from './domain/workflow-instance.js';
32
32
  export * from './domain/workflow-selector.js';
33
+ export * from './application/delivery-activity-report.js';
33
34
  export * from './application/work-completion-summary.js';
34
35
  export type { WorkflowCompileDiagnostic } from './domain/compile-diagnostics.js';
35
36
  export type { DelegationArtifacts, DelegationRepositories } from './contracts/delegation-ports.js';
@@ -30,6 +30,7 @@ export * from './domain/dispatch-priority.js';
30
30
  export * from './domain/interpreter.js';
31
31
  export * from './domain/workflow-instance.js';
32
32
  export * from './domain/workflow-selector.js';
33
+ export * from './application/delivery-activity-report.js';
33
34
  export * from './application/work-completion-summary.js';
34
35
  export { DelegationAttentionError, DelegationConflictError, DelegationPendingError, } from './contracts/delegation.js';
35
36
  export { DeliveryRejectionError, deliveryCandidateCommandSchema, deliveryMaintenanceCommandSchema, deliveryQaCommandSchema, deliverySelectionCommandSchema, } from './contracts/delivery.js';
@@ -21,5 +21,7 @@ export interface AnalyticsSummaryResponse {
21
21
  readonly totalCostUsd: number;
22
22
  readonly medianRunDurationMs: number | null;
23
23
  readonly workItemsDone: number;
24
+ readonly acceptedChildResults: number;
25
+ readonly correctiveActivations: number;
24
26
  readonly medianEndToEndDurationMs: number | null;
25
27
  }
@@ -52,6 +52,12 @@ export interface DeliveryQaResponse {
52
52
  readonly revision: string;
53
53
  }[];
54
54
  readonly stale: readonly string[];
55
+ /** Why each stale selected output no longer counts as current evidence. */
56
+ readonly staleOutputs?: readonly {
57
+ readonly workItemKey: WorkItemKey;
58
+ readonly outputName: string;
59
+ readonly reason: string;
60
+ }[];
55
61
  readonly verdict?: string;
56
62
  readonly effective: boolean;
57
63
  readonly canComplete: boolean;
@@ -64,13 +70,57 @@ export interface WorkDetailResponse {
64
70
  readonly qa?: DeliveryQaResponse;
65
71
  readonly rootWorkItemKey: WorkItemKey;
66
72
  readonly parentWorkItemKey?: WorkItemKey;
73
+ /** Present while the parent is waiting on an assessment of blocked children. */
74
+ readonly attention?: {
75
+ readonly cohortId: string;
76
+ readonly revision: number;
77
+ readonly blockers: readonly {
78
+ readonly blockerId: string;
79
+ readonly workItemKey: WorkItemKey;
80
+ readonly kind: string;
81
+ readonly reason: string;
82
+ /** A parent reply has been accepted for this blocker. */
83
+ readonly answered: boolean;
84
+ }[];
85
+ };
86
+ readonly cohorts?: readonly {
87
+ readonly cohortId: string;
88
+ /** The join has resolved; an unsettled cohort is still waiting on required children. */
89
+ readonly settled: boolean;
90
+ readonly failureReason?: string;
91
+ }[];
67
92
  readonly children: readonly {
68
93
  readonly workItemKey: WorkItemKey;
69
94
  readonly parentWorkItemKey: WorkItemKey;
70
95
  readonly objective: string;
71
96
  readonly workflowName: string;
72
97
  readonly status: string;
98
+ readonly currentStage?: string;
73
99
  readonly cohortId: string;
100
+ readonly repository?: {
101
+ readonly resourceId: string;
102
+ readonly pullRequestBase: string;
103
+ };
104
+ readonly prerequisites?: readonly WorkItemKey[];
105
+ /** Set only while a prerequisite is actually holding this child back. */
106
+ readonly prerequisiteBlocker?: string;
107
+ /** Original required assignment this corrective child replaces. */
108
+ readonly replaces?: {
109
+ readonly cohortId: string;
110
+ readonly assignmentId: string;
111
+ };
112
+ readonly outputs?: readonly {
113
+ readonly name: string;
114
+ readonly kind: string;
115
+ readonly required: boolean;
116
+ readonly selected: boolean;
117
+ readonly stale: boolean;
118
+ /** Declared per-output repository and PR base, when it differs from the child's. */
119
+ readonly repository?: {
120
+ readonly resourceId: string;
121
+ readonly pullRequestBase: string;
122
+ };
123
+ }[];
74
124
  readonly blockReason?: string;
75
125
  readonly resources: readonly ResourceItemResponse[];
76
126
  }[];