@orion-agents/orion-code 0.3.15 → 0.3.17

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 (44) hide show
  1. package/CHANGELOG.md +219 -0
  2. package/dist/runtime/release-receipts.d.ts +15 -3
  3. package/dist/runtime/release-receipts.js +27 -1
  4. package/dist/services/session-storage.d.ts +9 -0
  5. package/dist/services/session-storage.js +27 -1
  6. package/dist/web/git-compare-service.d.ts +45 -0
  7. package/dist/web/git-compare-service.js +160 -0
  8. package/dist/web/git-diff-document.d.ts +83 -0
  9. package/dist/web/git-diff-document.js +214 -0
  10. package/dist/web/git-file-source.d.ts +25 -0
  11. package/dist/web/git-file-source.js +21 -0
  12. package/dist/web/git-history-service.d.ts +151 -0
  13. package/dist/web/git-history-service.js +610 -0
  14. package/dist/web/git-index-transaction.d.ts +45 -0
  15. package/dist/web/git-index-transaction.js +174 -0
  16. package/dist/web/git-patch-builder.d.ts +30 -0
  17. package/dist/web/git-patch-builder.js +134 -0
  18. package/dist/web/git-read-model-service.d.ts +338 -18
  19. package/dist/web/git-read-model-service.js +1029 -110
  20. package/dist/web/git-version-service.d.ts +71 -0
  21. package/dist/web/git-version-service.js +255 -0
  22. package/dist/web/native-directory-picker.d.ts +63 -0
  23. package/dist/web/native-directory-picker.js +169 -0
  24. package/dist/web/protocol.d.ts +51 -2
  25. package/dist/web/server.js +384 -8
  26. package/dist/web/workbench-controller.d.ts +126 -10
  27. package/dist/web/workbench-controller.js +383 -15
  28. package/dist/web/workspace-open-telemetry.d.ts +55 -0
  29. package/dist/web/workspace-open-telemetry.js +73 -0
  30. package/dist/web-client/assets/FilesPanel-BARQCmne.js +1 -0
  31. package/dist/web-client/assets/GitPanel-DjB9eSiJ.js +4 -0
  32. package/dist/web-client/assets/ReviewPanel-YhEGlp-G.js +5 -0
  33. package/dist/web-client/assets/{TerminalPanel-BpsLphLv.js → TerminalPanel-DnWh3Vp2.js} +1 -1
  34. package/dist/web-client/assets/{index-D3sxrAh_.css → index--hnGXXjj.css} +1 -1
  35. package/dist/web-client/assets/index-Drja0_BT.js +20 -0
  36. package/dist/web-client/assets/{useAutoNotice-BeSf9Dfq.js → useAutoNotice-DfQi4G1X.js} +1 -1
  37. package/dist/web-client/index.html +2 -2
  38. package/npm-shrinkwrap.json +2 -2
  39. package/package.json +1 -1
  40. package/dist/web-client/assets/DiffViewer-C0A42Lma.js +0 -5
  41. package/dist/web-client/assets/FilesPanel-DiXKnFMj.js +0 -1
  42. package/dist/web-client/assets/GitPanel--_Yrbldp.js +0 -1
  43. package/dist/web-client/assets/ReviewPanel-BilzL9Ma.js +0 -1
  44. package/dist/web-client/assets/index-C2M48tcK.js +0 -20
