Skip to content

Commit 76c7bd0

Browse files
committed
refactor: rebuild scene graph
1 parent 90f6793 commit 76c7bd0

495 files changed

Lines changed: 42116 additions & 35449 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.cargo/config.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
[env]
2-
# refer: https://stackoverflow.com/questions/43577885/is-there-a-cargo-environment-variable-for-the-workspace-directory
3-
CARGO_WORKSPACE_DIR = { value = "", relative = true }
4-
WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS = { value = "--remote-debugging-port=0", force = false }
2+
WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS = { value = "--remote-debugging-port=4000", force = false }

.github/labeler.yml

Lines changed: 0 additions & 72 deletions
This file was deleted.

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ jobs:
5757
- run: bun install
5858
- uses: actions/cache@v6
5959
with:
60-
path: ${{ github.workspace }}/ui/.next/cache
61-
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/bun.lock') }}-${{ hashFiles('ui/**/*.js', 'ui/**/*.jsx', 'ui/**/*.ts', 'ui/**/*.tsx') }}
60+
path: ${{ github.workspace }}/packages/koharu/.next/cache
61+
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/bun.lock') }}-${{ hashFiles('packages/**/*.js', 'packages/**/*.jsx', 'packages/**/*.ts', 'packages/**/*.tsx') }}
6262
restore-keys: |
6363
${{ runner.os }}-nextjs-${{ hashFiles('**/bun.lock') }}-
6464
- run: bun tauri build --no-bundle

.github/workflows/labeler.yml

Lines changed: 0 additions & 20 deletions
This file was deleted.

.github/workflows/publish.yml

Lines changed: 0 additions & 30 deletions
This file was deleted.

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,4 @@ jobs:
6666
key: ${{ runner.os }}-bun-${{ hashFiles('**/bun.lock') }}
6767
- run: bun install --frozen-lockfile
6868
- name: Run headless Vitest suite
69-
run: bun run --filter ui test
69+
run: bun run --filter @koharu/app test

.oxfmtrc.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"$schema": "./node_modules/oxfmt/configuration_schema.json",
3-
"ignorePatterns": ["ui/lib/koharu/protocol.ts"],
3+
"ignorePatterns": ["packages/koharu/lib/protocol.ts"],
44
"semi": false,
55
"singleQuote": true,
66
"jsxSingleQuote": true,
77
"sortImports": {
8-
"internalPattern": ["@/"],
8+
"internalPattern": ["@/", "@koharu/"],
99
"newlinesBetween": true,
1010
"groups": [
1111
"builtin",
@@ -17,7 +17,7 @@
1717
]
1818
},
1919
"sortTailwindcss": {
20-
"stylesheet": "ui/app/globals.css",
20+
"stylesheet": "packages/ui/src/styles/globals.css",
2121
"functions": ["cn", "clsx", "cva", "tw"]
2222
}
2323
}

.vscode/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
22
"tailwindCSS.lint.suggestCanonicalClasses": "ignore",
3-
"git.addAICoAuthor": "off"
3+
"git.addAICoAuthor": "off",
4+
"json.schemaDownload.trustedDomains": {
5+
"https://ui.shadcn.com/schema.json": true
6+
}
47
}

AGENTS.md

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,62 @@
11
# Koharu Project Rules
22

3-
Document only repository-specific constraints here. Normal Rust, TypeScript, testing, formatting, and Git practices are assumed.
3+
Document only durable, repository-specific constraints here. Do not record current file layouts, temporary paths, model inventories, helper names, or other implementation details that may change during a refactor. Normal Rust, TypeScript, testing, formatting, and Git practices are assumed.
44

5-
## Source Boundaries
5+
## Change Policy
66

7-
- `temp/` contains read-only upstream checkouts used to port and compare implementations. Never modify or commit it.
8-
- `data/`, `models/`, and `runs/` are local inputs, weights, and outputs. Never commit them.
9-
- Public safe wrappers belong in `koharu-llama`, `koharu-diffusion`, and `koharu-torch`. Raw handles, dynamic loading, build logic, and `unsafe` FFI belong in the matching `*-sys` crate.
7+
- Never add backward compatibility. When an API, schema, configuration, or ownership boundary changes, update every in-repository consumer and remove the replaced form.
8+
- Prefer a coherent ownership redesign over aliases, forwarding layers, compatibility parsers, or cosmetic renaming.
9+
- Keep responsibilities self-contained. Defaults and provider-specific behavior belong to the component that owns them rather than a central list of special cases.
10+
- Remove dead abstractions and one-use helpers when direct code is clearer.
1011

11-
## Generated Code
12+
## Source Boundaries
1213

13-
The following are also generated or derived and should be changed through their generator or authoritative input:
14+
- Keep safe public APIs separate from unsafe FFI, dynamic loading, and build integration.
15+
- Do not hand-edit generated or derived source. Change its authoritative input and run the generator.
16+
- Do not commit credentials, model weights, datasets, generated outputs, or machine-specific artifacts.
1417

15-
- `crates/koharu-torch/src/wrappers/*generated.rs`
16-
- `crates/koharu-torch-sys/libtch/torch_api_generated.{h,cpp}`
17-
- bindings emitted by `crates/koharu-bindgen` from `*-sys/build.rs`
18+
## ML Architecture
1819

19-
## ML Model Interface
20+
- Keep a consistent public lifecycle across models while allowing model-specific inputs and outputs.
21+
- Separate network ownership and weight loading from preprocessing, postprocessing, slicing, and public result types.
22+
- Avoid pass-through types and layers that do not own a real responsibility.
23+
- Accept a device abstraction at the model boundary, convert it once, and avoid unnecessary transfers or synchronization.
24+
- Use the established runtime and variable-store loading paths unless they are proven insufficient.
25+
- Disable gradient tracking during inference.
2026

