document360-writer 0.4.92 → 0.4.93

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.
Files changed (2) hide show
  1. package/dist/cli.js +1 -1
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -245,7 +245,7 @@ Articles:
245
245
  ${Zd}
246
246
  Run /doctor anytime to re-check and see the fix. (You can configure Document360 meanwhile \u2014 the agent just needs Claude before it writes.)`}),!Q(e)){u({kind:"note",tone:"info",text:`Welcome! This repo isn't set up for d360-writer yet \u2014 three steps and you're writing docs:
247
247
  ${Ua}`}),q(l?["/doctor","/init"]:["/init"]);return}l&&q(["/doctor"]);try{let i=ce(e,s),a=Me(i.name);a&&De(a)&&a.refreshToken?op({profile:i.name,connection:i.connection}).then(()=>{u({kind:"note",tone:"ok",text:"\u2713 Document360 session refreshed."}),re(g=>g+1)}).catch(()=>{u({kind:"note",tone:"warn",text:"Document360 session refresh failed \u2014 do you want to log in now? (press 1)"}),q(["/login"])}):(!a||De(a))&&(u({kind:"note",tone:"warn",text:`Profile "${i.name}" is not signed in \u2014 do you want to log in now? (press 1)`}),q(["/login"]))}catch{}try{let i=Q(e),a=ce(e,s),g=Me(a.name);i&&g&&!De(g)&&Wa(e,i.authoritativeSourceFiles)&&(u({kind:"note",tone:"info",text:"Large repo \u2014 the docs scope isn\u2019t set yet. Run /scope to choose which folders back your docs."}),q(["/scope"]))}catch{}try{vn(e);let i=Cn(e);i.length&&(u({kind:"note",tone:"warn",text:i.join(`
