@atolis-hq/wake 0.4.105 → 0.4.107

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 (158) hide show
  1. package/dist/src/activities/agent/agent-activity.js +7 -0
  2. package/dist/src/activities/contracts/activity.d.ts +12 -0
  3. package/dist/src/activities/contracts/event-schema.d.ts +314 -8
  4. package/dist/src/activities/contracts/event-schema.js +20 -2
  5. package/dist/src/activities/contracts/events.d.ts +10 -0
  6. package/dist/src/activities/contracts/vocabulary.d.ts +2 -0
  7. package/dist/src/activities/contracts/vocabulary.js +2 -0
  8. package/dist/src/activities/index.d.ts +2 -0
  9. package/dist/src/activities/index.js +2 -0
  10. package/dist/src/activities/pr/activity-support.d.ts +1 -1
  11. package/dist/src/activities/pr/activity-support.js +10 -0
  12. package/dist/src/activities/pr/application.js +31 -10
  13. package/dist/src/activities/pr/approve.d.ts +2 -1
  14. package/dist/src/activities/pr/approve.js +33 -11
  15. package/dist/src/activities/pr/check-evidence.d.ts +10 -0
  16. package/dist/src/activities/pr/check-evidence.js +16 -0
  17. package/dist/src/activities/pr/contracts.d.ts +14 -0
  18. package/dist/src/activities/pr/event-data.js +5 -1
  19. package/dist/src/activities/pr/merge.d.ts +2 -1
  20. package/dist/src/activities/pr/merge.js +54 -38
  21. package/dist/src/activities/pr/parent-scope.d.ts +65 -0
  22. package/dist/src/activities/pr/parent-scope.js +24 -0
  23. package/dist/src/activities/pr/parent-target.d.ts +45 -0
  24. package/dist/src/activities/pr/parent-target.js +59 -0
  25. package/dist/src/activities/pr/projection.js +10 -2
  26. package/dist/src/activities/pr/vocabulary.d.ts +8 -0
  27. package/dist/src/activities/pr/vocabulary.js +8 -0
  28. package/dist/src/bootstrap/activity-registry.d.ts +2 -2
  29. package/dist/src/bootstrap/activity-registry.js +3 -3
  30. package/dist/src/bootstrap/composition-root.js +12 -3
  31. package/dist/src/bootstrap/config/root-schema.d.ts +6 -0
  32. package/dist/src/bootstrap/delivery-integration.d.ts +9 -0
  33. package/dist/src/bootstrap/delivery-integration.js +46 -0
  34. package/dist/src/bootstrap/surface-api-delivery.js +27 -0
  35. package/dist/src/bootstrap/version.js +1 -1
  36. package/dist/src/control-plane/application/activation-scheduler-ports.d.ts +3 -1
  37. package/dist/src/control-plane/application/advance-once-dispatch.js +10 -6
  38. package/dist/src/conversations/application/conversation-repository.d.ts +1 -1
  39. package/dist/src/conversations/application/conversation-repository.js +3 -1
  40. package/dist/src/execution/application/execution-service.js +10 -0
  41. package/dist/src/execution/application/maintenance-workspaces.d.ts +17 -0
  42. package/dist/src/execution/application/maintenance-workspaces.js +84 -0
  43. package/dist/src/execution/application/run-lifecycle.js +1 -0
  44. package/dist/src/execution/application/run-repository.js +27 -10
  45. package/dist/src/execution/contracts/commands.d.ts +2 -0
  46. package/dist/src/execution/contracts/events.d.ts +13 -0
  47. package/dist/src/execution/contracts/events.js +2 -0
  48. package/dist/src/execution/contracts/maintenance.d.ts +36 -0
  49. package/dist/src/execution/contracts/maintenance.js +44 -0
  50. package/dist/src/execution/contracts/views.d.ts +2 -0
  51. package/dist/src/execution/contracts/workspace.d.ts +2 -0
  52. package/dist/src/execution/index.d.ts +1 -0
  53. package/dist/src/execution/index.js +1 -0
  54. package/dist/src/integrations/application/artifact-registration-reactor.js +7 -14
  55. package/dist/src/integrations/application/delegation-outputs.js +1 -1
  56. package/dist/src/integrations/application/delivery-integration-verification.d.ts +13 -0
  57. package/dist/src/integrations/application/delivery-integration-verification.js +68 -0
  58. package/dist/src/integrations/application/latest-unresolved-artifacts.d.ts +3 -0
  59. package/dist/src/integrations/application/latest-unresolved-artifacts.js +16 -0
  60. package/dist/src/integrations/delivery/application/delivery-projector.js +3 -0
  61. package/dist/src/integrations/delivery/application/merged-delivery-evidence.js +9 -1
  62. package/dist/src/integrations/delivery/contracts/views.d.ts +2 -0
  63. package/dist/src/integrations/fake/external-source.d.ts +5 -2
  64. package/dist/src/integrations/fake/external-source.js +12 -2
  65. package/dist/src/integrations/fake/inbound-translator.js +7 -2
  66. package/dist/src/integrations/fake/provider.d.ts +17 -0
  67. package/dist/src/integrations/fake/provider.js +18 -2
  68. package/dist/src/integrations/github/application/comment-history-reader.d.ts +1 -1
  69. package/dist/src/integrations/github/application/comment-history-reader.js +56 -39
  70. package/dist/src/integrations/github/application/pull-request-translation.js +2 -0
  71. package/dist/src/integrations/github/contracts/events.d.ts +3 -1
  72. package/dist/src/integrations/github/contracts/events.js +3 -1
  73. package/dist/src/integrations/github/contracts/payloads.d.ts +23 -0
  74. package/dist/src/integrations/github/infrastructure/check-execution.d.ts +9 -0
  75. package/dist/src/integrations/github/infrastructure/check-execution.js +68 -0
  76. package/dist/src/integrations/github/infrastructure/checkout-revision.d.ts +2 -0
  77. package/dist/src/integrations/github/infrastructure/checkout-revision.js +23 -0
  78. package/dist/src/integrations/github/infrastructure/client.d.ts +2 -0
  79. package/dist/src/integrations/github/infrastructure/client.js +4 -0
  80. package/dist/src/integrations/github/infrastructure/pr-check-subject.d.ts +7 -0
  81. package/dist/src/integrations/github/infrastructure/pr-check-subject.js +77 -0
  82. package/dist/src/integrations/github/infrastructure/pr-evidence.d.ts +6 -3
  83. package/dist/src/integrations/github/infrastructure/pr-evidence.js +1 -1
  84. package/dist/src/integrations/github/infrastructure/pr-source.d.ts +3 -5
  85. package/dist/src/integrations/github/infrastructure/pr-source.js +11 -1
  86. package/dist/src/integrations/github/infrastructure/workflow-run-evidence.d.ts +5 -0
  87. package/dist/src/integrations/github/infrastructure/workflow-run-evidence.js +22 -0
  88. package/dist/src/integrations/index.d.ts +1 -0
  89. package/dist/src/integrations/index.js +1 -0
  90. package/dist/src/node_modules/@atolis-hq/eventing/dist/index.d.ts +1 -1
  91. package/dist/src/node_modules/@atolis-hq/eventing/dist/index.d.ts.map +1 -1
  92. package/dist/src/node_modules/@atolis-hq/eventing/dist/index.js +1 -1
  93. package/dist/src/node_modules/@atolis-hq/eventing/dist/projections/projection-processor.d.ts +14 -0
  94. package/dist/src/node_modules/@atolis-hq/eventing/dist/projections/projection-processor.d.ts.map +1 -1
  95. package/dist/src/node_modules/@atolis-hq/eventing/dist/projections/projection-processor.js +31 -1
  96. package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/journal-view.d.ts +22 -0
  97. package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/journal-view.d.ts.map +1 -0
  98. package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/journal-view.js +60 -0
  99. package/dist/src/node_modules/@atolis-hq/eventing-filesystem/dist/file-event-journal.d.ts +2 -0
  100. package/dist/src/node_modules/@atolis-hq/eventing-filesystem/dist/file-event-journal.d.ts.map +1 -1
  101. package/dist/src/node_modules/@atolis-hq/eventing-filesystem/dist/file-event-journal.js +82 -15
  102. package/dist/src/orchestration/application/advance-workflow.js +7 -2
  103. package/dist/src/orchestration/application/deferred-signals.js +2 -6
  104. package/dist/src/orchestration/application/delegation-commands.d.ts +3 -0
  105. package/dist/src/orchestration/application/delivery-coordinator.d.ts +70 -1
  106. package/dist/src/orchestration/application/delivery-coordinator.js +31 -5
  107. package/dist/src/orchestration/application/delivery-facts-reader.js +1 -0
  108. package/dist/src/orchestration/application/delivery-integration-reader.d.ts +9 -0
  109. package/dist/src/orchestration/application/delivery-integration-reader.js +23 -0
  110. package/dist/src/orchestration/application/delivery-integration-service.d.ts +50 -0
  111. package/dist/src/orchestration/application/delivery-integration-service.js +228 -0
  112. package/dist/src/orchestration/application/delivery-preparation.d.ts +1 -0
  113. package/dist/src/orchestration/application/delivery-preparation.js +7 -2
  114. package/dist/src/orchestration/application/orchestration-repository.d.ts +14 -9
  115. package/dist/src/orchestration/application/orchestration-repository.js +139 -64
  116. package/dist/src/orchestration/application/orchestration-service.d.ts +74 -3
  117. package/dist/src/orchestration/application/orchestration-service.js +55 -2
  118. package/dist/src/orchestration/contracts/config.d.ts +6 -0
  119. package/dist/src/orchestration/contracts/config.js +6 -0
  120. package/dist/src/orchestration/contracts/delivery-ports.d.ts +44 -0
  121. package/dist/src/orchestration/contracts/delivery.d.ts +58 -0
  122. package/dist/src/orchestration/contracts/delivery.js +53 -1
  123. package/dist/src/orchestration/contracts/event-decoder.js +2 -1
  124. package/dist/src/orchestration/contracts/event-factory.js +2 -0
  125. package/dist/src/orchestration/contracts/events.d.ts +3 -1
  126. package/dist/src/orchestration/contracts/events.js +1 -0
  127. package/dist/src/orchestration/contracts/vocabulary.d.ts +44 -1
  128. package/dist/src/orchestration/contracts/vocabulary.js +40 -1
  129. package/dist/src/orchestration/domain/compile-diagnostics.d.ts +1 -1
  130. package/dist/src/orchestration/domain/compile-diagnostics.js +5 -0
  131. package/dist/src/orchestration/domain/delivery-candidate.js +13 -0
  132. package/dist/src/orchestration/domain/delivery-facts.d.ts +7 -1
  133. package/dist/src/orchestration/domain/delivery-facts.js +33 -1
  134. package/dist/src/orchestration/domain/delivery-integration-policy.d.ts +7 -0
  135. package/dist/src/orchestration/domain/delivery-integration-policy.js +15 -0
  136. package/dist/src/orchestration/domain/delivery-integration.d.ts +54 -0
  137. package/dist/src/orchestration/domain/delivery-integration.js +144 -0
  138. package/dist/src/orchestration/domain/delivery-qa.d.ts +2 -1
  139. package/dist/src/orchestration/domain/delivery-qa.js +24 -4
  140. package/dist/src/orchestration/domain/delivery-workflow-policy.d.ts +3 -1
  141. package/dist/src/orchestration/domain/delivery-workflow-policy.js +19 -0
  142. package/dist/src/orchestration/domain/workflow-instance-events.js +1 -0
  143. package/dist/src/orchestration/index.d.ts +3 -2
  144. package/dist/src/orchestration/index.js +1 -1
  145. package/dist/src/resources/application/resource-lookup.d.ts +2 -1
  146. package/dist/src/resources/application/resource-lookup.js +3 -11
  147. package/dist/src/resources/application/resource-repository.js +10 -10
  148. package/dist/src/surfaces/api/contracts/transport-values.js +1 -0
  149. package/dist/src/surfaces/api/contracts/work.d.ts +26 -0
  150. package/dist/src/surfaces/api/presenters/execution.js +1 -0
  151. package/dist/src/surfaces/mcp/delegation.js +5 -1
  152. package/dist/src/surfaces/web-assets/assets/index-ih1h3dxC.js +1192 -0
  153. package/dist/src/surfaces/web-assets/index.html +1 -1
  154. package/package.json +1 -1
  155. package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/cached-journal-view.d.ts +0 -16
  156. package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/cached-journal-view.d.ts.map +0 -1
  157. package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/cached-journal-view.js +0 -79
  158. package/dist/src/surfaces/web-assets/assets/index-BfhxlN_h.js +0 -1192
