feat(knowledge): allow nested subdirectories in pack file paths#60
Merged
Conversation
Safari now lets knowledge-pack files live in subdirectories (knowledge/<scope>/<sub>/<file>). The runner's path layer assumed a flat single leaf and rejected anything deeper, so a nested file would sync up to the cloud but fail to stage back onto the workspace on the next session (StageKnowledgeFiles / ReconcileKnowledgeManifest both gate on validateKnowledgeRelPath). - validateKnowledgeRelPath: accept knowledge/<scope>/<leaf...> with len>=3, validating every leaf segment (no empty/`.`/`..`/dotfile) so a nested path still can't escape the scope dir when joined onto the root. - walkKnowledgeTree: rewrite with filepath.WalkDir so reconcile discovers (and can prune) nested files instead of ignoring subdirectories. StageKnowledgeFiles already MkdirAll's parent dirs, so nested files land correctly once validation passes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Companion to fc-safari #142 (knowledge-pack subdirectory support). Safari now accepts nested
rel_paths, but the runner's path layer assumed a flat single leaf and rejected anything deeper. Without this change a nested knowledge file syncs up to the cloud but fails to stage back onto the workspace on the next session —StageKnowledgeFilesandReconcileKnowledgeManifestboth gate onvalidateKnowledgeRelPath.Change
validateKnowledgeRelPath— acceptknowledge/<scope>/<leaf…>withlen(parts) >= 3, validating every leaf segment (no empty /./../ dotfile) so a nested path still cannot escape the scope directory when joined onto the workspace root.walkKnowledgeTree— rewrite withfilepath.WalkDirso reconcile discovers (and can prune) nested files instead of ignoring subdirectories.StageKnowledgeFilesalreadyMkdirAlls parent dirs, so nested files land correctly once validation passes.Verification
go build ./...clean;go test ./environment/...green; gofmt clean.TestStageKnowledgeFiles_NestedSubdir,TestReconcileKnowledgeManifest_Nested(nested kept + pruned-as-orphan); extendedTestValidateKnowledgeRelPathandTestStageKnowledgeFiles_RejectedPaths(traversal / nested-dotfile / empty-segment still rejected).filepath.Join, so a..prefix is caught and never reaches the write sink. No escape found.Rollout
mainis the runner's sole release trunk. After merge this needs av*tag release + fleet rollout (BYOC self-update / sandbox image rebuild + advertised version bump) for the subdirectory round-trip to work end-to-end against deployed runners.🤖 Generated with Claude Code