248
- `)}),ft(ze()),Dt.current=!1)}catch{}try{let i=Q(e),a=ce(e,s),g=Me(a.name),d=!!g&&(!De(g)||!!g.refreshToken),m=!i||!Wa(e,i.authoritativeSourceFiles);if(i&&d&&m&&!l){let w=Ur(e,a.name),v=w?Object.keys(w.articles).length:0,j=vt($t(e));if(v>0){let E=j?["/catch-up","/audit","/sync","/publish"]:["/audit","/sync","/publish","/catch-up"],te={"/audit":"find gaps & what changed in the code","/sync":"check drift vs Document360","/publish":"push drafts live","/catch-up":j?`do the queued work (${j}) + drift`:"process anything the builder queued"},V=j?`\u{1F4CB} ${j} queued by the builder \xB7 \u{1F4DA} ${v} article${v===1?"":"s"} tracked for "${a.name}". What next?`:`\u{1F4DA} ${v} article${v===1?"":"s"} tracked for "${a.name}". What next?`;u({kind:"note",tone:"info",text:[V,...E.map(($,P)=>` ${P+1} ${$.padEnd(9)} ${te[$]}`),"Or just tell me what to write or update."].join(`
248
+ `)}),ft(ze()),Dt.current=!1)}catch{}try{let i=Q(e),a=ce(e,s),g=Me(a.name),d=!!g&&(!De(g)||!!g.refreshToken),m=!i||!Wa(e,i.authoritativeSourceFiles);if(i&&d&&m&&!l){let w=Ur(e,a.name),v=w?Object.keys(w.articles).length:0,j=vt($t(e));if(v>0){let E=j?["/catch-up","/audit"]:["/audit","/sync"],te={"/catch-up":"write up everything your builder flagged","/audit":j?"also scan the code for other changes":"check the code for anything new or missing in the docs","/sync":"check Document360 for changes made there"},V=j?`\u{1F4CB} Your builder left ${j} for the docs:`:`\u{1F4DA} ${v} article${v===1?"":"s"} tracked for "${a.name}". What next?`;u({kind:"note",tone:"info",text:[V,...E.map(($,P)=>` ${P+1} ${$.padEnd(9)} ${te[$]}`),"Or just tell me what to write or update."].join(`
249
249
  `)}),q(E)}else u({kind:"note",tone:"info",text:'\u{1F4ED} No docs yet for this repo. Tell me "write the docs for this repo" and I\u2019ll read the code and draft a structure \u2014 or /audit to see what the docs should cover.'}),se("write the docs for this repo"),q(j?["/catch-up","/audit"]:["/audit"])}}catch{}ao()},[]),$e(()=>{let l=setInterval(()=>{ao()},Mp);return()=>clearInterval(l)},[ao]),$e(()=>{let l=null,i=null,a=()=>{l&&clearTimeout(l),l=setTimeout(()=>{l=null;let g=`${be.columns??80}x${be.rows??24}`;g!==Jr.current&&(Jr.current=g,Qa(d=>d+1),i&&clearTimeout(i),i=setTimeout(()=>{i=null,console.log("\x1B[?2026h\x1B[H\x1B[2J"+ei(nt.current,Ie())+"\x1B[?2026l")},80))},400)};return be.on("resize",a),()=>{l&&clearTimeout(l),i&&clearTimeout(i),be.off("resize",a)}},[be,Ie]);let Ye=Math.max(20,(be.columns??80)-1),Qr=Ir(()=>Ep(e,s),[e,s,ve]),po=(()=>{let l=Q(e);if(!l)return{text:"Press 1 to set up this repo, or /help\u2026",isSetup:!0};let i=Xt(e,(l.docsDir??qa).replace(/\/+$/,"")),a=(()=>{try{return Yt(i)&&Fa(i).length>0}catch{return!1}})();try{let g=ce(e,s),d=Me(g.name);if(!(!!d&&!(De(d)&&!d.refreshToken)))return{text:`Press 1 to sign in to Document360 (profile "${g.name}")\u2026`,isSetup:!0};if(!g.project.projectId)return{text:"Sign in to Document360 to pick your project\u2026",isSetup:!0};if(!g.project.workspaceId&&!a)return{text:"Press 1 to pick a workspace\u2026",isSetup:!0}}catch{}return a?{text:Ip,isSetup:!1}:ro?{text:"Press c to copy the prompt above, run it in your coding agent \u2014 then ask me to write the docs",isSetup:!1}:{text:"Ask me to write the docs for this repo",isSetup:!1}})(),jt=Cs(D),Zr=jt.length>0&&!_,fo=p!==null?ja(p,8,Ye):null,on=ge?ge.paths.filter(l=>!ge.query||l.toLowerCase().includes(ge.query.toLowerCase())).slice(0,8):[],rn=ye?ye.sessions.filter(l=>{let i=ye.query.toLowerCase();return!i||l.name.toLowerCase().includes(i)||l.firstPrompt.toLowerCase().includes(i)}).slice(0,8):[],de=G((l,i)=>{me.current?.close(),me.current=Ea({cwd:e,resume:l,profileName:i??s,allowProdWrites:ot.current}),l||(Ce.current={uuid:null,firstPrompt:null,titleFired:!1},rt(null)),dt(0),pt(0)},[e,s]),es=G((l,i,a)=>{if(Np.test(l))try{let g=ce(e,s),d=typeof i.project_id=="string"&&i.project_id||g.project.projectId,m=qn(i,a),w=[],v=Bn(a);l.endsWith("publish_article")&&v&&w.push(`Live: ${v}`),m&&d&&w.push(`Preview: ${Hn(g.connection.portalUrl,d,m,g.project.languageCode??"en")}`),w.length>0&&u({kind:"link",lines:w})}catch{}},[e,s,u]),pe=G(async(l,i)=>{Kt(!0),se(null),q([]),Zt(null),so(null),uo(null);let a=++Qe.current;i?.quietUser||u({kind:"user",text:i?.echoDisplay&&i.display?i.display:l});let g=Ce.current;g.firstPrompt||(g.firstPrompt=i?.display??l),We.current=Date.now(),Ze(0),U(!0),Qt.current.clear();let d="",m=!1,w=!1,v="",j=null,E=()=>{j||(j=setTimeout(()=>{j=null,h(v.length>0?v:null)},60))},te=()=>{j&&clearTimeout(j),j=null,h(null)},V=()=>{if(v.trim()){let $=v.trimEnd();u({kind:"assistant",text:$})}v="",te()};try{for await(let $ of me.current.send(l))if($.type==="session"){if(!g.uuid){g.uuid=$.sessionId;let P=new Date().toISOString(),N=cp(g.firstPrompt??"session");up({uuid:$.sessionId,name:N,renamed:!1,titled:!1,cwd:e,firstPrompt:g.firstPrompt??"",createdAt:P,updatedAt:P}),rt(N)}}else if($.type==="text"){v+=$.delta,d+=$.delta;let P=Aa(v);if(P>0){let N=v.slice(0,P).trimEnd();N&&u({kind:"assistant",text:N}),v=v.slice(P)}E(),Ze(N=>N+$.delta.length)}else if($.type==="tool"){m=!0;let P=Wn($.name,$.input);P&&(V(),u({kind:"tool",title:P.title,sep:P.sep,arg:P.arg}),Qt.current.set($.id,{name:$.name,input:$.input}))}else if($.type==="article_diff"){let P=Ke($.oldContent,$.newContent,Ie());P&&(V(),u({kind:"diff",added:P.added,removed:P.removed,lines:P.lines,hidden:P.hidden}))}else if($.type==="tool_result"){$.isError&&/run \/login|not logged in|session expired|rejected the token/i.test($.output)&&(en.current=!0);let P=Qt.current.get($.id);if(P){Qt.current.delete($.id),V();let N=Fn($.output,4,$.isError?void 0:P.name,P.input);u({kind:"tool-result",lines:N.lines,hidden:N.hidden,isError:$.isError}),$.isError||es(P.name,P.input,$.output)}}else if($.type==="result"){if(V(),dt(N=>N+$.outputTokens),pt(N=>N+$.costUsd),u({kind:"done",seconds:Math.round((Date.now()-We.current)/1e3),tokens:$.outputTokens,costUsd:$.costUsd,ok:$.ok}),!w&&!m&&!d.trim()&&!St.current&&u({kind:"note",tone:"warn",text:"The agent produced no output. This usually means the Claude model/runtime did not start \u2014 check sign-in and model with /doctor (on a subscription, make sure Claude Code is logged in on this machine)."}),$.ok&&/🛠|📣 Feedback for the d360-writer developers/.test(d))try{let N=Rp(e);if(Yt(N)){let J=Nr(N,"utf8").trim();J&&(uo(J),u({kind:"note",tone:"info",text:"\u{1F6E0} Press c to copy this feedback \u2014 send it to the d360-writer team (Teams / Slack / email)."}))}}catch{}let P=$.ok?ba(d,_t.map(N=>N.name)):[];if(P.length>0?q(P):$.ok&&d.trim()&&mp(l,d,e).then(N=>{N&&Qe.current===a&&se(N)}).catch(()=>{}),g.uuid&&(_r(g.uuid),!g.titleFired)){g.titleFired=!0;let N=g.uuid,J=g.firstPrompt;J&&Ia(J,e).then(O=>{O&&(lp(N,O),rt(O))}).catch(()=>{})}}else $.type==="error"&&(V(),w=!0,$.kind==="auth"&&(en.current=!0),u({kind:"note",text:`agent error: ${$.message}`,tone:"error"}))}finally{U(!1),te(),re($=>$+1),Ce.current.uuid&&ya(e,Ce.current.uuid,nt.current),en.current&&(en.current=!1,tn.current=i?.display??l,q(["/login"])),St.current&&(St.current=!1,Ge.current.length>0&&(u({kind:"note",tone:"info",text:`(${Ge.current.length} queued message(s) discarded)`}),Ge.current=[],no([])),u({kind:"note",tone:"warn",text:"Interrupted. What do you want to do next?"}))}},[e,u,es,Ie]),sn=G(async l=>{let i=Lr(l),a=Jn(e,"standard");We.current=Date.now(),Ze(0),U(!0);let g=new AbortController;we.current=g,K({verb:"Publishing",total:i.length,done:0,active:[],rows:Vt(i),tools:0,chars:0,lastAt:Date.now(),startedAt:Date.now()}),u({kind:"note",tone:"info",text:`Publishing ${l.length} article${l.length===1?"":"s"} across ${i.length} partition${i.length===1?"":"s"} (\u2264${Wt} agents at once) on ${a.model}\u2026 (esc to stop)`});try{for await(let d of Kn({cwd:e,partitions:i,promptFor:m=>Rn(m.paths),concurrency:Wt,profileName:s,allowProdWrites:ot.current,model:a.model,signal:g.signal}))if(d.type==="partition_status")d.status==="running"?K(m=>m&&{...m,active:[...m.active,d.label],rows:Re(m.rows,d.label,"active"),lastAt:Date.now()}):K(m=>m&&{...m,active:m.active.filter(w=>w!==d.label),done:m.done+1,rows:Re(m.rows,d.label,d.status==="done"?"done":"failed"),lastAt:Date.now()});else if(d.type==="partition_event")K(m=>{if(!m)return m;let w={...m,lastAt:Date.now()};return d.event.type==="tool"?w.tools=m.tools+1:d.event.type==="text"&&(w.chars=m.chars+d.event.delta.length),w});else if(d.type==="run_done"){pt(v=>v+d.totalCostUsd),dt(v=>v+d.results.reduce((j,E)=>j+E.outputTokens,0));let m=d.aborted?"Stopped. ":"",w=t.kind==="api"?"api":"subscription";u({kind:"note",tone:d.aborted?"warn":d.ok?"ok":"warn",text:m+Mo(d.results,i,w).join(`
