@orion-agents/orion-code 0.3.14 → 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 (49) hide show
  1. package/CHANGELOG.md +286 -0
  2. package/README.md +6 -8
  3. package/README.zh-CN.md +4 -5
  4. package/dist/runtime/release-receipts.d.ts +15 -3
  5. package/dist/runtime/release-receipts.js +27 -1
  6. package/dist/services/session-storage.d.ts +9 -0
  7. package/dist/services/session-storage.js +27 -1
  8. package/dist/web/git-compare-service.d.ts +45 -0
  9. package/dist/web/git-compare-service.js +160 -0
  10. package/dist/web/git-diff-document.d.ts +83 -0
  11. package/dist/web/git-diff-document.js +214 -0
  12. package/dist/web/git-file-source.d.ts +25 -0
  13. package/dist/web/git-file-source.js +21 -0
  14. package/dist/web/git-history-service.d.ts +151 -0
  15. package/dist/web/git-history-service.js +610 -0
  16. package/dist/web/git-index-transaction.d.ts +45 -0
  17. package/dist/web/git-index-transaction.js +174 -0
  18. package/dist/web/git-patch-builder.d.ts +30 -0
  19. package/dist/web/git-patch-builder.js +134 -0
  20. package/dist/web/git-read-model-service.d.ts +338 -18
  21. package/dist/web/git-read-model-service.js +1029 -110
  22. package/dist/web/git-version-service.d.ts +71 -0
  23. package/dist/web/git-version-service.js +255 -0
  24. package/dist/web/native-directory-picker.d.ts +63 -0
  25. package/dist/web/native-directory-picker.js +169 -0
  26. package/dist/web/protocol.d.ts +51 -2
  27. package/dist/web/server.js +384 -8
  28. package/dist/web/workbench-controller.d.ts +126 -10
  29. package/dist/web/workbench-controller.js +383 -15
  30. package/dist/web/workspace-open-telemetry.d.ts +55 -0
  31. package/dist/web/workspace-open-telemetry.js +73 -0
  32. package/dist/web-client/assets/FilesPanel-BARQCmne.js +1 -0
  33. package/dist/web-client/assets/GitPanel-DjB9eSiJ.js +4 -0
  34. package/dist/web-client/assets/ReviewPanel-YhEGlp-G.js +5 -0
  35. package/dist/web-client/assets/{TerminalPanel-IkCttxgw.js → TerminalPanel-DnWh3Vp2.js} +1 -1
  36. package/dist/web-client/assets/index--hnGXXjj.css +1 -0
  37. package/dist/web-client/assets/index-Drja0_BT.js +20 -0
  38. package/dist/web-client/assets/useAutoNotice-DfQi4G1X.js +1 -0
  39. package/dist/web-client/favicon.svg +9 -0
  40. package/dist/web-client/index.html +3 -2
  41. package/npm-shrinkwrap.json +2 -2
  42. package/package.json +1 -1
  43. package/dist/web-client/assets/DiffViewer-BrHqudpK.js +0 -5
  44. package/dist/web-client/assets/FilesPanel-BcFY6L1a.js +0 -1
  45. package/dist/web-client/assets/GitPanel-B6E5IEXm.js +0 -1
  46. package/dist/web-client/assets/ResourceSplitLayout-fPYE9JKJ.js +0 -1
  47. package/dist/web-client/assets/ReviewPanel-5ecTVmhT.js +0 -1
  48. package/dist/web-client/assets/index-DgVNIqmE.js +0 -20
  49. package/dist/web-client/assets/index-R6E589Fc.css +0 -1
@@ -0,0 +1 @@
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};
@@ -0,0 +1,9 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" shape-rendering="crispEdges">
2
+ <rect width="20" height="20" fill="#15191b" />
3
+ <rect x="2" y="9" width="4" height="8" fill="#7ea4ed" />
4
+ <rect x="2" y="17" width="4" height="1" fill="#5ab8ad" />
5
+ <rect x="8" y="4" width="4" height="13" fill="#7ea4ed" />
6
+ <rect x="8" y="17" width="4" height="1" fill="#5ab8ad" />
7
+ <rect x="14" y="7" width="4" height="10" fill="#7ea4ed" />
8
+ <rect x="14" y="17" width="4" height="1" fill="#5ab8ad" />
9
+ </svg>
@@ -6,9 +6,10 @@
6
6
  <meta name="color-scheme" content="dark light" />
