Skip to content

fix: use correct --allowedTools flag in claude_args - #10

Merged
robcohen merged 1 commit into
mainfrom
fix/correct-claude-action-params
Jan 6, 2026
Merged

robcohen merged 1 commit into
mainfrom
fix/correct-claude-action-params

Conversation

@robcohen

@robcohen robcohen commented Jan 6, 2026

Copy link
Copy Markdown
Member

Fixes invalid allowed_tools parameter. Uses --allowedTools in claude_args instead.

@robcohen
robcohen enabled auto-merge January 6, 2026 16:25
@robcohen
robcohen added this pull request to the merge queue Jan 6, 2026
Merged via the queue into main with commit 9d91149 Jan 6, 2026
@robcohen
robcohen deleted the fix/correct-claude-action-params branch January 6, 2026 16:27
robcohen added a commit that referenced this pull request Jan 14, 2026
fix: use correct --allowedTools flag in claude_args
robcohen added a commit that referenced this pull request Jan 14, 2026
fix: use correct --allowedTools flag in claude_args
robcohen added a commit that referenced this pull request May 17, 2026
…ed re-export

Six review items shipped; three deferred to wave 2.3e (where the
reference sample importer provides actual end-to-end validation).

# Item 1: type-annotated user-fn bindings

The macro now does:
```
let identify_fn: fn(&str) -> bool = $identify;
let extract_fn: fn(ImporterInput) -> ImporterOutput = $extract;
```
before calling the user fn, so a wrong signature surfaces at the
user's `fn` definition site with a clean "expected fn(&str) -> bool"
error instead of a cryptic message pointing inside the macro
expansion. (Trade-off: closures that don't coerce to fn pointers
hit a less precise error — guests should prefer free fns, which
the macro example already shows.)

# Item 2: optional extract_enriched with default passthrough

The macro now has two arms:

- Full: `wasm_importer_main! { name, description, identify, extract, extract_enriched }`
- Short: `wasm_importer_main! { name, description, identify, extract }`

The short form auto-generates `extract_enriched` that wraps the
user's `extract` output via the new `default_enriched_from` helper:
each directive gets a default (uncategorized, `"default"` method,
no alternatives, no fingerprint) `EnrichmentWrapper`. Matches the
host-side `EnrichedImportResult::from(ImportResult)` shape so the
round-trip is consistent. Saves ~10 lines per non-categorizing
importer.

3 new unit tests for `default_enriched_from`: empty passthrough,
per-directive default attachment, host-compatible method string.

# Item 5: narrow rmp_serde re-export

Was: `pub use rmp_serde;` (full crate, all major bumps affect our API)
Now: `pub use rmp_serde::{decode::Error as DecodeError, from_slice, to_vec};`

Just the symbols the macro needs + DecodeError for users handling
`decode_input`'s Result. Guests that want non-default Serializer
config still add `rmp-serde` to their own deps; default usage
unchanged.

# Items 4, 6, 7, 8, 9: doc-only improvements

Module-level rustdoc gained four new sections:

- **Required `Cargo.toml` setup** — `crate-type = ["cdylib"]` +
  the wasm32 build command. First-time authors will no longer hit
  "no .wasm output" or "function symbols mangled" surprises.
- **`std` is required** — explicit one-liner; `no_std` guests
  need to hand-roll the exports.
- **No `stdio` inside the guest** — surface diagnostics via
  `ImporterOutput::warnings` / `errors`, not println.
- **Sharing state across exports** — `OnceLock` pattern for the
  shared-parser-cache case the trait-based design would have
  handled naturally.

Tightened `pack_output`'s mem::forget rationale: the "leak" only
seems like one — the host's per-call wasmtime Store drops at
return, reclaiming the whole guest linear memory in one shot. The
guest never sees the Store.

# Verification

- 29 plugin-types lib tests (was 26; +3 for `default_enriched_from`)
- cargo check --workspace --all-targets --all-features clean
- cargo clippy --workspace --all-targets --all-features -- -D warnings clean
- cargo fmt --all -- --check clean

# Deferred (judgment / out-of-scope)

- #3 doctest validation via trybuild — deferred to wave 2.3e where
  the reference sample provides real end-to-end coverage
- #10 module-level `#![allow(unsafe_code)]` — appropriate for FFI module
- #11 `.to_string()` vs `.into()` — kept .to_string() for clarity

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
robcohen added a commit that referenced this pull request May 18, 2026
…etry + closures-everywhere test

