@atolis-hq/wake 0.4.0 → 0.4.2

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.
@@ -337,13 +337,8 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \\
337
337
  && chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg \\
338
338
  && echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" \\
339
339
  > /etc/apt/sources.list.d/github-cli.list \\
340
- && curl -fsSL https://ngrok-agent.s3.amazonaws.com/ngrok.asc \\
341
- | gpg --dearmor -o /etc/apt/keyrings/ngrok-archive-keyring.gpg \\
342
- && chmod go+r /etc/apt/keyrings/ngrok-archive-keyring.gpg \\
343
- && echo "deb [signed-by=/etc/apt/keyrings/ngrok-archive-keyring.gpg] https://ngrok-agent.s3.amazonaws.com buster main" \\
344
- > /etc/apt/sources.list.d/ngrok.list \\
345
340
  && apt-get update \\
346
- && apt-get install -y --no-install-recommends gh ngrok
341
+ && apt-get install -y --no-install-recommends gh
347
342
 
348
343
  RUN --mount=type=cache,target=/root/.npm \\
349
344
  npm install -g @anthropic-ai/claude-code @openai/codex
@@ -427,13 +422,8 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \\
427
422
  && chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg \\
428
423
  && echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" \\
429
424
  > /etc/apt/sources.list.d/github-cli.list \\
430
- && curl -fsSL https://ngrok-agent.s3.amazonaws.com/ngrok.asc \\
431
- | gpg --dearmor -o /etc/apt/keyrings/ngrok-archive-keyring.gpg \\
432
- && chmod go+r /etc/apt/keyrings/ngrok-archive-keyring.gpg \\
433
- && echo "deb [signed-by=/etc/apt/keyrings/ngrok-archive-keyring.gpg] https://ngrok-agent.s3.amazonaws.com buster main" \\
434
- > /etc/apt/sources.list.d/ngrok.list \\
435
425
  && apt-get update \\
436
- && apt-get install -y --no-install-recommends gh ngrok
426
+ && apt-get install -y --no-install-recommends gh
437
427
 
438
428
  ARG WAKE_VERSION=0.1.0
439
429
  RUN --mount=type=cache,target=/root/.npm \\
@@ -108,4 +108,4 @@ export function resolveWakeVersion(options = {}) {
108
108
  return `g${headHash.slice(0, 7)}`;
109
109
  return '0.1.0-dev';
110
110
  }
111
- export const wakeVersion = "g1e8b76d";
111
+ export const wakeVersion = "g869d6b3";
@@ -87,7 +87,10 @@ export async function runDispatchLoop(pending, ctx) {
87
87
  workflowInstanceId: selected.workflow.workflowInstanceId,
88
88
  orchestrationGroupId: selected.workflow.orchestrationGroupId,
89
89
  resources: resourceViews,
90
- sessionPolicy: selected.workflow.parentWorkflowInstanceId === undefined ? 'resume-stage' : 'fresh',
90
+ sessionPolicy: selected.activation.sessionPolicy === 'fresh' ||
91
+ selected.workflow.parentWorkflowInstanceId !== undefined
92
+ ? 'fresh'
93
+ : 'resume-stage',
91
94
  awaitImmediateCompletion: true,
92
95
  ...(ineligible.size === 0 ? {} : { ineligibleRunners: ineligible }),
93
96
  });