7
7
  <meta name="theme-color" content="#15191b" />
8
8
  <meta name="description" content="Orion Code local Web Workbench" />
9
+ <link rel="icon" href="/favicon.svg" type="image/svg+xml" />
9
10
  <title>Orion Code</title>
10
- <script type="module" crossorigin src="/assets/index-DgVNIqmE.js"></script>
11
- <link rel="stylesheet" crossorigin href="/assets/index-R6E589Fc.css">
11
+ <script type="module" crossorigin src="/assets/index-Drja0_BT.js"></script>
12
+ <link rel="stylesheet" crossorigin href="/assets/index--hnGXXjj.css">
12
13
  </head>
13
14
  <body>
14
15
  <div id="root"></div>
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@orion-agents/orion-code",
3
- "version": "0.3.14",
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.12",
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.14",
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-DgVNIqmE.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 l,j as e,I as R,s as fe,W as xe}from"./index-DgVNIqmE.js";import{R as me}from"./ResourceSplitLayout-fPYE9JKJ.js";function Ne({workspaceId:s,refreshEpoch:a,actions:o,navigatorWidthPx:r,onNavigatorWidthCommit:d}){const[u,h]=l.useState({}),[j,x]=l.useState(new Set(["workspace-root"])),[n,m]=l.useState(null),[b,M]=l.useState(""),[B,G]=l.useState(null),[U,z]=l.useState(!1),[X,K]=l.useState(""),[Y,N]=l.useState(""),[T,ie]=l.useState(""),[H,P]=l.useState({}),[J,_]=l.useState(""),[O,F]=l.useState("view"),[$,k]=l.useState(""),[D,V]=l.useState(!1),[le,S]=l.useState(!1),[ae,oe]=l.useState(""),f=l.useRef(0),w=l.useRef(0),Z=l.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 o.listFiles(t,C??void 0);if(g!==f.current)return;h(p=>({...p,[t]:{items:i?je(p[t]?.items??[],c.items):c.items,nextCursor:c.nextCursor,revision:c.revision,loading:!1}}))}catch(c){if(g!==f.current)return;if(i&&W(c)){N("目录已变化,已重新载入第一页。"),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)}}))}}},A=async(t=f.current)=>{try{const i=await o.gitStatus();if(t!==f.current)return;P(ve(i)),_(i.nextCursor?"Git 装饰仅显示首批 200 个变更;在 Git 面板继续分页查看。":"")}catch(i){if(t!==f.current)return;P({}),_(`Git 状态装饰不可用:${L(i)}`)}},q=l.useRef(s);l.useEffect(()=>{const t=f.current+1;f.current=t,w.current+=1;const i=q.current===s?Z.current:null;q.current=s,h({}),x(new Set(["workspace-root"])),m(i),M(""),G(null),z(!1),K(""),N(""),P({}),_(""),s&&(E("workspace-root",!1,t),A(t),i&&y(i,!1,!1,t))},[a,s]);const y=async(t,i=!1,g=!1,v=f.current,C=w.current+1)=>{if(v===f.current&&!(!t.readable||t.sensitive||Q(t))){w.current=C,m(t),K(""),i||(M(""),G(null),z(!1),F("view"),k(""),S(!1)),g||N("");try{const c=await o.readFileContent(t.id,i?B??void 0:void 0);if(v!==f.current||C!==w.current)return;z(c.binary),M(p=>i?`${p}${c.content??""}`:c.content??""),G(c.nextCursor),oe(c.revision),g&&N("文件已变化,已从第一页重新载入。")}catch(c){if(v!==f.current||C!==w.current)return;if(i&&W(c)){await y(t,!1,!0,v,C);return}K(L(c))}}},I=be({selected:n,binary:U,hasMorePages:B!==null}),ce=()=>{k(b),S(!1),F("edit")},ee=()=>{$!==b&&!window.confirm("放弃未保存的修改?")||(F("view"),k(""),S(!1))},ue=async()=>{if(!(!n||D)){V(!0),S(!1);try{await o.writeFileContent(n.id,$,ae),F("view"),k(""),await y(n,!1,!0,f.current,w.current+1),N("已保存文件。"),A()}catch(t){W(t)?S(!0):N(L(t))}finally{V(!1)}}},te=t=>{const i=new Set(j);i.has(t)?i.delete(t):(i.add(t),u[t]||E(t)),x(i)};l.useEffect(()=>{Z.current=n},[n]);const de=l.useMemo(()=>Object.values(u).flatMap(t=>t.items),[u]),se=T.trim()?de.filter(t=>t.name.toLocaleLowerCase().includes(T.toLocaleLowerCase())):null;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:14}),e.jsx("input",{type:"search",value:T,onChange:t=>ie(t.target.value),placeholder:"搜索已加载文件"})]}),e.jsx("button",{type:"button",className:"icon-button","aria-label":"刷新文件树",onClick:()=>{E("workspace-root"),A()},children:e.jsx(R,{name:"refresh",size:15})})]}),e.jsxs(me,{panelId:"files",navigatorWidthPx:r,onNavigatorWidthCommit:d,contentLabel:"文件预览",navigatorLabel:"工作区文件",handleLabel:"调整文件目录宽度",contentClassName:"file-preview",navigatorClassName:"file-tree",children:[e.jsxs(e.Fragment,{children:[J?e.jsx("p",{className:"resource-hint",role:"status",children:J}):null,se?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"resource-hint",children:"搜索仅覆盖已加载的目录和文件。"}),e.jsx("ul",{role:"list",className:"file-node-list search-results",children:se.map(t=>e.jsx(ne,{node:t,depth:0,expanded:!1,selected:n?.id===t.id,gitLabels:H[t.displayPath]??[],onToggle:te,onSelect:i=>{y(i)}},t.id))})]}):e.jsx(re,{parentId:"workspace-root",depth:0,directories:u,expanded:j,selectedId:n?.id,gitDecorations:H,onToggle:te,onSelect:t=>{y(t)},onLoadMore:t=>{E(t,!0)}})]}),e.jsxs(e.Fragment,{children:[Y?e.jsx("p",{className:"resource-notice",role:"status",children:Y}):null,n?e.jsxs(e.Fragment,{children:[e.jsxs("header",{children:[e.jsx("strong",{children:n.name}),e.jsx("span",{children:ye(n.sizeBytes??0)})]}),X?e.jsx("p",{className:"resource-error",role:"alert",children:X}):U?e.jsxs("div",{className:"resource-empty",children:[e.jsx(R,{name:"code"}),e.jsx("strong",{children:"二进制文件"}),e.jsx("p",{children:"出于安全和性能考虑,只显示元数据。"})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"file-preview-actions",children:O==="view"?e.jsx("button",{type:"button",className:"text-button",disabled:!I,title:I?void 0:"仅支持编辑 512 KB 内的 UTF-8 文本文件",onClick:ce,children:"编辑"}):e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"primary-button",disabled:D||$===b,onClick:()=>{ue()},children:D?"保存中…":"保存"}),e.jsx("button",{type:"button",className:"text-button",disabled:D,onClick:ee,children:"取消"})]})}),le?e.jsxs("p",{className:"resource-error",role:"alert",children:["文件已在别处变更,保存被拒绝。",e.jsx("button",{type:"button",className:"text-button",onClick:()=>{y(n,!1,!0)},children:"重新加载"})]}):null,O==="edit"?e.jsx("textarea",{className:"file-editor",value:$,spellCheck:!1,"aria-label":`编辑文件 ${n.name}`,onChange:t=>k(t.target.value),onKeyDown:t=>{t.key==="Escape"&&(t.preventDefault(),ee())}}):e.jsx("pre",{tabIndex:0,className:"file-code-view","aria-label":`文件内容 ${n.name}`,children:fe(b)})]}),B&&O==="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"}),e.jsx("strong",{children:"选择文件预览"}),e.jsx("p",{children:"敏感文件、工作区外链接和二进制正文不会返回浏览器。"})]})]})]})]})}function re({parentId:s,depth:a,directories:o,expanded:r,selectedId:d,gitDecorations:u,onToggle:h,onSelect:j,onLoadMore:x}){const n=o[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(m=>{const b=r.has(m.id);return e.jsxs("li",{children:[e.jsx(ne,{node:m,depth:a,expanded:b,selected:d===m.id,gitLabels:u[m.displayPath]??[],onToggle:h,onSelect:j}),Q(m)&&b?e.jsx(re,{parentId:m.id,depth:a+1,directories:o,expanded:r,selectedId:d,gitDecorations:u,onToggle:h,onSelect:j,onLoadMore:x}):null]},m.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:()=>x(s),children:"加载更多"})}):null]}):e.jsx("p",{className:"resource-loading",children:"正在读取…"})}function ne({node:s,depth:a,expanded:o,selected:r,gitLabels:d,onToggle:u,onSelect:h}){const j=s.sensitive||!s.readable,x=Q(s);return e.jsxs("button",{type:"button",className:`file-node ${r?"selected":""} ${j?"blocked":""}`,style:{paddingInlineStart:`${8+a*15}px`},"aria-expanded":x?o:void 0,"aria-label":`${he(s)} ${s.name}${j?",不可读取":""}${d.length?`,Git ${d.join("、")}`:""}`,onClick:()=>x?u(s.id):h(s),disabled:j,children:[e.jsx(R,{name:x?"workspace":"code",size:14}),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 he(s){return s.kind==="directory"?"目录":s.kind==="symlink"?s.targetKind==="directory"?"符号链接目录":"符号链接":"文件"}function Q(s){return s.kind==="directory"||s.kind==="symlink"&&s.targetKind==="directory"}function je(s,a){const o=new Map(s.map(r=>[r.id,r]));for(const r of a)o.set(r.id,r);return[...o.values()]}function ve(s){if(!s.isRepository)return{};const a=new Map,o=(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 x=1;x<j.length;x+=1){const n=j.slice(0,x).join("/"),m=a.get(n)??new Set;m.add("含变更"),a.set(n,m)}};return s.conflicted.forEach(r=>o(r.path,"冲突")),s.staged.forEach(r=>o(r.path,"已暂存")),s.unstaged.forEach(r=>o(r.path,"未暂存")),s.untracked.forEach(r=>o(r.path,"未跟踪")),Object.fromEntries([...a].map(([r,d])=>[r,Object.freeze([...d])]))}const pe=512*1024;function be(s){const{selected:a,binary:o,hasMorePages:r}=s;return!a||o||a.sensitive||!a.readable||r?!1:(a.sizeBytes??0)<=pe}function ye(s){return s<1024?`${s} B`:s<1048576?`${(s/1024).toFixed(1)} KB`:`${(s/1048576).toFixed(1)} MB`}function W(s){return s instanceof xe&&s.code==="file_revision_conflict"}function L(s){return s instanceof Error?s.message:"文件请求失败。"}export{pe as FILE_EDIT_MAX_BYTES,Ne as FilesPanel,be as canEditFileContent};
@@ -1 +0,0 @@
1
- import{r as d,j as e,I as g,W as F}from"./index-DgVNIqmE.js";import{R as V}from"./ResourceSplitLayout-fPYE9JKJ.js";import{D as B}from"./DiffViewer-BrHqudpK.js";function U({workspaceId:c,refreshEpoch:m,actions:u,onSendToComposer:o,navigatorWidthPx:_,onNavigatorWidthCommit:z}){const[a,I]=d.useState(null),[p,G]=d.useState(null),[k,y]=d.useState(null),[v,N]=d.useState(null),[R,h]=d.useState(!1),[C,f]=d.useState(""),[E,j]=d.useState(""),n=d.useRef(0),x=d.useRef(0),b=async(t=n.current)=>{if(t===n.current){h(!0),f("");try{const[s,l]=await Promise.all([u.gitStatus(),u.gitLog()]);if(t!==n.current)return;I(s),G(l),y(null),N(null)}catch(s){if(t!==n.current)return;f(S(s))}finally{t===n.current&&h(!1)}}},$=()=>{const t=n.current+1;n.current=t,x.current+=1,j(""),b(t)};d.useEffect(()=>{const t=n.current+1;n.current=t,x.current+=1,I(null),G(null),y(null),N(null),f(""),j(""),c&&b(t)},[m,c]);const M=async(t,s,l=n.current,r=x.current+1)=>{if(l===n.current){x.current=r,s||(y(t),N(null)),h(!0),f("");try{const i=await u.gitDiff(t.fileId,s);if(l!==n.current||r!==x.current||i.fileId!==t.fileId)return;y(t),N(L=>s&&L&&L.fileId===i.fileId?{...i,lines:[...L.lines,...i.lines]}:i)}catch(i){if(l!==n.current||r!==x.current)return;if(D(i)){j("仓库已变化,已重新载入 Git 状态。"),await b(l);return}f(S(i))}finally{l===n.current&&r===x.current&&h(!1)}}},P=async()=>{const t=a?.nextCursor;if(!t||!a)return;const s=n.current,l=a.repositoryRevision;h(!0),f("");try{const r=await u.gitStatus(t);if(s!==n.current)return;if(r.repositoryRevision!==l)throw A();I(i=>!i||i.repositoryRevision!==l?i:{...r,conflicted:w(i.conflicted,r.conflicted),staged:w(i.staged,r.staged),unstaged:w(i.unstaged,r.unstaged),untracked:w(i.untracked,r.untracked)})}catch(r){if(s!==n.current)return;if(D(r)){j("仓库已变化,已重新载入 Git 状态。"),await b(s);return}f(S(r))}finally{s===n.current&&h(!1)}},W=async()=>{const t=p?.nextCursor;if(!t||!p)return;const s=n.current,l=p.repositoryRevision;h(!0),f("");try{const r=await u.gitLog(t);if(s!==n.current)return;if(r.repositoryRevision!==l)throw A();G(i=>!i||i.repositoryRevision!==l?i:{...r,items:K(i.items,r.items)})}catch(r){if(s!==n.current)return;if(D(r)){j("提交历史已变化,已重新载入第一页。"),await b(s);return}f(S(r))}finally{s===n.current&&h(!1)}};if(C&&!a)return e.jsx(J,{message:C,onRetry:$});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"}),e.jsx("strong",{children:"当前项目不是 Git 仓库"}),e.jsx("p",{children:"文件和 Agent 仍可使用;Git 面板保持只读空状态。"})]});const H=[{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:15}),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 状态",onClick:$,disabled:R,children:e.jsx(g,{name:"refresh",size:15})})]}),E?e.jsx("p",{className:"resource-notice",role:"status",children:E}):null,C?e.jsx("p",{className:"resource-error",role:"alert",children:C}):null,e.jsxs(V,{panelId:"git",navigatorWidthPx:_,onNavigatorWidthCommit:z,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:"工作区干净"})]}):H.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:()=>{M(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:()=>{P()},disabled:R,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:()=>{W()},disabled:R,children:"加载更多提交"}):null]})]}),e.jsx(e.Fragment,{children:v?e.jsx(B,{page:v,loading:R,onLoadMore:v.nextCursor&&k?()=>{M(k,v.nextCursor??void 0)}:void 0,onSendToComposer:o}):e.jsxs("div",{className:"resource-empty",children:[e.jsx(g,{name:"code"}),e.jsx("strong",{children:"选择变更查看 Diff"}),e.jsx("p",{children:"Diff 来自受限 Git read model,不解析对话或工具输出。"})]})})]})]})}function J({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 S(c){return c instanceof Error?c.message:"Git 请求失败。"}function D(c){return c instanceof F&&c.code==="git_revision_conflict"}function A(){return new F("仓库版本已变化。",409,"git_revision_conflict")}function w(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 K(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{U as GitPanel};
@@ -1 +0,0 @@
1
- import{r as t,j as s,P as I,R as M,a as R,c as S,b as _}from"./index-DgVNIqmE.js";function O({panelId:r,navigatorWidthPx:m,onNavigatorWidthCommit:v,contentLabel:p,navigatorLabel:x,handleLabel:f,contentClassName:n="",navigatorClassName:a="",children:W}){const[N,b]=t.Children.toArray(W),o=t.useRef(null),[g,E]=t.useState(0),[$,c]=t.useState(null);t.useEffect(()=>{const e=o.current;if(!e)return;const u=new ResizeObserver(A=>{const h=A[0]?.contentRect.width;h&&E(h)});return u.observe(e),()=>u.disconnect()},[]);const i=_(g),l=Math.min(S($??m),i),j=e=>{c(null),v(Math.min(e,i))},w=`${r}-split-content`,d=`${r}-split-navigator`;return s.jsxs("div",{ref:o,className:"resource-split-layout",style:{"--resource-navigator-width":`${l}px`},children:[s.jsx("section",{id:w,className:`resource-split-content${n?` ${n}`:""}`,"aria-label":p,children:b}),s.jsx(I,{side:"right",className:"resource-split-handle",minWidth:R,maxWidth:Math.max(R,i),defaultWidth:M,label:f,width:l,controls:d,boundsRef:o,resizingScope:"resource-split",onPreview:c,onCommit:j}),s.jsx("section",{id:d,className:`resource-split-navigator${a?` ${a}`:""}`,"aria-label":x,children:N})]})}export{O as R};
@@ -1 +0,0 @@
1
- import{r as l,j as e,I as d,W as z}from"./index-DgVNIqmE.js";import{R as W}from"./ResourceSplitLayout-fPYE9JKJ.js";import{D as _}from"./DiffViewer-BrHqudpK.js";function P({workspaceId:r,refreshEpoch:g,actions:C,onSendToComposer:E,navigatorWidthPx:F,onNavigatorWidthCommit:L}){const[s,I]=l.useState(null),[h,m]=l.useState(null),[x,j]=l.useState(null),[S,v]=l.useState(!1),[p,f]=l.useState(""),[R,N]=l.useState(""),t=l.useRef(0),o=l.useRef(0),b=async(n=t.current,u)=>{if(n===t.current){v(!0),f("");try{const c=await C.review();if(n!==t.current)return;I(c);const a=u?c.changedFiles.find(i=>i.fileId===u)??null:null;m(a),j(null),a&&w(a,void 0,n)}catch(c){if(n!==t.current)return;f(D(c))}finally{n===t.current&&v(!1)}}},$=()=>{const n=t.current+1;t.current=n,o.current+=1,N(""),b(n,h?.fileId)};l.useEffect(()=>{const n=t.current+1;t.current=n,o.current+=1,I(null),m(null),j(null),f(""),N(""),r&&b(n)},[g,r]);const w=async(n,u,c=t.current,a=o.current+1)=>{if(c===t.current){o.current=a,u||(m(n),j(null)),v(!0),f("");try{const i=await C.gitDiff(n.fileId,u);if(c!==t.current||a!==o.current||i.fileId!==n.fileId)return;m(n),j(y=>u&&y&&y.fileId===i.fileId?{...i,lines:[...y.lines,...i.lines]}:i)}catch(i){if(c!==t.current||a!==o.current)return;if(A(i)){N("仓库已变化,已重新建立审阅快照。"),await b(c,n.fileId);return}f(D(i))}finally{c===t.current&&a===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"}):e.jsx(d,{name:"edit"})}),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":"刷新审阅快照",disabled:S,onClick:$,children:e.jsx(d,{name:"refresh",size:15})})]}),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}):null,p?e.jsx("p",{className:"resource-error",role:"alert",children:p}):null,e.jsxs(W,{panelId:"review",navigatorWidthPx:F,onNavigatorWidthCommit:L,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:x?e.jsx(_,{page:x,loading:S,onLoadMore:x.nextCursor&&h?()=>{w(h,x.nextCursor??void 0)}:void 0,onSendToComposer:E}):e.jsxs("div",{className:"resource-empty",children:[e.jsx(d,{name:"edit"}),e.jsx("strong",{children:"选择文件开始审阅"}),e.jsx("p",{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(r){const g=[`${r.stagedCount} 已暂存`,`${r.unstagedCount} 未暂存`,`${r.untrackedCount} 未跟踪`,`${r.conflictCount} 冲突`].join(" · ");return Object.freeze({headline:r.clean?"没有待审阅变更":`${r.totalChangedFiles} 个变更文件`,counters:`${r.truncated?"当前显示 · ":""}${g}`})}function D(r){return r instanceof Error?r.message:"审阅请求失败。"}function A(r){return r instanceof z&&r.code==="git_revision_conflict"}export{P as ReviewPanel,k as reviewSummary};