Skip to content

feat(schedule): CMATE.md schedule execution feature (Issue #294)#356

Merged
Kewton merged 14 commits intodevelopfrom
feature/294-worktree
Feb 23, 2026
Merged

feat(schedule): CMATE.md schedule execution feature (Issue #294)#356
Kewton merged 14 commits intodevelopfrom
feature/294-worktree

Conversation

@Kewton
Copy link
Owner

@Kewton Kewton commented Feb 23, 2026

Summary

  • CMATE.md ファイルの Schedules テーブルからスケジュール実行を登録・管理する機能を実装
  • claude -p / codex exec をバックグラウンドで定期実行し、結果を DB に保存
  • CMATE タブ UI(スケジュール一覧 + 実行ログ)を追加
  • セキュリティ強化: CLI ツールホワイトリスト、入力バリデーション、環境変数サニタイズ

主な変更

  • DB: scheduled_executions / execution_logs テーブル追加(migration v17)
  • Parser: cmate-parser.ts — CMATE.md 汎用パーサー + Schedules セクション解析
  • Validator: cmate-validator.ts — クライアント側バリデーション(fs 依存なし)
  • Executor: claude-executor.tsexecFile ベース CLI 実行エンジン(タイムアウト・出力制限付き)
  • Scheduler: schedule-manager.ts — croner による cron 評価、同時実行防止、stale レコード無効化
  • API: 4 エンドポイント(schedules CRUD + execution-logs 参照)
  • UI: ExecutionLogPane / NotesAndLogsPane / FileTreeView CMATE ボタン
  • Security: ALLOWED_CLI_TOOLS ホワイトリスト、env-sanitizer.ts で機密環境変数除去
  • i18n: 全 UI テキストを schedule.json (en/ja) で国際化
  • DRY: cmate-constants.ts に共有定数を抽出、パーサー/バリデーター間の重複解消
  • Permission: CMATE.md の Permission 列をオプション化(未指定時は CLI ツール別デフォルト値を適用)

Test plan

  • npx tsc --noEmit — 型エラーなし
  • npm run lint — ESLint エラーなし
  • npm run test:unit — 全 3947 テスト通過(191 ファイル)
  • CMATE.md テンプレート作成 → バリデーション → スケジュール登録の E2E 確認
  • Permission 列省略時にデフォルト値が適用されることを確認
  • 不正な cliToolId / cron 式が API で拒否されることを確認

🤖 Generated with Claude Code

Kewton and others added 14 commits February 23, 2026 14:32
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>
@Kewton Kewton merged commit 0485535 into develop Feb 23, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant