tryharness 0.7.32 → 0.7.34
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/lib/actorRoster.mjs +106 -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 +5 -83
- package/lib/coordinator.mjs +13 -3
- package/lib/daemon.mjs +809 -5459
- package/lib/goalCommands.mjs +459 -0
- package/lib/harnessModel.mjs +166 -0
- package/lib/mcp-stdio.mjs +8 -2
- package/lib/models.mjs +107 -11
- package/lib/phones.mjs +8 -121
- package/lib/roomPage.mjs +44 -0
- package/lib/runAuthority.mjs +109 -0
- package/lib/runWorker.mjs +503 -0
- package/lib/sessionControl.mjs +788 -0
- package/lib/sessionIndex.mjs +245 -0
- package/lib/store.mjs +28 -9
- package/lib/swarm.mjs +28 -9
- package/lib/taskCommands.mjs +737 -0
- package/lib/taskRuns.mjs +196 -0
- package/lib/threadRuns.mjs +487 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,6 +22,54 @@ paged when Harness displays them.
|
|
|
22
22
|
The command is idempotent. Run it again after installing another agent or to repair its
|
|
23
23
|
configuration.
|
|
24
24
|
|
|
25
|
+
## Daemon ownership
|
|
26
|
+
|
|
27
|
+
`lib/daemon.mjs` assembles features in `startDaemon` and connects the local control
|
|
28
|
+
socket and authenticated bridge. Features own their state and command handling:
|
|
29
|
+
|
|
30
|
+
| Module | Owns |
|
|
31
|
+
| --- | --- |
|
|
32
|
+
| `sessionIndex.mjs` | History scans, the OpenCode helper and targeted refreshes |
|
|
33
|
+
| `sessionControl.mjs` | Live sessions, app locations, Open plans and session messages |
|
|
34
|
+
| `runAuthority.mjs` | Prompt identity, workspace coverage and standing permission |
|
|
35
|
+
| `actorRoster.mjs` | Available agents, setup health and cards |
|
|
36
|
+
| `taskRuns.mjs` | Run records, output paging, restart recovery and execution identity |
|
|
37
|
+
| `models.mjs` | Agent catalogs, saved/run choices, agent settings and complete model/effort selections |
|
|
38
|
+
| `harnessModel.mjs` | Harness's own pick: a provider (Harness credits or a kept key or endpoint), a model of Harness's catalog there, and what a thread task carries for it |
|
|
39
|
+
| `roomPage.mjs` | One page of a thread's room, newest first, as every agent reads it (`read_room`, Harness's `thread_posts`) |
|
|
40
|
+
| `bridge.mjs` | Authenticated socket, requests, feature negotiation, heartbeat, reconnects and outage history |
|
|
41
|
+
| `threadRuns.mjs` | Durable pending wakes, fresh briefs, T3 continuity and worktree settlement |
|
|
42
|
+
| `runWorker.mjs` | Authorized board execution, workspace slots, holds, requeues and receipts |
|
|
43
|
+
| `boardFiles.mjs` | File storage, disclosure, redaction and file commands; `boardFileCommands.mjs` is its private command adapter |
|
|
44
|
+
| `goalCommands.mjs`, `taskCommands.mjs` | Goal/room operations and task lifecycle operations |
|
|
45
|
+
| `boardThreads.mjs`, `boardWatches.mjs`, `boardTools.mjs` | Relay-thread messages, watch/digest commands and local tool commands |
|
|
46
|
+
| `boardAccess.mjs` | Plain hosted-call policy and metadata-only responses |
|
|
47
|
+
|
|
48
|
+
`createModelRouter` returns the complete run selection, including model, effort,
|
|
49
|
+
provenance and any fallback explanation. It owns the precedence of a run's explicit
|
|
50
|
+
pick, the person's saved choice or Auto, and the agent's own settings. Missing
|
|
51
|
+
settings stay null. The worker records and executes the result without resolving
|
|
52
|
+
defaults again; `runner.mjs` and `t3.mjs` translate it for their execution formats.
|
|
53
|
+
Cards and model listings read agent settings through the same model module.
|
|
54
|
+
|
|
55
|
+
`boardCommands.mjs` establishes the common request context and dispatches to the
|
|
56
|
+
feature owner. Dispatch grants no authority: each feature still checks identity,
|
|
57
|
+
permissions, versions and sharing before acting. `daemon.mjs` wires thread execution
|
|
58
|
+
and transport through their owners; feature handlers do not own socket retry state.
|
|
59
|
+
|
|
60
|
+
Pending thread calls use the existing local metadata store. After restart, an already
|
|
61
|
+
queued wake keeps its later handoff in the fresh brief. An interrupted run remains
|
|
62
|
+
unknown. A later call for that interrupted agent becomes a held wake and the thread
|
|
63
|
+
asks for Start, so recovery preserves the request without replaying unknown effects.
|
|
64
|
+
|
|
65
|
+
`lib/boardProtocol.json` owns command names, routing, protocol/inbox versions,
|
|
66
|
+
metadata fields and the separate grants for each caller surface. Node consumers use
|
|
67
|
+
`boardProtocol.mjs`; web consumers use `src/schemas/boardProtocol.ts`; the Rust
|
|
68
|
+
desktop adapter embeds the JSON at build time. A surface uses only its own list:
|
|
69
|
+
adding a command to the catalog does not enable it for any caller. Browser and
|
|
70
|
+
hosted Harness grants deliberately differ. When adding a command, update its owner
|
|
71
|
+
and only the intended surface grants, then exercise that caller's runtime path.
|
|
72
|
+
|
|
25
73
|
## Operations
|
|
26
74
|
|
|
27
75
|
```sh
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { CLOUD_HOMED, TARGETS as ROOM_AGENTS } from "./members.mjs";
|
|
2
|
+
import { localWakes, LOCAL_WAKE_AGENTS } from "./wakes.mjs";
|
|
3
|
+
import { swarmCards } from "./cards.mjs";
|
|
4
|
+
import { nameOf } from "./members.mjs";
|
|
5
|
+
|
|
6
|
+
export function createActorRoster({
|
|
7
|
+
store,
|
|
8
|
+
installedAgents,
|
|
9
|
+
authority,
|
|
10
|
+
localWaker,
|
|
11
|
+
connected,
|
|
12
|
+
}) {
|
|
13
|
+
const RUNNERS = authority.RUNNERS;
|
|
14
|
+
const CLOUD_AGENTS = new Set(CLOUD_HOMED);
|
|
15
|
+
// What each agent that runs elsewhere needs before it picks up work by itself (Grok Bot, Muse), as Harness last said
|
|
16
|
+
// (`agent_setup`, sent on connect and on every change); OpenClaw and Hermes are set up and woken here.
|
|
17
|
+
let cloudSetup = new Map();
|
|
18
|
+
const SETUP_STATES = ["not_set_up", "waiting", "answering", "not_answering"];
|
|
19
|
+
/** { state, how, detail } for an agent that must be set up before it picks up work, null for one Harness starts. */
|
|
20
|
+
const setupOf = (agent) => {
|
|
21
|
+
if (cloudSetup.has(agent)) return cloudSetup.get(agent);
|
|
22
|
+
if (!LOCAL_WAKE_AGENTS.includes(agent)) return null;
|
|
23
|
+
const saved = localWakes()[agent];
|
|
24
|
+
if (!saved)
|
|
25
|
+
return { state: "not_set_up", how: "local-webhook", detail: null };
|
|
26
|
+
const health = localWaker.status()[agent];
|
|
27
|
+
if (health && !health.answering)
|
|
28
|
+
return {
|
|
29
|
+
state: "not_answering",
|
|
30
|
+
how: "local-webhook",
|
|
31
|
+
detail: health.lastFailure,
|
|
32
|
+
};
|
|
33
|
+
const seenAt = store
|
|
34
|
+
.agentsSeen()
|
|
35
|
+
.find((row) => row.agent === agent)?.last_seen_at;
|
|
36
|
+
return {
|
|
37
|
+
state:
|
|
38
|
+
seenAt && Date.parse(seenAt) >= Date.parse(saved.savedAt || 0)
|
|
39
|
+
? "answering"
|
|
40
|
+
: "waiting",
|
|
41
|
+
how: "local-webhook",
|
|
42
|
+
detail: null,
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
// Said to whoever hands work to an agent that will not pick it up by itself (the server says the same for its own).
|
|
46
|
+
const setupNote = (agent) => {
|
|
47
|
+
const setup = setupOf(agent);
|
|
48
|
+
if (setup?.state === "not_set_up")
|
|
49
|
+
return `${nameOf(agent)} is not set up to pick up work by itself yet, so this waits until the person sets it up in Harness.`;
|
|
50
|
+
if (setup?.state === "not_answering")
|
|
51
|
+
return `${nameOf(agent)} is not answering right now, so this waits until it does.`;
|
|
52
|
+
return null;
|
|
53
|
+
};
|
|
54
|
+
/** The agents this person can ask right now: coding agents installed here, the server's while connected, any agent that has used the board, and those Harness says can be set up. */
|
|
55
|
+
const available = () => {
|
|
56
|
+
const seen = new Set(store.agentsSeen().map((row) => row.agent));
|
|
57
|
+
const woken = localWakes();
|
|
58
|
+
return ROOM_AGENTS.filter(
|
|
59
|
+
(agent) =>
|
|
60
|
+
agent === "harness" ||
|
|
61
|
+
(RUNNERS.has(agent)
|
|
62
|
+
? installedAgents.includes(agent)
|
|
63
|
+
: CLOUD_AGENTS.has(agent)
|
|
64
|
+
? connected()
|
|
65
|
+
: seen.has(agent) || Boolean(woken[agent]) || cloudSetup.has(agent))
|
|
66
|
+
);
|
|
67
|
+
};
|
|
68
|
+
// Each agent's card (cards.mjs) as every other agent is told it, its setup included; `lessons`: what the person said
|
|
69
|
+
// about each, for a reader on this computer or Harness only.
|
|
70
|
+
const cardsFor = (ids, { lessons = true } = {}) =>
|
|
71
|
+
swarmCards(
|
|
72
|
+
store,
|
|
73
|
+
ids.map((id) => ({ id, setup: setupOf(id) })),
|
|
74
|
+
{ lessons }
|
|
75
|
+
);
|
|
76
|
+
// The person's words from other threads (lessons.mjs) stay with the agents on this computer and Harness.
|
|
77
|
+
const readsLessonsHere = (agent) => RUNNERS.has(agent) || agent === "harness";
|
|
78
|
+
|
|
79
|
+
const updateCloudSetup = (entries) => {
|
|
80
|
+
cloudSetup = new Map(
|
|
81
|
+
entries
|
|
82
|
+
.filter(
|
|
83
|
+
(entry) =>
|
|
84
|
+
entry &&
|
|
85
|
+
typeof entry.agent === "string" &&
|
|
86
|
+
SETUP_STATES.includes(entry.state)
|
|
87
|
+
)
|
|
88
|
+
.map((entry) => [
|
|
89
|
+
entry.agent,
|
|
90
|
+
{
|
|
91
|
+
state: entry.state,
|
|
92
|
+
how: typeof entry.how === "string" ? entry.how : null,
|
|
93
|
+
detail: typeof entry.detail === "string" ? entry.detail : null,
|
|
94
|
+
},
|
|
95
|
+
])
|
|
96
|
+
);
|
|
97
|
+
};
|
|
98
|
+
return {
|
|
99
|
+
setupOf,
|
|
100
|
+
setupNote,
|
|
101
|
+
available,
|
|
102
|
+
cardsFor,
|
|
103
|
+
readsLessonsHere,
|
|
104
|
+
updateCloudSetup,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import { boardCommandsFor, boardMetadata } from "./boardProtocol.mjs";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { documentText, isDocument } from "./files.mjs";
|
|
4
|
+
import { secretReason } from "./secrets.mjs";
|
|
5
|
+
import { imageKind } from "./ocr.mjs";
|
|
6
|
+
|
|
7
|
+
export function createBoardAccess({
|
|
8
|
+
store,
|
|
9
|
+
inRoom,
|
|
10
|
+
boardCommand,
|
|
11
|
+
sendThreadMessage,
|
|
12
|
+
notifyBoard,
|
|
13
|
+
namedPath,
|
|
14
|
+
textLike,
|
|
15
|
+
coveredImage,
|
|
16
|
+
}) {
|
|
17
|
+
// Once a browser is paired (store.sealedOnly), Harness's plain calls get metadata only: who, which state,
|
|
18
|
+
// when, the same as every board_changed already carries, and never the words (objectives, briefs,
|
|
19
|
+
// results, room posts, folders). The person's and Harness's own reads and writes come sealed from a paired
|
|
20
|
+
// device. What still works in the clear, for what runs on Harness's servers: a run's status, the
|
|
21
|
+
// timeline's counts, a trace's timings, a bounty's check that a guest posted; a hosted caller (Muse, Grok
|
|
22
|
+
// Bot, any connector) works the tasks it is part of in full, which it has to read.
|
|
23
|
+
const SEALED_ONLY = {
|
|
24
|
+
ok: false,
|
|
25
|
+
code: "sealed_only",
|
|
26
|
+
error:
|
|
27
|
+
"this computer answers Harness only end to end encrypted; connect this browser to it: npx tryharness link",
|
|
28
|
+
};
|
|
29
|
+
// Narrowing only: the timeline's Stop turns standing permission off.
|
|
30
|
+
const PLAIN_PERSON_COMMANDS = boardCommandsFor("plainPerson");
|
|
31
|
+
const PLAIN_HARNESS_READS = boardCommandsFor("plainHarnessReads");
|
|
32
|
+
const TASK_METADATA = boardMetadata.task;
|
|
33
|
+
const GOAL_METADATA = boardMetadata.goal;
|
|
34
|
+
const pick = (value, keys) =>
|
|
35
|
+
Object.fromEntries(
|
|
36
|
+
keys.filter((key) => key in value).map((key) => [key, value[key]])
|
|
37
|
+
);
|
|
38
|
+
const withoutWords = (task) =>
|
|
39
|
+
task && typeof task === "object"
|
|
40
|
+
? {
|
|
41
|
+
...pick(task, TASK_METADATA),
|
|
42
|
+
objective: "",
|
|
43
|
+
brief: "",
|
|
44
|
+
result: null,
|
|
45
|
+
context_refs: [],
|
|
46
|
+
run_workspace: task.run_workspace ? "(sealed)" : null,
|
|
47
|
+
redacted: true,
|
|
48
|
+
...(task.goal && typeof task.goal === "object"
|
|
49
|
+
? { goal: pick(task.goal, GOAL_METADATA) }
|
|
50
|
+
: {}),
|
|
51
|
+
}
|
|
52
|
+
: task;
|
|
53
|
+
const metadataOnly = (result) =>
|
|
54
|
+
result && typeof result === "object"
|
|
55
|
+
? {
|
|
56
|
+
...result,
|
|
57
|
+
redacted: true,
|
|
58
|
+
...(result.task ? { task: withoutWords(result.task) } : {}),
|
|
59
|
+
...(Array.isArray(result.tasks)
|
|
60
|
+
? { tasks: result.tasks.map(withoutWords) }
|
|
61
|
+
: {}),
|
|
62
|
+
...(Array.isArray(result.goals)
|
|
63
|
+
? { goals: result.goals.map(withoutWords) }
|
|
64
|
+
: {}),
|
|
65
|
+
...(Array.isArray(result.posts)
|
|
66
|
+
? {
|
|
67
|
+
posts: result.posts.map((post) =>
|
|
68
|
+
pick(post, ["id", "seq", "author", "kind", "created_at"])
|
|
69
|
+
),
|
|
70
|
+
}
|
|
71
|
+
: {}),
|
|
72
|
+
...(Array.isArray(result.files) ? { files: [] } : {}),
|
|
73
|
+
...(result.goal && typeof result.goal === "object" && !result.task
|
|
74
|
+
? { goal: pick(result.goal, ["id", "status"]) }
|
|
75
|
+
: {}),
|
|
76
|
+
}
|
|
77
|
+
: result;
|
|
78
|
+
// Harness's own notice in a goal's room (a bounty): kept as a note that mentions and wakes no one, shared with guests when asked.
|
|
79
|
+
const plainNotice = (input) => {
|
|
80
|
+
const goal = store.getTask(String(input.id || ""));
|
|
81
|
+
if (!goal || goal.kind !== "goal")
|
|
82
|
+
return { ok: false, error: "goal not found" };
|
|
83
|
+
if (goal.status !== "open")
|
|
84
|
+
return { ok: false, error: `the goal is ${goal.status}` };
|
|
85
|
+
const text = String(input.text || "")
|
|
86
|
+
.trim()
|
|
87
|
+
.slice(0, 2_000);
|
|
88
|
+
if (!text || secretReason(text))
|
|
89
|
+
return { ok: false, error: "a notice needs plain text" };
|
|
90
|
+
const post = store.roomPost({
|
|
91
|
+
goalId: goal.id,
|
|
92
|
+
author: "harness",
|
|
93
|
+
kind: "note",
|
|
94
|
+
text,
|
|
95
|
+
});
|
|
96
|
+
if (input.shareWithGuests === true)
|
|
97
|
+
for (const guest of goal.goal.guests) {
|
|
98
|
+
if (
|
|
99
|
+
!store.getThread(guest.thread) ||
|
|
100
|
+
store.getThread(guest.thread).closed_at
|
|
101
|
+
)
|
|
102
|
+
continue;
|
|
103
|
+
const sent = store.postMessage({
|
|
104
|
+
id: randomUUID(),
|
|
105
|
+
taskId: guest.thread,
|
|
106
|
+
sender: "harness",
|
|
107
|
+
text,
|
|
108
|
+
refs: [],
|
|
109
|
+
flagReason: null,
|
|
110
|
+
});
|
|
111
|
+
if (sent.ok && sent.message.state === "sent")
|
|
112
|
+
sendThreadMessage(sent.message);
|
|
113
|
+
}
|
|
114
|
+
notifyBoard(store.getTask(goal.id));
|
|
115
|
+
return {
|
|
116
|
+
ok: true,
|
|
117
|
+
post: pick(post, ["id", "seq", "author", "kind", "created_at"]),
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
const roomOf = (task) => {
|
|
121
|
+
const parent = task?.parent_id ? store.getTask(task.parent_id) : null;
|
|
122
|
+
return parent?.kind === "goal" ? parent : null;
|
|
123
|
+
};
|
|
124
|
+
// What an agent attached in a task's thread while it held the task: with the files on the task, what the task made.
|
|
125
|
+
const madeIn = (task) => {
|
|
126
|
+
const room = roomOf(task),
|
|
127
|
+
by = task.claimed_by || task.target_agent;
|
|
128
|
+
return room && task.claimed_at
|
|
129
|
+
? store
|
|
130
|
+
.taskFiles(room.id)
|
|
131
|
+
.filter(
|
|
132
|
+
(file) => file.author === by && file.created_at >= task.claimed_at
|
|
133
|
+
)
|
|
134
|
+
: [];
|
|
135
|
+
};
|
|
136
|
+
// What a caller through Harness may see: what it posted, holds or is named in, and the threads it is on. Work posted
|
|
137
|
+
// for anyone stays with the agents on this machine.
|
|
138
|
+
const visibleTo = (task, agent) =>
|
|
139
|
+
Boolean(task) &&
|
|
140
|
+
(task.target_agent === agent ||
|
|
141
|
+
task.origin_agent === agent ||
|
|
142
|
+
task.claimed_by === agent ||
|
|
143
|
+
(task.kind === "goal" && inRoom(task, agent)) ||
|
|
144
|
+
Boolean(roomOf(task) && inRoom(roomOf(task), agent)));
|
|
145
|
+
// What leaves this computer for an agent through Harness: any text in the answer that looks like a secret (the room's
|
|
146
|
+
// check, cli/lib/secrets.mjs) is replaced with a notice; the person still reads it in full here (docs/member-runs.md).
|
|
147
|
+
const withoutSecrets = (value) => {
|
|
148
|
+
if (typeof value === "string") {
|
|
149
|
+
const flag = secretReason(value);
|
|
150
|
+
return flag
|
|
151
|
+
? `[held on the person's computer: this looked like ${flag}]`
|
|
152
|
+
: value;
|
|
153
|
+
}
|
|
154
|
+
if (Array.isArray(value)) return value.map(withoutSecrets);
|
|
155
|
+
if (value && typeof value === "object")
|
|
156
|
+
return Object.fromEntries(
|
|
157
|
+
Object.entries(value).map(([key, item]) => [key, withoutSecrets(item)])
|
|
158
|
+
);
|
|
159
|
+
return value;
|
|
160
|
+
};
|
|
161
|
+
const plainBoard = (input) => {
|
|
162
|
+
const agent = String(input.agent || "");
|
|
163
|
+
// A file's bytes are checked as a whole: a text file that holds a secret stays here; an image goes with what must not
|
|
164
|
+
// leave covered (coveredImage); other binary files are not text to check.
|
|
165
|
+
if (input.command === "board.file.get") {
|
|
166
|
+
const answer = answerPlain(input);
|
|
167
|
+
if (!answer?.ok) return answer;
|
|
168
|
+
const file = store.file(String(input.fileId || ""));
|
|
169
|
+
// A document is checked by its words, which are what an agent reads; the person still gets the file itself.
|
|
170
|
+
const words =
|
|
171
|
+
file && isDocument(file.mime)
|
|
172
|
+
? documentText(namedPath(file), file.mime)
|
|
173
|
+
: null;
|
|
174
|
+
const flag =
|
|
175
|
+
(textLike(answer.file.mime) &&
|
|
176
|
+
secretReason(Buffer.from(answer.data, "base64").toString("utf8"))) ||
|
|
177
|
+
(words && secretReason(words));
|
|
178
|
+
if (flag)
|
|
179
|
+
return {
|
|
180
|
+
ok: false,
|
|
181
|
+
error: `held on the person's computer: this file looked like it holds ${flag}`,
|
|
182
|
+
};
|
|
183
|
+
if (words !== null && agent !== "user")
|
|
184
|
+
return { ok: true, file: withoutSecrets(answer.file), text: words };
|
|
185
|
+
const image =
|
|
186
|
+
(answer.file.mime.startsWith("image/") &&
|
|
187
|
+
!textLike(answer.file.mime)) ||
|
|
188
|
+
imageKind(Buffer.from(answer.data.slice(0, 12), "base64"));
|
|
189
|
+
return image
|
|
190
|
+
? {
|
|
191
|
+
pending: coveredImage(
|
|
192
|
+
{ ...answer, file: withoutSecrets(answer.file) },
|
|
193
|
+
file,
|
|
194
|
+
agent
|
|
195
|
+
),
|
|
196
|
+
}
|
|
197
|
+
: { ...answer, file: withoutSecrets(answer.file) };
|
|
198
|
+
}
|
|
199
|
+
if (agent !== "user" && agent !== "harness") {
|
|
200
|
+
const answer = answerPlain(input);
|
|
201
|
+
return answer?.pending
|
|
202
|
+
? { pending: answer.pending.then(withoutSecrets) }
|
|
203
|
+
: withoutSecrets(answer);
|
|
204
|
+
}
|
|
205
|
+
return answerPlain(input);
|
|
206
|
+
};
|
|
207
|
+
const answerPlain = (input) => {
|
|
208
|
+
const agent = String(input.agent || "");
|
|
209
|
+
// The person's and Harness's calls are answered in full only while no browser is paired; a hosted agent is always
|
|
210
|
+
// limited to what it is part of, paired or not.
|
|
211
|
+
if (!store.sealedOnly() && (agent === "user" || agent === "harness"))
|
|
212
|
+
return boardCommand(input);
|
|
213
|
+
const command = String(input.command || "");
|
|
214
|
+
// A thread Harness posts on accept: on the asking side, only one this machine asked for (it supplies the words itself).
|
|
215
|
+
if (
|
|
216
|
+
command === "board.post" &&
|
|
217
|
+
input.thread &&
|
|
218
|
+
typeof input.thread === "object" &&
|
|
219
|
+
agent === "user"
|
|
220
|
+
) {
|
|
221
|
+
return input.thread.role === "asker" &&
|
|
222
|
+
store.meta(`relay_pending:${String(input.id || "")}`)
|
|
223
|
+
? boardCommand(input)
|
|
224
|
+
: SEALED_ONLY;
|
|
225
|
+
}
|
|
226
|
+
if (agent === "harness" && PLAIN_HARNESS_READS.has(command)) {
|
|
227
|
+
const result = boardCommand(
|
|
228
|
+
command === "board.list" ? { ...input, all: true } : input
|
|
229
|
+
);
|
|
230
|
+
return result?.pending
|
|
231
|
+
? { pending: result.pending.then(metadataOnly) }
|
|
232
|
+
: metadataOnly(result);
|
|
233
|
+
}
|
|
234
|
+
// A hosted agent's search goes through Harness: only the threads it is in, never the machine's sessions.
|
|
235
|
+
if (
|
|
236
|
+
command === "board.swarm.search" &&
|
|
237
|
+
agent !== "user" &&
|
|
238
|
+
agent !== "harness"
|
|
239
|
+
)
|
|
240
|
+
return boardCommand({ ...input, teamOnly: true });
|
|
241
|
+
if (
|
|
242
|
+
command === "board.code.search" ||
|
|
243
|
+
command === "board.media.search" ||
|
|
244
|
+
command === "board.files.search" ||
|
|
245
|
+
command === "board.screens.compare" ||
|
|
246
|
+
command === "board.video.watch" ||
|
|
247
|
+
command === "board.audio.listen" ||
|
|
248
|
+
command === "board.screen.search"
|
|
249
|
+
)
|
|
250
|
+
return {
|
|
251
|
+
ok: false,
|
|
252
|
+
error:
|
|
253
|
+
"this runs only for agents on this computer: what it reads never leaves it",
|
|
254
|
+
};
|
|
255
|
+
if (
|
|
256
|
+
String(command).startsWith("board.watch.") ||
|
|
257
|
+
command === "board.digest" ||
|
|
258
|
+
command === "board.local.events"
|
|
259
|
+
)
|
|
260
|
+
return {
|
|
261
|
+
ok: false,
|
|
262
|
+
error: "watches are only for the person and agents on this computer",
|
|
263
|
+
};
|
|
264
|
+
if (agent === "harness" && command === "board.room.post")
|
|
265
|
+
return plainNotice(input);
|
|
266
|
+
if (agent === "user" || agent === "harness")
|
|
267
|
+
return PLAIN_PERSON_COMMANDS.has(command)
|
|
268
|
+
? boardCommand(input)
|
|
269
|
+
: SEALED_ONLY;
|
|
270
|
+
if (command === "board.list") {
|
|
271
|
+
const listed = boardCommand({ ...input, all: false });
|
|
272
|
+
return listed?.ok && Array.isArray(listed.tasks)
|
|
273
|
+
? {
|
|
274
|
+
...listed,
|
|
275
|
+
tasks: listed.tasks.filter((task) => visibleTo(task, agent)),
|
|
276
|
+
}
|
|
277
|
+
: listed;
|
|
278
|
+
}
|
|
279
|
+
if (command === "board.goal.list") {
|
|
280
|
+
const listed = boardCommand(input);
|
|
281
|
+
return listed?.ok
|
|
282
|
+
? {
|
|
283
|
+
...listed,
|
|
284
|
+
goals: listed.goals.filter((goal) =>
|
|
285
|
+
inRoom(store.getTask(goal.id) || { goal: { team: [] } }, agent)
|
|
286
|
+
),
|
|
287
|
+
}
|
|
288
|
+
: listed;
|
|
289
|
+
}
|
|
290
|
+
const id = String(input.id || "");
|
|
291
|
+
const task = id ? store.getTask(id) : null;
|
|
292
|
+
if (command === "board.post") {
|
|
293
|
+
const parent = input.parentId
|
|
294
|
+
? store.getTask(String(input.parentId))
|
|
295
|
+
: null;
|
|
296
|
+
return input.parentId && parent && !visibleTo(parent, agent)
|
|
297
|
+
? { ok: false, error: "task not found" }
|
|
298
|
+
: boardCommand(input);
|
|
299
|
+
}
|
|
300
|
+
if (
|
|
301
|
+
["board.thread.read", "board.thread.post"].includes(command) &&
|
|
302
|
+
task &&
|
|
303
|
+
task.claimed_by !== agent
|
|
304
|
+
)
|
|
305
|
+
return { ok: false, error: "task not found" };
|
|
306
|
+
if (command === "board.children" && task && visibleTo(task, agent)) {
|
|
307
|
+
const listed = boardCommand(input);
|
|
308
|
+
return listed?.ok
|
|
309
|
+
? {
|
|
310
|
+
...listed,
|
|
311
|
+
tasks: listed.tasks.filter((child) => visibleTo(child, agent)),
|
|
312
|
+
}
|
|
313
|
+
: listed;
|
|
314
|
+
}
|
|
315
|
+
// A task this machine does not hold is the server's own (boardCommand forwards it); one it holds is shown only to its parties.
|
|
316
|
+
if (task && !visibleTo(task, agent))
|
|
317
|
+
return {
|
|
318
|
+
ok: false,
|
|
319
|
+
error:
|
|
320
|
+
command.startsWith("board.goal.") || command.startsWith("board.room.")
|
|
321
|
+
? "goal not found"
|
|
322
|
+
: "task not found",
|
|
323
|
+
};
|
|
324
|
+
return boardCommand(input);
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
return { plainBoard, roomOf, madeIn, visibleTo, SEALED_ONLY };
|
|
328
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { boardCommandOwner } from "./boardProtocol.mjs";
|
|
2
|
+
|
|
3
|
+
// Every transport enters the same request context before a feature applies its
|
|
4
|
+
// own rules. Routing selects an implementation; it grants no execution authority.
|
|
5
|
+
export function createBoardCommands({
|
|
6
|
+
store,
|
|
7
|
+
validAgent,
|
|
8
|
+
touchListener,
|
|
9
|
+
handlers,
|
|
10
|
+
task,
|
|
11
|
+
}) {
|
|
12
|
+
return (request) => {
|
|
13
|
+
if (!validAgent(request.agent))
|
|
14
|
+
return { ok: false, error: "board requests need an agent name" };
|
|
15
|
+
if (request.command === "board.post") touchListener();
|
|
16
|
+
const agent = String(request.agent);
|
|
17
|
+
const lastLooked = store.lastSeenAt(agent);
|
|
18
|
+
store.touchAgent(agent);
|
|
19
|
+
const id = String(request.id || "");
|
|
20
|
+
const expected = Number.isInteger(request.expectedVersion)
|
|
21
|
+
? request.expectedVersion
|
|
22
|
+
: null;
|
|
23
|
+
const context = { agent, lastLooked, id, expected };
|
|
24
|
+
const owner = boardCommandOwner(String(request.command));
|
|
25
|
+
const handler = Object.hasOwn(handlers, owner) ? handlers[owner] : task;
|
|
26
|
+
return handler(request, context);
|
|
27
|
+
};
|
|
28
|
+
}
|