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/kanban.mjs
CHANGED
|
@@ -9,8 +9,9 @@
|
|
|
9
9
|
// finished, blocked with why when it failed.
|
|
10
10
|
// Every thread turn starts from the board (runBrief.mjs), and every change answers with the whole board. Nothing waits
|
|
11
11
|
// on it: no agent is held for a card. Cards are kept per thread like its plan, so the buddy and the phone read the same
|
|
12
|
-
// ones (board.swarm.read). A board shared with other people (a
|
|
13
|
-
// instead (`shared`,
|
|
12
|
+
// ones (board.swarm.read). A board shared with other people (a jam's room) is kept where they all read it
|
|
13
|
+
// instead (`shared`, jamBoard.mjs), and its cards from that record, a piece or work under way, move with the record.
|
|
14
|
+
import { TASK_ENDED } from "./taskRules.mjs";
|
|
14
15
|
import { randomUUID } from "node:crypto";
|
|
15
16
|
import { nameOf } from "./members.mjs";
|
|
16
17
|
import { oneLine } from "./oneLine.mjs";
|
|
@@ -31,7 +32,7 @@ const REVIEW_STEPS = new Set(["check", "judge"]);
|
|
|
31
32
|
// A task an agent holds and works on, and one not finished yet.
|
|
32
33
|
const WORKING = new Set(["claimed", "running"]);
|
|
33
34
|
const UNFINISHED = new Set(["open", "claimed", "running", "needs_input"]);
|
|
34
|
-
const ENDED = new Set(
|
|
35
|
+
const ENDED = new Set(TASK_ENDED);
|
|
35
36
|
// A task asked in a thread is named for the thread in front of its words (asks.mjs, threadActions.mjs): its card is
|
|
36
37
|
// named by the words alone.
|
|
37
38
|
const ASKED = /^Asked in "[^]*?": (?:\S+ (?:asked|mentioned) you: )?([^]*)$/;
|
|
@@ -356,11 +357,16 @@ export function createKanban({
|
|
|
356
357
|
};
|
|
357
358
|
|
|
358
359
|
/** The board as an agent reads it: one line per card, by column, with what each card is waiting on. */
|
|
359
|
-
const view = (threadId) => {
|
|
360
|
+
const view = (threadId, { starting = null } = {}) => {
|
|
360
361
|
const cards = cardsOf(threadId);
|
|
361
362
|
if (!cards.length) return "No cards yet.";
|
|
363
|
+
// A dry run shows the brief its task would start with, and starting moves the task's card to In progress.
|
|
364
|
+
const columnOf = (card) =>
|
|
365
|
+
card.column === "todo" && card.tasks.includes(starting)
|
|
366
|
+
? "doing"
|
|
367
|
+
: card.column;
|
|
362
368
|
return COLUMNS.flatMap((column) => {
|
|
363
|
-
const here = cards.filter((card) => card
|
|
369
|
+
const here = cards.filter((card) => columnOf(card) === column);
|
|
364
370
|
if (!here.length) return [];
|
|
365
371
|
return [
|
|
366
372
|
`${COLUMN_NAMES[column]}:`,
|
|
@@ -373,10 +379,10 @@ export function createKanban({
|
|
|
373
379
|
};
|
|
374
380
|
|
|
375
381
|
/** What a run in the thread is told of its board: the cards, and how it manages the work on them. */
|
|
376
|
-
const brief = (threadId) =>
|
|
382
|
+
const brief = (threadId, { starting = null } = {}) =>
|
|
377
383
|
[
|
|
378
384
|
`This thread's board is where its work is managed, and the person follows the work on it. Each piece of the work is a card in To do, In progress, Review or Done.`,
|
|
379
|
-
view(threadId),
|
|
385
|
+
view(threadId, { starting }),
|
|
380
386
|
`Manage your work on it with update_board (thread ${threadId}). When you do work this turn, put it on a card: take a card that is already there or add one, move it to In progress as you start, to Review when it is ready to be checked and to Done when it is finished. Mark it blocked with why, or say what it waits on from the person. A turn that only answers needs no card. Handing a piece to another agent with post_task adds its card; post it with card to hand out a card already there. The task's claim and end move the card. Never wait on the board to do your work.`,
|
|
381
387
|
].join("\n\n");
|
|
382
388
|
|
package/lib/landed.mjs
CHANGED
|
@@ -7,6 +7,7 @@ import { LIVE_AGENTS } from "./live.mjs";
|
|
|
7
7
|
import { nameOf } from "./members.mjs";
|
|
8
8
|
import {
|
|
9
9
|
EDITOR_IDS,
|
|
10
|
+
editorCliFor,
|
|
10
11
|
editorInstall,
|
|
11
12
|
editorName,
|
|
12
13
|
t3App,
|
|
@@ -556,10 +557,13 @@ export function createLanded({
|
|
|
556
557
|
after,
|
|
557
558
|
]),
|
|
558
559
|
];
|
|
560
|
+
// Only an install of the editor Harness found itself, never a tool a session's report named (places.mjs).
|
|
561
|
+
const cli = editorCliFor(editor);
|
|
562
|
+
if (!cli) return 0;
|
|
559
563
|
// One at a time: the first may start the editor, and the tabs belong in the window it opens.
|
|
560
564
|
for (const args of calls)
|
|
561
565
|
await new Promise((resolve) => {
|
|
562
|
-
const child = spawn(
|
|
566
|
+
const child = spawn(cli, args, { env, stdio: "ignore" });
|
|
563
567
|
child.on("error", resolve);
|
|
564
568
|
child.on("close", resolve);
|
|
565
569
|
});
|
package/lib/library.mjs
CHANGED
|
@@ -5,6 +5,8 @@ import { ATLAS_VERSION } from "./atlas.mjs";
|
|
|
5
5
|
import { fileKind, readParts, readPart } from "./readers.mjs";
|
|
6
6
|
import { clock } from "./media.mjs";
|
|
7
7
|
import { encodeWav } from "./speech.mjs";
|
|
8
|
+
import { createSources } from "./sources.mjs";
|
|
9
|
+
import { createFileKind } from "./fileSource.mjs";
|
|
8
10
|
|
|
9
11
|
// The library: what is in the person's files and in the files their threads hold, found by what it is about and by
|
|
10
12
|
// its exact words. Folders the person added (`tryharness local add`) are read on the background lane: PDFs page by
|
|
@@ -317,6 +319,13 @@ export function createLibrary({
|
|
|
317
319
|
mask = async (text) => text,
|
|
318
320
|
log = () => {},
|
|
319
321
|
version = ATLAS_VERSION,
|
|
322
|
+
// The library runs in the context worker, away from the daemon's log: it follows its folders through the file
|
|
323
|
+
// source (fileSource.mjs) quietly, so nothing it sees is written anywhere.
|
|
324
|
+
sources = createSources({
|
|
325
|
+
events: { append: () => null },
|
|
326
|
+
log,
|
|
327
|
+
kinds: { files: createFileKind({}) },
|
|
328
|
+
}),
|
|
320
329
|
}) {
|
|
321
330
|
const store = atlas.library;
|
|
322
331
|
let cache = null;
|
|
@@ -478,38 +487,48 @@ export function createLibrary({
|
|
|
478
487
|
},
|
|
479
488
|
]);
|
|
480
489
|
|
|
481
|
-
// Each searched folder is
|
|
490
|
+
// Each searched folder is followed through the file source, so a new or changed file is read seconds after it lands.
|
|
482
491
|
const watchers = new Map();
|
|
483
492
|
let quiet = null;
|
|
484
|
-
const changed =
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
493
|
+
const changed =
|
|
494
|
+
(folder) =>
|
|
495
|
+
({ changed: names = [], error }) => {
|
|
496
|
+
// A folder that can no longer be read (moved, removed) is followed again at the next refresh that finds it.
|
|
497
|
+
if (error) {
|
|
498
|
+
watchers.get(folder)?.();
|
|
499
|
+
watchers.delete(folder);
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
const kept = names.filter(
|
|
503
|
+
(name) =>
|
|
504
|
+
!String(name)
|
|
505
|
+
.split(path.sep)
|
|
506
|
+
.some((part) => SKIP_DIR.test(part))
|
|
507
|
+
);
|
|
508
|
+
if (!kept.length) return;
|
|
509
|
+
clearTimeout(quiet);
|
|
510
|
+
quiet = setTimeout(() => {
|
|
511
|
+
const running = refreshing ?? Promise.resolve();
|
|
512
|
+
void running.then(() => refresh()).catch(() => {});
|
|
513
|
+
}, CHANGE_QUIET_MS);
|
|
514
|
+
quiet.unref?.();
|
|
515
|
+
};
|
|
494
516
|
const watch = (wanted) => {
|
|
495
|
-
for (const [folder,
|
|
517
|
+
for (const [folder, unfollow] of watchers)
|
|
496
518
|
if (!wanted.includes(folder)) {
|
|
497
|
-
|
|
519
|
+
unfollow();
|
|
498
520
|
watchers.delete(folder);
|
|
499
521
|
}
|
|
500
522
|
for (const folder of wanted) {
|
|
501
523
|
if (watchers.has(folder)) continue;
|
|
502
524
|
try {
|
|
503
|
-
|
|
525
|
+
watchers.set(
|
|
504
526
|
folder,
|
|
505
|
-
|
|
506
|
-
|
|
527
|
+
sources.subscribe(
|
|
528
|
+
{ kind: "files", folder, quiet: true },
|
|
529
|
+
changed(folder)
|
|
530
|
+
)
|
|
507
531
|
);
|
|
508
|
-
watcher.on("error", () => {
|
|
509
|
-
watcher.close();
|
|
510
|
-
watchers.delete(folder);
|
|
511
|
-
});
|
|
512
|
-
watchers.set(folder, watcher);
|
|
513
532
|
} catch {}
|
|
514
533
|
}
|
|
515
534
|
};
|
|
@@ -751,7 +770,7 @@ export function createLibrary({
|
|
|
751
770
|
stop() {
|
|
752
771
|
clearTimeout(quiet);
|
|
753
772
|
clearTimeout(dropCache);
|
|
754
|
-
for (const
|
|
773
|
+
for (const unfollow of watchers.values()) unfollow();
|
|
755
774
|
watchers.clear();
|
|
756
775
|
},
|
|
757
776
|
status: async () => ({
|
package/lib/limits.mjs
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// Limits as states (docs/senses-plan.md S2.4): how close the swarm is to what the person let it do, as facts every
|
|
2
|
+
// agent reads the same (facts.mjs), and a happening when one comes near or is reached. Two limits so far: the runs an
|
|
3
|
+
// agent may start in a day without a Start, under its standing permission (runAuthority.mjs), and what a thread may
|
|
4
|
+
// spend of the person's Harness credits, its ceiling (swarm.mjs). A provider's rate limit waits until a run reports
|
|
5
|
+
// one in a form the daemon can read (owner, November 12). Kept on home, where the board is: a worker reads them from
|
|
6
|
+
// its copy.
|
|
7
|
+
|
|
8
|
+
// Near a limit from four fifths of it on.
|
|
9
|
+
const NEAR = 0.8;
|
|
10
|
+
|
|
11
|
+
const levelOf = (share) =>
|
|
12
|
+
share >= 1 ? "reached" : share >= NEAR ? "near" : "ok";
|
|
13
|
+
const dollars = (usd) => `$${usd.toFixed(2)}`;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* `look()` reads the limits again and keeps the facts; the daemon calls it when the board changes and at each local
|
|
17
|
+
* midnight, when the day's runs start again from none. `standingRules()` are runAuthority.mjs's rules with today's runs.
|
|
18
|
+
*/
|
|
19
|
+
export function createLimits({
|
|
20
|
+
store,
|
|
21
|
+
facts,
|
|
22
|
+
events,
|
|
23
|
+
standingRules,
|
|
24
|
+
isHome = () => true,
|
|
25
|
+
}) {
|
|
26
|
+
/** Writes the fact when it says something new; the log hears when its level changes. */
|
|
27
|
+
const keep = (key, value, text) => {
|
|
28
|
+
const before = facts.get(key)?.value ?? null;
|
|
29
|
+
if (JSON.stringify(before) === JSON.stringify(value)) return;
|
|
30
|
+
facts.set(key, value, { source: "limits" });
|
|
31
|
+
if ((before?.level ?? "ok") !== value.level)
|
|
32
|
+
events.append({
|
|
33
|
+
source: "limits",
|
|
34
|
+
kind: "level",
|
|
35
|
+
subject: key,
|
|
36
|
+
text,
|
|
37
|
+
data: { ...value, was: before?.level ?? null },
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const standing = () => {
|
|
42
|
+
for (const rule of standingRules()) {
|
|
43
|
+
const key = `limits.standing.${rule.agent}`;
|
|
44
|
+
// Only a standing permission the person named has a daily cap (runAuthority.mjs pastLimit).
|
|
45
|
+
if (rule.mode !== "named") {
|
|
46
|
+
if (facts.get(key))
|
|
47
|
+
keep(key, { level: "none" }, `${rule.agent} has no daily cap now`);
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
const cap = Math.max(1, rule.daily_cap);
|
|
51
|
+
const used = rule.runs_today;
|
|
52
|
+
const level = levelOf(used / cap);
|
|
53
|
+
keep(
|
|
54
|
+
key,
|
|
55
|
+
{ used, cap, level },
|
|
56
|
+
level === "reached"
|
|
57
|
+
? `${rule.agent} has started all ${cap} of the runs it may start today without a Start`
|
|
58
|
+
: `${rule.agent} has started ${used} of the ${cap} runs it may start today without a Start`
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const spending = () => {
|
|
64
|
+
for (const thread of store.goals()) {
|
|
65
|
+
const raw = store.meta(`spend-ceiling:${thread.id}`);
|
|
66
|
+
const ceiling = Number(raw);
|
|
67
|
+
if (!raw || !Number.isFinite(ceiling)) continue;
|
|
68
|
+
const spent = store.goalSpend(thread.id).cost_usd;
|
|
69
|
+
const share = ceiling > 0 ? spent / ceiling : 1;
|
|
70
|
+
const level = levelOf(share);
|
|
71
|
+
// Said in tenths of the ceiling, so the fact is not written again at every call that spends.
|
|
72
|
+
const tenths = Math.min(10, Math.floor(share * 10));
|
|
73
|
+
keep(
|
|
74
|
+
`limits.spend.${thread.id}`,
|
|
75
|
+
{ tenths, ceilingUsd: ceiling, level },
|
|
76
|
+
// A thread is named by its number: its title is the person's words, which the log never holds.
|
|
77
|
+
level === "reached"
|
|
78
|
+
? `thread ${thread.id.slice(0, 8)} has spent all it may (${dollars(spent)} of ${dollars(ceiling)})`
|
|
79
|
+
: `thread ${thread.id.slice(0, 8)} has spent ${dollars(spent)} of the ${dollars(ceiling)} it may`
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
look() {
|
|
86
|
+
if (!isHome()) return;
|
|
87
|
+
standing();
|
|
88
|
+
spending();
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
}
|
package/lib/lineDiff.mjs
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// What changed between two texts, line by line, as an agent reads it (senseCall.mjs, tripwires.mjs).
|
|
2
|
+
|
|
3
|
+
// A diff told to an agent is at most this many lines; a longer one says so, and the hold then asks for a read.
|
|
4
|
+
const DIFF_LINES = 40;
|
|
5
|
+
// Past this many lines on both sides, the changed middle is said as replaced, not compared line by line.
|
|
6
|
+
const COMPARED_LINES = 600;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* What changed between two texts, line by line: `{ text, complete, ranges }`. `ranges` are the changed lines in the
|
|
10
|
+
* new text (1-based, inclusive; a removal is the two lines it fell between), `text` a short diff an agent reads.
|
|
11
|
+
*/
|
|
12
|
+
export function diffOf(before, after) {
|
|
13
|
+
const a = before.split("\n");
|
|
14
|
+
const b = after.split("\n");
|
|
15
|
+
let head = 0;
|
|
16
|
+
while (head < a.length && head < b.length && a[head] === b[head]) head++;
|
|
17
|
+
let tail = 0;
|
|
18
|
+
while (
|
|
19
|
+
tail < a.length - head &&
|
|
20
|
+
tail < b.length - head &&
|
|
21
|
+
a[a.length - 1 - tail] === b[b.length - 1 - tail]
|
|
22
|
+
)
|
|
23
|
+
tail++;
|
|
24
|
+
const oldMiddle = a.slice(head, a.length - tail);
|
|
25
|
+
const newMiddle = b.slice(head, b.length - tail);
|
|
26
|
+
const ops =
|
|
27
|
+
oldMiddle.length <= COMPARED_LINES && newMiddle.length <= COMPARED_LINES
|
|
28
|
+
? compared(oldMiddle, newMiddle)
|
|
29
|
+
: [
|
|
30
|
+
...oldMiddle.map((line) => ({ kind: "-", line })),
|
|
31
|
+
...newMiddle.map((line) => ({ kind: "+", line })),
|
|
32
|
+
];
|
|
33
|
+
// Changed lines grouped into hunks, with where each is in the new text.
|
|
34
|
+
const hunks = [];
|
|
35
|
+
let newLine = head + 1;
|
|
36
|
+
let open = null;
|
|
37
|
+
for (const op of ops) {
|
|
38
|
+
if (op.kind === "=") {
|
|
39
|
+
open = null;
|
|
40
|
+
newLine++;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (!open) {
|
|
44
|
+
open = { at: newLine, lines: [], added: 0 };
|
|
45
|
+
hunks.push(open);
|
|
46
|
+
}
|
|
47
|
+
open.lines.push(`${op.kind} ${op.line}`);
|
|
48
|
+
if (op.kind === "+") {
|
|
49
|
+
open.added++;
|
|
50
|
+
newLine++;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const ranges = hunks.map((hunk) =>
|
|
54
|
+
hunk.added
|
|
55
|
+
? { from: hunk.at, to: hunk.at + hunk.added - 1 }
|
|
56
|
+
: { from: hunk.at - 1, to: hunk.at }
|
|
57
|
+
);
|
|
58
|
+
const shown = [];
|
|
59
|
+
let complete = true;
|
|
60
|
+
for (const hunk of hunks) {
|
|
61
|
+
const lines = [`@@ line ${hunk.at} @@`, ...hunk.lines];
|
|
62
|
+
if (shown.length + lines.length > DIFF_LINES) {
|
|
63
|
+
complete = false;
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
shown.push(...lines);
|
|
67
|
+
}
|
|
68
|
+
return { text: shown.join("\n"), complete, ranges };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// The longest common run of lines, as keep, take out and put in.
|
|
72
|
+
function compared(a, b) {
|
|
73
|
+
const rows = a.length + 1;
|
|
74
|
+
const cols = b.length + 1;
|
|
75
|
+
const table = new Uint16Array(rows * cols);
|
|
76
|
+
for (let i = a.length - 1; i >= 0; i--)
|
|
77
|
+
for (let j = b.length - 1; j >= 0; j--)
|
|
78
|
+
table[i * cols + j] =
|
|
79
|
+
a[i] === b[j]
|
|
80
|
+
? table[(i + 1) * cols + j + 1] + 1
|
|
81
|
+
: Math.max(table[(i + 1) * cols + j], table[i * cols + j + 1]);
|
|
82
|
+
const ops = [];
|
|
83
|
+
let i = 0;
|
|
84
|
+
let j = 0;
|
|
85
|
+
while (i < a.length && j < b.length) {
|
|
86
|
+
if (a[i] === b[j]) {
|
|
87
|
+
ops.push({ kind: "=", line: a[i] });
|
|
88
|
+
i++;
|
|
89
|
+
j++;
|
|
90
|
+
} else if (table[(i + 1) * cols + j] >= table[i * cols + j + 1])
|
|
91
|
+
ops.push({ kind: "-", line: a[i++] });
|
|
92
|
+
else ops.push({ kind: "+", line: b[j++] });
|
|
93
|
+
}
|
|
94
|
+
while (i < a.length) ops.push({ kind: "-", line: a[i++] });
|
|
95
|
+
while (j < b.length) ops.push({ kind: "+", line: b[j++] });
|
|
96
|
+
return ops;
|
|
97
|
+
}
|
package/lib/lineup.mjs
CHANGED
|
@@ -4,10 +4,11 @@ import path from "node:path";
|
|
|
4
4
|
import { detectAgents } from "./commands.mjs";
|
|
5
5
|
import { detectLocalAgents, setupHermes, setupOpenClaw } from "./wakes.mjs";
|
|
6
6
|
import { configureAgents } from "./adapters.mjs";
|
|
7
|
+
import { wiringOf } from "./agentWiring.mjs";
|
|
7
8
|
import { confirmAgentBinary } from "./agentBinaries.mjs";
|
|
8
9
|
import { MACHINE_RUNNERS, nameOf } from "./members.mjs";
|
|
9
10
|
import { paths } from "./paths.mjs";
|
|
10
|
-
import { readJson,
|
|
11
|
+
import { readJson, updateJson } from "./files.mjs";
|
|
11
12
|
import { createAgentReadiness, SIGN_IN } from "./readiness.mjs";
|
|
12
13
|
|
|
13
14
|
// The swarm's lineup: the agents the person put in it. Setup offers only the agents installed and signed in on this
|
|
@@ -146,15 +147,16 @@ export function createLineup({ file = paths.config } = {}) {
|
|
|
146
147
|
};
|
|
147
148
|
// `swarmRemoved`: the agents the person took out, which an agent watch (readiness.mjs) never puts back by itself.
|
|
148
149
|
const write = (list, removed) => {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
150
|
+
updateJson(file, (config) => {
|
|
151
|
+
const kept = (removed ?? config.swarmRemoved ?? []).filter(
|
|
152
|
+
(id) => !list.includes(id)
|
|
153
|
+
);
|
|
154
|
+
return {
|
|
155
|
+
...config,
|
|
156
|
+
swarmAgents: [...new Set(list)],
|
|
157
|
+
swarmRemoved: [...new Set(kept)],
|
|
158
|
+
swarmLineup: LINEUP_VERSION,
|
|
159
|
+
};
|
|
158
160
|
});
|
|
159
161
|
cached = { mtimeMs: -1, list: null };
|
|
160
162
|
};
|
|
@@ -263,11 +265,14 @@ export function joinAgent({
|
|
|
263
265
|
ok: false,
|
|
264
266
|
error: `${nameOf(agent)} could not be connected: ${state?.detail ?? "no answer"}`,
|
|
265
267
|
};
|
|
266
|
-
|
|
267
|
-
writeJsonAtomic(file, {
|
|
268
|
+
updateJson(file, (config) => ({
|
|
268
269
|
...config,
|
|
269
270
|
agentStates: { ...config.agentStates, [agent]: state },
|
|
270
|
-
|
|
271
|
+
agentWiring: {
|
|
272
|
+
...config.agentWiring,
|
|
273
|
+
...wiringOf([state], runtimeRoot),
|
|
274
|
+
},
|
|
275
|
+
}));
|
|
271
276
|
// Adding an agent is the person's word on the program it runs as (agentBinaries.mjs).
|
|
272
277
|
confirmAgentBinary(agent, { file });
|
|
273
278
|
} else {
|