tryharness 0.7.45 → 0.7.54
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 +239 -14
- package/assets/dsh-plugin.mjs +72 -0
- package/assets/opencode-plugin.js +4 -3
- package/cli.mjs +497 -196
- package/lib/actorRoster.mjs +28 -5
- package/lib/adapters.mjs +165 -222
- package/lib/agentRuntimeConfig.mjs +36 -0
- package/lib/agentRuntimes.mjs +570 -0
- package/lib/agentSignIn.mjs +226 -0
- package/lib/atlas.mjs +7 -2
- package/lib/audit.mjs +643 -0
- package/lib/backupSetup.mjs +141 -0
- package/lib/boardAccess.mjs +8 -1
- package/lib/boardBackup.mjs +283 -0
- package/lib/boardCommands.mjs +5 -10
- package/lib/boardFileCommands.mjs +2 -1
- package/lib/boardMirror.mjs +523 -0
- package/lib/boardProtocol.json +263 -6
- package/lib/boardTools.mjs +2 -6
- package/lib/boardWaits.mjs +102 -0
- package/lib/book.mjs +659 -0
- package/lib/bridge.mjs +26 -4
- package/lib/browserWake.mjs +60 -0
- package/lib/cards.mjs +159 -16
- package/lib/cloudBoot.mjs +124 -0
- package/lib/commands.mjs +25 -5
- package/lib/connectionTools.d.ts +13 -0
- package/lib/connectionTools.js +45 -0
- package/lib/connectorAuth.mjs +309 -0
- package/lib/connectorCatalog.json +41 -0
- package/lib/connectorCommands.mjs +121 -0
- package/lib/connectorGoogle.mjs +513 -0
- package/lib/connectors.mjs +805 -0
- package/lib/context.mjs +18 -4
- package/lib/contractGate.mjs +377 -0
- package/lib/coordinator.mjs +152 -39
- package/lib/coreModels.mjs +78 -0
- package/lib/daemon.mjs +973 -54
- package/lib/desk.mjs +239 -0
- package/lib/desktop.mjs +113 -8
- package/lib/digest.mjs +32 -0
- package/lib/directLink.mjs +283 -0
- package/lib/environments.mjs +825 -0
- package/lib/folders.mjs +4 -4
- package/lib/gitHost.mjs +174 -0
- package/lib/goalCommands.mjs +58 -14
- package/lib/hookDialects.mjs +298 -0
- package/lib/inference.mjs +263 -152
- package/lib/landed.mjs +887 -0
- package/lib/lessons.mjs +6 -0
- package/lib/lineup.mjs +324 -0
- package/lib/live.mjs +284 -13
- package/lib/localmodels.mjs +10 -0
- package/lib/machineIdentity.mjs +3 -0
- package/lib/machineRoutes.mjs +40 -2
- package/lib/machineRuns.mjs +30 -3
- package/lib/machineSeal.mjs +69 -10
- package/lib/mcp-stdio.mjs +189 -120
- package/lib/mcpRelay.mjs +119 -0
- package/lib/members.json +26 -0
- package/lib/members.mjs +33 -0
- package/lib/modelMemory.mjs +100 -0
- package/lib/models.mjs +48 -15
- package/lib/museSession.mjs +122 -0
- package/lib/nativeHost.mjs +203 -0
- package/lib/neovim.mjs +126 -0
- package/lib/network.mjs +7 -2
- package/lib/nudge.mjs +57 -18
- package/lib/onboard.mjs +430 -1
- package/lib/oneclawLocal.mjs +150 -0
- package/lib/ownMachines.mjs +828 -39
- package/lib/pairing.mjs +182 -0
- package/lib/paths.mjs +8 -0
- package/lib/personModel.mjs +89 -0
- package/lib/phones.mjs +119 -3
- package/lib/placeCommands.mjs +27 -0
- package/lib/places.mjs +337 -9
- package/lib/plans.mjs +151 -27
- package/lib/profile.mjs +152 -0
- package/lib/projects.mjs +624 -137
- package/lib/readiness.mjs +400 -0
- package/lib/record.mjs +115 -0
- package/lib/repoLinks.mjs +354 -0
- package/lib/roomChannels.mjs +641 -0
- package/lib/runBrief.mjs +32 -2
- package/lib/runRequests.mjs +157 -0
- package/lib/runWorker.mjs +37 -9
- package/lib/runner.mjs +74 -11
- package/lib/secretPatterns.json +55 -0
- package/lib/secrets.mjs +10 -27
- package/lib/seen.mjs +102 -0
- package/lib/service.mjs +11 -6
- package/lib/sessionControl.mjs +386 -96
- package/lib/sessionIndex.mjs +5 -3
- package/lib/specialties.json +74 -0
- package/lib/specialties.mjs +477 -0
- package/lib/specialtyKeys.d.ts +3 -0
- package/lib/specialtyKeys.js +58 -0
- package/lib/specialtyNotice.mjs +147 -0
- package/lib/specialtySnapshot.mjs +138 -0
- package/lib/store.mjs +829 -29
- package/lib/subagents.mjs +8 -4
- package/lib/swarm.mjs +483 -37
- package/lib/swarmMemory.mjs +947 -0
- package/lib/t3.mjs +56 -17
- package/lib/taskCommands.mjs +91 -13
- package/lib/taskRuns.mjs +68 -11
- package/lib/team.json +253 -144
- package/lib/team.mjs +538 -147
- package/lib/threadLine.mjs +116 -0
- package/lib/threadRuns.mjs +78 -12
- package/lib/threadView.mjs +66 -16
- package/lib/tokenizer.mjs +405 -0
- package/lib/ui.mjs +16 -2
- package/lib/usageTotals.mjs +148 -0
- package/lib/vault.mjs +1144 -0
- package/lib/vaultCloud.mjs +117 -0
- package/lib/vaultCommands.mjs +201 -0
- package/lib/vaultTools.d.ts +12 -0
- package/lib/vaultTools.js +42 -0
- package/lib/windowAsks.mjs +42 -0
- package/lib/workFocus.mjs +59 -0
- package/lib/workLinks.mjs +90 -0
- package/lib/worktrees.mjs +51 -13
- package/package.json +10 -5
package/lib/projects.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import path from "node:path";
|
|
|
3
3
|
import { randomUUID } from "node:crypto";
|
|
4
4
|
import { nameOf } from "./members.mjs";
|
|
5
5
|
import { secretReason } from "./secrets.mjs";
|
|
6
|
+
import { createRoomChannels, agreementHash } from "./roomChannels.mjs";
|
|
6
7
|
import {
|
|
7
8
|
SETTINGS,
|
|
8
9
|
SETTING_KEYS,
|
|
@@ -50,6 +51,7 @@ const OPEN_ONLY = new Set([
|
|
|
50
51
|
"board.project.setting",
|
|
51
52
|
"board.project.decide",
|
|
52
53
|
"board.project.note",
|
|
54
|
+
"board.project.goal",
|
|
53
55
|
]);
|
|
54
56
|
// Room posts both sides see; notes, held posts and the coordinator's bookkeeping stay on the computer that made them.
|
|
55
57
|
const SHARED_KINDS = new Set([
|
|
@@ -93,6 +95,7 @@ export function createProjects({
|
|
|
93
95
|
sentInvites = async () => [],
|
|
94
96
|
sendEvent,
|
|
95
97
|
endChannel = () => {},
|
|
98
|
+
stopRoom = () => {},
|
|
96
99
|
wake,
|
|
97
100
|
wakeRun,
|
|
98
101
|
notifyBoard = () => {},
|
|
@@ -148,11 +151,104 @@ export function createProjects({
|
|
|
148
151
|
shared_id text not null,
|
|
149
152
|
state text not null
|
|
150
153
|
);
|
|
154
|
+
create table if not exists project_receipts (
|
|
155
|
+
channel_id text not null,
|
|
156
|
+
message_id text not null,
|
|
157
|
+
primary key(channel_id, message_id)
|
|
158
|
+
);
|
|
151
159
|
`);
|
|
152
160
|
const all = (sql, ...values) =>
|
|
153
161
|
db.all(sql, values.length ? values : undefined);
|
|
154
162
|
const run = (sql, ...values) =>
|
|
155
163
|
db.run(sql, values.length ? values : undefined);
|
|
164
|
+
const outboxColumns = all("pragma table_info(project_outbox)").map(
|
|
165
|
+
(column) => column.name
|
|
166
|
+
);
|
|
167
|
+
for (const column of ["channel_id", "peer"])
|
|
168
|
+
if (!outboxColumns.includes(column))
|
|
169
|
+
db.exec(`alter table project_outbox add column ${column} text`);
|
|
170
|
+
const channels = createRoomChannels({
|
|
171
|
+
store,
|
|
172
|
+
request: relayRequest,
|
|
173
|
+
decide: decideRequest,
|
|
174
|
+
invites: listInvites,
|
|
175
|
+
sentInvites,
|
|
176
|
+
ownAgents: agents,
|
|
177
|
+
details: (id) => {
|
|
178
|
+
const p = project(id);
|
|
179
|
+
return {
|
|
180
|
+
settings: settingsOf(p),
|
|
181
|
+
agreements: items(id, "proposal")
|
|
182
|
+
.filter((entry) => stateOf(p, entry).state === "accepted")
|
|
183
|
+
.map(({ id, body }) => ({ id, body })),
|
|
184
|
+
};
|
|
185
|
+
},
|
|
186
|
+
end: endChannel,
|
|
187
|
+
log,
|
|
188
|
+
send: (id, event, peers) => send(project(id), event, peers),
|
|
189
|
+
onEvent: (id, event, peer) => receiveEvent(id, event, peer),
|
|
190
|
+
onOpen: (id, peer) => {
|
|
191
|
+
const p = project(id);
|
|
192
|
+
if (!p || p.status === "left") return;
|
|
193
|
+
const opened = makeRoom(save(id, { status: "open" }));
|
|
194
|
+
hello(opened, true, peer);
|
|
195
|
+
replay(opened, peer);
|
|
196
|
+
resend();
|
|
197
|
+
notifyBoard(store.getTask(opened.roomId));
|
|
198
|
+
},
|
|
199
|
+
onChange: (id, before, after) => {
|
|
200
|
+
const p = project(id);
|
|
201
|
+
if (!p) return;
|
|
202
|
+
const mine = after.members.find((member) => member.handle === p.me);
|
|
203
|
+
if (["left", "removed"].includes(mine?.status)) {
|
|
204
|
+
save(id, { status: "left" });
|
|
205
|
+
store.meta(`project-ended:${id}`, "you_left");
|
|
206
|
+
if (p.roomId) stopRoom(p.roomId);
|
|
207
|
+
run(
|
|
208
|
+
"delete from project_outbox where project_id = ? and delivered_at is null",
|
|
209
|
+
id
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
if (before) {
|
|
213
|
+
for (const member of after.members) {
|
|
214
|
+
const previous = before.members.find(
|
|
215
|
+
(entry) => entry.handle === member.handle
|
|
216
|
+
);
|
|
217
|
+
if (previous?.status === member.status) continue;
|
|
218
|
+
note(
|
|
219
|
+
p,
|
|
220
|
+
`${member.handle} ${member.status === "joined" ? "joined the room" : member.status === "invited" ? "was invited" : member.status === "removed" ? "was removed from the room" : "left the room"}.`
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
if (p.roomId) notifyBoard(store.getTask(p.roomId));
|
|
225
|
+
},
|
|
226
|
+
});
|
|
227
|
+
const groupOf = (p) => channels.read(p.id);
|
|
228
|
+
const peopleOf = (p) =>
|
|
229
|
+
groupOf(p)
|
|
230
|
+
?.members.filter((member) => member.status === "joined")
|
|
231
|
+
.map((member) => member.handle) ?? [p.me, p.partner];
|
|
232
|
+
const peersOf = (p) => peopleOf(p).filter((handle) => handle !== p.me);
|
|
233
|
+
const ownAgents = (p) => (groupOf(p) ? channels.agents(p.id) : agents());
|
|
234
|
+
const remoteAgents = (p) => {
|
|
235
|
+
const group = groupOf(p);
|
|
236
|
+
return group
|
|
237
|
+
? peersOf(p).flatMap((peer) =>
|
|
238
|
+
(group.rosters[peer] ?? []).map((id) => ({
|
|
239
|
+
id,
|
|
240
|
+
handle: peer,
|
|
241
|
+
address: `${peer}/${id}`,
|
|
242
|
+
}))
|
|
243
|
+
)
|
|
244
|
+
: p.roster.map((entry) => ({
|
|
245
|
+
...entry,
|
|
246
|
+
handle: p.partner,
|
|
247
|
+
address: `${p.partner}/${entry.id}`,
|
|
248
|
+
}));
|
|
249
|
+
};
|
|
250
|
+
const isPeer = (p, identity) =>
|
|
251
|
+
peersOf(p).includes(String(identity).split("/")[0]);
|
|
156
252
|
|
|
157
253
|
// ---- the project rows ----
|
|
158
254
|
|
|
@@ -242,7 +338,13 @@ export function createProjects({
|
|
|
242
338
|
const keep = (entry) => {
|
|
243
339
|
const current = item(entry.id);
|
|
244
340
|
if (current && current.rev >= entry.rev) return false;
|
|
245
|
-
if (
|
|
341
|
+
if (
|
|
342
|
+
current &&
|
|
343
|
+
(current.side !== entry.side ||
|
|
344
|
+
current.projectId !== entry.projectId ||
|
|
345
|
+
current.kind !== entry.kind)
|
|
346
|
+
)
|
|
347
|
+
return false;
|
|
246
348
|
run(
|
|
247
349
|
"insert into project_items(id, project_id, kind, side, rev, body, at, updated_at) values(?, ?, ?, ?, ?, ?, ?, ?) on conflict(id) do update set rev = excluded.rev, body = excluded.body, updated_at = excluded.updated_at",
|
|
248
350
|
entry.id,
|
|
@@ -279,21 +381,34 @@ export function createProjects({
|
|
|
279
381
|
|
|
280
382
|
// ---- the channel between the two computers ----
|
|
281
383
|
|
|
282
|
-
const send = (p, body) => {
|
|
384
|
+
const send = (p, body, peers = null) => {
|
|
385
|
+
if (!p) return;
|
|
283
386
|
if (!["open", "invited", "joining"].includes(p.status)) return;
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
387
|
+
const routes = groupOf(p)
|
|
388
|
+
? peers
|
|
389
|
+
? channels
|
|
390
|
+
.routes(p.id)
|
|
391
|
+
.filter(
|
|
392
|
+
(route) => peers.includes(route.peer) && route.state === "open"
|
|
393
|
+
)
|
|
394
|
+
: channels.recipients(p.id)
|
|
395
|
+
: [{ id: p.id, peer: p.partner }];
|
|
396
|
+
for (const route of routes) {
|
|
397
|
+
const seq = project(p.id).nextSeq;
|
|
398
|
+
run("update projects set next_seq = ? where id = ?", seq + 1, p.id);
|
|
399
|
+
const messageId = `p:${p.id.slice(0, 8)}:${p.me}:${seq}`;
|
|
400
|
+
run(
|
|
401
|
+
"insert into project_outbox(message_id, project_id, channel_id, peer, seq, body, created_at) values(?, ?, ?, ?, ?, ?, ?)",
|
|
402
|
+
messageId,
|
|
403
|
+
p.id,
|
|
404
|
+
route.id,
|
|
405
|
+
route.peer,
|
|
406
|
+
seq,
|
|
407
|
+
JSON.stringify(body),
|
|
408
|
+
now()
|
|
409
|
+
);
|
|
410
|
+
if (project(p.id).status === "open") deliver(messageId);
|
|
411
|
+
}
|
|
297
412
|
};
|
|
298
413
|
const deliver = (messageId) => {
|
|
299
414
|
const row = all(
|
|
@@ -303,8 +418,8 @@ export function createProjects({
|
|
|
303
418
|
const p = row && project(row.project_id);
|
|
304
419
|
if (!row || p?.status !== "open") return;
|
|
305
420
|
sendEvent({
|
|
306
|
-
projectId: p.id,
|
|
307
|
-
to: `${p.partner}/person`,
|
|
421
|
+
projectId: row.channel_id ?? p.id,
|
|
422
|
+
to: `${row.peer ?? p.partner}/person`,
|
|
308
423
|
messageId,
|
|
309
424
|
seq: Number(row.seq),
|
|
310
425
|
body: json(row.body, {}),
|
|
@@ -347,14 +462,15 @@ export function createProjects({
|
|
|
347
462
|
};
|
|
348
463
|
// The other side's agents a post names, by their address: "@igor/codex".
|
|
349
464
|
const partnerMentions = (p, text) =>
|
|
350
|
-
|
|
351
|
-
.map((entry) =>
|
|
352
|
-
.
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
)
|
|
465
|
+
[
|
|
466
|
+
...remoteAgents(p).map((entry) => entry.address),
|
|
467
|
+
...peersOf(p).map((peer) => `${peer}/person`),
|
|
468
|
+
].filter((address) =>
|
|
469
|
+
new RegExp(
|
|
470
|
+
`(^|\\s)@${address.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&")}\\b`,
|
|
471
|
+
"i"
|
|
472
|
+
).test(String(text))
|
|
473
|
+
);
|
|
358
474
|
|
|
359
475
|
// ---- settings ----
|
|
360
476
|
|
|
@@ -382,17 +498,31 @@ export function createProjects({
|
|
|
382
498
|
yes: answer.body.yes,
|
|
383
499
|
at: answer.updatedAt,
|
|
384
500
|
}));
|
|
385
|
-
const stateOf = (p, proposal) =>
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
);
|
|
501
|
+
const stateOf = (p, proposal) => {
|
|
502
|
+
const body = proposal.body;
|
|
503
|
+
const sharedDecision =
|
|
504
|
+
body.type === "setting" || body.type === "decision" || body.decision;
|
|
505
|
+
const group = groupOf(p);
|
|
506
|
+
const needs = group && sharedDecision ? peopleOf(p) : body.needs;
|
|
507
|
+
const implicit = group
|
|
508
|
+
? Object.entries(group.consents ?? {})
|
|
509
|
+
.filter(([, consent]) => consent[proposal.id] === agreementHash(body))
|
|
510
|
+
.map(([side]) => ({ side, yes: true, at: proposal.at }))
|
|
511
|
+
: [];
|
|
512
|
+
return proposalState({ ...body, needs, at: proposal.at }, [
|
|
513
|
+
...implicit,
|
|
514
|
+
...answersTo(p, proposal.id),
|
|
515
|
+
]);
|
|
516
|
+
};
|
|
390
517
|
|
|
391
518
|
// ---- the room ----
|
|
392
519
|
|
|
393
520
|
const roomOf = (p) => (p.roomId ? store.getTask(p.roomId) : null);
|
|
394
521
|
const makeRoom = (p) => {
|
|
395
522
|
if (p.roomId && store.getTask(p.roomId)) return p;
|
|
523
|
+
const workspace =
|
|
524
|
+
p.folder ?? path.join(worktreeRoot, p.id.slice(0, 8), "workspace");
|
|
525
|
+
if (!p.folder) fs.mkdirSync(workspace, { recursive: true });
|
|
396
526
|
const room = store.createGoal({
|
|
397
527
|
objective: p.title,
|
|
398
528
|
brief: "",
|
|
@@ -400,7 +530,7 @@ export function createProjects({
|
|
|
400
530
|
provenance: { trust: "user", chain: [] },
|
|
401
531
|
team: ["harness"],
|
|
402
532
|
facilitator: "harness",
|
|
403
|
-
workspace
|
|
533
|
+
workspace,
|
|
404
534
|
maxPosts,
|
|
405
535
|
maxWakes,
|
|
406
536
|
});
|
|
@@ -427,7 +557,10 @@ export function createProjects({
|
|
|
427
557
|
return;
|
|
428
558
|
const secret = secretReason(post.text);
|
|
429
559
|
const waits =
|
|
430
|
-
secret ||
|
|
560
|
+
secret ||
|
|
561
|
+
(post.author !== "user" &&
|
|
562
|
+
!saying &&
|
|
563
|
+
(!settingsOf(p).talk || !ownAgents(p).includes(post.author)));
|
|
431
564
|
run(
|
|
432
565
|
"insert into project_posts(post_id, project_id, shared_id, state) values(?, ?, ?, ?)",
|
|
433
566
|
post.id,
|
|
@@ -445,22 +578,26 @@ export function createProjects({
|
|
|
445
578
|
if (waits) return;
|
|
446
579
|
sharePost(p, post);
|
|
447
580
|
};
|
|
448
|
-
const sharePost = (p, post) =>
|
|
449
|
-
send(
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
...
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
581
|
+
const sharePost = (p, post, peers = null) =>
|
|
582
|
+
send(
|
|
583
|
+
p,
|
|
584
|
+
{
|
|
585
|
+
type: "post",
|
|
586
|
+
...clashOf(post),
|
|
587
|
+
id: post.id,
|
|
588
|
+
author: shared(p, post.author),
|
|
589
|
+
kind: post.kind,
|
|
590
|
+
text: post.text,
|
|
591
|
+
mentions: [
|
|
592
|
+
...new Set([
|
|
593
|
+
...(post.mentions ?? []).map((name) => shared(p, name)),
|
|
594
|
+
...partnerMentions(p, post.text),
|
|
595
|
+
]),
|
|
596
|
+
],
|
|
597
|
+
at: post.created_at ?? now(),
|
|
598
|
+
},
|
|
599
|
+
peers
|
|
600
|
+
);
|
|
464
601
|
|
|
465
602
|
// A post that names a clash carries the work it is about, so the other side's agents in it may talk it out.
|
|
466
603
|
const clashOf = (post) => {
|
|
@@ -479,7 +616,9 @@ export function createProjects({
|
|
|
479
616
|
new RegExp(`(^|\\s)@${escape(p.me)}/([a-z0-9][a-z0-9._-]*)`, "gi"),
|
|
480
617
|
`$1@${MINE}$2`
|
|
481
618
|
);
|
|
482
|
-
|
|
619
|
+
const senderAgents =
|
|
620
|
+
groupOf(p)?.rosters[p.partner]?.map((id) => ({ id })) ?? p.roster;
|
|
621
|
+
for (const entry of senderAgents)
|
|
483
622
|
words = words.replace(
|
|
484
623
|
new RegExp(`(^|\\s)@${escape(entry.id)}(?![\\w/-])`, "gi"),
|
|
485
624
|
`$1@${p.partner}/${entry.id}`
|
|
@@ -489,8 +628,34 @@ export function createProjects({
|
|
|
489
628
|
|
|
490
629
|
// ---- what arrives from the other computer ----
|
|
491
630
|
|
|
492
|
-
|
|
493
|
-
|
|
631
|
+
// Relay delivery can overlap or repeat after a lost acknowledgement. Record
|
|
632
|
+
// the transport receipt so a repeated hello cannot replay history again.
|
|
633
|
+
const receive = (channelId, event, messageId = null) => {
|
|
634
|
+
if (
|
|
635
|
+
messageId &&
|
|
636
|
+
all(
|
|
637
|
+
"select 1 from project_receipts where channel_id = ? and message_id = ?",
|
|
638
|
+
channelId,
|
|
639
|
+
messageId
|
|
640
|
+
).length
|
|
641
|
+
)
|
|
642
|
+
return { ok: true, duplicate: true };
|
|
643
|
+
const result = receiveEvent(channelId, event);
|
|
644
|
+
if (messageId && result.ok)
|
|
645
|
+
run(
|
|
646
|
+
"insert or ignore into project_receipts(channel_id, message_id) values(?, ?)",
|
|
647
|
+
channelId,
|
|
648
|
+
messageId
|
|
649
|
+
);
|
|
650
|
+
return result;
|
|
651
|
+
};
|
|
652
|
+
const receiveEvent = (projectId, event, source = null) => {
|
|
653
|
+
if (!source) {
|
|
654
|
+
const handled = channels.receive(projectId, event);
|
|
655
|
+
if (handled) return handled;
|
|
656
|
+
}
|
|
657
|
+
const stored = project(projectId);
|
|
658
|
+
const p = stored && source ? { ...stored, partner: source } : stored;
|
|
494
659
|
if (!p) return { ok: false, error: "no project on this thread" };
|
|
495
660
|
if (!event || typeof event !== "object")
|
|
496
661
|
return { ok: false, error: "an empty project event" };
|
|
@@ -501,15 +666,17 @@ export function createProjects({
|
|
|
501
666
|
: { ok: false, error: "the project is not open on this computer yet" };
|
|
502
667
|
if (event.type === "hello") {
|
|
503
668
|
// The other side is in: everything this side has made goes to it, and its agents are known here.
|
|
504
|
-
if (Array.isArray(event.agents))
|
|
669
|
+
if (!groupOf(p) && Array.isArray(event.agents))
|
|
670
|
+
setRoster(p, event.agents);
|
|
505
671
|
if (event.reply !== false) {
|
|
506
|
-
hello(p, false);
|
|
507
|
-
replay(p);
|
|
672
|
+
hello(p, false, source);
|
|
673
|
+
replay(p, source);
|
|
508
674
|
}
|
|
509
675
|
return { ok: true };
|
|
510
676
|
}
|
|
511
677
|
if (event.type === "roster") {
|
|
512
|
-
if (Array.isArray(event.agents))
|
|
678
|
+
if (!groupOf(p) && Array.isArray(event.agents))
|
|
679
|
+
setRoster(p, event.agents);
|
|
513
680
|
return { ok: true };
|
|
514
681
|
}
|
|
515
682
|
if (event.type === "left") {
|
|
@@ -575,6 +742,7 @@ export function createProjects({
|
|
|
575
742
|
(name) =>
|
|
576
743
|
!name.includes("/") &&
|
|
577
744
|
name !== "user" &&
|
|
745
|
+
ownAgents(p).includes(name) &&
|
|
578
746
|
(name !== "harness" || settingsOf(p).start)
|
|
579
747
|
);
|
|
580
748
|
if (mentions.includes("harness") && !named.includes("harness"))
|
|
@@ -593,6 +761,9 @@ export function createProjects({
|
|
|
593
761
|
)
|
|
594
762
|
);
|
|
595
763
|
for (const agent of settling) store.meta(settleKey(p, agent), "1");
|
|
764
|
+
const joining = named.filter((agent) => !room.goal.team.includes(agent));
|
|
765
|
+
if (joining.length)
|
|
766
|
+
store.setGoalTeam(room.id, [...room.goal.team, ...joining]);
|
|
596
767
|
if (named.length && room.status === "open")
|
|
597
768
|
wake(room.id, post, String(event.author), named, {
|
|
598
769
|
go: settingsOf(p).start || inClash(p, named) || settling.length > 0,
|
|
@@ -610,6 +781,16 @@ export function createProjects({
|
|
|
610
781
|
if (!["work", "proposal", "answer", "setting", "note"].includes(entry.kind))
|
|
611
782
|
return { ok: true };
|
|
612
783
|
const before = settingsOf(p);
|
|
784
|
+
if (
|
|
785
|
+
groupOf(p) &&
|
|
786
|
+
entry.kind === "setting" &&
|
|
787
|
+
(!validSetting(entry.body?.key, entry.body?.value) ||
|
|
788
|
+
widens(entry.body.key, before[entry.body.key], entry.body.value))
|
|
789
|
+
)
|
|
790
|
+
return {
|
|
791
|
+
ok: false,
|
|
792
|
+
error: "Giving agents more reach requires everyone's agreement.",
|
|
793
|
+
};
|
|
613
794
|
const previous = item(entry.id);
|
|
614
795
|
const kept = keep({
|
|
615
796
|
...entry,
|
|
@@ -625,22 +806,27 @@ export function createProjects({
|
|
|
625
806
|
if (fresh.roomId) notifyBoard(store.getTask(fresh.roomId));
|
|
626
807
|
return { ok: true };
|
|
627
808
|
};
|
|
628
|
-
const hello = (p, reply = true) =>
|
|
629
|
-
send(
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
809
|
+
const hello = (p, reply = true, peer = null) =>
|
|
810
|
+
send(
|
|
811
|
+
p,
|
|
812
|
+
{
|
|
813
|
+
type: "hello",
|
|
814
|
+
agents: ownAgents(p).map((id) => ({ id })),
|
|
815
|
+
agreements: groupOf(p)?.consents?.[p.me] ?? {},
|
|
816
|
+
reply,
|
|
817
|
+
},
|
|
818
|
+
peer ? [peer] : null
|
|
819
|
+
);
|
|
820
|
+
const replay = (p, peer = null) => {
|
|
635
821
|
for (const entry of items(p.id).filter((own) => own.side === p.me))
|
|
636
|
-
send(p, { type: "item", item: entry });
|
|
822
|
+
send(p, { type: "item", item: entry }, peer ? [peer] : null);
|
|
637
823
|
if (!p.roomId) return;
|
|
638
824
|
for (const post of store.roomPosts(p.roomId, 0, 500)) {
|
|
639
825
|
const sent = all(
|
|
640
826
|
"select state from project_posts where post_id = ?",
|
|
641
827
|
post.id
|
|
642
828
|
)[0];
|
|
643
|
-
if (sent?.state === "sent") sharePost(p, post);
|
|
829
|
+
if (sent?.state === "sent") sharePost(p, post, peer ? [peer] : null);
|
|
644
830
|
}
|
|
645
831
|
};
|
|
646
832
|
|
|
@@ -696,7 +882,7 @@ export function createProjects({
|
|
|
696
882
|
* one side's work needs that side's person (owner, October 20: agents settle it first, a person OKs it).
|
|
697
883
|
*/
|
|
698
884
|
const needsFor = (p, { decision, changes }) => {
|
|
699
|
-
if (decision) return
|
|
885
|
+
if (decision) return peopleOf(p);
|
|
700
886
|
const owners = new Set(
|
|
701
887
|
(changes ?? []).map((id) => item(id)?.side).filter(Boolean)
|
|
702
888
|
);
|
|
@@ -736,14 +922,19 @@ export function createProjects({
|
|
|
736
922
|
const describe = (p, work) => ({
|
|
737
923
|
id: work.id,
|
|
738
924
|
who: display(p, `${work.side}/${work.body.agent}`),
|
|
739
|
-
side: work.side === p.me ? "this person" :
|
|
925
|
+
side: work.side === p.me ? "this person" : work.side,
|
|
740
926
|
summary: work.body.summary,
|
|
741
927
|
...(work.body.touches?.length ? { touches: work.body.touches } : {}),
|
|
742
928
|
...(work.body.files?.length ? { files: work.body.files } : {}),
|
|
743
929
|
status: work.body.status,
|
|
744
930
|
});
|
|
745
|
-
|
|
746
|
-
|
|
931
|
+
// An invitation explicitly carries the current agreements. Keep that accepted
|
|
932
|
+
// baseline available even when an original author's computer is unavailable.
|
|
933
|
+
// It is attributed to the invitation, not forged as an original author's row.
|
|
934
|
+
const joinedAgreements = (p) => groupOf(p)?.agreements ?? [];
|
|
935
|
+
const decisionsOf = (p) => {
|
|
936
|
+
const proposals = items(p.id, "proposal");
|
|
937
|
+
const originals = proposals
|
|
747
938
|
.filter(
|
|
748
939
|
(proposal) =>
|
|
749
940
|
(proposal.body.type === "decision" || proposal.body.decision) &&
|
|
@@ -755,6 +946,34 @@ export function createProjects({
|
|
|
755
946
|
by: proposal.body.by,
|
|
756
947
|
at: stateOf(p, proposal).at,
|
|
757
948
|
}));
|
|
949
|
+
const baseline = joinedAgreements(p)
|
|
950
|
+
.filter(
|
|
951
|
+
(entry) =>
|
|
952
|
+
!proposals.some((proposal) => proposal.id === entry.id) &&
|
|
953
|
+
(entry.body.type === "decision" || entry.body.decision)
|
|
954
|
+
)
|
|
955
|
+
.map((entry) => ({
|
|
956
|
+
id: entry.id,
|
|
957
|
+
text: entry.body.decision || entry.body.text,
|
|
958
|
+
by: `Accepted on joining from ${groupOf(p).owner}`,
|
|
959
|
+
at: p.createdAt,
|
|
960
|
+
}));
|
|
961
|
+
return [...baseline, ...originals];
|
|
962
|
+
};
|
|
963
|
+
const goalOf = (p) => {
|
|
964
|
+
const agreed = items(p.id, "proposal")
|
|
965
|
+
.filter(
|
|
966
|
+
(entry) => entry.body.goal && stateOf(p, entry).state === "accepted"
|
|
967
|
+
)
|
|
968
|
+
.at(-1);
|
|
969
|
+
const baseline = joinedAgreements(p)
|
|
970
|
+
.filter((entry) => entry.body.goal)
|
|
971
|
+
.at(-1);
|
|
972
|
+
return (
|
|
973
|
+
agreed?.body.goal ??
|
|
974
|
+
baseline?.body.goal ?? { statement: p.title, criteria: [] }
|
|
975
|
+
);
|
|
976
|
+
};
|
|
758
977
|
|
|
759
978
|
/**
|
|
760
979
|
* Compares one piece of planned work with what both sides agreed and with every other open piece, and keeps the answer
|
|
@@ -850,11 +1069,18 @@ export function createProjects({
|
|
|
850
1069
|
*/
|
|
851
1070
|
const gate = ({ task, agent, reason, asker, go, mode, words }, start) => {
|
|
852
1071
|
const p = projectOfRoom(task.id);
|
|
853
|
-
if (!p
|
|
1072
|
+
if (!p) return start(mode);
|
|
1073
|
+
if (p.status !== "open")
|
|
1074
|
+
return { ok: false, error: "This shared room is not open." };
|
|
1075
|
+
if (!ownAgents(p).includes(agent))
|
|
1076
|
+
return {
|
|
1077
|
+
ok: false,
|
|
1078
|
+
error: "This agent has not been selected for the shared room.",
|
|
1079
|
+
};
|
|
854
1080
|
const settings = settingsOf(p);
|
|
855
1081
|
// The other side asking: it waits for the person unless they both let agents start such work. Talking out a clash
|
|
856
1082
|
// the other side found is read-only, and never waits.
|
|
857
|
-
const fromPartner =
|
|
1083
|
+
const fromPartner = isPeer(p, asker);
|
|
858
1084
|
if (fromPartner && store.meta(settleKey(p, agent))) {
|
|
859
1085
|
store.meta(settleKey(p, agent), "");
|
|
860
1086
|
return start("review");
|
|
@@ -868,7 +1094,20 @@ export function createProjects({
|
|
|
868
1094
|
`${display(p, asker)} asked ${nameOf(agent)} for work. It waits for your Start: agents here don't start work the other side asks for on their own.`
|
|
869
1095
|
);
|
|
870
1096
|
}
|
|
871
|
-
const begin = () =>
|
|
1097
|
+
const begin = () => {
|
|
1098
|
+
const fresh = project(p.id);
|
|
1099
|
+
if (
|
|
1100
|
+
fresh?.status !== "open" ||
|
|
1101
|
+
!ownAgents(fresh).includes(agent) ||
|
|
1102
|
+
(fromPartner && !isPeer(fresh, asker))
|
|
1103
|
+
)
|
|
1104
|
+
return {
|
|
1105
|
+
ok: false,
|
|
1106
|
+
error:
|
|
1107
|
+
"The room or this task's participation changed before it could start.",
|
|
1108
|
+
};
|
|
1109
|
+
return start(needsStart ? "wait" : mode);
|
|
1110
|
+
};
|
|
872
1111
|
let current = openWork(p, agent);
|
|
873
1112
|
if (current?.body.status === "clash") {
|
|
874
1113
|
write(p, "work", { waiting: { reason, asker, go } }, current.id);
|
|
@@ -1057,9 +1296,11 @@ export function createProjects({
|
|
|
1057
1296
|
};
|
|
1058
1297
|
|
|
1059
1298
|
/** Where an agent's run in a project's room works: its own branch for its open piece of work. */
|
|
1060
|
-
const folderFor = (task, agent) => {
|
|
1299
|
+
const folderFor = (task, agent, { review = false } = {}) => {
|
|
1061
1300
|
const p = projectOfRoom(task.id);
|
|
1062
|
-
if (!p
|
|
1301
|
+
if (!p) return null;
|
|
1302
|
+
if (!p.repo.first) return task.goal.workspace;
|
|
1303
|
+
if (review || !p.folder) return null;
|
|
1063
1304
|
const work = openWork(p, agent);
|
|
1064
1305
|
if (!work) return null;
|
|
1065
1306
|
const where = laneOf(p, work);
|
|
@@ -1079,7 +1320,7 @@ export function createProjects({
|
|
|
1079
1320
|
/** A finished turn's changes, committed on the agent's own branch; pushed when both people let agents push. */
|
|
1080
1321
|
const committed = (task) => {
|
|
1081
1322
|
const p = projectOfRoom(task.parent_id);
|
|
1082
|
-
if (!p) return undefined;
|
|
1323
|
+
if (!p || !p.folder) return undefined;
|
|
1083
1324
|
const work = openWork(p, task.target_agent);
|
|
1084
1325
|
// A run with no piece of work of its own (a review) worked in the thread's copy, which commits as any thread's does.
|
|
1085
1326
|
if (!work) return undefined;
|
|
@@ -1095,6 +1336,7 @@ export function createProjects({
|
|
|
1095
1336
|
return sha;
|
|
1096
1337
|
};
|
|
1097
1338
|
const push = async (p, work) => {
|
|
1339
|
+
if (!p.folder) return { ok: false, error: "This room has no repository." };
|
|
1098
1340
|
const pushed = await pushLane(laneOf(p, work), work.body.branch);
|
|
1099
1341
|
if (pushed.ok)
|
|
1100
1342
|
write(project(p.id), "work", { pushed: work.body.head ?? null }, work.id);
|
|
@@ -1106,6 +1348,7 @@ export function createProjects({
|
|
|
1106
1348
|
return pushed;
|
|
1107
1349
|
};
|
|
1108
1350
|
const pullRequest = async (p, work) => {
|
|
1351
|
+
if (!p.folder) return { ok: false, error: "This room has no repository." };
|
|
1109
1352
|
if (work.body.pr?.number) return { ok: true };
|
|
1110
1353
|
if (work.body.pushed !== work.body.head) {
|
|
1111
1354
|
const pushed = await push(p, work);
|
|
@@ -1167,7 +1410,73 @@ export function createProjects({
|
|
|
1167
1410
|
return effectiveSettings(settings, []);
|
|
1168
1411
|
};
|
|
1169
1412
|
|
|
1170
|
-
const create = async ({
|
|
1413
|
+
const create = async ({
|
|
1414
|
+
folder,
|
|
1415
|
+
partner,
|
|
1416
|
+
partners,
|
|
1417
|
+
title,
|
|
1418
|
+
settings,
|
|
1419
|
+
selectedAgents,
|
|
1420
|
+
}) => {
|
|
1421
|
+
if (Array.isArray(partners) || !folder) {
|
|
1422
|
+
const me = await myHandle();
|
|
1423
|
+
if (!me)
|
|
1424
|
+
throw new Error("Claim your swarm's name first (Swarms, Your card).");
|
|
1425
|
+
const chosen = Array.isArray(partners) ? partners : [partner];
|
|
1426
|
+
const handles = [
|
|
1427
|
+
...new Set(
|
|
1428
|
+
chosen.map((handle) =>
|
|
1429
|
+
String(handle ?? "")
|
|
1430
|
+
.trim()
|
|
1431
|
+
.toLowerCase()
|
|
1432
|
+
.replace(/^@/, "")
|
|
1433
|
+
)
|
|
1434
|
+
),
|
|
1435
|
+
];
|
|
1436
|
+
if (!handles.length || handles.some((handle) => !HANDLE.test(handle)))
|
|
1437
|
+
throw new Error("Write each person's swarm name, separated by commas.");
|
|
1438
|
+
if (handles.includes(me))
|
|
1439
|
+
throw new Error("That's your own swarm's name.");
|
|
1440
|
+
const anchored = folder
|
|
1441
|
+
? anchorOf(String(folder))
|
|
1442
|
+
: { ok: true, repo: {}, folder: null };
|
|
1443
|
+
if (!anchored.ok) throw new Error(anchored.error);
|
|
1444
|
+
const name = String(
|
|
1445
|
+
title || (anchored.repo.name ? path.basename(anchored.repo.name) : "")
|
|
1446
|
+
)
|
|
1447
|
+
.trim()
|
|
1448
|
+
.slice(0, 120);
|
|
1449
|
+
if (!name)
|
|
1450
|
+
throw new Error(
|
|
1451
|
+
"Give the room a name that says what you want to do together."
|
|
1452
|
+
);
|
|
1453
|
+
const group = channels.init({
|
|
1454
|
+
me,
|
|
1455
|
+
title: name,
|
|
1456
|
+
repo: anchored.repo,
|
|
1457
|
+
settings: chosenSettings(settings),
|
|
1458
|
+
agents: selectedAgents,
|
|
1459
|
+
});
|
|
1460
|
+
const p = makeRoom(
|
|
1461
|
+
insertProject({
|
|
1462
|
+
id: group.id,
|
|
1463
|
+
title: name,
|
|
1464
|
+
me,
|
|
1465
|
+
partner: handles[0],
|
|
1466
|
+
role: "inviter",
|
|
1467
|
+
status: "open",
|
|
1468
|
+
repo: anchored.repo,
|
|
1469
|
+
folder: anchored.folder,
|
|
1470
|
+
agreed: group.settings,
|
|
1471
|
+
})
|
|
1472
|
+
);
|
|
1473
|
+
await channels.invite(p.id, handles);
|
|
1474
|
+
note(
|
|
1475
|
+
p,
|
|
1476
|
+
`Invited ${handles.join(", ")}. Shared room history is visible to people who join; the room owner can invite others.`
|
|
1477
|
+
);
|
|
1478
|
+
return project(p.id);
|
|
1479
|
+
}
|
|
1171
1480
|
const handle = String(partner || "")
|
|
1172
1481
|
.toLowerCase()
|
|
1173
1482
|
.replace(/^@/, "")
|
|
@@ -1224,46 +1533,61 @@ export function createProjects({
|
|
|
1224
1533
|
return p;
|
|
1225
1534
|
};
|
|
1226
1535
|
|
|
1227
|
-
const join = async ({ id, folder, clone }) => {
|
|
1536
|
+
const join = async ({ id, folder, clone, selectedAgents }) => {
|
|
1228
1537
|
const invite = (await listInvites()).find((entry) => entry.id === id);
|
|
1229
1538
|
if (!invite) throw new Error("That invitation is no longer waiting.");
|
|
1230
1539
|
const offer = invite.project;
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1540
|
+
const groupId = offer.v === 2 ? offer.id : id;
|
|
1541
|
+
let checkout =
|
|
1542
|
+
folder && offer.repo?.first
|
|
1543
|
+
? findCheckout([String(folder)], offer.repo.first)
|
|
1544
|
+
: null;
|
|
1234
1545
|
if (folder && !checkout)
|
|
1235
1546
|
throw new Error(`That folder doesn't hold ${offer.repo.name}.`);
|
|
1236
|
-
|
|
1237
|
-
|
|
1547
|
+
if (offer.repo?.first)
|
|
1548
|
+
checkout ??= findCheckout(knownFolders(), offer.repo.first);
|
|
1549
|
+
if (offer.repo?.first && !checkout && clone) {
|
|
1238
1550
|
const cloned = await cloneInto(offer.repo.remote, offer.repo.name);
|
|
1239
1551
|
if (!cloned.ok) throw new Error(cloned.error);
|
|
1240
1552
|
checkout = findCheckout([cloned.folder], offer.repo.first);
|
|
1241
1553
|
}
|
|
1242
|
-
if (!checkout)
|
|
1554
|
+
if (offer.repo?.first && !checkout)
|
|
1243
1555
|
return {
|
|
1244
1556
|
ok: false,
|
|
1245
1557
|
code: "no_folder",
|
|
1246
1558
|
error: `${offer.repo.name} isn't on this computer yet.`,
|
|
1247
1559
|
};
|
|
1248
|
-
if (
|
|
1560
|
+
if (
|
|
1561
|
+
offer.v === 2 &&
|
|
1562
|
+
(!groupOf({ id: groupId }) || project(groupId)?.status === "left")
|
|
1563
|
+
)
|
|
1564
|
+
channels.join(invite, await myHandle(), selectedAgents);
|
|
1565
|
+
if (!project(groupId))
|
|
1249
1566
|
insertProject({
|
|
1250
|
-
id,
|
|
1567
|
+
id: groupId,
|
|
1251
1568
|
title: offer.title,
|
|
1252
1569
|
me: offer.to,
|
|
1253
1570
|
partner: offer.from,
|
|
1254
1571
|
role: "invitee",
|
|
1255
1572
|
status: "joining",
|
|
1256
|
-
repo: offer.repo,
|
|
1573
|
+
repo: offer.repo ?? {},
|
|
1257
1574
|
folder: checkout,
|
|
1258
1575
|
agreed: offer.settings,
|
|
1259
1576
|
});
|
|
1260
|
-
else
|
|
1577
|
+
else
|
|
1578
|
+
save(groupId, {
|
|
1579
|
+
folder: checkout,
|
|
1580
|
+
repo: offer.repo ?? {},
|
|
1581
|
+
agreed: offer.settings,
|
|
1582
|
+
status: "joining",
|
|
1583
|
+
});
|
|
1261
1584
|
await decideRequest(id, "accept");
|
|
1262
|
-
return { ok: true, project: view(project(
|
|
1585
|
+
return { ok: true, project: view(project(groupId)) };
|
|
1263
1586
|
};
|
|
1264
1587
|
|
|
1265
1588
|
/** The person thread under a project opened on this computer: the project is open, and the other side hears so. */
|
|
1266
1589
|
const channelOpened = (taskId) => {
|
|
1590
|
+
if (channels.opened(taskId)) return;
|
|
1267
1591
|
const p = project(taskId);
|
|
1268
1592
|
if (!p || !["invited", "joining"].includes(p.status)) return;
|
|
1269
1593
|
const opened = makeRoom(save(p.id, { status: "open" }));
|
|
@@ -1285,6 +1609,7 @@ export function createProjects({
|
|
|
1285
1609
|
|
|
1286
1610
|
/** The thread under a project ended from the other side: they left. */
|
|
1287
1611
|
const channelEnded = (taskId) => {
|
|
1612
|
+
if (channels.closed(taskId)) return;
|
|
1288
1613
|
const p = project(taskId);
|
|
1289
1614
|
if (!p || p.status !== "open") return;
|
|
1290
1615
|
save(p.id, { status: "left" });
|
|
@@ -1297,6 +1622,10 @@ export function createProjects({
|
|
|
1297
1622
|
};
|
|
1298
1623
|
|
|
1299
1624
|
const leave = (p) => {
|
|
1625
|
+
if (groupOf(p)) {
|
|
1626
|
+
channels.leave(p.id);
|
|
1627
|
+
return;
|
|
1628
|
+
}
|
|
1300
1629
|
if (p.status === "open") send(p, { type: "left", at: now() });
|
|
1301
1630
|
save(p.id, { status: "left" });
|
|
1302
1631
|
store.meta(`project-ended:${p.id}`, "you_left");
|
|
@@ -1330,7 +1659,7 @@ export function createProjects({
|
|
|
1330
1659
|
type: "setting",
|
|
1331
1660
|
key,
|
|
1332
1661
|
value,
|
|
1333
|
-
needs:
|
|
1662
|
+
needs: peopleOf(p),
|
|
1334
1663
|
text: settingLine(key, value),
|
|
1335
1664
|
},
|
|
1336
1665
|
"user"
|
|
@@ -1358,6 +1687,8 @@ export function createProjects({
|
|
|
1358
1687
|
const proposal = item(proposalId);
|
|
1359
1688
|
if (!proposal || proposal.side !== p.me)
|
|
1360
1689
|
throw new Error("Only a proposal from your side can be withdrawn here.");
|
|
1690
|
+
if (stateOf(p, proposal).state === "accepted")
|
|
1691
|
+
throw new Error("An agreed decision needs a new proposal to change it.");
|
|
1361
1692
|
write(p, "proposal", { withdrawn: true }, proposal.id);
|
|
1362
1693
|
return { ok: true };
|
|
1363
1694
|
};
|
|
@@ -1488,7 +1819,7 @@ export function createProjects({
|
|
|
1488
1819
|
|
|
1489
1820
|
const workView = (p, work) => {
|
|
1490
1821
|
const mine = work.side === p.me;
|
|
1491
|
-
const where = mine ? laneOf(p, work) : null;
|
|
1822
|
+
const where = mine && p.folder ? laneOf(p, work) : null;
|
|
1492
1823
|
return {
|
|
1493
1824
|
id: work.id,
|
|
1494
1825
|
side: work.side,
|
|
@@ -1545,6 +1876,7 @@ export function createProjects({
|
|
|
1545
1876
|
};
|
|
1546
1877
|
};
|
|
1547
1878
|
const view = (p) => {
|
|
1879
|
+
const group = groupOf(p);
|
|
1548
1880
|
const settings = settingsOf(p);
|
|
1549
1881
|
const proposals = items(p.id, "proposal").map((proposal) =>
|
|
1550
1882
|
proposalView(p, proposal)
|
|
@@ -1566,30 +1898,65 @@ export function createProjects({
|
|
|
1566
1898
|
title: p.title,
|
|
1567
1899
|
status: p.status,
|
|
1568
1900
|
role: p.role,
|
|
1901
|
+
kind: p.repo.first ? "project" : "room",
|
|
1902
|
+
goal: goalOf(p),
|
|
1903
|
+
...(group
|
|
1904
|
+
? {
|
|
1905
|
+
owner: group.owner,
|
|
1906
|
+
history: group.history,
|
|
1907
|
+
availableAgents: agents().map((id) => ({ id, name: nameOf(id) })),
|
|
1908
|
+
connectionErrors: group.errors,
|
|
1909
|
+
}
|
|
1910
|
+
: {}),
|
|
1569
1911
|
// Why it ended, as the list says it (declined, expired, they_left, you_left), or null.
|
|
1570
1912
|
ended: store.meta(`project-ended:${p.id}`) || null,
|
|
1571
1913
|
me: p.me,
|
|
1572
|
-
partner: p.partner,
|
|
1914
|
+
partner: group ? peersOf(p).join(", ") || p.partner : p.partner,
|
|
1573
1915
|
repo: {
|
|
1916
|
+
first: "",
|
|
1917
|
+
name: "",
|
|
1918
|
+
remote: "",
|
|
1919
|
+
canon: "",
|
|
1920
|
+
head: null,
|
|
1574
1921
|
...p.repo,
|
|
1575
1922
|
short: p.repo.head?.slice(0, 7) ?? null,
|
|
1576
1923
|
folder: p.folder,
|
|
1577
1924
|
},
|
|
1578
|
-
people:
|
|
1579
|
-
{
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1925
|
+
people: group
|
|
1926
|
+
? group.members.map((member) => ({
|
|
1927
|
+
...member,
|
|
1928
|
+
you: member.handle === p.me,
|
|
1929
|
+
agents: (member.handle === p.me
|
|
1930
|
+
? ownAgents(p)
|
|
1931
|
+
: (group.rosters[member.handle] ?? [])
|
|
1932
|
+
).map((id) => ({
|
|
1933
|
+
id: member.handle === p.me ? id : `${member.handle}/${id}`,
|
|
1934
|
+
name: nameOf(id),
|
|
1935
|
+
})),
|
|
1936
|
+
connected:
|
|
1937
|
+
member.handle === p.me ||
|
|
1938
|
+
channels
|
|
1939
|
+
.routes(p.id)
|
|
1940
|
+
.some(
|
|
1941
|
+
(route) =>
|
|
1942
|
+
route.peer === member.handle && route.state === "open"
|
|
1943
|
+
),
|
|
1944
|
+
}))
|
|
1945
|
+
: [
|
|
1946
|
+
{
|
|
1947
|
+
handle: p.me,
|
|
1948
|
+
you: true,
|
|
1949
|
+
agents: agents().map((id) => ({ id, name: nameOf(id) })),
|
|
1950
|
+
},
|
|
1951
|
+
{
|
|
1952
|
+
handle: p.partner,
|
|
1953
|
+
you: false,
|
|
1954
|
+
agents: p.roster.map((entry) => ({
|
|
1955
|
+
id: `${p.partner}/${entry.id}`,
|
|
1956
|
+
name: nameOf(entry.id),
|
|
1957
|
+
})),
|
|
1958
|
+
},
|
|
1959
|
+
],
|
|
1593
1960
|
work,
|
|
1594
1961
|
decisions: decisionsOf(p).map((entry) => ({
|
|
1595
1962
|
...entry,
|
|
@@ -1602,7 +1969,13 @@ export function createProjects({
|
|
|
1602
1969
|
by: display(p, entry.body.by ?? `${entry.side}/person`),
|
|
1603
1970
|
at: entry.at,
|
|
1604
1971
|
})),
|
|
1605
|
-
settings: SETTING_KEYS.
|
|
1972
|
+
settings: SETTING_KEYS.filter(
|
|
1973
|
+
(key) =>
|
|
1974
|
+
p.repo.first ||
|
|
1975
|
+
!["push", "pullRequests", "mergeChecks", "mergeDecisions"].includes(
|
|
1976
|
+
key
|
|
1977
|
+
)
|
|
1978
|
+
).map((key) => {
|
|
1606
1979
|
const pending = items(p.id, "proposal").find(
|
|
1607
1980
|
(proposal) =>
|
|
1608
1981
|
proposal.body.type === "setting" &&
|
|
@@ -1636,8 +2009,17 @@ export function createProjects({
|
|
|
1636
2009
|
roomId: p.roomId,
|
|
1637
2010
|
title: p.title,
|
|
1638
2011
|
status: p.status,
|
|
1639
|
-
partner:
|
|
1640
|
-
|
|
2012
|
+
partner: full.partner,
|
|
2013
|
+
kind: full.kind,
|
|
2014
|
+
invitationIds: groupOf(p)
|
|
2015
|
+
? channels.routes(p.id).map((route) => route.id)
|
|
2016
|
+
: [p.id],
|
|
2017
|
+
people: full.people.map(({ handle, status, you }) => ({
|
|
2018
|
+
handle,
|
|
2019
|
+
status,
|
|
2020
|
+
you,
|
|
2021
|
+
})),
|
|
2022
|
+
repo: { name: p.repo.name ?? "" },
|
|
1641
2023
|
// Why a project ended: declined, expired (the invitation ran out), they_left or you_left; null while it hasn't.
|
|
1642
2024
|
ended: store.meta(`project-ended:${p.id}`) || null,
|
|
1643
2025
|
working: full.work.filter((entry) => OPEN_WORK.includes(entry.status))
|
|
@@ -1659,16 +2041,23 @@ export function createProjects({
|
|
|
1659
2041
|
OPEN_WORK.includes(entry.body.status) || entry.body.status === "review"
|
|
1660
2042
|
);
|
|
1661
2043
|
const own = openWork(p, agent);
|
|
1662
|
-
const theirs = p.
|
|
2044
|
+
const theirs = remoteAgents(p).map((entry) => `@${entry.address}`);
|
|
1663
2045
|
const decisions = decisionsOf(p);
|
|
1664
2046
|
const notes = items(p.id, "note").slice(-10);
|
|
1665
2047
|
return [
|
|
1666
|
-
`This
|
|
1667
|
-
|
|
2048
|
+
`This is a shared room with ${peersOf(p).join(", ") || "people still joining"}${p.repo.first ? `, on ${p.repo.name} (canon branch ${p.repo.canon}${p.repo.head ? ` at ${p.repo.head.slice(0, 7)}` : ""})` : ""}. Posts here reach the room's members${theirs.length ? `. Their agents: ${theirs.join(", ")} (ask one by its full name)` : ""}. Each person's private conversations, history and credentials stay theirs. Share only the material intended for this room.`,
|
|
2049
|
+
`Shared goal: ${goalOf(p).statement}${
|
|
2050
|
+
goalOf(p).criteria.length
|
|
2051
|
+
? `\nDone when:\n${goalOf(p)
|
|
2052
|
+
.criteria.map((criterion) => `- ${criterion}`)
|
|
2053
|
+
.join("\n")}`
|
|
2054
|
+
: ""
|
|
2055
|
+
}`,
|
|
2056
|
+
own && p.repo.first
|
|
1668
2057
|
? `Your piece of work: "${oneLine(own.body.summary, 200)}" on your own branch ${own.body.branch}, made from canon. Your changes there are committed for you after each turn. Never push to canon or to another agent's branch.`
|
|
1669
2058
|
: "",
|
|
1670
2059
|
decisions.length
|
|
1671
|
-
? `What the
|
|
2060
|
+
? `What the room's people decided (keep to it; changing it needs their agreement):\n${decisions.map((entry, n) => `${n + 1}. ${oneLine(entry.text, 300)}`).join("\n")}`
|
|
1672
2061
|
: "",
|
|
1673
2062
|
work.length
|
|
1674
2063
|
? `Who is building what:\n${work.map((entry) => `- ${display(p, `${entry.side}/${entry.body.agent}`)} (work ${entry.id}): "${oneLine(entry.body.summary, 160)}" [${entry.body.status}]${entry.body.files?.length ? ` changing ${entry.body.files.slice(0, 8).join(", ")}` : ""}`).join("\n")}`
|
|
@@ -1681,10 +2070,12 @@ export function createProjects({
|
|
|
1681
2070
|
"- Before you change code for something new, say what you plan with plan_work (summary, and the files or interfaces it touches). It is checked against the decisions and the other side's work; if it clashes, it waits.",
|
|
1682
2071
|
"- When your work is ready, call plan_work with done.",
|
|
1683
2072
|
"- To settle a clash or change a decision, agree with the other agent here, then call propose. A person OKs it before it counts.",
|
|
1684
|
-
"-
|
|
1685
|
-
|
|
1686
|
-
? "-
|
|
1687
|
-
:
|
|
2073
|
+
"- Add what the other side's agents should know too with swarm_memory (remember); it is shared.",
|
|
2074
|
+
!p.repo.first
|
|
2075
|
+
? "- Work here can be research, writing or planning. Report what you produced and what evidence supports it; a claim of success alone is not completion."
|
|
2076
|
+
: settings.push
|
|
2077
|
+
? "- Your branch is pushed to the shared remote for you."
|
|
2078
|
+
: "- Your branch stays on this computer until the person pushes it.",
|
|
1688
2079
|
].join("\n"),
|
|
1689
2080
|
]
|
|
1690
2081
|
.filter(Boolean)
|
|
@@ -1704,10 +2095,9 @@ export function createProjects({
|
|
|
1704
2095
|
// ---- keeping up with the remote ----
|
|
1705
2096
|
|
|
1706
2097
|
const refresh = async () => {
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
const head = await fetchCanon(p.folder, p.repo.canon);
|
|
2098
|
+
await channels.sync();
|
|
2099
|
+
for (const p of projects().filter((entry) => entry.status === "open")) {
|
|
2100
|
+
const head = p.folder ? await fetchCanon(p.folder, p.repo.canon) : null;
|
|
1711
2101
|
if (head && head !== p.repo.head)
|
|
1712
2102
|
save(p.id, { repo: { ...p.repo, head } });
|
|
1713
2103
|
for (const work of items(p.id, "work").filter(
|
|
@@ -1740,10 +2130,10 @@ export function createProjects({
|
|
|
1740
2130
|
}
|
|
1741
2131
|
}
|
|
1742
2132
|
// A roster that changed (an agent set up here since) goes across.
|
|
1743
|
-
const roster = JSON.stringify(
|
|
2133
|
+
const roster = JSON.stringify(ownAgents(p));
|
|
1744
2134
|
if (store.meta(`project-roster:${p.id}`) !== roster) {
|
|
1745
2135
|
store.meta(`project-roster:${p.id}`, roster);
|
|
1746
|
-
send(p, { type: "roster", agents:
|
|
2136
|
+
send(p, { type: "roster", agents: ownAgents(p).map((id) => ({ id })) });
|
|
1747
2137
|
}
|
|
1748
2138
|
}
|
|
1749
2139
|
};
|
|
@@ -1793,6 +2183,7 @@ export function createProjects({
|
|
|
1793
2183
|
if (name === "board.project.list")
|
|
1794
2184
|
return answeredWith(
|
|
1795
2185
|
noteAnswers()
|
|
2186
|
+
.then(() => channels.sync())
|
|
1796
2187
|
.then(listInvites)
|
|
1797
2188
|
.then((invites) => ({
|
|
1798
2189
|
projects: projects()
|
|
@@ -1801,20 +2192,54 @@ export function createProjects({
|
|
|
1801
2192
|
invites: invites
|
|
1802
2193
|
.filter(
|
|
1803
2194
|
(invite) =>
|
|
1804
|
-
|
|
2195
|
+
invite.project.purpose !== "link" &&
|
|
2196
|
+
(!project(
|
|
2197
|
+
invite.project.v === 2 ? invite.project.id : invite.id
|
|
2198
|
+
) ||
|
|
2199
|
+
project(
|
|
2200
|
+
invite.project.v === 2 ? invite.project.id : invite.id
|
|
2201
|
+
).status === "joining" ||
|
|
2202
|
+
project(
|
|
2203
|
+
invite.project.v === 2 ? invite.project.id : invite.id
|
|
2204
|
+
)?.status === "left")
|
|
1805
2205
|
)
|
|
1806
2206
|
.map((invite) => ({
|
|
1807
2207
|
id: invite.id,
|
|
1808
2208
|
// Joined here and waiting for the other computer to hear: shown as joining, not counted as waiting on you.
|
|
1809
|
-
joining:
|
|
2209
|
+
joining:
|
|
2210
|
+
project(
|
|
2211
|
+
invite.project.v === 2 ? invite.project.id : invite.id
|
|
2212
|
+
)?.status === "joining",
|
|
1810
2213
|
title: invite.project.title,
|
|
1811
2214
|
from: invite.project.from,
|
|
2215
|
+
kind: invite.project.repo?.first ? "project" : "room",
|
|
2216
|
+
people: invite.project.members,
|
|
2217
|
+
history: invite.project.history,
|
|
2218
|
+
agreements: invite.project.agreements,
|
|
2219
|
+
availableAgents:
|
|
2220
|
+
invite.project.v === 2
|
|
2221
|
+
? agents().map((id) => ({
|
|
2222
|
+
id,
|
|
2223
|
+
name: nameOf(id),
|
|
2224
|
+
}))
|
|
2225
|
+
: undefined,
|
|
1812
2226
|
repo: {
|
|
1813
|
-
name: invite.project.repo
|
|
1814
|
-
remote: invite.project.repo
|
|
2227
|
+
name: invite.project.repo?.name ?? "",
|
|
2228
|
+
remote: invite.project.repo?.remote ?? "",
|
|
1815
2229
|
},
|
|
1816
|
-
here:
|
|
1817
|
-
|
|
2230
|
+
here: invite.project.repo?.first
|
|
2231
|
+
? findCheckout(knownFolders(), invite.project.repo.first)
|
|
2232
|
+
: null,
|
|
2233
|
+
settings: SETTING_KEYS.filter(
|
|
2234
|
+
(key) =>
|
|
2235
|
+
invite.project.repo?.first ||
|
|
2236
|
+
![
|
|
2237
|
+
"push",
|
|
2238
|
+
"pullRequests",
|
|
2239
|
+
"mergeChecks",
|
|
2240
|
+
"mergeDecisions",
|
|
2241
|
+
].includes(key)
|
|
2242
|
+
).map((key) => ({
|
|
1818
2243
|
key,
|
|
1819
2244
|
label: SETTINGS[key].label,
|
|
1820
2245
|
value:
|
|
@@ -1828,6 +2253,7 @@ export function createProjects({
|
|
|
1828
2253
|
return {
|
|
1829
2254
|
ok: true,
|
|
1830
2255
|
repos: repos(),
|
|
2256
|
+
availableAgents: agents().map((id) => ({ id, name: nameOf(id) })),
|
|
1831
2257
|
// What agents may do in a new project, as it starts, for the person to change before they invite.
|
|
1832
2258
|
settings: SETTING_KEYS.map((key) => ({
|
|
1833
2259
|
key,
|
|
@@ -1844,6 +2270,7 @@ export function createProjects({
|
|
|
1844
2270
|
id: String(request.id || ""),
|
|
1845
2271
|
folder: request.folder,
|
|
1846
2272
|
clone: request.clone === true,
|
|
2273
|
+
selectedAgents: request.selectedAgents,
|
|
1847
2274
|
}).catch((error) => ({ ok: false, error: error.message })),
|
|
1848
2275
|
};
|
|
1849
2276
|
if (name === "board.project.decline")
|
|
@@ -1863,6 +2290,55 @@ export function createProjects({
|
|
|
1863
2290
|
};
|
|
1864
2291
|
try {
|
|
1865
2292
|
switch (name) {
|
|
2293
|
+
case "board.project.retry":
|
|
2294
|
+
return answeredWith(
|
|
2295
|
+
channels
|
|
2296
|
+
.retry(p.id, String(request.handle || ""))
|
|
2297
|
+
.then(() => ({ project: view(project(p.id)) }))
|
|
2298
|
+
);
|
|
2299
|
+
case "board.project.goal": {
|
|
2300
|
+
const statement = String(request.statement || "")
|
|
2301
|
+
.trim()
|
|
2302
|
+
.slice(0, 4000);
|
|
2303
|
+
const criteria = [
|
|
2304
|
+
...new Set(
|
|
2305
|
+
(Array.isArray(request.criteria) ? request.criteria : [])
|
|
2306
|
+
.map(String)
|
|
2307
|
+
.map((text) => text.trim().slice(0, 500))
|
|
2308
|
+
.filter(Boolean)
|
|
2309
|
+
),
|
|
2310
|
+
].slice(0, 12);
|
|
2311
|
+
if (!statement || !criteria.length)
|
|
2312
|
+
throw new Error(
|
|
2313
|
+
"Write the goal and at least one check that shows it is reached."
|
|
2314
|
+
);
|
|
2315
|
+
const text = `Shared goal: ${statement}\nDone when:\n${criteria.map((criterion) => `- ${criterion}`).join("\n")}`;
|
|
2316
|
+
propose(
|
|
2317
|
+
p,
|
|
2318
|
+
{
|
|
2319
|
+
type: "decision",
|
|
2320
|
+
text,
|
|
2321
|
+
goal: { statement, criteria },
|
|
2322
|
+
needs: peopleOf(p),
|
|
2323
|
+
},
|
|
2324
|
+
"user"
|
|
2325
|
+
);
|
|
2326
|
+
return { ok: true };
|
|
2327
|
+
}
|
|
2328
|
+
case "board.project.invite":
|
|
2329
|
+
return answeredWith(
|
|
2330
|
+
channels
|
|
2331
|
+
.invite(p.id, request.partners ?? [request.partner])
|
|
2332
|
+
.then(() => ({ project: view(project(p.id)) }))
|
|
2333
|
+
);
|
|
2334
|
+
case "board.project.remove":
|
|
2335
|
+
channels.remove(p.id, String(request.handle || ""));
|
|
2336
|
+
return { ok: true, project: view(project(p.id)) };
|
|
2337
|
+
case "board.project.agents": {
|
|
2338
|
+
channels.setAgents(p.id, request.agents);
|
|
2339
|
+
hello(p);
|
|
2340
|
+
return { ok: true, project: view(project(p.id)) };
|
|
2341
|
+
}
|
|
1866
2342
|
case "board.project.read":
|
|
1867
2343
|
return { ok: true, project: view(p) };
|
|
1868
2344
|
case "board.project.answer":
|
|
@@ -1878,11 +2354,7 @@ export function createProjects({
|
|
|
1878
2354
|
case "board.project.decide": {
|
|
1879
2355
|
const text = String(request.text || "").trim();
|
|
1880
2356
|
if (!text) return { ok: false, error: "write what you decide" };
|
|
1881
|
-
propose(
|
|
1882
|
-
p,
|
|
1883
|
-
{ type: "decision", text, needs: [p.me, p.partner] },
|
|
1884
|
-
"user"
|
|
1885
|
-
);
|
|
2357
|
+
propose(p, { type: "decision", text, needs: peopleOf(p) }, "user");
|
|
1886
2358
|
return { ok: true, project: view(project(p.id)) };
|
|
1887
2359
|
}
|
|
1888
2360
|
case "board.project.note": {
|
|
@@ -1957,6 +2429,11 @@ export function createProjects({
|
|
|
1957
2429
|
const p = projectFor(request);
|
|
1958
2430
|
if (!p || p.status !== "open")
|
|
1959
2431
|
return { ok: false, error: "this thread is not an open shared project" };
|
|
2432
|
+
if (!ownAgents(p).includes(agent))
|
|
2433
|
+
return {
|
|
2434
|
+
ok: false,
|
|
2435
|
+
error: "This agent has not been selected for the shared room.",
|
|
2436
|
+
};
|
|
1960
2437
|
const room = roomOf(p);
|
|
1961
2438
|
if (name === "board.project.read")
|
|
1962
2439
|
return { ok: true, record: brief(room, agent) };
|
|
@@ -2038,15 +2515,25 @@ export function createProjects({
|
|
|
2038
2515
|
/** What a thread list says of a project's room: the project and who it is shared with. */
|
|
2039
2516
|
roomInfo: (goalId) => {
|
|
2040
2517
|
const p = projectOfRoom(goalId);
|
|
2041
|
-
return p
|
|
2518
|
+
return p
|
|
2519
|
+
? {
|
|
2520
|
+
id: p.id,
|
|
2521
|
+
partner: peersOf(p).join(", ") || p.partner,
|
|
2522
|
+
status: p.status,
|
|
2523
|
+
}
|
|
2524
|
+
: null;
|
|
2042
2525
|
},
|
|
2043
2526
|
/** Whether a relay thread is a project's channel, which Swarms does not list as a conversation. */
|
|
2044
|
-
isChannel: (threadId) =>
|
|
2527
|
+
isChannel: (threadId) =>
|
|
2528
|
+
Boolean(project(threadId) || channels.knowsChannel(threadId)),
|
|
2045
2529
|
// A post from the other side: its own swarm sorts it; this side's coordinator does not take a round on it.
|
|
2046
2530
|
fromPartner: (goalId, post) => {
|
|
2047
2531
|
const p = projectOfRoom(goalId);
|
|
2048
|
-
return Boolean(p) &&
|
|
2532
|
+
return Boolean(p) && isPeer(p, post.author);
|
|
2533
|
+
},
|
|
2534
|
+
stop: () => {
|
|
2535
|
+
clearInterval(timer);
|
|
2536
|
+
channels.stop();
|
|
2049
2537
|
},
|
|
2050
|
-
stop: () => clearInterval(timer),
|
|
2051
2538
|
};
|
|
2052
2539
|
}
|