tryharness 0.7.69 → 0.7.71
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/cli.mjs +37 -14
- package/lib/agentSignIn.mjs +2 -2
- package/lib/boardCommands.mjs +1 -2
- package/lib/cards.mjs +2 -2
- package/lib/computerAddress.mjs +150 -0
- package/lib/coordinator.mjs +25 -8
- package/lib/daemon.mjs +19 -3
- package/lib/firewall.mjs +4 -5
- package/lib/goalCommands.mjs +13 -1
- package/lib/machineRuns.mjs +56 -10
- package/lib/mcp-stdio.mjs +28 -5
- package/lib/members.mjs +16 -0
- package/lib/ownMachines.mjs +5 -28
- package/lib/redact.mjs +5 -5
- package/lib/runAuthority.mjs +159 -1
- package/lib/runWorker.mjs +20 -2
- package/lib/secretPatterns.json +8 -2
- package/lib/secrets.mjs +19 -3
- package/lib/store.mjs +207 -7
- package/lib/swarm.mjs +35 -15
- package/lib/taskCommands.mjs +154 -9
- package/lib/team.mjs +18 -0
- package/lib/threadActions.mjs +54 -18
- package/lib/threadAuthority.mjs +13 -15
- package/lib/threadRuns.mjs +113 -6
- package/lib/wakes.mjs +1 -1
- package/npm-shrinkwrap.json +10 -10
- package/package.json +3 -3
- package/release.json +30 -29
package/lib/store.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import sqliteWasm from "node-sqlite3-wasm";
|
|
|
4
4
|
import { parseSession } from "./parsers.mjs";
|
|
5
5
|
import { provenanceFor } from "./provenance.mjs";
|
|
6
6
|
import { BOOK_TABLES } from "./book.mjs";
|
|
7
|
+
import { PROPOSERS } from "./members.mjs";
|
|
7
8
|
|
|
8
9
|
const SCHEMA_VERSION = 11;
|
|
9
10
|
const INDEX_FORMAT_VERSION = 2;
|
|
@@ -32,6 +33,11 @@ export const DEFAULT_DAILY_RUNS = 10;
|
|
|
32
33
|
export const FAILURE_CAUSES = ["person", "start", "exit", "agent"];
|
|
33
34
|
// An agent's record leaves out failures that say nothing about it: the person's stop and a run that never started.
|
|
34
35
|
const AGENTS_OWN = "not (status = 'failed' and failure in ('person', 'start'))";
|
|
36
|
+
// What an asker hears of under finished (finishedFor), and the receipt naming one such result: the full task id, the
|
|
37
|
+
// status it reached and when it was reported, so a task asked again and reported anew is a new result to tell.
|
|
38
|
+
const FINISHED_STATUSES = "('done', 'failed', 'needs_input')";
|
|
39
|
+
const RESULT_RECEIPT =
|
|
40
|
+
"t.id || ':' || t.status || ':' || coalesce(t.reported_at, t.updated_at)";
|
|
35
41
|
// What the swarm's memory can show (swarmMemory.mjs): what was said, made, checked or asked in the person's threads and
|
|
36
42
|
// tasks. A contribution's thread is its own task when that is a thread, else its task's parent thread.
|
|
37
43
|
export const MEMORY_KINDS = [
|
|
@@ -176,7 +182,9 @@ export function openStore(file) {
|
|
|
176
182
|
mode text not null,
|
|
177
183
|
workspaces text not null,
|
|
178
184
|
daily_cap integer not null,
|
|
179
|
-
set_at text not null
|
|
185
|
+
set_at text not null,
|
|
186
|
+
proposers text not null default '[]',
|
|
187
|
+
proposers_set integer not null default 0
|
|
180
188
|
);
|
|
181
189
|
create table if not exists board_goals (
|
|
182
190
|
goal_id text primary key,
|
|
@@ -448,6 +456,24 @@ export function openStore(file) {
|
|
|
448
456
|
db.exec(
|
|
449
457
|
"alter table board_standing add column mode text not null default 'named'"
|
|
450
458
|
);
|
|
459
|
+
if (
|
|
460
|
+
!db
|
|
461
|
+
.all("pragma table_info(board_standing)")
|
|
462
|
+
.some((column) => column.name === "proposers")
|
|
463
|
+
)
|
|
464
|
+
db.exec(
|
|
465
|
+
"alter table board_standing add column proposers text not null default '[]'"
|
|
466
|
+
);
|
|
467
|
+
// Until October 31 nobody started a coding agent unless named; a rule naming someone is the person's own choice, except
|
|
468
|
+
// one naming both agents that could then be named (Grok Bot and Muse), which meant all of them.
|
|
469
|
+
if (
|
|
470
|
+
!db
|
|
471
|
+
.all("pragma table_info(board_standing)")
|
|
472
|
+
.some((column) => column.name === "proposers_set")
|
|
473
|
+
)
|
|
474
|
+
db.exec(
|
|
475
|
+
'alter table board_standing add column proposers_set integer not null default 0; update board_standing set proposers_set = 1 where proposers not in (\'[]\', \'["grok-bot","muse"]\', \'["muse","grok-bot"]\')'
|
|
476
|
+
);
|
|
451
477
|
if (
|
|
452
478
|
!db
|
|
453
479
|
.all("pragma table_info(board_contributions)")
|
|
@@ -575,6 +601,15 @@ export function openStore(file) {
|
|
|
575
601
|
// What the auditor's code found comparing a report's claims with its receipts (audit.mjs).
|
|
576
602
|
if (!boardColumns.has("audit") && boardColumns.size)
|
|
577
603
|
db.exec("alter table board_tasks add column audit text");
|
|
604
|
+
// Only the asker's explicit receipt establishes delivery. A pre-receipt board has no such evidence; its results
|
|
605
|
+
// remain available after upgrade rather than assuming an unrelated last-seen timestamp meant they were read.
|
|
606
|
+
db.exec(`create table if not exists board_result_acks (
|
|
607
|
+
agent text not null,
|
|
608
|
+
receipt text not null,
|
|
609
|
+
task_id text not null,
|
|
610
|
+
acked_at text not null,
|
|
611
|
+
primary key (agent, receipt)
|
|
612
|
+
)`);
|
|
578
613
|
|
|
579
614
|
for (const [table, columns] of [
|
|
580
615
|
["board_tasks", ["returned"]],
|
|
@@ -1158,12 +1193,43 @@ export function openStore(file) {
|
|
|
1158
1193
|
new Date().toISOString()
|
|
1159
1194
|
);
|
|
1160
1195
|
},
|
|
1196
|
+
// Back to the default; the agents the person let start it (setStandingProposers) stay theirs to take back.
|
|
1161
1197
|
resetStanding(agent) {
|
|
1198
|
+
const row = execute(
|
|
1199
|
+
"get",
|
|
1200
|
+
"select proposers_set from board_standing where agent = ?",
|
|
1201
|
+
agent
|
|
1202
|
+
);
|
|
1203
|
+
if (!row) return false;
|
|
1204
|
+
if (row.proposers_set)
|
|
1205
|
+
return (
|
|
1206
|
+
execute(
|
|
1207
|
+
"run",
|
|
1208
|
+
"update board_standing set mode = 'default', workspaces = '[]', daily_cap = ?, set_at = ? where agent = ?",
|
|
1209
|
+
DEFAULT_DAILY_RUNS,
|
|
1210
|
+
new Date().toISOString(),
|
|
1211
|
+
agent
|
|
1212
|
+
).changes === 1
|
|
1213
|
+
);
|
|
1162
1214
|
return (
|
|
1163
1215
|
execute("run", "delete from board_standing where agent = ?", agent)
|
|
1164
1216
|
.changes === 1
|
|
1165
1217
|
);
|
|
1166
1218
|
},
|
|
1219
|
+
// The person's own agents elsewhere whose clean asks in a thread start this agent's turn on its standing permission
|
|
1220
|
+
// (runAuthority.mjs admitProposed), all of them until the person chooses. Its mode, folders and daily limit stay as
|
|
1221
|
+
// they are.
|
|
1222
|
+
setStandingProposers(agent, proposers) {
|
|
1223
|
+
execute(
|
|
1224
|
+
"run",
|
|
1225
|
+
`insert into board_standing(agent, mode, workspaces, daily_cap, set_at, proposers, proposers_set) values(?, 'default', '[]', ?, ?, ?, 1)
|
|
1226
|
+
on conflict(agent) do update set proposers = excluded.proposers, proposers_set = 1, set_at = excluded.set_at`,
|
|
1227
|
+
agent,
|
|
1228
|
+
DEFAULT_DAILY_RUNS,
|
|
1229
|
+
new Date().toISOString(),
|
|
1230
|
+
JSON.stringify(proposers)
|
|
1231
|
+
);
|
|
1232
|
+
},
|
|
1167
1233
|
// One rule per agent installed here, with the runs it started since `since`.
|
|
1168
1234
|
standing(agents, since) {
|
|
1169
1235
|
const rows = new Map(
|
|
@@ -1189,6 +1255,9 @@ export function openStore(file) {
|
|
|
1189
1255
|
workspaces,
|
|
1190
1256
|
daily_cap: row ? Number(row.daily_cap) : DEFAULT_DAILY_RUNS,
|
|
1191
1257
|
set_at: row?.set_at || null,
|
|
1258
|
+
proposers: row?.proposers_set
|
|
1259
|
+
? JSON.parse(row.proposers)
|
|
1260
|
+
: [...PROPOSERS],
|
|
1192
1261
|
runs_today:
|
|
1193
1262
|
Number(this.meta(`prompt-quota:${since}:${agent}`) || "0") +
|
|
1194
1263
|
Number(
|
|
@@ -2931,6 +3000,87 @@ export function openStore(file) {
|
|
|
2931
3000
|
);
|
|
2932
3001
|
return written.changes === 1;
|
|
2933
3002
|
},
|
|
3003
|
+
/**
|
|
3004
|
+
* A thread's turn that one of the person's own agents elsewhere asked for, or the task it posted itself for a coding
|
|
3005
|
+
* agent, started on its agent's standing permission: the rule read, the day's runs counted and the row authorized in
|
|
3006
|
+
* one transaction, so two asks at once never both take the last run of the day. It counts as one of the day's
|
|
3007
|
+
* standing runs, whoever asked. `covered`: whether the rule covers `folder`, the folder checked (runAuthority.mjs).
|
|
3008
|
+
* `scratch`: where a posted task naming no folder runs on this computer; another computer's makes its own. The
|
|
3009
|
+
* receipt keeps the rule's revision, the folder checked, and the agent, folder and computer it was admitted to run
|
|
3010
|
+
* with, for the check again before it starts (runAuthority.mjs proposedHold). Null when
|
|
3011
|
+
* it started; otherwise why not.
|
|
3012
|
+
*/
|
|
3013
|
+
authorizeProposed(
|
|
3014
|
+
id,
|
|
3015
|
+
{ agent, proposer, since, covered, folder = null, scratch = null }
|
|
3016
|
+
) {
|
|
3017
|
+
db.exec("begin immediate");
|
|
3018
|
+
try {
|
|
3019
|
+
const rule = this.standing([agent], since)[0];
|
|
3020
|
+
const why =
|
|
3021
|
+
rule.mode === "off"
|
|
3022
|
+
? "off"
|
|
3023
|
+
: !rule.proposers.includes(proposer)
|
|
3024
|
+
? "not-proposer"
|
|
3025
|
+
: !covered(rule)
|
|
3026
|
+
? "outside"
|
|
3027
|
+
: rule.runs_today >= rule.daily_cap
|
|
3028
|
+
? "cap"
|
|
3029
|
+
: null;
|
|
3030
|
+
const now = new Date().toISOString();
|
|
3031
|
+
const written =
|
|
3032
|
+
!why &&
|
|
3033
|
+
execute(
|
|
3034
|
+
"run",
|
|
3035
|
+
`update board_tasks set run_authorized_by = 'standing', run_authorized_at = @now, updated_at = @now, version = version + 1,
|
|
3036
|
+
run_workspace = case when kind = 'task' then coalesce(run_workspace, @scratch) else run_workspace end
|
|
3037
|
+
where id = @id and status = 'open' and trust = 'agent' and target_agent = @agent and run_authorized_at is null
|
|
3038
|
+
and id not in (select task_id from board_threads)
|
|
3039
|
+
and ((kind = 'wake' and (run_workspace is not null or target_machine is not null))
|
|
3040
|
+
or (kind = 'task' and origin_agent = @proposer and parent_id is not null
|
|
3041
|
+
and coalesce(run_workspace, @scratch, target_machine) is not null))`,
|
|
3042
|
+
{ id, agent, proposer, scratch, now }
|
|
3043
|
+
).changes === 1;
|
|
3044
|
+
if (written)
|
|
3045
|
+
this.meta(
|
|
3046
|
+
`standing-proposal:${id}`,
|
|
3047
|
+
JSON.stringify({
|
|
3048
|
+
proposer,
|
|
3049
|
+
rule_set_at: rule.set_at,
|
|
3050
|
+
folder,
|
|
3051
|
+
agent,
|
|
3052
|
+
workspace: this.getTask(id).run_workspace ?? null,
|
|
3053
|
+
machine: this.getTask(id).target_machine ?? null,
|
|
3054
|
+
at: now,
|
|
3055
|
+
})
|
|
3056
|
+
);
|
|
3057
|
+
db.exec("commit");
|
|
3058
|
+
return why ?? (written ? null : "gone");
|
|
3059
|
+
} catch (error) {
|
|
3060
|
+
if (db.inTransaction) db.exec("rollback");
|
|
3061
|
+
throw error;
|
|
3062
|
+
}
|
|
3063
|
+
},
|
|
3064
|
+
/** Who asked for a turn started on standing permission (authorizeProposed), or null. */
|
|
3065
|
+
standingProposal(id) {
|
|
3066
|
+
try {
|
|
3067
|
+
return JSON.parse(this.meta(`standing-proposal:${id}`) || "null");
|
|
3068
|
+
} catch {
|
|
3069
|
+
return null;
|
|
3070
|
+
}
|
|
3071
|
+
},
|
|
3072
|
+
// A turn started on another agent's ask that may no longer start: it waits for the person's Start again.
|
|
3073
|
+
withdrawProposed(id) {
|
|
3074
|
+
const now = new Date().toISOString();
|
|
3075
|
+
const written = execute(
|
|
3076
|
+
"run",
|
|
3077
|
+
`update board_tasks set run_authorized_by = null, run_authorized_at = null, updated_at = @now, version = version + 1
|
|
3078
|
+
where id = @id and status = 'open' and run_authorized_by = 'standing'`,
|
|
3079
|
+
{ id, now }
|
|
3080
|
+
);
|
|
3081
|
+
if (written.changes === 1) this.meta(`standing-proposal:${id}`, "");
|
|
3082
|
+
return written.changes === 1;
|
|
3083
|
+
},
|
|
2934
3084
|
// Tasks a computer should run now: authorized, still open, for an agent installed there. `machine`: that computer;
|
|
2935
3085
|
// home runs the tasks meant for it and for no computer in particular, a worker (`only`) just those meant for it.
|
|
2936
3086
|
runnableTasks(agents, machine = null, { only = false } = {}) {
|
|
@@ -3768,17 +3918,67 @@ export function openStore(file) {
|
|
|
3768
3918
|
null
|
|
3769
3919
|
);
|
|
3770
3920
|
},
|
|
3771
|
-
// Work an agent asked for that finished, failed or came back with a question
|
|
3772
|
-
// asker that cannot be woken (the Claude app, ChatGPT)
|
|
3773
|
-
|
|
3921
|
+
// Work an agent asked for that finished, failed or came back with a question and whose result it has not yet
|
|
3922
|
+
// acknowledged: how an asker that cannot be woken (the Claude app, ChatGPT), or one woken by mail (Grok Bot), learns
|
|
3923
|
+
// of its answers. Any other board call, a list or a read leaves a result here; only the asker's own receipt for that
|
|
3924
|
+
// very result (ackResult) takes it off, so a result is never spent by an unrelated call or a restart.
|
|
3925
|
+
finishedFor(agent) {
|
|
3774
3926
|
return execute(
|
|
3775
3927
|
"all",
|
|
3776
|
-
`select id, objective, target_agent, claimed_by, status, updated_at
|
|
3777
|
-
|
|
3928
|
+
`select id, objective, target_agent, claimed_by, status, parent_id, updated_at, reported_at,
|
|
3929
|
+
${RESULT_RECEIPT} as receipt
|
|
3930
|
+
from board_tasks t
|
|
3931
|
+
where origin_agent = ? and kind = 'task' and removed_at is null and status in ${FINISHED_STATUSES}
|
|
3932
|
+
and not exists (select 1 from board_result_acks a where a.agent = t.origin_agent and a.receipt = ${RESULT_RECEIPT})
|
|
3778
3933
|
order by updated_at desc limit 20`,
|
|
3934
|
+
agent
|
|
3935
|
+
).map((row) => ({ ...row, root_id: this.rootIdOf(row.id) }));
|
|
3936
|
+
},
|
|
3937
|
+
// The asker's receipt for one result, exactly as finished gave it: the task, its status and when it was reported.
|
|
3938
|
+
// Another agent's receipt, or one for a result the task no longer holds (asked again, answered and reported anew),
|
|
3939
|
+
// takes nothing. A receipt grants nothing either; it only stops the result being told again.
|
|
3940
|
+
ackResult(agent, taskId, receipt) {
|
|
3941
|
+
const current = execute(
|
|
3942
|
+
"get",
|
|
3943
|
+
`select origin_agent, ${RESULT_RECEIPT} as receipt from board_tasks t
|
|
3944
|
+
where id = ? and kind = 'task' and removed_at is null and status in ${FINISHED_STATUSES}`,
|
|
3945
|
+
taskId
|
|
3946
|
+
);
|
|
3947
|
+
if (!current || current.origin_agent !== agent)
|
|
3948
|
+
return {
|
|
3949
|
+
acked: false,
|
|
3950
|
+
reason:
|
|
3951
|
+
"only the agent that asked for this work can acknowledge its result",
|
|
3952
|
+
};
|
|
3953
|
+
if (current.receipt !== String(receipt))
|
|
3954
|
+
return {
|
|
3955
|
+
acked: false,
|
|
3956
|
+
reason: "that receipt is not this task's current result",
|
|
3957
|
+
receipt: current.receipt,
|
|
3958
|
+
};
|
|
3959
|
+
execute(
|
|
3960
|
+
"run",
|
|
3961
|
+
"insert or ignore into board_result_acks(agent, receipt, task_id, acked_at) values (?, ?, ?, ?)",
|
|
3779
3962
|
agent,
|
|
3780
|
-
|
|
3963
|
+
current.receipt,
|
|
3964
|
+
taskId,
|
|
3965
|
+
new Date().toISOString()
|
|
3781
3966
|
);
|
|
3967
|
+
return { acked: true, receipt: current.receipt };
|
|
3968
|
+
},
|
|
3969
|
+
// The task a chain of handoffs started from: the asker's original request, so a result finds its way back to it.
|
|
3970
|
+
rootIdOf(taskId) {
|
|
3971
|
+
let id = taskId;
|
|
3972
|
+
for (let depth = 0; depth < 50; depth++) {
|
|
3973
|
+
const parent = execute(
|
|
3974
|
+
"get",
|
|
3975
|
+
"select parent_id from board_tasks where id = ?",
|
|
3976
|
+
id
|
|
3977
|
+
)?.parent_id;
|
|
3978
|
+
if (!parent || parent === taskId) return id;
|
|
3979
|
+
id = parent;
|
|
3980
|
+
}
|
|
3981
|
+
return id;
|
|
3782
3982
|
},
|
|
3783
3983
|
// Messages another person's agent sent on this agent's tasks since it last read the board from `machine`.
|
|
3784
3984
|
unreadFor(agent, machine = null) {
|
package/lib/swarm.mjs
CHANGED
|
@@ -163,6 +163,8 @@ export function createSwarm({
|
|
|
163
163
|
roomAgents,
|
|
164
164
|
mentionsIn,
|
|
165
165
|
wakeFor,
|
|
166
|
+
// The computers a message sends its agents to (threadActions.mjs computerAddress).
|
|
167
|
+
computerAddress,
|
|
166
168
|
notifyBoard,
|
|
167
169
|
goalCommand,
|
|
168
170
|
stopThreadRuns,
|
|
@@ -1107,6 +1109,10 @@ export function createSwarm({
|
|
|
1107
1109
|
ok: false,
|
|
1108
1110
|
error: `name who the thread is for with @, one of: ${roomAgents.filter((name) => name !== agent && name !== "harness").join(", ")}`,
|
|
1109
1111
|
};
|
|
1112
|
+
// Where its agents work is settled before the thread exists: a choice that cannot be read starts nothing.
|
|
1113
|
+
const target = request.targetMachine ?? null;
|
|
1114
|
+
const address = computerAddress(text, agent, { target });
|
|
1115
|
+
if (!address.ok) return { ok: false, error: address.error };
|
|
1110
1116
|
const objective =
|
|
1111
1117
|
text
|
|
1112
1118
|
.split("\n")
|
|
@@ -1131,21 +1137,32 @@ export function createSwarm({
|
|
|
1131
1137
|
const [from] = store.threadsWorkedIn(agent);
|
|
1132
1138
|
if (from)
|
|
1133
1139
|
linkThreads(store.getTask(from), store.getTask(thread.id), agent);
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1140
|
+
// The first message crosses the same admission seam as every later post:
|
|
1141
|
+
// guard readings and actual caller limits must survive thread creation.
|
|
1142
|
+
const posted = goalCommand(
|
|
1143
|
+
{
|
|
1144
|
+
...request,
|
|
1145
|
+
command: "board.room.post",
|
|
1146
|
+
id: thread.id,
|
|
1147
|
+
text,
|
|
1148
|
+
ask: [...team],
|
|
1149
|
+
},
|
|
1150
|
+
agent,
|
|
1151
|
+
machine
|
|
1152
|
+
);
|
|
1153
|
+
const started = (result) => {
|
|
1154
|
+
notifyBoard(store.getTask(thread.id));
|
|
1155
|
+
return {
|
|
1156
|
+
...result,
|
|
1157
|
+
thread: summary(store.getTask(thread.id)),
|
|
1158
|
+
note:
|
|
1159
|
+
result.note ??
|
|
1160
|
+
"Read the thread with read_room and add to it with post_to_room; its tasks report whether work is running or waiting.",
|
|
1161
|
+
};
|
|
1148
1162
|
};
|
|
1163
|
+
return posted?.pending
|
|
1164
|
+
? { pending: Promise.resolve(posted.pending).then(started) }
|
|
1165
|
+
: started(posted);
|
|
1149
1166
|
}
|
|
1150
1167
|
if (agent !== "user" && command === "board.swarm.stop") {
|
|
1151
1168
|
const thread = store.getTask(String(request.id || ""));
|
|
@@ -1413,6 +1430,9 @@ export function createSwarm({
|
|
|
1413
1430
|
]);
|
|
1414
1431
|
const picked = picksIn(store, text, roomAgents);
|
|
1415
1432
|
if (picked.error) return { ok: false, error: picked.error };
|
|
1433
|
+
const target = request.targetMachine ?? null;
|
|
1434
|
+
const address = computerAddress(text, "user", { target });
|
|
1435
|
+
if (!address.ok) return { ok: false, error: address.error };
|
|
1416
1436
|
if (from) {
|
|
1417
1437
|
const agentName = String(from.agent || ""),
|
|
1418
1438
|
sessionId = String(from.sessionId || "");
|
|
@@ -1477,7 +1497,7 @@ export function createSwarm({
|
|
|
1477
1497
|
};
|
|
1478
1498
|
const hear = ({ id, first }) => {
|
|
1479
1499
|
const opened = store.getTask(id);
|
|
1480
|
-
wakeFor(id, first, "user");
|
|
1500
|
+
wakeFor(id, first, "user", undefined, { target });
|
|
1481
1501
|
if (!to) heardBy(opened, first, text);
|
|
1482
1502
|
heardPerson(opened, first);
|
|
1483
1503
|
};
|
package/lib/taskCommands.mjs
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
member,
|
|
11
11
|
nameOf,
|
|
12
12
|
resolveMember,
|
|
13
|
+
speaksThroughHarness,
|
|
13
14
|
} from "./members.mjs";
|
|
14
15
|
import { LIVE_AGENTS, sessionOfProcess } from "./live.mjs";
|
|
15
16
|
import {
|
|
@@ -22,9 +23,16 @@ import {
|
|
|
22
23
|
} from "./cards.mjs";
|
|
23
24
|
import { PICKABLE, resolvePick, setRunPick } from "./models.mjs";
|
|
24
25
|
import { onMachine, placeTask } from "./machineRoutes.mjs";
|
|
26
|
+
import { computerAddress } from "./computerAddress.mjs";
|
|
25
27
|
import { within } from "./folders.mjs";
|
|
26
28
|
import { recordClaims } from "./audit.mjs";
|
|
27
|
-
import {
|
|
29
|
+
import {
|
|
30
|
+
HOSTED_CALLER,
|
|
31
|
+
limitedCaller,
|
|
32
|
+
PROPOSERS,
|
|
33
|
+
RUN_CALLER,
|
|
34
|
+
} from "./runAuthority.mjs";
|
|
35
|
+
import { prepareScratch, threadScratch } from "./scratch.mjs";
|
|
28
36
|
|
|
29
37
|
// An agent working in a thread may bring another agent in for part of the work there, as Harness does when it names
|
|
30
38
|
// one; an agent that moves money or takes positions joins only when the person names it (members.mjs TAGGED_ONLY).
|
|
@@ -88,6 +96,12 @@ export function createTaskCommands({
|
|
|
88
96
|
files: boardFiles,
|
|
89
97
|
// Threads mirrored from another app (environments.mjs), when the person reads them here.
|
|
90
98
|
outside = () => null,
|
|
99
|
+
// The local injection guard's reading of words (localStack.mjs readByGuard).
|
|
100
|
+
readByGuard = async () => ({
|
|
101
|
+
score: null,
|
|
102
|
+
verdict: "clean",
|
|
103
|
+
unavailable: true,
|
|
104
|
+
}),
|
|
91
105
|
}) {
|
|
92
106
|
// The one open thread an agent is working in now, when the work it hands on may join it there.
|
|
93
107
|
const soleThreadOf = (agent, target, folder) => {
|
|
@@ -154,7 +168,15 @@ export function createTaskCommands({
|
|
|
154
168
|
}),
|
|
155
169
|
};
|
|
156
170
|
};
|
|
157
|
-
|
|
171
|
+
// What a worker is told of a task home lists for it, sealed like every answer between the person's computers
|
|
172
|
+
// (machineRuns.mjs): started on another agent's ask on standing permission, so it gets none of the person's secrets,
|
|
173
|
+
// and, naming no folder, run in its thread's scratch folder there.
|
|
174
|
+
const forWorker = (task) => ({
|
|
175
|
+
...task,
|
|
176
|
+
standing: Boolean(store.standingProposal(task.id)),
|
|
177
|
+
scratch: !task.run_workspace && task.kind === "task" && !!task.parent_id,
|
|
178
|
+
});
|
|
179
|
+
return (request, { agent, id, expected, machine }) => {
|
|
158
180
|
if (request.command.startsWith("board.prompt."))
|
|
159
181
|
return promptFlow
|
|
160
182
|
? promptFlow.command(request, { agent, id, machine })
|
|
@@ -436,11 +458,27 @@ export function createTaskCommands({
|
|
|
436
458
|
}
|
|
437
459
|
// Which of the person's computers the work is for: the one named, else the poster's own when it works there in a
|
|
438
460
|
// folder, else the one with the agent and the thread's repository, else the only one with the agent.
|
|
461
|
+
const recipient = String(request.targetAgent || "");
|
|
462
|
+
const address =
|
|
463
|
+
!request.thread && authority.RUNNERS.has(recipient)
|
|
464
|
+
? computerAddress({
|
|
465
|
+
text: objective,
|
|
466
|
+
computers: machines.all(),
|
|
467
|
+
target: request.targetMachine ?? null,
|
|
468
|
+
recipient,
|
|
469
|
+
agentOf: (name) => {
|
|
470
|
+
const found = resolveMember(name);
|
|
471
|
+
return found.ok ? found.id : null;
|
|
472
|
+
},
|
|
473
|
+
})
|
|
474
|
+
: null;
|
|
475
|
+
if (address && !address.ok) return { ok: false, error: address.error };
|
|
439
476
|
const placed = request.thread
|
|
440
477
|
? { ok: true, machine: null }
|
|
441
478
|
: placeTask({
|
|
442
479
|
agent: request.targetAgent ? String(request.targetAgent) : null,
|
|
443
|
-
named:
|
|
480
|
+
named:
|
|
481
|
+
address?.forAgent(recipient)?.id ?? request.targetMachine ?? null,
|
|
444
482
|
machines: machines.all(),
|
|
445
483
|
poster:
|
|
446
484
|
fromElsewhere && typeof request.posterCwd === "string"
|
|
@@ -707,13 +745,66 @@ export function createTaskCommands({
|
|
|
707
745
|
const note = task.target_agent
|
|
708
746
|
? actors.setupNote(task.target_agent)
|
|
709
747
|
: null;
|
|
710
|
-
|
|
748
|
+
const posted = (started) => ({
|
|
711
749
|
ok: true,
|
|
712
750
|
task: labelled(store.getTask(task.id)),
|
|
713
751
|
thread: thread ? store.getThread(task.id) : null,
|
|
714
|
-
...(
|
|
752
|
+
...(started ? { standing: started } : {}),
|
|
715
753
|
...(note ? { note } : {}),
|
|
716
|
-
};
|
|
754
|
+
});
|
|
755
|
+
// A task one of the person's own agents posted for a coding agent, the way that agent speaks (through Harness's
|
|
756
|
+
// server, or from a process here): when the person has not taken that agent off the coding agent's standing
|
|
757
|
+
// permission, posting it is its start, on the computer it was placed on (runAuthority.mjs admitPosted), once the
|
|
758
|
+
// guard here reads its words clean. Explicit goal children use the same admission without spending twice when
|
|
759
|
+
// the goal already authorized them; their agent-written text does not borrow the goal's authority.
|
|
760
|
+
const cameAsItSpeaks = speaksThroughHarness(agent)
|
|
761
|
+
? request[HOSTED_CALLER] === true
|
|
762
|
+
: !noGo;
|
|
763
|
+
const proposed =
|
|
764
|
+
cameAsItSpeaks &&
|
|
765
|
+
PROPOSERS.includes(agent) &&
|
|
766
|
+
task.trust === "agent" &&
|
|
767
|
+
!thread &&
|
|
768
|
+
(goalParent || !request.parentId) &&
|
|
769
|
+
!standing?.started &&
|
|
770
|
+
authority.RUNNERS.has(target)
|
|
771
|
+
? store.getTask(task.id)
|
|
772
|
+
: null;
|
|
773
|
+
if (proposed?.parent_id) {
|
|
774
|
+
const scratch =
|
|
775
|
+
!elsewhere && !proposed.run_workspace
|
|
776
|
+
? threadScratch(proposed.parent_id)
|
|
777
|
+
: null;
|
|
778
|
+
return {
|
|
779
|
+
pending: readByGuard(
|
|
780
|
+
[proposed.objective, proposed.brief].filter(Boolean).join("\n\n")
|
|
781
|
+
).then((guard) => {
|
|
782
|
+
const started = authority.admitPosted(
|
|
783
|
+
proposed,
|
|
784
|
+
{
|
|
785
|
+
proposer: agent,
|
|
786
|
+
hosted: request[HOSTED_CALLER] === true,
|
|
787
|
+
here: !noGo,
|
|
788
|
+
guard,
|
|
789
|
+
limited,
|
|
790
|
+
window: request.fromWindow === true,
|
|
791
|
+
},
|
|
792
|
+
{ scratch }
|
|
793
|
+
);
|
|
794
|
+
if (started.started && scratch) prepareScratch(proposed.parent_id);
|
|
795
|
+
else if (!started.started)
|
|
796
|
+
store.roomPost({
|
|
797
|
+
goalId: proposed.parent_id,
|
|
798
|
+
author: "harness",
|
|
799
|
+
kind: "note",
|
|
800
|
+
text: `${nameOf(target)} waits for your Start: ${started.reason}`,
|
|
801
|
+
});
|
|
802
|
+
notifyBoard(store.getTask(task.id));
|
|
803
|
+
return posted(started);
|
|
804
|
+
}),
|
|
805
|
+
};
|
|
806
|
+
}
|
|
807
|
+
outcome = posted(standing);
|
|
717
808
|
} else if (request.command === "board.list") {
|
|
718
809
|
const tasks = store
|
|
719
810
|
.listTasks({
|
|
@@ -724,10 +815,22 @@ export function createTaskCommands({
|
|
|
724
815
|
machine,
|
|
725
816
|
})
|
|
726
817
|
.map(labelled);
|
|
818
|
+
// Each result carries its receipt and the files on it this caller may open, by id: get_task with `ack` set to
|
|
819
|
+
// the receipt is what takes it off this list.
|
|
727
820
|
const finished =
|
|
728
821
|
agent === "user" || agent === "harness"
|
|
729
822
|
? []
|
|
730
|
-
: store.finishedFor(agent
|
|
823
|
+
: store.finishedFor(agent).map((result) => ({
|
|
824
|
+
...result,
|
|
825
|
+
files: store
|
|
826
|
+
.taskFiles(result.id)
|
|
827
|
+
.filter(
|
|
828
|
+
(file) =>
|
|
829
|
+
boardFiles.visibleFile(file, agent, request.hostedCaller) &&
|
|
830
|
+
(!request.hostedCaller || file.cloud)
|
|
831
|
+
)
|
|
832
|
+
.map((file) => ({ id: file.id, name: file.name })),
|
|
833
|
+
}));
|
|
731
834
|
const extra = finished.length ? { finished } : {};
|
|
732
835
|
// A session starting (nudge.mjs, the Pi and OpenCode plugins) also hears who else is in the swarm.
|
|
733
836
|
if (request.swarm) {
|
|
@@ -822,10 +925,16 @@ export function createTaskCommands({
|
|
|
822
925
|
task && !request.hostedCaller
|
|
823
926
|
? frames.get(task.kind === "goal" ? id : (task.parent_id ?? ""))
|
|
824
927
|
: null;
|
|
928
|
+
// The asker's receipt for a result it was told under finished; read in the same answer it acknowledges.
|
|
929
|
+
const ack =
|
|
930
|
+
task && typeof request.ack === "string" && request.ack
|
|
931
|
+
? store.ackResult(agent, id, request.ack)
|
|
932
|
+
: null;
|
|
825
933
|
if (task)
|
|
826
934
|
return {
|
|
827
935
|
ok: true,
|
|
828
936
|
task: labelled({ ...task, files, ...(frame ? { frame } : {}) }),
|
|
937
|
+
...(ack ? ack : {}),
|
|
829
938
|
...(request.steps === true
|
|
830
939
|
? { steps: readRunSteps(taskFiles(id).log, 200) }
|
|
831
940
|
: {}),
|
|
@@ -891,11 +1000,30 @@ export function createTaskCommands({
|
|
|
891
1000
|
ok: false,
|
|
892
1001
|
error: `standing permission is for a coding agent: ${[...authority.RUNNERS].join(", ")}`,
|
|
893
1002
|
};
|
|
1003
|
+
// The person's own agents elsewhere whose clean asks in a thread start this agent on its standing permission
|
|
1004
|
+
// (runAuthority.mjs admitProposed); its mode, folders and daily limit stay as they are. [] takes them all back.
|
|
1005
|
+
const proposers =
|
|
1006
|
+
request.command === "board.standing.set" &&
|
|
1007
|
+
Object.hasOwn(request, "proposers")
|
|
1008
|
+
? request.proposers
|
|
1009
|
+
: null;
|
|
1010
|
+
if (
|
|
1011
|
+
proposers !== null &&
|
|
1012
|
+
(!Array.isArray(proposers) ||
|
|
1013
|
+
proposers.length > PROPOSERS.length ||
|
|
1014
|
+
!proposers.every((name) => PROPOSERS.includes(name)))
|
|
1015
|
+
)
|
|
1016
|
+
return {
|
|
1017
|
+
ok: false,
|
|
1018
|
+
error: `only your own agents elsewhere can start a coding agent: ${PROPOSERS.join(", ")}`,
|
|
1019
|
+
};
|
|
894
1020
|
if (request.command === "board.standing.off")
|
|
895
1021
|
store.setStanding(target, "off");
|
|
896
1022
|
else if (request.command === "board.standing.on")
|
|
897
1023
|
store.resetStanding(target);
|
|
898
|
-
else {
|
|
1024
|
+
else if (proposers !== null && request.workspaces === undefined) {
|
|
1025
|
+
// Only who may start it changed.
|
|
1026
|
+
} else {
|
|
899
1027
|
const workspaces = Array.isArray(request.workspaces)
|
|
900
1028
|
? [...new Set(request.workspaces.map(String))]
|
|
901
1029
|
: [];
|
|
@@ -924,6 +1052,8 @@ export function createTaskCommands({
|
|
|
924
1052
|
dailyCap
|
|
925
1053
|
);
|
|
926
1054
|
}
|
|
1055
|
+
if (proposers !== null)
|
|
1056
|
+
store.setStandingProposers(target, [...new Set(proposers)]);
|
|
927
1057
|
return { ok: true, standing: authority.standingRules() };
|
|
928
1058
|
} else if (request.command === "board.agents")
|
|
929
1059
|
return {
|
|
@@ -1117,9 +1247,18 @@ export function createTaskCommands({
|
|
|
1117
1247
|
const agents = Array.isArray(request.agents)
|
|
1118
1248
|
? request.agents.map(String).filter(validAgent).slice(0, 16)
|
|
1119
1249
|
: [];
|
|
1250
|
+
// A turn another of the person's agents asked for is checked again before a worker sees it (runAuthority.mjs).
|
|
1251
|
+
const held = (task) => {
|
|
1252
|
+
const why = authority.recheckProposed(task);
|
|
1253
|
+
if (why) notifyBoard(store.getTask(task.id));
|
|
1254
|
+
return Boolean(why);
|
|
1255
|
+
};
|
|
1120
1256
|
return {
|
|
1121
1257
|
ok: true,
|
|
1122
|
-
tasks: store
|
|
1258
|
+
tasks: store
|
|
1259
|
+
.runnableTasks(agents, machine, { only: true })
|
|
1260
|
+
.filter((task) => !held(task))
|
|
1261
|
+
.map(forWorker),
|
|
1123
1262
|
};
|
|
1124
1263
|
} else if (request.command === "board.machine.take") {
|
|
1125
1264
|
const task = store.getTask(id);
|
|
@@ -1132,8 +1271,14 @@ export function createTaskCommands({
|
|
|
1132
1271
|
ok: false,
|
|
1133
1272
|
error: "that task is not for this computer's agent",
|
|
1134
1273
|
};
|
|
1274
|
+
const held = task.status === "open" && authority.recheckProposed(task);
|
|
1275
|
+
if (held) {
|
|
1276
|
+
notifyBoard(store.getTask(id));
|
|
1277
|
+
return { ok: false, error: `it waits for the person's Start: ${held}` };
|
|
1278
|
+
}
|
|
1135
1279
|
const claimed = store.claimTask(id, agent, expected, null, machine);
|
|
1136
1280
|
outcome = claimed.ok ? store.startRun(id, agent) : claimed;
|
|
1281
|
+
if (outcome.ok) outcome = { ...outcome, task: forWorker(outcome.task) };
|
|
1137
1282
|
// A thread's turn carries the thread as home's run worker would hand it over, and goes on in the session of the
|
|
1138
1283
|
// turn the person's steer stopped there (threadRuns.mjs).
|
|
1139
1284
|
if (outcome.ok && outcome.task.kind === "wake") {
|