(
ctx: Pick<
HandlerContext,
`setGoal` | `clearGoal` | `getGoal` | `markGoalComplete`
>,
command: GoalCommand
)
| 183 | } |
| 184 | |
| 185 | export function dispatchGoalCommand( |
| 186 | ctx: Pick< |
| 187 | HandlerContext, |
| 188 | `setGoal` | `clearGoal` | `getGoal` | `markGoalComplete` |
| 189 | >, |
| 190 | command: GoalCommand |
| 191 | ): GoalDispatchResult { |
| 192 | switch (command.kind) { |
| 193 | case `set`: { |
| 194 | const input = |
| 195 | command.tokenBudget === undefined |
| 196 | ? { objective: command.objective } |
| 197 | : { objective: command.objective, tokenBudget: command.tokenBudget } |
| 198 | const entry = ctx.setGoal(input) |
| 199 | const budgetLabel = |
| 200 | entry.tokenBudget === null |
| 201 | ? `unlimited` |
| 202 | : `${formatTokenCount(entry.tokenBudget)} tokens` |
| 203 | return { |
| 204 | handled: true, |
| 205 | message: `Goal set: ${entry.objective} (budget: ${budgetLabel})`, |
| 206 | } |
| 207 | } |
| 208 | case `clear`: { |
| 209 | const cleared = ctx.clearGoal() |
| 210 | return { |
| 211 | handled: true, |
| 212 | message: cleared ? `Goal cleared` : `No goal to clear`, |
| 213 | } |
| 214 | } |
| 215 | case `complete`: { |
| 216 | const updated = ctx.markGoalComplete() |
| 217 | return { |
| 218 | handled: true, |
| 219 | message: updated ? `Goal marked complete` : `No goal to mark complete`, |
| 220 | } |
| 221 | } |
| 222 | case `show`: { |
| 223 | const goal = ctx.getGoal() |
| 224 | if (!goal) return { handled: true, message: `No goal set` } |
| 225 | const budgetLabel = |
| 226 | goal.tokenBudget === null |
| 227 | ? `${formatTokenCount(goal.tokensUsed)} tokens used (unlimited)` |
| 228 | : `${formatTokenCount(goal.tokensUsed)} / ${formatTokenCount( |
| 229 | goal.tokenBudget |
| 230 | )} tokens` |
| 231 | return { |
| 232 | handled: true, |
| 233 | message: `Goal: ${goal.objective} (${budgetLabel}, ${goal.status})${ |
| 234 | goal.summary ? `\nSummary: ${goal.summary}` : `` |
| 235 | }`, |
| 236 | } |
| 237 | } |
| 238 | case `error`: |
| 239 | return { handled: true, message: command.message } |
| 240 | } |
| 241 | } |
no test coverage detected