@atolis-hq/wake 0.4.106 → 0.4.108

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 (95) hide show
  1. package/dist/src/activities/agent/agent-activity.js +4 -0
  2. package/dist/src/activities/agent/agent-result.js +1 -0
  3. package/dist/src/activities/contracts/activity.d.ts +6 -0
  4. package/dist/src/activities/pr/application.js +23 -9
  5. package/dist/src/activities/pr/approve.js +1 -1
  6. package/dist/src/activities/pr/merge.js +1 -1
  7. package/dist/src/activities/pr/parent-scope.d.ts +8 -2
  8. package/dist/src/activities/pr/parent-scope.js +7 -1
  9. package/dist/src/activities/pr/parent-target.d.ts +2 -2
  10. package/dist/src/activities/pr/parent-target.js +1 -0
  11. package/dist/src/bootstrap/composition-root.js +1 -1
  12. package/dist/src/bootstrap/config/root-schema.d.ts +14 -0
  13. package/dist/src/bootstrap/delivery-integration.js +7 -4
  14. package/dist/src/bootstrap/version.js +1 -1
  15. package/dist/src/control-plane/application/activation-scheduler-ports.d.ts +10 -0
  16. package/dist/src/control-plane/application/advance-once-dispatch.js +3 -5
  17. package/dist/src/control-plane/application/dispatch-resources.d.ts +10 -0
  18. package/dist/src/control-plane/application/dispatch-resources.js +9 -0
  19. package/dist/src/conversations/application/conversation-repository.d.ts +1 -1
  20. package/dist/src/conversations/application/conversation-repository.js +3 -1
  21. package/dist/src/execution/application/change-output-workspaces.d.ts +20 -0
  22. package/dist/src/execution/application/change-output-workspaces.js +123 -0
  23. package/dist/src/execution/application/execution-service.js +15 -2
  24. package/dist/src/execution/application/maintenance-workspaces.js +20 -12
  25. package/dist/src/execution/application/run-lifecycle.d.ts +2 -0
  26. package/dist/src/execution/application/run-lifecycle.js +2 -0
  27. package/dist/src/execution/application/run-repository.js +27 -10
  28. package/dist/src/execution/contracts/change-output.d.ts +15 -0
  29. package/dist/src/execution/contracts/change-output.js +12 -0
  30. package/dist/src/execution/contracts/commands.d.ts +5 -0
  31. package/dist/src/execution/contracts/events.d.ts +16 -0
  32. package/dist/src/execution/contracts/events.js +4 -0
  33. package/dist/src/execution/contracts/runner.d.ts +1 -0
  34. package/dist/src/execution/contracts/views.d.ts +3 -0
  35. package/dist/src/execution/contracts/workspace.d.ts +4 -0
  36. package/dist/src/execution/domain/run.js +3 -0
  37. package/dist/src/execution/index.d.ts +1 -0
  38. package/dist/src/execution/index.js +1 -0
  39. package/dist/src/execution/infrastructure/workspace/git-workspace.js +14 -3
  40. package/dist/src/integrations/application/artifact-registration-reactor.d.ts +2 -11
  41. package/dist/src/integrations/application/artifact-registration-reactor.js +16 -36
  42. package/dist/src/integrations/application/artifact-verification-source.d.ts +26 -0
  43. package/dist/src/integrations/application/artifact-verification-source.js +36 -0
  44. package/dist/src/integrations/application/delegation-outputs.js +56 -20
  45. package/dist/src/integrations/application/latest-unresolved-artifacts.d.ts +3 -0
  46. package/dist/src/integrations/application/latest-unresolved-artifacts.js +16 -0
  47. package/dist/src/integrations/contracts/artifact-events.d.ts +1 -0
  48. package/dist/src/integrations/contracts/artifact-events.js +1 -0
  49. package/dist/src/integrations/github/application/comment-history-reader.d.ts +1 -1
  50. package/dist/src/integrations/github/application/comment-history-reader.js +56 -39
  51. package/dist/src/node_modules/@atolis-hq/eventing/dist/index.d.ts +1 -1
  52. package/dist/src/node_modules/@atolis-hq/eventing/dist/index.d.ts.map +1 -1
  53. package/dist/src/node_modules/@atolis-hq/eventing/dist/index.js +1 -1
  54. package/dist/src/node_modules/@atolis-hq/eventing/dist/projections/projection-processor.d.ts +14 -0
  55. package/dist/src/node_modules/@atolis-hq/eventing/dist/projections/projection-processor.d.ts.map +1 -1
  56. package/dist/src/node_modules/@atolis-hq/eventing/dist/projections/projection-processor.js +31 -1
  57. package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/journal-view.d.ts +22 -0
  58. package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/journal-view.d.ts.map +1 -0
  59. package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/journal-view.js +60 -0
  60. package/dist/src/node_modules/@atolis-hq/eventing-filesystem/dist/file-event-journal.d.ts +2 -0
  61. package/dist/src/node_modules/@atolis-hq/eventing-filesystem/dist/file-event-journal.d.ts.map +1 -1
  62. package/dist/src/node_modules/@atolis-hq/eventing-filesystem/dist/file-event-journal.js +82 -15
  63. package/dist/src/orchestration/application/advance-workflow.js +7 -2
  64. package/dist/src/orchestration/application/deferred-signals.js +2 -6
  65. package/dist/src/orchestration/application/delegated-work.d.ts +18 -0
  66. package/dist/src/orchestration/application/delegated-work.js +30 -3
  67. package/dist/src/orchestration/application/delegation-commands.d.ts +16 -0
  68. package/dist/src/orchestration/application/delegation-reservation.js +33 -5
  69. package/dist/src/orchestration/application/delivery-integration-service.js +5 -18
  70. package/dist/src/orchestration/application/orchestration-repository.d.ts +14 -9
  71. package/dist/src/orchestration/application/orchestration-repository.js +139 -64
  72. package/dist/src/orchestration/application/orchestration-service.d.ts +34 -0
  73. package/dist/src/orchestration/application/orchestration-service.js +6 -1
  74. package/dist/src/orchestration/contracts/config.d.ts +15 -0
  75. package/dist/src/orchestration/contracts/config.js +8 -1
  76. package/dist/src/orchestration/contracts/delegation.d.ts +33 -9
  77. package/dist/src/orchestration/contracts/delegation.js +11 -5
  78. package/dist/src/orchestration/contracts/vocabulary.d.ts +2 -0
  79. package/dist/src/orchestration/contracts/vocabulary.js +2 -0
  80. package/dist/src/orchestration/domain/assignment-output-requirements.d.ts +5 -0
  81. package/dist/src/orchestration/domain/assignment-output-requirements.js +23 -0
  82. package/dist/src/orchestration/domain/compiler.js +1 -0
  83. package/dist/src/orchestration/domain/delivery-facts.d.ts +9 -1
  84. package/dist/src/orchestration/domain/delivery-facts.js +4 -2
  85. package/dist/src/orchestration/domain/delivery-integration-target.d.ts +8 -0
  86. package/dist/src/orchestration/domain/delivery-integration-target.js +37 -0
  87. package/dist/src/orchestration/domain/delivery-replacement.js +11 -6
  88. package/dist/src/orchestration/domain/delivery-selection.js +2 -1
  89. package/dist/src/resources/application/resource-lookup.d.ts +2 -1
  90. package/dist/src/resources/application/resource-lookup.js +3 -11
  91. package/dist/src/resources/application/resource-repository.js +10 -10
  92. package/package.json +1 -1
  93. package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/cached-journal-view.d.ts +0 -16
  94. package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/cached-journal-view.d.ts.map +0 -1
  95. package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/cached-journal-view.js +0 -79
