@bastani/atomic 0.9.19-alpha.6 → 0.9.19-alpha.8
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 +6 -0
- package/README.md +2 -2
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/web-access/CHANGELOG.md +6 -0
- package/dist/builtin/web-access/index.bundle.mjs +22 -3
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/builtin/workflows/CHANGELOG.md +19 -0
- package/dist/builtin/workflows/README.md +1 -1
- package/dist/builtin/workflows/builtin/adversarial-verification.js +2 -2
- package/dist/builtin/workflows/builtin/{chunk-vhmnzdj9.js → chunk-1jth021m.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-p8jjwfg6.js → chunk-2377r57g.js} +4 -2
- package/dist/builtin/workflows/builtin/{chunk-hbnwv56f.js → chunk-31j2gs7h.js} +2 -2
- package/dist/builtin/workflows/builtin/{chunk-n8zysf1t.js → chunk-ngkqkzej.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-1nbq96fh.js → chunk-nkrafh9s.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-1kx4aggw.js → chunk-wf741bv3.js} +2 -2
- package/dist/builtin/workflows/builtin/{chunk-t6x2d78s.js → chunk-z29qbehr.js} +1 -1
- package/dist/builtin/workflows/builtin/generate-and-filter.js +2 -2
- package/dist/builtin/workflows/builtin/goal.js +3 -3
- package/dist/builtin/workflows/builtin/index.js +7 -7
- package/dist/builtin/workflows/builtin/ralph.js +3 -3
- package/dist/builtin/workflows/builtin/tournament.js +2 -2
- package/dist/builtin/workflows/package.json +1 -1
- package/dist/builtin/workflows/src/extension/index.bundle.mjs +590 -256
- package/dist/builtin/workflows/src/index.js +67 -19
- package/dist/builtin/workflows/src/shared/authoring-contract-stage.d.ts +2 -0
- package/dist/modes/interactive/components/task-live-transcript.d.ts +1 -1
- package/dist/modes/interactive/components/task-live-transcript.d.ts.map +1 -1
- package/dist/modes/interactive/components/task-live-transcript.js +19 -11
- package/dist/modes/interactive/components/task-live-transcript.js.map +1 -1
- package/docs/background-tasks.md +1 -1
- package/docs/build.md +51 -0
- package/docs/changelog.mdx +8 -8
- package/docs/compaction/reference.md +267 -0
- package/docs/compaction.md +36 -219
- package/docs/computer-use.md +35 -0
- package/docs/containerization.md +2 -0
- package/docs/custom-provider/api-reference.md +145 -0
- package/docs/custom-provider/oauth.md +131 -0
- package/docs/custom-provider/override.md +34 -0
- package/docs/custom-provider/registration.md +163 -0
- package/docs/custom-provider/streaming.md +214 -0
- package/docs/custom-provider.md +43 -607
- package/docs/development.md +76 -0
- package/docs/docs.json +199 -77
- package/docs/environment-variables.md +1 -1
- package/docs/extensions/api-reference.md +1001 -0
- package/docs/extensions/authoring.md +676 -0
- package/docs/extensions/events.md +793 -0
- package/docs/extensions/examples.md +94 -0
- package/docs/extensions/ui.md +470 -0
- package/docs/extensions.md +270 -2768
- package/docs/getting-started/authentication.md +55 -0
- package/docs/getting-started/first-session.md +172 -0
- package/docs/getting-started/installation.md +154 -0
- package/docs/getting-started/project-instructions.md +43 -0
- package/docs/guides/configuration.md +65 -0
- package/docs/guides/intercom.md +24 -0
- package/docs/guides/non-interactive.md +33 -0
- package/docs/guides/subagents.md +24 -0
- package/docs/guides/workflows.md +27 -0
- package/docs/guides.md +41 -0
- package/docs/index.md +13 -45
- package/docs/intercom/operations.md +178 -0
- package/docs/intercom/reference.md +146 -0
- package/docs/intercom.md +54 -259
- package/docs/json.md +17 -0
- package/docs/llama-cpp.md +5 -0
- package/docs/models/artificial-analysis-index.md +89 -0
- package/docs/models/evals.md +2 -2
- package/docs/models/model-selection.md +3 -3
- package/docs/models/pareto-efficiency.md +2 -2
- package/docs/models/reference.md +601 -0
- package/docs/models.md +45 -550
- package/docs/packages/authoring.md +88 -0
- package/docs/packages/reference.md +43 -0
- package/docs/packages.md +28 -107
- package/docs/programmatic.md +29 -0
- package/docs/prompt-templates.md +11 -0
- package/docs/providers/reference.md +23 -0
- package/docs/providers.md +10 -15
- package/docs/quickstart.md +44 -238
- package/docs/reference/cli.md +252 -0
- package/docs/reference.md +52 -0
- package/docs/rpc/examples.md +64 -0
- package/docs/rpc/extension-ui.md +198 -0
- package/docs/rpc/protocol.md +1341 -0
- package/docs/rpc.md +109 -1346
- package/docs/sdk/reference.md +1090 -0
- package/docs/sdk.md +56 -1002
- package/docs/session-format.md +2 -0
- package/docs/sessions.md +6 -10
- package/docs/settings.md +6 -45
- package/docs/skills/authoring.md +95 -0
- package/docs/skills/reference.md +60 -0
- package/docs/skills.md +20 -122
- package/docs/subagents/authoring.md +37 -0
- package/docs/subagents/reference.md +60 -0
- package/docs/subagents.md +39 -95
- package/docs/terminal-setup.md +1 -1
- package/docs/themes/reference.md +176 -0
- package/docs/themes.md +21 -135
- package/docs/tmux.md +5 -0
- package/docs/tools/edit.md +5 -0
- package/docs/tools.md +5 -0
- package/docs/tui/reference.md +343 -0
- package/docs/tui.md +23 -286
- package/docs/usage.md +26 -209
- package/docs/web-access.md +2 -0
- package/docs/windows.md +2 -1
- package/docs/workflows/api-reference.md +11 -4
- package/docs/workflows/authoring.md +4 -2
- package/docs/workflows/builtins.md +2 -2
- package/docs/workflows/operations.md +15 -10
- package/docs/workflows/reliable-design.md +21 -3
- package/docs/workflows/verification.md +8 -0
- package/npm-shrinkwrap.json +32 -32
- package/package.json +3 -3
package/docs/sdk.md
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "SDK"
|
|
3
|
+
description: "Embed Atomic in a Node.js application."
|
|
4
|
+
---
|
|
5
|
+
|
|
1
6
|
> Atomic can help you use the SDK. Ask it to build an integration for your use case.
|
|
2
7
|
|
|
3
8
|
# SDK
|
|
@@ -13,240 +18,13 @@ The SDK provides programmatic access to atomic's agent capabilities. Use it to e
|
|
|
13
18
|
|
|
14
19
|
See [examples/sdk/](https://github.com/bastani-inc/atomic/tree/main/packages/coding-agent/examples/sdk) for working examples from minimal to full control.
|
|
15
20
|
|
|
16
|
-
##
|
|
17
|
-
|
|
18
|
-
S1 adds an SDK-only task foundation in `src/core/tasks/contracts.ts` and
|
|
19
|
-
`src/core/tasks/supervisor.ts`, backed by the native `TaskSupervisor`. It is an
|
|
20
|
-
internal trusted-host integration surface, not a new CLI command. The package root
|
|
21
|
-
exports the narrow `AgentTaskHost` adapter and its integration types, not the raw
|
|
22
|
-
supervisor. Runtime-created subagent contexts use it; bash/PTY and task UI integration are separate slices.
|
|
23
|
-
|
|
24
|
-
`AgentTaskHost` binds an actual trusted scope and mandatory `authorizeLaunch` guard.
|
|
25
|
-
Its `startAgentTask(intent, operation, runnerFactory)` returns a Result containing
|
|
26
|
-
`{taskId, lease}` after setup. Each launch supplies its own factory receiving the
|
|
27
|
-
original `AbortSignal`, reference and `reportActivity` context. Return separate
|
|
28
|
-
`result` and `cleanup` promises; yielding never replaces either promise, and only
|
|
29
|
-
confirmed cleanup may report `reaped`. Exact operation replay never calls another factory.
|
|
30
|
-
`observeAgentLaunch(taskId, policy?)` delegates to S1 initial observation; `waitForTask`,
|
|
31
|
-
`resolveTask`, `cancelTask`, `watchOwnerTasks` and `close` remain owner-scoped S1 doors.
|
|
32
|
-
Observation returns the exact Result/WaitOutcome DTO, not a new model response shape.
|
|
33
|
-
These APIs are for trusted first-party hosts, never model-supplied ownership or permission.
|
|
34
|
-
|
|
35
|
-
For already-admitted in-process tasks, the optional `taskExecution` runner hooks
|
|
36
|
-
retain the original execution and cleanup promises. An exact Intercom commit
|
|
37
|
-
yields the registered observation. In an explicit foreground group it also yields
|
|
38
|
-
active sibling observations through the existing group signal, once per child;
|
|
39
|
-
neither path detaches or completes those executions. Public launches in actual sessions use this bridge by default.
|
|
40
|
-
|
|
41
|
-
Each workflow admission boundary allocates one process-private stage attempt identity.
|
|
42
|
-
The actual stage session binds its original session/run/stage identity; fallback session
|
|
43
|
-
replacement keeps that identity and the same lazily bound `bindAgentTaskHost` owner.
|
|
44
|
-
Replacement disposal does not close tasks. Boundary sealing fences task admission and
|
|
45
|
-
starts owner closure; generation close awaits independent cleanup and surfaces failure.
|
|
46
|
-
Fresh boundaries have fresh identities, including restoration; history is not a restart
|
|
47
|
-
capability. Public producers, durable callback joins and nonvisual completion intent/admission use this owner binding.
|
|
48
|
-
|
|
49
|
-
When a task completion outbox is created from session history, it immediately retries
|
|
50
|
-
unacknowledged terminal completion intents through the current admission boundary.
|
|
51
|
-
It does not wait for another task to settle or recreate execution capabilities.
|
|
52
|
-
Acknowledged intents are not redelivered. Failed admission keeps the original completion
|
|
53
|
-
identity pending for retry; a closed boundary prevents admission.
|
|
54
|
-
Top-level session initialization restores admission keys from persisted custom messages,
|
|
55
|
-
so a crash after delivery is persisted but before its outbox acknowledgement does not
|
|
56
|
-
deliver the same completion again.
|
|
57
|
-
|
|
58
|
-
A host binds its actual session or workflow-stage scope with `bindHostSession`,
|
|
59
|
-
provides launch authorization and a runner factory, then calls `openTaskOwner`.
|
|
60
|
-
Authorization runs before native admission. `startAgentTask` registers an agent
|
|
61
|
-
task before runner setup and returns its lease without waiting for completion.
|
|
62
|
-
Exact operation replay reuses that task and execution; a fresh operation creates
|
|
63
|
-
a distinct task. Leases are environment-local capabilities, cannot be serialized,
|
|
64
|
-
and cannot be reconstructed from task IDs or historical records.
|
|
65
|
-
|
|
66
|
-
`initialObservation` applies launch policy: omitted policy yields
|
|
67
|
-
`default-background`, explicit background yields `explicit`, and foreground
|
|
68
|
-
registers a wait with its requested budget. A ready terminal result wins.
|
|
69
|
-
`await waitForTask(task, budgetMs?, designation?)` and
|
|
70
|
-
`await foregroundTask(task, budgetMs?)` return a Result containing a WaitOutcome,
|
|
71
|
-
not a lease. Native registration and the WaitId registry are populated synchronously
|
|
72
|
-
before either door awaits. Host lifecycle actions can use `findWait(waitId)` to
|
|
73
|
-
yield or dispose a registered observation; ordinary callers need no extra observe call.
|
|
74
|
-
SDK waits do not replace the host designation unless given a matching HostSession.
|
|
75
|
-
An elapsed/explicit yield or observer disposal never stops or relaunches execution;
|
|
76
|
-
a later yield of a disposed wait replays its ObserverCancelled Result.
|
|
77
|
-
|
|
78
|
-
Requested agent waits default to 30000 ms. Supply owner-host settings through
|
|
79
|
-
`bindHostSession({ scope, tasks: { wait: { kind: "automatic", agentBudgetMs: 5000 } },
|
|
80
|
-
authorizeLaunch, createRunner })`; `{ kind: "until-settled" }` disables timed yielding.
|
|
81
|
-
Per-call budgets override settings, including zero for immediate yield. These settings
|
|
82
|
-
apply to explicit foreground-first launch, live foregrounding and task-ID waits,
|
|
83
|
-
never to a default independent launch. Wide numeric budgets are not narrowed to u32.
|
|
84
|
-
Accepted `NaN` budgets (including configured `agentBudgetMs`) do not panic native
|
|
85
|
-
scheduling. The implementation leaves such observations pending until explicit yield,
|
|
86
|
-
settlement, observer disposal or owner closure: the elapsed comparison never reaches
|
|
87
|
-
`NaN`. It uses bounded sleep chunks without rewriting the caller's budget. This is
|
|
88
|
-
scheduling behavior, not a new finite-only input restriction or an RFC-mandated deadline;
|
|
89
|
-
other numeric budgets and per-call precedence are unchanged.
|
|
90
|
-
|
|
91
|
-
`await cancelTask(task, cause)` returns a Result containing a cancellation receipt
|
|
92
|
-
and preserves the first accepted cause. `closeTaskOwner` seals admission before
|
|
93
|
-
draining and succeeds only after independent cleanup acknowledgement. The trusted
|
|
94
|
-
runner supplies separate result and cleanup promises: confirmed reaping after
|
|
95
|
-
cancellation can close even if no result arrives. Natural cleanup-first delivery
|
|
96
|
-
waits for its outcome before acknowledging reaping. External native owner closure
|
|
97
|
-
also aborts resources attached to already-settled results without rewriting them.
|
|
98
|
-
Failed cleanup remains observable; absent acknowledgement can leave close pending.
|
|
99
|
-
User cancellation retains pending input attention until settlement or owner closure;
|
|
100
|
-
event-reduced and reattached snapshots report the same native facts. Runner result
|
|
101
|
-
rejections become failed `RunnerFailed` results; cleanup rejections become diagnostic
|
|
102
|
-
`CleanupFailed` resources, never successful reaping. Setup throws retain `SpawnFailed`
|
|
103
|
-
and unconfirmed cleanup. Strings and Error messages are preserved verbatim; other JS
|
|
104
|
-
values use safe string conversion, with `Unprintable JavaScript rejection` if conversion
|
|
105
|
-
throws. Cancelled cleanup still does not depend on the result promise settling.
|
|
106
|
-
This slice exercises fake runners, not force-stop or real-process cleanup guarantees.
|
|
21
|
+
## On this page and its reference
|
|
107
22
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
`startCommandTask(owner, intent, operation)` starts an owned Unix pipe/PTY or Windows pipe/ConPTY command.
|
|
111
|
-
The command intent keeps execution timeout separate from observation: `waitForTask`
|
|
112
|
-
defaults to 10000 ms for commands, and expiry returns a yielded observation without
|
|
113
|
-
terminating the process. On Unix, owner closure sends TERM, allows 250 ms grace, then KILL,
|
|
114
|
-
reaps the leader and confirms process-group exit and reader drain. A cleanup failure
|
|
115
|
-
retains diagnostics instead of claiming a closed owner. This is normal owner/host
|
|
116
|
-
shutdown cleanup, not a guarantee for forced host death or a blocked JavaScript loop.
|
|
117
|
-
|
|
118
|
-
Both native and facade `CommandIntent` accept optional `shell: { program, args }`:
|
|
119
|
-
the executable is launched directly with `command` appended as one final argv argument.
|
|
120
|
-
Omitting `shell` preserves the default native pipe shell. `inheritEnv` defaults to
|
|
121
|
-
`true`; `false` uses exactly the supplied environment rather than inheriting the host's.
|
|
122
|
-
Both fields participate in operation replay identity.
|
|
123
|
-
|
|
124
|
-
`taskStdin(task)` returns a non-serializable stdin capability. `writeTaskInput` takes
|
|
125
|
-
an operation ID and `{kind:"bytes", bytes:Uint8Array}` or `{kind:"eof"}`. Empty bytes
|
|
126
|
-
are a no-op. Input has 65536 byte credits, refuses excess input before admission,
|
|
127
|
-
and replays recorded receipts without resending bytes. Ambiguous partial delivery
|
|
128
|
-
returns `InputDeliveryUnknown`, including operation ID and known accepted-byte count.
|
|
129
|
-
|
|
130
|
-
`readTaskOutput(task, {start, maximumBytes})` returns owned byte chunks at decimal
|
|
131
|
-
offsets, requested bounds, omitted ranges and an optional next offset. Requests
|
|
132
|
-
are clamped to the 1 MiB live-preview bound before allocating or reading a page;
|
|
133
|
-
use `nextOffset` to continue. It does not sanitize or normalize bytes. Retention
|
|
134
|
-
uses a 1 MiB live head/tail, 8 MiB foreground spill threshold and 5 GiB disk cap.
|
|
135
|
-
Retained output is not conversation history. File-spool policy uses supervised
|
|
136
|
-
pipe drains, never inherited direct file writers. Stdout, stderr and descendants
|
|
137
|
-
share one serialized disk budget; crossing writes retain only the permitted prefix.
|
|
138
|
-
The file remains within the cap during foreground collection and termination.
|
|
139
|
-
After foreground collection yields, rejected overflow kills the group and settles
|
|
140
|
-
`OutputLimitExceeded` after confirmed cleanup. Spool setup failure refuses launch
|
|
141
|
-
with `SpawnFailed`. Drained pipe/PTY output instead keeps running with bounded
|
|
142
|
-
retained bytes and omissions.
|
|
143
|
-
Unix PTY resize uses the retained portable-pty master; Windows PTY uses ConPTY.
|
|
144
|
-
Windows pipe and ConPTY commands start suspended and enter a kill-on-close Job Object
|
|
145
|
-
before resume. Failed containment refuses execution, with no unsupervised spawn fallback.
|
|
146
|
-
Cleanup must be confirmed; failures retain diagnostic resources rather than reporting reaping.
|
|
147
|
-
Native Windows legacy WSL `bash.exe` stdin transport remains refused for owned launch:
|
|
148
|
-
Windows jobs cannot supervise the Linux guest process tree. Atomic running inside WSL
|
|
149
|
-
uses the normal POSIX/Bash path instead.
|
|
150
|
-
|
|
151
|
-
Bash tools and `createLocalBashOperations` accept a trusted `taskOwner` binding.
|
|
152
|
-
On Unix and native Windows, that binding obtains pipe/PTY processes through supervised admission,
|
|
153
|
-
preserving configured shell arguments, cwd, environment and existing authorization.
|
|
154
|
-
Foreground collection honors the owner's command wait configuration, including
|
|
155
|
-
`until-settled`; the automatic default is 10000 ms. A yielded process stays owned
|
|
156
|
-
and its retained output remains readable. Bash output inserts explicit
|
|
157
|
-
`[Output omitted: bytes start-end]` markers, with an exclusive end offset, between
|
|
158
|
-
retained chunks rather than silently joining gaps. Without that binding, existing
|
|
159
|
-
bash and native PTY execution are unchanged. No UI is added.
|
|
160
|
-
|
|
161
|
-
`watchOwnerTasks(owner, cursor?)` provides an opaque `lease`, snapshot,
|
|
162
|
-
decimal-string cursor and disposable `AsyncIterable<NativeEvent>`. Each iterator
|
|
163
|
-
observes one contiguous delivery epoch. On local backlog overflow or native journal
|
|
164
|
-
reset, the subscription updates its authoritative `snapshot` and `cursor`, discards
|
|
165
|
-
stale queued deltas, and completes the old iterator (`next()` returns `done:true`,
|
|
166
|
-
including an already-pending read). This also works when an oversized final settlement
|
|
167
|
-
leaves no retained event, without later activity or cleanup. No synthetic reset event
|
|
168
|
-
is inserted and the `NativeEvent` and subscription types are unchanged.
|
|
169
|
-
|
|
170
|
-
After any iterator completion, reconcile `subscription.snapshot` at
|
|
171
|
-
`subscription.cursor`. If the owner is still live and observation is still wanted,
|
|
172
|
-
obtain another iterator from the **same** `subscription.events`; the old iterator stays
|
|
173
|
-
done. Reset does not dispose the subscription or close the owner. Subsequent deltas
|
|
174
|
-
are authentic and ordered; ignore events at or below an already-applied snapshot
|
|
175
|
-
cursor. Explicit `dispose()` (idempotent) or breaking out of a live iterator ends
|
|
176
|
-
observation, not the owner. Owner closure also ends delivery. Track your own disposal
|
|
177
|
-
when deciding whether to resume. New subscriptions are refused once owner closing
|
|
178
|
-
begins; existing subscriptions continue through cleanup/closure.
|
|
179
|
-
Calling `dispose()` from `onReconcile` also stops the active drain from publishing
|
|
180
|
-
its retained events. Pending and newly created iterators finish without those events;
|
|
181
|
-
the reconciled snapshot remains available.
|
|
182
|
-
|
|
183
|
-
The optional `subscription.onReconcile` callback is a convenience, not required for
|
|
184
|
-
correctness; callback exceptions remain visible as `subscription.failure`. Raw strings
|
|
185
|
-
and Error messages are preserved; unprintable values (including hostile conversion or
|
|
186
|
-
revoked proxies) use `Unprintable JavaScript rejection`. Diagnostic conversion cannot
|
|
187
|
-
interrupt event delivery or rearming the fallback poll. Native callbacks are wake hints;
|
|
188
|
-
journal drains and reset snapshots are authoritative. Each live subscription has one
|
|
189
|
-
fallback poll, stopped on disposal or observed closure.
|
|
190
|
-
The native byte journal and facade delivery backlog are bounded. Each task separately
|
|
191
|
-
retains its most recent 256 accepted activity report IDs, SHA-256 payload hashes and
|
|
192
|
-
receipts (`TASK_REPORT_IDENTITY_WINDOW`). Within that window, identical payloads return
|
|
193
|
-
`duplicate` with the original cursor; conflicting payloads return `ReportConflict`.
|
|
194
|
-
Neither check emits events or refreshes retention order. An evicted ID is fresh: while
|
|
195
|
-
the task is live it is `accepted`, applies its activity again and gets a new cursor;
|
|
196
|
-
existing terminal and owner-close guards still apply. Terminal outcome reports and
|
|
197
|
-
their recorded receipts are retained separately for the task record's lifetime and
|
|
198
|
-
never evicted by activity churn. This bounds identity entry count, not caller ID length,
|
|
199
|
-
task count, terminal payloads or total task-history memory. S1 adds no persistence layer.
|
|
200
|
-
|
|
201
|
-
Activity IDs have no reserved spellings, including `runner-outcome`, empty strings
|
|
202
|
-
and isolated surrogates. The facade submits its own result through private trusted
|
|
203
|
-
runner support: the actor selects a free terminal identity and accepts the outcome
|
|
204
|
-
under the same lock. With at most 256 retained activity IDs, at most 257 distinct
|
|
205
|
-
candidates suffice; selection emits no events and retains no extra ID history.
|
|
206
|
-
Caller-supplied reports still use the unchanged `reportTaskOutcome` contract:
|
|
207
|
-
same-ID cross-kind reports conflict, and terminal replay retains its original receipt.
|
|
208
|
-
The internal support also reuses an accepted terminal identity, so a different result
|
|
209
|
-
cannot replace it; cancellation-first still rejects late natural outcomes. Normal,
|
|
210
|
-
rejected and setup-failure results all use this path without bypassing cleanup evidence.
|
|
211
|
-
|
|
212
|
-
Caller-provided strings retain their exact JavaScript UTF-16 code units, including
|
|
213
|
-
isolated surrogates, valid pairs and embedded NUL, across scopes, intent, operation/report
|
|
214
|
-
identity, activity, results and nested output/cleanup metadata. They remain ordinary
|
|
215
|
-
`string` fields, not encoded wrappers. Replacing a surrogate with U+FFFD is a changed
|
|
216
|
-
payload or identity, never an exact replay. Nonempty descriptions supply the title;
|
|
217
|
-
otherwise the first nonblank task line is copied without rewriting its code units,
|
|
218
|
-
falling back to the agent name. Absent optional fields, empty strings, known zero metrics
|
|
219
|
-
and ordered duplicate data remain distinct. The optional `elapsedMs`, `toolCount` and `tokenCount` metrics and
|
|
220
|
-
completed/failed `exitCode` preserve JavaScript numbers without narrowing or normalization,
|
|
221
|
-
including fractional and extreme values. Within the retained activity window (and for
|
|
222
|
-
terminal reports throughout the task record's lifetime), exact replay distinguishes
|
|
223
|
-
omission, zero and negative zero; repeated NaN and infinite values acknowledge once.
|
|
224
|
-
Changed numeric payloads return `ReportConflict` without earning another event. `OutputRef` is
|
|
225
|
-
metadata, not proof of retained bytes: output
|
|
226
|
-
storage, `readTaskOutput`, command input, persistence, completion delivery and
|
|
227
|
-
real agent/Intercom integration belong to later slices. The credential-free
|
|
228
|
-
repository fixture `test/fixtures/task-s1-demo.ts` exercises this real facade and
|
|
229
|
-
native actor with one fake runner.
|
|
23
|
+
This page covers the SDK quick start, its core concepts, and one complete example. Options, resource loaders, return types, run modes, and exports live in the [SDK API reference](/sdk/reference).
|
|
230
24
|
|
|
231
|
-
|
|
25
|
+
For a custom host that runs background work, see [Owner-bound task supervisor](/sdk/reference#owner-bound-task-supervisor-s1), [Supervised command SDK](/sdk/reference#supervised-command-sdk), and [Task transcript references](/sdk/reference#task-transcript-references).
|
|
232
26
|
|
|
233
|
-
|
|
234
|
-
child session history. `readTaskTranscript(task, cursor?)` in `core/tasks/transcript.ts`
|
|
235
|
-
reads that binding through the task capability. It returns message and content-block
|
|
236
|
-
references, not copied text: `id`, `kind`, `source`, and `toolCallId` when applicable.
|
|
237
|
-
Kinds are `prompt`, `assistant`, `tool-call`, `tool-result`, and `response`.
|
|
238
|
-
Thinking blocks and non-conversation entries are excluded. Repeated source IDs are
|
|
239
|
-
deduplicated; repeated messages with different IDs remain distinct.
|
|
240
|
-
|
|
241
|
-
The first page contains up to 100 recent references in source order. Pass the opaque
|
|
242
|
-
`nextCursor` to read earlier references; `omittedEarlier` identifies remaining older
|
|
243
|
-
content. Cursors belong to one task and bound session. An unknown task returns
|
|
244
|
-
`UnknownTask`, a cursor from another task/session returns `ScopeMismatch`, and an
|
|
245
|
-
unbound or empty history returns `TranscriptUnavailable` with `Transcript unavailable`.
|
|
246
|
-
This adapter does not launch work or reconstruct live capabilities from history.
|
|
247
|
-
Production subagent runners bind their child history, and main and attached workflow
|
|
248
|
-
chat hosts mount the shared inspector. Command detail reads are scoped to the current
|
|
249
|
-
selection and view lifetime: late results and errors cannot overwrite another view.
|
|
27
|
+
Not sure the SDK is the right integration mode? Compare it with RPC and JSON mode on [Programmatic use](/programmatic).
|
|
250
28
|
|
|
251
29
|
## Quick Start
|
|
252
30
|
|
|
@@ -281,7 +59,7 @@ const { session } = await createAgentSession({
|
|
|
281
59
|
});
|
|
282
60
|
```
|
|
283
61
|
|
|
284
|
-
`ModelRuntime.create()` accepts custom `authPath`, `modelsPath`, credential storage, and runtime auth overrides, plus the model-catalog options `allowModelNetwork`, `modelRefreshTimeoutMs`, `modelsStorePath`, and `modelsStore` (see [Model catalog persistence and refresh](#model-catalog-persistence-and-refresh)). `ModelRegistry` and `AuthStorage` remain available as Atomic's synchronous compatibility facades. Use `readStoredCredential(provider, authPath?)` for a lightweight read of one stored provider credential.
|
|
62
|
+
`ModelRuntime.create()` accepts custom `authPath`, `modelsPath`, credential storage, and runtime auth overrides, plus the model-catalog options `allowModelNetwork`, `modelRefreshTimeoutMs`, `modelsStorePath`, and `modelsStore` (see [Model catalog persistence and refresh](/sdk/reference#model-catalog-persistence-and-refresh)). `ModelRegistry` and `AuthStorage` remain available as Atomic's synchronous compatibility facades. Use `readStoredCredential(provider, authPath?)` for a lightweight read of one stored provider credential.
|
|
285
63
|
|
|
286
64
|
Extensions supplied directly to SDK sessions can use the exported `InlineExtension` type. Extension APIs and event types include native `registerProvider(Provider)`, `registerEntryRenderer`, `entry_appended`, `before_provider_headers`, and `agent_settled`.
|
|
287
65
|
|
|
@@ -317,6 +95,14 @@ The SDK is included in the main package. No separate SDK package is needed.
|
|
|
317
95
|
|
|
318
96
|
`@bastani/atomic/client` re-exports `@earendil-works/pi-client`. Pi 0.85 replaced the experimental `RemoteSession` lease API with its service-addressed Chord client; use the upstream client and agent service APIs for remote sessions.
|
|
319
97
|
|
|
98
|
+
## Experimental remote sessions
|
|
99
|
+
|
|
100
|
+
Use [Pi client](#pi-client) for the current remote-session API.
|
|
101
|
+
|
|
102
|
+
## Experimental Harness factory
|
|
103
|
+
|
|
104
|
+
For the current supported integration, start with [createAgentSession()](#createagentsession) and the [SDK API reference](/sdk/reference).
|
|
105
|
+
|
|
320
106
|
## Core Concepts
|
|
321
107
|
|
|
322
108
|
### createAgentSession()
|
|
@@ -493,7 +279,7 @@ await session.prompt("What files are here?");
|
|
|
493
279
|
|
|
494
280
|
// With images
|
|
495
281
|
await session.prompt("What's in this image?", {
|
|
496
|
-
images: [{ type: "image",
|
|
282
|
+
images: [{ type: "image", data: "...", mimeType: "image/png" }]
|
|
497
283
|
});
|
|
498
284
|
|
|
499
285
|
// During streaming: must specify how to queue the message
|
|
@@ -630,677 +416,87 @@ streamed, if any.
|
|
|
630
416
|
|
|
631
417
|
## Options Reference
|
|
632
418
|
|
|
633
|
-
|
|
419
|
+
Moved to [SDK API reference](/sdk/reference#options-reference).
|
|
634
420
|
|
|
635
|
-
|
|
636
|
-
const { session } = await createAgentSession({
|
|
637
|
-
// Working directory for DefaultResourceLoader discovery
|
|
638
|
-
cwd: process.cwd(), // default
|
|
639
|
-
|
|
640
|
-
// Global config directory
|
|
641
|
-
agentDir: "~/.atomic/agent", // default (expands ~)
|
|
642
|
-
});
|
|
643
|
-
```
|
|
421
|
+
### Directories
|
|
644
422
|
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
`cwd` is used by `DefaultResourceLoader` for:
|
|
648
|
-
- Project extensions (`.atomic/extensions/`, then legacy `.pi/extensions/`)
|
|
649
|
-
- Project skills:
|
|
650
|
-
- `.atomic/skills/`, then legacy `.pi/skills/`
|
|
651
|
-
- `.agents/skills/` in `cwd` and ancestor directories (up to git repo root, or filesystem root when not in a repo)
|
|
652
|
-
- Project prompts (`.atomic/prompts/`, then legacy `.pi/prompts/`)
|
|
653
|
-
- Context files (`AGENTS.override.md`, `AGENTS.md`, or `CLAUDE.md` walking up from cwd)
|
|
654
|
-
- Session directory naming
|
|
655
|
-
|
|
656
|
-
`agentDir` is used by `DefaultResourceLoader` for:
|
|
657
|
-
- Global extensions (`extensions/`)
|
|
658
|
-
- Global skills:
|
|
659
|
-
- `skills/` under `agentDir` (for example `~/.atomic/agent/skills/`; legacy `~/.pi/agent/skills/` is also considered by default)
|
|
660
|
-
- `~/.agents/skills/`
|
|
661
|
-
- Global prompts (`prompts/`)
|
|
662
|
-
- Global context files (`AGENTS.override.md`, `AGENTS.md`, or `CLAUDE.md` under `agentDir`)
|
|
663
|
-
- Settings (`settings.json`)
|
|
664
|
-
- Custom models (`models.json`)
|
|
665
|
-
- Credentials (`auth.json`)
|
|
666
|
-
- Sessions (`sessions/`)
|
|
667
|
-
|
|
668
|
-
When you pass a custom `ResourceLoader`, `cwd` and `agentDir` no longer control resource discovery. They still influence session naming and tool path resolution.
|
|
423
|
+
Moved to [SDK API reference](/sdk/reference#directories).
|
|
669
424
|
|
|
670
425
|
### Model
|
|
671
426
|
|
|
672
|
-
|
|
673
|
-
import { getModel } from "@bastani/pi-ai/compat";
|
|
674
|
-
import { ModelRuntime } from "@bastani/atomic";
|
|
675
|
-
|
|
676
|
-
const modelRuntime = await ModelRuntime.create();
|
|
677
|
-
|
|
678
|
-
// Find specific built-in model (doesn't check if credentials exist)
|
|
679
|
-
const opus = getModel("anthropic", "claude-opus-4-5");
|
|
680
|
-
if (!opus) throw new Error("Model not found");
|
|
681
|
-
|
|
682
|
-
// Find any model by provider/id, including custom models from models.json
|
|
683
|
-
const customModel = modelRuntime.getModel("my-provider", "my-model");
|
|
684
|
-
|
|
685
|
-
// Get only models whose providers have configured authentication
|
|
686
|
-
const available = await modelRuntime.getAvailable();
|
|
687
|
-
|
|
688
|
-
const { session } = await createAgentSession({
|
|
689
|
-
model: opus,
|
|
690
|
-
thinkingLevel: "medium", // off, minimal, low, medium, high, xhigh, max (when supported by the model)
|
|
691
|
-
|
|
692
|
-
// Models for cycling (CTRL+P in interactive mode)
|
|
693
|
-
scopedModels: [
|
|
694
|
-
{ model: opus, thinkingLevel: "high" },
|
|
695
|
-
{ model: haiku, thinkingLevel: "off" },
|
|
696
|
-
],
|
|
697
|
-
|
|
698
|
-
modelRuntime,
|
|
699
|
-
});
|
|
700
|
-
```
|
|
701
|
-
|
|
702
|
-
`ModelRegistry` keeps synchronous reads for extension compatibility, while catalog refresh is asynchronous. Extensions should await `modelRegistry.refresh()` before synchronous `getAll()`, `find()`, or `getAvailable()` reads when a provider may update its catalog. New SDK integrations use `ModelRuntime`; `await modelRuntime.refresh()` reports `aborted` and per-provider `errors`, and failed providers retain their last-known models.
|
|
703
|
-
|
|
704
|
-
If no model is provided:
|
|
705
|
-
1. Tries to restore from session (if continuing)
|
|
706
|
-
2. Uses default from settings
|
|
707
|
-
3. Falls back to first available model
|
|
708
|
-
|
|
709
|
-
> See [examples/sdk/02-custom-model.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/sdk/02-custom-model.ts)
|
|
427
|
+
Moved to [SDK API reference](/sdk/reference#model).
|
|
710
428
|
|
|
711
429
|
#### Model catalog persistence and refresh
|
|
712
430
|
|
|
713
|
-
|
|
714
|
-
pi.dev unless you opt in. `allowModelNetwork` (default `false`) enables a create-time network
|
|
715
|
-
refresh, and `modelRefreshTimeoutMs` (default `15_000`) bounds how long that refresh may run
|
|
716
|
-
before it is aborted. Pass `refreshOnCreate: false` to skip the initial catalog and
|
|
717
|
-
availability refresh entirely; built-in models remain available.
|
|
718
|
-
|
|
719
|
-
```typescript
|
|
720
|
-
const refreshedRuntime = await ModelRuntime.create({
|
|
721
|
-
allowModelNetwork: true,
|
|
722
|
-
modelRefreshTimeoutMs: 15_000,
|
|
723
|
-
});
|
|
724
|
-
```
|
|
725
|
-
|
|
726
|
-
Remote catalogs are persisted locally so later runtimes can restore them without a network
|
|
727
|
-
request. The default file is `models-store.json` next to `models.json` — with the default
|
|
728
|
-
`modelsPath` that is `~/.atomic/agent/models-store.json`. Set `modelsStorePath` to choose
|
|
729
|
-
another location, or inject `modelsStore` to control persistence entirely; a runtime created
|
|
730
|
-
with `modelsPath: null` keeps its store in memory. Network refreshes are throttled to once
|
|
731
|
-
per provider every four hours unless forced. To force an immediate refresh, call
|
|
732
|
-
`await modelRuntime.refresh({ allowNetwork: true, force: true, signal })`. Setting
|
|
733
|
-
`ATOMIC_OFFLINE` (legacy alias `PI_OFFLINE`) disables model network access, and a
|
|
734
|
-
`refresh()` call that omits `allowNetwork` follows that same runtime network policy.
|
|
431
|
+
Moved to [SDK API reference](/sdk/reference#model-catalog-persistence-and-refresh).
|
|
735
432
|
|
|
736
433
|
### API Keys and OAuth
|
|
737
434
|
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
Credential resolution combines runtime API-key overrides, stored `auth.json` credentials, environment variables, and the active `models.json` provider configuration. OAuth acquisition is provider-owned and runs through `ModelRuntime.login()`.
|
|
741
|
-
|
|
742
|
-
```typescript
|
|
743
|
-
import { AuthStorage, ModelRuntime } from "@bastani/atomic";
|
|
744
|
-
|
|
745
|
-
const authStorage = AuthStorage.create();
|
|
746
|
-
const modelRuntime = await ModelRuntime.create({ credentials: authStorage });
|
|
747
|
-
|
|
748
|
-
const { session } = await createAgentSession({
|
|
749
|
-
sessionManager: SessionManager.inMemory(),
|
|
750
|
-
modelRuntime,
|
|
751
|
-
});
|
|
752
|
-
|
|
753
|
-
// Runtime API key override (not persisted to disk). Setting the key updates
|
|
754
|
-
// auth state; refresh the provider explicitly when its catalog must be current.
|
|
755
|
-
const providerId = "anthropic";
|
|
756
|
-
const authController = new AbortController();
|
|
757
|
-
await modelRuntime.setRuntimeApiKey(providerId, "sk-my-temp-key", { signal: authController.signal });
|
|
758
|
-
await modelRuntime.refresh({ providers: [providerId], signal: authController.signal });
|
|
759
|
-
|
|
760
|
-
// Custom credential and model configuration locations
|
|
761
|
-
const customRuntime = await ModelRuntime.create({
|
|
762
|
-
authPath: "/my/app/auth.json",
|
|
763
|
-
modelsPath: "/my/app/models.json",
|
|
764
|
-
});
|
|
765
|
-
|
|
766
|
-
const customSession = await createAgentSession({
|
|
767
|
-
sessionManager: SessionManager.inMemory(),
|
|
768
|
-
modelRuntime: customRuntime,
|
|
769
|
-
});
|
|
770
|
-
|
|
771
|
-
// Disable models.json while retaining built-in providers
|
|
772
|
-
const builtinsOnly = await ModelRuntime.create({ modelsPath: null });
|
|
773
|
-
```
|
|
774
|
-
|
|
775
|
-
> See the complete [`ModelRuntime` credential and model configuration example](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/sdk/09-api-keys-and-oauth.ts).
|
|
435
|
+
Moved to [SDK API reference](/sdk/reference#api-keys-and-oauth).
|
|
776
436
|
|
|
777
437
|
### System Prompt
|
|
778
438
|
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
```typescript
|
|
782
|
-
import { createAgentSession, DefaultResourceLoader } from "@bastani/atomic";
|
|
783
|
-
|
|
784
|
-
const loader = new DefaultResourceLoader({
|
|
785
|
-
systemPromptOverride: () => "You are a helpful assistant.",
|
|
786
|
-
});
|
|
787
|
-
await loader.reload();
|
|
788
|
-
|
|
789
|
-
const { session } = await createAgentSession({ resourceLoader: loader });
|
|
790
|
-
```
|
|
791
|
-
|
|
792
|
-
> See [examples/sdk/03-custom-prompt.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/sdk/03-custom-prompt.ts)
|
|
439
|
+
Moved to [SDK API reference](/sdk/reference#system-prompt).
|
|
793
440
|
|
|
794
441
|
### Tools
|
|
795
442
|
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
- Built-in tool names enabled by default: `read`, `bash`, `kill`, `edit`, `write`, `find`, `search`, `ask_user_question`, `todo`
|
|
799
|
-
- `find` discovers filesystem paths by glob; `search` searches file contents with regex patterns across files, directories, globs, and internal URLs.
|
|
800
|
-
- `tools` is an allowlist: when provided, only the listed built-in, extension, and custom tool names are exposed, plus mandatory ordinary `intercom`.
|
|
801
|
-
- `excludedTools` is a blocklist: matching built-in, extension, and custom tool names are omitted from the final registry and active tool set, except mandatory ordinary `intercom`. If both are provided, `tools` is applied first and `excludedTools` subtracts from it.
|
|
802
|
-
- `noTools: "all"` disables every tool except mandatory ordinary `intercom`
|
|
803
|
-
- `noTools: "builtin"` disables default built-ins while keeping extension and custom tools enabled, except names listed in `excludedTools`
|
|
804
|
-
|
|
805
|
-
```typescript
|
|
806
|
-
import { createAgentSession } from "@bastani/atomic";
|
|
807
|
-
|
|
808
|
-
// Read-only mode. `tools` selects optional tools; ordinary Intercom remains active.
|
|
809
|
-
const { session } = await createAgentSession({
|
|
810
|
-
tools: ["read", "search", "find", "ls"],
|
|
811
|
-
});
|
|
812
|
-
|
|
813
|
-
// Pick specific optional tools. Ordinary Intercom remains active even when omitted.
|
|
814
|
-
const { session } = await createAgentSession({
|
|
815
|
-
tools: ["read", "bash", "search"],
|
|
816
|
-
});
|
|
817
|
-
|
|
818
|
-
// Keep defaults but remove HITL prompts
|
|
819
|
-
const { session } = await createAgentSession({
|
|
820
|
-
excludedTools: ["ask_user_question"],
|
|
821
|
-
});
|
|
822
|
-
|
|
823
|
-
// Allowlist first, then subtract exclusions
|
|
824
|
-
const { session } = await createAgentSession({
|
|
825
|
-
tools: ["read", "bash", "ask_user_question"],
|
|
826
|
-
excludedTools: ["ask_user_question"], // optional tools: read, bash; ordinary Intercom remains active
|
|
827
|
-
});
|
|
828
|
-
```
|
|
443
|
+
Moved to [SDK API reference](/sdk/reference#tools).
|
|
829
444
|
|
|
830
445
|
#### Bash tool behavior
|
|
831
446
|
|
|
832
|
-
|
|
833
|
-
|
|
447
|
+
Moved to [SDK API reference](/sdk/reference#bash-tool-behavior).
|
|
834
448
|
|
|
835
449
|
#### Waiting for existing shell tasks
|
|
836
450
|
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
`budgetMs` is optional, finite, and non-negative. Omission uses the owner's command wait policy and zero polls. Results keep the `WaitOutcome` in `details.observation`, available exit information in `details.exitCode`, and retained output in text content. Failure and cancellation metadata remain in the settled observation. Yielded waits advance through bounded retained-output pages for the same owned task, even when the tool is recreated. Partial UTF-8 characters continue on the next page. Settled waits return all retained output again, subject to labelled gaps and truncation. Aborting the call releases only its observation. A binding from `AgentTaskHost.ownerBinding` also releases waits for incoming owner messages.
|
|
840
|
-
|
|
841
|
-
Do not mix wait arguments with launch fields. Unknown or foreign IDs and unbound waits are rejected before execution hooks. Custom `operations.exec` does not provide existing-task ownership. See [Background tasks](/background-tasks) for examples and lifetime rules.
|
|
451
|
+
Moved to [SDK API reference](/sdk/reference#waiting-for-existing-shell-tasks).
|
|
842
452
|
|
|
843
453
|
#### PowerShell tool behavior
|
|
844
454
|
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
PowerShell tools and local operations accept a trusted `taskOwner` binding and the same
|
|
848
|
-
`wait` observation policy as bash. Owned native Windows execution automatically yields
|
|
849
|
-
after the owner's command budget (normally 10000 ms); explicit per-call budgets override it,
|
|
850
|
-
and execution timeout remains separate. Commands use encoded PowerShell transport internally,
|
|
851
|
-
while task descriptions retain the original command text. Without a supported owner,
|
|
852
|
-
explicit background requests are refused and foreground execution waits for completion.
|
|
853
|
-
|
|
854
|
-
```typescript
|
|
855
|
-
import { createPowerShellTool } from "@bastani/atomic";
|
|
856
|
-
|
|
857
|
-
const powershell = createPowerShellTool("C:\\path\\to\\project");
|
|
858
|
-
```
|
|
455
|
+
Moved to [SDK API reference](/sdk/reference#powershell-tool-behavior).
|
|
859
456
|
|
|
860
457
|
#### Tools with Custom cwd
|
|
861
458
|
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
```typescript
|
|
865
|
-
import { createAgentSession, SessionManager } from "@bastani/atomic";
|
|
866
|
-
|
|
867
|
-
const cwd = "/path/to/project";
|
|
868
|
-
|
|
869
|
-
// Use default tools for custom cwd
|
|
870
|
-
const { session } = await createAgentSession({
|
|
871
|
-
cwd,
|
|
872
|
-
sessionManager: SessionManager.inMemory(cwd),
|
|
873
|
-
});
|
|
874
|
-
|
|
875
|
-
// Or pick specific tools for custom cwd
|
|
876
|
-
const { session } = await createAgentSession({
|
|
877
|
-
cwd,
|
|
878
|
-
tools: ["read", "bash", "search"],
|
|
879
|
-
sessionManager: SessionManager.inMemory(cwd),
|
|
880
|
-
});
|
|
881
|
-
```
|
|
882
|
-
|
|
883
|
-
> See [examples/sdk/05-tools.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/sdk/05-tools.ts)
|
|
459
|
+
Moved to [SDK API reference](/sdk/reference#tools-with-custom-cwd).
|
|
884
460
|
|
|
885
461
|
### Custom Tools
|
|
886
462
|
|
|
887
|
-
|
|
888
|
-
import { Type } from "typebox";
|
|
889
|
-
import { createAgentSession, defineTool } from "@bastani/atomic";
|
|
890
|
-
|
|
891
|
-
// Inline custom tool
|
|
892
|
-
const myTool = defineTool({
|
|
893
|
-
name: "my_tool",
|
|
894
|
-
label: "My Tool",
|
|
895
|
-
description: "Does something useful",
|
|
896
|
-
parameters: Type.Object({
|
|
897
|
-
input: Type.String({ description: "Input value" }),
|
|
898
|
-
}),
|
|
899
|
-
execute: async (_toolCallId, params) => ({
|
|
900
|
-
content: [{ type: "text", text: `Result: ${params.input}` }],
|
|
901
|
-
details: {},
|
|
902
|
-
}),
|
|
903
|
-
});
|
|
904
|
-
|
|
905
|
-
// Pass custom tools directly
|
|
906
|
-
const { session } = await createAgentSession({
|
|
907
|
-
customTools: [myTool],
|
|
908
|
-
});
|
|
909
|
-
```
|
|
910
|
-
|
|
911
|
-
Use `defineTool()` for standalone definitions and arrays like `customTools: [myTool]`. Inline `pi.registerTool({ ... })` already infers parameter types correctly.
|
|
912
|
-
|
|
913
|
-
Custom tools passed via `customTools` are combined with extension-registered tools. Extensions loaded by the ResourceLoader can also register tools via `pi.registerTool()`.
|
|
914
|
-
|
|
915
|
-
If you pass `tools`, include each custom or extension tool name you want enabled, for example `tools: ["read", "bash", "my_tool"]`. Use `excludedTools` to remove a custom or extension tool by name from the final exposed set.
|
|
916
|
-
|
|
917
|
-
`ToolDefinition.constrainedSampling` is part of the public SDK and survives `defineTool()`, `customTools`, tool wrappers, session/staged inspection, and isolated execution. Use `{ type: "json_schema", strict: "prefer" | "require" }`, `{ type: "grammar", variants: { openai_lark?: string, openai_regex?: string } }`, or `false`. `prefer` can fall back; `require` fails when the active model cannot enforce strict JSON Schema. Grammar constraints require one required string parameter and capable model metadata. Public inspection preserves optional-property identity exactly: an omitted key stays absent, an explicitly present `undefined` stays present, and `false` or a config object remains unchanged. The exported `ConstrainedSamplingConfig` type and [extension reference](/extensions#constrained-sampling) define the exact shape. Typed RPC clients receive the four model capability flags through optional `ModelInfo.compat`; see [RPC](/rpc#get_available_models).
|
|
918
|
-
|
|
919
|
-
Factory-created `createBashTool()` instances receive the same execution-time `ATOMIC_SESSION_*`/`PI_SESSION_*` model and session snapshot as the built-in bash tool. Set `exposeSessionEnvironment: false` only when the subprocess must not receive it. `MessageRenderOptions.outputPad` is likewise passed to normal and isolated custom message renderers.
|
|
920
|
-
|
|
921
|
-
Normal sessions also expose `kill({ id: taskId })` for their owned bash and PowerShell background tasks. Include `kill` when using a `tools` allowlist if the agent should be able to stop those tasks. The exported `createKillTool` and `createKillToolDefinition` factories accept `KillToolOptions.taskOwner`, a trusted execution-time callback returning the same owner binding used by shell launch. Without a binding they reject execution. The result details preserve the supervisor's `CancelReceipt`, including its decision, execution outcome, and cleanup state. See [Background tasks](/background-tasks#stop-a-shell-task-from-a-tool-call).
|
|
463
|
+
Moved to [SDK API reference](/sdk/reference#custom-tools).
|
|
922
464
|
|
|
923
465
|
#### Structured output final results
|
|
924
466
|
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
```typescript
|
|
928
|
-
import { Type, type Static } from "typebox";
|
|
929
|
-
import {
|
|
930
|
-
createAgentSession,
|
|
931
|
-
createStructuredOutputTool,
|
|
932
|
-
type StructuredOutputCapture,
|
|
933
|
-
} from "@bastani/atomic";
|
|
934
|
-
|
|
935
|
-
const DecisionSchema = Type.Object({
|
|
936
|
-
approved: Type.Boolean(),
|
|
937
|
-
findings: Type.Array(Type.String()),
|
|
938
|
-
}, { additionalProperties: false });
|
|
939
|
-
|
|
940
|
-
type Decision = Static<typeof DecisionSchema>;
|
|
941
|
-
const capture: StructuredOutputCapture<Decision> = {
|
|
942
|
-
called: false,
|
|
943
|
-
value: undefined,
|
|
944
|
-
};
|
|
945
|
-
|
|
946
|
-
const structuredOutput = createStructuredOutputTool({
|
|
947
|
-
schema: DecisionSchema,
|
|
948
|
-
capture,
|
|
949
|
-
});
|
|
950
|
-
|
|
951
|
-
const { session } = await createAgentSession({
|
|
952
|
-
customTools: [structuredOutput],
|
|
953
|
-
});
|
|
954
|
-
```
|
|
955
|
-
|
|
956
|
-
The tool parameters are exactly the supplied schema: with `DecisionSchema`, the model calls `structured_output({ approved, findings })`. Array and primitive schemas are also accepted by the factory when the target provider/tool runtime supports them; the captured value is whatever JSON value matches the schema. A successful call stores the params in `capture.value`, returns them as pretty-printed JSON tool-result text for text print mode, keeps the flat value in tool `details`, writes the same JSON to the configured `output.outputPath` when an `output` file sink is configured, and sets `terminate: true` so there is no extra follow-up assistant turn. Atomic relies on the tool schema instead of extra structured-output parsing or sidecar validation. Structured-output tool definitions opt out of oversized-result persistence.
|
|
957
|
-
|
|
958
|
-
Custom tool names are supported, and the prompt metadata follows the configured name. If you use a custom name such as `final_decision`, include that name in any explicit `tools` allowlist. If the standard `structured_output` name is required, register the factory with its default name:
|
|
959
|
-
|
|
960
|
-
```typescript
|
|
961
|
-
const finalDecision = createStructuredOutputTool({
|
|
962
|
-
name: "final_decision",
|
|
963
|
-
schema: DecisionSchema,
|
|
964
|
-
capture,
|
|
965
|
-
});
|
|
966
|
-
// The model is prompted to call final_decision exactly once, not structured_output.
|
|
967
|
-
|
|
968
|
-
await createAgentSession({
|
|
969
|
-
customTools: [finalDecision],
|
|
970
|
-
tools: ["final_decision"], // only this tool is enabled
|
|
971
|
-
});
|
|
972
|
-
|
|
973
|
-
await createAgentSession({
|
|
974
|
-
customTools: [createStructuredOutputTool({ schema: DecisionSchema, capture })],
|
|
975
|
-
// Registers the standard structured_output tool for this session only.
|
|
976
|
-
});
|
|
977
|
-
```
|
|
978
|
-
|
|
979
|
-
> See [examples/sdk/05-tools.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/sdk/05-tools.ts)
|
|
467
|
+
Moved to [SDK API reference](/sdk/reference#structured-output-final-results).
|
|
980
468
|
|
|
981
469
|
### Extensions
|
|
982
470
|
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
```typescript
|
|
986
|
-
import { createAgentSession, DefaultResourceLoader } from "@bastani/atomic";
|
|
987
|
-
|
|
988
|
-
const loader = new DefaultResourceLoader({
|
|
989
|
-
additionalExtensionPaths: ["/path/to/my-extension.ts"],
|
|
990
|
-
extensionFactories: [
|
|
991
|
-
(pi) => {
|
|
992
|
-
pi.on("agent_start", () => {
|
|
993
|
-
console.log("[Inline Extension] Agent starting");
|
|
994
|
-
});
|
|
995
|
-
},
|
|
996
|
-
],
|
|
997
|
-
});
|
|
998
|
-
await loader.reload();
|
|
999
|
-
|
|
1000
|
-
const { session } = await createAgentSession({ resourceLoader: loader });
|
|
1001
|
-
```
|
|
1002
|
-
|
|
1003
|
-
`createAgentSession()` preserves resources from a supplied loader but restores Atomic's mandatory bundled Intercom extension after loader overrides, deferred reloads, and same-name extension or `customTools` collisions. The supplied loader still controls every optional extension.
|
|
1004
|
-
|
|
1005
|
-
Strict reloads (`failOnExtensionErrors: true`) require the loader's transactional `prepareReload()` support so a failed candidate cannot mutate live state before validation. `DefaultResourceLoader` provides that support. Custom loaders without it remain compatible with ordinary reloads, but strict reload fails before calling their mutating `reload()` method.
|
|
1006
|
-
|
|
1007
|
-
Extensions can register tools, subscribe to events, add commands, and more. See [Extensions](/extensions) for the full API.
|
|
1008
|
-
|
|
1009
|
-
**Event Bus:** Extensions can communicate via `pi.events`. Pass a shared `eventBus` to `DefaultResourceLoader` if you need to emit or listen from outside:
|
|
1010
|
-
|
|
1011
|
-
```typescript
|
|
1012
|
-
import { createEventBus, DefaultResourceLoader } from "@bastani/atomic";
|
|
1013
|
-
|
|
1014
|
-
const eventBus = createEventBus();
|
|
1015
|
-
const loader = new DefaultResourceLoader({
|
|
1016
|
-
eventBus,
|
|
1017
|
-
});
|
|
1018
|
-
await loader.reload();
|
|
1019
|
-
|
|
1020
|
-
eventBus.on("my-extension:status", (data) => console.log(data));
|
|
1021
|
-
```
|
|
1022
|
-
|
|
1023
|
-
> See [examples/sdk/06-extensions.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/sdk/06-extensions.ts) and [Extensions](/extensions)
|
|
471
|
+
Moved to [SDK API reference](/sdk/reference#extensions).
|
|
1024
472
|
|
|
1025
473
|
### Skills
|
|
1026
474
|
|
|
1027
|
-
|
|
1028
|
-
import {
|
|
1029
|
-
createAgentSession,
|
|
1030
|
-
DefaultResourceLoader,
|
|
1031
|
-
type Skill,
|
|
1032
|
-
} from "@bastani/atomic";
|
|
1033
|
-
|
|
1034
|
-
const customSkill: Skill = {
|
|
1035
|
-
name: "my-skill",
|
|
1036
|
-
description: "Custom instructions",
|
|
1037
|
-
filePath: "/path/to/SKILL.md",
|
|
1038
|
-
baseDir: "/path/to",
|
|
1039
|
-
source: "custom",
|
|
1040
|
-
};
|
|
1041
|
-
|
|
1042
|
-
const loader = new DefaultResourceLoader({
|
|
1043
|
-
skillsOverride: (current) => ({
|
|
1044
|
-
skills: [...current.skills, customSkill],
|
|
1045
|
-
diagnostics: current.diagnostics,
|
|
1046
|
-
}),
|
|
1047
|
-
});
|
|
1048
|
-
await loader.reload();
|
|
1049
|
-
|
|
1050
|
-
const { session } = await createAgentSession({ resourceLoader: loader });
|
|
1051
|
-
```
|
|
1052
|
-
|
|
1053
|
-
> See [examples/sdk/04-skills.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/sdk/04-skills.ts)
|
|
475
|
+
Moved to [SDK API reference](/sdk/reference#skills).
|
|
1054
476
|
|
|
1055
477
|
### Context Files
|
|
1056
478
|
|
|
1057
|
-
|
|
1058
|
-
import { createAgentSession, DefaultResourceLoader } from "@bastani/atomic";
|
|
1059
|
-
|
|
1060
|
-
const loader = new DefaultResourceLoader({
|
|
1061
|
-
agentsFilesOverride: (current) => ({
|
|
1062
|
-
agentsFiles: [
|
|
1063
|
-
...current.agentsFiles,
|
|
1064
|
-
{ path: "/virtual/AGENTS.md", content: "# Guidelines\n\n- Be concise" },
|
|
1065
|
-
],
|
|
1066
|
-
}),
|
|
1067
|
-
});
|
|
1068
|
-
await loader.reload();
|
|
1069
|
-
|
|
1070
|
-
const { session } = await createAgentSession({ resourceLoader: loader });
|
|
1071
|
-
```
|
|
1072
|
-
|
|
1073
|
-
> See [examples/sdk/07-context-files.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/sdk/07-context-files.ts)
|
|
479
|
+
Moved to [SDK API reference](/sdk/reference#context-files).
|
|
1074
480
|
|
|
1075
481
|
### Slash Commands
|
|
1076
482
|
|
|
1077
|
-
|
|
1078
|
-
import {
|
|
1079
|
-
createAgentSession,
|
|
1080
|
-
DefaultResourceLoader,
|
|
1081
|
-
type PromptTemplate,
|
|
1082
|
-
} from "@bastani/atomic";
|
|
1083
|
-
|
|
1084
|
-
const customCommand: PromptTemplate = {
|
|
1085
|
-
name: "deploy",
|
|
1086
|
-
description: "Deploy the application",
|
|
1087
|
-
source: "(custom)",
|
|
1088
|
-
content: "# Deploy\n\n1. Build\n2. Test\n3. Deploy",
|
|
1089
|
-
};
|
|
1090
|
-
|
|
1091
|
-
const loader = new DefaultResourceLoader({
|
|
1092
|
-
promptsOverride: (current) => ({
|
|
1093
|
-
prompts: [...current.prompts, customCommand],
|
|
1094
|
-
diagnostics: current.diagnostics,
|
|
1095
|
-
}),
|
|
1096
|
-
});
|
|
1097
|
-
await loader.reload();
|
|
1098
|
-
|
|
1099
|
-
const { session } = await createAgentSession({ resourceLoader: loader });
|
|
1100
|
-
```
|
|
1101
|
-
|
|
1102
|
-
> See [examples/sdk/08-prompt-templates.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/sdk/08-prompt-templates.ts)
|
|
483
|
+
Moved to [SDK API reference](/sdk/reference#slash-commands).
|
|
1103
484
|
|
|
1104
485
|
### Session Management
|
|
1105
486
|
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
```typescript
|
|
1109
|
-
import {
|
|
1110
|
-
type CreateAgentSessionRuntimeFactory,
|
|
1111
|
-
createAgentSession,
|
|
1112
|
-
createAgentSessionFromServices,
|
|
1113
|
-
createAgentSessionRuntime,
|
|
1114
|
-
createAgentSessionServices,
|
|
1115
|
-
getAgentDir,
|
|
1116
|
-
SessionManager,
|
|
1117
|
-
} from "@bastani/atomic";
|
|
1118
|
-
|
|
1119
|
-
// In-memory (no persistence)
|
|
1120
|
-
const { session } = await createAgentSession({
|
|
1121
|
-
sessionManager: SessionManager.inMemory(),
|
|
1122
|
-
});
|
|
1123
|
-
|
|
1124
|
-
// New persistent session
|
|
1125
|
-
const { session: persisted } = await createAgentSession({
|
|
1126
|
-
sessionManager: SessionManager.create(process.cwd()),
|
|
1127
|
-
});
|
|
1128
|
-
|
|
1129
|
-
// Continue most recent
|
|
1130
|
-
const { session: continued, modelFallbackMessage } = await createAgentSession({
|
|
1131
|
-
sessionManager: SessionManager.continueRecent(process.cwd()),
|
|
1132
|
-
});
|
|
1133
|
-
if (modelFallbackMessage) {
|
|
1134
|
-
console.log("Note:", modelFallbackMessage);
|
|
1135
|
-
}
|
|
1136
|
-
|
|
1137
|
-
// Open specific file
|
|
1138
|
-
const { session: opened } = await createAgentSession({
|
|
1139
|
-
sessionManager: SessionManager.open("/path/to/session.jsonl"),
|
|
1140
|
-
});
|
|
1141
|
-
|
|
1142
|
-
// List sessions
|
|
1143
|
-
const currentProjectSessions = await SessionManager.list(process.cwd());
|
|
1144
|
-
const allSessions = await SessionManager.listAll(process.cwd());
|
|
1145
|
-
|
|
1146
|
-
// Session replacement API for /new, /resume, /fork, /clone, and import flows.
|
|
1147
|
-
const createRuntime: CreateAgentSessionRuntimeFactory = async ({ cwd, sessionManager, sessionStartEvent }) => {
|
|
1148
|
-
const services = await createAgentSessionServices({ cwd });
|
|
1149
|
-
return {
|
|
1150
|
-
...(await createAgentSessionFromServices({
|
|
1151
|
-
services,
|
|
1152
|
-
sessionManager,
|
|
1153
|
-
sessionStartEvent,
|
|
1154
|
-
})),
|
|
1155
|
-
services,
|
|
1156
|
-
diagnostics: services.diagnostics,
|
|
1157
|
-
};
|
|
1158
|
-
};
|
|
1159
|
-
|
|
1160
|
-
const runtime = await createAgentSessionRuntime(createRuntime, {
|
|
1161
|
-
cwd: process.cwd(),
|
|
1162
|
-
agentDir: getAgentDir(),
|
|
1163
|
-
sessionManager: SessionManager.create(process.cwd()),
|
|
1164
|
-
});
|
|
1165
|
-
|
|
1166
|
-
// Replace the active session with a fresh one
|
|
1167
|
-
await runtime.newSession();
|
|
1168
|
-
|
|
1169
|
-
// Replace the active session with another saved session
|
|
1170
|
-
await runtime.switchSession("/path/to/session.jsonl");
|
|
1171
|
-
|
|
1172
|
-
// Replace the active session with a fork from a specific user entry
|
|
1173
|
-
await runtime.fork("entry-id");
|
|
1174
|
-
|
|
1175
|
-
// Clone the active path through a specific entry
|
|
1176
|
-
await runtime.fork("entry-id", { position: "at" });
|
|
1177
|
-
```
|
|
1178
|
-
|
|
1179
|
-
**SessionManager tree API:**
|
|
1180
|
-
|
|
1181
|
-
```typescript
|
|
1182
|
-
const sm = SessionManager.open("/path/to/session.jsonl");
|
|
1183
|
-
|
|
1184
|
-
// Session listing
|
|
1185
|
-
const currentProjectSessions = await SessionManager.list(process.cwd());
|
|
1186
|
-
const allSessions = await SessionManager.listAll(process.cwd());
|
|
1187
|
-
|
|
1188
|
-
// Tree traversal
|
|
1189
|
-
const entries = sm.getEntries(); // All entries (excludes header)
|
|
1190
|
-
const tree = sm.getTree(); // Full tree structure
|
|
1191
|
-
const path = sm.getPath(); // Path from root to current leaf
|
|
1192
|
-
const leaf = sm.getLeafEntry(); // Current leaf entry
|
|
1193
|
-
const entry = sm.getEntry(id); // Get entry by ID
|
|
1194
|
-
const children = sm.getChildren(id); // Direct children of entry
|
|
1195
|
-
|
|
1196
|
-
// Labels
|
|
1197
|
-
const label = sm.getLabel(id); // Get label for entry
|
|
1198
|
-
sm.appendLabelChange(id, "checkpoint"); // Set label
|
|
1199
|
-
|
|
1200
|
-
// Branching
|
|
1201
|
-
sm.branch(entryId); // Move leaf to earlier entry
|
|
1202
|
-
sm.branchWithSummary(id, "Summary..."); // Branch with context summary
|
|
1203
|
-
sm.createBranchedSession(leafId); // Extract path to new file
|
|
1204
|
-
```
|
|
1205
|
-
|
|
1206
|
-
> See [examples/sdk/11-sessions.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/sdk/11-sessions.ts) and [Session Format](/session-format)
|
|
487
|
+
Moved to [SDK API reference](/sdk/reference#session-management).
|
|
1207
488
|
|
|
1208
489
|
### Settings Management
|
|
1209
490
|
|
|
1210
|
-
|
|
1211
|
-
import { createAgentSession, SettingsManager, SessionManager } from "@bastani/atomic";
|
|
1212
|
-
|
|
1213
|
-
// Default: loads from files (global + project merged)
|
|
1214
|
-
const { session } = await createAgentSession({
|
|
1215
|
-
settingsManager: SettingsManager.create(),
|
|
1216
|
-
});
|
|
1217
|
-
|
|
1218
|
-
// With overrides
|
|
1219
|
-
const settingsManager = SettingsManager.create();
|
|
1220
|
-
settingsManager.applyOverrides({
|
|
1221
|
-
compaction: { enabled: false },
|
|
1222
|
-
retry: { enabled: true, maxRetries: 5 },
|
|
1223
|
-
});
|
|
1224
|
-
const { session } = await createAgentSession({ settingsManager });
|
|
1225
|
-
|
|
1226
|
-
// In-memory (no file I/O, for testing)
|
|
1227
|
-
const { session } = await createAgentSession({
|
|
1228
|
-
settingsManager: SettingsManager.inMemory({ compaction: { enabled: false } }),
|
|
1229
|
-
sessionManager: SessionManager.inMemory(),
|
|
1230
|
-
});
|
|
1231
|
-
|
|
1232
|
-
// Custom directories
|
|
1233
|
-
const { session } = await createAgentSession({
|
|
1234
|
-
settingsManager: SettingsManager.create("/custom/cwd", "/custom/agent"),
|
|
1235
|
-
});
|
|
1236
|
-
```
|
|
1237
|
-
|
|
1238
|
-
**Static factories:**
|
|
1239
|
-
- `SettingsManager.create(cwd?, agentDir?)` - Load from files
|
|
1240
|
-
- `SettingsManager.inMemory(settings?)` - No file I/O
|
|
1241
|
-
|
|
1242
|
-
**Project-specific settings:**
|
|
1243
|
-
|
|
1244
|
-
Settings load from Atomic-first locations and merge:
|
|
1245
|
-
1. Global: `~/.atomic/agent/settings.json`, then legacy `~/.pi/agent/settings.json`
|
|
1246
|
-
2. Project: `<cwd>/.atomic/settings.json`, then legacy `<cwd>/.pi/settings.json`
|
|
1247
|
-
|
|
1248
|
-
Project overrides global. Nested objects merge keys. Setters modify global settings by default.
|
|
1249
|
-
|
|
1250
|
-
**Persistence and error handling semantics:**
|
|
1251
|
-
|
|
1252
|
-
- Settings getters/setters are synchronous for in-memory state.
|
|
1253
|
-
- Setters enqueue persistence writes asynchronously.
|
|
1254
|
-
- Call `await settingsManager.flush()` when you need a durability boundary (for example, before process exit or before asserting file contents in tests).
|
|
1255
|
-
- `SettingsManager` does not print settings I/O errors. Use `settingsManager.drainErrors()` and report them in your app layer.
|
|
1256
|
-
|
|
1257
|
-
> See [examples/sdk/10-settings.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/sdk/10-settings.ts)
|
|
491
|
+
Moved to [SDK API reference](/sdk/reference#settings-management).
|
|
1258
492
|
|
|
1259
493
|
## ResourceLoader
|
|
1260
494
|
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
```typescript
|
|
1264
|
-
import {
|
|
1265
|
-
DefaultResourceLoader,
|
|
1266
|
-
getAgentDir,
|
|
1267
|
-
} from "@bastani/atomic";
|
|
1268
|
-
|
|
1269
|
-
const loader = new DefaultResourceLoader({
|
|
1270
|
-
cwd,
|
|
1271
|
-
agentDir: getAgentDir(),
|
|
1272
|
-
});
|
|
1273
|
-
await loader.reload();
|
|
1274
|
-
|
|
1275
|
-
const extensions = loader.getExtensions();
|
|
1276
|
-
const skills = loader.getSkills();
|
|
1277
|
-
const prompts = loader.getPrompts();
|
|
1278
|
-
const themes = loader.getThemes();
|
|
1279
|
-
const contextFiles = loader.getAgentsFiles().agentsFiles;
|
|
1280
|
-
```
|
|
495
|
+
Moved to [SDK API reference](/sdk/reference#resourceloader).
|
|
1281
496
|
|
|
1282
497
|
## Return Value
|
|
1283
498
|
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
```typescript
|
|
1287
|
-
interface CreateAgentSessionResult {
|
|
1288
|
-
// The session
|
|
1289
|
-
session: AgentSession;
|
|
1290
|
-
|
|
1291
|
-
// Extensions result (for runner setup)
|
|
1292
|
-
extensionsResult: LoadExtensionsResult;
|
|
1293
|
-
|
|
1294
|
-
// Warning if session model couldn't be restored
|
|
1295
|
-
modelFallbackMessage?: string;
|
|
1296
|
-
}
|
|
1297
|
-
|
|
1298
|
-
interface LoadExtensionsResult {
|
|
1299
|
-
extensions: Extension[];
|
|
1300
|
-
errors: Array<{ path: string; error: string }>;
|
|
1301
|
-
runtime: ExtensionRuntime;
|
|
1302
|
-
}
|
|
1303
|
-
```
|
|
499
|
+
Moved to [SDK API reference](/sdk/reference#return-value).
|
|
1304
500
|
|
|
1305
501
|
## Complete Example
|
|
1306
502
|
|
|
@@ -1386,118 +582,19 @@ await session.prompt("Get status and list files.");
|
|
|
1386
582
|
|
|
1387
583
|
## Run Modes
|
|
1388
584
|
|
|
1389
|
-
|
|
585
|
+
Moved to [SDK API reference](/sdk/reference#run-modes).
|
|
1390
586
|
|
|
1391
587
|
### InteractiveMode
|
|
1392
588
|
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
```typescript
|
|
1396
|
-
import {
|
|
1397
|
-
type CreateAgentSessionRuntimeFactory,
|
|
1398
|
-
createAgentSessionFromServices,
|
|
1399
|
-
createAgentSessionRuntime,
|
|
1400
|
-
createAgentSessionServices,
|
|
1401
|
-
getAgentDir,
|
|
1402
|
-
InteractiveMode,
|
|
1403
|
-
SessionManager,
|
|
1404
|
-
} from "@bastani/atomic";
|
|
1405
|
-
|
|
1406
|
-
const createRuntime: CreateAgentSessionRuntimeFactory = async ({ cwd, sessionManager, sessionStartEvent }) => {
|
|
1407
|
-
const services = await createAgentSessionServices({ cwd });
|
|
1408
|
-
return {
|
|
1409
|
-
...(await createAgentSessionFromServices({ services, sessionManager, sessionStartEvent })),
|
|
1410
|
-
services,
|
|
1411
|
-
diagnostics: services.diagnostics,
|
|
1412
|
-
};
|
|
1413
|
-
};
|
|
1414
|
-
const runtime = await createAgentSessionRuntime(createRuntime, {
|
|
1415
|
-
cwd: process.cwd(),
|
|
1416
|
-
agentDir: getAgentDir(),
|
|
1417
|
-
sessionManager: SessionManager.create(process.cwd()),
|
|
1418
|
-
});
|
|
1419
|
-
|
|
1420
|
-
const mode = new InteractiveMode(runtime, {
|
|
1421
|
-
migratedProviders: [],
|
|
1422
|
-
modelFallbackMessage: undefined,
|
|
1423
|
-
initialMessage: "Hello",
|
|
1424
|
-
initialImages: [],
|
|
1425
|
-
initialMessages: [],
|
|
1426
|
-
});
|
|
1427
|
-
|
|
1428
|
-
await mode.run();
|
|
1429
|
-
```
|
|
589
|
+
Moved to [SDK API reference](/sdk/reference#interactivemode).
|
|
1430
590
|
|
|
1431
591
|
### runPrintMode
|
|
1432
592
|
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
```typescript
|
|
1436
|
-
import {
|
|
1437
|
-
type CreateAgentSessionRuntimeFactory,
|
|
1438
|
-
createAgentSessionFromServices,
|
|
1439
|
-
createAgentSessionRuntime,
|
|
1440
|
-
createAgentSessionServices,
|
|
1441
|
-
getAgentDir,
|
|
1442
|
-
runPrintMode,
|
|
1443
|
-
SessionManager,
|
|
1444
|
-
} from "@bastani/atomic";
|
|
1445
|
-
|
|
1446
|
-
const createRuntime: CreateAgentSessionRuntimeFactory = async ({ cwd, sessionManager, sessionStartEvent }) => {
|
|
1447
|
-
const services = await createAgentSessionServices({ cwd });
|
|
1448
|
-
return {
|
|
1449
|
-
...(await createAgentSessionFromServices({ services, sessionManager, sessionStartEvent })),
|
|
1450
|
-
services,
|
|
1451
|
-
diagnostics: services.diagnostics,
|
|
1452
|
-
};
|
|
1453
|
-
};
|
|
1454
|
-
const runtime = await createAgentSessionRuntime(createRuntime, {
|
|
1455
|
-
cwd: process.cwd(),
|
|
1456
|
-
agentDir: getAgentDir(),
|
|
1457
|
-
sessionManager: SessionManager.create(process.cwd()),
|
|
1458
|
-
});
|
|
1459
|
-
|
|
1460
|
-
await runPrintMode(runtime, {
|
|
1461
|
-
mode: "text",
|
|
1462
|
-
initialMessage: "Hello",
|
|
1463
|
-
initialImages: [],
|
|
1464
|
-
messages: ["Follow up"],
|
|
1465
|
-
});
|
|
1466
|
-
```
|
|
593
|
+
Moved to [SDK API reference](/sdk/reference#runprintmode).
|
|
1467
594
|
|
|
1468
595
|
### runRpcMode
|
|
1469
596
|
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
```typescript
|
|
1473
|
-
import {
|
|
1474
|
-
type CreateAgentSessionRuntimeFactory,
|
|
1475
|
-
createAgentSessionFromServices,
|
|
1476
|
-
createAgentSessionRuntime,
|
|
1477
|
-
createAgentSessionServices,
|
|
1478
|
-
getAgentDir,
|
|
1479
|
-
runRpcMode,
|
|
1480
|
-
SessionManager,
|
|
1481
|
-
} from "@bastani/atomic";
|
|
1482
|
-
|
|
1483
|
-
const createRuntime: CreateAgentSessionRuntimeFactory = async ({ cwd, sessionManager, sessionStartEvent }) => {
|
|
1484
|
-
const services = await createAgentSessionServices({ cwd });
|
|
1485
|
-
return {
|
|
1486
|
-
...(await createAgentSessionFromServices({ services, sessionManager, sessionStartEvent })),
|
|
1487
|
-
services,
|
|
1488
|
-
diagnostics: services.diagnostics,
|
|
1489
|
-
};
|
|
1490
|
-
};
|
|
1491
|
-
const runtime = await createAgentSessionRuntime(createRuntime, {
|
|
1492
|
-
cwd: process.cwd(),
|
|
1493
|
-
agentDir: getAgentDir(),
|
|
1494
|
-
sessionManager: SessionManager.create(process.cwd()),
|
|
1495
|
-
});
|
|
1496
|
-
|
|
1497
|
-
await runRpcMode(runtime);
|
|
1498
|
-
```
|
|
1499
|
-
|
|
1500
|
-
See [RPC documentation](/rpc) for the JSON protocol.
|
|
597
|
+
Moved to [SDK API reference](/sdk/reference#runrpcmode).
|
|
1501
598
|
|
|
1502
599
|
## RPC Mode Alternative
|
|
1503
600
|
|
|
@@ -1522,59 +619,16 @@ RPC mode is preferred when:
|
|
|
1522
619
|
|
|
1523
620
|
## Exports
|
|
1524
621
|
|
|
1525
|
-
|
|
622
|
+
Moved to [SDK API reference](/sdk/reference#exports).
|
|
1526
623
|
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
// Resource loading
|
|
1538
|
-
DefaultResourceLoader
|
|
1539
|
-
type ResourceLoader
|
|
1540
|
-
createEventBus
|
|
1541
|
-
|
|
1542
|
-
// Constants and helpers
|
|
1543
|
-
CONFIG_DIR_NAME
|
|
1544
|
-
defineTool
|
|
1545
|
-
STRUCTURED_OUTPUT_TOOL_NAME
|
|
1546
|
-
createStructuredOutputTool
|
|
1547
|
-
createStructuredOutputCapture
|
|
1548
|
-
getAgentDir
|
|
1549
|
-
getPackageDir
|
|
1550
|
-
getReadmePath
|
|
1551
|
-
getDocsPath
|
|
1552
|
-
getExamplesPath
|
|
1553
|
-
generateDiffString
|
|
1554
|
-
generateUnifiedPatch
|
|
1555
|
-
type EditDiffResult
|
|
1556
|
-
|
|
1557
|
-
// Session management
|
|
1558
|
-
SessionManager
|
|
1559
|
-
SettingsManager
|
|
1560
|
-
|
|
1561
|
-
// Tool factories
|
|
1562
|
-
createCodingTools
|
|
1563
|
-
createReadOnlyTools
|
|
1564
|
-
createReadTool, createBashTool, createEditTool, createWriteTool
|
|
1565
|
-
createGrepTool, createFindTool, createLsTool
|
|
1566
|
-
|
|
1567
|
-
// Types
|
|
1568
|
-
type CreateAgentSessionOptions
|
|
1569
|
-
type CreateAgentSessionResult
|
|
1570
|
-
type StructuredOutputCapture
|
|
1571
|
-
type StructuredOutputToolOptions
|
|
1572
|
-
type ExtensionFactory
|
|
1573
|
-
type ExtensionAPI
|
|
1574
|
-
type ToolDefinition
|
|
1575
|
-
type Skill
|
|
1576
|
-
type PromptTemplate
|
|
1577
|
-
type Tool
|
|
1578
|
-
```
|
|
624
|
+
## Owner-bound task supervisor (S1)
|
|
625
|
+
|
|
626
|
+
Moved to [SDK API reference](/sdk/reference#owner-bound-task-supervisor-s1).
|
|
627
|
+
|
|
628
|
+
### Supervised command SDK
|
|
629
|
+
|
|
630
|
+
Moved to [SDK API reference](/sdk/reference#supervised-command-sdk).
|
|
631
|
+
|
|
632
|
+
### Task transcript references
|
|
1579
633
|
|
|
1580
|
-
|
|
634
|
+
Moved to [SDK API reference](/sdk/reference#task-transcript-references).
|