fix(audit): expose verified visit exports and export-only recovery

This commit is contained in:
2026-10-20 21:20:06 +01:00
parent f87e1ed488
commit ca78b24f47
14 changed files with 359 additions and 59 deletions
+43 -26
View File
@@ -54,8 +54,46 @@ func (r *runner) scanArtifacts(runID int64, sequence int, directory string, publ
return nil, 0, 0
}
files := []protocol.StageArtifact{}
seen := map[string]bool{}
skipped, truncated := 0, 0
used := int64(0)
add := func(full, name string, info fs.FileInfo) bool {
if seen[full] {
return true
}
if len(files) >= maxArtifactFiles {
skipped++
return false
}
if info.Size() > maxArtifactFileBytes {
skipped++
return true
}
if used+info.Size() > maxArtifactTotalBytes {
truncated++
return false
}
contentType := mime.TypeByExtension(filepath.Ext(name))
if contentType == "" {
contentType = sniffArtifact(root, full)
if contentType == "" {
skipped++
return true
}
}
used += info.Size()
seen[full] = true
files = append(files, protocol.StageArtifact{Name: name, SizeBytes: info.Size(), ContentType: contentType, URL: artifactURL(runID, sequence, name)})
return true
}
// Mandatory runtime evidence must not disappear behind hundreds of private
// captures/public deliverables in the bounded inventory.
for _, name := range []string{"input.md", "memory.md", "output.md", "session.html"} {
full := path.Join(rel, name)
if info, err := root.Lstat(full); err == nil && info.Mode().IsRegular() && info.Mode()&fs.ModeSymlink == 0 && info.Size() <= maxArtifactFileBytes {
add(full, name, info)
}
}
scan := func(relative, prefix string) {
_ = fs.WalkDir(root.FS(), relative, func(name string, entry fs.DirEntry, walkErr error) error {
if walkErr != nil {
@@ -65,6 +103,9 @@ func (r *runner) scanArtifacts(runID int64, sequence int, directory string, publ
if name == relative || entry.IsDir() {
return nil
}
if seen[name] {
return nil
}
if entry.Type()&fs.ModeSymlink != 0 || !entry.Type().IsRegular() {
skipped++
return nil
@@ -74,36 +115,12 @@ func (r *runner) scanArtifacts(runID int64, sequence int, directory string, publ
skipped++
return nil
}
if len(files) >= maxArtifactFiles {
skipped++
return fs.SkipAll
}
if info.Size() > maxArtifactFileBytes {
skipped++
return nil
}
if used+info.Size() > maxArtifactTotalBytes {
truncated++
return fs.SkipAll
}
artifactName := strings.TrimPrefix(name, relative+"/")
artifactName = prefix + artifactName
full := path.Join(relative, strings.TrimPrefix(artifactName, prefix))
contentType := mime.TypeByExtension(filepath.Ext(artifactName))
if contentType == "" {
contentType = sniffArtifact(root, full)
if contentType == "" {
skipped++
return nil
}
if !add(full, artifactName, info) {
return fs.SkipAll
}
used += info.Size()
files = append(files, protocol.StageArtifact{
Name: artifactName,
SizeBytes: info.Size(),
ContentType: contentType,
URL: artifactURL(runID, sequence, artifactName),
})
return nil
})
}