High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
feat: profile metadata (useWhen) + dashboard details screen
Mario3b548b13c744
diff --git a/dashboard/app.js b/dashboard/app.jsindex 44fe6142..ae3e7500 100644--- a/dashboard/app.js+++ b/dashboard/app.js@@ -15,7 +15,7 @@ function switchView(view) {if (profilesInterval) { clearInterval(profilesInterval); profilesInterval = null; }if (view === 'profiles') {- profilesInterval = setInterval(loadProfiles, 3000);+ profilesInterval = setInterval(loadProfiles, 10000);}}diff --git a/dashboard/base.css b/dashboard/base.cssindex 55a91a02..70ed474e 100644--- a/dashboard/base.css+++ b/dashboard/base.css@@ -148,13 +148,15 @@box-shadow: 0 20px 40px rgba(0, 0, 0, 0.45);}.modal.modal-wide {- width: min(1100px, 95vw);+ width: 560px;+ max-width: 95vw;}.modal h3 {font-family: var(--font-heading);color: var(--text-bright);margin-bottom: 16px;letter-spacing: -0.01em;+ text-align: center;}.modal input, .modal select {width: 100%;diff --git a/dashboard/dashboard.html b/dashboard/dashboard.htmlindex 3ab9510f..7d6ddca0 100644--- a/dashboard/dashboard.html+++ b/dashboard/dashboard.html@@ -42,6 +42,8 @@<h3>π New Profile</h3><label style="color:#888;font-size:12px;display:block;margin-bottom:4px">Name</label><input id="create-name" placeholder="e.g. personal, work, scraping" />+ <label style="color:#888;font-size:12px;display:block;margin-bottom:4px">Use this profile when (helps agents pick the right profile)</label>+ <textarea id="create-usewhen" placeholder="e.g. I need to access Gmail for the team account" style="min-height:60px"></textarea><label style="color:#888;font-size:12px;display:block;margin-bottom:4px">Import from (optional β Chrome user data path)</label><input id="create-source" placeholder="e.g. /Users/you/Library/Application Support/Google/Chrome" /><div class="btn-row" style="margin-top:16px">diff --git a/dashboard/profiles.css b/dashboard/profiles.cssindex f5a6a94f..cccdbdc5 100644--- a/dashboard/profiles.css+++ b/dashboard/profiles.css@@ -104,8 +104,8 @@font-size: 13px;padding: 3px 0;}- .inst-card .inst-row .label { color: var(--text-dim); }- .inst-card .inst-row .value { color: var(--text-bright); }+ .inst-card .inst-row .label { color: var(--text-dim); min-width: 80px; flex-shrink: 0; }+ .inst-card .inst-row .value { color: var(--text-bright); text-align: right; }.inst-card .inst-actions {padding: 10px 16px;border-top: 1px solid var(--border);diff --git a/dashboard/profiles.js b/dashboard/profiles.jsindex 045de2e5..500cab3f 100644--- a/dashboard/profiles.js+++ b/dashboard/profiles.js@@ -84,7 +84,6 @@ function renderMainCard(tabCount) {<span class="inst-badge running">running :${location.port || '9867'}</span></div><div class="inst-body">- <div class="inst-row"><span class="label">Tabs</span><span class="value">${tabCount}</span></div><div class="inst-row"><span class="label">Port</span><span class="value">${location.port || '9867'}</span></div></div><div class="inst-actions">@@ -102,6 +101,7 @@ function renderProfileCard(profile, inst) {const accountText = profile.accountEmail || profile.accountName || '';const accountValue = accountText || '--';const chromeProfileName = profile.chromeProfileName || '';+ const useWhen = profile.useWhen || '';const status = inst ? inst.status : 'stopped';const isRunning = status === 'running';const isError = status === 'error';@@ -115,19 +115,11 @@ function renderProfileCard(profile, inst) {let actions = '';if (isRunning) {- actions =- '<button onclick="viewInstanceLive(\'' + esc(inst.id) + '\', \'' + esc(inst.port) + '\')">Live</button>'- + '<button class="btn-feed" onclick="viewProfileInfo(\'' + esc(name) + '\', \'' + esc(inst.id) + '\')">Info</button>'- + '<button class="danger" onclick="stopProfile(\'' + esc(name) + '\')">Stop</button>';- } else if (inst && (status === 'starting' || status === 'stopping')) {- actions =- '<button class="btn-feed" onclick="viewProfileInfo(\'' + esc(name) + '\', \'' + esc(inst.id) + '\')">Info</button>'+ actions = '<button onclick="viewProfileDetails(\'' + esc(name) + '\', \'' + esc(inst.id) + '\')">Details</button>'+ '<button class="danger" onclick="stopProfile(\'' + esc(name) + '\')">Stop</button>';} else {- actions =- '<button class="btn-launch" onclick="openLaunchModal(\'' + esc(name) + '\')">Launch</button>'- + '<button class="btn-feed" onclick="viewProfileInfo(\'' + esc(name) + '\', \'' + esc(inst ? inst.id : '') + '\')">Info</button>'- + '<button class="danger" onclick="deleteProfile(\'' + esc(name) + '\')">Delete</button>';+ actions = '<button onclick="viewProfileDetails(\'' + esc(name) + '\', \'' + esc(inst ? inst.id : '') + '\')">Details</button>'+ + '<button class="btn-launch" onclick="openLaunchModal(\'' + esc(name) + '\')">Launch</button>';}return `@@ -138,11 +130,8 @@ function renderProfileCard(profile, inst) {</div><div class="inst-body"><div class="inst-row"><span class="label">Size</span><span class="value">${sizeMB ? sizeMB.toFixed(0) + ' MB' : 'β'}</span></div>- <div class="inst-row"><span class="label">Source</span><span class="value">${esc(source)}</span></div>- ${chromeProfileName ? '<div class="inst-row"><span class="label">Chrome</span><span class="value">' + esc(chromeProfileName) + '</span></div>' : ''}<div class="inst-row"><span class="label">Account</span><span class="value">${esc(accountValue)}</span></div>- <div class="inst-row"><span class="label">Tabs</span><span class="value">${tabsValue}</span></div>- <div class="inst-row"><span class="label">PID</span><span class="value">${pidValue}</span></div>+ <div class="inst-row" style="align-items:flex-start"><span class="label">Use when</span><span class="value" style="display:-webkit-box;-webkit-line-clamp:3;-webkit-box-orient:vertical;overflow:hidden;text-overflow:ellipsis;height:3.9em;line-height:1.3em;text-align:left">${useWhen ? esc(useWhen) : '<span style="color:var(--text-faint)">β</span>'}</span></div>${isError && inst && inst.error ? '<div class="inst-row"><span class="label">Error</span><span class="value">' + esc(inst.error) + '</span></div>' : ''}</div><div class="inst-actions">@@ -164,23 +153,26 @@ function closeCreateProfileModal() {async function doCreateProfile() {const name = document.getElementById('create-name').value.trim();+ const useWhen = document.getElementById('create-usewhen').value.trim();const source = document.getElementById('create-source').value.trim();if (!name) { await appAlert('Name required'); return; }closeCreateProfileModal();try {+ const body = { name, useWhen };if (source) {+ body.source = source;await fetch('/profiles/import', {method: 'POST',headers: { 'Content-Type': 'application/json' },- body: JSON.stringify({ name, source })+ body: JSON.stringify(body)});} else {await fetch('/profiles/create', {method: 'POST',headers: { 'Content-Type': 'application/json' },- body: JSON.stringify({ name })+ body: JSON.stringify(body)});}loadProfiles();@@ -335,9 +327,10 @@ async function stopProfile(name) {setTimeout(loadProfiles, 700);}-async function viewProfileInfo(name, instanceID) {+async function viewProfileDetails(name, instanceID) {const encName = encodeURIComponent(name);- const [analytics, agents, liveTabs, state] = await Promise.all([+ const [profileInfo, analytics, agents, liveTabs, state] = await Promise.all([+ fetchJSONOr('/profiles', []).then(profiles => profiles.find(p => p.name === name) || {}),fetchJSONOr('/profiles/' + encName + '/analytics', null),fetchJSONOr('/dashboard/agents', []),fetchJSONOr('/instances/tabs', []),@@ -364,43 +357,161 @@ async function viewProfileInfo(name, instanceID) {const status = state && state.status ? state.status : 'stopped';const port = state && state.port ? state.port : '-';const pid = state && state.pid ? state.pid : '-';+ const isRunning = status === 'running';- let html = '';- html += '<h4 style="color:var(--text-muted);font-size:12px;margin-bottom:8px">STATUS</h4>';- html += '<div style="font-size:13px;color:var(--text-subtle);margin-bottom:4px">State: <span style="color:var(--text)">' + esc(status) + '</span></div>';- html += '<div style="font-size:13px;color:var(--text-subtle);margin-bottom:4px">Port: <span style="color:var(--text)">' + esc(String(port)) + '</span></div>';- html += '<div style="font-size:13px;color:var(--text-subtle);margin-bottom:12px">PID: <span style="color:var(--text)">' + esc(String(pid)) + '</span></div>';+ // Build tab content: Profile & Live/Logs+ let tabProfile = '';++ // Metadata+ tabProfile += '<label style="color:var(--text-muted);font-size:12px;display:block;margin-bottom:4px">Name</label>';+ tabProfile += '<input id="profile-name" value="' + esc(name) + '" style="width:100%;margin-bottom:12px" />';+ tabProfile += '<label style="color:var(--text-muted);font-size:12px;display:block;margin-bottom:4px">Use this profile when</label>';+ tabProfile += '<textarea id="profile-usewhen" style="width:100%;min-height:80px;margin-bottom:16px;resize:vertical">' + esc(profileInfo.useWhen || '') + '</textarea>';++ // Status+ tabProfile += '<h4 style="color:var(--text-muted);font-size:12px;margin-bottom:8px">STATUS</h4>';+ tabProfile += '<div style="font-size:13px;color:var(--text-subtle);margin-bottom:4px">State: <span style="color:var(--text)">' + esc(status) + '</span></div>';+ tabProfile += '<div style="font-size:13px;color:var(--text-subtle);margin-bottom:4px">Port: <span style="color:var(--text)">' + esc(String(port)) + '</span></div>';+ tabProfile += '<div style="font-size:13px;color:var(--text-subtle);margin-bottom:4px">PID: <span style="color:var(--text)">' + esc(String(pid)) + '</span></div>';+ tabProfile += '<div style="font-size:13px;color:var(--text-subtle);margin-bottom:4px">Size: <span style="color:var(--text)">' + (profileInfo.sizeMB ? profileInfo.sizeMB.toFixed(0) + ' MB' : 'β') + '</span></div>';+ tabProfile += '<div style="font-size:13px;color:var(--text-subtle);margin-bottom:4px">Source: <span style="color:var(--text)">' + esc(profileInfo.source || 'β') + '</span></div>';+ if (profileInfo.path) {+ tabProfile += '<div style="font-size:13px;color:var(--text-subtle);margin-bottom:4px">Path: <span style="color:var(--text);font-size:11px;font-family:var(--font-mono)">' + esc(profileInfo.path) + '</span></div>';+ }+ if (profileInfo.chromeProfileName) {+ tabProfile += '<div style="font-size:13px;color:var(--text-subtle);margin-bottom:4px">Chrome: <span style="color:var(--text)">' + esc(profileInfo.chromeProfileName) + '</span></div>';+ }+ if (profileInfo.accountEmail || profileInfo.accountName) {+ tabProfile += '<div style="font-size:13px;color:var(--text-subtle);margin-bottom:4px">Account: <span style="color:var(--text)">' + esc(profileInfo.accountEmail || profileInfo.accountName) + '</span></div>';+ }- html += '<h4 style="color:var(--text-muted);font-size:12px;margin-bottom:8px">LIVE</h4>';- html += '<div style="font-size:13px;color:var(--text-subtle);margin-bottom:4px">Tabs open: <span style="color:var(--text)">' + tabsCount + '</span></div>';- html += '<div style="font-size:13px;color:var(--text-subtle);margin-bottom:12px">Agents: <span style="color:var(--text)">' + agentsForProfile.length + '</span></div>';+ let tabLive = '';++ // Tabs & agents+ tabLive += '<h4 style="color:var(--text-muted);font-size:12px;margin-bottom:8px">TABS (' + tabsCount + ')</h4>';+ if (isRunning && Array.isArray(liveTabs)) {+ const profileTabs = name === 'main' ? liveTabs : liveTabs.filter(t => t.instanceName === name);+ if (profileTabs.length > 0) {+ profileTabs.forEach(tab => {+ const tabTitle = tab.title || 'Untitled';+ const tabUrl = tab.url || '';+ tabLive += '<div style="font-size:12px;padding:4px 0;border-bottom:1px solid var(--border)">';+ tabLive += '<div style="color:var(--text);overflow:hidden;text-overflow:ellipsis;white-space:nowrap">' + esc(tabTitle) + '</div>';+ tabLive += '<div style="color:var(--text-faint);font-size:11px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap">' + esc(tabUrl) + '</div>';+ tabLive += '</div>';+ });+ } else {+ tabLive += '<p style="color:var(--text-faint);font-size:12px">No tabs open.</p>';+ }+ } else {+ tabLive += '<p style="color:var(--text-faint);font-size:12px">Instance not running.</p>';+ }++ tabLive += '<div style="margin-top:16px"></div>';+ tabLive += '<h4 style="color:var(--text-muted);font-size:12px;margin-bottom:8px">AGENTS (' + agentsForProfile.length + ')</h4>';+ if (agentsForProfile.length > 0) {+ agentsForProfile.forEach(a => {+ tabLive += '<div style="font-size:12px;color:var(--text-subtle);padding:2px 0">' + esc(a.agentId) + ' β ' + esc(a.status) + '</div>';+ });+ } else {+ tabLive += '<p style="color:var(--text-faint);font-size:12px">No agents connected.</p>';+ }+ // Activity+ tabLive += '<div style="margin-top:16px"></div>';if (analytics && analytics.totalActions > 0) {- html += '<h4 style="color:var(--text-muted);font-size:12px;margin-bottom:8px">FEED (' + analytics.totalActions + ' actions)</h4>';+ tabLive += '<h4 style="color:var(--text-muted);font-size:12px;margin-bottom:8px">ACTIVITY (' + analytics.totalActions + ' actions)</h4>';if (analytics.topEndpoints) {analytics.topEndpoints.forEach(e => {- html += '<div style="font-size:12px;color:var(--text-subtle);padding:2px 0">' + esc(e.endpoint) + ' - ' + e.count + 'x, avg ' + e.avgMs + 'ms</div>';+ tabLive += '<div style="font-size:12px;color:var(--text-subtle);padding:2px 0">' + esc(e.endpoint) + ' β ' + e.count + 'x, avg ' + e.avgMs + 'ms</div>';});}- if (analytics.suggestions) {- html += '<div style="margin-top:8px">';- analytics.suggestions.forEach(s => {- html += '<p style="color:var(--text-bright);font-size:12px;margin-bottom:4px">' + esc(s) + '</p>';- });- html += '</div>';- }} else {- html += '<p style="color:var(--text-faint);font-size:12px;margin-bottom:12px">No tracked actions yet.</p>';+ tabLive += '<h4 style="color:var(--text-muted);font-size:12px;margin-bottom:8px">ACTIVITY</h4>';+ tabLive += '<p style="color:var(--text-faint);font-size:12px">No tracked actions yet.</p>';}- html += '<h4 style="color:var(--text-muted);font-size:12px;margin-bottom:8px">LOGS</h4>';+ // Logs+ tabLive += '<div style="margin-top:16px"></div>';+ tabLive += '<h4 style="color:var(--text-muted);font-size:12px;margin-bottom:8px">LOGS</h4>';if (!logsText) {- html += '<p style="color:var(--text-faint);font-size:12px">No instance logs available for this profile.</p>';+ tabLive += '<p style="color:var(--text-faint);font-size:12px">No instance logs available.</p>';} else {- html += '<pre style="background:var(--bg);padding:12px;border-radius:6px;font-size:11px;max-height:45vh;overflow:auto;color:var(--text-subtle);white-space:pre-wrap">' + esc(logsText) + '</pre>';+ tabLive += '<pre style="background:var(--bg);padding:12px;border-radius:6px;font-size:11px;max-height:30vh;overflow:auto;color:var(--text-subtle);white-space:pre-wrap">' + esc(logsText) + '</pre>';}- showModal('INFO: ' + name, html, null, { wide: true });+ // Assemble with tabs+ let html = '';+ html += '<div class="details-tabs" style="display:flex;gap:0;border-bottom:1px solid var(--border);margin-bottom:16px">';+ html += '<button class="details-tab active" onclick="switchDetailsTab(this, \'details-pane-profile\')" style="flex:1;padding:10px;background:none;border:none;border-radius:0;border-bottom:2px solid var(--primary);color:var(--text-bright);font-size:13px;font-weight:600;cursor:pointer;font-family:inherit">Profile</button>';+ html += '<button class="details-tab" onclick="switchDetailsTab(this, \'details-pane-live\')" style="flex:1;padding:10px;background:none;border:none;border-radius:0;border-bottom:2px solid transparent;color:var(--text-muted);font-size:13px;font-weight:600;cursor:pointer;font-family:inherit">Live & Logs</button>';+ html += '</div>';++ html += '<div style="height:400px;overflow-y:auto">';+ html += '<div id="details-pane-profile">' + tabProfile + '</div>';+ html += '<div id="details-pane-live" style="display:none">' + tabLive + '</div>';+ html += '</div>';++ // Footer buttons+ html += '<div style="display:flex;justify-content:space-between;align-items:center;margin-top:16px;padding-top:16px;border-top:1px solid var(--border)">';+ html += '<button class="danger" onclick="deleteProfileFromDetails(\'' + esc(name) + '\')">Delete</button>';+ html += '<div style="display:flex;gap:8px">';+ html += '<button onclick="saveProfileMetadata(\'' + esc(name) + '\')">Save</button>';+ html += '<button class="secondary" onclick="closeModal()">Close</button>';+ html += '</div>';+ html += '</div>';++ showModal('DETAILS', html, ' ', { wide: true });+}++function switchDetailsTab(btn, paneId) {+ btn.closest('.details-tabs').querySelectorAll('.details-tab').forEach(t => {+ t.style.borderBottomColor = 'transparent';+ t.style.color = 'var(--text-muted)';+ t.classList.remove('active');+ });+ btn.style.borderBottomColor = 'var(--primary)';+ btn.style.color = 'var(--text-bright)';+ btn.classList.add('active');+ document.getElementById('details-pane-profile').style.display = 'none';+ document.getElementById('details-pane-live').style.display = 'none';+ document.getElementById(paneId).style.display = '';+}++async function saveProfileMetadata(name) {+ const useWhen = document.getElementById('profile-usewhen').value.trim();+ const newName = document.getElementById('profile-name').value.trim();++ try {+ const res = await fetch('/profiles/' + encodeURIComponent(name), {+ method: 'PATCH',+ headers: { 'Content-Type': 'application/json' },+ body: JSON.stringify({ useWhen, name: newName })+ });++ if (res.ok) {+ closeModal();+ loadProfiles();+ } else {+ const data = await res.json().catch(() => ({}));+ await appAlert('Save failed: ' + (data.error || res.statusText), 'Error');+ }+ } catch (e) {+ await appAlert('Save error: ' + e.message, 'Error');+ }+}++async function deleteProfileFromDetails(name) {+ closeModal();+ if (!await appConfirm('Delete profile "' + name + '"? This removes all data.', 'ποΈ Delete Profile')) return;++ try {+ await fetch('/profiles/' + encodeURIComponent(name), { method: 'DELETE' });+ profilesLoading = false;+ loadProfiles();+ } catch (e) {+ await appAlert('Delete failed: ' + e.message, 'Error');+ }}const launchPortInput = document.getElementById('launch-port');diff --git a/profiles_handlers.go b/profiles_handlers.goindex 15ce17f1..a34cacf5 100644--- a/profiles_handlers.go+++ b/profiles_handlers.go@@ -11,6 +11,7 @@ func (pm *ProfileManager) RegisterHandlers(mux *http.ServeMux) {mux.HandleFunc("GET /profiles", pm.handleList)mux.HandleFunc("POST /profiles/import", pm.handleImport)mux.HandleFunc("POST /profiles/create", pm.handleCreate)+ mux.HandleFunc("PATCH /profiles/{name}", pm.handleUpdate)mux.HandleFunc("POST /profiles/{name}/reset", pm.handleReset)mux.HandleFunc("DELETE /profiles/{name}", pm.handleDelete)mux.HandleFunc("GET /profiles/{name}/logs", pm.handleLogs)@@ -28,8 +29,10 @@ func (pm *ProfileManager) handleList(w http.ResponseWriter, r *http.Request) {func (pm *ProfileManager) handleImport(w http.ResponseWriter, r *http.Request) {var req struct {- Name string `json:"name"`- Source string `json:"source"`+ Name string `json:"name"`+ Source string `json:"source"`+ UseWhen string `json:"useWhen"`+ Description string `json:"description"`}if err := json.NewDecoder(r.Body).Decode(&req); err != nil {jsonErr(w, http.StatusBadRequest, fmt.Errorf("invalid JSON"))@@ -39,16 +42,31 @@ func (pm *ProfileManager) handleImport(w http.ResponseWriter, r *http.Request) {jsonErr(w, http.StatusBadRequest, fmt.Errorf("name and source required"))return}- if err := pm.Import(req.Name, req.Source); err != nil {- jsonErr(w, http.StatusConflict, err)- return++ // Import with metadata if provided+ if req.UseWhen != "" || req.Description != "" {+ meta := ProfileMeta{+ UseWhen: req.UseWhen,+ Description: req.Description,+ }+ if err := pm.ImportWithMeta(req.Name, req.Source, meta); err != nil {+ jsonErr(w, http.StatusConflict, err)+ return+ }+ } else {+ if err := pm.Import(req.Name, req.Source); err != nil {+ jsonErr(w, http.StatusConflict, err)+ return+ }}jsonResp(w, http.StatusCreated, map[string]string{"status": "imported", "name": req.Name})}func (pm *ProfileManager) handleCreate(w http.ResponseWriter, r *http.Request) {var req struct {- Name string `json:"name"`+ Name string `json:"name"`+ UseWhen string `json:"useWhen"`+ Description string `json:"description"`}if err := json.NewDecoder(r.Body).Decode(&req); err != nil {jsonErr(w, http.StatusBadRequest, fmt.Errorf("invalid JSON"))@@ -58,9 +76,22 @@ func (pm *ProfileManager) handleCreate(w http.ResponseWriter, r *http.Request) {jsonErr(w, http.StatusBadRequest, fmt.Errorf("name required"))return}- if err := pm.Create(req.Name); err != nil {- jsonErr(w, http.StatusConflict, err)- return++ // Create with metadata if provided+ if req.UseWhen != "" || req.Description != "" {+ meta := ProfileMeta{+ UseWhen: req.UseWhen,+ Description: req.Description,+ }+ if err := pm.CreateWithMeta(req.Name, meta); err != nil {+ jsonErr(w, http.StatusConflict, err)+ return+ }+ } else {+ if err := pm.Create(req.Name); err != nil {+ jsonErr(w, http.StatusConflict, err)+ return+ }}jsonResp(w, http.StatusCreated, map[string]string{"status": "created", "name": req.Name})}@@ -96,6 +127,44 @@ func (pm *ProfileManager) handleAnalytics(w http.ResponseWriter, r *http.RequestjsonResp(w, http.StatusOK, report)}+func (pm *ProfileManager) handleUpdate(w http.ResponseWriter, r *http.Request) {+ name := r.PathValue("name")+ var req struct {+ Name string `json:"name"`+ UseWhen string `json:"useWhen"`+ Description string `json:"description"`+ }+ if err := json.NewDecoder(r.Body).Decode(&req); err != nil {+ jsonErr(w, http.StatusBadRequest, fmt.Errorf("invalid JSON"))+ return+ }++ meta := map[string]string{+ "useWhen": req.UseWhen,+ "description": req.Description,+ }+ if err := pm.UpdateMeta(name, meta); err != nil {+ jsonErr(w, http.StatusNotFound, err)+ return+ }++ if req.Name != "" && req.Name != name {+ if err := pm.Rename(name, req.Name); err != nil {+ jsonErr(w, http.StatusConflict, err)+ return+ }+ name = req.Name+ }++ // Return updated profile info+ info, err := pm.profileInfo(name)+ if err != nil {+ jsonErr(w, http.StatusNotFound, err)+ return+ }+ jsonResp(w, http.StatusOK, info)+}+func (pm *ProfileManager) TrackingMiddleware(profileName string, next http.Handler) http.Handler {return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {start := time.Now()diff --git a/profiles_manager.go b/profiles_manager.goindex a0391957..a509ead7 100644--- a/profiles_manager.go+++ b/profiles_manager.go@@ -19,6 +19,11 @@ type ProfileManager struct {mu sync.RWMutex}+type ProfileMeta struct {+ UseWhen string `json:"useWhen,omitempty"`+ Description string `json:"description,omitempty"`+}+type ProfileInfo struct {Name string `json:"name"`Path string `json:"path"`@@ -29,6 +34,8 @@ type ProfileInfo struct {AccountEmail string `json:"accountEmail,omitempty"`AccountName string `json:"accountName,omitempty"`HasAccount bool `json:"hasAccount,omitempty"`+ UseWhen string `json:"useWhen,omitempty"`+ Description string `json:"description,omitempty"`}func NewProfileManager(baseDir string) *ProfileManager {@@ -82,6 +89,7 @@ func (pm *ProfileManager) profileInfo(name string) (ProfileInfo, error) {}chromeProfileName, accountEmail, accountName, hasAccount := readChromeProfileIdentity(dir)+ meta := readProfileMeta(dir)return ProfileInfo{Name: name,@@ -93,6 +101,8 @@ func (pm *ProfileManager) profileInfo(name string) (ProfileInfo, error) {AccountEmail: accountEmail,AccountName: accountName,HasAccount: hasAccount,+ UseWhen: meta.UseWhen,+ Description: meta.Description,}, nil}@@ -122,6 +132,15 @@ func (pm *ProfileManager) Import(name, sourcePath string) error {return nil}+// ImportWithMeta imports a profile with metadata+func (pm *ProfileManager) ImportWithMeta(name, sourcePath string, meta ProfileMeta) error {+ if err := pm.Import(name, sourcePath); err != nil {+ return err+ }+ dest := filepath.Join(pm.baseDir, name)+ return writeProfileMeta(dest, meta)+}+func (pm *ProfileManager) Create(name string) error {pm.mu.Lock()defer pm.mu.Unlock()@@ -133,6 +152,15 @@ func (pm *ProfileManager) Create(name string) error {return os.MkdirAll(filepath.Join(dest, "Default"), 0755)}+// CreateWithMeta creates a profile with metadata+func (pm *ProfileManager) CreateWithMeta(name string, meta ProfileMeta) error {+ if err := pm.Create(name); err != nil {+ return err+ }+ dest := filepath.Join(pm.baseDir, name)+ return writeProfileMeta(dest, meta)+}+func (pm *ProfileManager) Reset(name string) error {pm.mu.Lock()defer pm.mu.Unlock()@@ -176,6 +204,21 @@ func (pm *ProfileManager) Reset(name string) error {return nil}+func (pm *ProfileManager) Rename(oldName, newName string) error {+ pm.mu.Lock()+ defer pm.mu.Unlock()++ oldDir := filepath.Join(pm.baseDir, oldName)+ newDir := filepath.Join(pm.baseDir, newName)+ if _, err := os.Stat(oldDir); os.IsNotExist(err) {+ return fmt.Errorf("profile %q not found", oldName)+ }+ if _, err := os.Stat(newDir); err == nil {+ return fmt.Errorf("profile %q already exists", newName)+ }+ return os.Rename(oldDir, newDir)+}+func (pm *ProfileManager) Delete(name string) error {pm.mu.Lock()defer pm.mu.Unlock()@@ -302,3 +345,41 @@ func readJSON(path string, out any) bool {}return true}++func readProfileMeta(profileDir string) ProfileMeta {+ var meta ProfileMeta+ readJSON(filepath.Join(profileDir, "profile.json"), &meta)+ return meta+}++func writeProfileMeta(profileDir string, meta ProfileMeta) error {+ data, err := json.MarshalIndent(meta, "", " ")+ if err != nil {+ return err+ }+ return os.WriteFile(filepath.Join(profileDir, "profile.json"), data, 0644)+}++// UpdateMeta updates the profile metadata (useWhen, description)+func (pm *ProfileManager) UpdateMeta(name string, meta map[string]string) error {+ pm.mu.Lock()+ defer pm.mu.Unlock()++ dir := filepath.Join(pm.baseDir, name)+ if _, err := os.Stat(dir); os.IsNotExist(err) {+ return fmt.Errorf("profile %q not found", name)+ }++ // Read existing metadata+ existing := readProfileMeta(dir)++ // Update fields if provided+ if useWhen, ok := meta["useWhen"]; ok {+ existing.UseWhen = useWhen+ }+ if description, ok := meta["description"]; ok {+ existing.Description = description+ }++ return writeProfileMeta(dir, existing)+}diff --git a/profiles_test.go b/profiles_test.goindex 91742eae..9083f7e3 100644--- a/profiles_test.go+++ b/profiles_test.go@@ -309,3 +309,104 @@ func TestProfileHandlerDelete(t *testing.T) {t.Fatalf("expected 200, got %d: %s", w.Code, w.Body.String())}}++func TestProfileMetaReadWrite(t *testing.T) {+ dir := t.TempDir()+ pm := NewProfileManager(dir)++ // Create profile with metadata+ meta := ProfileMeta{+ UseWhen: "I need to access work email",+ Description: "Work profile for corporate tasks",+ }+ if err := pm.CreateWithMeta("work-profile", meta); err != nil {+ t.Fatal(err)+ }++ // Read back the metadata+ readMeta := readProfileMeta(filepath.Join(dir, "work-profile"))+ if readMeta.UseWhen != "I need to access work email" {+ t.Errorf("expected useWhen 'I need to access work email', got %q", readMeta.UseWhen)+ }+ if readMeta.Description != "Work profile for corporate tasks" {+ t.Errorf("expected description 'Work profile for corporate tasks', got %q", readMeta.Description)+ }+}++func TestProfileUpdateMeta(t *testing.T) {+ pm := NewProfileManager(t.TempDir())+ mux := http.NewServeMux()+ pm.RegisterHandlers(mux)++ // Create profile+ _ = pm.Create("updatable")++ // Update metadata via PATCH+ body := `{"useWhen":"Updated use case","description":"Updated description"}`+ req := httptest.NewRequest("PATCH", "/profiles/updatable", strings.NewReader(body))+ req.Header.Set("Content-Type", "application/json")+ w := httptest.NewRecorder()+ mux.ServeHTTP(w, req)++ if w.Code != 200 {+ t.Fatalf("expected 200, got %d: %s", w.Code, w.Body.String())+ }++ // Verify response contains updated metadata+ var updatedProfile ProfileInfo+ if err := json.NewDecoder(w.Body).Decode(&updatedProfile); err != nil {+ t.Fatal(err)+ }+ if updatedProfile.UseWhen != "Updated use case" {+ t.Errorf("expected useWhen 'Updated use case', got %q", updatedProfile.UseWhen)+ }+}++func TestProfileCreateWithUseWhen(t *testing.T) {+ pm := NewProfileManager(t.TempDir())+ mux := http.NewServeMux()+ pm.RegisterHandlers(mux)++ // Create profile with useWhen+ body := `{"name":"test-usewhen","useWhen":"For testing purposes"}`+ req := httptest.NewRequest("POST", "/profiles/create", strings.NewReader(body))+ req.Header.Set("Content-Type", "application/json")+ w := httptest.NewRecorder()+ mux.ServeHTTP(w, req)++ if w.Code != 201 {+ t.Fatalf("expected 201, got %d: %s", w.Code, w.Body.String())+ }++ // Verify profile list includes useWhen+ profiles, err := pm.List()+ if err != nil {+ t.Fatal(err)+ }+ if len(profiles) != 1 {+ t.Fatalf("expected 1 profile, got %d", len(profiles))+ }+ if profiles[0].UseWhen != "For testing purposes" {+ t.Errorf("expected useWhen 'For testing purposes', got %q", profiles[0].UseWhen)+ }+}++func TestProfileListIncludesUseWhen(t *testing.T) {+ pm := NewProfileManager(t.TempDir())++ // Create profile with metadata+ meta := ProfileMeta{UseWhen: "Personal browsing"}+ _ = pm.CreateWithMeta("personal", meta)++ // List profiles and check useWhen is included+ profiles, err := pm.List()+ if err != nil {+ t.Fatal(err)+ }+ if len(profiles) != 1 {+ t.Fatalf("expected 1 profile, got %d", len(profiles))+ }+ if profiles[0].UseWhen != "Personal browsing" {+ t.Errorf("expected useWhen 'Personal browsing', got %q", profiles[0].UseWhen)+ }+}