@@ -0,0 +1,84 @@
1
+ import { BuiltInResourceKind } from '../../resources/index.js';
2
+ import { executionMaintenanceSchema } from '../contracts/maintenance.js';
3
+ import { RunStatus, WorkspaceMode } from '../contracts/vocabulary.js';
4
+ /**
5
+ * Leases the recorded branch workspace of every maintenance target as a unit, in a fixed order so
6
+ * concurrent parents cannot deadlock. An unresolved earlier writer of any target stops the whole
7
+ * preparation: it must be reconciled before another writer is allowed to act.
8
+ */
9
+ export async function acquireMaintenanceWorkspaces(request, provider) {
10
+ if (provider === undefined)
11
+ throw new Error('Maintenance needs a workspace provider');
12
+ const maintenance = executionMaintenanceSchema.parse(request.maintenance);
13
+ const targets = [...maintenance.targets].sort((a, b) => a.childWorkItemId < b.childWorkItemId ? -1 : a.childWorkItemId === b.childWorkItemId ? 0 : 1);
14
+ if (new Set(targets.map((entry) => entry.childWorkItemId)).size !== targets.length)
15
+ throw new Error('Duplicate maintenance target');
16
+ for (const target of targets) {
17
+ const unresolved = request.runs.find((run) => run.runId !== request.runId &&
18
+ run.status === RunStatus.Ambiguous &&
19
+ ((run.workspace?.branch === target.childWorkItemId &&
20
+ run.workspace?.mode === WorkspaceMode.Branch) ||
21
+ run.workspace?.maintenance?.targets.some((entry) => entry.childWorkItemId === target.childWorkItemId) === true));
22
+ if (unresolved !== undefined)
23
+ throw new Error(`Maintenance target ${target.childWorkItemId} has an unresolved earlier writer: Run ${unresolved.runId}`);
24
+ }
25
+ const leases = [];
26
+ try {
27
+ for (const target of targets) {
28
+ request.signal.throwIfAborted();
29
+ const resource = request.resources.find((entry) => entry.resourceId === target.repository.resourceId &&
30
+ entry.kind === BuiltInResourceKind.Repository);
31
+ if (resource === undefined)
32
+ throw new Error('Maintenance repository is unavailable');
33
+ const lease = await provider.acquire({
34
+ runId: request.runId,
35
+ workItemId: target.childWorkItemId,
36
+ signal: request.signal,
37
+ mode: WorkspaceMode.Branch,
38
+ repositoryResource: resource,
39
+ assignment: target.repository,
40
+ checkoutRevision: target.revision,
41
+ });
42
+ leases.push(lease);
43
+ }
44
+ return {
45
+ ...leases[0],
46
+ maintenance: {
47
+ targets: targets.map((target, index) => ({
48
+ childWorkItemId: target.childWorkItemId,
49
+ outputName: target.outputName,
50
+ resourceId: target.resourceId,
51
+ branch: target.branch,
52
+ revision: target.revision,
53
+ path: leases[index].path,
54
+ ...(target.reason === undefined ? {} : { reason: target.reason }),
55
+ })),
56
+ },
57
+ release: () => releaseAll(leases),
58
+ };
59
+ }
60
+ catch (error) {
61
+ try {
62
+ await releaseAll(leases);
63
+ }
64
+ catch (cleanup) {
65
+ throw new AggregateError([error, cleanup], 'Maintenance preparation and cleanup failed', {
66
+ cause: cleanup,
67
+ });
68
+ }
69
+ throw error;
70
+ }
71
+ }
72
+ async function releaseAll(leases) {
73
+ const failures = [];
74
+ for (const lease of [...leases].reverse()) {
75
+ try {
76
+ await lease.release();
77
+ }
78
+ catch (error) {
79
+ failures.push(error);
80
+ }
81
+ }
82
+ if (failures.length > 0)
83
+ throw new AggregateError(failures, 'Maintenance lease cleanup failed');
84
+ }
@@ -197,6 +197,7 @@ function workspacePayload(lease) {
197
197
  : { checkoutRevision: lease.checkoutRevision }),
