feat: writes via chat — Reginald proposes, you approve inline (P4)
Completes "chat is the write-path" (decisions.md D1). Ask Reginald to re-estimate
or reprioritize an issue; it formulates a proposal, you approve it inline, and the
write runs through the same guarded apply_changes engine the Issue screen uses.
The model never writes — it proposes; the app owns approval + execution.
core (@commitea/core):
- propose_change tool declaration + REGINALD_SYSTEM updated ("never claim a change
is applied; you propose, the human approves").
- proposalsFor(args, currentLabels, title): pure — builds the concrete, non-noop
ChangeProposal(s) (change + label diff) for a propose_change request, dropping
invalid/unchanged axes. ChangeProposal / ProposeChangeArgs types.
app:
- model bridge executes propose_change by planning against the issue's current
labels (no write) and returns the proposals with the turn.
- useChat surfaces pending proposals + approve/dismiss; approve calls onApplyChange
(AppShell's guarded handler → PUT + board/forecast refetch), dismiss leaves it.
- ChatPanel renders each proposal as a propose-approve card (diff + Approve/Dismiss).
Verified: 101 core tests green (4 proposalsFor added), desktop typecheck clean,
14 fixture e2e green. Gated live e2e against gemma-4-26b: "Set the estimate on #3
to est/5d" → Reginald proposes "est/2d → est/5d" as an inline card, says it's
*proposed* not done; Dismiss leaves the repo untouched. The approve→write path is
the #41 engine (separately verified change→revert).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -9,10 +9,14 @@
|
||||
|
||||
import {
|
||||
buildProjectView,
|
||||
type ChangeProposal,
|
||||
type ChatMessage,
|
||||
createChatClient,
|
||||
describeChange,
|
||||
type ModelRouter,
|
||||
type ProjectView,
|
||||
proposalsFor,
|
||||
type ProposeChangeArgs,
|
||||
type QueryFilters,
|
||||
REGINALD_SYSTEM,
|
||||
REGINALD_TOOLS,
|
||||
@@ -80,12 +84,28 @@ export function registerModelIpc(): void {
|
||||
const model = await resolveLoadedModel(router.small.baseUrl, router.small.model)
|
||||
const chat = createChatClient({ ...router.small, model }, fetch)
|
||||
|
||||
// Proposals the model formulates this turn; the renderer approves them (the
|
||||
// write happens through gitea:applyChange, never inside the loop).
|
||||
const proposals: ChangeProposal[] = []
|
||||
|
||||
const execute = async (name: string, args: unknown) => {
|
||||
if (name !== 'query_project') return { error: `unknown tool: ${name}` }
|
||||
if (!client) return { error: 'gitea is not configured' }
|
||||
const snap = await reconcileSnapshot(client)
|
||||
const a = (args ?? {}) as { view: ProjectView; filters?: QueryFilters }
|
||||
return buildProjectView(a.view, a.filters, snap, new Date())
|
||||
if (name === 'query_project') {
|
||||
const snap = await reconcileSnapshot(client)
|
||||
const a = (args ?? {}) as { view: ProjectView; filters?: QueryFilters }
|
||||
return buildProjectView(a.view, a.filters, snap, new Date())
|
||||
}
|
||||
if (name === 'propose_change') {
|
||||
const a = (args ?? {}) as ProposeChangeArgs
|
||||
const issue = await client.getIssue(a.issue).catch(() => null)
|
||||
if (!issue) return { error: `issue #${a.issue} not found` }
|
||||
const built = proposalsFor(a, issue.labels, issue.title)
|
||||
proposals.push(...built)
|
||||
return built.length
|
||||
? { proposed: built.map((p) => ({ issue: a.issue, diff: describeChange(p.plan) })) }
|
||||
: { proposed: [], note: 'no change — already at that value' }
|
||||
}
|
||||
return { error: `unknown tool: ${name}` }
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -95,7 +115,7 @@ export function registerModelIpc(): void {
|
||||
tools: REGINALD_TOOLS,
|
||||
execute,
|
||||
})
|
||||
return { ok: true as const, content: turn.content, steps: turn.steps }
|
||||
return { ok: true as const, content: turn.content, steps: turn.steps, proposals }
|
||||
} catch (e) {
|
||||
return { ok: false as const, reason: 'error' as const, message: e instanceof Error ? e.message : String(e) }
|
||||
}
|
||||
|
||||
@@ -337,7 +337,7 @@ export function AppShell() {
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<ChatPanel onOpenDirectives={() => setView('directives')} offline={offline} />
|
||||
<ChatPanel onOpenDirectives={() => setView('directives')} offline={offline} onApplyChange={applyChange} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,21 +1,25 @@
|
||||
import React, { useEffect, useRef, useState } from 'react'
|
||||
|
||||
import { describeChange, type IssueChange } from '@commitea/core'
|
||||
|
||||
import { useChat } from '../../lib/use-chat.js'
|
||||
import { Icon, IconButton } from '../ui/index.js'
|
||||
import { Button, Icon, IconButton } from '../ui/index.js'
|
||||
|
||||
/**
|
||||
* Reginald's panel — chat is the write-path (decisions.md D1). Wired to the
|
||||
* model bridge via `useChat`: when a model is configured, sending drives a real
|
||||
* agent turn (query_project + prose); otherwise it echoes the scripted fixture
|
||||
* reply so the layout stays real. Writes still go through propose-approve.
|
||||
* model bridge via `useChat`: a configured model drives a real agent turn
|
||||
* (query_project + prose, propose_change for edits); otherwise it echoes the
|
||||
* scripted fixture reply. Proposed changes are approved inline here — the write
|
||||
* runs through `onApplyChange`, the same guarded handler the Issue screen uses.
|
||||
*/
|
||||
export interface ChatPanelProps {
|
||||
onOpenDirectives?: () => void
|
||||
offline?: boolean
|
||||
onApplyChange?: (change: IssueChange) => Promise<{ ok: boolean }>
|
||||
}
|
||||
|
||||
export function ChatPanel({ onOpenDirectives, offline }: ChatPanelProps) {
|
||||
const { msgs, thinking, live, model, steps, send: sendChat } = useChat()
|
||||
export function ChatPanel({ onOpenDirectives, offline, onApplyChange }: ChatPanelProps) {
|
||||
const { msgs, thinking, live, model, steps, proposals, send: sendChat, approve, dismiss } = useChat(onApplyChange)
|
||||
// shorten "google/gemma-4-26b-a4b-qat" → "gemma-4-26b" for the header chip
|
||||
const modelLabel = model ? (model.split('/').pop() ?? model).replace(/-(qat|instruct|it|gguf)$/i, '') : 'gemma-4'
|
||||
const [text, setText] = useState('')
|
||||
@@ -97,9 +101,36 @@ export function ChatPanel({ onOpenDirectives, offline }: ChatPanelProps) {
|
||||
{thinking ? <div style={{ font: 'var(--text-agent)', color: 'var(--ink-3)' }}>considering…</div> : null}
|
||||
{!thinking && steps.length ? (
|
||||
<div style={{ font: 'var(--text-caption)', color: 'var(--ink-3)', display: 'flex', alignItems: 'center', gap: 5 }}>
|
||||
<Icon name="eye" size={11} /> consulted {Array.from(new Set(steps.map((s) => s.replace('query_project', 'the project')))).join(', ')}
|
||||
<Icon name="eye" size={11} /> consulted {Array.from(new Set(steps.map((s) => s.replace('query_project', 'the project').replace('propose_change', 'the labels')))).join(', ')}
|
||||
</div>
|
||||
) : null}
|
||||
{proposals.map((p) => (
|
||||
<div
|
||||
key={`${p.change.issue}:${p.change.kind}`}
|
||||
style={{
|
||||
border: '1px solid var(--line-2)',
|
||||
borderRadius: 'var(--radius-2)',
|
||||
background: 'var(--paper-0)',
|
||||
padding: '10px 12px',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
gap: 8,
|
||||
}}
|
||||
>
|
||||
<div style={{ font: 'var(--text-caption)', color: 'var(--ink-3)', textTransform: 'uppercase', letterSpacing: 'var(--letter-spacing-wide)' }}>
|
||||
Proposed · #{p.change.issue}
|
||||
</div>
|
||||
<div style={{ font: '500 13px var(--font-mono)', color: 'var(--ink-1)' }}>{describeChange(p.plan)}</div>
|
||||
<div style={{ display: 'flex', gap: 8 }}>
|
||||
<Button size="sm" onClick={() => approve(p)} disabled={offline}>
|
||||
Approve
|
||||
</Button>
|
||||
<Button size="sm" variant="ghost" onClick={() => dismiss(p)}>
|
||||
Dismiss
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div style={{ padding: 14, borderTop: '1px solid var(--line-1)', flexShrink: 0 }}>
|
||||
|
||||
3
apps/desktop/src/renderer/src/global.d.ts
vendored
3
apps/desktop/src/renderer/src/global.d.ts
vendored
@@ -1,5 +1,6 @@
|
||||
import type {
|
||||
AgentStep,
|
||||
ChangeProposal,
|
||||
ChatMessage,
|
||||
DependencyEdge,
|
||||
GiteaIssue,
|
||||
@@ -32,7 +33,7 @@ export interface GiteaBridge {
|
||||
/** One agent turn's result. */
|
||||
export type ChatResult =
|
||||
| { ok: false; reason: 'unconfigured' | 'error'; message?: string }
|
||||
| { ok: true; content: string; steps: AgentStep[] }
|
||||
| { ok: true; content: string; steps: AgentStep[]; proposals: ChangeProposal[] }
|
||||
|
||||
/** The model bridge (Reginald) exposed by the preload over IPC. */
|
||||
export interface ModelBridge {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useCallback, useEffect, useRef, useState } from 'react'
|
||||
|
||||
import type { ChatMessage as WireMessage } from '@commitea/core'
|
||||
import type { ChangeProposal, ChatMessage as WireMessage, IssueChange } from '@commitea/core'
|
||||
|
||||
import { CANNED_REPLY, CHAT, type ChatMessage } from '../data/fixtures.js'
|
||||
|
||||
@@ -18,7 +18,11 @@ export interface ChatState {
|
||||
model: string | null
|
||||
/** Tools Reginald consulted on the last turn (for a subtle activity line). */
|
||||
steps: string[]
|
||||
/** Changes Reginald has proposed and is awaiting approval on. */
|
||||
proposals: ChangeProposal[]
|
||||
send: (text: string) => void
|
||||
approve: (p: ChangeProposal) => void
|
||||
dismiss: (p: ChangeProposal) => void
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -26,18 +30,23 @@ export interface ChatState {
|
||||
* turn through the main-process bridge (which runs the tool loop). Otherwise it
|
||||
* echoes the scripted fixture reply, so the layout stays real with no model and
|
||||
* fixture e2e is unaffected. The fixture greeting is display-only — only real
|
||||
* turns (`convo`) are sent to the model as history.
|
||||
* turns (`convo`) are sent to the model as history. `onApplyChange` performs an
|
||||
* approved write (the same handler the Issue screen uses — it refetches).
|
||||
*/
|
||||
export function useChat(): ChatState {
|
||||
export function useChat(onApplyChange?: (change: IssueChange) => Promise<{ ok: boolean }>): ChatState {
|
||||
const [seed, setSeed] = useState<ChatMessage[]>(CHAT)
|
||||
const [convo, setConvo] = useState<ChatMessage[]>([])
|
||||
const [thinking, setThinking] = useState(false)
|
||||
const [live, setLive] = useState(false)
|
||||
const [model, setModel] = useState<string | null>(null)
|
||||
const [steps, setSteps] = useState<string[]>([])
|
||||
const [proposals, setProposals] = useState<ChangeProposal[]>([])
|
||||
const convoRef = useRef(convo)
|
||||
convoRef.current = convo
|
||||
|
||||
const proposalKey = (p: ChangeProposal) => `${p.change.issue}:${p.change.kind}`
|
||||
const drop = (p: ChangeProposal) => setProposals((ps) => ps.filter((x) => proposalKey(x) !== proposalKey(p)))
|
||||
|
||||
useEffect(() => {
|
||||
let alive = true
|
||||
window.commitea.model
|
||||
@@ -63,6 +72,7 @@ export function useChat(): ChatState {
|
||||
setConvo(nextConvo)
|
||||
setThinking(true)
|
||||
setSteps([])
|
||||
setProposals([])
|
||||
|
||||
if (!live) {
|
||||
window.setTimeout(() => {
|
||||
@@ -82,6 +92,7 @@ export function useChat(): ChatState {
|
||||
setThinking(false)
|
||||
if (res.ok) {
|
||||
setSteps(res.steps.map((s) => s.tool))
|
||||
setProposals(res.proposals)
|
||||
setConvo((c) => [...c, { from: 'agent', text: res.content || '…' }])
|
||||
} else {
|
||||
setConvo((c) => [
|
||||
@@ -101,5 +112,30 @@ export function useChat(): ChatState {
|
||||
[live],
|
||||
)
|
||||
|
||||
return { msgs: [...seed, ...convo], thinking, live, model, steps, send }
|
||||
const approve = useCallback(
|
||||
(p: ChangeProposal) => {
|
||||
if (!onApplyChange) return
|
||||
drop(p)
|
||||
const label = p.plan.added[0] ?? p.plan.removed[0] ?? 'change'
|
||||
void onApplyChange(p.change).then((res) => {
|
||||
setConvo((c) => [
|
||||
...c,
|
||||
{
|
||||
from: 'agent',
|
||||
text: res.ok
|
||||
? `Done — #${p.change.issue} is now ${label}. The plan's been re-run.`
|
||||
: `That didn't take — #${p.change.issue} is unchanged.`,
|
||||
},
|
||||
])
|
||||
})
|
||||
},
|
||||
[onApplyChange],
|
||||
)
|
||||
|
||||
const dismiss = useCallback((p: ChangeProposal) => {
|
||||
drop(p)
|
||||
setConvo((c) => [...c, { from: 'agent', text: `Left #${p.change.issue} as it was.` }])
|
||||
}, [])
|
||||
|
||||
return { msgs: [...seed, ...convo], thinking, live, model, steps, proposals, send, approve, dismiss }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user