Skip to content

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

address review: fix datetime docstring, optimize streak to Set, validate job type

Adam Eivy7df30b350e2b
diff --git a/server/routes/cos.js b/server/routes/cos.js
index 9e394dd06b..f4ec34c179 100644
--- a/server/routes/cos.js
+++ b/server/routes/cos.js
@@ -845,10 +845,13 @@ router.get('/jobs/:id', asyncHandler(async (req, res) => {
router.post('/jobs', asyncHandler(async (req, res) => {
const { name, description, category, type, interval, intervalMs, scheduledTime, enabled, priority, autonomyLevel, promptTemplate, command, triggerAction } = req.body;
- // Shell jobs require command, agent jobs require promptTemplate
+ const VALID_JOB_TYPES = ['agent', 'shell', 'script'];
if (!name) {
throw new ServerError('name is required', { status: 400, code: 'VALIDATION_ERROR' });
}
+ if (type && !VALID_JOB_TYPES.includes(type)) {
+ throw new ServerError(`Invalid job type: ${type}. Must be one of: ${VALID_JOB_TYPES.join(', ')}`, { status: 400, code: 'VALIDATION_ERROR' });
+ }
if (type === 'shell' && !command?.trim()) {
throw new ServerError('command is required for shell jobs', { status: 400, code: 'VALIDATION_ERROR' });
}
diff --git a/server/services/calendarApiSync.js b/server/services/calendarApiSync.js
index 5a18224106..219c5feffd 100644
--- a/server/services/calendarApiSync.js
+++ b/server/services/calendarApiSync.js
@@ -21,17 +21,16 @@ function mapResponseStatus(status) {
/**
* Normalize an Outlook DateTime value to ISO string.
- * Outlook may return bare datetimes (no offset/Z) with a separate TimeZone field,
- * or datetimes that already include an offset. Append 'Z' only when the value
- * has no existing timezone indicator and the TimeZone is UTC.
+ * Outlook Graph API returns bare datetimes (no offset/Z) in UTC with a separate
+ * TimeZone field. We always treat bare values as UTC and store the timeZone
+ * separately on the event object for display purposes.
*/
-function normalizeDateTime(dateTimeStr, timeZone) {
+function normalizeDateTime(dateTimeStr) {
// Already has timezone offset or Z suffix — parse as-is
if (/[Zz]$/.test(dateTimeStr) || /[+-]\d{2}:\d{2}$/.test(dateTimeStr)) {
return new Date(dateTimeStr).toISOString();
}
- // Bare datetime — always treat as UTC since Outlook Graph API returns UTC
- // datetimes with a separate TimeZone field. We store the timeZone separately.
+ // Bare datetime — treat as UTC
return new Date(dateTimeStr + 'Z').toISOString();
}
@@ -108,8 +107,8 @@ export async function syncOutlookCalendarApi(account, _cache, io, options = {})
title: item.Subject || '',
description: item.Body?.Content || '',
location: item.Location?.DisplayName || '',
- startTime: item.Start?.DateTime ? normalizeDateTime(item.Start.DateTime, item.Start.TimeZone) : null,
- endTime: item.End?.DateTime ? normalizeDateTime(item.End.DateTime, item.End.TimeZone) : null,
+ startTime: item.Start?.DateTime ? normalizeDateTime(item.Start.DateTime) : null,
+ endTime: item.End?.DateTime ? normalizeDateTime(item.End.DateTime) : null,
isAllDay: item.IsAllDay || false,
timeZone: item.Start?.TimeZone || 'UTC',
organizer: {
diff --git a/server/services/meatspacePostTraining.js b/server/services/meatspacePostTraining.js
index fc8ffb030d..3c514ea07d 100644
--- a/server/services/meatspacePostTraining.js
+++ b/server/services/meatspacePostTraining.js
@@ -75,20 +75,20 @@ export async function getTrainingStats(days = 30) {
}
// Compute streaks (consecutive days of practice)
- const allDates = [...new Set(entries.map(e => e.date))].sort();
+ const dateSet = new Set(entries.map(e => e.date));
let currentStreak = 0;
- if (allDates.length > 0) {
+ if (dateSet.size > 0) {
const today = new Date().toISOString().split('T')[0];
const yesterday = new Date(Date.now() - 86400000).toISOString().split('T')[0];
// Count backwards from today/yesterday
- let checkDate = allDates.includes(today) ? today : allDates.includes(yesterday) ? yesterday : null;
+ let checkDate = dateSet.has(today) ? today : dateSet.has(yesterday) ? yesterday : null;
if (checkDate) {
currentStreak = 1;
let ts = new Date(checkDate + 'T00:00:00Z').getTime();
while (true) {
ts -= 86400000;
const prev = new Date(ts).toISOString().split('T')[0];
- if (allDates.includes(prev)) {
+ if (dateSet.has(prev)) {
currentStreak++;
} else {
break;
@@ -96,6 +96,7 @@ export async function getTrainingStats(days = 30) {
}
}
}
+ const activeDays = dateSet.size;
// Summarize
const summary = {};
@@ -110,6 +111,7 @@ export async function getTrainingStats(days = 30) {
return {
days,
+ activeDays,
totalEntries: entries.length,
currentStreak,
byDrill: summary,