@discovery-tree/runner 0.1.23 → 0.1.25

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.
Files changed (3) hide show
  1. package/README.md +16 -2
  2. package/dist/cli.js +266 -33
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -161,8 +161,12 @@ never offered to you. What it may do without asking:
161
161
  still descending from Claude Code by parent process id, or seen descending from it earlier
162
162
  (it looks every 30 seconds, and once more just before it stops Claude Code), with
163
163
  `taskkill /T /F`. Without PowerShell it falls back to those alone. An interrupted turn
164
- leaves it running (unless Claude Code does not answer the interrupt and the SIGINT the
165
- runner then sends ends it). It can be left running only if it moves itself out of that
164
+ leaves it running as long as the agent stops by itself, on its interrupt request or on
165
+ SIGINT, which go to the agent alone. A Stop always ends the turn: Claude Code gets an interrupt
166
+ request, Cursor and Codex get SIGINT, and an agent still running 5 seconds after each step
167
+ gets the next one, SIGTERM and then SIGKILL to its whole tree (pressing Stop again takes
168
+ the next step at once); once it gets to SIGTERM, what the agent started ends with it. It
169
+ can be left running only if it moves itself out of that
166
170
  group (`setsid`, a daemon; on Windows, a process started in the first moments of Claude
167
171
  Code, before it is in its job, whose parent then exited unseen), or if the runner itself is
168
172
  killed with SIGKILL (or the computer loses power). On Windows the jobs end with the runner
@@ -271,6 +275,12 @@ Codex's own sandbox is what keeps a run in its worktree:
271
275
  Interrupting a Codex turn stops its process (and what it started); the next message resumes the
272
276
  conversation. Planning requests are still answered by Claude Code.
273
277
 
278
+ Which model a Codex run uses is chosen in Discovery Tree's model picker. The runner lists the
279
+ models your Codex offers (`codex debug models`) with each heartbeat, so the picker shows them
280
+ under "Codex (your computer)"; `dt-runner doctor` prints the same list. A Codex too old to list
281
+ models still runs on its own default. The models appear within a few minutes of starting the
282
+ runner (its agent probe is cached for five minutes).
283
+
274
284
  ## Running Cursor
275
285
 