@@ -122,6 +122,7 @@ export async function recordRunSuccess(input) {
122
122
  payload: {
123
123
  outcome,
124
124
  finishedAt,
125
+ ...(input.changeOutputs === undefined ? {} : { changeOutputs: input.changeOutputs }),
125
126
  ...(input.workspaceRevision === undefined
126
127
  ? {}
127
128
  : { workspaceRevision: input.workspaceRevision }),
@@ -196,6 +197,7 @@ function workspacePayload(lease) {
196
197
  ? {}
197
198
  : { checkoutRevision: lease.checkoutRevision }),
198
199
  path: lease.path,
200
+ ...(lease.changeOutputs === undefined ? {} : { changeOutputs: lease.changeOutputs }),
199
201
  ...(lease.candidate === undefined ? {} : { candidate: lease.candidate }),
200
202
  ...(lease.maintenance === undefined ? {} : { maintenance: lease.maintenance }),
201
203
  ...(lease.branch === undefined ? {} : { branch: lease.branch }),
@@ -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
  }
@@ -0,0 +1,15 @@
1
+ import { z } from 'zod';
2
+ /** Recorded by Execution from leased workspaces, never supplied by a PR claim. */
3
+ export declare const changeOutputWorkspaceSchema: z.ZodObject<{
4
+ name: z.ZodString;
5
+ path: z.ZodString;
6
+ branch: z.ZodString;
7
+ repository: z.ZodObject<{
8
+ resourceId: z.ZodString;
9
+ sourceRef: z.ZodString;
10
+ sourceRevision: z.ZodString;
11
+ pullRequestBase: z.ZodString;
12
+ }, z.core.$strict>;
13
+ revision: z.ZodString;
14
+ }, z.core.$strict>;
15
+ export type ChangeOutputWorkspace = z.infer<typeof changeOutputWorkspaceSchema>;
@@ -0,0 +1,12 @@
1
+ import { z } from 'zod';
2
+ import { repositoryAssignmentSchema } from './repository-assignment.js';
3
+ /** Recorded by Execution from leased workspaces, never supplied by a PR claim. */
4
+ export const changeOutputWorkspaceSchema = z
5
+ .object({
6
+ name: z.string().min(1),
7
+ path: z.string().min(1),
8
+ branch: z.string().min(1),
9
+ repository: repositoryAssignmentSchema,
10
+ revision: z.string().regex(/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/i),
11
+ })
12
+ .strict();
@@ -25,6 +25,11 @@ export interface ExecutionAttemptContext {
25
25
  readonly workflowInstanceId: ActivityWorkflowInstanceId;
26
26
  readonly orchestrationGroupId: ActivityOrchestrationGroupId;
27
27
  readonly resources: readonly ResourceView[];
28
+ readonly changeOutputAssignments?: readonly {
29
+ name: string;
30
+ repository: RepositoryAssignment;
31
+ isolated?: boolean;
32
+ }[];
28
33
  readonly repositoryAssignment?: RepositoryAssignment;
29
34
  readonly owner?: string;
30
35
  /** Runner names currently quota-paused; unset means none. */
@@ -2,6 +2,7 @@ import { type EventDataUnion, type EventEnvelope, type EventUnion } from '@atoli
2
2
  import { z } from 'zod';
3
3
  import { type ActivationId, type ActivityName, type ActivityOrchestrationGroupId, type ActivityOutcome, type ActivityWorkflowInstanceId } from '../../activities/index.js';
4
4
  import { type PreparedCandidate } from './candidate.js';
5
+ import { type ChangeOutputWorkspace } from './change-output.js';
5
6
  import { runId } from './identifiers.js';
6
7
  import type { Cancellation, ExternalExecutionReference, Lease } from './liveness.js';
7
8
  import { type PreparedMaintenance } from './maintenance.js';
@@ -59,6 +60,18 @@ export declare const runStartedPayloadSchema: z.ZodObject<{
59
60
  reason: z.ZodOptional<z.ZodString>;
60
61
  }, z.core.$strict>>;
61
62
  }, z.core.$strict>>;
63
+ changeOutputs: z.ZodOptional<z.ZodArray<z.ZodObject<{
64
+ name: z.ZodString;
65
+ path: z.ZodString;
66
+ branch: z.ZodString;
67
+ repository: z.ZodObject<{
68
+ resourceId: z.ZodString;
69
+ sourceRef: z.ZodString;
70
+ sourceRevision: z.ZodString;
71
+ pullRequestBase: z.ZodString;
72
+ }, z.core.$strict>;
73
+ revision: z.ZodString;
74
+ }, z.core.$strict>>>;
62
75
  }, z.core.$strict>>;