@@ -20,6 +20,8 @@ export function recognizedCommand(body) {
20
20
  return GitHubBuiltInCommand.Changes;
21
21
  if (matchesCommand(line, GitHubBuiltInCommand.Retry))
22
22
  return GitHubBuiltInCommand.Retry;
23
+ if (matchesCommand(line, GitHubBuiltInCommand.Restart))
24
+ return GitHubBuiltInCommand.Restart;
23
25
  if (line === GitHubBuiltInCommand.Extend)
24
26
  return GitHubBuiltInCommand.Extend;
25
27
  return null;
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable max-lines */
2
2
  import { ActivityOutcomeKind, ReviewActorKind, ReviewDecisionKind, ReviewerAuthorizationSource, createPullRequestService, isReviewAuthorized, } from '../../../activities/index.js';
3
- import { ApprovalAuthorityKind, isGroupBudgetExtensionEligible, selectOperatorRetryTarget, } from '../../../orchestration/index.js';
3
+ import { ApprovalAuthorityKind, isGroupBudgetExtensionEligible, isOperatorRetryEligible, selectOperatorRetryTarget, } from '../../../orchestration/index.js';
4
4
  import { BuiltInResourceKind, ResourceCorrelationRole, ResourceStreamKind, resourceId, } from '../../../resources/index.js';
5
5
  import { WorkStatus } from '../../../work/index.js';
6
6
  import { GitHubBuiltInCommand, UnknownGitHubIdentity } from '../contracts/vocabulary.js';
@@ -121,6 +121,8 @@ async function applyIssueCommand(input) {
121
121
  const { command, resource, resourceId: resourceIdValue } = input;
122
122
  if (command === GitHubBuiltInCommand.Retry)
123
123
  return applyIssueRetrySignal({ ...input, resourceId: resourceIdValue });
124
+ if (command === GitHubBuiltInCommand.Restart)
125
+ return applyIssueRestartSignal({ ...input, resourceId: resourceIdValue });
124
126
  if (command === GitHubBuiltInCommand.Extend)
125
127
  return applyIssueBudgetExtension({ ...input, resourceId: resourceIdValue });
126
128
  if (resource?.kind === BuiltInResourceKind.PullRequest)
@@ -184,6 +186,29 @@ async function applyIssueRetrySignal(input) {
184
186
  await ignoreIneligibleOperatorRetry(() => orchestration.retryBlockedFailedStage(target.workflowInstanceId, commandContext(event)));
185
187
  }
186
188
  }
189
+ async function applyIssueRestartSignal(input) {
190
+ const { event, resources, work, orchestration, resourceId: resourceIdValue } = input;
191
+ if (orchestration === undefined)
192
+ return;
193
+ if (!isReviewAuthorized({
194
+ actorId: event.payload.actor.id,
195
+ actorKind: event.payload.actor.kind,
196
+ resourceAuthorId: UnknownGitHubIdentity,
197
+ authorization: event.payload.authorization ?? { source: ReviewerAuthorizationSource.None },
198
+ }))
199
+ return;
200
+ const workItemIds = (await resources.correlations(resourceIdValue))
201
+ .filter((correlation) => correlation.role === ResourceCorrelationRole.Primary)
202
+ .map((correlation) => correlation.workItemId);
203
+ for (const workItemId of workItemIds) {
204
+ if (!(await isEligibleWorkItem(work, workItemId)))
205
+ continue;
206
+ const primary = (await orchestration.listForWorkItem(workItemId)).find((workflow) => workflow.parentWorkflowInstanceId === undefined);
207
+ if (primary === undefined || !isOperatorRetryEligible(primary))
208
+ continue;
209
+ await ignoreIneligibleOperatorRetry(() => orchestration.restartBlockedFailedStage(primary.workflowInstanceId, commandContext(event)));
210
+ }
211
+ }
187
212
  async function applyIssueApprovalSignal(input) {
188
213
  const { event, command, resources, work, lookup, orchestration, adapter } = input;
189
214
  if (resources === undefined || lookup === undefined || orchestration === undefined)
@@ -57,7 +57,8 @@ export const GitHubOutboundAction = {
57
57
  // Comment-channel commands the GitHub adapter recognizes from human replies.
58
58
  // /approved and /changes drive issue-review and PR-issue-comment signals;
59
59
  // /accepted and /changes drive formal (native) PR review comments; /retry
60
- // resumes a blocked/failed stage; /extend grants one exhausted gate attempt.
60
+ // resumes a blocked/failed stage; /restart starts it in a fresh runner session;
61
+ // /extend grants one exhausted gate attempt.
61
62
  // Kept as the single source of truth for both
62
63
  // recognition (inbound-comment-syntax.ts, review-command-translator.ts) and
63
64
  // the commands/instructions surface, so the two cannot drift.
@@ -66,5 +67,6 @@ export const GitHubBuiltInCommand = defineClosedVocabulary({
66
67
  Accepted: '/accepted',
67
68
  Changes: '/changes',
68
69
  Retry: '/retry',
70
+ Restart: '/restart',
69
71
  Extend: '/extend',
70
72
  });
@@ -70,7 +70,8 @@ async function issueCommentEventsForComment(context, issue, comment) {
70
70
  return event === null ? [] : [event];
71
71
  }
72
72
  async function retryAuthorization(context, comment) {
73
- if (comment.body?.trim().toLowerCase() !== GitHubBuiltInCommand.Retry)
73
+ const command = comment.body?.trim().toLowerCase();
74
+ if (command !== GitHubBuiltInCommand.Retry && command !== GitHubBuiltInCommand.Restart)
74
75
  return undefined;
75
76
  const login = comment.user?.login;
76
77
  if (login === undefined || context.client.collaboratorPermission === undefined)
@@ -3,7 +3,7 @@ import { OrchestrationEventType } from '../contracts/events.js';
3
3
  import { commandName, workflowInstanceId, } from '../contracts/identifiers.js';
4
4
  import { workflowInstanceStream } from '../contracts/streams.js';
5
5
  import { WorkflowStatus } from '../contracts/vocabulary.js';
6
- import { requestChangesResume as decideChangesResume, requestOperatorRetry as decideOperatorRetry, requestSupplementalActivity as decideSupplementalActivity, requestRunnerQuotaRetry, } from '../domain/interpreter.js';
6
+ import { requestChangesResume as decideChangesResume, requestFreshOperatorRetry as decideFreshOperatorRetry, requestOperatorRetry as decideOperatorRetry, requestSupplementalActivity as decideSupplementalActivity, requestRunnerQuotaRetry, } from '../domain/interpreter.js';
7
7
  import { isAuthorisedActor } from '../domain/supplemental-policy.js';
8
8
  import { appendWithIntentRecovery } from './durable-append.js';
9
9
  import { acceptResourceTransition, matchResourceTransitions, } from './resource-transition-matching.js';
@@ -136,6 +136,12 @@ export class AdvanceWorkflow {
136
136
  return (await this.repository.load(id)).view;
137
137
  }
138
138
  async retryBlockedFailedStage(id, context) {
139
+ return this.retryBlockedFailedStageWith(id, context, decideOperatorRetry);
140
+ }
141
+ async restartBlockedFailedStage(id, context) {
142
+ return this.retryBlockedFailedStageWith(id, context, decideFreshOperatorRetry);
143
+ }
144
+ async retryBlockedFailedStageWith(id, context, decide) {
139
145
  const loaded = await this.repository.load(id);
140
146
  if (loaded.view === null)
141
147
  throw new OperatorRetryIneligibleError('WorkflowInstance does not exist');
@@ -144,7 +150,7 @@ export class AdvanceWorkflow {
144
150
  const definition = await this.workflows.definitionForOperation(loaded.view, loaded.sequence, context);
145
151
  if (definition === null)
146
152
  return (await this.repository.loadRequired(id)).view;
147
- const decision = decideOperatorRetry(definition, loaded.view, {
153
+ const decision = decide(definition, loaded.view, {
148
154
  commandId: context.commandId,
149
155
  occurredAt: context.occurredAt,
150
156
  causationId: context.commandId,
@@ -84,6 +84,9 @@ export class OrchestrationService {
84
84
  retryBlockedFailedStage(workflowInstanceId, context) {
85
85
  return this.transitionWatchChildren(context, () => this.advanceWorkflow.retryBlockedFailedStage(workflowInstanceId, context));
86
86
  }
87
+ restartBlockedFailedStage(workflowInstanceId, context) {
88
+ return this.transitionWatchChildren(context, () => this.advanceWorkflow.restartBlockedFailedStage(workflowInstanceId, context));
89
+ }
87
90
  resumeBlockedStageForChanges(workflowInstanceId, context) {
88
91
  return this.transitionWatchChildren(context, () => this.advanceWorkflow.resumeBlockedStageForChanges(workflowInstanceId, context));
89
92
  }
@@ -15,6 +15,7 @@ export function activation(id, ordinal, activity, input, options) {
15
15
  ...(options.stage === undefined ? {} : { stage: options.stage }),
16
16
  input,
17
17
  execution: options.execution,
18
+ ...(options.sessionPolicy === undefined ? {} : { sessionPolicy: options.sessionPolicy }),
18
19
  ...(options.followOnIndex === undefined ? {} : { followOnIndex: options.followOnIndex }),
19
20
  ...(options.supplemental === true ? { supplemental: true } : {}),
20
21
  };
@@ -10,7 +10,7 @@ import { finishRoute } from './transition.js';
10
10
  export { startInstance } from './activation-policy.js';
11
11
  export { acceptSignal, waitForSignal } from './signal-policy.js';
12
12
  export { requestSupplementalActivity } from './supplemental-policy.js';
13
- export { isChangesResumeEligible, isGroupBudgetExtensionEligible, isOperatorRetryEligible, requestChangesResume, requestOperatorRetry, selectOperatorRetryTarget, } from './operator-retry-policy.js';
13
+ export { isChangesResumeEligible, isGroupBudgetExtensionEligible, isOperatorRetryEligible, requestChangesResume, requestFreshOperatorRetry, requestOperatorRetry, selectOperatorRetryTarget, } from './operator-retry-policy.js';
14
14
  export { isRunnerQuotaRetryEligible, requestRunnerQuotaRetry, } from './runner-quota-retry-policy.js';
15
15
  export function acceptActivityOutcome(definition, state, input) {
16
16
  if (!isPendingOutcome(state, input))
@@ -69,6 +69,13 @@ export function isGroupBudgetExtensionEligible(view) {
69
69
  view.waitingFor !== undefined);
70
70
  }
71
71
  export function requestOperatorRetry(definition, state, input) {
72
+ return requestRetry(definition, state, input);
73
+ }
74
+ /** Re-requests the failed stage while requiring a new runner session. */
75
+ export function requestFreshOperatorRetry(definition, state, input) {
76
+ return requestRetry(definition, state, input, 'fresh');
77
+ }
78
+ function requestRetry(definition, state, input, sessionPolicy) {
72
79
  if (input.commandId.length === 0)
73
80
  return { kind: 'ignored', reason: 'operator retry command id is required' };
74
81
  if (!isOperatorRetryEligible(state))
@@ -82,6 +89,7 @@ export function requestOperatorRetry(definition, state, input) {
82
89
  stateDraft(state, input, OrchestrationEventType.ActivityRequested, activation(state.workflowInstanceId, nextOrdinal(state), stage.activity, stage.with, {
83
90
  execution: stage.execution,
84
91
  stage: stageName(state.currentStage),
92
+ ...(sessionPolicy === undefined ? {} : { sessionPolicy }),
85
93
  }), 2),
86
94
  ];
87
95
  return { kind: 'append', events };
@@ -203,6 +203,7 @@ function applyActivityRequested(state, payload) {
203
203
  ...(payload.stage === undefined ? {} : { stage: payload.stage }),
204
204
  input: payload.input,
205
205
  execution: payload.execution,
206
+ ...(payload.sessionPolicy === undefined ? {} : { sessionPolicy: payload.sessionPolicy }),
206
207
  status: ActivityActivationStatus.Pending,
207
208
  ...(payload.followOnIndex === undefined ? {} : { followOnIndex: payload.followOnIndex }),
208
209
  ...(payload.supplemental === true ? { supplemental: true } : {}),
package/docker/Dockerfile CHANGED
@@ -11,13 +11,8 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
11
11
  && chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg \
12
12
  && echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" \
13
13
  > /etc/apt/sources.list.d/github-cli.list \
14
- && curl -fsSL https://ngrok-agent.s3.amazonaws.com/ngrok.asc \
15
- | gpg --dearmor -o /etc/apt/keyrings/ngrok-archive-keyring.gpg \
16
- && chmod go+r /etc/apt/keyrings/ngrok-archive-keyring.gpg \
17
- && echo "deb [signed-by=/etc/apt/keyrings/ngrok-archive-keyring.gpg] https://ngrok-agent.s3.amazonaws.com buster main" \
18
- > /etc/apt/sources.list.d/ngrok.list \
19
14
  && apt-get update \
20
- && apt-get install -y --no-install-recommends gh ngrok
15
+ && apt-get install -y --no-install-recommends gh
21
16
 
22
17
  RUN --mount=type=cache,target=/root/.npm \
23
18
  npm install -g @anthropic-ai/claude-code @openai/codex
@@ -11,13 +11,8 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
11
11
  && chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg \
12
12
  && echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" \
13
13
  > /etc/apt/sources.list.d/github-cli.list \
14
- && curl -fsSL https://ngrok-agent.s3.amazonaws.com/ngrok.asc \
15
- | gpg --dearmor -o /etc/apt/keyrings/ngrok-archive-keyring.gpg \
16
- && chmod go+r /etc/apt/keyrings/ngrok-archive-keyring.gpg \
17
- && echo "deb [signed-by=/etc/apt/keyrings/ngrok-archive-keyring.gpg] https://ngrok-agent.s3.amazonaws.com buster main" \
18
- > /etc/apt/sources.list.d/ngrok.list \
19
14
  && apt-get update \
20
- && apt-get install -y --no-install-recommends gh ngrok
15
+ && apt-get install -y --no-install-recommends gh
21
16
 
22
17
  ARG WAKE_VERSION
23
18
  RUN test -n "$WAKE_VERSION" || (echo "WAKE_VERSION build arg is required" && exit 1)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atolis-hq/wake",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Local autonomous agent control plane for software development",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -1,90 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -uo pipefail
3
-
4
- mkdir -p /wake/logs
5
-
6
- write_ngrok_public_url() {
7
- local output_file="/wake/control-plane-ui-url"
8
-
9
- rm -f "${output_file}"
10
- for _ in $(seq 1 30); do
11
- local public_url
12
- public_url="$(
13
- node -e '
14
- const http = require("node:http");
15
- const req = http.get("http://127.0.0.1:4040/api/tunnels", (res) => {
16
- let body = "";
17
- res.setEncoding("utf8");
18
- res.on("data", (chunk) => { body += chunk; });
19
- res.on("end", () => {
20
- try {
21
- const tunnels = JSON.parse(body).tunnels ?? [];
22
- const tunnel = tunnels.find((entry) => typeof entry.public_url === "string" && entry.public_url.startsWith("https://"))
23
- ?? tunnels.find((entry) => typeof entry.public_url === "string");
24
- if (tunnel !== undefined) {
25
- process.stdout.write(tunnel.public_url);
26
- }
27
- } catch {}
28
- });
29
- });
30
- req.on("error", () => {});
31
- req.setTimeout(1000, () => req.destroy());
32
- ' || true
33
- )"
34
-
35
- if [ -n "${public_url}" ]; then
36
- printf '%s\n' "${public_url}" > "${output_file}"
37
- echo "wake ui: ngrok tunnel available at ${public_url}"
38
- return 0
39
- fi
40
-
41
- sleep 1
42
- done
43
-
44
- echo "wake ui: ngrok tunnel started but public URL was not discovered; see /wake/logs/ngrok.log"
45
- }
46
-
47
- supervise_wake_start() {
48
- local restart_delay="${WAKE_START_RESTART_DELAY_SECONDS:-10}"
49
-
50
- while true; do
51
- echo "wake start: starting resident loop"
52
- node /app/dist/src/main.js start \
53
- --wake-root /wake \
54
- >> /wake/logs/start.log 2>&1 &
55
-
56
- local child_pid="$!"
57
- echo "${child_pid}" > /wake/logs/start.pid
58
-
59
- wait "${child_pid}"
60
- local exit_code="$?"
61
- echo "wake start: resident loop exited with status ${exit_code}; restarting in ${restart_delay}s"
62
- sleep "${restart_delay}"
63
- done
64
- }
65
-
66
- if [ "${WAKE_UI_ENABLED:-false}" = "true" ]; then
67
- echo "wake ui: starting on 0.0.0.0:${WAKE_UI_PORT:-4317}"
68
- node /app/dist/src/main.js ui \
69
- --wake-root /wake \
70
- --host 0.0.0.0 \
71
- --port "${WAKE_UI_PORT:-4317}" \
72
- ${WAKE_UI_TOKEN:+--token "${WAKE_UI_TOKEN}"} \
73
- >> /wake/logs/ui.log 2>&1 &
74
-
75
- if [ "${WAKE_UI_TUNNEL_ENABLED:-false}" = "true" ]; then
76
- if [ -n "${NGROK_AUTHTOKEN:-}" ]; then
77
- ngrok config add-authtoken "${NGROK_AUTHTOKEN}" >> /wake/logs/ngrok.log 2>&1
78
- fi
79
-
80
- echo "wake ui: starting ngrok tunnel for 127.0.0.1:${WAKE_UI_PORT:-4317}"
81
- ngrok http "127.0.0.1:${WAKE_UI_PORT:-4317}" --log=stdout >> /wake/logs/ngrok.log 2>&1 &
82
- write_ngrok_public_url &
83
- fi
84
- fi
85
-
86
- if [ "${WAKE_START_ENABLED:-false}" = "true" ]; then
87
- supervise_wake_start &
88
- fi
89
-
90
- exec sleep infinity