@signalridge/pi-workflows 1.3.2 → 1.5.0

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/src/ui.ts CHANGED
@@ -172,12 +172,30 @@ async function selectList<T>(
172
172
  }
173
173
 
174
174
  /** Interactive `/workflows` navigator. TUI-only by design. */
175
- export async function showWorkflowNavigator(ctx: ExtensionCommandContext, engine: WorkflowEngine): Promise<void> {
175
+ export async function showWorkflowNavigator(
176
+ ctx: ExtensionCommandContext,
177
+ engineSource: WorkflowEngine | (() => WorkflowEngine),
178
+ ): Promise<void> {
176
179
  if (ctx.mode !== "tui") {
177
180
  ctx.ui.notify("/workflows requires TUI mode; use workflow_control for machine-readable access.", "warning");
178
181
  return;
179
182
  }
183
+ const resolveEngine = typeof engineSource === "function" ? engineSource : () => engineSource;
184
+ let inactiveNotified = false;
185
+ const currentEngine = (): WorkflowEngine | undefined => {
186
+ try {
187
+ return resolveEngine();
188
+ } catch (error: unknown) {
189
+ if (!inactiveNotified) {
190
+ inactiveNotified = true;
191
+ ctx.ui.notify(error instanceof Error ? error.message : String(error), "warning");
192
+ }
193
+ return undefined;
194
+ }
195
+ };
180
196
  while (true) {
197
+ const engine = currentEngine();
198
+ if (!engine) return;
181
199
  const states = engine
182
200
  .list()
183
201
  .map((summary) => engine.getRun(String(summary.runId)))
@@ -198,7 +216,9 @@ export async function showWorkflowNavigator(ctx: ExtensionCommandContext, engine
198
216
  );
199
217
  if (!selected) return;
200
218
  while (true) {
201
- const run = engine.getRun(selected);
219
+ const latest = currentEngine();
220
+ if (!latest) return;
221
+ const run = latest.getRun(selected);
202
222
  if (!run) break;
203
223
  const name = sanitizeDisplayText(run.meta.name, MAX_NAME_CHARS);
204
224
  const action = await selectList<WorkflowAction>(
@@ -208,7 +228,10 @@ export async function showWorkflowNavigator(ctx: ExtensionCommandContext, engine
208
228
  value: item.value,
209
229
  label: item.label,
210
230
  })),
211
- () => formatWorkflowDetail(engine, selected),
231
+ () => {
232
+ const current = currentEngine();
233
+ return current ? formatWorkflowDetail(current, selected) : "Workflow surface is no longer active.";
234
+ },
212
235
  );
213
236
  if (action === undefined || action === "back") break;
214
237
  if (action === "refresh") continue;
@@ -217,7 +240,9 @@ export async function showWorkflowNavigator(ctx: ExtensionCommandContext, engine
217
240
  if (!confirmed) continue;
218
241
  }
219
242
  try {
220
- await engine.control(action, selected);
243
+ const current = currentEngine();
244
+ if (!current) return;
245
+ await current.control(action, selected);
221
246
  ctx.ui.notify(`Workflow ${action} requested.`, "info");
222
247
  } catch (error: unknown) {
223
248
  ctx.ui.notify(error instanceof Error ? error.message : String(error), "error");