tjs-lang 0.7.7 → 0.7.8
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 +90 -33
- package/bin/docs.js +4 -1
- package/demo/docs.json +45 -11
- 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-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 +3 -2
- 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 +328 -1
- package/src/lang/docs.ts +424 -24
- 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.ts +182 -2
- 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/parser-params.ts +31 -0
- package/src/lang/parser-transforms.ts +304 -0
- package/src/lang/parser-types.ts +2 -0
- package/src/lang/parser.test.ts +73 -1
- package/src/lang/parser.ts +34 -1
- package/src/lang/runtime.ts +98 -0
- package/src/lang/types.ts +6 -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,9 @@ 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
|
+
// Editor integrations: 'tjs-lang/editors/monaco', '/codemirror', '/ace'
|
|
143
140
|
```
|
|
144
141
|
|
|
145
142
|
### Transpiler Chain (TS → TJS → JS)
|
|
@@ -248,7 +245,7 @@ AJS expressions behave differently from JavaScript in several important ways:
|
|
|
248
245
|
- Unit tests alongside source files (`*.test.ts`)
|
|
249
246
|
- Integration tests in `src/use-cases/` (RAG, orchestration, malicious actors)
|
|
250
247
|
- Security tests in `src/use-cases/malicious-actor.test.ts`
|
|
251
|
-
- Language tests split across
|
|
248
|
+
- 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
249
|
|
|
253
250
|
Coverage targets: 98% lines on `src/vm/runtime.ts` (security-critical), 80%+ overall.
|
|
254
251
|
|
|
@@ -401,6 +398,66 @@ The playground is hosted on Firebase (`tjs-platform.web.app`). Demo build output
|
|
|
401
398
|
|
|
402
399
|
The `docs/` directory contains real documentation (markdown), not build artifacts. See `docs/README.md` for the documentation index.
|
|
403
400
|
|
|
401
|
+
### Playground Examples
|
|
402
|
+
|
|
403
|
+
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.
|
|
404
|
+
|
|
405
|
+
**Where they live:**
|
|
406
|
+
|
|
407
|
+
- TJS playground examples: `guides/examples/tjs/<slug>.md`
|
|
408
|
+
- AJS playground examples: `guides/examples/ajs/<slug>.md` (assumed parallel structure)
|
|
409
|
+
|
|
410
|
+
**File format:**
|
|
411
|
+
|
|
412
|
+
<!-- prettier-ignore -->
|
|
413
|
+
```markdown
|
|
414
|
+
<!--{"section":"tjs","type":"example","group":"basics","order":16}-->
|
|
415
|
+
|
|
416
|
+
# Example Title
|
|
417
|
+
|
|
418
|
+
Short intro paragraph (plain markdown).
|
|
419
|
+
|
|
420
|
+
```tjs
|
|
421
|
+
/*#
|
|
422
|
+
## Optional H2 — markdown rendered above the code in the playground
|
|
423
|
+
Explain the concept here. Use markdown freely.
|
|
424
|
+
*/
|
|
425
|
+
|
|
426
|
+
// Then the actual TJS code
|
|
427
|
+
function demo() { ... }
|
|
428
|
+
|
|
429
|
+
test 'a description' {
|
|
430
|
+
expect(...).toBe(...)
|
|
431
|
+
}
|
|
432
|
+
```
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
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.
|
|
436
|
+
|
|
437
|
+
**Registration:**
|
|
438
|
+
|
|
439
|
+
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.
|
|
440
|
+
|
|
441
|
+
**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`.)
|
|
442
|
+
|
|
443
|
+
**Testing playground examples:**
|
|
444
|
+
|
|
445
|
+
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:
|
|
446
|
+
|
|
447
|
+
1. **Console-log behavior** (works via CLI): extract the `tjs` code block and run it.
|
|
448
|
+
|
|
449
|
+
````bash
|
|
450
|
+
awk '/^```tjs$/{flag=1; next} /^```$/{flag=0} flag' \
|
|
451
|
+
guides/examples/tjs/<slug>.md > /tmp/example.tjs
|
|
452
|
+
bun src/cli/tjs.ts run /tmp/example.tjs
|
|
453
|
+
````
|
|
454
|
+
|
|
455
|
+
Verify the printed output matches the expected behavior shown in the example's comments.
|
|
456
|
+
|
|
457
|
+
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.
|
|
458
|
+
|
|
459
|
+
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`.
|
|
460
|
+
|
|
404
461
|
### Additional Directories
|
|
405
462
|
|
|
406
463
|
- `tjs-src/` — TJS runtime written in TJS itself (self-hosting)
|
|
@@ -410,6 +467,10 @@ The `docs/` directory contains real documentation (markdown), not build artifact
|
|
|
410
467
|
|
|
411
468
|
### Additional Documentation
|
|
412
469
|
|
|
470
|
+
- `llms.txt` — agent-facing navigation index (ships in npm bundle); points to docs and source entry points
|
|
471
|
+
- `guides/footguns.md` — JS footguns TJS fixes (boxed-primitive truthiness, `==` coercion, `typeof null`, uninitialized `let`, etc.). Demo: `examples/js-footguns-fixed.tjs`.
|
|
472
|
+
- `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.
|
|
473
|
+
- `README.md` — Project intro, install, quick start
|
|
413
474
|
- `DOCS-TJS.md` — TJS language guide
|
|
414
475
|
- `DOCS-AJS.md` — AJS runtime guide
|
|
415
476
|
- `TJS-FOR-JS.md` — TJS guide for JavaScript developers (syntax differences, gotchas)
|
|
@@ -418,39 +479,35 @@ The `docs/` directory contains real documentation (markdown), not build artifact
|
|
|
418
479
|
- `AGENTS.md` — Agent workflow instructions (session-completion checklist, push-before-done rule)
|
|
419
480
|
- `TODO.md` — Open work, organized by area; move items to the **Completed** section when done
|
|
420
481
|
- `PLAN.md` — Roadmap
|
|
482
|
+
- `MANIFESTO-BUILDER.md` / `MANIFESTO-ENTERPRISE.md` — Positioning docs (audience-targeted pitches)
|
|
483
|
+
- `benchmarks.md` — Top-level benchmark results (separate from `guides/benchmarks.md`)
|
|
421
484
|
|
|
422
|
-
###
|
|
485
|
+
### Keeping This File and `llms.txt` Current
|
|
423
486
|
|
|
424
|
-
|
|
487
|
+
Update both files when you change something an agent needs to discover:
|
|
425
488
|
|
|
426
|
-
|
|
489
|
+
- **New top-level markdown doc** → add to "Additional Documentation" here AND to the appropriate section of `llms.txt`.
|
|
490
|
+
- **New package entry point** (subpath export in `package.json`) → add to "Package Entry Points" here AND to "Package entry points" in `llms.txt`.
|
|
491
|
+
- **New CLI command or `bun run` script** → add to "Common Commands".
|
|
492
|
+
- **Renamed or moved key source file** → update "Key Source Files" here AND "Source map" in `llms.txt`.
|
|
493
|
+
- **New language mode / safety directive** → add to the TJS Syntax Reference section.
|
|
494
|
+
- **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
495
|
|
|
428
|
-
|
|
496
|
+
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
497
|
|
|
430
|
-
|
|
431
|
-
2. **Run quality gates** — if code changed: `bun run format`, `bun run typecheck`, `bun run test:fast` (or `bun test` for full suite).
|
|
432
|
-
3. **Commit** — focused commits with clear messages. Don't bundle unrelated changes.
|
|
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.
|
|
498
|
+
### Tracking Work
|
|
442
499
|
|
|
443
|
-
|
|
500
|
+
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.
|
|
501
|
+
|
|
502
|
+
### Landing the Plane (Session Completion Checklist)
|
|
444
503
|
|
|
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.
|
|
504
|
+
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
505
|
|
|
451
|
-
###
|
|
506
|
+
### Common Gotchas
|
|
452
507
|
|
|
453
|
-
|
|
508
|
+
- **`tjs(source)` returns an object, not a string.** It returns `{ code, types, metadata, testResults, ... }` — use `.code` for the transpiled JS string.
|
|
509
|
+
- **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).
|
|
510
|
+
- **`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
511
|
|
|
455
512
|
### Running Emitted TJS Code
|
|
456
513
|
|
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 {
|