@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
@@ -0,0 +1,247 @@
1
+ // The keys a plan-billed harness recipe runs on, saved for that harness alone (HARNESS.md#keys). Each is a sealed row of
2
+ // the one store's sealed_keys (server-keys.ts, AAD sealed_keys|<row>|sealed) named harness:<harness>:<KEY>, so a key saved
3
+ // for one harness is never another's, even under the same name; the store holds ciphertext alone. A value replaced or
4
+ // removed is kept sealed as a retired row (harness-retired:<harness>:<KEY>:<time>), up to RETIRED_KEPT per key, so the
5
+ // cut (the server's secretStores, and a runner's storeSecrets, which reads every sealed_keys row) still holds it, and a
6
+ // timeline written while it was live stays cut after it changes.
7
+ //
8
+ // The server reads and writes them through HarnessKeysOverStore (its Settings → Harness keys routes, owner only). A
9
+ // runner opens a claim's own at its claim (openHarnessKeys), for that run's harness alone, and lays them on its adapter's
10
+ // environment where only the agent's start reads them (runner/cli-run-spec.ts): never on its tools, never another run's.
11
+ import { ApiError, invalid } from "./errors.js";
12
+ import { getSealedKey, putSealedKey, removeSealedKey } from "./server-keys.js";
13
+ import { registerSecretPage, registerSecretWrite, secretMeta, secretName } from "./secret-writes.js";
14
+ import { sealColumn, sealedAt, unsealColumn } from "./store/index.js";
15
+ // Every value saved here is a secret: saving one or removing it takes the owner's session (secret-writes.ts), never the
16
+ // token, and the token's refusal names the console's page.
17
+ registerSecretWrite("saveHarnessKey", () => true);
18
+ registerSecretWrite("deleteHarnessKey", () => true);
19
+ /** The console's page for these keys (Settings → Harness keys). */
20
+ export const HARNESS_KEYS_PAGE = "/#/settings/harness-keys";
21
+ registerSecretPage(["saveHarnessKey", "deleteHarnessKey"], HARNESS_KEYS_PAGE);
22
+ /** The plane of a harness key's name (its row's, and its view's: harness:<harness>:<KEY>). */
23
+ export const HARNESS_KEY_PLANE = "harness";
24
+ const RETIRED_PLANE = "harness-retired";
25
+ /** How many replaced or removed values of one key stay sealed for the cut: the oldest beyond it leaves. */
26
+ export const RETIRED_KEPT = 8;
27
+ /** A value's bounds: under 8 characters or holding whitespace, no cut could hold it whole (server-secrets.ts' floor). */
28
+ const MIN_VALUE = 8;
29
+ const MAX_VALUE_BYTES = 1024;
30
+ const UNFIT = /[\s\u0000-\u001f\u007f-\u009f]/;
31
+ /** The row (and view) name of `key` saved for `harness`. */
32
+ export const harnessKeyRow = (harness, key) => secretName(HARNESS_KEY_PLANE, harness, key);
33
+ const retiredPrefix = (harness, key) => `${secretName(RETIRED_PLANE, harness, key)}:`;
34
+ /** The keys of `names` saved for `harness` that open under `sealKey`, by name. One that does not open (another seal key, or
35
+ * damaged) reads as not saved, never a clear fallback. For a runner's claim, whose run is on that harness. */
36
+ export async function openHarnessKeys(store, sealKey, harness, names) {
37
+ const opened = {};
38
+ for (const name of names) {
39
+ const value = await getSealedKey(store, sealKey, harnessKeyRow(harness, name));
40
+ if (value !== undefined)
41
+ opened[name] = value;
42
+ }
43
+ return opened;
44
+ }
45
+ /** Whether every key of `names` has a row saved for `harness` (its bytes never opened): a trigger's check, and a runner's
46
+ * claim before it opens them. */
47
+ export async function harnessKeysSaved(store, harness, names) {
48
+ if (!names.length)
49
+ return false;
50
+ const rows = new Set((await store.sealedKeys.all()).map((row) => row.name));
51
+ return names.every((name) => rows.has(harnessKeyRow(harness, name)));
52
+ }
53
+ /** Whether a claim laid every key of `names` on `env` (layHarnessKeys: own, never enumerable, not empty), which is when
54
+ * a start takes the keys route (harness-recipe-entry.ts serverRoute). A variable of the same name the environment
55
+ * carries enumerable (one the operator's shell set) is never one: a run takes the keys saved for its harness alone. */
56
+ export function keysLaid(env, names) {
57
+ return names.length > 0 && names.every((name) => {
58
+ const laid = Object.getOwnPropertyDescriptor(env, name);
59
+ return laid !== undefined && laid.enumerable === false && typeof laid.value === "string" && laid.value !== "";
60
+ });
61
+ }
62
+ /** For each data directory a server in this process serves, the harnesses whose every key it holds saved
63
+ * (HarnessKeysOverStore keeps its own in step with its snapshot; another server's writes never touch it): what that
64
+ * server's listing, offers and trigger checks read (harness-recipe-entry.ts `why`), so a save shows with no restart. A
65
+ * start never reads it: it runs only on the keys its claim laid (keysLaid). The snapshot is loaded at the server's start,
66
+ * so a second server on the same store sees another's write at its next start; its runs fail closed meanwhile, since
67
+ * each claim opens the rows itself. */
68
+ const savedHere = new Map();
69
+ export const harnessKeysSavedHere = (data, harness) => savedHere.get(data)?.has(harness) === true;
70
+ /** The words a run no person started (a schedule's, a trigger's, a learned workflow's audit shadow or replay:
71
+ * run-launch.ts personStarted) on a plan-billed recipe is refused in at its claim (runner/harness-loops.ts,
72
+ * runner/cli-run-spec.ts): such a run takes keys saved for that harness, never its owner's own sign-in, and not every
73
+ * one is saved, or not every one opened. */
74
+ export const RECIPE_SIGN_IN_PERSON_ONLY = `A run its owner did not start (a scheduled or triggered run, a learned workflow's audit or replay) on a harness recipe billed to its vendor's plan runs on keys saved for that harness, never on its owner's own sign-in, and not every one of its keys is saved: save them in Settings → Harness keys (${HARNESS_KEYS_PAGE}), start this run yourself, or run the agent on a harness billed through this server's model proxy.`;
75
+ /** The words a trigger's message is refused in by a session its claim started with not every key of its plan-billed
76
+ * recipe laid (runner/adapter-loop.ts, the spec's personOnly): that session runs on its owner's own sign-in, or on
77
+ * nothing, whatever was saved since, so a turn no person sent never goes into it. */
78
+ export const RECIPE_TURN_PERSON_ONLY = `This run started on its owner's own sign-in (its harness recipe is billed to its vendor's plan, and its claim opened not every key saved for that harness), so a trigger's message never runs in it, keys saved since or not: message the run yourself, or target a run started once every key was saved in Settings → Harness keys (${HARNESS_KEYS_PAGE}).`;
79
+ /** Lays `keys` on `env` where only a direct read finds them: never enumerable, so no spread, copy or child environment
80
+ * built from `env` carries them (claim-secrets.ts withModelKeys). */
81
+ export function layHarnessKeys(env, keys) {
82
+ for (const [name, value] of Object.entries(keys))
83
+ Object.defineProperty(env, name, { value, enumerable: false, configurable: true, writable: false });
84
+ }
85
+ /** The saved harness keys over the one store, for the server (the one writer of these rows): a snapshot loaded once at
86
+ * start (load()) and kept in step with every write, so a read answers without a round trip. */
87
+ export class HarnessKeysOverStore {
88
+ store;
89
+ sealKey;
90
+ recipes;
91
+ data;
92
+ current = new Map();
93
+ retired = new Map();
94
+ /** The last write in flight (save, remove): each waits for the one before it, so two that overlap never read the same
95
+ * value as the one they replace, and every value a claim may have opened is retired. */
96
+ writing = Promise.resolve();
97
+ /** `work` once every write before it has settled, its failure its own. */
98
+ serial(work) {
99
+ const next = this.writing.then(work);
100
+ this.writing = next.catch(() => undefined);
101
+ return next;
102
+ }
103
+ /** `recipes`: the plan-billed recipes this server is started with (harness-table.ts planRecipesOf), the only harnesses
104
+ * whose keys it saves or shows. `data`: its data directory, which its registry (harnessKeysSavedHere) is kept under. */
105
+ constructor(store, sealKey, recipes, data) {
106
+ this.store = store;
107
+ this.sealKey = sealKey;
108
+ this.recipes = recipes;
109
+ this.data = data;
110
+ }
111
+ /** This server's registry (harnessKeysSavedHere) set from the snapshot: each recipe whose every key is saved. */
112
+ mark() {
113
+ savedHere.set(this.data, new Set(this.recipes.filter((recipe) => this.saved(recipe)).map((recipe) => recipe.id)));
114
+ }
115
+ /** Reads every harness key row once: each current one opened, each retired one opened for the cut. A row that does not
116
+ * open reads as not saved. */
117
+ async load() {
118
+ const current = new Map();
119
+ const retired = new Map();
120
+ for (const row of await this.store.sealedKeys.all()) {
121
+ const isCurrent = row.name.startsWith(`${HARNESS_KEY_PLANE}:`);
122
+ if (!isCurrent && !row.name.startsWith(`${RETIRED_PLANE}:`))
123
+ continue;
124
+ let value;
125
+ try {
126
+ value = unsealColumn(this.sealKey, sealedAt.sealedKey(row.name), row.sealed).toString("utf8");
127
+ }
128
+ catch {
129
+ continue;
130
+ }
131
+ if (isCurrent)
132
+ current.set(row.name, { value, changedAt: row.updatedAt });
133
+ else {
134
+ const of = row.name.slice(0, row.name.lastIndexOf(":") + 1);
135
+ retired.set(of, [...(retired.get(of) ?? []), { row: row.name, value, at: row.updatedAt }]);
136
+ }
137
+ }
138
+ for (const list of retired.values())
139
+ list.sort((a, b) => a.at - b.at);
140
+ this.current = current;
141
+ this.retired = retired;
142
+ this.mark();
143
+ }
144
+ /** Whether every key `recipe` runs on is saved for it. */
145
+ saved(recipe) {
146
+ return recipe.keys.length > 0 && recipe.keys.every((name) => this.current.has(harnessKeyRow(recipe.id, name)));
147
+ }
148
+ /** Every value to cut: each saved key's, and each retired one's still kept. */
149
+ values() {
150
+ return [...[...this.current.values()].map((entry) => entry.value), ...[...this.retired.values()].flat().map((entry) => entry.value)];
151
+ }
152
+ /** GET: `recipe`'s keys, each by name, whether saved and when it changed: never a value. */
153
+ view(recipe) {
154
+ const keys = recipe.keys.map((name) => {
155
+ const row = harnessKeyRow(recipe.id, name);
156
+ const saved = this.current.get(row);
157
+ return secretMeta(row, saved ? { set: true, source: "console", changedAt: new Date(saved.changedAt) } : { set: false });
158
+ });
159
+ return { id: recipe.id, label: recipe.label, keys, ready: this.saved(recipe) };
160
+ }
161
+ /** GET /settings/harness-keys: every plan-billed recipe this server is started with, its keys by name. */
162
+ list() {
163
+ return { harnesses: this.recipes.map((recipe) => this.view(recipe)) };
164
+ }
165
+ /** The plan-billed recipe `id` names on this server, else 404. */
166
+ recipe(id) {
167
+ return planRecipeOr404(this.recipes, id);
168
+ }
169
+ /** PUT: `value` sealed as `key` for `recipe`'s harness alone; a value it replaces kept as a retired row. Durable before it
170
+ * resolves, so a 204 never outruns the store. */
171
+ async save(recipe, key, body) {
172
+ const value = admit(recipe, key, body);
173
+ const row = harnessKeyRow(recipe.id, key);
174
+ await this.serial(async () => {
175
+ const was = this.current.get(row);
176
+ if (was?.value === value)
177
+ return;
178
+ if (was)
179
+ await this.retire(recipe.id, key, was.value);
180
+ await putSealedKey(this.store, this.sealKey, row, value);
181
+ this.current.set(row, { value, changedAt: Date.now() });
182
+ this.mark();
183
+ await this.store.flush();
184
+ });
185
+ }
186
+ /** DELETE: `key`'s value for `recipe`'s harness gone from its runs, kept as a retired row for the cut. A row the snapshot
187
+ * does not hold (one that does not open under this server's seal key) is removed too, so no claim counts it saved. */
188
+ async remove(recipe, key) {
189
+ known(recipe, key);
190
+ const row = harnessKeyRow(recipe.id, key);
191
+ await this.serial(async () => {
192
+ const was = this.current.get(row);
193
+ if (was)
194
+ await this.retire(recipe.id, key, was.value);
195
+ await removeSealedKey(this.store, row);
196
+ this.current.delete(row);
197
+ this.mark();
198
+ await this.store.flush();
199
+ });
200
+ }
201
+ /** `value`, which `key` held, sealed as a retired row of its own; the oldest beyond RETIRED_KEPT leaves. */
202
+ async retire(harness, key, value) {
203
+ const of = retiredPrefix(harness, key);
204
+ const list = this.retired.get(of) ?? [];
205
+ const at = Math.max(Date.now(), (list.at(-1)?.at ?? 0) + 1);
206
+ const row = `${of}${at}`;
207
+ await putSealedKey(this.store, this.sealKey, row, value);
208
+ list.push({ row, value, at });
209
+ while (list.length > RETIRED_KEPT)
210
+ await removeSealedKey(this.store, list.shift().row);
211
+ this.retired.set(of, list);
212
+ }
213
+ }
214
+ /** 422 unless `key` is one `recipe` runs on (recipe.keys): a key no recipe names is never saved for it. */
215
+ function known(recipe, key) {
216
+ if (!recipe.keys.includes(key))
217
+ throw invalid([{ field: "key", reason: "not_an_option", message: `${recipe.label} runs on ${recipe.keys.join(", ")}.` }]);
218
+ }
219
+ /** What a PUT may save: `body.value`, text of 8 to 1024 bytes with no whitespace or control character, for a key the
220
+ * recipe names. No message holds the value. */
221
+ function admit(recipe, key, body) {
222
+ known(recipe, key);
223
+ if (typeof body !== "object" || body === null || Array.isArray(body))
224
+ throw invalid([{ field: "value", reason: "wrong_type", message: "The body is { value }." }]);
225
+ const extra = Object.keys(body).filter((name) => name !== "value");
226
+ if (extra.length)
227
+ throw invalid(extra.map((name) => ({ field: name, reason: "unknown", message: "The body is { value }." })));
228
+ const value = body.value;
229
+ if (typeof value !== "string" || value === "")
230
+ throw invalid([{ field: "value", reason: value === undefined ? "missing" : "wrong_type", message: `${key} is text, not empty` }]);
231
+ if (UNFIT.test(value))
232
+ throw invalid([{ field: "value", reason: "invalid", message: `${key} holds whitespace or a control character` }]);
233
+ if ([...value].length < MIN_VALUE)
234
+ throw invalid([{ field: "value", reason: "too_short", message: `${key} is at least ${MIN_VALUE} characters` }]);
235
+ if (Buffer.byteLength(value) > MAX_VALUE_BYTES)
236
+ throw invalid([{ field: "value", reason: "too_long", message: `${key} is at most ${MAX_VALUE_BYTES} bytes` }]);
237
+ return value;
238
+ }
239
+ /** 404 for a harness that is not a plan-billed recipe on this server's table: its keys are saved nowhere. */
240
+ export function planRecipeOr404(recipes, id) {
241
+ const recipe = recipes.find((entry) => entry.id === id);
242
+ if (!recipe)
243
+ throw new ApiError("not_found", `No harness recipe billed to its vendor's plan is named ${id} on this server: its keys are saved for a recipe the server is started with (--harness-recipe).`);
244
+ return recipe;
245
+ }
246
+ /** The bytes a value would be sealed as, for a test that checks a key is sealed at rest. */
247
+ export const sealedHarnessKeyBytes = (key, harness, name, value) => sealColumn(key, sealedAt.sealedKey(harnessKeyRow(harness, name)), value);
@@ -7,9 +7,9 @@ export declare const HARNESS_NOT_SIGNED_IN = "HARNESS_NOT_SIGNED_IN";
7
7
  /** A recipe a server names that has no passing harness-check on this data directory for the recipe, binary and files
8
8
  * it would run (harness-recipe.ts checkedOf). */
