Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d32784d
initial new schema implementation
barhanc Jul 22, 2026
9eee392
wip
barhanc Jul 23, 2026
36eb008
ts side kinda finished
barhanc Jul 24, 2026
2f4ca6e
small fix
barhanc Jul 24, 2026
aec8fe7
refactor ts side
barhanc Jul 24, 2026
1beef47
update
barhanc Jul 27, 2026
7ef1c8b
update
barhanc Jul 27, 2026
cf58a2c
update
barhanc Jul 27, 2026
de8c713
refactor schema validation to use validateSpec across all tasks
barhanc Jul 28, 2026
0416cf5
rebase
barhanc Jul 28, 2026
c1391da
small fix
barhanc Jul 28, 2026
8f13d2a
small fix
barhanc Jul 28, 2026
eacc19a
feat(schema): add helper methods for runtime constraints and update t…
barhanc Jul 28, 2026
d7098d0
refactor(schema): namespace schema exports and cleanup constraint hel…
barhanc Jul 28, 2026
aee02ec
docs(skills): update model-schema-validation skill to reflect constr …
barhanc Jul 28, 2026
e622b5f
docs(schema): document SpecMatch.dims and add dynamic dimension accessor
barhanc Jul 28, 2026
708e3fd
docs(schema): expand JSDoc comments and clarify validation phases
barhanc Jul 28, 2026
65609c2
small fix
barhanc Jul 28, 2026
7bdb7a5
fix attribute name
barhanc Jul 28, 2026
05fbc5e
fix
barhanc Jul 28, 2026
99b4d5f
fix
barhanc Jul 28, 2026
7dee00b
docs(schema): document get_model_schema companion method and spec sou…
barhanc Jul 29, 2026
f8d94a8
refactor: use std::visit pattern for variant matching in tensor_helpe…
barhanc Jul 29, 2026
5183a3a
docs: clarify audio padding comment in whisperSpeechToText
barhanc Jul 29, 2026
1b08e48
fix(schema): throw on step === 0 in RangeDim builder
barhanc Jul 29, 2026
9170477
docs: update model-schema-validation skill example and accessors
barhanc Jul 29, 2026
212851b
fix(schema): restore bind terminology in schema matching and document…
barhanc Jul 30, 2026
cbb69c5
fix(model): fix error string
barhanc Jul 30, 2026
3f0a772
fix(core): improve error messages for model, schema, and tensor_helpers
barhanc Jul 30, 2026
c8c6c62
fix: error message
barhanc Jul 30, 2026
4146707
fix(model): add bad model export cause to execution error message
barhanc Jul 30, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .agents/skills/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ This directory contains specialized skills (recipes) to guide contributors and A
- [Core Guidelines](./core-guidelines/SKILL.md) — Symmetrical architecture, conventions, and model rules.
- [Add Native Extension](./add-native-extension/SKILL.md) — C++ operations and JSI bindings.
- [Add Task Pipeline](./add-task-pipeline/SKILL.md) — TypeScript task pipelines and React hooks.
- [Model Schema Validation](./model-schema-validation/SKILL.md) — SymbolicTensor schemas and validation.
- [Model Schema Validation](./model-schema-validation/SKILL.md) — Model specs, dynamic shapes, and schema validation.
- [Verify and Build](./verify-and-build/SKILL.md) — TypeScript typechecking, native rebuilding, and troubleshooting.
- [Skills Maintenance](./skills-maintenance/SKILL.md) — Keeping skills synchronized with core primitives.
38 changes: 19 additions & 19 deletions .agents/skills/add-task-pipeline/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,17 @@ When implementing task constructors like `create<Task>` (e.g. `createClassifier`
- Handle model-specific configuration parameters (such as unique normalization factors, thresholds, or label arrays) dynamically through the TypeScript task options argument rather than baking them rigidly into JSI C++ code or the model structure. This rule contrasts TypeScript options against values baked into C++ or the model; to choose between a TypeScript **option** and a TypeScript **constant**, see Principle 6.

6. **Options vs. Constants (bucket by who varies the value)**:
- Every parameter belongs in exactly one of three places. Decide by asking *who varies this, and when*:
- Every parameter belongs in exactly one of three places. Decide by asking _who varies this, and when_:

| The value... | Lives as | Example |
| ------------------------------------------------------------------------------------ | -------------------------------------------------------------- | -------------------------------------------------------------- |
| Varies across the shipped models/variants of the pipeline | A task **option**, set per-model in `models.ts` | Whisper `tiny`/`base`/`small` sizes; normalization factors; labels |
| Is fixed by the model architecture or the `.pte` export contract, identical for every shipped variant | A **`const`** in the task file, beside the code that reads it | Static tensor shapes; export-pinned scheduler/decoder scalars |
| Is a per-call choice made by the app developer | An **argument** to the worklet executor | `threshold`, `seed`, `prompt` |
| The value... | Lives as | Example |
| ----------------------------------------------------------------------------------------------------- | ------------------------------------------------------------- | ------------------------------------------------------------------ |
| Varies across the shipped models/variants of the pipeline | A task **option**, set per-model in `models.ts` | Whisper `tiny`/`base`/`small` sizes; normalization factors; labels |
| Is fixed by the model architecture or the `.pte` export contract, identical for every shipped variant | A **`const`** in the task file, beside the code that reads it | Static tensor shapes; export-pinned scheduler/decoder scalars |
| Is a per-call choice made by the app developer | An **argument** to the worklet executor | `threshold`, `seed`, `prompt` |

- **A parameter with exactly one valid value is not an option — it is a constant.** For single-model pipelines (e.g. `sdxsTextToImage`), exposing export-pinned scalars or static shapes as options advertises knobs that either fail schema validation or silently corrupt output when touched. Prefer a `const` with a comment naming *why* the value is fixed.
- **Corollary (a quick smell test):** if every variant in `models.ts` passes an *identical* options object, those fields are not configuration — move them into the task file as constants and shrink the model type to the paths that actually differ.
- Do not keep a loop, parameter, or code path solely because it *looks* more general. If the surrounding math is only valid for one value (e.g. coefficients pinned to a single distilled timestep), the generality is fake and the parameter is a correctness trap.
- **A parameter with exactly one valid value is not an option — it is a constant.** For single-model pipelines (e.g. `sdxsTextToImage`), exposing export-pinned scalars or static shapes as options advertises knobs that either fail schema validation or silently corrupt output when touched. Prefer a `const` with a comment naming _why_ the value is fixed.
- **Corollary (a quick smell test):** if every variant in `models.ts` passes an _identical_ options object, those fields are not configuration — move them into the task file as constants and shrink the model type to the paths that actually differ.
- Do not keep a loop, parameter, or code path solely because it _looks_ more general. If the surrounding math is only valid for one value (e.g. coefficients pinned to a single distilled timestep), the generality is fake and the parameter is a correctness trap.

## 🚫 Avoid / Anti-Patterns

Expand All @@ -95,7 +95,7 @@ import type { WorkletRuntime } from 'react-native-worklets';

import { tensor } from '../../../core/tensor';
import { loadModel } from '../../../core/model';
import { validateModelSchema, SymbolicTensor } from '../../../core/modelSchema';
import { validateSpec, method, f32 } from '../../../core/schema';
import { wrapAsync } from '../../../core/runtime';
import { type ImageBuffer } from '../image';
import { createImagePreprocessor, type ImagePreprocessorOptions } from './preprocessing';
Expand Down Expand Up @@ -137,15 +137,15 @@ export async function createMyTask(
const { modelPath, taskOpts } = config;
const model = await wrapAsync(loadModel, runtime)(modelPath);

// Validate model schema
const meta = validateModelSchema(
model,
'forward',
[SymbolicTensor('float32', [1, 3, 'H', 'W'], [3, 'H', 'W'])],
[SymbolicTensor('float32', [1, 10], [10])]
);
const inpShape = meta.inputTensorMeta[0]!.shape;
const outShape = meta.outputTensorMeta[0]!.shape;
// Validate model spec
const { variant, dims } = validateSpec(model.schema, {
batched: method('forward', [f32(1, 3, 'H', 'W')], [f32(1, 10)]),
unbatched: method('forward', [f32(3, 'H', 'W')], [f32(10)]),
});

const [H, W] = dims.constant('H', 'W');
const inpShape = { batched: [1, 3, H, W], unbatched: [3, H, W] }[variant];
const outShape = { batched: [1, 10], unbatched: [10] }[variant];

// 2. Pre-allocate static tensors
const tensors = [tensor('float32', outShape)] as const;
Expand Down
2 changes: 1 addition & 1 deletion .agents/skills/core-guidelines/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Use the following index to locate the specific procedural guides for your task:
| **Add a new native operator or C++ binding** | [SKILL.md](../add-native-extension/SKILL.md) | Procedural guide to implementing C++ functions, exposing them via JSI, and writing TypeScript bridge wrappers. |
| **Create a task pipeline or hook** | [SKILL.md](../add-task-pipeline/SKILL.md) | Guide to building end-to-end TS pipelines (e.g. object detection) and exposing them via React hooks. |
| **Verify, rebuild, or troubleshoot changes** | [SKILL.md](../verify-and-build/SKILL.md) | Workflows for rebuilding TS/C++ and resolving common JSI runtime errors. |
| **Validate model constraints & schemas** | [SKILL.md](../model-schema-validation/SKILL.md) | Guide on specifying SymbolicTensor constraints and shapes for model signature validation. |
| **Validate model constraints & schemas** | [SKILL.md](../model-schema-validation/SKILL.md) | Guide on specifying model specs, dynamic shapes, and runtime constraints for model validation. |
| **Maintain or refactor codebase patterns** | [SKILL.md](../skills-maintenance/SKILL.md) | Guide to keeping workspace skills in sync with codebase state to prevent documentation decay. |

---
Expand Down
Loading