@brimveyn/aimux 1.7.4 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/README.md +27 -15
  2. package/package.json +2 -2
  3. package/src/app-runtime/auto-commit-driver.ts +286 -0
  4. package/src/app-runtime/auto-commit-ref.ts +20 -0
  5. package/src/app-runtime/backend-attach-runtime.ts +3 -1
  6. package/src/app-runtime/session-actions.ts +7 -2
  7. package/src/app-runtime/side-effects.ts +99 -1
  8. package/src/app-runtime/use-auto-commit-driver.ts +133 -0
  9. package/src/app-runtime/use-terminal-resize.ts +20 -12
  10. package/src/app.tsx +59 -22
  11. package/src/auto-commit/default-auto-commit-prompt.md +46 -0
  12. package/src/auto-commit/headless-commands.ts +40 -0
  13. package/src/auto-commit/output-parser.ts +21 -0
  14. package/src/auto-commit/prompt-loader.ts +33 -0
  15. package/src/auto-commit/staging-mode.ts +5 -0
  16. package/src/auto-commit/strip-ansi.ts +13 -0
  17. package/src/auto-commit/suggestion-runner.ts +55 -0
  18. package/src/auto-commit/working-tree-hash.ts +24 -0
  19. package/src/config.ts +24 -0
  20. package/src/daemon/session-registry.ts +1 -0
  21. package/src/index.tsx +1 -1
  22. package/src/input/keymap/help-entries.ts +4 -4
  23. package/src/input/modes/bridge.ts +7 -0
  24. package/src/input/modes/transitions.ts +6 -2
  25. package/src/input/modes/types.ts +5 -0
  26. package/src/ipc/manager-protocol.ts +2 -2
  27. package/src/ipc/protocol.ts +2 -8
  28. package/src/pty/assistant-status-detector.ts +1 -1
  29. package/src/pty/terminal-snapshot.ts +38 -4
  30. package/src/services/ai-usage/adapters/claude.ts +215 -0
  31. package/src/services/ai-usage/adapters/codex.ts +242 -0
  32. package/src/services/ai-usage/cache.ts +60 -0
  33. package/src/services/ai-usage/pace.ts +79 -0
  34. package/src/services/ai-usage/provider.ts +107 -0
  35. package/src/services/ai-usage/spawn.ts +49 -0
  36. package/src/services/ai-usage/types.ts +51 -0
  37. package/src/session-backend/local-session-backend.ts +10 -2
  38. package/src/state/ai-usage-store.ts +36 -0
  39. package/src/state/reducers/auto-commit-state.ts +59 -0
  40. package/src/state/reducers/modal-state.ts +119 -2
  41. package/src/state/reducers/session-state.ts +26 -14
  42. package/src/state/session-persistence.ts +14 -5
  43. package/src/state/store.ts +24 -14
  44. package/src/state/types.ts +62 -2
  45. package/src/state/workspace-save.ts +4 -0
  46. package/src/ui/components/ai-usage-indicator.tsx +163 -0
  47. package/src/ui/components/ai-usage-modal.tsx +186 -0
  48. package/src/ui/components/create-session-modal.tsx +2 -2
  49. package/src/ui/components/git-commit-modal.tsx +167 -18
  50. package/src/ui/components/session-bar.tsx +2 -2
  51. package/src/ui/components/session-picker-modal.tsx +4 -4
  52. package/src/ui/components/sidebar.tsx +3 -1
  53. package/src/ui/components/status-bar.tsx +2 -0
  54. package/src/ui/components/terminal-pane.tsx +18 -3
  55. package/src/ui/root.tsx +14 -2
  56. package/src/ui/status-bar-model.ts +1 -1
@@ -1,3 +1,10 @@
1
+ import { isAutoCommitEnabled } from '@brimveyn/aimux-config'
2
+ import { useEffect, useState } from 'react'
3
+
4
+ import type { ModeId } from '../../input/modes/types'
5
+
6
+ import { useAppStore } from '../../state/app-store'
7
+ import { dispatchGlobal, runSideEffectGlobal } from '../../state/dispatch-ref'
1
8
  import { useTokens } from '../theme'
2
9
  import { uiTokens } from '../ui-tokens'
3
10
  import { InputField } from './input-field'
