tryharness 0.7.67 → 0.7.68
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/boardFileCommands.mjs +5 -7
- package/lib/boardFiles.mjs +5 -0
- package/lib/boardProtocol.json +3 -0
- package/lib/boardWaits.mjs +6 -0
- package/lib/context.mjs +34 -20
- package/lib/contextWorker.mjs +199 -0
- package/lib/coordinator.mjs +23 -9
- package/lib/daemon.mjs +54 -8
- package/lib/environment.mjs +54 -69
- package/lib/files.mjs +35 -0
- package/lib/frames.mjs +5 -9
- package/lib/goalCommands.mjs +13 -10
- package/lib/kept.mjs +131 -0
- package/lib/landed.mjs +1 -34
- package/lib/library.mjs +18 -11
- package/lib/live.mjs +30 -11
- package/lib/localStack.mjs +17 -13
- package/lib/mcp-stdio.mjs +1 -1
- package/lib/openHere.mjs +36 -0
- package/lib/openRequests.mjs +56 -0
- package/lib/ownMachines.mjs +55 -1
- package/lib/phones.mjs +29 -4
- package/lib/places.mjs +44 -11
- package/lib/portCalls.mjs +54 -0
- package/lib/runBrief.mjs +1 -1
- package/lib/sealed.mjs +37 -0
- package/lib/sessionControl.mjs +47 -14
- package/lib/sessionIndex.mjs +11 -3
- package/lib/store.mjs +137 -27
- package/lib/swarm.mjs +85 -34
- package/lib/swarmMemory.mjs +39 -16
- package/lib/team.mjs +18 -13
- package/lib/threadBriefs.mjs +19 -8
- package/npm-shrinkwrap.json +14 -14
- package/package.json +4 -4
- package/release.json +37 -32
package/lib/localStack.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import os from "node:os";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { execFile } from "node:child_process";
|
|
5
5
|
import { ATLAS_VERSION } from "./atlas.mjs";
|
|
6
|
-
import {
|
|
6
|
+
import { createContextWorker } from "./contextWorker.mjs";
|
|
7
7
|
import { createCoreModels } from "./coreModels.mjs";
|
|
8
8
|
import { readJson, writeJsonAtomic } from "./files.mjs";
|
|
9
9
|
import { createFirewall } from "./firewall.mjs";
|
|
@@ -41,7 +41,7 @@ const COMMANDS = new Set([
|
|
|
41
41
|
*
|
|
42
42
|
* - The context space (search): the search model embeds it in the background, a batch at a time, so no request waits
|
|
43
43
|
* on it; until it is present, search answers from words and says so.
|
|
44
|
-
* - The context engine (context.mjs): the atlas of the folders the swarm works in, what every coding session there
|
|
44
|
+
* - The context engine (context.mjs, in its own thread: contextWorker.mjs): the atlas of the folders the swarm works in, what every coding session there
|
|
45
45
|
* needed, a context pack for each local agent's brief, the overnight learner, and the library of the person's own
|
|
46
46
|
* files. Documents and PDFs need only the search model; pictures, recordings and video wait for its image and audio
|
|
47
47
|
* part, which comes down on the charger.
|
|
@@ -195,7 +195,7 @@ export function createLocalStack({
|
|
|
195
195
|
path: namedPath(file),
|
|
196
196
|
}));
|
|
197
197
|
|
|
198
|
-
const contextEngine =
|
|
198
|
+
const contextEngine = createContextWorker({
|
|
199
199
|
store,
|
|
200
200
|
inference,
|
|
201
201
|
home: root,
|
|
@@ -248,10 +248,13 @@ export function createLocalStack({
|
|
|
248
248
|
const file = store.file(fileId);
|
|
249
249
|
return Boolean(file) && (!hostedCaller || file.cloud);
|
|
250
250
|
};
|
|
251
|
+
const allowed = libraryThreadFiles()
|
|
252
|
+
.filter((file) => file.thread === thread && readable(file.id))
|
|
253
|
+
.map((file) => file.id);
|
|
251
254
|
try {
|
|
252
255
|
const hits = await contextEngine.searchFiles(query, {
|
|
253
256
|
threads: [thread],
|
|
254
|
-
|
|
257
|
+
allowed,
|
|
255
258
|
limit: 5,
|
|
256
259
|
});
|
|
257
260
|
return hits.map((hit) =>
|
|
@@ -458,12 +461,15 @@ export function createLocalStack({
|
|
|
458
461
|
const command = (request) => {
|
|
459
462
|
switch (request.command) {
|
|
460
463
|
case "local.status":
|
|
461
|
-
return
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
464
|
+
return contextEngine.status().then(
|
|
465
|
+
(status) => ({
|
|
466
|
+
ok: true,
|
|
467
|
+
...status,
|
|
468
|
+
coreModels: coreModels.status(),
|
|
469
|
+
learning: contextEngine.report(),
|
|
470
|
+
}),
|
|
471
|
+
(error) => ({ ok: false, error: error.message })
|
|
472
|
+
);
|
|
467
473
|
case "local.learn":
|
|
468
474
|
void contextEngine
|
|
469
475
|
.learn({ force: true })
|
|
@@ -506,9 +512,7 @@ export function createLocalStack({
|
|
|
506
512
|
|
|
507
513
|
const stop = () => {
|
|
508
514
|
clearInterval(embedTimer);
|
|
509
|
-
|
|
510
|
-
contextEngine.stop();
|
|
511
|
-
} catch {}
|
|
515
|
+
void contextEngine.stop().catch(() => {});
|
|
512
516
|
inference.stop();
|
|
513
517
|
};
|
|
514
518
|
|
package/lib/mcp-stdio.mjs
CHANGED
|
@@ -437,7 +437,7 @@ const LOCAL_TOOLS = [
|
|
|
437
437
|
{
|
|
438
438
|
name: "post_to_room",
|
|
439
439
|
description:
|
|
440
|
-
|
|
440
|
+
'Post in a goal\'s room for the whole team: a finding, partial work, a question or what you did. To ask another agent for help, or to hand it the next step (a review, the next part of the work), put its name in ask (claude-code, codex, pi, opencode, grok-bot, openclaw, hermes, bankr, quotient, muse, or harness to have the thread coordinated), say exactly what you need, then stop: you are woken again when it answers you by name. When you answer someone who asked you, name them (@codex) and they are woken. To have a coding agent run on a particular model, write it after the name, @codex:gpt-6-luna or @codex:gpt-6-luna/high with an effort, from list_models. A name only in your text, like "Next: @codex" or a thanks, wakes no one: the thread then waits for Harness to pass it on. Post results and sources, not secrets: anything that looks like a key is held. For work someone else should do, post_task with parent_id set to the goal id.',
|
|
441
441
|
inputSchema: {
|
|
442
442
|
type: "object",
|
|
443
443
|
properties: {
|
package/lib/openHere.mjs
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Open on this computer, by the daemon itself, where the buddy would have opened it: a link (a T3 Code or Codex thread)
|
|
5
|
+
* or an app. For the phone's Open (landed.mjs) and another computer's Open with no buddy running here
|
|
6
|
+
* (openRequests.mjs). The link and the app are this computer's own reading of the work, never the caller's. A test
|
|
7
|
+
* stands in for the opener with HARNESS_OPEN_COMMAND, as notify.mjs takes HARNESS_NOTIFY_COMMAND.
|
|
8
|
+
*/
|
|
9
|
+
export function openHere(plan) {
|
|
10
|
+
if (!plan.ok || (!plan.link && !plan.app)) return plan;
|
|
11
|
+
const args =
|
|
12
|
+
process.platform === "darwin"
|
|
13
|
+
? plan.link
|
|
14
|
+
? [plan.link]
|
|
15
|
+
: ["-a", plan.app]
|
|
16
|
+
: plan.link
|
|
17
|
+
? [plan.link]
|
|
18
|
+
: null;
|
|
19
|
+
if (!args)
|
|
20
|
+
return {
|
|
21
|
+
ok: false,
|
|
22
|
+
error: `${plan.opensIn ?? "Its app"} can only be opened on this computer itself.`,
|
|
23
|
+
};
|
|
24
|
+
const child = spawn(
|
|
25
|
+
process.env.HARNESS_OPEN_COMMAND ||
|
|
26
|
+
(process.platform === "darwin" ? "open" : "xdg-open"),
|
|
27
|
+
args,
|
|
28
|
+
{
|
|
29
|
+
detached: true,
|
|
30
|
+
stdio: "ignore",
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
child.on("error", () => {});
|
|
34
|
+
child.unref();
|
|
35
|
+
return { ok: true, opensIn: plan.opensIn, openedHere: true };
|
|
36
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Open on another of the person's computers (owner, October 28: an agent on another computer opens "on that
|
|
2
|
+
// computer"). That computer plans the Open as its own buddy's Open would (sessionControl.mjs board.live.focus, a T3
|
|
3
|
+
// Code thread by its own link) and its buddy carries it out, so it lands where the person would go to see it there: a
|
|
4
|
+
// T3 thread, a terminal resuming the session, an editor. The buddy hears of it as it hears of any change, from
|
|
5
|
+
// board.wait, and takes it with board.live.opens. With no buddy waiting here, a link or an app opens by the daemon
|
|
6
|
+
// itself, as the phone's Open does (openHere.mjs); anything else says it needs the buddy.
|
|
7
|
+
|
|
8
|
+
// An Open the buddy has not taken within this is dropped, so a buddy started later never opens something the person
|
|
9
|
+
// asked for long before; and a buddy that waited on the board within it is still there, between two of its waits.
|
|
10
|
+
// Measured on this Mac (M5 Pro) with the buddy installed, October 28, 19 samples: handed over to taken 58 to 196 ms
|
|
11
|
+
// (median about 110 ms); one Open arrived while the daemon was busy (3.5 s to answer) and the buddy between waits.
|
|
12
|
+
// 10 s is fifty times the slowest and covers the daemon's stalls of up to 1.8 s after a restart.
|
|
13
|
+
const KEEP_MS = 10_000;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* `plan(open)` plans an Open here as the person: { to, sessionId, folder, fresh } for an agent's session (or, fresh,
|
|
17
|
+
* the agent itself where they use it), { thread } for a thread in this computer's T3 Code. `waits` is the board's
|
|
18
|
+
* (boardWaits.mjs): whether a buddy waits on this computer, and the bump that wakes it.
|
|
19
|
+
*/
|
|
20
|
+
export function createOpenRequests({
|
|
21
|
+
plan,
|
|
22
|
+
waits,
|
|
23
|
+
openHere,
|
|
24
|
+
log = () => {},
|
|
25
|
+
now = Date.now,
|
|
26
|
+
keepMs = KEEP_MS,
|
|
27
|
+
}) {
|
|
28
|
+
let queued = [];
|
|
29
|
+
|
|
30
|
+
const open = async (request) => {
|
|
31
|
+
const planned = await plan(request);
|
|
32
|
+
if (!planned?.ok) return planned;
|
|
33
|
+
if (now() - waits.waitedAt() > keepMs) {
|
|
34
|
+
const opened = openHere(planned);
|
|
35
|
+
if (opened.openedHere || !opened.ok) return opened;
|
|
36
|
+
return {
|
|
37
|
+
ok: false,
|
|
38
|
+
error: `${planned.opensIn ?? "It"} opens there only with Harness's buddy running on that computer.`,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
queued.push({ plan: planned, at: now() });
|
|
42
|
+
waits.bump();
|
|
43
|
+
return { ok: true, opensIn: planned.opensIn ?? null, openedThere: true };
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/** The buddy's: the Opens asked for since it last took them, oldest first. */
|
|
47
|
+
const take = () => {
|
|
48
|
+
const fresh = queued.filter(({ at }) => now() - at <= keepMs);
|
|
49
|
+
for (const { at } of queued)
|
|
50
|
+
log(`open for another computer taken after ${now() - at} ms`);
|
|
51
|
+
queued = [];
|
|
52
|
+
return { ok: true, plans: fresh.map(({ plan: planned }) => planned) };
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
return { open, take };
|
|
56
|
+
}
|
package/lib/ownMachines.mjs
CHANGED
|
@@ -2350,10 +2350,63 @@ export function createOwnMachines({
|
|
|
2350
2350
|
);
|
|
2351
2351
|
};
|
|
2352
2352
|
|
|
2353
|
-
/**
|
|
2353
|
+
/**
|
|
2354
|
+
* Open, on the computer an agent's session or thread is on, where the person would go to see it there (owner, October
|
|
2355
|
+
* 28): that computer plans and opens it (openRequests.mjs). Home reaches the worker; a worker goes through home.
|
|
2356
|
+
*/
|
|
2357
|
+
const openSession = async (request) => {
|
|
2358
|
+
const target = String(request.machine || machine.id);
|
|
2359
|
+
const open = {
|
|
2360
|
+
to: request.to,
|
|
2361
|
+
sessionId: request.sessionId,
|
|
2362
|
+
folder: request.folder,
|
|
2363
|
+
fresh: request.fresh === true,
|
|
2364
|
+
// Or a thread in that computer's T3 Code.
|
|
2365
|
+
thread: request.thread,
|
|
2366
|
+
};
|
|
2367
|
+
if (target === machine.id) return ownLive({ open });
|
|
2368
|
+
if (isHome()) {
|
|
2369
|
+
if (
|
|
2370
|
+
!siblings.some((sibling) => sibling.id === target && confirmed(sibling))
|
|
2371
|
+
)
|
|
2372
|
+
return { ok: false, error: "that computer is not in your swarm" };
|
|
2373
|
+
const answer = await askWorker(target, { live: { open } });
|
|
2374
|
+
if (!answer)
|
|
2375
|
+
return {
|
|
2376
|
+
ok: false,
|
|
2377
|
+
error: `${labelOf(target) ?? "That computer"} did not answer`,
|
|
2378
|
+
};
|
|
2379
|
+
// A computer older than Open there answers that it only lists and reads.
|
|
2380
|
+
if (!answer.ok && /listed or read/.test(String(answer.error)))
|
|
2381
|
+
return {
|
|
2382
|
+
ok: false,
|
|
2383
|
+
error: `${labelOf(target) ?? "That computer"} opens things for you once it has the latest tryharness.`,
|
|
2384
|
+
};
|
|
2385
|
+
return answer;
|
|
2386
|
+
}
|
|
2387
|
+
const pinned = pinnedHome();
|
|
2388
|
+
if (!pinned) return { ok: false, error: unreachableNote(null) };
|
|
2389
|
+
const answer = await callOnce(pinned, {
|
|
2390
|
+
command: LIVE_COMMAND,
|
|
2391
|
+
agent: "user",
|
|
2392
|
+
open,
|
|
2393
|
+
machine: target,
|
|
2394
|
+
});
|
|
2395
|
+
// A home older than Open there answers with every computer's sessions instead.
|
|
2396
|
+
if (answer?.ok && answer.computers)
|
|
2397
|
+
return {
|
|
2398
|
+
ok: false,
|
|
2399
|
+
error:
|
|
2400
|
+
"Your home computer passes this on once it has the latest tryharness.",
|
|
2401
|
+
};
|
|
2402
|
+
return answer ?? offline();
|
|
2403
|
+
};
|
|
2404
|
+
|
|
2405
|
+
/** On home: a worker's call for every computer's sessions, for one session read where it runs, or for an Open there. */
|
|
2354
2406
|
const answerLiveCall = async (call, from) => {
|
|
2355
2407
|
if (call.agent !== "user")
|
|
2356
2408
|
return { ok: false, error: "only the person reads their sessions" };
|
|
2409
|
+
if (call.open) return openSession({ ...call.open, machine: call.machine });
|
|
2357
2410
|
if (call.read) return readSession({ ...call.read, machine: call.machine });
|
|
2358
2411
|
return { ok: true, computers: await everyComputersLive(from) };
|
|
2359
2412
|
};
|
|
@@ -2744,6 +2797,7 @@ export function createOwnMachines({
|
|
|
2744
2797
|
models,
|
|
2745
2798
|
sessions,
|
|
2746
2799
|
readSession,
|
|
2800
|
+
openSession,
|
|
2747
2801
|
setModel,
|
|
2748
2802
|
allowSsh,
|
|
2749
2803
|
status,
|
package/lib/phones.mjs
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
open,
|
|
14
14
|
pairProof,
|
|
15
15
|
seal,
|
|
16
|
+
sealFilePart,
|
|
16
17
|
} from "./sealed.mjs";
|
|
17
18
|
|
|
18
19
|
// The daemon's side of the person's own devices: pairing offers made on this machine (a QR code
|
|
@@ -181,7 +182,11 @@ export async function createPhoneDesk({
|
|
|
181
182
|
const identity = await loadOrCreateIdentity(identityFile);
|
|
182
183
|
const offers = new Map();
|
|
183
184
|
const keys = new Map();
|
|
184
|
-
|
|
185
|
+
// The name the person knows this computer by (machine.json's label, which `npx tryharness machines name` changes),
|
|
186
|
+
// not its network name: macOS renames that on its own after a clash on the network, and a phone linking
|
|
187
|
+
// MacBook-Pro-3 said it was linking a MacBook-Pro-4 the person had never heard of.
|
|
188
|
+
const hostname = () =>
|
|
189
|
+
machines()?.status()?.label ?? os.hostname().slice(0, 64);
|
|
185
190
|
|
|
186
191
|
const setupOffer = setupOfferFile ? readSetupOffer(setupOfferFile) : null;
|
|
187
192
|
if (setupOffer)
|
|
@@ -221,7 +226,7 @@ export async function createPhoneDesk({
|
|
|
221
226
|
byHarness,
|
|
222
227
|
expiresAt: Date.now() + ttlMs,
|
|
223
228
|
});
|
|
224
|
-
return { o: offerId, s: secret, k: identity.publicKey, h: hostname };
|
|
229
|
+
return { o: offerId, s: secret, k: identity.publicKey, h: hostname() };
|
|
225
230
|
};
|
|
226
231
|
|
|
227
232
|
// What the QR code or link carries. The secret and the daemon's key never pass through Harness.
|
|
@@ -427,7 +432,7 @@ export async function createPhoneDesk({
|
|
|
427
432
|
String(requestId),
|
|
428
433
|
{
|
|
429
434
|
paired: true,
|
|
430
|
-
hostname,
|
|
435
|
+
hostname: hostname(),
|
|
431
436
|
label,
|
|
432
437
|
kind: device.kind,
|
|
433
438
|
version,
|
|
@@ -586,6 +591,26 @@ export async function createPhoneDesk({
|
|
|
586
591
|
};
|
|
587
592
|
}
|
|
588
593
|
const result = await answer(request.call, device, { holder, gesture });
|
|
594
|
+
// A file part asked for as bytes goes sealed as bytes; anything else, and every older phone, as JSON.
|
|
595
|
+
if (
|
|
596
|
+
request.call?.command === "board.file.get" &&
|
|
597
|
+
request.call.raw === true &&
|
|
598
|
+
result?.ok === true &&
|
|
599
|
+
typeof result.data === "string"
|
|
600
|
+
) {
|
|
601
|
+
const { data, ...header } = result;
|
|
602
|
+
return {
|
|
603
|
+
ok: true,
|
|
604
|
+
envelope: await sealFilePart(
|
|
605
|
+
key,
|
|
606
|
+
"d2p",
|
|
607
|
+
device.id,
|
|
608
|
+
envelope.requestId,
|
|
609
|
+
header,
|
|
610
|
+
Buffer.from(data, "base64")
|
|
611
|
+
),
|
|
612
|
+
};
|
|
613
|
+
}
|
|
589
614
|
return {
|
|
590
615
|
ok: true,
|
|
591
616
|
envelope: await seal(key, "d2p", device.id, envelope.requestId, result),
|
|
@@ -628,7 +653,7 @@ export async function createPhoneDesk({
|
|
|
628
653
|
const answer = async (callInput, device, sealedBy) => {
|
|
629
654
|
const command = String(callInput?.command || "");
|
|
630
655
|
if (command === "phone.hello")
|
|
631
|
-
return { ok: true, hostname, version, kind: device.kind };
|
|
656
|
+
return { ok: true, hostname: hostname(), version, kind: device.kind };
|
|
632
657
|
// A device sends a file's bytes. A path names a file already on this computer, which only an agent here may attach.
|
|
633
658
|
if (command === "board.file.add" && callInput?.path != null)
|
|
634
659
|
return {
|
package/lib/places.mjs
CHANGED
|
@@ -6,6 +6,7 @@ import { spawn, spawnSync } from "node:child_process";
|
|
|
6
6
|
import { historyRoots, paths } from "./paths.mjs";
|
|
7
7
|
import { agentEnvironment } from "./agentnode.mjs";
|
|
8
8
|
import { mainCheckout } from "./worktrees.mjs";
|
|
9
|
+
import { kept } from "./kept.mjs";
|
|
9
10
|
|
|
10
11
|
// Where a coding session runs, and how it opens there again. A session's place comes from its own environment: the
|
|
11
12
|
// Harness piece inside the agent sends it when the session starts (the Claude Code and Codex hooks, nudge.mjs; the
|
|
@@ -695,13 +696,37 @@ function t3Query(home, sql) {
|
|
|
695
696
|
);
|
|
696
697
|
return found.status === 0 ? (found.stdout || "").trim() : null;
|
|
697
698
|
}
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
699
|
+
// The same reads, answered from memory and taken again beside the daemon's thread (kept.mjs): T3's tables change only
|
|
700
|
+
// when T3 updates, and what it runs now is asked for on every read of the buddy's live list (t3ThreadRecent,
|
|
701
|
+
// t3WorkingRecently). A decision made once, such as whether a thread's round waits for T3, reads now.
|
|
702
|
+
function* t3QuerySteps(home, sql) {
|
|
703
|
+
const db = t3Database(home);
|
|
704
|
+
if (!db || !fs.existsSync(SQLITE)) return null;
|
|
705
|
+
const out = yield [SQLITE, ["-readonly", "-cmd", ".timeout 500", db, sql]];
|
|
706
|
+
return out === null ? null : out.trim();
|
|
707
|
+
}
|
|
708
|
+
const keptT3Query = (freshMs, staleMs, wanting) =>
|
|
709
|
+
kept(t3QuerySteps, {
|
|
710
|
+
freshMs,
|
|
711
|
+
staleMs,
|
|
712
|
+
keyOf: (home, sql) => `${home}\0${sql}`,
|
|
713
|
+
wanting,
|
|
714
|
+
});
|
|
715
|
+
// No answer (T3 not installed or started yet) is asked again, so a T3 that starts later is seen; so is a table the kept
|
|
716
|
+
// list lacks, so a T3 that updated since (or just made its tables) is seen at once.
|
|
717
|
+
const T3_TABLES_SQL = "select name from sqlite_master where type = 'table';";
|
|
718
|
+
const tableNames = (tables) => (tables || "").split("\n");
|
|
719
|
+
const t3QueryTables = keptT3Query(
|
|
720
|
+
10 * 60_000,
|
|
721
|
+
Infinity,
|
|
722
|
+
(tables, _home, _sql, needed) =>
|
|
723
|
+
!tables || Boolean(needed && !tableNames(tables).includes(needed))
|
|
724
|
+
);
|
|
725
|
+
const t3QueryRecent = keptT3Query(2_000, 15_000);
|
|
726
|
+
const t3Tables = (home) => ({
|
|
727
|
+
has: (name) =>
|
|
728
|
+
tableNames(t3QueryTables(home, T3_TABLES_SQL, name)).includes(name),
|
|
729
|
+
});
|
|
705
730
|
|
|
706
731
|
/** A read of T3's record that never holds the daemon (its database is gigabytes; a cold read took 5.7 s). */
|
|
707
732
|
function t3QueryLater(home, sql) {
|
|
@@ -816,7 +841,7 @@ export function t3Checkouts(home = t3Home()) {
|
|
|
816
841
|
* provider thread; 0.0.45 in provider_session_runtime), else T3's import of it. A T3 thread's own id (a turn Harness
|
|
817
842
|
* handed to T3, t3.mjs runInT3) is that thread.
|
|
818
843
|
*/
|
|
819
|
-
export function t3Thread(sessionId, home = t3Home()) {
|
|
844
|
+
export function t3Thread(sessionId, home = t3Home(), query = t3Query) {
|
|
820
845
|
if (!PLAIN_ID.test(String(sessionId || ""))) return null;
|
|
821
846
|
const tables = t3Tables(home);
|
|
822
847
|
// The id is checked above: letters, digits and . _ : - only.
|
|
@@ -835,13 +860,17 @@ export function t3Thread(sessionId, home = t3Home()) {
|
|
|
835
860
|
);
|
|
836
861
|
if (!parts.length) return null;
|
|
837
862
|
return (
|
|
838
|
-
|
|
863
|
+
query(
|
|
839
864
|
home,
|
|
840
865
|
`select thread_id from (${parts.join(" union all ")}) order by at desc limit 1;`
|
|
841
866
|
) || null
|
|
842
867
|
);
|
|
843
868
|
}
|
|
844
869
|
|
|
870
|
+
/** t3Thread as of a reading up to a couple of seconds old, for the buddy's live list. */
|
|
871
|
+
export const t3ThreadRecent = (sessionId, home = t3Home()) =>
|
|
872
|
+
t3Thread(sessionId, home, t3QueryRecent);
|
|
873
|
+
|
|
845
874
|
/** T3 Code's own link to one of its threads (t3code://threads/<environment>/<thread>). */
|
|
846
875
|
export function t3Link(threadId, home = t3Home()) {
|
|
847
876
|
let environment = "";
|
|
@@ -958,7 +987,7 @@ export function t3Model(agent, home = t3Home()) {
|
|
|
958
987
|
* its folder (the thread's worktree, else its project's). Codex in T3 runs on Codex's shared background server, outside
|
|
959
988
|
* T3's app, so this is how its running sessions there are found.
|
|
960
989
|
*/
|
|
961
|
-
export function t3Working(agent, home = t3Home()) {
|
|
990
|
+
export function t3Working(agent, home = t3Home(), query = t3Query) {
|
|
962
991
|
const provider = t3Provider(agent);
|
|
963
992
|
const tables = t3Tables(home);
|
|
964
993
|
if (
|
|
@@ -968,7 +997,7 @@ export function t3Working(agent, home = t3Home()) {
|
|
|
968
997
|
)
|
|
969
998
|
return [];
|
|
970
999
|
const projects = tables.has("projection_projects");
|
|
971
|
-
const rows =
|
|
1000
|
+
const rows = query(
|
|
972
1001
|
home,
|
|
973
1002
|
`select p.thread_id || char(9) || json_extract(p.payload_json, '$.nativeThreadRef.nativeId') || char(9) || coalesce(json_extract(t.payload_json, '$.worktreePath'), ${projects ? "r.workspace_root, " : ""}'') || char(9) || p.updated_at
|
|
974
1003
|
from orchestration_v2_projection_provider_threads p join orchestration_v2_projection_threads t on t.thread_id = p.thread_id${projects ? " left join projection_projects r on r.project_id = t.project_id" : ""}
|
|
@@ -986,6 +1015,10 @@ export function t3Working(agent, home = t3Home()) {
|
|
|
986
1015
|
}));
|
|
987
1016
|
}
|
|
988
1017
|
|
|
1018
|
+
/** t3Working as of a reading up to a couple of seconds old, for the buddy's live list. */
|
|
1019
|
+
export const t3WorkingRecently = (agent, home = t3Home()) =>
|
|
1020
|
+
t3Working(agent, home, t3QueryRecent);
|
|
1021
|
+
|
|
989
1022
|
/**
|
|
990
1023
|
* What a turn T3 Code ran used, from T3's own record of the provider's turns for that run (every attempt): tokens in
|
|
991
1024
|
* and out, cached and cache-written. T3 records no price, so the cost stays unknown. Null when T3 has no record of it.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calls across a worker thread's port, both ways: each side answers calls to the functions it serves and calls the
|
|
3
|
+
* other side's by name, getting a promise. Arguments and results are copied (structured clone), so a function or a
|
|
4
|
+
* class instance cannot cross; a Buffer arrives as a Uint8Array.
|
|
5
|
+
*
|
|
6
|
+
* The daemon runs its JavaScript, its WASM SQLite and every synchronous file read on one thread, so work that reads a
|
|
7
|
+
* large database runs in a worker (contextWorker.mjs) and asks the daemon only for what the daemon owns.
|
|
8
|
+
*/
|
|
9
|
+
export function portCalls(port, serve = {}) {
|
|
10
|
+
let next = 0;
|
|
11
|
+
const waiting = new Map();
|
|
12
|
+
|
|
13
|
+
const answer = async ({ call, name, args }) => {
|
|
14
|
+
try {
|
|
15
|
+
const fn = serve[name];
|
|
16
|
+
if (typeof fn !== "function") throw new Error(`${name} is not served`);
|
|
17
|
+
const value = await fn(...args);
|
|
18
|
+
port.postMessage({ reply: call, value });
|
|
19
|
+
} catch (error) {
|
|
20
|
+
port.postMessage({
|
|
21
|
+
reply: call,
|
|
22
|
+
error: error instanceof Error ? error.message : String(error),
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
port.on("message", (message) => {
|
|
28
|
+
if (message?.call !== undefined) return void answer(message);
|
|
29
|
+
const pending = waiting.get(message?.reply);
|
|
30
|
+
if (!pending) return;
|
|
31
|
+
waiting.delete(message.reply);
|
|
32
|
+
if (message.error !== undefined) pending.reject(new Error(message.error));
|
|
33
|
+
else pending.resolve(message.value);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
call: (name, ...args) =>
|
|
38
|
+
new Promise((resolve, reject) => {
|
|
39
|
+
const id = next++;
|
|
40
|
+
waiting.set(id, { resolve, reject });
|
|
41
|
+
try {
|
|
42
|
+
port.postMessage({ call: id, name, args });
|
|
43
|
+
} catch (error) {
|
|
44
|
+
waiting.delete(id);
|
|
45
|
+
reject(error);
|
|
46
|
+
}
|
|
47
|
+
}),
|
|
48
|
+
/** Fails every call still waiting, as when the other side has gone. */
|
|
49
|
+
fail(why) {
|
|
50
|
+
for (const pending of waiting.values()) pending.reject(new Error(why));
|
|
51
|
+
waiting.clear();
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
package/lib/runBrief.mjs
CHANGED
|
@@ -116,7 +116,7 @@ export function createRunBriefs({
|
|
|
116
116
|
// The thread's task frame, refreshed now, for an agent on this computer.
|
|
117
117
|
const frame =
|
|
118
118
|
RUNNERS.has(agent) && threadId
|
|
119
|
-
? frameFor(threadId, { pack: found.pack })
|
|
119
|
+
? await frameFor(threadId, { pack: found.pack })
|
|
120
120
|
: null;
|
|
121
121
|
found.frame = frame ? frames.briefText(frame, agent) : "";
|
|
122
122
|
if (found.frame && !dryRun) {
|
package/lib/sealed.mjs
CHANGED
|
@@ -138,6 +138,43 @@ export async function seal(key, direction, deviceId, requestId, value) {
|
|
|
138
138
|
};
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
+
// A file part for a phone that asked for bytes (board.file.get raw): the plaintext is BYTES_MAGIC, the length of a JSON
|
|
142
|
+
// header, the header, then the bytes themselves, so they are not base64 inside the seal as well as outside it.
|
|
143
|
+
// The phone tells the two apart by the first bytes (a JSON plaintext starts with "{"): src/shared/crypto/sealedChannel.ts.
|
|
144
|
+
export const BYTES_MAGIC = "HSB1";
|
|
145
|
+
export async function sealFilePart(
|
|
146
|
+
key,
|
|
147
|
+
direction,
|
|
148
|
+
deviceId,
|
|
149
|
+
requestId,
|
|
150
|
+
header,
|
|
151
|
+
bytes
|
|
152
|
+
) {
|
|
153
|
+
const head = encoder.encode(JSON.stringify(header));
|
|
154
|
+
const plain = new Uint8Array(8 + head.length + bytes.length);
|
|
155
|
+
plain.set(encoder.encode(BYTES_MAGIC), 0);
|
|
156
|
+
new DataView(plain.buffer).setUint32(4, head.length);
|
|
157
|
+
plain.set(head, 8);
|
|
158
|
+
plain.set(bytes, 8 + head.length);
|
|
159
|
+
const iv = webcrypto.getRandomValues(new Uint8Array(12));
|
|
160
|
+
const ct = await subtle.encrypt(
|
|
161
|
+
{
|
|
162
|
+
name: "AES-GCM",
|
|
163
|
+
iv,
|
|
164
|
+
additionalData: aad(direction, deviceId, requestId),
|
|
165
|
+
},
|
|
166
|
+
key,
|
|
167
|
+
plain
|
|
168
|
+
);
|
|
169
|
+
return {
|
|
170
|
+
v: SEALED_VERSION,
|
|
171
|
+
deviceId,
|
|
172
|
+
requestId,
|
|
173
|
+
iv: b64u(iv),
|
|
174
|
+
ct: b64u(new Uint8Array(ct)),
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
141
178
|
// Throws on a wrong key, a wrong direction, device or request id, or any changed byte.
|
|
142
179
|
export async function open(key, direction, envelope) {
|
|
143
180
|
const plain = await subtle.decrypt(
|
package/lib/sessionControl.mjs
CHANGED
|
@@ -266,10 +266,11 @@ export function createSessionControl({
|
|
|
266
266
|
// its process tree and its terminal. Codex's terminals share one background server, started from wherever Codex first
|
|
267
267
|
// ran: a session there has no app or terminal of its own, and is placed by the Codex terminal working in its folder.
|
|
268
268
|
const placeOfReport = (agentId, folder, request) => {
|
|
269
|
-
const
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
269
|
+
const named = (Array.isArray(request.pids) ? request.pids : []).filter(
|
|
270
|
+
(pid) => Number.isInteger(pid) && pid > 1
|
|
271
|
+
);
|
|
272
|
+
const table = processTable({ having: named });
|
|
273
|
+
const pids = named.filter((pid) => table.has(pid)).slice(0, 2);
|
|
273
274
|
if (harnessRun(folder, pids)) return null;
|
|
274
275
|
let env = placeEnv(request.env);
|
|
275
276
|
let host = pids.map((pid) => hostApp(table, pid)).find(Boolean) ?? null;
|
|
@@ -331,7 +332,8 @@ export function createSessionControl({
|
|
|
331
332
|
return link || command ? { link, command } : null;
|
|
332
333
|
};
|
|
333
334
|
|
|
334
|
-
|
|
335
|
+
// `fresh`: for a decision made once (send into a session, open it where it runs), the process table read now.
|
|
336
|
+
const liveNow = ({ fresh = false } = {}) => {
|
|
335
337
|
const recent = store.recentSessions(200);
|
|
336
338
|
// With the title the index gives it (its first request), when the index has it yet.
|
|
337
339
|
const titleOf = (session) => {
|
|
@@ -346,7 +348,7 @@ export function createSessionControl({
|
|
|
346
348
|
};
|
|
347
349
|
const linksOk = t3LinksOk();
|
|
348
350
|
const handed = handedToT3();
|
|
349
|
-
const table = processTable();
|
|
351
|
+
const table = processTable({ fresh });
|
|
350
352
|
const found = liveSessions({
|
|
351
353
|
exclude: new Set(runningPids()),
|
|
352
354
|
recent,
|
|
@@ -839,7 +841,7 @@ export function createSessionControl({
|
|
|
839
841
|
: `One of Harness's runs is working in this ${nameOf(agentId)} session right now. Open it again once the run is done.`,
|
|
840
842
|
};
|
|
841
843
|
}
|
|
842
|
-
const running = sessionId ? liveNow() : [];
|
|
844
|
+
const running = sessionId ? liveNow({ fresh: true }) : [];
|
|
843
845
|
const live = running.find(
|
|
844
846
|
(row) => row.agent === agentId && row.sessionId === sessionId
|
|
845
847
|
);
|
|
@@ -895,6 +897,39 @@ export function createSessionControl({
|
|
|
895
897
|
: { opensIn: null };
|
|
896
898
|
};
|
|
897
899
|
|
|
900
|
+
/**
|
|
901
|
+
* The agent itself, fresh, for a thread it has not worked in yet (owner, October 28: every agent on a thread opens
|
|
902
|
+
* outside the buddy, a coding agent with no session there "fresh in its home"): where the person uses it, in the
|
|
903
|
+
* thread's folder, never another of its conversations there. In T3 Code that is T3 itself, not the agent's thread for
|
|
904
|
+
* the folder, which is another conversation.
|
|
905
|
+
*/
|
|
906
|
+
const freshPlan = (agentId, folder, act) => {
|
|
907
|
+
const home = homeOf(agentId);
|
|
908
|
+
const where = folder && fs.existsSync(folder) ? folder : null;
|
|
909
|
+
const terminal = () => {
|
|
910
|
+
const { name, app } = lastResort();
|
|
911
|
+
return {
|
|
912
|
+
opensIn: name,
|
|
913
|
+
resume: { agent: agentId, session: null, cwd: where, app },
|
|
914
|
+
};
|
|
915
|
+
};
|
|
916
|
+
const plan =
|
|
917
|
+
home?.kind === "t3"
|
|
918
|
+
? home.app
|
|
919
|
+
? { opensIn: "T3 Code", app: home.app }
|
|
920
|
+
: null
|
|
921
|
+
: placePlan(agentId, home, null, where, act);
|
|
922
|
+
const shown =
|
|
923
|
+
plan ??
|
|
924
|
+
(CODING_AGENTS.includes(agentId) ? terminal() : { opensIn: null });
|
|
925
|
+
return shown.opensIn
|
|
926
|
+
? {
|
|
927
|
+
...shown,
|
|
928
|
+
note: `${nameOf(agentId)} hasn't worked in this thread yet, so it opens fresh in ${shown.opensIn}.`,
|
|
929
|
+
}
|
|
930
|
+
: shown;
|
|
931
|
+
};
|
|
932
|
+
|
|
898
933
|
/**
|
|
899
934
|
* Each coding agent's sessions that ended, as Open offers them: the person's newest (`last`), where the agent opens when
|
|
900
935
|
* it is not running; and the newest few another agent, a run or a test started (`traces`), each saying who.
|
|
@@ -1027,14 +1062,12 @@ export function createSessionControl({
|
|
|
1027
1062
|
if (!validAgent(agentId) || (sessionId && !SESSION_ID.test(sessionId)))
|
|
1028
1063
|
return { ok: false, error: "that session can't be opened" };
|
|
1029
1064
|
// Open itself: the daemon's part happens now, and the app does the rest.
|
|
1065
|
+
const act = request.command === "board.live.focus";
|
|
1030
1066
|
return {
|
|
1031
1067
|
ok: true,
|
|
1032
|
-
...
|
|
1033
|
-
agentId,
|
|
1034
|
-
sessionId || null,
|
|
1035
|
-
folderOf(request),
|
|
1036
|
-
request.command === "board.live.focus"
|
|
1037
|
-
),
|
|
1068
|
+
...(request.fresh === true && !sessionId
|
|
1069
|
+
? freshPlan(agentId, folderOf(request), act)
|
|
1070
|
+
: openPlan(agentId, sessionId || null, folderOf(request), act)),
|
|
1038
1071
|
};
|
|
1039
1072
|
}
|
|
1040
1073
|
if (request.command === "board.live.say") {
|
|
@@ -1042,7 +1075,7 @@ export function createSessionControl({
|
|
|
1042
1075
|
.trim()
|
|
1043
1076
|
.slice(0, 20_000);
|
|
1044
1077
|
if (!text) return { ok: false, error: "a message needs text" };
|
|
1045
|
-
const session = liveNow().find(
|
|
1078
|
+
const session = liveNow({ fresh: true }).find(
|
|
1046
1079
|
(row) => row.agent === request.to && row.sessionId === sessionId
|
|
1047
1080
|
);
|
|
1048
1081
|
if (!session)
|