💻 システム開発

05_scale-command_分離依頼

最終更新 2026年06月24日 / 31_システム開発部/分離プロジェクト依頼書/05_scale-command_分離依頼.md

依頼書: SCALE Base から「Command Center」を独立プロジェクトに分離

新しい Claude Code セッション宛て。コピペでそのまま実行可能。完了後 Slack #system_scalebase で大串に報告。


あなたが実行すること

SCALE Base モノリス内の Command Center 機能(事業戦略の司令塔)scale-command プロジェクトに分離。
完了後 scale-base のサイドバー「Command Center」をクリックすると新プロジェクトを開く。Pipeline (/pipeline) も Command 配下なので一緒に移植する。

並行セッションでの開発は無いので落ち着いて作業 OK。


SCALE Base 全体情報

項目 内容
scale-base ローカル /Users/oogushiyuuki/Library/CloudStorage/GoogleDrive-y-ogushi@scale-group.co.jp/マイドライブ/AI/scale-base/
scale-base 本番 https://scale-base.pages.dev/
Framework Next.js 15+(App Router)
デプロイ Cloudflare Pages(bash scripts/deploy.sh
共有データ Worker https://scale-task-cron.y-ogushi.workers.dev
認証 lib/auth-context.tsx の DEMO_USERS 固定

進捗チェックリスト

  • [ ] ローカル ~/Library/CloudStorage/.../AI/scale-command/ 作成
  • [ ] Next.js + Tailwind 雛形
  • [ ] scale-base 共通設定コピー
  • [ ] command + pipeline 関連コード移植
  • [ ] パスをトップレベル化
  • [ ] レイアウト + 認証
  • [ ] ローカル動作確認
  • [ ] Cloudflare Pages project scale-command 作成 + デプロイ
  • [ ] scale-base の systems.ts で command に externalUrl + 旧コード退避
  • [ ] scale-base 再デプロイ
  • [ ] Slack 完了報告

Step 1: 雛形

cd ~/Library/CloudStorage/GoogleDrive-y-ogushi@scale-group.co.jp/マイドライブ/AI/
npx create-next-app@latest scale-command --typescript --tailwind --app --src-dir=false --import-alias="@/*" --no-eslint
cd scale-command

Step 2: 共通設定コピー

SRC=~/Library/CloudStorage/GoogleDrive-y-ogushi@scale-group.co.jp/マイドライブ/AI/scale-base
cp "$SRC/tailwind.config.ts" ./
cp "$SRC/app/globals.css" ./app/globals.css
mkdir -p lib
cp "$SRC/lib/auth-context.tsx" ./lib/
cp "$SRC/lib/tasks-api.tsx" ./lib/ 2>/dev/null || true

Step 3: command + pipeline コード移植

mkdir -p app components functions/api
cp -r "$SRC/app/(dashboard)/command/." ./app/
# pipeline は command 配下として
mkdir -p ./app/pipeline
cp -r "$SRC/app/(dashboard)/pipeline/." ./app/pipeline/ 2>/dev/null || true
cp -r "$SRC/components/command" ./components/ 2>/dev/null || true
cp -r "$SRC/components/pipeline" ./components/ 2>/dev/null || true
cp "$SRC"/lib/command-*.ts ./lib/ 2>/dev/null || true
cp "$SRC"/lib/pipeline-*.ts ./lib/ 2>/dev/null || true
cp "$SRC"/functions/api/command*.ts ./functions/api/ 2>/dev/null || true
cp "$SRC"/functions/api/pipeline*.ts ./functions/api/ 2>/dev/null || true

Step 4: パスをトップレベル化

旧 /command              → 新 /
旧 /command/forecast     → 新 /forecast
旧 /command/kpis         → 新 /kpis
旧 /command/alerts       → 新 /alerts
旧 /pipeline             → 新 /pipeline (そのまま)
find ./app ./components ./lib -type f \( -name "*.tsx" -o -name "*.ts" \) -exec sed -i '' "s|'/command/|'/|g" {} \;
find ./app ./components ./lib -type f \( -name "*.tsx" -o -name "*.ts" \) -exec sed -i '' 's|"/command/|"/|g' {} \;
# command 単独のリンク(dashboard)も / に
find ./app ./components ./lib -type f \( -name "*.tsx" -o -name "*.ts" \) -exec sed -i '' "s|'/command'|'/'|g" {} \;
find ./app ./components ./lib -type f \( -name "*.tsx" -o -name "*.ts" \) -exec sed -i '' 's|"/command"|"/"|g' {} \;

Step 5: ルートレイアウト

app/layout.tsx

import './globals.css';
import { AuthProvider } from '@/lib/auth-context';

export const metadata = { title: 'SCALE Command Center' };

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="ja">
      <body className="bg-bg text-text">
        <AuthProvider>
          <header className="sticky top-0 z-30 bg-bg2 border-b border-border px-4 py-2 flex items-center justify-between">
            <a href="https://scale-base.pages.dev/home/" className="text-xs text-text2 hover:text-text">← SCALE Base に戻る</a>
            <span className="text-sm font-bold text-text">Command Center</span>
          </header>
          <main className="p-4 md:p-6">{children}</main>
        </AuthProvider>
      </body>
    </html>
  );
}