250
250
  `)})}}catch(d){u({kind:"note",tone:"error",text:`Publish run failed: ${d.message}`})}finally{we.current=null,K(null),U(!1),re(d=>d+1)}},[e,s,u,t]),mo=G(async l=>{await pe(Lo(l),{display:`/publish ${l}`,quietUser:!0});try{let i=await Dn(e,s,l.replace(/\\/g,"/"));i.length>0&&(Zt(`Related articles not yet published (${i.length}):`),q([`/publish --related ${l}`,...i.map(a=>`/publish ${a}`)]))}catch{}},[e,s,pe]),ho=G(l=>{let i=Me(l);if(!i||De(i)&&!i.refreshToken)return null;let a={...Ct(i.idToken)??{},...Ct(i.accessToken)??{}};return a.email??a.preferred_username??"signed in"},[]),go=G((l,i)=>{if(i){let a=Q(e);a&&(a.defaultProfile=l,hp(a,e))}c(l),de(void 0,l),u({kind:"note",tone:"ok",text:`\u2713 Switched to profile "${l}"${i?" (saved as default)":" (this session only)"} \u2014 agent restarted.`}),ho(l)||(u({kind:"note",tone:"warn",text:`Profile "${l}" is not signed in \u2014 do you want to log in now? (press 1)`}),q(["/login"])),re(a=>a+1)},[e,u,de,ho]),an=G((l,i,a)=>{pn(e,l,i,a.id,a.name),u({kind:"note",tone:"ok",text:`Switched to workspace "${a.name??a.id}" (agent restarted).`}),de(),Ur(e,l)||(u({kind:"note",tone:"ok",text:"\u2713 Connected. Configuration is done \u2014 one important step remains."}),u({kind:"note",tone:"warn",text:"\u26A0 Before I write the docs, hand the prompt below to your builder (your repo's coding agent). It gives me the architecture brief that makes the docs accurate:"}),u({kind:"note",tone:"info",text:kt(yt(e)).join(`
