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
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { spawnSync } from "node:child_process";
|
|
5
|
+
import { readJson, updateJson, writeJsonAtomic } from "./files.mjs";
|
|
6
|
+
|
|
7
|
+
// Where this computer keeps its secrets (device redesign 1.8f; owner, November 9: "a computer's token ... kept in the
|
|
8
|
+
// Mac keychain"): its connection token and its two private keys (phone-identity.json, the sealing and swarm key;
|
|
9
|
+
// device-identity.json, the signing key on the person's device list). On a Mac they live in the login keychain, so
|
|
10
|
+
// they are not a plain file a backup, a synced folder or a stray `cat` would carry; elsewhere (Linux, a cloud box) in
|
|
11
|
+
// 0600 files in ~/.harness, as before.
|
|
12
|
+
//
|
|
13
|
+
// The keychain holds only the person's own Harness: the one in ~/.harness of the account's real home. A Harness run
|
|
14
|
+
// from another folder (a test's, a development checkout's) keeps files, so nothing but the person's Harness ever
|
|
15
|
+
// writes to their keychain. What the keychain does not do: a program running as the person, an agent included, can
|
|
16
|
+
// still read an item through macOS's `security` tool, since a daemon that reads its token at every start cannot ask
|
|
17
|
+
// first. Secrets go to `security` on its standard input, never in its arguments, where any process could read them.
|
|
18
|
+
|
|
19
|
+
const SERVICE = "Harness";
|
|
20
|
+
const TOKEN_ACCOUNT = "connection-token";
|
|
21
|
+
|
|
22
|
+
/** The person's own Harness folder: ~/.harness of the account's real home, whatever HOME a process was given. */
|
|
23
|
+
const ownHome = () => path.join(os.userInfo().homedir, ".harness");
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The keychain for a file in the person's own Harness folder on a Mac; null elsewhere. `keychain` names a keychain
|
|
27
|
+
* file other than the login one (tests).
|
|
28
|
+
*/
|
|
29
|
+
export function keychainFor(
|
|
30
|
+
file,
|
|
31
|
+
{ platform = process.platform, keychain = null } = {}
|
|
32
|
+
) {
|
|
33
|
+
if (platform !== "darwin") return null;
|
|
34
|
+
if (path.dirname(path.resolve(file)) !== ownHome() && !keychain) return null;
|
|
35
|
+
return {
|
|
36
|
+
get(account) {
|
|
37
|
+
const found = spawnSync(
|
|
38
|
+
"security",
|
|
39
|
+
[
|
|
40
|
+
"find-generic-password",
|
|
41
|
+
"-s",
|
|
42
|
+
SERVICE,
|
|
43
|
+
"-a",
|
|
44
|
+
account,
|
|
45
|
+
"-w",
|
|
46
|
+
...(keychain ? [keychain] : []),
|
|
47
|
+
],
|
|
48
|
+
{ encoding: "utf8" }
|
|
49
|
+
);
|
|
50
|
+
if (found.status !== 0) return null;
|
|
51
|
+
return Buffer.from(found.stdout.trim(), "base64").toString("utf8");
|
|
52
|
+
},
|
|
53
|
+
set(account, text) {
|
|
54
|
+
// Base64 inside the quotes: nothing the interactive mode would read as a quote or a space.
|
|
55
|
+
const value = Buffer.from(text, "utf8").toString("base64");
|
|
56
|
+
const added = spawnSync("security", ["-i"], {
|
|
57
|
+
input: `add-generic-password -U -s ${SERVICE} -a ${account} -w "${value}"${keychain ? ` ${keychain}` : ""}\n`,
|
|
58
|
+
encoding: "utf8",
|
|
59
|
+
});
|
|
60
|
+
if (added.status !== 0 || /error|could not/i.test(added.stderr || ""))
|
|
61
|
+
throw new Error(
|
|
62
|
+
`the keychain did not take ${account}: ${(added.stderr || "").trim() || `exit ${added.status}`}`
|
|
63
|
+
);
|
|
64
|
+
},
|
|
65
|
+
remove(account) {
|
|
66
|
+
spawnSync(
|
|
67
|
+
"security",
|
|
68
|
+
[
|
|
69
|
+
"delete-generic-password",
|
|
70
|
+
"-s",
|
|
71
|
+
SERVICE,
|
|
72
|
+
"-a",
|
|
73
|
+
account,
|
|
74
|
+
...(keychain ? [keychain] : []),
|
|
75
|
+
],
|
|
76
|
+
{ stdio: "ignore" }
|
|
77
|
+
);
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const enoent = (file) =>
|
|
83
|
+
Object.assign(new Error(`ENOENT: no such file, ${file}`), { code: "ENOENT" });
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* A secret file's text: from the keychain for the person's own Harness on a Mac (a file left from before is moved in
|
|
87
|
+
* and deleted), else the file. Throws ENOENT when there is none, as reading the file would.
|
|
88
|
+
*/
|
|
89
|
+
export function readSecretFile(file, options = {}) {
|
|
90
|
+
const keychain = keychainFor(file, options);
|
|
91
|
+
if (!keychain) return fs.readFileSync(file, "utf8");
|
|
92
|
+
const account = path.basename(file);
|
|
93
|
+
const kept = keychain.get(account);
|
|
94
|
+
if (kept !== null) return kept;
|
|
95
|
+
if (!fs.existsSync(file)) throw enoent(file);
|
|
96
|
+
const text = fs.readFileSync(file, "utf8");
|
|
97
|
+
keychain.set(account, text);
|
|
98
|
+
fs.rmSync(file, { force: true });
|
|
99
|
+
return text;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Writes a secret file's text where readSecretFile reads it; `exclusive` fails with EEXIST when there is one. */
|
|
103
|
+
export function writeSecretFile(
|
|
104
|
+
file,
|
|
105
|
+
text,
|
|
106
|
+
{ exclusive = false, ...options } = {}
|
|
107
|
+
) {
|
|
108
|
+
const keychain = keychainFor(file, options);
|
|
109
|
+
if (!keychain) {
|
|
110
|
+
fs.writeFileSync(file, text, { mode: 0o600, flag: exclusive ? "wx" : "w" });
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const account = path.basename(file);
|
|
114
|
+
if (exclusive && (keychain.get(account) !== null || fs.existsSync(file)))
|
|
115
|
+
throw Object.assign(new Error(`EEXIST: ${file}`), { code: "EEXIST" });
|
|
116
|
+
keychain.set(account, text);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Takes a secret file away, from the keychain and the folder alike (uninstall). */
|
|
120
|
+
export function removeSecretFile(file, options = {}) {
|
|
121
|
+
keychainFor(file, options)?.remove(path.basename(file));
|
|
122
|
+
fs.rmSync(file, { force: true });
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// ---- the connection token, kept apart from the rest of config.json ----
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* config.json with the connection token in it, wherever the token is kept. A token still in the file on a Mac is
|
|
129
|
+
* moved to the keychain and taken out of the file.
|
|
130
|
+
*/
|
|
131
|
+
export function readConfig(configFile, fallback = {}, options = {}) {
|
|
132
|
+
const config = readJson(configFile, null);
|
|
133
|
+
if (!config) return fallback;
|
|
134
|
+
const keychain = keychainFor(configFile, options);
|
|
135
|
+
if (!keychain) return config;
|
|
136
|
+
if (typeof config.token === "string" && config.token) {
|
|
137
|
+
keychain.set(TOKEN_ACCOUNT, config.token);
|
|
138
|
+
const { token: _moved, ...rest } = config;
|
|
139
|
+
void _moved;
|
|
140
|
+
writeJsonAtomic(configFile, rest);
|
|
141
|
+
return config;
|
|
142
|
+
}
|
|
143
|
+
const token = keychain.get(TOKEN_ACCOUNT);
|
|
144
|
+
return token ? { ...config, token } : config;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** Writes config.json; on a Mac its token goes to the keychain instead (null or absent takes it out). */
|
|
148
|
+
export function writeConfig(configFile, config, options = {}) {
|
|
149
|
+
const keychain = keychainFor(configFile, options);
|
|
150
|
+
if (!keychain) {
|
|
151
|
+
writeJsonAtomic(configFile, config);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const { token, ...rest } = config;
|
|
155
|
+
if (typeof token === "string" && token) keychain.set(TOKEN_ACCOUNT, token);
|
|
156
|
+
else if ("token" in config) keychain.remove(TOKEN_ACCOUNT);
|
|
157
|
+
writeJsonAtomic(configFile, rest);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Changes the config: read strictly, so an unreadable config.json throws instead of being replaced (files.mjs
|
|
162
|
+
* updateJson), then written as writeConfig does, the token to the keychain where there is one. `change` gets the saved
|
|
163
|
+
* config and returns the whole new one.
|
|
164
|
+
*/
|
|
165
|
+
export function updateConfig(configFile, change, options = {}) {
|
|
166
|
+
let next = null;
|
|
167
|
+
updateJson(configFile, (saved) => {
|
|
168
|
+
next = change(saved);
|
|
169
|
+
return null;
|
|
170
|
+
});
|
|
171
|
+
if (next) writeConfig(configFile, next, options);
|
|
172
|
+
return next;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** Takes the connection token away (uninstall), wherever it is kept. */
|
|
176
|
+
export function forgetConnectionToken(configFile, options = {}) {
|
|
177
|
+
keychainFor(configFile, options)?.remove(TOKEN_ACCOUNT);
|
|
178
|
+
}
|
package/lib/secrets.mjs
CHANGED
|
@@ -27,6 +27,17 @@ export function secretReason(text) {
|
|
|
27
27
|
return firstReason(HOLDING, text);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
/** `text` with every value that looks like a secret replaced by the reason it was hidden. */
|
|
31
|
+
export function maskSecrets(text) {
|
|
32
|
+
let masked = String(text || "");
|
|
33
|
+
for (const { test, reason } of PATTERNS)
|
|
34
|
+
masked = masked.replace(
|
|
35
|
+
new RegExp(test.source, test.flags.replace("g", "") + "g"),
|
|
36
|
+
`[hidden: ${reason}]`
|
|
37
|
+
);
|
|
38
|
+
return masked;
|
|
39
|
+
}
|
|
40
|
+
|
|
30
41
|
/**
|
|
31
42
|
* The reason a value is masked before it leaves (the firewall, image redaction, a sign-in's output), or null. Wider
|
|
32
43
|
* than secretReason: a shape that is a hash as often as a key is hidden here, where hiding a hash costs nothing, but
|
package/lib/seen.mjs
CHANGED
|
@@ -11,13 +11,7 @@
|
|
|
11
11
|
const KEPT_REFS = 200;
|
|
12
12
|
const SHOWN = 6;
|
|
13
13
|
|
|
14
|
-
export function createSeen({
|
|
15
|
-
store,
|
|
16
|
-
askWindows,
|
|
17
|
-
// Whether Harness can carry a sealed question to the window now (connected, and it offers sealed_ask).
|
|
18
|
-
canAsk = () => true,
|
|
19
|
-
log = () => {},
|
|
20
|
-
}) {
|
|
14
|
+
export function createSeen({ store, askWindows, log = () => {} }) {
|
|
21
15
|
const cursorKey = (browser) => `seen-cursor:${browser}`;
|
|
22
16
|
// Every browser read so far, kept apart from what it saw: one whose items were all forgotten keeps its place.
|
|
23
17
|
const browsers = () => {
|
|
@@ -30,10 +24,10 @@ export function createSeen({
|
|
|
30
24
|
|
|
31
25
|
/** One read from the person's window: { ok, kept, gone } or { ok: false, why }. */
|
|
32
26
|
const read = async () => {
|
|
33
|
-
if (!canAsk())
|
|
34
|
-
return { ok: false, why: "Harness cannot reach the person's window now" };
|
|
35
27
|
const known = browsers();
|
|
36
28
|
const reply = await askWindows({
|
|
29
|
+
// A background read: it never opens a browser window in front of the person.
|
|
30
|
+
background: true,
|
|
37
31
|
tool: "screen_seen_since",
|
|
38
32
|
agent: "memory",
|
|
39
33
|
input: {
|
package/lib/selfUpdate.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { spawn } from "node:child_process";
|
|
3
|
+
import { execFileSync, spawn } from "node:child_process";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import { harnessNode, paths } from "./paths.mjs";
|
|
6
6
|
|
|
@@ -9,33 +9,69 @@ const CLI = fileURLToPath(new URL("../cli.mjs", import.meta.url));
|
|
|
9
9
|
/** What an update this computer started did, line by line: the upgrade's own words go here too. */
|
|
10
10
|
export const updateLog = () => path.join(paths.home, "update.log");
|
|
11
11
|
|
|
12
|
+
// An update that works restarts this daemon, so only "running" and "failed" are ever seen here.
|
|
13
|
+
let update = null;
|
|
14
|
+
|
|
15
|
+
/** The update this daemon started: "running", "failed", or null when there is none to speak of. */
|
|
16
|
+
export const updateState = () => update;
|
|
17
|
+
|
|
18
|
+
// The update runs on its own and outlives the daemon that started it, so a daemon restarted while it runs finds it here.
|
|
19
|
+
const updatePid = () => path.join(paths.home, "update.pid");
|
|
20
|
+
const runningUpdate = () => {
|
|
21
|
+
try {
|
|
22
|
+
const pid = Number(fs.readFileSync(updatePid(), "utf8"));
|
|
23
|
+
// The command, not just the id: a finished update's id can belong to something else by now.
|
|
24
|
+
const command = execFileSync("ps", ["-o", "command=", "-p", String(pid)], {
|
|
25
|
+
encoding: "utf8",
|
|
26
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
27
|
+
});
|
|
28
|
+
return command.includes("upgrade");
|
|
29
|
+
} catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
12
34
|
/**
|
|
13
|
-
* This computer updating itself to a published release, as the person asked
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* may not be at.
|
|
35
|
+
* This computer updating itself to a published release, as the person asked: `tryharness upgrade <spec>`, which fetches
|
|
36
|
+
* it, takes it only signed with Harness's release key and sets it up. It runs on its own, since setting up restarts the
|
|
37
|
+
* daemon that started it. Asked from this computer it also updates and reopens the buddy; asked from home it opens no
|
|
38
|
+
* window, as the person may not be at this computer.
|
|
17
39
|
*/
|
|
18
|
-
export function startUpdate(spec, { from, log = () => {} }) {
|
|
40
|
+
export function startUpdate(spec, { from, here = false, log = () => {} }) {
|
|
41
|
+
const to = spec === "latest" ? "the newest release" : spec;
|
|
42
|
+
if (update === "running" || runningUpdate())
|
|
43
|
+
return { ok: true, from, to: spec, note: `Already updating to ${to}.` };
|
|
44
|
+
const asked = `updating from ${from} to ${spec}, as the person asked ${here ? "here" : "from home"}`;
|
|
19
45
|
const out = fs.openSync(updateLog(), "a");
|
|
20
46
|
try {
|
|
21
|
-
fs.writeSync(
|
|
22
|
-
|
|
23
|
-
|
|
47
|
+
fs.writeSync(out, `${new Date().toISOString()} ${asked}\n`);
|
|
48
|
+
const child = spawn(
|
|
49
|
+
harnessNode(),
|
|
50
|
+
[CLI, "upgrade", spec, ...(here ? [] : ["--no-desktop"])],
|
|
51
|
+
{
|
|
52
|
+
detached: true,
|
|
53
|
+
stdio: ["ignore", out, out],
|
|
54
|
+
env: process.env,
|
|
55
|
+
}
|
|
24
56
|
);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
57
|
+
update = "running";
|
|
58
|
+
child.on("error", () => {
|
|
59
|
+
update = "failed";
|
|
60
|
+
});
|
|
61
|
+
child.on("exit", (code) => {
|
|
62
|
+
update = code === 0 ? null : "failed";
|
|
63
|
+
if (code !== 0) log(`the update to ${spec} stopped: see ${updateLog()}`);
|
|
29
64
|
});
|
|
65
|
+
fs.writeFileSync(updatePid(), String(child.pid));
|
|
30
66
|
child.unref();
|
|
31
67
|
} finally {
|
|
32
68
|
fs.closeSync(out);
|
|
33
69
|
}
|
|
34
|
-
log(
|
|
70
|
+
log(asked);
|
|
35
71
|
return {
|
|
36
72
|
ok: true,
|
|
37
73
|
from,
|
|
38
74
|
to: spec,
|
|
39
|
-
note: `Updating from ${from} to ${
|
|
75
|
+
note: `Updating from ${from} to ${to}: it restarts on its own in a minute or two.`,
|
|
40
76
|
};
|
|
41
77
|
}
|