Documentation
¶
Index ¶
- Constants
- func MCPTools(s *Service) []mcptool.Tool
- func RunSettleLoop(ctx context.Context, repo SettleRepo, wake func() <-chan struct{}, ...)
- func Topics() []eventbus.Topic
- type AccessChecker
- type Answer
- type AttachmentsCopier
- type Clarification
- type ClarificationAnswerEvent
- type ClarificationPostedEvent
- type ClarificationQuestion
- type ClarificationRepo
- type ClarificationRound
- type ClarificationRoundEvent
- type ClarifyGate
- type CreatedEvent
- type DeletedEvent
- type Doc
- type DocFilter
- type DocListItem
- type DocScope
- type DocVersion
- type Folder
- type FolderDeletedEvent
- type FolderEvent
- type FolderRepo
- type FolderUpdatedEvent
- type Handler
- type History
- type LiveSessions
- type MovedEvent
- type QuestionOption
- type Repo
- type RunningPlays
- type SearchResult
- type Service
- func (s *Service) AnswerQuestion(ctx context.Context, docID, questionID string, a Answer) (*ClarificationQuestion, error)
- func (s *Service) ApplyEdits(ctx context.Context, id string, edits []textedit.Edit) (string, error)
- func (s *Service) Archive(ctx context.Context, id string) (*Doc, error)
- func (s *Service) Clarification(ctx context.Context, docID string) (*Clarification, error)
- func (s *Service) ClearAnswer(ctx context.Context, docID, questionID string) (*ClarificationQuestion, error)
- func (s *Service) Clone(ctx context.Context, id, destinationProjectID string) (*Doc, error)
- func (s *Service) CloseClarification(ctx context.Context, docID string) (*Clarification, error)
- func (s *Service) CommitCollab(ctx context.Context, id, title, body string) error
- func (s *Service) CommitSitting(ctx context.Context, id string, editorIDs []string) error
- func (s *Service) Create(ctx context.Context, projectID, title, body string) (*Doc, error)
- func (s *Service) CreateFolder(ctx context.Context, projectID, parentID, name string) (*Folder, error)
- func (s *Service) CreateInFolder(ctx context.Context, projectID, folderID, title, body string) (*Doc, error)
- func (s *Service) CreateNamedVersion(ctx context.Context, docID, name string) (*DocVersion, error)
- func (s *Service) CreateWithID(ctx context.Context, id, projectID, folderID, title, body string) (*Doc, error)
- func (s *Service) Delete(ctx context.Context, id string) error
- func (s *Service) DeleteFolder(ctx context.Context, id string) error
- func (s *Service) EndRound(ctx context.Context, docID, trailID string) error
- func (s *Service) ExportMarkdown(ctx context.Context, id string) (string, error)
- func (s *Service) Get(ctx context.Context, id string) (*Doc, error)
- func (s *Service) GetVersion(ctx context.Context, docID string, version int) (*DocVersion, error)
- func (s *Service) History(ctx context.Context, docID string) (*History, error)
- func (s *Service) ImportMarkdown(ctx context.Context, projectID, title, body string) (*Doc, error)
- func (s *Service) List(ctx context.Context) ([]*DocListItem, error)
- func (s *Service) ListByProject(ctx context.Context, projectID string) ([]*DocListItem, error)
- func (s *Service) ListFolders(ctx context.Context, projectID string) ([]*Folder, error)
- func (s *Service) ListVersions(ctx context.Context, docID string) ([]*DocVersion, error)
- func (s *Service) Lock(ctx context.Context, id string) (*Doc, error)
- func (s *Service) LockForPlay(ctx context.Context, id string) (bool, error)
- func (s *Service) Locked(ctx context.Context, id string) (bool, error)
- func (s *Service) MoveFolder(ctx context.Context, id, parentID string) (*Folder, error)
- func (s *Service) MoveToFolder(ctx context.Context, docID, folderID string) (*Doc, error)
- func (s *Service) OpenRound(ctx context.Context, docID, starterID, trailID string, tookLock bool) (int, error)
- func (s *Service) PageDocs(ctx context.Context, f DocFilter, w paging.Window) ([]*DocListItem, int, error)
- func (s *Service) PostRound(ctx context.Context, docID string, questions []ClarificationQuestion, ...) error
- func (s *Service) RenameFolder(ctx context.Context, id, name string) (*Folder, error)
- func (s *Service) Restore(ctx context.Context, id string) (*Doc, error)
- func (s *Service) RestoreVersion(ctx context.Context, docID string, version int) (*Doc, error)
- func (s *Service) SaveAnythingElse(ctx context.Context, docID string, round int, text string) (*ClarificationRound, error)
- func (s *Service) Search(ctx context.Context, query string, limit int) ([]SearchResult, error)
- func (s *Service) SetClarifyGate(g ClarifyGate)
- func (s *Service) SetLiveSessions(live LiveSessions)
- func (s *Service) SetRunningPlays(r RunningPlays)
- func (s *Service) SetWatching(ctx context.Context, docID string, watching bool) (*Watchers, error)
- func (s *Service) Unlock(ctx context.Context, id string) (*Doc, error)
- func (s *Service) Update(ctx context.Context, id, title, body string) (*Doc, error)
- func (s *Service) Watchers(ctx context.Context, docID string) (*Watchers, error)
- func (s *Service) WriteNoGaps(ctx context.Context, docID, body string) (*Doc, error)
- type SettleRepo
- type SettledEvent
- type UpdatedEvent
- type VersionSummary
- type WatchedDoc
- type Watcher
- type WatcherRepo
- type WatcherSource
- type Watchers
- type WatchersChangedEvent
Constants ¶
const ( TopicCreated = "doc.created" TopicUpdated = "doc.updated" TopicDeleted = "doc.deleted" TopicMoved = "doc.moved" TopicSettled = "doc.settled" TopicFolderCreated = "doc.folder.created" TopicFolderUpdated = "doc.folder.updated" TopicFolderDeleted = "doc.folder.deleted" // TopicWatchersChanged is someone starting or stopping watching a doc; an edit adding its editor rides doc.updated. TopicWatchersChanged = "doc.watchers.changed" // Clarification topics carry the question and the author, never an answer or the "Anything else?" text. TopicClarificationRoundStarted = "doc.clarification.round_started" TopicClarificationRoundPosted = "doc.clarification.round_posted" TopicClarificationRoundEnded = "doc.clarification.round_ended" TopicClarificationRoundAnswered = "doc.clarification.round_answered" TopicClarificationAnswerSaved = "doc.clarification.answer_saved" TopicClarificationAnswerCleared = "doc.clarification.answer_cleared" TopicClarificationAnythingElseSaved = "doc.clarification.anything_else_saved" TopicClarificationClosed = "doc.clarification.closed" )
Topics published by the docs domain. Consumers: mcp (re-index).
const KeptUnnamedVersions = 10
KeptUnnamedVersions is how many unnamed versions a doc keeps; a save past it prunes the oldest, named ones never count.
const MaxFolderDepth = 10
MaxFolderDepth is how many folders deep a doc can sit, a top-level folder being one; the access reads walk at most 100.
const SettleWindow = 10 * time.Minute
SettleWindow is how long a person's edits to a doc must stop before doc.settled fires.
const SnippetRunes = 140
SnippetRunes bounds the list preview storage writes with each body; changing it needs a migration rewriting the stored ones.
Variables ¶
This section is empty.
Functions ¶
func RunSettleLoop ¶
func RunSettleLoop(ctx context.Context, repo SettleRepo, wake func() <-chan struct{}, logger *slog.Logger)
RunSettleLoop publishes doc.settled as windows close, sleeping until the earliest one or a commit, until ctx ends.
Types ¶
type AccessChecker ¶
type AccessChecker interface {
Can(ctx context.Context, userID, docID string, action permissions.Action) (bool, error)
// CanDocs answers Can for each of docIDs, all in projectID, at the cost of one check.
CanDocs(ctx context.Context, userID, projectID string, docIDs []string, action permissions.Action) map[string]bool
GrantCreator(ctx context.Context, docID, creatorID string) error
// DeleteByDoc removes every permission overwrite on docID; called explicitly, permission_overwrites has no FK to docs.
DeleteByDoc(ctx context.Context, docID string) error
// RequireProject checks the caller holds action in projectID's workspace; permissions.Member asks for membership.
RequireProject(ctx context.Context, projectID string, action permissions.Action) error
// CallerProjects lists the projects RequireProject lets the caller act in with action; all is true for any project.
CallerProjects(ctx context.Context, action permissions.Action) (projectIDs []string, all bool, err error)
// DocsWith is the docs userID may act on with action, in projectID when named: a project set, and the folders and
// docs whose own rules turn it.
DocsWith(ctx context.Context, userID, projectID string, action permissions.Action) (permissions.DocReach, error)
// RefuseDoc is the forbidden answer to userID's action on docID, naming the rule or role that refused it.
RefuseDoc(ctx context.Context, userID, docID string, action permissions.Action) error
}
AccessChecker is the slice of access docs consumes, defined consumer-side so docs never imports it (ADR 0017).
type Answer ¶
type Answer struct {
Selected []string `json:"selected"`
Text string `json:"text"`
Skipped bool `json:"skipped"`
}
Answer is what someone gives a question: picked labels, free text, or a skip, which carries neither.
type AttachmentsCopier ¶
type AttachmentsCopier interface {
ListOwnerIDs(ctx context.Context, docID string) ([]string, error)
CopyOwnerWithIDs(ctx context.Context, fromDocID, toDocID string, idMap map[string]string) error
}
AttachmentsCopier duplicates a doc's attachments under a clone's id; docs never imports attachments (ADR 0017).
type Clarification ¶
type Clarification struct {
Rounds []*ClarificationRound `json:"rounds"`
// Running is a round being written now; Closed is the newest round closed, until another round reopens it.
Running bool `json:"running"`
Closed bool `json:"closed"`
// CanAnswer is docs:write on this doc, through its role or a rule on the doc, which answering takes.
CanAnswer bool `json:"can_answer"`
// CanClose is docs:write plus plays:run on the Clarify play, which closing and the no-gaps signal take.
CanClose bool `json:"can_close"`
}
Clarification is a doc's rounds of questions and answers as one person sees them; NoGapsAt shows only when CanClose.
type ClarificationAnswerEvent ¶
type ClarificationAnswerEvent struct {
Doc WatchedDoc `json:"doc"`
Round int `json:"round" minimum:"1"`
QuestionID string `json:"question_id"`
Question string `json:"question"`
AuthorID string `json:"author_id"`
At time.Time `json:"at"`
}
ClarificationAnswerEvent is the answer_saved and answer_cleared payload: which question, never the answer.
type ClarificationPostedEvent ¶
type ClarificationPostedEvent struct {
ClarificationRoundEvent
QuestionCount int `json:"question_count" minimum:"0"`
NoGaps bool `json:"no_gaps" jsonschema:"true when the round found no gaps left and wrote the doc instead of asking."`
}
ClarificationPostedEvent is the doc.clarification.round_posted payload: a run posted its questions or found no gaps.
type ClarificationQuestion ¶
type ClarificationQuestion struct {
ID string `json:"id"`
DocID string `json:"doc_id"`
Round int `json:"round"`
Position int `json:"position"`
Question string `json:"question"`
Why string `json:"why"`
Options []QuestionOption `json:"options"`
MultiSelect bool `json:"multi_select"`
Selected []string `json:"selected"`
Text string `json:"text"`
Skipped bool `json:"skipped"`
AnsweredBy string `json:"answered_by,omitempty"`
AnsweredAt *time.Time `json:"answered_at,omitempty"`
}
ClarificationQuestion is one question of a round with its answer; no picks, no text, and not skipped is pending.
func (*ClarificationQuestion) Pending ¶
func (q *ClarificationQuestion) Pending() bool
Pending reports a question nobody has answered or skipped yet.
type ClarificationRepo ¶
type ClarificationRepo interface {
// ListClarificationRounds returns the doc's rounds oldest first, without their questions.
ListClarificationRounds(ctx context.Context, docID string) ([]*ClarificationRound, error)
// ListClarificationQuestions returns every question of the doc by round, then position.
ListClarificationQuestions(ctx context.Context, docID string) ([]*ClarificationQuestion, error)
// ClosedClarifications returns which docs in ids have their newest round closed.
ClosedClarifications(ctx context.Context, ids []string) (map[string]bool, error)
GetClarificationQuestion(ctx context.Context, id string) (*ClarificationQuestion, error)
// CreateClarificationRound returns ErrConflict when the doc already has a round of that number.
CreateClarificationRound(ctx context.Context, r *ClarificationRound, evts ...eventbus.OutboxEvent) error
// SaveClarification updates the given rounds and inserts the new questions in one transaction.
SaveClarification(ctx context.Context, rounds []*ClarificationRound, questions []*ClarificationQuestion, evts ...eventbus.OutboxEvent) error
DeleteClarificationRound(ctx context.Context, docID string, round int, evts ...eventbus.OutboxEvent) error
// SaveClarificationAnswer stores q's answer, writing roundAnswered too only when no question of q's round stays pending.
SaveClarificationAnswer(ctx context.Context, q *ClarificationQuestion, roundAnswered *eventbus.OutboxEvent, evts ...eventbus.OutboxEvent) error
}
ClarificationRepo persists a doc's clarification rounds and their questions; deleting the doc deletes them.
type ClarificationRound ¶
type ClarificationRound struct {
DocID string `json:"doc_id"`
Round int `json:"round"`
StartedBy string `json:"started_by"`
TrailID string `json:"trail_id"`
StartedAt time.Time `json:"started_at"`
Running bool `json:"running"`
// TookLock is whether this round's run locked the doc, so its end unlocks it (ADR 0121).
TookLock bool `json:"-"`
AnythingElse string `json:"anything_else"`
AnythingElseBy string `json:"anything_else_by,omitempty"`
AnythingElseAt *time.Time `json:"anything_else_at,omitempty"`
// AnythingElseReply is the next round's one-line answer to this round's AnythingElse.
AnythingElseReply string `json:"anything_else_reply"`
// NoGapsAt is when this round found no gaps left and wrote the doc.
NoGapsAt *time.Time `json:"no_gaps_at,omitempty"`
ClosedBy string `json:"closed_by,omitempty"`
ClosedAt *time.Time `json:"closed_at,omitempty"`
Questions []*ClarificationQuestion `json:"questions"`
}
ClarificationRound is one Clarify run's batch of questions, numbered from 1 within its doc.
type ClarificationRoundEvent ¶
type ClarificationRoundEvent struct {
Doc WatchedDoc `json:"doc"`
Round int `json:"round" minimum:"1"`
StartedBy string `json:"started_by" jsonschema:"Who started the round's Clarify via AI run."`
ActorID string `json:"actor_id,omitempty"`
Removed bool `json:"removed,omitempty" jsonschema:"true when the round asked nothing and found no gaps, so it is gone."`
}
ClarificationRoundEvent is the payload of a round starting, ending, being fully answered, its "Anything else?" being saved, and the clarification closing; StartedBy is the round's starter, ActorID whoever caused the event.
type ClarifyGate ¶
ClarifyGate says whether a person may run the Clarify play of a project's workspace, the bit closing a clarification takes beside docs:write; docs never imports plays (ADR 0017).
type CreatedEvent ¶
type CreatedEvent struct {
Doc Doc `json:"doc"`
// ActorID is the user who created the doc, so notifications skip them.
ActorID string `json:"actor_id,omitempty"`
// MentionedUserIDs are the people the body @-mentions, each told once in their inbox.
MentionedUserIDs []string `json:"mentioned_user_ids,omitempty" jsonschema:"People this save newly @-mentions, by user id."`
}
CreatedEvent is the payload for doc.created; field names are part of the event contract (ADR 0044) and additive-only.
type DeletedEvent ¶
type DeletedEvent struct {
ID string `json:"id"`
Title string `json:"title"`
ProjectID string `json:"project_id"`
}
DeletedEvent is the doc.deleted payload; the doc is already gone by publish time, so consumers get identity only.
type Doc ¶
type Doc struct {
ID string `json:"id"`
Title string `json:"title"`
Body string `json:"body"`
// ProjectID is the project this doc belongs to; mandatory, mirrors Ticket.ProjectID (ADR 0025).
ProjectID string `json:"project_id"`
// FolderID is the project folder the doc lives in; every doc is in exactly one (ADR 0096).
FolderID string `json:"folder_id" jsonschema:"The project folder the doc lives in."`
Version int `json:"version"`
Archived bool `json:"archived"`
Locked bool `json:"locked"`
CreatedBy string `json:"created_by"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
// Snippet is the list preview storage keeps beside the body; a project list reads it without the body.
Snippet string `json:"-"`
// Settler is the person a create or save opens the doc's settle window for; empty leaves the window as it is.
Settler string `json:"-"`
// Via is how a create came, recorded on its first version; see viaOf.
Via string `json:"-"`
// RestoredFrom is the version number a restore copied this save from; zero for any other save.
RestoredFrom int `json:"-"`
}
type DocFilter ¶
type DocFilter struct {
ProjectID string
FolderID string
// Query full-text searches titles and bodies and orders the list by relevance; archived docs never match it.
Query string
IncludeArchived bool
}
DocFilter narrows a doc list; empty fields narrow nothing, and the filters combine.
type DocListItem ¶
type DocListItem struct {
ID string `json:"id"`
// ProjectID lets the frontend group/filter the list by project (ticket 10), matching Ticket.ProjectID.
ProjectID string `json:"project_id"`
FolderID string `json:"folder_id"`
Title string `json:"title"`
Version int `json:"version"`
Archived bool `json:"archived"`
Locked bool `json:"locked"`
// CanOpen is always true, kept for clients that predate unreadable docs leaving lists (ADR 0082).
CanOpen bool `json:"can_open"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
CreatedBy string `json:"created_by,omitempty"`
Snippet string `json:"snippet,omitempty"`
// ClarificationClosed is true while the newest round of the doc's clarification is closed.
ClarificationClosed bool `json:"clarification_closed,omitempty"`
}
DocListItem is a doc in a list, without its body; a list holds only docs the caller may read (ADR 0148).
type DocScope ¶
type DocScope struct {
All bool
ProjectIDs []string
Read *permissions.DocReach
}
DocScope is what access lets a doc list show: everything with All, otherwise the docs of ProjectIDs. With Read set it also keeps only the docs the caller may read, as Read describes.
type DocVersion ¶
type DocVersion struct {
DocID string `json:"doc_id"`
Version int `json:"version"`
Title string `json:"title"`
Body string `json:"body"`
Name string `json:"name,omitempty"`
AuthorID string `json:"author_id,omitempty"`
// EditorIDs is who the version credits, AuthorID first; Via is the automation it came through, "mcp" for an agent's save, empty for the browser.
EditorIDs []string `json:"editor_ids"`
Via string `json:"via"`
CreatedAt time.Time `json:"created_at"`
}
DocVersion is one historical snapshot; each update appends a row while the docs table holds the current pointer.
type Folder ¶
type Folder struct {
ID string `json:"id"`
ProjectID string `json:"project_id"`
ParentID string `json:"parent_id" jsonschema:"The folder this one sits inside; empty for a top-level folder."`
Name string `json:"name"`
IsDefault bool `json:"is_default" jsonschema:"The project's default folder, where new docs land; it is never deleted."`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Folder groups a project's docs, inside another folder or at the top; each project has one default folder, which is never deleted or moved.
type FolderDeletedEvent ¶
type FolderDeletedEvent struct {
Folder Folder `json:"folder"`
MovedToFolderID string `json:"moved_to_folder_id"`
ActorID string `json:"actor_id,omitempty"`
}
FolderDeletedEvent is the doc.folder.deleted payload, one per folder of the deleted subtree; their docs moved to MovedToFolderID, never deleted.
type FolderEvent ¶
type FolderEvent struct {
Folder Folder `json:"folder"`
ActorID string `json:"actor_id,omitempty"`
}
FolderEvent is the doc.folder.created payload.
type FolderRepo ¶
type FolderRepo interface {
// ListFolders returns a project's folders, the default first, then the rest in creation order.
ListFolders(ctx context.Context, projectID string) ([]*Folder, error)
GetFolder(ctx context.Context, id string) (*Folder, error)
DefaultFolder(ctx context.Context, projectID string) (*Folder, error)
// FolderSubtree returns the folder's id and the ids of every folder inside it, at any depth.
FolderSubtree(ctx context.Context, id string) ([]string, error)
// CreateFolder returns ErrConflict when the parent already holds a folder of that name, ignoring case.
CreateFolder(ctx context.Context, f *Folder, evts ...eventbus.OutboxEvent) error
// UpdateFolder writes the folder's name and parent: ErrConflict for a sibling's name, ErrInvalid for a parent
// inside the folder itself.
UpdateFolder(ctx context.Context, f *Folder, evts ...eventbus.OutboxEvent) error
// DeleteFolder deletes the folder and every folder inside it, with their rules, and moves their docs into
// toFolderID, in one transaction.
DeleteFolder(ctx context.Context, id, toFolderID string, evts ...eventbus.OutboxEvent) error
SetDocFolder(ctx context.Context, docID, folderID string, evts ...eventbus.OutboxEvent) error
}
FolderRepo persists a project's doc folders; mutations carry events for the outbox write.
type FolderUpdatedEvent ¶
type FolderUpdatedEvent struct {
Folder Folder `json:"folder"`
PreviousName string `json:"previous_name"`
PreviousParentID string `json:"previous_parent_id" jsonschema:"The folder it sat inside before; empty when it was top-level."`
ActorID string `json:"actor_id,omitempty"`
}
FolderUpdatedEvent is the doc.folder.updated payload, sent when a folder is renamed or moved into another folder.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler adapts the docs use-cases to the HTTP/JSON gateway (ADR 0019); the browser never talks to MCP directly.
func NewHandler ¶
NewHandler wires the docs REST gateway over the given service.
type History ¶
type History struct {
Versions []VersionSummary `json:"versions"`
Changes []struct{} `json:"changes"`
}
History is what a doc's history route answers; docs keep no field changes, so Changes is always empty.
type LiveSessions ¶
type LiveSessions interface {
Reset(ctx context.Context, docID string, write func(context.Context) error) error
}
LiveSessions fences a body write against the doc's open editing session and resets the session after it, so the write wins; docs never imports collab (ADR 0017).
type MovedEvent ¶
type MovedEvent struct {
Doc Doc `json:"doc"`
FromFolderID string `json:"from_folder_id"`
ActorID string `json:"actor_id,omitempty"`
}
MovedEvent is the doc.moved payload: the doc as it now stands, in its new folder.
type QuestionOption ¶
type QuestionOption struct {
Label string `json:"label"`
Description string `json:"description,omitempty"`
}
QuestionOption is one choice a question offers.
type Repo ¶
type Repo interface {
FolderRepo
WatcherRepo
ClarificationRepo
Create(ctx context.Context, d *Doc, evts ...eventbus.OutboxEvent) error
GetByID(ctx context.Context, id string) (*Doc, error)
List(ctx context.Context) ([]*Doc, error)
// ListByProject returns the docs belonging to one project with their snippets but without their bodies.
ListByProject(ctx context.Context, projectID string) ([]*Doc, error)
// Update writes the new title and body and, unless they equal the newest version's, a version crediting editorID and
// via, then prunes the unnamed versions past KeptUnnamedVersions.
Update(ctx context.Context, d *Doc, editorID, via string, evts ...eventbus.OutboxEvent) error
SetArchived(ctx context.Context, id string, archived bool, evts ...eventbus.OutboxEvent) error
SetLocked(ctx context.Context, id string, locked bool, evts ...eventbus.OutboxEvent) error
Delete(ctx context.Context, id string, evts ...eventbus.OutboxEvent) error
Search(ctx context.Context, query string, limit int) ([]SearchResult, error)
// Page reads one window of the docs f and scope keep, and how many they keep in all: oldest first, or by relevance
// when f.Query searches them, which an archived doc never matches.
Page(ctx context.Context, f DocFilter, scope DocScope, w paging.Window) ([]*Doc, int, error)
ListVersions(ctx context.Context, docID string) ([]*DocVersion, error)
GetVersion(ctx context.Context, docID string, version int) (*DocVersion, error)
// ListVersionSummaries returns the doc's versions newest first, without their bodies.
ListVersionSummaries(ctx context.Context, docID string) ([]VersionSummary, error)
// CommitBody writes a converged collaboration state to the canonical doc without appending a version row.
CommitBody(ctx context.Context, d *Doc, editorID string, evts ...eventbus.OutboxEvent) error
// AppendSittingVersion writes the doc's current title and body as a version crediting editorIDs, the first as
// author, unless the newest version already holds them, then prunes like Update.
AppendSittingVersion(ctx context.Context, id string, editorIDs []string, at time.Time) error
// CreateNamedVersion appends a milestone version, capturing the doc's current state under a name and author.
CreateNamedVersion(ctx context.Context, v *DocVersion) error
}
Repo is the consumer-side persistence contract for docs; a save also makes its creator or editor a watcher (ADR 0101).
type RunningPlays ¶
type RunningPlays interface {
RunningOn(ctx context.Context, userID, targetType, targetID string) (label, trailID string, ok bool, err error)
}
RunningPlays finds a person's play run on a target, crediting their MCP saves to it; docs never imports plays (ADR 0017).
type SearchResult ¶
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the docs use-case layer (ADR 0019); permission checks run here so every adapter inherits them.
func NewService ¶
func NewService(repo Repo, access AccessChecker, attachments AttachmentsCopier) *Service
NewService wires the docs use-cases over the given repo, access checker, and attachment copier (for Clone).
func (*Service) AnswerQuestion ¶
func (s *Service) AnswerQuestion(ctx context.Context, docID, questionID string, a Answer) (*ClarificationQuestion, error)
AnswerQuestion saves picked options and text, or a skip, as the answer to one of the doc's questions, replacing any earlier one. Requires docs:write; a locked doc still takes answers, which are not edits to it.
func (*Service) ApplyEdits ¶
ApplyEdits is the body doc_get shows with edits applied, ready for Update; it needs the edit bit, like the save. ponytail: the read and the save are two steps, so a body saved between them is overwritten; a repo-level apply closes it
func (*Service) Archive ¶
Archive marks a doc archived (hidden from search), requiring the archive bit; Restore is the inverse.
func (*Service) Clarification ¶
Clarification returns a doc's rounds with their questions and answers; requires docs:read.
func (*Service) ClearAnswer ¶
func (s *Service) ClearAnswer(ctx context.Context, docID, questionID string) (*ClarificationQuestion, error)
ClearAnswer makes one of the doc's questions pending again; requires docs:write.
func (*Service) Clone ¶
Clone copies a doc, with its attachments, into destinationProjectID's default folder as a new doc with a fresh history; an empty destination duplicates it beside the original with " (copy)" on the title. Needs docs:read and docs:clone on the source and docs:write in the destination project.
func (*Service) CloseClarification ¶
CloseClarification closes the doc's clarification on its newest round; another round reopens it. Requires docs:write and plays:run on the Clarify play, and refuses while a round is running.
func (*Service) CommitCollab ¶
CommitCollab persists a converged collaboration state to the canonical doc without a heavyweight version row.
func (*Service) CommitSitting ¶
CommitSitting writes the version a live editing sitting ends with, crediting everyone who edited; the room already refused edits to a locked doc, and a body the newest version holds writes nothing.
func (*Service) Create ¶
Create validates and persists a new doc in its project's default folder; see CreateInFolder.
func (*Service) CreateFolder ¶
func (s *Service) CreateFolder(ctx context.Context, projectID, parentID, name string) (*Folder, error)
CreateFolder adds a folder to a project (docs:write), inside parentID or at the top when it is empty; a name another folder of that parent has, ignoring case, conflicts.
func (*Service) CreateInFolder ¶
func (s *Service) CreateInFolder(ctx context.Context, projectID, folderID, title, body string) (*Doc, error)
CreateInFolder persists a new doc (v1) in folderID, or the project's default folder when empty, enqueuing doc.created and granting the creator full permissions.
func (*Service) CreateNamedVersion ¶
CreateNamedVersion snapshots the doc's current state as a named milestone version; requires the edit bit.
func (*Service) CreateWithID ¶
func (s *Service) CreateWithID(ctx context.Context, id, projectID, folderID, title, body string) (*Doc, error)
CreateWithID is CreateInFolder with the doc's id chosen by the caller, as an import derives it; a doc that already has the id is ErrConflict.
func (*Service) Delete ¶
Delete removes a doc, requiring the delete bit, and publishes doc.deleted; tickets filed from it refuse it as a conflict.
func (*Service) DeleteFolder ¶
DeleteFolder deletes a folder and every folder inside it (docs:write) and moves all their docs to its parent, or to the project's default folder, which is never deleted, when it is top-level.
func (*Service) EndRound ¶
EndRound ends the round trailID opened, at any end of its run: it unlocks the doc if the run locked it, and removes a round that asked nothing and found no gaps. A round already ended is left as it is.
func (*Service) ExportMarkdown ¶
ExportMarkdown renders a doc's body as markdown for LLM/import/export/integrations; requires the read bit.
func (*Service) Get ¶
Get returns a doc by id; a user without the read bit gets ErrNotFound, though a mention pill still shows its title.
func (*Service) GetVersion ¶
GetVersion returns a specific historical version of a doc; requires the read bit.
func (*Service) History ¶
History returns the doc's versions newest first, without bodies; requires the read bit, as GetVersion does.
func (*Service) ImportMarkdown ¶
ImportMarkdown creates a doc from a markdown body, converted to the canonical structured representation.
func (*Service) List ¶
func (s *Service) List(ctx context.Context) ([]*DocListItem, error)
List returns every doc the actor may read, oldest first.
func (*Service) ListByProject ¶
ListByProject returns the docs in a project, oldest first, each naming its folder (ADR 0096).
func (*Service) ListFolders ¶
ListFolders returns a project's folders, the default first; a viewer without docs:write sees only the folders holding a doc they can open, which folder rules decide with the doc's own, and the folders those sit inside.
func (*Service) ListVersions ¶
ListVersions returns the version history for a doc, newest first; requires the read bit.
func (*Service) Lock ¶
Lock makes a doc read-only for everyone until Unlock, requiring docs:lock; archive, clone, and delete still work.
func (*Service) LockForPlay ¶
LockForPlay locks a doc as a doc play starts on it, with no check of its own: the run's start already checked the starter, and the lock comes with the run (ADR 0107). It reports whether the doc was unlocked until now.
func (*Service) Locked ¶
Locked reports whether a doc refuses edits; the collab relay asks per update, having checked access at join.
func (*Service) MoveFolder ¶
MoveFolder puts a folder inside parentID, or at the top when it is empty (docs:write), with every folder and doc in it; the default folder stays at the top, and no folder goes inside itself.
func (*Service) MoveToFolder ¶
MoveToFolder moves a doc into another folder of its project, needing docs:write on the doc; a locked doc moves too.
func (*Service) OpenRound ¶
func (s *Service) OpenRound(ctx context.Context, docID, starterID, trailID string, tookLock bool) (int, error)
OpenRound opens the doc's next round as a Clarify run starts, recording its starter, its trail, and whether the run took the doc's lock. No permission check: the run's start already checked the starter, as LockForPlay. A round still running is stale, since the runner allows one live run per doc, so it is ended first; a lock it took passes to the new round, which the runner's own lock attempt found already taken.
func (*Service) PageDocs ¶
func (s *Service) PageDocs(ctx context.Context, f DocFilter, w paging.Window) ([]*DocListItem, int, error)
PageDocs returns one window of the docs f keeps that the caller may read, and how many there are: oldest first, or by relevance for a query. It is filtered in SQL, a doc's own rules included, so the total counts only what the pages hold (ADR 0140), and a doc they cannot read is left out (ADR 0148).
func (*Service) PostRound ¶
func (s *Service) PostRound(ctx context.Context, docID string, questions []ClarificationQuestion, reply string) error
PostRound stores the running round's questions, and the reply to the round before's "Anything else?", from the round's starter while it runs: the run's own agent acts as them. Either part may come alone, each once.
func (*Service) RenameFolder ¶
RenameFolder renames a folder (docs:write), the default one included.
func (*Service) RestoreVersion ¶
RestoreVersion saves an old version's title and body as a new version on top, through Update, so the open sitting is saved first, open editors follow, and a locked doc refuses it; requires the edit bit.
func (*Service) SaveAnythingElse ¶
func (s *Service) SaveAnythingElse(ctx context.Context, docID string, round int, text string) (*ClarificationRound, error)
SaveAnythingElse stores the text of a round's "Anything else?" box, or clears it when empty; requires docs:write.
func (*Service) Search ¶
Search runs an FTS5 query over doc titles and bodies; archived and inaccessible docs are excluded entirely, never disclosed (ADR 0028).
func (*Service) SetClarifyGate ¶
func (s *Service) SetClarifyGate(g ClarifyGate)
SetClarifyGate wires the Clarify play check; without it nobody may close a clarification.
func (*Service) SetLiveSessions ¶
func (s *Service) SetLiveSessions(live LiveSessions)
SetLiveSessions wires the editing sessions a body write must win over; without it a write touches only the doc.
func (*Service) SetRunningPlays ¶
func (s *Service) SetRunningPlays(r RunningPlays)
SetRunningPlays wires the run lookup; without it an MCP save is always credited to the person's agent.
func (*Service) SetWatching ¶
SetWatching starts or stops the caller watching a doc, needing only docs:read; a stop outlasts their own later edits.
func (*Service) Update ¶
Update replaces the title/body, bumps the version, appends a version row unless nothing changed since the newest one, and enqueues doc.updated; requires the edit bit.
func (*Service) Watchers ¶
Watchers lists the people who get a doc's change notifications and whether the caller is one; requires docs:read.
func (*Service) WriteNoGaps ¶
WriteNoGaps replaces the doc's body with the running round's no-gaps rewrite, through the lock its run holds (ADR 0121); only the round's starter may send it, holding docs:write, and only instead of questions.
type SettleRepo ¶
type SettleRepo interface {
// NextSettleDue is when the earliest open window closes; false when none is open.
NextSettleDue(ctx context.Context) (time.Time, bool, error)
// SettleDue closes every window due by now, writing build's events for those whose doc is not archived, in one transaction.
SettleDue(ctx context.Context, now time.Time, build func([]SettledEvent) []eventbus.OutboxEvent) error
}
SettleRepo holds the open settle windows, one per doc a person created or edited.
type SettledEvent ¶
type SettledEvent struct {
Doc WatchedDoc `json:"doc"`
First bool `json:"first" jsonschema:"true when the doc was created inside the window: a create, not a change."`
ActorID string `json:"actor_id" jsonschema:"The person whose save last moved the window."`
}
SettledEvent is the doc.settled payload, built when the doc settles, so it names the doc as it then stands.
type UpdatedEvent ¶
type UpdatedEvent struct {
Doc Doc `json:"doc"`
// ActorID is the user whose edit, archive, or collaborative commit this is; empty when none is known.
ActorID string `json:"actor_id,omitempty"`
// MentionedUserIDs are the people this save @-mentions that the previous version did not.
MentionedUserIDs []string `json:"mentioned_user_ids,omitempty" jsonschema:"People this save newly @-mentions, by user id."`
// LockChanged marks a lock or unlock, so it tells no watcher.
LockChanged bool `json:"lock_changed,omitempty" jsonschema:"True when the doc was only locked or unlocked; its title and body are unchanged."`
}
UpdatedEvent is the payload for doc.updated.
type VersionSummary ¶
type VersionSummary struct {
Version int `json:"version"`
CreatedAt time.Time `json:"created_at"`
Name string `json:"name"`
EditorIDs []string `json:"editor_ids"`
Via string `json:"via"`
// WordsAdded and WordsRemoved size the version against the kept one before it; nil on the oldest kept.
WordsAdded *int `json:"words_added"`
WordsRemoved *int `json:"words_removed"`
// RestoredFrom is the version number a restore copied this version from; nil for any other version.
RestoredFrom *int `json:"restored_from"`
// Current marks the newest version.
Current bool `json:"current"`
}
VersionSummary is a version in a doc's history, without its body.
type WatchedDoc ¶
type WatchedDoc struct {
ID string `json:"id"`
ProjectID string `json:"project_id"`
Title string `json:"title"`
}
WatchedDoc is the slice of a doc a watcher or clarification event names; the body never travels with it.
type Watcher ¶
type Watcher struct {
UserID string `json:"user_id"`
Source WatcherSource `json:"source"`
CreatedAt time.Time `json:"created_at"`
}
Watcher is a person who gets a doc's change notifications (ADR 0101).
type WatcherRepo ¶
type WatcherRepo interface {
// ListWatchers returns the people currently watching the doc, earliest first.
ListWatchers(ctx context.Context, docID string) ([]*Watcher, error)
SetWatching(ctx context.Context, docID, userID string, watching bool, at time.Time, evts ...eventbus.OutboxEvent) error
}
WatcherRepo persists who watches a doc; a stopped watcher's row is kept so their own edits don't re-add them.
type WatcherSource ¶
type WatcherSource string
WatcherSource says how someone came to watch a doc: added for creating or editing it, or by choosing to.
const ( WatcherAuto WatcherSource = "auto" WatcherManual WatcherSource = "manual" )
type Watchers ¶
Watchers is a doc's watchers as one person sees them, with whether that person is one.
type WatchersChangedEvent ¶
type WatchersChangedEvent struct {
Doc WatchedDoc `json:"doc"`
UserID string `json:"user_id"`
Watching bool `json:"watching" jsonschema:"true when they started watching, false when they stopped."`
}
WatchersChangedEvent is the doc.watchers.changed payload: who started (watching true) or stopped watching which doc.