Skip to content

Commit ea52ed2

Browse files
refactor: github chat.
1 parent 9afd83b commit ea52ed2

10 files changed

Lines changed: 114 additions & 80 deletions

docs/ai-chat-context-and-payload-strategy.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Each request includes a system prompt with policy guidance, then augments that p
1616

1717
Primary implementation:
1818

19-
- src/modules/github/chat-drawer/payload.js
19+
- src/modules/github/chat/payload.js
2020

2121
### 2. Repository context
2222

@@ -29,7 +29,7 @@ Each request includes repository targeting context as a dedicated system message
2929

3030
Primary implementation:
3131

32-
- src/modules/github/chat-drawer/drawer.js
32+
- src/modules/github/chat/drawer.js
3333

3434
### 3. Editor context (Send tab content)
3535

@@ -44,8 +44,8 @@ This context is designed to support dynamic proposal targeting by tab id/path an
4444

4545
Primary implementation:
4646

47-
- src/modules/github/chat-drawer/active-tab-context.js
48-
- src/modules/github/chat-drawer/drawer.js
47+
- src/modules/github/chat/active-tab-context.js
48+
- src/modules/github/chat/drawer.js
4949

5050
### 4. Tooling model
5151

@@ -62,9 +62,9 @@ Contract:
6262

6363
Primary implementation:
6464

65-
- src/modules/github/chat-drawer/proposals.js
66-
- src/modules/github/chat-drawer/tab-target-resolver.js
67-
- src/modules/github/chat-drawer/drawer.js
65+
- src/modules/github/chat/proposals.js
66+
- src/modules/github/chat/tab-target-resolver.js
67+
- src/modules/github/chat/drawer.js
6868

6969
### 5. Apply and undo behavior
7070

@@ -74,8 +74,8 @@ Primary implementation:
7474

7575
Primary implementation:
7676

77-
- src/modules/github/chat-drawer/drawer.js
78-
- src/modules/github/chat-drawer/tab-scoped-undo-state.js
77+
- src/modules/github/chat/drawer.js
78+
- src/modules/github/chat/tab-scoped-undo-state.js
7979

8080
### 6. Payload size controls and summary strategy
8181

@@ -88,7 +88,7 @@ The payload builder includes bounded-conversation controls:
8888

8989
Primary implementation:
9090

91-
- src/modules/github/chat-drawer/payload.js
91+
- src/modules/github/chat/payload.js
9292

9393
### 7. Fallback and transport behavior
9494

@@ -98,7 +98,7 @@ Primary implementation:
9898

9999
Primary implementation:
100100

101-
- src/modules/github/chat-drawer/drawer.js
101+
- src/modules/github/chat/drawer.js
102102
- src/modules/github/api/chat.js
103103

104104
## Why this approach

src/app.js

