@andorra-labs/code 0.1.17 → 0.1.19

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 (313) hide show
  1. package/dist/src/account-jev-savings.d.ts +4 -0
  2. package/dist/src/account-jev-savings.js +92 -0
  3. package/dist/src/acp-agent.js +2 -2
  4. package/dist/src/agent-execution.js +441 -53
  5. package/dist/src/agent-mcp.js +7 -1
  6. package/dist/src/agent-modifiers.js +5 -7
  7. package/dist/src/analytics.d.ts +19 -1
  8. package/dist/src/analytics.js +9 -1
  9. package/dist/src/andorra/entry.js +15 -6
  10. package/dist/src/andorra/errors.js +3 -0
  11. package/dist/src/andorra/hosted.d.ts +8 -0
  12. package/dist/src/andorra/hosted.js +22 -3
  13. package/dist/src/andorra/streams.d.ts +49 -0
  14. package/dist/src/andorra/streams.js +98 -0
  15. package/dist/src/antigravity-acp.d.ts +28 -0
  16. package/dist/src/antigravity-acp.js +150 -0
  17. package/dist/src/antigravity-terminal.d.ts +2 -0
  18. package/dist/src/antigravity-terminal.js +214 -0
  19. package/dist/src/app-server/adaptive-routing-settings.d.ts +37 -0
  20. package/dist/src/app-server/adaptive-routing-settings.js +69 -0
  21. package/dist/src/app-server/artifact.d.ts +14 -0
  22. package/dist/src/app-server/artifact.js +46 -0
  23. package/dist/src/app-server/legal-protocol.d.ts +33 -0
  24. package/dist/src/app-server/legal-protocol.js +16 -0
  25. package/dist/src/app-server/protocol.d.ts +34 -3
  26. package/dist/src/app-server/protocol.js +3 -1
  27. package/dist/src/app-server/telemetry-protocol.d.ts +53 -0
  28. package/dist/src/app-server/telemetry-protocol.js +2 -0
  29. package/dist/src/app-server/telemetry.d.ts +38 -0
  30. package/dist/src/app-server/telemetry.js +163 -0
  31. package/dist/src/app-server/workspace.d.ts +21 -0
  32. package/dist/src/app-server/workspace.js +192 -10
  33. package/dist/src/app-server.d.ts +82 -26
  34. package/dist/src/app-server.js +1573 -417
  35. package/dist/src/attachments.d.ts +10 -0
  36. package/dist/src/attachments.js +102 -7
  37. package/dist/src/auth/AuthManager.d.ts +11 -2
  38. package/dist/src/auth/AuthManager.js +56 -13
  39. package/dist/src/auth/index.d.ts +5 -1
  40. package/dist/src/auth/index.js +8 -1
  41. package/dist/src/auth/lifecycle.d.ts +13 -0
  42. package/dist/src/auth/lifecycle.js +109 -0
  43. package/dist/src/auth/store.d.ts +1 -0
  44. package/dist/src/auth/store.js +12 -0
  45. package/dist/src/auth/types.d.ts +12 -0
  46. package/dist/src/automation-runner.js +2 -0
  47. package/dist/src/automation-service.js +7 -2
  48. package/dist/src/automation-tool.js +2 -1
  49. package/dist/src/benchmark-scores.d.ts +88 -0
  50. package/dist/src/benchmark-scores.js +302 -0
  51. package/dist/src/bridge/command.js +16 -1
  52. package/dist/src/bridge/control.d.ts +3 -1
  53. package/dist/src/bridge/control.js +9 -3
  54. package/dist/src/bridge/engines.d.ts +2 -0
  55. package/dist/src/bridge/engines.js +9 -0
  56. package/dist/src/bridge/github.d.ts +108 -0
  57. package/dist/src/bridge/github.js +378 -0
  58. package/dist/src/bridge/host-ops.d.ts +3 -3
  59. package/dist/src/bridge/host-ops.js +14 -2
  60. package/dist/src/bridge/host.d.ts +2 -0
  61. package/dist/src/bridge/host.js +70 -16
  62. package/dist/src/bridge/protocol.d.ts +1 -0
  63. package/dist/src/bridge/protocol.js +1 -0
  64. package/dist/src/browser-panel-tool.d.ts +12 -0
  65. package/dist/src/browser-panel-tool.js +30 -3
  66. package/dist/src/browser-runner.js +53 -62
  67. package/dist/src/browser-server.js +10 -4
  68. package/dist/src/browser-session.d.ts +14 -0
  69. package/dist/src/browser-session.js +57 -12
  70. package/dist/src/browser-view.d.ts +40 -1
  71. package/dist/src/browser-view.js +163 -9
  72. package/dist/src/browser-window-style.d.ts +27 -0
  73. package/dist/src/browser-window-style.js +244 -0
  74. package/dist/src/bug-report-attachments.d.ts +48 -0
  75. package/dist/src/bug-report-attachments.js +327 -0
  76. package/dist/src/bug-report.d.ts +23 -3
  77. package/dist/src/bug-report.js +72 -9
  78. package/dist/src/claude-provider.d.ts +1 -0
  79. package/dist/src/claude-provider.js +77 -36
  80. package/dist/src/cli.d.ts +1 -3
  81. package/dist/src/cli.js +245 -62
  82. package/dist/src/codex-provider.d.ts +1 -0
  83. package/dist/src/codex-provider.js +44 -8
  84. package/dist/src/coding-tools.d.ts +1 -0
  85. package/dist/src/coding-tools.js +28 -7
  86. package/dist/src/command-screens.d.ts +1 -1
  87. package/dist/src/command-screens.js +2 -2
  88. package/dist/src/commands.d.ts +9 -2
  89. package/dist/src/commands.js +69 -64
  90. package/dist/src/completion.js +13 -7
  91. package/dist/src/config.d.ts +14 -3
  92. package/dist/src/config.js +57 -17
  93. package/dist/src/context-budget.d.ts +11 -2
  94. package/dist/src/context-budget.js +38 -4
  95. package/dist/src/context-compaction.d.ts +10 -8
  96. package/dist/src/context-compaction.js +23 -24
  97. package/dist/src/deadline.js +1 -1
  98. package/dist/src/decision/DecisionEngine.d.ts +2 -0
  99. package/dist/src/decision/DecisionManager.d.ts +16 -0
  100. package/dist/src/decision/DecisionManager.js +75 -2
  101. package/dist/src/decision/applyTaskKind.d.ts +8 -0
  102. package/dist/src/decision/applyTaskKind.js +53 -0
  103. package/dist/src/decision/applyToolMenu.js +6 -2
  104. package/dist/src/decision/hostedPolicy.js +6 -3
  105. package/dist/src/decision/optimizationPolicy.d.ts +10 -0
  106. package/dist/src/decision/optimizationPolicy.js +23 -3
  107. package/dist/src/decision/providers/AndorraDecisionProvider.d.ts +4 -1
  108. package/dist/src/decision/providers/AndorraDecisionProvider.js +29 -7
  109. package/dist/src/decision/providers/index.js +1 -1
  110. package/dist/src/decision/taskKind.d.ts +52 -0
  111. package/dist/src/decision/taskKind.js +76 -0
  112. package/dist/src/decision/toolFamilies.js +1 -1
  113. package/dist/src/decision/types.d.ts +3 -1
  114. package/dist/src/default-graph.js +1 -1
  115. package/dist/src/efficiency.d.ts +80 -1
  116. package/dist/src/efficiency.js +119 -4
  117. package/dist/src/effort-routing.d.ts +27 -0
  118. package/dist/src/effort-routing.js +34 -0
  119. package/dist/src/evidence.d.ts +110 -0
  120. package/dist/src/evidence.js +195 -0
  121. package/dist/src/extensions.d.ts +2 -0
  122. package/dist/src/extensions.js +30 -20
  123. package/dist/src/github-app/agent-writes.d.ts +1 -1
  124. package/dist/src/github-app/agent-writes.js +1 -1
  125. package/dist/src/github-app/client.d.ts +19 -0
  126. package/dist/src/github-app/client.js +21 -1
  127. package/dist/src/github-app/event-source.d.ts +0 -5
  128. package/dist/src/github-app/event-source.js +1 -31
  129. package/dist/src/github-app/metrics.d.ts +2 -5
  130. package/dist/src/github-app/metrics.js +2 -14
  131. package/dist/src/github-app/review-loop.d.ts +5 -5
  132. package/dist/src/github-app/review-loop.js +1 -1
  133. package/dist/src/github-app/review-node.d.ts +2 -2
  134. package/dist/src/github-app/triggers.d.ts +3 -3
  135. package/dist/src/github-names.d.ts +7 -0
  136. package/dist/src/github-names.js +7 -0
  137. package/dist/src/glob-search.d.ts +1 -0
  138. package/dist/src/glob-search.js +3 -0
  139. package/dist/src/google-provider.d.ts +5 -28
  140. package/dist/src/google-provider.js +6 -141
  141. package/dist/src/graph-editor-session.d.ts +1 -0
  142. package/dist/src/graph-editor-session.js +2 -0
  143. package/dist/src/graph-health.js +3 -1
  144. package/dist/src/graph-preview.d.ts +2 -0
  145. package/dist/src/graph-preview.js +1 -0
  146. package/dist/src/graph-runner.js +20 -14
  147. package/dist/src/graph-selection.d.ts +3 -1
  148. package/dist/src/graph-selection.js +2 -2
  149. package/dist/src/graph-server.d.ts +8 -1
  150. package/dist/src/graph-server.js +49 -12
  151. package/dist/src/graph-sync.d.ts +2 -1
  152. package/dist/src/graph-sync.js +13 -0
  153. package/dist/src/graph-ui/app.js +49 -8
  154. package/dist/src/graph-ui/index.html +1 -1
  155. package/dist/src/graphs.d.ts +23 -1
  156. package/dist/src/graphs.js +58 -7
  157. package/dist/src/grok-provider.js +17 -14
  158. package/dist/src/hardened-runtime.js +39 -25
  159. package/dist/src/jev-savings.d.ts +4 -0
  160. package/dist/src/jev-savings.js +13 -0
  161. package/dist/src/legal/client.d.ts +25 -0
  162. package/dist/src/legal/client.js +47 -0
  163. package/dist/src/legal/command.d.ts +13 -0
  164. package/dist/src/legal/command.js +98 -0
  165. package/dist/src/legal/documents.d.ts +2 -0
  166. package/dist/src/legal/documents.js +14 -0
  167. package/dist/src/legal/gate.d.ts +13 -0
  168. package/dist/src/legal/gate.js +96 -0
  169. package/dist/src/legal/manifest.d.ts +21 -0
  170. package/dist/src/legal/manifest.js +23 -0
  171. package/dist/src/legal/receipt.d.ts +13 -0
  172. package/dist/src/legal/receipt.js +137 -0
  173. package/dist/src/legal/release.d.ts +27 -0
  174. package/dist/src/legal/release.js +28 -0
  175. package/dist/src/managed-sign-in.d.ts +0 -1
  176. package/dist/src/managed-sign-in.js +0 -13
  177. package/dist/src/membership.d.ts +27 -1
  178. package/dist/src/membership.js +139 -7
  179. package/dist/src/model-health-cache.js +1 -1
  180. package/dist/src/model-metadata.js +3 -7
  181. package/dist/src/model-override.d.ts +2 -1
  182. package/dist/src/model-override.js +9 -0
  183. package/dist/src/model-pool.d.ts +99 -0
  184. package/dist/src/model-pool.js +136 -0
  185. package/dist/src/model-relay/local.js +5 -0
  186. package/dist/src/model-relay/remote.d.ts +2 -0
  187. package/dist/src/model-relay/remote.js +4 -0
  188. package/dist/src/model-tiers.d.ts +16 -1
  189. package/dist/src/model-tiers.js +31 -7
  190. package/dist/src/opencode-cli-provider.js +59 -56
  191. package/dist/src/opencode-provider.js +16 -13
  192. package/dist/src/permissions.d.ts +5 -0
  193. package/dist/src/permissions.js +7 -0
  194. package/dist/src/plan-pass.js +2 -1
  195. package/dist/src/pool-scores.d.ts +45 -0
  196. package/dist/src/pool-scores.js +40 -0
  197. package/dist/src/provider-connection.js +3 -17
  198. package/dist/src/provider-engine.d.ts +13 -1
  199. package/dist/src/provider-engine.js +116 -12
  200. package/dist/src/provider-request-error.d.ts +8 -0
  201. package/dist/src/provider-request-error.js +12 -0
  202. package/dist/src/provider-settings.d.ts +1 -1
  203. package/dist/src/provider-settings.js +36 -18
  204. package/dist/src/provider-turn-deadline.d.ts +39 -0
  205. package/dist/src/provider-turn-deadline.js +139 -0
  206. package/dist/src/providers.d.ts +8 -9
  207. package/dist/src/providers.js +211 -150
  208. package/dist/src/pull-request-merge.d.ts +1 -8
  209. package/dist/src/pull-request-merge.js +0 -4
  210. package/dist/src/pull-requests.d.ts +83 -57
  211. package/dist/src/pull-requests.js +266 -225
  212. package/dist/src/qa/runtime/ProcessManager.d.ts +5 -1
  213. package/dist/src/qa/runtime/ProcessManager.js +9 -3
  214. package/dist/src/react-runtime.js +245 -71
  215. package/dist/src/reasoning-probe-cloud.d.ts +10 -0
  216. package/dist/src/reasoning-probe-cloud.js +209 -0
  217. package/dist/src/remote/engine-pool.d.ts +3 -0
  218. package/dist/src/remote/engine-pool.js +88 -21
  219. package/dist/src/remote/recovery.d.ts +6 -0
  220. package/dist/src/remote/recovery.js +37 -0
  221. package/dist/src/run-records.d.ts +13 -3
  222. package/dist/src/run-records.js +59 -34
  223. package/dist/src/runtime.d.ts +47 -2
  224. package/dist/src/runtime.js +33 -7
  225. package/dist/src/session-summary.d.ts +8 -0
  226. package/dist/src/session-summary.js +34 -0
  227. package/dist/src/sessions.d.ts +32 -0
  228. package/dist/src/sessions.js +65 -3
  229. package/dist/src/shell.js +6 -0
  230. package/dist/src/side-panel.js +36 -2
  231. package/dist/src/sign-in-detection.d.ts +1 -1
  232. package/dist/src/sign-in-detection.js +4 -10
  233. package/dist/src/sign-in-offer.js +1 -1
  234. package/dist/src/skill-commands.js +1 -1
  235. package/dist/src/skills/bundled/bug-report/SKILL.md +51 -7
  236. package/dist/src/skills/bundled/graph-manager/SKILL.md +2 -2
  237. package/dist/src/skills/bundled/graph-manager/patterns.md +13 -19
  238. package/dist/src/skills/bundled/provenance.json +3 -3
  239. package/dist/src/subagent-run.js +50 -50
  240. package/dist/src/subscription-usage.d.ts +50 -0
  241. package/dist/src/subscription-usage.js +92 -0
  242. package/dist/src/task-checkout.d.ts +157 -0
  243. package/dist/src/task-checkout.js +628 -0
  244. package/dist/src/telemetry/access.d.ts +18 -0
  245. package/dist/src/telemetry/access.js +43 -0
  246. package/dist/src/telemetry/aggregate.d.ts +18 -2
  247. package/dist/src/telemetry/aggregate.js +22 -9
  248. package/dist/src/telemetry/capture-core.d.ts +33 -14
  249. package/dist/src/telemetry/capture-core.js +124 -25
  250. package/dist/src/telemetry/capture.d.ts +3 -2
  251. package/dist/src/telemetry/capture.js +21 -1
  252. package/dist/src/telemetry/decision-capture.js +4 -0
  253. package/dist/src/telemetry/emitter.d.ts +6 -7
  254. package/dist/src/telemetry/emitter.js +124 -29
  255. package/dist/src/telemetry/gate.d.ts +41 -2
  256. package/dist/src/telemetry/gate.js +89 -4
  257. package/dist/src/telemetry/home.d.ts +1 -0
  258. package/dist/src/telemetry/home.js +20 -0
  259. package/dist/src/telemetry/identity.d.ts +6 -3
  260. package/dist/src/telemetry/identity.js +19 -6
  261. package/dist/src/telemetry/lifecycle.d.ts +8 -0
  262. package/dist/src/telemetry/lifecycle.js +76 -0
  263. package/dist/src/telemetry/outbox.d.ts +13 -8
  264. package/dist/src/telemetry/outbox.js +68 -12
  265. package/dist/src/telemetry/permission-command.d.ts +38 -0
  266. package/dist/src/telemetry/permission-command.js +208 -0
  267. package/dist/src/telemetry/permission.d.ts +168 -0
  268. package/dist/src/telemetry/permission.js +662 -0
  269. package/dist/src/telemetry/record-installation.d.ts +1 -0
  270. package/dist/src/telemetry/record-installation.js +9 -0
  271. package/dist/src/telemetry/region-data.d.ts +12 -0
  272. package/dist/src/telemetry/region-data.js +1314 -0
  273. package/dist/src/telemetry/region.d.ts +34 -0
  274. package/dist/src/telemetry/region.js +87 -0
  275. package/dist/src/telemetry/run-privacy.d.ts +11 -0
  276. package/dist/src/telemetry/run-privacy.js +165 -0
  277. package/dist/src/telemetry/schema.d.ts +27 -6
  278. package/dist/src/telemetry/schema.js +109 -14
  279. package/dist/src/telemetry/state.d.ts +11 -7
  280. package/dist/src/telemetry/state.js +39 -6
  281. package/dist/src/telemetry/surface.d.ts +20 -3
  282. package/dist/src/telemetry/surface.js +71 -15
  283. package/dist/src/telemetry/uploader.d.ts +6 -11
  284. package/dist/src/telemetry/uploader.js +72 -46
  285. package/dist/src/telemetry/uploads.d.ts +5 -1
  286. package/dist/src/telemetry/uploads.js +25 -6
  287. package/dist/src/telemetry/version.d.ts +5 -0
  288. package/dist/src/telemetry/version.js +34 -0
  289. package/dist/src/telemetry/workspace.d.ts +4 -1
  290. package/dist/src/telemetry/workspace.js +18 -3
  291. package/dist/src/terminal-ui.d.ts +3 -0
  292. package/dist/src/terminal-ui.js +48 -6
  293. package/dist/src/test-edit-guard.d.ts +30 -0
  294. package/dist/src/test-edit-guard.js +167 -2
  295. package/dist/src/thinking-level-detect.d.ts +13 -0
  296. package/dist/src/thinking-level-detect.js +52 -0
  297. package/dist/src/thinking-levels.d.ts +30 -0
  298. package/dist/src/thinking-levels.js +131 -0
  299. package/dist/src/timers.d.ts +3 -0
  300. package/dist/src/todos.d.ts +2 -1
  301. package/dist/src/todos.js +24 -4
  302. package/dist/src/tool-argument-coercion.d.ts +7 -0
  303. package/dist/src/tool-argument-coercion.js +49 -0
  304. package/dist/src/tool-catalog.d.ts +2 -2
  305. package/dist/src/tool-catalog.js +1 -1
  306. package/dist/src/tools.js +67 -22
  307. package/dist/src/transcript.js +3 -2
  308. package/dist/src/types.d.ts +48 -1
  309. package/dist/src/update.js +4 -0
  310. package/dist/src/usage-analytics.d.ts +7 -0
  311. package/dist/src/usage-analytics.js +85 -13
  312. package/dist/telemetry-consent-v1 +1 -0
  313. package/package.json +97 -96
@@ -0,0 +1,88 @@
1
+ import { type ModelScore, type PoolEffort } from './efficiency.js';
2
+ /**
3
+ * Model scores from published benchmarks, for routing. A model's score is the average of three providers'
4
+ * general-purpose scores: the Artificial Analysis Intelligence Index, the LiveBench overall score and the LMArena
5
+ * overall text rating. The three use different scales, so LiveBench and LMArena are first fitted onto the
6
+ * Intelligence Index scale (a straight line through the models both list), which is the scale the routing class
7
+ * scores are written on. Cost is the Intelligence Index cost per task, in US cents.
8
+ */
9
+ export type BenchmarkId = 'artificial-analysis' | 'livebench' | 'lmarena';
10
+ export declare const BENCHMARK_NAMES: Readonly<Record<BenchmarkId, string>>;
11
+ /** The benchmark whose scale the average is expressed on. Without it there are no scores. */
12
+ export declare const REFERENCE_BENCHMARK: BenchmarkId;
13
+ /** One listed model, at one thinking level when the benchmark names one. */
14
+ export interface BenchmarkEntry {
15
+ key: string;
16
+ effort?: PoolEffort;
17
+ score: number;
18
+ cost?: number;
19
+ }
20
+ export interface Benchmark {
21
+ id: BenchmarkId;
22
+ entries: BenchmarkEntry[];
23
+ }
24
+ /** What one benchmark contributed to a refresh. */
25
+ export interface BenchmarkReport {
26
+ id: BenchmarkId;
27
+ name: string;
28
+ listed: number;
29
+ used: boolean;
30
+ common?: number;
31
+ reason?: string;
32
+ }
33
+ export interface BenchmarkReading {
34
+ benchmarks: Benchmark[];
35
+ failed: BenchmarkReport[];
36
+ }
37
+ export interface BenchmarkSubject {
38
+ provider: string;
39
+ model: string;
40
+ name?: string;
41
+ efforts: readonly PoolEffort[];
42
+ }
43
+ /** A model name as every source can be compared: no provider prefix, no trailing date, letters and digits only. */
44
+ export declare function modelKey(name: string): string;
45
+ /**
46
+ * The model and thinking level in a leaderboard name such as "GPT-6.2 Astra (Xhigh)". A name whose brackets hold
47
+ * anything but a level, a date or a size is another variant of the model and is left out.
48
+ */
49
+ export declare function listedModel(name: string): {
50
+ key: string;
51
+ effort?: PoolEffort;
52
+ } | undefined;
53
+ /** The models in the Artificial Analysis leaderboard page, which carries its table as data inside the page. */
54
+ export declare function parseArtificialAnalysis(html: string): BenchmarkEntry[];
55
+ /** The models in a LiveBench release table. The overall score is the weighted mean of the categories, as the site computes it. */
56
+ export declare function parseLiveBench(table: string, categories: string, costs?: string): BenchmarkEntry[];
57
+ /** The models in LMArena's leaderboard rows, from the overall category only. */
58
+ export declare function parseLmArena(rows: readonly unknown[]): BenchmarkEntry[];
59
+ /**
60
+ * The straight line that turns a benchmark's scores into reference scores: over the entries both list, it gives the
61
+ * benchmark the reference's mean and spread. (A least-squares line would pull every score toward the middle wherever
62
+ * the two disagree.) Undefined when too few are shared or the two do not rise together.
63
+ */
64
+ export declare function fitToReference(source: readonly BenchmarkEntry[], reference: readonly BenchmarkEntry[]): {
65
+ slope: number;
66
+ intercept: number;
67
+ common: number;
68
+ } | undefined;
69
+ /**
70
+ * Scores for the subjects the benchmarks list, keyed `provider/model`. A model the reference does not price takes its
71
+ * cost from another benchmark, converted to the reference's unit. A model's score is the mean over the
72
+ * benchmarks that list it; a thinking level is scored on its own when at least one benchmark lists that level, and a
73
+ * benchmark that does not list the level contributes its score for the model.
74
+ */
75
+ export declare function benchmarkScores(subjects: readonly BenchmarkSubject[], benchmarks: readonly Benchmark[]): {
76
+ scores: Record<string, ModelScore>;
77
+ report: BenchmarkReport[];
78
+ };
79
+ export type BenchmarkFetcher = (url: string, init: {
80
+ signal: AbortSignal;
81
+ headers: Record<string, string>;
82
+ }) => Promise<{
83
+ ok: boolean;
84
+ status: number;
85
+ text(): Promise<string>;
86
+ }>;
87
+ /** Read the three benchmarks. One that cannot be read is reported in `failed` and never fails the others. */
88
+ export declare function readBenchmarks(signal: AbortSignal, fetcher?: BenchmarkFetcher): Promise<BenchmarkReading>;
@@ -0,0 +1,302 @@
1
+ import { POOL_EFFORTS, poolScoreKey } from './efficiency.js';
2
+ export const BENCHMARK_NAMES = {
3
+ 'artificial-analysis': 'Artificial Analysis Intelligence Index', livebench: 'LiveBench overall', lmarena: 'LMArena overall text rating',
4
+ };
5
+ /** The benchmark whose scale the average is expressed on. Without it there are no scores. */
6
+ export const REFERENCE_BENCHMARK = 'artificial-analysis';
7
+ /** A benchmark is fitted onto the reference scale only when at least this many of its entries are listed by both. */
8
+ const MIN_COMMON_ENTRIES = 5;
9
+ const mean = (values) => values.reduce((sum, value) => sum + value, 0) / values.length;
10
+ const tenth = (value) => Math.round(value * 10) / 10;
11
+ const finite = (value) => typeof value === 'number' && Number.isFinite(value);
12
+ /** A model name as every source can be compared: no provider prefix, no trailing date, letters and digits only. */
13
+ export function modelKey(name) {
14
+ return name.toLowerCase().replace(/^.*\//, '').replace(/[-_ ]?20\d{6}$/, '').replace(/[^a-z0-9]/g, '');
15
+ }
16
+ const LEVEL_WORDS = { 'non-reasoning': 'none', 'no reasoning': 'none', 'no thinking': 'none' };
17
+ const levelOf = (word) => Object.hasOwn(LEVEL_WORDS, word) ? LEVEL_WORDS[word] : POOL_EFFORTS.includes(word) ? word : undefined;
18
+ /**
19
+ * The model and thinking level in a leaderboard name such as "GPT-6.2 Astra (Xhigh)". A name whose brackets hold
20
+ * anything but a level, a date or a size is another variant of the model and is left out.
21
+ */
22
+ export function listedModel(name) {
23
+ const match = /^(.*?)\s*\(([^()]*)\)\s*$/.exec(name.trim());
24
+ let effort;
25
+ for (const raw of match ? match[2].split(',') : []) {
26
+ const word = raw.trim().toLowerCase();
27
+ const level = levelOf(word);
28
+ if (level)
29
+ effort = level;
30
+ else if (!/^(\d{6,8}|\d+k|default fallback|thinking|reasoning)$/.test(word))
31
+ return undefined;
32
+ }
33
+ const key = modelKey(match ? match[1] : name);
34
+ return key ? { key, ...(effort ? { effort } : {}) } : undefined;
35
+ }
36
+ /** The models in the Artificial Analysis leaderboard page, which carries its table as data inside the page. */
37
+ export function parseArtificialAnalysis(html) {
38
+ const text = html.replaceAll('\\"', '"');
39
+ const starts = [...text.matchAll(/"name":"([^"]{1,160})","shortName":"/g)];
40
+ const entries = [];
41
+ const seen = new Set();
42
+ starts.forEach((start, index) => {
43
+ // A record runs to the start of the next one, so a figure is never read from a neighbour.
44
+ const record = text.slice(start.index, starts[index + 1]?.index ?? start.index + 12_000);
45
+ const score = Number(/"intelligenceIndex":(-?[\d.]+)/.exec(record)?.[1]);
46
+ const model = listedModel(start[1]);
47
+ if (!model || !Number.isFinite(score))
48
+ return;
49
+ const id = `${model.key}\u0000${model.effort ?? ''}`;
50
+ if (seen.has(id))
51
+ return;
52
+ seen.add(id);
53
+ const cost = Number(/"intelligenceIndexCostPerTask":(-?[\d.]+)/.exec(record)?.[1]);
54
+ entries.push({ ...model, score, ...(Number.isFinite(cost) && cost >= 0 ? { cost: cost * 100 } : {}) });
55
+ });
56
+ return entries;
57
+ }
58
+ /** The models in a LiveBench release table. The overall score is the weighted mean of the categories, as the site computes it. */
59
+ export function parseLiveBench(table, categories, costs = '') {
60
+ const lines = table.split(/\r?\n/).filter(line => line.trim());
61
+ const header = (lines[0] ?? '').split(',').map(cell => cell.trim());
62
+ if (header[0] !== 'model')
63
+ return [];
64
+ let groups = [];
65
+ try {
66
+ const parsed = JSON.parse(categories);
67
+ const weights = parsed._overall_weights && typeof parsed._overall_weights === 'object' ? parsed._overall_weights : {};
68
+ groups = Object.entries(parsed).flatMap(([name, columns]) => {
69
+ const listed = Array.isArray(columns) ? columns.filter((column) => typeof column === 'string' && header.includes(column)) : [];
70
+ const weight = Object.hasOwn(weights, name) ? weights[name] : 1;
71
+ return listed.length ? [{ columns: listed, weight: finite(weight) && weight > 0 ? weight : 1 }] : [];
72
+ });
73
+ }
74
+ catch { /* an unreadable category file leaves every column weighted alike */ }
75
+ if (!groups.length)
76
+ groups = header.slice(1).map(column => ({ columns: [column], weight: 1 }));
77
+ // The release's cost file gives what each category cost to run; a model's cost is their sum, in the file's own unit.
78
+ const costLines = costs.split(/\r?\n/).filter(line => line.trim());
79
+ const costHeader = (costLines[0] ?? '').split(',').map(cell => cell.trim());
80
+ const costOf = new Map();
81
+ if (costHeader[0] === 'model') {
82
+ for (const line of costLines.slice(1)) {
83
+ const cells = line.split(',').map(cell => cell.trim());
84
+ const values = header.slice(1).map(column => costHeader.indexOf(column)).filter(at => at > 0)
85
+ .map(at => Number(cells[at] || NaN)).filter(value => Number.isFinite(value) && value >= 0);
86
+ if (cells[0] && values.length)
87
+ costOf.set(cells[0], values.reduce((sum, value) => sum + value, 0));
88
+ }
89
+ }
90
+ return lines.slice(1).flatMap((line) => {
91
+ const cells = line.split(',').map(cell => cell.trim());
92
+ const name = cells[0] ?? '';
93
+ const level = /^(.*)-(none|minimal|low|medium|high|xhigh|max)$/.exec(name);
94
+ const key = modelKey(level ? level[1] : name);
95
+ let total = 0;
96
+ let weight = 0;
97
+ for (const group of groups) {
98
+ const values = group.columns.map(column => Number(cells[header.indexOf(column)] || NaN)).filter(Number.isFinite);
99
+ if (!values.length)
100
+ continue;
101
+ total += mean(values) * group.weight;
102
+ weight += group.weight;
103
+ }
104
+ const cost = costOf.get(name);
105
+ return key && weight > 0 ? [{ key, ...(level ? { effort: level[2] } : {}), score: total / weight, ...(cost !== undefined && cost > 0 ? { cost } : {}) }] : [];
106
+ });
107
+ }
108
+ /** The models in LMArena's leaderboard rows, from the overall category only. */
109
+ export function parseLmArena(rows) {
110
+ const entries = [];
111
+ const seen = new Set();
112
+ for (const row of rows) {
113
+ if (!row || typeof row !== 'object')
114
+ continue;
115
+ const { model_name: name, rating, category } = row;
116
+ if (typeof name !== 'string' || !finite(rating) || category !== 'overall')
117
+ continue;
118
+ const model = listedModel(name);
119
+ const id = model ? `${model.key}\u0000${model.effort ?? ''}` : '';
120
+ if (!model || seen.has(id))
121
+ continue;
122
+ seen.add(id);
123
+ entries.push({ ...model, score: rating });
124
+ }
125
+ return entries;
126
+ }
127
+ function byModel(entries) {
128
+ const models = new Map();
129
+ for (const entry of entries)
130
+ models.set(entry.key, [...(models.get(entry.key) ?? []), entry]);
131
+ return models;
132
+ }
133
+ /** A model's figure at a level: the level as listed, else the entry with no level, else the mean of its levels. */
134
+ function figureAt(list, effort, figure) {
135
+ const having = list.filter(entry => entry[figure] !== undefined);
136
+ if (!having.length)
137
+ return undefined;
138
+ const chosen = having.find(entry => entry.effort === effort) ?? having.find(entry => entry.effort === undefined);
139
+ return chosen ? chosen[figure] : mean(having.map(entry => entry[figure]));
140
+ }
141
+ /**
142
+ * The straight line that turns a benchmark's scores into reference scores: over the entries both list, it gives the
143
+ * benchmark the reference's mean and spread. (A least-squares line would pull every score toward the middle wherever
144
+ * the two disagree.) Undefined when too few are shared or the two do not rise together.
145
+ */
146
+ export function fitToReference(source, reference) {
147
+ const models = byModel(reference);
148
+ const xs = [];
149
+ const ys = [];
150
+ for (const entry of source) {
151
+ const list = models.get(entry.key);
152
+ if (!list || (entry.effort !== undefined && !list.some(item => item.effort === entry.effort)))
153
+ continue;
154
+ xs.push(entry.score);
155
+ ys.push(figureAt(list, entry.effort, 'score'));
156
+ }
157
+ if (xs.length < MIN_COMMON_ENTRIES)
158
+ return undefined;
159
+ const mx = mean(xs);
160
+ const my = mean(ys);
161
+ let sxx = 0;
162
+ let syy = 0;
163
+ let sxy = 0;
164
+ xs.forEach((x, index) => { sxx += (x - mx) ** 2; syy += (ys[index] - my) ** 2; sxy += (x - mx) * (ys[index] - my); });
165
+ if (!(sxx > 0 && syy > 0 && sxy > 0))
166
+ return undefined;
167
+ const slope = Math.sqrt(syy / sxx);
168
+ return { slope, intercept: my - slope * mx, common: xs.length };
169
+ }
170
+ /**
171
+ * What one unit of a benchmark's cost is worth in reference cost: the median ratio over the entries both give a cost
172
+ * for. Undefined when too few do, and then that benchmark's costs are not used.
173
+ */
174
+ function costRate(source, reference) {
175
+ const models = byModel(reference);
176
+ const ratios = source.flatMap(entry => {
177
+ const list = models.get(entry.key);
178
+ const cost = list ? figureAt(list, entry.effort, 'cost') : undefined;
179
+ return entry.cost !== undefined && entry.cost > 0 && cost !== undefined && cost > 0 ? [cost / entry.cost] : [];
180
+ }).sort((a, b) => a - b);
181
+ return ratios.length >= MIN_COMMON_ENTRIES ? ratios[Math.floor(ratios.length / 2)] : undefined;
182
+ }
183
+ /**
184
+ * Scores for the subjects the benchmarks list, keyed `provider/model`. A model the reference does not price takes its
185
+ * cost from another benchmark, converted to the reference's unit. A model's score is the mean over the
186
+ * benchmarks that list it; a thinking level is scored on its own when at least one benchmark lists that level, and a
187
+ * benchmark that does not list the level contributes its score for the model.
188
+ */
189
+ export function benchmarkScores(subjects, benchmarks) {
190
+ const reference = benchmarks.find(item => item.id === REFERENCE_BENCHMARK);
191
+ if (!reference?.entries.length)
192
+ throw new Error(`${BENCHMARK_NAMES[REFERENCE_BENCHMARK]} could not be read, and the other scores are expressed on its scale.`);
193
+ const scaled = [];
194
+ const report = [];
195
+ for (const benchmark of benchmarks) {
196
+ const described = { id: benchmark.id, name: BENCHMARK_NAMES[benchmark.id], listed: benchmark.entries.length };
197
+ if (benchmark.id === REFERENCE_BENCHMARK) {
198
+ scaled.push({ id: benchmark.id, models: byModel(benchmark.entries) });
199
+ report.push({ ...described, used: true });
200
+ continue;
201
+ }
202
+ const fit = fitToReference(benchmark.entries, reference.entries);
203
+ if (!fit) {
204
+ report.push({ ...described, used: false, reason: 'too few models in common with the reference to compare scales' });
205
+ continue;
206
+ }
207
+ const rate = costRate(benchmark.entries, reference.entries);
208
+ scaled.push({ id: benchmark.id, models: byModel(benchmark.entries.map(({ cost, ...entry }) => ({ ...entry, score: Math.min(100, Math.max(0, fit.intercept + fit.slope * entry.score)),
209
+ ...(cost !== undefined && rate !== undefined ? { cost: cost * rate } : {}) }))) });
210
+ report.push({ ...described, used: true, common: fit.common });
211
+ }
212
+ const scores = {};
213
+ for (const subject of subjects) {
214
+ const keys = [...new Set([modelKey(subject.model), ...(subject.name ? [modelKey(subject.name)] : [])])].filter(Boolean);
215
+ const listed = scaled.flatMap(source => {
216
+ const list = keys.map(key => source.models.get(key)).find(found => found !== undefined);
217
+ return list ? [list] : [];
218
+ });
219
+ if (!listed.length)
220
+ continue;
221
+ const pair = (effort) => {
222
+ const cost = listed.map(list => figureAt(list, effort, 'cost')).find(finite);
223
+ return { quality: tenth(mean(listed.map(list => figureAt(list, effort, 'score')))), ...(cost === undefined ? {} : { cost: tenth(cost) }) };
224
+ };
225
+ const efforts = {};
226
+ for (const effort of subject.efforts)
227
+ if (listed.some(list => list.some(entry => entry.effort === effort)))
228
+ efforts[effort] = pair(effort);
229
+ scores[poolScoreKey(subject.provider, subject.model)] = { ...pair(undefined), ...(Object.keys(efforts).length ? { efforts } : {}) };
230
+ }
231
+ return { scores, report };
232
+ }
233
+ const ARTIFICIAL_ANALYSIS_URL = 'https://artificialanalysis.ai/leaderboards/models';
234
+ const LIVEBENCH_URL = 'https://livebench.ai/';
235
+ const LMARENA_ROWS_URL = 'https://datasets-server.huggingface.co/filter';
236
+ const SOURCE_TIMEOUT_MS = 60_000;
237
+ const LMARENA_PAGE = 100;
238
+ const LMARENA_MAX_PAGES = 20;
239
+ async function page(url, signal, fetcher) {
240
+ const response = await fetcher(url, { signal, headers: { 'user-agent': 'Mozilla/5.0 (compatible; AndorraCode)', accept: '*/*' } });
241
+ if (!response.ok)
242
+ throw new Error(`${new URL(url).host} answered ${response.status}`);
243
+ return response.text();
244
+ }
245
+ async function readLiveBench(signal, fetcher) {
246
+ // The site names its releases inside its script, newest last; each release has its own table.
247
+ const script = /static\/js\/main\.[\w.-]+\.js/.exec(await page(LIVEBENCH_URL, signal, fetcher))?.[0];
248
+ if (!script)
249
+ throw new Error('livebench.ai no longer names its script');
250
+ const bundle = await page(`${LIVEBENCH_URL}${script}`, signal, fetcher);
251
+ const releases = [...new Set([...bundle.matchAll(/"(20\d{6})"/g)].map(match => match[1]))].sort().reverse().slice(0, 4);
252
+ for (const release of releases) {
253
+ try {
254
+ const table = await page(`${LIVEBENCH_URL}data/${release}/table.csv`, signal, fetcher);
255
+ const categories = await page(`${LIVEBENCH_URL}data/${release}/categories.json`, signal, fetcher).catch(() => { signal.throwIfAborted(); return '{}'; });
256
+ const costs = await page(`${LIVEBENCH_URL}data/${release}/cost.csv`, signal, fetcher).catch(() => { signal.throwIfAborted(); return ''; });
257
+ const entries = parseLiveBench(table, categories, costs);
258
+ if (entries.length)
259
+ return entries;
260
+ }
261
+ catch {
262
+ signal.throwIfAborted();
263
+ }
264
+ }
265
+ throw new Error('livebench.ai lists no release table');
266
+ }
267
+ async function readLmArena(signal, fetcher) {
268
+ const rows = [];
269
+ for (let index = 0; index < LMARENA_MAX_PAGES; index++) {
270
+ const query = new URLSearchParams({ dataset: 'lmarena-ai/leaderboard-dataset', config: 'text', split: 'latest', where: `"category"='overall'`, offset: String(index * LMARENA_PAGE), length: String(LMARENA_PAGE) });
271
+ const answer = JSON.parse(await page(`${LMARENA_ROWS_URL}?${query}`, signal, fetcher));
272
+ const received = answer.rows ?? [];
273
+ rows.push(...received.map(item => item.row));
274
+ if (received.length < LMARENA_PAGE || rows.length >= (answer.num_rows_total ?? Infinity))
275
+ break;
276
+ }
277
+ return parseLmArena(rows);
278
+ }
279
+ /** Read the three benchmarks. One that cannot be read is reported in `failed` and never fails the others. */
280
+ export async function readBenchmarks(signal, fetcher = (url, init) => fetch(url, init)) {
281
+ const sources = {
282
+ 'artificial-analysis': async (bounded) => parseArtificialAnalysis(await page(ARTIFICIAL_ANALYSIS_URL, bounded, fetcher)),
283
+ livebench: bounded => readLiveBench(bounded, fetcher),
284
+ lmarena: bounded => readLmArena(bounded, fetcher),
285
+ };
286
+ const reading = { benchmarks: [], failed: [] };
287
+ await Promise.all(Object.keys(sources).map(async (id) => {
288
+ try {
289
+ const entries = await sources[id](AbortSignal.any([signal, AbortSignal.timeout(SOURCE_TIMEOUT_MS)]));
290
+ if (!entries.length)
291
+ throw new Error('no model scores were found in its answer');
292
+ reading.benchmarks.push({ id, entries });
293
+ }
294
+ catch (error) {
295
+ signal.throwIfAborted();
296
+ reading.failed.push({ id, name: BENCHMARK_NAMES[id], listed: 0, used: false, reason: error instanceof Error ? error.message : String(error) });
297
+ }
298
+ }));
299
+ const order = Object.keys(sources);
300
+ reading.benchmarks.sort((a, b) => order.indexOf(a.id) - order.indexOf(b.id));
301
+ return reading;
302
+ }
@@ -5,6 +5,7 @@ import { changeConfigFile, configDirectory, loadConfig } from '../config.js';
5
5
  import { ensureWorkFolder, MAX_BOOT_INPUT_BYTES, runCloudBoot } from './cloud.js';
6
6
  import { ControlError, environmentToken, heartbeat, linkPoll, linkStart } from './control.js';
7
7
  import { engineStoreFromEnvironment, HOST_RESTART_EXIT_CODE } from './engines.js';
8
+ import { installCredentialHelperFromEnvironment, runGitCredential } from './github.js';
8
9
  import { relayUrlFromEnvironment, runBridgeHost } from './host.js';
9
10
  import { linkAddress, openCommand, openOnThisComputer, overSshFromEnvironment } from './login-link.js';
10
11
  import { clearBridgeIdentity, readBridgeIdentity, shareFolder, writeBridgeIdentity } from './store.js';
@@ -232,6 +233,8 @@ async function run(print, apiBase, dependencies) {
232
233
  try {
233
234
  if (process.env.ANDORRA_CLOUD === '1') {
234
235
  await ensureWorkFolder(directory, dependencies.workDirectory).catch(error => print(`Could not share the work folder: ${message(error)}`));
236
+ // Clones made by an earlier engine name this file; it is pointed at the engine now running.
237
+ await installCredentialHelperFromEnvironment(directory).catch(error => print(`Could not write the Git credential helper: ${message(error)}`));
235
238
  }
236
239
  const outcome = await (dependencies.runHost ?? runBridgeHost)({
237
240
  directory,
@@ -244,7 +247,10 @@ async function run(print, apiBase, dependencies) {
244
247
  },
245
248
  signal: controller.signal,
246
249
  log: print,
247
- ...(process.env.ANDORRA_CLOUD === '1' ? { heartbeat: activity => heartbeat(apiBase, identity.environmentId, identity.secret, activity) } : {}),
250
+ ...(process.env.ANDORRA_CLOUD === '1' ? {
251
+ heartbeat: activity => heartbeat(apiBase, identity.environmentId, identity.secret, activity),
252
+ cloudUpdates: engines !== undefined,
253
+ } : {}),
248
254
  ...(engines ? { engines } : {}),
249
255
  ...(launcherAlive ? { launcherAlive } : {}),
250
256
  });
@@ -314,6 +320,15 @@ export async function runBridgeCommand(args, print, dependencies = {}) {
314
320
  switch (command) {
315
321
  case 'cloud-boot':
316
322
  return runCloudBoot({ apiBase, directory: configDirectory(), stdin: await readBoundedStdin(), print });
323
+ case 'git-credential':
324
+ // Git runs this on a Cloud machine (see ./github.ts). Standard output goes to Git and carries the credential alone.
325
+ return runGitCredential({
326
+ action: rest[0], stdin: rest[0] === 'get' ? await readBoundedStdin() : '', apiBase, directory: configDirectory(), print,
327
+ warn: line => {
328
+ process.stderr.write(`${line}
329
+ `);
330
+ },
331
+ });
317
332
  case 'link':
318
333
  return link(rest, print, apiBase, dependencies);
319
334
  case 'run':
@@ -1,4 +1,4 @@
1
- export type ControlErrorCode = 'code_expired' | 'code_unknown' | 'code_used' | 'boot_expired' | 'boot_used' | 'boot_unknown' | 'environment_limit' | 'invalid_name' | 'not_found' | 'unauthorized' | 'cloud_not_enabled' | 'cloud_environment' | 'invalid_version' | 'cloud_unavailable' | 'stopping' | 'no_capacity' | 'unlinked' | 'network' | 'server';
1
+ export type ControlErrorCode = 'code_expired' | 'code_unknown' | 'code_used' | 'boot_expired' | 'boot_used' | 'boot_unknown' | 'environment_limit' | 'invalid_name' | 'not_found' | 'unauthorized' | 'cloud_not_enabled' | 'cloud_plan' | 'cloud_environment' | 'invalid_version' | 'cloud_unavailable' | 'stopping' | 'no_capacity' | 'unlinked' | 'network' | 'server';
2
2
  export declare class ControlError extends Error {
3
3
  readonly code: ControlErrorCode;
4
4
  constructor(code: ControlErrorCode, message: string);
@@ -34,6 +34,8 @@ export type CloudState = 'none' | 'starting' | 'running' | 'stopping' | 'stopped
34
34
  export interface CloudStatus {
35
35
  state: CloudState;
36
36
  enabled: boolean;
37
+ /** Why Cloud is not enabled, when the service says: `plan` is an account on the Free plan. */
38
+ reason?: 'plan';
37
39
  environmentId?: string;
38
40
  label?: string;
39
41
  version?: string;
@@ -170,16 +170,19 @@ const CLOUD_REFUSALS = {
170
170
  invalid_version: { status: 400, code: 'invalid_version', message: 'This version of Andorra Code cannot start Cloud. Update Andorra Code and try again.' },
171
171
  };
172
172
  const CLOUD_STATES = ['none', 'starting', 'running', 'stopping', 'stopped'];
173
- const CLOUD_LABEL = /^Andorra-Code-Cloud-[1-9][0-9]{9}$/;
173
+ // The last group of the user's id, or the numbered name of a Cloud made before names came from it.
174
+ const CLOUD_LABEL = /^(?:[0-9a-f]{12}|Andorra-Code-Cloud-[1-9][0-9]{9})$/;
174
175
  const CLOUD_ENVIRONMENT_ID = /^env_[A-Za-z0-9_-]{22}$/;
175
176
  const CLOUD_VERSION = /^\d{1,4}\.\d{1,4}\.\d{1,4}$/;
176
177
  const ISO_TIME = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,9})?(Z|[+-]\d{2}:\d{2})$/;
177
178
  /** Keeps only the fields of a Cloud answer that have the expected shape; an unknown state is an error. */
178
179
  function cloudStatus(value) {
179
- const { state, enabled, environmentId, label, version, step, deleteAt, error, stopReason } = value;
180
+ const { state, enabled, reason, environmentId, label, version, step, deleteAt, error, stopReason } = value;
180
181
  if (typeof state !== 'string' || !CLOUD_STATES.includes(state))
181
182
  throw new ControlError('server', 'The Andorra service answered with an unknown Cloud state.');
182
183
  const status = { state: state, enabled: enabled === true };
184
+ if (enabled !== true && reason === 'plan')
185
+ status.reason = 'plan';
183
186
  if (typeof environmentId === 'string' && CLOUD_ENVIRONMENT_ID.test(environmentId))
184
187
  status.environmentId = environmentId;
185
188
  if (typeof label === 'string' && CLOUD_LABEL.test(label))
@@ -198,8 +201,11 @@ function cloudStatus(value) {
198
201
  }
199
202
  function cloudError(status, value) {
200
203
  const refusal = typeof value.error === 'string' ? CLOUD_REFUSALS[value.error] : undefined;
201
- if (refusal !== undefined && refusal.status === status)
204
+ if (refusal !== undefined && refusal.status === status) {
205
+ if (refusal.code === 'cloud_not_enabled' && value.reason === 'plan')
206
+ return new ControlError('cloud_plan', 'Cloud is not included in the Free plan.');
202
207
  return new ControlError(refusal.code, refusal.message);
208
+ }
203
209
  if (status === 401)
204
210
  return accountError(status, value);
205
211
  return new ControlError('cloud_unavailable', 'Cloud is not available right now. Try again in a moment.');
@@ -48,6 +48,8 @@ export interface EngineStore extends RelayEngines {
48
48
  } | undefined;
49
49
  /** Whether that version is installed and ready to start. */
50
50
  installed(version: string): Promise<boolean>;
51
+ /** The stable release of the CLI on the public npm registry, if it answers. */
52
+ latestRelease(): Promise<string | undefined>;
51
53
  /** Installs under way or waiting for a slot in this process. */
52
54
  installing(): number;
53
55
  /** Names the version the launcher should start as the next host, and records when it was asked for in last-host-request. */
@@ -12,6 +12,7 @@ export const PACKAGE_NAME = '@andorra-labs/code';
12
12
  export const MIN_ENGINE_VERSION = '0.1.16';
13
13
  export const MAX_ENGINE_VERSIONS = 3;
14
14
  export const ENGINE_INSTALL_TIMEOUT_MS = 300_000;
15
+ const RELEASE_CHECK_TIMEOUT_MS = 5_000;
15
16
  /** The exit code with which a host asks the launcher to start it again as the version in next-host-version. */
16
17
  export const HOST_RESTART_EXIT_CODE = 75;
17
18
  export const MAX_CONCURRENT_INSTALLS = 2;
@@ -507,6 +508,14 @@ export function createEngineStore(options) {
507
508
  const installQueueFull = () => new EngineStoreError('busy', 'This machine is busy installing other versions of Andorra Code. Try again in a moment.');
508
509
  return {
509
510
  hostVersion,
511
+ async latestRelease() {
512
+ const { program, prefix } = await npmProgram();
513
+ const result = await run(program, [
514
+ ...prefix, 'view', `${PACKAGE_NAME}@latest`, 'version', '--prefer-online', '--registry=https://registry.npmjs.org',
515
+ ], root, RELEASE_CHECK_TIMEOUT_MS);
516
+ const version = result.stdout.trim();
517
+ return result.code === 0 && !result.timedOut && acceptable(version) ? version : undefined;
518
+ },
510
519
  async commandFor(version) {
511
520
  if (version === undefined || version === hostVersion)
512
521
  return hostCommand();
@@ -0,0 +1,108 @@
1
+ /** A clone still running after this long is stopped and reported as failed. */
2
+ export declare const CLONE_TIMEOUT_MS: number;
3
+ /** How long a clone request waits for the clone before answering `cloning`; a host operation has 30 seconds in all. */
4
+ export declare const CLONE_ANSWER_MS = 2000;
5
+ export type RepositoryTokenErrorCode = 'off' | 'not-connected' | 'not-covered' | 'not-cloud' | 'suspended' | 'permissions-pending' | 'not-allowed' | 'account-unavailable' | 'unlinked' | 'rate-limited' | 'network' | 'server';
6
+ export declare class RepositoryTokenError extends Error {
7
+ readonly code: RepositoryTokenErrorCode;
8
+ constructor(code: RepositoryTokenErrorCode, message: string);
9
+ }
10
+ export interface RepositoryToken {
11
+ token: string;
12
+ expiresAt: string;
13
+ login: string;
14
+ githubUserId: number;
15
+ push: boolean;
16
+ }
17
+ /** Asks the service for a token for one repository, as the machine `environmentToken` names. */
18
+ export declare function repositoryToken(apiBase: string, environmentTokenValue: string, owner: string, repo: string, fetcher?: typeof globalThis.fetch): Promise<RepositoryToken>;
19
+ /** The machine's own token for `owner/repo`: its secret is traded for an environment token, and that for the repository's. */
20
+ export declare function machineRepositoryToken(directory: string, apiBase: string, owner: string, repo: string): Promise<RepositoryToken>;
21
+ /** `owner/repo` from the path Git names in a credential request (`owner/repo.git`, with or without what follows it). */
22
+ export declare function repositoryOfPath(path: string | undefined): {
23
+ owner: string;
24
+ repo: string;
25
+ } | undefined;
26
+ /** A credential request as Git writes it: `key=value` lines up to a blank line. */
27
+ export declare function parseCredentialRequest(stdin: string): Record<string, string>;
28
+ export interface GitCredentialInput {
29
+ /** What Git asks: `get`, `store` or `erase`. */
30
+ action: string | undefined;
31
+ stdin: string;
32
+ apiBase: string;
33
+ directory: string;
34
+ /** Writes to Git: the credential, and nothing else. */
35
+ print(line: string): void;
36
+ /** Writes what a person reads in Git's own output. */
37
+ warn(line: string): void;
38
+ token?: typeof machineRepositoryToken;
39
+ }
40
+ /**
41
+ * Git's credential helper (`andorra bridge git-credential <action>`). It answers only a `get` for
42
+ * `https://github.com/<owner>/<repo>`; anything else gets no credential, and Git goes on to whatever else it has.
43
+ * `store` and `erase` do nothing: there is nothing kept to change.
44
+ */
45
+ export declare function runGitCredential(input: GitCredentialInput): Promise<number>;
46
+ export type CloneAnswer = {
47
+ state: 'cloning';
48
+ } | {
49
+ state: 'ready';
50
+ rootId: string;
51
+ name: string;
52
+ } | {
53
+ state: 'failed';
54
+ message: string;
55
+ };
56
+ export interface CloneDependencies {
57
+ directory: string;
58
+ apiBase: string;
59
+ /** Whether this machine is a Cloud instance: a linked workstation keeps its own Git credentials and clones nothing here. */
60
+ cloud: boolean;
61
+ /** The credential helper as Git's configuration names it (`!command`). */
62
+ helper: string;
63
+ git?: string;
64
+ token?: typeof machineRepositoryToken;
65
+ /** Where the repository is fetched from; tests point it at a local repository. */
66
+ remoteUrl?: (owner: string, repo: string) => string;
67
+ answerMs?: number;
68
+ }
69
+ /**
70
+ * The helper this process's own CLI provides, named by the paths it is running from. `settings` are set for the
71
+ * helper itself, so it reaches the same service and home as this machine's bridge even when the Git that runs it was
72
+ * started with a narrower environment (a task's command, say).
73
+ */
74
+ export declare function credentialHelperCommand(execPath?: string, script?: string | undefined, settings?: Record<string, string>): string;
75
+ /** The helper's file in the machine's Andorra home: the one path every clone's configuration names. */
76
+ export declare const CREDENTIAL_HELPER_FILE = "git-credential-andorra";
77
+ /**
78
+ * Writes the helper every clone names and answers it as Git's configuration takes it. A clone's configuration
79
+ * outlives the engine that made it, and an engine's own path changes with its version (old versions are pruned), so
80
+ * clones name this one file instead, and it is rewritten to run the current engine whenever the bridge starts and
81
+ * before every clone. It holds paths and the service's address: no secret.
82
+ */
83
+ export declare function installCredentialHelper(directory: string, options?: {
84
+ execPath?: string;
85
+ script?: string;
86
+ settings?: Record<string, string>;
87
+ }): Promise<string>;
88
+ /** The helper for this machine as its environment describes it, written afresh. */
89
+ export declare function installCredentialHelperFromEnvironment(directory: string, environment?: NodeJS.ProcessEnv): Promise<string>;
90
+ export declare function cloneDependenciesFromEnvironment(directory: string, environment?: NodeJS.ProcessEnv): Promise<CloneDependencies>;
91
+ /**
92
+ * The entry of `parent` that is `name` in any capitalisation, or `name` when there is none. GitHub's names ignore
93
+ * case and Cloud's disk does not, so a repository picked again under another spelling must find the folder it has.
94
+ */
95
+ export declare function spelledAs(parent: string, name: string): Promise<string>;
96
+ /**
97
+ * How many clones are running now. The bridge counts them as work, so it does not restart itself for a newer engine
98
+ * under a clone whose request was already answered `cloning`.
99
+ */
100
+ export declare function clonesRunning(): number;
101
+ /** Forgets every clone this process knows of (tests). */
102
+ export declare function resetCloneJobs(): void;
103
+ /**
104
+ * Clones `owner/repo` into the machine's first shared folder and registers it as a project. It never waits long:
105
+ * while the clone runs every call answers `cloning`, so a desktop asks again until it is `ready` or `failed`. A
106
+ * repository already cloned there is reused. A failure is reported once; asking after that starts again.
107
+ */
108
+ export declare function cloneRepository(dependencies: CloneDependencies, params: Record<string, unknown>): Promise<CloneAnswer>;