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/daemon.mjs CHANGED
@@ -31,6 +31,8 @@ import { PROCESS_NAMES, createSwarm, nativeSessionId } from "./swarm.mjs";
31
31
  import { createCoordinator, speakerOf } from "./coordinator.mjs";
32
32
  import { createHarnessLane } from "./lane.mjs";
33
33
  import { createAsks } from "./asks.mjs";
34
+ import { createReactions } from "./reactions.mjs";
35
+ import { createLessons } from "./lessons.mjs";
34
36
  import { createWorktrees } from "./worktrees.mjs";
35
37
  import { createFolders } from "./folders.mjs";
36
38
  import { notificationFor, notifyDesktop } from "./notify.mjs";
@@ -54,6 +56,7 @@ import { createAppleSpeech, createSpeech } from "./speech.mjs";
54
56
  import { createEnvironment } from "./environment.mjs";
55
57
  import { createFrames } from "./frames.mjs";
56
58
  import { createWatches } from "./watches.mjs";
59
+ import { createSchedules } from "./schedules.mjs";
57
60
  import { createSnippets } from "./snippets.mjs";
58
61
  import { digestSince } from "./digest.mjs";
59
62
  import { createPhoneDesk } from "./phones.mjs";
@@ -123,10 +126,12 @@ import {
123
126
  import { detectAgentApps, detectMcpClients } from "./adapters.mjs";
124
127
  import {
125
128
  cardLine,
129
+ effortOf,
126
130
  modelOf,
127
131
  swarmBlock,
128
132
  swarmCards,
129
133
  swarmDigest,
134
+ toldBlock,
130
135
  } from "./cards.mjs";
131
136
  import {
132
137
  PICKABLE,
@@ -622,15 +627,24 @@ export async function startDaemon() {
622
627
  const SCRUBBED = new Set([
623
628
  "board_call",
624
629
  "harness_task",
630
+ "harness_steer",
625
631
  "coordinate",
626
632
  "pick_folder",
627
633
  "route_model",
634
+ "react",
635
+ "reflect",
628
636
  "wake",
629
637
  ]);
630
638
  // Requests that only decide (the coordinator's round, a folder pick, a model pick): nothing on Harness's server acts on
631
639
  // an email, phone number, wallet address or amount in them, so those go as placeholders too and come back restored.
632
640
  // Work that acts (board calls, Harness's own tasks) keeps them, as Bankr needs the real address.
633
- const DECIDE_ONLY = new Set(["coordinate", "pick_folder", "route_model"]);
641
+ const DECIDE_ONLY = new Set([
642
+ "coordinate",
643
+ "pick_folder",
644
+ "route_model",
645
+ "react",
646
+ "reflect",
647
+ ]);
634
648
  let scrubber = null;
635
649
  // `clear`: fields sent as they are, after the scrub (the person's own model lane, whose key must reach the provider).
636
650
  const askHarness = (type, input, timeoutMs = 15_000, clear = null) => {
@@ -1250,12 +1264,16 @@ export async function startDaemon() {
1250
1264
  : seen.has(agent) || Boolean(woken[agent]) || cloudSetup.has(agent))
1251
1265
  );
1252
1266
  };
1253
- // Each agent's card (cards.mjs) as every other agent is told it, its setup included.
1254
- const cardsFor = (ids) =>
1267
+ // Each agent's card (cards.mjs) as every other agent is told it, its setup included; `lessons`: what the person said
1268
+ // about each, for a reader on this computer or Harness only.
1269
+ const cardsFor = (ids, { lessons = true } = {}) =>
1255
1270
  swarmCards(
1256
1271
  store,
1257
- ids.map((id) => ({ id, setup: setupOf(id) }))
1272
+ ids.map((id) => ({ id, setup: setupOf(id) })),
1273
+ { lessons }
1258
1274
  );
1275
+ // The person's words from other threads (lessons.mjs) stay with the agents on this computer and Harness.
1276
+ const readsLessonsHere = (agent) => RUNNERS.has(agent) || agent === "harness";
1259
1277
  // How an agent works in a thread's room: read it, post to it, and bring in another agent by name.
1260
1278
  // Each thread's goal: drafted, kept current and checked by whoever coordinates it (goals.mjs).
1261
1279
  const goals = createGoals({
@@ -1289,9 +1307,10 @@ export async function startDaemon() {
1289
1307
  `- Share findings, partial work and what is left with post_to_room (id ${task.id}).`,
1290
1308
  `- Files the work is about go in the thread, whoever made them: attach_file (id ${task.id}) with the file's path on this computer. A teammate's file is listed by read_room; open it with get_file.`,
1291
1309
  "- Need help, a second opinion or something only another agent can do? Post to the room with that agent's name in ask, say exactly what you need, then stop: you are woken again when it answers you by name. Naming an agent without ask (a thanks, a credit) does not wake it. The agents you can ask:",
1292
- ...cardsFor(available().filter((name) => name !== agent)).map(
1293
- (card) => ` ${cardLine(card)}`
1294
- ),
1310
+ ...cardsFor(
1311
+ available().filter((name) => name !== agent),
1312
+ { lessons: readsLessonsHere(agent) }
1313
+ ).map((card) => ` ${cardLine(card)}`),
1295
1314
  ];
1296
1315
  const swarmBrief = (
1297
1316
  task,
@@ -1460,33 +1479,17 @@ export async function startDaemon() {
1460
1479
  };
1461
1480
  // A turn T3 carries out (t3.mjs runInT3): into the agent's T3 thread in this thread, else a new one in T3's project
1462
1481
  // for the folder, on the thread's T3 checkout. The thread works in T3 from its first launch.
1463
- // A model the relay chose goes to T3 as its selection, effort under the option name T3 gives each agent.
1464
- const t3Turn = (task, agent, chosen) => {
1482
+ // Every turn runs there on the model and effort the run was given (what the buddy shows), whatever the thread last ran.
1483
+ const t3Turn = (task, agent, { model, effort }) => {
1465
1484
  const thread = store.getTask(task.parent_id);
1466
1485
  const key = `t3-thread:${thread.id}:${agent}`;
1467
- const model = t3Model(agent);
1468
1486
  const project = t3Project(thread.goal.workspace);
1469
- const effort = chosen.effort
1470
- ? [
1471
- {
1472
- id: agent === "codex" ? "reasoningEffort" : "effort",
1473
- value: chosen.effort,
1474
- },
1475
- ]
1476
- : [];
1477
1487
  return {
1478
1488
  threadId: store.meta(key) || null,
1479
1489
  title: thread.objective.slice(0, 120),
1480
- model: chosen.model
1481
- ? {
1482
- instanceId: t3Provider(agent),
1483
- model: chosen.model,
1484
- options: effort,
1485
- }
1486
- : null,
1490
+ pick: { instanceId: t3Provider(agent), model, effort },
1487
1491
  launch: {
1488
1492
  ...(project ? { projectId: project.id } : {}),
1489
- ...(model ? { modelSelection: model } : {}),
1490
1493
  workspaceStrategy: worktrees.t3Workspace(thread),
1491
1494
  },
1492
1495
  onThread: (threadId) => {
@@ -1622,7 +1625,10 @@ export async function startDaemon() {
1622
1625
  steerRunning(goalId, agent, words, pending);
1623
1626
  return;
1624
1627
  }
1625
- if (store.wakeCount(goalId, agent) >= goal.max_wakes) {
1628
+ // The limit guards against agents waking each other in a loop, so it counts from the thread's last check-in: a thread
1629
+ // that checks in for days is not paused by the wakes its check-ins brought.
1630
+ const counting = store.meta(`check-in-at:${goalId}`) || null;
1631
+ if (store.wakeCount(goalId, agent, counting) >= goal.max_wakes) {
1626
1632
  pauseGoal(goalId, `${agent} was woken ${goal.max_wakes} times`);
1627
1633
  return;
1628
1634
  }
@@ -1772,6 +1778,8 @@ export async function startDaemon() {
1772
1778
  });
1773
1779
  notifyBoard(store.getTask(thread.id));
1774
1780
  };
1781
+ // Harness's tasks its server is working, by task, with their thread: an ask for Harness there goes into that turn.
1782
+ const harnessTurns = new Map();
1775
1783
  const asks = createAsks({
1776
1784
  store,
1777
1785
  deliver: postAsk,
@@ -1799,6 +1807,18 @@ export async function startDaemon() {
1799
1807
  : null;
1800
1808
  },
1801
1809
  say: sayInThread,
1810
+ turnOf: (threadId, agent) =>
1811
+ agent === "harness" && serverFeatures.has("harness_steer")
1812
+ ? ([...harnessTurns].find(([, thread]) => thread === threadId)?.[0] ??
1813
+ null)
1814
+ : null,
1815
+ steer: (taskId, ask) =>
1816
+ askHarness("harness_steer", {
1817
+ taskId,
1818
+ askId: ask.id,
1819
+ asker: ask.asker,
1820
+ words: ask.words.slice(0, 20_000),
1821
+ }).then((reply) => Boolean(reply?.ok && reply.taken)),
1802
1822
  });
1803
1823
  // Ask an agent that is not started here (asks.mjs). Returns what the asker is told when it does not go at once.
1804
1824
  const askAgent = (goalId, agent, reason, asker, words = reason) =>
@@ -1909,10 +1929,20 @@ export async function startDaemon() {
1909
1929
  ? offer(lane)
1910
1930
  : reply
1911
1931
  );
1932
+ // The asks its turn read are answered with it; whoever made them hears its answer as the task's asker does.
1933
+ const turnEnded = (outcome) => {
1934
+ harnessTurns.delete(taskId);
1935
+ const read = outcome?.status === "done" ? (outcome.read ?? []) : [];
1936
+ const askers = asks.turnEnded(goal.id, taskId, read);
1937
+ if (askers.length)
1938
+ store.meta(`harness-also-asked:${taskId}`, JSON.stringify(askers));
1939
+ };
1940
+ harnessTurns.set(taskId, goal.id);
1912
1941
  offer(null).then(
1913
1942
  (reply) => {
1914
1943
  // askHarness spreads Harness's answer into the reply.
1915
1944
  const outcome = reply?.ok ? reply : null;
1945
+ turnEnded(outcome);
1916
1946
  if (!outcome)
1917
1947
  return waits(
1918
1948
  `Harness could not take it here (${reply?.error || "no answer"})`
@@ -1960,7 +1990,10 @@ export async function startDaemon() {
1960
1990
  `Harness could not finish it here${outcome.text ? ` (${outcome.text.slice(0, 300)})` : ""}`
1961
1991
  );
1962
1992
  },
1963
- (error) => waits(`Harness could not take it here (${error.message})`)
1993
+ (error) => {
1994
+ turnEnded(null);
1995
+ waits(`Harness could not take it here (${error.message})`);
1996
+ }
1964
1997
  );
1965
1998
  };
1966
1999
  // What the person let a thread spend of their Harness credits, for a Harness that checks it (swarm_goal).
@@ -2173,9 +2206,16 @@ export async function startDaemon() {
2173
2206
  if (joining.length)
2174
2207
  store.setGoalTeam(goal.id, [...goal.goal.team, ...joining]);
2175
2208
  const team = [...goal.goal.team, ...joining];
2209
+ // Asks Harness's turn read while it worked (asks.mjs turnEnded): their askers hear the answer as the task's does.
2210
+ let alsoAsked = [];
2211
+ try {
2212
+ alsoAsked = JSON.parse(
2213
+ store.meta(`harness-also-asked:${task.id}`) || "[]"
2214
+ );
2215
+ } catch {}
2176
2216
  const mentions = root
2177
2217
  ? []
2178
- : [...new Set([task.origin_agent, ...named])].filter(
2218
+ : [...new Set([task.origin_agent, ...alsoAsked, ...named])].filter(
2179
2219
  (agent) => agent !== who && team.includes(agent)
2180
2220
  );
2181
2221
  // An answer that carries something like a key is held for the person, as any post is, and the room hears that it was.
@@ -2244,6 +2284,47 @@ export async function startDaemon() {
2244
2284
  agent === "user" ||
2245
2285
  agent === goal.goal.facilitator ||
2246
2286
  goal.goal.team.includes(agent);
2287
+ // The person's reaction to their agents' work, read when they post after it (reactions.mjs).
2288
+ const reactions = createReactions({
2289
+ store,
2290
+ askHarness,
2291
+ readsReactions: () =>
2292
+ coordinatorMode() !== "local" &&
2293
+ state.connected &&
2294
+ serverFeatures.has("swarm_reactions"),
2295
+ isCoordinatorPost: (post) =>
2296
+ Boolean(store.meta(`coordinator-post:${post.id}`)),
2297
+ log,
2298
+ });
2299
+ // What the swarm learns from the person's posts (lessons.mjs), kept apart from Harness's own memory.
2300
+ const lessons = createLessons({
2301
+ store,
2302
+ askHarness,
2303
+ isTaskRoom: (thread) => Boolean(store.meta(`task-room:${thread.id}`)),
2304
+ readsLessons: () =>
2305
+ coordinatorMode() !== "local" &&
2306
+ state.connected &&
2307
+ serverFeatures.has("swarm_lessons"),
2308
+ isCoordinatorPost: (post) =>
2309
+ Boolean(store.meta(`coordinator-post:${post.id}`)),
2310
+ embed: async (texts, kind) =>
2311
+ embedderReady()
2312
+ ? inference.embed(
2313
+ texts.map((text) =>
2314
+ kind === "document"
2315
+ ? { kind, title: "none", text }
2316
+ : { kind, text }
2317
+ ),
2318
+ { lane: "background" }
2319
+ )
2320
+ : null,
2321
+ log,
2322
+ });
2323
+ // Everything the person writes in a thread is read for their reaction to the work before it and for lessons.
2324
+ const heardPerson = (thread, post) => {
2325
+ void reactions.heard(thread, post);
2326
+ void lessons.heard(thread, post);
2327
+ };
2247
2328
  const goalCommand = (request, agent) => {
2248
2329
  const id = String(request.id || "");
2249
2330
  if (request.command === "board.goal.create") {
@@ -2440,6 +2521,7 @@ export async function startDaemon() {
2440
2521
  mentions,
2441
2522
  });
2442
2523
  replaceHeld(goal.id, agent, post);
2524
+ if (agent === "user") heardPerson(goal, post);
2443
2525
  if (verdict?.verdict === "flag")
2444
2526
  store.meta(`flagged:${post.id}`, String(verdict.score));
2445
2527
  // Shared with guests: the post goes out on each guest's thread, held for the owner unless that thread auto-sends.
@@ -3188,11 +3270,14 @@ export async function startDaemon() {
3188
3270
  `rendering:${place.id}`,
3189
3271
  JSON.stringify(rendering.filter((each) => each.jobId !== jobId))
3190
3272
  );
3191
- // Made after Harness answered (a video renders for minutes): said in the thread, waking whoever asked.
3273
+ // Made after Harness answered (a video renders for minutes): said in the thread, waking whoever asked. Asked by
3274
+ // Harness itself (the coordinator handing work on in its name), there is no one else to wake and the file's own post
3275
+ // shows it (October 16, the content factory: five "Made for Harness" posts, each a copy of the file posted above it).
3192
3276
  if (
3193
3277
  ["done", "failed"].includes(task.status) &&
3194
3278
  place.kind === "goal" &&
3195
- place.status === "open"
3279
+ place.status === "open" &&
3280
+ task.origin_agent !== "harness"
3196
3281
  ) {
3197
3282
  const forWhom =
3198
3283
  task.origin_agent === "user" ? "you" : nameOf(task.origin_agent);
@@ -3415,11 +3500,41 @@ export async function startDaemon() {
3415
3500
  };
3416
3501
  const presenceTimer = setInterval(notePresence, 60_000);
3417
3502
  presenceTimer.unref?.();
3503
+ // Check-ins (schedules.mjs): a run posts in the thread as its lead and wakes the agents it names, on the person's go
3504
+ // when the person set it and the lead's when the lead did; one that names none gives the lead a round.
3505
+ const checkIn = (schedule, { late }) => {
3506
+ const thread = store.getTask(schedule.threadId);
3507
+ const lead = thread.goal.facilitator;
3508
+ const setBy = schedule.by === "user" ? "you set" : "the lead set";
3509
+ // Named in the words too, as an @mention is: the thread shows who it is for, and Harness takes the person's ask by it.
3510
+ const named = schedule.agents.map((agent) => `@${agent} `).join("");
3511
+ const post = store.roomPost({
3512
+ goalId: thread.id,
3513
+ author: lead,
3514
+ kind: "check_in",
3515
+ text: `${named}Check-in ${setBy} (${schedule.when}): ${schedule.what}${late ? ` It was due at ${late} and ran when the relay was back.` : ""}`,
3516
+ mentions: schedule.agents,
3517
+ });
3518
+ if (post) store.meta(`coordinator-post:${post.id}`, "1");
3519
+ store.meta(`check-in-at:${thread.id}`, new Date().toISOString());
3520
+ if (schedule.agents.length)
3521
+ wakeFor(
3522
+ thread.id,
3523
+ { ...post, kind: "post" },
3524
+ schedule.by === "user" ? "user" : lead,
3525
+ schedule.agents,
3526
+ { why: `a check-in ${setBy} for this thread` }
3527
+ );
3528
+ else coordinator.poke(thread.id);
3529
+ notifyBoard(store.getTask(thread.id));
3530
+ };
3531
+ const schedules = createSchedules({ store, log, fire: checkIn });
3418
3532
  // An ask lost on the way to Harness while this computer stayed connected goes again (asks.mjs).
3419
3533
  const askRetry = setInterval(() => asks.retry(), 60_000);
3420
3534
  askRetry.unref?.();
3421
3535
  const coordinator = createCoordinator({
3422
3536
  store,
3537
+ lessons,
3423
3538
  busyInT3: (thread) =>
3424
3539
  thread.goal.team.filter((agent) => {
3425
3540
  const threadId = store.meta(`t3-thread:${thread.id}:${agent}`);
@@ -3430,6 +3545,7 @@ export async function startDaemon() {
3430
3545
  );
3431
3546
  }),
3432
3547
  goals,
3548
+ schedules,
3433
3549
  // A goal whose every check is reached: the thread's answer says so and the thread is done.
3434
3550
  finishGoal: (goalId, by) =>
3435
3551
  goalCommand(
@@ -3474,6 +3590,8 @@ export async function startDaemon() {
3474
3590
  const swarmCommand = createSwarm({
3475
3591
  store,
3476
3592
  goals,
3593
+ heardPerson,
3594
+ lessons,
3477
3595
  reofferHarness: () => reofferHarness(),
3478
3596
  roomAgents: ROOM_AGENTS,
3479
3597
  mentionsIn,
@@ -3503,6 +3621,7 @@ export async function startDaemon() {
3503
3621
  listModels,
3504
3622
  threadFiles,
3505
3623
  whyWaiting: (goalId, run) => whyWaiting(goalId, run),
3624
+ schedules,
3506
3625
  });
3507
3626
 
3508
3627
  // The person's own sessions running now (live.mjs), and what they sent one from Harness: it waits here until that
@@ -3801,6 +3920,9 @@ export async function startDaemon() {
3801
3920
  const tally = new Map();
3802
3921
  for (const place of Object.values(placesOf(agentId))) {
3803
3922
  if (!place?.kind || place.kind === "unknown") continue;
3923
+ // An agent T3 does not run, started from a shell inside T3 Code, is not one T3 can show (October 16: OpenCode's
3924
+ // home was T3, and Open on it landed on Claude Code's T3 thread).
3925
+ if (place.kind === "t3" && !t3Provider(agentId)) continue;
3804
3926
  const entry = tally.get(placeKey(place)) ?? { place, count: 0 };
3805
3927
  entry.count += 1;
3806
3928
  if ((place.seen || 0) >= (entry.place.seen || 0)) entry.place = place;
@@ -3853,7 +3975,7 @@ export async function startDaemon() {
3853
3975
  ? `${nameOf(agentId)} is still working on this${folder ? ` in ${path.basename(folder)}` : ""}; Open it again once it's done to carry on in the same session.`
3854
3976
  : null;
3855
3977
  if (place.kind === "t3") {
3856
- if (!place.app) return null;
3978
+ if (!place.app || !t3Provider(agentId)) return null;
3857
3979
  const thread = sessionId ? t3Thread(sessionId) : null;
3858
3980
  if (thread && t3OpensLinks(place.app))
3859
3981
  return { opensIn: "T3 Code", link: t3Link(thread) };
@@ -3995,35 +4117,53 @@ export async function startDaemon() {
3995
4117
  * where it would open, for Open's label.
3996
4118
  */
3997
4119
  const openPlan = (agentId, sessionId, folder, act) => {
3998
- // A session a thread's run is working in is not opened a second time: two processes in one session each finished
3999
- // the job their own way (October 11, two different PRDs from one job). The thread shows the run, and Stop.
4120
+ // A T3 Code thread itself (a turn Harness handed to T3) opens there, wherever the agent usually works, and even while
4121
+ // the turn runs: T3 runs that one turn and takes what the person types there in turn, so nothing runs twice.
4122
+ if (sessionId && t3Thread(sessionId) === sessionId) {
4123
+ const plan = placePlan(
4124
+ agentId,
4125
+ usable({ kind: "t3", name: "T3 Code" }),
4126
+ sessionId,
4127
+ folder,
4128
+ act
4129
+ );
4130
+ if (plan) return plan;
4131
+ }
4132
+ // A session one of Harness's runs is working in on this computer is not opened a second time: two processes in one
4133
+ // session each finished the job their own way (October 11, two different PRDs from one job). An editor the agent
4134
+ // lives in comes up on the run's folder and says it is still working (placePlan); anywhere else the run is followed
4135
+ // in its thread, which shows its steps as they come, and Stop. Only a run Harness started holds a session: a task
4136
+ // the person's own session claimed through its MCP server is that session at work, opened where it runs.
4000
4137
  const holding = sessionId
4001
4138
  ? store.runHoldingSession(agentId, sessionId)
4002
4139
  : null;
4003
- if (holding)
4140
+ if (
4141
+ holding &&
4142
+ [...activeRuns.values()].some(({ id }) => id === holding.id)
4143
+ ) {
4144
+ const home = homeOf(agentId);
4145
+ const shown =
4146
+ home?.kind === "editor"
4147
+ ? placePlan(agentId, home, sessionId, folder, act)
4148
+ : null;
4149
+ if (shown?.app && !shown.link && !shown.resume && !shown.copy)
4150
+ return shown;
4151
+ const thread = holding.parent_id ?? null;
4004
4152
  return {
4005
- opensIn: null,
4153
+ opensIn: thread ? "the thread" : null,
4006
4154
  run: holding.id,
4007
- thread: holding.parent_id ?? null,
4008
- note: `A thread's run is working in this ${nameOf(agentId)} session right now. Follow it in the thread, or stop it there before opening the session.`,
4155
+ thread,
4156
+ note: thread
4157
+ ? `A thread's run is working in this ${nameOf(agentId)} session right now, so it opens in that thread. Once the run is done, Open carries on in the session itself.`
4158
+ : `One of Harness's runs is working in this ${nameOf(agentId)} session right now. Open it again once the run is done.`,
4009
4159
  };
4160
+ }
4010
4161
  const live = sessionId
4011
4162
  ? (liveNow().find(
4012
4163
  (row) => row.agent === agentId && row.sessionId === sessionId
4013
4164
  ) ?? null)
4014
4165
  : null;
4015
4166
  if (live) return runningPlan(live, act);
4016
- // A T3 Code thread itself (a turn Harness handed to T3) opens there, wherever the agent usually works.
4017
- if (sessionId && t3Thread(sessionId) === sessionId) {
4018
- const plan = placePlan(
4019
- agentId,
4020
- usable({ kind: "t3", name: "T3 Code" }),
4021
- sessionId,
4022
- folder,
4023
- act
4024
- );
4025
- if (plan) return plan;
4026
- }
4027
4167
  const own = sessionId ? (placesOf(agentId)[sessionId] ?? null) : null;
4028
4168
  const where = folder ?? own?.folder ?? null;
4029
4169
  if (own?.reopen?.link)
@@ -4905,8 +5045,16 @@ export async function startDaemon() {
4905
5045
  const extra = finished.length ? { finished } : {};
4906
5046
  // A session starting (nudge.mjs, the Pi and OpenCode plugins) also hears who else is in the swarm.
4907
5047
  if (request.swarm) {
4908
- const cards = cardsFor(available().filter((name) => name !== agent));
4909
- extra.swarm = { text: swarmBlock(cards), digest: swarmDigest(cards) };
5048
+ const local = request.hostedCaller !== true;
5049
+ const cards = cardsFor(
5050
+ available().filter((name) => name !== agent),
5051
+ { lessons: local }
5052
+ );
5053
+ const told = local ? lessons.told() : [];
5054
+ extra.swarm = {
5055
+ text: swarmBlock(cards, Date.now(), told),
5056
+ digest: swarmDigest(cards, told),
5057
+ };
4910
5058
  }
4911
5059
  return request.unread
4912
5060
  ? {
@@ -5648,7 +5796,8 @@ export async function startDaemon() {
5648
5796
  // The context engine's pack (context.mjs): the files in this repository most likely needed and earlier sessions on
5649
5797
  // them. The request is the task's own words, or for a thread turn the thread and its newest posts.
5650
5798
  let context = "",
5651
- framed = "";
5799
+ framed = "",
5800
+ learned = "";
5652
5801
  try {
5653
5802
  const thread = wake ? store.getTask(task.parent_id) : null;
5654
5803
  const request = thread
@@ -5703,6 +5852,20 @@ export async function startDaemon() {
5703
5852
  ? frameFor(threadId, { pack: found })
5704
5853
  : null;
5705
5854
  framed = frame ? frames.briefText(frame, agent) : "";
5855
+ // What the person has told the swarm that fits this work (lessons.mjs), kept on the run so its outcome can be read
5856
+ // against the lessons it carried.
5857
+ const home =
5858
+ store.getTask(threadId ?? "")?.goal?.workspace ?? task.run_workspace;
5859
+ const carried = RUNNERS.has(agent)
5860
+ ? await lessons.forWork({ agent, folder: home, text: request })
5861
+ : [];
5862
+ if (carried.length) {
5863
+ learned = `\n\n${toldBlock(carried)}`;
5864
+ store.meta(
5865
+ `lessons-carried:${task.id}`,
5866
+ JSON.stringify(carried.map((lesson) => lesson.id))
5867
+ );
5868
+ }
5706
5869
  if (framed) {
5707
5870
  localEvent(
5708
5871
  "frame",
@@ -5718,7 +5881,7 @@ export async function startDaemon() {
5718
5881
  log(`context pack for ${task.id}: ${error.message}`);
5719
5882
  }
5720
5883
  const brief =
5721
- `${notice ? `${notice}\n\n` : ""}${task.objective}\n\n${task.brief}${refs}${guide}${framed}${memory}${context}`.trim();
5884
+ `${notice ? `${notice}\n\n` : ""}${task.objective}\n\n${task.brief}${refs}${guide}${framed}${learned}${memory}${context}`.trim();
5722
5885
  const startedAt = new Date().toISOString();
5723
5886
  // A run stopped for a safety rule continues its own session with a note; an agent without one starts over, told why.
5724
5887
  const stoppedFor = store.meta(`requeued:${task.id}`);
@@ -5727,6 +5890,10 @@ export async function startDaemon() {
5727
5890
  : stoppedFor
5728
5891
  ? task.session_id || undefined
5729
5892
  : undefined;
5893
+ // The session it resumes is the run's from its first moment, so Open never resumes it beside the run before the agent
5894
+ // says which session it is in (October 16: OpenCode said so only minutes into its turn).
5895
+ if (resumeSession && !task.session_id)
5896
+ store.setRunSession(task.id, resumeSession);
5730
5897
  const again = stoppedFor
5731
5898
  ? `This task was stopped partway because ${stoppedFor}. Continue from where you left off; check the folder for what you already changed.`
5732
5899
  : "";
@@ -5736,16 +5903,20 @@ export async function startDaemon() {
5736
5903
  task.trust !== "user" &&
5737
5904
  task.run_authorized_by === "goal" &&
5738
5905
  store.meta(`person-wake:${task.id}`) !== "1";
5739
- // The model and effort it starts with (models.mjs), kept on the run with who chose them; without a choice, the model
5740
- // the agent's own settings name, so each model's record covers every run.
5906
+ // The model and effort it runs with are the ones the buddy shows for the agent: the person's pick (models.mjs), else
5907
+ // the ones its own settings name. Both are named on every run, here and in T3 Code, so neither a session it resumes
5908
+ // nor a T3 thread's earlier selection runs it on another (October 17: Codex ran on gpt-6-astra for days in T3
5909
+ // while the buddy showed gpt-6.1-sol). Kept on the run with who chose them, so each model's record covers every run.
5741
5910
  const chosen = await modelForRun(task, agent);
5742
- const { model = null, effort = null } = chosen ?? {};
5911
+ const picked = Boolean(chosen?.model);
5912
+ const model = chosen?.model ?? modelOf(agent);
5913
+ const effort = chosen?.effort ?? effortOf(agent);
5743
5914
  store.setRunModel(task.id, {
5744
5915
  ...chosen,
5745
- model: model ?? modelOf(agent),
5916
+ model,
5746
5917
  effort,
5747
- by: model ? chosen.by : (chosen?.by ?? "its settings"),
5748
- ...(model ? {} : { ownSettings: true }),
5918
+ by: picked ? chosen.by : (chosen?.by ?? "its settings"),
5919
+ ...(picked ? {} : { ownSettings: true }),
5749
5920
  });
5750
5921
  const t3 =
5751
5922
  store.meta(`t3-run:${task.id}`) === "1"
@@ -5829,9 +6000,11 @@ export async function startDaemon() {
5829
6000
  // A stopped run's task is already closed, so nothing else frees the agent's next run.
5830
6001
  setImmediate(runBoard);
5831
6002
  if (extra?.usage) store.setRunUsage(task.id, extra.usage);
6003
+ // A run that failed without reaching its agent's own report ended early: the runner says why.
5832
6004
  const reported = store.reportTask(task.id, agent, {
5833
6005
  status: kind,
5834
6006
  result: text || "",
6007
+ failure: extra?.failure ?? "exit",
5835
6008
  });
5836
6009
  if (reported.ok) notifyBoard(reported.task);
5837
6010
  else
@@ -6882,7 +7055,7 @@ export async function startDaemon() {
6882
7055
  // is executed at most once: a known record answers with its outcome instead of a rerun.
6883
7056
  const startTask = (message, report) => {
6884
7057
  if (!validRunId(message.runId)) {
6885
- report("failed", "Invalid task run id.");
7058
+ report("failed", "Invalid task run id.", { failure: "start" });
6886
7059
  return;
6887
7060
  }
6888
7061
  // A run id is executed at most once, even if the same task arrives again.
@@ -6890,12 +7063,17 @@ export async function startDaemon() {
6890
7063
  // The daemon stopped this run itself and knows it ended: the next attempt keeps its log and record.
6891
7064
  if (known && !(message.again && known.status === "requeued")) {
6892
7065
  if (known.status === "done" || known.status === "failed")
6893
- report(known.status, known.message || undefined);
7066
+ report(
7067
+ known.status,
7068
+ known.message || undefined,
7069
+ known.failure ? { failure: known.failure } : undefined
7070
+ );
6894
7071
  else if (known.status === "running") report("accepted");
6895
7072
  else
6896
7073
  report(
6897
7074
  "failed",
6898
- "This run was interrupted earlier and is not started again."
7075
+ "This run was interrupted earlier and is not started again.",
7076
+ { failure: "exit" }
6899
7077
  );
6900
7078
  return;
6901
7079
  }
@@ -6929,6 +7107,7 @@ export async function startDaemon() {
6929
7107
  task.finishedAt = new Date().toISOString();
6930
7108
  task.message = text || null;
6931
7109
  if (extra?.usage) task.usage = extra.usage;
7110
+ if (extra?.failure) task.failure = extra.failure;
6932
7111
  }
6933
7112
  task.updatedAt = new Date().toISOString();
6934
7113
  persistTask(task);
@@ -7549,6 +7728,8 @@ export async function startDaemon() {
7549
7728
  };
7550
7729
  connect();
7551
7730
  setImmediate(runBoard);
7731
+ // Check-ins start once everything they wake through is ready: what came due while the relay was off runs now.
7732
+ schedules.start();
7552
7733
  // A ping still unanswered when the next is due means the connection is dead: after a Wi-Fi drop a socket can
7553
7734
  // stay open for minutes with nothing behind it. Measured 2026-10-10 against production over in-flight satellite
7554
7735
  // Wi-Fi, 420 round trips: p50 766 ms, p99 1.09 s, one stall of 14.0 s, so one interval is about twice the worst.
@@ -7617,6 +7798,7 @@ export async function startDaemon() {
7617
7798
  contextEngine.stop();
7618
7799
  } catch {}
7619
7800
  watches.stop();
7801
+ schedules.stop();
7620
7802
  clearInterval(presenceTimer);
7621
7803
  clearInterval(askRetry);
7622
7804
  inference.stop();
package/lib/desktop.mjs CHANGED
@@ -287,11 +287,14 @@ export function retireDesktop({
287
287
  if (installed.path)
288
288
  quitDesktop({ target: installed.path, platform, execute });
289
289
  // Where the app's own login item lives (tauri-plugin-autostart, named after the product).
290
- if (platform === "darwin")
291
- fs.rmSync(path.join(homeDir, "Library", "LaunchAgents", "Harness.plist"), {
292
- force: true,
293
- });
294
- else if (platform === "linux")
290
+ if (platform === "darwin") {
291
+ const agents = path.join(homeDir, "Library", "LaunchAgents");
292
+ fs.rmSync(path.join(agents, "Harness.plist"), { force: true });
293
+ // Lid-Closed Mode's crash backstop (backstop.rs in the app), which would go on starting a removed app every minute.
294
+ const backstop = "ai.tryharness.lid-backstop";
295
+ execute("launchctl", ["bootout", `gui/${process.getuid()}/${backstop}`]);
296
+ fs.rmSync(path.join(agents, `${backstop}.plist`), { force: true });
297
+ } else if (platform === "linux")
295
298
  fs.rmSync(path.join(homeDir, ".config", "autostart", "Harness.desktop"), {
296
299
  force: true,
297
300
  });
package/lib/digest.mjs CHANGED
@@ -13,6 +13,32 @@ const clip = (text, length) => {
13
13
  return flat.length > length ? `${flat.slice(0, length - 1)}…` : flat;
14
14
  };
15
15
 
16
+ // What the swarm learned from the person since (lessons.mjs), and what they had to say again after agents had been told.
17
+ function learnedLines(store, since) {
18
+ const kept = store.lessons?.({ limit: 200 }) ?? [];
19
+ const quoted = (lessons) =>
20
+ `${lessons
21
+ .slice(0, 2)
22
+ .map((lesson) => `"${clip(lesson.text.replace(/\.$/, ""), 70)}"`)
23
+ .join(
24
+ "; "
25
+ )}${lessons.length > 2 ? ` and ${lessons.length - 2} more` : ""}`;
26
+ const learned = kept.filter((lesson) => lesson.created_at > since);
27
+ const again = kept.filter((lesson) =>
28
+ lesson.evidence.some((entry) => entry.carried && entry.at > since)
29
+ );
30
+ return [
31
+ ...(learned.length
32
+ ? [`Learned from what you said: ${quoted(learned)}.`]
33
+ : []),
34
+ ...(again.length
35
+ ? [
36
+ `You had to say again what your agents had been told: ${quoted(again)}.`,
37
+ ]
38
+ : []),
39
+ ];
40
+ }
41
+
16
42
  /** { since, lines, threads, empty }: lines are plain sentences, threads their ids for opening them. */
17
43
  export function digestSince(
18
44
  store,
@@ -73,6 +99,7 @@ export function digestSince(
73
99
  if (threads.length >= MAX_THREADS) break;
74
100
  }
75
101
  for (const alert of alerts) lines.push(`Watch: ${alert.text}`);
102
+ lines.push(...learnedLines(store, since));
76
103
  if (learning?.kept && learning.at > since)
77
104
  lines.push(
78
105
  `Learned from ${learning.runs} runs: briefs now hold the files agents went on to change ${Math.round(learning.recallAt10.candidate * 100)}% of the time (was ${Math.round(Math.max(learning.recallAt10.default, learning.recallAt10.current ?? 0) * 100)}%).`