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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (261) hide show
  1. package/CHANGELOG.md +122 -1
  2. package/README.md +213 -24
  3. package/dist/agent-delete.d.ts +5 -6
  4. package/dist/agent-delete.js +30 -67
  5. package/dist/agent-package.d.ts +71 -0
  6. package/dist/agent-package.js +345 -0
  7. package/dist/agents-store.d.ts +26 -20
  8. package/dist/agents-store.js +41 -33
  9. package/dist/api-only.d.ts +26 -6
  10. package/dist/api-only.js +35 -13
  11. package/dist/claude-login.d.ts +1 -0
  12. package/dist/claude-login.js +1 -1
  13. package/dist/cli-learning/cli.d.ts +3 -0
  14. package/dist/cli-learning/cli.js +17 -3
  15. package/dist/cli-learning/connections.js +3 -2
  16. package/dist/cli-learning/schema.js +2 -1
  17. package/dist/cli.js +70 -7
  18. package/dist/composio-preset.d.ts +2 -1
  19. package/dist/composio-preset.js +4 -3
  20. package/dist/composio-triggers.d.ts +4 -0
  21. package/dist/composio-triggers.js +4 -1
  22. package/dist/computer-needs.d.ts +32 -0
  23. package/dist/computer-needs.js +80 -0
  24. package/dist/computer-setting.d.ts +1 -0
  25. package/dist/computer-setting.js +8 -1
  26. package/dist/console/assets/index-BFgyZzF_.js +734 -0
  27. package/dist/console/assets/index-DbilxljH.css +1 -0
  28. package/dist/console/index.html +2 -2
  29. package/dist/console-links.d.ts +1 -0
  30. package/dist/console-links.js +2 -0
  31. package/dist/env-switch.d.ts +14 -0
  32. package/dist/env-switch.js +23 -0
  33. package/dist/errors.d.ts +1 -0
  34. package/dist/errors.js +3 -0
  35. package/dist/eval-previous.js +4 -3
  36. package/dist/fal-price.js +10 -13
  37. package/dist/handed-secret.d.ts +4 -0
  38. package/dist/handed-secret.js +10 -0
  39. package/dist/harness-archive.d.ts +15 -5
  40. package/dist/harness-archive.js +71 -34
  41. package/dist/harness-check.d.ts +2 -1
  42. package/dist/harness-check.js +36 -95
  43. package/dist/harness-egress.d.ts +23 -0
  44. package/dist/harness-egress.js +69 -0
  45. package/dist/harness-recipe-entry.d.ts +71 -0
  46. package/dist/harness-recipe-entry.js +184 -0
  47. package/dist/harness-recipe.d.ts +73 -6
  48. package/dist/harness-recipe.js +185 -31
  49. package/dist/harness-sign-in.d.ts +29 -0
  50. package/dist/harness-sign-in.js +122 -0
  51. package/dist/harness-table.d.ts +21 -0
  52. package/dist/harness-table.js +58 -3
  53. package/dist/harness-zip.d.ts +6 -0
  54. package/dist/harness-zip.js +203 -0
  55. package/dist/ids.d.ts +11 -0
  56. package/dist/ids.js +36 -0
  57. package/dist/learn/commit.d.ts +14 -1
  58. package/dist/learn/commit.js +156 -1
  59. package/dist/learn/compile.js +22 -8
  60. package/dist/learn/folder.d.ts +5 -0
  61. package/dist/learn/folder.js +10 -1
  62. package/dist/learn/learning.sh +15 -3
  63. package/dist/learn/promote.d.ts +2 -2
  64. package/dist/learn/secrets.js +30 -7
  65. package/dist/learning-routes.d.ts +23 -11
  66. package/dist/learning-routes.js +110 -20
  67. package/dist/learning.d.ts +9 -6
  68. package/dist/learning.js +9 -4
  69. package/dist/mcp-gateway.js +15 -2
  70. package/dist/mcp-probe.d.ts +3 -0
  71. package/dist/mcp-probe.js +7 -2
  72. package/dist/mcp-resources.d.ts +44 -0
  73. package/dist/mcp-resources.js +100 -0
  74. package/dist/mcp-servers-store.d.ts +16 -12
  75. package/dist/model.d.ts +4 -4
  76. package/dist/model.js +6 -6
  77. package/dist/native/cli.js +9 -2
  78. package/dist/native/connection.d.ts +2 -2
  79. package/dist/native/connection.js +5 -2
  80. package/dist/native/discovery.d.ts +2 -0
  81. package/dist/native/discovery.js +10 -6
  82. package/dist/native/remote-worker-bridge.js +36 -4
  83. package/dist/native/remote.d.ts +18 -1
  84. package/dist/native/remote.js +126 -37
  85. package/dist/native/schema.d.ts +6 -0
  86. package/dist/native/schema.js +31 -6
  87. package/dist/native/source-account.d.ts +13 -0
  88. package/dist/native/source-account.js +114 -0
  89. package/dist/native/source-capture-hooks.d.ts +5 -0
  90. package/dist/native/source-capture-hooks.js +102 -0
  91. package/dist/native/source-mcp-selection.d.ts +13 -0
  92. package/dist/native/source-mcp-selection.js +72 -0
  93. package/dist/native/source-runtime-tools.d.ts +19 -0
  94. package/dist/native/source-runtime-tools.js +103 -0
  95. package/dist/native/source-snapshot-types.d.ts +138 -0
  96. package/dist/native/source-snapshot-types.js +12 -0
  97. package/dist/native/source-snapshot.d.ts +8 -0
  98. package/dist/native/source-snapshot.js +1201 -0
  99. package/dist/observation/learning.js +3 -2
  100. package/dist/openapi.js +167 -36
  101. package/dist/print.js +1 -1
  102. package/dist/purged-workflow.d.ts +12 -0
  103. package/dist/purged-workflow.js +43 -0
  104. package/dist/run-keys.d.ts +46 -0
  105. package/dist/run-keys.js +109 -0
  106. package/dist/run-launch.d.ts +16 -1
  107. package/dist/run-launch.js +30 -1
  108. package/dist/run-learning-served.d.ts +2 -2
  109. package/dist/run-model-key.d.ts +2 -2
  110. package/dist/run-model-key.js +5 -5
  111. package/dist/run-secrets.d.ts +2 -0
  112. package/dist/run-secrets.js +7 -4
  113. package/dist/run-view.d.ts +17 -0
  114. package/dist/run-view.js +25 -1
  115. package/dist/runner/adapter-loop.d.ts +11 -3
  116. package/dist/runner/adapter-loop.js +138 -22
  117. package/dist/runner/adapter-run-spec.js +25 -12
  118. package/dist/runner/audit.d.ts +2 -0
  119. package/dist/runner/audit.js +9 -1
  120. package/dist/runner/beside.js +2 -1
  121. package/dist/runner/claim-secrets.d.ts +29 -3
  122. package/dist/runner/claim-secrets.js +38 -4
  123. package/dist/runner/cli-run-spec.js +23 -12
  124. package/dist/runner/harness-loops.d.ts +6 -0
  125. package/dist/runner/harness-loops.js +11 -1
  126. package/dist/runner/held.d.ts +4 -0
  127. package/dist/runner/journal-kinds.d.ts +2 -0
  128. package/dist/runner/learned-first.d.ts +2 -0
  129. package/dist/runner/learned-first.js +1 -1
  130. package/dist/runner/learning-end.d.ts +7 -2
  131. package/dist/runner/learning-end.js +22 -10
  132. package/dist/runner/learning-seed.d.ts +9 -3
  133. package/dist/runner/learning-seed.js +2 -2
  134. package/dist/runner/main.d.ts +1 -0
  135. package/dist/runner/main.js +20 -13
  136. package/dist/runner/mcp-claim.js +6 -1
  137. package/dist/runner/mcp-run.d.ts +10 -7
  138. package/dist/runner/mcp-run.js +3 -5
  139. package/dist/runner/monid-run.js +9 -11
  140. package/dist/runner/project-checkpoint.d.ts +35 -0
  141. package/dist/runner/project-checkpoint.js +116 -0
  142. package/dist/runner/project-drain.d.ts +8 -0
  143. package/dist/runner/project-drain.js +25 -0
  144. package/dist/runner/project-host.d.ts +10 -0
  145. package/dist/runner/project-host.js +52 -0
  146. package/dist/runner/promotion.d.ts +14 -6
  147. package/dist/runner/promotion.js +98 -41
  148. package/dist/runner/redact.d.ts +13 -0
  149. package/dist/runner/redact.js +67 -1
  150. package/dist/runner/run-channel.d.ts +9 -0
  151. package/dist/runner/run-channel.js +15 -2
  152. package/dist/runner/run-child-host.d.ts +8 -4
  153. package/dist/runner/run-child-host.js +171 -41
  154. package/dist/runner/run-errors.js +2 -2
  155. package/dist/runner/runner-check.js +5 -2
  156. package/dist/runner/runner.js +26 -9
  157. package/dist/runner/store-secrets.js +7 -3
  158. package/dist/runner/workflow-first.d.ts +4 -0
  159. package/dist/runner/workflow-first.js +13 -0
  160. package/dist/runner/workflow-loop.d.ts +2 -1
  161. package/dist/runner/workflow-loop.js +2 -1
  162. package/dist/runner/workflow-spec.js +1 -1
  163. package/dist/runs-over-store.d.ts +34 -6
  164. package/dist/runs-over-store.js +133 -25
  165. package/dist/sdk/runs.d.ts +11 -1
  166. package/dist/sdk/runs.js +117 -26
  167. package/dist/sdk/schema.js +12 -2
  168. package/dist/sdk/workflows.d.ts +1 -1
  169. package/dist/server.d.ts +68 -32
  170. package/dist/server.js +600 -110
  171. package/dist/skills/agentrun-serve/SKILL.md +2 -1
  172. package/dist/source-sync/adoption.d.ts +15 -0
  173. package/dist/source-sync/adoption.js +36 -0
  174. package/dist/source-sync/auxiliary.d.ts +23 -0
  175. package/dist/source-sync/auxiliary.js +64 -0
  176. package/dist/source-sync/capture-git.d.ts +5 -0
  177. package/dist/source-sync/capture-git.js +272 -0
  178. package/dist/source-sync/capture-project.d.ts +53 -0
  179. package/dist/source-sync/capture-project.js +206 -0
  180. package/dist/source-sync/capture-refusal.d.ts +7 -0
  181. package/dist/source-sync/capture-refusal.js +16 -0
  182. package/dist/source-sync/capture.d.ts +11 -0
  183. package/dist/source-sync/capture.js +22 -0
  184. package/dist/source-sync/checkpoint-gate.d.ts +21 -0
  185. package/dist/source-sync/checkpoint-gate.js +52 -0
  186. package/dist/source-sync/checkpoints.d.ts +66 -0
  187. package/dist/source-sync/checkpoints.js +168 -0
  188. package/dist/source-sync/claim.d.ts +11 -0
  189. package/dist/source-sync/claim.js +48 -0
  190. package/dist/source-sync/destination.d.ts +47 -0
  191. package/dist/source-sync/destination.js +239 -0
  192. package/dist/source-sync/io.d.ts +15 -0
  193. package/dist/source-sync/io.js +52 -0
  194. package/dist/source-sync/local.d.ts +43 -0
  195. package/dist/source-sync/local.js +229 -0
  196. package/dist/source-sync/prepare.d.ts +59 -0
  197. package/dist/source-sync/prepare.js +93 -0
  198. package/dist/source-sync/projects.d.ts +61 -0
  199. package/dist/source-sync/projects.js +130 -0
  200. package/dist/source-sync/registry.d.ts +95 -0
  201. package/dist/source-sync/registry.js +226 -0
  202. package/dist/source-sync/service.d.ts +33 -0
  203. package/dist/source-sync/service.js +118 -0
  204. package/dist/source-sync/skill-edits.d.ts +12 -0
  205. package/dist/source-sync/skill-edits.js +122 -0
  206. package/dist/source-sync/snapshots.d.ts +48 -0
  207. package/dist/source-sync/snapshots.js +448 -0
  208. package/dist/source-sync/types.d.ts +9 -0
  209. package/dist/source-sync/types.js +14 -0
  210. package/dist/source-sync/workspace.d.ts +66 -0
  211. package/dist/source-sync/workspace.js +273 -0
  212. package/dist/store/agent-body.d.ts +4 -0
  213. package/dist/store/agent-body.js +16 -5
  214. package/dist/store/index.d.ts +2 -2
  215. package/dist/store/index.js +1 -1
  216. package/dist/store/schema.d.ts +2 -1
  217. package/dist/store/schema.js +2 -1
  218. package/dist/store/seal.d.ts +5 -1
  219. package/dist/store/seal.js +12 -3
  220. package/dist/store/sqlite/project-checkpoints.d.ts +11 -0
  221. package/dist/store/sqlite/project-checkpoints.js +70 -0
  222. package/dist/store/sqlite/run-launch.d.ts +4 -12
  223. package/dist/store/sqlite/run-launch.js +5 -19
  224. package/dist/store/sqlite/store.js +224 -170
  225. package/dist/store/store.d.ts +116 -39
  226. package/dist/store/store.js +14 -1
  227. package/dist/store-reads/learning.d.ts +2 -2
  228. package/dist/store-view.d.ts +3 -1
  229. package/dist/store-view.js +17 -5
  230. package/dist/template-import.d.ts +10 -2
  231. package/dist/template-import.js +116 -13
  232. package/dist/templates.d.ts +26 -5
  233. package/dist/templates.js +62 -10
  234. package/dist/timeline/index.d.ts +1 -1
  235. package/dist/timeline/index.js +1 -1
  236. package/dist/timeline/timeline.d.ts +5 -0
  237. package/dist/timeline/timeline.js +8 -0
  238. package/dist/tool-plane.d.ts +12 -12
  239. package/dist/tools.d.ts +8 -8
  240. package/dist/trigger-launch-hook.d.ts +47 -0
  241. package/dist/trigger-launch-hook.js +90 -0
  242. package/dist/trigger-targets.d.ts +14 -1
  243. package/dist/trigger-targets.js +20 -0
  244. package/dist/triggers.d.ts +54 -5
  245. package/dist/triggers.js +143 -8
  246. package/dist/uploads-archil.js +1 -1
  247. package/dist/uploads.js +1 -1
  248. package/dist/validate.js +1 -2
  249. package/dist/workspace/computer-for-claim.d.ts +2 -0
  250. package/dist/workspace/computer-for-claim.js +43 -0
  251. package/dist/workspace/paths.d.ts +6 -0
  252. package/dist/workspace/paths.js +6 -0
  253. package/dist/workspace/resolve-computer.d.ts +1 -0
  254. package/dist/workspace/run-tools.d.ts +2 -0
  255. package/dist/workspace/run-tools.js +8 -0
  256. package/launcher/agentrun-serve +1 -1
  257. package/package.json +10 -10
  258. package/skills/agentrun-serve/SKILL.md +2 -1
  259. package/templates/README.md +5 -2
  260. package/dist/console/assets/index-B-D0EM3j.js +0 -733
  261. package/dist/console/assets/index-DlQepP2J.css +0 -1
@@ -1,11 +1,5 @@
1
- import { type AgentRow, type NewRevision, type RevisionPlace, type RevisionRow, type Store, type TemplatePackage } from "./store/index.js";
1
+ import { type AgentRow, type NewRevision, type SettingsGuard, type RevisionPlace, type RevisionRow, type Store, type TemplatePackage } from "./store/index.js";
2
2
  import { type DefinitionBody, type Json } from "./validate.js";
3
- /** A UUIDv7: time-ordered, so a listing by (created_at, id) is stable, and unique per revision, per minted agent and per
4
- * upload (uploads.ts lists files by id, newest first). Two
5
- * minted in one millisecond keep their order: the 12 bits after the time count them up (RFC 9562's monotonic counter),
6
- * and a clock that steps back keeps the last millisecond, so each id sorts after the one before it. Without that, two
7
- * edits in one millisecond tie on created_at and their random ids could number the newer revision first. */
8
- export declare function uuidv7(now?: number): string;
9
3
  /** The store slice this module needs (its agents accessor). */
10
4
  export type AgentsStore = Pick<Store, "agents">;
11
5
  /** One agent as the routes show it: its row, its current revision and that revision's number (the oldest is 1), how many
@@ -17,13 +11,15 @@ export type AgentEntry = {
17
11
  version: number;
18
12
  revisions: number;
19
13
  sizes: Map<string, number>;
20
- /** The template package it was last applied from, as the newest revision an apply wrote keeps it (its first, until an
21
- * apply with agent_id updates it); absent or null for one made otherwise. */
14
+ /** The template package its current revision came from (packageOf): as the apply that wrote that revision, or the
15
+ * nearest one before it in its line, kept it; absent or null for one made otherwise. */
22
16
  template?: TemplatePackage | null;
23
17
  };
24
18
  /** Whether another system owns `agent`: an inline run with `external` made it (its `externalRef` set), so the system that
25
19
  * sent it sends its deletes, the agent's whole (DELETE /agents/{id}) and, on an API-only server, a run's purge. */
26
- export declare const ownedElsewhere: (agent: AgentRow) => boolean;
20
+ export declare const ownedElsewhere: (agent: AgentRow) => agent is AgentRow & {
21
+ externalRef: string;
22
+ };
27
23
  /** Refuses a write to an externally owned agent: one that mirrors an agent in another system (its `externalRef` set) is
28
24
  * read-only here — its source is the truth, which writes a new version by running it. Edits, set-current and archive are
29
25
  * refused (403 forbidden); reads work as for any agent. */
@@ -50,6 +46,11 @@ export type SaveStamp = Pick<NewRevision, "mcpPin" | "monidPin">;
50
46
  * to stamp on it. `on`: the revision this save is built on (an edit's: the agent's current one as this try read it, so a
51
47
  * retry on a newer one sees that one; null for a new agent), whose pins carry what the save's grants did not change. */
52
48
  export type SaveCheck = (revision: NewRevision, on: RevisionRow | null) => Promise<SaveStamp | void>;
49
+ /** Immutable assets prepared inside the delete turn; keep their I/O ownership until the revision CAS settles. */
50
+ export type SavePrepare = (revision: NewRevision, on: RevisionRow | null) => Promise<{
51
+ revision: NewRevision;
52
+ settled(): Promise<void>;
53
+ }>;
53
54
  /** The agent `id` as an entry, or null when there is no such agent: its row, its current revision (by the agent row's
54
55
  * current_revision), that revision's number (newest is the count), and the skill sizes. */
55
56
  export declare function getAgent(store: AgentsStore, id: string): Promise<AgentEntry | null>;
@@ -91,9 +92,11 @@ export type InTurn = <T>(work: () => Promise<T>) => Promise<T>;
91
92
  * `fromPackage`: the definition is a whole package's (an apply with agent_id), so what it leaves out is not carried over
92
93
  * (editOn). `inTurn`: where the agent is read again and the revision written (the server's agentWrite, which refuses a
93
94
  * purged agent, or one whose purge stopped part way); the check runs outside it. */
94
- export declare function commitAgent(store: AgentsStore, read: AgentEntry, { definition, skills, note }: DefinitionBody, { ifCurrent, check, contract, template, fromPackage, inTurn }?: {
95
+ export declare function commitAgent(store: AgentsStore, read: AgentEntry, { definition, skills, note }: DefinitionBody, { ifCurrent, settingsGuards, check, prepare, contract, template, fromPackage, inTurn }?: {
95
96
  ifCurrent?: string | null;
97
+ settingsGuards?: readonly SettingsGuard[];
96
98
  check?: SaveCheck;
99
+ prepare?: SavePrepare;
97
100
  contract?: boolean;
98
101
  template?: TemplatePackage;
99
102
  fromPackage?: boolean;
@@ -137,15 +140,6 @@ export declare function agentView(entry: AgentEntry, origin: string, extra?: {
137
140
  learning?: {
138
141
  pending: number;
139
142
  } | undefined;
140
- definition: Json | null;
141
- kind: string | null;
142
- mcp_pin: Record<string, {
143
- tools: Record<string, unknown>[];
144
- prices?: Record<string, number>;
145
- }> | null;
146
- revision: string | null;
147
- revisions: number;
148
- source: null;
149
143
  template: {
150
144
  id: string;
151
145
  version: string;
@@ -166,6 +160,18 @@ export declare function agentView(entry: AgentEntry, origin: string, extra?: {
166
160
  home_etag: string;
167
161
  archived_at: string | null;
168
162
  console_url: string;
163
+ source_sync?: {
164
+ moved: true;
165
+ } | undefined;
166
+ definition: Json | null;
167
+ kind: string | null;
168
+ mcp_pin: Record<string, {
169
+ tools: Record<string, unknown>[];
170
+ prices?: Record<string, number>;
171
+ }> | null;
172
+ revision: string | null;
173
+ revisions: number;
174
+ source: null;
169
175
  external?: (ExternalRef & {
170
176
  version: string | null;
171
177
  }) | undefined;
@@ -5,8 +5,9 @@
5
5
  // racing another writer; the store's own transactions make each write atomic.
6
6
  //
7
7
  // The run counts an agent view shows (runs.count, runs.live) are E3's run reads, not this module's; agentView takes them.
8
- import { randomBytes } from "node:crypto";
8
+ import { sourceSyncOf } from "./source-sync/types.js";
9
9
  import { purgedAgent } from "./agents.js";
10
+ import { uuidv7 } from "./ids.js";
10
11
  import { agentLink } from "./console-links.js";
11
12
  import { approvalsOf } from "./approvals.js";
12
13
  import { ApiError, invalid } from "./errors.js";
@@ -18,31 +19,6 @@ import { AgentBodyInvalid, RevisionMoved, bodyOf, canonical, isObject, StoreCons
18
19
  import { canonicalToolSettings, settingsIssues } from "./tool-plane.js";
19
20
  import { computerOfPlace, settingOfDefinition } from "./computer-setting.js";
20
21
  import { skillIssues, skillNames } from "./validate.js";
21
- /** The last millisecond a UUIDv7 was minted in, and how many were minted in it. */
22
- let mintedMs = -1;
23
- let mintedInMs = 0;
24
- /** A UUIDv7: time-ordered, so a listing by (created_at, id) is stable, and unique per revision, per minted agent and per
25
- * upload (uploads.ts lists files by id, newest first). Two
26
- * minted in one millisecond keep their order: the 12 bits after the time count them up (RFC 9562's monotonic counter),
27
- * and a clock that steps back keeps the last millisecond, so each id sorts after the one before it. Without that, two
28
- * edits in one millisecond tie on created_at and their random ids could number the newer revision first. */
29
- export function uuidv7(now = Date.now()) {
30
- if (now > mintedMs) {
31
- mintedMs = now;
32
- mintedInMs = 0;
33
- }
34
- else if (++mintedInMs > 0xfff) {
35
- mintedMs += 1;
36
- mintedInMs = 0;
37
- }
38
- const bytes = randomBytes(16);
39
- bytes.writeUIntBE(mintedMs, 0, 6);
40
- bytes[6] = 0x70 | (mintedInMs >> 8);
41
- bytes[7] = mintedInMs & 0xff;
42
- bytes[8] = (bytes[8] & 0x3f) | 0x80;
43
- const hex = bytes.toString("hex");
44
- return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
45
- }
46
22
  const ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
47
23
  /** A store refusal as the request's answer: a duplicate name (agent exists) and a constraint map the right way. */
48
24
  function storeError(error) {
@@ -68,7 +44,7 @@ export const externalKey = ({ source, kind, id }) => `${source}:${kind}:${id}`;
68
44
  /** The agent's reference in its source and the version its current revision maps there, or null for an agent of this
69
45
  * server's own. */
70
46
  export function externalOf(agent, revision) {
71
- if (agent.externalRef === null)
47
+ if (!ownedElsewhere(agent))
72
48
  return null;
73
49
  const [source = "", kind = "", ...id] = agent.externalRef.split(":");
74
50
  return { source, kind, id: id.join(":"), version: revision?.externalVersion ?? null };
@@ -181,7 +157,19 @@ export async function getAgent(store, id) {
181
157
  const revisions = await store.agents.revisions(id); // oldest first (created_at, id)
182
158
  const at = agent.currentRevision === null ? -1 : revisions.findIndex((r) => r.id === agent.currentRevision);
183
159
  const revision = at < 0 ? null : revisions[at];
184
- return { agent, revision, version: at < 0 ? 0 : at + 1, revisions: revisions.length, sizes: sizesOf(revision), template: revisions.findLast((r) => r.package)?.package ?? null };
160
+ return { agent, revision, version: at < 0 ? 0 : at + 1, revisions: revisions.length, sizes: sizesOf(revision), template: packageOf(revision, revisions) };
161
+ }
162
+ /** The package `revision` came from: its own, else that of the nearest revision before it in its line (each one's parent,
163
+ * the revision current when it was committed) that an apply wrote. An edit carries the package it was made on, and a
164
+ * restore of an older revision reads that revision's, never a later apply's. Null for a line no apply wrote. */
165
+ function packageOf(revision, revisions) {
166
+ const byId = new Map(revisions.map((one) => [one.id, one]));
167
+ // Bounded by the count: a line is never longer than the revisions there are.
168
+ for (let at = revision, steps = 0; at && steps < revisions.length; at = at.parent === null ? null : byId.get(at.parent) ?? null, steps++) {
169
+ if (at.package)
170
+ return at.package;
171
+ }
172
+ return null;
185
173
  }
186
174
  /** Every agent here, newest first (its creation, then its id). Archived agents are left out by default. */
187
175
  export async function listAgents(store, options = {}) {
@@ -250,7 +238,7 @@ const EDIT_TRIES = 5;
250
238
  * `fromPackage`: the definition is a whole package's (an apply with agent_id), so what it leaves out is not carried over
251
239
  * (editOn). `inTurn`: where the agent is read again and the revision written (the server's agentWrite, which refuses a
252
240
  * purged agent, or one whose purge stopped part way); the check runs outside it. */
253
- export async function commitAgent(store, read, { definition, skills, note }, { ifCurrent, check, contract = false, template, fromPackage = false, inTurn } = {}) {
241
+ export async function commitAgent(store, read, { definition, skills, note }, { ifCurrent, settingsGuards, check, prepare, contract = false, template, fromPackage = false, inTurn } = {}) {
254
242
  const stale = () => new ApiError("precondition_failed", "the agent's current revision moved since the If-Match it was read at: read the agent again");
255
243
  const held = (entry) => {
256
244
  if (ifCurrent !== undefined && (entry.revision?.id ?? null) !== ifCurrent)
@@ -300,8 +288,9 @@ export async function commitAgent(store, read, { definition, skills, note }, { i
300
288
  checkPast(definition, now.version);
301
289
  else
302
290
  checkVersion(definition, now.revisions + 1);
291
+ const prepared = await prepare?.(revision, now.revision);
303
292
  try {
304
- await store.agents.addRevision({ agentId: agent.id, ifCurrent: base, ...revision, ...(described ? { description } : {}) });
293
+ await store.agents.addRevision({ agentId: agent.id, ifCurrent: base, ...(settingsGuards ? { settingsGuards } : {}), ...(prepared?.revision ?? revision), ...(described ? { description } : {}) });
305
294
  return (await getAgent(store, agent.id));
306
295
  }
307
296
  catch (error) {
@@ -309,6 +298,9 @@ export async function commitAgent(store, read, { definition, skills, note }, { i
309
298
  storeError(error);
310
299
  return undefined;
311
300
  }
301
+ finally {
302
+ await prepared?.settled();
303
+ }
312
304
  });
313
305
  if (landed)
314
306
  return landed;
@@ -346,7 +338,7 @@ function editOn(entry, definition, skills, note, fromPackage = false) {
346
338
  // No approvals here: an edit that leaves them out asks (openapi.ts DefinitionInput.approvals),
347
339
  // so no edit makes an agent unattended by saying nothing. The console's edit sends back the approvals it read.
348
340
  ...(definition.max_cost_usd === undefined && currentBody.maxCostUsd !== undefined ? { max_cost_usd: currentBody.maxCostUsd } : {}),
349
- // So does its limit on each run's free-model requests (0 clears it): leaving a field out never removes a limit.
341
+ // So does its free-model request limit: see DefinitionInput.max_requests (openapi.ts).
350
342
  ...(definition.max_requests === undefined && currentBody.maxRequests !== undefined ? { max_requests: currentBody.maxRequests } : {}),
351
343
  // Its input's and its structured answer's schemas are the agent's contract with its callers: an edit that leaves
352
344
  // one out keeps it.
@@ -356,7 +348,22 @@ function editOn(entry, definition, skills, note, fromPackage = false) {
356
348
  ...(definition.checkout === undefined && current.kind === "agentic" && !isObject(definition.workflow) && currentBody.checkout !== undefined ? { checkout: currentBody.checkout } : {}),
357
349
  }
358
350
  : {};
359
- return makeRevision({ ...definition, ...carried, ...owned }, files, note);
351
+ const made = makeRevision({ ...definition, ...carried, ...owned }, files, note);
352
+ const sourceSync = sourceSyncOf(currentBody);
353
+ if (sourceSync) {
354
+ if (made.kind !== "agentic")
355
+ throw new ApiError("input_invalid", "A synced agent keeps its agentic execution. Create a workflow separately.");
356
+ const body = made.body;
357
+ if (body.native || body.sdk || body.cli_learning)
358
+ throw new ApiError("input_invalid", "A moved agent keeps managed execution. Its source connection only syncs setup and captures source runs.");
359
+ if (body.harness !== currentBody.harness) {
360
+ const missing = (currentBody.tools ?? []).filter(tool => !body.tools?.includes(tool));
361
+ if (missing.length)
362
+ throw new ApiError("input_invalid", `Changing harness must preserve this agent's required tools: ${missing.join(", ")}. Choose a compatible harness.`);
363
+ }
364
+ return { ...made, body: { ...made.body, sourceSync } };
365
+ }
366
+ return made;
360
367
  }
361
368
  /** Makes `revisionId`, one of the agent's own, its current one (POST /agents/{id}/current). */
362
369
  export async function setCurrentRevision(store, entry, revisionId) {
@@ -434,6 +441,7 @@ export function agentView(entry, origin, extra = {}) {
434
441
  revision: revision?.id ?? null,
435
442
  revisions: entry.revisions,
436
443
  source: null,
444
+ ...(sourceSyncOf(body) ? { source_sync: { moved: true } } : {}),
437
445
  // The template package it was applied from (its first revision keeps it): the package's id, version and the commit an
438
446
  // imported one was read at (null for a bundled one). Null for an agent made otherwise.
439
447
  template: entry.template ? { id: entry.template.id, version: entry.template.version, sha: entry.template.sha ?? null } : null,
@@ -475,7 +483,7 @@ export function pinView(pin) {
475
483
  const out = {};
476
484
  for (const [server, pinned] of Object.entries(pin)) {
477
485
  out[server] = {
478
- tools: (pinned.tools ?? []).map((tool) => ({ name: tool.name, ...(tool.title ? { title: tool.title } : {}), ...(tool.description ? { description: tool.description } : {}), input_schema: tool.inputSchema ?? {}, ...(tool.annotations ? { annotations: tool.annotations } : {}) })),
486
+ tools: (pinned.tools ?? []).map((tool) => ({ name: tool.name, ...(tool.title ? { title: tool.title } : {}), ...(tool.description ? { description: tool.description } : {}), input_schema: tool.inputSchema ?? {}, ...(tool.annotations ? { annotations: tool.annotations } : {}), ...(tool.resource !== undefined ? { resource: tool.resource } : {}) })),
479
487
  ...(pinned.prices && Object.keys(pinned.prices).length ? { prices: { ...pinned.prices } } : {}),
480
488
  };
481
489
  }
@@ -1,6 +1,5 @@
1
+ import { NOT_SET_UP } from "./runnable.js";
1
2
  import type { Route } from "./server.js";
2
- /** The variable that turns the profile on. */
3
- export declare const API_ONLY_ENV = "AGENTRUN_API_ONLY";
4
3
  /** The routes (server.ts ROUTES, by name) an API-only server serves. Past a run's own, why each group is here:
5
4
  * - a run's hosted machine fetches computerd with the token its create minted, not the server's;
6
5
  * - the computers list and the Archil settings are read before a launch, naming keys, never a value;
@@ -10,11 +9,32 @@ export declare const API_ONLY_ENV = "AGENTRUN_API_ONLY";
10
9
  * - a backend reads what its agents learned (loop, promotions, cost per run, a run's learning), cut as the console's,
11
10
  * and resets it (deleteAgentLearning: the agent and its runs kept) when it erases what an agent learned;
12
11
  * - a run's usage lines (what its cost.usd joins, by meter) are a read of that run alone, cut as the run's read is;
13
- * - an operator or a scaler reads the runners' capacity (getCapacity, capacity.ts) from the server whose runners run apart. */
12
+ * - an operator or a scaler reads the runners' capacity (getCapacity, capacity.ts) from the server whose runners run apart;
13
+ * - a backend that builds runs from the MCP servers saved here reads their names (listMcpServerNames), never a URL or a
14
+ * credential, to hold back a job whose server isn't saved before its launch is refused for it;
15
+ * - a backend uploads an agent's package (importTemplate, as {files} alone: a GitHub source is refused in this profile's
16
+ * words, template-import.ts), which an apply then makes into its agent;
17
+ * - a backend that deploys agents here applies their template, reads the agent and its revisions, moves its current
18
+ * revision back, and archives it before its delete (or unarchives it, the schedule and feed triggers its archive
19
+ * turned off on again when the server has the launch hook): its token already makes agents through inline runs, so it
20
+ * gains no new power. A trigger the apply can't make here is skipped, and said (apiOnlyTriggerSkipped). */
14
21
  export declare const API_ONLY_ROUTES: ReadonlySet<string>;
15
- /** Whether `env` turns the profile on: `1` or `true` on; unset, empty, `0` or `false` off. Any other value is refused in
16
- * words (a TypeError), so a typo never leaves the console open on a server meant to be API-only. */
17
- export declare function apiOnlyFrom(env?: NodeJS.ProcessEnv): boolean;
22
+ /** The trigger sources an apply on an API-only server makes once the server has the launch hook: the ones that fire on
23
+ * its own clock and need nothing a refused route sets up. Each firing goes to the backend in front of it
24
+ * (trigger-launch-hook.ts), which starts the run through the API on its own keys and budget, never on this server's
25
+ * model key. A webhook, GitHub or Composio trigger is delivered to a hook this profile refuses, and an email trigger
26
+ * reads the account Settings → Email saves: none of them is made here, hook or not. */
27
+ export declare const API_ONLY_HOOKED_KINDS: ReadonlySet<string>;
28
+ /** Why an apply on an API-only server (and its dry run's plan) does not make `trigger` of the `packageName` template, or
29
+ * undefined for one it makes: a schedule or a feed when the server has the launch hook (`hooked`). Without it, those two
30
+ * are not_set_up_here (set the hook and apply again); any other source is not_an_option, hook or not. */
31
+ export declare function apiOnlyTriggerSkipped(packageName: string, trigger: {
32
+ name?: unknown;
33
+ source?: unknown;
34
+ }, hooked: boolean): {
35
+ reason: typeof NOT_SET_UP | "not_an_option";
36
+ message: string;
37
+ } | undefined;
18
38
  /** Whether an API-only server serves `method` on `raw` (the path as sent, its query cut): a /v2 path one of
19
39
  * API_ONLY_ROUTES matches for that method (HEAD as GET), or a GET of a run's computer live view. */
20
40
  export declare function servedApiOnly(routes: readonly Route[], method: string | undefined, raw: string): boolean;
package/dist/api-only.js CHANGED
@@ -1,5 +1,10 @@
1
- /** The variable that turns the profile on. */
2
- export const API_ONLY_ENV = "AGENTRUN_API_ONLY";
1
+ // The API-only profile (AGENTRUN_API_ONLY=1): a server that runs behind its caller's backend serves the run routes and a
2
+ // deploy's routes alone, and refuses every other address before anything else reads the request: the console at "/" and
3
+ // its assets, sign-in and setup, settings, MCP, triggers and their webhook hooks, the rest of agents and templates.
4
+ // Off by default.
5
+ import { API_ONLY_ENV } from "./env-switch.js";
6
+ import { NOT_SET_UP } from "./runnable.js";
7
+ import { LAUNCH_HOOK_SECRET_ENV, LAUNCH_HOOK_URL_ENV } from "./trigger-launch-hook.js";
3
8
  /** The routes (server.ts ROUTES, by name) an API-only server serves. Past a run's own, why each group is here:
4
9
  * - a run's hosted machine fetches computerd with the token its create minted, not the server's;
5
10
  * - the computers list and the Archil settings are read before a launch, naming keys, never a value;
@@ -9,7 +14,15 @@ export const API_ONLY_ENV = "AGENTRUN_API_ONLY";
9
14
  * - a backend reads what its agents learned (loop, promotions, cost per run, a run's learning), cut as the console's,
10
15
  * and resets it (deleteAgentLearning: the agent and its runs kept) when it erases what an agent learned;
11
16
  * - a run's usage lines (what its cost.usd joins, by meter) are a read of that run alone, cut as the run's read is;
12
- * - an operator or a scaler reads the runners' capacity (getCapacity, capacity.ts) from the server whose runners run apart. */
17
+ * - an operator or a scaler reads the runners' capacity (getCapacity, capacity.ts) from the server whose runners run apart;
18
+ * - a backend that builds runs from the MCP servers saved here reads their names (listMcpServerNames), never a URL or a
19
+ * credential, to hold back a job whose server isn't saved before its launch is refused for it;
20
+ * - a backend uploads an agent's package (importTemplate, as {files} alone: a GitHub source is refused in this profile's
21
+ * words, template-import.ts), which an apply then makes into its agent;
22
+ * - a backend that deploys agents here applies their template, reads the agent and its revisions, moves its current
23
+ * revision back, and archives it before its delete (or unarchives it, the schedule and feed triggers its archive
24
+ * turned off on again when the server has the launch hook): its token already makes agents through inline runs, so it
25
+ * gains no new power. A trigger the apply can't make here is skipped, and said (apiOnlyTriggerSkipped). */
13
26
  export const API_ONLY_ROUTES = new Set([
14
27
  "createRun", "createInlineRun", "getComputerDaemon",
15
28
  "getRunComputer", "takeOverRunComputer", "handBackRunComputer", "createRunComputerViewer",
@@ -20,17 +33,26 @@ export const API_ONLY_ROUTES = new Set([
20
33
  "sendMessage", "stopRun", "cancelRun", "raiseRunCap", "gradeRun",
21
34
  "listRunFiles", "readRunFile",
22
35
  "createFile", "listFiles", "getFile", "uploadFile", "deleteFile",
23
- "getCapabilities", "getHealth", "getUsage", "getCapacity",
36
+ "getCapabilities", "getHealth", "getUsage", "getCapacity", "listMcpServerNames",
37
+ "importTemplate", "applyTemplate", "getAgent", "listRevisions", "setCurrent", "archiveAgent", "unarchiveAgent",
24
38
  ]);
25
- /** Whether `env` turns the profile on: `1` or `true` on; unset, empty, `0` or `false` off. Any other value is refused in
26
- * words (a TypeError), so a typo never leaves the console open on a server meant to be API-only. */
27
- export function apiOnlyFrom(env = process.env) {
28
- const given = env[API_ONLY_ENV]?.trim().toLowerCase() ?? "";
29
- if (given === "1" || given === "true")
30
- return true;
31
- if (given === "" || given === "0" || given === "false")
32
- return false;
33
- throw new TypeError(`${API_ONLY_ENV} is 1 (serve the run API only) or 0 (the whole server), not ${JSON.stringify(env[API_ONLY_ENV])}`);
39
+ /** The trigger sources an apply on an API-only server makes once the server has the launch hook: the ones that fire on
40
+ * its own clock and need nothing a refused route sets up. Each firing goes to the backend in front of it
41
+ * (trigger-launch-hook.ts), which starts the run through the API on its own keys and budget, never on this server's
42
+ * model key. A webhook, GitHub or Composio trigger is delivered to a hook this profile refuses, and an email trigger
43
+ * reads the account Settings → Email saves: none of them is made here, hook or not. */
44
+ export const API_ONLY_HOOKED_KINDS = new Set(["schedule", "feed"]);
45
+ /** Why an apply on an API-only server (and its dry run's plan) does not make `trigger` of the `packageName` template, or
46
+ * undefined for one it makes: a schedule or a feed when the server has the launch hook (`hooked`). Without it, those two
47
+ * are not_set_up_here (set the hook and apply again); any other source is not_an_option, hook or not. */
48
+ export function apiOnlyTriggerSkipped(packageName, trigger, hooked) {
49
+ const kind = trigger.source !== null && typeof trigger.source === "object" ? String(trigger.source.kind) : "";
50
+ const named = `The ${packageName} template's trigger ${String(trigger.name).trim()} (${kind}) was not made: this server serves the run API only (${API_ONLY_ENV}=1)`;
51
+ if (!API_ONLY_HOOKED_KINDS.has(kind))
52
+ return { reason: "not_an_option", message: `${named}, which serves no route or setting a ${kind} trigger needs. Start its runs through the API instead.` };
53
+ if (hooked)
54
+ return undefined;
55
+ return { reason: NOT_SET_UP, message: `${named} and has no launch hook, so its firings have nowhere to go. Start its runs through the API, or set the launch hook (${LAUNCH_HOOK_URL_ENV} and ${LAUNCH_HOOK_SECRET_ENV}) and apply again: each firing then goes to your backend, which starts its run.` };
34
56
  }
35
57
  /** A run's computer live view: its page, files and socket, which take the viewer credential alone here (server.ts). */
36
58
  const COMPUTER_LIVE = /^\/v2\/runs\/[^/]+\/computer\/live\//;
@@ -4,6 +4,7 @@ import type { Settings } from "./store/index.js";
4
4
  * loopback; unset, the listen address decides (claudeLoginSwitchedOff). */
5
5
  export declare const CLAUDE_LOGIN_ENV = "AGENTRUN_CLAUDE_CODE_LOGIN";
6
6
  export declare const claudeLoginOff: (env: Readonly<Record<string, string | undefined>>) => boolean;
7
+ export declare const loopback: (host: string) => boolean;
7
8
  /** Why the mode is off on a server listening on `listen`, or undefined where it is there: the switch's `off`, or, unset,
8
9
  * a listen address past loopback. */
9
10
  export declare function claudeLoginSwitchedOff(env: Readonly<Record<string, string | undefined>>, listen: string): string | undefined;
@@ -24,7 +24,7 @@ for (const operation of ["getClaudeLogin", "turnOnClaudeLogin", "turnOffClaudeLo
24
24
  export const CLAUDE_LOGIN_ENV = "AGENTRUN_CLAUDE_CODE_LOGIN";
25
25
  export const claudeLoginOff = (env) => /^(off|0|false|no)$/i.test((env[CLAUDE_LOGIN_ENV] ?? "").trim());
26
26
  const claudeLoginOn = (env) => /^(on|1|true|yes)$/i.test((env[CLAUDE_LOGIN_ENV] ?? "").trim());
27
- const loopback = (host) => host === "localhost" || host === "::1" || /^127\./.test(host); // key-gate: loopback-rule the default follows a loopback listen address
27
+ export const loopback = (host) => host === "localhost" || host === "::1" || /^127\./.test(host); // key-gate: loopback-rule the default follows a loopback listen address
28
28
  /** Why the mode is off on a server listening on `listen`, or undefined where it is there: the switch's `off`, or, unset,
29
29
  * a listen address past loopback. */
30
30
  export function claudeLoginSwitchedOff(env, listen) {
@@ -1,3 +1,5 @@
1
+ import { type CliLearningRuntime } from './install.js';
2
+ import { type SourceLocalConsent } from '../source-sync/local.js';
1
3
  type CliIO = {
2
4
  stdout?: (text: string) => void;
3
5
  stderr?: (text: string) => void;
@@ -5,6 +7,7 @@ type CliIO = {
5
7
  fetch?: typeof fetch;
6
8
  /** Test/packaging boundary: executable plus arguments, never evaluated while installing. */
7
9
  command?: string[];
10
+ sourceConsent?: (runtime: CliLearningRuntime, project: string) => Promise<SourceLocalConsent>;
8
11
  };
9
12
  /** Installer/status command plus the bounded stdin worker invoked by ordinary CLI hooks. */
10
13
  export declare function learningMain(argv: string[], io?: CliIO): Promise<number>;
@@ -6,7 +6,10 @@ import { defaultData } from '../server-fs.js';
6
6
  import { takeHold, releaseHold } from '../harness-install.js';
7
7
  import { cliLearningUrl, installCliLearning, removeCliLearning, statusCliLearning } from './install.js';
8
8
  import { connectionFile, readConnection, saveConnection } from './state.js';
9
- const USAGE = 'usage: agentrun-serve learning connect|status|disconnect|retry --runtime codex|claude-code [--project PATH] [--url LOOPBACK_URL] [--data SERVER_DATA]';
9
+ import { sourceLocalConsent } from '../source-sync/local.js';
10
+ import { selectedNative } from '../native/connection.js';
11
+ import { nativeEnvironment } from '../native/environment.js';
12
+ const USAGE = 'usage: agentrun-serve learning connect|status|disconnect|retry --runtime codex|claude-code [--project PATH] [--url LOOPBACK_URL] [--data SERVER_DATA] [--no-sync]';
10
13
  async function ownerToken(data) {
11
14
  const fromEnvironment = secret('AGENTRUN_API_KEY') || secret('AGENTRUN_TOKEN');
12
15
  if (fromEnvironment)
@@ -82,7 +85,7 @@ export async function learningMain(argv, io = {}) {
82
85
  try {
83
86
  const { values, positionals } = parseArgs({ args: argv, allowPositionals: true, options: {
84
87
  project: { type: 'string' }, runtime: { type: 'string' }, data: { type: 'string' }, url: { type: 'string' },
85
- json: { type: 'boolean' }, help: { type: 'boolean' },
88
+ json: { type: 'boolean' }, help: { type: 'boolean' }, 'no-sync': { type: 'boolean' },
86
89
  } });
87
90
  if (values.help) {
88
91
  output(USAGE);
@@ -166,6 +169,12 @@ export async function learningMain(argv, io = {}) {
166
169
  return 0;
167
170
  }
168
171
  const url = await serverUrl(values.url, dataDir);
172
+ const sourceSync = values['no-sync'] ? undefined : await (io.sourceConsent ?? (async (runtime, project) => {
173
+ const env = nativeEnvironment();
174
+ return sourceLocalConsent(await selectedNative({ runtime, project }, env), env);
175
+ }))(runtime, project);
176
+ if (sourceSync)
177
+ errorOutput('Setup sync copies this project’s instructions, authored skills and assets, supported tools/settings, project files and bounded Git history to AgentRun. Native credentials stay here. Future changes keep syncing until disabled; use --no-sync to connect capture only.');
169
178
  const before = await statusCliLearning(options);
170
179
  if (before.state === 'partial')
171
180
  throw new Error('AgentRun hooks were changed or disabled. Run learning disconnect before reconnecting.');
@@ -192,11 +201,16 @@ export async function learningMain(argv, io = {}) {
192
201
  if (!active)
193
202
  throw new Error('This learning connection is inactive. Run learning disconnect, then learning connect to enroll again.');
194
203
  const installation = await installCliLearning({ ...options, url, command: io.command });
204
+ if (sourceSync) {
205
+ const synced = await request(fetcher, url, '/v2/cli-learning/connections', await ownerToken(dataDir), 'POST', { project, runtime, source_sync: sourceSync });
206
+ if (!synced.ok)
207
+ throw new Error(`Capture is connected, but setup sync was refused (HTTP ${synced.status}). Check the source and server are on the same machine, then retry connect.`);
208
+ }
195
209
  output(JSON.stringify({ ...installation, connection_id: existing.connection_id, agent_id: existing.agent_id }, null, 2));
196
210
  return 0;
197
211
  }
198
212
  const token = await ownerToken(dataDir);
199
- const response = await request(fetcher, url, '/v2/cli-learning/connections', token, 'POST', { project, runtime });
213
+ const response = await request(fetcher, url, '/v2/cli-learning/connections', token, 'POST', { project, runtime, ...(sourceSync ? { source_sync: sourceSync } : {}) });
200
214
  if (!response.ok)
201
215
  throw new Error(`Server refused the learning connection (HTTP ${response.status}).`);
202
216
  const body = await response.json();
@@ -1,10 +1,11 @@
1
1
  // A local owner enrolls one installed CLI. Its hook credential can only submit prompt windows for this agent.
2
+ import { cliCaptureOf } from "../source-sync/capture.js";
2
3
  import { createHash, createHmac, randomBytes, timingSafeEqual } from 'node:crypto';
3
4
  import { basename } from 'node:path';
4
5
  import { createAgent, getAgent } from '../agents-store.js';
5
6
  import { ApiError } from '../errors.js';
6
7
  import { selectedNative, launchNative } from '../native/connection.js';
7
- import { cliLearningOf, isObject } from '../store/agent-body.js';
8
+ import { isObject } from '../store/agent-body.js';
8
9
  const key = (id) => `cli-learning-connection:${id}`;
9
10
  const hash = (text) => createHash('sha256').update(text).digest();
10
11
  export class CliLearningConnections {
@@ -69,7 +70,7 @@ export class CliLearningConnections {
69
70
  throw new ApiError("home_busy", "The connection changed concurrently; retry this prompt-window acknowledgement.");
70
71
  }
71
72
  async list() { const result = []; for (const agent of await this.store.agents.list()) {
72
- const entry = await getAgent(this.store, agent.id), binding = cliLearningOf(entry?.revision?.body);
73
+ const entry = await getAgent(this.store, agent.id), binding = entry ? (await cliCaptureOf(this.store, entry))?.binding : undefined;
73
74
  if (binding) {
74
75
  const row = await this.get(binding.connection_id).catch(() => undefined);
75
76
  if (row)
@@ -1,3 +1,4 @@
1
+ import { SOURCE_LOCAL_CONSENT } from '../native/schema.js';
1
2
  import { SDK_PATHS, SDK_RUN } from '../sdk/schema.js';
2
3
  const text = { type: 'string' };
3
4
  const object = (properties, required = Object.keys(properties)) => ({ type: 'object', additionalProperties: false, properties, required });
@@ -16,7 +17,7 @@ const completionSchema = completion.requestBody.content['application/json'].sche
16
17
  const receipt = SDK_PATHS['/agents/{agent_id}/sdk-runs'].post.responses[201];
17
18
  export const CLI_LEARNING_PATHS = {
18
19
  '/cli-learning/connections': {
19
- post: { ...owner, operationId: 'enrollCliLearning', summary: 'Enable learning for an existing local CLI without launching it', description: 'Owner authenticated, source server bound to loopback without a public URL. Verifies native sign-in without a model call. Repeated enrollment preserves the same agent and learned files, and keeps its current Learning Off setting. Store the returned connection token privately, never give it to a model.', requestBody: body(object({ runtime: { enum: ['codex', 'claude-code'] }, project: text, name: text }, ['runtime', 'project'])), responses: { 201: response(object({ ...connection.properties, token: text }, [...connection.required, "token"])) } },
20
+ post: { ...owner, operationId: 'enrollCliLearning', summary: 'Enable learning for an existing local CLI without launching it', description: 'Owner authenticated, source server bound to loopback without a public URL. Verifies native sign-in without a model call. Repeated enrollment preserves the same agent and learned files, and keeps its current Learning Off setting. Store the returned connection token privately, never give it to a model.', requestBody: body(object({ runtime: { enum: ['codex', 'claude-code'] }, project: text, name: text, source_sync: SOURCE_LOCAL_CONSENT }, ['runtime', 'project'])), responses: { 201: response(object({ ...connection.properties, token: text }, [...connection.required, "token"])) } },
20
21
  get: { ...owner, operationId: 'listCliLearning', summary: 'Read enrolled CLI learning connections', responses: { 200: response(object({ connections: { type: 'array', items: connection } })) } }
21
22
  },
22
23
  '/cli-learning/connections/{connection_id}': { delete: { ...owner, operationId: 'revokeCliLearning', summary: 'Revoke CLI capture and guidance delivery, retaining history and learned files', parameters: [id('connection_id')], responses: { 200: response(connection) } } },