uncamp 0.0.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,248 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
3
+ import { z } from "zod";
4
+ import { readFile, access } from "node:fs/promises";
5
+ import path from "node:path";
6
+ import { spawnSync } from "node:child_process";
7
+ import { configuredProject, defaultIndexPath, upsertProject } from "../projectRoot.js";
8
+ import { loadPreferences, suppress } from "../preferences.js";
9
+ import { currentItems, readEvents } from "../memory.js";
10
+ import { getProjectGuidance, recordProjectGuidance, recordProjectOutcome, recordResourceDecision, savedMemoryForPid, } from "../guidance.js";
11
+ import { listMemory, viewMemory, editMemory, deleteMemory } from "../memoryTools.js";
12
+ import { getSession, noteWorkload, finishSession, stopNoted } from "../session.js";
13
+ import { fingerprint, moveToTrash } from "../trash.js";
14
+ import { listeningPid } from "../workloads.js";
15
+ import { SchemaError } from "../core.js";
16
+ import { configureProject, unconfigureProject } from "../setup.js";
17
+ const pkg = JSON.parse(await readFile(new URL("../../package.json", import.meta.url), "utf8"));
18
+ const server = new McpServer({ name: "uncamp", version: pkg.version }, {
19
+ instructions: [
20
+ "uncamp provides project setup, per-project memory, workload notes, preferences, and two mechanics: ",
21
+ "stopping a noted workload after an identity check, and moving an approved path to Trash after ",
22
+ "safety checks. The agent makes every decision; uncamp never decides what to keep or stop.",
23
+ ].join(""),
24
+ });
25
+ const obj = z.record(z.string(), z.any());
26
+ const preferenceUpdate = z
27
+ .object({ suppress_location: z.string().optional(), suppress_item_id: z.string().optional() })
28
+ .strict();
29
+ const result = (data) => ({
30
+ content: [{ type: "text", text: JSON.stringify(data) }],
31
+ structuredContent: data,
32
+ });
33
+ function tool(name, description, schema, handler) {
34
+ server.registerTool(name, { description, inputSchema: schema }, async (a) => result(await handler(a)));
35
+ }
36
+ const project = { project_path: z.string() };
37
+ tool("uncamp_get_project_status", "Read configured project status and current memory items", project, async (a) => {
38
+ const { root, entry, memory } = await configuredProject(a.project_path), prefs = await loadPreferences(root);
39
+ return {
40
+ project_id: entry.id,
41
+ project_path: root,
42
+ preferences: prefs,
43
+ items: await currentItems(await readEvents(memory), root),
44
+ };
45
+ });
46
+ tool("uncamp_get_session_status", "Read session state and noted workloads", { ...project, session_id: z.string().optional() }, async (a) => {
47
+ const { root } = await configuredProject(a.project_path), s = await getSession(root, a.session_id);
48
+ return {
49
+ project_path: root,
50
+ session_id: s.session_id,
51
+ session: s.session,
52
+ workloads: s.workloads,
53
+ still_running: [],
54
+ reminder: "",
55
+ };
56
+ });
57
+ tool("uncamp_note_workload", "Note a resource that continues running after its command", {
58
+ ...project,
59
+ pid: z.number().optional(),
60
+ port: z.number().optional(),
61
+ session_id: z.string().optional(),
62
+ kind: z.string().default("process"),
63
+ reason: z.string().default(""),
64
+ }, async (a) => {
65
+ const { root } = await configuredProject(a.project_path);
66
+ const pid = a.pid ?? listeningPid(a.port);
67
+ const r = await noteWorkload(root, { ...a, pid });
68
+ const saved = await savedMemoryForPid(root, pid, r.session_id);
69
+ return {
70
+ ok: true,
71
+ session_id: r.session_id,
72
+ count: r.workloads.length,
73
+ workloads: r.workloads,
74
+ pid,
75
+ saved_memory: saved,
76
+ detail: saved
77
+ .slice(0, 2)
78
+ .map((x) => x.message)
79
+ .join(" "),
80
+ };
81
+ });
82
+ tool("uncamp_record_resource_decision", "Record the end-of-task decision for a noted workload", {
83
+ ...project,
84
+ pid: z.number(),
85
+ decision: z.enum(["stop", "keep"]),
86
+ resource: z.string().optional(),
87
+ reason: z.string().optional(),
88
+ sources: z.array(z.string()).optional(),
89
+ memory_event_id: z.string().optional(),
90
+ agent: z.string().default("unknown"),
91
+ session_id: z.string().optional(),
92
+ }, recordResourceDecision);
93
+ tool("uncamp_finish_session", "Close a session record without stopping workloads", { ...project, session_id: z.string().optional() }, async (a) => {
94
+ const { root } = await configuredProject(a.project_path), r = await finishSession(root, a.session_id), workloads = r.session?.workloads ?? [], still_running = workloads.filter((x) => x.running).map((x) => x.pid), unkept = workloads.filter((x) => x.running && x.decision?.outcome !== "keep").map((x) => x.pid);
95
+ return {
96
+ project_path: root,
97
+ session_id: r.session_id,
98
+ session: r.session,
99
+ workloads,
100
+ still_running,
101
+ reminder: unkept.length
102
+ ? `Still running although the decision is stop: ${unkept.join(", ")}. ` +
103
+ "Stop them with uncamp_stop_workload before your final answer."
104
+ : "",
105
+ };
106
+ });
107
+ tool("uncamp_stop_workload", "Stop a noted workload after rechecking identity", { ...project, pid: z.number(), session_id: z.string().optional(), grace_seconds: z.number().default(5) }, async (a) => {
108
+ const { root } = await configuredProject(a.project_path);
109
+ return stopNoted(root, a.pid, a.session_id, a.grace_seconds);
110
+ });
111
+ tool("uncamp_move_to_trash", "Move an approved exact project path to Trash", { ...project, path: z.string(), user_approval: z.string().default(""), expected_fingerprint: z.string().optional() }, async (a) => {
112
+ const { root } = await configuredProject(a.project_path), raw = path.resolve(root, a.path);
113
+ if (!raw.startsWith(root + path.sep))
114
+ throw new SchemaError(`outside-selected-project: ${a.path}`);
115
+ const fp = await fingerprint(raw);
116
+ if (a.expected_fingerprint && fp !== a.expected_fingerprint)
117
+ throw new SchemaError(`fingerprint-mismatch: ${path.relative(root, raw)}`);
118
+ if (!a.user_approval.trim())
119
+ throw new SchemaError("explicit user approval for this exact path is required (pass the user's words as user_approval)");
120
+ const dest = await moveToTrash(root, path.relative(root, raw), fp);
121
+ return {
122
+ status: "moved_to_trash",
123
+ path: raw,
124
+ trash_destination: dest,
125
+ fingerprint: fp,
126
+ detail: "Moved to the Trash. Record it with uncamp_record_verified_outcome (outcome moved, trash_destination).",
127
+ };
128
+ });
129
+ tool("uncamp_get_project_preferences", "Read uncamp project preferences", project, async (a) => {
130
+ const { root } = await configuredProject(a.project_path);
131
+ return { ok: true, preferences: await loadPreferences(root) };
132
+ });
133
+ tool("uncamp_update_project_preferences", "Update project suppressions", { ...project, update: preferenceUpdate }, async (a) => {
134
+ const { root } = await configuredProject(a.project_path), u = a.update;
135
+ if (!Object.keys(u).length)
136
+ throw new SchemaError("provide at least one preference change");
137
+ if (u.suppress_location)
138
+ await suppress(root, { location: u.suppress_location, whatId: u.suppress_item_id });
139
+ return { ok: true, preferences: await loadPreferences(root) };
140
+ });
141
+ tool("uncamp_review_project", "Review project records", { ...project }, async (a) => {
142
+ const { root, memory } = await configuredProject(a.project_path);
143
+ return {
144
+ project_path: root,
145
+ suppressions: (await loadPreferences(root)).suppressed_items,
146
+ items: await currentItems(await readEvents(memory), root),
147
+ standing_approvals: [],
148
+ };
149
+ });
150
+ tool("uncamp_get_project_guidance", "Read current project guidance", { ...project, item_ids: z.array(z.string()).optional(), location_prefix: z.string().optional() }, (a) => getProjectGuidance(a.project_path, a.item_ids, a.location_prefix));
151
+ tool("uncamp_record_project_guidance", "Record or revise scoped project guidance", {
152
+ ...project,
153
+ item: obj,
154
+ recommendations: z.array(obj),
155
+ claim: z.enum(["observed", "inferred", "verified"]),
156
+ agent: z.string(),
157
+ session_id: z.string(),
158
+ base_event_id: z.string().optional(),
159
+ }, recordProjectGuidance);
160
+ tool("uncamp_record_verified_outcome", "Record an action already completed", {
161
+ ...project,
162
+ session_id: z.string(),
163
+ agent: z.string(),
164
+ item: obj,
165
+ outcome: z.string(),
166
+ summary: z.string(),
167
+ evidence: z.array(z.string()),
168
+ can_go_when: z.string().optional(),
169
+ workload_pid: z.number().optional(),
170
+ trash_destination: z.string().optional(),
171
+ tool: z.string().optional(),
172
+ operation_id: z.string().optional(),
173
+ }, recordProjectOutcome);
174
+ tool("uncamp_setup_project", "Configure project rules and registration", { ...project, agent: z.enum(["codex", "claude", "cursor"]) }, async (a) => {
175
+ const root = path.resolve(a.project_path);
176
+ await configureProject(root, [a.agent]);
177
+ await upsertProject(defaultIndexPath(), {
178
+ project_id: path.basename(root),
179
+ memory_dir: path.join(root, ".uncamp", "memory"),
180
+ roots: [root],
181
+ });
182
+ return { ok: true, project_path: root, status: "configured", actions: [`configured ${a.agent}`] };
183
+ });
184
+ tool("uncamp_remove_project", "Remove project wiring and registration", { ...project }, async (a) => {
185
+ const { root } = await configuredProject(a.project_path);
186
+ await unconfigureProject(root);
187
+ return {
188
+ ok: true,
189
+ project_path: root,
190
+ status: "removed",
191
+ actions: ["removed project wiring"],
192
+ retained_records: [path.join(root, ".uncamp/memory"), path.join(root, ".uncamp/sessions")],
193
+ };
194
+ });
195
+ tool("uncamp_clear_project_memory", "Move project memory to Trash", { ...project }, async (a) => {
196
+ const { root, memory } = await configuredProject(a.project_path);
197
+ if (memory !== path.join(root, ".uncamp", "memory"))
198
+ throw new SchemaError("memory is stored at a nonstandard project path; refusing to clear an ambiguous location");
199
+ try {
200
+ await access(memory);
201
+ }
202
+ catch {
203
+ return { ok: true, project_path: root, status: "already_clear" };
204
+ }
205
+ const script = [
206
+ "import Foundation",
207
+ "let url = URL(fileURLWithPath: CommandLine.arguments[1])",
208
+ "var result: NSURL?",
209
+ 'do { try FileManager.default.trashItem(at: url, resultingItemURL: &result); print(result?.path ?? "") }',
210
+ 'catch { fputs("\\(error)\\n", stderr); exit(1) }',
211
+ ].join("\n");
212
+ const r = spawnSync("swift", ["-", memory], { input: script, encoding: "utf8" });
213
+ if (r.status !== 0)
214
+ throw new Error(r.stderr || "Trash move failed");
215
+ return {
216
+ ok: true,
217
+ project_path: root,
218
+ status: "moved_to_trash",
219
+ trash_path: r.stdout.trim(),
220
+ actions: ["moved project memory to Trash"],
221
+ };
222
+ });
223
+ tool("uncamp_list_memory", "List current memory entries", project, async (a) => {
224
+ const { root } = await configuredProject(a.project_path);
225
+ return listMemory(root);
226
+ });
227
+ tool("uncamp_view_memory", "View a memory entry and its revisions", { ...project, item_id: z.string() }, async (a) => {
228
+ const { root } = await configuredProject(a.project_path);
229
+ return viewMemory(root, a.item_id);
230
+ });
231
+ tool("uncamp_edit_memory", "Revise a memory entry with user words", {
232
+ ...project,
233
+ item_id: z.string(),
234
+ base_event_id: z.string(),
235
+ recommendations: z.array(obj),
236
+ reason: z.string(),
237
+ sources: z.array(z.string()),
238
+ }, async (a) => {
239
+ const { root } = await configuredProject(a.project_path);
240
+ return editMemory(root, a);
241
+ });
242
+ tool("uncamp_delete_memory", "Move a memory entry and its history to Trash with user words", { ...project, item_id: z.string(), reason: z.string(), sources: z.array(z.string()) }, async (a) => {
243
+ const { root } = await configuredProject(a.project_path);
244
+ return deleteMemory(root, a);
245
+ });
246
+ export async function startServer() {
247
+ await server.connect(new StdioServerTransport());
248
+ }
package/dist/memory.js ADDED
@@ -0,0 +1,199 @@
1
+ import { mkdir, readdir, readFile, stat } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { appendLine, atomicWriteText, dumpFrontmatter, loadFrontmatter, normalizeLocation, redactText, validateMemoryEvent, SchemaError, } from "./core.js";
4
+ import { isUncampState } from "./trash.js";
5
+ export const defaultMemoryDir = (root) => path.join(path.resolve(root), ".uncamp", "memory");
6
+ export const defaultMemoryLog = (root) => path.join(path.resolve(root), ".uncamp", "memory.jsonl");
7
+ function sanitize(raw, redact = true) {
8
+ const e = structuredClone(raw);
9
+ if (redact && typeof e.why === "string")
10
+ e.why = redactText(e.why);
11
+ if (redact && Array.isArray(e.recommendations))
12
+ for (const r of e.recommendations)
13
+ for (const k of ["situation", "recommendation", "scope", "evidence", "conditions", "rechecks", "sources"])
14
+ if (typeof r[k] === "string")
15
+ r[k] = redactText(r[k]);
16
+ else if (Array.isArray(r[k]))
17
+ r[k] = r[k].map((x) => (typeof x === "string" ? redactText(x) : x));
18
+ return validateMemoryEvent(e);
19
+ }
20
+ function toMeta(e) {
21
+ const w = e.what ?? {}, a = e.agent ?? {}, p = e.project ?? {}, c = e.created ?? {}, g = e.event_type === "item_instruction";
22
+ const m = {
23
+ schema_version: e.schema_version,
24
+ event_id: e.event_id,
25
+ event_type: e.event_type,
26
+ status: e.status ?? "active",
27
+ claim: e.claim,
28
+ "what.id": w.id,
29
+ "what.name": w.name,
30
+ "what.kind": w.kind,
31
+ "what.location": w.location,
32
+ "what.bytes": w.bytes ?? null,
33
+ "what.completeness": w.completeness ?? null,
34
+ "agent.harness": a.harness,
35
+ "agent.session_id": a.session_id,
36
+ "project.id": p.id,
37
+ "project.consumers": p.consumers ?? [],
38
+ "created.at": c.at,
39
+ "created.source": c.source,
40
+ correction_of: e.correction_of,
41
+ };
42
+ if (g)
43
+ m.recommendations = e.recommendations;
44
+ else {
45
+ m.action = e.action ?? null;
46
+ m.can_go_when = e.can_go_when;
47
+ m.evidence_ids = e.evidence_ids ?? [];
48
+ }
49
+ for (const k of ["runtime_identity"])
50
+ if (w[k] != null)
51
+ m[`what.${k}`] = w[k];
52
+ for (const k of ["cleanup", "review", "resource_observation", "proposal", "approvals", "attribution"])
53
+ if (e[k] != null)
54
+ m[k] = e[k];
55
+ return [m, g ? "" : `${(e.why ?? "").trim()}\n`];
56
+ }
57
+ function fromMeta(m, body) {
58
+ const g = m.event_type === "item_instruction";
59
+ const e = {
60
+ schema_version: Number(m.schema_version || 1),
61
+ event_id: m.event_id,
62
+ event_type: m.event_type,
63
+ status: m.status ?? "active",
64
+ what: {
65
+ id: m["what.id"],
66
+ name: m["what.name"],
67
+ kind: m["what.kind"],
68
+ location: m["what.location"],
69
+ bytes: m["what.bytes"],
70
+ completeness: m["what.completeness"],
71
+ },
72
+ claim: m.claim,
73
+ agent: { harness: m["agent.harness"], session_id: m["agent.session_id"] },
74
+ project: { id: m["project.id"], consumers: m["project.consumers"] ?? [] },
75
+ created: { at: m["created.at"], source: m["created.source"] },
76
+ correction_of: m.correction_of,
77
+ };
78
+ if (g)
79
+ e.recommendations = m.recommendations ?? [];
80
+ else
81
+ Object.assign(e, {
82
+ action: m.action,
83
+ why: body.trim(),
84
+ can_go_when: m.can_go_when,
85
+ evidence_ids: m.evidence_ids ?? [],
86
+ });
87
+ if (m["what.runtime_identity"])
88
+ e.what.runtime_identity = m["what.runtime_identity"];
89
+ for (const k of ["cleanup", "review", "resource_observation", "proposal", "approvals", "attribution"])
90
+ if (m[k] !== undefined)
91
+ e[k] = m[k];
92
+ return e;
93
+ }
94
+ export async function writeEventsMarkdown(dir, events, opts = {}) {
95
+ await mkdir(dir, { recursive: true });
96
+ const written = [];
97
+ for (const raw of events) {
98
+ const e = sanitize(raw, opts.redact !== false);
99
+ if (e.event_type === "item_instruction") {
100
+ const current = await currentItems(await readEvents(dir));
101
+ const prev = current.find((x) => x.id === e.what.id);
102
+ if (prev && e.correction_of !== prev.event_id)
103
+ throw new SchemaError("item changed since it was read; reload and reconcile the latest instruction");
104
+ if (prev && prev.location !== e.what.location && !e.correction_of)
105
+ throw new SchemaError("moving an item requires a revision of its stable what.id");
106
+ }
107
+ e.status ??= "active";
108
+ const [meta, body] = toMeta(e);
109
+ const file = path.join(dir, `${String(e.event_id).replace(/[^a-zA-Z0-9._-]+/g, "_")}.md`);
110
+ try {
111
+ await stat(file);
112
+ if (e.event_type === "item_instruction")
113
+ throw new SchemaError("item revisions require a new event_id; history must not be overwritten");
114
+ }
115
+ catch (err) {
116
+ if (err?.code !== "ENOENT")
117
+ throw err;
118
+ }
119
+ await atomicWriteText(file, dumpFrontmatter(meta, body));
120
+ written.push(e);
121
+ }
122
+ if (!written.length)
123
+ throw new SchemaError("at least one memory event is required");
124
+ return written;
125
+ }
126
+ export async function appendEvents(file, events, redact = true) {
127
+ const rows = events.map((e) => sanitize(e, redact));
128
+ for (const e of rows)
129
+ await appendLine(file, JSON.stringify(e));
130
+ if (!rows.length)
131
+ throw new SchemaError("at least one memory event is required");
132
+ return rows;
133
+ }
134
+ export async function readEvents(source) {
135
+ let s;
136
+ try {
137
+ s = await stat(source);
138
+ }
139
+ catch {
140
+ return [];
141
+ }
142
+ if (s.isDirectory()) {
143
+ const files = (await readdir(source)).filter((f) => f.endsWith(".md")).sort();
144
+ const out = [];
145
+ for (const f of files) {
146
+ const [meta, body] = loadFrontmatter(await readFile(path.join(source, f), "utf8"));
147
+ if (meta.event_id)
148
+ out.push(fromMeta(meta, body));
149
+ }
150
+ return out;
151
+ }
152
+ const text = await readFile(source, "utf8");
153
+ return text
154
+ .split(/\r?\n/)
155
+ .filter(Boolean)
156
+ .map((l, i) => {
157
+ try {
158
+ return JSON.parse(l);
159
+ }
160
+ catch {
161
+ throw new SchemaError(`torn or invalid JSONL at ${source}:${i + 1}`);
162
+ }
163
+ });
164
+ }
165
+ export async function currentItems(events, root) {
166
+ const corrected = new Set(events.map((e) => e.correction_of).filter(Boolean));
167
+ const rows = [];
168
+ for (const e of events) {
169
+ if (e.event_type !== "item_instruction")
170
+ continue;
171
+ if (e.schema_version !== 2)
172
+ throw new SchemaError("item_instruction schema_version must be 2");
173
+ if (corrected.has(e.event_id) || e.status === "inactive")
174
+ continue;
175
+ const loc = normalizeLocation(e.what.location);
176
+ if (!(loc.startsWith("/") || loc.startsWith("runtime://")))
177
+ continue;
178
+ if (loc.startsWith("/") && isUncampState(loc))
179
+ continue;
180
+ if (root) {
181
+ const { isSuppressed } = await import("./preferences.js");
182
+ if (await isSuppressed(root, { location: loc, whatId: e.what.id }))
183
+ continue;
184
+ }
185
+ if ((e.status ?? "active") !== "active")
186
+ continue;
187
+ rows.push({
188
+ id: e.what.id,
189
+ name: e.what.name,
190
+ kind: e.what.kind,
191
+ location: loc,
192
+ event_id: e.event_id,
193
+ claim: e.claim,
194
+ agent: e.agent?.harness,
195
+ recommendations: e.recommendations,
196
+ });
197
+ }
198
+ return rows.sort((a, b) => a.kind.localeCompare(b.kind) || a.name.localeCompare(b.name) || a.id.localeCompare(b.id));
199
+ }
@@ -0,0 +1 @@
1
+ export { listMemory, viewMemory, editMemory, deleteMemory } from "./guidance.js";
@@ -0,0 +1,97 @@
1
+ import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
2
+ import path from "node:path";
3
+ export function preferencesPath(root) {
4
+ return path.join(root, ".uncamp", "preferences.json");
5
+ }
6
+ export async function loadPreferences(root, opts = {}) {
7
+ const file = preferencesPath(root);
8
+ let d;
9
+ try {
10
+ d = JSON.parse(await readFile(file, "utf8"));
11
+ }
12
+ catch { }
13
+ if (!d) {
14
+ try {
15
+ const old = JSON.parse(await readFile(path.join(root, ".uncamp", "suppressed-items.json"), "utf8"));
16
+ d = { suppressed_items: old.items ?? old.suppressed_items };
17
+ }
18
+ catch { }
19
+ }
20
+ const prefs = {
21
+ schema_version: 1,
22
+ updated_at: d?.updated_at ?? "",
23
+ configured: d?.configured ?? true,
24
+ suppressed_items: Array.isArray(d?.suppressed_items) ? d.suppressed_items : [],
25
+ ...(Array.isArray(d?.agents) ? { agents: d.agents } : {}),
26
+ };
27
+ if (opts.migrate !== false && d && !(await exists(file)))
28
+ await writePreferences(root, {
29
+ suppressedItems: prefs.suppressed_items,
30
+ configured: prefs.configured,
31
+ agents: prefs.agents,
32
+ });
33
+ return prefs;
34
+ }
35
+ async function exists(file) {
36
+ try {
37
+ await readFile(file);
38
+ return true;
39
+ }
40
+ catch {
41
+ return false;
42
+ }
43
+ }
44
+ export async function writePreferences(root, updates = {}) {
45
+ const old = await loadPreferences(root, { migrate: false }), data = {
46
+ schema_version: 1,
47
+ updated_at: new Date().toISOString(),
48
+ configured: updates.configured ?? old.configured,
49
+ suppressed_items: updates.suppressedItems ?? old.suppressed_items,
50
+ ...((updates.agents ?? old.agents) ? { agents: updates.agents ?? old.agents } : {}),
51
+ };
52
+ const file = preferencesPath(root);
53
+ await mkdir(path.dirname(file), { recursive: true });
54
+ const tmp = `${file}.tmp`;
55
+ await writeFile(tmp, JSON.stringify(data, null, 2) + "\n");
56
+ await rename(tmp, file);
57
+ return file;
58
+ }
59
+ export async function suppress(root, input) {
60
+ if (!input.location.trim())
61
+ throw new Error("location required");
62
+ const p = await loadPreferences(root);
63
+ const rows = [
64
+ ...p.suppressed_items.filter((x) => !(x.location === input.location && x.what_id === (input.whatId ?? null))),
65
+ {
66
+ location: input.location,
67
+ what_id: input.whatId ?? null,
68
+ name: input.name ?? null,
69
+ suppressed_at: new Date().toISOString(),
70
+ },
71
+ ];
72
+ return writePreferences(root, { suppressedItems: rows });
73
+ }
74
+ export async function unsuppress(root, input) {
75
+ if (!input.location && !input.whatId)
76
+ throw new Error("location or what_id required");
77
+ const p = await loadPreferences(root);
78
+ return writePreferences(root, {
79
+ suppressedItems: p.suppressed_items.filter((x) => !(input.whatId ? x.what_id === input.whatId : x.location === input.location)),
80
+ });
81
+ }
82
+ export async function isSuppressed(root, input) {
83
+ if (!root)
84
+ return false;
85
+ const p = await loadPreferences(root), loc = (input.location || "").trim(), wid = input.whatId || undefined;
86
+ return p.suppressed_items.some((x) => {
87
+ if (wid && x.what_id === wid)
88
+ return true;
89
+ if (!loc)
90
+ return false;
91
+ if (x.location === loc)
92
+ return !x.what_id || x.what_id === wid;
93
+ return (!x.what_id &&
94
+ loc.startsWith("/") &&
95
+ (loc === x.location || loc.startsWith(String(x.location).replace(/\/$/, "") + "/")));
96
+ });
97
+ }