@parcha/agentrun-serve 0.1.0-beta.53 → 0.1.0-beta.55

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 (224) hide show
  1. package/CHANGELOG.md +138 -3
  2. package/README.md +346 -99
  3. package/dist/adapters.d.ts +10 -0
  4. package/dist/adapters.js +46 -0
  5. package/dist/agent-package.d.ts +3 -3
  6. package/dist/agent-package.js +7 -14
  7. package/dist/agent-rows.d.ts +1 -1
  8. package/dist/agents-store.js +7 -6
  9. package/dist/api-only.d.ts +17 -6
  10. package/dist/api-only.js +22 -9
  11. package/dist/cli.js +11 -4
  12. package/dist/composio-made.d.ts +26 -1
  13. package/dist/composio-made.js +39 -2
  14. package/dist/composio-preset.d.ts +6 -4
  15. package/dist/composio-preset.js +50 -17
  16. package/dist/computer-held-routes.js +2 -3
  17. package/dist/computer-needs.d.ts +1 -1
  18. package/dist/computer-needs.js +1 -1
  19. package/dist/computer-setting.d.ts +8 -4
  20. package/dist/computer-setting.js +0 -2
  21. package/dist/computers-running.d.ts +8 -0
  22. package/dist/computers-running.js +27 -0
  23. package/dist/computers.d.ts +0 -2
  24. package/dist/computers.js +1 -1
  25. package/dist/console/assets/backend-D5EmB4N3.js +166 -0
  26. package/dist/console/assets/index-DUYLaqiR.js +746 -0
  27. package/dist/console/assets/index-DYhU4adm.css +1 -0
  28. package/dist/console/index.html +2 -2
  29. package/dist/docker-host-addresses.d.ts +23 -3
  30. package/dist/docker-host-addresses.js +90 -18
  31. package/dist/errors.d.ts +4 -0
  32. package/dist/errors.js +7 -0
  33. package/dist/exa-keyless.d.ts +2 -3
  34. package/dist/exa-keyless.js +43 -127
  35. package/dist/firecrawl-keyless.d.ts +41 -0
  36. package/dist/firecrawl-keyless.js +152 -0
  37. package/dist/github-connection.d.ts +50 -1
  38. package/dist/github-connection.js +96 -3
  39. package/dist/github-faux.d.ts +11 -2
  40. package/dist/github-faux.js +138 -7
  41. package/dist/github-pull-request.d.ts +37 -0
  42. package/dist/github-pull-request.js +110 -0
  43. package/dist/handed-secret.d.ts +3 -1
  44. package/dist/handed-secret.js +4 -2
  45. package/dist/harness-keys.d.ts +98 -0
  46. package/dist/harness-keys.js +247 -0
  47. package/dist/harness-recipe-entry.d.ts +14 -9
  48. package/dist/harness-recipe-entry.js +25 -14
  49. package/dist/harness-table.d.ts +16 -1
  50. package/dist/harness-table.js +19 -7
  51. package/dist/harness.d.ts +4 -0
  52. package/dist/harness.js +12 -1
  53. package/dist/host-check.d.ts +2 -0
  54. package/dist/host-check.js +6 -0
  55. package/dist/import-summary.d.ts +1 -1
  56. package/dist/import-summary.js +1 -1
  57. package/dist/import.d.ts +5 -5
  58. package/dist/import.js +54 -67
  59. package/dist/keyless-mcp.d.ts +36 -0
  60. package/dist/keyless-mcp.js +127 -0
  61. package/dist/learn/audit.d.ts +3 -3
  62. package/dist/learn/audit.js +3 -3
  63. package/dist/learn/commit.d.ts +8 -7
  64. package/dist/learn/commit.js +60 -20
  65. package/dist/learn/compile.d.ts +4 -3
  66. package/dist/learn/compile.js +7 -5
  67. package/dist/learn/folder.d.ts +16 -3
  68. package/dist/learn/folder.js +46 -13
  69. package/dist/learn/promote.d.ts +37 -13
  70. package/dist/learn/promote.js +112 -40
  71. package/dist/learn/secrets.js +10 -2
  72. package/dist/learning-routes.d.ts +22 -17
  73. package/dist/learning-routes.js +40 -39
  74. package/dist/learning.js +2 -2
  75. package/dist/live-reach.d.ts +34 -7
  76. package/dist/live-reach.js +76 -11
  77. package/dist/manifest.d.ts +10 -0
  78. package/dist/manifest.js +30 -0
  79. package/dist/mcp-pin-first.d.ts +4 -2
  80. package/dist/mcp-pin-first.js +5 -2
  81. package/dist/mcp-probe.js +2 -2
  82. package/dist/mcp-secret-writes.d.ts +16 -7
  83. package/dist/mcp-secret-writes.js +35 -27
  84. package/dist/mcp-servers-store.d.ts +30 -6
  85. package/dist/mcp-servers-store.js +112 -28
  86. package/dist/mcp-sources.d.ts +10 -2
  87. package/dist/mcp-sources.js +9 -2
  88. package/dist/mcp-store.d.ts +13 -7
  89. package/dist/mcp-store.js +12 -9
  90. package/dist/model-form.d.ts +3 -2
  91. package/dist/model-form.js +11 -7
  92. package/dist/model.d.ts +20 -4
  93. package/dist/model.js +68 -9
  94. package/dist/native/history.d.ts +1 -1
  95. package/dist/native/history.js +2 -2
  96. package/dist/ollama-provider.d.ts +92 -0
  97. package/dist/ollama-provider.js +495 -0
  98. package/dist/openapi/agentrun-v2.openapi.json +2 -2
  99. package/dist/openapi.js +235 -41
  100. package/dist/page.d.ts +11 -3
  101. package/dist/page.js +22 -7
  102. package/dist/place-offers.d.ts +17 -1
  103. package/dist/place-offers.js +46 -5
  104. package/dist/print.js +1 -1
  105. package/dist/purged-workflow.d.ts +35 -7
  106. package/dist/purged-workflow.js +73 -26
  107. package/dist/run-computer.d.ts +2 -0
  108. package/dist/run-computer.js +2 -0
  109. package/dist/run-files.d.ts +4 -0
  110. package/dist/run-files.js +4 -0
  111. package/dist/run-keys.d.ts +2 -4
  112. package/dist/run-keys.js +6 -7
  113. package/dist/run-launch.d.ts +4 -0
  114. package/dist/run-launch.js +4 -0
  115. package/dist/run-reads-over-store.d.ts +3 -2
  116. package/dist/run-reads-over-store.js +66 -2
  117. package/dist/run-secrets.js +5 -2
  118. package/dist/runner/adapter-loop.d.ts +6 -3
  119. package/dist/runner/adapter-loop.js +34 -15
  120. package/dist/runner/adapter-run-spec.d.ts +3 -0
  121. package/dist/runner/adapter-run-spec.js +6 -4
  122. package/dist/runner/audit.js +8 -4
  123. package/dist/runner/beside.d.ts +2 -1
  124. package/dist/runner/beside.js +6 -2
  125. package/dist/runner/claim-secrets.d.ts +5 -8
  126. package/dist/runner/claim-secrets.js +6 -0
  127. package/dist/runner/cli-run-spec.d.ts +1 -1
  128. package/dist/runner/cli-run-spec.js +39 -7
  129. package/dist/runner/harness-loops.d.ts +22 -9
  130. package/dist/runner/harness-loops.js +21 -11
  131. package/dist/runner/held.d.ts +3 -0
  132. package/dist/runner/learning-end.d.ts +1 -1
  133. package/dist/runner/learning-end.js +8 -3
  134. package/dist/runner/loop-contract.d.ts +5 -4
  135. package/dist/runner/main.js +4 -2
  136. package/dist/runner/mcp-claim.d.ts +3 -0
  137. package/dist/runner/mcp-claim.js +26 -2
  138. package/dist/runner/mcp-run.d.ts +3 -0
  139. package/dist/runner/mcp-run.js +2 -1
  140. package/dist/runner/metrics.d.ts +10 -8
  141. package/dist/runner/metrics.js +20 -27
  142. package/dist/runner/model-route.d.ts +3 -0
  143. package/dist/runner/model-route.js +6 -2
  144. package/dist/runner/pr-checkout.d.ts +21 -4
  145. package/dist/runner/pr-checkout.js +103 -4
  146. package/dist/runner/promotion.d.ts +15 -9
  147. package/dist/runner/promotion.js +25 -15
  148. package/dist/runner/run-child-host.js +24 -11
  149. package/dist/runner/run-child.js +3 -1
  150. package/dist/runner/runner-check.d.ts +3 -0
  151. package/dist/runner/runner-check.js +23 -0
  152. package/dist/runner/sdk-loop.js +2 -0
  153. package/dist/runner/workflow-loop.d.ts +2 -2
  154. package/dist/runner/workflow-loop.js +1 -2
  155. package/dist/runner/workflow-spec.d.ts +1 -1
  156. package/dist/runner/workflow-spec.js +6 -6
  157. package/dist/sdk/check.d.ts +4 -1
  158. package/dist/sdk/check.js +2 -1
  159. package/dist/sdk/runs.d.ts +2 -2
  160. package/dist/sdk/runs.js +8 -6
  161. package/dist/secret-cut.js +2 -1
  162. package/dist/secret-writes.d.ts +3 -2
  163. package/dist/secret-writes.js +1 -1
  164. package/dist/server.d.ts +55 -8
  165. package/dist/server.js +363 -118
  166. package/dist/standard-webhooks.d.ts +11 -0
  167. package/dist/standard-webhooks.js +20 -2
  168. package/dist/store/agent-body.d.ts +2 -2
  169. package/dist/store/agent-body.js +2 -2
  170. package/dist/store/index.d.ts +1 -1
  171. package/dist/store/schema.js +5 -2
  172. package/dist/store/sqlite/store.js +90 -34
  173. package/dist/store/store.d.ts +54 -14
  174. package/dist/store-reads/journal.d.ts +7 -2
  175. package/dist/store-reads/journal.js +9 -6
  176. package/dist/store-reads/learning.d.ts +12 -9
  177. package/dist/store-reads/learning.js +18 -24
  178. package/dist/store-view.d.ts +0 -5
  179. package/dist/store-view.js +9 -8
  180. package/dist/suggestions.d.ts +282 -0
  181. package/dist/suggestions.js +919 -0
  182. package/dist/telemetry.d.ts +8 -1
  183. package/dist/telemetry.js +12 -4
  184. package/dist/template-eval.d.ts +49 -4
  185. package/dist/template-eval.js +168 -45
  186. package/dist/template-import.d.ts +17 -0
  187. package/dist/template-import.js +36 -2
  188. package/dist/templates.d.ts +83 -76
  189. package/dist/templates.js +29 -48
  190. package/dist/timeline/labels.d.ts +2 -2
  191. package/dist/timeline/labels.js +2 -2
  192. package/dist/timeline/timeline.d.ts +2 -2
  193. package/dist/timeline/timeline.js +1 -1
  194. package/dist/tool-plane.d.ts +17 -9
  195. package/dist/tool-plane.js +38 -17
  196. package/dist/tools.js +2 -2
  197. package/dist/trigger-launch-hook.d.ts +19 -9
  198. package/dist/trigger-launch-hook.js +35 -25
  199. package/dist/trigger-targets.d.ts +18 -8
  200. package/dist/trigger-targets.js +42 -19
  201. package/dist/triggers.d.ts +85 -23
  202. package/dist/triggers.js +303 -96
  203. package/dist/validate.d.ts +1 -1
  204. package/dist/validate.js +2 -2
  205. package/dist/web-fake.js +3 -3
  206. package/dist/web-fetch-direct.d.ts +4 -0
  207. package/dist/web-fetch-direct.js +8 -1
  208. package/dist/web-fetch.d.ts +12 -3
  209. package/dist/web-fetch.js +47 -14
  210. package/dist/web-search.d.ts +33 -4
  211. package/dist/web-search.js +100 -41
  212. package/dist/webhooks.js +4 -5
  213. package/dist/workspace/synced-folder.d.ts +1 -1
  214. package/dist/workspace/synced-folder.js +11 -14
  215. package/launcher/agentrun-serve +5 -1
  216. package/package.json +17 -13
  217. package/templates/README.md +5 -4
  218. package/templates/agent-scout/agent.md +46 -0
  219. package/templates/agent-scout/skills/scout/SKILL.md +88 -0
  220. package/templates/agent-scout/skills/scout/suggestions.schema.json +112 -0
  221. package/dist/console/assets/index-BFgyZzF_.js +0 -734
  222. package/dist/console/assets/index-DbilxljH.css +0 -1
  223. package/dist/import-sources.d.ts +0 -116
  224. package/dist/import-sources.js +0 -693