63
76
  }, z.core.$strict>;
64
77
  export declare const runPreparationStartedPayloadSchema: z.ZodObject<{
@@ -107,6 +120,7 @@ export declare const runnerResultPayloadSchema: z.ZodObject<{
107
120
  }>;
108
121
  displayBody: z.ZodString;
109
122
  artifacts: z.ZodOptional<z.ZodArray<z.ZodObject<{
123
+ name: z.ZodOptional<z.ZodString>;
110
124
  kind: z.ZodString;
111
125
  externalKey: z.ZodObject<{
112
126
  adapter: z.ZodString;
@@ -161,6 +175,7 @@ export interface RunStartedPayload {
161
175
  readonly checkoutRevision?: string | undefined;
162
176
  readonly candidate?: PreparedCandidate | undefined;
163
177
  readonly maintenance?: PreparedMaintenance | undefined;
178
+ readonly changeOutputs?: readonly ChangeOutputWorkspace[] | undefined;
164
179
  } | undefined;
165
180
  }
166
181
  export interface RunPreparationStartedPayload {
@@ -188,6 +203,7 @@ export interface RunExecutionEventPayloads {
188
203
  readonly [ExecutionEventType.RunPreparationStarted]: RunPreparationStartedPayload;
189
204
  readonly [ExecutionEventType.RunStarted]: RunStartedPayload;
190
205
  readonly [ExecutionEventType.RunSucceeded]: {
206
+ readonly changeOutputs?: readonly ChangeOutputWorkspace[] | undefined;
191
207
  readonly workspaceRevision?: string | undefined;
192
208
  readonly outcome: ActivityOutcome;
193
209
  readonly finishedAt: string;
@@ -3,6 +3,7 @@ import { z } from 'zod';
3
3
  import { activationId, activityName, activityOrchestrationGroupId, activityWorkflowInstanceId, ExternalExecutionKind, } from '../../activities/index.js';
4
4
  import { brandedStringSchema, offsetIsoTimestampSchema } from '../../kernel/index.js';
5
5
  import { preparedCandidateSchema } from './candidate.js';
6
+ import { changeOutputWorkspaceSchema } from './change-output.js';
6
7
  import { runId } from './identifiers.js';
7
8
  import { preparedMaintenanceSchema } from './maintenance.js';
8
9
  import { repositoryAssignmentSchema } from './repository-assignment.js';
@@ -37,6 +38,7 @@ export const runStartedPayloadSchema = z
37
38
  checkoutRevision: z.string().min(1).optional(),
38
39
  candidate: preparedCandidateSchema.optional(),
39
40
  maintenance: preparedMaintenanceSchema.optional(),
41
+ changeOutputs: z.array(changeOutputWorkspaceSchema).optional(),
40
42
  })
41
43
  .strict()
42
44
  .optional(),
@@ -89,6 +91,7 @@ export const runnerResultPayloadSchema = z
89
91
  artifacts: z
90
92
  .array(z
91
93
  .object({
94
+ name: z.string().min(1).optional(),
92
95
  kind: z.string().min(1),
93
96
  externalKey: z
94
97
  .object({ adapter: z.string().min(1), key: z.string().min(1) })
@@ -167,6 +170,7 @@ const runEventSchema = eventEnvelopeSchema.extend({
167
170
  eventType: z.literal(ExecutionEventType.RunSucceeded),
168
171
  payload: z
169
172
  .object({
173
+ changeOutputs: z.array(changeOutputWorkspaceSchema).optional(),
170
174
  workspaceRevision: z
171
175
  .string()
172
176
  .regex(/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/i)
@@ -38,6 +38,7 @@ export interface AgentRunResponse {
38
38
  readonly outcome: AgentRunOutcome;
39
39
  readonly displayBody: string;
40
40
  readonly artifacts?: readonly {
41
+ readonly name?: string | undefined;
41
42
  readonly kind: string;
42
43
  readonly externalKey: {
43
44
  readonly adapter: string;
@@ -1,5 +1,6 @@
1
1
  import type { ActivationId, ActivityName, ActivityOrchestrationGroupId, ActivityOutcome, ActivityWorkflowInstanceId } from '../../activities/index.js';
2
2
  import type { PreparedCandidate } from './candidate.js';
3
+ import type { ChangeOutputWorkspace } from './change-output.js';
3
4
  import type { RunId } from './identifiers.js';
4
5
  import type { Cancellation, ExternalExecutionReference, Lease } from './liveness.js';
5
6
  import type { PreparedMaintenance } from './maintenance.js';
@@ -36,6 +37,7 @@ export interface RunView {
36
37
  readonly cli?: string | undefined;
37
38
  } | undefined;
38
39
  readonly finishedAt?: string;
40
+ readonly changeOutputs?: readonly ChangeOutputWorkspace[] | undefined;
39
41
  readonly workspaceRevision?: string | undefined;
40
42
  readonly outcome?: ActivityOutcome;
41
43
  readonly failure?: ExecutionFailure;
@@ -47,6 +49,7 @@ export interface RunView {
47
49
  readonly checkoutRevision?: string | undefined;
48
50
  readonly candidate?: PreparedCandidate | undefined;
49
51
  readonly maintenance?: PreparedMaintenance | undefined;
52
+ readonly changeOutputs?: readonly ChangeOutputWorkspace[] | undefined;
50
53
  };
51
54
  readonly lease?: Lease;
52
55
  readonly externalExecution?: ExternalExecutionReference;
@@ -1,12 +1,14 @@
1
1
  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
+ import type { ChangeOutputWorkspace } from './change-output.js';
4
5
  import type { RunId } from './identifiers.js';
5
6
  import type { PreparedMaintenance } from './maintenance.js';
6
7
  import type { RepositoryAssignment } from './repository-assignment.js';
7
8
  import type { RunView } from './views.js';
8
9
  import type { WorkspaceMode } from './vocabulary.js';
9
10
  export interface WorkspaceRequest {
11
+ readonly outputName?: string;
10
12
  readonly runId: RunId;
11
13
  readonly signal: AbortSignal;
12
14
  readonly mode: typeof WorkspaceMode.ReadOnly | typeof WorkspaceMode.Branch;
@@ -18,6 +20,8 @@ export interface WorkspaceRequest {
18
20
  readonly assignment?: RepositoryAssignment;
19
21
  }
20
22
  export interface WorkspaceLease {
23
+ readonly changeOutputs?: readonly ChangeOutputWorkspace[];
24
+ readChangeOutputs?(): Promise<readonly ChangeOutputWorkspace[]>;
21
25
  readonly candidate?: PreparedCandidate;
22
26
  readonly maintenance?: PreparedMaintenance;
23
27
  readonly workspaceId: string;
@@ -113,6 +113,9 @@ function applyTerminalEvent(state, event) {
113
113
  status: RunStatus.Succeeded,
114
114
  finishedAt: event.payload.finishedAt,
115
115
  outcome: event.payload.outcome,
116
+ ...(event.payload.changeOutputs === undefined
117
+ ? {}
118
+ : { changeOutputs: event.payload.changeOutputs }),
116
119
  ...(event.payload.workspaceRevision === undefined
117
120
  ? {}
118
121
  : { workspaceRevision: event.payload.workspaceRevision }),
@@ -15,6 +15,7 @@ export * from './contracts/results.js';
15
15
  export * from './contracts/streams.js';
16
16
  export * from './contracts/views.js';
17
17
  export * from './contracts/vocabulary.js';
18
+ export * from './contracts/change-output.js';
18
19
  export * from './contracts/workspace.js';
19
20
  export * from './domain/run-result.js';
20
21
  export * from './domain/run.js';
@@ -15,6 +15,7 @@ export * from './contracts/results.js';
15
15
  export * from './contracts/streams.js';
16
16
  export * from './contracts/views.js';
17
17
  export * from './contracts/vocabulary.js';
18
+ export * from './contracts/change-output.js';
18
19
  export * from './contracts/workspace.js';
19
20
  export * from './domain/run-result.js';
20
21
  export * from './domain/run.js';
@@ -1,5 +1,6 @@
1
1
  /* eslint-disable max-lines */
2
2
  import { execFile } from 'node:child_process';
3
+ import { createHash } from 'node:crypto';
3
4
  import { access, mkdir, readdir, readFile, realpath, rename, rm, rmdir, unlink, writeFile, } from 'node:fs/promises';
4
5
  import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path';
5
6
  import { isDeepStrictEqual, promisify } from 'node:util';
@@ -45,7 +46,7 @@ export class GitWorkspaceProvider {
45
46
  }
46
47
  const locator = await this.resolver.cloneLocator(request.repositoryResource.resourceId, signal);
47
48
  signal.throwIfAborted();
48
- const name = `${request.workItemId}-${request.mode}-${slug(locator)}`;
49
+ const name = `${workspaceBranch(request)}-${request.mode}-${slug(locator)}`;
49
50
  const path = resolve(this.root, name);
50
51
  const markerPath = join(this.markerRoot, `${name}.json`);
51
52
  const lockPath = join(this.markerRoot, `${name}.lease`);
@@ -128,7 +129,7 @@ export class GitWorkspaceProvider {
128
129
  }
129
130
  if (initialRevision === undefined)
130
131
  initialRevision = await readCheckoutRevision(path, this.git, signal);
131
- const branch = request.mode === WorkspaceMode.Branch ? request.workItemId : undefined;
132
+ const branch = request.mode === WorkspaceMode.Branch ? workspaceBranch(request) : undefined;
132
133
  if (branch !== undefined) {
133
134
  initialRevision = await initializeBranch({
134
135
  path,
@@ -314,7 +315,10 @@ function protectsWorkspace(run) {
314
315
  }
315
316
  async function reclaimUnlockedMarker(input, markerPath, marker) {
316
317
  if (input.runs.some((run) => (isActiveRunStatus(run.status) || run.status === RunStatus.Ambiguous) &&
317
- (run.runId === marker.runId || run.workspace?.path === marker.path)))
318
+ (run.runId === marker.runId ||
319
+ run.workspace?.path === marker.path ||
320
+ run.workspace?.changeOutputs?.some((entry) => entry.path === marker.path) === true ||
321
+ run.workspace?.maintenance?.targets.some((entry) => entry.path === marker.path) === true)))
318
322
  return emptyRecovery();
319
323
  if ((await input.options.retainWorkItem?.(marker.workItemId)) === true)
320
324
  return emptyRecovery();
@@ -544,3 +548,10 @@ async function initializeBranch(input, git, signal) {
544
548
  ], signal);
545
549
  return initialRevision;
546
550
  }
551
+ function workspaceBranch(request) {
552
+ return request.outputName === undefined
553
+ ? request.workItemId
554
+ : request.workItemId +
555
+ '-output-' +
556
+ createHash('sha256').update(request.outputName).digest('hex');
557
+ }
@@ -2,6 +2,7 @@ import { type EventJournal, type EventProcessor } from '@atolis-hq/eventing';
2
2
  import { type IdGenerator } from '../../kernel/index.js';
3
3
  import { type ResourceService } from '../../resources/index.js';
4
4
  import type { ProviderInstance } from '../contracts/provider.js';
5
+ import { type ArtifactSourceRun } from './artifact-verification-source.js';
5
6
  interface ArtifactRegistrationDependencies {
6
7
  readonly journal: EventJournal;
7
8
  readonly resources: ResourceService;
@@ -9,16 +10,7 @@ interface ArtifactRegistrationDependencies {
9
10
  readonly providers: readonly ProviderInstance[];
10
11
  readonly maxAmbiguityReconciliationAttempts?: number;
11
12
  readonly runs: {
12
- list(activationId?: string): Promise<readonly {
13
- readonly repositoryAssignment?: {
14
- readonly resourceId: string;
15
- readonly pullRequestBase: string;
16
- } | undefined;
17
- readonly workspaceRevision?: string | undefined;
18
- readonly workspace?: {
19
- readonly branch?: string | undefined;
20
- };
21
- }[]>;
13
+ list(activationId?: string): Promise<readonly ArtifactSourceRun[]>;
22
14
  };
23
15
  }
24
16
  export declare class ArtifactRegistrationReactor {
@@ -29,7 +21,6 @@ export declare class ArtifactRegistrationReactor {
29
21
  private register;
30
22
  reconcileOnce(): Promise<void>;
31
23
  private verifyAndRegister;
32
- private verificationSource;
33
24
  private registerVerified;
34
25
  private recordUnresolved;
35
26
  private branchFor;
@@ -1,18 +1,23 @@
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 { artifactVerificationSource, } from './artifact-verification-source.js';
10
+ import { extendLatestUnresolved } from './latest-unresolved-artifacts.js';
9
11
  export class ArtifactRegistrationReactor {
10
12
  dependencies;
11
13
  latestUnresolved;
12
14
  processor;
13
15
  constructor(dependencies) {
14
16
  this.dependencies = dependencies;
15
- this.latestUnresolved = cachedJournalView(dependencies.journal, deriveLatestUnresolved);
17
+ this.latestUnresolved = foldedJournalView(dependencies.journal, {
18
+ initial: new Map(),
19
+ extend: extendLatestUnresolved,
20
+ });
16
21
  this.processor = defineEventProcessor({
17
22
  consumer: 'reactor:artifact-registration',
18
23
  name: 'artifact-registration',
@@ -74,7 +79,7 @@ export class ArtifactRegistrationReactor {
74
79
  const provider = this.dependencies.providers.find((candidate) => candidate.adapter === record.artifact.externalKey.adapter);
75
80
  if (provider === undefined)
76
81
  return;
77
- const source = await this.verificationSource(record.activationId, branch);
82
+ const source = await artifactVerificationSource((await this.dependencies.runs.list(record.activationId)).at(-1), branch, record.artifact.name, this.dependencies.resources);
78
83
  if (source === null) {
79
84
  await this.recordUnresolved(provider, record, ArtifactVerificationResult.NotFound, attempt);
80
85
  return;
@@ -86,26 +91,6 @@ export class ArtifactRegistrationReactor {
86
91
  }
87
92
  await this.registerVerified(record, verified, workItemId);
88
93
  }
89
- async verificationSource(activationId, branch) {
90
- const run = (await this.dependencies.runs.list(activationId)).at(-1);
91
- const assignment = run?.repositoryAssignment;
92
- const repository = assignment === undefined
93
- ? undefined
94
- : await this.dependencies.resources.get(resourceId(assignment.resourceId));
95
- if (repository === null)
96
- return null;
97
- // Direct workflows keep branch-only verification; head and base are exact only for assignments.
98
- if (assignment === undefined)
99
- return { workspaceBranch: branch };
100
- if (repository === undefined || run?.workspaceRevision === undefined)
101
- return null;
102
- return {
103
- workspaceBranch: branch,
104
- repository: repository.externalKey,
105
- workspaceRevision: run.workspaceRevision,
106
- pullRequestBase: assignment.pullRequestBase,
107
- };
108
- }
109
94
  async registerVerified(record, verified, workItemId) {
110
95
  const existing = await this.dependencies.resources.findByExternalKey(verified.externalKey);
111
96
  // Re-discover an existing resource so a re-report records its newly verified head.
@@ -164,17 +149,6 @@ export class ArtifactRegistrationReactor {
164
149
  : null;
165
150
  }
166
151
  }
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
152
  function reportedArtifacts(value) {
179
153
  if (typeof value !== 'object' || value === null || !('reportedArtifacts' in value))
180
154
  return [];
@@ -184,7 +158,13 @@ function reportedArtifacts(value) {
184
158
  return artifacts
185
159
  .map((artifact) => reportedArtifactSchema.safeParse(artifact))
186
160
  .flatMap((result) => result.success
187
- ? [{ kind: resourceKind(result.data.kind), externalKey: result.data.externalKey }]
161
+ ? [
162
+ {
163
+ ...(result.data.name === undefined ? {} : { name: result.data.name }),
164
+ kind: resourceKind(result.data.kind),
165
+ externalKey: result.data.externalKey,
166
+ },
167
+ ]
188
168
  : []);
189
169
  }
190
170
  function context(commandId, correlationId, occurredAt) {
@@ -0,0 +1,26 @@
1
+ import type { ChangeOutputWorkspace } from '../../execution/index.js';
2
+ import { type ResourceService } from '../../resources/index.js';
3
+ export interface ArtifactSourceRun {
4
+ readonly repositoryAssignment?: {
5
+ readonly resourceId: string;
6
+ readonly pullRequestBase: string;
7
+ } | undefined;
8
+ readonly workspaceRevision?: string | undefined;
9
+ readonly changeOutputs?: readonly ChangeOutputWorkspace[] | undefined;
10
+ readonly workspace?: {
11
+ readonly branch?: string | undefined;
12
+ readonly changeOutputs?: readonly ChangeOutputWorkspace[] | undefined;
13
+ };
14
+ }
15
+ /** Resolve a claim name only against Execution's durable snapshot, including ambiguity retries. */
16
+ export declare function artifactVerificationSource(run: ArtifactSourceRun | undefined, branch: string, name: string | undefined, resources: ResourceService): Promise<{
17
+ workspaceBranch: string;
18
+ repository?: never;
19
+ workspaceRevision?: never;
20
+ pullRequestBase?: never;
21
+ } | {
22
+ workspaceBranch: string;
23
+ repository: import("../../resources/index.js").ExternalResourceKey;
24
+ workspaceRevision: string;
25
+ pullRequestBase: string;
26
+ } | null>;
@@ -0,0 +1,36 @@
1
+ import { resourceId } from '../../resources/index.js';
2
+ /** Resolve a claim name only against Execution's durable snapshot, including ambiguity retries. */
3
+ export async function artifactVerificationSource(run, branch, name, resources) {
4
+ const source = namedSource(run, branch, name);
5
+ if (source === null)
6
+ return null;
7
+ const assignment = source.repositoryAssignment;
8
+ // Direct workflows retain branch-only verification.
9
+ if (assignment === undefined)
10
+ return { workspaceBranch: source.branch };
11
+ const repository = await resources.get(resourceId(assignment.resourceId));
12
+ if (repository === null || source.workspaceRevision === undefined)
13
+ return null;
14
+ return {
15
+ workspaceBranch: source.branch,
16
+ repository: repository.externalKey,
17
+ workspaceRevision: source.workspaceRevision,
18
+ pullRequestBase: assignment.pullRequestBase,
19
+ };
20
+ }
21
+ function namedSource(run, branch, name) {
22
+ if (run?.workspace?.changeOutputs === undefined)
23
+ return {
24
+ branch,
25
+ repositoryAssignment: run?.repositoryAssignment,
26
+ workspaceRevision: run?.workspaceRevision,
27
+ };
28
+ const output = run.changeOutputs?.find((entry) => entry.name === name);
29
+ return output === undefined
30
+ ? null
31
+ : {
32
+ branch: output.branch,
33
+ repositoryAssignment: output.repository,
34
+ workspaceRevision: output.revision,
35
+ };
36
+ }