inplan 0.2.1 → 0.2.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.
package/bin/cli.js CHANGED
@@ -2332,6 +2332,7 @@ function wakePredicate(wake) {
2332
2332
  return wake === "any-action" ? (e) => e.actor === "user" && e.type !== LogEventType.SettingsChanged : (e) => e.type === LogEventType.TurnEnded || e.type === LogEventType.SessionClosed || e.type === LogEventType.SaveLocallyRequested || e.type === LogEventType.NavigatedTo;
2333
2333
  }
2334
2334
  var REOPEN_GRACE_MS = 3 * 6e4;
2335
+ var PRESENCE_GONE_GRACE_MS = 9e4;
2335
2336
  async function awaitReopen(channel, cursor, opts = {}) {
2336
2337
  const graceMs = opts.graceMs ?? REOPEN_GRACE_MS;
2337
2338
  const pollMs = opts.pollMs ?? 2e3;
@@ -2385,6 +2386,7 @@ function waitForActions(opts) {
2385
2386
  const pollMs = opts.pollMs ?? 200;
2386
2387
  const isActionable = opts.isActionable ?? defaultActionable;
2387
2388
  const watchEditor = opts.watchEditor ?? true;
2389
+ const presenceGoneGraceMs = opts.presenceGoneGraceMs ?? PRESENCE_GONE_GRACE_MS;
2388
2390
  const errorGraceMs = opts.errorGraceMs ?? DEFAULT_ERROR_GRACE_MS;
2389
2391
  const pollTimeoutMs = opts.pollTimeoutMs ?? DEFAULT_POLL_TIMEOUT_MS;
2390
2392
  const now = opts.now ?? Date.now;
@@ -2393,6 +2395,7 @@ function waitForActions(opts) {
2393
2395
  let deadline = null;
2394
2396
  let lastCount = -1;
2395
2397
  let sawEditorAlive = false;
2398
+ let goneSince = null;
2396
2399
  let busy = false;
2397
2400
  let done = false;
2398
2401
  let failingSince = null;
@@ -2442,10 +2445,16 @@ function waitForActions(opts) {
2442
2445
  if (!presences.busy()) alive = await presences.run(() => ch.presence(), pollTimeoutMs);
2443
2446
  } catch {
2444
2447
  }
2445
- if (alive === true) sawEditorAlive = true;
2446
- else if (alive === false && sawEditorAlive) {
2447
- finish({ entries, cursor, editorGone: true });
2448
- return;
2448
+ if (alive === true) {
2449
+ sawEditorAlive = true;
2450
+ goneSince = null;
2451
+ } else if (alive === false && sawEditorAlive) {
2452
+ const at = now();
2453
+ goneSince ??= at;
2454
+ if (at - goneSince >= presenceGoneGraceMs) {
2455
+ finish({ entries, cursor, editorGone: true });
2456
+ return;
2457
+ }
2449
2458
  }
2450
2459
  }
2451
2460
  if (entries.some(isActionable)) {
@@ -2749,6 +2758,12 @@ function logWaitExit(p, reason) {
2749
2758
  } catch {
2750
2759
  }
2751
2760
  }
2761
+ function resolveWaitStatus(input) {
2762
+ if (input.closeReason !== null) return { status: "closed", reason: input.closeReason };
2763
+ if (input.editorGone && !input.hasActionable) return { status: "closed", reason: "crashed_or_killed" };
2764
+ if (input.editorGone) return { status: input.locksEditor ? "your_turn" : "activity", editorGone: true };
2765
+ return { status: input.locksEditor ? "your_turn" : "activity" };
2766
+ }
2752
2767
  async function waitCycle(backend, explicitCursor, confirmed, model, gate = null) {
2753
2768
  const { channel, store } = backend;
2754
2769
  const history = await backend.history();
@@ -2889,17 +2904,12 @@ async function waitCycle(backend, explicitCursor, confirmed, model, gate = null)
2889
2904
  }
2890
2905
  process.stderr.write("inplan: the editor did not come back \u2014 treating the session as closed.\n");
2891
2906
  }
2892
- let status;
2893
- let reason;
2894
- if (closeEntry) {
2895
- status = "closed";
2896
- reason = closeEntry.payload?.reason ?? "completed";
2897
- } else if (result.editorGone) {
2898
- status = "closed";
2899
- reason = "crashed_or_killed";
2900
- } else {
2901
- status = mode.locksEditor ? "your_turn" : "activity";
2902
- }
2907
+ const { status, reason, editorGone } = resolveWaitStatus({
2908
+ closeReason: closeEntry ? closeEntry.payload?.reason ?? "completed" : null,
2909
+ editorGone: result.editorGone === true,
2910
+ hasActionable: result.entries.some(isActionable),
2911
+ locksEditor: mode.locksEditor
2912
+ });
2903
2913
  backend.logExit(`status:${status}${reason ? `/${reason}` : ""}`);
2904
2914
  output({
2905
2915
  status,
@@ -2912,6 +2922,12 @@ async function waitCycle(backend, explicitCursor, confirmed, model, gate = null)
2912
2922
  // when --model was passed), so presence + authorship stay consistent.
2913
2923
  agentAuthor: agentAuthorFor(model),
2914
2924
  ...reason ? { reason } : {},
2925
+ // The human handed the turn back and THEN left. Surfaced because the handoff status
2926
+ // deliberately outranks the departure, and dropping the departure entirely would strand the
2927
+ // agent: a fresh `wait` starts with `sawEditorAlive` false, so an editor that is already gone
2928
+ // never flips it and that wait would block instead of reporting the closure. Act on the
2929
+ // handoff, then stop — do not wait again.
2930
+ ...editorGone ? { editorGone: true } : {},
2915
2931
  // The landing signal for a parked Review-mode edit (#88): pending_review means the push
2916
2932
  // REACHED the store and awaits the human — the canonical is unchanged by design. Absent
2917
2933
  // when the turn applied directly (or made no body change).
@@ -4481,6 +4497,7 @@ export {
4481
4497
  isKnownAgentEnv,
4482
4498
  notesFromHook,
4483
4499
  primeSessionOrFail,
4500
+ resolveWaitStatus,
4484
4501
  scrubAgentEnv,
4485
4502
  shellQuote,
4486
4503
  transcriptTextBlocks,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inplan",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "inplan — a Markdown editor for human ⇄ coding-agent planning. CLI + desktop editor.",
5
5
  "license": "AGPL-3.0-or-later",
6
6
  "repository": {
package/skill/SKILL.md CHANGED
@@ -268,6 +268,13 @@ the plan, then call `wait`.** Do not pass `--cursor` and do not hand-manage it.
268
268
  building what the document specifies (it's no longer a planning doc — act on it).
269
269
  - `window_closed` — they just closed the editor; **stop** and take no further action.
270
270
  - `crashed_or_killed` — the editor vanished with no close log; surface this to the human.
271
+ Only reported once the absence has persisted (a heartbeat that merely stalled — a
272
+ backgrounded tab, a network blip — is not a departure), and never in place of work you
273
+ were waiting for: if the human handed the turn back and *then* left, you get that
274
+ handoff (`your_turn` / `activity`) with **`editorGone: true`** alongside it. Treat that
275
+ flag as the closure: do the work the handoff describes, then **stop**. Do not call `wait`
276
+ again — the editor is already gone, so the next wait has nothing to see it leave and will
277
+ block rather than report it.
271
278
  - `superseded` — a newer `wait` took over this document (only one waiter runs at
272
279
  a time). This one stepped down; **do nothing** — the live waiter is in charge.
273
280
  - `navigated` — the human followed an in-window link to a **different document**;
@@ -302,13 +309,17 @@ the plan, then call `wait`.** Do not pass `--cursor` and do not hand-manage it.
302
309
  inplan wait <name>.plan.md
303
310
 
304
311
  `your_turn` and `activity` are **not** stop conditions — you always loop back
305
- and keep waiting. The **only** thing that ends the loop is `status: closed`.
312
+ and keep waiting. Two things end the loop: `status: closed`, or a handoff that
313
+ also carries `editorGone: true` (the human handed the turn back and then left —
314
+ finish that turn's work, then stop; see `crashed_or_killed` above for why a
315
+ further `wait` would block instead of reporting the closure).
306
316
 
307
317
  6. When you believe the plan is ready, signal it (the human still decides):
308
318
 
309
319
  inplan signal <name>.plan.md --done
310
320
 
311
- Then wait again. Stop only on `status: closed`.
321
+ Then wait again, and stop on the same two conditions as step 5: `status: closed`,
322
+ or a handoff carrying `editorGone: true`.
312
323
 
313
324
  ## Keeping the human informed
314
325