Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.
fix: artifacts on Windows paths; permissions file follows MERCURY_HOME
Salman Qureshie1e409eaa7a7
diff --git a/src/artifacts/artifacts.test.ts b/src/artifacts/artifacts.test.tsindex 96bba33b..5741b53f 100644--- a/src/artifacts/artifacts.test.ts+++ b/src/artifacts/artifacts.test.ts@@ -1,6 +1,6 @@import { mkdirSync, mkdtempSync, utimesSync, writeFileSync } from 'node:fs';import { tmpdir } from 'node:os';-import { join } from 'node:path';+import { join, resolve } from 'node:path';import { describe, expect, it } from 'vitest';import { classifyArtifact, type ClassifyContext } from './classify.js';import { ArtifactCollector, pathsIn } from './collector.js';@@ -64,10 +64,17 @@ describe('what counts as an artifact', () => {it('finds paths in commands and output, quoted, escaped or relative', () => {const found = pathsIn('ffmpeg -i in.mov -vf scale=1280:-1 "/Users/me/Movies/My Clip.mp4" && echo saved ./out/chart.png; cat x.ts', '/Users/me', { relative: true });- expect(found).toContain('/Users/me/Movies/My Clip.mp4');- expect(found).toContain('/Users/me/out/chart.png');+ // resolve(): on Windows these come back with the current drive in front.+ expect(found).toContain(resolve('/Users/me/Movies/My Clip.mp4'));+ expect(found).toContain(resolve('/Users/me/out/chart.png'));expect(found.some((p) => p.endsWith('x.ts'))).toBe(false);- expect(found).not.toContain('/out/chart.png');+ expect(found).not.toContain(resolve('/out/chart.png'));+ });++ it.runIf(process.platform === 'win32')('finds Windows paths in command output', () => {+ const found = pathsIn('Saved chart to C:\\Users\\me\\Desktop\\chart.png and "D:\\Videos\\My Clip.mp4"', 'C:\\Users\\me', { relative: false });+ expect(found).toContain('C:\\Users\\me\\Desktop\\chart.png');+ expect(found).toContain('D:\\Videos\\My Clip.mp4');});});diff --git a/src/artifacts/classify.ts b/src/artifacts/classify.tsindex a6ac2033..e0c0db3d 100644--- a/src/artifacts/classify.ts+++ b/src/artifacts/classify.ts@@ -62,6 +62,11 @@ export interface ClassifyContext {size: number;}+/** A path's folders and name, whichever separator it was written with (Windows takes both). */+function segments(path: string): string[] {+ return path.split(/[\\/]+/).filter(Boolean);+}+function inside(child: string, parent: string): boolean {const rel = relative(parent, child);return !!rel && !rel.startsWith('..') && !isAbsolute(rel);@@ -83,7 +88,7 @@ export function classifyArtifact(path: string, ctx: ClassifyContext): ArtifactKiif (name.startsWith('.') || name.startsWith('~$')) return null;// Folder rules apply below the system temp folder, not to it ("tmp" means a project's tmp/).const temp = tempRoot(path);- const parts = (temp ? relative(temp, path) : path).split(sep);+ const parts = segments(temp ? relative(temp, path) : path);if (parts.some((p) => NEVER_UNDER.has(p))) return null;if (inside(path, ctx.mercuryHome) && !inside(path, `${ctx.mercuryHome}${sep}artifacts`) && !inside(path, `${ctx.mercuryHome}${sep}workspace`) && !inside(path, `${ctx.mercuryHome}${sep}outputs`)) return null;@@ -104,7 +109,7 @@ export function classifyArtifact(path: string, ctx: ClassifyContext): ArtifactKiif (ctx.surface === 'code' && inside(path, ctx.cwd)) {// In a project, only a written-for-you report counts: a PDF, Markdown or text// deliverable at the root or in a reports/research folder, named like one.- const rel = relative(ctx.cwd, path).split(sep);+ const rel = segments(relative(ctx.cwd, path));const top = rel.length > 1 ? rel[0].toLowerCase() : '';if (rel.some((p, i) => i < rel.length - 1 && PROJECT_ASSET_DIRS.has(p.toLowerCase()))) return null;const deliverableDir = top === '' || /^(reports?|research|notes|output|outputs|artifacts|deliverables)$/.test(top);diff --git a/src/artifacts/collector.ts b/src/artifacts/collector.tsindex db90feaa..cec2edaa 100644--- a/src/artifacts/collector.ts+++ b/src/artifacts/collector.ts@@ -17,10 +17,10 @@ import type { Artifact, ArtifactStore } from './store.js';*/const ARTIFACT_EXT = 'png|jpe?g|gif|webp|heic|avif|bmp|tiff|svg|mp4|mov|webm|mkv|m4v|avi|mp3|wav|m4a|ogg|flac|aac|opus|pdf|docx?|pptx?|xlsx?|odt|ods|odp|key|pages|numbers|epub|csv|md|markdown|txt';-// An absolute path starts a token (after a space, quote, = or bracket), never mid-word ("./out/x.png" isn't "/out/x.png").-const ABS_PATH = new RegExp(`(?<=^|[\\s'"=(:\\[])(?:~|/)(?:[^\\s'"\`<>|;,()\\[\\]{}]|\\\\ )+\\.(?:${ARTIFACT_EXT})(?=$|[\\s'"\`<>|;,()\\]\\[.:!?])`, 'gi');-/** Quoted paths may contain spaces: "/Users/me/Movies/My Clip.mp4". */-const QUOTED_PATH = new RegExp(`(["'])((?:~|/)[^"'\\n]+?\\.(?:${ARTIFACT_EXT}))\\1`, 'gi');+// An absolute path (/…, ~/…, or C:\… on Windows) starts a token (after a space, quote, = or bracket), never mid-word ("./out/x.png" isn't "/out/x.png").+const ABS_PATH = new RegExp(`(?<=^|[\\s'"=(:\\[])(?:~|/|[A-Za-z]:[\\\\/])(?:[^\\s'"\`<>|;,()\\[\\]{}]|\\\\ )+\\.(?:${ARTIFACT_EXT})(?=$|[\\s'"\`<>|;,()\\]\\[.:!?])`, 'gi');+/** Quoted paths may contain spaces: "/Users/me/Movies/My Clip.mp4". Windows drive paths (C:\…) count too. */+const QUOTED_PATH = new RegExp(`(["'])((?:~|/|[A-Za-z]:[\\\\/])[^"'\\n]+?\\.(?:${ARTIFACT_EXT}))\\1`, 'gi');const REL_PATH = new RegExp(`(?:^|[\\s'"=])((?:\\./)?[\\w@][\\w.@/-]*\\.(?:${ARTIFACT_EXT}))(?=$|[\\s'"\`;,)])`, 'gi');type How = 'sent' | 'written' | 'mentioned';diff --git a/src/capabilities/permissions.ts b/src/capabilities/permissions.tsindex 882479da..59699341 100644--- a/src/capabilities/permissions.ts+++ b/src/capabilities/permissions.ts@@ -245,7 +245,10 @@ const DEFAULT_MANIFEST: PermissionsManifest = {},};-const PERMISSIONS_FILE = join(getMercuryHome(), 'permissions.yaml');+/** Where the owner's permissions live. Looked up each time: MERCURY_HOME can change after this module loads (tests, a profile switch), and the folder is created from the current one. */+function permissionsFile(): string {+ return join(getMercuryHome(), 'permissions.yaml');+}// Split a command into shell-segment strings so each pipeline/chain/substitution// is checked separately. Without this, a single auto-approved base command@@ -681,9 +684,9 @@ export class PermissionManager {}private load(): PermissionsManifest {- if (existsSync(PERMISSIONS_FILE)) {+ if (existsSync(permissionsFile())) {try {- const raw = readFileSync(PERMISSIONS_FILE, 'utf-8');+ const raw = readFileSync(permissionsFile(), 'utf-8');const parsed = parseYaml(raw) as PermissionsManifest;return this.mergeDefaults(parsed);} catch (err) {@@ -699,7 +702,7 @@ export class PermissionManager {const m = manifest || this.manifest;const dir = getMercuryHome();if (!existsSync(dir)) mkdirSync(dir, { recursive: true });- writeFileSync(PERMISSIONS_FILE, stringifyYaml(m, { lineWidth: 0 }), 'utf-8');+ writeFileSync(permissionsFile(), stringifyYaml(m, { lineWidth: 0 }), 'utf-8');this.manifest = m;}