tryharness 0.7.31 → 0.7.32

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/lib/t3.mjs CHANGED
@@ -400,6 +400,13 @@ export async function steerT3Run(runId, text) {
400
400
  /** The T3 threads running a turn Harness handed them: Harness's runs, not the person's own sessions. */
401
401
  export const handedToT3 = () => new Set(handed.values());
402
402
 
403
+ /** The thread's turn going on now when T3 began it after `runId` (a later ordinal), else null. */
404
+ function laterTurn(recent, runId, activeRunId) {
405
+ if (!activeRunId || activeRunId === runId) return null;
406
+ const ordinal = (id) => recent.find((entry) => entry.runId === id)?.ordinal;
407
+ return ordinal(activeRunId) > ordinal(runId) ? activeRunId : null;
408
+ }
409
+
403
410
  /** One item of a T3 thread as a step on the board: its words, or what it did in a line. */
404
411
  function stepOf(item) {
405
412
  const text = String(item.text || "").trim();
@@ -420,12 +427,62 @@ function stepOf(item) {
420
427
  };
421
428
  }
422
429
 
430
+ // The option T3 gives each agent's effort under, by agent.
431
+ const EFFORT_OPTIONS = new Set(["reasoningEffort", "effort"]);
432
+ const versionOf = (id) => (id.match(/\d+/g) ?? []).map(Number);
433
+ const newerFirst = (a, b) => {
434
+ const [left, right] = [versionOf(a.id), versionOf(b.id)];
435
+ for (let i = 0; i < Math.max(left.length, right.length); i++)
436
+ if ((right[i] ?? -1) !== (left[i] ?? -1))
437
+ return (right[i] ?? -1) - (left[i] ?? -1);
438
+ return 0;
439
+ };
440
+
441
+ /**
442
+ * The selection T3 Code runs an agent's turn with: the model and effort the buddy shows for it (the person's pick, else
443
+ * the agent's own settings), as T3 names them. T3 names Claude's models in full (claude-opus-5-5) where Claude Code takes
444
+ * a short name (opus), which is the newest of that family T3 offers. Null when nothing names a model. A model or effort
445
+ * T3 does not offer fails the turn rather than letting T3 run it on another (October 17: Codex ran on gpt-6-astra
446
+ * for days while the buddy showed gpt-6.1-sol).
447
+ */
448
+ async function selectionFor({ instanceId, model, effort } = {}) {
449
+ if (!model) return null;
450
+ const { providers = [] } = await t3Tool("orchestrator_capabilities", {});
451
+ const offered =
452
+ providers.find((entry) => entry.providerInstanceId === instanceId)
453
+ ?.models ?? [];
454
+ const found =
455
+ offered.find((entry) => entry.id === model) ??
456
+ offered
457
+ .filter((entry) => entry.id.startsWith(`claude-${model}-`))
458
+ .sort(newerFirst)[0];
459
+ if (!found)
460
+ throw new T3Error(
461
+ "model",
462
+ `T3 Code does not offer ${model} for this agent (it offers ${offered.map((entry) => entry.id).join(", ") || "none"}).`
463
+ );
464
+ if (!effort) return { instanceId, model: found.id, options: [] };
465
+ const option = found.options?.find((entry) => EFFORT_OPTIONS.has(entry.id));
466
+ if (!option?.options?.some((level) => level.id === effort))
467
+ throw new T3Error(
468
+ "model",
469
+ `T3 Code does not offer effort ${effort} for ${found.id}.`
470
+ );
471
+ return {
472
+ instanceId,
473
+ model: found.id,
474
+ options: [{ id: option.id, value: effort }],
475
+ };
476
+ }
477
+
423
478
  /**
424
479
  * A coding agent's turn in a Harness thread, carried out by T3 Code, so the person finds it in T3 like any thread there.
425
- * The agent's first turn launches its own T3 thread (`launch`: T3's project, workspace and the model the person last
426
- * chose for the agent there, unless the relay chose one, `model`; T3 applies the mode the person approved Harness with); later turns go into that thread,
427
- * queued behind whatever it is doing. It reports as runner.mjs does: accepted, its session (the T3 thread, which is
428
- * how Open finds it), each step, then done with the agent's last words or failed; Stop interrupts it in T3.
480
+ * The agent's first turn launches its own T3 thread (`launch`: T3's project and workspace; T3 applies the mode the
481
+ * person approved Harness with); later turns go into that thread, queued behind whatever it is doing. Every turn runs
482
+ * on `pick` ({ instanceId, model, effort }, what the buddy shows for the agent), set on the thread before it starts, so
483
+ * a thread never keeps a model it launched with or that was set on it since. It reports as runner.mjs does: accepted,
484
+ * its session (the T3 thread, which is how Open finds it), each step, then done with the agent's last words or failed;
485
+ * Stop interrupts it in T3.
429
486
  */
430
487
  export function runInT3(run, emit, observe) {
431
488
  let threadId = run.threadId ?? null,
@@ -454,11 +511,12 @@ export function runInT3(run, emit, observe) {
454
511
  release();
455
512
  };
456
513
  // What the turn used, as T3 recorded it, so a turn there counts toward its thread's spend like one run here.
457
- const finish = (kind, text) => {
514
+ const finish = (kind, text, failure) => {
458
515
  letGo();
459
516
  emit(kind, text.slice(0, 20_000), {
460
517
  usage:
461
518
  threadId && runId ? (run.usageOf?.(threadId, runId) ?? null) : null,
519
+ ...(failure ? { failure } : {}),
462
520
  });
463
521
  };
464
522
  const read = async () => {
@@ -500,9 +558,18 @@ export function runInT3(run, emit, observe) {
500
558
  } while (page.hasMore && page.items?.length);
501
559
  if (page.thread?.worktreePath)
502
560
  run.onWorktree?.(page.thread.worktreePath, page.thread.branch ?? null);
503
- const status = (page.recentRuns ?? []).find(
504
- (entry) => entry.runId === runId
505
- )?.status;
561
+ const recent = page.recentRuns ?? [];
562
+ const status = recent.find((entry) => entry.runId === runId)?.status;
563
+ // The person wrote into the turn in T3 itself and T3 began it again with their words: the turn going on after it
564
+ // carries this run on, as one Harness steered into does.
565
+ const later = laterTurn(recent, runId, page.thread?.activeRunId);
566
+ if (ENDED.has(status) && later && !stopped) {
567
+ runId = later;
568
+ // Its first steps were read past while they were the other turn's: read the thread again from the start.
569
+ cursor = null;
570
+ timer = setTimeout(() => void read(), READ_MS);
571
+ return;
572
+ }
506
573
  if (status === "completed")
507
574
  return finish(
508
575
  "done",
@@ -515,13 +582,15 @@ export function runInT3(run, emit, observe) {
515
582
  "failed",
516
583
  stopped
517
584
  ? "Stopped."
518
- : `T3 Code ended the turn (${status})${last ? `: ${last}` : "."}`
585
+ : `T3 Code ended the turn (${status})${last ? `: ${last}` : "."}`,
586
+ stopped ? "person" : "exit"
519
587
  );
520
588
  } catch (error) {
521
589
  if (["expired", "not_connected", "read_only"].includes(error.code))
522
590
  return finish(
523
591
  "failed",
524
- `${error.message} The turn may still be going in T3 Code.`
592
+ `${error.message} The turn may still be going in T3 Code.`,
593
+ "exit"
525
594
  );
526
595
  // T3 restarting or busy: read again next time.
527
596
  }
@@ -552,12 +621,12 @@ export function runInT3(run, emit, observe) {
552
621
  emit("accepted");
553
622
  void (async () => {
554
623
  try {
555
- // A model the relay chose for this turn (models.mjs) is the thread's selection from this turn on.
624
+ const selection = await selectionFor(run.pick);
556
625
  if (threadId) {
557
- if (run.model)
626
+ if (selection)
558
627
  await t3Tool("t3_thread_configure", {
559
628
  threadId,
560
- modelSelection: run.model,
629
+ modelSelection: selection,
561
630
  });
562
631
  runId =
563
632
  (
@@ -573,7 +642,7 @@ export function runInT3(run, emit, observe) {
573
642
  title: run.title,
574
643
  message: run.brief,
575
644
  ...run.launch,
576
- ...(run.model ? { modelSelection: run.model } : {}),
645
+ ...(selection ? { modelSelection: selection } : {}),
577
646
  });
578
647
  threadId = launched.threadId;
579
648
  runId = launched.runId ?? null;
@@ -596,7 +665,7 @@ export function runInT3(run, emit, observe) {
596
665
  run.fallback(error.message);
597
666
  return;
598
667
  }
599
- finish("failed", `T3 Code did not take it: ${error.message}`);
668
+ finish("failed", `T3 Code did not take it: ${error.message}`, "start");
600
669
  }
601
670
  })();
602
671
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tryharness",
3
- "version": "0.7.31",
3
+ "version": "0.7.32",
4
4
  "description": "Harness Relay: the daemon that turns the agents on this machine into your personal swarm. Memory, history, and work handed between any of them.",
5
5
  "bin": {
6
6
  "tryharness": "cli.mjs"