chat: give the operator their own sessions, separate from run sessions
chat_sessions used to list exactly the OpenCode sessions the pipelines own,
filtered through pipeline.SessionOwner (run_steps/run_session_owners), so an
operator-created chat was an accident of the run-ownership table and the
operator's working sessions were mixed with the internals of running pipelines.
Add a first-class operator session:
- internal/pipeline/operator_sessions.go: a dedicated operator_sessions table
(session_id PK, directory, title, tag, created_at, last_used_at) with
RecordOperatorSession (upsert preserving created_at), a one-statement
TouchOperatorSession (no-op for a non-operator id), OperatorSessions bounded to
128 rows most-recently-used first, and OperatorDirectories (bounded MRU,
deduped). run_steps/run_session_owners and SessionOwner/OwnedSessions are
untouched.
- internal/server/chat.go: chat_sessions returns operator sessions only - it
reads the registry once, intersects it with one broker session-list call, fills
directory/tag/created/updated from the registry, sets busy for a session held
by another connection, keeps MRU order, and stays fail-closed (empty list, never
the endpoint's whole list). A pipeline stage session and an untagged row can
never be listed. chat_create resolves the directory (empty/'~'/'~/...' ->
operator home; relative or missing rejected before any OpenCode call), calls
broker.Create(title, resolved) and records the row with the operator tag.
chat_directories returns home first then bounded (8) deduped recents. A
successful prompt touches the operator session without affecting pipeline
prompts.
- internal/opencode, internal/protocol, internal/server/websocket.go and
message.go: unscoped session list, Create posts {"title":...,
"location":{"directory":...}} to POST /api/session, additive protocol fields
(omitempty) and the ChatDirectories request/response, plus the OperatorRegistry
option defaulting to the first store. One OpenCode transport per server is
unchanged.
Docs and references: docs/cli.md gains a "Chat sessions" section documenting the
operator-only fail-closed list, directory defaulting/rejection, chat_directories
(home first, deduped, bounded 8) and why a dedicated request was chosen.
internal/author/skill/references/operations.md's stale "Brokered OpenCode chat"
text (chat_create unbrokered, run_steps filtering, "listed the owned scratch
session" evidence) is rewritten to the operator-session registry, the fail-closed
filter, directory defaulting and the corrected live-test wording. No new
reference file, so internal/author/install.go's inventory is unchanged.
Checked for staleness elsewhere: README.md, the docs/ topic pages and the
packaged server/TUI templates carry no chat-session ownership claims, so none
needed updating.
Verified: gofmt -l clean; go vet and go build ./... clean; go test -count=1
./internal/pipeline/... ./internal/protocol/... ./internal/opencode/...
./internal/server/... and the full go test -count=1 ./... pass.
This commit is contained in:
@@ -22,6 +22,13 @@ const (
|
||||
ChatMessages = "chat_messages"
|
||||
ChatInterrupt = "chat_interrupt"
|
||||
ChatReply = "chat_reply"
|
||||
// ChatDirectories is the request/response type for the operator's directory
|
||||
// choices: the home directory plus the directories of previous operator
|
||||
// sessions, most recently used first, deduplicated and bounded. It is a
|
||||
// dedicated request (not a field on chat_sessions) so the create dialog can
|
||||
// load the choices without first listing sessions and chat_sessions stays a
|
||||
// pure, fail-closed operator-session list.
|
||||
ChatDirectories = "chat_directories"
|
||||
// ChatEvent and ChatPermission are the server-pushed frames; they are the
|
||||
// only types the server sends without a matching request.
|
||||
ChatEvent = "chat_event"
|
||||
@@ -69,6 +76,15 @@ const (
|
||||
ChatDecisionReject = "reject"
|
||||
)
|
||||
|
||||
// ChatSession.Tag values. The stored tag vocabulary is exactly
|
||||
// ChatSessionTagOperator; the display label the app shows is
|
||||
// ChatSessionTagOperatorDisplay, derived from the wire tag rather than carried
|
||||
// as a second field so there is no duplicate mapping to drift.
|
||||
const (
|
||||
ChatSessionTagOperator = "operator"
|
||||
ChatSessionTagOperatorDisplay = "Operator"
|
||||
)
|
||||
|
||||
// ChatMessage.Role values.
|
||||
const (
|
||||
ChatRoleUser = "user"
|
||||
@@ -85,6 +101,10 @@ type ChatSession struct {
|
||||
Model string `json:"model,omitempty"`
|
||||
Directory string `json:"directory,omitempty"`
|
||||
ParentID string `json:"parent_id,omitempty"`
|
||||
// Tag marks the session kind. The only stored value is "operator" (a chat
|
||||
// the person created); pipeline stage sessions are never tagged and are never
|
||||
// listed by chat_sessions. Additive/omitempty so older peers ignore it.
|
||||
Tag string `json:"tag,omitempty"`
|
||||
CreatedAt int64 `json:"created_at,omitempty"`
|
||||
UpdatedAt int64 `json:"updated_at,omitempty"`
|
||||
// Busy marks a session another client currently holds (or one the server
|
||||
|
||||
Reference in New Issue
Block a user