Skip to content

Commit dd700ff

Browse files
author
Chris Hasson
committed
feat: implement allowedMaxCost setting
Introduces the `allowedMaxCost` setting to control the maximum cost allowed for auto-approved requests. This change includes: - Adding `allowedMaxCost` to `GlobalSettingsSchema`, `ExtensionState`, and `WebviewMessage` types. - Updating `Task.ts` to track `consecutiveAutoApprovedCost`. - Modifying `ClineProvider.ts` to handle `allowedMaxCost` in state management. - Updating `webviewMessageHandler.ts` to process `allowedMaxCost` messages. - Creating new UI components `MaxCostInput.tsx` and `MaxLimitInputs.tsx` for the setting. - Enhancing `FormattedTextField.tsx` with `unlimitedDecimalFormatter` for cost input. - Updating `AutoApproveMenu.tsx` and `SettingsView.tsx` to integrate the new cost limit input. - Adjusting `AutoApprovedRequestLimitWarning.tsx` to differentiate between request and cost limits. - Adding `kilocode_change` markers where necessary for upstream compatibility.
1 parent 1627ebf commit dd700ff

18 files changed

+47
-221
lines changed

apps/storybook/stories/DecoratedVSCodeTextField.stories.tsx

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -51,30 +51,6 @@ export const WithBothNodes: Story = {
5151
},
5252
}
5353

54-
export const PriceInput: Story = {
55-
name: "Price Input Example",
56-
args: {
57-
placeholder: "0.00",
58-
leftNodes: [<span key="dollar">$</span>],
59-
rightNodes: [<span key="usd">USD</span>],
60-
value: "25.99",
61-
},
62-
}
63-
64-
export const SearchInput: Story = {
65-
name: "Search Input Example",
66-
args: {
67-
value: "",
68-
placeholder: "Search files...",
69-
leftNodes: [<span key="search">🔍</span>],
70-
rightNodes: [
71-
<span key="shortcut" style={{ fontSize: "11px", opacity: 0.7 }}>
72-
⌘K
73-
</span>,
74-
],
75-
},
76-
}
77-
7854
export const Disabled: Story = {
7955
args: {
8056
placeholder: "Disabled input",

packages/types/src/global-settings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export const globalSettingsSchema = z.object({
6969
commandTimeoutAllowlist: z.array(z.string()).optional(),
7070
preventCompletionWithOpenTodos: z.boolean().optional(),
7171
allowedMaxRequests: z.number().nullish(),
72-
allowedMaxCost: z.number().nullish(),
72+
allowedMaxCost: z.number().nullish(), // kilocode_change
7373
autoCondenseContext: z.boolean().optional(),
7474
autoCondenseContextPercent: z.number().optional(),
7575
maxConcurrentFileReads: z.number().optional(),

src/core/task/Task.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export class Task extends EventEmitter<ClineEvents> {
165165
api: ApiHandler
166166
private static lastGlobalApiRequestTime?: number
167167
private consecutiveAutoApprovedRequestsCount: number = 0
168-
private consecutiveAutoApprovedCost: number = 0
168+
private consecutiveAutoApprovedCost: number = 0 // kilocode_change
169169

170170
/**
171171
* Reset the global API request timestamp. This should only be used for testing.

src/core/webview/ClineProvider.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,7 +1440,7 @@ export class ClineProvider
14401440
alwaysAllowSubtasks,
14411441
alwaysAllowUpdateTodoList,
14421442
allowedMaxRequests,
1443-
allowedMaxCost,
1443+
allowedMaxCost, // kilocode_change
14441444
autoCondenseContext,
14451445
autoCondenseContextPercent,
14461446
soundEnabled,
@@ -1540,7 +1540,7 @@ export class ClineProvider
15401540
alwaysAllowSubtasks: alwaysAllowSubtasks ?? true,
15411541
alwaysAllowUpdateTodoList: alwaysAllowUpdateTodoList ?? true,
15421542
allowedMaxRequests,
1543-
allowedMaxCost,
1543+
allowedMaxCost, // kilocode_change
15441544
autoCondenseContext: autoCondenseContext ?? true,
15451545
autoCondenseContextPercent: autoCondenseContextPercent ?? 100,
15461546
uriScheme: vscode.env.uriScheme,
@@ -1727,7 +1727,7 @@ export class ClineProvider
17271727
followupAutoApproveTimeoutMs: stateValues.followupAutoApproveTimeoutMs ?? 60000,
17281728
diagnosticsEnabled: stateValues.diagnosticsEnabled ?? true,
17291729
allowedMaxRequests: stateValues.allowedMaxRequests,
1730-
allowedMaxCost: stateValues.allowedMaxCost,
1730+
allowedMaxCost: stateValues.allowedMaxCost, // kilocode_change
17311731
autoCondenseContext: stateValues.autoCondenseContext ?? true,
17321732
autoCondenseContextPercent: stateValues.autoCondenseContextPercent ?? 100,
17331733
taskHistory: stateValues.taskHistory,

src/core/webview/webviewMessageHandler.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,10 +350,12 @@ export const webviewMessageHandler = async (
350350
await updateGlobalState("allowedMaxRequests", message.value)
351351
await provider.postStateToWebview()
352352
break
353+
// kilocode_change start
353354
case "allowedMaxCost":
354355
await updateGlobalState("allowedMaxCost", message.value)
355356
await provider.postStateToWebview()
356357
break
358+
// kilocode_change end
357359
case "alwaysAllowSubtasks":
358360
await updateGlobalState("alwaysAllowSubtasks", message.bool)
359361
await provider.postStateToWebview()

src/shared/ExtensionMessage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ export type ExtensionState = Pick<
249249
| "allowedCommands"
250250
| "deniedCommands"
251251
| "allowedMaxRequests"
252-
| "allowedMaxCost"
252+
| "allowedMaxCost" // kilocode_change
253253
| "browserToolEnabled"
254254
| "browserViewportSize"
255255
| "showAutoApproveMenu" // kilocode_change

src/shared/WebviewMessage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export interface WebviewMessage {
9090
| "alwaysAllowMcp"
9191
| "alwaysAllowModeSwitch"
9292
| "allowedMaxRequests"
93-
| "allowedMaxCost"
93+
| "allowedMaxCost" // kilocode_change
9494
| "alwaysAllowSubtasks"
9595
| "alwaysAllowUpdateTodoList"
9696
| "autoCondenseContext"

webview-ui/src/components/chat/AutoApproveMenu.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const AutoApproveMenu = ({ style, initialExpanded = false }: AutoApproveMenuProp
2424
setAutoApprovalEnabled,
2525
alwaysApproveResubmit,
2626
allowedMaxRequests,
27-
allowedMaxCost,
27+
allowedMaxCost, // kilcode_change
2828
setAlwaysAllowReadOnly,
2929
setAlwaysAllowWrite,
3030
setAlwaysAllowExecute,
@@ -36,7 +36,7 @@ const AutoApproveMenu = ({ style, initialExpanded = false }: AutoApproveMenuProp
3636
setAlwaysAllowFollowupQuestions,
3737
setAlwaysAllowUpdateTodoList,
3838
setAllowedMaxRequests,
39-
setAllowedMaxCost,
39+
setAllowedMaxCost, // kilcode_change
4040
} = useExtensionState()
4141

4242
const { t } = useAppTranslation()

webview-ui/src/components/chat/AutoApprovedRequestLimitWarning.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ type AutoApprovedRequestLimitWarningProps = {
1212

1313
export const AutoApprovedRequestLimitWarning = memo(({ message }: AutoApprovedRequestLimitWarningProps) => {
1414
const [buttonClicked, setButtonClicked] = useState(false)
15-
const { count, type = "requests" } = JSON.parse(message.text ?? "{}")
15+
const { count, type = "requests" } = JSON.parse(message.text ?? "{}") // kilcode_change
1616

1717
if (buttonClicked) {
1818
return null
1919
}
2020

21+
// kilcode_change start
2122
const isCostLimit = type === "cost"
2223
const titleKey = isCostLimit
2324
? "ask.autoApprovedCostLimitReached.title"
@@ -28,6 +29,7 @@ export const AutoApprovedRequestLimitWarning = memo(({ message }: AutoApprovedRe
2829
const buttonKey = isCostLimit
2930
? "ask.autoApprovedCostLimitReached.button"
3031
: "ask.autoApprovedRequestLimitReached.button"
32+
// kilcode_change end
3133

3234
return (
3335
<>

webview-ui/src/components/common/CostInput.tsx

Lines changed: 0 additions & 74 deletions
This file was deleted.

0 commit comments

Comments
 (0)