Skip to content

Commit b9c7f86

Browse files
feat: dynamic editor tabs. (#116)
* feat: idb infrastructure. (#63) * feat: dynamic tabs. (#64) * refactor: better accessbility for tabs. (#68) * feat: remove allow-same-origin for better security. (#69) * feat: tab reordering via drag-n-drop. (#70) * feat: explicit css imports, diagnostics per editor buffer. (#71) * feat: idb + github sync with atomic open and push to remote. (#78) * closes #73, closes #74, closes #75. * refactor: more colocation and smaller file sizes. (#79) * refactor: improvements with styles and gh syncs. (#82) * test: webkit flake. (#83) * test: address flake. (#84) * refactor: github pr context. (#85) * fix: require app in entry, hide workspaces without pat, remove star important. (#86) * feat: make idb source of truth for pr context. (#87) * fix: active pr context on reload and dedupe workspace identity. (#88) * fix: edited and push sync across reloads. (#89) * fix: properly commit tab name changes. (#90) * fix(tabs): filename edits, min-widths, scrolling, content sync. (#91) * feat: improved workspace disconnect and closed ux. (#92) * refactor: status styling and biome config. (#94) * fix(diagnostics): enforce current-editor snapshots and stale results. (#95) * fix: consistent head handling. (#96) * fix: prevent workspace overwrites. (#100) * fix(playwright): stabilize lint diagnostics waits with one-time rerun fallback. (#101) * feat: improved workspace ux and state identity separation. (#103) * fix: iframe protocol mismatch in receiver reads. (#104) * refactor: remove remaining fixed editor assumptions. (#105) * refactor: simplify PR close flow with deterministic workspace state updates (#106) * feat: mode-aware entry tab extensions. (#108) * feat: workspace status bar. (#109) * feat: tab-scoped ai chat. (#111) * refactor: better workspace drawer ux. (#112) * refactor: remove collapsible editors and update breakpoint styles. (#113) * docs: update for vnext. (#114) Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 1bc9ef1 commit b9c7f86

144 files changed

Lines changed: 31415 additions & 10366 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/instructions/pr-review.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ You are reviewing changes for @knighted/develop. Be concise, technical, and spec
2424
## What to verify
2525

2626
- No generated artifacts are edited (dist/, coverage/, test-results/).
27+
- Duplicated logic paths are avoided when a shared helper/module already exists; prefer reusing the established implementation.
2728
- CDN import/fallback behavior is not bypassed with ad hoc URLs in feature modules.
2829
- Sensitive values (PAT/token) are not logged or exposed in UI/status output.
2930
- New UI behavior is covered in Playwright where appropriate.

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
pull_request:
88
branches:
99
- main
10+
- next
1011

1112
jobs:
1213
ci:

.github/workflows/playwright.yml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
pull_request:
55
branches:
66
- main
7+
- next
78
types:
89
- opened
910
- synchronize
@@ -38,20 +39,25 @@ jobs:
3839
shardIndex: 1
3940
shardTotal: 1
4041
- browser: webkit
41-
jobName: E2E (Playwright, webkit, shard 1/3)
42+
jobName: E2E (Playwright, webkit, shard 1/4)
4243
workers: 1
4344
shardIndex: 1
44-
shardTotal: 3
45+
shardTotal: 4
4546
- browser: webkit
46-
jobName: E2E (Playwright, webkit, shard 2/3)
47+
jobName: E2E (Playwright, webkit, shard 2/4)
4748
workers: 1
4849
shardIndex: 2
49-
shardTotal: 3
50+
shardTotal: 4
5051
- browser: webkit
51-
jobName: E2E (Playwright, webkit, shard 3/3)
52+
jobName: E2E (Playwright, webkit, shard 3/4)
5253
workers: 1
5354
shardIndex: 3
54-
shardTotal: 3
55+
shardTotal: 4
56+
- browser: webkit
57+
jobName: E2E (Playwright, webkit, shard 4/4)
58+
workers: 1
59+
shardIndex: 4
60+
shardTotal: 4
5561

5662
steps:
5763
- name: Checkout

AGENTS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,18 @@ Repository structure:
4040

4141
- Preserve current project formatting: single quotes, no semicolons, print width 90, arrowParens avoid.
4242
- Do not use index files or barrel-file architecture; prefer explicit file names and explicit import paths.
43+
- Prefer modular, colocated architecture; split focused features into nearby files and avoid monolithic modules.
4344
- Keep UI changes intentional and lightweight; avoid broad visual rewrites unless requested.
4445
- Keep runtime logic defensive for flaky/slow CDN conditions.
4546
- Preserve progressive loading behavior (lazy-load optional compilers/runtime pieces where possible).
4647
- Do not introduce bundler-only assumptions into src/ runtime code.
4748
- Prefer async/await over promise chains.
49+
- Prefer const-assigned function expressions over function declarations, unless hoisting is explicitly required.
4850
- Do not use IIFE, find another pattern instead.
4951
- In Playwright tests, prefer accessible selectors first: `getByRole`, `getByLabel`, `getByText`, and explicit accessible names.
5052
- Avoid `locator()` for interactive controls when a semantic selector is available.
5153
- Use `locator()` only as a fallback for cases without reliable semantics (for example: document root `html`, structural class assertions, or implementation-only hooks).
54+
- For known WebKit HTML `<dialog>` top-layer issues, prefer a stable dialog id locator and `evaluate`-based click for dialog confirmation controls.
5255
- When testability needs improvement, prefer adding accessibility semantics (`role`, `aria-label`, `aria-labelledby`) over introducing new id-only selectors.
5356

5457
## CDN and runtime expectations

README.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,39 @@ CDN-first UI component workbench for rapid prototyping with [`@knighted/jsx`](ht
99

1010
## What it is
1111

12-
`@knighted/develop` is a browser-native UI component workbench that demonstrates
13-
modern component authoring without a local bundler-first inner loop.
12+
`@knighted/develop` is a browser-native component editor/workbench for fast
13+
UI iteration without a local bundler-first inner loop.
1414

1515
The app is designed to showcase two libraries:
1616

1717
- [`@knighted/jsx`](https://github.com/knightedcodemonkey/jsx) for DOM-first and React-mode JSX authoring
1818
- [`@knighted/css`](https://github.com/knightedcodemonkey/css) for in-browser CSS compilation workflows
1919

2020
Dependencies are delivered over CDN ESM with on-demand loading by mode, so the
21-
browser acts as the runtime host for render, lint, and typecheck flows.
21+
browser acts as the runtime host for editing, render, lint, and typecheck flows.
2222

2323
## Core capabilities
2424

2525
`@knighted/develop` lets you:
2626

27-
- write component code in the browser
27+
- write component code in dynamic editor tabs in the browser
28+
- add, rename, and remove tabs with entry-role protection for required tabs
29+
- keep per-tab dirty/synced state while iterating across files
2830
- switch render mode between DOM and React
2931
- switch style mode between native CSS, CSS Modules, Less, and Sass
3032
- run in-browser lint and type diagnostics
3133
- open diagnostics in a shared drawer and jump to source locations
32-
- toggle ShadowRoot preview isolation while iterating
33-
- switch layout and theme while preserving fast feedback loops
34+
- use iframe-isolated preview style encapsulation while iterating
35+
- connect a GitHub repository and run Open PR / Push Commit workflows
36+
- use AI chat with tab-aware proposals and apply/undo controls
37+
- switch theme and collapse the preview panel while preserving fast feedback loops
38+
39+
## Why this shape
40+
41+
The app started as a focused compile-and-preview loop and has grown into a
42+
more complete browser-native editor surface. The goal is still fast
43+
experimentation, now with practical multi-file editing and repository workflows
44+
in the same UI.
3445

3546
## Try it
3647

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
# AI Chat Context and Payload Strategy
2+
3+
This document describes the current AI chat request construction approach in @knighted/develop, including context shaping, tool usage, payload-size controls, and known improvement opportunities.
4+
5+
## Current Approach
6+
7+
### 1. System prompt and mode-aware policy
8+
9+
Each request includes a system prompt with policy guidance, then augments that prompt with mode-aware constraints:
10+
11+
- Render mode guidance (DOM vs React)
12+
- Style mode guidance (css, module, less, sass)
13+
- DOM-mode JSX guidance for @knighted/jsx runtime
14+
- Explicit React-avoidance in DOM mode unless migration is requested
15+
- Dialect preservation guidance (avoid cross-dialect rewrites unless requested)
16+
17+
Primary implementation:
18+
19+
- src/modules/github/chat/payload.js
20+
21+
### 2. Repository context
22+
23+
Each request includes repository targeting context as a dedicated system message:
24+
25+
- Selected repository full name
26+
- Repository URL
27+
- Default branch
28+
- Policy to treat selected repository as default unless overridden
29+
30+
Primary implementation:
31+
32+
- src/modules/github/chat/drawer.js
33+
34+
### 3. Editor context (Send tab content)
35+
36+
When enabled, the drawer includes active tab context as a system message:
37+
38+
- Render mode and style mode
39+
- Active tab label/path
40+
- Available tab targets list (id/path/name/language), currently capped to 20
41+
- Active tab source code block
42+
43+
This context is designed to support dynamic proposal targeting by tab id/path and reduce ambiguity.
44+
45+
Primary implementation:
46+
47+
- src/modules/github/chat/active-tab-context.js
48+
- src/modules/github/chat/drawer.js
49+
50+
### 4. Tooling model
51+
52+
AI proposal actions currently use a function tool:
53+
54+
- propose_editor_update
55+
56+
Contract:
57+
58+
- target: tab id or path
59+
- content: full replacement tab content
60+
- language: optional disambiguation hint
61+
- rationale: optional explanation
62+
63+
Primary implementation:
64+
65+
- src/modules/github/chat/proposals.js
66+
- src/modules/github/chat/tab-target-resolver.js
67+
- src/modules/github/chat/drawer.js
68+
69+
### 5. Apply and undo behavior
70+
71+
- Apply is proposal-driven and tab-target-aware (id/path resolution)
72+
- Undo is scoped per tab (latest snapshot per tab)
73+
- Undo UI is visible for active tab snapshot only
74+
75+
Primary implementation:
76+
77+
- src/modules/github/chat/drawer.js
78+
- src/modules/github/chat/tab-scoped-undo-state.js
79+
80+
### 6. Payload size controls and summary strategy
81+
82+
The payload builder includes bounded-conversation controls:
83+
84+
- Hard byte budget: 120_000 bytes
85+
- Direct conversation retention cap: latest 14 chat messages
86+
- Summary cap: 3_600 characters
87+
- Older dropped conversation turns are compacted into a rolling system summary
88+
89+
Primary implementation:
90+
91+
- src/modules/github/chat/payload.js
92+
93+
### 7. Fallback and transport behavior
94+
95+
- Streaming request path is attempted first
96+
- Non-stream fallback is attempted on streaming failure
97+
- Model access errors are surfaced with tailored status text
98+
99+
Primary implementation:
100+
101+
- src/modules/github/chat/drawer.js
102+
- src/modules/github/api/chat.js
103+
104+
## Why this approach
105+
106+
- Keeps active-tab workflows lightweight and responsive
107+
- Supports explicit user review before applying generated edits
108+
- Preserves model guidance quality with mode/dialect policy constraints
109+
- Reduces request-size growth with bounded message history and rolling summaries
110+
111+
## Possible Areas for Improvement
112+
113+
### 1. Hard-fit protection when system context alone is large
114+
115+
Current shrinking behavior primarily trims conversation turns. Add a final hard-fit step that can selectively trim editor context sections when total payload still exceeds budget.
116+
117+
Potential ideas:
118+
119+
- Trim available tab target list length adaptively
120+
- Clip active tab source with clear truncation markers
121+
- Retry once on 413 with reduced context envelope
122+
123+
### 2. Create-tab capability
124+
125+
Add a dedicated tool for creating workspace tabs so requests like "create a new styles tab" can be completed in one interaction.
126+
127+
Potential tool:
128+
129+
- create_workspace_tab(path, language, initialContent?, activate?)
130+
131+
### 3. Cross-tab source access
132+
133+
Support workflows where the user references a non-active tab.
134+
135+
Potential options:
136+
137+
- Add Send all tabs mode with explicit byte budgeting
138+
- Add read_workspace_tab tool for targeted lookup
139+
140+
### 4. Better summary fidelity
141+
142+
Current summary is compact and bounded, but can lose nuanced intent over long sessions.
143+
144+
Potential ideas:
145+
146+
- Structured summary sections (goals, constraints, pending asks)
147+
- Weighted retention for user constraints and accepted decisions
148+
149+
### 5. Context observability in UI
150+
151+
Provide optional diagnostics showing what context is being sent in the next request.
152+
153+
Potential ideas:
154+
155+
- "Preview outgoing context" drawer section
156+
- Approximate byte-count indicator before send
157+
158+
### 6. Tool-call UX clarity
159+
160+
Continue improving copy and actions so users understand what is proposed versus what is already applied.
161+
162+
Potential ideas:
163+
164+
- Show target tab path in each action
165+
- Add optional diff preview before apply
166+
167+
### 7. Optional stricter policy profiles
168+
169+
Allow policy strictness presets depending on user goals.
170+
171+
Potential ideas:
172+
173+
- Conservative mode: fewer tool proposals, stronger minimal-change bias
174+
- Refactor mode: broader architectural proposal tolerance
175+
176+
## Validation status
177+
178+
Current strategy has focused Playwright coverage for the chat drawer behavior and context policy assertions in:
179+
180+
- playwright/github-byot-ai.spec.ts
181+
182+
## Scope note
183+
184+
This document is intentionally implementation-oriented. It describes current behavior and practical next improvements without locking future UX or API contracts.

0 commit comments

Comments
 (0)