Compare commits
69 Commits
v0.2.56
...
95495a8332
| Author | SHA1 | Date | |
|---|---|---|---|
| 95495a8332 | |||
| 68b428e411 | |||
| 1214cf9a4d | |||
| 195c497c88 | |||
| a2272c5df6 | |||
| 5df5194651 | |||
| 39aeab62d6 | |||
| 8b1400da17 | |||
| dd17cefa3b | |||
| 2aa41e6366 | |||
| 696e9daf4d | |||
| 701e15ee9b | |||
| fe97d1aaf0 | |||
| df94ed3cd4 | |||
| de1fc198cb | |||
| f33e8c8b58 | |||
| dd38570c7b | |||
| 5dc00c1142 | |||
| cf10ca3ed8 | |||
| 1f8b45a327 | |||
| b1dcf51218 | |||
| 0fdc40a95c | |||
| 071cbe8ce5 | |||
| c750a5abcd | |||
| dd81070afd | |||
| be5c3884a0 | |||
| 7a2d5ded20 | |||
| 784cb4eeee | |||
| 6b2ab04f8d | |||
| ca4bad2ba7 | |||
| ac131f7f53 | |||
| b89289989a | |||
| f95463ef50 | |||
| 2d218853a5 | |||
| adae7ba26d | |||
| 3dd745586b | |||
| f0023ac033 | |||
| 73c5eb69d7 | |||
| 06eac66baa | |||
| b95bec7915 | |||
| 071be50977 | |||
| baf4008d97 | |||
| 83e072bc27 | |||
| a516353ae8 | |||
| 1df663f57c | |||
| e4091eee80 | |||
| dcc8450c62 | |||
| 12998170e3 | |||
| 691152f889 | |||
| 74ef58d274 | |||
| 5e7d074593 | |||
| c496608c86 | |||
| c040696d91 | |||
| 7ba0bd26fa | |||
| 4b1d140b53 | |||
| e0c88238da | |||
| b0e65e3980 | |||
| 648a5d2151 | |||
| 1a024eef96 | |||
| 6280e87078 | |||
| 64459ccdb3 | |||
| 38dc2efc6c | |||
| 390bffa208 | |||
| e034883abd | |||
| 6d4e8e7927 | |||
| 0f8939306d | |||
| 58675f0c69 | |||
| 88cafc7b8e | |||
| 485357c6dc |
@@ -1,12 +0,0 @@
|
||||
POSTGRES_DB=nexus
|
||||
POSTGRES_USER=nexus
|
||||
POSTGRES_PASSWORD=replace-with-a-strong-database-password
|
||||
JWT_KEY=replace-with-at-least-32-random-bytes
|
||||
OWNER_EMAIL=owner@example.com
|
||||
OWNER_PASSWORD=replace-with-at-least-14-characters
|
||||
OWNER_DISPLAY_NAME=Owner
|
||||
OPENCLAW_BASE_URL=http://host.docker.internal:18789
|
||||
OPENCLAW_GATEWAY_TOKEN=
|
||||
OPENCLAW_GATEWAY_PASSWORD=
|
||||
OLLAMA_BASE_URL=http://host.docker.internal:11434
|
||||
NVIDIA_API_KEY=
|
||||
+2
-4
@@ -15,10 +15,8 @@ JWT_KEY=*** # at least 32 bytes (base64-encoded)
|
||||
JWT_ISSUER=nexus
|
||||
JWT_AUDIENCE=nexus-web
|
||||
|
||||
# ── Owner Account ───────────────────────────────────────
|
||||
OWNER_EMAIL=***
|
||||
OWNER_PASSWORD=*** # at least 14 characters; leave empty for auto-generated
|
||||
OWNER_DISPLAY_NAME=*** # leave empty for auto-generated from email
|
||||
# ── Bootstrap Owner (first seed only) ───────────────────
|
||||
BOOTSTRAP_OWNER_EMAIL=***
|
||||
|
||||
# ── OpenClaw Integration ────────────────────────────────
|
||||
# Base URL of the OpenClaw gateway (host.docker.internal from inside container)
|
||||
|
||||
@@ -33,7 +33,7 @@ on:
|
||||
host_backup_path:
|
||||
description: 'Host path for backup (only if keep_on_host is true)'
|
||||
required: false
|
||||
default: '/opt/openclaw/backups'
|
||||
default: '/home/projekte_bao/openclaw/backups'
|
||||
type: string
|
||||
|
||||
# Optional: uncomment to enable nightly automatic backups
|
||||
@@ -47,7 +47,7 @@ jobs:
|
||||
env:
|
||||
ENV_TMPFILE: /tmp/nexus-backup-env
|
||||
ENV_POSTGRES_PASSWORD: ${{ secrets.ENV_POSTGRES_PASSWORD }}
|
||||
DEPLOY_PATH: /opt/openclaw/data/openclaw/workspace/nexus
|
||||
DEPLOY_PATH: /home/projekte_bao/openclaw/data/openclaw/workspace/nexus
|
||||
BACKUP_CONTAINER_NAME: nexus-postgres-1
|
||||
|
||||
steps:
|
||||
@@ -72,7 +72,7 @@ jobs:
|
||||
echo "🗄️ Dumping PostgreSQL cluster..."
|
||||
|
||||
docker exec "${BACKUP_CONTAINER_NAME}" \
|
||||
sh -c "PGPASSWORD='${ENV_POSTGRES_PASSWORD}' pg_dumpall -U nexus -h localhost" \
|
||||
sh -c "PGPASSWORD='${ENV_POSTGRES_PASSWORD}' pg_dumpall -U nexus" \
|
||||
| gzip > "${{ steps.meta.outputs.filename }}"
|
||||
|
||||
SIZE=$(du -h "${{ steps.meta.outputs.filename }}" | cut -f1)
|
||||
|
||||
@@ -51,7 +51,7 @@ jobs:
|
||||
- name: Setup pnpm
|
||||
run: |
|
||||
corepack enable
|
||||
corepack prepare pnpm@latest --activate
|
||||
corepack prepare pnpm@10.12.1 --activate
|
||||
|
||||
- name: Install dependencies
|
||||
run: pnpm install --frozen-lockfile
|
||||
|
||||
+91
-104
@@ -1,5 +1,5 @@
|
||||
name: Deploy to Production
|
||||
run-name: 🚀 Deploy by @${{ gitea.actor }}
|
||||
name: Deploy Nexus v2
|
||||
run-name: 🚀 Deploy v2 by @${{ gitea.actor }}
|
||||
|
||||
# ───────────────────────────────────────────────────────
|
||||
# Owner: DevOps (Architekt)
|
||||
@@ -7,7 +7,7 @@ run-name: 🚀 Deploy by @${{ gitea.actor }}
|
||||
#
|
||||
# Triggers:
|
||||
# 1. AUTOMATIC after successful CI on main (workflow_run)
|
||||
# → Uses safe defaults: patch bump, all services, main ref.
|
||||
# → Deploys main with the VERSION already present in the repo.
|
||||
# → Commits marked with [skip ci] are filtered at job level
|
||||
# (prevents version-bump loops).
|
||||
# 2. MANUAL via workflow_dispatch with full parameter control.
|
||||
@@ -15,12 +15,10 @@ run-name: 🚀 Deploy by @${{ gitea.actor }}
|
||||
# Concurrency: one deploy at a time.
|
||||
# Queued deploys wait — no race conditions with parallel builds.
|
||||
#
|
||||
# Version-Bump / CI Loop Prevention:
|
||||
# The version-bump commit includes "[skip ci]" in its message,
|
||||
# which Gitea Actions respects. The auto-trigger additionally
|
||||
# checks for "[skip ci]" as a second safety layer. Together
|
||||
# they guarantee that a version-bump commit does NOT trigger
|
||||
# another CI → Deploy → Bump → CI cycle.
|
||||
# Version Management:
|
||||
# The VERSION file in the repo root is the single source of truth.
|
||||
# Deploy only reads, validates, and logs the version.
|
||||
# Version changes happen before merge to main, not during deploy.
|
||||
# ───────────────────────────────────────────────────────
|
||||
concurrency:
|
||||
group: deploy-production
|
||||
@@ -35,31 +33,6 @@ on:
|
||||
|
||||
# ── Manual Trigger (full control) ──
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
version_bump:
|
||||
description: 'Version bump type'
|
||||
required: true
|
||||
default: 'patch'
|
||||
type: choice
|
||||
options:
|
||||
- patch
|
||||
- minor
|
||||
- major
|
||||
service:
|
||||
description: 'Service to deploy (empty = all)'
|
||||
required: false
|
||||
default: ''
|
||||
type: string
|
||||
no_cache:
|
||||
description: 'Disable Docker build cache'
|
||||
required: false
|
||||
default: false
|
||||
type: boolean
|
||||
git_ref:
|
||||
description: 'Git ref to deploy (branch, tag, or commit SHA; default: main)'
|
||||
required: false
|
||||
default: 'main'
|
||||
type: string
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
@@ -73,12 +46,13 @@ jobs:
|
||||
|
||||
# ── Env for the deploy target path ──
|
||||
env:
|
||||
DEPLOY_PATH: /opt/openclaw/data/openclaw/workspace/nexus
|
||||
DEPLOY_PATH: /home/projekte_bao/openclaw/data/openclaw/workspace/nexus
|
||||
ENV_TMPFILE: /tmp/nexus-deploy-env
|
||||
ENV_POSTGRES_PASSWORD: ${{ secrets.ENV_POSTGRES_PASSWORD }}
|
||||
ENV_JWT_KEY: ${{ secrets.ENV_JWT_KEY }}
|
||||
ENV_OWNER_PASSWORD: ${{ secrets.ENV_OWNER_PASSWORD }}
|
||||
ENV_OPENCLAW_TOKEN: ${{ secrets.ENV_OPENCLAW_TOKEN }}
|
||||
# Owner password is not injected at deploy time.
|
||||
# After first seed, the database is the only password source.
|
||||
|
||||
steps:
|
||||
# ═══════════════════════════════════════════════════
|
||||
@@ -87,7 +61,7 @@ jobs:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.git_ref || 'main' }}
|
||||
ref: main
|
||||
fetch-depth: 0
|
||||
fetch-tags: true
|
||||
|
||||
@@ -102,60 +76,39 @@ jobs:
|
||||
# ═══════════════════════════════════════════════════
|
||||
# Step 3: Resolve deploy version
|
||||
#
|
||||
# Deploying main: DevOps may bump VERSION and create a tag.
|
||||
# Deploying any other ref: deploy exactly that ref, but DO NOT
|
||||
# mutate main or create a version-bump commit on another branch.
|
||||
#
|
||||
# For auto-deploys (workflow_run): always "patch" bump on main.
|
||||
# Reads VERSION from repo root — the single source of truth.
|
||||
# Validates semver format, logs version + git metadata.
|
||||
# No git mutation: version bumps happen in the Dev workflow.
|
||||
# ═══════════════════════════════════════════════════
|
||||
- name: Resolve Version
|
||||
id: version
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
# Determine bump type (auto-deploy → patch; manual → user choice)
|
||||
BUMP_TYPE="${{ github.event_name == 'workflow_dispatch' && inputs.version_bump || 'patch' }}"
|
||||
|
||||
# Read current version
|
||||
# 1. Check VERSION exists
|
||||
if [ ! -f VERSION ]; then
|
||||
echo "❌ VERSION file not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
CURRENT=$(cat VERSION | tr -d '[:space:]')
|
||||
if ! echo "$CURRENT" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
|
||||
echo "❌ Invalid semver in VERSION: '$CURRENT'"
|
||||
# 2. Read and validate semver format
|
||||
VERSION=$(cat VERSION | tr -d '[:space:]')
|
||||
if ! echo "$VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
|
||||
echo "❌ Invalid semver in VERSION: '$VERSION'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
MAJOR=$(echo "$CURRENT" | cut -d. -f1)
|
||||
MINOR=$(echo "$CURRENT" | cut -d. -f2)
|
||||
PATCH=$(echo "$CURRENT" | cut -d. -f3)
|
||||
# 3. Log version, git ref, and describe
|
||||
GIT_REF=$(git rev-parse --short HEAD)
|
||||
GIT_DESCRIBE=$(git describe --always --dirty)
|
||||
|
||||
case "$BUMP_TYPE" in
|
||||
major) NEW_MAJOR=$((MAJOR + 1)); NEW_MINOR=0; NEW_PATCH=0 ;;
|
||||
minor) NEW_MAJOR=$MAJOR; NEW_MINOR=$((MINOR + 1)); NEW_PATCH=0 ;;
|
||||
patch) NEW_MAJOR=$MAJOR; NEW_MINOR=$MINOR; NEW_PATCH=$((PATCH + 1)) ;;
|
||||
*) echo "❌ Unknown bump type: $BUMP_TYPE"; exit 1 ;;
|
||||
esac
|
||||
echo "📦 Deploy version: v${VERSION}"
|
||||
echo "🔖 Git ref: ${GIT_REF}"
|
||||
echo "🏷️ Git describe: ${GIT_DESCRIBE}"
|
||||
|
||||
# Determine git ref — auto-deploy always uses main
|
||||
DEPLOY_REF="${{ github.event_name == 'workflow_dispatch' && inputs.git_ref || 'main' }}"
|
||||
if [ -z "$DEPLOY_REF" ] || [ "$DEPLOY_REF" = "main" ] || [ "$DEPLOY_REF" = "refs/heads/main" ]; then
|
||||
NEW_VERSION="${NEW_MAJOR}.${NEW_MINOR}.${NEW_PATCH}"
|
||||
echo "$NEW_VERSION" > VERSION
|
||||
git add VERSION
|
||||
git commit -m "chore: bump version to ${NEW_VERSION} [skip ci]"
|
||||
git tag -a "v${NEW_VERSION}" -m "Release v${NEW_VERSION}"
|
||||
git push origin HEAD:main --tags
|
||||
echo "version=$NEW_VERSION" >> "$GITEA_OUTPUT"
|
||||
echo "mutated_main=true" >> "$GITEA_OUTPUT"
|
||||
echo "📦 Main deploy: version $CURRENT -> v${NEW_VERSION} (bump: $BUMP_TYPE, trigger: ${{ github.event_name }})"
|
||||
else
|
||||
echo "version=$CURRENT" >> "$GITEA_OUTPUT"
|
||||
echo "mutated_main=false" >> "$GITEA_OUTPUT"
|
||||
echo "📦 Non-main deploy from '$DEPLOY_REF': using committed VERSION $CURRENT without git mutation"
|
||||
fi
|
||||
# 4. Set outputs for downstream steps
|
||||
echo "version=${VERSION}" >> "$GITEA_OUTPUT"
|
||||
echo "mutated_main=false" >> "$GITEA_OUTPUT"
|
||||
|
||||
# ═══════════════════════════════════════════════════
|
||||
# Step 4: Build .env from secrets (SAFE)
|
||||
@@ -164,6 +117,11 @@ jobs:
|
||||
# to a file inside the workspace that gets rsync'd to
|
||||
# the host. The temp file is deleted immediately after
|
||||
# compose operations complete.
|
||||
#
|
||||
# Owner password is deliberately omitted so production deploys
|
||||
# cannot overwrite the persisted DB password.
|
||||
# Other secrets (POSTGRES_PASSWORD, JWT_KEY, OPENCLAW_TOKEN)
|
||||
# come from Gitea secrets.
|
||||
# ═══════════════════════════════════════════════════
|
||||
- name: Prepare .env (secrets → temp file)
|
||||
run: |
|
||||
@@ -171,7 +129,7 @@ jobs:
|
||||
|
||||
cat > "${ENV_TMPFILE}" <<EOF
|
||||
# Nexus Production Environment — auto-generated by CD pipeline
|
||||
# Managed via Gitea Secrets → do NOT edit manually on the host.
|
||||
# Managed via Gitea Secrets → do NOT edit manually.
|
||||
# This file lives in /tmp and is removed after deploy completes.
|
||||
POSTGRES_DB=nexus
|
||||
POSTGRES_USER=nexus
|
||||
@@ -179,9 +137,7 @@ jobs:
|
||||
JWT_KEY=${ENV_JWT_KEY}
|
||||
JWT_ISSUER=nexus
|
||||
JWT_AUDIENCE=nexus-web
|
||||
OWNER_EMAIL=vmbao62@hotmail.de
|
||||
OWNER_PASSWORD=${ENV_OWNER_PASSWORD}
|
||||
OWNER_DISPLAY_NAME=
|
||||
BOOTSTRAP_OWNER_EMAIL=vmbao62@hotmail.de
|
||||
OPENCLAW_BASE_URL=http://host.docker.internal:18789
|
||||
OPENCLAW_GATEWAY_TOKEN=${ENV_OPENCLAW_TOKEN}
|
||||
OPENCLAW_GATEWAY_PASSWORD=
|
||||
@@ -223,35 +179,69 @@ jobs:
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
# Auto-deploy: always use cache. Manual: respect no_cache input.
|
||||
NO_CACHE="${{ github.event_name == 'workflow_dispatch' && inputs.no_cache || false }}"
|
||||
BUILD_ARGS=""
|
||||
if [ "$NO_CACHE" = "true" ]; then
|
||||
BUILD_ARGS="--no-cache"
|
||||
fi
|
||||
SERVICE_ARG=""
|
||||
|
||||
SERVICE_ARG="${{ github.event_name == 'workflow_dispatch' && inputs.service || '' }}"
|
||||
# Write the deploy script to a file to avoid nested quoting issues
|
||||
cat > /tmp/nexus-deploy-script.sh << 'DEPLOYSCRIPT'
|
||||
#!/bin/sh
|
||||
set -e
|
||||
trap 'rm -f /tmp/nexus-deploy-env' EXIT
|
||||
cat > /tmp/nexus-deploy-env
|
||||
|
||||
# ── Graceful shutdown (preserves DB volume integrity) ──
|
||||
docker compose --env-file /tmp/nexus-deploy-env stop postgres 2>/dev/null || true
|
||||
docker compose --env-file /tmp/nexus-deploy-env down --remove-orphans 2>/dev/null || true
|
||||
echo "Postgres volume preserved (nexus-postgres) — no WAL reset"
|
||||
|
||||
BUILD_ARGS="${DEPLOY_BUILD_ARGS:-}"
|
||||
SERVICE="${DEPLOY_SERVICE:-}"
|
||||
|
||||
if [ -n "$SERVICE" ]; then
|
||||
echo "Deploying service: $SERVICE"
|
||||
docker compose --env-file /tmp/nexus-deploy-env build $BUILD_ARGS $SERVICE
|
||||
docker compose --env-file /tmp/nexus-deploy-env up -d --force-recreate $SERVICE
|
||||
else
|
||||
echo 'Deploying all services'
|
||||
docker compose --env-file /tmp/nexus-deploy-env build $BUILD_ARGS
|
||||
docker compose --env-file /tmp/nexus-deploy-env up -d --force-recreate
|
||||
fi
|
||||
|
||||
echo 'Waiting for services to become healthy (up to 180s)...'
|
||||
for i in $(seq 1 36); do
|
||||
STATUS=$(docker compose --env-file /tmp/nexus-deploy-env ps -a 2>/dev/null | tail -n +2)
|
||||
if echo "$STATUS" | grep -q 'unhealthy'; then
|
||||
echo " [$i/36] Unhealthy containers - failing fast"
|
||||
docker compose --env-file /tmp/nexus-deploy-env ps -a
|
||||
docker compose --env-file /tmp/nexus-deploy-env logs --tail=30
|
||||
exit 1
|
||||
elif echo "$STATUS" | grep -q 'starting'; then
|
||||
echo " [$i/36] Still starting..."
|
||||
sleep 5
|
||||
else
|
||||
echo 'All containers healthy'
|
||||
docker compose --env-file /tmp/nexus-deploy-env ps -a
|
||||
exit 0
|
||||
fi
|
||||
done
|
||||
echo 'Timeout waiting for services'
|
||||
docker compose --env-file /tmp/nexus-deploy-env ps -a
|
||||
docker compose --env-file /tmp/nexus-deploy-env logs --tail=20
|
||||
exit 1
|
||||
DEPLOYSCRIPT
|
||||
|
||||
docker run --rm \
|
||||
-e "DEPLOY_BUILD_ARGS=${BUILD_ARGS:-}" \
|
||||
-e "DEPLOY_SERVICE=${SERVICE_ARG:-}" \
|
||||
-v "${DEPLOY_PATH}:/workspace/nexus" \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||
-v /tmp/nexus-deploy-script.sh:/deploy.sh:ro \
|
||||
-w /workspace/nexus \
|
||||
-i \
|
||||
docker:cli \
|
||||
sh -c "
|
||||
set -e
|
||||
trap 'rm -f /tmp/nexus-deploy-env' EXIT
|
||||
cat > /tmp/nexus-deploy-env
|
||||
if [ -n '${SERVICE_ARG}' ]; then
|
||||
echo '🚀 Deploying service: ${SERVICE_ARG}'
|
||||
docker compose --env-file /tmp/nexus-deploy-env build ${BUILD_ARGS} ${SERVICE_ARG}
|
||||
docker compose --env-file /tmp/nexus-deploy-env up -d --wait --force-recreate ${SERVICE_ARG}
|
||||
else
|
||||
echo '🚀 Deploying all services'
|
||||
docker compose --env-file /tmp/nexus-deploy-env build ${BUILD_ARGS}
|
||||
docker compose --env-file /tmp/nexus-deploy-env up -d --wait --force-recreate
|
||||
fi
|
||||
" < "${ENV_TMPFILE}"
|
||||
sh /deploy.sh < "${ENV_TMPFILE}"
|
||||
|
||||
rm -f /tmp/nexus-deploy-script.sh
|
||||
|
||||
echo "✅ Docker compose up completed"
|
||||
|
||||
@@ -334,17 +324,14 @@ jobs:
|
||||
if: always()
|
||||
run: |
|
||||
TRIGGER="${{ github.event_name == 'workflow_run' && 'Auto (CI success)' || 'Manual (workflow_dispatch)' }}"
|
||||
VERSION_BUMP="${{ github.event_name == 'workflow_dispatch' && inputs.version_bump || 'patch (auto)' }}"
|
||||
echo ""
|
||||
echo "═══════════════════════════════════════"
|
||||
echo " 📦 Deploy Summary"
|
||||
echo "═══════════════════════════════════════"
|
||||
echo " Version: v${{ steps.version.outputs.version }}"
|
||||
echo " Git ref: ${{ github.event_name == 'workflow_dispatch' && inputs.git_ref || 'main' }}"
|
||||
echo " Main bump: ${{ steps.version.outputs.mutated_main }}"
|
||||
echo " Service: ${{ github.event_name == 'workflow_dispatch' && inputs.service || 'all' }}"
|
||||
echo " Git ref: main"
|
||||
echo " Service: all"
|
||||
echo " Trigger: ${TRIGGER}"
|
||||
echo " Bump type: ${VERSION_BUMP}"
|
||||
echo " Actor: @${{ gitea.actor }}"
|
||||
echo " Status: ${{ job.status }}"
|
||||
echo "═══════════════════════════════════════"
|
||||
|
||||
@@ -18,9 +18,12 @@ run-name: 🔙 Rollback by @${{ gitea.actor }}
|
||||
# migrations). If the tag predates a destructive migration, manual
|
||||
# DB intervention is needed — that's an edge case surfaced to DevOps.
|
||||
# ───────────────────────────────────────────────────────
|
||||
# Rollback wins over queued/in-progress deploys.
|
||||
# It shares deploy-production with deploy.yaml so rollback and deploy never run together,
|
||||
# but cancel-in-progress=true prevents a queued auto-deploy from running after rollback.
|
||||
concurrency:
|
||||
group: deploy-production
|
||||
cancel-in-progress: false
|
||||
cancel-in-progress: true
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
@@ -39,11 +42,10 @@ jobs:
|
||||
name: Rollback Nexus
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
DEPLOY_PATH: /opt/openclaw/data/openclaw/workspace/nexus
|
||||
DEPLOY_PATH: /home/projekte_bao/openclaw/data/openclaw/workspace/nexus
|
||||
ENV_TMPFILE: /tmp/nexus-rollback-env
|
||||
ENV_POSTGRES_PASSWORD: ${{ secrets.ENV_POSTGRES_PASSWORD }}
|
||||
ENV_JWT_KEY: ${{ secrets.ENV_JWT_KEY }}
|
||||
ENV_OWNER_PASSWORD: ${{ secrets.ENV_OWNER_PASSWORD }}
|
||||
ENV_OPENCLAW_TOKEN: ${{ secrets.ENV_OPENCLAW_TOKEN }}
|
||||
|
||||
steps:
|
||||
@@ -109,9 +111,7 @@ jobs:
|
||||
JWT_KEY=${ENV_JWT_KEY}
|
||||
JWT_ISSUER=nexus
|
||||
JWT_AUDIENCE=nexus-web
|
||||
OWNER_EMAIL=vmbao62@hotmail.de
|
||||
OWNER_PASSWORD=${ENV_OWNER_PASSWORD}
|
||||
OWNER_DISPLAY_NAME=
|
||||
BOOTSTRAP_OWNER_EMAIL=vmbao62@hotmail.de
|
||||
OPENCLAW_BASE_URL=http://host.docker.internal:18789
|
||||
OPENCLAW_GATEWAY_TOKEN=${ENV_OPENCLAW_TOKEN}
|
||||
OPENCLAW_GATEWAY_PASSWORD=
|
||||
@@ -271,7 +271,7 @@ jobs:
|
||||
echo "│ Letzter bekannter funktionierender Stand: │"
|
||||
echo "│ → 'git log --oneline -5' zeigt letzte Commits │"
|
||||
echo "│ → Manuellen Rollback erwägen: │"
|
||||
echo "│ cd /opt/openclaw/data/openclaw/workspace/nexus │"
|
||||
echo "│ cd /home/projekte_bao/openclaw/data/openclaw/workspace/nexus │"
|
||||
echo "│ docker compose up -d (vorheriger Stand) │"
|
||||
echo "│ │"
|
||||
echo "└─────────────────────────────────────────────────────────────┘"
|
||||
|
||||
+7
-2
@@ -6,7 +6,6 @@
|
||||
|
||||
# Environment
|
||||
.env
|
||||
!.env.example
|
||||
!.env.template
|
||||
|
||||
# IDE
|
||||
@@ -30,7 +29,13 @@ docker-compose.override.yml
|
||||
*.tmp
|
||||
*.bak
|
||||
|
||||
# pnpm (lockfile IS committed for reproducible CI builds)
|
||||
# Crash artefacts / Core dumps
|
||||
**/core
|
||||
**/core.*
|
||||
|
||||
# pnpm / corepack local caches (lockfile IS committed for reproducible CI builds)
|
||||
frontend/.pnpm-home/
|
||||
frontend/.corepack-home/
|
||||
|
||||
# Claude local config (per-developer, not repo-shared)
|
||||
.claude/
|
||||
|
||||
@@ -3,10 +3,14 @@
|
||||
Nexus is the operations platform for the Noveria ecosystem. OpenClaw is an
|
||||
adapter-backed agent runtime, not a dependency of the frontend or domain model.
|
||||
|
||||
> 📋 **Architektur-Review** (2026-06-22): Board-first Orchestrierung, sichere
|
||||
> Backend-Brücke und Gateway-Integration geprüft. Siehe
|
||||
> [`docs/architecture-board-first-orchestration.md`](docs/architecture-board-first-orchestration.md)
|
||||
|
||||
> CI runs automatically on every push. CD can run **automatically after successful CI**
|
||||
> on main (patch-bump default) or can be triggered **manually** (workflow_dispatch) with
|
||||
> full parameter control. Main deploys bump/tag a release; arbitrary `git_ref` deploys
|
||||
> stay read-only. Rollback and database backup are separate manual workflows.
|
||||
> on main or can be triggered **manually** (workflow_dispatch). Deploy reads
|
||||
> `VERSION` but does not mutate Git or create tags. Rollback and database backup
|
||||
> are separate manual workflows.
|
||||
> See [phases/deployment.md](phases/deployment.md) for full CD documentation.
|
||||
|
||||
## Current foundation
|
||||
@@ -15,28 +19,26 @@ adapter-backed agent runtime, not a dependency of the frontend or domain model.
|
||||
- ASP.NET Core 10 REST API (Minimal API pattern)
|
||||
- Entity Framework Core and PostgreSQL
|
||||
- JWT owner authentication with rotating refresh sessions
|
||||
- `IAgentRuntime` abstraction with an OpenClaw adapter
|
||||
- `IModelProvider` abstractions for Ollama and NVIDIA
|
||||
- `IAgentRuntime` abstraction with an OpenClaw adapter (Ollama and NVIDIA removed — OpenClaw-only)
|
||||
- Responsive dark-mode operations dashboard
|
||||
- Container-only entry point on `127.0.0.1:18880`
|
||||
- Traefik reverse-proxy with Let's Encrypt TLS on `nexus.noveria.net`
|
||||
|
||||
## Local/container start
|
||||
|
||||
```bash
|
||||
cp .env.example .env
|
||||
# Replace every placeholder, especially POSTGRES_PASSWORD, JWT_KEY,
|
||||
# OWNER_EMAIL and OWNER_PASSWORD.
|
||||
cp .env.template .env
|
||||
# Replace every placeholder, especially POSTGRES_PASSWORD, JWT_KEY and BOOTSTRAP_OWNER_EMAIL.
|
||||
docker compose up --build -d
|
||||
curl http://127.0.0.1:18880/health
|
||||
```
|
||||
|
||||
On an empty database the API creates exactly one owner from `OWNER_EMAIL`,
|
||||
`OWNER_PASSWORD` and `OWNER_DISPLAY_NAME`. The password must contain at least 14
|
||||
characters. Existing databases are never overwritten by the bootstrap process.
|
||||
On an empty database the API creates exactly one owner from `BOOTSTRAP_OWNER_EMAIL`,
|
||||
derives the initial display name from that email, and logs a generated temporary password once.
|
||||
After first seed the password lives only in PostgreSQL. Existing databases are
|
||||
never overwritten by the bootstrap process.
|
||||
|
||||
The web service is loopback-only. Public reverse-proxy activation for
|
||||
`nexus.noveria.net` remains a separate infrastructure change and must terminate
|
||||
TLS before forwarding to port `18880`.
|
||||
The API is exposed via Traefik reverse-proxy with automatic Let's Encrypt TLS.
|
||||
Health checks, rate limiting, and security headers are active.
|
||||
|
||||
## Workspace mounts
|
||||
|
||||
@@ -45,12 +47,12 @@ and the config editor. These are mounted under `/mnt/workspace-{agentId}`:
|
||||
|
||||
| Host path | Container mount |
|
||||
|---|---|
|
||||
| `/opt/openclaw/data/openclaw/workspace-iris` | `/mnt/workspace-iris` |
|
||||
| `/opt/openclaw/data/openclaw/workspace-programmer` | `/mnt/workspace-programmer` |
|
||||
| `/opt/openclaw/data/openclaw/workspace-reviewer` | `/mnt/workspace-reviewer` |
|
||||
| `/opt/openclaw/data/openclaw/workspace-architekt` | `/mnt/workspace-architekt` |
|
||||
| `/opt/openclaw/data/openclaw/workspace-researcher` | `/mnt/workspace-researcher` |
|
||||
| `/opt/openclaw/data/openclaw/workspace-executor` | `/mnt/workspace-executor` |
|
||||
| `/home/projekte_bao/openclaw/data/openclaw/workspace-iris` | `/mnt/workspace-iris` |
|
||||
| `/home/projekte_bao/openclaw/data/openclaw/workspace-programmer` | `/mnt/workspace-programmer` |
|
||||
| `/home/projekte_bao/openclaw/data/openclaw/workspace-reviewer` | `/mnt/workspace-reviewer` |
|
||||
| `/home/projekte_bao/openclaw/data/openclaw/workspace-architekt` | `/mnt/workspace-architekt` |
|
||||
| `/home/projekte_bao/openclaw/data/openclaw/workspace-researcher` | `/mnt/workspace-researcher` |
|
||||
| `/home/projekte_bao/openclaw/data/openclaw/workspace-executor` | `/mnt/workspace-executor` |
|
||||
|
||||
## Frontend architecture
|
||||
|
||||
@@ -165,13 +167,45 @@ Legacy ModuleView routes (not standalone, rendered through `ModuleView.vue`):
|
||||
| Route | Name | Description |
|
||||
|---|---|---|
|
||||
| `/projects` | Projects | Project portfolio |
|
||||
| `/tasks` | Task Board | Task board |
|
||||
| `/tasks` | Task Board | Task board with visible parent/child agent flow |
|
||||
| `/models` | Models | Provider routing status |
|
||||
| `/activity` | Activity | Audit timeline |
|
||||
| `/chat` | Mobile Chat | Owner-chat preview |
|
||||
|
||||
## API endpoints
|
||||
|
||||
### Backend Bridge (Agent-zu-Backend, NICHT Frontend)
|
||||
|
||||
Der `/api/bridge/` Pfad ist ein strukturierter MCP-artiger Kommando-Adapter für die
|
||||
Agent-zu-Backend-Kommunikation. Kein Frontend-Code ruft diese Endpunkte auf.
|
||||
|
||||
Auth: `X-Agent-Id` Header, `X-Nexus-Api-Key`, oder JWT. Rate-Limited (30/min).
|
||||
|
||||
| Methode | Pfad | Kommando | Beschreibung |
|
||||
|---|---|---|---|
|
||||
| `GET` | `/api/bridge/health` | — | Bridge-Health-Check |
|
||||
| `POST` | `/api/bridge/tasks` | `create_task` | Neue Top-Level-Task erstellen |
|
||||
| `POST` | `/api/bridge/tasks/{id}/children` | `create_child_task` | Child-Task unter Parent erstellen |
|
||||
| `PATCH` | `/api/bridge/tasks/{id}/status` | `update_status` | Task-Status ändern |
|
||||
| `POST` | `/api/bridge/tasks/{id}/activity` | `append_activity` | Aktivitätseintrag anhängen |
|
||||
| `POST` | `/api/bridge/tasks/{id}/handoff` | `handoff` | Task an anderen Agent übergeben |
|
||||
| `GET` | `/api/bridge/board` | `get_board` | Vollständiges Task-Board |
|
||||
| `GET` | `/api/bridge/tasks/{id}` | `get_task` | Einzelne Task abrufen |
|
||||
| `GET` | `/api/bridge/tasks/{id}/children` | `get_children` | Child-Tasks abrufen |
|
||||
| `GET` | `/api/bridge/tasks/{id}/activity` | `get_activity` | Task-Aktivität abrufen |
|
||||
| `GET` | `/api/bridge/agent-overview` | `get_agent_overview` | Agent-Workflow-Übersicht |
|
||||
|
||||
Response-Format (TaskBridgeCommandResponse<T>):
|
||||
```json
|
||||
{
|
||||
"ok": true,
|
||||
"command": "create_task",
|
||||
"data": { ... },
|
||||
"error": null,
|
||||
"timestamp": "2026-06-22T15:30:00.000Z"
|
||||
}
|
||||
```
|
||||
|
||||
### Health & Auth (public or rate-limited)
|
||||
|
||||
| Method | Path | Auth | Description |
|
||||
@@ -191,6 +225,15 @@ Legacy ModuleView routes (not standalone, rendered through `ModuleView.vue`):
|
||||
|---|---|---|
|
||||
| `GET` | `/api/v1/operations/snapshot` | Full operations snapshot (runtime, agents, projects, tasks, activity, metrics) |
|
||||
|
||||
### Parent/Child task flow
|
||||
|
||||
The Task Board now models OpenClaw delegation as a visible parent/child flow:
|
||||
- Iris keeps the parent task `In progress` while delegated work is running.
|
||||
- Delegated agent work is represented as visible child tasks linked via `parentTaskId`.
|
||||
- Child tasks use the normal visible states (`Backlog`, `In progress`, `Review`, `Blocked`, `Done`) instead of a separate hidden delegation lane.
|
||||
- Agent progress hints on parent tasks derive from recent activity and child-task status summaries.
|
||||
- Full workflow documentation: [`docs/openclaw-task-board-flow.md`](docs/openclaw-task-board-flow.md)
|
||||
|
||||
### Projects
|
||||
|
||||
| Method | Path | Description |
|
||||
@@ -283,11 +326,16 @@ Backlog → Blocked → In progress / Done
|
||||
provider key. Conversation IDs are stable per browser and Iris is the default
|
||||
agent target.
|
||||
|
||||
The configured model-routing policy is:
|
||||
The configured model-routing policy routes through the OpenClaw Gateway only.
|
||||
Ollama and NVIDIA providers have been removed. Currently active models:
|
||||
|
||||
1. `qwen3:4b` through Ollama for routine and monitoring work
|
||||
2. `moonshotai/kimi-k2.6` through NVIDIA for primary work
|
||||
3. `gpt-5.5` through OpenClaw for strategic and critical review
|
||||
| Agent | Model |
|
||||
|-------|-------|
|
||||
| Iris | `openai/gpt-5.4` |
|
||||
| Programmer, Executor | `deepseek/deepseek-v4-flash` |
|
||||
| Reviewer, Architekt, Researcher | `deepseek/deepseek-v4-pro` |
|
||||
|
||||
Claude models (Sonnet 4.6, Opus 4.6/4.7/4.8) are available via `claude-cli` backend.
|
||||
|
||||
The Settings module reports runtime and provider state without exposing
|
||||
credentials.
|
||||
@@ -310,17 +358,15 @@ Deployment can happen automatically or manually:
|
||||
#### Auto-Deploy (after successful CI on main)
|
||||
|
||||
- Triggered by `workflow_run` after `CI - Build & Test` succeeds on `main`
|
||||
- Uses safe defaults: `patch` bump, all services, main ref
|
||||
- Skips automatically if the triggering commit contains `[skip ci]` (version-bump commits)
|
||||
- The version-bump commit itself uses `[skip ci]` → no infinite CI→Deploy→Bump→CI loops
|
||||
- Deploys the current `main` version after CI succeeds.
|
||||
- Skips automatically if the triggering commit contains `[skip ci]`
|
||||
- The deploy workflow reads `VERSION`; it does not mutate Git, bump versions, or create tags
|
||||
|
||||
#### Manual Deploy (`workflow_dispatch`)
|
||||
|
||||
1. DevOps triggers `Deploy to Production` in Gitea Actions
|
||||
2. Chooses version bump type: patch (default) / minor / major
|
||||
3. Optionally scopes to a single service or specific git ref
|
||||
4. Workflow bumps VERSION, creates git tag, builds and deploys
|
||||
5. Health check + smoke test verify the deployment
|
||||
1. DevOps triggers `Deploy Nexus v2` in Gitea Actions
|
||||
2. Workflow validates `VERSION`, builds and deploys `main`
|
||||
3. Health check + smoke test verify the deployment
|
||||
|
||||
#### Rollback (`workflow_dispatch`)
|
||||
|
||||
@@ -332,7 +378,7 @@ Deployment can happen automatically or manually:
|
||||
#### Database Backup (`workflow_dispatch`)
|
||||
|
||||
1. DevOps triggers `Database Backup` in Gitea Actions
|
||||
2. Optionally also copies backup to a host path (`/opt/openclaw/backups`)
|
||||
2. Optionally also copies backup to a host path (`/home/projekte_bao/backups`)
|
||||
3. Workflow dumps PostgreSQL via `pg_dumpall`, gzips, and uploads as a Gitea artifact
|
||||
4. Artifacts are retained for 90 days (configurable)
|
||||
5. Optional nightly schedule (uncomment the cron trigger in `backup.yaml`)
|
||||
|
||||
@@ -45,6 +45,94 @@ public class AgentServiceTests
|
||||
Assert.Null(agent);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetAllowedAgentIdsAsync_IncludesProductOwnerAndProgrammerFast()
|
||||
{
|
||||
var configPath = CreateAgentConfigFile();
|
||||
var config = CreateConfiguration(configPath);
|
||||
var runtime = new FakeRuntime();
|
||||
var service = new AgentService(config, runtime);
|
||||
|
||||
var ids = await service.GetAllowedAgentIdsAsync(CancellationToken.None);
|
||||
|
||||
Assert.Contains("product-owner", ids);
|
||||
Assert.Contains("programmer-fast", ids);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetAgentAsync_ProgrammerFast_UsesPrimaryModelAndDeveloperRole()
|
||||
{
|
||||
var configPath = CreateAgentConfigFile();
|
||||
var config = CreateConfiguration(configPath);
|
||||
var runtime = new FakeRuntime();
|
||||
var service = new AgentService(config, runtime);
|
||||
|
||||
var agent = await service.GetAgentAsync("programmer-fast", CancellationToken.None);
|
||||
|
||||
Assert.NotNull(agent);
|
||||
Assert.Equal("Developer", agent.Role);
|
||||
Assert.Equal("openai/gpt-5.3-codex-spark", agent.Model);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetAgentAsync_LegacyStringModel_IsSupported()
|
||||
{
|
||||
var configPath = CreateAgentConfigFile(
|
||||
"""
|
||||
{
|
||||
"agents": {
|
||||
"defaults": {
|
||||
"workspace": "/workspace/default",
|
||||
"model": "deepseek/deepseek-v4-flash"
|
||||
},
|
||||
"list": [
|
||||
{
|
||||
"id": "iris",
|
||||
"name": "iris",
|
||||
"model": "openai/gpt-5.5"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
""");
|
||||
var config = CreateConfiguration(configPath);
|
||||
var service = new AgentService(config, new FakeRuntime());
|
||||
|
||||
var agent = await service.GetAgentAsync("iris", CancellationToken.None);
|
||||
|
||||
Assert.NotNull(agent);
|
||||
Assert.Equal("openai/gpt-5.5", agent!.Model);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetAgentAsync_ObjectModel_InheritsStringDefaultModel()
|
||||
{
|
||||
var configPath = CreateAgentConfigFile(
|
||||
"""
|
||||
{
|
||||
"agents": {
|
||||
"defaults": {
|
||||
"workspace": "/workspace/default",
|
||||
"model": "openai/gpt-5.5-mini"
|
||||
},
|
||||
"list": [
|
||||
{
|
||||
"id": "reviewer",
|
||||
"name": "reviewer"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
""");
|
||||
var config = CreateConfiguration(configPath);
|
||||
var service = new AgentService(config, new FakeRuntime());
|
||||
|
||||
var agent = await service.GetAgentAsync("reviewer", CancellationToken.None);
|
||||
|
||||
Assert.NotNull(agent);
|
||||
Assert.Equal("openai/gpt-5.5-mini", agent!.Model);
|
||||
}
|
||||
|
||||
private static IConfiguration CreateConfiguration(string configPath)
|
||||
=> new ConfigurationBuilder()
|
||||
.AddInMemoryCollection(new Dictionary<string, string?>
|
||||
@@ -53,10 +141,10 @@ public class AgentServiceTests
|
||||
})
|
||||
.Build();
|
||||
|
||||
private static string CreateAgentConfigFile()
|
||||
private static string CreateAgentConfigFile(string? json = null)
|
||||
{
|
||||
var path = Path.Combine(Path.GetTempPath(), $"agent-config-{Guid.NewGuid():N}.json");
|
||||
File.WriteAllText(path,
|
||||
File.WriteAllText(path, json ??
|
||||
"""
|
||||
{
|
||||
"agents": {
|
||||
@@ -69,19 +157,33 @@ public class AgentServiceTests
|
||||
"list": [
|
||||
{
|
||||
"id": "iris",
|
||||
"name": "iris"
|
||||
"name": "iris",
|
||||
"model": { "primary": "openai/gpt-5.5" }
|
||||
},
|
||||
{
|
||||
"id": "product-owner",
|
||||
"name": "product-owner",
|
||||
"model": { "primary": "openai/gpt-5.5" }
|
||||
},
|
||||
{
|
||||
"id": "programmer",
|
||||
"name": "programmer"
|
||||
"name": "programmer",
|
||||
"model": { "primary": "openai/gpt-5.4" }
|
||||
},
|
||||
{
|
||||
"id": "programmer-fast",
|
||||
"name": "programmer-fast",
|
||||
"model": { "primary": "openai/gpt-5.3-codex-spark" }
|
||||
},
|
||||
{
|
||||
"id": "reviewer",
|
||||
"name": "reviewer"
|
||||
"name": "reviewer",
|
||||
"model": { "primary": "openai/gpt-5.5" }
|
||||
},
|
||||
{
|
||||
"id": "architekt",
|
||||
"name": "architekt"
|
||||
"name": "architekt",
|
||||
"model": { "primary": "openai/gpt-5.5" }
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,397 @@
|
||||
using System.Reflection;
|
||||
using System.Security.Claims;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
using Nexus.Api.Data;
|
||||
using Nexus.Api.DTOs;
|
||||
using Nexus.Api.Repositories;
|
||||
using Nexus.Api.Services;
|
||||
using Xunit;
|
||||
|
||||
namespace Nexus.Api.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Tests for AuthService login, change-password, admin-reset, and related flows.
|
||||
/// These are unit-level tests using an in-memory EF Core database so no
|
||||
/// external PostgreSQL instance is needed.
|
||||
/// </summary>
|
||||
public sealed class AuthServiceTests
|
||||
{
|
||||
// ── Fixture helpers ─────────────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// Creates a test fixture with an in-memory database, a UserRepository,
|
||||
/// and an AuthService backed by an in-memory configuration.
|
||||
/// </summary>
|
||||
private static (NexusDbContext db, IUserRepository repo, AuthService auth) CreateFixture()
|
||||
{
|
||||
var options = new DbContextOptionsBuilder<NexusDbContext>()
|
||||
.UseInMemoryDatabase(Guid.NewGuid().ToString())
|
||||
.Options;
|
||||
|
||||
var db = new NexusDbContext(options);
|
||||
var repo = new UserRepository(db);
|
||||
|
||||
// In-memory config with minimum required JWT settings
|
||||
var config = new MemoryConfig(new Dictionary<string, string?>
|
||||
{
|
||||
["Jwt:Key"] = "this-is-a-test-key-that-is-at-least-32-bytes-long!",
|
||||
["Jwt:Issuer"] = "nexus-test",
|
||||
["Jwt:Audience"] = "nexus-test-web",
|
||||
});
|
||||
|
||||
var logger = Microsoft.Extensions.Logging.Abstractions.NullLogger<AuthService>.Instance;
|
||||
var auth = new AuthService(repo, config, logger);
|
||||
return (db, repo, auth);
|
||||
}
|
||||
|
||||
private static LoginRequest Login(string email, string password)
|
||||
=> new() { Email = email, Password = password };
|
||||
|
||||
private static async Task<NexusUser> SeedUserAsync(NexusDbContext db, string email, string password, string role = "user")
|
||||
{
|
||||
var user = new NexusUser
|
||||
{
|
||||
Email = email,
|
||||
NormalizedEmail = AuthService.NormalizeEmail(email),
|
||||
DisplayName = email.Split('@')[0],
|
||||
PasswordHash = PasswordSecurity.Hash(password),
|
||||
Role = role
|
||||
};
|
||||
db.Users.Add(user);
|
||||
await db.SaveChangesAsync();
|
||||
return user;
|
||||
}
|
||||
|
||||
// ══════════════════════════════════════════════════════════════════
|
||||
// Password Security Unit Tests
|
||||
// ══════════════════════════════════════════════════════════════════
|
||||
|
||||
[Fact]
|
||||
public void Hash_And_Verify_RoundTrip_Succeeds()
|
||||
{
|
||||
const string password = "MyTestPassword123!";
|
||||
var hash = PasswordSecurity.Hash(password);
|
||||
Assert.NotNull(hash);
|
||||
Assert.StartsWith("v1.", hash);
|
||||
|
||||
var ok = PasswordSecurity.Verify(password, hash, out var needsUpgrade);
|
||||
Assert.True(ok);
|
||||
Assert.False(needsUpgrade);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Verify_WrongPassword_Fails()
|
||||
{
|
||||
var hash = PasswordSecurity.Hash("CorrectPassword123!");
|
||||
Assert.False(PasswordSecurity.Verify("WrongPassword456!", hash, out _));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Verify_EmptyHash_ReturnsFalse()
|
||||
{
|
||||
Assert.False(PasswordSecurity.Verify("password", "", out _));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Verify_LegacySha256_PassesAndFlagsUpgrade()
|
||||
{
|
||||
const string password = "OldFormatPassword123!";
|
||||
var legacyHash = Convert.ToHexString(
|
||||
System.Security.Cryptography.SHA256.HashData(
|
||||
System.Text.Encoding.UTF8.GetBytes(password)));
|
||||
|
||||
var ok = PasswordSecurity.Verify(password, legacyHash, out var needsUpgrade);
|
||||
Assert.True(ok);
|
||||
Assert.True(needsUpgrade);
|
||||
}
|
||||
|
||||
// ══════════════════════════════════════════════════════════════════
|
||||
// Login Tests
|
||||
// ══════════════════════════════════════════════════════════════════
|
||||
|
||||
[Fact]
|
||||
public async Task Login_WithValidCredentials_Succeeds()
|
||||
{
|
||||
var (db, repo, auth) = CreateFixture();
|
||||
const string password = "ValidPassword123!";
|
||||
await SeedUserAsync(db, "test@example.com", password);
|
||||
|
||||
var session = await auth.LoginAsync(Login("test@example.com", password));
|
||||
Assert.NotNull(session);
|
||||
Assert.Equal("test", session.User.DisplayName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Login_WithWrongPassword_ReturnsNull()
|
||||
{
|
||||
var (db, repo, auth) = CreateFixture();
|
||||
await SeedUserAsync(db, "test@example.com", "CorrectPassword123!");
|
||||
|
||||
Assert.Null(await auth.LoginAsync(Login("test@example.com", "WrongPassword456!")));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Login_WithNonexistentEmail_ReturnsNull()
|
||||
{
|
||||
var (db, repo, auth) = CreateFixture();
|
||||
Assert.Null(await auth.LoginAsync(Login("nobody@example.com", "SomePassword123!")));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Login_UpdatesLastLoginAt()
|
||||
{
|
||||
var (db, repo, auth) = CreateFixture();
|
||||
const string password = "TestPassword123!";
|
||||
var user = await SeedUserAsync(db, "test@example.com", password);
|
||||
|
||||
var beforeLogin = user.LastLoginAt;
|
||||
await Task.Delay(10);
|
||||
|
||||
Assert.NotNull(await auth.LoginAsync(Login("test@example.com", password)));
|
||||
|
||||
var updated = await repo.GetByIdAsync(user.Id);
|
||||
Assert.NotNull(updated!.LastLoginAt);
|
||||
Assert.True(updated.LastLoginAt > beforeLogin || beforeLogin is null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates that LoginAsync persists a password hash upgrade AND login
|
||||
/// timestamps even when there are NO expired refresh tokens. Previously
|
||||
/// the code relied on RemoveExpiredTokensAsync calling SaveChangesAsync,
|
||||
/// but that only happens when oldTokens.Count > 0.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task Login_WithLegacyHash_UpgradesAndPersistsWithoutExpiredTokens()
|
||||
{
|
||||
var (db, repo, auth) = CreateFixture();
|
||||
const string password = "LegacyUpgradePassword123!";
|
||||
|
||||
var legacyHash = Convert.ToHexString(
|
||||
System.Security.Cryptography.SHA256.HashData(
|
||||
System.Text.Encoding.UTF8.GetBytes(password)));
|
||||
|
||||
var user = new NexusUser
|
||||
{
|
||||
Email = "legacy@example.com",
|
||||
NormalizedEmail = AuthService.NormalizeEmail("legacy@example.com"),
|
||||
DisplayName = "Legacy",
|
||||
PasswordHash = legacyHash,
|
||||
Role = "user"
|
||||
};
|
||||
db.Users.Add(user);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
// Login triggers hash upgrade
|
||||
Assert.NotNull(await auth.LoginAsync(Login("legacy@example.com", password)));
|
||||
|
||||
var updated = await repo.GetByIdAsync(user.Id);
|
||||
Assert.NotNull(updated);
|
||||
Assert.StartsWith("v1.", updated.PasswordHash);
|
||||
Assert.NotEqual(legacyHash, updated.PasswordHash);
|
||||
|
||||
// Second login with the upgraded hash should also work
|
||||
Assert.NotNull(await auth.LoginAsync(Login("legacy@example.com", password)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Login_WithExistingHash_DoesNotChangeHash()
|
||||
{
|
||||
var (db, repo, auth) = CreateFixture();
|
||||
const string password = "StablePassword123!";
|
||||
var user = await SeedUserAsync(db, "stable@example.com", password);
|
||||
|
||||
var originalHash = user.PasswordHash;
|
||||
Assert.NotNull(await auth.LoginAsync(Login("stable@example.com", password)));
|
||||
|
||||
var updated = await repo.GetByIdAsync(user.Id);
|
||||
Assert.NotNull(updated);
|
||||
Assert.Equal(originalHash, updated.PasswordHash);
|
||||
}
|
||||
|
||||
// ══════════════════════════════════════════════════════════════════
|
||||
// Change Password Tests
|
||||
// ══════════════════════════════════════════════════════════════════
|
||||
|
||||
[Fact]
|
||||
public async Task ChangePassword_WithCorrectCurrentPassword_Succeeds()
|
||||
{
|
||||
var (db, repo, auth) = CreateFixture();
|
||||
const string oldPw = "OldPassword123!";
|
||||
const string newPw = "NewPassword456!";
|
||||
var user = await SeedUserAsync(db, "changepw@example.com", oldPw);
|
||||
|
||||
var result = await auth.ChangePasswordAsync(user.Id, new ChangePasswordRequest
|
||||
{
|
||||
CurrentPassword = oldPw,
|
||||
NewPassword = newPw
|
||||
});
|
||||
Assert.True(result);
|
||||
|
||||
Assert.Null(await auth.LoginAsync(Login("changepw@example.com", oldPw)));
|
||||
Assert.NotNull(await auth.LoginAsync(Login("changepw@example.com", newPw)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ChangePassword_WithWrongCurrentPassword_Fails()
|
||||
{
|
||||
var (db, repo, auth) = CreateFixture();
|
||||
var user = await SeedUserAsync(db, "wrongpw@example.com", "ActualPassword123!");
|
||||
|
||||
Assert.False(await auth.ChangePasswordAsync(user.Id, new ChangePasswordRequest
|
||||
{
|
||||
CurrentPassword = "WrongPassword456!",
|
||||
NewPassword = "NewPassword789!"
|
||||
}));
|
||||
}
|
||||
|
||||
// ══════════════════════════════════════════════════════════════════
|
||||
// Admin Reset Password Tests
|
||||
// ══════════════════════════════════════════════════════════════════
|
||||
|
||||
[Fact]
|
||||
public async Task AdminResetPassword_WithValidToken_Succeeds()
|
||||
{
|
||||
var (db, repo, auth) = CreateFixture();
|
||||
Environment.SetEnvironmentVariable("Admin__ResetToken", "test-admin-token-123");
|
||||
|
||||
const string oldPw = "OldPassword123!";
|
||||
const string newPw = "NewAdminPassword456!";
|
||||
await SeedUserAsync(db, "adminreset@example.com", oldPw);
|
||||
|
||||
Assert.True(await auth.AdminResetPasswordAsync("adminreset@example.com", newPw, "test-admin-token-123"));
|
||||
Assert.Null(await auth.LoginAsync(Login("adminreset@example.com", oldPw)));
|
||||
Assert.NotNull(await auth.LoginAsync(Login("adminreset@example.com", newPw)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AdminResetPassword_WithInvalidToken_Fails()
|
||||
{
|
||||
var (db, repo, auth) = CreateFixture();
|
||||
Environment.SetEnvironmentVariable("Admin__ResetToken", "real-token-xyz");
|
||||
await SeedUserAsync(db, "badreset@example.com", "OriginalPassword123!");
|
||||
|
||||
Assert.False(await auth.AdminResetPasswordAsync("badreset@example.com", "NewPassword456!", "wrong-token"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AdminResetPassword_NonexistentUser_Fails()
|
||||
{
|
||||
var (db, repo, auth) = CreateFixture();
|
||||
Environment.SetEnvironmentVariable("Admin__ResetToken", "test-token");
|
||||
Assert.False(await auth.AdminResetPasswordAsync("nobody@example.com", "NewPassword456!", "test-token"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AdminResetPassword_ShortPassword_Fails()
|
||||
{
|
||||
var (db, repo, auth) = CreateFixture();
|
||||
Environment.SetEnvironmentVariable("Admin__ResetToken", "test-token");
|
||||
Assert.False(await auth.AdminResetPasswordAsync("test@example.com", "short", "test-token"));
|
||||
}
|
||||
|
||||
// ══════════════════════════════════════════════════════════════════
|
||||
// Profile Update Tests
|
||||
// ══════════════════════════════════════════════════════════════════
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateProfile_ChangesDisplayName()
|
||||
{
|
||||
var (db, repo, auth) = CreateFixture();
|
||||
const string password = "Password123!";
|
||||
var user = await SeedUserAsync(db, "profile@example.com", password);
|
||||
|
||||
var updated = await auth.UpdateProfileAsync(user.Id, new UpdateProfileRequest
|
||||
{
|
||||
DisplayName = "New Name"
|
||||
});
|
||||
Assert.NotNull(updated);
|
||||
Assert.Equal("New Name", updated.DisplayName);
|
||||
}
|
||||
|
||||
// ══════════════════════════════════════════════════════════════════
|
||||
// NormalizeEmail
|
||||
// ══════════════════════════════════════════════════════════════════
|
||||
|
||||
[Fact]
|
||||
public void NormalizeEmail_TrimsAndUppercases()
|
||||
{
|
||||
Assert.Equal("TEST@EXAMPLE.COM", AuthService.NormalizeEmail(" test@Example.com "));
|
||||
Assert.Equal("A@B.COM", AuthService.NormalizeEmail("a@b.com"));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Minimal in-memory IConfiguration implementation for unit tests.
|
||||
/// Reads from a case-insensitive dictionary.
|
||||
/// </summary>
|
||||
internal sealed class MemoryConfig : Microsoft.Extensions.Configuration.IConfiguration
|
||||
{
|
||||
private readonly Dictionary<string, string?> _data;
|
||||
private readonly Dictionary<string, MemoryConfigSection> _sections;
|
||||
|
||||
public MemoryConfig(Dictionary<string, string?> data)
|
||||
{
|
||||
_data = new Dictionary<string, string?>(data, StringComparer.OrdinalIgnoreCase);
|
||||
_sections = new Dictionary<string, MemoryConfigSection>(StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
public string? this[string key]
|
||||
{
|
||||
get => _data.TryGetValue(key, out var val) ? val : null;
|
||||
set => _data[key] = value ?? string.Empty;
|
||||
}
|
||||
|
||||
public Microsoft.Extensions.Configuration.IConfigurationSection GetSection(string key)
|
||||
{
|
||||
if (!_sections.TryGetValue(key, out var section))
|
||||
{
|
||||
section = new MemoryConfigSection(key, this);
|
||||
_sections[key] = section;
|
||||
}
|
||||
return section;
|
||||
}
|
||||
|
||||
public IEnumerable<Microsoft.Extensions.Configuration.IConfigurationSection> GetChildren()
|
||||
=> Enumerable.Empty<Microsoft.Extensions.Configuration.IConfigurationSection>();
|
||||
|
||||
public IChangeToken GetReloadToken()
|
||||
=> NeverToken.Instance;
|
||||
}
|
||||
|
||||
internal sealed class MemoryConfigSection(string path, MemoryConfig root) : Microsoft.Extensions.Configuration.IConfigurationSection
|
||||
{
|
||||
public string Key => path.Split(':').Last();
|
||||
public string Path => path;
|
||||
public string? Value { get => root[path]; set => root[path] = value; }
|
||||
|
||||
public string? this[string key]
|
||||
{
|
||||
get => root[$"{path}:{key}"];
|
||||
set => root[$"{path}:{key}"] = value;
|
||||
}
|
||||
|
||||
public Microsoft.Extensions.Configuration.IConfigurationSection GetSection(string key)
|
||||
=> root.GetSection($"{path}:{key}");
|
||||
|
||||
public IEnumerable<Microsoft.Extensions.Configuration.IConfigurationSection> GetChildren()
|
||||
=> Enumerable.Empty<Microsoft.Extensions.Configuration.IConfigurationSection>();
|
||||
|
||||
public IChangeToken GetReloadToken()
|
||||
=> NeverToken.Instance;
|
||||
}
|
||||
|
||||
/// <summary>A change token that never signals — for test-use IConfiguration stubs.</summary>
|
||||
internal sealed class NeverToken : IChangeToken
|
||||
{
|
||||
public static readonly NeverToken Instance = new();
|
||||
public bool HasChanged => false;
|
||||
public bool ActiveChangeCallbacks => false;
|
||||
public IDisposable RegisterChangeCallback(Action<object?> callback, object? state) => NoopDisposable.Instance;
|
||||
}
|
||||
|
||||
internal sealed class NoopDisposable : IDisposable
|
||||
{
|
||||
public static readonly NoopDisposable Instance = new();
|
||||
public void Dispose() { }
|
||||
}
|
||||
@@ -9,6 +9,9 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.8" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="10.0.8" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="10.0.8" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.0">
|
||||
|
||||
@@ -109,6 +109,9 @@ internal sealed class GuardedActivityRepository(RepositoryConcurrencyGuard guard
|
||||
new() { Id = 1, Type = "agent", Message = "recent activity", CreatedAt = DateTimeOffset.UtcNow }
|
||||
}, ct);
|
||||
|
||||
public Task<List<ActivityEvent>> GetRecentForTasksAsync(IEnumerable<Guid> taskIds, CancellationToken ct = default)
|
||||
=> guard.RunAsync(new List<ActivityEvent>(), ct);
|
||||
|
||||
public Task<(List<ActivityEvent> Items, int TotalCount)> GetPagedAsync(string? type, string? sort, int page, int pageSize, CancellationToken ct = default)
|
||||
=> throw new NotSupportedException();
|
||||
|
||||
@@ -140,4 +143,7 @@ internal sealed class SnapshotAgentServiceStub : IAgentService
|
||||
|
||||
public Task<AgentDetail?> GetAgentAsync(string id, CancellationToken cancellationToken)
|
||||
=> throw new NotSupportedException();
|
||||
|
||||
public Task<IReadOnlySet<string>> GetAllowedAgentIdsAsync(CancellationToken cancellationToken)
|
||||
=> Task.FromResult<IReadOnlySet<string>>(new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "iris" });
|
||||
}
|
||||
|
||||
@@ -0,0 +1,245 @@
|
||||
using Nexus.Api.Data;
|
||||
using Xunit;
|
||||
|
||||
namespace Nexus.Api.Tests;
|
||||
|
||||
public class TaskBoardTests
|
||||
{
|
||||
// ── TaskStateHelper: BoardGroupKey ──
|
||||
|
||||
[Theory]
|
||||
[InlineData("Backlog", "offen")]
|
||||
[InlineData("In progress", "inProgress")]
|
||||
[InlineData("Review", "review")]
|
||||
[InlineData("Blocked", "blocked")]
|
||||
[InlineData("Done", "done")]
|
||||
[InlineData("backlog", "offen")]
|
||||
[InlineData("in progress", "inProgress")]
|
||||
[InlineData("review", "review")]
|
||||
[InlineData("blocked", "blocked")]
|
||||
[InlineData("done", "done")]
|
||||
[InlineData("", "offen")]
|
||||
[InlineData(null, "offen")]
|
||||
[InlineData("unknown", "offen")]
|
||||
public void BoardGroupKey_ReturnsExpectedGroup(string? state, string expected)
|
||||
{
|
||||
var result = TaskStateHelper.BoardGroupKey(state);
|
||||
Assert.Equal(expected, result);
|
||||
}
|
||||
|
||||
// ── TaskStateHelper: BoardGroupToState ──
|
||||
|
||||
[Theory]
|
||||
[InlineData("offen", "Backlog")]
|
||||
[InlineData("inProgress", "In progress")]
|
||||
[InlineData("inprogress", "In progress")]
|
||||
[InlineData("review", "Review")]
|
||||
[InlineData("blocked", "Blocked")]
|
||||
[InlineData("done", "Done")]
|
||||
[InlineData("Offen", "Backlog")]
|
||||
[InlineData("", null)]
|
||||
[InlineData(null, null)]
|
||||
[InlineData("unknown", null)]
|
||||
public void BoardGroupToState_ReturnsExpectedState(string? groupKey, string? expected)
|
||||
{
|
||||
var result = TaskStateHelper.BoardGroupToState(groupKey);
|
||||
Assert.Equal(expected, result);
|
||||
}
|
||||
|
||||
// ── TaskStateHelper: AllStates has 5 entries ──
|
||||
|
||||
[Fact]
|
||||
public void AllStates_ContainsAllFiveStates()
|
||||
{
|
||||
var states = TaskStateHelper.AllStates;
|
||||
Assert.Equal(5, states.Length);
|
||||
Assert.Contains("Backlog", states);
|
||||
Assert.Contains("In progress", states);
|
||||
Assert.Contains("Review", states);
|
||||
Assert.Contains("Blocked", states);
|
||||
Assert.Contains("Done", states);
|
||||
}
|
||||
|
||||
// ── TaskStateHelper: IsValidState ──
|
||||
|
||||
[Theory]
|
||||
[InlineData("Backlog", true)]
|
||||
[InlineData("In progress", true)]
|
||||
[InlineData("Review", true)]
|
||||
[InlineData("Blocked", true)]
|
||||
[InlineData("Done", true)]
|
||||
[InlineData("backlog", true)]
|
||||
[InlineData("offen", false)]
|
||||
[InlineData("", false)]
|
||||
[InlineData(null, false)]
|
||||
[InlineData("unknown", false)]
|
||||
public void IsValidState_ReturnsCorrectResult(string? state, bool expected)
|
||||
{
|
||||
Assert.Equal(expected, TaskStateHelper.IsValidState(state));
|
||||
}
|
||||
|
||||
// ── TaskStateHelper: IsInProgressOrBlocked ──
|
||||
|
||||
[Theory]
|
||||
[InlineData("In progress", true)]
|
||||
[InlineData("Blocked", true)]
|
||||
[InlineData("Backlog", false)]
|
||||
[InlineData("Review", false)]
|
||||
[InlineData("Done", false)]
|
||||
[InlineData(null, false)]
|
||||
public void IsInProgressOrBlocked_ReturnsCorrectResult(string? state, bool expected)
|
||||
{
|
||||
Assert.Equal(expected, TaskStateHelper.IsInProgressOrBlocked(state));
|
||||
}
|
||||
|
||||
// ── TaskStateHelper: IsDoneOrBacklog ──
|
||||
|
||||
[Theory]
|
||||
[InlineData("Done", true)]
|
||||
[InlineData("Backlog", true)]
|
||||
[InlineData("In progress", false)]
|
||||
[InlineData("Review", false)]
|
||||
[InlineData("Blocked", false)]
|
||||
[InlineData(null, false)]
|
||||
public void IsDoneOrBacklog_ReturnsCorrectResult(string? state, bool expected)
|
||||
{
|
||||
Assert.Equal(expected, TaskStateHelper.IsDoneOrBacklog(state));
|
||||
}
|
||||
|
||||
// ── TaskStateHelper: ToDisplayString ──
|
||||
|
||||
[Theory]
|
||||
[InlineData("Backlog", "Offen")]
|
||||
[InlineData("In progress", "In Bearbeitung")]
|
||||
[InlineData("Review", "Review")]
|
||||
[InlineData("Blocked", "Blockiert")]
|
||||
[InlineData("Done", "Erledigt")]
|
||||
[InlineData("backlog", "Offen")]
|
||||
[InlineData("", "")]
|
||||
[InlineData(null, "")]
|
||||
[InlineData("unknown", "unknown")]
|
||||
public void ToDisplayString_ReturnsGermanLabel(string? state, string expected)
|
||||
{
|
||||
Assert.Equal(expected, TaskStateHelper.ToDisplayString(state));
|
||||
}
|
||||
|
||||
// ── TaskState helper: ToStateString and ToTaskState roundtrip ──
|
||||
|
||||
[Fact]
|
||||
public void ToStateString_And_ToTaskState_RoundTrip()
|
||||
{
|
||||
var states = new[] { TaskState.Backlog, TaskState.InProgress, TaskState.Review, TaskState.Blocked, TaskState.Done };
|
||||
foreach (var state in states)
|
||||
{
|
||||
var str = state.ToStateString();
|
||||
var parsed = str.ToTaskState();
|
||||
Assert.Equal(state, parsed);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToTaskState_DefaultsToBacklog_ForUnknownString()
|
||||
{
|
||||
Assert.Equal(TaskState.Backlog, "unknown".ToTaskState());
|
||||
}
|
||||
|
||||
// ── TaskStateHelper: CanChangeState (Iris + Bao policy) ──
|
||||
|
||||
[Fact]
|
||||
public void CanChangeState_Iris_CanChangeAnyTask()
|
||||
{
|
||||
var agentTask = new WorkTask { Title = "test", IsAgentTask = true, Source = "iris" };
|
||||
var normalTask = new WorkTask { Title = "test", IsAgentTask = false, Source = "bao" };
|
||||
|
||||
Assert.True(TaskStateHelper.CanChangeState("iris", agentTask));
|
||||
Assert.True(TaskStateHelper.CanChangeState("iris", normalTask));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanChangeState_Bao_CanChangeAnyTask()
|
||||
{
|
||||
var agentTask = new WorkTask { Title = "test", IsAgentTask = true, Source = "iris" };
|
||||
var normalTask = new WorkTask { Title = "test", IsAgentTask = false, Source = "bao" };
|
||||
|
||||
Assert.True(TaskStateHelper.CanChangeState("bao", agentTask));
|
||||
Assert.True(TaskStateHelper.CanChangeState("bao", normalTask));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanChangeState_SubAgents_NeverAllowed()
|
||||
{
|
||||
var task = new WorkTask { Title = "test", IsAgentTask = false, Source = "bao" };
|
||||
|
||||
Assert.False(TaskStateHelper.CanChangeState("programmer", task));
|
||||
Assert.False(TaskStateHelper.CanChangeState("reviewer", task));
|
||||
Assert.False(TaskStateHelper.CanChangeState("architekt", task));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanChangeState_SubAgents_NeverAllowed_EvenForAgentTasks()
|
||||
{
|
||||
var agentTask = new WorkTask { Title = "test", IsAgentTask = true, Source = "iris" };
|
||||
|
||||
Assert.False(TaskStateHelper.CanChangeState("programmer", agentTask));
|
||||
Assert.False(TaskStateHelper.CanChangeState("reviewer", agentTask));
|
||||
Assert.False(TaskStateHelper.CanChangeState("architekt", agentTask));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanChangeState_NexusSystem_IsAllowed()
|
||||
{
|
||||
var task = new WorkTask { Title = "test", IsAgentTask = false };
|
||||
Assert.True(TaskStateHelper.CanChangeState("nexus-system", task));
|
||||
|
||||
var agentTask = new WorkTask { Title = "test", IsAgentTask = true };
|
||||
Assert.True(TaskStateHelper.CanChangeState("nexus-system", agentTask));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanChangeState_UnknownCaller_Rejected()
|
||||
{
|
||||
var task = new WorkTask { Title = "test", IsAgentTask = false };
|
||||
var agentTask = new WorkTask { Title = "test", IsAgentTask = true };
|
||||
|
||||
Assert.False(TaskStateHelper.CanChangeState("", task));
|
||||
Assert.False(TaskStateHelper.CanChangeState("", agentTask));
|
||||
Assert.False(TaskStateHelper.CanChangeState("unknown", task));
|
||||
Assert.False(TaskStateHelper.CanChangeState(null, task));
|
||||
}
|
||||
|
||||
// ── TaskStateHelper: CanEditContent ──
|
||||
|
||||
[Fact]
|
||||
public void CanEditContent_Iris_IsAllowed()
|
||||
{
|
||||
Assert.True(TaskStateHelper.CanEditContent("iris"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanEditContent_Bao_IsAllowed()
|
||||
{
|
||||
Assert.True(TaskStateHelper.CanEditContent("bao"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanEditContent_SubAgents_AreAllowed()
|
||||
{
|
||||
Assert.True(TaskStateHelper.CanEditContent("programmer"));
|
||||
Assert.True(TaskStateHelper.CanEditContent("reviewer"));
|
||||
Assert.True(TaskStateHelper.CanEditContent("architekt"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanEditContent_NexusSystem_IsAllowed()
|
||||
{
|
||||
Assert.True(TaskStateHelper.CanEditContent("nexus-system"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanEditContent_UnknownCaller_Rejected()
|
||||
{
|
||||
Assert.False(TaskStateHelper.CanEditContent(""));
|
||||
Assert.False(TaskStateHelper.CanEditContent(null));
|
||||
Assert.False(TaskStateHelper.CanEditContent(" "));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,548 @@
|
||||
using System.Security.Claims;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using Nexus.Api.Controllers;
|
||||
using Nexus.Api.Data;
|
||||
using Nexus.Api.Models;
|
||||
using Nexus.Api.Repositories;
|
||||
using Nexus.Api.Services;
|
||||
using Xunit;
|
||||
|
||||
namespace Nexus.Api.Tests;
|
||||
|
||||
public sealed class TaskWorkflowTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task CreateAgentTaskAsync_PreservesConfiguredAssigneeAndBacklogState_WhenPlannedChildTask()
|
||||
{
|
||||
await using var fixture = await TaskWorkflowFixture.CreateAsync();
|
||||
|
||||
var parent = await fixture.TaskService.CreateDashboardTaskAsync(
|
||||
"Parent", "Coordination", "iris", "High", "iris", null, CancellationToken.None);
|
||||
|
||||
var child = await fixture.TaskService.CreateAgentTaskAsync(
|
||||
"PO spec",
|
||||
"Prepare specification",
|
||||
"iris",
|
||||
"Medium",
|
||||
"product-owner",
|
||||
"programmer-fast",
|
||||
parent.Id,
|
||||
startsInProgress: false,
|
||||
initialState: null,
|
||||
ct: CancellationToken.None);
|
||||
|
||||
Assert.Equal("Backlog", child.State);
|
||||
Assert.Equal("product-owner", child.AssignedTo);
|
||||
Assert.Equal("programmer-fast", child.ExpectedFrom);
|
||||
Assert.True(child.IsAgentTask);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetDashboardTaskByIdAsync_MapsChildDelegationAndActivity()
|
||||
{
|
||||
await using var fixture = await TaskWorkflowFixture.CreateAsync();
|
||||
|
||||
var parent = await fixture.TaskService.CreateDashboardTaskAsync(
|
||||
"Parent", null, "iris", "High", "iris", null, CancellationToken.None);
|
||||
|
||||
var child = await fixture.TaskService.CreateAgentTaskAsync(
|
||||
"Implement",
|
||||
"Code changes",
|
||||
"iris",
|
||||
"High",
|
||||
"programmer-fast",
|
||||
"programmer-fast",
|
||||
parent.Id,
|
||||
startsInProgress: false,
|
||||
initialState: null,
|
||||
ct: CancellationToken.None);
|
||||
|
||||
var dto = await fixture.TaskService.GetDashboardTaskByIdAsync(child.Id, CancellationToken.None);
|
||||
|
||||
Assert.NotNull(dto);
|
||||
Assert.True(dto!.HasVisibleDelegation);
|
||||
Assert.NotNull(dto.LastActivityMessage);
|
||||
Assert.Equal("programmer-fast", dto.AssignedTo);
|
||||
Assert.Equal("programmer-fast", dto.ExpectedFrom);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task BridgeGetChildTasksAsync_ReturnsMappedActivityAndVisibleDelegation()
|
||||
{
|
||||
await using var fixture = await TaskWorkflowFixture.CreateAsync();
|
||||
|
||||
var parent = await fixture.TaskService.CreateDashboardTaskAsync(
|
||||
"Parent", null, "iris", "High", "iris", null, CancellationToken.None);
|
||||
|
||||
await fixture.TaskBridgeService.CreateChildTaskAsync(
|
||||
parent.Id,
|
||||
"Review",
|
||||
"Review implementation",
|
||||
"iris",
|
||||
"Medium",
|
||||
"reviewer",
|
||||
"reviewer",
|
||||
startsInProgress: false,
|
||||
ct: CancellationToken.None);
|
||||
|
||||
var children = await fixture.TaskBridgeService.GetChildTasksAsync(parent.Id, CancellationToken.None);
|
||||
var child = Assert.Single(children);
|
||||
|
||||
Assert.True(child.HasVisibleDelegation);
|
||||
Assert.NotNull(child.LastActivityMessage);
|
||||
Assert.Equal("reviewer", child.AssignedTo);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GatewayBridgeController_GetBoard_AcceptsProgrammerFastHeader()
|
||||
{
|
||||
await using var fixture = await TaskWorkflowFixture.CreateAsync();
|
||||
|
||||
var controller = new GatewayBridgeController(
|
||||
fixture.TaskBridgeService,
|
||||
fixture.AgentService,
|
||||
fixture.Configuration,
|
||||
NullLogger<GatewayBridgeController>.Instance)
|
||||
{
|
||||
ControllerContext = new ControllerContext
|
||||
{
|
||||
HttpContext = TaskWorkflowFixture.CreateHttpContext(headers: new Dictionary<string, string>
|
||||
{
|
||||
["X-Agent-Id"] = "programmer-fast"
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
var result = await controller.GetBoard(CancellationToken.None);
|
||||
Assert.IsType<OkObjectResult>(result.Result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GatewayBridgeController_GetBoard_AcceptsServiceKeyWithoutConfiguredNexusSystemAgent()
|
||||
{
|
||||
await using var fixture = await TaskWorkflowFixture.CreateAsync();
|
||||
|
||||
var controller = new GatewayBridgeController(
|
||||
fixture.TaskBridgeService,
|
||||
fixture.AgentService,
|
||||
fixture.Configuration,
|
||||
NullLogger<GatewayBridgeController>.Instance)
|
||||
{
|
||||
ControllerContext = new ControllerContext
|
||||
{
|
||||
HttpContext = TaskWorkflowFixture.CreateHttpContext(headers: new Dictionary<string, string>
|
||||
{
|
||||
["X-Nexus-Api-Key"] = "test-service-key"
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
var result = await controller.GetBoard(CancellationToken.None);
|
||||
Assert.IsType<OkObjectResult>(result.Result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DashboardController_GetBoard_AcceptsServiceKeyWithoutJwt()
|
||||
{
|
||||
await using var fixture = await TaskWorkflowFixture.CreateAsync();
|
||||
|
||||
var controller = new DashboardController(
|
||||
new FakeDashboardService(),
|
||||
fixture.TaskService,
|
||||
fixture.ActivityRepository,
|
||||
new HttpContextAccessor(),
|
||||
fixture.AgentService,
|
||||
fixture.Configuration,
|
||||
fixture.NotificationService,
|
||||
fixture.LiveUpdateService)
|
||||
{
|
||||
ControllerContext = new ControllerContext
|
||||
{
|
||||
HttpContext = TaskWorkflowFixture.CreateHttpContext(headers: new Dictionary<string, string>
|
||||
{
|
||||
["X-Nexus-Api-Key"] = "test-service-key"
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
var result = await controller.GetBoard(CancellationToken.None);
|
||||
Assert.IsType<OkObjectResult>(result.Result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task TasksController_GetBoard_AcceptsProgrammerFastHeader()
|
||||
{
|
||||
await using var fixture = await TaskWorkflowFixture.CreateAsync();
|
||||
|
||||
var controller = new TasksController(fixture.TaskService, fixture.AgentService, fixture.Configuration)
|
||||
{
|
||||
ControllerContext = new ControllerContext
|
||||
{
|
||||
HttpContext = TaskWorkflowFixture.CreateHttpContext(headers: new Dictionary<string, string>
|
||||
{
|
||||
["X-Agent-Id"] = "programmer-fast"
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
var result = await controller.GetBoard(CancellationToken.None);
|
||||
var httpContext = new DefaultHttpContext();
|
||||
await result.ExecuteAsync(httpContext);
|
||||
|
||||
Assert.Equal(StatusCodes.Status200OK, httpContext.Response.StatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task TasksController_ResetStale_Anonymous_IsUnauthorized()
|
||||
{
|
||||
await using var fixture = await TaskWorkflowFixture.CreateAsync();
|
||||
|
||||
var controller = new TasksController(fixture.TaskService, fixture.AgentService, fixture.Configuration)
|
||||
{
|
||||
ControllerContext = new ControllerContext
|
||||
{
|
||||
HttpContext = TaskWorkflowFixture.CreateHttpContext()
|
||||
}
|
||||
};
|
||||
|
||||
var result = await controller.ResetStale(new ResetStaleRequest(2), CancellationToken.None);
|
||||
var httpContext = new DefaultHttpContext();
|
||||
await result.ExecuteAsync(httpContext);
|
||||
|
||||
Assert.Equal(StatusCodes.Status401Unauthorized, httpContext.Response.StatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task TasksController_ResetStale_UnknownAgentHeader_IsForbidden()
|
||||
{
|
||||
await using var fixture = await TaskWorkflowFixture.CreateAsync();
|
||||
|
||||
var controller = new TasksController(fixture.TaskService, fixture.AgentService, fixture.Configuration)
|
||||
{
|
||||
ControllerContext = new ControllerContext
|
||||
{
|
||||
HttpContext = TaskWorkflowFixture.CreateHttpContext(headers: new Dictionary<string, string>
|
||||
{
|
||||
["X-Agent-Id"] = "unknown-agent"
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
var result = await controller.ResetStale(new ResetStaleRequest(2), CancellationToken.None);
|
||||
var httpContext = new DefaultHttpContext();
|
||||
await result.ExecuteAsync(httpContext);
|
||||
|
||||
Assert.Equal(StatusCodes.Status403Forbidden, httpContext.Response.StatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task TasksController_ResetStale_OrdinaryJwtUser_IsForbidden()
|
||||
{
|
||||
await using var fixture = await TaskWorkflowFixture.CreateAsync();
|
||||
|
||||
var controller = new TasksController(fixture.TaskService, fixture.AgentService, fixture.Configuration)
|
||||
{
|
||||
ControllerContext = new ControllerContext
|
||||
{
|
||||
HttpContext = TaskWorkflowFixture.CreateHttpContext(user: TaskWorkflowFixture.CreateUser("user-1", "user"))
|
||||
}
|
||||
};
|
||||
|
||||
var result = await controller.ResetStale(new ResetStaleRequest(2), CancellationToken.None);
|
||||
var httpContext = new DefaultHttpContext();
|
||||
await result.ExecuteAsync(httpContext);
|
||||
|
||||
Assert.Equal(StatusCodes.Status403Forbidden, httpContext.Response.StatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task TasksController_ResetStale_ServiceKey_IsAllowed()
|
||||
{
|
||||
await using var fixture = await TaskWorkflowFixture.CreateAsync();
|
||||
|
||||
var controller = new TasksController(fixture.TaskService, fixture.AgentService, fixture.Configuration)
|
||||
{
|
||||
ControllerContext = new ControllerContext
|
||||
{
|
||||
HttpContext = TaskWorkflowFixture.CreateHttpContext(headers: new Dictionary<string, string>
|
||||
{
|
||||
["X-Nexus-Api-Key"] = "test-service-key"
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
var result = await controller.ResetStale(new ResetStaleRequest(2), CancellationToken.None);
|
||||
var httpContext = new DefaultHttpContext();
|
||||
await result.ExecuteAsync(httpContext);
|
||||
|
||||
Assert.Equal(StatusCodes.Status200OK, httpContext.Response.StatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task TasksController_ResetStale_IrisHeader_IsAllowed()
|
||||
{
|
||||
await using var fixture = await TaskWorkflowFixture.CreateAsync();
|
||||
|
||||
var controller = new TasksController(fixture.TaskService, fixture.AgentService, fixture.Configuration)
|
||||
{
|
||||
ControllerContext = new ControllerContext
|
||||
{
|
||||
HttpContext = TaskWorkflowFixture.CreateHttpContext(agentId: "iris")
|
||||
}
|
||||
};
|
||||
|
||||
var result = await controller.ResetStale(new ResetStaleRequest(2), CancellationToken.None);
|
||||
var httpContext = new DefaultHttpContext();
|
||||
await result.ExecuteAsync(httpContext);
|
||||
|
||||
Assert.Equal(StatusCodes.Status200OK, httpContext.Response.StatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GatewayBridgeController_GetBoard_OrdinaryJwtUser_IsUnauthorized()
|
||||
{
|
||||
await using var fixture = await TaskWorkflowFixture.CreateAsync();
|
||||
|
||||
var controller = new GatewayBridgeController(
|
||||
fixture.TaskBridgeService,
|
||||
fixture.AgentService,
|
||||
fixture.Configuration,
|
||||
NullLogger<GatewayBridgeController>.Instance)
|
||||
{
|
||||
ControllerContext = new ControllerContext
|
||||
{
|
||||
HttpContext = TaskWorkflowFixture.CreateHttpContext(user: TaskWorkflowFixture.CreateUser("user-1", "user"))
|
||||
}
|
||||
};
|
||||
|
||||
var result = await controller.GetBoard(CancellationToken.None);
|
||||
Assert.IsType<UnauthorizedObjectResult>(result.Result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GatewayBridgeController_GetBoard_AdminJwt_IsAllowed()
|
||||
{
|
||||
await using var fixture = await TaskWorkflowFixture.CreateAsync();
|
||||
|
||||
var controller = new GatewayBridgeController(
|
||||
fixture.TaskBridgeService,
|
||||
fixture.AgentService,
|
||||
fixture.Configuration,
|
||||
NullLogger<GatewayBridgeController>.Instance)
|
||||
{
|
||||
ControllerContext = new ControllerContext
|
||||
{
|
||||
HttpContext = TaskWorkflowFixture.CreateHttpContext(user: TaskWorkflowFixture.CreateUser("bao", "admin"))
|
||||
}
|
||||
};
|
||||
|
||||
var result = await controller.GetBoard(CancellationToken.None);
|
||||
Assert.IsType<OkObjectResult>(result.Result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CreateChildTaskAsync_TransitionsBacklogParent_WhenCallerIsProgrammerFast()
|
||||
{
|
||||
await using var fixture = await TaskWorkflowFixture.CreateAsync();
|
||||
fixture.SetCallerAgent("programmer-fast");
|
||||
|
||||
var parent = await fixture.TaskService.CreateDashboardTaskAsync(
|
||||
"Parent", "Coordination", "iris", "High", "iris", null, CancellationToken.None);
|
||||
|
||||
var result = await fixture.TaskBridgeService.CreateChildTaskAsync(
|
||||
parent.Id,
|
||||
"Implement",
|
||||
"Ship the change",
|
||||
"programmer-fast",
|
||||
"Medium",
|
||||
"programmer-fast",
|
||||
"programmer-fast",
|
||||
startsInProgress: false,
|
||||
ct: CancellationToken.None);
|
||||
|
||||
var updatedParent = await fixture.TaskService.GetByIdAsync(parent.Id, CancellationToken.None);
|
||||
|
||||
Assert.Equal(TaskBridgeOutcome.Success, result.Outcome);
|
||||
Assert.NotNull(updatedParent);
|
||||
Assert.Equal("In progress", updatedParent!.State);
|
||||
}
|
||||
}
|
||||
|
||||
file sealed class TaskWorkflowFixture : IAsyncDisposable
|
||||
{
|
||||
private readonly NexusDbContext _db;
|
||||
|
||||
private TaskWorkflowFixture(
|
||||
NexusDbContext db,
|
||||
IConfiguration configuration,
|
||||
ITaskRepository taskRepository,
|
||||
IActivityRepository activityRepository,
|
||||
INotificationService notificationService,
|
||||
ILiveUpdateService liveUpdateService,
|
||||
ITaskService taskService,
|
||||
ITaskBridgeService taskBridgeService,
|
||||
IAgentService agentService,
|
||||
HttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
_db = db;
|
||||
Configuration = configuration;
|
||||
TaskRepository = taskRepository;
|
||||
ActivityRepository = activityRepository;
|
||||
NotificationService = notificationService;
|
||||
LiveUpdateService = liveUpdateService;
|
||||
TaskService = taskService;
|
||||
TaskBridgeService = taskBridgeService;
|
||||
AgentService = agentService;
|
||||
HttpContextAccessor = httpContextAccessor;
|
||||
}
|
||||
|
||||
public IConfiguration Configuration { get; }
|
||||
public ITaskRepository TaskRepository { get; }
|
||||
public IActivityRepository ActivityRepository { get; }
|
||||
public INotificationService NotificationService { get; }
|
||||
public ILiveUpdateService LiveUpdateService { get; }
|
||||
public ITaskService TaskService { get; }
|
||||
public ITaskBridgeService TaskBridgeService { get; }
|
||||
public IAgentService AgentService { get; }
|
||||
public HttpContextAccessor HttpContextAccessor { get; }
|
||||
|
||||
public static async Task<TaskWorkflowFixture> CreateAsync()
|
||||
{
|
||||
var options = new DbContextOptionsBuilder<NexusDbContext>()
|
||||
.UseInMemoryDatabase(Guid.NewGuid().ToString())
|
||||
.Options;
|
||||
|
||||
var db = new NexusDbContext(options);
|
||||
await db.Database.EnsureCreatedAsync();
|
||||
|
||||
var configPath = CreateAgentConfigFile();
|
||||
var configuration = new ConfigurationBuilder()
|
||||
.AddInMemoryCollection(new Dictionary<string, string?>
|
||||
{
|
||||
["AgentConfigPath"] = configPath,
|
||||
["NexusApiKey"] = "test-service-key"
|
||||
})
|
||||
.Build();
|
||||
|
||||
var agentService = new AgentService(configuration, new FakeRuntime());
|
||||
var liveUpdateService = new LiveUpdateService();
|
||||
var activityRepository = new ActivityRepository(db);
|
||||
var taskRepository = new TaskRepository(db);
|
||||
var notificationService = new NotificationService(db, liveUpdateService);
|
||||
var httpContextAccessor = new HttpContextAccessor { HttpContext = CreateHttpContext(agentId: "iris") };
|
||||
|
||||
var taskService = new TaskService(
|
||||
taskRepository,
|
||||
activityRepository,
|
||||
notificationService,
|
||||
agentService,
|
||||
httpContextAccessor,
|
||||
liveUpdateService);
|
||||
|
||||
var taskBridgeService = new TaskBridgeService(
|
||||
taskService,
|
||||
agentService,
|
||||
activityRepository,
|
||||
notificationService,
|
||||
liveUpdateService);
|
||||
|
||||
return new TaskWorkflowFixture(
|
||||
db,
|
||||
configuration,
|
||||
taskRepository,
|
||||
activityRepository,
|
||||
notificationService,
|
||||
liveUpdateService,
|
||||
taskService,
|
||||
taskBridgeService,
|
||||
agentService,
|
||||
httpContextAccessor);
|
||||
}
|
||||
|
||||
public static DefaultHttpContext CreateHttpContext(
|
||||
string? agentId = null,
|
||||
Dictionary<string, string>? headers = null,
|
||||
ClaimsPrincipal? user = null)
|
||||
{
|
||||
var httpContext = new DefaultHttpContext();
|
||||
if (!string.IsNullOrWhiteSpace(agentId))
|
||||
httpContext.Request.Headers["X-Agent-Id"] = agentId;
|
||||
|
||||
if (headers is not null)
|
||||
{
|
||||
foreach (var (key, value) in headers)
|
||||
httpContext.Request.Headers[key] = value;
|
||||
}
|
||||
|
||||
httpContext.User = user ?? new ClaimsPrincipal(new ClaimsIdentity());
|
||||
return httpContext;
|
||||
}
|
||||
|
||||
public static ClaimsPrincipal CreateUser(string userId, string role)
|
||||
{
|
||||
var claims = new[]
|
||||
{
|
||||
new Claim(ClaimTypes.NameIdentifier, userId),
|
||||
new Claim(ClaimTypes.Role, role)
|
||||
};
|
||||
|
||||
return new ClaimsPrincipal(new ClaimsIdentity(claims, "TestAuth"));
|
||||
}
|
||||
|
||||
public void SetCallerAgent(string agentId)
|
||||
{
|
||||
HttpContextAccessor.HttpContext = CreateHttpContext(agentId: agentId);
|
||||
}
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
await _db.DisposeAsync();
|
||||
}
|
||||
|
||||
private static string CreateAgentConfigFile()
|
||||
{
|
||||
var path = Path.Combine(Path.GetTempPath(), $"agent-config-{Guid.NewGuid():N}.json");
|
||||
File.WriteAllText(path,
|
||||
"""
|
||||
{
|
||||
"agents": {
|
||||
"defaults": {
|
||||
"workspace": "/workspace/default",
|
||||
"model": {
|
||||
"primary": "deepseek/deepseek-v4-flash"
|
||||
}
|
||||
},
|
||||
"list": [
|
||||
{ "id": "iris", "name": "iris", "model": { "primary": "openai/gpt-5.5" } },
|
||||
{ "id": "product-owner", "name": "product-owner", "model": { "primary": "openai/gpt-5.5" } },
|
||||
{ "id": "programmer", "name": "programmer", "model": { "primary": "openai/gpt-5.4" } },
|
||||
{ "id": "programmer-fast", "name": "programmer-fast", "model": { "primary": "openai/gpt-5.3-codex-spark" } },
|
||||
{ "id": "reviewer", "name": "reviewer", "model": { "primary": "openai/gpt-5.5" } }
|
||||
]
|
||||
}
|
||||
}
|
||||
""");
|
||||
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
file sealed class FakeDashboardService : IDashboardService
|
||||
{
|
||||
public Task<DashboardStatus> GetStatusAsync() => Task.FromResult(new DashboardStatus(true, "online", 1, 0));
|
||||
public Task<List<DashboardAgentInfo>> GetAgentsAsync() => Task.FromResult(new List<DashboardAgentInfo>());
|
||||
public Task<List<FeedEntry>> GetOperationsAsync(int limit, string? agentFilter) => Task.FromResult(new List<FeedEntry>());
|
||||
public Task<ChatResponse> SendChatAsync(string agentId, string message) => Task.FromResult(new ChatResponse(true, "", null));
|
||||
public Task<List<MessageEntry>> GetMessagesAsync(string? sessionKey, int limit, int offset) => Task.FromResult(new List<MessageEntry>());
|
||||
public Task<List<QueueItem>> GetQueueAsync(CancellationToken ct) => Task.FromResult(new List<QueueItem>());
|
||||
public Task<QueueDeleteResult> DeleteQueueItemAsync(string id, string? source, CancellationToken ct) => Task.FromResult(new QueueDeleteResult(QueueDeleteOutcome.Ignored));
|
||||
public Task<QueuePriorityResult> CycleQueuePriorityAsync(string id, CancellationToken ct) => Task.FromResult(new QueuePriorityResult(QueuePriorityOutcome.Ignored));
|
||||
public Task<AgentModelInfo?> GetAgentModelAsync(string agentId) => Task.FromResult<AgentModelInfo?>(null);
|
||||
public Task<bool> SetAgentModelAsync(string agentId, string model) => Task.FromResult(false);
|
||||
public Task<List<AgentActivityEntry>> GetAgentActivityAsync(string agentId, int limit) => Task.FromResult(new List<AgentActivityEntry>());
|
||||
public List<ModelOption> GetAvailableModels() => [];
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
bin/
|
||||
obj/
|
||||
*.user
|
||||
*.suo
|
||||
.vs/
|
||||
.vscode/
|
||||
.git/
|
||||
.gitignore
|
||||
.env
|
||||
*.log
|
||||
@@ -0,0 +1,184 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Nexus.Api.Data;
|
||||
using Nexus.Api.DTOs;
|
||||
using Nexus.Api.Repositories;
|
||||
using Nexus.Api.Services;
|
||||
|
||||
namespace Nexus.Api.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// Admin/User-Management – erreichbar für owner und admin-Rollen.
|
||||
///
|
||||
/// Sicherheitsregeln:
|
||||
/// - Nur owner und admin dürfen User verwalten.
|
||||
/// - Die Rolle "owner" kann weder vergeben noch überschrieben werden – sie ist
|
||||
/// eine Sonderrolle, die nur bei der initialen Seed-Erstellung gesetzt wird.
|
||||
/// - Über die API sind nur die Rollen "admin", "user" und "viewer" wählbar.
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("api/v1/admin")]
|
||||
[Authorize(Roles = "owner,admin")]
|
||||
public class AdminController(
|
||||
IUserRepository userRepository,
|
||||
ILogger<AdminController> logger) : ControllerBase
|
||||
{
|
||||
private static readonly string[] SettableRoles = ["admin", "user", "viewer"];
|
||||
|
||||
/// <summary>
|
||||
/// Alle registrierten User auflisten.
|
||||
/// </summary>
|
||||
[HttpGet("users")]
|
||||
public async Task<IResult> GetUsers(CancellationToken ct)
|
||||
{
|
||||
var users = await userRepository.GetAllAsync(ct);
|
||||
var result = users.Select(u => new AdminUserInfo
|
||||
{
|
||||
Id = u.Id,
|
||||
Email = u.Email,
|
||||
DisplayName = u.DisplayName,
|
||||
Role = u.Role,
|
||||
CreatedAt = u.CreatedAt,
|
||||
LastLoginAt = u.LastLoginAt,
|
||||
}).ToList();
|
||||
return Results.Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Neuen User anlegen.
|
||||
/// Die Rolle "owner" kann NICHT gesetzt werden.
|
||||
/// </summary>
|
||||
[HttpPost("users")]
|
||||
public async Task<IResult> CreateUser([FromBody] AdminCreateUserRequest request, CancellationToken ct)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(request.Email) || string.IsNullOrWhiteSpace(request.Password))
|
||||
return Results.ValidationProblem(new Dictionary<string, string[]>
|
||||
{
|
||||
["request"] = ["Email and password are required."]
|
||||
});
|
||||
|
||||
if (request.Password.Length < 10)
|
||||
return Results.ValidationProblem(new Dictionary<string, string[]>
|
||||
{
|
||||
["password"] = ["Password must be at least 10 characters."]
|
||||
});
|
||||
|
||||
// Role validieren – owner ist nicht über API setzbar
|
||||
var targetRole = string.IsNullOrWhiteSpace(request.Role) ? "user" : request.Role.Trim().ToLowerInvariant();
|
||||
if (!SettableRoles.Contains(targetRole))
|
||||
return Results.ValidationProblem(new Dictionary<string, string[]>
|
||||
{
|
||||
["role"] = [$"Invalid role. Valid roles: {string.Join(", ", SettableRoles)}."]
|
||||
});
|
||||
|
||||
var normalizedEmail = AuthService.NormalizeEmail(request.Email);
|
||||
var existing = await userRepository.GetByEmailAsync(normalizedEmail, ct);
|
||||
if (existing is not null)
|
||||
return Results.Conflict(new { error = "A user with this email already exists." });
|
||||
|
||||
var user = new NexusUser
|
||||
{
|
||||
Email = request.Email.Trim(),
|
||||
NormalizedEmail = normalizedEmail,
|
||||
DisplayName = string.IsNullOrWhiteSpace(request.DisplayName)
|
||||
? request.Email.Split('@')[0]
|
||||
: request.DisplayName.Trim(),
|
||||
PasswordHash = PasswordSecurity.Hash(request.Password),
|
||||
Role = targetRole,
|
||||
};
|
||||
|
||||
await userRepository.AddAsync(user, ct);
|
||||
logger.LogInformation("User {Role} created user {Email} with role {Role}", UserRole(), user.Email, user.Role);
|
||||
|
||||
return Results.Created($"/api/v1/admin/users/{user.Id}", new AdminUserInfo
|
||||
{
|
||||
Id = user.Id,
|
||||
Email = user.Email,
|
||||
DisplayName = user.DisplayName,
|
||||
Role = user.Role,
|
||||
CreatedAt = user.CreatedAt,
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// User löschen. Eigene owner-User und der eigene Account sind geschützt.
|
||||
/// </summary>
|
||||
[HttpDelete("users/{id:guid}")]
|
||||
public async Task<IResult> DeleteUser(Guid id, CancellationToken ct)
|
||||
{
|
||||
var user = await userRepository.GetByIdAsync(id, ct);
|
||||
if (user is null)
|
||||
return Results.NotFound(new { error = "User not found." });
|
||||
|
||||
if (string.Equals(user.Role, "owner", StringComparison.OrdinalIgnoreCase))
|
||||
return Results.Problem("Owner accounts cannot be deleted via API.", statusCode: 403);
|
||||
|
||||
if (user.Id.ToString() == CurrentUserId())
|
||||
return Results.Problem("You cannot delete your own account.", statusCode: 403);
|
||||
|
||||
await userRepository.DeleteAsync(user, ct);
|
||||
logger.LogInformation("User {Role} deleted user {Email}", UserRole(), user.Email);
|
||||
return Results.NoContent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rolle eines Users ändern. "owner" kann weder gesetzt noch überschrieben werden.
|
||||
/// </summary>
|
||||
[HttpPatch("users/{id:guid}/role")]
|
||||
public async Task<IResult> UpdateUserRole(Guid id, [FromBody] AdminUpdateRoleRequest request, CancellationToken ct)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(request.Role))
|
||||
return Results.ValidationProblem(new Dictionary<string, string[]>
|
||||
{
|
||||
["role"] = ["Role is required."]
|
||||
});
|
||||
|
||||
var newRole = request.Role.Trim().ToLowerInvariant();
|
||||
if (!SettableRoles.Contains(newRole))
|
||||
return Results.ValidationProblem(new Dictionary<string, string[]>
|
||||
{
|
||||
["role"] = [$"Invalid role. Valid: {string.Join(", ", SettableRoles)}. Owner is reserved."]
|
||||
});
|
||||
|
||||
var user = await userRepository.GetByIdAsync(id, ct);
|
||||
if (user is null)
|
||||
return Results.NotFound(new { error = "User not found." });
|
||||
|
||||
// Niemals owner überschreiben
|
||||
if (string.Equals(user.Role, "owner", StringComparison.OrdinalIgnoreCase))
|
||||
return Results.Problem("Owner role cannot be modified via API.", statusCode: 403);
|
||||
|
||||
// admin darf andere admins nicht ändern (nur owner)
|
||||
var callerRole = UserRole();
|
||||
if (callerRole == "admin" && string.Equals(user.Role, "admin", StringComparison.OrdinalIgnoreCase))
|
||||
return Results.Problem("Admin users can only be managed by the owner.", statusCode: 403);
|
||||
|
||||
// admin darf sich nicht selbst herabstufen
|
||||
if (callerRole == "admin" && user.Id.ToString() == CurrentUserId() && newRole != "admin")
|
||||
return Results.Problem("You cannot demote yourself.", statusCode: 403);
|
||||
|
||||
user.Role = newRole;
|
||||
user.UpdatedAt = DateTimeOffset.UtcNow;
|
||||
await userRepository.UpdateAsync(user, ct);
|
||||
logger.LogInformation("User {Role} changed role for {Email} from {OldRole} to {NewRole}",
|
||||
callerRole, user.Email, user.Role, newRole);
|
||||
|
||||
return Results.Ok(new AdminUserInfo
|
||||
{
|
||||
Id = user.Id,
|
||||
Email = user.Email,
|
||||
DisplayName = user.DisplayName,
|
||||
Role = user.Role,
|
||||
CreatedAt = user.CreatedAt,
|
||||
LastLoginAt = user.LastLoginAt,
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>Liefert die Rolle des aufrufenden Users.</summary>
|
||||
private string UserRole()
|
||||
=> User.FindFirst(System.Security.Claims.ClaimTypes.Role)?.Value?.ToLowerInvariant() ?? "unknown";
|
||||
|
||||
/// <summary>Liefert die Subject-ID des aufrufenden Users.</summary>
|
||||
private string? CurrentUserId()
|
||||
=> User.FindFirst(System.IdentityModel.Tokens.Jwt.JwtRegisteredClaimNames.Sub)?.Value;
|
||||
}
|
||||
@@ -92,9 +92,28 @@ public class AgentsController(
|
||||
if (request.Content.Length > 500 * 1024)
|
||||
return Results.BadRequest(new { error = "Content exceeds maximum size of 500KB." });
|
||||
|
||||
var result = await agentConfigService.SaveConfigFileAsync(id, fileName, request.Content, ct);
|
||||
return result is null
|
||||
? Results.BadRequest(new { error = "Invalid filename or path." })
|
||||
: Results.Ok(new { result.FileName, result.Size, result.ModifiedAt });
|
||||
try
|
||||
{
|
||||
var result = await agentConfigService.SaveConfigFileAsync(id, fileName, request.Content, ct);
|
||||
return result is null
|
||||
? Results.BadRequest(new { error = "Invalid filename or path." })
|
||||
: Results.Ok(new { result.FileName, result.Size, result.ModifiedAt });
|
||||
}
|
||||
catch (UnauthorizedAccessException ex)
|
||||
{
|
||||
logger.LogError(ex, "Permission denied saving config file {FileName} for agent {AgentId}", fileName, id);
|
||||
return Results.Problem(
|
||||
title: "Permission denied",
|
||||
detail: $"Cannot write config file '{fileName}' for agent '{id}'. The target path may be owned by a different user.",
|
||||
statusCode: StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
logger.LogError(ex, "I/O error saving config file {FileName} for agent {AgentId}", fileName, id);
|
||||
return Results.Problem(
|
||||
title: "File write error",
|
||||
detail: $"Failed to write config file '{fileName}' for agent '{id}': {ex.Message}",
|
||||
statusCode: StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ using Microsoft.AspNetCore.RateLimiting;
|
||||
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||
using Nexus.Api.DTOs;
|
||||
using Nexus.Api.Integrations;
|
||||
using Nexus.Api.RateLimiting;
|
||||
using Nexus.Api.Services;
|
||||
|
||||
namespace Nexus.Api.Controllers;
|
||||
@@ -14,7 +15,8 @@ public class AuthController(
|
||||
IAuthService authService,
|
||||
IAntiforgery antiforgery,
|
||||
IConfiguration config,
|
||||
IHostEnvironment env) : ControllerBase
|
||||
IHostEnvironment env,
|
||||
LoginAttemptTracker attemptTracker) : ControllerBase
|
||||
{
|
||||
[HttpGet("csrf")]
|
||||
public IActionResult GetCsrfToken()
|
||||
@@ -30,11 +32,38 @@ public class AuthController(
|
||||
if (string.IsNullOrWhiteSpace(request.Email) || string.IsNullOrWhiteSpace(request.Password))
|
||||
return Results.ValidationProblem(new Dictionary<string, string[]> { ["credentials"] = ["Email and password are required."] });
|
||||
|
||||
var session = await authService.LoginAsync(request, ct);
|
||||
if (session is null) return Results.Unauthorized();
|
||||
var ip = HttpContext.Connection.RemoteIpAddress?.ToString() ?? "unknown";
|
||||
|
||||
var session = await authService.LoginAsync(request, ct);
|
||||
if (session is null)
|
||||
{
|
||||
var remaining = attemptTracker.RecordFailedAttempt(ip);
|
||||
var retryAfterSeconds = attemptTracker.GetRetryAfterSeconds(ip);
|
||||
|
||||
// Attach remaining info to the 401 response via headers only
|
||||
// (the frontend can also parse the 429 body)
|
||||
HttpContext.Response.Headers["X-RateLimit-Remaining"] = remaining.ToString();
|
||||
HttpContext.Response.Headers["X-RateLimit-Limit"] = "5";
|
||||
if (retryAfterSeconds > 0)
|
||||
HttpContext.Response.Headers["X-RateLimit-Reset"] =
|
||||
DateTimeOffset.UtcNow.AddSeconds(retryAfterSeconds).ToUnixTimeSeconds().ToString();
|
||||
|
||||
// Return a structured body so the frontend can display remaining attempts
|
||||
return Results.Json(new
|
||||
{
|
||||
error = "invalid_credentials",
|
||||
message = "Invalid email or password.",
|
||||
remaining,
|
||||
retryAfterSeconds
|
||||
}, statusCode: 401);
|
||||
}
|
||||
|
||||
// Success — reset attempt counter
|
||||
attemptTracker.Reset(ip);
|
||||
SetRefreshCookie(Response, session.RefreshToken);
|
||||
Response.Headers.CacheControl = "no-store";
|
||||
Response.Headers["X-RateLimit-Remaining"] = "5";
|
||||
Response.Headers["X-RateLimit-Limit"] = "5";
|
||||
return Results.Ok(ToAuthResponse(session));
|
||||
}
|
||||
|
||||
@@ -54,6 +83,8 @@ public class AuthController(
|
||||
|
||||
SetRefreshCookie(Response, session.RefreshToken);
|
||||
Response.Headers.CacheControl = "no-store";
|
||||
Response.Headers["X-RateLimit-Remaining"] = "5";
|
||||
Response.Headers["X-RateLimit-Limit"] = "5";
|
||||
return Results.Ok(ToAuthResponse(session));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,25 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Nexus.Api.Data;
|
||||
using Nexus.Api.Models;
|
||||
using Nexus.Api.Repositories;
|
||||
using Nexus.Api.Services;
|
||||
|
||||
namespace Nexus.Api.Controllers;
|
||||
|
||||
[Authorize]
|
||||
[ApiController]
|
||||
[Route("api/dashboard")]
|
||||
public class DashboardController(IDashboardService dashboardService, ITaskService taskService) : ControllerBase
|
||||
public class DashboardController(
|
||||
IDashboardService dashboardService,
|
||||
ITaskService taskService,
|
||||
IActivityRepository activityService,
|
||||
IHttpContextAccessor httpContextAccessor,
|
||||
IAgentService agentService,
|
||||
IConfiguration configuration,
|
||||
INotificationService notificationService,
|
||||
ILiveUpdateService liveUpdateService) : ControllerBase
|
||||
{
|
||||
[HttpGet("status")]
|
||||
public async Task<DashboardStatus> GetStatus()
|
||||
@@ -115,9 +127,16 @@ public class DashboardController(IDashboardService dashboardService, ITaskServic
|
||||
if (string.IsNullOrWhiteSpace(request.Title))
|
||||
return BadRequest(new { error = "Title is required." });
|
||||
|
||||
var task = await taskService.CreateDashboardTaskAsync(
|
||||
request.Title, request.Detail, request.Source, request.Priority, request.AssignedTo, ct);
|
||||
return Created($"/api/dashboard/tasks/{task.Id}", MapToDto(task));
|
||||
try
|
||||
{
|
||||
var task = await taskService.CreateDashboardTaskAsync(
|
||||
request.Title, request.Detail, request.Source, request.Priority, request.AssignedTo, request.ParentTaskId, ct);
|
||||
return Created($"/api/dashboard/tasks/{task.Id}", MapToDto(task));
|
||||
}
|
||||
catch (ArgumentException ex)
|
||||
{
|
||||
return BadRequest(new { error = ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut("tasks/{id:guid}")]
|
||||
@@ -125,7 +144,7 @@ public class DashboardController(IDashboardService dashboardService, ITaskServic
|
||||
Guid id, [FromBody] UpdateDashboardTaskRequest request, CancellationToken ct)
|
||||
{
|
||||
var result = await taskService.UpdateDashboardTaskAsync(
|
||||
id, request.Title, request.Detail, request.Source, request.Priority, request.AssignedTo, ct);
|
||||
id, request.Title, request.Detail, request.Source, request.Priority, request.AssignedTo, request.DueDate, ct);
|
||||
return result.Outcome switch
|
||||
{
|
||||
TaskOperationOutcome.NotFound => NotFound(new { error = "Task not found." }),
|
||||
@@ -149,6 +168,20 @@ public class DashboardController(IDashboardService dashboardService, ITaskServic
|
||||
public async Task<ActionResult<DashboardTaskDto>> UpdateTaskStatus(
|
||||
Guid id, [FromBody] UpdateDashboardTaskStatusRequest request, CancellationToken ct)
|
||||
{
|
||||
// Enforce workflow rules based on caller agent
|
||||
var currentTask = await taskService.GetByIdAsync(id, ct);
|
||||
if (currentTask is null)
|
||||
return NotFound(new { error = "Task not found." });
|
||||
|
||||
// Resolve caller agent from header or JWT
|
||||
var callerAgent = ResolveCallerAgent();
|
||||
|
||||
// Nur Iris und Bao dürfen Status ändern
|
||||
if (!TaskStateHelper.CanChangeState(callerAgent, currentTask))
|
||||
{
|
||||
return StatusCode(403, new { error = "Statusänderungen sind nur Iris und Bao vorbehalten. Sub-Agenten können Tasks nicht verschieben." });
|
||||
}
|
||||
|
||||
var result = await taskService.UpdateStatusAsync(id, request.Status, ct);
|
||||
return result.Outcome switch
|
||||
{
|
||||
@@ -158,6 +191,257 @@ public class DashboardController(IDashboardService dashboardService, ITaskServic
|
||||
};
|
||||
}
|
||||
|
||||
// ── Task Board Endpoints ──
|
||||
|
||||
[AllowAnonymous]
|
||||
[HttpGet("tasks/board")]
|
||||
public async Task<ActionResult<BoardResponse>> GetBoard(CancellationToken ct)
|
||||
{
|
||||
if (!await CanReadBoardAsync(ct))
|
||||
return Unauthorized();
|
||||
|
||||
return Ok(await taskService.GetBoardAsync(ct));
|
||||
}
|
||||
|
||||
[HttpGet("live")]
|
||||
public async Task Live(
|
||||
[FromQuery] string forUser = "bao",
|
||||
[FromQuery] int notificationLimit = 50,
|
||||
[FromQuery] long? afterSequence = null,
|
||||
CancellationToken ct = default)
|
||||
{
|
||||
Response.Headers.Append("Content-Type", "text/event-stream");
|
||||
Response.Headers.Append("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||
Response.Headers.Append("Connection", "keep-alive");
|
||||
Response.Headers.Append("X-Accel-Buffering", "no");
|
||||
|
||||
async Task WriteEventAsync(string eventName, object payload)
|
||||
{
|
||||
await Response.WriteAsync($"event: {eventName}\n", ct);
|
||||
await Response.WriteAsync($"data: {System.Text.Json.JsonSerializer.Serialize(payload)}\n\n", ct);
|
||||
await Response.Body.FlushAsync(ct);
|
||||
}
|
||||
|
||||
var currentSequence = liveUpdateService.CurrentSequence;
|
||||
var initial = new DashboardLiveSnapshotDto(
|
||||
await taskService.GetBoardAsync(ct),
|
||||
await notificationService.GetSnapshotAsync(forUser, notificationLimit, ct: ct),
|
||||
new LiveCursorDto(currentSequence, DateTimeOffset.UtcNow, "live"));
|
||||
await WriteEventAsync("snapshot", initial);
|
||||
|
||||
var subscription = await liveUpdateService.SubscribeAsync(afterSequence, ct);
|
||||
using var heartbeat = new PeriodicTimer(TimeSpan.FromSeconds(20));
|
||||
|
||||
while (!ct.IsCancellationRequested)
|
||||
{
|
||||
var readTask = subscription.Reader.ReadAsync(ct).AsTask();
|
||||
var heartbeatTask = heartbeat.WaitForNextTickAsync(ct).AsTask();
|
||||
var completed = await Task.WhenAny(readTask, heartbeatTask);
|
||||
|
||||
if (completed == readTask)
|
||||
{
|
||||
var envelope = await readTask;
|
||||
if (envelope.Type == "notifications.snapshot")
|
||||
{
|
||||
var snapshot = envelope.Payload as NotificationSnapshotDto
|
||||
?? await notificationService.GetSnapshotAsync(forUser, notificationLimit, ct: ct);
|
||||
if (!string.Equals(snapshot.ForUser, forUser, StringComparison.OrdinalIgnoreCase))
|
||||
continue;
|
||||
envelope = envelope with { Payload = snapshot };
|
||||
}
|
||||
|
||||
if (envelope.Type == "tasks.board.snapshot")
|
||||
{
|
||||
envelope = envelope with { Payload = await taskService.GetBoardAsync(ct) };
|
||||
}
|
||||
|
||||
await WriteEventAsync("update", new DashboardLiveEventDto(
|
||||
envelope,
|
||||
new LiveCursorDto(envelope.Sequence, envelope.Timestamp, "live")));
|
||||
}
|
||||
else if (await heartbeatTask)
|
||||
{
|
||||
await WriteEventAsync("heartbeat", new LiveCursorDto(liveUpdateService.CurrentSequence, DateTimeOffset.UtcNow, "live"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPatch("tasks/{id:guid}/move")]
|
||||
public async Task<ActionResult<DashboardTaskDto>> MoveTask(
|
||||
Guid id, [FromBody] MoveTaskRequest request, CancellationToken ct)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(request.State))
|
||||
return BadRequest(new { error = "State is required." });
|
||||
|
||||
// Enforce workflow rules based on caller agent
|
||||
var currentTask = await taskService.GetByIdAsync(id, ct);
|
||||
if (currentTask is null)
|
||||
return NotFound(new { error = "Task not found." });
|
||||
|
||||
// Resolve caller agent from header or JWT
|
||||
var callerAgent = ResolveCallerAgent();
|
||||
|
||||
// Nur Iris und Bao dürfen Status ändern
|
||||
if (!TaskStateHelper.CanChangeState(callerAgent, currentTask))
|
||||
{
|
||||
return StatusCode(403, new { error = "Statusänderungen sind nur Iris und Bao vorbehalten. Sub-Agenten können Tasks nicht verschieben." });
|
||||
}
|
||||
|
||||
var result = await taskService.MoveTaskAsync(id, request.State, ct);
|
||||
return result.Outcome switch
|
||||
{
|
||||
TaskOperationOutcome.InvalidState => BadRequest(new { error = $"Unsupported state: '{request.State}'. Valid: {string.Join(", ", TaskStateHelper.AllStates)}" }),
|
||||
TaskOperationOutcome.NotFound => NotFound(new { error = "Task not found." }),
|
||||
_ => Ok(MapToDto(result.Task!))
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resolves the caller identity: checks X-Agent-Id header, then JWT name claim.
|
||||
/// Falls back to empty string (which authorization helpers reject accordingly).
|
||||
/// </summary>
|
||||
private string ResolveCallerAgent()
|
||||
{
|
||||
var httpContext = httpContextAccessor.HttpContext;
|
||||
if (httpContext is null) return "";
|
||||
|
||||
var agentHeader = httpContext.Request.Headers["X-Agent-Id"].FirstOrDefault();
|
||||
if (!string.IsNullOrWhiteSpace(agentHeader))
|
||||
return agentHeader.Trim().ToLowerInvariant();
|
||||
|
||||
var user = httpContext.User;
|
||||
var nameClaim = user?.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier)?.Value;
|
||||
return nameClaim?.ToLowerInvariant() ?? "";
|
||||
}
|
||||
|
||||
// ── New Endpoints: Reset Stale, Children, Activity ──
|
||||
|
||||
[HttpPost("tasks/reset-stale")]
|
||||
public async Task<ActionResult<ResetStaleResponse>> ResetStale(
|
||||
[FromBody] ResetStaleRequest request, CancellationToken ct)
|
||||
{
|
||||
var threshold = TimeSpan.FromHours(Math.Max(1, request.StaleHours));
|
||||
var count = await taskService.ResetStaleInProgressTasksAsync(threshold, ct);
|
||||
return Ok(new ResetStaleResponse(count));
|
||||
}
|
||||
|
||||
[HttpGet("tasks/{id:guid}/children")]
|
||||
public async Task<ActionResult<List<DashboardTaskDto>>> GetChildren(Guid id, CancellationToken ct)
|
||||
{
|
||||
var board = await taskService.GetBoardAsync(ct);
|
||||
var children = board.Offen
|
||||
.Concat(board.InProgress)
|
||||
.Concat(board.Review)
|
||||
.Concat(board.Blocked)
|
||||
.Concat(board.Done)
|
||||
.Where(task => task.ParentTaskId == id)
|
||||
.OrderByDescending(task => task.UpdatedAt)
|
||||
.ToList();
|
||||
|
||||
return Ok(children);
|
||||
}
|
||||
|
||||
[HttpGet("tasks/{id:guid}")]
|
||||
public async Task<ActionResult<DashboardTaskDto>> GetTask(Guid id, CancellationToken ct)
|
||||
{
|
||||
var task = await taskService.GetDashboardTaskByIdAsync(id, ct);
|
||||
if (task is null) return NotFound(new { error = "Task not found." });
|
||||
return Ok(task);
|
||||
}
|
||||
|
||||
[HttpGet("tasks/{id:guid}/activity")]
|
||||
public async Task<ActionResult<List<ActivityEvent>>> GetTaskActivity(Guid id, CancellationToken ct)
|
||||
{
|
||||
var events = await taskService.GetTaskActivityAsync(id, ct);
|
||||
return Ok(events);
|
||||
}
|
||||
|
||||
[HttpPost("tasks/{id:guid}/activity")]
|
||||
public async Task<ActionResult<ActivityEvent>> PostTaskActivity(
|
||||
Guid id, [FromBody] PostActivityRequest request, CancellationToken ct)
|
||||
{
|
||||
var task = await taskService.GetByIdAsync(id, ct);
|
||||
if (task is null) return NotFound(new { error = "Task not found." });
|
||||
|
||||
if (string.IsNullOrWhiteSpace(request.Message))
|
||||
return BadRequest(new { error = "Message is required." });
|
||||
|
||||
var ev = new ActivityEvent
|
||||
{
|
||||
Type = request.Type ?? "comment",
|
||||
Message = request.Message.Trim(),
|
||||
TaskId = id
|
||||
};
|
||||
|
||||
await activityService.AddAsync(ev, ct);
|
||||
return Created($"/api/dashboard/tasks/{id}/activity/{ev.Id}", ev);
|
||||
}
|
||||
|
||||
// ── Agent Workflow Endpoints (Iris Overview) ──
|
||||
|
||||
/// <summary>
|
||||
/// Returns agent-tasks that are still open and waiting for input.
|
||||
/// Iris uses this to see who she is waiting for.
|
||||
/// </summary>
|
||||
[HttpGet("tasks/agent-waiting")]
|
||||
public async Task<ActionResult<List<DashboardTaskDto>>> GetAgentWaitingTasks(CancellationToken ct)
|
||||
{
|
||||
var waiting = await taskService.GetWaitingTasksAsync(ct);
|
||||
return Ok(waiting.Select(MapToDto).ToList());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a complete agent-workflow overview grouped by expected respondent
|
||||
/// + stale detection. This is the main Iris dashboard data.
|
||||
/// </summary>
|
||||
[HttpGet("tasks/agent-overview")]
|
||||
public async Task<ActionResult<AgentWorkflowOverview>> GetAgentOverview(
|
||||
CancellationToken ct, [FromQuery] int staleHours = 2)
|
||||
{
|
||||
var threshold = TimeSpan.FromHours(Math.Max(1, staleHours));
|
||||
return Ok(await taskService.GetAgentWorkflowOverviewAsync(threshold, ct));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an agent-task: a task that is tracked as originating from the agent workflow.
|
||||
/// Sub-agents (programmer, reviewer) can only CREATE, not move state.
|
||||
/// </summary>
|
||||
[HttpPost("tasks/agent")]
|
||||
public async Task<ActionResult<DashboardTaskDto>> CreateAgentTask(
|
||||
[FromBody] CreateAgentTaskRequest request, CancellationToken ct)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(request.Title))
|
||||
return BadRequest(new { error = "Title is required." });
|
||||
|
||||
try
|
||||
{
|
||||
var task = await taskService.CreateAgentTaskAsync(
|
||||
request.Title, request.Detail, request.Source ?? "iris",
|
||||
request.Priority, request.AssignedTo, request.ExpectedFrom,
|
||||
request.ParentTaskId, request.StartsInProgress, request.InitialState, ct);
|
||||
|
||||
return Created($"/api/dashboard/tasks/{task.Id}", MapToDto(task));
|
||||
}
|
||||
catch (ArgumentException ex)
|
||||
{
|
||||
return BadRequest(new { error = ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
private static DashboardTaskDto MapToDto(WorkTask t) => new(
|
||||
t.Id, t.Title, t.Detail, t.Source, t.State, t.Priority, t.AssignedTo, t.CreatedAt, t.UpdatedAt);
|
||||
t.Id, t.Title, t.Detail, t.Source, t.State, t.Priority, t.AssignedTo,
|
||||
t.ParentTaskId, t.DueDate, t.CreatedAt, t.UpdatedAt,
|
||||
t.IsAgentTask, t.ExpectedFrom);
|
||||
|
||||
private async Task<bool> CanReadBoardAsync(CancellationToken ct)
|
||||
{
|
||||
var allowedAgent = await RequestAuthorizationHelper.ResolveAllowedAgentHeaderAsync(HttpContext, agentService, ct);
|
||||
if (!string.IsNullOrWhiteSpace(allowedAgent))
|
||||
return true;
|
||||
|
||||
if (RequestAuthorizationHelper.HasValidServiceKey(HttpContext, configuration))
|
||||
return true;
|
||||
|
||||
return User.Identity?.IsAuthenticated == true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,375 @@
|
||||
using System.Security.Claims;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.RateLimiting;
|
||||
using Nexus.Api.DTOs;
|
||||
using Nexus.Api.Models;
|
||||
using Nexus.Api.Services;
|
||||
|
||||
namespace Nexus.Api.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// MCP-style (structured-command) backend bridge for agent-facing operations.
|
||||
///
|
||||
/// This is the SINGLE entrypoint for agents (Iris + sub-agents) to interact with
|
||||
/// the Nexus task board, activity log, and delegation workflow.
|
||||
///
|
||||
/// AUTHENTICATION: Requires X-Nexus-Api-Key or a known allowed X-Agent-Id.
|
||||
/// The browser NEVER uses this controller — only backend-to-backend and gateway-to-backend.
|
||||
///
|
||||
/// DESIGN PRINCIPLE: No MCP protocol between Nexus and Gateway — instead, the Gateway
|
||||
/// calls these structured HTTP endpoints (same pattern, simpler transport).
|
||||
///
|
||||
/// COMMANDS:
|
||||
/// create_task → POST /api/bridge/tasks
|
||||
/// create_child_task → POST /api/bridge/tasks/{id}/children
|
||||
/// update_status → PATCH /api/bridge/tasks/{id}/status
|
||||
/// append_activity → POST /api/bridge/tasks/{id}/activity
|
||||
/// handoff → POST /api/bridge/tasks/{id}/handoff
|
||||
/// get_board → GET /api/bridge/board
|
||||
/// get_task → GET /api/bridge/tasks/{id}
|
||||
/// get_children → GET /api/bridge/tasks/{id}/children
|
||||
/// get_activity → GET /api/bridge/tasks/{id}/activity
|
||||
/// get_agent_overview → GET /api/bridge/agent-overview
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("api/bridge")]
|
||||
[EnableRateLimiting("agents")]
|
||||
public class GatewayBridgeController(
|
||||
ITaskBridgeService bridge,
|
||||
IAgentService agentService,
|
||||
IConfiguration configuration,
|
||||
ILogger<GatewayBridgeController> logger) : ControllerBase
|
||||
{
|
||||
private const string ApikeyErrorMessage =
|
||||
"Bridge endpoints require X-Nexus-Api-Key or X-Agent-Id header with a recognized agent identity.";
|
||||
|
||||
[HttpGet("health")]
|
||||
public IResult Health()
|
||||
{
|
||||
return Results.Ok(new
|
||||
{
|
||||
status = "ok",
|
||||
service = "nexus-bridge",
|
||||
version = "1.0.0",
|
||||
commands = new[]
|
||||
{
|
||||
"create_task", "create_child_task", "update_status",
|
||||
"append_activity", "handoff", "get_board", "get_task",
|
||||
"get_children", "get_activity", "get_agent_overview"
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[HttpPost("tasks")]
|
||||
public async Task<ActionResult<TaskBridgeCommandResponse<DashboardTaskDto>>> CreateTask(
|
||||
[FromBody] BridgeCreateTaskCommand command,
|
||||
CancellationToken ct)
|
||||
{
|
||||
var resolution = await TryResolveAgentAsync(ct);
|
||||
if (!resolution.Success)
|
||||
return resolution.ErrorResult!;
|
||||
|
||||
var agentId = resolution.AgentId;
|
||||
var result = await bridge.CreateTaskAsync(
|
||||
title: command.Title,
|
||||
detail: command.Detail,
|
||||
source: ResolveSource(agentId),
|
||||
priority: command.Priority ?? "Normal",
|
||||
assignedTo: command.AssignedTo ?? agentId,
|
||||
projectId: command.ProjectId,
|
||||
ct: ct);
|
||||
|
||||
return MapResult(result, "create_task");
|
||||
}
|
||||
|
||||
[HttpPost("tasks/{parentTaskId:guid}/children")]
|
||||
public async Task<ActionResult<TaskBridgeCommandResponse<DashboardTaskDto>>> CreateChildTask(
|
||||
Guid parentTaskId,
|
||||
[FromBody] BridgeCreateChildTaskCommand command,
|
||||
CancellationToken ct)
|
||||
{
|
||||
var resolution = await TryResolveAgentAsync(ct);
|
||||
if (!resolution.Success)
|
||||
return resolution.ErrorResult!;
|
||||
|
||||
var agentId = resolution.AgentId;
|
||||
var result = await bridge.CreateChildTaskAsync(
|
||||
parentTaskId: parentTaskId,
|
||||
title: command.Title,
|
||||
detail: command.Detail,
|
||||
source: ResolveSource(agentId),
|
||||
priority: command.Priority ?? "Normal",
|
||||
assignedTo: command.AssignedTo,
|
||||
expectedFrom: command.ExpectedFrom ?? command.AssignedTo,
|
||||
startsInProgress: command.StartsInProgress,
|
||||
ct: ct);
|
||||
|
||||
return MapResult(result, "create_child_task");
|
||||
}
|
||||
|
||||
[HttpPatch("tasks/{taskId:guid}/status")]
|
||||
public async Task<ActionResult<TaskBridgeCommandResponse<DashboardTaskDto>>> UpdateStatus(
|
||||
Guid taskId,
|
||||
[FromBody] BridgeUpdateStatusCommand command,
|
||||
CancellationToken ct)
|
||||
{
|
||||
var resolution = await TryResolveAgentAsync(ct);
|
||||
if (!resolution.Success)
|
||||
return resolution.ErrorResult!;
|
||||
|
||||
var agentId = resolution.AgentId;
|
||||
var result = await bridge.UpdateStatusAsync(
|
||||
taskId: taskId,
|
||||
state: command.State,
|
||||
callerAgent: agentId,
|
||||
ct: ct);
|
||||
|
||||
return MapResult(result, "update_status");
|
||||
}
|
||||
|
||||
[HttpPost("tasks/{taskId:guid}/activity")]
|
||||
public async Task<ActionResult<TaskBridgeCommandResponse<ActivityEntryDto>>> AppendActivity(
|
||||
Guid taskId,
|
||||
[FromBody] BridgeAppendActivityCommand command,
|
||||
CancellationToken ct)
|
||||
{
|
||||
var resolution = await TryResolveAgentAsync(ct);
|
||||
if (!resolution.Success)
|
||||
return resolution.ErrorResult!;
|
||||
|
||||
var result = await bridge.AppendActivityAsync(
|
||||
taskId: taskId,
|
||||
message: command.Message,
|
||||
type: command.Type ?? "comment",
|
||||
ct: ct);
|
||||
|
||||
return MapActivityResult(result, "append_activity");
|
||||
}
|
||||
|
||||
[HttpPost("tasks/{taskId:guid}/handoff")]
|
||||
public async Task<ActionResult<TaskBridgeCommandResponse<DashboardTaskDto>>> Handoff(
|
||||
Guid taskId,
|
||||
[FromBody] BridgeHandoffCommand command,
|
||||
CancellationToken ct)
|
||||
{
|
||||
var resolution = await TryResolveAgentAsync(ct);
|
||||
if (!resolution.Success)
|
||||
return resolution.ErrorResult!;
|
||||
|
||||
var result = await bridge.HandoffAsync(
|
||||
taskId: taskId,
|
||||
targetAgent: command.TargetAgent,
|
||||
note: command.Note,
|
||||
ct: ct);
|
||||
|
||||
return MapResult(result, "handoff");
|
||||
}
|
||||
|
||||
[HttpGet("board")]
|
||||
public async Task<ActionResult<BoardResponse>> GetBoard(CancellationToken ct)
|
||||
{
|
||||
var resolution = await TryResolveAgentAsync(ct);
|
||||
if (!resolution.Success)
|
||||
return resolution.ErrorResult!;
|
||||
|
||||
return Ok(await bridge.GetBoardAsync(ct));
|
||||
}
|
||||
|
||||
[HttpGet("tasks/{taskId:guid}")]
|
||||
public async Task<ActionResult<TaskBridgeCommandResponse<DashboardTaskDto>>> GetTask(
|
||||
Guid taskId, CancellationToken ct)
|
||||
{
|
||||
var resolution = await TryResolveAgentAsync(ct);
|
||||
if (!resolution.Success)
|
||||
return resolution.ErrorResult!;
|
||||
|
||||
var result = await bridge.GetTaskAsync(taskId, ct);
|
||||
return MapResult(result, "get_task");
|
||||
}
|
||||
|
||||
[HttpGet("tasks/{taskId:guid}/children")]
|
||||
public async Task<ActionResult<List<DashboardTaskDto>>> GetChildren(
|
||||
Guid taskId, CancellationToken ct)
|
||||
{
|
||||
var resolution = await TryResolveAgentAsync(ct);
|
||||
if (!resolution.Success)
|
||||
return resolution.ErrorResult!;
|
||||
|
||||
return Ok(await bridge.GetChildTasksAsync(taskId, ct));
|
||||
}
|
||||
|
||||
[HttpGet("tasks/{taskId:guid}/activity")]
|
||||
public async Task<ActionResult<TaskBridgeCommandResponse<List<ActivityEntryDto>>>> GetActivity(
|
||||
Guid taskId, CancellationToken ct)
|
||||
{
|
||||
var resolution = await TryResolveAgentAsync(ct);
|
||||
if (!resolution.Success)
|
||||
return resolution.ErrorResult!;
|
||||
|
||||
var events = await bridge.GetTaskActivityAsync(taskId, ct);
|
||||
var entries = events.Select(e => new ActivityEntryDto(e.Id, e.Type, e.Message, e.CreatedAt)).ToList();
|
||||
|
||||
return Ok(new TaskBridgeCommandResponse<List<ActivityEntryDto>>
|
||||
{
|
||||
Ok = true,
|
||||
Command = "get_activity",
|
||||
Data = entries
|
||||
});
|
||||
}
|
||||
|
||||
[HttpGet("agent-overview")]
|
||||
public async Task<ActionResult<AgentWorkflowOverview>> GetAgentOverview(
|
||||
CancellationToken ct,
|
||||
[FromQuery] int staleHours = 2)
|
||||
{
|
||||
var resolution = await TryResolveAgentAsync(ct);
|
||||
if (!resolution.Success)
|
||||
return resolution.ErrorResult!;
|
||||
|
||||
var threshold = TimeSpan.FromHours(Math.Max(1, staleHours));
|
||||
return Ok(await bridge.GetAgentOverviewAsync(threshold, ct));
|
||||
}
|
||||
|
||||
private async Task<(bool Success, string AgentId, ActionResult? ErrorResult)> TryResolveAgentAsync(CancellationToken ct)
|
||||
{
|
||||
var allowedAgentIds = await agentService.GetAllowedAgentIdsAsync(ct);
|
||||
var allowedActorIds = AgentIdentityCatalog.BuildAllowedActorIds(allowedAgentIds);
|
||||
|
||||
var agentHeader = Request.Headers["X-Agent-Id"].FirstOrDefault();
|
||||
if (!string.IsNullOrWhiteSpace(agentHeader))
|
||||
{
|
||||
var normalizedHeader = agentHeader.Trim().ToLowerInvariant();
|
||||
if (allowedActorIds.Contains(normalizedHeader))
|
||||
return (true, normalizedHeader, null);
|
||||
|
||||
logger.LogWarning("Bridge: ignoring unknown X-Agent-Id '{AgentId}' from {Ip} and continuing auth fallback",
|
||||
normalizedHeader,
|
||||
HttpContext.Connection.RemoteIpAddress);
|
||||
}
|
||||
|
||||
if (User.Identity?.IsAuthenticated == true)
|
||||
{
|
||||
var normalizedClaim = User.FindFirst(ClaimTypes.NameIdentifier)?.Value?.Trim().ToLowerInvariant();
|
||||
if (!string.IsNullOrWhiteSpace(normalizedClaim) && allowedActorIds.Contains(normalizedClaim))
|
||||
return (true, normalizedClaim, null);
|
||||
|
||||
// Browser JWT fallback is intentionally restricted to board owners/admins.
|
||||
// Agent/service traffic should authenticate as an allowed agent or service principal.
|
||||
if (User.IsInRole("owner") || User.IsInRole("admin"))
|
||||
return (true, "bao", null);
|
||||
}
|
||||
|
||||
if (RequestAuthorizationHelper.IsAuthenticatedService(HttpContext, configuration) &&
|
||||
allowedActorIds.Contains("nexus-system"))
|
||||
return (true, "nexus-system", null);
|
||||
|
||||
var unauthorized = Unauthorized(new { error = ApikeyErrorMessage });
|
||||
logger.LogWarning("Bridge: unauthenticated request rejected from {Ip}", HttpContext.Connection.RemoteIpAddress);
|
||||
return (false, string.Empty, unauthorized);
|
||||
}
|
||||
|
||||
private static string ResolveSource(string agentId) => agentId switch
|
||||
{
|
||||
"bao" or "nexus-system" => "bao",
|
||||
_ => agentId
|
||||
};
|
||||
|
||||
private static ActionResult MapResult<T>(TaskBridgeResult<T> result, string command) where T : class
|
||||
{
|
||||
if (result.Outcome == TaskBridgeOutcome.Success)
|
||||
return new OkObjectResult(new TaskBridgeCommandResponse<T>
|
||||
{
|
||||
Ok = true,
|
||||
Command = command,
|
||||
Data = result.Data
|
||||
});
|
||||
|
||||
var statusCode = result.Outcome switch
|
||||
{
|
||||
TaskBridgeOutcome.NotFound => 404,
|
||||
TaskBridgeOutcome.InvalidState => 422,
|
||||
TaskBridgeOutcome.Unauthorized => 403,
|
||||
TaskBridgeOutcome.ValidationError => 400,
|
||||
_ => 500
|
||||
};
|
||||
|
||||
return new ObjectResult(new TaskBridgeCommandResponse<T>
|
||||
{
|
||||
Ok = false,
|
||||
Command = command,
|
||||
Error = result.Error ?? "Unknown error"
|
||||
}) { StatusCode = statusCode };
|
||||
}
|
||||
|
||||
private static ActionResult MapActivityResult(TaskBridgeResult<Data.ActivityEvent> result, string command)
|
||||
{
|
||||
if (result.Outcome == TaskBridgeOutcome.Success)
|
||||
return new OkObjectResult(new TaskBridgeCommandResponse<ActivityEntryDto>
|
||||
{
|
||||
Ok = true,
|
||||
Command = command,
|
||||
Data = result.Data is null ? null : new ActivityEntryDto(
|
||||
result.Data.Id, result.Data.Type, result.Data.Message, result.Data.CreatedAt)
|
||||
});
|
||||
|
||||
var statusCode = result.Outcome switch
|
||||
{
|
||||
TaskBridgeOutcome.NotFound => 404,
|
||||
TaskBridgeOutcome.ValidationError => 400,
|
||||
_ => 500
|
||||
};
|
||||
|
||||
return new ObjectResult(new TaskBridgeCommandResponse<ActivityEntryDto>
|
||||
{
|
||||
Ok = false,
|
||||
Command = command,
|
||||
Error = result.Error ?? "Unknown error"
|
||||
}) { StatusCode = statusCode };
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class TaskBridgeCommandResponse<T>
|
||||
{
|
||||
public bool Ok { get; init; }
|
||||
public string Command { get; init; } = string.Empty;
|
||||
public T? Data { get; init; }
|
||||
public string? Error { get; init; }
|
||||
public string Timestamp { get; init; } = DateTimeOffset.UtcNow.ToString("o");
|
||||
}
|
||||
|
||||
public sealed record BridgeCreateTaskCommand(
|
||||
string Title,
|
||||
string? Detail = null,
|
||||
string? Priority = null,
|
||||
string? AssignedTo = null,
|
||||
Guid? ProjectId = null
|
||||
);
|
||||
|
||||
public sealed record BridgeCreateChildTaskCommand(
|
||||
string Title,
|
||||
string? Detail = null,
|
||||
string? Priority = null,
|
||||
string? AssignedTo = null,
|
||||
string? ExpectedFrom = null,
|
||||
bool StartsInProgress = false
|
||||
);
|
||||
|
||||
public sealed record BridgeUpdateStatusCommand(string State);
|
||||
|
||||
public sealed record BridgeAppendActivityCommand(
|
||||
string Message,
|
||||
string? Type = null
|
||||
);
|
||||
|
||||
public sealed record BridgeHandoffCommand(
|
||||
string TargetAgent,
|
||||
string? Note = null
|
||||
);
|
||||
|
||||
public sealed record ActivityEntryDto(
|
||||
long Id,
|
||||
string Type,
|
||||
string Message,
|
||||
DateTimeOffset CreatedAt
|
||||
);
|
||||
@@ -1,3 +1,4 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||
using Nexus.Api.Integrations;
|
||||
@@ -7,6 +8,7 @@ namespace Nexus.Api.Controllers;
|
||||
[ApiController]
|
||||
public class HealthController(IAgentRuntime runtime, HealthCheckService healthChecks) : ControllerBase
|
||||
{
|
||||
[AllowAnonymous]
|
||||
[HttpGet("/health/live")]
|
||||
public IResult Live()
|
||||
{
|
||||
@@ -32,20 +34,25 @@ public class HealthController(IAgentRuntime runtime, HealthCheckService healthCh
|
||||
runtimeDetail = ex.Message;
|
||||
}
|
||||
|
||||
static IReadOnlyDictionary<string, object?> NormalizeData(IReadOnlyDictionary<string, object> source)
|
||||
{
|
||||
return source.ToDictionary(kvp => kvp.Key, kvp => (object?)kvp.Value);
|
||||
}
|
||||
|
||||
var entries = report.Entries.ToDictionary(
|
||||
e => e.Key,
|
||||
e => new
|
||||
{
|
||||
status = e.Value.Status.ToString(),
|
||||
description = e.Value.Description,
|
||||
data = e.Value.Data
|
||||
data = NormalizeData(e.Value.Data)
|
||||
});
|
||||
|
||||
entries["runtime"] = new
|
||||
{
|
||||
status = runtimeStatus,
|
||||
description = runtimeDetail ?? "Runtime status checked",
|
||||
data = (IReadOnlyDictionary<string, object>)new Dictionary<string, object>()
|
||||
description = runtimeDetail,
|
||||
data = new Dictionary<string, object?>() as IReadOnlyDictionary<string, object?>
|
||||
};
|
||||
|
||||
var isHealthy = report.Status == HealthStatus.Healthy && runtimeStatus == "Online";
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Nexus.Api.Data;
|
||||
using Nexus.Api.Models;
|
||||
using Nexus.Api.Services;
|
||||
|
||||
namespace Nexus.Api.Controllers;
|
||||
|
||||
[Authorize]
|
||||
[ApiController]
|
||||
[Route("api/dashboard/notifications")]
|
||||
public class NotificationsController(INotificationService notificationService) : ControllerBase
|
||||
{
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<List<NotificationDto>>> GetNotifications(
|
||||
[FromQuery] string forUser = "bao",
|
||||
[FromQuery] int limit = 50,
|
||||
[FromQuery] bool unreadOnly = false,
|
||||
CancellationToken ct = default)
|
||||
{
|
||||
var notifications = await notificationService.GetForUserAsync(forUser, limit, unreadOnly, ct);
|
||||
return Ok(notifications.Select(MapToDto).ToList());
|
||||
}
|
||||
|
||||
[HttpGet("unread-count")]
|
||||
public async Task<ActionResult<UnreadCountDto>> GetUnreadCount(
|
||||
[FromQuery] string forUser = "bao",
|
||||
CancellationToken ct = default)
|
||||
{
|
||||
var count = await notificationService.GetUnreadCountAsync(forUser, ct);
|
||||
return Ok(new UnreadCountDto(count));
|
||||
}
|
||||
|
||||
[HttpGet("snapshot")]
|
||||
public async Task<ActionResult<NotificationSnapshotDto>> GetSnapshot(
|
||||
[FromQuery] string forUser = "bao",
|
||||
[FromQuery] int limit = 50,
|
||||
[FromQuery] bool unreadOnly = false,
|
||||
CancellationToken ct = default)
|
||||
{
|
||||
return Ok(await notificationService.GetSnapshotAsync(forUser, limit, unreadOnly, ct));
|
||||
}
|
||||
|
||||
[HttpPatch("{id:guid}/read")]
|
||||
public async Task<ActionResult> MarkAsRead(Guid id, CancellationToken ct = default)
|
||||
{
|
||||
var ok = await notificationService.MarkAsReadAsync(id, ct);
|
||||
return ok ? NoContent() : NotFound(new { error = "Notification not found." });
|
||||
}
|
||||
|
||||
[HttpPatch("read-all")]
|
||||
public async Task<ActionResult> MarkAllAsRead(
|
||||
[FromQuery] string forUser = "bao",
|
||||
CancellationToken ct = default)
|
||||
{
|
||||
var count = await notificationService.MarkAllAsReadAsync(forUser, ct);
|
||||
return Ok(new { marked = count });
|
||||
}
|
||||
|
||||
private static NotificationDto MapToDto(Notification n) => new(
|
||||
n.Id, n.Type, n.Title, n.Message,
|
||||
n.ForUser, n.TaskId, n.IsRead, n.CreatedAt);
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Nexus.Api.DTOs;
|
||||
using Nexus.Api.Services;
|
||||
|
||||
namespace Nexus.Api.Controllers;
|
||||
|
||||
[Authorize]
|
||||
[ApiController]
|
||||
[Route("api/v1/projects")]
|
||||
public class ProjectsController(IProjectService projectService) : ControllerBase
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Nexus.Api.Data;
|
||||
using Nexus.Api.DTOs;
|
||||
using Nexus.Api.Models;
|
||||
using Nexus.Api.Services;
|
||||
|
||||
namespace Nexus.Api.Controllers;
|
||||
|
||||
[Authorize]
|
||||
[ApiController]
|
||||
[Route("api/v1/tasks")]
|
||||
public class TasksController(ITaskService taskService) : ControllerBase
|
||||
public class TasksController(ITaskService taskService, IAgentService agentService, IConfiguration configuration) : ControllerBase
|
||||
{
|
||||
[HttpGet]
|
||||
public async Task<IResult> GetAll(CancellationToken ct)
|
||||
@@ -70,6 +73,10 @@ public class TasksController(ITaskService taskService) : ControllerBase
|
||||
return result.Outcome switch
|
||||
{
|
||||
TaskOperationOutcome.NotFound => Results.NotFound(),
|
||||
TaskOperationOutcome.InvalidState => Results.Problem(
|
||||
title: "Action denied",
|
||||
detail: "Statusänderungen sind nur Iris und Bao vorbehalten. Sub-Agenten können Tasks nicht verschieben.",
|
||||
statusCode: StatusCodes.Status403Forbidden),
|
||||
_ => Results.Ok(result.Task)
|
||||
};
|
||||
}
|
||||
@@ -99,4 +106,58 @@ public class TasksController(ITaskService taskService) : ControllerBase
|
||||
_ => Results.NoContent()
|
||||
};
|
||||
}
|
||||
|
||||
// ── Board & Stale-Reset (für Iris Autonomous Worker) ──
|
||||
|
||||
/// <summary>
|
||||
/// Gibt das Task-Board zurück (gruppiert nach Status, priorisiert sortiert).
|
||||
/// Wird vom Iris Autonomous Worker genutzt.
|
||||
///
|
||||
/// SICHERHEIT: Erfordert X-Agent-Id Header (bel. erkannter Agent) ODER
|
||||
/// X-Nexus-Api-Key / JWT. Kein [AllowAnonymous] mehr.
|
||||
/// Für Agent-zu-Agent-Kommunikation den /api/bridge/board Endpunkt nutzen.
|
||||
/// </summary>
|
||||
[AllowAnonymous]
|
||||
[HttpGet("board")]
|
||||
public async Task<IResult> GetBoard(CancellationToken ct)
|
||||
{
|
||||
var agentHeader = await RequestAuthorizationHelper.ResolveAllowedAgentHeaderAsync(HttpContext, agentService, ct);
|
||||
var isApiKey = RequestAuthorizationHelper.IsAuthenticatedService(HttpContext, configuration);
|
||||
var isAuth = HttpContext.User.Identity?.IsAuthenticated == true;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(agentHeader) && !isApiKey && !isAuth)
|
||||
return Results.Unauthorized();
|
||||
|
||||
return Results.Ok(await taskService.GetBoardAsync(ct));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Setzt stale Tasks (InProgress, älter als N Stunden) zurück auf Backlog.
|
||||
/// Wird vom Iris Autonomous Worker genutzt.
|
||||
///
|
||||
/// SICHERHEIT: Erfordert X-Agent-Id Header (nur iris) ODER
|
||||
/// X-Nexus-Api-Key / Service-Principal ODER owner/admin JWT.
|
||||
/// Für Agent-zu-Agent-Kommunikation den /api/bridge Endpunkt nutzen.
|
||||
/// </summary>
|
||||
[AllowAnonymous]
|
||||
[HttpPost("reset-stale")]
|
||||
public async Task<IResult> ResetStale([FromBody] ResetStaleRequest request, CancellationToken ct)
|
||||
{
|
||||
var agentHeaderResolution = await RequestAuthorizationHelper.ResolveAgentHeaderAsync(HttpContext, agentService, ct);
|
||||
var isService = RequestAuthorizationHelper.IsAuthenticatedService(HttpContext, configuration);
|
||||
var isPrivilegedUser = RequestAuthorizationHelper.IsPrivilegedUser(HttpContext);
|
||||
|
||||
var isIris = string.Equals(agentHeaderResolution.AgentId, "iris", StringComparison.OrdinalIgnoreCase);
|
||||
if (!isIris && !isService && !isPrivilegedUser)
|
||||
{
|
||||
// A presented but unrecognized agent header is an invalid credential, not a missing one.
|
||||
if (HttpContext.User.Identity?.IsAuthenticated == true || agentHeaderResolution.HeaderProvided)
|
||||
return Results.Forbid();
|
||||
|
||||
return Results.Unauthorized();
|
||||
}
|
||||
|
||||
var count = await taskService.ResetStaleAsync(request.StaleHours, ct);
|
||||
return Results.Ok(new ResetStaleResponse(count));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,29 @@ public sealed record UserInfo
|
||||
public string Role { get; init; } = string.Empty;
|
||||
}
|
||||
|
||||
public sealed record AdminUserInfo
|
||||
{
|
||||
public Guid Id { get; init; }
|
||||
public string Email { get; init; } = string.Empty;
|
||||
public string DisplayName { get; init; } = string.Empty;
|
||||
public string Role { get; init; } = string.Empty;
|
||||
public DateTimeOffset CreatedAt { get; init; }
|
||||
public DateTimeOffset? LastLoginAt { get; init; }
|
||||
}
|
||||
|
||||
public sealed record AdminCreateUserRequest
|
||||
{
|
||||
public string Email { get; init; } = string.Empty;
|
||||
public string Password { get; init; } = string.Empty;
|
||||
public string? DisplayName { get; init; }
|
||||
public string? Role { get; init; }
|
||||
}
|
||||
|
||||
public sealed record AdminUpdateRoleRequest
|
||||
{
|
||||
public string Role { get; init; } = string.Empty;
|
||||
}
|
||||
|
||||
public sealed record UpdateProfileRequest
|
||||
{
|
||||
[MaxLength(100)]
|
||||
|
||||
@@ -12,3 +12,4 @@ public sealed record IncidentInfoDto(
|
||||
string? Title,
|
||||
DateTimeOffset? Since
|
||||
);
|
||||
|
||||
|
||||
+120
-4
@@ -19,7 +19,8 @@ public enum TaskState
|
||||
Backlog,
|
||||
InProgress,
|
||||
Blocked,
|
||||
Done
|
||||
Done,
|
||||
Review
|
||||
}
|
||||
|
||||
public static class TaskStateHelper
|
||||
@@ -29,7 +30,8 @@ public static class TaskStateHelper
|
||||
[TaskState.Backlog] = "Backlog",
|
||||
[TaskState.InProgress] = "In progress",
|
||||
[TaskState.Blocked] = "Blocked",
|
||||
[TaskState.Done] = "Done"
|
||||
[TaskState.Done] = "Done",
|
||||
[TaskState.Review] = "Review"
|
||||
};
|
||||
|
||||
private static readonly Dictionary<string, TaskState> StringToState = new(StringComparer.OrdinalIgnoreCase)
|
||||
@@ -37,11 +39,22 @@ public static class TaskStateHelper
|
||||
["Backlog"] = TaskState.Backlog,
|
||||
["In progress"] = TaskState.InProgress,
|
||||
["Blocked"] = TaskState.Blocked,
|
||||
["Done"] = TaskState.Done
|
||||
["Done"] = TaskState.Done,
|
||||
["Review"] = TaskState.Review
|
||||
};
|
||||
|
||||
/// <summary>Mapping from state string to display label.</summary>
|
||||
private static readonly Dictionary<string, string> DisplayLabels = new(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
["Backlog"] = "Offen",
|
||||
["In progress"] = "In Bearbeitung",
|
||||
["Review"] = "Review",
|
||||
["Blocked"] = "Blockiert",
|
||||
["Done"] = "Erledigt"
|
||||
};
|
||||
|
||||
/// <summary>Valid task-state string values for API validation.</summary>
|
||||
public static readonly string[] AllStates = ["Backlog", "In progress", "Blocked", "Done"];
|
||||
public static readonly string[] AllStates = ["Backlog", "In progress", "Blocked", "Done", "Review"];
|
||||
|
||||
/// <summary>Convert a TaskState enum to its API string representation.</summary>
|
||||
public static string ToStateString(this TaskState state) => StateToString[state];
|
||||
@@ -54,6 +67,10 @@ public static class TaskStateHelper
|
||||
public static bool IsValidState(string? state) =>
|
||||
!string.IsNullOrWhiteSpace(state) && StringToState.ContainsKey(state);
|
||||
|
||||
/// <summary>Returns the German display label for a state string.</summary>
|
||||
public static string ToDisplayString(string? state) =>
|
||||
state is not null && DisplayLabels.TryGetValue(state, out var label) ? label : state ?? "";
|
||||
|
||||
public static bool IsInProgressOrBlocked(string? state) =>
|
||||
string.Equals(state, "In progress", StringComparison.OrdinalIgnoreCase)
|
||||
|| string.Equals(state, "Blocked", StringComparison.OrdinalIgnoreCase);
|
||||
@@ -61,6 +78,75 @@ public static class TaskStateHelper
|
||||
public static bool IsDoneOrBacklog(string? state) =>
|
||||
string.Equals(state, "Done", StringComparison.OrdinalIgnoreCase)
|
||||
|| string.Equals(state, "Backlog", StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the caller is allowed to change this task's state.
|
||||
/// POLICY:
|
||||
/// - **Iris und Bao** dürfen Status ändern / verschieben.
|
||||
/// - Sub-agents (programmer, reviewer, architekt, researcher, executor) dürfen NIEMALS Status ändern.
|
||||
/// - 'nexus-system' ist ein technischer Fallback für automatische Cron/Reset-Workflows.
|
||||
/// - Jeder andere (unbekannt, leer) wird abgewiesen.
|
||||
/// </summary>
|
||||
public static bool CanChangeState(string? callerAgent, WorkTask task)
|
||||
{
|
||||
var caller = callerAgent?.Trim().ToLowerInvariant() ?? "";
|
||||
|
||||
// Sub-agents must never move state
|
||||
var subAgents = new HashSet<string> { "programmer", "reviewer", "architekt", "researcher", "executor" };
|
||||
if (subAgents.Contains(caller)) return false;
|
||||
|
||||
// Technischer Fallback: nur für interne System-Operationen (Cron, ResetStale)
|
||||
if (caller == "nexus-system") return true;
|
||||
|
||||
// Iris und Bao dürfen Status ändern
|
||||
return caller == "iris" || caller == "bao";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the caller is allowed to edit a task's content fields
|
||||
/// (title, detail, priority, assignedTo, dueDate).
|
||||
/// POLICY:
|
||||
/// - Alle (iris, bao, sub-agents, nexus-system) dürfen inhaltlich bearbeiten.
|
||||
/// - Nur unbekannte/leere Caller werden abgewiesen.
|
||||
/// </summary>
|
||||
public static bool CanEditContent(string? callerAgent)
|
||||
{
|
||||
var caller = callerAgent?.Trim().ToLowerInvariant() ?? "";
|
||||
if (string.IsNullOrWhiteSpace(caller)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>Group key for board responses (lowercased English state).</summary>
|
||||
public static string BoardGroupKey(string? state)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(state)) return "offen";
|
||||
var lower = state.ToLowerInvariant();
|
||||
return lower switch
|
||||
{
|
||||
"backlog" => "offen",
|
||||
"in progress" => "inProgress",
|
||||
"review" => "review",
|
||||
"blocked" => "blocked",
|
||||
"done" => "done",
|
||||
_ => "offen"
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>Map a board group key back to the canonical state string.</summary>
|
||||
public static string? BoardGroupToState(string? groupKey)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(groupKey)) return null;
|
||||
var lower = groupKey.ToLowerInvariant();
|
||||
return lower switch
|
||||
{
|
||||
"offen" => "Backlog",
|
||||
"inprogress" => "In progress",
|
||||
"review" => "Review",
|
||||
"blocked" => "Blocked",
|
||||
"done" => "Done",
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class Project
|
||||
@@ -82,15 +168,45 @@ public sealed class WorkTask
|
||||
public string Priority { get; set; } = "Normal";
|
||||
public string Source { get; set; } = "bao";
|
||||
public string? AssignedTo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// True if this task was created programmatically by an agent (not manually by Bao).
|
||||
/// Agent-tasks in the board are subject to stricter workflow rules.
|
||||
/// </summary>
|
||||
public bool IsAgentTask { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Which agent/user is expected to respond next.
|
||||
/// Helps Iris see who she is waiting for.
|
||||
/// </summary>
|
||||
public string? ExpectedFrom { get; set; }
|
||||
|
||||
public Guid? ParentTaskId { get; set; }
|
||||
public WorkTask? ParentTask { get; set; }
|
||||
public ICollection<WorkTask> ChildTasks { get; set; } = new List<WorkTask>();
|
||||
public Guid? ProjectId { get; set; }
|
||||
public DateTimeOffset? DueDate { get; set; }
|
||||
public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.UtcNow;
|
||||
public DateTimeOffset UpdatedAt { get; set; } = DateTimeOffset.UtcNow;
|
||||
}
|
||||
|
||||
public sealed class Notification
|
||||
{
|
||||
public Guid Id { get; init; } = Guid.NewGuid();
|
||||
public required string Type { get; set; } // "task_assigned", "task_review", "task_blocked"
|
||||
public required string Title { get; set; } // "Neue Aufgabe: Memory-Index reparieren"
|
||||
public string? Message { get; set; } // Detailtext
|
||||
public required string ForUser { get; set; } // "bao" oder "iris"
|
||||
public Guid? TaskId { get; set; } // Verknüpfte Task
|
||||
public bool IsRead { get; set; } = false;
|
||||
public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.UtcNow;
|
||||
}
|
||||
|
||||
public sealed class ActivityEvent
|
||||
{
|
||||
public long Id { get; init; }
|
||||
public required string Type { get; set; }
|
||||
public required string Message { get; set; }
|
||||
public Guid? TaskId { get; set; }
|
||||
public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.UtcNow;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace Nexus.Api.Data;
|
||||
|
||||
@@ -28,6 +29,21 @@ public class NexusUser
|
||||
public ICollection<RefreshToken> RefreshTokens { get; set; } = new List<RefreshToken>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tracks one-time seed operations so they are never re-executed — even
|
||||
/// if the underlying data is deleted. This is the single guard that
|
||||
/// prevents owner-password drift after DB resets or volume recreations.
|
||||
/// </summary>
|
||||
[Table("SeedAudit")]
|
||||
public class SeedAudit
|
||||
{
|
||||
[Key]
|
||||
[MaxLength(80)]
|
||||
public string Key { get; set; } = string.Empty;
|
||||
|
||||
public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.UtcNow;
|
||||
}
|
||||
|
||||
public class RefreshToken
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
|
||||
@@ -0,0 +1,311 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Nexus.Api.Data;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Nexus.Api.Migrations
|
||||
{
|
||||
[DbContext(typeof(NexusDbContext))]
|
||||
[Migration("20260618214335_AddNotifications")]
|
||||
partial class AddNotifications
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "10.0.8")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.ActivityEvent", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Message")
|
||||
.IsRequired()
|
||||
.HasMaxLength(1000)
|
||||
.HasColumnType("character varying(1000)");
|
||||
|
||||
b.Property<Guid?>("TaskId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("Type")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("CreatedAt");
|
||||
|
||||
b.HasIndex("TaskId");
|
||||
|
||||
b.ToTable("Activity");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.NexusUser", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("DisplayName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasMaxLength(120)
|
||||
.HasColumnType("character varying(120)");
|
||||
|
||||
b.Property<DateTimeOffset?>("LastLoginAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("NormalizedEmail")
|
||||
.IsRequired()
|
||||
.HasMaxLength(120)
|
||||
.HasColumnType("character varying(120)");
|
||||
|
||||
b.Property<string>("PasswordHash")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Role")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTimeOffset>("UpdatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("NormalizedEmail")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.Notification", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("ForUser")
|
||||
.IsRequired()
|
||||
.HasMaxLength(60)
|
||||
.HasColumnType("character varying(60)");
|
||||
|
||||
b.Property<bool>("IsRead")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("Message")
|
||||
.HasMaxLength(1000)
|
||||
.HasColumnType("character varying(1000)");
|
||||
|
||||
b.Property<Guid?>("TaskId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasMaxLength(240)
|
||||
.HasColumnType("character varying(240)");
|
||||
|
||||
b.Property<string>("Type")
|
||||
.IsRequired()
|
||||
.HasMaxLength(60)
|
||||
.HasColumnType("character varying(60)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ForUser", "IsRead", "CreatedAt");
|
||||
|
||||
b.ToTable("Notifications");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.Project", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(160)
|
||||
.HasColumnType("character varying(160)");
|
||||
|
||||
b.Property<int>("Progress")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTimeOffset>("UpdatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Projects");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.RefreshToken", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Guid>("ConcurrencyStamp")
|
||||
.IsConcurrencyToken()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTimeOffset>("ExpiresAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Guid>("FamilyId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("ReplacedByTokenHash")
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("character varying(64)");
|
||||
|
||||
b.Property<DateTimeOffset?>("RevokedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("TokenHash")
|
||||
.IsRequired()
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("character varying(64)");
|
||||
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("TokenHash")
|
||||
.IsUnique();
|
||||
|
||||
b.HasIndex("UserId", "FamilyId");
|
||||
|
||||
b.ToTable("RefreshTokens");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.WorkTask", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("AssignedTo")
|
||||
.HasMaxLength(60)
|
||||
.HasColumnType("character varying(60)");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Detail")
|
||||
.HasMaxLength(2000)
|
||||
.HasColumnType("character varying(2000)");
|
||||
|
||||
b.Property<DateTimeOffset?>("DueDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Guid?>("ParentTaskId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("Priority")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<Guid?>("ProjectId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("Source")
|
||||
.IsRequired()
|
||||
.HasMaxLength(60)
|
||||
.HasColumnType("character varying(60)");
|
||||
|
||||
b.Property<string>("State")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasMaxLength(240)
|
||||
.HasColumnType("character varying(240)");
|
||||
|
||||
b.Property<DateTimeOffset>("UpdatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("AssignedTo");
|
||||
|
||||
b.HasIndex("ParentTaskId");
|
||||
|
||||
b.HasIndex("Source");
|
||||
|
||||
b.ToTable("Tasks");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.RefreshToken", b =>
|
||||
{
|
||||
b.HasOne("Nexus.Api.Data.NexusUser", "User")
|
||||
.WithMany("RefreshTokens")
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.WorkTask", b =>
|
||||
{
|
||||
b.HasOne("Nexus.Api.Data.WorkTask", "ParentTask")
|
||||
.WithMany("ChildTasks")
|
||||
.HasForeignKey("ParentTaskId")
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
b.Navigation("ParentTask");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.NexusUser", b =>
|
||||
{
|
||||
b.Navigation("RefreshTokens");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.WorkTask", b =>
|
||||
{
|
||||
b.Navigation("ChildTasks");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Nexus.Api.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddNotifications : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Notifications",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
Type = table.Column<string>(type: "character varying(60)", maxLength: 60, nullable: false),
|
||||
Title = table.Column<string>(type: "character varying(240)", maxLength: 240, nullable: false),
|
||||
Message = table.Column<string>(type: "character varying(1000)", maxLength: 1000, nullable: true),
|
||||
ForUser = table.Column<string>(type: "character varying(60)", maxLength: 60, nullable: false),
|
||||
TaskId = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
IsRead = table.Column<bool>(type: "boolean", nullable: false),
|
||||
CreatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Notifications", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Notifications_ForUser_IsRead_CreatedAt",
|
||||
table: "Notifications",
|
||||
columns: new[] { "ForUser", "IsRead", "CreatedAt" });
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Notifications");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Nexus.Api.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddTaskParentChild : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<Guid>(
|
||||
name: "ParentTaskId",
|
||||
table: "Tasks",
|
||||
type: "uuid",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Tasks_ParentTaskId",
|
||||
table: "Tasks",
|
||||
column: "ParentTaskId");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Tasks_Tasks_ParentTaskId",
|
||||
table: "Tasks",
|
||||
column: "ParentTaskId",
|
||||
principalTable: "Tasks",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.SetNull);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Tasks_Tasks_ParentTaskId",
|
||||
table: "Tasks");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Tasks_ParentTaskId",
|
||||
table: "Tasks");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "ParentTaskId",
|
||||
table: "Tasks");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Nexus.Api.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddTaskDueDate : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<DateTimeOffset>(
|
||||
name: "DueDate",
|
||||
table: "Tasks",
|
||||
type: "timestamp with time zone",
|
||||
nullable: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "DueDate",
|
||||
table: "Tasks");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Nexus.Api.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddActivityTaskReference : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<Guid>(
|
||||
name: "TaskId",
|
||||
table: "Activity",
|
||||
type: "uuid",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Activity_TaskId",
|
||||
table: "Activity",
|
||||
column: "TaskId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Activity_TaskId",
|
||||
table: "Activity");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "TaskId",
|
||||
table: "Activity");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,270 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Nexus.Api.Data;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Nexus.Api.Migrations
|
||||
{
|
||||
[DbContext(typeof(NexusDbContext))]
|
||||
[Migration("20260618233003_AddDelegatedState")]
|
||||
partial class AddDelegatedState
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "10.0.8")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.ActivityEvent", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Message")
|
||||
.IsRequired()
|
||||
.HasMaxLength(1000)
|
||||
.HasColumnType("character varying(1000)");
|
||||
|
||||
b.Property<Guid?>("TaskId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("Type")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("CreatedAt");
|
||||
|
||||
b.HasIndex("TaskId");
|
||||
|
||||
b.ToTable("Activity");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.NexusUser", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("DisplayName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasMaxLength(120)
|
||||
.HasColumnType("character varying(120)");
|
||||
|
||||
b.Property<DateTimeOffset?>("LastLoginAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("NormalizedEmail")
|
||||
.IsRequired()
|
||||
.HasMaxLength(120)
|
||||
.HasColumnType("character varying(120)");
|
||||
|
||||
b.Property<string>("PasswordHash")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Role")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTimeOffset>("UpdatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("NormalizedEmail")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.Project", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(160)
|
||||
.HasColumnType("character varying(160)");
|
||||
|
||||
b.Property<int>("Progress")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTimeOffset>("UpdatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Projects");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.RefreshToken", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Guid>("ConcurrencyStamp")
|
||||
.IsConcurrencyToken()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTimeOffset>("ExpiresAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Guid>("FamilyId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("ReplacedByTokenHash")
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("character varying(64)");
|
||||
|
||||
b.Property<DateTimeOffset?>("RevokedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("TokenHash")
|
||||
.IsRequired()
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("character varying(64)");
|
||||
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("TokenHash")
|
||||
.IsUnique();
|
||||
|
||||
b.HasIndex("UserId", "FamilyId");
|
||||
|
||||
b.ToTable("RefreshTokens");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.WorkTask", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("AssignedTo")
|
||||
.HasMaxLength(60)
|
||||
.HasColumnType("character varying(60)");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Detail")
|
||||
.HasMaxLength(2000)
|
||||
.HasColumnType("character varying(2000)");
|
||||
|
||||
b.Property<DateTimeOffset?>("DueDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Guid?>("ParentTaskId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("Priority")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<Guid?>("ProjectId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("Source")
|
||||
.IsRequired()
|
||||
.HasMaxLength(60)
|
||||
.HasColumnType("character varying(60)");
|
||||
|
||||
b.Property<string>("State")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasMaxLength(240)
|
||||
.HasColumnType("character varying(240)");
|
||||
|
||||
b.Property<DateTimeOffset>("UpdatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("AssignedTo");
|
||||
|
||||
b.HasIndex("ParentTaskId");
|
||||
|
||||
b.HasIndex("Source");
|
||||
|
||||
b.ToTable("Tasks");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.RefreshToken", b =>
|
||||
{
|
||||
b.HasOne("Nexus.Api.Data.NexusUser", "User")
|
||||
.WithMany("RefreshTokens")
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.WorkTask", b =>
|
||||
{
|
||||
b.HasOne("Nexus.Api.Data.WorkTask", "ParentTask")
|
||||
.WithMany("ChildTasks")
|
||||
.HasForeignKey("ParentTaskId")
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
b.Navigation("ParentTask");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.NexusUser", b =>
|
||||
{
|
||||
b.Navigation("RefreshTokens");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.WorkTask", b =>
|
||||
{
|
||||
b.Navigation("ChildTasks");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Nexus.Api.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddDelegatedState : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
// Delegated state is a pure code change to the TaskState enum and
|
||||
// TaskStateHelper. No schema change required since the State column
|
||||
// is already a free-form string column.
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
// No schema to revert.
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,322 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Nexus.Api.Data;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Nexus.Api.Migrations
|
||||
{
|
||||
[DbContext(typeof(NexusDbContext))]
|
||||
[Migration("20260620174200_AddAgentTaskFields")]
|
||||
partial class AddAgentTaskFields
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "10.0.8")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.ActivityEvent", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Message")
|
||||
.IsRequired()
|
||||
.HasMaxLength(1000)
|
||||
.HasColumnType("character varying(1000)");
|
||||
|
||||
b.Property<Guid?>("TaskId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("Type")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("CreatedAt");
|
||||
|
||||
b.HasIndex("TaskId");
|
||||
|
||||
b.ToTable("Activity");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.NexusUser", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("DisplayName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasMaxLength(120)
|
||||
.HasColumnType("character varying(120)");
|
||||
|
||||
b.Property<DateTimeOffset?>("LastLoginAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("NormalizedEmail")
|
||||
.IsRequired()
|
||||
.HasMaxLength(120)
|
||||
.HasColumnType("character varying(120)");
|
||||
|
||||
b.Property<string>("PasswordHash")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Role")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTimeOffset>("UpdatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("NormalizedEmail")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.Notification", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("ForUser")
|
||||
.IsRequired()
|
||||
.HasMaxLength(60)
|
||||
.HasColumnType("character varying(60)");
|
||||
|
||||
b.Property<bool>("IsRead")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("Message")
|
||||
.HasMaxLength(1000)
|
||||
.HasColumnType("character varying(1000)");
|
||||
|
||||
b.Property<Guid?>("TaskId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasMaxLength(240)
|
||||
.HasColumnType("character varying(240)");
|
||||
|
||||
b.Property<string>("Type")
|
||||
.IsRequired()
|
||||
.HasMaxLength(60)
|
||||
.HasColumnType("character varying(60)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ForUser", "IsRead", "CreatedAt");
|
||||
|
||||
b.ToTable("Notifications");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.Project", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(160)
|
||||
.HasColumnType("character varying(160)");
|
||||
|
||||
b.Property<int>("Progress")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTimeOffset>("UpdatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Projects");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.RefreshToken", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Guid>("ConcurrencyStamp")
|
||||
.IsConcurrencyToken()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTimeOffset>("ExpiresAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Guid>("FamilyId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("ReplacedByTokenHash")
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("character varying(64)");
|
||||
|
||||
b.Property<DateTimeOffset?>("RevokedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("TokenHash")
|
||||
.IsRequired()
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("character varying(64)");
|
||||
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("TokenHash")
|
||||
.IsUnique();
|
||||
|
||||
b.HasIndex("UserId", "FamilyId");
|
||||
|
||||
b.ToTable("RefreshTokens");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.WorkTask", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("AssignedTo")
|
||||
.HasMaxLength(60)
|
||||
.HasColumnType("character varying(60)");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Detail")
|
||||
.HasMaxLength(2000)
|
||||
.HasColumnType("character varying(2000)");
|
||||
|
||||
b.Property<DateTimeOffset?>("DueDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("ExpectedFrom")
|
||||
.HasMaxLength(60)
|
||||
.HasColumnType("character varying(60)");
|
||||
|
||||
b.Property<bool>("IsAgentTask")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<Guid?>("ParentTaskId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("Priority")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<Guid?>("ProjectId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("Source")
|
||||
.IsRequired()
|
||||
.HasMaxLength(60)
|
||||
.HasColumnType("character varying(60)");
|
||||
|
||||
b.Property<string>("State")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasMaxLength(240)
|
||||
.HasColumnType("character varying(240)");
|
||||
|
||||
b.Property<DateTimeOffset>("UpdatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("AssignedTo");
|
||||
|
||||
b.HasIndex("ExpectedFrom");
|
||||
|
||||
b.HasIndex("IsAgentTask");
|
||||
|
||||
b.HasIndex("ParentTaskId");
|
||||
|
||||
b.HasIndex("Source");
|
||||
|
||||
b.ToTable("Tasks");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.RefreshToken", b =>
|
||||
{
|
||||
b.HasOne("Nexus.Api.Data.NexusUser", "User")
|
||||
.WithMany("RefreshTokens")
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.WorkTask", b =>
|
||||
{
|
||||
b.HasOne("Nexus.Api.Data.WorkTask", "ParentTask")
|
||||
.WithMany("ChildTasks")
|
||||
.HasForeignKey("ParentTaskId")
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
b.Navigation("ParentTask");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.NexusUser", b =>
|
||||
{
|
||||
b.Navigation("RefreshTokens");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.WorkTask", b =>
|
||||
{
|
||||
b.Navigation("ChildTasks");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Nexus.Api.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddAgentTaskFields : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<bool>(
|
||||
name: "IsAgentTask",
|
||||
table: "Tasks",
|
||||
type: "boolean",
|
||||
nullable: false,
|
||||
defaultValue: false);
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "ExpectedFrom",
|
||||
table: "Tasks",
|
||||
type: "character varying(60)",
|
||||
maxLength: 60,
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Tasks_IsAgentTask",
|
||||
table: "Tasks",
|
||||
column: "IsAgentTask");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Tasks_ExpectedFrom",
|
||||
table: "Tasks",
|
||||
column: "ExpectedFrom");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Tasks_IsAgentTask",
|
||||
table: "Tasks");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Tasks_ExpectedFrom",
|
||||
table: "Tasks");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "ExpectedFrom",
|
||||
table: "Tasks");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "IsAgentTask",
|
||||
table: "Tasks");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,336 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Nexus.Api.Data;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Nexus.Api.Migrations
|
||||
{
|
||||
[DbContext(typeof(NexusDbContext))]
|
||||
[Migration("20260621081500_AddSeedAudit")]
|
||||
partial class AddSeedAudit
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "10.0.8")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.ActivityEvent", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Message")
|
||||
.IsRequired()
|
||||
.HasMaxLength(1000)
|
||||
.HasColumnType("character varying(1000)");
|
||||
|
||||
b.Property<Guid?>("TaskId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("Type")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("CreatedAt");
|
||||
|
||||
b.HasIndex("TaskId");
|
||||
|
||||
b.ToTable("Activity");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.NexusUser", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("DisplayName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasMaxLength(120)
|
||||
.HasColumnType("character varying(120)");
|
||||
|
||||
b.Property<DateTimeOffset?>("LastLoginAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("NormalizedEmail")
|
||||
.IsRequired()
|
||||
.HasMaxLength(120)
|
||||
.HasColumnType("character varying(120)");
|
||||
|
||||
b.Property<string>("PasswordHash")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Role")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTimeOffset>("UpdatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("NormalizedEmail")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.Notification", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("ForUser")
|
||||
.IsRequired()
|
||||
.HasMaxLength(60)
|
||||
.HasColumnType("character varying(60)");
|
||||
|
||||
b.Property<bool>("IsRead")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("Message")
|
||||
.HasMaxLength(1000)
|
||||
.HasColumnType("character varying(1000)");
|
||||
|
||||
b.Property<Guid?>("TaskId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasMaxLength(240)
|
||||
.HasColumnType("character varying(240)");
|
||||
|
||||
b.Property<string>("Type")
|
||||
.IsRequired()
|
||||
.HasMaxLength(60)
|
||||
.HasColumnType("character varying(60)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ForUser", "IsRead", "CreatedAt");
|
||||
|
||||
b.ToTable("Notifications");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.Project", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(160)
|
||||
.HasColumnType("character varying(160)");
|
||||
|
||||
b.Property<int>("Progress")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTimeOffset>("UpdatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Projects");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.RefreshToken", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Guid>("ConcurrencyStamp")
|
||||
.IsConcurrencyToken()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTimeOffset>("ExpiresAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Guid>("FamilyId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("ReplacedByTokenHash")
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("character varying(64)");
|
||||
|
||||
b.Property<DateTimeOffset?>("RevokedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("TokenHash")
|
||||
.IsRequired()
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("character varying(64)");
|
||||
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("TokenHash")
|
||||
.IsUnique();
|
||||
|
||||
b.HasIndex("UserId", "FamilyId");
|
||||
|
||||
b.ToTable("RefreshTokens");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.SeedAudit", b =>
|
||||
{
|
||||
b.Property<string>("Key")
|
||||
.HasMaxLength(80)
|
||||
.HasColumnType("character varying(80)");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("Key");
|
||||
|
||||
b.ToTable("SeedAudit");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.WorkTask", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("AssignedTo")
|
||||
.HasMaxLength(60)
|
||||
.HasColumnType("character varying(60)");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Detail")
|
||||
.HasMaxLength(2000)
|
||||
.HasColumnType("character varying(2000)");
|
||||
|
||||
b.Property<DateTimeOffset?>("DueDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("ExpectedFrom")
|
||||
.HasMaxLength(60)
|
||||
.HasColumnType("character varying(60)");
|
||||
|
||||
b.Property<bool>("IsAgentTask")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<Guid?>("ParentTaskId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("Priority")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<Guid?>("ProjectId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("Source")
|
||||
.IsRequired()
|
||||
.HasMaxLength(60)
|
||||
.HasColumnType("character varying(60)");
|
||||
|
||||
b.Property<string>("State")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasMaxLength(240)
|
||||
.HasColumnType("character varying(240)");
|
||||
|
||||
b.Property<DateTimeOffset>("UpdatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("AssignedTo");
|
||||
|
||||
b.HasIndex("ExpectedFrom");
|
||||
|
||||
b.HasIndex("IsAgentTask");
|
||||
|
||||
b.HasIndex("ParentTaskId");
|
||||
|
||||
b.HasIndex("Source");
|
||||
|
||||
b.ToTable("Tasks");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.RefreshToken", b =>
|
||||
{
|
||||
b.HasOne("Nexus.Api.Data.NexusUser", "User")
|
||||
.WithMany("RefreshTokens")
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.WorkTask", b =>
|
||||
{
|
||||
b.HasOne("Nexus.Api.Data.WorkTask", "ParentTask")
|
||||
.WithMany("ChildTasks")
|
||||
.HasForeignKey("ParentTaskId")
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
b.Navigation("ParentTask");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.NexusUser", b =>
|
||||
{
|
||||
b.Navigation("RefreshTokens");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.WorkTask", b =>
|
||||
{
|
||||
b.Navigation("ChildTasks");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Nexus.Api.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddSeedAudit : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "SeedAudit",
|
||||
columns: table => new
|
||||
{
|
||||
Key = table.Column<string>(type: "character varying(80)", maxLength: 80, nullable: false),
|
||||
CreatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_SeedAudit", x => x.Key);
|
||||
});
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "SeedAudit");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -38,12 +38,19 @@ namespace Nexus.Api.Migrations
|
||||
.HasMaxLength(1000)
|
||||
.HasColumnType("character varying(1000)");
|
||||
|
||||
b.Property<Guid?>("TaskId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("Type")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("CreatedAt");
|
||||
|
||||
b.HasIndex("TaskId");
|
||||
|
||||
b.ToTable("Activity");
|
||||
});
|
||||
|
||||
@@ -93,6 +100,47 @@ namespace Nexus.Api.Migrations
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.Notification", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("ForUser")
|
||||
.IsRequired()
|
||||
.HasMaxLength(60)
|
||||
.HasColumnType("character varying(60)");
|
||||
|
||||
b.Property<bool>("IsRead")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("Message")
|
||||
.HasMaxLength(1000)
|
||||
.HasColumnType("character varying(1000)");
|
||||
|
||||
b.Property<Guid?>("TaskId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasMaxLength(240)
|
||||
.HasColumnType("character varying(240)");
|
||||
|
||||
b.Property<string>("Type")
|
||||
.IsRequired()
|
||||
.HasMaxLength(60)
|
||||
.HasColumnType("character varying(60)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ForUser", "IsRead", "CreatedAt");
|
||||
|
||||
b.ToTable("Notifications");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.Project", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
@@ -166,6 +214,20 @@ namespace Nexus.Api.Migrations
|
||||
b.ToTable("RefreshTokens");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.SeedAudit", b =>
|
||||
{
|
||||
b.Property<string>("Key")
|
||||
.HasMaxLength(80)
|
||||
.HasColumnType("character varying(80)");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("Key");
|
||||
|
||||
b.ToTable("SeedAudit");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.WorkTask", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
@@ -183,6 +245,19 @@ namespace Nexus.Api.Migrations
|
||||
.HasMaxLength(2000)
|
||||
.HasColumnType("character varying(2000)");
|
||||
|
||||
b.Property<DateTimeOffset?>("DueDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("ExpectedFrom")
|
||||
.HasMaxLength(60)
|
||||
.HasColumnType("character varying(60)");
|
||||
|
||||
b.Property<bool>("IsAgentTask")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<Guid?>("ParentTaskId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("Priority")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
@@ -211,6 +286,12 @@ namespace Nexus.Api.Migrations
|
||||
|
||||
b.HasIndex("AssignedTo");
|
||||
|
||||
b.HasIndex("ExpectedFrom");
|
||||
|
||||
b.HasIndex("IsAgentTask");
|
||||
|
||||
b.HasIndex("ParentTaskId");
|
||||
|
||||
b.HasIndex("Source");
|
||||
|
||||
b.ToTable("Tasks");
|
||||
@@ -227,10 +308,25 @@ namespace Nexus.Api.Migrations
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.WorkTask", b =>
|
||||
{
|
||||
b.HasOne("Nexus.Api.Data.WorkTask", "ParentTask")
|
||||
.WithMany("ChildTasks")
|
||||
.HasForeignKey("ParentTaskId")
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
b.Navigation("ParentTask");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.NexusUser", b =>
|
||||
{
|
||||
b.Navigation("RefreshTokens");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Nexus.Api.Data.WorkTask", b =>
|
||||
{
|
||||
b.Navigation("ChildTasks");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,11 @@ public sealed class NexusDbContext(DbContextOptions<NexusDbContext> options) : D
|
||||
{
|
||||
public DbSet<Project> Projects => Set<Project>();
|
||||
public DbSet<WorkTask> Tasks => Set<WorkTask>();
|
||||
public DbSet<Notification> Notifications => Set<Notification>();
|
||||
public DbSet<ActivityEvent> Activity => Set<ActivityEvent>();
|
||||
public DbSet<NexusUser> Users => Set<NexusUser>();
|
||||
public DbSet<RefreshToken> RefreshTokens => Set<RefreshToken>();
|
||||
public DbSet<SeedAudit> SeedAudits => Set<SeedAudit>();
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
@@ -19,10 +21,30 @@ public sealed class NexusDbContext(DbContextOptions<NexusDbContext> options) : D
|
||||
entity.Property(x => x.Detail).HasMaxLength(2000);
|
||||
entity.Property(x => x.Source).HasMaxLength(60);
|
||||
entity.Property(x => x.AssignedTo).HasMaxLength(60);
|
||||
entity.Property(x => x.ExpectedFrom).HasMaxLength(60);
|
||||
entity.HasIndex(x => x.Source);
|
||||
entity.HasIndex(x => x.AssignedTo);
|
||||
entity.HasIndex(x => x.IsAgentTask);
|
||||
entity.HasIndex(x => x.ExpectedFrom);
|
||||
entity.HasOne(x => x.ParentTask)
|
||||
.WithMany(x => x.ChildTasks)
|
||||
.HasForeignKey(x => x.ParentTaskId)
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
});
|
||||
modelBuilder.Entity<Notification>(entity =>
|
||||
{
|
||||
entity.Property(x => x.Title).HasMaxLength(240);
|
||||
entity.Property(x => x.Message).HasMaxLength(1000);
|
||||
entity.Property(x => x.Type).HasMaxLength(60);
|
||||
entity.Property(x => x.ForUser).HasMaxLength(60);
|
||||
entity.HasIndex(x => new { x.ForUser, x.IsRead, x.CreatedAt });
|
||||
});
|
||||
|
||||
modelBuilder.Entity<ActivityEvent>(entity =>
|
||||
{
|
||||
entity.Property(x => x.Message).HasMaxLength(1000);
|
||||
entity.HasIndex(x => x.TaskId);
|
||||
});
|
||||
modelBuilder.Entity<ActivityEvent>().Property(x => x.Message).HasMaxLength(1000);
|
||||
modelBuilder.Entity<NexusUser>().HasIndex(u => u.NormalizedEmail).IsUnique();
|
||||
modelBuilder.Entity<RefreshToken>().HasIndex(r => r.TokenHash).IsUnique();
|
||||
modelBuilder.Entity<RefreshToken>().HasIndex(r => new { r.UserId, r.FamilyId });
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Nexus.Api.Data;
|
||||
using Nexus.Api.Helpers;
|
||||
using Nexus.Api.Middleware;
|
||||
using Nexus.Api.Services;
|
||||
|
||||
namespace Nexus.Api.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for configuring the Nexus application pipeline and startup.
|
||||
/// </summary>
|
||||
public static class ApplicationBuilderExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Applies pending EF Core migrations and seeds the initial owner account if none exist.
|
||||
/// Uses a <see cref="SeedAudit"/> guard so the owner is never re-created even if all users
|
||||
/// are deleted — the DB is the single source of truth for the owner password after first seed.
|
||||
///
|
||||
/// Single-transaction guarantee: if the seed block is entered at all (user creation needed
|
||||
/// or just the audit-log write), the SeedAudit row is written inside the same transaction
|
||||
/// so that a crash mid-way can never leave the DB in a re-seedable state.
|
||||
/// </summary>
|
||||
public static async Task EnsureDatabaseAsync(this WebApplication app)
|
||||
{
|
||||
var configuration = app.Configuration;
|
||||
|
||||
await using (var scope = app.Services.CreateAsyncScope())
|
||||
{
|
||||
var db = scope.ServiceProvider.GetRequiredService<NexusDbContext>();
|
||||
await db.Database.MigrateAsync();
|
||||
|
||||
const string seedKey = "owner_created";
|
||||
var alreadySeeded = await db.SeedAudits.AnyAsync(s => s.Key == seedKey);
|
||||
if (alreadySeeded)
|
||||
return;
|
||||
|
||||
var ownerEmail = configuration["Bootstrap:OwnerEmail"]?.Trim().ToLowerInvariant();
|
||||
var hasUsers = await db.Users.AnyAsync();
|
||||
|
||||
// ── Double-check SeedAudit after the migration — if another pod wrote it
|
||||
// while we were reading, bail out early. ──
|
||||
alreadySeeded = await db.SeedAudits.AnyAsync(s => s.Key == seedKey);
|
||||
if (alreadySeeded)
|
||||
return;
|
||||
|
||||
// ── Use a strategy-based transaction so the user + audit row are
|
||||
// persisted atomically. If the DB crashes after SaveChanges the
|
||||
// entire transaction is rolled back, preventing partial-seed states.
|
||||
var strategy = db.Database.CreateExecutionStrategy();
|
||||
await strategy.ExecuteAsync(async () =>
|
||||
{
|
||||
await using var tx = await db.Database.BeginTransactionAsync();
|
||||
|
||||
if (!hasUsers)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(ownerEmail))
|
||||
throw new InvalidOperationException("Bootstrap:OwnerEmail is required for initial setup.");
|
||||
|
||||
var initialDisplayName = PasswordHelper.BuildOwnerDisplayName(ownerEmail);
|
||||
var initialPassword = PasswordHelper.GenerateTemporaryPassword();
|
||||
|
||||
db.Users.Add(new NexusUser
|
||||
{
|
||||
Email = ownerEmail,
|
||||
NormalizedEmail = AuthService.NormalizeEmail(ownerEmail),
|
||||
DisplayName = initialDisplayName,
|
||||
PasswordHash = PasswordSecurity.Hash(initialPassword),
|
||||
Role = "owner"
|
||||
});
|
||||
|
||||
Console.Error.WriteLine($"[nexus] Initial owner credentials generated: displayName={initialDisplayName}, password={initialPassword}");
|
||||
}
|
||||
|
||||
// Record the seed attempt regardless of whether users already existed.
|
||||
// This prevents re-seeding even if the Users table is wiped.
|
||||
db.SeedAudits.Add(new SeedAudit { Key = seedKey });
|
||||
await db.SaveChangesAsync();
|
||||
await tx.CommitAsync();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the HTTP middleware pipeline: forwarded headers, rate limiting, auth, security headers, and Swagger in development.
|
||||
/// </summary>
|
||||
public static IApplicationBuilder UseNexusPipeline(this IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
app.UseForwardedHeaders();
|
||||
app.UseRateLimiter();
|
||||
app.UseApiKeyAuthentication();
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
app.UseSecurityHeaders();
|
||||
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
}
|
||||
|
||||
return app;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,253 @@
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.HttpOverrides;
|
||||
using Microsoft.AspNetCore.RateLimiting;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using Nexus.Api.Data;
|
||||
using Nexus.Api.Integrations;
|
||||
using Nexus.Api.RateLimiting;
|
||||
using Nexus.Api.Repositories;
|
||||
using Nexus.Api.Routing;
|
||||
using Nexus.Api.Services;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.Text;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading.RateLimiting;
|
||||
|
||||
namespace Nexus.Api.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for registering Nexus application services in the DI container.
|
||||
/// </summary>
|
||||
public static class ServiceCollectionExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Configures JWT authentication, authorization, and antiforgery.
|
||||
/// </summary>
|
||||
public static IServiceCollection AddNexusAuth(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
var jwtKey = configuration["Jwt:Key"];
|
||||
var jwtIssuer = configuration["Jwt:Issuer"] ?? "nexus";
|
||||
var jwtAudience = configuration["Jwt:Audience"] ?? "nexus-web";
|
||||
if (string.IsNullOrWhiteSpace(jwtKey) || Encoding.UTF8.GetByteCount(jwtKey) < 32)
|
||||
throw new InvalidOperationException("Jwt:Key must be configured with at least 32 bytes.");
|
||||
|
||||
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
||||
.AddJwtBearer(options =>
|
||||
{
|
||||
options.MapInboundClaims = false;
|
||||
options.TokenValidationParameters = new TokenValidationParameters
|
||||
{
|
||||
ValidateIssuer = true,
|
||||
ValidateAudience = true,
|
||||
ValidateLifetime = true,
|
||||
ValidateIssuerSigningKey = true,
|
||||
ValidIssuer = jwtIssuer,
|
||||
ValidAudience = jwtAudience,
|
||||
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtKey)),
|
||||
NameClaimType = JwtRegisteredClaimNames.Sub,
|
||||
RoleClaimType = System.Security.Claims.ClaimTypes.Role,
|
||||
ClockSkew = TimeSpan.FromSeconds(30)
|
||||
};
|
||||
});
|
||||
|
||||
services.AddAuthorization();
|
||||
services.AddAntiforgery(options =>
|
||||
{
|
||||
options.HeaderName = "X-CSRF-TOKEN";
|
||||
options.Cookie.Name = "nexus-csrf";
|
||||
options.Cookie.SecurePolicy = CookieSecurePolicy.SameAsRequest;
|
||||
options.Cookie.HttpOnly = false;
|
||||
});
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures rate limiting policies (auth and agents).
|
||||
/// </summary>
|
||||
public static IServiceCollection AddNexusRateLimiting(this IServiceCollection services)
|
||||
{
|
||||
services.AddRateLimiter(options =>
|
||||
{
|
||||
options.RejectionStatusCode = StatusCodes.Status429TooManyRequests;
|
||||
|
||||
options.OnRejected = async (context, ct) =>
|
||||
{
|
||||
context.HttpContext.Response.StatusCode = StatusCodes.Status429TooManyRequests;
|
||||
context.HttpContext.Response.Headers.ContentType = "application/json";
|
||||
|
||||
var retryAfterSeconds = 60;
|
||||
|
||||
// Try to read retry-after info from the metadata
|
||||
if (context.Lease.TryGetMetadata(MetadataName.RetryAfter, out var retryAfter))
|
||||
{
|
||||
retryAfterSeconds = (int)retryAfter.TotalSeconds;
|
||||
}
|
||||
|
||||
// Set standard headers
|
||||
context.HttpContext.Response.Headers.RetryAfter = retryAfterSeconds.ToString();
|
||||
context.HttpContext.Response.Headers["X-RateLimit-Remaining"] = "0";
|
||||
context.HttpContext.Response.Headers["X-RateLimit-Reset"] =
|
||||
DateTimeOffset.UtcNow.AddSeconds(retryAfterSeconds).ToUnixTimeSeconds().ToString();
|
||||
|
||||
var body = new
|
||||
{
|
||||
error = "rate_limit_exceeded",
|
||||
message = $"Too many attempts. Try again in {retryAfterSeconds} second(s).",
|
||||
remaining = 0,
|
||||
retryAfterSeconds
|
||||
};
|
||||
|
||||
await context.HttpContext.Response.WriteAsJsonAsync(body, ct);
|
||||
};
|
||||
|
||||
options.AddPolicy("auth", context => RateLimitPartition.GetFixedWindowLimiter(
|
||||
context.Connection.RemoteIpAddress?.ToString() ?? "unknown",
|
||||
_ => new FixedWindowRateLimiterOptions
|
||||
{
|
||||
PermitLimit = 5,
|
||||
Window = TimeSpan.FromMinutes(1),
|
||||
QueueLimit = 0,
|
||||
AutoReplenishment = true
|
||||
}));
|
||||
|
||||
options.AddPolicy("agents", context => RateLimitPartition.GetFixedWindowLimiter(
|
||||
context.Connection.RemoteIpAddress?.ToString() ?? "unknown",
|
||||
_ => new FixedWindowRateLimiterOptions
|
||||
{
|
||||
PermitLimit = 30,
|
||||
Window = TimeSpan.FromMinutes(1),
|
||||
QueueLimit = 0,
|
||||
AutoReplenishment = true
|
||||
}));
|
||||
});
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures forwarded headers for reverse proxy scenarios.
|
||||
/// </summary>
|
||||
public static IServiceCollection AddNexusForwardedHeaders(this IServiceCollection services)
|
||||
{
|
||||
services.Configure<ForwardedHeadersOptions>(options =>
|
||||
{
|
||||
options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
|
||||
options.KnownIPNetworks.Clear();
|
||||
options.KnownProxies.Clear();
|
||||
});
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures Swagger and JSON serialization options.
|
||||
/// </summary>
|
||||
public static IServiceCollection AddNexusSwagger(this IServiceCollection services)
|
||||
{
|
||||
services.AddEndpointsApiExplorer();
|
||||
services.AddSwaggerGen();
|
||||
services.ConfigureHttpJsonOptions(options =>
|
||||
options.SerializerOptions.Converters.Add(new JsonStringEnumConverter()));
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers the Entity Framework Core DbContext with Npgsql.
|
||||
/// </summary>
|
||||
public static IServiceCollection AddNexusDatabase(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
services.AddDbContext<NexusDbContext>(options =>
|
||||
options.UseNpgsql(configuration.GetConnectionString("Nexus"))
|
||||
.ConfigureWarnings(w => w.Ignore(
|
||||
Microsoft.EntityFrameworkCore.Diagnostics.RelationalEventId.PendingModelChangesWarning)));
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers typed and named HTTP clients for OpenClaw integration.
|
||||
/// </summary>
|
||||
public static IServiceCollection AddNexusHttpClients(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
services.AddHttpClient<IAgentRuntime, OpenClawRuntime>(client =>
|
||||
{
|
||||
client.BaseAddress = new(configuration["Integrations:OpenClaw:BaseUrl"]
|
||||
?? "http://127.0.0.1:18789");
|
||||
client.Timeout = TimeSpan.FromSeconds(120);
|
||||
});
|
||||
|
||||
services.AddHttpClient("gateway", client =>
|
||||
{
|
||||
client.BaseAddress = new(configuration["Integrations:OpenClaw:BaseUrl"]
|
||||
?? "http://127.0.0.1:18789");
|
||||
client.Timeout = TimeSpan.FromSeconds(120);
|
||||
});
|
||||
|
||||
services.AddHttpClient<IOpenClawGatewayClient, OpenClawGatewayClient>(client =>
|
||||
{
|
||||
client.BaseAddress = new(configuration["Integrations:OpenClaw:BaseUrl"]
|
||||
?? "http://127.0.0.1:18789");
|
||||
client.Timeout = TimeSpan.FromSeconds(120);
|
||||
});
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers application domain services (transient, scoped, singleton).
|
||||
/// </summary>
|
||||
public static IServiceCollection AddNexusApplicationServices(this IServiceCollection services)
|
||||
{
|
||||
services.AddHttpContextAccessor();
|
||||
services.AddSingleton<LoginAttemptTracker>();
|
||||
services.AddTransient<ModelRoutingService>();
|
||||
services.AddScoped<IAuthService, AuthService>();
|
||||
services.AddScoped<IAgentService, AgentService>();
|
||||
services.AddScoped<IDashboardService, DashboardService>();
|
||||
services.AddScoped<IProjectService, ProjectService>();
|
||||
services.AddScoped<ITaskService, TaskService>();
|
||||
services.AddScoped<IOperationsService, OperationsService>();
|
||||
services.AddScoped<ITeamService, TeamService>();
|
||||
services.AddSingleton<IAgentConfigService, AgentConfigService>();
|
||||
services.AddSingleton<IMemoryService, MemoryService>();
|
||||
services.AddSingleton<IIncidentService, IncidentService>();
|
||||
services.AddSingleton<IDocService, DocService>();
|
||||
services.AddSingleton<ILiveUpdateService, LiveUpdateService>();
|
||||
services.AddScoped<INotificationService, NotificationService>();
|
||||
services.AddScoped<ICalendarService, CalendarService>();
|
||||
|
||||
// ── Backend Bridge (Agent-Command-Service) ──
|
||||
services.AddScoped<ITaskBridgeService, TaskBridgeService>();
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers data repositories.
|
||||
/// </summary>
|
||||
public static IServiceCollection AddNexusRepositories(this IServiceCollection services)
|
||||
{
|
||||
services.AddScoped<IUserRepository, UserRepository>();
|
||||
services.AddScoped<IProjectRepository, ProjectRepository>();
|
||||
services.AddScoped<ITaskRepository, TaskRepository>();
|
||||
services.AddScoped<IActivityRepository, ActivityRepository>();
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures health checks (PostgreSQL connectivity and runtime status).
|
||||
/// </summary>
|
||||
public static IServiceCollection AddNexusHealthChecks(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
services.AddHealthChecks()
|
||||
.AddNpgSql(configuration.GetConnectionString("Nexus")!, name: "postgresql", tags: ["database"])
|
||||
.AddCheck("runtime", () => HealthCheckResult.Healthy("Runtime configured"), tags: ["runtime"]);
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace Nexus.Api.Helpers;
|
||||
|
||||
/// <summary>
|
||||
/// Helper methods for password generation and name construction.
|
||||
/// </summary>
|
||||
public static class PasswordHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Generates a cryptographically random temporary password (30 chars, URL-safe base64).
|
||||
/// </summary>
|
||||
public static string GenerateTemporaryPassword()
|
||||
=> Convert.ToBase64String(RandomNumberGenerator.GetBytes(18))
|
||||
.TrimEnd('=')
|
||||
.Replace('+', '-')
|
||||
.Replace('/', '_');
|
||||
|
||||
/// <summary>
|
||||
/// Builds a human-readable display name from an email address.
|
||||
/// </summary>
|
||||
public static string BuildOwnerDisplayName(string email)
|
||||
{
|
||||
var localPart = email.Split('@', 2)[0].Trim();
|
||||
if (string.IsNullOrWhiteSpace(localPart)) return "Owner";
|
||||
|
||||
var words = localPart
|
||||
.Replace('.', ' ')
|
||||
.Replace('_', ' ')
|
||||
.Replace('-', ' ')
|
||||
.Split(' ', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)
|
||||
.Select(word => char.ToUpperInvariant(word[0]) + word[1..].ToLowerInvariant());
|
||||
|
||||
var displayName = string.Join(' ', words);
|
||||
return string.IsNullOrWhiteSpace(displayName) ? "Owner" : displayName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace Nexus.Api.Middleware;
|
||||
|
||||
/// <summary>
|
||||
/// Middleware that authenticates requests via the X-Nexus-Api-Key header.
|
||||
/// On match, sets a ClaimsPrincipal with role "Service".
|
||||
/// On mismatch or absent header, passes through to next middleware (JWT auth).
|
||||
/// </summary>
|
||||
public sealed class ApiKeyMiddleware(RequestDelegate next)
|
||||
{
|
||||
public async Task InvokeAsync(HttpContext context)
|
||||
{
|
||||
var configuration = context.RequestServices.GetRequiredService<IConfiguration>();
|
||||
var apiKey = configuration["NexusApiKey"];
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(apiKey) &&
|
||||
context.Request.Headers.TryGetValue("X-Nexus-Api-Key", out var providedKey) &&
|
||||
string.Equals(apiKey, providedKey, StringComparison.Ordinal))
|
||||
{
|
||||
var claims = new[]
|
||||
{
|
||||
new Claim(ClaimTypes.NameIdentifier, "service"),
|
||||
new Claim(ClaimTypes.Name, "ApiService"),
|
||||
new Claim(ClaimTypes.Role, "Service")
|
||||
};
|
||||
var identity = new ClaimsIdentity(claims, "ApiKey");
|
||||
context.User = new ClaimsPrincipal(identity);
|
||||
}
|
||||
|
||||
await next(context);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ApiKeyMiddlewareExtensions
|
||||
{
|
||||
public static IApplicationBuilder UseApiKeyAuthentication(this IApplicationBuilder builder)
|
||||
=> builder.UseMiddleware<ApiKeyMiddleware>();
|
||||
}
|
||||
+108
-3
@@ -86,8 +86,18 @@ public sealed record DashboardTaskDto(
|
||||
string State,
|
||||
string Priority,
|
||||
string? AssignedTo,
|
||||
Guid? ParentTaskId,
|
||||
DateTimeOffset? DueDate,
|
||||
DateTimeOffset CreatedAt,
|
||||
DateTimeOffset UpdatedAt
|
||||
DateTimeOffset UpdatedAt,
|
||||
bool IsAgentTask = false,
|
||||
string? ExpectedFrom = null,
|
||||
string? LastActivityMessage = null,
|
||||
DateTimeOffset? LastActivityAt = null,
|
||||
List<DashboardTaskDto>? ChildTasks = null,
|
||||
int ChildTaskCount = 0,
|
||||
int OpenChildTaskCount = 0,
|
||||
bool HasVisibleDelegation = false
|
||||
);
|
||||
|
||||
public sealed record CreateDashboardTaskRequest(
|
||||
@@ -95,7 +105,20 @@ public sealed record CreateDashboardTaskRequest(
|
||||
string? Detail,
|
||||
string? Source,
|
||||
string? Priority,
|
||||
string? AssignedTo
|
||||
string? AssignedTo,
|
||||
Guid? ParentTaskId = null
|
||||
);
|
||||
|
||||
public sealed record CreateAgentTaskRequest(
|
||||
string Title,
|
||||
string? Detail,
|
||||
string? Source,
|
||||
string? Priority,
|
||||
string? AssignedTo,
|
||||
string? ExpectedFrom,
|
||||
Guid? ParentTaskId = null,
|
||||
bool StartsInProgress = true,
|
||||
string? InitialState = null
|
||||
);
|
||||
|
||||
public sealed record UpdateDashboardTaskRequest(
|
||||
@@ -103,7 +126,8 @@ public sealed record UpdateDashboardTaskRequest(
|
||||
string? Detail,
|
||||
string? Source,
|
||||
string? Priority,
|
||||
string? AssignedTo
|
||||
string? AssignedTo,
|
||||
DateTimeOffset? DueDate = null
|
||||
);
|
||||
|
||||
public sealed record UpdateDashboardTaskStatusRequest(
|
||||
@@ -114,3 +138,84 @@ public sealed record AgentActivityEntry(
|
||||
string Time,
|
||||
string Text
|
||||
);
|
||||
|
||||
// ── Task Board DTOs ──
|
||||
|
||||
public sealed record BoardResponse(
|
||||
List<DashboardTaskDto> Offen,
|
||||
List<DashboardTaskDto> InProgress,
|
||||
List<DashboardTaskDto> Review,
|
||||
List<DashboardTaskDto> Blocked,
|
||||
List<DashboardTaskDto> Done
|
||||
);
|
||||
|
||||
public sealed record MoveTaskRequest(
|
||||
string State
|
||||
);
|
||||
|
||||
public sealed record ResetStaleRequest(
|
||||
int StaleHours = 2
|
||||
);
|
||||
|
||||
public sealed record ResetStaleResponse(
|
||||
int ResetCount
|
||||
);
|
||||
|
||||
public sealed record PostActivityRequest(
|
||||
string Message,
|
||||
string? Type = null
|
||||
);
|
||||
|
||||
// ── Agent Workflow DTOs ──
|
||||
|
||||
/// <summary>
|
||||
/// Overview of the agent workflow state, grouping tasks by expected respondent
|
||||
/// and highlighting stale tasks. Used by Iris to see who she is waiting for.
|
||||
/// </summary>
|
||||
public sealed record AgentWorkflowOverview(
|
||||
List<DashboardTaskDto> WaitingForBao,
|
||||
List<DashboardTaskDto> WaitingForIris,
|
||||
List<DashboardTaskDto> WaitingForOthers,
|
||||
List<DashboardTaskDto> StaleTasks,
|
||||
TimeSpan StaleThreshold
|
||||
);
|
||||
|
||||
// ── Notification DTOs ──
|
||||
|
||||
public sealed record NotificationDto(
|
||||
Guid Id, string Type, string Title, string? Message,
|
||||
string ForUser, Guid? TaskId, bool IsRead, DateTimeOffset CreatedAt
|
||||
);
|
||||
|
||||
public sealed record UnreadCountDto(int Count);
|
||||
|
||||
public sealed record LiveUpdateEnvelope(
|
||||
string Type,
|
||||
DateTimeOffset Timestamp,
|
||||
object Payload,
|
||||
long Sequence,
|
||||
string Channel
|
||||
);
|
||||
|
||||
public sealed record LiveCursorDto(
|
||||
long Sequence,
|
||||
DateTimeOffset Timestamp,
|
||||
string Mode
|
||||
);
|
||||
|
||||
public sealed record NotificationSnapshotDto(
|
||||
List<NotificationDto> Notifications,
|
||||
int UnreadCount,
|
||||
string ForUser
|
||||
);
|
||||
|
||||
public sealed record DashboardLiveSnapshotDto(
|
||||
BoardResponse Board,
|
||||
NotificationSnapshotDto Notifications,
|
||||
LiveCursorDto Cursor
|
||||
);
|
||||
|
||||
public sealed record DashboardLiveEventDto(
|
||||
LiveUpdateEnvelope Envelope,
|
||||
LiveCursorDto Cursor
|
||||
);
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Design;
|
||||
using Nexus.Api.Data;
|
||||
|
||||
namespace Nexus.Api;
|
||||
|
||||
public class NexusDbContextFactory : IDesignTimeDbContextFactory<NexusDbContext>
|
||||
{
|
||||
public NexusDbContext CreateDbContext(string[] args)
|
||||
{
|
||||
var optionsBuilder = new DbContextOptionsBuilder<NexusDbContext>();
|
||||
var connectionString = args.Length > 0
|
||||
? args[0]
|
||||
: Environment.GetEnvironmentVariable("ConnectionStrings__Nexus")
|
||||
?? "Host=localhost;Port=5432;Database=nexus;Username=nexus;Password=nexus";
|
||||
|
||||
optionsBuilder.UseNpgsql(connectionString);
|
||||
return new NexusDbContext(optionsBuilder.Options);
|
||||
}
|
||||
}
|
||||
+14
-222
@@ -1,234 +1,26 @@
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.HttpOverrides;
|
||||
using Microsoft.AspNetCore.RateLimiting;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using Nexus.Api.Data;
|
||||
using Nexus.Api.Integrations;
|
||||
using Nexus.Api.Middleware;
|
||||
using Nexus.Api.Repositories;
|
||||
using Nexus.Api.Routing;
|
||||
using Nexus.Api.Services;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading.RateLimiting;
|
||||
using Nexus.Api.Extensions;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// --- JWT Configuration ---
|
||||
var jwtKey = builder.Configuration["Jwt:Key"];
|
||||
var jwtIssuer = builder.Configuration["Jwt:Issuer"] ?? "nexus";
|
||||
var jwtAudience = builder.Configuration["Jwt:Audience"] ?? "nexus-web";
|
||||
if (string.IsNullOrWhiteSpace(jwtKey) || Encoding.UTF8.GetByteCount(jwtKey) < 32)
|
||||
throw new InvalidOperationException("Jwt:Key must be configured with at least 32 bytes.");
|
||||
|
||||
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
||||
.AddJwtBearer(options =>
|
||||
{
|
||||
options.MapInboundClaims = false;
|
||||
options.TokenValidationParameters = new TokenValidationParameters
|
||||
{
|
||||
ValidateIssuer = true,
|
||||
ValidateAudience = true,
|
||||
ValidateLifetime = true,
|
||||
ValidateIssuerSigningKey = true,
|
||||
ValidIssuer = jwtIssuer,
|
||||
ValidAudience = jwtAudience,
|
||||
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtKey)),
|
||||
NameClaimType = JwtRegisteredClaimNames.Sub,
|
||||
RoleClaimType = System.Security.Claims.ClaimTypes.Role,
|
||||
ClockSkew = TimeSpan.FromSeconds(30)
|
||||
};
|
||||
});
|
||||
|
||||
builder.Services.AddAuthorization();
|
||||
builder.Services.AddAntiforgery(options =>
|
||||
{
|
||||
options.HeaderName = "X-CSRF-TOKEN";
|
||||
options.Cookie.Name = "nexus-csrf";
|
||||
options.Cookie.SecurePolicy = CookieSecurePolicy.SameAsRequest;
|
||||
options.Cookie.HttpOnly = false;
|
||||
});
|
||||
|
||||
// --- Rate Limiting ---
|
||||
builder.Services.AddRateLimiter(options =>
|
||||
{
|
||||
options.RejectionStatusCode = StatusCodes.Status429TooManyRequests;
|
||||
options.AddPolicy("auth", context => RateLimitPartition.GetFixedWindowLimiter(
|
||||
context.Connection.RemoteIpAddress?.ToString() ?? "unknown",
|
||||
_ => new FixedWindowRateLimiterOptions
|
||||
{
|
||||
PermitLimit = 5,
|
||||
Window = TimeSpan.FromMinutes(1),
|
||||
QueueLimit = 0,
|
||||
AutoReplenishment = true
|
||||
}));
|
||||
|
||||
options.AddPolicy("agents", context => RateLimitPartition.GetFixedWindowLimiter(
|
||||
context.Connection.RemoteIpAddress?.ToString() ?? "unknown",
|
||||
_ => new FixedWindowRateLimiterOptions
|
||||
{
|
||||
PermitLimit = 30,
|
||||
Window = TimeSpan.FromMinutes(1),
|
||||
QueueLimit = 0,
|
||||
AutoReplenishment = true
|
||||
}));
|
||||
});
|
||||
|
||||
// --- Forwarded Headers ---
|
||||
builder.Services.Configure<ForwardedHeadersOptions>(options =>
|
||||
{
|
||||
options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
|
||||
options.KnownIPNetworks.Clear();
|
||||
options.KnownProxies.Clear();
|
||||
});
|
||||
|
||||
// --- Swagger & JSON ---
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
builder.Services.ConfigureHttpJsonOptions(options =>
|
||||
options.SerializerOptions.Converters.Add(new JsonStringEnumConverter()));
|
||||
|
||||
// --- Database ---
|
||||
builder.Services.AddDbContext<NexusDbContext>(options =>
|
||||
options.UseNpgsql(builder.Configuration.GetConnectionString("Nexus"))
|
||||
.ConfigureWarnings(w => w.Ignore(Microsoft.EntityFrameworkCore.Diagnostics.RelationalEventId.PendingModelChangesWarning)));
|
||||
|
||||
// --- HTTP Clients ---
|
||||
builder.Services.AddHttpClient<IAgentRuntime, OpenClawRuntime>(client =>
|
||||
{
|
||||
client.BaseAddress = new(builder.Configuration["Integrations:OpenClaw:BaseUrl"]
|
||||
?? "http://127.0.0.1:18789");
|
||||
client.Timeout = TimeSpan.FromSeconds(120);
|
||||
});
|
||||
|
||||
builder.Services.AddHttpClient("gateway", client =>
|
||||
{
|
||||
client.BaseAddress = new(builder.Configuration["Integrations:OpenClaw:BaseUrl"]
|
||||
?? "http://127.0.0.1:18789");
|
||||
client.Timeout = TimeSpan.FromSeconds(120);
|
||||
});
|
||||
|
||||
builder.Services.AddHttpClient<IOpenClawGatewayClient, OpenClawGatewayClient>(client =>
|
||||
{
|
||||
client.BaseAddress = new(builder.Configuration["Integrations:OpenClaw:BaseUrl"]
|
||||
?? "http://127.0.0.1:18789");
|
||||
client.Timeout = TimeSpan.FromSeconds(120);
|
||||
});
|
||||
|
||||
// --- Application Services ---
|
||||
builder.Services.AddTransient<ModelRoutingService>();
|
||||
builder.Services.AddScoped<IAuthService, AuthService>();
|
||||
builder.Services.AddScoped<IAgentService, AgentService>();
|
||||
builder.Services.AddScoped<IDashboardService, DashboardService>();
|
||||
builder.Services.AddScoped<IProjectService, ProjectService>();
|
||||
builder.Services.AddScoped<ITaskService, TaskService>();
|
||||
builder.Services.AddScoped<IOperationsService, OperationsService>();
|
||||
builder.Services.AddScoped<ITeamService, TeamService>();
|
||||
builder.Services.AddSingleton<IAgentConfigService, AgentConfigService>();
|
||||
builder.Services.AddSingleton<IMemoryService, MemoryService>();
|
||||
builder.Services.AddSingleton<IIncidentService, IncidentService>();
|
||||
builder.Services.AddSingleton<IDocService, DocService>();
|
||||
builder.Services.AddScoped<ICalendarService, CalendarService>();
|
||||
|
||||
// --- Repositories ---
|
||||
builder.Services.AddScoped<IUserRepository, UserRepository>();
|
||||
builder.Services.AddScoped<IProjectRepository, ProjectRepository>();
|
||||
builder.Services.AddScoped<ITaskRepository, TaskRepository>();
|
||||
builder.Services.AddScoped<IActivityRepository, ActivityRepository>();
|
||||
|
||||
// --- Health Checks ---
|
||||
builder.Services.AddHealthChecks()
|
||||
.AddNpgSql(builder.Configuration.GetConnectionString("Nexus")!, name: "postgresql", tags: ["database"])
|
||||
.AddCheck("runtime", () => HealthCheckResult.Healthy("Runtime configured"), tags: ["runtime"]);
|
||||
|
||||
// --- Controllers ---
|
||||
// --- Service Registration ---
|
||||
builder.Services.AddNexusAuth(builder.Configuration);
|
||||
builder.Services.AddNexusRateLimiting();
|
||||
builder.Services.AddNexusForwardedHeaders();
|
||||
builder.Services.AddNexusSwagger();
|
||||
builder.Services.AddNexusDatabase(builder.Configuration);
|
||||
builder.Services.AddNexusHttpClients(builder.Configuration);
|
||||
builder.Services.AddNexusApplicationServices();
|
||||
builder.Services.AddNexusRepositories();
|
||||
builder.Services.AddNexusHealthChecks(builder.Configuration);
|
||||
builder.Services.AddControllers();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// --- Database Migration & Owner Seeding ---
|
||||
await using (var scope = app.Services.CreateAsyncScope())
|
||||
{
|
||||
var db = scope.ServiceProvider.GetRequiredService<NexusDbContext>();
|
||||
await db.Database.MigrateAsync();
|
||||
|
||||
var ownerEmail = builder.Configuration["Owner:Email"]?.Trim().ToLowerInvariant();
|
||||
var ownerPassword = builder.Configuration["Owner:Password"];
|
||||
var ownerDisplayName = builder.Configuration["Owner:DisplayName"]?.Trim();
|
||||
var hasUsers = await db.Users.AnyAsync();
|
||||
|
||||
if (!hasUsers)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(ownerEmail))
|
||||
throw new InvalidOperationException("Owner:Email is required for initial setup.");
|
||||
|
||||
var initialDisplayName = string.IsNullOrWhiteSpace(ownerDisplayName)
|
||||
? BuildOwnerDisplayName(ownerEmail)
|
||||
: ownerDisplayName;
|
||||
var initialPassword = string.IsNullOrWhiteSpace(ownerPassword)
|
||||
? GenerateTemporaryPassword()
|
||||
: ownerPassword;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(ownerPassword) && ownerPassword.Length < 10)
|
||||
throw new InvalidOperationException("Owner:Password must be at least 10 characters when provided explicitly.");
|
||||
|
||||
db.Users.Add(new NexusUser
|
||||
{
|
||||
Email = ownerEmail,
|
||||
NormalizedEmail = AuthService.NormalizeEmail(ownerEmail),
|
||||
DisplayName = initialDisplayName,
|
||||
PasswordHash = PasswordSecurity.Hash(initialPassword),
|
||||
Role = "owner"
|
||||
});
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(ownerPassword))
|
||||
{
|
||||
Console.Error.WriteLine($"[nexus] Initial owner credentials generated: displayName={initialDisplayName}, password={initialPassword}");
|
||||
}
|
||||
}
|
||||
}
|
||||
// --- Database Migration & Seeding ---
|
||||
await app.EnsureDatabaseAsync();
|
||||
|
||||
// --- Middleware Pipeline ---
|
||||
app.UseForwardedHeaders();
|
||||
app.UseRateLimiter();
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
app.UseSecurityHeaders();
|
||||
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
}
|
||||
app.UseNexusPipeline(app.Environment);
|
||||
|
||||
app.MapControllers();
|
||||
app.Run();
|
||||
|
||||
// --- Helpers ---
|
||||
|
||||
static string GenerateTemporaryPassword()
|
||||
=> Convert.ToBase64String(RandomNumberGenerator.GetBytes(18))
|
||||
.TrimEnd('=')
|
||||
.Replace('+', '-')
|
||||
.Replace('/', '_');
|
||||
|
||||
static string BuildOwnerDisplayName(string email)
|
||||
{
|
||||
var localPart = email.Split('@', 2)[0].Trim();
|
||||
if (string.IsNullOrWhiteSpace(localPart)) return "Owner";
|
||||
|
||||
var words = localPart
|
||||
.Replace('.', ' ')
|
||||
.Replace('_', ' ')
|
||||
.Replace('-', ' ')
|
||||
.Split(' ', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)
|
||||
.Select(word => char.ToUpperInvariant(word[0]) + word[1..].ToLowerInvariant());
|
||||
|
||||
var displayName = string.Join(' ', words);
|
||||
return string.IsNullOrWhiteSpace(displayName) ? "Owner" : displayName;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace Nexus.Api.RateLimiting;
|
||||
|
||||
/// <summary>
|
||||
/// Simple in-memory tracking of login attempts per IP,
|
||||
/// aligned with the fixed-window rate limiter (5 attempts / 1 minute).
|
||||
///
|
||||
/// Provides remaining-attempt count that can be passed back to the frontend.
|
||||
/// </summary>
|
||||
public sealed class LoginAttemptTracker
|
||||
{
|
||||
private const int MaxAttempts = 5;
|
||||
private static readonly TimeSpan Window = TimeSpan.FromMinutes(1);
|
||||
|
||||
// IP → (count, windowStartTicks)
|
||||
private static readonly ConcurrentDictionary<string, (int Count, long WindowStartTicks)> _store = new();
|
||||
|
||||
/// <summary>
|
||||
/// Registers a failed attempt for the given IP.
|
||||
/// Returns remaining attempts (0 = locked out until reset).
|
||||
/// </summary>
|
||||
public int RecordFailedAttempt(string ip)
|
||||
{
|
||||
var now = Environment.TickCount64;
|
||||
var windowTicks = (long)Window.TotalMilliseconds;
|
||||
|
||||
var (count, windowStart) = _store.AddOrUpdate(ip,
|
||||
_ => (1, now),
|
||||
(_, entry) =>
|
||||
{
|
||||
if (now - entry.WindowStartTicks >= windowTicks)
|
||||
return (1, now);
|
||||
return (entry.Count + 1, entry.WindowStartTicks);
|
||||
});
|
||||
|
||||
return Math.Max(0, MaxAttempts - count);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the remaining attempts for the given IP without recording.
|
||||
/// </summary>
|
||||
public int GetRemaining(string ip)
|
||||
{
|
||||
var now = Environment.TickCount64;
|
||||
var windowTicks = (long)Window.TotalMilliseconds;
|
||||
|
||||
if (_store.TryGetValue(ip, out var entry))
|
||||
{
|
||||
if (now - entry.WindowStartTicks >= windowTicks)
|
||||
return MaxAttempts;
|
||||
return Math.Max(0, MaxAttempts - entry.Count);
|
||||
}
|
||||
|
||||
return MaxAttempts;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the number of seconds until the rate-limit window resets,
|
||||
/// or 0 if the window has already expired / no attempts recorded.
|
||||
/// </summary>
|
||||
public int GetRetryAfterSeconds(string ip)
|
||||
{
|
||||
var now = Environment.TickCount64;
|
||||
var windowTicks = (long)Window.TotalMilliseconds;
|
||||
|
||||
if (!_store.TryGetValue(ip, out var entry))
|
||||
return 0;
|
||||
|
||||
var elapsed = now - entry.WindowStartTicks;
|
||||
if (elapsed >= windowTicks)
|
||||
return 0;
|
||||
|
||||
return (int)Math.Ceiling((windowTicks - elapsed) / 1000.0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets attempt count for the given IP (e.g. on success).
|
||||
/// </summary>
|
||||
public void Reset(string ip)
|
||||
{
|
||||
_store.TryRemove(ip, out _);
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,18 @@ public sealed class ActivityRepository(NexusDbContext db) : IActivityRepository
|
||||
public Task<List<ActivityEvent>> GetRecentAsync(int take, CancellationToken ct = default)
|
||||
=> db.Activity.AsNoTracking().OrderByDescending(x => x.CreatedAt).Take(take).ToListAsync(ct);
|
||||
|
||||
public Task<List<ActivityEvent>> GetRecentForTasksAsync(IEnumerable<Guid> taskIds, CancellationToken ct = default)
|
||||
{
|
||||
var ids = taskIds.Distinct().ToList();
|
||||
if (ids.Count == 0)
|
||||
return Task.FromResult(new List<ActivityEvent>());
|
||||
|
||||
return db.Activity.AsNoTracking()
|
||||
.Where(x => x.TaskId.HasValue && ids.Contains(x.TaskId.Value))
|
||||
.OrderByDescending(x => x.CreatedAt)
|
||||
.ToListAsync(ct);
|
||||
}
|
||||
|
||||
public async Task<(List<ActivityEvent> Items, int TotalCount)> GetPagedAsync(
|
||||
string? type, string? sort, int page, int pageSize, CancellationToken ct = default)
|
||||
{
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace Nexus.Api.Repositories;
|
||||
public interface IActivityRepository
|
||||
{
|
||||
Task<List<ActivityEvent>> GetRecentAsync(int take, CancellationToken ct = default);
|
||||
Task<List<ActivityEvent>> GetRecentForTasksAsync(IEnumerable<Guid> taskIds, CancellationToken ct = default);
|
||||
Task<(List<ActivityEvent> Items, int TotalCount)> GetPagedAsync(
|
||||
string? type, string? sort, int page, int pageSize, CancellationToken ct = default);
|
||||
Task<List<ActivityEvent>> GetByAgentAsync(string agentId, int take, CancellationToken ct = default);
|
||||
|
||||
@@ -7,8 +7,10 @@ public interface IUserRepository
|
||||
ValueTask<NexusUser?> GetByIdAsync(Guid userId, CancellationToken ct = default);
|
||||
Task<NexusUser?> GetByEmailAsync(string normalizedEmail, CancellationToken ct = default);
|
||||
Task<bool> AnyUsersAsync(CancellationToken ct = default);
|
||||
Task<List<NexusUser>> GetAllAsync(CancellationToken ct = default);
|
||||
Task<NexusUser> AddAsync(NexusUser user, CancellationToken ct = default);
|
||||
Task UpdateAsync(NexusUser user, CancellationToken ct = default);
|
||||
Task DeleteAsync(NexusUser user, CancellationToken ct = default);
|
||||
|
||||
Task<RefreshToken?> GetRefreshTokenByHashAsync(string tokenHash, CancellationToken ct = default);
|
||||
Task<List<RefreshToken>> GetActiveTokensByFamilyAsync(Guid familyId, CancellationToken ct = default);
|
||||
|
||||
@@ -30,6 +30,7 @@ public sealed class TaskRepository(NexusDbContext db) : ITaskRepository
|
||||
public async Task UpdateAsync(WorkTask task, CancellationToken ct = default)
|
||||
{
|
||||
task.UpdatedAt = DateTimeOffset.UtcNow;
|
||||
db.Tasks.Update(task);
|
||||
await db.SaveChangesAsync(ct);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,9 @@ public sealed class UserRepository(NexusDbContext db) : IUserRepository
|
||||
public Task<NexusUser?> GetByEmailAsync(string normalizedEmail, CancellationToken ct = default)
|
||||
=> db.Users.FirstOrDefaultAsync(u => u.NormalizedEmail == normalizedEmail, ct);
|
||||
|
||||
public Task<List<NexusUser>> GetAllAsync(CancellationToken ct = default)
|
||||
=> db.Users.OrderBy(u => u.CreatedAt).ToListAsync(ct);
|
||||
|
||||
public Task<bool> AnyUsersAsync(CancellationToken ct = default)
|
||||
=> db.Users.AnyAsync(ct);
|
||||
|
||||
@@ -24,6 +27,17 @@ public sealed class UserRepository(NexusDbContext db) : IUserRepository
|
||||
public Task UpdateAsync(NexusUser user, CancellationToken ct = default)
|
||||
=> db.SaveChangesAsync(ct);
|
||||
|
||||
public async Task DeleteAsync(NexusUser user, CancellationToken ct = default)
|
||||
{
|
||||
// Remove refresh tokens first
|
||||
var tokens = await db.RefreshTokens
|
||||
.Where(r => r.UserId == user.Id)
|
||||
.ToListAsync(ct);
|
||||
db.RefreshTokens.RemoveRange(tokens);
|
||||
db.Users.Remove(user);
|
||||
await db.SaveChangesAsync(ct);
|
||||
}
|
||||
|
||||
public Task<RefreshToken?> GetRefreshTokenByHashAsync(string tokenHash, CancellationToken ct = default)
|
||||
=> db.RefreshTokens
|
||||
.Include(r => r.User)
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
namespace Nexus.Api.Services;
|
||||
|
||||
public static class AgentIdentityCatalog
|
||||
{
|
||||
public static readonly string[] DefaultConfiguredAgentIds =
|
||||
[
|
||||
"main",
|
||||
"iris",
|
||||
"product-owner",
|
||||
"programmer",
|
||||
"programmer-fast",
|
||||
"reviewer",
|
||||
"architekt",
|
||||
"researcher",
|
||||
"executor"
|
||||
];
|
||||
|
||||
private static readonly string[] WorkflowActorIds =
|
||||
[
|
||||
"bao",
|
||||
"nexus-system"
|
||||
];
|
||||
|
||||
public static IReadOnlySet<string> BuildAllowedActorIds(IEnumerable<string> configuredAgentIds)
|
||||
{
|
||||
var ids = new HashSet<string>(WorkflowActorIds, StringComparer.OrdinalIgnoreCase);
|
||||
foreach (var configuredAgentId in configuredAgentIds)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(configuredAgentId))
|
||||
ids.Add(configuredAgentId.Trim().ToLowerInvariant());
|
||||
}
|
||||
|
||||
return ids;
|
||||
}
|
||||
|
||||
public static string? NormalizeActorId(string? actorId, IReadOnlySet<string> allowedActorIds)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(actorId))
|
||||
return null;
|
||||
|
||||
var normalized = actorId.Trim().ToLowerInvariant();
|
||||
return allowedActorIds.Contains(normalized) ? normalized : null;
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,8 @@ public sealed record AgentConfig
|
||||
public string? AgentDir { get; init; }
|
||||
|
||||
[JsonPropertyName("model")]
|
||||
public string? Model { get; init; }
|
||||
[JsonConverter(typeof(AgentModelConfigConverter))]
|
||||
public AgentModelConfig? Model { get; init; }
|
||||
|
||||
[JsonPropertyName("identity")]
|
||||
public AgentIdentityConfig? Identity { get; init; }
|
||||
@@ -44,6 +45,60 @@ public sealed record AgentIdentityConfig
|
||||
public string Theme { get; init; } = string.Empty;
|
||||
}
|
||||
|
||||
public sealed record AgentModelConfig
|
||||
{
|
||||
[JsonPropertyName("primary")]
|
||||
public string? Primary { get; init; }
|
||||
}
|
||||
|
||||
public sealed class AgentModelConfigConverter : JsonConverter<AgentModelConfig>
|
||||
{
|
||||
public override AgentModelConfig? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
if (reader.TokenType == JsonTokenType.Null)
|
||||
return null;
|
||||
|
||||
if (reader.TokenType == JsonTokenType.String)
|
||||
{
|
||||
var primary = reader.GetString();
|
||||
return string.IsNullOrWhiteSpace(primary) ? null : new AgentModelConfig { Primary = primary };
|
||||
}
|
||||
|
||||
if (reader.TokenType != JsonTokenType.StartObject)
|
||||
throw new JsonException("Agent model must be either a string or an object.");
|
||||
|
||||
using var document = JsonDocument.ParseValue(ref reader);
|
||||
var root = document.RootElement;
|
||||
|
||||
string? primary = null;
|
||||
foreach (var property in root.EnumerateObject())
|
||||
{
|
||||
if (!string.Equals(property.Name, "primary", StringComparison.OrdinalIgnoreCase))
|
||||
continue;
|
||||
|
||||
primary = property.Value.ValueKind switch
|
||||
{
|
||||
JsonValueKind.String => property.Value.GetString(),
|
||||
JsonValueKind.Null => null,
|
||||
_ => throw new JsonException("Agent model primary must be a string.")
|
||||
};
|
||||
break;
|
||||
}
|
||||
|
||||
return new AgentModelConfig { Primary = primary };
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, AgentModelConfig value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
if (!string.IsNullOrWhiteSpace(value.Primary))
|
||||
writer.WriteString("primary", value.Primary);
|
||||
else
|
||||
writer.WriteNull("primary");
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
}
|
||||
|
||||
public sealed record AgentInfo(
|
||||
string Id,
|
||||
string Name,
|
||||
@@ -73,6 +128,7 @@ public interface IAgentService
|
||||
{
|
||||
Task<IReadOnlyCollection<AgentInfo>> GetAgentsAsync(CancellationToken cancellationToken);
|
||||
Task<AgentDetail?> GetAgentAsync(string id, CancellationToken cancellationToken);
|
||||
Task<IReadOnlySet<string>> GetAllowedAgentIdsAsync(CancellationToken cancellationToken);
|
||||
}
|
||||
|
||||
public sealed class AgentService(IConfiguration configuration, IAgentRuntime runtime) : IAgentService
|
||||
@@ -93,7 +149,7 @@ public sealed class AgentService(IConfiguration configuration, IAgentRuntime run
|
||||
var agents = new List<AgentInfo>(configs.Count);
|
||||
foreach (var config in configs)
|
||||
{
|
||||
var model = config.Model ?? "deepseek/deepseek-v4-flash";
|
||||
var model = ResolveModel(config);
|
||||
var role = DeriveRole(config.Id);
|
||||
var description = config.Identity?.Theme ?? string.Empty;
|
||||
|
||||
@@ -140,7 +196,7 @@ public sealed class AgentService(IConfiguration configuration, IAgentRuntime run
|
||||
Id: config.Id,
|
||||
Name: config.Identity?.Name ?? config.Name ?? config.Id,
|
||||
Role: role,
|
||||
Model: config.Model ?? "deepseek/deepseek-v4-flash",
|
||||
Model: ResolveModel(config),
|
||||
Status: runtimeStatus.Status,
|
||||
LastSeen: now,
|
||||
Workspace: config.Workspace,
|
||||
@@ -151,33 +207,50 @@ public sealed class AgentService(IConfiguration configuration, IAgentRuntime run
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public async Task<IReadOnlySet<string>> GetAllowedAgentIdsAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
var configs = await LoadAgentConfigsAsync(cancellationToken);
|
||||
return configs
|
||||
.Where(config => !string.IsNullOrWhiteSpace(config.Id))
|
||||
.Select(config => config.Id.Trim().ToLowerInvariant())
|
||||
.DefaultIfEmpty()
|
||||
.Where(id => !string.IsNullOrWhiteSpace(id))
|
||||
.ToHashSet(StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
private static string DeriveRole(string agentId) => agentId.ToLowerInvariant() switch
|
||||
{
|
||||
"iris" => "Orchestrator",
|
||||
"product-owner" => "Product Owner",
|
||||
"programmer" => "Developer",
|
||||
"programmer-fast" => "Developer",
|
||||
"reviewer" => "Reviewer",
|
||||
"architekt" => "Architect",
|
||||
"main" => "Assistant",
|
||||
_ => "Custom"
|
||||
};
|
||||
|
||||
private static string ResolveModel(AgentConfig config)
|
||||
=> config.Model?.Primary ?? "deepseek/deepseek-v4-flash";
|
||||
|
||||
private async Task<IReadOnlyList<AgentConfig>> LoadAgentConfigsAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
var path = configuration.GetValue<string>("AgentConfigPath")
|
||||
?? "/home/node/.openclaw/openclaw.json";
|
||||
|
||||
if (!File.Exists(path))
|
||||
return Array.Empty<AgentConfig>();
|
||||
return BuildFallbackConfigs();
|
||||
|
||||
var json = await File.ReadAllTextAsync(path, cancellationToken);
|
||||
using var document = JsonDocument.Parse(json, new JsonDocumentOptions { AllowTrailingCommas = true });
|
||||
var root = document.RootElement;
|
||||
|
||||
if (!root.TryGetProperty("agents", out var agentsElement))
|
||||
return Array.Empty<AgentConfig>();
|
||||
return BuildFallbackConfigs();
|
||||
|
||||
if (!agentsElement.TryGetProperty("list", out var listElement))
|
||||
return Array.Empty<AgentConfig>();
|
||||
return BuildFallbackConfigs();
|
||||
|
||||
var defaults = agentsElement.TryGetProperty("defaults", out var defaultsElement)
|
||||
? JsonSerializer.Deserialize<AgentDefaults>(defaultsElement.GetRawText(), JsonOptions)
|
||||
@@ -193,29 +266,35 @@ public sealed class AgentService(IConfiguration configuration, IAgentRuntime run
|
||||
// Inherit defaults for missing fields
|
||||
if (string.IsNullOrWhiteSpace(config.Name))
|
||||
config = config with { Name = config.Id };
|
||||
if (string.IsNullOrWhiteSpace(config.Model) && defaults?.Model?.Primary is not null)
|
||||
config = config with { Model = defaults.Model.Primary };
|
||||
if (string.IsNullOrWhiteSpace(config.Model?.Primary) && defaults?.Model?.Primary is not null)
|
||||
config = config with { Model = new AgentModelConfig { Primary = defaults.Model.Primary } };
|
||||
if (string.IsNullOrWhiteSpace(config.Workspace) && defaults?.Workspace is not null)
|
||||
config = config with { Workspace = defaults.Workspace };
|
||||
|
||||
configs.Add(config);
|
||||
}
|
||||
|
||||
return configs.AsReadOnly();
|
||||
return configs.Count > 0 ? configs.AsReadOnly() : BuildFallbackConfigs();
|
||||
}
|
||||
|
||||
private static IReadOnlyList<AgentConfig> BuildFallbackConfigs()
|
||||
=> AgentIdentityCatalog.DefaultConfiguredAgentIds
|
||||
.Select(id => new AgentConfig
|
||||
{
|
||||
Id = id,
|
||||
Name = id,
|
||||
Model = new AgentModelConfig { Primary = "deepseek/deepseek-v4-flash" }
|
||||
})
|
||||
.ToList()
|
||||
.AsReadOnly();
|
||||
|
||||
private sealed record AgentDefaults
|
||||
{
|
||||
[JsonPropertyName("workspace")]
|
||||
public string? Workspace { get; init; }
|
||||
|
||||
[JsonPropertyName("model")]
|
||||
public AgentDefaultModel? Model { get; init; }
|
||||
}
|
||||
|
||||
private sealed record AgentDefaultModel
|
||||
{
|
||||
[JsonPropertyName("primary")]
|
||||
public string? Primary { get; init; }
|
||||
[JsonConverter(typeof(AgentModelConfigConverter))]
|
||||
public AgentModelConfig? Model { get; init; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,6 +56,11 @@ public sealed class AuthService : IAuthService
|
||||
user.LastLoginAt = DateTimeOffset.UtcNow;
|
||||
user.UpdatedAt = DateTimeOffset.UtcNow;
|
||||
|
||||
// Persist user changes (password upgrade, login timestamp) immediately.
|
||||
// Relying solely on RemoveExpiredTokensAsync / AddRefreshTokenAsync to
|
||||
// trigger SaveChangesAsync is fragile — if zero tokens are expired the
|
||||
// tracked changes might not be flushed before the response is produced.
|
||||
await _users.UpdateAsync(user, ct);
|
||||
await _users.RemoveExpiredTokensAsync(user.Id, ct);
|
||||
return await CreateSessionAsync(user, Guid.NewGuid(), null, ct);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
using System.Threading.Channels;
|
||||
using Nexus.Api.Models;
|
||||
|
||||
namespace Nexus.Api.Services;
|
||||
|
||||
public interface ILiveUpdateService
|
||||
{
|
||||
Task<LiveUpdateSubscription> SubscribeAsync(long? afterSequence = null, CancellationToken ct = default);
|
||||
LiveUpdateEnvelope Publish(string type, object payload, string channel = "dashboard");
|
||||
long CurrentSequence { get; }
|
||||
}
|
||||
|
||||
public sealed class LiveUpdateSubscription
|
||||
{
|
||||
public ChannelReader<LiveUpdateEnvelope> Reader { get; init; } = default!;
|
||||
public long StartingSequence { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Nexus.Api.Data;
|
||||
using Nexus.Api.Models;
|
||||
|
||||
namespace Nexus.Api.Services;
|
||||
|
||||
public interface INotificationService
|
||||
{
|
||||
Task<Notification> CreateAsync(string type, string title, string? message, string forUser, Guid? taskId = null, CancellationToken ct = default);
|
||||
Task<IReadOnlyList<Notification>> GetForUserAsync(string forUser, int limit = 50, bool unreadOnly = false, CancellationToken ct = default);
|
||||
Task<bool> MarkAsReadAsync(Guid id, CancellationToken ct = default);
|
||||
Task<int> MarkAllAsReadAsync(string forUser, CancellationToken ct = default);
|
||||
Task<int> GetUnreadCountAsync(string forUser, CancellationToken ct = default);
|
||||
Task<NotificationSnapshotDto> GetSnapshotAsync(string forUser, int limit = 50, bool unreadOnly = false, CancellationToken ct = default);
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
using Nexus.Api.Data;
|
||||
using Nexus.Api.DTOs;
|
||||
using Nexus.Api.Models;
|
||||
|
||||
namespace Nexus.Api.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Structured backend bridge for agent/task commands.
|
||||
/// Provides a clean, typed API for agents (Iris and sub-agents) to interact
|
||||
/// with the task board, activity log, and delegation workflow.
|
||||
///
|
||||
/// This is the internal service layer — never exposed directly to the browser.
|
||||
/// The GatewayBridgeController wraps this for agent-facing HTTP access.
|
||||
/// </summary>
|
||||
public interface ITaskBridgeService
|
||||
{
|
||||
// ── Task CRUD (Agent-Commands) ──
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new top-level task (parent or standalone).
|
||||
/// Returns the created task DTO.
|
||||
/// </summary>
|
||||
Task<TaskBridgeResult<DashboardTaskDto>> CreateTaskAsync(
|
||||
string title,
|
||||
string? detail = null,
|
||||
string? source = "iris",
|
||||
string? priority = "Normal",
|
||||
string? assignedTo = null,
|
||||
Guid? projectId = null,
|
||||
CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a child task linked to an existing parent.
|
||||
/// This is the primary delegation command: iris creates a child task,
|
||||
/// assigns it to a sub-agent, and tracks it on the board.
|
||||
/// </summary>
|
||||
Task<TaskBridgeResult<DashboardTaskDto>> CreateChildTaskAsync(
|
||||
Guid parentTaskId,
|
||||
string title,
|
||||
string? detail = null,
|
||||
string? source = "iris",
|
||||
string? priority = "Normal",
|
||||
string? assignedTo = null,
|
||||
string? expectedFrom = null,
|
||||
bool startsInProgress = false,
|
||||
CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Updates the status/state of a task.
|
||||
/// Enforces CanChangeState rules (only iris/bao/nexus-system may change state).
|
||||
/// </summary>
|
||||
Task<TaskBridgeResult<DashboardTaskDto>> UpdateStatusAsync(
|
||||
Guid taskId,
|
||||
string state,
|
||||
string? callerAgent = null,
|
||||
CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Appends an activity entry to a task (comment, status note, agent note).
|
||||
/// Used by agents to annotate their progress on the board.
|
||||
/// </summary>
|
||||
Task<TaskBridgeResult<ActivityEvent>> AppendActivityAsync(
|
||||
Guid taskId,
|
||||
string message,
|
||||
string? type = "comment",
|
||||
CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Handles a task handoff: sets ExpectedFrom to the target agent,
|
||||
/// appends a handoff activity entry, and optionally updates assigned-to.
|
||||
/// </summary>
|
||||
Task<TaskBridgeResult<DashboardTaskDto>> HandoffAsync(
|
||||
Guid taskId,
|
||||
string targetAgent,
|
||||
string? note = null,
|
||||
CancellationToken ct = default);
|
||||
|
||||
// ── Query (Read) ──
|
||||
|
||||
/// <summary>
|
||||
/// Returns the full task board state (grouped by status column).
|
||||
/// </summary>
|
||||
Task<BoardResponse> GetBoardAsync(CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a single task by ID.
|
||||
/// </summary>
|
||||
Task<TaskBridgeResult<DashboardTaskDto>> GetTaskAsync(
|
||||
Guid taskId,
|
||||
CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Returns all child tasks for a given parent task.
|
||||
/// </summary>
|
||||
Task<IReadOnlyList<DashboardTaskDto>> GetChildTasksAsync(
|
||||
Guid parentTaskId,
|
||||
CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Returns task activity history.
|
||||
/// </summary>
|
||||
Task<List<ActivityEvent>> GetTaskActivityAsync(
|
||||
Guid taskId,
|
||||
CancellationToken ct = default);
|
||||
|
||||
// ── Agent Workflow ──
|
||||
|
||||
/// <summary>
|
||||
/// Returns the agent-workflow overview: who is expected to respond,
|
||||
/// stale tasks, workload distribution.
|
||||
/// </summary>
|
||||
Task<AgentWorkflowOverview> GetAgentOverviewAsync(
|
||||
TimeSpan? staleThreshold = null,
|
||||
CancellationToken ct = default);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Result pattern for task-bridge operations.
|
||||
/// WorkTask? is null on NotFound; state is stored in the Outcome.
|
||||
/// </summary>
|
||||
public sealed record TaskBridgeResult<T>(
|
||||
TaskBridgeOutcome Outcome,
|
||||
T? Data = default,
|
||||
string? Error = null
|
||||
);
|
||||
|
||||
public enum TaskBridgeOutcome
|
||||
{
|
||||
Success,
|
||||
NotFound,
|
||||
InvalidState,
|
||||
Unauthorized,
|
||||
ValidationError
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using Nexus.Api.Data;
|
||||
using Nexus.Api.DTOs;
|
||||
using Nexus.Api.Models;
|
||||
|
||||
namespace Nexus.Api.Services;
|
||||
|
||||
@@ -21,9 +22,24 @@ public interface ITaskService
|
||||
|
||||
// Dashboard-facing task operations
|
||||
Task<IReadOnlyList<WorkTask>> GetOpenAsync(CancellationToken ct = default);
|
||||
Task<WorkTask> CreateDashboardTaskAsync(string title, string? detail, string? source, string? priority, string? assignedTo, CancellationToken ct = default);
|
||||
Task<TaskOperationResult> UpdateDashboardTaskAsync(Guid id, string? title, string? detail, string? source, string? priority, string? assignedTo, CancellationToken ct = default);
|
||||
Task<WorkTask> CreateDashboardTaskAsync(string title, string? detail, string? source, string? priority, string? assignedTo, Guid? parentTaskId = null, CancellationToken ct = default);
|
||||
Task<WorkTask> CreateAgentTaskAsync(string title, string? detail, string? source, string? priority, string? assignedTo, string? expectedFrom, Guid? parentTaskId = null, bool startsInProgress = true, string? initialState = null, CancellationToken ct = default);
|
||||
Task<TaskOperationResult> UpdateDashboardTaskAsync(Guid id, string? title, string? detail, string? source, string? priority, string? assignedTo, DateTimeOffset? dueDate = null, CancellationToken ct = default);
|
||||
Task<TaskOperationResult> UpdateStatusAsync(Guid id, string status, CancellationToken ct = default);
|
||||
Task<TaskOperationResult> StartCoordinationAsync(Guid id, CancellationToken ct = default);
|
||||
Task<TaskOperationResult> CompleteViaQueueAsync(Guid id, CancellationToken ct = default);
|
||||
Task<TaskOperationResult> CyclePriorityAsync(Guid id, CancellationToken ct = default);
|
||||
|
||||
// Task Board
|
||||
Task<BoardResponse> GetBoardAsync(CancellationToken ct = default);
|
||||
Task<TaskOperationResult> MoveTaskAsync(Guid id, string newState, CancellationToken ct = default);
|
||||
Task<int> ResetStaleAsync(int staleHours, CancellationToken ct = default);
|
||||
Task<int> ResetStaleInProgressTasksAsync(TimeSpan staleThreshold, CancellationToken ct = default);
|
||||
Task<IReadOnlyList<WorkTask>> GetChildTasksAsync(Guid parentId, CancellationToken ct = default);
|
||||
Task<List<ActivityEvent>> GetTaskActivityAsync(Guid taskId, CancellationToken ct = default);
|
||||
Task<DashboardTaskDto?> GetDashboardTaskByIdAsync(Guid id, CancellationToken ct = default);
|
||||
|
||||
// Agent Workflow Overview
|
||||
Task<IReadOnlyList<WorkTask>> GetWaitingTasksAsync(CancellationToken ct = default);
|
||||
Task<AgentWorkflowOverview> GetAgentWorkflowOverviewAsync(TimeSpan staleThreshold, CancellationToken ct = default);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Threading.Channels;
|
||||
using Nexus.Api.Models;
|
||||
|
||||
namespace Nexus.Api.Services;
|
||||
|
||||
public sealed class LiveUpdateService : ILiveUpdateService
|
||||
{
|
||||
private const int ReplayLimit = 256;
|
||||
|
||||
private readonly ConcurrentDictionary<Guid, Channel<LiveUpdateEnvelope>> _subscribers = new();
|
||||
private readonly object _historyLock = new();
|
||||
private readonly Queue<LiveUpdateEnvelope> _history = new();
|
||||
private long _sequence;
|
||||
|
||||
public long CurrentSequence => Interlocked.Read(ref _sequence);
|
||||
|
||||
public Task<LiveUpdateSubscription> SubscribeAsync(long? afterSequence = null, CancellationToken ct = default)
|
||||
{
|
||||
var channel = Channel.CreateUnbounded<LiveUpdateEnvelope>(new UnboundedChannelOptions
|
||||
{
|
||||
SingleReader = true,
|
||||
SingleWriter = false,
|
||||
AllowSynchronousContinuations = false
|
||||
});
|
||||
|
||||
var id = Guid.NewGuid();
|
||||
_subscribers[id] = channel;
|
||||
|
||||
var replay = afterSequence.HasValue ? GetReplay(afterSequence.Value) : Array.Empty<LiveUpdateEnvelope>();
|
||||
foreach (var envelope in replay)
|
||||
{
|
||||
channel.Writer.TryWrite(envelope);
|
||||
}
|
||||
|
||||
ct.Register(() =>
|
||||
{
|
||||
if (_subscribers.TryRemove(id, out var removed))
|
||||
{
|
||||
removed.Writer.TryComplete();
|
||||
}
|
||||
});
|
||||
|
||||
return Task.FromResult(new LiveUpdateSubscription
|
||||
{
|
||||
Reader = channel.Reader,
|
||||
StartingSequence = replay.LastOrDefault()?.Sequence ?? CurrentSequence
|
||||
});
|
||||
}
|
||||
|
||||
public LiveUpdateEnvelope Publish(string type, object payload, string channel = "dashboard")
|
||||
{
|
||||
var envelope = new LiveUpdateEnvelope(
|
||||
type,
|
||||
DateTimeOffset.UtcNow,
|
||||
payload,
|
||||
Interlocked.Increment(ref _sequence),
|
||||
channel);
|
||||
|
||||
lock (_historyLock)
|
||||
{
|
||||
_history.Enqueue(envelope);
|
||||
while (_history.Count > ReplayLimit)
|
||||
{
|
||||
_history.Dequeue();
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var (id, subscriber) in _subscribers)
|
||||
{
|
||||
if (!subscriber.Writer.TryWrite(envelope) && _subscribers.TryRemove(id, out var removed))
|
||||
{
|
||||
removed.Writer.TryComplete();
|
||||
}
|
||||
}
|
||||
|
||||
return envelope;
|
||||
}
|
||||
|
||||
private LiveUpdateEnvelope[] GetReplay(long afterSequence)
|
||||
{
|
||||
lock (_historyLock)
|
||||
{
|
||||
return _history.Where(item => item.Sequence > afterSequence).ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Nexus.Api.Data;
|
||||
using Nexus.Api.Models;
|
||||
|
||||
namespace Nexus.Api.Services;
|
||||
|
||||
public sealed class NotificationService(NexusDbContext db, ILiveUpdateService liveUpdateService) : INotificationService
|
||||
{
|
||||
public async Task<Notification> CreateAsync(string type, string title, string? message, string forUser, Guid? taskId = null, CancellationToken ct = default)
|
||||
{
|
||||
var notification = new Notification
|
||||
{
|
||||
Type = type,
|
||||
Title = title,
|
||||
Message = message,
|
||||
ForUser = forUser.ToLowerInvariant(),
|
||||
TaskId = taskId
|
||||
};
|
||||
db.Notifications.Add(notification);
|
||||
await db.SaveChangesAsync(ct);
|
||||
await PublishSnapshotAsync(notification.ForUser, ct);
|
||||
return notification;
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyList<Notification>> GetForUserAsync(string forUser, int limit = 50, bool unreadOnly = false, CancellationToken ct = default)
|
||||
{
|
||||
var query = db.Notifications
|
||||
.Where(n => n.ForUser == forUser.ToLowerInvariant());
|
||||
|
||||
if (unreadOnly)
|
||||
query = query.Where(n => !n.IsRead);
|
||||
|
||||
return await query
|
||||
.OrderByDescending(n => n.CreatedAt)
|
||||
.Take(limit)
|
||||
.ToListAsync(ct);
|
||||
}
|
||||
|
||||
public async Task<bool> MarkAsReadAsync(Guid id, CancellationToken ct = default)
|
||||
{
|
||||
var notification = await db.Notifications.FindAsync([id], ct);
|
||||
if (notification is null) return false;
|
||||
|
||||
notification.IsRead = true;
|
||||
await db.SaveChangesAsync(ct);
|
||||
await PublishSnapshotAsync(notification.ForUser, ct);
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task<int> MarkAllAsReadAsync(string forUser, CancellationToken ct = default)
|
||||
{
|
||||
var normalizedUser = forUser.ToLowerInvariant();
|
||||
var count = await db.Notifications
|
||||
.Where(n => n.ForUser == normalizedUser && !n.IsRead)
|
||||
.ExecuteUpdateAsync(s => s.SetProperty(n => n.IsRead, true), ct);
|
||||
await PublishSnapshotAsync(normalizedUser, ct);
|
||||
return count;
|
||||
}
|
||||
|
||||
public async Task<int> GetUnreadCountAsync(string forUser, CancellationToken ct = default)
|
||||
{
|
||||
return await db.Notifications
|
||||
.CountAsync(n => n.ForUser == forUser.ToLowerInvariant() && !n.IsRead, ct);
|
||||
}
|
||||
|
||||
public async Task<NotificationSnapshotDto> GetSnapshotAsync(string forUser, int limit = 50, bool unreadOnly = false, CancellationToken ct = default)
|
||||
{
|
||||
var normalizedUser = forUser.ToLowerInvariant();
|
||||
var notifications = await GetForUserAsync(normalizedUser, limit, unreadOnly, ct);
|
||||
var unreadCount = await GetUnreadCountAsync(normalizedUser, ct);
|
||||
return new NotificationSnapshotDto(
|
||||
notifications.Select(MapToDto).ToList(),
|
||||
unreadCount,
|
||||
normalizedUser);
|
||||
}
|
||||
|
||||
private async Task PublishSnapshotAsync(string forUser, CancellationToken ct)
|
||||
{
|
||||
var snapshot = await GetSnapshotAsync(forUser, ct: ct);
|
||||
liveUpdateService.Publish("notifications.snapshot", snapshot, "notifications");
|
||||
}
|
||||
|
||||
private static NotificationDto MapToDto(Notification n) => new(
|
||||
n.Id, n.Type, n.Title, n.Message,
|
||||
n.ForUser, n.TaskId, n.IsRead, n.CreatedAt);
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
using Microsoft.Extensions.Primitives;
|
||||
|
||||
namespace Nexus.Api.Services;
|
||||
|
||||
public static class RequestAuthorizationHelper
|
||||
{
|
||||
public sealed record AgentHeaderResolution(string? AgentId, bool HeaderProvided, bool IsRecognized);
|
||||
|
||||
public static bool IsAuthenticatedService(HttpContext httpContext, IConfiguration configuration) =>
|
||||
httpContext.User.IsInRole("Service") || HasValidServiceKey(httpContext, configuration);
|
||||
|
||||
public static bool IsPrivilegedUser(HttpContext httpContext) =>
|
||||
httpContext.User.Identity?.IsAuthenticated == true &&
|
||||
(httpContext.User.IsInRole("owner") || httpContext.User.IsInRole("admin"));
|
||||
|
||||
public static async Task<string?> ResolveAllowedAgentHeaderAsync(
|
||||
HttpContext httpContext,
|
||||
IAgentService agentService,
|
||||
CancellationToken ct)
|
||||
=> (await ResolveAgentHeaderAsync(httpContext, agentService, ct)).AgentId;
|
||||
|
||||
public static async Task<AgentHeaderResolution> ResolveAgentHeaderAsync(
|
||||
HttpContext httpContext,
|
||||
IAgentService agentService,
|
||||
CancellationToken ct)
|
||||
{
|
||||
var headerValue = httpContext.Request.Headers["X-Agent-Id"].FirstOrDefault();
|
||||
if (string.IsNullOrWhiteSpace(headerValue))
|
||||
return new AgentHeaderResolution(null, HeaderProvided: false, IsRecognized: false);
|
||||
|
||||
var allowed = AgentIdentityCatalog.BuildAllowedActorIds(await agentService.GetAllowedAgentIdsAsync(ct));
|
||||
var normalized = AgentIdentityCatalog.NormalizeActorId(headerValue, allowed);
|
||||
return new AgentHeaderResolution(
|
||||
normalized,
|
||||
HeaderProvided: true,
|
||||
IsRecognized: normalized is not null);
|
||||
}
|
||||
|
||||
public static bool HasValidServiceKey(HttpContext httpContext, IConfiguration configuration)
|
||||
{
|
||||
var configuredApiKey = configuration["NexusApiKey"];
|
||||
if (string.IsNullOrWhiteSpace(configuredApiKey))
|
||||
return false;
|
||||
|
||||
if (!httpContext.Request.Headers.TryGetValue("X-Nexus-Api-Key", out StringValues providedKey))
|
||||
return false;
|
||||
|
||||
return string.Equals(configuredApiKey, providedKey.FirstOrDefault(), StringComparison.Ordinal);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,264 @@
|
||||
using Nexus.Api.Data;
|
||||
using Nexus.Api.DTOs;
|
||||
using Nexus.Api.Models;
|
||||
using Nexus.Api.Repositories;
|
||||
|
||||
namespace Nexus.Api.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Concrete implementation of ITaskBridgeService.
|
||||
/// Wraps ITaskService, IActivityRepository, INotificationService, and ILiveUpdateService
|
||||
/// into structured, predictable commands for agent-facing usage.
|
||||
///
|
||||
/// All operations produce typed TaskBridgeResult<T> with explicit error codes,
|
||||
/// making agent consumption safe and debuggable.
|
||||
/// </summary>
|
||||
public sealed class TaskBridgeService(
|
||||
ITaskService taskService,
|
||||
IAgentService agentService,
|
||||
IActivityRepository activityRepo,
|
||||
INotificationService notificationService,
|
||||
ILiveUpdateService liveUpdateService) : ITaskBridgeService
|
||||
{
|
||||
private static readonly HashSet<string> ValidStates =
|
||||
new(TaskStateHelper.AllStates, StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
// ──────────────────────────────── Create Task ────────────────────────────────
|
||||
|
||||
public async Task<TaskBridgeResult<DashboardTaskDto>> CreateTaskAsync(
|
||||
string title,
|
||||
string? detail = null,
|
||||
string? source = "iris",
|
||||
string? priority = "Normal",
|
||||
string? assignedTo = null,
|
||||
Guid? projectId = null,
|
||||
CancellationToken ct = default)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(title))
|
||||
return Error<DashboardTaskDto>(TaskBridgeOutcome.ValidationError, "Title is required.");
|
||||
|
||||
var normalizedSource = NormalizeSource(source);
|
||||
|
||||
var task = await taskService.CreateDashboardTaskAsync(
|
||||
title.Trim(), detail?.Trim(), normalizedSource, priority, assignedTo, parentTaskId: null, ct);
|
||||
|
||||
var dto = await taskService.GetDashboardTaskByIdAsync(task.Id, ct) ?? MapToDto(task);
|
||||
return Success(dto);
|
||||
}
|
||||
|
||||
// ──────────────────────────────── Create Child Task ──────────────────────────
|
||||
|
||||
public async Task<TaskBridgeResult<DashboardTaskDto>> CreateChildTaskAsync(
|
||||
Guid parentTaskId,
|
||||
string title,
|
||||
string? detail = null,
|
||||
string? source = "iris",
|
||||
string? priority = "Normal",
|
||||
string? assignedTo = null,
|
||||
string? expectedFrom = null,
|
||||
bool startsInProgress = false,
|
||||
CancellationToken ct = default)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(title))
|
||||
return Error<DashboardTaskDto>(TaskBridgeOutcome.ValidationError, "Title is required.");
|
||||
|
||||
// Verify parent exists
|
||||
var parent = await taskService.GetByIdAsync(parentTaskId, ct);
|
||||
if (parent is null)
|
||||
return Error<DashboardTaskDto>(TaskBridgeOutcome.NotFound, $"Parent task {parentTaskId} not found.");
|
||||
|
||||
var task = await taskService.CreateAgentTaskAsync(
|
||||
title.Trim(), detail?.Trim(), NormalizeSource(source),
|
||||
priority, assignedTo, expectedFrom, parentTaskId, startsInProgress, null, ct);
|
||||
|
||||
// If parent was in Backlog, move it to InProgress (coordination starts)
|
||||
if (string.Equals(parent.State, "Backlog", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var parentTransition = await taskService.StartCoordinationAsync(parentTaskId, ct);
|
||||
if (parentTransition.Outcome != TaskOperationOutcome.Success)
|
||||
{
|
||||
return Error<DashboardTaskDto>(
|
||||
TaskBridgeOutcome.InvalidState,
|
||||
$"Parent task {parentTaskId} could not be moved to In progress for coordination.");
|
||||
}
|
||||
}
|
||||
|
||||
var dto = await taskService.GetDashboardTaskByIdAsync(task.Id, ct) ?? MapToDto(task);
|
||||
return Success(dto);
|
||||
}
|
||||
|
||||
// ──────────────────────────────── Update Status ──────────────────────────────
|
||||
|
||||
public async Task<TaskBridgeResult<DashboardTaskDto>> UpdateStatusAsync(
|
||||
Guid taskId,
|
||||
string state,
|
||||
string? callerAgent = null,
|
||||
CancellationToken ct = default)
|
||||
{
|
||||
if (!ValidStates.Contains(state))
|
||||
return Error<DashboardTaskDto>(TaskBridgeOutcome.ValidationError,
|
||||
$"Invalid state '{state}'. Valid: {string.Join(", ", TaskStateHelper.AllStates)}");
|
||||
|
||||
var task = await taskService.GetByIdAsync(taskId, ct);
|
||||
if (task is null)
|
||||
return Error<DashboardTaskDto>(TaskBridgeOutcome.NotFound, $"Task {taskId} not found.");
|
||||
|
||||
// Check authorization
|
||||
if (!TaskStateHelper.CanChangeState(callerAgent, task))
|
||||
return Error<DashboardTaskDto>(TaskBridgeOutcome.Unauthorized,
|
||||
$"Agent '{callerAgent}' is not authorized to change task state. Only iris and bao may move tasks.");
|
||||
|
||||
var result = await taskService.UpdateStatusAsync(taskId, state, ct);
|
||||
if (result.Outcome != TaskOperationOutcome.Success)
|
||||
return Error<DashboardTaskDto>(TaskBridgeOutcome.InvalidState, "Status update rejected.");
|
||||
|
||||
var dto = await taskService.GetDashboardTaskByIdAsync(result.Task!.Id, ct) ?? MapToDto(result.Task);
|
||||
return Success(dto);
|
||||
}
|
||||
|
||||
// ──────────────────────────────── Append Activity ────────────────────────────
|
||||
|
||||
public async Task<TaskBridgeResult<ActivityEvent>> AppendActivityAsync(
|
||||
Guid taskId,
|
||||
string message,
|
||||
string? type = "comment",
|
||||
CancellationToken ct = default)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(message))
|
||||
return Error<ActivityEvent>(TaskBridgeOutcome.ValidationError, "Message is required.");
|
||||
|
||||
var task = await taskService.GetByIdAsync(taskId, ct);
|
||||
if (task is null)
|
||||
return Error<ActivityEvent>(TaskBridgeOutcome.NotFound, $"Task {taskId} not found.");
|
||||
|
||||
var ev = new ActivityEvent
|
||||
{
|
||||
Type = type ?? "comment",
|
||||
Message = message.Trim(),
|
||||
TaskId = taskId
|
||||
};
|
||||
|
||||
await activityRepo.AddAsync(ev, ct);
|
||||
|
||||
// Trigger live update so the board refreshes
|
||||
var board = await taskService.GetBoardAsync(ct);
|
||||
liveUpdateService.Publish("tasks.board.snapshot", board);
|
||||
|
||||
return Success(ev);
|
||||
}
|
||||
|
||||
// ──────────────────────────────── Handoff ────────────────────────────────────
|
||||
|
||||
public async Task<TaskBridgeResult<DashboardTaskDto>> HandoffAsync(
|
||||
Guid taskId,
|
||||
string targetAgent,
|
||||
string? note = null,
|
||||
CancellationToken ct = default)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(targetAgent))
|
||||
return Error<DashboardTaskDto>(TaskBridgeOutcome.ValidationError, "Target agent is required.");
|
||||
|
||||
var task = await taskService.GetByIdAsync(taskId, ct);
|
||||
if (task is null)
|
||||
return Error<DashboardTaskDto>(TaskBridgeOutcome.NotFound, $"Task {taskId} not found.");
|
||||
|
||||
var normalizedTarget = await NormalizeActorAsync(targetAgent, ct);
|
||||
if (normalizedTarget is null)
|
||||
return Error<DashboardTaskDto>(TaskBridgeOutcome.ValidationError, $"Unknown target agent '{targetAgent}'.");
|
||||
|
||||
var handoffNote = string.IsNullOrWhiteSpace(note)
|
||||
? $"Handoff → {normalizedTarget}"
|
||||
: $"Handoff → {normalizedTarget}: {note.Trim()}";
|
||||
|
||||
// Update expected-from and optionally assigned-to
|
||||
task.ExpectedFrom = normalizedTarget;
|
||||
|
||||
// If this is a child task (has parent), keep assigned-to on the child
|
||||
// If standalone, set assigned-to to the target
|
||||
if (!task.ParentTaskId.HasValue)
|
||||
task.AssignedTo = normalizedTarget;
|
||||
|
||||
await taskService.UpdateDashboardTaskAsync(
|
||||
taskId, title: null, detail: null, source: null,
|
||||
priority: null, assignedTo: task.AssignedTo, dueDate: null, ct);
|
||||
|
||||
// Append handoff activity
|
||||
await AppendActivityAsync(taskId, handoffNote, "handoff", ct);
|
||||
|
||||
// Notify the target
|
||||
await notificationService.CreateAsync(
|
||||
"task_assigned",
|
||||
$"Handoff: {task.Title}",
|
||||
handoffNote,
|
||||
normalizedTarget,
|
||||
task.Id,
|
||||
ct);
|
||||
|
||||
var dto = await taskService.GetDashboardTaskByIdAsync(task.Id, ct) ?? MapToDto(task);
|
||||
return Success(dto);
|
||||
}
|
||||
|
||||
// ──────────────────────────────── Query ──────────────────────────────────────
|
||||
|
||||
public async Task<BoardResponse> GetBoardAsync(CancellationToken ct = default)
|
||||
=> await taskService.GetBoardAsync(ct);
|
||||
|
||||
public async Task<TaskBridgeResult<DashboardTaskDto>> GetTaskAsync(
|
||||
Guid taskId, CancellationToken ct = default)
|
||||
{
|
||||
var dto = await taskService.GetDashboardTaskByIdAsync(taskId, ct);
|
||||
return dto is null
|
||||
? Error<DashboardTaskDto>(TaskBridgeOutcome.NotFound, $"Task {taskId} not found.")
|
||||
: Success(dto);
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyList<DashboardTaskDto>> GetChildTasksAsync(
|
||||
Guid parentTaskId, CancellationToken ct = default)
|
||||
{
|
||||
var board = await taskService.GetBoardAsync(ct);
|
||||
return FlattenBoard(board)
|
||||
.Where(task => task.ParentTaskId == parentTaskId)
|
||||
.OrderByDescending(task => task.UpdatedAt)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public async Task<List<ActivityEvent>> GetTaskActivityAsync(
|
||||
Guid taskId, CancellationToken ct = default)
|
||||
=> await taskService.GetTaskActivityAsync(taskId, ct);
|
||||
|
||||
public async Task<AgentWorkflowOverview> GetAgentOverviewAsync(
|
||||
TimeSpan? staleThreshold = null, CancellationToken ct = default)
|
||||
{
|
||||
var threshold = staleThreshold ?? TimeSpan.FromHours(2);
|
||||
return await taskService.GetAgentWorkflowOverviewAsync(threshold, ct);
|
||||
}
|
||||
|
||||
// ──────────────────────────────── Helpers ────────────────────────────────────
|
||||
|
||||
private static TaskBridgeResult<T> Success<T>(T data) =>
|
||||
new(TaskBridgeOutcome.Success, data);
|
||||
|
||||
private static TaskBridgeResult<T> Error<T>(TaskBridgeOutcome outcome, string error) =>
|
||||
new(outcome, Data: default, Error: error);
|
||||
|
||||
private static string NormalizeSource(string? source) =>
|
||||
string.IsNullOrWhiteSpace(source) ? "iris" : source.Trim().ToLowerInvariant();
|
||||
|
||||
private async Task<string?> NormalizeActorAsync(string? actorId, CancellationToken ct)
|
||||
{
|
||||
var allowedActors = AgentIdentityCatalog.BuildAllowedActorIds(await agentService.GetAllowedAgentIdsAsync(ct));
|
||||
return AgentIdentityCatalog.NormalizeActorId(actorId, allowedActors);
|
||||
}
|
||||
|
||||
private static IEnumerable<DashboardTaskDto> FlattenBoard(BoardResponse board)
|
||||
=> board.Offen
|
||||
.Concat(board.InProgress)
|
||||
.Concat(board.Review)
|
||||
.Concat(board.Blocked)
|
||||
.Concat(board.Done);
|
||||
|
||||
private static DashboardTaskDto MapToDto(WorkTask t) => new(
|
||||
t.Id, t.Title, t.Detail, t.Source, t.State, t.Priority, t.AssignedTo,
|
||||
t.ParentTaskId, t.DueDate, t.CreatedAt, t.UpdatedAt,
|
||||
t.IsAgentTask, t.ExpectedFrom);
|
||||
}
|
||||
+523
-32
@@ -1,12 +1,17 @@
|
||||
using Nexus.Api.Data;
|
||||
using Nexus.Api.DTOs;
|
||||
using Nexus.Api.Models;
|
||||
using Nexus.Api.Repositories;
|
||||
|
||||
namespace Nexus.Api.Services;
|
||||
|
||||
public sealed class TaskService(
|
||||
ITaskRepository taskRepo,
|
||||
IActivityRepository activityRepo) : ITaskService
|
||||
IActivityRepository activityRepo,
|
||||
INotificationService notificationService,
|
||||
IAgentService agentService,
|
||||
IHttpContextAccessor httpContextAccessor,
|
||||
ILiveUpdateService liveUpdateService) : ITaskService
|
||||
{
|
||||
public async Task<IReadOnlyList<WorkTask>> GetAllAsync(CancellationToken ct = default)
|
||||
=> await taskRepo.GetAllAsync(ct);
|
||||
@@ -14,6 +19,16 @@ public sealed class TaskService(
|
||||
public async Task<WorkTask?> GetByIdAsync(Guid id, CancellationToken ct = default)
|
||||
=> await taskRepo.GetByIdAsync(id, ct);
|
||||
|
||||
public async Task<DashboardTaskDto?> GetDashboardTaskByIdAsync(Guid id, CancellationToken ct = default)
|
||||
{
|
||||
var allTasks = (await taskRepo.GetAllAsync(ct)).ToList();
|
||||
var task = allTasks.FirstOrDefault(t => t.Id == id);
|
||||
if (task is null) return null;
|
||||
|
||||
var activity = await activityRepo.GetRecentForTasksAsync(allTasks.Select(t => t.Id), ct);
|
||||
return MapToDtoWithChildren(task, allTasks, activity);
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyList<WorkTask>> GetPendingApprovalAsync(CancellationToken ct = default)
|
||||
=> await taskRepo.GetPendingApprovalAsync(ct);
|
||||
|
||||
@@ -26,7 +41,8 @@ public sealed class TaskService(
|
||||
ProjectId = request.ProjectId
|
||||
};
|
||||
await taskRepo.AddAsync(task, ct);
|
||||
await activityRepo.AddAsync(new ActivityEvent { Type = "task", Message = $"Task {task.Title} created" }, ct);
|
||||
await activityRepo.AddAsync(new ActivityEvent { Type = "task", Message = $"Task {task.Title} created", TaskId = task.Id }, ct);
|
||||
await PublishBoardSnapshotAsync(ct);
|
||||
return task;
|
||||
}
|
||||
|
||||
@@ -40,7 +56,8 @@ public sealed class TaskService(
|
||||
|
||||
task.State = TaskStateHelper.ToStateString(TaskState.Done);
|
||||
await taskRepo.UpdateAsync(task, ct);
|
||||
await activityRepo.AddAsync(new ActivityEvent { Type = "task", Message = $"Task {task.Title} approved" }, ct);
|
||||
await activityRepo.AddAsync(new ActivityEvent { Type = "task", Message = $"Task {task.Title} approved", TaskId = task.Id }, ct);
|
||||
await PublishBoardSnapshotAsync(ct);
|
||||
return new TaskOperationResult(TaskOperationOutcome.Success, task);
|
||||
}
|
||||
|
||||
@@ -54,7 +71,8 @@ public sealed class TaskService(
|
||||
|
||||
task.State = TaskStateHelper.ToStateString(TaskState.Backlog);
|
||||
await taskRepo.UpdateAsync(task, ct);
|
||||
await activityRepo.AddAsync(new ActivityEvent { Type = "task", Message = $"Task {task.Title} rejected, returned to backlog" }, ct);
|
||||
await activityRepo.AddAsync(new ActivityEvent { Type = "task", Message = $"Task {task.Title} rejected, returned to backlog", TaskId = task.Id }, ct);
|
||||
await PublishBoardSnapshotAsync(ct);
|
||||
return new TaskOperationResult(TaskOperationOutcome.Success, task);
|
||||
}
|
||||
|
||||
@@ -66,10 +84,11 @@ public sealed class TaskService(
|
||||
var task = await taskRepo.GetByIdAsync(id, ct);
|
||||
if (task is null) return new TaskOperationResult(TaskOperationOutcome.NotFound);
|
||||
|
||||
task.State = canonical;
|
||||
await taskRepo.UpdateAsync(task, ct);
|
||||
await activityRepo.AddAsync(new ActivityEvent { Type = "task", Message = $"Task {task.Title} moved to {task.State}" }, ct);
|
||||
return new TaskOperationResult(TaskOperationOutcome.Success, task);
|
||||
var caller = ResolveCaller();
|
||||
if (!TaskStateHelper.CanChangeState(caller, task))
|
||||
return new TaskOperationResult(TaskOperationOutcome.InvalidState);
|
||||
|
||||
return await UpdateTaskStatusInternalAsync(task, canonical, caller, "task", $"Task {task.Title} moved to {canonical}", ct);
|
||||
}
|
||||
|
||||
public async Task<TaskOperationResult> UpdateAsync(Guid id, UpdateTaskRequest request, CancellationToken ct = default)
|
||||
@@ -77,15 +96,28 @@ public sealed class TaskService(
|
||||
var task = await taskRepo.GetByIdAsync(id, ct);
|
||||
if (task is null) return new TaskOperationResult(TaskOperationOutcome.NotFound);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(request.Title))
|
||||
var changes = new List<string>();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(request.Title) && !string.Equals(task.Title, request.Title.Trim(), StringComparison.Ordinal))
|
||||
{
|
||||
changes.Add($"Titel: \"{task.Title}\" → \"{request.Title.Trim()}\"");
|
||||
task.Title = request.Title.Trim();
|
||||
if (!string.IsNullOrWhiteSpace(request.Priority))
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(request.Priority) && !string.Equals(task.Priority, request.Priority.Trim(), StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
changes.Add($"Priorität: {task.Priority} → {request.Priority.Trim()}");
|
||||
task.Priority = request.Priority.Trim();
|
||||
}
|
||||
if (request.ProjectId.HasValue)
|
||||
{
|
||||
changes.Add("Projekt-ID geändert");
|
||||
task.ProjectId = request.ProjectId.Value == Guid.Empty ? null : request.ProjectId;
|
||||
}
|
||||
|
||||
await taskRepo.UpdateAsync(task, ct);
|
||||
await activityRepo.AddAsync(new ActivityEvent { Type = "task", Message = $"Task {task.Title} updated" }, ct);
|
||||
var changeSummary = changes.Count > 0 ? string.Join("; ", changes) : "keine sichtbaren Änderungen";
|
||||
await activityRepo.AddAsync(new ActivityEvent { Type = "task", Message = $"Task \"{task.Title}\" aktualisiert: {changeSummary}", TaskId = task.Id }, ct);
|
||||
await PublishBoardSnapshotAsync(ct);
|
||||
return new TaskOperationResult(TaskOperationOutcome.Success, task);
|
||||
}
|
||||
|
||||
@@ -97,13 +129,12 @@ public sealed class TaskService(
|
||||
if (!TaskStateHelper.IsDoneOrBacklog(task.State))
|
||||
return new TaskOperationResult(TaskOperationOutcome.InvalidState, task);
|
||||
|
||||
await activityRepo.AddAsync(new ActivityEvent { Type = "task", Message = $"Task {task.Title} deleted" }, ct);
|
||||
await activityRepo.AddAsync(new ActivityEvent { Type = "task", Message = $"Task {task.Title} deleted", TaskId = task.Id }, ct);
|
||||
await taskRepo.DeleteAsync(task, ct);
|
||||
await PublishBoardSnapshotAsync(ct);
|
||||
return new TaskOperationResult(TaskOperationOutcome.Success);
|
||||
}
|
||||
|
||||
// ── Dashboard-facing operations ──
|
||||
|
||||
public async Task<IReadOnlyList<WorkTask>> GetOpenAsync(CancellationToken ct = default)
|
||||
{
|
||||
var all = await taskRepo.GetAllAsync(ct);
|
||||
@@ -112,36 +143,213 @@ public sealed class TaskService(
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public async Task<WorkTask> CreateDashboardTaskAsync(
|
||||
string title, string? detail, string? source, string? priority, string? assignedTo, CancellationToken ct = default)
|
||||
public async Task<IReadOnlyList<WorkTask>> GetWaitingTasksAsync(CancellationToken ct = default)
|
||||
{
|
||||
var all = await taskRepo.GetAllAsync(ct);
|
||||
return all
|
||||
.Where(t => t.IsAgentTask && !string.Equals(t.State, "Done", StringComparison.OrdinalIgnoreCase))
|
||||
.OrderBy(t => t.ExpectedFrom != null ? 0 : 1)
|
||||
.ThenByDescending(t => t.UpdatedAt)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public async Task<AgentWorkflowOverview> GetAgentWorkflowOverviewAsync(TimeSpan staleThreshold, CancellationToken ct = default)
|
||||
{
|
||||
var all = (await taskRepo.GetAllAsync(ct)).ToList();
|
||||
var threshold = DateTimeOffset.UtcNow - staleThreshold;
|
||||
var agentTasks = all.Where(t => t.IsAgentTask).ToList();
|
||||
var activity = await activityRepo.GetRecentForTasksAsync(agentTasks.Select(t => t.Id), ct);
|
||||
|
||||
List<DashboardTaskDto> map(IEnumerable<WorkTask> tasks)
|
||||
=> tasks.Select(task => MapToDtoWithChildren(task, all, activity)).ToList();
|
||||
|
||||
var waitingForBao = map(agentTasks
|
||||
.Where(t => string.Equals(t.ExpectedFrom, "bao", StringComparison.OrdinalIgnoreCase) &&
|
||||
!string.Equals(t.State, "Done", StringComparison.OrdinalIgnoreCase)));
|
||||
|
||||
var waitingForIris = map(agentTasks
|
||||
.Where(t => string.Equals(t.ExpectedFrom, "iris", StringComparison.OrdinalIgnoreCase) &&
|
||||
!string.Equals(t.State, "Done", StringComparison.OrdinalIgnoreCase)));
|
||||
|
||||
var waitingForOthers = map(agentTasks
|
||||
.Where(t =>
|
||||
{
|
||||
var expected = (t.ExpectedFrom ?? "").ToLowerInvariant();
|
||||
return expected != "bao" && expected != "iris" && !string.IsNullOrWhiteSpace(expected) &&
|
||||
!string.Equals(t.State, "Done", StringComparison.OrdinalIgnoreCase);
|
||||
}));
|
||||
|
||||
var staleTasks = map(agentTasks
|
||||
.Where(t => string.Equals(t.State, "In progress", StringComparison.OrdinalIgnoreCase) && t.UpdatedAt < threshold));
|
||||
|
||||
return new AgentWorkflowOverview(waitingForBao, waitingForIris, waitingForOthers, staleTasks, staleThreshold);
|
||||
}
|
||||
|
||||
public async Task<WorkTask> CreateDashboardTaskAsync(
|
||||
string title, string? detail, string? source, string? priority,
|
||||
string? assignedTo, Guid? parentTaskId = null, CancellationToken ct = default)
|
||||
{
|
||||
if (parentTaskId.HasValue)
|
||||
{
|
||||
var parent = await taskRepo.GetByIdAsync(parentTaskId.Value, ct);
|
||||
if (parent is null)
|
||||
throw new ArgumentException($"Parent task {parentTaskId} not found.", nameof(parentTaskId));
|
||||
}
|
||||
|
||||
var normalizedSource = string.IsNullOrWhiteSpace(source) ? "bao" : source.Trim().ToLowerInvariant();
|
||||
var normalizedAssignee = await NormalizeActorAsync(assignedTo, ct);
|
||||
var isVisibleDelegation = parentTaskId.HasValue;
|
||||
|
||||
var task = new WorkTask
|
||||
{
|
||||
Title = title.Trim(),
|
||||
Detail = detail?.Trim(),
|
||||
Source = string.IsNullOrWhiteSpace(source) ? "bao" : source.Trim(),
|
||||
Source = normalizedSource,
|
||||
Priority = string.IsNullOrWhiteSpace(priority) ? "Normal" : priority.Trim(),
|
||||
AssignedTo = assignedTo?.Trim()
|
||||
AssignedTo = normalizedAssignee,
|
||||
ParentTaskId = parentTaskId,
|
||||
IsAgentTask = isVisibleDelegation
|
||||
};
|
||||
await taskRepo.AddAsync(task, ct);
|
||||
await activityRepo.AddAsync(new ActivityEvent { Type = "task", Message = $"Task \"{task.Title}\" created ({task.Source})" }, ct);
|
||||
|
||||
var activityMessages = new List<string> { $"Task \"{task.Title}\" created ({task.Source})" };
|
||||
if (parentTaskId.HasValue)
|
||||
{
|
||||
activityMessages.Add($"Sichtbare Delegation erstellt: Child-Task von {parentTaskId.Value}.");
|
||||
await activityRepo.AddAsync(new ActivityEvent
|
||||
{
|
||||
Type = "delegation",
|
||||
Message = $"Board-first Delegation: Child-Task \"{task.Title}\" für {normalizedAssignee ?? task.Source} sichtbar angelegt.",
|
||||
TaskId = parentTaskId.Value
|
||||
}, ct);
|
||||
}
|
||||
|
||||
await activityRepo.AddAsync(new ActivityEvent { Type = "task", Message = string.Join(" ", activityMessages), TaskId = task.Id }, ct);
|
||||
|
||||
if (string.Equals(normalizedAssignee, "bao", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
await notificationService.CreateAsync(
|
||||
"task_assigned",
|
||||
$"Neue Aufgabe: {task.Title}",
|
||||
detail,
|
||||
"bao",
|
||||
task.Id,
|
||||
ct);
|
||||
}
|
||||
|
||||
await PublishBoardSnapshotAsync(ct);
|
||||
return task;
|
||||
}
|
||||
|
||||
public async Task<WorkTask> CreateAgentTaskAsync(
|
||||
string title, string? detail, string? source, string? priority,
|
||||
string? assignedTo, string? expectedFrom, Guid? parentTaskId = null, bool startsInProgress = true, string? initialState = null, CancellationToken ct = default)
|
||||
{
|
||||
var normalizedExpectedFrom = await NormalizeActorAsync(expectedFrom, ct);
|
||||
var task = await CreateDashboardTaskAsync(title, detail, source, priority, assignedTo, parentTaskId, ct);
|
||||
|
||||
task.IsAgentTask = true;
|
||||
task.ExpectedFrom = normalizedExpectedFrom;
|
||||
task.State = ResolveInitialAgentTaskState(startsInProgress, initialState);
|
||||
await taskRepo.UpdateAsync(task, ct);
|
||||
|
||||
await activityRepo.AddAsync(new ActivityEvent
|
||||
{
|
||||
Type = "agent_task",
|
||||
Message = $"Agent-Task created: \"{task.Title}\" (Source: {task.Source}, Expected: {task.ExpectedFrom ?? "none"})",
|
||||
TaskId = task.Id
|
||||
}, ct);
|
||||
|
||||
if (parentTaskId.HasValue)
|
||||
{
|
||||
await activityRepo.AddAsync(new ActivityEvent
|
||||
{
|
||||
Type = "delegation",
|
||||
Message = $"Parent-/Child-Delegation sichtbar: Parent {parentTaskId.Value}, Child {task.Id}, wartet auf {task.ExpectedFrom ?? task.AssignedTo ?? "unbekannt"}.",
|
||||
TaskId = parentTaskId.Value
|
||||
}, ct);
|
||||
}
|
||||
|
||||
await notificationService.CreateAsync(
|
||||
"agent_task_created",
|
||||
$"Neuer Agent-Task: {task.Title}",
|
||||
detail,
|
||||
"iris",
|
||||
task.Id,
|
||||
ct);
|
||||
|
||||
await PublishBoardSnapshotAsync(ct);
|
||||
return task;
|
||||
}
|
||||
|
||||
public async Task<TaskOperationResult> UpdateDashboardTaskAsync(
|
||||
Guid id, string? title, string? detail, string? source, string? priority, string? assignedTo, CancellationToken ct = default)
|
||||
Guid id, string? title, string? detail, string? source,
|
||||
string? priority, string? assignedTo, DateTimeOffset? dueDate = null, CancellationToken ct = default)
|
||||
{
|
||||
var caller = ResolveCaller();
|
||||
var task = await taskRepo.GetByIdAsync(id, ct);
|
||||
if (task is null) return new TaskOperationResult(TaskOperationOutcome.NotFound);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(title)) task.Title = title.Trim();
|
||||
if (detail is not null) task.Detail = string.IsNullOrWhiteSpace(detail) ? null : detail.Trim();
|
||||
if (!string.IsNullOrWhiteSpace(source)) task.Source = source.Trim();
|
||||
if (!string.IsNullOrWhiteSpace(priority)) task.Priority = priority.Trim();
|
||||
if (assignedTo is not null) task.AssignedTo = string.IsNullOrWhiteSpace(assignedTo) ? null : assignedTo.Trim();
|
||||
var changes = new List<string>();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(title) && !string.Equals(task.Title, title.Trim(), StringComparison.Ordinal))
|
||||
{
|
||||
changes.Add($"Titel: \"{task.Title}\" → \"{title.Trim()}\"");
|
||||
task.Title = title.Trim();
|
||||
}
|
||||
if (detail is not null)
|
||||
{
|
||||
var newDetail = string.IsNullOrWhiteSpace(detail) ? null : detail.Trim();
|
||||
if (!string.Equals(task.Detail ?? "", newDetail ?? "", StringComparison.Ordinal))
|
||||
{
|
||||
changes.Add("Beschreibung aktualisiert");
|
||||
task.Detail = newDetail;
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(source))
|
||||
task.Source = source.Trim();
|
||||
if (!string.IsNullOrWhiteSpace(priority) && !string.Equals(task.Priority, priority.Trim(), StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
changes.Add($"Priorität: {task.Priority} → {priority.Trim()}");
|
||||
task.Priority = priority.Trim();
|
||||
}
|
||||
if (assignedTo is not null)
|
||||
{
|
||||
var validated = await NormalizeActorAsync(assignedTo, ct);
|
||||
if (!string.Equals(task.AssignedTo ?? "", validated ?? "", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
changes.Add($"Zuständig: {task.AssignedTo ?? "niemand"} → {validated ?? "niemand"}");
|
||||
task.AssignedTo = validated;
|
||||
}
|
||||
}
|
||||
if (dueDate.HasValue && task.DueDate?.Date != dueDate.Value.Date)
|
||||
{
|
||||
changes.Add($"Fällig: {task.DueDate?.ToString("yyyy-MM-dd") ?? "kein Datum"} → {dueDate.Value:yyyy-MM-dd}");
|
||||
task.DueDate = dueDate;
|
||||
}
|
||||
|
||||
await taskRepo.UpdateAsync(task, ct);
|
||||
await activityRepo.AddAsync(new ActivityEvent { Type = "task", Message = $"Task \"{task.Title}\" updated" }, ct);
|
||||
|
||||
var changeSummary = changes.Count > 0 ? string.Join("; ", changes) : "keine sichtbaren Änderungen";
|
||||
await activityRepo.AddAsync(new ActivityEvent
|
||||
{
|
||||
Type = "task",
|
||||
Message = $"Task \"{task.Title}\" aktualisiert von {caller}: {changeSummary}",
|
||||
TaskId = task.Id
|
||||
}, ct);
|
||||
|
||||
if (changes.Count > 0 && caller == "bao")
|
||||
{
|
||||
await notificationService.CreateAsync(
|
||||
"task_content_changed",
|
||||
$"Bao hat \"{task.Title}\" geändert",
|
||||
changeSummary,
|
||||
"iris",
|
||||
task.Id,
|
||||
ct);
|
||||
}
|
||||
|
||||
await PublishBoardSnapshotAsync(ct);
|
||||
return new TaskOperationResult(TaskOperationOutcome.Success, task);
|
||||
}
|
||||
|
||||
@@ -153,11 +361,29 @@ public sealed class TaskService(
|
||||
var task = await taskRepo.GetByIdAsync(id, ct);
|
||||
if (task is null) return new TaskOperationResult(TaskOperationOutcome.NotFound);
|
||||
|
||||
var caller = ResolveCaller();
|
||||
if (!TaskStateHelper.CanChangeState(caller, task))
|
||||
return new TaskOperationResult(TaskOperationOutcome.InvalidState);
|
||||
|
||||
var canonical = TaskStateHelper.AllStates.First(s => s.Equals(status, StringComparison.OrdinalIgnoreCase));
|
||||
task.State = canonical;
|
||||
await taskRepo.UpdateAsync(task, ct);
|
||||
await activityRepo.AddAsync(new ActivityEvent { Type = "task", Message = $"Task \"{task.Title}\" → {canonical}" }, ct);
|
||||
return new TaskOperationResult(TaskOperationOutcome.Success, task);
|
||||
return await UpdateTaskStatusInternalAsync(task, canonical, caller, "task", null, ct);
|
||||
}
|
||||
|
||||
public async Task<TaskOperationResult> StartCoordinationAsync(Guid id, CancellationToken ct = default)
|
||||
{
|
||||
var task = await taskRepo.GetByIdAsync(id, ct);
|
||||
if (task is null) return new TaskOperationResult(TaskOperationOutcome.NotFound);
|
||||
|
||||
if (!string.Equals(task.State, "Backlog", StringComparison.OrdinalIgnoreCase))
|
||||
return new TaskOperationResult(TaskOperationOutcome.Success, task);
|
||||
|
||||
return await UpdateTaskStatusInternalAsync(
|
||||
task,
|
||||
canonical: TaskStateHelper.ToStateString(TaskState.InProgress),
|
||||
actor: "nexus-system",
|
||||
activityType: "delegation",
|
||||
activityMessage: $"Task \"{task.Title}\" → In progress (coordination started by child-task creation)",
|
||||
ct: ct);
|
||||
}
|
||||
|
||||
public async Task<TaskOperationResult> CompleteViaQueueAsync(Guid id, CancellationToken ct = default)
|
||||
@@ -167,7 +393,8 @@ public sealed class TaskService(
|
||||
|
||||
task.State = "Done";
|
||||
await taskRepo.UpdateAsync(task, ct);
|
||||
await activityRepo.AddAsync(new ActivityEvent { Type = "task", Message = $"Task \"{task.Title}\" completed via queue" }, ct);
|
||||
await activityRepo.AddAsync(new ActivityEvent { Type = "task", Message = $"Task \"{task.Title}\" completed via queue", TaskId = task.Id }, ct);
|
||||
await PublishBoardSnapshotAsync(ct);
|
||||
return new TaskOperationResult(TaskOperationOutcome.Success, task);
|
||||
}
|
||||
|
||||
@@ -185,7 +412,271 @@ public sealed class TaskService(
|
||||
};
|
||||
|
||||
await taskRepo.UpdateAsync(task, ct);
|
||||
await activityRepo.AddAsync(new ActivityEvent { Type = "task", Message = $"Task \"{task.Title}\" priority → {task.Priority}" }, ct);
|
||||
await activityRepo.AddAsync(new ActivityEvent { Type = "task", Message = $"Task \"{task.Title}\" priority → {task.Priority}", TaskId = task.Id }, ct);
|
||||
await PublishBoardSnapshotAsync(ct);
|
||||
return new TaskOperationResult(TaskOperationOutcome.Success, task);
|
||||
}
|
||||
|
||||
public async Task<BoardResponse> GetBoardAsync(CancellationToken ct = default)
|
||||
{
|
||||
var all = (await taskRepo.GetAllAsync(ct)).ToList();
|
||||
var activity = await activityRepo.GetRecentForTasksAsync(all.Select(t => t.Id), ct);
|
||||
|
||||
var offen = new List<DashboardTaskDto>();
|
||||
var inProgress = new List<DashboardTaskDto>();
|
||||
var review = new List<DashboardTaskDto>();
|
||||
var blocked = new List<DashboardTaskDto>();
|
||||
var done = new List<DashboardTaskDto>();
|
||||
|
||||
foreach (var task in all)
|
||||
{
|
||||
var dto = MapToDtoWithChildren(task, all, activity);
|
||||
switch (task.State.ToLowerInvariant())
|
||||
{
|
||||
case "backlog": offen.Add(dto); break;
|
||||
case "in progress": inProgress.Add(dto); break;
|
||||
case "review": review.Add(dto); break;
|
||||
case "blocked": blocked.Add(dto); break;
|
||||
case "done": done.Add(dto); break;
|
||||
default: offen.Add(dto); break;
|
||||
}
|
||||
}
|
||||
|
||||
offen.Sort(SortByPriorityThenCreatedAt);
|
||||
inProgress.Sort(SortByPriorityThenCreatedAt);
|
||||
review.Sort(SortByPriorityThenCreatedAt);
|
||||
blocked.Sort(SortByPriorityThenCreatedAt);
|
||||
done.Sort(SortByPriorityThenCreatedAt);
|
||||
|
||||
return new BoardResponse(offen, inProgress, review, blocked, done);
|
||||
}
|
||||
|
||||
private async Task PublishBoardSnapshotAsync(CancellationToken ct = default)
|
||||
{
|
||||
var board = await GetBoardAsync(ct);
|
||||
liveUpdateService.Publish("tasks.board.snapshot", board, "board");
|
||||
}
|
||||
|
||||
private static int SortByPriorityThenCreatedAt(DashboardTaskDto a, DashboardTaskDto b)
|
||||
{
|
||||
var priorityCompare = PriorityScore(b.Priority).CompareTo(PriorityScore(a.Priority));
|
||||
return priorityCompare != 0 ? priorityCompare : a.CreatedAt.CompareTo(b.CreatedAt);
|
||||
}
|
||||
|
||||
private static int PriorityScore(string priority) => priority.ToLowerInvariant() switch
|
||||
{
|
||||
"high" => 3,
|
||||
"medium" => 2,
|
||||
"normal" => 2,
|
||||
"low" => 1,
|
||||
_ => 2
|
||||
};
|
||||
|
||||
public async Task<TaskOperationResult> MoveTaskAsync(Guid id, string newState, CancellationToken ct = default)
|
||||
{
|
||||
var canonical = TaskStateHelper.AllStates.FirstOrDefault(s => s.Equals(newState, StringComparison.OrdinalIgnoreCase))
|
||||
?? TaskStateHelper.BoardGroupToState(newState);
|
||||
if (canonical is null)
|
||||
return new TaskOperationResult(TaskOperationOutcome.InvalidState);
|
||||
|
||||
var task = await taskRepo.GetByIdAsync(id, ct);
|
||||
if (task is null) return new TaskOperationResult(TaskOperationOutcome.NotFound);
|
||||
|
||||
var caller = ResolveCaller();
|
||||
if (!TaskStateHelper.CanChangeState(caller, task))
|
||||
return new TaskOperationResult(TaskOperationOutcome.InvalidState);
|
||||
|
||||
return await UpdateTaskStatusInternalAsync(task, canonical, caller, "task", $"Task \"{task.Title}\" moved to {canonical}", ct);
|
||||
}
|
||||
|
||||
public Task<int> ResetStaleAsync(int staleHours, CancellationToken ct = default)
|
||||
{
|
||||
var normalizedHours = Math.Max(1, staleHours);
|
||||
return ResetStaleInProgressTasksAsync(TimeSpan.FromHours(normalizedHours), ct);
|
||||
}
|
||||
|
||||
public async Task<int> ResetStaleInProgressTasksAsync(TimeSpan staleThreshold, CancellationToken ct = default)
|
||||
{
|
||||
var all = await taskRepo.GetAllAsync(ct);
|
||||
var threshold = DateTimeOffset.UtcNow - staleThreshold;
|
||||
var staleTasks = all.Where(t => string.Equals(t.State, "In progress", StringComparison.OrdinalIgnoreCase) && t.UpdatedAt < threshold).ToList();
|
||||
|
||||
foreach (var task in staleTasks)
|
||||
{
|
||||
var prevState = task.State;
|
||||
task.State = "Backlog";
|
||||
await taskRepo.UpdateAsync(task, ct);
|
||||
await activityRepo.AddAsync(new ActivityEvent
|
||||
{
|
||||
Type = "task",
|
||||
Message = $"Task \"{task.Title}\" reset from {prevState} to Backlog (stale)",
|
||||
TaskId = task.Id
|
||||
}, ct);
|
||||
}
|
||||
|
||||
if (staleTasks.Count > 0)
|
||||
await PublishBoardSnapshotAsync(ct);
|
||||
|
||||
return staleTasks.Count;
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyList<WorkTask>> GetChildTasksAsync(Guid parentId, CancellationToken ct = default)
|
||||
{
|
||||
var all = await taskRepo.GetAllAsync(ct);
|
||||
return all.Where(t => t.ParentTaskId == parentId)
|
||||
.OrderByDescending(t => t.CreatedAt)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public async Task<List<ActivityEvent>> GetTaskActivityAsync(Guid taskId, CancellationToken ct = default)
|
||||
{
|
||||
var all = await activityRepo.GetRecentAsync(100, ct);
|
||||
return all.Where(e => e.TaskId == taskId).ToList();
|
||||
}
|
||||
|
||||
private DashboardTaskDto MapToDtoWithChildren(WorkTask task, IReadOnlyList<WorkTask> allTasks, IEnumerable<ActivityEvent> activity)
|
||||
{
|
||||
var childTasks = allTasks.Where(t => t.ParentTaskId == task.Id)
|
||||
.OrderByDescending(t => t.UpdatedAt)
|
||||
.ToList();
|
||||
|
||||
var childDtos = childTasks.Select(child => MapToDtoWithActivity(child, activity, allTasks)).ToList();
|
||||
var openChildTaskCount = childTasks.Count(child => !string.Equals(child.State, "Done", StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
var dto = MapToDtoWithActivity(task, activity, allTasks);
|
||||
return dto with
|
||||
{
|
||||
ChildTasks = childDtos,
|
||||
ChildTaskCount = childDtos.Count,
|
||||
OpenChildTaskCount = openChildTaskCount,
|
||||
HasVisibleDelegation = dto.ParentTaskId.HasValue || childDtos.Count > 0 || dto.IsAgentTask
|
||||
};
|
||||
}
|
||||
|
||||
private static DashboardTaskDto MapToDto(WorkTask t) => new(
|
||||
t.Id, t.Title, t.Detail, t.Source, t.State, t.Priority, t.AssignedTo,
|
||||
t.ParentTaskId, t.DueDate, t.CreatedAt, t.UpdatedAt,
|
||||
t.IsAgentTask, t.ExpectedFrom);
|
||||
|
||||
private static DashboardTaskDto MapToDtoWithActivity(WorkTask t, IEnumerable<ActivityEvent> activity, IReadOnlyList<WorkTask>? _allTasks = null)
|
||||
{
|
||||
var last = activity
|
||||
.Where(e => e.TaskId == t.Id)
|
||||
.OrderByDescending(e => e.CreatedAt)
|
||||
.FirstOrDefault();
|
||||
|
||||
return new DashboardTaskDto(
|
||||
t.Id, t.Title, t.Detail, t.Source, t.State, t.Priority, t.AssignedTo,
|
||||
t.ParentTaskId, t.DueDate, t.CreatedAt, t.UpdatedAt,
|
||||
t.IsAgentTask, t.ExpectedFrom,
|
||||
last?.Message,
|
||||
last?.CreatedAt,
|
||||
null,
|
||||
0,
|
||||
0,
|
||||
t.ParentTaskId.HasValue || t.IsAgentTask);
|
||||
}
|
||||
|
||||
private async Task<string?> NormalizeActorAsync(string? actorId, CancellationToken ct)
|
||||
{
|
||||
var allowedActors = AgentIdentityCatalog.BuildAllowedActorIds(await agentService.GetAllowedAgentIdsAsync(ct));
|
||||
return AgentIdentityCatalog.NormalizeActorId(actorId, allowedActors);
|
||||
}
|
||||
|
||||
private static string ResolveInitialAgentTaskState(bool startsInProgress, string? initialState)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(initialState))
|
||||
{
|
||||
var canonical = TaskStateHelper.AllStates.FirstOrDefault(state =>
|
||||
state.Equals(initialState, StringComparison.OrdinalIgnoreCase));
|
||||
if (canonical is not null)
|
||||
return canonical;
|
||||
}
|
||||
|
||||
return startsInProgress
|
||||
? TaskStateHelper.ToStateString(TaskState.InProgress)
|
||||
: TaskStateHelper.ToStateString(TaskState.Backlog);
|
||||
}
|
||||
|
||||
private string ResolveCaller()
|
||||
{
|
||||
var httpContext = httpContextAccessor.HttpContext;
|
||||
if (httpContext is null) return "nexus-system";
|
||||
|
||||
var agentHeader = httpContext.Request.Headers["X-Agent-Id"].FirstOrDefault();
|
||||
if (!string.IsNullOrWhiteSpace(agentHeader))
|
||||
return agentHeader.Trim().ToLowerInvariant();
|
||||
|
||||
var user = httpContext.User;
|
||||
var nameClaim = user?.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier)?.Value;
|
||||
return nameClaim?.ToLowerInvariant() ?? "";
|
||||
}
|
||||
|
||||
private async Task<TaskOperationResult> UpdateTaskStatusInternalAsync(
|
||||
WorkTask task,
|
||||
string canonical,
|
||||
string actor,
|
||||
string activityType,
|
||||
string? activityMessage,
|
||||
CancellationToken ct)
|
||||
{
|
||||
task.State = canonical;
|
||||
await taskRepo.UpdateAsync(task, ct);
|
||||
await activityRepo.AddAsync(new ActivityEvent
|
||||
{
|
||||
Type = activityType,
|
||||
Message = activityMessage ?? $"Task \"{task.Title}\" → {canonical}",
|
||||
TaskId = task.Id
|
||||
}, ct);
|
||||
await CreateStatusChangeNotificationsAsync(task, canonical, actor, ct);
|
||||
await PublishBoardSnapshotAsync(ct);
|
||||
return new TaskOperationResult(TaskOperationOutcome.Success, task);
|
||||
}
|
||||
|
||||
private async Task CreateStatusChangeNotificationsAsync(WorkTask task, string canonical, string caller, CancellationToken ct)
|
||||
{
|
||||
if (string.Equals(canonical, "Review", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
await notificationService.CreateAsync(
|
||||
"task_review",
|
||||
$"Task zur Überprüfung: {task.Title}",
|
||||
$"Status auf Review geändert von {caller}",
|
||||
"bao",
|
||||
task.Id,
|
||||
ct);
|
||||
}
|
||||
else if (string.Equals(canonical, "Blocked", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
await notificationService.CreateAsync(
|
||||
"task_blocked",
|
||||
$"Aufgabe blockiert: {task.Title}",
|
||||
$"Die Task wurde von {caller} auf Blockiert gesetzt.",
|
||||
"iris",
|
||||
task.Id,
|
||||
ct);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (caller == "bao")
|
||||
{
|
||||
await notificationService.CreateAsync(
|
||||
"task_status_changed",
|
||||
$"Bao hat Status geändert: {task.Title}",
|
||||
$"Status → {canonical}",
|
||||
"iris",
|
||||
task.Id,
|
||||
ct);
|
||||
}
|
||||
else if (caller == "iris")
|
||||
{
|
||||
await notificationService.CreateAsync(
|
||||
"task_status_changed",
|
||||
$"Iris hat Status geändert: {task.Title}",
|
||||
$"Status → {canonical}",
|
||||
"bao",
|
||||
task.Id,
|
||||
ct);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+45
-31
@@ -1,10 +1,16 @@
|
||||
name: nexus
|
||||
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:17-alpine
|
||||
restart: unless-stopped
|
||||
restart: always
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 384M
|
||||
reservations:
|
||||
memory: 96M
|
||||
environment:
|
||||
POSTGRES_INITDB_ARGS: --data-checksums
|
||||
POSTGRES_DB: ${POSTGRES_DB:-nexus}
|
||||
POSTGRES_USER: ${POSTGRES_USER:-nexus}
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD in .env}
|
||||
@@ -22,17 +28,16 @@ services:
|
||||
options:
|
||||
max-size: "10m"
|
||||
max-file: "3"
|
||||
|
||||
api:
|
||||
build:
|
||||
context: ./backend
|
||||
restart: unless-stopped
|
||||
restart: always
|
||||
deploy:
|
||||
restart_policy:
|
||||
condition: on-failure
|
||||
delay: 5s
|
||||
max_attempts: 3
|
||||
window: 120s
|
||||
resources:
|
||||
limits:
|
||||
memory: 512M
|
||||
reservations:
|
||||
memory: 128M
|
||||
environment:
|
||||
ASPNETCORE_ENVIRONMENT: Production
|
||||
ASPNETCORE_URLS: http://+:8080
|
||||
@@ -40,18 +45,19 @@ services:
|
||||
Jwt__Key: ${JWT_KEY:?Set JWT_KEY in .env}
|
||||
Jwt__Issuer: ${JWT_ISSUER:-nexus}
|
||||
Jwt__Audience: ${JWT_AUDIENCE:-nexus-web}
|
||||
Owner__Email: ${OWNER_EMAIL:?Set OWNER_EMAIL in .env}
|
||||
Owner__Password: ${OWNER_PASSWORD:-}
|
||||
Owner__DisplayName: ${OWNER_DISPLAY_NAME:-Owner}
|
||||
Bootstrap__OwnerEmail: ${BOOTSTRAP_OWNER_EMAIL:?Set BOOTSTRAP_OWNER_EMAIL in .env}
|
||||
# Initial owner password is generated once at first seed and then lives only in the DB.
|
||||
Integrations__OpenClaw__BaseUrl: ${OPENCLAW_BASE_URL:-http://host.docker.internal:18789}
|
||||
Integrations__OpenClaw__Token: ${OPENCLAW_GATEWAY_TOKEN:-}
|
||||
Integrations__OpenClaw__Password: ${OPENCLAW_GATEWAY_PASSWORD:-}
|
||||
Admin__ResetToken: ${Admin__ResetToken:-}
|
||||
NexusApiKey: ${NEXUS_API_KEY:-}
|
||||
extra_hosts:
|
||||
- host.docker.internal:host-gateway
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
condition: service_started
|
||||
restart: true
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "wget --no-verbose --tries=1 --spider http://localhost:8080/health/live || exit 1"]
|
||||
interval: 30s
|
||||
@@ -59,13 +65,13 @@ services:
|
||||
retries: 3
|
||||
start_period: 15s
|
||||
volumes:
|
||||
- /opt/openclaw/data/openclaw/openclaw.json:/home/node/.openclaw/openclaw.json:ro
|
||||
- /opt/openclaw/data/openclaw/workspace-iris:/mnt/workspace-iris
|
||||
- /opt/openclaw/data/openclaw/workspace-programmer:/mnt/workspace-programmer
|
||||
- /opt/openclaw/data/openclaw/workspace-reviewer:/mnt/workspace-reviewer
|
||||
- /opt/openclaw/data/openclaw/workspace-architekt:/mnt/workspace-architekt
|
||||
- /opt/openclaw/data/openclaw/workspace-researcher:/mnt/workspace-researcher
|
||||
- /opt/openclaw/data/openclaw/workspace-executor:/mnt/workspace-executor
|
||||
- /home/projekte_bao/openclaw/data/openclaw/openclaw.json:/home/node/.openclaw/openclaw.json:ro
|
||||
- /home/projekte_bao/openclaw/data/openclaw/workspace-iris:/mnt/workspace-iris
|
||||
- /home/projekte_bao/openclaw/data/openclaw/workspace-programmer:/mnt/workspace-programmer
|
||||
- /home/projekte_bao/openclaw/data/openclaw/workspace-reviewer:/mnt/workspace-reviewer
|
||||
- /home/projekte_bao/openclaw/data/openclaw/workspace-architekt:/mnt/workspace-architekt
|
||||
- /home/projekte_bao/openclaw/data/openclaw/workspace-researcher:/mnt/workspace-researcher
|
||||
- /home/projekte_bao/openclaw/data/openclaw/workspace-executor:/mnt/workspace-executor
|
||||
networks:
|
||||
- nexus
|
||||
- openclaw_default
|
||||
@@ -74,39 +80,47 @@ services:
|
||||
options:
|
||||
max-size: "10m"
|
||||
max-file: "3"
|
||||
|
||||
web:
|
||||
build:
|
||||
context: ./frontend
|
||||
restart: unless-stopped
|
||||
restart: always
|
||||
deploy:
|
||||
restart_policy:
|
||||
condition: on-failure
|
||||
delay: 5s
|
||||
max_attempts: 3
|
||||
window: 120s
|
||||
resources:
|
||||
limits:
|
||||
memory: 128M
|
||||
reservations:
|
||||
memory: 32M
|
||||
labels:
|
||||
- "traefik.enable=true"
|
||||
- "traefik.http.routers.nexus.rule=Host(`nexus.noveria.net`)"
|
||||
- "traefik.http.routers.nexus.tls=true"
|
||||
- "traefik.http.routers.nexus.tls.certresolver=letsencrypt"
|
||||
- "traefik.http.services.nexus.loadbalancer.server.port=80"
|
||||
ports:
|
||||
- "127.0.0.1:18880:80"
|
||||
depends_on:
|
||||
api:
|
||||
condition: service_healthy
|
||||
condition: service_started
|
||||
restart: true
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "curl -f http://localhost:80/ || exit 1"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
start_period: 10s
|
||||
networks: [nexus]
|
||||
networks:
|
||||
- nexus
|
||||
- proxy
|
||||
logging:
|
||||
driver: "json-file"
|
||||
options:
|
||||
max-size: "10m"
|
||||
max-file: "3"
|
||||
|
||||
networks:
|
||||
nexus:
|
||||
openclaw_default:
|
||||
external: true
|
||||
|
||||
proxy:
|
||||
external: true
|
||||
volumes:
|
||||
nexus-postgres:
|
||||
|
||||
@@ -0,0 +1,503 @@
|
||||
# Nexus Board-First Orchestration & Sichere OpenClaw-Integration
|
||||
|
||||
> Gegenprüfung: Architekt, 2026-06-22
|
||||
> Gegenstand: Sicherster Pfad für Board-first-Agent-Orchestrierung und MCP-artige/strukturierte
|
||||
> OpenClaw-Integration im Nexus-Backend
|
||||
> Kein Frontend-direkter MCP-Pfad. Kein Deploy.
|
||||
|
||||
## 1. Executive Summary
|
||||
|
||||
### 1.1 Prüfergebnis
|
||||
|
||||
Der eingeschlagene Pfad ist **architektonisch korrekt und sicher**. Das Board-first-Modell mit
|
||||
Nexus-Backend als zentraler Brücke zwischen Benutzer, Board und OpenClaw-Gateway ist der richtige
|
||||
Ansatz. Das Backend fungiert bereits als sichere Schicht zwischen allen Akteuren.
|
||||
|
||||
### 1.2 Kernbewertung
|
||||
|
||||
| Aspekt | Status | Bewertung |
|
||||
|--------|--------|-----------|
|
||||
| Board-first Architektur | ✅ Umsetzung läuft | Parent/Child-Modell korrekt implementiert |
|
||||
| Kein Frontend-direkter Gateway-Zugriff | ✅ Eingehalten | Frontend spricht NUR mit Nexus-Backend |
|
||||
| Backend als sichere Brücke | ✅ Eingehalten | API-Container proxyt alle Gateway-Calls |
|
||||
| Auth-/Rechte-Modell | ✅ Solide | JWT + ApiKey + X-Agent-Id Enforcement |
|
||||
| Gateway-Security | ⚠️ Verbesserbar | `loopback`-Bind muss auf `lan` für Docker |
|
||||
| Migration-Reihenfolge | 📋 Vorgeschlagen | (siehe Abschnitt 8) |
|
||||
|
||||
## 2. Ist-Architektur: Wer spricht mit wem?
|
||||
|
||||
```
|
||||
┌──────────────────────────────────────────────────────────────────┐
|
||||
│ Browser (Bao/Iris) │
|
||||
│ auth.ts → JWT Access Token (15m) + HttpOnly Refresh Cookie │
|
||||
│ api.ts → fetch /api/v1/* → Authorization: Bearer <JWT> │
|
||||
└───────────────────────────┬──────────────────────────────────────┘
|
||||
│ HTTPS :443 (Traefik/npm)
|
||||
▼
|
||||
┌──────────────────────────────────────────────────────────────────┐
|
||||
│ Nexus web (nginx container) │
|
||||
│ location /api/ → proxy_pass http://api:8080 │
|
||||
│ location / → SPA (index.html) │
|
||||
│ CSP: connect-src 'self' — kein externer Gateway-Call möglich │
|
||||
└───────────────────────────┬──────────────────────────────────────┘
|
||||
│ HTTP :8080 (internal network)
|
||||
▼
|
||||
┌──────────────────────────────────────────────────────────────────┐
|
||||
│ Nexus API (.NET 10 Container) ← SICHERE BRÜCKE │
|
||||
│ │
|
||||
│ Auth-Middleware (JWT → Controller) │
|
||||
│ ApiKey-Middleware (X-Nexus-Api-Key → Role=Service) │
|
||||
│ SecurityHeaders-Middleware (HSTS, CSP, XFO) │
|
||||
│ Rate Limiter (auth: 5/min/caller, agents: 30/min/caller) │
|
||||
│ │
|
||||
│ IOpenClawGatewayClient │
|
||||
│ ├─ InvokeToolAsync("session_status", ...) │
|
||||
│ ├─ InvokeToolAsync("sessions_list", ...) │
|
||||
│ ├─ InvokeToolAsync("sessions_history", ...) │
|
||||
│ ├─ InvokeToolAsync("memory_search", ...) │
|
||||
│ ├─ InvokeToolAsync("sessions_send", ...) │
|
||||
│ └─ InvokeToolAsync("cron", ...) │
|
||||
│ │
|
||||
│ GatewayBridgeController (/api/bridge/*) <- NEU (2026-06-22) │
|
||||
│ └─ ITaskBridgeService │
|
||||
│ create_task / create_child_task / update_status / │
|
||||
│ append_activity / handoff / get_board / get_agent_overview │
|
||||
│ │
|
||||
│ IAgentRuntime (OpenClawRuntime) │
|
||||
│ └─ POST /v1/chat/completions (OpenAI-compat) │
|
||||
│ │
|
||||
│ ALLE Gateway-Calls → Authorization: Bearer <Gateway-Password> │
|
||||
└──────────────┬──────────────────────────────┬────────────────────┘
|
||||
│ host.docker.internal:18789 │
|
||||
│ (Gateway loopback/lan) │
|
||||
▼ │
|
||||
┌──────────────────────────────┐ │
|
||||
│ OpenClaw Gateway Container │ │
|
||||
│ Port 18789 │ │
|
||||
│ Auth: password │ │
|
||||
│ Bind: loopback (127.0.0.1) │ │
|
||||
│ │ │
|
||||
│ HTTP Deny-List (default): │ │
|
||||
│ exec, spawn, shell, │ │
|
||||
│ fs_write, fs_delete, │ │
|
||||
│ fs_move, apply_patch, │ │
|
||||
│ sessions_spawn, sessions_send│ │
|
||||
│ cron, gateway, nodes, │ │
|
||||
│ whatsapp_login │ │
|
||||
└───────────────────────────────┴──────────────┘
|
||||
```
|
||||
|
||||
### 2.1 Wichtig: Das Frontend sieht den Gateway NICHT
|
||||
|
||||
```
|
||||
Browser ─── [Nexus API] ─── Gateway
|
||||
│
|
||||
+─ Gateway-Passwort lebt NUR im Backend
|
||||
+─ CSP: connect-src 'self' blockiert jeden Direktzugriff
|
||||
+─ Gateway HTTP Deny-List blockiert alle RCE-Tools
|
||||
```
|
||||
|
||||
**Das ist die korrekte Architektur.** Kein Frontend-komponenten-direkter MCP-Pfad existiert
|
||||
und keiner sollte eingeführt werden.
|
||||
|
||||
## 3. Board-First Orchestrierung: Ist-Stand & Bewertung
|
||||
|
||||
### 3.1 Das Parent/Child-Task-Modell (Phase 3)
|
||||
|
||||
```
|
||||
Parent-Task (Owner: Iris)
|
||||
├── Child-Task A (AssignedTo: programmer)
|
||||
├── Child-Task B (AssignedTo: reviewer)
|
||||
└── Child-Task C (AssignedTo: architekt)
|
||||
```
|
||||
|
||||
**Status:** ✅ Implementiert (2026-06-21)
|
||||
|
||||
**Datenmodell (WorkTask):**
|
||||
- `ParentTaskId` (Guid?) — verknüpft Child mit Parent
|
||||
- `IsAgentTask` (bool) — markiert programmatisch erstellte Agent-Tasks
|
||||
- `ExpectedFrom` (string?) — wer als nächstes antworten soll
|
||||
- `AssignedTo` (string?) — operativer Owner der Task
|
||||
|
||||
**State Machine:**
|
||||
```
|
||||
Parent: Backlog → InProgress → Review → Done
|
||||
↘ Blocked → Backlog
|
||||
|
||||
Child: Backlog → InProgress → Done
|
||||
↘ Blocked → Backlog
|
||||
```
|
||||
|
||||
**Rules (aus TaskStateHelper.CanChangeState):**
|
||||
- **Nur Iris & Bao** dürfen State-Änderungen vornehmen
|
||||
- Sub-Agenten (programmer, reviewer, architekt, researcher, executor) **niemals**
|
||||
- `nexus-system` als technischer Fallback für Cron/Reset-Stale
|
||||
|
||||
### 3.2 Bewertung: Architektonisch korrekt
|
||||
|
||||
| Kriterium | Bewertung | Begründung |
|
||||
|-----------|-----------|------------|
|
||||
| Board als Single Source of Truth | ✅ | Task Board = sichtbare Aufgabenwahrheit |
|
||||
| Delegation sichtbar | ✅ | Child-Tasks statt unsichtbarem Delegations-Status |
|
||||
| Feingliedrige Berechtigung | ✅ | State-Change nur durch Iris/Bao |
|
||||
| Agenten arbeiten gegen Child-Tasks | ✅ | Klare Ownership durch `AssignedTo` |
|
||||
| Parent bleibt bei Iris | ✅ | Parent in `InProgress` während Koordination |
|
||||
| Review-Gate für Bao | ✅ | Parent erst in `Review`, dann Bao-Entscheidung |
|
||||
|
||||
### 3.3 Offene Punkte im Board-Modell
|
||||
|
||||
1. **Keine automatische Child-Task-Erstellung** — Das Board-Modell setzt voraus, dass Iris manuell
|
||||
Child-Tasks anlegt. Ein strukturierter Workflow für automatische Child-Task-Erstellung bei
|
||||
`spawn`/Subagent-Aufrufen fehlt.
|
||||
|
||||
2. **Keine Task→Session-Verknüpfung** — Es gibt keine direkte Verknüpfung zwischen einer
|
||||
Child-Task und der OpenClaw-Subagent-Session, die sie bearbeitet. Der `AgentService` kennt
|
||||
Sessions, `TaskService` kennt Tasks — aber sie sind nicht verknüpft.
|
||||
|
||||
3. **Reset-Stale ist ungeschützt** — `POST /api/v1/tasks/reset-stale` hat `[AllowAnonymous]`
|
||||
und kann von jedem aufgerufen werden (siehe Risiko #1).
|
||||
|
||||
## 4. Auth- und Rechte-Modell
|
||||
|
||||
### 4.1 Authentifizierungsebenen
|
||||
|
||||
```
|
||||
Ebene 1: Browser-JWT (Access Token 15m, Refresh Token HttpOnly Cookie)
|
||||
Ebene 2: X-Nexus-Api-Key (Service-zu-Service, Role=Service)
|
||||
Ebene 3: Gateway-Password (Backend → Gateway, Bearer Authorization)
|
||||
Ebene 4: X-Agent-Id Header (Agent-Identität für Task-State-Enforcement)
|
||||
```
|
||||
|
||||
### 4.2 Berechtigungsmatrix
|
||||
|
||||
| Aktion | Bao | Iris | Sub-Agent | nexus-system | Service (ApiKey) |
|
||||
|--------|-----|------|-----------|--------------|-------------------|
|
||||
| Task State ändern | ✅ | ✅ | ❌ | ✅ (intern) | ❌ |
|
||||
| Task Inhalt editieren | ✅ | ✅ | ✅ | ✅ | ✅ |
|
||||
| Agent-Config lesen | ✅ | ✅ | ❌ | ❌ | ✅ |
|
||||
| Gateway-Tool aufrufen | ❌ | ❌ | ❌ | ❌ | ✅ (intern) |
|
||||
| Dashboard-Metriken sehen | ✅ | ✅ | ❌ | ❌ | ✅ |
|
||||
|
||||
### 4.3 Bewertung
|
||||
|
||||
**Positiv:**
|
||||
- JWT-Sicherheit entspricht Best Practices (PBKDF2-SHA256, 210k Iterationen, Rotating Refresh Tokens)
|
||||
- Refresh-Token-Reuse-Detection verhindert Token-Theft
|
||||
- Rate-Limiting auf Login und Refresh
|
||||
- CSRF-Protection via `X-CSRF-TOKEN` + `nexus-csrf` Cookie
|
||||
- Security Headers (HSTS, CSP, XFO, Referrer-Policy)
|
||||
|
||||
**Kritisch:**
|
||||
- `[AllowAnonymous]` auf `/tasks/board` und `/tasks/reset-stale` — siehe Risiko-Analyse
|
||||
- Kein Scoped-ApiKey — der `X-Nexus-Api-Key` gibt volle Service-Rechte
|
||||
- Keine Audit-Protokollierung für ApiKey-Nutzung
|
||||
|
||||
## 5. Gateway-Integration: Sicherheitsanalyse
|
||||
|
||||
### 5.1 Tool-Invoke-Pfad (Ist-Stand)
|
||||
|
||||
```
|
||||
POST /api/v1/operations/snapshot
|
||||
→ DashboardService → OpenClawGatewayClient.InvokeToolAsync()
|
||||
→ POST http://host.docker.internal:18789/tools/invoke
|
||||
Authorization: Bearer <Gateway-Password>
|
||||
```
|
||||
|
||||
**Aufgerufene Tools (durch Nexus-Backend):**
|
||||
- `session_status` — Agent-Status abfragen (read-only)
|
||||
- `sessions_list` — Session-Liste (read-only)
|
||||
- `sessions_history` — Chat-Verlauf (read-only)
|
||||
- `memory_search` — Memory-Suche (read-only)
|
||||
- `sessions_send` — Chat-Nachricht senden (write, aber kontrolliert)
|
||||
- `cron` — Cron-Jobs verwalten (write)
|
||||
|
||||
**Gateway HTTP Deny-List blockiert:**
|
||||
- Alle Exec-Tools (exec, spawn, shell)
|
||||
- Alle Filesystem-Tools (fs_write, fs_delete, fs_move, apply_patch)
|
||||
- Gateway-Control-Plane (gateway)
|
||||
- Node-Relay (nodes)
|
||||
- Session-Orchestrierung (sessions_spawn, sessions_send)
|
||||
|
||||
### 5.2 Docker-Netzwerk & Gateway-Bind
|
||||
|
||||
**Aktuelles Problem:**
|
||||
```
|
||||
compose.yaml:
|
||||
api:
|
||||
extra_hosts:
|
||||
- host.docker.internal:host-gateway
|
||||
networks:
|
||||
- nexus
|
||||
- openclaw_default ← API-Container ist im Gateway-Netzwerk
|
||||
|
||||
Gateway-Konfiguration:
|
||||
gateway.bind: "loopback" ← Bindet nur 127.0.0.1 IM GATEWAY-CONTAINER
|
||||
```
|
||||
|
||||
**Ergebnis:**
|
||||
- `host.docker.internal:18789` funktioniert, weil `extra_hosts` auf den Docker-Host zeigt
|
||||
- ABER: Docker-Port-Forward (wenn vorhanden) sendet an Container-IP, nicht loopback
|
||||
- Die `openclaw_default` Netzwerk-Mitgliedschaft des API-Containers wird NICHT genutzt
|
||||
|
||||
**Empfehlung (siehe gateway-api-research.md, Abschnitt 6):**
|
||||
```json5
|
||||
// openclaw.json
|
||||
{
|
||||
gateway: {
|
||||
bind: "lan" // war "loopback"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Alternativ: API-Container über Gateway-Container-Namen ansprechen:
|
||||
```yaml
|
||||
Integrations__OpenClaw__BaseUrl: http://openclaw_gateway:18789
|
||||
```
|
||||
(Vorausgesetzt der Gateway-Container heißt `openclaw_gateway` und ist im `openclaw_default` Netzwerk)
|
||||
|
||||
### 5.3 MCP-artige Integration: Bewertung
|
||||
|
||||
**Das Gateway `/tools/invoke` ist bereits MCP-artig:**
|
||||
- JSON-RPC-ähnliche Aufrufe mit `tool` + `args` + `sessionKey`
|
||||
- Strukturierte Responses mit `{ ok, result, error }`
|
||||
- Tool-Discovery via Policy (Deny/Allow-List)
|
||||
- Request/Response mit eindeutiger Fehlersemantik
|
||||
|
||||
**Was fehlt für ein vollständiges MCP-Interface:**
|
||||
- Keine Tool-Listing/Discovery über API (kein `tools/list`)
|
||||
- Keine Schema-Validierung für Tool-Arguments
|
||||
- Keine Structured Outputs (function-calling-ähnliches Format)
|
||||
|
||||
**Empfehlung: NICHT ein MCP-Protokoll zwischen Nexus und Gateway einführen.**
|
||||
Stattdessen den bestehenden `/tools/invoke`-Pfad weiter nutzen und strukturieren.
|
||||
|
||||
### 5.4 Neue Backend-Bridge (Implementiert 2026-06-22)
|
||||
|
||||
Der Nexus-eigene strukturierte Kommando-Adapter wurde eingeführt:
|
||||
|
||||
```
|
||||
Nexus Backend
|
||||
├─ GatewayToolClient (bestehender OpenClawGatewayClient)
|
||||
│ └─ POST /tools/invoke (Gateway)
|
||||
│
|
||||
├─ GatewayBridgeController (NEU — /api/bridge/)
|
||||
│ ├─ POST /api/bridge/tasks (create_task)
|
||||
│ ├─ POST /api/bridge/tasks/{id}/children (create_child_task)
|
||||
│ ├─ PATCH /api/bridge/tasks/{id}/status (update_status)
|
||||
│ ├─ POST /api/bridge/tasks/{id}/activity (append_activity)
|
||||
│ ├─ POST /api/bridge/tasks/{id}/handoff (handoff)
|
||||
│ ├─ GET /api/bridge/board (get_board)
|
||||
│ ├─ GET /api/bridge/tasks/{id} (get_task)
|
||||
│ ├─ GET /api/bridge/tasks/{id}/children (get_children)
|
||||
│ ├─ GET /api/bridge/tasks/{id}/activity (get_activity)
|
||||
│ └─ GET /api/bridge/agent-overview (get_agent_overview)
|
||||
│
|
||||
├─ ITaskBridgeService / TaskBridgeService (NEU)
|
||||
│ └─ Typisierte TaskBridgeResult<T> mit Outcome: Success/NotFound/InvalidState/Unauthorized/ValidationError
|
||||
│
|
||||
├─ BoardOrchestrationService (offen)
|
||||
│ ├─ Tasks erstellen/aktualisieren
|
||||
│ ├─ Session-Status abfragen
|
||||
│ └─ Agent-Progress berechnen
|
||||
│
|
||||
└─ AgentDelegationService (offen)
|
||||
├─ Subagent-Task anlegen
|
||||
├─ Session verfolgen
|
||||
└─ Ergebnis integrieren
|
||||
```
|
||||
|
||||
**Auth-Modell für /api/bridge:**
|
||||
- Primär: `X-Agent-Id` Header (Agent-Identität vom Gateway)
|
||||
- Fallback: JWT (Browser-authenticated user → bao)
|
||||
- Fallback: `X-Nexus-Api-Key` (Backend-zu-Backend Service-Identität)
|
||||
- Rate-Limiting: 30 Requests/Minute (agents-Policy)
|
||||
|
||||
**Das Frontend sieht /api/bridge NICHT.** Der Pfad ist ausschließlich für Agent-zu-Backend-Kommunikation.
|
||||
|
||||
## 6. Risikoanalyse
|
||||
|
||||
### 6.1 KRITISCH — `[AllowAnonymous]` auf Board-Endpunkten ✅ BEHOBEN (2026-06-22)
|
||||
|
||||
**Betroffen (vorher):**
|
||||
```csharp
|
||||
// TasksController.cs
|
||||
[AllowAnonymous]
|
||||
[HttpGet("board")] // Gab ALLE Tasks zurück — inkl. Detail-Texte
|
||||
|
||||
[AllowAnonymous]
|
||||
[HttpPost("reset-stale")] // Konnte Tasks zurücksetzen — datenändernd
|
||||
```
|
||||
|
||||
**Fix angewandt:**
|
||||
- `[AllowAnonymous]` entfernt
|
||||
- Inline-Auth-Check: `X-Agent-Id` Header, ApiKey-Rolle, oder JWT erforderlich
|
||||
- `reset-stale` erfordert zusätzlich `X-Agent-Id: iris` Identität (nur Iris darf)
|
||||
- Neuer `/api/bridge/` Pfad als sauberer Agent-zu-Backend-Adapter
|
||||
- Rate-Limiting (agents-Policy: 30/min) auf Bridge-Endpunkte
|
||||
|
||||
### 6.2 MITTEL — Keine Task→Session-Verknüpfung
|
||||
|
||||
Wenn ein Subagent eine Child-Task bearbeitet, gibt es keine technische Verknüpfung zwischen
|
||||
der Child-Task und der OpenClaw-Session. Das bedeutet:
|
||||
- Keine automatische Status-Aktualisierung bei Session-Abschluss
|
||||
- Keine Sitzungs-Historie direkt von der Task aus erreichbar
|
||||
- Iris muss manuell prüfen, ob ein Agent fertig ist
|
||||
|
||||
**Empfehlung:**
|
||||
- `WorkTask` um `SessionKey` (string?) erweitern
|
||||
- Bei Child-Task-Erstellung Session-Key speichern
|
||||
- Status-Polling: Wenn Session inaktiv, Child-Task auf Done/Blocked prüfen
|
||||
|
||||
### 6.3 MITTEL — Gateway-Passwort in Config-Dateien
|
||||
|
||||
Das Gateway-Passwort `ieDmOjBiVfbbDM0ibrEebPAg` ist:
|
||||
- In `.env` auf dem Host (OK)
|
||||
- In `gateway-api-research.md` (maskiert: `ieDm...PAg`)
|
||||
- Im `openclaw.json` auf dem Host (OK)
|
||||
- In der API-Container-Umgebungsvariable (notwendig)
|
||||
|
||||
**Empfehlung:**
|
||||
- Gateway-Rate-Limiting aktiv halten (10 attempts/60s → 5min lockout)
|
||||
- Gateway-Bind auf `lan` ändern (nicht öffentlich exponiert)
|
||||
- `gateway-api-research.md` aus dem öffentlichen Repo entfernen oder Passwort entfernen
|
||||
|
||||
### 6.4 NIEDRIG — Keine Scoped API-Keys
|
||||
|
||||
Der `X-Nexus-Api-Key` gibt volle Service-Rechte. Es gibt keine Möglichkeit, verschiedene
|
||||
API-Keys mit unterschiedlichen Rechten zu vergeben.
|
||||
|
||||
**Empfehlung (spätere Phase):**
|
||||
- API-Key-Scopes einführen (read, write, admin)
|
||||
- Rate-Limiting pro API-Key
|
||||
- Audit-Log für ApiKey-Nutzung
|
||||
|
||||
### 6.5 NIEDRIG — Kein Structured Output vom Gateway
|
||||
|
||||
Die `/tools/invoke`-Responses sind JSON, aber ohne Schema-Garantie. Die Backend-Logik
|
||||
extrahiert Felder mit vielen Fallbacks (`??`-Kettenantworten).
|
||||
|
||||
**Empfehlung:**
|
||||
- Response-Typen für jedes Tool definieren (DTOs)
|
||||
- Deserialisierung mit Schema-Validierung
|
||||
- Fallback-Logik zentralisieren
|
||||
|
||||
## 7. Migrationsreihenfolge (Vorschlag)
|
||||
|
||||
### Phase 3b — Sichere Board-Grundlage (JETZT)
|
||||
```
|
||||
1. [AllowAnonymous] auf /tasks/board und /tasks/reset-stale fixen
|
||||
→ ApiKey-Auth plus X-Agent-Id-Validierung
|
||||
→ README/Iris-Doku aktualisieren
|
||||
|
||||
2. Gateway-Bind von loopback auf lan ändern
|
||||
→ API-Container über openclaw_default Netzwerk ansprechen
|
||||
→ host.docker.internal-Fallback entfernen
|
||||
```
|
||||
|
||||
### Phase 4 — Strukturierte Orchestrierung
|
||||
```
|
||||
3. Task→Session-Verknüpfung einführen
|
||||
→ WorkTask.SessionKey (string?)
|
||||
→ Bei Child-Task-Erstellung Session speichern
|
||||
|
||||
4. AgentDelegationService
|
||||
→ Zentralisierte Subagent-Task-Erstellung
|
||||
→ Session-Status-Monitoring
|
||||
→ Automatische Status-Propagation (Session done → Task done)
|
||||
|
||||
5. BoardOrchestrationService
|
||||
→ Refresh-Intervall für Agent-Progress
|
||||
→ Stale-Erkennung mit Session-Status
|
||||
→ Priorisierung nach Workload
|
||||
```
|
||||
|
||||
### Phase 5 — Erweiterte Integration
|
||||
```
|
||||
6. Structured Tool Responses
|
||||
→ DTOs für jedes Gateway-Tool
|
||||
→ Schema-Validierung
|
||||
→ Caching für häufige Abfragen
|
||||
|
||||
7. API-Key-Scopes
|
||||
→ read/write/admin Scopes
|
||||
→ Audit-Log für ApiKey-Nutzung
|
||||
|
||||
8. Automatische Child-Task-Erstellung
|
||||
→ Bei spawn/subagent-Aufrufen automatisch Child-Task anlegen
|
||||
→ Session-Key verknüpfen
|
||||
→ Activity-Feed erweitern
|
||||
```
|
||||
|
||||
## 8. Sichere Brücke: Architekturprinzipien
|
||||
|
||||
### 8.1 Das Backend ist die einzige Brücke
|
||||
|
||||
```
|
||||
Browser ←→ Nexus API ←→ OpenClaw Gateway
|
||||
↑ ↑
|
||||
JWT Auth Gateway Password
|
||||
(pro User) (nur im Backend)
|
||||
```
|
||||
|
||||
**Niemals:**
|
||||
- Gateway-Passwort im Frontend
|
||||
- Direkter Browser→Gateway API-Call
|
||||
- MCP-Protokoll zwischen Frontend und Gateway
|
||||
- Agent-Sessions direkt aus dem Frontend steuern
|
||||
|
||||
### 8.2 Prinzipien für jede neue Integration
|
||||
|
||||
1. **Neue Endpunkte immer im Nexus-Backend**
|
||||
2. **Auth über bestehendes JWT/ApiKey-System**
|
||||
3. **Gateway-Calls immer serverseitig mit Gateway-Passwort**
|
||||
4. **Kein Gateway-Tool direkt aus dem Frontend aufrufen**
|
||||
5. **State-Änderungen nur durch Iris/Bao (via Backend-Enforcement)**
|
||||
6. **Activity/Audit für jede State-Änderung**
|
||||
|
||||
### 8.3 Strukturierte OpenClaw-Integration (MCP-artig)
|
||||
|
||||
Der Gateway `/tools/invoke`-Endpunkt ist bereits strukturell MCP-artig. Eine formale
|
||||
MCP-Implementierung zwischen Nexus und Gateway ist **nicht notwendig**. Stattdessen:
|
||||
|
||||
```
|
||||
Nexus.Backend.Services
|
||||
├── IOpenClawGatewayClient (Gateway-Tool-Abstraktion)
|
||||
│ └── InvokeToolAsync(tool, args) → JsonNode?
|
||||
│
|
||||
├── IBoardOrchestrationService (NEU)
|
||||
│ ├── CreateDelegateTask(agentId, title, detail) → WorkTask
|
||||
│ ├── WatchAgentSession(agentId) → SessionWatcher
|
||||
│ └── SyncAgentProgress() → Progress[]
|
||||
│
|
||||
└── IAgentDelegationService (NEU)
|
||||
├── DelegateToAgent(parentTaskId, agentId, instruction)
|
||||
├── CollectResult(subTaskId) → AgentResult
|
||||
└── HandleBlocker(subTaskId, reason) → void
|
||||
```
|
||||
|
||||
## 9. Zusammenfassung
|
||||
|
||||
### Was gut ist (nicht ändern):
|
||||
- Board-first-Ansatz mit Parent/Child-Tasks
|
||||
- Backend als einzige Gateway-Brücke
|
||||
- JWT + Gateway-Password-Trennung
|
||||
- State-Change-Restriktion auf Iris/Bao
|
||||
- HTTP Deny-List des Gateways
|
||||
- CSP im Frontend (kein externer Connect)
|
||||
|
||||
### Was verbessert werden muss:
|
||||
- `[AllowAnonymous]` auf Board-Endpunkten → ApiKey-Auth
|
||||
- Gateway-Bind loopback → lan (oder Netzwerk-Routing korrigieren)
|
||||
- Task→Session-Verknüpfung fehlt
|
||||
|
||||
### Was später kommen kann:
|
||||
- Automatische Child-Task-Erstellung bei Subagent-Aufrufen
|
||||
- Structured Gateway Responses mit Schema-Validierung
|
||||
- API-Key-Scopes und Audit
|
||||
- Session-gesteuertes Progress-Tracking
|
||||
|
||||
### Was niemals kommen darf:
|
||||
- Gateway-Passwort im Frontend
|
||||
- Direkter MCP-Pfad Browser→Gateway
|
||||
- Agent-Session-Steuerung aus dem Frontend
|
||||
- Task-State-Änderung durch Sub-Agenten
|
||||
@@ -1,7 +1,12 @@
|
||||
# Gateway API Research
|
||||
|
||||
> Generated: 2026-06-10
|
||||
> Generated: 2026-06-10 | Updated: 2026-06-22
|
||||
> Auth mode: password (not token)
|
||||
>
|
||||
> ⚠️ **Security note:** Diese Datei enthält Infrastruktur-Details zur Gateway-Integration.
|
||||
> Sie gehört nicht ins öffentliche Repository. Bis zur Bereinigung: Gateway-Passwort
|
||||
> maskiert als `ieDm...PAg`. Vollständige Architektur-Analyse in
|
||||
> [`architecture-board-first-orchestration.md`](architecture-board-first-orchestration.md).
|
||||
|
||||
## 1. Authentication
|
||||
|
||||
|
||||
@@ -0,0 +1,323 @@
|
||||
# OpenClaw ↔ Nexus Task Board Flow
|
||||
|
||||
> Letzte Aktualisierung: 2026-06-21
|
||||
> Status: kanonische Arbeitsbeschreibung für Iris, Sub-Agenten und das Nexus Task Board
|
||||
|
||||
Diese Datei beschreibt den gewünschten und umgesetzten Arbeitsfluss zwischen:
|
||||
|
||||
- **Bao** als Auftraggeber
|
||||
- **Iris** als Chief of Staff / Koordinatorin
|
||||
- **Sub-Agenten** als ausführende Spezialisten
|
||||
- **OpenClaw** als Agent-Runtime
|
||||
- **Nexus Task Board** als sichtbare Aufgabenquelle
|
||||
|
||||
---
|
||||
|
||||
## 1. Kurzfassung
|
||||
|
||||
**Eine Hauptaufgabe gehört Iris.**
|
||||
Wenn Iris Arbeit delegiert, wird diese Delegation **nicht unsichtbar im Chat** geführt, sondern als **sichtbare Child-Task** im Nexus Task Board angelegt.
|
||||
|
||||
Das bedeutet:
|
||||
|
||||
- **Parent-Task** = Verantwortung von Iris
|
||||
- **Child-Task** = konkrete Arbeitsaufgabe für einen Spezial-Agenten
|
||||
- **Board** = sichtbare Wahrheit für Aufgabenstatus und Ownership
|
||||
- **OpenClaw** = Ausführungspfad für Agentenarbeit
|
||||
|
||||
---
|
||||
|
||||
## 2. Die Hauptidee
|
||||
|
||||
Früher war Delegation leicht unsichtbar oder lief über einen separaten `Delegated`-Status.
|
||||
|
||||
Der neue Flow ersetzt das durch:
|
||||
|
||||
1. **Iris übernimmt eine Parent-Task**
|
||||
2. **Iris zerlegt die Arbeit bei Bedarf in Subtasks**
|
||||
3. **Jede echte Delegation wird als Child-Task auf dem Board angelegt**
|
||||
4. **Der zuständige Agent arbeitet gegen diese Child-Task**
|
||||
5. **Iris integriert die Ergebnisse zurück in die Parent-Task**
|
||||
6. **Erst wenn alles fertig ist, geht die Parent-Task in Review**
|
||||
|
||||
---
|
||||
|
||||
## 3. Systembild
|
||||
|
||||
```mermaid
|
||||
flowchart LR
|
||||
Bao[Bao\nAuftraggeber]
|
||||
Iris[Iris\nChief of Staff]
|
||||
Board[Nexus Task Board\nParent + Child Tasks]
|
||||
OC[OpenClaw Runtime]
|
||||
Agents[Sub-Agenten\nDeveloper / Reviewer / Architekt / ...]
|
||||
|
||||
Bao -->|Auftrag / Priorisierung| Iris
|
||||
Iris -->|legt Parent-Task an / übernimmt Task| Board
|
||||
Iris -->|delegiert konkrete Arbeit| OC
|
||||
OC -->|führt Agenten-Task aus| Agents
|
||||
Iris -->|legt Child-Tasks an| Board
|
||||
Agents -->|arbeiten gegen Child-Tasks| Board
|
||||
Agents -->|liefern Ergebnis / melden Blocker| Iris
|
||||
Iris -->|integriert Ergebnis| Board
|
||||
Board -->|Review für Bao| Bao
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 4. Rollen und Verantwortlichkeiten
|
||||
|
||||
### Bao
|
||||
- gibt Aufgaben inhaltlich vor
|
||||
- priorisiert und nimmt fertige Arbeit ab
|
||||
- verschiebt fertige Hauptaufgaben aus **Review** nach **Done** oder zurück
|
||||
|
||||
### Iris
|
||||
- übernimmt die Parent-Task
|
||||
- analysiert, zerlegt, delegiert und reviewed
|
||||
- hält die Hauptaufgabe auf dem Board aktuell
|
||||
- erstellt sichtbare Child-Tasks für delegierte Arbeit
|
||||
- entscheidet, ob etwas **In Progress**, **Blocked** oder **Review** ist
|
||||
|
||||
### Sub-Agenten
|
||||
- arbeiten **nicht** direkt gegen eine diffuse Hauptaufgabe
|
||||
- arbeiten gegen eine **konkret zugewiesene Child-Task**
|
||||
- melden Fortschritt, Ergebnisse und Blocker an Iris
|
||||
|
||||
### OpenClaw
|
||||
- führt die Agentenarbeit technisch aus
|
||||
- liefert Nachrichten, Status und Arbeitsergebnisse zurück
|
||||
- ersetzt nicht das Board als Aufgabenwahrheit
|
||||
|
||||
### Nexus Task Board
|
||||
- ist die **sichtbare operative Quelle** für Aufgaben
|
||||
- zeigt Parent-Task, Child-Tasks, Ownership und Status
|
||||
- dokumentiert den tatsächlichen Arbeitsfluss
|
||||
|
||||
---
|
||||
|
||||
## 5. Parent-Task vs. Child-Task
|
||||
|
||||
| Ebene | Zweck | Owner | Sichtbarkeit |
|
||||
|---|---|---|---|
|
||||
| Parent-Task | Hauptauftrag / Koordination | Iris | Board |
|
||||
| Child-Task | Delegierter Arbeitsblock | zuständiger Agent | Board |
|
||||
|
||||
### Parent-Task-Regeln
|
||||
- bleibt bei Iris
|
||||
- bleibt in der Regel **In Progress**, solange Koordination läuft
|
||||
- geht erst auf **Review**, wenn alle nötigen Child-Tasks erledigt und integriert sind
|
||||
- geht nur auf **Blocked**, wenn Iris insgesamt nicht weiterkommt
|
||||
|
||||
### Child-Task-Regeln
|
||||
- repräsentiert eine echte delegierte Teilaufgabe
|
||||
- hat klare Ownership (`AssignedTo`)
|
||||
- zeigt sichtbar, welcher Agent woran arbeitet
|
||||
- wird nicht für triviale Mini-Schritte missbraucht
|
||||
|
||||
---
|
||||
|
||||
## 6. Zustandsmodell
|
||||
|
||||
### Parent-Task-Lifecycle
|
||||
|
||||
```mermaid
|
||||
stateDiagram-v2
|
||||
[*] --> Backlog
|
||||
Backlog --> InProgress: Iris übernimmt
|
||||
InProgress --> InProgress: Child-Tasks anlegen / koordinieren
|
||||
InProgress --> Blocked: Gesamtblocker
|
||||
InProgress --> Review: alles integriert
|
||||
Review --> Done: Bao nimmt ab
|
||||
Review --> Backlog: Bao gibt zurück
|
||||
Blocked --> Backlog: Blocker gelöst
|
||||
```
|
||||
|
||||
### Child-Task-Lifecycle
|
||||
|
||||
```mermaid
|
||||
stateDiagram-v2
|
||||
[*] --> Backlog
|
||||
Backlog --> InProgress: Agent startet
|
||||
InProgress --> Done: Ergebnis geliefert
|
||||
InProgress --> Blocked: Agent kommt nicht weiter
|
||||
Blocked --> Backlog: neu geplant / entsperrt
|
||||
Blocked --> InProgress: Iris stößt Weiterarbeit an
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 7. Der konkrete Arbeitsablauf
|
||||
|
||||
### Fall A: Bao gibt Iris einen neuen Auftrag
|
||||
|
||||
1. Bao formuliert einen Auftrag
|
||||
2. Iris prüft Ziel, Scope, Risiko und Umgebung
|
||||
3. Iris übernimmt oder erstellt die **Parent-Task**
|
||||
4. Parent-Task geht auf **In Progress**
|
||||
5. Wenn nötig zerlegt Iris die Arbeit in **Child-Tasks**
|
||||
6. Child-Tasks werden passenden Agenten zugewiesen
|
||||
7. Agenten arbeiten die Child-Tasks ab
|
||||
8. Iris sammelt Ergebnisse ein und integriert sie
|
||||
9. Parent-Task geht auf **Review**
|
||||
10. Bao entscheidet: **Done** oder zurück nach **Backlog**
|
||||
|
||||
### Fall B: Agent meldet einen Blocker
|
||||
|
||||
1. Agent meldet Blocker an Iris
|
||||
2. Iris prüft, ob der Blocker lokal lösbar ist
|
||||
3. Wenn nein: die betroffene **Child-Task** geht auf **Blocked**
|
||||
4. Falls nötig entsteht eine neue Ursachen-Task / neue Child-Task
|
||||
5. Parent-Task bleibt **In Progress**, solange der Gesamtauftrag noch koordiniert wird
|
||||
6. Nur wenn die Hauptaufgabe insgesamt feststeckt, geht die **Parent-Task** auf **Blocked**
|
||||
|
||||
---
|
||||
|
||||
## 8. OpenClaw- und Board-Interaktion
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
participant Bao
|
||||
participant Iris
|
||||
participant Board as Nexus Task Board
|
||||
participant OpenClaw
|
||||
participant Agent as Sub-Agent
|
||||
|
||||
Bao->>Iris: Auftrag
|
||||
Iris->>Board: Parent-Task übernehmen / anlegen
|
||||
Iris->>Board: Child-Task anlegen
|
||||
Iris->>OpenClaw: Agentenauftrag starten
|
||||
OpenClaw->>Agent: Task ausführen
|
||||
Agent-->>Iris: Ergebnis / Rückfrage / Blocker
|
||||
Iris->>Board: Child-Task aktualisieren
|
||||
Iris->>Board: Parent-Task integrieren
|
||||
Iris->>Board: Parent auf Review setzen
|
||||
Board-->>Bao: Review sichtbar
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 9. Regeln für gutes Schneiden von Child-Tasks
|
||||
|
||||
Eine Child-Task ist sinnvoll, wenn sie:
|
||||
|
||||
- einen **klaren Arbeitsblock** darstellt
|
||||
- einen **eigenen Verantwortlichen** hat
|
||||
- ein **eigenes Ergebnis** liefern soll
|
||||
- unabhängig als **Done** oder **Blocked** sichtbar sein kann
|
||||
|
||||
Keine gute Child-Task ist:
|
||||
|
||||
- „Datei öffnen"
|
||||
- „kurz nachschauen"
|
||||
- „eine Kleinigkeit prüfen"
|
||||
|
||||
Faustregel:
|
||||
|
||||
> **Eine Child-Task soll ein echter delegierbarer Arbeitsauftrag sein, kein Mikro-Schritt.**
|
||||
|
||||
---
|
||||
|
||||
## 10. Board-Sicht: was sichtbar sein soll
|
||||
|
||||
Im Board soll erkennbar sein:
|
||||
|
||||
- welche Parent-Task Iris gerade steuert
|
||||
- welche Child-Tasks darunter existieren
|
||||
- welcher Agent welche Child-Task besitzt
|
||||
- welche Child-Task blockiert ist
|
||||
- welche Parent-Task in Review auf Bao wartet
|
||||
|
||||
Im Task-Detail sollen sichtbar sein:
|
||||
|
||||
- Parent/Child-Beziehung
|
||||
- `AssignedTo`
|
||||
- Status
|
||||
- erwarteter nächster Beitrag / letzter Aktivitätshinweis
|
||||
- Child-Task-Liste direkt unter der Parent-Task
|
||||
|
||||
---
|
||||
|
||||
## 11. Kanonische Regeln
|
||||
|
||||
### Regel 1 — Das Board ist die sichtbare Aufgabenwahrheit
|
||||
Chat und Agentenläufe ergänzen das Board, ersetzen es aber nicht.
|
||||
|
||||
### Regel 2 — Iris bleibt Ownerin der Hauptaufgabe
|
||||
Delegation verschiebt Verantwortung nicht automatisch auf den Agenten.
|
||||
|
||||
### Regel 3 — Delegation ist sichtbar
|
||||
Jede echte delegierte Arbeit wird als Child-Task abgebildet.
|
||||
|
||||
### Regel 4 — Kein künstlicher Wartezustand auf Parent-Ebene
|
||||
Die Parent-Task bleibt **In Progress**, solange Iris aktiv koordiniert.
|
||||
|
||||
### Regel 5 — Blocker präzise markieren
|
||||
Wenn nur ein Arbeitspaket hängt, blockiert zuerst die **Child-Task**, nicht automatisch die ganze Parent-Task.
|
||||
|
||||
### Regel 6 — Review ist Bao-Gate
|
||||
Fertige Hauptaufgaben gehen erst in **Review**, dann nach Bao-Entscheid auf **Done** oder zurück.
|
||||
|
||||
---
|
||||
|
||||
## 12. Beispiel
|
||||
|
||||
### Parent-Task
|
||||
**„Nexus Taskflow auf Parent-/Child-Modell umstellen“** — Owner: `iris`
|
||||
|
||||
### Mögliche Child-Tasks
|
||||
- **PO-Spezifikation und Akzeptanzkriterien ausarbeiten** — Owner: `product-owner`
|
||||
- **Schnelle Voranalyse / kleiner Patch** — Owner: `programmer-fast`
|
||||
- **Backend-State-Handling anpassen** — Owner: `programmer`
|
||||
- **Frontend-Board-Spalten und Labels anpassen** — Owner: `programmer`
|
||||
- **Workflow verifizieren / Regression prüfen** — Owner: `reviewer`
|
||||
- **Deploy-/Runtime-Auswirkung prüfen** — Owner: `architekt`
|
||||
|
||||
So sieht Bao später nicht nur „Iris arbeitet daran“, sondern konkret:
|
||||
|
||||
- welcher Teil erledigt ist
|
||||
- welcher Teil noch läuft
|
||||
- welcher Teil blockiert ist
|
||||
- worauf Iris gerade wartet
|
||||
|
||||
---
|
||||
|
||||
## 13. Anti-Patterns
|
||||
|
||||
Diese Muster sollen vermieden werden:
|
||||
|
||||
- Parent-Task auf einen bloßen **Delegated**-Wartestatus schieben
|
||||
- Delegation nur im Chat sichtbar machen
|
||||
- Child-Tasks ohne klare Ownership anlegen
|
||||
- Blocker nur mündlich erwähnen, aber nicht im Board markieren
|
||||
- zehn Mikro-Subtasks für einen Mini-Arbeitsschritt erzeugen
|
||||
|
||||
---
|
||||
|
||||
## 14. Entscheidungsregel für Iris
|
||||
|
||||
Wenn Iris unsicher ist, ob sie eine Child-Task anlegen soll, gilt:
|
||||
|
||||
**Child-Task anlegen**, wenn mindestens einer der Punkte zutrifft:
|
||||
|
||||
- anderer Agent übernimmt echte Arbeit
|
||||
- eigener Status muss sichtbar verfolgt werden
|
||||
- eigener Blocker ist möglich
|
||||
- Bao soll Transparenz über diesen Teil sehen
|
||||
|
||||
---
|
||||
|
||||
## 15. Technische Leitplanken
|
||||
|
||||
- `parentTaskId` verknüpft Child-Tasks mit der Parent-Task
|
||||
- `AssignedTo` zeigt den operativen Owner
|
||||
- Child-Tasks dürfen geplant in `Backlog` erstellt werden; nur aktiv gestartete Delegationen beginnen direkt in `In progress`
|
||||
- Agentenstatus und Boardstatus dürfen sich ergänzen, aber nicht widersprechen
|
||||
- Board-Spalten und API-State-Mapping müssen das Parent-/Child-Modell sauber abbilden
|
||||
- UI und Doku müssen dieselbe Sprache sprechen
|
||||
|
||||
---
|
||||
|
||||
## 16. Merksatz
|
||||
|
||||
> **Iris koordiniert die Hauptaufgabe. Agenten erledigen sichtbare Child-Tasks. Das Board zeigt die Wahrheit. OpenClaw führt aus.**
|
||||
@@ -0,0 +1 @@
|
||||
{"locator":{"name":"pnpm","reference":"10.12.1"},"bin":{"pnpm":"./bin/pnpm.cjs","pnpx":"./bin/pnpx.cjs"},"hash":"sha512.f0dda8580f0ee9481c5c79a1d927b9164f2c478e90992ad268bbb2465a736984391d6333d2c327913578b2804af33474ca554ba29c04a8b13060a717675ae3ac"}
|
||||
@@ -0,0 +1,22 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015-2016 Rico Sta. Cruz and other contributors
|
||||
Copyright (c) 2016-2025 Zoltan Kochan and other contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,212 @@
|
||||
[简体中文](https://pnpm.io/zh/) |
|
||||
[日本語](https://pnpm.io/ja/) |
|
||||
[한국어](https://pnpm.io/ko/) |
|
||||
[Italiano](https://pnpm.io/it/) |
|
||||
[Português Brasileiro](https://pnpm.io/pt/)
|
||||
|
||||
<picture>
|
||||
<source media="(prefers-color-scheme: light)" srcset="https://i.imgur.com/qlW1eEG.png">
|
||||
<source media="(prefers-color-scheme: dark)" srcset="https://i.imgur.com/qlW1eEG.png">
|
||||
<img src="https://i.imgur.com/qlW1eEG.png" alt="pnpm">
|
||||
</picture>
|
||||
|
||||
Fast, disk space efficient package manager:
|
||||
|
||||
* **Fast.** Up to 2x faster than the alternatives (see [benchmark](#benchmark)).
|
||||
* **Efficient.** Files inside `node_modules` are linked from a single content-addressable storage.
|
||||
* **[Great for monorepos](https://pnpm.io/workspaces).**
|
||||
* **Strict.** A package can access only dependencies that are specified in its `package.json`.
|
||||
* **Deterministic.** Has a lockfile called `pnpm-lock.yaml`.
|
||||
* **Works as a Node.js version manager.** See [pnpm env use](https://pnpm.io/cli/env).
|
||||
* **Works everywhere.** Supports Windows, Linux, and macOS.
|
||||
* **Battle-tested.** Used in production by teams of [all sizes](https://pnpm.io/users) since 2016.
|
||||
* [See the full feature comparison with npm and Yarn](https://pnpm.io/feature-comparison).
|
||||
|
||||
To quote the [Rush](https://rushjs.io/) team:
|
||||
|
||||
> Microsoft uses pnpm in Rush repos with hundreds of projects and hundreds of PRs per day, and we’ve found it to be very fast and reliable.
|
||||
|
||||
[](https://github.com/pnpm/pnpm/releases/latest)
|
||||
[](https://r.pnpm.io/chat)
|
||||
[](https://opencollective.com/pnpm)
|
||||
[](https://opencollective.com/pnpm)
|
||||
[](https://x.com/intent/follow?screen_name=pnpmjs®ion=follow_link)
|
||||
[](https://stand-with-ukraine.pp.ua)
|
||||
|
||||
## Platinum Sponsors
|
||||
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td align="center" valign="middle">
|
||||
<a href="https://bit.dev/?utm_source=pnpm&utm_medium=readme" target="_blank"><img src="https://pnpm.io/img/users/bit.svg" width="80" alt="Bit"></a>
|
||||
</td>
|
||||
<td align="center" valign="middle">
|
||||
<a href="https://sanity.io/?utm_source=pnpm&utm_medium=readme" target="_blank"><img src="https://pnpm.io/img/users/sanity.svg" width="180" alt="Bit"></a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
## Gold Sponsors
|
||||
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td align="center" valign="middle">
|
||||
<a href="https://discord.com/?utm_source=pnpm&utm_medium=readme" target="_blank">
|
||||
<picture>
|
||||
<source media="(prefers-color-scheme: light)" srcset="https://pnpm.io/img/users/discord.svg" />
|
||||
<source media="(prefers-color-scheme: dark)" srcset="https://pnpm.io/img/users/discord_light.svg" />
|
||||
<img src="https://pnpm.io/img/users/discord.svg" width="220" alt="Discord" />
|
||||
</picture>
|
||||
</a>
|
||||
</td>
|
||||
<td align="center" valign="middle">
|
||||
<a href="https://coderabbit.ai/?utm_source=pnpm&utm_medium=readme" target="_blank">
|
||||
<picture>
|
||||
<source media="(prefers-color-scheme: light)" srcset="https://pnpm.io/img/users/coderabbit.svg" />
|
||||
<source media="(prefers-color-scheme: dark)" srcset="https://pnpm.io/img/users/coderabbit_light.svg" />
|
||||
<img src="https://pnpm.io/img/users/coderabbit.svg" width="220" alt="CodeRabbit" />
|
||||
</picture>
|
||||
</a>
|
||||
</td>
|
||||
<td align="center" valign="middle">
|
||||
<a href="https://workleap.com/?utm_source=pnpm&utm_medium=readme" target="_blank">
|
||||
<picture>
|
||||
<source media="(prefers-color-scheme: light)" srcset="https://pnpm.io/img/users/workleap.svg" />
|
||||
<source media="(prefers-color-scheme: dark)" srcset="https://pnpm.io/img/users/workleap_light.svg" />
|
||||
<img src="https://pnpm.io/img/users/workleap.svg" width="190" alt="Workleap" />
|
||||
</picture>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" valign="middle">
|
||||
<a href="https://stackblitz.com/?utm_source=pnpm&utm_medium=readme" target="_blank">
|
||||
<picture>
|
||||
<source media="(prefers-color-scheme: light)" srcset="https://pnpm.io/img/users/stackblitz.svg" />
|
||||
<source media="(prefers-color-scheme: dark)" srcset="https://pnpm.io/img/users/stackblitz_light.svg" />
|
||||
<img src="https://pnpm.io/img/users/stackblitz.svg" width="190" alt="Stackblitz" />
|
||||
</picture>
|
||||
</a>
|
||||
</td>
|
||||
<td align="center" valign="middle">
|
||||
<a href="https://vite.dev/?utm_source=pnpm&utm_medium=readme" target="_blank">
|
||||
<img src="https://pnpm.io/img/users/vitejs.svg" width="42" alt="Vite">
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
## Silver Sponsors
|
||||
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td align="center" valign="middle">
|
||||
<a href="https://uscreen.de/?utm_source=pnpm&utm_medium=readme" target="_blank">
|
||||
<picture>
|
||||
<source media="(prefers-color-scheme: light)" srcset="https://pnpm.io/img/users/uscreen.svg" />
|
||||
<source media="(prefers-color-scheme: dark)" srcset="https://pnpm.io/img/users/uscreen_light.svg" />
|
||||
<img src="https://pnpm.io/img/users/uscreen.svg" width="180" alt="u|screen" />
|
||||
</picture>
|
||||
</a>
|
||||
</td>
|
||||
<td align="center" valign="middle">
|
||||
<a href="https://leniolabs.com/?utm_source=pnpm&utm_medium=readme" target="_blank">
|
||||
<img src="https://pnpm.io/img/users/leniolabs.jpg" width="40" alt="Leniolabs_">
|
||||
</a>
|
||||
</td>
|
||||
<td align="center" valign="middle">
|
||||
<a href="https://depot.dev/?utm_source=pnpm&utm_medium=readme" target="_blank">
|
||||
<picture>
|
||||
<source media="(prefers-color-scheme: light)" srcset="https://pnpm.io/img/users/depot.svg" />
|
||||
<source media="(prefers-color-scheme: dark)" srcset="https://pnpm.io/img/users/depot_light.svg" />
|
||||
<img src="https://pnpm.io/img/users/depot.svg" width="100" alt="Depot" />
|
||||
</picture>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" valign="middle">
|
||||
<a href="https://devowl.io/?utm_source=pnpm&utm_medium=readme" target="_blank">
|
||||
<picture>
|
||||
<source media="(prefers-color-scheme: light)" srcset="https://pnpm.io/img/users/devowlio.svg" />
|
||||
<source media="(prefers-color-scheme: dark)" srcset="https://pnpm.io/img/users/devowlio.svg" />
|
||||
<img src="https://pnpm.io/img/users/devowlio.svg" width="100" alt="devowl.io" />
|
||||
</picture>
|
||||
</a>
|
||||
</td>
|
||||
<td align="center" valign="middle">
|
||||
<a href="https://cerbos.dev/?utm_source=pnpm&utm_medium=readme" target="_blank">
|
||||
<picture>
|
||||
<source media="(prefers-color-scheme: light)" srcset="https://pnpm.io/img/users/cerbos.svg" />
|
||||
<source media="(prefers-color-scheme: dark)" srcset="https://pnpm.io/img/users/cerbos_light.svg" />
|
||||
<img src="https://pnpm.io/img/users/cerbos.svg" width="90" alt="Cerbos" />
|
||||
</picture>
|
||||
</a>
|
||||
</td>
|
||||
<td align="center" valign="middle">
|
||||
<a href="https://opensource.mercedes-benz.com/?utm_source=pnpm&utm_medium=readme" target="_blank">
|
||||
<img src="https://pnpm.io/img/users/mercedes.svg" width="32" alt="Vite">
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
Support this project by [becoming a sponsor](https://opencollective.com/pnpm#sponsor).
|
||||
|
||||
## Background
|
||||
|
||||
pnpm uses a content-addressable filesystem to store all files from all module directories on a disk.
|
||||
When using npm, if you have 100 projects using lodash, you will have 100 copies of lodash on disk.
|
||||
With pnpm, lodash will be stored in a content-addressable storage, so:
|
||||
|
||||
1. If you depend on different versions of lodash, only the files that differ are added to the store.
|
||||
If lodash has 100 files, and a new version has a change only in one of those files,
|
||||
`pnpm update` will only add 1 new file to the storage.
|
||||
1. All the files are saved in a single place on the disk. When packages are installed, their files are linked
|
||||
from that single place consuming no additional disk space. Linking is performed using either hard-links or reflinks (copy-on-write).
|
||||
|
||||
As a result, you save gigabytes of space on your disk and you have a lot faster installations!
|
||||
If you'd like more details about the unique `node_modules` structure that pnpm creates and
|
||||
why it works fine with the Node.js ecosystem, read this small article: [Flat node_modules is not the only way](https://pnpm.io/blog/2020/05/27/flat-node-modules-is-not-the-only-way).
|
||||
|
||||
💖 Like this project? Let people know with a [tweet](https://r.pnpm.io/tweet)
|
||||
|
||||
## Installation
|
||||
|
||||
For installation options [visit our website](https://pnpm.io/installation).
|
||||
|
||||
## Usage
|
||||
|
||||
Just use pnpm in place of npm/Yarn. E.g., install dependencies via:
|
||||
|
||||
```
|
||||
pnpm install
|
||||
```
|
||||
|
||||
For more advanced usage, read [pnpm CLI](https://pnpm.io/pnpm-cli) on our website, or run `pnpm help`.
|
||||
|
||||
## Benchmark
|
||||
|
||||
pnpm is up to 2x faster than npm and Yarn classic. See all benchmarks [here](https://r.pnpm.io/benchmarks).
|
||||
|
||||
Benchmarks on an app with lots of dependencies:
|
||||
|
||||

|
||||
|
||||
## Support
|
||||
|
||||
- [Frequently Asked Questions](https://pnpm.io/faq)
|
||||
- [Chat](https://r.pnpm.io/chat)
|
||||
- [X](https://x.com/pnpmjs)
|
||||
- [Bluesky](https://bsky.app/profile/pnpm.io)
|
||||
|
||||
## License
|
||||
|
||||
[MIT](https://github.com/pnpm/pnpm/blob/main/LICENSE)
|
||||
|
||||
@@ -0,0 +1,189 @@
|
||||
{
|
||||
"name": "pnpm",
|
||||
"version": "10.12.1",
|
||||
"description": "Fast, disk space efficient package manager",
|
||||
"keywords": [
|
||||
"pnpm",
|
||||
"pnpm10",
|
||||
"dependencies",
|
||||
"dependency manager",
|
||||
"efficient",
|
||||
"fast",
|
||||
"hardlinks",
|
||||
"install",
|
||||
"installer",
|
||||
"link",
|
||||
"lockfile",
|
||||
"modules",
|
||||
"monorepo",
|
||||
"multi-package",
|
||||
"npm",
|
||||
"package manager",
|
||||
"package.json",
|
||||
"packages",
|
||||
"prune",
|
||||
"rapid",
|
||||
"remove",
|
||||
"shrinkwrap",
|
||||
"symlinks",
|
||||
"uninstall",
|
||||
"workspace"
|
||||
],
|
||||
"license": "MIT",
|
||||
"funding": "https://opencollective.com/pnpm",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/pnpm/pnpm.git",
|
||||
"directory": "pnpm"
|
||||
},
|
||||
"homepage": "https://pnpm.io",
|
||||
"bugs": {
|
||||
"url": "https://github.com/pnpm/pnpm/issues"
|
||||
},
|
||||
"main": "bin/pnpm.cjs",
|
||||
"exports": {
|
||||
".": "./package.json"
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
"bin"
|
||||
],
|
||||
"bin": {
|
||||
"pnpm": "bin/pnpm.cjs",
|
||||
"pnpx": "bin/pnpx.cjs"
|
||||
},
|
||||
"directories": {
|
||||
"test": "test"
|
||||
},
|
||||
"unpkg": "dist/pnpm.cjs",
|
||||
"__dependencies": {
|
||||
"v8-compile-cache": "2.4.0"
|
||||
},
|
||||
"__optionalDependencies": {
|
||||
"node-gyp": "^11.1.0"
|
||||
},
|
||||
"__devDependencies": {
|
||||
"@pnpm/assert-project": "workspace:*",
|
||||
"@pnpm/byline": "catalog:",
|
||||
"@pnpm/cache.commands": "workspace:*",
|
||||
"@pnpm/cli-meta": "workspace:*",
|
||||
"@pnpm/cli-utils": "workspace:*",
|
||||
"@pnpm/client": "workspace:*",
|
||||
"@pnpm/command": "workspace:*",
|
||||
"@pnpm/common-cli-options-help": "workspace:*",
|
||||
"@pnpm/config": "workspace:*",
|
||||
"@pnpm/constants": "workspace:*",
|
||||
"@pnpm/core-loggers": "workspace:*",
|
||||
"@pnpm/crypto.hash": "workspace:*",
|
||||
"@pnpm/default-reporter": "workspace:*",
|
||||
"@pnpm/dependency-path": "workspace:*",
|
||||
"@pnpm/env.path": "workspace:*",
|
||||
"@pnpm/error": "workspace:*",
|
||||
"@pnpm/exec.build-commands": "workspace:*",
|
||||
"@pnpm/filter-workspace-packages": "workspace:*",
|
||||
"@pnpm/find-workspace-dir": "workspace:*",
|
||||
"@pnpm/lockfile.types": "workspace:*",
|
||||
"@pnpm/logger": "workspace:*",
|
||||
"@pnpm/modules-yaml": "workspace:*",
|
||||
"@pnpm/nopt": "catalog:",
|
||||
"@pnpm/parse-cli-args": "workspace:*",
|
||||
"@pnpm/plugin-commands-audit": "workspace:*",
|
||||
"@pnpm/plugin-commands-completion": "workspace:*",
|
||||
"@pnpm/plugin-commands-config": "workspace:*",
|
||||
"@pnpm/plugin-commands-deploy": "workspace:*",
|
||||
"@pnpm/plugin-commands-doctor": "workspace:*",
|
||||
"@pnpm/plugin-commands-env": "workspace:*",
|
||||
"@pnpm/plugin-commands-init": "workspace:*",
|
||||
"@pnpm/plugin-commands-installation": "workspace:*",
|
||||
"@pnpm/plugin-commands-licenses": "workspace:*",
|
||||
"@pnpm/plugin-commands-listing": "workspace:*",
|
||||
"@pnpm/plugin-commands-outdated": "workspace:*",
|
||||
"@pnpm/plugin-commands-patching": "workspace:*",
|
||||
"@pnpm/plugin-commands-publishing": "workspace:*",
|
||||
"@pnpm/plugin-commands-rebuild": "workspace:*",
|
||||
"@pnpm/plugin-commands-script-runners": "workspace:*",
|
||||
"@pnpm/plugin-commands-server": "workspace:*",
|
||||
"@pnpm/plugin-commands-setup": "workspace:*",
|
||||
"@pnpm/plugin-commands-store": "workspace:*",
|
||||
"@pnpm/plugin-commands-store-inspecting": "workspace:*",
|
||||
"@pnpm/prepare": "workspace:*",
|
||||
"@pnpm/read-package-json": "workspace:*",
|
||||
"@pnpm/read-project-manifest": "workspace:*",
|
||||
"@pnpm/registry-mock": "catalog:",
|
||||
"@pnpm/run-npm": "workspace:*",
|
||||
"@pnpm/store.cafs": "workspace:*",
|
||||
"@pnpm/tabtab": "catalog:",
|
||||
"@pnpm/test-fixtures": "workspace:*",
|
||||
"@pnpm/test-ipc-server": "workspace:*",
|
||||
"@pnpm/tools.path": "workspace:*",
|
||||
"@pnpm/tools.plugin-commands-self-updater": "workspace:*",
|
||||
"@pnpm/types": "workspace:*",
|
||||
"@pnpm/worker": "workspace:*",
|
||||
"@pnpm/workspace.find-packages": "workspace:*",
|
||||
"@pnpm/workspace.pkgs-graph": "workspace:*",
|
||||
"@pnpm/workspace.read-manifest": "workspace:*",
|
||||
"@pnpm/workspace.state": "workspace:*",
|
||||
"@pnpm/write-project-manifest": "workspace:*",
|
||||
"@types/cross-spawn": "catalog:",
|
||||
"@types/is-windows": "catalog:",
|
||||
"@types/pnpm__byline": "catalog:",
|
||||
"@types/ramda": "catalog:",
|
||||
"@types/semver": "catalog:",
|
||||
"@zkochan/retry": "catalog:",
|
||||
"@zkochan/rimraf": "catalog:",
|
||||
"chalk": "catalog:",
|
||||
"ci-info": "catalog:",
|
||||
"cross-spawn": "catalog:",
|
||||
"deep-require-cwd": "catalog:",
|
||||
"delay": "catalog:",
|
||||
"dir-is-case-sensitive": "catalog:",
|
||||
"esbuild": "catalog:",
|
||||
"execa": "catalog:",
|
||||
"exists-link": "catalog:",
|
||||
"is-windows": "catalog:",
|
||||
"load-json-file": "catalog:",
|
||||
"loud-rejection": "catalog:",
|
||||
"normalize-newline": "catalog:",
|
||||
"p-any": "catalog:",
|
||||
"p-defer": "catalog:",
|
||||
"path-name": "catalog:",
|
||||
"pidtree": "catalog:",
|
||||
"ps-list": "catalog:",
|
||||
"ramda": "catalog:",
|
||||
"read-yaml-file": "catalog:",
|
||||
"render-help": "catalog:",
|
||||
"semver": "catalog:",
|
||||
"split-cmd": "catalog:",
|
||||
"symlink-dir": "catalog:",
|
||||
"tempy": "catalog:",
|
||||
"tree-kill": "catalog:",
|
||||
"write-json-file": "catalog:",
|
||||
"write-pkg": "catalog:",
|
||||
"write-yaml-file": "catalog:"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18.12"
|
||||
},
|
||||
"jest": {
|
||||
"preset": "@pnpm/jest-config/with-registry"
|
||||
},
|
||||
"preferGlobal": true,
|
||||
"publishConfig": {
|
||||
"tag": "next-10",
|
||||
"executableFiles": [
|
||||
"./dist/node-gyp-bin/node-gyp",
|
||||
"./dist/node-gyp-bin/node-gyp.cmd",
|
||||
"./dist/node_modules/node-gyp/bin/node-gyp.js"
|
||||
]
|
||||
},
|
||||
"scripts": {
|
||||
"bundle": "ts-node bundle.ts",
|
||||
"start": "tsc --watch",
|
||||
"lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
|
||||
"pretest:e2e": "rimraf node_modules/.bin/pnpm",
|
||||
"_test": "jest",
|
||||
"test": "pnpm run compile && pnpm run _test",
|
||||
"_compile": "tsc --build",
|
||||
"compile": "tsc --build && pnpm run lint --fix && rimraf dist bin/nodes && pnpm run bundle && shx cp -r node-gyp-bin dist/node-gyp-bin && shx cp -r node_modules/@pnpm/tabtab/lib/templates dist/templates && shx cp -r node_modules/ps-list/vendor dist/vendor && shx cp pnpmrc dist/pnpmrc"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
node_modules/
|
||||
dist/
|
||||
.pnpm-store/
|
||||
.pnpm-home/
|
||||
.corepack-home/
|
||||
.git/
|
||||
.gitignore
|
||||
.env
|
||||
*.log
|
||||
@@ -24,8 +24,37 @@ server {
|
||||
add_header Expires "0";
|
||||
}
|
||||
|
||||
# Bridge-Endpunkte (Agent-zu-Backend): separater Pfad ohne CSP-Einschränkungen
|
||||
# für Gateway-Calls. Kein Caching, kein Buffering.
|
||||
location /api/bridge/ {
|
||||
proxy_pass http://api:8080;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header X-Agent-Id $http_x_agent_id;
|
||||
proxy_buffering off;
|
||||
proxy_read_timeout 120s;
|
||||
}
|
||||
|
||||
# Dashboard SSE stream: single dedicated non-buffered block.
|
||||
location = /api/dashboard/live {
|
||||
proxy_pass http://api:8080;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Connection "";
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_buffering off;
|
||||
proxy_cache off;
|
||||
proxy_read_timeout 1h;
|
||||
proxy_send_timeout 1h;
|
||||
add_header Cache-Control "no-cache, no-store, must-revalidate" always;
|
||||
add_header X-Accel-Buffering no always;
|
||||
}
|
||||
|
||||
location /api/ {
|
||||
proxy_pass http://api:8080;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
|
||||
@@ -23,7 +23,7 @@ const activeView = computed(() => {
|
||||
const routePaths: Record<string, string> = {
|
||||
Dashboard: '/dashboard', Memory: '/memory', Docs: '/docs', Security: '/security',
|
||||
Projects: '/projects', 'Task Board': '/tasks', Incidents: '/incidents', Calendar: '/calendar',
|
||||
Agents: '/agents', Models: '/models', Activity: '/activity', 'Mobile Chat': '/chat', Settings: '/settings',
|
||||
Agents: '/agents', Models: '/models', Activity: '/activity', 'Mobile Chat': '/chat', Notifications: '/notifications', Settings: '/settings',
|
||||
}
|
||||
|
||||
const navigate = (label: string) => {
|
||||
@@ -32,7 +32,11 @@ const navigate = (label: string) => {
|
||||
}
|
||||
const mobileNavOpen = ref(false)
|
||||
|
||||
const standaloneViews = computed(() => ['Dashboard', 'Settings', 'ProjectDetail', 'Memory', 'Docs', 'Security', 'Incidents', 'Calendar', 'AgentDetail', 'Agents'].includes(activeView.value))
|
||||
const standaloneViews = computed(() => {
|
||||
if (route.name === 'Dashboard') return true
|
||||
if (route.meta?.standalone) return true
|
||||
return false
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
if (auth.isAuthenticated) store.refresh()
|
||||
|
||||
@@ -87,6 +87,12 @@ const statusColors: Record<string, string> = {
|
||||
idle: 'var(--st-idle)',
|
||||
block: 'var(--st-block)',
|
||||
}
|
||||
|
||||
function avatarLabel() {
|
||||
if (props.agent.id === 'iris') return 'IR'
|
||||
if (props.agent.name === 'Full-Stack Developer') return '</>'
|
||||
return props.agent.name.slice(0, 2).toUpperCase()
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -99,7 +105,7 @@ const statusColors: Record<string, string> = {
|
||||
<!-- Header -->
|
||||
<div class="m-head">
|
||||
<div :class="['m-av', { iris: agent.id === 'iris' }]">
|
||||
{{ agent.id === 'iris' ? 'IR' : agent.name.slice(0, 2).toUpperCase() }}
|
||||
{{ avatarLabel() }}
|
||||
</div>
|
||||
<div style="flex:1; min-width:0">
|
||||
<div class="m-name">{{ agent.name }}</div>
|
||||
@@ -160,6 +166,16 @@ const statusColors: Record<string, string> = {
|
||||
<div class="m-think">{{ thinkDisplay }}<span class="caret"></span></div>
|
||||
</div>
|
||||
|
||||
<div v-if="agent.activity.length" class="m-sec">
|
||||
<h4>Agent Activity</h4>
|
||||
<div class="m-activity">
|
||||
<div v-for="(entry, index) in agent.activity" :key="index" class="m-activity-row">
|
||||
<span class="m-activity-time">{{ entry.time }}</span>
|
||||
<span class="m-activity-text">{{ entry.text }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Modell wählen -->
|
||||
<div class="m-sec">
|
||||
<h4>Modell wählen</h4>
|
||||
@@ -519,6 +535,35 @@ const statusColors: Record<string, string> = {
|
||||
|
||||
@keyframes blink { 50% { opacity: 0; } }
|
||||
|
||||
.m-activity {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.m-activity-row {
|
||||
display: grid;
|
||||
grid-template-columns: 72px 1fr;
|
||||
gap: 10px;
|
||||
align-items: start;
|
||||
padding: 10px 12px;
|
||||
border-radius: 12px;
|
||||
background: rgba(124,108,255,.06);
|
||||
border: 1px solid var(--line);
|
||||
}
|
||||
|
||||
.m-activity-time {
|
||||
font-family: 'JetBrains Mono', monospace;
|
||||
font-size: 10px;
|
||||
color: var(--tx-3);
|
||||
}
|
||||
|
||||
.m-activity-text {
|
||||
font-size: 12px;
|
||||
line-height: 1.45;
|
||||
color: var(--tx-2);
|
||||
}
|
||||
|
||||
/* ── Models ──────────────────────────────────── */
|
||||
.m-models {
|
||||
display: flex;
|
||||
|
||||
@@ -33,7 +33,11 @@ defineEmits<{
|
||||
{ entering }
|
||||
]"
|
||||
:style="{ left: left + '%', top: top + '%' }"
|
||||
@click="$emit('select', agent.id)"
|
||||
tabindex="0"
|
||||
role="button"
|
||||
:aria-label="`${agent.name} öffnen`"
|
||||
@keydown.enter.prevent="$emit('select', agent.id)"
|
||||
@keydown.space.prevent="$emit('select', agent.id)"
|
||||
>
|
||||
<div class="ncard">
|
||||
<!-- Header: Avatar + Name + Role + Status-Dot -->
|
||||
|
||||
@@ -19,6 +19,7 @@ defineProps<{
|
||||
blockerCount: number
|
||||
todayCost: string
|
||||
todayTokens: string
|
||||
blockerLabel?: string
|
||||
}>()
|
||||
|
||||
defineEmits<{
|
||||
@@ -62,7 +63,7 @@ defineEmits<{
|
||||
@click="$emit('blockerClick')"
|
||||
>
|
||||
<span class="dot block"></span>
|
||||
{{ blockerCount }} Blocker
|
||||
{{ blockerLabel || `${blockerCount} Blocker` }}
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
@@ -168,4 +169,24 @@ defineEmits<{
|
||||
.blk:hover {
|
||||
background: rgba(251,113,133,.22);
|
||||
}
|
||||
|
||||
@media (max-width: 767px) {
|
||||
.alertbar {
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.seg {
|
||||
flex: 0 0 calc(50% - 4px);
|
||||
}
|
||||
|
||||
.sep {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.blk {
|
||||
margin-left: 0;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -16,6 +16,7 @@ import type { AgentNodeData } from '../../../composables/useFlowLayout'
|
||||
import { autoLayout, buildEdges, curve } from '../../../composables/useFlowLayout'
|
||||
import { icons } from '../../../composables/icons'
|
||||
import AgentNode from './AgentNode.vue'
|
||||
import { useFlowCanvasInteractions } from './useFlowCanvasInteractions'
|
||||
|
||||
const props = defineProps<{
|
||||
agents: AgentNodeData[]
|
||||
@@ -113,8 +114,8 @@ function renderEdges() {
|
||||
} else {
|
||||
// Orchestration (Iris → Agent)
|
||||
const targetAgent = props.agents.find(a => a.id === e.b)
|
||||
const op = targetAgent && isActive(targetAgent.status) ? 0.45 : 0.18
|
||||
paths += `<path d="${d}" fill="none" stroke="#7c6cff" stroke-width="1.2" stroke-dasharray="2 6" opacity="${op}"/>`
|
||||
const op = targetAgent && isActive(targetAgent.status) ? 0.52 : 0.34
|
||||
paths += `<path d="${d}" fill="none" stroke="#8b7cff" stroke-width="1.45" stroke-dasharray="2 6" opacity="${op}"/>`
|
||||
}
|
||||
})
|
||||
|
||||
@@ -172,93 +173,19 @@ watch(
|
||||
)
|
||||
|
||||
/* ── Drag & Drop ──────────────────────────────── */
|
||||
const DRAG_THRESHOLD = 5
|
||||
|
||||
interface DragState {
|
||||
id: string
|
||||
startX: number
|
||||
startY: number
|
||||
ox: number
|
||||
oy: number
|
||||
moved: boolean
|
||||
raf: number | null
|
||||
}
|
||||
|
||||
let drag: DragState | null = null
|
||||
|
||||
function onPointerDown(e: PointerEvent) {
|
||||
const node = (e.target as HTMLElement).closest('.node') as HTMLElement | null
|
||||
if (!node) return
|
||||
|
||||
e.preventDefault()
|
||||
const nr = node.getBoundingClientRect()
|
||||
|
||||
drag = {
|
||||
id: node.dataset.id || '',
|
||||
startX: e.clientX,
|
||||
startY: e.clientY,
|
||||
ox: e.clientX - (nr.left + nr.width / 2),
|
||||
oy: e.clientY - (nr.top + nr.height / 2),
|
||||
moved: false,
|
||||
raf: null,
|
||||
}
|
||||
|
||||
node.setPointerCapture(e.pointerId)
|
||||
}
|
||||
|
||||
function onPointerMove(e: PointerEvent) {
|
||||
if (!drag) return
|
||||
|
||||
const dist = Math.hypot(e.clientX - drag.startX, e.clientY - drag.startY)
|
||||
if (!drag.moved && dist < DRAG_THRESHOLD) return
|
||||
|
||||
if (!drag.moved) {
|
||||
drag.moved = true
|
||||
const node = flowRef.value?.querySelector(`.node[data-id="${drag.id}"]`) as HTMLElement | null
|
||||
if (node) node.classList.add('dragging')
|
||||
}
|
||||
|
||||
const flow = flowRef.value
|
||||
if (!flow) return
|
||||
|
||||
const fr = flow.getBoundingClientRect()
|
||||
const x = Math.max(8, Math.min(92, ((e.clientX - drag.ox - fr.left) / fr.width) * 100))
|
||||
const y = Math.max(10, Math.min(92, ((e.clientY - drag.oy - fr.top) / fr.height) * 100))
|
||||
|
||||
// Direct DOM manipulation for responsiveness
|
||||
const node = flow.querySelector(`.node[data-id="${drag.id}"]`) as HTMLElement | null
|
||||
if (node) {
|
||||
node.style.left = x + '%'
|
||||
node.style.top = y + '%'
|
||||
}
|
||||
|
||||
// Update positions state
|
||||
const newPos = { ...props.positions }
|
||||
newPos[drag.id] = { x, y }
|
||||
emit('updatePositions', newPos)
|
||||
|
||||
// Debounced edge re-render
|
||||
if (!drag.raf) {
|
||||
drag.raf = requestAnimationFrame(() => {
|
||||
renderEdges()
|
||||
if (drag) drag.raf = null
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function onPointerUp() {
|
||||
if (!drag) return
|
||||
|
||||
const node = flowRef.value?.querySelector(`.node[data-id="${drag.id}"]`) as HTMLElement | null
|
||||
if (node) node.classList.remove('dragging')
|
||||
|
||||
if (!drag.moved) {
|
||||
// Was a click — emit select
|
||||
emit('select', drag.id)
|
||||
}
|
||||
|
||||
drag = null
|
||||
}
|
||||
const {
|
||||
onClick,
|
||||
onClickCapture,
|
||||
onPointerDown,
|
||||
onPointerMove,
|
||||
onPointerUp,
|
||||
} = useFlowCanvasInteractions({
|
||||
flowRef,
|
||||
renderEdges,
|
||||
updatePositions: positions => emit('updatePositions', positions),
|
||||
selectAgent: id => emit('select', id),
|
||||
getPositions: () => props.positions,
|
||||
})
|
||||
|
||||
/* ── Keyboard handler for Enter key on buttons ── */
|
||||
function handleReset() {
|
||||
@@ -271,6 +198,8 @@ function handleReset() {
|
||||
<div
|
||||
ref="flowRef"
|
||||
class="flow"
|
||||
@click="onClick"
|
||||
@click.capture="onClickCapture"
|
||||
@pointerdown="onPointerDown"
|
||||
@pointermove="onPointerMove"
|
||||
@pointerup="onPointerUp"
|
||||
@@ -288,12 +217,12 @@ function handleReset() {
|
||||
@click="handleReset"
|
||||
>
|
||||
<span class="btn-icon" v-html="icons.flow || ''"></span>
|
||||
Reset
|
||||
<span class="reset-label">Reset</span>
|
||||
</button>
|
||||
|
||||
<button class="add-btn" @click="emit('add')">
|
||||
<button class="add-btn" @click="emit('add')" title="Agent hinzufügen">
|
||||
<span class="btn-icon" v-html="icons.plus || ''"></span>
|
||||
Agent hinzufügen
|
||||
<span class="add-label">Agent hinzufügen</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@@ -481,4 +410,28 @@ function handleReset() {
|
||||
:deep(.node.dragging) {
|
||||
cursor: grabbing;
|
||||
}
|
||||
|
||||
@media (max-width: 767px) {
|
||||
.add-label {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.reset-label {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.add-btn {
|
||||
width: 34px;
|
||||
padding: 0;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
}
|
||||
|
||||
.reset-btn {
|
||||
width: 30px;
|
||||
padding: 0;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -251,6 +251,22 @@ watch(
|
||||
|
||||
@keyframes blink { 50% { opacity: 0; } }
|
||||
|
||||
@media (max-width: 767px) {
|
||||
.iris-panel {
|
||||
width: 100%;
|
||||
flex: 0 0 auto;
|
||||
max-height: 45vh;
|
||||
}
|
||||
|
||||
.chat-scroll {
|
||||
max-height: 30vh;
|
||||
}
|
||||
|
||||
.expand-btn {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
/* ── Input ───────────────────────────────────── */
|
||||
.chat-in {
|
||||
padding: 12px;
|
||||
|
||||
@@ -146,4 +146,20 @@ function statusLabel(s: TaskItem['status']): string {
|
||||
padding: 12px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
@media (max-width: 767px) {
|
||||
.tstrip {
|
||||
overflow-x: auto;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
scrollbar-width: none;
|
||||
}
|
||||
|
||||
.tstrip::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.tcard {
|
||||
flex: 0 0 200px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -16,6 +16,8 @@ export interface TaskItem {
|
||||
priority: 'high' | 'medium' | 'low'
|
||||
status: 'active' | 'pending' | 'blocked'
|
||||
progress: number // 0–100
|
||||
detail?: string | null
|
||||
source?: string
|
||||
}
|
||||
|
||||
/* ── Agent Detail Modal Types ─────────────────── */
|
||||
@@ -26,6 +28,11 @@ export interface ThinkingItem {
|
||||
ts: string
|
||||
}
|
||||
|
||||
export interface AgentActivityItem {
|
||||
time: string
|
||||
text: string
|
||||
}
|
||||
|
||||
/** Dashboard view-model for an agent detail modal */
|
||||
export interface AgentDetailData {
|
||||
id: string
|
||||
@@ -51,5 +58,6 @@ export interface AgentDetailData {
|
||||
lastActive: string
|
||||
activeTaskCount: number
|
||||
thinking: ThinkingItem[]
|
||||
activity: AgentActivityItem[]
|
||||
availableModels: { id: string; alias: string }[]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
import { ref } from 'vue'
|
||||
|
||||
const DRAG_THRESHOLD = 5
|
||||
const CLICK_SUPPRESSION_MS = 400
|
||||
|
||||
export interface FlowPosition {
|
||||
x: number
|
||||
y: number
|
||||
}
|
||||
|
||||
interface DragState {
|
||||
id: string
|
||||
startX: number
|
||||
startY: number
|
||||
ox: number
|
||||
oy: number
|
||||
moved: boolean
|
||||
raf: number | null
|
||||
}
|
||||
|
||||
interface UseFlowCanvasInteractionsOptions {
|
||||
flowRef: { value: HTMLElement | null }
|
||||
renderEdges: () => void
|
||||
updatePositions: (positions: Record<string, FlowPosition>) => void
|
||||
selectAgent: (id: string) => void
|
||||
getPositions: () => Record<string, FlowPosition>
|
||||
}
|
||||
|
||||
function findNode(target: EventTarget | null) {
|
||||
return (target as HTMLElement | null)?.closest('.node') as HTMLElement | null
|
||||
}
|
||||
|
||||
export function useFlowCanvasInteractions(options: UseFlowCanvasInteractionsOptions) {
|
||||
const drag = ref<DragState | null>(null)
|
||||
const suppressClickUntil = ref(0)
|
||||
|
||||
function onPointerDown(e: PointerEvent) {
|
||||
const node = findNode(e.target)
|
||||
if (!node) return
|
||||
|
||||
e.preventDefault()
|
||||
const nr = node.getBoundingClientRect()
|
||||
|
||||
drag.value = {
|
||||
id: node.dataset.id || '',
|
||||
startX: e.clientX,
|
||||
startY: e.clientY,
|
||||
ox: e.clientX - (nr.left + nr.width / 2),
|
||||
oy: e.clientY - (nr.top + nr.height / 2),
|
||||
moved: false,
|
||||
raf: null,
|
||||
}
|
||||
|
||||
node.setPointerCapture(e.pointerId)
|
||||
}
|
||||
|
||||
function onPointerMove(e: PointerEvent) {
|
||||
if (!drag.value) return
|
||||
|
||||
const currentDrag = drag.value
|
||||
const dist = Math.hypot(e.clientX - currentDrag.startX, e.clientY - currentDrag.startY)
|
||||
if (!currentDrag.moved && dist < DRAG_THRESHOLD) return
|
||||
|
||||
if (!currentDrag.moved) {
|
||||
currentDrag.moved = true
|
||||
const node = options.flowRef.value?.querySelector(`.node[data-id="${currentDrag.id}"]`) as HTMLElement | null
|
||||
if (node) node.classList.add('dragging')
|
||||
}
|
||||
|
||||
const flow = options.flowRef.value
|
||||
if (!flow) return
|
||||
|
||||
const fr = flow.getBoundingClientRect()
|
||||
const x = Math.max(8, Math.min(92, ((e.clientX - currentDrag.ox - fr.left) / fr.width) * 100))
|
||||
const y = Math.max(10, Math.min(92, ((e.clientY - currentDrag.oy - fr.top) / fr.height) * 100))
|
||||
|
||||
const node = flow.querySelector(`.node[data-id="${currentDrag.id}"]`) as HTMLElement | null
|
||||
if (node) {
|
||||
node.style.left = x + '%'
|
||||
node.style.top = y + '%'
|
||||
}
|
||||
|
||||
options.updatePositions({
|
||||
...options.getPositions(),
|
||||
[currentDrag.id]: { x, y },
|
||||
})
|
||||
|
||||
if (!currentDrag.raf) {
|
||||
currentDrag.raf = requestAnimationFrame(() => {
|
||||
options.renderEdges()
|
||||
if (drag.value) drag.value.raf = null
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function onPointerUp(e: PointerEvent) {
|
||||
if (!drag.value) return
|
||||
|
||||
const currentDrag = drag.value
|
||||
const endDistance = Math.hypot(e.clientX - currentDrag.startX, e.clientY - currentDrag.startY)
|
||||
const wasDragged = currentDrag.moved || endDistance >= DRAG_THRESHOLD
|
||||
const node = options.flowRef.value?.querySelector(`.node[data-id="${currentDrag.id}"]`) as HTMLElement | null
|
||||
if (node) node.classList.remove('dragging')
|
||||
|
||||
if (wasDragged) {
|
||||
suppressClickUntil.value = performance.now() + CLICK_SUPPRESSION_MS
|
||||
}
|
||||
|
||||
drag.value = null
|
||||
}
|
||||
|
||||
function onClick(e: MouseEvent) {
|
||||
const node = findNode(e.target)
|
||||
if (!node) return
|
||||
if (performance.now() < suppressClickUntil.value) return
|
||||
|
||||
const id = node.dataset.id
|
||||
if (id) options.selectAgent(id)
|
||||
}
|
||||
|
||||
function onClickCapture(e: MouseEvent) {
|
||||
if (performance.now() >= suppressClickUntil.value) return
|
||||
if (!findNode(e.target)) return
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
}
|
||||
|
||||
return {
|
||||
onClick,
|
||||
onClickCapture,
|
||||
onPointerDown,
|
||||
onPointerMove,
|
||||
onPointerUp,
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,14 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { computed, onMounted } from 'vue'
|
||||
import {
|
||||
Activity, Bot, Boxes, Command, FileText,
|
||||
Activity, Bell, Bot, Boxes, Command, FileText,
|
||||
LayoutDashboard, ListTodo, LogOut, MessageSquareText, Settings,
|
||||
Shield, SlidersHorizontal, Sparkles, BookOpen,
|
||||
AlertTriangle, Calendar,
|
||||
} from '@lucide/vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useAuthStore } from '../../stores/auth'
|
||||
import { useNotificationStore } from '../../stores/notifications'
|
||||
import { initials } from '../../utils/format'
|
||||
|
||||
const props = defineProps<{
|
||||
@@ -23,6 +24,11 @@ const emit = defineEmits<{
|
||||
|
||||
const auth = useAuthStore()
|
||||
const router = useRouter()
|
||||
const notificationStore = useNotificationStore()
|
||||
|
||||
onMounted(() => {
|
||||
notificationStore.startPolling()
|
||||
})
|
||||
|
||||
const ownerInitials = computed(() =>
|
||||
auth.user?.displayName ? initials(auth.user.displayName) : 'OW'
|
||||
@@ -37,6 +43,7 @@ const navigation = [
|
||||
{ label: 'Task Board', icon: ListTodo },
|
||||
{ label: 'Incidents', icon: AlertTriangle },
|
||||
{ separator: true },
|
||||
{ label: 'Notifications', icon: Bell },
|
||||
{ label: 'Calendar', icon: Calendar },
|
||||
{ label: 'Agents', icon: Bot },
|
||||
{ label: 'Models', icon: SlidersHorizontal },
|
||||
@@ -76,6 +83,7 @@ async function logout() {
|
||||
<span>{{ item.label }}</span>
|
||||
<i v-if="item.label === 'Task Board'">{{ queuedTasks }}</i>
|
||||
<i v-if="item.label === 'Incidents'">{{ incidents }}</i>
|
||||
<i v-if="item.label === 'Notifications' && notificationStore.unreadCount > 0" class="badge-red">{{ notificationStore.unreadCount }}</i>
|
||||
</button>
|
||||
</template>
|
||||
</nav>
|
||||
@@ -154,6 +162,9 @@ async function logout() {
|
||||
border-radius: 5px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
.nav button i.badge-red {
|
||||
background: #e16e75;
|
||||
}
|
||||
.nav-separator {
|
||||
height: 1px;
|
||||
margin: 6px 10px;
|
||||
|
||||
@@ -6,6 +6,14 @@ import { useAgentStore } from '../../stores/agents'
|
||||
import { useTaskStore } from '../../stores/tasks'
|
||||
import { navigation, icons } from '../../composables/icons'
|
||||
import type { NavGroupDef } from '../../composables/icons'
|
||||
|
||||
defineProps<{
|
||||
mobileOpen?: boolean
|
||||
}>()
|
||||
|
||||
defineEmits<{
|
||||
close: []
|
||||
}>()
|
||||
import NavGroup from './NavGroup.vue'
|
||||
import { initials } from '../../utils/format'
|
||||
|
||||
@@ -63,7 +71,8 @@ const dynamicNavigation = computed<NavGroupDef[]>(() => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<aside class="sidebar">
|
||||
<aside :class="['sidebar', { open: mobileOpen }]">
|
||||
<button class="sidebar-close" @click="$emit('close')" v-html="icons.chevron_left || ''"></button>
|
||||
<!-- Brand -->
|
||||
<div class="side-top">
|
||||
<div class="brand-mark" v-html="icons.command || ''"></div>
|
||||
@@ -171,6 +180,54 @@ const dynamicNavigation = computed<NavGroupDef[]>(() => {
|
||||
background: rgba(124,108,255,.06);
|
||||
}
|
||||
|
||||
.sidebar-close {
|
||||
display: none;
|
||||
}
|
||||
|
||||
@media (max-width: 767px) {
|
||||
.sidebar {
|
||||
position: fixed;
|
||||
left: 0;
|
||||
top: 0;
|
||||
z-index: 100;
|
||||
height: 100vh;
|
||||
width: 280px;
|
||||
transform: translateX(-100%);
|
||||
transition: transform 0.25s ease;
|
||||
}
|
||||
|
||||
.sidebar.open {
|
||||
transform: translateX(0);
|
||||
}
|
||||
|
||||
.sidebar-close {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
position: absolute;
|
||||
top: 18px;
|
||||
right: 12px;
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
border-radius: 8px;
|
||||
border: none;
|
||||
background: transparent;
|
||||
color: var(--tx-2);
|
||||
cursor: pointer;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.sidebar-close:hover {
|
||||
background: rgba(124,108,255,.1);
|
||||
color: var(--tx);
|
||||
}
|
||||
|
||||
.sidebar-close :deep(svg) {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
}
|
||||
}
|
||||
|
||||
.avatar {
|
||||
width: 34px;
|
||||
height: 34px;
|
||||
|
||||
@@ -3,11 +3,19 @@ import { icons } from '../../composables/icons'
|
||||
|
||||
defineProps<{
|
||||
connected?: boolean
|
||||
statusLabel?: string
|
||||
}>()
|
||||
|
||||
defineEmits<{
|
||||
'toggle-sidebar': []
|
||||
}>()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<header class="topbar">
|
||||
<!-- Hamburger (mobile only) -->
|
||||
<button class="hamburger" @click="$emit('toggle-sidebar')" v-html="icons.list || ''"></button>
|
||||
|
||||
<!-- Search -->
|
||||
<div class="search">
|
||||
<span class="search-icon" v-html="icons.search || ''"></span>
|
||||
@@ -20,13 +28,13 @@ defineProps<{
|
||||
<!-- Status Pill -->
|
||||
<span :class="['pill', connected ? 'live' : 'preview']">
|
||||
<span class="status-dot" :class="connected ? 'on' : 'off'"></span>
|
||||
{{ connected ? 'OpenClaw verbunden' : 'Preview' }}
|
||||
{{ connected ? (statusLabel || 'OpenClaw verbunden') : 'Preview' }}
|
||||
</span>
|
||||
|
||||
<!-- Ask Iris Button -->
|
||||
<button class="btn btn-primary">
|
||||
<button class="btn btn-primary ask-iris-btn">
|
||||
<span class="btn-icon" v-html="icons.spark || ''"></span>
|
||||
Ask Iris
|
||||
<span class="ask-label">Ask Iris</span>
|
||||
</button>
|
||||
</header>
|
||||
</template>
|
||||
@@ -138,4 +146,65 @@ defineProps<{
|
||||
height: 15px;
|
||||
}
|
||||
|
||||
.hamburger {
|
||||
display: none;
|
||||
}
|
||||
|
||||
@media (max-width: 767px) {
|
||||
.topbar {
|
||||
padding: 0 14px;
|
||||
}
|
||||
|
||||
.search {
|
||||
flex: 1;
|
||||
max-width: none;
|
||||
}
|
||||
|
||||
.hamburger {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 34px;
|
||||
height: 34px;
|
||||
border-radius: 9px;
|
||||
border: none;
|
||||
background: transparent;
|
||||
color: var(--tx-2);
|
||||
cursor: pointer;
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
|
||||
.hamburger:hover {
|
||||
background: rgba(124,108,255,.1);
|
||||
color: var(--tx);
|
||||
}
|
||||
|
||||
.hamburger :deep(svg) {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
}
|
||||
|
||||
.pill {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.ask-iris-btn {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
padding: 0;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
border-radius: 9px;
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
|
||||
.ask-label {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.ask-iris-btn .btn-icon {
|
||||
display: flex;
|
||||
}
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
import { ref } from 'vue'
|
||||
import { extraAgentPool } from './useFlowLayout'
|
||||
import type { AgentNodeData } from './useFlowLayout'
|
||||
|
||||
interface FlowBoardAgentStore {
|
||||
agents: AgentNodeData[]
|
||||
models: Array<{ id: string; alias: string }>
|
||||
changeModel: (agentId: string, modelId: string) => void
|
||||
selectAgent: (id: string | null) => void
|
||||
}
|
||||
|
||||
interface FlowBoardChatStore {
|
||||
sendMessage: (text: string) => void
|
||||
}
|
||||
|
||||
const STORAGE_KEY = 'nexus-flow-positions'
|
||||
|
||||
function readStoredPositions() {
|
||||
if (typeof window === 'undefined') return {}
|
||||
try {
|
||||
const raw = window.localStorage.getItem(STORAGE_KEY)
|
||||
return raw ? JSON.parse(raw) as Record<string, { x: number; y: number }> : {}
|
||||
} catch {
|
||||
return {}
|
||||
}
|
||||
}
|
||||
|
||||
export function useFlowBoardState(agentStore: FlowBoardAgentStore, chatStore: FlowBoardChatStore) {
|
||||
const agentPositions = ref<Record<string, { x: number; y: number }>>(readStoredPositions())
|
||||
const enteringIds = ref<string[]>([])
|
||||
const localAgentPool = ref<AgentNodeData[]>([...extraAgentPool])
|
||||
|
||||
function selectAgent(id: string) {
|
||||
agentStore.selectAgent(id)
|
||||
}
|
||||
|
||||
function closeAgent() {
|
||||
agentStore.selectAgent(null)
|
||||
}
|
||||
|
||||
function changeModel(agentId: string, modelAlias: string) {
|
||||
const model = agentStore.models.find(m => m.alias === modelAlias)
|
||||
const modelId = model?.id ?? modelAlias
|
||||
agentStore.changeModel(agentId, modelId)
|
||||
}
|
||||
|
||||
function addAgent() {
|
||||
const next = localAgentPool.value.shift()
|
||||
if (!next) return
|
||||
|
||||
enteringIds.value = [...enteringIds.value, next.id]
|
||||
agentStore.agents.push(next)
|
||||
|
||||
window.setTimeout(() => {
|
||||
enteringIds.value = enteringIds.value.filter(id => id !== next.id)
|
||||
}, 600)
|
||||
}
|
||||
|
||||
function resetLayout() {
|
||||
agentPositions.value = {}
|
||||
if (typeof window !== 'undefined') window.localStorage.removeItem(STORAGE_KEY)
|
||||
}
|
||||
|
||||
function updatePositions(positions: Record<string, { x: number; y: number }>) {
|
||||
agentPositions.value = { ...positions }
|
||||
if (typeof window !== 'undefined') {
|
||||
window.localStorage.setItem(STORAGE_KEY, JSON.stringify(agentPositions.value))
|
||||
}
|
||||
}
|
||||
|
||||
function sendChatMessage(text: string) {
|
||||
chatStore.sendMessage(text)
|
||||
}
|
||||
|
||||
return {
|
||||
addAgent,
|
||||
agentPositions,
|
||||
changeModel,
|
||||
closeAgent,
|
||||
enteringIds,
|
||||
resetLayout,
|
||||
selectAgent,
|
||||
sendChatMessage,
|
||||
updatePositions,
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,24 @@
|
||||
import type { AgentNodeData } from '../types/agentNode'
|
||||
|
||||
export const TASK_AGENT_OPTIONS = [
|
||||
{ id: '', label: 'Nicht zugewiesen' },
|
||||
{ id: 'bao', label: '👤 Bao' },
|
||||
{ id: 'iris', label: '🤖 Iris' },
|
||||
{ id: 'product-owner', label: '📋 Product Owner' },
|
||||
{ id: 'programmer', label: '🛠 Programmer' },
|
||||
{ id: 'programmer-fast', label: '⚡ Programmer Fast' },
|
||||
{ id: 'reviewer', label: '🔎 Reviewer' },
|
||||
{ id: 'architekt', label: '🏛 Architekt' },
|
||||
{ id: 'researcher', label: '🔬 Researcher' },
|
||||
{ id: 'executor', label: '🚀 Executor' },
|
||||
] as const
|
||||
|
||||
export const TASK_AGENT_LABELS: Record<string, string> = Object.fromEntries(
|
||||
TASK_AGENT_OPTIONS
|
||||
.filter(option => option.id)
|
||||
.map(option => [option.id, option.label])
|
||||
) as Record<string, string>
|
||||
|
||||
export const EXTRA_AGENT_POOL: AgentNodeData[] = [
|
||||
{
|
||||
id: 'qa',
|
||||
|
||||
@@ -3,22 +3,46 @@
|
||||
* NexusLayout — V2 Dashboard Shell
|
||||
* Flex row, 100vh, overflow hidden.
|
||||
* Sidebar (248px) + Main (flex:1, flex-column)
|
||||
* Mobile: Sidebar als Overlay mit Hamburger-Toggle
|
||||
*/
|
||||
import { ref } from 'vue'
|
||||
import { RouterView } from 'vue-router'
|
||||
import { useAgentStore } from '../stores/agents'
|
||||
import { useDashboardStore } from '../stores/dashboard'
|
||||
import GalaxyBackground from '../components/background/GalaxyBackground.vue'
|
||||
import Sidebar from '../components/layout/Sidebar.vue'
|
||||
import Topbar from '../components/layout/Topbar.vue'
|
||||
|
||||
const agentStore = useAgentStore()
|
||||
const dashboardStore = useDashboardStore()
|
||||
|
||||
/* ── Mobile Sidebar State ───────────────────────── */
|
||||
const mobileMenuOpen = ref(false)
|
||||
|
||||
function closeMobileMenu() {
|
||||
mobileMenuOpen.value = false
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="nexus-layout">
|
||||
<GalaxyBackground />
|
||||
<Sidebar />
|
||||
<Sidebar
|
||||
:mobile-open="mobileMenuOpen"
|
||||
@close="closeMobileMenu"
|
||||
/>
|
||||
|
||||
<!-- Mobile Backdrop -->
|
||||
<div
|
||||
v-if="mobileMenuOpen"
|
||||
class="mobile-backdrop"
|
||||
@click="closeMobileMenu"
|
||||
></div>
|
||||
|
||||
<main class="nexus-main">
|
||||
<Topbar :connected="agentStore.isConnected" />
|
||||
<Topbar
|
||||
:connected="dashboardStore.isGatewayConnected"
|
||||
:status-label="dashboardStore.irisStatusLabel"
|
||||
@toggle-sidebar="mobileMenuOpen = !mobileMenuOpen"
|
||||
/>
|
||||
<div class="nexus-content">
|
||||
<RouterView />
|
||||
</div>
|
||||
@@ -49,4 +73,22 @@ const agentStore = useAgentStore()
|
||||
overflow: hidden;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.mobile-backdrop {
|
||||
display: none;
|
||||
}
|
||||
|
||||
@media (max-width: 767px) {
|
||||
.nexus-main {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.mobile-backdrop {
|
||||
display: block;
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 99;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -17,7 +17,9 @@ interface CatalogEntry {
|
||||
|
||||
const AGENT_CATALOG: Record<string, CatalogEntry> = {
|
||||
iris: { elapsed: '--', think: null, next: 'Standby' },
|
||||
'product-owner': { elapsed: '--', think: null, next: 'Standby' },
|
||||
programmer: { elapsed: '--', think: null, next: 'Standby' },
|
||||
'programmer-fast': { elapsed: '--', think: null, next: 'Standby' },
|
||||
developer: { elapsed: '--', think: null, next: 'Standby' },
|
||||
architekt: { elapsed: '--', think: null, next: 'Standby' },
|
||||
reviewer: { elapsed: '--', think: null, next: 'Standby' },
|
||||
@@ -33,7 +35,9 @@ function resolveStatus(isActive: boolean, currentTask: string | null): AgentNode
|
||||
|
||||
function resolveAvatar(id: string, name: string): string {
|
||||
if (id === 'iris') return 'IR'
|
||||
if (id === 'product-owner') return 'PO'
|
||||
if (id === 'programmer' || id === 'developer') return '</>'
|
||||
if (id === 'programmer-fast') return 'PF'
|
||||
return name.slice(0, 2).toUpperCase()
|
||||
}
|
||||
|
||||
|
||||
+15
-10
@@ -11,6 +11,9 @@ import IncidentsView from './views/IncidentsView.vue'
|
||||
import CalendarView from './views/CalendarView.vue'
|
||||
import NexusLayout from './layouts/NexusLayout.vue'
|
||||
import FlowBoard from './views/Dashboard/FlowBoard.vue'
|
||||
import TaskBoardView from './views/TaskBoardView.vue'
|
||||
import TaskDetailView from './views/TaskDetailView.vue'
|
||||
import NotificationsView from './views/NotificationsView.vue'
|
||||
|
||||
const routes = [
|
||||
{ path: '/login', name: 'Login', component: LoginView, meta: { public: true } },
|
||||
@@ -25,20 +28,22 @@ const routes = [
|
||||
],
|
||||
},
|
||||
|
||||
{ path: '/memory', name: 'Memory', component: MemoryView },
|
||||
{ path: '/docs', name: 'Docs', component: DocsView },
|
||||
{ path: '/agents/:id', name: 'AgentDetail', component: AgentDetailView },
|
||||
{ path: '/security', name: 'Security', component: SecurityView },
|
||||
{ path: '/incidents', name: 'Incidents', component: IncidentsView },
|
||||
{ path: '/calendar', name: 'Calendar', component: CalendarView },
|
||||
{ path: '/memory', name: 'Memory', component: MemoryView, meta: { standalone: true } },
|
||||
{ path: '/docs', name: 'Docs', component: DocsView, meta: { standalone: true } },
|
||||
{ path: '/agents/:id', name: 'AgentDetail', component: AgentDetailView, meta: { standalone: true } },
|
||||
{ path: '/security', name: 'Security', component: SecurityView, meta: { standalone: true } },
|
||||
{ path: '/incidents', name: 'Incidents', component: IncidentsView, meta: { standalone: true } },
|
||||
{ path: '/calendar', name: 'Calendar', component: CalendarView, meta: { standalone: true } },
|
||||
{ path: '/projects', name: 'Projects', component: { template: '' } },
|
||||
{ path: '/projects/:id', name: 'ProjectDetail', component: ProjectDetailView },
|
||||
{ path: '/tasks', name: 'Task Board', component: { template: '' } },
|
||||
{ path: '/agents', name: 'Agents', component: AgentsIndexView },
|
||||
{ path: '/projects/:id', name: 'ProjectDetail', component: ProjectDetailView, meta: { standalone: true } },
|
||||
{ path: '/tasks', name: 'Task Board', component: TaskBoardView, meta: { standalone: true } },
|
||||
{ path: '/tasks/:id', name: 'TaskDetail', component: TaskDetailView, meta: { standalone: true } },
|
||||
{ path: '/agents', name: 'Agents', component: AgentsIndexView, meta: { standalone: true } },
|
||||
{ path: '/models', name: 'Models', component: { template: '' } },
|
||||
{ path: '/activity', name: 'Activity', component: { template: '' } },
|
||||
{ path: '/chat', name: 'Mobile Chat', component: { template: '' } },
|
||||
{ path: '/settings', name: 'Settings', component: SettingsView },
|
||||
{ path: '/notifications', name: 'Notifications', component: NotificationsView, meta: { standalone: true } },
|
||||
{ path: '/settings', name: 'Settings', component: SettingsView, meta: { standalone: true } },
|
||||
{ path: '/:pathMatch(.*)*', redirect: '/dashboard' },
|
||||
]
|
||||
|
||||
|
||||
@@ -7,6 +7,13 @@ export async function apiFetch(input: RequestInfo | URL, init: RequestInit = {})
|
||||
const send = () => {
|
||||
const headers = new Headers(init.headers)
|
||||
if (auth.accessToken) headers.set('Authorization', `Bearer ${auth.accessToken}`)
|
||||
if (auth.isIris) headers.set('X-Agent-Id', 'iris')
|
||||
else if (auth.isBao) headers.set('X-Agent-Id', 'bao')
|
||||
// Set Content-Type for JSON body requests — needed because fetch() defaults
|
||||
// to text/plain for string bodies, which ASP.NET rejects for [FromBody] binding.
|
||||
if (typeof init.body === 'string' && !headers.has('Content-Type')) {
|
||||
headers.set('Content-Type', 'application/json')
|
||||
}
|
||||
return fetch(input, { ...init, headers, credentials: 'include' })
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
import { apiFetch } from './api'
|
||||
|
||||
export type LiveEventName = 'snapshot' | 'update' | 'heartbeat'
|
||||
export type LiveMode = 'live' | 'polling'
|
||||
|
||||
export interface LiveCursorDto {
|
||||
sequence: number
|
||||
timestamp: string
|
||||
mode: LiveMode
|
||||
}
|
||||
|
||||
export interface LiveUpdateEnvelope {
|
||||
type: string
|
||||
timestamp: string
|
||||
payload: unknown
|
||||
sequence: number
|
||||
channel: string
|
||||
}
|
||||
|
||||
export interface DashboardLiveEventDto {
|
||||
envelope: LiveUpdateEnvelope
|
||||
cursor: LiveCursorDto
|
||||
}
|
||||
|
||||
export interface OpenDashboardLiveStreamResult {
|
||||
closed: Promise<void>
|
||||
}
|
||||
|
||||
export async function openDashboardLiveStream(
|
||||
onEvent: (event: LiveEventName, data: unknown) => void,
|
||||
options: { forUser?: string; notificationLimit?: number; afterSequence?: number | null; signal?: AbortSignal } = {},
|
||||
): Promise<OpenDashboardLiveStreamResult> {
|
||||
const params = new URLSearchParams({
|
||||
forUser: options.forUser ?? 'bao',
|
||||
notificationLimit: String(options.notificationLimit ?? 50),
|
||||
})
|
||||
if (typeof options.afterSequence === 'number' && Number.isFinite(options.afterSequence) && options.afterSequence > 0) {
|
||||
params.set('afterSequence', String(options.afterSequence))
|
||||
}
|
||||
|
||||
const response = await apiFetch(`/api/dashboard/live?${params}`, {
|
||||
method: 'GET',
|
||||
headers: { Accept: 'text/event-stream', 'Cache-Control': 'no-cache' },
|
||||
signal: options.signal,
|
||||
})
|
||||
|
||||
if (!response.ok || !response.body) {
|
||||
throw new Error(`Live stream unavailable: HTTP ${response.status}`)
|
||||
}
|
||||
|
||||
const reader = response.body.getReader()
|
||||
const decoder = new TextDecoder()
|
||||
let buffer = ''
|
||||
|
||||
const flushBlock = (block: string) => {
|
||||
const lines = block.split('\n')
|
||||
let eventName: LiveEventName = 'update'
|
||||
const dataLines: string[] = []
|
||||
|
||||
for (const rawLine of lines) {
|
||||
const line = rawLine.trimEnd()
|
||||
if (line.startsWith('event:')) eventName = line.slice(6).trim() as LiveEventName
|
||||
if (line.startsWith('data:')) dataLines.push(line.slice(5).trim())
|
||||
}
|
||||
|
||||
if (!dataLines.length) return
|
||||
try {
|
||||
onEvent(eventName, JSON.parse(dataLines.join('\n')))
|
||||
} catch (error) {
|
||||
console.warn('[live] failed to parse event payload', error)
|
||||
}
|
||||
}
|
||||
|
||||
const closed = (async () => {
|
||||
while (true) {
|
||||
const { value, done } = await reader.read()
|
||||
if (done) break
|
||||
|
||||
buffer += decoder.decode(value, { stream: true })
|
||||
const parts = buffer.split('\n\n')
|
||||
buffer = parts.pop() ?? ''
|
||||
for (const part of parts) {
|
||||
if (part.trim()) flushBlock(part)
|
||||
}
|
||||
}
|
||||
|
||||
if (buffer.trim()) {
|
||||
flushBlock(buffer)
|
||||
buffer = ''
|
||||
}
|
||||
})()
|
||||
|
||||
return { closed }
|
||||
}
|
||||
@@ -11,7 +11,7 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { apiFetch } from '../services/api'
|
||||
import type { AgentNodeData } from '../composables/useFlowLayout'
|
||||
import type { AgentDetailData, ThinkingItem } from '../components/dashboard/v2/types'
|
||||
import type { AgentActivityItem, AgentDetailData, ThinkingItem } from '../components/dashboard/v2/types'
|
||||
|
||||
/* ── API Response Shapes ──────────────────────────── */
|
||||
|
||||
@@ -40,6 +40,11 @@ interface ModelOption {
|
||||
provider: string
|
||||
}
|
||||
|
||||
interface AgentActivityEntry {
|
||||
time: string
|
||||
text: string
|
||||
}
|
||||
|
||||
/* ── Status Mapping ───────────────────────────────── */
|
||||
|
||||
function mapStatus(isActive: boolean, currentTask: string | null): AgentNodeData['status'] {
|
||||
@@ -148,6 +153,7 @@ export function buildAgentDetail(data: AgentNodeData, models: { id: string; alia
|
||||
lastActive: data.elapsed !== '—' ? 'Vor ' + data.elapsed : 'Nicht aktiv',
|
||||
activeTaskCount: data.task ? 1 : 0,
|
||||
thinking: buildThinkingItems(data),
|
||||
activity: [],
|
||||
availableModels: models,
|
||||
}
|
||||
}
|
||||
@@ -159,6 +165,7 @@ export const useAgentStore = defineStore('agents', {
|
||||
loading: false,
|
||||
error: null as string | null,
|
||||
selectedAgentId: null as string | null,
|
||||
activityByAgentId: {} as Record<string, AgentActivityItem[]>,
|
||||
refreshInterval: null as ReturnType<typeof setInterval> | null,
|
||||
isConnected: false,
|
||||
}),
|
||||
@@ -179,7 +186,10 @@ export const useAgentStore = defineStore('agents', {
|
||||
if (!state.selectedAgentId) return null
|
||||
const data = state.agents.find(a => a.id === state.selectedAgentId)
|
||||
if (!data) return null
|
||||
return buildAgentDetail(data, state.models)
|
||||
return {
|
||||
...buildAgentDetail(data, state.models),
|
||||
activity: state.activityByAgentId[data.id] ?? [],
|
||||
}
|
||||
},
|
||||
|
||||
/** Is the modal open? */
|
||||
@@ -249,9 +259,24 @@ export const useAgentStore = defineStore('agents', {
|
||||
}
|
||||
},
|
||||
|
||||
async fetchAgentActivity(agentId: string) {
|
||||
try {
|
||||
const res = await apiFetch(`/api/dashboard/agents/${encodeURIComponent(agentId)}/activity?limit=5`)
|
||||
if (!res.ok) return
|
||||
const data: AgentActivityEntry[] = await res.json()
|
||||
this.activityByAgentId[agentId] = data.map(entry => ({
|
||||
time: entry.time,
|
||||
text: entry.text,
|
||||
}))
|
||||
} catch (err) {
|
||||
console.warn('[AgentStore] fetchAgentActivity failed', err)
|
||||
}
|
||||
},
|
||||
|
||||
/* ── Selection ───────────────────────────────── */
|
||||
selectAgent(id: string | null) {
|
||||
this.selectedAgentId = id
|
||||
if (id) void this.fetchAgentActivity(id)
|
||||
},
|
||||
|
||||
/* ── Polling ─────────────────────────────────── */
|
||||
|
||||
@@ -13,6 +13,12 @@ interface AuthPayload {
|
||||
user: AuthUser
|
||||
}
|
||||
|
||||
interface LoginErrorInfo {
|
||||
message: string
|
||||
remaining: number
|
||||
retryAfterSeconds: number
|
||||
}
|
||||
|
||||
let refreshInFlight: Promise<boolean> | null = null
|
||||
|
||||
export const useAuthStore = defineStore('auth', {
|
||||
@@ -22,28 +28,51 @@ export const useAuthStore = defineStore('auth', {
|
||||
user: null as AuthUser | null,
|
||||
initialized: false,
|
||||
loading: false,
|
||||
/** Remaining login attempts in the current window (null = unknown) */
|
||||
remainingAttempts: null as number | null,
|
||||
/** Seconds until rate-limit reset (0 = not rate-limited) */
|
||||
retryAfterSeconds: 0,
|
||||
}),
|
||||
getters: {
|
||||
isAuthenticated: state => Boolean(state.accessToken && state.user),
|
||||
isRateLimited: state => state.remainingAttempts === 0 && state.retryAfterSeconds > 0,
|
||||
/** Returns true if the current web-ui user is Iris (JWT user identity matches "iris"). */
|
||||
isIris: state => {
|
||||
if (!state.user) return false
|
||||
const lower = state.user.email.toLowerCase()
|
||||
return lower.includes('iris') || state.user.displayName.toLowerCase().includes('iris')
|
||||
},
|
||||
/** Returns true if the current web-ui user is Bao (JWT user identity matches "bao"). */
|
||||
isBao: state => {
|
||||
if (!state.user) return false
|
||||
const lower = state.user.email.toLowerCase()
|
||||
return lower.includes('bao') || state.user.displayName.toLowerCase().includes('bao')
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
applySession(payload: AuthPayload) {
|
||||
this.accessToken = payload.accessToken
|
||||
this.expiresAt = payload.expiresAt
|
||||
this.user = payload.user
|
||||
this.remainingAttempts = null
|
||||
this.retryAfterSeconds = 0
|
||||
},
|
||||
clearSession() {
|
||||
this.accessToken = null
|
||||
this.expiresAt = null
|
||||
this.user = null
|
||||
this.remainingAttempts = null
|
||||
this.retryAfterSeconds = 0
|
||||
},
|
||||
async initialize() {
|
||||
if (this.initialized) return this.isAuthenticated
|
||||
this.initialized = true
|
||||
return this.refresh()
|
||||
},
|
||||
async login(email: string, password: string) {
|
||||
async login(email: string, password: string): Promise<void> {
|
||||
this.loading = true
|
||||
this.remainingAttempts = null
|
||||
this.retryAfterSeconds = 0
|
||||
try {
|
||||
const response = await fetch('/api/v1/auth/login', {
|
||||
method: 'POST',
|
||||
@@ -52,9 +81,50 @@ export const useAuthStore = defineStore('auth', {
|
||||
body: JSON.stringify({ email, password }),
|
||||
})
|
||||
|
||||
// Try to parse remaining from headers
|
||||
const remainingHeader = response.headers.get('X-RateLimit-Remaining')
|
||||
if (remainingHeader !== null) {
|
||||
this.remainingAttempts = parseInt(remainingHeader, 10)
|
||||
}
|
||||
|
||||
const resetHeader = response.headers.get('X-RateLimit-Reset')
|
||||
if (resetHeader !== null) {
|
||||
const resetTs = parseInt(resetHeader, 10) * 1000
|
||||
this.retryAfterSeconds = Math.max(0, Math.ceil((resetTs - Date.now()) / 1000))
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
if (response.status === 429) throw new Error('Too many attempts. Please wait one minute.')
|
||||
throw new Error('Invalid email or password.')
|
||||
// Try to parse structured JSON body for rate-limit info
|
||||
let remaining = this.remainingAttempts
|
||||
let retryAfter = this.retryAfterSeconds
|
||||
|
||||
try {
|
||||
const body = await response.json() as Record<string, unknown>
|
||||
if (typeof body.remaining === 'number') remaining = body.remaining
|
||||
if (typeof body.retryAfterSeconds === 'number') retryAfter = body.retryAfterSeconds
|
||||
|
||||
if (response.status === 429) {
|
||||
this.remainingAttempts = 0
|
||||
this.retryAfterSeconds = retryAfter
|
||||
throw new LoginError(body.message as string || 'Too many attempts.', 0, retryAfter)
|
||||
} else if (response.status === 401) {
|
||||
this.remainingAttempts = remaining
|
||||
this.retryAfterSeconds = retryAfter
|
||||
throw new LoginError(body.message as string || 'Invalid email or password.', remaining, retryAfter)
|
||||
}
|
||||
} catch (error) {
|
||||
if (error instanceof LoginError) throw error
|
||||
// Fallback for non-JSON error responses
|
||||
}
|
||||
|
||||
if (response.status === 429) {
|
||||
this.remainingAttempts = 0
|
||||
const retryAfterSec = this.retryAfterSeconds || 60
|
||||
this.retryAfterSeconds = retryAfterSec
|
||||
throw new LoginError('Too many attempts. Please wait.', 0, retryAfterSec)
|
||||
}
|
||||
|
||||
throw new LoginError('Invalid email or password.', this.remainingAttempts ?? 4, this.retryAfterSeconds)
|
||||
}
|
||||
|
||||
this.applySession(await response.json() as AuthPayload)
|
||||
@@ -101,3 +171,16 @@ export const useAuthStore = defineStore('auth', {
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
/** Custom error carrying rate-limit metadata. */
|
||||
class LoginError extends Error {
|
||||
remaining: number
|
||||
retryAfterSeconds: number
|
||||
|
||||
constructor(message: string, remaining: number, retryAfterSeconds: number) {
|
||||
super(message)
|
||||
this.name = 'LoginError'
|
||||
this.remaining = remaining
|
||||
this.retryAfterSeconds = retryAfterSeconds
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { apiFetch } from '../services/api'
|
||||
|
||||
interface DashboardStatusDto {
|
||||
gatewayOk: boolean
|
||||
irisStatus: string
|
||||
activeAgents: number
|
||||
pendingTasks: number
|
||||
}
|
||||
|
||||
interface FeedEntryDto {
|
||||
agent: string
|
||||
action: string
|
||||
timestamp: string
|
||||
time: string
|
||||
agentId?: string | null
|
||||
type?: string | null
|
||||
}
|
||||
|
||||
interface QueueItemDto {
|
||||
id: string
|
||||
name: string
|
||||
status: string
|
||||
priority: string
|
||||
source: string
|
||||
waitTime: string
|
||||
}
|
||||
|
||||
export const useDashboardStore = defineStore('dashboard', {
|
||||
state: () => ({
|
||||
status: null as DashboardStatusDto | null,
|
||||
operations: [] as FeedEntryDto[],
|
||||
queue: [] as QueueItemDto[],
|
||||
loading: false,
|
||||
error: null as string | null,
|
||||
refreshInterval: null as ReturnType<typeof setInterval> | null,
|
||||
}),
|
||||
|
||||
getters: {
|
||||
isGatewayConnected: state => state.status?.gatewayOk ?? false,
|
||||
irisStatusLabel: state => state.status?.irisStatus ?? 'Offline',
|
||||
},
|
||||
|
||||
actions: {
|
||||
async fetchStatus() {
|
||||
try {
|
||||
const res = await apiFetch('/api/dashboard/status')
|
||||
if (!res.ok) throw new Error(`HTTP ${res.status}`)
|
||||
this.status = await res.json()
|
||||
} catch (err) {
|
||||
console.warn('[DashboardStore] fetchStatus failed', err)
|
||||
this.status = null
|
||||
}
|
||||
},
|
||||
|
||||
async fetchOperations() {
|
||||
try {
|
||||
const res = await apiFetch('/api/dashboard/operations?limit=20')
|
||||
if (!res.ok) throw new Error(`HTTP ${res.status}`)
|
||||
this.operations = await res.json()
|
||||
} catch (err) {
|
||||
console.warn('[DashboardStore] fetchOperations failed', err)
|
||||
this.operations = []
|
||||
}
|
||||
},
|
||||
|
||||
async fetchQueue() {
|
||||
try {
|
||||
const res = await apiFetch('/api/dashboard/queue')
|
||||
if (!res.ok) throw new Error(`HTTP ${res.status}`)
|
||||
this.queue = await res.json()
|
||||
} catch (err) {
|
||||
console.warn('[DashboardStore] fetchQueue failed', err)
|
||||
this.queue = []
|
||||
}
|
||||
},
|
||||
|
||||
async refresh() {
|
||||
this.loading = true
|
||||
try {
|
||||
await Promise.all([
|
||||
this.fetchStatus(),
|
||||
this.fetchOperations(),
|
||||
this.fetchQueue(),
|
||||
])
|
||||
this.error = null
|
||||
} catch (err) {
|
||||
console.warn('[DashboardStore] refresh failed', err)
|
||||
this.error = 'Dashboard metadata could not be loaded'
|
||||
} finally {
|
||||
this.loading = false
|
||||
}
|
||||
},
|
||||
|
||||
startPolling() {
|
||||
if (this.refreshInterval) return
|
||||
this.refresh()
|
||||
this.refreshInterval = setInterval(() => {
|
||||
this.refresh()
|
||||
}, 30000)
|
||||
},
|
||||
|
||||
stopPolling() {
|
||||
if (this.refreshInterval) {
|
||||
clearInterval(this.refreshInterval)
|
||||
this.refreshInterval = null
|
||||
}
|
||||
},
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,172 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { openDashboardLiveStream } from '../services/live'
|
||||
import type { BoardGroup, DashboardTaskDto } from './tasks'
|
||||
import type { NotificationItem } from './notifications'
|
||||
import type { TaskItem } from '../components/dashboard/v2/types'
|
||||
import { useTaskStore } from './tasks'
|
||||
import { useNotificationStore } from './notifications'
|
||||
import type { DashboardLiveEventDto, LiveCursorDto, LiveUpdateEnvelope } from '../services/live'
|
||||
|
||||
interface NotificationSnapshotDto {
|
||||
notifications: NotificationItem[]
|
||||
unreadCount: number
|
||||
forUser: string
|
||||
}
|
||||
|
||||
interface DashboardLiveSnapshotDto {
|
||||
board: BoardGroup
|
||||
notifications: NotificationSnapshotDto
|
||||
cursor: LiveCursorDto
|
||||
}
|
||||
|
||||
function isBoardGroup(value: unknown): value is BoardGroup {
|
||||
const v = value as BoardGroup
|
||||
return !!v && Array.isArray(v.offen) && Array.isArray(v.inProgress) && Array.isArray(v.review) && Array.isArray(v.blocked) && Array.isArray(v.done)
|
||||
}
|
||||
|
||||
function mapTasks(board: BoardGroup): DashboardTaskDto[] {
|
||||
return [...board.offen, ...board.inProgress, ...board.review, ...board.blocked, ...board.done]
|
||||
}
|
||||
|
||||
function mapTaskStripItem(t: DashboardTaskDto): TaskItem {
|
||||
return {
|
||||
id: t.id,
|
||||
title: t.title,
|
||||
agent: t.assignedTo ?? '—',
|
||||
priority: (['high', 'critical', 'urgent'].includes(t.priority.toLowerCase()) ? 'high' : ['low', 'minor'].includes(t.priority.toLowerCase()) ? 'low' : 'medium') as 'high' | 'medium' | 'low',
|
||||
status: (t.state.toLowerCase() === 'blocked' ? 'blocked' : (['in progress', 'active', 'working'].includes(t.state.toLowerCase()) ? 'active' : 'pending')) as 'active' | 'blocked' | 'pending',
|
||||
progress: t.state.toLowerCase() === 'done' ? 100 : t.state.toLowerCase() === 'blocked' ? 30 : (['in progress', 'active', 'working'].includes(t.state.toLowerCase()) ? 50 : 0),
|
||||
detail: t.detail,
|
||||
source: t.source,
|
||||
}
|
||||
}
|
||||
|
||||
export const useLiveSyncStore = defineStore('liveSync', {
|
||||
state: () => ({
|
||||
connected: false,
|
||||
connecting: false,
|
||||
lastEventAt: null as string | null,
|
||||
lastHeartbeatAt: null as string | null,
|
||||
error: null as string | null,
|
||||
controller: null as AbortController | null,
|
||||
reconnectTimer: null as ReturnType<typeof setTimeout> | null,
|
||||
mode: 'polling' as 'polling' | 'live',
|
||||
lastSequence: 0,
|
||||
reconnectAttempts: 0,
|
||||
}),
|
||||
|
||||
getters: {
|
||||
liveIndicatorLabel: (state) => {
|
||||
if (state.connecting) return 'Verbinde…'
|
||||
if (state.connected) return `Live · #${state.lastSequence}`
|
||||
return state.mode === 'polling' ? 'Polling' : 'Offline'
|
||||
},
|
||||
connectionHealth: (state) => {
|
||||
if (state.connected) return 'healthy'
|
||||
if (state.connecting) return 'connecting'
|
||||
return 'degraded'
|
||||
},
|
||||
},
|
||||
|
||||
actions: {
|
||||
async connect(forUser = 'bao') {
|
||||
if (this.connecting || this.connected) return
|
||||
this.connecting = true
|
||||
this.error = null
|
||||
this.controller = new AbortController()
|
||||
|
||||
const taskStore = useTaskStore()
|
||||
const notificationStore = useNotificationStore()
|
||||
|
||||
try {
|
||||
const stream = await openDashboardLiveStream((event, data) => {
|
||||
this.lastEventAt = new Date().toISOString()
|
||||
|
||||
if (event === 'heartbeat') {
|
||||
const cursor = data as LiveCursorDto
|
||||
this.lastHeartbeatAt = cursor.timestamp
|
||||
this.lastSequence = Math.max(this.lastSequence, cursor.sequence)
|
||||
return
|
||||
}
|
||||
|
||||
if (event === 'snapshot') {
|
||||
const snapshot = data as DashboardLiveSnapshotDto
|
||||
taskStore.board = snapshot.board
|
||||
taskStore.tasks = mapTasks(snapshot.board).map(mapTaskStripItem)
|
||||
notificationStore.notifications = snapshot.notifications.notifications
|
||||
notificationStore.unreadCount = snapshot.notifications.unreadCount
|
||||
this.lastSequence = snapshot.cursor.sequence
|
||||
this.connected = true
|
||||
this.mode = 'live'
|
||||
this.reconnectAttempts = 0
|
||||
taskStore.stopBoardPolling()
|
||||
return
|
||||
}
|
||||
|
||||
const eventDto = data as DashboardLiveEventDto
|
||||
this.applyEnvelope(eventDto.envelope, forUser)
|
||||
this.lastSequence = eventDto.cursor.sequence
|
||||
this.connected = true
|
||||
this.mode = 'live'
|
||||
this.reconnectAttempts = 0
|
||||
taskStore.stopBoardPolling()
|
||||
}, { forUser, signal: this.controller.signal, afterSequence: this.lastSequence || null })
|
||||
|
||||
await stream.closed
|
||||
} catch (error) {
|
||||
if (this.controller?.signal.aborted) return
|
||||
console.warn('[liveSync] stream failed, falling back to polling', error)
|
||||
this.error = 'Live updates unavailable'
|
||||
this.connected = false
|
||||
this.mode = 'polling'
|
||||
taskStore.startBoardPolling()
|
||||
this.scheduleReconnect(forUser)
|
||||
} finally {
|
||||
this.connecting = false
|
||||
if (!this.controller?.signal.aborted && !this.connected) {
|
||||
this.mode = 'polling'
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
applyEnvelope(envelope: LiveUpdateEnvelope, forUser: string) {
|
||||
const taskStore = useTaskStore()
|
||||
const notificationStore = useNotificationStore()
|
||||
|
||||
if (envelope.type === 'tasks.board.snapshot' && isBoardGroup(envelope.payload)) {
|
||||
taskStore.board = envelope.payload
|
||||
taskStore.tasks = mapTasks(envelope.payload).map(mapTaskStripItem)
|
||||
return
|
||||
}
|
||||
|
||||
if (envelope.type === 'notifications.snapshot') {
|
||||
const snapshot = envelope.payload as NotificationSnapshotDto
|
||||
if (snapshot.forUser !== forUser) return
|
||||
notificationStore.notifications = snapshot.notifications
|
||||
notificationStore.unreadCount = snapshot.unreadCount
|
||||
}
|
||||
},
|
||||
|
||||
disconnect() {
|
||||
this.controller?.abort()
|
||||
this.controller = null
|
||||
this.connected = false
|
||||
this.connecting = false
|
||||
this.mode = 'polling'
|
||||
if (this.reconnectTimer) {
|
||||
clearTimeout(this.reconnectTimer)
|
||||
this.reconnectTimer = null
|
||||
}
|
||||
},
|
||||
|
||||
scheduleReconnect(forUser = 'bao') {
|
||||
if (this.reconnectTimer) return
|
||||
const delay = Math.min(30000, 5000 * Math.max(1, this.reconnectAttempts + 1))
|
||||
this.reconnectAttempts += 1
|
||||
this.reconnectTimer = setTimeout(() => {
|
||||
this.reconnectTimer = null
|
||||
this.connect(forUser)
|
||||
}, delay)
|
||||
},
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,172 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { openDashboardLiveStream } from '../services/live'
|
||||
import type { BoardGroup, DashboardTaskDto } from './tasks'
|
||||
import type { NotificationItem } from './notifications'
|
||||
import type { TaskItem } from '../components/dashboard/v2/types'
|
||||
import { useTaskStore } from './tasks'
|
||||
import { useNotificationStore } from './notifications'
|
||||
import type { DashboardLiveEventDto, LiveCursorDto, LiveUpdateEnvelope } from '../services/live'
|
||||
|
||||
interface NotificationSnapshotDto {
|
||||
notifications: NotificationItem[]
|
||||
unreadCount: number
|
||||
forUser: string
|
||||
}
|
||||
|
||||
interface DashboardLiveSnapshotDto {
|
||||
board: BoardGroup
|
||||
notifications: NotificationSnapshotDto
|
||||
cursor: LiveCursorDto
|
||||
}
|
||||
|
||||
function isBoardGroup(value: unknown): value is BoardGroup {
|
||||
const v = value as BoardGroup
|
||||
return !!v && Array.isArray(v.offen) && Array.isArray(v.inProgress) && Array.isArray(v.review) && Array.isArray(v.blocked) && Array.isArray(v.done)
|
||||
}
|
||||
|
||||
function mapTasks(board: BoardGroup): DashboardTaskDto[] {
|
||||
return [...board.offen, ...board.inProgress, ...board.review, ...board.blocked, ...board.done]
|
||||
}
|
||||
|
||||
function mapTaskStripItem(t: DashboardTaskDto): TaskItem {
|
||||
return {
|
||||
id: t.id,
|
||||
title: t.title,
|
||||
agent: t.assignedTo ?? '—',
|
||||
priority: (['high', 'critical', 'urgent'].includes(t.priority.toLowerCase()) ? 'high' : ['low', 'minor'].includes(t.priority.toLowerCase()) ? 'low' : 'medium') as 'high' | 'medium' | 'low',
|
||||
status: (t.state.toLowerCase() === 'blocked' ? 'blocked' : (['in progress', 'active', 'working'].includes(t.state.toLowerCase()) ? 'active' : 'pending')) as 'active' | 'blocked' | 'pending',
|
||||
progress: t.state.toLowerCase() === 'done' ? 100 : t.state.toLowerCase() === 'blocked' ? 30 : (['in progress', 'active', 'working'].includes(t.state.toLowerCase()) ? 50 : 0),
|
||||
detail: t.detail,
|
||||
source: t.source,
|
||||
}
|
||||
}
|
||||
|
||||
export const useLiveSyncStore = defineStore('liveSync', {
|
||||
state: () => ({
|
||||
connected: false,
|
||||
connecting: false,
|
||||
lastEventAt: null as string | null,
|
||||
lastHeartbeatAt: null as string | null,
|
||||
error: null as string | null,
|
||||
controller: null as AbortController | null,
|
||||
reconnectTimer: null as ReturnType<typeof setTimeout> | null,
|
||||
mode: 'polling' as 'polling' | 'live',
|
||||
lastSequence: 0,
|
||||
reconnectAttempts: 0,
|
||||
}),
|
||||
|
||||
getters: {
|
||||
liveIndicatorLabel: (state) => {
|
||||
if (state.connecting) return 'Verbinde…'
|
||||
if (state.connected) return `Live · #${state.lastSequence}`
|
||||
return state.mode === 'polling' ? 'Polling' : 'Offline'
|
||||
},
|
||||
connectionHealth: (state) => {
|
||||
if (state.connected) return 'healthy'
|
||||
if (state.connecting) return 'connecting'
|
||||
return 'degraded'
|
||||
},
|
||||
},
|
||||
|
||||
actions: {
|
||||
async connect(forUser = 'bao') {
|
||||
if (this.connecting || this.connected) return
|
||||
this.connecting = true
|
||||
this.error = null
|
||||
this.controller = new AbortController()
|
||||
|
||||
const taskStore = useTaskStore()
|
||||
const notificationStore = useNotificationStore()
|
||||
|
||||
try {
|
||||
const stream = await openDashboardLiveStream((event, data) => {
|
||||
this.lastEventAt = new Date().toISOString()
|
||||
|
||||
if (event === 'heartbeat') {
|
||||
const cursor = data as LiveCursorDto
|
||||
this.lastHeartbeatAt = cursor.timestamp
|
||||
this.lastSequence = Math.max(this.lastSequence, cursor.sequence)
|
||||
return
|
||||
}
|
||||
|
||||
if (event === 'snapshot') {
|
||||
const snapshot = data as DashboardLiveSnapshotDto
|
||||
taskStore.board = snapshot.board
|
||||
taskStore.tasks = mapTasks(snapshot.board).map(mapTaskStripItem)
|
||||
notificationStore.notifications = snapshot.notifications.notifications
|
||||
notificationStore.unreadCount = snapshot.notifications.unreadCount
|
||||
this.lastSequence = snapshot.cursor.sequence
|
||||
this.connected = true
|
||||
this.mode = 'live'
|
||||
this.reconnectAttempts = 0
|
||||
taskStore.stopBoardPolling()
|
||||
return
|
||||
}
|
||||
|
||||
const eventDto = data as DashboardLiveEventDto
|
||||
this.applyEnvelope(eventDto.envelope, forUser)
|
||||
this.lastSequence = eventDto.cursor.sequence
|
||||
this.connected = true
|
||||
this.mode = 'live'
|
||||
this.reconnectAttempts = 0
|
||||
taskStore.stopBoardPolling()
|
||||
}, { forUser, signal: this.controller.signal, afterSequence: this.lastSequence || null })
|
||||
|
||||
await stream.closed
|
||||
} catch (error) {
|
||||
if (this.controller?.signal.aborted) return
|
||||
console.warn('[liveSync] stream failed, falling back to polling', error)
|
||||
this.error = 'Live updates unavailable'
|
||||
this.connected = false
|
||||
this.mode = 'polling'
|
||||
taskStore.startBoardPolling()
|
||||
this.scheduleReconnect(forUser)
|
||||
} finally {
|
||||
this.connecting = false
|
||||
if (!this.controller?.signal.aborted && !this.connected) {
|
||||
this.mode = 'polling'
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
applyEnvelope(envelope: LiveUpdateEnvelope, forUser: string) {
|
||||
const taskStore = useTaskStore()
|
||||
const notificationStore = useNotificationStore()
|
||||
|
||||
if (envelope.type === 'tasks.board.snapshot' && isBoardGroup(envelope.payload)) {
|
||||
taskStore.board = envelope.payload
|
||||
taskStore.tasks = mapTasks(envelope.payload).map(mapTaskStripItem)
|
||||
return
|
||||
}
|
||||
|
||||
if (envelope.type === 'notifications.snapshot') {
|
||||
const snapshot = envelope.payload as NotificationSnapshotDto
|
||||
if (snapshot.forUser !== forUser) return
|
||||
notificationStore.notifications = snapshot.notifications
|
||||
notificationStore.unreadCount = snapshot.unreadCount
|
||||
}
|
||||
},
|
||||
|
||||
disconnect() {
|
||||
this.controller?.abort()
|
||||
this.controller = null
|
||||
this.connected = false
|
||||
this.connecting = false
|
||||
this.mode = 'polling'
|
||||
if (this.reconnectTimer) {
|
||||
clearTimeout(this.reconnectTimer)
|
||||
this.reconnectTimer = null
|
||||
}
|
||||
},
|
||||
|
||||
scheduleReconnect(forUser = 'bao') {
|
||||
if (this.reconnectTimer) return
|
||||
const delay = Math.min(30000, 5000 * Math.max(1, this.reconnectAttempts + 1))
|
||||
this.reconnectAttempts += 1
|
||||
this.reconnectTimer = setTimeout(() => {
|
||||
this.reconnectTimer = null
|
||||
this.connect(forUser)
|
||||
}, delay)
|
||||
},
|
||||
},
|
||||
})
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user