tjs-lang 0.8.7 → 0.9.1
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 +19 -5
- package/dist/experiments/ambient/probe.d.ts +52 -0
- package/dist/index.js +110 -162
- package/dist/index.js.map +4 -4
- package/dist/scripts/build-editors.d.ts +19 -0
- package/dist/src/css/dimensions.d.ts +23 -0
- package/dist/src/css/index.d.ts +85 -0
- package/dist/src/css/predicates.d.ts +38 -0
- package/dist/src/css/shorthands.d.ts +31 -0
- package/dist/src/css/style.d.ts +48 -0
- package/dist/src/lang/emitters/js-wasm.d.ts +2 -0
- package/dist/src/lang/emitters/js.d.ts +9 -1
- package/dist/src/lang/index.d.ts +2 -2
- package/dist/src/lang/parser-transforms.d.ts +9 -5
- package/dist/src/lang/parser-types.d.ts +7 -0
- package/dist/src/lang/parser.d.ts +2 -0
- package/dist/src/lang/predicate.d.ts +60 -0
- package/dist/src/lang/transpiler.d.ts +3 -2
- package/dist/src/lang/types.d.ts +16 -0
- package/dist/src/schema/index.d.ts +12 -0
- package/dist/tjs-browser-from-ts.js +20 -20
- package/dist/tjs-browser-from-ts.js.map +3 -3
- package/dist/tjs-browser.js +108 -94
- package/dist/tjs-browser.js.map +4 -4
- package/dist/tjs-css.js +193 -0
- package/dist/tjs-css.js.map +7 -0
- package/dist/tjs-eval.js +43 -42
- package/dist/tjs-eval.js.map +4 -4
- package/dist/tjs-from-ts.js +13 -13
- package/dist/tjs-from-ts.js.map +2 -2
- package/dist/tjs-lang.js +106 -92
- package/dist/tjs-lang.js.map +4 -4
- package/dist/tjs-runtime.js +10 -0
- package/dist/tjs-runtime.js.map +7 -0
- package/dist/tjs-schema.js +6 -0
- package/dist/tjs-schema.js.map +7 -0
- package/dist/tjs-vm.js +55 -54
- package/dist/tjs-vm.js.map +4 -4
- package/docs/ambient-contracts.md +261 -0
- package/docs/type-system-north-star.md +100 -0
- package/editors/ace/ajs-mode.js +214 -233
- package/editors/codemirror/ajs-language.js +1570 -233
- package/editors/editors-build.test.ts +29 -0
- package/editors/monaco/ajs-monarch.js +239 -195
- package/llms.txt +4 -0
- package/package.json +35 -4
- package/src/css/css.test.ts +122 -0
- package/src/css/dimensions.test.ts +112 -0
- package/src/css/dimensions.ts +146 -0
- package/src/css/index.ts +243 -0
- package/src/css/perf.bench.test.ts +109 -0
- package/src/css/predicates.ts +232 -0
- package/src/css/property-aware.test.ts +84 -0
- package/src/css/shorthands.test.ts +90 -0
- package/src/css/shorthands.ts +113 -0
- package/src/css/style.test.ts +125 -0
- package/src/css/style.ts +134 -0
- package/src/index-tsfree.test.ts +58 -0
- package/src/lang/emit-verified-predicate.test.ts +95 -0
- package/src/lang/emitters/dts.test.ts +31 -0
- package/src/lang/emitters/dts.ts +23 -4
- package/src/lang/emitters/js-wasm.ts +8 -4
- package/src/lang/emitters/js.ts +58 -1
- package/src/lang/from-ts.test.ts +1 -1
- package/src/lang/generic-verified-predicate.test.ts +39 -0
- package/src/lang/index.ts +14 -5
- package/src/lang/parser-transforms.ts +113 -15
- package/src/lang/parser-types.ts +7 -0
- package/src/lang/parser.ts +18 -3
- package/src/lang/predicate-evaluator.test.ts +49 -0
- package/src/lang/predicate-report.test.ts +78 -0
- package/src/lang/predicate.ts +268 -0
- package/src/lang/redos-lint.test.ts +81 -0
- package/src/lang/transpiler.ts +13 -0
- package/src/lang/type-verified-predicate.test.ts +83 -0
- package/src/lang/types.ts +17 -0
- package/src/lang/typescript-syntax.test.ts +2 -1
- package/src/lang/wasm-fallback-warning.test.ts +50 -0
- package/src/lang/wasm-intdiv-lint.test.ts +45 -0
- package/src/lang/wasm-ready.test.ts +94 -0
- package/src/lang/wasm-simd-ops.test.ts +84 -0
- package/src/lang/wasm.ts +61 -2
- package/src/schema/index.ts +62 -0
- package/src/schema/schema.test.ts +66 -0
- package/src/use-cases/bootstrap.test.ts +14 -4
package/CLAUDE.md
CHANGED
|
@@ -20,7 +20,13 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
|
|
|
20
20
|
# Development
|
|
21
21
|
bun run format # ESLint fix + Prettier
|
|
22
22
|
bun run test:fast # Core tests (skips LLM & benchmarks)
|
|
23
|
-
bun run make # Full build (clean, format, grammars, tsc, esbuild)
|
|
23
|
+
bun run make # Full build (clean, format, grammars, editors, tsc, esbuild)
|
|
24
|
+
# Named `make`, NOT `build`, on purpose: `bun build` is a Bun
|
|
25
|
+
# builtin (the bundler). If a `build` script existed, `bun build`
|
|
26
|
+
# would silently run the builtin instead of the script while
|
|
27
|
+
# `bun run build` ran the script — an ever-present footgun where
|
|
28
|
+
# the two commands diverge. Don't add a `build` script.
|
|
29
|
+
bun run build:editors # Bundle editors/{codemirror,monaco,ace}/*.ts → published *.js
|
|
24
30
|
bun run dev # Development server with file watcher
|
|
25
31
|
bun run start # Build demo + start dev server
|
|
26
32
|
bun run latest # Clean reinstall (rm node_modules + bun install)
|
|
@@ -68,15 +74,15 @@ bun run functions:serve # Local functions emulator
|
|
|
68
74
|
### Two-Layer Design
|
|
69
75
|
|
|
70
76
|
1. **Builder Layer** (`src/builder.ts`): Fluent API that constructs AST nodes. Contains no execution logic.
|
|
71
|
-
2. **Runtime Layer** (`src/vm/runtime.ts`): Executes AST nodes. Contains all atom implementations (~
|
|
77
|
+
2. **Runtime Layer** (`src/vm/runtime.ts`): Executes AST nodes. Contains all atom implementations (~3134 lines, security-critical).
|
|
72
78
|
|
|
73
79
|
### Key Source Files
|
|
74
80
|
|
|
75
81
|
- `src/index.ts` - Main entry, re-exports everything
|
|
76
|
-
- `src/vm/runtime.ts` - All atom implementations, expression evaluation, fuel charging (~
|
|
82
|
+
- `src/vm/runtime.ts` - All atom implementations, expression evaluation, fuel charging (~3134 lines, security-critical)
|
|
77
83
|
- `src/vm/vm.ts` - AgentVM class (~247 lines)
|
|
78
84
|
- `src/vm/atoms/batteries.ts` - Battery atoms (vector search, LLM, store operations)
|
|
79
|
-
- `src/builder.ts` - TypedBuilder fluent API (~
|
|
85
|
+
- `src/builder.ts` - TypedBuilder fluent API (~754 lines / ~19KB)
|
|
80
86
|
- `src/lang/parser.ts` - TJS parser with colon shorthand, unsafe markers, return type extraction
|
|
81
87
|
- `src/lang/parser-transforms.ts` - Type, Generic, and FunctionPredicate block/function form transforms
|
|
82
88
|
- `src/lang/emitters/ast.ts` - Emits Agent99 AST from parsed source
|
|
@@ -93,6 +99,8 @@ bun run functions:serve # Local functions emulator
|
|
|
93
99
|
- `src/lang/emitters/js-wasm.ts` - JS bootstrap emitter for compiled wasm modules (one `WebAssembly.compile` per file, name→export-index table, type-aware wrappers)
|
|
94
100
|
- `src/lang/module-loader.ts` - Transpile-time `.tjs`/`.ts`/`.js` module loader (Phase 0.75); used by cross-file `wasm function` composition
|
|
95
101
|
- `src/linalg/` - `tjs-lang/linalg` stdlib subpath (f32x4 SIMD vector kernels)
|
|
102
|
+
- `src/schema/` - `tjs-lang/schema` subpath: **tosijs-schema pre-wired with `$predicate` support**. Re-exports the whole tosijs-schema surface and auto-registers `createPredicateEvaluator()` on import (batteries-included), so JSON-Schema validation is predicate-aware with zero wiring. Lives here (not in tosijs-schema) because tjs-lang depends on tosijs-schema — the reverse would be circular. `tosijs-schema` is externalized in the bundle (single instance → single global evaluator). Requires `tosijs-schema@^1.4.0` (the `setPredicateEvaluator` hook).
|
|
103
|
+
- `src/css/` - `tjs-lang/css` subpath: CSS validators built from verified-safe predicates. `predicates.ts` (colors), `dimensions.ts` (lengths/numbers/angles/times/keywords), `shorthands.ts` (order-flexible `animation`/`transition` — paren-aware tokenize + classify), `style.ts` (recursive style-object structure + the `$predicate` JSON-Schema builders `cssStyleSchema`/`cssColorSchema`); `index.ts` = compiled validators + `suggestColor` + `verifyCss` (verifies all clusters). The predicate-types thesis made real — phases 1/2/3(animation+transition)/4 done; font/background shorthands + perf (phase 5) remain (TODO #4)
|
|
96
104
|
- `src/types/` - Type system definitions (Type.ts, Generic.ts)
|
|
97
105
|
- `src/transpiler/` - AJS transpiler (source → AST)
|
|
98
106
|
- `src/batteries/` - LM Studio integration (lazy init, model audit, vector search)
|
|
@@ -146,6 +154,11 @@ import { fromTS } from 'tjs-lang/lang/from-ts' // TypeScript transpilation
|
|
|
146
154
|
import { AgentVM } from 'tjs-lang/vm' // VM only (smaller bundle)
|
|
147
155
|
import { batteryAtoms } from 'tjs-lang/batteries' // LM Studio batteries
|
|
148
156
|
import { dot, norm_sq } from 'tjs-lang/linalg' // SIMD linear-algebra kernels
|
|
157
|
+
import { isColor, suggestColor } from 'tjs-lang/css' // CSS validators (verified predicates)
|
|
158
|
+
import { s, validate } from 'tjs-lang/schema' // tosijs-schema pre-wired with $predicate support
|
|
159
|
+
import { createRuntime, Eq, isMonadicError } from 'tjs-lang/runtime' // TJS runtime (for emitted .tjs / integrations)
|
|
160
|
+
// Bun: enable native .tjs imports — `preload = ["tjs-lang/bun-plugin"]` in bunfig.toml, or:
|
|
161
|
+
import 'tjs-lang/bun-plugin' // registers the .tjs onLoad plugin + installs __tjs (bun-only)
|
|
149
162
|
// Editor integrations: 'tjs-lang/editors/monaco', '/codemirror', '/ace'
|
|
150
163
|
|
|
151
164
|
// Self-contained BROWSER bundles — drop-in via import() from any CDN, no
|
|
@@ -508,7 +521,8 @@ The CLI (`bun src/cli/tjs.ts run`) does NOT inject the test-block `expect` harne
|
|
|
508
521
|
|
|
509
522
|
### Additional Documentation
|
|
510
523
|
|
|
511
|
-
- `PRINCIPLES.md` — **non-negotiable language invariants**: options-off TJS ⊇ JS, and TJS ⊇ AJS. A richer layer may do _more_ with the same source but must never make subset-legal code _illegal_ (e.g. un-runnable signature tests are inconclusive, not errors). Read before changing parser/transpiler acceptance or signature-test behavior; a subset violation is a bug.
|
|
524
|
+
- `PRINCIPLES.md` — **non-negotiable language invariants**: options-off TJS ⊇ JS, and TJS ⊇ AJS. A richer layer may do _more_ with the same source but must never make subset-legal code _illegal_ (e.g. un-runnable signature tests are inconclusive, not errors). Read before changing parser/transpiler acceptance or signature-test behavior; a subset violation is a bug. Also carries the **type-system north star** (JSON-Schema + `$predicate` as the single source of truth for types — a decision lens).
|
|
525
|
+
- `docs/type-system-north-star.md` — the north-star design note: JSON-Schema + `$predicate` as the canonical type representation; the decision lens ("closer to or further from?"); and the small portable predicate-VM (serialized-AST, cross-language) that unlocks it. Strategic (possibly post-1.0).
|
|
512
526
|
- `llms.txt` — agent-facing navigation index (ships in npm bundle); points to docs and source entry points
|
|
513
527
|
- `guides/footguns.md` — JS footguns TJS fixes (boxed-primitive truthiness, `==` coercion, `typeof null`, uninitialized `let`, etc.). Demo: `examples/js-footguns-fixed.tjs`.
|
|
514
528
|
- `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.
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ambient-contract spike — the "derive" step in miniature.
|
|
3
|
+
*
|
|
4
|
+
* `deriveShapeContract(sample, name)` turns an observed value (a real object
|
|
5
|
+
* introspected from an ambient environment, or a synthetic stand-in) into a
|
|
6
|
+
* predicate-cluster SOURCE: presence + `typeof` checks per own key. Feed the
|
|
7
|
+
* source to `verifyPredicate`/`compilePredicate` and it's a certified, native,
|
|
8
|
+
* serializable contract for "looks like this thing". The real tool would source
|
|
9
|
+
* `sample` from a live browser probe (Claude-in-Chrome / the introspection
|
|
10
|
+
* iframe) and scope it to the surface a program actually uses; this is just the
|
|
11
|
+
* transform, so the whole loop is testable headlessly.
|
|
12
|
+
*
|
|
13
|
+
* See docs/ambient-contracts.md.
|
|
14
|
+
*/
|
|
15
|
+
/** A single derived check line. */
|
|
16
|
+
type Check = {
|
|
17
|
+
key: string;
|
|
18
|
+
type: string;
|
|
19
|
+
kind: 'value' | 'method';
|
|
20
|
+
};
|
|
21
|
+
export interface ProbeOptions {
|
|
22
|
+
/**
|
|
23
|
+
* Only probe these keys. STRONGLY recommended for host objects: the surface a
|
|
24
|
+
* program actually uses, traced from the real environment. Without it we walk
|
|
25
|
+
* the whole prototype chain, which for a DOM object is hundreds of props — a
|
|
26
|
+
* huge, over-specified contract.
|
|
27
|
+
*/
|
|
28
|
+
keys?: string[];
|
|
29
|
+
/** How many prototype levels to walk when `keys` is not given. Default 3. */
|
|
30
|
+
maxDepth?: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Introspect a sample's shape → (key, typeof, method?) checks.
|
|
34
|
+
*
|
|
35
|
+
* Host objects (DOM etc.) hide their real surface on the PROTOTYPE, non-
|
|
36
|
+
* enumerable — `Object.keys(element.style)` is nearly empty even though
|
|
37
|
+
* `typeof style.color === 'string'`. So we walk the prototype chain (or check a
|
|
38
|
+
* scoped `keys` list) and read `typeof sample[key]`, not `Object.keys`.
|
|
39
|
+
*
|
|
40
|
+
* Caveat (noted in docs/ambient-contracts.md): reading an accessor invokes its
|
|
41
|
+
* getter, which on a real DOM object can have side effects (e.g. `offsetWidth`
|
|
42
|
+
* forces layout). A scoped `keys` list keeps this bounded; a stricter probe would
|
|
43
|
+
* inspect property descriptors instead of reading. Getters that throw are skipped.
|
|
44
|
+
*/
|
|
45
|
+
export declare function probeShape(sample: Record<string, unknown>, opts?: ProbeOptions): Check[];
|
|
46
|
+
/**
|
|
47
|
+
* Emit a predicate-safe source cluster asserting `x` has the probed shape:
|
|
48
|
+
* non-null, and each key present with the observed `typeof`. The last function
|
|
49
|
+
* (`is<Name>`) is the entry, so the source drops straight into a `$predicate`.
|
|
50
|
+
*/
|
|
51
|
+
export declare function deriveShapeContract(sample: Record<string, unknown>, name: string, opts?: ProbeOptions): string;
|
|
52
|
+
export {};
|