Skip to content

Docs: Add the scripts spec - #68

Merged
ozgb merged 16 commits into
mainfrom
spec-scripts
Nov 30, 2026
Merged

ozgb merged 16 commits into
mainfrom
spec-scripts

Conversation

@ozgb

@ozgb ozgb commented Nov 28, 2026

Copy link
Copy Markdown
Owner

Spec: scripts, the COB interpreter, the piece state and the piece queries.

Written against kit interfaces-v66 / reference-traces-v55 (commit 74bdf5ef). The spec states every
slot of interfaces/scripts.h 3.0, the four events of Apply, the five sim events the effect command
records, the five effects the module publishes, the state it owns (the scripts, their channels,
statics, piece records and model states), the opcode table with exactness rules, the quirk list, and
16 examples, 15 of them recomputed from the spec's own definitions.

Model: opencode / deepseek-v4.1-flash
Lead: opencode

Checks:

  • uv run tools/speclint.py specs/scripts.md --kit <the kit>: passes
  • every example recomputed (checksum 0x8177e6b2, sleep 6 and 5, spin 182 and 364, the angles, the
    sizes and the frees)
  • phase 2 (leakage), two rounds: changes on 91ff9c6 (21 findings, all answered), approve on 3d6ba03

Left out:

  • phase 1 (completeness) and the sandboxed implementer run are in progress; their verdicts are issue
    comments on Spec: Write the scripts spec for btm byte-tactics-moddable#1197.
  • The kit's scripts entry lacks services.RecordSimEvent and the map placement service, and the
    reference's SetCob allocates through no service; the spec names each gap and they are raised on
    #1197.

opencode added 2 commits November 27, 2026 22:13
Assisted-by: opencode:deepseek-v4.1-flash
Assisted-by: opencode:deepseek-v4.1-flash
@ozgb

ozgb commented Nov 28, 2026

Copy link
Copy Markdown
Owner Author

Spec reviewer: phase 2 (leakage) of 3d6ba03: approve

First round on 91ff9c6 returned changes with 21 findings, all answered in 3d6ba03: the query's
stack[0..3] and sp 3 (Q1 and example 5), the 16-byte payload sizes, START form 0's silent
failure, RETURN's pop only with a callback, SET_YARD before SCRIPT_VALUE, the piece setters' model
writes, SetCob's grow-in-place, the node count, the −1 bank, the short statics read, the read set
(g_simGlobals, Game.units, Game.poolCount), the kit's entry without blocked, the fuel rule,
the callback's address-to-offset conversion, the wake mask, STORE's no-pop modes, services 4.2, and
the leakage of the Push/Pop/Wake helpers, the cross-slot calls, the pose helpers and Q4.

Second round, on the 10-line diff: none. uv run tools/speclint.py specs/scripts.md --kit <kit>
passes.

approve

Assisted-by: opencode:deepseek-v4.1-flash
opencode added 2 commits November 28, 2026 15:15
Assisted-by: opencode:deepseek-v4.1-flash
Assisted-by: opencode:deepseek-v4.1-flash
@ozgb

ozgb commented Nov 29, 2026

Copy link
Copy Markdown
Owner Author

Spec reviewer: phase 2 (leakage) of 7060e9d0 (the head after the phase-1 answers): approve

Rounds: changes on 91ff9c6 (21 findings), approve on 3d6ba03; then the phase-1 answers
(372bb4b), a changes report on them (8 findings), their answers (53e1c8c), and two wording fixes
(7060e9d: the object's word at offset 0, SetCob's statics growth and its checksum). The final diff
was read beside the source and the kit; speclint.py passes.

approve

Assisted-by: opencode:deepseek-v4.1-flash
@ozgb

ozgb commented Nov 29, 2026

Copy link
Copy Markdown
Owner Author

Spec reviewer: phase 2 (leakage) of 9279e11: approve

The head is the phase-1 answers (same tree as 25358c8, whose diff was approved after the 8-finding report at 372bb4b..53e1c8c). The last changes answer the implementer's questions: the ScriptTable arrays' kinds, the UpdateObjectState view's offsets, TURN's unsigned rotation, unit values 12 and 14 as unsigned 16-bit, the restore rule's parentless pieces, SetCob's order, CreatePlayerObjectState's root, and the effect command's update rule. speclint.py passes.

approve

@ozgb ozgb mentioned this pull request Nov 29, 2026
ozgb added 2 commits November 29, 2026 10:58
Move the kit to interfaces-v89 and reference-traces-v59. List the
imports the entry now has (SimRealloc, RecordSimEvent and
CanPlaceUnitFootprint), say SetCob reallocates through SimRealloc,
let the drop operation call the map, and drop the gaps they closed.
The entry is blocked, so the gate judges recordings only.

Assisted-by: Claude:claude-sonnet-5-5
The kit entry lists services.RandomInt; say that no recording
calls it and the module draws from rng.seed itself.

Assisted-by: Claude:claude-sonnet-5-5
@ozgb

ozgb commented Nov 29, 2026

Copy link
Copy Markdown
Owner Author

Spec reviewer: phase 2 (leakage and correctness) on the re-pin of the scripts spec to kit interfaces-v89 / reference-traces-v59, range 9279e11..aefb925 (two commits), pushed after this review.

  • a12614d (the re-pin): checked beside the source and the recordings: SetCob reallocates pieces (pieceCount * 76) then statics (staticCount * 4) through services.SimRealloc and then zeroes pieces, as orders-air call 1025 shows (SimRealloc null 608, then null 16); the five RecordSimEvent argument counts (9, 8, 8, 4, 4) and flags; the drop operation's map.CanPlaceUnitFootprint arguments. speclint passes. No leakage found. Optional findings, taken: the RandomInt row.
  • aefb925 (one table row: services.RandomInt, listed by the entry, called by no recording): speclint passes, claim checked, no leakage.

approve

ozgb added 2 commits November 30, 2026 00:13
Assisted-by: Claude:claude-sonnet-5-5
Assisted-by: Claude:claude-sonnet-5-5
@ozgb

ozgb commented Nov 30, 2026

Copy link
Copy Markdown
Owner Author

Spec writer: re-pin of the scripts spec to interfaces-v101 / reference-traces-v63 (ozgb/byte-tactics-moddable#1197, after #1333): the services import GetCobChecksum (services 4.6, a pure query) and SetCob's checksum taken from it, data of SetCob and CreatePlayerObjectState as a linear address of the loaded script in load_data (the 44-byte table described from the kit's ABI 7.1), slot kinds in section 2 made equal to the manifest entry (this also fixes CreateObjectState and CreatePlayerObjectState), the checksum formula dropped from section 5 (a module cannot compute it), and the held fix: offset 0 of a new script holds the CobScript class word (class_words index 5). Section 8 drops the two closed kit gaps (the checksum and the block kind).

Phase 2 (leakage and correctness), fresh reviewers with the source, before the push:

  • aefb925..5ba7776: approve (no must-fix; three optional wording items).
  • 5ba7776..e54b8f2 (the three optional items applied): fresh phase 2 approve (no must-fix).

speclint passes against the v101 kit. Pushing e54b8f2 with git-safe push after this comment.

Assisted-by: Claude:claude-sonnet-5-5
@ozgb

ozgb commented Nov 30, 2026

Copy link
Copy Markdown
Owner Author

Spec writer: phase 1 (completeness, in the microVM, session p1, kit interfaces-v101, spec head e54b8f2): changes. A scratch implementation replayed the four recordings (78 calls) with 0 differences after one deviation (the piece offset), and raised questions on the unit of a script, null state or owner, out-of-range operands, the EXPLODE_PIECE and SET_YARD fields, the wait test, a negative health, the publish comparison, and some wording. The proxy log of p1 had 3 requests, all on the allowlist (check-log: pass).

Answers, in 83ab746 (spec only):

  • Piece offset (contradiction 1): the loaded model is mirrored (x and z of each node's box and vertices are the file's negated), so the recording's x lines (file bytes) show the opposite sign of what a module reads from its copy. The rule's text and example 8 now say so and give the numbers. The kit's ABI 7.1 states the mirror for the vertices only, not for the box: to be filed as a kit doc gap.
  • The unit of a script is the owner of its model state; Unit.state and UnitScript.state are typed SpotState and ObjectState in layout.json while the record is the ModelState of the spec.
  • Script faults (null state or owner, out-of-range piece, axis or statics index, stack underflow or overflow, pc outside code) are outside the contract.
  • The effects are published as the script gives them and nothing is checked; SET_YARD's open is the value as set.
  • The wait test reads the script's own Piece record; unit value 4 is signed health times 100 divided as unsigned by maxHealth; the event records are 76 and 16 bytes with offsets counted from the header; Angles16 signedness; the publish comparison is outbox and size; unit values read by the recordings are 4 and 17.
  • Wording: Q1 as behaviour, the pose rule's restore as "a piece is restored when its modified is 0 or its parent was restored" (exact against the source; the old text said the descendants of the root's first child were restored whatever their modified), and the unclosed span of the animation step.

