@capybara-hq/kernel 0.1.0-rc.36 → 0.1.0-rc.38

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 (351) hide show
  1. package/bootstrap.json +5 -5
  2. package/dist/admin/admin.module.d.ts +3 -2
  3. package/dist/admin/admin.module.js +9 -5
  4. package/dist/admin/audit-log.service.d.ts +51 -0
  5. package/dist/admin/{platform-audit.service.js → audit-log.service.js} +20 -12
  6. package/dist/admin/audit.controller.d.ts +18 -6
  7. package/dist/admin/audit.controller.js +36 -6
  8. package/dist/admin/audit.schemas.d.ts +9 -1
  9. package/dist/admin/audit.schemas.js +22 -2
  10. package/dist/admin/org-network.controller.d.ts +30 -0
  11. package/dist/admin/org-network.controller.js +77 -0
  12. package/dist/admin/org-network.schemas.d.ts +16 -0
  13. package/dist/admin/org-network.schemas.js +27 -0
  14. package/dist/admin/org-network.service.d.ts +41 -0
  15. package/dist/admin/org-network.service.js +101 -0
  16. package/dist/admin/outbox-dead.controller.d.ts +4 -6
  17. package/dist/admin/outbox-dead.controller.js +9 -6
  18. package/dist/admin/outbox-dead.schemas.d.ts +16 -0
  19. package/dist/admin/outbox-dead.schemas.js +25 -1
  20. package/dist/admin/outbox-dead.service.d.ts +16 -7
  21. package/dist/admin/outbox-dead.service.js +34 -10
  22. package/dist/admin/overview.service.d.ts +3 -3
  23. package/dist/admin/overview.service.js +0 -1
  24. package/dist/agents/agent-lookup.js +2 -10
  25. package/dist/agents/agents.service.js +9 -20
  26. package/dist/agents/definition.d.ts +3 -51
  27. package/dist/agents/definition.js +4 -254
  28. package/dist/agents/org-templates.js +2 -6
  29. package/dist/agents/readiness.controller.d.ts +4 -12
  30. package/dist/agents/readiness.controller.js +4 -12
  31. package/dist/agents/readiness.service.d.ts +23 -11
  32. package/dist/agents/readiness.service.js +31 -14
  33. package/dist/agents/templates.d.ts +0 -6
  34. package/dist/agents/templates.js +8 -34
  35. package/dist/background/store.d.ts +2 -0
  36. package/dist/background/store.js +3 -1
  37. package/dist/background/wake-rules.js +2 -1
  38. package/dist/catalog/admin-catalog.controller.d.ts +1 -2
  39. package/dist/catalog/admin-catalog.controller.js +1 -2
  40. package/dist/catalog/appearance.service.js +1 -3
  41. package/dist/catalog/catalog-content.d.ts +1 -1
  42. package/dist/catalog/catalog-content.js +1 -4
  43. package/dist/catalog/catalog-items.js +3 -3
  44. package/dist/catalog/catalog-scope.service.d.ts +10 -28
  45. package/dist/catalog/catalog-scope.service.js +22 -73
  46. package/dist/catalog/cli.d.ts +0 -11
  47. package/dist/catalog/cli.js +0 -20
  48. package/dist/catalog/component-scope.service.js +0 -2
  49. package/dist/catalog/component-state.js +2 -2
  50. package/dist/catalog/install-status.d.ts +6 -0
  51. package/dist/catalog/install-status.js +6 -0
  52. package/dist/catalog/job-ids.d.ts +0 -4
  53. package/dist/catalog/job-ids.js +0 -4
  54. package/dist/catalog/marketplaces.service.d.ts +1 -1
  55. package/dist/catalog/org-catalog.service.d.ts +2 -0
  56. package/dist/catalog/org-catalog.service.js +8 -3
  57. package/dist/catalog/org-extension-switch.d.ts +7 -2
  58. package/dist/catalog/org-extension-switch.js +56 -9
  59. package/dist/catalog/org-plugin-uploads.d.ts +6 -15
  60. package/dist/catalog/org-plugin-uploads.js +9 -27
  61. package/dist/catalog/owned-items.js +1 -3
  62. package/dist/catalog/platform-import-update.js +1 -1
  63. package/dist/catalog/plugin-import.d.ts +15 -13
  64. package/dist/catalog/plugin-import.js +21 -30
  65. package/dist/catalog/plugin-install.d.ts +3 -43
  66. package/dist/catalog/plugin-install.js +8 -150
  67. package/dist/catalog/plugin-package.d.ts +5 -10
  68. package/dist/catalog/plugin-package.js +12 -33
  69. package/dist/catalog/plugin-upgrade.js +5 -4
  70. package/dist/catalog/scope-jobs.d.ts +34 -34
  71. package/dist/catalog/scope-jobs.js +50 -37
  72. package/dist/catalog/scope-orgs.d.ts +1 -1
  73. package/dist/catalog/scope-orgs.js +1 -2
  74. package/dist/catalog/scope-sync-workers.d.ts +4 -3
  75. package/dist/catalog/scope-sync-workers.js +18 -6
  76. package/dist/catalog/scope-sync.d.ts +56 -59
  77. package/dist/catalog/scope-sync.js +96 -166
  78. package/dist/catalog/unshare.d.ts +3 -4
  79. package/dist/catalog/unshare.js +5 -8
  80. package/dist/channels/job-ids.d.ts +2 -6
  81. package/dist/channels/job-ids.js +2 -6
  82. package/dist/channels/outbound.d.ts +1 -1
  83. package/dist/channels/outbound.js +1 -1
  84. package/dist/channels/supervisor.d.ts +2 -3
  85. package/dist/channels/supervisor.js +2 -3
  86. package/dist/client/client-access.service.js +1 -1
  87. package/dist/config/env.js +19 -1
  88. package/dist/config/load.d.ts +0 -6
  89. package/dist/config/load.js +8 -27
  90. package/dist/config/schema.d.ts +54 -47
  91. package/dist/config/schema.js +198 -42
  92. package/dist/conversations/attachments.service.d.ts +10 -3
  93. package/dist/conversations/attachments.service.js +49 -16
  94. package/dist/conversations/conversations.controller.d.ts +0 -39
  95. package/dist/conversations/conversations.controller.js +0 -39
  96. package/dist/conversations/event-log.js +4 -1
  97. package/dist/conversations/events.d.ts +71 -46
  98. package/dist/conversations/events.js +124 -112
  99. package/dist/conversations/media-types.d.ts +25 -0
  100. package/dist/conversations/media-types.js +38 -0
  101. package/dist/conversations/queue.d.ts +3 -1
  102. package/dist/conversations/queue.service.js +9 -2
  103. package/dist/conversations/titles.js +6 -0
  104. package/dist/ctx/create-ctx.d.ts +8 -1
  105. package/dist/ctx/create-ctx.js +13 -3
  106. package/dist/ctx/net.d.ts +50 -0
  107. package/dist/ctx/net.js +67 -0
  108. package/dist/ctx/secrets.d.ts +24 -7
  109. package/dist/ctx/secrets.js +97 -30
  110. package/dist/db/kernel-schema.d.ts +27 -6
  111. package/dist/devices/devices.service.js +2 -1
  112. package/dist/errors.d.ts +10 -2
  113. package/dist/errors.js +10 -2
  114. package/dist/evals/reconstruct.d.ts +4 -17
  115. package/dist/evals/reconstruct.js +13 -53
  116. package/dist/evals/recorded-tools.d.ts +0 -27
  117. package/dist/evals/recorded-tools.js +2 -92
  118. package/dist/evals/run-replay.d.ts +1 -6
  119. package/dist/evals/run-replay.js +10 -17
  120. package/dist/evals/sets.service.d.ts +17 -5
  121. package/dist/evals/sets.service.js +33 -12
  122. package/dist/evals/snapshot.d.ts +1 -2
  123. package/dist/evals/snapshot.js +4 -17
  124. package/dist/extensions/admin-ops.d.ts +6 -1
  125. package/dist/extensions/admin-ops.js +17 -4
  126. package/dist/extensions/admin-view.d.ts +7 -4
  127. package/dist/extensions/admin-view.js +27 -21
  128. package/dist/extensions/bootstrap.js +0 -1
  129. package/dist/extensions/cli.js +0 -1
  130. package/dist/extensions/extensions.module.js +3 -0
  131. package/dist/extensions/host.d.ts +9 -4
  132. package/dist/extensions/host.js +14 -8
  133. package/dist/extensions/installs.d.ts +1 -3
  134. package/dist/extensions/instance.d.ts +0 -2
  135. package/dist/extensions/instance.js +0 -3
  136. package/dist/extensions/org-config.d.ts +4 -4
  137. package/dist/extensions/org-config.js +13 -22
  138. package/dist/extensions/package.d.ts +6 -6
  139. package/dist/extensions/package.js +3 -7
  140. package/dist/extensions/permission-view.d.ts +2 -4
  141. package/dist/extensions/plugin-items.d.ts +21 -1
  142. package/dist/extensions/plugin-items.js +28 -0
  143. package/dist/extensions/sync.js +5 -10
  144. package/dist/extensions/unavailable.js +0 -1
  145. package/dist/http/api.module.js +4 -1
  146. package/dist/identity/audit.d.ts +0 -12
  147. package/dist/identity/audit.js +0 -27
  148. package/dist/identity/auth.controller.js +5 -9
  149. package/dist/identity/cookies.d.ts +4 -9
  150. package/dist/identity/cookies.js +8 -32
  151. package/dist/identity/initial-passwords.d.ts +1 -1
  152. package/dist/identity/initial-passwords.js +1 -2
  153. package/dist/identity/sessions.d.ts +0 -6
  154. package/dist/identity/sessions.js +0 -18
  155. package/dist/inbox/platform-inbox.service.d.ts +33 -1
  156. package/dist/inbox/platform-inbox.service.js +56 -6
  157. package/dist/index.d.ts +4 -2
  158. package/dist/index.js +4 -2
  159. package/dist/infra/cli/master-key-rewrap.d.ts +15 -0
  160. package/dist/infra/cli/master-key-rewrap.js +24 -0
  161. package/dist/infra/config/kernel-config.service.js +0 -17
  162. package/dist/infra/database/transaction-host.d.ts +32 -1
  163. package/dist/infra/database/transaction-host.js +30 -4
  164. package/dist/infra/database/xact-lock.d.ts +16 -0
  165. package/dist/infra/database/xact-lock.js +28 -1
  166. package/dist/infra/health/health.controller.js +8 -0
  167. package/dist/infra/health/process-fault.d.ts +16 -0
  168. package/dist/infra/health/process-fault.js +49 -0
  169. package/dist/infra/lifecycle/process-guards.d.ts +8 -2
  170. package/dist/infra/lifecycle/process-guards.js +12 -3
  171. package/dist/infra/lifecycle/shutdown-signals.d.ts +10 -1
  172. package/dist/infra/lifecycle/shutdown-signals.js +28 -13
  173. package/dist/infra/outbox/outbox.service.d.ts +12 -9
  174. package/dist/infra/outbox/outbox.service.js +22 -26
  175. package/dist/infra/outbox/registry.d.ts +15 -7
  176. package/dist/infra/outbox/registry.js +39 -23
  177. package/dist/lifecycle/kernel-lifecycle.js +1 -7
  178. package/dist/models/enablement.d.ts +5 -6
  179. package/dist/models/enablement.js +7 -14
  180. package/dist/net/public-address.d.ts +21 -1
  181. package/dist/net/public-address.js +56 -10
  182. package/dist/net/safe-fetch.d.ts +4 -1
  183. package/dist/net/safe-fetch.js +15 -4
  184. package/dist/orgs/directory-sync.js +2 -0
  185. package/dist/orgs/members.service.js +5 -0
  186. package/dist/orgs/network-allowances.service.d.ts +79 -0
  187. package/dist/orgs/network-allowances.service.js +371 -0
  188. package/dist/orgs/offboarding.d.ts +3 -1
  189. package/dist/orgs/offboarding.js +9 -2
  190. package/dist/orgs/org-lock.d.ts +28 -2
  191. package/dist/orgs/org-lock.js +59 -4
  192. package/dist/orgs/orgs.controller.d.ts +11 -2
  193. package/dist/orgs/orgs.controller.js +19 -3
  194. package/dist/orgs/orgs.module.d.ts +3 -2
  195. package/dist/orgs/orgs.module.js +6 -2
  196. package/dist/orgs/orgs.schemas.d.ts +12 -0
  197. package/dist/orgs/orgs.schemas.js +5 -0
  198. package/dist/orgs/orgs.service.js +6 -1
  199. package/dist/orgs/settings.controller.d.ts +3 -2
  200. package/dist/orgs/settings.service.d.ts +59 -14
  201. package/dist/orgs/settings.service.js +102 -20
  202. package/dist/overrides.d.ts +7 -7
  203. package/dist/overrides.js +4 -4
  204. package/dist/packages/tgz.d.ts +0 -2
  205. package/dist/packages/tgz.js +0 -2
  206. package/dist/platform/exclusions.js +0 -5
  207. package/dist/platform/operation.js +1 -1
  208. package/dist/platform/ops/admin.ops.d.ts +2 -2
  209. package/dist/platform/ops/admin.ops.js +9 -6
  210. package/dist/platform/ops/agents.ops.js +1 -1
  211. package/dist/platform/ops/connectors.ops.js +46 -1
  212. package/dist/platform/ops/evals.ops.js +1 -64
  213. package/dist/platform/ops/extensions-admin.ops.js +1 -1
  214. package/dist/platform/ops/inbox.ops.js +16 -3
  215. package/dist/platform/ops/org-plugins.ops.js +1 -1
  216. package/dist/platform/ops/orgs.ops.d.ts +11 -3
  217. package/dist/platform/ops/orgs.ops.js +139 -5
  218. package/dist/platform/ops/outbox.ops.js +5 -5
  219. package/dist/platform/route-schemas.js +3 -0
  220. package/dist/roles/worker-role.d.ts +2 -3
  221. package/dist/roles/worker-role.js +3 -13
  222. package/dist/runtime/checkpointer.d.ts +3 -0
  223. package/dist/runtime/checkpointer.js +7 -4
  224. package/dist/runtime/context/build.d.ts +56 -18
  225. package/dist/runtime/context/build.js +143 -50
  226. package/dist/runtime/context/compaction.d.ts +1 -3
  227. package/dist/runtime/context/compaction.js +42 -8
  228. package/dist/runtime/context/run-context.js +1 -2
  229. package/dist/runtime/context/skills.d.ts +27 -56
  230. package/dist/runtime/context/skills.js +42 -114
  231. package/dist/runtime/context/tool-changes.d.ts +3 -3
  232. package/dist/runtime/context/tool-changes.js +6 -16
  233. package/dist/runtime/hook-calls.d.ts +6 -6
  234. package/dist/runtime/hook-calls.js +7 -7
  235. package/dist/runtime/langgraph-loop.js +9 -3
  236. package/dist/runtime/maintenance.d.ts +3 -11
  237. package/dist/runtime/maintenance.js +5 -20
  238. package/dist/runtime/model-call.d.ts +5 -0
  239. package/dist/runtime/model-call.js +48 -36
  240. package/dist/runtime/providers.d.ts +33 -35
  241. package/dist/runtime/providers.js +64 -109
  242. package/dist/runtime/run-context.service.js +7 -22
  243. package/dist/runtime/run-deletion.d.ts +6 -0
  244. package/dist/runtime/run-deletion.js +39 -16
  245. package/dist/runtime/run-execution.d.ts +56 -3
  246. package/dist/runtime/run-execution.js +81 -11
  247. package/dist/runtime/run-finish.js +2 -1
  248. package/dist/runtime/run-liveness.d.ts +11 -0
  249. package/dist/runtime/run-liveness.js +19 -0
  250. package/dist/runtime/run-orphan-check.job.js +2 -1
  251. package/dist/runtime/run-queue.js +8 -16
  252. package/dist/runtime/run-worker.d.ts +2 -2
  253. package/dist/runtime/run-worker.js +8 -6
  254. package/dist/runtime/step-log.d.ts +5 -0
  255. package/dist/runtime/step-log.js +9 -4
  256. package/dist/runtime/subagents/definition.d.ts +16 -20
  257. package/dist/runtime/subagents/definition.js +27 -27
  258. package/dist/runtime/subagents/dispatch.d.ts +6 -2
  259. package/dist/runtime/subagents/dispatch.js +17 -3
  260. package/dist/runtime/subagents/org-agents.js +1 -2
  261. package/dist/runtime/subagents/preamble.d.ts +3 -2
  262. package/dist/runtime/subagents/preamble.js +3 -2
  263. package/dist/runtime/subagents/render.d.ts +1 -2
  264. package/dist/runtime/subagents/render.js +1 -2
  265. package/dist/runtime/subagents/skill-fork.d.ts +2 -4
  266. package/dist/runtime/subagents/template-skills.d.ts +47 -0
  267. package/dist/runtime/subagents/template-skills.js +76 -0
  268. package/dist/runtime/waits.js +3 -1
  269. package/dist/schedules/effective-settings.d.ts +9 -3
  270. package/dist/schedules/effective-settings.js +5 -4
  271. package/dist/schedules/fire.js +11 -0
  272. package/dist/schedules/scheduled-tasks.service.js +5 -0
  273. package/dist/schedules/unattended.d.ts +2 -0
  274. package/dist/schedules/unattended.js +6 -1
  275. package/dist/skills/agent-skills.service.js +1 -2
  276. package/dist/skills/catalog.d.ts +1 -3
  277. package/dist/skills/catalog.js +1 -3
  278. package/dist/skills/conversation-catalog.d.ts +1 -2
  279. package/dist/skills/conversation-catalog.js +1 -2
  280. package/dist/skills/usable.js +2 -3
  281. package/dist/storage/storage.service.js +9 -1
  282. package/dist/tools/approvals.service.js +2 -4
  283. package/dist/tools/builtin-names.d.ts +2 -9
  284. package/dist/tools/builtin-names.js +4 -13
  285. package/dist/tools/builtins/sandbox/bash.js +3 -3
  286. package/dist/tools/builtins/sandbox/common.d.ts +7 -13
  287. package/dist/tools/builtins/sandbox/common.js +8 -115
  288. package/dist/tools/builtins/sandbox/fetch-attachment.d.ts +10 -0
  289. package/dist/tools/builtins/sandbox/fetch-attachment.js +119 -0
  290. package/dist/tools/builtins/sandbox/glob.js +1 -3
  291. package/dist/tools/builtins/sandbox/grep.js +3 -5
  292. package/dist/tools/builtins/sandbox/index.d.ts +8 -5
  293. package/dist/tools/builtins/sandbox/index.js +10 -5
  294. package/dist/tools/builtins/sandbox/read.js +3 -2
  295. package/dist/tools/builtins/tool-search.d.ts +4 -7
  296. package/dist/tools/builtins/tool-search.js +6 -10
  297. package/dist/tools/connector-account-policies.d.ts +30 -3
  298. package/dist/tools/connector-account-policies.js +54 -7
  299. package/dist/tools/connector-content.js +1 -0
  300. package/dist/tools/connectors.controller.d.ts +24 -11
  301. package/dist/tools/connectors.controller.js +35 -6
  302. package/dist/tools/connectors.schemas.d.ts +14 -1
  303. package/dist/tools/connectors.schemas.js +14 -2
  304. package/dist/tools/connectors.service.d.ts +22 -0
  305. package/dist/tools/connectors.service.js +65 -6
  306. package/dist/tools/drift.d.ts +6 -2
  307. package/dist/tools/drift.js +10 -5
  308. package/dist/tools/git-push-policy.d.ts +4 -1
  309. package/dist/tools/git-push-policy.js +3 -1
  310. package/dist/tools/info.d.ts +1 -7
  311. package/dist/tools/info.js +5 -18
  312. package/dist/tools/job-ids.d.ts +0 -4
  313. package/dist/tools/job-ids.js +1 -6
  314. package/dist/tools/pipeline.d.ts +4 -10
  315. package/dist/tools/pipeline.js +17 -62
  316. package/dist/tools/policy.d.ts +6 -2
  317. package/dist/tools/policy.js +14 -12
  318. package/dist/tools/registry.js +1 -5
  319. package/dist/ui/views.d.ts +5 -5
  320. package/dist/ui/views.js +10 -16
  321. package/package.json +3 -3
  322. package/src/migrations/0137_audit_org_idx.sql +5 -0
  323. package/src/migrations/0138_plugin_install_status_no_upgrading.sql +18 -0
  324. package/src/migrations/0139_retire_legacy_forms.sql +183 -0
  325. package/src/migrations/0140_retire_history_forms.sql +148 -0
  326. package/src/migrations/0141_install_ledger_promoted_rows.sql +36 -0
  327. package/src/migrations/0142_backfill_event_fields.sql +74 -0
  328. package/src/migrations/0143_backfill_model_call_fields.sql +105 -0
  329. package/src/migrations/0144_retire_frozen_definition_keys.sql +163 -0
  330. package/src/migrations/0145_org_network_allowances.sql +12 -0
  331. package/dist/admin/platform-audit.service.d.ts +0 -41
  332. package/dist/conversations/job-ids.d.ts +0 -6
  333. package/dist/conversations/job-ids.js +0 -6
  334. package/dist/extensions/job-ids.d.ts +0 -6
  335. package/dist/extensions/job-ids.js +0 -6
  336. package/dist/infra/queue/retired-schedulers.d.ts +0 -7
  337. package/dist/infra/queue/retired-schedulers.js +0 -9
  338. package/dist/orgs/job-ids.d.ts +0 -8
  339. package/dist/orgs/job-ids.js +0 -8
  340. package/dist/runtime/context/legacy-text.d.ts +0 -22
  341. package/dist/runtime/context/legacy-text.js +0 -37
  342. package/dist/runtime/job-ids.d.ts +0 -10
  343. package/dist/runtime/job-ids.js +0 -10
  344. package/dist/runtime/retired-schedulers.d.ts +0 -7
  345. package/dist/runtime/retired-schedulers.js +0 -31
  346. package/dist/storage/job-ids.d.ts +0 -6
  347. package/dist/storage/job-ids.js +0 -6
  348. package/dist/tools/legacy-data.d.ts +0 -34
  349. package/dist/tools/legacy-data.js +0 -76
  350. package/dist/tools/legacy-keys.d.ts +0 -51
  351. package/dist/tools/legacy-keys.js +0 -114
