Files
kenn-io--agentsview/internal/parser/directory_jsonl_source_set.go
wehub-resource-sync f99010fae1
CI / lint (push) Failing after 1s
CI / frontend (push) Failing after 1s
CI / scripts (push) Failing after 1s
CI / Go Test (ubuntu-latest) (push) Failing after 0s
CI / frontend-node-25 (push) Failing after 1s
CI / docs (push) Failing after 0s
CI / coverage (push) Failing after 0s
CI / e2e (push) Failing after 0s
Docker / build-and-push (push) Failing after 1s
CI / integration (push) Failing after 4m43s
CI / Go Test (windows-latest) (push) Has been cancelled
CI / Desktop Unit Tests (Windows) (push) Has been cancelled
Desktop Artifacts / Desktop Build (Linux (arm64)) (push) Has been cancelled
Desktop Artifacts / Desktop Build (Linux) (push) Has been cancelled
Desktop Artifacts / Desktop Build (Windows) (push) Has been cancelled
Desktop Artifacts (macOS) / Desktop Build (macOS (aarch64)) (push) Has been cancelled
Desktop Artifacts (macOS) / Desktop Build (macOS (x86_64)) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:30:36 +08:00

60 lines
1.7 KiB
Go

package parser
import (
"path/filepath"
"strings"
)
// DirectoryJSONLSourceSet constrains JSONL sources to the common
// <root>/<project>/<session>.<ext> shape while keeping JSONLSourceSet's source
// methods available through embedding.
type DirectoryJSONLSourceSet struct {
JSONLSourceSet
}
// NewDirectoryJSONLSourceSet returns a JSONL source helper for providers whose
// transcripts live one project directory below each configured root. The
// returned helper is always recursive enough to classify watched project files,
// but it rejects root-level and deeper nested files through IncludePath.
func NewDirectoryJSONLSourceSet(
provider AgentType,
roots []string,
opts ...JSONLOption,
) DirectoryJSONLSourceSet {
var options JSONLSourceSetOptions
for _, opt := range opts {
opt(&options)
}
userIncludePath := options.IncludePath
options.Recursive = true
options.IncludePath = func(root, path string) bool {
if !IsDirectoryJSONLPath(root, path) {
return false
}
return userIncludePath == nil || userIncludePath(root, path)
}
if options.ProjectHint == nil {
options.ProjectHint = func(root, path string) string {
return DirectoryJSONLProjectFromPath(path)
}
}
return DirectoryJSONLSourceSet{
JSONLSourceSet: jsonlSourceSetFromOptions(provider, roots, options),
}
}
func IsDirectoryJSONLPath(root, path string) bool {
rel, err := filepath.Rel(root, path)
if err != nil {
return false
}
parts := strings.Split(rel, string(filepath.Separator))
return len(parts) == 2 &&
parts[0] != "" && parts[0] != "." && parts[0] != ".." &&
parts[1] != "" && parts[1] != "." && parts[1] != ".."
}
func DirectoryJSONLProjectFromPath(path string) string {
return filepath.Base(filepath.Dir(path))
}