@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
package/docs/sdk.md
CHANGED
|
@@ -1,53 +1,68 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: "TypeScript SDK"
|
|
3
|
-
sidebarTitle: "SDK"
|
|
4
|
-
description: "Embed Atomic agent sessions in Node.js applications with programmatic control over models, tools, storage, and human input."
|
|
2
|
+
title: "Use the TypeScript SDK"
|
|
3
|
+
sidebarTitle: "Use the SDK"
|
|
4
|
+
description: "Embed Atomic agent sessions in Node.js 24.20+ applications with programmatic control over models, tools, storage, workspaces, and human input."
|
|
5
5
|
---
|
|
6
6
|
|
|
7
7
|
Embed Atomic in Node.js applications (Node.js 24.20 or newer) to build custom UIs, power backend services, or drive automated workflows directly inside your Node.js process. Working examples live in [examples/sdk/](https://github.com/bastani-inc/atomic/tree/main/packages/coding-agent/examples/sdk).
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
<Columns cols={2}>
|
|
10
|
+
<Card title="SDK API reference" href="/sdk/reference">
|
|
11
|
+
Full options, `AgentSession` and `AgentSessionRuntime` methods, loaders, run modes, task supervision, error classes, and exports.
|
|
12
|
+
</Card>
|
|
13
|
+
<Card title="Configure session storage" href="/sdk/storage">
|
|
14
|
+
Recipes for SQLite, JSONL, in-memory, and PostgreSQL storage, `StorageProvider`, ownership rules, and `StorageError` handling.
|
|
15
|
+
</Card>
|
|
16
|
+
<Card title="Make structured decisions" href="/sdk/structured-decisions">
|
|
17
|
+
Run typed classifier or chat decisions with `decide()`, `generateStructuredOutput()`, and `structured_output`.
|
|
18
|
+
</Card>
|
|
19
|
+
<Card title="Stream from a web server" href="/sdk/web-server">
|
|
20
|
+
Build a streaming NDJSON HTTP endpoint with Next.js App Router and `createAgentSession()`.
|
|
21
|
+
</Card>
|
|
22
|
+
</Columns>
|
|
23
|
+
|
|
24
|
+
Need to compare Print mode, JSON event streams, RPC mode, and the SDK? See [Choose an integration mode](/programmatic).
|
|
14
25
|
|
|
15
26
|
## Quick start
|
|
16
27
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
28
|
+
<Steps>
|
|
29
|
+
<Step title="Install @bastani/atomic">
|
|
30
|
+
The SDK ships in the main package; dependency install scripts are not required.
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npm install @bastani/atomic
|
|
34
|
+
# or: pnpm add @bastani/atomic
|
|
35
|
+
# or: bun add @bastani/atomic
|
|
36
|
+
```
|
|
37
|
+
</Step>
|
|
38
|
+
<Step title="Configure TypeScript ESM">
|
|
39
|
+
Set `"type": "module"` in `package.json` and `"module": "NodeNext"`, `"moduleResolution": "NodeNext"`, `"strict": true` in `tsconfig.json`.
|
|
40
|
+
</Step>
|
|
41
|
+
<Step title="Create a session, stream deltas, and dispose cleanly">
|
|
42
|
+
```typescript
|
|
43
|
+
import { createAgentSession, ModelRuntime, SessionManager } from "@bastani/atomic";
|
|
44
|
+
|
|
45
|
+
const modelRuntime = await ModelRuntime.create();
|
|
46
|
+
|
|
47
|
+
const { session } = await createAgentSession({
|
|
48
|
+
sessionManager: SessionManager.inMemory(),
|
|
49
|
+
modelRuntime,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
session.subscribe((event) => {
|
|
53
|
+
if (event.type === "message_update" && event.assistantMessageEvent.type === "text_delta") {
|
|
54
|
+
process.stdout.write(event.assistantMessageEvent.delta);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
await session.prompt("What files are in the current directory?");
|
|
60
|
+
} finally {
|
|
61
|
+
await session.dispose();
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
</Step>
|
|
65
|
+
</Steps>
|
|
51
66
|
|
|
52
67
|
- **`ModelRuntime`:** Async runtime for credentials, native providers, and dynamic catalogs. Accepts `authPath`, `modelsPath`, `credentials`, runtime auth overrides, and catalog options (`allowModelNetwork`, `modelRefreshTimeoutMs`, `modelsStorePath`, `modelsStore`; see [Model catalog persistence and refresh](/sdk/reference#model-catalog-persistence-and-refresh)). Legacy synchronous facades `ModelRegistry` and `AuthStorage` remain available, and `readStoredCredential(provider, authPath?)` reads one stored credential.
|
|
53
68
|
- **Exact model restoration:** Call `await resolveRestoredModelReference(provider, modelId, modelRuntime)` to resolve an authenticated saved model (including custom or dynamic IDs) or receive `undefined` without falling back to a default.
|
|
@@ -93,7 +108,7 @@ const { session: custom } = await createAgentSession({
|
|
|
93
108
|
- **Startup hooks and rebinding:** `createAgentSession()` runs extension `session_start` hooks before resolving. Pass `extensionBindings` here if startup hooks need them; later `session.bindExtensions(...)` calls update bindings without replaying `session_start`.
|
|
94
109
|
- **Explicit recovery:** Opening a session never recovers interrupted work automatically. Call `await session.startPendingRecovery("resume")` once ready to display output; it returns `{ replayed, dropped, completions, notices }`.
|
|
95
110
|
|
|
96
|
-
### Workspaces
|
|
111
|
+
### Workspaces {#workspaces}
|
|
97
112
|
|
|
98
113
|
Bind a session to a Git repository, branch, and worktree with `workspace({ ... })` (requires Git 2.33+):
|
|
99
114
|
|
|
@@ -107,9 +122,13 @@ const reviewer = await createAgentSession({ workspace: api.readOnly() });
|
|
|
107
122
|
```
|
|
108
123
|
|
|
109
124
|
- **Resolution:** Local `repo` must point to a repository root. Remote repositories clone once under `<storageHome>/repos/` ([storage home](/storage#storage-home)) and create worktrees after fetching. Missing branches start from `base`; existing worktrees must match repository and branch (interrupted checkouts re-create automatically). Explicit `cwd` must stay inside the worktree, and an explicit `sessionManager` must already point inside it (`WorkspaceConfigError` otherwise).
|
|
110
|
-
- **Read-only (`api.readOnly()`):** Removes and blocks `write`, `edit`, and `todo` even if listed in `tools`.
|
|
125
|
+
- **Read-only (`api.readOnly()`):** Removes and blocks `write`, `edit`, and `todo` even if listed in `tools`. Child sessions stay read-only even with their own workspace.
|
|
111
126
|
- **Persistence and PRs:** Bindings persist as a `workspace_binding` entry and restore on reopen (call `bindSessionWorkspace(workspace, sessionManager, signal?)` beforehand if you need the resolved path early). Inspect commits with `workspaceChangeSet(binding)` and open pull requests via `publishPullRequest(changeSet, { draft: true })`.
|
|
112
|
-
- **Errors:** Invalid options throw `WorkspaceConfigError`. Binding failures throw `WorkspaceBindingError` with
|
|
127
|
+
- **Errors:** Invalid options throw `WorkspaceConfigError`. Binding failures throw `WorkspaceBindingError` with `code` set to `wrong-repository`, `wrong-branch`, `conflicting-worktree-input`, `invalid-repository`, `unknown-base`, `cwd-outside-worktree`, `git-unavailable`, `git-failed`, `filesystem-failed`, `drift`, `writer-conflict`, or `incomplete-worktree`. See [Workspace](/sdk/reference#workspace) for the full helper and error-class list.
|
|
128
|
+
|
|
129
|
+
<Warning>
|
|
130
|
+
Read-only workspaces are **not** an OS sandbox. Shell tools (`bash`, `powershell`) can still run and modify files unless you disable them via `tools`/`excludedTools` or isolate the process in a container or VM.
|
|
131
|
+
</Warning>
|
|
113
132
|
|
|
114
133
|
### Shared resource admission
|
|
115
134
|
|
|
@@ -139,7 +158,7 @@ const { session } = await createAgentSession({ resourceAdmission });
|
|
|
139
158
|
|
|
140
159
|
### Session storage
|
|
141
160
|
|
|
142
|
-
Sessions default to local SQLite at `~/.atomic/workflows/journal.sqlite` with the `session_` table prefix. Override storage per session with `sessionStore`, `storage`, or an explicit `sessionManager`. Read
|
|
161
|
+
Sessions default to local SQLite at `~/.atomic/workflows/journal.sqlite` with the `session_` table prefix. Override storage per session with `sessionStore`, `storage`, or an explicit `sessionManager`. Read [Configure session storage](/sdk/storage) for complete recipes across all four backends, `createAgentSessionRuntime()` wiring, `SessionManager` CRUD, `JsonlSessionStore` `exactDirectory` behavior, adapter resolution, ownership rules, and `StorageError` handling.
|
|
143
162
|
|
|
144
163
|
| Backend | Package | How to pass it to `createAgentSession()` |
|
|
145
164
|
| --- | --- | --- |
|
|
@@ -148,7 +167,7 @@ Sessions default to local SQLite at `~/.atomic/workflows/journal.sqlite` with th
|
|
|
148
167
|
| In-memory | Built into `@bastani/atomic` | `new MemorySessionStore()` (caller-owned) or `{ kind: "memory" }` (discarded on `dispose()`) |
|
|
149
168
|
| PostgreSQL (16+ for sessions) | [`@bastani/atomic-storage-postgres`](/libraries/storage-postgres) | `{ kind: "adapter", module: POSTGRES_ADAPTER_PACKAGE, ... }` or caller-owned `openPostgresDatabase()` |
|
|
150
169
|
|
|
151
|
-
Quick local SQLite session
|
|
170
|
+
Quick local SQLite session (Atomic opens the store and closes it in `dispose()`):
|
|
152
171
|
|
|
153
172
|
```typescript
|
|
154
173
|
import { createAgentSession } from "@bastani/atomic";
|
|
@@ -193,7 +212,7 @@ try {
|
|
|
193
212
|
- **Precedence:** Atomic resolves storage in order from `sessionManager`, `sessionStore`, `storage`, process flags and variables (`ATOMIC_SESSIONS_STORAGE` and `ATOMIC_STORAGE`), settings (`sessions.storage` before `storage`), and default SQLite. Memory is never an automatic fallback.
|
|
194
213
|
- **Ownership and mutations:** Atomic closes stores it opened from selection objects during `dispose()`, while leaving caller-owned `SessionStore`, `SessionManager`, and `database` instances open. Await every `SessionManager` write and every `atomic.appendEntry`, `setSessionName`, `setLabel`, `setThinkingLevel`, and `cycleThinkingLevel` call; there is no `flush()` method. `ExtensionContext.sessionSignal` aborts when reload or shutdown starts so extensions can cancel waits while finishing in-flight writes.
|
|
195
214
|
|
|
196
|
-
|
|
215
|
+
For CLI session commands, the full `SessionManager` method list, operator setup, and cross-machine resume, see [Sessions](/sessions), [SessionManager API](/session-format#sessionmanager-api), [Storage](/storage), and [Resume on any machine](/guides/resume-on-any-machine).
|
|
197
216
|
|
|
198
217
|
### Human input without a terminal
|
|
199
218
|
|
|
@@ -228,7 +247,7 @@ async function attachApplication(humanInput: HostInput) {
|
|
|
228
247
|
|
|
229
248
|
Read `session.sessionSummary` (`summary` and `summarizedThroughId`) or inspect `SessionManager.list()` / `listAll()`. Stored summaries remain readable when `sessionSummary.enabled` is `false`; `SessionManager.inMemory()` never generates summaries.
|
|
230
249
|
|
|
231
|
-
### Worktree snapshots
|
|
250
|
+
### Worktree snapshots {#worktree-snapshots}
|
|
232
251
|
|
|
233
252
|
SQLite and adapter-backed sessions capture checkout state automatically. Passing a reopened `sessionManager` to `createAgentSession({ sessionManager })` (or `runtime.rehydrate()`) restores missing or drifted checkouts into fresh worktrees while leaving matching local checkouts untouched. If a checkout cannot be rebuilt or Git is unavailable, resume continues with a warning notice instead of failing fast:
|
|
234
253
|
|
|
@@ -240,9 +259,9 @@ const { session } = await createAgentSession({ sessionManager });
|
|
|
240
259
|
```
|
|
241
260
|
|
|
242
261
|
- By default in the SDK (`resume.waitForBlueprint: "tools"`), `createAgentSession()` returns immediately while blueprint setup runs in the background and gates tool calls. Call `await blueprintBuildSettled(sessionId)` to wait explicitly, register `onBlueprintBuildFinished(listener)` for warnings, or set `resume.waitForBlueprint: "prompt"` to block startup (see [Start the first turn while the build runs](/guides/resume-on-any-machine#start-the-first-turn-while-the-build-runs)).
|
|
243
|
-
- Override per-session snapshot settings with `createAgentSession({ snapshots: { enabled: false } })`. Exported helpers include `captureWorktreeSnapshot()`, `restoreWorktreeSnapshot()`, `verifyWorktree()`, `session.sessionManager.getWorktreeRootMappings()`, `latestResumeTimings()`, `formatResumeTimings()`, and `session.exportToJsonl()`. See [Worktree snapshots](/worktree-snapshots).
|
|
262
|
+
- Override per-session snapshot settings with `createAgentSession({ snapshots: { enabled: false } })`. Exported helpers include `captureWorktreeSnapshot()`, `restoreWorktreeSnapshot()`, `verifyWorktree()`, `session.sessionManager.getWorktreeRootMappings()`, `latestResumeTimings()`, `formatResumeTimings()`, and `session.exportToJsonl()`. See [Worktree snapshots](/worktree-snapshots) and [Worktree snapshots reference](/worktree-snapshots/reference).
|
|
244
263
|
|
|
245
|
-
### Intercom group and reach
|
|
264
|
+
### Intercom group and reach {#intercom-group-and-reach}
|
|
246
265
|
|
|
247
266
|
Isolate multi-session hosts in one process with broker-enforced `intercom` policies (also accepted by `createAgentSessionFromServices()`):
|
|
248
267
|
|
|
@@ -258,7 +277,7 @@ await session.intercom.setReachable(["doc-1907", "doc-2011"]);
|
|
|
258
277
|
- Group names are trimmed of surrounding whitespace, cannot be empty, cannot exceed 1,024 characters, and cannot be the reserved names `"auto"` or `"true"` (case-insensitively). Duplicates and self-references in `reachable` are removed automatically.
|
|
259
278
|
- `setReachable()` updates live policy on the broker and leaves newly unreachable groups. Calling it on a session created without `intercom`, or passing an invalid group name or more than 1,000 reachable groups, throws `IntercomPolicyError` (which extends `TypeError`).
|
|
260
279
|
|
|
261
|
-
### Subagent children
|
|
280
|
+
### Subagent children {#subagent-children}
|
|
262
281
|
|
|
263
282
|
Children inherit the parent's `ModelRuntime`, settings, `agentDir`, `scopedModels`, `fallbackModels`, `customTools`, `resourceAdmission`, `humanInput`, and diagnostics. Working directory resolves in order: child `workspace`, child `cwd`, child `sessionManager.getCwd()`, then parent `cwd` or worktree.
|
|
264
283
|
|
|
@@ -267,7 +286,7 @@ Children inherit the parent's `ModelRuntime`, settings, `agentDir`, `scopedModel
|
|
|
267
286
|
|
|
268
287
|
### Driving a session
|
|
269
288
|
|
|
270
|
-
`AgentSession` is the handle for prompting, queueing, model switching, events, compaction, and disposal:
|
|
289
|
+
`AgentSession` is the primary handle for prompting, queueing, model switching, events, compaction, and disposal:
|
|
271
290
|
|
|
272
291
|
```typescript
|
|
273
292
|
interface AgentSession {
|
|
@@ -317,6 +336,8 @@ interface AgentSession {
|
|
|
317
336
|
}
|
|
318
337
|
```
|
|
319
338
|
|
|
339
|
+
`AgentSession` also exposes `stopTurns()`, `sendUserMessage()`, `sendCustomMessage()`, `executeBash()` / `abortBash()`, `exportToJsonl()` / `exportToHtml()`, `getSessionStats()`, `getContextUsage()`, `setActiveToolsByName()`, `setScopedModels()`, `reload()`, and cache-warming controls (`cacheWarmingStatus`, `setCacheWarmingMode()`). See [AgentSession and AgentSessionRuntime](/sdk/reference#agentsession-and-agentsessionruntime) for every method.
|
|
340
|
+
|
|
320
341
|
**Clean stop and disposal:** Always `await session.dispose()` in `finally` (60 s drain limit). If any cleanup step fails or stalls, `dispose()` rejects with an `AggregateError` tagged with `code: "ShutdownFailed"` (inspect `error.errors` for the individual causes). Pass `{ pauseQueuedMessages: true }` when aborting before disposal so arriving background notices do not launch another turn:
|
|
321
342
|
|
|
322
343
|
```typescript
|
|
@@ -329,7 +350,7 @@ try {
|
|
|
329
350
|
```
|
|
330
351
|
|
|
331
352
|
- `setModel(model, { thinkingLevel: "high", persist: true })` clamps unsupported thinking levels and optionally writes global defaults (project overrides still win at startup).
|
|
332
|
-
- `setCompactionModel(model, scope?, options?)` and `setDecisionModel(model, scope?, options?)` update the active session's compaction or decision model immediately without restarting or reloading. They save to `"global"` (default) or `"project"` settings unless `{ persist: false }` is passed. Pass `""` or `"auto"` for automatic selection, or an exact `provider/model` ID. Invalid values throw `CompactionConfigError` or `DecisionConfigError` synchronously. See [Compaction](/compaction) and [
|
|
353
|
+
- `setCompactionModel(model, scope?, options?)` and `setDecisionModel(model, scope?, options?)` update the active session's compaction or decision model immediately without restarting or reloading. They save to `"global"` (default) or `"project"` settings unless `{ persist: false }` is passed. Pass `""` or `"auto"` for automatic selection, or an exact `provider/model` ID. Invalid values throw `CompactionConfigError` or `DecisionConfigError` synchronously. See [Compaction](/compaction) and [Make structured decisions](/sdk/structured-decisions).
|
|
333
354
|
- Extension APIs reject new actions with an `Error` tagged with `code: "SessionClosed"` once close or reload starts. Give `atomic.exec()` calls timeouts or abort signals. Custom messages with `persistWhenStreaming: true` survive reload.
|
|
334
355
|
|
|
335
356
|
#### Event subscriptions
|
|
@@ -359,9 +380,9 @@ Disposal and reload drain admitted callbacks, model refreshes, and `atomic.exec(
|
|
|
359
380
|
|
|
360
381
|
- `await runtime.dispose()` rejects new replacements, drains pending work, waits up to 3 s for in-flight OAuth token refreshes, and stops Intercom broker startup. Pass `{ fromSignal: true }` on `SIGTERM` or `SIGHUP` so `session_shutdown` handlers receive the signal flag.
|
|
361
382
|
- Unrecovered `persist: true` settings write failures cause `dispose()` to reject with `AggregateError` (`code: "ShutdownFailed"`). `executeBash()` IDs are correlation IDs: `abortBash(id)` cancels all active calls sharing that ID.
|
|
362
|
-
- For
|
|
383
|
+
- For reload lifecycle effects (`publishExtensionContextEffect`, `registerExtensionContextRetirementEffect`), see [Reload lifecycle and resource ownership](/sdk/reference#reload-lifecycle-and-resource-ownership).
|
|
363
384
|
|
|
364
|
-
#### Compaction and tree navigation
|
|
385
|
+
#### Compaction and tree navigation {#compaction-and-tree-navigation}
|
|
365
386
|
|
|
366
387
|
`session.compact({ query?, compactionModel? })` stops active runs, clears context or replaces it with output from a configured compactor model such as `morph/morph-compactor`, appends a `verbatim-lines` `compaction` entry, and returns `VerbatimCompactionResult` (`form: "cleared" | "compacted"`). It rejects with `CompactionStateError` (`code: "nothing-to-compact"`) when nothing new has entered context since the last boundary; concurrent calls coalesce. Call `session.setCompactionModel(model, scope?, options?)` to change the configured compactor live. A chat, classifier, or unknown `compactionModel` ID clears the context with a notice instead of failing. See [Compaction errors](/compaction/reference#compaction-errors), [Compaction](/compaction), and [Session format](/session-format#compactionentry).
|
|
367
388
|
|
|
@@ -402,9 +423,9 @@ const runtime = await createAgentSessionRuntime(createRuntime, {
|
|
|
402
423
|
});
|
|
403
424
|
```
|
|
404
425
|
|
|
405
|
-
After any replacement, `runtime.session` points to the new session. Re-subscribe to events, call `bindExtensions()` again, and call `startPendingRecovery("resume")` after `switchSession()`.
|
|
426
|
+
After any replacement, `runtime.session` points to the new session. Re-subscribe to events, call `bindExtensions()` again, call `runtime.takeResumeNotices()` to display any resume warnings, and call `startPendingRecovery("resume")` after `switchSession()`. Pass `interactive: true` to `createAgentSessionRuntime()` only when attaching an interactive UI (by default `false`, so resumed worktree blueprint builds run behind the first turn unless `resume.waitForBlueprint` is set).
|
|
406
427
|
|
|
407
|
-
### Releasing idle sessions
|
|
428
|
+
### Releasing idle sessions {#releasing-idle-sessions}
|
|
408
429
|
|
|
409
430
|
Free in-memory resources (agent loop, extensions, tools, timers, MCP and Intercom connections) for idle conversations with `session.release()`, and restore them on demand with `runtime.rehydrate(sessionId)`:
|
|
410
431
|
|
|
@@ -415,7 +436,7 @@ await live.prompt("Here is the CI result you were waiting for.");
|
|
|
415
436
|
await live.release();
|
|
416
437
|
```
|
|
417
438
|
|
|
418
|
-
- **Auto-release:** Pass `releaseWhenIdle: { afterMs }` (`0` to `2,147,483,647` ms; invalid values throw `AgentReleaseConfigError`) to `createAgentSession()` or `createAgentSessionFromServices()`. If the session is still busy when the timer fires, Atomic reschedules for another `afterMs` instead of failing. Managed by the process-wide `agentWakeDispatcher()` (`handle`, `deliver`, `onUnobservedFailure`, `whenIdle`, `stats()`).
|
|
439
|
+
- **Auto-release:** Pass `releaseWhenIdle: { afterMs }` (`0` to `2,147,483,647` ms; invalid values throw `AgentReleaseConfigError`) to `createAgentSession()` or `createAgentSessionFromServices()`. Combining `releaseWhenIdle` with `SessionManager.inMemory()` rejects immediately in `createAgentSession()` with `AgentRehydrateError` (`code: "not-reopenable"`) before constructing the session. If the session is still busy when the timer fires, Atomic reschedules for another `afterMs` instead of failing. Managed by the process-wide `agentWakeDispatcher()` (`handle`, `deliver`, `onUnobservedFailure`, `whenIdle`, `stats()`).
|
|
419
440
|
- **Lifecycle:** Emits `session_released` before closing. Rejects with retryable `session-busy` if streaming, compacting, running shells or background tasks, or holding queued messages. `rehydrate()` opens at the current context window (`readHistory()` and `readEntry()` fetch older entries), shares matching-cwd `services`, runs alongside `runtime.session` without replacing it, deduplicates concurrent calls, and closes on `runtime.dispose()`.
|
|
420
441
|
- **In-memory store spilling:** A directly constructed `new MemorySessionStore()` has no spill directory and keeps released session history in RAM. Opening a memory store through `resolveSessionStore(cwd, { agentDir, sessionStore: { kind: "memory" } })` enables disk spilling to private owner-only files (`0700`/`0600`) under `<agentDir>/released-history/` with integrity verification (`SessionSpillError` on missing or corrupt files; see [Storage errors](/storage#storage-errors)). Spill files clean up on exit and sweep on restart after crashes; worker-only hosts must close stores before `worker.terminate()`. Custom stores can implement `releaseSession(id)`, `readEntryRange(id, query)`, and `readForkWindow(id, entryId)`.
|
|
421
442
|
|
|
@@ -459,7 +480,7 @@ Access the underlying [`@bastani/atomic-agent-core`](/libraries/agent-core) `Age
|
|
|
459
480
|
|
|
460
481
|
### Events and transcript collection
|
|
461
482
|
|
|
462
|
-
Subscribe with `session.subscribe((event) => ...)` for `message_start`/`message_update`/`message_end`, `tool_execution_start`/`update`/`end`, `agent_start`/`end`/`settled`, `turn_start`/`end`, `queue_update`, `compaction_start`/`end`, and retry events. Never mutate `message_start`'s live partial object (seed mid-turn subscribers from `session.agent.state.streamingMessage`).
|
|
483
|
+
Subscribe with `session.subscribe((event) => ...)` for `message_start`/`message_update`/`message_end`, `tool_execution_start`/`update`/`end`, `agent_start`/`end`/`settled`, `turn_start`/`end`, `queue_update`, `compaction_start`/`end`, `session_storage_reconnect` (emitted when ordered PostgreSQL session writes wait for reconnection or recover), and retry/fallback events. Never mutate `message_start`'s live partial object (seed mid-turn subscribers from `session.agent.state.streamingMessage`).
|
|
463
484
|
|
|
464
485
|
Use `createTranscript()` to collect ordered JSON-serializable parts (`text`, `thinking`, and `toolCall` with `result`). Pass `toolResult: (name) => "details" | "content"` to prefer structured details over text; redacted thinking is omitted, and nested tool events (`parentToolCallId`) are ignored.
|
|
465
486
|
|
|
@@ -478,7 +499,6 @@ console.log(JSON.stringify(transcript.parts()));
|
|
|
478
499
|
## Complete example
|
|
479
500
|
|
|
480
501
|
```typescript
|
|
481
|
-
import { getModel } from "@bastani/atomic-ai/compat";
|
|
482
502
|
import { Type } from "@bastani/atomic/typebox";
|
|
483
503
|
import {
|
|
484
504
|
AuthStorage,
|
|
@@ -511,7 +531,7 @@ const statusTool = defineTool({
|
|
|
511
531
|
}),
|
|
512
532
|
});
|
|
513
533
|
|
|
514
|
-
const model = getModel("anthropic", "claude-opus-4-5");
|
|
534
|
+
const model = modelRuntime.getModel("anthropic", "claude-opus-4-5");
|
|
515
535
|
if (!model) throw new Error("Model not found");
|
|
516
536
|
|
|
517
537
|
const settingsManager = SettingsManager.inMemory({
|
|
@@ -557,8 +577,9 @@ try {
|
|
|
557
577
|
|
|
558
578
|
### Error classes vs. `.code`-tagged errors
|
|
559
579
|
|
|
560
|
-
|
|
561
|
-
|
|
580
|
+
<Note>
|
|
581
|
+
`NativeModuleUnavailableError` is an exported class (`code: "NativeModuleUnavailable"`). By contrast, `ShutdownFailed`, `HumanInputUnavailable`, `InvalidHostInput`, `BuiltinUnavailable`, and `SessionClosed` are **not** exported classes — they are standard `Error` (or `AggregateError` for `ShutdownFailed`) instances tagged with string `.code` properties. Branch on `(error as { code?: string }).code` rather than `instanceof`.
|
|
582
|
+
</Note>
|
|
562
583
|
|
|
563
584
|
### Updating Atomic while your program runs
|
|
564
585
|
|
|
@@ -571,26 +592,27 @@ When `npm install`, `pnpm add`, or `bun add` replaces `@bastani/atomic` while a
|
|
|
571
592
|
|
|
572
593
|
Also restart after an in-place update if your process launched on an older Atomic release or before importing `@bastani/atomic/rpc-entry`.
|
|
573
594
|
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
Atomic
|
|
577
|
-
|
|
578
|
-
1. Run `node --version` to
|
|
579
|
-
2. Install the current Node.js 24 LTS release from [nodejs.org](https://nodejs.org/en/download), or with `nvm install 24`, `fnm install 24
|
|
580
|
-
3. Reinstall
|
|
581
|
-
4.
|
|
582
|
-
|
|
583
|
-
See [Node.js version](/getting-started/installation#nodejs-version) for
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
- **
|
|
588
|
-
- **
|
|
589
|
-
- **
|
|
590
|
-
- **
|
|
591
|
-
- **
|
|
592
|
-
|
|
595
|
+
<AccordionGroup>
|
|
596
|
+
<Accordion title="Upgrading from Node.js 22 hosts">
|
|
597
|
+
Atomic requires Node.js 24.20.0 or newer and no longer runs on Node.js 22:
|
|
598
|
+
|
|
599
|
+
1. Run `node --version` to verify your installed runtime.
|
|
600
|
+
2. Install the current Node.js 24 LTS release from [nodejs.org](https://nodejs.org/en/download), or with `nvm install 24`, `fnm install 24`, or `mise use -g node@24`.
|
|
601
|
+
3. Reinstall project dependencies with `npm install`.
|
|
602
|
+
4. Remove `--experimental-async-context-frame` from your startup command if you used it on Node 22 (Node 24 refuses to start with that flag).
|
|
603
|
+
|
|
604
|
+
See [Node.js version](/getting-started/installation#nodejs-version) for details.
|
|
605
|
+
</Accordion>
|
|
606
|
+
<Accordion title="Migrating an existing Node host from earlier releases">
|
|
607
|
+
- **Builtins load automatically:** Remove manual registration of shipped builtin extensions; disable selectively with `builtins` and restrict tools with `tools` / `excludedTools` (`tools: []` excludes Intercom too).
|
|
608
|
+
- **Host input:** Supply all five `HostInput` methods (`confirm`, `select`, `input`, `editor`, `questionnaire`) on `extensionBindings.humanInput`, honoring abort signals and returning literal `true` only on explicit approval (omission rejects with `code: "HumanInputUnavailable"`).
|
|
609
|
+
- **Removed `workflows` builtin:** Remove `workflows` from `builtins`; workflow SDK exports were removed. Convert older workflow files into skills ([Migrating workflows](/orchestration/migrating-workflows)).
|
|
610
|
+
- **Always `await session.dispose()` in `finally`:** Disposal is async and may reject with `AggregateError` (`code: "ShutdownFailed"`) after attempting all cleanup; do not swallow it or call `process.exit()`.
|
|
611
|
+
- **Diagnostics and packaging:** Capture operational events via `extensionBindings.onDiagnostic`. If creation fails with `code: "BuiltinUnavailable"`, reinstall the full package rather than copying only `dist/index.js`.
|
|
612
|
+
- **Removed experimental client:** `@bastani/atomic/client` was removed; embed `createAgentSession()` directly or drive [RPC mode](/rpc) (`--mode rpc` / `@bastani/atomic/rpc-entry`).
|
|
613
|
+
</Accordion>
|
|
614
|
+
</AccordionGroup>
|
|
593
615
|
|
|
594
616
|
## API reference
|
|
595
617
|
|
|
596
|
-
All factory options,
|
|
618
|
+
All factory options, `AgentSession` and `AgentSessionRuntime` methods, resource loaders, run modes (`InteractiveMode`, `runPrintMode`, `runRpcMode`), error families, task supervision, and exports are documented in the [SDK API reference](/sdk/reference).
|
package/docs/security.md
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: "
|
|
3
|
-
sidebarTitle: "Security"
|
|
2
|
+
title: "Manage security and project trust"
|
|
3
|
+
sidebarTitle: "Security & Project Trust"
|
|
4
4
|
description: "Configure project trust, restrict tools, understand local security boundaries, and safely export credentials."
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
Atomic is a local coding agent. It runs with the permissions of the user account that starts it and treats files writable by that user as inside the same local trust boundary.
|
|
7
|
+
Atomic is a local coding agent. It runs with the permissions of the OS user account that starts it and treats files writable by that user as inside the same local trust boundary.
|
|
8
8
|
|
|
9
9
|
## Project trust
|
|
10
10
|
|
|
11
|
-
Project trust controls whether Atomic loads project-local settings, instructions, resources, packages, and extensions. It is not a sandbox and does not
|
|
11
|
+
Project trust controls whether Atomic loads project-local settings, instructions, resources, packages, and extensions before work begins. It is not a sandbox and does not limit what tools can do once a session starts.
|
|
12
12
|
|
|
13
13
|
Atomic treats a folder as having trust-gated inputs when it finds any of these from the current working directory:
|
|
14
14
|
|
|
@@ -17,11 +17,13 @@ Atomic treats a folder as having trust-gated inputs when it finds any of these f
|
|
|
17
17
|
- `.agents/skills` in the current directory or an ancestor directory. `~/.agents/skills` in your home directory is always treated as a trusted user resource and never triggers project trust.
|
|
18
18
|
- At the nearest ancestor project root (any ancestor containing `.atomic/`, `.pi/`, or `.agents/`), any `.agents/` directory, `.atomic/agents`, `.pi/agents`, `.atomic/settings.json`, or `.pi/settings.json`. Your home directory is never treated as an ancestor project root for these checks.
|
|
19
19
|
|
|
20
|
+
### How decisions are stored and prompted
|
|
21
|
+
|
|
20
22
|
Saved decisions live in `~/.atomic/agent/trust.json`, keyed by canonical directory path mapped to `true` or `false`. Atomic checks `trust.json` from the current directory upward and applies the closest saved decision ahead of global defaults. A saved `false` entry for the current folder or an ancestor still marks the folder untrusted even when no trust-gated files are present right now.
|
|
21
23
|
|
|
22
|
-
|
|
24
|
+
Atomic saves `trust.json` safely across concurrent sessions and follows symlinks. On Windows, saved paths match case-insensitively and saving removes duplicate entries with different casing. If `trust.json` contains malformed JSON or invalid values, Atomic warns once and treats it as empty until the next save; if permissions prevent reading the file, saving fails instead of overwriting it.
|
|
23
25
|
|
|
24
|
-
When no saved decision matches and the folder has trust-gated inputs, Atomic checks global `defaultProjectTrust` in `~/.atomic/agent/settings.json` (`"ask"`, `"always"`, or `"never"`; default `"ask"`). `defaultProjectTrust` is global-only: Atomic ignores it in project `.atomic/settings.json` and falls back to `"ask"` if the global value is invalid or unreadable
|
|
26
|
+
When no saved decision matches and the folder has trust-gated inputs, Atomic checks global `defaultProjectTrust` in `~/.atomic/agent/settings.json` (`"ask"`, `"always"`, or `"never"`; default `"ask"`). `defaultProjectTrust` is global-only: Atomic ignores it in project `.atomic/settings.json` and falls back to `"ask"` if the global value is invalid or unreadable.
|
|
25
27
|
|
|
26
28
|
In an interactive session with `defaultProjectTrust: "ask"`, Atomic opens a trust prompt with five options (four at the filesystem root):
|
|
27
29
|
|
|
@@ -33,9 +35,11 @@ In an interactive session with `defaultProjectTrust: "ask"`, Atomic opens a trus
|
|
|
33
35
|
|
|
34
36
|
Choosing **Trust parent folder** saves `true` for the parent directory and removes any saved entry for the current directory so it inherits from the parent. Pressing `Escape` cancels the prompt and leaves the folder untrusted for this session only without writing to `trust.json`.
|
|
35
37
|
|
|
36
|
-
|
|
38
|
+
<Note>
|
|
39
|
+
Use `Up`/`Down` and `Enter` to confirm. If you typed or pasted text before or while the prompt opened, `Enter` is disarmed so it adds a newline to your draft instead of confirming trust by accident — press `Up` or `Down` once to arm `Enter`.
|
|
37
40
|
|
|
38
|
-
Run `/trust` at any time to save a persistent choice
|
|
41
|
+
Run `/trust` at any time to save a persistent choice, then **restart Atomic** for the new choice to take effect (`/reload` does not re-evaluate a newly saved `/trust` decision). To clear a saved entry completely, remove its path from `~/.atomic/agent/trust.json`.
|
|
42
|
+
</Note>
|
|
39
43
|
|
|
40
44
|
If you start an interactive session in a clean folder (no trust-gated inputs at startup and neither `--approve` nor `--no-approve`) and create trust-gated files such as `.atomic/settings.json` or `.atomic/extensions` during that session, running `/reload` automatically saves `true` for that folder in `trust.json` when no decision is saved yet.
|
|
41
45
|
|
|
@@ -48,26 +52,26 @@ Trusting a project lets Atomic load:
|
|
|
48
52
|
- Project-local `AGENTS.override.md`, `AGENTS.md`, `AGENTS.MD`, `CLAUDE.md`, and `CLAUDE.MD`, plus project `.agents/skills`
|
|
49
53
|
- Project subagent definitions and agent overrides (`.atomic/agents`, `.pi/agents`, and `.agents`)
|
|
50
54
|
- Earlier workflow files for on-demand [conversion to skills](/orchestration/migrating-workflows) (read as text only, never executed, modified, or deleted)
|
|
51
|
-
- Project MCP server config ([`.atomic/mcp.json`](/mcp-servers); `auth.provider` is forbidden in project configs and package manifests,
|
|
55
|
+
- Project MCP server config ([`.atomic/mcp.json`](/mcp-servers); reusing Atomic's saved provider credentials via `auth.provider` is forbidden in project configs and package manifests, while `!command` values run shell commands) and blueprint builds ([`.atomic/blueprint.yaml`](/guides/resume-on-any-machine#set-the-environment-up-with-a-blueprint))
|
|
52
56
|
- Project-configured [packages](/packages) (`atomic install -l` requires project trust or `--approve`), automatic installation of missing project packages, and package-managed extensions
|
|
53
57
|
|
|
54
|
-
Declining trust skips all of these project inputs
|
|
58
|
+
Declining trust skips all of these project inputs while keeping global instructions, global skills, global settings, and explicit CLI resources available. Interactive sessions in an untrusted project display a warning; run `/trust` and restart Atomic to enable project inputs.
|
|
55
59
|
|
|
56
60
|
### Folders, worktrees, non-interactive runs, and extension hooks
|
|
57
61
|
|
|
58
|
-
- **Per-folder trust
|
|
59
|
-
- **Git worktrees
|
|
60
|
-
- **Extension `project_trust` hooks
|
|
61
|
-
- **
|
|
62
|
-
- **Non-interactive runs
|
|
62
|
+
- **Per-folder trust.** Trust belongs to the folder a session works in, not the directory you launched Atomic from. Resuming a session (`--resume`, `--continue`, `--session`, or `/resume`) applies that folder's trust decision and prompts if none is saved. Session-only choices last until Atomic exits and never write to `trust.json`.
|
|
63
|
+
- **Git worktrees.** A worktree outside its main repository folder has its own trust decision because it can check out different `.atomic` content. Choose **Trust parent folder** (at the prompt or in `/trust`) to trust sibling worktrees under one parent directory.
|
|
64
|
+
- **Extension `project_trust` hooks.** Global and explicit CLI `-e` extensions can decide project trust through the [`project_trust`](/extensions/events#project_trust) hook before Atomic checks `trust.json` or prompts you. The first handler returning `{ trusted: "yes" }` or `{ trusted: "no" }` wins (and saves to `trust.json` when `remember: true`), while `{ trusted: "undecided" }` passes to later handlers and built-in trust rules; hooks do not run when `--approve` or `--no-approve` overrides trust. See `project-trust.ts` in [Extension examples](/extensions/examples#events-and-gates).
|
|
65
|
+
- **External `-e` directories.** If a directory passed to `-e <dir>` contains resources under its own `.atomic`, legacy `.pi`, or `.agents/skills`, Atomic checks `trust.json` for that directory's canonical path before loading them, because those extensions run with your user permissions. Passing `--approve` (`-a`) or `--no-approve` (`-na`) also overrides trust for those directories.
|
|
66
|
+
- **Non-interactive runs.** Print mode (`-p`), `--mode json`, and `--mode rpc` never open a trust prompt. Without a saved decision, `defaultProjectTrust: "ask"` and `"never"` leave the project untrusted and skip project resources, while `"always"` trusts the project. Pass `--approve` (`-a`) or `--no-approve` (`-na`) to override trust for one run.
|
|
63
67
|
|
|
64
68
|
## No built-in sandbox
|
|
65
69
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
70
|
+
<Warning>
|
|
71
|
+
Atomic does **not** include a built-in sandbox. Built-in tools read, write, and edit files and execute shell commands with the permissions of the OS user running Atomic, and extensions execute as TypeScript modules with the same permissions. Use OS isolation, a container, or a VM whenever you need a security boundary.
|
|
72
|
+
</Warning>
|
|
69
73
|
|
|
70
|
-
Project trust only
|
|
74
|
+
Project trust only prevents an untrusted repository from changing settings or running extensions before you approve it. It does not make untrusted code, prompts, or model output safe. Prompt injection from repository files, comments, docs, context files, or command output is an inherent risk for any local coding agent.
|
|
71
75
|
|
|
72
76
|
When shell tools are enabled, model-supplied commands run through the configured shell with your user permissions, and Atomic provides no command-level allowlist or denylist. Be careful with shells, interpreters, package managers, `curl`, `git`, `sudo`, `env`, `xargs`, and any other program that can run arbitrary commands.
|
|
73
77
|
|
|
@@ -77,7 +81,7 @@ You can narrow which tools a session exposes:
|
|
|
77
81
|
- **Settings:** Configure `defaultTools` in [Settings](/settings#tools) globally or in a trusted project.
|
|
78
82
|
- **SDK:** Pass `tools`, `excludedTools`, or `noTools` when creating a session ([SDK tools reference](/sdk/reference#tools)).
|
|
79
83
|
|
|
80
|
-
On native Windows, Atomic enables the [`powershell` tool](/windows#powershell-tool) alongside `bash` whenever PowerShell is installed. Excluding `bash` alone
|
|
84
|
+
On native Windows, Atomic enables the [`powershell` tool](/windows#powershell-tool) alongside `bash` whenever PowerShell is installed. Excluding `bash` alone leaves `powershell` enabled; exclude both to disable all shell execution:
|
|
81
85
|
|
|
82
86
|
```bash
|
|
83
87
|
atomic --exclude-tools bash,powershell
|
|
@@ -89,11 +93,11 @@ Use a container, VM, remote sandbox, restricted OS account, or custom extension
|
|
|
89
93
|
|
|
90
94
|
Atomic enforces several local guardrails by default:
|
|
91
95
|
|
|
92
|
-
- **
|
|
96
|
+
- **Private-network blocking on URL reads (SSRF protection).** `read` blocks `localhost`, `.localhost`, private IP ranges, cloud metadata endpoints, and redirects to them ([Documents and URLs](/tools#documents-and-urls)). Set `ATOMIC_ALLOW_PRIVATE_URL_READS=1` only when a workflow must read private URLs ([Environment variables](/environment-variables)). Bundled `@bastani/web-access` also keeps local or intranet hosts and credentialed URLs out of remote fallbacks ([Web access](/web-access)).
|
|
93
97
|
- **Opt-in browser cookies.** Gemini Web cookie lookup is disabled by default and activates only when you set `allowBrowserCookies: true` in `~/.atomic/web-search.json` or `ATOMIC_ALLOW_BROWSER_COOKIES=1` ([Web access](/web-access)).
|
|
94
98
|
- **Worktree snapshot secret deny list.** [Worktree snapshots](/worktree-snapshots) exclude `.env*`, `*.pem`, `*.key`, `*.p12`, `*.pfx`, `credentials`, `credentials.json`, `.netrc`, `_netrc`, `.git-credentials`, `.pgpass`, and private SSH key files before `.atomic/snapshot-ignore` or Git staging. This deny list cannot be overridden ([What is left out](/worktree-snapshots#what-is-left-out)).
|
|
95
99
|
- **Storage credentials and process overrides.** Shared storage rejects credentials embedded in URLs and saves static tokens in mode-`600` files. Process-level storage overrides (`--storage`, `--storage-file`, `ATOMIC_STORAGE`, `ATOMIC_SESSIONS_STORAGE`) come from the launching host and bypass project trust ([Selecting storage per process](/storage#selecting-storage-per-process)).
|
|
96
|
-
- **Session sharing and debug snapshots.** `/share` uploads a private GitHub gist and strips worktree snapshots and large tool-output blobs
|
|
100
|
+
- **Session sharing and debug snapshots.** `/share` uploads a private GitHub gist and strips worktree snapshots and large tool-output blobs while keeping the rest of the transcript ([Exporting and sharing sessions](/usage#exporting-and-sharing-sessions)). `/debug` writes all current session messages unredacted to `~/.atomic/agent/atomic-debug.log` ([Diagnostics and debugging](/development#debugging)).
|
|
97
101
|
|
|
98
102
|
## Running untrusted or unattended work
|
|
99
103
|
|
|
@@ -103,59 +107,33 @@ See [Run Atomic in containers](/containerization) for common setups:
|
|
|
103
107
|
|
|
104
108
|
- Run the whole `atomic` process inside Docker or NVIDIA OpenShell.
|
|
105
109
|
- Run Atomic on the host while routing built-in file and shell tools into a Gondolin micro-VM.
|
|
106
|
-
- Mount only the workspace paths the agent needs.
|
|
107
|
-
-
|
|
108
|
-
- Pass only the minimum required API keys or short-lived tokens.
|
|
109
|
-
- Restrict outbound network access when the task does not need it.
|
|
110
|
+
- Mount only the workspace paths the agent needs, and avoid mounting host `~/.atomic` or `~/.atomic/agent` unless the container should access host sessions, settings, and credentials.
|
|
111
|
+
- Pass only the minimum required API keys or short-lived tokens, and restrict outbound network access when the task does not need it.
|
|
110
112
|
- Review diffs and outputs before copying files back to trusted systems.
|
|
111
113
|
|
|
112
114
|
If you bind-mount a host directory read/write, writes inside the container or VM modify host files directly. Use read-only mounts or copy files in and out when you need to protect host checkouts from unintended writes.
|
|
113
115
|
|
|
114
116
|
## Credential export
|
|
115
117
|
|
|
116
|
-
`atomic auth print-api-key`, `atomic auth print-bearer-token`, and `atomic auth check --credentials` export a resolved credential to stdout so external clients can reuse your Atomic authentication without reading `auth.json`. `atomic auth check` without `--credentials` stays status-only and never prints a secret.
|
|
118
|
+
`atomic auth print-api-key`, `atomic auth print-bearer-token`, and `atomic auth check --credentials` export a resolved credential to stdout so external clients can reuse your Atomic authentication without reading `auth.json`. Plain `atomic auth check` (without `--credentials`) stays status-only and never prints a secret.
|
|
117
119
|
|
|
118
120
|
```bash
|
|
119
|
-
TOKEN=$(atomic auth print-bearer-token --provider openai-codex --model gpt-
|
|
121
|
+
TOKEN=$(atomic auth print-bearer-token --provider openai-codex --model gpt-6.2-sol --min-expiry 45m)
|
|
120
122
|
KEY=$(atomic auth check --provider openai --credentials)
|
|
121
123
|
```
|
|
122
124
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
- **
|
|
130
|
-
- **
|
|
131
|
-
- **No log leakage.** Atomic never writes exported credentials to debug logs, session transcripts, error messages, or RPC responses.
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
| Exit code | Meaning |
|
|
136
|
-
| --- | --- |
|
|
137
|
-
| `0` | Credential written to stdout |
|
|
138
|
-
| `1` | Usage error (invalid flag or missing `--model`) |
|
|
139
|
-
| `2` | No credential configured for the resolved provider |
|
|
140
|
-
| `3` | Provider ambiguous (multiple configured providers matched `--model`) |
|
|
141
|
-
| `4` | Wrong credential kind (provider uses OAuth when API key was requested, or vice versa) |
|
|
142
|
-
| `5` | OAuth refresh failed (stored credential left untouched) |
|
|
143
|
-
| `6` | Refreshed token still expires sooner than `--min-expiry` |
|
|
144
|
-
| `7` | OAuth credential derivation failed (a refresh may already have persisted) |
|
|
145
|
-
| `8` | Output write failed before any bytes were emitted |
|
|
146
|
-
| `9` | Partial write to stdout; discard the received bytes |
|
|
147
|
-
|
|
148
|
-
### Exit codes for `auth check`
|
|
149
|
-
|
|
150
|
-
| Exit code | Meaning |
|
|
151
|
-
| --- | --- |
|
|
152
|
-
| `0` | Provider is ready |
|
|
153
|
-
| `1` | Provider is not ready |
|
|
154
|
-
| `2` | Auth state or command is invalid |
|
|
155
|
-
| `8` | With `--credentials`, output write failed before any bytes were emitted |
|
|
156
|
-
| `9` | With `--credentials`, partial write to stdout; discard the received bytes |
|
|
157
|
-
|
|
158
|
-
Once a credential reaches stdout, it is ordinary text in your shell or pipeline. Prefer `print-bearer-token`, which emits an expiring token, over a long-lived API key, and never call credential export inside a script that logs its own stdout.
|
|
125
|
+
<Warning>
|
|
126
|
+
Once a credential reaches stdout, it is ordinary text in your shell or pipeline. Prefer `print-bearer-token` (which emits a short-lived OAuth token) over a long-lived API key, never run credential export inside a script that logs stdout, and discard received bytes whenever the command exits with code `9` (partial write).
|
|
127
|
+
</Warning>
|
|
128
|
+
|
|
129
|
+
Security guarantees to keep in mind when wiring credential export into automation:
|
|
130
|
+
|
|
131
|
+
- **Stdout carries secrets only on explicit export.** Warnings, refresh notices, and help text go to stderr. Failed raw exports leave stdout empty (except exit code `9` for a partial stream write).
|
|
132
|
+
- **Specify `--provider` to avoid ambiguity.** `print-api-key` and `print-bearer-token` require `--model`; omitting `--provider` falls back to fuzzy matching and can inspect (and refresh an expiring OAuth token on) multiple configured candidates before failing as ambiguous. `auth check --credentials` requires `--provider` or an exact `--model`.
|
|
133
|
+
- **No file sinks or log leakage.** There is no `--output` or clipboard flag, and Atomic never writes exported credentials to debug logs, session transcripts, error messages, or RPC responses.
|
|
134
|
+
- **Read-only probes.** Pass `--no-refresh` to `atomic auth check` when you want a read-only check that never modifies `auth.json`.
|
|
135
|
+
|
|
136
|
+
See [CLI credential commands](/reference/cli#credential-commands) for all flag rules (`--min-expiry`, `--no-refresh`, `--json`) and the complete exit-code tables (`0`–`9`).
|
|
159
137
|
|
|
160
138
|
## Reporting security issues
|
|
161
139
|
|