@mjasnikovs/pi-task 0.2.2 → 0.2.3

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.
@@ -175,6 +175,7 @@ function defaultDeps(ctx, cwd, signal, title) {
175
175
  }
176
176
  // ─── Loop ────────────────────────────────────────────────────────────────────
177
177
  let cancelRequested = false;
178
+ let autoRunning = false;
178
179
  export function requestAutoCancel() {
179
180
  cancelRequested = true;
180
181
  }
@@ -242,6 +243,7 @@ async function handleTaskAuto(args, ctx) {
242
243
  ctx.ui.notify('Describe the feature after /task-auto (use @ for file completion).', 'info');
243
244
  return;
244
245
  }
246
+ autoRunning = true;
245
247
  const abort = new AbortController();
246
248
  const deps = defaultDeps(ctx, cwd, abort.signal, deriveTitle(raw));
247
249
  let id;
@@ -249,6 +251,7 @@ async function handleTaskAuto(args, ctx) {
249
251
  id = await planAuto(ctx, cwd, raw, deps);
250
252
  }
251
253
  catch (err) {
254
+ autoRunning = false;
252
255
  const msg = err instanceof Error ? err.message : String(err);
253
256
  if (msg === USER_CANCELLED) {
254
257
  ctx.ui.notify('/task-auto cancelled.', 'warning');
@@ -257,9 +260,20 @@ async function handleTaskAuto(args, ctx) {
257
260
  ctx.ui.notify(`/task-auto planning failed: ${msg}`, 'error');
258
261
  return;
259
262
  }
260
- if (!id)
263
+ if (!id) {
264
+ autoRunning = false;
265
+ return;
266
+ }
267
+ // Check for a cancel that was requested during the planning phase before the
268
+ // loop resets the flag.
269
+ if (cancelRequested) {
270
+ cancelRequested = false;
271
+ autoRunning = false;
272
+ ctx.ui.notify('/task-auto cancelled.', 'warning');
261
273
  return;
274
+ }
262
275
  await runAutoLoop(ctx, cwd, id, deps);
276
+ autoRunning = false;
263
277
  }
264
278
  async function handleTaskAutoResume(_args, ctx) {
265
279
  await ctx.waitForIdle();
@@ -271,13 +285,19 @@ async function handleTaskAutoResume(_args, ctx) {
271
285
  }
272
286
  ctx.ui.notify(`Resuming ${id}…`, 'info');
273
287
  await updateTaskFrontMatter(cwd, id, { state: 'in_progress' });
288
+ autoRunning = true;
274
289
  const abort = new AbortController();
275
290
  // Resume only runs the loop (runTask); no planning children, so the loader
276
291
  // title is unused here — pass the id for clarity if that ever changes.
277
292
  await runAutoLoop(ctx, cwd, id, defaultDeps(ctx, cwd, abort.signal, id));
293
+ autoRunning = false;
278
294
  }
279
295
  // eslint-disable-next-line @typescript-eslint/require-await
280
296
  async function handleTaskAutoCancel(_args, ctx) {
297
+ if (!autoRunning) {
298
+ ctx.ui.notify('No /task-auto loop is running.', 'info');
299
+ return;
300
+ }
281
301
  requestAutoCancel();
282
302
  ctx.ui.notify('Stopping /task-auto after the current task…', 'warning');
283
303
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mjasnikovs/pi-task",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Deterministic spec-orchestration for local models, with bundled web/docs/fetch/worker subagent tools.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",