198
198
  path: lease.path,
199
199
  ...(lease.candidate === undefined ? {} : { candidate: lease.candidate }),
200
+ ...(lease.maintenance === undefined ? {} : { maintenance: lease.maintenance }),
200
201
  ...(lease.branch === undefined ? {} : { branch: lease.branch }),
201
202
  },
202
203
  }),
@@ -1,18 +1,19 @@
1
- import { cachedJournalView } from '@atolis-hq/eventing';
1
+ import { decodeOnce, foldedJournalView, } from '@atolis-hq/eventing';
2
2
  import { decodeRunExecutionEvent, } from '../contracts/events.js';
3
3
  import { runId } from '../contracts/identifiers.js';
4
4
  import { isRunStream, runStream } from '../contracts/streams.js';
5
5
  import { foldRun } from '../domain/run.js';
6
+ const decodeRun = decodeOnce(decodeRunExecutionEvent);
6
7
  export class RunRepository {
7
8
  journal;
8
9
  runs;
9
10
  constructor(journal) {
10
11
  this.journal = journal;
11
- this.runs = cachedJournalView(journal, deriveRuns);
12
+ this.runs = foldedJournalView(journal, { initial: emptyRuns, extend: extendRuns });
12
13
  }
13
14
  async load(runId) {
14
15
  const events = await this.journal.readStream(runStream(runId));
15
- const decoded = events.map(decodeRunExecutionEvent);
16
+ const decoded = events.map(decodeRun);
16
17
  return { sequence: events.length, events: decoded, view: foldRun(decoded) };
17
18
  }
18
19
  async append(runId, sequence, drafts) {
@@ -20,21 +21,37 @@ export class RunRepository {
20
21
  return events.map(decodeRunExecutionEvent);
21
22
  }
22
23
  async list(activationId) {
23
- const runs = await this.runs.get();
24
+ const { views: runs } = await this.runs.get();
24
25
  return activationId === undefined
25
26
  ? runs
26
27
  : runs.filter((run) => run.activationId === activationId);
27
28
  }
28
29
  }
29
- function deriveRuns(events) {
30
- const grouped = new Map();
30
+ const emptyRuns = { events: new Map(), byRun: new Map(), views: [] };
31
+ // Decodes and folds only the runs the new events touch; untouched runs keep
32
+ // their decoded history and view, so a journal move costs the delta.
33
+ function extendRuns(state, events) {
34
+ const touched = new Map();
31
35
  for (const event of events) {
32
36
  if (!isRunStream(event.stream))
33
37
  continue;
34
38
  const id = runId(event.stream.id);
35
- const decoded = grouped.get(id) ?? [];
36
- decoded.push(decodeRunExecutionEvent(event));
37
- grouped.set(id, decoded);
39
+ const batch = touched.get(id) ?? [];
40
+ batch.push(decodeRun(event));
41
+ touched.set(id, batch);
38
42
  }
39
- return [...grouped.values()].map(foldRun).filter((run) => run !== null);
43
+ if (touched.size === 0)
44
+ return state;
45
+ const history = new Map(state.events);
46
+ const byRun = new Map(state.byRun);
47
+ for (const [id, batch] of touched) {
48
+ const all = [...(history.get(id) ?? []), ...batch];
49
+ history.set(id, all);
50
+ byRun.set(id, foldRun(all));
51
+ }
52
+ return {
53
+ events: history,
54
+ byRun,
55
+ views: [...byRun.values()].filter((run) => run !== null),
56
+ };
40
57
  }
@@ -2,6 +2,7 @@ import type { ActivationId, ActivityName, ActivityOrchestrationGroupId, Activity
2
2
  import type { ResourceView } from '../../resources/index.js';
3
3
  import type { WorkItemId } from '../../work/index.js';
4
4
  import type { ExecutionCandidate } from './candidate.js';
5
+ import type { ExecutionMaintenance } from './maintenance.js';
5
6
  import type { RepositoryAssignment } from './repository-assignment.js';
6
7
  import type { WorkspaceMode } from './vocabulary.js';
7
8
  export interface ExecutionActivation {
@@ -19,6 +20,7 @@ export interface ExecutionActivation {
19
20
  }
20
21
  export interface ExecutionAttemptContext {
21
22
  readonly candidate?: ExecutionCandidate;
23
+ readonly maintenance?: ExecutionMaintenance;
22
24
  readonly workItemId: WorkItemId;
23
25
  readonly workflowInstanceId: ActivityWorkflowInstanceId;
24
26
  readonly orchestrationGroupId: ActivityOrchestrationGroupId;
@@ -4,6 +4,7 @@ import { type ActivationId, type ActivityName, type ActivityOrchestrationGroupId
4
4
  import { type PreparedCandidate } from './candidate.js';
5
5
  import { runId } from './identifiers.js';
6
6
  import type { Cancellation, ExternalExecutionReference, Lease } from './liveness.js';
7
+ import { type PreparedMaintenance } from './maintenance.js';
7
8
  import { type RepositoryAssignment } from './repository-assignment.js';
8
9
  import type { ExecutionFailure, RecordedRunnerResult, RecoveredRunResult } from './results.js';
9
10
  import { type ActivationStreamRef, type RunStreamRef } from './streams.js';
@@ -47,6 +48,17 @@ export declare const runStartedPayloadSchema: z.ZodObject<{
47
48
  path: z.ZodString;
48
49
  }, z.core.$strict>>;
49
50
  }, z.core.$strict>>;
51
+ maintenance: z.ZodOptional<z.ZodObject<{
52
+ targets: z.ZodArray<z.ZodObject<{
53
+ childWorkItemId: z.ZodString;
54
+ outputName: z.ZodString;
55
+ resourceId: z.ZodString;
56
+ branch: z.ZodString;
57
+ revision: z.ZodString;
58
+ path: z.ZodString;
59
+ reason: z.ZodOptional<z.ZodString>;
60
+ }, z.core.$strict>>;
61
+ }, z.core.$strict>>;
50
62
  }, z.core.$strict>>;
51
63
  }, z.core.$strict>;
52
64
  export declare const runPreparationStartedPayloadSchema: z.ZodObject<{
@@ -148,6 +160,7 @@ export interface RunStartedPayload {
148
160
  readonly repositoryResourceId?: string | undefined;
149
161
  readonly checkoutRevision?: string | undefined;
150
162
  readonly candidate?: PreparedCandidate | undefined;
163
+ readonly maintenance?: PreparedMaintenance | undefined;
151
164
  } | undefined;
152
165
  }
153
166
  export interface RunPreparationStartedPayload {
@@ -4,6 +4,7 @@ import { activationId, activityName, activityOrchestrationGroupId, activityWorkf
4
4
  import { brandedStringSchema, offsetIsoTimestampSchema } from '../../kernel/index.js';
5
5
  import { preparedCandidateSchema } from './candidate.js';
6
6
  import { runId } from './identifiers.js';
7
+ import { preparedMaintenanceSchema } from './maintenance.js';
7
8
  import { repositoryAssignmentSchema } from './repository-assignment.js';
8
9
  import { ExecutionStreamKind } from './streams.js';
9
10
  import { ExecutionCancellationReason, ExecutionFailureCode, RunStatus, WorkspaceMode, } from './vocabulary.js';
@@ -35,6 +36,7 @@ export const runStartedPayloadSchema = z
35
36
  repositoryResourceId: z.string().min(1).optional(),
36
37
  checkoutRevision: z.string().min(1).optional(),
37
38
  candidate: preparedCandidateSchema.optional(),
39
+ maintenance: preparedMaintenanceSchema.optional(),
38
40
  })
39
41
  .strict()
40
42
  .optional(),
@@ -0,0 +1,36 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * Selected pull requests an agent may maintain, chosen by Orchestration for one activation.
4
+ * Each target is leased through the child's own recorded branch workspace; the PR keeps its
5
+ * original owner and the maintaining Run is recorded as the actual producer.
6
+ */
7
+ export declare const executionMaintenanceSchema: z.ZodObject<{
8
+ targets: z.ZodArray<z.ZodObject<{
9
+ childWorkItemId: z.ZodString;
10
+ outputName: z.ZodString;
11
+ resourceId: z.ZodString;
12
+ repository: z.ZodObject<{
13
+ resourceId: z.ZodString;
14
+ sourceRef: z.ZodString;
15
+ sourceRevision: z.ZodString;
16
+ pullRequestBase: z.ZodString;
17
+ }, z.core.$strict>;
18
+ branch: z.ZodString;
19
+ revision: z.ZodString;
20
+ pullRequestBase: z.ZodString;
21
+ reason: z.ZodOptional<z.ZodString>;
22
+ }, z.core.$strict>>;
23
+ }, z.core.$strict>;
24
+ export type ExecutionMaintenance = z.infer<typeof executionMaintenanceSchema>;
25
+ export declare const preparedMaintenanceSchema: z.ZodObject<{
26
+ targets: z.ZodArray<z.ZodObject<{
27
+ childWorkItemId: z.ZodString;
28
+ outputName: z.ZodString;
29
+ resourceId: z.ZodString;
30
+ branch: z.ZodString;
31
+ revision: z.ZodString;
32
+ path: z.ZodString;
33
+ reason: z.ZodOptional<z.ZodString>;
34
+ }, z.core.$strict>>;
35
+ }, z.core.$strict>;
36
+ export type PreparedMaintenance = z.infer<typeof preparedMaintenanceSchema>;
@@ -0,0 +1,44 @@
1
+ import { z } from 'zod';
2
+ import { repositoryAssignmentSchema } from './repository-assignment.js';
3
+ /**
4
+ * Selected pull requests an agent may maintain, chosen by Orchestration for one activation.
5
+ * Each target is leased through the child's own recorded branch workspace; the PR keeps its
6
+ * original owner and the maintaining Run is recorded as the actual producer.
7
+ */
8
+ export const executionMaintenanceSchema = z
9
+ .object({
10
+ targets: z
11
+ .array(z
12
+ .object({
13
+ childWorkItemId: z.string().min(1),
14
+ outputName: z.string().min(1),
15
+ resourceId: z.string().min(1),
16
+ /** The repository assignment the child's workspace was created from. */
17
+ repository: repositoryAssignmentSchema,
18
+ branch: z.string().min(1),
19
+ revision: z.string().min(1),
20
+ pullRequestBase: z.string().min(1),
21
+ /** Why integration cannot proceed yet, when it cannot. */
22
+ reason: z.string().min(1).optional(),
23
+ })
24
+ .strict())
25
+ .min(1),
26
+ })
27
+ .strict();
28
+ export const preparedMaintenanceSchema = z
29
+ .object({
30
+ targets: z
31
+ .array(z
32
+ .object({
33
+ childWorkItemId: z.string().min(1),
34
+ outputName: z.string().min(1),
35
+ resourceId: z.string().min(1),
36
+ branch: z.string().min(1),
37
+ revision: z.string().min(1),
38
+ path: z.string().min(1),
39
+ reason: z.string().min(1).optional(),
40
+ })
41
+ .strict())
42
+ .min(1),
43
+ })
44
+ .strict();
@@ -2,6 +2,7 @@ import type { ActivationId, ActivityName, ActivityOrchestrationGroupId, Activity
2
2
  import type { PreparedCandidate } from './candidate.js';
3
3
  import type { RunId } from './identifiers.js';
4
4
  import type { Cancellation, ExternalExecutionReference, Lease } from './liveness.js';
5
+ import type { PreparedMaintenance } from './maintenance.js';
5
6
  import type { RepositoryAssignment } from './repository-assignment.js';
6
7
  import type { ExecutionFailure } from './results.js';
7
8
  import type { AgentRunResponse } from './runner.js';
@@ -45,6 +46,7 @@ export interface RunView {
45
46
  readonly repositoryResourceId?: string | undefined;
46
47
  readonly checkoutRevision?: string | undefined;
47
48
  readonly candidate?: PreparedCandidate | undefined;
49
+ readonly maintenance?: PreparedMaintenance | undefined;
48
50
  };
49
51
  readonly lease?: Lease;
50
52
  readonly externalExecution?: ExternalExecutionReference;
@@ -2,6 +2,7 @@ import type { ResourceView } from '../../resources/index.js';
2
2
  import type { WorkItemId } from '../../work/index.js';
3
3
  import type { PreparedCandidate } from './candidate.js';
4
4
  import type { RunId } from './identifiers.js';
5
+ import type { PreparedMaintenance } from './maintenance.js';
5
6
  import type { RepositoryAssignment } from './repository-assignment.js';
6
7
  import type { RunView } from './views.js';
7
8
  import type { WorkspaceMode } from './vocabulary.js';
@@ -18,6 +19,7 @@ export interface WorkspaceRequest {
18
19
  }
19
20
  export interface WorkspaceLease {
20
21
  readonly candidate?: PreparedCandidate;
22
+ readonly maintenance?: PreparedMaintenance;
21
23
  readonly workspaceId: string;
22
24
  readonly path: string;
23
25
  /** Branch actually checked out for this lease, when the provider can attest it. */
@@ -38,3 +38,4 @@ export { resolveGitSource } from './infrastructure/workspace/git-source.js';
38
38
  export * from './contracts/repository-assignment.js';
39
39
  export { createRepositoryAssignments } from './application/repository-assignments.js';
40
40
  export * from './contracts/candidate.js';
41
+ export * from './contracts/maintenance.js';
@@ -38,3 +38,4 @@ export { resolveGitSource } from './infrastructure/workspace/git-source.js';
38
38
  export * from './contracts/repository-assignment.js';
39
39
  export { createRepositoryAssignments } from './application/repository-assignments.js';
40
40
  export * from './contracts/candidate.js';
41
+ export * from './contracts/maintenance.js';
@@ -1,18 +1,22 @@
1
- import { cachedJournalView, defineEventProcessor, EventActorKind, EventProcessorCategory, EventProcessorReplayPolicy, EventSourceKind, } from '@atolis-hq/eventing';
1
+ import { defineEventProcessor, EventActorKind, EventProcessorCategory, EventProcessorReplayPolicy, EventSourceKind, foldedJournalView, } from '@atolis-hq/eventing';
2
2
  import { reportedArtifactSchema } from '../../activities/index.js';
3
3
  import { OrchestrationEventType, selectWorkflowOrchestrationEvent, workflowInstanceStream, } from '../../orchestration/index.js';
4
4
  import { ResourceCorrelationProvenance, ResourceCorrelationRole, resourceId, resourceKind, ResourceStreamKind, } from '../../resources/index.js';
5
5
  import { createArtifactEventData } from '../contracts/artifact-event-factory.js';
6
- import { ArtifactEventType, decodeArtifactEvent, } from '../contracts/artifact-events.js';
6
+ import { ArtifactEventType } from '../contracts/artifact-events.js';
7
7
  import { ArtifactVerificationResult, ArtifactVerificationStatus, } from '../contracts/artifact-vocabulary.js';
8
8
  import { integrationStream } from '../contracts/streams.js';
9
+ import { extendLatestUnresolved } from './latest-unresolved-artifacts.js';
9
10
  export class ArtifactRegistrationReactor {
10
11
  dependencies;
11
12
  latestUnresolved;
12
13
  processor;
13
14
  constructor(dependencies) {
14
15
  this.dependencies = dependencies;
15
- this.latestUnresolved = cachedJournalView(dependencies.journal, deriveLatestUnresolved);
16
+ this.latestUnresolved = foldedJournalView(dependencies.journal, {
17
+ initial: new Map(),
18
+ extend: extendLatestUnresolved,
19
+ });
16
20
  this.processor = defineEventProcessor({
17
21
  consumer: 'reactor:artifact-registration',
18
22
  name: 'artifact-registration',
@@ -164,17 +168,6 @@ export class ArtifactRegistrationReactor {
164
168
  : null;
165
169
  }
166
170
  }
167
- function deriveLatestUnresolved(events) {
168
- const latest = new Map();
169
- for (const event of events) {
170
- if (event.event.eventType !== ArtifactEventType.VerificationUnresolved)
171
- continue;
172
- const decoded = decodeArtifactEvent(event);
173
- const key = `${decoded.event.causationId}:${decoded.event.payload.artifact.externalKey.adapter}:${decoded.event.payload.artifact.externalKey.key}`;
174
- latest.set(key, decoded);
175
- }
176
- return latest;
177
- }
178
171
  function reportedArtifacts(value) {
179
172
  if (typeof value !== 'object' || value === null || !('reportedArtifacts' in value))
180
173
  return [];
@@ -101,7 +101,7 @@ async function qualifyingChange(input, child, output, condition) {
101
101
  branch,
102
102
  pullRequestBase: assignment.pullRequestBase,
103
103
  runId: run.runId,
104
- ...(condition === undefined ? {} : { baseRevision: observed.baseRevision }),
104
+ baseRevision: observed.baseRevision,
105
105
  ...(observed.state === PullRequestState.Merged ? { merged: true } : {}),
106
106
  },
107
107
  };
@@ -0,0 +1,13 @@
1
+ import { type PullRequestService } from '../../activities/index.js';
2
+ import type { RunView } from '../../execution/index.js';
3
+ import type { DeliveryIntegration } from '../../orchestration/index.js';
4
+ import { type ResourceService } from '../../resources/index.js';
5
+ import type { ProviderInstance } from '../contracts/provider.js';
6
+ export type DeliveryIntegrationVerification = Pick<DeliveryIntegration, 'verifyTarget'>;
7
+ /** Reuses provider artifact verification and the target's own current review/check authority. */
8
+ export declare function createDeliveryIntegrationVerification(input: {
9
+ readonly resources: ResourceService;
10
+ readonly pullRequests: PullRequestService;
11
+ readonly runs: () => Promise<readonly RunView[]>;
12
+ readonly providers: () => Promise<readonly ProviderInstance[]>;
13
+ }): DeliveryIntegrationVerification;
@@ -0,0 +1,68 @@
1
+ import { ActivityEventType, decidePullRequestOutputAuthority, } from '../../activities/index.js';
2
+ import { BuiltInResourceKind, resourceId } from '../../resources/index.js';
3
+ /** Reuses provider artifact verification and the target's own current review/check authority. */
4
+ export function createDeliveryIntegrationVerification(input) {
5
+ return {
6
+ async verifyTarget(request) {
7
+ const resource = await input.resources.get(resourceId(request.resourceId));
8
+ const repository = await input.resources.get(resourceId(request.repositoryResourceId));
9
+ const owner = await input.resources.primaryCorrelation(resourceId(request.resourceId));
10
+ if (resource === null || repository === null || owner?.workItemId !== request.ownerWorkItemId)
11
+ return false;
12
+ const provider = (await input.providers()).find((entry) => entry.adapter === resource.externalKey.adapter);
13
+ if (provider === undefined)
14
+ return false;
15
+ const verified = await provider.verifyArtifact(BuiltInResourceKind.PullRequest, resource.externalKey, {
16
+ repository: repository.externalKey,
17
+ workspaceBranch: request.branch,
18
+ workspaceRevision: request.revision,
19
+ pullRequestBase: request.pullRequestBase,
20
+ });
21
+ if (!matchesVerifiedTarget(verified, resource.externalKey, request.revision))
22
+ return false;
23
+ if (!(await freshEvidence(request, input, resource.resourceId)))
24
+ return false;
25
+ const decision = decidePullRequestOutputAuthority(await input.pullRequests.authorityInput(owner.workItemId), {
26
+ target: { resourceId: resource.resourceId },
27
+ requireAcceptedReview: request.requireReview,
28
+ requireChecks: request.requireChecks,
29
+ });
30
+ return decision.allowed && decision.revision.toLowerCase() === request.revision.toLowerCase();
31
+ },
32
+ };
33
+ }
34
+ async function freshEvidence(request, input, id) {
35
+ if (request.maintenanceRunId === undefined)
36
+ return true;
37
+ const run = (await input.runs()).find((entry) => entry.runId === request.maintenanceRunId);
38
+ if (run === undefined)
39
+ return false;
40
+ if (!(await freshChecks(request, input.pullRequests, id, run)))
41
+ return false;
42
+ if (!request.requireReview)
43
+ return true;
44
+ return (await input.pullRequests.factsFor(id)).some(({ event }) => event.eventType === ActivityEventType.ReviewAcceptanceSignalRecorded &&
45
+ event.payload.trusted &&
46
+ event.payload.revision.toLowerCase() === request.revision.toLowerCase() &&
47
+ event.occurredAt >= (run.executionStartedAt ?? run.startedAt));
48
+ }
49
+ function matchesVerifiedTarget(verified, key, revision) {
50
+ return (typeof verified !== 'string' &&
51
+ verified.kind === BuiltInResourceKind.PullRequest &&
52
+ verified.externalKey.adapter === key.adapter &&
53
+ verified.externalKey.key === key.key &&
54
+ verified.revision?.toLowerCase() === revision.toLowerCase());
55
+ }
56
+ async function freshChecks(request, pullRequests, id, run) {
57
+ if (!request.requireChecks)
58
+ return true;
59
+ const view = await pullRequests.get(id);
60
+ const evidence = view?.checkEvidence;
61
+ if (evidence?.testedRevision === undefined || request.baseRevision === undefined)
62
+ return false;
63
+ return (evidence.headRevision.toLowerCase() === request.revision.toLowerCase() &&
64
+ evidence.baseRevision.toLowerCase() === request.baseRevision.toLowerCase() &&
65
+ evidence.baseRevision.toLowerCase() === view.baseRevision.toLowerCase() &&
66
+ Date.parse(evidence.startedAt) >=
67
+ Math.max(Date.parse(request.maintenanceRecordedAt ?? run.finishedAt ?? ''), Date.parse(run.executionStartedAt ?? run.startedAt)));
68
+ }
@@ -0,0 +1,3 @@
1
+ import type { EventEnvelope } from '@atolis-hq/eventing';
2
+ import { type ArtifactEvent } from '../contracts/artifact-events.js';
3
+ export declare function extendLatestUnresolved(previous: ReadonlyMap<string, ArtifactEvent>, events: readonly EventEnvelope[]): ReadonlyMap<string, ArtifactEvent>;
@@ -0,0 +1,16 @@
1
+ import { ArtifactEventType, decodeArtifactEvent, } from '../contracts/artifact-events.js';
2
+ // Folds only the new events; the previous map is returned untouched when none
3
+ // of them record an unresolved verification.
4
+ export function extendLatestUnresolved(previous, events) {
5
+ if (!events.some((event) => event.event.eventType === ArtifactEventType.VerificationUnresolved))
6
+ return previous;
7
+ const latest = new Map(previous);
8
+ for (const event of events) {
9
+ if (event.event.eventType !== ArtifactEventType.VerificationUnresolved)
10
+ continue;
11
+ const decoded = decodeArtifactEvent(event);
12
+ const key = `${decoded.event.causationId}:${decoded.event.payload.artifact.externalKey.adapter}:${decoded.event.payload.artifact.externalKey.key}`;
13
+ latest.set(key, decoded);
14
+ }
15
+ return latest;
16
+ }
@@ -105,6 +105,9 @@ function activityIntentView(event) {
105
105
  revision: intent.event.payload.revision,
106
106
  method: intent.event.payload.method,
107
107
  autoMerge: intent.event.payload.autoMerge,
108
+ ...(intent.event.payload.parent === undefined
109
+ ? {}
110
+ : { ownerWorkItemId: intent.event.payload.parent.ownerWorkItemId }),
108
111
  },
109
112
  state: DeliveryState.Pending,
110
113
  attempts: 0,
@@ -1,6 +1,7 @@
1
1
  import { EventActorKind, EventSourceKind, } from '@atolis-hq/eventing';
2
2
  import { ActivityEventType, PullRequestState, selectPrimaryPullRequest, } from '../../../activities/index.js';
3
3
  import { ActivityActivationStatus, workflowInstanceId, } from '../../../orchestration/index.js';
4
+ import { workItemId } from '../../../work/index.js';
4
5
  import { deliveryStream, IntegrationStreamKind } from '../../contracts/streams.js';
5
6
  import { createDeliveryEventData } from '../contracts/event-factory.js';
6
7
  import { DeliveryEventType, selectDeliveryEvent } from '../contracts/events.js';
@@ -10,6 +11,12 @@ export async function reconcileMergedDeliveries(input) {
10
11
  await confirmMergedDelivery(entry.value, input.journal, input.orchestration, input.pullRequests);
11
12
  }
12
13
  }
14
+ /** A parent delivery merges a pull request its child owns; the requester never becomes owner. */
15
+ function owningWorkItem(payload, requester) {
16
+ return 'ownerWorkItemId' in payload && payload.ownerWorkItemId !== undefined
17
+ ? workItemId(payload.ownerWorkItemId)
18
+ : requester;
19
+ }
13
20
  /** Reconcile durable merged evidence only after the exact intent's wait exists. */
14
21
  export async function confirmMergedDelivery(intent, journal, orchestration, pullRequests) {
15
22
  if (intent.payload.kind !== DeliveryIntentKind.PrMerge ||
@@ -19,7 +26,8 @@ export async function confirmMergedDelivery(intent, journal, orchestration, pull
19
26
  const instance = await orchestration.get(workflowInstanceId(intent.workflowInstanceId));
20
27
  if (!isMatchingWait(instance, intent))
21
28
  return;
22
- const selected = selectPrimaryPullRequest(await pullRequests.authorityInput(instance.workItemId), instance.workItemId);
29
+ const owner = owningWorkItem(intent.payload, instance.workItemId);
30
+ const selected = selectPrimaryPullRequest(await pullRequests.authorityInput(owner), owner);
23
31
  if (selected?.pullRequest.resourceId !== intent.resourceId ||
24
32
  selected.pullRequest.state !== PullRequestState.Merged ||
25
33
  selected.pullRequest.headRevision !== intent.payload.revision)
@@ -20,6 +20,8 @@ export interface DeliveryIntentView {
20
20
  readonly revision: string;
21
21
  readonly method: MergeMethod;
22
22
  readonly autoMerge: boolean;
23
+ /** Set when a parent delivery merges a child-owned PR: the owner, not the requester. */
24
+ readonly ownerWorkItemId?: string;
23
25
  } | {
24
26
  readonly kind: typeof DeliveryIntentKind.IssueComplete;
25
27
  } | {
@@ -1,5 +1,5 @@
1
- import type { ReviewActorKind } from '../../activities/index.js';
2
- import { PullRequestCheckState } from '../../activities/index.js';
1
+ import type { PullRequestCheckEvidence, PullRequestMergeability, ReviewActorKind } from '../../activities/index.js';
2
+ import { PullRequestCheckState, PullRequestState } from '../../activities/index.js';
3
3
  import type { AdapterId } from '../contracts/identifiers.js';
4
4
  import type { ExternalEventSource, ProviderEventData } from '../contracts/intake.js';
5
5
  export declare const FakeEventType: {
@@ -13,7 +13,10 @@ export interface FakeWorkEvidence {
13
13
  readonly kind?: 'issue' | 'pull-request' | undefined;
14
14
  readonly revision?: string | undefined;
15
15
  readonly baseBranch?: string | undefined;
16
+ readonly checkEvidence?: PullRequestCheckEvidence | undefined;
16
17
  readonly baseRevision?: string | undefined;
18
+ readonly state?: PullRequestState | undefined;
19
+ readonly mergeability?: PullRequestMergeability | undefined;
17
20
  readonly checks?: typeof PullRequestCheckState.Unknown | typeof PullRequestCheckState.Pending | typeof PullRequestCheckState.Passing | typeof PullRequestCheckState.Failing | undefined;
18
21
  readonly acceptedReview?: boolean | undefined;
19
22
  readonly reviewActorId?: string | undefined;
@@ -1,10 +1,20 @@
1
1
  import { causationId, correlationId, EventActorKind, eventId, EventSourceKind, } from '@atolis-hq/eventing';
2
- import { PullRequestCheckState } from '../../activities/index.js';
2
+ import { PullRequestCheckState, PullRequestState } from '../../activities/index.js';
3
3
  export const FakeEventType = {
4
4
  WorkObserved: 'fake.work-observed',
5
5
  ReviewRequested: 'fake.review-requested',
6
6
  };
7
7
  const missingIdentityPart = '_';
8
+ // New provider facts about an unchanged head (merged, moved base) must not collapse into the old event.
9
+ function observationIdentity(payload) {
10
+ const parts = [
11
+ payload.state === undefined || payload.state === PullRequestState.Open ? '' : payload.state,
12
+ payload.baseRevision ?? '',
13
+ payload.checkEvidence?.startedAt ?? '',
14
+ payload.mergeability ?? '',
15
+ ];
16
+ return parts.every((part) => part === '') ? '' : `:${parts.join(':')}`;
17
+ }
8
18
  export class FakeExternalEventSource {
9
19
  adapter;
10
20
  events;
@@ -15,7 +25,7 @@ export class FakeExternalEventSource {
15
25
  async poll(signal) {
16
26
  void signal;
17
27
  return this.events.flatMap((payload, ordinal) => {
18
- const identity = `fake:${this.adapter}:${payload.key}:${payload.revision ?? missingIdentityPart}:${payload.checks ?? PullRequestCheckState.Unknown}:${payload.watchEvent ?? missingIdentityPart}:${ordinal}`;
28
+ const identity = `fake:${this.adapter}:${payload.key}:${payload.revision ?? missingIdentityPart}:${payload.checks ?? PullRequestCheckState.Unknown}:${payload.watchEvent ?? missingIdentityPart}:${ordinal}${observationIdentity(payload)}`;
19
29
  const metadata = {
20
30
  schemaVersion: 1,
21
31
  occurredAt: '2026-08-01T00:00:00.000Z',