@namzu/sdk 67.0.0 → 68.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/pricing/catalogue.generated.d.ts.map +1 -1
  3. package/dist/pricing/catalogue.generated.js +6 -0
  4. package/dist/pricing/catalogue.generated.js.map +1 -1
  5. package/dist/provider/fallback.d.ts.map +1 -1
  6. package/dist/provider/fallback.js +12 -0
  7. package/dist/provider/fallback.js.map +1 -1
  8. package/dist/provider/idle-timeout.d.ts.map +1 -1
  9. package/dist/provider/idle-timeout.js +5 -0
  10. package/dist/provider/idle-timeout.js.map +1 -1
  11. package/dist/provider/model-window-suffix.d.ts.map +1 -1
  12. package/dist/provider/model-window-suffix.js +1 -0
  13. package/dist/provider/model-window-suffix.js.map +1 -1
  14. package/dist/provider/retry.d.ts.map +1 -1
  15. package/dist/provider/retry.js +5 -0
  16. package/dist/provider/retry.js.map +1 -1
  17. package/dist/public-runtime.d.ts +2 -2
  18. package/dist/public-runtime.d.ts.map +1 -1
  19. package/dist/public-runtime.js +2 -2
  20. package/dist/public-runtime.js.map +1 -1
  21. package/dist/public-types.d.ts +3 -3
  22. package/dist/public-types.d.ts.map +1 -1
  23. package/dist/registry/command/kernel-commands.d.ts +11 -1
  24. package/dist/registry/command/kernel-commands.d.ts.map +1 -1
  25. package/dist/registry/command/kernel-commands.js +114 -46
  26. package/dist/registry/command/kernel-commands.js.map +1 -1
  27. package/dist/runtime/query/iteration/index.d.ts +1 -1
  28. package/dist/runtime/query/iteration/index.d.ts.map +1 -1
  29. package/dist/runtime/query/iteration/index.js +3 -3
  30. package/dist/runtime/query/iteration/index.js.map +1 -1
  31. package/dist/store/goal/index.d.ts +53 -3
  32. package/dist/store/goal/index.d.ts.map +1 -1
  33. package/dist/store/goal/index.js +245 -9
  34. package/dist/store/goal/index.js.map +1 -1
  35. package/dist/tools/builtins/browser.js +1 -1
  36. package/dist/tools/builtins/browser.js.map +1 -1
  37. package/dist/tools/goal/confirmation.d.ts +82 -1
  38. package/dist/tools/goal/confirmation.d.ts.map +1 -1
  39. package/dist/tools/goal/confirmation.js +153 -3
  40. package/dist/tools/goal/confirmation.js.map +1 -1
  41. package/dist/tools/goal/index.d.ts.map +1 -1
  42. package/dist/tools/goal/index.js +34 -3
  43. package/dist/tools/goal/index.js.map +1 -1
  44. package/dist/types/command/index.d.ts +26 -2
  45. package/dist/types/command/index.d.ts.map +1 -1
  46. package/dist/types/command/index.js +5 -2
  47. package/dist/types/command/index.js.map +1 -1
  48. package/dist/types/common/index.d.ts +4 -2
  49. package/dist/types/common/index.d.ts.map +1 -1
  50. package/dist/types/common/index.js.map +1 -1
  51. package/dist/types/goal/index.d.ts +59 -0
  52. package/dist/types/goal/index.d.ts.map +1 -1
  53. package/dist/types/provider/chat.d.ts +10 -5
  54. package/dist/types/provider/chat.d.ts.map +1 -1
  55. package/dist/types/provider/interface.d.ts +7 -0
  56. package/dist/types/provider/interface.d.ts.map +1 -1
  57. package/dist/types/provider/model.d.ts +5 -0
  58. package/dist/types/provider/model.d.ts.map +1 -1
  59. package/dist/types/session/config.d.ts +2 -2
  60. package/dist/types/session/outcome.d.ts +5 -2
  61. package/dist/types/session/outcome.d.ts.map +1 -1
  62. package/dist/types/session/outcome.js.map +1 -1
  63. package/dist/utils/cost.d.ts +1 -1
  64. package/dist/utils/cost.d.ts.map +1 -1
  65. package/dist/utils/cost.js +14 -5
  66. package/dist/utils/cost.js.map +1 -1
  67. package/package.json +1 -1
  68. package/src/pricing/catalogue.generated.ts +6 -0
  69. package/src/pricing/rates.source.json +13 -7
  70. package/src/provider/fallback.ts +11 -0
  71. package/src/provider/idle-timeout.ts +5 -0
  72. package/src/provider/model-window-suffix.ts +1 -0
  73. package/src/provider/retry.ts +5 -0
  74. package/src/public-runtime.ts +9 -0
  75. package/src/public-types.ts +7 -0
  76. package/src/registry/command/kernel-commands.ts +136 -49
  77. package/src/runtime/query/iteration/index.ts +9 -6
  78. package/src/store/goal/index.ts +320 -21
  79. package/src/tools/builtins/browser.ts +1 -1
  80. package/src/tools/goal/confirmation.ts +227 -3
  81. package/src/tools/goal/index.ts +40 -4
  82. package/src/types/command/index.ts +27 -2
  83. package/src/types/common/index.ts +4 -2
  84. package/src/types/goal/index.ts +61 -0
  85. package/src/types/provider/chat.ts +10 -5
  86. package/src/types/provider/interface.ts +8 -0
  87. package/src/types/provider/model.ts +5 -0
  88. package/src/types/session/config.ts +2 -2
  89. package/src/types/session/outcome.ts +3 -1
  90. package/src/utils/cost.ts +15 -6
