Changeset 0.21.4 (#90)

This commit is contained in:
2026-03-01 19:42:22 +00:00
parent bbbbe65bfa
commit d67cfd37c2
21 changed files with 1572 additions and 11 deletions

View File

@@ -20,7 +20,7 @@ func NewWorkspaceStore() *WorkspaceStore { return &WorkspaceStore{} }
// ── columns ────────────────────────────────
const workspaceCols = `id, owner_type, owner_id, name, root_path, max_bytes, status, indexing_enabled, created_at, updated_at`
const workspaceCols = `id, owner_type, owner_id, name, root_path, max_bytes, status, indexing_enabled, git_remote_url, git_branch, git_credential_id, git_last_sync, created_at, updated_at`
const workspaceFileCols = `id, workspace_id, path, is_directory, content_type, size_bytes, sha256, index_status, chunk_count, created_at, updated_at`
// ── scanners ───────────────────────────────
@@ -28,9 +28,11 @@ const workspaceFileCols = `id, workspace_id, path, is_directory, content_type, s
func scanWorkspace(row interface{ Scan(dest ...interface{}) error }) (*models.Workspace, error) {
var w models.Workspace
var maxBytes sql.NullInt64
var gitRemote, gitBranch, gitCredID sql.NullString
err := row.Scan(
&w.ID, &w.OwnerType, &w.OwnerID, &w.Name,
&w.RootPath, &maxBytes, &w.Status, &w.IndexingEnabled,
&gitRemote, &gitBranch, &gitCredID, stN(&w.GitLastSync),
st(&w.CreatedAt), st(&w.UpdatedAt),
)
if err != nil {
@@ -39,6 +41,15 @@ func scanWorkspace(row interface{ Scan(dest ...interface{}) error }) (*models.Wo
if maxBytes.Valid {
w.MaxBytes = &maxBytes.Int64
}
if gitRemote.Valid {
w.GitRemoteURL = &gitRemote.String
}
if gitBranch.Valid {
w.GitBranch = &gitBranch.String
}
if gitCredID.Valid {
w.GitCredentialID = &gitCredID.String
}
return &w, nil
}
@@ -107,6 +118,15 @@ func (s *WorkspaceStore) Update(ctx context.Context, id string, patch models.Wor
if patch.IndexingEnabled != nil {
b.Set("indexing_enabled", *patch.IndexingEnabled)
}
if patch.GitRemoteURL != nil {
b.Set("git_remote_url", *patch.GitRemoteURL)
}
if patch.GitBranch != nil {
b.Set("git_branch", *patch.GitBranch)
}
if patch.GitCredentialID != nil {
b.Set("git_credential_id", *patch.GitCredentialID)
}
if !b.HasSets() {
return nil
}
@@ -406,6 +426,13 @@ func (s *WorkspaceStore) UpdateFileIndexStatus(ctx context.Context, fileID, stat
return err
}
func (s *WorkspaceStore) SetGitLastSync(ctx context.Context, workspaceID string, t time.Time) error {
_, err := DB.ExecContext(ctx,
`UPDATE workspaces SET git_last_sync = ?, updated_at = datetime('now') WHERE id = ?`,
t.Format(timeFmt), workspaceID)
return err
}
// wsCosineSimilarity computes cosine similarity between two vectors.
// Named to avoid collision with the KB package-level function.
func wsCosineSimilarity(a, b []float64) float64 {