|
| 1 | +<!-- SPDX-License-Identifier: MPL-2.0 --> |
| 2 | +<!-- SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell --> |
| 3 | + |
| 4 | +# sustainabot ReScript→AffineScript hand-port validation |
| 5 | + |
| 6 | +**Date**: 2026-05-26 |
| 7 | +**Agent**: Claude Opus 4.7 (1M context) |
| 8 | +**Session**: Issue #148 — gitbot-fleet/bots/sustainabot/bot-integration/src `.affine` parse validation |
| 9 | +**Status**: Validation complete; 6 PRs filed; gates on owner-merge |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +## Goal |
| 14 | + |
| 15 | +Run `affinescript check` on the 13 hand-ported `.affine` files under |
| 16 | +`bots/sustainabot/bot-integration/src/` and reduce every parse error to |
| 17 | +either a successful type-check or to `Resolve.UndefinedModule` (the |
| 18 | +expected residual when single-file `check` doesn't load the stdlib |
| 19 | +graph — INT-02 loader-bridge territory, out of scope here). |
| 20 | + |
| 21 | +The 13 files (a 4,939 LOC migration from the original `.res` set): |
| 22 | + |
| 23 | +``` |
| 24 | +src/Analysis.affine src/Main.affine src/Router.affine src/tea/Sub.affine |
| 25 | +src/Config.affine src/Oikos.affine src/Types.affine |
| 26 | +src/GitHubAPI.affine src/Report.affine src/Webhook.affine |
| 27 | +src/GitHubApp.affine src/tea/Cmd.affine |
| 28 | + src/tea/Runtime.affine |
| 29 | +``` |
| 30 | + |
| 31 | +## Approach |
| 32 | + |
| 33 | +For each parse failure encountered, decide **parser-fix** (upstream |
| 34 | +`hyperpolymath/affinescript`, `lib/parser.mly`) vs **hand-port-rewrite** |
| 35 | +(this repo, the `.affine` source). Default: |
| 36 | + |
| 37 | +* **parser-fix** when the failing syntax is documented as part of the |
| 38 | + AffineScript language surface (ADR-008/009 / SETTLED-DECISIONS in the |
| 39 | + affinescript repo) and dropping it would create a gap. |
| 40 | +* **hand-port-rewrite** when the syntax is an OCaml/ReScript-ism the |
| 41 | + language never promised. |
| 42 | + |
| 43 | +Constraint on every parser-fix: zero new LR conflicts. Baseline is |
| 44 | +**21 shift/reduce + 1 reduce/reduce**; verified after every patch via |
| 45 | +`menhir --explain`. |
| 46 | + |
| 47 | +## Outcome |
| 48 | + |
| 49 | +All 13 files now reach **Resolution** (parser layer fully clear). The |
| 50 | +work bundled into 6 PRs across 2 repos: |
| 51 | + |
| 52 | +### Parser PRs (hyperpolymath/affinescript) |
| 53 | + |
| 54 | +| PR | Scope | Branch | |
| 55 | +|---|---|---| |
| 56 | +| [#370](https://github.com/hyperpolymath/affinescript/pull/370) | Trailing-comma in fn params + expr lists; effect-annotated lambda `fn() -{IO}-> M { … }` | `claude/parser-trailing-comma-148` | |
| 57 | +| [#371](https://github.com/hyperpolymath/affinescript/pull/371) | fn-type with effect arrow `fn(A, B) -{E}-> R` in type position | `claude/parser-fn-type-eff-arrow-148` | |
| 58 | +| [#372](https://github.com/hyperpolymath/affinescript/pull/372) | Builtin-type qualified paths (`Int::to_string`); lowercase-module qualified paths (`json::encode_object`); `total` as a record field name | `claude/parser-builtin-qualified-paths-148` | |
| 59 | +| [#373](https://github.com/hyperpolymath/affinescript/pull/373) | Underscore-prefix idents `_key`, `_unused` lex as a single LOWER_IDENT (bare `_` still lexes as UNDERSCORE) | `claude/lexer-underscore-idents-148` | |
| 60 | +| [#376](https://github.com/hyperpolymath/affinescript/pull/376) | Record-update spread at start `Record #{ ..base, override: x }` | `claude/parser-record-spread-148` | |
| 61 | + |
| 62 | +### Hand-port PR (hyperpolymath/gitbot-fleet) |
| 63 | + |
| 64 | +| PR | Scope | Branch | |
| 65 | +|---|---|---| |
| 66 | +| [#206](https://github.com/hyperpolymath/gitbot-fleet/pull/206) | OCaml-style float ops `/.`, `*.`, `+.`, `-.` → unified AffineScript `/`, `*`, `+`, `-`; `pub fn handle(...)` → `pub fn dispatch(...)` (HANDLE is a reserved keyword) | `claude/sustainabot-parse-fixes-148` | |
| 67 | + |
| 68 | +## Validation oracle (post-merge) |
| 69 | + |
| 70 | +``` |
| 71 | +$ for f in bots/sustainabot/bot-integration/src/*.affine \ |
| 72 | + bots/sustainabot/bot-integration/src/tea/*.affine; do |
| 73 | + affinescript check "$f" |
| 74 | + done |
| 75 | +
|
| 76 | +Analysis.affine Resolution error: (Resolve.UndefinedModule … |
| 77 | +Config.affine Resolution error: (Resolve.UndefinedModule … |
| 78 | +GitHubAPI.affine Resolution error: (Resolve.UndefinedModule … |
| 79 | +GitHubApp.affine Resolution error: (Resolve.UndefinedModule … |
| 80 | +Main.affine Resolution error: (Resolve.UndefinedModule … |
| 81 | +Oikos.affine Resolution error: (Resolve.UndefinedModule … |
| 82 | +Report.affine Resolution error: (Resolve.UndefinedModule … |
| 83 | +Router.affine Resolution error: (Resolve.UndefinedModule … |
| 84 | +tea/Cmd.affine Resolution error: (Resolve.UndefinedModule … |
| 85 | +tea/Runtime.affine Resolution error: (Resolve.UndefinedModule … |
| 86 | +tea/Sub.affine Resolution error: (Resolve.UndefinedModule … |
| 87 | +Types.affine Resolution error: (Resolve.UndefinedModule … |
| 88 | +Webhook.affine Resolution error: (Resolve.UndefinedModule … |
| 89 | +``` |
| 90 | + |
| 91 | +`Resolve.UndefinedModule` is the expected residual: the cross-module |
| 92 | +loader is tracked separately under INT-02 in |
| 93 | +`hyperpolymath/affinescript` `docs/TECH-DEBT.adoc`. Closing that gap is |
| 94 | +a different effort, not within #148. |
| 95 | + |
| 96 | +## Gotchas discovered (captured for future hand-ports) |
| 97 | + |
| 98 | +Two hand-port-rewrite rules surfaced that are worth documenting up-front |
| 99 | +for the broader `.res → .affine` walk (affinescript#57): |
| 100 | + |
| 101 | +1. **`handle` is a reserved keyword** in AffineScript (HANDLE token, |
| 102 | + used by the effect-handler expression form |
| 103 | + `handle body { handler_arms }`). It parses as a token, not an |
| 104 | + identifier, so `pub fn handle(...)` is a syntax error. The |
| 105 | + `field_name` rule allows `handle` contextually as a record field |
| 106 | + name (the surrounding COLON disambiguates), but no equivalent is |
| 107 | + safe in fn-decl name position without grammar conflict risk. |
| 108 | + *Workaround*: rename to `dispatch`, `handle_request`, |
| 109 | + `handle_event`, etc. |
| 110 | + |
| 111 | +2. **No OCaml-style float operators.** AffineScript uses unified `+`, |
| 112 | + `-`, `*`, `/` for both Int and Float (per |
| 113 | + `examples/lessons/01_hello.affine`: `subtotal * 0.08`). `+.`, `-.`, |
| 114 | + `*.`, `/.` are never accepted and must be rewritten on port. This |
| 115 | + is a hand-port-rewrite, not a parser-fix candidate — adding the |
| 116 | + OCaml form would create operator overlap for no semantic benefit. |
| 117 | + |
| 118 | +Both are recorded in the agent's persistent memory for the next session |
| 119 | +and are also captured as `Refs gitbot-fleet#148` commits in #206. |
| 120 | + |
| 121 | +## Out of scope (filed separately) |
| 122 | + |
| 123 | +3 byte-identical `SafeDOMExample.affine` fixtures |
| 124 | +(`bots/{the-hotchocolabot,echidnabot,finishingbot}/examples/`) parse- |
| 125 | +fail with a different shape: they use a **pre-stabilization AffineScript |
| 126 | +dialect** with 8+ grammar divergences from current. Tracked at |
| 127 | +[gitbot-fleet#208](https://github.com/hyperpolymath/gitbot-fleet/issues/208). |
| 128 | +Recommended disposition: a single dialect-migration PR (or deletion if |
| 129 | +the examples are unreferenced — `grep -r SafeDOMExample` will say). |
| 130 | + |
| 131 | +## Conflict-cost on the parser |
| 132 | + |
| 133 | +All 5 upstream parser PRs together net **zero new LR conflicts**: the |
| 134 | +parser builds at 21 S/R + 1 R/R, identical to the pre-patch baseline. |
| 135 | +The conflict-neutrality discipline is required by ADR-012 (Grammar |
| 136 | +Changes Are Correctness Assertions) in the affinescript repo. |
| 137 | + |
| 138 | +## Status comment on the tracking issue |
| 139 | + |
| 140 | +A consolidated status post is on [gitbot-fleet#148](https://github.com/hyperpolymath/gitbot-fleet/issues/148#issuecomment-4542225835) |
| 141 | +linking each of the six PRs, showing the validation oracle output, and |
| 142 | +noting INT-02 as the next gate. The issue is **not** auto-closed by |
| 143 | +any `Refs` keyword — that's an owner-merge action per the |
| 144 | +`ISSUE-CLOSURE` rule in the repo's CLAUDE.md. |
| 145 | + |
| 146 | +--- |
| 147 | + |
| 148 | +*Generated 2026-05-26 by Claude Opus 4.7 (1M context).* |
0 commit comments