@@ -8,32 +15,174 @@ interface GitCommitModalProps {
8
15
  title: string
9
16
  body: string
10
17
  cursorPos: number
18
+ stage: 'edit' | 'generating' | 'confirm'
19
+ assistant?: string
20
+ model?: string
21
+ }
22
+
23
+ const SPINNER_FRAMES = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']
24
+ const SPINNER_INTERVAL_MS = 80
25
+
26
+ function useSpinnerFrame(active: boolean): string {
27
+ const [index, setIndex] = useState(0)
28
+ useEffect(() => {
29
+ if (!active) return
30
+ const id = setInterval(
31
+ () => setIndex((i) => (i + 1) % SPINNER_FRAMES.length),
32
+ SPINNER_INTERVAL_MS
33
+ )
34
+ return () => clearInterval(id)
35
+ }, [active])
36
+ return SPINNER_FRAMES[index] ?? '⠋'
37
+ }
38
+
39
+ function pickModeId(stage: 'edit' | 'generating' | 'confirm'): ModeId {
40
+ if (stage === 'generating') return 'modal.git-commit.generating'
41
+ if (stage === 'confirm') return 'modal.git-commit.confirm'
42
+ return 'modal.git-commit'
43
+ }
44
+
45
+ function pickShellTitle(stage: 'edit' | 'generating' | 'confirm'): string {
46
+ if (stage === 'generating') return 'Auto-commit'
47
+ if (stage === 'confirm') return 'Auto-commit (stage all + commit)'
48
+ return 'Commit'
49
+ }
50
+
51
+ function GeneratingOverlay({ assistant, model }: { assistant?: string; model?: string }) {
52
+ const t = useTokens()
53
+ const frame = useSpinnerFrame(true)
54
+ const providerLabel = [assistant, model].filter(Boolean).join(' · ') || 'configured provider'
55
+ return (
56
+ <box
57
+ flexDirection="column"
58
+ alignItems="center"
59
+ justifyContent="center"
60
+ paddingTop={2}
61
+ paddingBottom={2}
62
+ >
63
+ <text fg={t.palette.primary}>🪄</text>
64
+ <box marginTop={1} flexDirection="row" gap={1}>
65
+ <text fg={t.palette.primary}>{frame}</text>
66
+ <text fg={t.palette.ink}>Generating commit message</text>
67
+ </box>
68
+ <text fg={t.muted}>via {providerLabel}</text>
69
+ <box marginTop={1}>
70
+ <text fg={t.muted}>Esc to cancel</text>
71
+ </box>
72
+ </box>
73
+ )
11
74
  }
12
75
 
