Files
stack/docs/tasks/WP3-mosaic-framework-plugin.md
Mos (Agent) 10689a30d2
Some checks failed
ci/woodpecker/push/ci Pipeline failed
ci/woodpecker/pr/ci Pipeline failed
feat: monorepo consolidation — forge pipeline, MACP protocol, framework plugin, profiles/guides/skills
Work packages completed:
- WP1: packages/forge — pipeline runner, stage adapter, board tasks, brief classifier,
  persona loader with project-level overrides. 89 tests, 95.62% coverage.
- WP2: packages/macp — credential resolver, gate runner, event emitter, protocol types.
  65 tests, 96.24% coverage. Full Python-to-TS port preserving all behavior.
- WP3: plugins/mosaic-framework — OC rails injection plugin (before_agent_start +
  subagent_spawning hooks for Mosaic contract enforcement).
- WP4: profiles/ (domains, tech-stacks, workflows), guides/ (17 docs),
  skills/ (5 universal skills), forge pipeline assets (48 markdown files).

Board deliberation: docs/reviews/consolidation-board-memo.md
Brief: briefs/monorepo-consolidation.md

Consolidates mosaic/stack (forge, MACP, bootstrap framework) into mosaic/mosaic-stack.
154 new tests total. Zero Python — all TypeScript/ESM.
2026-03-30 19:43:24 +00:00

2.4 KiB

WP3: plugins/mosaic-framework — OC Rails Injection Plugin

Context

Port the OpenClaw framework plugin from ~/src/mosaic-stack/oc-plugins/mosaic-framework/ to plugins/mosaic-framework in this monorepo. This plugin injects Mosaic framework contracts (rails, completion gates, worktree requirements) into every OpenClaw agent session.

This is SEPARATE from plugins/macp:

  • mosaic-framework = passive enforcement — injects rails into all OC sessions
  • macp = active runtime — provides ACP backend for MACP task execution

Source Files

Source: ~/src/mosaic-stack/oc-plugins/mosaic-framework/

  • index.ts — plugin hooks (before_agent_start, subagent_spawning)
  • openclaw.plugin.json — plugin manifest
  • package.json

What It Does

For OC native agents (before_agent_start hook):

  • Injects Mosaic global hard rules via appendSystemContext
  • Completion gates: code review ✓ | security review ✓ | tests GREEN ✓ | CI green ✓
  • Worker completion protocol: open PR → fire system event → EXIT — never merge
  • Worktree requirement: ~/src/{repo}-worktrees/{task-slug}, never /tmp
  • Injects dynamic mission state via prependContext (reads from project's .mosaic/orchestrator/mission.json)

For ACP coding workers (subagent_spawning hook):

  • Writes ~/.codex/instructions.md or ~/.claude/CLAUDE.md BEFORE the process starts
  • Full runtime contract: mandatory load order, hard gates, mode declaration
  • Global framework rules + worktree + completion gate requirements

Implementation

Port the TypeScript source, updating hardcoded paths to be configurable. The OC plugin SDK imports should reference the installed OpenClaw location dynamically (not hardcoded /home/jarvis/ paths like the OLD version).

Structure:

plugins/mosaic-framework/
├── src/
│   └── index.ts
├── openclaw.plugin.json
├── package.json
└── tsconfig.json

Key Constraint

The plugin SDK imports in the OLD version use absolute paths:

import type { OpenClawPluginApi } from '/home/jarvis/.npm-global/lib/node_modules/openclaw/dist/plugin-sdk/index.js';

This must be resolved dynamically or via a peer dependency. Check how plugins/macp handles this in the new repo and follow the same pattern.

Tests

Minimal — plugin hooks are integration-tested against OC runtime. Unit test the context string builders and config resolution.