Conversation
… and constants BREAKING CHANGE: Reporter namespace changed from 'kernel.policy' to 'wpk.policy' - Add WPK_EVENTS constant with all public API event names: - Action lifecycle: wpk.action.start/complete/error - Resource transport: wpk.resource.request/response/error - Cache invalidation: wpk.cache.invalidated - Add WPK_INFRASTRUCTURE.ACTIONS_CHANNEL for BroadcastChannel name - Update all event emission to use WPK_EVENTS constants instead of hardcoded strings - Update namespace detection to use WPK_NAMESPACE constant instead of 'wpk/' hardcoded - Update policy reporter to use WPK_SUBSYSTEM_NAMESPACES.POLICY This eliminates ALL hardcoded namespace/event strings outside the namespace module, providing a single source of truth and preventing namespace drift. Files updated: - packages/kernel/src/namespace/constants.ts - Added WPK_EVENTS constant - packages/kernel/src/namespace/index.ts - Export WPK_EVENTS and WPKEvent type - packages/kernel/src/actions/context.ts - Use WPK_EVENTS for lifecycle events - packages/kernel/src/http/fetch.ts - Use WPK_EVENTS for resource events - packages/kernel/src/data/plugins/events.ts - Use WPK_EVENTS.ACTION_ERROR - packages/kernel/src/resource/cache.ts - Use WPK_EVENTS.CACHE_INVALIDATED - packages/kernel/src/namespace/detect.ts - Use WPK_NAMESPACE constant - packages/kernel/src/policy/context.ts - Use WPK_SUBSYSTEM_NAMESPACES.POLICY - packages/kernel/src/actions/__tests__/context.test.ts - Update test expectations Coverage: All 890 tests passing, no regression
Add comprehensive ESLint rule 'no-hardcoded-namespace-strings' that enforces usage of centralized namespace constants instead of hardcoded strings. **Rule Capabilities:** - Detects hardcoded event names (wpk.action.*, wpk.resource.*, wpk.cache.*) - Detects subsystem namespaces (wpk.policy, kernel.policy, etc.) - Detects infrastructure identifiers (BroadcastChannel names, message types) - Detects namespace prefixes in string operations (wpk/, wpk., kernel.) - Provides specific suggestions for each violation (WPK_EVENTS.*, WPK_SUBSYSTEM_NAMESPACES.*, etc.) **Smart Skipping:** - Skips namespace/constants.ts (where constants are defined) - Skips eslint-rules/ (where patterns are defined) - Skips test files (they verify actual string values) - Skips markdown files (documentation shows actual names) - Skips comments and JSDoc (documentation references) **Additional Changes:** - Add WPK_INFRASTRUCTURE.ACTIONS_MESSAGE_TYPE_LIFECYCLE constant - Add WPK_INFRASTRUCTURE.ACTIONS_MESSAGE_TYPE_EVENT constant - Update actions/context.ts to use new message type constants - Add comprehensive README.md documenting the rule This prevents namespace drift and ensures a single source of truth for all framework namespace identifiers, catching violations at lint time rather than code review. Files: - eslint-rules/no-hardcoded-namespace-strings.js (new rule) - eslint-rules/README.md (documentation) - eslint.config.js (enable rule) - packages/kernel/src/namespace/constants.ts (add message type constants) - packages/kernel/src/actions/context.ts (use new constants)
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR centralizes all namespace strings into constants in namespace/constants.ts and adds ESLint enforcement to prevent future hardcoded namespace usage. This eliminates namespace drift risk discovered during Sprint 4.5 audit and provides a single source of truth for all framework identifiers.
- Eliminated ALL hardcoded namespace strings (
'wpk.action.start','kernel.policy', etc.) across the codebase - Added comprehensive
WPK_EVENTSconstants for public API event names - Added ESLint rule with intelligent pattern detection and specific suggestions
Reviewed Changes
Copilot reviewed 12 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
packages/kernel/src/namespace/constants.ts |
Added WPK_EVENTS and infrastructure message type constants |
packages/kernel/src/namespace/index.ts |
Export WPK_EVENTS for public API |
packages/kernel/src/actions/context.ts |
Replace hardcoded event names and message types with constants |
packages/kernel/src/http/fetch.ts |
Use WPK_EVENTS for resource lifecycle events |
packages/kernel/src/data/plugins/events.ts |
Use WPK_EVENTS.ACTION_ERROR constant |
packages/kernel/src/resource/cache.ts |
Use WPK_EVENTS.CACHE_INVALIDATED constant |
packages/kernel/src/namespace/detect.ts |
Use dynamic WPK_NAMESPACE for prefix detection |
packages/kernel/src/policy/context.ts |
Use WPK_SUBSYSTEM_NAMESPACES.POLICY (breaking change from kernel.policy) |
packages/kernel/src/actions/__tests__/context.test.ts |
Update test expectations for namespace change |
eslint.config.js |
Enable new ESLint rule enforcement |
eslint-rules/no-hardcoded-namespace-strings.js |
ESLint rule implementation with pattern detection |
eslint-rules/README.md |
Comprehensive documentation for the new rule |
Comment on lines
290
to
+313
| export function emitLifecycleEvent(event: ActionLifecycleEvent): void { | ||
| const hooks = getHooks(); | ||
| if (hooks?.doAction) { | ||
| hooks.doAction(`wpk.action.${event.phase}`, event); | ||
| let eventName: string; | ||
| if (event.phase === 'start') { | ||
| eventName = WPK_EVENTS.ACTION_START; | ||
| } else if (event.phase === 'complete') { | ||
| eventName = WPK_EVENTS.ACTION_COMPLETE; | ||
| } else { | ||
| eventName = WPK_EVENTS.ACTION_ERROR; | ||
| } | ||
| hooks.doAction(eventName, event); | ||
| } | ||
|
|
||
| const runtime = getRuntime(); | ||
| if (event.bridged && runtime?.bridge?.emit) { | ||
| runtime.bridge.emit(`wpk.action.${event.phase}`, event, event); | ||
| let eventName: string; | ||
| if (event.phase === 'start') { | ||
| eventName = WPK_EVENTS.ACTION_START; | ||
| } else if (event.phase === 'complete') { | ||
| eventName = WPK_EVENTS.ACTION_COMPLETE; | ||
| } else { | ||
| eventName = WPK_EVENTS.ACTION_ERROR; | ||
| } |
There was a problem hiding this comment.
The if-else chain for mapping event phases to event names is duplicated in lines 306-313. Consider extracting this logic into a helper function to reduce code duplication.
pipewrk
added a commit
that referenced
this pull request
Nov 8, 2025
…constants refactor(namespace): centralize all namespace strings and add ESLint enforcement
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR eliminates ALL hardcoded namespace and event name strings outside the
namespacemodule, providing a single source of truth and preventing namespace drift. It also adds an ESLint rule to prevent future violations.Motivation
After Sprint 4.5 merge, a comprehensive framework-wide audit revealed hardcoded namespace strings scattered across multiple modules:
wpk.action.*,wpk.resource.*,wpk.cache.*stringskernel.policyvswpk.policy'wpk/'prefixProblems with Hardcoded Strings
Changes
1. New Constants Added
WPK_EVENTS - Public API event names:
WPK_INFRASTRUCTURE - Added BroadcastChannel message types:
2. Files Updated
Namespace Constants (
packages/kernel/src/namespace/constants.ts)WPK_EVENTSconstant with all 7 public API event namesWPK_INFRASTRUCTURE.ACTIONS_MESSAGE_TYPE_LIFECYCLEWPK_INFRASTRUCTURE.ACTIONS_MESSAGE_TYPE_EVENTWPKEventtype for type safetyAction Context (
packages/kernel/src/actions/context.ts)WPK_EVENTS.ACTION_START/COMPLETE/ERROR'wpk.actions'withWPK_INFRASTRUCTURE.ACTIONS_CHANNELWPK_INFRASTRUCTURE.ACTIONS_MESSAGE_TYPE_*HTTP Transport (
packages/kernel/src/http/fetch.ts)'wpk.resource.request/response/error'withWPK_EVENTS.RESOURCE_*Events Plugin (
packages/kernel/src/data/plugins/events.ts)'wpk.action.error'withWPK_EVENTS.ACTION_ERRORCache Invalidation (
packages/kernel/src/resource/cache.ts)'wpk.cache.invalidated'withWPK_EVENTS.CACHE_INVALIDATEDNamespace Detection (
packages/kernel/src/namespace/detect.ts)'wpk/'with dynamic${WPK_NAMESPACE}/Policy Context (
packages/kernel/src/policy/context.ts)'kernel.policy'withWPK_SUBSYSTEM_NAMESPACES.POLICYTests (
packages/kernel/src/actions/__tests__/context.test.ts)[kernel.policy]to[wpk.policy]3. ESLint Rule Added
New Rule:
@kernel/no-hardcoded-namespace-stringsDetects and prevents hardcoded namespace strings:
Rule Features:
Documentation: Comprehensive README at
eslint-rules/README.mdBreaking Changes
Reporter Namespace Change
BREAKING: Reporter namespace changed from
kernel.policytowpk.policyImpact: External code listening to policy events must update event listeners.
Migration:
Verification
Search Results (Zero Hardcoded Strings)
Test Results
ESLint Rule Testing
Created test file with violations - rule correctly detected all 3 patterns:
Benefits
namespace/constants.ts'wpk.acton.start'vs'wpk.action.start'Related Issues
Follow-up from Sprint 4.5 namespace drift discovery during PR #62 review.
Files Changed
Added (2 files, +525 lines):
eslint-rules/no-hardcoded-namespace-strings.js- ESLint rule implementationeslint-rules/README.md- Comprehensive documentationModified (11 files):
packages/kernel/src/namespace/constants.ts- Added WPK_EVENTS + infrastructure constantspackages/kernel/src/namespace/index.ts- Export WPK_EVENTSpackages/kernel/src/actions/context.ts- Use constants for events + message typespackages/kernel/src/http/fetch.ts- Use WPK_EVENTS for resource eventspackages/kernel/src/data/plugins/events.ts- Use WPK_EVENTS.ACTION_ERRORpackages/kernel/src/resource/cache.ts- Use WPK_EVENTS.CACHE_INVALIDATEDpackages/kernel/src/namespace/detect.ts- Use WPK_NAMESPACE constantpackages/kernel/src/policy/context.ts- Use WPK_SUBSYSTEM_NAMESPACES.POLICYpackages/kernel/src/actions/__tests__/context.test.ts- Update test expectationseslint.config.js- Enable new ESLint ruledocs/api/generated/http/functions/fetch.md- Auto-generated doc updateChecklist