Five items from the final-pass review:

# Item 1: single-invocation-per-crate constraint documented

The macro generates Rust idents (`__wasm_importer_alloc` etc.)
and wasm32 symbols (`alloc` etc.) — calling twice in one crate
collides on both. Added an "Invocation constraint" section to the
macro rustdoc making this explicit: each WASM importer should be
its own cdylib crate.

# Item 2: short-form's fn-pointer constraint surfaced

The short-form arm's auto-generated `extract_enriched` internally
requires `extract` to coerce to `fn(...) -> ...`. Capturing
closures don't coerce. The full-form arm has the same constraint
documented; the short form inherits it implicitly. Added an
explicit paragraph under "Required user-fn signatures" so users
hitting the cryptic capturing-closure error can find the
contract.

# Item 3: cross-crate "default" symmetry pinned

Reframed `default_enriched_uses_host_compatible_method_string`'s
rustdoc to call out the explicit symmetry:

- Host (`rustledger-ops::enrichment::tests`):
  `CategorizationMethod::Default.as_meta_value() == "default"`
- Guest (this test): `default_enriched_from` emits `"default"`

Both sides assert the literal — a future rename surfaces as a
test failure on whichever side wasn't updated. Reviewer sees the
asymmetry and knows to fix both ends.

# Item 4: closures-everywhere compile-test variant

New `mod all_closures` in `tests/guest_macro_compiles.rs` invokes
the macro with non-capturing closures for ALL THREE callbacks
(identify, extract, extract_enriched). Previously only `identify`
was tested with a closure; if the macro's fn-pointer bounds ever
broke closure coercion for extract or extract_enriched, that
regression would slip through.

# Item 5: native vs wasm32 symbol-name clarification

Added "Native vs wasm32 symbol names" section to the macro
rustdoc noting that the `export_name` attribute is gated off on
native targets, so `objdump`/`nm` on a native build shows only
the `__wasm_importer_*` Rust identifiers — not the `alloc`/etc.
symbols a user might expect from reading the ABI table.

# Verification

- 29 plugin-types lib tests + 4 compile-tests pass (+1 all_closures)
- cargo clippy --workspace --all-targets --all-features -- -D warnings clean
- cargo fmt --all -- --check clean

# Deferred (per my own framing)