13
- export function GitCommitModal({ activeField, body, cursorPos, title }: GitCommitModalProps) {
76
+ export function GitCommitModal({
77
+ activeField,
78
+ assistant,
79
+ body,
80
+ cursorPos,
81
+ model,
82
+ stage,
83
+ title,
84
+ }: GitCommitModalProps) {
14
85
  const t = useTokens()
15
86
  const titleActive = activeField === 'title'
16
87
  const bodyActive = activeField === 'body'
88
+ const isConfirm = stage === 'confirm'
89
+ const isGenerating = stage === 'generating'
90
+ const currentSessionId = useAppStore((s) => s.currentSessionId)
91
+ const bgKind = useAppStore((s) => {
92
+ const id = s.currentSessionId
93
+ return id ? s.autoCommit.bySession[id]?.kind : undefined
94
+ })
95
+ const isBgGenerating = bgKind === 'generating'
96
+ const showBgSpinner = isBgGenerating && !isConfirm && !isGenerating
97
+ const bgSpinnerFrame = useSpinnerFrame(showBgSpinner)
98
+ const stagedCount = useAppStore(
99
+ (s) => s.gitPanel.files.filter((f) => f.section === 'staged').length
100
+ )
101
+
102
+ const onAutoCommitClick = (): void => {
103
+ const hasTitle = title.trim().length > 0
104
+ if (hasTitle || !currentSessionId) {
105
+ dispatchGlobal({ type: 'git-commit-enter-confirm' })
106
+ return
107
+ }
108
+ if (bgKind === 'ready') {
109
+ dispatchGlobal({ sessionId: currentSessionId, type: 'git-commit-use-background-suggestion' })
110
+ return
111
+ }
112
+ dispatchGlobal({ sessionId: currentSessionId, type: 'git-commit-enter-generating' })
113
+ if (bgKind !== 'generating') {
114
+ runSideEffectGlobal({ sessionId: currentSessionId, type: 'generate-auto-commit-now' })
115
+ }
116
+ }
117
+
118
+ const modeId = pickModeId(stage)
119
+ const shellTitle = pickShellTitle(stage)
17
120
 
18
121
  return (
19
- <ModalShell title="Commit" keybindsModeId="modal.git-commit" width={uiTokens.modalWidth.xl}>
20
- <box flexDirection="column">
21
- <text fg={titleActive ? t.palette.ink : t.muted}>Title</text>
22
- <InputField
23
- active={titleActive}
24
- cursorPos={titleActive ? cursorPos : undefined}
25
- value={title}
26
- />
27
- </box>
122
+ <ModalShell title={shellTitle} keybindsModeId={modeId} width={uiTokens.modalWidth.xl}>
123
+ {isGenerating ? <GeneratingOverlay assistant={assistant} model={model} /> : null}
28
124
 
29
- <box flexDirection="column">
30
- <text fg={bodyActive ? t.palette.ink : t.muted}>Body (optional)</text>
31
- <InputField
32
- active={bodyActive}
33
- cursorPos={bodyActive ? cursorPos : undefined}
34
- value={body}
35
- />
36
- </box>
125
+ {isConfirm ? (
126
+ <box flexDirection="column">
127
+ {stagedCount > 0 ? (
128
+ <text fg={t.palette.warning}>
129
+ Commit will include the <strong>{stagedCount} staged file(s)</strong> only.
130
+ </text>
131
+ ) : (
132
+ <text fg={t.palette.warning}>
133
+ <strong>git add -A</strong> will stage every change before committing.
134
+ </text>
135
+ )}
136
+ <text fg={t.muted}>Enter to confirm · Esc to cancel · edits below still apply.</text>
137
+ </box>
138
+ ) : null}
139
+
140
+ {isGenerating ? null : (
141
+ <>
142
+ <box flexDirection="column">
143
+ <text fg={titleActive ? t.palette.ink : t.muted}>Title</text>
144
+ <InputField
145
+ active={titleActive}
146
+ cursorPos={titleActive ? cursorPos : undefined}
147
+ value={title}
148
+ />
149
+ </box>
150
+
151
+ <box flexDirection="column">
152
+ <text fg={bodyActive ? t.palette.ink : t.muted}>Body (optional)</text>
153
+ <InputField
154
+ active={bodyActive}
155
+ cursorPos={bodyActive ? cursorPos : undefined}
156
+ value={body}
157
+ />
158
+ </box>
159
+ </>
160
+ )}
161
+
162
+ {isConfirm || isGenerating || !isAutoCommitEnabled() ? null : (
163
+ <box flexDirection="row" gap={1} marginTop={1} alignItems="center">
164
+ <box
165
+ border
166
+ borderColor={t.palette.primary}
167
+ paddingLeft={1}
168
+ paddingRight={1}
169
+ flexDirection="row"
170
+ gap={1}
171
+ alignItems="center"
172
+ onMouseDown={(event) => {
173
+ event.preventDefault()
174
+ event.stopPropagation()
175
+ onAutoCommitClick()
176
+ }}
177
+ >
178
+ {showBgSpinner ? <text fg={t.palette.primary}>{bgSpinnerFrame}</text> : null}
179
+ <text fg={t.palette.primary}>
180
+ <strong>Auto-commit</strong>
181
+ </text>
182
+ </box>
183
+ <text fg={t.muted}>C-a · stages all changes (AI-suggests message if empty)</text>
184
+ </box>
185
+ )}
37
186
  </ModalShell>
38
187
  )
39
188
  }
@@ -124,7 +124,7 @@ export function SessionBar() {
124
124
  onMouseDragEnd={cancelDrag}
125
125
  rightClickMenu={[
126
126
  [
127
- 'Rename',
127
+ 'Rename workspace',
128
128
  () =>
129
129
  dispatchGlobal({
130
130
  initialName: session.name,
@@ -134,7 +134,7 @@ export function SessionBar() {
134
134
  }),
135
135
  ],
136
136
  [
137
- 'Close',
137
+ 'Delete workspace',
138
138
  () => runSideEffectGlobal({ sessionId: session.id, type: 'delete-session' }),
139
139
  ],
140
140
  ]}
@@ -31,8 +31,8 @@ function formatSessionLine(
31
31
  }
32
32
 
33
33
  function getEmptyStateMessage(hasFilter: boolean): string {
34
- if (hasFilter) return 'No matching sessions.'
35
- return 'No sessions yet. Press Enter or n to create your first session.'
34
+ if (hasFilter) return 'No matching workspaces.'
35
+ return 'No workspaces yet. Press Enter or n to create your first workspace.'
36
36
  }
37
37
 
38
38
  export function SessionPickerModal({
@@ -72,7 +72,7 @@ export function SessionPickerModal({
72
72
  onClick: () => runSideEffectGlobal({ type: 'confirm-selected-session' }),
73
73
  title: (
74
74
  <text fg={selectedIndex === filtered.length ? t.palette.ink : t.muted}>
75
- Create new session
75
+ Create new workspace
76
76
  </text>
77
77
  ),
78
78
  }
@@ -81,7 +81,7 @@ export function SessionPickerModal({
81
81
 
82
82
  return (
83
83
  <Picker
84
- title="Sessions"
84
+ title="Workspaces"
85
85
  keybindsModeId="modal.session-picker.filtering"
86
86
  width={uiTokens.modalWidth.lg}
87
87
  gap={1}
@@ -63,7 +63,9 @@ const SidebarTop = memo(function SidebarTop({ contentWidth }: { contentWidth: nu
63
63
  <text fg={tokens.palette.primary}>
64
64
  <strong>aimux</strong>
65
65
  </text>
66
- <text fg={tokens.accent}>{currentSession ? currentSession.name : 'No session selected'}</text>
66
+ <text fg={tokens.accent}>
67
+ {currentSession ? currentSession.name : 'No workspace selected'}
68
+ </text>
67
69
  {branch ? (
68
70
  <box flexDirection="row">
69
71
  <text fg={tokens.palette.primary}>{'\u{e702}'} </text>
@@ -5,6 +5,7 @@ import { useAppStore } from '../../state/app-store'
5
5
  import { useKeymap } from '../keymap-context'
6
6
  import { getStatusBarModel } from '../status-bar-model'
7
7
  import { getCurrentTokens, useBg, useTokens } from '../theme'
8
+ import { AIUsageIndicator } from './ai-usage-indicator'
8
9
 
9
10
  function getModeColor(focusMode: AppState['focusMode']): string {
10
11
  const t = getCurrentTokens()
@@ -65,6 +66,7 @@ export function StatusBar() {
65
66
  <text fg={t.muted}>{model.right}</text>
66
67
  <box flexDirection="row" gap={2}>
67
68
  {model.help ? <text fg={t.muted}>{model.help}</text> : null}
69
+ <AIUsageIndicator />
68
70
  <text fg={t.hover}>v{APP_VERSION}</text>
69
71
  </box>
70
72
  </box>
@@ -33,7 +33,7 @@ function getTitle(
33
33
  focusMode: TerminalPaneProps['focusMode']
34
34
  ): string {
35
35
  if (!tab) {
36
- return 'No active session'
36
+ return 'No active workspace'
37
37
  }
38
38
 
39
39
  if (isActive && focusMode === 'terminal-input') {
@@ -107,7 +107,7 @@ const TerminalViewport = memo(function TerminalViewport({
107
107
  }
108
108
 
109
109
  return (
110
- <text fg={t.palette.ink}>{buffer.length > 0 ? buffer : 'Waiting for session output...'}</text>
110
+ <text fg={t.palette.ink}>{buffer.length > 0 ? buffer : 'Waiting for workspace output...'}</text>
111
111
  )
112
112
  })
113
113
 
@@ -239,6 +239,19 @@ export function TerminalPane({
239
239
  <text fg={t.palette.primary}>Ctrl+n</text>
240
240
  <text fg={t.muted}> to launch an assistant</text>
241
241
  </box>
242
+ <box
243
+ flexDirection="row"
244
+ justifyContent="center"
245
+ marginTop={1}
246
+ paddingX={2}
247
+ backgroundColor={t.selected}
248
+ onMouseDown={(event) => {
249
+ event.stopPropagation()
250
+ dispatchGlobal({ type: 'open-new-tab-modal' })
251
+ }}
252
+ >
253
+ <text fg={t.palette.ink}>New assistant</text>
254
+ </box>
242
255
  </box>
243
256
  ) : (
244
257
  <box
@@ -258,7 +271,9 @@ export function TerminalPane({
258
271
  )}
259
272
  </ContextMenuBox>
260
273
  {tab?.status === 'disconnected' ? (
261
- <text fg={t.palette.warning}>Restored snapshot. Press Ctrl+r to restart this session.</text>
274
+ <text fg={t.palette.warning}>
275
+ Restored snapshot. Press Ctrl+r to restart this workspace.
276
+ </text>
262
277
  ) : null}
263
278
  {tab?.errorMessage ? <text fg={t.palette.error}>{tab.errorMessage}</text> : null}
264
279
  </box>
package/src/ui/root.tsx CHANGED
@@ -1,13 +1,14 @@
1
1
  import type { MouseEvent } from '@opentui/core'
2
2
 
3
3
  import type { TerminalContentOrigin } from '../input/raw-input-handler'
4
- import type { ModalState, SessionRecord, SnippetRecord } from '../state/types'
4
+ import type { FocusMode, ModalState, SessionRecord, SnippetRecord } from '../state/types'
5
5
  import type { ThemeId } from './themes'
6
6
 
7
7
  import { useAppStore } from '../state/app-store'
8
8
  import { dispatchGlobal } from '../state/dispatch-ref'
9
9
  import { getGitPaneWidthFromRatio } from '../state/git-pane-sizing'
10
10
  import { getTreeForTab, PANE_BORDER, type SplitDirection } from '../state/layout-tree'
11
+ import { AIUsageModal } from './components/ai-usage-modal'
11
12
  import { ContextMenuBox } from './components/context-menu-box'
12
13
  import { ContextMenuOverlay } from './components/context-menu-overlay'
13
14
  import { CreateSessionModal } from './components/create-session-modal'
@@ -78,6 +79,9 @@ function renderModal(
78
79
  themeId: ThemeId
79
80
  createSessionFields: { directoryQuery: string; sessionName: string }
80
81
  snippetEditorFields: { snippetName: string; snippetContent: string }
82
+ focusMode: FocusMode
83
+ activeAssistant?: string
84
+ autoCommitModel?: string
81
85
  }
82
86
  ) {
83
87
  switch (modal.type) {
@@ -107,7 +111,7 @@ function renderModal(
107
111
  case 'session-name':
108
112
  return (
109
113
  <SessionNameModal
110
- title={modal.sessionTargetId ? 'Rename session' : 'Create session'}
114
+ title={modal.sessionTargetId ? 'Rename workspace' : 'Create workspace'}
111
115
  value={modal.editBuffer ?? ''}
112
116
  />
113
117
  )
@@ -168,6 +172,8 @@ function renderModal(
168
172
  cursorPos={modal.cursorPos}
169
173
  />
170
174
  )
175
+ case 'ai-usage':
176
+ return <AIUsageModal />
171
177
  case 'git-commit': {
172
178
  const titleText =
173
179
  modal.activeField === 'title' ? (modal.editBuffer ?? '') : modal.contentBuffer
@@ -176,8 +182,11 @@ function renderModal(
176
182
  return (
177
183
  <GitCommitModal
178
184
  activeField={modal.activeField}
185
+ assistant={options.activeAssistant}
179
186
  body={bodyText}
180
187
  cursorPos={modal.cursorPos ?? (modal.editBuffer ?? '').length}
188
+ model={options.autoCommitModel}
189
+ stage={modal.stage}
181
190
  title={titleText}
182
191
  />
183
192
  )
@@ -273,10 +282,12 @@ export function RootView({
273
282
  <PendingChordOverlay />
274
283
  <ContextMenuOverlay />
275
284
  {renderModal(modal, {
285
+ activeAssistant: activeTab?.assistant,
276
286
  createSessionFields,
277
287
  currentSessionId,
278
288
  currentTabCount: tabs.length,
279
289
  customCommands,
290
+ focusMode,
280
291
  sessions,
281
292
  snippetEditorFields,
282
293
  snippets,
@@ -379,6 +390,7 @@ export function RootView({
379
390
  currentSessionId,
380
391
  currentTabCount: tabs.length,
381
392
  customCommands,
393
+ focusMode,
382
394
  sessions,
383
395
  snippetEditorFields,
384
396
  snippets,
@@ -61,7 +61,7 @@ export function getStatusBarModel(
61
61
  const currentSession = state.currentSessionId
62
62
  ? state.sessions.find((session) => session.id === state.currentSessionId)
63
63
  : undefined
64
- const sessionName = currentSession?.name ?? 'no session'
64
+ const sessionName = currentSession?.name ?? 'no workspace'
65
65
  const sessionLabel = currentSession?.projectPath
66
66
  ? `${sessionName} (${abbreviatePath(currentSession.projectPath)})`
67
67
  : sessionName