@@ -309,6 +309,7 @@ export const VENDOR_RATES: readonly VendorRates[] = [
309
309
  inputCostPer1M: 2.5,
310
310
  outputCostPer1M: 15,
311
311
  cache: { promptIncludesCacheReads: true, readCostPer1M: 0.25 },
312
+ fastMultiplier: 2,
312
313
  },
313
314
  ],
314
315
  [
@@ -317,6 +318,7 @@ export const VENDOR_RATES: readonly VendorRates[] = [
317
318
  inputCostPer1M: 0.75,
318
319
  outputCostPer1M: 4.5,
319
320
  cache: { promptIncludesCacheReads: true, readCostPer1M: 0.075 },
321
+ fastMultiplier: 2,
320
322
  },
321
323
  ],
322
324
  [
@@ -333,6 +335,7 @@ export const VENDOR_RATES: readonly VendorRates[] = [
333
335
  inputCostPer1M: 5,
334
336
  outputCostPer1M: 30,
335
337
  cache: { promptIncludesCacheReads: true, readCostPer1M: 0.5 },
338
+ fastMultiplier: 2.5,
336
339
  },
337
340
  ],
338
341
  [
@@ -341,6 +344,7 @@ export const VENDOR_RATES: readonly VendorRates[] = [
341
344
  inputCostPer1M: 0.2,
342
345
  outputCostPer1M: 1.2,
343
346
  cache: { promptIncludesCacheReads: true, readCostPer1M: 0.02 },
347
+ fastMultiplier: 2,
344
348
  },
345
349
  ],
346
350
  [
@@ -349,6 +353,7 @@ export const VENDOR_RATES: readonly VendorRates[] = [
349
353
  inputCostPer1M: 5,
350
354
  outputCostPer1M: 30,
351
355
  cache: { promptIncludesCacheReads: true, readCostPer1M: 0.5 },
356
+ fastMultiplier: 2,
352
357
  },
353
358
  ],
354
359
  [
@@ -357,6 +362,7 @@ export const VENDOR_RATES: readonly VendorRates[] = [
357
362
  inputCostPer1M: 2,
358
363
  outputCostPer1M: 12,
359
364
  cache: { promptIncludesCacheReads: true, readCostPer1M: 0.2 },
365
+ fastMultiplier: 2,
360
366
  },
361
367
  ],
362
368
  [
@@ -219,43 +219,49 @@
219
219
  "verified": "2026-08-10",
220
220
  "promptIncludesCacheReads": true,
221
221
  "reportsCacheWrites": false,
222
- "note": "Vendor list prices for text models, cached-input rate included. The driver hard-codes cacheWriteTokens to zero, so no write rate is carried. Embedding models are omitted (no output rate, and a chat turn never reaches one), as are models whose cached-input rate was not published alongside the others — an unestablished rate is left out rather than approximated, which is the rule this whole file follows. gpt-6-astra has no row on purpose: the vendor prices it by input length (read 2026-11-11 on its pricing page, $10 in / $1 cached / $50 out up to 272,000 input tokens, $20 / $2 / $75 above), this table holds one rate per model, and either single rate would be wrong for the other half of requests, so its cost reports unknown.",
222
+ "note": "Vendor list prices for text models, cached-input rate included. The driver hard-codes cacheWriteTokens to zero, so no write rate is carried. Embedding models are omitted (no output rate, and a chat turn never reaches one), as are models whose cached-input rate was not published alongside the others — an unestablished rate is left out rather than approximated, which is the rule this whole file follows. gpt-6-astra has no row on purpose: the vendor prices it by input length (read 2026-11-11 on its pricing page, $10 in / $1 cached / $50 out up to 272,000 input tokens, $20 / $2 / $75 above), this table holds one rate per model, and either single rate would be wrong for the other half of requests, so its cost reports unknown. The fastMultiplier on six rows is the vendor's fast-mode multiple read on its API pricing page on 2026-11-22: 2 for gpt-5.4, gpt-5.4-mini and the gpt-5.6 models, 2.5 for gpt-5.5 (fast is $12.50 in / $75 out, standard is $5 in / $30 out). The gpt-6 family has no row, so its fast usage reports unknown.",
223
223
  "models": [
224
224
  {
225
225
  "id": "gpt-5.6-sol",
226
226
  "inputPer1M": 5,
227
227
  "outputPer1M": 30,
228
- "cacheReadPer1M": 0.5
228
+ "cacheReadPer1M": 0.5,
229
+ "fastMultiplier": 2
229
230
  },
230
231
  {
231
232
  "id": "gpt-5.6-terra",
232
233
  "inputPer1M": 2,
233
234
  "outputPer1M": 12,
234
- "cacheReadPer1M": 0.2
235
+ "cacheReadPer1M": 0.2,
236
+ "fastMultiplier": 2
235
237
  },
236
238
  {
237
239
  "id": "gpt-5.6-luna",
238
240
  "inputPer1M": 0.2,
239
241
  "outputPer1M": 1.2,
240
- "cacheReadPer1M": 0.02
242
+ "cacheReadPer1M": 0.02,
243
+ "fastMultiplier": 2
241
244
  },
242
245
  {
243
246
  "id": "gpt-5.5",
244
247
  "inputPer1M": 5,
245
248
  "outputPer1M": 30,
246
- "cacheReadPer1M": 0.5
249
+ "cacheReadPer1M": 0.5,
250
+ "fastMultiplier": 2.5
247
251
  },
248
252
  {
249
253
  "id": "gpt-5.4",
250
254
  "inputPer1M": 2.5,
251
255
  "outputPer1M": 15,
252
- "cacheReadPer1M": 0.25
256
+ "cacheReadPer1M": 0.25,
257
+ "fastMultiplier": 2
253
258
  },
254
259
  {
255
260
  "id": "gpt-5.4-mini",
256
261
  "inputPer1M": 0.75,
257
262
  "outputPer1M": 4.5,
258
- "cacheReadPer1M": 0.075
263
+ "cacheReadPer1M": 0.075,
264
+ "fastMultiplier": 2
259
265
  },
260
266
  {
261
267
  "id": "gpt-5.4-nano",
@@ -574,6 +574,17 @@ export function withProviderFallback(
574
574
  member.provider.acceptsForcedToolChoiceFor?.(member.model ?? model, thinking, effort) ??
575
575
  false,
576
576
  ),
577
+ // A tier is offered only when every member that may serve the request
578
+ // lists it; a member that cannot say makes the answer unknown.
579
+ speedTiersFor: (model: string) => {
580
+ let common: readonly ('fast' | 'ultrafast')[] | undefined
581
+ for (const member of members) {
582
+ const tiers = member.provider.speedTiersFor?.(member.model ?? model)
583
+ if (tiers === undefined) return undefined
584
+ common = common === undefined ? tiers : common.filter((t) => tiers.includes(t))
585
+ }
586
+ return common
587
+ },
577
588
  reasoningEffortLevelsFor: (model: string, thinking?: ThinkingConfig) =>
578
589
  commonReasoningEffortLevels(members, model, thinking),
579
590
  // Present on the chain wrapper for the same reason the menu method is:
@@ -232,6 +232,11 @@ export function withStreamIdleTimeout(
232
232
  ) => provider.acceptsForcedToolChoiceFor?.(model, thinking, effort) ?? false,
233
233
  }
234
234
  : {}),
235
+ ...(provider.speedTiersFor
236
+ ? {
237
+ speedTiersFor: (model: string) => provider.speedTiersFor?.(model),
238
+ }
239
+ : {}),
235
240
  ...(provider.reasoningEffortLevelsFor
236
241
  ? {
237
242
  reasoningEffortLevelsFor: (
@@ -17,6 +17,7 @@ const MODEL_FIRST_METHODS: ReadonlySet<string> = new Set([
17
17
  'supportsHostedWebSearchFor',
18
18
  'supportsImageInputFor',
19
19
  'reasoningEffortLevelsFor',
20
+ 'speedTiersFor',
20
21
  'reasoningEffortDefaultFor',
21
22
  'acceptsForcedToolChoiceFor',
22
23
  'effortLevelsFor',
@@ -444,6 +444,11 @@ export function withProviderRetry(
444
444
  ) => provider.acceptsForcedToolChoiceFor?.(model, thinking, effort) ?? false,
445
445
  }
446
446
  : {}),
447
+ ...(provider.speedTiersFor
448
+ ? {
449
+ speedTiersFor: (model: string) => provider.speedTiersFor?.(model),
450
+ }
451
+ : {}),
447
452
  ...(provider.reasoningEffortLevelsFor
448
453
  ? {
449
454
  reasoningEffortLevelsFor: (
@@ -230,8 +230,12 @@ export { StaleObjectiveError } from './types/topic/objective.js'
230
230
  // consumes this store; automatic continuation is a separate driver rather
231
231
  // than a side effect hidden inside persistence.
232
232
  export {
233
+ DEFAULT_GOAL_CHECK_IN_ROUNDS,
234
+ DEFAULT_GOAL_STALL_ROUNDS,
233
235
  DEFAULT_MAX_GOAL_ROUNDS,
234
236
  DiskSessionGoalStore,
237
+ GoalBudgetLimitError,
238
+ GoalCheckInError,
235
239
  GoalExistsError,
236
240
  GoalNotFoundError,
237
241
  GoalRoundLimitError,
@@ -240,6 +244,9 @@ export {
240
244
  InMemorySessionGoalStore,
241
245
  MAX_GOAL_OBJECTIVE_CHARS,
242
246
  StaleGoalError,
247
+ goalCostText,
248
+ goalTokensText,
249
+ goalUsageSentence,
243
250
  } from './store/goal/index.js'
244
251
 
245
252
  export {
@@ -286,10 +293,12 @@ export {
286
293
  } from './tools/goal/index.js'
287
294
  export {
288
295
  DEFAULT_GOAL_REFUSALS,
296
+ GOAL_AUDIT_RUBRIC,
289
297
  GoalConfirmation,
290
298
  NO_CHECK_REASON_CODE,
291
299
  decideGoalConfirmation,
292
300
  describeGoalEnding,
301
+ parseGoalEvidence,
293
302
  recordSentence,
294
303
  } from './tools/goal/confirmation.js'
295
304
  export { SessionGoalActivation } from './manager/goal/activation.js'
@@ -401,6 +401,7 @@ export type * from './types/guardrail/index.js'
401
401
  export type {
402
402
  HostCommandContext,
403
403
  HostCommandDescriptor,
404
+ HostCommandModelRun,
404
405
  HostCommandOutcome,
405
406
  HostCommandRow,
406
407
  SerializableHostCommand,
@@ -431,6 +432,7 @@ export type {
431
432
  DiskSessionGoalStoreConfig,
432
433
  EditSessionGoalParams,
433
434
  InMemorySessionGoalStoreConfig,
435
+ ResumeSessionGoalOptions,
434
436
  SessionGoalStore,
435
437
  } from './store/goal/index.js'
436
438
  export type { ResolveGoalRoundAuthority } from './tools/goal/index.js'
@@ -440,7 +442,12 @@ export type {
440
442
  GoalDecisionInput,
441
443
  GoalEnding,
442
444
  GoalEndingReport,
445
+ GoalEvidence,
446
+ GoalJudge,
447
+ GoalJudgeInput,
448
+ GoalJudgement,
443
449
  GoalStatement,
450
+ SelfAuditDecision,
444
451
  } from './tools/goal/confirmation.js'
445
452
  export type { ActiveSessionGoal } from './manager/goal/activation.js'
446
453
  export type { HandBack, HandBackKind } from './types/session/hand-back.js'
@@ -6,9 +6,11 @@ import {
6
6
  GoalTransitionError,
7
7
  type SessionGoalStore,
8
8
  StaleGoalError,
9
+ goalCostText,
10
+ goalTokensText,
9
11
  } from '../../store/goal/index.js'
10
12
  import type { HostCommandDescriptor } from '../../types/command/index.js'
11
- import type { GoalConfirmedBy, GoalRef, SessionGoal } from '../../types/goal/index.js'
13
+ import type { GoalConfirmedBy, GoalGuards, GoalRef, SessionGoal } from '../../types/goal/index.js'
12
14
  import type { SessionId, TenantId } from '../../types/ids/index.js'
13
15
  import type { Skill } from '../../types/skills/index.js'
14
16
  import { isInvocableBy, skillInvocation } from '../../types/skills/index.js'
@@ -50,10 +52,21 @@ export interface GoalCommandScope {
50
52
  readonly activation?: SessionGoalActivation
51
53
  /** What a goal that does not choose is confirmed by; shown by `/goal status`. Default `model`. */
52
54
  readonly defaultConfirmedBy?: GoalConfirmedBy
55
+ /**
56
+ * What a goal created here gets when the command does not say: the round cap
57
+ * and the stop rules the host applies. Absent leaves the kernel's own cap and
58
+ * no stop rules.
59
+ */
60
+ readonly defaults?: GoalCommandDefaults
61
+ }
62
+
63
+ export interface GoalCommandDefaults {
64
+ readonly maxGoalRounds?: number
65
+ readonly guards?: GoalGuards
53
66
  }
54
67
 
55
68
  const GOAL_ARGUMENTS =
56
- '[status|set [--confirmed-by record|model] <objective>|<objective>|edit <objective>|pause|resume|clear]'
69
+ '[status|set [--confirmed-by record|model] [--token-budget <n>] [--max-rounds <n>] <objective>|<objective>|edit <objective>|pause|resume|clear]'
57
70
  const GOAL_USAGE = `Usage: /goal ${GOAL_ARGUMENTS}`
58
71
 
59
72
  type ParsedGoalCommand =
@@ -81,58 +94,85 @@ function parseGoalCommand(args: readonly string[]): ParsedGoalCommand {
81
94
  return { kind: 'create', objective: input }
82
95
  }
83
96
 
84
- type ConfirmedByFlag =
85
- | {
86
- readonly kind: 'ok'
87
- readonly args: readonly string[]
88
- readonly confirmedBy?: GoalConfirmedBy
89
- }
90
- | { readonly kind: 'invalid' }
97
+ interface GoalFlags {
98
+ readonly confirmedBy?: GoalConfirmedBy
99
+ readonly tokenBudget?: number
100
+ readonly maxRounds?: number
101
+ }
102
+
103
+ type TakenFlags =
104
+ | { readonly kind: 'ok'; readonly args: readonly string[]; readonly flags: GoalFlags }
105
+ | { readonly kind: 'invalid'; readonly flag: string }
106
+
107
+ const GOAL_FLAG_NAMES = ['--confirmed-by', '--token-budget', '--max-rounds'] as const
108
+ type GoalFlagName = (typeof GOAL_FLAG_NAMES)[number]
109
+
110
+ /** `--name value` or `--name=value` at `args[i]`; the flag, its value and how many words it took. */
111
+ function flagAt(
112
+ args: readonly string[],
113
+ i: number,
114
+ ): { readonly name: GoalFlagName; readonly value: string; readonly width: number } | undefined {
115
+ const arg = args[i] ?? ''
116
+ for (const name of GOAL_FLAG_NAMES) {
117
+ if (arg === name) return { name, value: args[i + 1] ?? '', width: 2 }
118
+ if (arg.startsWith(`${name}=`)) return { name, value: arg.slice(name.length + 1), width: 1 }
119
+ }
120
+ return undefined
121
+ }
122
+
123
+ function applyFlag(flags: GoalFlags, name: GoalFlagName, value: string): GoalFlags | undefined {
124
+ if (name === '--confirmed-by') {
125
+ return value === 'model' || value === 'record' ? { ...flags, confirmedBy: value } : undefined
126
+ }
127
+ if (!/^[1-9][0-9]{0,15}$/u.test(value)) return undefined
128
+ const n = Number(value)
129
+ if (!Number.isSafeInteger(n)) return undefined
130
+ return name === '--token-budget' ? { ...flags, tokenBudget: n } : { ...flags, maxRounds: n }
131
+ }
91
132
 
92
133
  /**
93
- * Takes `--confirmed-by <model|record>` (or `=`) out of the arguments, but only
94
- * where a flag stands: at the front, right after `set`, or closing the command. In the middle the words
95
- * belong to the objective, so a goal about the flag itself keeps its text.
134
+ * Takes `--confirmed-by <model|record>`, `--token-budget <n>` and `--max-rounds
135
+ * <n>` (or `=`) out of the arguments, but only where a flag stands: at the
136
+ * front, right after `set`, or closing the command. In the middle the words
137
+ * belong to the objective, so a goal about a flag itself keeps its text.
96
138
  */
97
- function takeConfirmedBy(args: readonly string[]): ConfirmedByFlag {
139
+ function takeGoalFlags(args: readonly string[]): TakenFlags {
98
140
  const head: string[] = []
99
141
  let i = 0
100
142
  if ((args[0] ?? '').toLowerCase() === 'set') {
101
143
  head.push(args[0] ?? '')
102
144
  i = 1
103
145
  }
104
- let found: GoalConfirmedBy | undefined
105
- for (; i < args.length; i++) {
106
- const arg = args[i] ?? ''
107
- let value: string
108
- if (arg === '--confirmed-by') {
109
- value = args[i + 1] ?? ''
110
- i++
111
- } else if (arg.startsWith('--confirmed-by=')) {
112
- value = arg.slice('--confirmed-by='.length)
146
+ let flags: GoalFlags = {}
147
+ for (;;) {
148
+ const found = flagAt(args, i)
149
+ if (!found) break
150
+ const next = applyFlag(flags, found.name, found.value)
151
+ if (!next) return { kind: 'invalid', flag: found.name }
152
+ flags = next
153
+ i += found.width
154
+ }
155
+ let tail = args.slice(i)
156
+ // Flags may also close the command; in the middle their words are the objective's.
157
+ for (;;) {
158
+ const last = tail.length - 1
159
+ const one = flagAt(tail, last)
160
+ const two = last >= 1 ? flagAt(tail, last - 1) : undefined
161
+ if (one && one.width === 1) {
162
+ const next = applyFlag(flags, one.name, one.value)
163
+ if (!next) return { kind: 'invalid', flag: one.name }
164
+ flags = next
165
+ tail = tail.slice(0, -1)
166
+ } else if (two && two.width === 2) {
167
+ const next = applyFlag(flags, two.name, two.value)
168
+ if (!next) return { kind: 'invalid', flag: two.name }
169
+ flags = next
170
+ tail = tail.slice(0, -2)
113
171
  } else {
114
172
  break
115
173
  }
116
- if (value !== 'model' && value !== 'record') return { kind: 'invalid' }
117
- found = value
118
- }
119
- let tail = args.slice(i)
120
- // A flag may also close the command; in the middle its words are the objective's.
121
- const last = tail[tail.length - 1] ?? ''
122
- const beforeLast = tail[tail.length - 2] ?? ''
123
- let closing: string | undefined
124
- if (last.startsWith('--confirmed-by=')) {
125
- closing = last.slice('--confirmed-by='.length)
126
- tail = tail.slice(0, -1)
127
- } else if (beforeLast === '--confirmed-by') {
128
- closing = last
129
- tail = tail.slice(0, -2)
130
- }
131
- if (closing !== undefined) {
132
- if (closing !== 'model' && closing !== 'record') return { kind: 'invalid' }
133
- found = closing
134
174
  }
135
- return { kind: 'ok', args: [...head, ...tail], ...(found ? { confirmedBy: found } : {}) }
175
+ return { kind: 'ok', args: [...head, ...tail], flags }
136
176
  }
137
177
 
138
178
  function goalRef(goal: SessionGoal): GoalRef {
@@ -163,10 +203,22 @@ function renderGoal(
163
203
  ? ['Confirmed by: the record of the work']
164
204
  : []),
165
205
  `Automatic continuation: ${armed ? 'enabled' : 'paused'}`,
166
- `Automatic turns: ${goal.roundsAdmitted} / ${goal.maxGoalRounds}`,
206
+ `Automatic turns: ${goal.roundsAdmitted}, up to ${goal.maxGoalRounds}`,
207
+ `Tokens: ${goalTokensText(goal)}`,
208
+ `Cost: ${goalCostText(goal)}`,
209
+ ...(goal.guards?.tokenBudget !== undefined
210
+ ? [`Token budget: ${goal.guards.tokenBudget.toLocaleString('en-US')}`]
211
+ : []),
212
+ ...(goal.guards?.checkInEvery
213
+ ? [`Check-in: every ${goal.guards.checkInEvery} automatic turns`]
214
+ : []),
215
+ ...(goal.pauseReason ? [`Paused: ${goal.pauseReason.message}`] : []),
167
216
  ...(goal.blockedReason
168
217
  ? [`Blocker: ${goal.blockedReason.code}: ${goal.blockedReason.message}`]
169
218
  : []),
219
+ ...(goal.missing && goal.missing.length > 0
220
+ ? [`Still missing: ${goal.missing.join('; ')}`]
221
+ : []),
170
222
  `Objective: ${goal.objective}`,
171
223
  '',
172
224
  `Commands: ${goalCommands(goal, armed)}`,
@@ -196,18 +248,22 @@ async function runGoalCommand(scope: GoalCommandScope | undefined, args: readonl
196
248
  reason: 'Goals need a durable session. This host did not supply one for the current command.',
197
249
  }
198
250
  }
199
- const flag = takeConfirmedBy(args)
200
- if (flag.kind === 'invalid') {
251
+ const taken = takeGoalFlags(args)
252
+ if (taken.kind === 'invalid') {
201
253
  return {
202
254
  kind: 'refused' as const,
203
- reason: `--confirmed-by takes record or model.\n${GOAL_USAGE}`,
255
+ reason:
256
+ taken.flag === '--confirmed-by'
257
+ ? `--confirmed-by takes record or model.\n${GOAL_USAGE}`
258
+ : `${taken.flag} takes a whole number of at least 1.\n${GOAL_USAGE}`,
204
259
  }
205
260
  }
206
- const command = parseGoalCommand(flag.args)
207
- if (flag.confirmedBy !== undefined && command.kind !== 'create') {
261
+ const flag = taken.flags
262
+ const command = parseGoalCommand(taken.args)
263
+ if (Object.keys(flag).length > 0 && command.kind !== 'create') {
208
264
  return {
209
265
  kind: 'refused' as const,
210
- reason: `--confirmed-by is chosen when a goal is set.\n${GOAL_USAGE}`,
266
+ reason: `Flags such as --confirmed-by, --token-budget and --max-rounds are chosen when a goal is set.\n${GOAL_USAGE}`,
211
267
  }
212
268
  }
213
269
  try {
@@ -237,10 +293,18 @@ async function runGoalCommand(scope: GoalCommandScope | undefined, args: readonl
237
293
  reason: `A goal is already ${current.phase}. Use /goal edit <objective> to change it or /goal clear before replacing it.`,
238
294
  }
239
295
  }
296
+ const defaults = scope.defaults
297
+ const guards: GoalGuards = {
298
+ ...defaults?.guards,
299
+ ...(flag.tokenBudget !== undefined ? { tokenBudget: flag.tokenBudget } : {}),
300
+ }
301
+ const maxGoalRounds = flag.maxRounds ?? defaults?.maxGoalRounds
240
302
  const created = await scope.store.createGoal(
241
303
  {
242
304
  sessionId: scope.sessionId,
243
305
  objective: command.objective,
306
+ ...(maxGoalRounds !== undefined ? { maxGoalRounds } : {}),
307
+ ...(Object.keys(guards).length > 0 ? { guards } : {}),
244
308
  ...(flag.confirmedBy !== undefined ? { confirmedBy: flag.confirmedBy } : {}),
245
309
  },
246
310
  scope.tenantId,
@@ -255,7 +319,14 @@ async function runGoalCommand(scope: GoalCommandScope | undefined, args: readonl
255
319
  if (!current) return missingGoal('edit')
256
320
  if (current.phase === 'complete') {
257
321
  const replacement = await scope.store.createGoal(
258
- { sessionId: scope.sessionId, objective: command.objective },
322
+ {
323
+ sessionId: scope.sessionId,
324
+ objective: command.objective,
325
+ ...(scope.defaults?.maxGoalRounds !== undefined
326
+ ? { maxGoalRounds: scope.defaults.maxGoalRounds }
327
+ : {}),
328
+ ...(scope.defaults?.guards ? { guards: scope.defaults.guards } : {}),
329
+ },
259
330
  scope.tenantId,
260
331
  )
261
332
  scope.activation?.arm(replacement)
@@ -299,10 +370,20 @@ async function runGoalCommand(scope: GoalCommandScope | undefined, args: readonl
299
370
  message: renderScopedGoal('Goal resumed', current, scope),
300
371
  }
301
372
  }
373
+ // A goal stopped by a limit goes on when the setting now allows more.
302
374
  const resumed = await scope.store.resumeGoal(
303
375
  scope.sessionId,
304
376
  scope.tenantId,
305
377
  goalRef(current),
378
+ {
379
+ ...(scope.defaults?.maxGoalRounds !== undefined
380
+ ? { maxGoalRounds: scope.defaults.maxGoalRounds }
381
+ : {}),
382
+ ...(scope.defaults?.guards?.tokenBudget !== undefined
383
+ ? { tokenBudget: scope.defaults.guards.tokenBudget }
384
+ : {}),
385
+ ...(scope.defaults?.guards ? { guards: scope.defaults.guards } : {}),
386
+ },
306
387
  )
307
388
  scope.activation?.arm(resumed)
308
389
  return {
@@ -346,12 +427,17 @@ export function kernelHostCommands(options: KernelCommandOptions): HostCommandDe
346
427
  name: 'goal',
347
428
  description: 'Persist or inspect a completion goal for this conversation.',
348
429
  hint: GOAL_ARGUMENTS,
430
+ // Setting, editing, pausing, resuming and clearing change what the
431
+ // conversation does next; only reading the goal runs unasked.
432
+ modelRun: 'confirm',
433
+ modelRunReads: ['', 'status'],
349
434
  handler: async ({ args }) => await runGoalCommand(options.goal, args),
350
435
  },
351
436
  {
352
437
  name: 'skills',
353
438
  description: 'List the skills an operator may invoke.',
354
439
  hint: 'name, description and policy for every operator-invocable skill',
440
+ modelRun: 'run',
355
441
  handler() {
356
442
  // Operator-invocable only, which is the point of the split: the
357
443
  // model's manifest and the operator's menu are different lists
@@ -381,6 +467,7 @@ export function kernelHostCommands(options: KernelCommandOptions): HostCommandDe
381
467
  name: 'agents',
382
468
  description: 'List the agents this turn may delegate to.',
383
469
  hint: 'the roster, as the delegation tools see it',
470
+ modelRun: 'run',
384
471
  handler() {
385
472
  // An empty roster IS the answer here, unlike the store above: the
386
473
  // question is "who may I call", and "nobody" is a complete and
@@ -2117,7 +2117,7 @@ export class IterationOrchestrator {
2117
2117
  }
2118
2118
  const endNote =
2119
2119
  !forceFinalize && closingStopReason === undefined
2120
- ? await this.askBeforeEnd()
2120
+ ? await this.askBeforeEnd(response.message.content ?? '')
2121
2121
  : undefined
2122
2122
  if (endNote !== undefined) {
2123
2123
  recorder.pushMessage(createRuntimeContextMessage(endNote, 'progress-nudge'))
@@ -3617,14 +3617,17 @@ export class IterationOrchestrator {
3617
3617
  * for the model, or `undefined` to let the turn end. Bounded, and a hook that
3618
3618
  * fails never fails the turn.
3619
3619
  */
3620
- async askBeforeEnd(): Promise<string | undefined> {
3620
+ async askBeforeEnd(finalMessage = ''): Promise<string | undefined> {
3621
3621
  const hook = this.ctx.turnConfig.outcome?.beforeEnd
3622
3622
  if (hook === undefined || this.beforeEndNotes >= MAX_BEFORE_END_NOTES) return undefined
3623
3623
  try {
3624
- const note = await hook(async () => {
3625
- this.hydrateOutcome()
3626
- return await this.outcomeLedger.preview()
3627
- })
3624
+ const note = await hook(
3625
+ async () => {
3626
+ this.hydrateOutcome()
3627
+ return await this.outcomeLedger.preview()
3628
+ },
3629
+ { finalMessage },
3630
+ )
3628
3631
  if (typeof note !== 'string' || note.trim() === '') return undefined
3629
3632
  this.beforeEndNotes += 1
3630
3633
  return note