aitable-workflow-core 0.1.16 → 0.1.17-beta.1786415522134
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.
- package/dist/chunk-26KTSHZU.js +5 -0
- package/dist/{chunk-HMMYNMFU.js → chunk-IKWCZ5N6.js} +1 -1
- package/dist/chunk-R3AXT5CA.js +14 -0
- package/dist/chunk-XUSV3KOD.js +1 -0
- package/dist/index.d.ts +1651 -515
- package/dist/index.js +439 -578
- package/dist/migrate-JAARSV6T.js +1 -0
- package/dist/shared/question-form.d.ts +149 -0
- package/dist/shared/question-form.js +1 -0
- package/dist/shared/run-state.js +1 -1
- package/package.json +9 -2
- package/skills/aitable-workflow/SKILL.md +57 -0
- package/skills/aitable-workflow/reference/config-surface.md +113 -0
- package/skills/aitable-workflow/reference/event-handlers.md +187 -0
- package/skills/aitable-workflow/reference/event-source-filters.md +108 -0
- package/skills/aitable-workflow/reference/event-sources.md +169 -0
- package/skills/aitable-workflow/reference/field-types.md +80 -0
- package/skills/aitable-workflow/reference/generated/core-api.md +455 -0
- package/skills/aitable-workflow/reference/invariants.md +39 -0
- package/skills/aitable-workflow/reference/multi-workflow.md +140 -0
- package/skills/aitable-workflow/reference/profile-and-roles.md +194 -0
- package/skills/aitable-workflow/reference/recipe-contract.md +152 -0
- package/skills/aitable-workflow/reference/runtime-refs.md +155 -0
- package/skills/aitable-workflow/reference/views.md +104 -0
- package/skills/aitable-workflow/reference/workflow-yml.md +202 -0
- package/skills/aitable-workflow/reference/workspace-context.md +145 -0
- package/skills/aitable-workflow-design/SKILL.md +49 -0
- package/skills/aitable-workflow-design/patterns/brownfield-editing.md +113 -0
- package/skills/aitable-workflow-design/patterns/clarification-checklist.md +152 -0
- package/skills/aitable-workflow-design/patterns/config-in-aitable.md +217 -0
- package/skills/aitable-workflow-design/patterns/greenfield-checklist.md +106 -0
- package/skills/aitable-workflow-design/patterns/json-contract-and-repair.md +168 -0
- package/skills/aitable-workflow-design/patterns/output-and-report.md +46 -0
- package/skills/aitable-workflow-design/reference/question-form-protocol.md +57 -0
- package/wolai-crawler/lib/crawler.js +87 -3
- package/dist/chunk-7HYJUSV5.js +0 -14
- package/dist/chunk-EI7MMDWY.js +0 -1
- package/dist/migrate-Y47B7T7C.js +0 -1
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import{a as t}from"./chunk-XUSV3KOD.js";function c(r,e){return r===void 0?!1:Array.isArray(r)?r.includes(e):typeof r=="boolean"?String(r)===e:r===e}t(c,"answerContains");function p(r,e){return r.showIf?c(e[r.showIf.questionId],r.showIf.hasValue):!0}t(p,"isQuestionVisible");function i(r,e){return r.questions.filter(s=>p(s,e))}t(i,"visibleQuestions");function y(r,e){let s={};for(let n of i(r,e)){let o=e[n.id];o!==void 0&&(s[n.id]=o)}return s}t(y,"pruneHiddenAnswers");function F(r,e){let s=[`[form answers \u2014 ${r.id}]`];for(let n of i(r,e)){let o=m(n,e[n.id]);s.push(`- ${n.label}: ${o}`)}return s.join(`
|
|
2
|
+
`)}t(F,"serializeForm");function x(r){return r.map(({form:e,answers:s})=>F(e,s)).join(`
|
|
3
|
+
|
|
4
|
+
`)}t(x,"serializeForms");function I(r){let e=["\u7528\u6237\u5DF2\u786E\u8BA4\uFF1A"];for(let{form:s,answers:n}of r)for(let o of i(s,n))e.push(`- ${o.label}\uFF1A${m(o,n[o.id])}`);return e.join(`
|
|
5
|
+
`)}t(I,"summarizeForms");function m(r,e){if(e===void 0||A(e))return"(skipped)";switch(r.type){case"switch":return w(e)?"\u662F":"\u5426";case"radio":{let s=String(e),n=r.options?.find(o=>o.value===s);return n&&n.label!==n.value?`${n.label} [value: ${n.value}]`:s}case"checkbox":return(Array.isArray(e)?e:[String(e)]).map(o=>r.options?.find(l=>l.value===o)?.label??o).join(", ");default:return String(e)}}t(m,"formatAnswerDisplay");function A(r){return typeof r=="string"?r.trim()==="":Array.isArray(r)?r.length===0:!1}t(A,"isEmpty");function w(r){return typeof r=="boolean"?r:String(r)==="true"||r==="\u662F"}t(w,"toBool");function S(r,e){let s=[];for(let n of i(r,e)){let o=e[n.id];if(n.required&&d(o)){s.push({questionId:n.id,code:"required",message:`\u300C${n.label}\u300D\u4E3A\u5FC5\u586B\u9879`});continue}if(n.maxSelections!==void 0&&Array.isArray(o)&&o.length>n.maxSelections&&s.push({questionId:n.id,code:"max_selections",message:`\u300C${n.label}\u300D\u6700\u591A\u9009 ${n.maxSelections} \u9879\uFF0C\u5B9E\u9645 ${o.length} \u9879`}),n.allowCustom===!1&&n.options?.length&&!d(o)){let f=new Set(n.options.map(u=>u.value)),a=(Array.isArray(o)?o:[String(o)]).filter(u=>!f.has(u));a.length>0&&s.push({questionId:n.id,code:"not_in_options",message:`\u300C${n.label}\u300D\u53EA\u80FD\u4ECE\u7ED9\u5B9A\u9009\u9879\u4E2D\u9009\u62E9\uFF0C\u6536\u5230\uFF1A${a.join("\u3001")}`})}}return s}t(S,"validateFormAnswers");function d(r){return r===void 0?!0:typeof r=="string"?r.trim()==="":Array.isArray(r)?r.length===0:!1}t(d,"isBlankAnswer");export{p as a,i as b,y as c,F as d,x as e,I as f,m as g,S as h};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as u}from"./chunk-
|
|
1
|
+
import{a as u}from"./chunk-XUSV3KOD.js";function m(e,t,d={}){let r=l(d);if(t.type==="run.record.detected")return{records:I(e.records,{id:t.record.id,title:t.record.title||t.record.id,state:t.record.state,status:t.record.currentStep?"running":"todo",currentStepId:t.record.currentStep,doneStepIds:[],createdAt:r.now(),updatedAt:r.now()}),logs:o(e.logs,t.record.id,t.record.currentStep??"run","info",`\u53D1\u73B0\u5F85\u5904\u7406\u8BB0\u5F55\uFF1A${t.record.title||t.record.id}`,r)};if(t.type==="run.step.started"){let s=d.stepLevel?.(t.stepId,t)??"ai";return{records:p(e.records,t.itemId,n=>({...n,status:n.status==="done"?n.status:"running",currentStepId:n.status==="done"?n.currentStepId:t.stepId,updatedAt:r.now()})),logs:o(e.logs,t.itemId,t.stepId,s,`\u5F00\u59CB\u6267\u884C\u6B65\u9AA4\uFF1A${t.stepName}`,r)}}return t.type==="run.step.succeeded"?{records:p(e.records,t.itemId,s=>({...s,doneStepIds:c(s.doneStepIds,t.stepId),updatedAt:r.now()})),logs:a(o(e.logs,t.itemId,t.stepId,"ok",`\u6B65\u9AA4\u5B8C\u6210\uFF1A${t.stepName}`,r),t.itemId,t.stepId,"info",t.logs,r)}:t.type==="run.step.failed"?{records:p(e.records,t.itemId,s=>({...s,status:s.status==="done"?s.status:"blocked",currentStepId:s.status==="done"?s.currentStepId:t.stepId,updatedAt:r.now()})),logs:a(o(e.logs,t.itemId,t.stepId,"error",`\u6B65\u9AA4\u5931\u8D25\uFF1A${t.stepName} \xB7 ${t.error}`,r),t.itemId,t.stepId,"error",t.logs,r)}:t.type==="run.record.blocked"?{records:p(e.records,t.itemId,s=>({...s,status:s.status==="done"?s.status:t.reason.includes("\u4EBA\u5DE5")?"review":"blocked",currentStepId:s.status==="done"?s.currentStepId:t.stepId,doneStepIds:c(s.doneStepIds,t.stepId),updatedAt:r.now()})),logs:a(o(e.logs,t.itemId,t.stepId,"warn",`${t.stepName}\uFF1A${t.reason}`,r),t.itemId,t.stepId,"info",t.logs,r)}:t.type==="run.record.completed"?{records:p(e.records,t.itemId,s=>({...s,status:"done",currentStepId:null,updatedAt:r.now()})),logs:o(e.logs,t.itemId,"run","ok","\u6D41\u7A0B\u5B8C\u6210",r)}:e}u(m,"applyRunExecutionEvent");function l(e){return{now:e.now??Date.now,id:e.id??S,maxLogs:e.maxLogs??300}}u(l,"createContext");function I(e,t){return e.findIndex(r=>r.id===t.id)<0?[...e,t]:e.map(r=>r.id===t.id?{...r,...t,doneStepIds:r.doneStepIds,status:r.status==="done"?r.status:t.status,currentStepId:r.status==="done"?r.currentStepId:t.currentStepId,createdAt:r.createdAt}:r)}u(I,"upsertRunRecord");function p(e,t,d){return e.map(r=>r.id===t?d(r):r)}u(p,"updateRunRecord");function c(e,t){return e.includes(t)?e:[...e,t]}u(c,"addDoneStep");function o(e,t,d,r,s,n){return e.some(i=>i.itemId===t&&i.stepId===d&&i.level===r&&i.text===s)?e:[...e,{id:n.id(),ts:n.now(),itemId:t,stepId:d,level:r,text:s}].slice(-n.maxLogs)}u(o,"appendRunLog");function a(e,t,d,r,s,n){return s?.length?s.reduce((g,i)=>o(g,t,d,r,i,n),e):e}u(a,"appendRunLogs");function S(){return`run_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,7)}`}u(S,"createRunLogId");export{m as a};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import{a as l}from"./chunk-XUSV3KOD.js";import{access as se,cp as q,mkdir as G,mkdtemp as kt,readdir as vt,readFile as T,rm as Pt,writeFile as A}from"fs/promises";import w from"path";import Ct from"os";import B from"yaml";import{createHash as Ue}from"crypto";import{readFile as Q,writeFile as We}from"fs/promises";import K from"path";var fe=".migrate-meta.json";async function ee(e){try{let t=await Q(K.join(e,fe),"utf8");return JSON.parse(t)}catch{return null}}l(ee,"readMigrateMeta");async function J(e,t){let o=K.join(e,fe);await We(o,JSON.stringify(t,null,2)+`
|
|
2
|
+
`,"utf8")}l(J,"writeMigrateMeta");function te(e){return Ue("sha256").update(e,"utf8").digest("hex").slice(0,16)}l(te,"hashFileContent");async function L(e,t){let o={};for(let n of t)try{let c=await Q(K.join(e,n),"utf8");o[n]=te(c)}catch{}return o}l(L,"buildConfigSnapshot");async function U(e,t){let o={};for(let n of t)try{o[n]=await Q(K.join(e,n),"utf8")}catch{}return o}l(U,"buildConfigBaseContents");import{readdir as Ye}from"fs/promises";import ge from"path";var ue=new Set(["profile/profile.yml","aitable-workflow.config.yml","coding-agents.config.json"]),qe=new Set(["package.json",".npmrc","npmrc",".gitignore",".migrate-meta.json",".migrate-conflicts.yml"]),Ge=["wiki/","skills/","profile/prompts/","profile/escalation/","profile/fastpath/","profile/troubleshoot/"],Xe=new Set([".env",".env.example"]),ze=/^workspaces\/[^/]+\/AGENTS\.md$/,He=["lib/","workflows/"];function Ze(e){let t=e.replace(/\\/g,"/");if(ue.has(t))return"config";if(qe.has(t))return"managed";if(Xe.has(t)||ze.test(t))return"content";for(let o of Ge)if(t.startsWith(o))return"content";for(let o of He)if(t.startsWith(o))return"template";return"content"}l(Ze,"classifyFile");function W(){return[...ue]}l(W,"getConfigFilePaths");async function ne(e){let t=[];return await pe(e,e,t),t}l(ne,"classifyDirectory");var Qe=new Set(["node_modules",".migrate-backup",".git","traces"]);async function pe(e,t,o){let n=await Ye(t,{withFileTypes:!0});for(let c of n){let i=ge.join(t,c.name);if(c.isDirectory())Qe.has(c.name)||await pe(e,i,o);else if(c.isFile()){let r=ge.relative(e,i).replace(/\\/g,"/");o.push({relativePath:r,category:Ze(r)})}}}l(pe,"walkDir");function de(e,t,o){let n=[],c=[],i=[],r=[],a=[];return{merged:u(e,t,o,[]),conflicts:n,deprecated:c,newKeys:i,userPreserved:r,templateUpdated:a};function u(k,d,p,C){return I(k)&&I(d)&&I(p)?m(k,d,p,C):I(d)&&I(p)&&!I(k)?m(I(k)?k:{},d,p,C):F(k,d,p,C)}function m(k,d,p,C){let S=new Set;for(let f of Object.keys(k))S.add(f);for(let f of Object.keys(d))S.add(f);for(let f of Object.keys(p))S.add(f);let P={};for(let f of S){let x=f in k,b=f in d,D=f in p,N=[...C,f],$=N.join(".");!x&&!b&&D?(P[f]=p[f],i.push({path:N,pathString:$,theirsValue:p[f]})):!x&&b&&!D?P[f]=d[f]:!x&&b&&D?O(d[f],p[f])?P[f]=d[f]:I(d[f])&&I(p[f])?P[f]=m({},d[f],p[f],N):(P[f]=d[f],n.push({path:N,pathString:$,baseValue:void 0,oursValue:d[f],theirsValue:p[f]})):x&&!D?b&&!O(k[f],d[f])?(P[f]=d[f],n.push({path:N,pathString:$,baseValue:k[f],oursValue:d[f],theirsValue:void 0})):c.push({path:N,pathString:$,baseValue:k[f]}):x&&!b&&D?(P[f]=p[f],a.push($)):P[f]=u(k[f],d[f],p[f],N)}return P}function F(k,d,p,C){let S=O(k,d),P=O(k,p),f=O(d,p);return S&&P?d:S&&!P?(a.push(C.join(".")),p):!S&&P?(r.push(C.join(".")),d):(f||(n.push({path:C,pathString:C.join("."),baseValue:k,oursValue:d,theirsValue:p}),r.push(C.join("."))),d)}}l(de,"threeWayMerge");function I(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}l(I,"isPlainObject");function O(e,t){if(e===t)return!0;if(e==null||t==null)return e===t;if(typeof e!=typeof t)return!1;if(Array.isArray(e))return!Array.isArray(t)||e.length!==t.length?!1:e.every((o,n)=>O(o,t[n]));if(typeof e=="object"){let o=e,n=t,c=Object.keys(o),i=Object.keys(n);return c.length!==i.length?!1:c.every(r=>Object.prototype.hasOwnProperty.call(n,r)&&O(o[r],n[r]))}return!1}l(O,"deepEqual");import{cp as we,mkdir as et,readdir as oe,readFile as tt,rm as he,writeFile as nt}from"fs/promises";import j from"path";var ye=".migrate-backup",me=3,ke=new Set(["node_modules",".migrate-backup",".git"]);async function ve(e,t){let o=new Date,n=o.toISOString().replace(/[:.]/g,""),c=j.join(e,ye),i=j.join(c,n);await et(i,{recursive:!0});let r=await oe(e,{withFileTypes:!0});for(let g of r){if(ke.has(g.name))continue;let u=j.join(e,g.name),m=j.join(i,g.name);await we(u,m,{recursive:!0,force:!0,errorOnExist:!1})}let a=j.join(i,".backup-info.json");return await nt(a,JSON.stringify({timestamp:o.toISOString(),cliVersion:t},null,2)+`
|
|
3
|
+
`,"utf8"),{timestamp:o.toISOString(),dirName:n,fullPath:i,cliVersion:t}}l(ve,"createBackup");async function Y(e){let t=j.join(e,ye),o;try{o=(await oe(t,{withFileTypes:!0})).filter(i=>i.isDirectory()).map(i=>i.name)}catch{return[]}let n=[];for(let c of o){let i=j.join(t,c),r=j.join(i,".backup-info.json");try{let a=JSON.parse(await tt(r,"utf8"));n.push({timestamp:a.timestamp,dirName:c,fullPath:i,cliVersion:a.cliVersion})}catch{n.push({timestamp:c,dirName:c,fullPath:i,cliVersion:"unknown"})}}return n.sort((c,i)=>i.timestamp.localeCompare(c.timestamp)),n}l(Y,"listBackups");async function Pe(e,t){let o=await oe(e,{withFileTypes:!0});for(let n of o){if(ke.has(n.name))continue;let c=j.join(e,n.name);await he(c,{recursive:!0,force:!0})}await we(t.fullPath,e,{recursive:!0,force:!0,errorOnExist:!1,filter:l(n=>j.relative(t.fullPath,n)!==".backup-info.json","filter")})}l(Pe,"rollbackToBackup");async function Ce(e){let t=await Y(e);if(t.length<=me)return 0;let o=t.slice(me);for(let n of o)await he(n.fullPath,{recursive:!0,force:!0});return o.length}l(Ce,"pruneBackups");import{readFile as Se}from"fs/promises";var Me=/^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/;function ot(e){let t=new Map;for(let o of e.split(`
|
|
4
|
+
`)){let n=Me.exec(o.trim());n&&t.set(n[1],n[2])}return t}l(ot,"parseEnvKeys");async function Re(e,t){let o;try{o=await Se(t,"utf8")}catch{return[]}let n="";try{n=await Se(e,"utf8")}catch{}let c=ot(n),i=[],r=o.split(`
|
|
5
|
+
`);for(let a=0;a<r.length;a++){let g=Me.exec(r[a].trim());if(!g)continue;let u=g[1],m=g[2];if(c.has(u))continue;let F;a>0&&r[a-1].trim().startsWith("#")&&(F=r[a-1].trim().replace(/^#\s*/,"")),i.push({key:u,exampleValue:m,comment:F})}return i}l(Re,"detectNewEnvVars");var Ee=["dependencies","devDependencies","optionalDependencies","peerDependencies"],rt="aitable-workflow-",it=/^(file:|link:|workspace:|portal:)/;function Fe(e,t,o){let n=JSON.parse(JSON.stringify(t)),c=[],i=new Set;for(let r of Ee){let a=e[r];if(!a||typeof a!="object")continue;let g=n[r]??{};for(let[u,m]of Object.entries(a)){if(u.startsWith(rt)){typeof m=="string"&&it.test(m)&&(g[u]=m,i.add(u),c.push(u));continue}u in g||(g[u]=m,c.push(u))}n[r]=g}for(let r of Ee){let a=n[r];if(!(!a||typeof a!="object"))for(let[g,u]of Object.entries(a)){if(i.has(g))continue;let m=o[g];m&&(a[g]=m)}}return{merged:n,preservedDeps:c}}l(Fe,"mergePackageJson");import re from"yaml";var st="1to1",_e="group",at={files:["profile/profile.yml"],apply(e,t){let o=[],n=e.getIn(["workflows"]);if(!re.isMap(n))return o;for(let c of n.items){let i=String(c.key?.value??c.key),r=e.getIn(["workflows",i,"event_sources"]);if(re.isMap(r))for(let a of r.items){let g=String(a.key?.value??a.key),u=["workflows",i,"event_sources",g];if(e.getIn([...u,"type"])!=="dingtalk_stream"||!e.hasIn([...u,"drop_direct"]))continue;let m=e.getIn([...u,"drop_direct"]),F=e.hasIn([...u,"conversation_types"]),k=[...u,"drop_direct"].join(".");if(F){e.deleteIn([...u,"drop_direct"]),o.push({file:t,pathString:k,description:"\u5DF2\u5B58\u5728 conversation_types\uFF08\u8FD0\u884C\u671F\u4EE5\u5176\u4E3A\u51C6\uFF09\uFF0C\u79FB\u9664\u5E9F\u5F03\u7684 drop_direct"});continue}let d=m===!1?[_e,st]:[_e];e.deleteIn([...u,"drop_direct"]),e.setIn([...u,"conversation_types"],d),o.push({file:t,pathString:k,description:`drop_direct: ${JSON.stringify(m)} \u2192 conversation_types: ${JSON.stringify(d)}`})}}return o}},ct=[at];function be(e,t){let o=ct.filter(i=>i.files.includes(e));if(o.length===0)return{changes:[]};let n;try{n=re.parseDocument(t)}catch{return{changes:[]}}let c=[];for(let i of o)c.push(...i.apply(n,e));return c.length===0?{changes:[]}:{content:n.toString(),changes:c}}l(be,"applyConfigCodemods");function je(e){if(console.log(""),console.log("\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557"),console.log("\u2551 aitable-workflow migrate \u2551"),console.log(`\u2551 ${e.templateName} \xB7 ${e.profileName} \u2192 ${e.newVersion.padEnd(33)}\u2551`),console.log("\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D"),console.log(""),e.sourceDir?console.log(`\u6E90\u76EE\u5F55: ${e.sourceDir}`):console.log(`\u6A21\u677F\u7248\u672C: ${e.oldVersion} \u2192 ${e.newVersion}`),e.codemods.length>0){console.log(""),console.log("\u2500\u2500 \u914D\u7F6E\u8F6C\u5199 (codemod) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");for(let r of e.codemods)console.log(` \u21BB ${r.file}`),console.log(` \u2514 ${r.pathString}: ${r.description}`)}console.log(""),console.log("\u2500\u2500 \u914D\u7F6E\u5408\u5E76 (config) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");for(let r of e.configMerges){if(r.noChange){console.log(` \u2713 ${r.relativePath} \u2014 \u65E0\u53D8\u5316`);continue}console.log(` \u2713 ${r.relativePath}`),r.userPreservedCount>0&&console.log(` \u251C \u4FDD\u7559: ${r.userPreservedCount} \u9879\u7528\u6237\u914D\u7F6E`),r.templateUpdatedCount>0&&console.log(` \u251C \u66F4\u65B0: ${r.templateUpdatedCount} \u9879\u6A21\u677F\u53D8\u66F4`);for(let a of r.newKeys)console.log(` \u2514 \u65B0\u589E: ${a.pathString}`);for(let a of r.deprecated)console.log(` \u2514 \u79FB\u9664: ${a.pathString} (\u5DF2\u5E9F\u5F03)`)}let t=e.contentFiles.filter(r=>r.action==="preserve"),o=e.contentFiles.filter(r=>r.action==="add-new");if(t.length>0||o.length>0){console.log(""),console.log("\u2500\u2500 \u5185\u5BB9\u4FDD\u7559 (content) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");let r=lt(t.map(a=>a.relativePath));for(let[a,g]of r)console.log(` \u2713 ${a} \u2014 \u4FDD\u7559 (${g} \u6587\u4EF6)`);for(let a of o)console.log(` + ${a.relativePath} (\u65B0\u589E)`)}if(e.newEnvVars.length>0){console.log(" \u2713 .env \u2014 \u4FDD\u7559");for(let r of e.newEnvVars){let a=r.comment?` (${r.comment})`:"";console.log(` \u2514 \u26A0 \u65B0\u589E\u53D8\u91CF: ${r.key}${a}`)}}let n=e.templateFiles.filter(r=>r.action==="overwrite"),c=e.templateFiles.filter(r=>r.action==="add-new");if(n.length>0||c.length>0){console.log(""),console.log("\u2500\u2500 \u6A21\u677F\u66F4\u65B0 (template) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");let r=n.filter(a=>a.userModified);if(r.length>0){console.log(" \u26A0 \u4EE5\u4E0B\u6A21\u677F\u6587\u4EF6\u5DF2\u88AB\u624B\u52A8\u4FEE\u6539\uFF0C\u5347\u7EA7\u5C06\u8986\u76D6\u4F60\u7684\u4FEE\u6539\uFF1A");for(let a of r)console.log(` ${a.relativePath}`)}for(let a of n.filter(g=>!g.userModified))console.log(` \u21BB ${a.relativePath}`);for(let a of c)console.log(` + ${a.relativePath} (\u65B0\u589E)`)}if(e.managedFiles.length>0){console.log(""),console.log("\u2500\u2500 \u91CD\u65B0\u751F\u6210 (managed) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");for(let r of e.managedFiles)r.preservedDeps&&r.preservedDeps.length>0?console.log(` \u21BB ${r.relativePath} (\u4FDD\u7559\u81EA\u5B9A\u4E49\u4F9D\u8D56: ${r.preservedDeps.join(", ")})`):console.log(` \u21BB ${r.relativePath}`)}let i=e.configMerges.reduce((r,a)=>r+a.conflicts.length,0);if(i>0){console.log(""),console.log("\u2500\u2500 \u51B2\u7A81 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"),console.log(` \u26A0 ${i} \u5904\u51B2\u7A81\uFF08\u5DF2\u4FDD\u7559\u4F60\u7684\u503C\uFF0C\u8BF7\u5BA1\u67E5\uFF09:`);for(let r of e.configMerges)for(let a of r.conflicts)console.log(` ${r.relativePath} \u2192 ${a.pathString}`),console.log(` \u4F60\u7684\u503C: ${JSON.stringify(a.oursValue)}`),console.log(` \u65B0\u6A21\u677F\u503C: ${JSON.stringify(a.theirsValue)}`);console.log(""),console.log(" \u51B2\u7A81\u8BE6\u60C5\u5C06\u5199\u5165 .migrate-conflicts.yml")}console.log("")}l(je,"printMigrationPreview");function xe(){console.log("[dry-run] \u4EE5\u4E0A\u4E3A\u9884\u89C8\uFF0C\u672A\u6267\u884C\u4EFB\u4F55\u5199\u5165\u64CD\u4F5C\u3002"),console.log(` \u53BB\u6389 --dry-run \u6267\u884C\u5B9E\u9645\u8FC1\u79FB\u3002
|
|
6
|
+
`)}l(xe,"printDryRunFooter");function De(e){console.log(`\u2713 \u8FC1\u79FB\u5B8C\u6210
|
|
7
|
+
`),console.log("\u4E0B\u4E00\u6B65:"),console.log(` 1. cd ${e}`),console.log(" 2. tnpm i"),console.log(" 3. aitable-workflow setup"),console.log(` 4. aitable-workflow run
|
|
8
|
+
`)}l(De,"printPostMigrateSteps");function lt(e){let t=new Map;for(let o of e){let n=o.split("/")[0];t.set(n,(t.get(n)??0)+1)}return[...t.entries()].sort((o,n)=>o[0].localeCompare(n[0]))}l(lt,"groupByPrefix");import{cp as Ne,access as ft,readFile as gt,readdir as $e,rename as ut,writeFile as pt}from"fs/promises";import E from"path";import{fileURLToPath as dt}from"url";async function V(e){try{return await ft(e),!0}catch{return!1}}l(V,"exists");async function ie(){let e=E.dirname(dt(import.meta.url));for(let t=0;t<8;t++){let o=E.join(e,"templates");if(await V(o))return o;let n=E.dirname(e);if(n===e)break;e=n}throw new Error("\u627E\u4E0D\u5230\u5185\u7F6E templates \u76EE\u5F55(\u8BF7\u901A\u8FC7 templatesDir \u6CE8\u5165,\u6216\u786E\u8BA4 aitable-workflow-cli \u5DF2\u968F\u5305\u53D1\u5E03 templates)")}l(ie,"resolveTemplatesDir");async function mt(e){let t=e??await ie();return(await $e(t,{withFileTypes:!0})).filter(n=>n.isDirectory()).map(n=>n.name).sort()}l(mt,"listTemplates");async function wt(e,t){let o=t??await ie(),n=E.join(o,e,"profiles");return await V(n)?(await $e(n,{withFileTypes:!0})).filter(i=>i.isDirectory()).map(i=>i.name).sort():[]}l(wt,"listProfiles");async function Ie(e,t,o,n,c={},i,r){let a=n??await ie(),g=E.join(a,e);if(!await V(g)){let p=await mt(a);throw new Error(`\u672A\u627E\u5230\u6A21\u677F "${e}"\u3002\u53EF\u7528\u6A21\u677F: ${p.join(", ")||"(\u7A7A)"}`)}let u;if(i){if(u=E.join(g,"profiles",i),!await V(u)){let p=await wt(e,a);throw new Error(`\u6A21\u677F "${e}" \u672A\u627E\u5230 profile "${i}"\u3002\u53EF\u7528 profile: ${p.join(", ")||"(\u65E0)"}`)}}else{let p=E.join(g,"profiles","default");await V(p)&&(u=p,i="default")}let m=E.join(t,"package.json"),F=o||!await V(m),k=E.join(g,"profiles");await Ne(g,t,{recursive:!0,force:o,errorOnExist:!1,filter:l(p=>p!==k&&!p.startsWith(k+E.sep),"filter")}),u&&await Ne(u,t,{recursive:!0,force:!0,errorOnExist:!1}),F&&await yt(m,c);let d=E.join(t,"npmrc");if(await V(d)&&await ut(d,E.join(t,".npmrc")),r){let p=W(),[C,S]=await Promise.all([L(t,p),U(t,p)]);await J(t,{schema_version:1,template:e,profile:i??"default",cli_version:r,scaffolded_at:new Date().toISOString(),config_snapshot:C,config_base_contents:S})}return{template:e,from:g,target:t,...i?{profile:i}:{}}}l(Ie,"scaffoldFromTemplate");var ht=["dependencies","devDependencies","optionalDependencies","peerDependencies"];async function yt(e,t){if(!await V(e)||Object.keys(t).length===0)return;let o=JSON.parse(await gt(e,"utf8")),n=!1;for(let c of ht){let i=o[c];if(!(!i||typeof i!="object"||Array.isArray(i)))for(let[r,a]of Object.entries(i)){let g=t[r];!g||a===g||(i[r]=g,n=!0)}}n&&await pt(e,`${JSON.stringify(o,null,2)}
|
|
9
|
+
`,"utf8")}l(yt,"pinPackageVersions");async function Rn(e){let t=St(e.to??e.config),o=e.cliVersion??"unknown",n=e.from?w.resolve(e.from):void 0;if(n){if(e.template||e.profile)throw new Error("--from \u4E0E --template/--profile \u4E92\u65A5\uFF1A\u6E90\u76EE\u5F55\u6A21\u5F0F\u4E0D\u6309\u540D scaffold \u6A21\u677F\u3002");if(w.resolve(n)===w.resolve(t))throw new Error("--from \u4E0E --to \u6307\u5411\u540C\u4E00\u76EE\u5F55\uFF0C\u65E0\u9700\u8FC1\u79FB\u3002");try{await se(n)}catch{throw new Error(`--from \u6307\u5411\u7684\u6E90\u76EE\u5F55\u4E0D\u5B58\u5728: ${n}`)}}if(e.list){let u=await Y(t);if(u.length===0)console.log("\u65E0\u5907\u4EFD\u8BB0\u5F55\u3002");else{console.log("\u5907\u4EFD\u5217\u8868\uFF08\u6700\u65B0\u5728\u524D\uFF09\uFF1A");for(let m of u)console.log(` ${m.timestamp} CLI ${m.cliVersion} ${m.fullPath}`)}return{plan:Te(o)}}if(e.rollback){let u=await Y(t);if(u.length===0)throw new Error("\u65E0\u53EF\u7528\u5907\u4EFD\uFF0C\u65E0\u6CD5\u56DE\u6EDA\u3002");let m=u[0];return console.log(`\u56DE\u6EDA\u5230\u5907\u4EFD: ${m.timestamp} (CLI ${m.cliVersion})`),await Pe(t,m),console.log(`\u2713 \u56DE\u6EDA\u5B8C\u6210\u3002
|
|
10
|
+
`),{plan:Te(o)}}let c=await ee(t),i=n?w.basename(n):e.template??c?.template??await Rt(t),r=e.profile??c?.profile??"default",a=c?.cli_version??await Et(t)??"unknown";if(!i)throw new Error("\u65E0\u6CD5\u786E\u5B9A\u9879\u76EE\u4F7F\u7528\u7684\u6A21\u677F\u3002\u8BF7\u901A\u8FC7 --template <name> \u6307\u5B9A\uFF0C\u6216\u786E\u4FDD .migrate-meta.json \u5B58\u5728\u3002");let g=await kt(w.join(Ct.tmpdir(),"migrate-template-"));try{n?await Oe(n,g):await Ie(i,g,!0,e.templatesDir,e.templatePackageVersions,r);let u=W(),m=[],F=[],k=new Map;for(let s of u){let y=w.join(t,s),h=w.join(g,s),v,M;try{v=await T(y,"utf8")}catch{}try{M=await T(h,"utf8")}catch{}if(!v&&!M)continue;if(!v&&M){k.set(s,{result:{merged:{},conflicts:[],deprecated:[],newKeys:[],userPreserved:[],templateUpdated:[]},base:{},oursContent:"",theirsContent:M}),m.push({relativePath:s,conflicts:[],deprecated:[],newKeys:[],userPreservedCount:0,templateUpdatedCount:0,noChange:!1});continue}if(v&&!M)continue;let R=be(s,v);R.content!==void 0&&(v=R.content,F.push(...R.changes));let ce=c?.config_base_contents?.[s],H=s.endsWith(".json")?Z=>JSON.parse(Z):Z=>B.parse(Z)??{},le=ce?H(ce):{},Je=H(v),Le=H(M),_=de(le,Je,Le);k.set(s,{result:_,base:le,oursContent:v,theirsContent:M}),m.push({relativePath:s,conflicts:_.conflicts,deprecated:_.deprecated,newKeys:_.newKeys,userPreservedCount:_.userPreserved.length,templateUpdatedCount:_.templateUpdated.length,noChange:_.conflicts.length===0&&_.newKeys.length===0&&_.deprecated.length===0&&_.userPreserved.length===0&&_.templateUpdated.length===0})}let d=await ne(t),p=await ne(g),C=new Set(d.map(s=>s.relativePath)),S=new Set(p.map(s=>s.relativePath)),P=[];for(let s of d)s.category==="content"&&P.push({relativePath:s.relativePath,action:"preserve"});for(let s of p)s.category==="content"&&!C.has(s.relativePath)&&P.push({relativePath:s.relativePath,action:"add-new"});let f=[];for(let s of p)if(s.category==="template")if(C.has(s.relativePath)){let y=!1,h=c?.config_snapshot;if(h)try{let v=await T(w.join(t,s.relativePath),"utf8"),M=h[s.relativePath];M&&te(v)!==M&&(y=!0)}catch{}f.push({relativePath:s.relativePath,action:"overwrite",userModified:y})}else f.push({relativePath:s.relativePath,action:"add-new",userModified:!1});let x=[],b;if(S.has("package.json")){let s={},y={};try{s=JSON.parse(await T(w.join(t,"package.json"),"utf8"))}catch{}try{y=JSON.parse(await T(w.join(g,"package.json"),"utf8"))}catch{}b=Fe(s,y,e.templatePackageVersions??{}),x.push({relativePath:"package.json",preservedDeps:b.preservedDeps})}for(let s of[".npmrc",".gitignore"])S.has(s)&&x.push({relativePath:s});let D=[];for(let s of d)if(s.category==="template"&&s.relativePath.endsWith("workflow.yml"))try{let h=B.parse(await T(w.join(t,s.relativePath),"utf8")).tracker;if(h?.base_id||h?.table_id){let v=w.dirname(s.relativePath).split("/").pop()??s.relativePath;D.push({workflow:v,baseId:h.base_id??"",tableId:h.table_id??""})}}catch{}let N=await Re(w.join(t,".env"),w.join(g,".env.example")),$={templateName:i,profileName:r,oldVersion:a,newVersion:o,...n?{sourceDir:n}:{},configMerges:m,codemods:F,contentFiles:P,templateFiles:f,managedFiles:x,newEnvVars:N,workflowTrackerFields:D};if(je($),e.dryRun)return xe(),{plan:$};if(!e.force){let{confirm:s}=await import("@inquirer/prompts");if(!await s({message:"\u786E\u8BA4\u6267\u884C\u8FC1\u79FB\uFF1F",default:!0}))throw new Error("cancelled")}let X;e.noBackup||(X=await ve(t,o),console.log(`\u2713 \u5DF2\u5907\u4EFD\u5230: ${X.fullPath}`));for(let s of u){let y=m.find(R=>R.relativePath===s);if(!y||y.noChange)continue;let h=k.get(s);if(!h)continue;let v=w.join(t,s);if(!h.oursContent&&h.theirsContent){await G(w.dirname(v),{recursive:!0}),await A(v,h.theirsContent,"utf8");continue}if(!h.theirsContent)continue;if(s.endsWith(".json"))await A(v,JSON.stringify(h.result.merged,null,2)+`
|
|
11
|
+
`,"utf8");else{let R=B.parseDocument(h.oursContent);Ft(R,h.base,h.result.merged),await A(v,R.toString(),"utf8")}}for(let s of f){let y=w.join(g,s.relativePath),h=w.join(t,s.relativePath);await G(w.dirname(h),{recursive:!0}),await q(y,h,{force:!0})}for(let s of D){if(!s.baseId&&!s.tableId)continue;let y=f.filter(h=>h.relativePath.endsWith("workflow.yml")&&h.relativePath.includes(s.workflow));for(let h of y){let v=w.join(t,h.relativePath);try{let M=await T(v,"utf8"),R=B.parseDocument(M);s.baseId&&R.setIn(["tracker","base_id"],s.baseId),s.tableId&&R.setIn(["tracker","table_id"],s.tableId),await A(v,R.toString(),"utf8")}catch{}}}if(b){let s=w.join(t,"package.json");await A(s,JSON.stringify(b.merged,null,2)+`
|
|
12
|
+
`,"utf8")}for(let s of[".npmrc",".gitignore"]){let y=w.join(g,s),h=w.join(t,s);try{await se(y),await q(y,h,{force:!0})}catch{}}for(let s of P){if(s.action!=="add-new")continue;let y=w.join(g,s.relativePath),h=w.join(t,s.relativePath);await G(w.dirname(h),{recursive:!0}),await q(y,h,{force:!1,errorOnExist:!1})}let z,ae=m.flatMap(s=>s.conflicts.map(y=>({file:s.relativePath,...y})));if(ae.length>0){z=w.join(t,".migrate-conflicts.yml");let s=ae.map(y=>({file:y.file,path:y.pathString,your_value:y.oursValue,template_value:y.theirsValue,base_value:y.baseValue}));await A(z,B.stringify(s),"utf8")}let Be=await L(t,u),Ke=await U(g,u);return await J(t,{schema_version:1,template:i,profile:r,cli_version:o,scaffolded_at:new Date().toISOString(),config_snapshot:Be,config_base_contents:Ke}),await Ce(t),De(t),{plan:$,backup:X,conflictFile:z}}finally{await Pt(g,{recursive:!0,force:!0}).catch(()=>{})}}l(Rn,"runMigrate");async function En(e,t){try{let o=await ee(e);if(!o||o.cli_version===t)return;console.warn(`\u26A0 CLI \u7248\u672C\u5DF2\u4ECE ${o.cli_version} \u5347\u7EA7\u5230 ${t}\uFF0C\u6A21\u677F\u53EF\u80FD\u5DF2\u66F4\u65B0\u3002
|
|
13
|
+
\u8FD0\u884C aitable-workflow migrate \u4EE5\u5347\u7EA7\u9879\u76EE\u914D\u7F6E\u3002
|
|
14
|
+
`)}catch{}}l(En,"checkMigrateHint");function St(e){if(!e)return process.cwd();let t=w.resolve(e),o=w.extname(t).toLowerCase();return o===".yml"||o===".yaml"?w.dirname(t):t}l(St,"resolveConfigDir");var Mt=new Set(["node_modules",".git",".migrate-backup",".migrate-meta.json","traces",".memory",".DS_Store","package-lock.json","pnpm-lock.yaml"]);async function Oe(e,t){let o=await vt(e,{withFileTypes:!0});await G(t,{recursive:!0});for(let n of o){if(Mt.has(n.name))continue;let c=w.join(e,n.name),i=w.join(t,n.name);n.isDirectory()?await Oe(c,i):n.isFile()&&await q(c,i,{force:!0})}}l(Oe,"copySourceDir");async function Rt(e){try{return await se(w.join(e,"workflows")),"support-qa"}catch{return}}l(Rt,"inferTemplateName");async function Et(e){try{return JSON.parse(await T(w.join(e,"package.json"),"utf8")).dependencies?.["aitable-workflow-core"]?.replace(/^\^/,"")}catch{return}}l(Et,"inferCliVersion");function Ft(e,t,o){Ae(e,[],t,o)}l(Ft,"applyMergeToDoc");function Ae(e,t,o,n){if(Ve(o)&&Ve(n)){let c=new Set([...Object.keys(o),...Object.keys(n)]);for(let i of c){let r=[...t,i];i in n?i in o?Ae(e,r,o[i],n[i]):e.setIn(r,n[i]):e.deleteIn(r)}}else _t(o,n)||e.setIn(t,n)}l(Ae,"applyRecursive");function Ve(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}l(Ve,"isPlainObject");function _t(e,t){return JSON.stringify(e)===JSON.stringify(t)}l(_t,"deepEqualSimple");function Te(e){return{templateName:"",profileName:"",oldVersion:"",newVersion:e,configMerges:[],codemods:[],contentFiles:[],templateFiles:[],managedFiles:[],newEnvVars:[],workflowTrackerFields:[]}}l(Te,"emptyPlan");export{mt as a,wt as b,Ie as c,Rn as d,En as e};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var d=Object.defineProperty;var e=(b,a)=>d(b,"name",{value:a,configurable:!0});var f=(b,a)=>{for(var c in a)d(b,c,{get:a[c],enumerable:!0})};export{e as a,f as b};
|