-
Notifications
You must be signed in to change notification settings - Fork 3.2k
feat(vscode): add cross-platform keep-awake toggle #12974
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
822d0aa
feat(vscode): add cross-platform keep-awake toggle
marius-kilocode 4c20e5a
fix(vscode): clean up keep-awake shutdown
marius-kilocode c151cd7
Merge origin/main into implement-caffeine-button
marius-kilocode 2eade27
test(vscode): cover keep-awake disposal
marius-kilocode 242afc2
fix(vscode): only caffeinate while agent sessions are running
marius-kilocode e49476f
Merge branch 'main' into implement-caffeine-button
marius-kilocode a31c911
feat(vscode): revive opt-in keep-awake
marius-kilocode 1d70347
chore: merge latest main into keep-awake branch
marius-kilocode 55951bf
refactor(vscode): isolate keep-awake widget state
marius-kilocode dd7437c
fix(vscode): harden keep-awake activity and indicator
marius-kilocode 53819a0
chore: reconcile latest main intro handling
marius-kilocode 425a0d4
fix(cli): preserve legacy idle events during activity tracking
marius-kilocode 261b09a
refactor(vscode): minimize keep-awake to extension status tracking
marius-kilocode a12a747
Merge branch 'main' into implement-caffeine-button
marius-kilocode 30828e7
fix(vscode): keep multi-project toolbar controls visible
marius-kilocode 85bc28a
chore: update kilo-vscode visual regression baselines
kilo-maintainer[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "kilo-code": minor | ||
| --- | ||
|
|
||
| Add a default-off Keep Awake toggle for busy agent sessions without keeping the display on or disabling screen locking. Remember the safety notice after its first acceptance. Keep multi-project toolbar controls visible in narrow sidebars. |
3 changes: 3 additions & 0 deletions
3
...ode/visual-regression/agentmanager/multi-project-sidebar-200-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import type { CaffeinationService } from "./service" | ||
|
|
||
| export function confirmCaffeination( | ||
| service: Pick<CaffeinationService, "getState" | "setEnabled">, | ||
| ask: () => Promise<boolean>, | ||
| ) { | ||
| let accepted = false | ||
| let pending: Promise<void> | undefined | ||
| let revision = 0 | ||
|
|
||
| return (enabled: boolean): Promise<void> => { | ||
| if (!enabled) { | ||
| revision++ | ||
| return service.setEnabled(false) | ||
| } | ||
| const state = service.getState() | ||
| if (state.enabled || !state.available) return Promise.resolve() | ||
| if (accepted) return service.setEnabled(true) | ||
| if (pending) return pending | ||
|
|
||
| const current = revision | ||
| pending = Promise.resolve() | ||
| .then(ask) | ||
| .then((answer) => { | ||
| if (!answer || current !== revision) return | ||
| accepted = true | ||
| return service.setEnabled(true) | ||
| }) | ||
| .catch((error: unknown) => { | ||
| console.warn("[Kilo New] Keep-awake confirmation failed:", error) | ||
| }) | ||
| .finally(() => { | ||
| pending = undefined | ||
| }) | ||
| return pending | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| import { realpathSync } from "node:fs" | ||
| import type { SessionStatus } from "@kilocode/sdk/v2/client" | ||
| import type { SSEPayload } from "../cli-backend/sdk-sse-adapter" | ||
|
|
||
| type Snapshot = Record<string, Pick<SessionStatus, "type">> | ||
| type Update = Extract<SSEPayload, { type: "session.status" | "session.idle" | "session.deleted" | "session.error" }> | ||
| type State = { values: Set<string>; request?: { events: Update[]; promise: Promise<void> } } | ||
|
|
||
| function key(dir: string): string { | ||
| const path = dir.replace(/\\/g, "/").replace(/\/+$/u, "") || "/" | ||
| return process.platform === "win32" || process.platform === "darwin" ? path.toLowerCase() : path | ||
| } | ||
|
|
||
| function busy(status: Pick<SessionStatus, "type">): boolean { | ||
| return status.type === "busy" || status.type === "retry" | ||
| } | ||
|
|
||
| function apply(values: Set<string>, event: Update): void { | ||
| const id = event.properties.sessionID ?? (event.type === "session.deleted" ? event.properties.info?.id : undefined) | ||
| if (!id) return | ||
| if (event.type === "session.status" && busy(event.properties.status)) { | ||
| values.add(id) | ||
| return | ||
| } | ||
| values.delete(id) | ||
| } | ||
|
|
||
| export function feed(opts: { | ||
| paths: () => string[] | ||
| watching: () => boolean | ||
| load: (dir: string) => Promise<Snapshot> | ||
| post: (busy: boolean) => void | ||
| }) { | ||
| const dirs = new Map<string, string>() | ||
| const states = new Map<string, State>() | ||
| const aliases = new Map<string, string>() | ||
| const resolve = (dir: string): string => { | ||
| const path = key(dir) | ||
| const prior = aliases.get(path) | ||
| if (prior || !opts.watching()) return prior ?? path | ||
| try { | ||
| const id = key(realpathSync.native(dir)) | ||
| aliases.set(path, id) | ||
| aliases.set(id, id) | ||
| return id | ||
| } catch { | ||
| aliases.set(path, path) | ||
| return path | ||
| } | ||
| } | ||
| const publish = () => opts.post([...states.values()].some((state) => state.values.size > 0)) | ||
| const clear = () => { | ||
| states.clear() | ||
| aliases.clear() | ||
| publish() | ||
| } | ||
| const get = (dir: string, force = false): State => { | ||
| const id = resolve(dir) | ||
| const prior = states.get(id) | ||
| const state: State = prior ?? { values: new Set() } | ||
| states.set(id, state) | ||
| if (state.request || (prior && !force)) return state | ||
| const request: NonNullable<State["request"]> = { | ||
| events: [], | ||
| promise: Promise.resolve() | ||
| .then<Snapshot>(() => (opts.watching() ? opts.load(dir) : {})) | ||
| .catch((error: unknown) => { | ||
| console.warn(`[Kilo New] Keep-awake status refresh failed for ${dir}:`, error) | ||
| return {} | ||
| }) | ||
| .then((snapshot) => { | ||
| if (states.get(id) !== state || state.request !== request) return | ||
| state.values = new Set( | ||
| Object.entries(snapshot) | ||
| .filter(([, status]) => busy(status)) | ||
| .map(([id]) => id), | ||
| ) | ||
| for (const event of request.events) apply(state.values, event) | ||
| publish() | ||
| }) | ||
| .finally(() => { | ||
| if (state.request === request) state.request = undefined | ||
| }), | ||
| } | ||
| state.request = request | ||
| return state | ||
| } | ||
| const sync = async () => { | ||
| if (!opts.watching()) return | ||
| for (const dir of opts.paths()) if (dir) dirs.set(key(dir), dir) | ||
| const paths = [...dirs.values()] | ||
| dirs.clear() | ||
| for (const dir of paths) dirs.set(resolve(dir), dir) | ||
| await Promise.all([...dirs.values()].map((dir) => get(dir, true).request?.promise)) | ||
| } | ||
| return { | ||
| sync, | ||
| clear, | ||
| event(event: SSEPayload, directory?: string): void { | ||
| if (event.type === "server.instance.disposed") { | ||
| const id = resolve(event.properties.directory) | ||
| for (const [alias, target] of aliases) if (target === id) aliases.delete(alias) | ||
| dirs.delete(id) | ||
| states.delete(id) | ||
| publish() | ||
| return | ||
| } | ||
| if ( | ||
| event.type !== "session.status" && | ||
| event.type !== "session.idle" && | ||
| event.type !== "session.deleted" && | ||
| event.type !== "session.error" | ||
| ) | ||
| return | ||
| if (directory) dirs.set(resolve(directory), directory) | ||
| if (!opts.watching()) return | ||
| if (!directory && event.type === "session.status" && busy(event.properties.status)) { | ||
| clear() | ||
| void sync() | ||
| return | ||
| } | ||
| for (const state of directory ? [get(directory)] : states.values()) { | ||
| state.request?.events.push(event) | ||
| apply(state.values, event) | ||
| } | ||
| publish() | ||
| }, | ||
| dispose(): void { | ||
| clear() | ||
| dirs.clear() | ||
| }, | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| export { CaffeinationService } from "./service" | ||
| export type { CaffeinationState } from "./service" | ||
| export type { CaffeinationDriver } from "./inhibitor" |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.