Skip to content

armgit / Orkas

Public Imported from GitHub
0

Orkas is an open-source (MIT), local-first AI team for your desktop: a Commander turns your goal into to-dos and coordinates 16 built-in specialist agents plus Claude Code, Codex, OpenCode, OpenClaw and Hermes, with projects, scheduled automations and connectors. Free app for macOS & Windows; built-in models or your own keys.

2.5 KB
Raw Blame
// Time-bucket the sidebar conversation list by `last_active_at` (already
// computed by features/chats.ts::listConversations as
// `max(updated_at, created_at)`). Local-time boundaries: today / yesterday /
// last 7 days / last 30 days / older. Pure helper — `now` is injectable so
// the fixture tests in test/renderer/conversation-bucket.test.ts can pin
// DST-free wall clocks.
//
// Kept in its own file (per CLAUDE.md §9 — only pure functions are eligible
// for the CJS bridge that vitest uses; conversation.js touches createLogger /
// window / IPC at top level, so it can't be `require()`d directly).

const _BUCKET_ORDER = ['today', 'yesterday', 'last7', 'last30', 'older'];

function timeBucket(iso, now) {
  if (!now) now = new Date();
  if (!iso) return 'older';
  const t = new Date(iso).getTime();
  if (!Number.isFinite(t)) return 'older';
  const today = new Date(now);
  today.setHours(0, 0, 0, 0);
  const todayMs = today.getTime();
  const dayMs = 24 * 60 * 60 * 1000;
  if (t >= todayMs) return 'today';
  if (t >= todayMs - dayMs) return 'yesterday';
  if (t >= todayMs - 7 * dayMs) return 'last7';
  if (t >= todayMs - 30 * dayMs) return 'last30';
  return 'older';
}

// Rows whose sidebar activity falls in today's or yesterday's local bucket, in
// input order. Feeds the sidebar "Recent Tasks" section with the same
// `last_active_at` reading as the bucketed lists, so a row is never under
// "Today"/"Yesterday" in one list and missing from the aggregate. Using the
// calendar buckets (not a rolling 48h) keeps the section stable within a day:
// it only changes when a conversation gets a new message or when the local date
// rolls over, which is when the list already re-renders.
const _RECENT_BUCKETS = new Set(['today', 'yesterday']);

function selectRecentConversations(rows, now) {
  const out = [];
  for (const c of Array.isArray(rows) ? rows : []) {
    if (!c || !c.conversation_id) continue;
    const iso = c.last_active_at || c.updated_at || c.created_at || '';
    if (_RECENT_BUCKETS.has(timeBucket(iso, now))) out.push(c);
  }
  return out;
}

// Local start of yesterday: the lower bound the startup slice must load so
// rows under collapsed projects reach the Recent Tasks section.
function recentConversationsSince(now) {
  const d = new Date(now || new Date());
  d.setHours(0, 0, 0, 0);
  d.setDate(d.getDate() - 1);
  return d;
}

if (typeof module !== 'undefined' && typeof module.exports === 'object') {
  module.exports = {
    timeBucket, selectRecentConversations, recentConversationsSince, _BUCKET_ORDER,
  };
}