@snelusha/noto 1.3.6 → 2.0.0-beta.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/README.md +8 -8
- package/dist/index.js +9 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
|
|
7
7
|
- **Instant Commit Messages**: Generate clear, context-aware messages based on staged changes.
|
|
8
8
|
|
|
9
|
-
- **Seamless Git Integration**:
|
|
9
|
+
- **Seamless Git Integration**: Auto-commit by default, with a preview-only option.
|
|
10
10
|
|
|
11
|
-
- **Interactive Editing:**
|
|
11
|
+
- **Interactive Editing:** Edit the generated message in-line before committing (no flag needed).
|
|
12
12
|
|
|
13
13
|
- **Enhanced Configuration:** Manage your LLM model preferences with an improved configuration interface.
|
|
14
14
|
|
|
@@ -72,16 +72,16 @@ noto config reset
|
|
|
72
72
|
|
|
73
73
|
## Usage
|
|
74
74
|
|
|
75
|
-
Generate a new commit message:
|
|
75
|
+
Generate and commit with a new commit message (default behavior):
|
|
76
76
|
|
|
77
77
|
```bash
|
|
78
78
|
noto
|
|
79
79
|
```
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
Preview the generated message without committing:
|
|
82
82
|
|
|
83
83
|
```bash
|
|
84
|
-
noto --
|
|
84
|
+
noto --preview # or simply noto -p
|
|
85
85
|
```
|
|
86
86
|
|
|
87
87
|
Copy the generated commit message to your clipboard:
|
|
@@ -104,7 +104,7 @@ noto prev --amend --edit # or simply: noto prev --amend -e
|
|
|
104
104
|
|
|
105
105
|
> Note: When using the `--amend` flag with the noto prev command, the `--edit` (`-e`) flag is also required. This combination will allow you to modify (amend) the previous commit message before applying it.
|
|
106
106
|
|
|
107
|
-
Note:
|
|
107
|
+
Note: `--preview` and `--copy` can also be used with the `noto prev` command. `--edit` applies only when using `noto prev --amend`.
|
|
108
108
|
|
|
109
109
|
Switch between branches in your git repo with an interactive prompt:
|
|
110
110
|
|
|
@@ -128,7 +128,7 @@ noto upgrade
|
|
|
128
128
|
|
|
129
129
|
## Pro Tips
|
|
130
130
|
|
|
131
|
-
- 🚀 Get fast commits on the fly with `noto -
|
|
131
|
+
- 🚀 Get fast commits on the fly with `noto` - it commits by default!
|
|
132
132
|
|
|
133
133
|
## Contributing
|
|
134
134
|
|
|
@@ -139,4 +139,4 @@ Thank you for using noto!
|
|
|
139
139
|
## License
|
|
140
140
|
|
|
141
141
|
This project is licensed under the MIT License.
|
|
142
|
-
©
|
|
142
|
+
© 2024-2026 [Sithija Nelusha Silva](https://github.com/snelusha)
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{createCli as Ft}from"trpc-cli";var O="@snelusha/noto",C="
|
|
3
|
-
Please run \`noto upgrade\` to update`.trim())}var i=async(o,t=!0)=>{if(t)await yt();await new Promise((a)=>setTimeout(a,1)),console.log(),process.exit(o)};var T=bt.meta().create({defaultMeta:{intro:!0,authRequired:!0,repoRequired:!0,diffRequired:!1,promptRequired:!1}}),Ne=T.middleware(async(o)=>{let{meta:t,next:a}=o,e=await m.get(),r=process.env.NOTO_API_KEY||e.llm?.apiKey;if(t?.authRequired&&!r)return N.log.error(
|
|
4
|
-
${b.dim(`run ${b.cyan("`noto config key`")} to set it up.`)}`),await i(1);return a()}),Te=T.middleware(async(o)=>{let{meta:t,next:a}=o,e=await Y();if(t?.repoRequired&&!e)return N.log.error(
|
|
5
|
-
${b.dim(`run ${b.cyan("`git init`")} to initialize a new repository.`)}`),await i(1);let r=e&&await ye();if(t?.diffRequired&&!r)return N.log.error(
|
|
6
|
-
${b.dim(`run ${b.cyan("`git add <file>`")} or ${b.cyan("`git add .`")} to stage changes.`)}`),await i(1);let s=null;if(t?.promptRequired){let n=await Q();if(n)try{s=await wt.readFile(n,"utf-8")}catch{}}return a({ctx:{noto:{prompt:s},git:{isRepository:e,diff:r}}})}),x=T.procedure.use((o)=>{let{meta:t,next:a}=o;if(t?.intro)if(console.log(),B)N.intro(`${b.bgGreen(b.black(" @snelusha/noto [Prerelease] "))}`);else N.intro(`${b.bgCyan(b.black(" @snelusha/noto "))}`);return a()}),Oo=x.use(Ne),ee=x.use(Te),te=x.use(Ne).use(Te);import{z as F}from"zod";import*as c from"@clack/prompts";import u from"picocolors";import vt from"clipboardy";var Ee=ee.meta({description:"checkout a branch"}).input(F.object({copy:F.boolean().meta({description:"copy the selected branch to clipboard",alias:"c"}),create:F.union([F.boolean(),F.string()]).optional().meta({description:"create a new branch",alias:"b"}),branch:F.string().optional().meta({positional:!0})})).mutation(async(o)=>{let{input:t}=o,a=await ve();if(!a)return c.log.error("failed to fetch branches"),await i(1);let e=await be(),r=typeof t.create==="string"?t.create:t.branch;if((t.create===!0||typeof t.create==="string")&&r){if(a.includes(r))return c.log.error(`branch ${u.red(r)} already exists in the repository`),await i(1);if(!await ne(r))return c.log.error(`failed to create and checkout ${u.bold(r)}`),await i(1);return c.log.success(`created and checked out ${u.green(r)}`),await i(0)}if(r){if(!a.includes(r)){c.log.error(`branch ${u.red(r)} does not exist in the repository`);let G=await c.confirm({message:`do you want to create branch ${u.green(r)}?`});if(c.isCancel(G))return c.log.error("aborted"),await i(1);if(G){if(!await ne(r))return c.log.error(`failed to create and checkout ${u.bold(r)}`),await i(1);return c.log.success(`created and checked out ${u.green(r)}`),await i(0)}return await i(1)}if(r===e)return c.log.error(`${u.red("already on branch")} ${u.green(r)}`),await i(1);if(!await ie(r))return c.log.error(`failed to checkout ${u.bold(r)}`),await i(1);return c.log.success(`checked out ${u.green(r)}`),await i(0)}if(a.length===0)return c.log.error("no branches found in the repository"),await i(1);let n=await c.select({message:"select a branch to checkout",options:a.map((
|
|
2
|
+
import{createCli as Ft}from"trpc-cli";var O="@snelusha/noto",C="2.0.0-beta.0";import wt from"node:fs/promises";import{initTRPC as bt}from"@trpc/server";import*as N from"@clack/prompts";import b from"picocolors";import pe from"dedent";import at from"simple-git";var k=at(),Y=async()=>{return k.checkIsRepo()},H=async()=>{try{return await k.revparse(["--show-toplevel"])}catch{return null}};var he=async(o=20,t=!1)=>{try{let a=t?{maxCount:o,"--no-merges":null}:{maxCount:o};return(await k.log(a)).all.map((r)=>r.message)}catch{return null}};var ye=async()=>{try{return k.diff(["--cached","--",":!*.lock"])}catch{return null}},j=async(o,t)=>{try{let a=t?{"--amend":null}:void 0,{summary:{changes:e}}=await k.commit(o,void 0,a);return Boolean(e)}catch{return!1}},we=async()=>{try{let o=await k.push();return o.update||o.pushed&&o.pushed.length>0}catch{return!1}},be=async()=>{try{return(await k.branch()).current}catch{return null}},ve=async(o)=>{try{let t=await k.branch();return o?t.all:Object.keys(t.branches).filter((a)=>!a.startsWith("remotes/"))}catch{return null}},ie=async(o)=>{try{return await k.checkout(o,{}),!0}catch{return!1}},ne=async(o)=>{try{return await k.checkoutLocalBranch(o),!0}catch{return!1}};import*as U from"node:fs";import*as L from"node:path";import*as xe from"node:child_process";import se from"node:process";import rt from"semver";var B=rt.prerelease(C)!==null;async function Me(){let o=se.argv[1];if(!o)return{packageManager:"unknown",isGlobal:!1};let t=se.cwd();try{let a=U.realpathSync(o).replace(/\\/g,"/"),e=t.replace(/\\/g,"/");if(await Y()&&e&&a.startsWith(e)&&!a.includes("/node_modules/"))return{packageManager:"unknown",isGlobal:!1,updateMessage:'Running from a local git clone. Please update with "git pull".'};if(a.includes("/.npm/_npx")||a.includes("/npm/_npx"))return{packageManager:"npx",isGlobal:!1,updateMessage:"Running via npx, update not applicable."};if(se.platform==="darwin")try{return xe.execSync('brew list -1 | grep -q "^noto$"',{stdio:"ignore"}),{packageManager:"homebrew",isGlobal:!0,updateMessage:'Installed via Homebrew. Please update with "brew upgrade".'}}catch{}if(a.includes("/pnpm/dlx")||a.includes("/pnpm-cache/dlx"))return{packageManager:"pnpx",isGlobal:!1,updateMessage:"Running via pnpx, update not applicable."};if(a.includes("/pnpm/global"))return{packageManager:"pnpm",isGlobal:!0,updateCommand:"pnpm add -g @snelusha/noto@latest",updateMessage:"Please run pnpm add -g @snelusha/noto@latest to update"};if(a.includes("/.yarn/global"))return{packageManager:"yarn",isGlobal:!0,updateCommand:"yarn global add @snelusha/noto@latest",updateMessage:"Please run yarn global add @snelusha/noto@latest to update"};if(a.includes("/bunx"))return{packageManager:"bunx",isGlobal:!1,updateMessage:"Running via bunx, update not applicable."};if(a.includes("/.bun/install/global"))return{packageManager:"bun",isGlobal:!0,updateCommand:"bun add -g @snelusha/noto@latest",updateMessage:"Please run bun add -g @snelusha/noto@latest to update"};if(e&&a.startsWith(`${e}/node_modules`)){let n="npm";if(U.existsSync(L.join(t,"yarn.lock")))n="yarn";else if(U.existsSync(L.join(t,"pnpm-lock.yaml")))n="pnpm";else if(U.existsSync(L.join(t,"bun.lockb"))||U.existsSync(L.join(t,"bun.lock")))n="bun";return{packageManager:n,isGlobal:!1,updateMessage:"Locally installed. Please update via your project's package.json."}}let s="npm install -g @snelusha/noto@latest";return{packageManager:"npm",isGlobal:!0,updateCommand:s,updateMessage:`Please run ${s} to update`}}catch{return{packageManager:"unknown",isGlobal:!1}}}import st from"node:os";import Pe from"node:path";import{z}from"zod";import X from"node:fs/promises";import it from"node:path";function J(o){let{schema:t,path:a}=o;return class e{static storagePath=a;static storage={};static async load(){try{await X.access(e.storagePath);let r=await X.readFile(e.storagePath,"utf-8"),s=r?JSON.parse(r):{},n=t.safeParse(s);e.storage=n.success?n.data:{}}catch{e.storage={}}return e.storage}static async save(){try{let r=it.dirname(e.storagePath);await X.mkdir(r,{recursive:!0});let s=JSON.stringify(e.storage,null,2);await X.writeFile(e.storagePath,s,"utf-8")}catch{}}static async update(r){try{await e.load();let s=await r(e.storage),n=t.safeParse(s);if(n.success)e.storage=n.data,await e.save()}catch{}return e.storage}static async get(){return await e.load(),JSON.parse(JSON.stringify(e.storage))}static async clear(){e.storage={},await e.save()}static get path(){return e.storagePath}static set path(r){e.storagePath=r}static get raw(){return e.storage}}}import{z as nt}from"zod";var ke=nt.enum(["gemini-2.5-flash","gemini-2.5-flash-lite","gemini-2.5-pro","gemini-3-flash-preview","gemini-3-pro-preview"]);var ct=z.object({llm:z.object({apiKey:z.string().optional(),model:ke.optional().or(z.string())}).optional(),lastGeneratedMessage:z.string().optional()}),m=J({path:Pe.resolve(Pe.join(st.homedir(),".config","noto"),".notorc"),schema:ct});async function Ce(){try{let o=await m.get();await m.update(()=>o)}catch{}}import pt from"node:fs/promises";import D from"node:path";import{fileURLToPath as lt}from"node:url";var Re=(o)=>o instanceof URL?lt(o):o;async function Ae(o,t={}){let a=D.resolve(Re(t.cwd??"")),{root:e}=D.parse(a);t.stopAt=D.resolve(Re(t.stopAt??e));let r=D.isAbsolute(o);while(a){let s=r?o:D.join(a,o);try{let n=await pt.stat(s);if(t.type===void 0||t.type==="file"&&n.isFile()||t.type==="directory"&&n.isDirectory())return s}catch{}if(a===t.stopAt||a===e)break;a=D.dirname(a)}}var Q=async()=>{let o=await H();return await Ae(".noto/commit-prompt.md",{stopAt:o||process.cwd(),type:"file"})};import*as Ue from"@clack/prompts";import $e from"picocolors";import ht from"dedent";import w from"semver";import q from"latest-version";import mt from"node:os";import Ie from"node:path";import{z as R}from"zod";var dt=R.object({commitGenerationCache:R.record(R.string(),R.string()).optional(),update:R.object({timestamp:R.number(),current:R.string(),latest:R.string()}).optional()}),A=J({path:Ie.resolve(Ie.join(mt.homedir(),".cache","noto"),"cache"),schema:dt});var ut=86400000;function gt(o,t){if(!o||!t)return o||t||null;let a=w.parse(t),e=w.parse(o);if(!a||!e)return o||t||null;return w.gt(o,t)?o:t}async function ce(o=!1,t=!1,a="auto"){let e=(await A.get()).update;if(!t&&e){if(w.valid(e.current)&&w.valid(e.latest)){let s=w.gte(e.current,e.latest),n=Date.now()-e.timestamp<ut;if(s||n)return{latest:e.latest,current:e.current,timestamp:e.timestamp}}}try{let r;if(a==="stable")r=await q(O);else if(a==="beta")r=await q(O,{version:"beta"});else r=B?gt(...await Promise.all([q(O,{version:"beta"}),q(O)]))??C:await q(O);let s={latest:r,current:C,timestamp:Date.now()};if(o)await ft(s);return s}catch{if(e)return{latest:e.latest,current:e.current,timestamp:e.timestamp};return{latest:C,current:C,timestamp:Date.now()}}}async function ft(o){if(!o)return;await A.update((t)=>({...t,update:o&&{timestamp:o.timestamp,latest:o.latest,current:o.current}}))}async function Z(o=!1,t=!1,a="auto"){let e=await ce(o,t,a);if(w.valid(e.current)&&w.valid(e.latest)){if(B&&a==="stable"&&e.current!==e.latest)return e;if(!w.gte(e.current,e.latest))return e}return null}async function yt(){let o=await Z();if(o)Ue.log.warn(ht`A new version of noto is available: ${$e.dim(o.current)} → ${$e.green(o.latest)}
|
|
3
|
+
Please run \`noto upgrade\` to update`.trim())}var i=async(o,t=!0)=>{if(t)await yt();await new Promise((a)=>setTimeout(a,1)),console.log(),process.exit(o)};var T=bt.meta().create({defaultMeta:{intro:!0,authRequired:!0,repoRequired:!0,diffRequired:!1,promptRequired:!1}}),Ne=T.middleware(async(o)=>{let{meta:t,next:a}=o,e=await m.get(),r=process.env.NOTO_API_KEY||e.llm?.apiKey;if(t?.authRequired&&!r)return N.log.error(pe`${b.red("noto api key is missing.")}
|
|
4
|
+
${b.dim(`run ${b.cyan("`noto config key`")} to set it up.`)}`),await i(1);return a()}),Te=T.middleware(async(o)=>{let{meta:t,next:a}=o,e=await Y();if(t?.repoRequired&&!e)return N.log.error(pe`${b.red("no git repository found in cwd.")}
|
|
5
|
+
${b.dim(`run ${b.cyan("`git init`")} to initialize a new repository.`)}`),await i(1);let r=e&&await ye();if(t?.diffRequired&&!r)return N.log.error(pe`${b.red("no staged changes found.")}
|
|
6
|
+
${b.dim(`run ${b.cyan("`git add <file>`")} or ${b.cyan("`git add .`")} to stage changes.`)}`),await i(1);let s=null;if(t?.promptRequired){let n=await Q();if(n)try{s=await wt.readFile(n,"utf-8")}catch{}}return a({ctx:{noto:{prompt:s},git:{isRepository:e,diff:r}}})}),x=T.procedure.use((o)=>{let{meta:t,next:a}=o;if(t?.intro)if(console.log(),B)N.intro(`${b.bgGreen(b.black(" @snelusha/noto [Prerelease] "))}`);else N.intro(`${b.bgCyan(b.black(" @snelusha/noto "))}`);return a()}),Oo=x.use(Ne),ee=x.use(Te),te=x.use(Ne).use(Te);import{z as F}from"zod";import*as c from"@clack/prompts";import u from"picocolors";import vt from"clipboardy";var Ee=ee.meta({description:"checkout a branch"}).input(F.object({copy:F.boolean().meta({description:"copy the selected branch to clipboard",alias:"c"}),create:F.union([F.boolean(),F.string()]).optional().meta({description:"create a new branch",alias:"b"}),branch:F.string().optional().meta({positional:!0})})).mutation(async(o)=>{let{input:t}=o,a=await ve();if(!a)return c.log.error("failed to fetch branches"),await i(1);let e=await be(),r=typeof t.create==="string"?t.create:t.branch;if((t.create===!0||typeof t.create==="string")&&r){if(a.includes(r))return c.log.error(`branch ${u.red(r)} already exists in the repository`),await i(1);if(!await ne(r))return c.log.error(`failed to create and checkout ${u.bold(r)}`),await i(1);return c.log.success(`created and checked out ${u.green(r)}`),await i(0)}if(r){if(!a.includes(r)){c.log.error(`branch ${u.red(r)} does not exist in the repository`);let G=await c.confirm({message:`do you want to create branch ${u.green(r)}?`});if(c.isCancel(G))return c.log.error("aborted"),await i(1);if(G){if(!await ne(r))return c.log.error(`failed to create and checkout ${u.bold(r)}`),await i(1);return c.log.success(`created and checked out ${u.green(r)}`),await i(0)}return await i(1)}if(r===e)return c.log.error(`${u.red("already on branch")} ${u.green(r)}`),await i(1);if(!await ie(r))return c.log.error(`failed to checkout ${u.bold(r)}`),await i(1);return c.log.success(`checked out ${u.green(r)}`),await i(0)}if(a.length===0)return c.log.error("no branches found in the repository"),await i(1);let n=await c.select({message:"select a branch to checkout",options:a.map((p)=>({value:p,label:u.bold(p===e?u.green(p):p),hint:p===e?"current branch":void 0})),initialValue:e});if(c.isCancel(n))return c.log.error("nothing selected!"),await i(1);if(!n)return c.log.error("no branch selected"),await i(1);if(t.copy)return vt.writeSync(n),c.log.success(`copied ${u.green(n)} to clipboard`),await i(0);if(n===e)return c.log.error(`${u.red("already on branch")}`),await i(1);if(!await ie(n))return c.log.error(`failed to checkout ${u.bold(n)}`),await i(1);c.log.success(`checked out ${u.green(n)}`),await i(0)});import{z as xt}from"zod";import*as M from"@clack/prompts";import le from"picocolors";var Se=x.meta({description:"configure noto api key"}).input(xt.string().optional().describe("apiKey")).mutation(async(o)=>{let{input:t}=o,a=t;if((await m.get()).llm?.apiKey){let e=await M.confirm({message:"noto api key already configured, do you want to update it?"});if(M.isCancel(e)||!e)return M.log.error(le.red("nothing changed!")),await i(1)}if(!a){let e=await M.text({message:"enter your noto api key"});if(M.isCancel(e))return M.log.error(le.red("nothing changed!")),await i(1);a=e}await m.update((e)=>({...e,llm:{...e.llm,apiKey:a}})),M.log.success(le.green("noto api key configured!")),await i(0)});import*as E from"@clack/prompts";import Oe from"picocolors";import{createGoogleGenerativeAI as Mt}from"@ai-sdk/google";var V=Mt({apiKey:process.env.NOTO_API_KEY||(await m.get()).llm?.apiKey||"api-key"}),Ge="gemini-2.5-flash-lite",oe={"gemini-2.5-flash":V("gemini-2.5-flash"),"gemini-2.5-flash-lite":V("gemini-2.5-flash-lite"),"gemini-2.5-pro":V("gemini-2.5-pro"),"gemini-3-flash-preview":V("gemini-3-flash-preview"),"gemini-3-pro-preview":V("gemini-3-pro-preview")},kt=Object.keys(oe),me=async()=>{let o=(await m.get()).llm?.model;if(!o||!kt.includes(o))o=Ge,await m.update((t)=>({...t,llm:{...t.llm,model:Ge}}));return oe[o]};var De=x.meta({description:"configure model"}).mutation(async()=>{let o=await E.select({message:"select a model",initialValue:(await m.get()).llm?.model,options:Object.keys(oe).map((t)=>({label:t,value:t}))});if(E.isCancel(o))return E.log.error(Oe.red("nothing changed!")),await i(1);await m.update((t)=>({...t,llm:{...t.llm,model:o}})),E.log.success(Oe.green("model configured!")),await i(0)});import*as S from"@clack/prompts";import Fe from"picocolors";var je=x.meta({description:"reset the configuration"}).mutation(async()=>{let o=await S.confirm({message:"are you sure you want to reset the configuration?"});if(S.isCancel(o)||!o)return S.log.error(Fe.red("nothing changed!")),await i(1);await m.clear(),S.log.success(Fe.green("configuration reset!")),await i(0)});var Le=T.router({key:Se,model:De,reset:je});import{z as W}from"zod";import*as f from"@clack/prompts";import g from"picocolors";import Be from"dedent";import Pt from"clipboardy";var ze=ee.meta({description:"access the last generated commit",repoRequired:!1}).input(W.object({copy:W.boolean().meta({description:"copy the last commit to clipboard",alias:"c"}),apply:W.boolean().meta({description:"commit the last generated message",alias:"a"}),edit:W.boolean().meta({description:"edit the last generated commit message",alias:"e"}),amend:W.boolean().meta({description:"amend the last commit with the last message"})})).mutation(async(o)=>{let{input:t,ctx:a}=o,e=(await m.get()).lastGeneratedMessage;if(!e)return f.log.error(g.red("no previous commit message found")),await i(1);let{edit:r,amend:s}=t;if(s&&!r)return f.log.error(g.red("the --amend option requires the --edit option")),await i(1);if(f.log.step(r?g.white(e):g.green(e)),r){let n=await f.text({message:"edit the last generated commit message",initialValue:e,placeholder:e});if(f.isCancel(n))return f.log.error(g.red("nothing changed!")),await i(1);e=n,await m.update((h)=>({...h,lastGeneratedMessage:n})),f.log.step(g.green(e))}if(t.copy)Pt.writeSync(e),f.log.step(g.dim("copied last generated commit message to clipboard"));if(t.apply||s){if(!a.git.isRepository)return f.log.error(Be`${g.red("no git repository found in cwd.")}
|
|
7
7
|
${g.dim(`run ${g.cyan("`git init`")} to initialize a new repository.`)}`),await i(1);if(!a.git.diff&&!s)return f.log.error(Be`${g.red("no staged changes found.")}
|
|
8
8
|
${g.dim(`run ${g.cyan("`git add <file>`")} or ${g.cyan("`git add .`")} to stage changes.`)}`),await i(1);if(await j(e,s))f.log.step(g.dim("commit successful"));else f.log.error(g.red("failed to commit changes"))}return await i(0)});import Ye from"node:fs/promises";import{z as de}from"zod";import*as d from"@clack/prompts";import P from"picocolors";import K from"dedent";import{generateObject as We,wrapLanguageModel as Rt}from"ai";import ae from"zod";import _ from"dedent";import Ve from"superjson";import Ct from"node:crypto";function qe(o){let t=Buffer.from(o,"utf-8"),a=Buffer.from(`blob ${t.length}\x00`,"utf-8");return Ct.createHash("sha1").update(a).update(t).digest("hex")}var At=_`
|
|
9
9
|
# System Instruction for Noto
|
|
@@ -322,9 +322,9 @@ ${a}`:""}
|
|
|
322
322
|
# Add your custom guidelines here.
|
|
323
323
|
# When no guidelines are present, noto will use conventional commits format by default.`,He=te.meta({description:"initialize noto in the repository"}).input(de.object({root:de.boolean().meta({description:"create the prompt file in the git root"}),generate:de.boolean().meta({description:"generate a prompt file based on existing commits"})})).mutation(async(o)=>{let{input:t}=o,a=await H(),e=a,r=process.cwd(),s=await Q(),n=null;if(s)if(!s.startsWith(r)){d.log.warn(K`${P.yellow("a prompt file already exists!")}
|
|
324
324
|
${P.gray(s)}`);let y=await d.confirm({message:"do you want to create in the current directory instead?",initialValue:!0});if(d.isCancel(y)||!y)return d.log.error("aborted"),await i(1);e=r}else return d.log.error(K`${P.red("a prompt file already exists.")}
|
|
325
|
-
${P.gray(s)}`),await i(1);if(a!==r&&!t.root){let y=await d.confirm({message:"do you want to create the prompt file in the git root?",initialValue:!0});if(d.isCancel(y))return d.log.error("aborted"),await i(1);if(!y)e=r}let h=await he(20,!0),
|
|
326
|
-
${P.gray("at least 5 commits are required.")}`),await i(1)}else if(h&&h.length>=5){let y=await d.confirm({message:"do you want to generate a prompt file based on existing commits?",initialValue:!0});if(d.isCancel(y))return d.log.error("aborted"),await i(1);
|
|
327
|
-
${P.gray(ge)}`),await i(0)}catch{d.log.error(P.red("failed to create the prompt file!"))}});import{z as I}from"zod";import*as
|
|
328
|
-
${s}`:"";e.stop(v.red(`failed to generate commit message${n}`),1),await i(1)}});function Gt(o){if(typeof o!=="string")return;try{let t=JSON.parse(o);return t?.error?.message??t?.message}catch{return}}import{spawn as Ot}from"node:child_process";import{z as ue}from"zod";import*as $ from"@clack/prompts";import re from"picocolors";import Je from"semver";async function Dt(o){let t=await Me();if(!t.updateCommand){if(t.updateMessage)return $.log.warn(t.updateMessage),await i(0,!1);return $.log.error("unable to determine update command for your installation."),await i(1,!1)}let a=t.updateCommand.replace("@latest",`@${o}`),e=Ot(a,{stdio:"pipe",shell:!0}),r=$.spinner();r.start("upgrading noto");try{await new Promise((s,n)=>{e.on("close",(h)=>{if(h===0)s();else n()})}),r.stop(re.green("noto has been updated successfully!"))}catch{return $.log.error(`automatic update failed. please try updating manually by running: ${t.updateCommand}`),await i(1,!1)}return await A.update((s)=>({...s,update:void 0})),await i(0,!1)}var Qe=x.meta({description:"upgrade noto"}).input(ue.object({stable:ue.boolean().optional().meta({description:"upgrade to the latest stable version"}),beta:ue.boolean().optional().meta({description:"upgrade to the latest beta version"})})).mutation(async(o)=>{let{input:t}=o;if(t.stable&&t.beta)return $.log.error("please choose either --stable or --beta option, not both."),await i(1,!1);let a=t.stable?"stable":t.beta?"beta":"auto",e=$.spinner();e.start("fetching latest version");let r=await Z(!0,!0,a);if(!r)return e.stop(`You're already on the latest version of noto (${re.dim(`which is ${C}`)})`),await i(0,!1);e.stop(`noto ${re.green(r.latest)} is out! You are on ${re.dim(r.current)}.`);let n=Je.prerelease(r.latest)!==null||a==="beta"?"beta":r.latest;return await Dt(n)});var Ze={checkout:Ee,config:Le,prev:ze,init:He,noto:Xe,upgrade:Qe};var et=T.router(Ze);var tt=process.argv.slice(2),ot="
|
|
325
|
+
${P.gray(s)}`),await i(1);if(a!==r&&!t.root){let y=await d.confirm({message:"do you want to create the prompt file in the git root?",initialValue:!0});if(d.isCancel(y))return d.log.error("aborted"),await i(1);if(!y)e=r}let h=await he(20,!0),p=t.generate;if(p){if(!h||h.length<5)return d.log.error(K`${P.red("not enough commits to generate a prompt file.")}
|
|
326
|
+
${P.gray("at least 5 commits are required.")}`),await i(1)}else if(h&&h.length>=5){let y=await d.confirm({message:"do you want to generate a prompt file based on existing commits?",initialValue:!0});if(d.isCancel(y))return d.log.error("aborted"),await i(1);p=y}let G=d.spinner();if(h&&p)G.start("generating commit message guidelines"),n=await Ke(h),G.stop(P.green("generated commit message guidelines!"));else n=Nt;try{let y=`${e}/.noto`;await Ye.mkdir(y,{recursive:!0});let ge=`${y}/commit-prompt.md`;return await Ye.writeFile(ge,n,"utf-8"),d.log.success(K`${P.green("prompt file created!")}
|
|
327
|
+
${P.gray(ge)}`),await i(0)}catch{d.log.error(P.red("failed to create the prompt file!"))}});import{z as I}from"zod";import*as l from"@clack/prompts";import v from"picocolors";import Tt from"clipboardy";import{APICallError as Et,RetryError as St}from"ai";var Xe=te.meta({description:"generate a commit message",default:!0,diffRequired:!0,promptRequired:!0}).input(I.object({message:I.string().or(I.boolean()).meta({description:"provide context for commit message",alias:"m"}),copy:I.boolean().meta({description:"copy the generated message to clipboard",alias:"c"}),preview:I.boolean().meta({description:"preview the generated message without committing",alias:"p"}),push:I.boolean().meta({description:"commit and push the changes"}),force:I.boolean().meta({description:"bypass cache and force regeneration of commit message",alias:"f"}),manual:I.boolean().meta({description:"custom commit message"})})).mutation(async(o)=>{let{input:t,ctx:a}=o,e=l.spinner();try{if(t.manual){let p=await l.text({message:"edit the generated commit message",placeholder:"chore: init repo"});if(l.isCancel(p))return l.log.error(v.red("nothing changed!")),await i(1);if(l.log.step(v.green(p)),await m.update((y)=>({...y,lastGeneratedMessage:p})),await j(p))l.log.step(v.dim("commit successful"));else l.log.error(v.red("failed to commit changes"));return await i(0)}let s=t.message;if(typeof s==="string")s=s.trim();else if(typeof s==="boolean"&&s===!0){let p=await l.text({message:"provide context for the commit message",placeholder:"describe the changes"});if(l.isCancel(p))return l.log.error(v.red("nothing changed!")),await i(1);s=p}e.start("generating commit message");let n=null;n=await _e(a.git.diff,a.noto.prompt,typeof s==="string"?s:void 0,t.force),e.stop(v.white(n));let h=await l.text({message:"edit the generated commit message",initialValue:n,placeholder:n});if(l.isCancel(h))return l.log.error(v.red("nothing changed!")),await i(1);if(n=h,l.log.step(v.green(n)),await m.update((p)=>({...p,lastGeneratedMessage:n})),t.copy)Tt.writeSync(n),l.log.step(v.dim("copied commit message to clipboard"));if(!t.preview)if(await j(n))l.log.step(v.dim("commit successful"));else l.log.error(v.red("failed to commit changes"));if(t.push)if(await we())l.log.step(v.dim("push successful"));else l.log.error(v.red("failed to push changes"));return await i(0)}catch(r){let s;if(St.isInstance(r)&&Et.isInstance(r.lastError))s=Gt(r.lastError.responseBody);let n=s?`
|
|
328
|
+
${s}`:"";e.stop(v.red(`failed to generate commit message${n}`),1),await i(1)}});function Gt(o){if(typeof o!=="string")return;try{let t=JSON.parse(o);return t?.error?.message??t?.message}catch{return}}import{spawn as Ot}from"node:child_process";import{z as ue}from"zod";import*as $ from"@clack/prompts";import re from"picocolors";import Je from"semver";async function Dt(o){let t=await Me();if(!t.updateCommand){if(t.updateMessage)return $.log.warn(t.updateMessage),await i(0,!1);return $.log.error("unable to determine update command for your installation."),await i(1,!1)}let a=t.updateCommand.replace("@latest",`@${o}`),e=Ot(a,{stdio:"pipe",shell:!0}),r=$.spinner();r.start("upgrading noto");try{await new Promise((s,n)=>{e.on("close",(h)=>{if(h===0)s();else n()})}),r.stop(re.green("noto has been updated successfully!"))}catch{return $.log.error(`automatic update failed. please try updating manually by running: ${t.updateCommand}`),await i(1,!1)}return await A.update((s)=>({...s,update:void 0})),await i(0,!1)}var Qe=x.meta({description:"upgrade noto"}).input(ue.object({stable:ue.boolean().optional().meta({description:"upgrade to the latest stable version"}),beta:ue.boolean().optional().meta({description:"upgrade to the latest beta version"})})).mutation(async(o)=>{let{input:t}=o;if(t.stable&&t.beta)return $.log.error("please choose either --stable or --beta option, not both."),await i(1,!1);let a=t.stable?"stable":t.beta?"beta":"auto",e=$.spinner();e.start("fetching latest version");let r=await Z(!0,!0,a);if(!r)return e.stop(`You're already on the latest version of noto (${re.dim(`which is ${C}`)})`),await i(0,!1);e.stop(`noto ${re.green(r.latest)} is out! You are on ${re.dim(r.current)}.`);let n=Je.prerelease(r.latest)!==null||a==="beta"?"beta":r.latest;return await Dt(n)});var Ze={checkout:Ee,config:Le,prev:ze,init:He,noto:Xe,upgrade:Qe};var et=T.router(Ze);var tt=process.argv.slice(2),ot="2.0.0-beta.0";if(tt.includes("--version")||tt.includes("-v"))console.log(ot),process.exit(0);Ce();ce(!0);Ft({name:"noto",router:et,version:ot}).run();
|
|
329
329
|
|
|
330
330
|
// Made by a human on earth!
|