mirror of
https://github.com/KeygraphHQ/shannon.git
synced 2026-04-25 01:25:52 +03:00
[PR #141] [MERGED] refactor: decompose activities into services layer with structured error handling #142
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/shannon-KeygraphHQ#142
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/KeygraphHQ/shannon/pull/141
Author: @ajmallesh
Created: 2/17/2026
Status: ✅ Merged
Merged: 2/17/2026
Merged by: @ajmallesh
Base:
main← Head:refactor/architecture📝 Commits (10+)
7fce261refactor: remove ~750 lines of dead code across 12 files4239c1crefactor: remove ~275 lines of dead code and enable stricter tsconfig9fb9d97refactor: consolidate duplicate types and file I/O utilities1ef8d37refactor: extract services layer, Result type, and ErrorCode classification7d24c52refactor: replace console.log/chalk with ActivityLogger across services81faa87feat: add resume header to workflow.log showing previous workflow ID and checkpoint62967c2refactor: consolidate file layout and break circular dependencies9eb9162refactor: remove ~70 low-value comments across 13 files1c940aedocs: update CLAUDE.md and commands for services-layer architecture7d59d4drefactor: extract helpers from long functions in client, workflows, and agent-execution📊 Changes
56 files changed (+2880 additions, -2894 deletions)
View changed files
📝
.claude/commands/debug.md(+22 -14)📝
.claude/commands/review.md(+11 -0)📝
CLAUDE.md(+35 -13)📝
package-lock.json(+0 -1)📝
package.json(+0 -1)📝
src/ai/claude-executor.ts(+53 -208)📝
src/ai/message-handlers.ts(+30 -43)📝
src/ai/output-formatters.ts(+286 -41)📝
src/ai/router-utils.ts(+0 -6)📝
src/ai/types.ts(+0 -38)📝
src/audit/audit-session.ts(+46 -29)📝
src/audit/index.ts(+0 -4)➕
src/audit/log-stream.ts(+127 -0)📝
src/audit/logger.ts(+14 -54)📝
src/audit/metrics-tracker.ts(+30 -26)📝
src/audit/utils.ts(+7 -102)📝
src/audit/workflow-logger.ts(+57 -71)➖
src/cli/input-validator.ts(+0 -59)➖
src/cli/ui.ts(+0 -49)📝
src/config-parser.ts(+297 -92)...and 36 more files
📄 Description
Motivation
Community code review by @PopoviciGabriel (#78) identified structural issues as the project has grown:
activities.tshad grown to ~500 lines mixing Temporal orchestration, git lifecycle, audit logging, and Claude SDK invocation — making it hard to extend or reason about individuallySummary
Structural refactor that establishes clear architecture boundaries without changing any external behavior. The five-phase pipeline, Temporal orchestration, and all agent behavior remain identical.
Services layer extraction — Extracted three focused services (
AgentExecutionService,ConfigLoaderService,ExploitationCheckerService) wired through a manual DI container scoped per-workflow. Activities become thin Temporal wrappers (~150 lines) that own heartbeats and error classification while services own domain logic with zero Temporal imports.Codebase restructuring — Reorganized
src/into a clear module hierarchy. Movederror-handling,git-manager,prompt-manager,queue-validation, andreportingintosrc/services/. Consolidated scattered type definitions intosrc/types/(result.ts,errors.ts,metrics.ts,audit.ts,activity-logger.ts). Deletedsrc/constants.ts— absorbed agent validators and mappings intosession-manager.tsalongside agent definitions to create a singleAGENTSregistry as the source of truth. Broke a circular dependency betweentemporal/andservices/by extracting theActivityLoggerinterface intosrc/types/. Decomposed long functions inclient.ts,workflows.ts, andagent-execution.tsinto focused helpers — extracting CLI argument parsing, workspace resolution, sequential phase execution, and failure handling into single-responsibility functions.Structured error handling — Replaced scattered string-matching error classification with an
ErrorCodeenum andResult<T,E>type. The error classifier now matches on typed codes for internal errors and falls back to string matching only for external SDK/network errors. Config validation upgraded from fail-on-first to collect-all-errors with human-readable messages. Spending cap detection consolidated from 5 locations into a sharedbilling-detection.tsutility.Logging separation — Replaced
console.log/chalk calls across services with anActivityLoggerinterface threaded via DI. Workflows use Temporal's replay-safelogimport. CLI display code keepsconsole.log— that's user-facing terminal output, not operational logging.Removed ~1,025 lines of dead code across two passes and ~70 low-value comments. Enabled stricter tsconfig (
noUnusedLocals,noUnusedParameters).🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.