@minimalcorp/tsunagi 0.4.10 → 0.5.0

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.
Files changed (59) hide show
  1. package/.next/standalone/apps/web/.next/BUILD_ID +1 -1
  2. package/.next/standalone/apps/web/.next/build-manifest.json +3 -3
  3. package/.next/standalone/apps/web/.next/prerender-manifest.json +3 -3
  4. package/.next/standalone/apps/web/.next/server/app/_global-error.html +1 -1
  5. package/.next/standalone/apps/web/.next/server/app/_global-error.rsc +1 -1
  6. package/.next/standalone/apps/web/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  7. package/.next/standalone/apps/web/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  8. package/.next/standalone/apps/web/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  9. package/.next/standalone/apps/web/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  10. package/.next/standalone/apps/web/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  11. package/.next/standalone/apps/web/.next/server/app/_not-found.html +1 -1
  12. package/.next/standalone/apps/web/.next/server/app/_not-found.rsc +1 -1
  13. package/.next/standalone/apps/web/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  14. package/.next/standalone/apps/web/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  15. package/.next/standalone/apps/web/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  16. package/.next/standalone/apps/web/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  17. package/.next/standalone/apps/web/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  18. package/.next/standalone/apps/web/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  19. package/.next/standalone/apps/web/.next/server/app/index.html +1 -1
  20. package/.next/standalone/apps/web/.next/server/app/index.rsc +1 -1
  21. package/.next/standalone/apps/web/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  22. package/.next/standalone/apps/web/.next/server/app/index.segments/_full.segment.rsc +1 -1
  23. package/.next/standalone/apps/web/.next/server/app/index.segments/_head.segment.rsc +1 -1
  24. package/.next/standalone/apps/web/.next/server/app/index.segments/_index.segment.rsc +1 -1
  25. package/.next/standalone/apps/web/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  26. package/.next/standalone/apps/web/.next/server/app/settings/page_client-reference-manifest.js +1 -1
  27. package/.next/standalone/apps/web/.next/server/app/settings.html +1 -1
  28. package/.next/standalone/apps/web/.next/server/app/settings.rsc +2 -2
  29. package/.next/standalone/apps/web/.next/server/app/settings.segments/_full.segment.rsc +2 -2
  30. package/.next/standalone/apps/web/.next/server/app/settings.segments/_head.segment.rsc +1 -1
  31. package/.next/standalone/apps/web/.next/server/app/settings.segments/_index.segment.rsc +1 -1
  32. package/.next/standalone/apps/web/.next/server/app/settings.segments/_tree.segment.rsc +1 -1
  33. package/.next/standalone/apps/web/.next/server/app/settings.segments/settings/__PAGE__.segment.rsc +2 -2
  34. package/.next/standalone/apps/web/.next/server/app/settings.segments/settings.segment.rsc +1 -1
  35. package/.next/standalone/apps/web/.next/server/app/tasks/[id]/page_client-reference-manifest.js +1 -1
  36. package/.next/standalone/apps/web/.next/server/chunks/ssr/_03lm.~7._.js +1 -1
  37. package/.next/standalone/apps/web/.next/server/chunks/ssr/_09br4yx._.js +1 -1
  38. package/.next/standalone/apps/web/.next/server/chunks/ssr/apps_web_src_app_settings_page_tsx_0i6itlb._.js +1 -1
  39. package/.next/standalone/apps/web/.next/server/middleware-build-manifest.js +3 -3
  40. package/.next/standalone/apps/web/.next/server/pages/404.html +1 -1
  41. package/.next/standalone/apps/web/.next/server/pages/500.html +1 -1
  42. package/.next/standalone/apps/web/.next/server/server-reference-manifest.js +1 -1
  43. package/.next/standalone/apps/web/.next/server/server-reference-manifest.json +1 -1
  44. package/.next/standalone/apps/web/.next/static/chunks/{0v5rzwxc21oyr.js → 04hg.5_c9.hu8.js} +1 -1
  45. package/.next/standalone/apps/web/.next/static/chunks/{03g58abq.y4jn.js → 06_coigl92zz2.js} +1 -1
  46. package/.next/standalone/apps/web/.next/static/chunks/0ur9k0wvs407q.js +5 -0
  47. package/dist/server/lib/claude-tui.d.ts +14 -0
  48. package/dist/server/lib/claude-tui.js +31 -0
  49. package/dist/server/lib/pty-launch.d.ts +2 -1
  50. package/dist/server/lib/pty-launch.js +7 -1
  51. package/dist/server/pty-manager.d.ts +16 -0
  52. package/dist/server/pty-manager.js +58 -0
  53. package/dist/server/routes/settings.js +16 -0
  54. package/npm-shrinkwrap.json +8 -8
  55. package/package.json +1 -1
  56. package/.next/standalone/apps/web/.next/static/chunks/09csrfaxzz_e2.js +0 -5
  57. /package/.next/standalone/apps/web/.next/static/{BqpICo6yhvQE3XGVM855R → cVXrwF5fIctbkve2yARhv}/_buildManifest.js +0 -0
  58. /package/.next/standalone/apps/web/.next/static/{BqpICo6yhvQE3XGVM855R → cVXrwF5fIctbkve2yARhv}/_clientMiddlewareManifest.js +0 -0
  59. /package/.next/standalone/apps/web/.next/static/{BqpICo6yhvQE3XGVM855R → cVXrwF5fIctbkve2yARhv}/_ssgManifest.js +0 -0
