Files
AgentCompany/builtin-skills/software-engineer/clean-architecture/references/comp-common-reuse.md
T
ZacharyZhang-NY e74dafcd36 Silence render-disposed spam, unbreak bundled skills, drop board wake
Three independently ugly bugs that all fed the same log flood:

* Electron's `WebFrameMain.send` writes every "Render frame was disposed"
  to stderr via `console.error`. When the worker fans a second
  agent-event past a reloading renderer, we produced thousands of
  identical lines and stalled the main loop on stderr I/O. Added a
  `mainFrame.detached` guard so the send is short-circuited before
  Electron's own catch block fires, and installed a targeted filter in
  `suppress-warnings.ts` (now actually imported from the entry point)
  so the specific `console.error("Error sending from webFrameMain:"…)`
  noise never reaches the terminal. Any other payload still surfaces.

* `dispatchAgentMessage` accepted the human-reader sentinel as a wake
  target when an agent replied to `__board__` — `wakeAgentIfPossible`
  then called `db.getAgent("__board__")`, threw, and the dispatcher
  kept repeating on every send. Strip `HUMAN_SENDER_ID` at
  `resolveMessageWakeTargets`, and keep a defense-in-depth guard in the
  heartbeat so a stray caller (future automation fan-out) cannot
  reintroduce the crash.

* Pi's skills loader rejects any SKILL.md whose frontmatter `name`
  diverges from its parent directory. The four bundled `my-writing-style`
  copies declared `name: writing-style-skill`, so every install emitted
  a warning and dropped the skill. They also lived as orphan gitlinks
  (mode 160000 without .gitmodules), and the global `*.md` gitignore
  hid every other SKILL.md from version control. Fixed the frontmatter
  to match the dir, converted the dangling submodules to plain trees,
  and allowlisted `builtin-skills/**/*.md` so a fresh clone carries the
  catalogue instead of silently losing it.
2026-04-20 08:13:48 -04:00

72 lines
2.1 KiB
Markdown

---
title: Avoid Forcing Clients to Depend on Unused Code
impact: HIGH
impactDescription: reduces unnecessary recompilation and deployment
tags: comp, common-reuse, dependencies, coupling
---
## Avoid Forcing Clients to Depend on Unused Code
Classes used together should be in the same component. Classes not used together should be in separate components. Forcing a client to depend on things it doesn't use creates unnecessary coupling.
**Incorrect (monolithic utility package):**
```java
// utils/src/main/java/com/app/utils/
├── StringUtils.java
├── DateUtils.java
├── FileUtils.java
├── HttpUtils.java
├── CryptoUtils.java
├── ImageUtils.java // Depends on ImageMagick
└── PdfUtils.java // Depends on iText
// pom.xml for utils module
<dependencies>
<dependency>imagemagick</dependency> <!-- 50MB -->
<dependency>itext-pdf</dependency> <!-- 20MB -->
<dependency>bouncycastle</dependency> <!-- 10MB -->
</dependencies>
// A service that only needs StringUtils
// must now depend on all 80MB of transitive dependencies
```
**Correct (split by usage pattern):**
```java
// string-utils/
├── StringUtils.java
└── pom.xml // No heavy dependencies
// date-utils/
├── DateUtils.java
└── pom.xml
// image-processing/
├── ImageUtils.java
├── ImageResizer.java
└── pom.xml // ImageMagick dependency only here
// pdf-generation/
├── PdfUtils.java
├── PdfBuilder.java
└── pom.xml // iText dependency only here
// crypto/
├── CryptoUtils.java
├── HashingService.java
└── pom.xml // BouncyCastle dependency only here
// Services import only what they need
// order-service depends on string-utils, date-utils (2MB)
// report-service depends on string-utils, pdf-generation (22MB)
```
**Benefits:**
- Clients only pull dependencies they actually use
- Smaller deployment artifacts
- Changes to image processing don't redeploy order service
Reference: [Clean Architecture - Common Reuse Principle](https://www.oreilly.com/library/view/clean-architecture-a/9780134494272/ch13.xhtml)