tryharness 0.7.83 → 0.7.86
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 +21 -19
- package/assets/dsh-plugin.mjs +75 -4
- package/assets/herdr-mod/harness/main.js +367 -0
- package/assets/herdr-mod/harness/mod.json +6 -0
- package/assets/opencode-plugin.js +87 -22
- package/assets/pi-extension.ts +81 -2
- package/cli.mjs +544 -208
- package/lib/adapters.mjs +62 -27
- package/lib/agentBinaries.mjs +6 -8
- package/lib/agentClaims.mjs +168 -0
- package/lib/agentReadTools.json +415 -0
- package/lib/agentSignIn.mjs +17 -18
- package/lib/agentWiring.mjs +114 -0
- package/lib/archetypes.js +10 -11
- package/lib/attention.mjs +100 -0
- package/lib/audit.mjs +1 -1
- package/lib/backupSetup.mjs +6 -28
- package/lib/bankrApprovals.mjs +86 -0
- package/lib/boardAccess.mjs +40 -66
- package/lib/boardBackup.mjs +86 -85
- package/lib/boardCommands.mjs +28 -0
- package/lib/boardFileCommands.mjs +29 -36
- package/lib/boardFiles.mjs +83 -15
- package/lib/boardMirror.mjs +78 -11
- package/lib/boardProtocol.json +191 -123
- package/lib/boardThreads.mjs +19 -37
- package/lib/boardTools.mjs +22 -15
- package/lib/boardWatches.mjs +43 -15
- package/lib/bridge.mjs +7 -3
- package/lib/browserAgentTools.mjs +59 -0
- package/lib/browserWake.mjs +0 -6
- package/lib/cards.mjs +52 -0
- package/lib/circling.mjs +189 -0
- package/lib/cleanup.mjs +234 -0
- package/lib/cloudBoot.mjs +21 -4
- package/lib/cloudSave.mjs +46 -5
- package/lib/compaction.mjs +8 -1
- package/lib/completion.mjs +358 -0
- package/lib/computerDevices.mjs +853 -0
- package/lib/connectionStatus.mjs +34 -0
- package/lib/connectors.mjs +139 -1
- package/lib/coordinator.mjs +108 -14
- package/lib/coreModels.mjs +36 -12
- package/lib/daemon.mjs +2426 -338
- package/lib/daemonLock.mjs +103 -0
- package/lib/deviceDoor.mjs +308 -0
- package/lib/deviceIdentity.mjs +114 -0
- package/lib/deviceList.mjs +172 -0
- package/lib/deviceSeal.mjs +74 -0
- package/lib/dispatcher.mjs +497 -26
- package/lib/dispatches.mjs +3 -3
- package/lib/environment.mjs +2 -1
- package/lib/environments.mjs +67 -41
- package/lib/events.mjs +318 -0
- package/lib/facts.mjs +170 -0
- package/lib/fileSource.mjs +540 -0
- package/lib/files.mjs +47 -2
- package/lib/gitHost.mjs +39 -1
- package/lib/goalCommands.mjs +12 -80
- package/lib/handover.mjs +21 -16
- package/lib/harnessOffers.mjs +140 -15
- package/lib/herdr.mjs +100 -15
- package/lib/herdrAppCall.mjs +19 -0
- package/lib/herdrCore.mjs +59 -0
- package/lib/herdrRuns.mjs +1126 -0
- package/lib/hookDialects.mjs +235 -50
- package/lib/identityLink.mjs +81 -0
- package/lib/inference.mjs +31 -2
- package/lib/jamAccess.mjs +82 -0
- package/lib/{projectBoard.mjs → jamBoard.mjs} +5 -4
- package/lib/{projectGit.mjs → jamGit.mjs} +53 -15
- package/lib/jamKey.mjs +274 -0
- package/lib/{projectPieces.mjs → jamPieces.mjs} +35 -29
- package/lib/{projectSettings.mjs → jamSettings.mjs} +12 -22
- package/lib/jamStore.mjs +973 -0
- package/lib/jamUpgrade.mjs +112 -0
- package/lib/jams.mjs +3079 -0
- package/lib/kanban.mjs +13 -7
- package/lib/landed.mjs +5 -1
- package/lib/library.mjs +41 -22
- package/lib/limits.mjs +91 -0
- package/lib/lineDiff.mjs +97 -0
- package/lib/lineup.mjs +18 -13
- package/lib/link.mjs +584 -0
- package/lib/localStack.mjs +75 -16
- package/lib/localmodels.mjs +58 -78
- package/lib/loopBackstop.mjs +2 -1
- package/lib/machine.mjs +544 -0
- package/lib/machineLink.mjs +446 -0
- package/lib/machineRoutes.mjs +68 -19
- package/lib/machineRuns.mjs +85 -4
- package/lib/machineSeal.mjs +6 -31
- package/lib/manager.mjs +134 -12
- package/lib/mcp-stdio.mjs +492 -215
- package/lib/mcpRelay.mjs +34 -35
- package/lib/members.json +1 -1
- package/lib/modelRoute.mjs +162 -0
- package/lib/nativeHost.mjs +81 -90
- package/lib/nativeSenses.mjs +258 -0
- package/lib/nerves.mjs +523 -0
- package/lib/network.mjs +117 -278
- package/lib/networkPlaces.mjs +578 -0
- package/lib/nextStep.mjs +95 -0
- package/lib/notify.mjs +2 -2
- package/lib/nudge.mjs +116 -10
- package/lib/originals.mjs +216 -0
- package/lib/outsideEvents.mjs +383 -0
- package/lib/outsideRuns.mjs +230 -0
- package/lib/ownMachines.mjs +674 -256
- package/lib/pain.mjs +215 -0
- package/lib/pairing.mjs +91 -11
- package/lib/paths.mjs +42 -3
- package/lib/peerProcess.mjs +21 -7
- package/lib/peopleLink.mjs +268 -0
- package/lib/personNotices.mjs +3 -2
- package/lib/phones.mjs +252 -542
- package/lib/placeCards.mjs +282 -0
- package/lib/placeChecks.mjs +95 -0
- package/lib/placeCommands.mjs +8 -17
- package/lib/placeRequests.mjs +152 -0
- package/lib/placeStore.mjs +295 -0
- package/lib/placeTool.d.ts +12 -0
- package/lib/placeTool.js +40 -0
- package/lib/places.mjs +63 -14
- package/lib/plans.mjs +53 -8
- package/lib/presence.mjs +270 -0
- package/lib/privateNetwork.d.ts +2 -0
- package/lib/privateNetwork.js +93 -0
- package/lib/proposals.mjs +300 -0
- package/lib/publicFetch.d.ts +32 -0
- package/lib/publicFetch.js +248 -0
- package/lib/reach.mjs +128 -0
- package/lib/rebuildable.mjs +72 -0
- package/lib/recall.mjs +216 -0
- package/lib/record.mjs +13 -0
- package/lib/reflexes.mjs +392 -0
- package/lib/relayLimits.mjs +31 -2
- package/lib/releaseNotice.mjs +198 -0
- package/lib/removeHarness.mjs +15 -4
- package/lib/repoLinks.mjs +204 -35
- package/lib/runAuthority.mjs +102 -39
- package/lib/runBrief.mjs +93 -40
- package/lib/runRequests.mjs +52 -14
- package/lib/runUsage.mjs +31 -0
- package/lib/runWorker.mjs +74 -25
- package/lib/runner.mjs +289 -45
- package/lib/runtime-install.mjs +37 -8
- package/lib/schedules.mjs +171 -47
- package/lib/screenWatches.mjs +221 -0
- package/lib/sealed.mjs +12 -30
- package/lib/sealedThreads.mjs +198 -392
- package/lib/secretStore.mjs +178 -0
- package/lib/secrets.mjs +11 -0
- package/lib/seen.mjs +3 -9
- package/lib/selfUpdate.mjs +51 -15
- package/lib/senseCall.mjs +1514 -0
- package/lib/senseHook.mjs +114 -0
- package/lib/senseTools.mjs +1298 -0
- package/lib/sessionBriefs.mjs +87 -0
- package/lib/sessionControl.mjs +63 -13
- package/lib/sessionFiles.mjs +85 -0
- package/lib/setupChoices.mjs +12 -3
- package/lib/setupMode.mjs +70 -25
- package/lib/sharedKeys.mjs +166 -0
- package/lib/sleep.mjs +396 -0
- package/lib/sources.mjs +306 -0
- package/lib/speech.mjs +166 -411
- package/lib/spoken.mjs +210 -0
- package/lib/steerHook.mjs +3 -1
- package/lib/steerQueue.mjs +40 -11
- package/lib/store.mjs +323 -130
- package/lib/stuck.mjs +85 -7
- package/lib/swarm.mjs +157 -49
- package/lib/swarmDevices.mjs +25 -85
- package/lib/swarmMemory.mjs +93 -9
- package/lib/t3.mjs +73 -3
- package/lib/taskCommands.mjs +51 -60
- package/lib/taskRooms.mjs +30 -4
- package/lib/taskRules.json +29 -0
- package/lib/taskRules.mjs +21 -0
- package/lib/taskRuns.mjs +74 -11
- package/lib/team.mjs +2 -1
- package/lib/threadActions.mjs +37 -9
- package/lib/threadAuthority.mjs +4 -4
- package/lib/threadBriefs.mjs +173 -43
- package/lib/threadNotes.mjs +320 -0
- package/lib/threadRecord.mjs +491 -0
- package/lib/threadRuns.mjs +216 -108
- package/lib/threadView.mjs +27 -30
- package/lib/threadWatches.mjs +1962 -0
- package/lib/timeSense.mjs +839 -0
- package/lib/tripwires.mjs +454 -0
- package/lib/ui.mjs +1 -1
- package/lib/vault.mjs +560 -45
- package/lib/vaultCommands.mjs +5 -3
- package/lib/vaultPeers.mjs +165 -0
- package/lib/vaultTools.d.ts +4 -1
- package/lib/vaultTools.js +22 -1
- package/lib/verdicts.mjs +12 -26
- package/lib/versions.mjs +117 -0
- package/lib/waitTool.mjs +278 -0
- package/lib/wakePicture.mjs +268 -0
- package/lib/wakeQueue.mjs +108 -0
- package/lib/watchResponses.mjs +533 -0
- package/lib/watches.mjs +290 -145
- package/lib/windowAsks.mjs +80 -17
- package/lib/worktrees.mjs +159 -9
- package/npm-shrinkwrap.json +138 -631
- package/package.json +7 -6
- package/release.json +211 -129
- package/lib/callSessions.mjs +0 -51
- package/lib/directLink.mjs +0 -349
- package/lib/peopleBoard.mjs +0 -131
- package/lib/projects.mjs +0 -2917
- package/lib/roomChannels.mjs +0 -667
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
|
|
3
|
+
// A thread's agent resumes its session, so most of each wake's brief was already in it: on the board's resumed wakes a
|
|
4
|
+
// median 74% of the long lines were (token probe, November 6). This remembers what a session was told, and a resumed
|
|
5
|
+
// wake is told what it was not.
|
|
6
|
+
|
|
7
|
+
// Only so the record stays small; a line forgotten past this is told again, which costs little.
|
|
8
|
+
const MARKS_KEPT = 1_000;
|
|
9
|
+
|
|
10
|
+
const markOf = (text) =>
|
|
11
|
+
createHash("sha256").update(text).digest("base64url").slice(0, 10);
|
|
12
|
+
|
|
13
|
+
const newLines = (text, seen) => {
|
|
14
|
+
const lines = text.split("\n");
|
|
15
|
+
const fresh = lines.filter(
|
|
16
|
+
(line) => line.trim() && !seen.has(markOf(line.trim()))
|
|
17
|
+
);
|
|
18
|
+
if (!fresh.length) return "";
|
|
19
|
+
// The first line says what the rest are.
|
|
20
|
+
return (fresh[0] === lines[0] ? fresh : [lines[0], ...fresh]).join("\n");
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export function createSessionBriefs(store) {
|
|
24
|
+
const keyOf = (threadId, agent) => `session-brief:${threadId}:${agent}`;
|
|
25
|
+
|
|
26
|
+
const readRecord = (threadId, agent) => {
|
|
27
|
+
try {
|
|
28
|
+
return JSON.parse(store.meta(keyOf(threadId, agent)) || "null");
|
|
29
|
+
} catch {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* What one wake tells the session it runs in. `session` is the one it will resume, if any. The session counts as told
|
|
36
|
+
* only by a run that finished in it: a run that failed or was stopped may never have read its brief, so the next wake
|
|
37
|
+
* tells it everything, as does a new session.
|
|
38
|
+
*/
|
|
39
|
+
const forWake = (threadId, agent, session) => {
|
|
40
|
+
const record = readRecord(threadId, agent);
|
|
41
|
+
const lastRun = record && store.getTask(record.run);
|
|
42
|
+
const continuing =
|
|
43
|
+
Boolean(session) &&
|
|
44
|
+
lastRun?.status === "done" &&
|
|
45
|
+
lastRun.session_id === session;
|
|
46
|
+
const seen = new Set(continuing ? record.marks : []);
|
|
47
|
+
const blocks = [];
|
|
48
|
+
const seenPost = store.recentRoomPosts(threadId, { limit: 1 }).posts.at(-1);
|
|
49
|
+
return {
|
|
50
|
+
// The post the session last read up to; 0 when it is told the thread from the start.
|
|
51
|
+
afterSeq: continuing ? record.seq : 0,
|
|
52
|
+
// What says the state of something (the goal, the route): whole if any of it changed, since a line gone from it
|
|
53
|
+
// is news too.
|
|
54
|
+
block(text) {
|
|
55
|
+
const whole = String(text ?? "").trim();
|
|
56
|
+
if (!whole) return "";
|
|
57
|
+
blocks.push(markOf(whole));
|
|
58
|
+
return seen.has(markOf(whole)) ? "" : text;
|
|
59
|
+
},
|
|
60
|
+
// What was found for this turn (memory, files, lessons): only the lines the session has not had.
|
|
61
|
+
lines: (text) => (continuing ? newLines(String(text ?? ""), seen) : text),
|
|
62
|
+
// Once the brief is sent as `sent`; the post number was read before the brief, so a post made as it was written
|
|
63
|
+
// is told again rather than never.
|
|
64
|
+
remember({ run, sent }) {
|
|
65
|
+
const marks = [
|
|
66
|
+
...seen,
|
|
67
|
+
...blocks,
|
|
68
|
+
...sent
|
|
69
|
+
.split("\n")
|
|
70
|
+
.map((line) => line.trim())
|
|
71
|
+
.filter(Boolean)
|
|
72
|
+
.map(markOf),
|
|
73
|
+
];
|
|
74
|
+
store.meta(
|
|
75
|
+
keyOf(threadId, agent),
|
|
76
|
+
JSON.stringify({
|
|
77
|
+
run,
|
|
78
|
+
seq: seenPost?.seq ?? 0,
|
|
79
|
+
marks: [...new Set(marks)].slice(-MARKS_KEPT),
|
|
80
|
+
})
|
|
81
|
+
);
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
return { forWake };
|
|
87
|
+
}
|
package/lib/sessionControl.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { readConfig } from "./secretStore.mjs";
|
|
1
2
|
import fs from "node:fs";
|
|
2
3
|
import path from "node:path";
|
|
3
4
|
import { paths } from "./paths.mjs";
|
|
4
|
-
import { readJson } from "./files.mjs";
|
|
5
5
|
import { runningPids, runningProcesses } from "./runner.mjs";
|
|
6
6
|
import { PROCESS_NAMES, nativeSessionId } from "./swarm.mjs";
|
|
7
7
|
import { member, nameOf } from "./members.mjs";
|
|
@@ -48,6 +48,7 @@ import {
|
|
|
48
48
|
} from "./places.mjs";
|
|
49
49
|
import { resumeInNeovim, showInNeovim } from "./neovim.mjs";
|
|
50
50
|
import {
|
|
51
|
+
herdrApp,
|
|
51
52
|
herdrInstalled,
|
|
52
53
|
herdrRunning,
|
|
53
54
|
resumeInHerdr,
|
|
@@ -55,7 +56,12 @@ import {
|
|
|
55
56
|
} from "./herdr.mjs";
|
|
56
57
|
import { detectAgentApps, detectMcpClients } from "./adapters.mjs";
|
|
57
58
|
import { resolveCommand } from "./commands.mjs";
|
|
58
|
-
import { handedToT3, sendToT3, t3Access } from "./t3.mjs";
|
|
59
|
+
import { handedToT3, sendFilesToT3, sendToT3, t3Access } from "./t3.mjs";
|
|
60
|
+
import {
|
|
61
|
+
namedSessionFiles,
|
|
62
|
+
receiveSessionFile,
|
|
63
|
+
withSavedPaths,
|
|
64
|
+
} from "./sessionFiles.mjs";
|
|
59
65
|
|
|
60
66
|
export function createSessionControl({
|
|
61
67
|
store,
|
|
@@ -67,7 +73,18 @@ export function createSessionControl({
|
|
|
67
73
|
scrub = (value) => value,
|
|
68
74
|
// A running session's subagents (subagentSteering.mjs ofSession).
|
|
69
75
|
subagentsOf = () => [],
|
|
76
|
+
// Keeps the step an agent's turn ended with for its next turn in a thread (nextStep.mjs), on home.
|
|
77
|
+
keepNextStep = () => {},
|
|
70
78
|
}) {
|
|
79
|
+
// The thread a session works in: the one that resumes it, else the thread of the run Harness started in it (a turn
|
|
80
|
+
// another computer took is not one this computer resumes, but its run is on the board).
|
|
81
|
+
const threadOfSession = (agent, sessionId) => {
|
|
82
|
+
const resumed = store.threadForSession(agent, sessionId);
|
|
83
|
+
if (resumed) return resumed;
|
|
84
|
+
const run = store.runOfSession(agent, sessionId);
|
|
85
|
+
const parent = run?.parent_id ? store.getTask(run.parent_id) : null;
|
|
86
|
+
return parent?.kind === "goal" ? parent.id : null;
|
|
87
|
+
};
|
|
71
88
|
const saidKey = (agent, sessionId) => `said:${agent}:${sessionId}`;
|
|
72
89
|
const said = (agent, sessionId) => {
|
|
73
90
|
try {
|
|
@@ -497,7 +514,7 @@ export function createSessionControl({
|
|
|
497
514
|
// Where the person said threads open, in setup or settings (setupChoices.mjs): `all` when Harness cannot tell where
|
|
498
515
|
// they work, and per agent, which always wins for that agent.
|
|
499
516
|
const picked = () => {
|
|
500
|
-
const workplace =
|
|
517
|
+
const workplace = readConfig(paths.config, {}).workplace ?? {};
|
|
501
518
|
return { all: workplace.all ?? null, agents: workplace.agents ?? {} };
|
|
502
519
|
};
|
|
503
520
|
/** A place with the app that opens it now (T3's running build, an editor's install); null when it is not on this computer. */
|
|
@@ -588,6 +605,10 @@ export function createSessionControl({
|
|
|
588
605
|
* none attached, the person's terminal opens herdr itself, which shows the pane focused.
|
|
589
606
|
*/
|
|
590
607
|
const herdrShown = (agentId, shown) => {
|
|
608
|
+
if (shown.herdrApp)
|
|
609
|
+
return shown.app
|
|
610
|
+
? { app: shown.app }
|
|
611
|
+
: { note: `It's up in Herdr, which runs outside any app here.` };
|
|
591
612
|
if (shown.attach)
|
|
592
613
|
return {
|
|
593
614
|
resume: {
|
|
@@ -725,12 +746,12 @@ export function createSessionControl({
|
|
|
725
746
|
// In a new tab of the person's herdr, on the folder; when that herdr is not running, wherever else it opens.
|
|
726
747
|
if (place.kind === "herdr") {
|
|
727
748
|
if (!CODING_AGENTS.includes(agentId) || !herdrRunning(place)) return null;
|
|
728
|
-
if (busy) return { opensIn:
|
|
749
|
+
if (busy) return { opensIn: place.name, note: busy };
|
|
729
750
|
const fresh = startsFresh(agentId, sessionId);
|
|
730
751
|
if (!act)
|
|
731
752
|
return {
|
|
732
|
-
opensIn:
|
|
733
|
-
...(fresh ? { note: freshNote(agentId,
|
|
753
|
+
opensIn: place.name,
|
|
754
|
+
...(fresh ? { note: freshNote(agentId, place.name) } : {}),
|
|
734
755
|
};
|
|
735
756
|
const command =
|
|
736
757
|
sessionId && !fresh
|
|
@@ -742,9 +763,9 @@ export function createSessionControl({
|
|
|
742
763
|
if (!shown) return null;
|
|
743
764
|
const opened = herdrShown(agentId, shown);
|
|
744
765
|
return {
|
|
745
|
-
opensIn:
|
|
766
|
+
opensIn: place.name,
|
|
746
767
|
...opened,
|
|
747
|
-
...(fresh ? { note: freshNote(agentId,
|
|
768
|
+
...(fresh ? { note: freshNote(agentId, place.name) } : {}),
|
|
748
769
|
};
|
|
749
770
|
}
|
|
750
771
|
if (place.kind === "terminal") {
|
|
@@ -774,8 +795,18 @@ export function createSessionControl({
|
|
|
774
795
|
// herdr's server started (T3 Code's terminal, say), not where the session shows.
|
|
775
796
|
if (place?.kind === "herdr") {
|
|
776
797
|
const shown = act ? showInHerdr(place) : null;
|
|
777
|
-
if (shown)
|
|
778
|
-
|
|
798
|
+
if (shown)
|
|
799
|
+
return { opensIn: place.name, ...herdrShown(live.agent, shown) };
|
|
800
|
+
if (!act) return { opensIn: place.name };
|
|
801
|
+
// The Herdr app's window is closed: its terminals keep running in its core, and opening it lists them.
|
|
802
|
+
const closedApp =
|
|
803
|
+
place.client === "app" && !herdrRunning(place) ? herdrApp() : null;
|
|
804
|
+
if (closedApp)
|
|
805
|
+
return {
|
|
806
|
+
opensIn: place.name,
|
|
807
|
+
app: closedApp,
|
|
808
|
+
note: `${nameOf(live.agent)} is still running in Herdr; it's in Herdr's agents list.`,
|
|
809
|
+
};
|
|
779
810
|
}
|
|
780
811
|
if (
|
|
781
812
|
(live.host && /^T3 Code\b/.test(live.host.name)) ||
|
|
@@ -1072,6 +1103,17 @@ export function createSessionControl({
|
|
|
1072
1103
|
if (agent === "user")
|
|
1073
1104
|
return { ok: false, error: "a session reports its own turn" };
|
|
1074
1105
|
noteTurn(agent, sessionId, request, true);
|
|
1106
|
+
// Where its hook let the last message be read: the step it ended with, or none, for a thread the session works in.
|
|
1107
|
+
const thread =
|
|
1108
|
+
Object.hasOwn(request, "next") && sessionId
|
|
1109
|
+
? threadOfSession(agent, sessionId)
|
|
1110
|
+
: null;
|
|
1111
|
+
if (thread)
|
|
1112
|
+
keepNextStep(
|
|
1113
|
+
thread,
|
|
1114
|
+
agent,
|
|
1115
|
+
typeof request.next === "string" ? request.next : null
|
|
1116
|
+
);
|
|
1075
1117
|
return { ok: true };
|
|
1076
1118
|
}
|
|
1077
1119
|
if (agent !== "user")
|
|
@@ -1145,11 +1187,16 @@ export function createSessionControl({
|
|
|
1145
1187
|
: openPlan(agentId, sessionId || null, folderOf(request), act)),
|
|
1146
1188
|
};
|
|
1147
1189
|
}
|
|
1190
|
+
if (request.command === "board.live.file")
|
|
1191
|
+
return receiveSessionFile(request);
|
|
1148
1192
|
if (request.command === "board.live.say") {
|
|
1149
1193
|
const text = String(request.text || "")
|
|
1150
1194
|
.trim()
|
|
1151
1195
|
.slice(0, 20_000);
|
|
1152
|
-
|
|
1196
|
+
const { files, error } = namedSessionFiles(request.files);
|
|
1197
|
+
if (error) return { ok: false, error };
|
|
1198
|
+
if (!text && !files.length)
|
|
1199
|
+
return { ok: false, error: "a message needs text" };
|
|
1153
1200
|
const session = liveNow({ fresh: true }).find(
|
|
1154
1201
|
(row) => row.agent === request.to && row.sessionId === sessionId
|
|
1155
1202
|
);
|
|
@@ -1159,7 +1206,7 @@ export function createSessionControl({
|
|
|
1159
1206
|
const keep = (t3) => {
|
|
1160
1207
|
const messages = [
|
|
1161
1208
|
...said(session.agent, sessionId),
|
|
1162
|
-
{ text, at: new Date().toISOString() },
|
|
1209
|
+
{ text: withSavedPaths(text, files), at: new Date().toISOString() },
|
|
1163
1210
|
];
|
|
1164
1211
|
store.meta(saidKey(session.agent, sessionId), JSON.stringify(messages));
|
|
1165
1212
|
return {
|
|
@@ -1185,7 +1232,10 @@ export function createSessionControl({
|
|
|
1185
1232
|
: access.state
|
|
1186
1233
|
);
|
|
1187
1234
|
return {
|
|
1188
|
-
pending:
|
|
1235
|
+
pending: (files.length
|
|
1236
|
+
? sendFilesToT3(thread, text, files)
|
|
1237
|
+
: sendToT3(thread, text)
|
|
1238
|
+
).then(
|
|
1189
1239
|
(delivery) => ({ ok: true, sent: "t3", delivery, session }),
|
|
1190
1240
|
(error) => {
|
|
1191
1241
|
log(`T3 Code did not take a message: ${error.message}`);
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { fileLimit, fileName, joinFileParts } from "./boardFiles.mjs";
|
|
5
|
+
import { ensureDir, mimeFor } from "./files.mjs";
|
|
6
|
+
import { paths } from "./paths.mjs";
|
|
7
|
+
|
|
8
|
+
// Photos and files the person sends a running session from another device, with no thread to put them on. A session
|
|
9
|
+
// reads files, so each one is saved on this computer under its own name, readable by the person alone. It stays long
|
|
10
|
+
// enough for a session that takes its messages when its turn ends, then goes.
|
|
11
|
+
|
|
12
|
+
const KEPT_MS = 7 * 24 * 60 * 60 * 1000;
|
|
13
|
+
const ABOUT = ".file.json";
|
|
14
|
+
const ID = /^[0-9a-f-]{36}$/;
|
|
15
|
+
const MOST_FILES = 8;
|
|
16
|
+
|
|
17
|
+
const folder = () => path.join(paths.files, "sessions");
|
|
18
|
+
|
|
19
|
+
function dropOldFiles(now = Date.now()) {
|
|
20
|
+
for (const id of fs.existsSync(folder()) ? fs.readdirSync(folder()) : []) {
|
|
21
|
+
const place = path.join(folder(), id);
|
|
22
|
+
if (now - fs.statSync(place).mtimeMs > KEPT_MS)
|
|
23
|
+
fs.rmSync(place, { recursive: true, force: true });
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** One part of a file on its way; once it is whole, the file saved, with the id a message names it by. */
|
|
28
|
+
export function receiveSessionFile(request) {
|
|
29
|
+
if (typeof request.data !== "string" || !request.data)
|
|
30
|
+
return { ok: false, error: "give the file's content as base64 data" };
|
|
31
|
+
let bytes = Buffer.from(request.data, "base64");
|
|
32
|
+
if (request.upload !== undefined) {
|
|
33
|
+
const part = joinFileParts(request, "session", bytes);
|
|
34
|
+
if (part.reply) return part.reply;
|
|
35
|
+
bytes = part.bytes;
|
|
36
|
+
}
|
|
37
|
+
if (!bytes.length) return { ok: false, error: "the file is empty" };
|
|
38
|
+
const name = fileName(request.name);
|
|
39
|
+
const mime =
|
|
40
|
+
typeof request.mime === "string" &&
|
|
41
|
+
/^[a-z0-9.+-]+\/[a-z0-9.+-]+$/i.test(request.mime)
|
|
42
|
+
? request.mime.toLowerCase()
|
|
43
|
+
: mimeFor(name);
|
|
44
|
+
const limit = fileLimit(mime, bytes);
|
|
45
|
+
if (bytes.length > limit.bytes)
|
|
46
|
+
return {
|
|
47
|
+
ok: false,
|
|
48
|
+
error: `the file is ${(bytes.length / 2 ** 20).toFixed(1)} MB; ${limit.kind} can be up to ${limit.bytes / 2 ** 20} MB`,
|
|
49
|
+
};
|
|
50
|
+
dropOldFiles();
|
|
51
|
+
const id = randomUUID();
|
|
52
|
+
const place = path.join(folder(), id);
|
|
53
|
+
ensureDir(place);
|
|
54
|
+
fs.writeFileSync(path.join(place, name), bytes, { mode: 0o600 });
|
|
55
|
+
fs.writeFileSync(
|
|
56
|
+
path.join(place, ABOUT),
|
|
57
|
+
JSON.stringify({ name, mime, bytes: bytes.length }),
|
|
58
|
+
{ mode: 0o600 }
|
|
59
|
+
);
|
|
60
|
+
return { ok: true, file: { id, name, mime, bytes: bytes.length } };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** The files a message names, each with where it is saved; `{ error }` if any is not here to send. */
|
|
64
|
+
export function namedSessionFiles(ids) {
|
|
65
|
+
if (ids === undefined) return { files: [] };
|
|
66
|
+
if (!Array.isArray(ids) || ids.length > MOST_FILES)
|
|
67
|
+
return { error: `a message carries up to ${MOST_FILES} files` };
|
|
68
|
+
const files = [];
|
|
69
|
+
for (const id of ids) {
|
|
70
|
+
const place = ID.test(String(id)) ? path.join(folder(), String(id)) : null;
|
|
71
|
+
if (!place || !fs.existsSync(path.join(place, ABOUT)))
|
|
72
|
+
return {
|
|
73
|
+
error: "a file with this message is no longer here; add it again",
|
|
74
|
+
};
|
|
75
|
+
const about = JSON.parse(fs.readFileSync(path.join(place, ABOUT), "utf8"));
|
|
76
|
+
files.push({ ...about, id, path: path.join(place, about.name) });
|
|
77
|
+
}
|
|
78
|
+
return { files };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** The words a session takes, saying where each file is saved so it can open them. */
|
|
82
|
+
export const withSavedPaths = (text, files) =>
|
|
83
|
+
[text, ...files.map((file) => `(Attached ${file.name}: ${file.path})`)]
|
|
84
|
+
.filter(Boolean)
|
|
85
|
+
.join("\n\n");
|
package/lib/setupChoices.mjs
CHANGED
|
@@ -2,9 +2,9 @@ import fs from "node:fs";
|
|
|
2
2
|
import os from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { spawnSync } from "node:child_process";
|
|
5
|
-
import { readJson,
|
|
5
|
+
import { readJson, updateJson } from "./files.mjs";
|
|
6
6
|
import { appDirs, EDITOR_IDS, editorInstall, t3App } from "./places.mjs";
|
|
7
|
-
import { herdrInstalled } from "./herdr.mjs";
|
|
7
|
+
import { herdrApp, herdrInstalled } from "./herdr.mjs";
|
|
8
8
|
import { processTable } from "./live.mjs";
|
|
9
9
|
|
|
10
10
|
// What the setup screens choose, kept in the config the rest of Harness reads: where threads open (`workplace`,
|
|
@@ -105,6 +105,15 @@ export function appsHere({
|
|
|
105
105
|
}
|
|
106
106
|
// Places Harness opens threads in that are not apps: herdr (its tabs, through its own server) and, on a Mac, Neovim
|
|
107
107
|
// (in a tab of a Neovim already open, else the terminal picked above, or the one open now, running it).
|
|
108
|
+
// The Herdr app (a window over herdr-core) and the herdr TUI are different programs; either can be someone's home.
|
|
109
|
+
const herdrWindow = herdrApp();
|
|
110
|
+
if (herdrWindow)
|
|
111
|
+
apps.push({
|
|
112
|
+
id: "herdr-app",
|
|
113
|
+
name: "Herdr",
|
|
114
|
+
app: herdrWindow,
|
|
115
|
+
place: { kind: "herdr", name: "Herdr", client: "app" },
|
|
116
|
+
});
|
|
108
117
|
if (herdrInstalled({}))
|
|
109
118
|
apps.push({
|
|
110
119
|
id: "herdr",
|
|
@@ -279,7 +288,7 @@ export function createSetupChoices({
|
|
|
279
288
|
}) {
|
|
280
289
|
const config = () => readJson(configPath, {});
|
|
281
290
|
const save = (change) =>
|
|
282
|
-
|
|
291
|
+
updateJson(configPath, (saved) => ({ ...saved, ...change }));
|
|
283
292
|
const pickedNow = () => {
|
|
284
293
|
const current = config();
|
|
285
294
|
return new Set(
|
package/lib/setupMode.mjs
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
|
+
import { writeConfig } from "./secretStore.mjs";
|
|
1
2
|
import fs from "node:fs";
|
|
2
3
|
import os from "node:os";
|
|
3
4
|
import { listenControl } from "./controlSocket.mjs";
|
|
4
|
-
import {
|
|
5
|
+
import { updateJson } from "./files.mjs";
|
|
5
6
|
import {
|
|
7
|
+
createApprovalAnswers,
|
|
6
8
|
keepJoinCode,
|
|
7
9
|
setupPageUrl,
|
|
8
10
|
startPairing,
|
|
9
11
|
waitForApproval,
|
|
10
12
|
} from "./pairing.mjs";
|
|
11
|
-
import { writeBrowserOffer } from "./phones.mjs";
|
|
12
13
|
import { stopSetupHere } from "./removeHarness.mjs";
|
|
14
|
+
import { loadDeviceIdentity } from "./deviceIdentity.mjs";
|
|
13
15
|
|
|
14
16
|
// Before this computer is signed in, Harness runs here anyway, so the buddy can show setup and the installer can
|
|
15
17
|
// print the code. One pairing is held open at a time and it can be approved two ways: signing in on the page the
|
|
@@ -30,6 +32,23 @@ const RETRY_MAX_MS = 60_000;
|
|
|
30
32
|
*/
|
|
31
33
|
export async function untilSignedIn({ paths, origin, agents = [], log }) {
|
|
32
34
|
const say = (line) => log?.(line);
|
|
35
|
+
// This computer as one of the person's devices. The code to compare comes once a device starts approving it: both
|
|
36
|
+
// add a random number, each locked in before seeing the other's (src/shared/deviceApproval.ts).
|
|
37
|
+
const identity = await loadDeviceIdentity(paths);
|
|
38
|
+
const device = {
|
|
39
|
+
deviceId: identity.deviceId,
|
|
40
|
+
label: os
|
|
41
|
+
.hostname()
|
|
42
|
+
.replace(/\.local$/, "")
|
|
43
|
+
.slice(0, 64),
|
|
44
|
+
signingKey: identity.signing.publicKey,
|
|
45
|
+
sealingKey: identity.sealing.publicKey,
|
|
46
|
+
};
|
|
47
|
+
const keys = {
|
|
48
|
+
sealingKey: device.sealingKey,
|
|
49
|
+
signingKey: device.signingKey,
|
|
50
|
+
};
|
|
51
|
+
const answers = await createApprovalAnswers(origin, keys);
|
|
33
52
|
const state = {
|
|
34
53
|
code: null,
|
|
35
54
|
own: false,
|
|
@@ -40,16 +59,12 @@ export async function untilSignedIn({ paths, origin, agents = [], log }) {
|
|
|
40
59
|
let signedIn;
|
|
41
60
|
const done = new Promise((resolve) => (signedIn = resolve));
|
|
42
61
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
offerFile: paths.browserOffer,
|
|
49
|
-
}).catch(() => null)
|
|
62
|
+
// The page that approves this computer. The browser it opens in needs no link to it: once both are on the person's
|
|
63
|
+
// devices, they talk end to end (src/main/device/deviceLines.ts).
|
|
64
|
+
const linkFor = async () =>
|
|
65
|
+
state.code
|
|
66
|
+
? setupPageUrl(origin, { code: state.code, own: state.own })
|
|
50
67
|
: null;
|
|
51
|
-
return setupPageUrl(origin, { code: state.code, own: state.own }, browser);
|
|
52
|
-
};
|
|
53
68
|
|
|
54
69
|
const answer = async (request) => {
|
|
55
70
|
if (request.command === "status")
|
|
@@ -59,12 +74,14 @@ export async function untilSignedIn({ paths, origin, agents = [], log }) {
|
|
|
59
74
|
ok: true,
|
|
60
75
|
phase: "signin",
|
|
61
76
|
code: state.own ? state.code : null,
|
|
62
|
-
|
|
77
|
+
// The code to match on the device approving this computer, once one started; null until then.
|
|
78
|
+
approvalCode: answers.code(),
|
|
79
|
+
url: await linkFor(),
|
|
63
80
|
computer: os.hostname().replace(/\.local$/, ""),
|
|
64
81
|
error: state.error,
|
|
65
82
|
};
|
|
66
83
|
if (request.command === "setup.signin") {
|
|
67
|
-
const url = await linkFor(
|
|
84
|
+
const url = await linkFor();
|
|
68
85
|
return url
|
|
69
86
|
? { ok: true, url }
|
|
70
87
|
: { ok: false, error: state.error || "Harness is not reachable yet." };
|
|
@@ -92,12 +109,26 @@ export async function untilSignedIn({ paths, origin, agents = [], log }) {
|
|
|
92
109
|
let wait = RETRY_FIRST_MS;
|
|
93
110
|
for (;;) {
|
|
94
111
|
try {
|
|
95
|
-
|
|
112
|
+
await answers.renew();
|
|
113
|
+
const pairing = await startPairing(
|
|
114
|
+
origin,
|
|
115
|
+
agents,
|
|
116
|
+
device,
|
|
117
|
+
answers.commitment()
|
|
118
|
+
);
|
|
96
119
|
Object.assign(state, pairing, { error: null, startedAt: Date.now() });
|
|
97
120
|
if (pairing.own) keepJoinCode(paths.machine, pairing.code);
|
|
98
121
|
say(`setup: holding a sign-in for this computer (${pairing.pairId})`);
|
|
99
122
|
wait = RETRY_FIRST_MS;
|
|
100
|
-
const token = await waitForApproval(
|
|
123
|
+
const token = await waitForApproval(
|
|
124
|
+
origin,
|
|
125
|
+
pairing.pairId,
|
|
126
|
+
async (challenge) => {
|
|
127
|
+
const code = await answers.answer(pairing.pairId, challenge);
|
|
128
|
+
if (code)
|
|
129
|
+
say(`setup: connect this computer only where ${code} shows`);
|
|
130
|
+
}
|
|
131
|
+
);
|
|
101
132
|
return token;
|
|
102
133
|
} catch (error) {
|
|
103
134
|
// A pairing that ran out is replaced at once; anything else waits before asking Harness again.
|
|
@@ -115,16 +146,30 @@ export async function untilSignedIn({ paths, origin, agents = [], log }) {
|
|
|
115
146
|
// Signed in through setup: the app's screens come next, until the person presses Start there. None of the folders
|
|
116
147
|
// macOS guards is searched until the person picks it there: a config without the choice means all three, which is
|
|
117
148
|
// what installs from before setup chose (localStack.mjs), so a new one starts with the choice made, empty.
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
149
|
+
// A config that cannot be read is left as it is (files.mjs updateJson reads it strictly and writes nothing here)
|
|
150
|
+
// and setup says why, rather than signing in over the person's choices; the token then goes where the person's
|
|
151
|
+
// config keeps it (secretStore.mjs writeConfig: the keychain on a Mac).
|
|
152
|
+
let next;
|
|
153
|
+
try {
|
|
154
|
+
updateJson(paths.config, (before) => {
|
|
155
|
+
next = {
|
|
156
|
+
...before,
|
|
157
|
+
origin,
|
|
158
|
+
token,
|
|
159
|
+
setupDone: false,
|
|
160
|
+
// Nothing comes down until the person says yes in setup's Local models step, this time too if they set up before.
|
|
161
|
+
localModels: "ask",
|
|
162
|
+
searchFolders: Array.isArray(before.searchFolders)
|
|
163
|
+
? before.searchFolders
|
|
164
|
+
: [],
|
|
165
|
+
};
|
|
166
|
+
return null;
|
|
167
|
+
});
|
|
168
|
+
} catch (error) {
|
|
169
|
+
say(`setup: ${error.message}`);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
writeConfig(paths.config, next);
|
|
128
173
|
say("setup: signed in");
|
|
129
174
|
signedIn();
|
|
130
175
|
});
|