tryharness 0.7.44 → 0.7.53

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.
Files changed (101) hide show
  1. package/README.md +232 -12
  2. package/cli.mjs +406 -184
  3. package/lib/actorRoster.mjs +28 -5
  4. package/lib/adapters.mjs +9 -1
  5. package/lib/agentRuntimeConfig.mjs +36 -0
  6. package/lib/agentRuntimes.mjs +560 -0
  7. package/lib/atlas.mjs +7 -2
  8. package/lib/boardCommands.mjs +5 -10
  9. package/lib/boardFileCommands.mjs +2 -1
  10. package/lib/boardMirror.mjs +459 -0
  11. package/lib/boardProtocol.json +259 -6
  12. package/lib/boardTools.mjs +2 -6
  13. package/lib/bridge.mjs +27 -3
  14. package/lib/browserWake.mjs +60 -0
  15. package/lib/cards.mjs +35 -2
  16. package/lib/commands.mjs +20 -5
  17. package/lib/connectionTools.d.ts +13 -0
  18. package/lib/connectionTools.js +45 -0
  19. package/lib/connectorAuth.mjs +309 -0
  20. package/lib/connectorCatalog.json +41 -0
  21. package/lib/connectorCommands.mjs +121 -0
  22. package/lib/connectorGoogle.mjs +513 -0
  23. package/lib/connectors.mjs +805 -0
  24. package/lib/coordinator.mjs +16 -2
  25. package/lib/coreModels.mjs +78 -0
  26. package/lib/daemon.mjs +775 -46
  27. package/lib/desktop.mjs +7 -2
  28. package/lib/digest.mjs +32 -0
  29. package/lib/directLink.mjs +283 -0
  30. package/lib/environments.mjs +595 -0
  31. package/lib/folders.mjs +2 -2
  32. package/lib/goalCommands.mjs +61 -12
  33. package/lib/inference.mjs +263 -152
  34. package/lib/lessons.mjs +6 -0
  35. package/lib/lineup.mjs +324 -0
  36. package/lib/localmodels.mjs +10 -0
  37. package/lib/machineIdentity.mjs +3 -0
  38. package/lib/machineRoutes.mjs +40 -2
  39. package/lib/machineRuns.mjs +30 -3
  40. package/lib/machineSeal.mjs +69 -10
  41. package/lib/mcp-stdio.mjs +180 -98
  42. package/lib/mcpRelay.mjs +119 -0
  43. package/lib/members.json +12 -0
  44. package/lib/members.mjs +33 -0
  45. package/lib/modelMemory.mjs +100 -0
  46. package/lib/modelTiers.json +1183 -0
  47. package/lib/modelTiers.mjs +133 -0
  48. package/lib/models.mjs +41 -8
  49. package/lib/museSession.mjs +119 -0
  50. package/lib/nativeHost.mjs +203 -0
  51. package/lib/network.mjs +38 -1
  52. package/lib/nudge.mjs +10 -2
  53. package/lib/onboard.mjs +430 -1
  54. package/lib/oneclawLocal.mjs +150 -0
  55. package/lib/ownMachines.mjs +521 -36
  56. package/lib/pairing.mjs +165 -0
  57. package/lib/paths.mjs +4 -0
  58. package/lib/phones.mjs +61 -0
  59. package/lib/placeCommands.mjs +27 -0
  60. package/lib/places.mjs +10 -2
  61. package/lib/plans.mjs +151 -27
  62. package/lib/profile.mjs +152 -0
  63. package/lib/projectGit.mjs +328 -0
  64. package/lib/projectSettings.mjs +120 -0
  65. package/lib/projects.mjs +2539 -0
  66. package/lib/readiness.mjs +283 -0
  67. package/lib/repoLinks.mjs +354 -0
  68. package/lib/roomChannels.mjs +641 -0
  69. package/lib/runBrief.mjs +32 -2
  70. package/lib/runRequests.mjs +157 -0
  71. package/lib/runWorker.mjs +20 -7
  72. package/lib/runner.mjs +67 -8
  73. package/lib/secretPatterns.json +55 -0
  74. package/lib/secrets.mjs +10 -27
  75. package/lib/seen.mjs +102 -0
  76. package/lib/service.mjs +11 -6
  77. package/lib/sessionControl.mjs +10 -8
  78. package/lib/sessionIndex.mjs +5 -3
  79. package/lib/store.mjs +559 -30
  80. package/lib/subagents.mjs +8 -4
  81. package/lib/swarm.mjs +379 -38
  82. package/lib/swarmMemory.mjs +947 -0
  83. package/lib/t3.mjs +43 -13
  84. package/lib/taskCommands.mjs +58 -5
  85. package/lib/taskRuns.mjs +61 -11
  86. package/lib/team.json +17 -15
  87. package/lib/team.mjs +68 -18
  88. package/lib/threadRuns.mjs +50 -7
  89. package/lib/threadView.mjs +68 -15
  90. package/lib/tokenizer.mjs +405 -0
  91. package/lib/ui.mjs +16 -2
  92. package/lib/usageTotals.mjs +148 -0
  93. package/lib/vault.mjs +1144 -0
  94. package/lib/vaultCloud.mjs +117 -0
  95. package/lib/vaultCommands.mjs +201 -0
  96. package/lib/vaultTools.d.ts +12 -0
  97. package/lib/vaultTools.js +42 -0
  98. package/lib/windowAsks.mjs +42 -0
  99. package/lib/workFocus.mjs +59 -0
  100. package/lib/workLinks.mjs +90 -0
  101. package/package.json +9 -4
