@atolis-hq/wake 0.4.95 → 0.4.97

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 (107) hide show
  1. package/dist/src/activities/agent/agent-activity.js +12 -1
  2. package/dist/src/activities/agent/agent-result.d.ts +1 -0
  3. package/dist/src/activities/agent/agent-result.js +1 -0
  4. package/dist/src/activities/contracts/activity.d.ts +7 -0
  5. package/dist/src/artifacts/application/delegation-artifacts.d.ts +29 -0
  6. package/dist/src/artifacts/application/delegation-artifacts.js +37 -0
  7. package/dist/src/artifacts/index.d.ts +1 -0
  8. package/dist/src/artifacts/index.js +1 -0
  9. package/dist/src/bootstrap/composition-root.d.ts +6 -1
  10. package/dist/src/bootstrap/composition-root.js +50 -12
  11. package/dist/src/bootstrap/version.js +1 -1
  12. package/dist/src/control-plane/application/activation-scheduler-ports.d.ts +3 -1
  13. package/dist/src/control-plane/application/activation-scheduler.js +28 -43
  14. package/dist/src/control-plane/application/advance-once-dispatch.d.ts +1 -14
  15. package/dist/src/control-plane/application/advance-once-dispatch.js +14 -26
  16. package/dist/src/control-plane/application/dispatch-resources.d.ts +4 -0
  17. package/dist/src/control-plane/application/dispatch-resources.js +13 -0
  18. package/dist/src/control-plane/application/in-process-scheduler-serialiser.d.ts +1 -0
  19. package/dist/src/control-plane/application/in-process-scheduler-serialiser.js +15 -0
  20. package/dist/src/control-plane/application/runner-quota-outcome.d.ts +13 -0
  21. package/dist/src/control-plane/application/runner-quota-outcome.js +23 -0
  22. package/dist/src/execution/application/execution-service.js +27 -5
  23. package/dist/src/execution/application/execution-validation.d.ts +6 -1
  24. package/dist/src/execution/application/execution-validation.js +29 -11
  25. package/dist/src/execution/application/repository-assignments.d.ts +11 -0
  26. package/dist/src/execution/application/repository-assignments.js +18 -0
  27. package/dist/src/execution/application/run-lifecycle.d.ts +1 -0
  28. package/dist/src/execution/application/run-lifecycle.js +30 -10
  29. package/dist/src/execution/contracts/commands.d.ts +2 -0
  30. package/dist/src/execution/contracts/events.d.ts +20 -0
  31. package/dist/src/execution/contracts/events.js +9 -0
  32. package/dist/src/execution/contracts/repository-assignment.d.ts +17 -0
  33. package/dist/src/execution/contracts/repository-assignment.js +9 -0
  34. package/dist/src/execution/contracts/views.d.ts +5 -0
  35. package/dist/src/execution/contracts/workspace.d.ts +6 -0
  36. package/dist/src/execution/domain/run.js +9 -0
  37. package/dist/src/execution/index.d.ts +3 -0
  38. package/dist/src/execution/index.js +3 -0
  39. package/dist/src/execution/infrastructure/workspace/git-source.d.ts +6 -0
  40. package/dist/src/execution/infrastructure/workspace/git-source.js +35 -0
  41. package/dist/src/execution/infrastructure/workspace/git-workspace.d.ts +5 -0
  42. package/dist/src/execution/infrastructure/workspace/git-workspace.js +50 -3
  43. package/dist/src/integrations/application/artifact-registration-reactor.d.ts +6 -0
  44. package/dist/src/integrations/application/artifact-registration-reactor.js +35 -11
  45. package/dist/src/integrations/application/artifact-source.d.ts +9 -0
  46. package/dist/src/integrations/application/artifact-source.js +12 -0
  47. package/dist/src/integrations/application/delegation-outputs.d.ts +15 -0
  48. package/dist/src/integrations/application/delegation-outputs.js +118 -0
  49. package/dist/src/integrations/contracts/provider.d.ts +3 -0
  50. package/dist/src/integrations/fake/external-source.d.ts +1 -0
  51. package/dist/src/integrations/fake/inbound-translator.js +1 -0
  52. package/dist/src/integrations/fake/provider.d.ts +1 -0
  53. package/dist/src/integrations/fake/provider.js +11 -2
  54. package/dist/src/integrations/github/provider.js +7 -1
  55. package/dist/src/integrations/index.d.ts +1 -0
  56. package/dist/src/integrations/index.js +1 -0
  57. package/dist/src/orchestration/application/accept-signal.d.ts +3 -1
  58. package/dist/src/orchestration/application/accept-signal.js +2 -0
  59. package/dist/src/orchestration/application/advance-workflow.d.ts +0 -1
  60. package/dist/src/orchestration/application/advance-workflow.js +0 -4
  61. package/dist/src/orchestration/application/deferred-signals.d.ts +21 -0
  62. package/dist/src/orchestration/application/deferred-signals.js +119 -0
  63. package/dist/src/orchestration/application/delegated-work.d.ts +60 -0
  64. package/dist/src/orchestration/application/delegated-work.js +456 -0
  65. package/dist/src/orchestration/application/delegation-gate.d.ts +17 -0
  66. package/dist/src/orchestration/application/delegation-gate.js +31 -0
  67. package/dist/src/orchestration/application/delegation-ledger.d.ts +28 -0
  68. package/dist/src/orchestration/application/delegation-ledger.js +79 -0
  69. package/dist/src/orchestration/application/delegation-reservation.d.ts +15 -0
  70. package/dist/src/orchestration/application/delegation-reservation.js +77 -0
  71. package/dist/src/orchestration/application/expire-timed-out-waits.d.ts +1 -1
  72. package/dist/src/orchestration/application/expire-timed-out-waits.js +2 -2
  73. package/dist/src/orchestration/application/orchestration-projection.js +5 -1
  74. package/dist/src/orchestration/application/orchestration-repository.d.ts +5 -0
  75. package/dist/src/orchestration/application/orchestration-repository.js +69 -11
  76. package/dist/src/orchestration/application/orchestration-service.d.ts +43 -3
  77. package/dist/src/orchestration/application/orchestration-service.js +73 -20
  78. package/dist/src/orchestration/application/resource-transition-matching.js +11 -6
  79. package/dist/src/orchestration/application/start-workflow.js +4 -2
  80. package/dist/src/orchestration/application/workflow-definition-registry.d.ts +5 -1
  81. package/dist/src/orchestration/application/workflow-definition-registry.js +16 -3
  82. package/dist/src/orchestration/contracts/commands.d.ts +1 -0
  83. package/dist/src/orchestration/contracts/delegation-ports.d.ts +19 -0
  84. package/dist/src/orchestration/contracts/delegation-ports.js +1 -0
  85. package/dist/src/orchestration/contracts/delegation.d.ts +143 -0
  86. package/dist/src/orchestration/contracts/delegation.js +115 -0
  87. package/dist/src/orchestration/contracts/event-decoder.js +19 -0
  88. package/dist/src/orchestration/contracts/event-factory.js +16 -0
  89. package/dist/src/orchestration/contracts/events.d.ts +39 -0
  90. package/dist/src/orchestration/contracts/events.js +8 -0
  91. package/dist/src/orchestration/contracts/views.d.ts +8 -0
  92. package/dist/src/orchestration/contracts/vocabulary.d.ts +3 -0
  93. package/dist/src/orchestration/contracts/vocabulary.js +1 -0
  94. package/dist/src/orchestration/domain/workflow-completion.d.ts +3 -0
  95. package/dist/src/orchestration/domain/workflow-completion.js +9 -0
  96. package/dist/src/orchestration/domain/workflow-instance-events.d.ts +2 -0
  97. package/dist/src/orchestration/domain/workflow-instance-events.js +37 -0
  98. package/dist/src/orchestration/index.d.ts +2 -0
  99. package/dist/src/orchestration/index.js +1 -0
  100. package/dist/src/work/application/work-projection.js +3 -0
  101. package/dist/src/work/application/work-service.js +16 -0
  102. package/dist/src/work/contracts/commands.d.ts +6 -0
  103. package/dist/src/work/contracts/events.d.ts +2 -1
  104. package/dist/src/work/contracts/events.js +8 -0
  105. package/dist/src/work/contracts/views.d.ts +2 -1
  106. package/dist/src/work/domain/work-item.js +3 -0
  107. package/package.json +1 -1
