@hraness/slopcamera 3.7.0 → 3.8.1
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/README.md +286 -297
- package/apps/desktop/README.md +2 -9
- package/apps/desktop/application/html-overlay-integrity.ts +27 -4
- package/apps/desktop/application/operation.ts +1 -1
- package/apps/desktop/application/operations/spatial-render.ts +1 -1
- package/apps/desktop/application/spatial-assets.ts +1 -1
- package/apps/desktop/cli/{menubar-status.ts → activity-status.ts} +23 -21
- package/apps/desktop/cli/args.ts +2 -10
- package/apps/desktop/cli/command-host-resources.ts +0 -1
- package/apps/desktop/cli/commands.ts +14 -9
- package/apps/desktop/cli/desktop-status.ts +271 -0
- package/apps/desktop/cli/help.ts +10 -24
- package/apps/desktop/cli/legacy-login.ts +184 -0
- package/apps/desktop/cli/main.ts +8 -0
- package/apps/desktop/cli/outputs.ts +19 -0
- package/apps/desktop/cli/registry.ts +314 -0
- package/apps/desktop/cli/verbs.ts +193 -0
- package/apps/desktop/dist/cli/main.js +293 -306
- package/dist/cli.js +1 -1
- package/dist/{index-nv3byqa1.js → index-6jrxaser.js} +1 -1
- package/dist/index.js +1 -1
- package/docs/README.md +5 -2
- package/package.json +13 -7
- package/skills/slopcamera/SKILL.md +2 -2
- package/skills/slopcamera/references/install.md +2 -2
- package/skills/slopcamera/references/launch-films.md +4 -0
- package/skills/slopcamera/references/reference-led-3d.md +1 -1
- package/src/version.ts +1 -1
- package/apps/desktop/cli/menubar.ts +0 -272
|
@@ -1,272 +0,0 @@
|
|
|
1
|
-
import { closeSync, constants, fstatSync, lstatSync, mkdirSync, mkdtempSync, openSync, readSync, realpathSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
-
import type { Stats } from "node:fs";
|
|
3
|
-
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
4
|
-
import { CliError } from "./errors";
|
|
5
|
-
import type { CliIo } from "./io";
|
|
6
|
-
import { writeJson, writeLine } from "./io";
|
|
7
|
-
import { ensurePrivateDirectory } from "./paths";
|
|
8
|
-
|
|
9
|
-
const SETTLE_MS = 400;
|
|
10
|
-
/** The label earlier releases used; the menu bar now manages its own login item. */
|
|
11
|
-
const LABEL = "com.hraness.slopcamera.menubar";
|
|
12
|
-
|
|
13
|
-
function xml(value: string): string { return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'"); }
|
|
14
|
-
function exists(path: string): boolean { try { const info = lstatSync(path); return isAbsolute(path) && realpathSync(path) === resolve(path) && (info.uid === process.getuid?.() || info.uid === 0) && info.isFile() && (info.mode & 0o111) !== 0 && (info.mode & 0o022) === 0; } catch { return false; } }
|
|
15
|
-
|
|
16
|
-
/** The directory agents write user-facing outputs into. */
|
|
17
|
-
export function outputsRoot(stateRoot: string): string {
|
|
18
|
-
const productRoot = stateRoot.endsWith(`${sep}cli`) ? dirname(stateRoot) : stateRoot;
|
|
19
|
-
return join(productRoot, "outputs");
|
|
20
|
-
}
|
|
21
|
-
export function resolveMenubarBinary(repositoryRoot: string, environment: Readonly<Record<string, string | undefined>> = process.env): string | null {
|
|
22
|
-
const explicit = environment.SLOPCAMERA_MENUBAR;
|
|
23
|
-
if (explicit !== undefined) return explicit !== "" && exists(explicit) ? explicit : null;
|
|
24
|
-
const candidates = [ resolve(dirname(process.execPath), "slopcamera-menubar"), ...(environment.HOME === undefined || environment.HOME === "" ? [] : [installedBinaryPath(environment)]), resolve(repositoryRoot, "desktop", "target", "release", "slopcamera-menubar")];
|
|
25
|
-
for (const candidate of candidates) if (candidate !== undefined && candidate !== "" && exists(candidate)) return candidate;
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
export function launchAgentPath(environment: Readonly<Record<string, string | undefined>> = process.env): string {
|
|
29
|
-
const home = environment.HOME; if (home === undefined || home === "" || !isAbsolute(home)) throw new CliError("unavailable", "HOME is required for a per-user LaunchAgent.");
|
|
30
|
-
return join(home, "Library", "LaunchAgents", `${LABEL}.plist`);
|
|
31
|
-
}
|
|
32
|
-
export function installedBinaryPath(environment: Readonly<Record<string, string | undefined>> = process.env): string {
|
|
33
|
-
const home = environment.HOME; if (home === undefined || home === "" || !isAbsolute(home)) throw new CliError("unavailable", "HOME is required for a per-user menu-bar install.");
|
|
34
|
-
return join(home, "Library", "Application Support", "Slopcamera", "menubar", "slopcamera-menubar");
|
|
35
|
-
}
|
|
36
|
-
export function launchAgentPlist(binary: string): string {
|
|
37
|
-
return `<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n<plist version="1.0"><dict><key>Label</key><string>${xml(LABEL)}</string><key>ProgramArguments</key><array><string>${xml(binary)}</string></array><key>RunAtLoad</key><true/><key>KeepAlive</key><false/><key>ProcessType</key><string>Interactive</string><key>LimitLoadToSessionType</key><string>Aqua</string></dict></plist>\n`;
|
|
38
|
-
}
|
|
39
|
-
type Environment = Readonly<Record<string, string | undefined>>;
|
|
40
|
-
const MAX_BINARY_BYTES = 128 * 1024 * 1024;
|
|
41
|
-
|
|
42
|
-
function infoAt(path: string): Stats | null {
|
|
43
|
-
try { return lstatSync(path); } catch (error) {
|
|
44
|
-
if ((error as NodeJS.ErrnoException).code === "ENOENT") return null;
|
|
45
|
-
throw error;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/** Existing shared directories retain their permissions; links are never followed. */
|
|
50
|
-
function checkParents(path: string, environment: Environment, create = false): void {
|
|
51
|
-
const home = environment.HOME;
|
|
52
|
-
if (!home || !isAbsolute(home) || realpathSync(home) !== resolve(home)) {
|
|
53
|
-
throw new CliError("unsafe-path", "HOME must be an absolute physical directory.");
|
|
54
|
-
}
|
|
55
|
-
const suffix = relative(home, dirname(path));
|
|
56
|
-
if (suffix.startsWith(`..${sep}`) || suffix === ".." || isAbsolute(suffix)) {
|
|
57
|
-
throw new CliError("unsafe-path", "The menu-bar install must remain under HOME.");
|
|
58
|
-
}
|
|
59
|
-
let cursor = home;
|
|
60
|
-
for (const part of ["", ...suffix.split(sep)]) {
|
|
61
|
-
if (part) cursor = join(cursor, part);
|
|
62
|
-
let info = infoAt(cursor);
|
|
63
|
-
if (info === null) {
|
|
64
|
-
if (!create) return;
|
|
65
|
-
mkdirSync(cursor, { mode: 0o700 });
|
|
66
|
-
info = lstatSync(cursor);
|
|
67
|
-
}
|
|
68
|
-
if (!info.isDirectory() || info.uid !== process.getuid?.() || (info.mode & 0o022) !== 0) {
|
|
69
|
-
throw new CliError("unsafe-path", "Menu-bar install directories must be owned physical directories without shared write access.");
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function assertOwnedFile(path: string): void {
|
|
75
|
-
const info = infoAt(path);
|
|
76
|
-
if (info !== null && (!info.isFile() || info.nlink !== 1 || info.uid !== process.getuid?.() || (info.mode & 0o022) !== 0)) {
|
|
77
|
-
throw new CliError("unsafe-path", "The menu-bar install contains an unsafe file.");
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function readRegular(path: string, maximum: number, executable = false): Buffer {
|
|
82
|
-
if (!isAbsolute(path) || realpathSync(path) !== resolve(path) || Buffer.byteLength(path) > 4096 || /[\u0000-\u001f\u007f{}"\\]/u.test(path)) {
|
|
83
|
-
throw new CliError("unsafe-path", "The menu-bar file must have a bounded physical absolute path.");
|
|
84
|
-
}
|
|
85
|
-
const fd = openSync(path, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
86
|
-
try {
|
|
87
|
-
const info = fstatSync(fd);
|
|
88
|
-
if (!info.isFile() || (info.uid !== process.getuid?.() && info.uid !== 0) || info.size > maximum || info.size === 0 || (info.mode & 0o022) !== 0 || (executable && (info.mode & 0o111) === 0)) {
|
|
89
|
-
throw new CliError("unsafe-path", "The menu-bar file must be bounded, regular, and protected from shared writes.");
|
|
90
|
-
}
|
|
91
|
-
const bytes = Buffer.alloc(info.size + 1);
|
|
92
|
-
let count = 0;
|
|
93
|
-
while (count < bytes.length) {
|
|
94
|
-
const read = readSync(fd, bytes, count, bytes.length - count, count);
|
|
95
|
-
if (read === 0) break;
|
|
96
|
-
count += read;
|
|
97
|
-
}
|
|
98
|
-
const after = fstatSync(fd);
|
|
99
|
-
if (count !== info.size || after.size !== info.size || after.mtimeMs !== info.mtimeMs || after.ctimeMs !== info.ctimeMs) {
|
|
100
|
-
throw new CliError("conflict", "The menu-bar file changed while it was being read.");
|
|
101
|
-
}
|
|
102
|
-
return bytes.subarray(0, count);
|
|
103
|
-
} finally { closeSync(fd); }
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function readAgent(path: string, environment: Environment): string | null {
|
|
107
|
-
checkParents(path, environment);
|
|
108
|
-
if (infoAt(path) === null) return null;
|
|
109
|
-
assertOwnedFile(path);
|
|
110
|
-
return readRegular(path, 16 * 1024).toString("utf8");
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Copies the built menu bar into its installed location, replacing an
|
|
115
|
-
* earlier copy. Existing shared directory permissions are preserved;
|
|
116
|
-
* symbolic links and files other users can write are refused.
|
|
117
|
-
*/
|
|
118
|
-
export function installBinary(binary: string, environment: Environment = process.env): string {
|
|
119
|
-
if (!isAbsolute(binary)) throw new CliError("unsafe-path", "The menu-bar build must be an absolute path.");
|
|
120
|
-
const stable = installedBinaryPath(environment);
|
|
121
|
-
checkParents(stable, environment);
|
|
122
|
-
assertOwnedFile(stable);
|
|
123
|
-
const bytes = readRegular(binary, MAX_BINARY_BYTES, true);
|
|
124
|
-
checkParents(stable, environment, true);
|
|
125
|
-
const stage = mkdtempSync(join(dirname(stable), ".install-"));
|
|
126
|
-
try {
|
|
127
|
-
const staged = join(stage, "binary");
|
|
128
|
-
writeFileSync(staged, bytes, { mode: 0o700, flag: "wx" });
|
|
129
|
-
assertOwnedFile(stable);
|
|
130
|
-
renameSync(staged, stable);
|
|
131
|
-
return stable;
|
|
132
|
-
} finally {
|
|
133
|
-
rmSync(stage, { recursive: true });
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Removes the login item earlier releases wrote under the old label, but
|
|
139
|
-
* only when it is exactly the file they wrote. It never calls launchctl: a
|
|
140
|
-
* copy that is already running keeps running until you quit it or log out.
|
|
141
|
-
*/
|
|
142
|
-
export function removeLegacyAgent(environment: Environment = process.env): "absent" | "removed" | "foreign" {
|
|
143
|
-
const path = launchAgentPath(environment);
|
|
144
|
-
const current = readAgent(path, environment);
|
|
145
|
-
if (current === null) return "absent";
|
|
146
|
-
if (current !== launchAgentPlist(installedBinaryPath(environment))) return "foreign";
|
|
147
|
-
rmSync(path);
|
|
148
|
-
return "removed";
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
function assertMac(platform: NodeJS.Platform): void {
|
|
152
|
-
if (platform !== "darwin") throw new CliError("unsupported-plan", "The Slopcamera menu bar runs only on macOS.");
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
export interface HelperResult { readonly code: number; readonly stdout: string; readonly stderr: string }
|
|
156
|
-
/** Runs the installed menu bar's own install, uninstall or status command. */
|
|
157
|
-
export type HelperRunner = (binary: string, args: readonly string[], env: Environment) => Promise<HelperResult>;
|
|
158
|
-
|
|
159
|
-
async function runHelper(binary: string, args: readonly string[], env: Environment): Promise<HelperResult> {
|
|
160
|
-
const child = Bun.spawn([binary, ...args], { stdin: "ignore", stdout: "pipe", stderr: "pipe", env: { ...env } as Record<string, string> });
|
|
161
|
-
const [stdout, stderr, code] = await Promise.all([new Response(child.stdout).text(), new Response(child.stderr).text(), child.exited]);
|
|
162
|
-
return { code, stdout: stdout.slice(0, 64 * 1024), stderr: stderr.slice(0, 64 * 1024) };
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
const AGENT_MARKERS = ["AI_AGENT", "CLAUDECODE", "CODEX_SANDBOX", "CODEX_SANDBOX_NETWORK_DISABLED", "CURSOR_AGENT", "GEMINI_CLI"];
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* The helper decides between human and agent output from its environment.
|
|
169
|
-
* Its output is captured here, so a person's terminal is passed on as
|
|
170
|
-
* `HRANESS_AUDIENCE=human`; agents and explicit settings pass through.
|
|
171
|
-
*/
|
|
172
|
-
export function helperEnvironment(env: Environment): Environment {
|
|
173
|
-
const agent = AGENT_MARKERS.some((name) => (env[name] ?? "") !== "");
|
|
174
|
-
return env.HRANESS_AUDIENCE !== undefined || agent ? env : { ...env, HRANESS_AUDIENCE: "human" };
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
function helperFailure(result: HelperResult): CliError {
|
|
178
|
-
// The helper prints the login-item notice on stderr before the error;
|
|
179
|
-
// the failure is the last ✗ line plus the → hint that follows it.
|
|
180
|
-
const lines = result.stderr.split("\n");
|
|
181
|
-
let start = -1;
|
|
182
|
-
for (const [index, line] of lines.entries()) {
|
|
183
|
-
const trimmed = line.trimStart();
|
|
184
|
-
if (trimmed.startsWith("✗") || trimmed.startsWith("FAIL")) start = index;
|
|
185
|
-
}
|
|
186
|
-
const text = (start === -1 ? result.stderr : lines.slice(start).join("\n")).trim().replace(/^(✗|FAIL)\s+/u, "");
|
|
187
|
-
return new CliError(result.code === 2 ? "usage" : "unavailable", text === "" ? "The Slopcamera menu bar couldn't change its login item." : text);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/** `slopcamera-menubar` exits with this code when another copy already holds the menu bar. */
|
|
191
|
-
export const ALREADY_RUNNING_EXIT = 3;
|
|
192
|
-
const NOT_BUILT = "The Slopcamera menu bar isn't in this release yet. Build it with cargo build --release --manifest-path desktop/Cargo.toml in a Slopcamera checkout; slopcamera finds it there, or set SLOPCAMERA_MENUBAR to the built file.";
|
|
193
|
-
|
|
194
|
-
export type Launched = "running" | "already-running" | "exited";
|
|
195
|
-
export type BinaryRunner = (binary: string, foreground: boolean) => Promise<number | null>;
|
|
196
|
-
|
|
197
|
-
/** Resolves the exit code, or null when a background copy is still running after startup. */
|
|
198
|
-
async function spawnBinary(binary: string, foreground: boolean): Promise<number | null> {
|
|
199
|
-
let child: Bun.Subprocess;
|
|
200
|
-
try { child = Bun.spawn([binary], foreground ? { stdin: "inherit", stdout: "inherit", stderr: "inherit" } : { stdin: "ignore", stdout: "ignore", stderr: "ignore" }); } catch { throw new CliError("unavailable", "The Slopcamera menu bar couldn't start."); }
|
|
201
|
-
if (!foreground) { child.unref(); return await Promise.race([child.exited.then((code) => code as number | null), Bun.sleep(SETTLE_MS).then(() => null)]); }
|
|
202
|
-
return await child.exited;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/** Interprets the companion's exit: another running copy is success, not a failure. */
|
|
206
|
-
export function launchOutcome(code: number | null, foreground: boolean): Launched {
|
|
207
|
-
if (code === ALREADY_RUNNING_EXIT) return "already-running";
|
|
208
|
-
if (code === null && !foreground) return "running";
|
|
209
|
-
if (code === 0 && foreground) return "exited";
|
|
210
|
-
throw new CliError("unavailable", "The Slopcamera menu bar stopped while starting. Run it in the foreground to see why: slopcamera menubar --foreground");
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
interface Marks { readonly ok: string; readonly warn: string; readonly note: string; readonly next: string }
|
|
214
|
-
/** ✓ ⚠ 🔐 → with ASCII fallbacks for dumb terminals and non-UTF-8 locales. */
|
|
215
|
-
export function marks(env: Readonly<Record<string, string | undefined>>): Marks {
|
|
216
|
-
const utf8 = [env.LC_ALL, env.LC_CTYPE, env.LANG].some((value) => value !== undefined && /utf-?8/i.test(value));
|
|
217
|
-
const ascii = env.TERM === "dumb" || !utf8 || env.HRANESS_ASCII === "1";
|
|
218
|
-
return ascii ? { ok: "OK", warn: "WARN", note: "NOTE", next: "->" } : { ok: "✓", warn: "⚠", note: "🔐", next: "→" };
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
export function launchMessage(outcome: Launched, env: Readonly<Record<string, string | undefined>>): string {
|
|
222
|
-
const mark = marks(env);
|
|
223
|
-
if (outcome === "already-running") return `${mark.ok} Slopcamera is already in your menu bar. Look for 📷.`;
|
|
224
|
-
if (outcome === "running") return `${mark.ok} Slopcamera is in your menu bar. Look for 📷.`;
|
|
225
|
-
return "The Slopcamera menu bar closed.";
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
export async function launchMenubar(io: CliIo, repositoryRoot: string, asJson: boolean, mode: "foreground" | "background" = "foreground", runBinary: BinaryRunner = spawnBinary): Promise<void> {
|
|
229
|
-
const binary = resolveMenubarBinary(repositoryRoot, io.env);
|
|
230
|
-
if (binary === null) throw new CliError("unavailable", NOT_BUILT);
|
|
231
|
-
const outcome = launchOutcome(await runBinary(binary, mode === "foreground"), mode === "foreground");
|
|
232
|
-
if (asJson) writeJson(io, { running: outcome !== "exited", foreground: mode === "foreground", alreadyRunning: outcome === "already-running" });
|
|
233
|
-
else writeLine(io, launchMessage(outcome, io.env));
|
|
234
|
-
}
|
|
235
|
-
export async function manageMenubar(io: CliIo, repositoryRoot: string, action: "install" | "uninstall" | "status", asJson: boolean, run: HelperRunner = runHelper): Promise<void> {
|
|
236
|
-
assertMac(io.platform);
|
|
237
|
-
const stable = installedBinaryPath(io.env);
|
|
238
|
-
const args = asJson ? [action, "--json"] : [action];
|
|
239
|
-
const env = helperEnvironment(io.env);
|
|
240
|
-
const forward = (result: HelperResult): void => {
|
|
241
|
-
if (result.stdout !== "") io.stdout(result.stdout);
|
|
242
|
-
if (result.code !== 0) throw helperFailure(result);
|
|
243
|
-
if (result.stderr !== "") io.stderr(result.stderr);
|
|
244
|
-
};
|
|
245
|
-
if (action === "install") {
|
|
246
|
-
const binary = resolveMenubarBinary(repositoryRoot, io.env);
|
|
247
|
-
if (binary === null) throw new CliError("unavailable", NOT_BUILT);
|
|
248
|
-
const installed = binary === stable ? stable : installBinary(binary, io.env);
|
|
249
|
-
forward(await run(installed, args, env));
|
|
250
|
-
// The old login item goes only after the new one is in place, so a
|
|
251
|
-
// failed install never leaves nothing to start at login.
|
|
252
|
-
removeLegacyAgent(io.env);
|
|
253
|
-
return;
|
|
254
|
-
}
|
|
255
|
-
if (action === "uninstall") removeLegacyAgent(io.env);
|
|
256
|
-
if (!exists(stable)) {
|
|
257
|
-
if (asJson) writeJson(io, { login: "off", running: false, installed: false });
|
|
258
|
-
else if (action === "uninstall") writeLine(io, `${marks(io.env).ok} Slopcamera won't open at login.`);
|
|
259
|
-
else writeLine(io, `Slopcamera's menu bar isn't installed.\n${marks(io.env).next} slopcamera menubar install`);
|
|
260
|
-
return;
|
|
261
|
-
}
|
|
262
|
-
const result = await run(stable, args, env);
|
|
263
|
-
forward(result);
|
|
264
|
-
if (action === "uninstall") rmSync(stable);
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
export async function reportOutputsRoot(io: CliIo, stateRoot: string, asJson: boolean): Promise<void> {
|
|
268
|
-
const directory = outputsRoot(stateRoot);
|
|
269
|
-
await ensurePrivateDirectory(directory);
|
|
270
|
-
if (asJson) writeJson(io, { outputs: directory });
|
|
271
|
-
else writeLine(io, directory);
|
|
272
|
-
}
|