shadok-ai 0.19.64 → 0.19.66

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/dist/server.js CHANGED
@@ -47,7 +47,7 @@ import { openBrowser } from "./open-browser.js";
47
47
  import { parseSkillMeta, prepromptParts, prepromptFingerprint, stalenessReasons, LEGACY_FINGERPRINT, } from "./preprompt.js";
48
48
  import { ensureSpawnHelperExecutable } from "./node-pty-fix.js";
49
49
  import { TmuxPilot, tmuxAvailable, tmuxHasSession, tmuxKillSession, tmuxPaneCwd, tmuxSessionCreated } from "./tmux.js";
50
- import { scanUsageSamples, scanUsageSamplesAsync, subagentDirFor, sessionFilePath, tailSession, clearTailPos, seedTailPos, isNothingToShow, newestTranscriptById } from "./tail.js";
50
+ import { scanUsageSamples, scanUsageSamplesAsync, subagentDirFor, sessionFilePath, resumeOrStartArgs, tailSession, clearTailPos, seedTailPos, isNothingToShow, newestTranscriptById } from "./tail.js";
51
51
  import { windowStats, latestModel } from "./token-stats.js";
52
52
  import { strandedWorktreePlan } from "./worktree-relocate.js";
53
53
  import { detectFork, rootIdOfFile } from "./forktrace.js";
@@ -9518,11 +9518,14 @@ user = null,
9518
9518
  /** The isolation group the agent belongs to (null = commons / mono-tenant),
9519
9519
  * so its profile's secrets resolve by the agent's REAL group, not always Main. */