@@ -139,7 +139,7 @@ function escapeUntrustedJson(json) {
139
139
  function requestFrom(input, runId, template, runnerContext, resumeSessionId, usageBaseline, workspace, mcpServers, mcpPrompt, reportRunnerTimeout) {
140
140
  return {
141
141
  runId,
142
- prompt: appendMcpPrompt(input.prompt ?? template.prompt, mcpPrompt),
142
+ prompt: appendMcpPrompt(appendWorkspacePrompt(input.prompt ?? template.prompt, workspace), mcpPrompt),
143
143
  ...modelField(input.model ?? template?.model ?? runnerContext?.model),
144
144
  ...effortField(runnerContext?.effort),
145
145
  allowedTools: input.allowedTools ?? template?.allowedTools ?? [],
@@ -213,3 +213,14 @@ function agentOutcome(result) {
213
213
  function parseOutput(output) {
214
214
  return output;
215
215
  }
216
+ function appendWorkspacePrompt(prompt, workspace) {
217
+ if (workspace?.repository === undefined)
218
+ return prompt;
219
+ return (prompt +
220
+ '\n\nWake repository assignment (recorded execution provenance):\n' +
221
+ JSON.stringify({
222
+ ...workspace.repository,
223
+ checkoutRevision: workspace.checkoutRevision,
224
+ }) +
225
+ '\nCreate any PR against the recorded pullRequestBase. Report named change outputs using reportedArtifacts with name, kind, and externalKey.');
226
+ }
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  export declare const reportedArtifactSchema: z.ZodObject<{
3
+ name: z.ZodOptional<z.ZodString>;
3
4
  kind: z.ZodString;
4
5
  externalKey: z.ZodObject<{
5
6
  adapter: z.ZodString;
@@ -2,6 +2,7 @@ import { z } from 'zod';
2
2
  import { ActivityFailureCode, ActivityOutcomeKind, AgentResultStatus, } from '../contracts/vocabulary.js';
3
3
  export const reportedArtifactSchema = z
4
4
  .object({
5
+ name: z.string().min(1).optional(),
5
6
  kind: z.string().min(1),
6
7
  externalKey: z.object({ adapter: z.string().min(1), key: z.string().min(1) }).strict(),
7
8
  })
@@ -111,6 +111,13 @@ export interface ActivityExecutionContext {
111
111
  readonly workspace?: {
112
112
  readonly path: string;
113
113
  readonly mode: ActivityWorkspaceMode;
114
+ readonly checkoutRevision?: string | undefined;
115
+ readonly repository?: {
116
+ readonly resourceId: string;
117
+ readonly sourceRef: string;
118
+ readonly sourceRevision: string;
119
+ readonly pullRequestBase: string;
120
+ } | undefined;
114
121
  };
115
122
  readonly runner?: AgentRunnerPort;
116
123
  readonly mcpServers?: readonly {
@@ -0,0 +1,29 @@
1
+ import type { ArtifactRevisionReference } from '../contracts/context.js';
2
+ import type { ArtifactContextService } from './artifact-context-service.js';
3
+ import type { ArtifactService } from './artifact-service.js';
4
+ /** Binds delegation to Artifacts grants and accepted exact revisions; children never see the join. */
5
+ export declare function createDelegationArtifacts(input: {
6
+ readonly artifacts: ArtifactService;
7
+ readonly contexts: ArtifactContextService;
8
+ readonly accepted: (activationId: string, workItemId?: string) => Promise<boolean>;
9
+ }): {
10
+ validateInputs(_parent: {
11
+ readonly workItemId: string;
12
+ }, references: readonly ArtifactRevisionReference[]): Promise<void>;
13
+ registerChild: (args_0: import("../contracts/context.js").ArtifactDelegationGrant, args_1: import("@atolis-hq/eventing").CommandContext) => Promise<void>;
14
+ qualifyingOutputs(child: {
15
+ readonly workItemId: ArtifactRevisionReference["workItemId"];
16
+ }, outputs: readonly ({
17
+ readonly name: string;
18
+ readonly path: string;
19
+ } | {
20
+ readonly name: string;
21
+ readonly kind: string;
22
+ })[]): Promise<{
23
+ name: string;
24
+ reference: {
25
+ workItemId: import("../../work/index.js").WorkItemId;
26
+ revisionId: string;
27
+ };
28
+ }[] | null>;
29
+ };
@@ -0,0 +1,37 @@
1
+ /** Binds delegation to Artifacts grants and accepted exact revisions; children never see the join. */
2
+ export function createDelegationArtifacts(input) {
3
+ return {
4
+ async validateInputs(_parent, references) {
5
+ const accepted = input.accepted;
6
+ for (const reference of references) {
7
+ const revision = (await input.artifacts.get(reference.workItemId))?.revisions.find((candidate) => candidate.revisionId === reference.revisionId);
8
+ if (revision === undefined ||
9
+ revision.deleted ||
10
+ !(await accepted(revision.activationId, reference.workItemId)))
11
+ throw new Error('Delegation context must reference accepted artifact revisions');
12
+ }
13
+ },
14
+ registerChild: async (...args) => input.contexts.registerChild(args[0], input.accepted, args[1]),
15
+ async qualifyingOutputs(child, outputs) {
16
+ const published = await input.artifacts.latestPublished(child.workItemId, (activationId) => input.accepted(activationId, child.workItemId));
17
+ if (outputs.some((output) => !('path' in output)))
18
+ return null;
19
+ const selected = outputs
20
+ .filter((output) => 'path' in output)
21
+ .map((output) => ({
22
+ name: output.name,
23
+ revision: published.find((revision) => revision.path === output.path),
24
+ }));
25
+ const references = [];
26
+ for (const entry of selected) {
27
+ if (entry.revision === undefined)
28
+ return null;
29
+ references.push({
30
+ name: entry.name,
31
+ reference: { workItemId: child.workItemId, revisionId: entry.revision.revisionId },
32
+ });
33
+ }
34
+ return references;
35
+ },
36
+ };
37
+ }
@@ -18,3 +18,4 @@ export * from './contracts/context-events.js';
18
18
  export * from './contracts/context.js';
19
19
  export * from './application/operator-instructions-service.js';
20
20
  export * from './application/operator-instructions-projection.js';
21
+ export { createDelegationArtifacts } from './application/delegation-artifacts.js';
@@ -18,3 +18,4 @@ export * from './contracts/context-events.js';
18
18
  export * from './contracts/context.js';
19
19
  export * from './application/operator-instructions-service.js';
20
20
  export * from './application/operator-instructions-projection.js';
21
+ export { createDelegationArtifacts } from './application/delegation-artifacts.js';
@@ -3,7 +3,7 @@ import { createPullRequestService, type ActivityRegistry } from '../activities/i
3
3
  import { OperatorInstructionsService, createArtifactService } from '../artifacts/index.js';
4
4
  import { createControlPlaneService, createRunnerControlService, type ActivationScheduler, type ActivationSchedulerSubscriber, type IntakePipeline, type RunnerPipeline, type TriggerCheckpointStore, type TriggerConfig, type TriggerService } from '../control-plane/index.js';
5
5
  import { createConversationService } from '../conversations/index.js';
6
- import { GitWorkspaceProvider, RecoveryService, TranscriptStore, createExecutionService, type FakeScenarioResolver, type Runner } from '../execution/index.js';
6
+ import { GitWorkspaceProvider, RecoveryService, TranscriptStore, createExecutionService, type FakeScenarioResolver, type RepositoryCloneResolver, type Runner } from '../execution/index.js';
7
7
  import type { DeliveryService, DurableFakeDeliveryProvider, ExternalDeliveryAdapter, ProviderCompositionFailure, ProviderInstance } from '../integrations/index.js';
8
8
  import { UlidIdGenerator, type Clock } from '../kernel/index.js';
9
9
  import { createOrchestrationService } from '../orchestration/index.js';
@@ -36,6 +36,7 @@ export interface CompositionRootOptions {
36
36
  /** Trusted context binding supplies a shared scope identity; absent bindings use the trigger ID. */
37
37
  readonly triggerCoordinationKey?: (config: TriggerConfig) => string;
38
38
  readonly decorateDeliveryAdapter?: (adapter: ExternalDeliveryAdapter, provider: ProviderInstance) => ExternalDeliveryAdapter;
39
+ readonly decorateRepositoryCloneResolver?: (resolver: RepositoryCloneResolver) => RepositoryCloneResolver;
39
40
  readonly decorateRunner?: (runner: Runner, name: string) => Runner;
40
41
  /** A real fake-provider adapter for deterministic composed integration evidence. */
41
42
  readonly fakeDeliveryProvider?: DurableFakeDeliveryProvider;
@@ -86,6 +87,10 @@ export declare function resolveResourceRepositoryIdentity(externalKey: Parameter
86
87
  export declare function createDiagnosticRoot(wakeRoot: string): Promise<{
87
88
  providers: readonly ProviderInstance[];
88
89
  providerFailures: readonly ProviderCompositionFailure[];
90
+ providerInstances: {
91
+ promise: Promise<readonly ProviderInstance[]>;
92
+ resolve: (providers: readonly ProviderInstance[]) => void;
93
+ };
89
94
  config: ResolvedWakeModulesConfig;
90
95
  fakeScenarios: FakeScenarioResolver;
91
96
  workflowNotices: string[];
@@ -1,10 +1,11 @@
1
1
  import { acquireFileLock } from '@atolis-hq/eventing-filesystem';
2
2
  import { createPullRequestService } from '../activities/index.js';
3
- import { ArtifactContextService, FileArtifactMcpSessionStore, FileArtifactStore, OperatorInstructionsService, createArtifactService, } from '../artifacts/index.js';
3
+ import { ArtifactContextService, FileArtifactMcpSessionStore, FileArtifactStore, OperatorInstructionsService, createArtifactService, createDelegationArtifacts, } from '../artifacts/index.js';
4
4
  import { DispatchPolicy, createActivationScheduler, createActivationSchedulerSubscriber, createControlPlaneService, createDurableRunnerIneligibility, createRunnerControlService, } from '../control-plane/index.js';
5
5
  import { createConversationService } from '../conversations/index.js';
6
- import { ExecutionCancellationReason, GitWorkspaceProvider, RecoveryService, TranscriptStore, createExecutionService, createLocalProcessInspector, createRunnerMemoryProfileDecorator, } from '../execution/index.js';
6
+ import { ExecutionCancellationReason, GitWorkspaceProvider, RecoveryService, RunStatus, TranscriptStore, createExecutionService, createLocalProcessInspector, createRepositoryAssignments, createRunnerMemoryProfileDecorator, isActiveRunStatus, resolveGitSource, } from '../execution/index.js';
7
7
  import { createGitHubAgentContextReader, gitHubProviderDefinition, gitHubRepositoryIdentity, resolveGitHubResourceUrl, } from '../integrations/github/index.js';
8
+ import { createDelegationOutputs } from '../integrations/index.js';
8
9
  import { SystemClock, UlidIdGenerator } from '../kernel/index.js';
9
10
  import { compileWorkflow, createAgentActivityClassifier, createOrchestrationService, } from '../orchestration/index.js';
10
11
  import { createResourceLookup, createResourceService, resourceId, } from '../resources/index.js';
@@ -63,16 +64,30 @@ async function createApplicationServices(wakeRoot, options = {}) {
63
64
  process.stderr.write(`Warning: ${diagnostic.message}\n`);
64
65
  }),
65
66
  ]));
66
- const orchestration = createOrchestrationService(journal, work, definitions, projections, createAgentActivityClassifier(activities));
67
- const workspaces = new GitWorkspaceProvider(paths.workspacesRoot, {
68
- async cloneLocator(id) {
69
- const resource = await resources.get(resourceId(id));
70
- const match = resource === null ? null : /^([^/]+\/[^#]+)#\d+$/.exec(resource.externalKey.key);
71
- if (match === null)
72
- throw new Error('Workspace resource ' + id + ' does not identify a GitHub repository');
73
- return 'https://github.com/' + match[1] + '.git';
67
+ const providerInstances = createProviderBinding();
68
+ const cloneResolver = createCloneResolver(resources, options);
69
+ const orchestration = createOrchestrationService(journal, work, definitions, projections, createAgentActivityClassifier(activities), (queries) => ({
70
+ repositories: createRepositoryAssignments(resources, (request) => resolveGitSource(cloneResolver, request), (id) => orchestration.repositoryAssignment(id)),
71
+ artifacts: createDelegationOutputs({
72
+ providers: () => providerInstances.promise,
73
+ resources,
74
+ pullRequests,
75
+ runs: () => execution.list(),
76
+ artifacts: createDelegationArtifacts({
77
+ artifacts,
78
+ contexts: artifactContexts,
79
+ accepted: queries.isActivationAccepted,
80
+ }),
81
+ }),
82
+ runHasEnded: async (runId) => {
83
+ const run = (await execution.list()).find((entry) => entry.runId === runId);
84
+ return (run !== undefined &&
85
+ !isActiveRunStatus(run.status) &&
86
+ run.status !== RunStatus.Ambiguous &&
87
+ !execution.isLocallyActive(runId));
74
88
  },
75
- }, {
89
+ }));
90
+ const workspaces = new GitWorkspaceProvider(paths.workspacesRoot, cloneResolver, {
76
91
  tryAcquire: (path) => acquireFileLock(path, {
77
92
  staleAfterMs: 0,
78
93
  staleRequiresDeadProcess: true,
@@ -141,6 +156,7 @@ async function createApplicationServices(wakeRoot, options = {}) {
141
156
  runners: new Set(Object.values(config.execution.runnerPools).flat()),
142
157
  });
143
158
  return {
159
+ providerInstances,
144
160
  config,
145
161
  fakeScenarios,
146
162
  workflowNotices,
@@ -180,10 +196,11 @@ export async function createDiagnosticRoot(wakeRoot) {
180
196
  wakeRoot,
181
197
  providerDefinitions: [gitHubProviderDefinition],
182
198
  });
199
+ base.providerInstances.resolve(instances);
183
200
  return { ...base, providers: instances, providerFailures: failures };
184
201
  }
185
202
  export async function createCompositionRoot(wakeRoot, options = {}) {
186
- const { config, fakeScenarios, workflowNotices, paths, maintenance, clock, ids, journal, projections, checkpoints, processorState, subscriptionRunSerialiser, work, artifacts, operatorInstructions, conversations, resources, pullRequests, lookup, orchestration, execution, recovery, transcriptStore, runnerControls, controlPlane, isRuntimePaused, activities, runners, artifactTriggerContext, workspaces, } = await createApplicationServices(wakeRoot, options);
203
+ const { providerInstances, config, fakeScenarios, workflowNotices, paths, maintenance, clock, ids, journal, projections, checkpoints, processorState, subscriptionRunSerialiser, work, artifacts, operatorInstructions, conversations, resources, pullRequests, lookup, orchestration, execution, recovery, transcriptStore, runnerControls, controlPlane, isRuntimePaused, activities, runners, artifactTriggerContext, workspaces, } = await createApplicationServices(wakeRoot, options);
187
204
  const processorRuntime = new EventProcessorRuntime(journal, checkpoints, subscriptionRunSerialiser, clock);
188
205
  const activationScheduler = createActivationScheduler(orchestration, {
189
206
  ...execution,
@@ -244,6 +261,7 @@ export async function createCompositionRoot(wakeRoot, options = {}) {
244
261
  : { fakeDeliveryProvider: options.fakeDeliveryProvider }),
245
262
  providerDefinitions: [gitHubProviderDefinition],
246
263
  });
264
+ providerInstances.resolve(runtime.providers);
247
265
  processorRuntime.register([activationSchedulerSubscriber.processor, ...runtime.processors]);
248
266
  return {
249
267
  workflowNotices,
@@ -282,3 +300,23 @@ export async function createCompositionRoot(wakeRoot, options = {}) {
282
300
  function githubAdapters(config) {
283
301
  return Object.entries(config.integrations).flatMap(([adapter, integration]) => integration.enabled && (integration.provider ?? adapter) === 'github' ? [adapter] : []);
284
302
  }
303
+ function createCloneResolver(resources, options) {
304
+ const defaultCloneResolver = {
305
+ async cloneLocator(id) {
306
+ const resource = await resources.get(resourceId(id));
307
+ // Repository, PR and issue keys resolve to one clone; the '#N' suffix is optional.
308
+ const repository = resource?.externalKey.key.replace(/#\d+$/, '');
309
+ if (repository === undefined || !/^[^/]+\/[^/#]+$/.test(repository))
310
+ throw new Error('Workspace resource ' + id + ' does not identify a GitHub repository');
311
+ return 'https://github.com/' + repository + '.git';
312
+ },
313
+ };
314
+ return options.decorateRepositoryCloneResolver?.(defaultCloneResolver) ?? defaultCloneResolver;
315
+ }
316
+ function createProviderBinding() {
317
+ let bind;
318
+ const promise = new Promise((resolve) => {
319
+ bind = resolve;
320
+ });
321
+ return { promise, resolve: bind };
322
+ }
@@ -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.95";
127
+ export const wakeVersion = "v0.4.97";
128
128
  /** The registry-installable version used by packaged sandbox images. */
129
129
  export const wakePackageVersion = packageVersion(defaultRepoRoot) ?? wakeVersion;
@@ -1,5 +1,5 @@
1
1
  import type { CommandContext } from '@atolis-hq/eventing';
2
- import type { ExecutionFailureCode, RunView, WorkspaceRecovery } from '../../execution/index.js';
2
+ import type { ExecutionFailureCode, RepositoryAssignment, RunView, WorkspaceRecovery } from '../../execution/index.js';
3
3
  import type { IdGenerator } from '../../kernel/index.js';
4
4
  import type { ActivityActivationView, PendingActivationPriority, WorkflowInstanceView } from '../../orchestration/index.js';
5
5
  import type { ResourceService } from '../../resources/index.js';
@@ -13,6 +13,7 @@ export interface OrchestrationPort {
13
13
  priority?: PendingActivationPriority;
14
14
  }[]>;
15
15
  listWaiting(): Promise<readonly (WorkflowInstanceView | null)[]>;
16
+ repositoryAssignment?(workItemId: string): Promise<RepositoryAssignment | undefined>;
16
17
  get?(workflowInstanceId: string): Promise<WorkflowInstanceView | null>;
17
18
  expireTimedOutWaits?(context: CommandContext): Promise<readonly WorkflowInstanceView[]>;
18
19
  listAll?(): Promise<readonly WorkflowInstanceView[]>;
@@ -43,6 +44,7 @@ export interface ExecutionPort {
43
44
  workItemId: WorkflowInstanceView['workItemId'];
44
45
  workflowInstanceId: WorkflowInstanceView['workflowInstanceId'];
45
46
  orchestrationGroupId: WorkflowInstanceView['orchestrationGroupId'];
47
+ repositoryAssignment?: RepositoryAssignment;
46
48
  resources: readonly NonNullable<Awaited<ReturnType<ResourceService['get']>>>[];
47
49
  ineligibleRunners?: ReadonlySet<string>;
48
50
  sessionPolicy?: 'fresh' | 'resume-stage';
@@ -1,11 +1,13 @@
1
+ import { createInProcessSerialiser } from './in-process-scheduler-serialiser.js';
2
+ import { isRunnerQuotaOutcome, reportUnappliedRunnerQuotaRetry, runnerQuotaMessage, } from './runner-quota-outcome.js';
1
3
  /* eslint-disable complexity, max-lines-per-function */
2
4
  import { correlationId, EventActorKind } from '@atolis-hq/eventing';
3
5
  import { ExecutionFailureCode, RunStatus } from '../../execution/index.js';
4
- import { isAmbiguityResolutionBlock, WorkflowStatus, } from '../../orchestration/index.js';
6
+ import { DelegationPendingError, isAmbiguityResolutionBlock, WorkflowStatus, } from '../../orchestration/index.js';
5
7
  import { WorkStatus } from '../../work/index.js';
6
8
  import { ControlStreamKind } from '../contracts/streams.js';
7
9
  import { DispatchPolicy } from '../domain/dispatch-policy.js';
8
- import { advancementWasDurablyApplied, blockIsolatedWorkflow, isRunnerQuotaOutcome, reportUnappliedRunnerQuotaRetry, runDispatchLoop, runnerQuotaMessage, } from './advance-once-dispatch.js';
10
+ import { advancementWasDurablyApplied, blockIsolatedWorkflow, runDispatchLoop, } from './advance-once-dispatch.js';
9
11
  import { findUnresolvedSucceededTerminal, findUnresolvedTerminal, } from './execution-reconciliation.js';
10
12
  export function createActivationScheduler(orchestration, execution, resources, clock, dependencies) {
11
13
  const runnerIneligibility = dependencies.runnerIneligibility ?? (async () => new Set());
@@ -21,6 +23,19 @@ export function createActivationScheduler(orchestration, execution, resources, c
21
23
  occurredAt: clock.now().toISOString(),
22
24
  actor: { kind: EventActorKind.System, id: ControlStreamKind.Global },
23
25
  });
26
+ const dispatchContext = {
27
+ orchestration,
28
+ execution,
29
+ resources,
30
+ dispatchPolicy,
31
+ maxConcurrentRuns,
32
+ maxOpenWorkItems: dependencies.maxOpenWorkItems ?? null,
33
+ work: dependencies.work,
34
+ maxDispatches,
35
+ runnerIneligibility,
36
+ isDispatchPaused,
37
+ commandContext: context,
38
+ };
24
39
  const maintain = async () => {
25
40
  if (await isDispatchPaused())
26
41
  return { kind: 'paused' };
@@ -161,22 +176,19 @@ export function createActivationScheduler(orchestration, execution, resources, c
161
176
  };
162
177
  }
163
178
  catch (error) {
179
+ if (error instanceof DelegationPendingError) {
180
+ const result = await runDispatchLoop(pending.filter((item) => item.workflow.workflowInstanceId !== recovery.item.workflow.workflowInstanceId), dispatchContext);
181
+ return result.kind === 'no-work' || result.kind === WorkflowStatus.Waiting
182
+ ? {
183
+ kind: WorkflowStatus.Waiting,
184
+ workflowInstanceId: recovery.item.workflow.workflowInstanceId,
185
+ }
186
+ : result;
187
+ }
164
188
  if (await advancementWasDurablyApplied(orchestration, recovery.item.workflow.workflowInstanceId, recovery.item.activation.activationId))
165
189
  throw error;
166
190
  const reason = await blockIsolatedWorkflow(orchestration, recovery.item.workflow.workflowInstanceId, error, context(recovery.run.runId));
167
- const result = await runDispatchLoop(pending.filter((item) => item.workflow.workflowInstanceId !== recovery.item.workflow.workflowInstanceId), {
168
- orchestration,
169
- execution,
170
- resources,
171
- dispatchPolicy,
172
- maxConcurrentRuns,
173
- maxOpenWorkItems: dependencies.maxOpenWorkItems ?? null,
174
- work: dependencies.work,
175
- maxDispatches,
176
- runnerIneligibility,
177
- isDispatchPaused,
178
- commandContext: context,
179
- });
191
+ const result = await runDispatchLoop(pending.filter((item) => item.workflow.workflowInstanceId !== recovery.item.workflow.workflowInstanceId), dispatchContext);
180
192
  return result.kind === 'progressed'
181
193
  ? result
182
194
  : {
@@ -186,19 +198,7 @@ export function createActivationScheduler(orchestration, execution, resources, c
186
198
  };
187
199
  }
188
200
  }
189
- const result = await runDispatchLoop(pending, {
190
- orchestration,
191
- execution,
192
- resources,
193
- dispatchPolicy,
194
- maxConcurrentRuns,
195
- maxOpenWorkItems: dependencies.maxOpenWorkItems ?? null,
196
- work: dependencies.work,
197
- maxDispatches,
198
- runnerIneligibility,
199
- isDispatchPaused,
200
- commandContext: context,
201
- });
201
+ const result = await runDispatchLoop(pending, dispatchContext);
202
202
  if (expired.length === 0 ||
203
203
  (result.kind !== 'no-work' && result.kind !== WorkflowStatus.Waiting))
204
204
  return result;
@@ -221,18 +221,3 @@ export function createActivationScheduler(orchestration, execution, resources, c
221
221
  dispatch: (options, signal) => serialise(() => dispatch(options), signal),
222
222
  };
223
223
  }
224
- function createInProcessSerialiser() {
225
- let prior = Promise.resolve();
226
- return async (operation, signal) => {
227
- const current = prior.then(async () => {
228
- throwIfAborted(signal);
229
- return operation();
230
- });
231
- prior = current.then(() => undefined, () => undefined);
232
- return current;
233
- };
234
- }
235
- function throwIfAborted(signal) {
236
- if (signal?.aborted)
237
- throw signal.reason ?? new Error('Activation scheduler run aborted');
238
- }
@@ -1,7 +1,6 @@
1
1
  import type { CommandContext } from '@atolis-hq/eventing';
2
- import { type ActivityOutcome } from '../../activities/index.js';
3
2
  import type { ActivityActivationView, PendingActivationPriority, WorkflowInstanceView } from '../../orchestration/index.js';
4
- import type { ResourceService } from '../../resources/index.js';
3
+ import { type ResourceService } from '../../resources/index.js';
5
4
  import type { AdvanceResult } from '../contracts/views.js';
6
5
  import type { DispatchPolicy } from '../domain/dispatch-policy.js';
7
6
  import { type WorkAvailability } from '../domain/open-work-policy.js';
@@ -29,18 +28,6 @@ interface PendingActivation {
29
28
  export declare function advancementWasDurablyApplied(orchestration: OrchestrationPort, workflowInstanceId: WorkflowInstanceView['workflowInstanceId'], activationId: ActivityActivationView['activationId']): Promise<boolean>;
30
29
  export declare function isolatedWorkflowReason(error: unknown): string;
31
30
  export declare function blockIsolatedWorkflow(orchestration: OrchestrationPort, workflowInstanceId: string, error: unknown, context: CommandContext): Promise<string>;
32
- export declare function isRunnerQuotaOutcome(outcome: ActivityOutcome): boolean;
33
- export declare function runnerQuotaMessage(outcome: ActivityOutcome): string;
34
- /**
35
- * A quota retry deliberately leaves the outcome unaccepted, so a port that
36
- * never applied it (absent method, or a workflow instance that vanished)
37
- * leaves the Run permanently unresolved. Surface that rather than going
38
- * silent; it is an operational defect, not a workflow state.
39
- */
40
- export declare function reportUnappliedRunnerQuotaRetry(result: unknown, input: {
41
- readonly activationId: string;
42
- readonly runId: string;
43
- }): void;
44
31
  /**
45
32
  * Fills open capacity within one Advancement call: dispatches ready
46
33
  * activations one at a time, rechecking `maxConcurrentRuns` and reselecting
@@ -1,6 +1,7 @@
1
- import { ActivityFailureCode, ActivityOutcomeKind, } from '../../activities/index.js';
1
+ import { dispatchResources } from './dispatch-resources.js';
2
+ import { isRunnerQuotaOutcome, reportUnappliedRunnerQuotaRetry, runnerQuotaMessage, } from './runner-quota-outcome.js';
2
3
  import { ActivationClaimConflictError, isActiveRunStatus, NoEligibleRunnerError, RunStatus, WorkspaceMode, } from '../../execution/index.js';
3
- import { WorkflowStatus } from '../../orchestration/index.js';
4
+ import { DelegationPendingError, WorkflowStatus } from '../../orchestration/index.js';
4
5
  import { canDispatchWorkItem, readOpenWorkItemIds, } from '../domain/open-work-policy.js';
5
6
  import { isExecutionFailureTerminal } from './execution-reconciliation.js';
6
7
  // Ports without priority (older fakes) rank neutrally and fall back to oldest-first.
@@ -27,28 +28,6 @@ export async function blockIsolatedWorkflow(orchestration, workflowInstanceId, e
27
28
  await orchestration.block(workflowInstanceId, reason, context);
28
29
  return reason;
29
30
  }
30
- export function isRunnerQuotaOutcome(outcome) {
31
- return (outcome.kind === ActivityOutcomeKind.Failed &&
32
- typeof outcome.data === 'object' &&
33
- outcome.data !== null &&
34
- 'reason' in outcome.data &&
35
- outcome.data.reason === ActivityFailureCode.RunnerQuotaExceeded);
36
- }
37
- export function runnerQuotaMessage(outcome) {
38
- const data = outcome.data;
39
- return typeof data.message === 'string' ? data.message : 'runner reported quota exhaustion';
40
- }
41
- /**
42
- * A quota retry deliberately leaves the outcome unaccepted, so a port that
43
- * never applied it (absent method, or a workflow instance that vanished)
44
- * leaves the Run permanently unresolved. Surface that rather than going
45
- * silent; it is an operational defect, not a workflow state.
46
- */
47
- export function reportUnappliedRunnerQuotaRetry(result, input) {
48
- if (result !== null && result !== undefined)
49
- return;
50
- console.error(`Runner-quota retry was not applied for activation ${input.activationId} (run ${input.runId}); its outcome remains unaccepted.`);
51
- }
52
31
  /**
53
32
  * Fills open capacity within one Advancement call: dispatches ready
54
33
  * activations one at a time, rechecking `maxConcurrentRuns` and reselecting
@@ -119,13 +98,14 @@ export async function runDispatchLoop(pending, ctx) {
119
98
  }
120
99
  await ctx.orchestration.markActivationStarted(selected.workflow.workflowInstanceId, selected.activation.activationId, ctx.commandContext(selected.activation.activationId));
121
100
  startedWorkflowIds.add(selected.workflow.workflowInstanceId);
122
- const correlated = await ctx.resources.correlationsForWork(selected.workflow.workItemId);
123
- const resourceViews = (await Promise.all(correlated.map((entry) => ctx.resources.get(entry.resourceId)))).filter((resource) => resource !== null);
101
+ const repositoryAssignment = await ctx.orchestration.repositoryAssignment?.(selected.workflow.workItemId);
102
+ const resourceViews = await dispatchResources(ctx.resources, selected.workflow.workItemId, repositoryAssignment);
124
103
  const run = await ctx.execution.attempt(selected.activation, {
125
104
  workItemId: selected.workflow.workItemId,
126
105
  workflowInstanceId: selected.workflow.workflowInstanceId,
127
106
  orchestrationGroupId: selected.workflow.orchestrationGroupId,
128
107
  resources: resourceViews,
108
+ ...(repositoryAssignment === undefined ? {} : { repositoryAssignment }),
129
109
  sessionPolicy: selected.activation.sessionPolicy === 'fresh' ||
130
110
  selected.workflow.parentWorkflowInstanceId !== undefined
131
111
  ? 'fresh'
@@ -181,6 +161,14 @@ export async function runDispatchLoop(pending, ctx) {
181
161
  dispatchedIds.add(selected.activation.activationId);
182
162
  }
183
163
  catch (error) {
164
+ if (error instanceof DelegationPendingError) {
165
+ isolatedIds.add(selected.workflow.workflowInstanceId);
166
+ stopReason = {
167
+ kind: WorkflowStatus.Waiting,
168
+ workflowInstanceId: selected.workflow.workflowInstanceId,
169
+ };
170
+ continue;
171
+ }
184
172
  if (error instanceof ActivationClaimConflictError) {
185
173
  stopReason = { kind: 'no-work' };
186
174
  break;
@@ -0,0 +1,4 @@
1
+ import type { RepositoryAssignment } from '../../execution/index.js';
2
+ import { type ResourceService } from '../../resources/index.js';
3
+ import type { WorkItemId } from '../../work/index.js';
4
+ export declare function dispatchResources(resources: ResourceService, workItemId: WorkItemId, assignment: RepositoryAssignment | undefined): Promise<import("../../resources/index.js").ResourceView[]>;
@@ -0,0 +1,13 @@
1
+ import { resourceId } from '../../resources/index.js';
2
+ export async function dispatchResources(resources, workItemId, assignment) {
3
+ const correlated = await resources.correlationsForWork(workItemId);
4
+ const views = (await Promise.all(correlated.map((entry) => resources.get(entry.resourceId)))).filter((entry) => entry !== null);
5
+ if (assignment !== undefined &&
6
+ !views.some((entry) => entry.resourceId === assignment.resourceId)) {
7
+ const repository = await resources.get(resourceId(assignment.resourceId));
8
+ if (repository === null)
9
+ throw new Error(`Assigned repository ${assignment.resourceId} is unavailable`);
10
+ views.push(repository);
11
+ }
12
+ return views;
13
+ }
@@ -0,0 +1 @@
1
+ export declare function createInProcessSerialiser(): <Value>(operation: () => Promise<Value>, signal?: AbortSignal) => Promise<Value>;
@@ -0,0 +1,15 @@
1
+ export function createInProcessSerialiser() {
2
+ let prior = Promise.resolve();
3
+ return async (operation, signal) => {
4
+ const current = prior.then(async () => {
5
+ throwIfAborted(signal);
6
+ return operation();
7
+ });
8
+ prior = current.then(() => undefined, () => undefined);
9
+ return current;
10
+ };
11
+ }
12
+ function throwIfAborted(signal) {
13
+ if (signal?.aborted)
14
+ throw signal.reason ?? new Error('Activation scheduler run aborted');
15
+ }
@@ -0,0 +1,13 @@
1
+ import { type ActivityOutcome } from '../../activities/index.js';
2
+ export declare function isRunnerQuotaOutcome(outcome: ActivityOutcome): boolean;
3
+ export declare function runnerQuotaMessage(outcome: ActivityOutcome): string;
4
+ /**
5
+ * A quota retry deliberately leaves the outcome unaccepted, so a port that
6
+ * never applied it (absent method, or a workflow instance that vanished)
7
+ * leaves the Run permanently unresolved. Surface that rather than going
8
+ * silent; it is an operational defect, not a workflow state.
9
+ */
10
+ export declare function reportUnappliedRunnerQuotaRetry(result: unknown, input: {
11
+ readonly activationId: string;
12
+ readonly runId: string;
13
+ }): void;
@@ -0,0 +1,23 @@
1
+ import { ActivityFailureCode, ActivityOutcomeKind, } from '../../activities/index.js';
2
+ export function isRunnerQuotaOutcome(outcome) {
3
+ return (outcome.kind === ActivityOutcomeKind.Failed &&
4
+ typeof outcome.data === 'object' &&
5
+ outcome.data !== null &&
6
+ 'reason' in outcome.data &&
7
+ outcome.data.reason === ActivityFailureCode.RunnerQuotaExceeded);
8
+ }
9
+ export function runnerQuotaMessage(outcome) {
10
+ const data = outcome.data;
11
+ return typeof data.message === 'string' ? data.message : 'runner reported quota exhaustion';
12
+ }
13
+ /**
14
+ * A quota retry deliberately leaves the outcome unaccepted, so a port that
15
+ * never applied it (absent method, or a workflow instance that vanished)
16
+ * leaves the Run permanently unresolved. Surface that rather than going
17
+ * silent; it is an operational defect, not a workflow state.
18
+ */
19
+ export function reportUnappliedRunnerQuotaRetry(result, input) {
20
+ if (result !== null && result !== undefined)
21
+ return;
22
+ console.error(`Runner-quota retry was not applied for activation ${input.activationId} (run ${input.runId}); its outcome remains unaccepted.`);
23
+ }