Imported from OneTop4458/cu12 (
AGENTS.md). Install upstream withnpx skills add OneTop4458/cu12. Copyright stays with the author.
AGENTS Playbook
Mission
Keep implementation, API contracts, workflows, and operational docs consistent for CU12 Automation.
Architecture Summary
apps/web: Next.js API + UI (Vercel)apps/worker: Playwright worker (GitHub Actions)packages/core: shared parser/typesprisma: PostgreSQL schema (Neon).github/workflows: CI/CD and ops workflows
Context Routing
Read the current sources for the task instead of loading every document:
- Product and architecture: documentation index, then the relevant living specification.
- API and data changes: route implementation, OpenAPI, and
prisma/schema.prisma. - Web UI: DESIGN.md, then the affected page and shared components.
- Operations and validation:
package.json, the relevantscripts/or.github/workflows/entry, and the linked runbook.
Keep repository-wide rules here, visual rules in DESIGN.md, and detailed rationale in docs/. Link to the authoritative rule instead of copying it into another AI instruction file. Add .agents/skills/ only for a concrete recurring workflow that existing commands and docs do not cover; do not scaffold unused AI folders. See the dated web and harness research for adoption decisions.
Task Execution and Handoffs
- State the intended behavior, scope, and verification before editing. For work spanning multiple areas or sessions, keep a focused plan in
docs/with status, decisions, remaining work, and acceptance checks; update an existing relevant plan instead of creating a duplicate. Small changes do not require a separate plan document. - When using subagents, assign non-overlapping file ownership and one integration owner. The integration owner handles session bootstrap, shared dependency/Prisma generation, final validation, and shipping. Subagents use the assigned worktree and report changed files, evidence, and unresolved issues; they do not independently rerun bootstrap or mutate the branch.
- Reproduce behavioral defects and add a regression check when appropriate. Distinguish completed checks from planned checks in the handoff, including commands and relevant UI states. Keep the required validation gate below unchanged.
Encoding Rule
- All repository files must be encoded as UTF-8 (no BOM).
- Korean copy (UI labels, errors, docs notes) must remain UTF-8; do not use ANSI/CP949/UTF-16.
- For any text corruption reports (
U+FFFD, replacement char), retype the affected strings from a clean UTF-8 source and validate before commit. - On Windows/PowerShell, avoid text-write commands with implicit encoding defaults:
- Avoid:
Set-Content/Out-Filewithout explicit UTF-8 options. - Prefer:
apply_patchwhen available, or explicit UTF-8 no-BOM APIs.
- Avoid:
- If shell-based file writes are unavoidable, explicitly force UTF-8 (no BOM):
[System.IO.File]::WriteAllText($path, $text, [System.Text.UTF8Encoding]::new($false))- Do not use
Set-Content -Encoding utf8in Windows PowerShell 5.1; it writes a BOM.
- For Korean text edits, verify immediately after edit:
- Run
pnpm run check:textandpnpm run check:text:replacements. - Re-open changed files and confirm Korean is readable (no garbled fallback glyphs).
- Run
- Never mass-rewrite files that contain Korean strings using unknown encoding pipelines.
Authentication Model
- Every login starts with real-time CU12 credential verification.
- New users must pass real-time portal credential verification. Member approval is ON by default; when an administrator disables it, new and pending users are automatically approved on their next successful portal login.
- Pending users do not receive session cookies and their portal passwords are not stored.
- After administrator approval, users must log in again to complete account linking and policy consent.
- Registration pages are not used.
Documentation Policy
- Default documentation language is English.
- Korean summary is allowed only in
README.ko.md. - Keep
docs/04-api/openapi.yamlsynchronized with route behavior.
UI Design Contract
DESIGN.mdis the source of truth for the existing web visual system, information architecture, responsive behavior, and UI change boundaries.- Read
DESIGN.mdbefore inspecting or editing files underapps/webfor a user-facing UI task. - Do not change the established page structure, information hierarchy, university branding, or responsive behavior unless the user explicitly requests that change.
- Any UI change must render the real component or page at 1440px, 1024px, 719px, and 390px. Confirm that document scroll width does not exceed body client width at each size.
- Third-party design skills are advisory and must not override
DESIGN.md. Review their instructions, scripts, hooks, dependencies, and licenses before use. - When an intentional UI change makes
DESIGN.mdinaccurate, update it in the same pull request.
Public Repository Rules
- This repository is PUBLIC. Assume every commit, PR comment, and workflow log is externally visible.
- Never commit secrets or sensitive values (passwords, tokens, cookies, private keys, internal-only credentials, real approval data).
- Never print secrets in CI logs, PR comments, or automation script output.
mainmust be updated only through pull requests. Direct push tomainis prohibited.- Every AI/operator task must start by fetching
origin/main, updating the task/session branch onto the latestorigin/main, and then working from that isolated branch. - Branch protection baseline for
main:- required status checks:
test,secret-scan - required approving reviews:
0 - required conversation resolution: disabled
- required status checks:
Execution Context Detection
- Detect the current checkout before creating any worktree:
- linked worktree:
.gitis a file - primary checkout:
.gitis a directory
- linked worktree:
- Codex desktop linked worktrees with
CODEX_THREAD_IDare the default AI execution context. - In that Codex-linked mode, the current worktree is authoritative. Do not create nested repo-local
.worktrees/session-*worktrees. - Repo-local
.worktrees/*are fallback isolation only for manual shells or non-Codex parallel work. - Session lock file (
.codex-session.lock) marks an active branch/worktree. Do not override an active lock unless--forceis intentional.
Codex Session Bootstrap
- Package manager standard is
pnpm. - If
pnpmis not on PATH yet, runcorepack enable pnpmonce on the machine. - Every Codex session must start with
pnpm run ai:start --task "<task-slug>". - In a Codex-linked worktree,
ai:startmust:- fetch latest
origin/main - rebase any reused clean
ai/*session/task branch onto the fetchedorigin/mainbefore work begins - stop immediately if the current worktree is dirty or the rebase hits conflicts
- reuse the current-worktree branch
ai/session-<session-id>while that session branch is still active - automatically roll over to
ai/<task>-<timestamp>when the session branch is already merged into the base branch - allow
--new-taskto force a freshai/<task>-<timestamp>branch before merge when unrelated work should not share the session branch - write or refresh
.codex-session.lock
- fetch latest
- In this mode,
ai:startmust not create an additional repo-local worktree. - After a session branch PR is merged, re-run
pnpm run ai:start --task "<next-task>"; merged session branches automatically roll to a fresh task branch. - Prefer a separate Codex session for unrelated work instead of nesting a worktree inside the current one.
Manual Fallback Worktree
- Use
pnpm run ai:worktree --task "<task-slug>"only when you are outside the default Codex-linked flow and need an extra local worktree. - Outside Codex-linked mode,
pnpm run ai:startmay still create or attach repo-local.worktrees/session-*worktrees. - Do not run multi-agent work directly in the primary checkout.
ai:shipmust not run frommainordevelop; use feature branches only.
Dependencies and Prisma
- Install dependencies with
pnpm install --frozen-lockfile. - Re-run
pnpm install --frozen-lockfilewhen any of the following is true:pnpm-lock.yamlchanged- the active Node version changed
- the current worktree has no usable install yet
- Otherwise, reuse the existing install for the current worktree.
- Run
pnpm run prisma:generateafter a fresh install and wheneverprisma/schema.prismaor Prisma model usage changes. - CI, deployment, and scripted validation stages must run
pnpm run prisma:generateexplicitly; do not rely on install hooks. - Required local validation commands:
corepack enable pnpm
pnpm install --frozen-lockfile
pnpm run prisma:generate
pnpm run check:text
pnpm run check:openapi
pnpm run typecheck
pnpm run test:all
pnpm run build:web
Operator Execution Rule (Including AI)
- Any code or doc change must run the validation sequence before commit/push:
pnpm run check:textpnpm run check:openapipnpm run prisma:generatewhen required by the rules above or when running in CI/fresh installspnpm run typecheckpnpm run test:allpnpm run build:web(for web scope changes)
- Do not commit or push if the above checks fail.
- For AI-assisted changes, run the validation sequence first, then commit and push in the same workflow.
AGENTS.mdis policy guidance, not a hard runtime guard. Enforced protections must live in scripts such asai:startandai:ship.
AI Auto-PR Automation
- For AI implementation tasks that produce code/doc changes, default finish line is
pnpm run ai:shipunless the user explicitly requests otherwise (no-pr,no-push, plan-only, research-only). - After implementation, run:
pnpm run ai:ship --commit "type(scope): summary" --title "type(scope): summary"
ai:shipexecutes validation, then stages, commits, pushes, and opens a PR.- Validation must include
pnpm run test:all, which covers web, worker, and ops tests.
- Validation must include
--commit/--titleare optional. When omitted,ai:shipgenerates defaults from the current branch slug.ghauthentication must be active before running automation (gh auth status).- If validation fails, fix the root cause first. Do not bypass checks to force PR creation.
- Controlled exceptions:
--noPr: push only, skip PR creation.--noPush --noPr: local commit only.
ai:shipmust refuse to commit or push when the current branch already has a merged PR into the target base branch.- On success,
ai:shipreleases the current.codex-session.lockand prints the cleanup follow-up command.
Workflow Command Notes
- PowerShell-backed repo scripts expect named arguments directly (for example
pnpm run ai:start --task "...", notpnpm run ai:start -- --task "..."). - GitHub Actions workflows that call Prisma in CI/CD must pass the schema path explicitly or use the repository wrapper scripts successfully.
- When repairing production, prefer workflow-based operations (
DB Bootstrap,Deploy Vercel, targeted cleanup workflows) over ad-hoc manual DB changes.
Session Close and Cleanup
- After PR merge or when a repo-local worktree is no longer needed, run
pnpm run ai:clean. ai:cleanis responsible for:- removing merged and clean repo-local
.worktrees/* - deleting stale
.codex-session.lockfiles - deleting merged local
ai/*branches that are no longer checked out - running
git worktree prune --expire=7.days.ago
- removing merged and clean repo-local
ai:cleanmust skip the current worktree and any path with an active lock unless--forceis explicitly supplied.- Never prune active worktrees used by a live Codex session.
Codex Review Policy
- Codex review is optional guidance for PR quality and is not a required merge gate.
- Merge readiness is determined by required checks (currently
test,secret-scan) plus branch protection rules.
Secret Leak Response Baseline
- If any key/token/password is exposed, treat it as compromised immediately.
- Rotate/revoke the credential first, then investigate usage and blast radius.
- Verify no secret values were printed in Actions logs, PR comments, or issue threads.
- After rotation, rerun CI secret scan and confirm clean status before merge/redeploy.
Deployment Baseline
- DB update:
DB Bootstraporpnpm run prisma:push - Fresh auth setup: run
Auth Reset Bootstrap - Web deploy: Vercel production deploy (
apps/web) - Worker run:
worker-consume.yml(manual/scheduled) - Validation:
/api/healthreturns 200- recent worker consume run succeeded
Change Checklist
- Code and docs must be updated together.
- API/schema changes require OpenAPI updates.
pnpm run check:textmust pass.pnpm run check:openapimust pass.pnpm run typecheckmust pass.pnpm run test:allmust pass.- Run
pnpm run prisma:generateafter fresh installs and Prisma-affecting changes. - Run
pnpm run build:webwhen touching web code. - AI-assisted changes must complete validation and then commit/push together.
Prohibited Actions
- Manual production DB mutation without runbook/workflow.
- Re-running failed workflows repeatedly without root-cause analysis.
- Printing secrets/passwords/tokens in logs.
Incident Baseline
-
Worker failure:
- Inspect logs:
gh run view <run_id> --log-failed - Verify
APP_MASTER_KEY,DATABASE_URL,WEB_INTERNAL_BASE_URL - Fix and rerun
worker-consume.yml
- Inspect logs:
-
Vercel 404:
- Check Root Directory is
apps/web - Re-check env variables and redeploy
- Validate
/api/health
- Check Root Directory is