Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

feat(brain/notes): default Obsidian folder picker to iCloud vault folder (#313)

[._.]/ Adam Eivya330a03ba842
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 790f461755..be6e0226f9 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -31,6 +31,10 @@
- **Manual canon extraction from comicScript / teleplay stages.** Auto-extract still runs only after `prose`, but a new "Extract canon" button on both script stages lets writers pull characters/places/objects that surface only in panel directions or dialogue cues (a barkeep in a stage direction, a recurring location named only in the script) into the linked universe on demand. New route `POST /api/pipeline/issues/:id/stages/:stageId/extract-canon` (`stageId` must be `comicScript` or `teleplay`) reads the stage's `output` as the corpus and reuses the generic `extractCanonFromProse` with the same `parallel: true` + `autoLock: true` + `sourceSeriesId` stamping as the prose auto-extract, so script-derived entries survive later AI refines and stay attributable. Returns the merged universe + per-kind counts so the UI toast can summarize the merge. Three precondition errors: `PIPELINE_CANON_EXTRACT_BAD_STAGE`, `PIPELINE_CANON_EXTRACT_NO_CORPUS`, `PIPELINE_CANON_EXTRACT_NO_UNIVERSE`. New shared component `ExtractCanonButton.jsx` (gated on stage content + linked universe; tooltip explains the specific blocker when disabled); wired into `TeleplayStage` via `TextStagePanel.extraActions` and `ComicScriptStage` directly in its header. Client helper `extractPipelineCanonFromScript` in `apiPipeline.js`. 5 new vitest cases cover all precondition guards + happy path for both stage IDs.
+### Brain / Notes
+
+- **Obsidian vault picker opens to the iCloud Obsidian folder by default.** The "Add Custom Path" folder picker on Brain → Notes now defaults its initial open location to `~/Library/Mobile Documents/iCloud~md~obsidian/Documents` so users land directly inside their iCloud Obsidian root and can pick a vault subfolder without navigating from the project parent. Falls back silently to the server default when the folder doesn't exist (non-Mac, no iCloud Obsidian) — fallback is gated on the specific `INVALID_PATH` / `NOT_A_DIRECTORY` server error codes so network blips and 5xx surface as real errors instead of permanently disabling the default. The unavailable result is cached in a ref so subsequent re-opens skip the wasted 400 round trip. New `defaultPath` prop on `FolderPicker.jsx`; server `/api/scaffold/directories` route now expands a leading `~/` in paths (embedded `~` chars in the iCloud bundle name are preserved verbatim).
+
### Sharing
- **"🔄 live" badge on inbox subscription rows.** Sharing → Inbox now flags subscription rows whose latest manifest was queued within the last 5 minutes with a small green pill (spinning RefreshCw icon + "live" label). Re-exports fire on every record edit with a 3s server-side debounce and propagate via chokidar in <1s, so a recently-received subscription is a real-time "sender is editing right now" signal. Pure `isLiveSubscription(item, now)` helper exported from `client/src/pages/Sharing.jsx` (handles null inputs + unparseable `receivedAt` + one-shot non-subscription shares without throwing); 5 new vitest cases in `Sharing.test.jsx`. Freshness is computed on render so the badge naturally decays as the page re-renders past the 5-min mark.
diff --git a/client/src/components/FolderPicker.jsx b/client/src/components/FolderPicker.jsx
index e58fc57915..9e586f33d0 100644
--- a/client/src/components/FolderPicker.jsx
+++ b/client/src/components/FolderPicker.jsx
@@ -2,7 +2,7 @@ import { useState, useEffect, useRef, useCallback } from 'react';
import { Folder, FolderOpen, ChevronUp, HardDrive, Home, X, Check, AlertCircle } from 'lucide-react';
import * as api from '../services/api';
-export default function FolderPicker({ value, onChange }) {
+export default function FolderPicker({ value, onChange, defaultPath }) {
const [isOpen, setIsOpen] = useState(false);
const [currentPath, setCurrentPath] = useState('');
const [parentPath, setParentPath] = useState(null);
@@ -11,20 +11,50 @@ export default function FolderPicker({ value, onChange }) {
const [loading, setLoading] = useState(false);
const [error, setError] = useState(null);
const modalRef = useRef(null);
+ // Remember when `defaultPath` has already failed once so re-opens skip the
+ // wasted round trip (and the server-side 400 it logs). Ref-not-state because
+ // changing it must not re-trigger the open effect.
+ const defaultPathUnavailableRef = useRef(false);
- // Load directory contents
- const loadDirectory = useCallback(async (path = null) => {
+ // Load directory contents. When fallbackToDefault is true and the requested
+ // path fails BECAUSE IT DOESN'T EXIST (e.g. iCloud Obsidian folder absent),
+ // silently retry with the server's default so the picker still opens
+ // somewhere usable. Other failures (server down, permission denied,
+ // transient 5xx) propagate as errors and do NOT poison the
+ // defaultPathUnavailable cache — otherwise a one-time network blip would
+ // permanently disable the default for the rest of the session.
+ const loadDirectory = useCallback(async (path = null, { fallbackToDefault = false } = {}) => {
+ // Local helper so it stays inside the useCallback closure — keeps
+ // react-hooks/exhaustive-deps quiet and rules out stale-closure surprises
+ // if it ever starts reading state/props in the future.
+ const isPathAbsentError = (err) => (
+ err?.status === 400 && (err.code === 'INVALID_PATH' || err.code === 'NOT_A_DIRECTORY')
+ );
setLoading(true);
setError(null);
- const result = await api.getDirectories(path).catch((err) => {
- setError(err.message || 'Failed to load directory');
- return null;
- });
- if (result) {
+ const applyResult = (result) => {
setCurrentPath(result.currentPath);
setParentPath(result.parentPath);
setDirectories(result.directories || []);
setDrives(result.drives ?? null);
+ };
+ let lastError = null;
+ let result = await api.getDirectories(path).catch((err) => {
+ lastError = err;
+ return null;
+ });
+ if (!result && fallbackToDefault && path != null && isPathAbsentError(lastError)) {
+ defaultPathUnavailableRef.current = true;
+ lastError = null;
+ result = await api.getDirectories(null).catch((err) => {
+ lastError = err;
+ return null;
+ });
+ }
+ if (result) {
+ applyResult(result);
+ } else if (lastError) {
+ setError(lastError.message || 'Failed to load directory');
}
setLoading(false);
}, []);
@@ -32,9 +62,17 @@ export default function FolderPicker({ value, onChange }) {
// Load initial directory when opened
useEffect(() => {
if (isOpen) {
- loadDirectory(value || null);
+ const useDefault = !value && !!defaultPath && !defaultPathUnavailableRef.current;
+ const initialPath = value || (useDefault ? defaultPath : null);
+ loadDirectory(initialPath, { fallbackToDefault: useDefault });
}
- }, [isOpen, loadDirectory, value]);
+ }, [isOpen, loadDirectory, value, defaultPath]);
+
+ // Reset the "default unavailable" cache when the caller changes which
+ // defaultPath to try — a different path is worth probing again.
+ useEffect(() => {
+ defaultPathUnavailableRef.current = false;
+ }, [defaultPath]);
// Close on click outside
useEffect(() => {
diff --git a/client/src/components/brain/tabs/NotesTab.jsx b/client/src/components/brain/tabs/NotesTab.jsx
index 5fab4c81a8..38af8955d2 100644
--- a/client/src/components/brain/tabs/NotesTab.jsx
+++ b/client/src/components/brain/tabs/NotesTab.jsx
@@ -734,7 +734,11 @@ function VaultSetup({ detectedVaults, vaults, customPath, setCustomPath, adding,
placeholder="/path/to/obsidian/vault"
className="flex-1 min-w-0 bg-port-bg border border-port-border rounded px-3 py-2 text-sm text-white placeholder-gray-500"
/>
- <FolderPicker value={customPath} onChange={setCustomPath} />
+ <FolderPicker
+ value={customPath}
+ onChange={setCustomPath}
+ defaultPath="~/Library/Mobile Documents/iCloud~md~obsidian/Documents"
+ />
<button
onClick={() => {
if (customPath.trim()) {
diff --git a/server/routes/scaffold.js b/server/routes/scaffold.js
index a23758fdf8..b2a84b9e87 100644
--- a/server/routes/scaffold.js
+++ b/server/routes/scaffold.js
@@ -28,7 +28,17 @@ router.get('/directories', asyncHandler(async (req, res) => {
// Default to parent of PortOS project if no path provided
const defaultPath = resolve(join(__dirname, '../../..'));
- const targetPath = dirPath === '~' ? homedir() : dirPath ? resolve(dirPath) : defaultPath;
+ let targetPath;
+ if (!dirPath) {
+ targetPath = defaultPath;
+ } else if (dirPath === '~') {
+ targetPath = homedir();
+ } else if (dirPath.startsWith('~/') || dirPath.startsWith('~\\')) {
+ // Expand leading ~ only; preserve embedded ~ chars (e.g. iCloud~md~obsidian)
+ targetPath = resolve(join(homedir(), dirPath.slice(2)));
+ } else {
+ targetPath = resolve(dirPath);
+ }
// Validate path exists and is a directory
if (!existsSync(targetPath)) {