feat: add repository context to quick chats (#1679)
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
# 0038: Quick Chat Repository Isolation
|
||||
|
||||
**Status:** accepted
|
||||
**Date:** 2026-07-14
|
||||
**Area:** backend, frontend
|
||||
|
||||
## Context
|
||||
|
||||
Quick chat already creates an ephemeral task and can associate one repository, but it resolves
|
||||
the workspace default executor. When that executor is local, selecting another branch can
|
||||
switch the branch in the user's source checkout. Adding multiple repositories amplifies that
|
||||
risk, while cloning every repository into a new quick-chat-specific directory would duplicate
|
||||
the existing task materialization and cleanup systems.
|
||||
|
||||
## Decision
|
||||
|
||||
Repo-backed quick chats use the built-in worktree executor and the existing multi-repository
|
||||
task preparation pipeline. The quick-chat request accepts an ordered repository list and the
|
||||
backend enforces the worktree executor whenever that list is non-empty. Repo-less chats retain
|
||||
the current scratch workspace and resolved default executor.
|
||||
|
||||
The worktrees remain owned by the ephemeral task and use the existing task environment,
|
||||
session worktree, rollback, deletion, expiration, and garbage-collection paths. The selected
|
||||
base branch supplies committed repository state; uncommitted source-checkout changes are not
|
||||
copied.
|
||||
|
||||
## Consequences
|
||||
|
||||
Concurrent chats can target the same repository and base branch without mutating the user's
|
||||
checkout. Materialization stays smaller and faster than a full clone, and no second cleanup
|
||||
system is introduced. A chat does not see uncommitted local changes, and repository-backed
|
||||
quick chats always run through the local worktree executor rather than a workspace default
|
||||
remote executor in this initial version.
|
||||
|
||||
## Alternatives Considered
|
||||
|
||||
- **Clone every repository under `quick-chat/`.** Rejected because it duplicates clone,
|
||||
credential, preparation, persistence, and cleanup behavior already owned by task worktrees.
|
||||
- **Use the workspace default executor unchanged.** Rejected because a local executor may
|
||||
checkout the requested branch in the user's source directory.
|
||||
- **Copy the current working directory.** Rejected because it silently includes uncommitted or
|
||||
ignored files and has unclear performance and privacy behavior.
|
||||
@@ -43,3 +43,4 @@ Read individual ADRs for full context. Create new ones via `/record decision` or
|
||||
| 0035 | [Version AgentReady events by prompt generation](0035-version-agent-ready-events-by-prompt-generation.md) | accepted | backend | 2026-07-14 |
|
||||
| 0036 | [Normalize ACP shell output at the adapter boundary](0036-normalize-acp-shell-output-at-adapter-boundary.md) | accepted | backend, frontend, protocol | 2026-07-14 |
|
||||
| 0037 | [Resource-aware frontend unit tests](0037-resource-aware-frontend-unit-tests.md) | accepted | frontend, infra | 2026-07-14 |
|
||||
| 0038 | [Quick Chat Repository Isolation](0038-quick-chat-repository-isolation.md) | accepted | backend, frontend | 2026-07-14 |
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
---
|
||||
spec: docs/specs/tasks/quick-chat-repository-context.md
|
||||
created: 2026-07-14
|
||||
status: complete
|
||||
---
|
||||
|
||||
# Implementation Plan: Quick Chat Repository Context
|
||||
|
||||
## Overview
|
||||
|
||||
Extend quick chat's existing ephemeral-task contract to carry ordered repository inputs and
|
||||
enforce isolated worktree preparation. Then extract the controlled workspace repo/branch chips
|
||||
from task creation, replace the agent-card picker with a responsive setup form, and verify the
|
||||
desktop and mobile flows.
|
||||
|
||||
## Backend
|
||||
|
||||
- Extend `httpStartQuickChatRequest` in
|
||||
`apps/backend/internal/task/handlers/task_http_handlers.go` with plural repository inputs.
|
||||
- Normalize plural or legacy singleton fields into `[]service.TaskRepositoryInput`, reject mixed
|
||||
shapes, and force `models.ExecutorIDWorktree` for repo-backed starts.
|
||||
- Preserve eager launch and rollback through `Service.DeleteTask`.
|
||||
|
||||
## Frontend
|
||||
|
||||
- Add the plural request type in `apps/web/lib/api/domains/workspace-api.ts`.
|
||||
- Extract a controlled workspace repository/branch chip component from
|
||||
`apps/web/components/task-create-dialog-repo-chips.tsx` without moving task-only URL/folder and
|
||||
fresh-branch modes.
|
||||
- Add `apps/web/components/quick-chat/quick-chat-setup.tsx`; use the shared agent selector,
|
||||
repository chips, approved helper copy, and responsive footer.
|
||||
- Keep start supersession and orphan cleanup in `use-quick-chat-modal.ts`.
|
||||
|
||||
## Tests
|
||||
|
||||
- Backend handler tests cover plural normalization, compatibility, isolation, and validation.
|
||||
- Frontend unit tests cover payload construction/default selection logic and supersession.
|
||||
- Existing task chip tests guard the extraction against regressions.
|
||||
|
||||
## E2E Tests
|
||||
|
||||
- Extend `apps/web/e2e/tests/chat/quick-chat.spec.ts` for setup helper copy and repo-backed start.
|
||||
- Add a `mobile-*.spec.ts` flow for the same user value and narrow layout.
|
||||
|
||||
## Implementation Waves
|
||||
|
||||
Wave 1:
|
||||
- [x] [task-01-backend-contract](task-01-backend-contract.md)
|
||||
- [x] [task-02-shared-repository-chips](task-02-shared-repository-chips.md)
|
||||
|
||||
Wave 2:
|
||||
- [x] [task-03-quick-chat-setup](task-03-quick-chat-setup.md)
|
||||
|
||||
Wave 3:
|
||||
- [x] [task-04-e2e-verification](task-04-e2e-verification.md)
|
||||
@@ -0,0 +1,23 @@
|
||||
---
|
||||
id: "01-backend-contract"
|
||||
title: "Backend quick-chat repository contract"
|
||||
status: done
|
||||
wave: 1
|
||||
depends_on: []
|
||||
plan: "plan.md"
|
||||
spec: "../../specs/tasks/quick-chat-repository-context.md"
|
||||
---
|
||||
|
||||
# Task 01: Backend quick-chat repository contract
|
||||
|
||||
**Acceptance:** plural repository inputs preserve order and branches; legacy singleton input
|
||||
remains accepted; repo-backed starts always launch with the worktree executor.
|
||||
|
||||
**Verification:** `make -C apps/backend test` from the repository root.
|
||||
|
||||
**Files likely touched:** `apps/backend/internal/task/handlers/task_http_handlers.go`,
|
||||
`apps/backend/internal/task/handlers/task_http_handlers_test.go`.
|
||||
|
||||
**Dependencies:** None.
|
||||
|
||||
**Output contract:** summarize contract changes, tests run, files changed, risks, and status.
|
||||
@@ -0,0 +1,23 @@
|
||||
---
|
||||
id: "02-shared-repository-chips"
|
||||
title: "Shared controlled repository chips"
|
||||
status: done
|
||||
wave: 1
|
||||
depends_on: []
|
||||
plan: "plan.md"
|
||||
spec: "../../specs/tasks/quick-chat-repository-context.md"
|
||||
---
|
||||
|
||||
# Task 02: Shared controlled repository chips
|
||||
|
||||
**Acceptance:** task creation and quick chat can use one controlled workspace repo/branch chip
|
||||
surface; task-only source modes remain unchanged; quick chat can exclude duplicate repos.
|
||||
|
||||
**Verification:** run the focused repository-chip Vitest files from `apps/`.
|
||||
|
||||
**Files likely touched:** `apps/web/components/task-create-dialog-repo-chips.tsx`, new shared
|
||||
component and tests.
|
||||
|
||||
**Dependencies:** None.
|
||||
|
||||
**Output contract:** summarize extraction, tests run, files changed, risks, and status.
|
||||
@@ -0,0 +1,22 @@
|
||||
---
|
||||
id: "03-quick-chat-setup"
|
||||
title: "Responsive quick-chat setup"
|
||||
status: done
|
||||
wave: 2
|
||||
depends_on: ["01-backend-contract", "02-shared-repository-chips"]
|
||||
plan: "plan.md"
|
||||
spec: "../../specs/tasks/quick-chat-repository-context.md"
|
||||
---
|
||||
|
||||
# Task 03: Responsive quick-chat setup
|
||||
|
||||
**Acceptance:** users select an agent and optional repository branches before starting; first-use
|
||||
and field helper copy render correctly; failed/superseded starts preserve current cleanup rules.
|
||||
|
||||
**Verification:** run focused quick-chat Vitest tests and web typecheck from `apps/web`.
|
||||
|
||||
**Files likely touched:** quick-chat modal/hook/setup files and workspace API types.
|
||||
|
||||
**Dependencies:** Tasks 01 and 02.
|
||||
|
||||
**Output contract:** summarize UI/state changes, tests run, files changed, risks, and status.
|
||||
@@ -0,0 +1,27 @@
|
||||
---
|
||||
id: "04-e2e-verification"
|
||||
title: "Quick-chat repository E2E verification"
|
||||
status: done
|
||||
wave: 3
|
||||
depends_on: ["03-quick-chat-setup"]
|
||||
plan: "plan.md"
|
||||
spec: "../../specs/tasks/quick-chat-repository-context.md"
|
||||
---
|
||||
|
||||
# Task 04: Quick-chat repository E2E verification
|
||||
|
||||
**Acceptance:** desktop and mobile flows start a repo-backed quick chat; source checkout remains
|
||||
unchanged; controls fit narrow viewports.
|
||||
|
||||
**Verification:** from `apps/web`, run
|
||||
`pnpm e2e:run --host --no-build --project chromium -- tests/chat/quick-chat.spec.ts`
|
||||
(6 passed) and
|
||||
`pnpm e2e:run --host --no-build --project mobile-chrome -- tests/chat/mobile-quick-chat-repository.spec.ts`
|
||||
(1 passed). From the repository root, run `make fmt`, `make typecheck`, `make test`, and
|
||||
`make lint`; all completed successfully.
|
||||
|
||||
**Files likely touched:** quick-chat desktop/mobile E2E specs.
|
||||
|
||||
**Dependencies:** Task 03.
|
||||
|
||||
**Output contract:** report scenarios, commands, results, artifacts, risks, and status.
|
||||
@@ -51,6 +51,7 @@ Kandev's task model: documents, execution stages, labels, blocker escalation, su
|
||||
| [wip-limit-pull-system](tasks/wip-limit-pull-system.md) | building |
|
||||
| [multi-branch](tasks/multi-branch/spec.md) | shipped |
|
||||
| [quick-chat-expiration](tasks/quick-chat-expiration.md) | draft |
|
||||
| [quick-chat-repository-context](tasks/quick-chat-repository-context.md) | shipped |
|
||||
| [parent-child-message-interrupt](tasks/parent-child-message-interrupt.md) | shipped |
|
||||
|
||||
## agents/ — agent governance
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
---
|
||||
status: shipped
|
||||
created: 2026-07-14
|
||||
owner: kandev
|
||||
---
|
||||
|
||||
# Quick Chat Repository Context
|
||||
|
||||
## Why
|
||||
|
||||
Quick chat is useful for focused questions, but its agent-only picker does not explain the
|
||||
surface or let a user ground the conversation in repository code. Users need optional code
|
||||
context without changing their checked-out branches or creating a kanban task.
|
||||
|
||||
## What
|
||||
|
||||
- A new quick chat presents a searchable agent-profile selector and requires an agent before
|
||||
it can start.
|
||||
- A user may add zero, one, or multiple imported workspace repositories. Each selected
|
||||
repository has one explicit base branch and can appear at most once in a chat.
|
||||
- Selecting a repository automatically fills its preferred branch (`main`, `master`, or the
|
||||
first available branch), including when another repository lookup is still pending.
|
||||
- A workspace with no existing quick chats explains that quick chat is for discussing an idea,
|
||||
question, or codebase outside the task board.
|
||||
- Agent and repository fields include concise helper copy. Repository copy explains that the
|
||||
optional selection focuses the conversation on specific code and branches.
|
||||
- Repo-backed quick chats run in Kandev-owned isolated worktrees. They never switch or modify
|
||||
the branch checked out in the user's source directory.
|
||||
- Repository context contains committed branch state. Uncommitted files from the user's
|
||||
working directory are not copied into the chat.
|
||||
- Repo-less quick chats retain their current scratch workspace and default-executor behavior.
|
||||
- The desktop quick-chat dialog stays horizontally centered and can be resized from either
|
||||
horizontal edge. Its last user-selected width is restored across browser sessions and clamped
|
||||
to the current viewport.
|
||||
- The quick-chat message history and composer retain the dialog's popover surface color. The setup
|
||||
footer uses that same continuous surface, and the new chat action appears immediately after the
|
||||
last chat tab.
|
||||
- Quick-chat tabs remain in creation order across reloads; later activity does not reorder them.
|
||||
- Hovering either resize target highlights the dialog's outer border, not an inset line.
|
||||
- The setup flow supports desktop and mobile layouts without horizontal page scrolling or
|
||||
hover-only actions. Mobile quick chat remains full-screen and does not expose resize handles.
|
||||
|
||||
Decision: [ADR 0038](../../decisions/0038-quick-chat-repository-isolation.md).
|
||||
|
||||
## API surface
|
||||
|
||||
`POST /api/v1/workspaces/:id/quick-chat` accepts:
|
||||
|
||||
```json
|
||||
{
|
||||
"title": "Codex - Chat 1",
|
||||
"agent_profile_id": "profile-id",
|
||||
"repositories": [
|
||||
{ "repository_id": "repo-1", "base_branch": "main" },
|
||||
{ "repository_id": "repo-2", "base_branch": "develop" }
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
`agent_profile_id` is required after workspace-default resolution. `repositories` is optional
|
||||
and ordered. The legacy singleton repository fields remain accepted, but callers cannot mix
|
||||
the singleton and plural shapes in one request.
|
||||
|
||||
The response remains:
|
||||
|
||||
```json
|
||||
{ "task_id": "task-id", "session_id": "session-id" }
|
||||
```
|
||||
|
||||
## Failure modes
|
||||
|
||||
- An incomplete repository row keeps Start Chat disabled.
|
||||
- A missing agent, foreign repository, duplicate repository, invalid branch, or mixed request
|
||||
shape fails validation and does not launch an agent.
|
||||
- If repository preparation or agent launch fails, the backend deletes the ephemeral task and
|
||||
its materialized worktrees. The setup remains visible with its selections and reports the
|
||||
error.
|
||||
- A superseded in-flight start still deletes the completed orphan task.
|
||||
|
||||
## Persistence guarantees
|
||||
|
||||
Quick-chat task/session rows and their isolated worktrees survive backend restarts under the
|
||||
existing task runtime rules. Closing, deleting, workspace deletion, or idle expiration cleans
|
||||
them through the existing quick-chat task deletion path.
|
||||
|
||||
## Scenarios
|
||||
|
||||
- **GIVEN** a workspace with no quick chats, **WHEN** the user opens Quick Chat, **THEN** the
|
||||
setup explains its purpose and shows agent and repository helper copy.
|
||||
- **GIVEN** an agent and no repositories, **WHEN** the user starts a chat, **THEN** the chat uses
|
||||
the existing repo-less scratch workspace.
|
||||
- **GIVEN** an agent and two repository/branch selections, **WHEN** the user starts a chat,
|
||||
**THEN** the agent workspace contains both repositories at committed state from those branches.
|
||||
- **GIVEN** a repository with an empty branch selection, **WHEN** its branch list loads, **THEN**
|
||||
the preferred branch is selected automatically even if a prior repository request is pending.
|
||||
- **GIVEN** the user's source checkout is on another branch or dirty, **WHEN** a repo-backed chat
|
||||
starts, **THEN** the source checkout and its uncommitted files remain unchanged.
|
||||
- **GIVEN** one repo-backed chat is active, **WHEN** another chat targets the same repository and
|
||||
base branch, **THEN** both start in distinct Kandev-owned worktrees.
|
||||
- **GIVEN** an existing quick chat, **WHEN** the user opens a new chat tab, **THEN** the long
|
||||
first-use introduction is omitted while field helper copy remains.
|
||||
- **GIVEN** a mobile viewport, **WHEN** the user selects an agent and repository branch, **THEN**
|
||||
all controls remain touch-accessible and the page has no horizontal overflow.
|
||||
- **GIVEN** a desktop quick-chat dialog, **WHEN** the user drags either horizontal edge, **THEN**
|
||||
the centered dialog resizes within viewport limits and restores that width the next time it
|
||||
opens.
|
||||
- **GIVEN** one or more quick-chat tabs, **WHEN** the tab strip renders, **THEN** the new-chat
|
||||
action sits directly after the final tab rather than at the far edge of the dialog.
|
||||
|
||||
## Out of scope
|
||||
|
||||
- Remote repository URL entry or arbitrary local folders.
|
||||
- Including uncommitted working-directory changes.
|
||||
- Selecting the same repository more than once in a single quick chat.
|
||||
- Choosing an executor in the quick-chat setup.
|
||||
Reference in New Issue
Block a user