@@ -5,8 +5,6 @@ import { planningBounds } from "./fit.js";
5
5
  import { scheduleHeader, senderTranscriptLabel } from "./run-context.js";
6
6
  import { estimateTokens } from "./tokens.js";
7
7
  import { toolsChangedText } from "./tool-changes.js";
8
- /** 压缩请求的标记:放在 system 中,便于识别(model-fake 据此返回摘要)。 */
9
- export const COMPACTION_MARKER = "CAPYBARA_COMPACTION";
10
8
  /**
11
9
  * The summary request's output cap when the caller gives none: the built-in default of the
12
10
  * `compaction.maxOutputTokens` setting (context compaction spec §4.8). The effective setting is
@@ -22,7 +20,6 @@ const MIN_SUMMARY_RATIO = 0.05;
22
20
  * with nine sections; only the `<summary>` is stored and sent again in later requests.
23
21
  */
24
22
  const COMPACTION_INSTRUCTION = [
25
- COMPACTION_MARKER,
26
23
  "You are summarizing the earlier part of a conversation between people and an AI agent, so the agent can continue without the full history.",
27
24
  "If the transcript starts with an earlier summary, merge it into your summary.",
28
25
  "Write in the same language as the conversation.",
@@ -201,7 +198,7 @@ export function openingSeqs(events, runId, coversUpToSeq, absorbedUpToSeq = Numb
201
198
  return [];
202
199
  const first = sorted.find((e) => e.type === "model_call" && e.runId === runId && e.seq > start.seq);
203
200
  const upTo = first?.type === "model_call"
204
- ? Math.min(first.payload.request.absorbedUpToSeq ?? first.seq, first.seq)
201
+ ? Math.min(first.payload.request.absorbedUpToSeq, first.seq)
205
202
  : absorbedUpToSeq;
206
203
  let floor = Number.NEGATIVE_INFINITY;
207
204
  for (const e of sorted) {
@@ -210,7 +207,7 @@ export function openingSeqs(events, runId, coversUpToSeq, absorbedUpToSeq = Numb
210
207
  if (e.type === "assistant_message")
211
208
  floor = Math.max(floor, e.seq);
212
209
  else if (e.type === "model_call") {
213
- floor = Math.max(floor, e.payload.request.absorbedUpToSeq ?? e.seq);
210
+ floor = Math.max(floor, e.payload.request.absorbedUpToSeq);
214
211
  }
215
212
  }
216
213
  return sorted
@@ -297,7 +294,7 @@ function transcriptLine(e) {
297
294
  // scheduled tasks spec §12: the header the request shows, so the summary keeps the origin
298
295
  const schedule = e.payload.schedule;
299
296
  const text = schedule === undefined ? body : `${scheduleHeader(schedule)} ${body}`;
300
- // run context spec §5: the sender as logged (older logs have none: unchanged)
297
+ // run context spec §5: the sender as logged (a sub-agent task has none: unchanged)
301
298
  const sender = e.payload.sender;
302
299
  return sender !== undefined
303
300
  ? `User (${senderTranscriptLabel(sender)}): ${text}`
@@ -329,8 +326,44 @@ function transcriptLine(e) {
329
326
  // stale names should not be summarised as current
330
327
  case "tool_result":
331
328
  return `Tool result ${e.payload.toolKey}${e.payload.isError ? " (error)" : ""}: ${e.payload.content}`;
332
- default:
329
+ // Every other event type is left out of the transcript: not model-visible, or re-rendered
330
+ // after the summary (build.ts). Adding an event type fails typecheck until it is listed.
331
+ case "model_call":
332
+ case "run_started":
333
+ case "usage":
334
+ case "device_paths":
335
+ case "project_root":
336
+ case "run_context":
337
+ case "plugin_context":
338
+ case "tool_call_started":
339
+ case "connection_required":
340
+ case "approval_requested":
341
+ case "approval_decided":
342
+ case "approval_updated":
343
+ case "question_asked":
344
+ case "question_answered":
345
+ case "media_excluded":
346
+ case "artifact_created":
347
+ case "skills_catalog":
348
+ case "hook_denied":
349
+ case "network_blocked":
350
+ case "device_code":
351
+ case "model_switched":
352
+ case "subagent_started":
353
+ case "subagent_dispatched":
354
+ case "subagent_waiting":
355
+ case "subagent_finished":
356
+ case "compaction_summary":
357
+ case "compaction_failed":
358
+ case "run_finished":
359
+ case "run_aborted":
360
+ case "run_failed":
333
361
  return null;
362
+ default: {
363
+ const unrendered = e;
364
+ void unrendered;
365
+ return null;
366
+ }
334
367
  }
335
368
  }
336
369
  /**
@@ -470,7 +503,7 @@ function splitLine(line, max) {
470
503
  return pieces;
471
504
  }
472
505
  /**
473
- * The summary request: the marked English instruction as the system prompt and the transcript as
506
+ * The summary request: the English instruction (request `purpose: "compaction"`) as the system prompt and the transcript as
474
507
  * the only user message. `maxOutputTokens` is the effective `compaction.maxOutputTokens` setting,
475
508
  * which the caller narrows to the model's own cap (context compaction spec §4.8); omitted, it is
476
509
  * the built-in default.
@@ -488,6 +521,7 @@ export function buildCompactionRequest(transcript, model, maxOutputTokens = COMP
488
521
  tools: [],
489
522
  maxOutputTokens,
490
523
  params: {},
524
+ purpose: "compaction",
491
525
  };
492
526
  }
493
527
  /** Estimated input tokens of a plain text (a user message carries nothing else). */
@@ -104,8 +104,7 @@ export function runContextChange(prev, next) {
104
104
  }
105
105
  if (next.attribution !== undefined &&
106
106
  !sameAttribution(prev.attribution, next.attribution) &&
107
- // an all-empty value writes nothing when there was nothing to turn off (absence means "none",
108
- // so a conversation that never has an attribution stays as old logs are)
107
+ // an all-empty value writes nothing when there was nothing to turn off (absence means "none")
109
108
  (hasAttribution(next.attribution) || hasAttribution(prev.attribution))) {
110
109
  out.attribution = next.attribution;
111
110
  }
@@ -7,32 +7,26 @@ import type { ConversationEvent, EventPayload } from "../../conversations/events
7
7
  export type CatalogSkill = EventPayload<"skills_catalog">["skills"][number];
8
8
  /** The whole `skills_catalog` payload. */
9
9
  export type SkillsSnapshot = EventPayload<"skills_catalog">;
10
- /** A pinned skill in a snapshot (phase B, spec §9.1). */
11
- export type PinnedSkill = NonNullable<SkillsSnapshot["pinned"]>[number];
12
10
  /** 日志里的 `skills_catalog` 事件。 */
13
11
  export type SkillsCatalogEvent = Extract<ConversationEvent, {
14
12
  type: "skills_catalog";
15
13
  }>;
16
14
  /**
17
- * The model-visible skills texts that name the skill-loading builtin. A request recorded before the
18
- * tool rename renders {@link LEGACY_SKILL_TEXTS} instead (`./legacy-text.ts`, chosen from the
19
- * request's tools by `usesLegacyToolNames`), so its system text stays as it was sent.
15
+ * The model-visible skills texts that name the skill-loading builtin:
16
+ * - `skillsCatalogHeader`: the header of the first catalog (in the system cache segment);
17
+ * - `newSkills` / `updatedSkills`: the headings of the added and updated skills in a change notice;
18
+ * - `currentSkills`: the heading of the current catalog after a compaction summary;
19
+ * - `invokedSkills`: the line restored after a compaction summary for the skills invoked in its
20
+ * range (`names` non-empty): a person's invocations and the template skills the kernel wrote as
21
+ * invocations at a child's start (`user_message.skill.template`), so it names no invoker.
20
22
  */
21
- export interface SkillTexts {
22
- /** The header of the first catalog (in the system cache segment). */
23
+ export declare const SKILL_TEXTS: Readonly<{
23
24
  skillsCatalogHeader: string;
24
- /** The heading of the added skills in a change notice. */
25
- newSkills: string;
26
- /** The heading of the updated skills in a change notice. */
27
- updatedSkills: string;
28
- /** The heading of the current catalog after a compaction summary. */
25
+ newSkills: "New skills (call Skill with the name to use one):";
26
+ updatedSkills: "Updated skills (call Skill again before relying on earlier instructions):";
29
27
  currentSkills: string;
30
- /** The line restored after a compaction summary for the invoked skills (`names` non-empty). */
31
28
  invokedSkills: (names: readonly string[]) => string;
32
- /** The header of the pinned skills in the system cache segment. */
33
- pinnedSkillsHeader: string;
34
- }
35
- export declare const SKILL_TEXTS: SkillTexts;
29
+ }>;
36
30
  /** 目录开头的说明(system 缓存段里的第一份目录)。 */
37
31
  export declare const SKILLS_CATALOG_HEADER: string;
38
32
  /** 目录里每个技能描述最多的码点数(超出确定地截断;`Skill` 仍返回完整正文)。 */
@@ -43,28 +37,19 @@ export declare const catalogLine: (s: Pick<CatalogSkill, "name" | "description">
43
37
  * The heading of the name-only entries of a listing (skills default-on spec §7): the entries a
44
38
  * snapshot recorded past the catalog budget (`nameOnly`). Every listing (the system catalog, a
45
39
  * change notice's new or updated skills, the current catalog after a compaction) puts them after
46
- * its described lines under this heading, names in code point order joined by ", ". Introduced
47
- * with phase 2: no request before it has a name-only entry, so the legacy texts need no copy.
40
+ * its described lines under this heading, names in code point order joined by ", ".
48
41
  */
49
42
  export declare const MORE_SKILLS_HEADER: string;
50
43
  /** 第一份目录(进 system 缓存段),按名字排序。 */
51
- export declare function skillsCatalogText(skills: readonly CatalogSkill[], texts?: SkillTexts): string;
44
+ export declare function skillsCatalogText(skills: readonly CatalogSkill[]): string;
52
45
  /**
53
46
  * 两份快照是否相同(按 id、版本、名字、描述与来源)。顺序无关。 Also by `nameOnly` (absent = false):
54
47
  * an entry crossing the catalog budget writes a new snapshot and reads as updated.
55
48
  */
56
49
  export declare function sameSkills(a: readonly CatalogSkill[], b: readonly CatalogSkill[]): boolean;
57
50
  /**
58
- * Two pinned lists are the same: id, version and source in order (absent = []). Bodies follow the
59
- * source. The order counts, so a reordered `skills.pinned` writes a new snapshot; that snapshot
60
- * renders no message ({@link pinnedChangeText} is "" and the catalog part is skipped), and only the
61
- * system segment of a new conversation or a compaction restore shows the new order. This is
62
- * deliberate and consistent from the log: do not "fix" the missing message.
63
- */
64
- export declare function samePinned(a: readonly PinnedSkill[] | undefined, b: readonly PinnedSkill[] | undefined): boolean;
65
- /**
66
- * Two snapshots are the same: {@link sameSkills} (`plugin` is not compared, so a snapshot written
67
- * before phase B stays current), {@link samePinned} and the same `toolMap` (absent = undefined).
51
+ * Two snapshots are the same: {@link sameSkills} (`plugin` is not compared) and the same `toolMap`
52
+ * (absent = undefined).
68
53
  */
69
54
  export declare function sameSnapshot(a: SkillsSnapshot, b: SkillsSnapshot): boolean;
70
55
  /**
@@ -72,14 +57,15 @@ export declare function sameSnapshot(a: SkillsSnapshot, b: SkillsSnapshot): bool
72
57
  * 试用草稿被拒绝 / 批准了别人的同号版本时,内容变了而版本号可能不变)。
73
58
  * `prev` 为上一份快照(没有为空)。
74
59
  */
75
- export declare function skillsChangeText(prev: readonly CatalogSkill[], next: readonly CatalogSkill[], pinnedIds?: ReadonlySet<string>, texts?: SkillTexts): string;
60
+ export declare function skillsChangeText(prev: readonly CatalogSkill[], next: readonly CatalogSkill[]): string;
76
61
  /** 压缩摘要之后补上的「当前目录」(与 system 里的第一份不同时):完整列出,替代之前的目录与提醒。 */
77
- export declare function skillsCurrentText(skills: readonly CatalogSkill[], texts?: SkillTexts): string;
62
+ export declare function skillsCurrentText(skills: readonly CatalogSkill[]): string;
78
63
  /**
79
64
  * The line restored after a compaction summary whose range holds inline skill invocations
80
- * (`names`: distinct, code point order); empty for none. Bodies are not re-injected.
65
+ * (`names`: distinct, code point order; a person's and the template skills the kernel wrote as
66
+ * invocations); empty for none. Bodies are not re-injected.
81
67
  */
82
- export declare function invokedSkillsText(names: readonly string[], texts?: SkillTexts): string;
68
+ export declare function invokedSkillsText(names: readonly string[]): string;
83
69
  /** The distinct names (code point order) of the inline invocations in `events` up to `upToSeq`. */
84
70
  export declare function invokedSkillNames(events: readonly ConversationEvent[], upToSeq: number): string[];
85
71
  /** A skill a person invoked: the version recorded in their message. */
@@ -104,33 +90,18 @@ export declare function latestSkillsCatalog(events: readonly ConversationEvent[]
104
90
  * 改为在所在位置追加提醒,已发送的前缀不变)。没有为 null。
105
91
  */
106
92
  export declare function systemSkillsCatalog(events: readonly ConversationEvent[]): SkillsCatalogEvent | null;
107
- /** The header of the pinned skills in the system cache segment. */
108
- export declare const PINNED_SKILLS_HEADER: string;
109
- /** One pinned skill with its body. */
110
- export declare function pinnedBlock(p: PinnedSkill): string;
111
- /** The pinned skills of the system snapshot (non-empty), after the catalog. */
112
- export declare function pinnedSystemText(pinned: readonly PinnedSkill[], texts?: SkillTexts): string;
113
- /**
114
- * The pinned change notice between two snapshots ({@link samePinned} false): each entry that is new
115
- * or has another version or source, with its whole body; then the names of the removed ones.
116
- * Empty when nothing changed.
117
- */
118
- export declare function pinnedChangeText(prev: readonly PinnedSkill[] | undefined, next: readonly PinnedSkill[] | undefined): string;
119
- /** The pinned skills after a compaction summary, when they differ from the system snapshot's. */
120
- export declare function pinnedCurrentText(pinned: readonly PinnedSkill[] | undefined): string;
121
93
  /** The tool-name map change notice (the map differs from the previous one). */
122
94
  export declare function toolMapChangeText(next: string | undefined): string;
123
95
  /**
124
96
  * The one system message of a later snapshot: the catalog change (when the skills differ, or when
125
- * nothing else differs: logs before phase B render exactly as before), the pinned change, the
126
- * tool-name map change; joined by blank lines.
97
+ * the map does not), the tool-name map change; joined by blank lines.
127
98
  */
128
- export declare function snapshotChangeText(prev: SkillsSnapshot | undefined, next: SkillsSnapshot, texts?: SkillTexts): string;
99
+ export declare function snapshotChangeText(prev: SkillsSnapshot | undefined, next: SkillsSnapshot): string;
129
100
  /**
130
101
  * What follows a compaction summary when the covered snapshot is not the system one: today's
131
- * current catalog (when the skills differ from the system snapshot's), the current pinned skills
132
- * (when they differ), the tool-name map (when it differs); joined by blank lines, "" for nothing.
102
+ * current catalog (when the skills differ from the system snapshot's) and the tool-name map (when
103
+ * it differs); joined by blank lines, "" for nothing.
133
104
  */
134
- export declare function snapshotCurrentText(system: SkillsSnapshot | undefined, covered: SkillsSnapshot, texts?: SkillTexts): string;
135
- /** The system snapshot's text after the agent's instructions: catalog, pinned skills, tool map. */
136
- export declare function snapshotSystemText(s: SkillsSnapshot, texts?: SkillTexts): string;
105
+ export declare function snapshotCurrentText(system: SkillsSnapshot | undefined, covered: SkillsSnapshot): string;
106
+ /** The system snapshot's text after the agent's instructions: the catalog, then the tool map. */
107
+ export declare function snapshotSystemText(s: SkillsSnapshot): string;
@@ -1,4 +1,13 @@
1
1
  import { SKILL_LOAD } from "../../tools/builtin-names.js";
2
+ /**
3
+ * The model-visible skills texts that name the skill-loading builtin:
4
+ * - `skillsCatalogHeader`: the header of the first catalog (in the system cache segment);
5
+ * - `newSkills` / `updatedSkills`: the headings of the added and updated skills in a change notice;
6
+ * - `currentSkills`: the heading of the current catalog after a compaction summary;
7
+ * - `invokedSkills`: the line restored after a compaction summary for the skills invoked in its
8
+ * range (`names` non-empty): a person's invocations and the template skills the kernel wrote as
9
+ * invocations at a child's start (`user_message.skill.template`), so it names no invoker.
10
+ */
2
11
  export const SKILL_TEXTS = Object.freeze({
3
12
  skillsCatalogHeader: "Skills are available in this conversation. A skill is a set of instructions, sometimes with " +
4
13
  "scripts or other files, for a specific kind of task. When a task matches a skill's description, " +
@@ -8,10 +17,7 @@ export const SKILL_TEXTS = Object.freeze({
8
17
  updatedSkills: `Updated skills (call ${SKILL_LOAD} again before relying on earlier instructions):`,
9
18
  currentSkills: "Skills available in this conversation now (this replaces any earlier list of skills; call " +
10
19
  `${SKILL_LOAD} with a name to read a skill's instructions):`,
11
- invokedSkills: (names) => `Skills the user invoked earlier in this conversation: ${names.join(", ")}. Call ${SKILL_LOAD} with a name to read its instructions again.`,
12
- pinnedSkillsHeader: "Pinned skills: the owner of this agent pinned these skills, so their instructions apply " +
13
- `throughout this conversation. Follow them without calling ${SKILL_LOAD}; call ${SKILL_LOAD} ` +
14
- "only to copy a pinned skill's files into the sandbox.",
20
+ invokedSkills: (names) => `Skills invoked earlier in this conversation: ${names.join(", ")}. Call ${SKILL_LOAD} with a name to read its instructions again.`,
15
21
  });
16
22
  /** 目录开头的说明(system 缓存段里的第一份目录)。 */
17
23
  export const SKILLS_CATALOG_HEADER = SKILL_TEXTS.skillsCatalogHeader;
@@ -33,8 +39,7 @@ export const catalogLine = (s) => `- ${s.name}: ${shortDescription(s.description
33
39
  * The heading of the name-only entries of a listing (skills default-on spec §7): the entries a
34
40
  * snapshot recorded past the catalog budget (`nameOnly`). Every listing (the system catalog, a
35
41
  * change notice's new or updated skills, the current catalog after a compaction) puts them after
36
- * its described lines under this heading, names in code point order joined by ", ". Introduced
37
- * with phase 2: no request before it has a name-only entry, so the legacy texts need no copy.
42
+ * its described lines under this heading, names in code point order joined by ", ".
38
43
  */
39
44
  export const MORE_SKILLS_HEADER = `More skills (names only; call ${SKILL_LOAD} with the name to read one):`;
40
45
  /**
@@ -55,8 +60,8 @@ function lines(skills) {
55
60
  return head === "" ? more : `${head}\n${more}`;
56
61
  }
57
62
  /** 第一份目录(进 system 缓存段),按名字排序。 */
58
- export function skillsCatalogText(skills, texts = SKILL_TEXTS) {
59
- return `${texts.skillsCatalogHeader}\n${lines(skills)}`;
63
+ export function skillsCatalogText(skills) {
64
+ return `${SKILL_TEXTS.skillsCatalogHeader}\n${lines(skills)}`;
60
65
  }
61
66
  /**
62
67
  * 两份快照是否相同(按 id、版本、名字、描述与来源)。顺序无关。 Also by `nameOnly` (absent = false):
@@ -79,34 +84,14 @@ export function sameSkills(a, b) {
79
84
  });
80
85
  }
81
86
  /**
82
- * Two pinned lists are the same: id, version and source in order (absent = []). Bodies follow the
83
- * source. The order counts, so a reordered `skills.pinned` writes a new snapshot; that snapshot
84
- * renders no message ({@link pinnedChangeText} is "" and the catalog part is skipped), and only the
85
- * system segment of a new conversation or a compaction restore shows the new order. This is
86
- * deliberate and consistent from the log: do not "fix" the missing message.
87
- */
88
- export function samePinned(a, b) {
89
- const x = a ?? [];
90
- const y = b ?? [];
91
- return (x.length === y.length &&
92
- x.every((p, i) => {
93
- const q = y[i];
94
- return q !== undefined && p.id === q.id && p.version === q.version && p.source === q.source;
95
- }));
96
- }
97
- /**
98
- * Two snapshots are the same: {@link sameSkills} (`plugin` is not compared, so a snapshot written
99
- * before phase B stays current), {@link samePinned} and the same `toolMap` (absent = undefined).
87
+ * Two snapshots are the same: {@link sameSkills} (`plugin` is not compared) and the same `toolMap`
88
+ * (absent = undefined).
100
89
  */
101
90
  export function sameSnapshot(a, b) {
102
- return (sameSkills(a.skills, b.skills) && samePinned(a.pinned, b.pinned) && a.toolMap === b.toolMap);
91
+ return sameSkills(a.skills, b.skills) && a.toolMap === b.toolMap;
103
92
  }
104
- /**
105
- * The catalog differences between two snapshots. `pinnedIds` (the next snapshot's pinned ids, phase
106
- * B) are left out of `updated`: a pinned skill's new body is rendered by {@link pinnedChangeText},
107
- * and the pinned header says not to call `Skill` for it.
108
- */
109
- function catalogChanges(prev, next, pinnedIds) {
93
+ /** The catalog differences between two snapshots. */
94
+ function catalogChanges(prev, next) {
110
95
  const before = new Map(prev.map((s) => [s.id, s]));
111
96
  const after = new Map(next.map((s) => [s.id, s]));
112
97
  // A skill renamed under its id (the platform components migration renames a clashing org skill)
@@ -121,7 +106,6 @@ function catalogChanges(prev, next, pinnedIds) {
121
106
  const p = before.get(s.id);
122
107
  return (p !== undefined &&
123
108
  p.name === s.name &&
124
- !pinnedIds?.has(s.id) &&
125
109
  (p.version !== s.version ||
126
110
  p.description !== s.description ||
127
111
  p.source !== s.source ||
@@ -134,14 +118,14 @@ function catalogChanges(prev, next, pinnedIds) {
134
118
  * 试用草稿被拒绝 / 批准了别人的同号版本时,内容变了而版本号可能不变)。
135
119
  * `prev` 为上一份快照(没有为空)。
136
120
  */
137
- export function skillsChangeText(prev, next, pinnedIds, texts = SKILL_TEXTS) {
138
- const { added, updated, removed } = catalogChanges(prev, next, pinnedIds);
121
+ export function skillsChangeText(prev, next) {
122
+ const { added, updated, removed } = catalogChanges(prev, next);
139
123
  const parts = ["The skills available in this conversation have changed."];
140
124
  if (added.length > 0) {
141
- parts.push(`${texts.newSkills}\n${lines(added)}`);
125
+ parts.push(`${SKILL_TEXTS.newSkills}\n${lines(added)}`);
142
126
  }
143
127
  if (updated.length > 0) {
144
- parts.push(`${texts.updatedSkills}\n${lines(updated)}`);
128
+ parts.push(`${SKILL_TEXTS.updatedSkills}\n${lines(updated)}`);
145
129
  }
146
130
  if (removed.length > 0) {
147
131
  parts.push(`Removed skills (no longer available; do not use them): ${[...removed]
@@ -154,21 +138,22 @@ export function skillsChangeText(prev, next, pinnedIds, texts = SKILL_TEXTS) {
154
138
  return parts.join("\n\n");
155
139
  }
156
140
  /** 压缩摘要之后补上的「当前目录」(与 system 里的第一份不同时):完整列出,替代之前的目录与提醒。 */
157
- export function skillsCurrentText(skills, texts = SKILL_TEXTS) {
141
+ export function skillsCurrentText(skills) {
158
142
  if (skills.length === 0) {
159
143
  return "No skills are available in this conversation now (this replaces any earlier list of skills).";
160
144
  }
161
- return `${texts.currentSkills}\n${lines(skills)}`;
145
+ return `${SKILL_TEXTS.currentSkills}\n${lines(skills)}`;
162
146
  }
163
- // ---- Skills a person invoked (phase D spec §4.4; model-visible, English) ----
147
+ // ---- Invoked skills (phase D spec §4.4; model-visible, English) ----
164
148
  /**
165
149
  * The line restored after a compaction summary whose range holds inline skill invocations
166
- * (`names`: distinct, code point order); empty for none. Bodies are not re-injected.
150
+ * (`names`: distinct, code point order; a person's and the template skills the kernel wrote as
151
+ * invocations); empty for none. Bodies are not re-injected.
167
152
  */
168
- export function invokedSkillsText(names, texts = SKILL_TEXTS) {
153
+ export function invokedSkillsText(names) {
169
154
  if (names.length === 0)
170
155
  return "";
171
- return texts.invokedSkills(names);
156
+ return SKILL_TEXTS.invokedSkills(names);
172
157
  }
173
158
  /** The distinct names (code point order) of the inline invocations in `events` up to `upToSeq`. */
174
159
  export function invokedSkillNames(events, upToSeq) {
@@ -225,48 +210,7 @@ export function systemSkillsCatalog(events) {
225
210
  const earlierCall = events.some((e) => e.type === "model_call" && e.seq < first.seq);
226
211
  return earlierCall ? null : first;
227
212
  }
228
- // ---- Pinned skills and the tool-name map (phase B, spec §9.1, §9.4; model-visible, English) ----
229
- /** The header of the pinned skills in the system cache segment. */
230
- export const PINNED_SKILLS_HEADER = SKILL_TEXTS.pinnedSkillsHeader;
231
- /** One pinned skill with its body. */
232
- export function pinnedBlock(p) {
233
- return `<pinned_skill name="${p.name}" version="${p.version}">\n${p.body.trim()}\n</pinned_skill>`;
234
- }
235
- /** The pinned skills of the system snapshot (non-empty), after the catalog. */
236
- export function pinnedSystemText(pinned, texts = SKILL_TEXTS) {
237
- return `${texts.pinnedSkillsHeader}\n\n${pinned.map(pinnedBlock).join("\n\n")}`;
238
- }
239
- /**
240
- * The pinned change notice between two snapshots ({@link samePinned} false): each entry that is new
241
- * or has another version or source, with its whole body; then the names of the removed ones.
242
- * Empty when nothing changed.
243
- */
244
- export function pinnedChangeText(prev, next) {
245
- const before = new Map((prev ?? []).map((p) => [p.id, p]));
246
- const after = new Set((next ?? []).map((p) => p.id));
247
- const parts = [];
248
- for (const p of next ?? []) {
249
- const was = before.get(p.id);
250
- if (was && was.version === p.version && was.source === p.source)
251
- continue;
252
- parts.push(`Pinned skill "${p.name}" (version ${p.version}) now applies to this conversation and ` +
253
- `replaces any previous version of it:\n\n${pinnedBlock(p)}`);
254
- }
255
- const removed = (prev ?? []).filter((p) => !after.has(p.id)).map((p) => p.name);
256
- if (removed.length > 0) {
257
- parts.push(`Pinned skills removed (their pinned instructions no longer apply): ${removed.join(", ")}`);
258
- }
259
- return parts.join("\n\n");
260
- }
261
- /** The pinned skills after a compaction summary, when they differ from the system snapshot's. */
262
- export function pinnedCurrentText(pinned) {
263
- if (!pinned || pinned.length === 0) {
264
- return "No skills are pinned now (this replaces any earlier pinned skills).";
265
- }
266
- return `Pinned skills now (this replaces any earlier pinned skills):\n\n${pinned
267
- .map(pinnedBlock)
268
- .join("\n\n")}`;
269
- }
213
+ // ---- The tool-name map (phase B, spec §9.4; model-visible, English) ----
270
214
  /** The tool-name map change notice (the map differs from the previous one). */
271
215
  export function toolMapChangeText(next) {
272
216
  return next === undefined
@@ -275,53 +219,37 @@ export function toolMapChangeText(next) {
275
219
  }
276
220
  /**
277
221
  * The one system message of a later snapshot: the catalog change (when the skills differ, or when
278
- * nothing else differs: logs before phase B render exactly as before), the pinned change, the
279
- * tool-name map change; joined by blank lines.
222
+ * the map does not), the tool-name map change; joined by blank lines.
280
223
  */
281
- export function snapshotChangeText(prev, next, texts = SKILL_TEXTS) {
224
+ export function snapshotChangeText(prev, next) {
282
225
  const prevSkills = prev?.skills ?? [];
283
- const pinnedDiff = !samePinned(prev?.pinned, next.pinned);
284
226
  const mapDiff = prev?.toolMap !== next.toolMap;
285
- // a snapshot with pinned skills leaves them out of the "Updated skills" list; when that leaves no
286
- // catalog change, the catalog text is skipped (the pinned change carries the message). Logs
287
- // without `pinned` render exactly as before.
288
- const pinnedIds = next.pinned && next.pinned.length > 0 ? new Set(next.pinned.map((p) => p.id)) : undefined;
289
- const c = catalogChanges(prevSkills, next.skills, pinnedIds);
290
- const catalogDiff = pinnedIds
291
- ? c.added.length + c.updated.length + c.removed.length > 0
292
- : !sameSkills(prevSkills, next.skills);
293
227
  const parts = [];
294
- if (catalogDiff || (!pinnedDiff && !mapDiff)) {
295
- parts.push(skillsChangeText(prevSkills, next.skills, pinnedIds, texts));
228
+ if (!sameSkills(prevSkills, next.skills) || !mapDiff) {
229
+ parts.push(skillsChangeText(prevSkills, next.skills));
296
230
  }
297
- if (pinnedDiff)
298
- parts.push(pinnedChangeText(prev?.pinned, next.pinned));
299
231
  if (mapDiff)
300
232
  parts.push(toolMapChangeText(next.toolMap));
301
- return parts.filter((p) => p !== "").join("\n\n");
233
+ return parts.join("\n\n");
302
234
  }
303
235
  /**
304
236
  * What follows a compaction summary when the covered snapshot is not the system one: today's
305
- * current catalog (when the skills differ from the system snapshot's), the current pinned skills
306
- * (when they differ), the tool-name map (when it differs); joined by blank lines, "" for nothing.
237
+ * current catalog (when the skills differ from the system snapshot's) and the tool-name map (when
238
+ * it differs); joined by blank lines, "" for nothing.
307
239
  */
308
- export function snapshotCurrentText(system, covered, texts = SKILL_TEXTS) {
240
+ export function snapshotCurrentText(system, covered) {
309
241
  const parts = [];
310
242
  if (!sameSkills(system?.skills ?? [], covered.skills)) {
311
- parts.push(skillsCurrentText(covered.skills, texts));
243
+ parts.push(skillsCurrentText(covered.skills));
312
244
  }
313
- if (!samePinned(system?.pinned, covered.pinned))
314
- parts.push(pinnedCurrentText(covered.pinned));
315
245
  if (system?.toolMap !== covered.toolMap) {
316
246
  parts.push(toolMapChangeText(covered.toolMap));
317
247
  }
318
248
  return parts.join("\n\n");
319
249
  }
320
- /** The system snapshot's text after the agent's instructions: catalog, pinned skills, tool map. */
321
- export function snapshotSystemText(s, texts = SKILL_TEXTS) {
322
- let text = skillsCatalogText(s.skills, texts);
323
- if (s.pinned && s.pinned.length > 0)
324
- text += `\n\n${pinnedSystemText(s.pinned, texts)}`;
250
+ /** The system snapshot's text after the agent's instructions: the catalog, then the tool map. */
251
+ export function snapshotSystemText(s) {
252
+ let text = skillsCatalogText(s.skills);
325
253
  if (s.toolMap !== undefined)
326
254
  text += `\n\n${s.toolMap}`;
327
255
  return text;
@@ -13,9 +13,9 @@ export type ToolsChange = Pick<EventPayload<"tools_changed">, "added" | "removed
13
13
  * `model_call`'s `tools` and `catalog` keys (with `ToolSearch` the catalog holds the deferred
14
14
  * tools, so the union is the whole resolved set), then any `tools_changed` logged after it (a
15
15
  * step that logged its change and crashed before its request: the change is not logged twice).
16
- * Skipped: a `model_call` without recorded tools (older logs) and a call whose tools were left out
17
- * because its model has no tool support (empty, with that step's unsupported reminder): those say
18
- * nothing about the resolved set. Null when no request offered a known set yet.
16
+ * Skipped: a call whose tools the kernel left out because its model has no tool support
17
+ * (`toolsOmitted`): it says nothing about the resolved set. Null when no request offered a known
18
+ * set yet.
19
19
  */
20
20
  export declare function previousToolSet(events: readonly ConversationEvent[]): Set<string> | null;
21
21
  /**
@@ -1,30 +1,20 @@
1
- import { TOOLS_UNSUPPORTED_REMINDER } from "./reminders.js";
2
1
  /**
3
2
  * The tool set the conversation's previous model request offered, from the log alone: the last
4
3
  * `model_call`'s `tools` and `catalog` keys (with `ToolSearch` the catalog holds the deferred
5
4
  * tools, so the union is the whole resolved set), then any `tools_changed` logged after it (a
6
5
  * step that logged its change and crashed before its request: the change is not logged twice).
7
- * Skipped: a `model_call` without recorded tools (older logs) and a call whose tools were left out
8
- * because its model has no tool support (empty, with that step's unsupported reminder): those say
9
- * nothing about the resolved set. Null when no request offered a known set yet.
6
+ * Skipped: a call whose tools the kernel left out because its model has no tool support
7
+ * (`toolsOmitted`): it says nothing about the resolved set. Null when no request offered a known
8
+ * set yet.
10
9
  */
11
10
  export function previousToolSet(events) {
12
- const unsupported = new Set();
13
- for (const e of events) {
14
- if (e.type === "reminder" && e.payload.text === TOOLS_UNSUPPORTED_REMINDER) {
15
- unsupported.add(`${e.runId ?? ""}\u0000${e.payload.step}`);
16
- }
17
- }
18
11
  let known = null;
19
12
  for (const e of events) {
20
13
  if (e.type === "model_call") {
21
- const { tools, catalog } = e.payload.request;
22
- if (tools === undefined)
23
- continue;
24
- const keys = [...tools, ...(catalog ?? [])].map((t) => t.key);
25
- if (keys.length === 0 && unsupported.has(`${e.runId ?? ""}\u0000${e.payload.step}`))
14
+ const { tools, catalog, toolsOmitted } = e.payload.request;
15
+ if (toolsOmitted === true)
26
16
  continue;
27
- known = new Set(keys);
17
+ known = new Set([...tools, ...(catalog ?? [])].map((t) => t.key));
28
18
  }
29
19
  else if (e.type === "tools_changed" && known !== null) {
30
20
  for (const k of e.payload.removed)
@@ -36,12 +36,12 @@ export declare function hookScope(hooks: HookRunner | undefined, s: {
36
36
  */
37
37
  export declare function fireObserve<K extends "model.response" | "tool.postExecute">(hooks: HookRunner, mount: K, payload: HookPayloads[K], signal: AbortSignal, log: Pick<Logger, "warn">): void;
38
38
  /**
39
- * The `model.request` payload's request (F10, I-3): the request sent to the provider with every image
40
- * and document block replaced by a {@link HookMediaPlaceholder} (`kind`, `mediaType`, decoded `size`),
41
- * so hook payloads carry neither media bytes nor attachment ids. Media never sits outside user
42
- * messages, but every message is projected anyway. Building the copy also keeps the per-call clone
43
- * and freeze of the payload small. A `ref` source should never reach here (the kernel resolves refs
44
- * before sending); it becomes a placeholder of size 0 and logs a warning.
39
+ * The `model.request` payload's request (F10, I-3): the request sent to the provider with every image,
40
+ * document and file block replaced by a {@link HookMediaPlaceholder} (`kind`, `mediaType`, decoded
41
+ * `size`), so hook payloads carry neither media bytes nor attachment ids. Media never sits outside
42
+ * user messages, but every message is projected anyway. Building the copy also keeps the per-call
43
+ * clone and freeze of the payload small. A `ref` source should never reach here (the kernel resolves
44
+ * refs before sending); it becomes a placeholder of size 0 and logs a warning.
45
45
  */
46
46
  export declare function hookRequestOf(request: ModelRequest, log?: Pick<Logger, "warn">): HookModelRequest;
47
47
  /** Where a denial is recorded (conversation, run, actor and the idem key of its `hook_denied`). */
@@ -43,17 +43,17 @@ const base64Bytes = (data) => {
43
43
  return Math.max(0, Math.floor(data.length / 4) * 3 - pad);
44
44
  };
45
45
  /**
46
- * The `model.request` payload's request (F10, I-3): the request sent to the provider with every image
47
- * and document block replaced by a {@link HookMediaPlaceholder} (`kind`, `mediaType`, decoded `size`),
48
- * so hook payloads carry neither media bytes nor attachment ids. Media never sits outside user
49
- * messages, but every message is projected anyway. Building the copy also keeps the per-call clone
50
- * and freeze of the payload small. A `ref` source should never reach here (the kernel resolves refs
51
- * before sending); it becomes a placeholder of size 0 and logs a warning.
46
+ * The `model.request` payload's request (F10, I-3): the request sent to the provider with every image,
47
+ * document and file block replaced by a {@link HookMediaPlaceholder} (`kind`, `mediaType`, decoded
48
+ * `size`), so hook payloads carry neither media bytes nor attachment ids. Media never sits outside
49
+ * user messages, but every message is projected anyway. Building the copy also keeps the per-call
50
+ * clone and freeze of the payload small. A `ref` source should never reach here (the kernel resolves
51
+ * refs before sending); it becomes a placeholder of size 0 and logs a warning.
52
52
  */
53
53
  export function hookRequestOf(request, log) {
54
54
  let refs = 0;
55
55
  const project = (b) => {
56
- if (b.type !== "image" && b.type !== "document")
56
+ if (b.type !== "image" && b.type !== "document" && b.type !== "file")
57
57
  return b;
58
58
  if (b.source.kind === "ref")
59
59
  refs++;