21-
Every model under `crates/koharu-ml/src` uses the same outer shape:
27+
## Upstream Alignment
2228

23-
- The public model type exposes `pub async fn load(device: crate::Device) -> Result<Self>`.
24-
- The public model type exposes `pub fn inference(...) -> Result<...>`; model-specific arguments are allowed.
25-
- A private `model::Model` owns the Torch modules and `VarStore`s and implements `new`, weight loading, and `forward`.
26-
- `processor` owns preprocessing, postprocessing, crop/slice logic, and public detection/result types.
27-
- `config` exists only when the upstream architecture is configuration-driven.
29+
- Keep ports structurally traceable to a commit-pinned authoritative implementation.
30+
- Preserve checkpoint-affecting names, construction order, parameter paths, tensor layouts, execution order, and postprocessing semantics.
31+
- Treat missing or unexpected weights as an architecture or parameter-name mismatch before changing the loader.
32+
- Explain intentional divergences next to the affected code.
33+
- Compare ports on identical inputs using structured outputs such as shapes, ranges, boxes, scores, masks, and ordering.
2834

29-
Use `Model` for the private network and `Output` for a multi-tensor forward result unless the upstream API has a meaningful, more specific name. Do not add pass-through types or helpers such as `PreparedInput`, `load_with_config`, or an extra `inpaint_model` layer. Keep one-use model sizes and crop margins inline instead of extracting constants merely to name the literal.
35+
## Performance
3036

31-
All model loaders accept `Device`, never `cpu: bool`. Convert it once to the Torch device and keep tensors there through preprocessing, forward, and postprocessing where practical. Copy to CPU only for the final caller-facing output.
37+
- Optimize and benchmark the actual target device with representative inputs.
38+
- Remove redundant transfers, synchronization, allocations, and per-pixel host loops before adding concurrency or caching.
39+
- Account for asynchronous accelerator execution when timing work.
40+
- Load assets and warm models outside measured regions.
41+
- Report the device, input size, baseline, result, and correctness difference.
3242

33-
Resolve model assets with `koharu_runtime::huggingface!`. Construct and register the complete module tree before loading weights. Load `.safetensors` and other supported formats with the model's `koharu_torch::nn::VarStore::load`; do not add a custom SafeTensors reader, tensor-copy loader, or generic checkpoint helper unless `VarStore::load` is proven unable to load the required checkpoint.
43+
## Verification
3444

35-
Run inference inside `koharu_torch::no_grad`.
45+
- Optimize for fast development and iteration. By default, run the smallest relevant check or focused test once using the debug profile.
46+
- Do not run full test suites, repeatedly rerun unchanged tests or builds, or build and test profiles other than debug unless the user explicitly requests it.
47+
- Run end-to-end tests only when the user explicitly asks for them.
3648

37-
## Upstream Alignment
49+
## Desktop UI Debugging
3850

39-
Ports must remain structurally traceable to the authoritative implementation, especially Hugging Face Transformers, IOPaint, BallonsTranslator, and comic-translate references under `temp/`.
51+
- The default Windows debugging setup must define `WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS=--remote-debugging-port=4000` before launching Koharu. Treat `http://127.0.0.1:4000` as the default local CDP endpoint.
52+
- Connect `chrome-devtools-mcp` with `--browser-url=http://127.0.0.1:4000` and prefer its tools for WebView inspection and automation. Use semantic targets and observable conditions instead of coordinate-only actions or fixed delays.
53+
- Use a lower-level CDP client only when `chrome-devtools-mcp` does not expose a required protocol operation. Use native window capture when CDP cannot observe the composited desktop output.
4054

41-
- Match upstream module, struct, field, layer, and model names where Rust permits.
42-
- Preserve module construction, parameter paths, execution order, tensor layouts, interpolation modes, padding, thresholds, crop behavior, and postprocessing semantics.
43-
- Add a commit-pinned URL to the exact upstream file or symbol above each ported module or non-obvious algorithm.
44-
- Keep checkpoint-affecting upstream quirks. Explain intentional divergences next to the code.
45-
- Treat missing or unexpected weights as a model-tree/parameter-name mismatch first, not a loader problem.
46-
- For alignment work, run both implementations on identical inputs and compare structured outputs—shapes, ranges, boxes, scores, masks, and ordering—not just rendered images.
55+
## Desktop Rendering
4756

48-
Comments in ported code should explain mapping, invariants, or deliberate divergence. Do not narrate straightforward Rust.
57+
- Koharu composites native WGPU-rendered canvas pixels beneath a transparent WebView. Preserve WebView transparency wherever native output must remain visible, keep interface rendering in the WebView and canvas rendering in WGPU, and validate their final composition through the desktop window rather than either layer alone.
4958

50-
## GPU Performance
59+
## Documentation
5160

52-
- Optimize and benchmark the actual target device. Do not use CPU timings to evaluate CUDA work.
53-
- Keep preprocessing and postprocessing on the GPU when supported; first remove redundant transfers, synchronizations, allocations, and per-pixel CPU loops.
54-
- CUDA execution is asynchronous. Benchmarks must synchronize immediately before and after the timed inference.
55-
- Load weights, decode fixtures, and warm up the model outside the measured loop.
56-
- Use representative inputs, including the checked-in 4K LaMa fixture, and report the device, input size, baseline, result, and correctness difference.
61+
- Comments should explain ownership, invariants, upstream mapping, or deliberate divergence; do not narrate straightforward code.
62+
- Keep this file focused on long-lived decision rules rather than the current implementation.

0 commit comments

Comments
 (0)