Add capsules/sdk.4th: SDK v1.9.0 vocabulary + FENCE over the cookbook capsules

Loads turtle.4th and doe.4th, defines SDK-VERSION/SDK-HELP into an SDK
vocabulary, then calls FENCE once everything is loaded -- protecting the
base wordset and both cookbook capsules from FORGET. Kernel-only (EXEC
doesn't exist hosted), REPL-invoked via S" sdk.4th" EXEC, not part of
init.4th's boot sequence.

Verified before writing the capsule, not assumed: VOCABULARY/DEFINITIONS
does not actually scope word visibility in this interpreter -- vm_find_word
is a flat dictionary scan that never consults CONTEXT/CURRENT. Documented
plainly in the HOWTO so this isn't mistaken for namespace isolation later.

Block range 5109-5115 -- discovered along the way that user-block space is
capped at [2048, 5120) by mkcapsule, tighter than expected.

Verified: mkcapsule --lint clean, hosted-build trace runs SDK-HELP with
zero attributable VM errors, zero build warnings and identical 1012/0/0
POST results with matching dict_hash on all three kernel architectures.

HOWTO: docs/working/architecture/SDK-HOWTO-20260819.md

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Robert Allan James
2026-08-19 06:10:51 -04:00
co-authored by Claude Sonnet 5
parent 4e7dcdf889
commit d1547ecdae
10 changed files with 114512 additions and 21020 deletions
+33
View File
@@ -1802,3 +1802,36 @@ matching the new test count exactly), 0 failed, 0 errors; three-arch kernel boot
(1012/0/0 on amd64/aarch64/riscv64), `dict_hash` matches exactly across all three (changed from
the pre-`FENCE` baseline as expected — a new C word legitimately changes the dictionary hash;
cross-arch agreement is what's being checked, not stability against the prior baseline).
**`capsules/sdk.4th` written — the SDK capsule itself, done.** Block range `5109``5115` (clear
of `turtle.4th`'s `5100``5108`; discovered along the way that user-block space is actually
capped at `[2048, 5120)` by `mkcapsule`, tighter than the `4000+`/"5000s in practice" impression
from earlier sessions — `turtle.4th` at `5100``5108` and `sdk.4th` at `5109``5115` together
leave only 4 blocks of headroom before the hard ceiling). Loads `turtle.4th` and `doe.4th` via
`EXEC` (confirming the kernel-only decision was necessary, not just cautious), defines `SDK-
VERSION`/`SDK-HELP` into an `SDK` vocabulary, restores `FORTH DEFINITIONS`, then calls the new
`FENCE` — protecting the base wordset, both cookbook capsules, and its own two words in one
call. Verified before writing a line of the capsule, not assumed: whether `VOCABULARY`/
`DEFINITIONS` actually scope word visibility in this interpreter. It does not — `vm_find_word`
(the interpreter's primary dispatch) is a flat, first-character-bucketed scan that never
consults `CONTEXT`/`CURRENT`; a word defined under a custom vocabulary remained globally
callable immediately after switching back to `FORTH DEFINITIONS`, confirmed by direct hosted
test before committing to the capsule's design. Documented plainly in the HOWTO so nobody
later assumes `SDK DEFINITIONS` provides isolation it doesn't.
Verified: `mkcapsule --lint` clean; hosted-build trace (`fabric.4th` core + `turtle.4th` +
`doe.4th` + `sdk.4th`'s own blocks, its two `EXEC` lines stripped and the target capsules
concatenated directly instead, since `EXEC` doesn't exist hosted) runs `SDK-HELP` correctly
with zero VM errors attributable to any of this content; zero build warnings and identical
`1012 passed / 0 failed / 0 errors` boot on all three kernel architectures, `dict_hash`
unchanged from the pre-`sdk.4th` baseline on all three (expected — not autoloaded, so it cannot
affect boot-time dictionary content). HOWTO: `docs/working/architecture/SDK-HOWTO-20260819.md`.
Not yet driven interactively through a live REPL, same DoE-before-REPL practical limit as
`turtle.4th`'s own still-open item.
This closes the mechanism + capsule work for SDK v1.9.0 scoping. Still open, not decided here:
the `1.5.4``1.9.0` version-string bump itself, and whether to verify `turtle.4th`'s actual
rendering before treating either it or this SDK as release-ready — both are release-process
decisions, not implementation work, and belong to the user's call per the same pattern used
throughout this scoping (`AskUserQuestion` for the calls that are genuinely the user's, not
inferred).
+10 -2
View File
@@ -1,5 +1,5 @@
# Capsule Block Manifest — Auto-generated
<!-- Generated by mkcapsule --manifest 2026-08-19T09:54:15Z -->
<!-- Generated by mkcapsule --manifest 2026-08-19T10:07:24Z -->
<!-- DO NOT EDIT — re-run mkcapsule --manifest to refresh. -->
<!-- Hand-written justifications and immutability notes live -->
<!-- in MANIFEST.md alongside this auto-generated index. -->
@@ -35,6 +35,7 @@
| `init.4th` | 2049, 2050, 2057 | `0x214d424abd382707` |
| `lib.4th` | 4050 | `0x20625ebf1276c239` |
| `process.4th` | 4300, 4301 | `0x781afc1dbd0294f7` |
| `sdk.4th` | 5109, 5110, 5111, 5112, 5113, 5114, 5115 | `0x008fdbbb62c94a3a` |
| `turtle.4th` | 5100, 5101, 5102, 5103, 5104, 5105, 5106, 5107, 5108 | `0x4d470418ca543365` |
| `user-font-demo.4th` | 4200, 4201, 4202 | `0xce1fd7d1b581a56d` |
| `zuse.4th` | 4016, 4017, 4018 | `0x12f38ec782434a77` |
@@ -335,10 +336,17 @@
| 5106 | `turtle.4th` | `0x4d470418ca543365` | ok |
| 5107 | `turtle.4th` | `0x4d470418ca543365` | ok |
| 5108 | `turtle.4th` | `0x4d470418ca543365` | ok |
| 5109 | `sdk.4th` | `0x008fdbbb62c94a3a` | ok |
| 5110 | `sdk.4th` | `0x008fdbbb62c94a3a` | ok |
| 5111 | `sdk.4th` | `0x008fdbbb62c94a3a` | ok |
| 5112 | `sdk.4th` | `0x008fdbbb62c94a3a` | ok |
| 5113 | `sdk.4th` | `0x008fdbbb62c94a3a` | ok |
| 5114 | `sdk.4th` | `0x008fdbbb62c94a3a` | ok |
| 5115 | `sdk.4th` | `0x008fdbbb62c94a3a` | ok |
## Conflicts
None.
---
*30 capsule(s) scanned. Re-run `mkcapsule --manifest <dir>` to refresh.*
*31 capsule(s) scanned. Re-run `mkcapsule --manifest <dir>` to refresh.*
+60
View File
@@ -0,0 +1,60 @@
Block 5109
( sdk.4th -- SDK v1.9.0 scoping. Loads the cookbook )
( capsules (turtle.4th, doe.4th), a discoverable SDK )
( vocabulary entry point, and raises FENCE once )
( everything is loaded, so a developer at the REPL can )
( FORGET their own scratch work afterward without )
( disturbing any of this. Kernel-only (EXEC is kernel- )
( only); REPL-invoked -- S" sdk.4th" EXEC -- not part of )
( init.4th's boot sequence, matching turtle.4th's own )
( choice. NOTE: VOCABULARY/DEFINITIONS here is )
( organizational, not isolating -- this VM's word lookup )
( is a flat dictionary scan, so SDK words remain )
( globally callable like any other word, both before and )
( after this capsule loads. Verified directly on the )
( hosted build before writing this file. )
VOCABULARY SDK
Block 5110
( Load the cookbook capsules this SDK re-exports. )
S" turtle.4th" EXEC
S" doe.4th" EXEC
Block 5111
( SDK's own words, defined into the SDK vocabulary for )
( introspection -- see the note above, they are just as )
( callable from FORTH context as anywhere else. )
SDK DEFINITIONS
: SDK-VERSION ( -- )
." SDK v1.9.0 (scoping)" CR ;
Block 5112
: SDK-HELP ( -- )
." SDK vocabulary: turtle.4th + doe.4th + FENCE." CR
." Turtle graphics (docs/working/architecture/" CR
." TURTLE-GRAPHICS-HOWTO-20260819.md):" CR
." HOME CS FORWARD BACK LEFT RIGHT PENUP PENDOWN" CR
." SETCOLOR SETXY SETHEADING POLYGON STAR TURTLE-DEMO" CR
Block 5113
." DoE library (docs/working/architecture/" CR
." DOE-LIBRARY-HOWTO-20260819.md):" CR
." DOE ( -- ) or seed n-reps EXEC-DOE" CR
." SDK-VERSION prints the release tag." CR ;
Block 5114
( Back to FORTH context -- CURRENT no longer targets )
( SDK, so anything typed at the REPL after this loads )
( defines normally. )
FORTH DEFINITIONS
Block 5115
( Raise FENCE now that the base wordset, turtle.4th, )
( doe.4th, and this file's own words are all loaded -- )
( a developer can FORGET their own later scratch )
( definitions without being able to reach back )
( through any of this. )
FENCE
SDK-VERSION
." Loaded. Run SDK-HELP for the word list." CR
BIN
View File
Binary file not shown.
@@ -0,0 +1,95 @@
<!-- Living draft (docs/working/ tier). Source for a future docs/formal/cookbook
scrap once reviewed -- see docs/formal/CLAUDE.md's Scraps System. Not yet
promoted; do not cite. -->
# SDK HOWTO — `capsules/sdk.4th`
**Status:** WORKING. Part of the v1.9.0 scoping work (FABRIC-2.md section K).
Loads the two cookbook capsules (turtle graphics, DoE library) and adds an
`SDK` vocabulary entry point plus `FENCE` protection on top of them.
## Loading it
Kernel-only (it loads other capsules via `EXEC`, which does not exist in
the hosted build), REPL-invoked — not part of `init.4th`'s boot sequence,
matching `turtle.4th`'s own choice:
```forth
S" sdk.4th" EXEC
```
This loads `turtle.4th` and `doe.4th`, defines an `SDK` vocabulary with two
introspection words (`SDK-VERSION`, `SDK-HELP`), then calls `FENCE` to
protect everything loaded so far — the base wordset, both cookbook
capsules, and `sdk.4th`'s own words — from `FORGET`. Prints a one-line
confirmation and hint on load; run `SDK-HELP` for the full word list.
## What `VOCABULARY` actually does here — read before assuming isolation
`sdk.4th` defines its own words (`SDK-VERSION`, `SDK-HELP`) into a named
`SDK` vocabulary via `SDK DEFINITIONS`. This is **organizational, not
isolating**: this VM's primary word lookup (`vm_find_word`, used by the
ordinary interpreter loop) is a flat, first-character-bucketed scan of the
whole dictionary — it does not consult `CONTEXT`/`CURRENT` at all. Verified
directly before writing this file: a word defined while `CURRENT` targeted
a custom vocabulary remained globally callable immediately after switching
back to `FORTH DEFINITIONS`, exactly as if no vocabulary had been involved.
The `VOCABULARY`/`DEFINITIONS`/`CONTEXT`/`ORDER`/`(FIND)` machinery is real,
standard FORTH-79, and useful for anything that explicitly walks vocabulary
chains (`(FIND)`, `ORDER`) — it just isn't what makes SDK words reachable
day to day. Don't build anything on the assumption that loading a second
vocabulary hides or scopes its words from the rest of the system.
## FENCE — and the bug it surfaced
`FENCE ( -- )` is new (this scoping pass) — it raises the dictionary's
`FORGET` boundary to whatever is currently the newest word, so anything
defined afterward can be safely `FORGET`ten without reaching back into
protected territory. `sdk.4th` calls it once, at the very end of loading.
Building a direct test for `FENCE` surfaced a real, severe, pre-existing
bug in `FORGET` itself — completely independent of `FENCE`, reproducible
with the *original* boot-time fence alone. Forgetting the single newest
word wrongly destroyed every other word back to the fence too; forgetting
an older word (which correctly cascades to remove newer words, per
FORTH-79 semantics) crashed with a SIGSEGV — a use-after-free in the
dictionary relink logic. Found and fixed as part of this work; full
root-cause writeup in FABRIC-2.md section K. Three POST cases were added to
`dictionary_manipulation_words_test.c` (Module 14) alongside `FORGET`'s
own, including the exact regression scenario, so it can't silently return.
## Vocabulary
| Word | Effect |
|------|--------|
| `SDK-VERSION` | Prints the release tag (`SDK v1.9.0 (scoping)`). |
| `SDK-HELP` | Prints the full word list for both cookbook capsules, with HOWTO pointers. |
| `FENCE` | (Not SDK-specific — a base word, used by this capsule.) Raises the `FORGET` boundary to the current dictionary top. |
Everything from `turtle.4th` and `doe.4th` is also available after loading
— see their own HOWTOs (`TURTLE-GRAPHICS-HOWTO-20260819.md`,
`DOE-LIBRARY-HOWTO-20260819.md`) for their vocabularies.
## Verification performed
- `mkcapsule --lint capsules/` clean (block range `5109``5115`, clear of
`turtle.4th`'s `5100``5108`).
- Hosted-build logic trace: `fabric.4th`'s core blocks + `turtle.4th` +
`doe.4th` + `sdk.4th`'s own blocks (with its two `EXEC` lines stripped,
since `EXEC` doesn't exist hosted — the capsules they'd load were
concatenated directly instead) piped into the hosted binary. `SDK-HELP`
runs and prints correctly; zero VM errors from any of this content
(all errors present in the log are the built-in POST suite's own
deliberate error-injection cases, confirmed by cross-checking against
the same baseline used for the cookbook capsules' own verification).
- Built cleanly (zero warnings) and baked into the capsule set on all
three kernel architectures (amd64/aarch64/riscv64); boot verified clean
through POST on all three, `1012 passed / 0 failed / 0 errors`
identically, `dict_hash` unchanged from the pre-`sdk.4th` baseline on
all three (expected — `sdk.4th` isn't autoloaded, so it cannot affect
boot-time dictionary content).
- Not yet driven interactively through a live REPL — same practical
limitation as `turtle.4th`'s own HOWTO documents (the DoE campaign that
auto-runs on every kernel boot blocks the REPL for ~2530 minutes before
serial commands can reach it). The FORTH logic is verified; the
interactive load-and-run experience is not.
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff