feat(schedule): CMATE.md schedule execution feature (Issue #294)#356
Merged
feat(schedule): CMATE.md schedule execution feature (Issue #294)#356
Conversation
Add cron-based scheduled execution of claude -p commands per worktree, configured via CMATE.md Schedules section. Includes environment sanitization, CMATE.md parser, DB migration v17, schedule manager with croner, API endpoints, execution log UI, and i18n support. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Extract duplicated constants and validators into centralized config,
improve type safety, and add edge case tests.
Improvements:
- Extract UUID_V4_PATTERN, isValidUuidV4, MAX_SCHEDULE_*_LENGTH into src/config/schedule-config.ts (DRY)
- Remove 7 duplicated require('./db-instance') calls in schedule-manager.ts via getLazyDbInstance() helper
- Add typed DB row interfaces (WorktreeRow, ScheduleIdRow) in schedule-manager.ts
- Add ExecutionLogStatus union type (replaces plain string) in schedule-manager.ts and ExecutionLogPane.tsx
- Add JSDoc comments throughout schedule-manager.ts DB operations
- Exhaustive switch in getStatusColor() (no default branch needed)
- Add 27 new unit tests (3885 -> 3912 passed)
Quality Metrics:
- ESLint errors: 0 -> 0
- TypeScript errors: 0 -> 0
- Unit tests: 3885 -> 3912 (+27)
Relates to #294
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add buildCliArgs() to generate correct arguments per CLI tool (claude: --output-format text --permission-mode acceptEdits, codex: exec --sandbox workspace-write) - Close child stdin immediately to prevent yes/no prompt hang - Add unit tests for buildCliArgs() Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…294 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add a one-click CMATE button that creates CMATE.md from a template if it doesn't exist, or validates the Schedules section if it does. This improves discoverability and reduces silent configuration errors. - New src/lib/cmate-validator.ts: client-side parser and validator - FileTreeView: onCmateSetup prop with FileText icon button - WorktreeDetailRefactored: handleCmateSetup handler (desktop + mobile) - i18n keys for en/ja schedule.json - 18 unit tests for validator Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…reation The format check was not visible because handleCmateSetup returned immediately after creating the template without running validation. Now validation always runs: after creation it uses the template content directly, otherwise it reads from the API response. Also added defensive typeof check on API response content field. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Previously only data rows were validated, allowing incorrect header names (e.g. "Message2") to pass silently. Now validates that Schedules section headers match expected columns (Name, Cron, Message). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Rename "Notes & Logs" tab to "CMATE" and "Logs" sub-tab to "Schedules" to better reflect the schedule execution feature. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The /api/worktrees/:id/tree endpoint returns an object { path, name, items, parentPath },
not an array. Extract items from the response to fix TypeError in handleCmateSetup().
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace the single-line empty state message in the Schedules tab with an i18n-supported step-by-step guide to help first-time users configure schedules via CMATE.md. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…lback The CMATE.md Schedules table validator now treats the Permission column as optional. When omitted, the parser applies DEFAULT_PERMISSIONS per CLI tool (claude: acceptEdits, codex: workspace-write). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add per-schedule permission configuration parsed from CMATE.md Permission column. The permission value flows through the full pipeline: parser -> schedule manager -> CLI executor (--permission-mode for claude, --sandbox for codex). Includes stale schedule cleanup in DB sync. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Security: - Add ALLOWED_CLI_TOOLS whitelist to claude-executor.ts to prevent arbitrary command execution via execFile [SEC-001] - Add permission value validation against CLAUDE_PERMISSIONS/CODEX_SANDBOXES in cmate-validator.ts (not just empty check) DRY / Code Quality: - Extract shared constants (CONTROL_CHAR_PATTERN, NAME_PATTERN, isValidCronExpression, sanitizeContent) into src/config/cmate-constants.ts - Fix global regex /g flag state issue by using CONTROL_CHAR_PATTERN without /g and creating fresh RegExp in sanitizeContent() - Remove duplicated constants from cmate-parser.ts and cmate-validator.ts i18n: - Replace all hardcoded English strings in ExecutionLogPane with t() calls - Replace hardcoded tab labels in NotesAndLogsPane with t() calls - Fix LeftPaneTabSwitcher test to match renamed CMATE tab label Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…issues API Routes: - Add ALLOWED_CLI_TOOLS whitelist validation to POST/PUT schedules - Add isValidCronExpression() syntax check to POST/PUT schedules - Trim name/message fields to reject whitespace-only input Consistency: - Align permission validation between parser and validator (empty permission is allowed in both — parser applies default per CLI tool) - Merge default case into claude case in buildCliArgs() to eliminate unreachable dead code Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
claude -p/codex execをバックグラウンドで定期実行し、結果を DB に保存主な変更
scheduled_executions/execution_logsテーブル追加(migration v17)cmate-parser.ts— CMATE.md 汎用パーサー + Schedules セクション解析cmate-validator.ts— クライアント側バリデーション(fs 依存なし)claude-executor.ts—execFileベース CLI 実行エンジン(タイムアウト・出力制限付き)schedule-manager.ts— croner による cron 評価、同時実行防止、stale レコード無効化ExecutionLogPane/NotesAndLogsPane/ FileTreeView CMATE ボタンALLOWED_CLI_TOOLSホワイトリスト、env-sanitizer.tsで機密環境変数除去schedule.json(en/ja) で国際化cmate-constants.tsに共有定数を抽出、パーサー/バリデーター間の重複解消Test plan
npx tsc --noEmit— 型エラーなしnpm run lint— ESLint エラーなしnpm run test:unit— 全 3947 テスト通過(191 ファイル)🤖 Generated with Claude Code