Documentation
¶
Index ¶
- Constants
- func AddWorkdir(uuid, path, name string) error
- func ApplyPatch(originalSource string, patchExecutableCode string) (string, error)
- func CancelContract(uuid string) error
- func CompleteContract(uuid string) error
- func DeleteContract(uuid string) error
- func DiscoverContractHome() (string, error)
- func FormatContractInfo(info *ContractInfoResult, format string) string
- func FormatContractTest(result *ContractTestResult, format string) string
- func GetDefaultHomeDir(uuid string, dumpType string) string
- func GetEventsDBPath(uuid string) string
- func InsertEvent(contractUUID string, chatID int64, eventType string, payload interface{}, ...) error
- func InsertEventWithDB(db *sql.DB, chatID int64, eventType string, payload interface{}, source string, ...) error
- func NewFile(contractUUID string, authcode string, targetRelativePath string, ...) error
- func RemoveWorkdir(uuid, name string) error
- func RenewContract(uuid string, hours int) error
- func ResolveFileByParentUUID(parentUUID string, workdir string) (string, error)
- func SetPrimaryWorkdir(uuid, name string) error
- func StageCodeBlock(blockUUID string, targetFile string) (string, error)
- func UpdateFile(contractUUID string, authcode string, sourceFile string) error
- func WriteDebugArtifacts(msg db.Message, chat db.Chat, sourceCode string, phase1Diff string, ...) (string, error)
- type AliasDefinition
- type AppDefinitions
- type ChatMessagePayload
- type ContractChangePayload
- type ContractError
- type ContractInfoResult
- type ContractMetadata
- type ContractTestResult
- type DumpError
- type DumpWriter
- type EventStatus
- type LaunchCapabilities
- type LaunchRequest
- type LaunchResult
- type MappedDumpResult
- type MappedDumpStats
- type MappedFileEntry
- type MappedFileStatus
- type MappedWriter
- func (w *MappedWriter) GetMessageDir(chat db.Chat, msg db.Message, position int) string
- func (w *MappedWriter) Prepare(outputDir string) error
- func (w *MappedWriter) SetPathMap(pathMap map[string]string)
- func (w *MappedWriter) WriteBlock(msgDir string, block markdown.CodeBlock, trim bool) error
- func (w *MappedWriter) WriteMessage(msgDir string, msg db.Message) error
- func (w *MappedWriter) WritePatch(msgDir string, patch markdown.PatchBlock, trim bool) error
- func (w *MappedWriter) WritePatchedFile(msgDir string, patch markdown.PatchBlock, header string, content string) error
- func (w *MappedWriter) WriteProvenance(msgDir string, chats []db.Chat) error
- func (w *MappedWriter) WriteProvenanceJSON(msgDir string, data Provenance) error
- func (w *MappedWriter) WriteSourceFile(msgDir string, relPath string, content string) error
- type MergedNode
- type MergedWriter
- func (w *MergedWriter) GetMessageDir(chat db.Chat, msg db.Message, position int) string
- func (w *MergedWriter) Prepare(outputDir string) error
- func (w *MergedWriter) SetMetrics(rank int, count int)
- func (w *MergedWriter) WriteBlock(msgDir string, block markdown.CodeBlock, trim bool) error
- func (w *MergedWriter) WriteMessage(msgDir string, msg db.Message) error
- func (w *MergedWriter) WritePatch(msgDir string, patch markdown.PatchBlock, trim bool) error
- func (w *MergedWriter) WritePatchedFile(msgDir string, patch markdown.PatchBlock, header string, content string) error
- func (w *MergedWriter) WriteProvenance(msgDir string, chats []db.Chat) error
- func (w *MergedWriter) WriteProvenanceJSON(msgDir string, data Provenance) error
- func (w *MergedWriter) WriteSourceFile(msgDir string, relPath string, content string) error
- type PatchError
- type Provenance
- type ProvenanceEntry
- type ProvenanceStatus
- type ShadowWorkspace
- type TreeWriter
- func (w *TreeWriter) GetMessageDir(chat db.Chat, msg db.Message, visibleIndex int) string
- func (w *TreeWriter) Prepare(outputDir string) error
- func (w *TreeWriter) WriteBlock(msgDir string, block markdown.CodeBlock, trim bool) error
- func (w *TreeWriter) WriteMessage(msgDir string, msg db.Message) error
- func (w *TreeWriter) WritePatch(msgDir string, patch markdown.PatchBlock, trim bool) error
- func (w *TreeWriter) WritePatchedFile(msgDir string, patch markdown.PatchBlock, header string, content string) error
- func (w *TreeWriter) WriteProvenance(msgDir string, chats []db.Chat) error
- func (w *TreeWriter) WriteProvenanceJSON(msgDir string, data Provenance) error
- func (w *TreeWriter) WriteSourceFile(msgDir string, relPath string, content string) error
- type WorkspaceEntry
Constants ¶
const ( EventTypeTerminalSendMessage = "terminal_send_message" EventTypeContractChange = "contract_change" )
Event Type Constants
const ( ExitContractExpired = 10 // Contract has expired ExitParentUUIDMismatch = 11 // Parent-UUID in code doesn't match file ExitDuplicateBlockUUID = 12 // Block-UUID already exists in workdir ExitTargetFileNotFound = 13 // Target file not found (for update-file) ExitTargetPathExists = 14 // Target path already exists (for new-file) ExitInvalidTargetPath = 15 // Target path is not relative or escapes workdir ExitInvalidAuthcode = 16 // Invalid authorization code provided )
Contract-specific exit codes
const ( ErrCodeContractExpired = "CONTRACT_EXPIRED" ErrCodeContractCancelled = "CONTRACT_CANCELLED" ErrCodeDuplicateBlockUUID = "DUPLICATE_BLOCK_UUID" ErrCodeParentNotFound = "PARENT_UUID_NOT_FOUND" ErrCodeParentMismatch = "PARENT_UUID_MISMATCH" ErrCodeHeaderParseFailed = "HEADER_PARSE_FAILED" )
Error codes for the 'test' command
const EventsDBSchema = `` /* 383-byte string literal not displayed */
EventsDBSchema defines the SQL schema for the contract-level events database. This database acts as a message queue between the terminal and the web UI.
Variables ¶
This section is empty.
Functions ¶
func AddWorkdir ¶
AddWorkdir adds a new secondary working directory to an active contract. Validates path is a git repository, checks for duplicates, and enforces conflict constraints.
func ApplyPatch ¶
ApplyPatch takes a GitSense patch block's executable code and the original source code, and returns the resulting patched string.
It uses a multiphase approach: Phase 1: Attempt to apply the patch exactly as provided. Phase 2: If Phase 1 fails, attempt to detect if the hunk line numbers include the
metadata header offset, adjust them, and retry.
func CancelContract ¶
CancelContract terminates a contract immediately.
func CompleteContract ¶
CompleteContract marks a contract as finished/done. This state prevents further edits but preserves the contract for historical reference and dumping.
func DiscoverContractHome ¶
DiscoverContractHome walks up the directory tree to find the contract home.
func FormatContractInfo ¶
func FormatContractInfo(info *ContractInfoResult, format string) string
FormatContractInfo formats the output for the 'contract info' command.
func FormatContractTest ¶
func FormatContractTest(result *ContractTestResult, format string) string
FormatContractTest formats the output for the 'contract test' command.
func GetDefaultHomeDir ¶
GetDefaultHomeDir returns the default home directory for a contract. It now supports a dumpType parameter to create hierarchical structures (e.g., dumps/<uuid>/mapped).
func GetEventsDBPath ¶
GetEventsDBPath resolves the absolute path to the events database for a given contract UUID.
func InsertEvent ¶
func InsertEvent(contractUUID string, chatID int64, eventType string, payload interface{}, source string, expiresAt time.Time) error
InsertEvent inserts a new event into the contract_events table.
func InsertEventWithDB ¶
func InsertEventWithDB(db *sql.DB, chatID int64, eventType string, payload interface{}, source string, expiresAt time.Time) error
InsertEventWithDB inserts an event using an existing database connection.
func NewFile ¶
func NewFile(contractUUID string, authcode string, targetRelativePath string, sourceFile string) error
NewFile creates a new traceable file using a contract. It validates the Authcode, path safety and UUID uniqueness, then logs the provenance.
func RemoveWorkdir ¶
RemoveWorkdir removes a secondary working directory from an active contract. Prevents removal of the primary workdir (index 0).
func RenewContract ¶
RenewContract extends the expiration time of an active or expired contract.
func ResolveFileByParentUUID ¶
ResolveFileByParentUUID uses ripgrep to find the file containing the Parent-UUID.
func SetPrimaryWorkdir ¶
SetPrimaryWorkdir changes the primary workdir by swapping with the workdir at index 0. Validates no conflicts with other active contracts.
func StageCodeBlock ¶
StageCodeBlock fetches the AI code from the database and writes it to a temporary review file.
func UpdateFile ¶
UpdateFile updates an existing traceable file using a contract. It validates the Authcode, Parent-UUID, performs an atomic write, and logs the provenance.
func WriteDebugArtifacts ¶
func WriteDebugArtifacts(msg db.Message, chat db.Chat, sourceCode string, phase1Diff string, phase2Diff string, targetUUID string, patchError error) (string, error)
WriteDebugArtifacts persists the source and patch content to a debug directory along with the conversational context (message and chat info).
Types ¶
type AliasDefinition ¶
AliasDefinition defines a workflow alias.
type AppDefinitions ¶
type AppDefinitions struct {
Editors []string `json:"editors"`
Terminals []string `json:"terminals"`
}
AppDefinitions groups available apps by category.
type ChatMessagePayload ¶
type ChatMessagePayload struct {
Text string `json:"text"`
Type string `json:"type"` // e.g., "regular"
Visibility string `json:"visibility"` // e.g., "human-public", "human-only"
NoConfirmation bool `json:"no_confirmation"` // If true, bypass the UI confirmation modal
ReferenceMessageID int64 `json:"reference_message_id,omitempty"` // The ID of the message to target for operations
Replace bool `json:"replace,omitempty"` // If true, replace the reference message
InsertBefore bool `json:"insert_before,omitempty"` // If true, insert before the reference message
InsertAfter bool `json:"insert_after,omitempty"` // If true, insert after the reference message
MessageID int64 `json:"message_id,omitempty"` // The ID of the message inserted by the backend (for 'chat_message_posted')
}
ChatMessagePayload represents the data structure for a chat message event. It supports appending new messages as well as manipulating existing messages relative to a reference message ID (e.g., replace, insert before, insert after). It also supports the 'chat_message_posted' event type, which includes the ID of the message that was successfully inserted into the database.
type ContractChangePayload ¶
type ContractChangePayload struct {
Status string `json:"status"` // The new status (e.g., "cancelled", "done", "active")
ExpiresAt string `json:"expires_at,omitempty"` // ISO 8601 timestamp, present if renewed
}
ContractChangePayload represents the data structure for a contract lifecycle event.
type ContractError ¶
ContractError wraps an error with a specific exit code for the CLI.
func (*ContractError) Error ¶
func (e *ContractError) Error() string
type ContractInfoResult ¶
type ContractInfoResult struct {
UUID string `json:"uuid"`
Description string `json:"description"`
PrimaryWorkdir string `json:"primary_workdir"`
Workdirs []contract.WorkdirEntry `json:"workdirs"`
Status string `json:"status"`
CreatedAt time.Time `json:"created_at"`
ExpiresAt time.Time `json:"expires_at"`
Authcode string `json:"authcode"`
ExecTimeout int `json:"exec_timeout"`
Whitelist []string `json:"whitelist"`
NoWhitelist bool `json:"no_whitelist"`
PreferredEditor string `json:"preferred_editor"`
PreferredTerminal string `json:"preferred_terminal"`
PreferredReview string `json:"preferred_review"`
}
ContractInfoResult represents the sanitized output of the 'contract info' command.
func GetContractInfo ¶
func GetContractInfo(uuid string, sanitize bool) (*ContractInfoResult, error)
GetContractInfo retrieves contract information for the 'info' command.
type ContractMetadata ¶
type ContractMetadata struct {
// Embed the core data structure. This handles UnmarshalJSON automatically.
contract.ContractData
// Contract-specific fields not stored in the DB message
ChatID int64 `json:"chat_id"`
ChatUUID string `json:"chat_uuid"`
ContractMessageID int64 `json:"contract_message_id"`
CreatedAt time.Time `json:"created_at"`
// Workspace Registry
// Maps Workspace ID (Composite Hash) -> Workspace Entry
Workspaces map[string]WorkspaceEntry `json:"workspaces"`
}
ContractMetadata represents a traceability contract stored in ~/.gitsense/contracts.
func CreateContract ¶
func CreateContract(code string, description string, authcode string, workdir string, whitelist []string, noWhitelist bool, execTimeout int, preferredEditor string, preferredTerminal string, preferredReview string) (*ContractMetadata, error)
CreateContract initializes a new traceability contract using a valid handshake code. It validates the workdir, persists the contract metadata, and inserts the contract message into the chat.
func GetContract ¶
func GetContract(uuid string) (*ContractMetadata, error)
GetContract retrieves a specific contract by its UUID.
func GetContractByWorkdir ¶
func GetContractByWorkdir(workdir string) (*ContractMetadata, error)
GetContractByWorkdir retrieves the active contract for a specific working directory.
func ListContracts ¶
func ListContracts() ([]ContractMetadata, error)
ListContracts retrieves all contracts from the global storage.
func (*ContractMetadata) UnmarshalJSON ¶
func (c *ContractMetadata) UnmarshalJSON(data []byte) error
UnmarshalJSON handles JSON unmarshaling for ContractMetadata. This is necessary because ContractMetadata embeds ContractData, which has its own UnmarshalJSON method. Without this implementation, the embedded method would only populate ContractData fields, leaving Workspaces, ChatID, ChatUUID, etc. uninitialized.
type ContractTestResult ¶
type ContractTestResult struct {
ContractInfoResult // Embedded: Includes UUID, Status, ExpiresAt, etc.
// Test Specific Fields
Success bool `json:"success"` // Overall success/failure
ErrorCode string `json:"error_code"` // Specific error code if failed
Message string `json:"message"` // Human-readable status message
RelativePath string `json:"relative_path"` // Path relative to workdir (if parent found)
DiffHTML string `json:"diff_html"` // HTML fragment of the diff (if parent found)
DiffUnified string `json:"diff_unified"` // Unified diff text (if parent found)
BlockUUID string `json:"block_uuid"` // The UUID from the source file
ParentUUID string `json:"parent_uuid"` // The parent UUID from the source file
IsUnique bool `json:"is_unique"` // Whether the Block-UUID is unique
}
ContractTestResult represents the output of the 'contract test' command.
type DumpError ¶
type DumpError struct {
Code string `json:"code"` // e.g., "INVALID_MESSAGE_ID"
Message string `json:"message"` // Human-readable description
}
DumpError represents a structured error for the dump response.
type DumpWriter ¶
type DumpWriter interface {
// Prepare initializes the output directory (e.g., wiping old data).
Prepare(outputDir string) error
// GetMessageDir returns the relative path for a specific message's artifacts.
// This allows different writers to structure the hierarchy differently.
GetMessageDir(chat db.Chat, msg db.Message, position int) string
// WriteMessage handles the persistence of the raw message content (message.md).
WriteMessage(msgDir string, msg db.Message) error
// WriteProvenance persists the chat metadata (provenance) for a message.
// This is used by the 'merged' type to create the <n>_chats.md file.
WriteProvenance(msgDir string, chats []db.Chat) error
// WriteBlock handles the persistence of a code block.
// The trim flag determines if smart trimming should be applied.
WriteBlock(msgDir string, block markdown.CodeBlock, trim bool) error
// WritePatch handles the persistence of a patch block.
// The trim flag determines if smart trimming should be applied.
WritePatch(msgDir string, patch markdown.PatchBlock, trim bool) error
// WritePatchedFile persists the result of a successful patch application.
// The header is prepended to the content to maintain traceability.
WritePatchedFile(msgDir string, patch markdown.PatchBlock, header string, content string) error
// WriteSourceFile copies the original source file from the workdir to the dump directory.
// This is used by the 'mapped' type to create the 'source.<ext>' file in the shadow workspace.
WriteSourceFile(msgDir string, relPath string, content string) error
// WriteProvenanceJSON persists the structured provenance data for a specific file.
// This is used by the 'mapped' type to create the 'provenance.json' sidecar.
WriteProvenanceJSON(msgDir string, data Provenance) error
}
DumpWriter defines the strategy for organizing and writing chat artifacts to disk.
type EventStatus ¶
type EventStatus string
EventStatus defines the state of an event in the messaging queue.
const ( EventPending EventStatus = "pending" EventProcessed EventStatus = "processed" EventCancelled EventStatus = "cancelled" EventExpired EventStatus = "expired" EventFailed EventStatus = "failed" )
type LaunchCapabilities ¶
type LaunchCapabilities struct {
Aliases []AliasDefinition `json:"aliases"`
Apps AppDefinitions `json:"apps"`
Commands []string `json:"commands"`
}
LaunchCapabilities represents the response for 'gsc app contract launch --list'.
func GetLaunchCapabilities ¶
func GetLaunchCapabilities() LaunchCapabilities
GetLaunchCapabilities returns the available aliases, apps, and commands for discovery.
type LaunchRequest ¶
type LaunchRequest struct {
ContractUUID string `json:"contract_uuid"`
Authcode string `json:"authcode"`
Alias string `json:"alias"` // "review", "terminal", "editor", "exec", "dump"
BlockUUID string `json:"block_uuid,omitempty"`
ParentUUID string `json:"parent_uuid,omitempty"`
Action string `json:"action,omitempty"` // "source", "patch" (review) or "tree", "text", "mapped" (dump)
AppOverride string `json:"app_override,omitempty"` // Overrides preferred app (e.g., "zed", "iterm2")
Cmd string `json:"cmd,omitempty"`
Sort string `json:"sort,omitempty"` // Sort mode for 'merged' dump type
DebugPatch bool `json:"debug_patch,omitempty"` // Enable patch debugging artifacts
ActiveChatID int64 `json:"active_chat_id"` // The ID of the chat the user is currently viewing (for forks)
Hash string `json:"hash,omitempty"` // The message hash for shadow workspace resolution
Position int `json:"position"` // The 0-indexed position of the code block (-1 for root)
}
LaunchRequest represents the data contract from the Web UI to the CLI for the 'launch' command.
type LaunchResult ¶
type LaunchResult struct {
Success bool `json:"success"`
Message string `json:"message"`
Alias string `json:"alias"`
PrimaryWorkdir string `json:"primary_workdir"`
StagedPath string `json:"staged_path,omitempty"`
Command string `json:"command,omitempty"`
}
LaunchResult represents the response from the CLI to the Web UI for the 'launch' command.
func HandleLaunch ¶
func HandleLaunch(req LaunchRequest) (LaunchResult, error)
HandleLaunch processes a LaunchRequest and executes the appropriate workspace action.
type MappedDumpResult ¶
type MappedDumpResult struct {
Success bool `json:"success"`
Exists bool `json:"exists"` // True if the workspace directory was found (validation mode)
Valid bool `json:"valid"` // True if the workspace is not expired (validation mode)
Hash string `json:"hash"` // The message hash (directory name)
RootDir string `json:"root_dir"` // Absolute path to the dump directory
ExpiresAt string `json:"expires_at"` // ISO 8601 expiration timestamp
Stats MappedDumpStats `json:"stats"`
Files []MappedFileEntry `json:"files"`
Error *DumpError `json:"error,omitempty"` // Present if Success is false
}
MappedDumpResult is the JSON response structure for the 'mapped' dump command. It supports both generation and validation modes.
func ExecuteDump ¶
func ExecuteDump(contractUUID string, writer DumpWriter, outputDir string, includeSystem bool, trim bool, dumpType string, sortMode string, debugPatch bool, messageID int64, validate bool, activeChatID int64) (*MappedDumpResult, error)
ExecuteDump coordinates the full dump process for a given contract. It supports 'tree', 'merged', and 'mapped' strategies.
type MappedDumpStats ¶
type MappedDumpStats struct {
Mappable int `json:"mappable"` // Count of successfully mapped files
Unmappable int `json:"unmappable"` // Count of unmapped files
}
MappedDumpStats provides summary statistics for the dump.
type MappedFileEntry ¶
type MappedFileEntry struct {
Path string `json:"path"` // Relative path in the project (or component name)
OriginalPath string `json:"original_path,omitempty"` // Original component name before sanitization
FullRelPath string `json:"full_rel_path"` // Full relative path from workspace root (e.g., mapped/... or unmapped/components/...)
GenFileName string `json:"gen_file_name"` // The generated filename (e.g., "generated.go", "generated.diff")
Status MappedFileStatus `json:"status"` // "mapped" or "unmapped"
BlockUUID string `json:"block_uuid"` // The UUID of the code block
Reason string `json:"reason,omitempty"` // Why it was unmapped (e.g., "no_parent_uuid")
Position int `json:"position"` // 0-indexed position of the code block in the original message
Language string `json:"language"` // The programming language (e.g., "go", "javascript")
}
MappedFileEntry represents a single file in the mapped dump result.
type MappedFileStatus ¶
type MappedFileStatus string
MappedFileStatus defines the mapping status of a file in the dump.
const ( MappedStatusMapped MappedFileStatus = "mapped" MappedStatusUnmapped MappedFileStatus = "unmapped" )
type MappedWriter ¶
type MappedWriter struct {
// PathMap maps Block-UUIDs to their resolved relative paths in the project.
// This is populated by the orchestrator (dumper.go) during the discovery pass.
PathMap map[string]string
}
MappedWriter implements the DumpWriter interface for the project-mapped strategy.
func (*MappedWriter) GetMessageDir ¶
GetMessageDir returns the root of the dump directory. For the mapped type, we don't use a hierarchical message structure; everything is organized by file path relative to the dump root.
func (*MappedWriter) Prepare ¶
func (w *MappedWriter) Prepare(outputDir string) error
Prepare wipes the output directory to ensure a clean state for the new dump.
func (*MappedWriter) SetPathMap ¶
func (w *MappedWriter) SetPathMap(pathMap map[string]string)
SetPathMap allows the orchestrator to inject the UUID-to-Path mappings.
func (*MappedWriter) WriteBlock ¶
WriteBlock handles the persistence of a code block. If the block is mapped, it writes to mapped/<path>/generated.<ext>. If unmapped, it writes to unmapped/components/<name>/generated.<ext> or unmapped/snippets/<index>/generated.<ext>.
func (*MappedWriter) WriteMessage ¶
func (w *MappedWriter) WriteMessage(msgDir string, msg db.Message) error
WriteMessage persists the raw markdown content of the message. It now also creates a message.json sidecar for database traceability.
func (*MappedWriter) WritePatch ¶
func (w *MappedWriter) WritePatch(msgDir string, patch markdown.PatchBlock, trim bool) error
WritePatch handles the persistence of a patch block. For the mapped dump, we only store the patch if it's unmapped or as a reference. NEW: Creates a subdirectory with generated.diff inside.
func (*MappedWriter) WritePatchedFile ¶
func (w *MappedWriter) WritePatchedFile(msgDir string, patch markdown.PatchBlock, header string, content string) error
WritePatchedFile persists the result of a successful patch application. This becomes the 'generated.<ext>' file in the mapped directory. NEW: For unmapped files, creates a subdirectory with generated.<ext> inside.
func (*MappedWriter) WriteProvenance ¶
func (w *MappedWriter) WriteProvenance(msgDir string, chats []db.Chat) error
WriteProvenance is a no-op for MappedWriter.
func (*MappedWriter) WriteProvenanceJSON ¶
func (w *MappedWriter) WriteProvenanceJSON(msgDir string, data Provenance) error
WriteProvenanceJSON persists the structured provenance data for a specific file.
func (*MappedWriter) WriteSourceFile ¶
func (w *MappedWriter) WriteSourceFile(msgDir string, relPath string, content string) error
WriteSourceFile copies the original source file content to the dump directory.
type MergedNode ¶
type MergedNode struct {
Message db.Message
Hash string
Chats []db.Chat
Children []*MergedNode
ChatCount int
MaxSubtreeTime time.Time
}
MergedNode represents a unique message in the merged tree.
type MergedWriter ¶
type MergedWriter struct {
// contains filtered or unexported fields
}
MergedWriter implements the DumpWriter interface for the merged/squashed strategy.
func (*MergedWriter) GetMessageDir ¶
GetMessageDir generates the directory path for a specific message. Format: <rank>_<count>_<role>_<hash>/ The hash is calculated deterministically from the message content and timestamp.
func (*MergedWriter) Prepare ¶
func (w *MergedWriter) Prepare(outputDir string) error
Prepare wipes the output directory to ensure a clean state for the new dump.
func (*MergedWriter) SetMetrics ¶
func (w *MergedWriter) SetMetrics(rank int, count int)
SetMetrics allows the orchestrator (dumper.go) to inject the calculated rank and count before calling GetMessageDir. This avoids changing the DumpWriter interface signature.
func (*MergedWriter) WriteBlock ¶
WriteBlock persists a code block.
func (*MergedWriter) WriteMessage ¶
func (w *MergedWriter) WriteMessage(msgDir string, msg db.Message) error
WriteMessage persists the raw markdown content of the message. It now also creates a message.json sidecar for database traceability.
func (*MergedWriter) WritePatch ¶
func (w *MergedWriter) WritePatch(msgDir string, patch markdown.PatchBlock, trim bool) error
WritePatch persists a patch block.
func (*MergedWriter) WritePatchedFile ¶
func (w *MergedWriter) WritePatchedFile(msgDir string, patch markdown.PatchBlock, header string, content string) error
WritePatchedFile persists the result of a successful patch application.
func (*MergedWriter) WriteProvenance ¶
func (w *MergedWriter) WriteProvenance(msgDir string, chats []db.Chat) error
WriteProvenance persists the chat metadata (provenance) for a message. It creates a chats.md file listing all chats that contain this message.
func (*MergedWriter) WriteProvenanceJSON ¶
func (w *MergedWriter) WriteProvenanceJSON(msgDir string, data Provenance) error
WriteProvenanceJSON is a no-op for the MergedWriter as it does not support the mapped shadow workspace.
func (*MergedWriter) WriteSourceFile ¶
func (w *MergedWriter) WriteSourceFile(msgDir string, relPath string, content string) error
WriteSourceFile is a no-op for the MergedWriter as it does not support the mapped shadow workspace.
type PatchError ¶
type PatchError struct {
Err error
Phase1Diff string // The diff string used in Phase 1
Phase2Diff string // The diff string used in Phase 2 (empty if not reached)
Phase2Offset int // The offset calculated for Phase 2
}
PatchError wraps a patching failure with details about the attempted phases.
func (*PatchError) Error ¶
func (e *PatchError) Error() string
func (*PatchError) Unwrap ¶
func (e *PatchError) Unwrap() error
type Provenance ¶
type Provenance struct {
FilePath string `json:"file_path"` // Relative path in the project
BlockUUID string `json:"block_uuid"` // The UUID of the code block
ParentUUID string `json:"parent_uuid"` // The UUID of the parent block
Version string `json:"version"` // The version string
ChatID int64 `json:"chat_id"` // The ID of the chat
MessageID int64 `json:"message_id"` // The ID of the message
ContractUUID string `json:"contract_uuid"` // The contract UUID
Model string `json:"model"` // The AI model name
Timestamp string `json:"timestamp"` // ISO 8601 timestamp
Action string `json:"action"` // e.g., "patch_applied", "full_code"
Authors []string `json:"authors"` // List of authors
}
Provenance represents the content of the provenance.json sidecar file.
type ProvenanceEntry ¶
type ProvenanceEntry struct {
Timestamp time.Time `json:"timestamp"`
Status ProvenanceStatus `json:"status"`
Action string `json:"action"` // "update-file" or "create-file"
FilePath string `json:"file_path"` // Relative to repo root
BlockUUID string `json:"block_uuid"` // The New Block-UUID
ParentUUID string `json:"parent_uuid"` // The UUID of the code being replaced
SourceVersion string `json:"source_version"` // The version being replaced
TargetVersion string `json:"target_version"` // The version of the new code
Author string `json:"author"` // The LLM that generated the code
ContractUUID string `json:"contract_uuid"` // Link to the global contract
Error string `json:"error,omitempty"` // Error message if status is failed
Description string `json:"description"` // User-defined intent for the change
}
ProvenanceEntry represents a single "receipt" in the project-local provenance.log.
type ProvenanceStatus ¶
type ProvenanceStatus string
ProvenanceStatus defines the state of a provenance log entry.
const ( ProvenanceSaved ProvenanceStatus = "saved" ProvenanceAttempted ProvenanceStatus = "attempted" ProvenanceFailed ProvenanceStatus = "failed" )
type ShadowWorkspace ¶
type ShadowWorkspace struct {
Hash string `json:"hash"` // The Workspace ID (Composite Hash)
MessageID int64 `json:"message_id"` // The ID of the message
ContractUUID string `json:"contract_uuid"` // The contract UUID
CreatedAt string `json:"created_at"` // ISO 8601 timestamp
ExpiresAt string `json:"expires_at"` // ISO 8601 timestamp
Stats MappedDumpStats `json:"stats"` // Summary statistics for the dump
Files []MappedFileEntry `json:"files"` // Cached list of files for the UI
}
ShadowWorkspace represents the metadata stored at the root of a mapped dump. It acts as the "Source of Truth" for the shadow workspace's validity and contents.
type TreeWriter ¶
type TreeWriter struct{}
TreeWriter implements the DumpWriter interface for the conversational tree strategy.
func (*TreeWriter) GetMessageDir ¶
GetMessageDir generates the directory path for a specific message. Format: chat_<id>_<truncated_name>/<visible_index>_<abbreviated_role>/
func (*TreeWriter) Prepare ¶
func (w *TreeWriter) Prepare(outputDir string) error
Prepare wipes the output directory to ensure a clean state for the new dump.
func (*TreeWriter) WriteBlock ¶
WriteBlock persists a code block, including its traceability header. The trim flag is passed to satisfy the interface, but the actual trimming is handled by the parser before this method is called.
func (*TreeWriter) WriteMessage ¶
func (w *TreeWriter) WriteMessage(msgDir string, msg db.Message) error
WriteMessage persists the raw markdown content of the message. It now also creates a message.json sidecar for database traceability.
func (*TreeWriter) WritePatch ¶
func (w *TreeWriter) WritePatch(msgDir string, patch markdown.PatchBlock, trim bool) error
WritePatch persists a patch block, including its metadata header. The trim flag is passed to satisfy the interface, but the actual trimming is handled by the parser before this method is called.
func (*TreeWriter) WritePatchedFile ¶
func (w *TreeWriter) WritePatchedFile(msgDir string, patch markdown.PatchBlock, header string, content string) error
WritePatchedFile persists the result of a successful patch application. This is a "result" file and does not include the GitSense metadata header.
func (*TreeWriter) WriteProvenance ¶
func (w *TreeWriter) WriteProvenance(msgDir string, chats []db.Chat) error
WriteProvenance is a no-op for the TreeWriter as provenance files are specific to the MergedWriter.
func (*TreeWriter) WriteProvenanceJSON ¶
func (w *TreeWriter) WriteProvenanceJSON(msgDir string, data Provenance) error
WriteProvenanceJSON is a no-op for the TreeWriter as it does not support the mapped shadow workspace.
func (*TreeWriter) WriteSourceFile ¶
func (w *TreeWriter) WriteSourceFile(msgDir string, relPath string, content string) error
WriteSourceFile is a no-op for the TreeWriter as it does not support the mapped shadow workspace.
type WorkspaceEntry ¶
type WorkspaceEntry struct {
MessageHash string `json:"message_hash"` // The original 8-char message hash
MessageID int64 `json:"message_id"` // The DB message ID
CreatedAt string `json:"created_at"` // ISO 8601 timestamp of dump creation
}
WorkspaceEntry represents a single shadow workspace associated with a contract. It maps the Workspace ID (Composite Hash) to its underlying message details.