@@ -0,0 +1,5 @@
1
+ (globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,82341,e=>{"use strict";var t=e.i(18050),s=e.i(71645),a=e.i(18566),r=e.i(471),l=e.i(75254);let n=(0,l.default)("flask-conical",[["path",{d:"M14 2v6a2 2 0 0 0 .245.96l5.51 10.08A2 2 0 0 1 18 22H6a2 2 0 0 1-1.755-2.96l5.51-10.08A2 2 0 0 0 10 8V2",key:"18mbvz"}],["path",{d:"M6.453 15h11.094",key:"3shlmq"}],["path",{d:"M8.5 2h7",key:"csnxdl"}]]);var i=e.i(70935);let o=(0,l.default)("globe",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20",key:"13o1zl"}],["path",{d:"M2 12h20",key:"9i4pu4"}]]),c=(0,l.default)("folder",[["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]]);var d=e.i(55716),u=e.i(46349),u=u;let m=(0,l.default)("chevron-down",[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]]);var x=e.i(85902);function h({node:e,isSelected:s,isExpanded:a,depth:r,onSelect:l,onToggle:n}){let i=e.children&&e.children.length>0;return(0,t.jsxs)("div",{onClick:()=>{l(),i&&n&&!a&&n()},className:`
2
+ flex items-center gap-2 px-2 py-1.5 rounded cursor-pointer
3
+ transition-colors
4
+ ${s?"bg-accent":"hover:bg-accent"}
5
+ `,style:{paddingLeft:`${16*r+8}px`},children:[i&&(0,t.jsx)(x.Button,{variant:"ghost",size:"icon-xs",onClick:e=>{e.stopPropagation(),n&&n()},className:"size-4",children:a?(0,t.jsx)(m,{className:"w-3 h-3 text-muted-foreground"}):(0,t.jsx)(u.default,{className:"w-3 h-3 text-muted-foreground"})}),!i&&(0,t.jsx)("div",{className:"w-3"}),(0,t.jsx)("div",{className:"text-foreground",children:(()=>{switch(e.type){case"global":return(0,t.jsx)(o,{className:"w-4 h-4"});case"owner":return(0,t.jsx)(c,{className:"w-4 h-4"});case"repo":return(0,t.jsx)(d.GitBranch,{className:"w-4 h-4"})}})()}),(0,t.jsx)("span",{className:"text-sm text-foreground truncate",children:e.label})]})}function p({selectedNode:e,onNodeSelect:a,refreshKey:r}){let[l,n]=(0,s.useState)([]),[o,c]=(0,s.useState)(new Set),[d,u]=(0,s.useState)(!0);(0,s.useEffect)(()=>{let e=localStorage.getItem("tsunagi:env-tree-expanded");if(e)try{let t=JSON.parse(e);c(new Set(t))}catch(e){console.error("Failed to parse expanded owners:",e)}},[]),(0,s.useEffect)(()=>{localStorage.setItem("tsunagi:env-tree-expanded",JSON.stringify([...o]))},[o]),(0,s.useEffect)(()=>{(async()=>{u(!0);try{let e=await fetch((0,i.apiUrl)("/api/owners"));if(!e.ok)throw Error("Failed to fetch owners");let t=((await e.json()).data.owners||[]).map(e=>({id:`owner:${e.name}`,type:"owner",label:e.name,scope:"owner",owner:e.name,children:e.repositories.map(e=>({id:`repo:${e.owner}/${e.repo}`,type:"repo",label:e.repo,scope:"repo",owner:e.owner,repo:e.repo}))}));n([{id:"global",type:"global",label:"Global",scope:"global"},...t])}catch(e){console.error("Failed to load tree:",e)}finally{u(!1)}})()},[r]);let m=(s,r=0)=>{let l=e?.scope===s.scope&&e?.owner===s.owner&&e?.repo===s.repo,n=o.has(s.id);return(0,t.jsxs)("div",{children:[(0,t.jsx)(h,{node:s,isSelected:l,isExpanded:n,depth:r,onSelect:()=>{a({scope:s.scope,owner:s.owner,repo:s.repo,label:s.label})},onToggle:()=>{var e;return e=s.id,void c(t=>{let s=new Set(t);return s.has(e)?s.delete(e):s.add(e),s})}}),n&&s.children?.map(e=>m(e,r+1))]},s.id)};return d?(0,t.jsx)("div",{className:"p-4 text-muted-foreground text-sm",children:"Loading..."}):0===l.length?(0,t.jsx)("div",{className:"p-4 text-muted-foreground text-sm",children:"No repositories found"}):(0,t.jsx)("div",{className:"h-full overflow-y-auto",children:(0,t.jsx)("div",{className:"p-2",children:l.map(e=>m(e))})})}var g=e.i(7233),f=e.i(37727),j=e.i(43531);let v=(0,l.default)("clipboard-paste",[["path",{d:"M11 14h10",key:"1w8e9d"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v1.344",key:"1e62lh"}],["path",{d:"m17 18 4-4-4-4",key:"z2g111"}],["path",{d:"M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 1.793-1.113",key:"bjbb7m"}],["rect",{x:"8",y:"2",width:"8",height:"4",rx:"1",key:"ublpy"}]]),b=/^([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)$/,N=/^(?:export\s+|set\s+|\$env:)/i;var y=e.i(57024),k=e.i(86536);let w=(0,l.default)("eye-off",[["path",{d:"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49",key:"ct8e1f"}],["path",{d:"M14.084 14.158a3 3 0 0 1-4.242-4.242",key:"151rxh"}],["path",{d:"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143",key:"13bj9a"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]]);var C=e.i(27612),S=e.i(88699),L=e.i(10012);function z({variable:e,onToggle:a,onDelete:r,onUpdate:l,isDeletable:n=!0}){let[i,o]=(0,s.useState)(!1),[c,d]=(0,s.useState)(!1),[u,m]=(0,s.useState)(!1),[h,p]=(0,s.useState)(e.value),g=async t=>{d(!0);try{await a(e.key,t.target.checked)}finally{d(!1)}},v=async()=>{await r(e.key)},b=async()=>{try{await l(e.key,h),m(!1)}catch(e){console.error("Failed to update variable:",e),alert("Failed to update variable")}};return(0,t.jsxs)("div",{className:"border border-border rounded p-3 space-y-2",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsx)("span",{className:"text-sm font-mono text-foreground",children:e.key}),!u&&(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsxs)("label",{className:"flex items-center gap-2 cursor-pointer",children:[(0,t.jsx)("input",{type:"checkbox",checked:e.enabled,onChange:g,disabled:c,className:"w-4 h-4 cursor-pointer"}),(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:"Enabled"})]}),(0,t.jsx)(x.Button,{variant:"ghost",size:"icon-lg",onClick:()=>o(!i),title:i?"Hide value":"Show value",children:i?(0,t.jsx)(w,{className:"w-4 h-4 text-muted-foreground"}):(0,t.jsx)(k.Eye,{className:"w-4 h-4 text-muted-foreground"})}),(0,t.jsx)(x.Button,{variant:"ghost",size:"icon-lg",onClick:()=>{m(!0),p(e.value)},title:"Edit",children:(0,t.jsx)(S.Pencil,{className:"w-4 h-4 text-muted-foreground"})}),n&&(0,t.jsx)(x.Button,{variant:"ghost",size:"icon-lg",onClick:v,title:"Delete",children:(0,t.jsx)(C.Trash2,{className:"w-4 h-4 text-destructive"})})]})]}),u?(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(L.Input,{type:"password",value:h,onChange:e=>p(e.target.value),className:"w-full font-mono",autoFocus:!0}),(0,t.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,t.jsx)(x.Button,{variant:"outline",size:"sm",onClick:()=>{m(!1),p(e.value)},className:"active:scale-95",children:(0,t.jsx)(f.X,{className:"w-4 h-4"})}),(0,t.jsx)(x.Button,{size:"sm",onClick:b,className:"active:scale-95",children:(0,t.jsx)(j.Check,{className:"w-4 h-4"})})]})]}):(0,t.jsx)("div",{children:(0,t.jsx)(L.Input,{type:i?"text":"password",value:e.value,readOnly:!0,className:"w-full font-mono"})})]})}var E=e.i(37870),O=e.i(68995);let $=["ANTHROPIC_API_KEY","CLAUDE_CODE_OAUTH_TOKEN","CLAUDE_CONFIG_DIR","TSUNAGI_CLAUDE_PROFILE","CODEX_API_KEY","CODEX_ACCESS_TOKEN","CODEX_HOME","TSUNAGI_CODEX_PROFILE"];function M({selectedNode:e}){let[a,r]=(0,s.useState)([]),[l,n]=(0,s.useState)(!0),[o,c]=(0,s.useState)(null),[d,u]=(0,s.useState)(!1),[m,h]=(0,s.useState)(""),[p,k]=(0,s.useState)(""),[w,C]=(0,s.useState)(""),[S,D]=(0,s.useState)(null),P=async()=>{let t=new URLSearchParams({scope:e.scope});e.owner&&t.set("owner",e.owner),e.repo&&t.set("repo",e.repo);let s=await fetch((0,i.apiUrl)(`/api/env/list?${t}`));if(!s.ok)throw Error("Failed to fetch environment variables");return(await s.json()).data.envVars||[]};(0,s.useEffect)(()=>{(async()=>{n(!0),c(null);try{let t=new URLSearchParams({scope:e.scope});e.owner&&t.set("owner",e.owner),e.repo&&t.set("repo",e.repo);let s=await fetch((0,i.apiUrl)(`/api/env/list?${t}`));if(!s.ok)throw Error("Failed to fetch environment variables");let a=await s.json();r(a.data.envVars||[])}catch(e){console.error("Failed to load environment variables:",e),c("Failed to load environment variables")}finally{n(!1)}})()},[e]);let U=async(t,s)=>{try{if(!(await fetch((0,i.apiUrl)("/api/env/toggle"),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:t,scope:e.scope,owner:e.owner,repo:e.repo,enabled:s})})).ok)throw Error("Failed to toggle environment variable");r(e=>e.map(e=>e.key===t?{...e,enabled:s}:e))}catch(e){console.error("Failed to toggle environment variable:",e),r(e=>e.map(e=>e.key===t?{...e,enabled:!s}:e))}},I=async t=>{if(confirm(`Delete ${t}?`))try{let s=new URLSearchParams({key:t,scope:e.scope});if(e.owner&&s.set("owner",e.owner),e.repo&&s.set("repo",e.repo),!(await fetch((0,i.apiUrl)(`/api/env?${s}`),{method:"DELETE"})).ok)throw Error("Failed to delete environment variable");r(e=>e.filter(e=>e.key!==t))}catch(e){console.error("Failed to delete environment variable:",e),alert("Failed to delete environment variable")}},T=async(t,s)=>{try{if(!(await fetch((0,i.apiUrl)("/api/env"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:t,value:s,scope:e.scope,owner:e.owner,repo:e.repo})})).ok)throw Error("Failed to update environment variable");r(e=>e.map(e=>e.key===t?{...e,value:s}:e))}catch(e){throw console.error("Failed to update environment variable:",e),e}},F=async()=>{var t;if(C(""),!m.trim())return void C("Key is required");if(!p.trim())return void C("Value is required");if(t=m.trim(),/^[A-Z0-9_]+$/.test(t)?$.includes(t)?(C("エージェントの認証は Claude Profile / Codex Profile で設定してください"),!1):!a.some(e=>e.key===t)||(C(`Key "${t}" already exists in this scope`),!1):(C("Key must contain only uppercase letters, numbers, and underscores"),!1))try{if(!(await fetch((0,i.apiUrl)("/api/env"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:m.trim(),value:p.trim(),scope:e.scope,owner:e.owner,repo:e.repo})})).ok)throw Error("Failed to add environment variable");let t=new URLSearchParams({scope:e.scope});e.owner&&t.set("owner",e.owner),e.repo&&t.set("repo",e.repo);let s=await fetch((0,i.apiUrl)(`/api/env/list?${t}`));if(s.ok){let e=await s.json();r(e.data.envVars||[])}u(!1),h(""),k("")}catch(e){console.error("Failed to add environment variable:",e),C("Failed to add environment variable")}},B=()=>{u(!1),h(""),k(""),C("")},A=async t=>{C("");try{let s=await fetch((0,i.apiUrl)("/api/env/bulk"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scope:e.scope,owner:e.owner,repo:e.repo,vars:t})});if(!s.ok){let e=await s.json().catch(()=>null);throw Error(e?.error||"Failed to import environment variables")}r(await P()),B(),y.toaster.create({type:"success",title:`Imported ${t.length} variable${1===t.length?"":"s"}`,description:t.map(e=>e.key).join(", ")})}catch(e){console.error("Failed to import environment variables:",e),C(e instanceof Error?e.message:"Failed to import environment variables")}};return l?(0,t.jsx)("div",{className:"h-full flex items-center justify-center",children:(0,t.jsx)(E.LoadingSpinner,{size:"md",message:"Loading variables..."})}):o?(0,t.jsx)("div",{className:"h-full flex items-center justify-center",children:(0,t.jsx)("div",{className:"text-destructive text-sm",children:o})}):(0,t.jsxs)("div",{className:"h-full flex flex-col",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,t.jsx)("h2",{className:"text-lg font-bold text-foreground",children:"Environment Variables"}),!d&&(0,t.jsxs)(x.Button,{size:"sm",onClick:()=>u(!0),className:"active:scale-95",children:[(0,t.jsx)(g.Plus,{className:"w-4 h-4"}),"Add Variable"]})]}),(0,t.jsxs)("div",{className:"flex-1 overflow-y-auto space-y-3",children:[d&&(0,t.jsxs)("div",{className:"border border-border rounded p-3 bg-accent space-y-2",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsx)("div",{className:"text-sm font-medium text-foreground",children:"New Variable"}),(0,t.jsxs)("div",{className:"flex items-center gap-1 text-xs text-muted-foreground",title:"Paste `export KEY=value` / `KEY=value` / `SET KEY=value` lines to import them all at once",children:[(0,t.jsx)(v,{className:"w-3.5 h-3.5"}),(0,t.jsx)("span",{children:"Paste to import"})]})]}),(0,t.jsx)(L.Input,{type:"text",value:m,onChange:e=>h(e.target.value.toUpperCase()),onPaste:e=>{let t=function(e){let t=new Map,s=0;for(let a of e.split(/\r?\n/)){let e=a.trim();if(!e||e.startsWith("#")||e.startsWith(";")||/^\[.*\]$/.test(e))continue;let r=b.exec(e.replace(N,""));if(!r){s++;continue}let l=function(e){let t=e.trim();if(t.length>=2){let e=t[0],s=t[t.length-1];if(('"'===e||"'"===e)&&e===s)return t.slice(1,-1)}return t}(r[2]);if(!l||l.startsWith("=")){s++;continue}let n=r[1].toUpperCase();t.delete(n),t.set(n,l)}return{entries:Array.from(t,([e,t])=>({key:e,value:t})),unparsedLineCount:s}}(e.clipboardData.getData("text"));if(!(t.entries.length>0&&0===t.unparsedLineCount))return;e.preventDefault(),C("");let s=t.entries.filter(e=>$.includes(e.key)),r=t.entries.filter(e=>!$.includes(e.key));if(s.length>0&&y.toaster.create({type:"warning",title:"Skipped reserved keys",description:`${s.map(e=>e.key).join(", ")} — エージェントの認証は Claude Profile / Codex Profile で設定してください`}),0===r.length)return;let l=new Set(a.map(e=>e.key)),n=r.filter(e=>l.has(e.key)).map(e=>e.key);n.length>0?D({entries:r,overwriting:n}):A(r)},placeholder:"VARIABLE_NAME",className:"w-full font-mono",autoFocus:!0}),(0,t.jsx)(L.Input,{type:"password",value:p,onChange:e=>k(e.target.value),placeholder:"value",className:"w-full font-mono"}),w&&(0,t.jsx)("div",{className:"text-xs text-destructive",children:w}),(0,t.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,t.jsx)(x.Button,{variant:"outline",size:"sm",onClick:B,className:"active:scale-95",children:(0,t.jsx)(f.X,{className:"w-4 h-4"})}),(0,t.jsx)(x.Button,{size:"sm",onClick:F,className:"active:scale-95",children:(0,t.jsx)(j.Check,{className:"w-4 h-4"})})]})]}),0!==a.length||d?a.map(e=>(0,t.jsx)(z,{variable:e,onToggle:U,onDelete:I,onUpdate:T,isDeletable:!0},e.key)):(0,t.jsx)("div",{className:"text-center text-muted-foreground text-sm py-4",children:"No environment variables"})]}),(0,t.jsx)(O.ConfirmDialog,{open:null!==S,onOpenChange:({open:e})=>{e||D(null)},title:"Overwrite existing variables?",message:(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)("p",{children:"The following variables already exist in this scope and will be overwritten:"}),(0,t.jsx)("ul",{className:"font-mono text-foreground list-disc pl-5",children:S?.overwriting.map(e=>(0,t.jsx)("li",{children:e},e))})]}),confirmLabel:"Overwrite",variant:"danger",onConfirm:()=>{S&&A(S.entries)}})]})}var D=e.i(61653),D=D,P=e.i(78917);let U=(0,l.default)("log-in",[["path",{d:"m10 17 5-5-5-5",key:"1bsop3"}],["path",{d:"M15 12H3",key:"6jk70r"}],["path",{d:"M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4",key:"u53s6r"}]]),I=(0,l.default)("user-round",[["circle",{cx:"12",cy:"8",r:"5",key:"1hypcn"}],["path",{d:"M20 21a8 8 0 0 0-16 0",key:"rfgkzh"}]]);var T=e.i(28962),F=e.i(52088),B=e.i(1048),A=e.i(67211),u=u;async function R(e,t){let s=await fetch((0,i.apiUrl)(e),t),a=await s.json().catch(()=>null);if(!s.ok||a?.data===void 0)throw Error(a?.error||`HTTPエラー: ${s.status}`);return a.data}function _(e,t){return R(e,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}function G(e){return e instanceof Error?e.message:String(e)}function X({children:e}){return(0,t.jsx)("div",{className:"flex flex-wrap items-center gap-2 rounded-md border border-border bg-muted/30 px-3 py-2 text-sm",children:e})}function V({label:e,hint:s,children:a}){return(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"mb-1 block text-xs font-medium text-muted-foreground",children:e}),a,s&&(0,t.jsx)("p",{className:"mt-1 text-[0.65rem] text-muted-foreground",children:s})]})}function H({children:e}){let[a,r]=(0,s.useState)(!1);return(0,t.jsxs)("div",{children:[(0,t.jsxs)("button",{type:"button",onClick:()=>r(e=>!e),className:"flex items-center gap-1 text-xs font-medium text-muted-foreground transition-colors hover:text-foreground",children:[(0,t.jsx)(u.default,{className:`size-3.5 transition-transform ${a?"rotate-90":""}`}),"詳細設定"]}),a&&(0,t.jsx)("div",{className:"mt-3 flex flex-col gap-3 border-l border-border pl-3",children:e})]})}function q({children:e}){return(0,t.jsx)("code",{className:"rounded bg-muted px-1",children:e})}let K={claude:"ブラウザで認証してください。ブラウザが開かない場合は表示された URL を開き、表示されたコードをこのターミナルに貼り付けます。",codex:"ブラウザで認証してください。ブラウザが開かない場合は表示された URL を開きます。ログイン済みの場合、今のログインはこの時点で解除されています。"};function W({sessionId:e}){let[a,r]=(0,s.useState)(""),[l,n]=(0,s.useState)(!1),[i,o]=(0,s.useState)(null);return(0,t.jsxs)("form",{onSubmit:t=>{t.preventDefault(),n(!0),o(null),R(`/api/agent-profiles/login/${e}/callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:a})}).then(()=>r("")).catch(e=>o(G(e))).finally(()=>n(!1))},className:"space-y-1",children:[(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:"認証後にブラウザが 127.0.0.1 のページを開けなかったら、そのアドレスバーの URL を貼り付けてください。"}),(0,t.jsxs)("div",{className:"flex gap-2",children:[(0,t.jsx)(L.Input,{value:a,onChange:e=>r(e.target.value),placeholder:"http://127.0.0.1:1455/auth/callback?code=...","aria-label":"Callback URL"}),(0,t.jsx)(x.Button,{type:"submit",disabled:!a.trim()||l,children:"Submit"})]}),i&&(0,t.jsx)("p",{className:"text-xs text-destructive",children:i})]})}function J({profile:e,onClose:a}){let[r,l]=(0,s.useState)(null),n=r?.sessionId??null,[o,c]=(0,s.useState)(null),[d,u]=(0,s.useState)(null);(0,s.useEffect)(()=>{let t=null,s=!1;return R(`/api/agent-profiles/${e.agent}/${e.slug}/login`,{method:"POST"}).then(e=>{(t=e.sessionId,s)?fetch((0,i.apiUrl)(`/api/agent-profiles/login/${t}`),{method:"DELETE"}):l(e)}).catch(e=>c(G(e))),()=>{s=!0,t&&fetch((0,i.apiUrl)(`/api/agent-profiles/login/${t}`),{method:"DELETE"})}},[e.agent,e.slug]);let m=d?.loggedIn??!1;return(0,s.useEffect)(()=>{if(!n||m)return;let t=setInterval(()=>{R(`/api/agent-profiles/${e.agent}/${e.slug}/status`).then(t=>{t.status.loggedIn&&!e.status.loggedIn&&u(t.status)}).catch(()=>void 0)},2e3);return()=>clearInterval(t)},[n,m,e.agent,e.slug,e.status.loggedIn]),(0,t.jsx)(O.Dialog,{open:!0,onOpenChange:e=>{e.open||a()},title:`Login: ${e.name}`,maxWidth:"4xl",children:(0,t.jsxs)("div",{className:"space-y-3",children:[m&&d?(0,t.jsxs)("div",{className:"flex items-center gap-2 rounded-md border border-success/30 bg-success/10 px-3 py-2 text-sm text-success",children:[(0,t.jsx)(B.CircleCheck,{className:"size-4"}),(0,t.jsxs)("span",{className:"flex-1",children:["Logged in",d.email?` as ${d.email}`:"",d.orgName?` (${d.orgName})`:""]}),(0,t.jsx)(x.Button,{size:"sm",onClick:a,children:"Done"})]}):(0,t.jsxs)("p",{className:"text-xs text-muted-foreground",children:[K[e.agent],e.status.loggedIn&&" 再ログインが終わったら閉じてください。"]}),!m&&r?.callbackPaste&&(0,t.jsx)(W,{sessionId:r.sessionId}),(0,t.jsx)("div",{className:"h-[420px] overflow-hidden rounded-md border border-border",children:o?(0,t.jsx)("div",{className:"flex h-full items-center justify-center text-sm text-destructive",children:o}):n?(0,t.jsx)(A.TerminalView,{tabId:n,isActive:!0}):(0,t.jsx)("div",{className:"flex h-full items-center justify-center",children:(0,t.jsx)(E.LoadingSpinner,{size:"sm",message:"Starting..."})})})]})})}let Y="default",Z={claude:{label:"Claude",cliLabel:"Claude Code",installUrl:"https://docs.claude.com/en/docs/claude-code/overview",configDirEnv:"CLAUDE_CONFIG_DIR",defaultConfigDir:"~/.claude",loginCommand:"claude auth login"},codex:{label:"Codex",cliLabel:"Codex",installUrl:"https://developers.openai.com/codex/cli",configDirEnv:"CODEX_HOME",defaultConfigDir:"~/.codex",loginCommand:"codex login"}},Q=Object.keys(Z),ee=/^[A-Za-z0-9 _-]+$/;function et(e){return e.trim().replace(/\s+/g,"-").toLowerCase()}function es({agent:e,availability:s}){let a=Z[e];return!s||s.supported?null:(0,t.jsxs)("p",{className:"flex items-center gap-1.5 text-sm text-muted-foreground",children:[(0,t.jsx)(D.default,{className:"size-4 shrink-0 text-warning"}),s.installed?(0,T.agentOutdatedReason)(a.cliLabel,s):(0,t.jsxs)("span",{children:[a.cliLabel," の CLI が見つかりません。",(0,t.jsxs)("a",{href:a.installUrl,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-0.5 text-primary hover:underline",children:["インストール",(0,t.jsx)(P.ExternalLink,{className:"size-3"})]}),"すると使えます"]})]})}function ea({agent:e,availability:a,selectedNode:r}){let l,n=Z[e],o=`${n.label} Profile`,[c,d]=(0,s.useState)(null),[u,m]=(0,s.useState)(null),[h,p]=(0,s.useState)(null),[v,b]=(0,s.useState)(!1),[N,k]=(0,s.useState)(""),[w,S]=(0,s.useState)(null),[z,$]=(0,s.useState)(null),M="global"===r.scope,P=a?.installed===!1,T=(0,s.useCallback)(async()=>{try{let t=await R(`/api/agent-profiles/${e}`);d(t.profiles)}catch(e){p(G(e))}},[e]),B=(0,s.useCallback)(async()=>{try{let t,s=await R(`/api/agent-profiles/${e}/assignment?${(t=new URLSearchParams({scope:r.scope}),r.owner&&t.set("owner",r.owner),r.repo&&t.set("repo",r.repo),t.toString())}`);m(s.assignment)}catch(e){p(G(e))}},[e,r]);(0,s.useEffect)(()=>{T()},[T]),(0,s.useEffect)(()=>{m(null),B()},[B]);let A=async t=>{try{let s=await R(`/api/agent-profiles/${e}/assignment`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({scope:r.scope,owner:r.owner,repo:r.repo,slug:""===t?null:t})});m(s.assignment)}catch(e){y.toaster.create({type:"error",title:"プロファイルを変更できません",description:G(e)})}},_=async()=>{try{let t=await R(`/api/agent-profiles/${e}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:N.trim()})});b(!1),k(""),await T(),S(t.profile.slug)}catch(e){y.toaster.create({type:"error",title:"プロファイルを追加できません",description:G(e)})}},X=async t=>{try{let s=await fetch((0,i.apiUrl)(`/api/agent-profiles/${e}/${t.slug}`),{method:"DELETE"});if(!s.ok)throw Error(`HTTPエラー: ${s.status}`);await Promise.all([T(),B()])}catch(e){y.toaster.create({type:"error",title:"プロファイルを削除できません",description:G(e)})}};if(h)return(0,t.jsxs)("section",{className:"space-y-3",children:[(0,t.jsx)("h2",{className:"text-lg font-bold text-foreground",children:o}),(0,t.jsx)("p",{className:"text-sm text-destructive",children:h})]});if(!c||!u)return(0,t.jsxs)("section",{className:"space-y-3",children:[(0,t.jsx)("h2",{className:"text-lg font-bold text-foreground",children:o}),(0,t.jsx)(E.LoadingSpinner,{size:"sm",message:"Loading profiles..."})]});let H=function(e,t){let s=e.trim();if(!s)return null;if(!ee.test(s))return'Use only letters, numbers, spaces, "-" and "_"';let a=et(s);return t.some(e=>e.slug===a)?`"${a}" already exists`:null}(N,c),K=c.find(e=>e.slug===w);return(0,t.jsxs)("section",{className:"space-y-3",children:[(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)("h2",{className:"text-lg font-bold text-foreground",children:o}),(0,t.jsx)(es,{agent:e,availability:a})]}),(0,t.jsxs)("fieldset",{disabled:P,className:(0,F.cn)("min-w-0 space-y-3",P&&"opacity-50"),children:[(0,t.jsx)(V,{label:M?"Default profile":"Profile for this scope",hint:`このスコープのタスクのターミナル・${n.label} で使うアカウント。変更は開いているタブにも自動で反映されます`,children:(0,t.jsxs)("select",{value:u.assigned??"",onChange:e=>void A(e.target.value),className:"h-9 w-full rounded-md border border-input bg-transparent pl-3 pr-10 text-sm text-foreground shadow-xs",children:[!M&&(0,t.jsxs)("option",{value:"",children:["Inherit (",(l=u.effective,c.find(e=>e.slug===l)?.name??l),")"]}),c.map(e=>(0,t.jsx)("option",{value:M&&e.slug===Y?"":e.slug,children:e.name},e.slug))]})}),M&&(0,t.jsxs)("div",{className:"space-y-2",children:[c.map(e=>{var s;return(0,t.jsxs)("div",{className:"flex items-center justify-between gap-2 rounded-md border border-border p-3",children:[(0,t.jsxs)("div",{className:"flex min-w-0 items-center gap-3",children:[(0,t.jsx)(I,{className:"size-4 shrink-0 text-muted-foreground"}),(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsx)("div",{className:"text-sm font-medium text-foreground",children:e.name}),!P&&(0,t.jsxs)("div",{className:"flex items-center gap-1 truncate text-xs text-muted-foreground",children:[e.status.loggedIn?(0,t.jsx)(j.Check,{className:"size-3 shrink-0 text-success"}):(0,t.jsx)(D.default,{className:"size-3 shrink-0 text-warning"}),(0,t.jsx)("span",{className:"truncate",children:(s=e.status).loggedIn?[s.email,s.orgName??s.subscriptionType].filter(Boolean).join(" · ")||s.authMethod||"Logged in":"Not logged in"})]}),(0,t.jsx)("div",{className:"truncate text-[0.65rem] text-muted-foreground",children:(0,t.jsx)(q,{children:e.configDir??`${n.configDirEnv} 未指定(${n.defaultConfigDir})`})})]})]}),(0,t.jsxs)("div",{className:"flex shrink-0 items-center gap-1",children:[(0,t.jsxs)(x.Button,{variant:e.status.loggedIn?"ghost":"default",size:"sm",onClick:()=>S(e.slug),title:n.loginCommand,children:[(0,t.jsx)(U,{className:"size-4"}),e.status.loggedIn?"Re-login":"Login"]}),e.slug!==Y&&(0,t.jsx)(x.Button,{variant:"ghost",size:"icon",onClick:()=>$(e),className:"hover:bg-destructive/10",title:"Delete",children:(0,t.jsx)(C.Trash2,{className:"size-4 text-destructive"})})]})]},e.slug)}),v?(0,t.jsxs)("div",{className:"space-y-2 rounded-md border border-border bg-accent p-3",children:[(0,t.jsx)(L.Input,{value:N,onChange:e=>k(e.target.value),onKeyDown:e=>{"Enter"===e.key&&N.trim()&&!H&&_()},placeholder:"Profile name (e.g. work)",autoFocus:!0}),H?(0,t.jsx)("p",{className:"text-xs text-destructive",children:H}):N.trim()&&(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:(0,t.jsxs)(q,{children:["~/.tsunagi/",e,"-profiles/",et(N)]})}),(0,t.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,t.jsx)(x.Button,{variant:"outline",size:"sm",onClick:()=>{b(!1),k("")},children:(0,t.jsx)(f.X,{className:"size-4"})}),(0,t.jsx)(x.Button,{size:"sm",onClick:()=>void _(),disabled:!N.trim()||!!H,children:(0,t.jsx)(j.Check,{className:"size-4"})})]})]}):(0,t.jsxs)(x.Button,{variant:"outline",size:"sm",onClick:()=>b(!0),children:[(0,t.jsx)(g.Plus,{className:"size-4"}),"Add Profile"]})]})]}),K&&(0,t.jsx)(J,{profile:K,onClose:()=>{S(null),T()}}),(0,t.jsx)(O.ConfirmDialog,{open:null!==z,onOpenChange:e=>{e.open||$(null)},title:"Delete Profile",message:z?`${z.name} からログアウトし、${z.configDir} を削除します。このプロファイルを使っているスコープは親の設定を継承します。`:"",confirmLabel:"Delete",variant:"danger",onConfirm:()=>{z&&X(z)}})]})}let er=(0,l.default)("chevron-up",[["path",{d:"m18 15-6-6-6 6",key:"153udz"}]]);var el=e.i(5352);function en(){let[e,a]=(0,s.useState)([]),[r,l]=(0,s.useState)({}),[n,o]=(0,s.useState)(null),[c,d]=(0,s.useState)(!1),[u,h]=(0,s.useState)(!1),p=(0,s.useCallback)(async()=>{try{let[e,t]=await Promise.all([fetch((0,i.apiUrl)("/api/repos")).then(e=>e.json()),fetch((0,i.apiUrl)("/api/tasks")).then(e=>e.json())]);a(e.data??[]);let s={};for(let e of t.data?.tasks??[]){let t=`${e.owner}/${e.repo}`;s[t]=(s[t]??0)+1}l(s)}catch(e){console.error("Failed to load repositories:",e)}},[]);(0,s.useEffect)(()=>{p()},[p]);let g=async()=>{if(n){d(!0);try{if(!(await fetch((0,i.apiUrl)(`/api/repos/${n.owner}/${n.repo}`),{method:"DELETE"})).ok)throw Error("Failed to delete repository");await p()}catch(e){console.error("Failed to delete repository:",e)}finally{d(!1),o(null)}}},f=(0,s.useCallback)(async(t,s)=>{let r=t+s;if(r<0||r>=e.length)return;let l=[...e];[l[t],l[r]]=[l[r],l[t]],a(l.map((e,t)=>({...e,order:t}))),h(!0);try{if(!(await fetch((0,i.apiUrl)("/api/repos/reorder"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({repoIds:l.map(e=>e.id)})})).ok)throw Error("Failed to reorder repositories")}catch(e){console.error("Failed to reorder repositories:",e),await p()}finally{h(!1)}},[e,p]);return 0===e.length?(0,t.jsx)("div",{className:"text-sm text-muted-foreground",children:"No repositories cloned yet."}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(O.ConfirmDialog,{open:null!==n,onOpenChange:e=>{e.open||o(null)},title:"Delete Repository",message:n?`Delete ${n.owner}/${n.repo}? This will also delete ${r[`${n.owner}/${n.repo}`]??0} associated task(s), all worktrees, and the bare repository. This action cannot be undone.`:"",confirmLabel:c?"Deleting...":"Delete",cancelLabel:"Cancel",onConfirm:g,variant:"danger"}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:"この並び順がトップページの列の並び順になります"}),(0,t.jsx)("div",{className:"space-y-2",children:e.map((s,a)=>{let l=`${s.owner}/${s.repo}`,n=(0,el.getRepoColor)(s.owner,s.repo),i=r[l]??0;return(0,t.jsxs)("div",{className:"flex items-center justify-between gap-2 rounded-md border border-border p-3",children:[(0,t.jsxs)("div",{className:"flex min-w-0 items-center gap-3",children:[(0,t.jsx)("span",{className:`inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium ${n.bg} ${n.text}`,children:l}),(0,t.jsxs)("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:[i," task",1!==i?"s":""]})]}),(0,t.jsxs)("div",{className:"flex flex-shrink-0 items-center",children:[(0,t.jsx)(x.Button,{variant:"ghost",size:"icon",onClick:()=>f(a,-1),disabled:0===a||u,className:"text-muted-foreground",title:"Move up",children:(0,t.jsx)(er,{className:"size-4"})}),(0,t.jsx)(x.Button,{variant:"ghost",size:"icon",onClick:()=>f(a,1),disabled:a===e.length-1||u,className:"text-muted-foreground",title:"Move down",children:(0,t.jsx)(m,{className:"size-4"})}),(0,t.jsx)(x.Button,{variant:"ghost",size:"icon",onClick:()=>o(s),className:"text-muted-foreground hover:text-destructive",title:"Delete repository",children:(0,t.jsx)(C.Trash2,{className:"size-4"})})]})]},s.id)})})]})}var ei=e.i(69068);function eo({owner:e,repo:a,onDeleted:r}){let[l,n]=(0,s.useState)(!1),[o,c]=(0,s.useState)(""),[d,u]=(0,s.useState)(!1),m=`${e}/${a}`,h=o===m,p=async()=>{if(h){u(!0);try{if(!(await fetch((0,i.apiUrl)(`/api/repos/${e}/${a}`),{method:"DELETE"})).ok)throw Error("Failed to delete repository");r()}catch(e){console.error("Failed to delete repository:",e)}finally{u(!1),n(!1),c("")}}};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"rounded-md border border-destructive/30 p-4 space-y-3",children:[(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)("h3",{className:"text-sm font-semibold text-destructive",children:"Remove Repository"}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:"Remove this repository and all associated data including tasks, worktrees, and environment variables. This action cannot be undone."})]}),(0,t.jsxs)(x.Button,{variant:"destructive",size:"sm",onClick:()=>n(!0),children:[(0,t.jsx)(C.Trash2,{className:"size-4"}),"Remove Repository"]})]}),(0,t.jsx)(ei.Dialog,{open:l,onOpenChange:n,children:(0,t.jsxs)(ei.DialogContent,{showCloseButton:!1,children:[(0,t.jsxs)(ei.DialogHeader,{children:[(0,t.jsx)(ei.DialogTitle,{children:"Remove Repository"}),(0,t.jsxs)(ei.DialogDescription,{children:["This will permanently delete ",(0,t.jsx)("strong",{children:m})," and all associated tasks, worktrees, and environment variables."]})]}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsxs)("label",{className:"text-xs text-muted-foreground",children:["Type ",(0,t.jsx)("strong",{children:m})," to confirm"]}),(0,t.jsx)(L.Input,{value:o,onChange:e=>c(e.target.value),placeholder:m,autoComplete:"off"})]}),(0,t.jsxs)(ei.DialogFooter,{children:[(0,t.jsx)(x.Button,{variant:"outline",size:"sm",onClick:()=>{n(!1),c("")},disabled:d,children:"Cancel"}),(0,t.jsx)(x.Button,{variant:"destructive",size:"sm",onClick:p,disabled:!h||d,children:d?"Removing...":"Remove"})]})]})})]})}let ec=(0,l.default)("mic",[["path",{d:"M12 19v3",key:"npa21l"}],["path",{d:"M19 10v2a7 7 0 0 1-14 0v-2",key:"1vc78b"}],["rect",{x:"9",y:"2",width:"6",height:"13",rx:"3",key:"s6n7sd"}]]);function ed(){return(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsx)("h2",{className:"text-sm font-semibold text-foreground",children:"Voice Input"}),(0,t.jsxs)("div",{className:"flex items-center gap-3 rounded-md border border-border p-3",children:[(0,t.jsx)(ec,{className:"size-4 shrink-0 text-muted-foreground"}),(0,t.jsx)("p",{className:"min-w-0 flex-1 text-sm text-muted-foreground",children:"音声入力は mukuchi(macOS / Windows・無料)をご利用ください。話した内容をターミナルにそのまま入力できます"}),(0,t.jsxs)("a",{href:"https://mukuchi.minimalcorp.com/",target:"_blank",rel:"noreferrer",className:"inline-flex h-8 shrink-0 items-center gap-1 rounded-md border border-input bg-background px-3 text-sm shadow-xs transition-colors hover:bg-accent",children:["mukuchi",(0,t.jsx)(P.ExternalLink,{className:"size-3"})]})]})]})}var eu=e.i(31278);function em({className:e,size:s="default",...a}){return(0,t.jsx)("div",{"data-slot":"card","data-size":s,className:(0,F.cn)("group/card flex flex-col gap-4 overflow-hidden rounded-lg bg-card py-4 text-xs/relaxed text-card-foreground ring-1 ring-foreground/10 has-[>img:first-child]:pt-0 data-[size=sm]:gap-3 data-[size=sm]:py-3 *:[img:first-child]:rounded-t-lg *:[img:last-child]:rounded-b-lg",e),...a})}function ex({className:e,...s}){return(0,t.jsx)("div",{"data-slot":"card-header",className:(0,F.cn)("group/card-header @container/card-header grid auto-rows-min items-start gap-1 rounded-t-lg px-4 group-data-[size=sm]/card:px-3 has-data-[slot=card-action]:grid-cols-[1fr_auto] has-data-[slot=card-description]:grid-rows-[auto_auto] [.border-b]:pb-4 group-data-[size=sm]/card:[.border-b]:pb-3",e),...s})}function eh({className:e,...s}){return(0,t.jsx)("div",{"data-slot":"card-title",className:(0,F.cn)("font-heading text-sm font-medium",e),...s})}function ep({className:e,...s}){return(0,t.jsx)("div",{"data-slot":"card-description",className:(0,F.cn)("text-xs/relaxed text-muted-foreground",e),...s})}function eg({className:e,...s}){return(0,t.jsx)("div",{"data-slot":"card-content",className:(0,F.cn)("px-4 group-data-[size=sm]/card:px-3",e),...s})}let ef="/api/settings/claude-tui";function ej(){let[e,a]=(0,s.useState)(null),[r,l]=(0,s.useState)(!1);(0,s.useEffect)(()=>{R(ef).then(a).catch(e=>console.error("Failed to fetch Claude TUI settings:",e))},[]);let n=(0,s.useCallback)(async e=>{l(!0);try{a(await _(ef,e))}catch(e){y.toaster.create({type:"error",title:"画面描画の設定を保存できませんでした",description:G(e)})}finally{l(!1)}},[]);return(0,t.jsxs)(em,{children:[(0,t.jsxs)(ex,{children:[(0,t.jsx)(eh,{children:"Claude Code の画面描画"}),(0,t.jsxs)(ep,{children:["fullscreen レンダラでは、会話ログが重複・ループして表示される問題が起きません。OFF にすると Claude Code 自身の設定(",(0,t.jsx)(q,{children:"/tui"}),")に従います。起動中のタブは 応答が終わった後に再起動して反映されます。"]})]}),(0,t.jsx)(eg,{children:e?(0,t.jsxs)("label",{className:"flex items-center gap-2 text-sm",children:[(0,t.jsx)("input",{type:"checkbox",checked:e.fullscreen,disabled:r,onChange:e=>void n({fullscreen:e.target.checked}),className:"size-4 accent-primary"}),"fullscreen レンダラを使う(",(0,t.jsx)(q,{children:"CLAUDE_CODE_NO_FLICKER=1"}),")"]}):(0,t.jsxs)("span",{className:"flex items-center gap-2 text-muted-foreground",children:[(0,t.jsx)(eu.Loader2,{className:"size-4 animate-spin"}),"読み込み中..."]})})]})}var ev=e.i(63209),eb=e.i(95468);let eN=(0,l.default)("circle-question-mark",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3",key:"1u773s"}],["path",{d:"M12 17h.01",key:"p32p05"}]]);var ey=e.i(66992);let ek=(0,l.default)("memory-stick",[["path",{d:"M12 12v-2",key:"fwoke6"}],["path",{d:"M12 18v-2",key:"qj6yno"}],["path",{d:"M16 12v-2",key:"heuere"}],["path",{d:"M16 18v-2",key:"s1ct0w"}],["path",{d:"M2 11h1.5",key:"15p63e"}],["path",{d:"M20 18v-2",key:"12ehxp"}],["path",{d:"M20.5 11H22",key:"khsy7a"}],["path",{d:"M4 18v-2",key:"1c3oqr"}],["path",{d:"M8 12v-2",key:"1mwtfd"}],["path",{d:"M8 18v-2",key:"qcmpov"}],["rect",{x:"2",y:"6",width:"20",height:"10",rx:"2",key:"1qcswk"}]]);var ew=e.i(31343);let eC=(0,l.default)("power-off",[["path",{d:"M18.36 6.64A9 9 0 0 1 20.77 15",key:"dxknvb"}],["path",{d:"M6.16 6.16a9 9 0 1 0 12.68 12.68",key:"1x7qb5"}],["path",{d:"M12 2v4",key:"3427ic"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]]);var eS=e.i(16715),eL=e.i(47161),ez=e.i(41247),eE=e.i(93355),eO=e.i(38078);let e$={k:1024,m:1048576},eM=[32768,65536,131072,262144];function eD(e){let t=e.trim().replace(/[,_\s]/g,"").toLowerCase().match(/^(\d+(?:\.\d+)?)([km]?)$/);if(!t)return null;let s=Number(t[1])*(t[2]?e$[t[2]]:1);return Number.isInteger(s)&&s>0?s:null}function eP(e){return e>=e$.m&&e%e$.m==0?`${e/e$.m}m`:e>=e$.k&&e%e$.k==0?`${e/e$.k}k`:String(e)}var eU=e.i(64691);function eI({value:e,onChange:a,max:r}){let l=(0,s.useId)(),n=eD(e),i=null!==n&&void 0!==r&&r>0&&n>r,o=eM.filter(e=>!r||e<=r);return(0,t.jsxs)("div",{children:[(0,t.jsx)(L.Input,{value:e,onChange:e=>a(e.target.value),placeholder:"64k",list:l,"aria-invalid":null===n||i,className:"font-mono"}),(0,t.jsx)("datalist",{id:l,children:o.map(e=>(0,t.jsx)("option",{value:eP(e)},e))}),(0,t.jsx)("p",{className:`mt-1 text-[0.65rem] ${null===n||i?"text-destructive":"text-muted-foreground"}`,children:null===n?"64k / 128k / 1m または整数で入力してください(k = 1024)":i?`このモデルの最大値(${eP(r)})を超えています`:`${n.toLocaleString()} tokens`})]})}function eT(e,t){return`${e}:${t}`}function eF(e){let t=e.indexOf(":");if(t<0)return null;let s=e.slice(0,t);return"ollama"!==s&&"lmstudio"!==s?null:{provider:s,model:e.slice(t+1)}}function eB({status:e}){let s=e.active?`${e.active.model}(${eU.LOCAL_LLM_PROVIDER_LABEL[e.active.provider]}・${eP(e.active.contextTokens)})`:"";switch(e.state){case"unconfigured":return(0,t.jsx)("span",{className:"text-muted-foreground",children:"使用するモデルが未設定です"});case"loading":return(0,t.jsxs)("span",{className:"flex items-center gap-2 text-muted-foreground",children:[(0,t.jsx)(eu.Loader2,{className:"size-4 animate-spin"}),"読み込み中: ",s]});case"loaded":return(0,t.jsxs)("span",{className:"flex items-center gap-2 text-success",children:[(0,t.jsx)(eb.CheckCircle2,{className:"size-4"}),"読み込み済み: ",s]});case"unloaded":return(0,t.jsxs)("span",{className:"flex items-center gap-2 text-muted-foreground",children:[(0,t.jsx)(ek,{className:"size-4"}),"解放済み: ",s,"(次の発言で読み込みます)"]});case"error":return(0,t.jsxs)("span",{className:"flex items-center gap-2 text-destructive",children:[(0,t.jsx)(ev.AlertCircle,{className:"size-4"}),e.error]})}}function eA(){var e;let a,{settings:r,setSettings:l}=(0,eO.useLocalLlmSettings)(),[n,i]=(0,s.useState)(null),[o,c]=(0,s.useState)(null),[d,u]=(0,s.useState)(null),[m,h]=(0,s.useState)(!1),[p,g]=(0,s.useState)(null),[f,j]=(0,s.useState)(!1),[v,b]=(0,s.useState)(!1),[N,k]=(0,s.useState)(!1);(0,s.useEffect)(()=>{var e;r&&i({selection:(e=r).active?eT(e.active.provider,e.active.model):"",context:eP(e.active?.contextTokens??65536),idleUnloadMinutes:String(e.idleUnloadMinutes),unloadOnExit:e.unloadOnExit,webSearch:e.webSearch,extraEnvText:Object.entries(e.extraEnv).map(([e,t])=>`${e}=${t}`).join("\n")})},[r]);let w=(0,s.useCallback)(async()=>{try{c(await R("/api/settings/local-llm/status"))}catch(e){console.error("Failed to fetch local LLM status:",e)}},[]),C=(0,s.useCallback)(async()=>{h(!0);try{u(await R("/api/settings/local-llm/models"))}catch(e){y.toaster.create({type:"error",title:"モデル一覧を取得できません",description:G(e)})}finally{h(!1)}},[]);(0,s.useEffect)(()=>{w(),C();let e=setInterval(()=>void w(),3e3);return()=>clearInterval(e)},[w,C]);let S=n?eF(n.selection):null,z=(0,s.useMemo)(()=>d?.models.find(e=>e.provider===S?.provider&&e.model===S?.model),[d,S?.provider,S?.model]),E=z?.maxContextLength??void 0,$=S?.provider==="lmstudio"?S.model:"",M=n?eD(n.context):null;(0,s.useEffect)(()=>{if(g(null),!$||!M)return;let e=new AbortController,t=setTimeout(()=>{let t=new URLSearchParams({model:$,contextTokens:String(M)});R(`/api/settings/local-llm/estimate?${t}`,{signal:e.signal}).then(g).catch(()=>g(null))},600);return()=>{clearTimeout(t),e.abort()}},[$,M]);let D=Number(n?.idleUnloadMinutes),P=null!==n&&(e=n.context,null!==(a=eD(e))&&(!E||a<=E))&&Number.isInteger(D)&&D>=0,U=(0,s.useCallback)(async()=>{if(!n||!P)return;let e=eF(n.selection),t={active:e?{...e,contextTokens:eD(n.context)??65536}:null,idleUnloadMinutes:Number(n.idleUnloadMinutes),unloadOnExit:n.unloadOnExit,webSearch:n.webSearch,extraEnv:function(e){let t={};for(let s of e.split("\n")){let e=s.trim();if(!e||e.startsWith("#"))continue;let a=e.indexOf("=");a<=0||(t[e.slice(0,a).trim()]=e.slice(a+1).trim())}return t}(n.extraEnvText)},s=JSON.stringify(r?.active)!==JSON.stringify(t.active);j(!0);try{l(await _("/api/settings/local-llm",t)),y.toaster.create({type:"success",title:s?"使用するモデルを切り替えました(他のモデルは解放します)":"ローカルLLMの設定を保存しました"}),w()}catch(e){y.toaster.create({type:"error",title:"ローカルLLMの設定を保存できませんでした",description:G(e)})}finally{j(!1)}},[n,P,r?.active,l,w]),I=(0,s.useCallback)(async(e,t)=>{b(!0);try{c(await R(e,{method:"POST"}))}catch(e){y.toaster.create({type:"error",title:t,description:G(e)})}finally{b(!1)}},[]),T=e=>i(t=>t?{...t,...e}:t),F=(d?.models??[]).map(e=>{var t;return{value:eT(e.provider,e.model),label:[e.displayName,e.format.toUpperCase(),e.sizeBytes?(t=e.sizeBytes)>=0x40000000?`${(t/0x40000000).toFixed(1)} GB`:`${Math.round(t/1048576)} MB`:null,e.maxContextLength?`最大 ${eP(e.maxContextLength)}`:null].filter(Boolean).join(" · "),group:eU.LOCAL_LLM_PROVIDER_LABEL[e.provider]}}),B=r?.active;B&&!F.some(e=>e.value===eT(B.provider,B.model))&&F.unshift({value:eT(B.provider,B.model),label:`${B.model}(一覧にありません)`,group:eU.LOCAL_LLM_PROVIDER_LABEL[B.provider]});let A=null!==d&&0===d.models.length&&0===d.errors.length;return(0,t.jsxs)(em,{children:[(0,t.jsxs)(ex,{children:[(0,t.jsxs)("div",{className:"flex items-center gap-1",children:[(0,t.jsx)(eh,{children:"Claude Code のローカルLLM"}),(0,t.jsx)(x.Button,{variant:"ghost",size:"icon-sm",onClick:()=>k(!0),title:"ローカルLLMについて",children:(0,t.jsx)(eN,{})})]}),(0,t.jsxs)(ep,{children:["Ollama / LM Studio のローカルLLMで Claude Code を起動します。",(0,t.jsx)("strong",{className:"font-medium text-foreground",children:"使用するモデルは1つだけで、全てのローカルLLMタブで共有します"}),"。切り替えると他のモデルはメモリから解放されます。"]})]}),(0,t.jsx)(eg,{className:"flex flex-col gap-3",children:r&&n?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(X,{children:[o?(0,t.jsx)(eB,{status:o}):(0,t.jsx)(eu.Loader2,{className:"size-4 animate-spin"}),(0,t.jsxs)("div",{className:"ml-auto flex items-center gap-2",children:[o?.state==="unloaded"&&(0,t.jsxs)(x.Button,{variant:"outline",size:"sm",onClick:()=>void I("/api/settings/local-llm/load","モデルを読み込めません"),disabled:v,children:[(0,t.jsx)(ew.Play,{}),"読み込む"]}),(o?.state==="loaded"||o?.state==="error")&&(0,t.jsxs)(x.Button,{variant:"outline",size:"sm",onClick:()=>void I("/api/settings/local-llm/unload","モデルを解放できません"),disabled:v||(o?.inflight??0)>0,title:"メモリから外す(次の発言で自動で読み込み直します)",children:[v?(0,t.jsx)(eu.Loader2,{className:"animate-spin"}):(0,t.jsx)(eC,{}),"解放"]})]})]}),o&&o.inflight>0&&(0,t.jsxs)("p",{className:"text-[0.65rem] text-muted-foreground",children:["応答を生成中のタブがあります(",o.inflight,"件)。完了するまでモデルは切り替えられません。"]}),A?(0,t.jsx)("p",{className:"text-xs text-warning",children:"下の Ollama / LM Studio のどちらかを有効にすると、モデルを選べるようになります。"}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(V,{label:"使用するモデル",hint:d?.errors.length?(0,t.jsx)("span",{className:"text-destructive",children:d.errors.map(e=>`${eU.LOCAL_LLM_PROVIDER_LABEL[e.provider]}: ${e.message}`).join(" / ")}):`有効なプロバイダーにダウンロード済みのモデル(${d?.models.length??0}件)`,children:(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(eL.Combobox,{options:F,value:n.selection,onChange:e=>T({selection:String(e)}),placeholder:"モデルを選択",className:"flex-1"}),(0,t.jsx)(x.Button,{variant:"outline",size:"icon",onClick:()=>void C(),disabled:m,title:"モデル一覧を再取得",children:(0,t.jsx)(eS.RefreshCw,{className:m?"animate-spin":void 0})})]})}),(0,t.jsxs)(V,{label:"コンテキスト長",children:[(0,t.jsx)(eI,{value:n.context,onChange:e=>T({context:e}),max:E}),S?.provider==="lmstudio"&&(0,t.jsxs)("p",{className:"mt-1 flex items-center gap-1 text-[0.65rem] text-muted-foreground",children:[(0,t.jsx)(ey.Cpu,{className:"size-3"}),"必要メモリ(見積もり): ",p?.totalMemory??"-",z?.format==="mlx"&&"。MLX はモデルの最大値で読み込まれ、メモリは使った分だけ増えます"]}),S?.provider==="ollama"&&(0,t.jsxs)("p",{className:"mt-1 text-[0.65rem] text-muted-foreground",children:["このコンテキスト長を固定した派生モデル(",(0,t.jsx)(q,{children:"<モデル>-tsunagi-ctx<長さ>"}),")を作成して使います(重みは共有されます)。"]})]})]}),(0,t.jsx)(V,{label:"自動解放(分)",hint:"最後のリクエストからこの時間がたったらモデルをメモリから外します(0 で無効)。次の発言で自動で読み込み直します",children:(0,t.jsx)(L.Input,{type:"number",min:0,value:n.idleUnloadMinutes,onChange:e=>T({idleUnloadMinutes:e.target.value}),className:"w-32 font-mono"})}),(0,t.jsxs)("label",{className:"flex items-center gap-2 text-sm",children:[(0,t.jsx)("input",{type:"checkbox",checked:n.unloadOnExit,onChange:e=>T({unloadOnExit:e.target.checked}),className:"size-4 accent-primary"}),"tsunagi の終了時にモデルを解放する"]}),(0,t.jsxs)(V,{label:"WebSearch",children:[(0,t.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,t.jsx)(x.Button,{size:"sm",variant:"local"===n.webSearch?"default":"outline",onClick:()=>T({webSearch:"local"}),children:"ローカル検索(SearXNG)"}),(0,t.jsx)(x.Button,{size:"sm",variant:"ollama"===n.webSearch?"default":"outline",onClick:()=>T({webSearch:"ollama"}),children:"ollama.com(Ollama のみ・要サインイン)"})]}),(0,t.jsxs)("p",{className:"mt-1 text-[0.65rem] text-muted-foreground",children:["local"===n.webSearch?"組み込みの WebSearch を無効化し、ローカル検索(SearXNG)の web_search ツールを使います。":"使用するモデルが Ollama のとき、Ollama が ollama.com の Web 検索 API で代行します(Ollama 欄でサインイン状態を確認できます)。LM Studio のときはローカル検索になります。","設定はこの後に作成・起動したタブから反映されます。"]})]}),(0,t.jsx)(H,{children:(0,t.jsx)(V,{label:"追加の環境変数 (任意)",hint:"ローカルLLMタブにのみ適用されます。同名の既定値より優先されます",children:(0,t.jsx)(ez.Textarea,{value:n.extraEnvText,onChange:e=>T({extraEnvText:e.target.value}),placeholder:"KEY=VALUE(1行に1つ)",className:"min-h-16 font-mono text-xs"})})}),(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,t.jsxs)(x.Button,{size:"default",onClick:()=>void U(),disabled:f||!P,children:[f?(0,t.jsx)(eu.Loader2,{className:"animate-spin"}):S&&(0,t.jsx)(eE.LocalLlmIcon,{provider:S.provider,className:"size-4"}),"保存"]}),(0,t.jsx)("span",{className:"text-[0.65rem] text-muted-foreground",children:"モデルを変えて保存すると、他のモデルを解放して読み込みを始めます"})]})]}):(0,t.jsxs)("span",{className:"flex items-center gap-2 text-muted-foreground",children:[(0,t.jsx)(eu.Loader2,{className:"size-4 animate-spin"}),"読み込み中..."]})}),(0,t.jsx)(O.Dialog,{open:N,onOpenChange:({open:e})=>k(e),title:"ローカルLLMについて",maxWidth:"2xl",children:(0,t.jsxs)("div",{className:"space-y-4 text-sm",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"font-medium text-foreground",children:"実験的機能です"}),(0,t.jsx)("p",{className:"text-muted-foreground",children:"Claude Code の接続先を tsunagi の中継口に切り替え、tsunagi が Ollama / LM Studio の Anthropic 互換 API に転送します。Anthropic はClaude以外のモデルへの接続をサポートしていないため、動作は保証されません。"})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"font-medium text-foreground",children:"モデルは1つだけ"}),(0,t.jsx)("p",{className:"text-muted-foreground",children:"20〜30GB 級のモデルを2つ同時にメモリへ載せられるマシンは少ないため、使用するモデルは1つにし、全てのローカルLLMタブで共有します。切り替えると他のモデルは解放され、各タブは次の発言で会話全体を新しいモデルで読み直します(数十秒〜数分)。"})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"font-medium text-foreground",children:"/model について"}),(0,t.jsxs)("p",{className:"text-muted-foreground",children:["ローカルLLMタブでは ",(0,t.jsx)(q,{children:"/model"})," ","によるモデルの切り替えを無効にしています(Claude Code が切り替えたモデルを通常の Claude タブの既定値として保存してしまうため)。切り替えはここで行ってください。"]})]})]})})]})}var eR=e.i(82458),eR=eR;function e_(){let{settings:e,setSettings:a}=(0,eO.useOllamaSettings)(),[r,l]=(0,s.useState)(""),[n,i]=(0,s.useState)(!1),[c,d]=(0,s.useState)(null),[u,m]=(0,s.useState)(null),[h,p]=(0,s.useState)(!1),[g,f]=(0,s.useState)(null);(0,s.useEffect)(()=>{e&&l(e.baseUrl)},[e]);let j=(0,s.useCallback)(async e=>{i(!0);try{return a(await _("/api/settings/ollama",e)),!0}catch(e){return y.toaster.create({type:"error",title:"Ollama の設定を保存できませんでした",description:G(e)}),!1}finally{i(!1)}},[a]),v=(0,s.useCallback)(async e=>{try{d(await R(`/api/settings/ollama/status?baseUrl=${encodeURIComponent(e)}`))}catch(e){console.error("Failed to fetch Ollama status:",e)}},[]),b=(0,s.useCallback)(async e=>{p(!0),f(null);try{m(await R(`/api/settings/ollama/account?baseUrl=${encodeURIComponent(e)}`))}catch(e){m(null),f(G(e))}finally{p(!1)}},[]),N=e?.enabled===!0,k=e?.baseUrl;(0,s.useEffect)(()=>{if(!N||!k)return;v(k),b(k);let e=setInterval(()=>void v(k),5e3);return()=>clearInterval(e)},[N,k,v,b]);let w=(0,s.useCallback)(async()=>{e&&await j({...e,baseUrl:r})&&y.toaster.create({type:"success",title:"Ollama の設定を保存しました"})},[e,r,j]);return(0,t.jsxs)(em,{children:[(0,t.jsxs)(ex,{children:[(0,t.jsx)(eh,{children:"Ollama"}),(0,t.jsxs)(ep,{children:["ローカルLLMのプロバイダーとして Ollama を使います。Ollama のインストール・モデルの pull・起動はご自身で行ってください(例:"," ",(0,t.jsx)(q,{children:"ollama pull qwen3.6:35b-a3b-coding-nvfp4"}),")。"]})]}),(0,t.jsx)(eg,{className:"flex flex-col gap-3",children:e?N?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(X,{children:[c?c.reachable?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("span",{className:"flex items-center gap-2 text-success",children:[(0,t.jsx)(eb.CheckCircle2,{className:"size-4"}),"接続中",c.version&&` (v${c.version})`]}),(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:c.loaded.length>0?`読み込み中: ${c.loaded.map(e=>`${e.name}${e.contextLength?` (${eP(e.contextLength)})`:""}`).join(", ")}`:"読み込み中のモデルなし"})]}):(0,t.jsxs)("span",{className:"flex items-center gap-2 text-warning",children:[(0,t.jsx)(eR.default,{className:"size-4"}),"Ollama に接続できません。Ollama アプリを起動してください"]}):(0,t.jsxs)("span",{className:"flex items-center gap-2 text-muted-foreground",children:[(0,t.jsx)(eu.Loader2,{className:"size-4 animate-spin"}),"確認中..."]}),(0,t.jsx)(x.Button,{variant:"outline",size:"sm",className:"ml-auto",onClick:()=>void j({...e,enabled:!1}),disabled:n,children:"無効にする"})]}),(0,t.jsx)(V,{label:"ollama.com(WebSearch を Ollama に代行させる場合)",hint:(0,t.jsxs)(t.Fragment,{children:["「Claude Code のローカルLLM」欄の WebSearch を「ollama.com」にした場合のみ必要です。Ollama を動かしているマシンで"," ",(0,t.jsx)(q,{children:"ollama signin"})," を実行してください(検索クエリは ollama.com に送信されます)。"]}),children:(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-2 text-sm",children:[h?(0,t.jsxs)("span",{className:"flex items-center gap-2 text-muted-foreground",children:[(0,t.jsx)(eu.Loader2,{className:"size-4 animate-spin"}),"確認中..."]}):u?.signedIn?(0,t.jsxs)("span",{className:"flex items-center gap-2 text-success",children:[(0,t.jsx)(o,{className:"size-4"}),"サインイン済み(",u.name,")"]}):u?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("span",{className:"flex items-center gap-2 text-muted-foreground",children:[(0,t.jsx)(eR.default,{className:"size-4"}),"未サインイン"]}),u.signinUrl&&(0,t.jsxs)("a",{href:u.signinUrl,target:"_blank",rel:"noreferrer",className:(0,x.buttonVariants)({variant:"outline",size:"sm"}),children:[(0,t.jsx)(P.ExternalLink,{}),"サインイン"]})]}):(0,t.jsx)("span",{className:"text-xs text-destructive",children:g}),(0,t.jsx)(x.Button,{variant:"outline",size:"icon",onClick:()=>void b(e.baseUrl),disabled:h,title:"サインイン状態を再確認",children:(0,t.jsx)(eS.RefreshCw,{className:h?"animate-spin":void 0})})]})}),(0,t.jsx)(H,{children:(0,t.jsx)(V,{label:"Base URL",hint:(0,t.jsxs)(t.Fragment,{children:["Docker で tsunagi を動かしている場合は"," ",(0,t.jsx)(q,{children:"http://host.docker.internal:11434"})]}),children:(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(L.Input,{value:r,onChange:e=>l(e.target.value),placeholder:"http://localhost:11434"}),(0,t.jsx)(x.Button,{size:"default",onClick:()=>void w(),disabled:n||r===e.baseUrl,children:"保存"})]})})})]}):(0,t.jsxs)(x.Button,{size:"default",onClick:()=>void j({...e,enabled:!0}),disabled:n,children:[(0,t.jsx)(eE.OllamaIcon,{className:"size-4"}),"Ollama を有効化する"]}):(0,t.jsxs)("span",{className:"flex items-center gap-2 text-muted-foreground",children:[(0,t.jsx)(eu.Loader2,{className:"size-4 animate-spin"}),"読み込み中..."]})})]})}let eG=(0,l.default)("square",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]);var eR=eR;function eX(){let{settings:e,setSettings:a}=(0,eO.useLmStudioSettings)(),[r,l]=(0,s.useState)(null),[n,i]=(0,s.useState)(!1),[o,c]=(0,s.useState)(null),[d,u]=(0,s.useState)(!1);(0,s.useEffect)(()=>{e&&l({baseUrl:e.baseUrl,apiToken:e.apiToken,lmsPath:e.lmsPath})},[e]);let m=e?.enabled===!0,h=(0,s.useCallback)(async()=>{try{c(await R("/api/settings/lmstudio/status"))}catch(e){console.error("Failed to fetch LM Studio status:",e)}},[]);(0,s.useEffect)(()=>{if(!m)return;h();let e=setInterval(()=>void h(),5e3);return()=>clearInterval(e)},[m,h]);let p=(0,s.useCallback)(async e=>{i(!0);try{return a(await _("/api/settings/lmstudio",e)),!0}catch(e){return y.toaster.create({type:"error",title:"LM Studio の設定を保存できませんでした",description:G(e)}),!1}finally{i(!1)}},[a]),g=(0,s.useCallback)(async e=>{u(!0);try{c(await R(`/api/settings/lmstudio/server/${e}`,{method:"POST"}))}catch(t){y.toaster.create({type:"error",title:"start"===e?"サーバーを起動できません":"サーバーを停止できません",description:G(t)})}finally{u(!1)}},[]),f=(0,s.useCallback)(async()=>{e&&r&&await p({...e,...r})&&(y.toaster.create({type:"success",title:"LM Studio の設定を保存しました"}),h())},[e,r,p,h]),j=e=>l(t=>t?{...t,...e}:t);return(0,t.jsxs)(em,{children:[(0,t.jsxs)(ex,{children:[(0,t.jsx)(eh,{children:"LM Studio"}),(0,t.jsxs)(ep,{children:["ローカルLLMのプロバイダーとして LM Studio(0.4.1 以降)を使います。",(0,t.jsx)("a",{href:"https://lmstudio.ai/download",target:"_blank",rel:"noreferrer",className:"underline",children:"LM Studio"}),"のインストールとモデルのダウンロードはご自身で行ってください(例:"," ",(0,t.jsx)(q,{children:"mlx-community/Qwen3.6-35B-A3B-4bit"}),")。一度起動すると lms CLI が入ります。"]})]}),(0,t.jsx)(eg,{className:"flex flex-col gap-3",children:e&&r?m?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(X,{children:[o?o.serverRunning?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("span",{className:"flex items-center gap-2 text-success",children:[(0,t.jsx)(eb.CheckCircle2,{className:"size-4"}),"サーバー起動中"]}),(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:o.loaded.length>0?`読み込み中: ${o.loaded.map(e=>`${e.key} (${eP(e.contextLength)})`).join(", ")}`:"読み込み中のモデルなし"})]}):(0,t.jsxs)("span",{className:"flex items-center gap-2 text-warning",children:[(0,t.jsx)(eR.default,{className:"size-4"}),"サーバー停止中"]}):(0,t.jsxs)("span",{className:"flex items-center gap-2 text-muted-foreground",children:[(0,t.jsx)(eu.Loader2,{className:"size-4 animate-spin"}),"確認中..."]}),(0,t.jsxs)("div",{className:"ml-auto flex items-center gap-2",children:[o&&o.lmsPath?o.serverRunning?(0,t.jsxs)(x.Button,{variant:"outline",size:"sm",onClick:()=>void g("stop"),disabled:d,children:[d?(0,t.jsx)(eu.Loader2,{className:"animate-spin"}):(0,t.jsx)(eG,{}),"停止"]}):(0,t.jsxs)(x.Button,{size:"sm",onClick:()=>void g("start"),disabled:d,children:[d?(0,t.jsx)(eu.Loader2,{className:"animate-spin"}):(0,t.jsx)(ew.Play,{}),"起動"]}):null,(0,t.jsx)(x.Button,{variant:"outline",size:"sm",onClick:()=>void p({...e,enabled:!1}),disabled:n,children:"無効にする"})]})]}),o&&!o.lmsPath&&!o.serverRunning&&(0,t.jsxs)("p",{className:"text-xs text-muted-foreground",children:["tsunagi から LM Studio のサーバーを起動するための lms CLI が見つかりません(tsunagi を Docker で動かしている場合も同様です)。LM Studio アプリの Developer タブでサーバーを起動するか、LM Studio を動かしているマシンで"," ",(0,t.jsx)(q,{children:"lms server start"})," を実行してください。lms がある場合は詳細設定でパスを指定できます。"]}),(0,t.jsxs)(H,{children:[(0,t.jsx)(V,{label:"Base URL",children:(0,t.jsx)(L.Input,{value:r.baseUrl,onChange:e=>j({baseUrl:e.target.value}),placeholder:"http://localhost:1234"})}),(0,t.jsx)(V,{label:"API トークン (任意)",hint:"LM Studio で「Require Authentication」を有効にしている場合のみ",children:(0,t.jsx)(L.Input,{type:"password",value:r.apiToken,onChange:e=>j({apiToken:e.target.value})})}),(0,t.jsx)(V,{label:"lms のパス (任意)",hint:"空欄なら ~/.lmstudio/bin/lms → PATH の順で探します",children:(0,t.jsx)(L.Input,{value:r.lmsPath,onChange:e=>j({lmsPath:e.target.value}),placeholder:o?.lmsPath??"~/.lmstudio/bin/lms",className:"font-mono"})}),(0,t.jsx)("div",{children:(0,t.jsxs)(x.Button,{size:"default",onClick:()=>void f(),disabled:n,children:[n&&(0,t.jsx)(eu.Loader2,{className:"animate-spin"}),"保存"]})})]})]}):(0,t.jsxs)(x.Button,{size:"default",onClick:()=>void p({...e,enabled:!0}),disabled:n,children:[(0,t.jsx)(eE.LmStudioIcon,{className:"size-4"}),"LM Studio を有効化する"]}):(0,t.jsxs)("span",{className:"flex items-center gap-2 text-muted-foreground",children:[(0,t.jsx)(eu.Loader2,{className:"size-4 animate-spin"}),"読み込み中..."]})})]})}let eV=(0,l.default)("container",[["path",{d:"M22 7.7c0-.6-.4-1.2-.8-1.5l-6.3-3.9a1.72 1.72 0 0 0-1.7 0l-10.3 6c-.5.2-.9.8-.9 1.4v6.6c0 .5.4 1.2.8 1.5l6.3 3.9a1.72 1.72 0 0 0 1.7 0l10.3-6c.5-.3.9-1 .9-1.5Z",key:"1t2lqe"}],["path",{d:"M10 21.9V14L2.1 9.1",key:"o7czzq"}],["path",{d:"m10 14 11.9-6.9",key:"zm5e20"}],["path",{d:"M14 19.8v-8.1",key:"159ecu"}],["path",{d:"M18 17.5V9.4",key:"11uown"}]]),eH=(0,l.default)("package-x",[["path",{d:"M21 10V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l2-1.14",key:"e7tb2h"}],["path",{d:"m7.5 4.27 9 5.15",key:"1c824w"}],["polyline",{points:"3.29 7 12 12 20.71 7",key:"ousv84"}],["line",{x1:"12",x2:"12",y1:"22",y2:"12",key:"a4e8g8"}],["path",{d:"m17 13 5 5m-5 0 5-5",key:"im3w4b"}]]);var eq=e.i(91810),eK=e.i(20535);let eW={auto:"自動(searxng-run → Docker の順)",process:"searxng-run",docker:"Docker"};function eJ({status:e}){let s,{state:a,runner:r,docker:l}=e;if("not-installed"===a)return null;let n=(0,t.jsx)(q,{children:l.container}),i=(0,t.jsx)(q,{children:e.binPath??"searxng-run"});s="external"===a?"docker"===r?(0,t.jsxs)(t.Fragment,{children:["Docker コンテナ ",n,"(tsunagi 外で起動したため、tsunagi は停止しません)"]}):(0,t.jsx)(t.Fragment,{children:"tsunagi 外で起動した SearXNG(起動方法は不明。tsunagi は停止しません)"}):"running"===a?"docker"===r?(0,t.jsxs)(t.Fragment,{children:["Docker コンテナ ",n," を tsunagi が起動しました(停止時・終了時に停止します)"]}):(0,t.jsxs)(t.Fragment,{children:[i," を tsunagi が起動しました(停止時・終了時に停止します)"]}):"docker"===r?null===l.containerExists?(0,t.jsxs)(t.Fragment,{children:["Docker コンテナ ",n," を起動します(Docker が応答しません。Docker Desktop を起動してください)"]}):l.containerExists?(0,t.jsxs)(t.Fragment,{children:["Docker コンテナ ",n," を起動します"]}):(0,t.jsxs)(t.Fragment,{children:["Docker コンテナ ",n," を作成して起動します(初回はイメージの取得に数分かかります)"]}):(0,t.jsxs)(t.Fragment,{children:[i," を起動します"]});let o="docker"===r?eV:eK.SquareTerminal;return(0,t.jsxs)("p",{className:"flex items-start gap-1.5 text-xs text-muted-foreground",children:[(0,t.jsx)(o,{className:"mt-px size-3.5 shrink-0","aria-label":"起動方法"}),(0,t.jsx)("span",{children:s})]})}function eY(){let[e,a]=(0,s.useState)(null),[r,l]=(0,s.useState)(null),[n,i]=(0,s.useState)(null),[o,c]=(0,s.useState)(!1),[d,u]=(0,s.useState)(!1),m=(0,s.useCallback)(async()=>{try{a(await R("/api/settings/searxng/status"))}catch(e){console.error("Failed to fetch SearXNG status:",e)}},[]);(0,s.useEffect)(()=>{m(),R("/api/settings/searxng").then(l).catch(e=>console.error("Failed to fetch SearXNG settings:",e));let e=setInterval(()=>void m(),3e3);return()=>clearInterval(e)},[m]),(0,s.useEffect)(()=>{r&&i({port:String(r.port),method:r.method,binPath:r.binPath,settingsPath:r.settingsPath,dockerContainer:r.dockerContainer})},[r]);let h=(0,s.useCallback)(async(e,t)=>{c(!0);try{a(await R(e,{method:"POST"}))}catch(e){y.toaster.create({type:"error",title:t,description:G(e)})}finally{c(!1)}},[]),p=(0,s.useCallback)(async()=>{if(n){c(!0);try{l(await _("/api/settings/searxng",{port:Number(n.port),method:n.method,binPath:n.binPath,settingsPath:n.settingsPath,dockerContainer:n.dockerContainer}))}catch(e){y.toaster.create({type:"error",title:"SearXNG の設定を保存できませんでした",description:G(e)}),c(!1);return}c(!1),await h("/api/settings/searxng/restart","SearXNG を再起動できません")}},[n,h]);if(!e?.required)return null;let g=e=>i(t=>t?{...t,...e}:t);return(0,t.jsxs)(em,{children:[(0,t.jsxs)(ex,{children:[(0,t.jsxs)("div",{className:"flex items-center gap-1",children:[(0,t.jsx)(eh,{children:"ローカル検索 (SearXNG)"}),(0,t.jsx)(x.Button,{variant:"ghost",size:"icon-sm",onClick:()=>u(!0),title:"ローカル検索について",children:(0,t.jsx)(eN,{})})]}),(0,t.jsxs)(ep,{children:["Ollama / LM Studio タブの WebSearch をローカルの SearXNG で行います。",(0,t.jsx)("strong",{className:"font-medium text-foreground",children:"Ollama か LM Studio が有効な間、tsunagi が自動で起動・停止します"}),"。searxng-run が無ければ Docker で起動します(コンテナが無ければ作成します)。"]})]}),(0,t.jsxs)(eg,{className:"flex flex-col gap-3",children:[(0,t.jsxs)(X,{children:["running"===e.state||"external"===e.state?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("span",{className:"flex items-center gap-2 text-success",children:[(0,t.jsx)(eb.CheckCircle2,{className:"size-4"}),"running"===e.state?"起動中":"起動中(tsunagi 外で起動)"]}),(0,t.jsx)("span",{className:"font-mono text-xs text-muted-foreground",children:e.url})]}):"starting"===e.state?(0,t.jsxs)("span",{className:"flex items-center gap-2 text-muted-foreground",children:[(0,t.jsx)(eu.Loader2,{className:"size-4 animate-spin"}),e.message??"起動中","..."]}):"not-installed"===e.state?(0,t.jsxs)("span",{className:"flex items-center gap-2 text-warning",children:[(0,t.jsx)(eH,{className:"size-4"}),"SearXNG を起動できません(",(0,t.jsx)(q,{children:"searxng-run"})," も ",(0,t.jsx)(q,{children:"docker"})," ","も見つかりません)"]}):"error"===e.state?(0,t.jsxs)("span",{className:"flex items-center gap-2 text-destructive",children:[(0,t.jsx)(ev.AlertCircle,{className:"size-4"}),"エラー"]}):(0,t.jsx)("span",{className:"text-muted-foreground",children:"停止中"}),(0,t.jsxs)("div",{className:"ml-auto flex items-center gap-2",children:["external"!==e.state&&"starting"!==e.state&&(0,t.jsxs)(x.Button,{variant:"outline",size:"sm",onClick:()=>void h("/api/settings/searxng/restart","SearXNG を起動できません"),disabled:o,children:[(0,t.jsx)(eq.RotateCw,{}),"running"===e.state?"再起動":"起動"]}),"running"===e.state&&(0,t.jsxs)(x.Button,{variant:"outline",size:"sm",onClick:()=>void h("/api/settings/searxng/stop","SearXNG を停止できません"),disabled:o,children:[(0,t.jsx)(eG,{}),"停止"]})]})]}),(0,t.jsx)(eJ,{status:e}),"error"===e.state&&e.error&&(0,t.jsx)("pre",{className:"max-h-40 overflow-auto rounded-md bg-muted p-2 text-[0.65rem] whitespace-pre-wrap text-destructive",children:e.error}),"not-installed"===e.state&&(0,t.jsxs)("p",{className:"text-xs text-muted-foreground",children:["Docker Desktop を入れると、tsunagi がコンテナを作成して起動します(",(0,t.jsx)("a",{href:"https://minimalcorp.github.io/tsunagi/ja/features/local-search/",target:"_blank",rel:"noreferrer",className:"underline",children:"手順"}),")。Docker を使わない場合は、nix なら ",(0,t.jsx)(q,{children:"nix profile install nixpkgs#searxng"})," ","などで ",(0,t.jsx)(q,{children:"searxng-run"})," を PATH に入れてください(",(0,t.jsx)("a",{href:"https://docs.searxng.org/admin/installation.html",target:"_blank",rel:"noreferrer",className:"underline",children:"インストール方法"}),")。PATH にない場合は詳細設定でパスを指定できます。起動方法を固定したい場合も詳細設定で選べます。"]}),n&&(0,t.jsxs)(H,{children:[(0,t.jsx)(V,{label:"ポート",hint:"既定は 7964(キーパッドで sxng)",children:(0,t.jsx)(L.Input,{type:"number",min:1,max:65535,value:n.port,onChange:e=>g({port:e.target.value}),className:"font-mono"})}),(0,t.jsx)(V,{label:"起動方法",children:(0,t.jsx)("select",{value:n.method,onChange:e=>g({method:e.target.value}),className:"h-9 w-full rounded-md border border-input bg-transparent pl-3 pr-10 text-sm text-foreground shadow-xs",children:Object.keys(eW).map(e=>(0,t.jsx)("option",{value:e,children:eW[e]},e))})}),(0,t.jsx)(V,{label:"Docker のコンテナ名",hint:"無ければ tsunagi が公式イメージで作成します(設定は ~/.tsunagi/searxng/docker/<コンテナ名>/)",children:(0,t.jsx)(L.Input,{value:n.dockerContainer,onChange:e=>g({dockerContainer:e.target.value}),placeholder:"searxng",className:"font-mono"})}),(0,t.jsx)(V,{label:"searxng-run のパス (任意)",hint:"空欄なら PATH から探します",children:(0,t.jsx)(L.Input,{value:n.binPath,onChange:e=>g({binPath:e.target.value}),placeholder:e.binPath??"searxng-run",className:"font-mono"})}),(0,t.jsx)(V,{label:"settings.yml のパス (任意)",hint:"searxng-run で起動するときのみ。空欄なら tsunagi が生成したもの(~/.tsunagi/searxng/settings.yml)を使います。独自のものを使う場合は search.formats に json を含めてください",children:(0,t.jsx)(L.Input,{value:n.settingsPath,onChange:e=>g({settingsPath:e.target.value}),className:"font-mono"})}),(0,t.jsx)("div",{children:(0,t.jsxs)(x.Button,{size:"default",onClick:()=>void p(),disabled:o,children:[o&&(0,t.jsx)(eu.Loader2,{className:"animate-spin"}),"保存して再起動"]})})]})]}),(0,t.jsx)(O.Dialog,{open:d,onOpenChange:({open:e})=>u(e),title:"ローカル検索について",maxWidth:"2xl",children:(0,t.jsxs)("div",{className:"space-y-4 text-sm",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"font-medium text-foreground",children:"仕組み"}),(0,t.jsxs)("p",{className:"text-muted-foreground",children:["Claude Code の WebSearch は Anthropic のサーバーツールのため、ローカルLLMでは使えません(LM Studio は無視し、Ollama は ollama.com のサインインが必要)。ローカル検索を使うタブでは WebSearch を無効化し、tsunagi の MCP が提供する ",(0,t.jsx)(q,{children:"web_search"})," ツールで SearXNG に検索させます。"]})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"font-medium text-foreground",children:"自動起動・停止"}),(0,t.jsxs)("p",{className:"text-muted-foreground",children:["Ollama か LM Studio が有効なら、tsunagi の起動時・有効化時に SearXNG を起動し、両方を無効にしたときと tsunagi の終了時に停止します。起動方法は"," ",(0,t.jsx)(q,{children:"searxng-run"})," があればそれを、なければ Docker(コンテナが無ければ作成)を使います。既にポートで SearXNG が動いていればそれを使います(tsunagi は止めません)。SearXNG がなくても tsunagi 自体は通常どおり動きます。"]})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"font-medium text-foreground",children:"注意"}),(0,t.jsx)("p",{className:"text-muted-foreground",children:"SearXNG は Google / Bing / DuckDuckGo などの検索エンジンに問い合わせます。短時間に大量に検索すると、検索エンジン側で一時的にブロックされることがあります。"})]})]})})]})}var eZ=e.i(43034),eQ=e.i(37837),e0=e.i(99059),e1=e.i(44142);function e2(){let e=(0,e1.useUpdateStatus)(),a=(0,e1.useCheckForUpdate)(),[r,l]=(0,s.useState)(!1),n=async()=>{l(!0);try{await a()}catch(e){y.toaster.create({type:"error",title:"Failed to check for updates",description:e instanceof Error?e.message:String(e)})}finally{l(!1)}};return(0,t.jsxs)("div",{className:"border-t border-border p-3 space-y-1 text-xs",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between gap-1",children:[(0,t.jsxs)("span",{className:"font-medium text-foreground",children:["tsunagi ",e?.current?`v${e.current}`:"dev"]}),e?.current&&(0,t.jsx)(x.Button,{variant:"ghost",size:"icon-sm",onClick:()=>void n(),disabled:r,title:"Check for updates","aria-label":"Check for updates",children:(0,t.jsx)(eS.RefreshCw,{className:(0,F.cn)(r&&"animate-spin")})})]}),e?.updateAvailable?(0,t.jsxs)(eQ.Popover,{children:[(0,t.jsx)(eQ.PopoverTrigger,{className:"flex items-center gap-1 rounded-sm text-info hover:underline cursor-pointer outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50",children:"ready"===e.autoUpdate.state?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(eq.RotateCw,{className:"size-3.5"}),"Restart to update to v",e.autoUpdate.version]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(eZ.ArrowUpCircle,{className:"size-3.5"}),"v",e.latest," available"]})}),(0,t.jsx)(e0.UpdatePopoverContent,{status:e})]}):e?.checkedAt?(0,t.jsxs)("div",{className:"flex items-center gap-1 text-success",children:[(0,t.jsx)(eb.CheckCircle2,{className:"size-3.5"}),"Up to date"]}):(0,t.jsxs)("div",{className:"flex items-center gap-1 text-muted-foreground",children:[(0,t.jsx)(eN,{className:"size-3.5"}),"Not checked"]}),e?.entryOutdated&&!e.updateAvailable&&(0,t.jsxs)(eQ.Popover,{children:[(0,t.jsxs)(eQ.PopoverTrigger,{className:"flex items-center gap-1 rounded-sm text-warning hover:underline cursor-pointer outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50",children:[(0,t.jsx)(ev.AlertCircle,{className:"size-3.5"}),"Reinstall recommended"]}),(0,t.jsx)(e0.UpdatePopoverContent,{status:e})]}),e?.checkedAt&&(0,t.jsxs)("div",{className:"text-muted-foreground",children:["Last checked: ",new Date(e.checkedAt).toLocaleString()]})]})}var e4=e.i(51846),e3=e.i(81671);e.s(["default",0,function(){let e=(0,a.useRouter)();(0,e4.useDocumentTitle)("settings");let l=(0,e3.useAgentAvailability)(),o=l?.find(e=>"claude"===e.agent),c=o?.installed===!1,d=()=>{{let e=localStorage.getItem("tsunagi:env-selected-node");if(e)try{return JSON.parse(e)}catch(e){console.error("Failed to parse selected node:",e)}}return{scope:"global",label:"Global"}},[u,m]=(0,s.useState)(null),[h,g]=(0,s.useState)(0);return(0,s.useEffect)(()=>{fetch((0,i.apiUrl)("/api/onboarding/status")).then(e=>e.json()).then(e=>{e.data?.completed?m(d()):m({scope:"global",label:"Global"})}).catch(e=>{console.error("Failed to fetch onboarding status:",e),m(d())})},[]),(0,s.useEffect)(()=>{u&&localStorage.setItem("tsunagi:env-selected-node",JSON.stringify(u))},[u]),(0,t.jsxs)("div",{className:"h-screen flex flex-col bg-background",children:[(0,t.jsx)("div",{className:"sticky top-0 z-50 p-4 border-b border-border bg-card",children:(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)(x.Button,{variant:"ghost",onClick:()=>e.push("/"),className:"text-primary font-medium hover:bg-primary/10 hover:text-foreground",children:[(0,t.jsx)(r.ArrowLeft,{className:"w-4 h-4"}),"Back to Board"]}),(0,t.jsx)("h1",{className:"text-xl font-bold text-foreground absolute left-1/2 -translate-x-1/2",children:"Settings"}),(0,t.jsx)(e0.UpdateIndicator,{})]})}),(0,t.jsxs)("div",{className:"flex-1 flex min-h-0",children:[(0,t.jsxs)("div",{className:"w-64 border-r border-border bg-card flex flex-col",children:[(0,t.jsx)("div",{className:"flex-1 min-h-0",children:(0,t.jsx)(p,{selectedNode:u,onNodeSelect:e=>{m(e)},refreshKey:h})}),(0,t.jsx)(e2,{})]}),(0,t.jsx)("div",{className:"flex-1 bg-card p-4 overflow-y-auto",children:u?(0,t.jsxs)("div",{className:"space-y-6",children:[Q.map(e=>(0,t.jsx)(ea,{agent:e,availability:l?.find(t=>t.agent===e),selectedNode:u},e)),"global"===u.scope&&(0,t.jsx)(ej,{}),(0,t.jsx)(M,{selectedNode:u}),"global"===u.scope&&(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsx)("h2",{className:"text-sm font-semibold text-foreground",children:"Repositories"}),(0,t.jsx)(en,{})]}),"global"===u.scope&&(0,t.jsx)(ed,{}),"global"===u.scope&&(0,t.jsxs)("div",{className:"space-y-6",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2 pt-2 text-muted-foreground",children:[(0,t.jsx)(n,{className:"size-4"}),(0,t.jsx)("span",{className:"text-sm font-semibold",children:"Experimental"}),(0,t.jsx)("div",{className:"h-px flex-1 bg-border"})]}),(0,t.jsx)(es,{agent:"claude",availability:o}),(0,t.jsxs)("fieldset",{disabled:c,className:(0,F.cn)("min-w-0 space-y-6",c&&"opacity-50"),children:[(0,t.jsx)(eA,{}),(0,t.jsx)(e_,{}),(0,t.jsx)(eX,{})]}),(0,t.jsx)(eY,{})]}),"repo"===u.scope&&u.owner&&u.repo&&(0,t.jsx)(eo,{owner:u.owner,repo:u.repo,onDeleted:()=>{m({scope:"global",label:"Global"}),g(e=>e+1)}})]}):(0,t.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground text-sm",children:"Select a node from the left panel"})})]})]})}],82341)}]);
@@ -0,0 +1,14 @@
1
+ import type { ClaudeTuiSettings } from '@minimalcorp/tsunagi-shared';
2
+ export declare function getClaudeTuiSettings(): Promise<ClaudeTuiSettings>;
3
+ export declare function saveClaudeTuiSettings(settings: ClaudeTuiSettings): Promise<ClaudeTuiSettings>;
4
+ export declare function parseClaudeTuiSettings(value: unknown): {
5
+ settings: ClaudeTuiSettings;
6
+ } | {
7
+ error: string;
8
+ };
9
+ /**
10
+ * claude の起動時に渡す環境変数。OFF のときは何も渡さず、Claude Code 自身の設定(/tui)に任せる。
11
+ * CLAUDE_CODE_NO_FLICKER は settings.json の tui より優先されるため、ON の間は tsunagi 内の claude は
12
+ * 常に fullscreen になる(DB の環境変数で同名キーを設定すればそちらが優先される)
13
+ */
14
+ export declare function resolveClaudeTuiEnv(): Promise<Record<string, string>>;
@@ -0,0 +1,31 @@
1
+ import { readAppSetting, writeAppSetting } from './local-llm-env.js';
2
+ /**
3
+ * Claude Code の TUI レンダラ設定。
4
+ *
5
+ * 既定の classic レンダラは会話を通常画面に描くため、画面外へ流れた行を描き直せず、
6
+ * 内容が縮んだときや PTY の幅が変わったときにスクロールバックへ同じ行が重複して残る。
7
+ * fullscreen レンダラ(alt screen)ならこれが起きないため、tsunagi では既定で有効にする。
8
+ */
9
+ const SETTING_KEY = 'claudeTui';
10
+ const DEFAULT_SETTINGS = { fullscreen: true };
11
+ export function getClaudeTuiSettings() {
12
+ return readAppSetting(SETTING_KEY, DEFAULT_SETTINGS);
13
+ }
14
+ export function saveClaudeTuiSettings(settings) {
15
+ return writeAppSetting(SETTING_KEY, settings);
16
+ }
17
+ export function parseClaudeTuiSettings(value) {
18
+ const fullscreen = value?.fullscreen;
19
+ if (typeof fullscreen !== 'boolean')
20
+ return { error: 'fullscreen must be a boolean' };
21
+ return { settings: { fullscreen } };
22
+ }
23
+ /**
24
+ * claude の起動時に渡す環境変数。OFF のときは何も渡さず、Claude Code 自身の設定(/tui)に任せる。
25
+ * CLAUDE_CODE_NO_FLICKER は settings.json の tui より優先されるため、ON の間は tsunagi 内の claude は
26
+ * 常に fullscreen になる(DB の環境変数で同名キーを設定すればそちらが優先される)
27
+ */
28
+ export async function resolveClaudeTuiEnv() {
29
+ const { fullscreen } = await getClaudeTuiSettings();
30
+ return fullscreen ? { CLAUDE_CODE_NO_FLICKER: '1' } : {};
31
+ }
@@ -18,7 +18,8 @@ export { PtyLaunchError };
18
18
  /**
19
19
  * sessionId(=tab_id) から PTY の作業ディレクトリと環境変数を解決する。
20
20
  * 環境変数の優先順位: リクエストで渡されたenv > エージェント固有のenv(ローカルLLMの provider 等) >
21
- * DB env(global/owner/repo、エージェントのプロファイルを設定ディレクトリに変換) > tsunagi独自のEDITOR設定
21
+ * DB env(global/owner/repo、エージェントのプロファイルを設定ディレクトリに変換) >
22
+ * tsunagi独自の既定値(EDITOR・Claude の TUI レンダラ等)
22
23
  */
23
24
  export declare function resolvePtyLaunch(sessionId: string, request: PtyLaunchRequest): Promise<PtyLaunch>;
24
25
  /**
@@ -8,6 +8,7 @@ import { getWorktreePath } from './worktree-manager.js';
8
8
  import { getEnv } from './repositories/environment.js';
9
9
  import { resolveAgentProfileEnv } from './agent-profiles.js';
10
10
  import { AgentLaunchError as PtyLaunchError, getAgentForMode } from './agents/index.js';
11
+ import { resolveClaudeTuiEnv } from './claude-tui.js';
11
12
  // このファイル基準で解決する(cwd 非依存):
12
13
  // dev: apps/server/src/lib → apps/server/scripts
13
14
  // build: apps/server/dist/lib → apps/server/scripts
@@ -20,7 +21,8 @@ export { PtyLaunchError };
20
21
  /**
21
22
  * sessionId(=tab_id) から PTY の作業ディレクトリと環境変数を解決する。
22
23
  * 環境変数の優先順位: リクエストで渡されたenv > エージェント固有のenv(ローカルLLMの provider 等) >
23
- * DB env(global/owner/repo、エージェントのプロファイルを設定ディレクトリに変換) > tsunagi独自のEDITOR設定
24
+ * DB env(global/owner/repo、エージェントのプロファイルを設定ディレクトリに変換) >
25
+ * tsunagi独自の既定値(EDITOR・Claude の TUI レンダラ等)
24
26
  */
25
27
  export async function resolvePtyLaunch(sessionId, request) {
26
28
  // Taskに紐づかないタブは Tab レコードが存在しないため null になる。
@@ -56,7 +58,11 @@ export async function resolvePtyLaunch(sessionId, request) {
56
58
  const unsetKeys = [...new Set([...profile.unsetKeys, ...agentEnv.unsetKeys])];
57
59
  // tsunagi-editor.sh をデフォルトにすることで Ctrl+G が Monaco Modal を開く。
58
60
  // DB / リクエストで EDITOR が明示設定されている場合はそちらが優先される。
61
+ // claude を起動するタブ(terminal タブの Run も claude)には TUI レンダラの設定も既定値として渡す。
62
+ // DB の環境変数で CLAUDE_CODE_NO_FLICKER を明示した場合はそちらが優先される
63
+ const claudeTuiEnv = getAgentForMode(mode).id === 'claude' ? await resolveClaudeTuiEnv() : {};
59
64
  const tsunagiDefaultEnv = {
65
+ ...claudeTuiEnv,
60
66
  EDITOR: TSUNAGI_EDITOR_PATH,
61
67
  TSUNAGI_SESSION_ID: sessionId,
62
68
  // monaco-editor.sh が API(Fastify) を叩くためのベース URL。サーバーと同一
@@ -36,6 +36,8 @@ export interface PtySession {
36
36
  scrollbackSize: number;
37
37
  /** scrollback の先頭時点の PTY サイズ(最初のサイズ印より前の出力がこの幅で描かれた) */
38
38
  scrollbackStartSize: TerminalSize;
39
+ /** scrollback の先頭時点の DEC private mode(捨てた出力に含まれていたモード変更を反映したもの) */
40
+ scrollbackStartModes: ModeTracker;
39
41
  /** 最後にPTY出力があった時刻(GC判定用) */
40
42
  lastOutputAt: number;
41
43
  /** 最後にWebSocket接続があった時刻 */
@@ -53,6 +55,18 @@ export type ScrollbackEntry = string | TerminalSize;
53
55
  export interface ReplaySegment extends TerminalSize {
54
56
  data: string;
55
57
  }
58
+ /** 出力から DEC private mode の変更を拾う。チャンク境界で切れたシーケンスは次のチャンクとつなげて読む */
59
+ declare class ModeTracker {
60
+ readonly modes: Map<number, boolean>;
61
+ private carry;
62
+ feed(data: string): void;
63
+ /**
64
+ * 現在のモードをすべて明示的に設定するシーケンス。無効化を先に、有効化を後に並べる
65
+ * (xterm.js はマウス系のモードをどれか1つ無効化するとマウス追跡自体を止めるため、
66
+ * 有効化の後に別のマウスモードの無効化が来ると有効化が打ち消される)
67
+ */
68
+ toSequence(): string;
69
+ }
56
70
  declare class PtyManager {
57
71
  private sessions;
58
72
  /** sessionId → 最後に input を送信した socket.id */
@@ -83,6 +97,8 @@ declare class PtyManager {
83
97
  /**
84
98
  * 再接続時の画面復元用に、scrollback を PTY サイズごとの区間に分ける。
85
99
  * 末尾の区間は必ず現在の PTY サイズになる(出力が無くても返す)。
100
+ * 先頭の区間には scrollback の先頭時点の DEC private mode を設定するシーケンスを付ける
101
+ * (先頭が捨てられていても alt screen・マウス・bracketed paste の状態を正しく再現するため)。
86
102
  * @param transform 各区間の出力に適用する加工(端末クエリの除去など。区間ごとに join 済みの文字列を渡す)
87
103
  */
88
104
  getReplaySegments(session: PtySession, transform: (data: string) => string): ReplaySegment[];
@@ -46,6 +46,58 @@ function addTsunagiPluginDir(env) {
46
46
  env.CLAUDE_CODE_PLUGIN_DIRS = dirs.join(':');
47
47
  }
48
48
  const INITIAL_PTY_SIZE = { cols: 80, rows: 24 };
49
+ /**
50
+ * replay 時に復元する DEC private mode(ESC[?Nh / ESC[?Nl)と、端末の初期値。
51
+ * これらは有効化のシーケンスが起動時などに一度しか出力されないため、scrollback の上限で
52
+ * 先頭が捨てられると replay で失われる(例: fullscreen の Claude が出す ESC[?1049h が消え、
53
+ * alt screen に描くはずの画面が通常の画面に再生される)。
54
+ */
55
+ const TRACKED_MODE_DEFAULTS = new Map([
56
+ [1, false], // DECCKM(カーソルキーのアプリケーションモード)
57
+ [25, true], // カーソル表示
58
+ [47, false], // alt screen(旧式)
59
+ [1047, false], // alt screen
60
+ [1049, false], // alt screen(カーソル保存付き)
61
+ [1000, false], // マウス: クリック
62
+ [1002, false], // マウス: ドラッグ
63
+ [1003, false], // マウス: すべての移動
64
+ [1004, false], // フォーカスイベント
65
+ [1005, false], // マウス: UTF-8 形式
66
+ [1006, false], // マウス: SGR 形式
67
+ [1015, false], // マウス: urxvt 形式
68
+ [2004, false], // bracketed paste
69
+ ]);
70
+ /** 出力から DEC private mode の変更を拾う。チャンク境界で切れたシーケンスは次のチャンクとつなげて読む */
71
+ class ModeTracker {
72
+ modes = new Map(TRACKED_MODE_DEFAULTS);
73
+ carry = '';
74
+ feed(data) {
75
+ const text = this.carry + data;
76
+ for (const match of text.matchAll(/\x1b\[\?([0-9;]+)([hl])/g)) {
77
+ const enabled = match[2] === 'h';
78
+ for (const param of match[1].split(';')) {
79
+ const mode = Number(param);
80
+ if (this.modes.has(mode))
81
+ this.modes.set(mode, enabled);
82
+ }
83
+ }
84
+ // 末尾の書きかけのシーケンス(ESC / ESC[ / ESC[?123 など)は次のチャンクと合わせて読む
85
+ this.carry = /\x1b(\[(\?[0-9;]*)?)?$/.exec(text)?.[0] ?? '';
86
+ }
87
+ /**
88
+ * 現在のモードをすべて明示的に設定するシーケンス。無効化を先に、有効化を後に並べる
89
+ * (xterm.js はマウス系のモードをどれか1つ無効化するとマウス追跡自体を止めるため、
90
+ * 有効化の後に別のマウスモードの無効化が来ると有効化が打ち消される)
91
+ */
92
+ toSequence() {
93
+ const entries = Array.from(this.modes);
94
+ const set = (enabled) => entries
95
+ .filter(([, value]) => value === enabled)
96
+ .map(([mode]) => `\x1b[?${mode}${enabled ? 'h' : 'l'}`)
97
+ .join('');
98
+ return set(false) + set(true);
99
+ }
100
+ }
49
101
  class PtyManager {
50
102
  sessions = new Map();
51
103
  /** sessionId → 最後に input を送信した socket.id */
@@ -138,6 +190,7 @@ class PtyManager {
138
190
  scrollback: [],
139
191
  scrollbackSize: 0,
140
192
  scrollbackStartSize: INITIAL_PTY_SIZE,
193
+ scrollbackStartModes: new ModeTracker(),
141
194
  lastOutputAt: now,
142
195
  lastConnectedAt: now,
143
196
  gcTimer: null,
@@ -152,6 +205,8 @@ class PtyManager {
152
205
  const head = session.scrollback.shift();
153
206
  if (typeof head === 'string') {
154
207
  session.scrollbackSize -= head.length;
208
+ // 捨てる出力に含まれるモード変更は、先頭時点のモードとして持ち越す
209
+ session.scrollbackStartModes.feed(head);
155
210
  }
156
211
  else {
157
212
  // サイズ印を捨てる → 残りの先頭はこのサイズで描かれている
@@ -195,6 +250,8 @@ class PtyManager {
195
250
  /**
196
251
  * 再接続時の画面復元用に、scrollback を PTY サイズごとの区間に分ける。
197
252
  * 末尾の区間は必ず現在の PTY サイズになる(出力が無くても返す)。
253
+ * 先頭の区間には scrollback の先頭時点の DEC private mode を設定するシーケンスを付ける
254
+ * (先頭が捨てられていても alt screen・マウス・bracketed paste の状態を正しく再現するため)。
198
255
  * @param transform 各区間の出力に適用する加工(端末クエリの除去など。区間ごとに join 済みの文字列を渡す)
199
256
  */
200
257
  getReplaySegments(session, transform) {
@@ -222,6 +279,7 @@ class PtyManager {
222
279
  if (!last || last.cols !== current.cols || last.rows !== current.rows) {
223
280
  segments.push({ ...current, data: '' });
224
281
  }
282
+ segments[0].data = session.scrollbackStartModes.toSequence() + segments[0].data;
225
283
  return segments;
226
284
  }
227
285
  deleteSession(sessionId) {
@@ -3,6 +3,8 @@ import { getLmStudioSettings, getLmStudioStatus, parseLmStudioSettings, saveLmSt
3
3
  import { unloadProvider } from '../lib/local-llm.js';
4
4
  import { getSearxngSettings, getSearxngStatus, parseSearxngSettings, restartSearxng, saveSearxngSettings, stopSearxng, syncSearxng, } from '../lib/searxng.js';
5
5
  import { normalizeBaseUrl } from '../lib/local-llm-env.js';
6
+ import { getClaudeTuiSettings, parseClaudeTuiSettings, saveClaudeTuiSettings, } from '../lib/claude-tui.js';
7
+ import { notifyEnvChanged } from '../lib/pty-env-sync.js';
6
8
  /** クエリの baseUrl(未指定なら保存済みの値)を正規化する。不正なら null */
7
9
  async function resolveOllamaBaseUrl(baseUrl) {
8
10
  return normalizeBaseUrl(baseUrl || (await getOllamaSettings()).baseUrl);
@@ -20,6 +22,20 @@ async function sendResult(reply, run, prefix) {
20
22
  }
21
23
  }
22
24
  export async function settingsRoutes(fastify) {
25
+ // ---- Claude Code の TUI レンダラ ----
26
+ fastify.get('/settings/claude-tui', async (_request, reply) => {
27
+ return reply.status(200).send({ data: await getClaudeTuiSettings() });
28
+ });
29
+ fastify.put('/settings/claude-tui', async (request, reply) => {
30
+ const parsed = parseClaudeTuiSettings(request.body);
31
+ if ('error' in parsed) {
32
+ return reply.status(400).send({ error: parsed.error });
33
+ }
34
+ const saved = await saveClaudeTuiSettings(parsed.settings);
35
+ // 起動中の claude タブにも反映する(作り直して --resume。応答中などは反映待ちにする)
36
+ notifyEnvChanged().catch((err) => fastify.log.warn(err, 'Failed to sync PTY env'));
37
+ return reply.status(200).send({ data: saved });
38
+ });
23
39
  // ---- Ollama ----
24
40
  fastify.get('/settings/ollama', async (_request, reply) => {
25
41
  try {
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@minimalcorp/tsunagi",
3
- "version": "0.4.10",
3
+ "version": "0.5.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@minimalcorp/tsunagi",
9
- "version": "0.4.10",
9
+ "version": "0.5.0",
10
10
  "license": "SEE LICENSE IN LICENSE",
11
11
  "os": [
12
12
  "darwin",
@@ -4075,9 +4075,9 @@
4075
4075
  }
4076
4076
  },
4077
4077
  "node_modules/tslib": {
4078
- "version": "2.8.1",
4079
- "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz",
4080
- "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==",
4078
+ "version": "2.9.1",
4079
+ "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.9.1.tgz",
4080
+ "integrity": "sha512-a4Ux9VKuIMHsOS7ENbEq6hK2ZGYIT27Rtl0E4eD9KqwxhKiQeMZE/9xb3IdYwWaSOyIBQLExhQgXDTYoiCxnWA==",
4081
4081
  "license": "0BSD"
4082
4082
  },
4083
4083
  "node_modules/type-is": {
@@ -4202,9 +4202,9 @@
4202
4202
  "license": "ISC"
4203
4203
  },
4204
4204
  "node_modules/ws": {
4205
- "version": "8.22.0",
4206
- "resolved": "https://registry.npmjs.org/ws/-/ws-8.22.0.tgz",
4207
- "integrity": "sha512-Ydggc987+RO0AnWtZ/7Wq9FtNvcrL1b/RO0ud9mWjUPgDrsAAwQSF51sm2hm1XofbU/4jkpGEsLFsZZxU+1DOg==",
4205
+ "version": "8.22.1",
4206
+ "resolved": "https://registry.npmjs.org/ws/-/ws-8.22.1.tgz",
4207
+ "integrity": "sha512-oyL6OPYme/CmiFvNuGzeoxCJ4nOrZE2O1FwM9MWM1AsGri6nLXB2pg+lNA8aLeXMSav0J6eIVS1j6vUPzUtK9g==",
4208
4208
  "license": "MIT",
4209
4209
  "engines": {
4210
4210
  "node": ">=10.0.0"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@minimalcorp/tsunagi",
3
- "version": "0.4.10",
3
+ "version": "0.5.0",
4
4
  "description": "Multi-repo GitHub project management with Claude AI integration, designed for visualizing and controlling AI-driven development locally.",
5
5
  "keywords": [
6
6
  "tsunagi",