strands-darwin 0.0.32 → 0.0.34

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.
Files changed (117) hide show
  1. package/README.md +3 -1
  2. package/README.zh-CN.md +3 -1
  3. package/dist/src/agent/background-delegation.d.ts +69 -11
  4. package/dist/src/agent/background-delegation.js +156 -28
  5. package/dist/src/agent/background-delegation.js.map +1 -1
  6. package/dist/src/agent/cache-miss.d.ts +143 -0
  7. package/dist/src/agent/cache-miss.js +182 -0
  8. package/dist/src/agent/cache-miss.js.map +1 -0
  9. package/dist/src/agent/compact.d.ts +28 -0
  10. package/dist/src/agent/compact.js +34 -0
  11. package/dist/src/agent/compact.js.map +1 -1
  12. package/dist/src/agent/context-breakdown.d.ts +109 -0
  13. package/dist/src/agent/context-breakdown.js +116 -0
  14. package/dist/src/agent/context-breakdown.js.map +1 -0
  15. package/dist/src/agent/instructions.d.ts +1 -1
  16. package/dist/src/agent/instructions.js.map +1 -1
  17. package/dist/src/agent/permission-rules.d.ts +81 -2
  18. package/dist/src/agent/permission-rules.js +226 -6
  19. package/dist/src/agent/permission-rules.js.map +1 -1
  20. package/dist/src/agent/permission.d.ts +116 -2
  21. package/dist/src/agent/permission.js +201 -26
  22. package/dist/src/agent/permission.js.map +1 -1
  23. package/dist/src/agent/prompt-cache.d.ts +12 -3
  24. package/dist/src/agent/prompt-cache.js +12 -3
  25. package/dist/src/agent/prompt-cache.js.map +1 -1
  26. package/dist/src/agent/runtime.d.ts +141 -1
  27. package/dist/src/agent/runtime.js +259 -13
  28. package/dist/src/agent/runtime.js.map +1 -1
  29. package/dist/src/agent/task-terminal-delivery.d.ts +43 -0
  30. package/dist/src/agent/task-terminal-delivery.js +115 -0
  31. package/dist/src/agent/task-terminal-delivery.js.map +1 -0
  32. package/dist/src/agents/child-recipe.d.ts +9 -1
  33. package/dist/src/agents/child-recipe.js +2 -0
  34. package/dist/src/agents/child-recipe.js.map +1 -1
  35. package/dist/src/agents/dispatch-registry.d.ts +18 -0
  36. package/dist/src/agents/dispatch-registry.js +2 -0
  37. package/dist/src/agents/dispatch-registry.js.map +1 -1
  38. package/dist/src/agents/retained-children.d.ts +101 -0
  39. package/dist/src/agents/retained-children.js +101 -0
  40. package/dist/src/agents/retained-children.js.map +1 -0
  41. package/dist/src/agents/subagent-tool.d.ts +56 -1
  42. package/dist/src/agents/subagent-tool.js +148 -10
  43. package/dist/src/agents/subagent-tool.js.map +1 -1
  44. package/dist/src/agents/workflow-tool.d.ts +2 -0
  45. package/dist/src/agents/workflow-tool.js +1 -1
  46. package/dist/src/agents/workflow-tool.js.map +1 -1
  47. package/dist/src/cli-doctor.js +3 -1
  48. package/dist/src/cli-doctor.js.map +1 -1
  49. package/dist/src/cli-main.js +14 -3
  50. package/dist/src/cli-main.js.map +1 -1
  51. package/dist/src/commands/custom-commands.js +5 -4
  52. package/dist/src/commands/custom-commands.js.map +1 -1
  53. package/dist/src/config.d.ts +57 -6
  54. package/dist/src/config.js +43 -16
  55. package/dist/src/config.js.map +1 -1
  56. package/dist/src/headless-protocol.d.ts +1 -1
  57. package/dist/src/headless-runner.js +7 -2
  58. package/dist/src/headless-runner.js.map +1 -1
  59. package/dist/src/hooks/tool-hooks.js +10 -6
  60. package/dist/src/hooks/tool-hooks.js.map +1 -1
  61. package/dist/src/skills/builtin/self-evolution-research/SKILL.md +14 -1
  62. package/dist/src/skills/prompt.d.ts +17 -0
  63. package/dist/src/skills/prompt.js +20 -0
  64. package/dist/src/skills/prompt.js.map +1 -1
  65. package/dist/src/tools/background-bash.d.ts +11 -2
  66. package/dist/src/tools/background-bash.js +11 -5
  67. package/dist/src/tools/background-bash.js.map +1 -1
  68. package/dist/src/tools/background-tail.d.ts +1 -0
  69. package/dist/src/tools/background-tail.js +2 -1
  70. package/dist/src/tools/background-tail.js.map +1 -1
  71. package/dist/src/tools/background-wait-contract.d.ts +7 -0
  72. package/dist/src/tools/background-wait-contract.js +17 -0
  73. package/dist/src/tools/background-wait-contract.js.map +1 -1
  74. package/dist/src/trajectory/record.d.ts +212 -2
  75. package/dist/src/trajectory/record.js +138 -0
  76. package/dist/src/trajectory/record.js.map +1 -1
  77. package/dist/src/trajectory/replay.d.ts +34 -1
  78. package/dist/src/trajectory/replay.js +148 -4
  79. package/dist/src/trajectory/replay.js.map +1 -1
  80. package/dist/src/trajectory/resume-recap.js +10 -3
  81. package/dist/src/trajectory/resume-recap.js.map +1 -1
  82. package/dist/src/trajectory/spend.d.ts +14 -1
  83. package/dist/src/trajectory/spend.js +40 -6
  84. package/dist/src/trajectory/spend.js.map +1 -1
  85. package/dist/src/trajectory/writer.d.ts +57 -6
  86. package/dist/src/trajectory/writer.js +141 -9
  87. package/dist/src/trajectory/writer.js.map +1 -1
  88. package/dist/src/tui/App.d.ts +8 -4
  89. package/dist/src/tui/App.js +302 -55
  90. package/dist/src/tui/App.js.map +1 -1
  91. package/dist/src/tui/background-tool-presentation.js +2 -2
  92. package/dist/src/tui/background-tool-presentation.js.map +1 -1
  93. package/dist/src/tui/context-format.d.ts +16 -0
  94. package/dist/src/tui/context-format.js +41 -0
  95. package/dist/src/tui/context-format.js.map +1 -1
  96. package/dist/src/tui/prompt-queue.d.ts +52 -8
  97. package/dist/src/tui/prompt-queue.js +68 -8
  98. package/dist/src/tui/prompt-queue.js.map +1 -1
  99. package/dist/src/tui/status-format.d.ts +35 -16
  100. package/dist/src/tui/status-format.js +67 -8
  101. package/dist/src/tui/status-format.js.map +1 -1
  102. package/dist/src/tui/subagent-format.d.ts +8 -0
  103. package/dist/src/tui/subagent-format.js +24 -1
  104. package/dist/src/tui/subagent-format.js.map +1 -1
  105. package/dist/src/tui/task-wake.d.ts +75 -0
  106. package/dist/src/tui/task-wake.js +201 -0
  107. package/dist/src/tui/task-wake.js.map +1 -0
  108. package/dist/src/tui/terminal-notify.d.ts +40 -0
  109. package/dist/src/tui/terminal-notify.js +136 -0
  110. package/dist/src/tui/terminal-notify.js.map +1 -0
  111. package/dist/src/tui/terminal-title.d.ts +94 -0
  112. package/dist/src/tui/terminal-title.js +121 -0
  113. package/dist/src/tui/terminal-title.js.map +1 -0
  114. package/dist/src/tui/turn-state.d.ts +10 -1
  115. package/dist/src/tui/turn-state.js +17 -1
  116. package/dist/src/tui/turn-state.js.map +1 -1
  117. package/package.json +1 -1
