tryharness 0.7.77 → 0.7.81
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/boardProtocol.json +4 -0
- package/lib/capabilityCheck.mjs +9 -1
- package/lib/coordinator.mjs +156 -14
- package/lib/daemon.mjs +43 -3
- package/lib/dispatcher.mjs +24 -4
- package/lib/goalCommands.mjs +40 -11
- package/lib/goals.mjs +9 -3
- package/lib/kanban.mjs +217 -48
- package/lib/machineRoutes.mjs +9 -0
- package/lib/machineRuns.mjs +9 -1
- package/lib/manager.mjs +94 -2
- package/lib/mcp-stdio.mjs +3 -3
- package/lib/network.mjs +19 -0
- package/lib/ownMachines.mjs +96 -43
- package/lib/peopleBoard.mjs +131 -0
- package/lib/phones.mjs +1 -0
- package/lib/projectBoard.mjs +219 -0
- package/lib/projectPieces.mjs +26 -0
- package/lib/projects.mjs +19 -0
- package/lib/runAuthority.mjs +23 -9
- package/lib/runBrief.mjs +20 -14
- package/lib/store.mjs +6 -3
- package/lib/swarm.mjs +185 -62
- package/lib/taskCommands.mjs +25 -15
- package/lib/taskRooms.mjs +2 -4
- package/lib/threadActions.mjs +23 -8
- package/lib/threadAuthority.mjs +28 -10
- package/lib/threadRuns.mjs +279 -86
- package/lib/threadView.mjs +1 -1
- package/npm-shrinkwrap.json +14 -14
- package/package.json +4 -4
- package/release.json +33 -31
package/lib/network.mjs
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
// read). A sealed request's subject is opened here, never at Harness. Only the person ("user") calls
|
|
5
5
|
// these; another agent works a thread through board.thread.* on the task it holds.
|
|
6
6
|
|
|
7
|
+
import { peopleBoard } from "./peopleBoard.mjs";
|
|
8
|
+
|
|
7
9
|
const SEEN = (id) => `relay_seen:${id}`;
|
|
8
10
|
const AUTO_SEND_DEFAULT = "relay_auto_send_default";
|
|
9
11
|
const DECISIONS = new Set(["accept", "decline", "block"]);
|
|
@@ -236,6 +238,23 @@ export function createNetwork({
|
|
|
236
238
|
switch (request.command) {
|
|
237
239
|
case "board.relay.list":
|
|
238
240
|
return answered(conversations());
|
|
241
|
+
// The board of every ask between the person's swarm and one other person's (peopleBoard.mjs).
|
|
242
|
+
case "board.relay.board": {
|
|
243
|
+
const handle = String(request.handle || "")
|
|
244
|
+
.toLowerCase()
|
|
245
|
+
.replace(/^@/, "");
|
|
246
|
+
if (!handle) return { ok: false, error: "say whose board (handle)" };
|
|
247
|
+
return answered(
|
|
248
|
+
conversations().then((list) => ({
|
|
249
|
+
ok: true,
|
|
250
|
+
...peopleBoard(list.items, {
|
|
251
|
+
handle,
|
|
252
|
+
messagesOf: (taskId) => store.threadMessages(taskId),
|
|
253
|
+
taskOf: (taskId) => store.getTask(taskId),
|
|
254
|
+
}),
|
|
255
|
+
}))
|
|
256
|
+
);
|
|
257
|
+
}
|
|
239
258
|
// The server's half of Swarms (card, search, contacts, blocks): what the dashboard asks Harness directly.
|
|
240
259
|
case "board.relay.network": {
|
|
241
260
|
// Only the operation's own fields go to Harness, which refuses any other (a browser's call adds fromWindow and
|
package/lib/ownMachines.mjs
CHANGED
|
@@ -45,6 +45,7 @@ import { WINDOW_TOOLS } from "./windowAsks.mjs";
|
|
|
45
45
|
import { createCallSessions } from "./callSessions.mjs";
|
|
46
46
|
import { VIEW_COMMAND, VIEW_DROP_COMMAND } from "./liveViews.mjs";
|
|
47
47
|
import { computerAddress } from "./computerAddress.mjs";
|
|
48
|
+
import { RUN_CALLER } from "./runAuthority.mjs";
|
|
48
49
|
|
|
49
50
|
export { FROM_MACHINE };
|
|
50
51
|
|
|
@@ -182,6 +183,12 @@ export function createOwnMachines({
|
|
|
182
183
|
answerLink = null,
|
|
183
184
|
// Home asking whether this computer can do a piece of work (capabilityCheck.mjs), only over its sealed ask.
|
|
184
185
|
answerCapability = null,
|
|
186
|
+
// This computer's folders for a composer on home whose message names this computer (folders.mjs): the folders worked
|
|
187
|
+
// in here (`{ places: true }`) or the folders in a typed path (`{ browse }`).
|
|
188
|
+
ownFolders = async () => ({
|
|
189
|
+
ok: false,
|
|
190
|
+
error: "this computer cannot list its folders",
|
|
191
|
+
}),
|
|
185
192
|
// A cloud computer's own SSH keys (cloudSsh.mjs allow): { key, by } in, null on a computer that takes none.
|
|
186
193
|
ownSsh = null,
|
|
187
194
|
// This computer updating itself to a published release (daemon.mjs): `tryharness upgrade <spec>`, which takes only a
|
|
@@ -1298,6 +1305,18 @@ export function createOwnMachines({
|
|
|
1298
1305
|
}
|
|
1299
1306
|
};
|
|
1300
1307
|
|
|
1308
|
+
// The run here that made a call, as home reads it (runAuthority.mjs callerRun): its id, for counting hand-offs, and
|
|
1309
|
+
// how it was held in, so what it asks for is held in on home too. Work another person asked for asks as a held-in
|
|
1310
|
+
// run: home has no record of where such a run may reach (runAuthority.mjs privateReach). Never a caller's own word.
|
|
1311
|
+
const sealedRun = (request) => {
|
|
1312
|
+
const run = request[RUN_CALLER];
|
|
1313
|
+
if (!run) return undefined;
|
|
1314
|
+
return {
|
|
1315
|
+
id: run.id,
|
|
1316
|
+
review: run.review === true,
|
|
1317
|
+
restricted: run.restricted === true || run.forAnotherPerson === true,
|
|
1318
|
+
};
|
|
1319
|
+
};
|
|
1301
1320
|
const stripLocal = (request) => {
|
|
1302
1321
|
const {
|
|
1303
1322
|
agent,
|
|
@@ -1453,11 +1472,12 @@ export function createOwnMachines({
|
|
|
1453
1472
|
const pinned = pinnedHome();
|
|
1454
1473
|
if (!pinned) return homeListed() ? notJoined() : offline();
|
|
1455
1474
|
// A task started here gets its id here, so it is the same task whether home takes it now or once it is back.
|
|
1456
|
-
const call = stripLocal(
|
|
1457
|
-
request.command === "board.post" && request.id == null
|
|
1475
|
+
const call = stripLocal({
|
|
1476
|
+
...(request.command === "board.post" && request.id == null
|
|
1458
1477
|
? { ...request, id: randomUUID() }
|
|
1459
|
-
: request
|
|
1460
|
-
|
|
1478
|
+
: request),
|
|
1479
|
+
fromRun: sealedRun(request),
|
|
1480
|
+
});
|
|
1461
1481
|
if (call.command === "board.file.add" && call.path != null)
|
|
1462
1482
|
return (await attach(pinned, call)) ?? offline();
|
|
1463
1483
|
if (call.command === "board.file.get" && call.offset === undefined)
|
|
@@ -2102,24 +2122,26 @@ export function createOwnMachines({
|
|
|
2102
2122
|
? await answerCapability(call.capability)
|
|
2103
2123
|
: call.inventory === true
|
|
2104
2124
|
? { ok: true, folders: folders({ fresh: true }) }
|
|
2105
|
-
: call.
|
|
2106
|
-
? await
|
|
2107
|
-
: call.
|
|
2108
|
-
? await
|
|
2109
|
-
: call.
|
|
2110
|
-
? await
|
|
2111
|
-
: call.
|
|
2112
|
-
? await
|
|
2113
|
-
: call.
|
|
2114
|
-
?
|
|
2115
|
-
: call.
|
|
2116
|
-
?
|
|
2117
|
-
:
|
|
2118
|
-
?
|
|
2119
|
-
:
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2125
|
+
: call.folders
|
|
2126
|
+
? await ownFolders(call.folders)
|
|
2127
|
+
: call.home === true
|
|
2128
|
+
? await becomeHome(call.computers)
|
|
2129
|
+
: call.link && answerLink
|
|
2130
|
+
? await answerLink(pinned.machine_id, call.link)
|
|
2131
|
+
: call.models
|
|
2132
|
+
? await ownModels(call.models)
|
|
2133
|
+
: call.live
|
|
2134
|
+
? await ownLive(call.live)
|
|
2135
|
+
: call.ssh
|
|
2136
|
+
? ownSshAllow(call.ssh)
|
|
2137
|
+
: call.update
|
|
2138
|
+
? ownUpdateChecked(call.update)
|
|
2139
|
+
: WINDOW_TOOLS.has(call.tool)
|
|
2140
|
+
? await askOwnWindows(call)
|
|
2141
|
+
: {
|
|
2142
|
+
ok: false,
|
|
2143
|
+
error: `home cannot ask this computer's windows for ${call.tool}`,
|
|
2144
|
+
};
|
|
2123
2145
|
return {
|
|
2124
2146
|
envelope: await sealAskAnswer(
|
|
2125
2147
|
key,
|
|
@@ -2851,45 +2873,74 @@ export function createOwnMachines({
|
|
|
2851
2873
|
);
|
|
2852
2874
|
return sibling ? { machine: sibling.id, folder: null } : null;
|
|
2853
2875
|
}
|
|
2876
|
+
const withAgent = siblings.filter(
|
|
2877
|
+
(each) => each.agents.includes(agent) && store.ownMachine(each.id)
|
|
2878
|
+
);
|
|
2879
|
+
const checkout = withAgent
|
|
2880
|
+
.map((each) => ({
|
|
2881
|
+
machine: each.id,
|
|
2882
|
+
folder: checkoutOn(each.id, workspace),
|
|
2883
|
+
}))
|
|
2884
|
+
.find((place) => place.folder);
|
|
2885
|
+
if (checkout) return checkout;
|
|
2886
|
+
// One not yet saying which folders it has may hold a checkout: the turn waits for it, as before.
|
|
2887
|
+
if (withAgent.some((each) => inventoryOf(each.id).state !== "ready"))
|
|
2888
|
+
return null;
|
|
2889
|
+
// No computer with the agent has a checkout of the thread's folder: one takes the turn in its own scratch folder,
|
|
2890
|
+
// an online one first.
|
|
2891
|
+
const scratch =
|
|
2892
|
+
withAgent.find((each) => each.connected) ?? withAgent[0] ?? null;
|
|
2893
|
+
return scratch ? { machine: scratch.id, folder: null } : null;
|
|
2894
|
+
};
|
|
2895
|
+
|
|
2896
|
+
/** On home: that computer's checkout of the repository a folder here holds, from its inventory; null when none. */
|
|
2897
|
+
const checkoutOn = (id, workspace) => {
|
|
2898
|
+
if (inventoryOf(id).state !== "ready") return null;
|
|
2854
2899
|
const repository = repositoryOf(workspace);
|
|
2855
2900
|
if (!repository) return null;
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2901
|
+
return (
|
|
2902
|
+
infos.get(id)?.folders.find((each) => each.repository === repository)
|
|
2903
|
+
?.path ?? null
|
|
2904
|
+
);
|
|
2905
|
+
};
|
|
2906
|
+
|
|
2907
|
+
/** On home: another computer's folders for the composer (`{ places: true }` or `{ browse }`), asked there. */
|
|
2908
|
+
const foldersOn = async (id, question) => {
|
|
2909
|
+
const label = labelOf(id) ?? "that computer";
|
|
2910
|
+
const sibling = siblings.find((each) => each.id === id);
|
|
2911
|
+
if (!sibling || !store.ownMachine(id))
|
|
2912
|
+
return { ok: false, error: `${label} is not connected` };
|
|
2913
|
+
if (!sibling.connected) return { ok: false, error: `${label} is offline` };
|
|
2914
|
+
return (
|
|
2915
|
+
(await askWorker(id, { folders: question })) ?? {
|
|
2916
|
+
ok: false,
|
|
2917
|
+
error: `${label} did not answer`,
|
|
2918
|
+
}
|
|
2919
|
+
);
|
|
2866
2920
|
};
|
|
2867
2921
|
|
|
2868
2922
|
/**
|
|
2869
2923
|
* On home: the other computer named for an agent's thread turn (`@codex #pop-os`) and its checkout of the thread's
|
|
2870
|
-
* repository, or why it cannot take it.
|
|
2924
|
+
* repository, or why it cannot take it. With no checkout there (or a folder that is no repository) the turn works
|
|
2925
|
+
* in that computer's scratch folder: `folder` is null.
|
|
2871
2926
|
*/
|
|
2872
2927
|
const placeOn = (agent, workspace, id) => {
|
|
2873
2928
|
const sibling = siblings.find((each) => each.id === id);
|
|
2874
2929
|
const label = labelOf(id) ?? "that computer";
|
|
2875
2930
|
if (!sibling || !store.ownMachine(id))
|
|
2876
2931
|
return { error: `${label} is not connected` };
|
|
2877
|
-
|
|
2932
|
+
// Offline, or back but not yet saying which folders it has: the work can wait for it (threadRuns.mjs).
|
|
2933
|
+
if (!sibling.connected)
|
|
2934
|
+
return { error: `${label} is offline`, waits: true };
|
|
2878
2935
|
if (!sibling.agents.includes(agent))
|
|
2879
2936
|
return { error: `${nameOf(agent)} is not on ${label}` };
|
|
2880
2937
|
if (!workspace) return { machine: id, folder: null };
|
|
2881
2938
|
if (inventoryOf(id).state !== "ready")
|
|
2882
|
-
return { error: `${label}'s repository inventory is not ready` };
|
|
2883
|
-
const repository = repositoryOf(workspace);
|
|
2884
|
-
const folder = repository
|
|
2885
|
-
? infos.get(id)?.folders.find((each) => each.repository === repository)
|
|
2886
|
-
?.path
|
|
2887
|
-
: null;
|
|
2888
|
-
if (!folder)
|
|
2889
2939
|
return {
|
|
2890
|
-
error: `${label}
|
|
2940
|
+
error: `${label}'s repository inventory is not ready`,
|
|
2941
|
+
waits: true,
|
|
2891
2942
|
};
|
|
2892
|
-
return { machine: id, folder };
|
|
2943
|
+
return { machine: id, folder: checkoutOn(id, workspace) };
|
|
2893
2944
|
};
|
|
2894
2945
|
|
|
2895
2946
|
/** The computers the board may name: this one and every other the person has, with their agents and repositories. */
|
|
@@ -3046,6 +3097,8 @@ export function createOwnMachines({
|
|
|
3046
3097
|
refreshInventory,
|
|
3047
3098
|
placeElsewhere,
|
|
3048
3099
|
placeOn,
|
|
3100
|
+
checkoutOn,
|
|
3101
|
+
foldersOn,
|
|
3049
3102
|
addressIn,
|
|
3050
3103
|
computersWith,
|
|
3051
3104
|
computersFor,
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// The board of the work between the person's swarm and one other person's (Collab, People): every ask between the
|
|
2
|
+
// two swarms as a card, either way. It is read from the asks' own states, which both computers already hold (Harness's
|
|
3
|
+
// status of each ask, the messages, its end), so each side shows the same cards and nothing new crosses:
|
|
4
|
+
// - To do: asked, not accepted yet. Waiting on the person when it is theirs to accept.
|
|
5
|
+
// - In progress: accepted and open. Live while the person's agent works it; waiting on the person when a reply of
|
|
6
|
+
// their agent's is held for them to send.
|
|
7
|
+
// - Review: the side asked answered last, and the asker has not ended it.
|
|
8
|
+
// - Done: ended. One declined, blocked or expired is marked blocked with why.
|
|
9
|
+
import { nameOf } from "./members.mjs";
|
|
10
|
+
import { oneLine } from "./oneLine.mjs";
|
|
11
|
+
|
|
12
|
+
const OPEN = new Set(["accepted", "accepted_pending"]);
|
|
13
|
+
const REFUSED = {
|
|
14
|
+
declined: (item) =>
|
|
15
|
+
item.role === "target" ? "You declined" : `${item.peer.handle} declined`,
|
|
16
|
+
blocked: () => "Blocked",
|
|
17
|
+
expired: () => "Expired without an answer",
|
|
18
|
+
};
|
|
19
|
+
const TRAIL = 6;
|
|
20
|
+
const LIVE = new Set(["claimed", "running"]);
|
|
21
|
+
|
|
22
|
+
const theirs = (item) =>
|
|
23
|
+
item.peer.agent === "person"
|
|
24
|
+
? item.peer.handle
|
|
25
|
+
: `${item.peer.handle}'s ${nameOf(item.peer.agent)}`;
|
|
26
|
+
const yours = (item) =>
|
|
27
|
+
item.mine === "person" || item.mine === "user"
|
|
28
|
+
? "you"
|
|
29
|
+
: `your ${nameOf(item.mine)}`;
|
|
30
|
+
// Only the person's own side starts with a word to capitalize: a handle keeps its own case.
|
|
31
|
+
const capital = (text) => (text.startsWith("you") ? `Y${text.slice(1)}` : text);
|
|
32
|
+
const day = (at) =>
|
|
33
|
+
at
|
|
34
|
+
? new Date(at).toLocaleDateString("en-US", {
|
|
35
|
+
month: "short",
|
|
36
|
+
day: "numeric",
|
|
37
|
+
})
|
|
38
|
+
: null;
|
|
39
|
+
|
|
40
|
+
/** One ask as its card, from the conversation (network.mjs item) and its messages. */
|
|
41
|
+
function cardOf(item, messages) {
|
|
42
|
+
const asker = item.role === "asker" ? yours(item) : theirs(item);
|
|
43
|
+
const asked = item.role === "asker" ? theirs(item) : yours(item);
|
|
44
|
+
const here = item.thread;
|
|
45
|
+
const ended =
|
|
46
|
+
item.group === "ended" || (here && !here.open) || item.status === "closed";
|
|
47
|
+
const last = messages.at(-1) ?? null;
|
|
48
|
+
// The side asked answered last: the asked side sends out when it is this side, in when it is theirs.
|
|
49
|
+
const answered =
|
|
50
|
+
Boolean(last) &&
|
|
51
|
+
messages.length > 1 &&
|
|
52
|
+
last.direction === (item.role === "target" ? "out" : "in");
|
|
53
|
+
const card = {
|
|
54
|
+
id: item.id,
|
|
55
|
+
title: oneLine(item.about || "A message", 120),
|
|
56
|
+
route: `${capital(asker)} → ${asked}`,
|
|
57
|
+
column: "doing",
|
|
58
|
+
agent: item.role === "target" ? item.mine : null,
|
|
59
|
+
holder: null,
|
|
60
|
+
status: null,
|
|
61
|
+
note: null,
|
|
62
|
+
blocked: null,
|
|
63
|
+
needsYou: null,
|
|
64
|
+
tasks: [item.id],
|
|
65
|
+
by: item.role === "asker" ? item.mine : item.peer.handle,
|
|
66
|
+
at: item.updatedAt ?? item.createdAt ?? null,
|
|
67
|
+
history: messages.slice(-TRAIL).map((message) => ({
|
|
68
|
+
at: message.created_at,
|
|
69
|
+
by: message.direction === "in" ? item.peer.handle : message.sender,
|
|
70
|
+
text: `${capital(message.direction === "in" ? theirs(item) : message.sender === "user" ? "you" : `your ${nameOf(message.sender)}`)}: ${oneLine(message.text, 200)}`,
|
|
71
|
+
})),
|
|
72
|
+
};
|
|
73
|
+
if (REFUSED[item.status]) {
|
|
74
|
+
card.column = "done";
|
|
75
|
+
card.blocked = REFUSED[item.status](item);
|
|
76
|
+
card.status = card.blocked;
|
|
77
|
+
} else if (item.status === "requested") {
|
|
78
|
+
card.column = "todo";
|
|
79
|
+
if (item.role === "target") {
|
|
80
|
+
card.needsYou = "accept or decline it";
|
|
81
|
+
card.status = "Accept or decline";
|
|
82
|
+
} else card.status = `Waiting on ${item.peer.handle}`;
|
|
83
|
+
} else if (ended) {
|
|
84
|
+
card.column = "done";
|
|
85
|
+
const on = day(item.updatedAt);
|
|
86
|
+
card.status = on ? `Ended ${on}` : "Ended";
|
|
87
|
+
card.note = here?.outcome ? oneLine(here.outcome, 200) : null;
|
|
88
|
+
} else if (here?.held) {
|
|
89
|
+
card.needsYou = "a reply waits for you to send";
|
|
90
|
+
card.status = "Reply to send";
|
|
91
|
+
} else if (answered) {
|
|
92
|
+
card.column = "review";
|
|
93
|
+
card.status =
|
|
94
|
+
item.role === "asker"
|
|
95
|
+
? "Answered, yours to close"
|
|
96
|
+
: `Answered, ${item.peer.handle}'s to close`;
|
|
97
|
+
} else if (!OPEN.has(item.status) && !here) card.status = item.status;
|
|
98
|
+
return card;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* The board between this swarm and one other person's: its cards, and as runs the asks the person's own agents are
|
|
103
|
+
* working now (the board marks those live).
|
|
104
|
+
*/
|
|
105
|
+
export function peopleBoard(items, { handle, messagesOf, taskOf }) {
|
|
106
|
+
const withThem = items.filter(
|
|
107
|
+
(item) => item.peer.handle === String(handle).toLowerCase()
|
|
108
|
+
);
|
|
109
|
+
const cards = withThem.map((item) => cardOf(item, messagesOf(item.id)));
|
|
110
|
+
const runs = withThem
|
|
111
|
+
.filter((item) => item.role === "target")
|
|
112
|
+
.map((item) => ({ item, task: taskOf(item.id) }))
|
|
113
|
+
.filter(({ task }) => task && LIVE.has(task.status))
|
|
114
|
+
.map(({ item, task }) => ({
|
|
115
|
+
id: item.id,
|
|
116
|
+
agent: item.mine,
|
|
117
|
+
status: task.status,
|
|
118
|
+
startedAt: task.claimed_at ?? task.updated_at,
|
|
119
|
+
steps: [],
|
|
120
|
+
}));
|
|
121
|
+
for (const card of cards)
|
|
122
|
+
if (runs.some((run) => run.id === card.id))
|
|
123
|
+
card.holder = capital(yours(withThem.find((i) => i.id === card.id)));
|
|
124
|
+
return {
|
|
125
|
+
handle,
|
|
126
|
+
cards,
|
|
127
|
+
runs,
|
|
128
|
+
asks: cards.length,
|
|
129
|
+
needsYou: cards.filter((card) => card.needsYou).length,
|
|
130
|
+
};
|
|
131
|
+
}
|
package/lib/phones.mjs
CHANGED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
// A shared project's board: the one board every person in the project and their agents see, built on each computer
|
|
2
|
+
// from the project's record (projects.mjs), so every copy shows the same cards. It holds:
|
|
3
|
+
// - the project's pieces and the work agents said they are doing (plan_work) as cards, their column, title and holder
|
|
4
|
+
// following the record: an open piece is To do, one held or work under way In progress, work done Review, merged
|
|
5
|
+
// Done; work that clashes is blocked;
|
|
6
|
+
// - the cards agents and people add (update_board, a task handed out in the room): a `card` entry made by the side
|
|
7
|
+
// that added it.
|
|
8
|
+
// The record's rule holds: each side writes only its own entries. A side's changes to a card (its column, note,
|
|
9
|
+
// blocked, its tasks and trail) are one `card-edit` entry of that side's per card, each field stamped with when it was
|
|
10
|
+
// set; every computer reads a field's newest value across all sides, so moves from either side land the same way.
|
|
11
|
+
import { oneLine } from "./oneLine.mjs";
|
|
12
|
+
|
|
13
|
+
export const BOARD_KINDS = ["card", "card-edit"];
|
|
14
|
+
const FIELDS = ["title", "column", "agent", "note", "blocked", "needsYou"];
|
|
15
|
+
// A card from the record is moved by the record: these of its fields are never set on the board.
|
|
16
|
+
const RECORD_FIELDS = new Set(["title", "column", "agent"]);
|
|
17
|
+
const HISTORY_LIMIT = 30;
|
|
18
|
+
const WORK_COLUMNS = {
|
|
19
|
+
checking: "doing",
|
|
20
|
+
unchecked: "doing",
|
|
21
|
+
clear: "doing",
|
|
22
|
+
overlap: "doing",
|
|
23
|
+
clash: "doing",
|
|
24
|
+
review: "review",
|
|
25
|
+
merged: "done",
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/** The one entry a side keeps for its changes to one card; an entry under another id is not that side's. */
|
|
29
|
+
export const editIdOf = (cardId, side) => `card-edit:${cardId}:${side}`;
|
|
30
|
+
|
|
31
|
+
export function createProjectBoard({ items, write, local, shared, pieces }) {
|
|
32
|
+
const now = () => new Date().toISOString();
|
|
33
|
+
const named = (p, field, value, toShared) =>
|
|
34
|
+
field === "agent" && value
|
|
35
|
+
? toShared
|
|
36
|
+
? shared(p, value)
|
|
37
|
+
: local(p, value)
|
|
38
|
+
: (value ?? null);
|
|
39
|
+
const editsOf = (p) => {
|
|
40
|
+
const byCard = new Map();
|
|
41
|
+
for (const edit of items(p.id, "card-edit")) {
|
|
42
|
+
const cardId = String(edit.body.card ?? "");
|
|
43
|
+
if (edit.id !== editIdOf(cardId, edit.side)) continue;
|
|
44
|
+
byCard.set(cardId, [...(byCard.get(cardId) ?? []), edit]);
|
|
45
|
+
}
|
|
46
|
+
return byCard;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// A card as every side's changes leave it: each field its newest value, every side's tasks and trail together.
|
|
50
|
+
const fold = (p, base, edits) => {
|
|
51
|
+
const newest = {};
|
|
52
|
+
for (const edit of edits)
|
|
53
|
+
for (const [field, change] of Object.entries(edit.body.fields ?? {})) {
|
|
54
|
+
const settable =
|
|
55
|
+
[...FIELDS, "removed"].includes(field) &&
|
|
56
|
+
!(base.derived && RECORD_FIELDS.has(field));
|
|
57
|
+
if (!settable) continue;
|
|
58
|
+
if (!newest[field] || String(change.at) > String(newest[field].at))
|
|
59
|
+
newest[field] = change;
|
|
60
|
+
}
|
|
61
|
+
const card = { ...base };
|
|
62
|
+
for (const [field, change] of Object.entries(newest))
|
|
63
|
+
card[field] = named(p, field, change.value, false);
|
|
64
|
+
card.tasks = [...new Set(edits.flatMap((edit) => edit.body.tasks ?? []))];
|
|
65
|
+
card.history = edits
|
|
66
|
+
.flatMap((edit) =>
|
|
67
|
+
(edit.body.history ?? []).map((entry) => ({
|
|
68
|
+
...entry,
|
|
69
|
+
by: local(p, entry.by),
|
|
70
|
+
}))
|
|
71
|
+
)
|
|
72
|
+
.sort((a, b) => String(a.at).localeCompare(String(b.at)))
|
|
73
|
+
.slice(-HISTORY_LIMIT);
|
|
74
|
+
card.at = [base.at, ...edits.map((edit) => edit.updatedAt)]
|
|
75
|
+
.filter(Boolean)
|
|
76
|
+
.sort()
|
|
77
|
+
.at(-1);
|
|
78
|
+
return card;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const blank = {
|
|
82
|
+
note: null,
|
|
83
|
+
blocked: null,
|
|
84
|
+
needsYou: null,
|
|
85
|
+
tasks: [],
|
|
86
|
+
history: [],
|
|
87
|
+
};
|
|
88
|
+
// The pieces and the work under way, as the record has them.
|
|
89
|
+
const fromRecord = (p) => [
|
|
90
|
+
...pieces.cards(p).map((piece) => ({
|
|
91
|
+
...blank,
|
|
92
|
+
id: piece.id,
|
|
93
|
+
title: oneLine(piece.title, 120),
|
|
94
|
+
column: piece.column,
|
|
95
|
+
agent: piece.owner ? local(p, piece.owner) : null,
|
|
96
|
+
needsYou: piece.offered ? "a person's OK for its handoff" : null,
|
|
97
|
+
by: local(p, piece.by),
|
|
98
|
+
derived: "piece",
|
|
99
|
+
at: piece.at,
|
|
100
|
+
})),
|
|
101
|
+
...items(p.id, "work")
|
|
102
|
+
.filter((work) => !work.body.piece && WORK_COLUMNS[work.body.status])
|
|
103
|
+
.map((work) => {
|
|
104
|
+
const agent = local(p, `${work.side}/${work.body.agent}`);
|
|
105
|
+
const clash = work.body.status === "clash";
|
|
106
|
+
return {
|
|
107
|
+
...blank,
|
|
108
|
+
id: work.id,
|
|
109
|
+
title: oneLine(work.body.summary, 120),
|
|
110
|
+
column: WORK_COLUMNS[work.body.status],
|
|
111
|
+
agent,
|
|
112
|
+
blocked: clash
|
|
113
|
+
? oneLine(
|
|
114
|
+
`clashes with other work${work.body.check?.reason ? `: ${work.body.check.reason}` : ""}`,
|
|
115
|
+
240
|
|
116
|
+
)
|
|
117
|
+
: null,
|
|
118
|
+
by: agent,
|
|
119
|
+
derived: "work",
|
|
120
|
+
at: work.at,
|
|
121
|
+
};
|
|
122
|
+
}),
|
|
123
|
+
];
|
|
124
|
+
const added = (p) =>
|
|
125
|
+
items(p.id, "card").map((entry) => ({
|
|
126
|
+
...blank,
|
|
127
|
+
id: entry.id,
|
|
128
|
+
title: oneLine(entry.body.title, 120),
|
|
129
|
+
column: "todo",
|
|
130
|
+
agent: null,
|
|
131
|
+
by: local(p, entry.body.by ?? `${entry.side}/person`),
|
|
132
|
+
auto: Boolean(entry.body.auto),
|
|
133
|
+
at: entry.at,
|
|
134
|
+
}));
|
|
135
|
+
const every = (p) => {
|
|
136
|
+
const edits = editsOf(p);
|
|
137
|
+
return [...fromRecord(p), ...added(p)].map((card) =>
|
|
138
|
+
fold(p, card, edits.get(card.id) ?? [])
|
|
139
|
+
);
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
/** The board's cards, as on every computer in the project. */
|
|
143
|
+
const load = (p) => every(p).filter((card) => !card.removed);
|
|
144
|
+
|
|
145
|
+
/** The cards as this side left them: what it added and changed becomes its own entries, and goes across. */
|
|
146
|
+
const save = (p, cards) => {
|
|
147
|
+
const before = new Map(every(p).map((card) => [card.id, card]));
|
|
148
|
+
const edits = editsOf(p);
|
|
149
|
+
const at = now();
|
|
150
|
+
const record = (card, changes, history, tasks) => {
|
|
151
|
+
const id = editIdOf(card.id, p.me);
|
|
152
|
+
const mine = (edits.get(card.id) ?? []).find((edit) => edit.id === id);
|
|
153
|
+
write(
|
|
154
|
+
p,
|
|
155
|
+
"card-edit",
|
|
156
|
+
{
|
|
157
|
+
card: card.id,
|
|
158
|
+
fields: { ...(mine?.body.fields ?? {}), ...changes },
|
|
159
|
+
history: [
|
|
160
|
+
...(mine?.body.history ?? []),
|
|
161
|
+
...history.map((entry) => ({ ...entry, by: shared(p, entry.by) })),
|
|
162
|
+
].slice(-HISTORY_LIMIT),
|
|
163
|
+
tasks,
|
|
164
|
+
},
|
|
165
|
+
id
|
|
166
|
+
);
|
|
167
|
+
};
|
|
168
|
+
for (const card of cards) {
|
|
169
|
+
const was = before.get(card.id);
|
|
170
|
+
if (!was)
|
|
171
|
+
write(
|
|
172
|
+
p,
|
|
173
|
+
"card",
|
|
174
|
+
{
|
|
175
|
+
title: card.title,
|
|
176
|
+
by: shared(p, card.by ?? "user"),
|
|
177
|
+
auto: Boolean(card.auto),
|
|
178
|
+
},
|
|
179
|
+
card.id
|
|
180
|
+
);
|
|
181
|
+
const start = was ?? { ...card, ...blank, column: "todo", agent: null };
|
|
182
|
+
const changes = {};
|
|
183
|
+
for (const field of FIELDS) {
|
|
184
|
+
if (card.derived && RECORD_FIELDS.has(field)) continue;
|
|
185
|
+
const value = card[field] ?? null;
|
|
186
|
+
if (JSON.stringify(value) === JSON.stringify(start[field] ?? null))
|
|
187
|
+
continue;
|
|
188
|
+
changes[field] = { value: named(p, field, value, true), at };
|
|
189
|
+
}
|
|
190
|
+
const seen = new Set(
|
|
191
|
+
(was?.history ?? []).map((entry) => `${entry.at}|${entry.text}`)
|
|
192
|
+
);
|
|
193
|
+
const history = (card.history ?? []).filter(
|
|
194
|
+
(entry) => !seen.has(`${entry.at}|${entry.text}`)
|
|
195
|
+
);
|
|
196
|
+
// Tasks are each side's own: another side's task ids stay in its entry.
|
|
197
|
+
const theirs = new Set(
|
|
198
|
+
(edits.get(card.id) ?? [])
|
|
199
|
+
.filter((edit) => edit.side !== p.me)
|
|
200
|
+
.flatMap((edit) => edit.body.tasks ?? [])
|
|
201
|
+
);
|
|
202
|
+
const tasks = (card.tasks ?? []).filter((id) => !theirs.has(id));
|
|
203
|
+
const mineBefore = (was?.tasks ?? []).filter((id) => !theirs.has(id));
|
|
204
|
+
const tasksChanged = JSON.stringify(tasks) !== JSON.stringify(mineBefore);
|
|
205
|
+
if (Object.keys(changes).length || history.length || tasksChanged)
|
|
206
|
+
record(card, changes, history, tasks);
|
|
207
|
+
}
|
|
208
|
+
const kept = new Set(cards.map((card) => card.id));
|
|
209
|
+
for (const [id, was] of before) {
|
|
210
|
+
if (kept.has(id) || was.removed || was.derived) continue;
|
|
211
|
+
const mine = (edits.get(id) ?? [])
|
|
212
|
+
.filter((edit) => edit.side === p.me)
|
|
213
|
+
.flatMap((edit) => edit.body.tasks ?? []);
|
|
214
|
+
record(was, { removed: { value: true, at } }, [], mine);
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
return { load, save };
|
|
219
|
+
}
|
package/lib/projectPieces.mjs
CHANGED
|
@@ -871,12 +871,38 @@ export function createPieces({
|
|
|
871
871
|
return item(id);
|
|
872
872
|
};
|
|
873
873
|
|
|
874
|
+
/** The pieces as the project's board shows them (projectBoard.mjs), read without changing anything. */
|
|
875
|
+
const cards = (p) =>
|
|
876
|
+
items(p.id, "piece")
|
|
877
|
+
.filter((piece) => !piece.body.withdrawn)
|
|
878
|
+
.map((piece) => {
|
|
879
|
+
const state = stateOf(p, piece.id);
|
|
880
|
+
const done = doneOf(p, piece.id);
|
|
881
|
+
const column = done
|
|
882
|
+
? done.body.status === "merged"
|
|
883
|
+
? "done"
|
|
884
|
+
: "review"
|
|
885
|
+
: state.owner
|
|
886
|
+
? "doing"
|
|
887
|
+
: "todo";
|
|
888
|
+
return {
|
|
889
|
+
id: piece.id,
|
|
890
|
+
title: piece.body.summary,
|
|
891
|
+
column,
|
|
892
|
+
owner: state.owner,
|
|
893
|
+
offered: Boolean(state.offered),
|
|
894
|
+
by: piece.body.by ?? `${piece.side}/person`,
|
|
895
|
+
at: piece.at,
|
|
896
|
+
};
|
|
897
|
+
});
|
|
898
|
+
|
|
874
899
|
return {
|
|
875
900
|
changed,
|
|
876
901
|
accepted,
|
|
877
902
|
declined,
|
|
878
903
|
command,
|
|
879
904
|
view,
|
|
905
|
+
cards,
|
|
880
906
|
strengthsOf,
|
|
881
907
|
brief,
|
|
882
908
|
refresh,
|