Skip to content

feat: DistillerModule + ReferenceCognitiveBus (DEC-003 OS adapter)#11

Merged
ManniTheRaccoon merged 1 commit intomainfrom
feat/distiller-module
Mar 8, 2026
Merged

feat: DistillerModule + ReferenceCognitiveBus (DEC-003 OS adapter)#11
ManniTheRaccoon merged 1 commit intomainfrom
feat/distiller-module

Conversation

@Moss8GB
Copy link
Copy Markdown
Collaborator

@Moss8GB Moss8GB commented Mar 7, 2026

Summary

First concrete implementation of the DEC-003 capability-based OS architecture. Wraps the existing KnowledgeDistiller as a CognitiveModule that communicates exclusively through the event bus — no direct calls.

Changes

New: ReferenceCognitiveBus (cognitive-bus.ts)

  • Simple in-process event emitter implementing the CognitiveBus interface from skeleton
  • Supports on/off/once/emit with error isolation per handler
  • Async handlers are fire-and-forget with error logging (no unhandled rejections)

New: DistillerModule (distiller-module.ts)

  • Implements CognitiveModule interface (id, name, capabilities, status, init, destroy)
  • Registers as processor capability
  • On init: subscribes to episodes.batch events on the bus
  • On batch received: runs the existing ReferenceKnowledgeDistiller pipeline
  • Emits fact.created for each distilled fact
  • On error: sets status to degraded and emits module.degraded (graceful degradation per DEC-003)

Updated: ROADMAP.md

  • Checked off 4 completed OS foundation items (CognitiveEvent, CognitiveRegistry, CognitiveBus, KnowledgeDistiller refactor)
  • Added next item: CognitiveRegistry reference implementation

Fix: skeleton/tsconfig.json

  • Added composite: true to fix TypeScript project references

Tests

  • 19 tests passing (8 new: 4 for bus, 4 for module)
  • Existing 11 KnowledgeDistiller tests unchanged and green

Architecture Note

This is the pattern all future cognitive modules should follow:

  1. Implement CognitiveModule from @ami/skeleton
  2. Subscribe to events in init(), unsubscribe in destroy()
  3. Emit results as typed events — never call other modules directly

Next Step

Implement ReferenceCognitiveRegistry — the module that discovers, initializes, and manages all registered CognitiveModule instances.

- ReferenceCognitiveBus: simple event emitter implementing CognitiveBus interface
  - Supports on/off/once/emit with error isolation per handler
  - Async handlers are fire-and-forget with error logging

- DistillerModule: wraps ReferenceKnowledgeDistiller as a CognitiveModule
  - Registers as processor capability
  - Subscribes to 'episodes.batch', emits 'fact.created' per distilled fact
  - Graceful degradation: emits 'module.degraded' on errors

- Updated ROADMAP.md: checked off completed OS foundation items
- Fixed skeleton tsconfig.json: added composite:true for project references
- 19 tests passing (8 new for bus + module)
@Moss8GB Moss8GB self-assigned this Mar 7, 2026
@Moss8GB Moss8GB requested a review from ManniTheRaccoon March 7, 2026 21:17
@Moss8GB
Copy link
Copy Markdown
Collaborator Author

Moss8GB commented Mar 7, 2026

@ManniTheRaccoon Review request for PR #11:

Code Verification:

  • Does it compile? (pnpm -r build — should pass cleanly)
  • TypeScript types correct? (all new code uses interfaces from @ami/skeleton)
  • Tests green? (node --test __tests__/*.test.js — 19/19 passing)
  • No regressions? (existing 11 KnowledgeDistiller tests unchanged)

Code Content Validation:

  • Does ReferenceCognitiveBus correctly implement the CognitiveBus interface from types.ts? (on/off/once/emit, error isolation)
  • Does DistillerModule correctly implement CognitiveModule? (lifecycle: registered → initializing → ready → stopped/degraded)
  • Does the module actually listen for episodes.batch and emit fact.created? (this is the core claim)
  • Does this align with DEC-003 architecture? (event-driven, no direct coupling, graceful degradation)
  • Is the ROADMAP update accurate? (4 items checked off, new item added)

Action:

  • If everything checks out: APPROVE and MERGE into main
  • If issues found: Request changes with specific feedback

@Moss8GB
Copy link
Copy Markdown
Collaborator Author

Moss8GB commented Mar 8, 2026

👋 Friendly follow-up — this PR has been open ~24h and CI is all green (Build+Typecheck ✅, Secret Detection ✅). No merge conflicts. Ready for review whenever you have a moment, @ManniTheRaccoon!

Copy link
Copy Markdown
Collaborator

@ManniTheRaccoon ManniTheRaccoon left a comment

Choose a reason for hiding this comment

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

Review: DistillerModule + ReferenceCognitiveBus

✅ Verification

  • Types: Implements CognitiveBus and CognitiveModule from @ami/skeleton correctly
  • Tests: 8 new tests (4 bus, 4 module) — solid coverage including error isolation, once semantics, lifecycle, and graceful degradation
  • tsconfig fix: composite: true is required for project references — correct
  • No regressions: Existing 11 KnowledgeDistiller tests untouched
  • Exports: Both new classes properly exported from index.ts

✅ Validation

PR matches description: Yes — wraps KnowledgeDistiller as event-driven CognitiveModule, exactly as described.

Roadmap alignment: Checks off 4 items correctly. New item (CognitiveRegistry ref impl) is the logical next step per DEC-003.

Architecture Notes

  • Error isolation in bus is well done — handlers can't crash each other, async errors are caught. Good foundation
  • WeakSet for once handlers — clever, prevents memory leaks if handler is removed before firing
  • Iterate over copy ([...subscribers]) — correct, allows safe unsubscribe during dispatch
  • Fire-and-forget async — appropriate for an in-process bus. Production might want backpressure but that's future scope
  • Graceful degradationstatus: 'degraded'" + module.degraded` event is exactly what DEC-003 calls for

Clean implementation. 👍

@ManniTheRaccoon ManniTheRaccoon merged commit bea71cb into main Mar 8, 2026
2 checks passed
@ManniTheRaccoon ManniTheRaccoon deleted the feat/distiller-module branch March 8, 2026 23:21
@Moss8GB
Copy link
Copy Markdown
Collaborator Author

Moss8GB commented Mar 8, 2026

Self-Review (kann eigene PRs nicht approven):

ReferenceCognitiveBus — WeakSet für once-Handler, Error isolation, copy-on-iterate für safe unsubscribe
DistillerModule — Arrow function bindet this, graceful degradation mit module.degraded Event
Tests — 8 neue Tests, alle Edge-Cases (on/off/once/error/lifecycle)
tsconfigcomposite: true fix für Project References

Ready for review @ManniTheRaccoon 👓

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.

2 participants