[pine-worker]

TypeScript Pine evaluator port colocated in pynescript — architecture, status, and relationship to the Python oracle.

pine-worker

Abstract

pine-worker is a TypeScript implementation track for the Pine Script™ evaluator (AST types, visitor dispatch, series history, and eventually builtins + strategy events). It lives at pine-worker/ inside the pynescript repository as an extra tool, not a replacement for the Python package.

Colocation goals:

  • Share parity fixtures under tests/fixtures/parity/
  • Keep the ANTLR resource grammar as single syntactic truth (TS parser target can be generated later)
  • Allow cross-language porting in one checkout

Python (pynescript + backend/) remains the semantic oracle.

Conceptual model

Interface surface

Quick start (Bun)

cd pine-worker
bun install
bun test
bun run typecheck

package.json scripts:

ScriptAction
testbun test
test:watchwatch mode
typechecktsc --noEmit
parityreserved — harness not fully wired

Dependencies: Zod (AST schemas), TypeScript; runtime assumes Bun for tests.

Current skeleton

AreaState
AST Zod schemas + typesPartial (mirrors Python ASDL intent)
Base evaluator + visitor dispatchPartial
PineSeries historical accessPartial
Core NA / loop signal semanticsPartial
Full builtinsIn progress
ANTLR TS parserNot complete
Strategy event emissionPlan-driven (see opencode plans)
Parity harness test/parity/Planned

Relationship to HOOX

When mature, pine-worker may be vendored/submoduled into hoox-setup as a Cloudflare Worker bound to trade-worker. Until then it develops here. Sister: pyne-worker (Python edge) is a different repo.

Internals

PathRole
pine-worker/src/ast/types.tsAST typing / Zod
pine-worker/src/evaluator/evaluator.tsVisitor evaluator
pine-worker/src/evaluator/series.tsSeries model
pine-worker/src/evaluator/types.tsNA, signals, registries
pine-worker/test/*.test.tsUnit tests
pine-worker/scripts/convert-python-to-ts.pyPorting aid
tests/fixtures/parity/Shared oracle fixtures
.opencode/plans/*pine-worker*Strategy-events plans

Invariants & edge cases

  1. Python wins ties. If TS and Python disagree, fix TS (unless Python is proven wrong — then fix both + fixtures).
  2. NA is a sentinel, not JS null alone — truthiness differs from ordinary JS symbols.
  3. Do not fork grammar ad hoc in TS; prefer shared resource .g4.
  4. Converter emits stubs, not proofs — manual port + parity required.
  5. License follows parent pynescript project.

Worked examples

Minimal evaluator unit (conceptual)

TS tests construct literal AST nodes (Literal, Assign, Script) and assert visitor results — see pine-worker/test/evaluator.test.ts.

Regenerate Python fixtures

python tests/fixtures/parity/generate_fixtures.py

Failure modes

SymptomCauseFix
bun test fails on NAJS truthinessUse Pine truth helpers
Parity script no-opsHarness not wiredImplement test/parity per plan
Drift from Python builtinsManual port errorRe-run converter diff + fixtures

See also