agentpacks 1.7.13 → 1.8.0
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/api.js +48 -3658
- package/dist/cli/export-cmd.js +7 -1027
- package/dist/cli/generate.js +39 -2731
- package/dist/cli/import-cmd.js +19 -770
- package/dist/cli/info.js +4 -231
- package/dist/cli/init.js +9 -185
- package/dist/cli/install.js +4 -902
- package/dist/cli/login.js +6 -201
- package/dist/cli/models-explain.js +14 -1266
- package/dist/cli/pack/create.js +4 -146
- package/dist/cli/pack/enable.js +2 -65
- package/dist/cli/pack/list.js +5 -893
- package/dist/cli/pack/validate.js +4 -642
- package/dist/cli/publish.js +8 -679
- package/dist/cli/search.js +4 -209
- package/dist/core/config.d.ts +1 -1
- package/dist/core/config.js +1 -145
- package/dist/core/dependency-resolver.js +1 -126
- package/dist/core/feature-merger.js +3 -398
- package/dist/core/index.js +5 -1129
- package/dist/core/lockfile.js +2 -43
- package/dist/core/metarepo.js +1 -183
- package/dist/core/pack-loader.js +4 -841
- package/dist/core/profile-resolver.js +1 -110
- package/dist/exporters/cursor-plugin.js +6 -404
- package/dist/exporters/index.js +6 -404
- package/dist/features/agents.js +3 -161
- package/dist/features/commands.js +3 -161
- package/dist/features/hooks.js +3 -153
- package/dist/features/ignore.js +2 -43
- package/dist/features/index.js +4 -629
- package/dist/features/mcp.js +3 -143
- package/dist/features/models.js +3 -292
- package/dist/features/plugins.js +3 -139
- package/dist/features/rules.d.ts +0 -1
- package/dist/features/rules.js +3 -169
- package/dist/features/skills.js +3 -228
- package/dist/importers/claude-code.js +6 -195
- package/dist/importers/cursor.js +5 -355
- package/dist/importers/opencode.js +6 -346
- package/dist/importers/rulesync.js +5 -365
- package/dist/index.js +89 -4934
- package/dist/node/api.js +48 -3659
- package/dist/node/cli/export-cmd.js +7 -1028
- package/dist/node/cli/generate.js +39 -2732
- package/dist/node/cli/import-cmd.js +19 -771
- package/dist/node/cli/info.js +4 -232
- package/dist/node/cli/init.js +9 -186
- package/dist/node/cli/install.js +4 -903
- package/dist/node/cli/login.js +6 -202
- package/dist/node/cli/models-explain.js +14 -1267
- package/dist/node/cli/pack/create.js +4 -147
- package/dist/node/cli/pack/enable.js +2 -66
- package/dist/node/cli/pack/list.js +5 -894
- package/dist/node/cli/pack/validate.js +4 -643
- package/dist/node/cli/publish.js +8 -680
- package/dist/node/cli/search.js +4 -210
- package/dist/node/core/config.js +1 -146
- package/dist/node/core/dependency-resolver.js +1 -127
- package/dist/node/core/feature-merger.js +3 -399
- package/dist/node/core/index.js +5 -1130
- package/dist/node/core/lockfile.js +2 -44
- package/dist/node/core/metarepo.js +1 -184
- package/dist/node/core/pack-loader.js +4 -842
- package/dist/node/core/profile-resolver.js +1 -111
- package/dist/node/exporters/cursor-plugin.js +6 -405
- package/dist/node/exporters/index.js +6 -405
- package/dist/node/features/agents.js +3 -162
- package/dist/node/features/commands.js +3 -162
- package/dist/node/features/hooks.js +3 -154
- package/dist/node/features/ignore.js +2 -44
- package/dist/node/features/index.js +4 -630
- package/dist/node/features/mcp.js +3 -144
- package/dist/node/features/models.js +3 -293
- package/dist/node/features/plugins.js +3 -140
- package/dist/node/features/rules.js +3 -170
- package/dist/node/features/skills.js +3 -229
- package/dist/node/importers/claude-code.js +6 -196
- package/dist/node/importers/cursor.js +5 -356
- package/dist/node/importers/opencode.js +6 -347
- package/dist/node/importers/rulesync.js +5 -366
- package/dist/node/index.js +89 -4935
- package/dist/node/sources/git-ref.js +1 -56
- package/dist/node/sources/git.js +2 -222
- package/dist/node/sources/index.js +4 -714
- package/dist/node/sources/local.js +1 -24
- package/dist/node/sources/npm-ref.js +1 -56
- package/dist/node/sources/npm.js +2 -184
- package/dist/node/sources/registry-ref.js +1 -37
- package/dist/node/sources/registry.js +4 -355
- package/dist/node/targets/additional-targets.js +6 -587
- package/dist/node/targets/base-target.js +1 -23
- package/dist/node/targets/claude-code.js +6 -714
- package/dist/node/targets/codex-cli.js +3 -324
- package/dist/node/targets/copilot.js +5 -603
- package/dist/node/targets/cursor.js +6 -700
- package/dist/node/targets/gemini-cli.js +10 -319
- package/dist/node/targets/generic-md-target.js +6 -478
- package/dist/node/targets/index.js +32 -1873
- package/dist/node/targets/mistral-vibe.js +7 -661
- package/dist/node/targets/opencode.js +13 -723
- package/dist/node/targets/registry.js +32 -1864
- package/dist/node/utils/credentials.js +3 -38
- package/dist/node/utils/diff.js +5 -132
- package/dist/node/utils/filesystem.js +3 -124
- package/dist/node/utils/frontmatter.js +1 -24
- package/dist/node/utils/global.js +1 -53
- package/dist/node/utils/markdown.js +3 -30
- package/dist/node/utils/model-allowlist.js +1 -126
- package/dist/node/utils/model-guidance.js +2 -78
- package/dist/node/utils/registry-client.js +1 -142
- package/dist/node/utils/tarball.js +1 -49
- package/dist/sources/git-ref.js +1 -55
- package/dist/sources/git.js +2 -221
- package/dist/sources/index.js +4 -713
- package/dist/sources/local.js +1 -23
- package/dist/sources/npm-ref.js +1 -55
- package/dist/sources/npm.js +2 -183
- package/dist/sources/registry-ref.js +1 -36
- package/dist/sources/registry.js +4 -354
- package/dist/targets/additional-targets.js +6 -586
- package/dist/targets/base-target.js +1 -22
- package/dist/targets/claude-code.js +6 -713
- package/dist/targets/codex-cli.js +3 -323
- package/dist/targets/copilot.js +5 -602
- package/dist/targets/cursor.js +6 -699
- package/dist/targets/gemini-cli.js +10 -318
- package/dist/targets/generic-md-target.js +6 -477
- package/dist/targets/index.d.ts +0 -1
- package/dist/targets/index.js +32 -1872
- package/dist/targets/mistral-vibe.js +7 -660
- package/dist/targets/opencode.js +13 -722
- package/dist/targets/registry.js +32 -1863
- package/dist/utils/credentials.js +3 -37
- package/dist/utils/diff.js +5 -131
- package/dist/utils/filesystem.js +3 -123
- package/dist/utils/frontmatter.js +1 -23
- package/dist/utils/global.js +1 -52
- package/dist/utils/markdown.js +3 -29
- package/dist/utils/model-allowlist.js +1 -125
- package/dist/utils/model-guidance.js +2 -77
- package/dist/utils/registry-client.js +1 -141
- package/dist/utils/tarball.js +1 -48
- package/package.json +4 -16
- package/dist/node/targets/agents-md.js +0 -211
- package/dist/targets/agents-md.d.ts +0 -13
- package/dist/targets/agents-md.js +0 -211
package/dist/cli/generate.js
CHANGED
|
@@ -1,2749 +1,57 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var
|
|
2
|
+
var p2=import.meta.require;import{existsSync as k0,readFileSync as D0}from"fs";import{parse as w1}from"jsonc-parser";import{resolve as v0}from"path";import{z as P}from"zod";var z1=["opencode","cursor","claudecode","codexcli","mistralvibe","geminicli","copilot","cline","kilo","roo","qwencode","kiro","factorydroid","antigravity","junie","augmentcode","windsurf","warp","replit","zed"],q0=["rules","commands","agents","skills","hooks","plugins","mcp","ignore","models"],R1=["repo","monorepo","metarepo"],E0=P.object({name:P.string().min(1),version:P.string().default("1.0.0"),description:P.string().default(""),author:P.union([P.string(),P.object({name:P.string(),email:P.string().optional()})]).optional(),homepage:P.string().optional(),repository:P.union([P.string(),P.object({url:P.string(),type:P.string().optional()})]).optional(),license:P.string().optional(),logo:P.string().optional(),tags:P.array(P.string()).default([]),dependencies:P.array(P.string()).default([]),conflicts:P.array(P.string()).default([]),targets:P.union([P.literal("*"),P.array(P.string())]).default("*"),features:P.union([P.literal("*"),P.array(P.string())]).default("*")}),j1=P.union([P.literal("*"),P.array(P.string()),P.record(P.string(),P.union([P.literal("*"),P.array(P.string())]))]),T0=P.object({$schema:P.string().optional(),packs:P.array(P.string()).default(["./packs/default"]),disabled:P.array(P.string()).default([]),targets:P.union([P.literal("*"),P.array(P.string())]).default("*"),features:j1.default("*"),mode:P.enum(R1).default("repo"),baseDirs:P.array(P.string()).default(["."]),global:P.boolean().default(!1),delete:P.boolean().default(!0),verbose:P.boolean().default(!1),silent:P.boolean().default(!1),overrides:P.record(P.string(),P.record(P.string(),P.string())).default({}),sources:P.array(P.object({source:P.string(),packs:P.array(P.string()).optional(),skills:P.array(P.string()).optional()})).default([]),modelProfile:P.string().optional()}),E1=["agentpacks.local.jsonc","agentpacks.jsonc"];function H0($){for(let q of E1){let Y=v0($,q);if(k0(Y)){let Q=D0(Y,"utf-8"),Z=w1(Q);return T0.parse(Z)}}return T0.parse({})}function h0($){let q=v0($,"pack.json");if(!k0(q)){let Z=$.split("/").pop()??"unknown";return E0.parse({name:Z})}let Y=D0(q,"utf-8"),Q=JSON.parse(Y);return E0.parse(Q)}function u0($,q){let{features:Y}=$;if(Y==="*")return[...q0];if(Array.isArray(Y)){if(Y.includes("*"))return[...q0];return Y.filter((Z)=>q0.includes(Z))}let Q=Y[q];if(!Q)return[];if(Q==="*")return[...q0];if(Array.isArray(Q)&&Q.includes("*"))return[...q0];return Q.filter((Z)=>q0.includes(Z))}function m0($){if($.targets==="*")return[...z1];return $.targets}import{existsSync as J0,mkdirSync as T1,readdirSync as g0,readFileSync as k1,rmSync as D1,statSync as p0,writeFileSync as v1}from"fs";import{dirname as h1,join as d0,relative as u1}from"path";var c0="<!-- Generated by agentpacks. DO NOT EDIT. -->",f0="// Generated by agentpacks. DO NOT EDIT.",o0="// Generated by agentpacks. DO NOT EDIT.";function N($,q,Y={}){let{header:Q=!0,type:Z}=Y,V=Z??m1($);b(h1($));let H=q;if(Q){let J=g1(V);if(J)H=`${J}
|
|
3
|
+
${q}`}v1($,H,"utf-8")}function w($,q,Y={}){let Q=JSON.stringify(q,null,2);N($,Q+`
|
|
4
|
+
`,{...Y,type:"json"})}function n0($){if(!J0($))return null;return k1($,"utf-8")}function f($){let q=n0($);if(q===null)return null;return JSON.parse(q)}function b($){if(!J0($))T1($,{recursive:!0})}function S($){if(J0($))D1($,{recursive:!0,force:!0})}function D($,q={}){let{extension:Y,recursive:Q=!1}=q;if(!J0($))return[];let Z=[],V=g0($);for(let H of V){let J=d0($,H),L=p0(J);if(L.isDirectory()&&Q)Z.push(...D(J,q));else if(L.isFile()){if(!Y||H.endsWith(Y))Z.push(J)}}return Z}function l0($){if(!J0($))return[];return g0($).map((q)=>d0($,q)).filter((q)=>p0(q).isDirectory())}function i2($,q){return u1($,q)}function r2($){let q=n0($);if(!q)return!1;return q.startsWith(c0)||q.startsWith(f0)||q.startsWith(o0)}function m1($){if($.endsWith(".json")||$.endsWith(".jsonc"))return"json";if($.endsWith(".ts")||$.endsWith(".mts"))return"ts";if($.endsWith(".js")||$.endsWith(".mjs"))return"js";return"md"}function g1($){switch($){case"md":return c0;case"json":return f0;case"js":case"ts":return o0;default:return null}}import{join as p1}from"path";import{z as x}from"zod";var d1=[/["']api[_-]?key["']\s*:/i,/["']apiKey["']\s*:/i,/["']secret["']\s*:/i,/["']password["']\s*:/i,/["'](?:auth_token|access_token|bearer_token)["']\s*:/i,/["']private[_-]?key["']\s*:/i,/-----BEGIN\s+(RSA|EC|DSA|OPENSSH|PGP)\s+PRIVATE\s+KEY-----/,/sk-[a-zA-Z0-9]{20,}/,/Bearer\s+[a-zA-Z0-9._-]{20,}/],C0=x.object({model:x.string(),temperature:x.number().min(0).max(2).optional(),top_p:x.number().min(0).max(1).optional()}),c1=x.object({extends:x.string().optional(),description:x.string().optional(),default:x.string().optional(),small:x.string().optional(),agents:x.record(x.string(),C0).optional()}),Q3=x.object({complexity:x.enum(["low","medium","high","critical"]).optional().describe("Task complexity level"),urgency:x.enum(["low","normal","high"]).optional().describe("Time sensitivity"),budget:x.enum(["minimal","standard","premium"]).optional().describe("Cost/token budget tier"),contextWindowNeed:x.enum(["small","medium","large","max"]).optional().describe("Required context window size"),toolUseIntensity:x.enum(["none","light","heavy"]).optional().describe("Expected tool/function calling intensity")}),f1=x.object({when:x.record(x.string(),x.string()),use:x.string(),description:x.string().optional(),priority:x.number().optional()}),o1=x.object({options:x.record(x.string(),x.unknown()).optional(),variants:x.record(x.string(),x.record(x.string(),x.unknown())).optional()}),n1=x.object({options:x.record(x.string(),x.unknown()).optional(),models:x.record(x.string(),o1).optional()}),l1=x.object({default:x.string().optional(),small:x.string().optional(),agents:x.record(x.string(),C0).optional(),profiles:x.record(x.string(),c1).optional(),providers:x.record(x.string(),n1).optional(),routing:x.array(f1).optional(),overrides:x.record(x.string(),x.object({default:x.string().optional(),small:x.string().optional(),agents:x.record(x.string(),C0).optional()})).optional()});function a0($,q){let Y=p1($,"models.json"),Q=f(Y);if(!Q)return null;let Z=l1.parse(Q);return{packName:q,sourcePath:Y,config:Z}}function s0($){let q=[],Y={};for(let Q of $){let{config:Z,packName:V}=Q;if(Z.default!==void 0&&Y.default===void 0)Y.default=Z.default;else if(Z.default!==void 0&&Y.default!==void 0)q.push(`Models "default" from pack "${V}" skipped (already defined).`);if(Z.small!==void 0&&Y.small===void 0)Y.small=Z.small;else if(Z.small!==void 0&&Y.small!==void 0)q.push(`Models "small" from pack "${V}" skipped (already defined).`);if(Z.agents){if(!Y.agents)Y.agents={};for(let[H,J]of Object.entries(Z.agents)){if(H in Y.agents){q.push(`Models agent "${H}" from pack "${V}" skipped (already defined).`);continue}Y.agents[H]=J}}if(Z.profiles){if(!Y.profiles)Y.profiles={};for(let[H,J]of Object.entries(Z.profiles)){if(H in Y.profiles){q.push(`Models profile "${H}" from pack "${V}" skipped (already defined).`);continue}Y.profiles[H]=J}}if(Z.providers){if(!Y.providers)Y.providers={};for(let[H,J]of Object.entries(Z.providers))if(!(H in Y.providers))Y.providers[H]=J;else{let L=Y.providers[H];if(!L){Y.providers[H]=J;continue}if(J.options)L.options={...J.options,...L.options};if(J.models){if(!L.models)L.models={};for(let[W,F]of Object.entries(J.models))if(!(W in L.models))L.models[W]=F}}}if(Z.routing){if(!Y.routing)Y.routing=[];Y.routing.push(...Z.routing)}if(Z.overrides){if(!Y.overrides)Y.overrides={};for(let[H,J]of Object.entries(Z.overrides)){if(H in Y.overrides){q.push(`Models override for target "${H}" from pack "${V}" skipped (already defined).`);continue}Y.overrides[H]=J}}}return{config:Y,warnings:q}}function Y3($){let q=[],Y=JSON.stringify($);for(let Q of d1)if(Q.test(Y))q.push(`Potential secret detected in models.json matching pattern: ${Q.source}`);return q}class A0{packs;warnings=[];constructor($){this.packs=$}merge(){return this.warnings=[],{features:{rules:this.mergeRules(),commands:this.mergeByName("commands"),agents:this.mergeByName("agents"),skills:this.mergeByName("skills"),hooks:this.mergeHooks(),plugins:this.mergePlugins(),mcpServers:this.mergeMcp(),ignorePatterns:this.mergeIgnore(),models:this.mergeModels()},warnings:this.warnings}}mergeRules(){let $=new Map,q=[];for(let Y of this.packs)for(let Q of Y.rules){let Z=$.get(Q.name);if(Z){this.warnings.push(`Rule "${Q.name}" from pack "${Q.packName}" skipped (already defined by "${Z}").`);continue}$.set(Q.name,Q.packName),q.push(Q)}return q}mergeByName($){let q=new Map,Y=[];for(let Q of this.packs){let Z=Q[$];for(let V of Z){let H=q.get(V.name);if(H){this.warnings.push(`${$.slice(0,-1)} "${V.name}" from pack "${V.packName}" skipped (already defined by "${H}").`);continue}q.set(V.name,V.packName),Y.push(V)}}return Y}mergeHooks(){return this.packs.map(($)=>$.hooks).filter(($)=>$!==null)}mergePlugins(){let $=new Map,q=[];for(let Y of this.packs)for(let Q of Y.plugins){let Z=`${Q.name}.${Q.extension}`,V=$.get(Z);if(V){this.warnings.push(`Plugin "${Z}" from pack "${Q.packName}" skipped (already defined by "${V}").`);continue}$.set(Z,Q.packName),q.push(Q)}return q}mergeMcp(){let $={};for(let q of this.packs){if(!q.mcp)continue;for(let[Y,Q]of Object.entries(q.mcp.servers)){if(Y in $){this.warnings.push(`MCP server "${Y}" from pack "${q.manifest.name}" skipped (already defined).`);continue}$[Y]=Q}}return $}mergeIgnore(){let $=new Set,q=[];for(let Y of this.packs){if(!Y.ignore)continue;for(let Q of Y.ignore.patterns)if(!$.has(Q))$.add(Q),q.push(Q)}return q}mergeModels(){let $=this.packs.map((Q)=>Q.models).filter((Q)=>Q!=null);if($.length===0)return null;let{config:q,warnings:Y}=s0($);return this.warnings.push(...Y),q}}import i0 from"gray-matter";function g($){let{data:q,content:Y}=i0($);return{data:q,content:Y.trim(),raw:$}}function p($,q){let Y=Object.fromEntries(Object.entries($).filter(([,Q])=>Q!==void 0));if(Object.keys(Y).length===0)return q;return i0.stringify(q,Y)}import{readFileSync as a1}from"fs";import{basename as s1}from"path";function r0($,q){return D($,{extension:".md"}).map((Q)=>i1(Q,q))}function i1($,q){let Y=a1($,"utf-8"),{data:Q,content:Z}=g(Y);return{name:Q.name??s1($,".md"),sourcePath:$,packName:q,meta:Q,content:Z}}function v($,q){let{targets:Y}=$.meta;if(!Y||Y==="*")return!0;if(Array.isArray(Y)&&Y.includes("*"))return!0;return Array.isArray(Y)&&Y.includes(q)}import{readFileSync as r1}from"fs";import{basename as t1}from"path";function t0($,q){return D($,{extension:".md"}).map((Q)=>e1(Q,q))}function e1($,q){let Y=r1($,"utf-8"),{data:Q,content:Z}=g(Y);return{name:t1($,".md"),sourcePath:$,packName:q,meta:Q,content:Z}}function j($,q){let{targets:Y}=$.meta;if(!Y||Y==="*")return!0;if(Array.isArray(Y)&&Y.includes("*"))return!0;return Array.isArray(Y)&&Y.includes(q)}import{join as $2}from"path";var q2=["cursor","claudecode","codexcli","opencode"];function e0($,q){let Y=$2($,"hooks","hooks.json"),Q=f(Y);if(!Q)return null;let Z=Q.hooks??{},V={};for(let H of q2){let J=Q[H];if(J&&typeof J==="object"&&"hooks"in J&&J.hooks)V[H]=J.hooks}return{packName:q,sourcePath:Y,version:Q.version,shared:Z,targetOverrides:V}}function o($,q){let Y={};for(let[Z,V]of Object.entries($.shared))Y[Z]=[...V];let Q=$.targetOverrides[q];if(Q)for(let[Z,V]of Object.entries(Q))Y[Z]=[...Y[Z]??[],...V];return Y}import{existsSync as Q2,readFileSync as Y2}from"fs";import{join as Z2}from"path";var X2=["ignore",".aiignore"];function $1($,q){for(let Y of X2){let Q=Z2($,Y);if(Q2(Q)){let Z=Y2(Q,"utf-8"),V=U2(Z);return{packName:q,sourcePath:Q,patterns:V}}}return null}function U2($){return $.split(`
|
|
5
|
+
`).map((q)=>q.trim()).filter((q)=>q.length>0&&!q.startsWith("#"))}function S3($){let q=new Set,Y=[];for(let Q of $)for(let Z of Q.patterns)if(!q.has(Z))q.add(Z),Y.push(Z);return Y}import{join as V2}from"path";function q1($,q){let Y=V2($,"mcp.json"),Q=f(Y);if(!Q?.mcpServers)return null;return{packName:q,sourcePath:Y,servers:Q.mcpServers}}function w3($){let q={},Y=[];for(let Q of $)for(let[Z,V]of Object.entries(Q.servers)){if(Z in q){Y.push(`MCP server "${Z}" from pack "${Q.packName}" skipped (already defined).`);continue}q[Z]=V}return{servers:q,warnings:Y}}import{existsSync as B2,readFileSync as K2}from"fs";import{basename as J2,join as O2}from"path";function Q1($,q){let Y=O2($,"plugins");if(!B2(Y))return[];let Q=D(Y,{extension:".ts"}),Z=D(Y,{extension:".js"});return[...Q,...Z].map((H)=>L2(H,q))}function L2($,q){let Y=K2($,"utf-8"),Q=$.endsWith(".ts")?"ts":"js";return{name:J2($,`.${Q}`),sourcePath:$,packName:q,content:Y,extension:Q}}import{readFileSync as H2}from"fs";import{basename as W2}from"path";function Y1($,q){return D($,{extension:".md"}).map((Q)=>P2(Q,q))}function P2($,q){let Y=H2($,"utf-8"),{data:Q,content:Z}=g(Y);return{name:W2($,".md"),sourcePath:$,packName:q,meta:Q,content:Z}}function z($,q){let{targets:Y}=$.meta;if(!Y||Y==="*")return!0;if(Array.isArray(Y)&&Y.includes("*"))return!0;return Array.isArray(Y)&&Y.includes(q)}function W0($){return $.filter((q)=>q.meta.root===!0)}function Q0($){return $.filter((q)=>q.meta.root!==!0)}import{existsSync as _2,readFileSync as C2}from"fs";import{basename as X1,join as A2}from"path";var x2=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,Z1=64;function U1($,q){let Y=l0($),Q=[];for(let Z of Y){let V=A2(Z,"SKILL.md");if(_2(V))Q.push(N2(V,Z,q))}return Q}function N2($,q,Y){let Q=C2($,"utf-8"),{data:Z,content:V}=g(Q);return{name:Z.name??X1(q),sourcePath:$,sourceDir:q,packName:Y,meta:Z,content:V}}function b2($){return{...$.meta,name:$.name}}function T($){return p(b2($),$.content)}function c3($,q){let{data:Y,content:Q}=g($),Z={...Y,name:q},V=!1,H=Z.description;if(typeof H!=="string"||H.trim().length===0)Z.description=`Imported skill: ${q}`,V=!0;return{content:p(Z,Q),addedDescription:V}}function f3($){let q=[],Y=X1($.sourceDir),Q=$.meta.name;if(typeof Q!=="string"||Q.trim().length===0)q.push('Missing required frontmatter field "name".');else{if(Q.length>Z1)q.push(`Invalid "name": must be at most ${Z1} characters.`);if(!x2.test(Q))q.push('Invalid "name": use lowercase letters, numbers, and single hyphens only.');if(Q!==Y)q.push(`Invalid "name": must match containing directory "${Y}".`)}let Z=$.meta.description;if(typeof Z!=="string"||Z.trim().length===0)q.push('Missing required frontmatter field "description".');let V=$.meta["allowed-tools"];if(V!==void 0&&(!Array.isArray(V)||V.some((H)=>typeof H!=="string"||H.length===0)))q.push('Invalid "allowed-tools": expected an array of non-empty strings.');return q}function k($,q){let{targets:Y}=$.meta;if(!Y||Y==="*")return!0;if(Array.isArray(Y)&&Y.includes("*"))return!0;return Array.isArray(Y)&&Y.includes(q)}import{existsSync as r}from"fs";import{isAbsolute as I2,resolve as h}from"path";class P0{projectRoot;config;constructor($,q){this.projectRoot=$,this.config=q}loadAll(){let $=[],q=[],Y=new Set(this.config.disabled);for(let Q of this.config.packs){let Z=this.resolvePackPath(Q);if(!Z){$.push(`Pack "${Q}" could not be resolved. Skipping.`);continue}if(!r(Z)){$.push(`Pack directory "${Z}" does not exist. Skipping.`);continue}let V=h0(Z);if(Y.has(V.name)||Y.has(Q))continue;let H=this.loadPack(Z,V);q.push(H)}return{packs:q,warnings:$}}loadPack($,q){let Y=q.name,Q=h($,"rules"),Z=h($,"commands"),V=h($,"agents"),H=h($,"skills");return{manifest:q,directory:$,rules:r(Q)?Y1(Q,Y):[],commands:r(Z)?t0(Z,Y):[],agents:r(V)?r0(V,Y):[],skills:r(H)?U1(H,Y):[],hooks:e0($,Y),plugins:Q1($,Y),mcp:q1($,Y),ignore:$1($,Y),models:a0($,Y)}}loadForBaseDir($){let q=h(this.projectRoot,$),Y=h(q,"agentpacks.jsonc");if(!r(Y))return{packs:[],warnings:[]};let Q=H0(q);return new P0(q,Q).loadAll()}resolveCuratedPack($){let q=h(this.projectRoot,".agentpacks",".curated"),Y=$;if(Y.startsWith("registry:"))Y=Y.slice(9);if(Y.startsWith("npm:"))Y=Y.slice(4);if(Y.startsWith("github:"))Y=Y.slice(7);if(Y.startsWith("@"))Y=Y.slice(1);if(Y.includes("/")){let V=Y.split("/");Y=Y.includes("@")?V.join("-"):V[V.length-1]??Y}let Q=Y.split("@")[0]??Y;Y=Q.split(":")[0]??Q;let Z=h(q,Y);return r(Z)?Z:null}resolvePackPath($){if($.startsWith("./")||$.startsWith("../"))return h(this.projectRoot,$);if(I2($))return $;if($.startsWith("registry:"))return this.resolveCuratedPack($);if($.startsWith("@")||$.startsWith("npm:")||!$.includes("/"))return this.resolveCuratedPack($);if($.startsWith("github:")||$.includes("/"))return this.resolveCuratedPack($);return h(this.projectRoot,$)}}function R($,q,Y){let{default:Q,small:Z}=$,V={...$.agents};if(q&&$.profiles?.[q]){let W=F2(q,$.profiles);if(W.default)Q=W.default;if(W.small)Z=W.small;if(W.agents)V={...V,...W.agents}}if(Y){let W=$.overrides?.[Y];if(W){if(W.default)Q=W.default;if(W.small)Z=W.small;if(W.agents)V={...V,...W.agents}}}let H={};if($.providers)for(let[W,F]of Object.entries($.providers))H[W]={...F.options?{options:F.options}:{},...F.models?{models:F.models}:{}};let J=Object.keys($.profiles??{}),L={};if($.profiles)for(let[W,F]of Object.entries($.profiles))L[W]={description:F.description,default:F.default,small:F.small};return{default:Q,small:Z,agents:V,providers:H,routing:$.routing??[],profileNames:J,activeProfile:q,profiles:L}}function X5($,q,Y){let Q=$.agents[q];if(Q)return{model:Q.model,temperature:Q.temperature,top_p:Q.top_p};if(Y)return{model:Y};return{}}function F2($,q){return B1($,q,new Set,0)}var V1=10;function B1($,q,Y,Q){if(Q>V1)throw Error(`Profile inheritance too deep (max ${V1}): ${$}`);if(Y.has($))throw Error(`Circular profile inheritance detected: ${[...Y,$].join(" \u2192 ")}`);let Z=q[$];if(!Z)throw Error(`Profile "${$}" not found`);if(Y.add($),!Z.extends)return{...Z};let V=B1(Z.extends,q,Y,Q+1);return{description:Z.description??V.description,default:Z.default??V.default,small:Z.small??V.small,agents:{...V.agents,...Z.agents}}}function n($){if(!$.default&&!$.small&&Object.keys($.agents).length===0&&Object.keys($.profiles).length===0)return null;let q=[];if(q.push("# Model Configuration"),q.push(""),q.push("Use the following model preferences when working in this project."),q.push(""),$.default||$.small){if(q.push("## Default Models"),q.push(""),$.default)q.push(`- **Primary model**: ${$.default}`);if($.small)q.push(`- **Lightweight tasks** (titles, summaries): ${$.small}`);q.push("")}let Y=Object.entries($.agents);if(Y.length>0){q.push("## Agent Model Assignments"),q.push(""),q.push("| Agent | Model | Temperature |"),q.push("| --- | --- | --- |");for(let[Q,Z]of Y){let V=Z.temperature!==void 0?String(Z.temperature):"\u2014";q.push(`| ${Q} | ${Z.model} | ${V} |`)}q.push("")}if(Object.keys($.profiles).length>0){q.push("## Available Profiles"),q.push(""),q.push("| Profile | Description | Default Model |"),q.push("| --- | --- | --- |");for(let[Q,Z]of Object.entries($.profiles))q.push(`| ${Q} | ${Z.description??"\u2014"} | ${Z.default??"\u2014"} |`);q.push("")}if($.activeProfile)q.push(`**Active profile**: \`${$.activeProfile}\``),q.push("");if($.routing.length>0){q.push("## Task-Aware Routing"),q.push(""),q.push("Select the appropriate profile based on the task context:"),q.push(""),q.push("| Condition | Profile | Description |"),q.push("| --- | --- | --- |");for(let Q of $.routing){let Z=Object.entries(Q.when).map(([H,J])=>`${H}=${J}`).join(", "),V=Q.description??"\u2014";q.push(`| ${Z} | ${Q.use} | ${V} |`)}q.push(""),q.push("### Condition Reference"),q.push(""),q.push("- **complexity**: low | medium | high | critical"),q.push("- **urgency**: low | normal | high"),q.push("- **budget**: minimal | standard | premium"),q.push("- **contextWindowNeed**: small | medium | large | max"),q.push("- **toolUseIntensity**: none | light | heavy"),q.push("")}return q.join(`
|
|
6
|
+
`)}class y{supportsFeature($){return this.supportedFeatures.includes($)}getEffectiveFeatures($){return $.filter((q)=>this.supportsFeature(q))}createResult($=[],q=[],Y=[]){return{targetId:this.id,filesWritten:$,filesDeleted:q,warnings:Y}}}import{join as x0,resolve as Y0}from"path";function E($){return new K1($)}class K1 extends y{id;name;supportedFeatures;config;constructor($){super();this.id=$.id,this.name=$.name,this.supportedFeatures=$.supportedFeatures,this.config=$}generate($){let{projectRoot:q,baseDir:Y,features:Q,enabledFeatures:Z,deleteExisting:V}=$,H=Y0(q,Y),J=this.getEffectiveFeatures(Z),L=[],W=[],F=[],C=Y0(H,this.config.configDir),B=this.config.rulesDir??"rules",O=this.config.ruleExtension??".md";if(J.includes("rules")){let X=Y0(C,B);if(V)S(X),W.push(X);b(X);let U=Q.rules.filter((K)=>z(K,this.id));for(let K of U){let _=x0(X,`${K.name}${O}`);N(_,K.content),L.push(_)}}if(J.includes("commands")){let X=Y0(C,"commands");if(V)S(X),W.push(X);b(X);let U=Q.commands.filter((K)=>j(K,this.id));for(let K of U){let _=x0(X,`${K.name}.md`);N(_,K.content),L.push(_)}}if(J.includes("mcp")){if(Object.entries(Q.mcpServers).length>0){let U=this.config.mcpInConfigDir?C:H,K=Y0(U,"mcp.json");w(K,{mcpServers:Q.mcpServers},{header:!1}),L.push(K)}}if(J.includes("ignore")&&this.config.ignoreFile){if(Q.ignorePatterns.length>0){let X=Y0(H,this.config.ignoreFile);N(X,Q.ignorePatterns.join(`
|
|
7
|
+
`)+`
|
|
8
|
+
`),L.push(X)}}if(J.includes("models")&&Q.models){let X=R(Q.models,$.modelProfile,this.id),U=n(X);if(U){b(C);let K=x0(C,"model-config.md");N(K,U),L.push(K)}}return this.createResult(L,W,F)}}var J1=E({id:"cline",name:"Cline",configDir:".cline",supportedFeatures:["rules","commands","mcp","ignore"],ignoreFile:".clineignore",mcpInConfigDir:!0}),O1=E({id:"kilo",name:"Kilo Code",configDir:".kilo",supportedFeatures:["rules","commands","mcp","ignore"],ignoreFile:".kiloignore",mcpInConfigDir:!0}),L1=E({id:"roo",name:"Roo Code",configDir:".roo",supportedFeatures:["rules","commands","mcp","ignore"],ignoreFile:".rooignore",mcpInConfigDir:!0}),H1=E({id:"qwencode",name:"Qwen Code",configDir:".qwencode",supportedFeatures:["rules","mcp","ignore"],ignoreFile:".qwencodeignore",mcpInConfigDir:!0}),W1=E({id:"kiro",name:"Kiro",configDir:".kiro",supportedFeatures:["rules","mcp"],mcpInConfigDir:!0}),P1=E({id:"factorydroid",name:"Factory Droid",configDir:".factorydroid",supportedFeatures:["rules","mcp"],mcpInConfigDir:!0}),_1=E({id:"antigravity",name:"AntiGravity",configDir:".antigravity",supportedFeatures:["rules","mcp"],mcpInConfigDir:!0}),C1=E({id:"junie",name:"Junie",configDir:".junie",supportedFeatures:["rules","mcp"],mcpInConfigDir:!0}),A1=E({id:"augmentcode",name:"Augment Code",configDir:".augmentcode",supportedFeatures:["rules","mcp"],mcpInConfigDir:!0}),x1=E({id:"windsurf",name:"Windsurf",configDir:".windsurf",supportedFeatures:["rules","mcp","ignore"],ignoreFile:".windsurfignore",mcpInConfigDir:!0}),N1=E({id:"warp",name:"Warp",configDir:".warp",supportedFeatures:["rules"]}),b1=E({id:"replit",name:"Replit Agent",configDir:".replit",supportedFeatures:["rules","mcp"],mcpInConfigDir:!0}),I1=E({id:"zed",name:"Zed",configDir:".zed",supportedFeatures:["rules","mcp"],mcpInConfigDir:!0});import{join as Z0,resolve as d}from"path";var l="claudecode";class N0 extends y{id=l;name="Claude Code";supportedFeatures=["rules","commands","agents","skills","hooks","mcp","ignore","models"];generate($){let{projectRoot:q,baseDir:Y,features:Q,enabledFeatures:Z,deleteExisting:V}=$,H=d(q,Y),J=this.getEffectiveFeatures(Z),L=[],W=[],F=[],C=d(H,".claude");if(J.includes("rules")){let B=d(C,"rules");if(V)S(B),W.push(B);b(B);let O=Q.rules.filter((K)=>z(K,l)),X=W0(O),U=Q0(O);if(X.length>0){let K=X.map((A)=>A.content).join(`
|
|
3
9
|
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
import { parse as parseJsonc } from "jsonc-parser";
|
|
7
|
-
import { resolve } from "path";
|
|
8
|
-
import { z } from "zod";
|
|
9
|
-
var TARGET_IDS = [
|
|
10
|
-
"opencode",
|
|
11
|
-
"cursor",
|
|
12
|
-
"claudecode",
|
|
13
|
-
"codexcli",
|
|
14
|
-
"mistralvibe",
|
|
15
|
-
"geminicli",
|
|
16
|
-
"copilot",
|
|
17
|
-
"agentsmd",
|
|
18
|
-
"cline",
|
|
19
|
-
"kilo",
|
|
20
|
-
"roo",
|
|
21
|
-
"qwencode",
|
|
22
|
-
"kiro",
|
|
23
|
-
"factorydroid",
|
|
24
|
-
"antigravity",
|
|
25
|
-
"junie",
|
|
26
|
-
"augmentcode",
|
|
27
|
-
"windsurf",
|
|
28
|
-
"warp",
|
|
29
|
-
"replit",
|
|
30
|
-
"zed"
|
|
31
|
-
];
|
|
32
|
-
var FEATURE_IDS = [
|
|
33
|
-
"rules",
|
|
34
|
-
"commands",
|
|
35
|
-
"agents",
|
|
36
|
-
"skills",
|
|
37
|
-
"hooks",
|
|
38
|
-
"plugins",
|
|
39
|
-
"mcp",
|
|
40
|
-
"ignore",
|
|
41
|
-
"models"
|
|
42
|
-
];
|
|
43
|
-
var REPO_MODES = ["repo", "monorepo", "metarepo"];
|
|
44
|
-
var PackManifestSchema = z.object({
|
|
45
|
-
name: z.string().min(1),
|
|
46
|
-
version: z.string().default("1.0.0"),
|
|
47
|
-
description: z.string().default(""),
|
|
48
|
-
author: z.union([
|
|
49
|
-
z.string(),
|
|
50
|
-
z.object({ name: z.string(), email: z.string().optional() })
|
|
51
|
-
]).optional(),
|
|
52
|
-
homepage: z.string().optional(),
|
|
53
|
-
repository: z.union([
|
|
54
|
-
z.string(),
|
|
55
|
-
z.object({ url: z.string(), type: z.string().optional() })
|
|
56
|
-
]).optional(),
|
|
57
|
-
license: z.string().optional(),
|
|
58
|
-
logo: z.string().optional(),
|
|
59
|
-
tags: z.array(z.string()).default([]),
|
|
60
|
-
dependencies: z.array(z.string()).default([]),
|
|
61
|
-
conflicts: z.array(z.string()).default([]),
|
|
62
|
-
targets: z.union([z.literal("*"), z.array(z.string())]).default("*"),
|
|
63
|
-
features: z.union([z.literal("*"), z.array(z.string())]).default("*")
|
|
64
|
-
});
|
|
65
|
-
var FeaturesSchema = z.union([
|
|
66
|
-
z.literal("*"),
|
|
67
|
-
z.array(z.string()),
|
|
68
|
-
z.record(z.string(), z.union([z.literal("*"), z.array(z.string())]))
|
|
69
|
-
]);
|
|
70
|
-
var WorkspaceConfigSchema = z.object({
|
|
71
|
-
$schema: z.string().optional(),
|
|
72
|
-
packs: z.array(z.string()).default(["./packs/default"]),
|
|
73
|
-
disabled: z.array(z.string()).default([]),
|
|
74
|
-
targets: z.union([z.literal("*"), z.array(z.string())]).default("*"),
|
|
75
|
-
features: FeaturesSchema.default("*"),
|
|
76
|
-
mode: z.enum(REPO_MODES).default("repo"),
|
|
77
|
-
baseDirs: z.array(z.string()).default(["."]),
|
|
78
|
-
global: z.boolean().default(false),
|
|
79
|
-
delete: z.boolean().default(true),
|
|
80
|
-
verbose: z.boolean().default(false),
|
|
81
|
-
silent: z.boolean().default(false),
|
|
82
|
-
overrides: z.record(z.string(), z.record(z.string(), z.string())).default({}),
|
|
83
|
-
sources: z.array(z.object({
|
|
84
|
-
source: z.string(),
|
|
85
|
-
packs: z.array(z.string()).optional(),
|
|
86
|
-
skills: z.array(z.string()).optional()
|
|
87
|
-
})).default([]),
|
|
88
|
-
modelProfile: z.string().optional()
|
|
89
|
-
});
|
|
90
|
-
var CONFIG_FILES = ["agentpacks.local.jsonc", "agentpacks.jsonc"];
|
|
91
|
-
function loadWorkspaceConfig(projectRoot) {
|
|
92
|
-
for (const filename of CONFIG_FILES) {
|
|
93
|
-
const filepath = resolve(projectRoot, filename);
|
|
94
|
-
if (existsSync(filepath)) {
|
|
95
|
-
const raw = readFileSync(filepath, "utf-8");
|
|
96
|
-
const parsed = parseJsonc(raw);
|
|
97
|
-
return WorkspaceConfigSchema.parse(parsed);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
return WorkspaceConfigSchema.parse({});
|
|
101
|
-
}
|
|
102
|
-
function loadPackManifest(packDir) {
|
|
103
|
-
const filepath = resolve(packDir, "pack.json");
|
|
104
|
-
if (!existsSync(filepath)) {
|
|
105
|
-
const dirName = packDir.split("/").pop() ?? "unknown";
|
|
106
|
-
return PackManifestSchema.parse({ name: dirName });
|
|
107
|
-
}
|
|
108
|
-
const raw = readFileSync(filepath, "utf-8");
|
|
109
|
-
const parsed = JSON.parse(raw);
|
|
110
|
-
return PackManifestSchema.parse(parsed);
|
|
111
|
-
}
|
|
112
|
-
function resolveFeatures(config, targetId) {
|
|
113
|
-
const { features } = config;
|
|
114
|
-
if (features === "*") {
|
|
115
|
-
return [...FEATURE_IDS];
|
|
116
|
-
}
|
|
117
|
-
if (Array.isArray(features)) {
|
|
118
|
-
if (features.includes("*"))
|
|
119
|
-
return [...FEATURE_IDS];
|
|
120
|
-
return features.filter((f) => FEATURE_IDS.includes(f));
|
|
121
|
-
}
|
|
122
|
-
const targetFeatures = features[targetId];
|
|
123
|
-
if (!targetFeatures)
|
|
124
|
-
return [];
|
|
125
|
-
if (targetFeatures === "*")
|
|
126
|
-
return [...FEATURE_IDS];
|
|
127
|
-
if (Array.isArray(targetFeatures) && targetFeatures.includes("*"))
|
|
128
|
-
return [...FEATURE_IDS];
|
|
129
|
-
return targetFeatures.filter((f) => FEATURE_IDS.includes(f));
|
|
130
|
-
}
|
|
131
|
-
function resolveTargets(config) {
|
|
132
|
-
if (config.targets === "*")
|
|
133
|
-
return [...TARGET_IDS];
|
|
134
|
-
return config.targets;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// src/utils/filesystem.ts
|
|
138
|
-
import {
|
|
139
|
-
existsSync as existsSync2,
|
|
140
|
-
mkdirSync,
|
|
141
|
-
readdirSync,
|
|
142
|
-
readFileSync as readFileSync2,
|
|
143
|
-
rmSync,
|
|
144
|
-
statSync,
|
|
145
|
-
writeFileSync
|
|
146
|
-
} from "fs";
|
|
147
|
-
import { dirname, join, relative } from "path";
|
|
148
|
-
var GENERATED_HEADER_MD = "<!-- Generated by agentpacks. DO NOT EDIT. -->";
|
|
149
|
-
var GENERATED_HEADER_JSON = "// Generated by agentpacks. DO NOT EDIT.";
|
|
150
|
-
var GENERATED_HEADER_JS = "// Generated by agentpacks. DO NOT EDIT.";
|
|
151
|
-
function writeGeneratedFile(filepath, content, options = {}) {
|
|
152
|
-
const { header = true, type } = options;
|
|
153
|
-
const ext = type ?? inferFileType(filepath);
|
|
154
|
-
ensureDir(dirname(filepath));
|
|
155
|
-
let output = content;
|
|
156
|
-
if (header) {
|
|
157
|
-
const headerComment = getHeader(ext);
|
|
158
|
-
if (headerComment) {
|
|
159
|
-
output = `${headerComment}
|
|
160
|
-
${content}`;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
writeFileSync(filepath, output, "utf-8");
|
|
164
|
-
}
|
|
165
|
-
function writeGeneratedJson(filepath, data, options = {}) {
|
|
166
|
-
const json = JSON.stringify(data, null, 2);
|
|
167
|
-
writeGeneratedFile(filepath, json + `
|
|
168
|
-
`, { ...options, type: "json" });
|
|
169
|
-
}
|
|
170
|
-
function readFileOrNull(filepath) {
|
|
171
|
-
if (!existsSync2(filepath))
|
|
172
|
-
return null;
|
|
173
|
-
return readFileSync2(filepath, "utf-8");
|
|
174
|
-
}
|
|
175
|
-
function readJsonOrNull(filepath) {
|
|
176
|
-
const content = readFileOrNull(filepath);
|
|
177
|
-
if (content === null)
|
|
178
|
-
return null;
|
|
179
|
-
return JSON.parse(content);
|
|
180
|
-
}
|
|
181
|
-
function ensureDir(dirPath) {
|
|
182
|
-
if (!existsSync2(dirPath)) {
|
|
183
|
-
mkdirSync(dirPath, { recursive: true });
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
function removeIfExists(targetPath) {
|
|
187
|
-
if (existsSync2(targetPath)) {
|
|
188
|
-
rmSync(targetPath, { recursive: true, force: true });
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
function listFiles(dirPath, options = {}) {
|
|
192
|
-
const { extension, recursive = false } = options;
|
|
193
|
-
if (!existsSync2(dirPath))
|
|
194
|
-
return [];
|
|
195
|
-
const results = [];
|
|
196
|
-
const entries = readdirSync(dirPath);
|
|
197
|
-
for (const entry of entries) {
|
|
198
|
-
const fullPath = join(dirPath, entry);
|
|
199
|
-
const stat = statSync(fullPath);
|
|
200
|
-
if (stat.isDirectory() && recursive) {
|
|
201
|
-
results.push(...listFiles(fullPath, options));
|
|
202
|
-
} else if (stat.isFile()) {
|
|
203
|
-
if (!extension || entry.endsWith(extension)) {
|
|
204
|
-
results.push(fullPath);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
return results;
|
|
209
|
-
}
|
|
210
|
-
function listDirs(dirPath) {
|
|
211
|
-
if (!existsSync2(dirPath))
|
|
212
|
-
return [];
|
|
213
|
-
return readdirSync(dirPath).map((entry) => join(dirPath, entry)).filter((fullPath) => statSync(fullPath).isDirectory());
|
|
214
|
-
}
|
|
215
|
-
function relPath(projectRoot, filepath) {
|
|
216
|
-
return relative(projectRoot, filepath);
|
|
217
|
-
}
|
|
218
|
-
function isGeneratedFile(filepath) {
|
|
219
|
-
const content = readFileOrNull(filepath);
|
|
220
|
-
if (!content)
|
|
221
|
-
return false;
|
|
222
|
-
return content.startsWith(GENERATED_HEADER_MD) || content.startsWith(GENERATED_HEADER_JSON) || content.startsWith(GENERATED_HEADER_JS);
|
|
223
|
-
}
|
|
224
|
-
function inferFileType(filepath) {
|
|
225
|
-
if (filepath.endsWith(".json") || filepath.endsWith(".jsonc"))
|
|
226
|
-
return "json";
|
|
227
|
-
if (filepath.endsWith(".ts") || filepath.endsWith(".mts"))
|
|
228
|
-
return "ts";
|
|
229
|
-
if (filepath.endsWith(".js") || filepath.endsWith(".mjs"))
|
|
230
|
-
return "js";
|
|
231
|
-
return "md";
|
|
232
|
-
}
|
|
233
|
-
function getHeader(type) {
|
|
234
|
-
switch (type) {
|
|
235
|
-
case "md":
|
|
236
|
-
return GENERATED_HEADER_MD;
|
|
237
|
-
case "json":
|
|
238
|
-
return GENERATED_HEADER_JSON;
|
|
239
|
-
case "js":
|
|
240
|
-
case "ts":
|
|
241
|
-
return GENERATED_HEADER_JS;
|
|
242
|
-
default:
|
|
243
|
-
return null;
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
// src/features/models.ts
|
|
248
|
-
import { join as join2 } from "path";
|
|
249
|
-
import { z as z2 } from "zod";
|
|
250
|
-
var SECRET_PATTERNS = [
|
|
251
|
-
/["']api[_-]?key["']\s*:/i,
|
|
252
|
-
/["']apiKey["']\s*:/i,
|
|
253
|
-
/["']secret["']\s*:/i,
|
|
254
|
-
/["']password["']\s*:/i,
|
|
255
|
-
/["'](?:auth_token|access_token|bearer_token)["']\s*:/i,
|
|
256
|
-
/["']private[_-]?key["']\s*:/i,
|
|
257
|
-
/-----BEGIN\s+(RSA|EC|DSA|OPENSSH|PGP)\s+PRIVATE\s+KEY-----/,
|
|
258
|
-
/sk-[a-zA-Z0-9]{20,}/,
|
|
259
|
-
/Bearer\s+[a-zA-Z0-9._-]{20,}/
|
|
260
|
-
];
|
|
261
|
-
var AgentModelSchema = z2.object({
|
|
262
|
-
model: z2.string(),
|
|
263
|
-
temperature: z2.number().min(0).max(2).optional(),
|
|
264
|
-
top_p: z2.number().min(0).max(1).optional()
|
|
265
|
-
});
|
|
266
|
-
var ModelProfileSchema = z2.object({
|
|
267
|
-
extends: z2.string().optional(),
|
|
268
|
-
description: z2.string().optional(),
|
|
269
|
-
default: z2.string().optional(),
|
|
270
|
-
small: z2.string().optional(),
|
|
271
|
-
agents: z2.record(z2.string(), AgentModelSchema).optional()
|
|
272
|
-
});
|
|
273
|
-
var RoutingConditionSchema = z2.object({
|
|
274
|
-
complexity: z2.enum(["low", "medium", "high", "critical"]).optional().describe("Task complexity level"),
|
|
275
|
-
urgency: z2.enum(["low", "normal", "high"]).optional().describe("Time sensitivity"),
|
|
276
|
-
budget: z2.enum(["minimal", "standard", "premium"]).optional().describe("Cost/token budget tier"),
|
|
277
|
-
contextWindowNeed: z2.enum(["small", "medium", "large", "max"]).optional().describe("Required context window size"),
|
|
278
|
-
toolUseIntensity: z2.enum(["none", "light", "heavy"]).optional().describe("Expected tool/function calling intensity")
|
|
279
|
-
});
|
|
280
|
-
var RoutingRuleSchema = z2.object({
|
|
281
|
-
when: z2.record(z2.string(), z2.string()),
|
|
282
|
-
use: z2.string(),
|
|
283
|
-
description: z2.string().optional(),
|
|
284
|
-
priority: z2.number().optional()
|
|
285
|
-
});
|
|
286
|
-
var ProviderModelSchema = z2.object({
|
|
287
|
-
options: z2.record(z2.string(), z2.unknown()).optional(),
|
|
288
|
-
variants: z2.record(z2.string(), z2.record(z2.string(), z2.unknown())).optional()
|
|
289
|
-
});
|
|
290
|
-
var ProviderConfigSchema = z2.object({
|
|
291
|
-
options: z2.record(z2.string(), z2.unknown()).optional(),
|
|
292
|
-
models: z2.record(z2.string(), ProviderModelSchema).optional()
|
|
293
|
-
});
|
|
294
|
-
var ModelsSchema = z2.object({
|
|
295
|
-
default: z2.string().optional(),
|
|
296
|
-
small: z2.string().optional(),
|
|
297
|
-
agents: z2.record(z2.string(), AgentModelSchema).optional(),
|
|
298
|
-
profiles: z2.record(z2.string(), ModelProfileSchema).optional(),
|
|
299
|
-
providers: z2.record(z2.string(), ProviderConfigSchema).optional(),
|
|
300
|
-
routing: z2.array(RoutingRuleSchema).optional(),
|
|
301
|
-
overrides: z2.record(z2.string(), z2.object({
|
|
302
|
-
default: z2.string().optional(),
|
|
303
|
-
small: z2.string().optional(),
|
|
304
|
-
agents: z2.record(z2.string(), AgentModelSchema).optional()
|
|
305
|
-
})).optional()
|
|
306
|
-
});
|
|
307
|
-
function parseModels(packDir, packName) {
|
|
308
|
-
const modelsPath = join2(packDir, "models.json");
|
|
309
|
-
const raw = readJsonOrNull(modelsPath);
|
|
310
|
-
if (!raw)
|
|
311
|
-
return null;
|
|
312
|
-
const parsed = ModelsSchema.parse(raw);
|
|
313
|
-
return {
|
|
314
|
-
packName,
|
|
315
|
-
sourcePath: modelsPath,
|
|
316
|
-
config: parsed
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
|
-
function mergeModelsConfigs(configs) {
|
|
320
|
-
const warnings = [];
|
|
321
|
-
const result = {};
|
|
322
|
-
for (const entry of configs) {
|
|
323
|
-
const { config, packName } = entry;
|
|
324
|
-
if (config.default !== undefined && result.default === undefined) {
|
|
325
|
-
result.default = config.default;
|
|
326
|
-
} else if (config.default !== undefined && result.default !== undefined) {
|
|
327
|
-
warnings.push(`Models "default" from pack "${packName}" skipped (already defined).`);
|
|
328
|
-
}
|
|
329
|
-
if (config.small !== undefined && result.small === undefined) {
|
|
330
|
-
result.small = config.small;
|
|
331
|
-
} else if (config.small !== undefined && result.small !== undefined) {
|
|
332
|
-
warnings.push(`Models "small" from pack "${packName}" skipped (already defined).`);
|
|
333
|
-
}
|
|
334
|
-
if (config.agents) {
|
|
335
|
-
if (!result.agents)
|
|
336
|
-
result.agents = {};
|
|
337
|
-
for (const [name, assignment] of Object.entries(config.agents)) {
|
|
338
|
-
if (name in result.agents) {
|
|
339
|
-
warnings.push(`Models agent "${name}" from pack "${packName}" skipped (already defined).`);
|
|
340
|
-
continue;
|
|
341
|
-
}
|
|
342
|
-
result.agents[name] = assignment;
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
if (config.profiles) {
|
|
346
|
-
if (!result.profiles)
|
|
347
|
-
result.profiles = {};
|
|
348
|
-
for (const [name, profile] of Object.entries(config.profiles)) {
|
|
349
|
-
if (name in result.profiles) {
|
|
350
|
-
warnings.push(`Models profile "${name}" from pack "${packName}" skipped (already defined).`);
|
|
351
|
-
continue;
|
|
352
|
-
}
|
|
353
|
-
result.profiles[name] = profile;
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
if (config.providers) {
|
|
357
|
-
if (!result.providers)
|
|
358
|
-
result.providers = {};
|
|
359
|
-
for (const [providerName, providerConfig] of Object.entries(config.providers)) {
|
|
360
|
-
if (!(providerName in result.providers)) {
|
|
361
|
-
result.providers[providerName] = providerConfig;
|
|
362
|
-
} else {
|
|
363
|
-
const existing = result.providers[providerName];
|
|
364
|
-
if (!existing) {
|
|
365
|
-
result.providers[providerName] = providerConfig;
|
|
366
|
-
continue;
|
|
367
|
-
}
|
|
368
|
-
if (providerConfig.options) {
|
|
369
|
-
existing.options = {
|
|
370
|
-
...providerConfig.options,
|
|
371
|
-
...existing.options
|
|
372
|
-
};
|
|
373
|
-
}
|
|
374
|
-
if (providerConfig.models) {
|
|
375
|
-
if (!existing.models)
|
|
376
|
-
existing.models = {};
|
|
377
|
-
for (const [modelName, modelConfig] of Object.entries(providerConfig.models)) {
|
|
378
|
-
if (!(modelName in existing.models)) {
|
|
379
|
-
existing.models[modelName] = modelConfig;
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
if (config.routing) {
|
|
387
|
-
if (!result.routing)
|
|
388
|
-
result.routing = [];
|
|
389
|
-
result.routing.push(...config.routing);
|
|
390
|
-
}
|
|
391
|
-
if (config.overrides) {
|
|
392
|
-
if (!result.overrides)
|
|
393
|
-
result.overrides = {};
|
|
394
|
-
for (const [targetId, override] of Object.entries(config.overrides)) {
|
|
395
|
-
if (targetId in result.overrides) {
|
|
396
|
-
warnings.push(`Models override for target "${targetId}" from pack "${packName}" skipped (already defined).`);
|
|
397
|
-
continue;
|
|
398
|
-
}
|
|
399
|
-
result.overrides[targetId] = override;
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
return { config: result, warnings };
|
|
404
|
-
}
|
|
405
|
-
function scanModelsForSecrets(config) {
|
|
406
|
-
const warnings = [];
|
|
407
|
-
const json = JSON.stringify(config);
|
|
408
|
-
for (const pattern of SECRET_PATTERNS) {
|
|
409
|
-
if (pattern.test(json)) {
|
|
410
|
-
warnings.push(`Potential secret detected in models.json matching pattern: ${pattern.source}`);
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
return warnings;
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
// src/core/feature-merger.ts
|
|
417
|
-
class FeatureMerger {
|
|
418
|
-
packs;
|
|
419
|
-
warnings = [];
|
|
420
|
-
constructor(packs) {
|
|
421
|
-
this.packs = packs;
|
|
422
|
-
}
|
|
423
|
-
merge() {
|
|
424
|
-
this.warnings = [];
|
|
425
|
-
const features = {
|
|
426
|
-
rules: this.mergeRules(),
|
|
427
|
-
commands: this.mergeByName("commands"),
|
|
428
|
-
agents: this.mergeByName("agents"),
|
|
429
|
-
skills: this.mergeByName("skills"),
|
|
430
|
-
hooks: this.mergeHooks(),
|
|
431
|
-
plugins: this.mergePlugins(),
|
|
432
|
-
mcpServers: this.mergeMcp(),
|
|
433
|
-
ignorePatterns: this.mergeIgnore(),
|
|
434
|
-
models: this.mergeModels()
|
|
435
|
-
};
|
|
436
|
-
return { features, warnings: this.warnings };
|
|
437
|
-
}
|
|
438
|
-
mergeRules() {
|
|
439
|
-
const seen = new Map;
|
|
440
|
-
const result = [];
|
|
441
|
-
for (const pack of this.packs) {
|
|
442
|
-
for (const rule of pack.rules) {
|
|
443
|
-
const existing = seen.get(rule.name);
|
|
444
|
-
if (existing) {
|
|
445
|
-
this.warnings.push(`Rule "${rule.name}" from pack "${rule.packName}" skipped (already defined by "${existing}").`);
|
|
446
|
-
continue;
|
|
447
|
-
}
|
|
448
|
-
seen.set(rule.name, rule.packName);
|
|
449
|
-
result.push(rule);
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
return result;
|
|
453
|
-
}
|
|
454
|
-
mergeByName(featureKey) {
|
|
455
|
-
const seen = new Map;
|
|
456
|
-
const result = [];
|
|
457
|
-
for (const pack of this.packs) {
|
|
458
|
-
const items = pack[featureKey];
|
|
459
|
-
for (const item of items) {
|
|
460
|
-
const existing = seen.get(item.name);
|
|
461
|
-
if (existing) {
|
|
462
|
-
this.warnings.push(`${featureKey.slice(0, -1)} "${item.name}" from pack "${item.packName}" skipped (already defined by "${existing}").`);
|
|
463
|
-
continue;
|
|
464
|
-
}
|
|
465
|
-
seen.set(item.name, item.packName);
|
|
466
|
-
result.push(item);
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
return result;
|
|
470
|
-
}
|
|
471
|
-
mergeHooks() {
|
|
472
|
-
return this.packs.map((p) => p.hooks).filter((h) => h !== null);
|
|
473
|
-
}
|
|
474
|
-
mergePlugins() {
|
|
475
|
-
const seen = new Map;
|
|
476
|
-
const result = [];
|
|
477
|
-
for (const pack of this.packs) {
|
|
478
|
-
for (const plugin of pack.plugins) {
|
|
479
|
-
const key = `${plugin.name}.${plugin.extension}`;
|
|
480
|
-
const existing = seen.get(key);
|
|
481
|
-
if (existing) {
|
|
482
|
-
this.warnings.push(`Plugin "${key}" from pack "${plugin.packName}" skipped (already defined by "${existing}").`);
|
|
483
|
-
continue;
|
|
484
|
-
}
|
|
485
|
-
seen.set(key, plugin.packName);
|
|
486
|
-
result.push(plugin);
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
return result;
|
|
490
|
-
}
|
|
491
|
-
mergeMcp() {
|
|
492
|
-
const servers = {};
|
|
493
|
-
for (const pack of this.packs) {
|
|
494
|
-
if (!pack.mcp)
|
|
495
|
-
continue;
|
|
496
|
-
for (const [name, entry] of Object.entries(pack.mcp.servers)) {
|
|
497
|
-
if (name in servers) {
|
|
498
|
-
this.warnings.push(`MCP server "${name}" from pack "${pack.manifest.name}" skipped (already defined).`);
|
|
499
|
-
continue;
|
|
500
|
-
}
|
|
501
|
-
servers[name] = entry;
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
return servers;
|
|
505
|
-
}
|
|
506
|
-
mergeIgnore() {
|
|
507
|
-
const seen = new Set;
|
|
508
|
-
const result = [];
|
|
509
|
-
for (const pack of this.packs) {
|
|
510
|
-
if (!pack.ignore)
|
|
511
|
-
continue;
|
|
512
|
-
for (const pattern of pack.ignore.patterns) {
|
|
513
|
-
if (!seen.has(pattern)) {
|
|
514
|
-
seen.add(pattern);
|
|
515
|
-
result.push(pattern);
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
return result;
|
|
520
|
-
}
|
|
521
|
-
mergeModels() {
|
|
522
|
-
const configs = this.packs.map((p) => p.models).filter((m) => m != null);
|
|
523
|
-
if (configs.length === 0)
|
|
524
|
-
return null;
|
|
525
|
-
const { config, warnings } = mergeModelsConfigs(configs);
|
|
526
|
-
this.warnings.push(...warnings);
|
|
527
|
-
return config;
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
// src/utils/frontmatter.ts
|
|
532
|
-
import matter from "gray-matter";
|
|
533
|
-
function parseFrontmatter(source) {
|
|
534
|
-
const { data, content } = matter(source);
|
|
535
|
-
return {
|
|
536
|
-
data,
|
|
537
|
-
content: content.trim(),
|
|
538
|
-
raw: source
|
|
539
|
-
};
|
|
540
|
-
}
|
|
541
|
-
function serializeFrontmatter(data, content) {
|
|
542
|
-
const filtered = Object.fromEntries(Object.entries(data).filter(([, v]) => v !== undefined));
|
|
543
|
-
if (Object.keys(filtered).length === 0) {
|
|
544
|
-
return content;
|
|
545
|
-
}
|
|
546
|
-
return matter.stringify(content, filtered);
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
// src/features/agents.ts
|
|
550
|
-
import { readFileSync as readFileSync3 } from "fs";
|
|
551
|
-
import { basename } from "path";
|
|
552
|
-
function parseAgents(agentsDir, packName) {
|
|
553
|
-
const files = listFiles(agentsDir, { extension: ".md" });
|
|
554
|
-
return files.map((filepath) => parseAgentFile(filepath, packName));
|
|
555
|
-
}
|
|
556
|
-
function parseAgentFile(filepath, packName) {
|
|
557
|
-
const raw = readFileSync3(filepath, "utf-8");
|
|
558
|
-
const { data, content } = parseFrontmatter(raw);
|
|
559
|
-
return {
|
|
560
|
-
name: data.name ?? basename(filepath, ".md"),
|
|
561
|
-
sourcePath: filepath,
|
|
562
|
-
packName,
|
|
563
|
-
meta: data,
|
|
564
|
-
content
|
|
565
|
-
};
|
|
566
|
-
}
|
|
567
|
-
function agentMatchesTarget(agent, targetId) {
|
|
568
|
-
const { targets } = agent.meta;
|
|
569
|
-
if (!targets || targets === "*")
|
|
570
|
-
return true;
|
|
571
|
-
if (Array.isArray(targets) && targets.includes("*"))
|
|
572
|
-
return true;
|
|
573
|
-
return Array.isArray(targets) && targets.includes(targetId);
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
// src/features/commands.ts
|
|
577
|
-
import { readFileSync as readFileSync4 } from "fs";
|
|
578
|
-
import { basename as basename2 } from "path";
|
|
579
|
-
function parseCommands(commandsDir, packName) {
|
|
580
|
-
const files = listFiles(commandsDir, { extension: ".md" });
|
|
581
|
-
return files.map((filepath) => parseCommandFile(filepath, packName));
|
|
582
|
-
}
|
|
583
|
-
function parseCommandFile(filepath, packName) {
|
|
584
|
-
const raw = readFileSync4(filepath, "utf-8");
|
|
585
|
-
const { data, content } = parseFrontmatter(raw);
|
|
586
|
-
return {
|
|
587
|
-
name: basename2(filepath, ".md"),
|
|
588
|
-
sourcePath: filepath,
|
|
589
|
-
packName,
|
|
590
|
-
meta: data,
|
|
591
|
-
content
|
|
592
|
-
};
|
|
593
|
-
}
|
|
594
|
-
function commandMatchesTarget(cmd, targetId) {
|
|
595
|
-
const { targets } = cmd.meta;
|
|
596
|
-
if (!targets || targets === "*")
|
|
597
|
-
return true;
|
|
598
|
-
if (Array.isArray(targets) && targets.includes("*"))
|
|
599
|
-
return true;
|
|
600
|
-
return Array.isArray(targets) && targets.includes(targetId);
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
// src/features/hooks.ts
|
|
604
|
-
import { join as join3 } from "path";
|
|
605
|
-
var TARGET_OVERRIDE_KEYS = ["cursor", "claudecode", "opencode"];
|
|
606
|
-
function parseHooks(packDir, packName) {
|
|
607
|
-
const hooksPath = join3(packDir, "hooks", "hooks.json");
|
|
608
|
-
const raw = readJsonOrNull(hooksPath);
|
|
609
|
-
if (!raw)
|
|
610
|
-
return null;
|
|
611
|
-
const shared = raw.hooks ?? {};
|
|
612
|
-
const targetOverrides = {};
|
|
613
|
-
for (const key of TARGET_OVERRIDE_KEYS) {
|
|
614
|
-
const override = raw[key];
|
|
615
|
-
if (override && typeof override === "object" && "hooks" in override && override.hooks) {
|
|
616
|
-
targetOverrides[key] = override.hooks;
|
|
617
|
-
}
|
|
618
|
-
}
|
|
619
|
-
return {
|
|
620
|
-
packName,
|
|
621
|
-
sourcePath: hooksPath,
|
|
622
|
-
version: raw.version,
|
|
623
|
-
shared,
|
|
624
|
-
targetOverrides
|
|
625
|
-
};
|
|
626
|
-
}
|
|
627
|
-
function resolveHooksForTarget(hooks, targetId) {
|
|
628
|
-
const merged = {};
|
|
629
|
-
for (const [event, entries] of Object.entries(hooks.shared)) {
|
|
630
|
-
merged[event] = [...entries];
|
|
631
|
-
}
|
|
632
|
-
const overrides = hooks.targetOverrides[targetId];
|
|
633
|
-
if (overrides) {
|
|
634
|
-
for (const [event, entries] of Object.entries(overrides)) {
|
|
635
|
-
merged[event] = [...merged[event] ?? [], ...entries];
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
return merged;
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
// src/features/ignore.ts
|
|
642
|
-
import { existsSync as existsSync3, readFileSync as readFileSync5 } from "fs";
|
|
643
|
-
import { join as join4 } from "path";
|
|
644
|
-
var IGNORE_FILES = ["ignore", ".aiignore"];
|
|
645
|
-
function parseIgnore(packDir, packName) {
|
|
646
|
-
for (const filename of IGNORE_FILES) {
|
|
647
|
-
const filepath = join4(packDir, filename);
|
|
648
|
-
if (existsSync3(filepath)) {
|
|
649
|
-
const raw = readFileSync5(filepath, "utf-8");
|
|
650
|
-
const patterns = parseIgnoreContent(raw);
|
|
651
|
-
return {
|
|
652
|
-
packName,
|
|
653
|
-
sourcePath: filepath,
|
|
654
|
-
patterns
|
|
655
|
-
};
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
return null;
|
|
659
|
-
}
|
|
660
|
-
function parseIgnoreContent(content) {
|
|
661
|
-
return content.split(`
|
|
662
|
-
`).map((line) => line.trim()).filter((line) => line.length > 0 && !line.startsWith("#"));
|
|
663
|
-
}
|
|
664
|
-
function mergeIgnorePatterns(configs) {
|
|
665
|
-
const seen = new Set;
|
|
666
|
-
const result = [];
|
|
667
|
-
for (const config of configs) {
|
|
668
|
-
for (const pattern of config.patterns) {
|
|
669
|
-
if (!seen.has(pattern)) {
|
|
670
|
-
seen.add(pattern);
|
|
671
|
-
result.push(pattern);
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
return result;
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
// src/features/mcp.ts
|
|
679
|
-
import { join as join5 } from "path";
|
|
680
|
-
function parseMcp(packDir, packName) {
|
|
681
|
-
const mcpPath = join5(packDir, "mcp.json");
|
|
682
|
-
const raw = readJsonOrNull(mcpPath);
|
|
683
|
-
if (!raw?.mcpServers)
|
|
684
|
-
return null;
|
|
685
|
-
return {
|
|
686
|
-
packName,
|
|
687
|
-
sourcePath: mcpPath,
|
|
688
|
-
servers: raw.mcpServers
|
|
689
|
-
};
|
|
690
|
-
}
|
|
691
|
-
function mergeMcpConfigs(configs) {
|
|
692
|
-
const servers = {};
|
|
693
|
-
const warnings = [];
|
|
694
|
-
for (const config of configs) {
|
|
695
|
-
for (const [name, entry] of Object.entries(config.servers)) {
|
|
696
|
-
if (name in servers) {
|
|
697
|
-
warnings.push(`MCP server "${name}" from pack "${config.packName}" skipped (already defined).`);
|
|
698
|
-
continue;
|
|
699
|
-
}
|
|
700
|
-
servers[name] = entry;
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
return { servers, warnings };
|
|
704
|
-
}
|
|
705
|
-
|
|
706
|
-
// src/features/plugins.ts
|
|
707
|
-
import { existsSync as existsSync4, readFileSync as readFileSync6 } from "fs";
|
|
708
|
-
import { basename as basename3, join as join6 } from "path";
|
|
709
|
-
function parsePlugins(packDir, packName) {
|
|
710
|
-
const pluginsDir = join6(packDir, "plugins");
|
|
711
|
-
if (!existsSync4(pluginsDir))
|
|
712
|
-
return [];
|
|
713
|
-
const tsFiles = listFiles(pluginsDir, { extension: ".ts" });
|
|
714
|
-
const jsFiles = listFiles(pluginsDir, { extension: ".js" });
|
|
715
|
-
const allFiles = [...tsFiles, ...jsFiles];
|
|
716
|
-
return allFiles.map((filepath) => parsePluginFile(filepath, packName));
|
|
717
|
-
}
|
|
718
|
-
function parsePluginFile(filepath, packName) {
|
|
719
|
-
const content = readFileSync6(filepath, "utf-8");
|
|
720
|
-
const ext = filepath.endsWith(".ts") ? "ts" : "js";
|
|
721
|
-
return {
|
|
722
|
-
name: basename3(filepath, `.${ext}`),
|
|
723
|
-
sourcePath: filepath,
|
|
724
|
-
packName,
|
|
725
|
-
content,
|
|
726
|
-
extension: ext
|
|
727
|
-
};
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
// src/features/rules.ts
|
|
731
|
-
import { readFileSync as readFileSync7 } from "fs";
|
|
732
|
-
import { basename as basename4 } from "path";
|
|
733
|
-
function parseRules(rulesDir, packName) {
|
|
734
|
-
const files = listFiles(rulesDir, { extension: ".md" });
|
|
735
|
-
return files.map((filepath) => parseRuleFile(filepath, packName));
|
|
736
|
-
}
|
|
737
|
-
function parseRuleFile(filepath, packName) {
|
|
738
|
-
const raw = readFileSync7(filepath, "utf-8");
|
|
739
|
-
const { data, content } = parseFrontmatter(raw);
|
|
740
|
-
return {
|
|
741
|
-
name: basename4(filepath, ".md"),
|
|
742
|
-
sourcePath: filepath,
|
|
743
|
-
packName,
|
|
744
|
-
meta: data,
|
|
745
|
-
content
|
|
746
|
-
};
|
|
747
|
-
}
|
|
748
|
-
function ruleMatchesTarget(rule, targetId) {
|
|
749
|
-
const { targets } = rule.meta;
|
|
750
|
-
if (!targets || targets === "*")
|
|
751
|
-
return true;
|
|
752
|
-
if (Array.isArray(targets) && targets.includes("*"))
|
|
753
|
-
return true;
|
|
754
|
-
return Array.isArray(targets) && targets.includes(targetId);
|
|
755
|
-
}
|
|
756
|
-
function getRootRules(rules) {
|
|
757
|
-
return rules.filter((r) => r.meta.root === true);
|
|
758
|
-
}
|
|
759
|
-
function getDetailRules(rules) {
|
|
760
|
-
return rules.filter((r) => r.meta.root !== true);
|
|
761
|
-
}
|
|
762
|
-
|
|
763
|
-
// src/features/skills.ts
|
|
764
|
-
import { existsSync as existsSync5, readFileSync as readFileSync8 } from "fs";
|
|
765
|
-
import { basename as basename5, join as join7 } from "path";
|
|
766
|
-
var SKILL_NAME_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
767
|
-
var SKILL_NAME_MAX_LENGTH = 64;
|
|
768
|
-
function parseSkills(skillsDir, packName) {
|
|
769
|
-
const dirs = listDirs(skillsDir);
|
|
770
|
-
const skills = [];
|
|
771
|
-
for (const dir of dirs) {
|
|
772
|
-
const skillMd = join7(dir, "SKILL.md");
|
|
773
|
-
if (existsSync5(skillMd)) {
|
|
774
|
-
skills.push(parseSkillFile(skillMd, dir, packName));
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
return skills;
|
|
778
|
-
}
|
|
779
|
-
function parseSkillFile(filepath, skillDir, packName) {
|
|
780
|
-
const raw = readFileSync8(filepath, "utf-8");
|
|
781
|
-
const { data, content } = parseFrontmatter(raw);
|
|
782
|
-
return {
|
|
783
|
-
name: data.name ?? basename5(skillDir),
|
|
784
|
-
sourcePath: filepath,
|
|
785
|
-
sourceDir: skillDir,
|
|
786
|
-
packName,
|
|
787
|
-
meta: data,
|
|
788
|
-
content
|
|
789
|
-
};
|
|
790
|
-
}
|
|
791
|
-
function buildSkillFrontmatter(skill) {
|
|
792
|
-
return {
|
|
793
|
-
...skill.meta,
|
|
794
|
-
name: skill.name
|
|
795
|
-
};
|
|
796
|
-
}
|
|
797
|
-
function serializeSkill(skill) {
|
|
798
|
-
return serializeFrontmatter(buildSkillFrontmatter(skill), skill.content);
|
|
799
|
-
}
|
|
800
|
-
function normalizeImportedSkillMarkdown(source, skillName) {
|
|
801
|
-
const { data, content } = parseFrontmatter(source);
|
|
802
|
-
const normalized = {
|
|
803
|
-
...data,
|
|
804
|
-
name: skillName
|
|
805
|
-
};
|
|
806
|
-
let addedDescription = false;
|
|
807
|
-
const description = normalized.description;
|
|
808
|
-
if (typeof description !== "string" || description.trim().length === 0) {
|
|
809
|
-
normalized.description = `Imported skill: ${skillName}`;
|
|
810
|
-
addedDescription = true;
|
|
811
|
-
}
|
|
812
|
-
return {
|
|
813
|
-
content: serializeFrontmatter(normalized, content),
|
|
814
|
-
addedDescription
|
|
815
|
-
};
|
|
816
|
-
}
|
|
817
|
-
function validateAgentSkillsFrontmatter(skill) {
|
|
818
|
-
const errors = [];
|
|
819
|
-
const dirName = basename5(skill.sourceDir);
|
|
820
|
-
const declaredName = skill.meta.name;
|
|
821
|
-
if (typeof declaredName !== "string" || declaredName.trim().length === 0) {
|
|
822
|
-
errors.push('Missing required frontmatter field "name".');
|
|
823
|
-
} else {
|
|
824
|
-
if (declaredName.length > SKILL_NAME_MAX_LENGTH) {
|
|
825
|
-
errors.push(`Invalid "name": must be at most ${SKILL_NAME_MAX_LENGTH} characters.`);
|
|
826
|
-
}
|
|
827
|
-
if (!SKILL_NAME_PATTERN.test(declaredName)) {
|
|
828
|
-
errors.push('Invalid "name": use lowercase letters, numbers, and single hyphens only.');
|
|
829
|
-
}
|
|
830
|
-
if (declaredName !== dirName) {
|
|
831
|
-
errors.push(`Invalid "name": must match containing directory "${dirName}".`);
|
|
832
|
-
}
|
|
833
|
-
}
|
|
834
|
-
const description = skill.meta.description;
|
|
835
|
-
if (typeof description !== "string" || description.trim().length === 0) {
|
|
836
|
-
errors.push('Missing required frontmatter field "description".');
|
|
837
|
-
}
|
|
838
|
-
const allowedTools = skill.meta["allowed-tools"];
|
|
839
|
-
if (allowedTools !== undefined && (!Array.isArray(allowedTools) || allowedTools.some((tool) => typeof tool !== "string" || tool.length === 0))) {
|
|
840
|
-
errors.push('Invalid "allowed-tools": expected an array of non-empty strings.');
|
|
841
|
-
}
|
|
842
|
-
return errors;
|
|
843
|
-
}
|
|
844
|
-
function skillMatchesTarget(skill, targetId) {
|
|
845
|
-
const { targets } = skill.meta;
|
|
846
|
-
if (!targets || targets === "*")
|
|
847
|
-
return true;
|
|
848
|
-
if (Array.isArray(targets) && targets.includes("*"))
|
|
849
|
-
return true;
|
|
850
|
-
return Array.isArray(targets) && targets.includes(targetId);
|
|
851
|
-
}
|
|
852
|
-
|
|
853
|
-
// src/core/pack-loader.ts
|
|
854
|
-
import { existsSync as existsSync6 } from "fs";
|
|
855
|
-
import { isAbsolute, resolve as resolve2 } from "path";
|
|
856
|
-
class PackLoader {
|
|
857
|
-
projectRoot;
|
|
858
|
-
config;
|
|
859
|
-
constructor(projectRoot, config) {
|
|
860
|
-
this.projectRoot = projectRoot;
|
|
861
|
-
this.config = config;
|
|
862
|
-
}
|
|
863
|
-
loadAll() {
|
|
864
|
-
const warnings = [];
|
|
865
|
-
const packs = [];
|
|
866
|
-
const disabledSet = new Set(this.config.disabled);
|
|
867
|
-
for (const packRef of this.config.packs) {
|
|
868
|
-
const packDir = this.resolvePackPath(packRef);
|
|
869
|
-
if (!packDir) {
|
|
870
|
-
warnings.push(`Pack "${packRef}" could not be resolved. Skipping.`);
|
|
871
|
-
continue;
|
|
872
|
-
}
|
|
873
|
-
if (!existsSync6(packDir)) {
|
|
874
|
-
warnings.push(`Pack directory "${packDir}" does not exist. Skipping.`);
|
|
875
|
-
continue;
|
|
876
|
-
}
|
|
877
|
-
const manifest = loadPackManifest(packDir);
|
|
878
|
-
if (disabledSet.has(manifest.name) || disabledSet.has(packRef)) {
|
|
879
|
-
continue;
|
|
880
|
-
}
|
|
881
|
-
const loaded = this.loadPack(packDir, manifest);
|
|
882
|
-
packs.push(loaded);
|
|
883
|
-
}
|
|
884
|
-
return { packs, warnings };
|
|
885
|
-
}
|
|
886
|
-
loadPack(packDir, manifest) {
|
|
887
|
-
const name = manifest.name;
|
|
888
|
-
const rulesDir = resolve2(packDir, "rules");
|
|
889
|
-
const commandsDir = resolve2(packDir, "commands");
|
|
890
|
-
const agentsDir = resolve2(packDir, "agents");
|
|
891
|
-
const skillsDir = resolve2(packDir, "skills");
|
|
892
|
-
return {
|
|
893
|
-
manifest,
|
|
894
|
-
directory: packDir,
|
|
895
|
-
rules: existsSync6(rulesDir) ? parseRules(rulesDir, name) : [],
|
|
896
|
-
commands: existsSync6(commandsDir) ? parseCommands(commandsDir, name) : [],
|
|
897
|
-
agents: existsSync6(agentsDir) ? parseAgents(agentsDir, name) : [],
|
|
898
|
-
skills: existsSync6(skillsDir) ? parseSkills(skillsDir, name) : [],
|
|
899
|
-
hooks: parseHooks(packDir, name),
|
|
900
|
-
plugins: parsePlugins(packDir, name),
|
|
901
|
-
mcp: parseMcp(packDir, name),
|
|
902
|
-
ignore: parseIgnore(packDir, name),
|
|
903
|
-
models: parseModels(packDir, name)
|
|
904
|
-
};
|
|
905
|
-
}
|
|
906
|
-
loadForBaseDir(baseDir) {
|
|
907
|
-
const baseDirRoot = resolve2(this.projectRoot, baseDir);
|
|
908
|
-
const localConfigPath = resolve2(baseDirRoot, "agentpacks.jsonc");
|
|
909
|
-
if (!existsSync6(localConfigPath)) {
|
|
910
|
-
return { packs: [], warnings: [] };
|
|
911
|
-
}
|
|
912
|
-
const localConfig = loadWorkspaceConfig(baseDirRoot);
|
|
913
|
-
const loader = new PackLoader(baseDirRoot, localConfig);
|
|
914
|
-
return loader.loadAll();
|
|
915
|
-
}
|
|
916
|
-
resolveCuratedPack(packRef) {
|
|
917
|
-
const curatedDir = resolve2(this.projectRoot, ".agentpacks", ".curated");
|
|
918
|
-
let packName = packRef;
|
|
919
|
-
if (packName.startsWith("registry:"))
|
|
920
|
-
packName = packName.slice(9);
|
|
921
|
-
if (packName.startsWith("npm:"))
|
|
922
|
-
packName = packName.slice(4);
|
|
923
|
-
if (packName.startsWith("github:"))
|
|
924
|
-
packName = packName.slice(7);
|
|
925
|
-
if (packName.startsWith("@"))
|
|
926
|
-
packName = packName.slice(1);
|
|
927
|
-
if (packName.includes("/")) {
|
|
928
|
-
const parts = packName.split("/");
|
|
929
|
-
packName = packName.includes("@") ? parts.join("-") : parts[parts.length - 1] ?? packName;
|
|
930
|
-
}
|
|
931
|
-
const withoutVersion = packName.split("@")[0] ?? packName;
|
|
932
|
-
packName = withoutVersion.split(":")[0] ?? withoutVersion;
|
|
933
|
-
const resolved = resolve2(curatedDir, packName);
|
|
934
|
-
return existsSync6(resolved) ? resolved : null;
|
|
935
|
-
}
|
|
936
|
-
resolvePackPath(packRef) {
|
|
937
|
-
if (packRef.startsWith("./") || packRef.startsWith("../")) {
|
|
938
|
-
return resolve2(this.projectRoot, packRef);
|
|
939
|
-
}
|
|
940
|
-
if (isAbsolute(packRef)) {
|
|
941
|
-
return packRef;
|
|
942
|
-
}
|
|
943
|
-
if (packRef.startsWith("registry:")) {
|
|
944
|
-
return this.resolveCuratedPack(packRef);
|
|
945
|
-
}
|
|
946
|
-
if (packRef.startsWith("@") || packRef.startsWith("npm:") || !packRef.includes("/")) {
|
|
947
|
-
return this.resolveCuratedPack(packRef);
|
|
948
|
-
}
|
|
949
|
-
if (packRef.startsWith("github:") || packRef.includes("/")) {
|
|
950
|
-
return this.resolveCuratedPack(packRef);
|
|
951
|
-
}
|
|
952
|
-
return resolve2(this.projectRoot, packRef);
|
|
953
|
-
}
|
|
954
|
-
}
|
|
955
|
-
|
|
956
|
-
// src/core/profile-resolver.ts
|
|
957
|
-
function resolveModels(merged, modelProfile, targetId) {
|
|
958
|
-
let defaultModel = merged.default;
|
|
959
|
-
let smallModel = merged.small;
|
|
960
|
-
let agents = { ...merged.agents };
|
|
961
|
-
if (modelProfile && merged.profiles?.[modelProfile]) {
|
|
962
|
-
const resolvedProfile = resolveProfileInheritance(modelProfile, merged.profiles);
|
|
963
|
-
if (resolvedProfile.default)
|
|
964
|
-
defaultModel = resolvedProfile.default;
|
|
965
|
-
if (resolvedProfile.small)
|
|
966
|
-
smallModel = resolvedProfile.small;
|
|
967
|
-
if (resolvedProfile.agents) {
|
|
968
|
-
agents = { ...agents, ...resolvedProfile.agents };
|
|
969
|
-
}
|
|
970
|
-
}
|
|
971
|
-
if (targetId) {
|
|
972
|
-
const targetOverride = merged.overrides?.[targetId];
|
|
973
|
-
if (targetOverride) {
|
|
974
|
-
if (targetOverride.default)
|
|
975
|
-
defaultModel = targetOverride.default;
|
|
976
|
-
if (targetOverride.small)
|
|
977
|
-
smallModel = targetOverride.small;
|
|
978
|
-
if (targetOverride.agents) {
|
|
979
|
-
agents = { ...agents, ...targetOverride.agents };
|
|
980
|
-
}
|
|
981
|
-
}
|
|
982
|
-
}
|
|
983
|
-
const providers = {};
|
|
984
|
-
if (merged.providers) {
|
|
985
|
-
for (const [name, config] of Object.entries(merged.providers)) {
|
|
986
|
-
providers[name] = {
|
|
987
|
-
...config.options ? { options: config.options } : {},
|
|
988
|
-
...config.models ? { models: config.models } : {}
|
|
989
|
-
};
|
|
990
|
-
}
|
|
991
|
-
}
|
|
992
|
-
const profileNames = Object.keys(merged.profiles ?? {});
|
|
993
|
-
const profiles = {};
|
|
994
|
-
if (merged.profiles) {
|
|
995
|
-
for (const [name, profile] of Object.entries(merged.profiles)) {
|
|
996
|
-
profiles[name] = {
|
|
997
|
-
description: profile.description,
|
|
998
|
-
default: profile.default,
|
|
999
|
-
small: profile.small
|
|
1000
|
-
};
|
|
1001
|
-
}
|
|
1002
|
-
}
|
|
1003
|
-
return {
|
|
1004
|
-
default: defaultModel,
|
|
1005
|
-
small: smallModel,
|
|
1006
|
-
agents,
|
|
1007
|
-
providers,
|
|
1008
|
-
routing: merged.routing ?? [],
|
|
1009
|
-
profileNames,
|
|
1010
|
-
activeProfile: modelProfile,
|
|
1011
|
-
profiles
|
|
1012
|
-
};
|
|
1013
|
-
}
|
|
1014
|
-
function resolveAgentModel(resolved, agentName, frontmatterModel) {
|
|
1015
|
-
const fromModels = resolved.agents[agentName];
|
|
1016
|
-
if (fromModels) {
|
|
1017
|
-
return {
|
|
1018
|
-
model: fromModels.model,
|
|
1019
|
-
temperature: fromModels.temperature,
|
|
1020
|
-
top_p: fromModels.top_p
|
|
1021
|
-
};
|
|
1022
|
-
}
|
|
1023
|
-
if (frontmatterModel) {
|
|
1024
|
-
return { model: frontmatterModel };
|
|
1025
|
-
}
|
|
1026
|
-
return {};
|
|
1027
|
-
}
|
|
1028
|
-
function resolveProfileInheritance(profileName, profiles) {
|
|
1029
|
-
const visited = new Set;
|
|
1030
|
-
return resolveProfileChain(profileName, profiles, visited, 0);
|
|
1031
|
-
}
|
|
1032
|
-
var MAX_INHERITANCE_DEPTH = 10;
|
|
1033
|
-
function resolveProfileChain(name, profiles, visited, depth) {
|
|
1034
|
-
if (depth > MAX_INHERITANCE_DEPTH) {
|
|
1035
|
-
throw new Error(`Profile inheritance too deep (max ${MAX_INHERITANCE_DEPTH}): ${name}`);
|
|
1036
|
-
}
|
|
1037
|
-
if (visited.has(name)) {
|
|
1038
|
-
throw new Error(`Circular profile inheritance detected: ${[...visited, name].join(" \u2192 ")}`);
|
|
1039
|
-
}
|
|
1040
|
-
const profile = profiles[name];
|
|
1041
|
-
if (!profile) {
|
|
1042
|
-
throw new Error(`Profile "${name}" not found`);
|
|
1043
|
-
}
|
|
1044
|
-
visited.add(name);
|
|
1045
|
-
if (!profile.extends) {
|
|
1046
|
-
return { ...profile };
|
|
1047
|
-
}
|
|
1048
|
-
const parent = resolveProfileChain(profile.extends, profiles, visited, depth + 1);
|
|
1049
|
-
return {
|
|
1050
|
-
description: profile.description ?? parent.description,
|
|
1051
|
-
default: profile.default ?? parent.default,
|
|
1052
|
-
small: profile.small ?? parent.small,
|
|
1053
|
-
agents: {
|
|
1054
|
-
...parent.agents,
|
|
1055
|
-
...profile.agents
|
|
1056
|
-
}
|
|
1057
|
-
};
|
|
1058
|
-
}
|
|
1059
|
-
|
|
1060
|
-
// src/utils/model-guidance.ts
|
|
1061
|
-
function generateModelGuidanceMarkdown(resolved) {
|
|
1062
|
-
if (!resolved.default && !resolved.small && Object.keys(resolved.agents).length === 0 && Object.keys(resolved.profiles).length === 0) {
|
|
1063
|
-
return null;
|
|
1064
|
-
}
|
|
1065
|
-
const lines = [];
|
|
1066
|
-
lines.push("# Model Configuration");
|
|
1067
|
-
lines.push("");
|
|
1068
|
-
lines.push("Use the following model preferences when working in this project.");
|
|
1069
|
-
lines.push("");
|
|
1070
|
-
if (resolved.default || resolved.small) {
|
|
1071
|
-
lines.push("## Default Models");
|
|
1072
|
-
lines.push("");
|
|
1073
|
-
if (resolved.default) {
|
|
1074
|
-
lines.push(`- **Primary model**: ${resolved.default}`);
|
|
1075
|
-
}
|
|
1076
|
-
if (resolved.small) {
|
|
1077
|
-
lines.push(`- **Lightweight tasks** (titles, summaries): ${resolved.small}`);
|
|
1078
|
-
}
|
|
1079
|
-
lines.push("");
|
|
1080
|
-
}
|
|
1081
|
-
const agentEntries = Object.entries(resolved.agents);
|
|
1082
|
-
if (agentEntries.length > 0) {
|
|
1083
|
-
lines.push("## Agent Model Assignments");
|
|
1084
|
-
lines.push("");
|
|
1085
|
-
lines.push("| Agent | Model | Temperature |");
|
|
1086
|
-
lines.push("| --- | --- | --- |");
|
|
1087
|
-
for (const [name, assignment] of agentEntries) {
|
|
1088
|
-
const temp = assignment.temperature !== undefined ? String(assignment.temperature) : "\u2014";
|
|
1089
|
-
lines.push(`| ${name} | ${assignment.model} | ${temp} |`);
|
|
1090
|
-
}
|
|
1091
|
-
lines.push("");
|
|
1092
|
-
}
|
|
1093
|
-
if (Object.keys(resolved.profiles).length > 0) {
|
|
1094
|
-
lines.push("## Available Profiles");
|
|
1095
|
-
lines.push("");
|
|
1096
|
-
lines.push("| Profile | Description | Default Model |");
|
|
1097
|
-
lines.push("| --- | --- | --- |");
|
|
1098
|
-
for (const [name, profile] of Object.entries(resolved.profiles)) {
|
|
1099
|
-
lines.push(`| ${name} | ${profile.description ?? "\u2014"} | ${profile.default ?? "\u2014"} |`);
|
|
1100
|
-
}
|
|
1101
|
-
lines.push("");
|
|
1102
|
-
}
|
|
1103
|
-
if (resolved.activeProfile) {
|
|
1104
|
-
lines.push(`**Active profile**: \`${resolved.activeProfile}\``);
|
|
1105
|
-
lines.push("");
|
|
1106
|
-
}
|
|
1107
|
-
if (resolved.routing.length > 0) {
|
|
1108
|
-
lines.push("## Task-Aware Routing");
|
|
1109
|
-
lines.push("");
|
|
1110
|
-
lines.push("Select the appropriate profile based on the task context:");
|
|
1111
|
-
lines.push("");
|
|
1112
|
-
lines.push("| Condition | Profile | Description |");
|
|
1113
|
-
lines.push("| --- | --- | --- |");
|
|
1114
|
-
for (const rule of resolved.routing) {
|
|
1115
|
-
const conditions = Object.entries(rule.when).map(([k, v]) => `${k}=${v}`).join(", ");
|
|
1116
|
-
const desc = rule.description ?? "\u2014";
|
|
1117
|
-
lines.push(`| ${conditions} | ${rule.use} | ${desc} |`);
|
|
1118
|
-
}
|
|
1119
|
-
lines.push("");
|
|
1120
|
-
lines.push("### Condition Reference");
|
|
1121
|
-
lines.push("");
|
|
1122
|
-
lines.push("- **complexity**: low | medium | high | critical");
|
|
1123
|
-
lines.push("- **urgency**: low | normal | high");
|
|
1124
|
-
lines.push("- **budget**: minimal | standard | premium");
|
|
1125
|
-
lines.push("- **contextWindowNeed**: small | medium | large | max");
|
|
1126
|
-
lines.push("- **toolUseIntensity**: none | light | heavy");
|
|
1127
|
-
lines.push("");
|
|
1128
|
-
}
|
|
1129
|
-
return lines.join(`
|
|
1130
|
-
`);
|
|
1131
|
-
}
|
|
1132
|
-
|
|
1133
|
-
// src/targets/base-target.ts
|
|
1134
|
-
class BaseTarget {
|
|
1135
|
-
supportsFeature(feature) {
|
|
1136
|
-
return this.supportedFeatures.includes(feature);
|
|
1137
|
-
}
|
|
1138
|
-
getEffectiveFeatures(enabledFeatures) {
|
|
1139
|
-
return enabledFeatures.filter((f) => this.supportsFeature(f));
|
|
1140
|
-
}
|
|
1141
|
-
createResult(filesWritten = [], filesDeleted = [], warnings = []) {
|
|
1142
|
-
return {
|
|
1143
|
-
targetId: this.id,
|
|
1144
|
-
filesWritten,
|
|
1145
|
-
filesDeleted,
|
|
1146
|
-
warnings
|
|
1147
|
-
};
|
|
1148
|
-
}
|
|
1149
|
-
}
|
|
1150
|
-
|
|
1151
|
-
// src/targets/generic-md-target.ts
|
|
1152
|
-
import { join as join8, resolve as resolve3 } from "path";
|
|
1153
|
-
function createGenericMdTarget(config) {
|
|
1154
|
-
return new GenericMdTarget(config);
|
|
1155
|
-
}
|
|
1156
|
-
|
|
1157
|
-
class GenericMdTarget extends BaseTarget {
|
|
1158
|
-
id;
|
|
1159
|
-
name;
|
|
1160
|
-
supportedFeatures;
|
|
1161
|
-
config;
|
|
1162
|
-
constructor(config) {
|
|
1163
|
-
super();
|
|
1164
|
-
this.id = config.id;
|
|
1165
|
-
this.name = config.name;
|
|
1166
|
-
this.supportedFeatures = config.supportedFeatures;
|
|
1167
|
-
this.config = config;
|
|
1168
|
-
}
|
|
1169
|
-
generate(options) {
|
|
1170
|
-
const { projectRoot, baseDir, features, enabledFeatures, deleteExisting } = options;
|
|
1171
|
-
const root = resolve3(projectRoot, baseDir);
|
|
1172
|
-
const effective = this.getEffectiveFeatures(enabledFeatures);
|
|
1173
|
-
const filesWritten = [];
|
|
1174
|
-
const filesDeleted = [];
|
|
1175
|
-
const warnings = [];
|
|
1176
|
-
const configDir = resolve3(root, this.config.configDir);
|
|
1177
|
-
const rulesSubDir = this.config.rulesDir ?? "rules";
|
|
1178
|
-
const ext = this.config.ruleExtension ?? ".md";
|
|
1179
|
-
if (effective.includes("rules")) {
|
|
1180
|
-
const rulesDir = resolve3(configDir, rulesSubDir);
|
|
1181
|
-
if (deleteExisting) {
|
|
1182
|
-
removeIfExists(rulesDir);
|
|
1183
|
-
filesDeleted.push(rulesDir);
|
|
1184
|
-
}
|
|
1185
|
-
ensureDir(rulesDir);
|
|
1186
|
-
const rules = features.rules.filter((r) => ruleMatchesTarget(r, this.id));
|
|
1187
|
-
for (const rule of rules) {
|
|
1188
|
-
const filepath = join8(rulesDir, `${rule.name}${ext}`);
|
|
1189
|
-
writeGeneratedFile(filepath, rule.content);
|
|
1190
|
-
filesWritten.push(filepath);
|
|
1191
|
-
}
|
|
1192
|
-
}
|
|
1193
|
-
if (effective.includes("commands")) {
|
|
1194
|
-
const commandsDir = resolve3(configDir, "commands");
|
|
1195
|
-
if (deleteExisting) {
|
|
1196
|
-
removeIfExists(commandsDir);
|
|
1197
|
-
filesDeleted.push(commandsDir);
|
|
1198
|
-
}
|
|
1199
|
-
ensureDir(commandsDir);
|
|
1200
|
-
const commands = features.commands.filter((c) => commandMatchesTarget(c, this.id));
|
|
1201
|
-
for (const cmd of commands) {
|
|
1202
|
-
const filepath = join8(commandsDir, `${cmd.name}.md`);
|
|
1203
|
-
writeGeneratedFile(filepath, cmd.content);
|
|
1204
|
-
filesWritten.push(filepath);
|
|
1205
|
-
}
|
|
1206
|
-
}
|
|
1207
|
-
if (effective.includes("mcp")) {
|
|
1208
|
-
const mcpEntries = Object.entries(features.mcpServers);
|
|
1209
|
-
if (mcpEntries.length > 0) {
|
|
1210
|
-
const mcpDir = this.config.mcpInConfigDir ? configDir : root;
|
|
1211
|
-
const filepath = resolve3(mcpDir, "mcp.json");
|
|
1212
|
-
writeGeneratedJson(filepath, { mcpServers: features.mcpServers }, {
|
|
1213
|
-
header: false
|
|
1214
|
-
});
|
|
1215
|
-
filesWritten.push(filepath);
|
|
1216
|
-
}
|
|
1217
|
-
}
|
|
1218
|
-
if (effective.includes("ignore") && this.config.ignoreFile) {
|
|
1219
|
-
if (features.ignorePatterns.length > 0) {
|
|
1220
|
-
const filepath = resolve3(root, this.config.ignoreFile);
|
|
1221
|
-
writeGeneratedFile(filepath, features.ignorePatterns.join(`
|
|
1222
|
-
`) + `
|
|
1223
|
-
`);
|
|
1224
|
-
filesWritten.push(filepath);
|
|
1225
|
-
}
|
|
1226
|
-
}
|
|
1227
|
-
if (effective.includes("models") && features.models) {
|
|
1228
|
-
const resolved = resolveModels(features.models, options.modelProfile, this.id);
|
|
1229
|
-
const guidance = generateModelGuidanceMarkdown(resolved);
|
|
1230
|
-
if (guidance) {
|
|
1231
|
-
ensureDir(configDir);
|
|
1232
|
-
const filepath = join8(configDir, "model-config.md");
|
|
1233
|
-
writeGeneratedFile(filepath, guidance);
|
|
1234
|
-
filesWritten.push(filepath);
|
|
1235
|
-
}
|
|
1236
|
-
}
|
|
1237
|
-
return this.createResult(filesWritten, filesDeleted, warnings);
|
|
1238
|
-
}
|
|
1239
|
-
}
|
|
1240
|
-
|
|
1241
|
-
// src/targets/additional-targets.ts
|
|
1242
|
-
var ClineTarget = createGenericMdTarget({
|
|
1243
|
-
id: "cline",
|
|
1244
|
-
name: "Cline",
|
|
1245
|
-
configDir: ".cline",
|
|
1246
|
-
supportedFeatures: ["rules", "commands", "mcp", "ignore"],
|
|
1247
|
-
ignoreFile: ".clineignore",
|
|
1248
|
-
mcpInConfigDir: true
|
|
1249
|
-
});
|
|
1250
|
-
var KiloTarget = createGenericMdTarget({
|
|
1251
|
-
id: "kilo",
|
|
1252
|
-
name: "Kilo Code",
|
|
1253
|
-
configDir: ".kilo",
|
|
1254
|
-
supportedFeatures: ["rules", "commands", "mcp", "ignore"],
|
|
1255
|
-
ignoreFile: ".kiloignore",
|
|
1256
|
-
mcpInConfigDir: true
|
|
1257
|
-
});
|
|
1258
|
-
var RooTarget = createGenericMdTarget({
|
|
1259
|
-
id: "roo",
|
|
1260
|
-
name: "Roo Code",
|
|
1261
|
-
configDir: ".roo",
|
|
1262
|
-
supportedFeatures: ["rules", "commands", "mcp", "ignore"],
|
|
1263
|
-
ignoreFile: ".rooignore",
|
|
1264
|
-
mcpInConfigDir: true
|
|
1265
|
-
});
|
|
1266
|
-
var QwenCodeTarget = createGenericMdTarget({
|
|
1267
|
-
id: "qwencode",
|
|
1268
|
-
name: "Qwen Code",
|
|
1269
|
-
configDir: ".qwencode",
|
|
1270
|
-
supportedFeatures: ["rules", "mcp", "ignore"],
|
|
1271
|
-
ignoreFile: ".qwencodeignore",
|
|
1272
|
-
mcpInConfigDir: true
|
|
1273
|
-
});
|
|
1274
|
-
var KiroTarget = createGenericMdTarget({
|
|
1275
|
-
id: "kiro",
|
|
1276
|
-
name: "Kiro",
|
|
1277
|
-
configDir: ".kiro",
|
|
1278
|
-
supportedFeatures: ["rules", "mcp"],
|
|
1279
|
-
mcpInConfigDir: true
|
|
1280
|
-
});
|
|
1281
|
-
var FactoryDroidTarget = createGenericMdTarget({
|
|
1282
|
-
id: "factorydroid",
|
|
1283
|
-
name: "Factory Droid",
|
|
1284
|
-
configDir: ".factorydroid",
|
|
1285
|
-
supportedFeatures: ["rules", "mcp"],
|
|
1286
|
-
mcpInConfigDir: true
|
|
1287
|
-
});
|
|
1288
|
-
var AntiGravityTarget = createGenericMdTarget({
|
|
1289
|
-
id: "antigravity",
|
|
1290
|
-
name: "AntiGravity",
|
|
1291
|
-
configDir: ".antigravity",
|
|
1292
|
-
supportedFeatures: ["rules", "mcp"],
|
|
1293
|
-
mcpInConfigDir: true
|
|
1294
|
-
});
|
|
1295
|
-
var JunieTarget = createGenericMdTarget({
|
|
1296
|
-
id: "junie",
|
|
1297
|
-
name: "Junie",
|
|
1298
|
-
configDir: ".junie",
|
|
1299
|
-
supportedFeatures: ["rules", "mcp"],
|
|
1300
|
-
mcpInConfigDir: true
|
|
1301
|
-
});
|
|
1302
|
-
var AugmentCodeTarget = createGenericMdTarget({
|
|
1303
|
-
id: "augmentcode",
|
|
1304
|
-
name: "Augment Code",
|
|
1305
|
-
configDir: ".augmentcode",
|
|
1306
|
-
supportedFeatures: ["rules", "mcp"],
|
|
1307
|
-
mcpInConfigDir: true
|
|
1308
|
-
});
|
|
1309
|
-
var WindsurfTarget = createGenericMdTarget({
|
|
1310
|
-
id: "windsurf",
|
|
1311
|
-
name: "Windsurf",
|
|
1312
|
-
configDir: ".windsurf",
|
|
1313
|
-
supportedFeatures: ["rules", "mcp", "ignore"],
|
|
1314
|
-
ignoreFile: ".windsurfignore",
|
|
1315
|
-
mcpInConfigDir: true
|
|
1316
|
-
});
|
|
1317
|
-
var WarpTarget = createGenericMdTarget({
|
|
1318
|
-
id: "warp",
|
|
1319
|
-
name: "Warp",
|
|
1320
|
-
configDir: ".warp",
|
|
1321
|
-
supportedFeatures: ["rules"]
|
|
1322
|
-
});
|
|
1323
|
-
var ReplitTarget = createGenericMdTarget({
|
|
1324
|
-
id: "replit",
|
|
1325
|
-
name: "Replit Agent",
|
|
1326
|
-
configDir: ".replit",
|
|
1327
|
-
supportedFeatures: ["rules", "mcp"],
|
|
1328
|
-
mcpInConfigDir: true
|
|
1329
|
-
});
|
|
1330
|
-
var ZedTarget = createGenericMdTarget({
|
|
1331
|
-
id: "zed",
|
|
1332
|
-
name: "Zed",
|
|
1333
|
-
configDir: ".zed",
|
|
1334
|
-
supportedFeatures: ["rules", "mcp"],
|
|
1335
|
-
mcpInConfigDir: true
|
|
1336
|
-
});
|
|
1337
|
-
|
|
1338
|
-
// src/targets/agents-md.ts
|
|
1339
|
-
import { resolve as resolve4 } from "path";
|
|
1340
|
-
class AgentsMdTarget extends BaseTarget {
|
|
1341
|
-
id = "agentsmd";
|
|
1342
|
-
name = "AGENTS.md";
|
|
1343
|
-
supportedFeatures = ["rules"];
|
|
1344
|
-
generate(options) {
|
|
1345
|
-
const { projectRoot, baseDir, features } = options;
|
|
1346
|
-
const root = resolve4(projectRoot, baseDir);
|
|
1347
|
-
const filesWritten = [];
|
|
1348
|
-
const warnings = [];
|
|
1349
|
-
const rootRules = getRootRules(features.rules);
|
|
1350
|
-
if (rootRules.length === 0) {
|
|
1351
|
-
warnings.push("No root rules found. AGENTS.md will not be generated.");
|
|
1352
|
-
return this.createResult(filesWritten, [], warnings);
|
|
1353
|
-
}
|
|
1354
|
-
const sections = rootRules.map((r) => r.content);
|
|
1355
|
-
const content = sections.join(`
|
|
1356
|
-
|
|
1357
|
-
`);
|
|
1358
|
-
const filepath = resolve4(root, "AGENTS.md");
|
|
1359
|
-
writeGeneratedFile(filepath, content);
|
|
1360
|
-
filesWritten.push(filepath);
|
|
1361
|
-
return this.createResult(filesWritten, [], warnings);
|
|
1362
|
-
}
|
|
1363
|
-
}
|
|
1364
|
-
|
|
1365
|
-
// src/targets/claude-code.ts
|
|
1366
|
-
import { join as join9, resolve as resolve5 } from "path";
|
|
1367
|
-
var TARGET_ID = "claudecode";
|
|
1368
|
-
|
|
1369
|
-
class ClaudeCodeTarget extends BaseTarget {
|
|
1370
|
-
id = TARGET_ID;
|
|
1371
|
-
name = "Claude Code";
|
|
1372
|
-
supportedFeatures = [
|
|
1373
|
-
"rules",
|
|
1374
|
-
"commands",
|
|
1375
|
-
"agents",
|
|
1376
|
-
"skills",
|
|
1377
|
-
"hooks",
|
|
1378
|
-
"mcp",
|
|
1379
|
-
"ignore",
|
|
1380
|
-
"models"
|
|
1381
|
-
];
|
|
1382
|
-
generate(options) {
|
|
1383
|
-
const { projectRoot, baseDir, features, enabledFeatures, deleteExisting } = options;
|
|
1384
|
-
const root = resolve5(projectRoot, baseDir);
|
|
1385
|
-
const effective = this.getEffectiveFeatures(enabledFeatures);
|
|
1386
|
-
const filesWritten = [];
|
|
1387
|
-
const filesDeleted = [];
|
|
1388
|
-
const warnings = [];
|
|
1389
|
-
const claudeDir = resolve5(root, ".claude");
|
|
1390
|
-
if (effective.includes("rules")) {
|
|
1391
|
-
const rulesDir = resolve5(claudeDir, "rules");
|
|
1392
|
-
if (deleteExisting) {
|
|
1393
|
-
removeIfExists(rulesDir);
|
|
1394
|
-
filesDeleted.push(rulesDir);
|
|
1395
|
-
}
|
|
1396
|
-
ensureDir(rulesDir);
|
|
1397
|
-
const rules = features.rules.filter((r) => ruleMatchesTarget(r, TARGET_ID));
|
|
1398
|
-
const rootRules = getRootRules(rules);
|
|
1399
|
-
const detailRules = getDetailRules(rules);
|
|
1400
|
-
if (rootRules.length > 0) {
|
|
1401
|
-
const claudeMd = rootRules.map((r) => r.content).join(`
|
|
1402
|
-
|
|
1403
|
-
`);
|
|
1404
|
-
const filepath = resolve5(claudeDir, "CLAUDE.md");
|
|
1405
|
-
writeGeneratedFile(filepath, claudeMd);
|
|
1406
|
-
filesWritten.push(filepath);
|
|
1407
|
-
}
|
|
1408
|
-
for (const rule of detailRules) {
|
|
1409
|
-
const filepath = join9(rulesDir, `${rule.name}.md`);
|
|
1410
|
-
writeGeneratedFile(filepath, rule.content);
|
|
1411
|
-
filesWritten.push(filepath);
|
|
1412
|
-
}
|
|
1413
|
-
}
|
|
1414
|
-
if (effective.includes("agents")) {
|
|
1415
|
-
const agentsDir = resolve5(claudeDir, "agents");
|
|
1416
|
-
if (deleteExisting) {
|
|
1417
|
-
removeIfExists(agentsDir);
|
|
1418
|
-
filesDeleted.push(agentsDir);
|
|
1419
|
-
}
|
|
1420
|
-
ensureDir(agentsDir);
|
|
1421
|
-
const resolvedModels = features.models ? resolveModels(features.models, options.modelProfile, TARGET_ID) : null;
|
|
1422
|
-
const agents = features.agents.filter((a) => agentMatchesTarget(a, TARGET_ID));
|
|
1423
|
-
for (const agent of agents) {
|
|
1424
|
-
const filepath = join9(agentsDir, `${agent.name}.md`);
|
|
1425
|
-
const cc = agent.meta.claudecode ?? {};
|
|
1426
|
-
const modelsAgent = resolvedModels?.agents[agent.name];
|
|
1427
|
-
const agentModel = modelsAgent?.model ?? cc.model;
|
|
1428
|
-
let content = agent.content;
|
|
1429
|
-
if (agentModel) {
|
|
1430
|
-
content = `<!-- model: ${agentModel} -->
|
|
1431
|
-
${content}`;
|
|
1432
|
-
}
|
|
1433
|
-
writeGeneratedFile(filepath, content);
|
|
1434
|
-
filesWritten.push(filepath);
|
|
1435
|
-
}
|
|
1436
|
-
}
|
|
1437
|
-
if (effective.includes("skills")) {
|
|
1438
|
-
const skillsDir = resolve5(claudeDir, "skills");
|
|
1439
|
-
if (deleteExisting) {
|
|
1440
|
-
removeIfExists(skillsDir);
|
|
1441
|
-
filesDeleted.push(skillsDir);
|
|
1442
|
-
}
|
|
1443
|
-
ensureDir(skillsDir);
|
|
1444
|
-
const skills = features.skills.filter((s) => skillMatchesTarget(s, TARGET_ID));
|
|
1445
|
-
for (const skill of skills) {
|
|
1446
|
-
const skillSubDir = join9(skillsDir, skill.name);
|
|
1447
|
-
ensureDir(skillSubDir);
|
|
1448
|
-
const filepath = join9(skillSubDir, "SKILL.md");
|
|
1449
|
-
writeGeneratedFile(filepath, serializeSkill(skill));
|
|
1450
|
-
filesWritten.push(filepath);
|
|
1451
|
-
}
|
|
1452
|
-
}
|
|
1453
|
-
if (effective.includes("commands")) {
|
|
1454
|
-
const commandsDir = resolve5(claudeDir, "commands");
|
|
1455
|
-
if (deleteExisting) {
|
|
1456
|
-
removeIfExists(commandsDir);
|
|
1457
|
-
filesDeleted.push(commandsDir);
|
|
1458
|
-
}
|
|
1459
|
-
ensureDir(commandsDir);
|
|
1460
|
-
const commands = features.commands.filter((c) => commandMatchesTarget(c, TARGET_ID));
|
|
1461
|
-
for (const cmd of commands) {
|
|
1462
|
-
const filepath = join9(commandsDir, `${cmd.name}.md`);
|
|
1463
|
-
writeGeneratedFile(filepath, cmd.content);
|
|
1464
|
-
filesWritten.push(filepath);
|
|
1465
|
-
}
|
|
1466
|
-
}
|
|
1467
|
-
if (effective.includes("models") && features.models) {
|
|
1468
|
-
const resolved = resolveModels(features.models, options.modelProfile, TARGET_ID);
|
|
1469
|
-
const guidance = generateModelGuidanceMarkdown(resolved);
|
|
1470
|
-
if (guidance) {
|
|
1471
|
-
const rulesDir = resolve5(claudeDir, "rules");
|
|
1472
|
-
ensureDir(rulesDir);
|
|
1473
|
-
const filepath = join9(rulesDir, "model-config.md");
|
|
1474
|
-
writeGeneratedFile(filepath, guidance);
|
|
1475
|
-
filesWritten.push(filepath);
|
|
1476
|
-
}
|
|
1477
|
-
}
|
|
1478
|
-
if (effective.includes("hooks") || effective.includes("mcp") || effective.includes("ignore")) {
|
|
1479
|
-
const settings = buildClaudeSettings(options, effective);
|
|
1480
|
-
if (Object.keys(settings).length > 0) {
|
|
1481
|
-
const filepath = resolve5(claudeDir, "settings.json");
|
|
1482
|
-
const existing = readJsonOrNull(filepath) ?? {};
|
|
1483
|
-
const merged = { ...existing, ...settings };
|
|
1484
|
-
writeGeneratedJson(filepath, merged, { header: false });
|
|
1485
|
-
filesWritten.push(filepath);
|
|
1486
|
-
}
|
|
1487
|
-
}
|
|
1488
|
-
return this.createResult(filesWritten, filesDeleted, warnings);
|
|
1489
|
-
}
|
|
1490
|
-
}
|
|
1491
|
-
function buildClaudeSettings(options, effective) {
|
|
1492
|
-
const settings = {};
|
|
1493
|
-
if (effective.includes("hooks")) {
|
|
1494
|
-
const allHookEntries = {};
|
|
1495
|
-
for (const hookSet of options.features.hooks) {
|
|
1496
|
-
const events = resolveHooksForTarget(hookSet, TARGET_ID);
|
|
1497
|
-
for (const [event, entries] of Object.entries(events)) {
|
|
1498
|
-
const pascalEvent = toPascalCase(event);
|
|
1499
|
-
if (!allHookEntries[pascalEvent]) {
|
|
1500
|
-
allHookEntries[pascalEvent] = [];
|
|
1501
|
-
}
|
|
1502
|
-
allHookEntries[pascalEvent].push(...entries.map((e) => ({
|
|
1503
|
-
type: e.type ?? "command",
|
|
1504
|
-
...e.matcher ? { matcher: e.matcher } : {},
|
|
1505
|
-
command: e.command
|
|
1506
|
-
})));
|
|
1507
|
-
}
|
|
1508
|
-
}
|
|
1509
|
-
if (Object.keys(allHookEntries).length > 0) {
|
|
1510
|
-
settings.hooks = allHookEntries;
|
|
1511
|
-
}
|
|
1512
|
-
}
|
|
1513
|
-
if (effective.includes("mcp")) {
|
|
1514
|
-
const mcpEntries = Object.entries(options.features.mcpServers);
|
|
1515
|
-
if (mcpEntries.length > 0) {
|
|
1516
|
-
const mcpServers = {};
|
|
1517
|
-
for (const [name, entry] of mcpEntries) {
|
|
1518
|
-
if (entry.url) {
|
|
1519
|
-
mcpServers[name] = { url: entry.url };
|
|
1520
|
-
} else if (entry.command) {
|
|
1521
|
-
mcpServers[name] = {
|
|
1522
|
-
command: entry.command,
|
|
1523
|
-
...entry.args ? { args: entry.args } : {},
|
|
1524
|
-
...entry.env ? { env: entry.env } : {}
|
|
1525
|
-
};
|
|
1526
|
-
}
|
|
1527
|
-
}
|
|
1528
|
-
settings.mcpServers = mcpServers;
|
|
1529
|
-
}
|
|
1530
|
-
}
|
|
1531
|
-
return settings;
|
|
1532
|
-
}
|
|
1533
|
-
function toPascalCase(str) {
|
|
1534
|
-
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
1535
|
-
}
|
|
1536
|
-
|
|
1537
|
-
// src/targets/codex-cli.ts
|
|
1538
|
-
import { join as join10, resolve as resolve6 } from "path";
|
|
1539
|
-
var TARGET_ID2 = "codexcli";
|
|
1540
|
-
|
|
1541
|
-
class CodexCliTarget extends BaseTarget {
|
|
1542
|
-
id = TARGET_ID2;
|
|
1543
|
-
name = "Codex CLI";
|
|
1544
|
-
supportedFeatures = ["rules", "skills", "mcp", "hooks"];
|
|
1545
|
-
generate(options) {
|
|
1546
|
-
const { projectRoot, baseDir, features, enabledFeatures, deleteExisting } = options;
|
|
1547
|
-
const root = resolve6(projectRoot, baseDir);
|
|
1548
|
-
const effective = this.getEffectiveFeatures(enabledFeatures);
|
|
1549
|
-
const filesWritten = [];
|
|
1550
|
-
const filesDeleted = [];
|
|
1551
|
-
const warnings = [];
|
|
1552
|
-
const codexDir = resolve6(root, ".codex");
|
|
1553
|
-
if (effective.includes("rules")) {
|
|
1554
|
-
const memoriesDir = resolve6(codexDir, "memories");
|
|
1555
|
-
if (deleteExisting) {
|
|
1556
|
-
removeIfExists(memoriesDir);
|
|
1557
|
-
filesDeleted.push(memoriesDir);
|
|
1558
|
-
}
|
|
1559
|
-
ensureDir(memoriesDir);
|
|
1560
|
-
const rules = features.rules.filter((r) => ruleMatchesTarget(r, TARGET_ID2));
|
|
1561
|
-
for (const rule of rules) {
|
|
1562
|
-
const filepath = join10(memoriesDir, `${rule.name}.md`);
|
|
1563
|
-
writeGeneratedFile(filepath, rule.content);
|
|
1564
|
-
filesWritten.push(filepath);
|
|
1565
|
-
}
|
|
1566
|
-
}
|
|
1567
|
-
if (effective.includes("skills")) {
|
|
1568
|
-
const skillsDir = resolve6(codexDir, "skills");
|
|
1569
|
-
if (deleteExisting) {
|
|
1570
|
-
removeIfExists(skillsDir);
|
|
1571
|
-
filesDeleted.push(skillsDir);
|
|
1572
|
-
}
|
|
1573
|
-
ensureDir(skillsDir);
|
|
1574
|
-
const skills = features.skills.filter((s) => skillMatchesTarget(s, TARGET_ID2));
|
|
1575
|
-
for (const skill of skills) {
|
|
1576
|
-
const skillSubDir = join10(skillsDir, skill.name);
|
|
1577
|
-
ensureDir(skillSubDir);
|
|
1578
|
-
const filepath = join10(skillSubDir, "SKILL.md");
|
|
1579
|
-
writeGeneratedFile(filepath, serializeSkill(skill));
|
|
1580
|
-
filesWritten.push(filepath);
|
|
1581
|
-
}
|
|
1582
|
-
}
|
|
1583
|
-
return this.createResult(filesWritten, filesDeleted, warnings);
|
|
1584
|
-
}
|
|
1585
|
-
}
|
|
1586
|
-
|
|
1587
|
-
// src/targets/copilot.ts
|
|
1588
|
-
import { join as join11, resolve as resolve7 } from "path";
|
|
1589
|
-
var TARGET_ID3 = "copilot";
|
|
1590
|
-
|
|
1591
|
-
class CopilotTarget extends BaseTarget {
|
|
1592
|
-
id = TARGET_ID3;
|
|
1593
|
-
name = "GitHub Copilot";
|
|
1594
|
-
supportedFeatures = [
|
|
1595
|
-
"rules",
|
|
1596
|
-
"commands",
|
|
1597
|
-
"agents",
|
|
1598
|
-
"skills",
|
|
1599
|
-
"mcp",
|
|
1600
|
-
"ignore",
|
|
1601
|
-
"models"
|
|
1602
|
-
];
|
|
1603
|
-
generate(options) {
|
|
1604
|
-
const { projectRoot, baseDir, features, enabledFeatures, deleteExisting } = options;
|
|
1605
|
-
const root = resolve7(projectRoot, baseDir);
|
|
1606
|
-
const effective = this.getEffectiveFeatures(enabledFeatures);
|
|
1607
|
-
const filesWritten = [];
|
|
1608
|
-
const filesDeleted = [];
|
|
1609
|
-
const warnings = [];
|
|
1610
|
-
const githubDir = resolve7(root, ".github");
|
|
1611
|
-
if (effective.includes("rules")) {
|
|
1612
|
-
const rules = features.rules.filter((r) => ruleMatchesTarget(r, TARGET_ID3));
|
|
1613
|
-
if (rules.length > 0) {
|
|
1614
|
-
const combinedContent = rules.map((r) => r.content).join(`
|
|
10
|
+
`),_=d(C,"CLAUDE.md");N(_,K),L.push(_)}for(let K of U){let _=Z0(B,`${K.name}.md`);N(_,K.content),L.push(_)}}if(J.includes("agents")){let B=d(C,"agents");if(V)S(B),W.push(B);b(B);let O=Q.models?R(Q.models,$.modelProfile,l):null,X=Q.agents.filter((U)=>v(U,l));for(let U of X){let K=Z0(B,`${U.name}.md`),_=U.meta.claudecode??{},I=O?.agents[U.name]?.model??_.model,M=U.content;if(I)M=`<!-- model: ${I} -->
|
|
11
|
+
${M}`;N(K,M),L.push(K)}}if(J.includes("skills")){let B=d(C,"skills");if(V)S(B),W.push(B);b(B);let O=Q.skills.filter((X)=>k(X,l));for(let X of O){let U=Z0(B,X.name);b(U);let K=Z0(U,"SKILL.md");N(K,T(X)),L.push(K)}}if(J.includes("commands")){let B=d(C,"commands");if(V)S(B),W.push(B);b(B);let O=Q.commands.filter((X)=>j(X,l));for(let X of O){let U=Z0(B,`${X.name}.md`);N(U,X.content),L.push(U)}}if(J.includes("models")&&Q.models){let B=R(Q.models,$.modelProfile,l),O=n(B);if(O){let X=d(C,"rules");b(X);let U=Z0(X,"model-config.md");N(U,O),L.push(U)}}if(J.includes("hooks")||J.includes("mcp")||J.includes("ignore")){let B=S2($,J);if(Object.keys(B).length>0){let O=d(C,"settings.json"),U={...f(O)??{},...B};w(O,U,{header:!1}),L.push(O)}}return this.createResult(L,W,F)}}function S2($,q){let Y={};if(q.includes("hooks")){let Q={};for(let Z of $.features.hooks){let V=o(Z,l);for(let[H,J]of Object.entries(V)){let L=G2(H);if(!Q[L])Q[L]=[];Q[L].push(...J.map((W)=>({type:W.type??"command",...W.matcher?{matcher:W.matcher}:{},command:W.command})))}}if(Object.keys(Q).length>0)Y.hooks=Q}if(q.includes("mcp")){let Q=Object.entries($.features.mcpServers);if(Q.length>0){let Z={};for(let[V,H]of Q)if(H.url)Z[V]={url:H.url};else if(H.command)Z[V]={command:H.command,...H.args?{args:H.args}:{},...H.env?{env:H.env}:{}};Y.mcpServers=Z}}return Y}function G2($){return $.charAt(0).toUpperCase()+$.slice(1)}import{join as b0,resolve as X0}from"path";var _0="codexcli";class F0 extends y{id=_0;name="Codex CLI";supportedFeatures=["rules","skills","mcp","hooks"];generate($){let{projectRoot:q,baseDir:Y,features:Q,enabledFeatures:Z,deleteExisting:V}=$,H=X0(q,Y),J=this.getEffectiveFeatures(Z),L=[],W=[],F=[],C=X0(H,".codex");if(J.includes("rules")){let B=X0(C,"memories");if(V)I0(B,W,F);b(B);let O=Q.rules.filter((X)=>z(X,_0));for(let X of O){let U=b0(B,`${X.name}.md`);N(U,X.content),L.push(U)}}if(J.includes("skills")){let B=X0(C,"skills");if(V)I0(B,W,F);b(B);let O=Q.skills.filter((X)=>k(X,_0));for(let X of O){let U=b0(B,X.name);b(U);let K=b0(U,"SKILL.md");N(K,T(X)),L.push(K)}}if(J.includes("hooks")){let B=X0(C,"hooks.json");if(V)I0(B,W,F);let O={};for(let X of Q.hooks){let U=o(X,_0);for(let[K,_]of Object.entries(U)){if(!O[K])O[K]=[];O[K].push(..._)}}if(Object.keys(O).length>0){let X=Q.hooks.find((U)=>U.version!==void 0)?.version??1;w(B,{version:X,hooks:O},{header:!1}),L.push(B)}}if(J.includes("mcp")){let B=Object.entries(Q.mcpServers);if(B.length>0){let O={};for(let[X,U]of B)if(U.url)O[X]={url:U.url};else if(U.command)O[X]={command:U.command,...U.args?{args:U.args}:{},...U.env?{env:U.env}:{}};if(Object.keys(O).length>0){let X=X0(C,"mcp.json");w(X,{mcpServers:O},{header:!1}),L.push(X)}}}return this.createResult(L,W,F)}}function I0($,q,Y){try{S($),q.push($)}catch(Q){Y.push(`Could not remove ${$}: ${Q instanceof Error?Q.message:String(Q)}`)}}import{join as O0,resolve as u}from"path";var U0="copilot";class S0 extends y{id=U0;name="GitHub Copilot";supportedFeatures=["rules","commands","agents","skills","mcp","ignore","models"];generate($){let{projectRoot:q,baseDir:Y,features:Q,enabledFeatures:Z,deleteExisting:V}=$,H=u(q,Y),J=this.getEffectiveFeatures(Z),L=[],W=[],F=[],C=u(H,".github");if(J.includes("rules")){let B=Q.rules.filter((O)=>z(O,U0));if(B.length>0){let O=B.map((U)=>U.content).join(`
|
|
1615
12
|
|
|
1616
13
|
---
|
|
1617
14
|
|
|
1618
|
-
`);
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
filesWritten.push(filepath);
|
|
1623
|
-
}
|
|
1624
|
-
}
|
|
1625
|
-
if (effective.includes("agents")) {
|
|
1626
|
-
const copilotDir = resolve7(githubDir, "copilot");
|
|
1627
|
-
const agentsDir = resolve7(copilotDir, "agents");
|
|
1628
|
-
if (deleteExisting) {
|
|
1629
|
-
removeIfExists(agentsDir);
|
|
1630
|
-
filesDeleted.push(agentsDir);
|
|
1631
|
-
}
|
|
1632
|
-
ensureDir(agentsDir);
|
|
1633
|
-
const agents = features.agents.filter((a) => agentMatchesTarget(a, TARGET_ID3));
|
|
1634
|
-
for (const agent of agents) {
|
|
1635
|
-
const filepath = join11(agentsDir, `${agent.name}.md`);
|
|
1636
|
-
writeGeneratedFile(filepath, agent.content);
|
|
1637
|
-
filesWritten.push(filepath);
|
|
1638
|
-
}
|
|
1639
|
-
}
|
|
1640
|
-
if (effective.includes("skills")) {
|
|
1641
|
-
const copilotDir = resolve7(githubDir, "copilot");
|
|
1642
|
-
const skillsDir = resolve7(copilotDir, "skills");
|
|
1643
|
-
if (deleteExisting) {
|
|
1644
|
-
removeIfExists(skillsDir);
|
|
1645
|
-
filesDeleted.push(skillsDir);
|
|
1646
|
-
}
|
|
1647
|
-
ensureDir(skillsDir);
|
|
1648
|
-
const skills = features.skills.filter((s) => skillMatchesTarget(s, TARGET_ID3));
|
|
1649
|
-
for (const skill of skills) {
|
|
1650
|
-
const skillSubDir = join11(skillsDir, skill.name);
|
|
1651
|
-
ensureDir(skillSubDir);
|
|
1652
|
-
const filepath = join11(skillSubDir, "SKILL.md");
|
|
1653
|
-
writeGeneratedFile(filepath, serializeSkill(skill));
|
|
1654
|
-
filesWritten.push(filepath);
|
|
1655
|
-
}
|
|
1656
|
-
}
|
|
1657
|
-
if (effective.includes("commands")) {
|
|
1658
|
-
const copilotDir = resolve7(githubDir, "copilot");
|
|
1659
|
-
const commandsDir = resolve7(copilotDir, "commands");
|
|
1660
|
-
if (deleteExisting) {
|
|
1661
|
-
removeIfExists(commandsDir);
|
|
1662
|
-
filesDeleted.push(commandsDir);
|
|
1663
|
-
}
|
|
1664
|
-
ensureDir(commandsDir);
|
|
1665
|
-
const commands = features.commands.filter((c) => commandMatchesTarget(c, TARGET_ID3));
|
|
1666
|
-
for (const cmd of commands) {
|
|
1667
|
-
const filepath = join11(commandsDir, `${cmd.name}.md`);
|
|
1668
|
-
writeGeneratedFile(filepath, cmd.content);
|
|
1669
|
-
filesWritten.push(filepath);
|
|
1670
|
-
}
|
|
1671
|
-
}
|
|
1672
|
-
if (effective.includes("ignore")) {}
|
|
1673
|
-
if (effective.includes("models") && features.models) {
|
|
1674
|
-
const resolved = resolveModels(features.models, options.modelProfile, TARGET_ID3);
|
|
1675
|
-
const guidance = generateModelGuidanceMarkdown(resolved);
|
|
1676
|
-
if (guidance) {
|
|
1677
|
-
const copilotDir = resolve7(githubDir, "copilot");
|
|
1678
|
-
ensureDir(copilotDir);
|
|
1679
|
-
const filepath = join11(copilotDir, "model-config.md");
|
|
1680
|
-
writeGeneratedFile(filepath, guidance);
|
|
1681
|
-
filesWritten.push(filepath);
|
|
1682
|
-
}
|
|
1683
|
-
}
|
|
1684
|
-
return this.createResult(filesWritten, filesDeleted, warnings);
|
|
1685
|
-
}
|
|
1686
|
-
}
|
|
1687
|
-
|
|
1688
|
-
// src/targets/cursor.ts
|
|
1689
|
-
import { join as join12, resolve as resolve8 } from "path";
|
|
1690
|
-
var TARGET_ID4 = "cursor";
|
|
1691
|
-
|
|
1692
|
-
class CursorTarget extends BaseTarget {
|
|
1693
|
-
id = TARGET_ID4;
|
|
1694
|
-
name = "Cursor";
|
|
1695
|
-
supportedFeatures = [
|
|
1696
|
-
"rules",
|
|
1697
|
-
"commands",
|
|
1698
|
-
"agents",
|
|
1699
|
-
"skills",
|
|
1700
|
-
"hooks",
|
|
1701
|
-
"mcp",
|
|
1702
|
-
"ignore",
|
|
1703
|
-
"models"
|
|
1704
|
-
];
|
|
1705
|
-
generate(options) {
|
|
1706
|
-
const { projectRoot, baseDir, features, enabledFeatures, deleteExisting } = options;
|
|
1707
|
-
const root = resolve8(projectRoot, baseDir);
|
|
1708
|
-
const effective = this.getEffectiveFeatures(enabledFeatures);
|
|
1709
|
-
const filesWritten = [];
|
|
1710
|
-
const filesDeleted = [];
|
|
1711
|
-
const warnings = [];
|
|
1712
|
-
const cursorDir = resolve8(root, ".cursor");
|
|
1713
|
-
if (effective.includes("rules")) {
|
|
1714
|
-
const rulesDir = resolve8(cursorDir, "rules");
|
|
1715
|
-
if (deleteExisting) {
|
|
1716
|
-
removeIfExists(rulesDir);
|
|
1717
|
-
filesDeleted.push(rulesDir);
|
|
1718
|
-
}
|
|
1719
|
-
ensureDir(rulesDir);
|
|
1720
|
-
const rules = features.rules.filter((r) => ruleMatchesTarget(r, TARGET_ID4));
|
|
1721
|
-
for (const rule of rules) {
|
|
1722
|
-
const cursorMeta = rule.meta.cursor ?? {};
|
|
1723
|
-
const frontmatter = {
|
|
1724
|
-
description: cursorMeta.description ?? rule.meta.description ?? "",
|
|
1725
|
-
alwaysApply: cursorMeta.alwaysApply ?? rule.meta.root ?? false
|
|
1726
|
-
};
|
|
1727
|
-
const globs = cursorMeta.globs ?? rule.meta.globs;
|
|
1728
|
-
if (globs) {
|
|
1729
|
-
frontmatter.globs = globs;
|
|
1730
|
-
}
|
|
1731
|
-
const filepath = join12(rulesDir, `${rule.name}.mdc`);
|
|
1732
|
-
const content = serializeFrontmatter(frontmatter, rule.content);
|
|
1733
|
-
writeGeneratedFile(filepath, content);
|
|
1734
|
-
filesWritten.push(filepath);
|
|
1735
|
-
}
|
|
1736
|
-
}
|
|
1737
|
-
if (effective.includes("agents")) {
|
|
1738
|
-
const agentsDir = resolve8(cursorDir, "agents");
|
|
1739
|
-
if (deleteExisting) {
|
|
1740
|
-
removeIfExists(agentsDir);
|
|
1741
|
-
filesDeleted.push(agentsDir);
|
|
1742
|
-
}
|
|
1743
|
-
ensureDir(agentsDir);
|
|
1744
|
-
const resolvedModels = features.models ? resolveModels(features.models, options.modelProfile, TARGET_ID4) : null;
|
|
1745
|
-
const agents = features.agents.filter((a) => agentMatchesTarget(a, TARGET_ID4));
|
|
1746
|
-
for (const agent of agents) {
|
|
1747
|
-
const frontmatter = {
|
|
1748
|
-
name: agent.name,
|
|
1749
|
-
description: agent.meta.description ?? ""
|
|
1750
|
-
};
|
|
1751
|
-
const cursorMeta = agent.meta.cursor ?? {};
|
|
1752
|
-
const modelsAgent = resolvedModels?.agents[agent.name];
|
|
1753
|
-
const model = modelsAgent?.model ?? cursorMeta.model;
|
|
1754
|
-
if (model) {
|
|
1755
|
-
frontmatter.model = model;
|
|
1756
|
-
}
|
|
1757
|
-
const filepath = join12(agentsDir, `${agent.name}.md`);
|
|
1758
|
-
const content = serializeFrontmatter(frontmatter, agent.content);
|
|
1759
|
-
writeGeneratedFile(filepath, content);
|
|
1760
|
-
filesWritten.push(filepath);
|
|
1761
|
-
}
|
|
1762
|
-
}
|
|
1763
|
-
if (effective.includes("skills")) {
|
|
1764
|
-
const skillsDir = resolve8(cursorDir, "skills");
|
|
1765
|
-
if (deleteExisting) {
|
|
1766
|
-
removeIfExists(skillsDir);
|
|
1767
|
-
filesDeleted.push(skillsDir);
|
|
1768
|
-
}
|
|
1769
|
-
ensureDir(skillsDir);
|
|
1770
|
-
const skills = features.skills.filter((s) => skillMatchesTarget(s, TARGET_ID4));
|
|
1771
|
-
for (const skill of skills) {
|
|
1772
|
-
const skillSubDir = join12(skillsDir, skill.name);
|
|
1773
|
-
ensureDir(skillSubDir);
|
|
1774
|
-
const filepath = join12(skillSubDir, "SKILL.md");
|
|
1775
|
-
const content = serializeSkill(skill);
|
|
1776
|
-
writeGeneratedFile(filepath, content);
|
|
1777
|
-
filesWritten.push(filepath);
|
|
1778
|
-
}
|
|
1779
|
-
}
|
|
1780
|
-
if (effective.includes("commands")) {
|
|
1781
|
-
const commandsDir = resolve8(cursorDir, "commands");
|
|
1782
|
-
if (deleteExisting) {
|
|
1783
|
-
removeIfExists(commandsDir);
|
|
1784
|
-
filesDeleted.push(commandsDir);
|
|
1785
|
-
}
|
|
1786
|
-
ensureDir(commandsDir);
|
|
1787
|
-
const commands = features.commands.filter((c) => commandMatchesTarget(c, TARGET_ID4));
|
|
1788
|
-
for (const cmd of commands) {
|
|
1789
|
-
const filepath = join12(commandsDir, `${cmd.name}.md`);
|
|
1790
|
-
writeGeneratedFile(filepath, cmd.content);
|
|
1791
|
-
filesWritten.push(filepath);
|
|
1792
|
-
}
|
|
1793
|
-
}
|
|
1794
|
-
if (effective.includes("hooks")) {
|
|
1795
|
-
const hooksFilepath = resolve8(cursorDir, "hooks.json");
|
|
1796
|
-
if (deleteExisting) {
|
|
1797
|
-
removeIfExists(hooksFilepath);
|
|
1798
|
-
filesDeleted.push(hooksFilepath);
|
|
1799
|
-
}
|
|
1800
|
-
const mergedHooks = {};
|
|
1801
|
-
for (const hookSet of features.hooks) {
|
|
1802
|
-
const events = resolveHooksForTarget(hookSet, TARGET_ID4);
|
|
1803
|
-
for (const [event, entries] of Object.entries(events)) {
|
|
1804
|
-
if (!mergedHooks[event]) {
|
|
1805
|
-
mergedHooks[event] = [];
|
|
1806
|
-
}
|
|
1807
|
-
mergedHooks[event].push(...entries);
|
|
1808
|
-
}
|
|
1809
|
-
}
|
|
1810
|
-
if (Object.keys(mergedHooks).length > 0) {
|
|
1811
|
-
const hooksVersion = features.hooks.find((h) => h.version !== undefined)?.version ?? 1;
|
|
1812
|
-
writeGeneratedJson(hooksFilepath, { version: hooksVersion, hooks: mergedHooks }, { header: false });
|
|
1813
|
-
filesWritten.push(hooksFilepath);
|
|
1814
|
-
}
|
|
1815
|
-
}
|
|
1816
|
-
if (effective.includes("mcp")) {
|
|
1817
|
-
const mcpEntries = Object.entries(features.mcpServers);
|
|
1818
|
-
if (mcpEntries.length > 0) {
|
|
1819
|
-
const mcpConfig = buildCursorMcp(features.mcpServers);
|
|
1820
|
-
const filepath = resolve8(cursorDir, "mcp.json");
|
|
1821
|
-
writeGeneratedJson(filepath, mcpConfig, { header: false });
|
|
1822
|
-
filesWritten.push(filepath);
|
|
1823
|
-
}
|
|
1824
|
-
}
|
|
1825
|
-
if (effective.includes("ignore")) {
|
|
1826
|
-
if (features.ignorePatterns.length > 0) {
|
|
1827
|
-
const filepath = resolve8(root, ".cursorignore");
|
|
1828
|
-
const content = features.ignorePatterns.join(`
|
|
1829
|
-
`) + `
|
|
1830
|
-
`;
|
|
1831
|
-
writeGeneratedFile(filepath, content);
|
|
1832
|
-
filesWritten.push(filepath);
|
|
1833
|
-
}
|
|
1834
|
-
}
|
|
1835
|
-
if (effective.includes("models") && features.models) {
|
|
1836
|
-
const resolved = resolveModels(features.models, options.modelProfile, TARGET_ID4);
|
|
1837
|
-
const guidanceContent = buildCursorModelGuidance(resolved);
|
|
1838
|
-
if (guidanceContent) {
|
|
1839
|
-
const rulesDir = resolve8(cursorDir, "rules");
|
|
1840
|
-
ensureDir(rulesDir);
|
|
1841
|
-
const filepath = join12(rulesDir, "model-config.mdc");
|
|
1842
|
-
writeGeneratedFile(filepath, guidanceContent, { header: false });
|
|
1843
|
-
filesWritten.push(filepath);
|
|
1844
|
-
}
|
|
1845
|
-
}
|
|
1846
|
-
return this.createResult(filesWritten, filesDeleted, warnings);
|
|
1847
|
-
}
|
|
1848
|
-
}
|
|
1849
|
-
function buildCursorMcp(servers) {
|
|
1850
|
-
const mcpServers = {};
|
|
1851
|
-
for (const [name, entry] of Object.entries(servers)) {
|
|
1852
|
-
if (entry.url) {
|
|
1853
|
-
mcpServers[name] = { url: entry.url };
|
|
1854
|
-
} else if (entry.command) {
|
|
1855
|
-
mcpServers[name] = {
|
|
1856
|
-
command: entry.command,
|
|
1857
|
-
...entry.args ? { args: entry.args } : {},
|
|
1858
|
-
...entry.env ? { env: entry.env } : {}
|
|
1859
|
-
};
|
|
1860
|
-
}
|
|
1861
|
-
}
|
|
1862
|
-
return { mcpServers };
|
|
1863
|
-
}
|
|
1864
|
-
function buildCursorModelGuidance(resolved) {
|
|
1865
|
-
if (!resolved.default && !resolved.small && Object.keys(resolved.agents).length === 0) {
|
|
1866
|
-
return null;
|
|
1867
|
-
}
|
|
1868
|
-
const frontmatter = {
|
|
1869
|
-
description: "Model configuration and selection guidelines for this workspace",
|
|
1870
|
-
alwaysApply: true
|
|
1871
|
-
};
|
|
1872
|
-
const lines = [];
|
|
1873
|
-
lines.push("# Model Configuration");
|
|
1874
|
-
lines.push("");
|
|
1875
|
-
lines.push("Use the following model preferences when working in this project.");
|
|
1876
|
-
lines.push("");
|
|
1877
|
-
if (resolved.default || resolved.small) {
|
|
1878
|
-
lines.push("## Default Models");
|
|
1879
|
-
lines.push("");
|
|
1880
|
-
if (resolved.default) {
|
|
1881
|
-
lines.push(`- **Primary model**: ${resolved.default}`);
|
|
1882
|
-
}
|
|
1883
|
-
if (resolved.small) {
|
|
1884
|
-
lines.push(`- **Lightweight tasks** (titles, summaries): ${resolved.small}`);
|
|
1885
|
-
}
|
|
1886
|
-
lines.push("");
|
|
1887
|
-
}
|
|
1888
|
-
const agentEntries = Object.entries(resolved.agents);
|
|
1889
|
-
if (agentEntries.length > 0) {
|
|
1890
|
-
lines.push("## Agent Model Assignments");
|
|
1891
|
-
lines.push("");
|
|
1892
|
-
lines.push("| Agent | Model | Temperature |");
|
|
1893
|
-
lines.push("| --- | --- | --- |");
|
|
1894
|
-
for (const [name, assignment] of agentEntries) {
|
|
1895
|
-
const temp = assignment.temperature !== undefined ? String(assignment.temperature) : "\u2014";
|
|
1896
|
-
lines.push(`| ${name} | ${assignment.model} | ${temp} |`);
|
|
1897
|
-
}
|
|
1898
|
-
lines.push("");
|
|
1899
|
-
}
|
|
1900
|
-
if (Object.keys(resolved.profiles).length > 0) {
|
|
1901
|
-
lines.push("## Available Profiles");
|
|
1902
|
-
lines.push("");
|
|
1903
|
-
lines.push("| Profile | Description | Default Model |");
|
|
1904
|
-
lines.push("| --- | --- | --- |");
|
|
1905
|
-
for (const [name, profile] of Object.entries(resolved.profiles)) {
|
|
1906
|
-
lines.push(`| ${name} | ${profile.description ?? "\u2014"} | ${profile.default ?? "\u2014"} |`);
|
|
1907
|
-
}
|
|
1908
|
-
lines.push("");
|
|
1909
|
-
}
|
|
1910
|
-
if (resolved.activeProfile) {
|
|
1911
|
-
lines.push(`**Active profile**: \`${resolved.activeProfile}\``);
|
|
1912
|
-
lines.push("");
|
|
1913
|
-
}
|
|
1914
|
-
return serializeFrontmatter(frontmatter, lines.join(`
|
|
1915
|
-
`));
|
|
1916
|
-
}
|
|
1917
|
-
|
|
1918
|
-
// src/targets/gemini-cli.ts
|
|
1919
|
-
import { join as join13, resolve as resolve9 } from "path";
|
|
1920
|
-
var TARGET_ID5 = "geminicli";
|
|
15
|
+
`),X=u(C,"copilot-instructions.md");b(C),N(X,O),L.push(X)}}if(J.includes("agents")){let B=u(C,"copilot"),O=u(B,"agents");if(V)S(O),W.push(O);b(O);let X=Q.agents.filter((U)=>v(U,U0));for(let U of X){let K=O0(O,`${U.name}.md`);N(K,U.content),L.push(K)}}if(J.includes("skills")){let B=u(C,"copilot"),O=u(B,"skills");if(V)S(O),W.push(O);b(O);let X=Q.skills.filter((U)=>k(U,U0));for(let U of X){let K=O0(O,U.name);b(K);let _=O0(K,"SKILL.md");N(_,T(U)),L.push(_)}}if(J.includes("commands")){let B=u(C,"copilot"),O=u(B,"commands");if(V)S(O),W.push(O);b(O);let X=Q.commands.filter((U)=>j(U,U0));for(let U of X){let K=O0(O,`${U.name}.md`);N(K,U.content),L.push(K)}}if(J.includes("ignore"));if(J.includes("models")&&Q.models){let B=R(Q.models,$.modelProfile,U0),O=n(B);if(O){let X=u(C,"copilot");b(X);let U=O0(X,"model-config.md");N(U,O),L.push(U)}}return this.createResult(L,W,F)}}import{join as V0,resolve as m}from"path";var a="cursor";class G0 extends y{id=a;name="Cursor";supportedFeatures=["rules","commands","agents","skills","hooks","mcp","ignore","models"];generate($){let{projectRoot:q,baseDir:Y,features:Q,enabledFeatures:Z,deleteExisting:V}=$,H=m(q,Y),J=this.getEffectiveFeatures(Z),L=[],W=[],F=[],C=m(H,".cursor");if(J.includes("rules")){let B=m(C,"rules");if(V)S(B),W.push(B);b(B);let O=Q.rules.filter((X)=>z(X,a));for(let X of O){let U=X.meta.cursor??{},K={description:U.description??X.meta.description??"",alwaysApply:U.alwaysApply??X.meta.root??!1},_=U.globs??X.meta.globs;if(_)K.globs=_;let A=V0(B,`${X.name}.mdc`),I=p(K,X.content);N(A,I),L.push(A)}}if(J.includes("agents")){let B=m(C,"agents");if(V)S(B),W.push(B);b(B);let O=Q.models?R(Q.models,$.modelProfile,a):null,X=Q.agents.filter((U)=>v(U,a));for(let U of X){let K={name:U.name,description:U.meta.description??""},_=U.meta.cursor??{},I=O?.agents[U.name]?.model??_.model;if(I)K.model=I;let M=V0(B,`${U.name}.md`),$0=p(K,U.content);N(M,$0),L.push(M)}}if(J.includes("skills")){let B=m(C,"skills");if(V)S(B),W.push(B);b(B);let O=Q.skills.filter((X)=>k(X,a));for(let X of O){let U=V0(B,X.name);b(U);let K=V0(U,"SKILL.md"),_=T(X);N(K,_),L.push(K)}}if(J.includes("commands")){let B=m(C,"commands");if(V)S(B),W.push(B);b(B);let O=Q.commands.filter((X)=>j(X,a));for(let X of O){let U=V0(B,`${X.name}.md`);N(U,X.content),L.push(U)}}if(J.includes("hooks")){let B=m(C,"hooks.json");if(V)S(B),W.push(B);let O={};for(let X of Q.hooks){let U=o(X,a);for(let[K,_]of Object.entries(U)){if(!O[K])O[K]=[];O[K].push(..._)}}if(Object.keys(O).length>0){let X=Q.hooks.find((U)=>U.version!==void 0)?.version??1;w(B,{version:X,hooks:O},{header:!1}),L.push(B)}}if(J.includes("mcp")){if(Object.entries(Q.mcpServers).length>0){let O=M2(Q.mcpServers),X=m(C,"mcp.json");w(X,O,{header:!1}),L.push(X)}}if(J.includes("ignore")){if(Q.ignorePatterns.length>0){let B=m(H,".cursorignore"),O=Q.ignorePatterns.join(`
|
|
16
|
+
`)+`
|
|
17
|
+
`;N(B,O),L.push(B)}}if(J.includes("models")&&Q.models){let B=R(Q.models,$.modelProfile,a),O=y2(B);if(O){let X=m(C,"rules");b(X);let U=V0(X,"model-config.mdc");N(U,O,{header:!1}),L.push(U)}}return this.createResult(L,W,F)}}function M2($){let q={};for(let[Y,Q]of Object.entries($))if(Q.url)q[Y]={url:Q.url};else if(Q.command)q[Y]={command:Q.command,...Q.args?{args:Q.args}:{},...Q.env?{env:Q.env}:{}};return{mcpServers:q}}function y2($){if(!$.default&&!$.small&&Object.keys($.agents).length===0)return null;let q={description:"Model configuration and selection guidelines for this workspace",alwaysApply:!0},Y=[];if(Y.push("# Model Configuration"),Y.push(""),Y.push("Use the following model preferences when working in this project."),Y.push(""),$.default||$.small){if(Y.push("## Default Models"),Y.push(""),$.default)Y.push(`- **Primary model**: ${$.default}`);if($.small)Y.push(`- **Lightweight tasks** (titles, summaries): ${$.small}`);Y.push("")}let Q=Object.entries($.agents);if(Q.length>0){Y.push("## Agent Model Assignments"),Y.push(""),Y.push("| Agent | Model | Temperature |"),Y.push("| --- | --- | --- |");for(let[Z,V]of Q){let H=V.temperature!==void 0?String(V.temperature):"\u2014";Y.push(`| ${Z} | ${V.model} | ${H} |`)}Y.push("")}if(Object.keys($.profiles).length>0){Y.push("## Available Profiles"),Y.push(""),Y.push("| Profile | Description | Default Model |"),Y.push("| --- | --- | --- |");for(let[Z,V]of Object.entries($.profiles))Y.push(`| ${Z} | ${V.description??"\u2014"} | ${V.default??"\u2014"} |`);Y.push("")}if($.activeProfile)Y.push(`**Active profile**: \`${$.activeProfile}\``),Y.push("");return p(q,Y.join(`
|
|
18
|
+
`))}import{join as F1,resolve as t}from"path";var M0="geminicli";class y0 extends y{id=M0;name="Gemini CLI";supportedFeatures=["rules","commands","mcp","ignore","skills","hooks"];generate($){let{projectRoot:q,baseDir:Y,features:Q,enabledFeatures:Z,deleteExisting:V}=$,H=t(q,Y),J=this.getEffectiveFeatures(Z),L=[],W=[],F=[],C=t(H,".gemini");if(J.includes("rules")){let B=Q.rules.filter((U)=>z(U,M0)),O=W0(B),X=Q0(B);if(O.length>0){let U=O.map((_)=>_.content).join(`
|
|
1921
19
|
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
"commands",
|
|
1928
|
-
"mcp",
|
|
1929
|
-
"ignore",
|
|
1930
|
-
"skills",
|
|
1931
|
-
"hooks"
|
|
1932
|
-
];
|
|
1933
|
-
generate(options) {
|
|
1934
|
-
const { projectRoot, baseDir, features, enabledFeatures, deleteExisting } = options;
|
|
1935
|
-
const root = resolve9(projectRoot, baseDir);
|
|
1936
|
-
const effective = this.getEffectiveFeatures(enabledFeatures);
|
|
1937
|
-
const filesWritten = [];
|
|
1938
|
-
const filesDeleted = [];
|
|
1939
|
-
const warnings = [];
|
|
1940
|
-
const geminiDir = resolve9(root, ".gemini");
|
|
1941
|
-
if (effective.includes("rules")) {
|
|
1942
|
-
const rules = features.rules.filter((r) => ruleMatchesTarget(r, TARGET_ID5));
|
|
1943
|
-
const rootRules = getRootRules(rules);
|
|
1944
|
-
const detailRules = getDetailRules(rules);
|
|
1945
|
-
if (rootRules.length > 0) {
|
|
1946
|
-
const geminiMd = rootRules.map((r) => r.content).join(`
|
|
1947
|
-
|
|
1948
|
-
`);
|
|
1949
|
-
const filepath = resolve9(root, "GEMINI.md");
|
|
1950
|
-
writeGeneratedFile(filepath, geminiMd);
|
|
1951
|
-
filesWritten.push(filepath);
|
|
1952
|
-
}
|
|
1953
|
-
if (detailRules.length > 0) {
|
|
1954
|
-
const memoriesDir = resolve9(geminiDir, "memories");
|
|
1955
|
-
if (deleteExisting) {
|
|
1956
|
-
removeIfExists(memoriesDir);
|
|
1957
|
-
filesDeleted.push(memoriesDir);
|
|
1958
|
-
}
|
|
1959
|
-
ensureDir(memoriesDir);
|
|
1960
|
-
for (const rule of detailRules) {
|
|
1961
|
-
const filepath = join13(memoriesDir, `${rule.name}.md`);
|
|
1962
|
-
writeGeneratedFile(filepath, rule.content);
|
|
1963
|
-
filesWritten.push(filepath);
|
|
1964
|
-
}
|
|
1965
|
-
}
|
|
1966
|
-
}
|
|
1967
|
-
if (effective.includes("commands")) {
|
|
1968
|
-
const commandsDir = resolve9(geminiDir, "commands");
|
|
1969
|
-
if (deleteExisting) {
|
|
1970
|
-
removeIfExists(commandsDir);
|
|
1971
|
-
filesDeleted.push(commandsDir);
|
|
1972
|
-
}
|
|
1973
|
-
ensureDir(commandsDir);
|
|
1974
|
-
const commands = features.commands.filter((c) => commandMatchesTarget(c, TARGET_ID5));
|
|
1975
|
-
for (const cmd of commands) {
|
|
1976
|
-
const toml = buildGeminiCommand(cmd.name, cmd.meta.description ?? "", cmd.content);
|
|
1977
|
-
const filepath = join13(commandsDir, `${cmd.name}.toml`);
|
|
1978
|
-
writeGeneratedFile(filepath, toml, { type: "md" });
|
|
1979
|
-
filesWritten.push(filepath);
|
|
1980
|
-
}
|
|
1981
|
-
}
|
|
1982
|
-
if (effective.includes("mcp")) {
|
|
1983
|
-
const mcpEntries = Object.entries(features.mcpServers);
|
|
1984
|
-
if (mcpEntries.length > 0) {
|
|
1985
|
-
const settings = buildGeminiSettings(features.mcpServers);
|
|
1986
|
-
const filepath = resolve9(geminiDir, "settings.json");
|
|
1987
|
-
writeGeneratedJson(filepath, settings, { header: false });
|
|
1988
|
-
filesWritten.push(filepath);
|
|
1989
|
-
}
|
|
1990
|
-
}
|
|
1991
|
-
if (effective.includes("ignore")) {
|
|
1992
|
-
if (features.ignorePatterns.length > 0) {
|
|
1993
|
-
const filepath = resolve9(root, ".geminiignore");
|
|
1994
|
-
const content = features.ignorePatterns.join(`
|
|
1995
|
-
`) + `
|
|
1996
|
-
`;
|
|
1997
|
-
writeGeneratedFile(filepath, content);
|
|
1998
|
-
filesWritten.push(filepath);
|
|
1999
|
-
}
|
|
2000
|
-
}
|
|
2001
|
-
return this.createResult(filesWritten, filesDeleted, warnings);
|
|
2002
|
-
}
|
|
2003
|
-
}
|
|
2004
|
-
function buildGeminiCommand(name, description, content) {
|
|
2005
|
-
return `[command]
|
|
2006
|
-
name = "${name}"
|
|
2007
|
-
description = "${description}"
|
|
20
|
+
`),K=t(H,"GEMINI.md");N(K,U),L.push(K)}if(X.length>0){let U=t(C,"memories");if(V)S(U),W.push(U);b(U);for(let K of X){let _=F1(U,`${K.name}.md`);N(_,K.content),L.push(_)}}}if(J.includes("commands")){let B=t(C,"commands");if(V)S(B),W.push(B);b(B);let O=Q.commands.filter((X)=>j(X,M0));for(let X of O){let U=w2(X.name,X.meta.description??"",X.content),K=F1(B,`${X.name}.toml`);N(K,U,{type:"md"}),L.push(K)}}if(J.includes("mcp")){if(Object.entries(Q.mcpServers).length>0){let O=z2(Q.mcpServers),X=t(C,"settings.json");w(X,O,{header:!1}),L.push(X)}}if(J.includes("ignore")){if(Q.ignorePatterns.length>0){let B=t(H,".geminiignore"),O=Q.ignorePatterns.join(`
|
|
21
|
+
`)+`
|
|
22
|
+
`;N(B,O),L.push(B)}}return this.createResult(L,W,F)}}function w2($,q,Y){return`[command]
|
|
23
|
+
name = "${$}"
|
|
24
|
+
description = "${q}"
|
|
2008
25
|
|
|
2009
26
|
[prompt]
|
|
2010
27
|
content = """
|
|
2011
|
-
${
|
|
28
|
+
${Y}
|
|
2012
29
|
"""
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
function
|
|
2016
|
-
|
|
2017
|
-
for (const [name, entry] of Object.entries(servers)) {
|
|
2018
|
-
if (entry.command) {
|
|
2019
|
-
mcpServers[name] = {
|
|
2020
|
-
command: entry.command,
|
|
2021
|
-
...entry.args ? { args: entry.args } : {},
|
|
2022
|
-
...entry.env ? { env: entry.env } : {}
|
|
2023
|
-
};
|
|
2024
|
-
} else if (entry.url) {
|
|
2025
|
-
mcpServers[name] = { url: entry.url };
|
|
2026
|
-
}
|
|
2027
|
-
}
|
|
2028
|
-
return { mcpServers };
|
|
2029
|
-
}
|
|
2030
|
-
|
|
2031
|
-
// src/targets/mistral-vibe.ts
|
|
2032
|
-
import { join as join14, resolve as resolve10 } from "path";
|
|
2033
|
-
var TARGET_ID6 = "mistralvibe";
|
|
2034
|
-
|
|
2035
|
-
class MistralVibeTarget extends BaseTarget {
|
|
2036
|
-
id = TARGET_ID6;
|
|
2037
|
-
name = "Mistral Vibe";
|
|
2038
|
-
supportedFeatures = [
|
|
2039
|
-
"rules",
|
|
2040
|
-
"commands",
|
|
2041
|
-
"agents",
|
|
2042
|
-
"skills",
|
|
2043
|
-
"mcp",
|
|
2044
|
-
"ignore",
|
|
2045
|
-
"models"
|
|
2046
|
-
];
|
|
2047
|
-
generate(options) {
|
|
2048
|
-
const { projectRoot, baseDir, features, enabledFeatures, deleteExisting } = options;
|
|
2049
|
-
const root = resolve10(projectRoot, baseDir);
|
|
2050
|
-
const effective = this.getEffectiveFeatures(enabledFeatures);
|
|
2051
|
-
const filesWritten = [];
|
|
2052
|
-
const filesDeleted = [];
|
|
2053
|
-
const warnings = [];
|
|
2054
|
-
const vibeDir = resolve10(root, ".vibe");
|
|
2055
|
-
ensureDir(vibeDir);
|
|
2056
|
-
if (effective.includes("rules")) {
|
|
2057
|
-
const rulesDir = resolve10(vibeDir, "rules");
|
|
2058
|
-
if (deleteExisting) {
|
|
2059
|
-
removeIfExists(rulesDir);
|
|
2060
|
-
filesDeleted.push(rulesDir);
|
|
2061
|
-
}
|
|
2062
|
-
ensureDir(rulesDir);
|
|
2063
|
-
const rules = features.rules.filter((r) => ruleMatchesTarget(r, TARGET_ID6));
|
|
2064
|
-
for (const rule of rules) {
|
|
2065
|
-
const filepath = join14(rulesDir, `${rule.name}.md`);
|
|
2066
|
-
writeGeneratedFile(filepath, rule.content);
|
|
2067
|
-
filesWritten.push(filepath);
|
|
2068
|
-
}
|
|
2069
|
-
}
|
|
2070
|
-
if (effective.includes("agents")) {
|
|
2071
|
-
const agentsDir = resolve10(vibeDir, "agents");
|
|
2072
|
-
if (deleteExisting) {
|
|
2073
|
-
removeIfExists(agentsDir);
|
|
2074
|
-
filesDeleted.push(agentsDir);
|
|
2075
|
-
}
|
|
2076
|
-
ensureDir(agentsDir);
|
|
2077
|
-
const agents = features.agents.filter((a) => agentMatchesTarget(a, TARGET_ID6));
|
|
2078
|
-
for (const agent of agents) {
|
|
2079
|
-
const filepath = join14(agentsDir, `${agent.name}.md`);
|
|
2080
|
-
writeGeneratedFile(filepath, agent.content);
|
|
2081
|
-
filesWritten.push(filepath);
|
|
2082
|
-
}
|
|
2083
|
-
}
|
|
2084
|
-
if (effective.includes("skills")) {
|
|
2085
|
-
const skillsDir = resolve10(vibeDir, "skills");
|
|
2086
|
-
if (deleteExisting) {
|
|
2087
|
-
removeIfExists(skillsDir);
|
|
2088
|
-
filesDeleted.push(skillsDir);
|
|
2089
|
-
}
|
|
2090
|
-
ensureDir(skillsDir);
|
|
2091
|
-
const skills = features.skills.filter((s) => skillMatchesTarget(s, TARGET_ID6));
|
|
2092
|
-
for (const skill of skills) {
|
|
2093
|
-
const skillSubDir = join14(skillsDir, skill.name);
|
|
2094
|
-
ensureDir(skillSubDir);
|
|
2095
|
-
const filepath = join14(skillSubDir, "SKILL.md");
|
|
2096
|
-
writeGeneratedFile(filepath, serializeSkill(skill));
|
|
2097
|
-
filesWritten.push(filepath);
|
|
2098
|
-
}
|
|
2099
|
-
}
|
|
2100
|
-
if (effective.includes("commands")) {
|
|
2101
|
-
const commandsDir = resolve10(vibeDir, "commands");
|
|
2102
|
-
if (deleteExisting) {
|
|
2103
|
-
removeIfExists(commandsDir);
|
|
2104
|
-
filesDeleted.push(commandsDir);
|
|
2105
|
-
}
|
|
2106
|
-
ensureDir(commandsDir);
|
|
2107
|
-
const commands = features.commands.filter((c) => commandMatchesTarget(c, TARGET_ID6));
|
|
2108
|
-
for (const command of commands) {
|
|
2109
|
-
const filepath = join14(commandsDir, `${command.name}.md`);
|
|
2110
|
-
writeGeneratedFile(filepath, command.content);
|
|
2111
|
-
filesWritten.push(filepath);
|
|
2112
|
-
}
|
|
2113
|
-
}
|
|
2114
|
-
let hasMcpConfig = false;
|
|
2115
|
-
if (effective.includes("mcp")) {
|
|
2116
|
-
const mcpEntries = Object.entries(features.mcpServers);
|
|
2117
|
-
if (mcpEntries.length > 0) {
|
|
2118
|
-
const filepath = resolve10(vibeDir, "mcp.json");
|
|
2119
|
-
writeGeneratedJson(filepath, { mcpServers: features.mcpServers }, {
|
|
2120
|
-
header: false
|
|
2121
|
-
});
|
|
2122
|
-
filesWritten.push(filepath);
|
|
2123
|
-
hasMcpConfig = true;
|
|
2124
|
-
}
|
|
2125
|
-
}
|
|
2126
|
-
if (effective.includes("ignore") && features.ignorePatterns.length > 0) {
|
|
2127
|
-
const filepath = resolve10(root, ".vibeignore");
|
|
2128
|
-
writeGeneratedFile(filepath, features.ignorePatterns.join(`
|
|
2129
|
-
`) + `
|
|
2130
|
-
`);
|
|
2131
|
-
filesWritten.push(filepath);
|
|
2132
|
-
}
|
|
2133
|
-
let defaultModel;
|
|
2134
|
-
let smallModel;
|
|
2135
|
-
if (effective.includes("models") && features.models) {
|
|
2136
|
-
const resolved = resolveModels(features.models, options.modelProfile, TARGET_ID6);
|
|
2137
|
-
defaultModel = resolved.default;
|
|
2138
|
-
smallModel = resolved.small;
|
|
2139
|
-
const guidance = generateModelGuidanceMarkdown(resolved);
|
|
2140
|
-
if (guidance) {
|
|
2141
|
-
const filepath = join14(vibeDir, "model-config.md");
|
|
2142
|
-
writeGeneratedFile(filepath, guidance);
|
|
2143
|
-
filesWritten.push(filepath);
|
|
2144
|
-
}
|
|
2145
|
-
}
|
|
2146
|
-
const vibeConfig = buildVibeConfigToml({
|
|
2147
|
-
hasMcpConfig,
|
|
2148
|
-
defaultModel,
|
|
2149
|
-
smallModel,
|
|
2150
|
-
profile: options.modelProfile
|
|
2151
|
-
});
|
|
2152
|
-
if (vibeConfig.length > 0) {
|
|
2153
|
-
const filepath = resolve10(vibeDir, "config.toml");
|
|
2154
|
-
writeGeneratedFile(filepath, vibeConfig);
|
|
2155
|
-
filesWritten.push(filepath);
|
|
2156
|
-
}
|
|
2157
|
-
return this.createResult(filesWritten, filesDeleted, warnings);
|
|
2158
|
-
}
|
|
2159
|
-
}
|
|
2160
|
-
function buildVibeConfigToml(options) {
|
|
2161
|
-
const lines = [];
|
|
2162
|
-
if (options.defaultModel || options.smallModel || options.profile) {
|
|
2163
|
-
lines.push("[models]");
|
|
2164
|
-
if (options.defaultModel) {
|
|
2165
|
-
lines.push(`default = "${escapeTomlString(options.defaultModel)}"`);
|
|
2166
|
-
}
|
|
2167
|
-
if (options.smallModel) {
|
|
2168
|
-
lines.push(`small = "${escapeTomlString(options.smallModel)}"`);
|
|
2169
|
-
}
|
|
2170
|
-
if (options.profile) {
|
|
2171
|
-
lines.push(`profile = "${escapeTomlString(options.profile)}"`);
|
|
2172
|
-
}
|
|
2173
|
-
lines.push("");
|
|
2174
|
-
}
|
|
2175
|
-
if (options.hasMcpConfig) {
|
|
2176
|
-
lines.push("[mcp]");
|
|
2177
|
-
lines.push('config_path = ".vibe/mcp.json"');
|
|
2178
|
-
lines.push("");
|
|
2179
|
-
}
|
|
2180
|
-
return lines.join(`
|
|
2181
|
-
`).trim();
|
|
2182
|
-
}
|
|
2183
|
-
function escapeTomlString(value) {
|
|
2184
|
-
return value.replace(/\\/g, "\\\\").replace(/"/g, "\\\"");
|
|
2185
|
-
}
|
|
2186
|
-
|
|
2187
|
-
// src/utils/markdown.ts
|
|
2188
|
-
function stripGeneratedHeader(content) {
|
|
2189
|
-
return content.replace(/^<!-- Generated by agentpacks.*-->\n/, "").replace(/^\/\/ Generated by agentpacks.*\n/, "");
|
|
2190
|
-
}
|
|
2191
|
-
function packNameToIdentifier(packName) {
|
|
2192
|
-
return packName.split(/[-_.]/).filter((part) => part.length > 0).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
|
|
2193
|
-
}
|
|
2194
|
-
function extractFirstHeading(content) {
|
|
2195
|
-
const match = content.match(/^#{1,6}\s+(.+)$/m);
|
|
2196
|
-
return match?.[1]?.trim() ?? null;
|
|
2197
|
-
}
|
|
2198
|
-
function combineMarkdown(sections, separator = `
|
|
30
|
+
`}function z2($){let q={};for(let[Y,Q]of Object.entries($))if(Q.command)q[Y]={command:Q.command,...Q.args?{args:Q.args}:{},...Q.env?{env:Q.env}:{}};else if(Q.url)q[Y]={url:Q.url};return{mcpServers:q}}import{join as B0,resolve as c}from"path";var K0="mistralvibe";class z0 extends y{id=K0;name="Mistral Vibe";supportedFeatures=["rules","commands","agents","skills","mcp","ignore","models"];generate($){let{projectRoot:q,baseDir:Y,features:Q,enabledFeatures:Z,deleteExisting:V}=$,H=c(q,Y),J=this.getEffectiveFeatures(Z),L=[],W=[],F=[],C=c(H,".vibe");if(b(C),J.includes("rules")){let K=c(C,"rules");if(V)S(K),W.push(K);b(K);let _=Q.rules.filter((A)=>z(A,K0));for(let A of _){let I=B0(K,`${A.name}.md`);N(I,A.content),L.push(I)}}if(J.includes("agents")){let K=c(C,"agents");if(V)S(K),W.push(K);b(K);let _=Q.agents.filter((A)=>v(A,K0));for(let A of _){let I=B0(K,`${A.name}.md`);N(I,A.content),L.push(I)}}if(J.includes("skills")){let K=c(C,"skills");if(V)S(K),W.push(K);b(K);let _=Q.skills.filter((A)=>k(A,K0));for(let A of _){let I=B0(K,A.name);b(I);let M=B0(I,"SKILL.md");N(M,T(A)),L.push(M)}}if(J.includes("commands")){let K=c(C,"commands");if(V)S(K),W.push(K);b(K);let _=Q.commands.filter((A)=>j(A,K0));for(let A of _){let I=B0(K,`${A.name}.md`);N(I,A.content),L.push(I)}}let B=!1;if(J.includes("mcp")){if(Object.entries(Q.mcpServers).length>0){let _=c(C,"mcp.json");w(_,{mcpServers:Q.mcpServers},{header:!1}),L.push(_),B=!0}}if(J.includes("ignore")&&Q.ignorePatterns.length>0){let K=c(H,".vibeignore");N(K,Q.ignorePatterns.join(`
|
|
31
|
+
`)+`
|
|
32
|
+
`),L.push(K)}let O,X;if(J.includes("models")&&Q.models){let K=R(Q.models,$.modelProfile,K0);O=K.default,X=K.small;let _=n(K);if(_){let A=B0(C,"model-config.md");N(A,_),L.push(A)}}let U=R2({hasMcpConfig:B,defaultModel:O,smallModel:X,profile:$.modelProfile});if(U.length>0){let K=c(C,"config.toml");N(K,U),L.push(K)}return this.createResult(L,W,F)}}function R2($){let q=[];if($.defaultModel||$.smallModel||$.profile){if(q.push("[models]"),$.defaultModel)q.push(`default = "${w0($.defaultModel)}"`);if($.smallModel)q.push(`small = "${w0($.smallModel)}"`);if($.profile)q.push(`profile = "${w0($.profile)}"`);q.push("")}if($.hasMcpConfig)q.push("[mcp]"),q.push('config_path = ".vibe/mcp.json"'),q.push("");return q.join(`
|
|
33
|
+
`).trim()}function w0($){return $.replace(/\\/g,"\\\\").replace(/"/g,"\\\"")}function N6($){return $.replace(/^<!-- Generated by agentpacks.*-->\n/,"").replace(/^\/\/ Generated by agentpacks.*\n/,"")}function S1($){return $.split(/[-_.]/).filter((q)=>q.length>0).map((q)=>q.charAt(0).toUpperCase()+q.slice(1)).join("")}function b6($){return $.match(/^#{1,6}\s+(.+)$/m)?.[1]?.trim()??null}function I6($,q=`
|
|
2199
34
|
|
|
2200
35
|
---
|
|
2201
36
|
|
|
2202
|
-
`) {
|
|
2203
|
-
return sections.filter(Boolean).join(separator);
|
|
2204
|
-
}
|
|
2205
|
-
function wrapSection(heading, content, level = 2) {
|
|
2206
|
-
const prefix = "#".repeat(level);
|
|
2207
|
-
return `${prefix} ${heading}
|
|
37
|
+
`){return $.filter(Boolean).join(q)}function F6($,q,Y=2){return`${"#".repeat(Y)} ${$}
|
|
2208
38
|
|
|
2209
|
-
${content}
|
|
2210
|
-
}
|
|
39
|
+
${q}`}import{join as e,resolve as s}from"path";var i="opencode";class R0 extends y{id=i;name="OpenCode";supportedFeatures=["rules","commands","agents","skills","hooks","plugins","mcp","ignore","models"];generate($){let{projectRoot:q,baseDir:Y,features:Q,enabledFeatures:Z,deleteExisting:V}=$,H=s(q,Y),J=this.getEffectiveFeatures(Z),L=[],W=[],F=[],C=s(H,".opencode");if(J.includes("agents")){let B=s(C,"agent");if(V)S(B),W.push(B);b(B);let O=Q.models?R(Q.models,$.modelProfile,i):null,X=Q.agents.filter((U)=>v(U,i));for(let U of X){let K=e(B,`${U.name}.md`),_={},A=U.meta.opencode??{},I=O?.agents[U.name],M=I?.model??A.model,$0=I?.temperature??A.temperature;if(M)_.model=M;if($0!==void 0)_.temperature=$0;if(A.mode)_.mode=A.mode;if(A.top_p!==void 0)_.top_p=A.top_p;let L0=Object.keys(_).length>0?p(_,U.content):U.content;N(K,L0),L.push(K)}}if(J.includes("skills")){let B=s(C,"skill");if(V)S(B),W.push(B);b(B);let O=Q.skills.filter((X)=>k(X,i));for(let X of O){let U=e(B,X.name);b(U);let K=e(U,"SKILL.md");N(K,T(X)),L.push(K)}}if(J.includes("commands")){let B=s(C,"command");if(V)S(B),W.push(B);b(B);let O=Q.commands.filter((X)=>j(X,i));for(let X of O){let U=e(B,`${X.name}.md`);N(U,X.content),L.push(U)}}if(J.includes("hooks")||J.includes("plugins")){let B=s(C,"plugins");if(b(B),J.includes("hooks"))for(let O of Q.hooks){let X=o(O,i);if(Object.keys(X).length>0){let U=e(B,`agentpacks-${O.packName}.ts`),K=E2(O.packName,X);N(U,K,{type:"ts"}),L.push(U)}}if(J.includes("plugins"))for(let O of Q.plugins){let X=e(B,`agentpacks-${O.packName}-${O.name}.${O.extension}`);N(X,O.content,{type:O.extension}),L.push(X)}}if(J.includes("mcp")||J.includes("models")){let B=s(H,"opencode.json"),O={$schema:"https://opencode.ai/config.json"};if(J.includes("mcp")){if(Object.entries(Q.mcpServers).length>0)O.mcp=j2(Q.mcpServers)}if(J.includes("models")&&Q.models){let X=R(Q.models,$.modelProfile,i);if(X.default)O.model=X.default;if(X.small)O.small_model=X.small;if(Object.keys(X.providers).length>0)O.provider=X.providers;let U=Object.entries(X.agents);if(U.length>0){let K={};for(let[_,A]of U){let I={model:A.model};if(A.temperature!==void 0)I.temperature=A.temperature;if(A.top_p!==void 0)I.top_p=A.top_p;K[_]=I}O.agent=K}}if(Object.keys(O).length>1)w(B,O,{header:!1}),L.push(B)}if(J.includes("rules")){let B=Q.rules.filter((X)=>z(X,i)),O=Q0(B);if(O.length>0){let X=s(C,"memories");if(V)S(X),W.push(X);b(X);for(let U of O){let K=e(X,`${U.name}.md`);N(K,U.content),L.push(K)}}}return this.createResult(L,W,F)}}function j2($){let q={};for(let[Y,Q]of Object.entries($))if(Q.url)q[Y]={type:"remote",url:Q.url,enabled:!0,...Q.headers&&Object.keys(Q.headers).length>0?{headers:Q.headers}:{}};else if(Q.command){let Z=Q.args?[Q.command,...Q.args]:[Q.command];q[Y]={type:"local",command:Z,enabled:!0,...Q.env&&Object.keys(Q.env).length>0?{environment:Q.env}:{}}}return q}function E2($,q){let Y=S1($),Q=T2(q),Z=Object.entries(Q).map(([V,H])=>{let J=H.map((L)=>{return` ${L.matcher?`if (!/(?:${L.matcher})/.test(String(input?.tool ?? ""))) return;
|
|
40
|
+
`:""}await $\`${L.command}\`;`}).join(`
|
|
41
|
+
`);return` "${V}": async (input, output) => {
|
|
42
|
+
${J}
|
|
43
|
+
},`}).join(`
|
|
44
|
+
`);return`import type { Plugin } from "@opencode-ai/plugin";
|
|
2211
45
|
|
|
2212
|
-
|
|
2213
|
-
import { join as join15, resolve as resolve11 } from "path";
|
|
2214
|
-
var TARGET_ID7 = "opencode";
|
|
2215
|
-
|
|
2216
|
-
class OpenCodeTarget extends BaseTarget {
|
|
2217
|
-
id = TARGET_ID7;
|
|
2218
|
-
name = "OpenCode";
|
|
2219
|
-
supportedFeatures = [
|
|
2220
|
-
"rules",
|
|
2221
|
-
"commands",
|
|
2222
|
-
"agents",
|
|
2223
|
-
"skills",
|
|
2224
|
-
"hooks",
|
|
2225
|
-
"plugins",
|
|
2226
|
-
"mcp",
|
|
2227
|
-
"ignore",
|
|
2228
|
-
"models"
|
|
2229
|
-
];
|
|
2230
|
-
generate(options) {
|
|
2231
|
-
const { projectRoot, baseDir, features, enabledFeatures, deleteExisting } = options;
|
|
2232
|
-
const root = resolve11(projectRoot, baseDir);
|
|
2233
|
-
const effective = this.getEffectiveFeatures(enabledFeatures);
|
|
2234
|
-
const filesWritten = [];
|
|
2235
|
-
const filesDeleted = [];
|
|
2236
|
-
const warnings = [];
|
|
2237
|
-
const opencodeDir = resolve11(root, ".opencode");
|
|
2238
|
-
if (effective.includes("agents")) {
|
|
2239
|
-
const agentDir = resolve11(opencodeDir, "agent");
|
|
2240
|
-
if (deleteExisting) {
|
|
2241
|
-
removeIfExists(agentDir);
|
|
2242
|
-
filesDeleted.push(agentDir);
|
|
2243
|
-
}
|
|
2244
|
-
ensureDir(agentDir);
|
|
2245
|
-
const resolvedModels = features.models ? resolveModels(features.models, options.modelProfile, TARGET_ID7) : null;
|
|
2246
|
-
const agents = features.agents.filter((a) => agentMatchesTarget(a, TARGET_ID7));
|
|
2247
|
-
for (const agent of agents) {
|
|
2248
|
-
const filepath = join15(agentDir, `${agent.name}.md`);
|
|
2249
|
-
const fm = {};
|
|
2250
|
-
const oc = agent.meta.opencode ?? {};
|
|
2251
|
-
const modelsAgent = resolvedModels?.agents[agent.name];
|
|
2252
|
-
const agentModel = modelsAgent?.model ?? oc.model;
|
|
2253
|
-
const agentTemp = modelsAgent?.temperature ?? oc.temperature;
|
|
2254
|
-
if (agentModel)
|
|
2255
|
-
fm.model = agentModel;
|
|
2256
|
-
if (agentTemp !== undefined)
|
|
2257
|
-
fm.temperature = agentTemp;
|
|
2258
|
-
if (oc.mode)
|
|
2259
|
-
fm.mode = oc.mode;
|
|
2260
|
-
if (oc.top_p !== undefined)
|
|
2261
|
-
fm.top_p = oc.top_p;
|
|
2262
|
-
const content = Object.keys(fm).length > 0 ? serializeFrontmatter(fm, agent.content) : agent.content;
|
|
2263
|
-
writeGeneratedFile(filepath, content);
|
|
2264
|
-
filesWritten.push(filepath);
|
|
2265
|
-
}
|
|
2266
|
-
}
|
|
2267
|
-
if (effective.includes("skills")) {
|
|
2268
|
-
const skillDir = resolve11(opencodeDir, "skill");
|
|
2269
|
-
if (deleteExisting) {
|
|
2270
|
-
removeIfExists(skillDir);
|
|
2271
|
-
filesDeleted.push(skillDir);
|
|
2272
|
-
}
|
|
2273
|
-
ensureDir(skillDir);
|
|
2274
|
-
const skills = features.skills.filter((s) => skillMatchesTarget(s, TARGET_ID7));
|
|
2275
|
-
for (const skill of skills) {
|
|
2276
|
-
const skillSubDir = join15(skillDir, skill.name);
|
|
2277
|
-
ensureDir(skillSubDir);
|
|
2278
|
-
const filepath = join15(skillSubDir, "SKILL.md");
|
|
2279
|
-
writeGeneratedFile(filepath, serializeSkill(skill));
|
|
2280
|
-
filesWritten.push(filepath);
|
|
2281
|
-
}
|
|
2282
|
-
}
|
|
2283
|
-
if (effective.includes("commands")) {
|
|
2284
|
-
const cmdDir = resolve11(opencodeDir, "command");
|
|
2285
|
-
if (deleteExisting) {
|
|
2286
|
-
removeIfExists(cmdDir);
|
|
2287
|
-
filesDeleted.push(cmdDir);
|
|
2288
|
-
}
|
|
2289
|
-
ensureDir(cmdDir);
|
|
2290
|
-
const commands = features.commands.filter((c) => commandMatchesTarget(c, TARGET_ID7));
|
|
2291
|
-
for (const cmd of commands) {
|
|
2292
|
-
const filepath = join15(cmdDir, `${cmd.name}.md`);
|
|
2293
|
-
writeGeneratedFile(filepath, cmd.content);
|
|
2294
|
-
filesWritten.push(filepath);
|
|
2295
|
-
}
|
|
2296
|
-
}
|
|
2297
|
-
if (effective.includes("hooks") || effective.includes("plugins")) {
|
|
2298
|
-
const pluginsDir = resolve11(opencodeDir, "plugins");
|
|
2299
|
-
ensureDir(pluginsDir);
|
|
2300
|
-
if (effective.includes("hooks")) {
|
|
2301
|
-
for (const hookSet of features.hooks) {
|
|
2302
|
-
const events = resolveHooksForTarget(hookSet, TARGET_ID7);
|
|
2303
|
-
if (Object.keys(events).length > 0) {
|
|
2304
|
-
const filepath = join15(pluginsDir, `agentpacks-${hookSet.packName}.ts`);
|
|
2305
|
-
const content = generateOpenCodeHookPlugin(hookSet.packName, events);
|
|
2306
|
-
writeGeneratedFile(filepath, content, { type: "ts" });
|
|
2307
|
-
filesWritten.push(filepath);
|
|
2308
|
-
}
|
|
2309
|
-
}
|
|
2310
|
-
}
|
|
2311
|
-
if (effective.includes("plugins")) {
|
|
2312
|
-
for (const plugin of features.plugins) {
|
|
2313
|
-
const filepath = join15(pluginsDir, `agentpacks-${plugin.packName}-${plugin.name}.${plugin.extension}`);
|
|
2314
|
-
writeGeneratedFile(filepath, plugin.content, {
|
|
2315
|
-
type: plugin.extension
|
|
2316
|
-
});
|
|
2317
|
-
filesWritten.push(filepath);
|
|
2318
|
-
}
|
|
2319
|
-
}
|
|
2320
|
-
}
|
|
2321
|
-
if (effective.includes("mcp") || effective.includes("models")) {
|
|
2322
|
-
const filepath = resolve11(root, "opencode.json");
|
|
2323
|
-
const opencodeConfig = {
|
|
2324
|
-
$schema: "https://opencode.ai/config.json"
|
|
2325
|
-
};
|
|
2326
|
-
if (effective.includes("mcp")) {
|
|
2327
|
-
const mcpEntries = Object.entries(features.mcpServers);
|
|
2328
|
-
if (mcpEntries.length > 0) {
|
|
2329
|
-
opencodeConfig.mcp = buildOpenCodeMcpServers(features.mcpServers);
|
|
2330
|
-
}
|
|
2331
|
-
}
|
|
2332
|
-
if (effective.includes("models") && features.models) {
|
|
2333
|
-
const resolved = resolveModels(features.models, options.modelProfile, TARGET_ID7);
|
|
2334
|
-
if (resolved.default)
|
|
2335
|
-
opencodeConfig.model = resolved.default;
|
|
2336
|
-
if (resolved.small)
|
|
2337
|
-
opencodeConfig.small_model = resolved.small;
|
|
2338
|
-
if (Object.keys(resolved.providers).length > 0) {
|
|
2339
|
-
opencodeConfig.provider = resolved.providers;
|
|
2340
|
-
}
|
|
2341
|
-
const agentEntries = Object.entries(resolved.agents);
|
|
2342
|
-
if (agentEntries.length > 0) {
|
|
2343
|
-
const agentConfig = {};
|
|
2344
|
-
for (const [name, assignment] of agentEntries) {
|
|
2345
|
-
const config = { model: assignment.model };
|
|
2346
|
-
if (assignment.temperature !== undefined) {
|
|
2347
|
-
config.temperature = assignment.temperature;
|
|
2348
|
-
}
|
|
2349
|
-
if (assignment.top_p !== undefined) {
|
|
2350
|
-
config.top_p = assignment.top_p;
|
|
2351
|
-
}
|
|
2352
|
-
agentConfig[name] = config;
|
|
2353
|
-
}
|
|
2354
|
-
opencodeConfig.agent = agentConfig;
|
|
2355
|
-
}
|
|
2356
|
-
}
|
|
2357
|
-
if (Object.keys(opencodeConfig).length > 1) {
|
|
2358
|
-
writeGeneratedJson(filepath, opencodeConfig, { header: false });
|
|
2359
|
-
filesWritten.push(filepath);
|
|
2360
|
-
}
|
|
2361
|
-
}
|
|
2362
|
-
if (effective.includes("rules")) {
|
|
2363
|
-
const rules = features.rules.filter((r) => ruleMatchesTarget(r, TARGET_ID7));
|
|
2364
|
-
const detailRules = getDetailRules(rules);
|
|
2365
|
-
if (detailRules.length > 0) {
|
|
2366
|
-
const memoriesDir = resolve11(opencodeDir, "memories");
|
|
2367
|
-
if (deleteExisting) {
|
|
2368
|
-
removeIfExists(memoriesDir);
|
|
2369
|
-
filesDeleted.push(memoriesDir);
|
|
2370
|
-
}
|
|
2371
|
-
ensureDir(memoriesDir);
|
|
2372
|
-
for (const rule of detailRules) {
|
|
2373
|
-
const filepath = join15(memoriesDir, `${rule.name}.md`);
|
|
2374
|
-
writeGeneratedFile(filepath, rule.content);
|
|
2375
|
-
filesWritten.push(filepath);
|
|
2376
|
-
}
|
|
2377
|
-
}
|
|
2378
|
-
}
|
|
2379
|
-
return this.createResult(filesWritten, filesDeleted, warnings);
|
|
2380
|
-
}
|
|
2381
|
-
}
|
|
2382
|
-
function buildOpenCodeMcpServers(servers) {
|
|
2383
|
-
const mcp = {};
|
|
2384
|
-
for (const [name, entry] of Object.entries(servers)) {
|
|
2385
|
-
if (entry.url) {
|
|
2386
|
-
mcp[name] = {
|
|
2387
|
-
type: "remote",
|
|
2388
|
-
url: entry.url,
|
|
2389
|
-
enabled: true,
|
|
2390
|
-
...entry.headers && Object.keys(entry.headers).length > 0 ? { headers: entry.headers } : {}
|
|
2391
|
-
};
|
|
2392
|
-
} else if (entry.command) {
|
|
2393
|
-
const cmd = entry.args ? [entry.command, ...entry.args] : [entry.command];
|
|
2394
|
-
mcp[name] = {
|
|
2395
|
-
type: "local",
|
|
2396
|
-
command: cmd,
|
|
2397
|
-
enabled: true,
|
|
2398
|
-
...entry.env && Object.keys(entry.env).length > 0 ? { environment: entry.env } : {}
|
|
2399
|
-
};
|
|
2400
|
-
}
|
|
2401
|
-
}
|
|
2402
|
-
return mcp;
|
|
2403
|
-
}
|
|
2404
|
-
function generateOpenCodeHookPlugin(packName, events) {
|
|
2405
|
-
const identifier = packNameToIdentifier(packName);
|
|
2406
|
-
const hookMap = mapHookEvents(events);
|
|
2407
|
-
const hookEntries = Object.entries(hookMap).map(([event, handlers]) => {
|
|
2408
|
-
const body = handlers.map((h) => {
|
|
2409
|
-
const matcherGuard = h.matcher ? `if (!/(?:${h.matcher})/.test(String(input?.tool ?? ""))) return;
|
|
2410
|
-
` : "";
|
|
2411
|
-
return ` ${matcherGuard}await $\`${h.command}\`;`;
|
|
2412
|
-
}).join(`
|
|
2413
|
-
`);
|
|
2414
|
-
return ` "${event}": async (input, output) => {
|
|
2415
|
-
${body}
|
|
2416
|
-
},`;
|
|
2417
|
-
}).join(`
|
|
2418
|
-
`);
|
|
2419
|
-
return `import type { Plugin } from "@opencode-ai/plugin";
|
|
2420
|
-
|
|
2421
|
-
export const ${identifier}Plugin: Plugin = async ({ project, client, $, directory, worktree }) => {
|
|
46
|
+
export const ${Y}Plugin: Plugin = async ({ project, client, $, directory, worktree }) => {
|
|
2422
47
|
return {
|
|
2423
|
-
${
|
|
48
|
+
${Z}
|
|
2424
49
|
};
|
|
2425
50
|
};
|
|
2426
|
-
|
|
2427
|
-
}
|
|
2428
|
-
function
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
preToolUse: "tool.execute.before",
|
|
2434
|
-
stop: "session.idle",
|
|
2435
|
-
afterFileEdit: "file.edited",
|
|
2436
|
-
afterShellExecution: "command.executed"
|
|
2437
|
-
};
|
|
2438
|
-
for (const [event, handlers] of Object.entries(events)) {
|
|
2439
|
-
const opencodeEvent = eventMapping[event] ?? event;
|
|
2440
|
-
if (!mapped[opencodeEvent]) {
|
|
2441
|
-
mapped[opencodeEvent] = [];
|
|
2442
|
-
}
|
|
2443
|
-
mapped[opencodeEvent].push(...handlers.filter((h) => h.command));
|
|
2444
|
-
}
|
|
2445
|
-
return mapped;
|
|
2446
|
-
}
|
|
2447
|
-
|
|
2448
|
-
// src/targets/registry.ts
|
|
2449
|
-
var TARGETS = [
|
|
2450
|
-
new OpenCodeTarget,
|
|
2451
|
-
new CursorTarget,
|
|
2452
|
-
new ClaudeCodeTarget,
|
|
2453
|
-
new CodexCliTarget,
|
|
2454
|
-
new MistralVibeTarget,
|
|
2455
|
-
new GeminiCliTarget,
|
|
2456
|
-
new CopilotTarget,
|
|
2457
|
-
new AgentsMdTarget,
|
|
2458
|
-
ClineTarget,
|
|
2459
|
-
KiloTarget,
|
|
2460
|
-
RooTarget,
|
|
2461
|
-
QwenCodeTarget,
|
|
2462
|
-
KiroTarget,
|
|
2463
|
-
FactoryDroidTarget,
|
|
2464
|
-
AntiGravityTarget,
|
|
2465
|
-
JunieTarget,
|
|
2466
|
-
AugmentCodeTarget,
|
|
2467
|
-
WindsurfTarget,
|
|
2468
|
-
WarpTarget,
|
|
2469
|
-
ReplitTarget,
|
|
2470
|
-
ZedTarget
|
|
2471
|
-
];
|
|
2472
|
-
var targetMap = new Map(TARGETS.map((t) => [t.id, t]));
|
|
2473
|
-
function getTarget(id) {
|
|
2474
|
-
return targetMap.get(id);
|
|
2475
|
-
}
|
|
2476
|
-
function getAllTargets() {
|
|
2477
|
-
return [...TARGETS];
|
|
2478
|
-
}
|
|
2479
|
-
function getTargets(ids) {
|
|
2480
|
-
return ids.map((id) => targetMap.get(id)).filter((t) => t !== undefined);
|
|
2481
|
-
}
|
|
2482
|
-
function listTargetIds() {
|
|
2483
|
-
return TARGETS.map((t) => t.id);
|
|
2484
|
-
}
|
|
2485
|
-
|
|
2486
|
-
// src/utils/diff.ts
|
|
2487
|
-
import { existsSync as existsSync7, readFileSync as readFileSync9 } from "fs";
|
|
2488
|
-
function diffFile(filepath, newContent) {
|
|
2489
|
-
if (!existsSync7(filepath)) {
|
|
2490
|
-
return {
|
|
2491
|
-
filepath,
|
|
2492
|
-
status: "added",
|
|
2493
|
-
diffLines: formatAddedDiff(filepath, newContent)
|
|
2494
|
-
};
|
|
2495
|
-
}
|
|
2496
|
-
const existing = readFileSync9(filepath, "utf-8");
|
|
2497
|
-
if (existing === newContent) {
|
|
2498
|
-
return { filepath, status: "unchanged", diffLines: [] };
|
|
2499
|
-
}
|
|
2500
|
-
return {
|
|
2501
|
-
filepath,
|
|
2502
|
-
status: "modified",
|
|
2503
|
-
diffLines: computeUnifiedDiff(filepath, existing, newContent)
|
|
2504
|
-
};
|
|
2505
|
-
}
|
|
2506
|
-
function formatAddedDiff(filepath, content) {
|
|
2507
|
-
const lines = [
|
|
2508
|
-
`--- /dev/null`,
|
|
2509
|
-
`+++ ${filepath}`,
|
|
2510
|
-
`@@ -0,0 +1,${content.split(`
|
|
2511
|
-
`).length} @@`
|
|
2512
|
-
];
|
|
2513
|
-
for (const line of content.split(`
|
|
2514
|
-
`)) {
|
|
2515
|
-
lines.push(`+${line}`);
|
|
2516
|
-
}
|
|
2517
|
-
return lines;
|
|
2518
|
-
}
|
|
2519
|
-
function computeUnifiedDiff(filepath, oldContent, newContent) {
|
|
2520
|
-
const oldLines = oldContent.split(`
|
|
2521
|
-
`);
|
|
2522
|
-
const newLines = newContent.split(`
|
|
2523
|
-
`);
|
|
2524
|
-
const result = [`--- ${filepath}`, `+++ ${filepath}`];
|
|
2525
|
-
const hunks = findHunks(oldLines, newLines);
|
|
2526
|
-
for (const hunk of hunks) {
|
|
2527
|
-
result.push(`@@ -${hunk.oldStart + 1},${hunk.oldCount} +${hunk.newStart + 1},${hunk.newCount} @@`);
|
|
2528
|
-
for (const line of hunk.lines) {
|
|
2529
|
-
result.push(line);
|
|
2530
|
-
}
|
|
2531
|
-
}
|
|
2532
|
-
return result;
|
|
2533
|
-
}
|
|
2534
|
-
function findHunks(oldLines, newLines) {
|
|
2535
|
-
const CONTEXT = 3;
|
|
2536
|
-
const changes = [];
|
|
2537
|
-
let oi = 0;
|
|
2538
|
-
let ni = 0;
|
|
2539
|
-
while (oi < oldLines.length || ni < newLines.length) {
|
|
2540
|
-
if (oi < oldLines.length && ni < newLines.length && oldLines[oi] === newLines[ni]) {
|
|
2541
|
-
changes.push({
|
|
2542
|
-
type: " ",
|
|
2543
|
-
line: oldLines[oi] ?? "",
|
|
2544
|
-
oldIdx: oi,
|
|
2545
|
-
newIdx: ni
|
|
2546
|
-
});
|
|
2547
|
-
oi++;
|
|
2548
|
-
ni++;
|
|
2549
|
-
} else if (ni < newLines.length && (oi >= oldLines.length || !newLines.slice(ni).includes(oldLines[oi] ?? ""))) {
|
|
2550
|
-
changes.push({
|
|
2551
|
-
type: "+",
|
|
2552
|
-
line: newLines[ni] ?? "",
|
|
2553
|
-
oldIdx: oi,
|
|
2554
|
-
newIdx: ni
|
|
2555
|
-
});
|
|
2556
|
-
ni++;
|
|
2557
|
-
} else {
|
|
2558
|
-
changes.push({
|
|
2559
|
-
type: "-",
|
|
2560
|
-
line: oldLines[oi] ?? "",
|
|
2561
|
-
oldIdx: oi,
|
|
2562
|
-
newIdx: oi
|
|
2563
|
-
});
|
|
2564
|
-
oi++;
|
|
2565
|
-
}
|
|
2566
|
-
}
|
|
2567
|
-
const hunks = [];
|
|
2568
|
-
let currentHunk = null;
|
|
2569
|
-
let unchangedCount = 0;
|
|
2570
|
-
for (const change of changes) {
|
|
2571
|
-
if (change.type === " ") {
|
|
2572
|
-
unchangedCount++;
|
|
2573
|
-
if (currentHunk && unchangedCount <= CONTEXT) {
|
|
2574
|
-
currentHunk.lines.push(` ${change.line}`);
|
|
2575
|
-
currentHunk.oldCount++;
|
|
2576
|
-
currentHunk.newCount++;
|
|
2577
|
-
} else if (currentHunk && unchangedCount > CONTEXT * 2) {
|
|
2578
|
-
hunks.push(currentHunk);
|
|
2579
|
-
currentHunk = null;
|
|
2580
|
-
}
|
|
2581
|
-
} else {
|
|
2582
|
-
if (!currentHunk) {
|
|
2583
|
-
const contextStart = Math.max(0, changes.indexOf(change) - CONTEXT);
|
|
2584
|
-
currentHunk = {
|
|
2585
|
-
oldStart: change.oldIdx - Math.min(CONTEXT, changes.indexOf(change) - contextStart),
|
|
2586
|
-
oldCount: 0,
|
|
2587
|
-
newStart: change.newIdx - Math.min(CONTEXT, changes.indexOf(change) - contextStart),
|
|
2588
|
-
newCount: 0,
|
|
2589
|
-
lines: []
|
|
2590
|
-
};
|
|
2591
|
-
for (let i = contextStart;i < changes.indexOf(change); i++) {
|
|
2592
|
-
const entry = changes[i];
|
|
2593
|
-
if (entry?.type === " ") {
|
|
2594
|
-
currentHunk.lines.push(` ${entry.line}`);
|
|
2595
|
-
currentHunk.oldCount++;
|
|
2596
|
-
currentHunk.newCount++;
|
|
2597
|
-
}
|
|
2598
|
-
}
|
|
2599
|
-
}
|
|
2600
|
-
unchangedCount = 0;
|
|
2601
|
-
currentHunk.lines.push(`${change.type}${change.line}`);
|
|
2602
|
-
if (change.type === "-")
|
|
2603
|
-
currentHunk.oldCount++;
|
|
2604
|
-
if (change.type === "+")
|
|
2605
|
-
currentHunk.newCount++;
|
|
2606
|
-
}
|
|
2607
|
-
}
|
|
2608
|
-
if (currentHunk)
|
|
2609
|
-
hunks.push(currentHunk);
|
|
2610
|
-
return hunks;
|
|
2611
|
-
}
|
|
2612
|
-
|
|
2613
|
-
// src/cli/generate.ts
|
|
2614
|
-
import chalk from "chalk";
|
|
2615
|
-
import { existsSync as existsSync8, readFileSync as readFileSync10 } from "fs";
|
|
2616
|
-
function runGenerate(projectRoot, options) {
|
|
2617
|
-
const config = loadWorkspaceConfig(projectRoot);
|
|
2618
|
-
if (options.targets) {
|
|
2619
|
-
const targetList = options.targets === "*" ? "*" : options.targets.split(",");
|
|
2620
|
-
config.targets = targetList;
|
|
2621
|
-
}
|
|
2622
|
-
if (options.features) {
|
|
2623
|
-
const featureList = options.features === "*" ? "*" : options.features.split(",");
|
|
2624
|
-
config.features = featureList;
|
|
2625
|
-
}
|
|
2626
|
-
if (options.verbose !== undefined) {
|
|
2627
|
-
config.verbose = options.verbose;
|
|
2628
|
-
}
|
|
2629
|
-
const verbose = config.verbose;
|
|
2630
|
-
if (verbose)
|
|
2631
|
-
console.log(chalk.dim("Loading packs..."));
|
|
2632
|
-
const loader = new PackLoader(projectRoot, config);
|
|
2633
|
-
const { packs, warnings: loadWarnings } = loader.loadAll();
|
|
2634
|
-
for (const w of loadWarnings) {
|
|
2635
|
-
console.log(chalk.yellow(` warn: ${w}`));
|
|
2636
|
-
}
|
|
2637
|
-
if (packs.length === 0) {
|
|
2638
|
-
console.log(chalk.red("No packs loaded. Nothing to generate."));
|
|
2639
|
-
console.log(chalk.dim("Run 'agentpacks init' to create a default pack."));
|
|
2640
|
-
return;
|
|
2641
|
-
}
|
|
2642
|
-
if (verbose) {
|
|
2643
|
-
console.log(chalk.dim(` Loaded ${packs.length} pack(s): ${packs.map((p) => p.manifest.name).join(", ")}`));
|
|
2644
|
-
}
|
|
2645
|
-
if (verbose)
|
|
2646
|
-
console.log(chalk.dim("Merging features..."));
|
|
2647
|
-
const merger = new FeatureMerger(packs);
|
|
2648
|
-
const { features, warnings: mergeWarnings } = merger.merge();
|
|
2649
|
-
for (const w of mergeWarnings) {
|
|
2650
|
-
console.log(chalk.yellow(` warn: ${w}`));
|
|
2651
|
-
}
|
|
2652
|
-
const targetIds = resolveTargets(config);
|
|
2653
|
-
if (!targetIds.includes("agentsmd")) {
|
|
2654
|
-
targetIds.push("agentsmd");
|
|
2655
|
-
}
|
|
2656
|
-
const targets = getTargets(targetIds);
|
|
2657
|
-
if (targets.length === 0) {
|
|
2658
|
-
console.log(chalk.red("No valid targets found."));
|
|
2659
|
-
return;
|
|
2660
|
-
}
|
|
2661
|
-
const allResults = [];
|
|
2662
|
-
const diffEntries = [];
|
|
2663
|
-
for (const baseDir of config.baseDirs) {
|
|
2664
|
-
for (const target of targets) {
|
|
2665
|
-
const enabledFeatures = resolveFeatures(config, target.id);
|
|
2666
|
-
const effectiveFeatures = enabledFeatures.filter((f) => target.supportsFeature(f));
|
|
2667
|
-
if (effectiveFeatures.length === 0 && target.id !== "agentsmd") {
|
|
2668
|
-
if (verbose) {
|
|
2669
|
-
console.log(chalk.dim(` Skipping ${target.name} (no enabled features)`));
|
|
2670
|
-
}
|
|
2671
|
-
continue;
|
|
2672
|
-
}
|
|
2673
|
-
if (options.dryRun && !options.diff) {
|
|
2674
|
-
console.log(chalk.cyan(` [dry-run] Would generate ${target.name} in ${baseDir}`));
|
|
2675
|
-
continue;
|
|
2676
|
-
}
|
|
2677
|
-
const generateOptions = {
|
|
2678
|
-
projectRoot,
|
|
2679
|
-
baseDir,
|
|
2680
|
-
features,
|
|
2681
|
-
enabledFeatures,
|
|
2682
|
-
deleteExisting: options.diff ? false : config.delete,
|
|
2683
|
-
global: config.global,
|
|
2684
|
-
verbose: config.verbose,
|
|
2685
|
-
modelProfile: config.modelProfile
|
|
2686
|
-
};
|
|
2687
|
-
try {
|
|
2688
|
-
const result = target.generate(generateOptions);
|
|
2689
|
-
allResults.push(result);
|
|
2690
|
-
if (options.diff) {
|
|
2691
|
-
for (const filepath of result.filesWritten) {
|
|
2692
|
-
const newContent = existsSync8(filepath) ? readFileSync10(filepath, "utf-8") : "";
|
|
2693
|
-
const entry = diffFile(filepath, newContent);
|
|
2694
|
-
if (entry.status !== "unchanged") {
|
|
2695
|
-
diffEntries.push(entry);
|
|
2696
|
-
}
|
|
2697
|
-
}
|
|
2698
|
-
}
|
|
2699
|
-
for (const w of result.warnings) {
|
|
2700
|
-
console.log(chalk.yellow(` warn [${target.name}]: ${w}`));
|
|
2701
|
-
}
|
|
2702
|
-
if (verbose && result.filesWritten.length > 0) {
|
|
2703
|
-
console.log(chalk.dim(` ${target.name}: wrote ${result.filesWritten.length} file(s)`));
|
|
2704
|
-
}
|
|
2705
|
-
} catch (err) {
|
|
2706
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
2707
|
-
console.log(chalk.red(` error [${target.name}]: ${message}`));
|
|
2708
|
-
}
|
|
2709
|
-
}
|
|
2710
|
-
}
|
|
2711
|
-
if (options.diff && diffEntries.length > 0) {
|
|
2712
|
-
const added = diffEntries.filter((e) => e.status === "added").length;
|
|
2713
|
-
const modified = diffEntries.filter((e) => e.status === "modified").length;
|
|
2714
|
-
console.log(chalk.bold(`
|
|
2715
|
-
Diff: ${added} added, ${modified} modified
|
|
2716
|
-
`));
|
|
2717
|
-
for (const entry of diffEntries) {
|
|
2718
|
-
const label = entry.status === "added" ? chalk.green("[+] " + entry.filepath) : chalk.yellow("[M] " + entry.filepath);
|
|
2719
|
-
console.log(label);
|
|
2720
|
-
if (verbose) {
|
|
2721
|
-
for (const line of entry.diffLines.slice(0, 50)) {
|
|
2722
|
-
if (line.startsWith("+") && !line.startsWith("+++")) {
|
|
2723
|
-
console.log(chalk.green(line));
|
|
2724
|
-
} else if (line.startsWith("-") && !line.startsWith("---")) {
|
|
2725
|
-
console.log(chalk.red(line));
|
|
2726
|
-
} else {
|
|
2727
|
-
console.log(chalk.dim(line));
|
|
2728
|
-
}
|
|
2729
|
-
}
|
|
2730
|
-
if (entry.diffLines.length > 50) {
|
|
2731
|
-
console.log(chalk.dim(` ... ${entry.diffLines.length - 50} more lines`));
|
|
2732
|
-
}
|
|
2733
|
-
}
|
|
2734
|
-
}
|
|
2735
|
-
console.log();
|
|
2736
|
-
} else if (options.diff) {
|
|
2737
|
-
console.log(chalk.dim("No changes detected."));
|
|
2738
|
-
}
|
|
2739
|
-
if (!options.dryRun) {
|
|
2740
|
-
const totalWritten = allResults.reduce((sum, r) => sum + r.filesWritten.length, 0);
|
|
2741
|
-
const totalDeleted = allResults.reduce((sum, r) => sum + r.filesDeleted.length, 0);
|
|
2742
|
-
const targetNames = allResults.map((r) => r.targetId);
|
|
2743
|
-
const uniqueTargets = [...new Set(targetNames)];
|
|
2744
|
-
console.log(chalk.green(`Generated ${totalWritten} file(s) for ${uniqueTargets.length} target(s)` + (totalDeleted > 0 ? ` (cleaned ${totalDeleted} dir(s))` : "")));
|
|
2745
|
-
}
|
|
2746
|
-
}
|
|
2747
|
-
export {
|
|
2748
|
-
runGenerate
|
|
2749
|
-
};
|
|
51
|
+
`}function T2($){let q={},Y={sessionStart:"session.created",postToolUse:"tool.execute.after",preToolUse:"tool.execute.before",stop:"session.idle",afterFileEdit:"file.edited",afterShellExecution:"command.executed"};for(let[Q,Z]of Object.entries($)){let V=Y[Q]??Q;if(!q[V])q[V]=[];q[V].push(...Z.filter((H)=>H.command))}return q}var j0=[new R0,new G0,new N0,new F0,new z0,new y0,new S0,J1,O1,L1,H1,W1,P1,_1,C1,A1,x1,N1,b1,I1],G1=new Map(j0.map(($)=>[$.id,$]));function o6($){return G1.get($)}function n6(){return[...j0]}function M1($){return $.map((q)=>G1.get(q)).filter((q)=>q!==void 0)}function l6(){return j0.map(($)=>$.id)}import{existsSync as k2,readFileSync as D2}from"fs";function y1($,q){if(!k2($))return{filepath:$,status:"added",diffLines:v2($,q)};let Y=D2($,"utf-8");if(Y===q)return{filepath:$,status:"unchanged",diffLines:[]};return{filepath:$,status:"modified",diffLines:h2($,Y,q)}}function v2($,q){let Y=["--- /dev/null",`+++ ${$}`,`@@ -0,0 +1,${q.split(`
|
|
52
|
+
`).length} @@`];for(let Q of q.split(`
|
|
53
|
+
`))Y.push(`+${Q}`);return Y}function h2($,q,Y){let Q=q.split(`
|
|
54
|
+
`),Z=Y.split(`
|
|
55
|
+
`),V=[`--- ${$}`,`+++ ${$}`],H=u2(Q,Z);for(let J of H){V.push(`@@ -${J.oldStart+1},${J.oldCount} +${J.newStart+1},${J.newCount} @@`);for(let L of J.lines)V.push(L)}return V}function u2($,q){let Q=[],Z=0,V=0;while(Z<$.length||V<q.length)if(Z<$.length&&V<q.length&&$[Z]===q[V])Q.push({type:" ",line:$[Z]??"",oldIdx:Z,newIdx:V}),Z++,V++;else if(V<q.length&&(Z>=$.length||!q.slice(V).includes($[Z]??"")))Q.push({type:"+",line:q[V]??"",oldIdx:Z,newIdx:V}),V++;else Q.push({type:"-",line:$[Z]??"",oldIdx:Z,newIdx:Z}),Z++;let H=[],J=null,L=0;for(let W of Q)if(W.type===" "){if(L++,J&&L<=3)J.lines.push(` ${W.line}`),J.oldCount++,J.newCount++;else if(J&&L>6)H.push(J),J=null}else{if(!J){let F=Math.max(0,Q.indexOf(W)-3);J={oldStart:W.oldIdx-Math.min(3,Q.indexOf(W)-F),oldCount:0,newStart:W.newIdx-Math.min(3,Q.indexOf(W)-F),newCount:0,lines:[]};for(let C=F;C<Q.indexOf(W);C++){let B=Q[C];if(B?.type===" ")J.lines.push(` ${B.line}`),J.oldCount++,J.newCount++}}if(L=0,J.lines.push(`${W.type}${W.line}`),W.type==="-")J.oldCount++;if(W.type==="+")J.newCount++}if(J)H.push(J);return H}import G from"chalk";import{existsSync as m2,readFileSync as g2}from"fs";function Z7($,q){let Y=H0($);if(q.targets){let X=q.targets==="*"?"*":q.targets.split(",");Y.targets=X}if(q.features){let X=q.features==="*"?"*":q.features.split(",");Y.features=X}if(q.verbose!==void 0)Y.verbose=q.verbose;let Q=Y.verbose;if(Q)console.log(G.dim("Loading packs..."));let Z=new P0($,Y),{packs:V,warnings:H}=Z.loadAll();for(let X of H)console.log(G.yellow(` warn: ${X}`));if(V.length===0){console.log(G.red("No packs loaded. Nothing to generate.")),console.log(G.dim("Run 'agentpacks init' to create a default pack."));return}if(Q)console.log(G.dim(` Loaded ${V.length} pack(s): ${V.map((X)=>X.manifest.name).join(", ")}`));if(Q)console.log(G.dim("Merging features..."));let J=new A0(V),{features:L,warnings:W}=J.merge();for(let X of W)console.log(G.yellow(` warn: ${X}`));let F=m0(Y),C=M1(F);if(C.length===0){console.log(G.red("No valid targets found."));return}let B=[],O=[];for(let X of Y.baseDirs)for(let U of C){let K=u0(Y,U.id);if(K.filter((I)=>U.supportsFeature(I)).length===0){if(Q)console.log(G.dim(` Skipping ${U.name} (no enabled features)`));continue}if(q.dryRun&&!q.diff){console.log(G.cyan(` [dry-run] Would generate ${U.name} in ${X}`));continue}let A={projectRoot:$,baseDir:X,features:L,enabledFeatures:K,deleteExisting:q.diff?!1:Y.delete,global:Y.global,verbose:Y.verbose,modelProfile:Y.modelProfile};try{let I=U.generate(A);if(B.push(I),q.diff)for(let M of I.filesWritten){let $0=m2(M)?g2(M,"utf-8"):"",L0=y1(M,$0);if(L0.status!=="unchanged")O.push(L0)}for(let M of I.warnings)console.log(G.yellow(` warn [${U.name}]: ${M}`));if(Q&&I.filesWritten.length>0)console.log(G.dim(` ${U.name}: wrote ${I.filesWritten.length} file(s)`))}catch(I){let M=I instanceof Error?I.message:String(I);console.log(G.red(` error [${U.name}]: ${M}`))}}if(q.diff&&O.length>0){let X=O.filter((K)=>K.status==="added").length,U=O.filter((K)=>K.status==="modified").length;console.log(G.bold(`
|
|
56
|
+
Diff: ${X} added, ${U} modified
|
|
57
|
+
`));for(let K of O){let _=K.status==="added"?G.green("[+] "+K.filepath):G.yellow("[M] "+K.filepath);if(console.log(_),Q){for(let A of K.diffLines.slice(0,50))if(A.startsWith("+")&&!A.startsWith("+++"))console.log(G.green(A));else if(A.startsWith("-")&&!A.startsWith("---"))console.log(G.red(A));else console.log(G.dim(A));if(K.diffLines.length>50)console.log(G.dim(` ... ${K.diffLines.length-50} more lines`))}}console.log()}else if(q.diff)console.log(G.dim("No changes detected."));if(!q.dryRun){let X=B.reduce((A,I)=>A+I.filesWritten.length,0),U=B.reduce((A,I)=>A+I.filesDeleted.length,0),K=B.map((A)=>A.targetId),_=[...new Set(K)];console.log(G.green(`Generated ${X} file(s) for ${_.length} target(s)`+(U>0?` (cleaned ${U} dir(s))`:"")))}}export{Z7 as runGenerate};
|