- #6-#10 are nits / scope-creep documented in the review

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
robcohen added a commit that referenced this pull request May 18, 2026
… 2.3d) (#1134)

* feat(plugin-types): wasm_importer_main! macro for guest authors (wave 2.3d)

Wave 2.3d of the v0.16.0 reshape: collapses WASM importer guest
boilerplate from ~150 lines to ~20 via a declarative macro. A user
writes three free functions (identify, extract, extract_enriched)
plus a single macro invocation; the macro emits the five
host-callable exports (alloc, metadata, identify, extract,
extract_enriched).

# Public API

New `guest` Cargo feature on `rustledger-plugin-types`:

```toml
rustledger-plugin-types = { version = "0.15", features = ["guest"] }
```

Enables `pub mod guest` with:

- `wasm_importer_main!` macro (exported at crate root via
  `#[macro_export]`) — the only thing most guest authors need
- `guest::pack_output(Vec<u8>) -> u64` — host-ABI packing helper
- `guest::decode_input<T>(ptr: u32, len: u32) -> Result<T, _>` —
  host-ABI decoding helper
- `guest::rmp_serde` re-export so guests don't need their own
  rmp-serde dep

# Example

```rust
use rustledger_plugin_types::{
    wasm_importer_main, EnrichedImporterOutput, ImporterInput,
    ImporterOutput,
};

fn identify(path: &str) -> bool { path.ends_with(".mt940") }
fn extract(_: ImporterInput) -> ImporterOutput { ImporterOutput::empty() }
fn extract_enriched(_: ImporterInput) -> EnrichedImporterOutput { /* ... */ }

wasm_importer_main! {
    name: "MT940",
    description: "MT940 bank statement importer",
    identify: identify,
    extract: extract,
    extract_enriched: extract_enriched,
}
```

The expansion handles:

- `#[no_mangle] pub extern "C" fn alloc(size: u32) -> *mut u8` —
  Vec-backed bump allocator, leaked via `mem::forget`
- `metadata() -> u64` — msgpack-encodes the name/description
  constants from the macro invocation
- `identify`/`extract`/`extract_enriched` — decode the host's
  msgpack input via `decode_input`, call user fn, encode output,
  pack pointer + length

# wasm32-only contract

The packing math (`(ptr << 32) | len`) only works when pointers
fit in u32. `pack_output` now uses `u32::try_from(ptr as usize)`
so it panics loudly on non-wasm32 targets instead of silently
truncating (which produced a SIGSEGV in earlier test iteration).
Documented in the function's rustdoc as wasm32-only by contract.

# Tests

6 unit tests in `guest::tests`:
- packing_math_round_trips_synthetic_values
- packing_math_handles_zero_and_max
- identify_input/output/metadata_output_msgpack_encoding_is_stable
- pack_output_panics_on_non_wasm32_targets (gated; pins the
  defense against silent pointer truncation)

End-to-end "load a real macro-generated .wasm via WasmImporter"
test lives in wave 2.3e — that's the wave specifically designed
to ship a reference sample importer + the full integration test
that exercises the macro through the host loader.

# Verification

- 26 plugin-types lib tests pass with `--features guest` (was 20;
  +6 new)
- All workspace tests still pass (52 result lines, all "0 failed")
- cargo check --workspace --all-targets --all-features clean
- cargo clippy --workspace --all-targets --all-features -- -D warnings clean
- cargo fmt --all -- --check clean

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* fix(plugin-types): address review of #1134 — DX improvements + narrowed re-export

Six review items shipped; three deferred to wave 2.3e (where the
reference sample importer provides actual end-to-end validation).

# Item 1: type-annotated user-fn bindings

The macro now does:
```
let identify_fn: fn(&str) -> bool = $identify;
let extract_fn: fn(ImporterInput) -> ImporterOutput = $extract;
```
before calling the user fn, so a wrong signature surfaces at the
user's `fn` definition site with a clean "expected fn(&str) -> bool"
error instead of a cryptic message pointing inside the macro
expansion. (Trade-off: closures that don't coerce to fn pointers
hit a less precise error — guests should prefer free fns, which
the macro example already shows.)

# Item 2: optional extract_enriched with default passthrough

The macro now has two arms:

- Full: `wasm_importer_main! { name, description, identify, extract, extract_enriched }`
- Short: `wasm_importer_main! { name, description, identify, extract }`

The short form auto-generates `extract_enriched` that wraps the
user's `extract` output via the new `default_enriched_from` helper:
each directive gets a default (uncategorized, `"default"` method,
no alternatives, no fingerprint) `EnrichmentWrapper`. Matches the
host-side `EnrichedImportResult::from(ImportResult)` shape so the
round-trip is consistent. Saves ~10 lines per non-categorizing
importer.

3 new unit tests for `default_enriched_from`: empty passthrough,
per-directive default attachment, host-compatible method string.

# Item 5: narrow rmp_serde re-export

Was: `pub use rmp_serde;` (full crate, all major bumps affect our API)
Now: `pub use rmp_serde::{decode::Error as DecodeError, from_slice, to_vec};`

Just the symbols the macro needs + DecodeError for users handling
`decode_input`'s Result. Guests that want non-default Serializer
config still add `rmp-serde` to their own deps; default usage
unchanged.

# Items 4, 6, 7, 8, 9: doc-only improvements

Module-level rustdoc gained four new sections:

- **Required `Cargo.toml` setup** — `crate-type = ["cdylib"]` +
  the wasm32 build command. First-time authors will no longer hit
  "no .wasm output" or "function symbols mangled" surprises.
- **`std` is required** — explicit one-liner; `no_std` guests
  need to hand-roll the exports.
- **No `stdio` inside the guest** — surface diagnostics via
  `ImporterOutput::warnings` / `errors`, not println.
- **Sharing state across exports** — `OnceLock` pattern for the
  shared-parser-cache case the trait-based design would have
  handled naturally.

Tightened `pack_output`'s mem::forget rationale: the "leak" only
seems like one — the host's per-call wasmtime Store drops at
return, reclaiming the whole guest linear memory in one shot. The
guest never sees the Store.

# Verification

- 29 plugin-types lib tests (was 26; +3 for `default_enriched_from`)
- cargo check --workspace --all-targets --all-features clean
- cargo clippy --workspace --all-targets --all-features -- -D warnings clean
- cargo fmt --all -- --check clean

# Deferred (judgment / out-of-scope)

- #3 doctest validation via trybuild — deferred to wave 2.3e where
  the reference sample provides real end-to-end coverage
- #10 module-level `#![allow(unsafe_code)]` — appropriate for FFI module
- #11 `.to_string()` vs `.into()` — kept .to_string() for clarity

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* fix(plugin-types): critical macro bugs caught by Copilot review of #1134

Three Copilot comments — all real bugs. The macro's headline example
did not compile until this commit. Caught + fixed before further
guest authors hit them.

# Bug 1: name collision (E0428)

The macro generated `#[no_mangle] pub extern "C" fn identify(...)`
at the SAME module scope as the user's `fn identify(...)`. Two
items with the same Rust name at the same scope = hard compile
error. The documented example would not compile.

Fix: rename generated fns to `__wasm_importer_alloc/metadata/
identify/extract/extract_enriched`. Set the WASM linker symbol
via `#[cfg_attr(target_arch = "wasm32", unsafe(export_name = "..."))]`
so the wasm32 export name still matches what the host expects,
without polluting the Rust namespace.

Why `cfg_attr(target_arch = "wasm32", ...)` rather than always-on
export_name: on native test targets, multiple macro invocations in
the same crate would collide at link time (e.g., 3 modules each
exporting "alloc"). Gating on wasm32 means the symbol-export only
applies where it's actually meaningful — production guest builds.

# Bug 2: Rust 2024 unsafe attributes

Workspace is on edition 2024. Bare `#[no_mangle]` is now a hard
error — must be `#[unsafe(no_mangle)]` or `#[unsafe(export_name = "...")]`.

Fix: all generated linker-affecting attributes wrapped in
`unsafe(...)`. (Same applies to `export_name` from bug 1's fix.)

# Bug 3: decode_input was safe fn with unsafe internals

`pub fn decode_input<T>(ptr: u32, len: u32)` constructed a slice
via `from_raw_parts(ptr as *const u8, len)` inside the body. Safe
Rust could call `decode_input(0, 100)` and trigger UB by reading
arbitrary guest memory.

Fix: `pub unsafe fn decode_input<T>(...)`. The macro's call sites
now wrap in `unsafe { ... }` blocks with SAFETY comments
documenting the host-memory contract that justifies the call.

# Compile-test fixture

New `tests/guest_macro_compiles.rs` integration test that invokes
`wasm_importer_main!` in three configurations (short form, full
form, with closures) — each in its own module so the test crate
compiling proves the macro doesn't collide with user fns of the
same name. If the macro ever regresses to bare `#[no_mangle] pub
extern "C" fn identify`, this test crate fails to compile.

Each test verifies the macro-generated fn signatures via
`extern "C" fn(...)` pointer coercion (compile-time check; the
fns aren't invoked because their pack_output panics on non-wasm32
targets by design).

This is the test that would have caught all three Copilot bugs
before push. Lesson: macro authors need compile-tests, not just
unit tests of the helper fns.

# Verification

- 29 plugin-types lib tests pass with --features guest
- 3 new compile-test integration tests pass
- cargo check --workspace --all-targets --all-features clean
- cargo clippy --workspace --all-targets --all-features -- -D warnings clean
- cargo fmt --all -- --check clean

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* chore(plugin-types): polish — expect-with-reason + sharper test rustdoc

Two small follow-ups to the Copilot critical-bug fix in 8a08ea1:

# `#[expect(dead_code, reason = ...)]` over `#[allow(dead_code)]`

Rust 1.81+ introduced `expect` as the documented-intent variant of
`allow`. The reason field makes the lint suppression self-explaining
("consumed by macro expansion; clippy can't see through") instead
of a bare `allow` a future reader has to puzzle out.

# Test-fixture rustdoc: explicit "what this doesn't verify" section

Added a "# What this test does NOT verify" block noting that the
`cfg_attr(target_arch = "wasm32", ...)` gate means on the native
test target the generated fns don't carry the host-expected
linker symbols (`alloc`/`metadata`/etc.) — only their Rust
identifiers (`__wasm_importer_*`). End-to-end host-visible
export-name correctness lands in wave 2.3e where a real `.wasm`
gets loaded via `WasmImporter::load` (which fails fast on missing
exports).

# Verification

- 29 plugin-types lib tests pass with --features guest
- 3 compile-test integration tests pass
- cargo clippy --workspace --all-targets --all-features -- -D warnings clean
- cargo fmt --all -- --check clean

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* chore(plugin-types): drop #[expect(dead_code)] — fix test instead

The previous fix used `#[expect(dead_code, reason = "...")]` to
silence a clippy warning on `extract_impl`/`enriched_impl` in the
`with_closures` test module. The real problem was the test itself:
`closures_compile` only referenced `__wasm_importer_alloc`, so
clippy's dead-code chain couldn't reach the user fns the macro
consumes.

Fix: reference all 5 generated fns in the closures test (same
shape as the `short_form`/`full_form` tests). The liveness chain
flows naturally:

  closures_emit_expected_signatures
    → with_closures::__wasm_importer_extract
    → extract_impl  // now considered used

No more dead-code suppression needed. Renamed the test to
`closures_emit_expected_signatures` to match the sibling tests'
naming.

This is what the reviewer's "why do we have dead code?" question
correctly poked at: suppression annotations are a smell, not a
solution.

# Verification

- 29 plugin-types lib tests + 3 compile-tests pass
- cargo clippy --workspace --all-targets --all-features -- -D warnings clean
- No #[allow] / #[expect] in the test module anymore

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* docs(plugin-types): close remaining review items — constraints + symmetry + closures-everywhere test

Five items from the final-pass review:

# Item 1: single-invocation-per-crate constraint documented

The macro generates Rust idents (`__wasm_importer_alloc` etc.)
and wasm32 symbols (`alloc` etc.) — calling twice in one crate
collides on both. Added an "Invocation constraint" section to the
macro rustdoc making this explicit: each WASM importer should be
its own cdylib crate.

# Item 2: short-form's fn-pointer constraint surfaced

The short-form arm's auto-generated `extract_enriched` internally
requires `extract` to coerce to `fn(...) -> ...`. Capturing
closures don't coerce. The full-form arm has the same constraint
documented; the short form inherits it implicitly. Added an
explicit paragraph under "Required user-fn signatures" so users
hitting the cryptic capturing-closure error can find the
contract.

# Item 3: cross-crate "default" symmetry pinned

Reframed `default_enriched_uses_host_compatible_method_string`'s
rustdoc to call out the explicit symmetry:

- Host (`rustledger-ops::enrichment::tests`):
  `CategorizationMethod::Default.as_meta_value() == "default"`
- Guest (this test): `default_enriched_from` emits `"default"`

Both sides assert the literal — a future rename surfaces as a
test failure on whichever side wasn't updated. Reviewer sees the
asymmetry and knows to fix both ends.

# Item 4: closures-everywhere compile-test variant

New `mod all_closures` in `tests/guest_macro_compiles.rs` invokes
the macro with non-capturing closures for ALL THREE callbacks
(identify, extract, extract_enriched). Previously only `identify`
was tested with a closure; if the macro's fn-pointer bounds ever
broke closure coercion for extract or extract_enriched, that
regression would slip through.

# Item 5: native vs wasm32 symbol-name clarification

Added "Native vs wasm32 symbol names" section to the macro
rustdoc noting that the `export_name` attribute is gated off on
native targets, so `objdump`/`nm` on a native build shows only
the `__wasm_importer_*` Rust identifiers — not the `alloc`/etc.
symbols a user might expect from reading the ABI table.

# Verification

- 29 plugin-types lib tests + 4 compile-tests pass (+1 all_closures)
- cargo clippy --workspace --all-targets --all-features -- -D warnings clean
- cargo fmt --all -- --check clean

# Deferred (per my own framing)

- #6-#10 are nits / scope-creep documented in the review

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* fix(plugin-types): two broken intra-doc links in guest module

CI Documentation job (cargo doc -Dwarnings) caught two broken
intra-doc links in `guest.rs`:

- `[``wasm_importer_main!``]` → `wasm_importer_main` macro lives
  at crate root via `#[macro_export]`, not in the `guest` module
  namespace. Path-prefixed to `[``crate::wasm_importer_main!``]`.
- `[``PluginError``]` → same root-vs-module mismatch.
  Path-prefixed to `[``crate::PluginError``]`.

Other intra-doc links in the same file (`ImporterOutput::warnings`,
`ImporterOutput::errors`, `DecodeError`, `default_enriched_from`,
etc.) already resolved correctly because they're either reachable
via Rust's `use crate::{...}` import at the top of `guest.rs` or
defined in the same module.

# Local repro

`RUSTDOCFLAGS=-Dwarnings cargo doc -p rustledger-plugin-types
--features guest --no-deps` now passes. `RUSTDOCFLAGS=-Dwarnings
cargo doc --workspace --no-deps` also clean.

# Process note

I ran clippy locally but skipped cargo doc — CI caught what I
should have. Worth adding to the "before push" checklist:
`RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-deps`.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
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