oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1# Slice 5b: bounded per-file diffs
2
3Status: approved by the controller, 2026-11-26. ProtocolChangeDiffs = 35 (reallocated by the controller after main shipped 32, then Assistant files 33 and Places 34).
4
5## Source and transport
6
7Use the runner's existing private Git object store, alongside Engineering's
8`changeFiles` measurement in `internal/runner/thin/engineer.go`. The thin instance
9relays candidate packs between runners; it does not maintain a forge clone
10(`internal/equipo/chat/transfers.go`). Do not introduce instance forge credentials
11or a new clone solely to display a diff.
12
13Prepare a bounded collection of display patches for the accepted Engineering
14candidate, then upload it separately from the ordinary step/task view. This
15makes a viewed diff available when the runner is offline and keeps device GETs
16read-only. Bind every upload to instance, assigned runner, task, step, attempt,
17base and candidate, with a digest and declared byte count. Validate all bindings
18at acceptance; publish the collection only with its matching accepted report.
19An interrupted collection remains unavailable and is pruned. Duplicate uploads
20must match their digest and content; conflicting replacements are refused.
21
22This needs a new runner protocol capability and bounded chunk frames, following
23the research-image transfer pattern, plus a small final-report reference. The
24number must be allocated with the controller before code, considering other
25open branches. Old runners and old steps keep the reviewed Amadan link. No
26patches go into task lists, snapshots, events, the Coordinator tool or prompts.
27The existing Review measurements and merge authority remain unchanged.
28
29## Device endpoint and binding
30
31`GET /api/v1/tasks/{id}/changes/diff?candidate_sha=<sha>&path=<encoded-path>`
32
33Use exactly the task-read authority, including current membership. Resolve the
34current candidate's latest Engineering step on the server. The requested path
35must exactly match a validated change_files entry; derive base and rename source
36from that entry, never from caller-supplied Git arguments. A candidate mismatch
37returns a reviewed conflict; unknown or invisible tasks are indistinguishable.
38The candidate and task visibility are checked again before returning bytes.
39
40Return task/step/attempt/base/candidate/path identity, status, old path if renamed,
41and either bounded unified patch text or an explicit unavailable reason.
42Flags distinguish truncation, binary content and secret withholding. Native
43renders plain text, never HTML, and discards responses for a candidate or file
44that is no longer selected. Responses use no-store and never offer a raw-file
45or unredacted-download mode. New user-facing reasons require reviewed copy.
46
47## Computation and bounds
48
49Only entries already included in the at-most-200-file facts listing are eligible.
50Use the exact candidate against its recorded base, including the existing
51verified initial-commit/empty-tree behavior. Read Git objects, not checkout paths;
52never follow symlinks or submodules. Treat paths literally, with the shared path
53validator (including U+061C), NUL-safe listing and no shell interpolation.
54Disable hooks, external diff, textconv, filters, config discovery and network
55access, following the existing trusted Git environment. Rename identity comes
56from the measured entries, not a second heuristic applied to one path.
57
58Approved hard limits: 1 MiB per input blob, 8 MiB of input across a collection,
59200 files, 64 KiB and 2,000 lines of patch text per file, 2 MiB retained patch text
60per candidate, and 128 KiB encoded JSON per device response. Process files in
61stable path order. Apply a 10-second total collection deadline and one collector
62per runner; cap unaccepted uploads per attempt and prune them after 15 minutes.
63No unbounded subprocess buffering; kill and wait on timeout/overflow. Collection
64failure must not fail Engineering or affect merging.
65
66Binary/non-UTF-8 files have metadata only. Large blobs, symlinks and submodules
67link out without content. Oversized scanned text patches may end at a complete
68line with truncated=true; omitted files get an explicit unavailable result, not
69an empty diff. Native retains the file counts and the Amadan action throughout.
70Accepted collections are replaced when the candidate changes and expire after
71seven days; the task then falls back to Amadan. These display limits are separate
72from the Review gate's evidence limits.
73
74## Secret handling
75
76Scan complete bounded before/after blobs before generating or clipping patches.
77Use the runner's pinned Gitleaks rules and trusted scanner setup already used by
78Preview (`preview_security.go`); repository configs, ignores and inline allow
79comments cannot weaken it. Also apply known credential-value and existing token
80redaction checks. If a secret is detected, withhold that file's whole diff for
81this slice. If scanning fails, times out or encounters an over-limit input,
82withhold it as unavailable. Never ship a partially scanned prefix.
83
84The instance independently rechecks the bounded incoming patch with the same
85trusted detection rules before persistence; a runner's clean flag is not proof.
86Do not store rejected patch bytes, secret matches or raw scanner reports. Audit
87identity, digest, outcome and sizes only. This reduces accidental disclosure;
88pattern scanning cannot prove arbitrary source text contains no secret.
89
90## Tests and approval points
91
92Test task visibility/revocation, stale candidate races, wrong runner/attempt and
93upload replay, literal paths and renames, initial commits, binary/large files,
94every byte/line/time cap, interrupted uploads, expiry, and old-runner fallback.
95Secrets tests cover added/deleted/context lines, multiline keys, encoded values,
96cut boundaries, scanner failure and hostile repository scanner configuration.
97Mutate each guard. Add OpenAPI/contract coverage and a perf budget record; native
98fake-server tests prove the selected file and candidate reach the endpoint.
99
100Controller decisions before implementation: approve precomputed runner patches
101and their storage/retention bounds, allocate the protocol capability, and confirm
102whole-file withholding for detected secrets. This note proposes no new copy.
103
104
105## Implementation refinements
106
107A complete 64 KiB file patch fits a single base64 durable frame under the
108256 KiB stream bound. There are no partial unscanned chunks in storage. The
109collection hash binds every path, refusal, truncation flag and patch byte; its
110matching accepted report publishes the collection transactionally.
111
112Both ends scan in memory with the pinned Gitleaks 8.30.1 embedded default rules,
113using a fresh detector, a trusted configuration and no path-based exemptions.
114No candidate files configure it. The library logger is disabled. Known-token
115checks run on decoded layers too. Full before/after inputs are scanned on the
116runner; the instance independently scans each complete patch before storage.
117
118Expired bytes are pruned by the existing sweep and during uploads. An internal
119attempt-bound deadline remains on the step to distinguish expiry from an old
120runner that never supplied a patch. It is never projected to the Coordinator.
121