@@ -0,0 +1,513 @@
1
+ // Google's public APIs avoid the Workspace MCP Developer Preview. Operations
2
+ // still cross Relay's grants, approval and receipt interface before execution.
3
+ const string = { type: "string", minLength: 1 };
4
+ const integer = { type: "integer", minimum: 1, maximum: 100 };
5
+ const object = { type: "object" };
6
+ function tool(name, description, effect, properties, required = []) {
7
+ return {
8
+ name,
9
+ description,
10
+ effect,
11
+ inputSchema: {
12
+ type: "object",
13
+ properties,
14
+ required,
15
+ additionalProperties: false,
16
+ },
17
+ };
18
+ }
19
+ const calendar = { calendarId: string };
20
+ const event = { ...calendar, eventId: string };
21
+ const calendarTools = [
22
+ tool(
23
+ "list_calendars",
24
+ "List calendars this account can access. Returns IDs for resource restrictions.",
25
+ "read",
26
+ { pageToken: string }
27
+ ),
28
+ tool(
29
+ "list_events",
30
+ "List events in one calendar. Follow nextPageToken for more; preserve etags before editing.",
31
+ "read",
32
+ {
33
+ ...calendar,
34
+ timeMin: string,
35
+ timeMax: string,
36
+ q: string,
37
+ pageToken: string,
38
+ maxResults: integer,
39
+ },
40
+ ["calendarId"]
41
+ ),
42
+ tool(
43
+ "get_event",
44
+ "Read an event and its current etag before an edit or deletion.",
45
+ "read",
46
+ event,
47
+ ["calendarId", "eventId"]
48
+ ),
49
+ tool(
50
+ "create_event",
51
+ "Create a calendar event without guests. Includes an independent read-back receipt.",
52
+ "write",
53
+ { ...calendar, event: object },
54
+ ["calendarId", "event"]
55
+ ),
56
+ tool(
57
+ "update_event",
58
+ "Edit an event without changing guests. Requires the etag from the last read; refuses stale edits.",
59
+ "write",
60
+ { ...event, etag: string, patch: object },
61
+ ["calendarId", "eventId", "etag", "patch"]
62
+ ),
63
+ tool(
64
+ "delete_event",
65
+ "Delete the exact event at its last-read etag. Guest notifications are suppressed.",
66
+ "delete",
67
+ { ...event, etag: string },
68
+ ["calendarId", "eventId", "etag"]
69
+ ),
70
+ ];
71
+ const gmailTools = [
72
+ tool(
73
+ "search_messages",
74
+ "Search Gmail using its query syntax. Returns message IDs; read only the messages needed.",
75
+ "read",
76
+ { q: string, pageToken: string, maxResults: integer },
77
+ ["q"]
78
+ ),
79
+ tool(
80
+ "get_message",
81
+ "Read one Gmail message with its headers, body and label IDs.",
82
+ "read",
83
+ { messageId: string },
84
+ ["messageId"]
85
+ ),
86
+ tool(
87
+ "get_thread",
88
+ "Read one Gmail conversation.",
89
+ "read",
90
+ { threadId: string },
91
+ ["threadId"]
92
+ ),
93
+ tool("list_labels", "List this Gmail account's labels and IDs.", "read", {}),
94
+ tool(
95
+ "get_draft",
96
+ "Read an existing draft, including its current message ID and complete content.",
97
+ "read",
98
+ { draftId: string },
99
+ ["draftId"]
100
+ ),
101
+ tool(
102
+ "create_draft",
103
+ "Save an unsent RFC 2822 email draft. raw is the complete base64url encoded MIME message; the approval contains that exact content.",
104
+ "write",
105
+ { raw: string, threadId: string },
106
+ ["raw"]
107
+ ),
108
+ tool(
109
+ "send_message",
110
+ "Send this exact RFC 2822 message, never a mutable draft ID. raw is the complete base64url MIME message; recipients and content are bound to approval. Sent-copy verification does not prove delivery to recipients.",
111
+ "send",
112
+ { raw: string, threadId: string },
113
+ ["raw"]
114
+ ),
115
+ ];
116
+ // A mutable draft ID cannot bind its later contents to approval. Sending uses
117
+ // the exact bytes approved and persisted in Relay's operation instead.
118
+
119
+ function mimeContent(raw) {
120
+ if (!/^[A-Za-z0-9_-]+={0,2}$/.test(raw))
121
+ throw new Error("message raw must be base64url MIME content");
122
+ const bytes = Buffer.from(raw, "base64url");
123
+ if (bytes.toString("base64url") !== raw.replace(/=+$/, ""))
124
+ throw new Error("message raw must be canonical base64url");
125
+ const text = new TextDecoder("utf-8", { fatal: true }).decode(bytes);
126
+ const normalized = text.replaceAll("\r\n", "\n");
127
+ const boundary = normalized.indexOf("\n\n");
128
+ if (boundary < 0)
129
+ throw new Error("a message needs complete MIME headers and a body");
130
+ const fields = normalized
131
+ .slice(0, boundary)
132
+ .replace(/\n[ \t]+/g, " ")
133
+ .split("\n");
134
+ const headers = fields.map((line) => {
135
+ const match = /^([!-9;-~]+):[ \t]*(.*)$/.exec(line);
136
+ if (!match || /[\x00-\x08\x0b-\x1f\x7f]/.test(match[2]))
137
+ throw new Error("invalid MIME header");
138
+ return [match[1].toLowerCase(), match[2]];
139
+ });
140
+ const single = new Set([
141
+ "from",
142
+ "sender",
143
+ "reply-to",
144
+ "to",
145
+ "cc",
146
+ "bcc",
147
+ "subject",
148
+ "date",
149
+ "message-id",
150
+ "mime-version",
151
+ "content-type",
152
+ "content-transfer-encoding",
153
+ ]);
154
+ const seen = new Set();
155
+ for (const [name] of headers) {
156
+ if (single.has(name) && seen.has(name))
157
+ throw new Error("duplicate MIME header");
158
+ seen.add(name);
159
+ }
160
+ return { text, headers, body: normalized.slice(boundary + 2) };
161
+ }
162
+
163
+ function sameSentContent(expectedRaw, observedRaw) {
164
+ try {
165
+ const expected = mimeContent(expectedRaw);
166
+ const observed = mimeContent(observedRaw);
167
+ const names = new Set(expected.headers.map(([name]) => name));
168
+ const added = new Set([
169
+ "date",
170
+ "message-id",
171
+ "mime-version",
172
+ "from",
173
+ "received",
174
+ "return-path",
175
+ "dkim-signature",
176
+ ]);
177
+ if (
178
+ observed.headers.some(
179
+ ([name]) =>
180
+ !names.has(name) &&
181
+ !added.has(name) &&
182
+ !name.startsWith("x-google-") &&
183
+ !name.startsWith("x-gm-") &&
184
+ !name.startsWith("arc-")
185
+ )
186
+ )
187
+ return false;
188
+ const supplied = observed.headers.filter(([name]) => names.has(name));
189
+ const sorted = (headers) =>
190
+ JSON.stringify([...headers].sort(([a], [b]) => a.localeCompare(b)));
191
+ return (
192
+ expected.body === observed.body &&
193
+ sorted(expected.headers) === sorted(supplied)
194
+ );
195
+ } catch {
196
+ return false;
197
+ }
198
+ }
199
+
200
+ export const GOOGLE_OAUTH = {
201
+ authorization_endpoint: "https://accounts.google.com/o/oauth2/v2/auth",
202
+ token_endpoint: "https://oauth2.googleapis.com/token",
203
+ token_endpoint_auth_methods_supported: ["client_secret_post", "none"],
204
+ };
205
+
206
+ export function googleProvider(url, requested) {
207
+ const choices = {
208
+ calendar: "https://www.googleapis.com/calendar/v3",
209
+ gmail: "https://gmail.googleapis.com/gmail/v1",
210
+ };
211
+ const parsed = new URL(url);
212
+ for (const [id, base] of Object.entries(choices)) {
213
+ if (url.replace(/\/$/, "") === base) return id;
214
+ // A person can point the adapter at a local provider fixture or proxy. This
215
+ // cannot redirect an official Google credential to another public origin.
216
+ if (
217
+ requested === id &&
218
+ ["127.0.0.1", "localhost", "[::1]"].includes(parsed.hostname) &&
219
+ parsed.pathname.replace(/\/$/, "") === new URL(base).pathname
220
+ )
221
+ return id;
222
+ }
223
+ return null;
224
+ }
225
+
226
+ function validate(tool, args) {
227
+ if (!tool || !args || typeof args !== "object" || Array.isArray(args))
228
+ throw new Error("invalid Google operation");
229
+ for (const name of tool.inputSchema.required)
230
+ if (!(name in args)) throw new Error(`missing ${name}`);
231
+ for (const [name, value] of Object.entries(args)) {
232
+ const schema = tool.inputSchema.properties[name];
233
+ if (!schema) throw new Error(`unknown argument ${name}`);
234
+ if (
235
+ schema.type === "string" &&
236
+ (typeof value !== "string" || !value.length)
237
+ )
238
+ throw new Error(`invalid ${name}`);
239
+ if (
240
+ schema.type === "object" &&
241
+ (!value || typeof value !== "object" || Array.isArray(value))
242
+ )
243
+ throw new Error(`invalid ${name}`);
244
+ if (
245
+ schema.type === "integer" &&
246
+ (!Number.isInteger(value) || value < 1 || value > 100)
247
+ )
248
+ throw new Error(`invalid ${name}`);
249
+ }
250
+ }
251
+
252
+ export function googleOperation(provider, name, args) {
253
+ const tools = provider === "calendar" ? calendarTools : gmailTools;
254
+ const found = tools.find((entry) => entry.name === name);
255
+ validate(found, args);
256
+ const encoded = (value) => encodeURIComponent(value);
257
+ const events = `calendars/${encoded(args.calendarId)}/events`;
258
+ const query = (names) =>
259
+ Object.fromEntries(
260
+ names
261
+ .filter((key) => args[key] !== undefined)
262
+ .map((key) => [key, args[key]])
263
+ );
264
+ const id = `${events}/${encoded(args.eventId)}`;
265
+ if (provider === "calendar") {
266
+ if (name === "list_calendars")
267
+ return { path: "users/me/calendarList", query: query(["pageToken"]) };
268
+ if (name === "list_events")
269
+ return {
270
+ path: events,
271
+ query: query(["timeMin", "timeMax", "q", "pageToken", "maxResults"]),
272
+ };
273
+ if (name === "get_event") return { path: id };
274
+ if (["create_event", "update_event"].includes(name)) {
275
+ const body = args.event || args.patch;
276
+ const permitted = new Set([
277
+ "summary",
278
+ "description",
279
+ "location",
280
+ "start",
281
+ "end",
282
+ "recurrence",
283
+ "colorId",
284
+ "transparency",
285
+ "visibility",
286
+ "reminders",
287
+ ]);
288
+ if (Object.keys(body).some((key) => !permitted.has(key)))
289
+ throw new Error(
290
+ "only event details can change; invitations and sharing need separate authority"
291
+ );
292
+ if (name === "create_event" && (!body.start || !body.end))
293
+ throw new Error("an event needs start and end times");
294
+ return {
295
+ path: name === "create_event" ? events : id,
296
+ method: name === "create_event" ? "POST" : "PATCH",
297
+ body,
298
+ etag: args.etag,
299
+ query: { sendUpdates: "none" },
300
+ };
301
+ }
302
+ if (name === "delete_event")
303
+ return {
304
+ path: id,
305
+ method: "DELETE",
306
+ etag: args.etag,
307
+ query: { sendUpdates: "none" },
308
+ };
309
+ } else {
310
+ if (name === "search_messages")
311
+ return {
312
+ path: "users/me/messages",
313
+ query: query(["q", "pageToken", "maxResults"]),
314
+ };
315
+ if (name === "get_message")
316
+ return {
317
+ path: `users/me/messages/${encoded(args.messageId)}`,
318
+ query: { format: "full" },
319
+ };
320
+ if (name === "get_thread")
321
+ return {
322
+ path: `users/me/threads/${encoded(args.threadId)}`,
323
+ query: { format: "full" },
324
+ };
325
+ if (name === "list_labels") return { path: "users/me/labels" };
326
+ if (name === "get_draft")
327
+ return {
328
+ path: `users/me/drafts/${encoded(args.draftId)}`,
329
+ query: { format: "full" },
330
+ };
331
+ if (name === "create_draft" || name === "send_message") {
332
+ const mime = mimeContent(args.raw);
333
+ if (
334
+ name === "send_message" &&
335
+ !mime.headers.some(
336
+ ([name, value]) => ["to", "cc", "bcc"].includes(name) && value.trim()
337
+ )
338
+ )
339
+ throw new Error(
340
+ "a send needs explicit recipients in the approved message"
341
+ );
342
+ const message = {
343
+ raw: args.raw,
344
+ ...(args.threadId ? { threadId: args.threadId } : {}),
345
+ };
346
+ return {
347
+ path:
348
+ name === "send_message"
349
+ ? "users/me/messages/send"
350
+ : "users/me/drafts",
351
+ preview: mime.text,
352
+ method: "POST",
353
+ body: name === "send_message" ? message : { message },
354
+ };
355
+ }
356
+ }
357
+ throw new Error("unknown Google operation");
358
+ }
359
+
360
+ export function createGoogleConnector({
361
+ provider,
362
+ url,
363
+ bearer,
364
+ scope = "",
365
+ signal,
366
+ }) {
367
+ const scopes = new Set(scope.split(/\s+/));
368
+ const writable =
369
+ provider === "calendar"
370
+ ? scopes.has("https://www.googleapis.com/auth/calendar.events") ||
371
+ scopes.has("https://www.googleapis.com/auth/calendar")
372
+ : scopes.has("https://www.googleapis.com/auth/gmail.compose");
373
+ const sending = scopes.has("https://www.googleapis.com/auth/gmail.send");
374
+ const tools = (provider === "calendar" ? calendarTools : gmailTools).filter(
375
+ (entry) =>
376
+ entry.effect === "send" ? sending : entry.effect === "read" || writable
377
+ );
378
+ async function request(operation) {
379
+ const target = new URL(`${url.replace(/\/$/, "")}/${operation.path}`);
380
+ for (const [key, value] of Object.entries(operation.query || {}))
381
+ target.searchParams.set(key, String(value));
382
+ const response = await fetch(target, {
383
+ method: operation.method || "GET",
384
+ redirect: "error",
385
+ signal,
386
+ headers: {
387
+ authorization: `Bearer ${bearer}`,
388
+ "content-type": "application/json",
389
+ ...(operation.etag ? { "if-match": operation.etag } : {}),
390
+ },
391
+ ...(operation.body ? { body: JSON.stringify(operation.body) } : {}),
392
+ });
393
+ const text = await response.text();
394
+ if (!response.ok)
395
+ throw Object.assign(new Error(`Google HTTP ${response.status}`), {
396
+ // An upstream 5xx is not evidence that a mutation did not happen.
397
+ answered: response.status >= 400 && response.status < 500,
398
+ status: response.status,
399
+ });
400
+ return text ? JSON.parse(text) : null;
401
+ }
402
+ return {
403
+ async initialize() {},
404
+ async identity() {
405
+ const profile = await request({
406
+ path:
407
+ provider === "gmail"
408
+ ? "users/me/profile"
409
+ : "users/me/calendarList/primary",
410
+ });
411
+ return {
412
+ id: provider === "gmail" ? profile.emailAddress : profile.id,
413
+ source: provider === "gmail" ? "gmail.profile" : "calendar.primary",
414
+ checkedAt: new Date().toISOString(),
415
+ };
416
+ },
417
+ async resources() {
418
+ if (provider !== "calendar") return [];
419
+ const resources = [];
420
+ const seen = new Set();
421
+ let pageToken;
422
+ do {
423
+ const page = await request({
424
+ path: "users/me/calendarList",
425
+ query: { ...(pageToken ? { pageToken } : {}) },
426
+ });
427
+ for (const item of page.items || []) {
428
+ if (typeof item.id === "string")
429
+ resources.push({ id: item.id, label: item.summary || item.id });
430
+ }
431
+ pageToken = page.nextPageToken;
432
+ if (pageToken && seen.has(pageToken))
433
+ throw new Error("Google repeated a calendar page");
434
+ seen.add(pageToken);
435
+ } while (pageToken);
436
+ return resources;
437
+ },
438
+ async rpc(method, params) {
439
+ if (method === "tools/list") return { tools };
440
+ if (method !== "tools/call")
441
+ throw new Error("unsupported Google request");
442
+ if (!tools.some((entry) => entry.name === params.name))
443
+ throw new Error("this operation needs additional Google consent");
444
+ const operation = googleOperation(
445
+ provider,
446
+ params.name,
447
+ params.arguments
448
+ );
449
+ const value = await request(operation);
450
+ const sentMessage = params.name === "send_message";
451
+ let verification;
452
+ if (operation.method && operation.method !== "GET") {
453
+ const path =
454
+ provider === "gmail"
455
+ ? `users/me/${sentMessage ? "messages" : "drafts"}/${encodeURIComponent(value.id)}`
456
+ : operation.method === "POST"
457
+ ? `${operation.path}/${encodeURIComponent(value.id)}`
458
+ : operation.path;
459
+ try {
460
+ const observed = await request({
461
+ path,
462
+ ...(provider === "gmail" ? { query: { format: "raw" } } : {}),
463
+ });
464
+ const expected = operation.body;
465
+ const matched =
466
+ operation.method !== "DELETE" &&
467
+ (provider === "gmail"
468
+ ? sentMessage
469
+ ? observed.id === value.id &&
470
+ observed.labelIds?.includes("SENT") &&
471
+ sameSentContent(params.arguments.raw, observed.raw) &&
472
+ (!params.arguments.threadId ||
473
+ observed.threadId === params.arguments.threadId)
474
+ : observed.id === value.id &&
475
+ observed.message?.id === value.message?.id &&
476
+ observed.message?.raw === params.arguments.raw
477
+ : Object.entries(expected).every(
478
+ ([key, entry]) =>
479
+ JSON.stringify(observed[key]) === JSON.stringify(entry)
480
+ ));
481
+ verification = {
482
+ status: matched ? "verified" : "unverified",
483
+ ...(sentMessage
484
+ ? { outcome: "sent", delivery: "not_verified" }
485
+ : {}),
486
+ source: new URL(path, `${url}/`).href,
487
+ checkedAt: new Date().toISOString(),
488
+ observed,
489
+ };
490
+ } catch (error) {
491
+ verification = {
492
+ status:
493
+ operation.method === "DELETE" && [404, 410].includes(error.status)
494
+ ? "verified"
495
+ : "unverified",
496
+ checkedAt: new Date().toISOString(),
497
+ };
498
+ }
499
+ }
500
+ return {
501
+ content: [
502
+ {
503
+ type: "text",
504
+ text: JSON.stringify({
505
+ value,
506
+ ...(verification ? { verification } : {}),
507
+ }),
508
+ },
509
+ ],
510
+ };
511
+ },
512
+ };
513
+ }