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 optional chaining, calendar schema, spawn cleanup, nav order, typos

Adam Eivy15185ab01116
diff --git a/CLAUDE.md b/CLAUDE.md
index 7f68f7cea8..704f3d1f98 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -82,7 +82,7 @@ When CoS agents or AI tools work on managed apps outside PortOS, all research, p
- **Zod validation** - all route inputs validated via `lib/validation.js`
- **Command allowlist** - shell execution restricted to approved commands only
- **Mobile responsive** - all pages should be mobile responsive friendly
-- **Above the fold** - keep actionable content and info above the fold and design pages for maximum information and acess without scrolling
+- **Above the fold** - keep actionable content and info above the fold and design pages for maximum information and access without scrolling
- **No hardcoded localhost** - use `window.location.hostname` for URLs; app accessed via Tailscale remotely
- **Alphabetical navigation** - sidebar nav items in `Layout.jsx` are alphabetically ordered after the Dashboard+CyberCity top section and separator; children within collapsible sections are also alphabetical
- **Reactive UI updates** - after mutations (delete, create, update), update local state directly instead of refetching the entire list from the server. Use `setState(prev => prev.filter(...))` or similar patterns for immediate feedback
@@ -110,6 +110,6 @@ port-error: #ef4444
- **Changelog**: `/cam` appends to `.changelog/NEXT.md`; `/release` finalizes it into a versioned file
- **Versioning**: Version in `package.json` reflects the last release. Do not bump during development — `/release` handles version bumps
- After each feature or bug fix, run `/simplify` and then commit and push code
-- If we have created enough commits to wrap up a feature or issue to warrent a production release, pull the latest maina nd release branches and then run `/release` from main
+- If we have created enough commits to wrap up a feature or issue to warrant a production release, pull the latest main and release branches and then run `/release` from main
See `.changelog/README.md` for detailed format and best practices.
diff --git a/client/src/components/Layout.jsx b/client/src/components/Layout.jsx
index b2764f29a3..e17fef4b6f 100644
--- a/client/src/components/Layout.jsx
+++ b/client/src/components/Layout.jsx
@@ -193,10 +193,10 @@ const navItems = [
label: 'Messages',
icon: Mail,
children: [
+ { to: '/messages/config', label: 'Config', icon: Settings },
{ to: '/messages/drafts', label: 'Drafts', icon: FilePen },
{ to: '/messages/inbox', label: 'Inbox', icon: Inbox },
- { to: '/messages/sync', label: 'Sync', icon: RefreshCw },
- { to: '/messages/config', label: 'Config', icon: Settings }
+ { to: '/messages/sync', label: 'Sync', icon: RefreshCw }
]
},
{ to: '/post', label: 'POST', icon: Zap, single: true },
diff --git a/client/src/hooks/usePostSession.js b/client/src/hooks/usePostSession.js
index 1b33b37290..90d69f4508 100644
--- a/client/src/hooks/usePostSession.js
+++ b/client/src/hooks/usePostSession.js
@@ -264,7 +264,7 @@ export function usePostSession() {
if (isTraining) {
for (const r of drillResults) {
const questionCount = r.questions?.length || r.responses?.length || 0;
- const correctCount = r.questions?.filter(q => q.correct).length ?? 0;
+ const correctCount = r.questions?.filter(q => q.correct)?.length ?? 0;
await submitTrainingEntry({
module: r.module,
drillType: r.type,
diff --git a/server/routes/calendar.js b/server/routes/calendar.js
index b5e47853e1..2b0dcb10fb 100644
--- a/server/routes/calendar.js
+++ b/server/routes/calendar.js
@@ -11,7 +11,7 @@ const router = express.Router();
// === Validation Schemas ===
const createAccountSchema = z.object({
name: z.string().min(1),
- type: z.enum(['outlook-calendar', 'gmail-calendar']),
+ type: z.enum(['outlook-calendar']),
email: z.union([z.string().email(), z.literal('')]).optional().default(''),
syncConfig: z.object({
maxAge: z.string().optional(),
diff --git a/server/services/calendarApiSync.js b/server/services/calendarApiSync.js
index ef28899d04..f07d937bf8 100644
--- a/server/services/calendarApiSync.js
+++ b/server/services/calendarApiSync.js
@@ -19,6 +19,23 @@ function mapResponseStatus(status) {
return map[status?.Response] || 'unknown';
}
+/**
+ * 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.
+ */
+function normalizeDateTime(dateTimeStr, timeZone) {
+ // 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 — assume UTC only when TimeZone says so (or is absent)
+ const isUtc = !timeZone || timeZone === 'UTC' || timeZone === 'tzone://Microsoft/Utc';
+ const suffix = isUtc ? 'Z' : '';
+ return new Date(dateTimeStr + suffix).toISOString();
+}
+
function mapAttendeeStatus(status) {
const map = {
None: 'none',
@@ -90,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 ? new Date(item.Start.DateTime + 'Z').toISOString() : null,
- endTime: item.End?.DateTime ? new Date(item.End.DateTime + 'Z').toISOString() : null,
+ startTime: item.Start?.DateTime ? normalizeDateTime(item.Start.DateTime, item.Start.TimeZone) : null,
+ endTime: item.End?.DateTime ? normalizeDateTime(item.End.DateTime, item.End.TimeZone) : null,
isAllDay: item.IsAllDay || false,
timeZone: item.Start?.TimeZone || 'UTC',
organizer: {
diff --git a/server/services/calendarSync.js b/server/services/calendarSync.js
index 61bddcc68f..dc2472f6c3 100644
--- a/server/services/calendarSync.js
+++ b/server/services/calendarSync.js
@@ -158,7 +158,7 @@ export async function syncAccount(accountId, io, options = {}) {
// Reconcile: remove cached events no longer present
let pruned = 0;
- if (providerStatus === 'success' && newEvents.length > 0) {
+ if (providerStatus === 'success') {
const fetchedIds = new Set(newEvents.filter(e => e.externalId).map(e => e.externalId));
const before = cache.events.length;
cache.events = cache.events.filter(e => !e.externalId || fetchedIds.has(e.externalId));
diff --git a/server/services/cos.js b/server/services/cos.js
index 8a446b7cc4..72e0b27caf 100644
--- a/server/services/cos.js
+++ b/server/services/cos.js
@@ -3610,6 +3610,26 @@ async function registerSingleJobSchedule(jobId) {
// Track jobs currently being spawned (between task:ready emit and agent registration)
// to prevent duplicate spawns when timers overlap or fire during spawn
const spawningJobIds = new Set();
+const spawningJobTimeouts = new Map();
+
+function addSpawningJob(jobId) {
+ spawningJobIds.add(jobId);
+ // Auto-clear after 5 minutes if spawn never completes
+ if (spawningJobTimeouts.has(jobId)) clearTimeout(spawningJobTimeouts.get(jobId));
+ spawningJobTimeouts.set(jobId, setTimeout(() => {
+ spawningJobIds.delete(jobId);
+ spawningJobTimeouts.delete(jobId);
+ }, 5 * 60 * 1000));
+}
+
+function clearSpawningJob(jobId) {
+ spawningJobIds.delete(jobId);
+ const timeout = spawningJobTimeouts.get(jobId);
+ if (timeout) {
+ clearTimeout(timeout);
+ spawningJobTimeouts.delete(jobId);
+ }
+}
/**
* Execute a scheduled autonomous job and re-register its timer.
@@ -3680,10 +3700,15 @@ async function executeScheduledJob(jobId) {
}
// Mark as spawning before emitting task:ready to prevent races
- spawningJobIds.add(jobId);
- const task = await generateTaskFromJob(job);
- emitLog('info', `Autonomous job firing: ${job.name}`, { jobId, category: job.category });
- cosEvents.emit('task:ready', task);
+ addSpawningJob(jobId);
+ try {
+ const task = await generateTaskFromJob(job);
+ emitLog('info', `Autonomous job firing: ${job.name}`, { jobId, category: job.category });
+ cosEvents.emit('task:ready', task);
+ } catch (err) {
+ clearSpawningJob(jobId);
+ emitLog('error', `Failed to fire autonomous job: ${job.name} - ${err?.message || err}`, { jobId, category: job.category });
+ }
}
// Re-register for next fire time
@@ -3787,7 +3812,7 @@ async function init() {
// Record autonomous job execution only after the agent actually spawns
cosEvents.on('job:spawned', async ({ jobId }) => {
- spawningJobIds.delete(jobId);
+ clearSpawningJob(jobId);
await recordJobExecution(jobId).catch(err =>
console.error(`❌ Failed to record job execution for ${jobId}: ${err.message}`)
);