9
9
  export declare const HARNESS_NOT_CHECKED = "HARNESS_NOT_CHECKED";
10
- /** A plan-billed recipe a server names, whose runs take keys saved for its harness alone: this server saves none yet (the
11
- * cut every child's environment takes keeps the server's own out), so it runs under harness-check, or on its owner's
12
- * own sign-in on their own machine (--harness-sign-in). */
10
+ /** A plan-billed recipe a server names, whose runs take keys saved for its harness alone (harness-keys.ts), and not every
11
+ * one is saved: its owner saves them in Settings → Harness keys. Until then it runs under harness-check, or on its
12
+ * owner's own sign-in on their own machine (--harness-sign-in). */
13
13
  export declare const HARNESS_KEYS_NOT_SAVED = "HARNESS_KEYS_NOT_SAVED";
14
14
  /** What a recipe's agent runs on: its keys (each read by its saved name where it runs; none for a proxy-billed agent,
15
15
  * on the model proxy), or its owner's own sign-in, whose folder (`home`) the agent is handed by signIn.homeArg. */
@@ -20,12 +20,16 @@ export type RecipeRoute = {
20
20
  readonly home: string;
21
21
  };
22
22
  /** The route a server runs `recipe`'s agent on, or why there is none. Proxy-billed: the model proxy. Plan-billed: keys
23
- * saved for its harness alone, which come first wherever they are saved; none are yet (HARNESS_KEYS_NOT_SAVED). Its
24
- * owner's own sign-in only where `signIn` (the server's --harness-sign-in: one owner, on their own machine, its runs as
25
- * its own user, which the start proved) and only for a person's run (a scheduled or triggered one is refused at its
26
- * claim, run-child-host.ts staysInRunner). harness-check never takes this route: it runs on the recipe's keys alone. */
27
- export declare function serverRoute(recipe: Recipe, file: string, data: string, env: NodeJS.ProcessEnv, { signIn }: {
23
+ * saved for its harness alone (harness-keys.ts), which come first: for a start, only those its claim laid on `env`
24
+ * (keysLaid); for the server's listing and offers, `saved` too, every one held saved by the server on this data
25
+ * directory (harnessKeysSavedHere), whose claims lay them. Its owner's own sign-in only where `signIn` (the server's
26
+ * --harness-sign-in: one owner, on their own machine, its runs as its own user, which the start proved) and only for a
27
+ * person's run: a scheduled or triggered one whose claim laid not every key is refused at its claim, before this
28
+ * (runner/cli-run-spec.ts, harness-keys.ts RECIPE_SIGN_IN_PERSON_ONLY). Else HARNESS_KEYS_NOT_SAVED, naming the
29
+ * console's page. harness-check never takes this route: it runs on the recipe's keys from the shell alone. */
30
+ export declare function serverRoute(recipe: Recipe, file: string, data: string, env: NodeJS.ProcessEnv, { signIn, saved }: {
28
31
  signIn: boolean;
32
+ saved?: boolean;
29
33
  }): RecipeRoute | {
30
34
  refused: string;
31
35
  message: string;
@@ -47,7 +51,8 @@ export interface RecipeEntryOptions extends AcpEntryHost {
47
51
  readonly recipe: Recipe;
48
52
  readonly binary: string;
49
53
  readonly release: RecipeArchive;
50
- route(env: NodeJS.ProcessEnv): RecipeRoute;
54
+ /** `probe`: the adapter is built only to check it (harness-table.ts PlanLaunch.probe), not to start its agent. */
55
+ route(env: NodeJS.ProcessEnv, probe?: boolean): RecipeRoute;
51
56
  beforeStart(command: string): Promise<void>;
52
57
  /** The variables beside the recipe's env at each start: the egress proxy's (harness-egress.ts egressVars). */
53
58
  vars(): Readonly<Record<string, string>>;
@@ -8,6 +8,7 @@ import { ACP_PACKAGE, acpPackage } from "./acp-package.js";
8
8
  import { ARCHIVE_CODES, archivePlatform, digestOf } from "./harness-archive.js";
9
9
  import { egressProxy, egressVars } from "./harness-egress.js";
10
10
  import { installDirOf } from "./harness-install.js";
11
+ import { HARNESS_KEYS_PAGE, harnessKeysSavedHere, keysLaid } from "./harness-keys.js";
11
12
  import { checkedOf, loadRecipe, pinnedDigest, pinnedTree, recipeBinaryOf, recipeCheckLine, recipeInstallLine, recipeSignInLine, releaseFor, signedIn, signInHomeOf } from "./harness-recipe.js";
12
13
  import { acpEntryOf } from "./harness-table.js";
13
14
  import { HarnessUnavailable } from "./provider.js";
@@ -17,25 +18,30 @@ export const HARNESS_NOT_SIGNED_IN = "HARNESS_NOT_SIGNED_IN";
17
18
  /** A recipe a server names that has no passing harness-check on this data directory for the recipe, binary and files
18
19
  * it would run (harness-recipe.ts checkedOf). */
19
20
  export const HARNESS_NOT_CHECKED = "HARNESS_NOT_CHECKED";
20
- /** A plan-billed recipe a server names, whose runs take keys saved for its harness alone: this server saves none yet (the
21
- * cut every child's environment takes keeps the server's own out), so it runs under harness-check, or on its owner's
22
- * own sign-in on their own machine (--harness-sign-in). */
21
+ /** A plan-billed recipe a server names, whose runs take keys saved for its harness alone (harness-keys.ts), and not every
22
+ * one is saved: its owner saves them in Settings → Harness keys. Until then it runs under harness-check, or on its
23
+ * owner's own sign-in on their own machine (--harness-sign-in). */
23
24
  export const HARNESS_KEYS_NOT_SAVED = "HARNESS_KEYS_NOT_SAVED";
24
25
  /** The route a server runs `recipe`'s agent on, or why there is none. Proxy-billed: the model proxy. Plan-billed: keys
25
- * saved for its harness alone, which come first wherever they are saved; none are yet (HARNESS_KEYS_NOT_SAVED). Its
26
- * owner's own sign-in only where `signIn` (the server's --harness-sign-in: one owner, on their own machine, its runs as
27
- * its own user, which the start proved) and only for a person's run (a scheduled or triggered one is refused at its
28
- * claim, run-child-host.ts staysInRunner). harness-check never takes this route: it runs on the recipe's keys alone. */
29
- export function serverRoute(recipe, file, data, env, { signIn }) {
26
+ * saved for its harness alone (harness-keys.ts), which come first: for a start, only those its claim laid on `env`
27
+ * (keysLaid); for the server's listing and offers, `saved` too, every one held saved by the server on this data
28
+ * directory (harnessKeysSavedHere), whose claims lay them. Its owner's own sign-in only where `signIn` (the server's
29
+ * --harness-sign-in: one owner, on their own machine, its runs as its own user, which the start proved) and only for a
30
+ * person's run: a scheduled or triggered one whose claim laid not every key is refused at its claim, before this
31
+ * (runner/cli-run-spec.ts, harness-keys.ts RECIPE_SIGN_IN_PERSON_ONLY). Else HARNESS_KEYS_NOT_SAVED, naming the
32
+ * console's page. harness-check never takes this route: it runs on the recipe's keys from the shell alone. */
33
+ export function serverRoute(recipe, file, data, env, { signIn, saved = false }) {
30
34
  if (recipe.model.billing === "proxy")
31
35
  return { on: "keys" };
36
+ if (saved || keysLaid(env, recipe.keys))
37
+ return { on: "keys" };
32
38
  if (signIn && recipe.signIn) {
33
39
  if (signedIn(data, recipe))
34
40
  return { on: "sign-in", home: signInHomeOf(data, recipe.id) };
35
- return { refused: HARNESS_NOT_SIGNED_IN, message: `${recipe.label} runs on this server on its owner's own sign-in (--harness-sign-in), and its agent is not signed in here: sign it in with: ${recipeSignInLine(file, data, env)}` };
41
+ return { refused: HARNESS_NOT_SIGNED_IN, message: `${recipe.label} runs on this server on its keys saved in Settings → Harness keys (${HARNESS_KEYS_PAGE}), else on its owner's own sign-in (--harness-sign-in), and neither is here: save its keys there, or sign it in with: ${recipeSignInLine(file, data, env)}` };
36
42
  }
37
43
  const own = recipe.signIn ? "; on your own machine alone, a server started with --harness-sign-in runs it on your own sign-in" : "";
38
- return { refused: HARNESS_KEYS_NOT_SAVED, message: `${recipe.label} runs on its keys (${recipe.keys.join(", ")}) saved for this harness alone, and this server saves no harness's keys yet: check it with harness-check, where its keys are read from your shell${own}` };
44
+ return { refused: HARNESS_KEYS_NOT_SAVED, message: `${recipe.label} runs on its keys (${recipe.keys.join(", ")}) saved for this harness alone, and not every one is saved: save them in Settings → Harness keys (${HARNESS_KEYS_PAGE}; \`agentrun harness keys\` prints the link)${own}` };
39
45
  }
40
46
  /** The ACP adapter's recipe for one start of `recipe`'s agent on `route`: the installed `binary`, the platform's own
41
47
  * arguments where its release lists them (else the recipe's), and on the sign-in its folder after them. On its keys:
@@ -97,7 +103,7 @@ export function recipeEntryOf(options) {
97
103
  }, host)
98
104
  : acpEntryOf({
99
105
  facts: { ...acp.cursorFacts, id: recipe.id, label: recipe.label },
100
- recipe: (launch) => acpRecipeFor(recipe, binary, release, options.route(launch.env), { vars: options.vars(), model: launch.model }),
106
+ recipe: (launch) => acpRecipeFor(recipe, binary, release, options.route(launch.env, launch.probe === true), { vars: options.vars(), model: launch.model }),
101
107
  beforeStart: options.beforeStart,
102
108
  ...checks,
103
109
  ...(options.hidden ? { hidden: options.hidden } : {}),
@@ -119,7 +125,12 @@ export function recipeServerEntry(file, data, { signIn = false } = {}) {
119
125
  throw new Error(`harness recipe ${loaded.file}: ${recipe.label} ${recipe.release.version} has no release for ${platform ?? `${process.platform}-${process.arch}`}`);
120
126
  const binary = recipeBinaryOf(data, recipe, release);
121
127
  const installed = installDirOf(data, recipe.id);
122
- const route = (env) => serverRoute(recipe, loaded.file, data, env, { signIn });
128
+ // What the server's listing, offers and checks read (`why`, and the adapter built as a probe): the keys route when its
129
+ // server holds every one saved on this data directory (harnessKeysSavedHere), whose claims lay them. An agent's start
130
+ // reads only what its claim laid (`start`): never what the server lists, which a removal can have outrun, nor the
131
+ // shell's variable of a key's name.
132
+ const route = (env) => serverRoute(recipe, loaded.file, data, env, { signIn, saved: harnessKeysSavedHere(data, recipe.id) });
133
+ const start = (env) => serverRoute(recipe, loaded.file, data, env, { signIn });
123
134
  /** Why it cannot run on `env`, in words that end with the command that fixes it; undefined when it can. Nothing is
124
135
  * digested here (each start is, beforeStart): the pins and the check's note are compared. */
125
136
  const why = (env) => {
@@ -150,8 +161,8 @@ export function recipeServerEntry(file, data, { signIn = false } = {}) {
150
161
  throw new HarnessUnavailable(`${recipe.label}'s egress proxy is not running, so its agent does not start`);
151
162
  return egressVars(egressUrl);
152
163
  },
153
- route: (env) => {
154
- const on = route(env);
164
+ route: (env, probe) => {
165
+ const on = probe ? route(env) : start(env);
155
166
  if ("refused" in on)
156
167
  throw new HarnessUnavailable(`${on.refused}: ${on.message}`);
157
168
  return on;
@@ -170,7 +170,12 @@ export declare const HARNESS_RESUME_UNDECLARED = "HARNESS_RESUME_UNDECLARED";
170
170
  /** What a run of a plan-billed ACP agent is given (acpEntryOf's plan branch): its model as its vendor names it (`default`
171
171
  * for the vendor's own), a log, the confinement its process starts under and the server's environment. No provider or
172
172
  * price: its vendor bills its owner's plan, and no request of it reaches a proxy of ours. */
173
- export type PlanLaunch = Omit<ModuleLaunch, "provider" | "price" | "skills">;
173
+ export type PlanLaunch = Omit<ModuleLaunch, "provider" | "price" | "skills"> & {
174
+ /** Set where the adapter is built only to say whether it would run (the entry's refusal: offers, a save's or a start's
175
+ * check), never to start its agent: a recipe's route reads its server's listing then, and only what a claim laid when
176
+ * its agent starts (harness-recipe-entry.ts). */
177
+ readonly probe?: boolean;
178
+ };
174
179
  /** What serve gives acpEntryOf for an ACP agent billed to its owner's plan (its facts' wire `plan`): Cursor's entry and
175
180
  * harness-check's plan-billed recipes. Not the kit's: a module's acpEntry is proxy-billed. `missing` may throw a
176
181
  * HarnessUnavailable of its own, which keeps the fix (install, pins) it names; `recipe` may throw one too (a key unset). */
@@ -224,6 +229,16 @@ export declare function harnessTable(env: NodeJS.ProcessEnv): Readonly<Record<st
224
229
  * that user, never a slot's; and a plan-billed one runs on keys saved for it or, for a person's run alone, its owner's
225
230
  * own sign-in (harness-recipe-entry.ts serverRoute). */
226
231
  export declare const recipeHarness: (env: NodeJS.ProcessEnv, id: string) => "proxy" | "plan" | undefined;
232
+ /** A harness on `env`'s table whose keys are saved for it alone (harness-keys.ts): a recipe billed to its vendor's plan. */
233
+ export type PlanRecipe = {
234
+ readonly id: string;
235
+ readonly label: string;
236
+ readonly keys: readonly string[];
237
+ };
238
+ /** The names of the keys `id` runs on when it is a plan-billed recipe's harness on `env`'s table, else undefined. */
239
+ export declare const recipeKeysOf: (env: NodeJS.ProcessEnv, id: string) => readonly string[] | undefined;
240
+ /** Every plan-billed recipe's harness on `env`'s table, in its order: what Settings → Harness keys lists. */
241
+ export declare const planRecipesOf: (env: NodeJS.ProcessEnv) => PlanRecipe[];
227
242
  /** The owner's setting that names harness modules when no option does: package names or paths, comma-separated. */
228
243
  export declare const HARNESS_MODULES_SETTING = "AGENTRUN_SERVE_HARNESS_MODULES";
229
244
  /** The harness modules `given` names (a server's or a runner's `--harness-module`, else HARNESS_MODULES_SETTING): none
@@ -226,7 +226,7 @@ function acpPlanEntryOf(options, host = {}) {
226
226
  if (modelWire(facts.wire))
227
227
  throw new Error(`${id} runs on a model wire of ours, so its ACP entry is the proxy-billed one`);
228
228
  const prefix = `${id}/`;
229
- const make = async (env, needs) => {
229
+ const make = async (env, needs, probe = false) => {
230
230
  const { fixOf, harnessLog } = await import("./adapters.js");
231
231
  // What no key fixes is said first, as for the built-in harnesses' binaries.
232
232
  const lacks = await options.missing?.(env);
@@ -239,7 +239,7 @@ function acpPlanEntryOf(options, host = {}) {
239
239
  throw new HarnessUnavailable(`${label} runs ${label}'s models, named ${prefix}<model-id>; the run's model is ${needs.model.provider}/${needs.model.modelId}.`);
240
240
  const log = host.log ?? harnessLog(id, env);
241
241
  try {
242
- const recipe = await ownKeysOnly(facts, await options.recipe({ model: needs.model.modelId, log, ...(needs.confine ? { confine: needs.confine } : {}), env }));
242
+ const recipe = await ownKeysOnly(facts, await options.recipe({ model: needs.model.modelId, log, ...(needs.confine ? { confine: needs.confine } : {}), env, ...(probe ? { probe } : {}) }));
243
243
  // Its keys (recipe.keys) are read from the run's environment, which holds its own (ownKeys: run-secrets.ts keysFor).
244
244
  return acp.acpAdapter({ recipe, ...(options.beforeStart ? { beforeStart: options.beforeStart } : {}), ...(needs.confine ? { confine: needs.confine } : {}), env, log });
245
245
  }
@@ -272,11 +272,12 @@ function acpPlanEntryOf(options, host = {}) {
272
272
  return { model: { provider: id, modelId } };
273
273
  },
274
274
  priceModel: (_env, model) => model,
275
- adapter: make,
275
+ adapter: (env, needs) => make(env, needs),
276
+ // Built only to check it (a probe), never started.
276
277
  refusal: async (env, given, { atStart }) => {
277
278
  const { startReason } = await import("./adapters.js");
278
279
  try {
279
- const adapter = await make(env, given ?? { model: { provider: id, modelId: PLAN_DEFAULT_MODEL }, models: { getModel: () => undefined } });
280
+ const adapter = await make(env, given ?? { model: { provider: id, modelId: PLAN_DEFAULT_MODEL }, models: { getModel: () => undefined } }, true);
280
281
  const problems = adapter.check({ key: "capabilities", label: "capabilities", system: [], tools: [], context: "fresh" });
281
282
  return problems.length ? { reason: problems.join(" ") } : undefined;
282
283
  }
@@ -507,14 +508,14 @@ export function harnessTable(env) {
507
508
  if (Object.hasOwn(built, entry.id))
508
509
  throw new Error(`harness recipe ${file} names ${entry.id}, which a harness module or another recipe already adds`);
509
510
  built[entry.id] = entry;
510
- madeByRecipe.set(entry, loadRecipe(file).recipe.model.billing);
511
+ const { recipe } = loadRecipe(file);
512
+ madeByRecipe.set(entry, { billing: recipe.model.billing, label: recipe.label, keys: Object.freeze([...recipe.keys]) });
511
513
  }
512
514
  table = Object.freeze(built);
513
515
  loaded.set(key, table);
514
516
  }
515
517
  return table;
516
518
  }
517
- /** The entries harnessTable made from a recipe (HARNESS_RECIPES_ENV), with the recipe's billing. */
518
519
  const madeByRecipe = new WeakMap();
519
520
  /** How `id` on `env`'s table is billed when it is a recipe's harness, else undefined. A recipe's install, its check's
520
521
  * note and its owner's sign-in are the server user's alone (0700 and 0600 under `<data>/harnesses`), so its runs run as
@@ -522,8 +523,19 @@ const madeByRecipe = new WeakMap();
522
523
  * own sign-in (harness-recipe-entry.ts serverRoute). */
523
524
  export const recipeHarness = (env, id) => {
524
525
  const entry = Object.hasOwn(harnessTable(env), id) ? harnessTable(env)[id] : undefined;
525
- return entry === undefined ? undefined : madeByRecipe.get(entry);
526
+ return entry === undefined ? undefined : madeByRecipe.get(entry)?.billing;
527
+ };
528
+ /** The names of the keys `id` runs on when it is a plan-billed recipe's harness on `env`'s table, else undefined. */
529
+ export const recipeKeysOf = (env, id) => {
530
+ const entry = Object.hasOwn(harnessTable(env), id) ? harnessTable(env)[id] : undefined;
531
+ const made = entry === undefined ? undefined : madeByRecipe.get(entry);
532
+ return made?.billing === "plan" ? made.keys : undefined;
526
533
  };
534
+ /** Every plan-billed recipe's harness on `env`'s table, in its order: what Settings → Harness keys lists. */
535
+ export const planRecipesOf = (env) => Object.values(harnessTable(env)).flatMap((entry) => {
536
+ const made = madeByRecipe.get(entry);
537
+ return made?.billing === "plan" ? [{ id: entry.id, label: made.label, keys: made.keys }] : [];
538
+ });
527
539
  /** The owner's setting that names harness modules when no option does: package names or paths, comma-separated. */
528
540
  export const HARNESS_MODULES_SETTING = "AGENTRUN_SERVE_HARNESS_MODULES";
529
541
  /** The harness modules `given` names (a server's or a runner's `--harness-module`, else HARNESS_MODULES_SETTING): none
package/dist/harness.d.ts CHANGED
@@ -51,7 +51,11 @@ export type HarnessCapability = HarnessOffer & {
51
51
  }[];
52
52
  run_memory_mib: number;
53
53
  needs?: HarnessNeed[];
54
+ noModelRuns?: true;
54
55
  };
56
+ /** `noModelRuns` (never served): a harness this server runs, its default model lacking a key (`needs`), and no model it
57
+ * offers runs here now either, so capabilities serve it `available: false` (server.ts capabilitiesWith). Absent where
58
+ * any model it offers runs, though its default does not: a revision that names that model runs. */
55
59
  /** What would give a harness that runs nothing here a model, any one of them: a model key (`key`), or the ChatGPT sign-in
56
60
  * (`chatgpt`: codex and pi, on a server that signs in, not signed in or signed in no longer, AGENT_MODEL naming no key's
57
61
  * model the harness runs: planWouldRun). */
package/dist/harness.js CHANGED
@@ -78,6 +78,9 @@ export function harnessOffers(env) {
78
78
  // so the picker never offers one a save would refuse. None for a harness that does not run here.
79
79
  const entry = harnessOf(env, offer.id);
80
80
  const models = [];
81
+ // Whether any model it offers runs here now, not only lacks a key: its default lacking one leaves it available
82
+ // where another runs (noModelRuns).
83
+ let runsOne = false;
81
84
  // Its free models (model-form.ts freeCandidates) are offered after the others, by the same checks.
82
85
  const free = offer.available ? await freeCandidates(env, offer.id) : [];
83
86
  if (offer.available) {
@@ -90,12 +93,15 @@ export function harnessOffers(env) {
90
93
  const { FAUX_ENV } = await import("./model.js");
91
94
  const { factsOf } = await import("./harness-table.js");
92
95
  const facts = factsOf(env, offer.id);
96
+ const { OLLAMA_PROVIDER, ollamaToolsModels } = await import("./ollama-provider.js");
97
+ const toolsModels = ollamaToolsModels(env);
93
98
  for (const id of new Set([...pickerCandidates(env, offer.id), ...free.map((m) => m.id)])) {
94
99
  if (!MODEL_REF.test(id))
95
100
  continue;
96
101
  const chosen = await entry.model(env, id, true);
97
102
  if (!chosen || !("model" in chosen || chosen.needs === "key"))
98
103
  continue;
104
+ let lacksKey = !("model" in chosen);
99
105
  if (facts && "model" in chosen && !env[FAUX_ENV]) {
100
106
  try {
101
107
  providerFor(facts.wire, env, chosen.model, offer.id);
@@ -103,9 +109,14 @@ export function harnessOffers(env) {
103
109
  catch (error) {
104
110
  if (!(error instanceof HarnessUnavailable && error.keys?.length))
105
111
  continue;
112
+ lacksKey = true;
106
113
  }
107
114
  }
108
115
  models.push(id);
116
+ // A model of the Ollama here that takes no tools stays pickable, but gives a run no tools: it is no model a
117
+ // run of this harness has now, as the host's default never is one (model.ts localDefault).
118
+ if (!lacksKey && (!id.startsWith(`${OLLAMA_PROVIDER}/`) || toolsModels.includes(id)))
119
+ runsOne = true;
109
120
  }
110
121
  }
111
122
  // One that runs nothing here for want of a key (unavailable with `keys`, or available with no default model for
@@ -114,7 +125,7 @@ export function harnessOffers(env) {
114
125
  const wantsKey = offer.available ? resolved !== undefined && "why" in resolved && resolved.needs === "key" : Boolean(offer.keys?.length);
115
126
  const sayWhy = !wantsKey ? {} : offer.available ? { reason: resolved.why } : offer.reason ? { reason: withPlanWords(env, offer.id, offer.reason) } : {};
116
127
  const needs = wantsKey ? ["key", ...(planWouldRun(env, offer.id) ? ["chatgpt"] : [])] : [];
117
- return { ...offer, ...sayWhy, default_model: resolved && "model" in resolved ? `${resolved.model.provider}/${resolved.model.modelId}` : null, models, free_models: free.filter((m) => models.includes(m.id)), run_memory_mib: entry.runMib, ...(needs.length ? { needs } : {}) };
128
+ return { ...offer, ...sayWhy, default_model: resolved && "model" in resolved ? `${resolved.model.provider}/${resolved.model.modelId}` : null, models, free_models: free.filter((m) => models.includes(m.id)), run_memory_mib: entry.runMib, ...(needs.length ? { needs } : {}), ...(offer.available && needs.length && !runsOne ? { noModelRuns: true } : {}) };
118
129
  }));
119
130
  })();
120
131
  offered.set(env, offers);
@@ -1,6 +1,8 @@
1
1
  /** The name a Host header gives, lowercased and without its port (an IPv6 address keeps its brackets). Undefined for a
2
2
  * header that is not `name` or `name:port`: no user part, no path, no empty or non-numeric port. */
3
3
  export declare function hostName(header: string | undefined): string | undefined;
4
+ /** The port a Host header names (1 to 65535), or undefined for none, or for a header that is not `name` or `name:port`. */
5
+ export declare function hostPort(header: string | undefined): number | undefined;
4
6
  /** The names a server listening on loopback `host` answers to: this machine's (localhost, 127.0.0.1, [::1], and `host`
5
7
  * itself), each --allow-host name, and the name of the address people open (AGENTRUN_PUBLIC_URL), which a proxy in
6
8
  * front of it sends. */
@@ -9,6 +9,12 @@ export function hostName(header) {
9
9
  const match = /^(\[[0-9a-f:.]+\]|[a-z0-9._-]+)(?::(\d{1,5}))?$/.exec(String(header ?? "").trim().toLowerCase());
10
10
  return match && (match[2] === undefined || Number(match[2]) <= 65535) ? match[1] : undefined;
11
11
  }
12
+ /** The port a Host header names (1 to 65535), or undefined for none, or for a header that is not `name` or `name:port`. */
13
+ export function hostPort(header) {
14
+ const match = /^(?:\[[0-9a-f:.]+\]|[a-z0-9._-]+):(\d{1,5})$/.exec(String(header ?? "").trim().toLowerCase());
15
+ const port = match ? Number(match[1]) : 0;
16
+ return port >= 1 && port <= 65535 ? port : undefined;
17
+ }
12
18
  /** The names a server listening on loopback `host` answers to: this machine's (localhost, 127.0.0.1, [::1], and `host`
13
19
  * itself), each --allow-host name, and the name of the address people open (AGENTRUN_PUBLIC_URL), which a proxy in
14
20
  * front of it sends. */
@@ -1,5 +1,5 @@
1
1
  import type { RunMetrics } from "./timeline/index.js";
2
- import { type Source } from "./import-sources.js";
2
+ import { type Source } from "@parcha/agentrun-import";
3
3
  /** A session an import found: its source and agent; what it used (undefined: unknown), with its time at work; and its
4
4
  * model requests by local hour of the day (undefined: their times are unknown). `untied`: a subagent's session whose
5
5
  * file names no parent, so no session of its own either: its tokens and tool calls count in the totals, nothing else. */
@@ -1,4 +1,4 @@
1
- import { SOURCE_NAMES, SOURCES } from "./import-sources.js";
1
+ import { SOURCE_NAMES, SOURCES } from "@parcha/agentrun-import";
2
2
  /** Requests by local hour of the day, from their times (ms). */
3
3
  export function hoursOf(times) {
4
4
  const hours = new Array(24).fill(0);
package/dist/import.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { type StorageWrite } from "@earendil-works/pi-durable";
2
2
  import { type EntryLike } from "./timeline/index.js";
3
- import { type Session, type Source } from "./import-sources.js";
3
+ import { type Locator, type Session, type Source } from "@parcha/agentrun-import";
4
4
  import { type Found } from "./import-summary.js";
5
5
  import { type Store } from "./store/index.js";
6
6
  /** What `runImport`, `planImport` and the CLI reach of the server's open store: the agents it reads and writes, the runs it
@@ -111,8 +111,8 @@ export type ProjectPlan = {
111
111
  sessions: Session[];
112
112
  };
113
113
  /** `already`: the session files an earlier import took whole, left unread; `held`, the runs an import would not take
114
- * again: theirs, and (when measuring) those of planned sessions the store holds already. `children`: the files of each
115
- * session's subagents, whose usage is its run's: Claude Code's by the session file beside them, Codex's by `source:thread`; `untied`, those of subagents whose file names
114
+ * again: theirs, and (when measuring) those of planned sessions the store holds already. `children`: the locators of each
115
+ * session's subagents, whose usage is its run's: Claude Code's by the locator (locatorKey) of the session file beside them, Codex's by `source:thread`; `untied`, those of subagents whose file names
116
116
  * no parent, counted in a summary's totals alone. `found`: each other planned session measured,
117
117
  * when the plan was made to (`measure`). `stopped`: `signal` ended the listing with session files still unlisted. */
118
118
  export type Plan = {
@@ -120,9 +120,9 @@ export type Plan = {
120
120
  skipped: Skipped[];
121
121
  already: number;
122
122
  held: string[];
123
- children: Map<string, string[]>;
123
+ children: Map<string, Locator[]>;
124
124
  untied: {
125
- file: string;
125
+ locator: Locator;
126
126
  source: Source;
127
127
  }[];
128
128
  found?: Found[];