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
47 changes: 6 additions & 41 deletions contract/CONTRACT.md
Original file line number Diff line number Diff line change
Expand Up @@ -349,50 +349,13 @@ incl. Pyfa's mass / capacity / volume / radius attributes), `effects` [{id, name
(Pyfa Traits tab HTML), `required_skills` {skill id: level} (cases `type_*`; MKT-003, ENG-SHIP-006, CHR-008; a
case's `_fields` param lists the fields it scores).

## `compute` (unified entry, `exfa/compute@1`)

One input object produces one output object; the engine stays workspace/group-agnostic and only sees fully
resolved fits (no host-side `fit_id` / `character_id` references). Available as the `compute` RPC method
(`params` = the request envelope), the `exfa compute [FILE]` CLI (file or stdin → one JSON line on stdout,
exit 2 on an error envelope), and `exfa_core::compute_json` / `exfa_core::compute::compute` (WASM gets the RPC
method for free).

```jsonc
// request
{"format": "exfa/compute@1", "operation": "calc", "fit": { /* FitSpec */ }}
{"format": "exfa/compute@1", "operation": "batch", "batch": { /* BatchSpec */ }}
// response
{"format": "exfa/compute-result@1", "operation": "calc", "result": { /* FitStats */ }}
{"format": "exfa/compute-result@1", "operation": "batch", "result": { /* BatchResponse */ }}
{"format": "exfa/compute-result@1", "operation": "calc", "error": {"code": "...", "message": "...", "path": "..."}}
```

- A missing or non-`"exfa/compute@1"` `format` → `UNSUPPORTED_FORMAT`; a missing or non-`"calc"`/`"batch"`
`operation` → `BAD_REQUEST`; inner calc/batch failures keep their `code`/`message`/`path` inside the error
envelope. A top-level JSON parse failure still answers with the error envelope (`BAD_JSON`; `operation`
echoed when recoverable from the raw text, else `"calc"`). `compute_json` never panics.
- `batch` is exactly the docs/23 BatchRequest (`batch_version`, exactly one of `fits`/`variants`/`product`/
`sweep`, `fields`, `deltas`, `delta_ref`, `filter`, `sort_by`, `top_n`, `max_combinations`, price layers);
expansion, per-item errors and the `fits[]` item `id`/`label` echo behave as before.

**FitSpec = FitRequest + stable ids + shorthand normalization.**
## Item ids and `select`

- `modules[]`, `drones[]` and `fighters[]` entries take an optional string `id` (a stable caller-chosen id;
ignored everywhere except `select`, below).
- Shorthand defaults (applied by the `compute` entry point only — `calc`/`batch`/`graph` keep the existing
FitRequest defaults; explicit values always win, so `default_level: 0` stays 0):
- `character.skills.default_level` omitted → `5` (an omitted `character` is the same);
- `modules[].state` omitted → `"active"` when the type can be activated (has an active or target effect and
`activationBlocked` ≤ 0 — the `type` RPC `allowed_states` rule), else `"online"`; an unknown type is left
alone so the usual error reports it;
- `drones[].active` omitted → `quantity` (every drone active); `fighters[].active` already defaults true;
- everything else uses the existing FitRequest defaults at build time.
- Normalization recurses into every nested FitRequest (`projected[kind=fit].fit`, `fleet.booster_fits[]`,
`scenarios[].target.fit`). Under `operation=calc` each defaulted category is reported once as an
`adjustments[]` entry `{"code": "DEFAULTED", "path": "/character/skills/default_level" | "/modules/*/state" |
"/drones/*/active", "from": null, "to": <value | list of applied values>, "message": "compute shorthand
default applied"}` (top-level fit only). Under `operation=batch` the `base` and each `fits[].fit` are
normalized silently *before* expansion, so patches act on a fully normalized base.
- The engine applies no input shorthand: an omitted `character.skills.default_level` is 0, an omitted module
`state` is `online`. Defaults, groups and other host-side conveniences are the caller's (EXFA Format)
concern; the engine only ever sees fully resolved fits.

**`select` on `projected[kind=fit]`** chooses which of the source fit's items project onto this fit:

Expand Down Expand Up @@ -470,3 +433,5 @@ method for free).
FIGHTER_TUBES for resource-bar overloads (Pyfa shows these as red bars, not fit problems).
- v1.5.0: add top-level `adjustments[]` for silent request normalization and optional `scenarios[]` /
`scenario_results[]` for fixed-target effective damage; scenario failures are isolated per result.
- 2026-11-08: the `exfa/compute@1` envelope, the `compute` RPC method and the `exfa compute` CLI command are
removed (they only added shorthand defaults, now the caller's job). `select` and item `id`s are unchanged.
12 changes: 1 addition & 11 deletions crates/exfa-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ const USAGE: &str = "exfa <command> [args] (dataset compiled in; --dataset PAT

Commands:
calc [FILE] FitRequest JSON (file or stdin) -> FitStats JSON
compute [FILE] exfa/compute@1 envelope (file or stdin) -> one exfa/compute-result@1 JSON line
batch JSONL FitRequests on stdin -> JSONL FitStats on stdout (a BatchRequest line -> one BatchResponse line)
batch --request FILE|- BatchRequest JSON (docs/23: fits / variants / product / sweep) -> BatchResponse JSON
optimize [FILE] OptimizeRequest JSON (docs/21) -> ranked fits
serve-stdio JSONL RPC: {\"id\":..,\"method\":\"calc|batch|compute|prices_load|version|sde_override|optimize|graph|search|type|meta|eft_parse|eft_export|format_import|format_export|fits.backup|item.variations|item.compare|market.group|market.search|implant_sets.list|character.import_evemon|names.resolve|pyfa_data_load|pyfa_data_status\",\"params\":..}
serve-stdio JSONL RPC: {\"id\":..,\"method\":\"calc|batch|prices_load|version|sde_override|optimize|graph|search|type|meta|eft_parse|eft_export|format_import|format_export|fits.backup|item.variations|item.compare|market.group|market.search|implant_sets.list|character.import_evemon|names.resolve|pyfa_data_load|pyfa_data_status\",\"params\":..}
eft [FILE] EFT text (file or stdin) -> FitRequest JSON (add --calc to compute, --skills N)
search QUERY [--limit N] [--kinds ship,module,..] search types by name (exact > prefix > substring)
type ID|NAME show type with base attributes
Expand Down Expand Up @@ -120,15 +119,6 @@ fn main() {
std::process::exit(2);
}
}
"compute" => {
let s = read_input(args.get(1));
let res = exfa_core::compute_json(&s);
writeln!(out, "{res}").or_pipe();
out.flush().or_pipe();
if serde_json::from_str::<serde_json::Value>(&res).ok().and_then(|v| v.get("error").cloned()).is_some() {
std::process::exit(2);
}
}
"batch" => {
if let Some(f) = take_flag(&mut args, "--request") {
let res = exfa_core::batch_json(&read_input(Some(&f)));
Expand Down
212 changes: 0 additions & 212 deletions crates/exfa-core/src/compute.rs

This file was deleted.

4 changes: 2 additions & 2 deletions crates/exfa-core/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ pub struct Item {
pub distance: Option<f64>,
/// mutated (rolled) attributes: request overrides do not replace them (Pyfa reads mutators after overrides)
pub rolled: Vec<u16>,
/// stable caller-chosen id (FitSpec `id` on modules/drones/fighters; projected-fit `select` refers to it)
/// stable caller-chosen id (`id` on modules/drones/fighters; projected-fit `select` refers to it)
pub id: Option<String>,
}

Expand Down Expand Up @@ -1509,7 +1509,7 @@ impl Fit {
}
}
for (sf, amount, dist, select) in &self.ext {
// `select` = explicit whitelist of source items by their FitSpec id: a kind whose list is absent
// `select` = explicit whitelist of source items by their `id`: a kind whose list is absent
// contributes nothing, a present list contributes only its active items whose id is in it. The
// source fit itself was built completely, so unselected items still shape the source's attributes.
let mut unmatched: Vec<(&'static str, &str)> = Vec::new();
Expand Down
8 changes: 0 additions & 8 deletions crates/exfa-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//! The SDE dataset is compiled into this crate by `build.rs`: the `sde` static tables plus the generated
//! Rust code for every effect's modifiers. `calc(request) -> stats` is pure: no I/O, no clocks, no global state, no data loading.
pub mod capsim;
pub mod compute;
pub mod model;
pub mod sde;
pub mod data;
Expand Down Expand Up @@ -243,12 +242,6 @@ pub fn batch_json(s: &str) -> String {
batch::run_json(s)
}

/// Unified compute envelope `exfa/compute@1` (docs/27 §5.3): JSON string in, one
/// `exfa/compute-result@1` JSON line out; never panics (any failure is the error envelope).
pub fn compute_json(input: &str) -> String {
compute::compute_json(input)
}

/// JSONL RPC line: {"id","method","params"} -> {"id","result"}
pub fn rpc(line: &str) -> Value {
let v: Value = match serde_json::from_str(line) {
Expand All @@ -264,7 +257,6 @@ pub fn rpc(line: &str) -> Value {
Err(e) => json!({"error": {"code": "BAD_REQUEST", "message": e.to_string()}}),
},
"batch" | "calc_batch" => batch::run(&p),
"compute" => compute::compute(&p),
"prices_load" => prices_load(&p),
"version" => prov::version(),
"sde_override" => prov::sde_override(&p),
Expand Down
8 changes: 4 additions & 4 deletions crates/exfa-core/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub struct Mutation {
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct ModuleReq {
pub type_id: u32,
/// Stable caller-chosen id (exfa/compute@1 FitSpec): `projected[kind=fit].select.module_ids` refers to it.
/// Stable caller-chosen id: `projected[kind=fit].select.module_ids` refers to it.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
#[serde(default)]
Expand All @@ -71,7 +71,7 @@ pub struct ModuleReq {
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct DroneReq {
pub type_id: u32,
/// Stable caller-chosen id (FitSpec): `projected[kind=fit].select.drone_ids` refers to it.
/// Stable caller-chosen id: `projected[kind=fit].select.drone_ids` refers to it.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
#[serde(default = "one")]
Expand All @@ -88,7 +88,7 @@ fn one() -> u32 {
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct FighterReq {
pub type_id: u32,
/// Stable caller-chosen id (FitSpec): `projected[kind=fit].select.fighter_ids` refers to it.
/// Stable caller-chosen id: `projected[kind=fit].select.fighter_ids` refers to it.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
#[serde(default)]
Expand Down Expand Up @@ -153,7 +153,7 @@ pub struct Fleet {
pub booster_fits: Vec<FitRequest>,
}

/// Whitelist of source items a `projected[kind=fit]` entry projects (FitSpec): present = explicit selection,
/// Whitelist of source items a `projected[kind=fit]` entry projects: present = explicit selection,
/// so a kind whose id list is absent contributes nothing. The source fit is still computed in full.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct Select {
Expand Down
Loading
Loading