Phase 2 (fresh reviewer with the source) before this push: e54b8f2..83ab746 approve (no must-fix; two optional wording items left for the next revision). Pushing 83ab746 with git-safe push after this comment.

Assisted-by: Claude:claude-sonnet-5-5
@ozgb

ozgb commented Nov 30, 2026

Copy link
Copy Markdown
Owner Author

Spec writer: re-pin of the scripts spec to the newest exporting kit, interfaces-v102 / reference-traces-v64 (the tags #1353 made). For scripts they hold what v101 / v63 hold: a diff of interfaces, wasm/modules.json, the ABI, layout.json, the schema and tests/replay/scripts between the two tags is empty (v102 adds the weapons scenario ai-antinuke-pair). Two wording items from the previous phase 2 are in the same commit: the pose visits the pieces under the root, and the unchecked effect fields have the attach operation's own tests as the exception.

Phase 2 (fresh reviewer with the source) before the push: 83ab746..2aa14ce approve (no must-fix; two optional wording points, left as they are so that the pushed text is the approved one: "under the root" could say "the root and every piece below it", and the exception could name the drop operation's tests too).

Phase 1 (completeness, microVM) was run on e54b8f2, kit v101: changes, answered in 83ab746 (phase 2 approve, comment above). A second phase 1 on this head is not needed for the pin: the delta is one version line and two sentences.

Pushing 2aa14ce with git-safe push after this comment.

Assisted-by: Claude:claude-sonnet-5-5
@ozgb

ozgb commented Nov 30, 2026

Copy link
Copy Markdown
Owner Author

Spec writer: answers to code review round 1 (session r1, base 2aa14ce, head a690493 equal on all four recordings, Findings: 1 bug, 3 risk, 5 nit) that touch the spec, in 9cdacff:

  • review 1 (services.RandomInt called for a range below 2): the spec's import row now says the draw never calls it, a range below 2 included.
  • review 3 (CanPlaceUnitFootprint's def): the spec said "as a block offset" for a block argument; it now says the address (g_blockBase plus the stored offset), as the ABI's block kind requires.
  • review 2 (pose restore order): stated also as "a piece is restored when it or any of its ancestors has modified 0 when the pass begins, whatever order the records come in"; the code's reading is the spec's.
  • review 4 (EXPLODE_PIECE's piece out of range): listed as outside the contract, published or dropped.
    The rest (dead code, notes that lag the code, the replay.js count, the deep model, INIT_STATE with a null model) are the implementer's to fix or answer.

Phase 2 (fresh reviewer with the source) before this push: 2aa14ce..9cdacff approve, no must-fix (optional: the "its own affair" clause of the RandomInt row edges towards build advice; a def of 0; wrap one long line; left as approved).

Assisted-by: Claude:claude-sonnet-5-5
@ozgb

ozgb commented Nov 30, 2026

Copy link
Copy Markdown
Owner Author

Spec writer: answers to code review round 2 (session r2, base a690493, head 38638e7 equal; Findings: 0 bug, 3 risk, 4 nit) that touch the spec, in f762d66: a record with no parent (the root or another top-level piece) takes the unit's angles in the piece offset, while the pose reaches only the root's subtree (a top-level piece that is not the root is not posed); a null model at CreateObjectState, CreatePlayerObjectState and ObjectStateSize, or a feature whose model is null at INIT_STATE, is outside the contract; the effects sentence names the exceptions (the tests of the attach and drop operations, and EXPLODE_PIECE's piece index) so it no longer conflicts with section 4. The notes' staleness, tptr, the null root write and the unexercised slots are the implementer's.

Phase 2 (fresh reviewer with the source) before this push: 9cdacff..f762d66 approve, no must-fix (optional: reword "faults of a script's code" for the null-model cases; left as approved). Pushing f762d66 with git-safe push after this comment.

Assisted-by: Claude:claude-sonnet-5-5
@ozgb

ozgb commented Nov 30, 2026

Copy link
Copy Markdown
Owner Author

Spec writer: answer to code review round 3 (session r3, base 38638e7, head 47e802a equal; Findings: 0 bug, 1 risk, 4 nit) that touches the spec, in 5b1ca63: the unit of an id in the attach operation, the drop operation and unit values 9 to 11 is the entry at that 16-bit index of the unit table (index 0 is no unit), alive by bit 28 of its flags, and Game.poolCount is not tested (the old text said the unit whose id equals the value, which is not how the reference finds it).

Phase 2 (fresh reviewer with the source) before this push: f762d66..5b1ca63 approve, no must-fix (optional: rewrap one line). Pushing 5b1ca63 with git-safe push after this comment.

Assisted-by: Claude:claude-sonnet-5-5
@ozgb

ozgb commented Nov 30, 2026

Copy link
Copy Markdown
Owner Author

Spec writer: re-pin of the scripts spec to interfaces-v103 / reference-traces-v65 (#1356). For scripts nothing changed since v101 / v63: the scripts manifest entry is identical, and interfaces/ (but presentation.h), layout.json, the schema, tests/replay/scripts and the ABI sections the spec cites are unchanged; v103 adds a view region above the load data and a presentation entry. #1365 (the doc of the mirrored box) had not merged when I looked.

Phase 2 (fresh reviewer with the source) before the push: 5b1ca63..a2c2e1d approve, no must-fix. Pushing a2c2e1d with git-safe push after this comment.

@ozgb

ozgb commented Nov 30, 2026

Copy link
Copy Markdown
Owner Author

Lead: hand-over update for the scripts module, after #1360 (fdd1bb079) merged (lead lead).

Verdict on moddable. Run in the #1197 worktree on fdd1bb079cf3c00c6ad27f6386b9e913aa2cb71d (origin/moddable, my local patch dropped, build/rwsets removed, build/modern and the wasm_runtime target rebuilt, build/playtest/prefix removed first), uv run tools/oraclegate.py --subsystem scripts --recordings-only on the module of #75 (30273 bytes, sha256 0c4e7a8f7558...), kit in the verdict interfaces-v103 / reference-traces-v65. The exact result line, run twice (the module of 19ff592, then the module of the head below, byte-identical):

equal on recordings; scenarios not judged; budgets not judged (0 not equal)

Re-pin. v103 / v65 changed nothing for scripts (the scripts manifest entry is identical, interfaces/ but presentation.h, layout.json, the schema, tests/replay/scripts and the ABI sections the spec cites are unchanged; v103 adds a view region and a presentation entry). The spec is re-pinned in btm#68 at a2c2e1d (phase 2 approve on 5b1ca63..a2c2e1d before the push, comment on #68). #1365 (the mirrored box in the ABI doc) had not merged; the spec already states the mirror.

Notes. The two stale lines of scripts/IMPLEMENTATION-NOTES.md (UpdateObjectState, TURN's signedness) and the open-looking question A are fixed by an implementer session in the microVM (s6, check-log: pass, verdict equal on its submission), which merged the spec and changed notes only: btm#75 is at 091af4662fdf, reached through the broker's push (not by me). Review rounds: three, none clean, as in the hand-over above; the findings no recording reaches are on #1361.

Left for the maintainer: merge #68, then #75 (its diff shows the spec until #68 merges); #1365 for the doc of the mirrored box (#1364); #1361 for the vectors.

@ozgb
ozgb merged commit 282d14a into main Nov 30, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant