GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(extension): context usage donut and compaction (#4283) · IamCoder18/cloud@7ecef86

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • .github/workflows
    • extension-ci.yml
  • apps/extension
    • entrypoints
      • background.ts
      • sidepanel
        • agent-chat-atoms.ts
        • agent-chat-panel.tsx
        • agent-footer-controls.tsx
        • agent-llm-turn-runner.ts
        • agent-safe-llm-turn-runner.ts
        • app.tsx
        • context-donut.tsx
        • conversation-list.tsx
        • conversation-tabs.tsx
        • message-composer.tsx
    • package.json
    • src/shared
      • agent-chat-atoms.test.ts
      • agent-context-compaction.test.ts
      • agent-context-compaction.ts
      • agent-conversation-persistence.ts
      • agent-llm-turn-runner-core.test.ts
      • agent-llm-turn-runner-core.ts
      • context-usage.test.ts
      • context-usage.ts
      • kilo-api-client.test.ts
      • kilo-api-client.ts
      • kilo-gateway-chat-client.ts
      • kilo-gateway-chat-stream-client.test.ts
      • kilo-gateway-chat-stream-client.ts
      • tab-debugger.ts
    • tests/e2e
      • context-usage.test.ts
      • conversation-drafts.test.ts
      • conversation-tabs.test.ts
      • firefox-selenium-e2e.ts
      • kilo-api-fixture.ts
      • local-backend-live.test.ts
  • pnpm-lock.yaml
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎.github/workflows/extension-ci.yml‎

Copy file name to clipboard
+120Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
name: extension CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
paths:
7+
- 'apps/extension/**'
8+
- 'pnpm-lock.yaml'
9+
- 'pnpm-workspace.yaml'
10+
- '.nvmrc'
11+
- '.github/workflows/extension-ci.yml'
12+
pull_request:
13+
branches: [main]
14+
paths:
15+
- 'apps/extension/**'
16+
- 'pnpm-lock.yaml'
17+
- 'pnpm-workspace.yaml'
18+
- '.nvmrc'
19+
- '.github/workflows/extension-ci.yml'
20+
21+
concurrency:
22+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
23+
cancel-in-progress: true
24+
25+
permissions:
26+
contents: read
27+
pull-requests: read
28+
29+
jobs:
30+
# Compiler, linter, formatting and unit tests, via the extension's own `verify`
31+
# script so the extension's stricter (type-aware) oxlint config is what runs.
32+
verify:
33+
runs-on: ${{ vars.RUNNER_DEFAULT_LABEL || 'ubuntu-latest' }}
34+
timeout-minutes: 15
35+
steps:
36+
- uses: useblacksmith/checkout@41cdeedae8edb2e684ba22896a5fd2a3cb85db6b # v1
37+
with:
38+
lfs: true
39+
40+
- name: Setup pnpm
41+
uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v4.4.0
42+
43+
- name: Setup Node
44+
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
45+
with:
46+
node-version-file: '.nvmrc'
47+
cache: 'pnpm'
48+
49+
- name: Install dependencies
50+
run: pnpm install --frozen-lockfile
51+
52+
- name: Verify (typecheck, lint, format, unit tests)
53+
run: pnpm --filter kilo-extension verify
54+
55+
# Prove the Firefox MV3 target still builds (the Chrome build runs inside e2e).
56+
build-firefox:
57+
runs-on: ${{ vars.RUNNER_DEFAULT_LABEL || 'ubuntu-latest' }}
58+
timeout-minutes: 15
59+
steps:
60+
- uses: useblacksmith/checkout@41cdeedae8edb2e684ba22896a5fd2a3cb85db6b # v1
61+
with:
62+
lfs: true
63+
64+
- name: Setup pnpm
65+
uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v4.4.0
66+
67+
- name: Setup Node
68+
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
69+
with:
70+
node-version-file: '.nvmrc'
71+
cache: 'pnpm'
72+
73+
- name: Install dependencies
74+
run: pnpm install --frozen-lockfile
75+
76+
- name: Build (Firefox MV3)
77+
run: pnpm --filter kilo-extension build:firefox
78+
79+
# Chrome end-to-end tests. `e2e:chrome` builds the Chrome MV3 bundle first, so this
80+
# also covers the Chrome build. Firefox Selenium e2e (`e2e:firefox`) is intentionally
81+
# not run here: it relies on geckodriver tab detection that is unreliable headless.
82+
e2e-chrome:
83+
needs: verify
84+
runs-on: ${{ vars.RUNNER_LARGE_LABEL || 'ubuntu-24.04-8core' }}
85+
timeout-minutes: 20
86+
env:
87+
CI: 'true'
88+
steps:
89+
- uses: useblacksmith/checkout@41cdeedae8edb2e684ba22896a5fd2a3cb85db6b # v1
90+
with:
91+
lfs: true
92+
93+
- name: Setup pnpm
94+
uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v4.4.0
95+
96+
- name: Setup Node
97+
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
98+
with:
99+
node-version-file: '.nvmrc'
100+
cache: 'pnpm'
101+
102+
- name: Install dependencies
103+
run: pnpm install --frozen-lockfile
104+
105+
- name: Install Playwright Chromium
106+
run: pnpm --filter kilo-extension exec playwright install --with-deps chromium
107+
108+
- name: Run Chrome e2e (builds the Chrome MV3 bundle first)
109+
run: pnpm --filter kilo-extension e2e:chrome
110+
111+
- name: Upload Playwright report on failure
112+
if: failure()
113+
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
114+
with:
115+
name: extension-playwright-report
116+
path: |
117+
apps/extension/playwright-report
118+
apps/extension/test-results
119+
retention-days: 7
120+
if-no-files-found: ignore
Collapse file

‎apps/extension/entrypoints/background.ts‎

Copy file name to clipboardExpand all lines: apps/extension/entrypoints/background.ts
+12-4Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,24 @@ interface ChromeRuntimeApi {
3636
/*
3737
* Trust boundary for the eval/debugger message path. Today only the extension's own pages (the
3838
* side panel) can reach this listener — there is no externally_connectable and no content script.
39-
* Accept only same-extension, non-tab senders so adding either later can't silently widen access
40-
* to the dangerous eval path. Content scripts carry a `tab`; external pages carry a different `id`.
39+
* Accept only same-extension senders whose origin is an extension page, so adding a content script
40+
* later can't silently widen access to the dangerous eval path: a content script shares the
41+
* extension `id` but reports the host page's web origin, while an extension page reports an
42+
* extension-scheme origin (`chrome-extension://` on Chrome, `moz-extension://` on Firefox).
4143
*/
44+
const isExtensionScheme = (value: unknown): boolean =>
45+
typeof value === 'string' &&
46+
(value.startsWith('chrome-extension://') || value.startsWith('moz-extension://'));
47+
4248
const isTrustedExtensionSender = (sender: unknown, runtimeId: string | undefined): boolean => {
4349
if (runtimeId === undefined || typeof sender !== 'object' || sender === null) {
4450
return false;
4551
}
4652

47-
const { id, tab } = sender as { id?: unknown; tab?: unknown };
48-
return id === runtimeId && tab === undefined;
53+
const { id, origin, url } = sender as { id?: unknown; origin?: unknown; url?: unknown };
54+
55+
// Same-extension is already pinned by `id === runtimeId`, so origin only separates an extension page from a content script.
56+
return id === runtimeId && (isExtensionScheme(origin) || isExtensionScheme(url));
4957
};
5058

5159
const handleTabDebuggerRequest = async ({
Collapse file

‎apps/extension/entrypoints/sidepanel/agent-chat-atoms.ts‎

Copy file name to clipboard
+39Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { atom, getDefaultStore } from 'jotai';
2+
import { atomFamily } from 'jotai-family';
3+
import type { ContextUsage } from '@/src/shared/context-usage';
4+
5+
// Per-conversation in-memory draft text (reset on reload by design).
6+
// Keys for closed-but-not-deleted conversations are kept so their drafts survive reopen; evicted on delete and on sign-out.
7+
export const draftAtomFamily = atomFamily((_conversationId: string) => atom(''));
8+
9+
// Per-conversation context usage from the latest gateway turn (in-memory only).
10+
// Same lifecycle as drafts: kept across close, evicted on delete and on sign-out.
11+
export const contextUsageAtomFamily = atomFamily((_conversationId: string) =>
12+
atom<ContextUsage | undefined>()
13+
);
14+
15+
// Ids of conversations with an in-flight run / compaction.
16+
export const runningConversationIdsAtom = atom<readonly string[]>([]);
17+
export const compactingConversationIdsAtom = atom<readonly string[]>([]);
18+
19+
// Evict a single conversation's in-memory atoms (draft + context usage).
20+
export const evictConversationAtoms = (conversationId: string): void => {
21+
draftAtomFamily.remove(conversationId);
22+
contextUsageAtomFamily.remove(conversationId);
23+
};
24+
25+
/*
26+
* Drop all per-conversation in-memory state. Called on sign-out so a different
27+
* account on the same profile (no reload) never inherits the prior user's
28+
* drafts/usage — conversation ids are deterministic (conversation-1, ...), so
29+
* the atom families would otherwise hand back the old account's values.
30+
*/
31+
export const clearPerConversationAtoms = (): void => {
32+
const ids = new Set([...draftAtomFamily.getParams(), ...contextUsageAtomFamily.getParams()]);
33+
for (const id of ids) {
34+
evictConversationAtoms(id);
35+
}
36+
const store = getDefaultStore();
37+
store.set(runningConversationIdsAtom, []);
38+
store.set(compactingConversationIdsAtom, []);
39+
};

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.