@bastani/atomic 0.10.9 → 0.10.10-alpha.2
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.
- package/CHANGELOG.md +83 -0
- package/README.md +226 -163
- package/dist/_shared/dist-KOELCESV.js +2 -2
- package/dist/_shared/fork-row-index-UAUAQRD5.js +2 -2
- package/dist/_shared/lib-4PES5P4V.js +2 -2
- package/dist/_shared/mode-interactive-sdk-7KXUFI2F.js +27 -12
- package/dist/_shared/mode-interactive-sdk-7KXUFI2F.js.map +1 -1
- package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js +47 -7
- package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js.map +1 -1
- package/dist/_shared/mode-shared-2QJSCUM6.js +48 -19
- package/dist/_shared/mode-shared-2QJSCUM6.js.map +1 -1
- package/dist/_shared/{p1a-prewarm-UQY3X2UK.js → p1a-prewarm-XIU57JHF.js} +5 -5
- package/dist/_shared/{p1a-prewarm-UQY3X2UK.js.map → p1a-prewarm-XIU57JHF.js.map} +1 -1
- package/dist/_shared/p2-shell-main-B2WIALFD.js +30 -25
- package/dist/_shared/p2-shell-main-B2WIALFD.js.map +1 -1
- package/dist/_shared/runtime-O4KCSG4C.js +5 -5
- package/dist/_shared/{sdk-OSBEPR3Q.js → sdk-RRLVN7ER.js} +15 -9
- package/dist/_shared/sdk-RRLVN7ER.js.map +1 -0
- package/dist/_shared/session-data-AHTU7IS6.js +2 -2
- package/dist/_shared/session-manager-list-2BLEEZVG.js +1 -1
- package/dist/_shared/settings-startup-8-DNZ2RIHM.js +4 -1
- package/dist/_shared/settings-startup-8-DNZ2RIHM.js.map +1 -1
- package/dist/_shared/{startup-0-0-TYUFUOJZ.js → startup-0-0-4VG2G44V.js} +427 -33
- package/dist/_shared/startup-0-0-4VG2G44V.js.map +1 -0
- package/dist/_shared/{startup-0-1-W2G2UY7R.js → startup-0-1-XTIL65D4.js} +18 -11
- package/dist/_shared/startup-0-1-XTIL65D4.js.map +1 -0
- package/dist/_shared/{startup-0-2-UXBUEOXW.js → startup-0-2-27OWFHV6.js} +150 -62
- package/dist/_shared/startup-0-2-27OWFHV6.js.map +1 -0
- package/dist/_shared/startup-0-3-T4DVFYWX.js +15 -25
- package/dist/_shared/startup-0-3-T4DVFYWX.js.map +1 -1
- package/dist/_shared/{startup-0-4-HN5EB4K7.js → startup-0-4-ZMJV547D.js} +81 -12
- package/dist/_shared/startup-0-4-ZMJV547D.js.map +1 -0
- package/dist/_shared/startup-0-5-FD2P735I.js +90 -50
- package/dist/_shared/startup-0-5-FD2P735I.js.map +1 -1
- package/dist/_shared/startup-10-0-TDQNBDDL.js +5 -5
- package/dist/_shared/startup-12-0-55AAXBJZ.js +13 -7
- package/dist/_shared/startup-12-0-55AAXBJZ.js.map +1 -1
- package/dist/_shared/startup-14-0-MLX36RBG.js +4 -4
- package/dist/_shared/startup-15-0-YUKGAC63.js +4 -4
- package/dist/_shared/startup-15-1-4S7FLMNG.js +88 -28
- package/dist/_shared/startup-15-1-4S7FLMNG.js.map +1 -1
- package/dist/_shared/startup-8-0-34CBHPZH.js +5 -5
- package/dist/_shared/startup-8-1-4KANEHRA.js +61 -17
- package/dist/_shared/startup-8-1-4KANEHRA.js.map +1 -1
- package/dist/_shared/storage-command-7MGXLJGZ.js +4 -4
- package/dist/_shared/task-unsaved-answer-VJ2KTB4V.js +2 -2
- package/dist/_shared/tree-outline-MUEPK5B7.js +2 -2
- package/dist/builtin/intercom/CHANGELOG.md +6 -0
- package/dist/builtin/intercom/README.md +87 -116
- package/dist/builtin/intercom/broker/broker.bundle.mjs +3 -3
- package/dist/builtin/intercom/broker/presence-handler.ts +1 -1
- package/dist/builtin/intercom/group.ts +7 -3
- package/dist/builtin/intercom/index.bundle.mjs +1 -1
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/README.md +61 -27
- package/dist/builtin/mcp/index.bundle.mjs +1 -1
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/CHANGELOG.md +8 -0
- package/dist/builtin/subagents/README.md +74 -141
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +213 -74
- package/dist/builtin/web-access/CHANGELOG.md +9 -0
- package/dist/builtin/web-access/README.md +61 -88
- package/dist/builtin/web-access/index.bundle.mjs +387 -351
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/cli/args.js +2 -2
- package/dist/cli/auth-cli.code.js +4 -4
- package/dist/cli/auth-cli.impl.js +3 -3
- package/dist/cli/auth-cli.js +3 -3
- package/dist/cli/blueprint-command.code.js +2 -2
- package/dist/cli/blueprint-command.impl.js +3 -3
- package/dist/cli/blueprint-command.js +3 -3
- package/dist/cli/intercom-command.code.js +3 -3
- package/dist/cli/intercom-command.impl.js +3 -3
- package/dist/cli/intercom-command.js +3 -3
- package/dist/cli/list-models.code.js +3 -3
- package/dist/cli/list-models.impl.js +3 -3
- package/dist/cli/list-models.js +3 -3
- package/dist/cli/session-picker.code.js +2 -2
- package/dist/cli/session-picker.impl.js +3 -3
- package/dist/cli/session-picker.js +3 -3
- package/dist/cli/startup-ui.code.js +2 -2
- package/dist/cli/startup-ui.impl.js +3 -3
- package/dist/cli/startup-ui.js +3 -3
- package/dist/cli/storage-command.impl.js +3 -3
- package/dist/cli/storage-command.js +3 -3
- package/dist/cli/storage-search-session.code.js +2 -2
- package/dist/cli/storage-search-session.impl.js +3 -3
- package/dist/cli/storage-search-session.js +3 -3
- package/dist/cli/team-command.code.js +2 -2
- package/dist/cli/team-command.impl.js +3 -3
- package/dist/cli/team-command.js +3 -3
- package/dist/cli.js +2 -2
- package/dist/core/agent-session-methods.d.ts +4 -1
- package/dist/core/agent-session-methods.js.map +1 -1
- package/dist/core/agent-session.d.ts +3 -0
- package/dist/core/compaction/compactor.d.ts +20 -14
- package/dist/core/compaction/errors.d.ts +120 -0
- package/dist/core/compaction/index.d.ts +1 -0
- package/dist/core/compaction/model-resolver.d.ts +2 -2
- package/dist/core/debug.impl.js +3 -3
- package/dist/core/debug.js +3 -3
- package/dist/core/export-html/card-projection.impl.js +3 -3
- package/dist/core/export-html/card-projection.js +3 -3
- package/dist/core/export-html/index.code.js +2 -2
- package/dist/core/export-html/index.impl.js +3 -3
- package/dist/core/export-html/index.js +3 -3
- package/dist/core/export-html/json-spans.impl.js +3 -3
- package/dist/core/export-html/json-spans.js +3 -3
- package/dist/core/export-html/oversized-render-inputs.impl.js +3 -3
- package/dist/core/export-html/oversized-render-inputs.js +3 -3
- package/dist/core/export-html/tool-renderer.code.js +1 -1
- package/dist/core/export-html/tool-renderer.impl.js +3 -3
- package/dist/core/export-html/tool-renderer.js +3 -3
- package/dist/core/extensions/api-types.d.ts +1 -1
- package/dist/core/extensions/api-types.js.map +1 -1
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/jiti-loader.impl.js +3 -3
- package/dist/core/extensions/jiti-loader.js +3 -3
- package/dist/core/extensions/jiti-static-loader.impl.js +3 -3
- package/dist/core/extensions/jiti-static-loader.js +3 -3
- package/dist/core/extensions/loader-host-modules.code.js +1 -1
- package/dist/core/extensions/loader-host-modules.impl.js +3 -3
- package/dist/core/extensions/loader-host-modules.js +3 -3
- package/dist/core/extensions/loader-virtual-modules.js +1 -1
- package/dist/core/extensions/provider-types.d.ts +18 -6
- package/dist/core/extensions/provider-types.js.map +1 -1
- package/dist/core/extensions/runner-context.js +1 -1
- package/dist/core/intercom-broker-control-host.code.js +1 -1
- package/dist/core/intercom-broker-control-host.impl.js +3 -3
- package/dist/core/intercom-broker-control-host.js +3 -3
- package/dist/core/intercom-broker-control.code.js +3 -3
- package/dist/core/intercom-broker-control.impl.js +3 -3
- package/dist/core/intercom-broker-control.js +3 -3
- package/dist/core/model-config.d.ts +40 -0
- package/dist/core/model-registry.js +1 -1
- package/dist/core/model-resolver-scope.d.ts +4 -4
- package/dist/core/model-runtime.d.ts +1 -1
- package/dist/core/package-manager-storage-adapters.impl.js +3 -3
- package/dist/core/package-manager-storage-adapters.js +3 -3
- package/dist/core/provider-composer-internal.d.ts +11 -2
- package/dist/core/sdk.code.js +3 -3
- package/dist/core/sdk.impl.js +3 -3
- package/dist/core/sdk.js +3 -3
- package/dist/core/session-manager-core.js +5 -5
- package/dist/core/session-manager-list.impl.js +3 -3
- package/dist/core/session-manager-list.js +3 -3
- package/dist/core/session-manager.code.js +1 -1
- package/dist/core/session-manager.impl.js +3 -3
- package/dist/core/session-manager.js +3 -3
- package/dist/core/session-storage.impl.js +3 -3
- package/dist/core/session-storage.js +3 -3
- package/dist/core/settings-manager-basic-accessors.d.ts +6 -2
- package/dist/core/storage/index.js +2 -2
- package/dist/core/storage/node-sqlite-thread.js +2 -2
- package/dist/core/storage/node-sqlite.js +2 -2
- package/dist/core/storage/offline-snapshot-file.impl.js +3 -3
- package/dist/core/storage/offline-snapshot-file.js +3 -3
- package/dist/core/storage/provider.js +2 -2
- package/dist/core/storage/selection.js +2 -2
- package/dist/core/storage/session/branch-fork-source.code.js +2 -2
- package/dist/core/storage/session/branch-fork-source.impl.js +3 -3
- package/dist/core/storage/session/branch-fork-source.js +3 -3
- package/dist/core/storage/session/card-view.impl.js +3 -3
- package/dist/core/storage/session/card-view.js +3 -3
- package/dist/core/storage/session/child-reader.code.js +3 -3
- package/dist/core/storage/session/child-reader.impl.js +3 -3
- package/dist/core/storage/session/child-reader.js +3 -3
- package/dist/core/storage/session/chunked-resume-projection.impl.js +3 -3
- package/dist/core/storage/session/chunked-resume-projection.js +3 -3
- package/dist/core/storage/session/expanded-child-details.code.js +2 -2
- package/dist/core/storage/session/expanded-child-details.impl.js +3 -3
- package/dist/core/storage/session/expanded-child-details.js +3 -3
- package/dist/core/storage/session/fork-row-bytes.impl.js +3 -3
- package/dist/core/storage/session/fork-row-bytes.js +3 -3
- package/dist/core/storage/session/fork-row-index.impl.js +3 -3
- package/dist/core/storage/session/fork-row-index.js +3 -3
- package/dist/core/storage/session/fork-staging.code.js +2 -2
- package/dist/core/storage/session/fork-staging.impl.js +3 -3
- package/dist/core/storage/session/fork-staging.js +3 -3
- package/dist/core/storage/session/fork-window.code.js +3 -3
- package/dist/core/storage/session/fork-window.impl.js +3 -3
- package/dist/core/storage/session/fork-window.js +3 -3
- package/dist/core/storage/session/history-pages.impl.js +3 -3
- package/dist/core/storage/session/history-pages.js +3 -3
- package/dist/core/storage/session/jsonl-entry-projection.impl.js +3 -3
- package/dist/core/storage/session/jsonl-entry-projection.js +3 -3
- package/dist/core/storage/session/jsonl-session-store.impl.js +3 -3
- package/dist/core/storage/session/jsonl-session-store.js +3 -3
- package/dist/core/storage/session/memory-session-store.impl.js +3 -3
- package/dist/core/storage/session/memory-session-store.js +3 -3
- package/dist/core/storage/session/pinned-branch-resume.code.js +3 -3
- package/dist/core/storage/session/pinned-branch-resume.impl.js +3 -3
- package/dist/core/storage/session/pinned-branch-resume.js +3 -3
- package/dist/core/storage/session/released-history-files.code.js +3 -3
- package/dist/core/storage/session/released-history-files.impl.js +3 -3
- package/dist/core/storage/session/released-history-files.js +3 -3
- package/dist/core/storage/session/resident-fork-rows.impl.js +3 -3
- package/dist/core/storage/session/resident-fork-rows.js +3 -3
- package/dist/core/storage/session/session-resume.impl.js +3 -3
- package/dist/core/storage/session/session-resume.js +3 -3
- package/dist/core/storage/session/snapshot-cut.impl.js +3 -3
- package/dist/core/storage/session/snapshot-cut.js +3 -3
- package/dist/core/storage/session/snapshot-history.code.js +3 -3
- package/dist/core/storage/session/snapshot-history.impl.js +3 -3
- package/dist/core/storage/session/snapshot-history.js +3 -3
- package/dist/core/storage/session/sql-session-store.code.js +1 -1
- package/dist/core/storage/session/sql-session-store.impl.js +3 -3
- package/dist/core/storage/session/sql-session-store.js +3 -3
- package/dist/core/storage/session/tree-outline.impl.js +3 -3
- package/dist/core/storage/session/tree-outline.js +3 -3
- package/dist/core/storage/session/tree-presentation.impl.js +3 -3
- package/dist/core/storage/session/tree-presentation.js +3 -3
- package/dist/core/storage/storage-status.impl.js +3 -3
- package/dist/core/storage/storage-status.js +3 -3
- package/dist/core/storage/team.impl.js +3 -3
- package/dist/core/storage/team.js +3 -3
- package/dist/core/structured-output/index.code.js +1 -1
- package/dist/core/structured-output/index.impl.js +3 -3
- package/dist/core/structured-output/index.js +3 -3
- package/dist/core/tasks/task-completion-entry.impl.js +3 -3
- package/dist/core/tasks/task-completion-entry.js +3 -3
- package/dist/core/tasks/task-file-history.code.js +3 -3
- package/dist/core/tasks/task-file-history.impl.js +3 -3
- package/dist/core/tasks/task-file-history.js +3 -3
- package/dist/core/tasks/task-reference-archive.code.js +4 -4
- package/dist/core/tasks/task-reference-archive.js +3 -3
- package/dist/core/tasks/task-reference-identity.code.js +1 -1
- package/dist/core/tasks/task-reference-identity.js +3 -3
- package/dist/core/tasks/task-reference-stream.impl.js +3 -3
- package/dist/core/tasks/task-reference-stream.js +3 -3
- package/dist/core/tasks/task-unsaved-answer.impl.js +3 -3
- package/dist/core/tasks/task-unsaved-answer.js +3 -3
- package/dist/core/tasks/task-view-source.impl.js +3 -3
- package/dist/core/tasks/task-view-source.js +3 -3
- package/dist/core/tools/read-url.code.js +2 -2
- package/dist/core/tools/read-url.impl.js +3 -3
- package/dist/core/tools/read-url.js +3 -3
- package/dist/core/worktree-snapshot/blob-store.js +2 -2
- package/dist/core/worktree-snapshot/errors.code.js +3 -3
- package/dist/core/worktree-snapshot/errors.impl.js +3 -3
- package/dist/core/worktree-snapshot/errors.js +3 -3
- package/dist/core/worktree-snapshot/session-index-reset.impl.js +3 -3
- package/dist/core/worktree-snapshot/session-index-reset.js +3 -3
- package/dist/extensions/codemode/execute.code.js +1 -1
- package/dist/extensions/codemode/execute.impl.js +3 -3
- package/dist/extensions/codemode/execute.js +3 -3
- package/dist/extensions/codemode/renderer.code.js +2 -2
- package/dist/extensions/codemode/renderer.impl.js +3 -3
- package/dist/extensions/codemode/renderer.js +3 -3
- package/dist/extensions/mcp/cli.code.js +2 -2
- package/dist/extensions/mcp/cli.impl.js +3 -3
- package/dist/extensions/mcp/cli.js +3 -3
- package/dist/extensions/mcp/cli.lazy.code.js +2 -2
- package/dist/extensions/mcp/cli.lazy.impl.js +3 -3
- package/dist/extensions/mcp/cli.lazy.js +3 -3
- package/dist/extensions/mcp/runtime.code.js +1 -1
- package/dist/extensions/mcp/runtime.impl.js +3 -3
- package/dist/extensions/mcp/runtime.js +3 -3
- package/dist/index-extensions.d.ts +1 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +7 -7
- package/dist/main-first-time-setup.code.js +2 -2
- package/dist/main-first-time-setup.impl.js +3 -3
- package/dist/main-first-time-setup.js +3 -3
- package/dist/modes/interactive/components/settings-selector-types.d.ts +1 -0
- package/dist/modes/interactive/components/settings-selector-types.js.map +1 -1
- package/dist/modes/interactive/components/stored-tree-view.code.js +2 -2
- package/dist/modes/interactive/components/stored-tree-view.impl.js +3 -3
- package/dist/modes/interactive/components/stored-tree-view.js +3 -3
- package/dist/modes/interactive/components/user-message-selector-archive.impl.js +3 -3
- package/dist/modes/interactive/components/user-message-selector-archive.js +3 -3
- package/dist/modes/interactive/theme/color-utils.d.ts +5 -5
- package/dist/modes/interactive/theme/theme-loading.d.ts +1 -0
- package/dist/modes/interactive-engine/engine-prewarm.js +1 -1
- package/dist/modes/interactive-engine/remote-model-catalog.d.ts +1 -0
- package/dist/modes/print-mode.js +1 -1
- package/dist/modes/rpc/rpc-client-api.d.ts +6 -0
- package/dist/modes/rpc/rpc-types.d.ts +29 -2
- package/dist/package-manager-cli.code.js +5 -5
- package/dist/package-manager-cli.impl.js +3 -3
- package/dist/package-manager-cli.js +3 -3
- package/dist/rpc-entry.js +1 -1
- package/dist/startup-files.json +1 -1
- package/dist/startup-stages/5.js +1 -1
- package/dist/startup-stages/7.js +1 -1
- package/dist/startup-stages/8.js +1 -2
- package/dist/startup-stages/9.js +2 -1
- package/dist/utils/native-module.d.ts +44 -0
- package/dist/utils/startup-database-spare.code.js +3 -3
- package/dist/utils/startup-database-spare.impl.js +3 -3
- package/dist/utils/startup-database-spare.js +3 -3
- package/dist/utils/tools-manager.code.js +1 -1
- package/dist/utils/tools-manager.impl.js +3 -3
- package/dist/utils/tools-manager.js +3 -3
- package/docs/background-tasks.md +238 -243
- package/docs/build.md +21 -15
- package/docs/changelog.mdx +1 -1
- package/docs/codemode.md +68 -51
- package/docs/compaction/reference.md +65 -26
- package/docs/compaction.md +118 -66
- package/docs/computer-use.md +179 -146
- package/docs/containerization.md +87 -33
- package/docs/custom-provider/api-reference.md +152 -13
- package/docs/custom-provider/oauth.md +45 -28
- package/docs/custom-provider/override.md +14 -7
- package/docs/custom-provider/registration.md +77 -67
- package/docs/custom-provider/streaming.md +42 -19
- package/docs/custom-provider.md +26 -62
- package/docs/development.md +81 -42
- package/docs/docs.json +54 -38
- package/docs/environment-variables.md +92 -64
- package/docs/extensions/api-reference.md +326 -735
- package/docs/extensions/authoring.md +186 -269
- package/docs/extensions/events.md +308 -375
- package/docs/extensions/examples.md +122 -74
- package/docs/extensions/ui.md +217 -197
- package/docs/extensions.md +189 -259
- package/docs/getting-started/authentication.md +27 -14
- package/docs/getting-started/first-session.md +25 -26
- package/docs/getting-started/installation.md +62 -84
- package/docs/getting-started/project-instructions.md +39 -14
- package/docs/guides/configuration.md +62 -20
- package/docs/guides/intercom.md +20 -12
- package/docs/guides/non-interactive.md +31 -16
- package/docs/guides/orchestration.md +17 -9
- package/docs/guides/resume-on-any-machine.md +63 -52
- package/docs/guides/subagents.md +26 -14
- package/docs/guides/team-setup.md +49 -27
- package/docs/guides.md +30 -23
- package/docs/herdr.md +22 -17
- package/docs/index.md +24 -17
- package/docs/intercom/operations.md +90 -66
- package/docs/intercom/reference.md +219 -192
- package/docs/intercom.md +111 -92
- package/docs/json.md +73 -71
- package/docs/keybindings.md +74 -48
- package/docs/libraries/agent-core.md +52 -9
- package/docs/libraries/ai.md +90 -63
- package/docs/libraries/codemode.md +31 -8
- package/docs/libraries/schema.md +12 -9
- package/docs/libraries/storage-libsql.md +92 -0
- package/docs/libraries/storage-postgres.md +119 -0
- package/docs/libraries/telemetry.md +42 -9
- package/docs/libraries/tui.md +74 -94
- package/docs/libraries.md +25 -8
- package/docs/llama-cpp.md +38 -33
- package/docs/mcp-servers.md +140 -88
- package/docs/models/reference.md +53 -36
- package/docs/models-configuration.md +19 -13
- package/docs/models.md +102 -87
- package/docs/orchestration/migrating-workflows.md +22 -20
- package/docs/orchestration/patterns.md +36 -21
- package/docs/orchestration.md +24 -21
- package/docs/packages/authoring.md +29 -18
- package/docs/packages/reference.md +77 -16
- package/docs/packages.md +34 -34
- package/docs/programmatic.md +28 -21
- package/docs/prompt-templates.md +65 -41
- package/docs/providers/reference.md +36 -20
- package/docs/providers.md +78 -76
- package/docs/quickstart.md +42 -54
- package/docs/reference/cli.md +256 -254
- package/docs/reference.md +30 -23
- package/docs/rpc/examples.md +121 -17
- package/docs/rpc/extension-ui.md +86 -63
- package/docs/rpc/protocol.md +817 -358
- package/docs/rpc.md +78 -152
- package/docs/sdk/reference.md +309 -73
- package/docs/sdk/storage.md +614 -0
- package/docs/sdk/structured-decisions.md +168 -65
- package/docs/sdk/web-server.md +80 -46
- package/docs/sdk.md +168 -215
- package/docs/security.md +117 -44
- package/docs/session-format.md +127 -76
- package/docs/sessions.md +155 -113
- package/docs/settings.md +293 -205
- package/docs/shell-aliases.md +15 -6
- package/docs/skills/authoring.md +17 -9
- package/docs/skills/reference.md +23 -21
- package/docs/skills.md +148 -97
- package/docs/storage.md +172 -260
- package/docs/subagents/authoring.md +148 -15
- package/docs/subagents/reference.md +105 -29
- package/docs/subagents.md +247 -250
- package/docs/terminal-setup.md +97 -69
- package/docs/termux.md +51 -85
- package/docs/themes/reference.md +51 -37
- package/docs/themes.md +52 -55
- package/docs/tmux.md +38 -21
- package/docs/tools.md +209 -147
- package/docs/tui/reference.md +64 -32
- package/docs/tui.md +38 -66
- package/docs/usage.md +94 -86
- package/docs/verification.md +25 -25
- package/docs/web-access.md +106 -54
- package/docs/windows.md +55 -57
- package/docs/worktree-snapshots.md +82 -74
- package/examples/sdk/11-sessions.ts +4 -4
- package/package.json +8 -8
- package/schemas/models.schema.json +58 -7
- package/dist/_shared/sdk-OSBEPR3Q.js.map +0 -1
- package/dist/_shared/startup-0-0-TYUFUOJZ.js.map +0 -1
- package/dist/_shared/startup-0-1-W2G2UY7R.js.map +0 -1
- package/dist/_shared/startup-0-2-UXBUEOXW.js.map +0 -1
- package/dist/_shared/startup-0-4-HN5EB4K7.js.map +0 -1
|
@@ -1,61 +1,63 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: Extension events
|
|
3
|
-
|
|
2
|
+
title: "Extension events"
|
|
3
|
+
sidebarTitle: "Events"
|
|
4
|
+
description: "Reference for extension lifecycle events, payloads, handler chaining rules, and return contracts."
|
|
4
5
|
---
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
<div id="events" />
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
Subscribe to lifecycle events with `atomic.on(event, handler)`. Every `atomic.on()` call returns an unsubscribe function `() => void` if you need to detach a listener before reload or shutdown.
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
## Lifecycle overview
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
When interactive startup needs to ask whether you trust a project, user, global, and CLI `-e` extensions start first (receiving `session_start` and `resources_discover`) so they can participate in `project_trust` and display UI. After trust is granted, project extensions load, receive `session_start`, and `resources_discover` runs again for the full set.
|
|
13
14
|
|
|
14
|
-
A `resources_discover` handler that fails both
|
|
15
|
+
A `resources_discover` handler that fails both passes with the same error is reported once. Different handlers are reported separately even if they throw the same message. Extensions already started during the first pass keep their session and do not receive a second `session_start`. Non-interactive startup resolves trust before running the normal lifecycle.
|
|
15
16
|
|
|
16
|
-
```
|
|
17
|
+
```text
|
|
17
18
|
Atomic starts
|
|
18
19
|
│
|
|
19
|
-
├─► session_start / resources_discover (
|
|
20
|
-
├─► project_trust (user/global and CLI extensions only, before project resources load)
|
|
21
|
-
├─► session_start { reason: "startup" } (extensions
|
|
20
|
+
├─► session_start / resources_discover (user/global and CLI -e extensions when trust is needed)
|
|
21
|
+
├─► project_trust (user/global and CLI -e extensions only, before project resources load)
|
|
22
|
+
├─► session_start { reason: "startup" } (remaining extensions)
|
|
22
23
|
├─► resources_discover { reason: "startup" }
|
|
23
24
|
└─► after the transcript renders: session_recovery_restore / session_recovery_replay
|
|
24
25
|
│
|
|
25
26
|
▼
|
|
26
27
|
user sends prompt ─────────────────────────────────────────┐
|
|
27
28
|
│ │
|
|
28
|
-
├─► (extension commands checked first
|
|
29
|
+
├─► (extension commands checked first; bypass if found) │
|
|
29
30
|
├─► input (can intercept, transform, or handle) │
|
|
30
31
|
├─► (skill/template expansion if not handled) │
|
|
31
|
-
├─► before_agent_start (can inject message,
|
|
32
|
+
├─► before_agent_start (can inject message, adjust prompt)
|
|
32
33
|
├─► agent_start │
|
|
33
34
|
├─► message_start / message_update / message_end │
|
|
34
35
|
│ │
|
|
35
|
-
│ ┌─── turn (repeats while
|
|
36
|
+
│ ┌─── turn (repeats while model calls tools) ─┐ │
|
|
36
37
|
│ │ │ │
|
|
37
38
|
│ ├─► turn_start │ │
|
|
38
|
-
│ ├─► context (
|
|
39
|
-
│ ├─► context_with_system (
|
|
40
|
-
│ ├─►
|
|
41
|
-
│ ├─►
|
|
42
|
-
│ ├─►
|
|
39
|
+
│ ├─► context (modify conversation messages) │ │
|
|
40
|
+
│ ├─► context_with_system (modify full list) │ │
|
|
41
|
+
│ ├─► before_provider_headers (mutate headers) │ │
|
|
42
|
+
│ ├─► before_provider_request (edit payload) │ │
|
|
43
|
+
│ ├─► after_provider_response (status+headers) │ │
|
|
44
|
+
│ ├─► provider_stream_event (raw chunk events) │ │
|
|
43
45
|
│ │ │ │
|
|
44
|
-
│ │
|
|
46
|
+
│ │ Model responds, may call tools: │ │
|
|
45
47
|
│ │ ├─► tool_execution_start │ │
|
|
46
|
-
│ │ ├─► tool_call (can block)
|
|
48
|
+
│ │ ├─► tool_call (can block or patch) │ │
|
|
47
49
|
│ │ ├─► tool_execution_update │ │
|
|
48
|
-
│ │ ├─► tool_result (can modify)
|
|
50
|
+
│ │ ├─► tool_result (can modify result) │ │
|
|
49
51
|
│ │ └─► tool_execution_end │ │
|
|
50
52
|
│ │ │ │
|
|
51
|
-
│ ├─► turn_end (can append entries
|
|
52
|
-
│ └─►
|
|
53
|
-
│ (may compact before
|
|
53
|
+
│ ├─► turn_end (can append entries & continue) │ │
|
|
54
|
+
│ └─► context-size check after tool results │ │
|
|
55
|
+
│ (may compact before next model request) │ │
|
|
54
56
|
├─► agent_end │
|
|
55
|
-
├─► retry backoff or final-attempt recovery (when
|
|
57
|
+
├─► retry backoff or final-attempt recovery (when needed)│
|
|
56
58
|
│ └─► fresh agent_start on successful recovery │
|
|
57
|
-
├─► agent_before_settle (
|
|
58
|
-
└─► agent_settled (final, notification
|
|
59
|
+
├─► agent_before_settle (append entries & continue) │
|
|
60
|
+
└─► agent_settled (final, notification-only) │
|
|
59
61
|
│
|
|
60
62
|
user sends another prompt ◄────────────────────────────────┘
|
|
61
63
|
|
|
@@ -75,7 +77,6 @@ user sends another prompt ◄─────────────────
|
|
|
75
77
|
└─► resources_discover { reason: "startup" }
|
|
76
78
|
|
|
77
79
|
/compact or auto-compaction
|
|
78
|
-
├─► compaction_start / compaction_end (compaction status)
|
|
79
80
|
├─► session_before_compact (can cancel or provide compactedText)
|
|
80
81
|
├─► session_compact (after the compaction boundary is persisted)
|
|
81
82
|
└─► session_compact_failed (failure or cancellation)
|
|
@@ -85,45 +86,45 @@ user sends another prompt ◄─────────────────
|
|
|
85
86
|
└─► session_tree
|
|
86
87
|
|
|
87
88
|
/model or CTRL+P (model selection/cycling)
|
|
88
|
-
├─► thinking_level_select (if model change
|
|
89
|
+
├─► thinking_level_select (if model change clamps thinking level)
|
|
89
90
|
└─► model_select
|
|
90
91
|
|
|
91
92
|
thinking level changes (settings, keybinding, atomic.setThinkingLevel())
|
|
92
93
|
└─► thinking_level_select
|
|
93
94
|
|
|
94
95
|
prompt cache warming (when enabled)
|
|
95
|
-
└─► cache_warming_decision (can return
|
|
96
|
+
└─► cache_warming_decision (can return { action: "warm" | "stop" })
|
|
96
97
|
|
|
97
98
|
exit (CTRL+C, CTRL+D, SIGHUP, SIGTERM)
|
|
98
99
|
└─► session_shutdown
|
|
99
100
|
```
|
|
100
101
|
|
|
101
|
-
|
|
102
|
+
## Startup events
|
|
102
103
|
|
|
103
|
-
|
|
104
|
+
### project_trust
|
|
104
105
|
|
|
105
|
-
Fired before Atomic decides whether to trust a project with
|
|
106
|
+
Fired before Atomic decides whether to trust a project with local configuration (`.atomic`, legacy `.pi`, or `.agents/skills`). Runs during startup and when switching sessions (such as `/resume`) enters a working directory whose trust has not been resolved in this process. Only user, global, and CLI `-e` extensions participate because project extensions load after trust is granted.
|
|
106
107
|
|
|
107
108
|
```typescript
|
|
108
109
|
atomic.on("project_trust", async (event, ctx) => {
|
|
109
110
|
// event.cwd - current working directory
|
|
110
111
|
// ctx has a limited trust context: cwd, mode, hasUI, and select/confirm/input/notify UI helpers
|
|
111
|
-
if (ctx.hasUI && await ctx.ui.confirm("Trust project?", event.cwd)) {
|
|
112
|
+
if (ctx.hasUI && (await ctx.ui.confirm("Trust project?", event.cwd))) {
|
|
112
113
|
return { trusted: "yes", remember: true };
|
|
113
114
|
}
|
|
114
115
|
return { trusted: "undecided" };
|
|
115
116
|
});
|
|
116
117
|
```
|
|
117
118
|
|
|
118
|
-
A `project_trust` handler must return `{ trusted: "yes" | "no" | "undecided" }`. The first yes or no decision
|
|
119
|
+
A `project_trust` handler must return `{ trusted: "yes" | "no" | "undecided" }`. The first `"yes"` or `"no"` decision wins and suppresses the built-in trust prompt. Set `remember: true` to persist the decision; otherwise it applies to the current process only.
|
|
119
120
|
|
|
120
|
-
Return `"undecided"` to
|
|
121
|
+
Return `"undecided"` to pass control to later handlers or Atomic's built-in trust flow, and check `ctx.hasUI` before prompting. If no handler decides, saved `trust.json` decisions apply first, then `defaultProjectTrust` decides whether Atomic asks, trusts, or declines.
|
|
121
122
|
|
|
122
|
-
|
|
123
|
+
## Resource events
|
|
123
124
|
|
|
124
|
-
|
|
125
|
+
### resources_discover
|
|
125
126
|
|
|
126
|
-
Fired after `session_start` so extensions can contribute
|
|
127
|
+
Fired after `session_start` so extensions can contribute skill, prompt template, and theme paths. Startup passes `reason: "startup"`; `/reload` passes `reason: "reload"`.
|
|
127
128
|
|
|
128
129
|
```typescript
|
|
129
130
|
atomic.on("resources_discover", async (event, _ctx) => {
|
|
@@ -137,67 +138,78 @@ atomic.on("resources_discover", async (event, _ctx) => {
|
|
|
137
138
|
});
|
|
138
139
|
```
|
|
139
140
|
|
|
140
|
-
|
|
141
|
+
## Session events
|
|
141
142
|
|
|
142
143
|
See [Session format](/session-format) for session storage details and the `SessionManager` API.
|
|
143
144
|
|
|
144
|
-
|
|
145
|
+
For all cancellable `session_before_*` events (`session_before_switch`, `session_before_fork`, `session_before_compact`, `session_before_tree`), the **first** handler returning `{ cancel: true }` immediately short-circuits remaining handlers and cancels the action. Otherwise, the last non-empty result wins.
|
|
146
|
+
|
|
147
|
+
### session_start
|
|
145
148
|
|
|
146
|
-
Fired when a session
|
|
149
|
+
Fired when a session starts, reloads, switches, or forks.
|
|
147
150
|
|
|
148
151
|
```typescript
|
|
149
152
|
atomic.on("session_start", async (event, ctx) => {
|
|
150
153
|
// event.reason - "startup" | "reload" | "new" | "resume" | "fork"
|
|
151
154
|
// event.previousSessionId - present for "new", "resume", and "fork"
|
|
155
|
+
// event.engineRestart - true only when a crashed interactive worker process restarted
|
|
152
156
|
ctx.ui.notify(`Session: ${ctx.sessionManager.getSessionId()}`, "info");
|
|
153
157
|
});
|
|
154
158
|
```
|
|
155
159
|
|
|
156
|
-
If
|
|
160
|
+
If a handler throws, interactive mode shows the error with the extension's path and keeps the session open; print mode, RPC mode, and SDK sessions fail startup instead. See [Error handling](/extensions/api-reference#error-handling).
|
|
161
|
+
|
|
162
|
+
### session_recovery_restore / session_recovery_replay
|
|
157
163
|
|
|
158
|
-
|
|
164
|
+
Fired once per session when recovering unfinished work from an earlier process. Interactive mode runs them after the transcript renders; SDK and RPC hosts run them when calling `session.startPendingRecovery()` or sending `start_pending_recovery`.
|
|
159
165
|
|
|
160
|
-
|
|
166
|
+
`session_recovery_restore` runs first so extensions can restore background work such as child agents. It receives `event.reason` (`"startup" | "resume"`) and `event.engineRestart` (`true` when triggered after an automatic worker restart).
|
|
161
167
|
|
|
162
|
-
`
|
|
168
|
+
`session_recovery_replay` follows only when delivery cards shown before exit never reached the model. Each decision in `decisions` takes `{ entryId, action }`, where `action` is:
|
|
163
169
|
|
|
164
|
-
`
|
|
170
|
+
- `"replay"`: explicitly deliver the pending card in a visible turn (also the default when no handler returns a decision for that card).
|
|
171
|
+
- `"drop"`: permanently close a card whose sender or target no longer exists.
|
|
172
|
+
- `"defer"`: leave the card pending without starting a turn so the next recovery offers it again (useful when a peer service is unreachable).
|
|
165
173
|
|
|
166
|
-
Notices from either event
|
|
174
|
+
If handlers disagree on the same card, `"drop"` wins over `"defer"`. Notices returned from either event combine into one non-triggering message for the user and model.
|
|
167
175
|
|
|
168
176
|
```typescript
|
|
169
|
-
atomic.on("session_recovery_restore", async (event
|
|
177
|
+
atomic.on("session_recovery_restore", async (event) => {
|
|
170
178
|
// event.reason - "startup" | "resume"
|
|
179
|
+
// event.engineRestart - true after a worker restart
|
|
171
180
|
return { notices: ["Worker reviewer could not be restored and is gone."] };
|
|
172
181
|
});
|
|
173
182
|
|
|
174
|
-
atomic.on("session_recovery_replay", async (event
|
|
183
|
+
atomic.on("session_recovery_replay", async (event) => {
|
|
175
184
|
// event.pending - [{ entryId, customType, content, details, timestamp, stageAdmissionKey?, delivery }]
|
|
176
|
-
|
|
177
|
-
|
|
185
|
+
return {
|
|
186
|
+
decisions: event.pending.map((entry) => ({
|
|
187
|
+
entryId: entry.entryId,
|
|
188
|
+
action: entry.customType === "my-extension:stale" ? "drop" : "replay",
|
|
189
|
+
})),
|
|
190
|
+
};
|
|
178
191
|
});
|
|
179
192
|
```
|
|
180
193
|
|
|
181
|
-
|
|
194
|
+
### session_info_changed
|
|
182
195
|
|
|
183
|
-
Fired when the
|
|
196
|
+
Fired when the session display name changes via `/name`, RPC, or `atomic.setSessionName()`.
|
|
184
197
|
|
|
185
198
|
```typescript
|
|
186
199
|
atomic.on("session_info_changed", async (event, ctx) => {
|
|
187
|
-
// event.name -
|
|
200
|
+
// event.name - normalized name, or undefined if cleared
|
|
188
201
|
ctx.ui.notify(`Session renamed: ${event.name ?? "(none)"}`, "info");
|
|
189
202
|
});
|
|
190
203
|
```
|
|
191
204
|
|
|
192
|
-
|
|
205
|
+
### session_before_switch
|
|
193
206
|
|
|
194
|
-
Fired before
|
|
207
|
+
Fired before `/new` or `/resume`. The first handler returning `{ cancel: true }` stops the switch and skips later handlers.
|
|
195
208
|
|
|
196
209
|
```typescript
|
|
197
210
|
atomic.on("session_before_switch", async (event, ctx) => {
|
|
198
|
-
// event.reason - "new"
|
|
199
|
-
// event.targetSessionId - session
|
|
200
|
-
|
|
211
|
+
// event.reason - "new" | "resume"
|
|
212
|
+
// event.targetSessionId - destination session ID (only for "resume")
|
|
201
213
|
if (event.reason === "new") {
|
|
202
214
|
const ok = await ctx.ui.confirm("Clear?", "Delete all messages?");
|
|
203
215
|
if (!ok) return { cancel: true };
|
|
@@ -205,54 +217,47 @@ atomic.on("session_before_switch", async (event, ctx) => {
|
|
|
205
217
|
});
|
|
206
218
|
```
|
|
207
219
|
|
|
208
|
-
After a successful switch
|
|
209
|
-
Do cleanup work in `session_shutdown`, then reestablish any in-memory state in `session_start`.
|
|
220
|
+
After a successful switch, Atomic emits `session_shutdown` for the previous instance, reloads extensions for the new session, and emits `session_start` with `reason: "new" | "resume"` and `previousSessionId`.
|
|
210
221
|
|
|
211
|
-
|
|
222
|
+
### session_before_fork
|
|
212
223
|
|
|
213
|
-
Fired
|
|
224
|
+
Fired before `/fork` or `/clone`. The first handler returning `{ cancel: true }` cancels the action and skips later handlers.
|
|
214
225
|
|
|
215
226
|
```typescript
|
|
216
|
-
atomic.on("session_before_fork", async (event
|
|
227
|
+
atomic.on("session_before_fork", async (event) => {
|
|
217
228
|
// event.entryId - ID of the selected entry
|
|
218
229
|
// event.position - "before" for /fork, "at" for /clone
|
|
219
|
-
return { cancel: true };
|
|
220
|
-
//
|
|
221
|
-
return { skipConversationRestore: true }; // Reserved for future conversation restore control
|
|
230
|
+
return { cancel: true };
|
|
231
|
+
// Or: return { skipConversationRestore: true };
|
|
222
232
|
});
|
|
223
233
|
```
|
|
224
234
|
|
|
225
|
-
After a successful fork or clone, Atomic emits `session_shutdown
|
|
226
|
-
Do cleanup work in `session_shutdown`, then reestablish any in-memory state in `session_start`.
|
|
235
|
+
After a successful fork or clone, Atomic emits `session_shutdown`, reloads extensions for the new session, and emits `session_start` with `reason: "fork"` and `previousSessionId`.
|
|
227
236
|
|
|
228
|
-
|
|
237
|
+
### session_before_compact / session_compact / session_compact_failed
|
|
229
238
|
|
|
230
|
-
Fired by `/compact` and
|
|
239
|
+
Fired by `/compact` and automatic compaction, including when tool output pushes the prospective next-turn context past the threshold. Atomic prepares all context since the last compaction boundary.
|
|
231
240
|
|
|
232
|
-
|
|
241
|
+
Handlers on `session_before_compact` can cancel compaction (`{ cancel: true }`, short-circuiting later handlers) or return `{ compactedText }`. When `compactedText` is provided, Atomic skips the configured compactor and inserts that text verbatim into a `Context compacted` boundary message followed by history recovery instructions. Empty or whitespace-only text counts as no replacement.
|
|
233
242
|
|
|
234
|
-
|
|
243
|
+
If replacement text exceeds the compactor's output limit or still exceeds the automatic trigger together with the system prompt and recovery instructions, Atomic clears the context instead. A successful post-tool compaction feeds its rebuilt context directly into the active turn loop; cancellation or failure stops the follow-up model request.
|
|
235
244
|
|
|
236
245
|
```typescript
|
|
237
246
|
atomic.on("session_before_compact", async (event) => {
|
|
238
247
|
const { preparation, branchEntries, parameters, reason, signal } = event;
|
|
239
|
-
|
|
240
|
-
// preparation.
|
|
241
|
-
// preparation.firstKeptEntryId - always null: no earlier message stays in context
|
|
248
|
+
// preparation.region.lines - role-tagged lines since the last boundary (deep-frozen)
|
|
249
|
+
// preparation.firstKeptEntryId - always null
|
|
242
250
|
// preparation.tokensBefore - whole-context token estimate
|
|
243
|
-
// parameters.query -
|
|
251
|
+
// parameters.query - /compact instructions or latest user request
|
|
244
252
|
// branchEntries - raw entries on the active branch
|
|
245
253
|
// reason - "manual" | "threshold" | "overflow"
|
|
246
|
-
// preparation is a deep-frozen clone
|
|
247
254
|
|
|
248
255
|
if (signal.aborted) return { cancel: true };
|
|
249
256
|
|
|
250
|
-
// Cancel compaction:
|
|
251
|
-
return { cancel: true };
|
|
252
|
-
|
|
253
|
-
// Or replace the context with your own text. Whitespace-only text is no replacement.
|
|
254
257
|
return {
|
|
255
|
-
compactedText: preparation.region.lines
|
|
258
|
+
compactedText: preparation.region.lines
|
|
259
|
+
.filter((line) => line.startsWith("[User]: "))
|
|
260
|
+
.join("\n"),
|
|
256
261
|
};
|
|
257
262
|
});
|
|
258
263
|
|
|
@@ -260,154 +265,148 @@ atomic.on("session_compact", async (event) => {
|
|
|
260
265
|
// event.result - VerbatimCompactionResult (compactedText, form, backend, model, fallbackReason, history, stats)
|
|
261
266
|
// event.compactionEntry - saved CompactionEntry with strategy "verbatim-lines"
|
|
262
267
|
// event.fromExtension - true when session_before_compact provided compactedText
|
|
263
|
-
//
|
|
268
|
+
// Notification-only: handler errors are logged and do not affect the saved compaction.
|
|
264
269
|
});
|
|
265
270
|
|
|
266
271
|
atomic.on("session_compact_failed", async (event) => {
|
|
267
272
|
// event.reason - "manual" | "threshold" | "overflow"
|
|
268
|
-
// event.errorMessage - absent
|
|
273
|
+
// event.errorMessage - absent on cancellation
|
|
269
274
|
// event.aborted / event.willRetry - terminal state
|
|
270
275
|
// event.fromExtension - whether extension-provided text was active
|
|
271
276
|
});
|
|
272
277
|
```
|
|
273
278
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
When a user navigates with `/tree`, `session_before_tree` receives the real entries of the abandoned branch segment in `event.preparation.entriesToSummarize`, even if the user did not request a summary. This is a temporary exception to the context-window limit for an explicit navigation with a handler or summarizer. Without either, Atomic does not load that segment. The manager does not retain those entries after navigation; if your extension keeps the array, it owns that memory.
|
|
279
|
+
### session_before_tree / session_tree
|
|
277
280
|
|
|
278
281
|
Fired on `/tree` navigation. See [Sessions](/sessions) for tree navigation concepts.
|
|
279
282
|
|
|
283
|
+
When a handler is registered or summarization is requested, `event.preparation.entriesToSummarize` contains the entries of the abandoned branch segment (even when `userWantsSummary` is `false`). Atomic releases that array after navigation; if your extension retains a reference, it owns that memory.
|
|
284
|
+
|
|
280
285
|
```typescript
|
|
281
|
-
atomic.on("session_before_tree", async (event
|
|
286
|
+
atomic.on("session_before_tree", async (event) => {
|
|
282
287
|
const { preparation, signal } = event;
|
|
283
|
-
|
|
284
|
-
//
|
|
285
|
-
|
|
288
|
+
// preparation.targetId - destination entry ID
|
|
289
|
+
// preparation.oldLeafId - leaf ID before navigation
|
|
290
|
+
// preparation.commonAncestorId - shared ancestor entry ID
|
|
291
|
+
// preparation.entriesToSummarize - entries leaving the active branch
|
|
292
|
+
// preparation.userWantsSummary - whether the user requested a branch summary
|
|
293
|
+
// preparation.customInstructions / preparation.replaceInstructions / preparation.label
|
|
294
|
+
|
|
295
|
+
if (signal.aborted) return { cancel: true };
|
|
296
|
+
|
|
297
|
+
// Cancel navigation:
|
|
298
|
+
// return { cancel: true };
|
|
299
|
+
|
|
300
|
+
// Customize summary prompt or label without replacing summarization:
|
|
301
|
+
// return { customInstructions: "Keep API contract decisions", replaceInstructions: false, label: "branch-cut" };
|
|
302
|
+
|
|
303
|
+
// Or supply a custom summary directly:
|
|
304
|
+
return { summary: { summary: "Explored approach A; switched to B.", details: {} }, label: "approach-a" };
|
|
286
305
|
});
|
|
287
306
|
|
|
288
|
-
atomic.on("session_tree", async (event
|
|
289
|
-
// event.newLeafId, oldLeafId, summaryEntry, fromExtension
|
|
307
|
+
atomic.on("session_tree", async (event) => {
|
|
308
|
+
// event.newLeafId, event.oldLeafId, event.summaryEntry, event.fromExtension
|
|
290
309
|
});
|
|
291
310
|
```
|
|
292
311
|
|
|
293
|
-
|
|
312
|
+
### session_shutdown
|
|
294
313
|
|
|
295
|
-
Fired before a started session
|
|
314
|
+
Fired before a started session shuts down, reloads, switches, or forks. Close background resources opened in `session_start` here.
|
|
296
315
|
|
|
297
316
|
```typescript
|
|
298
|
-
atomic.on("session_shutdown", async (event
|
|
317
|
+
atomic.on("session_shutdown", async (event) => {
|
|
299
318
|
// event.reason - "quit" | "reload" | "new" | "resume" | "fork"
|
|
300
|
-
// event.targetSessionId - destination session
|
|
301
|
-
// event.fromSignal - true when
|
|
302
|
-
// Cleanup, save state, etc.
|
|
319
|
+
// event.targetSessionId - destination session ID on switches or forks
|
|
320
|
+
// event.fromSignal - true when "quit" came from SIGTERM/SIGHUP rather than explicit quit
|
|
303
321
|
});
|
|
304
322
|
```
|
|
305
323
|
|
|
306
|
-
`fromSignal` is set only
|
|
324
|
+
`fromSignal` is set only when `reason === "quit"` came from an OS signal (`SIGTERM`, `SIGHUP`, or terminal close); `Ctrl+D` and `/quit` leave it unset.
|
|
307
325
|
|
|
308
|
-
|
|
326
|
+
Handlers have about 5 seconds to finish on Linux and macOS quit or signal shutdown (a second `SIGTERM` exits immediately), and about 4 seconds on Windows console close or OS shutdown after startup finishes. Any running [`atomic.exec`](/extensions/api-reference#atomic-exec-command-args-options) command is stopped first so it cannot block shutdown handlers.
|
|
309
327
|
|
|
310
|
-
|
|
328
|
+
## Agent events
|
|
311
329
|
|
|
312
|
-
|
|
330
|
+
### before_agent_start
|
|
313
331
|
|
|
314
|
-
|
|
332
|
+
Fired before a run starts from a user prompt or from `atomic.sendMessage(..., { triggerTurn: true })` while idle. Multiple handlers returning `message` all inject their messages in extension load order. Returning `systemPrompt` updates `systemPromptOptions.forceSystemPrompt` (last handler wins), while `event.systemPrompt` and `ctx.getSystemPrompt()` update live for each subsequent handler.
|
|
315
333
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
Fired before a run starts from a user prompt or from `atomic.sendMessage(..., { triggerTurn: true })` while idle. Can inject a message and/or modify the system prompt for the whole run, including requests after tool calls. Messages sent while this hook runs join the starting run rather than starting a second run.
|
|
319
|
-
|
|
320
|
-
Check `event.messageType` before reading the starting input. A `"user"` event has `prompt` and optional `images`; a `"custom"` event has `message`, the custom message that started the run. Existing handlers that read `event.prompt` or `event.images` should first narrow to `event.messageType === "user"`.
|
|
334
|
+
Always check `event.messageType` before reading the trigger payload: `"user"` events carry `prompt` and optional `images`, while `"custom"` events carry `message`.
|
|
321
335
|
|
|
322
336
|
```typescript
|
|
323
|
-
atomic.on("before_agent_start", async (event
|
|
337
|
+
atomic.on("before_agent_start", async (event) => {
|
|
324
338
|
if (event.messageType === "user") {
|
|
325
|
-
// event.prompt
|
|
326
|
-
// event.images - attached images (if any)
|
|
339
|
+
// event.prompt, event.images
|
|
327
340
|
} else {
|
|
328
|
-
// event.message
|
|
341
|
+
// event.message (starting custom message)
|
|
329
342
|
}
|
|
330
|
-
// event.systemPrompt -
|
|
331
|
-
//
|
|
332
|
-
//
|
|
333
|
-
//
|
|
334
|
-
// .forceSystemPrompt - optional exact replacement for the complete prompt
|
|
335
|
-
// .selectedTools - tools currently active in the prompt
|
|
336
|
-
// .toolSnippets - one-line descriptions for each tool
|
|
337
|
-
// .toolGuidelines - guideline bullets keyed by tool name
|
|
338
|
-
// .sections - custom XML-wrapped sections keyed by tag name
|
|
339
|
-
// .promptGuidelines - custom guideline bullets
|
|
340
|
-
// .appendSystemPrompt - text from --append-system-prompt flags
|
|
341
|
-
// .cwd - working directory
|
|
342
|
-
// .contextFiles - AGENTS.md files and other loaded context files
|
|
343
|
-
// .skills - loaded skills
|
|
343
|
+
// event.systemPrompt - chained system prompt so far
|
|
344
|
+
// event.systemPromptOptions - mutable BuildSystemPromptOptions:
|
|
345
|
+
// customPrompt, forceSystemPrompt, selectedTools, toolSnippets, toolGuidelines,
|
|
346
|
+
// sections, promptGuidelines, appendSystemPrompt, cwd, contextFiles, skills
|
|
344
347
|
|
|
345
348
|
return {
|
|
346
|
-
// Inject a persistent message (stored in session, sent to LLM)
|
|
347
349
|
message: {
|
|
348
350
|
customType: "my-extension",
|
|
349
|
-
content: "Additional context for the
|
|
351
|
+
content: "Additional context for the model",
|
|
350
352
|
display: true,
|
|
351
353
|
},
|
|
352
|
-
|
|
353
|
-
systemPrompt: event.systemPrompt + "\n\nExtra instructions for this turn...",
|
|
354
|
+
systemPrompt: `${event.systemPrompt}\n\nExtra instructions for this run.`,
|
|
354
355
|
};
|
|
355
356
|
});
|
|
356
357
|
```
|
|
357
358
|
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
Returning `systemPrompt`, or setting `forceSystemPrompt`, replaces the complete provider prompt for the run without recording the forced text. The transcript still records structured sections. Models supporting mid-conversation system messages receive patches in place; other models receive the replayed leading prompt. A forced replacement or unsupported tool transition can invalidate the cached prefix.
|
|
361
|
-
|
|
362
|
-
Inside `before_agent_start`, `event.systemPrompt` and `ctx.getSystemPrompt()` both reflect the chained system prompt as of the current handler. Later `before_agent_start` handlers can still modify it again.
|
|
363
|
-
|
|
364
|
-
#### agent_start / agent_end / agent_before_settle / agent_settled
|
|
359
|
+
Prefer mutating `event.systemPromptOptions.sections`, `selectedTools`, or `promptGuidelines` instead of returning a full `systemPrompt` override so prompt caching stays intact. Editing `selectedTools` or calling `atomic.setActiveTools()` here applies to the same run's executable tools as well as its prompt text.
|
|
365
360
|
|
|
366
|
-
|
|
361
|
+
### agent_start / agent_end / agent_before_settle / agent_settled
|
|
367
362
|
|
|
368
|
-
|
|
363
|
+
- `agent_start` marks the start of one low-level model run.
|
|
364
|
+
- `agent_end` marks the end of that run (Atomic may still retry, compact and retry, or deliver queued follow-ups).
|
|
365
|
+
- `agent_before_settle` is the final actionable boundary before going idle: handlers can append entries and request one continuation (`continue: true`).
|
|
366
|
+
- `agent_settled` is final and notification-only, with `event.aborted: boolean` (`true` if cancelled, including during `agent_before_settle`).
|
|
369
367
|
|
|
370
368
|
```typescript
|
|
371
|
-
atomic.on("agent_start", async (
|
|
372
|
-
atomic.on("agent_end", async (event
|
|
373
|
-
// event.messages - messages
|
|
369
|
+
atomic.on("agent_start", async () => {});
|
|
370
|
+
atomic.on("agent_end", async (event) => {
|
|
371
|
+
// event.messages - messages produced in this run
|
|
374
372
|
});
|
|
375
373
|
|
|
376
374
|
let addedReviewReminder = false;
|
|
377
|
-
atomic.on("agent_before_settle", async (event
|
|
375
|
+
atomic.on("agent_before_settle", async (event) => {
|
|
378
376
|
if (addedReviewReminder) return;
|
|
379
377
|
addedReviewReminder = true;
|
|
380
378
|
return {
|
|
381
|
-
entries: [
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
379
|
+
entries: [
|
|
380
|
+
...event.entries,
|
|
381
|
+
{
|
|
382
|
+
type: "custom_message",
|
|
383
|
+
customType: "review-reminder",
|
|
384
|
+
content: "Review the final diff before replying.",
|
|
385
|
+
display: false,
|
|
386
|
+
},
|
|
387
|
+
],
|
|
387
388
|
continue: true,
|
|
388
389
|
};
|
|
389
390
|
});
|
|
390
391
|
|
|
391
|
-
atomic.on("agent_settled", async (
|
|
392
|
-
//
|
|
392
|
+
atomic.on("agent_settled", async (event, ctx) => {
|
|
393
|
+
// event.aborted - true when cancelled
|
|
394
|
+
// ctx.isIdle() is true; any new prompt started here waits until all agent_settled handlers finish.
|
|
393
395
|
});
|
|
394
396
|
```
|
|
395
397
|
|
|
396
|
-
If
|
|
398
|
+
If aborted during `agent_before_settle`, valid entries still persist while `continue: true` is suppressed. Input queued from `agent_before_settle` with `deliverAs: "steer"` or `"followUp"` joins the requested continuation instead of starting a second run.
|
|
397
399
|
|
|
398
|
-
Each provider request
|
|
400
|
+
Each provider request builds from the persisted session after earlier event handlers (`agent_start`, `turn_start`, `message_start`, `message_end`, `tool_execution_*`) settle, because `message_end` can modify a saved message. Do not await something later in the same run inside one of those handlers; wait in `agent_end` or `agent_settled` instead.
|
|
399
401
|
|
|
400
|
-
|
|
402
|
+
### ui_prompt_start / ui_prompt_end
|
|
401
403
|
|
|
402
|
-
|
|
404
|
+
Notification-only events wrapping blocking user-facing prompts:
|
|
403
405
|
|
|
404
|
-
- `ui_prompt`:
|
|
405
|
-
|
|
406
|
-
- `project_trust`: interactive startup/resume trust dialogs, trust-hook dialogs, borrowed extension-source authorization, and the built-in `/trust` selector. Silent saved/default/CLI decisions and noninteractive startup do not emit artificial waits.
|
|
406
|
+
- `reason: "ui_prompt"`: prompts opened via `ctx.ui.select()`, `confirm()`, `input()`, `editor()`, and `custom()` (unless `{ purpose: "navigation" }` is passed).
|
|
407
|
+
- `reason: "project_trust"`: interactive trust dialogs and `/trust`.
|
|
407
408
|
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
Nested or overlapping prompts share one outer span. Its end retains the original reason, kind, and title and fires after all nested prompts settle. Prompt display and answers never wait for observers. An observer's asynchronous start and end work can overlap, so update lifecycle state before awaiting unrelated work. During session replacement, pending notification delivery has a 1,000 ms limit; do not assume an old context remains valid beyond it.
|
|
409
|
+
Nested or overlapping prompts emit a single start/end pair that closes only after all nested prompts finish, preserving the original `reason`, `kind`, and `title`. Prompt display never waits for observers, so update your tracking state before awaiting async work. During session switches, pending notification delivery has a 1,000 ms limit.
|
|
411
410
|
|
|
412
411
|
```typescript
|
|
413
412
|
atomic.on("ui_prompt_start", (event) => {
|
|
@@ -417,24 +416,25 @@ atomic.on("ui_prompt_start", (event) => {
|
|
|
417
416
|
});
|
|
418
417
|
|
|
419
418
|
atomic.on("ui_prompt_end", (event) => {
|
|
420
|
-
//
|
|
419
|
+
// All prompts in this span have closed.
|
|
421
420
|
});
|
|
422
421
|
```
|
|
423
422
|
|
|
424
|
-
|
|
423
|
+
### turn_start / turn_end
|
|
425
424
|
|
|
426
|
-
Fired
|
|
425
|
+
Fired around each turn (one model response plus its tool calls). `turn_end` runs after the assistant message and tool results persist, and lets extensions append structural entries and request a continuation.
|
|
427
426
|
|
|
428
427
|
```typescript
|
|
429
|
-
atomic.on("turn_start", async (event
|
|
428
|
+
atomic.on("turn_start", async (event) => {
|
|
430
429
|
// event.turnIndex, event.timestamp
|
|
431
430
|
});
|
|
432
431
|
|
|
433
432
|
let replacedResponse = false;
|
|
434
|
-
atomic.on("turn_end", async (event
|
|
433
|
+
atomic.on("turn_end", async (event) => {
|
|
435
434
|
// event.turnIndex, event.message, event.toolResults
|
|
436
435
|
// event.messageEntryId, event.toolResultEntryIds, event.outcome
|
|
437
|
-
// event.entries
|
|
436
|
+
// event.entries - entries proposed by earlier handlers
|
|
437
|
+
// event.context - rebuilt projection (contextEntries, contextMessages, llmMessages, pendingMessages, canContinue)
|
|
438
438
|
if (replacedResponse || event.outcome !== "completed" || event.toolResults.length > 0) return;
|
|
439
439
|
replacedResponse = true;
|
|
440
440
|
return {
|
|
@@ -453,148 +453,128 @@ atomic.on("turn_end", async (event, ctx) => {
|
|
|
453
453
|
});
|
|
454
454
|
```
|
|
455
455
|
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
Boundary handlers run in extension load and registration order. Each handler sees earlier proposals in `event.entries` and `event.context` rebuilt from them (`contextEntries`, `contextMessages`, `llmMessages`, `pendingMessages`, `canContinue`). Returning `entries` or `continue` replaces only that field; omitted fields keep the current proposal.
|
|
456
|
+
Boundary rules shared by `turn_end` and `agent_before_settle`:
|
|
459
457
|
|
|
460
|
-
Allowed draft entry types are `custom`, `custom_message`, `context_edit`, and `compaction` (`summary`
|
|
458
|
+
- Allowed draft entry types are `custom`, `custom_message`, `context_edit`, and `compaction` (`summary` text with `firstKeptEntryId: null`).
|
|
459
|
+
- Returning `entries` or `continue` updates only that field; omitted fields keep earlier handlers' proposals.
|
|
460
|
+
- Atomic validates the combined proposal before appending entries in order. A handler error is reported without stopping later handlers.
|
|
461
|
+
- `continue: true` ensures one next model request when tool results, steering, or follow-ups do not already trigger one. Always guard `continue: true` so it cannot loop indefinitely. Error and aborted outcomes stop regardless.
|
|
461
462
|
|
|
462
|
-
|
|
463
|
+
### message_start / message_update / message_end
|
|
463
464
|
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
- `message_start` and `message_end` fire for user, assistant, and toolResult messages.
|
|
469
|
-
- `message_update` fires for assistant streaming updates.
|
|
470
|
-
- `message_end` handlers can return `{ message }` to replace the finalized message. The replacement must keep the same `role`.
|
|
465
|
+
- `message_start` and `message_end` fire for `user`, `assistant`, and `toolResult` messages.
|
|
466
|
+
- `message_update` fires for streaming assistant deltas (`event.assistantMessageEvent`).
|
|
467
|
+
- `message_end` handlers can return `{ message }` to replace the finalized message. The replacement must keep the same `role`; returning a different `role` reports an extension error and ignores that handler's replacement (keeping the previous message).
|
|
471
468
|
|
|
472
469
|
```typescript
|
|
473
|
-
atomic.on("message_start", async (event
|
|
470
|
+
atomic.on("message_start", async (event) => {
|
|
474
471
|
// event.message
|
|
475
472
|
});
|
|
476
473
|
|
|
477
|
-
atomic.on("message_update", async (event
|
|
478
|
-
// event.assistantMessageEvent (token-by-token delta
|
|
474
|
+
atomic.on("message_update", async (event) => {
|
|
475
|
+
// event.assistantMessageEvent (token-by-token delta)
|
|
479
476
|
});
|
|
480
477
|
|
|
481
|
-
atomic.on("message_end", async (event
|
|
478
|
+
atomic.on("message_end", async (event) => {
|
|
482
479
|
if (event.message.role !== "assistant") return;
|
|
483
|
-
|
|
484
480
|
return {
|
|
485
481
|
message: {
|
|
486
482
|
...event.message,
|
|
487
|
-
usage: {
|
|
488
|
-
...event.message.usage,
|
|
489
|
-
cost: {
|
|
490
|
-
...event.message.usage.cost,
|
|
491
|
-
total: 0.123,
|
|
492
|
-
},
|
|
493
|
-
},
|
|
483
|
+
usage: { ...event.message.usage, cost: { ...event.message.usage.cost, total: 0.123 } },
|
|
494
484
|
},
|
|
495
485
|
};
|
|
496
486
|
});
|
|
497
487
|
```
|
|
498
488
|
|
|
499
|
-
|
|
489
|
+
### tool_execution_start / tool_execution_update / tool_execution_end
|
|
500
490
|
|
|
501
|
-
Fired
|
|
491
|
+
Fired around each tool execution. Nested tool calls invoked through `ctx.executeTool()` include `event.parentToolCallId`.
|
|
502
492
|
|
|
503
493
|
In parallel tool mode:
|
|
504
|
-
|
|
505
|
-
- `
|
|
506
|
-
- `
|
|
507
|
-
-
|
|
494
|
+
|
|
495
|
+
- `tool_execution_start` fires in assistant message order while calls are checked sequentially before parallel execution begins.
|
|
496
|
+
- `tool_execution_update` events can interleave across concurrent calls.
|
|
497
|
+
- `tool_execution_end` fires in completion order (`durationMs` measures time spent in `execute()` via a monotonic clock, or is omitted if the tool did not run).
|
|
498
|
+
- Final `toolResult` message events still emit in assistant message order.
|
|
508
499
|
|
|
509
500
|
```typescript
|
|
510
|
-
atomic.on("tool_execution_start", async (event
|
|
511
|
-
// event.toolCallId, event.toolName, event.args
|
|
501
|
+
atomic.on("tool_execution_start", async (event) => {
|
|
502
|
+
// event.toolCallId, event.toolName, event.args, event.parentToolCallId?
|
|
512
503
|
});
|
|
513
504
|
|
|
514
|
-
atomic.on("tool_execution_update", async (event
|
|
515
|
-
// event.toolCallId, event.toolName, event.args, event.partialResult
|
|
505
|
+
atomic.on("tool_execution_update", async (event) => {
|
|
506
|
+
// event.toolCallId, event.toolName, event.args, event.partialResult, event.parentToolCallId?
|
|
516
507
|
});
|
|
517
508
|
|
|
518
|
-
atomic.on("tool_execution_end", async (event
|
|
519
|
-
// event.toolCallId, event.toolName, event.result, event.isError, event.durationMs
|
|
509
|
+
atomic.on("tool_execution_end", async (event) => {
|
|
510
|
+
// event.toolCallId, event.toolName, event.result, event.isError, event.durationMs, event.parentToolCallId?
|
|
520
511
|
});
|
|
521
512
|
```
|
|
522
513
|
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
#### context
|
|
514
|
+
### context
|
|
526
515
|
|
|
527
|
-
Fired before each
|
|
516
|
+
Fired before each model request to filter or adjust conversation messages non-destructively. If tool output crossed the compaction threshold, the context-size check and compaction finish before `context` runs, so `event.messages` reflects the compacted transcript.
|
|
528
517
|
|
|
529
518
|
```typescript
|
|
530
|
-
atomic.on("context", async (event
|
|
519
|
+
atomic.on("context", async (event) => {
|
|
531
520
|
// event.messages - deep copy without system messages, safe to modify
|
|
532
|
-
const filtered = event.messages.filter(m => !shouldPrune(m));
|
|
521
|
+
const filtered = event.messages.filter((m) => !shouldPrune(m));
|
|
533
522
|
return { messages: filtered };
|
|
534
523
|
});
|
|
535
524
|
```
|
|
536
525
|
|
|
537
|
-
`event.messages`
|
|
538
|
-
|
|
539
|
-
An unchanged list keeps mid-conversation system messages in place so models that accept them keep their cached prefix. System messages a handler adds stay after Atomic's leading message. To change the prompt or tool set durably, use [`before_agent_start`](#before_agent_start) or `atomic.setActiveTools()`; to edit system messages for one request, use [`context_with_system`](#context_with_system).
|
|
526
|
+
`event.messages` excludes system messages so filtering cannot drop Atomic's prompt or tool declarations. When a handler modifies or returns a new message list, Atomic replays the active prompt sections and tool declarations into one leading system message ahead of your returned messages. Leaving `event.messages` unchanged preserves mid-conversation system patches for prompt caching. To change prompts or tools durably, use [`before_agent_start`](#before_agent_start) or `atomic.setActiveTools()`; to edit system messages directly for one request, use [`context_with_system`](#context_with_system).
|
|
540
527
|
|
|
541
|
-
|
|
528
|
+
### context_with_system
|
|
542
529
|
|
|
543
|
-
Fired
|
|
530
|
+
Fired after every `context` handler runs and Atomic restores prompt and tool state. `event.messages` contains the complete transcript including system messages. The returned list is sent verbatim.
|
|
544
531
|
|
|
545
532
|
```typescript
|
|
546
533
|
import { getCurrentSystemMessage } from "@bastani/atomic-ai";
|
|
547
534
|
|
|
548
|
-
atomic.on("context_with_system", async (event
|
|
535
|
+
atomic.on("context_with_system", async (event) => {
|
|
549
536
|
const cut = findCutIndex(event.messages);
|
|
550
|
-
// Fold the dropped prefix so its prompt and tool state survives as the new head.
|
|
551
537
|
const head = getCurrentSystemMessage(event.messages.slice(0, cut));
|
|
552
538
|
return { messages: head ? [head, ...event.messages.slice(cut)] : event.messages.slice(cut) };
|
|
553
539
|
});
|
|
554
540
|
```
|
|
555
541
|
|
|
556
|
-
|
|
542
|
+
Keep a system message at index `0` (dropping it triggers an extension error). Verify your result with `getCurrentSystemPrompt()` and `getCurrentTools()` from `@bastani/atomic-ai`. A `systemPrompt` forced in `before_agent_start` still applies afterward.
|
|
557
543
|
|
|
558
|
-
|
|
544
|
+
### before_provider_headers
|
|
559
545
|
|
|
560
|
-
|
|
546
|
+
Fired after outgoing HTTP headers are assembled. `event` contains only `{ type: "before_provider_headers", headers }`; read `ctx.model` if you need the active provider or model ID. Mutate `event.headers` in place to add, change, or remove headers.
|
|
561
547
|
|
|
562
|
-
|
|
548
|
+
Atomic's default `User-Agent` and provider attribution headers (OpenRouter, NVIDIA NIM, OpenCode) are added afterward, so headers you set here or in `models.json` take precedence. For OpenCode models, `x-opencode-session` is already present and can be read, replaced, or deleted. Fires again if Atomic retries a request with updated credentials.
|
|
563
549
|
|
|
564
550
|
```typescript
|
|
565
551
|
atomic.on("before_provider_headers", (event, ctx) => {
|
|
566
|
-
|
|
552
|
+
if (ctx.model?.provider === "openai") {
|
|
553
|
+
event.headers["x-session-id"] = ctx.sessionManager.getSessionId();
|
|
554
|
+
}
|
|
567
555
|
delete event.headers["x-remove-me"];
|
|
568
556
|
});
|
|
569
557
|
```
|
|
570
558
|
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
Fired after the provider-specific payload is built, right before the request is sent. Handlers run in extension load order. Returning `undefined` keeps the payload unchanged. Returning any other value replaces the payload for later handlers and for the actual request.
|
|
559
|
+
### before_provider_request
|
|
574
560
|
|
|
575
|
-
|
|
561
|
+
Fired right before sending the serialized provider request body. Handlers run in load order; returning `undefined` leaves the payload unchanged, while returning any other value replaces the payload for later handlers and the request. Fires again on credential-refresh retries.
|
|
576
562
|
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
The payload is the full request. Providers that continue from a previous response (OpenAI Codex over WebSocket, Anthropic message threads) may send only the part that is new since the previous request.
|
|
563
|
+
Payload edits here do not update `ctx.getSystemPrompt()`. Providers using stateful continuations (OpenAI Codex WebSockets, Anthropic threads) may send only the new delta since the prior request.
|
|
580
564
|
|
|
581
565
|
```typescript
|
|
582
|
-
atomic.on("before_provider_request", (event
|
|
566
|
+
atomic.on("before_provider_request", (event) => {
|
|
583
567
|
console.log(JSON.stringify(event.payload, null, 2));
|
|
584
|
-
|
|
585
|
-
// Optional: replace payload
|
|
586
|
-
// return { ...event.payload, temperature: 0 };
|
|
568
|
+
// Optional: return { ...event.payload, temperature: 0 };
|
|
587
569
|
});
|
|
588
570
|
```
|
|
589
571
|
|
|
590
|
-
|
|
572
|
+
### after_provider_response
|
|
591
573
|
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
Fired after an HTTP response is received and before its stream body is consumed. Handlers run in extension load order.
|
|
574
|
+
Fired after an HTTP response arrives and before its stream body is consumed. Header availability depends on the provider transport.
|
|
595
575
|
|
|
596
576
|
```typescript
|
|
597
|
-
atomic.on("after_provider_response", (event
|
|
577
|
+
atomic.on("after_provider_response", (event) => {
|
|
598
578
|
// event.status - HTTP status code
|
|
599
579
|
// event.headers - normalized response headers
|
|
600
580
|
if (event.status === 429) {
|
|
@@ -603,66 +583,50 @@ atomic.on("after_provider_response", (event, ctx) => {
|
|
|
603
583
|
});
|
|
604
584
|
```
|
|
605
585
|
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
#### provider_stream_event
|
|
586
|
+
### provider_stream_event
|
|
609
587
|
|
|
610
|
-
Fired for each parsed provider stream
|
|
588
|
+
Fired for each parsed provider stream chunk before Atomic normalizes it into assistant message events.
|
|
611
589
|
|
|
612
590
|
```typescript
|
|
613
|
-
atomic.on("provider_stream_event", (event
|
|
614
|
-
// event.provider, event.api, event.model
|
|
615
|
-
// event.data -
|
|
591
|
+
atomic.on("provider_stream_event", (event) => {
|
|
592
|
+
// event.provider, event.api, event.model
|
|
593
|
+
// event.data - parsed provider chunk (treat as read-only)
|
|
616
594
|
const chunk = event.data as Record<string, unknown>;
|
|
617
595
|
if (chunk.openrouter_metadata) console.log(chunk.openrouter_metadata);
|
|
618
596
|
});
|
|
619
597
|
```
|
|
620
598
|
|
|
621
|
-
|
|
599
|
+
Notification-only and not persisted to the session; cache-warming requests do not emit it. Handlers are awaited in stream order, so keep them fast. Custom providers using `streamSimple` emit this event only when they call `options.onProviderStreamEvent`. See [`debug-provider.ts`](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/debug-provider.ts).
|
|
622
600
|
|
|
623
|
-
|
|
601
|
+
## Model events
|
|
624
602
|
|
|
625
|
-
###
|
|
603
|
+
### model_select
|
|
626
604
|
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
Fired when the model changes via `/model`, model cycling (`Ctrl+P`), session restore, or fallback selection.
|
|
605
|
+
Fired when the active model changes via `/model`, `Ctrl+P`, session restore, or fallback selection.
|
|
630
606
|
|
|
631
607
|
```typescript
|
|
632
608
|
atomic.on("model_select", async (event, ctx) => {
|
|
633
|
-
// event.model
|
|
634
|
-
// event.previousModel - previous model (undefined if first selection)
|
|
609
|
+
// event.model, event.previousModel (undefined on initial selection)
|
|
635
610
|
// event.source - "set" | "cycle" | "restore" | "fallback"
|
|
636
|
-
|
|
637
|
-
const prev = event.previousModel
|
|
638
|
-
? `${event.previousModel.provider}/${event.previousModel.id}`
|
|
639
|
-
: "none";
|
|
640
611
|
const next = `${event.model.provider}/${event.model.id}`;
|
|
641
|
-
|
|
642
|
-
ctx.ui.notify(`Model changed (${event.source}): ${prev} to ${next}`, "info");
|
|
612
|
+
ctx.ui.notify(`Model changed (${event.source}): ${next}`, "info");
|
|
643
613
|
});
|
|
644
614
|
```
|
|
645
615
|
|
|
646
|
-
|
|
616
|
+
### thinking_level_select
|
|
647
617
|
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
Fired when the thinking level changes. This is notification-only; handler return values are ignored.
|
|
618
|
+
Notification-only event fired when the thinking level changes via settings, keybindings, model clamping, or `atomic.setThinkingLevel()`.
|
|
651
619
|
|
|
652
620
|
```typescript
|
|
653
621
|
atomic.on("thinking_level_select", async (event, ctx) => {
|
|
654
|
-
// event.level
|
|
655
|
-
// event.previousLevel - previous thinking level
|
|
656
|
-
|
|
622
|
+
// event.level, event.previousLevel
|
|
657
623
|
ctx.ui.setStatus("thinking", `thinking: ${event.level}`);
|
|
658
624
|
});
|
|
659
625
|
```
|
|
660
626
|
|
|
661
|
-
|
|
627
|
+
### cache_warming_decision
|
|
662
628
|
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
Fired when prompt cache warming evaluates whether to send a warming request. Handlers run in load order and receive `warmCost`, `missCost`, `continuationProbability`, and the current `action` (`"warm"` or `"stop"`). Return `{ action: "warm" }` or `{ action: "stop" }` to override the decision for later handlers and the cache warmer.
|
|
629
|
+
Fired when prompt cache warming decides whether to send a warming request. Handlers run in load order and receive `warmCost`, `missCost`, `continuationProbability`, and the current `action` (`"warm"` or `"stop"`). Return `{ action: "warm" }` or `{ action: "stop" }` to override the decision for later handlers and the warmer.
|
|
666
630
|
|
|
667
631
|
```typescript
|
|
668
632
|
atomic.on("cache_warming_decision", (event) => {
|
|
@@ -672,57 +636,42 @@ atomic.on("cache_warming_decision", (event) => {
|
|
|
672
636
|
});
|
|
673
637
|
```
|
|
674
638
|
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
#### tool_call
|
|
639
|
+
## Tool events
|
|
678
640
|
|
|
679
|
-
|
|
641
|
+
### tool_call
|
|
680
642
|
|
|
681
|
-
|
|
643
|
+
Fired after `tool_execution_start` and before `execute()`. **Can block or patch arguments.**
|
|
682
644
|
|
|
683
|
-
|
|
645
|
+
Before `tool_call` runs, `ctx.sessionManager` is synced through the current assistant tool-calling message. In parallel tool mode, sibling calls from the same assistant message are checked sequentially before running concurrently, so `tool_call` may not see sibling tool results from that message. Nested `ctx.executeTool()` calls run `tool_call` too and include `event.parentToolCallId` (see [Structured results and nested tools](/extensions/authoring#structured-results-and-nested-tools)).
|
|
684
646
|
|
|
685
|
-
|
|
647
|
+
Chaining and mutation rules:
|
|
686
648
|
|
|
687
|
-
`event.input` is mutable
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
-
|
|
691
|
-
- Later `tool_call` handlers see mutations made by earlier handlers
|
|
692
|
-
- No re-validation is performed after your mutation
|
|
693
|
-
- Return values from `tool_call` control blocking via `{ block: true, reason?: string, terminate?: boolean }`
|
|
694
|
-
- `terminate` only applies to a blocked call; the agent stops early only when every finalized result in the batch is terminating
|
|
649
|
+
- `event.input` is mutable; later `tool_call` handlers and `execute()` see in-place edits without re-validation.
|
|
650
|
+
- The **first** handler returning `{ block: true, reason?, terminate? }` immediately short-circuits later handlers and blocks the tool call.
|
|
651
|
+
- If a `tool_call` handler **throws an error**, Atomic immediately blocks the tool call with that error and skips remaining handlers.
|
|
652
|
+
- `terminate: true` applies only on a blocked call; the turn ends early only when every finalized result in the batch is terminating.
|
|
695
653
|
|
|
696
654
|
```typescript
|
|
697
655
|
import { isToolCallEventType } from "@bastani/atomic";
|
|
698
656
|
|
|
699
|
-
atomic.on("tool_call", async (event
|
|
700
|
-
// event.toolName
|
|
701
|
-
// event.toolCallId
|
|
702
|
-
// event.input - tool parameters (mutable)
|
|
703
|
-
|
|
704
|
-
// Built-in tools: no type params needed
|
|
657
|
+
atomic.on("tool_call", async (event) => {
|
|
658
|
+
// event.toolName, event.toolCallId, event.input (mutable), event.parentToolCallId?
|
|
705
659
|
if (isToolCallEventType("bash", event)) {
|
|
706
|
-
// event.input is { command: string; timeout?: number }
|
|
707
660
|
event.input.command = `source ~/.profile\n${event.input.command}`;
|
|
708
|
-
|
|
709
661
|
if (event.input.command.includes("rm -rf")) {
|
|
710
662
|
return { block: true, reason: "Dangerous command", terminate: true };
|
|
711
663
|
}
|
|
712
664
|
}
|
|
713
665
|
|
|
714
666
|
if (isToolCallEventType("powershell", event)) {
|
|
715
|
-
// event.input is typed as PowerShellToolInput
|
|
716
667
|
event.input.command = `$ErrorActionPreference = "Stop"\n${event.input.command}`;
|
|
717
668
|
}
|
|
718
669
|
|
|
719
670
|
if (isToolCallEventType("read", event)) {
|
|
720
|
-
// event.input is { path: string }
|
|
721
671
|
console.log(`Reading: ${event.input.path}`);
|
|
722
672
|
}
|
|
723
673
|
|
|
724
674
|
if (isToolCallEventType("search", event)) {
|
|
725
|
-
// event.input is typed as SearchToolInput
|
|
726
675
|
event.input.paths ??= ".";
|
|
727
676
|
}
|
|
728
677
|
});
|
|
@@ -730,58 +679,53 @@ atomic.on("tool_call", async (event, ctx) => {
|
|
|
730
679
|
|
|
731
680
|
#### Typing custom tool input
|
|
732
681
|
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
```typescript
|
|
736
|
-
// my-extension.ts
|
|
737
|
-
export type MyToolInput = Static<typeof myToolSchema>;
|
|
738
|
-
```
|
|
739
|
-
|
|
740
|
-
Use `isToolCallEventType` with explicit type parameters:
|
|
682
|
+
Export the static input type from your tool module and pass type arguments to `isToolCallEventType`:
|
|
741
683
|
|
|
742
684
|
```typescript
|
|
743
685
|
import { isToolCallEventType } from "@bastani/atomic";
|
|
744
|
-
import type { MyToolInput } from "my-
|
|
686
|
+
import type { MyToolInput } from "./my-tool.js";
|
|
745
687
|
|
|
746
688
|
atomic.on("tool_call", (event) => {
|
|
747
689
|
if (isToolCallEventType<"my_tool", MyToolInput>("my_tool", event)) {
|
|
748
|
-
event.input.action;
|
|
690
|
+
console.log(event.input.action);
|
|
749
691
|
}
|
|
750
692
|
});
|
|
751
693
|
```
|
|
752
694
|
|
|
753
|
-
|
|
695
|
+
### tool_result
|
|
754
696
|
|
|
755
|
-
Fired after tool
|
|
697
|
+
Fired after a tool finishes and before `tool_execution_end` and the final `toolResult` message event. **Can modify the result.**
|
|
756
698
|
|
|
757
|
-
In parallel
|
|
699
|
+
In parallel mode, `tool_result` runs in tool completion order while final `toolResult` transcript messages still emit in assistant message order.
|
|
758
700
|
|
|
759
|
-
`
|
|
760
|
-
- Handlers run in extension load order
|
|
761
|
-
- Each handler sees the latest result after previous handler changes
|
|
762
|
-
- Handlers can return partial patches (`content`, `structuredContent`, `details`, `usage`, or `isError`); omitted fields keep their current values, except replacing `content` without replacing `structuredContent` drops the structured value
|
|
701
|
+
Handlers chain in extension load order, each seeing prior changes. Return partial patches for `content`, `structuredContent`, `details`, `usage`, or `isError`. Omitted fields stay unchanged, except replacing `content` without replacing `structuredContent` drops `structuredContent` so redacted data cannot leak. After all handlers finish, Atomic applies `images.autoResize` to returned images.
|
|
763
702
|
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
Use `ctx.signal` for nested async work inside the handler. This lets Escape cancel model calls, `fetch()`, and other abort-aware operations started by the extension.
|
|
703
|
+
Built-in result type guards exported from `@bastani/atomic`: `isBashToolResult`, `isPowerShellToolResult`, `isReadToolResult`, `isEditToolResult`, `isWriteToolResult`, `isFindToolResult`, `isSearchToolResult`, and `isLsToolResult`.
|
|
767
704
|
|
|
768
705
|
```typescript
|
|
769
|
-
import {
|
|
706
|
+
import {
|
|
707
|
+
isBashToolResult,
|
|
708
|
+
isEditToolResult,
|
|
709
|
+
isFindToolResult,
|
|
710
|
+
isLsToolResult,
|
|
711
|
+
isPowerShellToolResult,
|
|
712
|
+
isReadToolResult,
|
|
713
|
+
isSearchToolResult,
|
|
714
|
+
isWriteToolResult,
|
|
715
|
+
} from "@bastani/atomic";
|
|
770
716
|
|
|
771
717
|
atomic.on("tool_result", async (event, ctx) => {
|
|
772
|
-
// event.toolName, event.toolCallId, event.input
|
|
773
|
-
// event.content, event.details, event.isError
|
|
718
|
+
// event.toolName, event.toolCallId, event.input, event.parentToolCallId?
|
|
719
|
+
// event.content, event.structuredContent, event.details, event.usage, event.isError
|
|
774
720
|
|
|
775
721
|
if (isBashToolResult(event)) {
|
|
776
|
-
// event.details is
|
|
722
|
+
// event.details is BashToolDetails | undefined
|
|
777
723
|
}
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
// event.details is typed as PowerShellToolDetails | undefined
|
|
724
|
+
if (isReadToolResult(event) || isEditToolResult(event) || isWriteToolResult(event)) {
|
|
725
|
+
// Narrowed built-in details types
|
|
781
726
|
}
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
// event.details is typed as SearchToolDetails | undefined
|
|
727
|
+
if (isFindToolResult(event) || isSearchToolResult(event) || isLsToolResult(event) || isPowerShellToolResult(event)) {
|
|
728
|
+
// Narrowed built-in details types
|
|
785
729
|
}
|
|
786
730
|
|
|
787
731
|
const response = await fetch("https://example.com/summarize", {
|
|
@@ -790,97 +734,86 @@ atomic.on("tool_result", async (event, ctx) => {
|
|
|
790
734
|
signal: ctx.signal,
|
|
791
735
|
});
|
|
792
736
|
|
|
793
|
-
|
|
794
|
-
return { content: [...], details: {...}, isError: false };
|
|
737
|
+
return { content: event.content, details: await response.json(), isError: false };
|
|
795
738
|
});
|
|
796
739
|
```
|
|
797
740
|
|
|
798
|
-
|
|
741
|
+
## User bash events
|
|
799
742
|
|
|
800
|
-
|
|
743
|
+
### user_bash
|
|
801
744
|
|
|
802
|
-
Fired when user
|
|
745
|
+
Fired when the user runs `!` or `!!` shell commands. Return `{ operations }` to customize execution (optionally wrapping `createLocalBashOperations()` from `@bastani/atomic`) or `{ result }` to return a result directly.
|
|
803
746
|
|
|
804
747
|
```typescript
|
|
805
748
|
import { createLocalBashOperations } from "@bastani/atomic";
|
|
806
749
|
|
|
807
|
-
atomic.on("user_bash", (event
|
|
808
|
-
// event.command
|
|
809
|
-
// event.excludeFromContext - true if !! prefix
|
|
810
|
-
// event.cwd - working directory
|
|
750
|
+
atomic.on("user_bash", (event) => {
|
|
751
|
+
// event.command, event.excludeFromContext (true for !!), event.cwd
|
|
811
752
|
|
|
812
|
-
// Option 1:
|
|
813
|
-
return { operations: remoteBashOps };
|
|
753
|
+
// Option 1: Custom operations (such as SSH)
|
|
754
|
+
// return { operations: remoteBashOps };
|
|
814
755
|
|
|
815
|
-
// Option 2: Wrap
|
|
756
|
+
// Option 2: Wrap Atomic's local bash backend
|
|
816
757
|
const local = createLocalBashOperations();
|
|
817
758
|
return {
|
|
818
759
|
operations: {
|
|
819
760
|
exec(command, cwd, options) {
|
|
820
761
|
return local.exec(`source ~/.profile\n${command}`, cwd, options);
|
|
821
|
-
}
|
|
822
|
-
}
|
|
762
|
+
},
|
|
763
|
+
},
|
|
823
764
|
};
|
|
824
765
|
|
|
825
|
-
// Option 3: Full replacement
|
|
826
|
-
return { result: { output: "...", exitCode: 0, cancelled: false, truncated: false } };
|
|
766
|
+
// Option 3: Full replacement
|
|
767
|
+
// return { result: { output: "...", exitCode: 0, cancelled: false, truncated: false } };
|
|
827
768
|
});
|
|
828
769
|
```
|
|
829
770
|
|
|
830
|
-
|
|
771
|
+
## Input events
|
|
831
772
|
|
|
832
|
-
|
|
773
|
+
### input
|
|
833
774
|
|
|
834
|
-
Fired
|
|
835
|
-
|
|
836
|
-
Direct `session.steer()` and `session.followUp()` calls also run input handlers before skill and template expansion and queue admission. Handled input is not queued; transformed text and images are queued instead. Their optional third argument sets `source`, defaulting to `interactive`; RPC queue commands use `rpc`.
|
|
775
|
+
Fired on user input after extension commands are checked and before `/skill:` and prompt template expansion. Direct `session.steer()` and `session.followUp()` calls also run `input` handlers before queueing (`source` defaults to `"interactive"`, or `"rpc"` for RPC queue commands).
|
|
837
776
|
|
|
838
777
|
Processing order:
|
|
839
778
|
|
|
840
|
-
1. Extension commands (`/cmd`)
|
|
841
|
-
2.
|
|
842
|
-
3. If not handled, skill commands
|
|
843
|
-
4. If not handled, prompt templates (`/template`) expand
|
|
844
|
-
5. Agent
|
|
779
|
+
1. Extension slash commands (`/cmd`) match first and skip `input`.
|
|
780
|
+
2. `input` handlers run and can return `"continue"`, `"transform"`, or `"handled"`.
|
|
781
|
+
3. If not handled, `/skill:<name>` commands expand.
|
|
782
|
+
4. If not handled, prompt templates (`/template`) expand.
|
|
783
|
+
5. Agent execution begins (`before_agent_start`).
|
|
784
|
+
|
|
785
|
+
`event.streamingBehavior` tells you whether the input is an immediate submission (`undefined`) or queued while a turn is running (`"steer"` or `"followUp"`):
|
|
845
786
|
|
|
846
787
|
```typescript
|
|
847
788
|
atomic.on("input", async (event, ctx) => {
|
|
848
|
-
// event.text - raw
|
|
789
|
+
// event.text - raw text before skill/template expansion
|
|
849
790
|
// event.images - attached images, if any
|
|
850
|
-
// event.source - "interactive"
|
|
791
|
+
// event.source - "interactive" | "rpc" | "extension"
|
|
792
|
+
// event.streamingBehavior - undefined (immediate) | "steer" | "followUp" (queued while streaming)
|
|
851
793
|
|
|
852
|
-
|
|
853
|
-
if (event.text.startsWith("?quick "))
|
|
794
|
+
if (event.text.startsWith("?quick ")) {
|
|
854
795
|
return { action: "transform", text: `Respond briefly: ${event.text.slice(7)}` };
|
|
796
|
+
}
|
|
855
797
|
|
|
856
|
-
// Handle: respond without LLM (extension shows its own feedback)
|
|
857
798
|
if (event.text === "ping") {
|
|
858
799
|
ctx.ui.notify("pong", "info");
|
|
859
800
|
return { action: "handled" };
|
|
860
801
|
}
|
|
861
802
|
|
|
862
|
-
// Route by source: skip processing for extension-injected messages
|
|
863
803
|
if (event.source === "extension") return { action: "continue" };
|
|
864
804
|
|
|
865
|
-
|
|
866
|
-
if (event.text.startsWith("/skill:")) {
|
|
867
|
-
// Could transform, block, or let pass through
|
|
868
|
-
}
|
|
869
|
-
|
|
870
|
-
return { action: "continue" }; // Default: pass through to expansion
|
|
805
|
+
return { action: "continue" };
|
|
871
806
|
});
|
|
872
807
|
```
|
|
873
808
|
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
- `continue`. Pass through unchanged (default when a handler returns nothing).
|
|
877
|
-
- `transform`. Modify text or images, then continue to expansion.
|
|
878
|
-
- `handled`. Skip the agent completely (the first handler returning `handled` wins).
|
|
809
|
+
Return actions:
|
|
879
810
|
|
|
880
|
-
|
|
811
|
+
- `"continue"`: pass through unchanged (default when returning `undefined`).
|
|
812
|
+
- `"transform"`: replace `text` or `images` and continue to later handlers and expansion. Transformed text is what enters the session and `Ctrl+R` search, while Up/Down editor history keeps what you typed.
|
|
813
|
+
- `"handled"`: stop processing without sending to the model (first `"handled"` result wins).
|
|
881
814
|
|
|
882
|
-
|
|
815
|
+
See [input-transform.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/input-transform.ts) and [input-transform-streaming.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/input-transform-streaming.ts).
|
|
883
816
|
|
|
884
817
|
## Next steps
|
|
885
818
|
|
|
886
|
-
Continue with [
|
|
819
|
+
Continue with [Extension UI](/extensions/ui) to add dialogs, pickers, widgets, and custom components, or inspect all context properties in the [Extension API reference](/extensions/api-reference#extensioncontext).
|