@stackmemoryai/stackmemory
Version:
Lossless, project-scoped memory for AI coding tools. Durable context across sessions with 56 MCP tools, FTS5 search, conductor orchestrator, loop/watch monitoring, snapshot capture, pre-flight overlap checks, Claude/Codex/OpenCode wrappers, Linear sync, a
33 lines (32 loc) • 1.15 kB
JavaScript
import { fileURLToPath as __fileURLToPath } from 'url';
import { dirname as __pathDirname } from 'path';
const __filename = __fileURLToPath(import.meta.url);
const __dirname = __pathDirname(__filename);
function filterPending(items, filters = {}, now = Date.now()) {
let out = [...items];
const { taskContains, olderThanMs, newerThanMs, sort, limit } = filters;
if (taskContains) {
const q = taskContains.toLowerCase();
out = out.filter((it) => (it.task || "").toLowerCase().includes(q));
}
if (typeof olderThanMs === "number") {
out = out.filter(
(it) => typeof it.createdAt === "number" && now - it.createdAt > olderThanMs
);
}
if (typeof newerThanMs === "number") {
out = out.filter(
(it) => typeof it.createdAt === "number" && now - it.createdAt < newerThanMs
);
}
const getTs = (t) => t === null ? Infinity : t;
if (sort === "asc")
out.sort((a, b) => getTs(a.createdAt) - getTs(b.createdAt));
if (sort === "desc")
out.sort((a, b) => getTs(b.createdAt) - getTs(a.createdAt));
if (typeof limit === "number") out = out.slice(0, limit);
return out;
}
export {
filterPending
};