Lines changed: 15 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ import { persistClosedPrContextRecords } from './modules/app-core/pr-context-rec
5151
import { createPrContextStateChangeHandler } from './modules/app-core/pr-context-state-change-handler.js'
5252
import { createWorkspaceContextStatusController } from './modules/app-core/workspace-context-status-controller.js'
5353
import { createWorkspaceRecordAppliedHandler } from './modules/app-core/workspace-record-applied-handler.js'
54+
import { createGitHubChatWorkspaceActions } from './modules/app-core/github-chat-workspace-actions.js'
5455
import { createDiagnosticsUiController } from './modules/diagnostics/diagnostics-ui.js'
55-
import { createGitHubChatDrawer } from './modules/github/chat-drawer/drawer.js'
56+
import { createGitHubChatDrawer } from './modules/github/chat/drawer.js'
5657
import { createGitHubByotControls } from './modules/github/byot-controls.js'
5758
import {
5859
formatActivePrReference,
@@ -1041,6 +1042,18 @@ const onPrContextStateChange = createPrContextStateChangeHandler({
10411042
editedIndicatorVisibilityController,
10421043
})
10431044

1045+
const githubChatWorkspaceActions = createGitHubChatWorkspaceActions({
1046+
getActiveWorkspaceTab,
1047+
isStyleWorkspaceTab,
1048+
getCssSource: () => getCssSource(),
1049+
getJsxSource: () => getJsxSource(),
1050+
workspaceTabsState,
1051+
getDirtyStateForTabChange,
1052+
loadWorkspaceTabIntoEditor,
1053+
renderWorkspaceTabs,
1054+
queueWorkspaceSave: () => queueWorkspaceSave(),
1055+
})
1056+
10441057
const githubWorkflows = createGitHubWorkflowsSetup({
10451058
factories: {
10461059
createGitHubPrEditorSyncController,
@@ -1218,71 +1231,7 @@ const githubWorkflows = createGitHubWorkflowsSetup({
12181231
confirmAction: options => confirmAction(options),
12191232
setStatus,
12201233
showAppToast,
1221-
getActiveWorkspaceTabContext: () => {
1222-
const activeTab = getActiveWorkspaceTab()
1223-
if (!activeTab) {
1224-
return null
1225-
}
1226-
1227-
const isStylesTab = isStyleWorkspaceTab(activeTab)
1228-
1229-
return {
1230-
id: activeTab.id,
1231-
name: activeTab.name,
1232-
path: activeTab.path,
1233-
language: activeTab.language,
1234-
content: isStylesTab ? getCssSource() : getJsxSource(),
1235-
isActive: true,
1236-
}
1237-
},
1238-
getWorkspaceTabContexts: () => {
1239-
const activeTabId = workspaceTabsState.getActiveTabId()
1240-
return workspaceTabsState.getTabs().map(tab => {
1241-
const isActive = tab.id === activeTabId
1242-
const isStylesTab = isStyleWorkspaceTab(tab)
1243-
return {
1244-
id: tab.id,
1245-
name: tab.name,
1246-
path: tab.path,
1247-
language: tab.language,
1248-
isActive,
1249-
content: isActive
1250-
? isStylesTab
1251-
? getCssSource()
1252-
: getJsxSource()
1253-
: tab.content,
1254-
}
1255-
})
1256-
},
1257-
applyWorkspaceTabContent: ({ tabId, content }) => {
1258-
const tab = workspaceTabsState.getTab(tabId)
1259-
if (!tab || typeof content !== 'string') {
1260-
return null
1261-
}
1262-
1263-
const updatedTab = workspaceTabsState.upsertTab(
1264-
{
1265-
...tab,
1266-
content,
1267-
isDirty: getDirtyStateForTabChange(tab, content),
1268-
lastModified: Date.now(),
1269-
isActive: tab.isActive,
1270-
},
1271-
{ emitReason: 'chatApplyTabContent' },
1272-
)
1273-
1274-
if (!updatedTab) {
1275-
return null
1276-
}
1277-
1278-
if (updatedTab.isActive) {
1279-
loadWorkspaceTabIntoEditor(updatedTab)
1280-
}
1281-
1282-
renderWorkspaceTabs()
1283-
queueWorkspaceSave()
1284-
return updatedTab
1285-
},
1234+
...githubChatWorkspaceActions,
12861235
scheduleRender: () => {
12871236
if (
12881237
autoRenderToggle?.checked &&
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
const createGitHubChatWorkspaceActions = ({
2+
getActiveWorkspaceTab,
3+
isStyleWorkspaceTab,
4+
getCssSource,
5+
getJsxSource,
6+
workspaceTabsState,
7+
getDirtyStateForTabChange,
8+
loadWorkspaceTabIntoEditor,
9+
renderWorkspaceTabs,
10+
queueWorkspaceSave,
11+
}) => {
12+
const getActiveWorkspaceTabContext = () => {
13+
const activeTab = getActiveWorkspaceTab()
14+
if (!activeTab) {
15+
return null
16+
}
17+
18+
const isStylesTab = isStyleWorkspaceTab(activeTab)
19+
20+
return {
21+
id: activeTab.id,
22+
name: activeTab.name,
23+
path: activeTab.path,
24+
language: activeTab.language,
25+
content: isStylesTab ? getCssSource() : getJsxSource(),
26+
isActive: true,
27+
}
28+
}
29+
30+
const getWorkspaceTabContexts = () => {
31+
const activeTabId = workspaceTabsState.getActiveTabId()
32+
33+
return workspaceTabsState.getTabs().map(tab => {
34+
const isActive = tab.id === activeTabId
35+
const isStylesTab = isStyleWorkspaceTab(tab)
36+
37+
return {
38+
id: tab.id,
39+
name: tab.name,
40+
path: tab.path,
41+
language: tab.language,
42+
isActive,
43+
content: isActive ? (isStylesTab ? getCssSource() : getJsxSource()) : tab.content,
44+
}
45+
})
46+
}
47+
48+
const applyWorkspaceTabContent = ({ tabId, content }) => {
49+
const tab = workspaceTabsState.getTab(tabId)
50+
if (!tab || typeof content !== 'string') {
51+
return null
52+
}
53+
54+
const updatedTab = workspaceTabsState.upsertTab(
55+
{
56+
...tab,
57+
content,
58+
isDirty: getDirtyStateForTabChange(tab, content),
59+
lastModified: Date.now(),
60+
isActive: tab.isActive,
61+
},
62+
{ emitReason: 'chatApplyTabContent' },
63+
)
64+
65+
if (!updatedTab) {
66+
return null
67+
}
68+
69+
if (updatedTab.isActive) {
70+
loadWorkspaceTabIntoEditor(updatedTab)
71+
}
72+
73+
renderWorkspaceTabs()
74+
queueWorkspaceSave()
75+
return updatedTab
76+
}
77+
78+
return {
79+
getActiveWorkspaceTabContext,
80+
getWorkspaceTabContexts,
81+
applyWorkspaceTabContent,
82+
}
83+
}
84+
85+
export { createGitHubChatWorkspaceActions }
File renamed without changes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
toModelId,
1313
toRepositoryLabel,
1414
toRepositoryUrl,
15-
} from './chat-utils.js'
15+
} from './utils.js'
1616
import {
1717
buildActiveTabEditorContext,
1818
normalizeWorkspaceTabContext,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { toChatText } from './chat-utils.js'
1+
import { toChatText } from './utils.js'
22

33
const chatByteBudget = 120_000
44
const chatMaxSummaryChars = 3_600

src/modules/github/chat-drawer/proposals.js renamed to src/modules/github/chat/proposals.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { toChatText } from './chat-utils.js'
1+
import { toChatText } from './utils.js'
22

33
export const editorProposalTools = [
44
{
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)