Target:
@h-rig/coreContext: Config and plugin composition library for Rigβs OMP extension ecosystem. Pure task-graph and engine logic. No app-shell assumptions.
π Quick Start
- Purpose: Orchestrates Rig configuration, plugin metadata, task graphs, and runtime dependency injection using
effectSchemas. - Initialization: Wrap configuration in
defineConfig()and plugins indefinePlugin()to separate serializable schema metadata from executable runtime components. - Host Generation: Pass validated plugins to
createPluginHost()to build the globally deduplicated registry for hooks, skills, validators, and tasks.
π§ Configuration & Composition Patterns
- Split Architecture (
metavs__runtime): Plugins strictly separate string-serializable metadata (skills, hooks, task sources) from executable implementations (functions). - Config Decoding Injection:
defineConfig()intercepts__runtimeproperties, passes the serializable metadata through strictSchema.decodeUnknownSync(RigConfig), and safely reattaches the executable__runtimeobjects to prevent validation from stripping them. - Workspace Normalization: If missing, workspace defaults to
checkout: "worktree",isolation: "worktree",sandbox: "enforce".
π‘ Best Practices
- Use
projectRootfor FS Paths: InsideTaskSourceFactoryContext, ALWAYS resolve relative config/asset paths againstcontext.projectRoot. NEVER useprocess.cwd(), as servers/extensions might spawn outside the project root. - App-Agnostic Selectors: Keep reducers and task-graph logic app-agnostic (reusable by web, TUI, server, tests). Push shared logic to
@h-rig/corebefore duplicating in UI. - Strict Runtime Matching: When providing
runtime.validatorsorruntime.taskSources, ensure their IDs,category, andkindproperties exactly match the metadata declared incontributes. - Exclusive Hook Implementations: Choose exactly ONE implementation strategy per hook: a typed function inside
runtime.hooksOR a stringcommandin metadata.
π¨ Gotchas / Anti-patterns
- Anti-pattern: Leaking functions into metadata: Attempting to put functions, promises, or classes directly into
RigPluginmetadata results in them being stripped or throwing errors duringSchema.decodeUnknownSync(). - Anti-pattern: Partial Implementations: Registering a validator/task-source in metadata without a corresponding
__runtimeimplementation (or vice-versa) immediately throws a fatal initialization error. - Anti-pattern: Dual Hook Implementation: Defining a hook with both a CLI
commandstring in metadata AND a typed implementation in__runtime.hooksthrows a fatal error. - Anti-pattern: Namespace Collisions: Reusing plugin names, validator IDs, skill IDs, or task source
kinds across plugins hard-crashescreatePluginHost()at boot. - Gotcha: Mismatched Categories/Kinds: The
categoryfor validators andkindfor task sources in the runtime objects must strictly equal the values declared in metadata. Any divergence causes a throw indefinePlugin(). - Gotcha: Path Inconsistency: Assuming
process.cwd()is the workspace root inside task-source factories breaks workspace-spawned server operations.