feature

Multi-file packages and imports

Large definitions can be split across multiple files, and they can subscribe to events from other definitions — neither of those features exists on indicators or studies.

Use relative ESM (./helpers.js) for local modules, and imports.use / imports.subscribe only for cross-definition event wiring. Snapshots freeze the whole package.

Multi-file package rules

  • Relative ESM only: import { x } from "./helpers.js"

  • One entry file exports onBar

  • meta() runs in the entry only

  • Helpers may call events.declare / outputs.declare; they must not export onBar

  • Forbidden: bare package names, require, dynamic import(), top-level await, exported let/var, .cjs

  • Cycles are rejected; unreachable files can exist in the editor but do not affect the manifest

Entry sketch

// main.js (entry)
import { classify } from "./classify.js";

meta({ name: "London", kind: "flow", slug: "london" });
events.declare({
  id: "classified",
  intent: "Regime",
  payload: { regime: { type: "string", description: "Regime" } },
  paint: "pin",
});

export function onBar(ctx) {
  const regime = classify(ctx);
  if (!regime) return;
  ctx.emit("classified", { regime }, { label: `Regime: ${regime}`, price: ctx.close });
}
// classify.js
export function classify(ctx) {
  if (ctx.close > ctx.open) return "up";
  if (ctx.close < ctx.open) return "down";
  return null;
}

Snapshots freeze the whole package — edit, then snapshot again before Collect.

imports.use / subscribe

imports.use({
  /* ImportDecl — alias + upstream flow / event contract — see IntelliSense */
});

imports.subscribe("upstream", "event_id", (payload) => {
  // handle imported event payload
});

Drawing / deps still shared

outputs.declare and indicators.declare work the same as documented in Drawing on the chart and Declaring indicator dependencies — including inside helper modules.

Agent note

Flow authoring uses get_flow_files (live unsaved draft) and propose_flow_edit with patches. Lint merges patches over the draft.

Next

  1. Definition API overview

  2. Flow authoring agent