tryharness 0.7.31 → 0.7.33
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 +48 -0
- package/cli.mjs +175 -1
- package/lib/activity.mjs +82 -28
- package/lib/actorRoster.mjs +106 -0
- package/lib/asks.mjs +58 -0
- package/lib/boardAccess.mjs +328 -0
- package/lib/boardCommands.mjs +28 -0
- package/lib/boardFileCommands.mjs +228 -0
- package/lib/boardFiles.mjs +584 -0
- package/lib/boardProtocol.json +470 -0
- package/lib/boardProtocol.mjs +27 -0
- package/lib/boardThreads.mjs +153 -0
- package/lib/boardTools.mjs +202 -0
- package/lib/boardWatches.mjs +92 -0
- package/lib/bridge.mjs +272 -0
- package/lib/cards.mjs +70 -82
- package/lib/coordinator.mjs +153 -15
- package/lib/daemon.mjs +927 -5395
- package/lib/desktop.mjs +8 -5
- package/lib/digest.mjs +27 -0
- package/lib/goalCommands.mjs +459 -0
- package/lib/harnessModel.mjs +166 -0
- package/lib/lessons.mjs +328 -0
- package/lib/mcp-stdio.mjs +8 -2
- package/lib/models.mjs +118 -13
- package/lib/phones.mjs +8 -119
- package/lib/reactions.mjs +108 -0
- package/lib/roomPage.mjs +44 -0
- package/lib/runAuthority.mjs +109 -0
- package/lib/runWorker.mjs +503 -0
- package/lib/runner.mjs +11 -6
- package/lib/schedules.mjs +361 -0
- package/lib/sessionControl.mjs +788 -0
- package/lib/sessionIndex.mjs +245 -0
- package/lib/store.mjs +386 -20
- package/lib/swarm.mjs +183 -14
- package/lib/t3.mjs +84 -15
- package/lib/taskCommands.mjs +737 -0
- package/lib/taskRuns.mjs +196 -0
- package/lib/threadRuns.mjs +471 -0
- package/package.json +1 -1
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// The person's reaction to their agents' work, step 1b of the swarm's learning. When the person posts in a thread after
|
|
2
|
+
// agents delivered something since they last wrote, Harness's server reads the post against that work
|
|
3
|
+
// (src/server/swarm/reaction.ts): approves, approves with changes, rejects, or not a reaction, and whose work it is
|
|
4
|
+
// about (one agent's post, or what they made together). The verdict is kept on this board for each agent it is about,
|
|
5
|
+
// and each agent's card counts the verdicts on its work (cards.mjs). Nothing is read on the privacy setting, with this
|
|
6
|
+
// computer off Harness, or from a Harness that does not read reactions (swarm_reactions): such a post has no verdict.
|
|
7
|
+
|
|
8
|
+
// What an agent delivers in a thread: its result, a post or a file. Questions, notes and held posts are not work.
|
|
9
|
+
const WORK_KINDS = new Set(["result", "post", "file"]);
|
|
10
|
+
// Never read for a reaction, as the coordinator's round leaves them out: notes, the coordinator's own records, and posts
|
|
11
|
+
// held for the person (one may carry a secret).
|
|
12
|
+
const QUIET_KINDS = new Set(["note", "held", "round", "goal_update"]);
|
|
13
|
+
const RESULTS = 6;
|
|
14
|
+
const BEFORE = 8;
|
|
15
|
+
const POST_CHARS = 4_000;
|
|
16
|
+
|
|
17
|
+
const clip = (post) => ({
|
|
18
|
+
seq: post.seq,
|
|
19
|
+
author: post.author,
|
|
20
|
+
kind: post.kind,
|
|
21
|
+
text: post.text.slice(0, POST_CHARS),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* What the person's post in a thread may react to, from the thread's posts: the posts since they last wrote (`before`)
|
|
26
|
+
* and, among them, the agents' work (`results`), newest last. No results: nothing was delivered to react to.
|
|
27
|
+
*/
|
|
28
|
+
export function workSince(posts, post, isCoordinatorPost) {
|
|
29
|
+
const earlier = posts.filter(
|
|
30
|
+
(other) => other.seq < post.seq && !QUIET_KINDS.has(other.kind)
|
|
31
|
+
);
|
|
32
|
+
const lastOwn = earlier.findLast(
|
|
33
|
+
(other) => other.author === "user" && other.kind === "post"
|
|
34
|
+
);
|
|
35
|
+
const since = earlier.filter((other) => other.seq > (lastOwn?.seq ?? 0));
|
|
36
|
+
return {
|
|
37
|
+
before: since.slice(-BEFORE).map(clip),
|
|
38
|
+
results: since
|
|
39
|
+
.filter(
|
|
40
|
+
(other) =>
|
|
41
|
+
WORK_KINDS.has(other.kind) &&
|
|
42
|
+
other.author !== "user" &&
|
|
43
|
+
!isCoordinatorPost(other)
|
|
44
|
+
)
|
|
45
|
+
.slice(-RESULTS)
|
|
46
|
+
.map(clip),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function createReactions({
|
|
51
|
+
store,
|
|
52
|
+
askHarness,
|
|
53
|
+
readsReactions,
|
|
54
|
+
isCoordinatorPost,
|
|
55
|
+
log,
|
|
56
|
+
}) {
|
|
57
|
+
/** Read the person's post in a thread; resolves once its verdicts are kept, or there is none to keep. */
|
|
58
|
+
const heard = async (thread, post) => {
|
|
59
|
+
if (!readsReactions()) return null;
|
|
60
|
+
const { before, results } = workSince(
|
|
61
|
+
store.roomPosts(thread.id, 0, 500),
|
|
62
|
+
post,
|
|
63
|
+
isCoordinatorPost
|
|
64
|
+
);
|
|
65
|
+
if (!results.length) return null;
|
|
66
|
+
let reply;
|
|
67
|
+
try {
|
|
68
|
+
reply = await askHarness(
|
|
69
|
+
"react",
|
|
70
|
+
{
|
|
71
|
+
thread: { id: thread.id, title: thread.objective.slice(0, 500) },
|
|
72
|
+
post: { seq: post.seq, text: post.text.slice(0, POST_CHARS) },
|
|
73
|
+
before,
|
|
74
|
+
results,
|
|
75
|
+
},
|
|
76
|
+
null
|
|
77
|
+
);
|
|
78
|
+
} catch (error) {
|
|
79
|
+
log(`reaction to post ${post.seq} in ${thread.id}: ${error.message}`);
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
// The bridge's answer carries the reaction's fields beside `ok`.
|
|
83
|
+
const reaction = reply?.ok ? (reply.result ?? reply) : null;
|
|
84
|
+
const delivered = new Set(results.map((result) => result.author));
|
|
85
|
+
const agents = (reaction?.agents ?? []).filter((agent) =>
|
|
86
|
+
delivered.has(agent)
|
|
87
|
+
);
|
|
88
|
+
if (!reaction?.verdict || !agents.length) {
|
|
89
|
+
log(
|
|
90
|
+
`reaction to post ${post.seq} in ${thread.id}: ${reply?.error || "no verdict"}`
|
|
91
|
+
);
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
for (const agent of agents)
|
|
95
|
+
store.recordReaction({
|
|
96
|
+
postId: post.id,
|
|
97
|
+
goalId: thread.id,
|
|
98
|
+
postSeq: post.seq,
|
|
99
|
+
aboutSeq: reaction.about ?? null,
|
|
100
|
+
agent,
|
|
101
|
+
verdict: reaction.verdict,
|
|
102
|
+
judgments: reaction.judgments ?? null,
|
|
103
|
+
});
|
|
104
|
+
return { agents, verdict: reaction.verdict };
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
return { heard };
|
|
108
|
+
}
|
package/lib/roomPage.mjs
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// One page of a thread's room as any agent reads it: its newest posts, the ones before a post (`before`) going back, or
|
|
2
|
+
// the ones after a post (`since`) catching up. Each page says where the posts on either side of it start, and fits in
|
|
3
|
+
// one tool result (October 17: 27 posts of a video thread came to 64,553 characters, more than Claude Code takes in one).
|
|
4
|
+
const PAGE_CHARS = 30_000;
|
|
5
|
+
const PAGE_POSTS = 50;
|
|
6
|
+
|
|
7
|
+
const size = (post) => post.text.length + 200;
|
|
8
|
+
|
|
9
|
+
export function roomPage(store, goalId, { since, before } = {}) {
|
|
10
|
+
if (Number(since) > 0) {
|
|
11
|
+
const after = store.roomPosts(goalId, since, PAGE_POSTS + 1);
|
|
12
|
+
const posts = [];
|
|
13
|
+
let used = 0;
|
|
14
|
+
for (const post of after.slice(0, PAGE_POSTS)) {
|
|
15
|
+
if (posts.length && used + size(post) > PAGE_CHARS) break;
|
|
16
|
+
posts.push(post);
|
|
17
|
+
used += size(post);
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
posts,
|
|
21
|
+
earlierBefore: null,
|
|
22
|
+
laterAfter: posts.length < after.length ? posts.at(-1).seq : null,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
const recent = store.recentRoomPosts(goalId, {
|
|
26
|
+
before,
|
|
27
|
+
limit: PAGE_POSTS,
|
|
28
|
+
});
|
|
29
|
+
const posts = [];
|
|
30
|
+
let used = 0;
|
|
31
|
+
for (const post of [...recent.posts].reverse()) {
|
|
32
|
+
if (posts.length && used + size(post) > PAGE_CHARS) break;
|
|
33
|
+
posts.unshift(post);
|
|
34
|
+
used += size(post);
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
posts,
|
|
38
|
+
earlierBefore:
|
|
39
|
+
posts.length < recent.posts.length
|
|
40
|
+
? (posts[0]?.seq ?? null)
|
|
41
|
+
: recent.earlierBefore,
|
|
42
|
+
laterAfter: Number(before) > 0 ? (posts.at(-1)?.seq ?? null) : null,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import { spawnSync } from "node:child_process";
|
|
5
|
+
import { PS } from "./nudge.mjs";
|
|
6
|
+
import { paths } from "./paths.mjs";
|
|
7
|
+
import { MACHINE_RUNNERS } from "./members.mjs";
|
|
8
|
+
|
|
9
|
+
export function createRunAuthority({ store, installedAgents }) {
|
|
10
|
+
const RUNNERS = new Set(MACHINE_RUNNERS);
|
|
11
|
+
// A session the person typed in: its prompt hook (Claude Code, Codex) or its extension or plugin (pi, OpenCode) names
|
|
12
|
+
// the agent process, the parent of the board MCP it posts through.
|
|
13
|
+
// A run this daemon started is never one (the daemon is its parent), and an agent holding another agent's task writes
|
|
14
|
+
// as an agent until it reports.
|
|
15
|
+
const promptedBy = new Map();
|
|
16
|
+
// Unknown parent: not the person's.
|
|
17
|
+
const parentOf = (pid) =>
|
|
18
|
+
Number(
|
|
19
|
+
spawnSync(PS, ["-o", "ppid=", "-p", String(pid)], {
|
|
20
|
+
encoding: "utf8",
|
|
21
|
+
}).stdout?.trim()
|
|
22
|
+
) || null;
|
|
23
|
+
const personSession = (agent, pid) => {
|
|
24
|
+
if (
|
|
25
|
+
!RUNNERS.has(agent) ||
|
|
26
|
+
!Number.isInteger(pid) ||
|
|
27
|
+
promptedBy.get(pid) !== agent
|
|
28
|
+
)
|
|
29
|
+
return false;
|
|
30
|
+
const parent = parentOf(pid);
|
|
31
|
+
return (
|
|
32
|
+
parent !== null && parent !== process.pid && !store.holdsAgentTask(agent)
|
|
33
|
+
);
|
|
34
|
+
};
|
|
35
|
+
const runners = () => installedAgents.filter((agent) => RUNNERS.has(agent));
|
|
36
|
+
const startOfToday = () => {
|
|
37
|
+
const day = new Date();
|
|
38
|
+
day.setHours(0, 0, 0, 0);
|
|
39
|
+
return day.toISOString();
|
|
40
|
+
};
|
|
41
|
+
const realDir = (dir) => {
|
|
42
|
+
try {
|
|
43
|
+
return fs.realpathSync(dir);
|
|
44
|
+
} catch {
|
|
45
|
+
return path.resolve(dir);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const within = (dir, root) => {
|
|
49
|
+
const rel = path.relative(realDir(root), realDir(dir));
|
|
50
|
+
return rel === "" || (!rel.startsWith("..") && !path.isAbsolute(rel));
|
|
51
|
+
};
|
|
52
|
+
const aboveHome = (dir) => within(os.homedir(), dir);
|
|
53
|
+
// A coding agent's own scratch folder, for the person's tasks that name none: nothing of theirs is in it.
|
|
54
|
+
const scratchFolder = (agent) => path.join(paths.home, "work", agent);
|
|
55
|
+
const covers = (rule, dir) =>
|
|
56
|
+
realDir(dir) === realDir(scratchFolder(rule.agent)) ||
|
|
57
|
+
rule.workspaces.some((root) =>
|
|
58
|
+
rule.mode === "default" && aboveHome(root)
|
|
59
|
+
? realDir(root) === realDir(dir)
|
|
60
|
+
: within(dir, root)
|
|
61
|
+
);
|
|
62
|
+
const standingRules = () => store.standing(runners(), startOfToday());
|
|
63
|
+
// null when the run may start now; otherwise why it waits for the person.
|
|
64
|
+
const standingVerdict = ({ trust, target, workspace }) => {
|
|
65
|
+
if (trust !== "user")
|
|
66
|
+
return "Another agent wrote it, so it never starts without the person.";
|
|
67
|
+
const rule = standingRules().find((entry) => entry.agent === target);
|
|
68
|
+
if (!rule)
|
|
69
|
+
return `${target} is not a coding agent installed on this machine.`;
|
|
70
|
+
if (rule.mode === "off")
|
|
71
|
+
return `${target} is set to wait for the person's Start.`;
|
|
72
|
+
if (!covers(rule, workspace))
|
|
73
|
+
return rule.mode === "default"
|
|
74
|
+
? `${target} has not worked in ${workspace} before, so its first run there waits for the person.`
|
|
75
|
+
: `${workspace} is outside the folders ${target} may run in without asking (${rule.workspaces.join(", ")}).`;
|
|
76
|
+
if (rule.runs_today >= rule.daily_cap)
|
|
77
|
+
return `${target} already started ${rule.runs_today} runs today without asking, its daily limit.`;
|
|
78
|
+
return null;
|
|
79
|
+
};
|
|
80
|
+
const applyStanding = (task) => {
|
|
81
|
+
if (!task?.run_workspace || task.run_authorized_at) return undefined;
|
|
82
|
+
const start = `It waits for the person's Start on the Harness Board, or: npx tryharness board run ${task.id}`;
|
|
83
|
+
const reason = standingVerdict({
|
|
84
|
+
trust: task.trust,
|
|
85
|
+
target: task.target_agent,
|
|
86
|
+
workspace: task.run_workspace,
|
|
87
|
+
});
|
|
88
|
+
if (reason) return { started: false, reason: `${reason} ${start}` };
|
|
89
|
+
return store.authorizeStanding(task.id)
|
|
90
|
+
? { started: true }
|
|
91
|
+
: { started: false, reason: `It could not be authorized. ${start}` };
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const markPrompt = (pids, agent) => {
|
|
95
|
+
for (const pid of Array.isArray(pids) ? pids.slice(0, 2) : [])
|
|
96
|
+
if (Number.isInteger(pid) && pid > 1) promptedBy.set(pid, agent);
|
|
97
|
+
};
|
|
98
|
+
return {
|
|
99
|
+
RUNNERS,
|
|
100
|
+
within,
|
|
101
|
+
personSession,
|
|
102
|
+
aboveHome,
|
|
103
|
+
scratchFolder,
|
|
104
|
+
standingRules,
|
|
105
|
+
standingVerdict,
|
|
106
|
+
applyStanding,
|
|
107
|
+
markPrompt,
|
|
108
|
+
};
|
|
109
|
+
}
|