Files
hyperguild/ingestion/internal/wiki/log.go
T
mathiasandClaude Opus 5.5 138d6e2545
CI / Lint / Test / Vet (pull_request) Successful in 1m17s
CI / Mirror to GitHub (pull_request) Skipped
fix: generated and promoted writes go through the brain root (#188, #158)
Writers that created or rewrote brain files by path followed symlinks:
- promote/reject: os.MkdirAll + os.WriteFile of the destination, then
  os.Remove of the raw source. Now PutRegular + brainfs.Remove; the source
  is kept when the write is refused.
- StampProvenanceFile (brain_edit's re-stamp): provenance.ApplyFile read
  and rewrote by path. Now ReadRegular + WriteRegular; ApplyFile, now
  unused, is removed.
- BuildWingIndex (_index.md) and wiki.RebuildIndex (wiki/index.md): now
  PutRegular.
- wiki.AppendLog (log.md) and AutoTunnel's fuzzy-candidate log
  (raw/tunnel-candidates-*.md): now AppendRegular; tunnel's fileExists,
  now unused, is removed.
- New brainfs.Remove: clean path, real parent, removes a final symlink
  itself, never its target.

brain_edit's own atomic rename was already refused behind a symlinked
directory by #187's read check; a guard test pins it.

Pipeline writes, BackfillRefs, the watcher's raw/ markers and the session
archive in cmd/server follow in a separate PR (#158).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 22:39:41 +02:00

40 lines
1.0 KiB
Go

// ingestion/internal/wiki/log.go
package wiki
import (
"fmt"
"github.com/mathiasbq/hyperguild/ingestion/internal/brainfs"
"strings"
)
// AppendLog appends one ingestion record to brain/log.md.
func AppendLog(brainDir, source string, pages, warnings []string, date string) error {
var sb strings.Builder
fmt.Fprintf(&sb, "## %s — ingest\n\n", date)
fmt.Fprintf(&sb, "- **Source:** %s\n", source)
if len(pages) > 0 {
sb.WriteString("- **Pages written:**\n")
for _, p := range pages {
fmt.Fprintf(&sb, " - %s\n", p)
}
}
if len(warnings) > 0 {
sb.WriteString("- **Warnings:**\n")
for _, w := range warnings {
fmt.Fprintf(&sb, " - %s\n", w)
}
}
sb.WriteString("\n")
// Appended through the brain root, never through a symlink (#158).
bfs, err := brainfs.Open(brainDir)
if err != nil {
return fmt.Errorf("open brain: %w", err)
}
defer func() { _ = bfs.Close() }()
if err := bfs.AppendRegular("log.md", []byte(sb.String())); err != nil {
return fmt.Errorf("write log: %w", err)
}
return nil
}