Compare commits
88 Commits
chore/bump
...
feat/feder
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f74fc9687f | ||
|
|
7383380f64 | ||
| 58169f9979 | |||
| 51402bdb6d | |||
| 9c89c32684 | |||
| 8aabb8c5b2 | |||
| 66512550df | |||
| 46dd799548 | |||
| 5f03c05523 | |||
| c3f810bbd1 | |||
| b2cbf898d7 | |||
| b2cec8c6ba | |||
| 81c1775a03 | |||
| f64ec12f39 | |||
| 026382325c | |||
| 1bfd8570d6 | |||
| 312acd8bad | |||
| d08b969918 | |||
| 051de0d8a9 | |||
| bd76df1a50 | |||
| 62b2ce2da1 | |||
| 172bacb30f | |||
| 43667d7349 | |||
| 783884376c | |||
| c08aa6fa46 | |||
| 0ae932ab34 | |||
| a8cd52e88c | |||
| a4c94d9a90 | |||
| cee838d22e | |||
| 732f8a49cf | |||
| be917e2496 | |||
| cd8b1f666d | |||
| 8fa5995bde | |||
| 25cada7735 | |||
| be6553101c | |||
| 417805f330 | |||
| 2472ce52e8 | |||
| 597eb232d7 | |||
| afe997db82 | |||
| b9d464de61 | |||
| 872c124581 | |||
| a531029c5b | |||
| 35ab619bd0 | |||
| 831193cdd8 | |||
| df460d5a49 | |||
| 119ff0eb1b | |||
| 3abd63ea5c | |||
| 641e4604d5 | |||
|
|
9b5ecc0171 | ||
|
|
a00325da0e | ||
| 4ebce3422d | |||
| 751e0ee330 | |||
| 54b2920ef3 | |||
| 5917016509 | |||
| 7b4f1d249d | |||
| 5425f9268e | |||
| febd866098 | |||
| 2446593fff | |||
| 651426cf2e | |||
| cf46f6e0ae | |||
| 6f15a84ccf | |||
| c39433c361 | |||
| 257796ce87 | |||
|
|
2357602f50 | ||
| 1230f6b984 | |||
| 14b775f1b9 | |||
|
|
c7691d9807 | ||
| 9a53d55678 | |||
|
|
31008ef7ff | ||
| 621ab260c0 | |||
| 2b1840214e | |||
|
|
5cfccc2ead | ||
|
|
774b76447d | ||
| 80994bdc8e | |||
| 2e31626f87 | |||
| 255ba46a4d | |||
| 10285933a0 | |||
| 543388e18b | |||
| 07a1f5d594 | |||
|
|
c6fc090c98 | ||
| 9723b6b948 | |||
| c0d0fd44b7 | |||
| 30c0fb1308 | |||
| 26fac4722f | |||
| e3f64c79d9 | |||
| cbd5e8c626 | |||
| 7560c7dee7 | |||
| 982a0e8f83 |
12
.env.example
12
.env.example
@@ -23,8 +23,8 @@ VALKEY_URL=redis://localhost:6380
|
|||||||
|
|
||||||
|
|
||||||
# ─── Gateway ─────────────────────────────────────────────────────────────────
|
# ─── Gateway ─────────────────────────────────────────────────────────────────
|
||||||
# TCP port the NestJS/Fastify gateway listens on (default: 4000)
|
# TCP port the NestJS/Fastify gateway listens on (default: 14242)
|
||||||
GATEWAY_PORT=4000
|
GATEWAY_PORT=14242
|
||||||
|
|
||||||
# Comma-separated list of allowed CORS origins.
|
# Comma-separated list of allowed CORS origins.
|
||||||
# Must include the web app origin in production.
|
# Must include the web app origin in production.
|
||||||
@@ -37,12 +37,12 @@ GATEWAY_CORS_ORIGIN=http://localhost:3000
|
|||||||
BETTER_AUTH_SECRET=change-me-to-a-random-32-char-string
|
BETTER_AUTH_SECRET=change-me-to-a-random-32-char-string
|
||||||
|
|
||||||
# Public base URL of the gateway (used by BetterAuth for callback URLs)
|
# Public base URL of the gateway (used by BetterAuth for callback URLs)
|
||||||
BETTER_AUTH_URL=http://localhost:4000
|
BETTER_AUTH_URL=http://localhost:14242
|
||||||
|
|
||||||
|
|
||||||
# ─── Web App (Next.js) ───────────────────────────────────────────────────────
|
# ─── Web App (Next.js) ───────────────────────────────────────────────────────
|
||||||
# Public gateway URL — accessible from the browser, not just the server.
|
# Public gateway URL — accessible from the browser, not just the server.
|
||||||
NEXT_PUBLIC_GATEWAY_URL=http://localhost:4000
|
NEXT_PUBLIC_GATEWAY_URL=http://localhost:14242
|
||||||
|
|
||||||
|
|
||||||
# ─── OpenTelemetry ───────────────────────────────────────────────────────────
|
# ─── OpenTelemetry ───────────────────────────────────────────────────────────
|
||||||
@@ -121,12 +121,12 @@ OTEL_SERVICE_NAME=mosaic-gateway
|
|||||||
# ─── Discord Plugin (optional — set DISCORD_BOT_TOKEN to enable) ─────────────
|
# ─── Discord Plugin (optional — set DISCORD_BOT_TOKEN to enable) ─────────────
|
||||||
# DISCORD_BOT_TOKEN=
|
# DISCORD_BOT_TOKEN=
|
||||||
# DISCORD_GUILD_ID=
|
# DISCORD_GUILD_ID=
|
||||||
# DISCORD_GATEWAY_URL=http://localhost:4000
|
# DISCORD_GATEWAY_URL=http://localhost:14242
|
||||||
|
|
||||||
|
|
||||||
# ─── Telegram Plugin (optional — set TELEGRAM_BOT_TOKEN to enable) ───────────
|
# ─── Telegram Plugin (optional — set TELEGRAM_BOT_TOKEN to enable) ───────────
|
||||||
# TELEGRAM_BOT_TOKEN=
|
# TELEGRAM_BOT_TOKEN=
|
||||||
# TELEGRAM_GATEWAY_URL=http://localhost:4000
|
# TELEGRAM_GATEWAY_URL=http://localhost:14242
|
||||||
|
|
||||||
|
|
||||||
# ─── SSO Providers (add credentials to enable) ───────────────────────────────
|
# ─── SSO Providers (add credentials to enable) ───────────────────────────────
|
||||||
|
|||||||
2
.npmrc
2
.npmrc
@@ -1 +1 @@
|
|||||||
@mosaic:registry=https://git.mosaicstack.dev/api/packages/mosaic/npm/
|
@mosaicstack:registry=https://git.mosaicstack.dev/api/packages/mosaicstack/npm/
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ steps:
|
|||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
# Run migrations (DATABASE_URL is set in environment above)
|
# Run migrations (DATABASE_URL is set in environment above)
|
||||||
- pnpm --filter @mosaic/db run db:migrate
|
- pnpm --filter @mosaicstack/db run db:migrate
|
||||||
# Run all tests
|
# Run all tests
|
||||||
- pnpm test
|
- pnpm test
|
||||||
depends_on:
|
depends_on:
|
||||||
|
|||||||
@@ -33,15 +33,44 @@ steps:
|
|||||||
- *enable_pnpm
|
- *enable_pnpm
|
||||||
# Configure auth for Gitea npm registry
|
# Configure auth for Gitea npm registry
|
||||||
- |
|
- |
|
||||||
echo "//git.mosaicstack.dev/api/packages/mosaic/npm/:_authToken=$NPM_TOKEN" > ~/.npmrc
|
echo "//git.mosaicstack.dev/api/packages/mosaicstack/npm/:_authToken=$NPM_TOKEN" > ~/.npmrc
|
||||||
echo "@mosaic:registry=https://git.mosaicstack.dev/api/packages/mosaic/npm/" >> ~/.npmrc
|
echo "@mosaicstack:registry=https://git.mosaicstack.dev/api/packages/mosaicstack/npm/" >> ~/.npmrc
|
||||||
# Publish non-private packages to Gitea (--no-git-checks skips dirty/branch checks in CI)
|
# Publish non-private packages to Gitea.
|
||||||
# --filter excludes web (private)
|
#
|
||||||
- >
|
# The only publish failure we tolerate is "version already exists" —
|
||||||
pnpm --filter "@mosaic/*"
|
# that legitimately happens when only some packages were bumped in
|
||||||
--filter "!@mosaic/web"
|
# the merge. Any other failure (registry 404, auth error, network
|
||||||
publish --no-git-checks --access public
|
# error) MUST fail the pipeline loudly: the previous
|
||||||
|| echo "[publish] Some packages may already exist at this version — continuing"
|
# `|| echo "... continuing"` fallback silently hid a 404 from the
|
||||||
|
# Gitea org rename and caused every @mosaicstack/* publish to fall
|
||||||
|
# on the floor while CI still reported green.
|
||||||
|
- |
|
||||||
|
# Portable sh (Alpine ash) — avoid bashisms like PIPESTATUS.
|
||||||
|
set +e
|
||||||
|
pnpm --filter "@mosaicstack/*" --filter "!@mosaicstack/web" publish --no-git-checks --access public >/tmp/publish.log 2>&1
|
||||||
|
EXIT=$?
|
||||||
|
set -e
|
||||||
|
cat /tmp/publish.log
|
||||||
|
if [ "$EXIT" -eq 0 ]; then
|
||||||
|
echo "[publish] all packages published successfully"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
# Hard registry / auth / network errors → fatal. Match npm's own
|
||||||
|
# error lines specifically to avoid false positives on arbitrary
|
||||||
|
# log text that happens to contain "E404" etc.
|
||||||
|
if grep -qE "npm (error|ERR!) code (E404|E401|ENEEDAUTH|ECONNREFUSED|ETIMEDOUT|ENOTFOUND)" /tmp/publish.log; then
|
||||||
|
echo "[publish] FATAL: registry/auth/network error detected — failing pipeline" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
# Only tolerate the explicit "version already published" case.
|
||||||
|
# npm returns this as E403 with body "You cannot publish over..."
|
||||||
|
# or EPUBLISHCONFLICT depending on version.
|
||||||
|
if grep -qE "EPUBLISHCONFLICT|You cannot publish over|previously published" /tmp/publish.log; then
|
||||||
|
echo "[publish] some packages already at this version — continuing (non-fatal)"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
echo "[publish] FATAL: publish failed with unrecognized error — failing pipeline" >&2
|
||||||
|
exit 1
|
||||||
depends_on:
|
depends_on:
|
||||||
- build
|
- build
|
||||||
|
|
||||||
@@ -74,12 +103,12 @@ steps:
|
|||||||
- mkdir -p /kaniko/.docker
|
- mkdir -p /kaniko/.docker
|
||||||
- echo "{\"auths\":{\"git.mosaicstack.dev\":{\"username\":\"$REGISTRY_USER\",\"password\":\"$REGISTRY_PASS\"}}}" > /kaniko/.docker/config.json
|
- echo "{\"auths\":{\"git.mosaicstack.dev\":{\"username\":\"$REGISTRY_USER\",\"password\":\"$REGISTRY_PASS\"}}}" > /kaniko/.docker/config.json
|
||||||
- |
|
- |
|
||||||
DESTINATIONS="--destination git.mosaicstack.dev/mosaic/mosaic-stack/gateway:sha-${CI_COMMIT_SHA:0:7}"
|
DESTINATIONS="--destination git.mosaicstack.dev/mosaicstack/stack/gateway:sha-${CI_COMMIT_SHA:0:7}"
|
||||||
if [ "$CI_COMMIT_BRANCH" = "main" ]; then
|
if [ "$CI_COMMIT_BRANCH" = "main" ]; then
|
||||||
DESTINATIONS="$DESTINATIONS --destination git.mosaicstack.dev/mosaic/mosaic-stack/gateway:latest"
|
DESTINATIONS="$DESTINATIONS --destination git.mosaicstack.dev/mosaicstack/stack/gateway:latest"
|
||||||
fi
|
fi
|
||||||
if [ -n "$CI_COMMIT_TAG" ]; then
|
if [ -n "$CI_COMMIT_TAG" ]; then
|
||||||
DESTINATIONS="$DESTINATIONS --destination git.mosaicstack.dev/mosaic/mosaic-stack/gateway:$CI_COMMIT_TAG"
|
DESTINATIONS="$DESTINATIONS --destination git.mosaicstack.dev/mosaicstack/stack/gateway:$CI_COMMIT_TAG"
|
||||||
fi
|
fi
|
||||||
/kaniko/executor --context . --dockerfile docker/gateway.Dockerfile $DESTINATIONS
|
/kaniko/executor --context . --dockerfile docker/gateway.Dockerfile $DESTINATIONS
|
||||||
depends_on:
|
depends_on:
|
||||||
@@ -99,12 +128,12 @@ steps:
|
|||||||
- mkdir -p /kaniko/.docker
|
- mkdir -p /kaniko/.docker
|
||||||
- echo "{\"auths\":{\"git.mosaicstack.dev\":{\"username\":\"$REGISTRY_USER\",\"password\":\"$REGISTRY_PASS\"}}}" > /kaniko/.docker/config.json
|
- echo "{\"auths\":{\"git.mosaicstack.dev\":{\"username\":\"$REGISTRY_USER\",\"password\":\"$REGISTRY_PASS\"}}}" > /kaniko/.docker/config.json
|
||||||
- |
|
- |
|
||||||
DESTINATIONS="--destination git.mosaicstack.dev/mosaic/mosaic-stack/web:sha-${CI_COMMIT_SHA:0:7}"
|
DESTINATIONS="--destination git.mosaicstack.dev/mosaicstack/stack/web:sha-${CI_COMMIT_SHA:0:7}"
|
||||||
if [ "$CI_COMMIT_BRANCH" = "main" ]; then
|
if [ "$CI_COMMIT_BRANCH" = "main" ]; then
|
||||||
DESTINATIONS="$DESTINATIONS --destination git.mosaicstack.dev/mosaic/mosaic-stack/web:latest"
|
DESTINATIONS="$DESTINATIONS --destination git.mosaicstack.dev/mosaicstack/stack/web:latest"
|
||||||
fi
|
fi
|
||||||
if [ -n "$CI_COMMIT_TAG" ]; then
|
if [ -n "$CI_COMMIT_TAG" ]; then
|
||||||
DESTINATIONS="$DESTINATIONS --destination git.mosaicstack.dev/mosaic/mosaic-stack/web:$CI_COMMIT_TAG"
|
DESTINATIONS="$DESTINATIONS --destination git.mosaicstack.dev/mosaicstack/stack/web:$CI_COMMIT_TAG"
|
||||||
fi
|
fi
|
||||||
/kaniko/executor --context . --dockerfile docker/web.Dockerfile $DESTINATIONS
|
/kaniko/executor --context . --dockerfile docker/web.Dockerfile $DESTINATIONS
|
||||||
depends_on:
|
depends_on:
|
||||||
|
|||||||
28
AGENTS.md
28
AGENTS.md
@@ -21,11 +21,11 @@ Mosaic Stack is a self-hosted, multi-user AI agent platform. TypeScript monorepo
|
|||||||
| `apps/web` | Next.js dashboard | React 19, Tailwind |
|
| `apps/web` | Next.js dashboard | React 19, Tailwind |
|
||||||
| `packages/types` | Shared TypeScript contracts | class-validator |
|
| `packages/types` | Shared TypeScript contracts | class-validator |
|
||||||
| `packages/db` | Drizzle ORM schema + migrations | drizzle-orm, postgres |
|
| `packages/db` | Drizzle ORM schema + migrations | drizzle-orm, postgres |
|
||||||
| `packages/auth` | BetterAuth configuration | better-auth, @mosaic/db |
|
| `packages/auth` | BetterAuth configuration | better-auth, @mosaicstack/db |
|
||||||
| `packages/brain` | Data layer (PG-backed) | @mosaic/db |
|
| `packages/brain` | Data layer (PG-backed) | @mosaicstack/db |
|
||||||
| `packages/queue` | Valkey task queue + MCP | ioredis |
|
| `packages/queue` | Valkey task queue + MCP | ioredis |
|
||||||
| `packages/coord` | Mission coordination | @mosaic/queue |
|
| `packages/coord` | Mission coordination | @mosaicstack/queue |
|
||||||
| `packages/cli` | Unified CLI + Pi TUI | Ink, Pi SDK |
|
| `packages/mosaic` | Unified `mosaic` CLI + TUI | Ink, Pi SDK, commander |
|
||||||
| `plugins/discord` | Discord channel plugin | discord.js |
|
| `plugins/discord` | Discord channel plugin | discord.js |
|
||||||
| `plugins/telegram` | Telegram channel plugin | Telegraf |
|
| `plugins/telegram` | Telegram channel plugin | Telegraf |
|
||||||
|
|
||||||
@@ -33,9 +33,9 @@ Mosaic Stack is a self-hosted, multi-user AI agent platform. TypeScript monorepo
|
|||||||
|
|
||||||
1. Gateway is the single API surface — all clients connect through it
|
1. Gateway is the single API surface — all clients connect through it
|
||||||
2. Pi SDK is ESM-only — gateway and CLI must use ESM
|
2. Pi SDK is ESM-only — gateway and CLI must use ESM
|
||||||
3. Socket.IO typed events defined in `@mosaic/types` enforce compile-time contracts
|
3. Socket.IO typed events defined in `@mosaicstack/types` enforce compile-time contracts
|
||||||
4. OTEL auto-instrumentation loads before NestJS bootstrap
|
4. OTEL auto-instrumentation loads before NestJS bootstrap
|
||||||
5. BetterAuth manages auth tables; schema defined in `@mosaic/db`
|
5. BetterAuth manages auth tables; schema defined in `@mosaicstack/db`
|
||||||
6. Docker Compose provides PG (5433), Valkey (6380), OTEL Collector (4317/4318), Jaeger (16686)
|
6. Docker Compose provides PG (5433), Valkey (6380), OTEL Collector (4317/4318), Jaeger (16686)
|
||||||
7. Explicit `@Inject()` decorators required in NestJS (tsx/esbuild doesn't emit decorator metadata)
|
7. Explicit `@Inject()` decorators required in NestJS (tsx/esbuild doesn't emit decorator metadata)
|
||||||
|
|
||||||
@@ -58,14 +58,14 @@ pnpm typecheck && pnpm lint && pnpm format:check # Quality gates
|
|||||||
|
|
||||||
The `agent` column specifies the required model for each task. **This is set at task creation by the orchestrator and must not be changed by workers.**
|
The `agent` column specifies the required model for each task. **This is set at task creation by the orchestrator and must not be changed by workers.**
|
||||||
|
|
||||||
| Value | When to use | Budget |
|
| Value | When to use | Budget |
|
||||||
| -------- | ----------------------------------------------------------- | -------------------------- |
|
| --------- | ----------------------------------------------------------- | -------------------------- |
|
||||||
| `codex` | All coding tasks (default for implementation) | OpenAI credits — preferred |
|
| `codex` | All coding tasks (default for implementation) | OpenAI credits — preferred |
|
||||||
| `glm-5` | Cost-sensitive coding where Codex is unavailable | Z.ai credits |
|
| `glm-5.1` | Cost-sensitive coding where Codex is unavailable | Z.ai credits |
|
||||||
| `haiku` | Review gates, verify tasks, status checks, docs-only | Cheapest Claude tier |
|
| `haiku` | Review gates, verify tasks, status checks, docs-only | Cheapest Claude tier |
|
||||||
| `sonnet` | Complex planning, multi-file reasoning, architecture review | Claude quota |
|
| `sonnet` | Complex planning, multi-file reasoning, architecture review | Claude quota |
|
||||||
| `opus` | Major cross-cutting architecture decisions ONLY | Most expensive — minimize |
|
| `opus` | Major cross-cutting architecture decisions ONLY | Most expensive — minimize |
|
||||||
| `—` | No preference / auto-select cheapest capable | Pipeline decides |
|
| `—` | No preference / auto-select cheapest capable | Pipeline decides |
|
||||||
|
|
||||||
Pipeline crons read this column and spawn accordingly. Workers never modify `docs/TASKS.md` — only the orchestrator writes it.
|
Pipeline crons read this column and spawn accordingly. Workers never modify `docs/TASKS.md` — only the orchestrator writes it.
|
||||||
|
|
||||||
|
|||||||
10
CLAUDE.md
10
CLAUDE.md
@@ -10,7 +10,7 @@ Self-hosted, multi-user AI agent platform. TypeScript monorepo.
|
|||||||
- **Web**: Next.js 16 + React 19 (`apps/web`)
|
- **Web**: Next.js 16 + React 19 (`apps/web`)
|
||||||
- **ORM**: Drizzle ORM + PostgreSQL 17 + pgvector (`packages/db`)
|
- **ORM**: Drizzle ORM + PostgreSQL 17 + pgvector (`packages/db`)
|
||||||
- **Auth**: BetterAuth (`packages/auth`)
|
- **Auth**: BetterAuth (`packages/auth`)
|
||||||
- **Agent**: Pi SDK (`packages/agent`, `packages/cli`)
|
- **Agent**: Pi SDK (`packages/agent`, `packages/mosaic`)
|
||||||
- **Queue**: Valkey 8 (`packages/queue`)
|
- **Queue**: Valkey 8 (`packages/queue`)
|
||||||
- **Build**: pnpm workspaces + Turborepo
|
- **Build**: pnpm workspaces + Turborepo
|
||||||
- **CI**: Woodpecker CI
|
- **CI**: Woodpecker CI
|
||||||
@@ -26,13 +26,13 @@ pnpm test # Vitest (all packages)
|
|||||||
pnpm build # Build all packages
|
pnpm build # Build all packages
|
||||||
|
|
||||||
# Database
|
# Database
|
||||||
pnpm --filter @mosaic/db db:push # Push schema to PG (dev)
|
pnpm --filter @mosaicstack/db db:push # Push schema to PG (dev)
|
||||||
pnpm --filter @mosaic/db db:generate # Generate migrations
|
pnpm --filter @mosaicstack/db db:generate # Generate migrations
|
||||||
pnpm --filter @mosaic/db db:migrate # Run migrations
|
pnpm --filter @mosaicstack/db db:migrate # Run migrations
|
||||||
|
|
||||||
# Dev
|
# Dev
|
||||||
docker compose up -d # Start PG, Valkey, OTEL, Jaeger
|
docker compose up -d # Start PG, Valkey, OTEL, Jaeger
|
||||||
pnpm --filter @mosaic/gateway exec tsx src/main.ts # Start gateway
|
pnpm --filter @mosaicstack/gateway exec tsx src/main.ts # Start gateway
|
||||||
```
|
```
|
||||||
|
|
||||||
## Conventions
|
## Conventions
|
||||||
|
|||||||
160
README.md
160
README.md
@@ -7,26 +7,39 @@ Mosaic gives you a unified launcher for Claude Code, Codex, OpenCode, and Pi —
|
|||||||
## Quick Install
|
## Quick Install
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
bash <(curl -fsSL https://git.mosaicstack.dev/mosaic/mosaic-stack/raw/branch/main/tools/install.sh)
|
curl -fsSL https://mosaicstack.dev/install.sh | bash
|
||||||
|
```
|
||||||
|
|
||||||
|
Or use the direct URL:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bash <(curl -fsSL https://git.mosaicstack.dev/mosaicstack/stack/raw/branch/main/tools/install.sh)
|
||||||
|
```
|
||||||
|
|
||||||
|
The installer auto-launches the setup wizard, which walks you through gateway install and verification. Flags for non-interactive use:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bash <(curl -fsSL …) --yes # Accept all defaults
|
||||||
|
bash <(curl -fsSL …) --yes --no-auto-launch # Install only, skip wizard
|
||||||
```
|
```
|
||||||
|
|
||||||
This installs both components:
|
This installs both components:
|
||||||
|
|
||||||
| Component | What | Where |
|
| Component | What | Where |
|
||||||
| --------------- | ----------------------------------------------------- | -------------------- |
|
| ----------------------- | ---------------------------------------------------------------- | -------------------- |
|
||||||
| **Framework** | Bash launcher, guides, runtime configs, tools, skills | `~/.config/mosaic/` |
|
| **Framework** | Bash launcher, guides, runtime configs, tools, skills | `~/.config/mosaic/` |
|
||||||
| **@mosaic/cli** | TUI, gateway client, wizard, auto-updater | `~/.npm-global/bin/` |
|
| **@mosaicstack/mosaic** | Unified `mosaic` CLI — TUI, gateway client, wizard, auto-updater | `~/.npm-global/bin/` |
|
||||||
|
|
||||||
After install, set up your agent identity:
|
After install, the wizard runs automatically or you can invoke it manually:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
mosaic init # Interactive wizard
|
mosaic wizard # Full guided setup (gateway install → verify)
|
||||||
```
|
```
|
||||||
|
|
||||||
### Requirements
|
### Requirements
|
||||||
|
|
||||||
- Node.js ≥ 20
|
- Node.js ≥ 20
|
||||||
- npm (for global @mosaic/cli install)
|
- npm (for global @mosaicstack/mosaic install)
|
||||||
- One or more runtimes: [Claude Code](https://docs.anthropic.com/en/docs/claude-code), [Codex](https://github.com/openai/codex), [OpenCode](https://opencode.ai), or [Pi](https://github.com/mariozechner/pi-coding-agent)
|
- One or more runtimes: [Claude Code](https://docs.anthropic.com/en/docs/claude-code), [Codex](https://github.com/openai/codex), [OpenCode](https://opencode.ai), or [Pi](https://github.com/mariozechner/pi-coding-agent)
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
@@ -49,10 +62,32 @@ The launcher verifies your config, checks for `SOUL.md`, injects your `AGENTS.md
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
mosaic tui # Interactive TUI connected to the gateway
|
mosaic tui # Interactive TUI connected to the gateway
|
||||||
mosaic login # Authenticate with a gateway instance
|
mosaic gateway login # Authenticate with a gateway instance
|
||||||
mosaic sessions list # List active agent sessions
|
mosaic sessions list # List active agent sessions
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Gateway Management
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mosaic gateway install # Install and configure the gateway service
|
||||||
|
mosaic gateway verify # Post-install health check
|
||||||
|
mosaic gateway login # Authenticate and store a session token
|
||||||
|
mosaic gateway config rotate-token # Rotate your API token
|
||||||
|
mosaic gateway config recover-token # Recover a token via BetterAuth cookie
|
||||||
|
```
|
||||||
|
|
||||||
|
If you already have a gateway account but no token, use `mosaic gateway config recover-token` to retrieve one without recreating your account.
|
||||||
|
|
||||||
|
### Configuration
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mosaic config show # Print full config as JSON
|
||||||
|
mosaic config get <key> # Read a specific key
|
||||||
|
mosaic config set <key> <val># Write a key
|
||||||
|
mosaic config edit # Open config in $EDITOR
|
||||||
|
mosaic config path # Print config file path
|
||||||
|
```
|
||||||
|
|
||||||
### Management
|
### Management
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@@ -65,6 +100,80 @@ mosaic coord init # Initialize a new orchestration mission
|
|||||||
mosaic prdy init # Create a PRD via guided session
|
mosaic prdy init # Create a PRD via guided session
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Sub-package Commands
|
||||||
|
|
||||||
|
Each Mosaic sub-package exposes its API surface through the unified CLI:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# User management
|
||||||
|
mosaic auth users list
|
||||||
|
mosaic auth users create
|
||||||
|
mosaic auth sso
|
||||||
|
|
||||||
|
# Agent brain (projects, missions, tasks)
|
||||||
|
mosaic brain projects
|
||||||
|
mosaic brain missions
|
||||||
|
mosaic brain tasks
|
||||||
|
mosaic brain conversations
|
||||||
|
|
||||||
|
# Agent forge pipeline
|
||||||
|
mosaic forge run
|
||||||
|
mosaic forge status
|
||||||
|
mosaic forge resume
|
||||||
|
mosaic forge personas
|
||||||
|
|
||||||
|
# Structured logging
|
||||||
|
mosaic log tail
|
||||||
|
mosaic log search
|
||||||
|
mosaic log export
|
||||||
|
mosaic log level
|
||||||
|
|
||||||
|
# MACP protocol
|
||||||
|
mosaic macp tasks
|
||||||
|
mosaic macp submit
|
||||||
|
mosaic macp gate
|
||||||
|
mosaic macp events
|
||||||
|
|
||||||
|
# Agent memory
|
||||||
|
mosaic memory search
|
||||||
|
mosaic memory stats
|
||||||
|
mosaic memory insights
|
||||||
|
mosaic memory preferences
|
||||||
|
|
||||||
|
# Task queue (Valkey)
|
||||||
|
mosaic queue list
|
||||||
|
mosaic queue stats
|
||||||
|
mosaic queue pause
|
||||||
|
mosaic queue resume
|
||||||
|
mosaic queue jobs
|
||||||
|
mosaic queue drain
|
||||||
|
|
||||||
|
# Object storage
|
||||||
|
mosaic storage status
|
||||||
|
mosaic storage tier
|
||||||
|
mosaic storage export
|
||||||
|
mosaic storage import
|
||||||
|
mosaic storage migrate
|
||||||
|
```
|
||||||
|
|
||||||
|
### Telemetry
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Local observability (OTEL / Jaeger)
|
||||||
|
mosaic telemetry local status
|
||||||
|
mosaic telemetry local tail
|
||||||
|
mosaic telemetry local jaeger
|
||||||
|
|
||||||
|
# Remote telemetry (dry-run by default)
|
||||||
|
mosaic telemetry status
|
||||||
|
mosaic telemetry opt-in
|
||||||
|
mosaic telemetry opt-out
|
||||||
|
mosaic telemetry test
|
||||||
|
mosaic telemetry upload # Dry-run unless opted in
|
||||||
|
```
|
||||||
|
|
||||||
|
Consent state is persisted in config. Remote upload is a no-op until you run `mosaic telemetry opt-in`.
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
|
|
||||||
### Prerequisites
|
### Prerequisites
|
||||||
@@ -76,8 +185,8 @@ mosaic prdy init # Create a PRD via guided session
|
|||||||
### Setup
|
### Setup
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git clone git@git.mosaicstack.dev:mosaic/mosaic-stack.git
|
git clone git@git.mosaicstack.dev:mosaicstack/stack.git
|
||||||
cd mosaic-stack
|
cd stack
|
||||||
|
|
||||||
# Start infrastructure (Postgres, Valkey, Jaeger)
|
# Start infrastructure (Postgres, Valkey, Jaeger)
|
||||||
docker compose up -d
|
docker compose up -d
|
||||||
@@ -86,7 +195,7 @@ docker compose up -d
|
|||||||
pnpm install
|
pnpm install
|
||||||
|
|
||||||
# Run migrations
|
# Run migrations
|
||||||
pnpm --filter @mosaic/db run db:migrate
|
pnpm --filter @mosaicstack/db run db:migrate
|
||||||
|
|
||||||
# Start all services in dev mode
|
# Start all services in dev mode
|
||||||
pnpm dev
|
pnpm dev
|
||||||
@@ -126,13 +235,12 @@ npm packages are published to the Gitea package registry on main merges.
|
|||||||
## Architecture
|
## Architecture
|
||||||
|
|
||||||
```
|
```
|
||||||
mosaic-stack/
|
stack/
|
||||||
├── apps/
|
├── apps/
|
||||||
│ ├── gateway/ NestJS API + WebSocket hub (Fastify, Socket.IO, OTEL)
|
│ ├── gateway/ NestJS API + WebSocket hub (Fastify, Socket.IO, OTEL)
|
||||||
│ └── web/ Next.js dashboard (React 19, Tailwind)
|
│ └── web/ Next.js dashboard (React 19, Tailwind)
|
||||||
├── packages/
|
├── packages/
|
||||||
│ ├── cli/ Mosaic CLI — TUI, gateway client, wizard
|
│ ├── mosaic/ Unified CLI — TUI, gateway client, wizard, sub-package commands
|
||||||
│ ├── mosaic/ Framework — wizard, runtime detection, update checker
|
|
||||||
│ ├── types/ Shared TypeScript contracts (Socket.IO typed events)
|
│ ├── types/ Shared TypeScript contracts (Socket.IO typed events)
|
||||||
│ ├── db/ Drizzle ORM schema + migrations (pgvector)
|
│ ├── db/ Drizzle ORM schema + migrations (pgvector)
|
||||||
│ ├── auth/ BetterAuth configuration
|
│ ├── auth/ BetterAuth configuration
|
||||||
@@ -153,7 +261,7 @@ mosaic-stack/
|
|||||||
│ ├── macp/ OpenClaw MACP runtime plugin
|
│ ├── macp/ OpenClaw MACP runtime plugin
|
||||||
│ └── mosaic-framework/ OpenClaw framework injection plugin
|
│ └── mosaic-framework/ OpenClaw framework injection plugin
|
||||||
├── tools/
|
├── tools/
|
||||||
│ └── install.sh Unified installer (framework + npm CLI)
|
│ └── install.sh Unified installer (framework + npm CLI, --yes / --no-auto-launch)
|
||||||
├── scripts/agent/ Agent session lifecycle scripts
|
├── scripts/agent/ Agent session lifecycle scripts
|
||||||
├── docker-compose.yml Dev infrastructure
|
├── docker-compose.yml Dev infrastructure
|
||||||
└── .woodpecker/ CI pipeline configs
|
└── .woodpecker/ CI pipeline configs
|
||||||
@@ -163,7 +271,7 @@ mosaic-stack/
|
|||||||
|
|
||||||
- **Gateway is the single API surface** — all clients (TUI, web, Discord, Telegram) connect through it
|
- **Gateway is the single API surface** — all clients (TUI, web, Discord, Telegram) connect through it
|
||||||
- **ESM everywhere** — `"type": "module"`, `.js` extensions in imports, NodeNext resolution
|
- **ESM everywhere** — `"type": "module"`, `.js` extensions in imports, NodeNext resolution
|
||||||
- **Socket.IO typed events** — defined in `@mosaic/types`, enforced at compile time
|
- **Socket.IO typed events** — defined in `@mosaicstack/types`, enforced at compile time
|
||||||
- **OTEL auto-instrumentation** — loads before NestJS bootstrap
|
- **OTEL auto-instrumentation** — loads before NestJS bootstrap
|
||||||
- **Explicit `@Inject()` decorators** — required since tsx/esbuild doesn't emit decorator metadata
|
- **Explicit `@Inject()` decorators** — required since tsx/esbuild doesn't emit decorator metadata
|
||||||
|
|
||||||
@@ -200,7 +308,13 @@ Each stage has a dispatch mode (`exec` for research/review, `yolo` for coding),
|
|||||||
Run the installer again — it handles upgrades automatically:
|
Run the installer again — it handles upgrades automatically:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
bash <(curl -fsSL https://git.mosaicstack.dev/mosaic/mosaic-stack/raw/branch/main/tools/install.sh)
|
curl -fsSL https://mosaicstack.dev/install.sh | bash
|
||||||
|
```
|
||||||
|
|
||||||
|
Or use the direct URL:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bash <(curl -fsSL https://git.mosaicstack.dev/mosaicstack/stack/raw/branch/main/tools/install.sh)
|
||||||
```
|
```
|
||||||
|
|
||||||
Or use the CLI:
|
Or use the CLI:
|
||||||
@@ -215,10 +329,12 @@ The CLI also performs a background update check on every invocation (cached for
|
|||||||
### Installer Flags
|
### Installer Flags
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
bash tools/install.sh --check # Version check only
|
bash tools/install.sh --check # Version check only
|
||||||
bash tools/install.sh --framework # Framework only (skip npm CLI)
|
bash tools/install.sh --framework # Framework only (skip npm CLI)
|
||||||
bash tools/install.sh --cli # npm CLI only (skip framework)
|
bash tools/install.sh --cli # npm CLI only (skip framework)
|
||||||
bash tools/install.sh --ref v1.0 # Install from a specific git ref
|
bash tools/install.sh --ref v1.0 # Install from a specific git ref
|
||||||
|
bash tools/install.sh --yes # Non-interactive, accept all defaults
|
||||||
|
bash tools/install.sh --no-auto-launch # Skip auto-launch of wizard
|
||||||
```
|
```
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"name": "@mosaic/gateway",
|
"name": "@mosaicstack/gateway",
|
||||||
"version": "0.0.2",
|
"version": "0.0.6",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://git.mosaicstack.dev/mosaic/mosaic-stack.git",
|
"url": "https://git.mosaicstack.dev/mosaicstack/stack.git",
|
||||||
"directory": "apps/gateway"
|
"directory": "apps/gateway"
|
||||||
},
|
},
|
||||||
"type": "module",
|
"type": "module",
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
"dist"
|
"dist"
|
||||||
],
|
],
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"registry": "https://git.mosaicstack.dev/api/packages/mosaic/npm/",
|
"registry": "https://git.mosaicstack.dev/api/packages/mosaicstack/npm/",
|
||||||
"access": "public"
|
"access": "public"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -28,28 +28,28 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@anthropic-ai/sdk": "^0.80.0",
|
"@anthropic-ai/sdk": "^0.80.0",
|
||||||
"@fastify/helmet": "^13.0.2",
|
"@fastify/helmet": "^13.0.2",
|
||||||
"@mariozechner/pi-ai": "~0.57.1",
|
"@mariozechner/pi-ai": "^0.65.0",
|
||||||
"@mariozechner/pi-coding-agent": "~0.57.1",
|
"@mariozechner/pi-coding-agent": "^0.65.0",
|
||||||
"@modelcontextprotocol/sdk": "^1.27.1",
|
"@modelcontextprotocol/sdk": "^1.27.1",
|
||||||
"@mosaic/auth": "workspace:^",
|
"@mosaicstack/auth": "workspace:^",
|
||||||
"@mosaic/brain": "workspace:^",
|
"@mosaicstack/brain": "workspace:^",
|
||||||
"@mosaic/config": "workspace:^",
|
"@mosaicstack/config": "workspace:^",
|
||||||
"@mosaic/coord": "workspace:^",
|
"@mosaicstack/coord": "workspace:^",
|
||||||
"@mosaic/db": "workspace:^",
|
"@mosaicstack/db": "workspace:^",
|
||||||
"@mosaic/discord-plugin": "workspace:^",
|
"@mosaicstack/discord-plugin": "workspace:^",
|
||||||
"@mosaic/log": "workspace:^",
|
"@mosaicstack/log": "workspace:^",
|
||||||
"@mosaic/memory": "workspace:^",
|
"@mosaicstack/memory": "workspace:^",
|
||||||
"@mosaic/queue": "workspace:^",
|
"@mosaicstack/queue": "workspace:^",
|
||||||
"@mosaic/storage": "workspace:^",
|
"@mosaicstack/storage": "workspace:^",
|
||||||
"@mosaic/telegram-plugin": "workspace:^",
|
"@mosaicstack/telegram-plugin": "workspace:^",
|
||||||
"@mosaic/types": "workspace:^",
|
"@mosaicstack/types": "workspace:^",
|
||||||
"@nestjs/common": "^11.0.0",
|
"@nestjs/common": "^11.0.0",
|
||||||
"@nestjs/core": "^11.0.0",
|
"@nestjs/core": "^11.0.0",
|
||||||
"@nestjs/platform-fastify": "^11.0.0",
|
"@nestjs/platform-fastify": "^11.0.0",
|
||||||
"@nestjs/platform-socket.io": "^11.0.0",
|
"@nestjs/platform-socket.io": "^11.0.0",
|
||||||
"@nestjs/throttler": "^6.5.0",
|
"@nestjs/throttler": "^6.5.0",
|
||||||
"@nestjs/websockets": "^11.0.0",
|
"@nestjs/websockets": "^11.0.0",
|
||||||
"@opentelemetry/auto-instrumentations-node": "^0.71.0",
|
"@opentelemetry/auto-instrumentations-node": "^0.72.0",
|
||||||
"@opentelemetry/exporter-metrics-otlp-http": "^0.213.0",
|
"@opentelemetry/exporter-metrics-otlp-http": "^0.213.0",
|
||||||
"@opentelemetry/exporter-trace-otlp-http": "^0.213.0",
|
"@opentelemetry/exporter-trace-otlp-http": "^0.213.0",
|
||||||
"@opentelemetry/resources": "^2.6.0",
|
"@opentelemetry/resources": "^2.6.0",
|
||||||
@@ -63,8 +63,10 @@
|
|||||||
"class-validator": "^0.15.1",
|
"class-validator": "^0.15.1",
|
||||||
"dotenv": "^17.3.1",
|
"dotenv": "^17.3.1",
|
||||||
"fastify": "^5.0.0",
|
"fastify": "^5.0.0",
|
||||||
|
"ioredis": "^5.10.0",
|
||||||
"node-cron": "^4.2.1",
|
"node-cron": "^4.2.1",
|
||||||
"openai": "^6.32.0",
|
"openai": "^6.32.0",
|
||||||
|
"postgres": "^3.4.8",
|
||||||
"reflect-metadata": "^0.2.0",
|
"reflect-metadata": "^0.2.0",
|
||||||
"rxjs": "^7.8.0",
|
"rxjs": "^7.8.0",
|
||||||
"socket.io": "^4.8.0",
|
"socket.io": "^4.8.0",
|
||||||
@@ -72,11 +74,17 @@
|
|||||||
"zod": "^4.3.6"
|
"zod": "^4.3.6"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@nestjs/testing": "^11.1.18",
|
||||||
|
"@swc/core": "^1.15.24",
|
||||||
|
"@swc/helpers": "^0.5.21",
|
||||||
"@types/node": "^22.0.0",
|
"@types/node": "^22.0.0",
|
||||||
"@types/node-cron": "^3.0.11",
|
"@types/node-cron": "^3.0.11",
|
||||||
|
"@types/supertest": "^7.2.0",
|
||||||
"@types/uuid": "^10.0.0",
|
"@types/uuid": "^10.0.0",
|
||||||
|
"supertest": "^7.2.2",
|
||||||
"tsx": "^4.0.0",
|
"tsx": "^4.0.0",
|
||||||
"typescript": "^5.8.0",
|
"typescript": "^5.8.0",
|
||||||
|
"unplugin-swc": "^1.5.9",
|
||||||
"vitest": "^2.0.0"
|
"vitest": "^2.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import { BadRequestException, NotFoundException } from '@nestjs/common';
|
|||||||
import { describe, expect, it, vi, beforeEach } from 'vitest';
|
import { describe, expect, it, vi, beforeEach } from 'vitest';
|
||||||
import type { ConversationHistoryMessage } from '../agent/agent.service.js';
|
import type { ConversationHistoryMessage } from '../agent/agent.service.js';
|
||||||
import { ConversationsController } from '../conversations/conversations.controller.js';
|
import { ConversationsController } from '../conversations/conversations.controller.js';
|
||||||
import type { Message } from '@mosaic/brain';
|
import type { Message } from '@mosaicstack/brain';
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Shared test data
|
// Shared test data
|
||||||
|
|||||||
@@ -18,13 +18,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest';
|
import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest';
|
||||||
import { createDb } from '@mosaic/db';
|
import { createDb } from '@mosaicstack/db';
|
||||||
import { createConversationsRepo } from '@mosaic/brain';
|
import { createConversationsRepo } from '@mosaicstack/brain';
|
||||||
import { createAgentsRepo } from '@mosaic/brain';
|
import { createAgentsRepo } from '@mosaicstack/brain';
|
||||||
import { createPreferencesRepo, createInsightsRepo } from '@mosaic/memory';
|
import { createPreferencesRepo, createInsightsRepo } from '@mosaicstack/memory';
|
||||||
import { users, conversations, messages, agents, preferences, insights } from '@mosaic/db';
|
import { users, conversations, messages, agents, preferences, insights } from '@mosaicstack/db';
|
||||||
import { eq } from '@mosaic/db';
|
import { eq } from '@mosaicstack/db';
|
||||||
import type { DbHandle } from '@mosaic/db';
|
import type { DbHandle } from '@mosaicstack/db';
|
||||||
|
|
||||||
// ─── Fixed IDs so the afterAll cleanup is deterministic ──────────────────────
|
// ─── Fixed IDs so the afterAll cleanup is deterministic ──────────────────────
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Controller, Get, Inject, UseGuards } from '@nestjs/common';
|
import { Controller, Get, Inject, UseGuards } from '@nestjs/common';
|
||||||
import { sql, type Db } from '@mosaic/db';
|
import { sql, type Db } from '@mosaicstack/db';
|
||||||
import { createQueue } from '@mosaic/queue';
|
import { createQueue } from '@mosaicstack/queue';
|
||||||
import { DB } from '../database/database.module.js';
|
import { DB } from '../database/database.module.js';
|
||||||
import { AgentService } from '../agent/agent.service.js';
|
import { AgentService } from '../agent/agent.service.js';
|
||||||
import { ProviderService } from '../agent/provider.service.js';
|
import { ProviderService } from '../agent/provider.service.js';
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import {
|
|||||||
UseGuards,
|
UseGuards,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { randomBytes, createHash } from 'node:crypto';
|
import { randomBytes, createHash } from 'node:crypto';
|
||||||
import { eq, type Db, adminTokens } from '@mosaic/db';
|
import { eq, type Db, adminTokens } from '@mosaicstack/db';
|
||||||
import { v4 as uuid } from 'uuid';
|
import { v4 as uuid } from 'uuid';
|
||||||
import { DB } from '../database/database.module.js';
|
import { DB } from '../database/database.module.js';
|
||||||
import { AdminGuard } from './admin.guard.js';
|
import { AdminGuard } from './admin.guard.js';
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ import {
|
|||||||
Post,
|
Post,
|
||||||
UseGuards,
|
UseGuards,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { eq, type Db, users as usersTable } from '@mosaic/db';
|
import { eq, type Db, users as usersTable } from '@mosaicstack/db';
|
||||||
import type { Auth } from '@mosaic/auth';
|
import type { Auth } from '@mosaicstack/auth';
|
||||||
import { AUTH } from '../auth/auth.tokens.js';
|
import { AUTH } from '../auth/auth.tokens.js';
|
||||||
import { DB } from '../database/database.module.js';
|
import { DB } from '../database/database.module.js';
|
||||||
import { AdminGuard } from './admin.guard.js';
|
import { AdminGuard } from './admin.guard.js';
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ import {
|
|||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { createHash } from 'node:crypto';
|
import { createHash } from 'node:crypto';
|
||||||
import { fromNodeHeaders } from 'better-auth/node';
|
import { fromNodeHeaders } from 'better-auth/node';
|
||||||
import type { Auth } from '@mosaic/auth';
|
import type { Auth } from '@mosaicstack/auth';
|
||||||
import type { Db } from '@mosaic/db';
|
import type { Db } from '@mosaicstack/db';
|
||||||
import { eq, adminTokens, users as usersTable } from '@mosaic/db';
|
import { eq, adminTokens, users as usersTable } from '@mosaicstack/db';
|
||||||
import type { FastifyRequest } from 'fastify';
|
import type { FastifyRequest } from 'fastify';
|
||||||
import { AUTH } from '../auth/auth.tokens.js';
|
import { AUTH } from '../auth/auth.tokens.js';
|
||||||
import { DB } from '../database/database.module.js';
|
import { DB } from '../database/database.module.js';
|
||||||
|
|||||||
@@ -8,12 +8,13 @@ import {
|
|||||||
Post,
|
Post,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { randomBytes, createHash } from 'node:crypto';
|
import { randomBytes, createHash } from 'node:crypto';
|
||||||
import { count, eq, type Db, users as usersTable, adminTokens } from '@mosaic/db';
|
import { count, eq, type Db, users as usersTable, adminTokens } from '@mosaicstack/db';
|
||||||
import type { Auth } from '@mosaic/auth';
|
import type { Auth } from '@mosaicstack/auth';
|
||||||
import { v4 as uuid } from 'uuid';
|
import { v4 as uuid } from 'uuid';
|
||||||
import { AUTH } from '../auth/auth.tokens.js';
|
import { AUTH } from '../auth/auth.tokens.js';
|
||||||
import { DB } from '../database/database.module.js';
|
import { DB } from '../database/database.module.js';
|
||||||
import type { BootstrapSetupDto, BootstrapStatusDto, BootstrapResultDto } from './bootstrap.dto.js';
|
import { BootstrapSetupDto } from './bootstrap.dto.js';
|
||||||
|
import type { BootstrapStatusDto, BootstrapResultDto } from './bootstrap.dto.js';
|
||||||
|
|
||||||
@Controller('api/bootstrap')
|
@Controller('api/bootstrap')
|
||||||
export class BootstrapController {
|
export class BootstrapController {
|
||||||
|
|||||||
190
apps/gateway/src/admin/bootstrap.e2e.spec.ts
Normal file
190
apps/gateway/src/admin/bootstrap.e2e.spec.ts
Normal file
@@ -0,0 +1,190 @@
|
|||||||
|
/**
|
||||||
|
* E2E integration test — POST /api/bootstrap/setup
|
||||||
|
*
|
||||||
|
* Regression guard for the `import type { BootstrapSetupDto }` class-erasure
|
||||||
|
* bug (IUV-M01, issue #436).
|
||||||
|
*
|
||||||
|
* When `BootstrapSetupDto` is imported with `import type`, TypeScript erases
|
||||||
|
* the class at compile time. NestJS then sees `Object` as the `@Body()`
|
||||||
|
* metatype, and ValidationPipe with `whitelist:true + forbidNonWhitelisted:true`
|
||||||
|
* treats every property as non-whitelisted, returning:
|
||||||
|
*
|
||||||
|
* 400 { message: ["property email should not exist", "property password should not exist"] }
|
||||||
|
*
|
||||||
|
* The fix is a plain value import (`import { BootstrapSetupDto }`), which
|
||||||
|
* preserves the class reference so Nest can read the class-validator decorators.
|
||||||
|
*
|
||||||
|
* This test MUST fail if `import type` is re-introduced on `BootstrapSetupDto`.
|
||||||
|
* A controller unit test that constructs ValidationPipe manually won't catch
|
||||||
|
* this — only the real DI binding path exercises the metatype lookup.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import 'reflect-metadata';
|
||||||
|
import { describe, it, expect, afterAll, beforeAll } from 'vitest';
|
||||||
|
import { Test } from '@nestjs/testing';
|
||||||
|
import { ValidationPipe, type INestApplication } from '@nestjs/common';
|
||||||
|
import { FastifyAdapter, type NestFastifyApplication } from '@nestjs/platform-fastify';
|
||||||
|
import request from 'supertest';
|
||||||
|
import { BootstrapController } from './bootstrap.controller.js';
|
||||||
|
import type { BootstrapResultDto } from './bootstrap.dto.js';
|
||||||
|
|
||||||
|
// ─── Minimal mock dependencies ───────────────────────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We use explicit `@Inject(AUTH)` / `@Inject(DB)` in the controller so we
|
||||||
|
* can provide mock values by token without spinning up the real DB or Auth.
|
||||||
|
*/
|
||||||
|
import { AUTH } from '../auth/auth.tokens.js';
|
||||||
|
import { DB } from '../database/database.module.js';
|
||||||
|
|
||||||
|
const MOCK_USER_ID = 'mock-user-id-001';
|
||||||
|
|
||||||
|
const mockAuth = {
|
||||||
|
api: {
|
||||||
|
createUser: () =>
|
||||||
|
Promise.resolve({
|
||||||
|
user: {
|
||||||
|
id: MOCK_USER_ID,
|
||||||
|
name: 'Admin',
|
||||||
|
email: 'admin@example.com',
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// Override db.select() so the second query (verify user exists) returns a user.
|
||||||
|
// The bootstrap controller calls select().from() twice:
|
||||||
|
// 1. count() to check zero users → returns [{total: 0}]
|
||||||
|
// 2. select().where().limit() → returns [the created user]
|
||||||
|
let selectCallCount = 0;
|
||||||
|
const mockDbWithUser = {
|
||||||
|
select: () => {
|
||||||
|
selectCallCount++;
|
||||||
|
return {
|
||||||
|
from: () => {
|
||||||
|
if (selectCallCount === 1) {
|
||||||
|
// First call: count — zero users
|
||||||
|
return Promise.resolve([{ total: 0 }]);
|
||||||
|
}
|
||||||
|
// Subsequent calls: return a mock user row
|
||||||
|
return {
|
||||||
|
where: () => ({
|
||||||
|
limit: () =>
|
||||||
|
Promise.resolve([
|
||||||
|
{
|
||||||
|
id: MOCK_USER_ID,
|
||||||
|
name: 'Admin',
|
||||||
|
email: 'admin@example.com',
|
||||||
|
role: 'admin',
|
||||||
|
},
|
||||||
|
]),
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
update: () => ({
|
||||||
|
set: () => ({
|
||||||
|
where: () => Promise.resolve([]),
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
insert: () => ({
|
||||||
|
values: () => ({
|
||||||
|
returning: () =>
|
||||||
|
Promise.resolve([
|
||||||
|
{
|
||||||
|
id: 'token-id-001',
|
||||||
|
label: 'Initial setup token',
|
||||||
|
},
|
||||||
|
]),
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
|
||||||
|
// ─── Test suite ───────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
describe('POST /api/bootstrap/setup — ValidationPipe DTO binding', () => {
|
||||||
|
let app: INestApplication;
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
selectCallCount = 0;
|
||||||
|
|
||||||
|
const moduleRef = await Test.createTestingModule({
|
||||||
|
controllers: [BootstrapController],
|
||||||
|
providers: [
|
||||||
|
{ provide: AUTH, useValue: mockAuth },
|
||||||
|
{ provide: DB, useValue: mockDbWithUser },
|
||||||
|
],
|
||||||
|
}).compile();
|
||||||
|
|
||||||
|
app = moduleRef.createNestApplication<NestFastifyApplication>(new FastifyAdapter());
|
||||||
|
|
||||||
|
// Mirror main.ts configuration exactly — this is what reproduced the 400.
|
||||||
|
app.useGlobalPipes(
|
||||||
|
new ValidationPipe({
|
||||||
|
whitelist: true,
|
||||||
|
forbidNonWhitelisted: true,
|
||||||
|
transform: true,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
await app.init();
|
||||||
|
// Fastify requires waiting for the adapter to be ready
|
||||||
|
await app.getHttpAdapter().getInstance().ready();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
await app.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns 201 (not 400) when a valid {name, email, password} body is sent', async () => {
|
||||||
|
const res = await request(app.getHttpServer())
|
||||||
|
.post('/api/bootstrap/setup')
|
||||||
|
.send({ name: 'Admin', email: 'admin@example.com', password: 'password123' })
|
||||||
|
.set('Content-Type', 'application/json');
|
||||||
|
|
||||||
|
// Before the fix (import type), Nest ValidationPipe returned 400 with
|
||||||
|
// "property email should not exist" / "property password should not exist"
|
||||||
|
// because the DTO class was erased and every field looked non-whitelisted.
|
||||||
|
expect(res.status).not.toBe(400);
|
||||||
|
expect(res.status).toBe(201);
|
||||||
|
const body = res.body as BootstrapResultDto;
|
||||||
|
expect(body.user).toBeDefined();
|
||||||
|
expect(body.user.email).toBe('admin@example.com');
|
||||||
|
expect(body.token).toBeDefined();
|
||||||
|
expect(body.token.plaintext).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns 400 when extra forbidden properties are sent', async () => {
|
||||||
|
// This proves ValidationPipe IS active and working (forbidNonWhitelisted).
|
||||||
|
const res = await request(app.getHttpServer())
|
||||||
|
.post('/api/bootstrap/setup')
|
||||||
|
.send({
|
||||||
|
name: 'Admin',
|
||||||
|
email: 'admin@example.com',
|
||||||
|
password: 'password123',
|
||||||
|
extraField: 'should-be-rejected',
|
||||||
|
})
|
||||||
|
.set('Content-Type', 'application/json');
|
||||||
|
|
||||||
|
expect(res.status).toBe(400);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns 400 when email is invalid', async () => {
|
||||||
|
const res = await request(app.getHttpServer())
|
||||||
|
.post('/api/bootstrap/setup')
|
||||||
|
.send({ name: 'Admin', email: 'not-an-email', password: 'password123' })
|
||||||
|
.set('Content-Type', 'application/json');
|
||||||
|
|
||||||
|
expect(res.status).toBe(400);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns 400 when password is too short', async () => {
|
||||||
|
const res = await request(app.getHttpServer())
|
||||||
|
.post('/api/bootstrap/setup')
|
||||||
|
.send({ name: 'Admin', email: 'admin@example.com', password: 'short' })
|
||||||
|
.set('Content-Type', 'application/json');
|
||||||
|
|
||||||
|
expect(res.status).toBe(400);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -62,7 +62,7 @@ function restoreEnv(saved: Map<EnvKey, string | undefined>): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function makeRegistry(): ModelRegistry {
|
function makeRegistry(): ModelRegistry {
|
||||||
return new ModelRegistry(AuthStorage.inMemory());
|
return ModelRegistry.inMemory(AuthStorage.inMemory());
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
||||||
import { RoutingService } from '../routing.service.js';
|
import { RoutingService } from '../routing.service.js';
|
||||||
import type { ModelInfo } from '@mosaic/types';
|
import type { ModelInfo } from '@mosaicstack/types';
|
||||||
|
|
||||||
const mockModels: ModelInfo[] = [
|
const mockModels: ModelInfo[] = [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import type {
|
|||||||
IProviderAdapter,
|
IProviderAdapter,
|
||||||
ModelInfo,
|
ModelInfo,
|
||||||
ProviderHealth,
|
ProviderHealth,
|
||||||
} from '@mosaic/types';
|
} from '@mosaicstack/types';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Anthropic provider adapter.
|
* Anthropic provider adapter.
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import type {
|
|||||||
IProviderAdapter,
|
IProviderAdapter,
|
||||||
ModelInfo,
|
ModelInfo,
|
||||||
ProviderHealth,
|
ProviderHealth,
|
||||||
} from '@mosaic/types';
|
} from '@mosaicstack/types';
|
||||||
|
|
||||||
/** Embedding models that Ollama ships with out of the box */
|
/** Embedding models that Ollama ships with out of the box */
|
||||||
const OLLAMA_EMBEDDING_MODELS: ReadonlyArray<{
|
const OLLAMA_EMBEDDING_MODELS: ReadonlyArray<{
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import type {
|
|||||||
IProviderAdapter,
|
IProviderAdapter,
|
||||||
ModelInfo,
|
ModelInfo,
|
||||||
ProviderHealth,
|
ProviderHealth,
|
||||||
} from '@mosaic/types';
|
} from '@mosaicstack/types';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OpenAI provider adapter.
|
* OpenAI provider adapter.
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import type {
|
|||||||
IProviderAdapter,
|
IProviderAdapter,
|
||||||
ModelInfo,
|
ModelInfo,
|
||||||
ProviderHealth,
|
ProviderHealth,
|
||||||
} from '@mosaic/types';
|
} from '@mosaicstack/types';
|
||||||
|
|
||||||
const OPENROUTER_BASE_URL = 'https://openrouter.ai/api/v1';
|
const OPENROUTER_BASE_URL = 'https://openrouter.ai/api/v1';
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import type {
|
|||||||
IProviderAdapter,
|
IProviderAdapter,
|
||||||
ModelInfo,
|
ModelInfo,
|
||||||
ProviderHealth,
|
ProviderHealth,
|
||||||
} from '@mosaic/types';
|
} from '@mosaicstack/types';
|
||||||
import { getModelCapability } from '../model-capabilities.js';
|
import { getModelCapability } from '../model-capabilities.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import {
|
|||||||
Post,
|
Post,
|
||||||
UseGuards,
|
UseGuards,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import type { Brain } from '@mosaic/brain';
|
import type { Brain } from '@mosaicstack/brain';
|
||||||
import { BRAIN } from '../brain/brain.tokens.js';
|
import { BRAIN } from '../brain/brain.tokens.js';
|
||||||
import { AuthGuard } from '../auth/auth.guard.js';
|
import { AuthGuard } from '../auth/auth.guard.js';
|
||||||
import { CurrentUser } from '../auth/current-user.decorator.js';
|
import { CurrentUser } from '../auth/current-user.decorator.js';
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ import {
|
|||||||
type AgentSessionEvent,
|
type AgentSessionEvent,
|
||||||
type ToolDefinition,
|
type ToolDefinition,
|
||||||
} from '@mariozechner/pi-coding-agent';
|
} from '@mariozechner/pi-coding-agent';
|
||||||
import type { Brain } from '@mosaic/brain';
|
import type { Brain } from '@mosaicstack/brain';
|
||||||
import type { Memory } from '@mosaic/memory';
|
import type { Memory } from '@mosaicstack/memory';
|
||||||
import { BRAIN } from '../brain/brain.tokens.js';
|
import { BRAIN } from '../brain/brain.tokens.js';
|
||||||
import { MEMORY } from '../memory/memory.tokens.js';
|
import { MEMORY } from '../memory/memory.tokens.js';
|
||||||
import { EmbeddingService } from '../memory/embedding.service.js';
|
import { EmbeddingService } from '../memory/embedding.service.js';
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { ModelCapability } from '@mosaic/types';
|
import type { ModelCapability } from '@mosaicstack/types';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comprehensive capability matrix for all target models.
|
* Comprehensive capability matrix for all target models.
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Inject, Injectable, Logger } from '@nestjs/common';
|
import { Inject, Injectable, Logger } from '@nestjs/common';
|
||||||
import { createCipheriv, createDecipheriv, createHash, randomBytes } from 'node:crypto';
|
import { createCipheriv, createDecipheriv, createHash, randomBytes } from 'node:crypto';
|
||||||
import type { Db } from '@mosaic/db';
|
import type { Db } from '@mosaicstack/db';
|
||||||
import { providerCredentials, eq, and } from '@mosaic/db';
|
import { providerCredentials, eq, and } from '@mosaicstack/db';
|
||||||
import { DB } from '../database/database.module.js';
|
import { DB } from '../database/database.module.js';
|
||||||
import type { ProviderCredentialSummaryDto } from './provider-credentials.dto.js';
|
import type { ProviderCredentialSummaryDto } from './provider-credentials.dto.js';
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import type {
|
|||||||
ModelInfo,
|
ModelInfo,
|
||||||
ProviderHealth,
|
ProviderHealth,
|
||||||
ProviderInfo,
|
ProviderInfo,
|
||||||
} from '@mosaic/types';
|
} from '@mosaicstack/types';
|
||||||
import {
|
import {
|
||||||
AnthropicAdapter,
|
AnthropicAdapter,
|
||||||
OllamaAdapter,
|
OllamaAdapter,
|
||||||
@@ -67,7 +67,7 @@ export class ProviderService implements OnModuleInit, OnModuleDestroy {
|
|||||||
|
|
||||||
async onModuleInit(): Promise<void> {
|
async onModuleInit(): Promise<void> {
|
||||||
const authStorage = AuthStorage.inMemory();
|
const authStorage = AuthStorage.inMemory();
|
||||||
this.registry = new ModelRegistry(authStorage);
|
this.registry = ModelRegistry.inMemory(authStorage);
|
||||||
|
|
||||||
// Build the default set of adapters that rely on the registry
|
// Build the default set of adapters that rely on the registry
|
||||||
this.adapters = [
|
this.adapters = [
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Body, Controller, Delete, Get, Inject, Param, Post, UseGuards } from '@nestjs/common';
|
import { Body, Controller, Delete, Get, Inject, Param, Post, UseGuards } from '@nestjs/common';
|
||||||
import type { RoutingCriteria } from '@mosaic/types';
|
import type { RoutingCriteria } from '@mosaicstack/types';
|
||||||
import { AuthGuard } from '../auth/auth.guard.js';
|
import { AuthGuard } from '../auth/auth.guard.js';
|
||||||
import { CurrentUser } from '../auth/current-user.decorator.js';
|
import { CurrentUser } from '../auth/current-user.decorator.js';
|
||||||
import { ProviderService } from './provider.service.js';
|
import { ProviderService } from './provider.service.js';
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Inject, Injectable, Logger } from '@nestjs/common';
|
import { Inject, Injectable, Logger } from '@nestjs/common';
|
||||||
import type { ModelInfo } from '@mosaic/types';
|
import type { ModelInfo } from '@mosaicstack/types';
|
||||||
import type { RoutingCriteria, RoutingResult, CostTier } from '@mosaic/types';
|
import type { RoutingCriteria, RoutingResult, CostTier } from '@mosaicstack/types';
|
||||||
import { ProviderService } from './provider.service.js';
|
import { ProviderService } from './provider.service.js';
|
||||||
|
|
||||||
/** Per-million-token cost thresholds for tier classification */
|
/** Per-million-token cost thresholds for tier classification */
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Inject, Injectable, Logger, type OnModuleInit } from '@nestjs/common';
|
import { Inject, Injectable, Logger, type OnModuleInit } from '@nestjs/common';
|
||||||
import { routingRules, type Db, sql } from '@mosaic/db';
|
import { routingRules, type Db, sql } from '@mosaicstack/db';
|
||||||
import { DB } from '../../database/database.module.js';
|
import { DB } from '../../database/database.module.js';
|
||||||
import type { RoutingCondition, RoutingAction } from './routing.types.js';
|
import type { RoutingCondition, RoutingAction } from './routing.types.js';
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Inject, Injectable, Logger } from '@nestjs/common';
|
import { Inject, Injectable, Logger } from '@nestjs/common';
|
||||||
import { routingRules, type Db, and, asc, eq, or } from '@mosaic/db';
|
import { routingRules, type Db, and, asc, eq, or } from '@mosaicstack/db';
|
||||||
import { DB } from '../../database/database.module.js';
|
import { DB } from '../../database/database.module.js';
|
||||||
import { ProviderService } from '../provider.service.js';
|
import { ProviderService } from '../provider.service.js';
|
||||||
import { classifyTask } from './task-classifier.js';
|
import { classifyTask } from './task-classifier.js';
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import {
|
|||||||
Post,
|
Post,
|
||||||
UseGuards,
|
UseGuards,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { routingRules, type Db, and, asc, eq, or, inArray } from '@mosaic/db';
|
import { routingRules, type Db, and, asc, eq, or, inArray } from '@mosaicstack/db';
|
||||||
import { DB } from '../../database/database.module.js';
|
import { DB } from '../../database/database.module.js';
|
||||||
import { AuthGuard } from '../../auth/auth.guard.js';
|
import { AuthGuard } from '../../auth/auth.guard.js';
|
||||||
import { CurrentUser } from '../../auth/current-user.decorator.js';
|
import { CurrentUser } from '../../auth/current-user.decorator.js';
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* Routing engine types — M4-002 (condition types) and M4-003 (action types).
|
* Routing engine types — M4-002 (condition types) and M4-003 (action types).
|
||||||
*
|
*
|
||||||
* These types are re-exported from `@mosaic/types` for shared use across packages.
|
* These types are re-exported from `@mosaicstack/types` for shared use across packages.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// ─── Classification primitives ───────────────────────────────────────────────
|
// ─── Classification primitives ───────────────────────────────────────────────
|
||||||
@@ -23,7 +23,7 @@ export type Domain = 'frontend' | 'backend' | 'devops' | 'docs' | 'general';
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Cost tier for model selection.
|
* Cost tier for model selection.
|
||||||
* Extends the existing `CostTier` in `@mosaic/types` with `local` for self-hosted models.
|
* Extends the existing `CostTier` in `@mosaicstack/types` with `local` for self-hosted models.
|
||||||
*/
|
*/
|
||||||
export type CostTier = 'cheap' | 'standard' | 'premium' | 'local';
|
export type CostTier = 'cheap' | 'standard' | 'premium' | 'local';
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Type } from '@sinclair/typebox';
|
import { Type } from '@sinclair/typebox';
|
||||||
import type { ToolDefinition } from '@mariozechner/pi-coding-agent';
|
import type { ToolDefinition } from '@mariozechner/pi-coding-agent';
|
||||||
import type { Brain } from '@mosaic/brain';
|
import type { Brain } from '@mosaicstack/brain';
|
||||||
|
|
||||||
export function createBrainTools(brain: Brain): ToolDefinition[] {
|
export function createBrainTools(brain: Brain): ToolDefinition[] {
|
||||||
const listProjects: ToolDefinition = {
|
const listProjects: ToolDefinition = {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Type } from '@sinclair/typebox';
|
import { Type } from '@sinclair/typebox';
|
||||||
import type { ToolDefinition } from '@mariozechner/pi-coding-agent';
|
import type { ToolDefinition } from '@mariozechner/pi-coding-agent';
|
||||||
import type { Memory } from '@mosaic/memory';
|
import type { Memory } from '@mosaicstack/memory';
|
||||||
import type { EmbeddingProvider } from '@mosaic/memory';
|
import type { EmbeddingProvider } from '@mosaicstack/memory';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create memory tools bound to the session's authenticated userId.
|
* Create memory tools bound to the session's authenticated userId.
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { IncomingMessage, ServerResponse } from 'node:http';
|
import type { IncomingMessage, ServerResponse } from 'node:http';
|
||||||
import { toNodeHandler } from 'better-auth/node';
|
import { toNodeHandler } from 'better-auth/node';
|
||||||
import type { Auth } from '@mosaic/auth';
|
import type { Auth } from '@mosaicstack/auth';
|
||||||
import type { NestFastifyApplication } from '@nestjs/platform-fastify';
|
import type { NestFastifyApplication } from '@nestjs/platform-fastify';
|
||||||
import { AUTH } from './auth.tokens.js';
|
import { AUTH } from './auth.tokens.js';
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
UnauthorizedException,
|
UnauthorizedException,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { fromNodeHeaders } from 'better-auth/node';
|
import { fromNodeHeaders } from 'better-auth/node';
|
||||||
import type { Auth } from '@mosaic/auth';
|
import type { Auth } from '@mosaicstack/auth';
|
||||||
import type { FastifyRequest } from 'fastify';
|
import type { FastifyRequest } from 'fastify';
|
||||||
import { AUTH } from './auth.tokens.js';
|
import { AUTH } from './auth.tokens.js';
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Global, Module } from '@nestjs/common';
|
import { Global, Module } from '@nestjs/common';
|
||||||
import { createAuth, type Auth } from '@mosaic/auth';
|
import { createAuth, type Auth } from '@mosaicstack/auth';
|
||||||
import type { Db } from '@mosaic/db';
|
import type { Db } from '@mosaicstack/db';
|
||||||
import { DB } from '../database/database.module.js';
|
import { DB } from '../database/database.module.js';
|
||||||
import { AUTH } from './auth.tokens.js';
|
import { AUTH } from './auth.tokens.js';
|
||||||
import { SsoController } from './sso.controller.js';
|
import { SsoController } from './sso.controller.js';
|
||||||
@@ -14,7 +14,7 @@ import { SsoController } from './sso.controller.js';
|
|||||||
useFactory: (db: Db): Auth =>
|
useFactory: (db: Db): Auth =>
|
||||||
createAuth({
|
createAuth({
|
||||||
db,
|
db,
|
||||||
baseURL: process.env['BETTER_AUTH_URL'] ?? 'http://localhost:4000',
|
baseURL: process.env['BETTER_AUTH_URL'] ?? 'http://localhost:14242',
|
||||||
secret: process.env['BETTER_AUTH_SECRET'],
|
secret: process.env['BETTER_AUTH_SECRET'],
|
||||||
}),
|
}),
|
||||||
inject: [DB],
|
inject: [DB],
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Controller, Get } from '@nestjs/common';
|
import { Controller, Get } from '@nestjs/common';
|
||||||
import { buildSsoDiscovery, type SsoProviderDiscovery } from '@mosaic/auth';
|
import { buildSsoDiscovery, type SsoProviderDiscovery } from '@mosaicstack/auth';
|
||||||
|
|
||||||
@Controller('api/sso/providers')
|
@Controller('api/sso/providers')
|
||||||
export class SsoController {
|
export class SsoController {
|
||||||
|
|||||||
344
apps/gateway/src/bootstrap/tier-detector.spec.ts
Normal file
344
apps/gateway/src/bootstrap/tier-detector.spec.ts
Normal file
@@ -0,0 +1,344 @@
|
|||||||
|
/**
|
||||||
|
* Unit tests for tier-detector.ts.
|
||||||
|
*
|
||||||
|
* All external I/O (postgres, ioredis) is mocked — no live services required.
|
||||||
|
*
|
||||||
|
* Note on hoisting: vi.mock() factories are hoisted above all imports by vitest.
|
||||||
|
* Variables referenced inside factory callbacks must be declared via vi.hoisted()
|
||||||
|
* so they are available at hoist time.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------ */
|
||||||
|
/* Hoist shared mock state so factories can reference it */
|
||||||
|
/* ------------------------------------------------------------------ */
|
||||||
|
|
||||||
|
const mocks = vi.hoisted(() => {
|
||||||
|
const mockSqlFn = vi.fn();
|
||||||
|
const mockEnd = vi.fn().mockResolvedValue(undefined);
|
||||||
|
const mockPostgresConstructor = vi.fn(() => {
|
||||||
|
const sql = mockSqlFn as ReturnType<typeof mockSqlFn>;
|
||||||
|
(sql as unknown as Record<string, unknown>)['end'] = mockEnd;
|
||||||
|
return sql;
|
||||||
|
});
|
||||||
|
|
||||||
|
const mockRedisConnect = vi.fn().mockResolvedValue(undefined);
|
||||||
|
const mockRedisPing = vi.fn().mockResolvedValue('PONG');
|
||||||
|
const mockRedisDisconnect = vi.fn();
|
||||||
|
const MockRedis = vi.fn().mockImplementation(() => ({
|
||||||
|
connect: mockRedisConnect,
|
||||||
|
ping: mockRedisPing,
|
||||||
|
disconnect: mockRedisDisconnect,
|
||||||
|
}));
|
||||||
|
|
||||||
|
return {
|
||||||
|
mockSqlFn,
|
||||||
|
mockEnd,
|
||||||
|
mockPostgresConstructor,
|
||||||
|
mockRedisConnect,
|
||||||
|
mockRedisPing,
|
||||||
|
mockRedisDisconnect,
|
||||||
|
MockRedis,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------ */
|
||||||
|
/* Module mocks (registered at hoist time) */
|
||||||
|
/* ------------------------------------------------------------------ */
|
||||||
|
|
||||||
|
vi.mock('postgres', () => ({
|
||||||
|
default: mocks.mockPostgresConstructor,
|
||||||
|
}));
|
||||||
|
|
||||||
|
vi.mock('ioredis', () => ({
|
||||||
|
Redis: mocks.MockRedis,
|
||||||
|
}));
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------ */
|
||||||
|
/* Import SUT after mocks are registered */
|
||||||
|
/* ------------------------------------------------------------------ */
|
||||||
|
|
||||||
|
import { detectAndAssertTier, TierDetectionError } from './tier-detector.js';
|
||||||
|
import type { MosaicConfig } from '@mosaicstack/config';
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------ */
|
||||||
|
/* Config fixtures */
|
||||||
|
/* ------------------------------------------------------------------ */
|
||||||
|
|
||||||
|
const LOCAL_CONFIG: MosaicConfig = {
|
||||||
|
tier: 'local',
|
||||||
|
storage: { type: 'pglite', dataDir: '.mosaic/pglite' },
|
||||||
|
queue: { type: 'local', dataDir: '.mosaic/queue' },
|
||||||
|
memory: { type: 'keyword' },
|
||||||
|
};
|
||||||
|
|
||||||
|
const STANDALONE_CONFIG: MosaicConfig = {
|
||||||
|
tier: 'standalone',
|
||||||
|
storage: { type: 'postgres', url: 'postgresql://mosaic:mosaic@db-host:5432/mosaic' },
|
||||||
|
queue: { type: 'bullmq', url: 'redis://valkey-host:6380' },
|
||||||
|
memory: { type: 'keyword' },
|
||||||
|
};
|
||||||
|
|
||||||
|
const FEDERATED_CONFIG: MosaicConfig = {
|
||||||
|
tier: 'federated',
|
||||||
|
storage: {
|
||||||
|
type: 'postgres',
|
||||||
|
url: 'postgresql://mosaic:mosaic@db-host:5433/mosaic',
|
||||||
|
enableVector: true,
|
||||||
|
},
|
||||||
|
queue: { type: 'bullmq', url: 'redis://valkey-host:6380' },
|
||||||
|
memory: { type: 'pgvector' },
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------ */
|
||||||
|
/* Tests */
|
||||||
|
/* ------------------------------------------------------------------ */
|
||||||
|
|
||||||
|
describe('detectAndAssertTier', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
vi.clearAllMocks();
|
||||||
|
|
||||||
|
// Default: all probes succeed.
|
||||||
|
mocks.mockSqlFn.mockResolvedValue([]);
|
||||||
|
mocks.mockEnd.mockResolvedValue(undefined);
|
||||||
|
mocks.mockRedisConnect.mockResolvedValue(undefined);
|
||||||
|
mocks.mockRedisPing.mockResolvedValue('PONG');
|
||||||
|
|
||||||
|
// Re-wire constructor to return a fresh sql-like object each time.
|
||||||
|
mocks.mockPostgresConstructor.mockImplementation(() => {
|
||||||
|
const sql = mocks.mockSqlFn as ReturnType<typeof mocks.mockSqlFn>;
|
||||||
|
(sql as unknown as Record<string, unknown>)['end'] = mocks.mockEnd;
|
||||||
|
return sql;
|
||||||
|
});
|
||||||
|
mocks.MockRedis.mockImplementation(() => ({
|
||||||
|
connect: mocks.mockRedisConnect,
|
||||||
|
ping: mocks.mockRedisPing,
|
||||||
|
disconnect: mocks.mockRedisDisconnect,
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- */
|
||||||
|
/* 1. local — no-op */
|
||||||
|
/* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
it('resolves immediately for tier=local without touching postgres or ioredis', async () => {
|
||||||
|
await expect(detectAndAssertTier(LOCAL_CONFIG)).resolves.toBeUndefined();
|
||||||
|
expect(mocks.mockPostgresConstructor).not.toHaveBeenCalled();
|
||||||
|
expect(mocks.MockRedis).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- */
|
||||||
|
/* 2. standalone — happy path */
|
||||||
|
/* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
it('resolves for tier=standalone when postgres and valkey are reachable', async () => {
|
||||||
|
await expect(detectAndAssertTier(STANDALONE_CONFIG)).resolves.toBeUndefined();
|
||||||
|
|
||||||
|
// Postgres was probed (SELECT 1 only — no pgvector check).
|
||||||
|
expect(mocks.mockPostgresConstructor).toHaveBeenCalledTimes(1);
|
||||||
|
expect(mocks.mockSqlFn).toHaveBeenCalledTimes(1);
|
||||||
|
// Valkey was probed.
|
||||||
|
expect(mocks.MockRedis).toHaveBeenCalledTimes(1);
|
||||||
|
expect(mocks.mockRedisPing).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- */
|
||||||
|
/* 3. standalone — postgres unreachable */
|
||||||
|
/* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
it('throws TierDetectionError with service=postgres when postgres query rejects', async () => {
|
||||||
|
mocks.mockSqlFn.mockRejectedValueOnce(new Error('connection refused'));
|
||||||
|
|
||||||
|
const promise = detectAndAssertTier(STANDALONE_CONFIG);
|
||||||
|
await expect(promise).rejects.toBeInstanceOf(TierDetectionError);
|
||||||
|
|
||||||
|
// Confirm no valkey probe happened (fail fast on first error).
|
||||||
|
expect(mocks.MockRedis).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('sets service=postgres on the error when postgres fails', async () => {
|
||||||
|
mocks.mockSqlFn.mockRejectedValue(new Error('connection refused'));
|
||||||
|
|
||||||
|
try {
|
||||||
|
await detectAndAssertTier(STANDALONE_CONFIG);
|
||||||
|
expect.fail('should have thrown');
|
||||||
|
} catch (err) {
|
||||||
|
expect(err).toBeInstanceOf(TierDetectionError);
|
||||||
|
const typed = err as TierDetectionError;
|
||||||
|
expect(typed.service).toBe('postgres');
|
||||||
|
expect(typed.remediation).toContain('docker compose');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- */
|
||||||
|
/* 4. standalone — valkey unreachable */
|
||||||
|
/* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
it('throws TierDetectionError with service=valkey when ping fails', async () => {
|
||||||
|
// Postgres probe succeeds; valkey connect fails.
|
||||||
|
mocks.mockSqlFn.mockResolvedValue([]);
|
||||||
|
mocks.mockRedisConnect.mockRejectedValue(new Error('ECONNREFUSED'));
|
||||||
|
|
||||||
|
try {
|
||||||
|
await detectAndAssertTier(STANDALONE_CONFIG);
|
||||||
|
expect.fail('should have thrown');
|
||||||
|
} catch (err) {
|
||||||
|
expect(err).toBeInstanceOf(TierDetectionError);
|
||||||
|
const typed = err as TierDetectionError;
|
||||||
|
expect(typed.service).toBe('valkey');
|
||||||
|
expect(typed.message).toContain('valkey');
|
||||||
|
expect(typed.remediation).toContain('valkey-federated');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- */
|
||||||
|
/* 5. federated — happy path */
|
||||||
|
/* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
it('resolves for tier=federated when all three checks pass', async () => {
|
||||||
|
// SELECT 1 and CREATE EXTENSION both succeed.
|
||||||
|
mocks.mockSqlFn.mockResolvedValue([]);
|
||||||
|
|
||||||
|
await expect(detectAndAssertTier(FEDERATED_CONFIG)).resolves.toBeUndefined();
|
||||||
|
|
||||||
|
// postgres probe (SELECT 1) + pgvector probe (CREATE EXTENSION) = 2 postgres constructors.
|
||||||
|
expect(mocks.mockPostgresConstructor).toHaveBeenCalledTimes(2);
|
||||||
|
expect(mocks.mockSqlFn).toHaveBeenCalledTimes(2);
|
||||||
|
// Valkey probed once.
|
||||||
|
expect(mocks.MockRedis).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- */
|
||||||
|
/* 6. federated — pgvector not installable */
|
||||||
|
/* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
it('throws TierDetectionError with service=pgvector when CREATE EXTENSION fails', async () => {
|
||||||
|
// SELECT 1 succeeds (first call), CREATE EXTENSION fails (second call).
|
||||||
|
mocks.mockSqlFn
|
||||||
|
.mockResolvedValueOnce([]) // SELECT 1
|
||||||
|
.mockRejectedValueOnce(new Error('extension "vector" is not available'));
|
||||||
|
|
||||||
|
try {
|
||||||
|
await detectAndAssertTier(FEDERATED_CONFIG);
|
||||||
|
expect.fail('should have thrown');
|
||||||
|
} catch (err) {
|
||||||
|
expect(err).toBeInstanceOf(TierDetectionError);
|
||||||
|
const typed = err as TierDetectionError;
|
||||||
|
expect(typed.service).toBe('pgvector');
|
||||||
|
expect(typed.message).toContain('pgvector');
|
||||||
|
expect(typed.remediation).toContain('pgvector/pgvector');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- */
|
||||||
|
/* 7. probeValkey honors connectTimeout */
|
||||||
|
/* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
it('constructs the ioredis Redis client with connectTimeout: 5000', async () => {
|
||||||
|
await detectAndAssertTier(STANDALONE_CONFIG);
|
||||||
|
|
||||||
|
expect(mocks.MockRedis).toHaveBeenCalledOnce();
|
||||||
|
const [, options] = mocks.MockRedis.mock.calls[0] as [string, Record<string, unknown>];
|
||||||
|
expect(options).toMatchObject({ connectTimeout: 5000 });
|
||||||
|
});
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- */
|
||||||
|
/* 8. probePgvector — library-not-installed remediation */
|
||||||
|
/* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
it('includes pgvector/pgvector:pg17 in remediation when pgvector library is missing', async () => {
|
||||||
|
// SELECT 1 succeeds; CREATE EXTENSION fails with the canonical library-missing message.
|
||||||
|
mocks.mockSqlFn
|
||||||
|
.mockResolvedValueOnce([]) // SELECT 1 (probePostgres)
|
||||||
|
.mockRejectedValueOnce(new Error('extension "vector" is not available')); // probePgvector
|
||||||
|
|
||||||
|
try {
|
||||||
|
await detectAndAssertTier(FEDERATED_CONFIG);
|
||||||
|
expect.fail('should have thrown');
|
||||||
|
} catch (err) {
|
||||||
|
expect(err).toBeInstanceOf(TierDetectionError);
|
||||||
|
const typed = err as TierDetectionError;
|
||||||
|
expect(typed.service).toBe('pgvector');
|
||||||
|
expect(typed.remediation).toContain('pgvector/pgvector:pg17');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- */
|
||||||
|
/* 9. probePgvector — permission / other error remediation */
|
||||||
|
/* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
it('mentions CREATE permission or superuser in remediation for a generic pgvector error', async () => {
|
||||||
|
// SELECT 1 succeeds; CREATE EXTENSION fails with a permission error (not the library-missing message).
|
||||||
|
mocks.mockSqlFn
|
||||||
|
.mockResolvedValueOnce([]) // SELECT 1 (probePostgres)
|
||||||
|
.mockRejectedValueOnce(new Error('permission denied to create extension'));
|
||||||
|
|
||||||
|
try {
|
||||||
|
await detectAndAssertTier(FEDERATED_CONFIG);
|
||||||
|
expect.fail('should have thrown');
|
||||||
|
} catch (err) {
|
||||||
|
expect(err).toBeInstanceOf(TierDetectionError);
|
||||||
|
const typed = err as TierDetectionError;
|
||||||
|
expect(typed.service).toBe('pgvector');
|
||||||
|
// Must NOT point to the image fix — that's only for the library-missing case.
|
||||||
|
expect(typed.remediation).not.toContain('pgvector/pgvector:pg17');
|
||||||
|
// Must mention permissions or superuser.
|
||||||
|
expect(typed.remediation).toMatch(/CREATE|superuser/i);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- */
|
||||||
|
/* 10. federated tier rejects non-bullmq queue.type */
|
||||||
|
/* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
it('throws TierDetectionError with service=config for federated tier with queue.type !== bullmq', async () => {
|
||||||
|
const badConfig: MosaicConfig = {
|
||||||
|
tier: 'federated',
|
||||||
|
storage: {
|
||||||
|
type: 'postgres',
|
||||||
|
url: 'postgresql://mosaic:mosaic@db-host:5433/mosaic',
|
||||||
|
enableVector: true,
|
||||||
|
},
|
||||||
|
queue: { type: 'local', dataDir: '.mosaic/queue' },
|
||||||
|
memory: { type: 'pgvector' },
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
await detectAndAssertTier(badConfig);
|
||||||
|
expect.fail('should have thrown');
|
||||||
|
} catch (err) {
|
||||||
|
expect(err).toBeInstanceOf(TierDetectionError);
|
||||||
|
const typed = err as TierDetectionError;
|
||||||
|
expect(typed.service).toBe('config');
|
||||||
|
expect(typed.remediation).toContain('bullmq');
|
||||||
|
}
|
||||||
|
|
||||||
|
// No network probes should have been attempted.
|
||||||
|
expect(mocks.mockPostgresConstructor).not.toHaveBeenCalled();
|
||||||
|
expect(mocks.MockRedis).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- */
|
||||||
|
/* 11. Error fields populated */
|
||||||
|
/* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
it('populates host, port, and remediation on a thrown TierDetectionError', async () => {
|
||||||
|
mocks.mockSqlFn.mockRejectedValue(new Error('connection refused'));
|
||||||
|
|
||||||
|
let caught: TierDetectionError | undefined;
|
||||||
|
try {
|
||||||
|
await detectAndAssertTier(STANDALONE_CONFIG);
|
||||||
|
} catch (err) {
|
||||||
|
caught = err as TierDetectionError;
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(caught).toBeInstanceOf(TierDetectionError);
|
||||||
|
expect(caught!.service).toBe('postgres');
|
||||||
|
// Host and port are extracted from the Postgres URL in STANDALONE_CONFIG.
|
||||||
|
expect(caught!.host).toBe('db-host');
|
||||||
|
expect(caught!.port).toBe(5432);
|
||||||
|
expect(caught!.remediation).toMatch(/docker compose/i);
|
||||||
|
expect(caught!.message).toContain('db-host:5432');
|
||||||
|
});
|
||||||
|
});
|
||||||
220
apps/gateway/src/bootstrap/tier-detector.ts
Normal file
220
apps/gateway/src/bootstrap/tier-detector.ts
Normal file
@@ -0,0 +1,220 @@
|
|||||||
|
/**
|
||||||
|
* Tier Detector — pre-flight service reachability assertions.
|
||||||
|
*
|
||||||
|
* Runs BEFORE NestFactory.create() to surface actionable errors immediately
|
||||||
|
* rather than crashing mid-boot with an opaque stack trace.
|
||||||
|
*
|
||||||
|
* Library choices:
|
||||||
|
* - Postgres: `postgres` npm package (already a dep via @mosaicstack/db / drizzle-orm).
|
||||||
|
* The spec mentions `pg`, but only `postgres` is installed in this monorepo.
|
||||||
|
* - Valkey: `ioredis` (already a dep via @mosaicstack/queue → bullmq; same URL
|
||||||
|
* convention used by the bullmq adapter).
|
||||||
|
*/
|
||||||
|
|
||||||
|
import postgres from 'postgres';
|
||||||
|
import { Redis } from 'ioredis';
|
||||||
|
import type { MosaicConfig } from '@mosaicstack/config';
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------ */
|
||||||
|
/* Structured error type */
|
||||||
|
/* ------------------------------------------------------------------ */
|
||||||
|
|
||||||
|
export class TierDetectionError extends Error {
|
||||||
|
public readonly service: 'postgres' | 'valkey' | 'pgvector' | 'config';
|
||||||
|
public readonly host: string;
|
||||||
|
public readonly port: number;
|
||||||
|
public readonly remediation: string;
|
||||||
|
|
||||||
|
constructor(opts: {
|
||||||
|
service: 'postgres' | 'valkey' | 'pgvector' | 'config';
|
||||||
|
host: string;
|
||||||
|
port: number;
|
||||||
|
remediation: string;
|
||||||
|
cause?: unknown;
|
||||||
|
}) {
|
||||||
|
const message =
|
||||||
|
`[tier-detector] ${opts.service} unreachable or unusable at ` +
|
||||||
|
`${opts.host}:${opts.port} — ${opts.remediation}`;
|
||||||
|
super(message, { cause: opts.cause });
|
||||||
|
this.name = 'TierDetectionError';
|
||||||
|
this.service = opts.service;
|
||||||
|
this.host = opts.host;
|
||||||
|
this.port = opts.port;
|
||||||
|
this.remediation = opts.remediation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------ */
|
||||||
|
/* URL helpers */
|
||||||
|
/* ------------------------------------------------------------------ */
|
||||||
|
|
||||||
|
/** Extract host and port from a URL string, returning safe fallbacks on parse failure. */
|
||||||
|
function parseHostPort(url: string, defaultPort: number): { host: string; port: number } {
|
||||||
|
try {
|
||||||
|
const parsed = new URL(url);
|
||||||
|
const host = parsed.hostname || 'unknown';
|
||||||
|
const port = parsed.port ? parseInt(parsed.port, 10) : defaultPort;
|
||||||
|
return { host, port };
|
||||||
|
} catch {
|
||||||
|
return { host: 'unknown', port: defaultPort };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------ */
|
||||||
|
/* Postgres probe */
|
||||||
|
/* ------------------------------------------------------------------ */
|
||||||
|
|
||||||
|
async function probePostgres(url: string): Promise<void> {
|
||||||
|
const { host, port } = parseHostPort(url, 5432);
|
||||||
|
let sql: ReturnType<typeof postgres> | undefined;
|
||||||
|
try {
|
||||||
|
sql = postgres(url, {
|
||||||
|
max: 1,
|
||||||
|
connect_timeout: 5,
|
||||||
|
idle_timeout: 5,
|
||||||
|
});
|
||||||
|
// Run a trivial query to confirm connectivity.
|
||||||
|
await sql`SELECT 1`;
|
||||||
|
} catch (cause) {
|
||||||
|
throw new TierDetectionError({
|
||||||
|
service: 'postgres',
|
||||||
|
host,
|
||||||
|
port,
|
||||||
|
remediation:
|
||||||
|
'Start Postgres: `docker compose -f docker-compose.federated.yml --profile federated up -d postgres-federated`',
|
||||||
|
cause,
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
if (sql) {
|
||||||
|
await sql.end({ timeout: 2 }).catch(() => {
|
||||||
|
// Ignore cleanup errors — we already have what we need.
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------ */
|
||||||
|
/* pgvector probe */
|
||||||
|
/* ------------------------------------------------------------------ */
|
||||||
|
|
||||||
|
async function probePgvector(url: string): Promise<void> {
|
||||||
|
const { host, port } = parseHostPort(url, 5432);
|
||||||
|
let sql: ReturnType<typeof postgres> | undefined;
|
||||||
|
try {
|
||||||
|
sql = postgres(url, {
|
||||||
|
max: 1,
|
||||||
|
connect_timeout: 5,
|
||||||
|
idle_timeout: 5,
|
||||||
|
});
|
||||||
|
// This succeeds whether the extension is already installed or freshly created.
|
||||||
|
// It errors only if the pgvector shared library is missing from the Postgres binary.
|
||||||
|
await sql`CREATE EXTENSION IF NOT EXISTS vector`;
|
||||||
|
} catch (cause) {
|
||||||
|
const causeMsg = cause instanceof Error ? cause.message.toLowerCase() : '';
|
||||||
|
const isLibraryMissing = causeMsg.includes('extension "vector" is not available');
|
||||||
|
const remediation = isLibraryMissing
|
||||||
|
? 'Use the `pgvector/pgvector:pg17` image, not the stock `postgres:17` image. See `docker-compose.federated.yml`.'
|
||||||
|
: 'The database role lacks permission to CREATE EXTENSION. Grant `CREATE` on the database, or run as a superuser.';
|
||||||
|
throw new TierDetectionError({
|
||||||
|
service: 'pgvector',
|
||||||
|
host,
|
||||||
|
port,
|
||||||
|
remediation,
|
||||||
|
cause,
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
if (sql) {
|
||||||
|
await sql.end({ timeout: 2 }).catch(() => {
|
||||||
|
// Ignore cleanup errors.
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------ */
|
||||||
|
/* Valkey probe */
|
||||||
|
/* ------------------------------------------------------------------ */
|
||||||
|
|
||||||
|
const DEFAULT_VALKEY_URL = 'redis://localhost:6380';
|
||||||
|
|
||||||
|
async function probeValkey(url: string): Promise<void> {
|
||||||
|
const { host, port } = parseHostPort(url, 6380);
|
||||||
|
const client = new Redis(url, {
|
||||||
|
enableReadyCheck: false,
|
||||||
|
maxRetriesPerRequest: 0,
|
||||||
|
retryStrategy: () => null, // no retries — fail fast
|
||||||
|
lazyConnect: true,
|
||||||
|
connectTimeout: 5000, // fail-fast: 5-second hard cap on connection attempt
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
await client.connect();
|
||||||
|
const pong = await client.ping();
|
||||||
|
if (pong !== 'PONG') {
|
||||||
|
throw new Error(`Unexpected PING response: ${pong}`);
|
||||||
|
}
|
||||||
|
} catch (cause) {
|
||||||
|
throw new TierDetectionError({
|
||||||
|
service: 'valkey',
|
||||||
|
host,
|
||||||
|
port,
|
||||||
|
remediation:
|
||||||
|
'Start Valkey: `docker compose -f docker-compose.federated.yml --profile federated up -d valkey-federated`',
|
||||||
|
cause,
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
client.disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------ */
|
||||||
|
/* Public entry point */
|
||||||
|
/* ------------------------------------------------------------------ */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assert that all services required by `config.tier` are reachable.
|
||||||
|
*
|
||||||
|
* - `local` — no-op (PGlite is in-process; no external services).
|
||||||
|
* - `standalone` — assert Postgres + Valkey (if queue.type === 'bullmq').
|
||||||
|
* - `federated` — assert Postgres + Valkey + pgvector installability.
|
||||||
|
*
|
||||||
|
* Throws `TierDetectionError` on the first failure with host:port and
|
||||||
|
* a remediation hint.
|
||||||
|
*/
|
||||||
|
export async function detectAndAssertTier(config: MosaicConfig): Promise<void> {
|
||||||
|
if (config.tier === 'local') {
|
||||||
|
// PGlite runs in-process — nothing to probe.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const pgUrl =
|
||||||
|
config.storage.type === 'postgres' ? config.storage.url : 'postgresql://localhost:5432/mosaic';
|
||||||
|
|
||||||
|
const valkeyUrl =
|
||||||
|
config.queue.type === 'bullmq' ? (config.queue.url ?? DEFAULT_VALKEY_URL) : null;
|
||||||
|
|
||||||
|
if (config.tier === 'standalone') {
|
||||||
|
await probePostgres(pgUrl);
|
||||||
|
if (valkeyUrl) {
|
||||||
|
await probeValkey(valkeyUrl);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// tier === 'federated'
|
||||||
|
// Reject misconfigured queue upfront — federated requires bullmq + a Valkey URL.
|
||||||
|
if (config.queue.type !== 'bullmq') {
|
||||||
|
throw new TierDetectionError({
|
||||||
|
service: 'config',
|
||||||
|
host: 'localhost',
|
||||||
|
port: 0,
|
||||||
|
remediation:
|
||||||
|
"Federated tier requires queue.type === 'bullmq'. " +
|
||||||
|
"Set queue: { type: 'bullmq', url: 'redis://...' } in your mosaic.config.json.",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const federatedValkeyUrl = config.queue.url ?? DEFAULT_VALKEY_URL;
|
||||||
|
await probePostgres(pgUrl);
|
||||||
|
await probeValkey(federatedValkeyUrl);
|
||||||
|
await probePgvector(pgUrl);
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Global, Module } from '@nestjs/common';
|
import { Global, Module } from '@nestjs/common';
|
||||||
import { createBrain, type Brain } from '@mosaic/brain';
|
import { createBrain, type Brain } from '@mosaicstack/brain';
|
||||||
import type { Db } from '@mosaic/db';
|
import type { Db } from '@mosaicstack/db';
|
||||||
import { DB } from '../database/database.module.js';
|
import { DB } from '../database/database.module.js';
|
||||||
import { BRAIN } from './brain.tokens.js';
|
import { BRAIN } from './brain.tokens.js';
|
||||||
|
|
||||||
|
|||||||
@@ -11,15 +11,15 @@ import {
|
|||||||
} from '@nestjs/websockets';
|
} from '@nestjs/websockets';
|
||||||
import { Server, Socket } from 'socket.io';
|
import { Server, Socket } from 'socket.io';
|
||||||
import type { AgentSessionEvent } from '@mariozechner/pi-coding-agent';
|
import type { AgentSessionEvent } from '@mariozechner/pi-coding-agent';
|
||||||
import type { Auth } from '@mosaic/auth';
|
import type { Auth } from '@mosaicstack/auth';
|
||||||
import type { Brain } from '@mosaic/brain';
|
import type { Brain } from '@mosaicstack/brain';
|
||||||
import type {
|
import type {
|
||||||
SetThinkingPayload,
|
SetThinkingPayload,
|
||||||
SlashCommandPayload,
|
SlashCommandPayload,
|
||||||
SystemReloadPayload,
|
SystemReloadPayload,
|
||||||
RoutingDecisionInfo,
|
RoutingDecisionInfo,
|
||||||
AbortPayload,
|
AbortPayload,
|
||||||
} from '@mosaic/types';
|
} from '@mosaicstack/types';
|
||||||
import { AgentService, type ConversationHistoryMessage } from '../agent/agent.service.js';
|
import { AgentService, type ConversationHistoryMessage } from '../agent/agent.service.js';
|
||||||
import { AUTH } from '../auth/auth.tokens.js';
|
import { AUTH } from '../auth/auth.tokens.js';
|
||||||
import { BRAIN } from '../brain/brain.tokens.js';
|
import { BRAIN } from '../brain/brain.tokens.js';
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||||
import { CommandExecutorService } from './command-executor.service.js';
|
import { CommandExecutorService } from './command-executor.service.js';
|
||||||
import type { SlashCommandPayload } from '@mosaic/types';
|
import type { SlashCommandPayload } from '@mosaicstack/types';
|
||||||
|
|
||||||
// Minimal mock implementations
|
// Minimal mock implementations
|
||||||
const mockRegistry = {
|
const mockRegistry = {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { forwardRef, Inject, Injectable, Logger, Optional } from '@nestjs/common';
|
import { forwardRef, Inject, Injectable, Logger, Optional } from '@nestjs/common';
|
||||||
import type { QueueHandle } from '@mosaic/queue';
|
import type { QueueHandle } from '@mosaicstack/queue';
|
||||||
import type { Brain } from '@mosaic/brain';
|
import type { Brain } from '@mosaicstack/brain';
|
||||||
import type { SlashCommandPayload, SlashCommandResultPayload } from '@mosaic/types';
|
import type { SlashCommandPayload, SlashCommandResultPayload } from '@mosaicstack/types';
|
||||||
import { AgentService } from '../agent/agent.service.js';
|
import { AgentService } from '../agent/agent.service.js';
|
||||||
import { ChatGateway } from '../chat/chat.gateway.js';
|
import { ChatGateway } from '../chat/chat.gateway.js';
|
||||||
import { SessionGCService } from '../gc/session-gc.service.js';
|
import { SessionGCService } from '../gc/session-gc.service.js';
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { describe, it, expect, beforeEach } from 'vitest';
|
import { describe, it, expect, beforeEach } from 'vitest';
|
||||||
import { CommandRegistryService } from './command-registry.service.js';
|
import { CommandRegistryService } from './command-registry.service.js';
|
||||||
import type { CommandDef } from '@mosaic/types';
|
import type { CommandDef } from '@mosaicstack/types';
|
||||||
|
|
||||||
const mockCmd: CommandDef = {
|
const mockCmd: CommandDef = {
|
||||||
name: 'test',
|
name: 'test',
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Injectable, type OnModuleInit } from '@nestjs/common';
|
import { Injectable, type OnModuleInit } from '@nestjs/common';
|
||||||
import type { CommandDef, CommandManifest } from '@mosaic/types';
|
import type { CommandDef, CommandManifest } from '@mosaicstack/types';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CommandRegistryService implements OnModuleInit {
|
export class CommandRegistryService implements OnModuleInit {
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||||
import { CommandRegistryService } from './command-registry.service.js';
|
import { CommandRegistryService } from './command-registry.service.js';
|
||||||
import { CommandExecutorService } from './command-executor.service.js';
|
import { CommandExecutorService } from './command-executor.service.js';
|
||||||
import type { SlashCommandPayload } from '@mosaic/types';
|
import type { SlashCommandPayload } from '@mosaicstack/types';
|
||||||
|
|
||||||
// ─── Mocks ───────────────────────────────────────────────────────────────────
|
// ─── Mocks ───────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { forwardRef, Inject, Module, type OnApplicationShutdown } from '@nestjs/common';
|
import { forwardRef, Inject, Module, type OnApplicationShutdown } from '@nestjs/common';
|
||||||
import { createQueue, type QueueHandle } from '@mosaic/queue';
|
import { createQueue, type QueueHandle } from '@mosaicstack/queue';
|
||||||
import { ChatModule } from '../chat/chat.module.js';
|
import { ChatModule } from '../chat/chat.module.js';
|
||||||
import { GCModule } from '../gc/gc.module.js';
|
import { GCModule } from '../gc/gc.module.js';
|
||||||
import { ReloadModule } from '../reload/reload.module.js';
|
import { ReloadModule } from '../reload/reload.module.js';
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Global, Module } from '@nestjs/common';
|
import { Global, Module } from '@nestjs/common';
|
||||||
import { loadConfig, type MosaicConfig } from '@mosaic/config';
|
import { loadConfig, type MosaicConfig } from '@mosaicstack/config';
|
||||||
|
|
||||||
export const MOSAIC_CONFIG = 'MOSAIC_CONFIG';
|
export const MOSAIC_CONFIG = 'MOSAIC_CONFIG';
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import {
|
|||||||
Query,
|
Query,
|
||||||
UseGuards,
|
UseGuards,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import type { Brain } from '@mosaic/brain';
|
import type { Brain } from '@mosaicstack/brain';
|
||||||
import { BRAIN } from '../brain/brain.tokens.js';
|
import { BRAIN } from '../brain/brain.tokens.js';
|
||||||
import { AuthGuard } from '../auth/auth.guard.js';
|
import { AuthGuard } from '../auth/auth.guard.js';
|
||||||
import { CurrentUser } from '../auth/current-user.decorator.js';
|
import { CurrentUser } from '../auth/current-user.decorator.js';
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import {
|
|||||||
type MissionStatusSummary,
|
type MissionStatusSummary,
|
||||||
type MissionTask,
|
type MissionTask,
|
||||||
type TaskDetail,
|
type TaskDetail,
|
||||||
} from '@mosaic/coord';
|
} from '@mosaicstack/coord';
|
||||||
import { promises as fs } from 'node:fs';
|
import { promises as fs } from 'node:fs';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ import { mkdirSync } from 'node:fs';
|
|||||||
import { homedir } from 'node:os';
|
import { homedir } from 'node:os';
|
||||||
import { join } from 'node:path';
|
import { join } from 'node:path';
|
||||||
import { Global, Inject, Module, type OnApplicationShutdown } from '@nestjs/common';
|
import { Global, Inject, Module, type OnApplicationShutdown } from '@nestjs/common';
|
||||||
import { createDb, createPgliteDb, type Db, type DbHandle } from '@mosaic/db';
|
import { createDb, createPgliteDb, type Db, type DbHandle } from '@mosaicstack/db';
|
||||||
import { createStorageAdapter, type StorageAdapter } from '@mosaic/storage';
|
import { createStorageAdapter, type StorageAdapter } from '@mosaicstack/storage';
|
||||||
import type { MosaicConfig } from '@mosaic/config';
|
import type { MosaicConfig } from '@mosaicstack/config';
|
||||||
import { MOSAIC_CONFIG } from '../config/config.module.js';
|
import { MOSAIC_CONFIG } from '../config/config.module.js';
|
||||||
|
|
||||||
export const DB_HANDLE = 'DB_HANDLE';
|
export const DB_HANDLE = 'DB_HANDLE';
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Module, type OnApplicationShutdown, Inject } from '@nestjs/common';
|
import { Module, type OnApplicationShutdown, Inject } from '@nestjs/common';
|
||||||
import { createQueue, type QueueHandle } from '@mosaic/queue';
|
import { createQueue, type QueueHandle } from '@mosaicstack/queue';
|
||||||
import { SessionGCService } from './session-gc.service.js';
|
import { SessionGCService } from './session-gc.service.js';
|
||||||
import { REDIS } from './gc.tokens.js';
|
import { REDIS } from './gc.tokens.js';
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||||
import { Logger } from '@nestjs/common';
|
import { Logger } from '@nestjs/common';
|
||||||
import type { QueueHandle } from '@mosaic/queue';
|
import type { QueueHandle } from '@mosaicstack/queue';
|
||||||
import type { LogService } from '@mosaic/log';
|
import type { LogService } from '@mosaicstack/log';
|
||||||
import { SessionGCService } from './session-gc.service.js';
|
import { SessionGCService } from './session-gc.service.js';
|
||||||
|
|
||||||
type MockRedis = {
|
type MockRedis = {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Inject, Injectable, Logger, type OnModuleInit } from '@nestjs/common';
|
import { Inject, Injectable, Logger, type OnModuleInit } from '@nestjs/common';
|
||||||
import type { QueueHandle } from '@mosaic/queue';
|
import type { QueueHandle } from '@mosaicstack/queue';
|
||||||
import type { LogService } from '@mosaic/log';
|
import type { LogService } from '@mosaicstack/log';
|
||||||
import { LOG_SERVICE } from '../log/log.tokens.js';
|
import { LOG_SERVICE } from '../log/log.tokens.js';
|
||||||
import { REDIS } from './gc.tokens.js';
|
import { REDIS } from './gc.tokens.js';
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Body, Controller, Get, Inject, Param, Post, Query, UseGuards } from '@nestjs/common';
|
import { Body, Controller, Get, Inject, Param, Post, Query, UseGuards } from '@nestjs/common';
|
||||||
import type { LogService } from '@mosaic/log';
|
import type { LogService } from '@mosaicstack/log';
|
||||||
import { LOG_SERVICE } from './log.tokens.js';
|
import { LOG_SERVICE } from './log.tokens.js';
|
||||||
import { AuthGuard } from '../auth/auth.guard.js';
|
import { AuthGuard } from '../auth/auth.guard.js';
|
||||||
import type { IngestLogDto, QueryLogsDto } from './log.dto.js';
|
import type { IngestLogDto, QueryLogsDto } from './log.dto.js';
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Global, Module } from '@nestjs/common';
|
import { Global, Module } from '@nestjs/common';
|
||||||
import { createLogService, type LogService } from '@mosaic/log';
|
import { createLogService, type LogService } from '@mosaicstack/log';
|
||||||
import type { Db } from '@mosaic/db';
|
import type { Db } from '@mosaicstack/db';
|
||||||
import { DB } from '../database/database.module.js';
|
import { DB } from '../database/database.module.js';
|
||||||
import { LOG_SERVICE } from './log.tokens.js';
|
import { LOG_SERVICE } from './log.tokens.js';
|
||||||
import { LogController } from './log.controller.js';
|
import { LogController } from './log.controller.js';
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import { Inject, Injectable, Logger } from '@nestjs/common';
|
import { Inject, Injectable, Logger } from '@nestjs/common';
|
||||||
import type { LogService } from '@mosaic/log';
|
import type { LogService } from '@mosaicstack/log';
|
||||||
import type { Memory } from '@mosaic/memory';
|
import type { Memory } from '@mosaicstack/memory';
|
||||||
import { LOG_SERVICE } from './log.tokens.js';
|
import { LOG_SERVICE } from './log.tokens.js';
|
||||||
import { MEMORY } from '../memory/memory.tokens.js';
|
import { MEMORY } from '../memory/memory.tokens.js';
|
||||||
import { EmbeddingService } from '../memory/embedding.service.js';
|
import { EmbeddingService } from '../memory/embedding.service.js';
|
||||||
import type { Db } from '@mosaic/db';
|
import type { Db } from '@mosaicstack/db';
|
||||||
import { sql, summarizationJobs } from '@mosaic/db';
|
import { sql, summarizationJobs } from '@mosaicstack/db';
|
||||||
import { DB } from '../database/database.module.js';
|
import { DB } from '../database/database.module.js';
|
||||||
|
|
||||||
const SUMMARIZATION_PROMPT = `You are a knowledge extraction assistant. Given the following agent interaction logs, extract the key decisions, learnings, and patterns. Output a concise summary (2-4 sentences) that captures the most important information for future reference. Focus on actionable insights, not raw events.
|
const SUMMARIZATION_PROMPT = `You are a knowledge extraction assistant. Given the following agent interaction logs, extract the key decisions, learnings, and patterns. Output a concise summary (2-4 sentences) that captures the most important information for future reference. Focus on actionable insights, not raw events.
|
||||||
|
|||||||
@@ -19,11 +19,13 @@ import { NestFactory } from '@nestjs/core';
|
|||||||
import { Logger, ValidationPipe } from '@nestjs/common';
|
import { Logger, ValidationPipe } from '@nestjs/common';
|
||||||
import { FastifyAdapter, type NestFastifyApplication } from '@nestjs/platform-fastify';
|
import { FastifyAdapter, type NestFastifyApplication } from '@nestjs/platform-fastify';
|
||||||
import helmet from '@fastify/helmet';
|
import helmet from '@fastify/helmet';
|
||||||
import { listSsoStartupWarnings } from '@mosaic/auth';
|
import { listSsoStartupWarnings } from '@mosaicstack/auth';
|
||||||
|
import { loadConfig } from '@mosaicstack/config';
|
||||||
import { AppModule } from './app.module.js';
|
import { AppModule } from './app.module.js';
|
||||||
import { mountAuthHandler } from './auth/auth.controller.js';
|
import { mountAuthHandler } from './auth/auth.controller.js';
|
||||||
import { mountMcpHandler } from './mcp/mcp.controller.js';
|
import { mountMcpHandler } from './mcp/mcp.controller.js';
|
||||||
import { McpService } from './mcp/mcp.service.js';
|
import { McpService } from './mcp/mcp.service.js';
|
||||||
|
import { detectAndAssertTier, TierDetectionError } from './bootstrap/tier-detector.js';
|
||||||
|
|
||||||
async function bootstrap(): Promise<void> {
|
async function bootstrap(): Promise<void> {
|
||||||
const logger = new Logger('Bootstrap');
|
const logger = new Logger('Bootstrap');
|
||||||
@@ -32,6 +34,20 @@ async function bootstrap(): Promise<void> {
|
|||||||
throw new Error('BETTER_AUTH_SECRET is required');
|
throw new Error('BETTER_AUTH_SECRET is required');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Pre-flight: assert all external services required by the configured tier
|
||||||
|
// are reachable. Runs before NestFactory.create() so failures are visible
|
||||||
|
// immediately with actionable remediation hints.
|
||||||
|
const mosaicConfig = loadConfig();
|
||||||
|
try {
|
||||||
|
await detectAndAssertTier(mosaicConfig);
|
||||||
|
} catch (err) {
|
||||||
|
if (err instanceof TierDetectionError) {
|
||||||
|
logger.error(`Tier detection failed: ${err.message}`);
|
||||||
|
logger.error(`Remediation: ${err.remediation}`);
|
||||||
|
}
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
|
||||||
for (const warning of listSsoStartupWarnings()) {
|
for (const warning of listSsoStartupWarnings()) {
|
||||||
logger.warn(warning);
|
logger.warn(warning);
|
||||||
}
|
}
|
||||||
@@ -59,7 +75,7 @@ async function bootstrap(): Promise<void> {
|
|||||||
mountAuthHandler(app);
|
mountAuthHandler(app);
|
||||||
mountMcpHandler(app, app.get(McpService));
|
mountMcpHandler(app, app.get(McpService));
|
||||||
|
|
||||||
const port = Number(process.env['GATEWAY_PORT'] ?? 4000);
|
const port = Number(process.env['GATEWAY_PORT'] ?? 14242);
|
||||||
await app.listen(port, '0.0.0.0');
|
await app.listen(port, '0.0.0.0');
|
||||||
logger.log(`Gateway listening on port ${port}`);
|
logger.log(`Gateway listening on port ${port}`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { IncomingMessage, ServerResponse } from 'node:http';
|
import type { IncomingMessage, ServerResponse } from 'node:http';
|
||||||
import { Logger } from '@nestjs/common';
|
import { Logger } from '@nestjs/common';
|
||||||
import { fromNodeHeaders } from 'better-auth/node';
|
import { fromNodeHeaders } from 'better-auth/node';
|
||||||
import type { Auth } from '@mosaic/auth';
|
import type { Auth } from '@mosaicstack/auth';
|
||||||
import type { NestFastifyApplication } from '@nestjs/platform-fastify';
|
import type { NestFastifyApplication } from '@nestjs/platform-fastify';
|
||||||
import type { McpService } from './mcp.service.js';
|
import type { McpService } from './mcp.service.js';
|
||||||
import { AUTH } from '../auth/auth.tokens.js';
|
import { AUTH } from '../auth/auth.tokens.js';
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|||||||
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
||||||
import { randomUUID } from 'node:crypto';
|
import { randomUUID } from 'node:crypto';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import type { Brain } from '@mosaic/brain';
|
import type { Brain } from '@mosaicstack/brain';
|
||||||
import type { Memory } from '@mosaic/memory';
|
import type { Memory } from '@mosaicstack/memory';
|
||||||
import { BRAIN } from '../brain/brain.tokens.js';
|
import { BRAIN } from '../brain/brain.tokens.js';
|
||||||
import { MEMORY } from '../memory/memory.tokens.js';
|
import { MEMORY } from '../memory/memory.tokens.js';
|
||||||
import { EmbeddingService } from '../memory/embedding.service.js';
|
import { EmbeddingService } from '../memory/embedding.service.js';
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Injectable, Logger } from '@nestjs/common';
|
import { Injectable, Logger } from '@nestjs/common';
|
||||||
import type { EmbeddingProvider } from '@mosaic/memory';
|
import type { EmbeddingProvider } from '@mosaicstack/memory';
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Environment-driven configuration
|
// Environment-driven configuration
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import {
|
|||||||
Query,
|
Query,
|
||||||
UseGuards,
|
UseGuards,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import type { Memory } from '@mosaic/memory';
|
import type { Memory } from '@mosaicstack/memory';
|
||||||
import { MEMORY } from './memory.tokens.js';
|
import { MEMORY } from './memory.tokens.js';
|
||||||
import { AuthGuard } from '../auth/auth.guard.js';
|
import { AuthGuard } from '../auth/auth.guard.js';
|
||||||
import { CurrentUser } from '../auth/current-user.decorator.js';
|
import { CurrentUser } from '../auth/current-user.decorator.js';
|
||||||
|
|||||||
@@ -5,10 +5,10 @@ import {
|
|||||||
createMemoryAdapter,
|
createMemoryAdapter,
|
||||||
type MemoryAdapter,
|
type MemoryAdapter,
|
||||||
type MemoryConfig,
|
type MemoryConfig,
|
||||||
} from '@mosaic/memory';
|
} from '@mosaicstack/memory';
|
||||||
import type { Db } from '@mosaic/db';
|
import type { Db } from '@mosaicstack/db';
|
||||||
import type { StorageAdapter } from '@mosaic/storage';
|
import type { StorageAdapter } from '@mosaicstack/storage';
|
||||||
import type { MosaicConfig } from '@mosaic/config';
|
import type { MosaicConfig } from '@mosaicstack/config';
|
||||||
import { MOSAIC_CONFIG } from '../config/config.module.js';
|
import { MOSAIC_CONFIG } from '../config/config.module.js';
|
||||||
import { DB, STORAGE_ADAPTER } from '../database/database.module.js';
|
import { DB, STORAGE_ADAPTER } from '../database/database.module.js';
|
||||||
import { MEMORY } from './memory.tokens.js';
|
import { MEMORY } from './memory.tokens.js';
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import {
|
|||||||
Post,
|
Post,
|
||||||
UseGuards,
|
UseGuards,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import type { Brain } from '@mosaic/brain';
|
import type { Brain } from '@mosaicstack/brain';
|
||||||
import { BRAIN } from '../brain/brain.tokens.js';
|
import { BRAIN } from '../brain/brain.tokens.js';
|
||||||
import { AuthGuard } from '../auth/auth.guard.js';
|
import { AuthGuard } from '../auth/auth.guard.js';
|
||||||
import { CurrentUser } from '../auth/current-user.decorator.js';
|
import { CurrentUser } from '../auth/current-user.decorator.js';
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import {
|
|||||||
type OnModuleDestroy,
|
type OnModuleDestroy,
|
||||||
type OnModuleInit,
|
type OnModuleInit,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { DiscordPlugin } from '@mosaic/discord-plugin';
|
import { DiscordPlugin } from '@mosaicstack/discord-plugin';
|
||||||
import { TelegramPlugin } from '@mosaic/telegram-plugin';
|
import { TelegramPlugin } from '@mosaicstack/telegram-plugin';
|
||||||
import { PluginService } from './plugin.service.js';
|
import { PluginService } from './plugin.service.js';
|
||||||
import type { IChannelPlugin } from './plugin.interface.js';
|
import type { IChannelPlugin } from './plugin.interface.js';
|
||||||
import { PLUGIN_REGISTRY } from './plugin.tokens.js';
|
import { PLUGIN_REGISTRY } from './plugin.tokens.js';
|
||||||
@@ -48,7 +48,7 @@ class TelegramChannelPluginAdapter implements IChannelPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const DEFAULT_GATEWAY_URL = 'http://localhost:4000';
|
const DEFAULT_GATEWAY_URL = 'http://localhost:14242';
|
||||||
|
|
||||||
function createPluginRegistry(): IChannelPlugin[] {
|
function createPluginRegistry(): IChannelPlugin[] {
|
||||||
const plugins: IChannelPlugin[] = [];
|
const plugins: IChannelPlugin[] = [];
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { describe, it, expect, vi } from 'vitest';
|
import { describe, it, expect, vi } from 'vitest';
|
||||||
import { PreferencesService, PLATFORM_DEFAULTS, IMMUTABLE_KEYS } from './preferences.service.js';
|
import { PreferencesService, PLATFORM_DEFAULTS, IMMUTABLE_KEYS } from './preferences.service.js';
|
||||||
import type { Db } from '@mosaic/db';
|
import type { Db } from '@mosaicstack/db';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build a mock Drizzle DB where the select chain supports:
|
* Build a mock Drizzle DB where the select chain supports:
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Inject, Injectable, Logger } from '@nestjs/common';
|
import { Inject, Injectable, Logger } from '@nestjs/common';
|
||||||
import { eq, and, sql, type Db, preferences as preferencesTable } from '@mosaic/db';
|
import { eq, and, sql, type Db, preferences as preferencesTable } from '@mosaicstack/db';
|
||||||
import { DB } from '../database/database.module.js';
|
import { DB } from '../database/database.module.js';
|
||||||
|
|
||||||
export const PLATFORM_DEFAULTS: Record<string, unknown> = {
|
export const PLATFORM_DEFAULTS: Record<string, unknown> = {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Injectable, Logger } from '@nestjs/common';
|
import { Injectable, Logger } from '@nestjs/common';
|
||||||
import { createQueue, type QueueHandle } from '@mosaic/queue';
|
import { createQueue, type QueueHandle } from '@mosaicstack/queue';
|
||||||
|
|
||||||
const SESSION_SYSTEM_KEY = (sessionId: string) => `mosaic:session:${sessionId}:system`;
|
const SESSION_SYSTEM_KEY = (sessionId: string) => `mosaic:session:${sessionId}:system`;
|
||||||
const SESSION_SYSTEM_FRAGMENTS_KEY = (sessionId: string) =>
|
const SESSION_SYSTEM_FRAGMENTS_KEY = (sessionId: string) =>
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import {
|
|||||||
Post,
|
Post,
|
||||||
UseGuards,
|
UseGuards,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import type { Brain } from '@mosaic/brain';
|
import type { Brain } from '@mosaicstack/brain';
|
||||||
import { BRAIN } from '../brain/brain.tokens.js';
|
import { BRAIN } from '../brain/brain.tokens.js';
|
||||||
import { AuthGuard } from '../auth/auth.guard.js';
|
import { AuthGuard } from '../auth/auth.guard.js';
|
||||||
import { CurrentUser } from '../auth/current-user.decorator.js';
|
import { CurrentUser } from '../auth/current-user.decorator.js';
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Global, Module } from '@nestjs/common';
|
import { Global, Module } from '@nestjs/common';
|
||||||
import { createQueueAdapter, type QueueAdapter } from '@mosaic/queue';
|
import { createQueueAdapter, type QueueAdapter } from '@mosaicstack/queue';
|
||||||
import type { MosaicConfig } from '@mosaic/config';
|
import type { MosaicConfig } from '@mosaicstack/config';
|
||||||
import { MOSAIC_CONFIG } from '../config/config.module.js';
|
import { MOSAIC_CONFIG } from '../config/config.module.js';
|
||||||
import { QueueService } from './queue.service.js';
|
import { QueueService } from './queue.service.js';
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import {
|
|||||||
type OnModuleDestroy,
|
type OnModuleDestroy,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { Queue, Worker, type Job, type ConnectionOptions } from 'bullmq';
|
import { Queue, Worker, type Job, type ConnectionOptions } from 'bullmq';
|
||||||
import type { LogService } from '@mosaic/log';
|
import type { LogService } from '@mosaicstack/log';
|
||||||
import { LOG_SERVICE } from '../log/log.tokens.js';
|
import { LOG_SERVICE } from '../log/log.tokens.js';
|
||||||
import type { JobDto, JobStatus } from './queue-admin.dto.js';
|
import type { JobDto, JobStatus } from './queue-admin.dto.js';
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Controller, HttpCode, HttpStatus, Inject, Post, UseGuards } from '@nestjs/common';
|
import { Controller, HttpCode, HttpStatus, Inject, Post, UseGuards } from '@nestjs/common';
|
||||||
import type { SystemReloadPayload } from '@mosaic/types';
|
import type { SystemReloadPayload } from '@mosaicstack/types';
|
||||||
import { AdminGuard } from '../admin/admin.guard.js';
|
import { AdminGuard } from '../admin/admin.guard.js';
|
||||||
import { ChatGateway } from '../chat/chat.gateway.js';
|
import { ChatGateway } from '../chat/chat.gateway.js';
|
||||||
import { ReloadService } from './reload.service.js';
|
import { ReloadService } from './reload.service.js';
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
type OnApplicationBootstrap,
|
type OnApplicationBootstrap,
|
||||||
type OnApplicationShutdown,
|
type OnApplicationShutdown,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import type { SystemReloadPayload } from '@mosaic/types';
|
import type { SystemReloadPayload } from '@mosaicstack/types';
|
||||||
import { CommandRegistryService } from '../commands/command-registry.service.js';
|
import { CommandRegistryService } from '../commands/command-registry.service.js';
|
||||||
import { isMosaicPlugin } from './mosaic-plugin.interface.js';
|
import { isMosaicPlugin } from './mosaic-plugin.interface.js';
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Inject, Injectable } from '@nestjs/common';
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
import { eq, type Db, skills } from '@mosaic/db';
|
import { eq, type Db, skills } from '@mosaicstack/db';
|
||||||
import { DB } from '../database/database.module.js';
|
import { DB } from '../database/database.module.js';
|
||||||
|
|
||||||
type Skill = typeof skills.$inferSelect;
|
type Skill = typeof skills.$inferSelect;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import {
|
|||||||
Query,
|
Query,
|
||||||
UseGuards,
|
UseGuards,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import type { Brain } from '@mosaic/brain';
|
import type { Brain } from '@mosaicstack/brain';
|
||||||
import { BRAIN } from '../brain/brain.tokens.js';
|
import { BRAIN } from '../brain/brain.tokens.js';
|
||||||
import { AuthGuard } from '../auth/auth.guard.js';
|
import { AuthGuard } from '../auth/auth.guard.js';
|
||||||
import { CurrentUser } from '../auth/current-user.decorator.js';
|
import { CurrentUser } from '../auth/current-user.decorator.js';
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Inject, Injectable, Logger } from '@nestjs/common';
|
import { Inject, Injectable, Logger } from '@nestjs/common';
|
||||||
import type { Brain } from '@mosaic/brain';
|
import type { Brain } from '@mosaicstack/brain';
|
||||||
import { BRAIN } from '../brain/brain.tokens.js';
|
import { BRAIN } from '../brain/brain.tokens.js';
|
||||||
import { PluginService } from '../plugin/plugin.service.js';
|
import { PluginService } from '../plugin/plugin.service.js';
|
||||||
import { WorkspaceService } from './workspace.service.js';
|
import { WorkspaceService } from './workspace.service.js';
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Inject, Injectable, Logger } from '@nestjs/common';
|
import { Inject, Injectable, Logger } from '@nestjs/common';
|
||||||
import { eq, and, type Db, teams, teamMembers, projects } from '@mosaic/db';
|
import { eq, and, type Db, teams, teamMembers, projects } from '@mosaicstack/db';
|
||||||
import { DB } from '../database/database.module.js';
|
import { DB } from '../database/database.module.js';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
|||||||
@@ -4,15 +4,15 @@
|
|||||||
"rootDir": "../..",
|
"rootDir": "../..",
|
||||||
"baseUrl": ".",
|
"baseUrl": ".",
|
||||||
"paths": {
|
"paths": {
|
||||||
"@mosaic/auth": ["../../packages/auth/src/index.ts"],
|
"@mosaicstack/auth": ["../../packages/auth/src/index.ts"],
|
||||||
"@mosaic/brain": ["../../packages/brain/src/index.ts"],
|
"@mosaicstack/brain": ["../../packages/brain/src/index.ts"],
|
||||||
"@mosaic/coord": ["../../packages/coord/src/index.ts"],
|
"@mosaicstack/coord": ["../../packages/coord/src/index.ts"],
|
||||||
"@mosaic/db": ["../../packages/db/src/index.ts"],
|
"@mosaicstack/db": ["../../packages/db/src/index.ts"],
|
||||||
"@mosaic/log": ["../../packages/log/src/index.ts"],
|
"@mosaicstack/log": ["../../packages/log/src/index.ts"],
|
||||||
"@mosaic/memory": ["../../packages/memory/src/index.ts"],
|
"@mosaicstack/memory": ["../../packages/memory/src/index.ts"],
|
||||||
"@mosaic/types": ["../../packages/types/src/index.ts"],
|
"@mosaicstack/types": ["../../packages/types/src/index.ts"],
|
||||||
"@mosaic/discord-plugin": ["../../plugins/discord/src/index.ts"],
|
"@mosaicstack/discord-plugin": ["../../plugins/discord/src/index.ts"],
|
||||||
"@mosaic/telegram-plugin": ["../../plugins/telegram/src/index.ts"]
|
"@mosaicstack/telegram-plugin": ["../../plugins/telegram/src/index.ts"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import swc from 'unplugin-swc';
|
||||||
import { defineConfig } from 'vitest/config';
|
import { defineConfig } from 'vitest/config';
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
@@ -5,4 +6,22 @@ export default defineConfig({
|
|||||||
globals: true,
|
globals: true,
|
||||||
environment: 'node',
|
environment: 'node',
|
||||||
},
|
},
|
||||||
|
plugins: [
|
||||||
|
swc.vite({
|
||||||
|
jsc: {
|
||||||
|
parser: {
|
||||||
|
syntax: 'typescript',
|
||||||
|
decorators: true,
|
||||||
|
},
|
||||||
|
transform: {
|
||||||
|
decoratorMetadata: true,
|
||||||
|
legacyDecorator: true,
|
||||||
|
},
|
||||||
|
target: 'es2022',
|
||||||
|
},
|
||||||
|
module: {
|
||||||
|
type: 'nodenext',
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import type { NextConfig } from 'next';
|
|||||||
|
|
||||||
const nextConfig: NextConfig = {
|
const nextConfig: NextConfig = {
|
||||||
output: 'standalone',
|
output: 'standalone',
|
||||||
transpilePackages: ['@mosaic/design-tokens'],
|
transpilePackages: ['@mosaicstack/design-tokens'],
|
||||||
|
|
||||||
// Enable gzip/brotli compression for all responses.
|
// Enable gzip/brotli compression for all responses.
|
||||||
compress: true,
|
compress: true,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "@mosaic/web",
|
"name": "@mosaicstack/web",
|
||||||
"version": "0.0.2",
|
"version": "0.0.2",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
"start": "next start"
|
"start": "next start"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@mosaic/design-tokens": "workspace:^",
|
"@mosaicstack/design-tokens": "workspace:^",
|
||||||
"better-auth": "^1.5.5",
|
"better-auth": "^1.5.5",
|
||||||
"clsx": "^2.1.0",
|
"clsx": "^2.1.0",
|
||||||
"next": "^16.0.0",
|
"next": "^16.0.0",
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ import { defineConfig, devices } from '@playwright/test';
|
|||||||
*
|
*
|
||||||
* Assumes:
|
* Assumes:
|
||||||
* - Next.js web app running on http://localhost:3000
|
* - Next.js web app running on http://localhost:3000
|
||||||
* - NestJS gateway running on http://localhost:4000
|
* - NestJS gateway running on http://localhost:14242
|
||||||
*
|
*
|
||||||
* Run with: pnpm --filter @mosaic/web test:e2e
|
* Run with: pnpm --filter @mosaicstack/web test:e2e
|
||||||
*/
|
*/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
testDir: './e2e',
|
testDir: './e2e',
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const GATEWAY_URL = process.env['NEXT_PUBLIC_GATEWAY_URL'] ?? 'http://localhost:4000';
|
const GATEWAY_URL = process.env['NEXT_PUBLIC_GATEWAY_URL'] ?? 'http://localhost:14242';
|
||||||
|
|
||||||
export interface ApiRequestInit extends Omit<RequestInit, 'body'> {
|
export interface ApiRequestInit extends Omit<RequestInit, 'body'> {
|
||||||
body?: unknown;
|
body?: unknown;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { createAuthClient } from 'better-auth/react';
|
|||||||
import { adminClient, genericOAuthClient } from 'better-auth/client/plugins';
|
import { adminClient, genericOAuthClient } from 'better-auth/client/plugins';
|
||||||
|
|
||||||
export const authClient = createAuthClient({
|
export const authClient = createAuthClient({
|
||||||
baseURL: process.env['NEXT_PUBLIC_GATEWAY_URL'] ?? 'http://localhost:4000',
|
baseURL: process.env['NEXT_PUBLIC_GATEWAY_URL'] ?? 'http://localhost:14242',
|
||||||
plugins: [adminClient(), genericOAuthClient()],
|
plugins: [adminClient(), genericOAuthClient()],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { io, type Socket } from 'socket.io-client';
|
import { io, type Socket } from 'socket.io-client';
|
||||||
|
|
||||||
const GATEWAY_URL = process.env['NEXT_PUBLIC_GATEWAY_URL'] ?? 'http://localhost:4000';
|
const GATEWAY_URL = process.env['NEXT_PUBLIC_GATEWAY_URL'] ?? 'http://localhost:14242';
|
||||||
|
|
||||||
let socket: Socket | null = null;
|
let socket: Socket | null = null;
|
||||||
|
|
||||||
|
|||||||
60
docker-compose.federated.yml
Normal file
60
docker-compose.federated.yml
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
# docker-compose.federated.yml — Federated tier overlay
|
||||||
|
#
|
||||||
|
# USAGE:
|
||||||
|
# docker compose -f docker-compose.federated.yml --profile federated up -d
|
||||||
|
#
|
||||||
|
# This file is a standalone overlay for the Mosaic federated tier.
|
||||||
|
# It is NOT an extension of docker-compose.yml — it defines its own services
|
||||||
|
# and named volumes so it can run independently of the base dev stack.
|
||||||
|
#
|
||||||
|
# IMPORTANT — HOST PORT CONFLICTS:
|
||||||
|
# The federated services bind the same host ports as the base dev stack
|
||||||
|
# (5433 for Postgres, 6380 for Valkey). You must stop the base dev stack
|
||||||
|
# before starting the federated stack on the same machine:
|
||||||
|
# docker compose down
|
||||||
|
# docker compose -f docker-compose.federated.yml --profile federated up -d
|
||||||
|
#
|
||||||
|
# pgvector extension:
|
||||||
|
# The vector extension is created automatically at first boot via
|
||||||
|
# ./infra/pg-init/01-extensions.sql (CREATE EXTENSION IF NOT EXISTS vector).
|
||||||
|
#
|
||||||
|
# Tier configuration:
|
||||||
|
# Used by `mosaic` instances configured with `tier: federated`.
|
||||||
|
# DEFAULT_FEDERATED_CONFIG points at:
|
||||||
|
# postgresql://mosaic:mosaic@localhost:5433/mosaic
|
||||||
|
|
||||||
|
services:
|
||||||
|
postgres-federated:
|
||||||
|
image: pgvector/pgvector:pg17
|
||||||
|
profiles: [federated]
|
||||||
|
ports:
|
||||||
|
- '${PG_FEDERATED_HOST_PORT:-5433}:5432'
|
||||||
|
environment:
|
||||||
|
POSTGRES_USER: mosaic
|
||||||
|
POSTGRES_PASSWORD: mosaic
|
||||||
|
POSTGRES_DB: mosaic
|
||||||
|
volumes:
|
||||||
|
- pg_federated_data:/var/lib/postgresql/data
|
||||||
|
- ./infra/pg-init:/docker-entrypoint-initdb.d:ro
|
||||||
|
healthcheck:
|
||||||
|
test: ['CMD-SHELL', 'pg_isready -U mosaic']
|
||||||
|
interval: 5s
|
||||||
|
timeout: 3s
|
||||||
|
retries: 5
|
||||||
|
|
||||||
|
valkey-federated:
|
||||||
|
image: valkey/valkey:8-alpine
|
||||||
|
profiles: [federated]
|
||||||
|
ports:
|
||||||
|
- '${VALKEY_FEDERATED_HOST_PORT:-6380}:6379'
|
||||||
|
volumes:
|
||||||
|
- valkey_federated_data:/data
|
||||||
|
healthcheck:
|
||||||
|
test: ['CMD', 'valkey-cli', 'ping']
|
||||||
|
interval: 5s
|
||||||
|
timeout: 3s
|
||||||
|
retries: 5
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
pg_federated_data:
|
||||||
|
valkey_federated_data:
|
||||||
@@ -1,70 +1,116 @@
|
|||||||
# Mission Manifest — Harness Foundation
|
# Mission Manifest — MVP
|
||||||
|
|
||||||
> Persistent document tracking full mission scope, status, and session history.
|
> Top-level rollup tracking Mosaic Stack MVP execution.
|
||||||
> Updated by the orchestrator at each phase transition and milestone completion.
|
> Workstreams have their own manifests; this document is the source of truth for MVP scope, status, and history.
|
||||||
|
> Owner: Orchestrator (sole writer).
|
||||||
|
|
||||||
## Mission
|
## Mission
|
||||||
|
|
||||||
**ID:** harness-20260321
|
**ID:** mvp-20260312
|
||||||
**Statement:** Transform Mosaic Stack from a functional demo into a real multi-provider, task-routing AI harness. Persist all conversations, integrate frontier LLM providers (Anthropic, OpenAI, OpenRouter, Z.ai, Ollama), build granular task-aware agent routing, harden agent sessions, replace cron with BullMQ, and design the channel protocol for future Matrix/remote integration.
|
**Statement:** Ship a self-hosted, multi-user AI agent platform that consolidates the user's disparate jarvis-brain usage across home and USC workstations into a single coherent system reachable via three first-class surfaces — webUI, TUI, and CLI — with federation as the data-layer mechanism that makes cross-host agent sessions work in real time without copying user data across the boundary.
|
||||||
**Phase:** Complete
|
**Phase:** Execution (workstream W1 in planning-complete state)
|
||||||
**Current Milestone:** All milestones done
|
**Current Workstream:** W1 — Federation v1
|
||||||
**Progress:** 7 / 7 milestones
|
**Progress:** 0 / 1 declared workstreams complete (more workstreams will be declared as scope is refined)
|
||||||
**Status:** complete
|
**Status:** active (continuous since 2026-03-13)
|
||||||
**Last Updated:** 2026-03-22 UTC
|
**Last Updated:** 2026-04-19 (manifest authored at the rollup level; install-ux-v2 archived; W1 federation planning landed via PR #468)
|
||||||
|
**Source PRD:** [docs/PRD.md](./PRD.md) — Mosaic Stack v0.1.0
|
||||||
|
**Scratchpad:** [docs/scratchpads/mvp-20260312.md](./scratchpads/mvp-20260312.md) (active since 2026-03-13; 14 prior sessions of phase-based execution)
|
||||||
|
|
||||||
|
## Context
|
||||||
|
|
||||||
|
Jarvis (v0.2.0) was a single-host Python/Next.js assistant. The user runs sessions across 3–4 workstations split between home and USC. Today every session reaches back to a single jarvis-brain checkout, which is brittle (offline-hostile, no consolidation, no shared state beyond a single repo). A prior OpenBrain attempt punished offline use, introduced cache/latency/opacity pain, and tightly coupled every session to a remote service.
|
||||||
|
|
||||||
|
The MVP solution: keep each user's home gateway as the source of truth, connect gateways gateway-to-gateway over mTLS with scoped read-only data exposure, and expose the unified experience through three coherent surfaces:
|
||||||
|
|
||||||
|
- **webUI** — the primary visual control plane (Next.js + React 19, `apps/web`)
|
||||||
|
- **TUI** — the terminal-native interface for agent work (`packages/mosaic` wizard + Pi TUI)
|
||||||
|
- **CLI** — `mosaic` command for scripted/headless workflows
|
||||||
|
|
||||||
|
Federation is required NOW because it unblocks cross-host consolidation; it is necessary but not sufficient for MVP. Additional workstreams will be declared as their scope solidifies.
|
||||||
|
|
||||||
|
## Prior Execution (March 13 → April 5)
|
||||||
|
|
||||||
|
This manifest was authored on 2026-04-19 to rollup work that began 2026-03-13. Before this date, MVP work was tracked via phase-based Gitea milestones and the scratchpad — there was no rollup manifest at the `docs/MISSION-MANIFEST.md` path (the slot was occupied by sub-mission manifests for `install-ux-hardening` and then `install-ux-v2`).
|
||||||
|
|
||||||
|
Prior execution outline (full detail in [scratchpads/mvp-20260312.md](./scratchpads/mvp-20260312.md)):
|
||||||
|
|
||||||
|
- **Phases 0 → 7** (Gitea milestones `ms-157` → `ms-164`, issues #1–#59): foundation, core API, agent layer, web dashboard, memory, remote control, CLI/tools, polish/beta. Substantially shipped by Session 13.
|
||||||
|
- **Phase 8** (Gitea milestone `ms-165`, issues #160–#172): platform architecture extension — teams, workspaces, `/provider` OAuth, preferences, etc. Wave-based execution plan defined at Session 14.
|
||||||
|
- **Sub-missions** during the gap: `install-ux-hardening` (complete, `mosaic-v0.0.25`), `install-ux-v2` (complete on 2026-04-19, `0.0.27` → `0.0.29`). Both archived under `docs/archive/missions/`.
|
||||||
|
|
||||||
|
Going forward, MVP execution is tracked through the **Workstreams** table below. Phase-based issue numbering is preserved on Gitea but is no longer the primary control plane.
|
||||||
|
|
||||||
|
## Cross-Cutting MVP Requirements
|
||||||
|
|
||||||
|
These apply to every workstream and every milestone. A workstream cannot ship if it breaks any of them.
|
||||||
|
|
||||||
|
| # | Requirement |
|
||||||
|
| ------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
|
| MVP-X1 | Three-surface parity: every user-facing capability is reachable via webUI **and** TUI **and** CLI (read paths at minimum; mutating paths where applicable to the surface). |
|
||||||
|
| MVP-X2 | Multi-tenant isolation is enforced at every boundary; no cross-user leakage under any circumstance. |
|
||||||
|
| MVP-X3 | Auth via BetterAuth (existing); SSO adapters per PRD; admin bootstrap remains a one-shot. |
|
||||||
|
| MVP-X4 | Three quality gates green before push: `pnpm typecheck`, `pnpm lint`, `pnpm format:check`. |
|
||||||
|
| MVP-X5 | Federated tier (PG + pgvector + Valkey) is the canonical MVP deployment topology; local/standalone tiers continue to work for non-federated installs but are not the MVP target. |
|
||||||
|
| MVP-X6 | OTEL tracing on every request path; `traceparent` propagated across the federation boundary in both directions. |
|
||||||
|
| MVP-X7 | Trunk merge strategy: branch from `main`, squash-merge via PR, never push to `main` directly. |
|
||||||
|
|
||||||
## Success Criteria
|
## Success Criteria
|
||||||
|
|
||||||
- [x] AC-1: Send messages in TUI → restart TUI → resume conversation → agent has full history and context
|
The MVP is complete when ALL declared workstreams are complete AND every cross-cutting requirement is verifiable on a live two-host deployment (woltje.com ↔ uscllc.com).
|
||||||
- [x] AC-2: Route a coding task to Claude Opus 4.6, a simple question to Haiku, a summarization to GLM-5 — all via granular routing rules
|
|
||||||
- [x] AC-3: Two users exist, User A's memory searches never return User B's data
|
|
||||||
- [x] AC-4: `/model claude-sonnet-4-6` in TUI switches the active model for subsequent messages
|
|
||||||
- [x] AC-5: `/agent coding-agent` in TUI switches to a different agent with different system prompt and tools
|
|
||||||
- [x] AC-6: BullMQ jobs execute on schedule, failures retry with backoff, admin can inspect via `/api/admin/jobs`
|
|
||||||
- [x] AC-7: Channel protocol document exists with Matrix integration points defined, reviewed, and approved
|
|
||||||
- [x] AC-8: Embeddings run on Ollama local models (no external API dependency for vector operations)
|
|
||||||
- [x] AC-9: All five providers (Anthropic, OpenAI, OpenRouter, Z.ai, Ollama) connect, list models, and complete chat requests
|
|
||||||
- [x] AC-10: Routing transparency — TUI displays which model was selected and the routing reason for each response
|
|
||||||
|
|
||||||
## Milestones
|
- [ ] AC-MVP-1: All declared workstreams reach `complete` status with merged PRs and green CI
|
||||||
|
- [ ] AC-MVP-2: A user session on the home gateway can transparently query work-gateway data subject to scope, with no data persisted across the boundary
|
||||||
|
- [ ] AC-MVP-3: The same user-facing capability is reachable from webUI, TUI, and CLI (per MVP-X1)
|
||||||
|
- [ ] AC-MVP-4: Two-gateway production deployment (woltje.com ↔ uscllc.com) operational ≥7 days without incident
|
||||||
|
- [ ] AC-MVP-5: All cross-cutting requirements (MVP-X1 → MVP-X7) verified with evidence
|
||||||
|
- [ ] AC-MVP-6: PRD `docs/PRD.md` "In Scope (v0.1.0 Beta)" list mapped to evidence (each item: shipped / explicitly deferred with rationale)
|
||||||
|
|
||||||
| # | ID | Name | Status | Branch | Issue | Started | Completed |
|
## Workstreams
|
||||||
| --- | ------ | ---------------------------------- | ------ | ------ | --------- | ---------- | ---------- |
|
|
||||||
| 1 | ms-166 | Conversation Persistence & Context | done | — | #224–#231 | 2026-03-21 | 2026-03-21 |
|
|
||||||
| 2 | ms-167 | Security & Isolation | done | — | #232–#239 | 2026-03-21 | 2026-03-21 |
|
|
||||||
| 3 | ms-168 | Provider Integration | done | — | #240–#251 | 2026-03-21 | 2026-03-22 |
|
|
||||||
| 4 | ms-169 | Agent Routing Engine | done | — | #252–#264 | 2026-03-22 | 2026-03-22 |
|
|
||||||
| 5 | ms-170 | Agent Session Hardening | done | — | #265–#272 | 2026-03-22 | 2026-03-22 |
|
|
||||||
| 6 | ms-171 | Job Queue Foundation | done | — | #273–#280 | 2026-03-22 | 2026-03-22 |
|
|
||||||
| 7 | ms-172 | Channel Protocol Design | done | — | #281–#288 | 2026-03-22 | 2026-03-22 |
|
|
||||||
|
|
||||||
## Deployment
|
| # | ID | Name | Status | Manifest | Notes |
|
||||||
|
| --- | --- | ------------------------------------------- | ----------------- | ----------------------------------------------------------------------- | --------------------------------------------------- |
|
||||||
|
| W1 | FED | Federation v1 | planning-complete | [docs/federation/MISSION-MANIFEST.md](./federation/MISSION-MANIFEST.md) | 7 milestones, ~175K tokens, issues #460–#466 filed |
|
||||||
|
| W2+ | TBD | (additional workstreams declared as scoped) | — | — | Scope creep is expected and explicitly accommodated |
|
||||||
|
|
||||||
| Target | URL | Method |
|
### Likely Additional Workstreams (Not Yet Declared)
|
||||||
| -------------------- | --------- | -------------------------- |
|
|
||||||
| Docker Compose (dev) | localhost | docker compose up |
|
|
||||||
| Production | TBD | Docker Swarm via Portainer |
|
|
||||||
|
|
||||||
## Coordination
|
These are anticipated based on the PRD `In Scope` list but are NOT counted toward MVP completion until they have their own manifest, milestones, and tracking issues. Listed here so the orchestrator knows what's likely coming.
|
||||||
|
|
||||||
- **Primary Agent:** claude-opus-4-6
|
- Web dashboard parity with PRD scope (chat, tasks, projects, missions, agent status surfaces)
|
||||||
- **Sibling Agents:** sonnet (workers), haiku (verification)
|
- Pi TUI integration for terminal-native agent work
|
||||||
- **Shared Contracts:** docs/PRD-Harness_Foundation.md, docs/TASKS.md
|
- CLI completeness for headless / scripted workflows that mirror webUI capability
|
||||||
|
- Remote control plugins (Discord priority, then Telegram)
|
||||||
|
- Multi-user / SSO finishing (BetterAuth + Authentik/WorkOS/Keycloak adapters per PRD)
|
||||||
|
- LLM provider expansion (Anthropic, Codex, Z.ai, Ollama, LM Studio, llama.cpp) + routing matrix
|
||||||
|
- MCP server/client capability + skill import interface
|
||||||
|
- Brain (`@mosaicstack/brain`) as the structured data layer on PG + vector
|
||||||
|
|
||||||
## Token Budget
|
When any of these solidify into a real workstream, add a row to the Workstreams table, create a workstream-level manifest under `docs/{workstream}/MISSION-MANIFEST.md`, and file tracking issues.
|
||||||
|
|
||||||
| Metric | Value |
|
## Risks
|
||||||
| ------ | ------ |
|
|
||||||
| Budget | — |
|
- **Scope creep is the named risk.** Workstreams will be added; the rule is that each must have its own manifest + milestones + acceptance criteria before it consumes execution capacity.
|
||||||
| Used | ~2.5M |
|
- **Federation urgency vs. surface parity** — federation is being built first because it unblocks the user, but webUI/TUI/CLI parity (MVP-X1) cannot slip indefinitely. Track surface coverage explicitly when each workstream lands.
|
||||||
| Mode | normal |
|
- **Three-surface fan-out** — the same capability exposed three ways multiplies test surface and design effort. Default to a shared API/contract layer, then thin surface adapters; resist surface-specific business logic.
|
||||||
|
- **Federated-tier dependency** — MVP requires PG + pgvector + Valkey; users on local/standalone tier cannot federate. This is intentional but must be communicated clearly in the wizard.
|
||||||
|
|
||||||
|
## Out of Scope (MVP)
|
||||||
|
|
||||||
|
- SaaS / multi-tenant revenue model — personal/family/team tool only
|
||||||
|
- Mobile native apps — responsive web only
|
||||||
|
- Public npm registry publishing — Gitea registry only
|
||||||
|
- Voice / video agent interaction
|
||||||
|
- Full OpenClaw feature parity — inspiration only
|
||||||
|
- Calendar / GLPI / Woodpecker tooling integrations (deferred to post-MVP)
|
||||||
|
|
||||||
## Session History
|
## Session History
|
||||||
|
|
||||||
| Session | Runtime | Started | Duration | Ended Reason | Last Task |
|
For sessions 1–14 (phase-based execution, 2026-03-13 → 2026-03-15), see [scratchpads/mvp-20260312.md](./scratchpads/mvp-20260312.md). Sessions below are tracked at the rollup level.
|
||||||
| ------- | --------------- | ---------- | -------- | ------------ | ----------------- |
|
|
||||||
| 1 | claude-opus-4-6 | 2026-03-21 | ~6h | complete | M7-008 — all done |
|
|
||||||
|
|
||||||
## Scratchpad
|
| Session | Date | Runtime | Outcome |
|
||||||
|
| ------- | ---------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
|
| S15 | 2026-04-19 | claude | MVP rollup manifest authored. Install-ux-v2 archived (IUV-M03 retroactively closed — shipped via PR #446 + releases 0.0.27 → 0.0.29). Federation v1 planning landed via PR #468. W1 manifest reachable at `docs/federation/MISSION-MANIFEST.md`. Next: kickoff FED-M1. |
|
||||||
|
|
||||||
Path: `docs/scratchpads/harness-20260321.md`
|
## Next Step
|
||||||
|
|
||||||
|
Begin W1 / FED-M1 — federated tier infrastructure. Task breakdown lives at [docs/federation/TASKS.md](./federation/TASKS.md).
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ for any `<Image>` components added in the future.
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Run the DB migration (requires a live DB)
|
# Run the DB migration (requires a live DB)
|
||||||
pnpm --filter @mosaic/db exec drizzle-kit migrate
|
pnpm --filter @mosaicstack/db exec drizzle-kit migrate
|
||||||
|
|
||||||
# Or, in Docker/Swarm — migrations run automatically on gateway startup
|
# Or, in Docker/Swarm — migrations run automatically on gateway startup
|
||||||
# via runMigrations() in packages/db/src/migrate.ts
|
# via runMigrations() in packages/db/src/migrate.ts
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ Multi-panel layout with keyboard navigation.
|
|||||||
|
|
||||||
- **Ink 5** (React for CLI) — already in deps
|
- **Ink 5** (React for CLI) — already in deps
|
||||||
- **Component architecture** — break monolithic `app.tsx` into composable components
|
- **Component architecture** — break monolithic `app.tsx` into composable components
|
||||||
- **Typed Socket.IO events** — leverage `@mosaic/types` `ServerToClientEvents` / `ClientToServerEvents`
|
- **Typed Socket.IO events** — leverage `@mosaicstack/types` `ServerToClientEvents` / `ClientToServerEvents`
|
||||||
- **Local state only** (Wave 1) — cwd/branch read from `process.cwd()` and `git` at startup
|
- **Local state only** (Wave 1) — cwd/branch read from `process.cwd()` and `git` at startup
|
||||||
- **Gateway metadata** (future) — extend socket handshake or add REST endpoint for model info, token usage
|
- **Gateway metadata** (future) — extend socket handshake or add REST endpoint for model info, token usage
|
||||||
|
|
||||||
|
|||||||
164
docs/PRD.md
164
docs/PRD.md
@@ -8,7 +8,7 @@
|
|||||||
- **Best-Guess Mode:** true
|
- **Best-Guess Mode:** true
|
||||||
- Repo (target): `git.mosaicstack.dev/mosaic/mosaic-stack`
|
- Repo (target): `git.mosaicstack.dev/mosaic/mosaic-stack`
|
||||||
- Baseline: `~/src/jarvis-old` (jarvis v0.2.0)
|
- Baseline: `~/src/jarvis-old` (jarvis v0.2.0)
|
||||||
- Package source: `~/src/mosaic-mono-v0` (@mosaic/\* packages)
|
- Package source: `~/src/mosaic-mono-v0` (@mosaicstack/\* packages)
|
||||||
- Agent harness: [pi](https://github.com/badlogic/pi-mono) (v0.57.1)
|
- Agent harness: [pi](https://github.com/badlogic/pi-mono) (v0.57.1)
|
||||||
- Remote control reference: [OpenClaw](https://github.com/openclaw/openclaw) (upstream, canonical)
|
- Remote control reference: [OpenClaw](https://github.com/openclaw/openclaw) (upstream, canonical)
|
||||||
|
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
## Problem Statement
|
## Problem Statement
|
||||||
|
|
||||||
Jarvis (v0.2.0) is a self-hosted AI assistant with a Python FastAPI backend and Next.js frontend. It handles chat, projects, tasks, and LLM routing but lacks orchestration depth, agent coordination, shared memory, and remote access. The Mosaic framework (`~/.config/mosaic`) provides agent guides, shell-based orchestration tools, and quality rails — but these are loose scripts, not an integrated platform. The `@mosaic/*` packages in mosaic-mono-v0 began consolidating these into TypeScript packages (brain, queue, coord, cli, prdy, quality-rails) but have no UI, no auth, and no agent runtime integration.
|
Jarvis (v0.2.0) is a self-hosted AI assistant with a Python FastAPI backend and Next.js frontend. It handles chat, projects, tasks, and LLM routing but lacks orchestration depth, agent coordination, shared memory, and remote access. The Mosaic framework (`~/.config/mosaic`) provides agent guides, shell-based orchestration tools, and quality rails — but these are loose scripts, not an integrated platform. The `@mosaicstack/*` packages in mosaic-mono-v0 began consolidating these into TypeScript packages (brain, queue, coord, cli, prdy, quality-rails) but have no UI, no auth, and no agent runtime integration.
|
||||||
|
|
||||||
**The gap:** Three codebases with overlapping concerns, no unified runtime, no remote control surface (Discord/Telegram), no gateway orchestrator, and a Python backend that doesn't align with the target TypeScript-everywhere stack.
|
**The gap:** Three codebases with overlapping concerns, no unified runtime, no remote control surface (Discord/Telegram), no gateway orchestrator, and a Python backend that doesn't align with the target TypeScript-everywhere stack.
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ Jarvis (v0.2.0) is a self-hosted AI assistant with a Python FastAPI backend and
|
|||||||
4. **Gateway orchestrator** — Central routing layer that dispatches tasks to appropriate agents based on capability, cost, and context
|
4. **Gateway orchestrator** — Central routing layer that dispatches tasks to appropriate agents based on capability, cost, and context
|
||||||
5. **Shared memory** — PostgreSQL canonical store + vector DB for semantic search + tiered log summarization to prevent context creep
|
5. **Shared memory** — PostgreSQL canonical store + vector DB for semantic search + tiered log summarization to prevent context creep
|
||||||
6. **Multi-user with SSO** — BetterAuth with Authentik/WorkOS/Keycloak SSO, RBAC for family/team/business use
|
6. **Multi-user with SSO** — BetterAuth with Authentik/WorkOS/Keycloak SSO, RBAC for family/team/business use
|
||||||
7. **Full @mosaic/\* package integration** — brain, queue, coord, mosaic, prdy, quality-rails, cli all integrated
|
7. **Full @mosaicstack/\* package integration** — brain, queue, coord, mosaic, prdy, quality-rails, cli all integrated
|
||||||
8. **Extensible** — MCP capability, skill import interface, plugin architecture for LLM providers and remote channels
|
8. **Extensible** — MCP capability, skill import interface, plugin architecture for LLM providers and remote channels
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -44,7 +44,7 @@ Jarvis (v0.2.0) is a self-hosted AI assistant with a Python FastAPI backend and
|
|||||||
1. Chat/conversation UI (web) — carry forward from jarvis-old, rewrite frontend to work with new backend
|
1. Chat/conversation UI (web) — carry forward from jarvis-old, rewrite frontend to work with new backend
|
||||||
2. Pi TUI integration — terminal-based agent interaction using Pi SDK
|
2. Pi TUI integration — terminal-based agent interaction using Pi SDK
|
||||||
3. Web dashboard — settings, task management, projects, PRDs, missions, agent status
|
3. Web dashboard — settings, task management, projects, PRDs, missions, agent status
|
||||||
4. Gateway orchestrator (`@mosaic/gateway`) — central dispatch for agent tasks with routing logic
|
4. Gateway orchestrator (`@mosaicstack/gateway`) — central dispatch for agent tasks with routing logic
|
||||||
5. Task management — CRUD, kanban, mission-scoped tasks, dependency tracking
|
5. Task management — CRUD, kanban, mission-scoped tasks, dependency tracking
|
||||||
6. Project management — projects, milestones, PRDs linked to missions
|
6. Project management — projects, milestones, PRDs linked to missions
|
||||||
7. Shared memory system — learned preferences, behaviors, defaults; tiered storage with summarization
|
7. Shared memory system — learned preferences, behaviors, defaults; tiered storage with summarization
|
||||||
@@ -55,13 +55,13 @@ Jarvis (v0.2.0) is a self-hosted AI assistant with a Python FastAPI backend and
|
|||||||
12. Agent routing — task-based model/provider selection (cost/capability matrix)
|
12. Agent routing — task-based model/provider selection (cost/capability matrix)
|
||||||
13. MCP capability — server and client, tool registration
|
13. MCP capability — server and client, tool registration
|
||||||
14. Skill import interface — browse, install, manage agent skills
|
14. Skill import interface — browse, install, manage agent skills
|
||||||
15. `@mosaic/brain` — structured data layer (migrated to PG + vector DB backend)
|
15. `@mosaicstack/brain` — structured data layer (migrated to PG + vector DB backend)
|
||||||
16. `@mosaic/queue` — Valkey-backed task queue with MCP tools
|
16. `@mosaicstack/queue` — Valkey-backed task queue with MCP tools
|
||||||
17. `@mosaic/coord` — mission coordination engine
|
17. `@mosaicstack/coord` — mission coordination engine
|
||||||
18. `@mosaic/mosaic` — install wizard / bootstrap
|
18. `@mosaicstack/mosaic` — install wizard / bootstrap
|
||||||
19. `@mosaic/prdy` — PRD wizard
|
19. `@mosaicstack/prdy` — PRD wizard
|
||||||
20. `@mosaic/quality-rails` — code quality scaffolder
|
20. `@mosaicstack/quality-rails` — code quality scaffolder
|
||||||
21. `@mosaic/cli` — unified `mosaic` CLI
|
21. `@mosaicstack/cli` — unified `mosaic` CLI
|
||||||
22. Docker Compose deployment + bare-metal capability
|
22. Docker Compose deployment + bare-metal capability
|
||||||
23. Agent log service — ingest, parse, tier, summarize agent interaction logs
|
23. Agent log service — ingest, parse, tier, summarize agent interaction logs
|
||||||
|
|
||||||
@@ -94,14 +94,14 @@ Jarvis (v0.2.0) is a self-hosted AI assistant with a Python FastAPI backend and
|
|||||||
│ └──────────────┴───────┬───────┴────────────────┘ │
|
│ └──────────────┴───────┬───────┴────────────────┘ │
|
||||||
│ │ │
|
│ │ │
|
||||||
│ ┌─────────▼──────────┐ │
|
│ ┌─────────▼──────────┐ │
|
||||||
│ │ @mosaic/gateway │ ← Central Orchestrator│
|
│ │ @mosaicstack/gateway │ ← Central Orchestrator│
|
||||||
│ │ (NestJS+Fastify) │ │
|
│ │ (NestJS+Fastify) │ │
|
||||||
│ └────┬────┬────┬─────┘ │
|
│ └────┬────┬────┬─────┘ │
|
||||||
│ │ │ │ │
|
│ │ │ │ │
|
||||||
│ ┌──────────────┤ │ ├──────────────┐ │
|
│ ┌──────────────┤ │ ├──────────────┐ │
|
||||||
│ │ │ │ │ │ │
|
│ │ │ │ │ │ │
|
||||||
│ ┌───────▼──────┐ ┌────▼────▼──┐ │ ┌───────────▼────────┐ │
|
│ ┌───────▼──────┐ ┌────▼────▼──┐ │ ┌───────────▼────────┐ │
|
||||||
│ │ @mosaic/brain│ │ @mosaic/ │ │ │ Agent Pool │ │
|
│ │ @mosaicstack/brain│ │ @mosaicstack/ │ │ │ Agent Pool │ │
|
||||||
│ │ (Data Layer) │ │ queue │ │ │ (Pi SDK sessions) │ │
|
│ │ (Data Layer) │ │ queue │ │ │ (Pi SDK sessions) │ │
|
||||||
│ └───────┬──────┘ └────────────┘ │ │ - Anthropic │ │
|
│ └───────┬──────┘ └────────────┘ │ │ - Anthropic │ │
|
||||||
│ │ │ │ - Codex │ │
|
│ │ │ │ - Codex │ │
|
||||||
@@ -111,12 +111,12 @@ Jarvis (v0.2.0) is a self-hosted AI assistant with a Python FastAPI backend and
|
|||||||
│ └──────────────┴───────────┘ │ │ - llama.cpp │ │
|
│ └──────────────┴───────────┘ │ │ - llama.cpp │ │
|
||||||
│ │ └────────────────────┘ │
|
│ │ └────────────────────┘ │
|
||||||
│ ┌─────────────▼──────┐ │
|
│ ┌─────────────▼──────┐ │
|
||||||
│ │ @mosaic/coord │ │
|
│ │ @mosaicstack/coord │ │
|
||||||
│ │ Mission lifecycle │ │
|
│ │ Mission lifecycle │ │
|
||||||
│ └────────────────────┘ │
|
│ └────────────────────┘ │
|
||||||
│ │
|
│ │
|
||||||
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────────┐ │
|
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────────┐ │
|
||||||
│ │ @mosaic/cli │ │ @mosaic/prdy │ │ @mosaic/ │ │
|
│ │ @mosaicstack/cli │ │ @mosaicstack/prdy │ │ @mosaicstack/ │ │
|
||||||
│ │ │ │ │ │ quality-rails │ │
|
│ │ │ │ │ │ quality-rails │ │
|
||||||
│ └──────────────┘ └──────────────┘ └──────────────────┘ │
|
│ └──────────────┘ └──────────────┘ └──────────────────┘ │
|
||||||
│ │
|
│ │
|
||||||
@@ -130,20 +130,20 @@ Jarvis (v0.2.0) is a self-hosted AI assistant with a Python FastAPI backend and
|
|||||||
|
|
||||||
| Layer | Technology | Rationale |
|
| Layer | Technology | Rationale |
|
||||||
| ------------------ | ------------------------------------ | ----------------------------------------------------------------------------------------------------------- |
|
| ------------------ | ------------------------------------ | ----------------------------------------------------------------------------------------------------------- |
|
||||||
| **Web Frontend** | Next.js 16 + React 19 + Tailwind CSS | SSR, RSC; design tokens from @mosaic/design-tokens (mosaic-stack-website) |
|
| **Web Frontend** | Next.js 16 + React 19 + Tailwind CSS | SSR, RSC; design tokens from @mosaicstack/design-tokens (mosaic-stack-website) |
|
||||||
| **API / Gateway** | NestJS + Fastify adapter | Module system, DI, guards/interceptors for complex gateway; Fastify performance underneath |
|
| **API / Gateway** | NestJS + Fastify adapter | Module system, DI, guards/interceptors for complex gateway; Fastify performance underneath |
|
||||||
| **Agent Runtime** | Pi SDK (embedded) | Extensible harness with tools, skills, session management |
|
| **Agent Runtime** | Pi SDK (embedded) | Extensible harness with tools, skills, session management |
|
||||||
| **TUI** | Pi interactive mode | Native terminal agent interaction |
|
| **TUI** | Pi interactive mode | Native terminal agent interaction |
|
||||||
| **Auth** | BetterAuth + SSO adapters | Multi-user RBAC with Authentik/WorkOS/Keycloak |
|
| **Auth** | BetterAuth + SSO adapters | Multi-user RBAC with Authentik/WorkOS/Keycloak |
|
||||||
| **Database** | PostgreSQL 17 + pgvector | Canonical store; pgvector for embedding search |
|
| **Database** | PostgreSQL 17 + pgvector | Canonical store; pgvector for embedding search |
|
||||||
| **Vector DB** | pgvector + VectorStore interface | pgvector for v0.1.0; `VectorStore` abstraction in @mosaic/memory makes Qdrant a drop-in later |
|
| **Vector DB** | pgvector + VectorStore interface | pgvector for v0.1.0; `VectorStore` abstraction in @mosaicstack/memory makes Qdrant a drop-in later |
|
||||||
| **Cache / Queue** | Valkey 8 | Redis-compatible; proven in @mosaic/queue |
|
| **Cache / Queue** | Valkey 8 | Redis-compatible; proven in @mosaicstack/queue |
|
||||||
| **ORM** | Drizzle ORM | TypeScript-native, lightweight, good migration story |
|
| **ORM** | Drizzle ORM | TypeScript-native, lightweight, good migration story |
|
||||||
| **Validation** | Zod | Already used across @mosaic/\* packages |
|
| **Validation** | Zod | Already used across @mosaicstack/\* packages |
|
||||||
| **Build** | pnpm workspaces + Turborepo | Proven in both jarvis-old and mosaic-mono-v0 |
|
| **Build** | pnpm workspaces + Turborepo | Proven in both jarvis-old and mosaic-mono-v0 |
|
||||||
| **Testing** | Vitest + Playwright | Unit/integration via Vitest, E2E via Playwright |
|
| **Testing** | Vitest + Playwright | Unit/integration via Vitest, E2E via Playwright |
|
||||||
| **Remote Control** | Discord.js + Telegraf | Inspired by OpenClaw plugin architecture |
|
| **Remote Control** | Discord.js + Telegraf | Inspired by OpenClaw plugin architecture |
|
||||||
| **MCP** | @modelcontextprotocol/sdk | Already used in @mosaic/brain and @mosaic/queue |
|
| **MCP** | @modelcontextprotocol/sdk | Already used in @mosaicstack/brain and @mosaicstack/queue |
|
||||||
| **Container** | Docker Compose | Self-hosted; bare-metal also supported |
|
| **Container** | Docker Compose | Self-hosted; bare-metal also supported |
|
||||||
| **CI** | Woodpecker CI | Existing infrastructure at git.mosaicstack.dev |
|
| **CI** | Woodpecker CI | Existing infrastructure at git.mosaicstack.dev |
|
||||||
| **Observability** | OpenTelemetry + SigNoz | Wide-event logging from day one; OTEL auto-instrumentation for NestJS/PG/HTTP; SigNoz as all-in-one backend |
|
| **Observability** | OpenTelemetry + SigNoz | Wide-event logging from day one; OTEL auto-instrumentation for NestJS/PG/HTTP; SigNoz as all-in-one backend |
|
||||||
@@ -158,12 +158,12 @@ The jarvis-old FastAPI backend is not carried forward as code. Its domain logic
|
|||||||
Instead of a custom LLM provider abstraction (jarvis-old's `BaseLLMProvider`), Pi SDK manages agent sessions. Pi handles model selection, tool calling, context management, and compaction. The gateway dispatches work to Pi sessions configured with appropriate providers.
|
Instead of a custom LLM provider abstraction (jarvis-old's `BaseLLMProvider`), Pi SDK manages agent sessions. Pi handles model selection, tool calling, context management, and compaction. The gateway dispatches work to Pi sessions configured with appropriate providers.
|
||||||
|
|
||||||
**AD-3: Gateway as the central nervous system (NestJS + Fastify adapter)**
|
**AD-3: Gateway as the central nervous system (NestJS + Fastify adapter)**
|
||||||
`@mosaic/gateway` is the single API surface. The web app, TUI, Discord, and Telegram all talk to the gateway. The gateway routes to brain (data), queue (coordination), agent pool (LLM work), and coord (mission lifecycle). This replaces the direct FastAPI-to-DB pattern from jarvis-old.
|
`@mosaicstack/gateway` is the single API surface. The web app, TUI, Discord, and Telegram all talk to the gateway. The gateway routes to brain (data), queue (coordination), agent pool (LLM work), and coord (mission lifecycle). This replaces the direct FastAPI-to-DB pattern from jarvis-old.
|
||||||
|
|
||||||
NestJS was chosen over raw Fastify because the gateway is inherently complex — it hosts channel plugins, agent pool management, routing engine, WebSocket hub, MCP server, auth middleware, and integrates brain, queue, memory, and log services. NestJS provides the module system, dependency injection, guards, and interceptors needed to organize this cleanly. NestJS uses Fastify as its HTTP adapter, so Fastify's performance is preserved. This also aligns with the stated stack preference in USER.md ("NestJS API + Next.js web"). @mosaic/brain's existing Fastify code migrates naturally into a NestJS module with Fastify adapter.
|
NestJS was chosen over raw Fastify because the gateway is inherently complex — it hosts channel plugins, agent pool management, routing engine, WebSocket hub, MCP server, auth middleware, and integrates brain, queue, memory, and log services. NestJS provides the module system, dependency injection, guards, and interceptors needed to organize this cleanly. NestJS uses Fastify as its HTTP adapter, so Fastify's performance is preserved. This also aligns with the stated stack preference in USER.md ("NestJS API + Next.js web"). @mosaicstack/brain's existing Fastify code migrates naturally into a NestJS module with Fastify adapter.
|
||||||
|
|
||||||
**AD-4: Brain migrates from JSON files to PostgreSQL**
|
**AD-4: Brain migrates from JSON files to PostgreSQL**
|
||||||
`@mosaic/brain` currently uses a JSON file store. For Mosaic Stack, brain's data model (tasks, projects, events, agents, missions, tickets) moves to PostgreSQL via Drizzle ORM. Brain's REST + MCP interface is preserved — only the storage backend changes.
|
`@mosaicstack/brain` currently uses a JSON file store. For Mosaic Stack, brain's data model (tasks, projects, events, agents, missions, tickets) moves to PostgreSQL via Drizzle ORM. Brain's REST + MCP interface is preserved — only the storage backend changes.
|
||||||
|
|
||||||
**AD-5: Tiered memory with summarization**
|
**AD-5: Tiered memory with summarization**
|
||||||
Agent interaction logs are ingested into a log service. Raw logs are stored short-term. A summarization pipeline (using a cheap LLM) periodically compresses logs into structured insights stored in the vector DB. This prevents unbounded log growth while preserving searchable context.
|
Agent interaction logs are ingested into a log service. Raw logs are stored short-term. A summarization pipeline (using a cheap LLM) periodically compresses logs into structured insights stored in the vector DB. This prevents unbounded log growth while preserving searchable context.
|
||||||
@@ -189,8 +189,8 @@ The gateway includes a cron scheduler for recurring tasks: log summarization run
|
|||||||
**AD-12: Web search tool (DuckDuckGo MCP)**
|
**AD-12: Web search tool (DuckDuckGo MCP)**
|
||||||
Agent sessions include a web search tool for information retrieval. DuckDuckGo via MCP server is the primary option (privacy-respecting, no API key required). Falls back to other search MCP providers if configured. Registered as a standard MCP tool available to all agent sessions.
|
Agent sessions include a web search tool for information retrieval. DuckDuckGo via MCP server is the primary option (privacy-respecting, no API key required). Falls back to other search MCP providers if configured. Registered as a standard MCP tool available to all agent sessions.
|
||||||
|
|
||||||
**AD-13: Design system from @mosaic/design-tokens**
|
**AD-13: Design system from @mosaicstack/design-tokens**
|
||||||
The web dashboard uses the Mosaic Stack design system established in `mosaic-stack-website`. The `@mosaic/design-tokens` package provides CSS custom properties, Tailwind preset, and TS color/font/radius exports. Dark theme default with light theme support. Fonts: Outfit (sans), Fira Code (mono). Color palette: deep blue-grays with blue/purple/teal accents.
|
The web dashboard uses the Mosaic Stack design system established in `mosaic-stack-website`. The `@mosaicstack/design-tokens` package provides CSS custom properties, Tailwind preset, and TS color/font/radius exports. Dark theme default with light theme support. Fonts: Outfit (sans), Fira Code (mono). Color palette: deep blue-grays with blue/purple/teal accents.
|
||||||
|
|
||||||
**AD-14: Multi-tier deployment readiness**
|
**AD-14: Multi-tier deployment readiness**
|
||||||
Code is structured assuming eventual multi-node deployment with dedicated roles (gateway nodes, agent worker nodes, brain/DB nodes). Packages communicate via well-defined APIs (HTTP/WS/MCP), not in-process calls where avoidable. Service boundaries are clean: gateway is stateless (state in PG/Valkey), agent pool can scale independently, brain is a separate service. v0.1.0 runs single-node; the architecture doesn't fight horizontal scaling later.
|
Code is structured assuming eventual multi-node deployment with dedicated roles (gateway nodes, agent worker nodes, brain/DB nodes). Packages communicate via well-defined APIs (HTTP/WS/MCP), not in-process calls where avoidable. Service boundaries are clean: gateway is stateless (state in PG/Valkey), agent pool can scale independently, brain is a separate service. v0.1.0 runs single-node; the architecture doesn't fight horizontal scaling later.
|
||||||
@@ -205,25 +205,25 @@ Code is structured assuming eventual multi-node deployment with dedicated roles
|
|||||||
mosaic-mono-v1/
|
mosaic-mono-v1/
|
||||||
├── apps/
|
├── apps/
|
||||||
│ ├── web/ Next.js 16 web dashboard
|
│ ├── web/ Next.js 16 web dashboard
|
||||||
│ └── gateway/ @mosaic/gateway — NestJS API + WebSocket
|
│ └── gateway/ @mosaicstack/gateway — NestJS API + WebSocket
|
||||||
├── packages/
|
├── packages/
|
||||||
│ ├── types/ @mosaic/types — shared type contracts
|
│ ├── types/ @mosaicstack/types — shared type contracts
|
||||||
│ ├── brain/ @mosaic/brain — data layer (PG-backed)
|
│ ├── brain/ @mosaicstack/brain — data layer (PG-backed)
|
||||||
│ ├── queue/ @mosaic/queue — Valkey task queue + MCP
|
│ ├── queue/ @mosaicstack/queue — Valkey task queue + MCP
|
||||||
│ ├── coord/ @mosaic/coord — mission coordination
|
│ ├── coord/ @mosaicstack/coord — mission coordination
|
||||||
│ ├── mosaic/ @mosaic/mosaic — install wizard
|
│ ├── mosaic/ @mosaicstack/mosaic — install wizard
|
||||||
│ ├── prdy/ @mosaic/prdy — PRD wizard
|
│ ├── prdy/ @mosaicstack/prdy — PRD wizard
|
||||||
│ ├── quality-rails/ @mosaic/quality-rails — code quality scaffolder
|
│ ├── quality-rails/ @mosaicstack/quality-rails — code quality scaffolder
|
||||||
│ ├── cli/ @mosaic/cli — unified CLI
|
│ ├── cli/ @mosaicstack/cli — unified CLI
|
||||||
│ ├── auth/ @mosaic/auth — BetterAuth config + SSO adapters
|
│ ├── auth/ @mosaicstack/auth — BetterAuth config + SSO adapters
|
||||||
│ ├── db/ @mosaic/db — Drizzle schema, migrations, connection
|
│ ├── db/ @mosaicstack/db — Drizzle schema, migrations, connection
|
||||||
│ ├── agent/ @mosaic/agent — Pi SDK integration, agent pool manager
|
│ ├── agent/ @mosaicstack/agent — Pi SDK integration, agent pool manager
|
||||||
│ ├── memory/ @mosaic/memory — tiered memory + summarization service
|
│ ├── memory/ @mosaicstack/memory — tiered memory + summarization service
|
||||||
│ ├── log/ @mosaic/log — agent log ingest + processing
|
│ ├── log/ @mosaicstack/log — agent log ingest + processing
|
||||||
│ └── design-tokens/ @mosaic/design-tokens — CSS vars, Tailwind preset, colors
|
│ └── design-tokens/ @mosaicstack/design-tokens — CSS vars, Tailwind preset, colors
|
||||||
├── plugins/
|
├── plugins/
|
||||||
│ ├── discord/ @mosaic/discord-plugin — Discord channel
|
│ ├── discord/ @mosaicstack/discord-plugin — Discord channel
|
||||||
│ └── telegram/ @mosaic/telegram-plugin — Telegram channel
|
│ └── telegram/ @mosaicstack/telegram-plugin — Telegram channel
|
||||||
├── docker/
|
├── docker/
|
||||||
│ ├── gateway.Dockerfile
|
│ ├── gateway.Dockerfile
|
||||||
│ ├── web.Dockerfile
|
│ ├── web.Dockerfile
|
||||||
@@ -244,7 +244,7 @@ mosaic-mono-v1/
|
|||||||
|
|
||||||
### Package Responsibilities
|
### Package Responsibilities
|
||||||
|
|
||||||
#### `apps/gateway` — @mosaic/gateway (NEW — critical path)
|
#### `apps/gateway` — @mosaicstack/gateway (NEW — critical path)
|
||||||
|
|
||||||
The central nervous system. All clients connect here. Built with NestJS (Fastify adapter).
|
The central nervous system. All clients connect here. Built with NestJS (Fastify adapter).
|
||||||
|
|
||||||
@@ -303,7 +303,7 @@ Carried forward from jarvis-old with significant refactoring.
|
|||||||
- User management (admin RBAC panel)
|
- User management (admin RBAC panel)
|
||||||
- Auth pages (login, SSO redirect, registration)
|
- Auth pages (login, SSO redirect, registration)
|
||||||
|
|
||||||
#### `packages/types` — @mosaic/types
|
#### `packages/types` — @mosaicstack/types
|
||||||
|
|
||||||
Migrated from mosaic-mono-v0. Extended with:
|
Migrated from mosaic-mono-v0. Extended with:
|
||||||
|
|
||||||
@@ -313,7 +313,7 @@ Migrated from mosaic-mono-v0. Extended with:
|
|||||||
- Memory types (preference, insight, summary)
|
- Memory types (preference, insight, summary)
|
||||||
- Plugin channel types (Discord, Telegram message mapping)
|
- Plugin channel types (Discord, Telegram message mapping)
|
||||||
|
|
||||||
#### `packages/brain` — @mosaic/brain
|
#### `packages/brain` — @mosaicstack/brain
|
||||||
|
|
||||||
Migrated from mosaic-mono-v0. **Storage backend changes from JSON to PostgreSQL.**
|
Migrated from mosaic-mono-v0. **Storage backend changes from JSON to PostgreSQL.**
|
||||||
|
|
||||||
@@ -324,7 +324,7 @@ Migrated from mosaic-mono-v0. **Storage backend changes from JSON to PostgreSQL.
|
|||||||
- New: computed endpoints (today, stale, stats, search, audit) run against PG
|
- New: computed endpoints (today, stale, stats, search, audit) run against PG
|
||||||
- New: appreciation collection preserved for family use
|
- New: appreciation collection preserved for family use
|
||||||
|
|
||||||
#### `packages/queue` — @mosaic/queue
|
#### `packages/queue` — @mosaicstack/queue
|
||||||
|
|
||||||
Migrated from mosaic-mono-v0 with minimal changes.
|
Migrated from mosaic-mono-v0 with minimal changes.
|
||||||
|
|
||||||
@@ -332,7 +332,7 @@ Migrated from mosaic-mono-v0 with minimal changes.
|
|||||||
- MCP server with 8 tools
|
- MCP server with 8 tools
|
||||||
- Used by gateway for agent task dispatch and coordination
|
- Used by gateway for agent task dispatch and coordination
|
||||||
|
|
||||||
#### `packages/coord` — @mosaic/coord
|
#### `packages/coord` — @mosaicstack/coord
|
||||||
|
|
||||||
Migrated from mosaic-mono-v0.
|
Migrated from mosaic-mono-v0.
|
||||||
|
|
||||||
@@ -342,7 +342,7 @@ Migrated from mosaic-mono-v0.
|
|||||||
- Continuation prompt generation
|
- Continuation prompt generation
|
||||||
- Integration with gateway for mission-driven orchestration
|
- Integration with gateway for mission-driven orchestration
|
||||||
|
|
||||||
#### `packages/db` — @mosaic/db (NEW)
|
#### `packages/db` — @mosaicstack/db (NEW)
|
||||||
|
|
||||||
Shared database package.
|
Shared database package.
|
||||||
|
|
||||||
@@ -351,7 +351,7 @@ Shared database package.
|
|||||||
- Connection pool configuration
|
- Connection pool configuration
|
||||||
- Shared by gateway, brain, auth, memory
|
- Shared by gateway, brain, auth, memory
|
||||||
|
|
||||||
#### `packages/auth` — @mosaic/auth (NEW)
|
#### `packages/auth` — @mosaicstack/auth (NEW)
|
||||||
|
|
||||||
Authentication and authorization.
|
Authentication and authorization.
|
||||||
|
|
||||||
@@ -361,7 +361,7 @@ Authentication and authorization.
|
|||||||
- API key generation for brain/MCP access
|
- API key generation for brain/MCP access
|
||||||
- Session management middleware
|
- Session management middleware
|
||||||
|
|
||||||
#### `packages/agent` — @mosaic/agent (NEW — critical path)
|
#### `packages/agent` — @mosaicstack/agent (NEW — critical path)
|
||||||
|
|
||||||
Pi SDK integration layer.
|
Pi SDK integration layer.
|
||||||
|
|
||||||
@@ -372,7 +372,7 @@ Pi SDK integration layer.
|
|||||||
- Skill management — loads and configures Pi skills for agent sessions
|
- Skill management — loads and configures Pi skills for agent sessions
|
||||||
- Session lifecycle — create, monitor, complete, fail, timeout
|
- Session lifecycle — create, monitor, complete, fail, timeout
|
||||||
|
|
||||||
#### `packages/memory` — @mosaic/memory (NEW)
|
#### `packages/memory` — @mosaicstack/memory (NEW)
|
||||||
|
|
||||||
Tiered memory system.
|
Tiered memory system.
|
||||||
|
|
||||||
@@ -382,7 +382,7 @@ Tiered memory system.
|
|||||||
- Summarization pipeline — compress raw logs into structured insights
|
- Summarization pipeline — compress raw logs into structured insights
|
||||||
- Memory API — used by gateway and agent sessions
|
- Memory API — used by gateway and agent sessions
|
||||||
|
|
||||||
#### `packages/log` — @mosaic/log (NEW)
|
#### `packages/log` — @mosaicstack/log (NEW)
|
||||||
|
|
||||||
Agent log service.
|
Agent log service.
|
||||||
|
|
||||||
@@ -392,7 +392,7 @@ Agent log service.
|
|||||||
- Summarization trigger — invokes cheap LLM to compress aging logs
|
- Summarization trigger — invokes cheap LLM to compress aging logs
|
||||||
- Retention policy — configurable TTLs per tier
|
- Retention policy — configurable TTLs per tier
|
||||||
|
|
||||||
#### `packages/mosaic` — @mosaic/mosaic
|
#### `packages/mosaic` — @mosaicstack/mosaic
|
||||||
|
|
||||||
Migrated from mosaic-mono-v0, updated for v1.
|
Migrated from mosaic-mono-v0, updated for v1.
|
||||||
|
|
||||||
@@ -400,7 +400,7 @@ Migrated from mosaic-mono-v0, updated for v1.
|
|||||||
- Detects existing installations, offers upgrade path
|
- Detects existing installations, offers upgrade path
|
||||||
- Configures `~/.config/mosaic/` with guides, tools, runtime configs
|
- Configures `~/.config/mosaic/` with guides, tools, runtime configs
|
||||||
|
|
||||||
#### `packages/prdy` — @mosaic/prdy
|
#### `packages/prdy` — @mosaicstack/prdy
|
||||||
|
|
||||||
Migrated from mosaic-mono-v0.
|
Migrated from mosaic-mono-v0.
|
||||||
|
|
||||||
@@ -408,7 +408,7 @@ Migrated from mosaic-mono-v0.
|
|||||||
- Template-based PRD creation with Zod validation
|
- Template-based PRD creation with Zod validation
|
||||||
- CLI integration via `mosaic prdy`
|
- CLI integration via `mosaic prdy`
|
||||||
|
|
||||||
#### `packages/quality-rails` — @mosaic/quality-rails
|
#### `packages/quality-rails` — @mosaicstack/quality-rails
|
||||||
|
|
||||||
Migrated from mosaic-mono-v0.
|
Migrated from mosaic-mono-v0.
|
||||||
|
|
||||||
@@ -416,15 +416,15 @@ Migrated from mosaic-mono-v0.
|
|||||||
- Generates ESLint, tsconfig, Woodpecker, husky, lint-staged configs
|
- Generates ESLint, tsconfig, Woodpecker, husky, lint-staged configs
|
||||||
- Supports project types: monorepo, typescript-node, nextjs
|
- Supports project types: monorepo, typescript-node, nextjs
|
||||||
|
|
||||||
#### `packages/cli` — @mosaic/cli
|
#### `packages/cli` — @mosaicstack/cli
|
||||||
|
|
||||||
Migrated from mosaic-mono-v0, extended.
|
Migrated from mosaic-mono-v0, extended.
|
||||||
|
|
||||||
- Unified `mosaic` binary
|
- Unified `mosaic` binary
|
||||||
- Subcommands: `mosaic coord`, `mosaic prdy`, `mosaic queue`, `mosaic quality`, `mosaic gateway`, `mosaic brain`
|
- Subcommands: `mosaic coord`, `mosaic prdy`, `mosaic queue`, `mosaic quality`, `mosaic gateway`, `mosaic brain`
|
||||||
- Plugin discovery for installed @mosaic/\* packages
|
- Plugin discovery for installed @mosaicstack/\* packages
|
||||||
|
|
||||||
#### `plugins/discord` — @mosaic/discord-plugin (NEW — high priority)
|
#### `plugins/discord` — @mosaicstack/discord-plugin (NEW — high priority)
|
||||||
|
|
||||||
Discord remote control channel. Architecture inspired by OpenClaw (https://github.com/openclaw/openclaw).
|
Discord remote control channel. Architecture inspired by OpenClaw (https://github.com/openclaw/openclaw).
|
||||||
|
|
||||||
@@ -436,7 +436,7 @@ Discord remote control channel. Architecture inspired by OpenClaw (https://githu
|
|||||||
- Bot pairing and permission management (Discord user → Mosaic user mapping)
|
- Bot pairing and permission management (Discord user → Mosaic user mapping)
|
||||||
- DM support for private conversations
|
- DM support for private conversations
|
||||||
|
|
||||||
#### `plugins/telegram` — @mosaic/telegram-plugin (NEW)
|
#### `plugins/telegram` — @mosaicstack/telegram-plugin (NEW)
|
||||||
|
|
||||||
Telegram remote control channel.
|
Telegram remote control channel.
|
||||||
|
|
||||||
@@ -547,7 +547,7 @@ Telegram remote control channel.
|
|||||||
- WebSocket hub — real-time updates for chat, agent status, notifications
|
- WebSocket hub — real-time updates for chat, agent status, notifications
|
||||||
- Rate limiting and request validation
|
- Rate limiting and request validation
|
||||||
|
|
||||||
### FR-3: Agent Pool (@mosaic/agent)
|
### FR-3: Agent Pool (@mosaicstack/agent)
|
||||||
|
|
||||||
- Manage concurrent Pi SDK sessions
|
- Manage concurrent Pi SDK sessions
|
||||||
- Provider configuration: API key management, endpoint URLs, model lists
|
- Provider configuration: API key management, endpoint URLs, model lists
|
||||||
@@ -582,7 +582,7 @@ Telegram remote control channel.
|
|||||||
- Mission CRUD (linked to project and PRD)
|
- Mission CRUD (linked to project and PRD)
|
||||||
- Mission tasks with phases, dependencies, ordering
|
- Mission tasks with phases, dependencies, ordering
|
||||||
- Mission summary with computed progress
|
- Mission summary with computed progress
|
||||||
- Mission coordination via @mosaic/coord
|
- Mission coordination via @mosaicstack/coord
|
||||||
- Active mission dashboard in web UI
|
- Active mission dashboard in web UI
|
||||||
|
|
||||||
### FR-7: Memory System
|
### FR-7: Memory System
|
||||||
@@ -844,7 +844,7 @@ Telegram remote control channel.
|
|||||||
- [ ] Database migrations run automatically on first start
|
- [ ] Database migrations run automatically on first start
|
||||||
- [ ] `.env.example` documents all required configuration
|
- [ ] `.env.example` documents all required configuration
|
||||||
|
|
||||||
### AC-11: @mosaic/\* Packages
|
### AC-11: @mosaicstack/\* Packages
|
||||||
|
|
||||||
- [ ] All 7 migrated packages build, pass tests, and integrate with gateway
|
- [ ] All 7 migrated packages build, pass tests, and integrate with gateway
|
||||||
- [ ] `mosaic` CLI provides subcommands for each package
|
- [ ] `mosaic` CLI provides subcommands for each package
|
||||||
@@ -870,7 +870,7 @@ Telegram remote control channel.
|
|||||||
|
|
||||||
| Risk | Likelihood | Impact | Mitigation |
|
| Risk | Likelihood | Impact | Mitigation |
|
||||||
| -------------------------------------------------- | ---------- | ------ | ---------------------------------------------------------------------------------------- |
|
| -------------------------------------------------- | ---------- | ------ | ---------------------------------------------------------------------------------------- |
|
||||||
| Pi SDK API instability (pre-1.0) | Medium | High | Pin version, abstract behind @mosaic/agent interface |
|
| Pi SDK API instability (pre-1.0) | Medium | High | Pin version, abstract behind @mosaicstack/agent interface |
|
||||||
| Brain PG migration complexity | Medium | Medium | Preserve Brain REST/MCP API contract; only storage changes |
|
| Brain PG migration complexity | Medium | Medium | Preserve Brain REST/MCP API contract; only storage changes |
|
||||||
| Discord plugin complexity (OpenClaw has ~60 files) | Medium | Medium | Start minimal (DM + mention in channel), single-guild only; expand iteratively post-beta |
|
| Discord plugin complexity (OpenClaw has ~60 files) | Medium | Medium | Start minimal (DM + mention in channel), single-guild only; expand iteratively post-beta |
|
||||||
| LLM provider subscription auth varies by provider | Medium | Medium | Abstract behind provider interface; implement per-provider adapters |
|
| LLM provider subscription auth varies by provider | Medium | Medium | Abstract behind provider interface; implement per-provider adapters |
|
||||||
@@ -882,7 +882,7 @@ Telegram remote control channel.
|
|||||||
|
|
||||||
| # | Question | Priority | Status |
|
| # | Question | Priority | Status |
|
||||||
| --- | ------------------------------------------------------------------------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
| --- | ------------------------------------------------------------------------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
||||||
| 1 | Pi SDK version to pin for v0.1.0? | High | ✅ Resolved — Pin `@mariozechner/pi-coding-agent@~0.57.1` (current stable). Abstract behind `@mosaic/agent` interface to insulate from breaking changes. Bump deliberately after testing. |
|
| 1 | Pi SDK version to pin for v0.1.0? | High | ✅ Resolved — Pin `@mariozechner/pi-coding-agent@~0.57.1` (current stable). Abstract behind `@mosaicstack/agent` interface to insulate from breaking changes. Bump deliberately after testing. |
|
||||||
| 2 | Authentik vs WorkOS vs Keycloak — which SSO provider to implement first? | Medium | ✅ Resolved — Authentik first (already in Jason's infrastructure) |
|
| 2 | Authentik vs WorkOS vs Keycloak — which SSO provider to implement first? | Medium | ✅ Resolved — Authentik first (already in Jason's infrastructure) |
|
||||||
| 3 | Vector DB: pgvector sufficient or need Qdrant from the start? | Medium | ✅ Resolved — pgvector with VectorStore interface abstraction. Qdrant drops in later if needed. |
|
| 3 | Vector DB: pgvector sufficient or need Qdrant from the start? | Medium | ✅ Resolved — pgvector with VectorStore interface abstraction. Qdrant drops in later if needed. |
|
||||||
| 4 | Summarization LLM: which model for log compression? | Medium | ✅ Resolved — Haiku-tier default with structured output guardrails, configurable via routing engine. |
|
| 4 | Summarization LLM: which model for log compression? | Medium | ✅ Resolved — Haiku-tier default with structured output guardrails, configurable via routing engine. |
|
||||||
@@ -910,9 +910,9 @@ All work is **alpha** (< 0.1.0) until Jason approves 0.1.0 beta release.
|
|||||||
### Phase 0: Foundation (v0.0.1)
|
### Phase 0: Foundation (v0.0.1)
|
||||||
|
|
||||||
- Scaffold monorepo (pnpm + turbo + tsconfig + eslint + vitest)
|
- Scaffold monorepo (pnpm + turbo + tsconfig + eslint + vitest)
|
||||||
- `@mosaic/types` — migrate and extend from v0
|
- `@mosaicstack/types` — migrate and extend from v0
|
||||||
- `@mosaic/db` — Drizzle schema, PG connection, migrations
|
- `@mosaicstack/db` — Drizzle schema, PG connection, migrations
|
||||||
- `@mosaic/auth` — BetterAuth setup with email/password
|
- `@mosaicstack/auth` — BetterAuth setup with email/password
|
||||||
- OTEL foundation — `@opentelemetry/sdk-node` setup, SigNoz in docker-compose, trace propagation wired
|
- OTEL foundation — `@opentelemetry/sdk-node` setup, SigNoz in docker-compose, trace propagation wired
|
||||||
- Docker Compose (PG 17 + Valkey + SigNoz)
|
- Docker Compose (PG 17 + Valkey + SigNoz)
|
||||||
- CI pipeline (Woodpecker)
|
- CI pipeline (Woodpecker)
|
||||||
@@ -921,19 +921,19 @@ All work is **alpha** (< 0.1.0) until Jason approves 0.1.0 beta release.
|
|||||||
### Phase 1: Core API (v0.0.2)
|
### Phase 1: Core API (v0.0.2)
|
||||||
|
|
||||||
- `apps/gateway` — NestJS server (Fastify adapter), auth middleware, health endpoints
|
- `apps/gateway` — NestJS server (Fastify adapter), auth middleware, health endpoints
|
||||||
- `@mosaic/brain` — migrate from v0, swap JSON store for PG via @mosaic/db
|
- `@mosaicstack/brain` — migrate from v0, swap JSON store for PG via @mosaicstack/db
|
||||||
- `@mosaic/queue` — migrate from v0 (minimal changes)
|
- `@mosaicstack/queue` — migrate from v0 (minimal changes)
|
||||||
- Gateway routes: conversations, tasks, projects, missions
|
- Gateway routes: conversations, tasks, projects, missions
|
||||||
- WebSocket server for chat streaming
|
- WebSocket server for chat streaming
|
||||||
- Basic agent dispatch (single provider, no routing)
|
- Basic agent dispatch (single provider, no routing)
|
||||||
|
|
||||||
### Phase 2: Agent Layer (v0.0.3)
|
### Phase 2: Agent Layer (v0.0.3)
|
||||||
|
|
||||||
- `@mosaic/agent` — Pi SDK integration, agent pool manager
|
- `@mosaicstack/agent` — Pi SDK integration, agent pool manager
|
||||||
- Multi-provider support (Anthropic + Ollama minimum)
|
- Multi-provider support (Anthropic + Ollama minimum)
|
||||||
- Agent routing engine (cost/capability matrix)
|
- Agent routing engine (cost/capability matrix)
|
||||||
- Tool registration (brain, queue, memory tools injected into agent sessions)
|
- Tool registration (brain, queue, memory tools injected into agent sessions)
|
||||||
- `@mosaic/coord` — migrate from v0, integrate with gateway
|
- `@mosaicstack/coord` — migrate from v0, integrate with gateway
|
||||||
|
|
||||||
### Phase 3: Web Dashboard (v0.0.4)
|
### Phase 3: Web Dashboard (v0.0.4)
|
||||||
|
|
||||||
@@ -946,25 +946,25 @@ All work is **alpha** (< 0.1.0) until Jason approves 0.1.0 beta release.
|
|||||||
|
|
||||||
### Phase 4: Memory & Intelligence (v0.0.5)
|
### Phase 4: Memory & Intelligence (v0.0.5)
|
||||||
|
|
||||||
- `@mosaic/memory` — preference store, insight store, semantic search
|
- `@mosaicstack/memory` — preference store, insight store, semantic search
|
||||||
- `@mosaic/log` — log ingest, parsing, tiered storage
|
- `@mosaicstack/log` — log ingest, parsing, tiered storage
|
||||||
- Summarization pipeline
|
- Summarization pipeline
|
||||||
- Memory integration into agent sessions
|
- Memory integration into agent sessions
|
||||||
- Skill management interface (web UI + CLI)
|
- Skill management interface (web UI + CLI)
|
||||||
|
|
||||||
### Phase 5: Remote Control (v0.0.6)
|
### Phase 5: Remote Control (v0.0.6)
|
||||||
|
|
||||||
- `@mosaic/discord-plugin` — Discord channel plugin
|
- `@mosaicstack/discord-plugin` — Discord channel plugin
|
||||||
- `@mosaic/telegram-plugin` — Telegram channel plugin
|
- `@mosaicstack/telegram-plugin` — Telegram channel plugin
|
||||||
- Plugin host in gateway
|
- Plugin host in gateway
|
||||||
- SSO configuration (Authentik)
|
- SSO configuration (Authentik)
|
||||||
|
|
||||||
### Phase 6: CLI & Tools (v0.0.7)
|
### Phase 6: CLI & Tools (v0.0.7)
|
||||||
|
|
||||||
- `@mosaic/cli` — unified CLI with all subcommands
|
- `@mosaicstack/cli` — unified CLI with all subcommands
|
||||||
- `@mosaic/prdy` — migrate from v0
|
- `@mosaicstack/prdy` — migrate from v0
|
||||||
- `@mosaic/quality-rails` — migrate from v0
|
- `@mosaicstack/quality-rails` — migrate from v0
|
||||||
- `@mosaic/mosaic` — install wizard updated for v1
|
- `@mosaicstack/mosaic` — install wizard updated for v1
|
||||||
- Pi TUI integration (`mosaic tui`)
|
- Pi TUI integration (`mosaic tui`)
|
||||||
|
|
||||||
### Phase 7: Polish & Beta (v0.0.8 → v0.1.0)
|
### Phase 7: Polish & Beta (v0.0.8 → v0.1.0)
|
||||||
@@ -982,11 +982,11 @@ All work is **alpha** (< 0.1.0) until Jason approves 0.1.0 beta release.
|
|||||||
|
|
||||||
## Assumptions
|
## Assumptions
|
||||||
|
|
||||||
1. RESOLVED: **pgvector is sufficient** for semantic search at v0.1.0 scale (personal/family/team = thousands to low hundreds-of-thousands of vectors). `@mosaic/memory` defines a `VectorStore` interface with pgvector as the default adapter. The interface boundary makes Qdrant a drop-in migration if PG resource contention or scale demands it later. Zero additional infrastructure for v0.1.0. Rationale: Reduces ops burden; pgvector HNSW indexes are fast at this scale; interface abstraction costs almost nothing now.
|
1. RESOLVED: **pgvector is sufficient** for semantic search at v0.1.0 scale (personal/family/team = thousands to low hundreds-of-thousands of vectors). `@mosaicstack/memory` defines a `VectorStore` interface with pgvector as the default adapter. The interface boundary makes Qdrant a drop-in migration if PG resource contention or scale demands it later. Zero additional infrastructure for v0.1.0. Rationale: Reduces ops burden; pgvector HNSW indexes are fast at this scale; interface abstraction costs almost nothing now.
|
||||||
|
|
||||||
2. RESOLVED: **Authentik is the first SSO provider** — confirmed, already running in Jason's infrastructure. WorkOS and Keycloak adapters follow in Phase 7.
|
2. RESOLVED: **Authentik is the first SSO provider** — confirmed, already running in Jason's infrastructure. WorkOS and Keycloak adapters follow in Phase 7.
|
||||||
|
|
||||||
3. RESOLVED: **NestJS with Fastify adapter for the gateway.** The gateway's complexity (plugin host, agent pool, routing engine, WebSocket hub, MCP server, auth, brain/queue/memory/log integration) warrants NestJS's module system, DI, and guards. Fastify performance preserved via adapter. Aligns with USER.md stated stack ("NestJS API + Next.js web"). @mosaic/brain's Fastify code migrates into a NestJS module.
|
3. RESOLVED: **NestJS with Fastify adapter for the gateway.** The gateway's complexity (plugin host, agent pool, routing engine, WebSocket hub, MCP server, auth, brain/queue/memory/log integration) warrants NestJS's module system, DI, and guards. Fastify performance preserved via adapter. Aligns with USER.md stated stack ("NestJS API + Next.js web"). @mosaicstack/brain's Fastify code migrates into a NestJS module.
|
||||||
|
|
||||||
4. RESOLVED: **OpenTelemetry from Phase 0.** Wide-event logging is required from the start. OTEL auto-instrumentation for NestJS/PG/HTTP via `@opentelemetry/sdk-node`. SigNoz as the all-in-one OTEL backend (single Docker service). Every significant operation emits structured events with rich context. Custom spans for agent dispatch, routing decisions, memory writes. Rationale: Retrofitting observability is painful; baking it in from day one means consistent instrumentation across all services.
|
4. RESOLVED: **OpenTelemetry from Phase 0.** Wide-event logging is required from the start. OTEL auto-instrumentation for NestJS/PG/HTTP via `@opentelemetry/sdk-node`. SigNoz as the all-in-one OTEL backend (single Docker service). Every significant operation emits structured events with rich context. Custom spans for agent dispatch, routing decisions, memory writes. Rationale: Retrofitting observability is painful; baking it in from day one means consistent instrumentation across all services.
|
||||||
|
|
||||||
@@ -1002,4 +1002,4 @@ All work is **alpha** (< 0.1.0) until Jason approves 0.1.0 beta release.
|
|||||||
|
|
||||||
10. ASSUMPTION: **Conversations and messages get their own PG tables** (not stored in brain's entity model). They follow a chat-specific schema with proper foreign keys to users and projects. Rationale: Chat has different access patterns (streaming, pagination, search) than brain entities.
|
10. ASSUMPTION: **Conversations and messages get their own PG tables** (not stored in brain's entity model). They follow a chat-specific schema with proper foreign keys to users and projects. Rationale: Chat has different access patterns (streaming, pagination, search) than brain entities.
|
||||||
|
|
||||||
11. RESOLVED: **Pi handles all target LLM providers natively.** Anthropic, OpenAI/Codex, Z.ai, Ollama, LM Studio, and llama.cpp are all supported via Pi's built-in providers or `models.json` configuration with `openai-completions` API type. No custom provider adapters needed in @mosaic/agent — only configuration management.
|
11. RESOLVED: **Pi handles all target LLM providers natively.** Anthropic, OpenAI/Codex, Z.ai, Ollama, LM Studio, and llama.cpp are all supported via Pi's built-in providers or `models.json` configuration with `openai-completions` API type. No custom provider adapters needed in @mosaicstack/agent — only configuration management.
|
||||||
|
|||||||
@@ -108,4 +108,4 @@ The web login page renders provider buttons from `NEXT_PUBLIC_*_ENABLED` flags.
|
|||||||
|
|
||||||
## Failure mode
|
## Failure mode
|
||||||
|
|
||||||
Provider config is optional, but partial config is rejected at startup. If any provider-specific env var is present without the full required set, `@mosaic/auth` throws a bootstrap error with the missing keys instead of silently registering a broken provider.
|
Provider config is optional, but partial config is rejected at startup. If any provider-specific env var is present without the full required set, `@mosaicstack/auth` throws a bootstrap error with the missing keys instead of silently registering a broken provider.
|
||||||
|
|||||||
@@ -91,15 +91,15 @@ packages/cli/src/tui/
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd /home/jwoltje/src/mosaic-mono-v1-worktrees/tui-improvements
|
cd /home/jwoltje/src/mosaic-mono-v1-worktrees/tui-improvements
|
||||||
pnpm --filter @mosaic/cli exec tsx src/cli.ts tui
|
pnpm --filter @mosaicstack/cli exec tsx src/cli.ts tui
|
||||||
# or after build:
|
# or after build:
|
||||||
node packages/cli/dist/cli.js tui --gateway http://localhost:4000
|
node packages/cli/dist/cli.js tui --gateway http://localhost:14242
|
||||||
```
|
```
|
||||||
|
|
||||||
### Quality Gates
|
### Quality Gates
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pnpm --filter @mosaic/cli typecheck && pnpm --filter @mosaic/cli lint
|
pnpm --filter @mosaicstack/cli typecheck && pnpm --filter @mosaicstack/cli lint
|
||||||
pnpm --filter @mosaic/gateway typecheck && pnpm --filter @mosaic/gateway lint
|
pnpm --filter @mosaicstack/gateway typecheck && pnpm --filter @mosaicstack/gateway lint
|
||||||
pnpm --filter @mosaic/types typecheck
|
pnpm --filter @mosaicstack/types typecheck
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -1,30 +1,40 @@
|
|||||||
# Tasks — Storage Abstraction Retrofit
|
# Tasks — MVP (Top-Level Rollup)
|
||||||
|
|
||||||
> Single-writer: orchestrator only. Workers read but never modify.
|
> Single-writer: orchestrator only. Workers read but never modify.
|
||||||
>
|
>
|
||||||
> **Mission:** Decouple gateway from hardcoded Postgres/Valkey backends. Introduce interface-driven middleware so the gateway is backend-agnostic. Default to local tier (SQLite + JSON) for zero-dependency installs.
|
> **Mission:** mvp-20260312
|
||||||
|
> **Manifest:** [docs/MISSION-MANIFEST.md](./MISSION-MANIFEST.md)
|
||||||
>
|
>
|
||||||
> **`agent` column values:** `codex` | `sonnet` | `haiku` | `glm-5` | `opus` | `—` (auto/default)
|
> This file is a **rollup**. Per-workstream task breakdowns live in workstream task files
|
||||||
|
> (e.g. `docs/federation/TASKS.md`). Workers operating inside a workstream should treat
|
||||||
|
> the workstream file as their primary task source; this file exists for orchestrator-level
|
||||||
|
> visibility into MVP-wide state.
|
||||||
|
>
|
||||||
|
> **Status values:** `not-started` | `in-progress` | `done` | `blocked` | `failed`
|
||||||
|
|
||||||
| id | status | agent | description | tokens |
|
## Workstream Rollup
|
||||||
| --------- | ----------- | ------ | ---------------------------------------------------------------- | ------ |
|
|
||||||
| SA-P1-001 | done | sonnet | Define QueueAdapter interface in packages/queue/src/types.ts | 3K |
|
| id | status | workstream | progress | tasks file | notes |
|
||||||
| SA-P1-002 | done | sonnet | Define StorageAdapter interface in packages/storage/src/types.ts | 3K |
|
| --- | ----------------- | ------------------- | ---------------- | ------------------------------------------------- | --------------------------------------------------------------- |
|
||||||
| SA-P1-003 | done | sonnet | Define MemoryAdapter interface in packages/memory/src/types.ts | 3K |
|
| W1 | planning-complete | Federation v1 (FED) | 0 / 7 milestones | [docs/federation/TASKS.md](./federation/TASKS.md) | M1 task breakdown populated; M2–M7 deferred to mission planning |
|
||||||
| SA-P1-004 | done | sonnet | Create adapter factory pattern + config types | 3K |
|
|
||||||
| SA-P2-001 | done | sonnet | Refactor @mosaic/queue: wrap ioredis as BullMQ adapter | 3K |
|
## Cross-Cutting Tracking
|
||||||
| SA-P2-002 | done | sonnet | Create @mosaic/storage: wrap Drizzle as Postgres adapter | 6K |
|
|
||||||
| SA-P2-003 | done | sonnet | Refactor @mosaic/memory: extract pgvector adapter | 4K |
|
These are MVP-level checks that don't belong to any single workstream. Updated by the orchestrator at each session.
|
||||||
| SA-P2-004 | done | sonnet | Update gateway modules to use factories + DI tokens | 5K |
|
|
||||||
| SA-P2-005 | done | opus | Verify Phase 2: all tests pass, typecheck clean | — |
|
| id | status | description | notes |
|
||||||
| SA-P3-001 | done | sonnet | Implement local queue adapter: JSON file persistence | 5K |
|
| ------- | ----------- | -------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- |
|
||||||
| SA-P3-002 | done | sonnet | Implement SQLite storage adapter with better-sqlite3 | 8K |
|
| MVP-T01 | done | Author MVP-level manifest at `docs/MISSION-MANIFEST.md` | This session (2026-04-19); PR pending |
|
||||||
| SA-P3-003 | done | sonnet | Implement keyword memory adapter — no vector dependency | 4K |
|
| MVP-T02 | done | Archive install-ux-v2 mission state to `docs/archive/missions/install-ux-v2-20260405/` | IUV-M03 retroactively closed (shipped via PR #446 + releases 0.0.27→0.0.29) |
|
||||||
| SA-P3-004 | done | opus | Verify Phase 3: 42 new tests, 347 total passing | — |
|
| MVP-T03 | done | Land federation v1 planning artifacts on `main` | PR #468 merged 2026-04-19 (commit `66512550`) |
|
||||||
| SA-P4-001 | done | sonnet | MosaicConfig schema + loader with tier auto-detection | 6K |
|
| MVP-T04 | not-started | Sync `.mosaic/orchestrator/mission.json` MVP slot with this manifest (milestone enumeration, etc.) | Coord state file; consider whether to repopulate via `mosaic coord` or accept hand-edit |
|
||||||
| SA-P4-002 | done | sonnet | CLI: mosaic gateway init — interactive wizard | 4K |
|
| MVP-T05 | in-progress | Kick off W1 / FED-M1 — federated tier infrastructure | Session 16 (2026-04-19): FED-M1-01 in-progress on `feat/federation-m1-tier-config` |
|
||||||
| SA-P4-003 | done | sonnet | CLI: mosaic gateway start/stop/status lifecycle | 5K |
|
| MVP-T06 | not-started | Declare additional workstreams (web dashboard, TUI/CLI parity, remote control, etc.) as scope solidifies | Track each new workstream by adding a row to the Workstream Rollup |
|
||||||
| SA-P4-004 | done | opus | Verify Phase 4: 381 tests passing, 40/40 tasks clean | — |
|
|
||||||
| SA-P5-001 | not-started | codex | Migration tooling: mosaic storage export/import | — |
|
## Pointer to Active Workstream
|
||||||
| SA-P5-002 | not-started | codex | Docker Compose profiles: local vs team | — |
|
|
||||||
| SA-P5-003 | not-started | codex | Final verification + docs: README, architecture diagram | — |
|
Active workstream is **W1 — Federation v1**. Workers should:
|
||||||
|
|
||||||
|
1. Read [docs/federation/MISSION-MANIFEST.md](./federation/MISSION-MANIFEST.md) for workstream scope
|
||||||
|
2. Read [docs/federation/TASKS.md](./federation/TASKS.md) for the next pending task
|
||||||
|
3. Follow per-task agent + tier guidance from the workstream manifest
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
# Mission Manifest — CLI Unification & E2E First-Run
|
||||||
|
|
||||||
|
> Persistent document tracking full mission scope, status, and session history.
|
||||||
|
> Updated by the orchestrator at each phase transition and milestone completion.
|
||||||
|
|
||||||
|
## Mission
|
||||||
|
|
||||||
|
**ID:** cli-unification-20260404
|
||||||
|
**Statement:** Transform the Mosaic CLI from a partially-duplicated, manually-assembled experience into a single cohesive entry point that installs, configures, and controls the entire Mosaic system. Every Mosaic package gets first-class CLI surface. The first-run experience works end-to-end with no manual stitching. Gateway token recovery is possible without the web UI. Opt-in telemetry uses the published telemetry clients.
|
||||||
|
**Phase:** Complete
|
||||||
|
**Current Milestone:** —
|
||||||
|
**Progress:** 8 / 8 milestones
|
||||||
|
**Status:** completed
|
||||||
|
**Last Updated:** 2026-04-05
|
||||||
|
**Release:** [`mosaic-v0.0.24`](https://git.mosaicstack.dev/mosaicstack/mosaic-stack/releases/tag/mosaic-v0.0.24) (`@mosaicstack/mosaic@0.0.24`, alpha — stays in 0.0.x until GA)
|
||||||
|
|
||||||
|
## Success Criteria
|
||||||
|
|
||||||
|
- [x] AC-1: Fresh machine `bash <(curl …install.sh)` → single command lands on a working authenticated gateway with a usable admin token; no secondary manual wizards required
|
||||||
|
- [x] AC-2: `mosaic --help` lists every sub-package as a top-level command and is alphabetized for readability
|
||||||
|
- [x] AC-3: `mosaic auth`, `mosaic brain`, `mosaic forge`, `mosaic log`, `mosaic macp`, `mosaic memory`, `mosaic queue`, `mosaic storage`, `mosaic telemetry` each expose at least one working subcommand that exercises the underlying package
|
||||||
|
- [x] AC-4: Gateway admin token can be rotated or recovered from the CLI alone — operator is never stranded because the web UI is inaccessible
|
||||||
|
- [x] AC-5: `mosaic telemetry` uses the published `@mosaicstack/telemetry-client-js` (from the Gitea npm registry); local OTEL stays for wide-event logging / post-mortems; remote upload is opt-in and disabled by default
|
||||||
|
- [x] AC-6: Install → wizard → gateway install → TUI verification flow is a single cohesive path with clear state transitions and no dead ends
|
||||||
|
- [x] AC-7: `@mosaicstack/mosaic` is the sole `mosaic` binary owner; `@mosaicstack/cli` is gone from the repo and all docs
|
||||||
|
- [x] AC-8: All milestones ship as merged PRs with green CI, closed issues, and updated release notes
|
||||||
|
|
||||||
|
## Milestones
|
||||||
|
|
||||||
|
| # | ID | Name | Status | Branch | Issue | Started | Completed |
|
||||||
|
| --- | ------ | ------------------------------------------------------------------------ | ------ | ----------------------------------- | --------------------------------- | ---------- | ---------- |
|
||||||
|
| 1 | cu-m01 | Kill legacy @mosaicstack/cli package | done | chore/remove-cli-package-duplicate | #398 | 2026-04-04 | 2026-04-04 |
|
||||||
|
| 2 | cu-m02 | Archive stale mission state + scaffold new mission | done | docs/mission-cli-unification | #399 | 2026-04-04 | 2026-04-04 |
|
||||||
|
| 3 | cu-m03 | Fix gateway bootstrap token recovery (server + CLI paths) | done | feat/gateway-token-recovery | #411, #414 | 2026-04-05 | 2026-04-05 |
|
||||||
|
| 4 | cu-m04 | Alphabetize + group `mosaic --help` output | done | feat/help-sort + feat/mosaic-config | #402, #408 | 2026-04-05 | 2026-04-05 |
|
||||||
|
| 5 | cu-m05 | Sub-package CLI surface (auth/brain/forge/log/macp/memory/queue/storage) | done | feat/mosaic-\*-cli (x9) | #403–#407, #410, #412, #413, #415 | 2026-04-05 | 2026-04-05 |
|
||||||
|
| 6 | cu-m06 | `mosaic telemetry` — local OTEL + opt-in remote upload | done | feat/mosaic-telemetry | #417 | 2026-04-05 | 2026-04-05 |
|
||||||
|
| 7 | cu-m07 | Unified first-run UX (install.sh → wizard → gateway → TUI) | done | feat/mosaic-first-run-ux | #418 | 2026-04-05 | 2026-04-05 |
|
||||||
|
| 8 | cu-m08 | Docs refresh + release tag | done | docs/cli-unification-release-v0.1.0 | #419 | 2026-04-05 | 2026-04-05 |
|
||||||
|
|
||||||
|
## Deployment
|
||||||
|
|
||||||
|
| Target | URL | Method |
|
||||||
|
| -------------------- | --------- | ----------------------------------------------- |
|
||||||
|
| Local tier (default) | localhost | `mosaic gateway install` — pglite + local queue |
|
||||||
|
| Team tier | any host | `mosaic gateway install` — PG + Valkey |
|
||||||
|
| Docker Compose (dev) | localhost | `docker compose up` for PG/Valkey/OTEL/Jaeger |
|
||||||
|
|
||||||
|
## Coordination
|
||||||
|
|
||||||
|
- **Primary Agent:** claude-opus-4-6[1m]
|
||||||
|
- **Sibling Agents:** sonnet (standard implementation), haiku (status/explore/verify), codex (coding-heavy tasks)
|
||||||
|
- **Shared Contracts:** `docs/PRD.md` (existing v0.1.0 PRD — still the long-term target), this manifest, `docs/TASKS.md`, `docs/scratchpads/cli-unification-20260404.md`
|
||||||
|
|
||||||
|
## Token Budget
|
||||||
|
|
||||||
|
| Metric | Value |
|
||||||
|
| ------ | ------ |
|
||||||
|
| Budget | TBD |
|
||||||
|
| Used | ~80K |
|
||||||
|
| Mode | normal |
|
||||||
|
|
||||||
|
## Session History
|
||||||
|
|
||||||
|
| Session | Runtime | Started | Duration | Ended Reason | Last Task |
|
||||||
|
| ------- | --------------- | ---------- | -------- | ---------------- | ------------------------------------------------------------ |
|
||||||
|
| 1 | claude-opus-4-6 | 2026-04-04 | ~4h | context-budget | cu-m01 + cu-m02 merged (#398, #399); open questions resolved |
|
||||||
|
| 2 | claude-opus-4-6 | 2026-04-05 | ~6h | mission-complete | cu-m03..cu-m08 all merged; mosaic-v0.1.0 released |
|
||||||
|
|
||||||
|
## Scratchpad
|
||||||
|
|
||||||
|
Path: `docs/scratchpads/cli-unification-20260404.md`
|
||||||
90
docs/archive/missions/cli-unification-20260404/TASKS.md
Normal file
90
docs/archive/missions/cli-unification-20260404/TASKS.md
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
# Tasks — CLI Unification & E2E First-Run
|
||||||
|
|
||||||
|
> Single-writer: orchestrator only. Workers read but never modify.
|
||||||
|
>
|
||||||
|
> **Mission:** cli-unification-20260404
|
||||||
|
> **Schema:** `| id | status | description | issue | agent | branch | depends_on | estimate | notes |`
|
||||||
|
> **Status values:** `not-started` | `in-progress` | `done` | `blocked` | `failed` | `needs-qa`
|
||||||
|
> **Agent values:** `codex` | `sonnet` | `haiku` | `opus` | `glm-5` | `—` (auto)
|
||||||
|
|
||||||
|
## Milestone 1 — Kill legacy @mosaicstack/cli (done)
|
||||||
|
|
||||||
|
| id | status | description | issue | agent | branch | depends_on | estimate | notes |
|
||||||
|
| -------- | ------ | ----------------------------------------------------------------- | ----- | ----- | ---------------------------------- | ---------- | -------- | --------------------------- |
|
||||||
|
| CU-01-01 | done | Delete packages/cli directory; update workspace + docs references | #398 | opus | chore/remove-cli-package-duplicate | — | 5K | Merged c39433c3. 6685 LOC−. |
|
||||||
|
|
||||||
|
## Milestone 2 — Archive stale mission + scaffold new mission (done)
|
||||||
|
|
||||||
|
| id | status | description | issue | agent | branch | depends_on | estimate | notes |
|
||||||
|
| -------- | ------ | ------------------------------------------------------------------ | ----- | ----- | ---------------------------- | ---------- | -------- | --------------------------------- |
|
||||||
|
| CU-02-01 | done | Move stale MISSION-MANIFEST / TASKS / PRD-Harness to docs/archive/ | #399 | opus | docs/mission-cli-unification | CU-01-01 | 3K | Harness + storage missions done. |
|
||||||
|
| CU-02-02 | done | Scaffold new MISSION-MANIFEST.md, TASKS.md, scratchpad | #399 | opus | docs/mission-cli-unification | CU-02-01 | 5K | This file + manifest + scratchpad |
|
||||||
|
| CU-02-03 | done | PR review, merge, branch cleanup | #399 | opus | docs/mission-cli-unification | CU-02-02 | 2K | Merged as 6f15a84c |
|
||||||
|
|
||||||
|
## Milestone 3 — Gateway bootstrap token recovery
|
||||||
|
|
||||||
|
| id | status | description | issue | agent | branch | depends_on | estimate | notes |
|
||||||
|
| -------- | ------ | ---------------------------------------------------------------------------------------------- | ----- | ------ | ------ | ---------- | -------- | ----------------------------- |
|
||||||
|
| CU-03-01 | done | Implementation plan for BetterAuth-cookie recovery flow (decision locked 2026-04-04) | — | opus | — | CU-02-03 | 4K | Design locked; plan-only task |
|
||||||
|
| CU-03-02 | done | Server: add recovery/rotate endpoint on apps/gateway/src/admin (gated by design from CU-03-01) | — | sonnet | — | CU-03-01 | 12K | |
|
||||||
|
| CU-03-03 | done | CLI: `mosaic gateway login` — interactive BetterAuth sign-in, persist session | — | sonnet | — | CU-03-02 | 10K | |
|
||||||
|
| CU-03-04 | done | CLI: `mosaic gateway config rotate-token` — mint new admin token via authenticated API | — | sonnet | — | CU-03-03 | 8K | |
|
||||||
|
| CU-03-05 | done | CLI: `mosaic gateway config recover-token` — execute the recovery flow from CU-03-01 | — | sonnet | — | CU-03-03 | 10K | |
|
||||||
|
| CU-03-06 | done | Install UX: fix the "user exists, no token" dead-end in runInstall bootstrapFirstUser path | — | sonnet | — | CU-03-05 | 8K | |
|
||||||
|
| CU-03-07 | done | Tests: integration tests for each recovery path (happy + error) | — | sonnet | — | CU-03-06 | 10K | |
|
||||||
|
| CU-03-08 | done | Code review + remediation | — | haiku | — | CU-03-07 | 4K | |
|
||||||
|
|
||||||
|
## Milestone 4 — `mosaic --help` alphabetize + grouping
|
||||||
|
|
||||||
|
| id | status | description | issue | agent | branch | depends_on | estimate | notes |
|
||||||
|
| -------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- | ------ | ------ | ---------- | -------- | ------------------------------- |
|
||||||
|
| CU-04-01 | done | Enable `configureHelp({ sortSubcommands: true })` on root program and each subgroup | — | sonnet | — | CU-02-03 | 3K | |
|
||||||
|
| CU-04-02 | done | Group commands into sections (Runtime, Gateway, Framework, Platform) in help output | — | sonnet | — | CU-04-01 | 5K | |
|
||||||
|
| CU-04-03 | done | Verify help snapshots render readably; update any docs with stale output | — | haiku | — | CU-04-02 | 3K | |
|
||||||
|
| CU-04-04 | done | Top-level `mosaic config` command — `show`, `get <key>`, `set <key> <val>`, `edit`, `path` — wraps packages/mosaic/src/config/config-service.ts (framework/agent config; distinct from `mosaic gateway config`) | — | sonnet | — | CU-02-03 | 10K | New scope (decision 2026-04-04) |
|
||||||
|
| CU-04-05 | done | Tests + code review for CU-04-04 | — | haiku | — | CU-04-04 | 4K | |
|
||||||
|
|
||||||
|
## Milestone 5 — Sub-package CLI surface
|
||||||
|
|
||||||
|
> Pattern: each sub-package exports `register<Name>Command(program: Command)` co-located with the library code (proven by `@mosaicstack/quality-rails`). Wire into `packages/mosaic/src/cli.ts`.
|
||||||
|
|
||||||
|
| id | status | description | issue | agent | branch | depends_on | estimate | notes |
|
||||||
|
| -------- | ------ | --------------------------------------------------------------------------------------------------------- | ----- | ------ | ------ | ---------- | -------- | ------------------- |
|
||||||
|
| CU-05-01 | done | `mosaic forge` — subcommands: `run`, `status`, `resume`, `personas list` | — | sonnet | — | CU-02-03 | 18K | User priority |
|
||||||
|
| CU-05-02 | done | `mosaic storage` — subcommands: `status`, `tier show`, `tier switch`, `export`, `import`, `migrate` | — | sonnet | — | CU-02-03 | 15K | |
|
||||||
|
| CU-05-03 | done | `mosaic queue` — subcommands: `list`, `stats`, `pause/resume`, `jobs tail`, `drain` | — | sonnet | — | CU-02-03 | 12K | |
|
||||||
|
| CU-05-04 | done | `mosaic memory` — subcommands: `search`, `stats`, `insights list`, `preferences list` | — | sonnet | — | CU-02-03 | 12K | |
|
||||||
|
| CU-05-05 | done | `mosaic brain` — subcommands: `projects list/create`, `missions list`, `tasks list`, `conversations list` | — | sonnet | — | CU-02-03 | 15K | |
|
||||||
|
| CU-05-06 | done | `mosaic auth` — subcommands: `users list/create/delete`, `sso list`, `sso test`, `sessions list` | — | sonnet | — | CU-03-03 | 15K | needs gateway login |
|
||||||
|
| CU-05-07 | done | `mosaic log` — subcommands: `tail`, `search`, `export`, `level <level>` | — | sonnet | — | CU-02-03 | 10K | |
|
||||||
|
| CU-05-08 | done | `mosaic macp` — subcommands: `tasks list`, `submit`, `gate`, `events tail` | — | sonnet | — | CU-02-03 | 12K | |
|
||||||
|
| CU-05-09 | done | Wire all eight `register<Name>Command` calls into packages/mosaic/src/cli.ts | — | haiku | — | CU-05-01…8 | 3K | |
|
||||||
|
| CU-05-10 | done | Integration test: `mosaic <cmd> --help` exits 0 for every new command | — | haiku | — | CU-05-09 | 5K | |
|
||||||
|
|
||||||
|
## Milestone 6 — `mosaic telemetry`
|
||||||
|
|
||||||
|
| id | status | description | issue | agent | branch | depends_on | estimate | notes |
|
||||||
|
| -------- | ------ | ------------------------------------------------------------------------------------------------- | ----- | ------ | ------ | ---------- | -------- | ---------------------------------------------- |
|
||||||
|
| CU-06-01 | done | Add `@mosaicstack/telemetry-client-js` as dependency of `@mosaicstack/mosaic` from Gitea registry | — | sonnet | — | CU-02-03 | 3K | |
|
||||||
|
| CU-06-02 | done | `mosaic telemetry local` — status, tail, Jaeger link (wraps existing apps/gateway/src/tracing.ts) | — | sonnet | — | CU-06-01 | 8K | |
|
||||||
|
| CU-06-03 | done | `mosaic telemetry` — status, opt-in, opt-out, test, upload (uses telemetry-client-js) | — | sonnet | — | CU-06-01 | 12K | Dry-run mode when server endpoint not yet live |
|
||||||
|
| CU-06-04 | done | Persistent consent state in mosaic config; disabled by default | — | sonnet | — | CU-06-03 | 5K | |
|
||||||
|
| CU-06-05 | done | Tests + code review | — | haiku | — | CU-06-04 | 5K | |
|
||||||
|
|
||||||
|
## Milestone 7 — Unified first-run UX
|
||||||
|
|
||||||
|
| id | status | description | issue | agent | branch | depends_on | estimate | notes |
|
||||||
|
| -------- | ------ | ---------------------------------------------------------------------------------------------- | ----- | ------ | ------ | ---------- | -------- | ----- |
|
||||||
|
| CU-07-01 | done | tools/install.sh: after npm install, hand off to `mosaic wizard` then `mosaic gateway install` | — | sonnet | — | CU-03-06 | 10K | |
|
||||||
|
| CU-07-02 | done | `mosaic wizard` and `mosaic gateway install` coordination: shared state, no duplicate prompts | — | sonnet | — | CU-07-01 | 12K | |
|
||||||
|
| CU-07-03 | done | Post-install verification step: "gateway healthy, tui connects, admin token on file" | — | sonnet | — | CU-07-02 | 8K | |
|
||||||
|
| CU-07-04 | done | End-to-end test on a clean container from scratch | — | haiku | — | CU-07-03 | 8K | |
|
||||||
|
|
||||||
|
## Milestone 8 — Docs + release
|
||||||
|
|
||||||
|
| id | status | description | issue | agent | branch | depends_on | estimate | notes |
|
||||||
|
| -------- | ------ | ---------------------------------------------------------------------- | ----- | ------ | ------ | ---------- | -------- | ----- |
|
||||||
|
| CU-08-01 | done | Update README.md with new command tree, install flow, and feature list | — | sonnet | — | CU-07-04 | 8K | |
|
||||||
|
| CU-08-02 | done | Update docs/guides/user-guide.md with all new sub-package commands | — | sonnet | — | CU-08-01 | 10K | |
|
||||||
|
| CU-08-03 | done | Version bump `@mosaicstack/mosaic`, publish to Gitea registry | — | opus | — | CU-08-02 | 3K | |
|
||||||
|
| CU-08-04 | done | Release notes, tag `v0.1.0-rc.N`, publish release on Gitea | — | opus | — | CU-08-03 | 3K | |
|
||||||
70
docs/archive/missions/harness-20260321/MISSION-MANIFEST.md
Normal file
70
docs/archive/missions/harness-20260321/MISSION-MANIFEST.md
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
# Mission Manifest — Harness Foundation
|
||||||
|
|
||||||
|
> Persistent document tracking full mission scope, status, and session history.
|
||||||
|
> Updated by the orchestrator at each phase transition and milestone completion.
|
||||||
|
|
||||||
|
## Mission
|
||||||
|
|
||||||
|
**ID:** harness-20260321
|
||||||
|
**Statement:** Transform Mosaic Stack from a functional demo into a real multi-provider, task-routing AI harness. Persist all conversations, integrate frontier LLM providers (Anthropic, OpenAI, OpenRouter, Z.ai, Ollama), build granular task-aware agent routing, harden agent sessions, replace cron with BullMQ, and design the channel protocol for future Matrix/remote integration.
|
||||||
|
**Phase:** Complete
|
||||||
|
**Current Milestone:** All milestones done
|
||||||
|
**Progress:** 7 / 7 milestones
|
||||||
|
**Status:** complete
|
||||||
|
**Last Updated:** 2026-03-22 UTC
|
||||||
|
|
||||||
|
## Success Criteria
|
||||||
|
|
||||||
|
- [x] AC-1: Send messages in TUI → restart TUI → resume conversation → agent has full history and context
|
||||||
|
- [x] AC-2: Route a coding task to Claude Opus 4.6, a simple question to Haiku, a summarization to GLM-5 — all via granular routing rules
|
||||||
|
- [x] AC-3: Two users exist, User A's memory searches never return User B's data
|
||||||
|
- [x] AC-4: `/model claude-sonnet-4-6` in TUI switches the active model for subsequent messages
|
||||||
|
- [x] AC-5: `/agent coding-agent` in TUI switches to a different agent with different system prompt and tools
|
||||||
|
- [x] AC-6: BullMQ jobs execute on schedule, failures retry with backoff, admin can inspect via `/api/admin/jobs`
|
||||||
|
- [x] AC-7: Channel protocol document exists with Matrix integration points defined, reviewed, and approved
|
||||||
|
- [x] AC-8: Embeddings run on Ollama local models (no external API dependency for vector operations)
|
||||||
|
- [x] AC-9: All five providers (Anthropic, OpenAI, OpenRouter, Z.ai, Ollama) connect, list models, and complete chat requests
|
||||||
|
- [x] AC-10: Routing transparency — TUI displays which model was selected and the routing reason for each response
|
||||||
|
|
||||||
|
## Milestones
|
||||||
|
|
||||||
|
| # | ID | Name | Status | Branch | Issue | Started | Completed |
|
||||||
|
| --- | ------ | ---------------------------------- | ------ | ------ | --------- | ---------- | ---------- |
|
||||||
|
| 1 | ms-166 | Conversation Persistence & Context | done | — | #224–#231 | 2026-03-21 | 2026-03-21 |
|
||||||
|
| 2 | ms-167 | Security & Isolation | done | — | #232–#239 | 2026-03-21 | 2026-03-21 |
|
||||||
|
| 3 | ms-168 | Provider Integration | done | — | #240–#251 | 2026-03-21 | 2026-03-22 |
|
||||||
|
| 4 | ms-169 | Agent Routing Engine | done | — | #252–#264 | 2026-03-22 | 2026-03-22 |
|
||||||
|
| 5 | ms-170 | Agent Session Hardening | done | — | #265–#272 | 2026-03-22 | 2026-03-22 |
|
||||||
|
| 6 | ms-171 | Job Queue Foundation | done | — | #273–#280 | 2026-03-22 | 2026-03-22 |
|
||||||
|
| 7 | ms-172 | Channel Protocol Design | done | — | #281–#288 | 2026-03-22 | 2026-03-22 |
|
||||||
|
|
||||||
|
## Deployment
|
||||||
|
|
||||||
|
| Target | URL | Method |
|
||||||
|
| -------------------- | --------- | -------------------------- |
|
||||||
|
| Docker Compose (dev) | localhost | docker compose up |
|
||||||
|
| Production | TBD | Docker Swarm via Portainer |
|
||||||
|
|
||||||
|
## Coordination
|
||||||
|
|
||||||
|
- **Primary Agent:** claude-opus-4-6
|
||||||
|
- **Sibling Agents:** sonnet (workers), haiku (verification)
|
||||||
|
- **Shared Contracts:** docs/PRD-Harness_Foundation.md, docs/TASKS.md
|
||||||
|
|
||||||
|
## Token Budget
|
||||||
|
|
||||||
|
| Metric | Value |
|
||||||
|
| ------ | ------ |
|
||||||
|
| Budget | — |
|
||||||
|
| Used | ~2.5M |
|
||||||
|
| Mode | normal |
|
||||||
|
|
||||||
|
## Session History
|
||||||
|
|
||||||
|
| Session | Runtime | Started | Duration | Ended Reason | Last Task |
|
||||||
|
| ------- | --------------- | ---------- | -------- | ------------ | ----------------- |
|
||||||
|
| 1 | claude-opus-4-6 | 2026-03-21 | ~6h | complete | M7-008 — all done |
|
||||||
|
|
||||||
|
## Scratchpad
|
||||||
|
|
||||||
|
Path: `docs/scratchpads/harness-20260321.md`
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user