Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix(cos): add scheduledTime to autonomous jobs for time-of-day scheduling
Adam Eivyc1541e9352f7
diff --git a/.changelog/v0.12.x.md b/.changelog/v0.12.x.mdindex 77225731fc..ed0b96b87e 100644--- a/.changelog/v0.12.x.md+++ b/.changelog/v0.12.x.md@@ -285,6 +285,11 @@ This release adds branch management and automated release workflow capabilities**Toolkit changes**:- `portos-ai-toolkit/src/server/runner.js` — Added `console.log` in `createRun()` after provider resolution+### Autonomous Jobs — Daily Briefing Not Running at Scheduled Time+- **Fix**: Autonomous jobs used a simple 24-hour interval from `lastRun` with no concept of time-of-day scheduling — the daily briefing would run whenever 24 hours elapsed, not at a specific morning hour+- **Solution**: Added `scheduledTime` field (HH:MM format) to autonomous jobs. `getDueJobs()` now checks both interval elapsed AND whether the current local time has passed the scheduled time. Daily briefing defaults to `05:00`+- **UI**: Job cards display scheduled time next to interval, edit/create forms include a time picker+## Improvements### CoS — Learning Health Summary on Dashboarddiff --git a/client/src/components/cos/tabs/JobsTab.jsx b/client/src/components/cos/tabs/JobsTab.jsxindex e3a5c8168e..f714141140 100644--- a/client/src/components/cos/tabs/JobsTab.jsx+++ b/client/src/components/cos/tabs/JobsTab.jsx@@ -32,9 +32,16 @@ function formatTimeAgo(dateStr) {return mins > 0 ? `${mins}m ago` : 'Just now';}-function formatNextDue(lastRun, intervalMs) {- if (!lastRun) return 'Immediately';- const nextDue = new Date(lastRun).getTime() + intervalMs;+function formatNextDue(lastRun, intervalMs, scheduledTime) {+ if (!lastRun) return scheduledTime ? `at ${scheduledTime}` : 'Immediately';+ let nextDue = new Date(lastRun).getTime() + intervalMs;+ // If there's a scheduledTime, adjust the next-due to that time of day+ if (scheduledTime) {+ const [hours, minutes] = scheduledTime.split(':').map(Number);+ const nextDate = new Date(nextDue);+ nextDate.setHours(hours, minutes, 0, 0);+ if (nextDate.getTime() > nextDue) nextDue = nextDate.getTime();+ }const diff = nextDue - Date.now();if (diff <= 0) return 'Now';const hours = Math.floor(diff / 3600000);@@ -55,6 +62,7 @@ function JobCard({ job, onToggle, onTrigger, onDelete, onUpdate }) {name: job.name,description: job.description,interval: job.interval,+ scheduledTime: job.scheduledTime || '',priority: job.priority,autonomyLevel: job.autonomyLevel,promptTemplate: job.promptTemplate@@ -110,11 +118,12 @@ function JobCard({ job, onToggle, onTrigger, onDelete, onUpdate }) {<span className="flex items-center gap-1"><Clock size={10} />{INTERVAL_OPTIONS.find(i => i.value === job.interval)?.label || job.interval}+ {job.scheduledTime && ` at ${job.scheduledTime}`}</span><span>Last: {formatTimeAgo(job.lastRun)}</span>{job.enabled && (<span className={isDue ? 'text-port-warning' : 'text-gray-500'}>- Next: {formatNextDue(job.lastRun, job.intervalMs)}+ Next: {formatNextDue(job.lastRun, job.intervalMs, job.scheduledTime)}</span>)}<span>Runs: {job.runCount || 0}</span>@@ -175,6 +184,13 @@ function JobCard({ job, onToggle, onTrigger, onDelete, onUpdate }) {<option key={opt.value} value={opt.value}>{opt.label}</option>))}</select>+ <input+ type="time"+ value={editData.scheduledTime || ''}+ onChange={e => setEditData(d => ({ ...d, scheduledTime: e.target.value || null }))}+ className="px-3 py-2 bg-port-bg border border-port-border rounded-lg text-white text-sm"+ title="Run at specific time (leave empty for any time)"+ /><selectvalue={editData.priority}onChange={e => setEditData(d => ({ ...d, priority: e.target.value }))}@@ -257,6 +273,7 @@ export default function JobsTab() {description: '',category: 'custom',interval: 'daily',+ scheduledTime: '',priority: 'MEDIUM',autonomyLevel: 'manager',promptTemplate: '',@@ -293,6 +310,7 @@ export default function JobsTab() {description: '',category: 'custom',interval: 'daily',+ scheduledTime: '',priority: 'MEDIUM',autonomyLevel: 'manager',promptTemplate: '',@@ -419,6 +437,13 @@ export default function JobsTab() {<option key={opt.value} value={opt.value}>{opt.label}</option>))}</select>+ <input+ type="time"+ value={newJob.scheduledTime || ''}+ onChange={e => setNewJob(j => ({ ...j, scheduledTime: e.target.value || null }))}+ className="px-3 py-2 bg-port-bg border border-port-border rounded-lg text-white text-sm"+ title="Run at specific time (leave empty for any time)"+ /><selectvalue={newJob.priority}onChange={e => setNewJob(j => ({ ...j, priority: e.target.value }))}diff --git a/server/routes/cos.js b/server/routes/cos.jsindex 737d1d286e..fa0ced7837 100644--- a/server/routes/cos.js+++ b/server/routes/cos.js@@ -729,14 +729,14 @@ router.get('/jobs/:id', asyncHandler(async (req, res) => {// POST /api/cos/jobs - Create a new autonomous jobrouter.post('/jobs', asyncHandler(async (req, res) => {- const { name, description, category, interval, intervalMs, enabled, priority, autonomyLevel, promptTemplate } = req.body;+ const { name, description, category, interval, intervalMs, scheduledTime, enabled, priority, autonomyLevel, promptTemplate } = req.body;if (!name || !promptTemplate) {throw new ServerError('name and promptTemplate are required', { status: 400, code: 'VALIDATION_ERROR' });}const job = await autonomousJobs.createJob({- name, description, category, interval, intervalMs,+ name, description, category, interval, intervalMs, scheduledTime,enabled, priority, autonomyLevel, promptTemplate});res.json({ success: true, job });diff --git a/server/services/autonomousJobs.js b/server/services/autonomousJobs.jsindex cafaba4e34..43a8a0c8db 100644--- a/server/services/autonomousJobs.js+++ b/server/services/autonomousJobs.js@@ -109,6 +109,7 @@ Focus on surfacing actionable insights. Don't just classify — think about whatcategory: 'daily-briefing',interval: 'daily',intervalMs: DAY,+ scheduledTime: '05:00',enabled: false,priority: 'LOW',autonomyLevel: 'assistant',@@ -260,6 +261,22 @@ async function getEnabledJobs() {return data.jobs.filter(j => j.enabled)}+/**+ * Check if the current time has passed a job's scheduledTime today.+ * scheduledTime is "HH:MM" in local time (e.g., "05:00").+ * Returns true if no scheduledTime is set, or if current local time >= scheduledTime.+ * @param {string|null} scheduledTime - "HH:MM" or null/undefined+ * @returns {boolean}+ */+function isScheduledTimeMet(scheduledTime) {+ if (!scheduledTime) return true+ const [hours, minutes] = scheduledTime.split(':').map(Number)+ const now = new Date()+ const nowMinutes = now.getHours() * 60 + now.getMinutes()+ const targetMinutes = hours * 60 + minutes+ return nowMinutes >= targetMinutes+}+/*** Get jobs that are due to run* @returns {Promise<Array>} Due jobs with reason@@ -274,6 +291,9 @@ async function getDueJobs() {const timeSinceLastRun = now - lastRunif (timeSinceLastRun >= job.intervalMs) {+ // If job has a scheduledTime, only mark due if we've passed that time today+ if (!isScheduledTimeMet(job.scheduledTime)) continue+due.push({...job,reason: job.lastRun ? `${job.interval}-due` : 'never-run',@@ -304,6 +324,7 @@ async function createJob(jobData) {category: jobData.category || 'custom',interval: jobData.interval || 'weekly',intervalMs: resolveIntervalMs(jobData.interval || 'weekly', jobData.intervalMs),+ scheduledTime: jobData.scheduledTime || null,enabled: jobData.enabled !== undefined ? jobData.enabled : false,priority: jobData.priority || 'MEDIUM',autonomyLevel: jobData.autonomyLevel || 'manager',@@ -336,7 +357,7 @@ async function updateJob(jobId, updates) {const updatableFields = ['name', 'description', 'category', 'interval', 'intervalMs',- 'enabled', 'priority', 'autonomyLevel', 'promptTemplate'+ 'scheduledTime', 'enabled', 'priority', 'autonomyLevel', 'promptTemplate']for (const field of updatableFields) {@@ -567,15 +588,29 @@ async function getNextDueJob() {for (const job of enabledJobs) {const lastRun = job.lastRun ? new Date(job.lastRun).getTime() : 0- const nextDue = lastRun + job.intervalMs+ let nextDue = lastRun + job.intervalMs++ // If job has scheduledTime, adjust nextDue to that time of day+ if (job.scheduledTime) {+ const [hours, minutes] = job.scheduledTime.split(':').map(Number)+ const nextDueDate = new Date(nextDue)+ nextDueDate.setHours(hours, minutes, 0, 0)+ // If the scheduled time already passed on the interval-due date, it's fine+ // If not, the job waits until that time+ if (nextDueDate.getTime() > nextDue) {+ nextDue = nextDueDate.getTime()+ }+ }if (nextDue < earliestTime) {earliestTime = nextDue+ const isDue = Date.now() >= nextDue && isScheduledTimeMet(job.scheduledTime)earliest = {jobId: job.id,jobName: job.name,nextDueAt: new Date(nextDue).toISOString(),- isDue: Date.now() >= nextDue+ scheduledTime: job.scheduledTime || null,+ isDue}}}@@ -626,6 +661,7 @@ export {generateTaskFromJob,getJobStats,getNextDueJob,+ isScheduledTimeMet,INTERVAL_OPTIONS,loadJobSkillTemplate,saveJobSkillTemplate,