tjs-lang 0.8.7 → 0.9.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 +12 -4
- package/dist/experiments/ambient/probe.d.ts +52 -0
- package/dist/index.js +115 -171
- 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.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.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 +100 -90
- 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 +102 -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/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.ts +33 -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 +109 -14
- package/src/lang/parser.ts +9 -2
- package/src/lang/predicate-evaluator.test.ts +49 -0
- package/src/lang/predicate-report.test.ts +54 -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/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,8 @@ 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
|
+
bun run build:editors # Bundle editors/{codemirror,monaco,ace}/*.ts → published *.js
|
|
24
25
|
bun run dev # Development server with file watcher
|
|
25
26
|
bun run start # Build demo + start dev server
|
|
26
27
|
bun run latest # Clean reinstall (rm node_modules + bun install)
|
|
@@ -68,15 +69,15 @@ bun run functions:serve # Local functions emulator
|
|
|
68
69
|
### Two-Layer Design
|
|
69
70
|
|
|
70
71
|
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 (~
|
|
72
|
+
2. **Runtime Layer** (`src/vm/runtime.ts`): Executes AST nodes. Contains all atom implementations (~3134 lines, security-critical).
|
|
72
73
|
|
|
73
74
|
### Key Source Files
|
|
74
75
|
|
|
75
76
|
- `src/index.ts` - Main entry, re-exports everything
|
|
76
|
-
- `src/vm/runtime.ts` - All atom implementations, expression evaluation, fuel charging (~
|
|
77
|
+
- `src/vm/runtime.ts` - All atom implementations, expression evaluation, fuel charging (~3134 lines, security-critical)
|
|
77
78
|
- `src/vm/vm.ts` - AgentVM class (~247 lines)
|
|
78
79
|
- `src/vm/atoms/batteries.ts` - Battery atoms (vector search, LLM, store operations)
|
|
79
|
-
- `src/builder.ts` - TypedBuilder fluent API (~
|
|
80
|
+
- `src/builder.ts` - TypedBuilder fluent API (~754 lines / ~19KB)
|
|
80
81
|
- `src/lang/parser.ts` - TJS parser with colon shorthand, unsafe markers, return type extraction
|
|
81
82
|
- `src/lang/parser-transforms.ts` - Type, Generic, and FunctionPredicate block/function form transforms
|
|
82
83
|
- `src/lang/emitters/ast.ts` - Emits Agent99 AST from parsed source
|
|
@@ -93,6 +94,8 @@ bun run functions:serve # Local functions emulator
|
|
|
93
94
|
- `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
95
|
- `src/lang/module-loader.ts` - Transpile-time `.tjs`/`.ts`/`.js` module loader (Phase 0.75); used by cross-file `wasm function` composition
|
|
95
96
|
- `src/linalg/` - `tjs-lang/linalg` stdlib subpath (f32x4 SIMD vector kernels)
|
|
97
|
+
- `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).
|
|
98
|
+
- `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
99
|
- `src/types/` - Type system definitions (Type.ts, Generic.ts)
|
|
97
100
|
- `src/transpiler/` - AJS transpiler (source → AST)
|
|
98
101
|
- `src/batteries/` - LM Studio integration (lazy init, model audit, vector search)
|
|
@@ -146,6 +149,11 @@ import { fromTS } from 'tjs-lang/lang/from-ts' // TypeScript transpilation
|
|
|
146
149
|
import { AgentVM } from 'tjs-lang/vm' // VM only (smaller bundle)
|
|
147
150
|
import { batteryAtoms } from 'tjs-lang/batteries' // LM Studio batteries
|
|
148
151
|
import { dot, norm_sq } from 'tjs-lang/linalg' // SIMD linear-algebra kernels
|
|
152
|
+
import { isColor, suggestColor } from 'tjs-lang/css' // CSS validators (verified predicates)
|
|
153
|
+
import { s, validate } from 'tjs-lang/schema' // tosijs-schema pre-wired with $predicate support
|
|
154
|
+
import { createRuntime, Eq, isMonadicError } from 'tjs-lang/runtime' // TJS runtime (for emitted .tjs / integrations)
|
|
155
|
+
// Bun: enable native .tjs imports — `preload = ["tjs-lang/bun-plugin"]` in bunfig.toml, or:
|
|
156
|
+
import 'tjs-lang/bun-plugin' // registers the .tjs onLoad plugin + installs __tjs (bun-only)
|
|
149
157
|
// Editor integrations: 'tjs-lang/editors/monaco', '/codemirror', '/ace'
|
|
150
158
|
|
|
151
159
|
// Self-contained BROWSER bundles — drop-in via import() from any CDN, no
|
|
@@ -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 {};
|