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
21 changes: 21 additions & 0 deletions .agents/skills/boot-triage/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2026 Jake Schincariol

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
142 changes: 142 additions & 0 deletions .agents/skills/boot-triage/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
---
name: boot-triage
description: >-
Run the title under a hard timeout, keep its log outside the checkout, call the run PASS, HANG, CRASH or
EXIT, and turn the log and crashes.log into a ranked list of what stopped it: the crash report, the
unimplemented import that trapped, D3D12.X methods that are not implemented, and GPU failures. Compares a
run with the one before it. Use when the user says "run it", "does it boot", "why did it crash", "what do
I fix next", "did that break anything", or after a change to the loader, leonida-hle or leonida-gpu.
---

# Boot triage

Every fix ends the same way: build, run, read the log, decide. This skill keeps that loop short and the
same every time. The method comes from the tester skill of
[Jakeschincariol/console-skill](https://github.com/Jakeschincariol/console-skill) (MIT, see
[LICENSE](LICENSE)), rewritten for this repository. Read [CLAUDE.md](../../../CLAUDE.md) first.

Its partner skills: [missing-imports](../missing-imports/SKILL.md) fixes what this one ranks,
[trace-import](../trace-import/SKILL.md) works out what the title expects when the log doesn't say, and
[renderdoc-gpu-debug](../renderdoc-gpu-debug/SKILL.md) takes over when it runs but the picture is wrong.

## Logs stay local

The run's log and `crashes.log` keep the title's last debug output, and crash reports name its code. They
stay on your PC, outside the checkout (the "Derived data stays outside the repository" rule), and never go
into a commit, issue or pull request. Share import names, `module+offset` addresses and counts, never the
logs.

## The state file

`%LOCALAPPDATA%\leonida\agent-state.md` is the memory between sessions, outside the checkout for the same
reason. Read it first and write back one line per run. It holds:

- the run command and the switches it was run with, copied and never rebuilt from memory;
- which build (`target\release` or `target\diag`);
- one line per run: date, what changed, verdict, run folder;
- the open stops, each with how many fixes were tried on it;
- the regression runs: the exact command and expected verdict of each milestone reached.

If it does not exist, create it. The game folder comes from `leonida.toml` (`leonida config` prints it;
`run-gta6.ps1` asks for it once).

## Without the game

The loader and HLE tests build their input with our own code, and are the first thing to run after a change
there:

```powershell
cargo test -p leonida-loader --locked
cargo test -p leonida-hle --locked
```

## One run

1. **Build.** `cargo build --profile diag -p leonida --features diagnostics` for the debugging aids
(`LEONIDA_STACKS`, `LEONIDA_WATCH`, `LEONIDA_KEYS`, debug output), or `cargo build --release -p leonida`
to check what players get. Never `cargo clean` to make sure.
2. **Bind first, without running.** `target\diag\leonida.exe run` stops after binding and prints
`bound <image>: N hle, N host, N title, N missing` with a `missing dll!symbol` line for each. A new
missing import here is cheaper to find than in a run.
3. **Run short, log to a new folder:**