251
251
  `)}),ft(ze()),Dt.current=_e(e).status==="current",u({kind:"note",tone:"info",text:`No separate builder agent? Then just ask me now: "write the docs for this repo" \u2014 I'll read the code directly.`}))},[e,u,de,ft]),ln=G(async l=>{let i;try{i=await It(e,l)}catch{u({kind:"note",tone:"info",text:"Next: pick a workspace \u2014 run /workspace."}),q(["/workspace"]);return}if(i.workspaces.length===0){u({kind:"note",tone:"warn",text:"This project has no workspaces yet. Create one in Document360, then run /workspace."});return}let a=i.workspaces.filter(d=>(d.workspace_type??"").toLowerCase()!=="apidocumentation"),g=a.length>0?a:i.workspaces;if(g.length===1){let d=g[0],m=i.workspaces.length-g.length;u({kind:"note",tone:"ok",text:`Selected the "${d.name??d.id}" workspace${m>0?" (skipped the API-documentation workspace)":""}.`}),an(i.profile,i.projectId,d);return}u({kind:"note",tone:"info",text:`Next: pick the workspace your articles publish to (${g.length} available).`}),q(["/workspace"])},[e,u,an]),ts=G((l,i)=>{xo(e,l,i.id,i.name),u({kind:"note",tone:"ok",text:`Project set to "${i.name??i.id}" (agent restarted).`}),de(),ln(l)},[e,u,de,ln]),ns=G(async l=>{let i;try{i=ce(e,l)}catch{return}if(!i.project.workspaceId){if(i.project.projectId){if(!i.project.projectName)try{let{projects:a}=await gt(e,i.name),g=a.find(d=>d.id===i.project.projectId);g?.name&&Dp(e,i.name,{projectName:g.name})}catch{}await ln(i.name);return}u({kind:"note",tone:"info",text:"Next: pick the Document360 project."}),q(["/project"])}},[e,u,ln]),cn=G(()=>{let l=Ae.current[0];if(!l)return;u({kind:"note",tone:"info",text:`\u25CF ${l.title} (${l.path})`});for(let a of l.notes)u({kind:"note",tone:"warn",text:`\u26A0 ${a}`});l.overwritesLocalChanges&&u({kind:"note",tone:"warn",text:"\u26A0 This OVERWRITES local edits made since the last sync."});let i=Ke(l.oldContent,l.newContent,Ie());u(i?{kind:"diff",added:i.added,removed:i.removed,lines:i.lines,hidden:i.hidden}:{kind:"note",tone:"info",text:"Local file already matches the remote content \u2014 applying only advances the sync base."}),u({kind:"note",tone:"info",text:`Write ${l.path}? (y/n \u2014 anything else cancels)`})},[u,Ie]),os=G(l=>{if(Ae.current.length===0)return!1;let i=l.trim().toLowerCase();if(i==="y"||i==="yes"){let a=Ae.current.shift();try{gp({cwd:e,profileName:s},a),u({kind:"note",tone:"ok",text:`\u2713 Pulled ${a.path} (sync base advanced).`}),Ae.current.length===0&&q(g=>g.length>0?g:["/sync"])}catch(g){u({kind:"note",tone:"error",text:`Pull failed: ${g.message}`})}}else if(i==="n"||i==="no"){let a=Ae.current.shift();u({kind:"note",tone:"info",text:`Skipped ${a.path}.`})}else{let a=Ae.current.length;return Ae.current=[],u({kind:"note",tone:"info",text:`Pull cancelled (${a} article(s) left untouched).`}),!0}return cn(),!0},[e,s,cn,u]),rs=G(l=>{let i=to.current;if(!i)return!1;if(to.current=null,se(null),Qe.current++,l.trim()!==i.repoName)return u({kind:"note",tone:"warn",text:"Reset cancelled \u2014 nothing deleted."}),!0;let{removed:a,failed:g}=Cr(e,i.targets);u({kind:"note",tone:g.length?"warn":"ok",text:`\u2713 Reset complete \u2014 removed ${a.length} item${a.length===1?"":"s"}. The repo is back to its original state.`});for(let d of g)u({kind:"note",tone:"error",text:` \u2717 ${d.path}: ${d.error}`});return i.hadDevhints&&(u({kind:"note",tone:"warn",text:Pn().join(`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "document360-writer",
3
- "version": "0.4.92",
3
+ "version": "0.4.93",
4
4
  "description": "Standalone documentation agent CLI. Reads your code, writes your docs. Specialized for Document360 publishing.",
5
5
  "type": "module",
6
6
  "bin": {