tryharness 0.7.45 → 0.7.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +239 -14
- package/assets/dsh-plugin.mjs +72 -0
- package/assets/opencode-plugin.js +4 -3
- package/cli.mjs +497 -196
- package/lib/actorRoster.mjs +28 -5
- package/lib/adapters.mjs +165 -222
- package/lib/agentRuntimeConfig.mjs +36 -0
- package/lib/agentRuntimes.mjs +570 -0
- package/lib/agentSignIn.mjs +226 -0
- package/lib/atlas.mjs +7 -2
- package/lib/audit.mjs +643 -0
- package/lib/backupSetup.mjs +141 -0
- package/lib/boardAccess.mjs +8 -1
- package/lib/boardBackup.mjs +283 -0
- package/lib/boardCommands.mjs +5 -10
- package/lib/boardFileCommands.mjs +2 -1
- package/lib/boardMirror.mjs +523 -0
- package/lib/boardProtocol.json +263 -6
- package/lib/boardTools.mjs +2 -6
- package/lib/boardWaits.mjs +102 -0
- package/lib/book.mjs +659 -0
- package/lib/bridge.mjs +26 -4
- package/lib/browserWake.mjs +60 -0
- package/lib/cards.mjs +159 -16
- package/lib/cloudBoot.mjs +124 -0
- package/lib/commands.mjs +25 -5
- package/lib/connectionTools.d.ts +13 -0
- package/lib/connectionTools.js +45 -0
- package/lib/connectorAuth.mjs +309 -0
- package/lib/connectorCatalog.json +41 -0
- package/lib/connectorCommands.mjs +121 -0
- package/lib/connectorGoogle.mjs +513 -0
- package/lib/connectors.mjs +805 -0
- package/lib/context.mjs +18 -4
- package/lib/contractGate.mjs +377 -0
- package/lib/coordinator.mjs +152 -39
- package/lib/coreModels.mjs +78 -0
- package/lib/daemon.mjs +973 -54
- package/lib/desk.mjs +239 -0
- package/lib/desktop.mjs +113 -8
- package/lib/digest.mjs +32 -0
- package/lib/directLink.mjs +283 -0
- package/lib/environments.mjs +825 -0
- package/lib/folders.mjs +4 -4
- package/lib/gitHost.mjs +174 -0
- package/lib/goalCommands.mjs +58 -14
- package/lib/hookDialects.mjs +298 -0
- package/lib/inference.mjs +263 -152
- package/lib/landed.mjs +887 -0
- package/lib/lessons.mjs +6 -0
- package/lib/lineup.mjs +324 -0
- package/lib/live.mjs +284 -13
- package/lib/localmodels.mjs +10 -0
- package/lib/machineIdentity.mjs +3 -0
- package/lib/machineRoutes.mjs +40 -2
- package/lib/machineRuns.mjs +30 -3
- package/lib/machineSeal.mjs +69 -10
- package/lib/mcp-stdio.mjs +189 -120
- package/lib/mcpRelay.mjs +119 -0
- package/lib/members.json +26 -0
- package/lib/members.mjs +33 -0
- package/lib/modelMemory.mjs +100 -0
- package/lib/models.mjs +48 -15
- package/lib/museSession.mjs +122 -0
- package/lib/nativeHost.mjs +203 -0
- package/lib/neovim.mjs +126 -0
- package/lib/network.mjs +7 -2
- package/lib/nudge.mjs +57 -18
- package/lib/onboard.mjs +430 -1
- package/lib/oneclawLocal.mjs +150 -0
- package/lib/ownMachines.mjs +828 -39
- package/lib/pairing.mjs +182 -0
- package/lib/paths.mjs +8 -0
- package/lib/personModel.mjs +89 -0
- package/lib/phones.mjs +119 -3
- package/lib/placeCommands.mjs +27 -0
- package/lib/places.mjs +337 -9
- package/lib/plans.mjs +151 -27
- package/lib/profile.mjs +152 -0
- package/lib/projects.mjs +624 -137
- package/lib/readiness.mjs +400 -0
- package/lib/record.mjs +115 -0
- package/lib/repoLinks.mjs +354 -0
- package/lib/roomChannels.mjs +641 -0
- package/lib/runBrief.mjs +32 -2
- package/lib/runRequests.mjs +157 -0
- package/lib/runWorker.mjs +37 -9
- package/lib/runner.mjs +74 -11
- package/lib/secretPatterns.json +55 -0
- package/lib/secrets.mjs +10 -27
- package/lib/seen.mjs +102 -0
- package/lib/service.mjs +11 -6
- package/lib/sessionControl.mjs +386 -96
- package/lib/sessionIndex.mjs +5 -3
- package/lib/specialties.json +74 -0
- package/lib/specialties.mjs +477 -0
- package/lib/specialtyKeys.d.ts +3 -0
- package/lib/specialtyKeys.js +58 -0
- package/lib/specialtyNotice.mjs +147 -0
- package/lib/specialtySnapshot.mjs +138 -0
- package/lib/store.mjs +829 -29
- package/lib/subagents.mjs +8 -4
- package/lib/swarm.mjs +483 -37
- package/lib/swarmMemory.mjs +947 -0
- package/lib/t3.mjs +56 -17
- package/lib/taskCommands.mjs +91 -13
- package/lib/taskRuns.mjs +68 -11
- package/lib/team.json +253 -144
- package/lib/team.mjs +538 -147
- package/lib/threadLine.mjs +116 -0
- package/lib/threadRuns.mjs +78 -12
- package/lib/threadView.mjs +66 -16
- package/lib/tokenizer.mjs +405 -0
- package/lib/ui.mjs +16 -2
- package/lib/usageTotals.mjs +148 -0
- package/lib/vault.mjs +1144 -0
- package/lib/vaultCloud.mjs +117 -0
- package/lib/vaultCommands.mjs +201 -0
- package/lib/vaultTools.d.ts +12 -0
- package/lib/vaultTools.js +42 -0
- package/lib/windowAsks.mjs +42 -0
- package/lib/workFocus.mjs +59 -0
- package/lib/workLinks.mjs +90 -0
- package/lib/worktrees.mjs +51 -13
- package/package.json +10 -5
package/lib/plans.mjs
CHANGED
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
// The person wires nodes on the buddy's canvas; agents do it with post_task's `after`; a template is the same nodes
|
|
6
6
|
// and wires as JSON, with {{blanks}} filled in when it is used. A node can only wait on work that exists or on nodes
|
|
7
7
|
// given with it, so no wiring can loop.
|
|
8
|
+
// The person's drafts are plan nodes too, kept here so every device that shows the thread (the buddy, the phone) sees
|
|
9
|
+
// and edits the same ones: a draft's agent, prompt and wiring can change, and nothing of it starts until the person
|
|
10
|
+
// runs it, when it waits like any other node.
|
|
8
11
|
import fs from "node:fs";
|
|
9
12
|
import path from "node:path";
|
|
10
13
|
import { randomUUID } from "node:crypto";
|
|
@@ -31,6 +34,20 @@ const blanksIn = (texts) => [
|
|
|
31
34
|
),
|
|
32
35
|
];
|
|
33
36
|
|
|
37
|
+
/** What a node is asked, from its prompt: the first line is its objective, a longer prompt is its brief. */
|
|
38
|
+
function askOf(node, key) {
|
|
39
|
+
const objective = words(node?.objective || node?.prompt)
|
|
40
|
+
.split("\n")[0]
|
|
41
|
+
.slice(0, 500);
|
|
42
|
+
const brief = words(
|
|
43
|
+
node?.brief ?? (words(node?.prompt).includes("\n") ? node.prompt : "")
|
|
44
|
+
);
|
|
45
|
+
if (!objective) return { error: `node ${key} asks nothing` };
|
|
46
|
+
if ((objective + brief).length > PROMPT_LIMIT)
|
|
47
|
+
return { error: `node ${key}'s prompt is over ${PROMPT_LIMIT} characters` };
|
|
48
|
+
return { objective, brief };
|
|
49
|
+
}
|
|
50
|
+
|
|
34
51
|
/** Nodes in an order where each comes after everything it waits on, or null when the wiring loops. */
|
|
35
52
|
function ordered(nodes, waitsOn) {
|
|
36
53
|
const byKey = new Map(nodes.map((node) => [node.key, node]));
|
|
@@ -252,10 +269,15 @@ export function createPlans({
|
|
|
252
269
|
return plan;
|
|
253
270
|
}
|
|
254
271
|
|
|
255
|
-
/**
|
|
256
|
-
|
|
272
|
+
/**
|
|
273
|
+
* Adds nodes to a thread's plan; those waiting on nothing (or only on finished work) start at once. As drafts they
|
|
274
|
+
* start only when the person runs them.
|
|
275
|
+
*/
|
|
276
|
+
function add(threadId, by, given, { draft = false } = {}) {
|
|
257
277
|
const thread = threadOf(threadId);
|
|
258
278
|
if (!thread) return { ok: false, error: "thread not found" };
|
|
279
|
+
if (draft && by !== "user")
|
|
280
|
+
return { ok: false, error: "only the person keeps drafts" };
|
|
259
281
|
if (!Array.isArray(given) || !given.length)
|
|
260
282
|
return { ok: false, error: "no nodes to add" };
|
|
261
283
|
const plan = planOf(thread.id);
|
|
@@ -274,23 +296,13 @@ export function createPlans({
|
|
|
274
296
|
ok: false,
|
|
275
297
|
error: `${agent || "no one"} cannot be in a thread`,
|
|
276
298
|
};
|
|
277
|
-
const
|
|
278
|
-
|
|
279
|
-
.slice(0, 500);
|
|
280
|
-
const brief = words(
|
|
281
|
-
node?.brief ?? (words(node?.prompt).includes("\n") ? node.prompt : "")
|
|
282
|
-
);
|
|
283
|
-
if (!objective) return { ok: false, error: `node ${key} asks nothing` };
|
|
284
|
-
if ((objective + brief).length > PROMPT_LIMIT)
|
|
285
|
-
return {
|
|
286
|
-
ok: false,
|
|
287
|
-
error: `node ${key}'s prompt is over ${PROMPT_LIMIT} characters`,
|
|
288
|
-
};
|
|
299
|
+
const asked = askOf(node, key);
|
|
300
|
+
if (asked.error) return { ok: false, error: asked.error };
|
|
289
301
|
nodes.push({
|
|
290
302
|
key,
|
|
291
303
|
agent,
|
|
292
|
-
objective,
|
|
293
|
-
brief,
|
|
304
|
+
objective: asked.objective,
|
|
305
|
+
brief: asked.brief,
|
|
294
306
|
after: Array.isArray(node?.after) ? node.after.map(String) : [],
|
|
295
307
|
});
|
|
296
308
|
}
|
|
@@ -319,17 +331,20 @@ export function createPlans({
|
|
|
319
331
|
objective: node.objective,
|
|
320
332
|
brief: node.brief,
|
|
321
333
|
after: node.after.map((ref) => ids.get(ref) ?? ref),
|
|
322
|
-
state: "waiting",
|
|
334
|
+
state: draft ? "draft" : "waiting",
|
|
323
335
|
at,
|
|
324
336
|
});
|
|
325
337
|
savePlan(thread.id, plan);
|
|
326
|
-
|
|
338
|
+
return outcome(thread.id, ids);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/** What became of nodes just added or run: the tasks that started, the nodes still waiting or kept as drafts. */
|
|
342
|
+
function outcome(threadId, ids) {
|
|
343
|
+
const settled = settle(threadId);
|
|
327
344
|
const mine = settled.filter((node) => [...ids.values()].includes(node.id));
|
|
328
345
|
return {
|
|
329
346
|
ok: true,
|
|
330
|
-
nodes: Object.fromEntries(
|
|
331
|
-
nodes.map((node) => [node.key, ids.get(node.key)])
|
|
332
|
-
),
|
|
347
|
+
nodes: Object.fromEntries(ids),
|
|
333
348
|
started: mine.filter((node) => node.taskId).map((node) => node.taskId),
|
|
334
349
|
waiting: mine
|
|
335
350
|
.filter((node) => node.state === "waiting")
|
|
@@ -337,9 +352,97 @@ export function createPlans({
|
|
|
337
352
|
blocked: mine
|
|
338
353
|
.filter((node) => node.state === "blocked")
|
|
339
354
|
.map((node) => ({ id: node.id, reason: node.reason })),
|
|
355
|
+
drafts: mine
|
|
356
|
+
.filter((node) => node.state === "draft")
|
|
357
|
+
.map((node) => node.id),
|
|
340
358
|
};
|
|
341
359
|
}
|
|
342
360
|
|
|
361
|
+
/** Whether `ref` is something a node in this thread may wait on: another plan node, or a task in the thread. */
|
|
362
|
+
const waitable = (threadId, plan, ref) =>
|
|
363
|
+
plan.some((other) => other.id === ref) ||
|
|
364
|
+
store.getTask(ref)?.parent_id === threadId;
|
|
365
|
+
const loops = (plan) => {
|
|
366
|
+
const ids = new Set(plan.map((node) => node.id));
|
|
367
|
+
return !ordered(
|
|
368
|
+
plan.map((node) => ({ key: node.id, after: node.after })),
|
|
369
|
+
(node) => node.after.filter((ref) => ids.has(ref))
|
|
370
|
+
);
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
/** A draft's agent, prompt or wiring (`change`), changed by the person. */
|
|
374
|
+
function edit(threadId, nodeId, change) {
|
|
375
|
+
const thread = threadOf(threadId);
|
|
376
|
+
if (!thread) return { ok: false, error: "thread not found" };
|
|
377
|
+
const plan = planOf(thread.id);
|
|
378
|
+
const node = plan.find((n) => n.id === String(nodeId || ""));
|
|
379
|
+
if (!node) return { ok: false, error: "no such step" };
|
|
380
|
+
if (node.state !== "draft")
|
|
381
|
+
return { ok: false, error: "only a draft can change" };
|
|
382
|
+
const next = { ...node };
|
|
383
|
+
if (change.agent !== undefined) {
|
|
384
|
+
const agent = words(change.agent);
|
|
385
|
+
if (!roomAgents.includes(agent))
|
|
386
|
+
return {
|
|
387
|
+
ok: false,
|
|
388
|
+
error: `${agent || "no one"} cannot be in a thread`,
|
|
389
|
+
};
|
|
390
|
+
next.agent = agent;
|
|
391
|
+
}
|
|
392
|
+
if (change.prompt !== undefined) {
|
|
393
|
+
const asked = askOf({ prompt: change.prompt }, node.key);
|
|
394
|
+
if (asked.error) return { ok: false, error: asked.error };
|
|
395
|
+
next.objective = asked.objective;
|
|
396
|
+
next.brief = asked.brief;
|
|
397
|
+
}
|
|
398
|
+
if (change.after !== undefined) {
|
|
399
|
+
if (!Array.isArray(change.after))
|
|
400
|
+
return { ok: false, error: "after is a list" };
|
|
401
|
+
const after = [...new Set(change.after.map(String))];
|
|
402
|
+
for (const ref of after) {
|
|
403
|
+
if (ref === node.id)
|
|
404
|
+
return { ok: false, error: "a step cannot wait for itself" };
|
|
405
|
+
if (!waitable(thread.id, plan, ref))
|
|
406
|
+
return { ok: false, error: `${ref} is not work in this thread` };
|
|
407
|
+
}
|
|
408
|
+
next.after = after;
|
|
409
|
+
}
|
|
410
|
+
const changed = plan.map((n) => (n.id === node.id ? next : n));
|
|
411
|
+
if (loops(changed))
|
|
412
|
+
return { ok: false, error: "the wires go round in a loop" };
|
|
413
|
+
savePlan(thread.id, changed);
|
|
414
|
+
return { ok: true };
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/** The person's drafts set going: the ones named (all of them when none are) and every draft they wait for. */
|
|
418
|
+
function run(threadId, named) {
|
|
419
|
+
const thread = threadOf(threadId);
|
|
420
|
+
if (!thread) return { ok: false, error: "thread not found" };
|
|
421
|
+
const plan = planOf(thread.id);
|
|
422
|
+
const drafts = plan.filter((node) => node.state === "draft");
|
|
423
|
+
const wanted = Array.isArray(named) ? named.map(String) : null;
|
|
424
|
+
if (wanted?.some((id) => !drafts.some((node) => node.id === id)))
|
|
425
|
+
return { ok: false, error: "that is not a draft here" };
|
|
426
|
+
const chosen = new Set();
|
|
427
|
+
const visit = (node) => {
|
|
428
|
+
if (chosen.has(node)) return;
|
|
429
|
+
chosen.add(node);
|
|
430
|
+
for (const ref of node.after) {
|
|
431
|
+
const up = drafts.find((other) => other.id === ref);
|
|
432
|
+
if (up) visit(up);
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
for (const node of drafts)
|
|
436
|
+
if (!wanted || wanted.includes(node.id)) visit(node);
|
|
437
|
+
if (!chosen.size) return { ok: false, error: "no drafts to run" };
|
|
438
|
+
for (const node of chosen) node.state = "waiting";
|
|
439
|
+
savePlan(thread.id, plan);
|
|
440
|
+
return outcome(
|
|
441
|
+
thread.id,
|
|
442
|
+
new Map([...chosen].map((node) => [node.id, node.id]))
|
|
443
|
+
);
|
|
444
|
+
}
|
|
445
|
+
|
|
343
446
|
// ── Templates, kept with the daemon so agents can use them too ────────────────
|
|
344
447
|
const templateFile = (name) => path.join(folder, `${slugOf(name)}.json`);
|
|
345
448
|
function templates() {
|
|
@@ -377,7 +480,7 @@ export function createPlans({
|
|
|
377
480
|
};
|
|
378
481
|
|
|
379
482
|
/** Puts a template's nodes into a thread, its blanks filled; the nodes with nothing wired into them start now. */
|
|
380
|
-
function fromTemplate(threadId, by, checked, values = {}) {
|
|
483
|
+
function fromTemplate(threadId, by, checked, values = {}, options = {}) {
|
|
381
484
|
const empty = checked.blanks.filter((name) => !words(values[name]));
|
|
382
485
|
if (empty.length)
|
|
383
486
|
return {
|
|
@@ -400,7 +503,8 @@ export function createPlans({
|
|
|
400
503
|
after: checked.template.wires
|
|
401
504
|
.filter((w) => w.to === node.key)
|
|
402
505
|
.map((w) => w.from),
|
|
403
|
-
}))
|
|
506
|
+
})),
|
|
507
|
+
options
|
|
404
508
|
);
|
|
405
509
|
}
|
|
406
510
|
|
|
@@ -419,6 +523,7 @@ export function createPlans({
|
|
|
419
523
|
by,
|
|
420
524
|
agent,
|
|
421
525
|
objective,
|
|
526
|
+
brief,
|
|
422
527
|
after,
|
|
423
528
|
state,
|
|
424
529
|
reason,
|
|
@@ -430,6 +535,8 @@ export function createPlans({
|
|
|
430
535
|
by,
|
|
431
536
|
agent,
|
|
432
537
|
objective,
|
|
538
|
+
// A draft's whole prompt, so whoever edits it starts from what was written.
|
|
539
|
+
...(state === "draft" ? { prompt: brief || objective } : {}),
|
|
433
540
|
after,
|
|
434
541
|
state,
|
|
435
542
|
reason: reason ?? null,
|
|
@@ -453,7 +560,16 @@ export function createPlans({
|
|
|
453
560
|
command(request, agent) {
|
|
454
561
|
const command = String(request.command);
|
|
455
562
|
if (command === "board.plan.add")
|
|
456
|
-
return add(request.id, agent, request.nodes
|
|
563
|
+
return add(request.id, agent, request.nodes, {
|
|
564
|
+
draft: request.draft === true,
|
|
565
|
+
});
|
|
566
|
+
if (command === "board.plan.edit")
|
|
567
|
+
return (
|
|
568
|
+
personOnly(agent) ??
|
|
569
|
+
edit(request.id, request.node, request.change ?? {})
|
|
570
|
+
);
|
|
571
|
+
if (command === "board.plan.run")
|
|
572
|
+
return personOnly(agent) ?? run(request.id, request.nodes);
|
|
457
573
|
if (command === "board.plan.remove") {
|
|
458
574
|
const refused = personOnly(agent);
|
|
459
575
|
if (refused) return refused;
|
|
@@ -465,8 +581,9 @@ export function createPlans({
|
|
|
465
581
|
ok: false,
|
|
466
582
|
error: "that step has started; stop it in the thread",
|
|
467
583
|
};
|
|
584
|
+
// Drafts wired to it are only drafts: they lose the wire. A step already set going would wait forever.
|
|
468
585
|
const waiting = plan.filter(
|
|
469
|
-
(n) => n.after.includes(node.id) && !n.taskId
|
|
586
|
+
(n) => n.after.includes(node.id) && !n.taskId && n.state !== "draft"
|
|
470
587
|
);
|
|
471
588
|
if (waiting.length)
|
|
472
589
|
return {
|
|
@@ -475,7 +592,13 @@ export function createPlans({
|
|
|
475
592
|
};
|
|
476
593
|
savePlan(
|
|
477
594
|
String(request.id),
|
|
478
|
-
plan
|
|
595
|
+
plan
|
|
596
|
+
.filter((n) => n.id !== node.id)
|
|
597
|
+
.map((n) =>
|
|
598
|
+
n.state === "draft"
|
|
599
|
+
? { ...n, after: n.after.filter((ref) => ref !== node.id) }
|
|
600
|
+
: n
|
|
601
|
+
)
|
|
479
602
|
);
|
|
480
603
|
return { ok: true };
|
|
481
604
|
}
|
|
@@ -530,7 +653,8 @@ export function createPlans({
|
|
|
530
653
|
request.id,
|
|
531
654
|
agent,
|
|
532
655
|
checked,
|
|
533
|
-
request.fill && typeof request.fill === "object" ? request.fill : {}
|
|
656
|
+
request.fill && typeof request.fill === "object" ? request.fill : {},
|
|
657
|
+
{ draft: request.draft === true }
|
|
534
658
|
);
|
|
535
659
|
}
|
|
536
660
|
return { ok: false, error: `unknown command ${command}` };
|
package/lib/profile.mjs
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import pc from "picocolors";
|
|
3
|
+
import { readJson, writeJsonAtomic } from "./files.mjs";
|
|
4
|
+
import { paths } from "./paths.mjs";
|
|
5
|
+
|
|
6
|
+
// The person's Harness profile on this computer: their name and how they like to work, so every agent here knows who
|
|
7
|
+
// it works for. The profile is the account's, one for all their computers: Harness sends it to the daemon when it
|
|
8
|
+
// connects and whenever it changes anywhere (src/server/bridge/profilePush.ts), and the daemon keeps it here. Setup
|
|
9
|
+
// imports it too, and when the account has no name yet, asks for one and saves it to the account. Each run's brief
|
|
10
|
+
// carries it (runBrief.mjs). The saved copy holds only what the server shares with a computer.
|
|
11
|
+
|
|
12
|
+
const NAME_LIMIT = 80;
|
|
13
|
+
const PREFERENCE_LIMIT = 200;
|
|
14
|
+
|
|
15
|
+
/** The account's profile as this computer last had it, or null. */
|
|
16
|
+
export function readProfile(file = paths.profile) {
|
|
17
|
+
const saved = readJson(file, null);
|
|
18
|
+
return saved?.displayName ? saved : null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Keeps the account's profile as Harness sent it; one without a name leaves this computer with none. */
|
|
22
|
+
export function keepProfile(profile, file = paths.profile) {
|
|
23
|
+
if (profile?.displayName) writeJsonAtomic(file, profile);
|
|
24
|
+
else fs.rmSync(file, { force: true });
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function request(origin, token, init = {}) {
|
|
28
|
+
const response = await fetch(
|
|
29
|
+
`${String(origin).replace(/\/$/, "")}/api/mcp/profile`,
|
|
30
|
+
{
|
|
31
|
+
...init,
|
|
32
|
+
headers: {
|
|
33
|
+
authorization: `Bearer ${token}`,
|
|
34
|
+
"content-type": "application/json",
|
|
35
|
+
},
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
const body = await response.json().catch(() => null);
|
|
39
|
+
if (!response.ok)
|
|
40
|
+
throw Object.assign(
|
|
41
|
+
new Error(body?.error || `Harness answered ${response.status}`),
|
|
42
|
+
{ status: response.status }
|
|
43
|
+
);
|
|
44
|
+
return body?.profile ?? {};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const preferenceCount = (profile) =>
|
|
48
|
+
(profile.hardPreferences?.length ?? 0) +
|
|
49
|
+
(profile.softPreferences?.length ?? 0);
|
|
50
|
+
|
|
51
|
+
const plural = (count, word) => `${count} ${word}${count === 1 ? "" : "s"}`;
|
|
52
|
+
|
|
53
|
+
async function ask(ui, profile) {
|
|
54
|
+
ui.note(
|
|
55
|
+
"Your agents work for you, so they should know who you are. What you write here is saved to your Harness account, so Harness and the agents on all your computers use it. Change it any time in Harness, Settings, Profile.",
|
|
56
|
+
"About you"
|
|
57
|
+
);
|
|
58
|
+
const name = await ui.text({
|
|
59
|
+
message: "What should your agents call you?",
|
|
60
|
+
validate: (value) =>
|
|
61
|
+
String(value ?? "").trim().length > NAME_LIMIT
|
|
62
|
+
? `Keep it under ${NAME_LIMIT} characters`
|
|
63
|
+
: undefined,
|
|
64
|
+
});
|
|
65
|
+
const displayName = String(name ?? "").trim();
|
|
66
|
+
if (!displayName) return null;
|
|
67
|
+
const update = { displayName };
|
|
68
|
+
if (!preferenceCount(profile)) {
|
|
69
|
+
const said = await ui.text({
|
|
70
|
+
message:
|
|
71
|
+
"Anything they should always keep in mind about how you work? Press Enter to skip.",
|
|
72
|
+
placeholder: "Keep answers short, and ask before deleting anything",
|
|
73
|
+
validate: (value) =>
|
|
74
|
+
String(value ?? "").trim().length > PREFERENCE_LIMIT
|
|
75
|
+
? `Keep it under ${PREFERENCE_LIMIT} characters`
|
|
76
|
+
: undefined,
|
|
77
|
+
});
|
|
78
|
+
const preference = String(said ?? "").trim();
|
|
79
|
+
if (preference) update.hardPreferences = [preference];
|
|
80
|
+
}
|
|
81
|
+
return update;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Setup's step: imports the person's profile into this computer, asking for their name (and one preference, when they
|
|
86
|
+
* have none) if their account has no name yet. Never stops setup: a profile Harness cannot give leaves the last import.
|
|
87
|
+
*/
|
|
88
|
+
export async function setupProfile({
|
|
89
|
+
ui,
|
|
90
|
+
origin,
|
|
91
|
+
token,
|
|
92
|
+
file = paths.profile,
|
|
93
|
+
}) {
|
|
94
|
+
let profile;
|
|
95
|
+
try {
|
|
96
|
+
profile = await request(origin, token);
|
|
97
|
+
} catch (error) {
|
|
98
|
+
// A Harness from before profiles reached computers has no such page: nothing is wrong, so nothing is said.
|
|
99
|
+
if (error.status === 404) return readProfile(file);
|
|
100
|
+
ui.warn(
|
|
101
|
+
`Your Harness profile did not load (${error.message}). Your agents will learn your name the next time you run setup.`
|
|
102
|
+
);
|
|
103
|
+
return readProfile(file);
|
|
104
|
+
}
|
|
105
|
+
if (!profile.displayName) {
|
|
106
|
+
const update = ui.interactive ? await ask(ui, profile) : null;
|
|
107
|
+
if (!update) {
|
|
108
|
+
ui.info(
|
|
109
|
+
"Your agents will not know your name yet. Add it any time in Harness, Settings, Profile, then run setup again."
|
|
110
|
+
);
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
try {
|
|
114
|
+
profile = await request(origin, token, {
|
|
115
|
+
method: "PUT",
|
|
116
|
+
body: JSON.stringify(update),
|
|
117
|
+
});
|
|
118
|
+
} catch (error) {
|
|
119
|
+
// The agents here still get it; the next setup, finding no name in the account, asks again.
|
|
120
|
+
profile = { ...profile, ...update };
|
|
121
|
+
ui.warn(
|
|
122
|
+
`Saved on this computer, but not to your Harness account yet (${error.message}).`
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
writeJsonAtomic(file, profile);
|
|
127
|
+
const count = preferenceCount(profile);
|
|
128
|
+
ui.success(
|
|
129
|
+
`Your agents know you as ${pc.bold(profile.displayName)}${count ? `, with your ${plural(count, "preference")} from Harness` : ""}`
|
|
130
|
+
);
|
|
131
|
+
return profile;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** The profile as an agent is told it at the start of a run; empty without one. */
|
|
135
|
+
export function profileBrief(profile = readProfile()) {
|
|
136
|
+
if (!profile?.displayName) return "";
|
|
137
|
+
const lines = [
|
|
138
|
+
`You are working for ${profile.displayName}${profile.role ? `, ${profile.role}` : ""}. From their Harness profile:`,
|
|
139
|
+
];
|
|
140
|
+
if (profile.communicationStyle)
|
|
141
|
+
lines.push(`- They prefer ${profile.communicationStyle} communication.`);
|
|
142
|
+
const hard = profile.hardPreferences ?? [];
|
|
143
|
+
const soft = profile.softPreferences ?? [];
|
|
144
|
+
if (hard.length)
|
|
145
|
+
lines.push("Always follow:", ...hard.map((item) => `- ${item}`));
|
|
146
|
+
if (soft.length)
|
|
147
|
+
lines.push(
|
|
148
|
+
"When in doubt, they prefer:",
|
|
149
|
+
...soft.map((item) => `- ${item}`)
|
|
150
|
+
);
|
|
151
|
+
return lines.join("\n");
|
|
152
|
+
}
|