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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Gopikrishnan Sasikumar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,2 +1,65 @@
1
- This package name is reserved.
2
- The uncamp tool is coming soon.
1
+ # uncamp
2
+
3
+ uncamp is a plugin for coding agents (Claude Code, Codex and Cursor) that helps them leave the Mac the way they found it. When an agent starts a dev server, a watcher, a container or anything else that keeps running or keeps using CPU, memory or disk, uncamp has it note the resource, decide what should happen to it when the work is done, and follow that decision before it replies.
4
+
5
+ uncamp is only a plugin: skills, a one-line agent rule, and a small MCP server, shown through the coding agent's own interface. There are no hooks, no background process and no separate app.
6
+
7
+ ## The idea
8
+
9
+ The coding agent makes the decisions. uncamp gives it a per-project memory and a few safe mechanics.
10
+
11
+ - **The agent decides.** When it first meets a resource, the agent checks the project's memory. If nothing covers the resource, it looks at what started it, whether the user asked for it, and what depends on it, decides what should happen at the end of the task, and writes that decision to memory.
12
+ - **Memory carries the decision forward.** At the end of the task the agent follows the memory. Next time the same kind of situation comes up in that project, the memory is already there.
13
+ - **The user corrects by talking.** If the user says "keep that running" or "don't leave it up next time", the agent revises the memory entry and records the user's words as its source.
14
+ - **Never assume a keep.** A resource stays after the task only when the user explicitly asked for it or a memory entry the user confirmed says so. Asking for a URL or a port is not a keep request.
15
+ - **uncamp does the mechanics.** Stopping a noted process with an identity check, moving a file to the Trash after safety checks, and reading and writing memory. uncamp never deletes permanently and never empties the Trash.
16
+
17
+ ## Example
18
+
19
+ > You: start the preview and give me the URL.
20
+ >
21
+ > The agent starts the server, notes it with uncamp, and finds no memory for it. You started nothing yourself and did not ask for it to stay, so it records "stop at the end of the task" and gives you the URL. Before replying it stops the server, checks it is gone, and records the outcome.
22
+ >
23
+ > You: actually, keep the preview running in this project.
24
+ >
25
+ > The agent revises the memory entry to "keep running", with your words as the source. From then on it leaves that preview up in this project.
26
+
27
+ ## Install
28
+
29
+ uncamp is a Node 22 package (`uncamp` on npm; not published yet). From this checkout:
30
+
31
+ ```sh
32
+ npm install && npm run build
33
+ node dist/cli.js install # detected hosts among Claude Code, Codex, Cursor
34
+ node dist/cli.js install --host codex,claude,cursor
35
+ node dist/cli.js uninstall --host codex,claude,cursor # keeps project memory
36
+ ```
37
+
38
+ Once it is on npm this becomes `npx uncamp install`. Install copies the runtime to `~/.uncamp/runtime`, registers the
39
+ MCP server, plugin and skills for each host, and backs up every host config file it edits (`*.uncamp-backup-<time>`).
40
+ v1 supports Claude Code, Codex and Cursor; Gemini CLI and Antigravity bundles are later work.
41
+
42
+ Then, in a project, ask the agent to set up uncamp (`$uncamp setup` in Codex, or "set up uncamp for this project").
43
+
44
+ ## Memory
45
+
46
+ Each project's memory is markdown notes in `.uncamp/memory/`. Ask the agent to show, change or forget what uncamp
47
+ remembers: it lists and views entries freely, and edits or forgets one only with your own words as the source.
48
+ Forgetting moves the entry's notes to the Trash.
49
+
50
+ ## Safety and privacy
51
+
52
+ - uncamp works inside configured projects. It is not a Mac cleaner and does not scan the whole Mac.
53
+ - Removing anything on disk needs your explicit yes for that exact path. Files go to the Trash after protected-path and fingerprint checks.
54
+ - Global host opt-outs live in `~/.uncamp/host-opt-outs.json` (`{"hosts":["cursor"]}`); `UNCAMP_DISABLED_HOSTS` adds comma-separated host names.
55
+ - Project records live in the project's `.uncamp/` folder on your Mac.
56
+
57
+ ## Learn more
58
+
59
+ - [Engineering guide](docs/engineering.md): how skills, rules, MCP and memory fit together.
60
+ - [Abstraction audit](docs/abstraction-audit.md): what uncamp's code still decides and why.
61
+ - [Release gates](docs/release-gates.md) and [skill-trigger results](docs/skill-trigger-eval.md).
62
+
63
+ ## Licence
64
+
65
+ [MIT](LICENSE).
@@ -0,0 +1 @@
1
+ If your work starts something that keeps running or keeps holding CPU, memory, or disk after its command (for example a server or preview, even for a quick check), note it with uncamp MCP right after launch, decide and record with uncamp what should happen to it when the work is done, and follow the uncamp-session-end skill before your final answer, including for side steps. Never assume a keep.
@@ -0,0 +1,47 @@
1
+ import path from "node:path";
2
+ import { currentItems, defaultMemoryDir, readEvents } from "./memory.js";
3
+ import { fingerprint } from "./trash.js";
4
+ /** Normalize an approval record and reject incomplete path or fingerprint pairs. */
5
+ export function normalizeApproval(entry) {
6
+ if (!entry || typeof entry !== "object")
7
+ return undefined;
8
+ const target = entry.path || entry.location;
9
+ const expected = entry.fingerprint || entry.expected_fingerprint;
10
+ if (typeof target !== "string" || !target.trim())
11
+ return undefined;
12
+ if (typeof expected !== "string" || !expected.trim())
13
+ return undefined;
14
+ return { path: target, fingerprint: expected };
15
+ }
16
+ /** Extract normalized approvals from a memory event. */
17
+ export function approvalsFromEvent(event) {
18
+ const raw = event?.approvals ?? event?.what?.approvals;
19
+ return Array.isArray(raw) ? raw.map(normalizeApproval).filter(Boolean) : [];
20
+ }
21
+ /** Load unique approvals attached to current project memory entries. */
22
+ export async function loadProjectApprovals(projectRoot) {
23
+ const root = path.resolve(projectRoot);
24
+ const events = await readEvents(defaultMemoryDir(root));
25
+ const byId = new Map(events.filter((event) => event.event_id).map((event) => [event.event_id, event]));
26
+ const items = await currentItems(events, root);
27
+ const seen = new Set();
28
+ const approvals = [];
29
+ for (const item of items) {
30
+ for (const approval of approvalsFromEvent(byId.get(item.event_id))) {
31
+ const key = `${approval.path}\0${approval.fingerprint}`;
32
+ if (seen.has(key))
33
+ continue;
34
+ seen.add(key);
35
+ approvals.push(approval);
36
+ }
37
+ }
38
+ return approvals;
39
+ }
40
+ /** Check whether an exact target fingerprint has an approval. */
41
+ export async function exactItemApproved(target, approvals, expected) {
42
+ const actual = expected ?? (await fingerprint(target));
43
+ return approvals.some((approval) => {
44
+ const row = normalizeApproval(approval);
45
+ return row && path.resolve(row.path) === path.resolve(target) && row.fingerprint === actual;
46
+ });
47
+ }
package/dist/cli.js ADDED
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env node
2
+ import { readFile } from "node:fs/promises";
3
+ import { projectRegister } from "./projectRoot.js";
4
+ import { configureProject, runInstall, runUninstall, unconfigureProject } from "./setup.js";
5
+ const pkg = JSON.parse(await readFile(new URL("../package.json", import.meta.url), "utf8"));
6
+ const args = process.argv.slice(2);
7
+ const help = [
8
+ "uncamp commands: install [--host codex,claude,cursor] [--dry-run], uninstall [--host ...] [--dry-run],",
9
+ "project register <path>, project setup <path> --host <h>, project remove <path>, mcp",
10
+ ].join(" ");
11
+ try {
12
+ if (args.includes("--mode"))
13
+ throw new Error("unknown option: --mode");
14
+ if (args[0] === "--version" || args[0] === "-v") {
15
+ console.log(pkg.version);
16
+ }
17
+ else if (args[0] === "--help" || args[0] === "-h" || !args.length) {
18
+ console.log(help);
19
+ }
20
+ else if (args[0] === "project" && args[1] === "register" && args[2]) {
21
+ await projectRegister(args[2]);
22
+ }
23
+ else if (args[0] === "project" && args[1] === "setup" && args[2]) {
24
+ const h = args[args.indexOf("--host") + 1];
25
+ console.log(JSON.stringify(await configureProject(args[2], [h])));
26
+ }
27
+ else if (args[0] === "project" && args[1] === "remove" && args[2]) {
28
+ console.log(JSON.stringify(await unconfigureProject(args[2])));
29
+ }
30
+ else if (args[0] === "install" || args[0] === "uninstall") {
31
+ const hostsArg = args.find((a) => a.startsWith("--host="))?.split("=")[1] ??
32
+ (args.includes("--host") ? args[args.indexOf("--host") + 1] : undefined);
33
+ const dry = args.includes("--dry-run");
34
+ const result = args[0] === "install"
35
+ ? await runInstall(hostsArg?.split(","), dry)
36
+ : await runUninstall(hostsArg?.split(","), dry);
37
+ console.log(JSON.stringify({
38
+ status: dry ? "dry-run" : args[0] === "install" ? "installed" : "uninstalled",
39
+ actions: result,
40
+ }));
41
+ }
42
+ else if (args[0] === "mcp") {
43
+ const { startServer } = await import("./mcp/server.js");
44
+ await startServer();
45
+ }
46
+ else
47
+ throw new Error(help);
48
+ }
49
+ catch (e) {
50
+ console.error(e instanceof Error ? e.message : String(e));
51
+ process.exitCode = 2;
52
+ }
package/dist/core.js ADDED
@@ -0,0 +1,373 @@
1
+ import { mkdir, open, readFile, rename, unlink } from "node:fs/promises";
2
+ import path from "node:path";
3
+ export class SchemaError extends Error {
4
+ name = "SchemaError";
5
+ }
6
+ export const record = (v, label) => {
7
+ if (!v || typeof v !== "object" || Array.isArray(v))
8
+ throw new SchemaError(`${label} must be an object`);
9
+ return v;
10
+ };
11
+ export const required = (v, label) => {
12
+ if (typeof v !== "string" || !v.trim())
13
+ throw new SchemaError(`${label} must be a non-empty string`);
14
+ return v;
15
+ };
16
+ export async function atomicWriteText(file, text) {
17
+ await mkdir(path.dirname(file), { recursive: true });
18
+ const tmp = path.join(path.dirname(file), `.${path.basename(file)}.${process.pid}.${Date.now()}.tmp`);
19
+ const fh = await open(tmp, "w", 0o600);
20
+ try {
21
+ await fh.writeFile(text, "utf8");
22
+ await fh.sync();
23
+ }
24
+ finally {
25
+ await fh.close();
26
+ }
27
+ await rename(tmp, file);
28
+ }
29
+ export async function appendLine(file, line) {
30
+ await mkdir(path.dirname(file), { recursive: true });
31
+ const fh = await open(file, "a", 0o600);
32
+ try {
33
+ await fh.writeFile(line.replace(/\n?$/, "\n"));
34
+ await fh.sync();
35
+ }
36
+ finally {
37
+ await fh.close();
38
+ }
39
+ }
40
+ const lockQueues = new Map();
41
+ export async function withFileLock(target, fn, timeoutMs = 10000) {
42
+ const lock = `${target}.lock`, prev = lockQueues.get(lock) ?? Promise.resolve();
43
+ let release;
44
+ const current = new Promise((r) => (release = r)), tail = prev.then(() => current);
45
+ lockQueues.set(lock, tail);
46
+ await prev;
47
+ await mkdir(path.dirname(lock), { recursive: true });
48
+ const deadline = Date.now() + timeoutMs;
49
+ let handle;
50
+ try {
51
+ while (!handle) {
52
+ try {
53
+ handle = await open(lock, "wx", 0o600);
54
+ }
55
+ catch (e) {
56
+ if (e.code !== "EEXIST" || Date.now() > deadline)
57
+ throw e;
58
+ await new Promise((r) => setTimeout(r, 20));
59
+ }
60
+ }
61
+ return await fn();
62
+ }
63
+ finally {
64
+ if (handle) {
65
+ await handle.close();
66
+ await unlink(lock).catch(() => { });
67
+ }
68
+ release();
69
+ if (lockQueues.get(lock) === tail)
70
+ lockQueues.delete(lock);
71
+ }
72
+ }
73
+ const secretPatterns = [
74
+ /\bsk-[A-Za-z0-9_-]{8,}\b/g,
75
+ /\bghp_[A-Za-z0-9]{20,}\b/g,
76
+ /\bgithub_pat_[A-Za-z0-9_]{20,}\b/g,
77
+ /\bxox[baprs]-[A-Za-z0-9-]{10,}\b/g,
78
+ /\b(api[_-]?key|token|password|secret)\s*[:=]\s*\S+/gi,
79
+ /\bBearer\s+[A-Za-z0-9._-]+/gi,
80
+ ];
81
+ export function redactText(value) {
82
+ return secretPatterns.reduce((s, re) => s.replace(re, "[redacted]"), value);
83
+ }
84
+ const fmt = (v) => v === null || v === undefined
85
+ ? "null"
86
+ : typeof v === "boolean"
87
+ ? String(v)
88
+ : typeof v === "string"
89
+ ? v.includes("\n") || /^[\[{]/.test(v)
90
+ ? JSON.stringify(v)
91
+ : v
92
+ : JSON.stringify(v);
93
+ export function dumpFrontmatter(data, body = "") {
94
+ const lines = ["---", ...Object.entries(data).map(([k, v]) => `${k}: ${fmt(v)}`), "---"];
95
+ return `${lines.join("\n")}${body ? `\n\n${body.trimEnd()}\n` : "\n"}`;
96
+ }
97
+ function parse(raw) {
98
+ if (["null", "~", ""].includes(raw))
99
+ return null;
100
+ if (raw === "true")
101
+ return true;
102
+ if (raw === "false")
103
+ return false;
104
+ if (/^-?\d+$/.test(raw))
105
+ return Number(raw);
106
+ if (/^[{[\"]/.test(raw)) {
107
+ try {
108
+ return JSON.parse(raw);
109
+ }
110
+ catch { }
111
+ }
112
+ return raw;
113
+ }
114
+ export function loadFrontmatter(text) {
115
+ const m = text.replace(/^\uFEFF/, "").match(/^---\s*\n([\s\S]*?)\n---\n?([\s\S]*)$/);
116
+ if (!m)
117
+ return [{}, text];
118
+ const data = {};
119
+ for (const line of m[1].split("\n")) {
120
+ if (!line.trim() || line.trim().startsWith("#"))
121
+ continue;
122
+ const i = line.indexOf(":");
123
+ if (i >= 0)
124
+ data[line.slice(0, i).trim()] = parse(line.slice(i + 1).trim());
125
+ }
126
+ return [data, m[2]];
127
+ }
128
+ export const normalizeLocation = (value) => value.startsWith("runtime://")
129
+ ? value
130
+ : value.startsWith("~/")
131
+ ? path.resolve(value.replace(/^~/, process.env.HOME ?? ""))
132
+ : path.normalize(value);
133
+ function runtimeIdentity(value, label) {
134
+ const x = record(value, label);
135
+ const kind = required(x.kind, `${label}.kind`), id = required(x.id, `${label}.id`);
136
+ if (kind === "process") {
137
+ required(x.started_at, `${label}.started_at`);
138
+ if (!required(x.executable, `${label}.executable`).startsWith("/"))
139
+ throw new SchemaError(`${label}.executable must be an absolute executable path`);
140
+ }
141
+ if (x.started_at != null && typeof x.started_at !== "string")
142
+ throw new SchemaError(`${label}.started_at must be a string`);
143
+ return {
144
+ kind,
145
+ id,
146
+ ...Object.fromEntries(["started_at", "executable", "name"].filter((k) => x[k] != null).map((k) => [k, x[k]])),
147
+ };
148
+ }
149
+ function validateRuntimeLocation(location, identity) {
150
+ const m = location.match(/^runtime:\/\/([^/]+)\/([^/?#]+)$/);
151
+ if (!m || m[1] !== identity.kind || decodeURIComponent(m[2]) !== identity.id)
152
+ throw new SchemaError("what.location must match its runtime identity kind and id");
153
+ }
154
+ export function validateMemoryEvent(e) {
155
+ record(e, "event");
156
+ required(e.event_id, "event_id");
157
+ const item = e.event_type === "item_instruction";
158
+ if (![
159
+ "artifact",
160
+ "setup_change",
161
+ "cleanup_outcome",
162
+ "coverage_receipt",
163
+ "correction",
164
+ "lesson",
165
+ "decision",
166
+ "cleanup_proposal",
167
+ "item_instruction",
168
+ "resource_observation",
169
+ ].includes(e.event_type))
170
+ throw new SchemaError("event_type is invalid");
171
+ if (e.schema_version !== (item ? 2 : 1))
172
+ throw new SchemaError(`${e.event_type} schema_version must be ${item ? 2 : 1}`);
173
+ const w = record(e.what, "what"), unsupported = Object.keys(w).filter((k) => !["id", "name", "kind", "location", "bytes", "completeness", "runtime_identity"].includes(k));
174
+ if (unsupported.length)
175
+ throw new SchemaError(`unsupported resource identity fields: ${unsupported.sort().join(", ")}`);
176
+ required(w.id, "what.id");
177
+ required(w.kind, "what.kind");
178
+ w.location = normalizeLocation(required(w.location, "what.location"));
179
+ if (w.runtime_identity) {
180
+ w.runtime_identity = runtimeIdentity(w.runtime_identity, "what.runtime_identity");
181
+ if (!w.location.startsWith("runtime://"))
182
+ throw new SchemaError("what.runtime_identity requires a runtime:// location");
183
+ validateRuntimeLocation(w.location, w.runtime_identity);
184
+ }
185
+ else if (w.location.startsWith("runtime://"))
186
+ throw new SchemaError("runtime item locations require what.runtime_identity");
187
+ if (item) {
188
+ const extras = Object.keys(e).filter((k) => ![
189
+ "schema_version",
190
+ "event_id",
191
+ "event_type",
192
+ "status",
193
+ "claim",
194
+ "what",
195
+ "agent",
196
+ "project",
197
+ "created",
198
+ "correction_of",
199
+ "recommendations",
200
+ "approvals",
201
+ "review",
202
+ "resource_observation",
203
+ "proposal",
204
+ "cleanup",
205
+ "attribution",
206
+ ].includes(k));
207
+ if (extras.length)
208
+ throw new SchemaError(`unsupported resource guidance fields: ${extras.sort().join(", ")}`);
209
+ required(w.name, "what.name");
210
+ if (!(w.location.startsWith("/") || w.location.startsWith("runtime://")))
211
+ throw new SchemaError("resource guidance requires an exact filesystem or runtime location");
212
+ if (!Array.isArray(e.recommendations) || !e.recommendations.length)
213
+ throw new SchemaError("recommendations must contain at least one situation");
214
+ for (let i = 0; i < e.recommendations.length; i++) {
215
+ const r = record(e.recommendations[i], `recommendations[${i}]`);
216
+ for (const k of ["situation", "recommendation", "scope", "evidence"])
217
+ required(r[k], `recommendations[${i}].${k}`);
218
+ for (const k of ["conditions", "rechecks", "sources"]) {
219
+ if (!Array.isArray(r[k]))
220
+ throw new SchemaError(`recommendations[${i}].${k} must be a list`);
221
+ for (const x of r[k])
222
+ required(x, `recommendations[${i}].${k}[]`);
223
+ }
224
+ if (!r.sources.length)
225
+ throw new SchemaError(`recommendations[${i}].sources must be non-empty`);
226
+ }
227
+ }
228
+ else {
229
+ if (e.recommendations)
230
+ throw new SchemaError("recommendations belong to item_instruction events");
231
+ required(e.why, "why");
232
+ required(e.can_go_when, "can_go_when");
233
+ if (!Array.isArray(e.evidence_ids) || (!e.evidence_ids.length && e.attribution?.label !== "unattributed"))
234
+ throw new SchemaError("evidence_ids must be non-empty");
235
+ if (e.action != null &&
236
+ (!required(e.action, "action") || e.action.length > 32 || e.action.trim().split(/\s+/).length > 2))
237
+ throw new SchemaError("action must be a concise label of one or two words");
238
+ }
239
+ if (!["observed", "inferred", "verified"].includes(e.claim))
240
+ throw new SchemaError("claim must be observed, inferred, or verified");
241
+ const agent = record(e.agent, "agent"), project = record(e.project, "project"), created = record(e.created, "created");
242
+ required(agent.harness, "agent.harness");
243
+ required(agent.session_id, "agent.session_id");
244
+ required(project.id, "project.id");
245
+ if (project.consumers != null && !Array.isArray(project.consumers))
246
+ throw new SchemaError("project.consumers must be a list");
247
+ required(created.at, "created.at");
248
+ if (!["observed", "inferred", "discovered"].includes(e.created.source))
249
+ throw new SchemaError("created.source must be observed, inferred, or discovered");
250
+ if (!Object.hasOwn(e, "correction_of"))
251
+ throw new SchemaError("correction_of is required (use null when not a correction)");
252
+ if (w.bytes != null && !Number.isInteger(w.bytes))
253
+ throw new SchemaError("what.bytes must be an int or null");
254
+ if (w.completeness != null && !["known", "partial", "unknown"].includes(w.completeness))
255
+ throw new SchemaError("what.completeness must be known, partial, unknown, or absent");
256
+ if (e.approvals != null) {
257
+ if (!Array.isArray(e.approvals))
258
+ throw new SchemaError("approvals must be a list");
259
+ for (const a of e.approvals) {
260
+ if (!a || typeof a !== "object")
261
+ throw new SchemaError("approvals entries must be objects");
262
+ required(a.path || a.location, "approvals[].path");
263
+ required(a.fingerprint || a.expected_fingerprint, "approvals[].fingerprint");
264
+ }
265
+ }
266
+ if (e.resource_observation != null) {
267
+ if (e.event_type !== "resource_observation")
268
+ throw new SchemaError("resource_observation belongs to resource_observation events");
269
+ const o = record(e.resource_observation, "resource_observation");
270
+ required(o.scope, "resource_observation.scope");
271
+ required(o.observed_at, "resource_observation.observed_at");
272
+ required(o.source, "resource_observation.source");
273
+ if (o.attribution != null && !["host", "project_process", "session", "unknown"].includes(o.attribution))
274
+ throw new SchemaError("resource_observation.attribution must be host, project_process, session, or unknown");
275
+ if (!Array.isArray(o.readings) || !o.readings.length)
276
+ throw new SchemaError("resource_observation.readings must not be empty");
277
+ const dimensions = [
278
+ "cpu",
279
+ "gpu",
280
+ "memory",
281
+ "temperature",
282
+ "battery",
283
+ "processes",
284
+ "ports",
285
+ "containers",
286
+ "simulators",
287
+ "disk",
288
+ "tokens",
289
+ "energy",
290
+ ];
291
+ for (let i = 0; i < o.readings.length; i++) {
292
+ const r = record(o.readings[i], `resource_observation.readings[${i}]`);
293
+ if (!dimensions.includes(r.dimension))
294
+ throw new SchemaError(`resource_observation.readings[${i}].dimension is invalid`);
295
+ required(r.name, `resource_observation.readings[${i}].name`);
296
+ if (typeof r.value !== "number" || !Number.isFinite(r.value))
297
+ throw new SchemaError(`resource_observation.readings[${i}].value must be finite numeric`);
298
+ required(r.unit, `resource_observation.readings[${i}].unit`);
299
+ }
300
+ }
301
+ if (e.review != null) {
302
+ const r = record(e.review, "review");
303
+ if (e.event_type !== "coverage_receipt")
304
+ throw new SchemaError("review belongs to coverage_receipt events");
305
+ if (!["completed", "partial", "failed"].includes(r.status))
306
+ throw new SchemaError("review.status must be completed, partial, or failed");
307
+ if (!Array.isArray(r.inspected) || !Array.isArray(r.unreviewed))
308
+ throw new SchemaError("review.inspected and review.unreviewed must be lists");
309
+ if (r.status === "completed" && r.unreviewed.length)
310
+ throw new SchemaError("completed review cannot contain unreviewed scope");
311
+ }
312
+ if (e.proposal != null) {
313
+ const p = record(e.proposal, "proposal");
314
+ if (e.event_type !== "cleanup_proposal")
315
+ throw new SchemaError("proposal belongs to cleanup_proposal events");
316
+ required(p.action, "proposal.action");
317
+ if (p.action !== "move_to_trash")
318
+ throw new SchemaError("unsupported proposal action");
319
+ required(p.reason, "proposal.reason");
320
+ if (e.claim !== "verified")
321
+ throw new SchemaError("cleanup proposal must have verified evidence");
322
+ }
323
+ if (e.cleanup != null) {
324
+ const c = record(e.cleanup, "cleanup");
325
+ if (e.event_type !== "cleanup_outcome")
326
+ throw new SchemaError("cleanup belongs to cleanup_outcome events");
327
+ const allowed = [
328
+ "moved",
329
+ "restored",
330
+ "kept",
331
+ "kept_always",
332
+ "skipped",
333
+ "failed",
334
+ "nothing_to_clean",
335
+ "tool_removed",
336
+ "stopped",
337
+ "stopped_default",
338
+ "restarted",
339
+ ];
340
+ if (!allowed.includes(c.outcome))
341
+ throw new SchemaError("invalid cleanup.outcome");
342
+ required(c.operation_id, "cleanup.operation_id");
343
+ if (c.outcome === "moved")
344
+ required(c.trash_destination, "cleanup.trash_destination");
345
+ if (c.outcome === "tool_removed") {
346
+ required(c.tool, "cleanup.tool");
347
+ if (c.trash_destination)
348
+ throw new SchemaError("tool_removed must not claim a trash_destination");
349
+ }
350
+ if (["stopped", "stopped_default", "restarted"].includes(c.outcome)) {
351
+ if (w.bytes != null && w.bytes !== 0)
352
+ throw new SchemaError("stopped workload outcomes cannot claim reclaimed bytes");
353
+ if (!c.runtime_identity)
354
+ throw new SchemaError("stopped outcomes require cleanup.runtime_identity");
355
+ c.runtime_identity = runtimeIdentity(c.runtime_identity, "cleanup.runtime_identity");
356
+ if (!w.location.startsWith("runtime://"))
357
+ throw new SchemaError("stopped outcomes require a runtime:// what.location");
358
+ validateRuntimeLocation(w.location, c.runtime_identity);
359
+ if (JSON.stringify(w.runtime_identity) !== JSON.stringify(c.runtime_identity))
360
+ throw new SchemaError("stopped outcome identity must match what.runtime_identity");
361
+ }
362
+ if (c.outcome === "nothing_to_clean") {
363
+ if (w.bytes != null && w.bytes !== 0)
364
+ throw new SchemaError("nothing_to_clean cannot claim cleaned bytes");
365
+ if (c.scope_complete !== true)
366
+ throw new SchemaError("nothing_to_clean requires a completed inspection");
367
+ if (!Array.isArray(c.reviewed_paths) || !c.reviewed_paths.length)
368
+ throw new SchemaError("nothing_to_clean requires the inspected paths");
369
+ }
370
+ }
371
+ return e;
372
+ }
373
+ export const readText = (p) => readFile(p, "utf8");