9520
9520
  group = null) {
9521
- const pilot = makePilot(id, cwd, args, profile, model, effort, user, group);
9522
9521
  // A dropped group agent writes its transcript under ITS OWN home, not the
9523
9522
  // server's — so the content tail / history must read from there (invariant:
9524
9523
  // all content comes from the .jsonl). `agentStateHome` is the one answer.
9525
9524
  const transcriptHome = agentStateHome(user);
9525
+ // A resume of an agent that never got a first prompt has no transcript to
9526
+ // resume: start it under the same id instead (`resumeOrStartArgs`).
9527
+ args = resumeOrStartArgs(args, fs.existsSync(sessionFilePath(cwd, id, transcriptHome)));
9528
+ const pilot = makePilot(id, cwd, args, profile, model, effort, user, group);
9526
9529
  // Resumed sessions start with what the transcript already consumed. One scan
9527
9530
  // feeds both the context gauge (last message's usage) and the stats windows
9528
9531
  // (every message's usage + time + model), so a huge file is read once here.
@@ -9546,6 +9549,7 @@ group = null) {
9546
9549
  screenTimer: null,
9547
9550
  lastScreen: "",
9548
9551
  lastDialogKey: null,
9552
+ answering: 0,
9549
9553
  contextWindow,
9550
9554
  backend: backend.kind,
9551
9555
  // A reattached session must show its bar at once, not only after the next
@@ -9825,7 +9829,7 @@ async function attachPilot(s) {
9825
9829
  // screen change closes that hole for `key` and for any future path that
9826
9830
  // bypasses `finishTurn`. `publishDialog` dedups, so a dialog sitting
9827
9831
  // there while the footer clock ticks is announced exactly once.
9828
- if (settled && !s.busy) {
9832
+ if (settled && !s.busy && !s.answering) {
9829
9833
  const d = detectDialog(scr);
9830
9834
  if (d)
9831
9835
  publishDialog(s, d);
@@ -9838,7 +9842,7 @@ async function attachPilot(s) {
9838
9842
  // finishTurn, so watch for it here and signal the turn like any other.
9839
9843
  // SAY it when that fails: this is the one `finishTurn` call with nobody to
9840
9844
  // report to, and swallowing it is how a flag left up here stayed invisible.
9841
- if (settled && !s.busy && pilot.isWorking())
9845
+ if (settled && !s.busy && !s.answering && pilot.isWorking())
9842
9846
  finishTurn(s).catch((e) => console.error(`[sk-${s.id}] finishTurn (spontaneous resume) failed — ${e instanceof Error ? e.message : e}`));
9843
9847
  // Is `busy` still held by anyone? A flag that latches ON makes the agent
9844
9848
  // refuse every later prompt, for as long as the process lives, with
@@ -11459,9 +11463,17 @@ wss.on("connection", (ws, req) => {
11459
11463
  // running — either way there's nothing to select here.
11460
11464
  if (!detectDialog(session.pilot.screen()))
11461
11465
  return fail(session.busy ? "a response is already in progress" : "this dialog is no longer active");
11462
- await selectOption(session.pilot, msg.n);
11463
- await sleep(500);
11464
- await finishTurn(session);
11466
+ // Keep the screen watcher out until finishTurn has published whatever
11467
+ // comes next (see `Live.answering`).
11468
+ session.answering++;
11469
+ try {
11470
+ await selectOption(session.pilot, msg.n);
11471
+ await sleep(500);
11472
+ await finishTurn(session);
11473
+ }
11474
+ finally {
11475
+ session.answering--;
11476
+ }
11465
11477
  break;
11466
11478
  }
11467
11479
  case "toggle": {
@@ -11492,17 +11504,28 @@ wss.on("connection", (ws, req) => {
11492
11504
  const t = msg.text.trim();
11493
11505
  if (!t)
11494
11506
  return;
11495
- session.pilot.write(String(msg.n));
11496
- await sleep(700);
11497
- session.pilot.write(`\x1b[200~${t}\x1b[201~`);
11498
- await sleep(400);
11499
- session.pilot.press("enter");
11500
- await sleep(600);
11501
- const d = detectDialog(session.pilot.screen());
11502
- if (d)
11503
- broadcast(session, dialogMessage(session, d));
11504
- else
11505
- await finishTurn(session);
11507
+ session.answering++;
11508
+ try {
11509
+ session.pilot.write(String(msg.n));
11510
+ await sleep(700);
11511
+ session.pilot.write(`\x1b[200~${t}\x1b[201~`);
11512
+ await sleep(400);
11513
+ session.pilot.press("enter");
11514
+ await sleep(600);
11515
+ const d = detectDialog(session.pilot.screen());
11516
+ if (d) {
11517
+ // The next question of a form, or the same one again: either way a
11518
+ // fresh ask. Through publishDialog, so the key is recorded and the
11519
+ // watcher does not announce it a second time once we let go.
11520
+ session.lastDialogKey = null;
11521
+ publishDialog(session, d);
11522
+ }
11523
+ else
11524
+ await finishTurn(session);
11525
+ }
11526
+ finally {
11527
+ session.answering--;
11528
+ }
11506
11529
  break;
11507
11530
  }
11508
11531
  case "confirm": {
@@ -11521,22 +11544,28 @@ wss.on("connection", (ws, req) => {
11521
11544
  // — in the multi-question case that Enter answered the next question
11522
11545
  // with its default (silently, wrongly), corrupting the form. Wait for
11523
11546
  // whichever screen Tab produced, then decide.
11524
- session.pilot.press("tab");
11525
- await session.pilot
11526
- .waitFor((scr) => SUBMIT_PAGE.test(scr) || (detectDialog(scr)?.question ?? before.question) !== before.question, { timeoutMs: 5000 })
11527
- .catch(() => { }); // neither settled in time: fall through and inspect
11528
- await sleep(300);
11529
- const scr = session.pilot.screen();
11530
- const next = detectDialog(scr);
11531
- if (SUBMIT_PAGE.test(scr) || !next) {
11532
- // The recap/submit page (this was the last question), or the form is
11533
- // gone: let finishTurn drive it — it auto-confirms the recap.
11534
- await finishTurn(session);
11547
+ session.answering++;
11548
+ try {
11549
+ session.pilot.press("tab");
11550
+ await session.pilot
11551
+ .waitFor((scr) => SUBMIT_PAGE.test(scr) || (detectDialog(scr)?.question ?? before.question) !== before.question, { timeoutMs: 5000 })
11552
+ .catch(() => { }); // neither settled in time: fall through and inspect
11553
+ await sleep(300);
11554
+ const scr = session.pilot.screen();
11555
+ const next = detectDialog(scr);
11556
+ if (SUBMIT_PAGE.test(scr) || !next) {
11557
+ // The recap/submit page (this was the last question), or the form is
11558
+ // gone: let finishTurn drive it — it auto-confirms the recap.
11559
+ await finishTurn(session);
11560
+ }
11561
+ else {
11562
+ // Tab landed on a FURTHER question — hand it back to the user to
11563
+ // answer rather than auto-picking its default with Enter.
11564
+ publishDialog(session, next);
11565
+ }
11535
11566
  }
11536
- else {
11537
- // Tab landed on a FURTHER question — hand it back to the user to
11538
- // answer rather than auto-picking its default with Enter.
11539
- publishDialog(session, next);
11567
+ finally {
11568
+ session.answering--;
11540
11569
  }
11541
11570
  break;
11542
11571
  }