@@ -1 +1 @@
1
- import{r as t,j as l,P as _,R as M,a as N,c as $,b as j}from"./index-C2M48tcK.js";function y({panelId:i,navigatorWidthPx:o,onNavigatorWidthCommit:e,contentLabel:d,navigatorLabel:h,handleLabel:s,contentClassName:r="",navigatorClassName:n="",children:p}){const[x,W]=t.Children.toArray(p),a=t.useRef(null),[E,T]=t.useState(0),[A,m]=t.useState(null);t.useEffect(()=>{const c=a.current;if(!c)return;const w=new ResizeObserver(S=>{const v=S[0]?.contentRect.width;v&&T(v)});return w.observe(c),()=>w.disconnect()},[]);const u=j(E),f=Math.min($(A??o),u),b=c=>{m(null),e(Math.min(c,u))},g=`${i}-split-content`,R=`${i}-split-navigator`;return l.jsxs("div",{ref:a,className:"resource-split-layout",style:{"--resource-navigator-width":`${f}px`},children:[l.jsx("section",{id:g,className:`resource-split-content${r?` ${r}`:""}`,"aria-label":d,children:W}),l.jsx(_,{side:"right",className:"resource-split-handle",minWidth:N,maxWidth:Math.max(N,u),defaultWidth:M,label:s,width:f,controls:R,boundsRef:a,resizingScope:"resource-split",onPreview:m,onCommit:b}),l.jsx("section",{id:R,className:`resource-split-navigator${n?` ${n}`:""}`,"aria-label":h,children:x})]})}const I=4e3;function D(){const[i,o]=t.useState(null),e=t.useRef(null);return t.useEffect(()=>()=>{e.current!==null&&window.clearTimeout(e.current)},[]),{notice:i,showNotice:(s,r="info")=>{e.current!==null&&(window.clearTimeout(e.current),e.current=null),o({text:s,tone:r}),r!=="error"&&(e.current=window.setTimeout(()=>{e.current=null,o(n=>n?.text===s?null:n)},I))},clearNotice:()=>{e.current!==null&&(window.clearTimeout(e.current),e.current=null),o(null)}}}export{y as R,D as u};
1
+ import{r as t,j as l,P as _,R as M,b as N,c as $,d as j}from"./index-Drja0_BT.js";function y({panelId:i,navigatorWidthPx:o,onNavigatorWidthCommit:e,contentLabel:d,navigatorLabel:h,handleLabel:s,contentClassName:r="",navigatorClassName:n="",children:p}){const[x,W]=t.Children.toArray(p),u=t.useRef(null),[E,T]=t.useState(0),[A,m]=t.useState(null);t.useEffect(()=>{const c=u.current;if(!c)return;const w=new ResizeObserver(S=>{const v=S[0]?.contentRect.width;v&&T(v)});return w.observe(c),()=>w.disconnect()},[]);const a=j(E),f=Math.min($(A??o),a),b=c=>{m(null),e(Math.min(c,a))},g=`${i}-split-content`,R=`${i}-split-navigator`;return l.jsxs("div",{ref:u,className:"resource-split-layout",style:{"--resource-navigator-width":`${f}px`},children:[l.jsx("section",{id:g,className:`resource-split-content${r?` ${r}`:""}`,"aria-label":d,children:W}),l.jsx(_,{side:"right",className:"resource-split-handle",minWidth:N,maxWidth:Math.max(N,a),defaultWidth:M,label:s,width:f,controls:R,boundsRef:u,resizingScope:"resource-split",onPreview:m,onCommit:b}),l.jsx("section",{id:R,className:`resource-split-navigator${n?` ${n}`:""}`,"aria-label":h,children:x})]})}const I=4e3;function D(){const[i,o]=t.useState(null),e=t.useRef(null);return t.useEffect(()=>()=>{e.current!==null&&window.clearTimeout(e.current)},[]),{notice:i,showNotice:(s,r="info")=>{e.current!==null&&(window.clearTimeout(e.current),e.current=null),o({text:s,tone:r}),r!=="error"&&(e.current=window.setTimeout(()=>{e.current=null,o(n=>n?.text===s?null:n)},I))},clearNotice:()=>{e.current!==null&&(window.clearTimeout(e.current),e.current=null),o(null)}}}export{y as R,D as u};
@@ -8,8 +8,8 @@
8
8
  <meta name="description" content="Orion Code local Web Workbench" />
9
9
  <link rel="icon" href="/favicon.svg" type="image/svg+xml" />
10
10
  <title>Orion Code</title>
11
- <script type="module" crossorigin src="/assets/index-C2M48tcK.js"></script>
12
- <link rel="stylesheet" crossorigin href="/assets/index-D3sxrAh_.css">
11
+ <script type="module" crossorigin src="/assets/index-Drja0_BT.js"></script>
12
+ <link rel="stylesheet" crossorigin href="/assets/index--hnGXXjj.css">
13
13
  </head>
14
14
  <body>
15
15
  <div id="root"></div>
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@orion-agents/orion-code",
3
- "version": "0.3.15",
3
+ "version": "0.3.17",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@orion-agents/orion-code",
9
- "version": "0.3.15",
9
+ "version": "0.3.17",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@clack/prompts": "^0.7.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orion-agents/orion-code",
3
- "version": "0.3.15",
3
+ "version": "0.3.17",
4
4
  "description": "Orion Code - local-first goal-driven coding agent for terminal and Web.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,5 +0,0 @@
