tryharness 0.7.31 → 0.7.33
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/README.md +48 -0
- package/cli.mjs +175 -1
- package/lib/activity.mjs +82 -28
- package/lib/actorRoster.mjs +106 -0
- package/lib/asks.mjs +58 -0
- package/lib/boardAccess.mjs +328 -0
- package/lib/boardCommands.mjs +28 -0
- package/lib/boardFileCommands.mjs +228 -0
- package/lib/boardFiles.mjs +584 -0
- package/lib/boardProtocol.json +470 -0
- package/lib/boardProtocol.mjs +27 -0
- package/lib/boardThreads.mjs +153 -0
- package/lib/boardTools.mjs +202 -0
- package/lib/boardWatches.mjs +92 -0
- package/lib/bridge.mjs +272 -0
- package/lib/cards.mjs +70 -82
- package/lib/coordinator.mjs +153 -15
- package/lib/daemon.mjs +927 -5395
- package/lib/desktop.mjs +8 -5
- package/lib/digest.mjs +27 -0
- package/lib/goalCommands.mjs +459 -0
- package/lib/harnessModel.mjs +166 -0
- package/lib/lessons.mjs +328 -0
- package/lib/mcp-stdio.mjs +8 -2
- package/lib/models.mjs +118 -13
- package/lib/phones.mjs +8 -119
- package/lib/reactions.mjs +108 -0
- package/lib/roomPage.mjs +44 -0
- package/lib/runAuthority.mjs +109 -0
- package/lib/runWorker.mjs +503 -0
- package/lib/runner.mjs +11 -6
- package/lib/schedules.mjs +361 -0
- package/lib/sessionControl.mjs +788 -0
- package/lib/sessionIndex.mjs +245 -0
- package/lib/store.mjs +386 -20
- package/lib/swarm.mjs +183 -14
- package/lib/t3.mjs +84 -15
- package/lib/taskCommands.mjs +737 -0
- package/lib/taskRuns.mjs +196 -0
- package/lib/threadRuns.mjs +471 -0
- package/package.json +1 -1
package/lib/swarm.mjs
CHANGED
|
@@ -4,16 +4,11 @@ import path from "node:path";
|
|
|
4
4
|
import { spawnSync } from "node:child_process";
|
|
5
5
|
import { readRunSteps } from "./runner.mjs";
|
|
6
6
|
import { nameOf, resolveMember } from "./members.mjs";
|
|
7
|
-
import {
|
|
8
|
-
modelOf,
|
|
9
|
-
setNote,
|
|
10
|
-
swarmBlock,
|
|
11
|
-
swarmCards,
|
|
12
|
-
swarmDigest,
|
|
13
|
-
} from "./cards.mjs";
|
|
7
|
+
import { setNote, swarmBlock, swarmCards, swarmDigest } from "./cards.mjs";
|
|
14
8
|
import {
|
|
15
9
|
DEFAULT_ROUTING,
|
|
16
10
|
PICKABLE,
|
|
11
|
+
agentModelSettings,
|
|
17
12
|
choiceOf,
|
|
18
13
|
listingOf,
|
|
19
14
|
picksIn,
|
|
@@ -100,12 +95,17 @@ export function createSwarm({
|
|
|
100
95
|
authorizeRun,
|
|
101
96
|
pickable,
|
|
102
97
|
listModels,
|
|
98
|
+
harnessModel,
|
|
103
99
|
folders,
|
|
104
100
|
runsIn,
|
|
105
101
|
threadFiles = () => ({ files: [], rendering: [] }),
|
|
106
102
|
whyWaiting = () => null,
|
|
107
103
|
goals = null,
|
|
108
104
|
reofferHarness = () => {},
|
|
105
|
+
schedules = null,
|
|
106
|
+
// The person's post read for their reaction and for lessons (reactions.mjs, lessons.mjs), and what was learned.
|
|
107
|
+
heardPerson = () => {},
|
|
108
|
+
lessons = null,
|
|
109
109
|
}) {
|
|
110
110
|
// What the person let a thread spend of their Harness credits, in dollars, or null for no limit of its own.
|
|
111
111
|
const ceilingOf = (threadId) => {
|
|
@@ -138,9 +138,16 @@ export function createSwarm({
|
|
|
138
138
|
|
|
139
139
|
// Who a message is for: the agents it names, else whoever coordinates, which brings in every agent with a part in it.
|
|
140
140
|
// Where the coordinator cannot assemble (the privacy setting, a Harness without it) the thread's only agent takes it.
|
|
141
|
-
// `@swarm` is for the whole swarm
|
|
141
|
+
// `@swarm` is for the whole swarm: whoever coordinates brings in the rest, and the agents it names hear it from the post
|
|
142
|
+
// itself (October 16: a message naming an orchestrator and a role for each agent reached none of them).
|
|
142
143
|
const addressed = (thread, text) => {
|
|
143
|
-
if (SWARM.test(text))
|
|
144
|
+
if (SWARM.test(text))
|
|
145
|
+
return [
|
|
146
|
+
...new Set([
|
|
147
|
+
thread.goal.facilitator,
|
|
148
|
+
...mentionsIn(text, thread.goal.team),
|
|
149
|
+
]),
|
|
150
|
+
];
|
|
144
151
|
const named = mentionsIn(text, thread.goal.team);
|
|
145
152
|
if (named.length) return named;
|
|
146
153
|
const agents = agentsOf(thread);
|
|
@@ -270,6 +277,8 @@ export function createSwarm({
|
|
|
270
277
|
},
|
|
271
278
|
// The goal as the swarm keeps it (goals.mjs): what the person wants, its checks, where it stands, every version.
|
|
272
279
|
goal: goals?.record(thread.id) ?? null,
|
|
280
|
+
// When the thread comes back on its own (schedules.mjs): what for, how often, who set it, the next run.
|
|
281
|
+
checkIns: schedules?.list({ threadId: thread.id }) ?? [],
|
|
273
282
|
ceilingUsd: ceilingOf(thread.id),
|
|
274
283
|
changes: worktrees.summary(thread.id),
|
|
275
284
|
};
|
|
@@ -364,6 +373,8 @@ export function createSwarm({
|
|
|
364
373
|
ok: true,
|
|
365
374
|
thread: summary(thread),
|
|
366
375
|
posts: store.roomPosts(thread.id, 0, 500),
|
|
376
|
+
// What each of the person's posts changed in what the swarm keeps (lessons.mjs), for the line under the post.
|
|
377
|
+
kept: store.lessonsFromThread?.(thread.id) ?? [],
|
|
367
378
|
runs,
|
|
368
379
|
// Posts held for the person (who wrote one, when, never its words), and the post that replaced each one an agent
|
|
369
380
|
// posted again.
|
|
@@ -445,20 +456,34 @@ export function createSwarm({
|
|
|
445
456
|
ok: true,
|
|
446
457
|
threads: store.searchThreads(query, { goalIds: mine, k: 8 }),
|
|
447
458
|
sessions: request.teamOnly ? [] : store.search({ query, limit: 5 }),
|
|
459
|
+
// What the person told the swarm (lessons.mjs), to a caller on this computer.
|
|
460
|
+
lessons:
|
|
461
|
+
request.teamOnly || request.hostedCaller === true
|
|
462
|
+
? []
|
|
463
|
+
: store.lessonsMatching(query, 5).map((lesson) => ({
|
|
464
|
+
about: lesson.about,
|
|
465
|
+
agent: lesson.agent,
|
|
466
|
+
text: lesson.text,
|
|
467
|
+
quote: lesson.evidence.at(-1)?.quote ?? null,
|
|
468
|
+
})),
|
|
448
469
|
};
|
|
449
470
|
}
|
|
450
471
|
// Who can be asked: every other agent's card (cards.mjs), and the same cards as the block an agent is told when its
|
|
451
472
|
// session starts. Open to every caller, so an agent picks a name instead of guessing one.
|
|
452
473
|
if (command === "board.swarm.agents") {
|
|
474
|
+
// The person's words from other threads stay on this computer: a caller through Harness gets the cards alone.
|
|
475
|
+
const local = request.hostedCaller !== true;
|
|
453
476
|
const agents = swarmCards(
|
|
454
477
|
store,
|
|
455
|
-
roster().filter((entry) => entry.id !== agent)
|
|
478
|
+
roster().filter((entry) => entry.id !== agent),
|
|
479
|
+
{ lessons: local }
|
|
456
480
|
);
|
|
481
|
+
const told = local ? (lessons?.told() ?? []) : [];
|
|
457
482
|
return {
|
|
458
483
|
ok: true,
|
|
459
484
|
agents,
|
|
460
|
-
text: swarmBlock(agents),
|
|
461
|
-
digest: swarmDigest(agents),
|
|
485
|
+
text: swarmBlock(agents, Date.now(), told),
|
|
486
|
+
digest: swarmDigest(agents, told),
|
|
462
487
|
};
|
|
463
488
|
}
|
|
464
489
|
// Each coding agent's models as it lists them, the person's choice for it and their routing words (models.mjs). Open
|
|
@@ -467,6 +492,15 @@ export function createSwarm({
|
|
|
467
492
|
const named = request.target ? resolveMember(request.target) : null;
|
|
468
493
|
if (named && !named.ok)
|
|
469
494
|
return { ok: false, error: `no agent called "${request.target}"` };
|
|
495
|
+
// Harness's own: a provider, then a model of Harness's catalog on it (harnessModel.mjs).
|
|
496
|
+
if (named?.id === "harness")
|
|
497
|
+
return request.refresh === true && agent === "user"
|
|
498
|
+
? {
|
|
499
|
+
pending: harnessModel
|
|
500
|
+
.refresh()
|
|
501
|
+
.then(() => ({ ok: true, harness: harnessModel.view() })),
|
|
502
|
+
}
|
|
503
|
+
: { ok: true, harness: harnessModel.view() };
|
|
470
504
|
const ids = pickable().filter((id) => !named || id === named.id);
|
|
471
505
|
if (named && !ids.length)
|
|
472
506
|
return {
|
|
@@ -483,16 +517,20 @@ export function createSwarm({
|
|
|
483
517
|
id,
|
|
484
518
|
name: nameOf(id),
|
|
485
519
|
choice: choiceOf(store, id),
|
|
486
|
-
ownModel:
|
|
520
|
+
ownModel: agentModelSettings(id).model,
|
|
487
521
|
listedAt: listed?.at ?? null,
|
|
488
522
|
...(listed?.error ? { error: listed.error } : {}),
|
|
489
523
|
models: listed?.models ?? [],
|
|
490
524
|
};
|
|
491
525
|
}),
|
|
526
|
+
...(named ? {} : { harness: harnessModel.view() }),
|
|
492
527
|
});
|
|
528
|
+
// Harness's catalog is read the first time it is shown, once the server can send it.
|
|
493
529
|
return request.refresh === true && agent === "user"
|
|
494
530
|
? { pending: listModels().then(listing) }
|
|
495
|
-
:
|
|
531
|
+
: !named && !harnessModel.listed() && agent === "user"
|
|
532
|
+
? { pending: harnessModel.refresh().then(listing) }
|
|
533
|
+
: listing();
|
|
496
534
|
}
|
|
497
535
|
// Any of the person's agents may start a thread and stop one it started. The thread carries the agent's trust, so
|
|
498
536
|
// nothing in it runs without the person's Start, and one started through Harness gets no coordinator rounds (they
|
|
@@ -618,6 +656,15 @@ export function createSwarm({
|
|
|
618
656
|
// The person's choice of model and effort for one agent: a model it lists, "auto", or "default" for its own settings.
|
|
619
657
|
if (command === "board.swarm.model") {
|
|
620
658
|
const named = resolveMember(request.target);
|
|
659
|
+
// Harness's: a provider and one of its models there, or "default" for the person's last Harness model.
|
|
660
|
+
if (named.ok && named.id === "harness") {
|
|
661
|
+
if (agent !== "user")
|
|
662
|
+
return { ok: false, error: "only the person picks Harness's model" };
|
|
663
|
+
const set = harnessModel.set(request.provider, request.model);
|
|
664
|
+
return set.ok
|
|
665
|
+
? { ok: true, agent: "harness", choice: set.choice }
|
|
666
|
+
: set;
|
|
667
|
+
}
|
|
621
668
|
if (!named.ok || !PICKABLE.has(named.id))
|
|
622
669
|
return {
|
|
623
670
|
ok: false,
|
|
@@ -759,6 +806,7 @@ export function createSwarm({
|
|
|
759
806
|
});
|
|
760
807
|
wakeFor(thread.id, first, "user");
|
|
761
808
|
if (!to) heardBy(opened, first, text);
|
|
809
|
+
heardPerson(opened, first);
|
|
762
810
|
notifyBoard(store.getTask(thread.id));
|
|
763
811
|
return { ok: true, thread: summary(store.getTask(thread.id)) };
|
|
764
812
|
};
|
|
@@ -770,9 +818,127 @@ export function createSwarm({
|
|
|
770
818
|
.then((suggested) => begin(suggested.folder)),
|
|
771
819
|
};
|
|
772
820
|
}
|
|
821
|
+
// What the swarm learned from the person (lessons.mjs), the person's to read: only the person gets this far.
|
|
822
|
+
if (command === "board.swarm.lessons")
|
|
823
|
+
return {
|
|
824
|
+
ok: true,
|
|
825
|
+
lessons: (
|
|
826
|
+
lessons?.list({
|
|
827
|
+
status: request.replaced === true ? "replaced" : "active",
|
|
828
|
+
}) ?? []
|
|
829
|
+
).map((lesson) => {
|
|
830
|
+
const last = lesson.evidence.at(-1);
|
|
831
|
+
return {
|
|
832
|
+
...lesson,
|
|
833
|
+
// The last two times the person said it, with the thread's title, for the buddy's open lesson.
|
|
834
|
+
said: lesson.evidence
|
|
835
|
+
.filter((entry) => entry.quote && !entry.tookBack)
|
|
836
|
+
.slice(-2)
|
|
837
|
+
.map((entry) => ({
|
|
838
|
+
quote: entry.quote,
|
|
839
|
+
thread: store.getTask(entry.goalId)?.objective ?? null,
|
|
840
|
+
at: entry.at,
|
|
841
|
+
})),
|
|
842
|
+
from: last
|
|
843
|
+
? {
|
|
844
|
+
thread: store.getTask(last.goalId)?.objective ?? null,
|
|
845
|
+
seq: last.seq,
|
|
846
|
+
quote: last.quote,
|
|
847
|
+
}
|
|
848
|
+
: null,
|
|
849
|
+
};
|
|
850
|
+
}),
|
|
851
|
+
};
|
|
852
|
+
if (command === "board.swarm.lessons.remove") {
|
|
853
|
+
const removed = lessons?.remove(request.id);
|
|
854
|
+
return removed
|
|
855
|
+
? { ok: true, lesson: removed }
|
|
856
|
+
: { ok: false, error: "no lesson starts with that id" };
|
|
857
|
+
}
|
|
858
|
+
if (command === "board.swarm.lessons.undo")
|
|
859
|
+
return {
|
|
860
|
+
pending: (
|
|
861
|
+
lessons?.undo(
|
|
862
|
+
String(request.lessonId || ""),
|
|
863
|
+
String(request.change || "")
|
|
864
|
+
) ?? Promise.resolve(null)
|
|
865
|
+
).then((lesson) =>
|
|
866
|
+
lesson
|
|
867
|
+
? { ok: true, lesson }
|
|
868
|
+
: { ok: false, error: "that cannot be undone now" }
|
|
869
|
+
),
|
|
870
|
+
};
|
|
871
|
+
if (command === "board.swarm.lessons.edit")
|
|
872
|
+
return {
|
|
873
|
+
pending: (
|
|
874
|
+
lessons?.edit(request.id, request.text) ?? Promise.resolve(null)
|
|
875
|
+
).then((edited) =>
|
|
876
|
+
edited
|
|
877
|
+
? { ok: true, lesson: edited }
|
|
878
|
+
: {
|
|
879
|
+
ok: false,
|
|
880
|
+
error:
|
|
881
|
+
"no lesson starts with that id, or the new words are empty",
|
|
882
|
+
}
|
|
883
|
+
),
|
|
884
|
+
};
|
|
885
|
+
// Check-ins (schedules.mjs), the person's: only the person gets this far, and the lead sets its own in its rounds
|
|
886
|
+
// (coordinator.mjs). Every thread's, or ending one by its own id.
|
|
887
|
+
if (command === "board.swarm.checkins" && !request.id)
|
|
888
|
+
return {
|
|
889
|
+
ok: true,
|
|
890
|
+
checkIns: schedules?.list({ all: request.all === true }) ?? [],
|
|
891
|
+
};
|
|
892
|
+
if (command === "board.swarm.checkin.remove") {
|
|
893
|
+
const removed = schedules?.remove(String(request.checkIn || "")) ?? {
|
|
894
|
+
ok: false,
|
|
895
|
+
error: "this daemon keeps no check-ins",
|
|
896
|
+
};
|
|
897
|
+
if (removed.ok) notifyBoard(store.getTask(removed.schedule.threadId));
|
|
898
|
+
return removed;
|
|
899
|
+
}
|
|
773
900
|
const thread = store.getTask(String(request.id || ""));
|
|
774
901
|
if (!thread || thread.kind !== "goal")
|
|
775
902
|
return { ok: false, error: "thread not found" };
|
|
903
|
+
if (command === "board.swarm.checkins")
|
|
904
|
+
return {
|
|
905
|
+
ok: true,
|
|
906
|
+
checkIns: schedules?.list({ threadId: thread.id }) ?? [],
|
|
907
|
+
};
|
|
908
|
+
// The person's check-in on this thread: when, what for, and who it wakes (the lead when it names no one), only agents
|
|
909
|
+
// that can be in a thread.
|
|
910
|
+
if (command === "board.swarm.checkin") {
|
|
911
|
+
if (!schedules)
|
|
912
|
+
return { ok: false, error: "this daemon keeps no check-ins" };
|
|
913
|
+
const agents = Array.isArray(request.agents)
|
|
914
|
+
? request.agents.map(String)
|
|
915
|
+
: [];
|
|
916
|
+
const unknown = agents.filter((name) => !roomAgents.includes(name));
|
|
917
|
+
if (unknown.length)
|
|
918
|
+
return { ok: false, error: `no such agent: ${unknown.join(", ")}` };
|
|
919
|
+
const set = schedules.add({
|
|
920
|
+
threadId: thread.id,
|
|
921
|
+
what: request.what,
|
|
922
|
+
agents,
|
|
923
|
+
cadence: request.cadence,
|
|
924
|
+
by: "user",
|
|
925
|
+
maxRuns: request.maxRuns ?? null,
|
|
926
|
+
endsAt: request.endsAt ?? null,
|
|
927
|
+
});
|
|
928
|
+
if (!set.ok) return set;
|
|
929
|
+
store.roomPost({
|
|
930
|
+
goalId: thread.id,
|
|
931
|
+
author: "user",
|
|
932
|
+
kind: "note",
|
|
933
|
+
text: `You set a check-in (${set.schedule.when}): ${set.schedule.what}`,
|
|
934
|
+
});
|
|
935
|
+
notifyBoard(store.getTask(thread.id));
|
|
936
|
+
return {
|
|
937
|
+
ok: true,
|
|
938
|
+
checkIn: set.schedule,
|
|
939
|
+
thread: summary(store.getTask(thread.id)),
|
|
940
|
+
};
|
|
941
|
+
}
|
|
776
942
|
if (command === "board.swarm.read")
|
|
777
943
|
return read(thread, request.hostedCaller === true);
|
|
778
944
|
if (command === "board.swarm.diff")
|
|
@@ -907,7 +1073,10 @@ export function createSwarm({
|
|
|
907
1073
|
kind: "note",
|
|
908
1074
|
text: "Resumed by you.",
|
|
909
1075
|
});
|
|
1076
|
+
// A one-time check-in held while the thread was paused runs now.
|
|
1077
|
+
schedules?.tick();
|
|
910
1078
|
notifyBoard(store.getTask(thread.id));
|
|
1079
|
+
coordinator.resumed(thread.id);
|
|
911
1080
|
return { ok: true, thread: summary(store.getTask(thread.id)) };
|
|
912
1081
|
}
|
|
913
1082
|
// The person moves the thread to another folder between turns. Each agent starts a new session there, as a session
|
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
|
|
426
|
-
*
|
|
427
|
-
*
|
|
428
|
-
*
|
|
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
|
|
504
|
-
|
|
505
|
-
|
|
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
|
-
|
|
624
|
+
const selection = await selectionFor(run.pick);
|
|
556
625
|
if (threadId) {
|
|
557
|
-
if (
|
|
626
|
+
if (selection)
|
|
558
627
|
await t3Tool("t3_thread_configure", {
|
|
559
628
|
threadId,
|
|
560
|
-
modelSelection:
|
|
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
|
-
...(
|
|
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
|
}
|