276
286
  The runner can also run a session with the [Cursor Agent CLI](https://cursor.com/cli) signed in
@@ -330,6 +340,10 @@ sandbox.
330
340
  Interrupting a Cursor turn stops its process (and what it started); the next message resumes the
331
341
  chat. Planning requests are still answered by Claude Code.
332
342
 
343
+ The Cursor models come from `cursor-agent --list-models`,
344
+ reported the same way and shown under "Cursor (your computer)" in the picker; `dt-runner doctor`
345
+ prints them too. Without a list, Cursor runs the model its CLI is set to.
346
+
333
347
  ## Planning on your own Claude Code
334
348
 
335
349
  Turn on **Plan on my own Claude Code** under Account settings → Local runners, and your
package/dist/cli.js CHANGED
@@ -22,6 +22,7 @@ var WORKSPACE_KEY_PROVIDER_TYPES = [
22
22
  var AI_CATEGORY_MODEL_MAX_LENGTH = 200;
23
23
 
24
24
  // ../contracts/src/agent-work.ts
25
+ var OWN_CLAUDE_PROVIDER = "own_claude";
25
26
  var AGENT_WORK_IDLE_AFTER_MS = 24 * 60 * 60 * 1e3;
26
27
 
27
28
  // ../contracts/src/default-task-model.ts
@@ -89,6 +90,15 @@ var AGENT_RUN_MAX_WALL_MS = 6 * 60 * 60 * 1e3;
89
90
  var AGENT_RUN_ABANDONED_GRACE_MS = 30 * 60 * 1e3;
90
91
  var AGENT_RUN_AUTO_RECOVER_MAX_MS = 5 * 6e4;
91
92
 
93
+ // ../contracts/src/active-run-summary.ts
94
+ var ACTIVE_RUN_AGENT_SHORT = {
95
+ [OWN_CLAUDE_PROVIDER]: "Claude",
96
+ local_claude_code: "Claude",
97
+ local_codex: "Codex",
98
+ local_cursor: "Cursor",
99
+ cursor_cloud: "Cursor"
100
+ };
101
+
92
102
  // ../contracts/src/discovered-work.ts
93
103
  var MAX_DISCOVERED_TASKS_PER_TURN = 5;
94
104
  var EXAMPLE_TITLE = "Return 404 instead of 500 when an invoice id is unknown";
@@ -485,6 +495,7 @@ checkout: ${EXAMPLE_CHECKOUT}
485
495
  cwd: .
486
496
  url: http://localhost:8000
487
497
  expect: 6h
498
+ limit: 7h
488
499
  ---
489
500
  Records order books into $DT_JOB_DATA_DIR/books, which the backtest reads.
490
501
  -->
@@ -516,14 +527,23 @@ Rules:
516
527
  - \`url\`: where it serves, when it does: an http://localhost address. Leave it out otherwise.
517
528
  - \`expect\`: how long it should run (\`45m\`, \`6h\`, \`2d\`); leave it out for one that runs
518
529
  until stopped.
530
+ - \`limit\`: how long it may run before Discovery Tree stops it (\`45m\`, \`7h\`, \`2d\`),
531
+ counted from when it starts. Give one for any job that should finish, a little past
532
+ \`expect\`, so one that hangs does not run for ever. Leave it out for one that serves until
533
+ a person stops it.
519
534
  - Below \`---\`, what it is for and where its output goes, at most
520
535
  ${MAX_JOB_REQUEST_PURPOSE_CHARS} characters.
521
536
  - The same job asked for again while it still waits or runs is not asked for twice.
522
- - If a job you asked for fails or is lost, this run hears about it: a message while it is
523
- still going, or a continuation if it has finished. Fix the command and ask again with a
524
- new DT-JOB block. That ask still waits for the owner's approval. After several failures
525
- in a row the run is not told again, and the job says that automatic tries have stopped.
526
- A later run of the same job that exits cleanly starts that count over.
537
+ - When a job you asked for ends (it exits, fails, is lost, or reaches its \`limit\`), this
538
+ run is woken with its report: how it ended, how long it ran, and the last lines of its
539
+ log. A message while the run is still going, or a continuation if it has finished. So
540
+ have the job print a short summary of what it did and where its output is as it ends:
541
+ that is what you will read. Then take the follow-up: check the output, finish the task,
542
+ or fix the command and ask again with a new DT-JOB block (which still waits for the
543
+ owner's approval). A job a person stops does not wake the run. After several failures
544
+ (or limits reached) in a row the run is not woken again, and the job says that
545
+ automatic tries have stopped. A later run of the same job that exits cleanly starts that
546
+ count over.
527
547
  - What the job writes in your checkout is kept for ${TREE_JOB_OUTPUT_KEPT_MS / 864e5} days after the job ends, then removed with
528
548
  the checkout; its data folder stays. Say where its output goes (below \`---\`), and say in a
529
549
  DT-RESULT block where to find it: in the job's data folder (its log names the path), and
@@ -679,7 +699,7 @@ function toolGrantRepositoryKey(url) {
679
699
  var RUN_STUCK_TOOL_CALL_AFTER_MS = 15 * 6e4;
680
700
 
681
701
  // src/version.ts
682
- var RUNNER_VERSION = true ? "0.1.23" : "0.0.0-dev";
702
+ var RUNNER_VERSION = true ? "0.1.25" : "0.0.0-dev";
683
703
  var RUNNER_PLATFORM = `${process.platform}-${process.arch}`;
684
704
 
685
705
  // src/api.ts
@@ -3240,6 +3260,56 @@ function startupHint(stderr) {
3240
3260
  return "";
3241
3261
  }
3242
3262
 
3263
+ // src/drivers/model-list.ts
3264
+ var MAX_LISTED_MODELS = 200;
3265
+ var MODEL_ID = /^[A-Za-z0-9][\w.:@/-]{0,199}$/;
3266
+ var ANSI = /\u001b\[[0-9;?]*[ -/]*[@-~]/g;
3267
+ function tidy(ids) {
3268
+ const out = [];
3269
+ for (const raw of ids) {
3270
+ const id = raw.trim();
3271
+ if (MODEL_ID.test(id) && !out.includes(id)) out.push(id);
3272
+ if (out.length >= MAX_LISTED_MODELS) break;
3273
+ }
3274
+ return out.length ? out : void 0;
3275
+ }
3276
+ function parseCodexModels(stdout) {
3277
+ const text = stdout.trim();
3278
+ if (!text) return void 0;
3279
+ let parsed;
3280
+ try {
3281
+ parsed = JSON.parse(text);
3282
+ } catch {
3283
+ return void 0;
3284
+ }
3285
+ const list = Array.isArray(parsed) ? parsed : parsed && typeof parsed === "object" ? parsed.models : void 0;
3286
+ if (!Array.isArray(list)) return void 0;
3287
+ const ids = [];
3288
+ for (const item of list) {
3289
+ if (typeof item === "string") {
3290
+ ids.push(item);
3291
+ } else if (item && typeof item === "object") {
3292
+ const m = item;
3293
+ if (typeof m.visibility === "string" && m.visibility !== "list") continue;
3294
+ const id = [m.slug, m.id, m.model, m.name].find((v) => typeof v === "string");
3295
+ if (typeof id === "string") ids.push(id);
3296
+ }
3297
+ }
3298
+ return tidy(ids);
3299
+ }
3300
+ function parseCursorModels(stdout) {
3301
+ const ids = [];
3302
+ for (const raw of stdout.replace(ANSI, "").split(/\r?\n/)) {
3303
+ const line = raw.replace(/^[\s*•✓-]+(?=[A-Za-z0-9])/, "").trim();
3304
+ if (!line) continue;
3305
+ const m = /^(\S+)(?:\s+-\s+.*)?$/.exec(line);
3306
+ if (m && !m[1].endsWith(":") && (line !== m[1] || /[-.\d]/.test(m[1]) || m[1] === "auto")) {
3307
+ ids.push(m[1]);
3308
+ }
3309
+ }
3310
+ return tidy(ids);
3311
+ }
3312
+
3243
3313
  // src/drivers/codex/codex.ts
3244
3314
  var CODEX_NPM_SCRIPT = ["node_modules", "@openai", "codex", "bin", "codex.js"];
3245
3315
  async function findCodex(env = process.env) {
@@ -3261,6 +3331,14 @@ async function codexVersion(bin, env = process.env) {
3261
3331
  return null;
3262
3332
  }
3263
3333
  }
3334
+ async function codexModels(bin, env = process.env) {
3335
+ try {
3336
+ const res = await runCodex(bin, ["debug", "models"], 2e4, env);
3337
+ return res.code === 0 ? parseCodexModels(res.stdout) : void 0;
3338
+ } catch {
3339
+ return void 0;
3340
+ }
3341
+ }
3264
3342
  async function codexAuthStatus(bin, env = process.env) {
3265
3343
  try {
3266
3344
  const res = await runCodex(bin, ["login", "status"], 2e4, env);
@@ -3287,7 +3365,7 @@ function codexKeyVariable(env = process.env) {
3287
3365
  if (env.OPENAI_API_KEY) return "OPENAI_API_KEY";
3288
3366
  return null;
3289
3367
  }
3290
- async function probeCodex(env = process.env) {
3368
+ async function probeCodex(env = process.env, opts = {}) {
3291
3369
  const bin = await findCodex(env);
3292
3370
  if (!bin) {
3293
3371
  return {
@@ -3312,7 +3390,13 @@ async function probeCodex(env = process.env) {
3312
3390
  codexProblem: "Codex is not signed in. Run `codex login` on this computer."
3313
3391
  };
3314
3392
  }
3315
- return { codexVersion: version, codexReady: auth.loggedIn, codexProblem: null };
3393
+ const models = auth.loggedIn === true && opts.models !== false ? await codexModels(bin, env) : void 0;
3394
+ return {
3395
+ codexVersion: version,
3396
+ codexReady: auth.loggedIn,
3397
+ codexProblem: null,
3398
+ ...models ? { codexModels: models } : {}
3399
+ };
3316
3400
  }
3317
3401
  var SIGN_IN_FAILURE2 = /not logged in|please (run|use) `?codex login|401 unauthorized|status 401|invalid[_ ]api[_ ]key|incorrect api key|refresh token|token (has )?expired|token_expired|could not be refreshed/i;
3318
3402
  function looksLikeCodexSignInFailure(text) {
@@ -3541,10 +3625,10 @@ var codexDriver = {
3541
3625
  resolveBinary: (env) => findCodex(env),
3542
3626
  notInstalledMessage: () => "Codex is not installed on the runner\u2019s computer (no `codex` on PATH). Install it with `npm i -g @openai/codex` and run `codex login`.",
3543
3627
  readFeatures: async () => ({}),
3544
- probe: async (env) => ({
3628
+ probe: async (env, opts) => ({
3545
3629
  claudeVersion: null,
3546
3630
  claudeReady: null,
3547
- ...await probeCodex(env),
3631
+ ...await probeCodex(env, opts),
3548
3632
  runsCodex: true
3549
3633
  }),
3550
3634
  doctor: doctor2,
@@ -3624,6 +3708,14 @@ async function doctor2(env = process.env) {
3624
3708
  detail: "could not tell (`codex login status` failed)"
3625
3709
  }
3626
3710
  );
3711
+ if (auth.loggedIn === true) {
3712
+ const models = await codexModels(bin, env);
3713
+ checks.push({
3714
+ name: "Codex models",
3715
+ level: models ? "ok" : "warn",
3716
+ detail: models ? `${models.length} available: ${models.slice(0, 6).join(", ")}${models.length > 6 ? ", \u2026" : ""}` : "could not list them (`codex debug models`): runs can only use Codex\u2019s own default model"
3717
+ });
3718
+ }
3627
3719
  const key = codexKeyVariable(env);
3628
3720
  if (key) {
3629
3721
  checks.push({
@@ -3654,6 +3746,14 @@ async function cursorVersion(bin, env = process.env) {
3654
3746
  return null;
3655
3747
  }
3656
3748
  }
3749
+ async function cursorModels(bin, env = process.env) {
3750
+ try {
3751
+ const res = await runCursor(bin, ["--list-models"], 2e4, env);
3752
+ return res.code === 0 ? parseCursorModels(res.stdout) : void 0;
3753
+ } catch {
3754
+ return void 0;
3755
+ }
3756
+ }
3657
3757
  async function cursorAuthStatus(bin, env = process.env) {
3658
3758
  try {
3659
3759
  const res = await runCursor(bin, ["status"], 2e4, env);
@@ -3678,7 +3778,7 @@ function cursorSignInFix(env = process.env) {
3678
3778
  }
3679
3779
  return "On the runner\u2019s computer, run `cursor-agent login` and sign in, and check that `cursor-agent status` says you are logged in.";
3680
3780
  }
3681
- async function probeCursor(env = process.env) {
3781
+ async function probeCursor(env = process.env, opts = {}) {
3682
3782
  const bin = await findCursor(env);
3683
3783
  if (!bin) {
3684
3784
  return {
@@ -3703,7 +3803,13 @@ async function probeCursor(env = process.env) {
3703
3803
  cursorProblem: "The Cursor Agent CLI is not signed in. Run `cursor-agent login` on this computer."
3704
3804
  };
3705
3805
  }
3706
- return { cursorVersion: version, cursorReady: auth.loggedIn, cursorProblem: null };
3806
+ const models = opts.models === false ? void 0 : await cursorModels(bin, env);
3807
+ return {
3808
+ cursorVersion: version,
3809
+ cursorReady: auth.loggedIn,
3810
+ cursorProblem: null,
3811
+ ...models ? { cursorModels: models } : {}
3812
+ };
3707
3813
  }
3708
3814
  var SIGN_IN_FAILURE3 = /authentication required|not (logged|signed) in|please run `?(cursor-)?agent login|invalid api key|401 unauthorized|status 401|unauthenticated|session (has )?expired/i;
3709
3815
  function looksLikeCursorSignInFailure(text) {
@@ -4102,10 +4208,10 @@ var cursorDriver = {
4102
4208
  resolveBinary: (env) => findCursor(env),
4103
4209
  notInstalledMessage: () => "The Cursor Agent CLI is not installed on the runner\u2019s computer (no `cursor-agent` on PATH). Install it from https://cursor.com/cli and run `cursor-agent login`.",
4104
4210
  readFeatures: async () => ({}),
4105
- probe: async (env) => ({
4211
+ probe: async (env, opts) => ({
4106
4212
  claudeVersion: null,
4107
4213
  claudeReady: null,
4108
- ...await probeCursor(env),
4214
+ ...await probeCursor(env, opts),
4109
4215
  runsCursor: true
4110
4216
  }),
4111
4217
  doctor: doctor3,
@@ -4190,6 +4296,14 @@ async function doctor3(env = process.env) {
4190
4296
  detail: "could not tell (`cursor-agent status` said nothing the runner reads)"
4191
4297
  }
4192
4298
  );
4299
+ if (auth.loggedIn !== false) {
4300
+ const models = await cursorModels(bin, env);
4301
+ checks.push({
4302
+ name: "Cursor models",
4303
+ level: models ? "ok" : "warn",
4304
+ detail: models ? `${models.length} available: ${models.slice(0, 6).join(", ")}${models.length > 6 ? ", \u2026" : ""}` : "could not list them (`cursor-agent --list-models`): runs can only use the model the CLI is set to"
4305
+ });
4306
+ }
4193
4307
  if (cursorKeyVariable(env)) {
4194
4308
  checks.push({
4195
4309
  name: "CURSOR_API_KEY",
@@ -7867,6 +7981,15 @@ var AgentSession = class {
7867
7981
  stopping = null;
7868
7982
  interruptRequested = false;
7869
7983
  interruptTimer = null;
7984
+ /** The process the interrupt under way is for, and how far it has escalated (0: asked). */
7985
+ interruptChild = null;
7986
+ interruptStage = 0;
7987
+ /** per_turn agents: an interrupt came while a turn's process was starting; applied once it is up. */
7988
+ interruptPending = false;
7989
+ /** The turn's result is being reported (push, pull request): see `interrupt`. */
7990
+ endingTurn = false;
7991
+ /** Interrupt command ids handled, so a redelivered command is not a second Stop. */
7992
+ interruptIds = [];
7870
7993
  controlSeq = 0;
7871
7994
  stderrTail = "";
7872
7995
  /** `stderrTail` lost its start (it keeps the last 4,000 characters). */
@@ -8213,31 +8336,110 @@ var AgentSession = class {
8213
8336
  }
8214
8337
  }
8215
8338
  /**
8216
- * Stops the current turn. An agent that takes an interrupt request on stdin (Claude Code,
8217
- * as the Agent SDK sends it) gets one and ends the turn itself; if it has not within the
8218
- * grace period, or takes none, SIGINT does the same the hard way.
8339
+ * Stops the current turn, escalating until it does. An agent that takes an interrupt
8340
+ * request on stdin (Claude Code, as the Agent SDK sends it) gets one and ends the turn
8341
+ * itself; one that takes none (Cursor, Codex) gets SIGINT. Each step not answered within
8342
+ * the grace period gives way to the next: SIGINT, then SIGTERM and SIGKILL to the agent's
8343
+ * whole tree, so a CLI that traps or ignores SIGINT cannot keep a stopped turn running. A
8344
+ * repeated interrupt (the person pressing Stop again) takes the next step at once.
8345
+ *
8346
+ * A Stop stops whatever the agent is doing or about to do. On a per_turn agent, one that
8347
+ * finds a turn's process starting (a message just sent, a resume retry) or messages queued
8348
+ * to start once the last turn is over (while it is reported, or just after) is held, and
8349
+ * applied as soon as that turn's process is up. While a finished turn is being reported
8350
+ * (push, pull request), Claude Code gets the interrupt request alone, which stops a turn
8351
+ * it began meanwhile on a message sent mid-turn and is ignored if it is idle: no signal
8352
+ * escalates against an agent that may be idle. A redelivered command (same `commandId`)
8353
+ * changes nothing. Returns whether anything was sent or held.
8219
8354
  */
8220
- interrupt() {
8355
+ interrupt(commandId) {
8356
+ if (commandId) {
8357
+ if (this.interruptIds.includes(commandId)) return false;
8358
+ this.interruptIds.push(commandId);
8359
+ if (this.interruptIds.length > 50) this.interruptIds.shift();
8360
+ }
8361
+ if (this.driver.processModel === "per_turn") {
8362
+ const queuedNext = this.queuedTurns.length > 0 && (this.endingTurn || !this.record.turnActive);
8363
+ if (this.startingTurn || queuedNext) {
8364
+ this.interruptPending = true;
8365
+ return true;
8366
+ }
8367
+ }
8368
+ if (this.endingTurn) return this.requestInterruptOnly();
8221
8369
  const child = this.child;
8222
8370
  if (!child || !this.record.turnActive) return false;
8371
+ if (this.interruptRequested && this.interruptChild === child) {
8372
+ this.escalateInterrupt(child);
8373
+ return true;
8374
+ }
8223
8375
  this.interruptRequested = true;
8376
+ this.interruptChild = child;
8377
+ this.interruptStage = 0;
8224
8378
  this.permissions.expireAll(PERMISSION_EXPIRED_INTERRUPTED);
8225
- const sigint = () => child.kill("SIGINT");
8226
8379
  const message = this.driver.interruptMessage?.(`dt_interrupt_${++this.controlSeq}`);
8227
8380
  if (message === void 0) {
8228
- sigint();
8381
+ this.escalateInterrupt(child);
8382
+ return true;
8383
+ }
8384
+ try {
8385
+ this.write(message);
8386
+ this.armInterruptTimer(child);
8387
+ } catch {
8388
+ this.escalateInterrupt(child);
8389
+ }
8390
+ return true;
8391
+ }
8392
+ /** The agent's own interrupt request, with no escalation behind it (see `interrupt`). */
8393
+ requestInterruptOnly() {
8394
+ const message = this.driver.interruptMessage?.(`dt_interrupt_${++this.controlSeq}`);
8395
+ if (!this.child || message === void 0) return false;
8396
+ try {
8397
+ this.write(message);
8229
8398
  return true;
8399
+ } catch {
8400
+ return false;
8230
8401
  }
8231
- this.write(message);
8402
+ }
8403
+ /**
8404
+ * The next step of an interrupt: SIGINT to the agent alone (a dev server it started in the
8405
+ * background outlives an interrupted turn, though not the agent, if SIGINT ends it), then
8406
+ * SIGTERM and SIGKILL to its tree. Nothing once the process is gone or the turn is over.
8407
+ */
8408
+ escalateInterrupt(child) {
8409
+ if (this.interruptTimer) clearTimeout(this.interruptTimer);
8410
+ this.interruptTimer = null;
8411
+ if (this.child !== child || !this.record.turnActive || this.endingTurn) return;
8412
+ if (child.exitCode !== null || child.signalCode !== null) return;
8413
+ const stage = ++this.interruptStage;
8414
+ if (stage === 1) {
8415
+ child.kill("SIGINT");
8416
+ } else if (stage === 2) {
8417
+ this.deps.logger.warn(
8418
+ `session ${this.sessionId}: ${this.driver.displayName} did not stop on SIGINT; sending SIGTERM`
8419
+ );
8420
+ signalTree(child, "SIGTERM");
8421
+ } else {
8422
+ this.deps.logger.warn(
8423
+ `session ${this.sessionId}: ${this.driver.displayName} did not stop on SIGTERM; killing it`
8424
+ );
8425
+ signalTree(child, "SIGKILL");
8426
+ return;
8427
+ }
8428
+ this.armInterruptTimer(child);
8429
+ }
8430
+ armInterruptTimer(child) {
8232
8431
  if (this.interruptTimer) clearTimeout(this.interruptTimer);
8233
8432
  this.interruptTimer = setTimeout(() => {
8234
8433
  this.interruptTimer = null;
8235
- if (this.child === child && this.record.turnActive) {
8236
- this.deps.logger.warn(`session ${this.sessionId}: no answer to interrupt; sending SIGINT`);
8237
- sigint();
8434
+ if (this.child === child && this.record.turnActive && !this.endingTurn) {
8435
+ if (this.interruptStage === 0) {
8436
+ this.deps.logger.warn(
8437
+ `session ${this.sessionId}: no answer to interrupt; sending SIGINT`
8438
+ );
8439
+ }
8440
+ this.escalateInterrupt(child);
8238
8441
  }
8239
8442
  }, this.deps.interruptGraceMs ?? 5e3);
8240
- return true;
8241
8443
  }
8242
8444
  /**
8243
8445
  * Ends the process (closing stdin first, so the agent saves its session and exits), and
@@ -8349,6 +8551,11 @@ ${text}` : text;
8349
8551
  this.emit({ type: "status", status: "running" });
8350
8552
  } finally {
8351
8553
  this.startingTurn = false;
8554
+ const pending = this.interruptPending;
8555
+ this.interruptPending = false;
8556
+ if (pending && this.interrupt()) {
8557
+ this.deps.logger.info(`session ${this.sessionId}: interrupting the turn just started`);
8558
+ }
8352
8559
  }
8353
8560
  }
8354
8561
  /** The turn's message went to the agent: the turn is active, and said to be. */
@@ -8592,7 +8799,16 @@ ${text}` : text;
8592
8799
  this.resumeRetry = this.turnText;
8593
8800
  this.record.conversationId = null;
8594
8801
  }
8802
+ /** Reports the turn's end; meanwhile a Stop does not escalate (see `interrupt`). */
8595
8803
  async endTurn(rawTurn) {
8804
+ this.endingTurn = true;
8805
+ try {
8806
+ await this.reportTurnEnd(rawTurn);
8807
+ } finally {
8808
+ this.endingTurn = false;
8809
+ }
8810
+ }
8811
+ async reportTurnEnd(rawTurn) {
8596
8812
  const redactor = this.deps.environment?.redactor;
8597
8813
  const turn = redactor?.active && rawTurn.text ? { ...rawTurn, text: redactor.redact(rawTurn.text) } : rawTurn;
8598
8814
  this.permissions.expireAll(PERMISSION_EXPIRED_TURN_ENDED);
@@ -8602,6 +8818,7 @@ ${text}` : text;
8602
8818
  }
8603
8819
  const interrupted = this.interruptRequested;
8604
8820
  this.interruptRequested = false;
8821
+ this.interruptChild = null;
8605
8822
  if (this.interruptTimer) clearTimeout(this.interruptTimer);
8606
8823
  this.interruptTimer = null;
8607
8824
  const turnFailed = turn.isError && !interrupted;
@@ -8833,9 +9050,10 @@ ${text}` : text;
8833
9050
  const waiters = this.exitWaiters;
8834
9051
  this.exitWaiters = [];
8835
9052
  try {
8836
- if (this.resumeRetry === null && !reason && this.record.turnActive && this.resumeNotFound(true) && this.driver.resumeNotFound(this.stderrTail)) {
9053
+ if (this.resumeRetry === null && !reason && this.record.turnActive && !this.interruptRequested && this.resumeNotFound(true) && this.driver.resumeNotFound(this.stderrTail)) {
8837
9054
  this.planFreshRetry();
8838
9055
  }
9056
+ if (this.resumeRetry !== null && this.interruptRequested) this.resumeRetry = null;
8839
9057
  if (this.resumeRetry !== null) {
8840
9058
  const text = this.resumeRetry;
8841
9059
  this.resumeRetry = null;
@@ -8848,6 +9066,7 @@ ${text}` : text;
8848
9066
  else await this.beginTurn(text);
8849
9067
  } catch (err) {
8850
9068
  this.startingTurn = false;
9069
+ this.interruptPending = false;
8851
9070
  this.emit(
8852
9071
  {
8853
9072
  type: "error",
@@ -8860,6 +9079,7 @@ ${text}` : text;
8860
9079
  return;
8861
9080
  }
8862
9081
  if (reason) {
9082
+ this.interruptRequested = false;
8863
9083
  this.deps.logger.info(
8864
9084
  `session ${this.sessionId}: ${this.driver.displayName} stopped (${reason})`
8865
9085
  );
@@ -8876,6 +9096,7 @@ ${text}` : text;
8876
9096
  return;
8877
9097
  }
8878
9098
  if (!this.record.turnActive) {
9099
+ this.interruptRequested = false;
8879
9100
  if (this.driver.processModel === "persistent") {
8880
9101
  this.deps.logger.info(
8881
9102
  `session ${this.sessionId}: ${this.driver.displayName} exited while idle`,
@@ -9042,7 +9263,7 @@ var SessionManager = class {
9042
9263
  case "send_message":
9043
9264
  return await this.send(cmd.sessionId, cmd.text, cmd.id);
9044
9265
  case "interrupt":
9045
- return this.interrupt(cmd.sessionId);
9266
+ return await this.interrupt(cmd.sessionId, cmd.id);
9046
9267
  case "close_session":
9047
9268
  await this.close(cmd.sessionId);
9048
9269
  return { ok: true };
@@ -9466,10 +9687,11 @@ var SessionManager = class {
9466
9687
  await session.grantTool(cmd.denialId, cmd.scope, cmd.rule.trim());
9467
9688
  return { ok: true };
9468
9689
  }
9469
- interrupt(sessionId) {
9690
+ async interrupt(sessionId, commandId) {
9691
+ await this.starting.get(sessionId)?.catch(() => void 0);
9470
9692
  const session = this.sessions.get(sessionId);
9471
9693
  if (!session) return { ok: true };
9472
- if (session.interrupt()) this.opts.logger.info(`session ${sessionId}: interrupting`);
9694
+ if (session.interrupt(commandId)) this.opts.logger.info(`session ${sessionId}: interrupting`);
9473
9695
  return { ok: true };
9474
9696
  }
9475
9697
  /** Stops the agent, removes the worktree (the branch stays), forgets the session. */
@@ -10056,8 +10278,14 @@ var RunnerDaemon = class {
10056
10278
  async agentProblem(driver) {
10057
10279
  const agent = this.optional.find((a) => a.driver.kind === driver.kind);
10058
10280
  if (!agent) return null;
10059
- const fresh = readAgentFields(await agent.driver.probe(), agent);
10060
- if (this.agentInfo) this.agentInfo.info = withAgentFields(this.agentInfo.info, agent, fresh);
10281
+ const fresh = readAgentFields(await agent.driver.probe(void 0, { models: false }), agent);
10282
+ if (this.agentInfo) {
10283
+ const kept = readAgentFields(this.agentInfo.info, agent).models;
10284
+ this.agentInfo.info = withAgentFields(this.agentInfo.info, agent, {
10285
+ ...fresh,
10286
+ models: fresh.models ?? kept
10287
+ });
10288
+ }
10061
10289
  if (fresh.ready === true) this.signInFailed.delete(agent.driver.kind);
10062
10290
  if (fresh.ready !== false) return null;
10063
10291
  return fresh.problem || `${agent.driver.displayName} is not ready. ${agent.driver.signInFix()}`;
@@ -10409,6 +10637,7 @@ var OPTIONAL_AGENTS = [
10409
10637
  version: "codexVersion",
10410
10638
  ready: "codexReady",
10411
10639
  problem: "codexProblem",
10640
+ models: "codexModels",
10412
10641
  runs: "runsCodex"
10413
10642
  },
10414
10643
  {
@@ -10416,6 +10645,7 @@ var OPTIONAL_AGENTS = [
10416
10645
  version: "cursorVersion",
10417
10646
  ready: "cursorReady",
10418
10647
  problem: "cursorProblem",
10648
+ models: "cursorModels",
10419
10649
  runs: "runsCursor"
10420
10650
  }
10421
10651
  ];
@@ -10423,7 +10653,8 @@ function readAgentFields(info, agent) {
10423
10653
  return {
10424
10654
  version: info[agent.version] ?? null,
10425
10655
  ready: info[agent.ready] ?? null,
10426
- problem: info[agent.problem] ?? null
10656
+ problem: info[agent.problem] ?? null,
10657
+ models: info[agent.models]
10427
10658
  };
10428
10659
  }
10429
10660
  function withAgentFields(info, agent, fields) {
@@ -10431,7 +10662,9 @@ function withAgentFields(info, agent, fields) {
10431
10662
  ...info,
10432
10663
  [agent.version]: fields.version,
10433
10664
  [agent.ready]: fields.ready,
10434
- [agent.problem]: fields.problem
10665
+ [agent.problem]: fields.problem,
10666
+ // A fresh probe that listed none clears what an earlier one listed.
10667
+ [agent.models]: fields.models
10435
10668
  };
10436
10669
  }
10437
10670
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@discovery-tree/runner",
3
- "version": "0.1.23",
3
+ "version": "0.1.25",
4
4
  "description": "dt-runner: run Discovery Tree agent sessions on your own computer with your own signed-in Claude Code",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {