tjs-lang 0.7.7 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +99 -33
- package/bin/docs.js +4 -1
- package/demo/docs.json +104 -22
- package/demo/src/examples.test.ts +1 -0
- package/demo/src/imports.test.ts +16 -4
- package/demo/src/imports.ts +60 -15
- package/demo/src/playground-shared.ts +9 -8
- package/demo/src/tfs-worker.js +205 -147
- package/demo/src/tjs-playground.ts +34 -10
- package/demo/src/ts-examples.ts +8 -8
- package/demo/src/ts-playground.ts +24 -8
- package/dist/index.js +118 -101
- package/dist/index.js.map +4 -4
- package/dist/src/lang/bool-coercion.d.ts +50 -0
- package/dist/src/lang/docs.d.ts +31 -6
- package/dist/src/lang/linter.d.ts +8 -0
- package/dist/src/lang/parser-transforms.d.ts +18 -0
- package/dist/src/lang/parser-types.d.ts +2 -0
- package/dist/src/lang/parser.d.ts +3 -0
- package/dist/src/lang/runtime.d.ts +34 -0
- package/dist/src/lang/types.d.ts +9 -1
- package/dist/src/rbac/index.d.ts +1 -1
- package/dist/src/vm/runtime.d.ts +1 -1
- package/dist/tjs-eval.js +38 -36
- package/dist/tjs-eval.js.map +4 -4
- package/dist/tjs-from-ts.js +20 -20
- package/dist/tjs-from-ts.js.map +3 -3
- package/dist/tjs-lang.js +85 -83
- package/dist/tjs-lang.js.map +4 -4
- package/dist/tjs-vm.js +47 -45
- package/dist/tjs-vm.js.map +4 -4
- package/llms.txt +79 -0
- package/package.json +9 -4
- package/src/cli/commands/convert.test.ts +16 -21
- package/src/lang/bool-coercion.test.ts +203 -0
- package/src/lang/bool-coercion.ts +314 -0
- package/src/lang/codegen.test.ts +137 -0
- package/src/lang/docs.test.ts +476 -1
- package/src/lang/docs.ts +471 -37
- package/src/lang/emitters/ast.ts +11 -12
- package/src/lang/emitters/dts.test.ts +41 -0
- package/src/lang/emitters/dts.ts +9 -0
- package/src/lang/emitters/js-tests.ts +9 -4
- package/src/lang/emitters/js-wasm.ts +57 -65
- package/src/lang/emitters/js.ts +198 -3
- package/src/lang/features.test.ts +4 -3
- package/src/lang/index.ts +9 -0
- package/src/lang/inference.ts +54 -0
- package/src/lang/linter.test.ts +104 -1
- package/src/lang/linter.ts +124 -1
- package/src/lang/module-loader.test.ts +318 -0
- package/src/lang/module-loader.ts +419 -0
- package/src/lang/parser-params.ts +31 -0
- package/src/lang/parser-transforms.ts +640 -0
- package/src/lang/parser-types.ts +35 -0
- package/src/lang/parser.test.ts +73 -1
- package/src/lang/parser.ts +77 -3
- package/src/lang/runtime.ts +98 -0
- package/src/lang/types.ts +6 -0
- package/src/lang/wasm.test.ts +1293 -2
- package/src/lang/wasm.ts +470 -87
- package/src/linalg/index.tjs +119 -0
- package/src/linalg/linalg.test.ts +294 -0
- package/src/linalg/vector-search.bench.test.ts +395 -0
- package/src/rbac/index.ts +2 -2
- package/src/rbac/rules.tjs.d.ts +9 -0
- package/src/vm/atoms/batteries.ts +2 -2
- package/src/vm/runtime.ts +10 -3
- package/dist/src/rbac/rules.d.ts +0 -184
- package/src/rbac/rules.js +0 -338
package/CLAUDE.md
CHANGED
|
@@ -54,13 +54,7 @@ bun run docs # Generate documentation
|
|
|
54
54
|
# Build standalone CLI binaries
|
|
55
55
|
bun run build:cli # Compiles tjs + tjsx to dist/
|
|
56
56
|
|
|
57
|
-
# Compatibility testing (
|
|
58
|
-
bun scripts/compat-zod.ts # Zod validation library
|
|
59
|
-
bun scripts/compat-effect.ts # Effect (HKTs, intersections)
|
|
60
|
-
bun scripts/compat-radash.ts # Radash utilities
|
|
61
|
-
bun scripts/compat-superstruct.ts # Superstruct validation
|
|
62
|
-
bun scripts/compat-ts-pattern.ts # ts-pattern matching
|
|
63
|
-
bun scripts/compat-kysely.ts # Kysely SQL builder
|
|
57
|
+
# Compatibility testing — see scripts/compat-*.ts (zod, effect, radash, superstruct, ts-pattern, kysely)
|
|
64
58
|
|
|
65
59
|
# Deployment (Firebase)
|
|
66
60
|
bun run deploy # Build demo + deploy functions + hosting
|
|
@@ -99,7 +93,7 @@ bun run functions:serve # Local functions emulator
|
|
|
99
93
|
- `src/batteries/` - LM Studio integration (lazy init, model audit, vector search)
|
|
100
94
|
- `src/store/` - Store implementations for persistence
|
|
101
95
|
- `src/rbac/` - Role-based access control
|
|
102
|
-
- `src/use-cases/` - Integration tests and real-world examples (
|
|
96
|
+
- `src/use-cases/` - Integration tests and real-world examples (30 test files)
|
|
103
97
|
- `src/cli/tjs.ts` - CLI tool for check/run/types/emit/convert/test commands
|
|
104
98
|
- `src/cli/tjsx.ts` - JSX/component runner
|
|
105
99
|
- `src/cli/playground.ts` - Local playground server
|
|
@@ -140,6 +134,10 @@ import { Agent, AgentVM, ajs, tjs } from 'tjs-lang' // Main entry
|
|
|
140
134
|
import { Eval, SafeFunction } from 'tjs-lang/eval' // Safe eval utilities
|
|
141
135
|
import { tjs, transpile } from 'tjs-lang/lang' // Language tools only
|
|
142
136
|
import { fromTS } from 'tjs-lang/lang/from-ts' // TypeScript transpilation
|
|
137
|
+
import { AgentVM } from 'tjs-lang/vm' // VM only (smaller bundle)
|
|
138
|
+
import { batteryAtoms } from 'tjs-lang/batteries' // LM Studio batteries
|
|
139
|
+
import { dot, norm_sq } from 'tjs-lang/linalg' // SIMD linear-algebra kernels
|
|
140
|
+
// Editor integrations: 'tjs-lang/editors/monaco', '/codemirror', '/ace'
|
|
143
141
|
```
|
|
144
142
|
|
|
145
143
|
### Transpiler Chain (TS → TJS → JS)
|
|
@@ -248,7 +246,7 @@ AJS expressions behave differently from JavaScript in several important ways:
|
|
|
248
246
|
- Unit tests alongside source files (`*.test.ts`)
|
|
249
247
|
- Integration tests in `src/use-cases/` (RAG, orchestration, malicious actors)
|
|
250
248
|
- Security tests in `src/use-cases/malicious-actor.test.ts`
|
|
251
|
-
- Language tests split across
|
|
249
|
+
- Language tests split across 17 files in `src/lang/` (lang.test.ts, features.test.ts, codegen.test.ts, parser.test.ts, from-ts.test.ts, wasm.test.ts, etc.)
|
|
252
250
|
|
|
253
251
|
Coverage targets: 98% lines on `src/vm/runtime.ts` (security-critical), 80%+ overall.
|
|
254
252
|
|
|
@@ -401,6 +399,72 @@ The playground is hosted on Firebase (`tjs-platform.web.app`). Demo build output
|
|
|
401
399
|
|
|
402
400
|
The `docs/` directory contains real documentation (markdown), not build artifacts. See `docs/README.md` for the documentation index.
|
|
403
401
|
|
|
402
|
+
### Playground Examples
|
|
403
|
+
|
|
404
|
+
The playground (https://tjs-platform.web.app) shows interactive TJS and AJS examples in a navigable sidebar. Examples live as markdown files with embedded code blocks, NOT as raw `.tjs` files.
|
|
405
|
+
|
|
406
|
+
**Where they live:**
|
|
407
|
+
|
|
408
|
+
- TJS playground examples: `guides/examples/tjs/<slug>.md`
|
|
409
|
+
- AJS playground examples: `guides/examples/ajs/<slug>.md` (assumed parallel structure)
|
|
410
|
+
|
|
411
|
+
**File format:**
|
|
412
|
+
|
|
413
|
+
<!-- prettier-ignore -->
|
|
414
|
+
```markdown
|
|
415
|
+
<!--{"section":"tjs","type":"example","group":"basics","order":16}-->
|
|
416
|
+
|
|
417
|
+
# Example Title
|
|
418
|
+
|
|
419
|
+
Short intro paragraph (plain markdown).
|
|
420
|
+
|
|
421
|
+
```tjs
|
|
422
|
+
/*#
|
|
423
|
+
## Optional H2 — markdown rendered above the code in the playground
|
|
424
|
+
Explain the concept here. Use markdown freely.
|
|
425
|
+
*/
|
|
426
|
+
|
|
427
|
+
// Then the actual TJS code
|
|
428
|
+
function demo() { ... }
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* JSDoc-style /** ... */ blocks are also extracted as docs.
|
|
432
|
+
* Leading ` * ` is stripped from each line; the rest renders as markdown.
|
|
433
|
+
* Use this when porting TS source where JSDoc is already idiomatic.
|
|
434
|
+
*/
|
|
435
|
+
|
|
436
|
+
test 'a description' {
|
|
437
|
+
expect(...).toBe(...)
|
|
438
|
+
}
|
|
439
|
+
```
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
Frontmatter fields: `section` (`tjs`/`ajs`), `type: "example"`, `group` (`basics`/`advanced`/etc.), `order` (numeric, controls sidebar position). The H1 becomes the example title in the nav.
|
|
443
|
+
|
|
444
|
+
**Registration:**
|
|
445
|
+
|
|
446
|
+
Examples are auto-discovered by `bin/docs.js` (run via `bun run docs`), which walks the markdown tree, parses frontmatter, extracts the `tjs`/`ajs` code block, and writes the result to `demo/docs.json`. The demo loads `docs.json` at runtime — no other registration step.
|
|
447
|
+
|
|
448
|
+
**After adding/editing an example:** run `bun run docs` and commit the regenerated `demo/docs.json` alongside the `.md` file. (The docs builder also runs as part of `bun run build:demo` and `bun run deploy`.)
|
|
449
|
+
|
|
450
|
+
**Testing playground examples:**
|
|
451
|
+
|
|
452
|
+
The CLI (`bun src/cli/tjs.ts run`) does NOT inject the test-block `expect` harness — that's a playground-only thing. So running an extracted code block via the CLI prints "expect is not defined" for any `test { expect(...) }` blocks even though they pass in the playground. To verify an example:
|
|
453
|
+
|
|
454
|
+
1. **Console-log behavior** (works via CLI): extract the `tjs` code block and run it.
|
|
455
|
+
|
|
456
|
+
````bash
|
|
457
|
+
awk '/^```tjs$/{flag=1; next} /^```$/{flag=0} flag' \
|
|
458
|
+
guides/examples/tjs/<slug>.md > /tmp/example.tjs
|
|
459
|
+
bun src/cli/tjs.ts run /tmp/example.tjs
|
|
460
|
+
````
|
|
461
|
+
|
|
462
|
+
Verify the printed output matches the expected behavior shown in the example's comments.
|
|
463
|
+
|
|
464
|
+
2. **Test blocks**: spin up the dev server (`bun run start`) and load the example in the playground UI to confirm tests pass under the real `expect` harness.
|
|
465
|
+
|
|
466
|
+
3. **Frontmatter / registration**: after `bun run docs`, grep `demo/docs.json` for the slug to confirm it was picked up with the right `section`/`group`/`order`.
|
|
467
|
+
|
|
404
468
|
### Additional Directories
|
|
405
469
|
|
|
406
470
|
- `tjs-src/` — TJS runtime written in TJS itself (self-hosting)
|
|
@@ -410,6 +474,10 @@ The `docs/` directory contains real documentation (markdown), not build artifact
|
|
|
410
474
|
|
|
411
475
|
### Additional Documentation
|
|
412
476
|
|
|
477
|
+
- `llms.txt` — agent-facing navigation index (ships in npm bundle); points to docs and source entry points
|
|
478
|
+
- `guides/footguns.md` — JS footguns TJS fixes (boxed-primitive truthiness, `==` coercion, `typeof null`, uninitialized `let`, etc.). Demo: `examples/js-footguns-fixed.tjs`.
|
|
479
|
+
- `guides/playground-imports.md` — how the playground/dev-server resolves bare imports: TFS service worker, default JSDelivr `/+esm` routing, esm.sh allowlist for peer-dep packages (React), CDN hints (`jsdelivr/`, `esmsh/`, `unpkg/`, `github/`), and full-URL passthrough.
|
|
480
|
+
- `README.md` — Project intro, install, quick start
|
|
413
481
|
- `DOCS-TJS.md` — TJS language guide
|
|
414
482
|
- `DOCS-AJS.md` — AJS runtime guide
|
|
415
483
|
- `TJS-FOR-JS.md` — TJS guide for JavaScript developers (syntax differences, gotchas)
|
|
@@ -418,39 +486,37 @@ The `docs/` directory contains real documentation (markdown), not build artifact
|
|
|
418
486
|
- `AGENTS.md` — Agent workflow instructions (session-completion checklist, push-before-done rule)
|
|
419
487
|
- `TODO.md` — Open work, organized by area; move items to the **Completed** section when done
|
|
420
488
|
- `PLAN.md` — Roadmap
|
|
489
|
+
- `DOCS-WASM.md` — Canonical WASM reference: inline blocks, `wasm function` declarations, memory model, cross-file composition, `tjs-lang/linalg`, current limitations
|
|
490
|
+
- `wasm-library-plan.md` — Cross-file WASM library design (composable `wasm function` declarations, transpile-time module composition, linalg stdlib). Phases 0–5 complete; see plan for current status.
|
|
491
|
+
- `MANIFESTO-BUILDER.md` / `MANIFESTO-ENTERPRISE.md` — Positioning docs (audience-targeted pitches)
|
|
492
|
+
- `benchmarks.md` — Top-level benchmark results (separate from `guides/benchmarks.md`)
|
|
421
493
|
|
|
422
|
-
###
|
|
494
|
+
### Keeping This File and `llms.txt` Current
|
|
423
495
|
|
|
424
|
-
|
|
496
|
+
Update both files when you change something an agent needs to discover:
|
|
425
497
|
|
|
426
|
-
|
|
498
|
+
- **New top-level markdown doc** → add to "Additional Documentation" here AND to the appropriate section of `llms.txt`.
|
|
499
|
+
- **New package entry point** (subpath export in `package.json`) → add to "Package Entry Points" here AND to "Package entry points" in `llms.txt`.
|
|
500
|
+
- **New CLI command or `bun run` script** → add to "Common Commands".
|
|
501
|
+
- **Renamed or moved key source file** → update "Key Source Files" here AND "Source map" in `llms.txt`.
|
|
502
|
+
- **New language mode / safety directive** → add to the TJS Syntax Reference section.
|
|
503
|
+
- **New playground example** → add to `guides/examples/{tjs,ajs}/<slug>.md`, then `bun run docs` to regenerate `demo/docs.json`. See "Playground Examples" above.
|
|
427
504
|
|
|
428
|
-
|
|
505
|
+
Skip stale-prone precision (exact line counts, file sizes) for new entries — they drift silently. The existing `~3024` etc. are kept current opportunistically, not on every commit.
|
|
429
506
|
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
4. **Push to remote** — mandatory:
|
|
434
|
-
```bash
|
|
435
|
-
git pull --rebase
|
|
436
|
-
git push
|
|
437
|
-
git status # MUST show "up to date with 'origin/...'"
|
|
438
|
-
```
|
|
439
|
-
5. **Clean up** — clear stale stashes, prune merged remote branches if appropriate.
|
|
440
|
-
6. **Verify** — working tree clean AND branch up to date with origin.
|
|
441
|
-
7. **Hand off** — leave a brief summary so the next session can pick up cold.
|
|
507
|
+
### Tracking Work
|
|
508
|
+
|
|
509
|
+
Work is tracked in plain markdown — no external issue tracker. Open items live in `TODO.md` (organized by area). When you start a task, find or add the relevant entry; when you finish, check the box and (for substantial work) move it to the Completed section with a short note.
|
|
442
510
|
|
|
443
|
-
|
|
511
|
+
### Landing the Plane (Session Completion Checklist)
|
|
444
512
|
|
|
445
|
-
-
|
|
446
|
-
- Never stop before pushing — leaving work stranded locally is leaving it lost.
|
|
447
|
-
- Never say "ready to push when you are" — push it yourself.
|
|
448
|
-
- If push fails, resolve the cause (rebase conflicts, hook failures, auth) and retry until it succeeds.
|
|
449
|
-
- Never `--no-verify` to bypass hooks. Fix the underlying issue.
|
|
513
|
+
See `AGENTS.md` for the canonical session-completion checklist. Hard rule: work is not complete until `git push` succeeds — never stop before pushing, never `--no-verify` to bypass hooks.
|
|
450
514
|
|
|
451
|
-
###
|
|
515
|
+
### Common Gotchas
|
|
452
516
|
|
|
453
|
-
|
|
517
|
+
- **`tjs(source)` returns an object, not a string.** It returns `{ code, types, metadata, testResults, ... }` — use `.code` for the transpiled JS string.
|
|
518
|
+
- **Prettier mangles bare-expression code blocks in markdown.** Code blocks tagged ` ```js` get reformatted; bare expressions like `'5' == 5` and `[1] == 1` on consecutive lines collapse into one expression with ASI guards. Use `<!-- prettier-ignore -->` directly above the code fence to preserve hand-formatted JS examples (or tag the block as `text`/`tjs`/`ts` instead — Prettier ignores those).
|
|
519
|
+
- **`tjs-lang` package alias only works inside the project** (set in `bunfig.toml`). Test scripts written in `/tmp` won't resolve `import { tjs } from 'tjs-lang/lang'` to the local source — they'll resolve to whatever's in `node_modules`. For ad-hoc experiments outside the repo, use absolute paths: `import { tjs } from '/Users/.../tjs-lang/src/lang/index'`.
|
|
454
520
|
|
|
455
521
|
### Running Emitted TJS Code
|
|
456
522
|
|
package/bin/docs.js
CHANGED
|
@@ -54,7 +54,10 @@ function extractDescription(content) {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
function metadata(content, filePath) {
|
|
57
|
-
|
|
57
|
+
// Only the FIRST non-blank line may be frontmatter. Matching anywhere in
|
|
58
|
+
// the file produces false positives when docs document the format itself
|
|
59
|
+
// (e.g. CLAUDE.md showing an example of <!--{...}--> ).
|
|
60
|
+
let source = content.match(/^\s*(?:<\!\-\-(\{.*\})\-\->|\/\*(\{.*\})\*\/)/)
|
|
58
61
|
let data = {}
|
|
59
62
|
if (source) {
|
|
60
63
|
try {
|