Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -432,11 +432,17 @@ happy-path LLM loop.

Not yet done, roughly in priority order:

- [x] Add self-buffs to calc
- [ ] Add self-buffs to scoring
- [ ] Include skill usage/damage in calc and scoring
- [ ] Vector search over saved trajectories' reasoning text. Today's `get_similar_past_builds` uses class+scenario
lookup.
- [ ] Add RAG with injecting get_similar_past_builds into initial system prompt
- [ ] Postgres migration for the build library. SQLite pins the API to `replicas: 1` and `strategy: Recreate`; HPA / PDB
are excluded from the Helm chart until this lands.
- [ ] General prompt tuning - less tokens, more progress.
- [ ] More server profiles beyond UARO. Drop a YAML, no code change.
- [ ] More golden fixtures beyond Taekwon Kid. The shim handles all 45 supported classes already
- [ ] Golden fixtures for Full Support builds
- [ ] Renewal mode end-to-end. The API rejects `mode: "renewal"` at the boundary today; the data layer is already
mode-aware. The calc adapter hasn't been validated for renewal.
- [ ] Rotation simulator with SP economy. Today's scoring uses single-skill DPS + sustained auto-attack as a proxy.
Expand All @@ -445,8 +451,8 @@ Not yet done, roughly in priority order:
- [ ] Real time-to-level scoring at leveling checkpoints. Currently the leveling target is attached as a proxy for "can
you farm here"
- [ ] Genetic / beam-search optimizer over gear combinations. Today the LLM proposes; deterministic scoring ranks.
- [ ] Vector search over saved trajectories' reasoning text. Today's `get_similar_past_builds` uses class+scenario
lookup.
- [ ] Custom dungeons (containers) in `ServerProfile`. Custom mobs are wired; containers are not.
- [ ] Model custom skill changes from server profile into calc
- [ ] Model custom equipment changes from server profile into calc

Bug reports, missing card effects, server-profile additions, and additional calc backends are all welcome via PR.
2 changes: 1 addition & 1 deletion api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ components:
combat: { $ref: "#/components/schemas/CombatResults" }
calc_version:
type: string
description: engine snapshot stamp (e.g. "rocalc-2026-04-06")
description: engine snapshot stamp (backend name + data snapshot date)

# --- /generate request + response ---

Expand Down
36 changes: 25 additions & 11 deletions calc-sidecar/src/backends/registry.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,49 @@
// Backend registry. Each backend exports createShim and CALC_VERSION
// (the ShimSession factory + version stamp); the registry table maps a
// short name to a dynamic-import factory and the env var CALC_BACKEND
// selects which one is active.
// short name to its module specifier and the env var CALC_BACKEND selects
// which one is active.
//
// Dynamic import() is load-bearing: when CALC_BACKEND=stub, the rocalc
// module is never imported and never tries to read vendor/. This is
// what lets CI run against the stub on a checkout with an empty vendor.
// Selective loading is load-bearing: when CALC_BACKEND=stub, the rocalc
// module is never loaded and never tries to read vendor/. This is what lets
// CI run against the stub on a checkout with an empty vendor.
//
// We load the selected backend with a SYNCHRONOUS require() rather than a
// dynamic import(), specifically so this module, and therefore a worker
// thread's entire module graph, contains NO top-level await. A worker whose
// module graph is async can abort the process with a V8 fatal ("Check failed:
// (location_) != nullptr", in AsyncModuleExecutionFulfilled) when it is
// terminated, or calls process.exit(), while that async graph is still
// evaluating. Those are unfixed, TLA-specific upstream Node bugs
// (nodejs/node#53238, #43182). ShimPool spawns short-lived workers and
// terminates them eagerly, so the window was hit intermittently, only under
// the fast stub backend, where one pool's teardown overlaps the next pool's
// spawn. require() keeps the selective-load property AND keeps createShim
// synchronous, while making this module's evaluation fully synchronous.
//
// Adding a backend: drop a dir under ./<name>/, export createShim and
// CALC_VERSION, add one entry to BACKENDS below.

import { createRequire } from "node:module";
import type { ShimSession } from "../types.ts";

type BackendModule = {
createShim: () => ShimSession;
CALC_VERSION: string;
};

const BACKENDS: Record<string, () => Promise<BackendModule>> = {
rocalc: () => import("./rocalc/index.ts"),
stub: () => import("./stub/index.ts"),
const BACKENDS: Record<string, string> = {
rocalc: "./rocalc/index.ts",
stub: "./stub/index.ts",
};

const name = process.env.CALC_BACKEND ?? "rocalc";
const factory = BACKENDS[name];
if (!factory) {
const spec = BACKENDS[name];
if (!spec) {
throw new Error(
`unknown CALC_BACKEND: ${name} (valid: ${Object.keys(BACKENDS).join(", ")})`,
);
}

const backend = await factory();
const backend = createRequire(import.meta.url)(spec) as BackendModule;
export const createShim = backend.createShim;
export const CALC_VERSION = backend.CALC_VERSION;
8 changes: 8 additions & 0 deletions calc-sidecar/src/backends/rocalc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1854,13 +1854,21 @@ export function createShim(): ShimSession {
win.calc();
}

// supportedBuffs (ShimSession contract): the buff names this backend can
// bind, independent of class. The shim-contract parity test asserts the Go
// overlay is a subset of this, so it never reaches into BUFF_BINDINGS itself.
function supportedBuffs(): readonly string[] {
return Object.keys(BUFF_BINDINGS);
}

const session: ShimSession = {
setStats,
setLevel,
setClass,
equip,
setSkills,
setBuffs,
supportedBuffs,
setEnemy,
setEnemyInline,
readDerivedStats,
Expand Down
5 changes: 5 additions & 0 deletions calc-sidecar/src/backends/stub/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ export function createShim(): ShimSession {
setBuffs(_buffs: Buff[]): void {
// stub: deterministic fiction, buffs don't alter output
},
supportedBuffs(): readonly string[] | null {
// The stub accepts any buff name (no enforcement), so buff-binding parity
// is vacuous for it; null signals "not enforced" to callers.
return null;
},
setEnemy(id) {
state.enemy = id;
state.enemyInline = null;
Expand Down
8 changes: 8 additions & 0 deletions calc-sidecar/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ export interface ShimSession {
* setSkills/equip and before any read. */
setBuffs(buffs: Buff[]): void;

/** The set of self-buff names this backend recognizes (has a binding for),
* independent of the active class. The shim-contract parity test uses this to
* assert every declarable buff (the Go-side catalog overlay) is bindable,
* without reaching into backend internals. Returns null for backends that do
* not enforce buff names -- they accept any name, so the parity check is
* vacuous for them (e.g. the stub). */
supportedBuffs(): readonly string[] | null;

/** Set the combat-sim target. mobId is engine-specific (rocalc currently
* uses its m_Monster index; a mob iRO mapping pass will let this take iRO
* mob ids the same way equip does for items). */
Expand Down
57 changes: 57 additions & 0 deletions calc-sidecar/test/shim/buff-binding-parity.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import { join } from "node:path";
import { createShim } from "../../src/shim.ts";

// Parity guard: every self-buff the Go side can declare (the catalog overlays)
// must have a binding in the active calc backend, else the buff silently does
// nothing and surfaces only at score time. This references ONLY the shim
// contract (ShimSession.supportedBuffs) -- never a backend's internal binding
// table -- so it stays correct across backends. Backends that do not enforce
// buff names (supportedBuffs() === null, e.g. the stub) make the check vacuous.

// The overlays live in the Go catalog tree; they are the shared source of truth
// for buff names across the Go/sidecar boundary. class_innate_buffs.yaml carries
// class-mechanic buffs (e.g. Super Novice no_death_bonus) that also flow through
// setBuffs and therefore need a binding too.
const OVERLAY_DIR = join(import.meta.dirname, "../../../internal/catalog/data");
const OVERLAYS = ["skill_buffs.yaml", "class_innate_buffs.yaml"];

// Buff names are the lowercase_snake value of a `name:` key inside a self_buff
// or class-innate entry. Scanned without a YAML-parser dependency: per line,
// drop any `#` comment, then match `name:`. The leading [\s{,] excludes
// `aegis_name:` (the char before "name:" there is "_"), and the lowercase-only
// value class excludes the uppercase aegis names.
function overlayBuffNames(): string[] {
const names = new Set<string>();
for (const file of OVERLAYS) {
const text = readFileSync(join(OVERLAY_DIR, file), "utf8");
for (const raw of text.split("\n")) {
const hash = raw.indexOf("#");
const line = hash === -1 ? raw : raw.slice(0, hash);
const m = line.match(/[\s{,]name:\s*([a-z][a-z0-9_]*)/);
if (m) names.add(m[1]);
}
}
return [...names];
}

test("every overlay buff name has a binding in the active backend", () => {
const names = overlayBuffNames();
assert.ok(
names.length > 0,
"overlay scan found no buff names; check the regex/paths",
);

const supported = createShim().supportedBuffs();
if (supported === null) return; // backend does not enforce buff names (stub)

const supportedSet = new Set(supported);
const missing = names.filter((n) => !supportedSet.has(n));
assert.deepEqual(
missing,
[],
`overlay buff(s) with no binding in the active backend: ${missing.join(", ")}`,
);
});
1 change: 1 addition & 0 deletions calc-sidecar/test/shim/contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ test("createShim returns an object with all required methods", () => {
"equip",
"setSkills",
"setBuffs",
"supportedBuffs",
"setEnemy",
"setEnemyInline",
"readDerivedStats",
Expand Down
8 changes: 4 additions & 4 deletions cmd/build-catalog/main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// build-catalog is a run-only refresh tool, not a deployable binary. It
// reads emulator data and writes a single catalog.json that the runtime
// API embeds into its binary at compile time. Source is selectable:
// Hercules (default) or rAthena. Same pattern as build-rocalc-mapping
// → mapping.json.
// Hercules (default) or rAthena. Same run-only-refresh pattern as the other
// one-shot data tools.
//
// Invoke via `go run ./cmd/build-catalog` (or `task catalog`); this
// tool intentionally has no `task build:catalog` target. Running it
Expand Down Expand Up @@ -148,7 +148,7 @@ func main() {

// Layer the hand-authored self-buff overlay onto skill records. Lives at
// internal/catalog/data/skill_buffs.yaml; see that file's comment block for
// the editing rules and the spec reference.
// the editing rules.
skillBuffsAbs := resolvePath(repoRoot, skillBuffsPath)
skillBuffs, err := loadSkillBuffs(skillBuffsAbs)
if err != nil {
Expand Down Expand Up @@ -747,7 +747,7 @@ func loadJobMaxLevels(herculesPath, repoRoot string) ([]data.JobMaxLevels, error
// allocated (inherited) for a class but which the class cannot actually USE. A
// Soul Linker / Star Gladiator was a TaeKwon Kid, so the flattened tree carries
// every TK skill, but only a usable subset remains. Taekwon Ranker (TK_MISSION)
// is TaeKwon-Kid-only (rocalc models it solely in m_JobBuff[41]); without this it
// is TaeKwon-Kid-only (the calc engine applies it only for TaeKwon Kid); without this it
// would wrongly surface as a self-buff for both 2nd classes. Keyed by shim-style
// class name -> set of aegis names to drop.
var usabilityExclusions = map[string]map[string]bool{
Expand Down
Loading
Loading