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

add PortOS changelog service for daily briefing commit summaries

Adam Eivyd485a2e2bad0
diff --git a/server/services/portosChangelog.js b/server/services/portosChangelog.js
new file mode 100644
index 0000000000..a015123d39
--- /dev/null
+++ b/server/services/portosChangelog.js
@@ -0,0 +1,77 @@
+/**
+ * PortOS Changelog Service
+ *
+ * Extracts recent PortOS feature commits from git history.
+ * Used by the daily briefing to highlight new features for the user.
+ */
+
+import { execFileSync } from 'child_process';
+import { writeFile } from 'fs/promises';
+import { join } from 'path';
+import { readJSONFile, PATHS, DAY } from '../lib/fileUtils.js';
+
+const STATE_FILE = join(PATHS.data, 'portos-changelog.json');
+const NUL = '\x00';
+
+const DEFAULT_STATE = { lastBriefedAt: null, lastBriefedCommit: null };
+
+function parseConventionalCommit(message) {
+ const match = message.match(/^(feat|fix|refactor|perf|docs|chore|style|test)(?:\(([^)]+)\))?:\s*(.+)/);
+ if (!match) return null;
+ return { type: match[1], scope: match[2] || null, description: match[3] };
+}
+
+/**
+ * @param {string} [since] - ISO date string. Defaults to last briefed time or 24h ago.
+ * @returns {{ features: Array, fixes: Array, other: Array, since: string }}
+ */
+export async function getRecentChanges(since) {
+ let sinceDate = since;
+ if (!sinceDate) {
+ const state = await readJSONFile(STATE_FILE, DEFAULT_STATE);
+ sinceDate = state.lastBriefedAt || new Date(Date.now() - DAY).toISOString();
+ }
+
+ // NUL delimiter avoids breakage from | in commit messages
+ const raw = execFileSync('git', [
+ 'log', `--since=${sinceDate}`, '--no-merges', `--format=%H${NUL}%s${NUL}%ai`
+ ], { cwd: process.cwd(), encoding: 'utf-8', windowsHide: true }).trim();
+
+ if (!raw) {
+ return { features: [], fixes: [], other: [], since: sinceDate };
+ }
+
+ const features = [];
+ const fixes = [];
+ const other = [];
+
+ for (const line of raw.split('\n')) {
+ const [hash, message, date] = line.split(NUL);
+ const parsed = parseConventionalCommit(message);
+ const commit = { hash: hash?.slice(0, 8), message, date, parsed };
+ if (parsed?.type === 'feat') features.push(commit);
+ else if (parsed?.type === 'fix') fixes.push(commit);
+ else if (parsed) other.push(commit);
+ }
+
+ return { features, fixes, other, since: sinceDate };
+}
+
+export async function markBriefed() {
+ const headCommit = execFileSync('git', ['rev-parse', '--short', 'HEAD'], {
+ cwd: process.cwd(), encoding: 'utf-8', windowsHide: true
+ }).trim();
+
+ const state = {
+ lastBriefedAt: new Date().toISOString(),
+ lastBriefedCommit: headCommit
+ };
+
+ await writeFile(STATE_FILE, JSON.stringify(state, null, 2));
+ console.log(`📋 PortOS changelog briefed at ${headCommit}`);
+ return state;
+}
+
+export async function getState() {
+ return readJSONFile(STATE_FILE, DEFAULT_STATE);
+}
diff --git a/server/services/portosChangelog.test.js b/server/services/portosChangelog.test.js
new file mode 100644
index 0000000000..59c59096e8
--- /dev/null
+++ b/server/services/portosChangelog.test.js
@@ -0,0 +1,132 @@
+import { describe, it, expect, vi, beforeEach } from 'vitest';
+
+const NUL = '\x00';
+
+vi.mock('child_process', () => ({
+ execFileSync: vi.fn()
+}));
+
+vi.mock('fs/promises', () => ({
+ writeFile: vi.fn().mockResolvedValue(undefined)
+}));
+
+vi.mock('../lib/fileUtils.js', () => ({
+ readJSONFile: vi.fn(),
+ PATHS: { data: '/mock/data' },
+ DAY: 86400000
+}));
+
+import { execFileSync } from 'child_process';
+import { writeFile } from 'fs/promises';
+import { readJSONFile } from '../lib/fileUtils.js';
+import { getRecentChanges, markBriefed, getState } from './portosChangelog.js';
+
+beforeEach(() => {
+ vi.clearAllMocks();
+ readJSONFile.mockResolvedValue({ lastBriefedAt: null, lastBriefedCommit: null });
+});
+
+describe('getRecentChanges', () => {
+ it('returns empty arrays when no commits found', async () => {
+ execFileSync.mockReturnValue('');
+ const result = await getRecentChanges();
+ expect(result.features).toEqual([]);
+ expect(result.fixes).toEqual([]);
+ expect(result.other).toEqual([]);
+ });
+
+ it('parses feature commits correctly', async () => {
+ execFileSync.mockReturnValue(
+ `abc12345${NUL}feat(cos): add new briefing section${NUL}2026-03-23 10:00:00 -0700\n` +
+ `def67890${NUL}feat(ui): add dark mode toggle${NUL}2026-03-23 09:00:00 -0700`
+ );
+ const result = await getRecentChanges();
+ expect(result.features).toHaveLength(2);
+ expect(result.features[0].parsed.type).toBe('feat');
+ expect(result.features[0].parsed.scope).toBe('cos');
+ expect(result.features[0].parsed.description).toBe('add new briefing section');
+ expect(result.features[0].hash).toBe('abc12345');
+ });
+
+ it('separates features from fixes', async () => {
+ execFileSync.mockReturnValue(
+ `abc12345${NUL}feat(cos): add feature${NUL}2026-03-23 10:00:00 -0700\n` +
+ `def67890${NUL}fix(ui): broken button${NUL}2026-03-23 09:00:00 -0700`
+ );
+ const result = await getRecentChanges();
+ expect(result.features).toHaveLength(1);
+ expect(result.fixes).toHaveLength(1);
+ expect(result.fixes[0].parsed.type).toBe('fix');
+ });
+
+ it('categorizes refactor/chore/docs as other', async () => {
+ execFileSync.mockReturnValue(
+ `abc12345${NUL}refactor(api): clean up routes${NUL}2026-03-23 10:00:00 -0700\n` +
+ `def67890${NUL}chore: update deps${NUL}2026-03-23 09:00:00 -0700`
+ );
+ const result = await getRecentChanges();
+ expect(result.features).toHaveLength(0);
+ expect(result.fixes).toHaveLength(0);
+ expect(result.other).toHaveLength(2);
+ });
+
+ it('uses lastBriefedAt from state when no since param provided', async () => {
+ readJSONFile.mockResolvedValue({ lastBriefedAt: '2026-03-22T00:00:00Z', lastBriefedCommit: 'aaa' });
+ execFileSync.mockReturnValue('');
+ const result = await getRecentChanges();
+ expect(result.since).toBe('2026-03-22T00:00:00Z');
+ expect(execFileSync).toHaveBeenCalledWith(
+ 'git',
+ expect.arrayContaining(['--since=2026-03-22T00:00:00Z']),
+ expect.any(Object)
+ );
+ });
+
+ it('skips state file read when since param is provided', async () => {
+ execFileSync.mockReturnValue('');
+ const result = await getRecentChanges('2026-03-20T00:00:00Z');
+ expect(result.since).toBe('2026-03-20T00:00:00Z');
+ expect(readJSONFile).not.toHaveBeenCalled();
+ });
+
+ it('handles commits without conventional format', async () => {
+ execFileSync.mockReturnValue(
+ `abc12345${NUL}feat(cos): add feature${NUL}2026-03-23 10:00:00 -0700\n` +
+ `bbb22222${NUL}Merge branch main${NUL}2026-03-23 08:00:00 -0700`
+ );
+ const result = await getRecentChanges();
+ expect(result.features).toHaveLength(1);
+ expect(result.fixes).toHaveLength(0);
+ expect(result.other).toHaveLength(0);
+ });
+
+ it('handles feat commits without scope', async () => {
+ execFileSync.mockReturnValue(`abc12345${NUL}feat: global feature${NUL}2026-03-23 10:00:00 -0700`);
+ const result = await getRecentChanges();
+ expect(result.features).toHaveLength(1);
+ expect(result.features[0].parsed.scope).toBeNull();
+ expect(result.features[0].parsed.description).toBe('global feature');
+ });
+});
+
+describe('markBriefed', () => {
+ it('writes state file with current commit hash', async () => {
+ execFileSync.mockReturnValue('abc1234\n');
+ const result = await markBriefed();
+ expect(result.lastBriefedCommit).toBe('abc1234');
+ expect(result.lastBriefedAt).toBeDefined();
+ expect(writeFile).toHaveBeenCalledWith(
+ expect.stringContaining('portos-changelog.json'),
+ expect.any(String)
+ );
+ });
+});
+
+describe('getState', () => {
+ it('returns default state when no file exists', async () => {
+ readJSONFile.mockResolvedValue({ lastBriefedAt: null, lastBriefedCommit: null });
+ const state = await getState();
+ expect(state.lastBriefedAt).toBeNull();
+ expect(state.lastBriefedCommit).toBeNull();
+ });
+});