Skip to content

feat: add C, C++, Rust, Java, and Kotlin probe templates#19

Merged
Toubat merged 18 commits into
mainfrom
feat/systems-language-templates
Jul 21, 2026
Merged

feat: add C, C++, Rust, Java, and Kotlin probe templates#19
Toubat merged 18 commits into
mainfrom
feat/systems-language-templates

Conversation

@Toubat

@Toubat Toubat commented Jul 20, 2026

Copy link
Copy Markdown
Owner

Extends the advertised template matrix from nine to fourteen language/ingest pairs: C, C++, Rust, Java, Kotlin (all file ingest).

Design

  • Java/Kotlin: structured-value helpers with at-source redaction (clones of the C# approach — regex normalization, reflection fallback, IdentityHashMap cycle detection).
  • C/C++/Rust: lightweight serialized-JSON interface per specs/lightweight-probe-templates.md. The call site passes one complete JSON value (the application's own serializer, or the helper's json_string text fallback); the daemon performs canonical redaction. Helpers carry only envelope construction, timestamp, 65536-byte cap, a control-character/NDJSON-framing guard, and secure 0600 append — 63%/62%/74% smaller than the initial value-model helpers (Rust 96, C++ 113, C 142 nonblank lines, all under the 150 cap).

Verification

  • Every pair passes the live behavioral parity suite with its real toolchain (rustc/clang/clang++/java/kotlinc); CI enforces all runtimes via REQUIRE_TEMPLATE_RUNTIMES=1. Daemon-side canonical evidence deep-compares against redactSecrets output for all five.
  • 32-process concurrent-append test produces only complete parseable NDJSON lines; realistic-insertion fixtures compile with application symbol collisions (AgentValue) present, proving namespace isolation.
  • Whole-branch review approved; framing-integrity guard (raw control chars rejected) and changeset wording landed as fast-follows.

Ships as a minor release via the included changeset. Supersedes #18 (author-identity rewrite).

🤖 Generated with Claude Code

Toubat and others added 18 commits July 20, 2026 14:23
Add the Rust (file ingest) probe template: an owned AgentValue enum with
From impls and an adbg! json-style macro, hand-rolled key normalization
matching the shared redaction contract (Rust std has no regex), a
backslash-free JSON serializer, verbatim redaction policy, 65536-byte cap,
depth-64 cap, epoch-ms timestamp, 0600 append via OpenOptions, and total
failure suppression. Registered as "rust" (alias "rs"), file ingest only.

Cycles are unrepresentable in an owned value tree, so the live cycle fixture
exercises the depth cap instead. Docs matrices and contract/e2e suites
extended; live e2e compiles single-file rustc with no cargo/serde.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Add the C++ (file ingest) probe template: an owned AgentValue struct with
implicit ctors from bool/long long/double/const char*/std::string plus an
nlohmann-style initializer_list constructor for nested object/array literals,
hand-rolled key normalization matching the shared redaction contract (no
regex, ported 1:1 from the verified Rust normalizer), a backslash-free JSON
serializer via ostringstream, verbatim redaction policy, 65536-byte cap,
depth-64 cap, chrono epoch-ms timestamp, ofstream append with 0600 on POSIX,
and total failure suppression (try/catch(...)). Registered as "cpp" (aliases
"c++", "cxx"), file ingest only.

Cycles are unrepresentable in an owned value tree, so the live cycle fixture
exercises the depth cap instead. Docs matrices and contract/e2e suites
extended; live e2e compiles single-file clang++ (g++ fallback), -std=c++17.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Add a Java (file-ingest) probe template cloning the csharp.ts approach:
real java.util.regex key normalization, Map/List/array/scalar handling
with a java.lang.reflect fallback over public getters and fields,
IdentityHashMap-based cycle detection with a depth-64 cap, fully-qualified
names (no imports) so the helper is injectable anywhere, and single-file
`java <File>.java` execution.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Add the Kotlin (file ingest) probe template, closing the five-language
systems batch (C, C++, Rust, Java, Kotlin). Kotlin clones the Java JVM
approach: java.lang.reflect over public getters then fields (not
kotlin-reflect), IdentityHashMap cycle detection, depth cap 64, real
java.util.regex secret-key normalization, Files.write(CREATE, APPEND)
with 0600-at-create POSIX handling, and an object AgentDebugLog.emit
static helper that never alters control flow (catch Throwable).

Also updates the changeset (minor bump: nine helper/runtime pairs become
fourteen) and every current-facing language matrix and count (README,
DESIGN, SKILL, REFERENCE, spec advertised list + region-marker row).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
DESIGN.md advertised-list contradiction; C NULL-key guard on malloc
failure; Rust allow attributes so user builds stay warning-free; C++
int constructor to remove the LL-suffix footgun.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The C/C++/Rust/Kotlin fixtures compiled and ran their probe binaries
through a single `cmd /c "<compile> && <run>"` (or `sh -c`) command
string. On Windows, cmd.exe mangles the quotes of that compound string,
so every step failed with `'"...rustc.exe"' is not recognized`. Run each
step as its own shell-free Bun.spawn argv instead: a new runSteps helper
executes compile then run in order, stopping on the first non-zero exit.
Kotlin's kotlinc resolves to kotlinc.bat on Windows, which cmd.exe must
interpret, so its compile step is wrapped in `cmd /c` with the batch path
and arguments passed as separate argv elements (correctly quoted by Bun)
rather than one pre-quoted string.

Also build the C++ cyclic-drop fixture's 100-deep structure by appending
to arrayValue explicitly. `AgentValue{ __agent_cycle }` is a
single-element braced-init-list whose overload resolution differs across
compilers (Apple clang selects the initializer_list constructor and
wraps; clang 18 / gcc 13 select the copy constructor and leave a scalar),
so the nesting depth the serializer saw varied by toolchain and the
depth-64 cap only tripped locally. The explicit array wrap nests
identically everywhere, so the value is dropped on every compiler.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
On Windows a just-exited process can hold an executable's file handle open
for a short window after termination. The language e2e step spawns detached
debug-mode daemons that run dist/debug-mode.exe; `stop` returns as soon as a
daemon acks shutdown, before the OS releases the handle. The next CI step's
build:binary then races that release and fails with
`EACCES: permission denied, rm '...\dist'`, failing the Distribution and
System test steps. Retry the dist removal with a short backoff (up to ~5s)
on EACCES/EPERM/EBUSY so the rebuild proceeds once the handle is freed; other
platforms release handles on exit and still succeed on the first attempt.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Extend ProbeTemplates with a dataEncoding discriminator
("native-json-value" | "serialized-json") and machine-readable placement
metadata for the helper and call insertion points. Every existing renderer
declares metadata matching today's behavior (native-json-value; helper
file-start for C/C++, top-level elsewhere). The template command surfaces
the new fields via JSON passthrough, and the pretty renderer prints a data
encoding and placement section.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Replace the Rust helper's recursive AgentValue model, adbg! macro, depth
handling, and client-side secret redaction with a small `mod agent_debug_mode`
that only escapes envelope metadata, timestamps, bounds, and appends. The call
template now accepts a serialized-JSON expression (__DATA_JSON_EXPRESSION__),
and json_string provides the escaped-text fallback. The daemon performs
redaction, so serialized-json callers may write raw caller text to the incoming
file. Helper drops from 260 to 96 nonblank lines (63% smaller).

