chief-clancy 0.7.4 → 0.8.1

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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  **Autonomous, board-driven development for Claude Code.**
4
4
 
5
- [![npm](https://img.shields.io/npm/v/chief-clancy?style=for-the-badge&color=cb3837)](https://www.npmjs.com/package/chief-clancy) [![License: MIT](https://img.shields.io/badge/License-MIT-blue?style=for-the-badge)](./LICENSE) [![Tests](https://img.shields.io/badge/tests-896%20passing-brightgreen?style=for-the-badge)](docs/TESTING.md) [![GitHub Stars](https://img.shields.io/github/stars/Pushedskydiver/clancy?style=for-the-badge)](https://github.com/Pushedskydiver/clancy/stargazers)
5
+ [![npm](https://img.shields.io/npm/v/chief-clancy?style=for-the-badge&color=cb3837)](https://www.npmjs.com/package/chief-clancy) [![License: MIT](https://img.shields.io/badge/License-MIT-blue?style=for-the-badge)](./LICENSE) [![Tests](https://img.shields.io/badge/tests-1217%20passing-brightgreen?style=for-the-badge)](docs/TESTING.md) [![GitHub Stars](https://img.shields.io/github/stars/Pushedskydiver/clancy?style=for-the-badge)](https://github.com/Pushedskydiver/clancy/stargazers)
6
6
 
7
7
  > [!WARNING]
8
8
  > Clancy is in early development. Expect bugs, breaking changes, and rough edges. If you hit an issue, please [open a bug report](https://github.com/Pushedskydiver/clancy/issues/new).
@@ -42,7 +42,7 @@ Brief → approve → plan → implement. Pipeline labels (`clancy:brief` → `c
42
42
 
43
43
  Clancy is for developers who:
44
44
 
45
- - Use a Kanban board (Jira, GitHub Issues, or Linear) and want Claude to work through their backlog unattended
45
+ - Use a Kanban board (Jira, GitHub Issues, Linear, Shortcut, Notion, or Azure DevOps) and want Claude to work through their backlog unattended
46
46
  - Are comfortable with Claude Code and want to extend it for team workflows — not just solo hacking
47
47
  - Have a codebase with enough structure that an AI agent can make meaningful progress on a ticket without constant hand-holding
48
48
  - Want to go AFK and come back to committed, merged work
@@ -91,6 +91,9 @@ A few ways to manage costs:
91
91
  - **Jira** — via REST API v3, JQL, ADF description parsing
92
92
  - **GitHub Issues** — via REST API with PR filtering
93
93
  - **Linear** — via GraphQL, `viewer.assignedIssues`, `state.type: unstarted`
94
+ - **Shortcut** — via REST API v3, workflow state resolution, epic stories
95
+ - **Notion** — via REST API, database rows as tickets, property name overrides
96
+ - **Azure DevOps** — via REST API, work items, org + project scoping
94
97
 
95
98
  Community can add boards — see [CONTRIBUTING.md](./CONTRIBUTING.md).
96
99
 
@@ -1,6 +1,6 @@
1
- import{spawnSync as J}from"node:child_process";import{existsSync as X}from"node:fs";import{dirname as Z,join as q,resolve as z}from"node:path";import{setTimeout as G}from"node:timers/promises";import{fileURLToPath as M}from"node:url";function $(t){let o=Math.floor(t/1e3);if(o<60)return`${o}s`;let r=Math.floor(o/60),i=o%60;if(r<60)return i>0?`${r}m ${i}s`:`${r}m`;let u=Math.floor(r/60),c=r%60;return c>0?`${u}h ${c}m`:`${u}h`}function L(t){return t.includes("hooks.slack.com")}function O(t){return JSON.stringify({text:t})}function _(t){return JSON.stringify({type:"message",attachments:[{contentType:"application/vnd.microsoft.card.adaptive",content:{$schema:"http://adaptivecards.io/schemas/adaptive-card.json",type:"AdaptiveCard",version:"1.4",body:[{type:"TextBlock",text:t,wrap:!0}]}}]})}async function C(t,o){let r=L(t)?O(o):_(o);try{let i=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:r});i.ok||console.warn(`\u26A0 Notification failed: HTTP ${i.status}`)}catch{console.warn("\u26A0 Notification failed: could not reach webhook")}}var p=t=>`\x1B[2m${t}\x1B[0m`,x=t=>`\x1B[1m${t}\x1B[0m`;var D=t=>`\x1B[32m${t}\x1B[0m`,w=t=>`\x1B[31m${t}\x1B[0m`;import{mkdirSync as j,readFileSync as B,writeFileSync as W}from"node:fs";import{join as E}from"node:path";import{appendFileSync as rt,mkdirSync as it,readFileSync as U}from"node:fs";import{dirname as at,join as K}from"node:path";function R(t){let o=K(t,".clancy","progress.txt"),r;try{r=U(o,"utf8")}catch{return[]}let i=[];for(let u of r.split(`
2
- `)){let c=u.trim();if(!c)continue;let s=c.split(" | ");if(s.length<4)continue;let l=s[0];if(s[1]==="BRIEF"||s[1]==="APPROVE_BRIEF"){i.push({timestamp:l,key:s[2],summary:s.slice(3).join(" | "),status:s[1]});continue}let f=s[1],a,h,y,k=[];for(let g=2;g<s.length;g++){let m=s[g],S=m.match(/^pr:(\d+)$/),n=m.match(/^parent:(.+)$/);S?h=parseInt(S[1],10):n?y=n[1]:g>=3&&!a&&m===m.toUpperCase()&&m.length>1?a=m:k.push(m)}a&&(a==="APPROVE"&&(a="APPROVE_PLAN"),i.push({timestamp:l,key:f,summary:k.join(" | "),status:a,...h!=null&&{prNumber:h},...y!=null&&{parent:y}}))}return i}function H(t,o){let r=E(t,".clancy","costs.log"),i;try{i=B(r,"utf8")}catch{return[]}let u=[];for(let c of i.split(`
3
- `)){let s=c.trim();if(!s)continue;let l=s.split(" | ");if(l.length<4)continue;let f=l[0],a=new Date(f).getTime();Number.isNaN(a)||a<o||u.push({timestamp:f,key:l[1],duration:l[2],tokens:l[3]})}return u}function Y(t){return/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}$/.test(t)?new Date(t.replace(" ","T")+":00Z").getTime():NaN}var A=new Set(["DONE","PR_CREATED","PUSHED","EPIC_PR_CREATED","RESUMED"]),V=new Set(["SKIPPED","PUSH_FAILED","TIME_LIMIT"]);function F(t,o,r){let i=Math.floor(o/6e4)*6e4,c=R(t).filter(e=>{let d=Y(e.timestamp);return!Number.isNaN(d)&&d>=i}),s=H(t,o),l=new Map;for(let e of s)l.set(e.key,e);let f=new Map;for(let e of c)f.set(e.key,e);let a=[];for(let e of f.values()){let d=l.get(e.key);a.push({key:e.key,summary:e.summary,status:e.status,...e.prNumber!=null&&{prNumber:e.prNumber},...d&&{duration:d.duration,tokens:d.tokens}})}let h=a.filter(e=>A.has(e.status)),y=a.filter(e=>V.has(e.status)),k=$(r-o),g=0;for(let e of s){let d=e.tokens.match(/~(\d[\d,]*)/);d&&(g+=parseInt(d[1].replace(/,/g,""),10))}let m=new Date(o),S=`${m.getUTCFullYear()}-${String(m.getUTCMonth()+1).padStart(2,"0")}-${String(m.getUTCDate()).padStart(2,"0")}`,n=[];n.push(`# AFK Session Report \u2014 ${S}`),n.push(""),n.push("## Summary"),n.push(`- Tickets completed: ${h.length}`),n.push(`- Tickets failed: ${y.length}`),n.push(`- Total duration: ${k}`),g>0&&n.push(`- Estimated token usage: ${g.toLocaleString("en-US")}`),n.push(""),n.push("## Tickets"),a.length===0&&(n.push(""),n.push("No tickets were processed in this session."));for(let e of a){let I=A.has(e.status)?"\u2713":"\u2717";n.push(""),n.push(`### ${I} ${e.key} \u2014 ${e.summary}`),e.duration&&n.push(`- Duration: ${e.duration}`),e.tokens&&n.push(`- Tokens: ${e.tokens}`),e.prNumber!=null&&n.push(`- PR: #${e.prNumber}`),n.push(`- Status: ${e.status}`)}let T=a.filter(e=>e.prNumber!=null).map(e=>`#${e.prNumber}`),b=y.map(e=>e.key);if(T.length>0||b.length>0){n.push(""),n.push("## Next Steps"),T.length>0&&n.push(`- Review PRs ${T.join(", ")}`);for(let e of b)n.push(`- ${e} needs manual intervention`)}n.push("");let N=n.join(`
4
- `);try{let e=E(t,".clancy","session-report.md");j(E(t,".clancy"),{recursive:!0}),W(e,N,"utf8")}catch{}return N}var P={noTickets:/No tickets found|No issues found|All done/,skipped:/Ticket skipped/,preflightFail:/^✗ /m};function Q(t){return P.noTickets.test(t)?{stop:!0,reason:"No more tickets \u2014 all done"}:P.skipped.test(t)?{stop:!0,reason:"Ticket was skipped \u2014 update the ticket and re-run"}:P.preflightFail.test(t)?{stop:!0,reason:"Preflight check failed"}:{stop:!1}}async function tt(t,o=5){let r=q(t,"clancy-once.js");if(!X(r)){console.error(w("\u2717 clancy-once.js not found in"),t);return}console.log(p("\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510")),console.log(p("\u2502")+x(" \u{1F916} Clancy \u2014 AFK mode ")+p("\u2502")),console.log(p("\u2502")+p(` "I'm on it. Proceed to the abandoned warehouse." `)+p("\u2502")),console.log(p("\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518"));let i=Date.now();for(let c=1;c<=o;c++){let s=Date.now();console.log(""),console.log(x(`\u{1F501} Iteration ${c}/${o}`));let l=J("node",[r],{encoding:"utf8",stdio:["inherit","pipe","inherit"],cwd:process.cwd(),env:{...process.env,CLANCY_AFK_MODE:"1"}}),f=l.stdout??"";f&&process.stdout.write(f);let a=$(Date.now()-s);if(l.error){console.error(w(`\u2717 Failed to run clancy-once: ${l.error.message}`));return}let h=Q(f);if(h.stop){let y=$(Date.now()-i);console.log(""),console.log(p(` Iteration ${c} took ${a}`)),console.log(`
5
- ${h.reason}`),console.log(p(` Total: ${c} iteration${c>1?"s":""} in ${y}`)),v(i);return}console.log(p(` Iteration ${c} took ${a}`)),c<o&&await G(2e3)}let u=$(Date.now()-i);console.log(""),console.log(D(`\u{1F3C1} Completed ${o} iterations`)+p(` (${u})`)),console.log(p(` "That's some good police work."`)),console.log(p(" Run clancy-afk again to continue.")),v(i)}function v(t){try{let o=F(process.cwd(),t,Date.now());console.log(""),console.log(p("\u2500\u2500\u2500 Session Report \u2500\u2500\u2500")),console.log(o);let r=process.env.CLANCY_NOTIFY_WEBHOOK;if(r){let c=`Clancy AFK: ${o.split(`
6
- `).filter(s=>s.startsWith("- Tickets")||s.startsWith("- Total")).join(". ")}. Report: .clancy/session-report.md`;C(r,c).catch(()=>{})}}catch{}}if(process.argv[1]&&M(import.meta.url)===z(process.argv[1])){let t=Z(M(import.meta.url)),o=parseInt(process.env.MAX_ITERATIONS??"5",10)||5;tt(t,o)}export{Q as checkStopCondition,tt as runAfkLoop};
1
+ import{spawnSync as nt}from"node:child_process";import{existsSync as st}from"node:fs";import{dirname as rt,join as it,resolve as ct}from"node:path";import{setTimeout as F}from"node:timers/promises";import{fileURLToPath as _}from"node:url";function $(t){let n=Math.floor(t/1e3);if(n<60)return`${n}s`;let o=Math.floor(n/60),r=n%60;if(o<60)return r>0?`${o}m ${r}s`:`${o}m`;let l=Math.floor(o/60),c=o%60;return c>0?`${l}h ${c}m`:`${l}h`}function j(t){return t.includes("hooks.slack.com")}function B(t){return JSON.stringify({text:t})}function H(t){return JSON.stringify({type:"message",attachments:[{contentType:"application/vnd.microsoft.card.adaptive",content:{$schema:"http://adaptivecards.io/schemas/adaptive-card.json",type:"AdaptiveCard",version:"1.4",body:[{type:"TextBlock",text:t,wrap:!0}]}}]})}async function N(t,n){let o=j(t)?B(n):H(n);try{let r=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:o});r.ok||console.warn(`\u26A0 Notification failed: HTTP ${r.status}`)}catch{console.warn("\u26A0 Notification failed: could not reach webhook")}}var p=t=>`\x1B[2m${t}\x1B[0m`,w=t=>`\x1B[1m${t}\x1B[0m`;var P=t=>`\x1B[32m${t}\x1B[0m`,x=t=>`\x1B[31m${t}\x1B[0m`,M=t=>`\x1B[33m${t}\x1B[0m`;import{mkdirSync as Z,readFileSync as z,writeFileSync as G}from"node:fs";import{join as v}from"node:path";import{mkdirSync as yt,readFileSync as K,renameSync as ht,writeFileSync as gt}from"node:fs";import{join as V}from"node:path";function Y(t){return V(t,".clancy","quality.json")}function q(t){try{let n=K(Y(t),"utf8"),o=JSON.parse(n);if(o&&typeof o.tickets=="object"&&o.tickets!==null&&!Array.isArray(o.tickets))return W(o),o}catch{}return{tickets:{},summary:{totalTickets:0,avgReworkCycles:0,avgVerificationRetries:0,avgDuration:0}}}function W(t){let n=Object.values(t.tickets),o=n.length;if(o===0){t.summary={totalTickets:0,avgReworkCycles:0,avgVerificationRetries:0,avgDuration:0};return}let r=0,l=0,c=0,s=0;for(let a of n)r+=a.reworkCycles,l+=a.verificationRetries,a.duration!=null&&(c+=a.duration,s++);t.summary={totalTickets:o,avgReworkCycles:Math.round(r/o*100)/100,avgVerificationRetries:Math.round(l/o*100)/100,avgDuration:s>0?Math.round(c/s*100)/100:0}}function R(t){let n=q(t);if(Object.keys(n.tickets).length!==0)return n}import{appendFileSync as Tt,mkdirSync as wt,readFileSync as J}from"node:fs";import{dirname as vt,join as X}from"node:path";function b(t){let n=X(t,".clancy","progress.txt"),o;try{o=J(n,"utf8")}catch{return[]}let r=[];for(let l of o.split(`
2
+ `)){let c=l.trim();if(!c)continue;let s=c.split(" | ");if(s.length<4)continue;let a=s[0];if(s[1]==="BRIEF"||s[1]==="APPROVE_BRIEF"){r.push({timestamp:a,key:s[2],summary:s.slice(3).join(" | "),status:s[1]});continue}let m=s[1],u,y,g,k=[];for(let f=2;f<s.length;f++){let d=s[f],S=d.match(/^pr:(\d+)$/),i=d.match(/^parent:(.+)$/);S?y=parseInt(S[1],10):i?g=i[1]:f>=3&&!u&&d===d.toUpperCase()&&d.length>1?u=d:k.push(d)}u&&(u==="APPROVE"&&(u="APPROVE_PLAN"),r.push({timestamp:a,key:m,summary:k.join(" | "),status:u,...y!=null&&{prNumber:y},...g!=null&&{parent:g}}))}return r}function tt(t,n){let o=v(t,".clancy","costs.log"),r;try{r=z(o,"utf8")}catch{return[]}let l=[];for(let c of r.split(`
3
+ `)){let s=c.trim();if(!s)continue;let a=s.split(" | ");if(a.length<4)continue;let m=a[0],u=new Date(m).getTime();Number.isNaN(u)||u<n||l.push({timestamp:m,key:a[1],duration:a[2],tokens:a[3]})}return l}function et(t){return/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}$/.test(t)?new Date(t.replace(" ","T")+":00Z").getTime():NaN}var A=new Set(["DONE","PR_CREATED","PUSHED","EPIC_PR_CREATED","RESUMED"]),ot=new Set(["SKIPPED","PUSH_FAILED","TIME_LIMIT"]);function I(t,n,o){let r=Math.floor(n/6e4)*6e4,c=b(t).filter(e=>{let h=et(e.timestamp);return!Number.isNaN(h)&&h>=r}),s=tt(t,n),a=new Map;for(let e of s)a.set(e.key,e);let m=new Map;for(let e of c)m.set(e.key,e);let u=[];for(let e of m.values()){let h=a.get(e.key);u.push({key:e.key,summary:e.summary,status:e.status,...e.prNumber!=null&&{prNumber:e.prNumber},...h&&{duration:h.duration,tokens:h.tokens}})}let y=u.filter(e=>A.has(e.status)),g=u.filter(e=>ot.has(e.status)),k=$(o-n),f=0;for(let e of s){let h=e.tokens.match(/~(\d[\d,]*)/);h&&(f+=parseInt(h[1].replace(/,/g,""),10))}let d=new Date(n),S=`${d.getUTCFullYear()}-${String(d.getUTCMonth()+1).padStart(2,"0")}-${String(d.getUTCDate()).padStart(2,"0")}`,i=[];i.push(`# AFK Session Report \u2014 ${S}`),i.push(""),i.push("## Summary"),i.push(`- Tickets completed: ${y.length}`),i.push(`- Tickets failed: ${g.length}`),i.push(`- Total duration: ${k}`),f>0&&i.push(`- Estimated token usage: ${f.toLocaleString("en-US")}`),i.push(""),i.push("## Tickets"),u.length===0&&(i.push(""),i.push("No tickets were processed in this session."));for(let e of u){let Q=A.has(e.status)?"\u2713":"\u2717";i.push(""),i.push(`### ${Q} ${e.key} \u2014 ${e.summary}`),e.duration&&i.push(`- Duration: ${e.duration}`),e.tokens&&i.push(`- Tokens: ${e.tokens}`),e.prNumber!=null&&i.push(`- PR: #${e.prNumber}`),i.push(`- Status: ${e.status}`)}let T=u.filter(e=>e.prNumber!=null).map(e=>`#${e.prNumber}`),C=g.map(e=>e.key);if(T.length>0||C.length>0){i.push(""),i.push("## Next Steps"),T.length>0&&i.push(`- Review PRs ${T.join(", ")}`);for(let e of C)i.push(`- ${e} needs manual intervention`)}try{let e=R(t);e&&(i.push(""),i.push("## Quality Metrics"),i.push(`- Avg rework cycles: ${e.summary.avgReworkCycles}`),i.push(`- Avg verification retries: ${e.summary.avgVerificationRetries}`),e.summary.avgDuration>0&&i.push(`- Avg delivery time: ${$(e.summary.avgDuration)}`))}catch{}i.push("");let D=i.join(`
4
+ `);try{let e=v(t,".clancy","session-report.md");Z(v(t,".clancy"),{recursive:!0}),G(e,D,"utf8")}catch{}return D}function L(t){let n=t.trim().match(/^(\d{1,2}):(\d{2})$/);if(!n)return null;let o=parseInt(n[1],10),r=parseInt(n[2],10);return o<0||o>23||r<0||r>59?null:{hours:o,minutes:r}}var O=!1;function at(t,n,o=new Date){let r=L(t),l=L(n);if(!r||!l)return O||(console.warn("\u26A0 Invalid quiet hours format. Expected HH:MM (24h). Quiet hours disabled."),O=!0),0;let c=o.getHours()*60+o.getMinutes(),s=r.hours*60+r.minutes,a=l.hours*60+l.minutes,m=!1;if(s<a?m=c>=s&&c<a:s>a&&(m=c>=s||c<a),!m)return 0;let u=a-c;u<=0&&(u+=1440);let y=o.getSeconds()*1e3+o.getMilliseconds();return Math.max(0,u*6e4-y)}var E={noTickets:/No tickets found|No issues found|All done/,skipped:/Ticket skipped/,preflightFail:/^✗ /m};function ut(t){return E.noTickets.test(t)?{stop:!0,reason:"No more tickets \u2014 all done"}:E.skipped.test(t)?{stop:!0,reason:"Ticket was skipped \u2014 update the ticket and re-run"}:E.preflightFail.test(t)?{stop:!0,reason:"Preflight check failed"}:{stop:!1}}async function lt(t,n=5){let o=it(t,"clancy-once.js");if(!st(o)){console.error(x("\u2717 clancy-once.js not found in"),t);return}console.log(p("\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510")),console.log(p("\u2502")+w(" \u{1F916} Clancy \u2014 AFK mode ")+p("\u2502")),console.log(p("\u2502")+p(` "I'm on it. Proceed to the abandoned warehouse." `)+p("\u2502")),console.log(p("\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518"));let r=Date.now();for(let c=1;c<=n;c++){let s=process.env.CLANCY_QUIET_START,a=process.env.CLANCY_QUIET_END;if(s&&a){let f=at(s,a);if(f>0){let d=Math.ceil(f/6e4);console.log(""),console.log(M(`\u23F8 Quiet hours active (${s}\u2013${a}). Sleeping ${d} minutes until ${a}.`)),await F(f),console.log(p(" Quiet hours ended. Resuming."))}}else(s&&!a||!s&&a)&&console.log(p(" \u26A0 Only one of CLANCY_QUIET_START / CLANCY_QUIET_END is set \u2014 skipping quiet hours check."));let m=Date.now();console.log(""),console.log(w(`\u{1F501} Iteration ${c}/${n}`));let u=nt("node",[o],{encoding:"utf8",stdio:["inherit","pipe","inherit"],cwd:process.cwd(),env:{...process.env,CLANCY_AFK_MODE:"1"}}),y=u.stdout??"";y&&process.stdout.write(y);let g=$(Date.now()-m);if(u.error){console.error(x(`\u2717 Failed to run clancy-once: ${u.error.message}`));return}let k=ut(y);if(k.stop){let f=$(Date.now()-r);console.log(""),console.log(p(` Iteration ${c} took ${g}`)),console.log(`
5
+ ${k.reason}`),console.log(p(` Total: ${c} iteration${c>1?"s":""} in ${f}`)),U(r);return}console.log(p(` Iteration ${c} took ${g}`)),c<n&&await F(2e3)}let l=$(Date.now()-r);console.log(""),console.log(P(`\u{1F3C1} Completed ${n} iterations`)+p(` (${l})`)),console.log(p(` "That's some good police work."`)),console.log(p(" Run clancy-afk again to continue.")),U(r)}function U(t){try{let n=I(process.cwd(),t,Date.now());console.log(""),console.log(p("\u2500\u2500\u2500 Session Report \u2500\u2500\u2500")),console.log(n);let o=process.env.CLANCY_NOTIFY_WEBHOOK;if(o){let c=`Clancy AFK: ${n.split(`
6
+ `).filter(s=>s.startsWith("- Tickets")||s.startsWith("- Total")).join(". ")}. Report: .clancy/session-report.md`;N(o,c).catch(()=>{})}}catch{}}if(process.argv[1]&&_(import.meta.url)===ct(process.argv[1])){let t=rt(_(import.meta.url)),n=parseInt(process.env.MAX_ITERATIONS??"5",10)||5;lt(t,n)}export{ut as checkStopCondition,at as getQuietSleepMs,L as parseTime,lt as runAfkLoop};