aitable-workflow-core 0.1.25 → 0.1.26-beta.1788916459616
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-7ZN5IYNW.js +14 -0
- package/dist/index.d.ts +10 -3
- package/dist/index.js +189 -188
- package/dist/migrate-GD2E2KYE.js +1 -0
- package/package.json +2 -2
- package/skills/aitable-workflow/SKILL.md +4 -2
- package/skills/aitable-workflow/references/aitable-cell-values.md +17 -0
- package/skills/aitable-workflow/references/automations.md +88 -2
- package/skills/aitable-workflow/references/config-surface.md +30 -0
- package/skills/aitable-workflow/references/event-handlers.md +8 -1
- package/skills/aitable-workflow/references/forms.md +28 -0
- package/skills/aitable-workflow/references/generated/core-api.md +2 -0
- package/skills/aitable-workflow/references/invariants.md +2 -0
- package/skills/aitable-workflow/references/profile-and-roles.md +20 -0
- package/skills/aitable-workflow/references/recipe-contract.md +5 -2
- package/skills/aitable-workflow/references/runtime-refs.md +4 -0
- package/skills/aitable-workflow/references/tracker-state.md +11 -0
- package/skills/aitable-workflow/references/trigger-once.md +45 -0
- package/skills/aitable-workflow/references/workflow-yml.md +5 -1
- package/skills/aitable-workflow-design/patterns/clarification-checklist.md +3 -1
- package/skills/aitable-workflow-design/patterns/dingtalk-bot-patterns.md +9 -1
- package/skills/aitable-workflow-design/patterns/external-aitable-read.md +4 -1
- package/skills/aitable-workflow-design/patterns/greenfield-checklist.md +4 -1
- package/skills/aitable-workflow-design/patterns/json-contract-and-repair.md +13 -9
- package/skills/aitable-workflow-design/patterns/output-and-report.md +1 -0
- package/skills/aitable-workflow-design/patterns/recipe-vs-automation.md +6 -4
- package/dist/chunk-B45CQPV6.js +0 -14
- package/dist/migrate-XVGE3KR7.js +0 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
var ge=Object.defineProperty;var l=(e,t)=>ge(e,"name",{value:t,configurable:!0});var Lt=(e,t)=>{for(var r in t)ge(e,r,{get:t[r],enumerable:!0})};import{access as ce,cp as X,mkdir as H,mkdtemp as $t,readdir as Dt,readFile as A,rm as Nt,writeFile as K}from"fs/promises";import m from"path";import It from"os";import J from"yaml";import{createHash as Ze}from"crypto";import{readFile as ne,writeFile as Qe}from"fs/promises";import L from"path";var pe=".migrate-meta.json";async function re(e){try{let t=await ne(L.join(e,pe),"utf8");return JSON.parse(t)}catch{return null}}l(re,"readMigrateMeta");async function U(e,t){let r=L.join(e,pe);await Qe(r,JSON.stringify(t,null,2)+`
|
|
2
|
+
`,"utf8")}l(U,"writeMigrateMeta");function oe(e){return Ze("sha256").update(e,"utf8").digest("hex").slice(0,16)}l(oe,"hashFileContent");async function W(e,t){let r={};for(let n of t)try{let s=await ne(L.join(e,n),"utf8");r[n]=oe(s)}catch{}return r}l(W,"buildConfigSnapshot");async function Y(e,t){let r={};for(let n of t)try{r[n]=await ne(L.join(e,n),"utf8")}catch{}return r}l(Y,"buildConfigBaseContents");import{readdir as et}from"fs/promises";import de from"path";var me=new Set(["profile/profile.yml","aitable-workflow.config.yml","coding-agents.config.json"]),tt=new Set(["package.json",".npmrc","npmrc",".gitignore",".migrate-meta.json",".migrate-conflicts.yml"]),nt=["wiki/","skills/","profile/prompts/","profile/escalation/","profile/fastpath/","profile/troubleshoot/"],rt=new Set([".env",".env.example"]),ot=/^workspaces\/[^/]+\/AGENTS\.md$/,it=["lib/","workflows/"];function st(e){let t=e.replace(/\\/g,"/");if(me.has(t))return"config";if(tt.has(t))return"managed";if(rt.has(t)||ot.test(t))return"content";for(let r of nt)if(t.startsWith(r))return"content";for(let r of it)if(t.startsWith(r))return"template";return"content"}l(st,"classifyFile");function q(){return[...me]}l(q,"getConfigFilePaths");async function ie(e){let t=[];return await we(e,e,t),t}l(ie,"classifyDirectory");var at=new Set(["node_modules",".migrate-backup",".git","traces"]);async function we(e,t,r){let n=await et(t,{withFileTypes:!0});for(let s of n){let i=de.join(t,s.name);if(s.isDirectory())at.has(s.name)||await we(e,i,r);else if(s.isFile()){let o=de.relative(e,i).replace(/\\/g,"/");r.push({relativePath:o,category:st(o)})}}}l(we,"walkDir");function he(e,t,r){let n=[],s=[],i=[],o=[],a=[];return{merged:u(e,t,r,[]),conflicts:n,deprecated:s,newKeys:i,userPreserved:o,templateUpdated:a};function u(k,d,y,S){return I(k)&&I(d)&&I(y)?p(k,d,y,S):I(d)&&I(y)&&!I(k)?p(I(k)?k:{},d,y,S):M(k,d,y,S)}function p(k,d,y,S){let v=new Set;for(let g of Object.keys(k))v.add(g);for(let g of Object.keys(d))v.add(g);for(let g of Object.keys(y))v.add(g);let P={};for(let g of v){let F=g in k,b=g in d,$=g in y,D=[...S,g],N=D.join(".");!F&&!b&&$?(P[g]=y[g],i.push({path:D,pathString:N,theirsValue:y[g]})):!F&&b&&!$?P[g]=d[g]:!F&&b&&$?O(d[g],y[g])?P[g]=d[g]:I(d[g])&&I(y[g])?P[g]=p({},d[g],y[g],D):(P[g]=d[g],n.push({path:D,pathString:N,baseValue:void 0,oursValue:d[g],theirsValue:y[g]})):F&&!$?b&&!O(k[g],d[g])?(P[g]=d[g],n.push({path:D,pathString:N,baseValue:k[g],oursValue:d[g],theirsValue:void 0})):s.push({path:D,pathString:N,baseValue:k[g]}):F&&!b&&$?(P[g]=y[g],a.push(N)):P[g]=u(k[g],d[g],y[g],D)}return P}function M(k,d,y,S){let v=O(k,d),P=O(k,y),g=O(d,y);return v&&P?d:v&&!P?(a.push(S.join(".")),y):!v&&P?(o.push(S.join(".")),d):(g||(n.push({path:S,pathString:S.join("."),baseValue:k,oursValue:d,theirsValue:y}),o.push(S.join("."))),d)}}l(he,"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((r,n)=>O(r,t[n]));if(typeof e=="object"){let r=e,n=t,s=Object.keys(r),i=Object.keys(n);return s.length!==i.length?!1:s.every(o=>Object.prototype.hasOwnProperty.call(n,o)&&O(r[o],n[o]))}return!1}l(O,"deepEqual");import{cp as ke,mkdir as ct,readdir as se,readFile as lt,rm as ve,writeFile as ft}from"fs/promises";import x from"path";var Pe=".migrate-backup",ye=3,Ce=new Set(["node_modules",".migrate-backup",".git"]);async function Se(e,t){let r=new Date,n=r.toISOString().replace(/[:.]/g,""),s=x.join(e,Pe),i=x.join(s,n);await ct(i,{recursive:!0});let o=await se(e,{withFileTypes:!0});for(let f of o){if(Ce.has(f.name))continue;let u=x.join(e,f.name),p=x.join(i,f.name);await ke(u,p,{recursive:!0,force:!0,errorOnExist:!1})}let a=x.join(i,".backup-info.json");return await ft(a,JSON.stringify({timestamp:r.toISOString(),cliVersion:t},null,2)+`
|
|
3
|
+
`,"utf8"),{timestamp:r.toISOString(),dirName:n,fullPath:i,cliVersion:t}}l(Se,"createBackup");async function z(e){let t=x.join(e,Pe),r;try{r=(await se(t,{withFileTypes:!0})).filter(i=>i.isDirectory()).map(i=>i.name)}catch{return[]}let n=[];for(let s of r){let i=x.join(t,s),o=x.join(i,".backup-info.json");try{let a=JSON.parse(await lt(o,"utf8"));n.push({timestamp:a.timestamp,dirName:s,fullPath:i,cliVersion:a.cliVersion})}catch{n.push({timestamp:s,dirName:s,fullPath:i,cliVersion:"unknown"})}}return n.sort((s,i)=>i.timestamp.localeCompare(s.timestamp)),n}l(z,"listBackups");async function Me(e,t){let r=await se(e,{withFileTypes:!0});for(let n of r){if(Ce.has(n.name))continue;let s=x.join(e,n.name);await ve(s,{recursive:!0,force:!0})}await ke(t.fullPath,e,{recursive:!0,force:!0,errorOnExist:!1,filter:l(n=>x.relative(t.fullPath,n)!==".backup-info.json","filter")})}l(Me,"rollbackToBackup");async function _e(e){let t=await z(e);if(t.length<=ye)return 0;let r=t.slice(ye);for(let n of r)await ve(n.fullPath,{recursive:!0,force:!0});return r.length}l(_e,"pruneBackups");import{readFile as Ee}from"fs/promises";var Re=/^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/;function ut(e){let t=new Map;for(let r of e.split(`
|
|
4
|
+
`)){let n=Re.exec(r.trim());n&&t.set(n[1],n[2])}return t}l(ut,"parseEnvKeys");async function je(e,t){let r;try{r=await Ee(t,"utf8")}catch{return[]}let n="";try{n=await Ee(e,"utf8")}catch{}let s=ut(n),i=[],o=r.split(`
|
|
5
|
+
`);for(let a=0;a<o.length;a++){let f=Re.exec(o[a].trim());if(!f)continue;let u=f[1],p=f[2];if(s.has(u))continue;let M;a>0&&o[a-1].trim().startsWith("#")&&(M=o[a-1].trim().replace(/^#\s*/,"")),i.push({key:u,exampleValue:p,comment:M})}return i}l(je,"detectNewEnvVars");var be=["dependencies","devDependencies","optionalDependencies","peerDependencies"],gt="aitable-workflow-",pt=/^(file:|link:|workspace:|portal:)/;function xe(e,t,r){let n=JSON.parse(JSON.stringify(t)),s=[],i=new Set;for(let o of be){let a=e[o];if(!a||typeof a!="object")continue;let f=n[o]??{};for(let[u,p]of Object.entries(a)){if(u.startsWith(gt)){typeof p=="string"&&pt.test(p)&&(f[u]=p,i.add(u),s.push(u));continue}u in f||(f[u]=p,s.push(u))}n[o]=f}for(let o of be){let a=n[o];if(!(!a||typeof a!="object"))for(let[f,u]of Object.entries(a)){if(i.has(f))continue;let p=r[f];p&&(a[f]=p)}}return{merged:n,preservedDeps:s}}l(xe,"mergePackageJson");import B from"yaml";var dt="1to1",Fe="group",mt={files:["profile/profile.yml"],apply(e,t){let r=[],n=e.getIn(["workflows"]);if(!B.isMap(n))return r;for(let s of n.items){let i=String(s.key?.value??s.key),o=e.getIn(["workflows",i,"event_sources"]);if(B.isMap(o))for(let a of o.items){let f=String(a.key?.value??a.key),u=["workflows",i,"event_sources",f];if(e.getIn([...u,"type"])!=="dingtalk_stream"||!e.hasIn([...u,"drop_direct"]))continue;let p=e.getIn([...u,"drop_direct"]),M=e.hasIn([...u,"conversation_types"]),k=[...u,"drop_direct"].join(".");if(M){e.deleteIn([...u,"drop_direct"]),r.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=p===!1?[Fe,dt]:[Fe];e.deleteIn([...u,"drop_direct"]),e.setIn([...u,"conversation_types"],d),r.push({file:t,pathString:k,description:`drop_direct: ${JSON.stringify(p)} \u2192 conversation_types: ${JSON.stringify(d)}`})}}return r}},wt={files:["profile/profile.yml"],apply(e,t){let r=[],n=e.getIn(["workflows"]);if(!B.isMap(n))return r;for(let s of n.items){let i=String(s.key?.value??s.key),o=e.getIn(["workflows",i,"event_sources"]);if(B.isMap(o))for(let a of o.items){let f=String(a.key?.value??a.key),u=["workflows",i,"event_sources",f];e.getIn([...u,"type"])==="dingtalk_user_message"&&e.hasIn([...u,"exclude_sender_nicks"])&&(e.deleteIn([...u,"exclude_sender_nicks"]),r.push({file:t,pathString:[...u,"exclude_sender_nicks"].join("."),description:"\u6309\u53D1\u9001\u8005\u6392\u9664\u5DF2\u79FB\u4EA4 handler\uFF08handler_config.bots/admins\uFF09\uFF0C\u79FB\u9664\u6E90\u7EA7 exclude_sender_nicks"}))}}return r}},ht=[mt,wt];function $e(e,t){let r=ht.filter(i=>i.files.includes(e));if(r.length===0)return{changes:[]};let n;try{n=B.parseDocument(t)}catch{return{changes:[]}}let s=[];for(let i of r)s.push(...i.apply(n,e));return s.length===0?{changes:[]}:{content:n.toString(),changes:s}}l($e,"applyConfigCodemods");function De(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 o of e.codemods)console.log(` \u21BB ${o.file}`),console.log(` \u2514 ${o.pathString}: ${o.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 o of e.configMerges){if(o.noChange){console.log(` \u2713 ${o.relativePath} \u2014 \u65E0\u53D8\u5316`);continue}console.log(` \u2713 ${o.relativePath}`),o.userPreservedCount>0&&console.log(` \u251C \u4FDD\u7559: ${o.userPreservedCount} \u9879\u7528\u6237\u914D\u7F6E`),o.templateUpdatedCount>0&&console.log(` \u251C \u66F4\u65B0: ${o.templateUpdatedCount} \u9879\u6A21\u677F\u53D8\u66F4`);for(let a of o.newKeys)console.log(` \u2514 \u65B0\u589E: ${a.pathString}`);for(let a of o.deprecated)console.log(` \u2514 \u79FB\u9664: ${a.pathString} (\u5DF2\u5E9F\u5F03)`)}let t=e.contentFiles.filter(o=>o.action==="preserve"),r=e.contentFiles.filter(o=>o.action==="add-new");if(t.length>0||r.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 o=yt(t.map(a=>a.relativePath));for(let[a,f]of o)console.log(` \u2713 ${a} \u2014 \u4FDD\u7559 (${f} \u6587\u4EF6)`);for(let a of r)console.log(` + ${a.relativePath} (\u65B0\u589E)`)}if(e.newEnvVars.length>0){console.log(" \u2713 .env \u2014 \u4FDD\u7559");for(let o of e.newEnvVars){let a=o.comment?` (${o.comment})`:"";console.log(` \u2514 \u26A0 \u65B0\u589E\u53D8\u91CF: ${o.key}${a}`)}}let n=e.templateFiles.filter(o=>o.action==="overwrite"),s=e.templateFiles.filter(o=>o.action==="add-new");if(n.length>0||s.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 o=n.filter(a=>a.userModified);if(o.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 o)console.log(` ${a.relativePath}`)}for(let a of n.filter(f=>!f.userModified))console.log(` \u21BB ${a.relativePath}`);for(let a of s)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 o of e.managedFiles)o.preservedDeps&&o.preservedDeps.length>0?console.log(` \u21BB ${o.relativePath} (\u4FDD\u7559\u81EA\u5B9A\u4E49\u4F9D\u8D56: ${o.preservedDeps.join(", ")})`):console.log(` \u21BB ${o.relativePath}`)}let i=e.configMerges.reduce((o,a)=>o+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 o of e.configMerges)for(let a of o.conflicts)console.log(` ${o.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(De,"printMigrationPreview");function Ne(){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(Ne,"printDryRunFooter");function Ie(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(Ie,"printPostMigrateSteps");function yt(e){let t=new Map;for(let r of e){let n=r.split("/")[0];t.set(n,(t.get(n)??0)+1)}return[...t.entries()].sort((r,n)=>r[0].localeCompare(n[0]))}l(yt,"groupByPrefix");import{cp as Be,access as St,readFile as Mt,readdir as Je,rename as _t,writeFile as Et}from"fs/promises";import _ from"path";import{fileURLToPath as Rt}from"url";import{cp as Ve,readFile as Te,stat as kt}from"fs/promises";import V from"path";import vt from"yaml";async function Ke(e,t){let r=await Ct(e);Object.keys(r).length!==0&&await Pt(e,t,r)}l(Ke,"materializeSharedKnowledge");async function Pt(e,t,r){for(let[n,s]of Object.entries(r)){let i=typeof s=="string"?s:s.source,o=typeof s=="string"?void 0:s.include,a=typeof s=="string"?void 0:s.exclude,f=V.join(t,i);if(!await G(f))throw new Error(`\u5171\u4EAB\u77E5\u8BC6\u6E90\u4E0D\u5B58\u5728: ${f}`);let u=V.join(e,n);if(o&&o.length>0)for(let p of o){let M=V.join(f,p);if(!await G(M))throw new Error(`\u5171\u4EAB\u77E5\u8BC6\u6E90\u5B50\u8DEF\u5F84\u4E0D\u5B58\u5728: ${M}\uFF08include: ${JSON.stringify(o)}\uFF09`);await Ae(M,V.join(u,p),f,a)}else await Ae(f,u,f,a)}}l(Pt,"materializeWithMapping");async function Ae(e,t,r,n){if(!n||n.length===0){await Ve(e,t,{recursive:!0});return}await Ve(e,t,{recursive:!0,filter:l(s=>{let i=V.relative(r,s).split(V.sep).join("/");return i===""?!0:!n.some(o=>i===o||i.startsWith(`${o}/`))},"filter")})}l(Ae,"copyTree");async function Ct(e){let t=V.join(e,"profile","profile.yml");if(await G(t)){let n=await Te(t,"utf8"),i=vt.parse(n)?.shared_knowledge;if(i&&typeof i=="object"&&!Array.isArray(i))return Oe(i)}let r=V.join(e,"_skill","template.json");if(await G(r)){let s=JSON.parse(await Te(r,"utf8")).sharedKnowledge;if(s&&typeof s=="object"&&!Array.isArray(s))return Oe(s)}return{}}l(Ct,"resolveMapping");function Oe(e){let t={};for(let[r,n]of Object.entries(e))if(typeof n=="string")t[r]=n;else if(n&&typeof n=="object"&&!Array.isArray(n)){let s=n;if(typeof s.source!="string"||!s.source)throw new Error(`shared_knowledge.${r} \u7F3A\u5C11 source \u5B57\u6BB5`);for(let i of["include","exclude"]){let o=s[i];if(o!==void 0){if(!Array.isArray(o)||!o.every(a=>typeof a=="string"))throw new Error(`shared_knowledge.${r}.${i} \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4`);for(let a of o)if(!a||V.isAbsolute(a)||a.split(/[/\\]/).includes(".."))throw new Error(`shared_knowledge.${r}.${i} \u7684\u9879\u5FC5\u987B\u662F source \u5185\u7684\u76F8\u5BF9\u8DEF\u5F84: ${JSON.stringify(a)}`)}}t[r]={source:s.source,include:s.include,exclude:s.exclude}}else throw new Error(`shared_knowledge.${r} \u7684\u503C\u5FC5\u987B\u662F\u5B57\u7B26\u4E32\uFF08\u6E90\u540D\uFF09\u6216\u5BF9\u8C61\uFF08{ source, include?, exclude? }\uFF09`);return t}l(Oe,"validateMapping");async function G(e){try{return await kt(e),!0}catch{return!1}}l(G,"pathExists");async function T(e){try{return await St(e),!0}catch{return!1}}l(T,"exists");async function ae(){let e=_.dirname(Rt(import.meta.url));for(let t=0;t<8;t++){let r=_.join(e,"templates");if(await T(r))return r;let n=_.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(ae,"resolveTemplatesDir");async function jt(e){let t=e??await ae();return(await Je(t,{withFileTypes:!0})).filter(n=>n.isDirectory()&&!n.name.startsWith("_")).map(n=>n.name).sort()}l(jt,"listTemplates");async function bt(e,t){let r=t??await ae(),n=_.join(r,e,"profiles");return await T(n)?(await Je(n,{withFileTypes:!0})).filter(i=>i.isDirectory()).map(i=>i.name).sort():[]}l(bt,"listProfiles");async function Le(e,t,r,n,s={},i,o,a){let f=n??await ae(),u=_.join(f,e);if(!await T(u)){let v=await jt(f);throw new Error(`\u672A\u627E\u5230\u6A21\u677F "${e}"\u3002\u53EF\u7528\u6A21\u677F: ${v.join(", ")||"(\u7A7A)"}`)}let p;if(i){if(p=_.join(u,"profiles",i),!await T(p)){let v=await bt(e,f);throw new Error(`\u6A21\u677F "${e}" \u672A\u627E\u5230 profile "${i}"\u3002\u53EF\u7528 profile: ${v.join(", ")||"(\u65E0)"}`)}}else{let v=_.join(u,"profiles","default");await T(v)&&(p=v,i="default")}let M=_.join(t,"package.json"),k=r||!await T(M),d=_.join(u,"profiles");await Be(u,t,{recursive:!0,force:r,errorOnExist:!1,filter:l(v=>!(v===d||v.startsWith(d+_.sep)||_.relative(u,v).split(_.sep).includes("__tests__")||/\.test\.[cm]?[jt]sx?$/.test(v)),"filter")}),p&&await Be(p,t,{recursive:!0,force:!0,errorOnExist:!1});let y=a??_.join(f,"_shared");await T(y)&&await Ke(t,y),k&&await Ft(M,s);let S=_.join(t,"npmrc");if(await T(S)&&await _t(S,_.join(t,".npmrc")),o){let v=q(),[P,g]=await Promise.all([W(t,v),Y(t,v)]);await U(t,{schema_version:1,template:e,profile:i??"default",cli_version:o,scaffolded_at:new Date().toISOString(),config_snapshot:P,config_base_contents:g})}return{template:e,from:u,target:t,...i?{profile:i}:{}}}l(Le,"scaffoldFromTemplate");var xt=["dependencies","devDependencies","optionalDependencies","peerDependencies"];async function Ft(e,t){if(!await T(e)||Object.keys(t).length===0)return;let r=JSON.parse(await Mt(e,"utf8")),n=!1;for(let s of xt){let i=r[s];if(!(!i||typeof i!="object"||Array.isArray(i)))for(let[o,a]of Object.entries(i)){let f=t[o];!f||a===f||(i[o]=f,n=!0)}}n&&await Et(e,`${JSON.stringify(r,null,2)}
|
|
9
|
+
`,"utf8")}l(Ft,"pinPackageVersions");async function Yn(e){let t=Vt(e.to??e.config),r=e.cliVersion??"unknown",n=e.from?m.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(m.resolve(n)===m.resolve(t))throw new Error("--from \u4E0E --to \u6307\u5411\u540C\u4E00\u76EE\u5F55\uFF0C\u65E0\u9700\u8FC1\u79FB\u3002");try{await ce(n)}catch{throw new Error(`--from \u6307\u5411\u7684\u6E90\u76EE\u5F55\u4E0D\u5B58\u5728: ${n}`)}}if(e.list){let u=await z(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 p of u)console.log(` ${p.timestamp} CLI ${p.cliVersion} ${p.fullPath}`)}return{plan:We(r)}}if(e.rollback){let u=await z(t);if(u.length===0)throw new Error("\u65E0\u53EF\u7528\u5907\u4EFD\uFF0C\u65E0\u6CD5\u56DE\u6EDA\u3002");let p=u[0];return console.log(`\u56DE\u6EDA\u5230\u5907\u4EFD: ${p.timestamp} (CLI ${p.cliVersion})`),await Me(t,p),console.log(`\u2713 \u56DE\u6EDA\u5B8C\u6210\u3002
|
|
10
|
+
`),{plan:We(r)}}let s=await re(t),i=n?m.basename(n):e.template??s?.template??await At(t),o=e.profile??s?.profile??"default",a=s?.cli_version??await Ot(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 f=await $t(m.join(It.tmpdir(),"migrate-template-"));try{n?await Ye(n,f):await Le(i,f,!0,e.templatesDir,e.templatePackageVersions,o);let u=q(),p=[],M=[],k=new Map;for(let c of u){let h=m.join(t,c),w=m.join(f,c),C,E;try{C=await A(h,"utf8")}catch{}try{E=await A(w,"utf8")}catch{}if(!C&&!E)continue;if(!C&&E){k.set(c,{result:{merged:{},conflicts:[],deprecated:[],newKeys:[],userPreserved:[],templateUpdated:[]},base:{},oursContent:"",theirsContent:E}),p.push({relativePath:c,conflicts:[],deprecated:[],newKeys:[],userPreservedCount:0,templateUpdatedCount:0,noChange:!1});continue}if(C&&!E)continue;let R=$e(c,C);R.content!==void 0&&(C=R.content,M.push(...R.changes));let fe=s?.config_base_contents?.[c],ee=c.endsWith(".json")?te=>JSON.parse(te):te=>J.parse(te)??{},ue=fe?ee(fe):{},Xe=ee(C),He=ee(E),j=he(ue,Xe,He);k.set(c,{result:j,base:ue,oursContent:C,theirsContent:E}),p.push({relativePath:c,conflicts:j.conflicts,deprecated:j.deprecated,newKeys:j.newKeys,userPreservedCount:j.userPreserved.length,templateUpdatedCount:j.templateUpdated.length,noChange:j.conflicts.length===0&&j.newKeys.length===0&&j.deprecated.length===0&&j.userPreserved.length===0&&j.templateUpdated.length===0})}let d=await ie(t),y=await ie(f),S=new Set(d.map(c=>c.relativePath)),v=new Set(y.map(c=>c.relativePath)),P=[];for(let c of d)c.category==="content"&&P.push({relativePath:c.relativePath,action:"preserve"});for(let c of y)c.category==="content"&&!S.has(c.relativePath)&&P.push({relativePath:c.relativePath,action:"add-new"});let g=[];for(let c of y)if(c.category==="template")if(S.has(c.relativePath)){let h=!1,w=s?.config_snapshot;if(w)try{let C=await A(m.join(t,c.relativePath),"utf8"),E=w[c.relativePath];E&&oe(C)!==E&&(h=!0)}catch{}g.push({relativePath:c.relativePath,action:"overwrite",userModified:h})}else g.push({relativePath:c.relativePath,action:"add-new",userModified:!1});let F=[],b;if(v.has("package.json")){let c={},h={};try{c=JSON.parse(await A(m.join(t,"package.json"),"utf8"))}catch{}try{h=JSON.parse(await A(m.join(f,"package.json"),"utf8"))}catch{}b=xe(c,h,e.templatePackageVersions??{}),F.push({relativePath:"package.json",preservedDeps:b.preservedDeps})}for(let c of[".npmrc",".gitignore"])v.has(c)&&F.push({relativePath:c});let $=[];for(let c of d)if(c.category==="template"&&c.relativePath.endsWith("workflow.yml"))try{let w=J.parse(await A(m.join(t,c.relativePath),"utf8")).tracker;if(w?.base_id||w?.table_id){let C=m.dirname(c.relativePath).split("/").pop()??c.relativePath;$.push({workflow:C,baseId:w.base_id??"",tableId:w.table_id??""})}}catch{}let D=await je(m.join(t,".env"),m.join(f,".env.example")),N={templateName:i,profileName:o,oldVersion:a,newVersion:r,...n?{sourceDir:n}:{},configMerges:p,codemods:M,contentFiles:P,templateFiles:g,managedFiles:F,newEnvVars:D,workflowTrackerFields:$};if(De(N),e.dryRun)return Ne(),{plan:N};if(!e.force){let{confirm:c}=await import("@inquirer/prompts");if(!await c({message:"\u786E\u8BA4\u6267\u884C\u8FC1\u79FB\uFF1F",default:!0}))throw new Error("cancelled")}let Z;e.noBackup||(Z=await Se(t,r),console.log(`\u2713 \u5DF2\u5907\u4EFD\u5230: ${Z.fullPath}`));for(let c of u){let h=p.find(R=>R.relativePath===c);if(!h||h.noChange)continue;let w=k.get(c);if(!w)continue;let C=m.join(t,c);if(!w.oursContent&&w.theirsContent){await H(m.dirname(C),{recursive:!0}),await K(C,w.theirsContent,"utf8");continue}if(!w.theirsContent)continue;if(c.endsWith(".json"))await K(C,JSON.stringify(w.result.merged,null,2)+`
|
|
11
|
+
`,"utf8");else{let R=J.parseDocument(w.oursContent);Kt(R,w.base,w.result.merged),await K(C,R.toString(),"utf8")}}for(let c of g){let h=m.join(f,c.relativePath),w=m.join(t,c.relativePath);await H(m.dirname(w),{recursive:!0}),await X(h,w,{force:!0})}for(let c of $){if(!c.baseId&&!c.tableId)continue;let h=g.filter(w=>w.relativePath.endsWith("workflow.yml")&&w.relativePath.includes(c.workflow));for(let w of h){let C=m.join(t,w.relativePath);try{let E=await A(C,"utf8"),R=J.parseDocument(E);c.baseId&&R.setIn(["tracker","base_id"],c.baseId),c.tableId&&R.setIn(["tracker","table_id"],c.tableId),await K(C,R.toString(),"utf8")}catch{}}}if(b){let c=m.join(t,"package.json");await K(c,JSON.stringify(b.merged,null,2)+`
|
|
12
|
+
`,"utf8")}for(let c of[".npmrc",".gitignore"]){let h=m.join(f,c),w=m.join(t,c);try{await ce(h),await X(h,w,{force:!0})}catch{}}for(let c of P){if(c.action!=="add-new")continue;let h=m.join(f,c.relativePath),w=m.join(t,c.relativePath);await H(m.dirname(w),{recursive:!0}),await X(h,w,{force:!1,errorOnExist:!1})}let Q,le=p.flatMap(c=>c.conflicts.map(h=>({file:c.relativePath,...h})));if(le.length>0){Q=m.join(t,".migrate-conflicts.yml");let c=le.map(h=>({file:h.file,path:h.pathString,your_value:h.oursValue,template_value:h.theirsValue,base_value:h.baseValue}));await K(Q,J.stringify(c),"utf8")}let ze=await W(t,u),Ge=await Y(f,u);return await U(t,{schema_version:1,template:i,profile:o,cli_version:r,scaffolded_at:new Date().toISOString(),config_snapshot:ze,config_base_contents:Ge}),await _e(t),Ie(t),{plan:N,backup:Z,conflictFile:Q}}finally{await Nt(f,{recursive:!0,force:!0}).catch(()=>{})}}l(Yn,"runMigrate");async function qn(e,t){try{let r=await re(e);if(!r||r.cli_version===t)return;console.warn(`\u26A0 CLI \u7248\u672C\u5DF2\u4ECE ${r.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(qn,"checkMigrateHint");function Vt(e){if(!e)return process.cwd();let t=m.resolve(e),r=m.extname(t).toLowerCase();return r===".yml"||r===".yaml"?m.dirname(t):t}l(Vt,"resolveConfigDir");var Tt=new Set(["node_modules",".git",".migrate-backup",".migrate-meta.json","traces",".memory",".DS_Store","package-lock.json","pnpm-lock.yaml"]);async function Ye(e,t){let r=await Dt(e,{withFileTypes:!0});await H(t,{recursive:!0});for(let n of r){if(Tt.has(n.name))continue;let s=m.join(e,n.name),i=m.join(t,n.name);n.isDirectory()?await Ye(s,i):n.isFile()&&await X(s,i,{force:!0})}}l(Ye,"copySourceDir");async function At(e){try{return await ce(m.join(e,"workflows")),"support-qa"}catch{return}}l(At,"inferTemplateName");async function Ot(e){try{return JSON.parse(await A(m.join(e,"package.json"),"utf8")).dependencies?.["aitable-workflow-core"]?.replace(/^\^/,"")}catch{return}}l(Ot,"inferCliVersion");function Kt(e,t,r){qe(e,[],t,r)}l(Kt,"applyMergeToDoc");function qe(e,t,r,n){if(Ue(r)&&Ue(n)){let s=new Set([...Object.keys(r),...Object.keys(n)]);for(let i of s){let o=[...t,i];i in n?i in r?qe(e,o,r[i],n[i]):e.setIn(o,n[i]):e.deleteIn(o)}}else Bt(r,n)||e.setIn(t,n)}l(qe,"applyRecursive");function Ue(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}l(Ue,"isPlainObject");function Bt(e,t){return JSON.stringify(e)===JSON.stringify(t)}l(Bt,"deepEqualSimple");function We(e){return{templateName:"",profileName:"",oldVersion:"",newVersion:e,configMerges:[],codemods:[],contentFiles:[],templateFiles:[],managedFiles:[],newEnvVars:[],workflowTrackerFields:[]}}l(We,"emptyPlan");export{l as a,Lt as b,Ke as c,Pt as d,jt as e,bt as f,Le as g,Yn as h,qn as i};
|
package/dist/index.d.ts
CHANGED
|
@@ -2028,6 +2028,8 @@ declare function createPerWorkflowSettings(base: Settings, entry: WorkflowEntry,
|
|
|
2028
2028
|
|
|
2029
2029
|
/** 工作流模板元数据 */
|
|
2030
2030
|
type WorkflowMeta = {
|
|
2031
|
+
/** 可选:多 workflow 项目中通常与 workflows/<id>/ 目录名一致 */
|
|
2032
|
+
id?: string;
|
|
2031
2033
|
name: string;
|
|
2032
2034
|
version: string;
|
|
2033
2035
|
domain: string;
|
|
@@ -7180,14 +7182,19 @@ declare function ensureLatestDws(options?: DwsMaintenanceOptions): Promise<DwsMa
|
|
|
7180
7182
|
* 仓库内知识只存一份,scaffold / bundle 时自动物化。
|
|
7181
7183
|
*/
|
|
7182
7184
|
/**
|
|
7183
|
-
* 映射值:字符串 = 源名全量复制;对象 = 源名 +
|
|
7185
|
+
* 映射值:字符串 = 源名全量复制;对象 = 源名 + 子路径白名单 / 黑名单。
|
|
7186
|
+
*
|
|
7187
|
+
* "wiki/aitable-faq": "aitable-faq" # 全量
|
|
7188
|
+
* "knowledge/aitable-faq": { source: "aitable-faq", include: [".kb"] } # 仅 .kb
|
|
7189
|
+
* "knowledge/aitable-faq/wiki": { source: "aitable-faq/.kb/wiki", exclude: ["log.md"] }
|
|
7184
7190
|
*
|
|
7185
|
-
*
|
|
7186
|
-
*
|
|
7191
|
+
* `include` 是白名单(新增内容默认不复制),`exclude` 是黑名单(新增内容默认复制)。
|
|
7192
|
+
* 描述「这些编译中间产物不要」时用 exclude —— 用 include 会让 taxonomy 新增分类被静默漏掉。
|
|
7187
7193
|
*/
|
|
7188
7194
|
type SharedKnowledgeEntry = string | {
|
|
7189
7195
|
source: string;
|
|
7190
7196
|
include?: string[];
|
|
7197
|
+
exclude?: string[];
|
|
7191
7198
|
};
|
|
7192
7199
|
type SharedKnowledgeMapping = Record<string, SharedKnowledgeEntry>;
|
|
7193
7200
|
/**
|