Skip to content

feat: add schedule execution feature (Issue #294)#363

Merged
Kewton merged 29 commits intomainfrom
develop
Feb 24, 2026
Merged

feat: add schedule execution feature (Issue #294)#363
Kewton merged 29 commits intomainfrom
develop

Conversation

@Kewton
Copy link
Owner

@Kewton Kewton commented Feb 24, 2026

Summary

  • CMATE.mdによるスケジュール実行機能を追加(Issue スケジュール実行の登録 #294
  • claude -p を使用した定期タスク自動実行エンジンの実装
  • スケジュール管理API(CRUD)、実行ログAPI、UIコンポーネントの追加
  • CMATE.mdパーサー・バリデーター、環境変数サニタイズ、DBマイグレーション
  • ユーザーガイド(日英)の追加

Changes

  • 新規モジュール: cmate-parser.ts, cmate-validator.ts, claude-executor.ts, schedule-manager.ts, env-sanitizer.ts
  • API: schedules CRUD, execution-logs, scheduleId routes
  • UI: ExecutionLogPane, NotesAndLogsPane, FileTreeView CMATE統合
  • 設定: cmate-constants.ts, schedule-config.ts, i18n (schedule namespace)
  • DB: migration 17 (scheduled_executions, execution_logs tables)
  • ドキュメント: CMATE Schedules Guide (ja/en), webapp-guide更新

Test plan

  • ユニットテスト追加(cmate-parser, cmate-validator, claude-executor, schedule-manager, env-sanitizer, schedule-config, db-migrations)
  • 既存テスト更新(MobileTabBar, LeftPaneTabSwitcher, i18n namespace)
  • E2Eテスト(スケジュール登録→実行→ログ確認)

🤖 Generated with Claude Code

Kewton and others added 29 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>
feat(schedule): CMATE.md schedule execution feature (Issue #294)
Align mobile tab label with desktop LeftPaneTabSwitcher naming.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
fix: rename mobile tab label from 'Notes' to 'CMATE'
Reflect current 5-tab layout: Terminal, History, Files, CMATE, Info.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
docs: update mobile tab bar table in webapp-guide
…ssion-mode values

Replace incorrect ['default', 'acceptEdits', 'full'] with the actual
5 valid values: 'default', 'acceptEdits', 'plan', 'dontAsk', 'bypassPermissions'.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
fix(schedule): correct CLAUDE_PERMISSIONS values
…ponse detail

Execution log list now displays the schedule name instead of the message
content for consistency with the Schedules section. Expanded log detail
shows both Message and Response as labeled sections.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
feat(schedule): show schedule name in execution logs with Message/Response detail
…gs via LEFT JOIN

Schedules API now returns only enabled schedules (enabled=1) so renamed/
removed entries no longer appear. Execution logs API uses LEFT JOIN to
include schedule_name for all logs, preserving history from old schedules.
ExecutionLogPane uses the API-provided schedule_name directly instead of
a client-side Map lookup.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
fix(schedule): filter disabled schedules and resolve name display on logs
…n CLI docs

Add bilingual user guides for the CMATE schedule feature covering
table format, cron reference, permissions, examples, and troubleshooting.
Register 'cmate-schedules' section in docs-reader SECTION_MAP for CLI access.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
docs(schedule): add CMATE schedules user guide (ja/en)
@Kewton Kewton merged commit 378dc33 into main Feb 24, 2026
10 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