@atolis-hq/wake 0.3.114 → 0.3.115

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.
@@ -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 = "gff9150c";
111
+ export const wakeVersion = "g67783ec";
@@ -1,3 +1,13 @@
1
+ export function isTerminalWaitOutput(value) {
2
+ if (!Array.isArray(value) || value.length !== 2)
3
+ return false;
4
+ const initialOutput = record(value[0]);
5
+ const finalOutput = record(value[1]);
6
+ return (initialOutput?.type === 'input_text' &&
7
+ typeof initialOutput.text === 'string' &&
8
+ finalOutput?.type === 'input_text' &&
9
+ finalOutput.text === '');
10
+ }
1
11
  export function structuredResult(value) {
2
12
  return outputTexts(value).reduce(mergeResult, {});
3
13
  }
@@ -1,7 +1,7 @@
1
1
  import { readFile, readdir } from 'node:fs/promises';
2
2
  import { join } from 'node:path';
3
3
  import { pathToFileURL } from 'node:url';
4
- import { structuredResult, writeStdinSessionArgument, } from './codex-stop-hook-protocol.js';
4
+ import { isTerminalWaitOutput, structuredResult, writeStdinSessionArgument, } from './codex-stop-hook-protocol.js';
5
5
  export const unverifiedCodexCompletionReason = 'unverified: could not confirm background command completion from Codex structured telemetry';
