AtlatestRepositoryminder

minder / tree / src / mindermain.sgl

1;;; (minder main) - Scheduled task channel server entry point.
2;;;
3;;; MCP channel server that manages cron-based scheduled tasks and
4;;; pushes events into a Claude Code session. Designed to be spawned
5;;; by Claude Code as a subprocess and communicate over stdio.
6
7(define-library (minder main)
8 (import (sigil core)
9 (sigil async)
10 (sigil process)
11 (sigil meta)
12 (sigil mcp server)
13 (sigil mcp channel)
14 (sigil log)
15 (minder config)
16 (minder scheduler))
17 (export main)
18 (begin
20 (define (main)
21 (when (member "--version" (command-line))
22 (display (string-append (app-name) " " (app-version)
23 " (sigil " (sigil-version) ")\n"))
24 (exit 0))
26 (log-configure-from-args!)
28 (let* ((config (load-minder-config))
29 (server (mcp-channel-server
30 name: (app-name)
31 version: (app-version)
32 instructions: (minder-instructions))))
34 ;; Register schedule management tools
35 (register-schedule-tools! server config)
37 (log-info "Minder starting"
38 schedules: (length (minder-config-schedules config)))
40 ;; Run everything in an async context. mcp-server-run
41 ;; yields to the scheduler via fd-waiters when stdin is a
42 ;; pipe, so goroutines can interleave.
43 (with-async
44 ;; Start scheduled tasks (if any)
45 (scheduler-start! server config)
47 ;; Run the MCP server loop (reads stdin, writes stdout)
48 (mcp-server-run server))))
50 ;; Build the instructions string for Claude's system prompt.
51 (define (minder-instructions)
52 (string-append
53 "You are receiving events from the minder channel server. "
54 "Scheduled task events arrive as <channel source=\"minder\" "
55 "type=\"schedule\" task=\"...\">.\n\n"
56 "Use add-schedule to create recurring tasks, "
57 "remove-schedule to delete them, and list-schedules to see "
58 "what's active. Schedules use cron syntax (5 fields: "
59 "min hour dom month dow)."))))