Skip to content

The open source AI video agent: turns any coding agent into a video agent, with an editor to change anything it makes.

Desktop: unlink expired skill sessions without touching real skills (#302)

千颜cf06197212af
diff --git a/.changeset/session-skills-cleanup-links.md b/.changeset/session-skills-cleanup-links.md
new file mode 100644
index 0000000..5a696d6
--- /dev/null
+++ b/.changeset/session-skills-cleanup-links.md
@@ -0,0 +1,5 @@
+---
+"@openfilm/desktop": patch
+---
+
+Expired agent skill sessions now remove only their own links and files, never the real skills those links point at.
diff --git a/apps/desktop/src/agent-skills.mjs b/apps/desktop/src/agent-skills.mjs
index ff43f1a..efdc338 100644
--- a/apps/desktop/src/agent-skills.mjs
+++ b/apps/desktop/src/agent-skills.mjs
@@ -29,7 +29,7 @@
* A session's OpenFilm skills are a folder of the app's, links to each skill's own folder (agent-skills/<id>/skills),
* as each agent reads a plugin or a skills folder. Reads no Electron module, so `node --test` can use it.
*/
-import { mkdirSync, readFileSync, readdirSync, rmSync, statSync, symlinkSync, writeFileSync } from 'node:fs';
+import { mkdirSync, readFileSync, readdirSync, rmSync, statSync, symlinkSync, unlinkSync, writeFileSync } from 'node:fs';
import { homedir } from 'node:os';
import { basename, dirname, join, resolve } from 'node:path';
import { createRequire } from 'node:module';
@@ -210,11 +210,21 @@ export function ownMcpServers(agent, { cwd = '', env = {}, home = homedir() } =
/* ── a session's switches ────────────────────────────────────────────────── */
+/** Remove an expired session's links before its own folder, never anything they point at. */
+function removeSession(dir) {
+ for (const entry of readdirSync(dir, { withFileTypes: true })) {
+ const path = join(dir, entry.name);
+ if (entry.isSymbolicLink()) unlinkSync(path);
+ else if (entry.isDirectory()) removeSession(path);
+ }
+ rmSync(dir, { recursive: true, force: true });
+}
+
/** A folder of links to OpenFilm's skills, as a Claude Code plugin and as a skills folder (`skills`, `.agents/skills`). */
function linkFolder(base, skills) {
mkdirSync(base, { recursive: true });
for (const name of subdirs(base)) {
- try { if (Date.now() - statSync(join(base, name)).mtimeMs > KEEP_MS) rmSync(join(base, name), { recursive: true, force: true }); } catch { /* in use */ }
+ try { if (Date.now() - statSync(join(base, name)).mtimeMs > KEEP_MS) removeSession(join(base, name)); } catch { /* in use */ }
}
const dir = join(base, `${Date.now().toString(36)}-${process.pid}-${Math.random().toString(36).slice(2, 8)}`);
const link = process.platform === 'win32' ? 'junction' : 'dir';
diff --git a/apps/desktop/src/agent-skills.test.mjs b/apps/desktop/src/agent-skills.test.mjs
index 63f5ada..4124398 100644
--- a/apps/desktop/src/agent-skills.test.mjs
+++ b/apps/desktop/src/agent-skills.test.mjs
@@ -1,8 +1,8 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
-import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, writeFileSync } from 'node:fs';
+import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, utimesSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
-import { join } from 'node:path';
+import { dirname, join } from 'node:path';
import { codexServers, mergeConfig, ownMcpServers, ownSkills, sessionSkills, skillStore } from './agent-skills.mjs';
/* which official skills are installed is read from Studio's prefs.json: a scratch home, never the person's */
@@ -111,6 +111,20 @@ test("OpenCode: every skill denied but its own, OpenFilm's and those let in; Pi:
assert.equal(realpathSync(join(pi.piSkills.paths[0], 'brand')), realpathSync(join(w.project, 'skills', 'brand')));
});
+test('expired session cleanup unlinks skills without removing their real folders', async () => {
+ const w = world();
+ const first = await sessionSkills('byok', { cwd: w.project, home: w.home, dataDir: w.dataDir, mine: join(w.openfilmHome, 'skills'), prefsHome: w.openfilmHome });
+ const expired = dirname(first.piSkills.paths[0]);
+ const old = Date.now() / 1000 - 3 * 24 * 60 * 60;
+ utimesSync(expired, old, old);
+ const second = await sessionSkills('byok', { cwd: w.project, home: w.home, dataDir: w.dataDir, mine: join(w.openfilmHome, 'skills'), prefsHome: w.openfilmHome });
+ assert.notEqual(dirname(second.piSkills.paths[0]), expired);
+ assert.equal(existsSync(expired), false, 'the expired session itself is removed');
+ assert.equal(readFileSync(join(w.project, 'skills', 'brand', 'SKILL.md'), 'utf8').includes('name: brand'), true, 'the project skill is untouched');
+ assert.equal(readFileSync(join(w.openfilmHome, 'skills', 'lyric-pv', 'SKILL.md'), 'utf8').includes('name: lyric-pv'), true, 'the personal skill is untouched');
+ assert.equal(realpathSync(join(second.piSkills.paths[0], 'brand')), realpathSync(join(w.project, 'skills', 'brand')), 'the next session links to the same skill again');
+});
+
test("an OpenFilm skill the person turned off is given to no session", async () => {
const w = world();
mkdirSync(w.openfilmHome, { recursive: true });