const m=new Set(["spec","tasks","agents","commits","gates"]),d=new Set(["shortcuts","general","project","components","workflows","models","palette","directories","account","appearance","maintenance"]);function w(){const t=window.location.pathname||"";if(t==="/walkthrough"||t.endsWith("/walkthrough")){const a=new URLSearchParams(window.location.search||"");return{view:"walkthrough",walkthroughSessionId:a.get("session")||void 0,walkthroughTabId:a.get("tab")||void 0}}const e=window.location.hash||"";if(e==="#/search"||e.startsWith("#/search?")){const a=e.indexOf("?");return{view:"search",searchQuery:(a>=0?new URLSearchParams(e.slice(a+1)):null)?.get("q")||void 0}}if(e==="#/walkthrough"||e.startsWith("#/walkthrough?")){const a=e.indexOf("?"),n=a>=0?new URLSearchParams(e.slice(a+1)):null;return{view:"walkthrough",walkthroughSessionId:n?.get("session")||void 0,walkthroughTabId:n?.get("tab")||void 0}}const o=e.match(/^#\/session\/([a-zA-Z0-9_-]+)$/i);if(o)return{view:"session",sessionId:o[1]};const s=e.match(/^#\/goal\/([a-f0-9-]+)(?:\?(.*))?$/i);if(s){const a=s[2]?new URLSearchParams(s[2]):null,n=a?.get("tab")||void 0;return{view:"goal-dashboard",goalId:s[1],dashboardTab:n&&m.has(n)?n:void 0,focusGateId:a?.get("gate")||void 0,focusSignalId:a?.get("signal")||void 0}}const i=e.match(/^#\/roles\/([a-zA-Z0-9_-]+)$/);if(i)return{view:"role-edit",roleName:i[1]};if(e==="#/roles")return{view:"roles"};const l=e.match(/^#\/tools\/([a-zA-Z0-9_-]+)$/);if(l)return{view:"tool-edit",toolName:l[1]};if(e==="#/tools")return{view:"tools"};const r=e.match(/^#\/workflows\/([a-zA-Z0-9_-]+)$/);if(r)return{view:"workflow-edit",workflowId:r[1]};if(e==="#/workflows")return{view:"workflows"};const g=e.match(/^#\/staff\/([a-f0-9-]+)$/i);if(g)return{view:"staff-edit",staffId:g[1]};if(e==="#/staff")return{view:"staff"};if(e==="#/skills")return{view:"skills"};const c=e.match(/^#\/settings(?:\/([a-z0-9-]+))?(?:\/([a-z]+))?$/);if(c){const a=c[1],n=c[2];if(!a)return{view:"settings"};if(!n&&d.has(a))return{view:"settings",settingsScope:"system",settingsTab:a};const h=n;return{view:"settings",settingsScope:a,settingsTab:h&&d.has(h)?h:void 0}}if(e)return{view:"landing"};const u=t.match(/^\/session\/([a-zA-Z0-9_-]+)$/i);return u?{view:"session",sessionId:u[1]}:{view:"landing"}}function k(t,e,o,s){const i=new URLSearchParams;e?.tab&&i.set("tab",e.tab),e?.gate&&i.set("gate",e.gate),e?.signal&&i.set("signal",e.signal);const l=i.toString(),r=`#/goal/${t}${l?`?${l}`:""}`;window.location.hash!==r&&(o?(history.replaceState({},"",r),s||window.dispatchEvent(new HashChangeEvent("hashchange"))):window.location.hash=r)}function v(t){const e=`/session/${t}`,o=`#/session/${t}`;window.location.pathname!==e||window.location.hash!==o||history.replaceState(history.state??{},"",`/#/session/${t}`)}function p(t,e,o){let s;t==="session"&&e?s=`#/session/${e}`:t==="goal-dashboard"&&e?s=`#/goal/${e}`:t==="role-edit"&&e?s=`#/roles/${e}`:t==="roles"?s="#/roles":t==="tool-edit"&&e?s=`#/tools/${e}`:t==="tools"?s="#/tools":t==="workflow-edit"&&e?s=`#/workflows/${e}`:t==="workflows"?s="#/workflows":t==="staff-edit"&&e?s=`#/staff/${e}`:t==="staff"?s="#/staff":t==="skills"?s="#/skills":t==="search"?s=e?`#/search?q=${encodeURIComponent(e)}`:"#/search":t==="walkthrough"?s=e?`#/walkthrough?${e}`:"#/walkthrough":t==="settings"?e?s=`#/settings/${e}`:s="#/settings":s="#/",window.location.hash!==s&&(o?(history.replaceState({},"",s),window.dispatchEvent(new HashChangeEvent("hashchange"))):window.location.hash=s)}const S=new Set(["roles","role-edit","tools","tool-edit","workflows","workflow-edit","skills","settings","staff","staff-edit","search"]);function $(){return S.has(w().view)}function I(...t){const e=w().view;return t.some(o=>o===e)}let f=null;function b(t,e){const o=w().view;if(t.some(s=>s===o)){const s=f||"#/";f=null,window.location.hash!==s&&(history.replaceState({},"",s),window.dispatchEvent(new HashChangeEvent("hashchange")))}else f=window.location.hash||"#/",e()}function R(t,e,o){localStorage.setItem(`session.${t}.model`,JSON.stringify({provider:e,modelId:o}))}function E(t){const e=localStorage.getItem(`session.${t}.model`);if(!e)return null;try{const o=JSON.parse(e);if(o.provider&&o.modelId)return o}catch{}return null}function M(t){localStorage.removeItem(`session.${t}.model`)}export{v as canonicalizePathSessionRoute,M as clearSessionModel,w as getRouteFromHash,$ as isConfigPageRoute,I as isRouteActive,E as loadSessionModel,R as saveSessionModel,k as setGoalDashboardRoute,p as setHashRoute,b as toggleConfigPage};
