strands-darwin 0.0.35 → 0.0.37
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/README.md +23 -6
- package/README.zh-CN.md +23 -6
- package/dist/patches/{@strands-agents+sdk+1.16.0.patch → @strands-agents+sdk+1.18.0.patch} +320 -9
- package/dist/src/agent/compact.js +1 -1
- package/dist/src/agent/prompt-cache.js +15 -2
- package/dist/src/agent/prompt-cache.js.map +1 -1
- package/dist/src/agent/rewind.d.ts +2 -0
- package/dist/src/agent/rewind.js +4 -1
- package/dist/src/agent/rewind.js.map +1 -1
- package/dist/src/agent/runtime.d.ts +81 -20
- package/dist/src/agent/runtime.js +227 -43
- package/dist/src/agent/runtime.js.map +1 -1
- package/dist/src/agent/session.d.ts +96 -4
- package/dist/src/agent/session.js +249 -9
- package/dist/src/agent/session.js.map +1 -1
- package/dist/src/agent/stream-idle.d.ts +16 -0
- package/dist/src/agent/stream-idle.js +127 -0
- package/dist/src/agent/stream-idle.js.map +1 -0
- package/dist/src/agent/system-prompt.d.ts +1 -1
- package/dist/src/agent/system-prompt.js +12 -0
- package/dist/src/agent/system-prompt.js.map +1 -1
- package/dist/src/agent/task-terminal-delivery.d.ts +25 -2
- package/dist/src/agent/task-terminal-delivery.js +80 -7
- package/dist/src/agent/task-terminal-delivery.js.map +1 -1
- package/dist/src/agent/working-context.d.ts +21 -1
- package/dist/src/agent/working-context.js +28 -1
- package/dist/src/agent/working-context.js.map +1 -1
- package/dist/src/agent/workspace-trust.d.ts +112 -0
- package/dist/src/agent/workspace-trust.js +207 -0
- package/dist/src/agent/workspace-trust.js.map +1 -0
- package/dist/src/agentcore/auto-policy.d.ts +7 -0
- package/dist/src/agentcore/auto-policy.js +50 -0
- package/dist/src/agentcore/auto-policy.js.map +1 -0
- package/dist/src/agentcore/auto-state.d.ts +43 -0
- package/dist/src/agentcore/auto-state.js +73 -0
- package/dist/src/agentcore/auto-state.js.map +1 -0
- package/dist/src/agentcore/cli.d.ts +2 -0
- package/dist/src/agentcore/cli.js +38 -0
- package/dist/src/agentcore/cli.js.map +1 -0
- package/dist/src/agentcore/config.d.ts +48 -0
- package/dist/src/agentcore/config.js +44 -0
- package/dist/src/agentcore/config.js.map +1 -0
- package/dist/src/agentcore/controller.d.ts +105 -0
- package/dist/src/agentcore/controller.js +979 -0
- package/dist/src/agentcore/controller.js.map +1 -0
- package/dist/src/agentcore/projection.d.ts +2 -0
- package/dist/src/agentcore/projection.js +8 -0
- package/dist/src/agentcore/projection.js.map +1 -0
- package/dist/src/agentcore/records.d.ts +41 -0
- package/dist/src/agentcore/records.js +149 -0
- package/dist/src/agentcore/records.js.map +1 -0
- package/dist/src/agentcore/state.d.ts +16 -0
- package/dist/src/agentcore/state.js +149 -0
- package/dist/src/agentcore/state.js.map +1 -0
- package/dist/src/agentcore/tools.d.ts +3 -0
- package/dist/src/agentcore/tools.js +11 -0
- package/dist/src/agentcore/tools.js.map +1 -0
- package/dist/src/agentcore/transport.d.ts +37 -0
- package/dist/src/agentcore/transport.js +242 -0
- package/dist/src/agentcore/transport.js.map +1 -0
- package/dist/src/agentcore/upload-projection.d.ts +208 -0
- package/dist/src/agentcore/upload-projection.js +823 -0
- package/dist/src/agentcore/upload-projection.js.map +1 -0
- package/dist/src/agents/child-recipe.js +4 -1
- package/dist/src/agents/child-recipe.js.map +1 -1
- package/dist/src/agents/loader.d.ts +12 -0
- package/dist/src/agents/loader.js +15 -1
- package/dist/src/agents/loader.js.map +1 -1
- package/dist/src/agents/subagent-tool.js +2 -4
- package/dist/src/agents/subagent-tool.js.map +1 -1
- package/dist/src/agents/workflow-tool.js +2 -4
- package/dist/src/agents/workflow-tool.js.map +1 -1
- package/dist/src/cli-doctor.js +7 -0
- package/dist/src/cli-doctor.js.map +1 -1
- package/dist/src/cli-import.d.ts +1 -0
- package/dist/src/cli-import.js +26 -0
- package/dist/src/cli-import.js.map +1 -0
- package/dist/src/cli-main.js +60 -10
- package/dist/src/cli-main.js.map +1 -1
- package/dist/src/cli-permissions.d.ts +2 -0
- package/dist/src/cli-permissions.js +20 -0
- package/dist/src/cli-permissions.js.map +1 -0
- package/dist/src/cli-sessions.js +6 -2
- package/dist/src/cli-sessions.js.map +1 -1
- package/dist/src/cli-usage.d.ts +9 -1
- package/dist/src/cli-usage.js +13 -0
- package/dist/src/cli-usage.js.map +1 -1
- package/dist/src/cli.js +19 -2
- package/dist/src/cli.js.map +1 -1
- package/dist/src/commands/custom-commands.d.ts +1 -1
- package/dist/src/commands/custom-commands.js +14 -6
- package/dist/src/commands/custom-commands.js.map +1 -1
- package/dist/src/commands/review-command.d.ts +10 -0
- package/dist/src/commands/review-command.js +28 -0
- package/dist/src/commands/review-command.js.map +1 -0
- package/dist/src/config-file.d.ts +9 -0
- package/dist/src/config-file.js +82 -0
- package/dist/src/config-file.js.map +1 -0
- package/dist/src/config.d.ts +66 -5
- package/dist/src/config.js +126 -42
- package/dist/src/config.js.map +1 -1
- package/dist/src/dev-repl.js +17 -1
- package/dist/src/dev-repl.js.map +1 -1
- package/dist/src/headless-protocol.d.ts +24 -1
- package/dist/src/headless-protocol.js +18 -0
- package/dist/src/headless-protocol.js.map +1 -1
- package/dist/src/headless-runner.d.ts +8 -0
- package/dist/src/headless-runner.js +37 -1
- package/dist/src/headless-runner.js.map +1 -1
- package/dist/src/hooks/hook-process.js +7 -2
- package/dist/src/hooks/hook-process.js.map +1 -1
- package/dist/src/hooks/lifecycle-hooks.js +3 -1
- package/dist/src/hooks/lifecycle-hooks.js.map +1 -1
- package/dist/src/hooks/tool-hooks.js +3 -1
- package/dist/src/hooks/tool-hooks.js.map +1 -1
- package/dist/src/import-claude-files.d.ts +28 -0
- package/dist/src/import-claude-files.js +227 -0
- package/dist/src/import-claude-files.js.map +1 -0
- package/dist/src/import-claude-snippets.d.ts +2 -0
- package/dist/src/import-claude-snippets.js +105 -0
- package/dist/src/import-claude-snippets.js.map +1 -0
- package/dist/src/import-claude.d.ts +13 -0
- package/dist/src/import-claude.js +287 -0
- package/dist/src/import-claude.js.map +1 -0
- package/dist/src/mcp/registry.d.ts +57 -1
- package/dist/src/mcp/registry.js +78 -6
- package/dist/src/mcp/registry.js.map +1 -1
- package/dist/src/memory/command.d.ts +1 -1
- package/dist/src/memory/command.js +89 -4
- package/dist/src/memory/command.js.map +1 -1
- package/dist/src/memory/controller.d.ts +32 -0
- package/dist/src/memory/controller.js +39 -3
- package/dist/src/memory/controller.js.map +1 -1
- package/dist/src/memory/state.d.ts +6 -0
- package/dist/src/memory/state.js +6 -1
- package/dist/src/memory/state.js.map +1 -1
- package/dist/src/memory/store.d.ts +13 -0
- package/dist/src/memory/store.js +38 -2
- package/dist/src/memory/store.js.map +1 -1
- package/dist/src/memory/tools.d.ts +7 -0
- package/dist/src/memory/tools.js +12 -1
- package/dist/src/memory/tools.js.map +1 -1
- package/dist/src/npm-package/patch-package-format.d.ts +5 -5
- package/dist/src/npm-package/patch-package-format.js +4 -4
- package/dist/src/paths.js +3 -0
- package/dist/src/paths.js.map +1 -1
- package/dist/src/permissions-test.d.ts +18 -0
- package/dist/src/permissions-test.js +207 -0
- package/dist/src/permissions-test.js.map +1 -0
- package/dist/src/pricing/model-prices.d.ts +8 -5
- package/dist/src/pricing/model-prices.js +30 -15
- package/dist/src/pricing/model-prices.js.map +1 -1
- package/dist/src/project-identity.d.ts +3 -0
- package/dist/src/project-identity.js +8 -0
- package/dist/src/project-identity.js.map +1 -0
- package/dist/src/project-overrides.d.ts +57 -0
- package/dist/src/project-overrides.js +79 -0
- package/dist/src/project-overrides.js.map +1 -0
- package/dist/src/sdk-patch-preflight.js +1 -1
- package/dist/src/skills/builtin/developer/SKILL.md +2 -0
- package/dist/src/skills/builtin/self-reflection/references/reflection-template.md +2 -1
- package/dist/src/skills/builtin/setup-agentcore-memory/SKILL.md +158 -0
- package/dist/src/skills/loader.d.ts +1 -1
- package/dist/src/skills/loader.js +4 -1
- package/dist/src/skills/loader.js.map +1 -1
- package/dist/src/tools/background-bash.d.ts +13 -1
- package/dist/src/tools/background-bash.js +36 -8
- package/dist/src/tools/background-bash.js.map +1 -1
- package/dist/src/tools/shell-env.d.ts +24 -0
- package/dist/src/tools/shell-env.js +34 -0
- package/dist/src/tools/shell-env.js.map +1 -1
- package/dist/src/trajectory/reader.d.ts +1 -1
- package/dist/src/trajectory/reader.js +23 -3
- package/dist/src/trajectory/reader.js.map +1 -1
- package/dist/src/trajectory/record.d.ts +50 -2
- package/dist/src/trajectory/record.js +32 -0
- package/dist/src/trajectory/record.js.map +1 -1
- package/dist/src/trajectory/replay.d.ts +12 -1
- package/dist/src/trajectory/replay.js +31 -2
- package/dist/src/trajectory/replay.js.map +1 -1
- package/dist/src/trajectory/resume-recap.d.ts +11 -1
- package/dist/src/trajectory/resume-recap.js +10 -1
- package/dist/src/trajectory/resume-recap.js.map +1 -1
- package/dist/src/trajectory/rewind-history.d.ts +8 -0
- package/dist/src/trajectory/rewind-history.js +81 -0
- package/dist/src/trajectory/rewind-history.js.map +1 -0
- package/dist/src/trajectory/writer.d.ts +14 -1
- package/dist/src/trajectory/writer.js +38 -0
- package/dist/src/trajectory/writer.js.map +1 -1
- package/dist/src/tui/App.d.ts +5 -1
- package/dist/src/tui/App.js +284 -51
- package/dist/src/tui/App.js.map +1 -1
- package/dist/src/tui/InputBox.d.ts +1 -1
- package/dist/src/tui/InputBox.js +3 -2
- package/dist/src/tui/InputBox.js.map +1 -1
- package/dist/src/tui/MessageList.js +1 -1
- package/dist/src/tui/MessageList.js.map +1 -1
- package/dist/src/tui/PermissionPrompt.js +5 -3
- package/dist/src/tui/PermissionPrompt.js.map +1 -1
- package/dist/src/tui/QueuedMessages.js +14 -8
- package/dist/src/tui/QueuedMessages.js.map +1 -1
- package/dist/src/tui/ToolCallPanel.js +2 -2
- package/dist/src/tui/ToolCallPanel.js.map +1 -1
- package/dist/src/tui/WorkspaceTrustPrompt.d.ts +8 -0
- package/dist/src/tui/WorkspaceTrustPrompt.js +37 -0
- package/dist/src/tui/WorkspaceTrustPrompt.js.map +1 -0
- package/dist/src/tui/draft-stash.d.ts +25 -0
- package/dist/src/tui/draft-stash.js +49 -0
- package/dist/src/tui/draft-stash.js.map +1 -0
- package/dist/src/tui/frame-budget.d.ts +2 -2
- package/dist/src/tui/frame-budget.js +3 -3
- package/dist/src/tui/frame-budget.js.map +1 -1
- package/dist/src/tui/help-format.d.ts +2 -2
- package/dist/src/tui/help-format.js +3 -3
- package/dist/src/tui/help-format.js.map +1 -1
- package/dist/src/tui/mcp-format.d.ts +9 -0
- package/dist/src/tui/mcp-format.js +5 -3
- package/dist/src/tui/mcp-format.js.map +1 -1
- package/dist/src/tui/permission-rule-preview.d.ts +23 -0
- package/dist/src/tui/permission-rule-preview.js +38 -0
- package/dist/src/tui/permission-rule-preview.js.map +1 -0
- package/dist/src/tui/prompt-editor.d.ts +12 -0
- package/dist/src/tui/prompt-editor.js +57 -37
- package/dist/src/tui/prompt-editor.js.map +1 -1
- package/dist/src/tui/prompt-history-search.js +3 -2
- package/dist/src/tui/prompt-history-search.js.map +1 -1
- package/dist/src/tui/prompt-queue.d.ts +4 -2
- package/dist/src/tui/prompt-queue.js +18 -3
- package/dist/src/tui/prompt-queue.js.map +1 -1
- package/dist/src/tui/rewind-search.js +4 -3
- package/dist/src/tui/rewind-search.js.map +1 -1
- package/dist/src/tui/search-preview.d.ts +2 -0
- package/dist/src/tui/search-preview.js +9 -0
- package/dist/src/tui/search-preview.js.map +1 -0
- package/dist/src/tui/shell-command.js +4 -1
- package/dist/src/tui/shell-command.js.map +1 -1
- package/dist/src/tui/spinner.d.ts +1 -0
- package/dist/src/tui/spinner.js +6 -0
- package/dist/src/tui/spinner.js.map +1 -0
- package/dist/src/tui/status-format.d.ts +9 -0
- package/dist/src/tui/status-format.js +37 -2
- package/dist/src/tui/status-format.js.map +1 -1
- package/dist/src/tui/subagent-format.js +6 -0
- package/dist/src/tui/subagent-format.js.map +1 -1
- package/dist/src/tui/task-format.d.ts +5 -0
- package/dist/src/tui/task-format.js +15 -0
- package/dist/src/tui/task-format.js.map +1 -1
- package/dist/src/tui/trust-format.d.ts +31 -0
- package/dist/src/tui/trust-format.js +102 -0
- package/dist/src/tui/trust-format.js.map +1 -0
- package/dist/src/tui/turn-state.d.ts +1 -0
- package/dist/src/tui/turn-state.js +2 -0
- package/dist/src/tui/turn-state.js.map +1 -1
- package/package.json +4 -3
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { access, cp, mkdir, readFile, readdir, writeFile } from 'node:fs/promises';
|
|
1
|
+
import { access, cp, mkdir, readFile, readdir, rm, rmdir, writeFile } from 'node:fs/promises';
|
|
2
|
+
import os from 'node:os';
|
|
2
3
|
import path from 'node:path';
|
|
4
|
+
import process from 'node:process';
|
|
3
5
|
import { SessionManager } from '@strands-agents/sdk';
|
|
4
6
|
import { LocalFileStorage } from '@strands-agents/sdk/storage';
|
|
5
7
|
import { darwinDir, userProjectSessionsDir } from '../paths.js';
|
|
@@ -9,6 +11,20 @@ const POINTER_FILENAME = 'last-session.json';
|
|
|
9
11
|
export const TRAJECTORY_FILENAME = 'trajectory.jsonl';
|
|
10
12
|
/** Per-session opt-in diagnostics log; the same sibling convention. */
|
|
11
13
|
export const DIAGNOSTICS_FILENAME = 'diagnostics.log';
|
|
14
|
+
/**
|
|
15
|
+
* Per-session ownership marker (SER-091), the same sibling convention:
|
|
16
|
+
* `<sessionsDir>/<sessionId>/lease.json` names the one process that may append to
|
|
17
|
+
* this session's record and overwrite its snapshot.
|
|
18
|
+
*/
|
|
19
|
+
export const LEASE_FILENAME = 'lease.json';
|
|
20
|
+
/**
|
|
21
|
+
* A lease written on another host cannot be checked with `process.kill(pid, 0)`, so
|
|
22
|
+
* it counts as live until its `startedAt` is this old; then it is stale and taken over.
|
|
23
|
+
* There is no heartbeat: this is the only bound, and it is stated in the user guide.
|
|
24
|
+
*/
|
|
25
|
+
export const FOREIGN_LEASE_STALE_AFTER_MS = 24 * 60 * 60 * 1000;
|
|
26
|
+
/** Longest `hostname`/`startedAt` text a lease record may put into a notice, in code points. */
|
|
27
|
+
const MAX_LEASE_FIELD_CHARS = 64;
|
|
12
28
|
export function sessionPaths(projectRoot) {
|
|
13
29
|
const stateDir = userProjectSessionsDir(projectRoot);
|
|
14
30
|
return {
|
|
@@ -51,6 +67,13 @@ export function sessionDir(projectRoot, sessionId) {
|
|
|
51
67
|
export function sessionStateDir(projectRoot, sessionId) {
|
|
52
68
|
return path.join(sessionPaths(projectRoot).sessionsDir, sessionId);
|
|
53
69
|
}
|
|
70
|
+
/** `<sessionsDir>/<sessionId>/lease.json` — the state dir, never the SDK's `session/<id>`. */
|
|
71
|
+
export function leasePath(projectRoot, sessionId) {
|
|
72
|
+
return leasePathIn(sessionPaths(projectRoot), sessionId);
|
|
73
|
+
}
|
|
74
|
+
function leasePathIn(paths, sessionId) {
|
|
75
|
+
return path.join(paths.sessionsDir, sessionId, LEASE_FILENAME);
|
|
76
|
+
}
|
|
54
77
|
/** Whether this project has a restorable snapshot for `sessionId`. */
|
|
55
78
|
export function hasSnapshot(projectRoot, sessionId, agentId) {
|
|
56
79
|
return snapshotExists(sessionPaths(projectRoot), sessionId, agentId);
|
|
@@ -119,10 +142,30 @@ export class SessionNotFoundError extends Error {
|
|
|
119
142
|
}
|
|
120
143
|
}
|
|
121
144
|
/**
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
145
|
+
* An explicitly named session whose lease another live process holds (SER-091).
|
|
146
|
+
*
|
|
147
|
+
* The sibling of {@link SessionNotFoundError}, refused in the same shape and for the
|
|
148
|
+
* same reason: the caller asked for one specific conversation, and opening it twice
|
|
149
|
+
* is how its snapshot and trajectory get corrupted (last writer wins on both). Never
|
|
150
|
+
* a fallback — bare `--resume` is the forgiving selector, and it starts fresh instead.
|
|
151
|
+
*/
|
|
152
|
+
export class SessionInUseError extends Error {
|
|
153
|
+
sessionId;
|
|
154
|
+
lease;
|
|
155
|
+
constructor(sessionId, lease) {
|
|
156
|
+
super(`Session ${JSON.stringify(sessionId)} is open ${describeHolder(lease)}; close it or start a new session.`);
|
|
157
|
+
this.sessionId = sessionId;
|
|
158
|
+
this.lease = lease;
|
|
159
|
+
this.name = 'SessionInUseError';
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Picks the session id for this run and takes its lease. `continue` retains the
|
|
164
|
+
* TUI's forgiving behavior and starts fresh when there is no pointer — or when the
|
|
165
|
+
* pointed session is open in another live process (the notice says so). An explicit
|
|
166
|
+
* id is strict: it means "continue this persisted conversation", so a typo must not
|
|
167
|
+
* silently create a different empty session, and a live lease is a refusal
|
|
168
|
+
* ({@link SessionInUseError}), never a fallback.
|
|
126
169
|
*/
|
|
127
170
|
export async function resolveSession(projectRoot, selector, agentId) {
|
|
128
171
|
const paths = sessionPaths(projectRoot);
|
|
@@ -131,8 +174,22 @@ export async function resolveSession(projectRoot, selector, agentId) {
|
|
|
131
174
|
const previous = await readPointer(paths.pointerFile);
|
|
132
175
|
if (previous !== undefined) {
|
|
133
176
|
const exists = await snapshotExists(paths, previous, agentId);
|
|
134
|
-
if (exists)
|
|
135
|
-
|
|
177
|
+
if (exists) {
|
|
178
|
+
const acquired = await acquireLease(paths, previous);
|
|
179
|
+
if (acquired.kind === 'acquired') {
|
|
180
|
+
return {
|
|
181
|
+
sessionId: previous,
|
|
182
|
+
restoreRequested: true,
|
|
183
|
+
lease: acquired.lease,
|
|
184
|
+
...(acquired.notice === undefined ? {} : { leaseNotice: acquired.notice }),
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
const fresh = await acquireFresh(paths);
|
|
188
|
+
return {
|
|
189
|
+
...fresh,
|
|
190
|
+
leaseNotice: `session ${previous} is open ${describeHolder(acquired.record)}; started a fresh session instead`,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
136
193
|
}
|
|
137
194
|
}
|
|
138
195
|
if (selector.kind === 'id') {
|
|
@@ -142,9 +199,192 @@ export async function resolveSession(projectRoot, selector, agentId) {
|
|
|
142
199
|
if (!(await snapshotExists(paths, selector.sessionId, agentId))) {
|
|
143
200
|
throw new SessionNotFoundError(selector.sessionId);
|
|
144
201
|
}
|
|
145
|
-
|
|
202
|
+
const acquired = await acquireLease(paths, selector.sessionId);
|
|
203
|
+
if (acquired.kind === 'held')
|
|
204
|
+
throw new SessionInUseError(selector.sessionId, acquired.record);
|
|
205
|
+
return {
|
|
206
|
+
sessionId: selector.sessionId,
|
|
207
|
+
restoreRequested: true,
|
|
208
|
+
lease: acquired.lease,
|
|
209
|
+
...(acquired.notice === undefined ? {} : { leaseNotice: acquired.notice }),
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
return acquireFresh(paths);
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* A brand-new id and its lease. The id is timestamp-derived, so a collision is a
|
|
216
|
+
* second darwin started in the same millisecond in the same project — the `wx`
|
|
217
|
+
* write refuses it and the next id is tried, bounded.
|
|
218
|
+
*/
|
|
219
|
+
async function acquireFresh(paths) {
|
|
220
|
+
for (let attempt = 0; attempt < 3; attempt += 1) {
|
|
221
|
+
const sessionId = newSessionId();
|
|
222
|
+
const acquired = await acquireLease(paths, sessionId);
|
|
223
|
+
if (acquired.kind === 'acquired') {
|
|
224
|
+
return { sessionId, restoreRequested: false, lease: acquired.lease };
|
|
225
|
+
}
|
|
226
|
+
// Ids carry milliseconds: wait for the next one rather than retrying the same id.
|
|
227
|
+
await new Promise((resolve) => setTimeout(resolve, 2));
|
|
228
|
+
}
|
|
229
|
+
throw new Error('Could not allocate a fresh session id: every candidate is already leased.');
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Writes `lease.json` with `wx`. An existing file is read and classified: live means
|
|
233
|
+
* `held`; stale means the file is removed and the `wx` write tried once more, so two
|
|
234
|
+
* launches taking over the same stale lease at the same instant still end with one
|
|
235
|
+
* holder (the second `wx` sees the first's file and reads it back as live). Never a
|
|
236
|
+
* manual unlock: liveness, not a flag, decides.
|
|
237
|
+
*/
|
|
238
|
+
async function acquireLease(paths, sessionId) {
|
|
239
|
+
const file = leasePathIn(paths, sessionId);
|
|
240
|
+
await mkdir(path.dirname(file), { recursive: true });
|
|
241
|
+
const record = { pid: process.pid, hostname: os.hostname(), startedAt: new Date().toISOString() };
|
|
242
|
+
const body = `${JSON.stringify(record, null, 2)}\n`;
|
|
243
|
+
let notice;
|
|
244
|
+
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
245
|
+
try {
|
|
246
|
+
await writeFile(file, body, { encoding: 'utf8', flag: 'wx' });
|
|
247
|
+
return { kind: 'acquired', lease: makeLease(sessionId, file, record), ...(notice === undefined ? {} : { notice }) };
|
|
248
|
+
}
|
|
249
|
+
catch (error) {
|
|
250
|
+
if (!isExisting(error))
|
|
251
|
+
throw error;
|
|
252
|
+
}
|
|
253
|
+
const status = classifyLease(await readLeaseRecord(file), defaultLeaseEnvironment());
|
|
254
|
+
if (status.kind === 'live')
|
|
255
|
+
return { kind: 'held', record: status.record };
|
|
256
|
+
if (status.kind === 'none')
|
|
257
|
+
continue; // Removed between the write and the read: try again.
|
|
258
|
+
notice = status.record === undefined
|
|
259
|
+
? `session ${sessionId}: replaced an unreadable lease file`
|
|
260
|
+
: `session ${sessionId}: took over a stale lease left by ${describeHolderShort(status.record)}`;
|
|
261
|
+
await rm(file, { force: true });
|
|
262
|
+
}
|
|
263
|
+
// Both attempts lost the race to a competitor whose lease now reads live.
|
|
264
|
+
const status = classifyLease(await readLeaseRecord(file), defaultLeaseEnvironment());
|
|
265
|
+
if (status.kind === 'live')
|
|
266
|
+
return { kind: 'held', record: status.record };
|
|
267
|
+
throw new Error(`Could not take the lease for session ${JSON.stringify(sessionId)}: ${file} keeps reappearing.`);
|
|
268
|
+
}
|
|
269
|
+
function makeLease(sessionId, file, record) {
|
|
270
|
+
let released = false;
|
|
271
|
+
return {
|
|
272
|
+
sessionId,
|
|
273
|
+
file,
|
|
274
|
+
record,
|
|
275
|
+
async release() {
|
|
276
|
+
if (released)
|
|
277
|
+
return;
|
|
278
|
+
released = true;
|
|
279
|
+
try {
|
|
280
|
+
const current = await readLeaseRecord(file);
|
|
281
|
+
if (current === undefined || current.pid !== record.pid || current.hostname !== record.hostname)
|
|
282
|
+
return;
|
|
283
|
+
await rm(file, { force: true });
|
|
284
|
+
// A session that never wrote anything else leaves no directory behind, so
|
|
285
|
+
// `darwin sessions` and `trajectory list` do not count every aborted launch.
|
|
286
|
+
// `rmdir` refuses a non-empty directory, which is exactly the intent.
|
|
287
|
+
await rmdir(path.dirname(file)).catch(() => undefined);
|
|
288
|
+
}
|
|
289
|
+
catch {
|
|
290
|
+
// Left in place: it names a pid that is about to be dead, so it is stale.
|
|
291
|
+
}
|
|
292
|
+
},
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* The lease rule (SER-091). Same host: the pid decides — alive (including `EPERM`,
|
|
297
|
+
* which means it exists under another user) is live, gone is stale. Other host: live
|
|
298
|
+
* until `startedAt` is {@link FOREIGN_LEASE_STALE_AFTER_MS} old, unparseable dates
|
|
299
|
+
* count as stale. A record that does not parse is stale with no holder to name.
|
|
300
|
+
*/
|
|
301
|
+
export function classifyLease(record, environment) {
|
|
302
|
+
if (record === undefined)
|
|
303
|
+
return { kind: 'stale', record: undefined };
|
|
304
|
+
if (record.hostname === environment.hostname) {
|
|
305
|
+
return environment.pidAlive(record.pid) ? { kind: 'live', record } : { kind: 'stale', record };
|
|
306
|
+
}
|
|
307
|
+
const started = Date.parse(record.startedAt);
|
|
308
|
+
if (Number.isNaN(started) || environment.now - started >= FOREIGN_LEASE_STALE_AFTER_MS) {
|
|
309
|
+
return { kind: 'stale', record };
|
|
146
310
|
}
|
|
147
|
-
return {
|
|
311
|
+
return { kind: 'live', record };
|
|
312
|
+
}
|
|
313
|
+
/** `process.kill(pid, 0)` — signal 0 checks existence; `EPERM` means it exists under another user. */
|
|
314
|
+
export function pidAlive(pid) {
|
|
315
|
+
if (!Number.isInteger(pid) || pid <= 0)
|
|
316
|
+
return false;
|
|
317
|
+
try {
|
|
318
|
+
process.kill(pid, 0);
|
|
319
|
+
return true;
|
|
320
|
+
}
|
|
321
|
+
catch (error) {
|
|
322
|
+
return typeof error === 'object' && error !== null && error.code === 'EPERM';
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
function defaultLeaseEnvironment() {
|
|
326
|
+
return { hostname: os.hostname(), now: Date.now(), pidAlive };
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* How one session's lease reads right now, for `darwin sessions` — a read of one
|
|
330
|
+
* file and one signal-0 probe, no write. An absent file is `none`.
|
|
331
|
+
*/
|
|
332
|
+
export async function inspectLease(projectRoot, sessionId) {
|
|
333
|
+
const file = leasePath(projectRoot, sessionId);
|
|
334
|
+
try {
|
|
335
|
+
await access(file);
|
|
336
|
+
}
|
|
337
|
+
catch {
|
|
338
|
+
return { kind: 'none' };
|
|
339
|
+
}
|
|
340
|
+
return classifyLease(await readLeaseRecord(file), defaultLeaseEnvironment());
|
|
341
|
+
}
|
|
342
|
+
/** The parsed record, or `undefined` for a missing, unreadable or malformed file. */
|
|
343
|
+
async function readLeaseRecord(file) {
|
|
344
|
+
let raw;
|
|
345
|
+
try {
|
|
346
|
+
raw = await readFile(file, 'utf8');
|
|
347
|
+
}
|
|
348
|
+
catch {
|
|
349
|
+
return undefined;
|
|
350
|
+
}
|
|
351
|
+
try {
|
|
352
|
+
const parsed = JSON.parse(raw);
|
|
353
|
+
if (typeof parsed !== 'object' || parsed === null)
|
|
354
|
+
return undefined;
|
|
355
|
+
const { pid, hostname, startedAt } = parsed;
|
|
356
|
+
if (!Number.isInteger(pid) || typeof hostname !== 'string' || typeof startedAt !== 'string')
|
|
357
|
+
return undefined;
|
|
358
|
+
return {
|
|
359
|
+
pid: pid,
|
|
360
|
+
hostname: boundField(hostname),
|
|
361
|
+
startedAt: boundField(startedAt),
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
catch {
|
|
365
|
+
return undefined;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
function boundField(value) {
|
|
369
|
+
const points = [...value];
|
|
370
|
+
return points.length > MAX_LEASE_FIELD_CHARS ? `${points.slice(0, MAX_LEASE_FIELD_CHARS).join('')}…` : value;
|
|
371
|
+
}
|
|
372
|
+
/** `in pid N since <time>` on this host, `on <host> in pid N since <time>` elsewhere. */
|
|
373
|
+
export function describeHolder(record, hostname = os.hostname()) {
|
|
374
|
+
return `${describeHolderLocation(record, hostname)} since ${record.startedAt}`;
|
|
375
|
+
}
|
|
376
|
+
/** The holder without the time: `in pid N`, or `on <host> in pid N` for another host. */
|
|
377
|
+
export function describeHolderLocation(record, hostname = os.hostname()) {
|
|
378
|
+
const where = record.hostname === hostname ? '' : `on ${record.hostname} `;
|
|
379
|
+
return `${where}in pid ${record.pid}`;
|
|
380
|
+
}
|
|
381
|
+
/** `pid N (started <time>)`, with the host named only when it is not this one. */
|
|
382
|
+
function describeHolderShort(record) {
|
|
383
|
+
const where = record.hostname === os.hostname() ? '' : ` on ${record.hostname}`;
|
|
384
|
+
return `pid ${record.pid}${where} (started ${record.startedAt})`;
|
|
385
|
+
}
|
|
386
|
+
function isExisting(error) {
|
|
387
|
+
return typeof error === 'object' && error !== null && error.code === 'EEXIST';
|
|
148
388
|
}
|
|
149
389
|
async function snapshotExists(paths, sessionId, agentId) {
|
|
150
390
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../../src/agent/session.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACnF,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAE/D,OAAO,EAAE,S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,YAAY;KAC3B,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Middleware } from '@anthropic-ai/sdk';
|
|
2
|
+
import type { LocalAgent } from '@strands-agents/sdk';
|
|
3
|
+
export declare const DEFAULT_STREAM_IDLE_TIMEOUT_SECONDS = 120;
|
|
4
|
+
export declare const MAX_STREAM_IDLE_TIMEOUT_SECONDS = 2147483;
|
|
5
|
+
export declare class StreamIdleError extends Error {
|
|
6
|
+
constructor(seconds: number);
|
|
7
|
+
}
|
|
8
|
+
export declare const modelStreamMiddleware: Middleware;
|
|
9
|
+
/**
|
|
10
|
+
* Register AFTER model retry, so its intentional backoff is outside this stage.
|
|
11
|
+
* A per-call model facade uses the public streamAggregated extension: SDK parsing,
|
|
12
|
+
* event bytes, metadata and model state are unchanged. Only pending provider reads
|
|
13
|
+
* are timed; upstream hooks/driver backpressure, token counting, tools, permission,
|
|
14
|
+
* background completion and compaction have no timer. No prefetch or loop fork.
|
|
15
|
+
*/
|
|
16
|
+
export declare function installStreamIdleWatchdog(agent: LocalAgent, seconds?: number): void;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/** Parent model-stream idle watchdog (SER-095), not a turn deadline. */
|
|
2
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
3
|
+
import { InvokeModelStage } from '@strands-agents/sdk';
|
|
4
|
+
export const DEFAULT_STREAM_IDLE_TIMEOUT_SECONDS = 120;
|
|
5
|
+
export const MAX_STREAM_IDLE_TIMEOUT_SECONDS = 2_147_483;
|
|
6
|
+
export class StreamIdleError extends Error {
|
|
7
|
+
constructor(seconds) {
|
|
8
|
+
super(`stream idle for ${seconds}s`);
|
|
9
|
+
this.name = 'StreamIdleError';
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
// The direct Anthropic adapter in the pinned SDK drops StreamOptions.cancelSignal.
|
|
13
|
+
// Its client middleware is the transport bridge. Async-local scope is entered
|
|
14
|
+
// only for a provider iterator read, never around an Agent/tool. Set the public
|
|
15
|
+
// request options signal too: the client's error path consults it before retrying
|
|
16
|
+
// a pre-header abort. No retry, private provider fields or global fetch replacement.
|
|
17
|
+
const transportSignal = new AsyncLocalStorage();
|
|
18
|
+
export const modelStreamMiddleware = (request, next, context) => {
|
|
19
|
+
const signal = transportSignal.getStore();
|
|
20
|
+
if (signal === undefined)
|
|
21
|
+
return next(request);
|
|
22
|
+
const combined = request.signal ? AbortSignal.any([signal, request.signal]) : signal;
|
|
23
|
+
if (context.options !== undefined)
|
|
24
|
+
context.options.signal = combined;
|
|
25
|
+
return next({ ...request, signal: combined });
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Register AFTER model retry, so its intentional backoff is outside this stage.
|
|
29
|
+
* A per-call model facade uses the public streamAggregated extension: SDK parsing,
|
|
30
|
+
* event bytes, metadata and model state are unchanged. Only pending provider reads
|
|
31
|
+
* are timed; upstream hooks/driver backpressure, token counting, tools, permission,
|
|
32
|
+
* background completion and compaction have no timer. No prefetch or loop fork.
|
|
33
|
+
*/
|
|
34
|
+
export function installStreamIdleWatchdog(agent, seconds = DEFAULT_STREAM_IDLE_TIMEOUT_SECONDS) {
|
|
35
|
+
const watchdog = async function* (context, next) {
|
|
36
|
+
const userSignal = context.agent.cancelSignal;
|
|
37
|
+
const model = context.model;
|
|
38
|
+
let active;
|
|
39
|
+
const guardedStream = async function* (messages, options) {
|
|
40
|
+
const abort = new AbortController();
|
|
41
|
+
const signal = AbortSignal.any([userSignal, abort.signal]);
|
|
42
|
+
const source = model.streamAggregated(messages, { ...options, cancelSignal: signal });
|
|
43
|
+
let idle;
|
|
44
|
+
let done = false;
|
|
45
|
+
try {
|
|
46
|
+
while (true) {
|
|
47
|
+
let timer;
|
|
48
|
+
if (seconds > 0 && !userSignal.aborted) {
|
|
49
|
+
timer = setTimeout(() => {
|
|
50
|
+
if (userSignal.aborted)
|
|
51
|
+
return;
|
|
52
|
+
idle = new StreamIdleError(seconds);
|
|
53
|
+
abort.abort();
|
|
54
|
+
}, seconds * 1000);
|
|
55
|
+
timer.unref();
|
|
56
|
+
}
|
|
57
|
+
let result;
|
|
58
|
+
try {
|
|
59
|
+
// Await the aborting read, not a detached Promise.race loser. A late
|
|
60
|
+
// result is discarded before the SDK can append it or launch a tool.
|
|
61
|
+
result = await transportSignal.run(signal, () => source.next());
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
userSignal.throwIfAborted();
|
|
65
|
+
throw idle ?? error;
|
|
66
|
+
}
|
|
67
|
+
finally {
|
|
68
|
+
clearTimeout(timer);
|
|
69
|
+
}
|
|
70
|
+
userSignal.throwIfAborted();
|
|
71
|
+
if (idle !== undefined)
|
|
72
|
+
throw idle;
|
|
73
|
+
if (result.done) {
|
|
74
|
+
done = true;
|
|
75
|
+
return result.value;
|
|
76
|
+
}
|
|
77
|
+
yield result.value;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
finally {
|
|
81
|
+
abort.abort();
|
|
82
|
+
try {
|
|
83
|
+
if (!done)
|
|
84
|
+
await source.return(undefined);
|
|
85
|
+
}
|
|
86
|
+
finally {
|
|
87
|
+
// Cleanup cannot replace the terminal idle identity; user cancellation
|
|
88
|
+
// still wins if it arrives while the provider's finally is running.
|
|
89
|
+
userSignal.throwIfAborted();
|
|
90
|
+
if (idle !== undefined)
|
|
91
|
+
throw idle;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
// Do not mutate the shared provider (children may use it too). Bind delegated
|
|
96
|
+
// methods to the original, including methods with provider-private fields.
|
|
97
|
+
const guarded = new Proxy(model, {
|
|
98
|
+
get(target, key) {
|
|
99
|
+
if (key === 'streamAggregated')
|
|
100
|
+
return (...args) => {
|
|
101
|
+
active = guardedStream(...args);
|
|
102
|
+
return active;
|
|
103
|
+
};
|
|
104
|
+
const value = Reflect.get(target, key, target);
|
|
105
|
+
return typeof value === 'function' ? value.bind(target) : value;
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
try {
|
|
109
|
+
return yield* next({ ...context, model: guarded });
|
|
110
|
+
}
|
|
111
|
+
finally {
|
|
112
|
+
// The SDK checks cancel between yields and manually advances its model
|
|
113
|
+
// iterator. Close ours even when that check bypasses the next provider read.
|
|
114
|
+
try {
|
|
115
|
+
await active?.return(undefined);
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
// The SDK already owns a between-yield cancellation. Do not replace its
|
|
119
|
+
// internal CancelledError with the provider generator's cleanup abort.
|
|
120
|
+
if (!userSignal.aborted)
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
agent.addMiddleware(InvokeModelStage, watchdog);
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=stream-idle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-idle.js","sourceRoot":"","sources":["../../../src/agent/stream-idle.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAGvD,MAAM,CAAC,MAAM,mCAAmC,GAAG,GAAG,CAAC;AACvD,MAAM,CAAC,MAAM,+BAA+B,GAAG,SAAS,CAAC;AAEzD,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACxC,YAAY,OAAe;QACzB,KAAK,CAAC,mBAAmB,OAAO,GAAG,CAAC,CAAC;QACrC,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AAED,mFAAmF;AACnF,8EAA8E;AAC9E,gFAAgF;AAChF,kFAAkF;AAClF,qFAAqF;AACrF,MAAM,eAAe,GAAG,IAAI,iBAAiB,EAAe,CAAC;AAC7D,MAAM,CAAC,MAAM,qBAAqB,GAAe,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE;IAC1E,MAAM,MAA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ENAME = "system-prompt.md";
|
|
|
14
14
|
* anything is unverifiable, and one that works around a denied tool call defeats
|
|
15
15
|
* the permission gate.
|
|
16
16
|
*/
|
|
17
|
-
export declare const DEFAULT_SYSTEM_PROMPT = "You are darwin, a coding agent working inside a real git repository on the user's machine.\nYou act like a careful senior engineer: you read before you change, you change as little as\npossible, and you prove that what you changed works.\n\n## Tools\n\nEach tool's description is its contract: what it does, which parameters it requires and its\nlimits live there, not here. Optional runtime plugins and MCP servers may add tools beyond the\nbuilt-ins. Prefer using a tool to find something out over guessing or asking the user for what\nyou could read yourself.\n\n## Working method\n\n1. Understand the code before touching it. Locate the relevant files, read them, and follow the\n conventions already there \u2014 matching the surrounding style matters more than your own taste.\n2. Never edit a file you have not read in this conversation. Never invent an API, a flag, a\n dependency or a file path you have not verified.\n3. Make small, targeted edits. Prefer str_replace over rewriting a whole file, and do not\n reformat, rename or \"improve\" code the task did not ask about. A new file longer than roughly\n one screen is created as a skeleton (title, headings, short placeholders) and filled section\n by section with separate str_replace/insert calls, each bounded to a few thousand words: one\n whole-document tool-call payload can exceed what the provider stream completes.\n4. Verify your work by running something: the project's typecheck, its tests, or a command that\n exercises the change. If verification is impossible, say so instead of implying success.\n5. After a tool fails twice with the same cause, state a materially new evidence-backed hypothesis\n before retrying. Three equivalent failures are the limit: stop, report the blocker and collected\n artifacts, and ask the user before continuing in a new turn.\n6. Do not add dependencies, delete data, or rewrite git history unless asked.\n7. Batch independent reads: when several tool calls have no dependency between them \u2014 searches,\n file views, status checks \u2014 issue them together in one assistant message instead of one call\n per round. Every round replays the whole conversation to the model; a round that carries one\n small read costs the same replay as one that carries five.\n8. Consolidate edits: collect what an analysis or review pass found, then change each file\n region in one edit; overlapping fixes to one region are one edit. Do not alternate\n one small str_replace per round when the next change is already known: tool calls in one\n message run concurrently, but fileEditor edits to the same file are applied in call order, so\n disjoint edits to one file may share a message and each later call sees the earlier result.\n A verification command (typecheck, tests, a build, `rg` for the new text) never shares a\n message with the edits it checks \u2014 it runs in the next message, after the edit results are in.\n File mutations go through fileEditor (create, str_replace, insert), not `cat >`/heredocs,\n `sed -i`, `python3 - <<EOF` or `tee`, so the edit diff, the permission classification and the\n trajectory record exist; create refuses an existing file \u2014 view, then str_replace the scaffold.\n\n## Working with the user\n\n- Report what you did, what you ran, and what the result was. State failures plainly; a passing\n claim that turns out to be false is worse than an admitted problem.\n- When the task is ambiguous or a requirement conflicts with something you found in the code,\n ask before implementing a guess.\n- Lead with the outcome: the first sentence of a finished turn says what happened or what you\n found; supporting detail follows. Output is read in a terminal \u2014 keep it readable rather than\n compressed: drop details that would not change what the reader does next, but write complete\n sentences, no arrow chains or shorthand you coined while working, no restating the request\n back. Before a long stretch of tool calls say in a line what you are about to do, and close a\n long run with a recap that stands on its own.\n- Only you see a tool's full output; the user's terminal shows at most a few lines of it. If\n the user needs to read any of it, put it in your reply.\n- Follow the project's own instructions (AGENTS.md, skills) when they conflict with these\n general rules \u2014 they know the repository and this prompt does not.\n\n## Permissions\n\nSome tool calls need the user's approval. If a call comes back denied, do not retry it and do\nnot work around it \u2014 explain what you were attempting and ask how to proceed.";
|
|
17
|
+
export declare const DEFAULT_SYSTEM_PROMPT = "You are darwin, a coding agent working inside a real git repository on the user's machine.\nYou act like a careful senior engineer: you read before you change, you change as little as\npossible, and you prove that what you changed works.\n\n## Tools\n\nEach tool's description is its contract: what it does, which parameters it requires and its\nlimits live there, not here. Optional runtime plugins and MCP servers may add tools beyond the\nbuilt-ins. Prefer using a tool to find something out over guessing or asking the user for what\nyou could read yourself.\n\n## Working method\n\n1. Understand the code before touching it. Locate the relevant files, read them, and follow the\n conventions already there \u2014 matching the surrounding style matters more than your own taste.\n2. Never edit a file you have not read in this conversation. Never invent an API, a flag, a\n dependency or a file path you have not verified.\n3. Make small, targeted edits. Prefer str_replace over rewriting a whole file, and do not\n reformat, rename or \"improve\" code the task did not ask about. A new file longer than roughly\n one screen is created as a skeleton (title, headings, short placeholders) and filled section\n by section with separate str_replace/insert calls, each bounded to a few thousand words: one\n whole-document tool-call payload can exceed what the provider stream completes.\n4. Verify your work by running something: the project's typecheck, its tests, or a command that\n exercises the change. If verification is impossible, say so instead of implying success.\n When a reply reports material numbers, compute sums and other summaries with an available\n local tool rather than mentally, and reconcile the components against the authoritative total,\n units and time window. Keep requested apart from executed quantities and observed apart from\n estimated or counterfactual values; state missing evidence or an unexplained residual instead\n of claiming the figures reconcile.\n5. After a tool fails twice with the same cause, state a materially new evidence-backed hypothesis\n before retrying. Three equivalent failures are the limit: stop, report the blocker and collected\n artifacts, and ask the user before continuing in a new turn.\n Code you write to run unattended with side effects needs the same bounds: after a bounded\n number of identical deterministic rejections, pause that action with its reason stated until\n inputs or observed state change; retry transient limits a bounded number of times with backoff,\n honouring any server-directed delay; when a state-changing request's outcome is ambiguous (a\n timeout, say), reconcile the actual state or use an idempotency key before replaying it. When\n feasible, check such a script against representative offline response sequences before an\n unattended launch.\n6. Do not add dependencies, delete data, or rewrite git history unless asked.\n7. Batch independent reads: when several tool calls have no dependency between them \u2014 searches,\n file views, status checks \u2014 issue them together in one assistant message instead of one call\n per round. Every round replays the whole conversation to the model; a round that carries one\n small read costs the same replay as one that carries five.\n8. Consolidate edits: collect what an analysis or review pass found, then change each file\n region in one edit; overlapping fixes to one region are one edit. Do not alternate\n one small str_replace per round when the next change is already known: tool calls in one\n message run concurrently, but fileEditor edits to the same file are applied in call order, so\n disjoint edits to one file may share a message and each later call sees the earlier result.\n A verification command (typecheck, tests, a build, `rg` for the new text) never shares a\n message with the edits it checks \u2014 it runs in the next message, after the edit results are in.\n File mutations go through fileEditor (create, str_replace, insert), not `cat >`/heredocs,\n `sed -i`, `python3 - <<EOF` or `tee`, so the edit diff, the permission classification and the\n trajectory record exist; create refuses an existing file \u2014 view, then str_replace the scaffold.\n\n## Working with the user\n\n- Report what you did, what you ran, and what the result was. State failures plainly; a passing\n claim that turns out to be false is worse than an admitted problem.\n- When the task is ambiguous or a requirement conflicts with something you found in the code,\n ask before implementing a guess.\n- Lead with the outcome: the first sentence of a finished turn says what happened or what you\n found; supporting detail follows. Output is read in a terminal \u2014 keep it readable rather than\n compressed: drop details that would not change what the reader does next, but write complete\n sentences, no arrow chains or shorthand you coined while working, no restating the request\n back. Before a long stretch of tool calls say in a line what you are about to do, and close a\n long run with a recap that stands on its own.\n- Only you see a tool's full output; the user's terminal shows at most a few lines of it. If\n the user needs to read any of it, put it in your reply.\n- Follow the project's own instructions (AGENTS.md, skills) when they conflict with these\n general rules \u2014 they know the repository and this prompt does not.\n\n## Permissions\n\nSome tool calls need the user's approval. If a call comes back denied, do not retry it and do\nnot work around it \u2014 explain what you were attempting and ask how to proceed.";
|
|
18
18
|
/**
|
|
19
19
|
* Appended to the base prompt for headless (`-p`) runs only, where no one answers a
|
|
20
20
|
* question mid-turn. It overrides the interactive "ask before implementing a guess"
|
|
@@ -56,9 +56,21 @@ you could read yourself.
|
|
|
56
56
|
whole-document tool-call payload can exceed what the provider stream completes.
|
|
57
57
|
4. Verify your work by running something: the project's typecheck, its tests, or a command that
|
|
58
58
|
exercises the change. If verification is impossible, say so instead of implying success.
|
|
59
|
+
When a reply reports material numbers, compute sums and other summaries with an available
|
|
60
|
+
local tool rather than mentally, and reconcile the components against the authoritative total,
|
|
61
|
+
units and time window. Keep requested apart from executed quantities and observed apart from
|
|
62
|
+
estimated or counterfactual values; state missing evidence or an unexplained residual instead
|
|
63
|
+
of claiming the figures reconcile.
|
|
59
64
|
5. After a tool fails twice with the same cause, state a materially new evidence-backed hypothesis
|
|
60
65
|
before retrying. Three equivalent failures are the limit: stop, report the blocker and collected
|
|
61
66
|
artifacts, and ask the user before continuing in a new turn.
|
|
67
|
+
Code you write to run unattended with side effects needs the same bounds: after a bounded
|
|
68
|
+
number of identical deterministic rejections, pause that action with its reason stated until
|
|
69
|
+
inputs or observed state change; retry transient limits a bounded number of times with backoff,
|
|
70
|
+
honouring any server-directed delay; when a state-changing request's outcome is ambiguous (a
|
|
71
|
+
timeout, say), reconcile the actual state or use an idempotency key before replaying it. When
|
|
72
|
+
feasible, check such a script against representative offline response sequences before an
|
|
73
|
+
unattended launch.
|
|
62
74
|
6. Do not add dependencies, delete data, or rewrite git history unless asked.
|
|
63
75
|
7. Batch independent reads: when several tool calls have no dependency between them — searches,
|
|
64
76
|
file views, status checks — issue them together in one assistant message instead of one call
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"system-prompt.js","sourceRoot":"","sources":["../../../src/agent/system-prompt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,gDAAgD;AAChD,MAAM,CAAC,MAAM,sBAAsB,GAAG,kBAAkB,CAAC;AAEzD;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG
|
|
1
|
+
{"version":3,"file":"system-prompt.js","sourceRoot":"","sources":["../../../src/agent/system-prompt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,gDAAgD;AAChD,MAAM,CAAC,MAAM,sBAAsB,GAAG,kBAAkB,CAAC;AAEzD;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8EA2EyC,CAAC;AAE/E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG;;;;;;;;;2BASd,CAAC;AAkB5B;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,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AI,CAAC,CAAC,CAAC,SAAS,CAAC;IAC9F,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,SAAS,CAAC;AACjD,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAChE,CAAC"}
|
|
@@ -15,12 +15,25 @@
|
|
|
15
15
|
* (`endTurn`) commits them, because a cancelled turn's tool result may never have
|
|
16
16
|
* been reasoned about. `observe` cannot throw — observer discipline: a ledger
|
|
17
17
|
* failure costs a possible duplicate wake, never a turn.
|
|
18
|
+
*
|
|
19
|
+
* SRF-036: the SDK `ContextOffloader` replaces an oversized result at default hook
|
|
20
|
+
* order with an `[Offloaded: …]` text preview, so the stream carries only the
|
|
21
|
+
* preview. {@link TerminalDeliveryLedger.install} therefore registers one
|
|
22
|
+
* `HookOrder.SDK_FIRST` `AfterToolCallEvent` hook that reads the *original* result
|
|
23
|
+
* and keeps its terminal ids as candidates keyed by `toolUseId`; `observe` resolves
|
|
24
|
+
* them against the result the stream actually carries. Unchanged, it counts exactly
|
|
25
|
+
* as before. Replaced, a candidate id counts only when the model-visible
|
|
26
|
+
* replacement text contains that exact id, so snapshots cut off by the preview stay
|
|
27
|
+
* undelivered. The preview is only searched for the literal id, never parsed for
|
|
28
|
+
* state: the state comes from the original.
|
|
18
29
|
*/
|
|
19
|
-
import
|
|
30
|
+
import { AfterToolCallEvent } from '@strands-agents/sdk';
|
|
31
|
+
import type { Agent, AgentStreamEvent } from '@strands-agents/sdk';
|
|
20
32
|
/**
|
|
21
33
|
* Task ids whose terminal state a successful `bash` result carried to the model.
|
|
22
34
|
* Recognizes the manager's own shapes only — `wait` (`status.state`), `status`/`stop`
|
|
23
|
-
* (a snapshot) and `list` (snapshots
|
|
35
|
+
* (a snapshot) and `list` (snapshots: a bare array, or the SDK's `{ $value: [...] }`
|
|
36
|
+
* envelope the real tool path produces) — by the result, never by the input, because
|
|
24
37
|
* some SDK after-events omit the original input. Foreground `execute` results and
|
|
25
38
|
* `output` results carry no state and contribute nothing.
|
|
26
39
|
*/
|
|
@@ -31,6 +44,16 @@ export declare function terminalTaskIdsInToolResult(toolName: string, result: {
|
|
|
31
44
|
export declare class TerminalDeliveryLedger {
|
|
32
45
|
private readonly delivered;
|
|
33
46
|
private pending;
|
|
47
|
+
/** Pre-replacement terminal ids per `toolUseId`, resolved by `observe`, dropped by `closeTurn`. */
|
|
48
|
+
private candidates;
|
|
49
|
+
/**
|
|
50
|
+
* Registers the pre-offload hook on the parent Agent: `SDK_FIRST`, so it runs
|
|
51
|
+
* before the `ContextOffloader`'s default-order hook can replace the result.
|
|
52
|
+
* It only reads; it never changes the event.
|
|
53
|
+
*/
|
|
54
|
+
install(agent: Pick<Agent, 'addHook'>): void;
|
|
55
|
+
/** Records the original result's terminal ids for `observe`. Synchronous, non-throwing. */
|
|
56
|
+
candidate(event: AfterToolCallEvent): void;
|
|
34
57
|
/** Observes one stream event of the current turn. Synchronous, non-throwing. */
|
|
35
58
|
observe(event: AgentStreamEvent): void;
|
|
36
59
|
/**
|