Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ bunx wrangler secret put BETTER_AUTH_SECRET --env dev

## 関連 / Related

- [worker-secret-values.md](worker-secret-values.md) — 各値の**取得方法**(どこから取るか)
- [migration-plan.md](migration-plan.md) — フェーズ定義
- [token-scopes.md](token-scopes.md) — API トークンスコープ
- `server/api/.env.example` — 鍵名とコメント
Expand Down
130 changes: 130 additions & 0 deletions .agents/skills/cloudflare-zedi/references/worker-secret-values.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# Worker secrets の値の取得方法 / How to obtain each Worker secret

`server/api/.env.worker.dev`(および `.env.worker.production`)を埋めるときの、
**各値をどこから取るか**の実務ガイド。何のための値か・ライフサイクルは
[secrets-template.md](secrets-template.md) を、鍵名の一覧は
`server/api/.env.worker.dev.example` を正とする。

> 大原則: ほとんどの値は **Railway で現在稼働中の api サービスの Variables から
> そのままコピー**する(本番と同じ値で dev Worker を動かす)。新規に発行するのは
> R2 アクセスキーと(必要なら)Sentry DSN くらい。
>
> 取得元:
>
> - **Railway**: dashboard → プロジェクト → `api` サービス → **Variables** タブ。
> 値は目のアイコンで表示、またはコピー。CLI なら `railway variables`(要ログイン)。
> - 秘密値は **Issue / PR / チャットに貼らない**。`.env.worker.dev`(gitignore 済み)にだけ書く。

---

## 必須 / Required at boot(未設定だと `wrangler deploy` が失敗する)

### BETTER_AUTH_SECRET

- **取得**: Railway `api` の `BETTER_AUTH_SECRET` をそのままコピー。
- ⚠️ API / MCP / hocuspocus と**必ず同一値**(署名鍵の共有)。新規生成しない。

### BETTER_AUTH_URL

- **取得**: dev Worker の公開 URL。
- workers.dev を使う場合: `https://zedi-api-dev.<アカウントのサブドメイン>.workers.dev`
- サブドメインは Cloudflare dashboard → **Workers & Pages** → `zedi-api-dev` を開くと
表示される URL、または **Workers & Pages → 右側の `<xxx>.workers.dev` サブドメイン**で確認。
- custom domain(`api-dev.zedi-note.app` 等)を後で使う場合はそれを設定。
- ⚠️ 認証フローの dev 検証は #1090(D1)後なので、起動時に URL としてパースできれば
暫定値で可。ただし OAuth コールバック base になるため、OAuth を実際に試すときは
この URL を Google/GitHub の redirect URI にも登録する。

### CORS_ORIGIN

- **取得**: Railway `api` の `CORS_ORIGIN` をコピー(フロント/admin のオリジン、カンマ区切り)。
- dev フロントを Pages で見る場合の例: `https://zedi-dev.pages.dev,https://zedi-admin-dev.pages.dev`
- Chrome 拡張を使うなら `chrome-extension://<id>` も含める(`chrome://extensions` で ID 確認)。

### GOOGLE_CLIENT_ID / GOOGLE_CLIENT_SECRET

