Skip to content

feat: add runtime file discovery chain#379

Open
fry69 wants to merge 3 commits into
antirez:mainfrom
fry69:fry69/feat-runtime
Open

feat: add runtime file discovery chain#379
fry69 wants to merge 3 commits into
antirez:mainfrom
fry69:fry69/feat-runtime

Conversation

@fry69

@fry69 fry69 commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

This PR adds automatic discovery for runtime files to ds4 and ds4-agent, so they can be run from anywhere without fuss.

There is also a new Makefile target install-user that installs those runtime files automatically, defensively.

This works for me on macOS, it may need polish for other platforms.

Automatically generated PR message below:


Problem

ds4-agent currently depends on the process CWD to find the model file, Metal kernel sources, and expert routing files. The user must either launch from the ds4 source tree, use --chdir to point to it, or pass -m /full/path/to/model.gguf explicitly every time. This is fragile and confusing — the binary should "just work" from any directory.

Solution

Add a runtime file discovery chain and a make install-user target so the binaries work from any CWD with zero flags.

Runtime discovery (ds4.c, ds4_metal.m, ds4.h)

New functions ds4_get_executable_path() and ds4_find_runtime_file() search for runtime files in this order:

  1. Absolute path (starts with /) → used as-is
  2. $DS4_RUNTIME_DIR env var → checked first
  3. Binary-relative (dirname of the running executable) → checked next
  4. ~/.ds4/runtime/ → user-level runtime directory
  5. CWD-relative → current fallback (preserved for backward compat)

Where the lookup is applied:

Call site File What it resolves
ds4_engine_open() ds4.c model_path, mtp_path
ds4_dump_text_tokenization() ds4.c model_path for --dump-tokens
ds4_gpu_full_source() ds4_metal.m metal/*.metal kernel sources

User-local install (Makefile)

New make install-user target copies files to user-local paths (no system directories touched):

File Destination Notes
ds4 ~/.local/bin/ds4 Configurable via INSTALL_BIN_DIR
ds4-agent ~/.local/bin/ds4-agent Same
metal/*.metal ~/.ds4/runtime/metal/ 19 kernel files
Model symlink Suggested, not auto-created Prints ln -s command if ds4flash.gguf exists
Download instructions Printed Points to download_model.sh if no model found

The model file itself is never copied (multi-GB, fragile). If ds4flash.gguf exists in the build directory the install target prints a one-line ln -s command the user can run explicitly.

--chdir is kept for backward compatibility but is now rarely needed.

Files changed: 4 files, +191/-18 lines

fry69 added 3 commits June 10, 2026 20:59
…me/, $DS4_RUNTIME_DIR)

Implement ds4_get_executable_path() and ds4_find_runtime_file() so the
binary works from any CWD without --chdir.  The lookup chain is:

  1. Absolute path (starts with '/')        → use as-is
  2. $DS4_RUNTIME_DIR env var               → check there
  3. Binary-relative (dirname of executable)  → check there
  4. ~/.ds4/runtime/                          → check there
  5. CWD-relative (current fallback)          → check there

Changes:

- ds4.h: declare ds4_get_executable_path() and ds4_find_runtime_file()
- ds4.c: implement both functions; resolve opt->model_path and
  opt->mtp_path through the chain in ds4_engine_open()
- ds4_metal.m: resolve metal/*.metal sources through ds4_find_runtime_file()
  instead of the old hard-coded CWD list; env overrides still work
…me discovery chain

The --dump-tokens path in ds4 (the basic CLI binary) called model_open()
directly without resolving through ds4_find_runtime_file(), so it would
fail unless -m /abs/path was given or CWD was the source tree.

Now it uses the same ds4_find_runtime_file() lookup that ds4_engine_open()
uses, making --dump-tokens work from any CWD.
…e installation

Introduce 'make install-user' that copies ds4 and ds4-agent to
~/.local/bin (configurable via INSTALL_BIN_DIR), copies metal/*.metal
to ~/.ds4/runtime/metal/, and suggests a model symlink or points to
download_model.sh.  No system directories are touched.

The model file itself is never copied (multi-GB); only a symlink
command is printed if ds4flash.gguf exists in the build directory.
@fry69 fry69 force-pushed the fry69/feat-runtime branch from 9e98560 to 3c10f66 Compare June 10, 2026 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant