Skip to content

refactor: merge hm-util into hm-common#178

Merged
markovejnovic merged 6 commits into
mainfrom
refactor/merge-hm-util-into-hm-common
Jul 26, 2026
Merged

refactor: merge hm-util into hm-common#178
markovejnovic merged 6 commits into
mainfrom
refactor/merge-hm-util-into-hm-common

Conversation

@markovejnovic

Copy link
Copy Markdown
Contributor

Generated by an AI agent.

Fold the hm-util crate (dirs resolution + os fs helpers) into hm-common
and delete it. Its modules land as hm_common::dirs, hm_common::fs, and a
pub(crate) hm_common::os for platform primitives.

Replace the FileMode(u32)/DirMode(u32) newtypes on the atomic writer with
a semantic Privacy enum (Private = owner-only, Public = world-readable).
The parent dir is now always created owner-only, so the dir-mode argument
drops out entirely. Raw mode bits no longer leak into call sites, and the
long-standing Windows no-op (modes silently ignored) is now documented on
Privacy rather than hidden in u32s. write_atomic_restricted is renamed to
write_atomic.

Call sites in hm-config/hm-exec/hm move from hm_util::* to hm_common::*.
@markovejnovic
markovejnovic force-pushed the refactor/merge-hm-util-into-hm-common branch from a16b8b0 to 66f0aec Compare July 26, 2026 03:42
The fs::blocking wrappers existed for extism host_fn sync callbacks,
which the plugin-era cleanup already removed. Delete the module and make
every public fs writer async: write_atomic, atomic_rename_over,
remove_file_if_exists, and write_create_all (now tokio::fs, was std::fs).

Propagate async through the only sync callers — hm-config's credential
and config writers (save/set/delete/save_to/save_user/set_cloud_token/
forget_cloud_token) and hm's init/run helpers (write_template,
write_skills, persist_project_pipeline) — plus the cloud auth verbs that
drive them. Tests touching these move to #[tokio::test].
Introduce DirProvider (dir_provider.rs): it resolves the platform
per-user directory roots (config, cache) a single time at construction
and hands them out as &Path, so consumers stop re-resolving them per
call. It is deliberately application-agnostic — it knows nothing of
Harmont's own `hm/` subdirectory; callers join that (and any file name)
onto these roots. Replaces the pub(crate) os/dirs.rs platform
primitives, which are deleted, and the hm_config_dir/hm_cache_dir/
hm_workspace_cache_dir free functions in dirs.rs. dirs.rs now holds only
find_project_root (project discovery, orthogonal to the platform roots).

AppRuntime gains a resolved-once DirProvider and an AppRuntime::dirs()
accessor, alongside an InitError::Dirs variant. Consumers migrate:
hm/cache-clean reads AppRuntime::dirs(); hm-config and hm-exec (no
app-runtime feature) construct DirProvider::new() directly. Each joins
`hm/` onto the returned root as before, so resolved paths are unchanged.

Also make write_atomic create the parent directory at the file's own
Privacy (0o755 for Public, 0o700 for Private) rather than always
owner-only.
@markovejnovic
markovejnovic force-pushed the refactor/merge-hm-util-into-hm-common branch from dc27505 to 3bb8470 Compare July 26, 2026 06:09
Rename app_runtime.rs -> sys_runtime.rs, the AppRuntime type ->
SysRuntime, and the app-runtime feature -> sys-runtime, across
hm-common, hm, and hm-dsl-engine. The type resolves host toolchain and
platform directories from the OS environment, so the "system runtime"
name fits better than "app runtime".

Also correct the SysRuntime::dirs() and DirProvider docblocks, which
described the roots as hm-namespaced; DirProvider now exposes the raw
platform roots.
…-export

Delete crates/hm-common/src/dirs.rs. Its sole remaining function,
find_project_root, discovers the `.hm/` project root and is used only by
the hm crate (context.rs and the config_layered test), so it moves to
crates/hm/src/project.rs where it belongs.

Also drop the `pub use dir_provider::DirProvider` crate-root re-export:
every other hm-common type is module-qualified (hm_common::git::Git,
hm_common::fs::write_atomic), so callers now use
hm_common::dir_provider::DirProvider for consistency.
@markovejnovic
markovejnovic marked this pull request as ready for review July 26, 2026 06:27
@markovejnovic
markovejnovic merged commit 7210ae4 into main Jul 26, 2026
15 of 17 checks passed
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