@tracecode/harness 0.4.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/CHANGELOG.md +113 -0
- package/LICENSE +674 -0
- package/README.md +266 -0
- package/dist/browser.cjs +1352 -0
- package/dist/browser.cjs.map +1 -0
- package/dist/browser.d.cts +49 -0
- package/dist/browser.d.ts +49 -0
- package/dist/browser.js +1317 -0
- package/dist/browser.js.map +1 -0
- package/dist/cli.cjs +70 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +70 -0
- package/dist/cli.js.map +1 -0
- package/dist/core.cjs +286 -0
- package/dist/core.cjs.map +1 -0
- package/dist/core.d.cts +69 -0
- package/dist/core.d.ts +69 -0
- package/dist/core.js +254 -0
- package/dist/core.js.map +1 -0
- package/dist/index.cjs +2603 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +2538 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/browser.cjs +647 -0
- package/dist/internal/browser.cjs.map +1 -0
- package/dist/internal/browser.d.cts +143 -0
- package/dist/internal/browser.d.ts +143 -0
- package/dist/internal/browser.js +617 -0
- package/dist/internal/browser.js.map +1 -0
- package/dist/javascript.cjs +549 -0
- package/dist/javascript.cjs.map +1 -0
- package/dist/javascript.d.cts +11 -0
- package/dist/javascript.d.ts +11 -0
- package/dist/javascript.js +518 -0
- package/dist/javascript.js.map +1 -0
- package/dist/python.cjs +744 -0
- package/dist/python.cjs.map +1 -0
- package/dist/python.d.cts +97 -0
- package/dist/python.d.ts +97 -0
- package/dist/python.js +698 -0
- package/dist/python.js.map +1 -0
- package/dist/runtime-types-C7d1LFbx.d.ts +85 -0
- package/dist/runtime-types-Dvgn07z9.d.cts +85 -0
- package/dist/types-Bzr1Ohcf.d.cts +96 -0
- package/dist/types-Bzr1Ohcf.d.ts +96 -0
- package/package.json +89 -0
- package/workers/javascript/javascript-worker.js +2918 -0
- package/workers/python/generated-python-harness-snippets.js +20 -0
- package/workers/python/pyodide-worker.js +1197 -0
- package/workers/python/runtime-core.js +1529 -0
- package/workers/vendor/typescript.js +200276 -0
package/README.md
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
# TraceCode Harness
|
|
2
|
+
|
|
3
|
+
Browser-first execution and tracing harness for Python, JavaScript, and TypeScript.
|
|
4
|
+
|
|
5
|
+
`@tracecode/harness` is a browser-consumable runtime SDK for code execution and tracing: explicit browser runtime creation, package-managed worker assets, and no app-specific storage/bootstrap contract in the public API.
|
|
6
|
+
|
|
7
|
+
Project site: [tracecode.app](https://tracecode.app)
|
|
8
|
+
|
|
9
|
+
## Scope
|
|
10
|
+
|
|
11
|
+
This package provides an execution and tracing runtime for browser applications.
|
|
12
|
+
|
|
13
|
+
It includes:
|
|
14
|
+
|
|
15
|
+
- browser-hosted execution for Python, JavaScript, and TypeScript
|
|
16
|
+
- trace capture and normalized runtime contracts
|
|
17
|
+
- browser worker assets and asset sync tooling
|
|
18
|
+
- runtime-side structural annotations such as object kinds and hash/map payloads
|
|
19
|
+
|
|
20
|
+
It does not include a full end-user product.
|
|
21
|
+
|
|
22
|
+
Specifically, this package does not ship:
|
|
23
|
+
|
|
24
|
+
- any curriculum or problem corpus
|
|
25
|
+
- guided-learning logic
|
|
26
|
+
- higher-level visualization planners or rendering strategy
|
|
27
|
+
- personalization, analytics, or product workflows
|
|
28
|
+
- a complete application UI
|
|
29
|
+
|
|
30
|
+
## Non-Goals
|
|
31
|
+
|
|
32
|
+
`@tracecode/harness` is not intended to be:
|
|
33
|
+
|
|
34
|
+
- a full web IDE framework
|
|
35
|
+
- a white-labeled teaching product
|
|
36
|
+
- a higher-level pedagogy or visualization-planning layer
|
|
37
|
+
|
|
38
|
+
Consuming apps are expected to own their own UI, persistence, product logic, and any higher-order visualization behavior built on top of the runtime payloads.
|
|
39
|
+
|
|
40
|
+
## What You Get
|
|
41
|
+
|
|
42
|
+
- shared runtime contract types and trace adapters
|
|
43
|
+
- browser runtime clients for Python, JavaScript, and TypeScript
|
|
44
|
+
- published worker assets plus a CLI to copy them into your app
|
|
45
|
+
- capability profiles for honest per-language support claims
|
|
46
|
+
- regression coverage for runtime parity, packaging, and consumer smoke tests
|
|
47
|
+
|
|
48
|
+
This is not a general workflow engine. It is an opinionated execution harness designed for interactive code execution and trace playback in browser apps.
|
|
49
|
+
|
|
50
|
+
## Installation
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pnpm add @tracecode/harness
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
If your app bundles dependencies, transpiling the package is usually the safest option. For Next.js:
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
transpilePackages: ['@tracecode/harness']
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Quick Start
|
|
63
|
+
|
|
64
|
+
1. Copy the worker assets into your app's public directory.
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
pnpm exec tracecode-harness sync-assets public/workers
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
2. Create an explicit browser harness instance.
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import { createBrowserHarness } from '@tracecode/harness/browser';
|
|
74
|
+
|
|
75
|
+
const harness = createBrowserHarness({
|
|
76
|
+
assetBaseUrl: '/workers',
|
|
77
|
+
});
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
3. Get a runtime client and execute code.
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
const client = harness.getClient('python');
|
|
84
|
+
|
|
85
|
+
await client.init();
|
|
86
|
+
|
|
87
|
+
const result = await client.executeCode(
|
|
88
|
+
`
|
|
89
|
+
def solve(nums, target):
|
|
90
|
+
seen = {}
|
|
91
|
+
for index, value in enumerate(nums):
|
|
92
|
+
complement = target - value
|
|
93
|
+
if complement in seen:
|
|
94
|
+
return [seen[complement], index]
|
|
95
|
+
seen[value] = index
|
|
96
|
+
return []
|
|
97
|
+
`,
|
|
98
|
+
'solve',
|
|
99
|
+
{ nums: [2, 7, 11, 15], target: 9 }
|
|
100
|
+
);
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
4. Run tracing when the selected language profile supports it.
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
const trace = await client.executeWithTracing(
|
|
107
|
+
code,
|
|
108
|
+
'solve',
|
|
109
|
+
inputs,
|
|
110
|
+
{ maxTraceSteps: 200 },
|
|
111
|
+
'function'
|
|
112
|
+
);
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Public Package Surface
|
|
116
|
+
|
|
117
|
+
The package publishes built ESM and CommonJS entrypoints plus `.d.ts` files.
|
|
118
|
+
|
|
119
|
+
- `@tracecode/harness`
|
|
120
|
+
Re-exports the documented public surface.
|
|
121
|
+
- `@tracecode/harness/browser`
|
|
122
|
+
Browser harness factory, capability guards, and language profiles.
|
|
123
|
+
- `@tracecode/harness/core`
|
|
124
|
+
Shared runtime contracts, result types, and trace helpers.
|
|
125
|
+
- `@tracecode/harness/python`
|
|
126
|
+
Python harness generation helpers and snippet artifacts.
|
|
127
|
+
- `@tracecode/harness/javascript`
|
|
128
|
+
JavaScript and TypeScript execution helpers.
|
|
129
|
+
|
|
130
|
+
The browser entrypoint is intentionally narrow. Low-level worker constructors, language gates, and isolation helpers are internal implementation details, not public SDK surface.
|
|
131
|
+
|
|
132
|
+
## Browser API
|
|
133
|
+
|
|
134
|
+
The browser package centers on `createBrowserHarness(options)`.
|
|
135
|
+
|
|
136
|
+
```ts
|
|
137
|
+
import {
|
|
138
|
+
createBrowserHarness,
|
|
139
|
+
getLanguageRuntimeProfile,
|
|
140
|
+
isLanguageSupported,
|
|
141
|
+
SUPPORTED_LANGUAGES,
|
|
142
|
+
} from '@tracecode/harness/browser';
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
The returned harness exposes:
|
|
146
|
+
|
|
147
|
+
- `getClient(language)`
|
|
148
|
+
- `getProfile(language)`
|
|
149
|
+
- `getSupportedLanguageProfiles()`
|
|
150
|
+
- `isLanguageSupported(language)`
|
|
151
|
+
- `disposeLanguage(language)`
|
|
152
|
+
- `dispose()`
|
|
153
|
+
|
|
154
|
+
Configuration:
|
|
155
|
+
|
|
156
|
+
- `assetBaseUrl?: string`
|
|
157
|
+
- `assets?: Partial<{ pythonWorker; pythonRuntimeCore; pythonSnippets; javascriptWorker; typescriptCompiler }>`
|
|
158
|
+
- `debug?: boolean`
|
|
159
|
+
|
|
160
|
+
Example:
|
|
161
|
+
|
|
162
|
+
```ts
|
|
163
|
+
const harness = createBrowserHarness({
|
|
164
|
+
assetBaseUrl: '/workers',
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
const profile = harness.getProfile('typescript');
|
|
168
|
+
|
|
169
|
+
if (profile.capabilities.tracing.supported) {
|
|
170
|
+
// show trace controls
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## Worker Assets
|
|
175
|
+
|
|
176
|
+
`tracecode-harness sync-assets <target-dir>` copies the canonical browser asset set:
|
|
177
|
+
|
|
178
|
+
- `pyodide-worker.js`
|
|
179
|
+
- `generated-python-harness-snippets.js`
|
|
180
|
+
- `pyodide/runtime-core.js`
|
|
181
|
+
- `javascript-worker.js`
|
|
182
|
+
- `vendor/typescript.js`
|
|
183
|
+
|
|
184
|
+
By default, `createBrowserHarness({ assetBaseUrl: '/workers' })` resolves those assets as:
|
|
185
|
+
|
|
186
|
+
- `/workers/pyodide-worker.js`
|
|
187
|
+
- `/workers/generated-python-harness-snippets.js`
|
|
188
|
+
- `/workers/pyodide/runtime-core.js`
|
|
189
|
+
- `/workers/javascript-worker.js`
|
|
190
|
+
- `/workers/vendor/typescript.js`
|
|
191
|
+
|
|
192
|
+
Advanced consumers can override individual asset URLs through the `assets` option.
|
|
193
|
+
|
|
194
|
+
## Capability Model
|
|
195
|
+
|
|
196
|
+
Runtime support is expressed through language profiles, not a few flat booleans.
|
|
197
|
+
|
|
198
|
+
Each profile includes:
|
|
199
|
+
|
|
200
|
+
- `language`
|
|
201
|
+
- `maturity`
|
|
202
|
+
- `capabilities`
|
|
203
|
+
|
|
204
|
+
Capability domains:
|
|
205
|
+
|
|
206
|
+
- `execution`
|
|
207
|
+
- `tracing`
|
|
208
|
+
- `diagnostics`
|
|
209
|
+
- `structures`
|
|
210
|
+
- `visualization`
|
|
211
|
+
|
|
212
|
+
That lets the package be explicit about partial support and fail closed for unsupported requests.
|
|
213
|
+
|
|
214
|
+
## Example Consumer
|
|
215
|
+
|
|
216
|
+
A minimal reference browser IDE lives in [examples/web-ide](./examples/web-ide). It is intentionally small and exists to prove that a third-party app can:
|
|
217
|
+
|
|
218
|
+
- consume the public browser API
|
|
219
|
+
- sync worker assets with the CLI
|
|
220
|
+
- initialize all supported runtimes
|
|
221
|
+
- execute and trace code without any app-specific state wiring
|
|
222
|
+
|
|
223
|
+
It is a reference consumer for the SDK contract, not a canonical product UI.
|
|
224
|
+
|
|
225
|
+
## Development
|
|
226
|
+
|
|
227
|
+
Install workspace dependencies:
|
|
228
|
+
|
|
229
|
+
```bash
|
|
230
|
+
pnpm install
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
Run the full gate:
|
|
234
|
+
|
|
235
|
+
```bash
|
|
236
|
+
pnpm test
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
That covers:
|
|
240
|
+
|
|
241
|
+
- package typechecks
|
|
242
|
+
- runtime and trace contract tests
|
|
243
|
+
- packaging/import smoke tests
|
|
244
|
+
- asset sync contract tests
|
|
245
|
+
- example app browser smoke tests
|
|
246
|
+
|
|
247
|
+
If you change Python harness templates or generated snippets, regenerate artifacts:
|
|
248
|
+
|
|
249
|
+
```bash
|
|
250
|
+
pnpm generate:python-harness
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
## Releases
|
|
254
|
+
|
|
255
|
+
This repo uses explicit versioned release boundaries.
|
|
256
|
+
|
|
257
|
+
- `0.1.0` introduced the public harness baseline
|
|
258
|
+
- `0.2.0` introduced structured runtime capability profiles
|
|
259
|
+
- `0.3.0` introduced runtime access metadata in traces
|
|
260
|
+
- `0.4.0` makes the harness a clean browser SDK with explicit runtime creation and asset sync tooling
|
|
261
|
+
|
|
262
|
+
Detailed release notes live in [CHANGELOG.md](./CHANGELOG.md).
|
|
263
|
+
|
|
264
|
+
## License
|
|
265
|
+
|
|
266
|
+
GPL-3.0-only
|