@atolis-hq/wake 0.4.96 → 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.
- package/dist/src/activities/agent/agent-activity.js +12 -1
- package/dist/src/activities/agent/agent-result.d.ts +1 -0
- package/dist/src/activities/agent/agent-result.js +1 -0
- package/dist/src/activities/contracts/activity.d.ts +7 -0
- package/dist/src/artifacts/application/delegation-artifacts.d.ts +5 -2
- package/dist/src/artifacts/application/delegation-artifacts.js +5 -1
- package/dist/src/bootstrap/composition-root.d.ts +6 -1
- package/dist/src/bootstrap/composition-root.js +40 -15
- package/dist/src/bootstrap/version.js +1 -1
- package/dist/src/control-plane/application/activation-scheduler-ports.d.ts +3 -1
- package/dist/src/control-plane/application/advance-once-dispatch.d.ts +1 -1
- package/dist/src/control-plane/application/advance-once-dispatch.js +4 -2
- package/dist/src/control-plane/application/dispatch-resources.d.ts +4 -0
- package/dist/src/control-plane/application/dispatch-resources.js +13 -0
- package/dist/src/execution/application/execution-service.js +27 -5
- package/dist/src/execution/application/execution-validation.d.ts +6 -1
- package/dist/src/execution/application/execution-validation.js +29 -11
- package/dist/src/execution/application/repository-assignments.d.ts +11 -0
- package/dist/src/execution/application/repository-assignments.js +18 -0
- package/dist/src/execution/application/run-lifecycle.d.ts +1 -0
- package/dist/src/execution/application/run-lifecycle.js +30 -10
- package/dist/src/execution/contracts/commands.d.ts +2 -0
- package/dist/src/execution/contracts/events.d.ts +20 -0
- package/dist/src/execution/contracts/events.js +9 -0
- package/dist/src/execution/contracts/repository-assignment.d.ts +17 -0
- package/dist/src/execution/contracts/repository-assignment.js +9 -0
- package/dist/src/execution/contracts/views.d.ts +5 -0
- package/dist/src/execution/contracts/workspace.d.ts +6 -0
- package/dist/src/execution/domain/run.js +9 -0
- package/dist/src/execution/index.d.ts +3 -0
- package/dist/src/execution/index.js +3 -0
- package/dist/src/execution/infrastructure/workspace/git-source.d.ts +6 -0
- package/dist/src/execution/infrastructure/workspace/git-source.js +35 -0
- package/dist/src/execution/infrastructure/workspace/git-workspace.d.ts +5 -0
- package/dist/src/execution/infrastructure/workspace/git-workspace.js +50 -3
- package/dist/src/integrations/application/artifact-registration-reactor.d.ts +6 -0
- package/dist/src/integrations/application/artifact-registration-reactor.js +35 -11
- package/dist/src/integrations/application/artifact-source.d.ts +9 -0
- package/dist/src/integrations/application/artifact-source.js +12 -0
- package/dist/src/integrations/application/delegation-outputs.d.ts +15 -0
- package/dist/src/integrations/application/delegation-outputs.js +118 -0
- package/dist/src/integrations/contracts/provider.d.ts +3 -0
- package/dist/src/integrations/fake/external-source.d.ts +1 -0
- package/dist/src/integrations/fake/inbound-translator.js +1 -0
- package/dist/src/integrations/fake/provider.d.ts +1 -0
- package/dist/src/integrations/fake/provider.js +11 -2
- package/dist/src/integrations/github/provider.js +7 -1
- package/dist/src/integrations/index.d.ts +1 -0
- package/dist/src/integrations/index.js +1 -0
- package/dist/src/orchestration/application/delegated-work.d.ts +10 -1
- package/dist/src/orchestration/application/delegated-work.js +41 -5
- package/dist/src/orchestration/application/delegation-reservation.d.ts +2 -2
- package/dist/src/orchestration/application/delegation-reservation.js +34 -11
- package/dist/src/orchestration/application/orchestration-service.d.ts +16 -1
- package/dist/src/orchestration/application/orchestration-service.js +4 -0
- package/dist/src/orchestration/contracts/delegation-ports.d.ts +6 -1
- package/dist/src/orchestration/contracts/delegation.d.ts +52 -7
- package/dist/src/orchestration/contracts/delegation.js +47 -2
- package/dist/src/orchestration/contracts/vocabulary.d.ts +3 -0
- package/dist/src/orchestration/contracts/vocabulary.js +1 -0
- package/dist/src/orchestration/index.d.ts +1 -1
- 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
|
+
}
|
|
@@ -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 {
|
|
@@ -13,10 +13,13 @@ export declare function createDelegationArtifacts(input: {
|
|
|
13
13
|
registerChild: (args_0: import("../contracts/context.js").ArtifactDelegationGrant, args_1: import("@atolis-hq/eventing").CommandContext) => Promise<void>;
|
|
14
14
|
qualifyingOutputs(child: {
|
|
15
15
|
readonly workItemId: ArtifactRevisionReference["workItemId"];
|
|
16
|
-
}, outputs: readonly {
|
|
16
|
+
}, outputs: readonly ({
|
|
17
17
|
readonly name: string;
|
|
18
18
|
readonly path: string;
|
|
19
|
-
}
|
|
19
|
+
} | {
|
|
20
|
+
readonly name: string;
|
|
21
|
+
readonly kind: string;
|
|
22
|
+
})[]): Promise<{
|
|
20
23
|
name: string;
|
|
21
24
|
reference: {
|
|
22
25
|
workItemId: import("../../work/index.js").WorkItemId;
|
|
@@ -14,7 +14,11 @@ export function createDelegationArtifacts(input) {
|
|
|
14
14
|
registerChild: async (...args) => input.contexts.registerChild(args[0], input.accepted, args[1]),
|
|
15
15
|
async qualifyingOutputs(child, outputs) {
|
|
16
16
|
const published = await input.artifacts.latestPublished(child.workItemId, (activationId) => input.accepted(activationId, child.workItemId));
|
|
17
|
-
|
|
17
|
+
if (outputs.some((output) => !('path' in output)))
|
|
18
|
+
return null;
|
|
19
|
+
const selected = outputs
|
|
20
|
+
.filter((output) => 'path' in output)
|
|
21
|
+
.map((output) => ({
|
|
18
22
|
name: output.name,
|
|
19
23
|
revision: published.find((revision) => revision.path === output.path),
|
|
20
24
|
}));
|
|
@@ -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[];
|
|
@@ -3,8 +3,9 @@ import { createPullRequestService } from '../activities/index.js';
|
|
|
3
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, RunStatus, TranscriptStore, createExecutionService, createLocalProcessInspector, createRunnerMemoryProfileDecorator, isActiveRunStatus, } 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,11 +64,20 @@ async function createApplicationServices(wakeRoot, options = {}) {
|
|
|
63
64
|
process.stderr.write(`Warning: ${diagnostic.message}\n`);
|
|
64
65
|
}),
|
|
65
66
|
]));
|
|
67
|
+
const providerInstances = createProviderBinding();
|
|
68
|
+
const cloneResolver = createCloneResolver(resources, options);
|
|
66
69
|
const orchestration = createOrchestrationService(journal, work, definitions, projections, createAgentActivityClassifier(activities), (queries) => ({
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
+
}),
|
|
71
81
|
}),
|
|
72
82
|
runHasEnded: async (runId) => {
|
|
73
83
|
const run = (await execution.list()).find((entry) => entry.runId === runId);
|
|
@@ -77,15 +87,7 @@ async function createApplicationServices(wakeRoot, options = {}) {
|
|
|
77
87
|
!execution.isLocallyActive(runId));
|
|
78
88
|
},
|
|
79
89
|
}));
|
|
80
|
-
const workspaces = new GitWorkspaceProvider(paths.workspacesRoot, {
|
|
81
|
-
async cloneLocator(id) {
|
|
82
|
-
const resource = await resources.get(resourceId(id));
|
|
83
|
-
const match = resource === null ? null : /^([^/]+\/[^#]+)#\d+$/.exec(resource.externalKey.key);
|
|
84
|
-
if (match === null)
|
|
85
|
-
throw new Error('Workspace resource ' + id + ' does not identify a GitHub repository');
|
|
86
|
-
return 'https://github.com/' + match[1] + '.git';
|
|
87
|
-
},
|
|
88
|
-
}, {
|
|
90
|
+
const workspaces = new GitWorkspaceProvider(paths.workspacesRoot, cloneResolver, {
|
|
89
91
|
tryAcquire: (path) => acquireFileLock(path, {
|
|
90
92
|
staleAfterMs: 0,
|
|
91
93
|
staleRequiresDeadProcess: true,
|
|
@@ -154,6 +156,7 @@ async function createApplicationServices(wakeRoot, options = {}) {
|
|
|
154
156
|
runners: new Set(Object.values(config.execution.runnerPools).flat()),
|
|
155
157
|
});
|
|
156
158
|
return {
|
|
159
|
+
providerInstances,
|
|
157
160
|
config,
|
|
158
161
|
fakeScenarios,
|
|
159
162
|
workflowNotices,
|
|
@@ -193,10 +196,11 @@ export async function createDiagnosticRoot(wakeRoot) {
|
|
|
193
196
|
wakeRoot,
|
|
194
197
|
providerDefinitions: [gitHubProviderDefinition],
|
|
195
198
|
});
|
|
199
|
+
base.providerInstances.resolve(instances);
|
|
196
200
|
return { ...base, providers: instances, providerFailures: failures };
|
|
197
201
|
}
|
|
198
202
|
export async function createCompositionRoot(wakeRoot, options = {}) {
|
|
199
|
-
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);
|
|
200
204
|
const processorRuntime = new EventProcessorRuntime(journal, checkpoints, subscriptionRunSerialiser, clock);
|
|
201
205
|
const activationScheduler = createActivationScheduler(orchestration, {
|
|
202
206
|
...execution,
|
|
@@ -257,6 +261,7 @@ export async function createCompositionRoot(wakeRoot, options = {}) {
|
|
|
257
261
|
: { fakeDeliveryProvider: options.fakeDeliveryProvider }),
|
|
258
262
|
providerDefinitions: [gitHubProviderDefinition],
|
|
259
263
|
});
|
|
264
|
+
providerInstances.resolve(runtime.providers);
|
|
260
265
|
processorRuntime.register([activationSchedulerSubscriber.processor, ...runtime.processors]);
|
|
261
266
|
return {
|
|
262
267
|
workflowNotices,
|
|
@@ -295,3 +300,23 @@ export async function createCompositionRoot(wakeRoot, options = {}) {
|
|
|
295
300
|
function githubAdapters(config) {
|
|
296
301
|
return Object.entries(config.integrations).flatMap(([adapter, integration]) => integration.enabled && (integration.provider ?? adapter) === 'github' ? [adapter] : []);
|
|
297
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.
|
|
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,6 +1,6 @@
|
|
|
1
1
|
import type { CommandContext } from '@atolis-hq/eventing';
|
|
2
2
|
import type { ActivityActivationView, PendingActivationPriority, WorkflowInstanceView } from '../../orchestration/index.js';
|
|
3
|
-
import type
|
|
3
|
+
import { type ResourceService } from '../../resources/index.js';
|
|
4
4
|
import type { AdvanceResult } from '../contracts/views.js';
|
|
5
5
|
import type { DispatchPolicy } from '../domain/dispatch-policy.js';
|
|
6
6
|
import { type WorkAvailability } from '../domain/open-work-policy.js';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { dispatchResources } from './dispatch-resources.js';
|
|
1
2
|
import { isRunnerQuotaOutcome, reportUnappliedRunnerQuotaRetry, runnerQuotaMessage, } from './runner-quota-outcome.js';
|
|
2
3
|
import { ActivationClaimConflictError, isActiveRunStatus, NoEligibleRunnerError, RunStatus, WorkspaceMode, } from '../../execution/index.js';
|
|
3
4
|
import { DelegationPendingError, WorkflowStatus } from '../../orchestration/index.js';
|
|
@@ -97,13 +98,14 @@ export async function runDispatchLoop(pending, ctx) {
|
|
|
97
98
|
}
|
|
98
99
|
await ctx.orchestration.markActivationStarted(selected.workflow.workflowInstanceId, selected.activation.activationId, ctx.commandContext(selected.activation.activationId));
|
|
99
100
|
startedWorkflowIds.add(selected.workflow.workflowInstanceId);
|
|
100
|
-
const
|
|
101
|
-
const resourceViews =
|
|
101
|
+
const repositoryAssignment = await ctx.orchestration.repositoryAssignment?.(selected.workflow.workItemId);
|
|
102
|
+
const resourceViews = await dispatchResources(ctx.resources, selected.workflow.workItemId, repositoryAssignment);
|
|
102
103
|
const run = await ctx.execution.attempt(selected.activation, {
|
|
103
104
|
workItemId: selected.workflow.workItemId,
|
|
104
105
|
workflowInstanceId: selected.workflow.workflowInstanceId,
|
|
105
106
|
orchestrationGroupId: selected.workflow.orchestrationGroupId,
|
|
106
107
|
resources: resourceViews,
|
|
108
|
+
...(repositoryAssignment === undefined ? {} : { repositoryAssignment }),
|
|
107
109
|
sessionPolicy: selected.activation.sessionPolicy === 'fresh' ||
|
|
108
110
|
selected.workflow.parentWorkflowInstanceId !== undefined
|
|
109
111
|
? 'fresh'
|
|
@@ -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
|
+
}
|
|
@@ -313,11 +313,20 @@ async function completeRun(runtime, currentRunId, activation, context, startedAt
|
|
|
313
313
|
...(resumeSessionId === undefined ? {} : { resumeSessionId }),
|
|
314
314
|
...(resumeStartedAt === undefined ? {} : { resumeStartedAt }),
|
|
315
315
|
...(usageBaseline === undefined ? {} : { usageBaseline }),
|
|
316
|
-
...(lease === undefined
|
|
316
|
+
...(lease === undefined
|
|
317
|
+
? {}
|
|
318
|
+
: {
|
|
319
|
+
workspace: {
|
|
320
|
+
path: lease.path,
|
|
321
|
+
mode: lease.mode,
|
|
322
|
+
checkoutRevision: lease.checkoutRevision,
|
|
323
|
+
repository: context.repositoryAssignment,
|
|
324
|
+
},
|
|
325
|
+
}),
|
|
317
326
|
reportRunnerStarted,
|
|
318
327
|
});
|
|
319
328
|
await stopRenewal();
|
|
320
|
-
await settleRunSuccess(runtime, currentRunId, activation, context, outcome);
|
|
329
|
+
await settleRunSuccess(runtime, currentRunId, activation, context, outcome, lease);
|
|
321
330
|
}
|
|
322
331
|
catch (error) {
|
|
323
332
|
try {
|
|
@@ -337,17 +346,19 @@ async function completeRun(runtime, currentRunId, activation, context, startedAt
|
|
|
337
346
|
});
|
|
338
347
|
}
|
|
339
348
|
}
|
|
340
|
-
async function settleRunSuccess(runtime, currentRunId, activation, context, outcome) {
|
|
349
|
+
async function settleRunSuccess(runtime, currentRunId, activation, context, outcome, lease) {
|
|
341
350
|
if (await shutdownCancellationSucceeded(runtime, currentRunId)) {
|
|
342
351
|
await confirmCancellation(runtime.repository, runtime.dependencies.clock, currentRunId);
|
|
343
352
|
return;
|
|
344
353
|
}
|
|
354
|
+
const workspaceRevision = await lease?.readRevision?.();
|
|
345
355
|
await recordRunSuccess({
|
|
346
356
|
dependencies: runLifecycleDependencies(runtime),
|
|
347
357
|
runId: currentRunId,
|
|
348
358
|
activation,
|
|
349
359
|
context,
|
|
350
360
|
outcome,
|
|
361
|
+
...(workspaceRevision === undefined ? {} : { workspaceRevision }),
|
|
351
362
|
});
|
|
352
363
|
}
|
|
353
364
|
async function settleRunFailure(runtime, currentRunId, activation, context, error) {
|
|
@@ -597,8 +608,19 @@ async function claimActivationForAttempt(runtime, activation, currentRunId, owne
|
|
|
597
608
|
occurredAt,
|
|
598
609
|
});
|
|
599
610
|
}
|
|
600
|
-
function acquireAttemptWorkspace(runtime, activation, context, currentRunId, signal) {
|
|
601
|
-
|
|
611
|
+
async function acquireAttemptWorkspace(runtime, activation, context, currentRunId, signal) {
|
|
612
|
+
const previous = context.repositoryAssignment === undefined
|
|
613
|
+
? undefined
|
|
614
|
+
: (await runtime.repository.list())
|
|
615
|
+
.filter((run) => run.orchestrationGroupId === context.orchestrationGroupId &&
|
|
616
|
+
run.workspace?.mode === WorkspaceMode.Branch &&
|
|
617
|
+
run.status === RunStatus.Succeeded)
|
|
618
|
+
.at(-1);
|
|
619
|
+
return acquireWorkspace(currentRunId, activation.execution?.workspace ?? WorkspaceMode.None, context.workItemId, context.resources, runtime.dependencies.workspaces, {
|
|
620
|
+
signal,
|
|
621
|
+
assignment: context.repositoryAssignment,
|
|
622
|
+
reviewRevision: previous?.workspaceRevision,
|
|
623
|
+
});
|
|
602
624
|
}
|
|
603
625
|
function existingRun(runs, clock, owner) {
|
|
604
626
|
const completed = runs.find((run) => run.status === RunStatus.Succeeded);
|
|
@@ -2,7 +2,12 @@ import { type ResourceRequirement } from '../../activities/index.js';
|
|
|
2
2
|
import { type ResourceView } from '../../resources/index.js';
|
|
3
3
|
import type { WorkItemId } from '../../work/index.js';
|
|
4
4
|
import type { RunId } from '../contracts/identifiers.js';
|
|
5
|
+
import type { RepositoryAssignment } from '../contracts/repository-assignment.js';
|
|
5
6
|
import { WorkspaceMode } from '../contracts/vocabulary.js';
|
|
6
7
|
import type { WorkspaceLease, WorkspaceProvider } from '../contracts/workspace.js';
|
|
7
|
-
export declare function acquireWorkspace(runId: RunId, mode: typeof WorkspaceMode.None | typeof WorkspaceMode.ReadOnly | typeof WorkspaceMode.Branch, workItemId: WorkItemId, resources: readonly ResourceView[], provider?: WorkspaceProvider,
|
|
8
|
+
export declare function acquireWorkspace(runId: RunId, mode: typeof WorkspaceMode.None | typeof WorkspaceMode.ReadOnly | typeof WorkspaceMode.Branch, workItemId: WorkItemId, resources: readonly ResourceView[], provider?: WorkspaceProvider, options?: {
|
|
9
|
+
readonly signal?: AbortSignal | undefined;
|
|
10
|
+
readonly assignment?: RepositoryAssignment | undefined;
|
|
11
|
+
readonly reviewRevision?: string | undefined;
|
|
12
|
+
}): Promise<WorkspaceLease | undefined>;
|
|
8
13
|
export declare function validateResourceRequirements(requirements: readonly ResourceRequirement[], resources: readonly ResourceView[]): void;
|
|
@@ -1,33 +1,40 @@
|
|
|
1
1
|
import { ActivityResourceCardinality } from '../../activities/index.js';
|
|
2
2
|
import { BuiltInResourceKind } from '../../resources/index.js';
|
|
3
3
|
import { WorkspaceMode } from '../contracts/vocabulary.js';
|
|
4
|
-
export async function acquireWorkspace(runId, mode, workItemId, resources, provider,
|
|
4
|
+
export async function acquireWorkspace(runId, mode, workItemId, resources, provider, options = {}) {
|
|
5
|
+
const { signal = new AbortController().signal, assignment, reviewRevision } = options;
|
|
5
6
|
if (mode === WorkspaceMode.None)
|
|
6
7
|
return undefined;
|
|
7
8
|
if (provider === undefined)
|
|
8
9
|
throw new Error('Workspace provider is required');
|
|
9
|
-
const repositoryResource = resources
|
|
10
|
-
resources.find((resource) => resource.kind === BuiltInResourceKind.PullRequest) ??
|
|
11
|
-
resources.find((resource) => resource.kind === BuiltInResourceKind.Issue);
|
|
10
|
+
const repositoryResource = selectWorkspaceResource(resources, assignment);
|
|
12
11
|
if (repositoryResource === undefined)
|
|
13
12
|
throw new Error('Repository Resource is required');
|
|
14
13
|
signal.throwIfAborted();
|
|
15
|
-
const
|
|
16
|
-
const checkoutRevision = repositoryResource.kind === BuiltInResourceKind.Repository ||
|
|
17
|
-
(repositoryResource.kind === BuiltInResourceKind.PullRequest &&
|
|
18
|
-
revision !== undefined &&
|
|
19
|
-
/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/i.test(revision))
|
|
20
|
-
? revision
|
|
21
|
-
: undefined;
|
|
14
|
+
const checkoutRevision = checkoutTarget(repositoryResource, mode, assignment, reviewRevision);
|
|
22
15
|
return provider.acquire({
|
|
23
16
|
runId,
|
|
24
17
|
signal,
|
|
25
18
|
mode,
|
|
26
19
|
workItemId,
|
|
27
20
|
repositoryResource,
|
|
21
|
+
...(assignment === undefined ? {} : { assignment }),
|
|
28
22
|
...(checkoutRevision === undefined ? {} : { checkoutRevision }),
|
|
29
23
|
});
|
|
30
24
|
}
|
|
25
|
+
function checkoutTarget(resource, mode, assignment, reviewRevision) {
|
|
26
|
+
if (assignment !== undefined)
|
|
27
|
+
return mode === WorkspaceMode.ReadOnly
|
|
28
|
+
? (reviewRevision ?? assignment.sourceRevision)
|
|
29
|
+
: assignment.sourceRevision;
|
|
30
|
+
if (resource.kind === BuiltInResourceKind.Repository)
|
|
31
|
+
return resource.revision;
|
|
32
|
+
if (resource.kind === BuiltInResourceKind.PullRequest &&
|
|
33
|
+
resource.revision !== undefined &&
|
|
34
|
+
/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/i.test(resource.revision))
|
|
35
|
+
return resource.revision;
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
31
38
|
export function validateResourceRequirements(requirements, resources) {
|
|
32
39
|
for (const requirement of requirements) {
|
|
33
40
|
const count = resources.filter((resource) => resource.capabilities.includes(requirement.capability)).length;
|
|
@@ -39,3 +46,14 @@ export function validateResourceRequirements(requirements, resources) {
|
|
|
39
46
|
throw new Error(`Activity allows at most one ${requirement.capability} Resource`);
|
|
40
47
|
}
|
|
41
48
|
}
|
|
49
|
+
function selectWorkspaceResource(resources, assignment) {
|
|
50
|
+
const repositoryResource = assignment === undefined
|
|
51
|
+
? (resources.find((resource) => resource.kind === BuiltInResourceKind.Repository) ??
|
|
52
|
+
resources.find((resource) => resource.kind === BuiltInResourceKind.PullRequest) ??
|
|
53
|
+
resources.find((resource) => resource.kind === BuiltInResourceKind.Issue))
|
|
54
|
+
: resources.find((resource) => resource.resourceId === assignment.resourceId &&
|
|
55
|
+
resource.kind === BuiltInResourceKind.Repository);
|
|
56
|
+
if (assignment !== undefined && repositoryResource === undefined)
|
|
57
|
+
throw new Error('Assigned Repository Resource ' + assignment.resourceId + ' is unavailable');
|
|
58
|
+
return repositoryResource;
|
|
59
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ResourceService } from '../../resources/index.js';
|
|
2
|
+
import type { WorkItemId } from '../../work/index.js';
|
|
3
|
+
import type { RepositoryAssignment, RepositoryAssignmentRequest } from '../contracts/repository-assignment.js';
|
|
4
|
+
/** Correlations are the parent's explicit repository authority, not the provider catalogue. */
|
|
5
|
+
export declare function createRepositoryAssignments(resources: ResourceService, resolveSource: (request: RepositoryAssignmentRequest) => Promise<RepositoryAssignment>, inherited: (workItemId: string) => Promise<{
|
|
6
|
+
readonly resourceId: string;
|
|
7
|
+
} | undefined>): {
|
|
8
|
+
resolve(parent: {
|
|
9
|
+
readonly workItemId: WorkItemId;
|
|
10
|
+
}, request: RepositoryAssignmentRequest): Promise<RepositoryAssignment>;
|
|
11
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { BuiltInResourceKind, resourceId } from '../../resources/index.js';
|
|
2
|
+
/** Correlations are the parent's explicit repository authority, not the provider catalogue. */
|
|
3
|
+
export function createRepositoryAssignments(resources, resolveSource, inherited) {
|
|
4
|
+
return {
|
|
5
|
+
async resolve(parent, request) {
|
|
6
|
+
const repository = await resources.get(resourceId(request.resourceId));
|
|
7
|
+
if (repository === null || repository.kind !== BuiltInResourceKind.Repository)
|
|
8
|
+
throw new Error(`Repository Resource ${request.resourceId} is unavailable; select an existing Repository Resource`);
|
|
9
|
+
const correlations = await resources.correlationsForWork(parent.workItemId);
|
|
10
|
+
const scope = await inherited(parent.workItemId);
|
|
11
|
+
if (scope === undefined
|
|
12
|
+
? !correlations.some((entry) => entry.resourceId === repository.resourceId)
|
|
13
|
+
: scope.resourceId !== repository.resourceId)
|
|
14
|
+
throw new Error(`Repository ${request.resourceId} is outside the parent assignment; explicitly authorize the repository before delegating`);
|
|
15
|
+
return resolveSource(request);
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -50,6 +50,7 @@ export declare function recordRunSuccess(input: {
|
|
|
50
50
|
readonly activation: ExecutionActivation;
|
|
51
51
|
readonly context: ExecutionAttemptContext;
|
|
52
52
|
readonly outcome: ActivityOutcome;
|
|
53
|
+
readonly workspaceRevision?: string;
|
|
53
54
|
}): Promise<void>;
|
|
54
55
|
export declare function recordRunFailure(input: {
|
|
55
56
|
readonly dependencies: RunLifecycleDependencies;
|
|
@@ -53,15 +53,7 @@ export async function startRun(input) {
|
|
|
53
53
|
payload: {
|
|
54
54
|
...runPreparationPayload(activation, context, attempt, runner),
|
|
55
55
|
startedAt,
|
|
56
|
-
...(lease
|
|
57
|
-
? {}
|
|
58
|
-
: {
|
|
59
|
-
workspace: {
|
|
60
|
-
mode: lease.mode,
|
|
61
|
-
path: lease.path,
|
|
62
|
-
...(lease.branch === undefined ? {} : { branch: lease.branch }),
|
|
63
|
-
},
|
|
64
|
-
}),
|
|
56
|
+
...workspacePayload(lease),
|
|
65
57
|
},
|
|
66
58
|
}),
|
|
67
59
|
]);
|
|
@@ -76,6 +68,9 @@ export async function startRun(input) {
|
|
|
76
68
|
}
|
|
77
69
|
function runPreparationPayload(activation, context, attempt, runner) {
|
|
78
70
|
return {
|
|
71
|
+
...(context.repositoryAssignment === undefined
|
|
72
|
+
? {}
|
|
73
|
+
: { repositoryAssignment: context.repositoryAssignment }),
|
|
79
74
|
activationId: activation.activationId,
|
|
80
75
|
activity: activation.activity,
|
|
81
76
|
...(activation.stage === undefined ? {} : { stage: activation.stage }),
|
|
@@ -124,7 +119,13 @@ export async function recordRunSuccess(input) {
|
|
|
124
119
|
occurredAt: finishedAt,
|
|
125
120
|
correlationId: context.orchestrationGroupId,
|
|
126
121
|
causationId: activation.activationId,
|
|
127
|
-
payload: {
|
|
122
|
+
payload: {
|
|
123
|
+
outcome,
|
|
124
|
+
finishedAt,
|
|
125
|
+
...(input.workspaceRevision === undefined
|
|
126
|
+
? {}
|
|
127
|
+
: { workspaceRevision: input.workspaceRevision }),
|
|
128
|
+
},
|
|
128
129
|
}),
|
|
129
130
|
]);
|
|
130
131
|
}
|
|
@@ -181,3 +182,22 @@ function requireRunEventData(event) {
|
|
|
181
182
|
return event;
|
|
182
183
|
}
|
|
183
184
|
}
|
|
185
|
+
function workspacePayload(lease) {
|
|
186
|
+
return {
|
|
187
|
+
...(lease === undefined
|
|
188
|
+
? {}
|
|
189
|
+
: {
|
|
190
|
+
workspace: {
|
|
191
|
+
mode: lease.mode,
|
|
192
|
+
...(lease.repositoryResourceId === undefined
|
|
193
|
+
? {}
|
|
194
|
+
: { repositoryResourceId: lease.repositoryResourceId }),
|
|
195
|
+
...(lease.checkoutRevision === undefined
|
|
196
|
+
? {}
|
|
197
|
+
: { checkoutRevision: lease.checkoutRevision }),
|
|
198
|
+
path: lease.path,
|
|
199
|
+
...(lease.branch === undefined ? {} : { branch: lease.branch }),
|
|
200
|
+
},
|
|
201
|
+
}),
|
|
202
|
+
};
|
|
203
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ActivationId, ActivityName, ActivityOrchestrationGroupId, ActivityWorkflowInstanceId } from '../../activities/index.js';
|
|
2
2
|
import type { ResourceView } from '../../resources/index.js';
|
|
3
3
|
import type { WorkItemId } from '../../work/index.js';
|
|
4
|
+
import type { RepositoryAssignment } from './repository-assignment.js';
|
|
4
5
|
import type { WorkspaceMode } from './vocabulary.js';
|
|
5
6
|
export interface ExecutionActivation {
|
|
6
7
|
readonly activationId: ActivationId;
|
|
@@ -20,6 +21,7 @@ export interface ExecutionAttemptContext {
|
|
|
20
21
|
readonly workflowInstanceId: ActivityWorkflowInstanceId;
|
|
21
22
|
readonly orchestrationGroupId: ActivityOrchestrationGroupId;
|
|
22
23
|
readonly resources: readonly ResourceView[];
|
|
24
|
+
readonly repositoryAssignment?: RepositoryAssignment;
|
|
23
25
|
readonly owner?: string;
|
|
24
26
|
/** Runner names currently quota-paused; unset means none. */
|
|
25
27
|
readonly ineligibleRunners?: ReadonlySet<string>;
|