```powershell
$run = Join-Path $env:LOCALAPPDATA "leonida\runs\$(Get-Date -Format yyyyMMdd-HHmmss)"
New-Item -ItemType Directory -Force $run | Out-Null
$env:LEONIDA_LOG = 'info'
$p = Start-Process target\diag\leonida.exe -PassThru -NoNewWindow -ArgumentList 'run', '--execute' `
-RedirectStandardError "$run\stderr.log" -RedirectStandardOutput "$run\stdout.log"
$null = $p.Handle
if ($p.WaitForExit(120000)) { "exit $($p.ExitCode)" } else { taskkill /pid $p.Id /t /f | Out-Null; 'timeout' }
```

Two minutes covers the loader, the intro and the menus; raise it only when chasing a later milestone,
and set `LEONIDA_KEYS` (diag build) to get through the menus unattended. `$p.Handle` is read so
PowerShell keeps the exit code. `taskkill /t` ends the whole process tree, so no game window is left.
4. **Give the verdict** (table below).
5. **Read only what matters**, not the whole log:

```powershell
Get-Content "$run\stdout.log" -Tail 20
Select-String -Path "$run\stderr.log" -Pattern 'ERROR|unimplemented import|not implemented|panicked' |
Select-Object -First 40
Get-Content (Join-Path $env:LOCALAPPDATA 'leonida\data\*\crashes.log') -Tail 80
```

`crashes.log` is appended to by every build, in the title's folder under `%LOCALAPPDATA%\leonida\data`;
take the entries with this run's time.
6. **Rank** (next section) and work the top item.
7. **Record** the line in the state file.

## Verdicts

| Verdict | When |
|---|---|
| PASS | the milestone being chased was reached (a log line, a picture, play) and nothing crashed before the timeout |
| HANG | the timeout came first and the milestone did not. `LEONIDA_STACKS=60,90` (diag) shows what every thread was waiting on |
| CRASH | a crash report in `crashes.log` for this run, an unimplemented import that trapped, a host GPU failure, or a negative exit code |
| EXIT | `title exited with <code>` before the milestone |

## Ranking

The first thing that went wrong usually caused the rest. In this order:

1. **An unimplemented import that trapped.** With the default `--unimplemented trap` the run logs it,
writes `Leonida Legacy: unimplemented import dll!symbol called` to `crashes.log`, and aborts. That
import is the stop: [missing-imports](../missing-imports/SKILL.md).
2. **The crash report.** The faulting address as `module+offset`, the frames and the title's last lines of
debug output, which often say what it checked (`crates/leonida-loader/src/crash.rs`). A breakpoint is
usually the title's own assertion. Inside our code: a bug of ours. Inside the title's code with nothing
missing before it: [trace-import](../trace-import/SKILL.md), starting from that address.
3. **Host GPU failures** in `crashes.log` (device removed, a pipeline the driver refused).
`LEONIDA_D3D12_DRED=1` names the allocation and the commands in flight; `docs/fork-notes.md` lists the
other GPU switches.
4. **`method not implemented`** warnings (`crates/leonida-gpu/src/object.rs`): the object, the slot and the
caller. The method answered `E_NOTIMPL`, and the title may have gone on without it.
5. **Imports that returned 0** under `--unimplemented zero`: each is logged once. Use `zero` only to see how
far the title gets past a trap, never as the fix.

## Comparing two runs

After a fix, set this run's ranked list next to the one before:

- The stop is gone: progress. Update the state file.
- A new stop after the old one: usually progress too, the title got further.
- A new stop earlier than the old one: the change broke something. Look at it before the next fix.

After any change to the loader, `leonida-hle` or `leonida-gpu`, run every regression run in the state
file. A milestone that passed before and fails now is the first thing to fix.

## Three strikes

Three fixes on the same stop that did not move it: stop guessing. Reread the state file and
`docs/fork-notes.md`, trace the address with [trace-import](../trace-import/SKILL.md), and if it is still
unclear, ask the user one specific question.

## Do not

- leave a process running: one run at a time, ended at the timeout;
- make a stop pass silently to get further: an approximation gets a `shortcut:` marker, a risky behaviour a
`LEONIDA_*` switch that is off by default;
- clean the build or change a test to make a run pass;
- post a log, `crashes.log`, a `LEONIDA_CRASH_SAVE` file or a screenshot of the title anywhere.
21 changes: 21 additions & 0 deletions .agents/skills/missing-imports/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2026 Jake Schincariol

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
88 changes: 88 additions & 0 deletions .agents/skills/missing-imports/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
name: missing-imports
description: >-
Turn the imports and D3D12.X methods the title needs but Leonida Legacy does not implement into a ranked
list of fixes, each with the file it belongs in: an hle_export! in a leonida-hle module, a new module, a
method of a leonida-gpu object, or a console path. Reads leonida census, the bind report of leonida run and
the run's log. Use when the user says "unimplemented import", "missing import", "what does the game still
need", "method not implemented", "E_NOTIMPL", or after boot-triage ranks a missing import as the stop.
---

# Missing imports

The title's code runs unchanged; everything it expects from the console (the system DLLs, the GDK runtime,
the D3D12.X device) has to come from us. Every missing piece shows up as an import with no implementation,
a method that answers `E_NOTIMPL`, or a call that fails. This skill ranks them and says where each fix goes.
The method comes from the backend skill of
[Jakeschincariol/console-skill](https://github.com/Jakeschincariol/console-skill) (MIT, see
[LICENSE](LICENSE)), rewritten for this repository. Read [CLAUDE.md](../../../CLAUDE.md) first.

It reads; it does not write the code for you. Some fixes are one line in a table, others a whole area.

## What the title needs, before running it

None of these run title code.

```powershell
target\release\leonida.exe census --missing # every missing dll!function, most used first
target\release\leonida.exe census --strict --missing # the same, host pass-through not counted as covered
target\release\leonida.exe run # bind only: "bound ...: N hle, N host, N title, N missing"
target\release\leonida.exe inspect <image> --imports # one image's imports
```

`census` with no paths reads the configured game folder. Its table has one row per DLL: functions
imported, served by us (`hle`), passed to the host, missing.

Rank by:

1. the import that trapped in the last run (`--unimplemented trap`, the default, aborts at the first call;
[boot-triage](../boot-triage/SKILL.md) finds it in `crashes.log`);
2. imports that returned 0 during a run with `--unimplemented zero` (each is logged once), in the order
they were called;
3. `method not implemented` warnings from `crates/leonida-gpu/src/object.rs`: object, slot, caller;
4. the rest of `census --missing`, by number of images using them.

## Where each fix goes

| What is missing | Where the fix goes |
|---|---|
| an export of a DLL a module already serves | an `extern "system"` function named exactly like the import, listed with `hle_export!` in that module's `module()`, as `crates/leonida-hle/src/modules/xmem.rs` does |
| a DLL no module serves | a new file in `crates/leonida-hle/src/modules/`, declared in `mod.rs` and pushed in `all()`; its `dlls` list may end a name with `*` to cover versioned API sets (`crates/leonida-hle/src/registry.rs`) |
| a D3D12.X method that answers `E_NOTIMPL` | the object's table in `crates/leonida-gpu/src/` (`object.rs` names the kind and the slot); device methods and pipeline creation are in `device.rs` |
| a file the title cannot open | `crates/leonida-hle/src/modules/files.rs`: the package is mounted as `G:` and temporary files as `T:` (`apps/leonida/src/run.rs`) |
| an import that should go to the PC's own DLL | the host pass-through; `leonida run --strict` turns it off to check what still depends on it |

A new function comes with a test that needs no game, in the module's own `#[cfg(test)]` block as
`xmem.rs` has, or under `crates/leonida-hle/tests/`.