Runtime coverage: raw arrays/strings/numbers/booleans/null passthrough,
json_string escaping torture, malformed-JSON rejection, oversize drop,
concurrent append, metadata with control characters, and a realistic insertion
fixture with nested modules and an application type named AgentValue proving
symbol isolation. The cycle and shared-reference cases (client-side value
model) are removed for serialized-json fixtures and retained for the rest.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Replace the C++ helper's recursive AgentValue model, AgentKind enum,
initializer-list object detection, depth handling, and client-side secret
normalization/redaction with a small `namespace agent_debug_mode` that only
escapes envelope metadata, timestamps, bounds, and appends. The call template
now accepts a serialized-JSON expression (__DATA_JSON_EXPRESSION__); json_string
provides the escaped-text fallback and AGENT_DEBUG_STRINGIFY builds a
__FILE__ ":" __LINE__ location. The POSIX append ports C's atomic
open(O_WRONLY|O_APPEND|O_CREAT, 0600) with an ofstream fallback under _WIN32,
and catch(...) suppresses every failure. The daemon performs redaction, so
serialized-json callers may write raw caller text to the incoming file. Helper
drops from 297 to 113 nonblank lines (62% smaller).

Runtime coverage mirrors Rust: raw arrays/strings/numbers/booleans/null
passthrough, json_string escaping torture, malformed-JSON rejection, oversize
drop, concurrent append, metadata with control characters, and a realistic
insertion fixture with a namespace and an application type named AgentValue
proving symbol isolation. The cycle and shared-reference cases (client-side
value model) are removed for the serialized-json cpp fixture.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Replace the C probe's allocated AgentValue pointer tree, adbg_* variadic
builders, recursive serializer, depth handling, and secret-key redaction
with a raw-JSON passthrough emitter that mirrors the migrated Rust and C++
templates. The caller now supplies one complete serialized JSON value; the
helper only escapes envelope metadata, stamps the timestamp, enforces the
65,536-byte cap, and atomically appends. Symbols carry a distinctive
agent_debug_ prefix in place of the removed generic global names.

