@yuandc/aica 0.1.83 → 0.1.84

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.
@@ -1,2 +1,2 @@
1
- import{execFileSync as l}from"node:child_process";import d from"node:fs";import c from"node:path";import h from"node:crypto";import{mediaMimeForExtension as m}from"./media-file-types.js";const g=50*1024*1024,x=["path","file","filePath","file_path","filename","targetPath","target_path","move_path"];function E(t){if(!b(t))return null;const e=v(t);if(!e)return null;const n=new Map;for(const r of e)n.set(r.path,{status:r.status,objectHash:r.status.includes("D")?null:A(t,r.path)});return n}function R(t){const e=new Map;for(const n of t.evidencePaths)w(e,t.cwd,n,"unknown","acp_tool");return[...e.values()].filter(n=>n.relativePath&&!n.relativePath.startsWith(".git/")).sort((n,r)=>n.relativePath.localeCompare(r.relativePath))}function G(t){const e=new Set;return u(t,(n,r)=>{if(typeof n=="string"&&(S(r)&&p(e,n),r==="command"))for(const s of C(n))p(e,s)}),j(t,e),F(t,e),[...e]}function w(t,e,n,r,s){const a=P(e,n);if(!a)return;const i=t.get(a.relativePath),o=H(a.absolutePath),f={path:a.absolutePath,absolutePath:a.absolutePath,relativePath:a.relativePath,changeType:y(i?.changeType,r),source:i?.source==="acp_tool"||i?.source==="acp_diff"?i.source:s,exists:!!o?.isFile(),downloadable:!!o?.isFile(),...o?.isFile()?{size:o.size,mime:z(a.absolutePath),sha256:o.size<=g?_(a.absolutePath):void 0}:{}};t.set(a.relativePath,f)}function y(t,e){return!t||t==="unknown"?e:e==="unknown"||t===e?t:t==="created"&&e==="modified"?"created":e}function P(t,e){if(!e||e.includes("\0"))return null;const n=c.resolve(t),r=c.isAbsolute(e)?c.resolve(e):c.resolve(n,e),s=c.relative(n,r).replace(/\\/g,"/");return!s||s.startsWith("..")||c.isAbsolute(s)?null:{absolutePath:r,relativePath:s}}function b(t){try{return l("git",["-C",t,"rev-parse","--is-inside-work-tree"],{windowsHide:!0,encoding:"utf8",stdio:["ignore","pipe","ignore"]}),!0}catch{return!1}}function v(t){try{const n=l("git",["-C",t,"status","--porcelain=v1","-z","--untracked-files=all"],{windowsHide:!0,encoding:"buffer",maxBuffer:20971520}).toString("utf8").split("\0").filter(Boolean),r=[];for(let s=0;s<n.length;s+=1){const a=n[s],i=a.slice(0,2),o=a.slice(3);if(o)if(i.startsWith("R")||i.startsWith("C")){const f=n[s+1];f&&(r.push({status:i,path:f}),s+=1)}else r.push({status:i,path:o})}return r}catch{return null}}function A(t,e){try{const n=l("git",["-C",t,"hash-object","--",e],{windowsHide:!0,encoding:"utf8",stdio:["ignore","pipe","ignore"],maxBuffer:1048576}).trim();return/^[0-9a-f]{40,64}$/i.test(n)?n:null}catch{return null}}function u(t,e,n,r=0){if(!(r>8)&&(e(t,n),!(!t||typeof t!="object"))){if(Array.isArray(t)){for(const s of t)u(s,e,void 0,r+1);return}for(const[s,a]of Object.entries(t))u(a,e,s,r+1)}}function j(t,e){u(t,n=>{if(!n||typeof n!="object"||Array.isArray(n))return;const r=n;r.type==="diff"&&p(e,r.path)})}function F(t,e){u(t,(n,r)=>{if(!(r!=="changes"||!n||typeof n!="object"||Array.isArray(n)))for(const s of Object.keys(n))p(e,s)})}function S(t){return t?x.includes(t):!1}function p(t,e){if(typeof e!="string")return;const n=k(e);!n||n.length>500||n.includes(`
2
- `)||n==="."||n===".."||t.add(n)}function k(t){let e=t.trim();e=e.replace(/\s+\+\d+\s*\/\s*-\d+(?:\s+.*)?$/,""),e=e.replace(/\s+\(\s*\+\d+\s*[,/ ]\s*-\d+\s*\)(?:\s+.*)?$/,""),e=e.replace(/\s+(?:source|event|workspace|session|last)=\S+.*$/,"");const n=e.split(/\s+/)[0]||"";return n&&/\.[A-Za-z][A-Za-z0-9+-]{0,12}$/.test(n)&&(e=n),e.replace(/^["']|["']$/g,"").trim()}function C(t){const e=[],n=/(?:^|\s)(?:\d?>|>>)\s*(?:"([^"]+)"|'([^']+)'|([^\s;&|<>]+))/g;let r;for(;r=n.exec(t);){const a=r[1]||r[2]||r[3];a&&e.push(a)}const s=/(?:^|\s)touch\s+(?:"([^"]+)"|'([^']+)'|([^\s;&|<>]+))/g;for(;r=s.exec(t);){const a=r[1]||r[2]||r[3];a&&!a.startsWith("-")&&e.push(a)}return e}function H(t){try{return d.statSync(t)}catch{return null}}function _(t){try{return h.createHash("sha256").update(d.readFileSync(t)).digest("hex")}catch{return}}function z(t){const e=m(c.extname(t));if(e)return e;switch(c.extname(t).toLowerCase()){case".doc":return"application/msword";case".xls":return"application/vnd.ms-excel";case".xlsm":return"application/vnd.ms-excel.sheet.macroEnabled.12";case".ppt":return"application/vnd.ms-powerpoint";case".pptx":return"application/vnd.openxmlformats-officedocument.presentationml.presentation";case".odt":return"application/vnd.oasis.opendocument.text";case".ods":return"application/vnd.oasis.opendocument.spreadsheet";case".odp":return"application/vnd.oasis.opendocument.presentation";case".rtf":return"application/rtf";case".svg":return"image/svg+xml";case".bmp":return"image/bmp";case".tif":case".tiff":return"image/tiff";case".avif":return"image/avif";case".pdf":return"application/pdf";case".md":case".markdown":return"text/markdown; charset=utf-8";case".txt":case".log":return"text/plain; charset=utf-8";case".json":return"application/json; charset=utf-8";case".csv":return"text/csv; charset=utf-8";case".png":return"image/png";case".jpg":case".jpeg":return"image/jpeg";case".gif":return"image/gif";case".webp":return"image/webp";case".zip":return"application/zip";case".docx":return"application/vnd.openxmlformats-officedocument.wordprocessingml.document";case".xlsx":return"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";default:return"application/octet-stream"}}export{E as captureGitSnapshot,R as collectAffectedFiles,G as extractAffectedFilePathsFromAcpRaw,z as mimeForPath};
1
+ import{execFileSync as l}from"node:child_process";import d from"node:fs";import o from"node:path";import h from"node:crypto";import{mediaMimeForExtension as m}from"./media-file-types.js";import{packageMimeForExtension as g}from"./package-file-types.js";const x=50*1024*1024,w=["path","file","filePath","file_path","filename","targetPath","target_path","move_path"];function G(t){if(!P(t))return null;const e=A(t);if(!e)return null;const n=new Map;for(const r of e)n.set(r.path,{status:r.status,objectHash:r.status.includes("D")?null:k(t,r.path)});return n}function K(t){const e=new Map;for(const n of t.evidencePaths)y(e,t.cwd,n,"unknown","acp_tool");return[...e.values()].filter(n=>n.relativePath&&!n.relativePath.startsWith(".git/")).sort((n,r)=>n.relativePath.localeCompare(r.relativePath))}function O(t){const e=new Set;return u(t,(n,r)=>{if(typeof n=="string"&&(S(r)&&p(e,n),r==="command"))for(const s of H(n))p(e,s)}),F(t,e),j(t,e),[...e]}function y(t,e,n,r,s){const a=v(e,n);if(!a)return;const i=t.get(a.relativePath),c=_(a.absolutePath),f={path:a.absolutePath,absolutePath:a.absolutePath,relativePath:a.relativePath,changeType:b(i?.changeType,r),source:i?.source==="acp_tool"||i?.source==="acp_diff"?i.source:s,exists:!!c?.isFile(),downloadable:!!c?.isFile(),...c?.isFile()?{size:c.size,mime:M(a.absolutePath),sha256:c.size<=x?B(a.absolutePath):void 0}:{}};t.set(a.relativePath,f)}function b(t,e){return!t||t==="unknown"?e:e==="unknown"||t===e?t:t==="created"&&e==="modified"?"created":e}function v(t,e){if(!e||e.includes("\0"))return null;const n=o.resolve(t),r=o.isAbsolute(e)?o.resolve(e):o.resolve(n,e),s=o.relative(n,r).replace(/\\/g,"/");return!s||s.startsWith("..")||o.isAbsolute(s)?null:{absolutePath:r,relativePath:s}}function P(t){try{return l("git",["-C",t,"rev-parse","--is-inside-work-tree"],{windowsHide:!0,encoding:"utf8",stdio:["ignore","pipe","ignore"]}),!0}catch{return!1}}function A(t){try{const n=l("git",["-C",t,"status","--porcelain=v1","-z","--untracked-files=all"],{windowsHide:!0,encoding:"buffer",maxBuffer:20971520}).toString("utf8").split("\0").filter(Boolean),r=[];for(let s=0;s<n.length;s+=1){const a=n[s],i=a.slice(0,2),c=a.slice(3);if(c)if(i.startsWith("R")||i.startsWith("C")){const f=n[s+1];f&&(r.push({status:i,path:f}),s+=1)}else r.push({status:i,path:c})}return r}catch{return null}}function k(t,e){try{const n=l("git",["-C",t,"hash-object","--",e],{windowsHide:!0,encoding:"utf8",stdio:["ignore","pipe","ignore"],maxBuffer:1048576}).trim();return/^[0-9a-f]{40,64}$/i.test(n)?n:null}catch{return null}}function u(t,e,n,r=0){if(!(r>8)&&(e(t,n),!(!t||typeof t!="object"))){if(Array.isArray(t)){for(const s of t)u(s,e,void 0,r+1);return}for(const[s,a]of Object.entries(t))u(a,e,s,r+1)}}function F(t,e){u(t,n=>{if(!n||typeof n!="object"||Array.isArray(n))return;const r=n;r.type==="diff"&&p(e,r.path)})}function j(t,e){u(t,(n,r)=>{if(!(r!=="changes"||!n||typeof n!="object"||Array.isArray(n)))for(const s of Object.keys(n))p(e,s)})}function S(t){return t?w.includes(t):!1}function p(t,e){if(typeof e!="string")return;const n=C(e);!n||n.length>500||n.includes(`
2
+ `)||n==="."||n===".."||t.add(n)}function C(t){let e=t.trim();e=e.replace(/\s+\+\d+\s*\/\s*-\d+(?:\s+.*)?$/,""),e=e.replace(/\s+\(\s*\+\d+\s*[,/ ]\s*-\d+\s*\)(?:\s+.*)?$/,""),e=e.replace(/\s+(?:source|event|workspace|session|last)=\S+.*$/,"");const n=e.split(/\s+/)[0]||"";return n&&/\.[A-Za-z][A-Za-z0-9+-]{0,12}$/.test(n)&&(e=n),e.replace(/^["']|["']$/g,"").trim()}function H(t){const e=[],n=/(?:^|\s)(?:\d?>|>>)\s*(?:"([^"]+)"|'([^']+)'|([^\s;&|<>]+))/g;let r;for(;r=n.exec(t);){const a=r[1]||r[2]||r[3];a&&e.push(a)}const s=/(?:^|\s)touch\s+(?:"([^"]+)"|'([^']+)'|([^\s;&|<>]+))/g;for(;r=s.exec(t);){const a=r[1]||r[2]||r[3];a&&!a.startsWith("-")&&e.push(a)}return e}function _(t){try{return d.statSync(t)}catch{return null}}function B(t){try{return h.createHash("sha256").update(d.readFileSync(t)).digest("hex")}catch{return}}function M(t){const e=g(o.extname(t));if(e)return e;const n=m(o.extname(t));if(n)return n;switch(o.extname(t).toLowerCase()){case".doc":return"application/msword";case".xls":return"application/vnd.ms-excel";case".xlsm":return"application/vnd.ms-excel.sheet.macroEnabled.12";case".ppt":return"application/vnd.ms-powerpoint";case".pptx":return"application/vnd.openxmlformats-officedocument.presentationml.presentation";case".odt":return"application/vnd.oasis.opendocument.text";case".ods":return"application/vnd.oasis.opendocument.spreadsheet";case".odp":return"application/vnd.oasis.opendocument.presentation";case".rtf":return"application/rtf";case".svg":return"image/svg+xml";case".bmp":return"image/bmp";case".tif":case".tiff":return"image/tiff";case".avif":return"image/avif";case".pdf":return"application/pdf";case".md":case".markdown":return"text/markdown; charset=utf-8";case".txt":case".log":return"text/plain; charset=utf-8";case".json":return"application/json; charset=utf-8";case".csv":return"text/csv; charset=utf-8";case".png":return"image/png";case".jpg":case".jpeg":return"image/jpeg";case".gif":return"image/gif";case".webp":return"image/webp";case".docx":return"application/vnd.openxmlformats-officedocument.wordprocessingml.document";case".xlsx":return"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";default:return"application/octet-stream"}}export{G as captureGitSnapshot,K as collectAffectedFiles,O as extractAffectedFilePathsFromAcpRaw,M as mimeForPath};
@@ -1 +1 @@
1
- import l from"node:fs";import n from"node:path";import{mimeForPath as S}from"../affected-files.js";import{MEDIA_FILE_EXTENSIONS as _}from"../media-file-types.js";const N=new Set([".pdf",".doc",".docx",".odt",".rtf",".xls",".xlsx",".xlsm",".ods",".csv",".ppt",".pptx",".odp",".png",".jpg",".jpeg",".gif",".webp",".bmp",".tif",".tiff",".svg",".avif",..._]),T=new Set([".git","node_modules",".venv","venv","__pycache__"]),A=[["target","classes"],["target","test-classes"],[".next","cache"],[".angular","cache"],[".gradle","caches"]],x=[["build","resources","main"],["build","resources","test"],["build","intermediates","merged_res"],["build","intermediates","packaged_res"],["build","intermediates","merged_assets"]],D=[".aca/attachments",".aica/attachments",".aca/artifacts",".aica/artifacts",".aca/logs",".aica/logs",".aca/server-data",".aica/server-data"],I=8192,b=1e4,w=new Map;function g(c,e){const t=n.basename(c);return!f(c,e)&&!t.startsWith("~$")&&N.has(n.extname(t).toLowerCase())}function f(c,e){const t=c.split(n.sep).join("/"),i=t.split("/"),s=(r,a)=>a.some(o=>o.every((d,p)=>i[r+p]===d));return i.some((r,a)=>T.has(r)||s(a,A)||r==="build"&&e?.has(i.slice(0,a+1).join("/"))&&s(a,x))||D.some(r=>t===r||t.startsWith(`${r}/`))}class j{root;warn;watches=new Map;gradleBuildPaths=new Set;subscribers=new Set;pending=new Set;timer;closed=!1;warned=!1;draining=!1;constructor(e,t){this.root=e,this.warn=t}degraded(e){this.warned||this.closed||(this.warned=!0,this.warn(`产物监听部分不可用,将以结束扫描补偿(仍可能遗漏瞬时变化):${String(e)}`))}watchDirectory(e){if(!(this.closed||this.watches.has(e))){if(this.watches.size>=I){this.degraded("目录监听数量达到上限");return}try{const t=l.watch(e,{persistent:!1},(i,s)=>{if(this.closed||!s)return;const r=n.join(e,s.toString()),a=n.relative(this.root,r);if(!f(a,this.gradleBuildPaths)){if(g(a,this.gradleBuildPaths))for(const o of this.subscribers)o.size<b?o.add(a):this.degraded("文件事件候选数量达到上限");i==="rename"&&this.schedule(r)}});t.on("error",i=>{t.close(),this.watches.get(e)===t&&this.watches.delete(e),this.degraded(i)}),this.watches.set(e,t)}catch(t){this.degraded(t)}}}schedule(e){if(this.pending.size>=b){this.degraded("目录事件积压");return}this.pending.add(e),!(this.timer||this.draining)&&(this.timer=setTimeout(()=>{this.timer=void 0,this.drain()},50),this.timer.unref())}async drain(){this.draining=!0;try{for(;!this.closed&&this.pending.size>0;){const e=this.pending.values().next().value;if(this.pending.delete(e),this.watches.has(e))for(const[t,i]of this.watches)(t===e||t.startsWith(`${e}${n.sep}`))&&(i.close(),this.watches.delete(t));await this.walk(e,new Map)}}finally{this.draining=!1}}async snapshot(){const e=new Map;return await this.walk(this.root,e),e}async updateGradleContext(e,t){if(!t||n.basename(e)!=="build")return;const i=await Promise.all(["build.gradle","build.gradle.kts"].map(async r=>{try{return(await l.promises.lstat(n.join(n.dirname(e),r))).isFile()}catch(a){const o=a.code;return o!=="ENOENT"&&o!=="ENOTDIR"&&this.degraded(a),!1}})),s=t.split(n.sep).join("/");i.some(Boolean)?this.gradleBuildPaths.add(s):this.gradleBuildPaths.delete(s)}async walk(e,t){if(this.closed)return;const i=n.relative(this.root,e);if(!f(i,this.gradleBuildPaths))try{const s=await l.promises.lstat(e);if(s.isSymbolicLink())return;if(s.isDirectory()){await this.updateGradleContext(e,i),this.watchDirectory(e);const r=await l.promises.opendir(e);for await(const a of r){if(this.closed)break;if(a.isSymbolicLink())continue;const o=n.join(e,a.name),d=n.relative(this.root,o);f(d,this.gradleBuildPaths)||(a.isDirectory()||g(d,this.gradleBuildPaths))&&await this.walk(o,t)}}else if(s.isFile()&&g(i,this.gradleBuildPaths)){const r=await l.promises.realpath(e),a=n.relative(this.root,r);if(a.startsWith(`..${n.sep}`)||n.isAbsolute(a)||f(a,this.gradleBuildPaths))return;t.set(i,{size:s.size,signature:`${s.dev}:${s.ino}:${s.size}:${s.mtimeMs}:${s.ctimeMs}`})}}catch(s){const r=s.code;r!=="ENOENT"&&r!=="ENOTDIR"&&this.degraded(s)}}close(){this.closed=!0,this.timer&&clearTimeout(this.timer);for(const e of this.watches.values())e.close();this.watches.clear(),this.pending.clear()}}async function P(c,e){const t=await l.promises.realpath(c);let i=w.get(t);i||(i=new j(t,e),w.set(t,i));const s=i,r=new Set;s.subscribers.add(r);let a=!1;const o=()=>{a||(a=!0,s.subscribers.delete(r),s.subscribers.size===0&&(s.close(),w.delete(t)))};let d;try{d=await s.snapshot(),r.clear()}catch(m){throw o(),m}let p;return{dispose:o,finish(){return p??=(async()=>{if(a)return[];try{const m=await s.snapshot(),v=[];for(const[h,u]of m){const y=d.get(h);if(!r.has(h)&&y?.signature===u.signature)continue;const E=n.join(t,h);v.push({path:E,absolutePath:E,relativePath:h.split(n.sep).join("/"),changeType:y?"modified":"created",source:"job_time_window",exists:!0,downloadable:!0,size:u.size,mime:S(h)})}return v.sort((h,u)=>h.relativePath.localeCompare(u.relativePath))}finally{o()}})()}}}function $(c,e){const t=new Map(c.map(i=>[i.relativePath,i]));for(const i of e)t.set(i.relativePath,i);return[...t.values()]}export{g as isArtifactPath,f as isIgnoredArtifactPath,$ as mergeArtifactFiles,P as startJobArtifactMonitor};
1
+ import l from"node:fs";import n from"node:path";import{mimeForPath as _}from"../affected-files.js";import{MEDIA_FILE_EXTENSIONS as b}from"../media-file-types.js";import{PACKAGE_FILE_EXTENSIONS as N}from"../package-file-types.js";const A=new Set([".pdf",".doc",".docx",".odt",".rtf",".xls",".xlsx",".xlsm",".ods",".csv",".ppt",".pptx",".odp",".png",".jpg",".jpeg",".gif",".webp",".bmp",".tif",".tiff",".svg",".avif",...b,...N]),T=new Set([".git","node_modules",".venv","venv","__pycache__"]),I=[["target","classes"],["target","test-classes"],[".next","cache"],[".angular","cache"],[".gradle","caches"]],x=[["build","resources","main"],["build","resources","test"],["build","intermediates","merged_res"],["build","intermediates","packaged_res"],["build","intermediates","merged_assets"]],D=[".aca/attachments",".aica/attachments",".aca/artifacts",".aica/artifacts",".aca/logs",".aica/logs",".aca/server-data",".aica/server-data"],j=8192,S=1e4,w=new Map;function g(c,t){const e=n.basename(c);return!f(c,t)&&!e.startsWith("~$")&&A.has(n.extname(e).toLowerCase())}function f(c,t){const e=c.split(n.sep).join("/"),i=e.split("/"),s=(r,a)=>a.some(o=>o.every((d,p)=>i[r+p]===d));return i.some((r,a)=>T.has(r)||s(a,I)||r==="build"&&t?.has(i.slice(0,a+1).join("/"))&&s(a,x))||D.some(r=>e===r||e.startsWith(`${r}/`))}class z{root;warn;watches=new Map;gradleBuildPaths=new Set;subscribers=new Set;pending=new Set;timer;closed=!1;warned=!1;draining=!1;constructor(t,e){this.root=t,this.warn=e}degraded(t){this.warned||this.closed||(this.warned=!0,this.warn(`产物监听部分不可用,将以结束扫描补偿(仍可能遗漏瞬时变化):${String(t)}`))}watchDirectory(t){if(!(this.closed||this.watches.has(t))){if(this.watches.size>=j){this.degraded("目录监听数量达到上限");return}try{const e=l.watch(t,{persistent:!1},(i,s)=>{if(this.closed||!s)return;const r=n.join(t,s.toString()),a=n.relative(this.root,r);if(!f(a,this.gradleBuildPaths)){if(g(a,this.gradleBuildPaths))for(const o of this.subscribers)o.size<S?o.add(a):this.degraded("文件事件候选数量达到上限");i==="rename"&&this.schedule(r)}});e.on("error",i=>{e.close(),this.watches.get(t)===e&&this.watches.delete(t),this.degraded(i)}),this.watches.set(t,e)}catch(e){this.degraded(e)}}}schedule(t){if(this.pending.size>=S){this.degraded("目录事件积压");return}this.pending.add(t),!(this.timer||this.draining)&&(this.timer=setTimeout(()=>{this.timer=void 0,this.drain()},50),this.timer.unref())}async drain(){this.draining=!0;try{for(;!this.closed&&this.pending.size>0;){const t=this.pending.values().next().value;if(this.pending.delete(t),this.watches.has(t))for(const[e,i]of this.watches)(e===t||e.startsWith(`${t}${n.sep}`))&&(i.close(),this.watches.delete(e));await this.walk(t,new Map)}}finally{this.draining=!1}}async snapshot(){const t=new Map;return await this.walk(this.root,t),t}async updateGradleContext(t,e){if(!e||n.basename(t)!=="build")return;const i=await Promise.all(["build.gradle","build.gradle.kts"].map(async r=>{try{return(await l.promises.lstat(n.join(n.dirname(t),r))).isFile()}catch(a){const o=a.code;return o!=="ENOENT"&&o!=="ENOTDIR"&&this.degraded(a),!1}})),s=e.split(n.sep).join("/");i.some(Boolean)?this.gradleBuildPaths.add(s):this.gradleBuildPaths.delete(s)}async walk(t,e){if(this.closed)return;const i=n.relative(this.root,t);if(!f(i,this.gradleBuildPaths))try{const s=await l.promises.lstat(t);if(s.isSymbolicLink())return;if(s.isDirectory()){await this.updateGradleContext(t,i),this.watchDirectory(t);const r=await l.promises.opendir(t);for await(const a of r){if(this.closed)break;if(a.isSymbolicLink())continue;const o=n.join(t,a.name),d=n.relative(this.root,o);f(d,this.gradleBuildPaths)||(a.isDirectory()||g(d,this.gradleBuildPaths))&&await this.walk(o,e)}}else if(s.isFile()&&g(i,this.gradleBuildPaths)){const r=await l.promises.realpath(t),a=n.relative(this.root,r);if(a.startsWith(`..${n.sep}`)||n.isAbsolute(a)||f(a,this.gradleBuildPaths))return;e.set(i,{size:s.size,signature:`${s.dev}:${s.ino}:${s.size}:${s.mtimeMs}:${s.ctimeMs}`})}}catch(s){const r=s.code;r!=="ENOENT"&&r!=="ENOTDIR"&&this.degraded(s)}}close(){this.closed=!0,this.timer&&clearTimeout(this.timer);for(const t of this.watches.values())t.close();this.watches.clear(),this.pending.clear()}}async function $(c,t){const e=await l.promises.realpath(c);let i=w.get(e);i||(i=new z(e,t),w.set(e,i));const s=i,r=new Set;s.subscribers.add(r);let a=!1;const o=()=>{a||(a=!0,s.subscribers.delete(r),s.subscribers.size===0&&(s.close(),w.delete(e)))};let d;try{d=await s.snapshot(),r.clear()}catch(m){throw o(),m}let p;return{dispose:o,finish(){return p??=(async()=>{if(a)return[];try{const m=await s.snapshot(),E=[];for(const[h,u]of m){const v=d.get(h);if(!r.has(h)&&v?.signature===u.signature)continue;const y=n.join(e,h);E.push({path:y,absolutePath:y,relativePath:h.split(n.sep).join("/"),changeType:v?"modified":"created",source:"job_time_window",exists:!0,downloadable:!0,size:u.size,mime:_(h)})}return E.sort((h,u)=>h.relativePath.localeCompare(u.relativePath))}finally{o()}})()}}}function C(c,t){const e=new Map(c.map(i=>[i.relativePath,i]));for(const i of t)e.set(i.relativePath,i);return[...e.values()]}export{g as isArtifactPath,f as isIgnoredArtifactPath,C as mergeArtifactFiles,$ as startJobArtifactMonitor};
@@ -1 +1 @@
1
- import{managementActivity as f}from"./management/activity.js";import{managedClaim as x}from"./management/claims.js";import c from"node:fs";import y from"node:os";import o from"node:path";import{Readable as l}from"node:stream";import{acaServerRequest as u,acaServerStreamRequest as d}from"./aca-server-client.js";import{loadAcaConfig as b}from"./aca-config.js";import{expandWorkerRuntimePath as S}from"./worker-runtime-paths.js";import{startLongPollWorker as I}from"./long-poll-worker.js";import{openImageFile as j}from"./image-file-access.js";import{mediaMimeForExtension as v}from"./media-file-types.js";const g=25e3,E=g+1e4;function Q(e){return I({run:async()=>{const t=b();if(!t.token)throw new Error("Worker 尚未配置认证令牌");const a=await x("file",()=>u("GET",`/api/client/file-requests/claim?machineId=${encodeURIComponent(t.machineId)}&waitMs=${g}`,void 0,{timeoutMs:E}));if(!a.item)return;const n=f.track("file");try{await $(a.item,t,e)}catch(i){const r=i instanceof Error?i.message:String(i);e.warn(`file request failed request=${a.item.requestId}: ${r}`);try{await R(a.item.requestId,r)}catch(s){f.uncertain.add("file-finalize"),e.warn(`file request fail callback failed request=${a.item.requestId}: ${s instanceof Error?s.message:String(s)}`)}}finally{n()}},onError:(t,a)=>e.warn(`file transfer worker failed, retry in ${a}ms: ${t instanceof Error?t.message:String(t)}`)})}async function R(e,t){await u("POST",`/api/client/file-requests/${encodeURIComponent(e)}/fail`,{message:t})}async function $(e,t,a){const n=t.projects.find(m=>m.projectId===e.projectId),i=h(e.projectRoot||n?.rootPath||"");if(e.purpose==="image-file"){const m=j(i,e.path,e.maxBytes);try{a.info(`streaming image request=${e.requestId} path=${m.path}`),await d("POST",`/api/client/file-requests/${encodeURIComponent(e.requestId)}/stream`,l.toWeb(m.stream),{"content-type":"application/octet-stream","x-aca-file-name":encodeURIComponent(o.basename(m.path)),"x-aca-file-size":String(m.sizeBytes),"x-aca-file-mime":m.mimeType})}finally{m.stream.destroy()}return}if(!i)throw new Error(`file request ${e.requestId} project root is unknown`);const r=e.purpose==="temp-image"?"temp-image":e.purpose==="project-preview"?"project-preview":"project-file",s=r==="temp-image"?k(e.path):F(i,e.path),p=c.statSync(s);if(!p.isFile())throw new Error(`file request ${e.requestId} target is not a file`);if(p.size>e.maxBytes)throw new Error(`file request ${e.requestId} target is too large (${p.size} bytes)`);const w=r==="temp-image"?T(s):q(s);a.info(`streaming file request=${e.requestId} path=${s}`),await d("POST",`/api/client/file-requests/${encodeURIComponent(e.requestId)}/stream`,l.toWeb(c.createReadStream(s)),{"content-type":"application/octet-stream","x-aca-file-name":encodeURIComponent(o.basename(s)),"x-aca-file-size":String(p.size),"x-aca-file-mime":w})}function F(e,t){const a=c.realpathSync(h(e)),n=o.isAbsolute(t)?t:o.join(a,t),i=c.realpathSync(n),r=o.relative(a,i);if(r===""||r.startsWith("..")||o.isAbsolute(r))throw new Error("requested file is outside project root");return i}function k(e){const t=L(e);if(!o.isAbsolute(t))throw new Error("temporary image path must be absolute");const a=c.lstatSync(t);if(a.isSymbolicLink())throw new Error("temporary image cannot be a symbolic link");if(!a.isFile())throw new Error("temporary image target is not a regular file");const n=c.realpathSync(y.tmpdir()),i=c.realpathSync(t),r=o.relative(n,i);if(r===""||r.startsWith("..")||o.isAbsolute(r))throw new Error("temporary image is outside the system temp directory");return i}function T(e){const t=o.extname(e).toLowerCase(),a=Buffer.alloc(16),n=c.openSync(e,"r");let i=0;try{i=c.readSync(n,a,0,a.length,0)}finally{c.closeSync(n)}const r=a.subarray(0,i);if(t===".png"&&r.length>=8&&r.subarray(0,8).equals(Buffer.from([137,80,78,71,13,10,26,10])))return"image/png";if([".jpg",".jpeg"].includes(t)&&r.length>=3&&r[0]===255&&r[1]===216&&r[2]===255)return"image/jpeg";if(t===".gif"&&r.length>=6&&["GIF87a","GIF89a"].includes(r.subarray(0,6).toString("ascii")))return"image/gif";if(t===".webp"&&r.length>=12&&r.subarray(0,4).toString("ascii")==="RIFF"&&r.subarray(8,12).toString("ascii")==="WEBP")return"image/webp";throw new Error("temporary file is not a supported raster image")}function L(e){const t=String(e||"").trim();if(!t.startsWith("file://"))return t;try{return decodeURIComponent(new URL(t).pathname)}catch{throw new Error("temporary image path is invalid")}}function h(e){return S(e)}function q(e){const t=v(o.extname(e));if(t)return t;switch(o.extname(e).toLowerCase()){case".pdf":return"application/pdf";case".md":case".markdown":return"text/markdown; charset=utf-8";case".txt":case".log":return"text/plain; charset=utf-8";case".html":case".htm":return"text/html; charset=utf-8";case".css":return"text/css; charset=utf-8";case".js":case".mjs":return"text/javascript; charset=utf-8";case".json":case".map":return"application/json; charset=utf-8";case".xml":return"application/xml; charset=utf-8";case".svg":return"image/svg+xml; charset=utf-8";case".png":return"image/png";case".jpg":case".jpeg":return"image/jpeg";case".gif":return"image/gif";case".webp":return"image/webp";case".avif":return"image/avif";case".ico":return"image/x-icon";case".ppm":return"image/x-portable-pixmap";case".bmp":return"image/bmp";case".woff":return"font/woff";case".woff2":return"font/woff2";case".ttf":return"font/ttf";case".otf":return"font/otf";case".eot":return"application/vnd.ms-fontobject";case".webmanifest":return"application/manifest+json; charset=utf-8";case".zip":return"application/zip";case".docx":return"application/vnd.openxmlformats-officedocument.wordprocessingml.document";case".xlsx":return"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";default:return"application/octet-stream"}}export{T as detectSafeTempImageMime,q as mimeForPath,F as resolveProjectFile,k as resolveTempImageFile,Q as startFileTransferWorkerLoop};
1
+ import{managementActivity as f}from"./management/activity.js";import{managedClaim as x}from"./management/claims.js";import c from"node:fs";import y from"node:os";import i from"node:path";import{Readable as l}from"node:stream";import{acaServerRequest as u,acaServerStreamRequest as g}from"./aca-server-client.js";import{loadAcaConfig as b}from"./aca-config.js";import{expandWorkerRuntimePath as S}from"./worker-runtime-paths.js";import{startLongPollWorker as I}from"./long-poll-worker.js";import{openImageFile as j}from"./image-file-access.js";import{mediaMimeForExtension as E}from"./media-file-types.js";import{packageMimeForExtension as v}from"./package-file-types.js";const d=25e3,R=d+1e4;function H(e){return I({run:async()=>{const t=b();if(!t.token)throw new Error("Worker 尚未配置认证令牌");const a=await x("file",()=>u("GET",`/api/client/file-requests/claim?machineId=${encodeURIComponent(t.machineId)}&waitMs=${d}`,void 0,{timeoutMs:R}));if(!a.item)return;const n=f.track("file");try{await F(a.item,t,e)}catch(o){const r=o instanceof Error?o.message:String(o);e.warn(`file request failed request=${a.item.requestId}: ${r}`);try{await $(a.item.requestId,r)}catch(s){f.uncertain.add("file-finalize"),e.warn(`file request fail callback failed request=${a.item.requestId}: ${s instanceof Error?s.message:String(s)}`)}}finally{n()}},onError:(t,a)=>e.warn(`file transfer worker failed, retry in ${a}ms: ${t instanceof Error?t.message:String(t)}`)})}async function $(e,t){await u("POST",`/api/client/file-requests/${encodeURIComponent(e)}/fail`,{message:t})}async function F(e,t,a){const n=t.projects.find(m=>m.projectId===e.projectId),o=h(e.projectRoot||n?.rootPath||"");if(e.purpose==="image-file"){const m=j(o,e.path,e.maxBytes);try{a.info(`streaming image request=${e.requestId} path=${m.path}`),await g("POST",`/api/client/file-requests/${encodeURIComponent(e.requestId)}/stream`,l.toWeb(m.stream),{"content-type":"application/octet-stream","x-aca-file-name":encodeURIComponent(i.basename(m.path)),"x-aca-file-size":String(m.sizeBytes),"x-aca-file-mime":m.mimeType})}finally{m.stream.destroy()}return}if(!o)throw new Error(`file request ${e.requestId} project root is unknown`);const r=e.purpose==="temp-image"?"temp-image":e.purpose==="project-preview"?"project-preview":"project-file",s=r==="temp-image"?T(e.path):k(o,e.path),p=c.statSync(s);if(!p.isFile())throw new Error(`file request ${e.requestId} target is not a file`);if(p.size>e.maxBytes)throw new Error(`file request ${e.requestId} target is too large (${p.size} bytes)`);const w=r==="temp-image"?L(s):C(s);a.info(`streaming file request=${e.requestId} path=${s}`),await g("POST",`/api/client/file-requests/${encodeURIComponent(e.requestId)}/stream`,l.toWeb(c.createReadStream(s)),{"content-type":"application/octet-stream","x-aca-file-name":encodeURIComponent(i.basename(s)),"x-aca-file-size":String(p.size),"x-aca-file-mime":w})}function k(e,t){const a=c.realpathSync(h(e)),n=i.isAbsolute(t)?t:i.join(a,t),o=c.realpathSync(n),r=i.relative(a,o);if(r===""||r.startsWith("..")||i.isAbsolute(r))throw new Error("requested file is outside project root");return o}function T(e){const t=q(e);if(!i.isAbsolute(t))throw new Error("temporary image path must be absolute");const a=c.lstatSync(t);if(a.isSymbolicLink())throw new Error("temporary image cannot be a symbolic link");if(!a.isFile())throw new Error("temporary image target is not a regular file");const n=c.realpathSync(y.tmpdir()),o=c.realpathSync(t),r=i.relative(n,o);if(r===""||r.startsWith("..")||i.isAbsolute(r))throw new Error("temporary image is outside the system temp directory");return o}function L(e){const t=i.extname(e).toLowerCase(),a=Buffer.alloc(16),n=c.openSync(e,"r");let o=0;try{o=c.readSync(n,a,0,a.length,0)}finally{c.closeSync(n)}const r=a.subarray(0,o);if(t===".png"&&r.length>=8&&r.subarray(0,8).equals(Buffer.from([137,80,78,71,13,10,26,10])))return"image/png";if([".jpg",".jpeg"].includes(t)&&r.length>=3&&r[0]===255&&r[1]===216&&r[2]===255)return"image/jpeg";if(t===".gif"&&r.length>=6&&["GIF87a","GIF89a"].includes(r.subarray(0,6).toString("ascii")))return"image/gif";if(t===".webp"&&r.length>=12&&r.subarray(0,4).toString("ascii")==="RIFF"&&r.subarray(8,12).toString("ascii")==="WEBP")return"image/webp";throw new Error("temporary file is not a supported raster image")}function q(e){const t=String(e||"").trim();if(!t.startsWith("file://"))return t;try{return decodeURIComponent(new URL(t).pathname)}catch{throw new Error("temporary image path is invalid")}}function h(e){return S(e)}function C(e){const t=v(i.extname(e));if(t)return t;const a=E(i.extname(e));if(a)return a;switch(i.extname(e).toLowerCase()){case".pdf":return"application/pdf";case".md":case".markdown":return"text/markdown; charset=utf-8";case".txt":case".log":return"text/plain; charset=utf-8";case".html":case".htm":return"text/html; charset=utf-8";case".css":return"text/css; charset=utf-8";case".js":case".mjs":return"text/javascript; charset=utf-8";case".json":case".map":return"application/json; charset=utf-8";case".xml":return"application/xml; charset=utf-8";case".svg":return"image/svg+xml; charset=utf-8";case".png":return"image/png";case".jpg":case".jpeg":return"image/jpeg";case".gif":return"image/gif";case".webp":return"image/webp";case".avif":return"image/avif";case".ico":return"image/x-icon";case".ppm":return"image/x-portable-pixmap";case".bmp":return"image/bmp";case".woff":return"font/woff";case".woff2":return"font/woff2";case".ttf":return"font/ttf";case".otf":return"font/otf";case".eot":return"application/vnd.ms-fontobject";case".webmanifest":return"application/manifest+json; charset=utf-8";case".docx":return"application/vnd.openxmlformats-officedocument.wordprocessingml.document";case".xlsx":return"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";default:return"application/octet-stream"}}export{L as detectSafeTempImageMime,C as mimeForPath,k as resolveProjectFile,T as resolveTempImageFile,H as startFileTransferWorkerLoop};
@@ -0,0 +1 @@
1
+ const a={".apk":"application/vnd.android.package-archive",".aab":"application/octet-stream",".exe":"application/vnd.microsoft.portable-executable",".msi":"application/x-msi",".msix":"application/msix",".dmg":"application/x-apple-diskimage",".pkg":"application/octet-stream",".deb":"application/vnd.debian.binary-package",".rpm":"application/x-rpm",".appimage":"application/vnd.appimage",".zip":"application/zip",".tar":"application/x-tar",".gz":"application/gzip",".tgz":"application/gzip",".bz2":"application/x-bzip2",".tbz2":"application/x-bzip2",".xz":"application/x-xz",".txz":"application/x-xz",".zst":"application/zstd",".tzst":"application/zstd",".rar":"application/vnd.rar",".7z":"application/x-7z-compressed"},i=Object.keys(a);function t(p){return a[p.toLowerCase()]}export{i as PACKAGE_FILE_EXTENSIONS,t as packageMimeForExtension};
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- const o="0.1.83";export{o as AICA_VERSION};
1
+ const o="0.1.84";export{o as AICA_VERSION};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuandc/aica",
3
- "version": "0.1.83",
3
+ "version": "0.1.84",
4
4
  "description": "AICA remote Agent worker",
5
5
  "author": "yuandc",
6
6
  "type": "module",