## The method

1. **Read the state file** (`%LOCALAPPDATA%\leonida\agent-state.md`, see
[boot-triage](../boot-triage/SKILL.md)): the run command, the open stops, the fixes already tried.
2. **Rank** with the commands above and the latest run's log.
3. **Find out what the function has to do before writing it.** Its public reference page gives the
signature; the title's call sites give the arguments it passes and what it does with the result
([trace-import](../trace-import/SKILL.md)). Read `docs/fork-notes.md` too: much is measured there.
Quote where each fact comes from, or call it a guess.
4. **Write the smallest real implementation.** Returning success with the outputs unset is the bug the
`trap` default exists to catch; return a documented failure the title handles rather than a success it
cannot use. Code that approximates the console gets a `shortcut:` comment; a behaviour that might break
a picture or lose the device goes behind a `LEONIDA_*` switch, off by default, noted in
`docs/fork-notes.md`. Every new `unsafe` block gets a `// SAFETY:` comment.
5. **Test without the game:** `cargo test -p leonida-hle --locked` (or the crate you changed), then
`cargo clippy --workspace --all-targets --locked -- -D warnings` and compare with `main`: no new warning.
6. **Run again with [boot-triage](../boot-triage/SKILL.md)** and compare with the run before. Fixed:
update the state file. Same stop after the fix: count a strike; at three, stop guessing.
7. **Write it down** in `docs/fork-notes.md` when something was measured, with how.

Before writing code, say in one paragraph what will change, why it fixes the cause, what it could break,
and whether that comes from reading the code or from memory.

## Do not

- make an import succeed silently to get past it, or switch a run to `--unimplemented zero` and call that
a fix;
- add a network call: the title must not reach the network (`crates/leonida-hle/src/modules/net.rs`);
- touch keys, licensing or protection: if a call turns out to need one, write that down and stop;
- quote the title's bytes, strings or disassembly in code, comments, tests or pull requests. Import names
and `module+offset` addresses are fine.
21 changes: 21 additions & 0 deletions .agents/skills/renderdoc-gpu-debug/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 Alexey Medvedev

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading
Loading