The generated helper drops from 538 to 142 nonblank lines (74% smaller).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Document the migrated native probe contract across the agent-facing docs:
the native-json-value vs serialized-json data encodings and their
__DATA_EXPRESSION__ / __DATA_JSON_EXPRESSION__ placeholders, the
json_string escaped-text fallback, the caller's no-secrets responsibility
(daemon redaction is defense-in-depth; Rust/C++/C do no client-side
redaction), the file-start vs top-level helper placement and statement
call placement, per-language region markers, and application/x-ndjson as
the actual HTTP content type. Java, Kotlin, and the other languages with a
safe standard serializer keep native structured values.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…aming

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The injected helper's `#define _POSIX_C_SOURCE` cannot take effect when a
real application file includes system headers (e.g. <stdio.h>) before the
helper: glibc's <features.h> locks the feature-test macros on first
inclusion, so under strict -std=c99 clock_gettime, CLOCK_REALTIME, and
struct timespec stay hidden and the file fails to compile on Linux (macOS
libc exposes them regardless). Gate the clock_gettime path on
CLOCK_REALTIME's preprocessor visibility (which shares the
__USE_POSIX199309 guard with clock_gettime and struct timespec) and fall
back to ISO C time(NULL)*1000 when it is unavailable, keeping millisecond
precision wherever the POSIX clock API is visible.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
requestDaemonShutdown returned as soon as the daemon stopped answering
health checks (its listener socket closed), but on Windows the process
briefly outlives that moment while it unwinds and the OS releases the
mandatory locks it holds on files under the daemon home. Callers -- the
stop command and integration tests -- delete that home directory the
instant shutdown returns, racing the dying process and failing with
EBUSY/EACCES, or EFAULT under Bun's recursive rm. This surfaced as
chronic windows-2025 flakiness where a different daemon test's afterEach
rm failed each run.

Wait (bounded by the existing 5s shutdown deadline) for the recorded
process to actually exit on win32, verified by process identity so a
reused pid cannot be mistaken for the daemon. This is a single
synchronization point that also makes the stop command synchronous on
Windows. POSIX has no mandatory locks and returns as soon as health is
down -- behavior unchanged.

Also harden retryOnWindowsLock: treat EFAULT as a transient lock code
and widen the budget (25 attempts, escalating backoff capped at 200ms)
so a just-exited binary's lock-release window is covered, fixing the
npm-install EBUSY timeout.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The win32 wait added to requestDaemonShutdown polled inspectProcess for
the recorded pid to exit. Integration tests that run the daemon in-process
via startDaemonServer record the current process's pid, which never exits,
so the wait spun to the 5s deadline and timed out the SSE backpressure
test. A real daemon is always a separate spawned process, so skip the wait
when the recorded pid is our own -- closing the listener is all an
in-process server can observe.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@Toubat
Toubat merged commit c87330b into main Jul 21, 2026
3 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