6
6
  /**
7
7
  * Bound on how long this hook will keep forcing continuation for the same
@@ -175,7 +175,7 @@ function recordToolOutput(payload, telemetry) {
175
175
  const result = structuredResult(payload.output);
176
176
  if (call.name === 'exec')
177
177
  return recordExecOutput(call, result, telemetry);
178
- recordWaitOutput(call, result, telemetry);
178
+ recordWaitOutput(call, result, payload.output, telemetry);
179
179
  }
180
180
  function recordExecOutput(call, result, telemetry) {
181
181
  if (call.spawnsBackgroundJob === true && result.exitCode === undefined && result.pendingCellId)
@@ -192,13 +192,15 @@ function resolveSession(sessionId, telemetry) {
192
192
  telemetry.resolvedCells.add(cellId);
193
193
  }
194
194
  }
195
- function recordWaitOutput(call, result, telemetry) {
195
+ function recordWaitOutput(call, result, output, telemetry) {
196
196
  if (call.cellId === undefined)
197
197
  return;
198
- if (result.exitCode !== undefined) {
198
+ const nativeTerminal = result.sessionId === undefined && isTerminalWaitOutput(output);
199
+ const terminal = result.exitCode !== undefined || nativeTerminal;
200
+ if (terminal) {
199
201
  telemetry.resolvedCells.add(call.cellId);
200
202
  const sessionId = telemetry.sessionsByCell.get(call.cellId);
201
- if (sessionId !== undefined && result.jsonExitCode !== undefined)
203
+ if (sessionId !== undefined && (result.jsonExitCode !== undefined || nativeTerminal))
202
204
  resolveSession(sessionId, telemetry);
203
205
  }
204
206
  if (result.sessionId !== undefined)
@@ -98,6 +98,7 @@ const transitionTargetSchema = z.discriminatedUnion('kind', [
98
98
  signal: brandedStringSchema(signalName),
99
99
  })
100
100
  .strict(),
101
+ z.object({ kind: z.literal(TransitionTargetKind.ResourceTransitionWait) }).strict(),
101
102
  ]);
102
103
  const resourceTransitionSchema = z
103
104
  .object({
@@ -3,6 +3,7 @@ export const TransitionTargetKind = defineClosedVocabulary({
3
3
  Stage: 'stage',
4
4
  Complete: 'complete',
5
5
  AwaitSignal: 'await-signal',
6
+ ResourceTransitionWait: 'resource-transition-wait',
6
7
  });
7
8
  export const WorkflowStatus = defineClosedVocabulary({
8
9
  Active: 'active',
@@ -10,7 +10,7 @@ export function compileWorkflow(name, input, activities, knownWorkflowNames = [n
10
10
  const config = workflowDefinitionConfigSchema.parse(input);
11
11
  const rawStageNames = Object.keys(config.stages);
12
12
  for (const candidate of rawStageNames) {
13
- if (isReservedTerminal(candidate))
13
+ if (isReservedRouteTarget(candidate))
14
14
  throw new Error(`Reserved stage name: ${candidate}`);
15
15
  }
16
16
  const stageNames = rawStageNames.map(stageName);
@@ -84,12 +84,18 @@ function compileStage(context, rawStageName, stage, allStages) {
84
84
  ([outcomeKind, route]) => {
85
85
  if (!definition.outcomeKinds.includes(outcomeKind))
86
86
  throw new Error(`Workflow outcome route ${outcomeKind} is not declared by Activity ${definition.name}`);
87
- if (!isReservedTerminal(route.then) && !(route.then in allStages))
87
+ if (!isReservedRouteTarget(route.then) && !(route.then in allStages))
88
88
  throw new Error(`Unknown transition target: ${route.then}`);
89
89
  if (route.await !== undefined && route.watchGates !== undefined)
90
90
  throw new Error(`Route ${compiledWorkflowName}:${rawStageName}:${outcomeKind} cannot configure both await and watchGates`);
91
91
  if (route.resourceTransitions !== undefined && outcomeKind !== ActivityOutcomeKind.Done)
92
92
  throw new Error(`Route ${compiledWorkflowName}:${rawStageName}:${outcomeKind} resourceTransitions are only valid on done`);
93
+ if (route.then === 'wait' && outcomeKind !== ActivityOutcomeKind.Done)
94
+ throw new Error('then: wait is only valid on done');
95
+ if (route.then === 'wait' && route.resourceTransitions === undefined)
96
+ throw new Error('then: wait requires resourceTransitions');
97
+ if (route.then === 'wait' && (route.await !== undefined || route.watchGates !== undefined))
98
+ throw new Error('then: wait cannot configure await or watchGates');
93
99
  const followOns = route.activities?.map((activity) => ({
94
100
  use: activityName(activity.use),
95
101
  with: activities.validateInput(activityName(activity.use), activity.with),
@@ -115,7 +121,11 @@ function compileStage(context, rawStageName, stage, allStages) {
115
121
  ...(route.resourceTransitions === undefined
116
122
  ? {}
117
123
  : {
118
- resourceTransitions: compileResourceTransitions(route.resourceTransitions, route.then, outcomeKind, allStages, isReservedTerminal, compileTarget),
124
+ resourceTransitions: compileResourceTransitions(route.resourceTransitions, {
125
+ inheritedThen: route.then,
126
+ outcomeKind,
127
+ requiresExplicitTarget: route.then === 'wait',
128
+ }, allStages, isReservedRouteTarget, compileTarget),
119
129
  }),
120
130
  id: `${compiledWorkflowName}:${rawStageName}:${outcomeKind}`,
121
131
  });
@@ -136,7 +146,7 @@ function compileWatchGates(workflow, rawStageName, outcomeKind, entries, declare
136
146
  if (!declaredWatchIds.has(normalized.watch))
137
147
  throw new Error(`Unknown watch reference in workflow "${workflow}" stage "${rawStageName}": "${normalized.watch}"`);
138
148
  const onRejectThen = normalized.onReject?.then ?? rawStageName;
139
- if (!isReservedTerminal(onRejectThen) && !(onRejectThen in allStages))
149
+ if (!isReservedTerminalTarget(onRejectThen) && !(onRejectThen in allStages))
140
150
  throw new Error(`Unknown watchGates onReject target: ${onRejectThen}`);
141
151
  return Object.freeze({
142
152
  watch: watchId(normalized.watch),
@@ -170,11 +180,14 @@ function compileCommands(config, activities) {
170
180
  }),
171
181
  ]));
172
182
  }
173
- const isReservedTerminal = (target) => target === ActivityOutcomeKind.Done || target === 'await-human';
183
+ const isReservedRouteTarget = (target) => target === ActivityOutcomeKind.Done || target === 'await-human' || target === 'wait';
184
+ const isReservedTerminalTarget = (target) => target === ActivityOutcomeKind.Done || target === 'await-human';
174
185
  function compileTarget(target, outcomeKind) {
175
186
  if (target === ActivityOutcomeKind.Done)
176
187
  return { kind: TransitionTargetKind.Complete };
177
188
  if (target === 'await-human')
178
189
  return { kind: TransitionTargetKind.AwaitSignal, signal: signalName(outcomeKind) };
190
+ if (target === 'wait')
191
+ return { kind: TransitionTargetKind.ResourceTransitionWait };
179
192
  return { kind: TransitionTargetKind.Stage, stage: stageName(target) };
180
193
  }
@@ -1,12 +1,16 @@
1
- export function compileResourceTransitions(entries, inheritedThen, outcomeKind, allStages, isReservedTerminal, compileTarget) {
1
+ export function compileResourceTransitions(entries, context, allStages, isReservedTarget, compileTarget) {
2
2
  return Object.freeze(entries.map((entry) => {
3
- const then = entry.then ?? inheritedThen;
4
- if (!isReservedTerminal(then) && !(then in allStages))
3
+ const then = entry.then ?? context.inheritedThen;
4
+ if (context.requiresExplicitTarget && entry.then === undefined)
5
+ throw new Error('resourceTransitions under then: wait require then');
6
+ if (then === 'wait')
7
+ throw new Error('resourceTransitions cannot target wait');
8
+ if (!isReservedTarget(then) && !(then in allStages))
5
9
  throw new Error(`Unknown resourceTransitions target: ${then}`);
6
10
  return Object.freeze({
7
11
  event: entry.events[0],
8
12
  ...(!('where' in entry) || entry.where === undefined ? {} : { where: entry.where }),
9
- target: compileTarget(then, outcomeKind),
13
+ target: compileTarget(then, context.outcomeKind),
10
14
  });
11
15
  }));
12
16
  }
@@ -65,5 +65,7 @@ export function resumeToTarget(events, definition, state, input, target) {
65
65
  events.push(stateDraft(state, input, OrchestrationEventType.SignalWaitStarted, { signalKind: target.signal }, events.length + 1));
66
66
  return;
67
67
  }
68
+ if (target.kind === TransitionTargetKind.ResourceTransitionWait)
69
+ throw new Error('resource-transition wait must be resumed by a resource transition');
68
70
  pushStageEntry(events, definition, state, input, target.stage);
69
71
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atolis-hq/wake",
3
- "version": "0.3.114",
3
+ "version": "0.3.115",
4
4
  "description": "Local autonomous agent control plane for software development",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {