@andorra-labs/code 0.1.18 → 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 (277) 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 +347 -45
  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/hosted.d.ts +8 -0
  11. package/dist/src/andorra/hosted.js +22 -3
  12. package/dist/src/andorra/streams.d.ts +49 -0
  13. package/dist/src/andorra/streams.js +98 -0
  14. package/dist/src/antigravity-acp.d.ts +28 -0
  15. package/dist/src/antigravity-acp.js +150 -0
  16. package/dist/src/antigravity-terminal.d.ts +2 -0
  17. package/dist/src/antigravity-terminal.js +214 -0
  18. package/dist/src/app-server/adaptive-routing-settings.d.ts +37 -0
  19. package/dist/src/app-server/adaptive-routing-settings.js +69 -0
  20. package/dist/src/app-server/artifact.d.ts +14 -0
  21. package/dist/src/app-server/artifact.js +46 -0
  22. package/dist/src/app-server/legal-protocol.d.ts +33 -0
  23. package/dist/src/app-server/legal-protocol.js +16 -0
  24. package/dist/src/app-server/protocol.d.ts +23 -3
  25. package/dist/src/app-server/protocol.js +3 -1
  26. package/dist/src/app-server/telemetry-protocol.d.ts +53 -0
  27. package/dist/src/app-server/telemetry-protocol.js +2 -0
  28. package/dist/src/app-server/telemetry.d.ts +38 -0
  29. package/dist/src/app-server/telemetry.js +163 -0
  30. package/dist/src/app-server/workspace.d.ts +3 -1
  31. package/dist/src/app-server/workspace.js +39 -8
  32. package/dist/src/app-server.d.ts +50 -25
  33. package/dist/src/app-server.js +1008 -400
  34. package/dist/src/auth/AuthManager.d.ts +11 -2
  35. package/dist/src/auth/AuthManager.js +56 -13
  36. package/dist/src/auth/index.d.ts +5 -1
  37. package/dist/src/auth/index.js +8 -1
  38. package/dist/src/auth/lifecycle.d.ts +13 -0
  39. package/dist/src/auth/lifecycle.js +109 -0
  40. package/dist/src/auth/store.d.ts +1 -0
  41. package/dist/src/auth/store.js +12 -0
  42. package/dist/src/auth/types.d.ts +12 -0
  43. package/dist/src/automation-runner.js +2 -0
  44. package/dist/src/automation-service.js +7 -2
  45. package/dist/src/benchmark-scores.d.ts +88 -0
  46. package/dist/src/benchmark-scores.js +302 -0
  47. package/dist/src/bridge/command.js +4 -1
  48. package/dist/src/bridge/control.js +2 -1
  49. package/dist/src/bridge/engines.d.ts +2 -0
  50. package/dist/src/bridge/engines.js +9 -0
  51. package/dist/src/bridge/host-ops.d.ts +2 -2
  52. package/dist/src/bridge/host-ops.js +4 -2
  53. package/dist/src/bridge/host.d.ts +2 -0
  54. package/dist/src/bridge/host.js +63 -12
  55. package/dist/src/bridge/protocol.d.ts +1 -0
  56. package/dist/src/bridge/protocol.js +1 -0
  57. package/dist/src/browser-panel-tool.d.ts +12 -0
  58. package/dist/src/browser-panel-tool.js +30 -3
  59. package/dist/src/browser-runner.js +53 -62
  60. package/dist/src/browser-server.js +10 -4
  61. package/dist/src/browser-session.d.ts +14 -0
  62. package/dist/src/browser-session.js +57 -12
  63. package/dist/src/browser-view.d.ts +40 -1
  64. package/dist/src/browser-view.js +163 -9
  65. package/dist/src/browser-window-style.d.ts +27 -0
  66. package/dist/src/browser-window-style.js +244 -0
  67. package/dist/src/claude-provider.d.ts +1 -0
  68. package/dist/src/claude-provider.js +77 -36
  69. package/dist/src/cli.js +235 -58
  70. package/dist/src/codex-provider.d.ts +1 -0
  71. package/dist/src/codex-provider.js +43 -7
  72. package/dist/src/coding-tools.d.ts +1 -0
  73. package/dist/src/coding-tools.js +19 -5
  74. package/dist/src/command-screens.d.ts +1 -1
  75. package/dist/src/command-screens.js +2 -2
  76. package/dist/src/commands.d.ts +8 -1
  77. package/dist/src/commands.js +67 -63
  78. package/dist/src/completion.js +5 -3
  79. package/dist/src/config.d.ts +14 -3
  80. package/dist/src/config.js +54 -16
  81. package/dist/src/context-budget.d.ts +11 -2
  82. package/dist/src/context-budget.js +23 -2
  83. package/dist/src/context-compaction.d.ts +10 -8
  84. package/dist/src/context-compaction.js +23 -24
  85. package/dist/src/deadline.js +1 -1
  86. package/dist/src/decision/DecisionManager.d.ts +5 -0
  87. package/dist/src/decision/DecisionManager.js +39 -2
  88. package/dist/src/decision/applyToolMenu.js +6 -2
  89. package/dist/src/decision/hostedPolicy.js +6 -4
  90. package/dist/src/decision/optimizationPolicy.d.ts +10 -0
  91. package/dist/src/decision/optimizationPolicy.js +23 -3
  92. package/dist/src/decision/providers/AndorraDecisionProvider.d.ts +2 -1
  93. package/dist/src/decision/providers/AndorraDecisionProvider.js +17 -7
  94. package/dist/src/decision/providers/index.js +1 -1
  95. package/dist/src/decision/toolFamilies.js +1 -1
  96. package/dist/src/decision/types.d.ts +2 -0
  97. package/dist/src/efficiency.d.ts +75 -1
  98. package/dist/src/efficiency.js +114 -3
  99. package/dist/src/extensions.d.ts +2 -0
  100. package/dist/src/extensions.js +30 -20
  101. package/dist/src/github-app/agent-writes.d.ts +1 -1
  102. package/dist/src/github-app/agent-writes.js +1 -1
  103. package/dist/src/github-app/event-source.d.ts +0 -5
  104. package/dist/src/github-app/event-source.js +1 -31
  105. package/dist/src/github-app/metrics.d.ts +2 -5
  106. package/dist/src/github-app/metrics.js +2 -14
  107. package/dist/src/github-app/review-loop.d.ts +5 -5
  108. package/dist/src/github-app/review-loop.js +1 -1
  109. package/dist/src/github-app/review-node.d.ts +2 -2
  110. package/dist/src/github-app/triggers.d.ts +3 -3
  111. package/dist/src/glob-search.d.ts +1 -0
  112. package/dist/src/glob-search.js +3 -0
  113. package/dist/src/google-provider.d.ts +5 -28
  114. package/dist/src/google-provider.js +6 -141
  115. package/dist/src/graph-editor-session.d.ts +1 -0
  116. package/dist/src/graph-editor-session.js +2 -0
  117. package/dist/src/graph-health.js +3 -1
  118. package/dist/src/graph-runner.js +19 -13
  119. package/dist/src/graph-selection.d.ts +3 -1
  120. package/dist/src/graph-selection.js +2 -2
  121. package/dist/src/graph-server.d.ts +8 -1
  122. package/dist/src/graph-server.js +45 -10
  123. package/dist/src/graph-sync.d.ts +2 -1
  124. package/dist/src/graph-sync.js +13 -0
  125. package/dist/src/graph-ui/app.js +19 -8
  126. package/dist/src/graph-ui/index.html +1 -1
  127. package/dist/src/graphs.d.ts +17 -1
  128. package/dist/src/graphs.js +51 -5
  129. package/dist/src/grok-provider.js +17 -14
  130. package/dist/src/hardened-runtime.js +7 -4
  131. package/dist/src/jev-savings.d.ts +4 -0
  132. package/dist/src/jev-savings.js +13 -0
  133. package/dist/src/legal/client.d.ts +25 -0
  134. package/dist/src/legal/client.js +47 -0
  135. package/dist/src/legal/command.d.ts +13 -0
  136. package/dist/src/legal/command.js +98 -0
  137. package/dist/src/legal/documents.d.ts +2 -0
  138. package/dist/src/legal/documents.js +14 -0
  139. package/dist/src/legal/gate.d.ts +13 -0
  140. package/dist/src/legal/gate.js +96 -0
  141. package/dist/src/legal/manifest.d.ts +21 -0
  142. package/dist/src/legal/manifest.js +23 -0
  143. package/dist/src/legal/receipt.d.ts +13 -0
  144. package/dist/src/legal/receipt.js +137 -0
  145. package/dist/src/legal/release.d.ts +27 -0
  146. package/dist/src/legal/release.js +28 -0
  147. package/dist/src/managed-sign-in.d.ts +0 -1
  148. package/dist/src/managed-sign-in.js +0 -13
  149. package/dist/src/membership.d.ts +27 -1
  150. package/dist/src/membership.js +139 -7
  151. package/dist/src/model-metadata.js +3 -7
  152. package/dist/src/model-pool.d.ts +99 -0
  153. package/dist/src/model-pool.js +136 -0
  154. package/dist/src/model-relay/local.js +5 -0
  155. package/dist/src/model-relay/remote.d.ts +2 -0
  156. package/dist/src/model-relay/remote.js +4 -0
  157. package/dist/src/model-tiers.d.ts +13 -1
  158. package/dist/src/model-tiers.js +28 -4
  159. package/dist/src/opencode-cli-provider.js +59 -56
  160. package/dist/src/opencode-provider.js +16 -13
  161. package/dist/src/permissions.d.ts +5 -0
  162. package/dist/src/permissions.js +7 -0
  163. package/dist/src/plan-pass.js +2 -1
  164. package/dist/src/pool-scores.d.ts +45 -0
  165. package/dist/src/pool-scores.js +40 -0
  166. package/dist/src/provider-connection.js +3 -17
  167. package/dist/src/provider-engine.js +42 -12
  168. package/dist/src/provider-request-error.d.ts +8 -0
  169. package/dist/src/provider-request-error.js +12 -0
  170. package/dist/src/provider-settings.d.ts +1 -1
  171. package/dist/src/provider-settings.js +36 -18
  172. package/dist/src/provider-turn-deadline.d.ts +39 -0
  173. package/dist/src/provider-turn-deadline.js +139 -0
  174. package/dist/src/providers.d.ts +3 -9
  175. package/dist/src/providers.js +181 -146
  176. package/dist/src/pull-request-merge.d.ts +1 -8
  177. package/dist/src/pull-request-merge.js +0 -4
  178. package/dist/src/pull-requests.d.ts +82 -66
  179. package/dist/src/pull-requests.js +266 -276
  180. package/dist/src/qa/runtime/ProcessManager.d.ts +5 -1
  181. package/dist/src/qa/runtime/ProcessManager.js +9 -3
  182. package/dist/src/react-runtime.js +147 -56
  183. package/dist/src/reasoning-probe-cloud.d.ts +10 -0
  184. package/dist/src/reasoning-probe-cloud.js +209 -0
  185. package/dist/src/remote/engine-pool.d.ts +3 -0
  186. package/dist/src/remote/engine-pool.js +85 -18
  187. package/dist/src/remote/recovery.d.ts +6 -0
  188. package/dist/src/remote/recovery.js +37 -0
  189. package/dist/src/run-records.d.ts +13 -3
  190. package/dist/src/run-records.js +59 -34
  191. package/dist/src/runtime.d.ts +18 -1
  192. package/dist/src/runtime.js +25 -7
  193. package/dist/src/session-summary.d.ts +8 -0
  194. package/dist/src/session-summary.js +34 -0
  195. package/dist/src/sessions.d.ts +8 -0
  196. package/dist/src/sessions.js +12 -3
  197. package/dist/src/shell.js +6 -0
  198. package/dist/src/side-panel.js +36 -2
  199. package/dist/src/sign-in-detection.d.ts +1 -1
  200. package/dist/src/sign-in-detection.js +4 -10
  201. package/dist/src/sign-in-offer.js +1 -1
  202. package/dist/src/skill-commands.js +1 -1
  203. package/dist/src/skills/bundled/graph-manager/SKILL.md +2 -2
  204. package/dist/src/skills/bundled/graph-manager/patterns.md +13 -19
  205. package/dist/src/skills/bundled/provenance.json +2 -2
  206. package/dist/src/subagent-run.js +50 -50
  207. package/dist/src/subscription-usage.d.ts +50 -0
  208. package/dist/src/subscription-usage.js +92 -0
  209. package/dist/src/task-checkout.d.ts +20 -4
  210. package/dist/src/task-checkout.js +78 -8
  211. package/dist/src/telemetry/access.d.ts +18 -0
  212. package/dist/src/telemetry/access.js +43 -0
  213. package/dist/src/telemetry/aggregate.d.ts +18 -2
  214. package/dist/src/telemetry/aggregate.js +22 -9
  215. package/dist/src/telemetry/capture-core.d.ts +33 -14
  216. package/dist/src/telemetry/capture-core.js +124 -25
  217. package/dist/src/telemetry/capture.d.ts +3 -2
  218. package/dist/src/telemetry/capture.js +21 -1
  219. package/dist/src/telemetry/decision-capture.js +4 -0
  220. package/dist/src/telemetry/emitter.d.ts +6 -7
  221. package/dist/src/telemetry/emitter.js +124 -29
  222. package/dist/src/telemetry/gate.d.ts +41 -2
  223. package/dist/src/telemetry/gate.js +89 -4
  224. package/dist/src/telemetry/home.d.ts +1 -0
  225. package/dist/src/telemetry/home.js +20 -0
  226. package/dist/src/telemetry/identity.d.ts +6 -3
  227. package/dist/src/telemetry/identity.js +19 -6
  228. package/dist/src/telemetry/lifecycle.d.ts +8 -0
  229. package/dist/src/telemetry/lifecycle.js +76 -0
  230. package/dist/src/telemetry/outbox.d.ts +13 -8
  231. package/dist/src/telemetry/outbox.js +68 -12
  232. package/dist/src/telemetry/permission-command.d.ts +38 -0
  233. package/dist/src/telemetry/permission-command.js +208 -0
  234. package/dist/src/telemetry/permission.d.ts +168 -0
  235. package/dist/src/telemetry/permission.js +662 -0
  236. package/dist/src/telemetry/record-installation.d.ts +1 -0
  237. package/dist/src/telemetry/record-installation.js +9 -0
  238. package/dist/src/telemetry/region-data.d.ts +12 -0
  239. package/dist/src/telemetry/region-data.js +1314 -0
  240. package/dist/src/telemetry/region.d.ts +34 -0
  241. package/dist/src/telemetry/region.js +87 -0
  242. package/dist/src/telemetry/run-privacy.d.ts +11 -0
  243. package/dist/src/telemetry/run-privacy.js +165 -0
  244. package/dist/src/telemetry/schema.d.ts +27 -6
  245. package/dist/src/telemetry/schema.js +109 -14
  246. package/dist/src/telemetry/state.d.ts +11 -7
  247. package/dist/src/telemetry/state.js +39 -6
  248. package/dist/src/telemetry/surface.d.ts +20 -3
  249. package/dist/src/telemetry/surface.js +71 -15
  250. package/dist/src/telemetry/uploader.d.ts +6 -11
  251. package/dist/src/telemetry/uploader.js +72 -46
  252. package/dist/src/telemetry/uploads.d.ts +5 -1
  253. package/dist/src/telemetry/uploads.js +25 -6
  254. package/dist/src/telemetry/version.d.ts +5 -0
  255. package/dist/src/telemetry/version.js +34 -0
  256. package/dist/src/telemetry/workspace.d.ts +4 -1
  257. package/dist/src/telemetry/workspace.js +18 -3
  258. package/dist/src/terminal-ui.d.ts +3 -0
  259. package/dist/src/terminal-ui.js +48 -6
  260. package/dist/src/thinking-level-detect.d.ts +3 -1
  261. package/dist/src/thinking-level-detect.js +8 -3
  262. package/dist/src/thinking-levels.d.ts +1 -1
  263. package/dist/src/thinking-levels.js +11 -4
  264. package/dist/src/timers.d.ts +2 -0
  265. package/dist/src/todos.d.ts +2 -1
  266. package/dist/src/todos.js +24 -4
  267. package/dist/src/tool-argument-coercion.d.ts +7 -0
  268. package/dist/src/tool-argument-coercion.js +49 -0
  269. package/dist/src/tool-catalog.d.ts +2 -2
  270. package/dist/src/tools.js +67 -22
  271. package/dist/src/transcript.js +2 -1
  272. package/dist/src/types.d.ts +14 -1
  273. package/dist/src/update.js +4 -0
  274. package/dist/src/usage-analytics.d.ts +7 -0
  275. package/dist/src/usage-analytics.js +85 -13
  276. package/dist/telemetry-consent-v1 +1 -0
  277. package/package.json +97 -96
