tryharness 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/daemon.mjs +18 -1
- package/package.json +1 -1
package/lib/daemon.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import fs from "node:fs";
|
|
|
2
2
|
import net from "node:net";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { spawn } from "node:child_process";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
5
6
|
import WebSocket from "ws";
|
|
6
7
|
import { randomBytes, randomUUID } from "node:crypto";
|
|
7
8
|
import { detectAgents, run } from "./commands.mjs";
|
|
@@ -16,15 +17,31 @@ import { provenanceFor, provenanceLine } from "./provenance.mjs";
|
|
|
16
17
|
import { createEmbedder, EMBEDDING_VERSION, modelPresent } from "./embedder.mjs";
|
|
17
18
|
import { fromBlob, toBlob, topK } from "./vectors.mjs";
|
|
18
19
|
|
|
19
|
-
const DAEMON_VERSION = "
|
|
20
|
+
const DAEMON_VERSION = readJson(fileURLToPath(new URL("../package.json", import.meta.url)), {}).version;
|
|
20
21
|
const PROTOCOL_VERSION = 1;
|
|
21
22
|
const RESCAN_MS = 60_000;
|
|
22
23
|
const TASK_LOG_PAGE = 64_000;
|
|
23
24
|
|
|
25
|
+
function daemonAnswers(socketPath) {
|
|
26
|
+
return new Promise((resolve) => {
|
|
27
|
+
const probe = net.createConnection(socketPath);
|
|
28
|
+
probe.once("connect", () => { probe.destroy(); resolve(true); });
|
|
29
|
+
probe.once("error", () => resolve(false));
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
24
33
|
export async function startDaemon() {
|
|
25
34
|
ensureDir(paths.home);
|
|
26
35
|
const config = readJson(paths.config, {});
|
|
27
36
|
if (!config.origin || !config.token) throw new Error("Harness is not paired. Run: npx tryharness");
|
|
37
|
+
// node-sqlite3-wasm locks with a directory that exists only during a transaction. A daemon
|
|
38
|
+
// killed mid-transaction leaves it behind and every later open fails "database is locked";
|
|
39
|
+
// with no daemon answering, nothing can hold it.
|
|
40
|
+
const lock = `${paths.database}.lock`;
|
|
41
|
+
if (fs.existsSync(lock) && !(await daemonAnswers(paths.socket))) {
|
|
42
|
+
fs.rmdirSync(lock);
|
|
43
|
+
appendLog(paths.log, "removed a stale database lock left by a stopped daemon");
|
|
44
|
+
}
|
|
28
45
|
const store = openStore(paths.database);
|
|
29
46
|
const detected = detectAgents();
|
|
30
47
|
const installedAgents = detected.filter((entry) => entry.path).map((entry) => entry.agent);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tryharness",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Harness Relay: the daemon that turns the agents on this machine into your personal swarm. Memory, history, and work handed between any of them.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"tryharness": "cli.mjs"
|