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
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// The 1claw API, as the relay's vault uses it for the person's backup (vault.mjs). Shapes from @1claw/openapi-spec
|
|
2
|
+
// 0.61.76 and the 1claw CLI's own sign-in and provisioning (src/auth.ts loginWithDevice, src/lib/provisioning.ts).
|
|
3
|
+
// No request here has a deadline of its own: none of these endpoints has been measured (AGENTS.md), so a call lasts
|
|
4
|
+
// until 1claw answers or the caller gives up.
|
|
5
|
+
|
|
6
|
+
export const ONECLAW_API = "https://api.1claw.co";
|
|
7
|
+
|
|
8
|
+
/** An answer from 1claw that is not a success, with what 1claw said. */
|
|
9
|
+
export class OneclawError extends Error {
|
|
10
|
+
constructor(status, detail, type) {
|
|
11
|
+
super(detail || `1claw answered ${status}`);
|
|
12
|
+
this.status = status;
|
|
13
|
+
this.type = type ?? null;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function createOneclawCloud({
|
|
18
|
+
base = ONECLAW_API,
|
|
19
|
+
fetch = globalThis.fetch,
|
|
20
|
+
} = {}) {
|
|
21
|
+
const root = base.replace(/\/+$/, "");
|
|
22
|
+
const call = async (method, path, { token, body } = {}) => {
|
|
23
|
+
const response = await fetch(`${root}/v1${path}`, {
|
|
24
|
+
method,
|
|
25
|
+
headers: {
|
|
26
|
+
...(body === undefined ? {} : { "content-type": "application/json" }),
|
|
27
|
+
...(token ? { authorization: `Bearer ${token}` } : {}),
|
|
28
|
+
},
|
|
29
|
+
...(body === undefined ? {} : { body: JSON.stringify(body) }),
|
|
30
|
+
});
|
|
31
|
+
const text = await response.text();
|
|
32
|
+
let value = null;
|
|
33
|
+
try {
|
|
34
|
+
value = text ? JSON.parse(text) : null;
|
|
35
|
+
} catch {}
|
|
36
|
+
if (!response.ok)
|
|
37
|
+
throw new OneclawError(
|
|
38
|
+
response.status,
|
|
39
|
+
value?.detail ?? value?.error ?? value?.message ?? text.slice(0, 200),
|
|
40
|
+
value?.type
|
|
41
|
+
);
|
|
42
|
+
return value;
|
|
43
|
+
};
|
|
44
|
+
const secretPath = (path) =>
|
|
45
|
+
path.split("/").map(encodeURIComponent).join("/");
|
|
46
|
+
// A signed-in person (the device flow's token) or this computer's agent (its exchanged token).
|
|
47
|
+
const as = (token) => ({
|
|
48
|
+
vaults: async () => (await call("GET", "/vaults", { token }))?.vaults ?? [],
|
|
49
|
+
createVault: (name, description) =>
|
|
50
|
+
call("POST", "/vaults", { token, body: { name, description } }),
|
|
51
|
+
agents: async () => (await call("GET", "/agents", { token }))?.agents ?? [],
|
|
52
|
+
createAgent: (name, description) =>
|
|
53
|
+
call("POST", "/agents", {
|
|
54
|
+
token,
|
|
55
|
+
body: {
|
|
56
|
+
name,
|
|
57
|
+
description,
|
|
58
|
+
auth_method: "api_key",
|
|
59
|
+
skip_default_policy: true,
|
|
60
|
+
},
|
|
61
|
+
}),
|
|
62
|
+
rotateKey: (agentId) =>
|
|
63
|
+
call("POST", `/agents/${agentId}/rotate-key`, { token }),
|
|
64
|
+
bindVault: (agentId, vaultId) =>
|
|
65
|
+
call("PATCH", `/agents/${agentId}`, {
|
|
66
|
+
token,
|
|
67
|
+
body: { vault_ids: [vaultId] },
|
|
68
|
+
}),
|
|
69
|
+
grantAgent: (vaultId, agentId) =>
|
|
70
|
+
call("POST", `/vaults/${vaultId}/policies`, {
|
|
71
|
+
token,
|
|
72
|
+
body: {
|
|
73
|
+
secret_path_pattern: "**",
|
|
74
|
+
principal_type: "agent",
|
|
75
|
+
principal_id: agentId,
|
|
76
|
+
permissions: ["read", "write", "delete"],
|
|
77
|
+
},
|
|
78
|
+
}),
|
|
79
|
+
secrets: async (vaultId) =>
|
|
80
|
+
(await call("GET", `/vaults/${vaultId}/secrets`, { token }))?.secrets ??
|
|
81
|
+
[],
|
|
82
|
+
secret: (vaultId, path) =>
|
|
83
|
+
call("GET", `/vaults/${vaultId}/secrets/${secretPath(path)}`, { token }),
|
|
84
|
+
putSecret: (vaultId, path, body) =>
|
|
85
|
+
call("PUT", `/vaults/${vaultId}/secrets/${secretPath(path)}`, {
|
|
86
|
+
token,
|
|
87
|
+
body,
|
|
88
|
+
}),
|
|
89
|
+
deleteSecret: (vaultId, path) =>
|
|
90
|
+
call("DELETE", `/vaults/${vaultId}/secrets/${secretPath(path)}`, {
|
|
91
|
+
token,
|
|
92
|
+
}),
|
|
93
|
+
share: (secretId, body) =>
|
|
94
|
+
call("POST", `/secrets/${secretId}/share`, { token, body }),
|
|
95
|
+
unshare: (shareId) => call("DELETE", `/share/${shareId}`, { token }),
|
|
96
|
+
});
|
|
97
|
+
return {
|
|
98
|
+
base: root,
|
|
99
|
+
// Where the person approves a sign-in code: the dashboard beside the API (api.1claw.co → 1claw.co).
|
|
100
|
+
verifyUrl: (code) =>
|
|
101
|
+
`${root.replace("://api.", "://")}/cli/verify?code=${encodeURIComponent(code)}`,
|
|
102
|
+
deviceCode: (email) =>
|
|
103
|
+
call("POST", "/auth/device/code", {
|
|
104
|
+
body: { client_id: "harness", email },
|
|
105
|
+
}),
|
|
106
|
+
deviceToken: (deviceCode) =>
|
|
107
|
+
call("POST", "/auth/device/token", {
|
|
108
|
+
body: {
|
|
109
|
+
device_code: deviceCode,
|
|
110
|
+
grant_type: "urn:ietf:params:oauth:grant-type:device_code",
|
|
111
|
+
},
|
|
112
|
+
}),
|
|
113
|
+
agentToken: (apiKey) =>
|
|
114
|
+
call("POST", "/auth/agent-token", { body: { api_key: apiKey } }),
|
|
115
|
+
as,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { daemonRequest } from "./control-client.mjs";
|
|
2
|
+
|
|
3
|
+
// `npx tryharness vault`: the person's vault in this computer's relay (vault.mjs), from the terminal. A value is
|
|
4
|
+
// typed at a hidden prompt, piped in, or named by an environment variable; never written on the command line, where
|
|
5
|
+
// the shell's history would keep it.
|
|
6
|
+
|
|
7
|
+
const USAGE = `vault what is kept, who is asking, who may use what, and the backup
|
|
8
|
+
vault add <name> --hosts api.fly.io[,...] [--value-env NAME] keep a secret (typed hidden, piped, or from NAME)
|
|
9
|
+
vault hosts <name> <host,...> change where it may be sent
|
|
10
|
+
vault remove <name>
|
|
11
|
+
vault allow <agent> <name> let an agent use it (the relay sends it; the agent never sees it)
|
|
12
|
+
vault runs <agent> <name> <VARIABLE> [--elsewhere] put it in the agent's runs (it can read it there)
|
|
13
|
+
vault revoke <grant id>
|
|
14
|
+
vault backup <email> [--bring-in] keep a copy in your 1claw account (the email you sign in with; a new one makes an account)
|
|
15
|
+
vault backup sync | vault backup off
|
|
16
|
+
vault import --key-env NAME bring in what a 1claw agent key (ocv_) can read; the key is not kept
|
|
17
|
+
vault share <name> [--hours 24] [--uses 1] a 1claw link, for an agent outside your swarm`;
|
|
18
|
+
|
|
19
|
+
/** A value typed without showing it, or piped in. */
|
|
20
|
+
async function hiddenValue(prompt) {
|
|
21
|
+
const input = process.stdin;
|
|
22
|
+
if (!input.isTTY) {
|
|
23
|
+
let piped = "";
|
|
24
|
+
for await (const chunk of input) piped += chunk;
|
|
25
|
+
return piped.replace(/\r?\n$/, "");
|
|
26
|
+
}
|
|
27
|
+
process.stdout.write(prompt);
|
|
28
|
+
input.setRawMode(true);
|
|
29
|
+
input.resume();
|
|
30
|
+
input.setEncoding("utf8");
|
|
31
|
+
return new Promise((resolve, reject) => {
|
|
32
|
+
let value = "";
|
|
33
|
+
const done = (error) => {
|
|
34
|
+
input.setRawMode(false);
|
|
35
|
+
input.pause();
|
|
36
|
+
input.removeListener("data", onData);
|
|
37
|
+
process.stdout.write("\n");
|
|
38
|
+
error ? reject(error) : resolve(value);
|
|
39
|
+
};
|
|
40
|
+
const onData = (chunk) => {
|
|
41
|
+
for (const character of chunk) {
|
|
42
|
+
if (character === "\r" || character === "\n") return done();
|
|
43
|
+
if (character === "\u0003") return done(new Error("cancelled"));
|
|
44
|
+
if (character === "\u007f") value = value.slice(0, -1);
|
|
45
|
+
else value += character;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
input.on("data", onData);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export async function vaultCommands(argv) {
|
|
53
|
+
const option = (name) => {
|
|
54
|
+
const at = argv.indexOf(name);
|
|
55
|
+
return at < 0 ? null : argv[at + 1];
|
|
56
|
+
};
|
|
57
|
+
const call = async (action, fields = {}) => {
|
|
58
|
+
const reply = await daemonRequest({
|
|
59
|
+
command: `board.vault.${action}`,
|
|
60
|
+
agent: "user",
|
|
61
|
+
...fields,
|
|
62
|
+
});
|
|
63
|
+
if (!reply.ok) throw new Error(reply.error || "the vault refused");
|
|
64
|
+
return reply;
|
|
65
|
+
};
|
|
66
|
+
const [action = "list", first, second, third] = argv;
|
|
67
|
+
const hostsOf = (text) =>
|
|
68
|
+
String(text || "")
|
|
69
|
+
.split(",")
|
|
70
|
+
.map((host) => host.trim())
|
|
71
|
+
.filter(Boolean);
|
|
72
|
+
|
|
73
|
+
if (action === "list") {
|
|
74
|
+
const vault = await call("list");
|
|
75
|
+
for (const request of vault.requests)
|
|
76
|
+
console.log(
|
|
77
|
+
request.why === "missing"
|
|
78
|
+
? `${request.agent} needs ${request.secret}${request.host ? ` for ${request.host}` : ""}: npx tryharness vault add ${request.secret} --hosts ${request.host ?? "<website>"}`
|
|
79
|
+
: `${request.agent} asks to use ${request.secret}: npx tryharness vault allow ${request.agent} ${request.secret}`
|
|
80
|
+
);
|
|
81
|
+
if (!vault.secrets.length) console.log("Nothing kept yet.");
|
|
82
|
+
for (const secret of vault.secrets)
|
|
83
|
+
console.log(
|
|
84
|
+
`${secret.name} ${secret.hosts.length ? `only sent to ${secret.hosts.join(", ")}` : "no website yet, so no agent can use it"}`
|
|
85
|
+
);
|
|
86
|
+
for (const grant of vault.grants)
|
|
87
|
+
console.log(
|
|
88
|
+
grant.mode === "use"
|
|
89
|
+
? ` ${grant.agent} may use ${grant.secret} (${grant.id})`
|
|
90
|
+
: ` ${grant.secret} is in ${grant.agent}'s runs as ${grant.env}${grant.machines === "own" ? ", on your other computers too" : ""} (${grant.id})`
|
|
91
|
+
);
|
|
92
|
+
const backup = vault.backup;
|
|
93
|
+
console.log(
|
|
94
|
+
backup.status === "on"
|
|
95
|
+
? `Backup: on, in 1claw (${backup.email}).`
|
|
96
|
+
: backup.status === "waiting"
|
|
97
|
+
? `Backup: approve code ${backup.code} at ${backup.verifyUrl}`
|
|
98
|
+
: `Backup: ${backup.status}.${backup.message ? ` ${backup.message}` : ""}`
|
|
99
|
+
);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (action === "add") {
|
|
103
|
+
const name = first;
|
|
104
|
+
const fromEnv = option("--value-env");
|
|
105
|
+
if (fromEnv && !process.env[fromEnv])
|
|
106
|
+
throw new Error(`nothing is set in ${fromEnv}`);
|
|
107
|
+
const value = fromEnv
|
|
108
|
+
? process.env[fromEnv]
|
|
109
|
+
: await hiddenValue(`Value for ${name} (hidden): `);
|
|
110
|
+
await call("save", { name, value, hosts: hostsOf(option("--hosts")) });
|
|
111
|
+
console.log(
|
|
112
|
+
`Kept ${name} on this computer${option("--hosts") ? `, only sent to ${hostsOf(option("--hosts")).join(", ")}` : ". Name its website before an agent uses it: npx tryharness vault hosts " + name + " <host>"}.`
|
|
113
|
+
);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (action === "hosts") {
|
|
117
|
+
await call("save", { name: first, value: "", hosts: hostsOf(second) });
|
|
118
|
+
console.log(`${first} is only sent to ${hostsOf(second).join(", ")}.`);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (action === "remove") {
|
|
122
|
+
await call("remove", { name: first });
|
|
123
|
+
console.log(`Removed ${first}.`);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (action === "allow") {
|
|
127
|
+
await call("grant", { forAgent: first, secret: second, mode: "use" });
|
|
128
|
+
console.log(`${first} may use ${second}.`);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (action === "runs") {
|
|
132
|
+
const elsewhere = argv.includes("--elsewhere");
|
|
133
|
+
await call("grant", {
|
|
134
|
+
forAgent: first,
|
|
135
|
+
secret: second,
|
|
136
|
+
mode: "env",
|
|
137
|
+
env: third,
|
|
138
|
+
machines: elsewhere ? "own" : "home",
|
|
139
|
+
});
|
|
140
|
+
console.log(
|
|
141
|
+
`${second} is in ${first}'s runs as ${third}${elsewhere ? ", on your other computers too" : ""}. ${first} can read it there; what its runs say is cleaned of it.`
|
|
142
|
+
);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
if (action === "revoke") {
|
|
146
|
+
await call("revoke", { id: first });
|
|
147
|
+
console.log("Removed.");
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
if (action === "backup" && first === "sync") {
|
|
151
|
+
await call("backup.sync");
|
|
152
|
+
console.log("Backed up.");
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
if (action === "backup" && first === "off") {
|
|
156
|
+
await call("backup.stop");
|
|
157
|
+
console.log(
|
|
158
|
+
"Backup is off. 1claw still holds the last copy; remove it there if you want it gone."
|
|
159
|
+
);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
if (action === "backup") {
|
|
163
|
+
const started = await call("backup.start", {
|
|
164
|
+
email: first,
|
|
165
|
+
bringIn: argv.includes("--bring-in"),
|
|
166
|
+
});
|
|
167
|
+
console.log(
|
|
168
|
+
`Approve code ${started.code} in 1claw: ${started.verifyUrl}\nWith no 1claw account, signing up with ${first} makes one. Then: npx tryharness vault`
|
|
169
|
+
);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
if (action === "import") {
|
|
173
|
+
const name = option("--key-env");
|
|
174
|
+
if (!name || !process.env[name])
|
|
175
|
+
throw new Error(
|
|
176
|
+
"put the 1claw key in an environment variable and name it: --key-env NAME"
|
|
177
|
+
);
|
|
178
|
+
const { imported } = await call("import", { apiKey: process.env[name] });
|
|
179
|
+
console.log(
|
|
180
|
+
imported.length
|
|
181
|
+
? `Brought in ${imported.join(", ")}. Name each one's website: npx tryharness vault hosts <name> <host>`
|
|
182
|
+
: "Nothing new to bring in."
|
|
183
|
+
);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
if (action === "share") {
|
|
187
|
+
const hours = Number(option("--hours") || 24);
|
|
188
|
+
const uses = Number(option("--uses") || 1);
|
|
189
|
+
const { share } = await call("share", {
|
|
190
|
+
name: first,
|
|
191
|
+
to: "link",
|
|
192
|
+
expiresAt: new Date(Date.now() + hours * 3_600_000).toISOString(),
|
|
193
|
+
maxUses: uses,
|
|
194
|
+
});
|
|
195
|
+
console.log(
|
|
196
|
+
`${share.url}\nWorks ${uses === 1 ? "once" : `${uses} times`}, for ${hours === 1 ? "an hour" : `${hours} hours`}. Whoever has the link can read ${first}.`
|
|
197
|
+
);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
throw new Error(USAGE);
|
|
201
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const USE_SECRET_TOOL: {
|
|
2
|
+
name: "use_secret";
|
|
3
|
+
description: string;
|
|
4
|
+
inputSchema: Record<string, unknown>;
|
|
5
|
+
};
|
|
6
|
+
export function secretToolRequest(input: Record<string, unknown>): {
|
|
7
|
+
command: "board.vault.list" | "board.vault.use";
|
|
8
|
+
url?: string;
|
|
9
|
+
method?: string;
|
|
10
|
+
headers?: string[];
|
|
11
|
+
body?: string;
|
|
12
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// use_secret, one definition for every agent: the swarm's agents through their stdio MCP (mcp-stdio.mjs) and Harness's
|
|
2
|
+
// own chat through the person's browser (src/runtime/client-channel/vaultTools.ts). The daemon's vault (vault.mjs)
|
|
3
|
+
// answers it; plain JavaScript so the app and the published cli/ share it.
|
|
4
|
+
export const USE_SECRET_TOOL = {
|
|
5
|
+
name: "use_secret",
|
|
6
|
+
description:
|
|
7
|
+
"Call a website's API with one of the person's secrets (an API key, a token, a password) without ever seeing it. Write {{secret:name}} where it goes in the url, a header or the body; Harness Relay on the person's computer puts the value in, sends the request only to the websites the person allowed for that secret, and gives you the answer with the value replaced by [secret:name]. If the secret is missing or you may not use it yet, the person is asked: tell them, and try again once they have. list: true shows the secrets you may use and where. Never ask the person to paste a secret into the chat.",
|
|
8
|
+
inputSchema: {
|
|
9
|
+
type: "object",
|
|
10
|
+
properties: {
|
|
11
|
+
url: {
|
|
12
|
+
type: "string",
|
|
13
|
+
description: "https address, for example https://api.fly.io/v1/apps",
|
|
14
|
+
},
|
|
15
|
+
method: {
|
|
16
|
+
type: "string",
|
|
17
|
+
enum: ["GET", "POST", "PUT", "PATCH", "DELETE"],
|
|
18
|
+
},
|
|
19
|
+
headers: {
|
|
20
|
+
type: "array",
|
|
21
|
+
items: { type: "string" },
|
|
22
|
+
description:
|
|
23
|
+
'Header lines, for example "Authorization: Bearer {{secret:fly-token}}"',
|
|
24
|
+
},
|
|
25
|
+
body: { type: "string" },
|
|
26
|
+
list: { type: "boolean", description: "show the secrets you may use" },
|
|
27
|
+
},
|
|
28
|
+
additionalProperties: false,
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/** The daemon request a use_secret call makes. */
|
|
33
|
+
export function secretToolRequest(input) {
|
|
34
|
+
if (input.list === true) return { command: "board.vault.list" };
|
|
35
|
+
return {
|
|
36
|
+
command: "board.vault.use",
|
|
37
|
+
url: typeof input.url === "string" ? input.url : "",
|
|
38
|
+
method: typeof input.method === "string" ? input.method : undefined,
|
|
39
|
+
headers: Array.isArray(input.headers) ? input.headers.map(String) : [],
|
|
40
|
+
body: typeof input.body === "string" ? input.body : undefined,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// This computer asking the person's own Harness window for what only it holds (phones.mjs ask): this computer's own
|
|
2
|
+
// windows first, then those linked to each of the person's other computers (ownMachines.mjs). With no Harness window
|
|
3
|
+
// open, the browser that listens for this computer (browserWake.mjs, the extension's native host) is woken: the
|
|
4
|
+
// extension brings up its hidden Harness page, which answers like a tab (owner, October 22: the swarm reads what the
|
|
5
|
+
// person has seen from the hidden page). It is asked again as it comes up, until WAKE_DEADLINE_MS.
|
|
6
|
+
|
|
7
|
+
// How long to keep asking a woken hidden page: the owner's value (October 22: "lets go 1 min on the wait"). Measured
|
|
8
|
+
// only against a local app on loopback (e2e hidden-page-seen, run 20261022-161745-75cbcea9-f21f: closed page to
|
|
9
|
+
// answer 1.04 to 1.08 s, 5 samples on an M5 Pro), never against tryharness.ai.
|
|
10
|
+
export const WAKE_DEADLINE_MS = 60_000;
|
|
11
|
+
const ASK_EVERY_MS = 1_000;
|
|
12
|
+
|
|
13
|
+
export function createWindowAsks({
|
|
14
|
+
askOwn,
|
|
15
|
+
askWorkers = async () => null,
|
|
16
|
+
browserWake,
|
|
17
|
+
log = () => {},
|
|
18
|
+
now = () => Date.now(),
|
|
19
|
+
wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
|
|
20
|
+
}) {
|
|
21
|
+
const nobodyAt = (reply) =>
|
|
22
|
+
reply?.ok === false && ["unpaired", "closed"].includes(reply.code);
|
|
23
|
+
const askAnywhere = async (call) => {
|
|
24
|
+
const here = await askOwn(call);
|
|
25
|
+
return (nobodyAt(here) && (await askWorkers(call))) || here;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/** The window's answer to `call`, waking the hidden page when no window is open and a browser listens. */
|
|
29
|
+
return async function ask(call) {
|
|
30
|
+
const first = await askAnywhere(call);
|
|
31
|
+
if (first?.code !== "closed" || !browserWake?.listening()) return first;
|
|
32
|
+
browserWake.send({ kind: "window" });
|
|
33
|
+
log(`windows: none open, woke the browser for ${call.tool}`);
|
|
34
|
+
const until = now() + WAKE_DEADLINE_MS;
|
|
35
|
+
let reply = first;
|
|
36
|
+
while (reply?.code === "closed" && now() < until) {
|
|
37
|
+
await wait(ASK_EVERY_MS);
|
|
38
|
+
reply = await askAnywhere(call);
|
|
39
|
+
}
|
|
40
|
+
return reply;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
|
|
3
|
+
/** Following and read receipts belong to the work, so paired surfaces agree. */
|
|
4
|
+
export function createWorkFocus({ store }) {
|
|
5
|
+
const keyOf = (id) => `work-focus:${id}`;
|
|
6
|
+
const saved = (id) => JSON.parse(store.meta(keyOf(id)) || "{}");
|
|
7
|
+
// What the person can read: new words, a new question, the thread ending. Agents starting, stopping or queueing
|
|
8
|
+
// are not, so reading a thread while its agents work stays read.
|
|
9
|
+
const revisionOf = (thread) =>
|
|
10
|
+
createHash("sha256")
|
|
11
|
+
.update(
|
|
12
|
+
JSON.stringify([
|
|
13
|
+
thread.updatedAt,
|
|
14
|
+
thread.status,
|
|
15
|
+
thread.view?.needsYou,
|
|
16
|
+
thread.posts,
|
|
17
|
+
thread.last,
|
|
18
|
+
thread.activityVersion,
|
|
19
|
+
thread.relatedVersion,
|
|
20
|
+
])
|
|
21
|
+
)
|
|
22
|
+
.digest("hex");
|
|
23
|
+
const decorate = (thread) => {
|
|
24
|
+
const receipt = saved(thread.id);
|
|
25
|
+
const following = receipt.following ?? !thread.source;
|
|
26
|
+
const revision = revisionOf(thread);
|
|
27
|
+
return {
|
|
28
|
+
...thread,
|
|
29
|
+
focus: {
|
|
30
|
+
following,
|
|
31
|
+
revision,
|
|
32
|
+
changed: following && receipt.seen !== revision,
|
|
33
|
+
seenAt: receipt.seenAt ?? null,
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
const update = (thread, request) => {
|
|
38
|
+
const receipt = saved(thread.id);
|
|
39
|
+
if (request.command === "board.swarm.follow") {
|
|
40
|
+
if (typeof request.following !== "boolean")
|
|
41
|
+
return { ok: false, error: "Choose whether to follow this work." };
|
|
42
|
+
receipt.following = request.following;
|
|
43
|
+
} else {
|
|
44
|
+
const revision = revisionOf(thread);
|
|
45
|
+
if (request.revision !== revision)
|
|
46
|
+
return {
|
|
47
|
+
ok: false,
|
|
48
|
+
code: "changed",
|
|
49
|
+
error:
|
|
50
|
+
"This work changed since your check-in. Read the update first.",
|
|
51
|
+
};
|
|
52
|
+
receipt.seen = revision;
|
|
53
|
+
receipt.seenAt = new Date().toISOString();
|
|
54
|
+
}
|
|
55
|
+
store.meta(keyOf(thread.id), JSON.stringify(receipt));
|
|
56
|
+
return { ok: true, thread: decorate(thread) };
|
|
57
|
+
};
|
|
58
|
+
return { decorate, update };
|
|
59
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
|
|
3
|
+
/** Private references beside an objective. No copied history, agent input or execution authority. */
|
|
4
|
+
export function createWorkLinks({ store, readWork }) {
|
|
5
|
+
const key = (id) => `work-links:${id}`;
|
|
6
|
+
const references = (id) => JSON.parse(store.meta(key(id)) || "[]");
|
|
7
|
+
const read = async (id) => {
|
|
8
|
+
const entries = await Promise.all(
|
|
9
|
+
references(id).map(async (sourceId) => {
|
|
10
|
+
try {
|
|
11
|
+
const source = await readWork(sourceId);
|
|
12
|
+
if (!source.ok) return { id: sourceId, available: false };
|
|
13
|
+
const { thread, posts } = source;
|
|
14
|
+
const result = posts
|
|
15
|
+
.filter(
|
|
16
|
+
(post) =>
|
|
17
|
+
post.author !== "user" &&
|
|
18
|
+
["result", "post"].includes(post.kind) &&
|
|
19
|
+
post.text.trim()
|
|
20
|
+
)
|
|
21
|
+
.sort((a, b) => a.created_at.localeCompare(b.created_at))
|
|
22
|
+
.at(-1);
|
|
23
|
+
return {
|
|
24
|
+
id: sourceId,
|
|
25
|
+
available: true,
|
|
26
|
+
title: thread.title,
|
|
27
|
+
environment: thread.source?.environmentName ?? "Harness",
|
|
28
|
+
source: thread.source ?? null,
|
|
29
|
+
agents: thread.agents,
|
|
30
|
+
line: thread.view?.line ?? null,
|
|
31
|
+
working: thread.working,
|
|
32
|
+
needsYou: thread.view?.needsYou?.length ?? 0,
|
|
33
|
+
result: result
|
|
34
|
+
? {
|
|
35
|
+
id: result.id,
|
|
36
|
+
author: result.author,
|
|
37
|
+
text: result.text,
|
|
38
|
+
at: result.created_at,
|
|
39
|
+
url: result.source?.url ?? thread.source?.url ?? null,
|
|
40
|
+
truncated: result.source?.truncated === true,
|
|
41
|
+
}
|
|
42
|
+
: null,
|
|
43
|
+
};
|
|
44
|
+
} catch {
|
|
45
|
+
// A revoked or unavailable source must not leave its old private content on the card.
|
|
46
|
+
return { id: sourceId, available: false };
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
);
|
|
50
|
+
return { ok: true, entries };
|
|
51
|
+
};
|
|
52
|
+
const update = async (request) => {
|
|
53
|
+
const { id, sourceId, linked } = request;
|
|
54
|
+
if (
|
|
55
|
+
typeof sourceId !== "string" ||
|
|
56
|
+
typeof linked !== "boolean" ||
|
|
57
|
+
sourceId === id
|
|
58
|
+
)
|
|
59
|
+
return {
|
|
60
|
+
ok: false,
|
|
61
|
+
error: "Choose another work thread to keep beside this objective.",
|
|
62
|
+
};
|
|
63
|
+
if (linked) {
|
|
64
|
+
const source = await readWork(sourceId);
|
|
65
|
+
if (!source.ok) return source;
|
|
66
|
+
}
|
|
67
|
+
// Read after the source check so simultaneous additions preserve each other.
|
|
68
|
+
const current = references(id);
|
|
69
|
+
if (linked && !current.includes(sourceId) && current.length >= 12)
|
|
70
|
+
return {
|
|
71
|
+
ok: false,
|
|
72
|
+
error: "Keep up to 12 work threads beside an objective.",
|
|
73
|
+
};
|
|
74
|
+
const next = linked
|
|
75
|
+
? [...new Set([...current, sourceId])]
|
|
76
|
+
: current.filter((entry) => entry !== sourceId);
|
|
77
|
+
store.meta(key(id), JSON.stringify(next));
|
|
78
|
+
return read(id);
|
|
79
|
+
};
|
|
80
|
+
const version = (id, lookup) => {
|
|
81
|
+
const ids = references(id);
|
|
82
|
+
if (!ids.length) return null;
|
|
83
|
+
return createHash("sha256")
|
|
84
|
+
.update(
|
|
85
|
+
JSON.stringify(ids.map((sourceId) => [sourceId, lookup(sourceId)]))
|
|
86
|
+
)
|
|
87
|
+
.digest("hex");
|
|
88
|
+
};
|
|
89
|
+
return { read, update, version };
|
|
90
|
+
}
|
package/lib/worktrees.mjs
CHANGED
|
@@ -64,6 +64,10 @@ export function mainCheckout(folder) {
|
|
|
64
64
|
);
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
/** Files as a thread says them: the first five, and how many more. */
|
|
68
|
+
export const namedFiles = (files) =>
|
|
69
|
+
`${files.slice(0, 5).join(", ")}${files.length > 5 ? ` and ${files.length - 5} more` : ""}`;
|
|
70
|
+
|
|
67
71
|
const slug = (text) =>
|
|
68
72
|
String(text)
|
|
69
73
|
.toLowerCase()
|
|
@@ -121,25 +125,51 @@ export function createWorktrees({ store, root }) {
|
|
|
121
125
|
return path.join(where, repo.inside);
|
|
122
126
|
};
|
|
123
127
|
|
|
124
|
-
|
|
125
|
-
const commitTurn = (threadId, runId, message) => {
|
|
128
|
+
const openTree = (threadId) => {
|
|
126
129
|
const tree = get(threadId);
|
|
127
|
-
|
|
128
|
-
|
|
130
|
+
return tree?.state === "open" && fs.existsSync(tree.path) ? tree : null;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
/** Where the thread's branch is as a turn starts, so commits the agent makes itself count as that turn's too. */
|
|
134
|
+
const startTurn = (threadId, runId) => {
|
|
135
|
+
const tree = openTree(threadId);
|
|
136
|
+
if (!tree) return;
|
|
137
|
+
store.meta(`turn-from:${runId}`, git(tree.path, ["rev-parse", "HEAD"]).out);
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Commits what a turn left uncommitted on the thread's branch. The turn's diff runs from where the branch was when it
|
|
142
|
+
* started (startTurn) to the commit it ends on, so commits the agent made itself are its own too. Null when the turn
|
|
143
|
+
* changed nothing on the branch.
|
|
144
|
+
*/
|
|
145
|
+
const commitTurn = (threadId, runId, message) => {
|
|
146
|
+
const tree = openTree(threadId);
|
|
147
|
+
if (!tree) return null;
|
|
129
148
|
git(tree.path, ["add", "-A"]);
|
|
130
|
-
|
|
131
|
-
const committed =
|
|
132
|
-
|
|
133
|
-
"-q",
|
|
134
|
-
"-m",
|
|
135
|
-
String(message).slice(0, 200),
|
|
136
|
-
]);
|
|
137
|
-
if (!committed.ok) return null;
|
|
149
|
+
const staged = !git(tree.path, ["diff", "--cached", "--quiet"]).ok;
|
|
150
|
+
const committed =
|
|
151
|
+
staged &&
|
|
152
|
+
git(tree.path, ["commit", "-q", "-m", String(message).slice(0, 200)]).ok;
|
|
138
153
|
const sha = git(tree.path, ["rev-parse", "HEAD"]).out;
|
|
154
|
+
// A turn from before turns recorded their start counts only the commit made here.
|
|
155
|
+
const from = store.meta(`turn-from:${runId}`);
|
|
156
|
+
const moved = from ? sha !== from : committed;
|
|
157
|
+
if (!moved) return null;
|
|
139
158
|
store.meta(`turn:${runId}`, sha);
|
|
140
159
|
return sha;
|
|
141
160
|
};
|
|
142
161
|
|
|
162
|
+
/** The files in the thread's copy that are not committed on its branch, such as a change git would not commit. */
|
|
163
|
+
const uncommitted = (threadId) => {
|
|
164
|
+
const tree = openTree(threadId);
|
|
165
|
+
if (!tree) return [];
|
|
166
|
+
const lines = (args) =>
|
|
167
|
+
git(tree.path, args).out.split("\n").filter(Boolean);
|
|
168
|
+
const changed = lines(["diff", "--name-only", "HEAD"]);
|
|
169
|
+
const added = lines(["ls-files", "--others", "--exclude-standard"]);
|
|
170
|
+
return [...new Set([...changed, ...added])];
|
|
171
|
+
};
|
|
172
|
+
|
|
143
173
|
const stat = (cwd, range) => {
|
|
144
174
|
const out = git(cwd, ["diff", "--numstat", range]).out;
|
|
145
175
|
const files = out
|
|
@@ -165,7 +195,8 @@ export function createWorktrees({ store, root }) {
|
|
|
165
195
|
if (runId) {
|
|
166
196
|
const sha = store.meta(`turn:${runId}`);
|
|
167
197
|
if (!sha) return { ok: true, files: [], patch: "" };
|
|
168
|
-
|
|
198
|
+
const from = store.meta(`turn-from:${runId}`);
|
|
199
|
+
range = from ? `${from}..${sha}` : `${sha}~1..${sha}`;
|
|
169
200
|
} else
|
|
170
201
|
range = `${tree.base}..${tree.state === "open" ? "HEAD" : tree.branch}`;
|
|
171
202
|
const patch = git(cwd, ["diff", range]).out;
|
|
@@ -230,12 +261,15 @@ export function createWorktrees({ store, root }) {
|
|
|
230
261
|
: `git would not merge into ${into}: ${merged.err.split("\n")[0]}; nothing was merged`,
|
|
231
262
|
};
|
|
232
263
|
}
|
|
264
|
+
// The branch goes once it is merged; its last commit stays, so what it brought in can still be shown.
|
|
265
|
+
const tip = git(tree.repo, ["rev-parse", tree.branch]).out || null;
|
|
233
266
|
retire(tree);
|
|
234
267
|
git(tree.repo, ["branch", "-d", tree.branch]);
|
|
235
268
|
save(threadId, {
|
|
236
269
|
...tree,
|
|
237
270
|
state: "merged",
|
|
238
271
|
into,
|
|
272
|
+
tip,
|
|
239
273
|
mergedAt: new Date().toISOString(),
|
|
240
274
|
});
|
|
241
275
|
return { ok: true, into };
|
|
@@ -327,8 +361,12 @@ export function createWorktrees({ store, root }) {
|
|
|
327
361
|
};
|
|
328
362
|
|
|
329
363
|
return {
|
|
364
|
+
/** The thread's copy as kept: where it is, its branch, what it started from, and open, merged, t3 or in place. */
|
|
365
|
+
record: get,
|
|
330
366
|
folderFor,
|
|
367
|
+
startTurn,
|
|
331
368
|
commitTurn,
|
|
369
|
+
uncommitted,
|
|
332
370
|
head,
|
|
333
371
|
diff,
|
|
334
372
|
summary,
|