@bastani/atomic 0.10.14 → 0.10.15-alpha.1
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 +17 -0
- 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 +3 -3
- package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js +3 -3
- package/dist/_shared/mode-shared-2QJSCUM6.js +3 -3
- package/dist/_shared/p1a-prewarm-XIU57JHF.js +3 -3
- package/dist/_shared/runtime-O4KCSG4C.js +2 -2
- package/dist/_shared/{sdk-B5LEWGGI.js → sdk-OHKMDJ74.js} +27 -5
- package/dist/_shared/{sdk-B5LEWGGI.js.map → sdk-OHKMDJ74.js.map} +1 -1
- package/dist/_shared/session-data-AHTU7IS6.js +2 -2
- package/dist/_shared/startup-0-0-Q3MWKUK4.js +2 -2
- package/dist/_shared/startup-0-1-M6OWAYHH.js +2 -2
- package/dist/_shared/{startup-0-2-5QHPCEON.js → startup-0-2-2HUMCPKX.js} +14 -16
- package/dist/_shared/startup-0-2-2HUMCPKX.js.map +1 -0
- package/dist/_shared/startup-0-3-4ZYBYQNM.js +3 -3
- package/dist/_shared/startup-0-4-ZMJV547D.js +3 -3
- package/dist/_shared/startup-0-5-YDW47QX6.js +3 -3
- package/dist/_shared/startup-10-0-TDQNBDDL.js +3 -3
- package/dist/_shared/startup-14-0-MLX36RBG.js +1 -1
- package/dist/_shared/startup-15-0-YUKGAC63.js +1 -1
- package/dist/_shared/startup-15-1-4S7FLMNG.js +6 -30
- package/dist/_shared/startup-15-1-4S7FLMNG.js.map +1 -1
- package/dist/_shared/startup-8-0-34CBHPZH.js +3 -3
- package/dist/_shared/startup-8-1-LZFXSD3Z.js +3 -3
- package/dist/_shared/storage-command-7MGXLJGZ.js +2 -2
- package/dist/_shared/storage-status-K7PX2RXA.js +3 -3
- package/dist/_shared/task-unsaved-answer-VJ2KTB4V.js +2 -2
- package/dist/_shared/tree-outline-MUEPK5B7.js +2 -2
- package/dist/builtin/intercom/index.bundle.mjs +1 -1
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/index.bundle.mjs +1 -1
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +1 -1
- package/dist/builtin/web-access/index.bundle.mjs +1 -1
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/cli/auth-cli.code.js +1 -1
- package/dist/cli/auth-cli.impl.js +3 -3
- package/dist/cli/auth-cli.js +3 -3
- 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.impl.js +3 -3
- package/dist/cli/list-models.js +3 -3
- package/dist/cli/session-picker.code.js +1 -1
- package/dist/cli/session-picker.impl.js +3 -3
- package/dist/cli/session-picker.js +3 -3
- package/dist/cli/startup-ui.code.js +1 -1
- 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 +1 -1
- 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 +1 -1
- 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/compaction/compactor.d.ts +0 -8
- 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.impl.js +3 -3
- package/dist/core/export-html/tool-renderer.js +3 -3
- 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.impl.js +3 -3
- package/dist/core/extensions/loader-host-modules.js +3 -3
- 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 +2 -2
- package/dist/core/intercom-broker-control.impl.js +3 -3
- package/dist/core/intercom-broker-control.js +3 -3
- package/dist/core/package-manager-storage-adapters.impl.js +3 -3
- package/dist/core/package-manager-storage-adapters.js +3 -3
- package/dist/core/sdk.code.js +1 -1
- package/dist/core/sdk.impl.js +3 -3
- package/dist/core/sdk.js +3 -3
- package/dist/core/session-manager-core.js +3 -3
- package/dist/core/session-manager-list.impl.js +3 -3
- package/dist/core/session-manager-list.js +3 -3
- 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/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 +2 -2
- 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 +1 -1
- 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 +2 -2
- 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 +2 -2
- 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 +1 -1
- 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 +2 -2
- 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 +2 -2
- 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 +2 -2
- package/dist/core/tasks/task-reference-archive.js +3 -3
- 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.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 +1 -1
- 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.impl.js +3 -3
- package/dist/extensions/codemode/execute.js +3 -3
- package/dist/extensions/codemode/renderer.impl.js +3 -3
- package/dist/extensions/codemode/renderer.js +3 -3
- package/dist/extensions/mcp/cli.code.js +1 -1
- 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.d.ts +21 -1
- package/dist/index.js +2 -2
- package/dist/main-first-time-setup.code.js +1 -1
- package/dist/main-first-time-setup.impl.js +3 -3
- package/dist/main-first-time-setup.js +3 -3
- 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/print-mode.js +1 -1
- package/dist/package-manager-cli.code.js +2 -2
- package/dist/package-manager-cli.impl.js +3 -3
- package/dist/package-manager-cli.js +3 -3
- package/dist/startup-files.json +1 -1
- package/dist/startup-stages/6.js +1 -1
- package/dist/utils/startup-database-spare.code.js +1 -1
- package/dist/utils/startup-database-spare.impl.js +3 -3
- package/dist/utils/startup-database-spare.js +3 -3
- package/dist/utils/tools-manager.impl.js +3 -3
- package/dist/utils/tools-manager.js +3 -3
- package/docs/background-tasks/reference.md +182 -0
- package/docs/background-tasks.md +98 -405
- package/docs/build.md +67 -27
- package/docs/changelog.mdx +1 -1
- package/docs/codemode.md +108 -39
- package/docs/compaction/branch-summaries.md +54 -0
- package/docs/compaction/custom-compactors.md +161 -0
- package/docs/compaction/memory-compaction.md +77 -0
- package/docs/compaction/reference.md +86 -38
- package/docs/compaction.md +51 -252
- package/docs/computer-use.md +169 -321
- package/docs/containerization.md +71 -57
- package/docs/custom-provider/api-reference.md +119 -25
- package/docs/custom-provider/oauth.md +114 -132
- package/docs/custom-provider/override.md +37 -27
- package/docs/custom-provider/registration.md +107 -83
- package/docs/custom-provider/streaming.md +85 -71
- package/docs/custom-provider.md +85 -52
- package/docs/development.md +39 -29
- package/docs/docs.json +76 -63
- package/docs/environment-variables.md +94 -44
- package/docs/extensions/api-reference.md +86 -43
- package/docs/extensions/authoring.md +162 -154
- package/docs/extensions/events.md +80 -25
- package/docs/extensions/examples.md +90 -85
- package/docs/extensions/ui.md +206 -82
- package/docs/extensions.md +79 -108
- package/docs/getting-started/authentication.md +67 -36
- package/docs/getting-started/first-session.md +53 -43
- package/docs/getting-started/installation.md +116 -89
- package/docs/getting-started/project-instructions.md +48 -34
- package/docs/guides/configuration.md +82 -20
- package/docs/guides/non-interactive.md +66 -24
- package/docs/guides/resume-on-any-machine.md +135 -82
- package/docs/guides/team-setup.md +114 -105
- package/docs/guides.md +76 -32
- package/docs/herdr.md +15 -16
- package/docs/how-atomic-works.md +140 -0
- package/docs/index.md +58 -44
- package/docs/intercom/operations.md +141 -151
- package/docs/intercom/reference.md +85 -108
- package/docs/intercom.md +84 -145
- package/docs/json.md +120 -67
- package/docs/keybindings.md +85 -49
- package/docs/libraries/agent-core.md +137 -275
- package/docs/libraries/ai.md +100 -84
- package/docs/libraries/codemode.md +210 -300
- package/docs/libraries/schema.md +59 -53
- package/docs/libraries/storage-postgres.md +49 -35
- package/docs/libraries/telemetry.md +153 -354
- package/docs/libraries/tui.md +265 -393
- package/docs/libraries.md +42 -26
- package/docs/llama-cpp.md +171 -161
- package/docs/mcp-servers.md +90 -51
- package/docs/models/choose-a-model.md +188 -0
- package/docs/models/reference.md +74 -30
- package/docs/models.md +153 -88
- package/docs/orchestration/migrating-workflows.md +23 -16
- package/docs/orchestration/patterns.md +39 -44
- package/docs/orchestration.md +65 -26
- package/docs/packages/authoring.md +51 -29
- package/docs/packages/reference.md +42 -21
- package/docs/packages.md +69 -58
- package/docs/programmatic.md +118 -24
- package/docs/prompt-templates.md +84 -83
- package/docs/providers/reference.md +43 -48
- package/docs/providers.md +219 -451
- package/docs/quickstart.md +140 -120
- package/docs/reference/cli.md +135 -97
- package/docs/reference.md +20 -18
- package/docs/rpc/examples.md +76 -20
- package/docs/rpc/extension-ui.md +64 -38
- package/docs/rpc/protocol.md +361 -110
- package/docs/rpc.md +57 -17
- package/docs/sdk/reference.md +409 -534
- package/docs/sdk/storage.md +53 -13
- package/docs/sdk/structured-decisions.md +82 -56
- package/docs/sdk/web-server.md +57 -43
- package/docs/sdk.md +106 -84
- package/docs/security.md +42 -64
- package/docs/session-format.md +62 -38
- package/docs/sessions.md +99 -214
- package/docs/settings.md +165 -195
- package/docs/shell-aliases.md +9 -6
- package/docs/skills/authoring.md +69 -48
- package/docs/skills/reference.md +51 -20
- package/docs/skills.md +99 -148
- package/docs/slash-commands.md +129 -0
- package/docs/storage/custom-adapters.md +160 -85
- package/docs/storage/jsonl.md +81 -66
- package/docs/storage/postgres/pgbouncer.md +120 -126
- package/docs/storage/postgres/tuning.md +120 -143
- package/docs/storage/postgres.md +314 -330
- package/docs/storage/sqlite.md +71 -42
- package/docs/storage.md +298 -302
- package/docs/subagents/authoring.md +55 -38
- package/docs/subagents/reference.md +73 -33
- package/docs/subagents.md +119 -187
- package/docs/terminal-setup.md +50 -38
- package/docs/termux.md +67 -41
- package/docs/themes/reference.md +23 -19
- package/docs/themes.md +142 -127
- package/docs/tmux.md +47 -55
- package/docs/tools.md +147 -109
- package/docs/tui/reference.md +166 -214
- package/docs/tui.md +196 -341
- package/docs/usage.md +118 -138
- package/docs/verification.md +79 -51
- package/docs/web-access.md +121 -101
- package/docs/windows.md +26 -27
- package/docs/worktree-snapshots/reference.md +245 -0
- package/docs/worktree-snapshots.md +71 -259
- package/package.json +8 -8
- package/dist/_shared/startup-0-2-5QHPCEON.js.map +0 -1
- package/docs/guides/intercom.md +0 -32
- package/docs/guides/orchestration.md +0 -28
- package/docs/guides/subagents.md +0 -37
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: "Write an extension"
|
|
3
3
|
sidebarTitle: "Write an extension"
|
|
4
|
-
description: "Structure an extension,
|
|
4
|
+
description: "Structure an extension, manage state across reloads and restarts, build custom tools, and customize terminal rendering."
|
|
5
5
|
---
|
|
6
6
|
|
|
7
7
|
An extension exports a default factory function that receives `ExtensionAPI`. The parameter can have any name; older extensions and examples call it `pi`. The factory can be synchronous or asynchronous:
|
|
@@ -10,7 +10,7 @@ An extension exports a default factory function that receives `ExtensionAPI`. Th
|
|
|
10
10
|
import type { ExtensionAPI } from "@bastani/atomic";
|
|
11
11
|
|
|
12
12
|
export default function (atomic: ExtensionAPI) {
|
|
13
|
-
// Subscribe to events
|
|
13
|
+
// Subscribe to lifecycle events
|
|
14
14
|
atomic.on("event_name", async (event, ctx) => {
|
|
15
15
|
const ok = await ctx.ui.confirm("Title", "Are you sure?");
|
|
16
16
|
ctx.ui.notify("Done!", "info");
|
|
@@ -26,13 +26,7 @@ export default function (atomic: ExtensionAPI) {
|
|
|
26
26
|
}
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
Editable extensions support TypeScript without a separate build step.
|
|
30
|
-
|
|
31
|
-
Imports from Atomic's bundled core packages keep the running host's classes and shared state across `/reload`, including on Windows. The `@earendil-works/pi-coding-agent` compatibility import shares those exports with `@bastani/atomic`, so `instanceof` checks work across both names after reload. Restart Atomic after updating Atomic itself.
|
|
32
|
-
|
|
33
|
-
In Bun single-file builds, bundled built-in packages keep their module-scoped state across `/reload`. Restart Atomic to reload shipped code.
|
|
34
|
-
|
|
35
|
-
If your factory returns a `Promise`, Atomic awaits it before continuing startup. Async initialization completes before `session_start`, before `resources_discover`, and before provider registrations queued with `atomic.registerProvider()` are flushed.
|
|
29
|
+
Editable extensions support TypeScript without a separate build step. If your factory returns a `Promise`, Atomic awaits it before continuing startup—before `session_start`, before `resources_discover`, and before provider registrations queued with `atomic.registerProvider()` are flushed.
|
|
36
30
|
|
|
37
31
|
## Async factory functions
|
|
38
32
|
|
|
@@ -73,7 +67,7 @@ Models registered here become available during normal startup and in `atomic --l
|
|
|
73
67
|
|
|
74
68
|
## Long-lived resources and shutdown
|
|
75
69
|
|
|
76
|
-
Extension factories can run during commands that never start a full session, such as
|
|
70
|
+
Extension factories can run during commands that never start a full session, such as `atomic --help` or `atomic --list-models`. Do not start child processes, sockets, file watchers, or timers directly inside the factory function.
|
|
77
71
|
|
|
78
72
|
Start background resources inside `session_start` or inside the command, tool, or event handler that needs them. Register an idempotent `session_shutdown` handler to close every resource you open.
|
|
79
73
|
|
|
@@ -125,15 +119,19 @@ Use `"atomic"` as the manifest key (legacy `"pi"` is also accepted). Run `npm in
|
|
|
125
119
|
|
|
126
120
|
## State management
|
|
127
121
|
|
|
128
|
-
Choose the store that matches the lifetime
|
|
122
|
+
Choose the store that matches the lifetime your extension needs:
|
|
129
123
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
124
|
+
| What you need | Use this | Survives `/reload`? | Survives restarts & `/branch`? |
|
|
125
|
+
| --- | --- | --- | --- |
|
|
126
|
+
| State tied to conversation branches | Tool result `details` | Yes (rebuilt from transcript) | Yes (follows `/branch`, `/tree`, `/resume`) |
|
|
127
|
+
| Durable session data hidden from the model | `atomic.appendEntry()` | Yes | Yes |
|
|
128
|
+
| Live in-memory handles (pools, registries, counters) | `sessionScopedExtensionState()` | Yes | No (reset on process restart) |
|
|
133
129
|
|
|
134
|
-
|
|
130
|
+
<Note>
|
|
131
|
+
**Module caching across `/reload`:** Running `/reload` re-evaluates your extension and any local files you edited, resetting module-scoped variables when those files change (unchanged files in Bun single-file builds may retain module-scoped variables). Atomic's bundled core packages—including the `@earendil-works/pi-coding-agent` compatibility alias—always resolve to the running host's instances across `/reload` so `instanceof` checks keep working. Restart Atomic after updating Atomic itself.
|
|
132
|
+
</Note>
|
|
135
133
|
|
|
136
|
-
Extensions whose state must follow conversation branches should store a snapshot in tool result `details`:
|
|
134
|
+
Extensions whose state must follow conversation branches should store a snapshot in tool result `details` and rebuild it in `session_start`:
|
|
137
135
|
|
|
138
136
|
```typescript
|
|
139
137
|
export default function (atomic: ExtensionAPI) {
|
|
@@ -191,10 +189,10 @@ export default function (atomic: ExtensionAPI) {
|
|
|
191
189
|
}
|
|
192
190
|
```
|
|
193
191
|
|
|
194
|
-
- **Required scope.** Pass the extension's `atomic.events` object (or the session `EventBus` directly). Every `/reload` of the same session reconnects to the same stored object, while separate sessions stay independent. Do not pass a
|
|
192
|
+
- **Required scope.** Pass the extension's `atomic.events` object (or the session `EventBus` directly). Every `/reload` of the same session reconnects to the same stored object, while separate sessions stay independent. Do not pass a plain object; an unregistered scope will not reconnect after reload.
|
|
195
193
|
- **Session-wide key namespace.** Keys are shared across all extensions in the session. Two extensions passing the same key receive the first extension's object, and the second factory does not run. Prefix every key with a unique extension identifier.
|
|
196
194
|
- **Key versioning.** Append a version suffix and bump it when the stored shape changes (for example `"my-extension:counter:v1"` to `"my-extension:counter:v2"`). The new key ignores older incompatible state.
|
|
197
|
-
- **Reload behavior.** `/reload` creates a new `atomic.events` wrapper backed by the same session bus. Calling `sessionScopedExtensionState()` with the same key returns the existing object without running `create` again. Failed reloads do not undo mutations made to this object during factory setup
|
|
195
|
+
- **Reload behavior.** `/reload` creates a new `atomic.events` wrapper backed by the same session bus. Calling `sessionScopedExtensionState()` with the same key returns the existing object without running `create` again. Failed reloads do not undo mutations made to this object during factory setup, so keep factory setup idempotent and avoid mutating shared state until `session_start`. Use `atomic.appendEntry()` when data must survive a full restart.
|
|
198
196
|
- **Shutdown.** `session_shutdown` still runs for resources you opened. Close sockets, watchers, or timers there; the next `session_start` or first use can recreate them inside the same session-scoped object.
|
|
199
197
|
|
|
200
198
|
## Custom tools
|
|
@@ -211,35 +209,9 @@ Prompt metadata options:
|
|
|
211
209
|
- **`promptSnippet`:** Adds a short one-line entry in the `Available tools` section of the default system prompt. If omitted, the tool is left out of that list.
|
|
212
210
|
- **`promptGuidelines`:** Adds tool-specific bullets to the default system prompt `Guidelines` section while the tool is active. Because guidelines are appended flat without grouping, always name the tool explicitly (write `"Use my_tool when..."`, not `"Use this tool when..."`).
|
|
213
211
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
If your tool edits files, wrap the full read-modify-write operation in `withFileMutationQueue()` so it shares the same per-file lock as built-in `edit` and `write`. Because tool calls run concurrently by default, unqueued tools can read stale contents and overwrite each other's changes.
|
|
219
|
-
|
|
220
|
-
Resolve the target path to an absolute path relative to `ctx.cwd` before calling `withFileMutationQueue()`. For existing files, Atomic canonicalizes the path with `realpath()` so symlinks share the same queue; for new files, it uses the resolved absolute path. If your callback throws, the queue releases automatically so waiting mutations can proceed.
|
|
221
|
-
|
|
222
|
-
```typescript
|
|
223
|
-
import { withFileMutationQueue } from "@bastani/atomic";
|
|
224
|
-
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
225
|
-
import { dirname, resolve } from "node:path";
|
|
226
|
-
|
|
227
|
-
async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
|
|
228
|
-
const absolutePath = resolve(ctx.cwd, params.path);
|
|
229
|
-
|
|
230
|
-
return withFileMutationQueue(absolutePath, async () => {
|
|
231
|
-
await mkdir(dirname(absolutePath), { recursive: true });
|
|
232
|
-
const current = await readFile(absolutePath, "utf8");
|
|
233
|
-
const next = current.replace(params.oldText, params.newText);
|
|
234
|
-
await writeFile(absolutePath, next, "utf8");
|
|
235
|
-
|
|
236
|
-
return {
|
|
237
|
-
content: [{ type: "text", text: `Updated ${params.path}` }],
|
|
238
|
-
details: {},
|
|
239
|
-
};
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
```
|
|
212
|
+
<Tip>
|
|
213
|
+
Some models include a leading `@` prefix in file path arguments. Built-in tools strip a leading `@` before resolving paths; normalize it in your custom path-taking tools too.
|
|
214
|
+
</Tip>
|
|
243
215
|
|
|
244
216
|
### Tool definition
|
|
245
217
|
|
|
@@ -306,7 +278,7 @@ atomic.registerTool(myTool);
|
|
|
306
278
|
Additional `ToolDefinition` fields:
|
|
307
279
|
|
|
308
280
|
- **`maxResultSizeChars?: number`:** Sets a per-tool character cap for model-visible result persistence. Pass `Infinity` to opt out for self-bounded tools.
|
|
309
|
-
- **`prepareArguments(args)`:** Optional normalizer that runs before schema validation and `execute()`.
|
|
281
|
+
- **`prepareArguments(args)`:** Optional normalizer that runs before schema validation and `execute()`. Use it to accept renamed fields without cluttering the public schema.
|
|
310
282
|
- **`terminate: true`:** Return on a tool result to skip the automatic follow-up model call when every finalized result in the batch also sets `terminate: true`.
|
|
311
283
|
- **Signaling errors:** Throw an `Error` from `execute()` to report a failure. When a failure also carries structured data, return `{ isError: true, content, structuredContent }`.
|
|
312
284
|
|
|
@@ -319,56 +291,42 @@ async execute(_toolCallId, params) {
|
|
|
319
291
|
}
|
|
320
292
|
```
|
|
321
293
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
For a schema-backed decision, use `createStructuredOutputTool({ schema, name?, capture?, output?, timeoutMs? })` (see [Structured decisions](/sdk/structured-decisions)). Atomic does not register `structured_output` in normal sessions by default. Include any custom `name` (such as `"final_decision"`) in explicit tool allowlists.
|
|
325
|
-
|
|
326
|
-
- **`capture`:** Pass `createStructuredOutputCapture()` to inspect `{ called, value }` in memory after the call finishes.
|
|
327
|
-
- **`output`:** Pass `{ outputPath }` to write the validated JSON result to disk with `0o600` file permissions.
|
|
328
|
-
- **`timeoutMs`:** Overrides the default wall-clock deadline (`httpIdleTimeoutMs`) covering every repair attempt, transport retry, and model fallback.
|
|
329
|
-
|
|
330
|
-
When the model calls the tool, it supplies `instructions`, nonempty named `state`, and optional `model` and `fallbackModels`:
|
|
331
|
-
|
|
332
|
-
- Omitting `model` uses the session's configured **`decisionModel`** (via `ctx.getDecisionModel()`, which defaults to the current chat model when unset or `""`), then any explicit `fallbackModels`, and finally the current chat model as the terminal fallback.
|
|
333
|
-
- A registered classifier runs only for a finite Choice schema and is skipped for incompatible schemas.
|
|
334
|
-
- Provider errors (including refusals) advance to the next model. Plain-text responses without a valid structured value are repaired up to three times before advancing. Cancellation stops the call immediately.
|
|
294
|
+
### Serializing file mutations
|
|
335
295
|
|
|
336
|
-
|
|
296
|
+
If your tool edits files, wrap the full read-modify-write operation in `withFileMutationQueue()` so it shares the same per-file lock as built-in `edit` and `write`. Because tool calls run concurrently by default, unqueued tools can read stale contents and overwrite each other's changes.
|
|
337
297
|
|
|
338
|
-
`
|
|
298
|
+
Resolve the target path to an absolute path relative to `ctx.cwd` before calling `withFileMutationQueue()`. For existing files, Atomic canonicalizes the path with `realpath()` so symlinks share the same queue; for new files, it uses the resolved absolute path. If your callback throws, the queue releases automatically so waiting mutations can proceed.
|
|
339
299
|
|
|
340
300
|
```typescript
|
|
341
|
-
atomic
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
description: "Edit one file",
|
|
345
|
-
parameters: Type.Object({ path: Type.String(), content: Type.String() }),
|
|
346
|
-
constrainedSampling: { type: "json_schema", strict: "prefer" },
|
|
347
|
-
async execute(_id, params) {
|
|
348
|
-
return { content: [{ type: "text", text: params.path }], details: {} };
|
|
349
|
-
},
|
|
350
|
-
});
|
|
351
|
-
```
|
|
352
|
-
|
|
353
|
-
Supported values:
|
|
301
|
+
import { withFileMutationQueue } from "@bastani/atomic";
|
|
302
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
303
|
+
import { dirname, resolve } from "node:path";
|
|
354
304
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
- `{ type: "grammar", variants: { openai_lark?: string, openai_regex?: string } }`: requests an OpenAI custom grammar tool (Lark wins when both non-empty variants are set).
|
|
358
|
-
- `false`: explicitly opts out while preserving `false` during public tool inspection.
|
|
305
|
+
async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
|
|
306
|
+
const absolutePath = resolve(ctx.cwd, params.path);
|
|
359
307
|
|
|
360
|
-
|
|
308
|
+
return withFileMutationQueue(absolutePath, async () => {
|
|
309
|
+
await mkdir(dirname(absolutePath), { recursive: true });
|
|
310
|
+
const current = await readFile(absolutePath, "utf8");
|
|
311
|
+
const next = current.replace(params.oldText, params.newText);
|
|
312
|
+
await writeFile(absolutePath, next, "utf8");
|
|
361
313
|
|
|
362
|
-
|
|
314
|
+
return {
|
|
315
|
+
content: [{ type: "text", text: `Updated ${params.path}` }],
|
|
316
|
+
details: {},
|
|
317
|
+
};
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
```
|
|
363
321
|
|
|
364
|
-
|
|
322
|
+
### Concurrency and sequential execution
|
|
365
323
|
|
|
366
324
|
When one assistant message contains multiple tool calls, Atomic runs them concurrently by default unless configured otherwise:
|
|
367
325
|
|
|
368
326
|
- **`concurrency: "shared"` (default):** May overlap other shared calls, starting only after any earlier `"exclusive"` call finishes.
|
|
369
327
|
- **`concurrency: "exclusive"`:** Waits for every earlier call in the message to finish, and blocks later calls until it completes.
|
|
370
328
|
- **`concurrency: (args) => "shared" | "exclusive"`:** Decides per call. If the function throws, the call runs exclusively.
|
|
371
|
-
- **`executionMode: "sequential" | "parallel"`:** Setting `executionMode: "sequential"` forces every call in the message to execute strictly one at a time in order (see
|
|
329
|
+
- **`executionMode: "sequential" | "parallel"`:** Setting `executionMode: "sequential"` forces every call in the message to execute strictly one at a time in order (see [tic-tac-toe.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/tic-tac-toe.ts)).
|
|
372
330
|
|
|
373
331
|
Built-in `edit`, `write`, `todo`, and `ask_user_question` are exclusive, and `bash` is exclusive when `pty: true`. Other `bash` calls are shared, so declare `"exclusive"` on custom tools that modify state later calls depend on:
|
|
374
332
|
|
|
@@ -385,9 +343,40 @@ atomic.registerTool({
|
|
|
385
343
|
});
|
|
386
344
|
```
|
|
387
345
|
|
|
388
|
-
|
|
346
|
+
### Output truncation
|
|
389
347
|
|
|
390
|
-
|
|
348
|
+
**Tools must truncate large output** to avoid context overflow errors, compaction failures, and degraded responses. The built-in limit is **50 KB** (~10k tokens) and **2,000 lines**, whichever comes first:
|
|
349
|
+
|
|
350
|
+
```typescript
|
|
351
|
+
import {
|
|
352
|
+
truncateHead, // Keep first N lines/bytes (file reads, search results)
|
|
353
|
+
truncateTail, // Keep last N lines/bytes (logs, command output)
|
|
354
|
+
truncateLine, // Truncate a single line to maxBytes with ellipsis
|
|
355
|
+
formatSize, // Human-readable size ("50KB", "1.5MB")
|
|
356
|
+
DEFAULT_MAX_BYTES, // 50KB
|
|
357
|
+
DEFAULT_MAX_LINES, // 2000
|
|
358
|
+
} from "@bastani/atomic";
|
|
359
|
+
|
|
360
|
+
async execute() {
|
|
361
|
+
const output = await runCommand();
|
|
362
|
+
const truncation = truncateHead(output, {
|
|
363
|
+
maxLines: DEFAULT_MAX_LINES,
|
|
364
|
+
maxBytes: DEFAULT_MAX_BYTES,
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
let result = truncation.content;
|
|
368
|
+
if (truncation.truncated) {
|
|
369
|
+
const tempFile = writeTempFile(output);
|
|
370
|
+
result += `\n\n[Output truncated: ${truncation.outputLines} of ${truncation.totalLines} lines`;
|
|
371
|
+
result += ` (${formatSize(truncation.outputBytes)} of ${formatSize(truncation.totalBytes)}).`;
|
|
372
|
+
result += ` Full output saved to: ${tempFile}]`;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
return { content: [{ type: "text", text: result }] };
|
|
376
|
+
}
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
Use `truncateHead` when the beginning matters, `truncateTail` when the end matters, tell the model where full output was saved, and document truncation limits in the tool description. To spill and bound arbitrary extension text using the same mechanism Atomic uses for oversized tool results, `@bastani/atomic` also exports `boundOversizedText()`. See [examples/extensions/truncated-tool.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/truncated-tool.ts).
|
|
391
380
|
|
|
392
381
|
### Structured results and nested tools
|
|
393
382
|
|
|
@@ -419,11 +408,84 @@ Nested execution events and the nested tool's `ctx` include `parentToolCallId`.
|
|
|
419
408
|
- `namespace: { name, description, instructions? }` groups related tools and optional namespace-level guidance.
|
|
420
409
|
- Optional `annotations` carry advisory hints (`readOnlyHint`, `destructiveHint`, `idempotentHint`, `openWorldHint`) that do not enforce permissions.
|
|
421
410
|
- Set `writesFiles: true` on tools that modify files so turns calling them record a [worktree snapshot](/worktree-snapshots) like `bash`, `edit`, and `write`.
|
|
422
|
-
- An active orchestrator tool can implement `prepareLoadout(loadout)` to adjust how tools are described or hidden from the model (returning `descriptions` or `hiddenDeclarations`). This changes model presentation only, not authorization.
|
|
423
411
|
|
|
424
|
-
|
|
412
|
+
### Multiple tools
|
|
413
|
+
|
|
414
|
+
One extension can register multiple tools sharing one resource and release it on `session_shutdown`:
|
|
415
|
+
|
|
416
|
+
```typescript
|
|
417
|
+
export default function (atomic: ExtensionAPI) {
|
|
418
|
+
let connection: DbConnection | null = null;
|
|
419
|
+
|
|
420
|
+
atomic.registerTool({ name: "db_connect", /* ... */ });
|
|
421
|
+
atomic.registerTool({ name: "db_query", /* ... */ });
|
|
422
|
+
atomic.registerTool({ name: "db_close", /* ... */ });
|
|
423
|
+
|
|
424
|
+
atomic.on("session_shutdown", async () => {
|
|
425
|
+
connection?.close();
|
|
426
|
+
connection = null;
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
## Advanced tool options
|
|
432
|
+
|
|
433
|
+
### Structured output helper
|
|
434
|
+
|
|
435
|
+
For a schema-backed decision, register a tool built with `createStructuredOutputTool({ schema, name?, capture?, output?, timeoutMs? })` from `@bastani/atomic`. It marks the tool with `structuredOutput: true` so print mode knows to emit its validated JSON result even under a custom tool name (normal sessions do not register `structured_output` by default; include custom names in explicit tool allowlists).
|
|
436
|
+
|
|
437
|
+
Pass `capture: createStructuredOutputCapture()` to inspect `{ called, value }` in memory, `output: { outputPath }` to write validated JSON with `0o600` permissions, and optional `timeoutMs` to override `httpIdleTimeoutMs`. See [Structured decisions](/sdk/structured-decisions) for model fallback, classifier routing, and repair behavior.
|
|
438
|
+
|
|
439
|
+
### Constrained sampling
|
|
440
|
+
|
|
441
|
+
`ToolDefinition.constrainedSampling` is preserved for extension tools, [SDK `customTools`](/sdk/reference#custom-tools), wrappers, and default interactive mode. It accepts `false` or a `ConstrainedSamplingConfig`:
|
|
442
|
+
|
|
443
|
+
```typescript
|
|
444
|
+
atomic.registerTool({
|
|
445
|
+
name: "strict_edit",
|
|
446
|
+
label: "Strict edit",
|
|
447
|
+
description: "Edit one file",
|
|
448
|
+
parameters: Type.Object({ path: Type.String(), content: Type.String() }),
|
|
449
|
+
constrainedSampling: { type: "json_schema", strict: "prefer" },
|
|
450
|
+
async execute(_id, params) {
|
|
451
|
+
return { content: [{ type: "text", text: params.path }], details: {} };
|
|
452
|
+
},
|
|
453
|
+
});
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
Supported values:
|
|
457
|
+
|
|
458
|
+
- `{ type: "json_schema", strict: "prefer" }`: requests strict provider enforcement and falls back to ordinary tool calling when unavailable.
|
|
459
|
+
- `{ type: "json_schema", strict: "require" }`: fails the request instead of weakening the constraint.
|
|
460
|
+
- `{ type: "grammar", variants: { openai_lark?: string, openai_regex?: string } }`: requests an OpenAI custom grammar tool (Lark wins when both non-empty variants are set).
|
|
461
|
+
- `false`: explicitly opts out while preserving `false` during public tool inspection.
|
|
462
|
+
|
|
463
|
+
If Anthropic rejects a request because strict tools exceed its grammar-size, tool-count, or union-parameter limits, Atomic retries once with `prefer` tools using ordinary schemas while keeping `require` tools strict (never retried after streaming starts).
|
|
464
|
+
|
|
465
|
+
Built-in `read`, `edit`, `write`, `bash`, and `powershell` default to `{ type: "json_schema", strict: "prefer" }`. Grammar tools require an object schema with one required string property and apply only when model metadata advertises `supportsOpenAIGrammarTools` (alias `supportsGrammarTools`). See [Custom models](/models/reference#constrained-tool-sampling) and [RPC](/rpc/protocol#get_available_models).
|
|
466
|
+
|
|
467
|
+
### Detachable long waits
|
|
468
|
+
|
|
469
|
+
A tool that only waits on external work (such as a CI job or deployment) can set `detachable: true` or `detachable: (args) => boolean`. When running inside a background subagent that suspends while waiting, a call still running past the detachment delay continues independently, releases the subagent, and wakes it when the result arrives.
|
|
470
|
+
|
|
471
|
+
If the tool must finish recording a durable handoff (such as sending an external request or storing a job ID) before it can safely detach, also set `detachmentRequiresReady: true` and call `markToolCallReadyForDetachment(signal)` (exported from `@bastani/atomic`, alongside `toolCallNeedsDetachmentHandoff(signal)`) once the handoff is saved. Atomic will not detach the call until that readiness callback fires.
|
|
472
|
+
|
|
473
|
+
Once a call detaches, `onUpdate` progress updates are dropped and `ctx` only answers `cwd`. Because a restarted session can re-run a detached call with the same ID and arguments, mark a tool `detachable` only when re-running it is safe. Built-in `bash` detaches only `{ action: "wait" }` calls without `budgetMs`.
|
|
474
|
+
|
|
475
|
+
### Customizing tool loadouts
|
|
476
|
+
|
|
477
|
+
An active orchestrator tool can implement `prepareLoadout(loadout)` to adjust how other tools are described or hidden from the model for that turn. It changes model presentation only, not authorization.
|
|
478
|
+
|
|
479
|
+
`loadout` (`ToolLoadout`) provides:
|
|
425
480
|
|
|
426
|
-
|
|
481
|
+
- `declared`, `callable`, and `registered`: read-only arrays of tools in each visibility bucket.
|
|
482
|
+
- `getExposure(name)`: returns the tool's `ToolExposure`.
|
|
483
|
+
- `getNamespace(name)`: returns the tool's `ToolNamespace` (if set).
|
|
484
|
+
- `getPromptGuidelines(name)`: returns the tool's prompt guidelines (omitted from system prompt rules when its declaration is hidden).
|
|
485
|
+
|
|
486
|
+
Return `{ descriptions?: Record<string, string>, hiddenDeclarations?: string[] }` (or `undefined` to leave the loadout unchanged).
|
|
487
|
+
|
|
488
|
+
## Overriding built-in tools
|
|
427
489
|
|
|
428
490
|
Extensions can override built-in tools (`read`, `bash`, `powershell`, `kill`, `edit`, `write`, `find`, `search`, `ls`, `ask_user_question`, `todo`) by registering a tool with the same name. Interactive mode displays a warning when a built-in tool is overridden:
|
|
429
491
|
|
|
@@ -432,7 +494,7 @@ Extensions can override built-in tools (`read`, `bash`, `powershell`, `kill`, `e
|
|
|
432
494
|
atomic -e ./tool-override.ts
|
|
433
495
|
```
|
|
434
496
|
|
|
435
|
-
Use `--no-builtin-tools` (
|
|
497
|
+
Use `--no-builtin-tools` (`-nbt`) to start with no built-in tools while keeping extension tools enabled:
|
|
436
498
|
|
|
437
499
|
```bash
|
|
438
500
|
atomic --no-builtin-tools -e ./my-extension.ts
|
|
@@ -452,7 +514,7 @@ See [examples/extensions/tool-override.ts](https://github.com/bastani-inc/atomic
|
|
|
452
514
|
- `ls`: `LsToolDetails` (`createLsToolDefinition`)
|
|
453
515
|
- `write`, `kill`, `ask_user_question`, `todo`: `createWriteToolDefinition`, `createKillToolDefinition`, `createAskUserQuestionToolDefinition`, `createTodoToolDefinition`
|
|
454
516
|
|
|
455
|
-
|
|
517
|
+
## Remote execution
|
|
456
518
|
|
|
457
519
|
Built-in tools accept pluggable operations objects for SSH, containers, and sandboxes:
|
|
458
520
|
|
|
@@ -480,8 +542,8 @@ atomic.registerTool({
|
|
|
480
542
|
```
|
|
481
543
|
|
|
482
544
|
- `ReadOperations` can provide `stat` and `listDir` for remote directory reads, and optional `createReadStream` (returning an async iterable of `Uint8Array` chunks, such as a Node `Readable` without encoding) so line ranges of large files stream without reading the whole file into memory. `:conflicts` views and notebooks still read the full file. Archive, SQLite, internal-resource, and notebook helpers stay local.
|
|
483
|
-
- **
|
|
484
|
-
- `
|
|
545
|
+
- **Exported operations interfaces:** `ReadOperations`, `WriteOperations`, `EditOperations`, `BashOperations`, `PowerShellOperations`, `LsOperations`, `FindOperations`.
|
|
546
|
+
- Built-in `search` always scans the local filesystem; override `execute()` to search a remote host.
|
|
485
547
|
- For `user_bash` handlers, call `createLocalBashOperations()` to reuse Atomic's local shell spawning and process-tree cleanup.
|
|
486
548
|
- `createBashTool()` supports `spawnHook` to modify `command`, `cwd`, or `env` before launch:
|
|
487
549
|
|
|
@@ -499,65 +561,11 @@ const bashTool = createBashTool(cwd, {
|
|
|
499
561
|
|
|
500
562
|
See [examples/extensions/ssh.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/ssh.ts) for a full SSH example.
|
|
501
563
|
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
**Tools must truncate large output** to avoid context overflow errors, compaction failures, and degraded responses. The built-in limit is **50 KB** (~10k tokens) and **2,000 lines**, whichever comes first:
|
|
505
|
-
|
|
506
|
-
```typescript
|
|
507
|
-
import {
|
|
508
|
-
truncateHead, // Keep first N lines/bytes (file reads, search results)
|
|
509
|
-
truncateTail, // Keep last N lines/bytes (logs, command output)
|
|
510
|
-
truncateLine, // Truncate a single line to maxBytes with ellipsis
|
|
511
|
-
formatSize, // Human-readable size ("50KB", "1.5MB")
|
|
512
|
-
DEFAULT_MAX_BYTES, // 50KB
|
|
513
|
-
DEFAULT_MAX_LINES, // 2000
|
|
514
|
-
} from "@bastani/atomic";
|
|
515
|
-
|
|
516
|
-
async execute() {
|
|
517
|
-
const output = await runCommand();
|
|
518
|
-
const truncation = truncateHead(output, {
|
|
519
|
-
maxLines: DEFAULT_MAX_LINES,
|
|
520
|
-
maxBytes: DEFAULT_MAX_BYTES,
|
|
521
|
-
});
|
|
522
|
-
|
|
523
|
-
let result = truncation.content;
|
|
524
|
-
if (truncation.truncated) {
|
|
525
|
-
const tempFile = writeTempFile(output);
|
|
526
|
-
result += `\n\n[Output truncated: ${truncation.outputLines} of ${truncation.totalLines} lines`;
|
|
527
|
-
result += ` (${formatSize(truncation.outputBytes)} of ${formatSize(truncation.totalBytes)}).`;
|
|
528
|
-
result += ` Full output saved to: ${tempFile}]`;
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
return { content: [{ type: "text", text: result }] };
|
|
532
|
-
}
|
|
533
|
-
```
|
|
534
|
-
|
|
535
|
-
Use `truncateHead` when the beginning matters, `truncateTail` when the end matters, inform the model where full output was saved, and document truncation limits in the tool description. See [examples/extensions/truncated-tool.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/truncated-tool.ts).
|
|
536
|
-
|
|
537
|
-
### Multiple tools
|
|
538
|
-
|
|
539
|
-
One extension can register multiple tools sharing one resource and release it on `session_shutdown`:
|
|
540
|
-
|
|
541
|
-
```typescript
|
|
542
|
-
export default function (atomic: ExtensionAPI) {
|
|
543
|
-
let connection: DbConnection | null = null;
|
|
544
|
-
|
|
545
|
-
atomic.registerTool({ name: "db_connect", /* ... */ });
|
|
546
|
-
atomic.registerTool({ name: "db_query", /* ... */ });
|
|
547
|
-
atomic.registerTool({ name: "db_close", /* ... */ });
|
|
548
|
-
|
|
549
|
-
atomic.on("session_shutdown", async () => {
|
|
550
|
-
connection?.close();
|
|
551
|
-
connection = null;
|
|
552
|
-
});
|
|
553
|
-
}
|
|
554
|
-
```
|
|
555
|
-
|
|
556
|
-
### Custom rendering
|
|
564
|
+
## Custom rendering
|
|
557
565
|
|
|
558
566
|
Tools can provide `renderCall` and `renderResult` for custom display in the interactive transcript and HTML exports. See [TUI components](/tui) for the full component API.
|
|
559
567
|
|
|
560
|
-
To select renderers dynamically for any tool (including MCP tools in resumed sessions before their server connects), register a resolver with `atomic.registerToolRenderer((toolName, next) => renderers)`. Resolvers run in extension load order; `next()` returns the remaining resolvers' choice and then the tool's own renderers, so `next() ?? mine` acts as a fallback. See [`atomic.registerToolRenderer()`](/extensions/api-reference#atomic-registertoolrenderer-resolver).
|
|
568
|
+
To select renderers dynamically for any tool (including MCP tools in resumed sessions before their server connects), register a resolver with `atomic.registerToolRenderer((toolName, next) => renderers)` returning `{ renderCall?, renderResult?, renderShell?, label? }`. Resolvers run in extension load order; `next()` returns the remaining resolvers' choice and then the tool's own renderers, so `next() ?? mine` acts as a fallback. See [`atomic.registerToolRenderer()`](/extensions/api-reference#atomic-registertoolrenderer-resolver).
|
|
561
569
|
|
|
562
570
|
Extension `Image` components render JPEG, GIF, and WebP images on Kitty-protocol terminals automatically.
|
|
563
571
|
|
|
@@ -591,7 +599,7 @@ atomic.registerTool({
|
|
|
591
599
|
- `keyText()`, `keyHint()`: format the user's configured keybindings (see [Keybinding hints](#keybinding-hints))
|
|
592
600
|
- Optional helpers `getTaskRecord?()`, `getElapsedMs?()`, and `getToolDefinition?()` when exposed by the host
|
|
593
601
|
|
|
594
|
-
|
|
602
|
+
### renderCall
|
|
595
603
|
|
|
596
604
|
Renders the tool call header:
|
|
597
605
|
|
|
@@ -610,7 +618,7 @@ renderCall(args, theme, context) {
|
|
|
610
618
|
}
|
|
611
619
|
```
|
|
612
620
|
|
|
613
|
-
|
|
621
|
+
### renderResult
|
|
614
622
|
|
|
615
623
|
Renders the tool output:
|
|
616
624
|
|
|
@@ -636,7 +644,7 @@ renderResult(result, { expanded, isPartial }, theme) {
|
|
|
636
644
|
|
|
637
645
|
Return an empty `Container` when a slot intentionally displays nothing.
|
|
638
646
|
|
|
639
|
-
|
|
647
|
+
### Keybinding hints
|
|
640
648
|
|
|
641
649
|
Use `context.keyHint()` and `context.keyText()` (or `options.keyHint()` and `options.keyText()` in message and entry renderers) so hints match the user's `keybindings.json`. Test `keyText()` for an empty string before adding punctuation when a keybinding may be unbound:
|
|
642
650
|
|
|
@@ -658,7 +666,7 @@ To make a plain-text hint clickable, pass it through `clickableHintText()` from
|
|
|
658
666
|
|
|
659
667
|
Use namespaced keybinding IDs (`app.*` for coding-agent actions and `tui.*` for shared TUI actions; see [Keybindings](/keybindings)). Custom editors and `ctx.ui.custom()` components receive `keybindings: KeybindingsManager` as an argument; use it directly instead of calling `getKeybindings()` or `setKeybindings()`.
|
|
660
668
|
|
|
661
|
-
|
|
669
|
+
### Best practices
|
|
662
670
|
|
|
663
671
|
- Use `Text` with padding `(0, 0)` because the default `Box` adds padding.
|
|
664
672
|
- Handle `isPartial` for streaming progress and `expanded` for details on demand (`Ctrl+O` toggles all blocks; clicking toggles one block).
|
|
@@ -666,7 +674,7 @@ Use namespaced keybinding IDs (`app.*` for coding-agent actions and `tui.*` for
|
|
|
666
674
|
- Reuse `context.lastComponent` when updating the same component across renders.
|
|
667
675
|
- Use `renderShell: "self"` only when you need custom outer framing, padding, and background.
|
|
668
676
|
|
|
669
|
-
|
|
677
|
+
### Fallback
|
|
670
678
|
|
|
671
679
|
If a slot renderer is omitted or throws:
|
|
672
680
|
|