Skip to content

feat: harden external parent event envelopes - #108

Open
twaldin wants to merge 1 commit into
mainfrom
hermes-external-parent-events
Open

feat: harden external parent event envelopes#108
twaldin wants to merge 1 commit into
mainfrom
hermes-external-parent-events

Conversation

@twaldin

@twaldin twaldin commented Jun 11, 2026

Copy link
Copy Markdown
Owner

Hardens the events.jsonl envelope written by appendExternalEvent when an agent's parent is an external orchestrator (#98 follow-up):

  • adds version: 1 so future envelope changes are detectable by readers
  • emits both text and message fields for reader compatibility
  • switches ts to epoch milliseconds
  • opaquely forwards HERMES_KANBAN_TASK / HERMES_KANBAN_RUN_ID / HERMES_KANBAN_PARENT_REF env refs into a refs object when present

Within flt nothing consumes events.jsonl (writer + sink config only); the consumer is the external hermes orchestrator this is co-designed with. Rebased on v0.3.4; tsc clean; full unit suite 838 pass / 0 fail.

Summary by CodeRabbit

  • Improvements

    • Event logging now uses enhanced versioned schema with richer payload data.
    • Events capture both message content and configuration references from environment variables.
    • Timestamps converted to numeric format for improved compatibility.
  • Tests

    • Event logging test suite updated to validate new versioned schema structure.
    • Added tests for environment variable reference handling in event records.

@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR upgrades external event logging with a versioned JSON format. appendExternalEvent now writes richer payloads including both text and message fields, a numeric timestamp (Date.now()), and an optional refs object populated from Hermes-specific environment variables. A new internal helper externalEventRefs() collects these refs; tests validate the new schema and verify environment variable forwarding.

Changes

Enriched external event logging

Layer / File(s) Summary
Event serialization and ref collection
src/commands/send.ts
appendExternalEvent builds versioned JSON events with version, type, text, message, numeric ts, and conditional refs; new externalEventRefs() helper collects HERMES_KANBAN_* environment variables into refs.
Event schema and environment ref tests
tests/unit/external-orchestrator.test.ts
Existing event tests expanded to validate versioned schema (version, type, numeric timestamp); new test confirms Hermes environment variables are captured and forwarded via refs object with safe env variable restoration.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A richer log now flows from send,
with timestamp numbers, refs to blend,
Hermes whispers in the JSON deep,
versioned schema tight we keep.
Hop!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: harden external parent event envelopes' directly describes the main change: hardening the events.jsonl envelope structure for external orchestrator parent events, which is the primary focus of the changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch hermes-external-parent-events

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
src/commands/send.ts (2)

199-206: 💤 Low value

Consider extracting the environment variable list to a module-level constant.

The hardcoded array of environment variable names on Line 201 could be extracted to improve maintainability, especially if this list needs to be referenced elsewhere or modified in the future.

♻️ Suggested refactor
+const HERMES_REF_ENV_VARS = ['HERMES_KANBAN_TASK', 'HERMES_KANBAN_RUN_ID', 'HERMES_KANBAN_PARENT_REF'] as const
+
 function externalEventRefs(): Record<string, string> {
   const refs: Record<string, string> = {}
-  for (const key of ['HERMES_KANBAN_TASK', 'HERMES_KANBAN_RUN_ID', 'HERMES_KANBAN_PARENT_REF']) {
+  for (const key of HERMES_REF_ENV_VARS) {
     const value = process.env[key]
     if (value && value.length > 0) refs[key] = value
   }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/commands/send.ts` around lines 199 - 206, The array of environment
variable names used inside externalEventRefs() should be pulled out to a
module-level constant so it can be reused and maintained more easily; create a
const (e.g., EXTERNAL_EVENT_ENV_KEYS) at top of the file containing
['HERMES_KANBAN_TASK','HERMES_KANBAN_RUN_ID','HERMES_KANBAN_PARENT_REF'] and
update externalEventRefs() to iterate that constant instead of the inline array,
keeping the function name and behavior unchanged.

182-192: ⚡ Quick win

Consider adding a type for the event object.

The inline event object lacks type annotation, which reduces compile-time safety and IDE support. Defining an interface would catch schema errors earlier and document the expected structure.

♻️ Suggested type definition

Add an interface near the top of the file:

+interface ExternalEventPayload {
+  version: number
+  type: 'message'
+  from: string
+  to: string
+  text: string
+  message: string
+  ts: number
+  refs?: Record<string, string>
+}
+

Then type the event object:

     const refs = externalEventRefs()
-    const event = JSON.stringify({
+    const payload: ExternalEventPayload = {
       version: 1,
       type: 'message',
       from,
       to,
       text: message,
       message,
       ts: Date.now(),
       ...(Object.keys(refs).length > 0 ? { refs } : {}),
-    })
+    }
+    const event = JSON.stringify(payload)

As per coding guidelines, TypeScript should be used for type safety and better developer experience.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/commands/send.ts` around lines 182 - 192, The inline event object
assigned to the variable event is untyped; add a TypeScript interface (e.g.,
OutgoingEvent or MessageEvent) that describes fields version, type, from, to,
text, message, ts, and optional refs (matching externalEventRefs()), place the
interface near the top of the file, then annotate the event variable with that
interface (const event: OutgoingEvent = { ... }) so the compiler and IDE can
validate the schema and catch mismatches in send.ts around the
externalEventRefs() usage.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/commands/send.ts`:
- Around line 199-206: The array of environment variable names used inside
externalEventRefs() should be pulled out to a module-level constant so it can be
reused and maintained more easily; create a const (e.g.,
EXTERNAL_EVENT_ENV_KEYS) at top of the file containing
['HERMES_KANBAN_TASK','HERMES_KANBAN_RUN_ID','HERMES_KANBAN_PARENT_REF'] and
update externalEventRefs() to iterate that constant instead of the inline array,
keeping the function name and behavior unchanged.
- Around line 182-192: The inline event object assigned to the variable event is
untyped; add a TypeScript interface (e.g., OutgoingEvent or MessageEvent) that
describes fields version, type, from, to, text, message, ts, and optional refs
(matching externalEventRefs()), place the interface near the top of the file,
then annotate the event variable with that interface (const event: OutgoingEvent
= { ... }) so the compiler and IDE can validate the schema and catch mismatches
in send.ts around the externalEventRefs() usage.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f4d46bc7-f33d-4817-b76b-7c028f4bbad2

📥 Commits

Reviewing files that changed from the base of the PR and between fe05463 and 9b6f72b.

📒 Files selected for processing (2)
  • src/commands/send.ts
  • tests/unit/external-orchestrator.test.ts

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