@@ -9,7 +9,15 @@
9
9
  // endpoint off loopback takes no request without a good, fresh proof for its own viewer. The proof is not the viewer's:
10
10
  // the hello's token still decides who watches. The hop is plain HTTP, for a private network (the server and its
11
11
  // runners' own); TLS on it is a later step.
12
+ //
13
+ // Runners that are replicas of one deployment (Kubernetes pods, a platform's instances) have no host name of their own
14
+ // the server resolves, and their addresses change at each start. For them both settings take an IPv4 block in CIDR form:
15
+ // a runner whose AGENTRUN_RUNNER_LIVE_HOST is a block answers at its own address in that block (its one network
16
+ // interface address there), and a server whose AGENTRUN_RUNNER_HOSTS lists a block dials any IPv4 address in it. The
17
+ // block is the private network the runners' addresses come from (a cluster's pod range), and the proof above still
18
+ // guards every request on it.
12
19
  import { createHmac, hkdfSync, timingSafeEqual } from "node:crypto";
20
+ import { networkInterfaces } from "node:os";
13
21
  /** The header the proxy's proof travels in. */
14
22
  export const LIVE_PROOF_HEADER = "x-agentrun-live";
15
23
  /** How far a proof's time may be from the endpoint's clock. */
@@ -23,26 +31,83 @@ const LABEL = "agentrun live proxy v1";
23
31
  export const isLiveHost = (host) => typeof host === "string" && HOST.test(host);
24
32
  const proofKey = (sealKey) => Buffer.from(hkdfSync("sha256", sealKey, Buffer.alloc(0), LABEL, 32));
25
33
  const mac = (key, viewerId, at) => createHmac("sha256", key).update(`${viewerId}\n${at}`).digest("hex");
26
- /** The server's reach, from its environment (AGENTRUN_RUNNER_HOSTS) and the seal key. A name that is not a host is left
27
- * out. */
34
+ /** The shortest prefix a block may have: a /8 is a whole private range, and anything wider is no runners' network. */
35
+ export const MIN_BLOCK_BITS = 8;
36
+ const IPV4 = /^(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/;
37
+ /** `address` (dotted IPv4, no leading zeros) as a 32-bit number, or undefined. */
38
+ export function ipv4Of(address) {
39
+ const match = IPV4.exec(address);
40
+ return match ? match.slice(1).reduce((sum, octet) => sum * 256 + Number(octet), 0) : undefined;
41
+ }
42
+ const maskOf = (bits) => (bits === 0 ? 0 : (0xffffffff << (32 - bits)) >>> 0);
43
+ /** `value` as an IPv4 block: its address the block's network address (no host bits set) and its prefix from
44
+ * MIN_BLOCK_BITS to 32; else undefined. */
45
+ export function ipv4BlockOf(value) {
46
+ const match = /^([0-9.]+)\/(\d{1,2})$/.exec(value);
47
+ if (!match)
48
+ return undefined;
49
+ const base = ipv4Of(match[1]);
50
+ const bits = Number(match[2]);
51
+ if (base === undefined || bits < MIN_BLOCK_BITS || bits > 32 || ((base & ~maskOf(bits)) >>> 0) !== 0)
52
+ return undefined;
53
+ return { base, bits };
54
+ }
55
+ /** Whether IPv4 `address` is in `block`. */
56
+ export const inBlock = (address, block) => ((address & maskOf(block.bits)) >>> 0) === block.base;
57
+ /** The server's reach, from its environment (AGENTRUN_RUNNER_HOSTS: host names, IPv4 addresses and IPv4 blocks) and
58
+ * the seal key. An entry that is none of them is left out. */
28
59
  export function liveReachOf(env, sealKey) {
29
- const hosts = new Set((env.AGENTRUN_RUNNER_HOSTS ?? "").split(",").map((host) => host.trim().toLowerCase()).filter(isLiveHost));
30
- return { hosts, key: proofKey(sealKey) };
60
+ const entries = (env.AGENTRUN_RUNNER_HOSTS ?? "").split(",").map((host) => host.trim().toLowerCase());
61
+ const hosts = new Set(entries.filter(isLiveHost));
62
+ const blocks = entries.map(ipv4BlockOf).filter((block) => block !== undefined);
63
+ return { hosts, blocks, key: proofKey(sealKey) };
31
64
  }
32
- /** Where the server dials `host` (a row's): loopback with none; the host when it is one of its runners'; else nowhere. */
65
+ /** Where the server dials `host` (a row's): loopback with none; the host when it is one of its runners' or an IPv4
66
+ * address in one of their blocks; else nowhere. */
33
67
  export function dialHost(host, reach) {
34
68
  if (host === undefined || host === LOOPBACK)
35
69
  return LOOPBACK;
36
- return reach?.hosts.has(host.toLowerCase()) ? host : undefined;
70
+ if (reach === undefined)
71
+ return undefined;
72
+ if (reach.hosts.has(host.toLowerCase()))
73
+ return host;
74
+ const address = ipv4Of(host);
75
+ return address !== undefined && reach.blocks.some((block) => inBlock(address, block)) ? host : undefined;
37
76
  }
38
77
  /** The proxy's proof for viewer `viewerId`, at `at` (ms). */
39
78
  export const liveProof = (reach, viewerId, at = Date.now()) => `${at}.${mac(reach.key, viewerId, at)}`;
79
+ /** A runner's live host it cannot take: its AGENTRUN_RUNNER_LIVE_HOST names a block that holds none, or more than one,
80
+ * of this machine's addresses. Thrown at the runner's start, so it never says it answers where the server cannot
81
+ * reach it. */
82
+ export class RunnerLiveRefused extends Error {
83
+ name = "RunnerLiveRefused";
84
+ }
85
+ /** This machine's one IPv4 address in `block` (AGENTRUN_RUNNER_LIVE_HOST as a block, named `given`); refused in words
86
+ * with none or several. */
87
+ function ownAddressIn(block, given, interfaces) {
88
+ const found = new Set();
89
+ for (const addresses of Object.values(interfaces())) {
90
+ for (const one of addresses ?? []) {
91
+ const address = one.family === "IPv4" && !one.internal ? ipv4Of(one.address) : undefined;
92
+ if (address !== undefined && inBlock(address, block))
93
+ found.add(one.address);
94
+ }
95
+ }
96
+ if (found.size === 1)
97
+ return [...found][0];
98
+ throw new RunnerLiveRefused(found.size === 0
99
+ ? `AGENTRUN_RUNNER_LIVE_HOST is ${given}, and no network interface of this machine has an IPv4 address in it: name the block this runner's address is in, or the host the server reaches it at`
100
+ : `AGENTRUN_RUNNER_LIVE_HOST is ${given}, and this machine has ${found.size} IPv4 addresses in it (${[...found].sort().join(", ")}): name a narrower block, or the host the server reaches it at`);
101
+ }
40
102
  /** The runner's live host, from its environment (AGENTRUN_RUNNER_LIVE_HOST, AGENTRUN_RUNNER_LIVE_BIND) and the seal key;
41
- * undefined with none (or one that is not a host): its viewers answer on loopback, as on a server's own machine. */
42
- export function runnerLiveOf(env, sealKey) {
103
+ * undefined with none (or one that is not a host): its viewers answer on loopback, as on a server's own machine. An
104
+ * IPv4 block for a host is this machine's own address in it (refused, RunnerLiveRefused, with none or several). */
105
+ export function runnerLiveOf(env, sealKey, interfaces = networkInterfaces) {
43
106
  // Lower case, as a URL's hostname reads a DNS name and the server's runners' hosts are read (liveReachOf): one form for
44
107
  // the links, the origins and the rows.
45
- const host = env.AGENTRUN_RUNNER_LIVE_HOST?.trim().toLowerCase();
108
+ const given = env.AGENTRUN_RUNNER_LIVE_HOST?.trim().toLowerCase();
109
+ const block = given === undefined ? undefined : ipv4BlockOf(given);
110
+ const host = block !== undefined ? ownAddressIn(block, given, interfaces) : given;
46
111
  if (!isLiveHost(host) || host === LOOPBACK)
47
112
  return undefined;
48
113
  const bind = env.AGENTRUN_RUNNER_LIVE_BIND?.trim().toLowerCase();
@@ -53,8 +118,8 @@ export function runnerLiveOf(env, sealKey) {
53
118
  const runKey = (key, runId) => createHmac("sha256", key).update(`${RUN_LABEL}\n${runId}`).digest();
54
119
  /** The run label of runKey: another MAC than the proof's own. */
55
120
  const RUN_LABEL = "agentrun live run v1";
56
- /** The server's reach for run `runId`'s viewers: its hosts, under that run's key. */
57
- export const reachForRun = (reach, runId) => ({ hosts: reach.hosts, key: runKey(reach.key, runId) });
121
+ /** The server's reach for run `runId`'s viewers: its hosts and blocks, under that run's key. */
122
+ export const reachForRun = (reach, runId) => ({ hosts: reach.hosts, blocks: reach.blocks, key: runKey(reach.key, runId) });
58
123
  /** A runner's live address for run `runId`'s viewers: its host and bind, under that run's key. */
59
124
  export const liveForRun = (live, runId) => ({ host: live.host, bind: live.bind, key: runKey(live.key, runId) });
60
125
  /** Whether `req` carries a good, fresh proof for viewer `viewerId` under `live`'s key: its time within `windowMs` of
@@ -0,0 +1,10 @@
1
+ /** A file's front matter, parsed (core schema, unique keys, no merge keys, no aliases), and the body after it; or why it
2
+ * does not read (`problem`, said after "its front matter"); undefined when the file has none. */
3
+ export declare function frontMatter(text: string): {
4
+ data: unknown;
5
+ body: string;
6
+ } | {
7
+ problem: string;
8
+ } | undefined;
9
+ /** agent.md's manifest, its front matter when that reads as a mapping, else undefined (the package reader says why). */
10
+ export declare function manifestOf(text: string): Record<string, unknown> | undefined;
@@ -0,0 +1,30 @@
1
+ // A package file's YAML front matter, read one way wherever it is read: the package reader (templates.ts), its eval
2
+ // cases (template-eval.ts) and `agentrun deploy`, which imports this module (`@parcha/agentrun-serve/manifest`) to find
3
+ // the files a folder's package holds before it sends them. It loads nothing but the YAML parser.
4
+ import { parseDocument } from "yaml";
5
+ /** The front matter: the text between a `---` line at the file's top and the next `---` line. */
6
+ const FRONT = /^---\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/;
7
+ /** A file's front matter, parsed (core schema, unique keys, no merge keys, no aliases), and the body after it; or why it
8
+ * does not read (`problem`, said after "its front matter"); undefined when the file has none. */
9
+ export function frontMatter(text) {
10
+ const match = FRONT.exec(text);
11
+ if (!match)
12
+ return undefined;
13
+ const doc = parseDocument(match[1], { schema: "core", merge: false, uniqueKeys: true, strict: true });
14
+ if (doc.errors.length)
15
+ return { problem: `is not YAML: ${doc.errors[0].message.split("\n")[0]}` };
16
+ try {
17
+ return { data: doc.toJS({ maxAliasCount: 0 }), body: text.slice(match[0].length) };
18
+ }
19
+ catch (error) {
20
+ return { problem: `is refused: ${error.message}` };
21
+ }
22
+ }
23
+ /** agent.md's manifest, its front matter when that reads as a mapping, else undefined (the package reader says why). */
24
+ export function manifestOf(text) {
25
+ const front = frontMatter(text);
26
+ if (!front || "problem" in front)
27
+ return undefined;
28
+ const { data } = front;
29
+ return typeof data === "object" && data !== null && !Array.isArray(data) ? data : undefined;
30
+ }
@@ -29,11 +29,13 @@ export declare function pinFirst(revision: {
29
29
  * that server's own ports (`own`, Serve.own). `githubApp`:
30
30
  * the run's GitHub App access (runner/mcp-github.ts), which lists a `github_app` server with a token of the run's
31
31
  * repository, metadata read alone, as a save lists it with one (github-connection.ts tokenForListing); without it such a
32
- * server can't be listed. `appOrigin`: a test's fake GitHub MCP (McpServersOverStore.appOrigin). */
33
- export declare function registryListing(store: Parameters<typeof mcpServersOverStore>[0], sealKey: Buffer, { loopback, own, network, githubApp, appOrigin }?: {
32
+ * server can't be listed. `appOrigin`: a test's fake GitHub MCP (McpServersOverStore.appOrigin). `composioOrigin`: a
33
+ * test's fake Composio MCP (McpServersOverStore.composioOrigin). */
34
+ export declare function registryListing(store: Parameters<typeof mcpServersOverStore>[0], sealKey: Buffer, { loopback, own, network, githubApp, appOrigin, composioOrigin }?: {
34
35
  loopback?: boolean;
35
36
  own?: readonly string[];
36
37
  network?: OAuthNetwork;
37
38
  githubApp?: GithubAppAccess;
38
39
  appOrigin?: string;
40
+ composioOrigin?: string;
39
41
  }): (server: string, stop?: AbortSignal) => Promise<PinListing>;
@@ -68,8 +68,9 @@ export async function pinFirst(revision, deps) {
68
68
  * that server's own ports (`own`, Serve.own). `githubApp`:
69
69
  * the run's GitHub App access (runner/mcp-github.ts), which lists a `github_app` server with a token of the run's
70
70
  * repository, metadata read alone, as a save lists it with one (github-connection.ts tokenForListing); without it such a
71
- * server can't be listed. `appOrigin`: a test's fake GitHub MCP (McpServersOverStore.appOrigin). */
72
- export function registryListing(store, sealKey, { loopback = false, own = [], network, githubApp, appOrigin } = {}) {
71
+ * server can't be listed. `appOrigin`: a test's fake GitHub MCP (McpServersOverStore.appOrigin). `composioOrigin`: a
72
+ * test's fake Composio MCP (McpServersOverStore.composioOrigin). */
73
+ export function registryListing(store, sealKey, { loopback = false, own = [], network, githubApp, appOrigin, composioOrigin } = {}) {
73
74
  let registry;
74
75
  // The listing tokens minted and not yet revoked, and how many listings are under way: no one holds a listing token
75
76
  // after its listing (the claim's cleanup reaches only githubTokens' tokens), so once no listing is under way, each is
@@ -82,6 +83,8 @@ export function registryListing(store, sealKey, { loopback = false, own = [], ne
82
83
  opened.attach("", "", loopback, own);
83
84
  if (appOrigin)
84
85
  opened.appOrigin = appOrigin;
86
+ if (composioOrigin)
87
+ opened.composioOrigin = composioOrigin;
85
88
  if (githubApp)
86
89
  opened.appToken = async () => {
87
90
  const got = await listingToken(githubApp);
package/dist/mcp-probe.js CHANGED
@@ -5,7 +5,7 @@
5
5
  // Nothing here opens a credential or touches a store: listServer connects to a URL with the official SDK client, agrees a
6
6
  // protocol revision and lists every tool (all pages, under caps); the validation turns a request body into a URL, auth and
7
7
  // prices, or a 422; no redirect is followed, so a credential goes only where the owner sends it.
8
- import { COMPOSIO_ACCOUNT_ID, COMPOSIO_USER, COMPOSIO_USER_ID } from "./composio-preset.js";
8
+ import { COMPOSIO_ACCOUNT_ID, COMPOSIO_USER, COMPOSIO_USER_ID, COMPOSIO_USER_ID_WORDS } from "./composio-preset.js";
9
9
  import { ApiError, invalid } from "./errors.js";
10
10
  import { metaToolOf } from "./mcp-meta.js";
11
11
  import { SIGN_IN_AGAIN } from "./mcp-oauth.js";
@@ -278,7 +278,7 @@ function composioBindingOf(field, entry, issues) {
278
278
  const user = entry.composio_user_id;
279
279
  const account = entry.connected_account_id;
280
280
  if (typeof user !== "string" || !COMPOSIO_USER_ID.test(user))
281
- issues.push({ field: `${field}.composio_user_id`, reason: "invalid", message: "composio_user_id is the Composio user this run's calls run as: letters, digits and . _ @ : - (1 to 128)." });
281
+ issues.push({ field: `${field}.composio_user_id`, reason: "invalid", message: `composio_user_id is the Composio user this run's calls run as: ${COMPOSIO_USER_ID_WORDS}.` });
282
282
  // The preset's default user is the one single-user preset servers call as: a run that forgot to name its own never lands there.
283
283
  else if (user === COMPOSIO_USER)
284
284
  issues.push({ field: `${field}.composio_user_id`, reason: "not_allowed", message: "That composio_user_id is the Composio preset's shared default user, the one single-user preset servers call as: bind the run to its own person's Composio user." });
@@ -2,24 +2,33 @@ import { type SecretRequest } from "./secret-writes.js";
2
2
  import type { McpCredentialMark } from "./store/index.js";
3
3
  /** Whether `operation`'s `body` writes an MCP secret by the body alone (see above). */
4
4
  export declare function mcpWritesSecret(operation: string, body: unknown): boolean;
5
- /** The least of a saved server's row a save's check reads: its auth type, its sealed credential and when that was set. */
5
+ /** The least of a saved server's row a save's check reads: its auth type, its sealed credential and when that was set,
6
+ * and when the row was made (its source record is bound to it). */
6
7
  type SavedRow = {
7
8
  auth: string;
8
9
  sealed: unknown;
9
10
  credentialChangedAt?: number | null;
11
+ createdAt?: number;
10
12
  };
11
13
  /** A saved server's credential as a writer read it (McpCredentialMark): its auth type, whether one is sealed, and when it
12
14
  * was set. A save let through against one mark writes only while the row still has it, in the store's one statement
13
15
  * (Mcp.putIfCredential), so it never lands over a credential saved or signed in with after the check. */
14
16
  export declare const credentialMark: (row: SavedRow | undefined) => McpCredentialMark;
15
- /** Whether a save of the server its path names (with no value in its body) would drop or change the credential the
16
- * server holds: it holds one, and the save names another auth type, or none (a body with no auth is none). */
17
- export declare function mcpSaveDropsSecret(body: unknown, request: SecretRequest): Promise<boolean>;
18
- /** Whether removing the server its path names drops a credential: it holds a sealed one. A server saved with none (an
19
- * eval's fake, say) is the token's to remove; the removal lands only while that is still so (request.seen). */
20
- export declare function mcpDeleteDropsSecret(_body: unknown, request: SecretRequest): Promise<boolean>;
17
+ /** The one rule for the token's write over the saved server its path names, whatever the route: a save over it (the
18
+ * generic save, a Composio save) or its removal. Refused unless the token saved that very row (its source record's mark,
19
+ * mcp-sources.ts savedByToken) and it seals no credential: an owner's server stays the owner's, sealed or not, so the
20
+ * token never drops or changes its credential, moves it, or removes what it made at Composio. A new name has nothing to
21
+ * write over. The write lands only while the row's credential is still the one read here (request.seen) and the row
22
+ * still carries the token's mark, both compared in the store's statement that writes or removes it (McpServers save and
23
+ * remove), so an owner's save landing after this check is never written over or removed. */
24
+ export declare function tokenWriteOverRefused(_body: unknown, request: SecretRequest): Promise<boolean>;
21
25
  /** MCP's operations the one gate reads: the predicates above decide each request. */
22
26
  export declare const MCP_SECRET_OPERATIONS: readonly ["saveMcpServer", "startMcpOAuth", "putMcpPrivateHosts", "deleteMcpServer"];
27
+ /** A Composio save that names its key by api_key_env (the server keeps the variable's name, never its value) writes no
28
+ * secret only on an API-only server, which has no owner to save the key from the console: its token's own save, over a
29
+ * new name or a server the token saved, by the one rule (tokenWriteOverRefused). Anywhere else the owner saves keys from
30
+ * the console, so the token's is the one refusal as before. */
31
+ export declare function composioSaveDropsSecret(body: unknown, request: SecretRequest): Promise<boolean>;
23
32
  /** The URL a refusal's console link may carry: only one a save would take as it is (http or https, at most 2048
24
33
  * characters, no user or password, no query parameter named like a credential: urlOf, the save's own check), with
25
34
  * nothing in it shaped like a secret (secretShapes, the learning guard's shapes), no key-shaped path segment or query
@@ -1,17 +1,19 @@
1
1
  // MCP's predicates for the one secret-write gate (secret-writes.ts): which MCP operations the server's dispatch takes from
2
2
  // the owner's signed-in page alone, refusing every token.
3
3
  // - A save that sends a value (a bearer token or a header's value, in any auth type: a value sent is a value, even in a
4
- // body the save then refuses) writes a secret; so does one that would DROP or CHANGE the credential a saved server
5
- // holds (another auth type, or none), read from the store.
4
+ // body the save then refuses) writes a secret.
6
5
  // - A sign-in's start always writes one: its callback seals whatever token set the sign-in it started returns, so who
7
6
  // starts it decides whose credential the server's runs use.
8
- // - Removing a server that holds a credential drops it (read from the store); the private-network OAuth hosts count whole,
9
- // since they widen where a sign-in sends its code and tokens.
10
- // A server with no credential, a save that keeps the sealed one (prices, tools, url), a preview and a refresh (each keeps
11
- // nothing new) stay open to a token.
7
+ // - The private-network OAuth hosts count whole, since they widen where a sign-in sends its code and tokens.
8
+ // - The token saves over and removes only a server the token saved that seals no credential (tokenWriteOverRefused: one
9
+ // rule for every such route, read from the store): the owner's stays the owner's, sealed or not, so the token never
10
+ // drops or changes its credential, moves it, or removes what it made at Composio.
11
+ // A new server with no credential, the token's own server, a preview and a refresh (each keeps nothing new) stay open to a
12
+ // token.
12
13
  import { COMPOSIO_TOOLKIT } from "./composio-preset.js";
13
14
  import { secretShapes } from "./learn/secrets.js";
14
15
  import { urlOf } from "./mcp-probe.js";
16
+ import { mcpSourceKey, savedByToken } from "./mcp-sources.js";
15
17
  import { registerNotSecretWrite, registerSecretPage, registerSecretWrite } from "./secret-writes.js";
16
18
  import { MCP_SERVER_NAME } from "./tool-names.js";
17
19
  import { isObject } from "./validate.js";
@@ -32,40 +34,46 @@ export function mcpWritesSecret(operation, body) {
32
34
  * was set. A save let through against one mark writes only while the row still has it, in the store's one statement
33
35
  * (Mcp.putIfCredential), so it never lands over a credential saved or signed in with after the check. */
34
36
  export const credentialMark = (row) => (row ? { auth: row.auth, sealed: row.sealed !== null && row.sealed !== undefined, changedAt: row.credentialChangedAt ?? null } : null);
35
- /** Whether a save of the server its path names (with no value in its body) would drop or change the credential the
36
- * server holds: it holds one, and the save names another auth type, or none (a body with no auth is none). */
37
- export async function mcpSaveDropsSecret(body, request) {
37
+ /** The one rule for the token's write over the saved server its path names, whatever the route: a save over it (the
38
+ * generic save, a Composio save) or its removal. Refused unless the token saved that very row (its source record's mark,
39
+ * mcp-sources.ts savedByToken) and it seals no credential: an owner's server stays the owner's, sealed or not, so the
40
+ * token never drops or changes its credential, moves it, or removes what it made at Composio. A new name has nothing to
41
+ * write over. The write lands only while the row's credential is still the one read here (request.seen) and the row
42
+ * still carries the token's mark, both compared in the store's statement that writes or removes it (McpServers save and
43
+ * remove), so an owner's save landing after this check is never written over or removed. */
44
+ export async function tokenWriteOverRefused(_body, request) {
38
45
  const [name] = request.params;
39
46
  if (!name)
40
47
  return false;
41
- const was = await request.store.mcp.server(name);
42
- // What the save is let through against: it lands only if the credential is still this one.
48
+ const store = request.store;
49
+ const was = await store.mcp.server(name);
43
50
  request.seen = credentialMark(was);
44
- if (!was || was.sealed === null || was.sealed === undefined)
51
+ if (!was)
45
52
  return false;
46
- const auth = isObject(body) ? body.auth : undefined;
47
- const type = auth === undefined ? "none" : isObject(auth) ? auth.type : undefined;
48
- return type !== was.auth;
49
- }
50
- /** Whether removing the server its path names drops a credential: it holds a sealed one. A server saved with none (an
51
- * eval's fake, say) is the token's to remove; the removal lands only while that is still so (request.seen). */
52
- export async function mcpDeleteDropsSecret(_body, request) {
53
- const [name] = request.params;
54
- if (!name)
55
- return false;
56
- const was = await request.store.mcp.server(name);
57
- request.seen = credentialMark(was);
58
- return !!was && was.sealed !== null && was.sealed !== undefined;
53
+ return (was.sealed !== null && was.sealed !== undefined) || !savedByToken(await store.settings.get(mcpSourceKey(name)), was.createdAt);
59
54
  }
60
55
  /** MCP's operations the one gate reads: the predicates above decide each request. */
61
56
  export const MCP_SECRET_OPERATIONS = ["saveMcpServer", "startMcpOAuth", "putMcpPrivateHosts", "deleteMcpServer"];
62
- const STORED = { saveMcpServer: mcpSaveDropsSecret, deleteMcpServer: mcpDeleteDropsSecret };
57
+ const STORED = { saveMcpServer: tokenWriteOverRefused, deleteMcpServer: tokenWriteOverRefused };
63
58
  for (const operation of MCP_SECRET_OPERATIONS)
64
59
  registerSecretWrite(operation, (body) => mcpWritesSecret(operation, body), STORED[operation]);
65
60
  // The Composio preset takes the owner's API key and seals it as an MCP header: both routes are the owner's session alone,
66
61
  // whatever the body (the listing sends the key too, and only the session may type one).
67
62
  registerSecretWrite("listComposioTools", () => true);
68
- registerSecretWrite("saveComposioServer", () => true);
63
+ registerSecretWrite("saveComposioServer", composioSaveSendsKey, composioSaveDropsSecret);
64
+ // A save's body that sends a key's value, or anything but api_key_env alone in its place: a secret written.
65
+ function composioSaveSendsKey(body) {
66
+ return !(isObject(body) && body.api_key === undefined && body.api_key_env !== undefined);
67
+ }
68
+ /** A Composio save that names its key by api_key_env (the server keeps the variable's name, never its value) writes no
69
+ * secret only on an API-only server, which has no owner to save the key from the console: its token's own save, over a
70
+ * new name or a server the token saved, by the one rule (tokenWriteOverRefused). Anywhere else the owner saves keys from
71
+ * the console, so the token's is the one refusal as before. */
72
+ export async function composioSaveDropsSecret(body, request) {
73
+ if (!request.apiOnly || !request.params[0])
74
+ return true;
75
+ return tokenWriteOverRefused(body, request);
76
+ }
69
77
  // A Composio server's webhook subscription (composio-triggers.ts): a rotate seals its new secret, a delete drops it.
70
78
  registerSecretWrite("rotateComposioSecret", () => true);
71
79
  registerSecretWrite("deleteComposioSubscription", () => true);
@@ -1,10 +1,10 @@
1
1
  import { type Listed, type McpPrices, type McpTool } from "./mcp-probe.js";
2
2
  import { type SecretMeta } from "./secret-writes.js";
3
3
  import { type ClientKind, type OAuthNetwork } from "./mcp-oauth.js";
4
- import { type Cleanup, type ComposioMade } from "./composio-made.js";
4
+ import { type Cleanup, COMPOSIO_KEY_ENV, type ComposioMade } from "./composio-made.js";
5
5
  import { type RecordedRow, type SourceRecord } from "./mcp-sources.js";
6
6
  import { type ToolSettingsMap } from "./tool-plane.js";
7
- import { type McpCredentialMark, type Mcp, type McpOauth, type Settings, type Store } from "./store/index.js";
7
+ import { type McpCredentialMark, type Mcp, type McpOauth, type McpServerRow, type Settings, type Store } from "./store/index.js";
8
8
  import { MCP_ALLOW_LOOPBACK_ENV } from "./start-switches.js";
9
9
  /** The store slice this layer reads and writes; `settings` for the private-network OAuth hosts the owner allows and each
10
10
  * server's source and toolkit (mcp-sources.ts). */
@@ -64,10 +64,15 @@ export declare class McpServersOverStore {
64
64
  /** The one origin a github_app server may have (GITHUB_MCP_ORIGIN; a test's fake through the server's seam): the App's
65
65
  * tokens are minted for, and sent to, nothing else. */
66
66
  appOrigin: string;
67
+ /** The one origin a key read from the environment is sent to (COMPOSIO_ORIGIN; a test's fake through the server's
68
+ * seam): a Composio server saved with api_key_env at any other address is refused (composioEnvKey). */
69
+ composioOrigin: string;
67
70
  private readonly sealKey;
68
71
  private readonly signIns;
69
72
  /** The callbacks under way, which close() waits out before the server lets its data go. */
70
73
  private readonly inflight;
74
+ /** Each server name's save turn (nameTurn): the last save in it, settled either way. */
75
+ private readonly nameTurns;
71
76
  private readonly stopped;
72
77
  /** Whether this server is a local install (attach): only then may an MCP server's URL be on loopback. */
73
78
  private loopback;
@@ -142,6 +147,7 @@ export declare class McpServersOverStore {
142
147
  expires_at?: string | undefined;
143
148
  } | undefined;
144
149
  auth: {
150
+ api_key_env?: "COMPOSIO_API_KEY" | undefined;
145
151
  headers?: string[] | undefined;
146
152
  type: string;
147
153
  };
@@ -184,6 +190,7 @@ export declare class McpServersOverStore {
184
190
  expires_at?: string | undefined;
185
191
  } | undefined;
186
192
  auth: {
193
+ api_key_env?: "COMPOSIO_API_KEY" | undefined;
187
194
  headers?: string[] | undefined;
188
195
  type: string;
189
196
  };
@@ -244,8 +251,11 @@ export declare class McpServersOverStore {
244
251
  * server's record now owns or the caller removes. `guard`, a preset row's: the turn its write and cleanup take, once
245
252
  * the listing is done (never across it), and the check of the triggers that use it, made in that turn before a write
246
253
  * that leaves what they stand on (an ordinary save moving the row off Composio, a preset save as another user or auth
247
- * config): refused, nothing written. */
248
- save(name: string, body: Record<string, unknown>, stop?: AbortSignal, checkedAgainst?: McpCredentialMark, made?: SourceRecord, stands?: ComposioMade, dropped?: (left: ComposioDropped) => void, guard?: SaveGuard): Promise<{
254
+ * config): refused, nothing written. `byToken`: the API token makes the save (a request the secret-write gate read), so
255
+ * a row it makes is recorded as the token's (mcp-sources.ts savedByToken), and it writes over a saved row only while
256
+ * that row still carries the token's mark, compared in the row's own statement (412, nothing written, when an owner's
257
+ * save took it meanwhile). */
258
+ save(name: string, body: Record<string, unknown>, stop?: AbortSignal, checkedAgainst?: McpCredentialMark, made?: SourceRecord, stands?: ComposioMade, dropped?: (left: ComposioDropped) => void, guard?: SaveGuard, byToken?: boolean): Promise<{
249
259
  listed_at: string;
250
260
  updated_at: string;
251
261
  secret: SecretMeta;
@@ -256,6 +266,7 @@ export declare class McpServersOverStore {
256
266
  expires_at?: string | undefined;
257
267
  } | undefined;
258
268
  auth: {
269
+ api_key_env?: "COMPOSIO_API_KEY" | undefined;
259
270
  headers?: string[] | undefined;
260
271
  type: string;
261
272
  };
@@ -286,6 +297,11 @@ export declare class McpServersOverStore {
286
297
  source: "url" | "github" | "composio";
287
298
  toolkit: string | null;
288
299
  }>;
300
+ /** `work` in the turn of the saved server `name`, after every save of that name already in it: a save writes its row and
301
+ * then its source record (mcp-sources.ts), so the token's mark, written after its row, never lands on a row an owner's
302
+ * save wrote between the two. One server holds a store (StoreOwned), so the turn is this process's. A delete takes
303
+ * none: its statement compares the mark itself (Mcp.removeIfCredential). */
304
+ private nameTurn;
289
305
  /** POST refresh: list the saved server's tools again, keep them, and say what was added, removed and changed. */
290
306
  refresh(name: string, stop?: AbortSignal): Promise<{
291
307
  added: string[];
@@ -302,6 +318,7 @@ export declare class McpServersOverStore {
302
318
  expires_at?: string | undefined;
303
319
  } | undefined;
304
320
  auth: {
321
+ api_key_env?: "COMPOSIO_API_KEY" | undefined;
305
322
  headers?: string[] | undefined;
306
323
  type: string;
307
324
  };
@@ -341,8 +358,12 @@ export declare class McpServersOverStore {
341
358
  * none: removing it drops no secret); the row goes only while it is still that, in the store's one statement, so a
342
359
  * credential saved meanwhile is never dropped by it. An OAuth one's sign-in is then let go at its authorization server
343
360
  * (its refresh token revoked, RFC 7009, where its metadata names a revocation_endpoint), behind the answer: best effort,
344
- * never holding or failing the removal. A claimed run sees the removal at its next call (runner/mcp-claim.ts check). */
345
- remove(name: string, checkedAgainst?: McpCredentialMark): Promise<{
361
+ * never holding or failing the removal. A claimed run sees the removal at its next call (runner/mcp-claim.ts check).
362
+ * `byToken`: the API token removes it, which it may only while the row is one the token saved (savedByToken): its
363
+ * credential and its mark are compared in the deleting statement itself (Mcp.removeIfCredential), never in a read
364
+ * before it, so an owner's save that lands after the gate's check (it drops the mark in the transaction that writes
365
+ * its row) is never removed, and nothing is sent to Composio for it. */
366
+ remove(name: string, checkedAgainst?: McpCredentialMark, byToken?: boolean): Promise<{
346
367
  composio?: ComposioHandle;
347
368
  }>;
348
369
  /** Whether `name` is a Composio preset server now (auth headers, source composio): a save of it takes the Composio turn,
@@ -379,6 +400,9 @@ export declare class McpServersOverStore {
379
400
  * read and checked, never the one saved now: a save at another address with a new credential while the caller waited
380
401
  * (its address check, a listing) must never have that credential sent to the old address. */
381
402
  private opened;
403
+ /** The variable a Composio server saved with api_key_env reads its key from (composio-made.ts key_env): a headers row
404
+ * that seals no credential, whose record for this row names it. None for every other row. */
405
+ keyEnvOf(row: McpServerRow): Promise<typeof COMPOSIO_KEY_ENV | undefined>;
382
406
  /** The saved OAuth token set of `row` (the row read and checked, as opened), for a sign-in again that reuses the kept
383
407
  * client. */
384
408
  private openedSet;