the lock records what the source could be read as, and check audits it

Access is verified once, at fetch, and the copy is durable — so whether an
adoption is still legitimate rests on the relative visibility of two
repositories, which somebody can change with a checkbox a year later without ever
seeing the adoption. The lock gains an optional fourth field and check turns that
from a silent permanent hazard into something that runs.

It costs nothing at add time, because the anonymous request already happened to
decide whether to warn and the answer was being thrown away, and one request per
run at check time rather than one per document, because only our own visibility
has to be current. The stored value decays in both directions, so a source
recorded not-public is re-probed only when the alarm would fire, and a source that
has since gone public updates the lock and says nothing.

Fixes a bug found while testing the alarm rather than after shipping it.
sourceVisibility returned public whenever no credential was configured, which is
sound at add time — the fetch had just succeeded anonymously — and wrong in the
audit, where it is a probe and not a fetch: it would have silently cleared real
alarms. Probing is now its own function that always asks with no credential,
because what matters is what a stranger can read and not what we can.

The value is recorded as public or not-public and never private: an anonymous
request tells those apart and nothing finer, so it cannot see two repositories
private to different people, which is the case that genuinely widens access.

Three-field locks still load, and unknown visibility round-trips as absent rather
than as a value.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018UTxuSizozEA8yDitPuris
This commit is contained in:
2026-09-08 09:22:42 -04:00
co-authored by Claude Opus 5
parent da6e8b9b51
commit b3617ed195
5 changed files with 216 additions and 32 deletions
+36 -6
View File
@@ -25,8 +25,10 @@ const Dir = ".loom/externals"
const File = ".locks"
const header = "# loomctl locks — one record per adopted document.\n" +
"# path<TAB>url<TAB>etag The url is resolved: a short form would follow\n" +
"# whatever the default branch is at the time you ask.\n"
"# path<TAB>url<TAB>etag[<TAB>visibility]\n" +
"# The url is resolved: a short form would follow whatever the default branch\n" +
"# is at the time you ask. visibility is what the source could be read as when\n" +
"# it was fetched, because that is checked once and the copy is durable.\n"
// Record is one adopted document.
type Record struct {
@@ -38,8 +40,28 @@ type Record struct {
URL string
// ETag is the publisher's, verbatim, including its quotes.
ETag string
// Visibility is what the source could be read as when it was fetched:
// "public", "not-public", or empty for locks written before this was
// recorded.
//
// It is deliberately coarse. An anonymous request tells public from
// not-public and nothing finer, so this cannot distinguish two repositories
// private to different people — which is the case where adopting between
// private repositories genuinely widens access.
//
// It is recorded because access is checked once, at fetch, and the copy is
// durable. Whether an adoption is still legitimate depends on the relative
// visibility of two repositories, which somebody can change with a checkbox
// a year later without ever seeing the adoption.
Visibility string
}
// Visibility values. Never "private": the signal cannot support the word.
const (
Public = "public"
NotPublic = "not-public"
)
// Set is every lock, keyed by path.
type Set struct {
file string
@@ -75,10 +97,14 @@ func LoadFile(file string) (*Set, error) {
continue
}
parts := strings.Split(line, "\t")
if len(parts) != 3 {
return nil, fmt.Errorf("%s:%d: want 3 tab-separated fields, got %d", file, n, len(parts))
if len(parts) != 3 && len(parts) != 4 {
return nil, fmt.Errorf("%s:%d: want 3 or 4 tab-separated fields, got %d", file, n, len(parts))
}
s.recs[parts[0]] = Record{Path: parts[0], URL: parts[1], ETag: parts[2]}
r := Record{Path: parts[0], URL: parts[1], ETag: parts[2]}
if len(parts) == 4 {
r.Visibility = parts[3]
}
s.recs[parts[0]] = r
}
return s, sc.Err()
}
@@ -112,7 +138,11 @@ func (s *Set) Save() error {
var b strings.Builder
b.WriteString(header)
for _, r := range s.All() {
fmt.Fprintf(&b, "%s\t%s\t%s\n", r.Path, r.URL, r.ETag)
if r.Visibility == "" {
fmt.Fprintf(&b, "%s\t%s\t%s\n", r.Path, r.URL, r.ETag)
continue
}
fmt.Fprintf(&b, "%s\t%s\t%s\t%s\n", r.Path, r.URL, r.ETag, r.Visibility)
}
tmp, err := os.CreateTemp(filepath.Dir(p), ".locks-*")
if err != nil {