Files
knox/internal/cmd/obsidian.go
T
david d6d2a24ddc style: gofmt all packages (#4)
Applies gofmt to the 18 files that were already unformatted at HEAD (pre-existing debt — 122 insertions / 122 deletions, whitespace plus import-block reorderings only; `git diff -w` confirms no semantic changes).

Kept on its own branch so the functional change set (see the review-hardening PR) stays reviewable without formatting noise.

Verified: go build, go vet, go test ./... pass on this branch; a merge simulation with the functional branch produces a clean 3-way merge with all tests green.
Reviewed-on: #4
Co-authored-by: David Gwilliam <dhgwilliam@gmail.com>
Co-committed-by: David Gwilliam <dhgwilliam@gmail.com>
2026-09-17 09:05:57 +00:00

72 lines
1.9 KiB
Go

package cmd
import (
"fmt"
"log"
"github.com/david/knox/internal/db"
"github.com/david/knox/internal/ingest"
"github.com/spf13/cobra"
)
func NewObsidianCmd(kdb *db.KnoxDB) *cobra.Command {
var vault string
cmd := &cobra.Command{
Use: "obsidian",
Short: "Ingest Obsidian notes into the knowledge index",
Long: `Scans an Obsidian vault for markdown notes, extracts frontmatter
(title, tags, dates), and fingerprints them into the index.
Auto-detects vault path from ~/.config/obsidian/obsidian.json
or override with --vault.`,
RunE: func(c *cobra.Command, args []string) error {
ing := ingest.NewObsidianIngester(vault)
log.Printf("[knox] ingesting Obsidian notes...")
results, err := ing.IngestAll()
if err != nil {
return fmt.Errorf("obsidian ingest: %w", err)
}
if len(results) == 0 {
fmt.Println("No Obsidian notes found.")
return nil
}
var newCount, dupCount int
for _, result := range results {
_, isNew, err := kdb.RecordObservation(db.ObservationRecord{
Fingerprint: result.Fingerprint,
SourceID: result.SourceID,
SourcePath: result.SourcePath,
Project: result.Project,
ContentType: result.ContentType,
Title: result.Title,
Summary: result.Summary,
CreatedAt: result.CreatedAt,
LineStart: result.LineStart,
LineEnd: result.LineEnd,
Confidence: result.Confidence,
IngesterVersion: result.IngesterVersion,
Trigger: "obsidian_ingest",
Provenance: ingest.ProvenanceJSON(result.Provenance),
})
if err != nil {
log.Printf("[knox] db error: %v", err)
continue
}
if isNew {
newCount++
} else {
dupCount++
}
}
fmt.Printf("Obsidian notes: %d new, %d updated\n", newCount, dupCount)
return nil
},
}
cmd.Flags().StringVarP(&vault, "vault", "v", "", "Obsidian vault path (auto-detect if empty)")
return cmd
}