tryharness 0.7.82 → 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 +193 -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 +57 -2
- 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 +2435 -333
- 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 +2 -2
- 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/onboard.mjs +6 -6
- 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 +212 -130
- 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
package/lib/repoLinks.mjs
CHANGED
|
@@ -1,57 +1,111 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import os from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import { spawn } from "node:child_process";
|
|
4
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
5
5
|
import { randomUUID } from "node:crypto";
|
|
6
|
+
import { gitSaid, IDENTITY } from "./jamGit.mjs";
|
|
6
7
|
|
|
7
8
|
// A room from a repository link: the person pastes a GitHub link (or any git host's), Harness finds that repository on
|
|
8
9
|
// this computer by its shared remote, and the room works there; when it is not here, the person picks a folder and
|
|
9
10
|
// Harness clones it into that folder. Git stays the record: the room is anchored by the checkout's first commit and
|
|
10
|
-
// its origin remote (
|
|
11
|
+
// its origin remote (jamGit.mjs anchorOf), so whatever the people agree on lives on the remote, not in Harness.
|
|
12
|
+
// accessTo says what this computer's own git sign-ins can do with a repository, for starting a room (jamAccess.mjs).
|
|
11
13
|
//
|
|
12
14
|
// Board commands, the person's only (an agent does not clone onto the computer):
|
|
13
15
|
// board.repo.find { link } → { repo, here: folder | null, places: [folders to clone into] }
|
|
14
16
|
// board.repo.clone { link, parent } → { folder }
|
|
15
17
|
// With detached:true, clone returns {operation,state:"cloning"}; board.repo.clone.read {operation} returns progress
|
|
16
18
|
// or the final result. Short calls fit existing browser/buddy transports while the clone's own deadline runs here.
|
|
17
|
-
// Then board.
|
|
19
|
+
// Then board.jam.create { link } (or { folder }) starts a jam on it.
|
|
18
20
|
|
|
19
|
-
const HOSTS = ["github.com", "gitlab.com", "bitbucket.org", "codeberg.org"];
|
|
20
21
|
const NAME = /^[A-Za-z0-9._-]+$/;
|
|
22
|
+
const HOST = /^[a-z0-9][a-z0-9.-]*$/;
|
|
23
|
+
const SSH_USER = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
24
|
+
// On these hosts a repository is always owner/name, so anything after that is a page of it.
|
|
25
|
+
const TWO_PART_HOSTS = ["github.com", "bitbucket.org", "codeberg.org"];
|
|
26
|
+
// Elsewhere a repository can sit in nested groups, and its pages start at one of these words.
|
|
27
|
+
const PAGE_WORDS = [
|
|
28
|
+
"-",
|
|
29
|
+
"tree",
|
|
30
|
+
"blob",
|
|
31
|
+
"pull",
|
|
32
|
+
"pulls",
|
|
33
|
+
"issues",
|
|
34
|
+
"commit",
|
|
35
|
+
"commits",
|
|
36
|
+
"src",
|
|
37
|
+
"browse",
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
const repositoryParts = (host, repoPath) => {
|
|
41
|
+
const parts = repoPath.split("/").filter(Boolean);
|
|
42
|
+
if (TWO_PART_HOSTS.includes(host)) return parts.slice(0, 2);
|
|
43
|
+
const page = parts.findIndex(
|
|
44
|
+
(part, index) => index >= 2 && PAGE_WORDS.includes(part)
|
|
45
|
+
);
|
|
46
|
+
return page === -1 ? parts : parts.slice(0, page);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/** The parts of a link's text that name a place: host, port, ssh user, repository path, and web scheme. */
|
|
50
|
+
function placeOf(raw) {
|
|
51
|
+
if (raw.startsWith("/")) return null;
|
|
52
|
+
const sshUrl = raw.match(
|
|
53
|
+
/^ssh:\/\/(?:([^@/]+)@)?([^:/]+)(?::(\d+))?\/(.+)$/i
|
|
54
|
+
);
|
|
55
|
+
if (sshUrl) {
|
|
56
|
+
const [, user, host, port, repoPath] = sshUrl;
|
|
57
|
+
return { user, host, sshPort: port, repoPath };
|
|
58
|
+
}
|
|
59
|
+
const scp = raw.match(/^([^@/\s]+)@([^:/\s]+):(.+)$/);
|
|
60
|
+
if (scp) {
|
|
61
|
+
const [, user, host, repoPath] = scp;
|
|
62
|
+
return { user, host, repoPath };
|
|
63
|
+
}
|
|
64
|
+
const hasScheme = /^[a-z][a-z0-9+.-]*:\/\//i.test(raw);
|
|
65
|
+
let url;
|
|
66
|
+
try {
|
|
67
|
+
url = new URL(hasScheme ? raw : `https://${raw}`);
|
|
68
|
+
} catch {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
if (!["https:", "http:"].includes(url.protocol)) return null;
|
|
72
|
+
// Text with no scheme is a link only if its first part reads as a host name, not a word or a relative path.
|
|
73
|
+
if (!hasScheme && !url.hostname.includes(".")) return null;
|
|
74
|
+
return {
|
|
75
|
+
host: url.hostname,
|
|
76
|
+
webPort: url.port,
|
|
77
|
+
scheme: url.protocol.slice(0, -1),
|
|
78
|
+
repoPath: url.pathname,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
21
81
|
|
|
22
82
|
/**
|
|
23
|
-
* A repository link as people paste it: https://github.com/owner/name, with or without .git, a /tree/…
|
|
24
|
-
* github.com/owner/name,
|
|
83
|
+
* A repository link as people paste it, on any git host: https://github.com/owner/name, with or without .git, a /tree/…
|
|
84
|
+
* page of it, github.com/owner/name, git@github.com:owner/name.git, https://git.acme.com/group/team/name or
|
|
85
|
+
* ssh://git@git.acme.com:2222/group/name.git. Null for anything else.
|
|
25
86
|
*/
|
|
26
87
|
export function parseRepoLink(text) {
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
if (!["https:", "http:"].includes(url.protocol)) return null;
|
|
39
|
-
host = url.hostname;
|
|
40
|
-
[owner, name] = url.pathname.split("/").filter(Boolean);
|
|
41
|
-
}
|
|
42
|
-
host = String(host || "")
|
|
43
|
-
.toLowerCase()
|
|
44
|
-
.replace(/^www\./, "");
|
|
45
|
-
name = String(name || "").replace(/\.git$/, "");
|
|
46
|
-
if (!HOSTS.includes(host) || !NAME.test(owner || "") || !NAME.test(name))
|
|
88
|
+
const place = placeOf(String(text || "").trim());
|
|
89
|
+
if (!place) return null;
|
|
90
|
+
const host = place.host.toLowerCase().replace(/^www\./, "");
|
|
91
|
+
const user = place.user ?? "git";
|
|
92
|
+
if (!HOST.test(host) || !SSH_USER.test(user)) return null;
|
|
93
|
+
const parts = repositoryParts(host, place.repoPath);
|
|
94
|
+
if (parts.length < 2) return null;
|
|
95
|
+
const name = parts.at(-1).replace(/\.git$/, "");
|
|
96
|
+
const owner = parts.slice(0, -1).join("/");
|
|
97
|
+
if (!NAME.test(name) || parts.slice(0, -1).some((part) => !NAME.test(part)))
|
|
47
98
|
return null;
|
|
99
|
+
const web = place.webPort ? `${host}:${place.webPort}` : host;
|
|
48
100
|
return {
|
|
49
101
|
host,
|
|
50
102
|
owner,
|
|
51
103
|
name,
|
|
52
104
|
label: `${owner}/${name}`,
|
|
53
|
-
https:
|
|
54
|
-
ssh:
|
|
105
|
+
https: `${place.scheme ?? "https"}://${web}/${owner}/${name}.git`,
|
|
106
|
+
ssh: place.sshPort
|
|
107
|
+
? `ssh://${user}@${host}:${place.sshPort}/${owner}/${name}.git`
|
|
108
|
+
: `${user}@${host}:${owner}/${name}.git`,
|
|
55
109
|
};
|
|
56
110
|
}
|
|
57
111
|
|
|
@@ -186,13 +240,15 @@ const beforeRemote = (text) =>
|
|
|
186
240
|
.split(/[\r\n]+/)
|
|
187
241
|
.every((line) => !line.trim() || /^Cloning into /.test(line.trim()));
|
|
188
242
|
|
|
189
|
-
|
|
243
|
+
/** `wholeCall`: the deadline covers the whole call, not only the wait for the remote's first byte. */
|
|
244
|
+
function gitLater(cwd, args, firstByteMs, { wholeCall = false } = {}) {
|
|
190
245
|
return new Promise((resolve) => {
|
|
191
246
|
// Its own process group: git hands the network to a helper (git-remote-https, ssh) that would outlive git itself
|
|
192
247
|
// and keep the output open, so giving up stops the whole group.
|
|
193
248
|
const child = spawn("git", args, {
|
|
194
249
|
cwd,
|
|
195
|
-
|
|
250
|
+
// LC_ALL: accessTo reads git's own English words to tell a dead network from a refusal.
|
|
251
|
+
env: { ...process.env, GIT_TERMINAL_PROMPT: "0", LC_ALL: "C" },
|
|
196
252
|
detached: true,
|
|
197
253
|
});
|
|
198
254
|
let err = "";
|
|
@@ -217,7 +273,7 @@ function gitLater(cwd, args, firstByteMs) {
|
|
|
217
273
|
}, firstByteMs);
|
|
218
274
|
child.stderr.on("data", (chunk) => {
|
|
219
275
|
err += chunk;
|
|
220
|
-
if (!answered && !beforeRemote(String(chunk))) {
|
|
276
|
+
if (!wholeCall && !answered && !beforeRemote(String(chunk))) {
|
|
221
277
|
answered = true;
|
|
222
278
|
clearTimeout(timer);
|
|
223
279
|
}
|
|
@@ -227,6 +283,110 @@ function gitLater(cwd, args, firstByteMs) {
|
|
|
227
283
|
});
|
|
228
284
|
}
|
|
229
285
|
|
|
286
|
+
// How long one question to a remote may take (reading its branches, or a dry-run push). Measured on a Mac against
|
|
287
|
+
// github.com, November 2026, 10 runs of each over https and ssh, on a private repository with write access, a public
|
|
288
|
+
// one without it and one that does not exist: 173-801 ms, the slowest a dry-run push over ssh. Thirty seconds is about
|
|
289
|
+
// forty times that, for a company host behind a VPN, which has not been measured. Past it the answer is "unknown": the
|
|
290
|
+
// person is asked to try again and nobody is told they lack access.
|
|
291
|
+
export const ACCESS_ASK_MS = 30_000;
|
|
292
|
+
|
|
293
|
+
// A throwaway branch name a dry-run push asks about. Nothing is ever written to it.
|
|
294
|
+
const PROBE_REF = "refs/heads/harness-access-check";
|
|
295
|
+
|
|
296
|
+
// git's own words for not reaching the remote at all, which says nothing about the person's access.
|
|
297
|
+
const UNREACHABLE =
|
|
298
|
+
/could not resolve host|failed to connect|connection (?:timed out|refused|reset)|operation timed out|network is unreachable|no route to host|did not answer/i;
|
|
299
|
+
|
|
300
|
+
/** Runs `work` with a throwaway repository holding one empty commit, for a dry-run push to ask about. */
|
|
301
|
+
async function withProbe(work) {
|
|
302
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "harness-access-"));
|
|
303
|
+
const inProbe = (...args) =>
|
|
304
|
+
spawnSync("git", [...IDENTITY, ...args], { cwd: dir, encoding: "utf8" });
|
|
305
|
+
try {
|
|
306
|
+
inProbe("init", "-q");
|
|
307
|
+
inProbe(
|
|
308
|
+
"-c",
|
|
309
|
+
"commit.gpgsign=false",
|
|
310
|
+
"commit",
|
|
311
|
+
"-q",
|
|
312
|
+
"--allow-empty",
|
|
313
|
+
"-m",
|
|
314
|
+
"access check"
|
|
315
|
+
);
|
|
316
|
+
const sha = inProbe("rev-parse", "HEAD").stdout.trim();
|
|
317
|
+
return await work({ dir, refspec: `${sha}:${PROBE_REF}` });
|
|
318
|
+
} finally {
|
|
319
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/** Whether this computer can read and push through one address: write, read, none, or unknown (no answer). */
|
|
324
|
+
async function levelAt(address, probe, deadlineMs) {
|
|
325
|
+
const ask = (cwd, args) =>
|
|
326
|
+
gitLater(cwd, args, deadlineMs, { wholeCall: true });
|
|
327
|
+
const failed = (level, err) => ({
|
|
328
|
+
level: UNREACHABLE.test(err) ? "unknown" : level,
|
|
329
|
+
address,
|
|
330
|
+
said: gitSaid(err),
|
|
331
|
+
});
|
|
332
|
+
const read = await ask(probe.dir, ["ls-remote", "-q", "--", address, "HEAD"]);
|
|
333
|
+
if (!read.ok) return failed("none", read.err);
|
|
334
|
+
const write = await ask(probe.dir, [
|
|
335
|
+
...IDENTITY,
|
|
336
|
+
"push",
|
|
337
|
+
"--dry-run",
|
|
338
|
+
"--quiet",
|
|
339
|
+
"--",
|
|
340
|
+
address,
|
|
341
|
+
probe.refspec,
|
|
342
|
+
]);
|
|
343
|
+
return write.ok
|
|
344
|
+
? { level: "write", address, said: "" }
|
|
345
|
+
: failed("read", write.err);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// Best first: someone whose https says no but whose ssh key can push has write access.
|
|
349
|
+
const LEVEL_ORDER = ["write", "read", "none", "unknown"];
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* What this computer's own git sign-ins can do with a repository, asked of the remote and changing nothing there: its
|
|
353
|
+
* best level over the address given and the same repository's other addresses (https and ssh), and the address that
|
|
354
|
+
* reached it. A folder remote has only itself to try.
|
|
355
|
+
*/
|
|
356
|
+
export async function accessTo(remote, { deadlineMs = ACCESS_ASK_MS } = {}) {
|
|
357
|
+
const link = parseRepoLink(remote);
|
|
358
|
+
const addresses = [
|
|
359
|
+
...new Set([remote, ...(link ? [link.https, link.ssh] : [])]),
|
|
360
|
+
];
|
|
361
|
+
return withProbe(async (probe) => {
|
|
362
|
+
const answers = [];
|
|
363
|
+
for (const address of addresses) {
|
|
364
|
+
const answer = await levelAt(address, probe, deadlineMs);
|
|
365
|
+
if (answer.level === "write") return answer;
|
|
366
|
+
answers.push(answer);
|
|
367
|
+
}
|
|
368
|
+
return LEVEL_ORDER.flatMap((level) =>
|
|
369
|
+
answers.filter((answer) => answer.level === level)
|
|
370
|
+
)[0];
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/** Whether pushes through exactly this address get through; unknown when the remote doesn't answer. */
|
|
375
|
+
export const levelThrough = (address) =>
|
|
376
|
+
withProbe((probe) => levelAt(address, probe, ACCESS_ASK_MS));
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Points a new copy's origin at the address that can push. A public repository clones over https with no sign-in at all,
|
|
380
|
+
* and its pushes would then fail even though the person's ssh key could make them.
|
|
381
|
+
*/
|
|
382
|
+
async function originThatPushes(copy, clonedFrom) {
|
|
383
|
+
const access = await accessTo(clonedFrom);
|
|
384
|
+
if (access.level !== "write" || access.address === clonedFrom) return;
|
|
385
|
+
spawnSync("git", ["remote", "set-url", "origin", access.address], {
|
|
386
|
+
cwd: copy,
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
|
|
230
390
|
/**
|
|
231
391
|
* Clone the linked repository into `parent`, as a folder named for it (name-2 and on when one is there). The https
|
|
232
392
|
* address first, then ssh, so either the person's GitHub sign-in or their ssh key opens a private repository.
|
|
@@ -247,19 +407,28 @@ export async function cloneInto({ link, parent, firstByteMs = FIRST_BYTE_MS }) {
|
|
|
247
407
|
// --progress: git reports the remote's answer as it comes, which is what the deadline waits for.
|
|
248
408
|
const cloned = await gitLater(
|
|
249
409
|
where,
|
|
250
|
-
["clone", "--progress", address, target],
|
|
410
|
+
["clone", "--progress", "--", address, target],
|
|
251
411
|
firstByteMs
|
|
252
412
|
);
|
|
253
|
-
if (cloned.ok)
|
|
254
|
-
|
|
413
|
+
if (cloned.ok) {
|
|
414
|
+
await originThatPushes(target, address);
|
|
415
|
+
return { ok: true, folder: fs.realpathSync(target) };
|
|
416
|
+
}
|
|
417
|
+
last = gitSaid(cloned.err) || "git clone failed";
|
|
255
418
|
fs.rmSync(target, { recursive: true, force: true });
|
|
256
419
|
}
|
|
257
420
|
return {
|
|
258
421
|
ok: false,
|
|
259
|
-
error: `Couldn't clone ${link.label}: ${last}.
|
|
422
|
+
error: `Couldn't clone ${link.label}: ${last}. The link may be wrong, or this computer isn't signed in to an account with access to it. ${signInHint(link.host)}`,
|
|
260
423
|
};
|
|
261
424
|
}
|
|
262
425
|
|
|
426
|
+
/** How to sign in to a git host on this computer, in words. */
|
|
427
|
+
export const signInHint = (host) =>
|
|
428
|
+
host === "github.com"
|
|
429
|
+
? "To sign in to GitHub: gh auth login."
|
|
430
|
+
: `Sign in to ${host} on this computer.`;
|
|
431
|
+
|
|
263
432
|
/** The board commands above. `knownFolders`: the folders the person's agents work in (folders.mjs). */
|
|
264
433
|
export function createRepoLinks({
|
|
265
434
|
knownFolders = () => [],
|
package/lib/runAuthority.mjs
CHANGED
|
@@ -12,13 +12,8 @@ import {
|
|
|
12
12
|
speaksThroughHarness,
|
|
13
13
|
} from "./members.mjs";
|
|
14
14
|
import { FROM_MACHINE } from "./machineRoutes.mjs";
|
|
15
|
-
import { runCapability, runningPids } from "./runner.mjs";
|
|
16
|
-
import {
|
|
17
|
-
descendsFrom,
|
|
18
|
-
peerPids,
|
|
19
|
-
processParents,
|
|
20
|
-
seesPeers,
|
|
21
|
-
} from "./peerProcess.mjs";
|
|
15
|
+
import { runCapability, runCapabilityOfPid, runningPids } from "./runner.mjs";
|
|
16
|
+
import { peerPids, processParents, rootOf, seesPeers } from "./peerProcess.mjs";
|
|
22
17
|
|
|
23
18
|
/**
|
|
24
19
|
* Set by the daemon on a board call Harness's server made for a hosted agent (daemon.mjs, the bridge's board message):
|
|
@@ -65,7 +60,6 @@ const RUN_COMMANDS = new Set([
|
|
|
65
60
|
"runs.here",
|
|
66
61
|
"wake.local",
|
|
67
62
|
"t3.status",
|
|
68
|
-
"phone.identity",
|
|
69
63
|
"machine.report",
|
|
70
64
|
]);
|
|
71
65
|
// Reading the board as the person: what these answer is already in the board's own file, which a program a run starts
|
|
@@ -105,6 +99,7 @@ const PRIVATE_COMMANDS = new Set([
|
|
|
105
99
|
"board.swarm.memory",
|
|
106
100
|
"board.wallet",
|
|
107
101
|
"board.watch.add",
|
|
102
|
+
"board.watch.arm",
|
|
108
103
|
"mcp.download",
|
|
109
104
|
]);
|
|
110
105
|
// Harness's own tools such a run may call through the relay: none that read the person's screen, memory or
|
|
@@ -112,8 +107,47 @@ const PRIVATE_COMMANDS = new Set([
|
|
|
112
107
|
const OPEN_HARNESS_TOOLS = new Set(["archetype"]);
|
|
113
108
|
const PRIVATE_REFUSAL =
|
|
114
109
|
"Work done for someone else does not reach the person's screen, memory, conversations, files, money or secrets: only this thread and its folder.";
|
|
115
|
-
|
|
116
|
-
|
|
110
|
+
// A run in a jam reaches what is in the jam and nothing else of the person's (docs/jam-plan.md J4.4): its own room, the
|
|
111
|
+
// tasks and files in it, and its own folder. Listings of the person's threads and their friendships are theirs.
|
|
112
|
+
const JAM_REFUSAL =
|
|
113
|
+
"A run in a jam reaches that jam alone: its room, the tasks and files in it, and its own folder.";
|
|
114
|
+
const JAM_LISTINGS = new Set([
|
|
115
|
+
"board.list",
|
|
116
|
+
"board.goal.list",
|
|
117
|
+
"board.swarm.list",
|
|
118
|
+
"board.jam.list",
|
|
119
|
+
"board.digest",
|
|
120
|
+
]);
|
|
121
|
+
// The fields a call names a thread, a task or a file by.
|
|
122
|
+
const NAMED_THREAD = ["id", "goalId", "thread", "threadId", "parentId", "work"];
|
|
123
|
+
/**
|
|
124
|
+
* Why a run working for someone else (or held in, or in a jam) may not make this call, or null. `within(file, folder)`;
|
|
125
|
+
* `inThread(id, thread)` and `fileIn(fileId, thread)`: whether a task or thread, or a file, is in the jam's room
|
|
126
|
+
* `run.thread`.
|
|
127
|
+
*/
|
|
128
|
+
export const privateReach = (
|
|
129
|
+
command,
|
|
130
|
+
request,
|
|
131
|
+
run,
|
|
132
|
+
within,
|
|
133
|
+
inThread = () => false,
|
|
134
|
+
fileIn = () => false
|
|
135
|
+
) => {
|
|
136
|
+
if (run.thread) {
|
|
137
|
+
if (
|
|
138
|
+
JAM_LISTINGS.has(command) ||
|
|
139
|
+
command.startsWith("board.relay.") ||
|
|
140
|
+
command.startsWith("board.thread.")
|
|
141
|
+
)
|
|
142
|
+
return JAM_REFUSAL;
|
|
143
|
+
for (const field of NAMED_THREAD) {
|
|
144
|
+
const named = request[field];
|
|
145
|
+
if (named == null || named === "") continue;
|
|
146
|
+
if (!inThread(String(named), run.thread)) return JAM_REFUSAL;
|
|
147
|
+
}
|
|
148
|
+
if (request.fileId && !fileIn(String(request.fileId), run.thread))
|
|
149
|
+
return JAM_REFUSAL;
|
|
150
|
+
}
|
|
117
151
|
if (PRIVATE_COMMANDS.has(command)) return PRIVATE_REFUSAL;
|
|
118
152
|
if (command === "board.swarm.search" && !request.thread)
|
|
119
153
|
return PRIVATE_REFUSAL;
|
|
@@ -149,7 +183,13 @@ const runMayAsk = (command) =>
|
|
|
149
183
|
command.startsWith("mcp.") ||
|
|
150
184
|
RUN_COMMANDS.has(command);
|
|
151
185
|
|
|
152
|
-
export function createRunAuthority({
|
|
186
|
+
export function createRunAuthority({
|
|
187
|
+
store,
|
|
188
|
+
installedAgents,
|
|
189
|
+
// Whether a folder is one another of the person's computers runs home's work in (ownMachines.mjs runsWorkIn).
|
|
190
|
+
runsWorkOn = () => false,
|
|
191
|
+
self = () => null,
|
|
192
|
+
}) {
|
|
153
193
|
const RUNNERS = new Set(MACHINE_RUNNERS);
|
|
154
194
|
// A session the person typed in: its prompt hook (Claude Code, Codex) or its extension or plugin (pi, OpenCode) names
|
|
155
195
|
// the agent process, the parent of the board MCP it posts through.
|
|
@@ -193,6 +233,15 @@ export function createRunAuthority({ store, installedAgents }) {
|
|
|
193
233
|
return rel === "" || (!rel.startsWith("..") && !path.isAbsolute(rel));
|
|
194
234
|
};
|
|
195
235
|
const aboveHome = (dir) => within(os.homedir(), dir);
|
|
236
|
+
// A task or thread in a jam's room: the room itself, the jam it is the room of, or a task in it.
|
|
237
|
+
const inThread = (id, thread) =>
|
|
238
|
+
id === thread ||
|
|
239
|
+
store.meta(`jam-room:${thread}`) === id ||
|
|
240
|
+
store.getTask(id)?.parent_id === thread;
|
|
241
|
+
const fileIn = (fileId, thread) => {
|
|
242
|
+
const owner = store.file(fileId)?.task_id;
|
|
243
|
+
return Boolean(owner) && inThread(owner, thread);
|
|
244
|
+
};
|
|
196
245
|
// A coding agent's own scratch folder, for the person's tasks that name none: nothing of theirs is in it.
|
|
197
246
|
const scratchFolder = (agent) => path.join(paths.home, "work", agent);
|
|
198
247
|
// The only limits on where and how often the person's agents start are the ones the person set: folders and a daily
|
|
@@ -203,16 +252,20 @@ export function createRunAuthority({ store, installedAgents }) {
|
|
|
203
252
|
["work", "worktrees"].some((place) =>
|
|
204
253
|
within(dir, path.join(paths.home, place))
|
|
205
254
|
);
|
|
206
|
-
const
|
|
255
|
+
const awayMachine = (id) => (id && id !== self() ? id : null);
|
|
256
|
+
// A folder on another computer goes by that computer's home and folders; this one's mean nothing there.
|
|
257
|
+
const covers = (rule, dir, machine = null) =>
|
|
207
258
|
realDir(dir) === realDir(scratchFolder(rule.agent)) ||
|
|
208
259
|
(rule.mode === "named"
|
|
209
260
|
? rule.workspaces.some((root) => within(dir, root))
|
|
210
|
-
:
|
|
261
|
+
: machine
|
|
262
|
+
? runsWorkOn(machine, dir)
|
|
263
|
+
: harnessWork(dir) || (within(dir, os.homedir()) && !aboveHome(dir)));
|
|
211
264
|
const pastLimit = (rule) =>
|
|
212
265
|
rule.mode === "named" && rule.runs_today >= rule.daily_cap;
|
|
213
266
|
const standingRules = () => store.standing(runners(), startOfToday());
|
|
214
267
|
// null when the run may start now; otherwise why it waits for the person.
|
|
215
|
-
const standingVerdict = ({ trust, target, workspace }) => {
|
|
268
|
+
const standingVerdict = ({ trust, target, workspace, machine = null }) => {
|
|
216
269
|
if (trust !== "user")
|
|
217
270
|
return "Another agent wrote it, so it never starts without the person.";
|
|
218
271
|
const rule = standingRules().find((entry) => entry.agent === target);
|
|
@@ -220,7 +273,7 @@ export function createRunAuthority({ store, installedAgents }) {
|
|
|
220
273
|
return `${target} is not a coding agent installed on this machine.`;
|
|
221
274
|
if (rule.mode === "off")
|
|
222
275
|
return `${target} is set to wait for the person's Start.`;
|
|
223
|
-
if (!covers(rule, workspace))
|
|
276
|
+
if (!covers(rule, workspace, awayMachine(machine)))
|
|
224
277
|
return rule.mode === "named"
|
|
225
278
|
? `${workspace} is outside the folders ${target} may run in without asking (${rule.workspaces.join(", ")}).`
|
|
226
279
|
: `${workspace} is not a folder below the home folder, where agents run without the person.`;
|
|
@@ -233,6 +286,7 @@ export function createRunAuthority({ store, installedAgents }) {
|
|
|
233
286
|
const start = `It waits for the person's Start on the Harness Board, or: npx tryharness board run ${task.id}`;
|
|
234
287
|
const reason = standingVerdict({
|
|
235
288
|
trust: task.trust,
|
|
289
|
+
machine: task.target_machine,
|
|
236
290
|
target: task.target_agent,
|
|
237
291
|
workspace: task.run_workspace,
|
|
238
292
|
});
|
|
@@ -290,7 +344,8 @@ export function createRunAuthority({ store, installedAgents }) {
|
|
|
290
344
|
agent: task.target_agent,
|
|
291
345
|
proposer,
|
|
292
346
|
since: startOfToday(),
|
|
293
|
-
covered: (rule) =>
|
|
347
|
+
covered: (rule) =>
|
|
348
|
+
!folder || covers(rule, folder, awayMachine(task.target_machine)),
|
|
294
349
|
pastLimit,
|
|
295
350
|
folder,
|
|
296
351
|
scratch,
|
|
@@ -335,7 +390,7 @@ export function createRunAuthority({ store, installedAgents }) {
|
|
|
335
390
|
const reason =
|
|
336
391
|
askRefusal(ask) ??
|
|
337
392
|
(task.origin_agent !== ask.proposer ||
|
|
338
|
-
task.trust !== "agent" ||
|
|
393
|
+
(task.trust !== "agent" && ask.here !== true) ||
|
|
339
394
|
task.kind !== "task" ||
|
|
340
395
|
!task.parent_id ||
|
|
341
396
|
!RUNNERS.has(task.target_agent)
|
|
@@ -367,7 +422,8 @@ export function createRunAuthority({ store, installedAgents }) {
|
|
|
367
422
|
? `${nameOf(task.target_agent)} is set to wait for your Start.`
|
|
368
423
|
: !rule?.proposers.includes(proposal.proposer)
|
|
369
424
|
? `you took ${nameOf(proposal.proposer)}'s asks off ${nameOf(task.target_agent)}'s standing permission.`
|
|
370
|
-
: proposal.folder &&
|
|
425
|
+
: proposal.folder &&
|
|
426
|
+
!covers(rule, proposal.folder, awayMachine(task.target_machine))
|
|
371
427
|
? `${proposal.folder} is no longer among the folders it may run in without asking.`
|
|
372
428
|
: changed && rule.mode === "named" && rule.runs_today > rule.daily_cap
|
|
373
429
|
? "you lowered its daily limit below the runs it already started today."
|
|
@@ -398,11 +454,27 @@ export function createRunAuthority({ store, installedAgents }) {
|
|
|
398
454
|
return why;
|
|
399
455
|
};
|
|
400
456
|
|
|
457
|
+
// A call a run makes is that run's agent's, under that run's limits, whatever agent it names.
|
|
458
|
+
const asRun = (request, command, run) => {
|
|
459
|
+
request.agent = run.agent;
|
|
460
|
+
if (run.restricted) request.restricted = true;
|
|
461
|
+
request[RUN_CALLER] = run;
|
|
462
|
+
if (!runMayAsk(command))
|
|
463
|
+
return "A run Harness started cannot do that; only the person can.";
|
|
464
|
+
if (run.restricted && command.startsWith("mcp."))
|
|
465
|
+
return "A restricted run reaches this computer's board, not the person's Harness.";
|
|
466
|
+
if (run.restricted || run.forAnotherPerson || run.thread)
|
|
467
|
+
return privateReach(command, request, run, within, inThread, fileIn);
|
|
468
|
+
return null;
|
|
469
|
+
};
|
|
470
|
+
|
|
401
471
|
/**
|
|
402
472
|
* Who a call on the local socket is, before anything acts on it; a refusal to answer with, or null. A call carrying a
|
|
403
|
-
* run's capability is that run's agent with that run's limits, whatever agent it names. Without one, a call
|
|
404
|
-
*
|
|
405
|
-
*
|
|
473
|
+
* run's capability is that run's agent with that run's limits, whatever agent it names. Without one, a call (any but
|
|
474
|
+
* a read of the board) from a program inside a run this daemon started is held to that run all the same, whatever
|
|
475
|
+
* agent it names: the capability was dropped on the way (Codex gives its MCP servers few of its variables), and
|
|
476
|
+
* naming another agent, Harness or the person is no way around the run's limits. The person's own sessions and
|
|
477
|
+
* terminal are not runs.
|
|
406
478
|
*/
|
|
407
479
|
const checkCaller = async (request, socket) => {
|
|
408
480
|
const command = String(request.command || "");
|
|
@@ -411,18 +483,8 @@ export function createRunAuthority({ store, installedAgents }) {
|
|
|
411
483
|
delete request.runToken;
|
|
412
484
|
if (!run)
|
|
413
485
|
return "That run has ended, so Harness does not take its calls.";
|
|
414
|
-
request
|
|
415
|
-
if (run.restricted) request.restricted = true;
|
|
416
|
-
request[RUN_CALLER] = run;
|
|
417
|
-
if (!runMayAsk(command))
|
|
418
|
-
return "A run Harness started cannot do that; only the person can.";
|
|
419
|
-
if (run.restricted && command.startsWith("mcp."))
|
|
420
|
-
return "A restricted run reaches this computer's board, not the person's Harness.";
|
|
421
|
-
if (run.restricted || run.forAnotherPerson)
|
|
422
|
-
return privateReach(command, request, run, within);
|
|
423
|
-
return null;
|
|
486
|
+
return asRun(request, command, run);
|
|
424
487
|
}
|
|
425
|
-
if (request.agent !== "user" && runMayAsk(command)) return null;
|
|
426
488
|
if (PERSON_READS.has(command)) return null;
|
|
427
489
|
const runs = runningPids();
|
|
428
490
|
// Windows has no tool here that names a named pipe's client; there the capability alone tells a run's calls apart.
|
|
@@ -432,13 +494,14 @@ export function createRunAuthority({ store, installedAgents }) {
|
|
|
432
494
|
peerPids(socket),
|
|
433
495
|
processParents(),
|
|
434
496
|
]);
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
497
|
+
if (!peers?.length || !parents)
|
|
498
|
+
return "Harness could not tell which program asked, so it did not act. Try again.";
|
|
499
|
+
const root = rootOf(peers, runs, parents);
|
|
500
|
+
if (root === null) return null;
|
|
501
|
+
const run = runCapabilityOfPid(root);
|
|
502
|
+
return run
|
|
503
|
+
? asRun(request, command, run)
|
|
504
|
+
: "A program inside a run Harness started cannot act as another agent or as the person.";
|
|
442
505
|
};
|
|
443
506
|
|
|
444
507
|
const markPrompt = (pids, agent) => {
|