Step 6: 認証ガード(各 page 先頭)

'use client';
import { useEffect } from 'react';
import { useAuth } from '@/lib/auth-context';

export default function Page() {
  const { user, isLoading } = useAuth();
  useEffect(() => {
    if (!isLoading && !user) window.location.href = 'https://scale-base.pages.dev/';
  }, [user, isLoading]);
  // ...
}

Step 7: ローカル確認

npm run dev

Step 8: deploy.sh

mkdir -p scripts
cat > scripts/deploy.sh <<'EOF'
#!/bin/bash
set -e
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT"
TS=$(date +%Y-%m-%d_%H%M%S)
mkdir -p "$ROOT/../scale-command-backups"
tar --exclude='node_modules' --exclude='.next' --exclude='out' --exclude='.wrangler' \
  -czf "$ROOT/../scale-command-backups/scale-command_${TS}_pre-deploy.tar.gz" -C "$ROOT" .
rm -rf .next out
NODE_OPTIONS="--max-old-space-size=8192" npx next build
npx wrangler pages deploy out --project-name=scale-command --branch=main --commit-message="scale-command deploy"
tar --exclude='node_modules' --exclude='.next' --exclude='out' --exclude='.wrangler' \
  -czf "$ROOT/../scale-command-backups/scale-command_${TS}_post-deploy.tar.gz" -C "$ROOT" .
echo "✓ Deploy complete → https://scale-command.pages.dev/"
EOF
chmod +x scripts/deploy.sh

Step 9: Cloudflare Pages 作成 + デプロイ

npx wrangler pages project create scale-command --production-branch=main
bash scripts/deploy.sh

Step 10: scale-base 側更新

scale-base/lib/systems.ts の command エントリ:

{
  id: 'command',
  name: 'Command Center',
  shortName: '司令塔',
  icon: LineChart,
  color: '#c96868',
  bgColor: 'rgba(201,104,104,0.15)',
  sections: [],
  externalUrl: 'https://scale-command.pages.dev/',
},

旧コード退避:

cd ~/Library/CloudStorage/GoogleDrive-y-ogushi@scale-group.co.jp/マイドライブ/AI/scale-base
mkdir -p _archived_apps
mv "app/(dashboard)/command" "_archived_apps/command_$(date +%Y%m%d)"
mv "app/(dashboard)/pipeline" "_archived_apps/pipeline_$(date +%Y%m%d)" 2>/dev/null || true
mv "components/command" "_archived_apps/components_command_$(date +%Y%m%d)" 2>/dev/null || true
mv "components/pipeline" "_archived_apps/components_pipeline_$(date +%Y%m%d)" 2>/dev/null || true
mkdir -p _archived_apps/lib_command _archived_apps/functions_command
mv lib/command-*.ts lib/pipeline-*.ts _archived_apps/lib_command/ 2>/dev/null || true
mv functions/api/command*.ts functions/api/pipeline*.ts _archived_apps/functions_command/ 2>/dev/null || true
npx next build
bash scripts/deploy.sh

Step 11: 動作確認 + Slack 報告

#system_scalebase に:

:white_check_mark: scale-command 分離完了
URL: https://scale-command.pages.dev/ (Pipeline 内包)

重要ルール

  1. scale-base の command/pipeline 関連以外は触らない
  2. デプロイ前後にスナップショット必須

依頼者: 大串 / 最終更新: 2026-04-29