Files
claw3d/src/lib/office/standup/store.ts
T
Luke The Dev a997f13601 feat(kanban): Interactive Kanban board with real-time task tracking (#83)
* feat(kanban): add Kanban board with task-manager skill, modal UI, and desk clutter

Implement a full Kanban board system for tracking agent tasks:
- Add task-manager skill with shared JSON task store for persistence
- Render board as a floating modal over the live 3D office (not immersive)
- Auto-create tasks from actionable user messages with heuristic filtering
- Sync task status through OpenClaw agent lifecycle events
- Collapse task details panel by default, expand on card click
- Add dynamic desk clutter (papers, folders, etc.) reflecting active task count
- Exclude done tasks from desk clutter count
- Extract KANBAN_CLUTTER_OFFSET for easy positioning adjustment
- Add install flow with progress bar for the task-manager skill
- Include unit and e2e test coverage

Made-with: Cursor

* feat(kanban): production-harden task board with AI-free classification, resilient persistence, and modal UX

- Harden shared task store with atomic writes, payload size limits, and server-side enum validation
- Add client resilience: request timeouts (AbortController), exponential backoff retries, poll deduplication
- Implement optimistic UI with rollback on all card mutations (update, move, archive)
- Add modal accessibility: focus trap, Escape to close, aria-modal, keyboard card navigation
- Trust OpenClaw agent lifecycle phase=start as task classification signal instead of regex heuristics
- Keep regex heuristic only as lightweight filter for direct chat events (conversational noise)
- Expand verb recognition with typo tolerance and broader action vocabulary
- Create tasks from agent runs even when no chat event is received (external channel support)
- Merge dual header bars into single bar; reposition close button outside modal corner
- Exclude done tasks from desk clutter count; make clutter position configurable via KANBAN_CLUTTER_OFFSET
- Update default furniture layout to match user configuration
- Ensure kanban_board furniture persists in local storage across sessions
- Add comprehensive test coverage for store, API route, and controller logic

Made-with: Cursor

---------

Co-authored-by: iamlukethedev <lucas.guilherme@smartwayslfl.com>
2026-03-30 22:58:18 -05:00

112 lines
3.5 KiB
TypeScript

import fs from "node:fs";
import path from "node:path";
import { resolveStateDir } from "@/lib/clawdbot/paths";
import type { StandupMeeting, StandupMeetingStore } from "@/lib/office/standup/types";
const STORE_DIR = "claw3d";
const STORE_FILE = "standup-store.json";
const GATHERING_MEETING_MAX_AGE_MS = 5 * 60 * 1000;
const ACTIVE_MEETING_MAX_AGE_MS = 20 * 60 * 1000;
const ensureDirectory = (dirPath: string) => {
if (!fs.existsSync(dirPath)) {
fs.mkdirSync(dirPath, { recursive: true });
}
};
const resolveStorePath = () => {
const dir = path.join(resolveStateDir(), STORE_DIR);
ensureDirectory(dir);
return path.join(dir, STORE_FILE);
};
const defaultStore = (): StandupMeetingStore => ({
activeMeeting: null,
lastMeeting: null,
});
const isRecord = (value: unknown): value is Record<string, unknown> =>
Boolean(value && typeof value === "object" && !Array.isArray(value));
const normalizeMeeting = (value: unknown): StandupMeeting | null => {
if (!isRecord(value)) return null;
if (typeof value.id !== "string") return null;
if (!Array.isArray(value.cards) || !Array.isArray(value.participantOrder)) return null;
if (!Array.isArray(value.arrivedAgentIds)) return null;
if (typeof value.startedAt !== "string" || typeof value.updatedAt !== "string") return null;
return value as StandupMeeting;
};
const isActiveMeetingStale = (
meeting: StandupMeeting | null,
nowMs: number = Date.now()
): boolean => {
if (!meeting) return false;
if (meeting.phase === "gathering") {
const startedAtMs = Date.parse(meeting.startedAt);
if (!Number.isFinite(startedAtMs)) return false;
return nowMs - startedAtMs > GATHERING_MEETING_MAX_AGE_MS;
}
if (meeting.phase !== "in_progress") {
return false;
}
const updatedAtMs = Date.parse(meeting.updatedAt);
if (!Number.isFinite(updatedAtMs)) return false;
return nowMs - updatedAtMs > ACTIVE_MEETING_MAX_AGE_MS;
};
const readStore = (): StandupMeetingStore => {
const storePath = resolveStorePath();
if (!fs.existsSync(storePath)) {
return defaultStore();
}
const raw = fs.readFileSync(storePath, "utf8");
const parsed = JSON.parse(raw) as unknown;
if (!isRecord(parsed)) return defaultStore();
const activeMeeting = normalizeMeeting(parsed.activeMeeting);
const lastMeeting = normalizeMeeting(parsed.lastMeeting);
return {
activeMeeting: isActiveMeetingStale(activeMeeting) ? null : activeMeeting,
lastMeeting,
};
};
const writeStore = (store: StandupMeetingStore) => {
const storePath = resolveStorePath();
fs.writeFileSync(storePath, JSON.stringify(store, null, 2), "utf8");
};
export const loadStandupMeetingStore = (): StandupMeetingStore => readStore();
export const loadActiveStandupMeeting = (): StandupMeeting | null => readStore().activeMeeting;
export const saveStandupMeeting = (meeting: StandupMeeting | null): StandupMeetingStore => {
const current = readStore();
const next: StandupMeetingStore = {
activeMeeting: meeting,
lastMeeting: meeting ?? current.lastMeeting,
};
if (meeting?.phase === "complete") {
next.lastMeeting = meeting;
}
writeStore(next);
return next;
};
export const updateStandupMeeting = (
updater: (meeting: StandupMeeting | null) => StandupMeeting | null
): StandupMeetingStore => {
const current = readStore();
const nextMeeting = updater(current.activeMeeting);
const nextStore: StandupMeetingStore = {
activeMeeting: nextMeeting,
lastMeeting:
nextMeeting?.phase === "complete"
? nextMeeting
: current.lastMeeting,
};
writeStore(nextStore);
return nextStore;
};