tryharness 0.7.83 → 0.7.86
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 +21 -19
- package/assets/dsh-plugin.mjs +75 -4
- package/assets/herdr-mod/harness/main.js +367 -0
- package/assets/herdr-mod/harness/mod.json +6 -0
- package/assets/opencode-plugin.js +87 -22
- package/assets/pi-extension.ts +81 -2
- package/cli.mjs +544 -208
- package/lib/adapters.mjs +62 -27
- package/lib/agentBinaries.mjs +6 -8
- package/lib/agentClaims.mjs +168 -0
- package/lib/agentReadTools.json +415 -0
- package/lib/agentSignIn.mjs +17 -18
- package/lib/agentWiring.mjs +114 -0
- package/lib/archetypes.js +10 -11
- package/lib/attention.mjs +100 -0
- package/lib/audit.mjs +1 -1
- package/lib/backupSetup.mjs +6 -28
- package/lib/bankrApprovals.mjs +86 -0
- package/lib/boardAccess.mjs +40 -66
- package/lib/boardBackup.mjs +86 -85
- package/lib/boardCommands.mjs +28 -0
- package/lib/boardFileCommands.mjs +29 -36
- package/lib/boardFiles.mjs +83 -15
- package/lib/boardMirror.mjs +78 -11
- package/lib/boardProtocol.json +191 -123
- package/lib/boardThreads.mjs +19 -37
- package/lib/boardTools.mjs +22 -15
- package/lib/boardWatches.mjs +43 -15
- package/lib/bridge.mjs +7 -3
- package/lib/browserAgentTools.mjs +59 -0
- package/lib/browserWake.mjs +0 -6
- package/lib/cards.mjs +52 -0
- package/lib/circling.mjs +189 -0
- package/lib/cleanup.mjs +234 -0
- package/lib/cloudBoot.mjs +21 -4
- package/lib/cloudSave.mjs +46 -5
- package/lib/compaction.mjs +8 -1
- package/lib/completion.mjs +358 -0
- package/lib/computerDevices.mjs +853 -0
- package/lib/connectionStatus.mjs +34 -0
- package/lib/connectors.mjs +139 -1
- package/lib/coordinator.mjs +108 -14
- package/lib/coreModels.mjs +36 -12
- package/lib/daemon.mjs +2426 -338
- package/lib/daemonLock.mjs +103 -0
- package/lib/deviceDoor.mjs +308 -0
- package/lib/deviceIdentity.mjs +114 -0
- package/lib/deviceList.mjs +172 -0
- package/lib/deviceSeal.mjs +74 -0
- package/lib/dispatcher.mjs +497 -26
- package/lib/dispatches.mjs +3 -3
- package/lib/environment.mjs +2 -1
- package/lib/environments.mjs +67 -41
- package/lib/events.mjs +318 -0
- package/lib/facts.mjs +170 -0
- package/lib/fileSource.mjs +540 -0
- package/lib/files.mjs +47 -2
- package/lib/gitHost.mjs +39 -1
- package/lib/goalCommands.mjs +12 -80
- package/lib/handover.mjs +21 -16
- package/lib/harnessOffers.mjs +140 -15
- package/lib/herdr.mjs +100 -15
- package/lib/herdrAppCall.mjs +19 -0
- package/lib/herdrCore.mjs +59 -0
- package/lib/herdrRuns.mjs +1126 -0
- package/lib/hookDialects.mjs +235 -50
- package/lib/identityLink.mjs +81 -0
- package/lib/inference.mjs +31 -2
- package/lib/jamAccess.mjs +82 -0
- package/lib/{projectBoard.mjs → jamBoard.mjs} +5 -4
- package/lib/{projectGit.mjs → jamGit.mjs} +53 -15
- package/lib/jamKey.mjs +274 -0
- package/lib/{projectPieces.mjs → jamPieces.mjs} +35 -29
- package/lib/{projectSettings.mjs → jamSettings.mjs} +12 -22
- package/lib/jamStore.mjs +973 -0
- package/lib/jamUpgrade.mjs +112 -0
- package/lib/jams.mjs +3079 -0
- package/lib/kanban.mjs +13 -7
- package/lib/landed.mjs +5 -1
- package/lib/library.mjs +41 -22
- package/lib/limits.mjs +91 -0
- package/lib/lineDiff.mjs +97 -0
- package/lib/lineup.mjs +18 -13
- package/lib/link.mjs +584 -0
- package/lib/localStack.mjs +75 -16
- package/lib/localmodels.mjs +58 -78
- package/lib/loopBackstop.mjs +2 -1
- package/lib/machine.mjs +544 -0
- package/lib/machineLink.mjs +446 -0
- package/lib/machineRoutes.mjs +68 -19
- package/lib/machineRuns.mjs +85 -4
- package/lib/machineSeal.mjs +6 -31
- package/lib/manager.mjs +134 -12
- package/lib/mcp-stdio.mjs +492 -215
- package/lib/mcpRelay.mjs +34 -35
- package/lib/members.json +1 -1
- package/lib/modelRoute.mjs +162 -0
- package/lib/nativeHost.mjs +81 -90
- package/lib/nativeSenses.mjs +258 -0
- package/lib/nerves.mjs +523 -0
- package/lib/network.mjs +117 -278
- package/lib/networkPlaces.mjs +578 -0
- package/lib/nextStep.mjs +95 -0
- package/lib/notify.mjs +2 -2
- package/lib/nudge.mjs +116 -10
- package/lib/originals.mjs +216 -0
- package/lib/outsideEvents.mjs +383 -0
- package/lib/outsideRuns.mjs +230 -0
- package/lib/ownMachines.mjs +674 -256
- package/lib/pain.mjs +215 -0
- package/lib/pairing.mjs +91 -11
- package/lib/paths.mjs +42 -3
- package/lib/peerProcess.mjs +21 -7
- package/lib/peopleLink.mjs +268 -0
- package/lib/personNotices.mjs +3 -2
- package/lib/phones.mjs +252 -542
- package/lib/placeCards.mjs +282 -0
- package/lib/placeChecks.mjs +95 -0
- package/lib/placeCommands.mjs +8 -17
- package/lib/placeRequests.mjs +152 -0
- package/lib/placeStore.mjs +295 -0
- package/lib/placeTool.d.ts +12 -0
- package/lib/placeTool.js +40 -0
- package/lib/places.mjs +63 -14
- package/lib/plans.mjs +53 -8
- package/lib/presence.mjs +270 -0
- package/lib/privateNetwork.d.ts +2 -0
- package/lib/privateNetwork.js +93 -0
- package/lib/proposals.mjs +300 -0
- package/lib/publicFetch.d.ts +32 -0
- package/lib/publicFetch.js +248 -0
- package/lib/reach.mjs +128 -0
- package/lib/rebuildable.mjs +72 -0
- package/lib/recall.mjs +216 -0
- package/lib/record.mjs +13 -0
- package/lib/reflexes.mjs +392 -0
- package/lib/relayLimits.mjs +31 -2
- package/lib/releaseNotice.mjs +198 -0
- package/lib/removeHarness.mjs +15 -4
- package/lib/repoLinks.mjs +204 -35
- package/lib/runAuthority.mjs +102 -39
- package/lib/runBrief.mjs +93 -40
- package/lib/runRequests.mjs +52 -14
- package/lib/runUsage.mjs +31 -0
- package/lib/runWorker.mjs +74 -25
- package/lib/runner.mjs +289 -45
- package/lib/runtime-install.mjs +37 -8
- package/lib/schedules.mjs +171 -47
- package/lib/screenWatches.mjs +221 -0
- package/lib/sealed.mjs +12 -30
- package/lib/sealedThreads.mjs +198 -392
- package/lib/secretStore.mjs +178 -0
- package/lib/secrets.mjs +11 -0
- package/lib/seen.mjs +3 -9
- package/lib/selfUpdate.mjs +51 -15
- package/lib/senseCall.mjs +1514 -0
- package/lib/senseHook.mjs +114 -0
- package/lib/senseTools.mjs +1298 -0
- package/lib/sessionBriefs.mjs +87 -0
- package/lib/sessionControl.mjs +63 -13
- package/lib/sessionFiles.mjs +85 -0
- package/lib/setupChoices.mjs +12 -3
- package/lib/setupMode.mjs +70 -25
- package/lib/sharedKeys.mjs +166 -0
- package/lib/sleep.mjs +396 -0
- package/lib/sources.mjs +306 -0
- package/lib/speech.mjs +166 -411
- package/lib/spoken.mjs +210 -0
- package/lib/steerHook.mjs +3 -1
- package/lib/steerQueue.mjs +40 -11
- package/lib/store.mjs +323 -130
- package/lib/stuck.mjs +85 -7
- package/lib/swarm.mjs +157 -49
- package/lib/swarmDevices.mjs +25 -85
- package/lib/swarmMemory.mjs +93 -9
- package/lib/t3.mjs +73 -3
- package/lib/taskCommands.mjs +51 -60
- package/lib/taskRooms.mjs +30 -4
- package/lib/taskRules.json +29 -0
- package/lib/taskRules.mjs +21 -0
- package/lib/taskRuns.mjs +74 -11
- package/lib/team.mjs +2 -1
- package/lib/threadActions.mjs +37 -9
- package/lib/threadAuthority.mjs +4 -4
- package/lib/threadBriefs.mjs +173 -43
- package/lib/threadNotes.mjs +320 -0
- package/lib/threadRecord.mjs +491 -0
- package/lib/threadRuns.mjs +216 -108
- package/lib/threadView.mjs +27 -30
- package/lib/threadWatches.mjs +1962 -0
- package/lib/timeSense.mjs +839 -0
- package/lib/tripwires.mjs +454 -0
- package/lib/ui.mjs +1 -1
- package/lib/vault.mjs +560 -45
- package/lib/vaultCommands.mjs +5 -3
- package/lib/vaultPeers.mjs +165 -0
- package/lib/vaultTools.d.ts +4 -1
- package/lib/vaultTools.js +22 -1
- package/lib/verdicts.mjs +12 -26
- package/lib/versions.mjs +117 -0
- package/lib/waitTool.mjs +278 -0
- package/lib/wakePicture.mjs +268 -0
- package/lib/wakeQueue.mjs +108 -0
- package/lib/watchResponses.mjs +533 -0
- package/lib/watches.mjs +290 -145
- package/lib/windowAsks.mjs +80 -17
- package/lib/worktrees.mjs +159 -9
- package/npm-shrinkwrap.json +138 -631
- package/package.json +7 -6
- package/release.json +211 -129
- package/lib/callSessions.mjs +0 -51
- package/lib/directLink.mjs +0 -349
- package/lib/peopleBoard.mjs +0 -131
- package/lib/projects.mjs +0 -2917
- package/lib/roomChannels.mjs +0 -667
package/lib/store.mjs
CHANGED
|
@@ -1,10 +1,25 @@
|
|
|
1
1
|
import { verdictEntriesByRun } from "./record.mjs";
|
|
2
|
+
import {
|
|
3
|
+
SQL_ENDED,
|
|
4
|
+
SQL_LIVE,
|
|
5
|
+
TASK_REPORTS,
|
|
6
|
+
sqlFrom,
|
|
7
|
+
taskEnded,
|
|
8
|
+
taskMay,
|
|
9
|
+
} from "./taskRules.mjs";
|
|
2
10
|
import { randomUUID } from "node:crypto";
|
|
3
11
|
import sqliteWasm from "node-sqlite3-wasm";
|
|
4
12
|
import { parseSession } from "./parsers.mjs";
|
|
5
13
|
import { provenanceFor } from "./provenance.mjs";
|
|
6
14
|
import { BOOK_TABLES } from "./book.mjs";
|
|
15
|
+
import { EVENT_TABLES, addArrivalColumns } from "./events.mjs";
|
|
16
|
+
import { FACT_TABLES } from "./facts.mjs";
|
|
17
|
+
import { WATCH_TABLES } from "./threadWatches.mjs";
|
|
18
|
+
import { FIRE_TABLES } from "./watchResponses.mjs";
|
|
19
|
+
import { NEXT_STEP_TABLES } from "./nextStep.mjs";
|
|
20
|
+
import { ownUsage } from "./runUsage.mjs";
|
|
7
21
|
import { DISPATCHER, PROPOSERS } from "./members.mjs";
|
|
22
|
+
import { PLACE_TABLES } from "./placeStore.mjs";
|
|
8
23
|
|
|
9
24
|
const SCHEMA_VERSION = 11;
|
|
10
25
|
const INDEX_FORMAT_VERSION = 2;
|
|
@@ -100,7 +115,11 @@ const roomPostOf = ({ source, ...row }) => ({
|
|
|
100
115
|
: {}),
|
|
101
116
|
});
|
|
102
117
|
|
|
103
|
-
|
|
118
|
+
/**
|
|
119
|
+
* `hasBlob(sha256)`: whether a file's bytes are on this computer. A row can say a file is here when its bytes are not:
|
|
120
|
+
* a board copied from another computer or brought back from a backup carries the rows without the bytes.
|
|
121
|
+
*/
|
|
122
|
+
export function openStore(file, { hasBlob = () => true } = {}) {
|
|
104
123
|
const db = new Database(file);
|
|
105
124
|
// The daemon is the database's single writer. DELETE mode is portable across the
|
|
106
125
|
// WASM VFS on every supported Node LTS line; no native addon or ABI is involved.
|
|
@@ -109,6 +128,10 @@ export function openStore(file) {
|
|
|
109
128
|
db.exec(
|
|
110
129
|
"pragma journal_mode = DELETE; pragma synchronous = NORMAL; pragma busy_timeout = 5000; pragma cache_size = -32768;"
|
|
111
130
|
);
|
|
131
|
+
// The schema and its upgrades below are one transaction: each statement on its own wrote, synced and deleted a
|
|
132
|
+
// journal, and a new database's first start spent 5.5 s on it, past 10 s with other programs writing (November 16).
|
|
133
|
+
// A start that fails partway leaves the database as it was.
|
|
134
|
+
db.exec("begin");
|
|
112
135
|
db.exec(`
|
|
113
136
|
create table if not exists schema_info (version integer not null);
|
|
114
137
|
insert into schema_info(version) select ${SCHEMA_VERSION} where not exists (select 1 from schema_info);
|
|
@@ -442,6 +465,55 @@ export function openStore(file) {
|
|
|
442
465
|
`);
|
|
443
466
|
// The onchain desk's book (book.mjs): board tables, so the board's copies and its backup carry it.
|
|
444
467
|
db.exec(BOOK_TABLES);
|
|
468
|
+
// The log of what happened on this computer (events.mjs) and the facts every computer reads the same (facts.mjs).
|
|
469
|
+
db.exec(EVENT_TABLES);
|
|
470
|
+
addArrivalColumns(db);
|
|
471
|
+
db.exec(FACT_TABLES);
|
|
472
|
+
// How many steps of a chain of watches' responses led to a fact (facts.mjs), on a board from before it was kept.
|
|
473
|
+
if (
|
|
474
|
+
!db
|
|
475
|
+
.all("pragma table_info(board_facts)")
|
|
476
|
+
.some((column) => column.name === "hops")
|
|
477
|
+
)
|
|
478
|
+
db.exec(
|
|
479
|
+
"alter table board_facts add column hops integer not null default 0"
|
|
480
|
+
);
|
|
481
|
+
db.exec(WATCH_TABLES);
|
|
482
|
+
db.exec(FIRE_TABLES);
|
|
483
|
+
// What the watch read when it tripped, said as its read-back says it (S9.1): attention judges a briefed trip by it.
|
|
484
|
+
if (
|
|
485
|
+
!db
|
|
486
|
+
.all("pragma table_info(board_watch_fires)")
|
|
487
|
+
.some((column) => column.name === "seen")
|
|
488
|
+
)
|
|
489
|
+
db.exec("alter table board_watch_fires add column seen text");
|
|
490
|
+
// The number a watch on a limit read when it tripped (S9.2): sleep proposes a limit from what the person let pass.
|
|
491
|
+
if (
|
|
492
|
+
!db
|
|
493
|
+
.all("pragma table_info(board_watch_fires)")
|
|
494
|
+
.some((column) => column.name === "value")
|
|
495
|
+
)
|
|
496
|
+
db.exec("alter table board_watch_fires add column value real");
|
|
497
|
+
db.exec(NEXT_STEP_TABLES);
|
|
498
|
+
// What the swarm believes is added to, never rewritten (docs/senses-plan.md S8.3): a belief that changes is a new one,
|
|
499
|
+
// and the one it replaces stays, named by it. Each dream's writes are journaled so the person can undo it whole.
|
|
500
|
+
if (
|
|
501
|
+
!db
|
|
502
|
+
.all("pragma table_info(board_observations)")
|
|
503
|
+
.some((column) => column.name === "replaced_by")
|
|
504
|
+
)
|
|
505
|
+
db.exec("alter table board_observations add column replaced_by text");
|
|
506
|
+
db.exec(`
|
|
507
|
+
create table if not exists board_dream_journal (
|
|
508
|
+
id integer primary key autoincrement,
|
|
509
|
+
dream text not null,
|
|
510
|
+
op text not null,
|
|
511
|
+
target text not null,
|
|
512
|
+
before text,
|
|
513
|
+
at text not null
|
|
514
|
+
);
|
|
515
|
+
create index if not exists board_dream_journal_dream on board_dream_journal(dream);
|
|
516
|
+
`);
|
|
445
517
|
const sessionColumns = new Set(
|
|
446
518
|
db.all("pragma table_info(sessions)").map((column) => column.name)
|
|
447
519
|
);
|
|
@@ -575,6 +647,23 @@ export function openStore(file) {
|
|
|
575
647
|
db.exec(
|
|
576
648
|
"create index if not exists phone_requests_received_idx on phone_requests(received_at)"
|
|
577
649
|
);
|
|
650
|
+
// A friend's computer's signing key, pinned with its sealing key: what checks who wrote a jam's event (jamKey.mjs).
|
|
651
|
+
if (
|
|
652
|
+
!db
|
|
653
|
+
.all("pragma table_info(relay_peers)")
|
|
654
|
+
.some((column) => column.name === "signing_key")
|
|
655
|
+
)
|
|
656
|
+
db.exec("alter table relay_peers add column signing_key text");
|
|
657
|
+
// A friend's identity keys before its newest (identityLink.mjs): what still checks a jam card or event they signed
|
|
658
|
+
// before their keys changed.
|
|
659
|
+
if (
|
|
660
|
+
!db
|
|
661
|
+
.all("pragma table_info(relay_peers)")
|
|
662
|
+
.some((column) => column.name === "past_signing_keys")
|
|
663
|
+
)
|
|
664
|
+
db.exec(
|
|
665
|
+
"alter table relay_peers add column past_signing_keys text not null default '[]'"
|
|
666
|
+
);
|
|
578
667
|
// A thread whose other side's computer holds a key: everything on it goes sealed to that key.
|
|
579
668
|
if (
|
|
580
669
|
!db
|
|
@@ -648,6 +737,9 @@ export function openStore(file) {
|
|
|
648
737
|
db.exec("alter table board_tasks add column audit text");
|
|
649
738
|
// Only the asker's explicit receipt establishes delivery. A pre-receipt board has no such evidence; its results
|
|
650
739
|
// remain available after upgrade rather than assuming an unrelated last-seen timestamp meant they were read.
|
|
740
|
+
// The person's places at outside networks (networkPlaces.mjs): made with the board, so the board copy carries them
|
|
741
|
+
// (boardMirror.mjs) and they follow home when it moves.
|
|
742
|
+
db.exec(PLACE_TABLES);
|
|
651
743
|
db.exec(`create table if not exists board_result_acks (
|
|
652
744
|
agent text not null,
|
|
653
745
|
receipt text not null,
|
|
@@ -656,6 +748,17 @@ export function openStore(file) {
|
|
|
656
748
|
primary key (agent, receipt)
|
|
657
749
|
)`);
|
|
658
750
|
|
|
751
|
+
// An agent's read of the person's browser that no browser was there to answer, waiting for the agent to ask again
|
|
752
|
+
// (deviceDoor.mjs get_held_read).
|
|
753
|
+
db.exec(`create table if not exists held_reads (
|
|
754
|
+
id text primary key,
|
|
755
|
+
agent text not null,
|
|
756
|
+
tool text not null,
|
|
757
|
+
input text not null,
|
|
758
|
+
device text,
|
|
759
|
+
held_at text not null
|
|
760
|
+
)`);
|
|
761
|
+
|
|
659
762
|
for (const [table, columns] of [
|
|
660
763
|
["board_tasks", ["returned"]],
|
|
661
764
|
["board_reactions", ["run_id", "source", "reason"]],
|
|
@@ -667,6 +770,7 @@ export function openStore(file) {
|
|
|
667
770
|
if (!existing.has(column))
|
|
668
771
|
db.exec(`alter table ${table} add column ${column} text`);
|
|
669
772
|
}
|
|
773
|
+
db.exec("commit");
|
|
670
774
|
|
|
671
775
|
const statements = [];
|
|
672
776
|
const prepare = (sql) => {
|
|
@@ -1146,19 +1250,10 @@ export function openStore(file) {
|
|
|
1146
1250
|
},
|
|
1147
1251
|
refreshGroup(parentId) {
|
|
1148
1252
|
const group = this.getTask(parentId);
|
|
1149
|
-
if (
|
|
1150
|
-
!group ||
|
|
1151
|
-
group.kind !== "group" ||
|
|
1152
|
-
["done", "failed", "unknown"].includes(group.status)
|
|
1153
|
-
)
|
|
1253
|
+
if (!group || group.kind !== "group" || taskEnded(group.status))
|
|
1154
1254
|
return null;
|
|
1155
1255
|
const parts = this.children(parentId);
|
|
1156
|
-
if (
|
|
1157
|
-
!parts.length ||
|
|
1158
|
-
parts.some(
|
|
1159
|
-
(part) => !["done", "failed", "unknown"].includes(part.status)
|
|
1160
|
-
)
|
|
1161
|
-
)
|
|
1256
|
+
if (!parts.length || parts.some((part) => !taskEnded(part.status)))
|
|
1162
1257
|
return null;
|
|
1163
1258
|
const status = parts.some((part) => part.status === "failed")
|
|
1164
1259
|
? "failed"
|
|
@@ -1198,7 +1293,7 @@ export function openStore(file) {
|
|
|
1198
1293
|
return {
|
|
1199
1294
|
ok: false,
|
|
1200
1295
|
error:
|
|
1201
|
-
"a
|
|
1296
|
+
"a friendship never runs on its own: no agent is in one, and work with other people's agents happens in a jam",
|
|
1202
1297
|
};
|
|
1203
1298
|
const group = this.getTask(id);
|
|
1204
1299
|
if (group?.kind === "group") {
|
|
@@ -1446,7 +1541,7 @@ export function openStore(file) {
|
|
|
1446
1541
|
"run",
|
|
1447
1542
|
`update board_tasks set status = 'failed', failure = 'start', result = ?,
|
|
1448
1543
|
holder = null, reported_at = ?, updated_at = ?, version = version + 1
|
|
1449
|
-
where id = ? and origin_agent = 'user' and status
|
|
1544
|
+
where id = ? and origin_agent = 'user' and status in ${sqlFrom("retire")}
|
|
1450
1545
|
and run_authorized_at is null and claimed_by is null`,
|
|
1451
1546
|
reason,
|
|
1452
1547
|
now,
|
|
@@ -1666,7 +1761,6 @@ export function openStore(file) {
|
|
|
1666
1761
|
max_wakes: Number(row.max_wakes),
|
|
1667
1762
|
paused_reason: row.paused_reason,
|
|
1668
1763
|
sessions: JSON.parse(row.sessions || "{}"),
|
|
1669
|
-
guests: JSON.parse(row.guests || "[]"),
|
|
1670
1764
|
posts: this.roomCount(id),
|
|
1671
1765
|
spend: this.goalSpend(id),
|
|
1672
1766
|
};
|
|
@@ -1703,32 +1797,6 @@ export function openStore(file) {
|
|
|
1703
1797
|
);
|
|
1704
1798
|
return this.getTask(id);
|
|
1705
1799
|
},
|
|
1706
|
-
// An invited guest: another person's agent on a relay thread linked to this goal.
|
|
1707
|
-
addGuest(id, thread, withAgent) {
|
|
1708
|
-
const guests = [
|
|
1709
|
-
...(this.goal(id)?.guests || []).filter(
|
|
1710
|
-
(guest) => guest.thread !== thread
|
|
1711
|
-
),
|
|
1712
|
-
{ thread, with: withAgent },
|
|
1713
|
-
];
|
|
1714
|
-
execute(
|
|
1715
|
-
"run",
|
|
1716
|
-
"update board_goals set guests = ? where goal_id = ?",
|
|
1717
|
-
JSON.stringify(guests),
|
|
1718
|
-
id
|
|
1719
|
-
);
|
|
1720
|
-
},
|
|
1721
|
-
guestGoalFor(thread) {
|
|
1722
|
-
const row = execute(
|
|
1723
|
-
"all",
|
|
1724
|
-
"select goal_id, guests from board_goals"
|
|
1725
|
-
).find((entry) =>
|
|
1726
|
-
JSON.parse(entry.guests || "[]").some(
|
|
1727
|
-
(guest) => guest.thread === thread
|
|
1728
|
-
)
|
|
1729
|
-
);
|
|
1730
|
-
return row?.goal_id || null;
|
|
1731
|
-
},
|
|
1732
1800
|
// At posting only: the task's room is part of how it was posted, not a change anyone races.
|
|
1733
1801
|
setParent(id, parentId) {
|
|
1734
1802
|
execute(
|
|
@@ -1808,7 +1876,7 @@ export function openStore(file) {
|
|
|
1808
1876
|
post.id
|
|
1809
1877
|
);
|
|
1810
1878
|
const made = post ? { ...post, mentions } : null;
|
|
1811
|
-
// Whoever follows a room's posts (a
|
|
1879
|
+
// Whoever follows a room's posts (a jam carries them to every member) hears each one as it is made.
|
|
1812
1880
|
if (made) publishRoomPost(goalId, made);
|
|
1813
1881
|
return made;
|
|
1814
1882
|
},
|
|
@@ -2400,34 +2468,107 @@ export function openStore(file) {
|
|
|
2400
2468
|
);
|
|
2401
2469
|
return this.getObservation(id);
|
|
2402
2470
|
},
|
|
2403
|
-
// Changed by later words:
|
|
2471
|
+
// Changed by later words: a new belief, never the old one rewritten. The old one stays as it was, `replaced` and
|
|
2472
|
+
// naming the new one; the new one carries what the old said in its history, with when and why.
|
|
2404
2473
|
reviseObservation(id, { text, evidence, why }) {
|
|
2405
2474
|
const observation = this.getObservation(id);
|
|
2406
2475
|
if (!observation || observation.status !== "active") return null;
|
|
2407
2476
|
const now = new Date().toISOString();
|
|
2477
|
+
const added = this.addObservation({
|
|
2478
|
+
kind: observation.kind,
|
|
2479
|
+
agent: observation.agent,
|
|
2480
|
+
folder: observation.folder,
|
|
2481
|
+
text,
|
|
2482
|
+
evidence: [...observation.evidence, ...evidence].slice(-30),
|
|
2483
|
+
});
|
|
2408
2484
|
execute(
|
|
2409
2485
|
"run",
|
|
2410
|
-
"update board_observations set
|
|
2411
|
-
text,
|
|
2412
|
-
JSON.stringify([...observation.evidence, ...evidence].slice(-30)),
|
|
2486
|
+
"update board_observations set history = ? where id = ?",
|
|
2413
2487
|
JSON.stringify(
|
|
2414
2488
|
[
|
|
2415
2489
|
...observation.history,
|
|
2416
|
-
{ text: observation.text, until: now, why },
|
|
2490
|
+
{ text: observation.text, until: now, why, was: id },
|
|
2417
2491
|
].slice(-20)
|
|
2418
2492
|
),
|
|
2493
|
+
added.id
|
|
2494
|
+
);
|
|
2495
|
+
execute(
|
|
2496
|
+
"run",
|
|
2497
|
+
"update board_observations set status = 'replaced', replaced_by = ?, updated_at = ? where id = ?",
|
|
2498
|
+
added.id,
|
|
2419
2499
|
now,
|
|
2420
2500
|
id
|
|
2421
2501
|
);
|
|
2422
2502
|
execute("run", "delete from board_observations_fts where id = ?", id);
|
|
2503
|
+
return this.getObservation(added.id);
|
|
2504
|
+
},
|
|
2505
|
+
// The person's own words for what the swarm believes: a new belief whose source is the person, replacing the old.
|
|
2506
|
+
correctObservation(id, text) {
|
|
2507
|
+
const observation = this.getObservation(id);
|
|
2508
|
+
const words = String(text ?? "")
|
|
2509
|
+
.trim()
|
|
2510
|
+
.slice(0, 1_000);
|
|
2511
|
+
if (!observation || observation.status !== "active" || !words)
|
|
2512
|
+
return null;
|
|
2513
|
+
const corrected = this.reviseObservation(id, {
|
|
2514
|
+
text: words,
|
|
2515
|
+
evidence: [{ person: true, at: new Date().toISOString() }],
|
|
2516
|
+
why: "the person corrected it",
|
|
2517
|
+
});
|
|
2518
|
+
return corrected;
|
|
2519
|
+
},
|
|
2520
|
+
// A belief undone: back to how it was before a write it no longer stands on.
|
|
2521
|
+
reopenObservation(id) {
|
|
2423
2522
|
execute(
|
|
2424
2523
|
"run",
|
|
2425
|
-
"
|
|
2426
|
-
id
|
|
2427
|
-
|
|
2524
|
+
"update board_observations set replaced_by = null where id = ?",
|
|
2525
|
+
id
|
|
2526
|
+
);
|
|
2527
|
+
return this.setObservationStatus(id, "active");
|
|
2528
|
+
},
|
|
2529
|
+
setObservationEvidence(id, evidence) {
|
|
2530
|
+
execute(
|
|
2531
|
+
"run",
|
|
2532
|
+
"update board_observations set evidence = ?, updated_at = ? where id = ?",
|
|
2533
|
+
JSON.stringify(evidence),
|
|
2534
|
+
new Date().toISOString(),
|
|
2535
|
+
id
|
|
2428
2536
|
);
|
|
2429
2537
|
return this.getObservation(id);
|
|
2430
2538
|
},
|
|
2539
|
+
// A widened lesson back in the scope and folder it had (the dream's Undo).
|
|
2540
|
+
unwidenLesson(id, { scope, folder }) {
|
|
2541
|
+
execute(
|
|
2542
|
+
"run",
|
|
2543
|
+
"update board_lessons set scope = ?, folder = ?, updated_at = ? where id = ?",
|
|
2544
|
+
scope,
|
|
2545
|
+
folder,
|
|
2546
|
+
new Date().toISOString(),
|
|
2547
|
+
id
|
|
2548
|
+
);
|
|
2549
|
+
return this.getLesson(id);
|
|
2550
|
+
},
|
|
2551
|
+
journalDream(dream, op, target, before = null) {
|
|
2552
|
+
execute(
|
|
2553
|
+
"run",
|
|
2554
|
+
"insert into board_dream_journal(dream, op, target, before, at) values(?, ?, ?, ?, ?)",
|
|
2555
|
+
dream,
|
|
2556
|
+
op,
|
|
2557
|
+
target,
|
|
2558
|
+
before === null ? null : JSON.stringify(before),
|
|
2559
|
+
new Date().toISOString()
|
|
2560
|
+
);
|
|
2561
|
+
},
|
|
2562
|
+
dreamJournal(dream) {
|
|
2563
|
+
return execute(
|
|
2564
|
+
"all",
|
|
2565
|
+
"select * from board_dream_journal where dream = ? order by id desc",
|
|
2566
|
+
dream
|
|
2567
|
+
).map((row) => ({
|
|
2568
|
+
...row,
|
|
2569
|
+
before: row.before ? JSON.parse(row.before) : null,
|
|
2570
|
+
}));
|
|
2571
|
+
},
|
|
2431
2572
|
// Out of the work (`retired` by the dream, `removed` by the person), on record; back with restoreObservation.
|
|
2432
2573
|
setObservationStatus(id, status) {
|
|
2433
2574
|
const observation = this.getObservation(id);
|
|
@@ -2748,7 +2889,7 @@ export function openStore(file) {
|
|
|
2748
2889
|
const retired = execute(
|
|
2749
2890
|
"run",
|
|
2750
2891
|
`update board_tasks set status = 'failed', failure = 'start', result = ?, holder = null,
|
|
2751
|
-
reported_at = ?, updated_at = ?, version = version + 1 where id = ? and status
|
|
2892
|
+
reported_at = ?, updated_at = ?, version = version + 1 where id = ? and status in ${sqlFrom("retire")} and version = ?`,
|
|
2752
2893
|
text,
|
|
2753
2894
|
at,
|
|
2754
2895
|
at,
|
|
@@ -2783,7 +2924,7 @@ export function openStore(file) {
|
|
|
2783
2924
|
}
|
|
2784
2925
|
},
|
|
2785
2926
|
// Stop: every open child closes; the caller stops what is running.
|
|
2786
|
-
// `agent`: only that agent's runs, the rest of the goal's work going on (a
|
|
2927
|
+
// `agent`: only that agent's runs, the rest of the goal's work going on (a jam's piece released).
|
|
2787
2928
|
closeGoalChildren(goalId, reason, agent = null) {
|
|
2788
2929
|
const now = new Date().toISOString();
|
|
2789
2930
|
const running = execute(
|
|
@@ -2795,7 +2936,7 @@ export function openStore(file) {
|
|
|
2795
2936
|
);
|
|
2796
2937
|
execute(
|
|
2797
2938
|
"run",
|
|
2798
|
-
|
|
2939
|
+
`update board_tasks set status = 'failed', result = ?, failure = 'person', holder = null, reported_at = ?, updated_at = ?, version = version + 1 where parent_id = ? and status in ${sqlFrom("stop")} and (? is null or target_agent = ?)`,
|
|
2799
2940
|
reason,
|
|
2800
2941
|
now,
|
|
2801
2942
|
now,
|
|
@@ -3178,7 +3319,7 @@ export function openStore(file) {
|
|
|
3178
3319
|
const now = new Date().toISOString();
|
|
3179
3320
|
const written = execute(
|
|
3180
3321
|
"run",
|
|
3181
|
-
|
|
3322
|
+
`update board_tasks set status = 'running', updated_at = @now, version = version + 1 where id = @id and status in ${sqlFrom("start")} and holder = @agent`,
|
|
3182
3323
|
{ id, agent, now }
|
|
3183
3324
|
);
|
|
3184
3325
|
return written.changes === 1
|
|
@@ -3191,11 +3332,23 @@ export function openStore(file) {
|
|
|
3191
3332
|
);
|
|
3192
3333
|
},
|
|
3193
3334
|
// What the run cost as its agent reported it; read back by the chain's trace.
|
|
3335
|
+
// What the run itself used, whatever its agent counted from earlier runs of the session (runUsage.mjs).
|
|
3194
3336
|
setRunUsage(id, usage) {
|
|
3337
|
+
const previous = usage?.session_totals
|
|
3338
|
+
? execute(
|
|
3339
|
+
"get",
|
|
3340
|
+
`select earlier.usage from board_tasks earlier join board_tasks run on run.id = ?
|
|
3341
|
+
where earlier.session_id = run.session_id and earlier.id != run.id and earlier.usage is not null
|
|
3342
|
+
order by coalesce(earlier.reported_at, earlier.created_at) desc limit 1`,
|
|
3343
|
+
id
|
|
3344
|
+
)
|
|
3345
|
+
: null;
|
|
3195
3346
|
execute(
|
|
3196
3347
|
"run",
|
|
3197
3348
|
"update board_tasks set usage = ? where id = ?",
|
|
3198
|
-
JSON.stringify(
|
|
3349
|
+
JSON.stringify(
|
|
3350
|
+
ownUsage(usage, previous ? JSON.parse(previous.usage) : null)
|
|
3351
|
+
),
|
|
3199
3352
|
id
|
|
3200
3353
|
);
|
|
3201
3354
|
},
|
|
@@ -3259,7 +3412,7 @@ export function openStore(file) {
|
|
|
3259
3412
|
const written = execute(
|
|
3260
3413
|
"run",
|
|
3261
3414
|
`update board_tasks set status = 'open', holder = target_agent, claimed_by = null, claimed_machine = null, claimed_at = null, lease_until = null, updated_at = @now, version = version + 1
|
|
3262
|
-
where id = @id and status
|
|
3415
|
+
where id = @id and status in ${sqlFrom("requeue")}`,
|
|
3263
3416
|
{ id, now }
|
|
3264
3417
|
);
|
|
3265
3418
|
return written.changes === 1
|
|
@@ -3270,17 +3423,21 @@ export function openStore(file) {
|
|
|
3270
3423
|
};
|
|
3271
3424
|
},
|
|
3272
3425
|
// A daemon restart lost every agent process it was running; those outcomes are unknown, never assumed.
|
|
3273
|
-
|
|
3426
|
+
// The runs this computer (`machine`) had going when its daemon stopped. A run another computer holds goes on
|
|
3427
|
+
// there, and that computer reports how it ended (machineRuns.mjs), so it is left as it is.
|
|
3428
|
+
settleInterruptedRuns(machine) {
|
|
3274
3429
|
const now = new Date().toISOString();
|
|
3430
|
+
const here = `status in ${sqlFrom("lost")} and (claimed_machine is null or claimed_machine = @machine)`;
|
|
3275
3431
|
const affected = execute(
|
|
3276
3432
|
"all",
|
|
3277
|
-
|
|
3433
|
+
`select id from board_tasks where ${here}`,
|
|
3434
|
+
{ machine }
|
|
3278
3435
|
).map((row) => row.id);
|
|
3279
3436
|
if (affected.length)
|
|
3280
3437
|
execute(
|
|
3281
3438
|
"run",
|
|
3282
|
-
`update board_tasks set status = 'unknown', holder = null, result = 'The daemon restarted during this run; its outcome is unknown. Check the workspace.', reported_at = @now, updated_at = @now, version = version + 1 where
|
|
3283
|
-
{ now }
|
|
3439
|
+
`update board_tasks set status = 'unknown', holder = null, result = 'The daemon restarted during this run; its outcome is unknown. Check the workspace.', reported_at = @now, updated_at = @now, version = version + 1 where ${here}`,
|
|
3440
|
+
{ now, machine }
|
|
3284
3441
|
);
|
|
3285
3442
|
return affected;
|
|
3286
3443
|
},
|
|
@@ -3458,10 +3615,9 @@ export function openStore(file) {
|
|
|
3458
3615
|
).map((row) => ({ ...row, score: -Number(row.rank) }));
|
|
3459
3616
|
},
|
|
3460
3617
|
|
|
3461
|
-
// A
|
|
3462
|
-
//
|
|
3463
|
-
//
|
|
3464
|
-
// are received as data with the sender's handle on them.
|
|
3618
|
+
// A friendship's messages, on the task both daemons hold under the same id. Outbound messages start held, or
|
|
3619
|
+
// flagged when they look like a secret, become sent when the person presses Send, and delivered when the other side
|
|
3620
|
+
// acknowledges them. Inbound ones are received as data with the friend's handle on them.
|
|
3465
3621
|
openThread(taskId, { withAgent, role, peerKey = null }) {
|
|
3466
3622
|
execute(
|
|
3467
3623
|
"run",
|
|
@@ -3474,22 +3630,50 @@ export function openStore(file) {
|
|
|
3474
3630
|
);
|
|
3475
3631
|
return this.getThread(taskId);
|
|
3476
3632
|
},
|
|
3477
|
-
// Another person's
|
|
3633
|
+
// Another person's identity, by handle: the keys first seen for them, then those their keys' links led to
|
|
3634
|
+
// (identityLink.mjs). Keys linked to nothing are refused until the person trusts them.
|
|
3478
3635
|
relayPeer(handle) {
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
handle
|
|
3484
|
-
) || null
|
|
3636
|
+
const row = execute(
|
|
3637
|
+
"get",
|
|
3638
|
+
"select handle, public_key, signing_key, past_signing_keys, pinned_at from relay_peers where handle = ?",
|
|
3639
|
+
handle
|
|
3485
3640
|
);
|
|
3641
|
+
return row
|
|
3642
|
+
? {
|
|
3643
|
+
...row,
|
|
3644
|
+
past_signing_keys: JSON.parse(row.past_signing_keys || "[]"),
|
|
3645
|
+
}
|
|
3646
|
+
: null;
|
|
3486
3647
|
},
|
|
3487
|
-
|
|
3648
|
+
/** A friend's identity moved on along its links: the new keys pinned, the signing key before kept as a past one. */
|
|
3649
|
+
followRelayPeer(handle, publicKey, signingKey) {
|
|
3650
|
+
const before = this.relayPeer(handle);
|
|
3651
|
+
const past = before?.signing_key
|
|
3652
|
+
? [before.signing_key, ...(before.past_signing_keys ?? [])]
|
|
3653
|
+
: (before?.past_signing_keys ?? []);
|
|
3488
3654
|
execute(
|
|
3489
3655
|
"run",
|
|
3490
|
-
"
|
|
3656
|
+
"update relay_peers set public_key = ?, signing_key = ?, past_signing_keys = ?, pinned_at = ? where handle = ?",
|
|
3657
|
+
publicKey,
|
|
3658
|
+
signingKey,
|
|
3659
|
+
JSON.stringify([...new Set(past)].slice(0, 32)),
|
|
3660
|
+
new Date().toISOString(),
|
|
3661
|
+
handle
|
|
3662
|
+
);
|
|
3663
|
+
return this.relayPeer(handle);
|
|
3664
|
+
},
|
|
3665
|
+
// `signingKey`: null from a Harness from before signing keys, which keeps the one pinned for that same key.
|
|
3666
|
+
pinRelayPeer(handle, publicKey, signingKey = null) {
|
|
3667
|
+
execute(
|
|
3668
|
+
"run",
|
|
3669
|
+
`insert into relay_peers(handle, public_key, signing_key, pinned_at) values(?, ?, ?, ?)
|
|
3670
|
+
on conflict(handle) do update set
|
|
3671
|
+
signing_key = case when relay_peers.public_key = excluded.public_key
|
|
3672
|
+
then coalesce(excluded.signing_key, relay_peers.signing_key) else excluded.signing_key end,
|
|
3673
|
+
public_key = excluded.public_key, pinned_at = excluded.pinned_at`,
|
|
3491
3674
|
handle,
|
|
3492
3675
|
publicKey,
|
|
3676
|
+
signingKey,
|
|
3493
3677
|
new Date().toISOString()
|
|
3494
3678
|
);
|
|
3495
3679
|
return this.relayPeer(handle);
|
|
@@ -3574,7 +3758,8 @@ export function openStore(file) {
|
|
|
3574
3758
|
...row,
|
|
3575
3759
|
bytes: row.bytes == null ? null : Number(row.bytes),
|
|
3576
3760
|
cloud: Number(row.cloud) === 1,
|
|
3577
|
-
|
|
3761
|
+
// Here only with its bytes: a row without them is a file still to come, never one to open.
|
|
3762
|
+
present: Number(row.present) === 1 && hasBlob(row.sha256),
|
|
3578
3763
|
}
|
|
3579
3764
|
: null;
|
|
3580
3765
|
},
|
|
@@ -3590,7 +3775,9 @@ export function openStore(file) {
|
|
|
3590
3775
|
return execute(
|
|
3591
3776
|
"all",
|
|
3592
3777
|
"select id from board_files where present = 1 order by created_at asc"
|
|
3593
|
-
)
|
|
3778
|
+
)
|
|
3779
|
+
.map((row) => this.file(row.id))
|
|
3780
|
+
.filter((file) => file.present);
|
|
3594
3781
|
},
|
|
3595
3782
|
taskFiles(taskId) {
|
|
3596
3783
|
return execute(
|
|
@@ -3692,7 +3879,10 @@ export function openStore(file) {
|
|
|
3692
3879
|
"select * from board_threads where task_id = ?",
|
|
3693
3880
|
taskId
|
|
3694
3881
|
);
|
|
3695
|
-
|
|
3882
|
+
if (!row) return null;
|
|
3883
|
+
// auto_send is a column from before friends, when another person's agent could reply on its own; never read.
|
|
3884
|
+
const { auto_send: _unread, ...thread } = row;
|
|
3885
|
+
return thread;
|
|
3696
3886
|
},
|
|
3697
3887
|
threadMessages(taskId) {
|
|
3698
3888
|
return execute(
|
|
@@ -3705,11 +3895,11 @@ export function openStore(file) {
|
|
|
3705
3895
|
refs: JSON.parse(row.refs || "[]"),
|
|
3706
3896
|
}));
|
|
3707
3897
|
},
|
|
3708
|
-
// Every
|
|
3898
|
+
// Every friendship on this computer, newest first, with what Friends and Messages show of each (network.mjs).
|
|
3709
3899
|
relayThreads(limit = 200) {
|
|
3710
3900
|
return execute(
|
|
3711
3901
|
"all",
|
|
3712
|
-
`select th.task_id, th.with_agent, th.role, th.
|
|
3902
|
+
`select th.task_id, th.with_agent, th.role, th.opened_at, th.closed_at, th.outcome, b.objective, b.target_agent, b.status, b.updated_at,
|
|
3713
3903
|
(select count(*) from board_messages m where m.task_id = th.task_id and m.state in ('held', 'flagged')) as held,
|
|
3714
3904
|
(select coalesce(max(seq), 0) from board_messages m where m.task_id = th.task_id and m.direction = 'in') as last_in_seq,
|
|
3715
3905
|
(select count(*) from board_messages m where m.task_id = th.task_id) as messages
|
|
@@ -3724,7 +3914,6 @@ export function openStore(file) {
|
|
|
3724
3914
|
) || null;
|
|
3725
3915
|
return {
|
|
3726
3916
|
...row,
|
|
3727
|
-
auto_send: Number(row.auto_send) === 1,
|
|
3728
3917
|
held: Number(row.held),
|
|
3729
3918
|
last_in_seq: Number(row.last_in_seq),
|
|
3730
3919
|
messages: Number(row.messages),
|
|
@@ -3793,23 +3982,11 @@ export function openStore(file) {
|
|
|
3793
3982
|
),
|
|
3794
3983
|
};
|
|
3795
3984
|
},
|
|
3796
|
-
postMessage({
|
|
3797
|
-
id,
|
|
3798
|
-
taskId,
|
|
3799
|
-
sender,
|
|
3800
|
-
text,
|
|
3801
|
-
refs = [],
|
|
3802
|
-
flagReason = null,
|
|
3803
|
-
hold = false,
|
|
3804
|
-
}) {
|
|
3985
|
+
postMessage({ id, taskId, sender, text, refs = [], flagReason = null }) {
|
|
3805
3986
|
const thread = this.getThread(taskId);
|
|
3806
3987
|
if (!thread) return { ok: false, error: "no thread on this task" };
|
|
3807
3988
|
if (thread.closed_at) return { ok: false, error: "the thread is closed" };
|
|
3808
|
-
const state = flagReason
|
|
3809
|
-
? "flagged"
|
|
3810
|
-
: thread.auto_send && !hold
|
|
3811
|
-
? "sent"
|
|
3812
|
-
: "held";
|
|
3989
|
+
const state = flagReason ? "flagged" : "held";
|
|
3813
3990
|
const now = new Date().toISOString();
|
|
3814
3991
|
execute(
|
|
3815
3992
|
"run",
|
|
@@ -3826,7 +4003,7 @@ export function openStore(file) {
|
|
|
3826
4003
|
state,
|
|
3827
4004
|
flagReason,
|
|
3828
4005
|
now,
|
|
3829
|
-
sentAt:
|
|
4006
|
+
sentAt: null,
|
|
3830
4007
|
}
|
|
3831
4008
|
);
|
|
3832
4009
|
execute(
|
|
@@ -3907,6 +4084,28 @@ export function openStore(file) {
|
|
|
3907
4084
|
? { ok: true }
|
|
3908
4085
|
: { ok: false, error: "no held message with that id" };
|
|
3909
4086
|
},
|
|
4087
|
+
forgetMeta(key) {
|
|
4088
|
+
execute("run", "delete from board_meta where key = ?", key);
|
|
4089
|
+
},
|
|
4090
|
+
// The person trusted another person's new key: their open threads are sealed with it from now on.
|
|
4091
|
+
repinThreads(handle, publicKey) {
|
|
4092
|
+
execute(
|
|
4093
|
+
"run",
|
|
4094
|
+
"update board_threads set peer_key = ? where closed_at is null and peer_key is not null and (with_agent = ? or with_agent like ?)",
|
|
4095
|
+
publicKey,
|
|
4096
|
+
handle,
|
|
4097
|
+
`${handle}/%`
|
|
4098
|
+
);
|
|
4099
|
+
},
|
|
4100
|
+
// The other side (or Harness for it) refused a message: kept as refused with why, never sent again on its own.
|
|
4101
|
+
markRefused(messageId, reason) {
|
|
4102
|
+
execute(
|
|
4103
|
+
"run",
|
|
4104
|
+
"update board_messages set state = 'refused', flag_reason = ? where id = ? and state = 'sent'",
|
|
4105
|
+
String(reason).slice(0, 300),
|
|
4106
|
+
messageId
|
|
4107
|
+
);
|
|
4108
|
+
},
|
|
3910
4109
|
markDelivered(messageId) {
|
|
3911
4110
|
execute(
|
|
3912
4111
|
"run",
|
|
@@ -3925,25 +4124,6 @@ export function openStore(file) {
|
|
|
3925
4124
|
refs: JSON.parse(row.refs || "[]"),
|
|
3926
4125
|
}));
|
|
3927
4126
|
},
|
|
3928
|
-
setAutoSend(taskId, on) {
|
|
3929
|
-
const thread = this.getThread(taskId);
|
|
3930
|
-
if (!thread) return { ok: false, error: "no thread on this task" };
|
|
3931
|
-
execute(
|
|
3932
|
-
"run",
|
|
3933
|
-
"update board_threads set auto_send = ? where task_id = ?",
|
|
3934
|
-
on ? 1 : 0,
|
|
3935
|
-
taskId
|
|
3936
|
-
);
|
|
3937
|
-
return { ok: true, thread: this.getThread(taskId) };
|
|
3938
|
-
},
|
|
3939
|
-
// A flag on any message turns auto-send off again; the person switches it back on knowingly.
|
|
3940
|
-
revertAutoSend(taskId) {
|
|
3941
|
-
execute(
|
|
3942
|
-
"run",
|
|
3943
|
-
"update board_threads set auto_send = 0 where task_id = ?",
|
|
3944
|
-
taskId
|
|
3945
|
-
);
|
|
3946
|
-
},
|
|
3947
4127
|
closeThread(taskId, outcome) {
|
|
3948
4128
|
const thread = this.getThread(taskId);
|
|
3949
4129
|
if (!thread) return { ok: false, error: "no thread on this task" };
|
|
@@ -3958,7 +4138,7 @@ export function openStore(file) {
|
|
|
3958
4138
|
);
|
|
3959
4139
|
execute(
|
|
3960
4140
|
"run",
|
|
3961
|
-
|
|
4141
|
+
`update board_tasks set status = 'done', holder = null, result = coalesce(?, result), reported_at = ?, updated_at = ?, version = version + 1 where id = ? and status in ${sqlFrom("close")}`,
|
|
3962
4142
|
outcome || null,
|
|
3963
4143
|
now,
|
|
3964
4144
|
now,
|
|
@@ -4052,8 +4232,10 @@ export function openStore(file) {
|
|
|
4052
4232
|
}
|
|
4053
4233
|
return id;
|
|
4054
4234
|
},
|
|
4055
|
-
// Messages
|
|
4235
|
+
// Messages from the person's friends since they last read the board from `machine`.
|
|
4056
4236
|
unreadFor(agent, machine = null) {
|
|
4237
|
+
// The only messages on this board are a friendship's, and no agent is ever in one.
|
|
4238
|
+
if (agent !== "user") return [];
|
|
4057
4239
|
const seen =
|
|
4058
4240
|
this.lastSeenAt(agent, machine) || "1970-01-01T00:00:00.000Z";
|
|
4059
4241
|
return execute(
|
|
@@ -4287,10 +4469,10 @@ export function openStore(file) {
|
|
|
4287
4469
|
return execute(
|
|
4288
4470
|
"all",
|
|
4289
4471
|
`select b.id, b.objective, b.kind, b.status, b.origin_agent, b.target_agent, b.claimed_by, b.holder, b.parent_id,
|
|
4290
|
-
b.run_workspace, b.run_authorized_at, b.lease_until, b.claimed_at, b.reported_at, b.created_at, b.updated_at,
|
|
4472
|
+
b.run_workspace, b.run_authorized_at, b.lease_until, b.claimed_at, b.reported_at, b.created_at, b.updated_at, b.session_id,
|
|
4291
4473
|
case when g.kind = 'goal' then g.status end as thread_status
|
|
4292
4474
|
from board_tasks b left join board_tasks g on g.id = b.parent_id
|
|
4293
|
-
where b.kind in ('task', 'wake') and b.removed_at is null and b.status in
|
|
4475
|
+
where b.kind in ('task', 'wake') and b.removed_at is null and b.status in ${SQL_LIVE}`
|
|
4294
4476
|
);
|
|
4295
4477
|
},
|
|
4296
4478
|
// When the author last posted in a thread (its own words, files or results), or null. Notes are bookkeeping, not
|
|
@@ -4307,6 +4489,16 @@ export function openStore(file) {
|
|
|
4307
4489
|
},
|
|
4308
4490
|
// Each agent's work on the board, newest first, for its card (cards.mjs): what it holds and finished, and when it
|
|
4309
4491
|
// could start (the person's Start, else the post) and reported.
|
|
4492
|
+
/** What each agent's finished runs used, newest first: the agent and its usage (S9.3, cards.mjs costOf). */
|
|
4493
|
+
runCosts() {
|
|
4494
|
+
return execute(
|
|
4495
|
+
"all",
|
|
4496
|
+
`select coalesce(claimed_by, target_agent) as agent, usage from board_tasks
|
|
4497
|
+
where kind in ('task', 'wake') and status = 'done' and usage is not null and removed_at is null
|
|
4498
|
+
and coalesce(claimed_by, target_agent) is not null and ${AGENTS_OWN}
|
|
4499
|
+
order by reported_at desc limit 5000`
|
|
4500
|
+
);
|
|
4501
|
+
},
|
|
4310
4502
|
agentWork() {
|
|
4311
4503
|
return execute(
|
|
4312
4504
|
"all",
|
|
@@ -4322,13 +4514,14 @@ export function openStore(file) {
|
|
|
4322
4514
|
if (status) {
|
|
4323
4515
|
clauses.push("b.status = @status");
|
|
4324
4516
|
params.status = status;
|
|
4325
|
-
} else if (!all)
|
|
4326
|
-
clauses.push(
|
|
4327
|
-
"b.status in ('open', 'claimed', 'running', 'needs_input')"
|
|
4328
|
-
);
|
|
4517
|
+
} else if (!all) clauses.push(`b.status in ${SQL_LIVE}`);
|
|
4329
4518
|
// An agent's whole-board list is work, not threads: those it reads as its rooms.
|
|
4330
4519
|
if (agent && agent !== "user" && all)
|
|
4331
4520
|
clauses.push("b.kind not in ('goal', 'wake')");
|
|
4521
|
+
// A friendship is the person's alone (docs/jam-plan.md J2): no agent is offered one. Harness's window still lists
|
|
4522
|
+
// them for the person's own board until the screens move to Friends and Messages (J5); it reads none of them.
|
|
4523
|
+
if (agent && agent !== "user" && agent !== "harness")
|
|
4524
|
+
clauses.push("th.task_id is null");
|
|
4332
4525
|
if (agent && !all) {
|
|
4333
4526
|
clauses.push(
|
|
4334
4527
|
"b.kind not in ('group', 'goal', 'wake') and (b.target_agent is null or b.target_agent = @agent or b.origin_agent = @agent or b.claimed_by = @agent)"
|
|
@@ -4349,7 +4542,7 @@ export function openStore(file) {
|
|
|
4349
4542
|
b.run_workspace, b.run_authorized_at, b.session_id, b.trust, b.origin_chain, b.target_machine, b.claimed_machine, b.created_at, b.updated_at, th.with_agent as thread_with, th.closed_at as thread_closed_at,
|
|
4350
4543
|
(select count(*) from board_messages m where m.task_id = b.id and m.state in ('held', 'flagged')) as held_messages,
|
|
4351
4544
|
(select count(*) from board_tasks c where c.parent_id = b.id) as child_count,
|
|
4352
|
-
(select count(*) from board_tasks c where c.parent_id = b.id and c.status in
|
|
4545
|
+
(select count(*) from board_tasks c where c.parent_id = b.id and c.status in ${SQL_ENDED}) as child_done,
|
|
4353
4546
|
(select group_concat(c.target_agent, ', ') from board_tasks c where c.parent_id = b.id) as child_agents
|
|
4354
4547
|
from board_tasks b left join board_threads th on th.task_id = b.id ${clauses.length ? `where ${clauses.join(" and ")}` : ""} order by b.created_at desc limit @limit`,
|
|
4355
4548
|
params
|
|
@@ -4399,7 +4592,7 @@ export function openStore(file) {
|
|
|
4399
4592
|
running.push(taskId);
|
|
4400
4593
|
execute(
|
|
4401
4594
|
"run",
|
|
4402
|
-
|
|
4595
|
+
`update board_tasks set status = 'failed', result = 'Removed by you.', failure = 'person', holder = null, reported_at = ?, updated_at = ?, version = version + 1 where id = ? and kind != 'goal' and status in ${sqlFrom("stop")}`,
|
|
4403
4596
|
now,
|
|
4404
4597
|
now,
|
|
4405
4598
|
taskId
|
|
@@ -4480,7 +4673,7 @@ export function openStore(file) {
|
|
|
4480
4673
|
const written = execute(
|
|
4481
4674
|
"run",
|
|
4482
4675
|
`update board_tasks set status = 'claimed', claimed_by = @agent, holder = @agent, claimed_machine = @machine, claimed_at = @now, lease_until = @leaseUntil, updated_at = @now, version = version + 1
|
|
4483
|
-
where id = @id and status
|
|
4676
|
+
where id = @id and status in ${sqlFrom("claim")} and (holder is null or holder = @agent) and (@expected is null or version = @expected)
|
|
4484
4677
|
and (@machine is null or target_machine is null or target_machine = @machine)`,
|
|
4485
4678
|
{
|
|
4486
4679
|
id,
|
|
@@ -4507,7 +4700,7 @@ export function openStore(file) {
|
|
|
4507
4700
|
expectedVersion = null,
|
|
4508
4701
|
machine = null
|
|
4509
4702
|
) {
|
|
4510
|
-
if (!
|
|
4703
|
+
if (!TASK_REPORTS.includes(status))
|
|
4511
4704
|
return {
|
|
4512
4705
|
ok: false,
|
|
4513
4706
|
error: "status must be done, failed or needs_input",
|
|
@@ -4518,7 +4711,7 @@ export function openStore(file) {
|
|
|
4518
4711
|
`update board_tasks set status = @status, result = @result, reported_at = @now, updated_at = @now, version = version + 1,
|
|
4519
4712
|
holder = case when @status = 'needs_input' then origin_agent else null end,
|
|
4520
4713
|
failure = case when @status = 'failed' then @failure else null end
|
|
4521
|
-
where id = @id and status in (
|
|
4714
|
+
where id = @id and status in ${sqlFrom("report")} and holder = @agent and (@expected is null or version = @expected)
|
|
4522
4715
|
and (@machine is null or claimed_machine is null or claimed_machine = @machine)`,
|
|
4523
4716
|
{
|
|
4524
4717
|
id,
|
|
@@ -4543,7 +4736,7 @@ export function openStore(file) {
|
|
|
4543
4736
|
return { ok: true, task: this.getTask(id) };
|
|
4544
4737
|
}
|
|
4545
4738
|
return conflict(this.getTask(id), agent, expectedVersion, (task) =>
|
|
4546
|
-
|
|
4739
|
+
taskMay("report", task.status)
|
|
4547
4740
|
? machine && task.claimed_machine && task.claimed_machine !== machine
|
|
4548
4741
|
? `task is held by ${task.holder} on another computer`
|
|
4549
4742
|
: `task is held by ${task.holder}`
|
|
@@ -4557,7 +4750,7 @@ export function openStore(file) {
|
|
|
4557
4750
|
const written = execute(
|
|
4558
4751
|
"run",
|
|
4559
4752
|
`update board_tasks set status = 'open', holder = target_agent, claimed_by = null, claimed_at = null, lease_until = null, result = null, reported_at = null, updated_at = @now, version = version + 1
|
|
4560
|
-
where id = @id and status in (
|
|
4753
|
+
where id = @id and status in ${sqlFrom("release")} and (origin_agent = @agent or @agent = 'user') and (@expected is null or version = @expected)`,
|
|
4561
4754
|
{
|
|
4562
4755
|
id,
|
|
4563
4756
|
agent,
|
|
@@ -4567,7 +4760,7 @@ export function openStore(file) {
|
|
|
4567
4760
|
);
|
|
4568
4761
|
if (written.changes === 1) return { ok: true, task: this.getTask(id) };
|
|
4569
4762
|
return conflict(this.getTask(id), agent, expectedVersion, (task) =>
|
|
4570
|
-
|
|
4763
|
+
taskMay("release", task.status)
|
|
4571
4764
|
? `only ${task.origin_agent} or the user can release this task`
|
|
4572
4765
|
: `task is ${task.status}`
|
|
4573
4766
|
);
|
|
@@ -4581,7 +4774,7 @@ export function openStore(file) {
|
|
|
4581
4774
|
`update board_tasks set status = 'claimed', holder = claimed_by, updated_at = @now, version = version + 1,
|
|
4582
4775
|
brief = brief || char(10) || char(10) || 'Question from ' || claimed_by || ': ' || coalesce(result, '') || char(10) || 'Answer from ' || @agent || ': ' || @answer,
|
|
4583
4776
|
result = null, reported_at = null
|
|
4584
|
-
where id = @id and status
|
|
4777
|
+
where id = @id and status in ${sqlFrom("answer")} and holder = @agent and (@expected is null or version = @expected)`,
|
|
4585
4778
|
{
|
|
4586
4779
|
id,
|
|
4587
4780
|
agent,
|