@ouro.bot/cli 0.1.0-alpha.1166 → 0.1.0-alpha.1168

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.json CHANGED
@@ -1,6 +1,18 @@
1
1
  {
2
2
  "_note": "This changelog is maintained as part of the PR/version-bump workflow. Agent-curated, not auto-generated. Agents read this file directly via read_file to understand what changed between versions.",
3
3
  "versions": [
4
+ {
5
+ "version": "0.1.0-alpha.1168",
6
+ "changes": [
7
+ "An agent's context window is read from the provider's own model listing (GitHub Copilot's capabilities.limits.max_context_window_tokens) once per model and cached. The built-in 200k/400k estimates apply only when that read fails, and the log says so (engine.context_window_fallback)."
8
+ ]
9
+ },
10
+ {
11
+ "version": "0.1.0-alpha.1167",
12
+ "changes": [
13
+ "An agent's context window now follows its model's real limit (200k for Claude, 400k for GPT) unless agent.json sets context.maxTokens to something other than the old 80000 default; new agents no longer get maxTokens written. scripts/measure-prompt.cjs counts the system prompt and tool schemas per channel, with no model calls."
14
+ ]
15
+ },
4
16
  {
5
17
  "version": "0.1.0-alpha.1166",
6
18
  "changes": [
@@ -1,5 +1,5 @@
1
1
  {
2
- "runtimeVersion": "0.1.0-alpha.1166",
2
+ "runtimeVersion": "0.1.0-alpha.1168",
3
3
  "bundleSchemaVersion": 3,
4
4
  "lastUpdated": "2026-09-03T00:00:00.000Z"
5
5
  }
@@ -1,7 +1,7 @@
1
1
  <?xml version="1.0"?>
2
2
  <Container version="2">
3
3
  <Name>ouro-butler</Name>
4
- <Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.1166</Repository>
4
+ <Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.1168</Repository>
5
5
  <Registry>https://github.com/ourostack/ouroboros/pkgs/container/ouroboros-butler</Registry>
6
6
  <Network>host</Network>
7
7
  <Shell>sh</Shell>
@@ -149,9 +149,9 @@ const registryData = [
149
149
  {
150
150
  path: "context.maxTokens",
151
151
  tier: "self",
152
- description: "Maximum context window size in tokens.",
152
+ description: "Override for the context window size in tokens. Unset, it follows the configured model's real window.",
153
153
  default: 80000,
154
- effects: "Larger values allow more context but increase cost and latency. Must match model capability.",
154
+ effects: "Larger values allow more context but increase cost and latency. Must not exceed the model's window. 80000 applies only to a model whose window is unknown.",
155
155
  topics: ["context", "tokens", "notes", "performance"],
156
156
  validate: validateInteger(1000, 1000000),
157
157
  },
@@ -66,6 +66,8 @@ exports.sessionPath = sessionPath;
66
66
  exports.logPath = logPath;
67
67
  const fs = __importStar(require("fs"));
68
68
  const path = __importStar(require("path"));
69
+ const model_limits_1 = require("./model-limits");
70
+ const model_capabilities_1 = require("./model-capabilities");
69
71
  const identity_1 = require("./identity");
70
72
  const provider_credentials_1 = require("./provider-credentials");
71
73
  const runtime_credentials_1 = require("./runtime-credentials");
@@ -271,20 +273,24 @@ function getTeamsSecondaryConfig() {
271
273
  const config = loadConfig();
272
274
  return { ...config.teamsSecondary };
273
275
  }
274
- function getContextConfig() {
276
+ /**
277
+ * The context window follows the model: an agent.json `context.maxTokens` that differs from the old hatch-time
278
+ * default is an explicit override; otherwise the model's real window applies, and the default only when it is unknown.
279
+ */
280
+ function getContextConfig(model) {
275
281
  if (_testContextOverride) {
276
282
  return { ..._testContextOverride };
277
283
  }
278
284
  const defaults = identity_1.DEFAULT_AGENT_CONTEXT;
279
- const agentContext = (0, identity_1.loadAgentConfig)().context;
280
- if (!agentContext || typeof agentContext !== "object") {
281
- return { ...defaults };
282
- }
285
+ const agentConfig = (0, identity_1.loadAgentConfig)();
286
+ const agentContext = agentConfig.context;
287
+ const override = typeof agentContext?.maxTokens === "number" && agentContext.maxTokens !== defaults.maxTokens
288
+ ? agentContext.maxTokens
289
+ : undefined;
290
+ const modelId = model ?? agentConfig.humanFacing?.model;
283
291
  return {
284
- maxTokens: typeof agentContext.maxTokens === "number" ? agentContext.maxTokens : defaults.maxTokens,
285
- contextMargin: typeof agentContext.contextMargin === "number"
286
- ? agentContext.contextMargin
287
- : defaults.contextMargin,
292
+ maxTokens: override ?? (modelId ? (0, model_limits_1.getLearnedContextWindow)(modelId) ?? (0, model_capabilities_1.getModelCapabilities)(modelId).contextWindowTokens : undefined) ?? defaults.maxTokens,
293
+ contextMargin: typeof agentContext?.contextMargin === "number" ? agentContext.contextMargin : defaults.contextMargin,
288
294
  };
289
295
  }
290
296
  function getOAuthConfig() {
@@ -23,6 +23,7 @@ exports.dropReplayedReasoning = dropReplayedReasoning;
23
23
  exports.runAgent = runAgent;
24
24
  const config_1 = require("./config");
25
25
  const identity_1 = require("./identity");
26
+ const model_limits_1 = require("./model-limits");
26
27
  const source_grounding_1 = require("./source-grounding");
27
28
  const shelf_claims_1 = require("./shelf-claims");
28
29
  const reply_style_1 = require("./reply-style");
@@ -188,6 +189,7 @@ async function getProviderRuntime(facing = "human", owner) {
188
189
  console.error(`\n[fatal] ${msg}\n`);
189
190
  throw new Error(msg);
190
191
  }
192
+ await (0, model_limits_1.learnContextWindow)(runtime);
191
193
  // The shared tool loop supplies approval continuation to every provider adapter.
192
194
  return { ...runtime, capabilities: new Set([...runtime.capabilities, "approval-continuation"]) };
193
195
  }
@@ -202,6 +204,7 @@ async function getChainEntryRuntime(entry, owner) {
202
204
  /* v8 ignore next -- defensive: the registry resolves every provider id @preserve */
203
205
  if (!runtime)
204
206
  throw new Error(`${entry.provider} (${entry.model}) runtime could not be initialized.`);
207
+ await (0, model_limits_1.learnContextWindow)(runtime);
205
208
  return { ...runtime, capabilities: new Set([...runtime.capabilities, "approval-continuation"]) };
206
209
  }
207
210
  // Called after getProviderRuntime has loaded the same agent.json, so a bad config has already failed the turn.
@@ -1171,7 +1174,7 @@ async function runAgent(messages, callbacks, channel, signal, options) {
1171
1174
  requiredPromptEvidence: options.requiredPromptEvidence,
1172
1175
  provider: providerRuntime.id,
1173
1176
  model: providerRuntime.model,
1174
- contextWindowTokens: (0, config_1.getContextConfig)().maxTokens,
1177
+ contextWindowTokens: (0, config_1.getContextConfig)(providerRuntime.model).maxTokens,
1175
1178
  });
1176
1179
  }
1177
1180
  catch (error) {
@@ -1594,7 +1597,7 @@ async function runAgent(messages, callbacks, channel, signal, options) {
1594
1597
  requiredPromptEvidence: options?.requiredPromptEvidence,
1595
1598
  provider: providerRuntime.id,
1596
1599
  model: providerRuntime.model,
1597
- contextWindowTokens: (0, config_1.getContextConfig)().maxTokens,
1600
+ contextWindowTokens: (0, config_1.getContextConfig)(providerRuntime.model).maxTokens,
1598
1601
  };
1599
1602
  const canonicalBudget = (0, prompt_budget_1.applyPromptBudget)({ ...budgetOptions, messages });
1600
1603
  const currentUserMessage = budgetOptions.requiredPromptEvidence?.currentUserMessage
@@ -1658,7 +1661,7 @@ async function runAgent(messages, callbacks, channel, signal, options) {
1658
1661
  const overflowMessages = attemptMessages.slice(0, protectedStart).map((message) => message.role === "assistant" ? { ...message } : message);
1659
1662
  stripLastToolCalls(overflowMessages);
1660
1663
  overflowMessages.push(...currentAttempt);
1661
- const { maxTokens, contextMargin } = (0, config_1.getContextConfig)();
1664
+ const { maxTokens, contextMargin } = (0, config_1.getContextConfig)(providerRuntime.model);
1662
1665
  const trimmed = (0, context_1.trimMessages)(overflowMessages, maxTokens, contextMargin, maxTokens * 2);
1663
1666
  const requiredEvidence = options?.requiredPromptEvidence;
1664
1667
  const requiredMessages = new Set([
@@ -81,6 +81,7 @@ exports.PROVIDER_CREDENTIALS = {
81
81
  "openai-compatible-gemini": { required: ["apiKey", "baseUrl"], envVars: {}, promptLabels: { apiKey: "Gemini API key", baseUrl: "Gemini canonical base URL" } },
82
82
  };
83
83
  exports.SHEPHERD_NOTICE_POLICIES = ["every", "needs-me", "off"];
84
+ /** maxTokens is only the fallback for a model whose window is unknown; known models carry their own. */
84
85
  exports.DEFAULT_AGENT_CONTEXT = {
85
86
  maxTokens: 80000,
86
87
  contextMargin: 20,
@@ -357,7 +358,7 @@ function buildDefaultAgentTemplate(_agentName) {
357
358
  enabled: true,
358
359
  humanFacing: { provider: "anthropic", model: "claude-opus-5-5" },
359
360
  agentFacing: { provider: "anthropic", model: "claude-opus-5-5" },
360
- context: { ...exports.DEFAULT_AGENT_CONTEXT },
361
+ context: { contextMargin: exports.DEFAULT_AGENT_CONTEXT.contextMargin },
361
362
  habitPaidTurnsPerDay: autonomy_budget_1.DEFAULT_HABIT_PAID_TURNS_PER_DAY,
362
363
  senses: {
363
364
  cli: { ...exports.DEFAULT_AGENT_SENSES.cli },
@@ -9,88 +9,103 @@ exports.MODEL_CAPABILITIES = {
9
9
  "claude-opus-5.5": {
10
10
  reasoningEffort: ["low", "medium", "high", "xhigh", "max"],
11
11
  maxOutputTokens: 128000,
12
+ contextWindowTokens: 200000,
12
13
  vision: true,
13
14
  },
14
15
  "claude-sonnet-5.5": {
15
16
  reasoningEffort: ["low", "medium", "high", "xhigh", "max"],
16
17
  maxOutputTokens: 128000,
18
+ contextWindowTokens: 200000,
17
19
  vision: true,
18
20
  },
19
21
  "claude-haiku-5.5": {
20
22
  reasoningEffort: ["low", "medium", "high", "xhigh", "max"],
21
23
  maxOutputTokens: 128000,
24
+ contextWindowTokens: 200000,
22
25
  vision: true,
23
26
  },
24
27
  "claude-opus-5-5": {
25
28
  reasoningEffort: ["low", "medium", "high", "xhigh", "max"],
26
29
  thinkingFormat: "anthropic",
27
30
  maxOutputTokens: 128000,
31
+ contextWindowTokens: 200000,
28
32
  vision: true,
29
33
  },
30
34
  "claude-sonnet-5-5": {
31
35
  reasoningEffort: ["low", "medium", "high", "xhigh", "max"],
32
36
  thinkingFormat: "anthropic",
33
37
  maxOutputTokens: 128000,
38
+ contextWindowTokens: 200000,
34
39
  vision: true,
35
40
  },
36
41
  "claude-haiku-5-5": {
37
42
  reasoningEffort: ["low", "medium", "high", "xhigh", "max"],
38
43
  thinkingFormat: "anthropic",
39
44
  maxOutputTokens: 128000,
45
+ contextWindowTokens: 200000,
40
46
  vision: true,
41
47
  },
42
48
  "gpt-6.1-sol": {
43
49
  reasoningEffort: ["none", "low", "medium", "high", "xhigh", "max"],
44
50
  phase: true,
45
51
  maxOutputTokens: 128000,
52
+ contextWindowTokens: 400000,
46
53
  vision: true,
47
54
  },
48
55
  "gpt-6-sol": {
49
56
  reasoningEffort: ["none", "low", "medium", "high", "xhigh", "max"],
50
57
  phase: true,
51
58
  maxOutputTokens: 128000,
59
+ contextWindowTokens: 400000,
52
60
  vision: true,
53
61
  },
54
62
  "gpt-6-luna": {
55
63
  reasoningEffort: ["none", "low", "medium", "high", "xhigh", "max"],
56
64
  phase: true,
57
65
  maxOutputTokens: 128000,
66
+ contextWindowTokens: 400000,
58
67
  vision: true,
59
68
  },
60
69
  "gpt-6-astra": {
61
70
  reasoningEffort: ["low", "medium", "high", "xhigh", "max"],
62
71
  phase: true,
63
72
  maxOutputTokens: 128000,
73
+ contextWindowTokens: 400000,
64
74
  vision: true,
65
75
  },
66
76
  "gpt-5.6-sol": {
67
77
  reasoningEffort: ["none", "low", "medium", "high", "xhigh", "max"],
68
78
  phase: true,
69
79
  maxOutputTokens: 128000,
80
+ contextWindowTokens: 400000,
70
81
  vision: true,
71
82
  },
72
83
  "gpt-5.6-sol-fast": {
73
84
  reasoningEffort: ["none", "low", "medium", "high", "xhigh", "max"],
74
85
  phase: true,
75
86
  maxOutputTokens: 128000,
87
+ contextWindowTokens: 400000,
76
88
  vision: true,
77
89
  },
78
90
  "gpt-5.6-luna": {
79
91
  reasoningEffort: ["none", "low", "medium", "high", "xhigh", "max"],
80
92
  phase: true,
81
93
  maxOutputTokens: 128000,
94
+ contextWindowTokens: 400000,
82
95
  vision: true,
83
96
  },
84
97
  "gpt-5.6-terra": {
85
98
  reasoningEffort: ["none", "low", "medium", "high", "xhigh", "max"],
86
99
  phase: true,
87
100
  maxOutputTokens: 128000,
101
+ contextWindowTokens: 400000,
88
102
  vision: true,
89
103
  },
90
104
  "gpt-5.5": {
91
105
  reasoningEffort: ["none", "low", "medium", "high", "xhigh"],
92
106
  phase: true,
93
107
  maxOutputTokens: 128000,
108
+ contextWindowTokens: 400000,
94
109
  vision: true,
95
110
  },
96
111
  "MiniMax-Text-01": {
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getLearnedContextWindow = getLearnedContextWindow;
4
+ exports.learnContextWindow = learnContextWindow;
5
+ exports.resetLearnedContextWindowsForTests = resetLearnedContextWindowsForTests;
6
+ const runtime_1 = require("../nerves/runtime");
7
+ const learned = new Map();
8
+ const attempted = new Set();
9
+ /** The context window a provider reported for this model, once learned. */
10
+ function getLearnedContextWindow(model) {
11
+ return learned.get(model);
12
+ }
13
+ /**
14
+ * Ask the provider once per model for its real context window and remember it. A provider that cannot say, or a failed
15
+ * read, leaves the static table in model-capabilities.ts as the fallback, and says so in the log.
16
+ */
17
+ async function learnContextWindow(runtime) {
18
+ const key = runtime.model;
19
+ if (learned.has(key) || attempted.has(key))
20
+ return;
21
+ attempted.add(key);
22
+ if (!runtime.fetchContextWindow)
23
+ return;
24
+ try {
25
+ const tokens = await runtime.fetchContextWindow(AbortSignal.timeout(5000));
26
+ if (tokens === undefined)
27
+ throw new Error("the provider's model list has no context window for this model");
28
+ learned.set(key, tokens);
29
+ (0, runtime_1.emitNervesEvent)({
30
+ component: "engine",
31
+ event: "engine.context_window_learned",
32
+ message: "context window read from the provider",
33
+ meta: { provider: runtime.id, model: key, tokens },
34
+ });
35
+ }
36
+ catch (error) {
37
+ (0, runtime_1.emitNervesEvent)({
38
+ level: "warn",
39
+ component: "engine",
40
+ event: "engine.context_window_fallback",
41
+ message: "context window read failed; using the built-in estimate for this model",
42
+ meta: { provider: runtime.id, model: key, reason: error instanceof Error ? error.message : String(error) },
43
+ });
44
+ }
45
+ }
46
+ function resetLearnedContextWindowsForTests() {
47
+ learned.clear();
48
+ attempted.clear();
49
+ }
@@ -38,6 +38,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.classifyGithubCopilotError = classifyGithubCopilotError;
40
40
  exports.withCopilotVisionHeader = withCopilotVisionHeader;
41
+ exports.contextWindowFromModels = contextWindowFromModels;
41
42
  exports.createGithubCopilotPooledCaller = createGithubCopilotPooledCaller;
42
43
  exports.createGithubCopilotProviderRuntime = createGithubCopilotProviderRuntime;
43
44
  const openai_1 = __importDefault(require("openai"));
@@ -67,6 +68,12 @@ function withCopilotVisionHeader(fetchImpl) {
67
68
  return send(input, { ...init, headers });
68
69
  };
69
70
  }
71
+ /** Pull one model's context window out of Copilot's /models listing (`capabilities.limits.max_context_window_tokens`). */
72
+ function contextWindowFromModels(models, modelId) {
73
+ const entry = models.find((m) => m?.id === modelId);
74
+ const tokens = entry?.capabilities?.limits?.max_context_window_tokens;
75
+ return typeof tokens === "number" && Number.isFinite(tokens) && tokens > 0 ? Math.floor(tokens) : undefined;
76
+ }
70
77
  /**
71
78
  * The agent's account pool for this turn, when `ouro auth` discovered one; null for a single account.
72
79
  * Without an owning agent (a daemon-side ping, provider discovery) the pool still switches on a 402 or 429,
@@ -161,6 +168,12 @@ function createGithubCopilotProviderRuntime(model, config = (0, config_1.getGith
161
168
  }
162
169
  },
163
170
  /* v8 ignore stop */
171
+ /* v8 ignore start -- network read: the parsing is tested via contextWindowFromModels @preserve */
172
+ async fetchContextWindow(signal) {
173
+ const page = await callModel(this.client, (turnClient) => turnClient.models.list({ signal }));
174
+ return contextWindowFromModels(page.data, this.model);
175
+ },
176
+ /* v8 ignore stop */
164
177
  /* v8 ignore start -- ping: tested via provider-ping.test.ts @preserve */
165
178
  async ping(signal) {
166
179
  await callModel(this.client, (turnClient) => turnClient.chat.completions.create({ model: this.model, max_tokens: 1, messages: [{ role: "user", content: "ping" }] }, { signal }));
@@ -220,6 +233,12 @@ function createGithubCopilotProviderRuntime(model, config = (0, config_1.getGith
220
233
  }
221
234
  },
222
235
  /* v8 ignore stop */
236
+ /* v8 ignore start -- network read: the parsing is tested via contextWindowFromModels @preserve */
237
+ async fetchContextWindow(signal) {
238
+ const page = await callModel(this.client, (turnClient) => turnClient.models.list({ signal }));
239
+ return contextWindowFromModels(page.data, this.model);
240
+ },
241
+ /* v8 ignore stop */
223
242
  /* v8 ignore start -- ping: tested via provider-ping.test.ts @preserve */
224
243
  async ping(signal) {
225
244
  await callModel(this.client, (turnClient) => turnClient.responses.create({ model: this.model, input: "ping", max_output_tokens: 16 }, { signal }));
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@ouro.bot/cli",
3
- "version": "0.1.0-alpha.1166",
3
+ "version": "0.1.0-alpha.1168",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@ouro.bot/cli",
9
- "version": "0.1.0-alpha.1166",
9
+ "version": "0.1.0-alpha.1168",
10
10
  "bundleDependencies": [
11
11
  "@ouro.bot/friends"
12
12
  ],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ouro.bot/cli",
3
- "version": "0.1.0-alpha.1166",
3
+ "version": "0.1.0-alpha.1168",
4
4
  "engines": {
5
5
  "node": ">=22"
6
6
  },