|
| 1 | +# TechScript Repository Audit (2026-03-17) |
| 2 | + |
| 3 | +This document is a **ground-truth audit** of the current TechScript repository implementation vs the promised behavior in docs/examples. It is intended to drive the stabilization/refactor work. |
| 4 | + |
| 5 | +## Architecture snapshot |
| 6 | + |
| 7 | +- **Workspace**: Rust workspace with `techscript-core`, `techscript-cli`, `techscript-lsp`. |
| 8 | + - `Cargo.toml` |
| 9 | + - `crates/techscript-core/Cargo.toml` |
| 10 | + - `crates/techscript-cli/Cargo.toml` |
| 11 | + - `crates/techscript-lsp/Cargo.toml` |
| 12 | +- **Pipeline**: `Lexer` → `Parser` → `Compiler` (bytecode) → `VM`. |
| 13 | + - `crates/techscript-core/src/lexer.rs` |
| 14 | + - `crates/techscript-core/src/parser.rs` |
| 15 | + - `crates/techscript-core/src/compiler.rs` |
| 16 | + - `crates/techscript-core/src/vm.rs` |
| 17 | + |
| 18 | +## Feature × status matrix |
| 19 | + |
| 20 | +Legend: **OK** (implemented and used), **PARTIAL** (implemented but incomplete/buggy), **DRIFT** (docs/examples disagree), **MISSING** (promised but absent). |
| 21 | + |
| 22 | +### Language core (syntax / semantics) |
| 23 | + |
| 24 | +- **Lexing**: **OK** |
| 25 | + - Supports numbers (incl `0x`/`0b`/`0o`), strings (single/double/triple), raw strings, f-strings token (`TokenType::FString`). |
| 26 | + - `crates/techscript-core/src/lexer.rs` |
| 27 | +- **Parsing**: **OK** (broad coverage), **DRIFT** (some keywords) |
| 28 | + - Statements: `say/make/keep/use/take/share/when/or when/else/each/repeat/until/build/model/attempt/rescue|catch/always/match/case/guard/with/defer/drop/stop/skip/pass/send/fail` |
| 29 | + - `crates/techscript-core/src/parser.rs` |
| 30 | +- **Formatting**: **PARTIAL / BUG** |
| 31 | + - Formatter prints `when ... } alt ... {` but parser/docs use `} or when ... {`. |
| 32 | + - `crates/techscript-core/src/formatter.rs` vs `crates/techscript-core/src/parser.rs` |
| 33 | +- **Compilation**: **OK** for implemented AST surface, **NOTE** |
| 34 | + - Compiler does **not** emit `OpCode::Invoke`; it emits `GetProperty` + `Call` for method-style calls. |
| 35 | + - `crates/techscript-core/src/compiler.rs`, `crates/techscript-core/src/opcode.rs` |
| 36 | +- **VM execution**: **PARTIAL** |
| 37 | + - `OpCode::Invoke` exists in opcode set but is unimplemented in VM (`/* TODO */`); currently **likely unused** by the compiler. |
| 38 | + - String method binding appears incorrect (`make_native_str` ignores receiver). |
| 39 | + - `crates/techscript-core/src/vm.rs` |
| 40 | +- **Error reporting**: **OK baseline**, can improve |
| 41 | + - Central error types + formatting used by CLI. |
| 42 | + - `crates/techscript-core/src/error.rs` |
| 43 | +- **Async/task**: **PARTIAL** |
| 44 | + - `spawn` queues tasks, `await` is a no-op; event loop runs tasks by calling them. |
| 45 | + - `crates/techscript-core/src/vm.rs` |
| 46 | + |
| 47 | +### Builtins (globals) |
| 48 | + |
| 49 | +- **I/O**: **OK** (`say/print/write`, plus `log/warn/error/debug/clear`) |
| 50 | + - `crates/techscript-core/src/builtins.rs` |
| 51 | +- **Core**: **OK** (`assert/sleep/time/time_ms/exit/callable`) |
| 52 | + - `crates/techscript-core/src/builtins.rs` |
| 53 | +- **String & list helpers**: **OK as globals**, **DRIFT as methods** |
| 54 | + - `split/join/replace/replace_all/contains/...` exist as **global functions**. |
| 55 | + - Docs claim these as **string methods** (e.g. `"hello".split()`), but VM only exposes a small set of string properties/methods and method-binding is buggy. |
| 56 | + - `crates/techscript-core/src/builtins.rs`, `crates/techscript-core/src/vm.rs`, `docs/REFERENCE.md` |
| 57 | +- **List methods**: **PARTIAL** |
| 58 | + - VM list property supports `append/remove/reverse` (and mentions `sort` but does not implement it). |
| 59 | + - Docs claim `map/filter/sort/reverse`. |
| 60 | + - `crates/techscript-core/src/vm.rs`, `docs/REFERENCE.md` |
| 61 | + |
| 62 | +### Standard library modules (`use ...`) |
| 63 | + |
| 64 | +Builtin module resolution list includes: `math/fs/os/random/json/crypto/date/api/web/gui/three_d/anime/debug` (plus `net` in stdlib). |
| 65 | + - `crates/techscript-core/src/module_resolver.rs` |
| 66 | + |
| 67 | +- **math**: **OK** |
| 68 | + - `crates/techscript-core/src/stdlib/math.rs` |
| 69 | +- **fs**: **OK** |
| 70 | + - `crates/techscript-core/src/stdlib/fs.rs` |
| 71 | +- **os**: **OK** (but includes shell execution) |
| 72 | + - `crates/techscript-core/src/stdlib/os.rs` |
| 73 | +- **random**: **OK** (LCG-ish, not cryptographic) |
| 74 | + - `crates/techscript-core/src/stdlib/random.rs` |
| 75 | +- **json**: **OK** (custom JSON codec; limited types) |
| 76 | + - `crates/techscript-core/src/stdlib/json.rs` |
| 77 | +- **crypto**: **PARTIAL / SECURITY NOTE** |
| 78 | + - `sha256` and base64 are implemented; `md5` is a non-MD5 FNV-like hash despite the name. |
| 79 | + - `crates/techscript-core/src/stdlib/crypto.rs` |
| 80 | +- **date**: **OK** |
| 81 | + - `crates/techscript-core/src/stdlib/date.rs` |
| 82 | +- **debug**: **OK** |
| 83 | + - `crates/techscript-core/src/stdlib/debug.rs` |
| 84 | +- **net**: **PARTIAL / NON-PORTABLE** |
| 85 | + - Uses `curl` via shell-out for GET/POST. |
| 86 | + - `crates/techscript-core/src/stdlib/net.rs` |
| 87 | +- **web/gui/three_d/anime**: **OK baseline (browser-based hybrid)**, needs hardening |
| 88 | + - Generates HTML/JS and serves via a blocking localhost TCP server, auto-opens browser/app mode. |
| 89 | + - Implemented under `crates/techscript-core/src/stdlib/web.rs` (`web`, `gui`, `scene`, `anime` namespaces). |
| 90 | +- **api**: **MISSING** |
| 91 | + - Docs + examples reference `use api` + `api.listen(3000)` but there is no stdlib `api` module registration and VM import handler does not include `api`. |
| 92 | + - `docs/REFERENCE.md`, `examples/api_server.txs`, `crates/techscript-core/src/vm.rs`, `crates/techscript-core/src/stdlib/mod.rs` |
| 93 | + |
| 94 | +### CLI tooling |
| 95 | + |
| 96 | +- **Commands**: **OK baseline** |
| 97 | + - `run/build/check/fmt/lint/repl/test/init/doc/install/doctor` |
| 98 | + - `crates/techscript-cli/src/main.rs` |
| 99 | +- **Native build**: **PARTIAL** |
| 100 | + - `tech build --native` generates a temporary Cargo project and compiles a runner embedding bytecode. |
| 101 | + - `crates/techscript-cli/src/main.rs` |
| 102 | +- **Test runner**: **PARTIAL** |
| 103 | + - Executes `.txs` files but does not verify outputs beyond “no runtime error”. |
| 104 | + - `crates/techscript-cli/src/main.rs` |
| 105 | +- **Package install**: **OK baseline** |
| 106 | + - Clones git repos into `.techscript-modules/` and updates `tech.toml`. |
| 107 | + - `crates/techscript-cli/src/pkg.rs` |
| 108 | + |
| 109 | +### LSP |
| 110 | + |
| 111 | +- **Diagnostics**: **OK baseline** |
| 112 | + - Lex/parse/compile to produce diagnostics. |
| 113 | + - `crates/techscript-lsp/src/main.rs` |
| 114 | +- **Completions**: **DRIFT** |
| 115 | + - Includes keywords like `alt` even though parser uses `or when` form; also includes builtins that don’t exist as list methods. |
| 116 | + - `crates/techscript-lsp/src/main.rs` |
| 117 | + |
| 118 | +## High-impact mismatches (action list) |
| 119 | + |
| 120 | +1. **Implement `api` module** to make `examples/api_server.txs` and `docs/REFERENCE.md` real. |
| 121 | +2. **Fix formatter** to emit syntax the parser accepts (`or when`, and `take ... in` vs `take ... from` drift if needed). |
| 122 | +3. **Fix receiver-based methods** (strings/lists) or adjust docs to match “globals-only” API. For compatibility, methods are preferred. |
| 123 | +4. **Remove `curl` dependency** in `net` (replace with Rust HTTP client implementation) to support Windows and “zero external deps”. |
| 124 | +5. **Add headless / no-auto-open modes** for `web/gui/three_d/anime` to enable automated testing. |
| 125 | + |
0 commit comments