# Continuation Prompt — REBOL/View 2.7.8.3.1 Clone (`demo33`)

Paste the **short start prompt** at the bottom into a fresh **pi** session on
this VPS.  This file is the detailed handoff and is self-contained: all
history lives in the repo (`docs/history/`, `HANDOFF-PROMPT.md`,
`REVERSE-ENGINEERING.md`, `evidence/`, `r2-extracted/`).

---

## 1. Mission and current status

We are building a **functional, clean-room clone of REBOL/View 2.7.8.3.1
(Win32)** in C, starting from the original executable and the REBOL sources
recovered from its boot image with **REA**.  Work happens in
`/root/rebol-view-clone/`.  The clone loads the recovered R2 boot image,
mezzanine, Internet Protocols, Graphics/Draw, View/VID and View Desktop
modules, so the REBOL-level code is the original.

State at handoff (build marker **demo33-2026-11-28**):

- **Golden conformance suite: 93/93 passing on native Linux and 93/93 on the
  Windows PE build under Wine** (goldens generated by the reference binary).
- **re-bol.com corpus: 325 extracted snippets, 20 sections, 0 errors**, all
  sections complete (no timeout / no missing result) on Linux **and** Wine.
- **GUI screenshot regression: 3/3 shots match their baselines (0.00 % diff)**
  (`tools/gui_shots.py`, `tests/gui/`, `tests/gui-baseline/`).
- Bundled examples smoke (`tools/examples_smoke.py`, native + Wine), network
  smoke (`tools/net_smoke.py`, native + Wine incl. HTTP/FTP port specs) and
  the two-party port harness (`tools/ports_smoke.py`, incl. `--mix` against
  the reference) all pass.

Published artifacts (see §9 for URLs and how to verify):

- `rebol-view.exe` / `rebol-view-demo33-2026-11-28.exe`
  - 1022976 bytes
  - sha256 `5c95d5415fee7b6b7cbc9992dc220bff6c43563a164076080d664721e471bcc9`
- `rebol-view-2-clone.zip` / `rebol-view-2-clone-demo33-2026-11-28.zip`
  - 1259500 bytes
  - sha256 `19a793b68fc69733c379cb5d1112a77a4e3809f75f31b39972dfe3f352f8c648`
- Reference oracle: `reference-rebol-view-278-3-1.exe`
  (sha256 `215e28f9660472b6271a9902573c9d190e4d7ccca33fcf8d6054941d52a3ab85`).
- Pi Web download mirror: `/root/rebol-view-clone/downloads/` (see §9).

**Verify before debugging any user report:** `rebol-view.exe -v` must print

```
REBOL/View 2.7.8.3.1 (demo33-2026-11-28)
```

If the marker is missing, the user has an old/cached download: always publish
**uniquely versioned filenames** (`…-demo33-2026-11-28.exe`) next to the
stable ones, because browsers and CDNs cache the stable URL.

Baseline commands (do this first):

```bash
cd /root/rebol-view-clone
python3 tests/tools/run.py test            # Linux clone  -> 93/93
python3 tests/tools/run.py test --wine     # Windows PE   -> 93/93
python3 tools/examples_sections.py         # 20 sections, 0 errors
python3 tools/examples_sections.py --wine  # 20 sections, 0 errors
python3 tools/examples_smoke.py            # bundled examples, native
python3 tools/examples_smoke.py --wine     # bundled examples, Wine GUI
python3 tools/net_smoke.py                 # local HTTP/FTP/POP/SMTP/IMAP
python3 tools/net_smoke.py --wine
python3 tools/ports_smoke.py --mix         # clone <-> reference TCP/UDP/awake
python3 tools/ports_smoke.py --mix --wine
python3 tools/gui_shots.py                 # GUI screenshot regression
```

Tooling notes: the Windows PE is expected at `/tmp/rebol-view.exe` (rebuild per
§3); the reference needs Wine + Xvfb.  If a GUI/probe run leaves stale
processes, clean them first:

```bash
pkill -9 -x rebol-view.exe; pkill -9 -x reference-rebol
pkill -9 -x wine; pkill -9 -x wineserver32; pkill -9 -x wineserver
pkill -9 -x Xvfb; rm -f /tmp/.X9*-lock /tmp/.X1[0-9][0-9]-lock
```

(`pkill -x`, never `pkill -f` with a pattern that matches your own command.)

---

## 2. Key paths

```
r2clone/                     C interpreter clone (Linux `r2` + Windows objects)
  reb.h value.c scan.c eval.c native.c port.c view_win.c net.c ffi.c
  main.c image.c draw.c hash.c zlib.c boot_image.c modules.c
  vendor/zlib/               vendored zlib 1.2.11 deflate (Z_SOLO/NO_GZIP)
  stb_image.h font8x8.h Makefile
reference-rebol-view-278-3-1.exe   original R2 oracle (never modify/delete)
r2-extracted/                21 recovered REBOL source modules
tests/                       93-case golden suite (cases/, expected/, fixtures/, tools/run.py)
tests/gui/                   static VID layouts for the screenshot harness
tests/gui-baseline/          expected screenshots (widgets, image effects, text list)
examples/                    demo.r (10 apps), ports.r, hello.r, tour.r, gui.r, draw.r, effects.r
tools/examples_corpus.py     fetch/extract/validate the re-bol.com examples
tools/examples_sections.py   replay the corpus section by section
tools/ports_smoke.py         two-party port harness (clone <-> reference)
tools/net_smoke.py           local HTTP/FTP/POP/SMTP/IMAP + port-spec smoke test
tools/examples_smoke.py      run every examples/*.r (native + Wine GUI)
tools/gui_shots.py           GUI screenshot regression (Wine/Xvfb + Pillow)
tools/extract_boot.py        reproducible boot-image extractor
examples-corpus/             examples.txt, cases/, index.json, REPORT.md, fixtures/
dist-r2/                     shipped package (exe + sources + tests + docs + zip)
downloads/                   current exe/zip/manifest mirrored for Pi Web downloads
docs/history/                dated snapshots (do not delete)
docs/download-page.html      landing page source (copy to /root/download/)
evidence/                    REA/behavioural evidence (port model, image filters, metrics)
debug/                       instrumented demo harnesses used for GUI debugging
README.md REVERSE-ENGINEERING.md HANDOFF-PROMPT.md CONTINUE-PROMPT.md START-PROMPT.txt
/root/download/              Caddy-served static dir (https://download.xqx1.com/)
```

---

## 3. Build

### Linux (native, default test mode)

```bash
cd /root/rebol-view-clone/r2clone
make clean && make          # -> ./r2   (make clean is mandatory: no header deps)
```

### Windows PE32 (mingw-w64, used by `--wine`)

```bash
cd /root/rebol-view-clone/r2clone
rm -f /tmp/rel-*.o
for f in value scan eval native port view_win net boot_image modules main \
         image draw hash zlib ffi; do
  i686-w64-mingw32-gcc -O2 -std=gnu99 -c $f.c -o /tmp/rel-$f.o || echo "FAIL $f"
done
for f in deflate trees adler32 crc32 zutil; do
  i686-w64-mingw32-gcc -O2 -std=gnu99 -DZ_SOLO -DNO_GZIP -Ivendor/zlib \
    -c vendor/zlib/$f.c -o /tmp/rel-z-$f.o
done
i686-w64-mingw32-gcc -O2 -s -o /tmp/rebol-view.exe /tmp/rel-*.o \
  -lm -luser32 -lgdi32 -lwinhttp -lws2_32 -lmsimg32 -lcomdlg32 -lshell32 -lwinmm
```

- `port.c`, `ffi.c` and the five vendored zlib sources **must** be included.
- `-lws2_32` (dns/ports), `-lwinmm` (`sound://`), `-lwinhttp` (HTTP).
- Bump `R2CLONE_BUILD` in `r2clone/reb.h` for every published change
  (currently `demo33-2026-11-28`).
- Run the PE under Wine with Xvfb:
  `WINEPREFIX=/root/.wine32 WINEARCH=win32 WINEDEBUG=-all xvfb-run -a /usr/lib/wine/wine /tmp/rebol-view.exe -s Z:/tmp/script.r`
- A stale `/tmp/rebol-view.exe` silently breaks `--wine`, `gui_shots`,
  `net_smoke --wine` and `ports_smoke --wine`: always rebuild it (§3) before
  those, and check `-v` shows the current marker.

---

## 4. Golden-output suite (primary oracle)

`tests/cases/*.r` are deterministic R2 scripts (no REBOL header, no `quit`).
`tests/expected/*.txt` are generated by running the **reference** under Wine.

```bash
python3 tests/tools/run.py test             # Linux clone
python3 tests/tools/run.py test --wine      # Windows PE under Wine
python3 tests/tools/run.py test --diff
python3 tests/tools/run.py test --only 86 --diff
python3 tests/tools/run.py gen              # generate missing goldens (oracle)
python3 tests/tools/run.py gen --all        # regenerate every golden
```

The runner wraps each case with a `print`/`prin`/`probe` capture layer and
`either error? try [...]` (that specific form is required: R2 re-raises an
error value stored in a word).  Cases must be deterministic and must not use
`now`, `random`, `alert`, `request-*`, `editor`, external networks or `view`
(unless the case is about them).

R2 quirks that shape the goldens (full list in `tests/README.md`):

- `try` does **not** catch "has no value": a case with an undefined word drops
  the reference into its error console and the run times out.
- Ports: R2 only flushes TCP writes when the writing port is **closed** (or
  the event loop runs); `copy` on a file port returns the whole buffered image
  each time; `read port` raises in R2 (the clone returns the data — a
  deliberate, documented deviation); `port/awake` receives the **port itself**,
  once per `wait`, and is not called on a timeout; `wait <time>`/`wait []` do
  not process port events.
- A case must **not** `change-dir`: the harness writes its result file
  relative to `system/script/path`.  (Test `what-dir`/change-dir behaviour by
  spawning a separate script instead.)
- Port cases must close the **client** side first, otherwise the listener port
  lands in `TIME_WAIT` and the next run may fail to bind it.  Use fixed high
  ports (19xxx) and close everything.
- `mold` reproduces R2's layout: the break is a flag on the **value**
  (`Series.nl[i]`, plus `Series.eol` for the position before `]`).  A break
  becomes space + newline + 4 spaces per nesting level and is emitted even for
  the first value of a block or of a sub-series (`next`/`find`/`at`); the
  closing bracket goes on its own line when a break was emitted at that level
  or the tail flag is set.  `copy`/`reduce`/`compose` keep the per-value flags
  but drop the tail flag; `insert`/`append` of a block carry the source's
  flags; `poke` clears the replaced value's flag; `load "[^/1 2]"` loses the
  flag because R2 shares the integers 0 and 1 (the clone reproduces that in
  `Scan_Keeps_NL`).  `make object!`/`make function!` deep copies keep the
  markers, which is what makes the VID style objects mould identically.
- `size-text` uses a metric table measured from the reference (Arial advances
  for ASCII 32..126 at point sizes 8..48 plus line heights) — do not replace it
  with a formula; long strings may still differ by a pixel or two because R2's
  inter-character spacing is not derivable from single-char probes.
- R2's effect filters were reverse-engineered by delta/ramp probes: `flip`
  (axes), `rotate 90/180/270` (odd-size 180° leaves the centre pixel
  transparent), `invert`, `grayscale` (0.3/0.59/0.11 truncated), `key`,
  `colorize`, `crop`, `luma`, `multiply` (v·c/128), `blur`
  (`{0,1,0,1,1,1,0,1,0}/5`), `sharpen` (`{0,-1,0,-1,8,-1,0,-1,0}/4`,
  truncated) and `contrast n` (a per-channel stretch around that channel's
  *image mean*: `mean + trunc((v-mean)*num/den)` with `num/den = (18+n)/18`
  for `n>=0` and `18/(25+|n|)` for `n<0`, `n` clamped to ±128).  `tint`
  (integer: a lossy colour-space rotation, `tint 0` alone shifts pixels by
  ±1) and `hsv` (tuple) remain unimplemented — see §9 of
  `evidence/PORT-MODEL-EVIDENCE.md` for the probe data.
- Loop variables are local to their loop but visible to nested blocks
  (`repeat i 3 [append s rejoin [i " "]]` works inside a function); the clone
  binds the name in a temporary context and rebinds it in the body, paths
  included.  A loop value never leaks to a global of the same name.
- `CHANGE` on a **string** replaces `length? new-text` characters by default
  (`change copy "Tom" "Phil"` -> `"Phil"`, `change copy "abcdef" [1 2 3]` ->
  `"123def"`), while on a **block** it replaces one element; `/part` wins.
- A **path component may be a paren** or a get-word: `b/(i)`, `o/(w)`,
  `m/(j)/(1)` and the set-path forms `b/(i): value`, `o/(w)/f: value` all
  work (the paren is evaluated).  `read %dir/` returns names **sorted**
  case-insensitively.
- A spec's `[types...]` block is **enforced at call time**: `f1: func [a
  [integer!]] [a]  f1 "x"` -> `script/expect-arg` with the message
  `f1 expected a argument of type: integer`; `none` is only accepted when the
  block allows it, refinement arguments are checked too, and a **missing
  argument** raises `script/no-arg`.  The clone normalises the datatype words
  of a spec to datatype values when the function is built (that is why HELP
  prints `(Type: integer)` without the `!`) and matches R2's typeset names
  (`series!`, `number!`, `any-string!`, `any-word!`, `any-path!`,
  `any-block!`, `any-function!`, `any-type!`) by name.
- `type? first [string!]` is `word` in R2: type literals are plain words that
  resolve to datatypes when evaluated (the clone stores words too).
- `to-date <integer>` errors in R2 (no day-number conversion); add days to a
  date instead (`1-Jan-2030 + n`).
- `hline`/`vline`/`shape`/`fill-rule`/`matrix` are accepted-but-ignored by R2
  itself; `set-modes`/`get-modes` on files and file ports raise in R2.

Cases 70–87 (added over demo19–demo29):

```
70-port-object-model 71-tcp-client-server 72-udp-port 73-file-port
74-port-read-io 75-port-wait-errors 76-port-awake-accept 77-port-awake-read
78-image-mold-binary 79-face-effects 80-image-effects-filters
81-port-spec-block 82-text-metrics 83-what-dir-absolute 84-mold-line-breaks
85-mold-breaks-more 86-loop-binding 87-contrast-effect 88-eval-path-forms
89-gradient-effect 90-image-placement 91-path-paren-forms
92-arg-type-checks 93-change-default-range
```

---

## 5. re-bol.com example corpus

Source: <https://re-bol.com/examples.txt> (638 KB, 325 snippets, 20 sections).

```bash
python3 tools/examples_corpus.py fetch && python3 tools/examples_corpus.py extract
python3 tools/examples_sections.py                      # section sweep
python3 tools/examples_sections.py --detail             # error ids / args
python3 tools/examples_sections.py --section DRAW --detail
python3 tools/examples_sections.py --wine
python3 tools/examples_sections.py --timeout 180
python3 tools/examples_sections.py --diff --section FUNCTIONS   # clone vs reference
```

`--diff` replays a section through the reference *and* the clone and diffs the
printed output line by line (each difference is tagged with the `--@<snippet
line>` marker that precedes it).  The result file is rewritten after every
snippet so a stalled reference still leaves a comparable prefix; the reference
is given a *relative* result path (it cannot write `to-file "Z:/..."`), the
prelude's `now` avoids `to-date` of an integer and its `random` stub is
deterministic and type-preserving, and snippets that are *supposed* to raise
are marked `ERROR (expected)`.

Harness behaviour (do not regress): the prelude stubs interactive/GUI words
(`alert`, `request-*`, `editor`, `browse`, `view`→layout, `wait`, deterministic
`now`), loops are capped by the clone's native `R2_LOOP_LIMIT=1000`, each
snippet runs inside `try`/`catch`, results are written to an **absolute** path
(so `change-dir` cannot hide them), and the network filter (`NET_RE`) skips
URL forms *and* `scheme: '<net-scheme>` port specs.  Five paragraphs are
explicitly skipped (infinite console app, invalid `parse` example, incomplete
PORTS snippet, MySQL/SQLite GUI examples needing servers);
`examples-corpus/REPORT.md` documents them.  Update the report after every
sweep if counts change.

---

## 6. What is implemented (state at demo33)

- Core language: scan/eval, series (strings/binaries/blocks/files/URLs,
  images), objects, contexts, functions/closures, refinements, `parse`
  (incl. `/all`, `into`, `copy`/`set`, `to`/`thru`), dates/times/money/
  tuples/pairs, codecs (`enbase`/`debase`, zlib compress/decompress, all
  `checksum` variants), bitsets, `R2_LOOP_LIMIT`.
- **Formatted `mold`**: R2's line-break markers per block element (with the
  nested leading-break rule), reproduced through `copy`/`reduce`/`compose`,
  function bodies, and `load` results; path word marks (`o/:w`, `a/b:`).
- **Image text form + `to-binary`**: `make image! [WxH #{rgb} #{alpha}]`
  (10 pixels/line, alpha block only when needed), raw `B,G,R,A` bytes.
- **Face image effects** (shared by the window renderer and `to-image`):
  `flip`, `rotate 90/180/270`, `invert`, `grayscale`, `key`, `colorize`,
  `crop`, `luma`, `multiply`, `blur`, `sharpen`, `contrast` (per-channel mean
  stretch), `gradient` (R2's exact `c1 + trunc((c2-c1)*i/n)` ramp along the
  dialect's direction pair, shared with the draw command), `emboss` (approx.),
  `arrow`, `draw`.  The effect dialect resolves colour words (`blue`, `gold`).  `to-image`
  paints an edge only when it is bevelled or has an edge image (R2 leaves
  the base face's plain 2x2 colour edge unpainted).
- **Text metrics**: `size-text`/wrapping/caret geometry from the reference's
  own Arial metric table; `what-dir` returns the absolute script directory in
  R2's `%/Z/dir/` form (mapped to `Z:/dir/` for file I/O).
- **Generic ports** (`port.c`): `open` of `tcp://`, `udp://`, `file://`,
  `console://` (URL/file/block/object specs, all R2 refinements) → a real
  `port!` with R2's 45-field spec, `mold`/`form`, `state`, port numbering;
  `insert`/`write` (TCP, UDP incl. broadcast, `/lines` CRLF),
  `copy`/`read` (`/part`, `/binary`, `/lines`, `/direct`, `/seek`), `first`
  (accept), `wait`/`wait/all` (+timeouts), `close`, `read-io`/`write-io`,
  `length?`, `get-modes`/`set-modes`, `query`, `port/timeout`, bounded
  (10 s) non-blocking connect, and the **event model** (`port/awake` gets the
  port, one event per `wait`, EOF is a read event).
- **Port specs in `read`/`write`**: block specs are evaluated key by key
  (`target: join …` works), file/network/socket targets resolved.
- **Network**: HTTP(S) (redirects, `load` of images), passive FTP
  (`read`/`write`/`dir?`), POP3/IMAP reads, SMTP `send`, DNS,
  `sound://` WAV playback.
- **View/VID**: recovered View Desktop styles, native controls, canvas faces,
  nested panes (text-list rows, selection, row actions), request-list/dir,
  editor Find dialog (focus + Enter), `unview/only`, `to-image` of a face,
  `save/png`, rate timers, the 10-app demo (`examples/demo.r`).
- **Formatted MOLD**: the per-value break-flag model (see §4) reproduces
  every layout R2 keeps, including the VID style objects and their inherited
  functions (golden 85), and `compose` now has `/deep` and `/only` and
  splices block results.
- **Loop binding**: `repeat`/`foreach`/`for`/`forall`/`forskip`/`remove-each`/
  `use` variables are local yet visible inside nested blocks (golden 86).
- **Evaluator path forms**: `obj/func/ref: value` (calls the function with
  that refinement and the value as its argument), `obj/series/n/field: value`,
  and `make function!` copying spec/body (so functions survive later binding
  of shared style blocks).  This is what lets VID's `scroller` lay out its
  children, so TEXT-LIST/REQUEST-LIST now show up/down scrollbar arrows and
  row selection (golden 88; GUI baseline renewed).
- **Series/path semantics**: `change`'s string default range, paren and
  get-word path components (incl. set-paths), sorted directory listings, and
  call-time **argument type checking** for user functions (goldens 91-93).
- **Corpus differential harness**: `tools/examples_sections.py --diff` runs a
  section through the reference *and* the clone and diffs the printed output
  (see §5); it found and drove the fixes above.
- **Tests/tooling**: 93 goldens; corpus sweep + differential mode; examples
  smoke; net smoke; two-party ports smoke (incl. `--mix` against the
  reference); GUI screenshot regression with baselines.

Known gaps (deliberate, documented): `tint`/`hsv` pixel maths (their exact
colour space was not identified; both are accepted and ignored);
`scale`/`extend` placement parity (the *default* placement now matches R2:
top-left, natural size, clipped, with `fit`/`aspect` scaling — golden 90); `merge`/`grid`/`tile-view`/`reflect`/`shadow`; chaining two
convolutions in one effect block diverges from R2; at |contrast| > ~70 the
reference occasionally lands one intensity step below the exact formula;
requestor list keyboard selection/editor Find polish; `port/sub-port` and
REBOL-level protocol ports; memory reclamation (no GC); `read port` returns
data where R2 raises.  (The TEXT-LIST/REQUEST-LIST scrollbar arrows and row
selection now render; R2 has no list keyboard navigation in 2.7.8.3.1.)

---

## 7. Suggested next priorities (in order)

1. **Keep sweeping the corpus with `--diff`** (the highest-yield work right
   now).  `python3 tools/examples_sections.py --diff --section <NAME>` diffs a
   section against the reference line by line and prints the `--@<snippet
   line>` marker for each difference.  Sections not yet swept to zero:
   `DRAW`, `PORTS`, `NETWORK PORTS`, `OBJECTS` (one cosmetic HELP line),
   `SEVERAL APPLICATION EXAMPLES`, `VARIOUS ADDITIONAL APPL…`.  Note the
   reference stalls on endless examples, so a section may end with
   `ref=timeout`; only the common prefix is compared.  Some remaining diffs
   are *cosmetic mold layout* of derived blocks (`extract`/`map`/`sort`
   results) because R2 keeps the line-break flag on the **value**, while the
   clone keeps it per series position — the real fix is a small refactor that
   moves `nl` into `Value` (see §8, "known model gaps").
2. **`tint` / `hsv`**: the last two chroma effects.  Argument types come from
   the effect dialect (`tint: [integer!]`, `hsv: [tuple!]`; `contrast` is done,
   golden 87).  `tint 0` alone perturbs pixels by ±1 (a lossy colour-space
   round trip, probably the same 16-bit pipeline that makes the reference land
   one step low at high contrast), and `tint n` rotates that space;
   `hsv h.s.v` is *not* a plain HSV add (see `evidence/PORT-MODEL-EVIDENCE.md`
   §9.4).  A componentwise HSV model was brute-forced and only reached ~80 % of
   the pixels, so model it in a wider space (16-bit) instead.
3. **`extend` effect** (the last piece of the stock-button look): the BTN
   style stretches its 7x14 stock image with `extend 14`.  Probes show an
   integer argument pins the last column/row at the far edge and fills the gap
   with the column before it, but the pair forms (`extend 1x1`, `0x1`, `5x2`)
   and narrow images behave differently — see
   `evidence/PORT-MODEL-EVIDENCE.md` §12.  Get more probes before coding.
4. **Requestor/editor polish** (lock with `tools/gui_shots.py`): the
   `text-list`/`request-list` scrollbar arrows and row selection render now
   (demo30); still open: editor Find highlight + scroll-to-match, live
   request-file filters, and a `tests/gui/request-list.r` baseline (compare a
   requestor popup against a reference screenshot, see §8).  R2 2.7.8.3.1 has
   **no** list keyboard navigation, so do not add it.
5. **Port depth**: `port/sub-port` and REBOL-level protocol ports (so the
   recovered `12-REBOL_Internet_Protocols.r` handlers can drive sockets), i.e.
   a native port dispatcher that calls `system/schemes/<scheme>/init|open|
   read|write|awake`; then `open http://...` returns R2's port object
   (`scheme: 'HTTP`, `host`, `port-id`, `path`/`target`, `timeout: 30`,
   `state` with the request in `outBuffer`, `sub-port` = the TCP port,
   `status`/`size`/`date` filled by the handler).
6. **Memory**: series/context/function refcounts and window teardown (ASan
   first) — the clone currently leaks by design.
7. **Coverage**: more goldens for `parse`/`series` edge cases and screenshot
   coverage for more widgets.

---

## 8. Debugging tips (learned the hard way)

- **Old downloads**: check `-v` first; publish versioned filenames.
- **Stale processes**: `pkill -9 -x rebol-view.exe`, `-x reference-rebol`,
  `-x wineserver32`, `-x Xvfb` (see §1).  Stale Xvfb displays and Wine
  processes are the #1 cause of flaky GUI/probe runs.
- **A stale `/tmp/rebol-view.exe`** makes `--wine`/`gui_shots`/`net_smoke
  --wine` test an old build: rebuild it and check `-v`.
- **GUI debugging recipe** (window placement needs a real X server):

  ```bash
  pkill -9 -x rebol-view.exe; pkill -9 -x wine; pkill -9 -x Xvfb; sleep 1
  Xvfb :99 -screen 0 1280x1024x24 -ac & sleep 2
  WINEPREFIX=/root/.wine32 WINEARCH=win32 WINEDEBUG=-all DISPLAY=:99 \
    timeout 120 /usr/lib/wine/wine /tmp/rebol-view.exe -s Z:/path/demo.r &
  sleep 16
  DISPLAY=:99 xwininfo -root -tree | grep REBOL     # window ids/geometry
  DISPLAY=:99 ffmpeg -y -f x11grab -video_size 1280x1024 -i :99 -frames:v 1 /tmp/shot.png
  DISPLAY=:99 xdotool mousemove X Y click 1
  DISPLAY=:99 xdotool keydown Down keyup Down; xdotool keydown Return keyup Return
  ```

  Screenshots are the fastest way to see placement/controls; `tools/gui_shots.py`
  automates the crop/compare part.
- **Corpus differential harness** (the best bug-finder right now):

  ```bash
  python3 tools/examples_sections.py --diff --section FUNCTIONS --max-diffs 8
  ```

  Each difference is tagged with the `--@<snippet line>` marker of the snippet
  that produced it (`examples-corpus/index.json` maps lines to code).  It only
  compares the common prefix, so a `ref=timeout` is normal for sections with
  endless examples.  Snippets that are *supposed* to raise are listed in
  `EXPECT_ERROR` (they print `ERROR (expected)` and are not counted).
- **Reference quirks that broke the harness** (do not re-learn them): the
  reference cannot write an absolute `to-file "Z:/…"` path (it lands in its
  error console) — use a relative name with `cwd` set; `to-date <integer>`
  errors; `view/new: :view` is a *set-path call* (`view` gets called, it does
  not assign) so the prelude must not use it; `mold`/`form` of a *datatype*
  drops the `!`; `first [block!]` is a **word**.
- **Known model gap**: R2 keeps MOLD's break flag on the **value**, the clone
  keeps it per series position.  Everything that copies values therefore needs
  explicit flag copying (`copy`/`reduce`/`compose`/`insert`/`append` do it;
  `extract`/`map`/`sort` results still lose it).  Moving `nl` into `Value`
  would fix the whole class at once — see §7.1.
- **Probing the oracle for language behaviour**: run a small script through the
  capture wrapper (`/tmp/pp/probe.py` pattern: redefine `print`/`prin`/`probe`
  to append to a buffer and `write %result.txt` incrementally) so partial
  output survives; the reference is a GUI binary and its stdout is not usable
  under Wine.  `cat -A` shows trailing spaces, which matter for `mold`.
- **Trace flags**: `R2_TRACE=1` prints the `near` context for Linux script
  errors; `R2_SKIP_VIEW=1` skips the View Desktop module;
  `R2_EXTRA_MODULE=/path.r` evaluates an extra module; `R2_VIEW_DEBUG=1`
  traces `[view]`/`[key]`/`[timer]`/`[repos]`; `R2_PORT_DEBUG=1` traces port
  I/O; `R2_SPEC_DEBUG=1` prints parsed port specs.  The PE's stdout must be
  redirected to a file and flushed.
- **ASan**: `make clean && make CFLAGS="-g -O1 -std=gnu99 -fsanitize=address
  -fno-omit-frame-pointer -Wno-unused-parameter -Wno-unused-variable
  -Wno-unused-function"` then `ASAN_OPTIONS=detect_leaks=0 ./r2 /tmp/case.r`.
- If the reference "hangs", it dropped into its error console (its `try` does
  not catch "has no value") — screenshot it or simplify the case.
- R3 sources (for algorithms/checksums): <https://github.com/rebol/rebol>
  (a copy may be at `/tmp/rebol-src`; the AGG effect backend is not there).

---

## 9. Packaging and publishing

After code/docs changes: run both suites, the corpus sweep, examples smoke,
net smoke, ports smoke and `gui_shots.py` (§1).  Then:

```bash
cd /root/rebol-view-clone
# 1) bump R2CLONE_BUILD in r2clone/reb.h, rebuild BOTH targets (§3)
# 2) refresh dist-r2 (exclude .o files!)
make -C r2clone clean
cp /tmp/rebol-view.exe dist-r2/rebol-view.exe
cp README.md REVERSE-ENGINEERING.md dist-r2/
rm -rf dist-r2/tests && cp -r tests dist-r2/tests          # includes tests/gui*
rm -rf dist-r2/clone-source && mkdir -p dist-r2/clone-source
cp r2clone/*.c r2clone/*.h r2clone/Makefile dist-r2/clone-source/
cp -r r2clone/vendor dist-r2/clone-source/
mkdir -p dist-r2/tools
cp tools/examples_corpus.py tools/examples_sections.py tools/net_smoke.py \
   tools/examples_smoke.py tools/ports_smoke.py tools/gui_shots.py \
   tools/extract_boot.py dist-r2/tools/
cp examples-corpus/REPORT.md dist-r2/
cp examples/*.r dist-r2/examples/
# 3) build the package zip (prompts are published separately: they quote the
#    zip's own hash)
cd dist-r2 && rm -f rebol-view-2-clone.zip && zip -qr rebol-view-2-clone.zip .
unzip -l rebol-view-2-clone.zip | grep -c '\.o$'      # must be 0
sha256sum rebol-view.exe rebol-view-2-clone.zip
```

Publish to `/root/download` (Caddy serves <https://download.xqx1.com/>):

```bash
cd /root/rebol-view-clone && cp dist-r2/rebol-view.exe dist-r2/rebol-view-2-clone.zip /root/download/
cd /root/download
cp rebol-view.exe rebol-view-demoN-YYYY-MM-DD.exe
cp rebol-view-2-clone.zip rebol-view-2-clone-demoN-YYYY-MM-DD.zip
sha256sum rebol-view-2-clone.zip rebol-view.exe | tee rebol-view-2-clone.sha256
sha256sum rebol-view-demoN-YYYY-MM-DD.exe rebol-view-2-clone-demoN-YYYY-MM-DD.zip \
  | tee rebol-view-demoN-YYYY-MM-DD.sha256
```

**Pi Web download mirror** (so the files are downloadable from the browser of
the user running the session — Pi Web serves any file under the session cwd):

```bash
mkdir -p /root/rebol-view-clone/downloads
cd /root/rebol-view-clone/downloads
rm -f rebol-view-demoOLD*.exe rebol-view-2-clone-demoOLD*.zip rebol-view-demoOLD*.sha256
cp /root/download/rebol-view-demoN-YYYY-MM-DD.exe \
   /root/download/rebol-view-2-clone-demoN-YYYY-MM-DD.zip \
   /root/download/rebol-view-demoN-YYYY-MM-DD.sha256 .
sha256sum -c rebol-view-demoN-YYYY-MM-DD.sha256
# refresh downloads/README.txt (names, sizes, hashes, both link styles)
```

Then update **every** place with the new sizes/hashes/marker: `CONTINUE-PROMPT.md`
§1, `HANDOFF-PROMPT.md`, `README.md`/`tests/README.md`/`REVERSE-ENGINEERING.md`
if counts changed, `dist-r2/README.txt`, `docs/download-page.html` (plus copy to
`/root/download/rebol-view-clone.html`), snapshot the prompts/report into
`docs/history/`, and re-cut the prompt bundle:

```bash
cd /root/download
cp /root/rebol-view-clone/CONTINUE-PROMPT.md CONTINUE-PROMPT.md
cp /root/rebol-view-clone/START-PROMPT.txt START-PROMPT.txt
cp /root/rebol-view-clone/{README.md,REVERSE-ENGINEERING.md,HANDOFF-PROMPT.md} .
cp /root/rebol-view-clone/tests/README.md REBOL-VIEW-TESTS.md
cp /root/rebol-view-clone/examples-corpus/REPORT.md REBOL-VIEW-CORPUS-REPORT.md
cp CONTINUE-PROMPT.md rebol-view-clone-CONTINUE-PROMPT-YYYY-MM-DD.md
cp START-PROMPT.txt rebol-view-clone-START-PROMPT-YYYY-MM-DD.txt
rm -f rebol-view-clone-next-session-YYYY-MM-DD.zip*
zip -q rebol-view-clone-next-session-YYYY-MM-DD.zip CONTINUE-PROMPT.md \
  START-PROMPT.txt HANDOFF-PROMPT.md README.md REVERSE-ENGINEERING.md \
  REBOL-VIEW-TESTS.md REBOL-VIEW-CORPUS-REPORT.md
sha256sum rebol-view-clone-next-session-YYYY-MM-DD.zip \
  > rebol-view-clone-next-session-YYYY-MM-DD.sha256
```

Current release (copy/paste, replacing demoN with the new marker):

```bash
cd /root/rebol-view-clone
# versioned copies next to the stable ones (browsers cache the stable URL)
cp dist-r2/rebol-view.exe /root/download/rebol-view-demoN-YYYY-MM-DD.exe
cp dist-r2/rebol-view-2-clone.zip /root/download/rebol-view-2-clone-demoN-YYYY-MM-DD.zip
cd /root/download
sha256sum rebol-view-2-clone.zip rebol-view.exe > rebol-view-2-clone.sha256
sha256sum rebol-view-demoN-YYYY-MM-DD.exe rebol-view-2-clone-demoN-YYYY-MM-DD.zip \
  > rebol-view-demoN-YYYY-MM-DD.sha256
cd /root
tar czf /root/download/rebol-view-clone-snapshot-demoN-YYYY-MM-DD.tar.gz \
  --exclude='rebol-view-clone/r2clone/*.o' --exclude='rebol-view-clone/r2clone/r2' \
  --exclude='rebol-view-clone/downloads' \
  --exclude='rebol-view-clone/dist-r2/rebol-view-2-clone.zip' rebol-view-clone
# Pi Web mirror: keep ONLY the current versioned files + the prompt bundle
cd /root/rebol-view-clone/downloads
rm -f rebol-view-demoOLD* rebol-view-2-clone-demoOLD* rebol-view-clone-snapshot-demoOLD*
cp /root/download/rebol-view-demoN-YYYY-MM-DD.exe \
   /root/download/rebol-view-2-clone-demoN-YYYY-MM-DD.zip \
   /root/download/rebol-view-demoN-YYYY-MM-DD.sha256 \
   /root/download/rebol-view-clone-snapshot-demoN-YYYY-MM-DD.tar.gz .
sha256sum -c rebol-view-demoN-YYYY-MM-DD.sha256
```

Verify live (public + Pi Web):

```bash
curl -s https://download.xqx1.com/rebol-view-demoN-YYYY-MM-DD.sha256
curl -s -o /tmp/pub.exe https://download.xqx1.com/rebol-view-demoN-YYYY-MM-DD.exe
sha256sum /tmp/pub.exe
WINEPREFIX=/root/.wine32 WINEARCH=win32 WINEDEBUG=-all xvfb-run -a \
  /usr/lib/wine/wine /tmp/pub.exe -v          # marker check
# Pi Web mirror (needs the deployment password in /etc/pi-web.env):
PW=$(grep '^PI_WEB_PASSWORD=' /etc/pi-web.env | cut -d= -f2-)
curl -s -o /dev/null -w "%{http_code} %{size_download}\n" -u "pi:$PW" \
  "https://pi.xqx1.com/api/files/root/rebol-view-clone/downloads/rebol-view-demoN-YYYY-MM-DD.exe?type=download"
```

Do not ship `.o` files; keep the versioned filenames in release notes/commands.

---

## 10. First actions in the new session

1. Read this file, `tests/README.md`, `examples-corpus/REPORT.md`,
   `REVERSE-ENGINEERING.md` §6a/§7, `HANDOFF-PROMPT.md` and skim
   `docs/history/`.
2. Run the full baseline (§1): 93/93 Linux, 93/93 Wine, corpus 20/0 both,
   examples smoke, net smoke, ports smoke `--mix` (Linux + Wine), `gui_shots`.
3. Verify `/tmp/rebol-view.exe -v` shows `(demo33-2026-11-28)`; if not, rebuild
   it (§3) before trusting any Wine result.
4. Take the top priority from §7 (the corpus `--diff` sweep, then `tint`/
   `hsv`/`extend`, then requestor polish and port depth), add a golden/corpus/gui check where deterministic, fix, rerun the
   whole matrix, update docs, bump the marker, repackage with a new versioned
   filename, publish, and verify the live hash + `-v` (§9).
5. Do not ask for permission between steps.  Never delete `docs/history/`,
   `HANDOFF-PROMPT.md`, `r2-extracted/`, `evidence/` or the reference oracle.

---

## 11. Preservation / where the history lives

Nothing in `docs/history/`, `HANDOFF-PROMPT.md`, `r2-extracted/`, `evidence/`
or the reference oracle may be deleted.  Every release adds a dated report and
a dated copy of this prompt there, plus a snapshot tarball and the handoff
bundle in `/root/download/` and `/root/rebol-view-clone/downloads/`.

- `docs/history/` — dated snapshots of the handoff/report/prompt (one per
  release; `REPORT-demoN-YYYY-MM-DD.md`, `CONTINUE-PROMPT-demoN-…md`).
- `HANDOFF-PROMPT.md` — historical state and the accumulated bug/fidelity list
  (has a section per recent demo).
- `REVERSE-ENGINEERING.md` — REA method, recovered-source analysis, coverage,
  known gaps (including the reverse-engineered port model, image/effects and
  text-metric notes).
- `evidence/PORT-MODEL-EVIDENCE.md` — the oracle experiments behind the port
  model, image text form, effect filters, text metrics, draw no-ops, port
  specs and `form`-of-words.
- `README.md`, `tests/README.md`, `examples-corpus/REPORT.md` — current user,
  test and corpus docs.
- `r2-extracted/` — the 21 recovered REBOL modules.
- `dist-r2/` — the shipped package (sources, tests incl. GUI baselines, docs).
- `/root/download/` — published artifacts, manifests, dated prompts, bundle,
  landing page.
- Optional snapshot tarball for the handoff:

  ```bash
  cd /root && tar czf rebol-view-clone-snapshot-$(date +%Y%m%d).tar.gz \
    --exclude='rebol-view-clone/r2clone/*.o' \
    --exclude='rebol-view-clone/r2clone/r2' \
    rebol-view-clone
  ```

---

## Short start prompt

```
Read /root/rebol-view-clone/CONTINUE-PROMPT.md (and /root/rebol-view-clone/START-PROMPT.txt) and continue the REBOL/View 2 clone work from exactly where it leaves off. Baseline: 93/93 golden cases on Linux and Wine, examples.txt corpus 20 sections / 0 errors, examples smoke + net smoke + ports smoke (--mix) + gui_shots all passing. Start by sweeping the corpus with `python3 tools/examples_sections.py --diff` (DRAW, PORTS, OBJECTS first) and fixing what it finds, then tint/hsv, the `extend` effect, requestor/editor polish and port depth. Work autonomously: keep the golden suite, corpus, smoke tests, GUI baselines and docs updated, rebuild and re-verify on Linux and Wine, bump the build marker, and republish versioned artifacts (including the Pi Web downloads/ mirror) when appropriate. Don't ask for permission between steps.
```