- **取得(推奨)**: Railway `api` の同名変数をコピー。
- **元の発行元**: [Google Cloud Console](https://console.cloud.google.com/apis/credentials)
→ APIs & Services → **Credentials** → OAuth 2.0 Client IDs → 該当クライアント。
Secret は「Reset」しない限り再表示可(クライアント作成時のもの)。
- OAuth を dev Worker URL で試すなら、同画面の **Authorized redirect URIs** に
`<BETTER_AUTH_URL>/api/auth/callback/google` を追加。

### GITHUB_CLIENT_ID / GITHUB_CLIENT_SECRET

- **取得(推奨)**: Railway `api` の同名変数をコピー。
- **元の発行元**: GitHub → Settings → **Developer settings** → **OAuth Apps** →
該当アプリ。Client secret は再表示不可なので、無ければ「Generate a new client secret」。
- dev Worker URL で試すなら **Authorization callback URL** に
`<BETTER_AUTH_URL>/api/auth/callback/github` を追加。

### DATABASE_URL

- **取得**: #1090(D1 移行)まで **到達しないプレースホルダで可**。
例ファイルの `postgresql://placeholder:unused@127.0.0.1:5432/unused` のままで良い。
- 理由: auth.ts がモジュールロード時に pg.Pool を構築するため起動時に必須だが、
実接続は DB 依存ルートを叩くまで発生しない(遅延接続)。dev の DB 依存経路の
検証は #1090 後。
- (もし dev で実 DB に繋ぎたい場合のみ)Railway Postgres の接続文字列をコピー。

---

## 任意 / Optional(未設定なら no-op、またはその機能だけ無効)

### SENTRY_DSN_API

- **取得**: [Sentry](https://sentry.io) → 対象プロジェクト → Settings → **Client Keys (DSN)**。
または Railway `api` の同名変数をコピー。
- 空のままなら Sentry 送信は no-op(起動には影響しない)。

### STORAGE_ENDPOINT / STORAGE_ACCESS_KEY / STORAGE_SECRET_KEY / STORAGE_BUCKET_NAME

- presigned URL 生成にのみ必要(R2 の読み書きは `STORAGE_BUCKET` binding が処理)。
- **STORAGE_ENDPOINT**: `https://<CLOUDFLARE_ACCOUNT_ID>.r2.cloudflarestorage.com`
(アカウント ID = `175c04a4465bcc9815b21176a852f0c0`)。
- **STORAGE_ACCESS_KEY / STORAGE_SECRET_KEY**: R2 の S3 互換キー。
- 今回 `zedi-migration` トークン作成時に発行された **アクセスキー ID / シークレット
アクセスキー**をそのまま使える(`.env` の `CLOUDFLARE_R2_ACCESS_KEY_ID` /
`CLOUDFLARE_R2_SECRET_ACCESS_KEY`)。
- もしくは Cloudflare dashboard → **R2 → Manage R2 API Tokens** で専用トークンを発行
(MCP では発行不可)。Railway で稼働中の `STORAGE_*` は別トークン由来なので touch しない。
- **STORAGE_BUCKET_NAME**: dev は `zedi-storage-dev`(例ファイル既定)。

### RESEND_API_KEY / RESEND_FROM_EMAIL

- **取得**: [Resend](https://resend.com/api-keys) の API キー、または Railway からコピー。
- 未設定なら招待メール等のメール送信が無効になるだけ(起動には影響しない)。

### MCP_REDIRECT_URI_ALLOW / MCP_JWT_EXP_DAYS

- 外部 MCP クライアント連携を dev で使う場合のみ。Railway `api` からコピー。
- 未設定だと `/api/mcp/authorize-code` が全 redirect を拒否する(MCP 機能のみ無効)。

### OPENROUTER_API_KEY / YOUTUBE_DATA_API_KEY

- それぞれ AI モデル料金 sync / YouTube クリップ用の任意キー。Railway からコピー。

---

## 投入と確認 / Put & verify

```bash
cd server/api
bun run worker:secrets:put -- --env dev --dry-run # 埋めた項目の確認(空値はスキップされる)
bun run worker:secrets:put -- --env dev # 一括投入
bunx wrangler secret list --env dev # Worker 側に載った secret 名の確認
```

- ⚠️ `worker:secrets:put` は **空値をスキップ**する。必須 8 項目に実値が入っていないと
アップロードされず、deploy が `... must be set` で失敗する。`--dry-run` で 8 項目
(最低でも `DATABASE_URL` プレースホルダ含む)が出ることを確認する。
- ⚠️ **順序**: secrets 投入 → その後 `wrangler deploy`(deploy 時の起動検証で必須値を読む)。
- 投入後、CI の `deploy-api-worker-dev.yml` を再実行するか develop への push で dev デプロイ。

---

## 関連 / Related

- [secrets-template.md](secrets-template.md) — 全 secret のライフサイクル台帳
- [token-scopes.md](token-scopes.md) — API トークンのスコープと作成手順
- `server/api/.env.worker.dev.example` — 鍵名と必須/任意の区別
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,13 @@ jobs:
working-directory: server/api
run: bunx tsc --noEmit

# Worker バンドル検査 (#1091 FR-1.2): dry-run(資格情報不要)で
# LangGraph / @hono/node-server / @sentry/node / ioredis の不在を fail-fast。
# Credential-free Worker bundle guard (dry-run) — forbidden deps must be absent.
- name: Worker bundle check
working-directory: server/api
run: bun run worker:bundle:check

api-test:
name: API Tests
if: github.event_name != 'pull_request' || !github.event.pull_request.draft
Expand Down Expand Up @@ -316,6 +323,12 @@ jobs:
working-directory: server/api
run: bunx vitest run --coverage

# workerd 実行テスト (#1091 FR-5): Worker エントリを実ランタイムで検証。
# Worker-runtime tests on workerd via vitest-pool-workers.
- name: Run worker-runtime tests
working-directory: server/api
run: bun run test:worker

- name: Upload API coverage report
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/deploy-api-worker-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ jobs:
- name: Install dependencies
working-directory: server/api
run: bun install --frozen-lockfile
# ci.yml とは並列起動のため、デプロイ前実行を機械的に保証するのはこのステップ
# (#1091 LC-5)。dry-run のため Cloudflare 資格情報は不要。
# Runs the credential-free bundle guard right before deploy — ci.yml runs
# in parallel on the same push, so this step is the ordering guarantee.
- name: Worker bundle check
working-directory: server/api
run: bun run worker:bundle:check
- name: Deploy to Cloudflare Workers (dev)
uses: nick-fields/retry@v4
env:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# AI-DLC State Tracking

## Project Information
- **Project**: https://github.com/otomatty/zedi/issues/1091 こちらのissueに取り組んでください
- **Project Type**: Brownfield
- **Scope**: infra
- **Start Date**: 2026-07-18T02:00:49Z
- **State Version**: 7
- **Active Agent**: aidlc-operations-agent
- **Worktree Path**:
- **Bolt Refs**:
- **Practices Affirmed Timestamp**: 2026-07-18T03:56:48Z

## Scope Configuration
- **Stages to Execute**: 0.1, 0.2, 0.3, 2.2, 2.3, 3.2, 3.3, 3.4, 3.7, 4.1, 4.2, 4.3, 4.4
- **Stages to Skip**: 1.1 (intent-capture), 1.2 (market-research), 1.3 (feasibility), 1.4 (scope-definition), 1.5 (team-formation), 1.6 (rough-mockups), 1.7 (approval-handoff), 2.1 (reverse-engineering), 2.4 (user-stories), 2.5 (refined-mockups), 2.6 (application-design), 2.7 (units-generation), 2.8 (delivery-planning), 3.1 (functional-design), 3.5 (code-generation), 3.6 (build-and-test), 4.5 (incident-response), 4.6 (performance-validation), 4.7 (feedback-optimization)
- **Depth**: Standard
- **Test Strategy**: Standard

## Workspace State
- **Project Root**: C:\Users\saedg\apps\zedi

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win

Remove workstation-specific absolute paths from the tracked artifacts.

  • aidlc/spaces/default/intents/260718-api-workers-migration/aidlc-state.md#L21-L21: replace C:\Users\saedg\apps\zedi with a repository-relative path or placeholder.
  • aidlc/spaces/default/intents/260718-api-workers-migration/audit/saedgewell-353e06d8a0b4.md#L214-L214: redact the absolute Destination path.
  • aidlc/spaces/default/intents/260718-api-workers-migration/audit/saedgewell-353e06d8a0b4.md#L225-L225: redact the absolute Destination path.
  • aidlc/spaces/default/intents/260718-api-workers-migration/audit/saedgewell-353e06d8a0b4.md#L246-L246: redact the absolute --project-dir path.
  • aidlc/spaces/default/intents/260718-api-workers-migration/audit/saedgewell-353e06d8a0b4.md#L255-L255: redact the absolute --project-dir path.
  • aidlc/spaces/default/intents/260718-api-workers-migration/audit/saedgewell-353e06d8a0b4.md#L338-L338: redact the absolute Destination path.
  • aidlc/spaces/default/intents/260718-api-workers-migration/audit/saedgewell-353e06d8a0b4.md#L349-L349: redact the absolute Destination path.
  • aidlc/spaces/default/intents/260718-api-workers-migration/audit/saedgewell-353e06d8a0b4.md#L445-L445: redact the absolute Destination path.
  • aidlc/spaces/default/intents/260718-api-workers-migration/audit/saedgewell-353e06d8a0b4.md#L520-L520: redact the absolute Destination path.
  • aidlc/spaces/default/intents/260718-api-workers-migration/audit/saedgewell-353e06d8a0b4.md#L531-L531: redact the absolute Destination path.
  • aidlc/spaces/default/intents/260718-api-workers-migration/audit/saedgewell-353e06d8a0b4.md#L594-L594: redact the absolute Destination path.
  • aidlc/spaces/default/intents/260718-api-workers-migration/audit/saedgewell-353e06d8a0b4.md#L605-L605: redact the absolute Destination path.
📍 Affects 2 files
  • aidlc/spaces/default/intents/260718-api-workers-migration/aidlc-state.md#L21-L21 (this comment)
  • aidlc/spaces/default/intents/260718-api-workers-migration/audit/saedgewell-353e06d8a0b4.md#L214-L214
  • aidlc/spaces/default/intents/260718-api-workers-migration/audit/saedgewell-353e06d8a0b4.md#L225-L225
  • aidlc/spaces/default/intents/260718-api-workers-migration/audit/saedgewell-353e06d8a0b4.md#L246-L246
  • aidlc/spaces/default/intents/260718-api-workers-migration/audit/saedgewell-353e06d8a0b4.md#L255-L255
  • aidlc/spaces/default/intents/260718-api-workers-migration/audit/saedgewell-353e06d8a0b4.md#L338-L338
  • aidlc/spaces/default/intents/260718-api-workers-migration/audit/saedgewell-353e06d8a0b4.md#L349-L349
  • aidlc/spaces/default/intents/260718-api-workers-migration/audit/saedgewell-353e06d8a0b4.md#L445-L445
  • aidlc/spaces/default/intents/260718-api-workers-migration/audit/saedgewell-353e06d8a0b4.md#L520-L520
  • aidlc/spaces/default/intents/260718-api-workers-migration/audit/saedgewell-353e06d8a0b4.md#L531-L531
  • aidlc/spaces/default/intents/260718-api-workers-migration/audit/saedgewell-353e06d8a0b4.md#L594-L594
  • aidlc/spaces/default/intents/260718-api-workers-migration/audit/saedgewell-353e06d8a0b4.md#L605-L605
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@aidlc/spaces/default/intents/260718-api-workers-migration/aidlc-state.md` at
line 21, The tracked artifacts contain workstation-specific absolute paths that
must be removed. In
aidlc/spaces/default/intents/260718-api-workers-migration/aidlc-state.md:21,
replace the Project Root value with a repository-relative path or placeholder;
in
aidlc/spaces/default/intents/260718-api-workers-migration/audit/saedgewell-353e06d8a0b4.md:214,
225, 338, 349, 445, 520, 531, 594, and 605, redact each absolute Destination
path; and at lines 246 and 255, redact each absolute --project-dir path,
preserving the surrounding audit content.

- **Languages**: TypeScript
- **Frameworks**: Vite, React
- **Build System**: bun (package.json)

## Execution Plan Summary
- **Total Stages**: 13
- **Completed**: 13
- **In Progress**: none

## Runtime State
- **Revision Count**: 0

- **Skeleton Stance**: on
## Phase Progress
<!-- Status values: Pending, Active, Verified, Skipped -->

- **Initialization**: Verified
- **Ideation**: Skipped
- **Inception**: Verified
- **Construction**: Verified
- **Operation**: Verified

## Stage Progress
<!-- Checkbox states: [ ] not started, [-] in progress, [?] awaiting approval (gate open), [R] revising (user rejected gate), [x] completed, [S] skipped via --stage/--phase jump -->

### INITIALIZATION PHASE
- [x] workspace-scaffold — EXECUTE
- [x] workspace-detection — EXECUTE
- [x] state-init — EXECUTE

### IDEATION PHASE
- [ ] intent-capture — SKIP
- [ ] market-research — SKIP
- [ ] feasibility — SKIP
- [ ] scope-definition — SKIP
- [ ] team-formation — SKIP
- [ ] rough-mockups — SKIP
- [ ] approval-handoff — SKIP

### INCEPTION PHASE
- [ ] reverse-engineering — SKIP
- [x] practices-discovery — EXECUTE
- [x] requirements-analysis — EXECUTE
- [ ] user-stories — SKIP
- [ ] refined-mockups — SKIP
- [ ] application-design — SKIP
- [ ] units-generation — SKIP
- [ ] delivery-planning — SKIP

### CONSTRUCTION PHASE
Per unit: [TBD]
- [ ] functional-design — SKIP
- [x] nfr-requirements — EXECUTE
- [x] nfr-design — EXECUTE
- [x] infrastructure-design — EXECUTE
- [ ] code-generation — SKIP
- [ ] build-and-test — SKIP
- [x] ci-pipeline — EXECUTE

### OPERATION PHASE
- [x] deployment-pipeline — EXECUTE
- [x] environment-provisioning — EXECUTE
- [x] deployment-execution — EXECUTE
- [x] observability-setup — EXECUTE
- [ ] incident-response — SKIP
- [ ] performance-validation — SKIP
- [ ] feedback-optimization — SKIP

## Current Status
- **Lifecycle Phase**: OPERATION
- **Current Stage**: observability-setup
- **Next Stage**: none
- **Status**: Completed
- **Last Updated**: 2026-07-18T08:12:11Z

## Session Resume Point
- **Last Completed Stage**: observability-setup
- **Next Action**: Workflow complete
- **Pending Artifacts**: none
Loading
Loading