@@ -5,7 +5,7 @@ export function createDecisionProvider(config) {
5
5
  if (!config.mode || config.mode === 'off' || !config.provider || config.provider === 'none')
6
6
  return new NoOpDecisionProvider();
7
7
  if (config.provider === 'andorra')
8
- return new AndorraDecisionProvider();
8
+ return new AndorraDecisionProvider(undefined, config.anonymous === true);
9
9
  const endpoint = config.endpoint ?? (config.provider === 'jev' ? 'https://api.typesafe.ai/v1' : undefined);
10
10
  if (!endpoint)
11
11
  return new NoOpDecisionProvider();
@@ -1,6 +1,6 @@
1
1
  import { DecisionPolicy } from './DecisionPolicy.js';
2
2
  import { hasFactGuidance } from './guidancePolicy.js';
3
- const families = { Read: 'filesystem-read', Glob: 'code-search', Grep: 'code-search', Write: 'filesystem-write', Edit: 'filesystem-write', Bash: 'shell', PowerShell: 'shell', NativeExec: 'shell', AsyncProcess: 'shell', PowerShellFast: 'shell', ShellMetrics: 'shell', read: 'filesystem-read', ls: 'filesystem-read', find: 'code-search', grep: 'code-search', write: 'filesystem-write', edit: 'filesystem-write', powershell: 'shell', bash: 'shell', read_file: 'filesystem-read', list_files: 'filesystem-read', write_file: 'filesystem-write', edit_file: 'filesystem-write', apply_patch: 'filesystem-write', search_files: 'code-search', repo_explore: 'codegraph', git_read: 'git', pull_request: 'git', shell: 'shell', memory_search: 'memory', spawn_subagent: 'subagents', wait_subagent: 'subagents', message_subagent: 'subagents', cancel_subagent: 'subagents', read_artifact: 'artifact', write_artifact: 'artifact' };
3
+ const families = { Read: 'filesystem-read', Glob: 'code-search', Grep: 'code-search', Write: 'filesystem-write', Edit: 'filesystem-write', Bash: 'shell', PowerShell: 'shell', NativeExec: 'shell', AsyncProcess: 'shell', PowerShellFast: 'shell', ShellMetrics: 'shell', read: 'filesystem-read', ls: 'filesystem-read', find: 'code-search', grep: 'code-search', write: 'filesystem-write', edit: 'filesystem-write', powershell: 'shell', bash: 'shell', read_file: 'filesystem-read', list_files: 'filesystem-read', write_file: 'filesystem-write', edit_file: 'filesystem-write', apply_patch: 'filesystem-write', search_files: 'code-search', repo_explore: 'codegraph', git_read: 'git', pull_request: 'git', shell: 'shell', memory_search: 'memory', spawn_subagent: 'subagents', wait_subagent: 'subagents', message_subagent: 'subagents', cancel_subagent: 'subagents', currentAndorraStreams: 'subagents', read_artifact: 'artifact', write_artifact: 'artifact' };
4
4
  const protectedTools = new Set(['complete_agent', 'complete', 'complete_task', 'submit_completion', 'update_todos', 'ask_user', 'load_project_skill', 'restore_tools', 'prepare_steps', 'prepare_finish']);
5
5
  export function toolFamily(tool) { return tool.family ?? families[tool.name]; }
6
6
  export function toolFamilies(tools) { return [...new Set(tools.map(toolFamily).filter((family) => family !== undefined))]; }
@@ -5,6 +5,8 @@ export interface DecisionConfig {
5
5
  model?: string;
6
6
  apiKeyEnv?: string;
7
7
  requestTimeoutMs?: number;
8
+ /** The run has no account and the service lets it use the hosted provider anyway (`withAnonymousJev`). */
9
+ anonymous?: boolean;
8
10
  features?: Partial<Record<'toolRouting' | 'taskRouting' | 'codeGraphRouting' | 'memoryRouting' | 'webRouting' | 'delegationRouting' | 'verificationRouting' | 'riskClassification' | 'resultRouting', boolean>>;
9
11
  style?: 'facts' | 'questions';
10
12
  }
@@ -1,6 +1,8 @@
1
1
  export interface ModelTierTarget {
2
2
  provider: string;
3
3
  model?: string;
4
+ /** The thinking level the tier runs at. Without one it is chosen from the model's `scores`, when its levels are scored. */
5
+ effort?: PoolEffort;
4
6
  }
5
7
  export interface ModelPricing {
6
8
  inputPerMillionUsd: number;
@@ -16,6 +18,61 @@ export interface AdaptiveRoutingConfig {
16
18
  };
17
19
  maxEscalations?: number;
18
20
  pricing?: Record<string, ModelPricing>;
21
+ /** `tiers` (the default) routes by the three tiers; `pool` routes by scored pairs and subscription usage. */
22
+ strategy?: 'tiers' | 'pool';
23
+ /** Pool only. `shadow` records the decision and changes nothing; `enforce` (the default) applies it. */
24
+ mode?: 'shadow' | 'enforce';
25
+ pool?: PoolEntry[];
26
+ /** Pool only. The score a pair must reach for each task class, replacing the defaults. */
27
+ classScores?: Partial<Record<PoolClass, number>>;
28
+ quota?: PoolQuotaConfig;
29
+ /**
30
+ * Subagents that would inherit the parent's model get their own routing decision, under either strategy and also when
31
+ * the run's own model was chosen. A model a graph names for a subagent or its node is kept.
32
+ */
33
+ subagents?: boolean;
34
+ /**
35
+ * Pool only. `listed` (the default) routes among the `pool` pairs. `all` also routes among every model of every
36
+ * configured provider that has an entry in `scores`, at each thinking level scored for it.
37
+ */
38
+ candidates?: 'listed' | 'all';
39
+ /** Scores by `provider/model`, written by the refresh action or by hand. */
40
+ scores?: Record<string, ModelScore>;
41
+ /** When the refresh action last wrote `scores` (ISO 8601). */
42
+ scoresUpdatedAt?: string;
43
+ }
44
+ export declare const POOL_CLASSES: readonly ["routine", "quick", "standard", "deep", "escalated"];
45
+ export type PoolClass = typeof POOL_CLASSES[number];
46
+ export declare const DEFAULT_POOL_CLASS_SCORES: Readonly<Record<PoolClass, number>>;
47
+ export declare const POOL_EFFORTS: readonly ["none", "minimal", "low", "medium", "high", "xhigh", "max"];
48
+ export type PoolEffort = typeof POOL_EFFORTS[number];
49
+ /** The most `scores` entries a configuration may hold. */
50
+ export declare const MAX_POOL_SCORES = 512;
51
+ /** One pair the pool router may select. The score and the cost are the user's own figures; the runtime rates no model. */
52
+ export interface PoolEntry {
53
+ provider: string;
54
+ model?: string;
55
+ /** The thinking level the pair runs at; without one the pair runs at the provider's saved level. */
56
+ effort?: typeof POOL_EFFORTS[number];
57
+ /** 0 to 100, compared with the class scores. */
58
+ quality: number;
59
+ /** Relative cost per task, in any one unit across the pool. Without one, a higher score is taken to cost more. */
60
+ cost?: number;
61
+ }
62
+ export interface PoolQuotaConfig {
63
+ /** A subscription with this share or less of any usage window left is not selected. Default 5. */
64
+ reservePercent?: number;
65
+ /** Pairs whose cost is within this share of the cheapest count as equal. Default 10. */
66
+ nearTiePercent?: number;
67
+ }
68
+ /** A score from 0 to 100, compared with the class scores, and an optional relative cost per task. */
69
+ export interface PairScore {
70
+ quality: number;
71
+ cost?: number;
72
+ }
73
+ /** One model's score: at the provider's saved thinking level, and at each level scored on its own under `efforts`. */
74
+ export interface ModelScore extends PairScore {
75
+ efforts?: Partial<Record<PoolEffort, PairScore>>;
19
76
  }
20
77
  export interface ToolMenuRoutingConfig {
21
78
  mode?: 'off' | 'shadow' | 'lean';
@@ -62,6 +119,23 @@ export interface ResolvedEfficiency {
62
119
  };
63
120
  }
64
121
  export declare function resolveEfficiency(config: EfficiencyConfig | undefined): ResolvedEfficiency;
65
- export declare const EFFICIENCY_REASONS: readonly ["deterministic_continuation", "jev_selected", "no_candidates", "no_actionable_decision", "stale_task", "stale_permissions", "catalog_mismatch", "blocked", "denied", "invalid_arguments", "automatic_limit", "batch_failed", "batch_succeeded", "filtered", "below_threshold", "unknown_format", "protected_tool", "error_output", "expanded", "expansion_rejected", "empty_workspace", "index_unavailable", "memory_unavailable", "selected", "duplicate", "changed", "fallback", "economy", "balanced", "premium", "baseline", "pinned", "unconfigured", "low_confidence", "risk", "escalated", "escalation_limit", "omitted", "restored", "historical", "explicit"];
122
+ export declare const EFFICIENCY_REASONS: readonly ["deterministic_continuation", "jev_selected", "no_candidates", "no_actionable_decision", "stale_task", "stale_permissions", "catalog_mismatch", "blocked", "denied", "invalid_arguments", "automatic_limit", "batch_failed", "batch_succeeded", "filtered", "below_threshold", "unknown_format", "protected_tool", "error_output", "expanded", "expansion_rejected", "empty_workspace", "index_unavailable", "memory_unavailable", "selected", "duplicate", "changed", "fallback", "economy", "balanced", "premium", "baseline", "pinned", "unconfigured", "low_confidence", "risk", "escalated", "escalation_limit", "omitted", "restored", "historical", "explicit", "routine", "quick", "standard", "deep", "no_candidate", "quota_reserve"];
66
123
  export type EfficiencyReason = typeof EFFICIENCY_REASONS[number];
124
+ /** The key of a model in `adaptiveRouting.scores`. A provider id holds no slash, so the first one divides the two. */
125
+ export declare const poolScoreKey: (provider: string, model: string) => string;
126
+ /**
127
+ * The pairs pool routing chooses among. With `candidates: listed` they are the `pool` as written. With `all`, every
128
+ * model of every configured provider that has a score is added: one pair per scored thinking level the model takes
129
+ * (`levels`, when given, names the levels it takes), or one pair at the provider's saved level when none is scored.
130
+ * A model the `pool` names keeps the pairs written for it. `unscored` counts the configured models left out for want
131
+ * of a score.
132
+ */
133
+ export declare function poolEntries(routing: Pick<AdaptiveRoutingConfig, 'pool' | 'candidates' | 'scores'>, configured: readonly {
134
+ id: string;
135
+ model?: string;
136
+ models?: readonly string[];
137
+ }[], levels?: (provider: string, model: string) => readonly string[] | undefined): {
138
+ entries: PoolEntry[];
139
+ unscored: number;
140
+ };
67
141
  export {};
@@ -1,3 +1,8 @@
1
+ export const POOL_CLASSES = ['routine', 'quick', 'standard', 'deep', 'escalated'];
2
+ export const DEFAULT_POOL_CLASS_SCORES = { routine: 29, quick: 38, standard: 50, deep: 55, escalated: 60 };
3
+ export const POOL_EFFORTS = ['none', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'];
4
+ /** The most `scores` entries a configuration may hold. */
5
+ export const MAX_POOL_SCORES = 512;
1
6
  export const EFFICIENCY_FEATURES = ['preparedContinuations', 'postflightOnlyWithCandidates', 'toolResultFiltering', 'contextSelection', 'catalogSelection'];
2
7
  export const DEFAULT_TOOL_RESULT_FILTER_THRESHOLD = 6000;
3
8
  const TIERS = ['economy', 'balanced', 'premium'];
@@ -6,12 +11,14 @@ const record = (value) => !!value && typeof value === 'object' && !Array.isArray
6
11
  const identifier = (value, max) => typeof value === 'string' && value.trim().length > 0 && value.length <= max && !/[\r\n]/.test(value);
7
12
  const price = (value) => typeof value === 'number' && Number.isFinite(value) && value >= 0;
8
13
  function validateTarget(value, label) {
9
- if (!record(value) || Object.keys(value).some(key => !['provider', 'model'].includes(key)))
14
+ if (!record(value) || Object.keys(value).some(key => !['provider', 'model', 'effort'].includes(key)))
10
15
  throw new Error(`Invalid efficiency.adaptiveRouting.tiers.${label}`);
11
16
  if (!/^[\w-]+$/.test(String(value.provider ?? '')))
12
17
  throw new Error(`efficiency.adaptiveRouting.tiers.${label}.provider must name a configured provider id`);
13
18
  if (value.model !== undefined && !identifier(value.model, 500))
14
19
  throw new Error(`Invalid efficiency.adaptiveRouting.tiers.${label}.model`);
20
+ if (value.effort !== undefined && !POOL_EFFORTS.includes(value.effort))
21
+ throw new Error(`efficiency.adaptiveRouting.tiers.${label}.effort must be one of ${POOL_EFFORTS.join(', ')}`);
15
22
  }
16
23
  export function validateEfficiencyConfig(value) {
17
24
  if (!record(value))
@@ -47,8 +54,66 @@ export function validateEfficiencyConfig(value) {
47
54
  const routing = value.adaptiveRouting;
48
55
  if (routing === undefined)
49
56
  return;
50
- if (!record(routing) || Object.keys(routing).some(key => !['enabled', 'tiers', 'maxEscalations', 'pricing'].includes(key)))
57
+ if (!record(routing) || Object.keys(routing).some(key => !['enabled', 'tiers', 'maxEscalations', 'pricing', 'strategy', 'mode', 'pool', 'classScores', 'quota', 'subagents', 'candidates', 'scores', 'scoresUpdatedAt'].includes(key)))
51
58
  throw new Error('Invalid efficiency.adaptiveRouting');
59
+ const percent = (entry, max = 100) => typeof entry === 'number' && Number.isFinite(entry) && entry >= 0 && entry <= max;
60
+ if (routing.strategy !== undefined && (typeof routing.strategy !== 'string' || !['tiers', 'pool'].includes(routing.strategy)))
61
+ throw new Error('efficiency.adaptiveRouting.strategy must be tiers or pool');
62
+ if (routing.mode !== undefined && (typeof routing.mode !== 'string' || !['shadow', 'enforce'].includes(routing.mode)))
63
+ throw new Error('efficiency.adaptiveRouting.mode must be shadow or enforce');
64
+ if (routing.subagents !== undefined && typeof routing.subagents !== 'boolean')
65
+ throw new Error('efficiency.adaptiveRouting.subagents must be a boolean');
66
+ if (routing.pool !== undefined) {
67
+ if (!Array.isArray(routing.pool) || routing.pool.length > 64)
68
+ throw new Error('efficiency.adaptiveRouting.pool must be a list of at most 64 pairs');
69
+ routing.pool.forEach((entry, index) => {
70
+ const label = `efficiency.adaptiveRouting.pool[${index}]`;
71
+ if (!record(entry) || Object.keys(entry).some(key => !['provider', 'model', 'effort', 'quality', 'cost'].includes(key)))
72
+ throw new Error(`Invalid ${label}`);
73
+ if (!/^[\w-]+$/.test(String(entry.provider ?? '')))
74
+ throw new Error(`${label}.provider must name a configured provider id`);
75
+ if (entry.model !== undefined && !identifier(entry.model, 500))
76
+ throw new Error(`Invalid ${label}.model`);
77
+ if (entry.effort !== undefined && !POOL_EFFORTS.includes(entry.effort))
78
+ throw new Error(`${label}.effort must be one of ${POOL_EFFORTS.join(', ')}`);
79
+ if (!percent(entry.quality))
80
+ throw new Error(`${label}.quality must be a number from 0 to 100`);
81
+ if (entry.cost !== undefined && !price(entry.cost))
82
+ throw new Error(`${label}.cost must be a number of 0 or more`);
83
+ });
84
+ }
85
+ if (routing.candidates !== undefined && (typeof routing.candidates !== 'string' || !['listed', 'all'].includes(routing.candidates)))
86
+ throw new Error('efficiency.adaptiveRouting.candidates must be listed or all');
87
+ if (routing.scoresUpdatedAt !== undefined && (typeof routing.scoresUpdatedAt !== 'string' || Number.isNaN(Date.parse(routing.scoresUpdatedAt))))
88
+ throw new Error('efficiency.adaptiveRouting.scoresUpdatedAt must be a date');
89
+ if (routing.scores !== undefined) {
90
+ if (!record(routing.scores) || Object.keys(routing.scores).length > MAX_POOL_SCORES)
91
+ throw new Error(`efficiency.adaptiveRouting.scores must hold at most ${MAX_POOL_SCORES} models`);
92
+ const pair = (entry, extra = []) => record(entry) && Object.keys(entry).every(key => ['quality', 'cost', ...extra].includes(key))
93
+ && percent(entry.quality) && (entry.cost === undefined || price(entry.cost));
94
+ for (const [key, entry] of Object.entries(routing.scores)) {
95
+ const label = `efficiency.adaptiveRouting.scores["${key}"]`;
96
+ if (!identifier(key, 600) || !/^[\w-]+\/.+$/.test(key))
97
+ throw new Error('efficiency.adaptiveRouting.scores must be keyed provider/model');
98
+ if (!pair(entry, ['efforts']))
99
+ throw new Error(`${label} needs a quality from 0 to 100 and an optional cost of 0 or more`);
100
+ if (entry.efforts !== undefined && (!record(entry.efforts) || Object.entries(entry.efforts).some(([effort, score]) => !POOL_EFFORTS.includes(effort) || !pair(score)))) {
101
+ throw new Error(`${label}.efforts accepts ${POOL_EFFORTS.join(', ')}, each with a quality from 0 to 100 and an optional cost`);
102
+ }
103
+ }
104
+ }
105
+ if (routing.classScores !== undefined) {
106
+ if (!record(routing.classScores) || Object.entries(routing.classScores).some(([key, entry]) => !POOL_CLASSES.includes(key) || !percent(entry)))
107
+ throw new Error(`efficiency.adaptiveRouting.classScores accepts ${POOL_CLASSES.join(', ')} with scores from 0 to 100`);
108
+ }
109
+ if (routing.quota !== undefined) {
110
+ if (!record(routing.quota) || Object.keys(routing.quota).some(key => !['reservePercent', 'nearTiePercent'].includes(key)))
111
+ throw new Error('Invalid efficiency.adaptiveRouting.quota');
112
+ if (routing.quota.reservePercent !== undefined && !percent(routing.quota.reservePercent, 50))
113
+ throw new Error('efficiency.adaptiveRouting.quota.reservePercent must be a number from 0 to 50');
114
+ if (routing.quota.nearTiePercent !== undefined && !percent(routing.quota.nearTiePercent))
115
+ throw new Error('efficiency.adaptiveRouting.quota.nearTiePercent must be a number from 0 to 100');
116
+ }
52
117
  if (routing.enabled !== undefined && typeof routing.enabled !== 'boolean')
53
118
  throw new Error('efficiency.adaptiveRouting.enabled must be a boolean');
54
119
  if (routing.maxEscalations !== undefined && (!Number.isSafeInteger(routing.maxEscalations) || routing.maxEscalations < 0 || routing.maxEscalations > 3))
@@ -68,7 +133,12 @@ export function validateEfficiencyConfig(value) {
68
133
  throw new Error(`Invalid efficiency.adaptiveRouting.pricing entry: ${key}`);
69
134
  }
70
135
  }
71
- if (routing.enabled === true && !(record(routing.tiers) && Object.keys(routing.tiers).length))
136
+ if (routing.enabled === true && routing.strategy === 'pool') {
137
+ // With `candidates: all` the pairs come from `scores`, which the refresh action fills in.
138
+ if (routing.candidates !== 'all' && !(Array.isArray(routing.pool) && routing.pool.length))
139
+ throw new Error('efficiency.adaptiveRouting.enabled with strategy pool requires at least one pool pair, or candidates set to all');
140
+ }
141
+ else if (routing.enabled === true && !(record(routing.tiers) && Object.keys(routing.tiers).length))
72
142
  throw new Error('efficiency.adaptiveRouting.enabled requires at least one tier');
73
143
  }
74
144
  export function resolveEfficiency(config) {
@@ -89,4 +159,45 @@ export const EFFICIENCY_REASONS = [
89
159
  'empty_workspace', 'index_unavailable', 'memory_unavailable', 'selected', 'duplicate', 'changed', 'fallback',
90
160
  'economy', 'balanced', 'premium', 'baseline', 'pinned', 'unconfigured', 'low_confidence', 'risk', 'escalated', 'escalation_limit',
91
161
  'omitted', 'restored', 'historical', 'explicit',
162
+ 'routine', 'quick', 'standard', 'deep', 'no_candidate', 'quota_reserve',
92
163
  ];
164
+ /** The key of a model in `adaptiveRouting.scores`. A provider id holds no slash, so the first one divides the two. */
165
+ export const poolScoreKey = (provider, model) => `${provider}/${model}`;
166
+ /**
167
+ * The pairs pool routing chooses among. With `candidates: listed` they are the `pool` as written. With `all`, every
168
+ * model of every configured provider that has a score is added: one pair per scored thinking level the model takes
169
+ * (`levels`, when given, names the levels it takes), or one pair at the provider's saved level when none is scored.
170
+ * A model the `pool` names keeps the pairs written for it. `unscored` counts the configured models left out for want
171
+ * of a score.
172
+ */
173
+ export function poolEntries(routing, configured, levels) {
174
+ const own = routing.pool ?? [];
175
+ const entries = [...own];
176
+ if (routing.candidates !== 'all')
177
+ return { entries, unscored: 0 };
178
+ let unscored = 0;
179
+ for (const provider of configured) {
180
+ const listed = new Set(own.filter(entry => entry.provider === provider.id).map(entry => entry.model ?? provider.model));
181
+ for (const model of new Set([provider.model, ...(provider.models ?? [])])) {
182
+ if (!model || listed.has(model))
183
+ continue;
184
+ const key = poolScoreKey(provider.id, model);
185
+ const score = routing.scores && Object.hasOwn(routing.scores, key) ? routing.scores[key] : undefined;
186
+ if (!score) {
187
+ unscored++;
188
+ continue;
189
+ }
190
+ const taken = levels?.(provider.id, model);
191
+ const scored = POOL_EFFORTS.filter(effort => score.efforts?.[effort] !== undefined && (taken === undefined || taken.includes(effort)));
192
+ if (!scored.length) {
193
+ entries.push({ provider: provider.id, model, quality: score.quality, ...(score.cost === undefined ? {} : { cost: score.cost }) });
194
+ continue;
195
+ }
196
+ for (const effort of scored) {
197
+ const pair = score.efforts[effort];
198
+ entries.push({ provider: provider.id, model, effort, quality: pair.quality, ...(pair.cost === undefined ? {} : { cost: pair.cost }) });
199
+ }
200
+ }
201
+ }
202
+ return { entries, unscored };
203
+ }
@@ -19,6 +19,8 @@ export interface BundleEntry {
19
19
  relativePath?: string;
20
20
  command?: string;
21
21
  }
22
+ /** Default cap for installing a GitHub skill or plugin: the compressed archive download, its expanded size and the selected bundle's file content are all bounded by this byte budget. Raise it with `extensions.githubArchiveMaxBytes` in config.json. */
23
+ export declare const DEFAULT_GITHUB_ARCHIVE_MAX_BYTES: number;
22
24
  export declare const MAX_SKILL_DOCUMENT_BYTES: number;
23
25
  export declare function listBundles(kind: Kind, config: Config, options?: {
24
26
  notices?: string[];
@@ -6,19 +6,29 @@ import { gunzip } from 'node:zlib';
6
6
  import { promisify } from 'node:util';
7
7
  import { parseDocument } from 'yaml';
8
8
  import { acquireSaveLock, SaveLockBusyError } from './save-lock.js';
9
- import { configDirectory, validateMcpServer } from './config.js';
9
+ import { configDirectory, validateMcpServer, MIN_GITHUB_ARCHIVE_MAX_BYTES } from './config.js';
10
10
  export { validateMcpServer } from './config.js';
11
11
  import { resolveBuiltinSkill } from './skills/invocable-skills.js';
12
12
  import { bundledSkillCatalog, bundledSkillDirectory } from './skills/runtime-skills.js';
13
13
  import { isBuiltinSlashCommand } from './skill-commands.js';
14
14
  import { workspacePermissionKey } from './permissions.js';
15
15
  const unzip = promisify(gunzip);
16
- const MAX_ARCHIVE_BYTES = 64 * 1024 * 1024;
17
- const MAX_EXPANDED_ARCHIVE_BYTES = 80 * 1024 * 1024;
18
- async function githubArchive(url, stage, subtree, signal) {
16
+ /** Default cap for installing a GitHub skill or plugin: the compressed archive download, its expanded size and the selected bundle's file content are all bounded by this byte budget. Raise it with `extensions.githubArchiveMaxBytes` in config.json. */
17
+ export const DEFAULT_GITHUB_ARCHIVE_MAX_BYTES = 1024 * 1024 * 1024;
18
+ const mib = (bytes) => Math.ceil(bytes / (1024 * 1024));
19
+ function githubArchiveMaxBytes(config) {
20
+ const configured = config.extensions?.githubArchiveMaxBytes;
21
+ if (configured === undefined)
22
+ return DEFAULT_GITHUB_ARCHIVE_MAX_BYTES;
23
+ if (!Number.isSafeInteger(configured) || configured < MIN_GITHUB_ARCHIVE_MAX_BYTES)
24
+ throw new Error('extensions.githubArchiveMaxBytes must be a whole number of at least 1 MiB');
25
+ return configured;
26
+ }
27
+ async function githubArchive(url, stage, subtree, signal, maxBytes = DEFAULT_GITHUB_ARCHIVE_MAX_BYTES) {
19
28
  const controller = new AbortController();
20
29
  const timeout = setTimeout(() => controller.abort(new Error('GitHub installation timed out')), 120_000);
21
30
  const active = signal ? AbortSignal.any([signal, controller.signal]) : controller.signal;
31
+ const expandedMax = Math.ceil(maxBytes * 5 / 4);
22
32
  try {
23
33
  const response = await fetch(url, { signal: active, redirect: 'error' });
24
34
  if (!response.ok || !response.body) {
@@ -30,16 +40,16 @@ async function githubArchive(url, stage, subtree, signal) {
30
40
  let received = 0;
31
41
  try {
32
42
  const declared = response.headers.get('content-length');
33
- if (declared !== null && Number(declared) > MAX_ARCHIVE_BYTES)
34
- throw new Error('GitHub archive exceeds 64 MiB download limit');
43
+ if (declared !== null && Number(declared) > maxBytes)
44
+ throw new Error(`GitHub archive exceeds the ${mib(maxBytes)} MiB download limit`);
35
45
  while (true) {
36
46
  active.throwIfAborted();
37
47
  const item = await reader.read();
38
48
  if (item.done)
39
49
  break;
40
50
  received += item.value.byteLength;
41
- if (received > MAX_ARCHIVE_BYTES)
42
- throw new Error('GitHub archive exceeds 64 MiB download limit');
51
+ if (received > maxBytes)
52
+ throw new Error(`GitHub archive exceeds the ${mib(maxBytes)} MiB download limit`);
43
53
  chunks.push(item.value);
44
54
  }
45
55
  }
@@ -50,11 +60,11 @@ async function githubArchive(url, stage, subtree, signal) {
50
60
  active.throwIfAborted();
51
61
  let archive;
52
62
  try {
53
- archive = await unzip(Buffer.concat(chunks), { maxOutputLength: MAX_EXPANDED_ARCHIVE_BYTES });
63
+ archive = await unzip(Buffer.concat(chunks), { maxOutputLength: expandedMax });
54
64
  }
55
65
  catch (error) {
56
66
  if (error.code === 'ERR_BUFFER_TOO_LARGE')
57
- throw new Error('GitHub archive exceeds 80 MiB expanded limit');
67
+ throw new Error(`GitHub archive exceeds the ${mib(expandedMax)} MiB expanded limit`);
58
68
  throw new Error('Invalid GitHub gzip archive');
59
69
  }
60
70
  const selected = subtree?.split('/');
@@ -153,8 +163,8 @@ async function githubArchive(url, stage, subtree, signal) {
153
163
  if (treePaths.size + 1 > 10_000)
154
164
  throw new Error('Extension exceeds 10,000 files or 64 MiB');
155
165
  }
156
- if (treePaths.size + 1 > 10_000 || (bytes += size) > MAX_ARCHIVE_BYTES)
157
- throw new Error('Extension exceeds 10,000 files or 64 MiB');
166
+ if (treePaths.size + 1 > 10_000 || (bytes += size) > maxBytes)
167
+ throw new Error(`Extension exceeds 10,000 files or ${mib(maxBytes)} MiB`);
158
168
  entries.push({ path: target, mode: number(header, 100, 8) & 0o777, ...(type !== '5' ? { data } : {}) });
159
169
  }
160
170
  if (!ended || nextPath || !prefix || !entries.length)
@@ -218,17 +228,17 @@ function skillIdValid(id) { const [group, ...rest] = id.split(':'); idValid(grou
218
228
  function disabled(kind, config) { return config.extensions?.[kind === 'skills' ? 'disabledSkills' : 'disabledPlugins'] ?? []; }
219
229
  function root(kind, directory = configDirectory()) { return resolve(directory, kind); }
220
230
  function contained(base, target) { const rel = relative(base, target); return !isAbsolute(rel) && rel !== '..' && !rel.startsWith('..\\') && !rel.startsWith('../'); }
221
- async function safeTree(path, signal, budget = { count: 0, bytes: 0 }) {
231
+ async function safeTree(path, signal, maxBytes = DEFAULT_GITHUB_ARCHIVE_MAX_BYTES, budget = { count: 0, bytes: 0 }) {
222
232
  signal?.throwIfAborted();
223
233
  const info = await lstat(path);
224
- if (++budget.count > 10_000 || (budget.bytes += info.size) > 64 * 1024 * 1024)
225
- throw new Error('Extension exceeds 10,000 files or 64 MiB');
234
+ if (++budget.count > 10_000 || (budget.bytes += info.size) > maxBytes)
235
+ throw new Error(`Extension exceeds 10,000 files or ${mib(maxBytes)} MiB`);
226
236
  if (info.isSymbolicLink() || (!info.isDirectory() && !info.isFile()))
227
237
  throw new Error('Extension links and special files are not supported');
228
238
  if (info.isDirectory())
229
239
  for (const item of await readdir(path))
230
240
  if (item !== '.git')
231
- await safeTree(join(path, item), signal, budget);
241
+ await safeTree(join(path, item), signal, maxBytes, budget);
232
242
  }
233
243
  async function checkedResourcePath(base, path, signal) {
234
244
  signal?.throwIfAborted();
@@ -360,7 +370,7 @@ async function discoverSkillPaths(base, signal) {
360
370
  async function walk(path) {
361
371
  signal?.throwIfAborted();
362
372
  if (++count > 10_000)
363
- throw new Error('Extension exceeds 10,000 files or 64 MiB');
373
+ throw new Error('Extension exceeds 10,000 files');
364
374
  const items = await readdir(path, { withFileTypes: true });
365
375
  if (items.some(item => item.name === 'SKILL.md' && item.isFile()))
366
376
  paths.push(relative(base, path).split(sep).join('/') || '.');
@@ -483,7 +493,7 @@ export async function installBundle(kind, source, config, signal, directory = co
483
493
  url.hash = '';
484
494
  url.pathname = `/${match[1]}/${match[2]}`;
485
495
  const archiveUrl = `https://codeload.github.com/${match[1]}/${match[2]}/tar.gz/${ref ? encodeURIComponent(ref) : 'HEAD'}`;
486
- await githubArchive(archiveUrl, stage, subtree, signal);
496
+ await githubArchive(archiveUrl, stage, subtree, signal, githubArchiveMaxBytes(config));
487
497
  }
488
498
  else {
489
499
  const path = await realpath(resolve(source));
@@ -491,11 +501,11 @@ export async function installBundle(kind, source, config, signal, directory = co
491
501
  idValid(id);
492
502
  if (contained(path, await realpath(root(kind, directory))))
493
503
  throw new Error('Cannot install an ancestor of the extension directory');
494
- await safeTree(path, signal);
504
+ await safeTree(path, signal, githubArchiveMaxBytes(config));
495
505
  await cp(path, stage, { recursive: true, dereference: false, filter: path => basename(path) !== '.git' });
496
506
  }
497
507
  idValid(id);
498
- await safeTree(stage, signal);
508
+ await safeTree(stage, signal, githubArchiveMaxBytes(config));
499
509
  if (kind === 'skills' && (repository || !await lstat(join(stage, 'SKILL.md')).then(() => true, (e) => { if (e.code !== 'ENOENT')
500
510
  throw e; return false; }))) {
501
511
  repository ??= { name: id, source, skills: [] };
@@ -90,7 +90,7 @@ export declare const CHANGED_WHILE_APPROVING = "The pull request or reply settin
90
90
  export declare function approvalDetail(write: AgentPullRequestWrite, pullRequest: SessionPullRequest, bot: boolean, botName?: string): string;
91
91
  /**
92
92
  * Whether an agent write goes to the service first: agent writes set to the bot, and the PR covered (or
93
- * `permissions-pending`, where the service decides per action). The Auto-fix prompt uses the same rule, so
93
+ * `permissions-pending`, where the service decides per action). The review prompt uses the same rule, so
94
94
  * the prompt and the tool agree on who the replies post as.
95
95
  */
96
96
  export declare const asksBot: (setting: AgentWritesSetting, coverage: GitHubCoverage) => boolean;
@@ -111,7 +111,7 @@ export function approvalDetail(write, pullRequest, bot, botName) {
111
111
  }
112
112
  /**
113
113
  * Whether an agent write goes to the service first: agent writes set to the bot, and the PR covered (or
114
- * `permissions-pending`, where the service decides per action). The Auto-fix prompt uses the same rule, so
114
+ * `permissions-pending`, where the service decides per action). The review prompt uses the same rule, so
115
115
  * the prompt and the tool agree on who the replies post as.
116
116
  */
117
117
  export const asksBot = (setting, coverage) => setting === 'bot' && (coverage === 'covered' || coverage === 'permissions-pending');
@@ -72,7 +72,6 @@ export interface GitHubEventSourceOptions {
72
72
  onSummary?(summary: GitHubWatchSummary): void | Promise<void>;
73
73
  log?(level: 'info' | 'warn', detail: string): void;
74
74
  now?(): number;
75
- isReviewer?(login: string | undefined): boolean;
76
75
  metrics?: GitHubWatchMetrics;
77
76
  /** The timers `start()` schedules runs with (tests pass a fake clock's). */
78
77
  timers?: {
@@ -97,7 +96,6 @@ export declare class GitHubEventSource {
97
96
  private readonly options;
98
97
  private readonly metrics;
99
98
  private readonly now;
100
- private readonly isReviewer;
101
99
  /** off: signed out, switched off here, or nothing learned yet. disabled: the service said `enabled: false` or not allowed. */
102
100
  private mode;
103
101
  private offReason;
@@ -125,7 +123,6 @@ export declare class GitHubEventSource {
125
123
  private readonly seenOrder;
126
124
  private watched;
127
125
  private holder;
128
- private readonly wakeNotices;
129
126
  private ticking?;
130
127
  private again;
131
128
  private timer?;
@@ -158,8 +155,6 @@ export declare class GitHubEventSource {
158
155
  covers(sessionId: string): boolean;
159
156
  /** For the measures: one gh call the watcher made for a session. Nothing is counted while the source is off. */
160
157
  countGhCall(sessionId: string): void;
161
- /** The watcher armed an Auto-fix wake: if a code-review notice caused it, its latency is recorded. */
162
- woke(sessionId: string): void;
163
158
  get eventMode(): EventMode;
164
159
  private get modeReason();
165
160
  /** What `github.status` reports: this process's view when it holds the lease, else the holder's saved view. */
@@ -1,4 +1,4 @@
1
- import { isCodeReviewer, listPullRequests, pullRequestNeedsWatch } from '../pull-requests.js';
1
+ import { listPullRequests, pullRequestNeedsWatch } from '../pull-requests.js';
2
2
  import { GitHubAppError, isMentionNotice } from './client.js';
3
3
  import { GitHubWatchMetrics } from './metrics.js';
4
4
  import { engineId, readCursor, readSharedCoverage, writeCursor, writeSharedCoverage } from './store.js';
@@ -25,7 +25,6 @@ export const BREAKER_MAX_BACKOFF_MS = 5 * 60_000;
25
25
  export const MAX_SUBSCRIBED = 50;
26
26
  export const SEEN_IDS = 1_000;
27
27
  const MAX_PAGES = 10;
28
- const WAKE_NOTICE_TTL_MS = 15 * 60_000;
29
28
  /** The shortest wait between two runs the source schedules itself, whatever is due: no due time in the past can spin it. */
30
29
  export const MIN_TICK_MS = 1_000;
31
30
  /** Renewals start this long before the service's `renewBy`, so one failed attempt does not lose coverage. */
@@ -47,7 +46,6 @@ export class GitHubEventSource {
47
46
  options;
48
47
  metrics;
49
48
  now;
50
- isReviewer;
51
49
  /** off: signed out, switched off here, or nothing learned yet. disabled: the service said `enabled: false` or not allowed. */
52
50
  mode = 'off';
53
51
  offReason = 'pending';
@@ -75,7 +73,6 @@ export class GitHubEventSource {
75
73
  seenOrder = [];
76
74
  watched = new Map();
77
75
  holder = false;
78
- wakeNotices = new Map();
79
76
  ticking;
80
77
  again = false;
81
78
  timer;
@@ -93,7 +90,6 @@ export class GitHubEventSource {
93
90
  this.options = options;
94
91
  this.metrics = options.metrics ?? new GitHubWatchMetrics();
95
92
  this.now = options.now ?? Date.now;
96
- this.isReviewer = options.isReviewer ?? (login => isCodeReviewer(login));
97
93
  this.timers = options.timers ?? {
98
94
  setTimeout: (callback, ms) => { const handle = setTimeout(callback, ms); handle.unref?.(); return handle; },
99
95
  clearTimeout: handle => clearTimeout(handle),
@@ -180,15 +176,6 @@ export class GitHubEventSource {
180
176
  return;
181
177
  this.metrics.call(sessionId, this.coverageOf(sessionId), this.now());
182
178
  }
183
- /** The watcher armed an Auto-fix wake: if a code-review notice caused it, its latency is recorded. */
184
- woke(sessionId) {
185
- const at = this.wakeNotices.get(sessionId);
186
- if (at === undefined)
187
- return;
188
- this.wakeNotices.delete(sessionId);
189
- const now = this.now();
190
- this.metrics.wake(now - at, now);
191
- }
192
179
  get eventMode() {
193
180
  if (this.mode === 'events' && !this.breakerOpen && [...this.watched.keys()].some(id => this.covers(id)))
194
181
  return 'events';
@@ -346,9 +333,6 @@ export class GitHubEventSource {
346
333
  if (this.holder && active)
347
334
  for (const entry of this.watched.values())
348
335
  this.metrics.watched(entry.sessionId, this.coverageOf(entry.sessionId), at);
349
- for (const [sessionId, noticeAt] of this.wakeNotices)
350
- if (at - noticeAt > WAKE_NOTICE_TTL_MS)
351
- this.wakeNotices.delete(sessionId);
352
336
  if (this.metrics.due(at) && !this.stopped) {
353
337
  const summary = this.metrics.take(at);
354
338
  if (summary)
@@ -641,20 +625,6 @@ export class GitHubEventSource {
641
625
  this.options.onStale?.(entry.sessionId);
642
626
  if (notice.kind === 'state' || notice.kind === 'head' || notice.kind === 'checks')
643
627
  void this.options.watcher.checkNow(entry.sessionId);
644
- else if ((notice.kind === 'review' || notice.kind === 'comment') && entry.pullRequest.autoFix && this.isReviewer(notice.actor)) {
645
- const sessionId = entry.sessionId;
646
- const at = notice.at === undefined ? this.now() : Date.parse(notice.at);
647
- const known = this.wakeNotices.get(sessionId);
648
- if (known === undefined || at < known)
649
- this.wakeNotices.set(sessionId, at);
650
- const noted = this.wakeNotices.get(sessionId);
651
- // The wake this notice is timed for is the one its own read arms: a read that arms none forgets the
652
- // notice, so a later wake with another cause is never counted as its latency.
653
- void Promise.resolve(this.options.watcher.checkNow(sessionId)).then(() => {
654
- if (this.wakeNotices.get(sessionId) === noted)
655
- this.wakeNotices.delete(sessionId);
656
- }, () => { });
657
- }
658
628
  }
659
629
  }
660
630
  }
@@ -8,24 +8,21 @@ export interface GitHubWatchSummary {
8
8
  prs: number;
9
9
  calls: number;
10
10
  }[];
11
- /** Seconds from a code-review notice's time to the Auto-fix wake it caused, whole seconds. */
11
+ /** Retained for consumers of the historical telemetry shape. */
12
12
  wakeLatencies: number[];
13
13
  }
14
14
  /**
15
- * Counts for product telemetry (ADR 0021, `github.watch`): gh calls per watched PR by coverage, and wake
16
- * latency. Only numbers and coverage states are kept: no PR, repository or session leaves this object.
15
+ * Counts for product telemetry (ADR 0021, `github.watch`): gh calls per watched PR by coverage. Only numbers and coverage states are kept: no PR, repository or session leaves this object.
17
16
  */
18
17
  export declare class GitHubWatchMetrics {
19
18
  private readonly windowMs;
20
19
  private started?;
21
20
  private readonly prs;
22
21
  private readonly calls;
23
- private latencies;
24
22
  constructor(windowMs?: number);
25
23
  private begin;
26
24
  watched(sessionId: string, coverage: GitHubCoverage, now: number): void;
27
25
  call(sessionId: string, coverage: GitHubCoverage, now: number): void;
28
- wake(latencyMs: number, now: number): void;
29
26
  due(now: number): boolean;
30
27
  /** The window so far, and a fresh one begun; undefined when no PR was watched in it. */
31
28
  take(now: number): GitHubWatchSummary | undefined;
@@ -1,16 +1,12 @@
1
1
  const WINDOW_MS = 60 * 60_000;
2
- const MAX_LATENCIES = 60;
3
- const MAX_LATENCY_SECONDS = 86_400;
4
2
  /**
5
- * Counts for product telemetry (ADR 0021, `github.watch`): gh calls per watched PR by coverage, and wake
6
- * latency. Only numbers and coverage states are kept: no PR, repository or session leaves this object.
3
+ * Counts for product telemetry (ADR 0021, `github.watch`): gh calls per watched PR by coverage. Only numbers and coverage states are kept: no PR, repository or session leaves this object.
7
4
  */
8
5
  export class GitHubWatchMetrics {
9
6
  windowMs;
10
7
  started;
11
8
  prs = new Map();
12
9
  calls = new Map();
13
- latencies = [];
14
10
  constructor(windowMs = WINDOW_MS) {
15
11
  this.windowMs = windowMs;
16
12
  }
@@ -25,25 +21,17 @@ export class GitHubWatchMetrics {
25
21
  this.watched(sessionId, coverage, now);
26
22
  this.calls.set(coverage, (this.calls.get(coverage) ?? 0) + 1);
27
23
  }
28
- wake(latencyMs, now) {
29
- this.begin(now);
30
- if (this.latencies.length >= MAX_LATENCIES || !Number.isFinite(latencyMs))
31
- return;
32
- this.latencies.push(Math.max(0, Math.min(MAX_LATENCY_SECONDS, Math.round(latencyMs / 1000))));
33
- }
34
24
  due(now) { return this.started !== undefined && now - this.started >= this.windowMs; }
35
25
  /** The window so far, and a fresh one begun; undefined when no PR was watched in it. */
36
26
  take(now) {
37
27
  const started = this.started;
38
28
  const coverage = [...this.prs.entries()].map(([state, sessions]) => ({ state, prs: Math.min(sessions.size, 10_000), calls: this.calls.get(state) ?? 0 }));
39
- const latencies = this.latencies;
40
29
  this.started = undefined;
41
30
  this.prs.clear();
42
31
  this.calls.clear();
43
- this.latencies = [];
44
32
  if (started === undefined || coverage.length === 0)
45
33
  return undefined;
46
34
  const minutes = Math.max(1, Math.min(60, Math.ceil((now - started) / 60_000)));
47
- return { minutes, coverage, wakeLatencies: latencies };
35
+ return { minutes, coverage, wakeLatencies: [] };
48
36
  }
49
37
  }