1
- import{r as u,j as s,I as N}from"./index-C2M48tcK.js";function v(t){const n=[];let i;for(const r of t)r.startsWith("@@")?(i&&n.push(i),i={title:r,lines:[r]}):i&&i.lines.push(r);return i&&n.push(i),n}function D(t,n){const i={schemaVersion:1,type:"review_context",repositoryRevision:t.repositoryRevision,path:t.path,hunk:n.title},r=n.lines.join(`
2
- `).slice(0,12e3);return[`请审阅 ${t.path} 的这个 diff hunk,并指出正确性、安全性和测试风险:`,"","```review_context",JSON.stringify(i,null,2),"```","","```diff",r,"```"].join(`
3
- `)}function H({page:t,loading:n=!1,onLoadMore:i,onSendToComposer:r}){const a=u.useMemo(()=>v(t.lines),[t.lines]),[m,h]=u.useState(0),[f,p]=u.useState(!1),[x,k]=u.useState(!1),[b,y]=u.useState(""),d=Math.min(m,Math.max(0,a.length-1)),c=a[d];u.useEffect(()=>{h(0),p(!1),y("")},[t.fileId,t.repositoryRevision]);const j=(e,l)=>{let o=l;if(e.key==="ArrowRight"||e.key==="ArrowDown")o=(l+1)%a.length;else if(e.key==="ArrowLeft"||e.key==="ArrowUp")o=(l-1+a.length)%a.length;else if(e.key==="Home")o=0;else if(e.key==="End")o=a.length-1;else return;e.preventDefault(),h(o);const w=e.currentTarget.parentElement;window.requestAnimationFrame(()=>w?.querySelector(`[data-hunk-index="${o}"]`)?.focus())};return t.binary?s.jsxs("div",{className:"resource-empty compact",children:[s.jsx(N,{name:"code"}),s.jsx("strong",{children:"二进制差异"}),s.jsx("p",{children:"只展示变更事实,不返回 binary patch。"})]}):s.jsxs("div",{className:"diff-viewer",children:[s.jsxs("header",{children:[s.jsx("strong",{title:t.path,children:t.path}),s.jsx("span",{children:t.truncated?"受限预览":`${t.lines.length} 行`})]}),a.length>1?s.jsx("div",{className:"diff-hunk-nav",role:"tablist","aria-label":"Diff hunks",children:a.map((e,l)=>s.jsx("button",{type:"button",role:"tab","data-hunk-index":l,"aria-selected":d===l,tabIndex:d===l?0:-1,onClick:()=>h(l),onKeyDown:o=>j(o,l),children:e.title||`Hunk ${l+1}`},`${e.title}-${l}`))}):null,s.jsxs("div",{className:"diff-actions","aria-label":"Diff 显示选项",children:[c?s.jsx("button",{type:"button",className:"text-button","aria-expanded":!f,onClick:()=>p(e=>!e),children:f?"展开 Hunk":"折叠 Hunk"}):null,s.jsx("button",{type:"button",className:"text-button","aria-pressed":x,onClick:()=>k(e=>!e),children:"显示空白字符"}),c?s.jsx("button",{type:"button",className:"text-button",onClick:()=>{$(c.lines.join(`
4
- `),y)},children:"复制 Hunk"}):null]}),f?null:s.jsx("pre",{className:"diff-lines",tabIndex:0,"aria-label":`Diff ${t.path}`,children:(c?.lines??t.lines).map((e,l)=>s.jsxs("span",{className:e.startsWith("+")?"addition":e.startsWith("-")?"deletion":"",children:[S(e,x)||" ",`
5
- `]},`${l}:${e}`))}),b?s.jsx("p",{className:"resource-notice",role:"status",children:b}):null,s.jsxs("footer",{children:[r&&c?s.jsx("button",{type:"button",className:"secondary-button",onClick:()=>r(D(t,c)),children:"发送此 Hunk 到对话"}):null,t.nextCursor&&i?s.jsx("button",{type:"button",className:"text-button",onClick:i,disabled:n,children:n?"加载中…":"加载更多 Diff"}):null]})]})}function S(t,n){return n?t.replace(/\t/gu,"→ ").replace(/ +$/gu,i=>"·".repeat(i.length)):t}async function $(t,n){try{await navigator.clipboard.writeText(t),n("已复制当前 Hunk。")}catch{n("浏览器未允许复制,请手动选择 Diff。")}}export{H as D};
@@ -1 +0,0 @@
1
- import{r as o,j as e,I as R,s as ve,C as pe,W as be}from"./index-C2M48tcK.js";import{u as ye,R as ge}from"./useAutoNotice-BeSf9Dfq.js";function Fe({workspaceId:s,refreshEpoch:a,actions:l,navigatorWidthPx:r,onNavigatorWidthCommit:d}){const[u,h]=o.useState({}),[j,m]=o.useState(new Set(["workspace-root"])),[n,x]=o.useState(null),[b,z]=o.useState(""),[B,M]=o.useState(null),[X,G]=o.useState(!1),[Y,K]=o.useState(""),{notice:H,showNotice:D,clearNotice:J}=ye(),[T,le]=o.useState(""),[V,P]=o.useState({}),[Z,_]=o.useState(""),[A,F]=o.useState("view"),[$,w]=o.useState(""),[k,q]=o.useState(!1),[ce,S]=o.useState(!1),[ue,de]=o.useState(""),[fe,O]=o.useState(!1),f=o.useRef(0),N=o.useRef(0),I=o.useRef(null),E=async(t,i=!1,g=f.current)=>{if(g!==f.current)return;const v=u[t],C=i?v?.nextCursor:void 0;if(!(i&&!C)){h(c=>({...c,[t]:{items:v?.items??[],nextCursor:v?.nextCursor??null,revision:v?.revision??"",loading:!0}}));try{const c=await l.listFiles(t,C??void 0);if(g!==f.current)return;h(p=>({...p,[t]:{items:i?Ne(p[t]?.items??[],c.items):c.items,nextCursor:c.nextCursor,revision:c.revision,loading:!1}}))}catch(c){if(g!==f.current)return;if(i&&Q(c)){D("目录已变化,已重新载入第一页。"),E(t,!1,g);return}h(p=>({...p,[t]:{items:p[t]?.items??[],nextCursor:p[t]?.nextCursor??null,revision:p[t]?.revision??"",loading:!1,error:L(c)}}))}}},W=async(t=f.current)=>{try{const i=await l.gitStatus();if(t!==f.current)return;P(we(i)),_(i.nextCursor?"Git 装饰仅显示首批 200 个变更;在 Git 面板继续分页查看。":"")}catch(i){if(t!==f.current)return;P({}),_(`Git 状态装饰不可用:${L(i)}`)}},ee=o.useRef(s);o.useEffect(()=>{const t=f.current+1;f.current=t,N.current+=1;const i=ee.current===s?I.current:null;ee.current=s,h({}),m(new Set(["workspace-root"])),x(i),z(""),M(null),G(!1),K(""),J(),P({}),_(""),s&&(E("workspace-root",!1,t),W(t),i&&y(i,!1,!1,t))},[a,s]);const y=async(t,i=!1,g=!1,v=f.current,C=N.current+1)=>{if(v===f.current&&!(!t.readable||t.sensitive||U(t))){N.current=C,x(t),K(""),i||(z(""),M(null),G(!1),F("view"),w(""),S(!1)),g||J();try{const c=await l.readFileContent(t.id,i?B??void 0:void 0);if(v!==f.current||C!==N.current)return;G(c.binary),z(p=>i?`${p}${c.content??""}`:c.content??""),M(c.nextCursor),de(c.revision),g&&D("文件已变化,已从第一页重新载入。")}catch(c){if(v!==f.current||C!==N.current)return;if(i&&Q(c)){await y(t,!1,!0,v,C);return}K(L(c))}}},te=Se({selected:n,binary:X,hasMorePages:B!==null}),me=()=>{w(b),S(!1),F("edit")},se=()=>{if($!==b){O(!0);return}re()},re=()=>{F("view"),w(""),S(!1),O(!1)},xe=async()=>{if(!(!n||k)){q(!0),S(!1);try{await l.writeFileContent(n.id,$,ue),F("view"),w(""),await y(n,!1,!0,f.current,N.current+1),D("已保存文件。","success"),W()}catch(t){Q(t)?S(!0):D(L(t),"error")}finally{q(!1)}}},ne=t=>{const i=new Set(j);i.has(t)?i.delete(t):(i.add(t),u[t]||E(t)),m(i)};o.useEffect(()=>{I.current=n},[n]);const he=o.useMemo(()=>Object.values(u).flatMap(t=>t.items),[u]),ie=T.trim()?he.filter(t=>t.name.toLocaleLowerCase().includes(T.toLocaleLowerCase())):null,je=!!u["workspace-root"]?.loading;return e.jsxs("div",{className:"work-resource-panel files-panel",children:[e.jsxs("div",{className:"resource-toolbar",children:[e.jsxs("label",{className:"resource-search",children:[e.jsx("span",{className:"sr-only",children:"搜索已加载文件"}),e.jsx(R,{name:"search",size:16}),e.jsx("input",{type:"search",value:T,onChange:t=>le(t.target.value),placeholder:"搜索已加载文件",title:"搜索仅覆盖已加载的目录和文件"})]}),e.jsx("button",{type:"button",className:"icon-button","aria-label":"刷新文件树","aria-busy":je,onClick:()=>{E("workspace-root"),W()},children:e.jsx(R,{name:"refresh",size:16})})]}),e.jsxs(ge,{panelId:"files",navigatorWidthPx:r,onNavigatorWidthCommit:d,contentLabel:"文件预览",navigatorLabel:"工作区文件",handleLabel:"调整文件目录宽度",contentClassName:"file-preview",navigatorClassName:"file-tree",children:[e.jsxs(e.Fragment,{children:[Z?e.jsx("p",{className:"resource-hint",role:"status",children:Z}):null,ie?e.jsx(e.Fragment,{children:e.jsx("ul",{role:"list",className:"file-node-list search-results",children:ie.map(t=>e.jsx(ae,{node:t,depth:0,expanded:!1,selected:n?.id===t.id,gitLabels:V[t.displayPath]??[],onToggle:ne,onSelect:i=>{y(i)}},t.id))})}):e.jsx(oe,{parentId:"workspace-root",depth:0,directories:u,expanded:j,selectedId:n?.id,gitDecorations:V,onToggle:ne,onSelect:t=>{y(t)},onLoadMore:t=>{E(t,!0)}})]}),e.jsxs(e.Fragment,{children:[H?e.jsx("p",{className:"resource-notice",role:"status",children:H.text}):null,n?e.jsxs(e.Fragment,{children:[e.jsxs("header",{children:[e.jsx("strong",{children:n.name}),e.jsx("span",{children:Ee(n.sizeBytes??0)})]}),Y?e.jsx("p",{className:"resource-error",role:"alert",children:Y}):X?e.jsxs("div",{className:"resource-empty",children:[e.jsx(R,{name:"code",size:16}),e.jsx("strong",{title:"出于安全和性能考虑,只显示元数据。",children:"二进制文件"})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"file-preview-actions",children:A==="view"?e.jsx("button",{type:"button",className:"text-button",disabled:!te,title:te?void 0:"仅支持编辑 512 KB 内的 UTF-8 文本文件",onClick:me,children:"编辑"}):e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"primary-button",disabled:k||$===b,"aria-busy":k,onClick:()=>{xe()},children:k?"保存中…":"保存"}),e.jsx("button",{type:"button",className:"text-button",disabled:k,onClick:se,children:"取消"})]})}),ce?e.jsxs("p",{className:"resource-error",role:"alert",children:["文件已在别处变更,保存被拒绝。",e.jsx("button",{type:"button",className:"text-button",onClick:()=>{y(n,!1,!0)},children:"重新加载"})]}):null,A==="edit"?e.jsx("textarea",{className:"file-editor",value:$,spellCheck:!1,"aria-label":`编辑文件 ${n.name}`,onChange:t=>w(t.target.value),onKeyDown:t=>{t.key==="Escape"&&(t.preventDefault(),se())}}):e.jsx("pre",{tabIndex:0,className:"file-code-view","aria-label":`文件内容 ${n.name}`,children:ve(b)})]}),B&&A==="view"?e.jsx("button",{type:"button",className:"secondary-button",onClick:()=>{y(n,!0)},children:"加载更多内容"}):null]}):e.jsxs("div",{className:"resource-empty",children:[e.jsx(R,{name:"workspace",size:16}),e.jsx("strong",{children:"选择文件预览"}),e.jsx("p",{title:"敏感文件、工作区外链接和二进制正文不会返回浏览器。",children:"受限内容不会返回浏览器。"})]})]})]}),e.jsx(pe,{open:fe,onClose:()=>O(!1),title:"放弃未保存的修改?",body:"当前草稿尚未保存,放弃后将回到文件的最新内容。",confirmLabel:"放弃修改",danger:!0,onConfirm:re})]})}function oe({parentId:s,depth:a,directories:l,expanded:r,selectedId:d,gitDecorations:u,onToggle:h,onSelect:j,onLoadMore:m}){const n=l[s];return n?n.error?e.jsx("p",{className:"resource-error",role:"alert",children:n.error}):e.jsxs("ul",{role:"list",className:"file-node-list",children:[n.items.map(x=>{const b=r.has(x.id);return e.jsxs("li",{children:[e.jsx(ae,{node:x,depth:a,expanded:b,selected:d===x.id,gitLabels:u[x.displayPath]??[],onToggle:h,onSelect:j}),U(x)&&b?e.jsx(oe,{parentId:x.id,depth:a+1,directories:l,expanded:r,selectedId:d,gitDecorations:u,onToggle:h,onSelect:j,onLoadMore:m}):null]},x.id)}),n.loading?e.jsx("li",{className:"resource-loading",children:"正在读取…"}):null,n.nextCursor?e.jsx("li",{children:e.jsx("button",{type:"button",className:"text-button",onClick:()=>m(s),children:"加载更多"})}):null]}):e.jsx("p",{className:"resource-loading",children:"正在读取…"})}function ae({node:s,depth:a,expanded:l,selected:r,gitLabels:d,onToggle:u,onSelect:h}){const j=s.sensitive||!s.readable,m=U(s);return e.jsxs("button",{type:"button",className:`file-node ${r?"selected":""} ${j?"blocked":""}`,style:{paddingInlineStart:`${8+a*15}px`},"aria-expanded":m?l:void 0,"aria-label":`${Ce(s)} ${s.name}${j?",不可读取":""}${d.length?`,Git ${d.join("、")}`:""}`,onClick:()=>m?u(s.id):h(s),disabled:j,children:[e.jsx(R,{name:m?"workspace":"code",size:16}),e.jsx("span",{children:s.name}),s.kind==="symlink"?e.jsx("small",{children:"链接"}):null,s.sensitive?e.jsx("small",{children:"敏感"}):null,d.length?e.jsx("small",{className:"file-git-status",title:`Git ${d.join("、")}`,children:d.join(" · ")}):null]})}function Ce(s){return s.kind==="directory"?"目录":s.kind==="symlink"?s.targetKind==="directory"?"符号链接目录":"符号链接":"文件"}function U(s){return s.kind==="directory"||s.kind==="symlink"&&s.targetKind==="directory"}function Ne(s,a){const l=new Map(s.map(r=>[r.id,r]));for(const r of a)l.set(r.id,r);return[...l.values()]}function we(s){if(!s.isRepository)return{};const a=new Map,l=(r,d)=>{const u=r.replace(/\\/gu,"/").replace(/^\.\//u,"");if(!u)return;const h=a.get(u)??new Set;h.add(d),a.set(u,h);const j=u.split("/");for(let m=1;m<j.length;m+=1){const n=j.slice(0,m).join("/"),x=a.get(n)??new Set;x.add("含变更"),a.set(n,x)}};return s.conflicted.forEach(r=>l(r.path,"冲突")),s.staged.forEach(r=>l(r.path,"已暂存")),s.unstaged.forEach(r=>l(r.path,"未暂存")),s.untracked.forEach(r=>l(r.path,"未跟踪")),Object.fromEntries([...a].map(([r,d])=>[r,Object.freeze([...d])]))}const ke=512*1024;function Se(s){const{selected:a,binary:l,hasMorePages:r}=s;return!a||l||a.sensitive||!a.readable||r?!1:(a.sizeBytes??0)<=ke}function Ee(s){return s<1024?`${s} B`:s<1048576?`${(s/1024).toFixed(1)} KB`:`${(s/1048576).toFixed(1)} MB`}function Q(s){return s instanceof be&&s.code==="file_revision_conflict"}function L(s){return s instanceof Error?s.message:"文件请求失败。"}export{ke as FILE_EDIT_MAX_BYTES,Fe as FilesPanel,Se as canEditFileContent};
@@ -1 +0,0 @@
1
- import{r as f,j as e,I as g,W as F}from"./index-C2M48tcK.js";import{u as B,R as J}from"./useAutoNotice-BeSf9Dfq.js";import{D as K}from"./DiffViewer-C0A42Lma.js";function Y({workspaceId:c,refreshEpoch:m,actions:u,onSendToComposer:o,navigatorWidthPx:_,onNavigatorWidthCommit:P}){const[a,S]=f.useState(null),[p,I]=f.useState(null),[k,y]=f.useState(null),[v,N]=f.useState(null),[j,h]=f.useState(!1),[R,d]=f.useState(""),{notice:E,showNotice:L,clearNotice:$}=B(),n=f.useRef(0),x=f.useRef(0),b=async(t=n.current)=>{if(t===n.current){h(!0),d("");try{const[s,l]=await Promise.all([u.gitStatus(),u.gitLog()]);if(t!==n.current)return;S(s),I(l),y(null),N(null)}catch(s){if(t!==n.current)return;d(w(s))}finally{t===n.current&&h(!1)}}},z=()=>{const t=n.current+1;n.current=t,x.current+=1,$(),b(t)};f.useEffect(()=>{const t=n.current+1;n.current=t,x.current+=1,S(null),I(null),y(null),N(null),d(""),$(),c&&b(t)},[m,c]);const A=async(t,s,l=n.current,r=x.current+1)=>{if(l===n.current){x.current=r,s||(y(t),N(null)),h(!0),d("");try{const i=await u.gitDiff(t.fileId,s);if(l!==n.current||r!==x.current||i.fileId!==t.fileId)return;y(t),N(G=>s&&G&&G.fileId===i.fileId?{...i,lines:[...G.lines,...i.lines]}:i)}catch(i){if(l!==n.current||r!==x.current)return;if(D(i)){L("仓库已变化,已重新载入 Git 状态。"),await b(l);return}d(w(i))}finally{l===n.current&&r===x.current&&h(!1)}}},W=async()=>{const t=a?.nextCursor;if(!t||!a)return;const s=n.current,l=a.repositoryRevision;h(!0),d("");try{const r=await u.gitStatus(t);if(s!==n.current)return;if(r.repositoryRevision!==l)throw M();S(i=>!i||i.repositoryRevision!==l?i:{...r,conflicted:C(i.conflicted,r.conflicted),staged:C(i.staged,r.staged),unstaged:C(i.unstaged,r.unstaged),untracked:C(i.untracked,r.untracked)})}catch(r){if(s!==n.current)return;if(D(r)){L("仓库已变化,已重新载入 Git 状态。"),await b(s);return}d(w(r))}finally{s===n.current&&h(!1)}},H=async()=>{const t=p?.nextCursor;if(!t||!p)return;const s=n.current,l=p.repositoryRevision;h(!0),d("");try{const r=await u.gitLog(t);if(s!==n.current)return;if(r.repositoryRevision!==l)throw M();I(i=>!i||i.repositoryRevision!==l?i:{...r,items:Q(i.items,r.items)})}catch(r){if(s!==n.current)return;if(D(r)){L("提交历史已变化,已重新载入第一页。"),await b(s);return}d(w(r))}finally{s===n.current&&h(!1)}};if(R&&!a)return e.jsx(O,{message:R,onRetry:z});if(!a)return e.jsx("p",{className:"resource-loading",children:"正在读取 Git 状态…"});if(!a.isRepository)return e.jsxs("div",{className:"resource-empty",children:[e.jsx(g,{name:"branch",size:16}),e.jsx("strong",{children:"当前项目不是 Git 仓库"}),e.jsx("p",{children:"文件和 Agent 不受影响。"})]});const V=[{label:"冲突",tone:"conflict",items:a.conflicted},{label:"已暂存",tone:"staged",items:a.staged},{label:"未暂存",tone:"unstaged",items:a.unstaged},{label:"未跟踪",tone:"untracked",items:a.untracked}];return e.jsxs("div",{className:"work-resource-panel git-panel",children:[e.jsxs("div",{className:"git-summary",children:[e.jsxs("div",{children:[e.jsx(g,{name:"branch",size:16}),e.jsx("strong",{children:a.detached?`detached ${a.head??""}`:a.branch||"HEAD"})]}),e.jsxs("span",{children:[a.upstream||"无 upstream",a.ahead||a.behind?` · ↑${a.ahead} ↓${a.behind}`:""]}),e.jsx("button",{type:"button",className:"icon-button","aria-label":"刷新 Git 状态","aria-busy":j,onClick:z,disabled:j,children:e.jsx(g,{name:"refresh",size:16})})]}),E?e.jsx("p",{className:"resource-notice",role:"status",children:E.text}):null,R?e.jsx("p",{className:"resource-error",role:"alert",children:R}):null,e.jsxs(J,{panelId:"git",navigatorWidthPx:_,onNavigatorWidthCommit:P,contentLabel:"Git Diff",navigatorLabel:"Git 变更",handleLabel:"调整 Git 变更列表宽度",contentClassName:"git-diff",navigatorClassName:"git-changes",children:[e.jsxs(e.Fragment,{children:[a.clean?e.jsxs("div",{className:"resource-empty compact",children:[e.jsx(g,{name:"check"}),e.jsx("strong",{children:"工作区干净"})]}):V.map(t=>t.items.length?e.jsxs("div",{className:"git-group",children:[e.jsxs("h3",{children:[t.label," ",e.jsx("span",{children:t.items.length})]}),t.items.map(s=>e.jsxs("button",{type:"button",className:k?.fileId===s.fileId?"selected":"",onClick:()=>{A(s)},children:[e.jsx("span",{className:`git-status-code ${t.tone}`,children:s.indexStatus.trim()||s.worktreeStatus.trim()||"?"}),e.jsx("span",{title:s.path,children:s.path})]},`${t.label}:${s.fileId}`))]},t.label):null),a.nextCursor?e.jsx("button",{type:"button",className:"text-button resource-load-more",onClick:()=>{W()},disabled:j,children:"加载更多变更"}):null,e.jsxs("div",{className:"git-history",children:[e.jsx("h3",{children:"提交历史"}),p?.items.map(t=>e.jsxs("article",{children:[e.jsx("code",{children:t.shortId}),e.jsx("strong",{children:t.subject}),e.jsxs("span",{children:[t.authorName," · ",new Date(t.authoredAt).toLocaleDateString("zh-CN")]})]},t.id)),p?.nextCursor?e.jsx("button",{type:"button",className:"text-button resource-load-more",onClick:()=>{H()},disabled:j,children:"加载更多提交"}):null]})]}),e.jsx(e.Fragment,{children:v?e.jsx(K,{page:v,loading:j,onLoadMore:v.nextCursor&&k?()=>{A(k,v.nextCursor??void 0)}:void 0,onSendToComposer:o}):e.jsxs("div",{className:"resource-empty",children:[e.jsx(g,{name:"code",size:16}),e.jsx("strong",{children:"选择变更查看 Diff"})]})})]})]})}function O({message:c,onRetry:m}){return e.jsxs("div",{className:"resource-empty",role:"alert",children:[e.jsx(g,{name:"warning"}),e.jsx("strong",{children:"Git 状态读取失败"}),e.jsx("p",{children:c}),e.jsx("button",{type:"button",className:"secondary-button",onClick:m,children:"重试"})]})}function w(c){return c instanceof Error?c.message:"Git 请求失败。"}function D(c){return c instanceof F&&c.code==="git_revision_conflict"}function M(){return new F("仓库版本已变化。",409,"git_revision_conflict")}function C(c,m){const u=new Map(c.map(o=>[o.fileId,o]));for(const o of m)u.set(o.fileId,o);return[...u.values()]}function Q(c,m){const u=new Map(c.map(o=>[o.id,o]));for(const o of m)u.set(o.id,o);return[...u.values()]}export{Y as GitPanel};
@@ -1 +0,0 @@
1
- import{r as a,j as e,I as d,W as A}from"./index-C2M48tcK.js";import{u as H,R as W}from"./useAutoNotice-BeSf9Dfq.js";import{D as _}from"./DiffViewer-C0A42Lma.js";function B({workspaceId:t,refreshEpoch:g,actions:C,onSendToComposer:D,navigatorWidthPx:E,onNavigatorWidthCommit:F}){const[s,I]=a.useState(null),[h,x]=a.useState(null),[m,j]=a.useState(null),[N,v]=a.useState(!1),[p,f]=a.useState(""),{notice:R,showNotice:L,clearNotice:S}=H(),r=a.useRef(0),o=a.useRef(0),b=async(n=r.current,u)=>{if(n===r.current){v(!0),f("");try{const c=await C.review();if(n!==r.current)return;I(c);const l=u?c.changedFiles.find(i=>i.fileId===u)??null:null;x(l),j(null),l&&w(l,void 0,n)}catch(c){if(n!==r.current)return;f(z(c))}finally{n===r.current&&v(!1)}}},$=()=>{const n=r.current+1;r.current=n,o.current+=1,S(),b(n,h?.fileId)};a.useEffect(()=>{const n=r.current+1;r.current=n,o.current+=1,I(null),x(null),j(null),f(""),S(),t&&b(n)},[g,t]);const w=async(n,u,c=r.current,l=o.current+1)=>{if(c===r.current){o.current=l,u||(x(n),j(null)),v(!0),f("");try{const i=await C.gitDiff(n.fileId,u);if(c!==r.current||l!==o.current||i.fileId!==n.fileId)return;x(n),j(y=>u&&y&&y.fileId===i.fileId?{...i,lines:[...y.lines,...i.lines]}:i)}catch(i){if(c!==r.current||l!==o.current)return;if(M(i)){L("仓库已变化,已重新建立审阅快照。"),await b(c,n.fileId);return}f(z(i))}finally{c===r.current&&l===o.current&&v(!1)}}};return!s&&!p?e.jsx("p",{className:"resource-loading",children:"正在建立审阅快照…"}):s?e.jsxs("div",{className:"work-resource-panel review-panel",children:[e.jsxs("div",{className:"review-summary",children:[e.jsxs("div",{children:[e.jsx("span",{className:`review-score ${s.clean?"clean":"changed"}`,children:s.clean?e.jsx(d,{name:"check",size:16}):e.jsx(d,{name:"edit",size:16})}),e.jsxs("div",{children:[e.jsx("strong",{children:k(s).headline}),e.jsx("span",{children:k(s).counters})]})]}),e.jsx("button",{type:"button",className:"icon-button","aria-label":"刷新审阅快照","aria-busy":N,disabled:N,onClick:$,children:e.jsx(d,{name:"refresh",size:16})})]}),s.truncated?e.jsxs("p",{className:"resource-notice",role:"status",children:["当前显示 ",s.changedFiles.length," / ",s.totalChangedFiles," ","个变更文件;分类计数仅覆盖当前显示范围。"]}):null,R?e.jsx("p",{className:"resource-notice",role:"status",children:R.text}):null,p?e.jsx("p",{className:"resource-error",role:"alert",children:p}):null,e.jsxs(W,{panelId:"review",navigatorWidthPx:E,onNavigatorWidthCommit:F,contentLabel:"审阅 Diff",navigatorLabel:"待审阅文件",handleLabel:"调整待审阅文件列表宽度",contentClassName:"review-diff",navigatorClassName:"review-files",children:[e.jsx(e.Fragment,{children:s.changedFiles.map(n=>e.jsxs("button",{type:"button",className:h?.fileId===n.fileId?"selected":"",onClick:()=>{w(n)},children:[e.jsx(d,{name:"code",size:14}),e.jsx("span",{title:n.path,children:n.path}),e.jsx("small",{children:`${n.indexStatus}${n.worktreeStatus}`.trim()||"?"})]},n.fileId))}),e.jsx(e.Fragment,{children:m?e.jsx(_,{page:m,loading:N,onLoadMore:m.nextCursor&&h?()=>{w(h,m.nextCursor??void 0)}:void 0,onSendToComposer:D}):e.jsxs("div",{className:"resource-empty",children:[e.jsx(d,{name:"edit",size:16}),e.jsx("strong",{children:"选择文件开始审阅"}),e.jsx("p",{title:"你可以把某个 Hunk 作为草稿送回对话,提交前仍由你确认。",children:"选中 Hunk 可送回对话。"})]})})]})]}):e.jsxs("div",{className:"resource-empty",role:"alert",children:[e.jsx(d,{name:"warning"}),e.jsx("strong",{children:"无法读取审阅快照"}),e.jsx("p",{children:p}),e.jsx("button",{type:"button",className:"secondary-button",onClick:$,children:"重试"})]})}function k(t){const g=[`${t.stagedCount} 已暂存`,`${t.unstagedCount} 未暂存`,`${t.untrackedCount} 未跟踪`,`${t.conflictCount} 冲突`].join(" · ");return Object.freeze({headline:t.clean?"没有待审阅变更":`${t.totalChangedFiles} 个变更文件`,counters:`${t.truncated?"当前显示 · ":""}${g}`})}function z(t){return t instanceof Error?t.message:"审阅请求失败。"}function M(t){return t instanceof A&&t.code==="git_revision_conflict"}export{B as ReviewPanel,k as reviewSummary};