@@ -0,0 +1,182 @@
1
+ /**
2
+ * Why the prompt cache missed (SER-074): a derivation over facts darwin already
3
+ * holds, never a new measurement.
4
+ *
5
+ * `/usage` and `/status` have always shown cache read/write counts and a hit ratio,
6
+ * but a number alone does not say why a call re-read the conversation uncached.
7
+ * Every input needed to name a likely cause is already in the runtime: the per-call
8
+ * provider counters `observeCallStats` folds (`afterModelCallEvent`
9
+ * `stopData.message.metadata.usage`), the cache-invalidating events the session
10
+ * itself performed (`/model`, `/effort`, `/compact`), the configured TTL
11
+ * (`promptCacheTtl`: `1h` default, `5m`), the wall clock, and whether the session
12
+ * was resumed. This module is the pure arithmetic over those facts; the runtime
13
+ * feeds it through {@link CacheMissTracker} with the same synchronous,
14
+ * non-throwing, latch-on-failure discipline the call stats observe under.
15
+ *
16
+ * Advisory only, on the context-pressure row's terms: the verdict is printed on
17
+ * existing reports (`/usage`, `/status`) and as one transcript notice before a
18
+ * `/model` or `/effort` switch on a warm cache. Nothing is compacted, no second
19
+ * threshold exists, no frame row, tick or channel is added, nothing is persisted or
20
+ * recorded in the trajectory.
21
+ *
22
+ * Invalidators, and one deliberate non-invalidator. A model switch, an effective
23
+ * effort change and a compaction each change the request prefix (a different model
24
+ * keys a different cache; `output_config.effort` is part of the request; compaction
25
+ * rewrites the messages), and idling past the TTL lets the entries expire. `/rewind`
26
+ * is not marked: it restores an earlier prefix of the same conversation, whose cache
27
+ * entries are still valid if they have not expired — the same rule Claude Code's
28
+ * prompt-caching documentation states. File edits, permission-mode changes and skill
29
+ * loads change no cached section either.
30
+ *
31
+ * Claude-only by the gate `prompt-cache.ts` explains: OpenAI caches automatically
32
+ * at the provider with no darwin-placed cache points, so its counters describe a
33
+ * cache darwin did not configure — the tracker stays silent unless the live plan
34
+ * has Darwin-managed cache points.
35
+ */
36
+ import { DEFAULT_PROMPT_CACHE_TTL } from './prompt-cache.js';
37
+ /**
38
+ * A call reading less than this share of its own request total from the cache is a
39
+ * miss. A warm call on a long conversation reads nearly all of it (the last user
40
+ * message is the only uncached part); one fifth leaves room for a large tool result
41
+ * or user message without calling an ordinary turn a miss.
42
+ */
43
+ export const CACHE_MISS_READ_FRACTION = 0.2;
44
+ /** The TTL in milliseconds; an unset TTL is darwin's {@link DEFAULT_PROMPT_CACHE_TTL}. */
45
+ export function promptCacheTtlMs(ttl) {
46
+ return (ttl ?? DEFAULT_PROMPT_CACHE_TTL) === '1h' ? 3_600_000 : 300_000;
47
+ }
48
+ /**
49
+ * True when a call read less than {@link CACHE_MISS_READ_FRACTION} of its request
50
+ * from the cache. Unreported counters and an empty request are not misses: they are
51
+ * unknown, and unknown is never a verdict.
52
+ */
53
+ export function isCacheMiss(call) {
54
+ if (call.cacheRead === undefined || call.requestInput === undefined)
55
+ return false;
56
+ if (!Number.isFinite(call.cacheRead) || !Number.isFinite(call.requestInput) || call.requestInput <= 0)
57
+ return false;
58
+ return call.cacheRead < call.requestInput * CACHE_MISS_READ_FRACTION;
59
+ }
60
+ /**
61
+ * The likely cause of the current call's cache miss, or `undefined` for no verdict.
62
+ *
63
+ * No verdict when the current call's counters are unreported, when it is not a miss,
64
+ * when it is a fresh session's first call (expected cold: nothing has been written
65
+ * yet), or when the previous call was itself cold — a miss is only a miss relative
66
+ * to a cache that was demonstrably warm. When several causes apply, the one that
67
+ * certainly invalidated the prefix wins over the one that merely could have:
68
+ * `model switched` > `effort changed` > `compacted` > `idle past cache TTL` >
69
+ * `first request of a resumed session` > `unknown`.
70
+ */
71
+ export function cacheMissCause(input) {
72
+ const { previous, current, events, ttlMs, firstCallAfterResume } = input;
73
+ if (!isCacheMiss(current))
74
+ return undefined;
75
+ if (previous === undefined) {
76
+ if (!firstCallAfterResume)
77
+ return undefined;
78
+ }
79
+ else if (previous.cacheRead === undefined || !(previous.cacheRead > 0)) {
80
+ return undefined;
81
+ }
82
+ if (events.has('model'))
83
+ return 'model switched';
84
+ if (events.has('effort'))
85
+ return 'effort changed';
86
+ if (events.has('compact'))
87
+ return 'compacted';
88
+ if (previous !== undefined && current.at - previous.at > ttlMs)
89
+ return 'idle past cache TTL';
90
+ if (firstCallAfterResume)
91
+ return 'first request of a resumed session';
92
+ return 'unknown';
93
+ }
94
+ /** The cause as `/usage` and `/status` print it; the TTL cause names the configured TTL. */
95
+ export function describeCacheMissCause(cause, ttl) {
96
+ return cause === 'idle past cache TTL' ? `${cause} (${ttl ?? DEFAULT_PROMPT_CACHE_TTL})` : cause;
97
+ }
98
+ /**
99
+ * The one bounded notice `/model <target>` and `/effort <level>` print before a
100
+ * switch on a warm cache — `undefined` when the cache is cold or nothing is known,
101
+ * so a cold switch prints nothing new. States the cost and lets the switch proceed;
102
+ * deliberately not a confirmation dialog.
103
+ */
104
+ export function warmCacheSwitchNotice(kind, warmth) {
105
+ if (warmth === undefined || !warmth.warm)
106
+ return undefined;
107
+ return (`cache is warm (${formatWarmthAge(warmth.ageMs)} ago, ${warmth.lastCacheRead.toLocaleString('en-US')} tokens read last call): ` +
108
+ `switching ${kind} re-reads the conversation uncached`);
109
+ }
110
+ /** `12s`, `3m 12s`, `1h 2m` — the `/tasks` duration vocabulary, without a TUI import. */
111
+ function formatWarmthAge(milliseconds) {
112
+ const seconds = Math.floor(Math.max(0, milliseconds) / 1000);
113
+ if (seconds < 60)
114
+ return `${seconds}s`;
115
+ const minutes = Math.floor(seconds / 60);
116
+ if (minutes < 60)
117
+ return `${minutes}m ${seconds % 60}s`;
118
+ const hours = Math.floor(minutes / 60);
119
+ return `${hours}h ${minutes % 60}m`;
120
+ }
121
+ /**
122
+ * The per-runtime state behind {@link CacheMissReport} and {@link CacheWarmth}.
123
+ *
124
+ * Pure over what it is handed: the runtime passes each completed call's facts and
125
+ * the clock, marks the events it performed, and reads the two projections. Nothing
126
+ * here throws on ordinary data; the runtime wraps the calls in the observer latch
127
+ * anyway, so a surprise degrades to absence rather than to a dead turn. `/clear`'s
128
+ * successor runtime builds a new tracker, which is how the state stays session-scoped.
129
+ */
130
+ export class CacheMissTracker {
131
+ ttlMs;
132
+ previous = undefined;
133
+ events = new Set();
134
+ lastMiss = undefined;
135
+ misses = 0;
136
+ firstCallAfterResume;
137
+ /**
138
+ * @param ttlMs the live TTL, read per call because `promptCacheTtl` is a model
139
+ * field and `/model` can change it mid-session.
140
+ */
141
+ constructor(ttlMs, resumed) {
142
+ this.ttlMs = ttlMs;
143
+ this.firstCallAfterResume = resumed;
144
+ }
145
+ /** Records that the session performed one invalidating event since the last call. */
146
+ mark(event) {
147
+ this.events.add(event);
148
+ }
149
+ /** Folds one completed call in; returns the verdict for that call, if any. */
150
+ observe(call) {
151
+ const cause = cacheMissCause({
152
+ previous: this.previous,
153
+ current: call,
154
+ events: this.events,
155
+ ttlMs: this.ttlMs(),
156
+ firstCallAfterResume: this.firstCallAfterResume,
157
+ });
158
+ if (cause !== undefined && call.cacheRead !== undefined && call.requestInput !== undefined) {
159
+ this.misses += 1;
160
+ this.lastMiss = { cause, at: call.at, cacheRead: call.cacheRead, requestInput: call.requestInput };
161
+ }
162
+ // Every completed call closes the "since last call" window and settles the
163
+ // resume question, verdict or not: the events have had their effect on this
164
+ // request whether or not the counters let us see it.
165
+ this.previous = call;
166
+ this.events.clear();
167
+ this.firstCallAfterResume = false;
168
+ return cause;
169
+ }
170
+ report() {
171
+ return { lastMiss: this.lastMiss, misses: this.misses };
172
+ }
173
+ /** `undefined` until a call has completed. */
174
+ warmth(now) {
175
+ if (this.previous === undefined)
176
+ return undefined;
177
+ const lastCacheRead = this.previous.cacheRead ?? 0;
178
+ const ageMs = Math.max(0, now - this.previous.at);
179
+ return { warm: lastCacheRead > 0 && ageMs < this.ttlMs(), ageMs, lastCacheRead };
180
+ }
181
+ }
182
+ //# sourceMappingURL=cache-miss.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AS,EAAE,CAAC;YAC3F,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC;YACjB,IAAI,CAAC,QAAQ,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,YAAY,EAAE,IAAI,CAAC,YAAY,EAAE,CAAC;QACrG,CAAC;QACD,2EAA2E;QAC3E,4EAA4E;QAC5E,qDAAqD;QACrD,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QACpB,IAAI,CAAC,oBAAoB,GAAG,KAAK,CAAC;QAClC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM;QACJ,OAAO,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC;IAC1D,CAAC;IAED,8CAA8C;IAC9C,MAAM,CAAC,GAAW;QAChB,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS;YAAE,OAAO,SAAS,CAAC;QAClD,MAAM,aAAa,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,IAAI,CAAC,CAAC;QACnD,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QAClD,OAAO,EAAE,IAAI,EAAE,aAAa,GAAG,CAAC,IAAI,KAAK,GAAG,IAAI,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC;IACnF,CAAC;CACF"}
@@ -7,6 +7,7 @@
7
7
  */
8
8
  import type { Agent, Message, Model, SummarizingConversationManagerConfig } from '@strands-agents/sdk';
9
9
  import { SummarizingConversationManager } from '@strands-agents/sdk';
10
+ import type { ContextCompactedEntry } from '../trajectory/record.js';
10
11
  /**
11
12
  * `/compact` collapses every reducible old message in one command, leaving one
12
13
  * summary plus the recent window. 0.8 is the SDK's maximum ratio and minimizes
@@ -85,6 +86,33 @@ export interface CompactConversationOptions {
85
86
  * Both rules apply to focused and unfocused managers alike.
86
87
  */
87
88
  export declare function compactConversation({ agent, model, manager, preserveRecentMessages, persist, }: CompactConversationOptions): Promise<CompactResult>;
89
+ /**
90
+ * What a driver needs from the runtime to run one `/compact` and record it: the
91
+ * structural slice of `AgentRuntime` the TUI and headless drivers already hold.
92
+ * Typed structurally so `spike/verify-compact.ts` can prove the recording rules with
93
+ * a scripted host and a real recorder, without an `Agent`.
94
+ */
95
+ export interface CompactionHost {
96
+ contextEstimate(): Promise<{
97
+ estimatedTokens: number;
98
+ }>;
99
+ compact(focus?: string): Promise<CompactResult>;
100
+ recordContextCompacted(entry: ContextCompactedEntry): void;
101
+ }
102
+ /**
103
+ * Runs one `/compact` through the host and appends the SRF-027 `contextCompacted`
104
+ * trajectory record when — and only when — the result says `compacted: true`.
105
+ *
106
+ * The one place that composes the record, shared by both drivers so the TUI and
107
+ * `--compact-before` cannot describe the same compaction two ways. The pre-compaction
108
+ * estimate is the host's own `contextEstimate()` read **before** the compaction (the
109
+ * anchor it rests on drops with the rewritten history), taken best-effort: a failed or
110
+ * non-positive read is absence, never 0, and never a reason not to compact. A
111
+ * no-shrink pass records nothing; a failure records nothing and rethrows untouched.
112
+ * `focused` is whether a non-empty focus was given — the focus text stays with the
113
+ * summarizer request and is not handed to the recorder.
114
+ */
115
+ export declare function compactAndRecord(host: CompactionHost, focus?: string): Promise<CompactResult>;
88
116
  /**
89
117
  * Repairs user-role messages that carry `reasoningBlock` content in place.
90
118
  *
@@ -151,6 +151,40 @@ export async function compactConversation({ agent, model, manager, preserveRecen
151
151
  throw error;
152
152
  }
153
153
  }
154
+ /**
155
+ * Runs one `/compact` through the host and appends the SRF-027 `contextCompacted`
156
+ * trajectory record when — and only when — the result says `compacted: true`.
157
+ *
158
+ * The one place that composes the record, shared by both drivers so the TUI and
159
+ * `--compact-before` cannot describe the same compaction two ways. The pre-compaction
160
+ * estimate is the host's own `contextEstimate()` read **before** the compaction (the
161
+ * anchor it rests on drops with the rewritten history), taken best-effort: a failed or
162
+ * non-positive read is absence, never 0, and never a reason not to compact. A
163
+ * no-shrink pass records nothing; a failure records nothing and rethrows untouched.
164
+ * `focused` is whether a non-empty focus was given — the focus text stays with the
165
+ * summarizer request and is not handed to the recorder.
166
+ */
167
+ export async function compactAndRecord(host, focus) {
168
+ let estimatedTokensBefore;
169
+ try {
170
+ const estimate = await host.contextEstimate();
171
+ const tokens = estimate.estimatedTokens;
172
+ estimatedTokensBefore = Number.isFinite(tokens) && tokens > 0 ? Math.round(tokens) : undefined;
173
+ }
174
+ catch {
175
+ estimatedTokensBefore = undefined;
176
+ }
177
+ const result = await host.compact(focus);
178
+ if (result.compacted) {
179
+ host.recordContextCompacted({
180
+ messagesBefore: result.messagesBefore,
181
+ messagesAfter: result.messagesAfter,
182
+ ...(estimatedTokensBefore === undefined ? {} : { estimatedTokensBefore }),
183
+ focused: normalizeCompactFocus(focus) !== undefined,
184
+ });
185
+ }
186
+ return result;
187
+ }
154
188
  /**
155
189
  * Repairs user-role messages that carry `reasoningBlock` content in place.
156
190
  *
@@ -1 +1 @@
1
- {"version":3,"file":"compact.js","sourceRoot":"","sources":["../../../src/agent/compact.ts"],"names":[],"mappings":"AAQA,kFAAkF;AAClF,6EAA6E;AAC7E,6EAA6E;AAC7E,+EAA+E;AAC/E,qBAAqB;AACrB,OAAO,EAAE,4BAA4B,EAAE,8BAA8B,EAAE,MAAM,qBAAqB,CAAC;AAEnG;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,CAAC;AACzC,sFAAsF;AACtF,MAAM,CAAC,MAAM,6BAA6B,GAAG,GAAG,CAAC;AACjD;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,+DAA+D,CAAC;AAErG;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAwB;IAC5D,MAAM,OAAO,GAAG,IAA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AC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC;QAC3D,QAAQ,EAAE,CAAC;IACb,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,uBAAuB,CAAC,KAAY,EAAE,KAAY;IAChE,OAAO,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,QAAQ,EAAE;QACvC,GAAG,CAAC,KAAK,CAAC,YAAY,KAAK,SAAS,IAAI,EAAE,YAAY,EAAE,KAAK,CAAC,YAAY,EAAE,CAAC;QAC7E,SAAS,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC;KACpD,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,109 @@
1
+ /**
2
+ * The `/context` breakdown: what the next request is made of, component by component
3
+ * (SER-077).
4
+ *
5
+ * The total `/context` prints is one number — measured base plus a counted tail, or
6
+ * one whole-request count — and says nothing about *what* is large. This module
7
+ * counts the parts separately: the system prompt by section as Darwin composes it
8
+ * (base prompt, `<project-instructions>`, the official `<available_skills>`
9
+ * catalogue, `<working-context>`), the tool specs grouped by origin (darwin's own
10
+ * built-ins, then each MCP server by its configured name), and the conversation by
11
+ * role. Every component goes through the same `model.countTokens` the total already
12
+ * uses, so the parts are stated in the total's own units — but they are an
13
+ * *estimate over the current request shape*, never the anchor measurement, and the
14
+ * formatter labels them so. The measured total stays the authoritative line.
15
+ *
16
+ * Two rules from the rest of the runtime hold here. It is computed on demand only:
17
+ * `/context` asks for it, nothing else does — not the post-turn pressure advisory,
18
+ * not `/status` — because a provider-native `countTokens` may reach the provider's
19
+ * counting API and this makes several calls. And a component whose count fails is
20
+ * absent (`tokens: undefined`, rendered `not reported`), never 0: the `usageBuckets`
21
+ * honesty rule. Everything here is a pure function over injected inputs; the
22
+ * runtime supplies the live prompt, tools, servers, messages and the counter.
23
+ */
24
+ import type { CountTokensOptions, Message, SystemPrompt, ToolSpec } from '@strands-agents/sdk';
25
+ import type { McpServerStatus } from '../mcp/registry.js';
26
+ /** One counted component of the request. */
27
+ export interface ContextComponent {
28
+ /** Bounded label, rendered as written. */
29
+ label: string;
30
+ /** Estimated tokens; absent when the count failed — `not reported`, never 0. */
31
+ tokens: number | undefined;
32
+ /**
33
+ * A stated absence that is not a failed count — e.g. the skills catalogue before
34
+ * the plugin's first injection. Rendered instead of a count when present.
35
+ */
36
+ absent?: string;
37
+ }
38
+ /** The request, component by component. Row order is the rendering order. */
39
+ export interface ContextBreakdown {
40
+ /** System prompt sections in composition order. */
41
+ systemPrompt: ContextComponent[];
42
+ /** Darwin's own tools plus plugin tools — everything no MCP server registered. */
43
+ builtinTools: ContextComponent;
44
+ /** One row per configured MCP server, in configuration order; the formatter bounds them. */
45
+ mcpServers: ContextComponent[];
46
+ /** Conversation messages by role, whole messages only. */
47
+ conversation: ContextComponent[];
48
+ }
49
+ /** `model.countTokens`, injected so the runtime and an offline suite share one path. */
50
+ export type ComponentCounter = (messages: Message[], options: CountTokensOptions) => Promise<number>;
51
+ export interface BreakdownInputs {
52
+ /** The live `agent.systemPrompt`. */
53
+ systemPrompt: SystemPrompt | undefined;
54
+ /** The section strings the composition seam produced (`composeSystemPrompt`'s inputs). */
55
+ composed: {
56
+ base: string;
57
+ instructions: string | undefined;
58
+ };
59
+ /** The live `agent.tools`. */
60
+ tools: readonly {
61
+ name: string;
62
+ toolSpec: ToolSpec;
63
+ }[];
64
+ /** `mcpServerStatuses(...)` — names and registered tool names, never `listTools()`. */
65
+ servers: readonly McpServerStatus[];
66
+ /** The live `agent.messages`. */
67
+ messages: readonly Message[];
68
+ }
69
+ export declare const BASE_PROMPT_LABEL = "system prompt \u00B7 base";
70
+ export declare const PROJECT_INSTRUCTIONS_LABEL = "system prompt \u00B7 project instructions (AGENTS.md)";
71
+ /** A restored prompt whose base block no longer equals the current composition. */
72
+ export declare const RESTORED_PROMPT_LABEL = "system prompt \u00B7 base + project instructions (restored)";
73
+ /** A prompt array in a shape Darwin does not own: counted whole rather than guessed at. */
74
+ export declare const WHOLE_PROMPT_LABEL = "system prompt";
75
+ export declare const SKILLS_CATALOGUE_LABEL = "system prompt \u00B7 skills catalogue";
76
+ export declare const WORKING_CONTEXT_LABEL = "system prompt \u00B7 working context";
77
+ export declare const CATALOGUE_NOT_INJECTED = "not yet injected (added before the first model call)";
78
+ export declare const BUILTIN_TOOLS_LABEL = "tools \u00B7 darwin built-ins";
79
+ export declare const UNATTRIBUTED_TOOLS_LABEL = "tools \u00B7 darwin built-ins and unattributed";
80
+ export declare const MCP_TOOLS_LABEL_PREFIX = "tools \u00B7 mcp ";
81
+ export declare const USER_MESSAGES_LABEL = "conversation \u00B7 user prompts and tool results";
82
+ export declare const ASSISTANT_MESSAGES_LABEL = "conversation \u00B7 assistant replies and tool calls";
83
+ /**
84
+ * Counts every component with `countTokens`, one call per component, sequentially
85
+ * so a provider-backed counter is never fanned out. A failed count is recorded as
86
+ * absent and the rest are still counted: one gap costs one row, never the report.
87
+ */
88
+ export declare function measureContextBreakdown(inputs: BreakdownInputs, countTokens: ComponentCounter): Promise<ContextBreakdown>;
89
+ export interface ToolOriginGroups {
90
+ /** Names the built-in row honestly when a server's tool names could not be read. */
91
+ builtinLabel: string;
92
+ builtins: ToolSpec[];
93
+ /** `specs` is absent when the server's registered names are unavailable. */
94
+ servers: {
95
+ label: string;
96
+ specs: ToolSpec[] | undefined;
97
+ }[];
98
+ }
99
+ /**
100
+ * Attributes each live tool spec to the MCP server that registered it, by the
101
+ * names `mcpServerStatuses` already reads; whatever no server claims is darwin's
102
+ * own (built-ins, plugin tools, parent-only tools). A server whose names cannot be
103
+ * read gets a row with no specs — its tools then land in the built-in group, which
104
+ * says so in its label rather than passing them off as darwin's.
105
+ */
106
+ export declare function groupToolsByOrigin(tools: readonly {
107
+ name: string;
108
+ toolSpec: ToolSpec;
109
+ }[], servers: readonly McpServerStatus[]): ToolOriginGroups;
@@ -0,0 +1,116 @@
1
+ import { composeSystemPrompt } from './instructions.js';
2
+ import { knownPromptSections } from '../skills/prompt.js';
3
+ export const BASE_PROMPT_LABEL = 'system prompt · base';
4
+ export const PROJECT_INSTRUCTIONS_LABEL = 'system prompt · project instructions (AGENTS.md)';
5
+ /** A restored prompt whose base block no longer equals the current composition. */
6
+ export const RESTORED_PROMPT_LABEL = 'system prompt · base + project instructions (restored)';
7
+ /** A prompt array in a shape Darwin does not own: counted whole rather than guessed at. */
8
+ export const WHOLE_PROMPT_LABEL = 'system prompt';
9
+ export const SKILLS_CATALOGUE_LABEL = 'system prompt · skills catalogue';
10
+ export const WORKING_CONTEXT_LABEL = 'system prompt · working context';
11
+ export const CATALOGUE_NOT_INJECTED = 'not yet injected (added before the first model call)';
12
+ export const BUILTIN_TOOLS_LABEL = 'tools · darwin built-ins';
13
+ export const UNATTRIBUTED_TOOLS_LABEL = 'tools · darwin built-ins and unattributed';
14
+ export const MCP_TOOLS_LABEL_PREFIX = 'tools · mcp ';
15
+ export const USER_MESSAGES_LABEL = 'conversation · user prompts and tool results';
16
+ export const ASSISTANT_MESSAGES_LABEL = 'conversation · assistant replies and tool calls';
17
+ /**
18
+ * Counts every component with `countTokens`, one call per component, sequentially
19
+ * so a provider-backed counter is never fanned out. A failed count is recorded as
20
+ * absent and the rest are still counted: one gap costs one row, never the report.
21
+ */
22
+ export async function measureContextBreakdown(inputs, countTokens) {
23
+ const count = async (label, messages, options) => {
24
+ try {
25
+ return { label, tokens: await countTokens(messages, options) };
26
+ }
27
+ catch {
28
+ return { label, tokens: undefined };
29
+ }
30
+ };
31
+ const systemPrompt = [];
32
+ const sections = knownPromptSections(inputs.systemPrompt);
33
+ if (sections === undefined) {
34
+ if (inputs.systemPrompt !== undefined) {
35
+ systemPrompt.push(await count(WHOLE_PROMPT_LABEL, [], { systemPrompt: inputs.systemPrompt }));
36
+ }
37
+ }
38
+ else {
39
+ const composed = composeSystemPrompt(inputs.composed.base, inputs.composed.instructions === undefined
40
+ ? undefined
41
+ : { fragment: inputs.composed.instructions });
42
+ if (sections.base === composed.trimEnd()) {
43
+ // The live block is exactly what this run composed, so the seam strings are
44
+ // its sections and can be counted apart.
45
+ systemPrompt.push(await count(BASE_PROMPT_LABEL, [], { systemPrompt: inputs.composed.base }));
46
+ if (inputs.composed.instructions !== undefined) {
47
+ systemPrompt.push(await count(PROJECT_INSTRUCTIONS_LABEL, [], { systemPrompt: inputs.composed.instructions }));
48
+ }
49
+ }
50
+ else {
51
+ // A resumed session carries the snapshot's prompt, which may predate an
52
+ // AGENTS.md edit: the split is unknowable, so the block is counted whole.
53
+ systemPrompt.push(await count(RESTORED_PROMPT_LABEL, [], { systemPrompt: sections.base }));
54
+ }
55
+ systemPrompt.push(sections.catalogue === undefined
56
+ ? { label: SKILLS_CATALOGUE_LABEL, tokens: undefined, absent: CATALOGUE_NOT_INJECTED }
57
+ : await count(SKILLS_CATALOGUE_LABEL, [], { systemPrompt: sections.catalogue }));
58
+ if (sections.workingContext !== undefined) {
59
+ systemPrompt.push(await count(WORKING_CONTEXT_LABEL, [], { systemPrompt: sections.workingContext }));
60
+ }
61
+ }
62
+ const groups = groupToolsByOrigin(inputs.tools, inputs.servers);
63
+ const builtinTools = await count(groups.builtinLabel, [], { toolSpecs: groups.builtins });
64
+ const mcpServers = [];
65
+ for (const server of groups.servers) {
66
+ mcpServers.push(server.specs === undefined
67
+ ? { label: server.label, tokens: undefined }
68
+ : await count(server.label, [], { toolSpecs: server.specs }));
69
+ }
70
+ const byRole = (role) => inputs.messages.filter((message) => message.role === role);
71
+ const conversation = [
72
+ await count(USER_MESSAGES_LABEL, byRole('user'), {}),
73
+ await count(ASSISTANT_MESSAGES_LABEL, byRole('assistant'), {}),
74
+ ];
75
+ return { systemPrompt, builtinTools, mcpServers, conversation };
76
+ }
77
+ /**
78
+ * Attributes each live tool spec to the MCP server that registered it, by the
79
+ * names `mcpServerStatuses` already reads; whatever no server claims is darwin's
80
+ * own (built-ins, plugin tools, parent-only tools). A server whose names cannot be
81
+ * read gets a row with no specs — its tools then land in the built-in group, which
82
+ * says so in its label rather than passing them off as darwin's.
83
+ */
84
+ export function groupToolsByOrigin(tools, servers) {
85
+ const owner = new Map();
86
+ let unattributed = false;
87
+ for (const server of servers) {
88
+ if (server.toolNames === undefined) {
89
+ unattributed = true;
90
+ continue;
91
+ }
92
+ for (const name of server.toolNames)
93
+ owner.set(name, server.name);
94
+ }
95
+ const perServer = new Map();
96
+ const builtins = [];
97
+ for (const tool of tools) {
98
+ const server = owner.get(tool.name);
99
+ if (server === undefined) {
100
+ builtins.push(tool.toolSpec);
101
+ continue;
102
+ }
103
+ const specs = perServer.get(server) ?? [];
104
+ specs.push(tool.toolSpec);
105
+ perServer.set(server, specs);
106
+ }
107
+ return {
108
+ builtinLabel: unattributed ? UNATTRIBUTED_TOOLS_LABEL : BUILTIN_TOOLS_LABEL,
109
+ builtins,
110
+ servers: servers.map((server) => ({
111
+ label: `${MCP_TOOLS_LABEL_PREFIX}${server.name}`,
112
+ specs: server.toolNames === undefined ? undefined : perServer.get(server.name) ?? [],
113
+ })),
114
+ };
115
+ }
116
+ //# sourceMappingURL=context-breakdown.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-breakdown.js","sourceRoot":"","sources":["../../../src/agent/context-breakdown.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AA2C1D,MAAM,CAAC,MAAM,iBAAiB,GAAG,sBAAsB,CAAC;AACxD,MAAM,CAAC,MAAM,0BAA0B,GAAG,kDAAkD,CAAC;AAC7F,mFAAmF;AACnF,MAAM,CAAC,MAAM,qBAAqB,GAAG,wDAAwD,CAAC;AAC9F,2FAA2F;AAC3F,MAAM,CAAC,MAAM,kBAAkB,GAAG,eAAe,CAAC;AAClD,MAAM,CAAC,MAAM,sBAAsB,GAAG,kCAAkC,CAAC;AACzE,MAAM,CAAC,MAAM,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S,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE;SACrF,CAAC,CAAC;KACJ,CAAC;AACJ,CAAC"}
@@ -51,4 +51,4 @@ export declare function loadProjectInstructions(projectRoot: string): Promise<Pr
51
51
  * describe how to work in this repository; the skills list is a menu and reads
52
52
  * better last, and the working context is not rules at all.
53
53
  */
54
- export declare function composeSystemPrompt(basePrompt: string, instructions: ProjectInstructions | undefined): string;
54
+ export declare function composeSystemPrompt(basePrompt: string, instructions: Pick<ProjectInstructions, 'fragment'> | undefined): string;
@@ -1 +1 @@
1
- {"version":3,"file":"instructions.js","sourceRoot":"","sources":["../../../src/agent/instructions.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,MAAM,CAAC,MAAM,eAAe,GAAG,WAAW,CAAC;AAE3C;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,EAAE,GAAG,IAAI,CAAC;AA0BhD;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,WAAmB;IAEnB,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,eAAe,CAAC,CAAC;IAEzD,IAAI,GAAW,CAAC;IAChB,IAAI,CAAC;QACH,GAAG,GAAG,MAAM,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACjC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,OAAO,EAAE,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;IAClG,CAAC;IAED,MAAM,KAAK,GAAG,GAAG,CAAC,UAAU,C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