document360-writer 0.4.38 → 0.4.39
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/cli.js +42 -41
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var ti=Object.defineProperty;var Ho=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(o){throw n=[o],o}};var ni=(e,t)=>{for(var n in t)ti(e,n,{get:t[n],enumerable:!0})};import Ae from"picocolors";var z,oi,ri,si,Bo,pt,f,x,L,D,R,Q,ve,H=Ho(()=>{"use strict";z="#7f56d9",[oi,ri,si]=[127,86,217],Bo=e=>Ae.isColorSupported?`\x1B[38;2;${oi};${ri};${si}m${e}\x1B[39m`:e,pt=e=>Ae.bold(Bo(e)),f=e=>Ae.dim(e),x=e=>Ae.red(e),L=e=>Ae.yellow(e),D=e=>Ae.green(e),R=Bo,Q=e=>Ae.gray(e),ve=e=>Ae.bold(e)});var Vr={};ni(Vr,{doctorCommand:()=>$t,renderDoctorChecks:()=>Xr,runDoctorChecks:()=>Yr});import{existsSync as Gl}from"node:fs";import{d360GetAll as Yl,getAccessToken as Xl,isExpired as no,loadProfileMap as Vl,loadTokens as Jl,packageSkillsDir as Gr,projectConfigPath as Kl,readProjectConfig as Ql,resolveActiveProfile as Zl,resolveAuth as ea,resolveModelSetting as ta}from"document360-engine";async function Yr(e){let t=[],n=Number(process.versions.node.split(".")[0]);t.push(n>=20?{level:"ok",label:`Node ${process.versions.node}`}:{level:"fail",label:`Node ${process.versions.node} \u2014 20+ required`,fix:"Install Node 20 or later (nodejs.org)"});let o=ea("auto");t.push(o.kind==="none"?{level:"fail",label:"Claude auth: not configured",fix:"Set ANTHROPIC_API_KEY, or sign in to Claude Code once (subscription reuse)"}:{level:"ok",label:`Claude auth: ${o.kind==="api"?"API key":"subscription"}`});let r=ta(e);t.push({level:"ok",label:`Model: ${r.model??"Claude Code default"} (${r.source})`});let s=Ql(e);if(!s)return t.push({level:"fail",label:`No ${Kl(e)}`,fix:"Run: /init (or d360-writer init)"}),t;t.push({level:"ok",label:`Project config: ${s.projectId}`});let c=(s.docsDir??"user-docs").replace(/\/+$/,"");t.push(s.mode==="engineer"?{level:"warn",label:"Mode: engineer \u2014 agent may modify any source file (dogfooding)",fix:'Remove "mode" from .d360-writer/config.json for the writer-mode boundary'}:{level:"ok",label:`Mode: writer \u2014 edits limited to ${c}/ and .d360-writer/ (docs, capture specs, config); product source is read-only`});let u=s.authoritativeSourceFiles??[];t.push(u.length>0?{level:"ok",label:`Sources: docs grounded in ${u.length} path(s) (${u.slice(0,3).join(", ")}${u.length>3?", \u2026":""})`}:{level:"warn",label:"Sources: not set \u2014 docs are grounded in the whole repo",fix:"Run: /scope to choose which files/folders the docs are written from"});let g;try{g=Zl(e),t.push({level:"ok",label:`Profile: ${g.name} (${g.connection.name})${g.production?" \u26A0 PRODUCTION":""}`})}catch(j){return t.push({level:"fail",label:`Profile config: ${j.message.split(".")[0]}`,fix:"Run: /init to scaffold the profiles map"}),t}let m=Jl(g.name);m?no(m)&&!m.refreshToken?t.push({level:"fail",label:"Document360: session expired (no refresh token)",fix:"/login"}):no(m)?t.push({level:"warn",label:"Document360: token expired \u2014 will auto-refresh on next call"}):t.push({level:"ok",label:`Document360: logged in (until ${new Date(m.expiresAt).toLocaleString()})`}):t.push({level:"fail",label:"Document360: not logged in",fix:`Run: /login (or d360-writer login --profile ${g.name})`}),t.push(g.project.workspaceId?{level:"ok",label:`Workspace: ${g.project.workspaceName??g.project.workspaceId}`}:{level:"warn",label:"No workspace selected",fix:"Run: /workspace"});let w=Vl(e,g.name);if(w?w.projectId&&g.project.projectId&&w.projectId!==g.project.projectId?t.push({level:"fail",label:`Category map projectId (${w.projectId}) \u2260 profile projectId (${g.project.projectId})`,fix:"The map section belongs to a different project \u2014 fix .d360-writer/config.json or the map before publishing"}):t.push({level:"ok",label:`Category map: ${Object.keys(w.articles).length} articles, ${Object.keys(w.categories).length} categories`}):t.push({level:"ok",label:`Category map: none yet for "${g.name}" (created on first /publish)`}),t.push(Gl(Gr())?{level:"ok",label:"Skills bundle present"}:{level:"fail",label:`Skills folder missing at ${Gr()}`,fix:"Reinstall document360-writer (broken install)"}),m&&(!no(m)||m.refreshToken)){let j={profile:g.name,connection:g.connection};try{await Xl(j);let b=await Yl(j,"/v3/projects");t.push({level:"ok",label:`API reachable (${g.connection.apiUrl}) \u2014 ${b.length} project(s) visible`})}catch(b){t.push({level:"fail",label:`API call failed: ${b.message.slice(0,120)}`,fix:"/login if auth-related; otherwise check the apiUrl/network"})}}return t}function Xr(e){let t=[""];for(let r of e){let s=r.level==="ok"?D("\u2713"):r.level==="warn"?L("\u26A0"):x("\u2717");t.push(` ${s} ${r.label}${r.detail?f(` \u2014 ${r.detail}`):""}`),r.fix&&t.push(` ${f("fix:")} ${R(r.fix)}`)}let n=e.filter(r=>r.level==="fail").length,o=e.filter(r=>r.level==="warn").length;return t.push(""),t.push(n===0?D(`\u2713 ${o===0?"All checks passed":`Healthy (${o} warning${o===1?"":"s"})`}`):x(`\u2717 ${n} problem${n===1?"":"s"} found`)),t.push(""),t}async function $t(e,t){console.log(f("Running checks\u2026"));for(let n of Xr(await Yr(t.cwd)))console.log(n);return{kind:"continue"}}var Qt=Ho(()=>{"use strict";H()});import{Command as Hc}from"commander";import{createRequire as Bc}from"node:module";import{AUTH_MODES as qc}from"document360-engine";import{input as gi}from"@inquirer/prompts";import{loginPkce as hi,refreshTokens as ki,toStoredTokens as Yo,clearTokens as yi,decodeJwtClaims as Go,isExpired as wi,loadTokens as $i,saveTokens as Xo,resolveActiveProfile as Lt,setProfileProject as xi,readProjectConfig as bi}from"document360-engine";H();import{select as ii}from"@inquirer/prompts";import{resolveActiveProfile as li,setProfileProject as ai,resolveProjectId as ci,listWorkspaces as ui}from"document360-engine";async function Mt(e,t){let n=li(e,t),o={profile:n.name,connection:n.connection},r=n.project.projectId??ci(o);return{workspaces:await ui(o,r),projectId:r,profile:n.name,environment:n.connection.name,current:n.project.workspaceId}}var qo=e=>`${e.name??e.id}${e.workspace_type?` \xB7 ${e.workspace_type}`:""}`;function Pn(e,t){let n=t.toLowerCase();return e.find(o=>(o.name??"").toLowerCase()===n)??e.find(o=>(o.name??"").toLowerCase().startsWith(n))??e.find(o=>o.id.startsWith(t))}function Nt(e,t,n,o,r){ai(e,t,{projectId:n,workspaceId:o,workspaceName:r})}async function zo(e,t,n){let o;try{o=await Mt(e,n)}catch(s){return console.log(x(`Could not list workspaces: ${s.message}`)),1}let r=Pn(o.workspaces,t);return r?(Nt(e,o.profile,o.projectId,r.id,r.name),console.log(D(`\u2713 Workspace set to "${r.name??r.id}" for profile "${o.profile}".`)),0):(console.log(x(`No workspace matches "${t}". Available: ${o.workspaces.map(s=>s.name??s.id).join(", ")}`)),1)}async function Ze(e,t){let n;try{n=await Mt(e,t)}catch(m){console.log(x(`Could not list workspaces: ${m.message}`));return}let{workspaces:o,projectId:r,profile:s,current:c}=n;if(o.length===0){console.log(f("No workspaces found in this project."));return}if(!process.stdin.isTTY){console.log("");for(let m of o)console.log(` ${m.id===c?R("\u25CF"):" "} ${qo(m)} ${f(m.id)}`);console.log(f("Run: d360-writer workspace use <name>"));return}let u=await ii({message:"Select the Document360 workspace for this repo:",choices:o.map(m=>({name:`${qo(m)}${m.id===c?" (current)":""}`,value:m.id}))}),g=o.find(m=>m.id===u);Nt(e,s,r,u,g?.name),console.log(D(`\u2713 Workspace set to "${g?.name??u}" for profile "${s}".`))}H();import di from"picocolors";function pi(e=process.env){return e.FORCE_HYPERLINK==="0"||!di.isColorSupported?!1:e.FORCE_HYPERLINK?!0:!!(e.WT_SESSION||e.TERM_PROGRAM==="vscode"||e.TERM_PROGRAM==="iTerm.app"||e.TERM_PROGRAM==="WezTerm"||e.TERM_PROGRAM==="ghostty"||e.VTE_VERSION||e.KONSOLE_VERSION)}function fi(e,t=e,n){return pi(n)?`\x1B]8;;${e}\x07${t}\x1B]8;;\x07`:t}var mi=/https?:\/\/[^\s\x1b]+/g;function ft(e,t){return e.replace(mi,n=>fi(n,n,t))}function Vo(e){return{...Go(e.idToken)??{},...Go(e.accessToken)??{}}}function Ot(e){let t=Vo(e),n=t.email??t.preferred_username??t.sub??"unknown",o=t.doc360_project_id?` \xB7 project ${t.doc360_project_id}`:"";return`${n}${o}`}async function Ut(e){let t=Lt(process.cwd(),e.profile),n=t.connection;console.log(f(`Profile "${t.name}" \u2192 ${n.name} (${n.apiUrl})${t.production?" \u26A0 PRODUCTION":""}`));let o=await hi(n,{manual:e.manual,promptForRedirect:s=>gi({message:s})},s=>console.log(ft(s))),r=Yo(t.name,o);if(Xo(r),Sn(r,t.name,s=>console.log(f(s))),console.log(""),console.log(D(`\u2713 Logged in to "${t.name}" as ${Ot(r)}`)),console.log(f(` access token expires: ${r.expiresAt}`)),console.log(f(` refresh token: ${r.refreshToken?"yes":"NO \u2014 session ends at expiry"}`)),process.stdin.isTTY)try{bi(process.cwd())?.profiles?.[t.name]&&(console.log(""),await Ze(process.cwd(),t.name))}catch{}}function Sn(e,t,n){let r=Vo(e).doc360_project_id;if(!(typeof r!="string"||!r))try{if(Lt(process.cwd(),t).project.projectId)return;xi(process.cwd(),t,{projectId:r}),n(` Project ${r} written to profile "${t}".`)}catch{}}async function Jo(e){let t=Lt(process.cwd(),e.profile),n=t.connection,o=$i(t.name);if(!o){console.log(x(`Not logged in to Document360 (profile "${t.name}").`)),console.log(f(`Run: d360-writer login --profile ${t.name}`)),process.exitCode=1;return}if(console.log(`Profile ${R(t.name)}${t.production?" \u26A0 PRODUCTION":""}: ${Ot(o)}`),wi(o))if(o.refreshToken)try{let r=Yo(t.name,await ki(n,o.refreshToken));Xo(r),console.log(D(`\u2713 Session refreshed \u2014 expires ${r.expiresAt}`))}catch(r){console.log(L(`Session expired and refresh failed (${r.message.slice(0,120)})`)),console.log(f(`Run: d360-writer login --profile ${t.name}`)),process.exitCode=1}else console.log(L("Session expired (no refresh token).")),console.log(f(`Run: d360-writer login --profile ${t.name}`)),process.exitCode=1;else console.log(f(` expires: ${o.expiresAt}`))}async function Ko(e){let t=Lt(process.cwd(),e.profile);yi(t.name)?console.log(D(`\u2713 Logged out of Document360 (profile "${t.name}").`)):console.log(f(`No Document360 session for profile "${t.name}" \u2014 nothing to do.`))}H();import{readProjectConfig as Qo,writeProjectConfig as vi,resolveActiveProfile as Ci,loadTokens as Pi,isExpired as Si}from"document360-engine";function Wt(e){let t=Qo(e);if(!t?.profiles||Object.keys(t.profiles).length===0){console.log(x("No profiles in .d360-writer.json. Run: d360-writer init")),process.exitCode=1;return}console.log("");for(let[n,o]of Object.entries(t.profiles)){let r=n===t.defaultProfile?R("\u25CF "):" ",s=o.production?L(" \u26A0 PRODUCTION"):"",c=o.connection.environment??"(inline)",u=Pi(n),g=u?Si(u)&&!u.refreshToken?L("expired"):f("logged in"):f("not logged in");console.log(`${r}${R(n)} \u2192 ${c}${s} [${g}]`)}console.log(""),console.log(f("\u25CF = default. Switch with: d360-writer profile use <name>")),console.log("")}function Ft(e,t){let n=Qo(e);if(!n?.profiles?.[t]){let r=n?.profiles?Object.keys(n.profiles).join(", "):"(none \u2014 run init)";console.log(x(`Unknown profile "${t}". Available: ${r}`)),process.exitCode=1;return}n.defaultProfile=t,vi(n,e);let o=n.profiles[t].production?L(" \u26A0 PRODUCTION"):"";console.log(D(`\u2713 Default profile is now "${t}"${o}`))}function Ht(e,t){try{let n=Ci(e,t);console.log(""),console.log(`Profile ${R(n.name)}${n.production?L(" \u26A0 PRODUCTION"):""}`),console.log(f(` api: ${n.connection.apiUrl}`)),console.log(f(` identity: ${n.connection.authorizationUrl}`)),console.log(f(` clientId: ${n.connection.clientId}`)),console.log(f(` scopes: ${n.connection.scopes.join(" ")}`)),console.log(f(` project: ${n.project.projectId??"(set at login)"}`)),console.log(f(` workspace:${n.project.workspaceId?" "+n.project.workspaceId:" (none)"}`)),console.log("")}catch(n){console.log(x(n.message)),process.exitCode=1}}H();import{existsSync as Ti,readdirSync as Ri,statSync as Ai}from"node:fs";import{join as ji}from"node:path";import{apiLogDir as Ei}from"document360-engine";function Zo(){let e=Ei();if(console.log(""),console.log(`Document360 API logs: ${R(e)}`),!Ti(e)){console.log(f(" No logs yet \u2014 they appear after the first Document360 API call.")),console.log("");return}let t=Ri(e).filter(n=>n.endsWith(".jsonl")).sort().reverse();t.length===0&&console.log(f(" No logs yet \u2014 they appear after the first Document360 API call."));for(let n of t.slice(0,14)){let o=(Ai(ji(e,n)).size/1024).toFixed(1);console.log(` ${n} ${f(`${o} KB`)}`)}console.log(""),console.log(f("Failed calls include request/response bodies (tokens redacted, 4 KB cap).")),console.log(f("Set D360_LOG_BODIES=1 to also log bodies for successful calls.")),console.log("")}H();import{createSession as Di,resolveAuth as Ii,findByName as _i,slugify as Mi,touchSession as Ni,upsertSession as Li,resolveActiveProfile as Oi}from"document360-engine";async function er(e,t,n,o,r,s){let c=Ii(n);c.kind==="none"&&(console.error(""),console.error(x("ANTHROPIC_API_KEY is not set (required for --auth api).")),console.error(`Get a key at ${R("https://console.anthropic.com/settings/keys")}`),console.error(`Or use your Claude subscription instead: ${R("d360-writer --auth subscription")}`),process.exit(2)),c.kind==="subscription"&&console.error(f("Using your Claude subscription (no API key set)."));let u=null;try{u=Oi(e,r)}catch(b){console.error(x(`Document360 profile error: ${b.message}`)),process.exit(2)}u.production&&(console.error(L(`\u26A0 Profile "${u.name}" is PRODUCTION.`)),s||(console.error(x("Refusing to run against a production profile without --yes.")),process.exit(2)),console.error(f(" --yes given \u2014 proceeding against production.")));let g;if(o){let b=_i(e,o);b||(console.error(x(`No saved session matches "${o}" in this repo.`)),console.error(f("List sessions inside the REPL with /resume.")),process.exit(2)),g=b.uuid,console.error(f(`Resuming "${b.name}"`))}let m=Di({cwd:e,resume:g,profileName:r,allowProdWrites:s===!0}),w=g??null,j=1;for await(let b of m.send(t))switch(b.type){case"session":if(!w){w=b.sessionId;let v=new Date().toISOString();Li({uuid:w,name:Mi(t),renamed:!1,titled:!1,cwd:e,firstPrompt:t,createdAt:v,updatedAt:v})}break;case"text":process.stdout.write(b.delta);break;case"tool":console.error(Q(` \u2699 ${b.name}`));break;case"result":j=b.ok?0:1,console.error(f(`(${b.inputTokens}\u2192${b.outputTokens} tokens`+(b.costUsd>0?`, $${b.costUsd<.01?b.costUsd.toFixed(4):b.costUsd.toFixed(2)}`:"")+")")),b.ok||console.error(x("agent finished with an error result"));break;case"error":console.error(""),console.error(x(`agent error: ${b.message}`)),process.exit(1)}w&&Ni(w),process.stdout.write(`
|
|
3
|
-
`),process.exit(j)}import{createInterface as
|
|
2
|
+
var ni=Object.defineProperty;var Ho=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(o){throw n=[o],o}};var oi=(e,t)=>{for(var n in t)ni(e,n,{get:t[n],enumerable:!0})};import Ae from"picocolors";var z,ri,si,ii,Bo,pt,f,x,L,D,R,Q,ve,H=Ho(()=>{"use strict";z="#7f56d9",[ri,si,ii]=[127,86,217],Bo=e=>Ae.isColorSupported?`\x1B[38;2;${ri};${si};${ii}m${e}\x1B[39m`:e,pt=e=>Ae.bold(Bo(e)),f=e=>Ae.dim(e),x=e=>Ae.red(e),L=e=>Ae.yellow(e),D=e=>Ae.green(e),R=Bo,Q=e=>Ae.gray(e),ve=e=>Ae.bold(e)});var Vr={};oi(Vr,{doctorCommand:()=>$t,renderDoctorChecks:()=>Xr,runDoctorChecks:()=>Yr});import{existsSync as Yl}from"node:fs";import{d360GetAll as Xl,getAccessToken as Vl,isExpired as no,loadProfileMap as Jl,loadTokens as Kl,packageSkillsDir as Gr,projectConfigPath as Ql,readProjectConfig as Zl,resolveActiveProfile as ea,resolveAuth as ta,resolveModelSetting as na}from"document360-engine";async function Yr(e){let t=[],n=Number(process.versions.node.split(".")[0]);t.push(n>=20?{level:"ok",label:`Node ${process.versions.node}`}:{level:"fail",label:`Node ${process.versions.node} \u2014 20+ required`,fix:"Install Node 20 or later (nodejs.org)"});let o=ta("auto");t.push(o.kind==="none"?{level:"fail",label:"Claude auth: not configured",fix:"Set ANTHROPIC_API_KEY, or sign in to Claude Code once (subscription reuse)"}:{level:"ok",label:`Claude auth: ${o.kind==="api"?"API key":"subscription"}`});let r=na(e);t.push({level:"ok",label:`Model: ${r.model??"Claude Code default"} (${r.source})`});let s=Zl(e);if(!s)return t.push({level:"fail",label:`No ${Ql(e)}`,fix:"Run: /init (or d360-writer init)"}),t;t.push({level:"ok",label:`Project config: ${s.projectId}`});let c=(s.docsDir??"user-docs").replace(/\/+$/,"");t.push(s.mode==="engineer"?{level:"warn",label:"Mode: engineer \u2014 agent may modify any source file (dogfooding)",fix:'Remove "mode" from .d360-writer/config.json for the writer-mode boundary'}:{level:"ok",label:`Mode: writer \u2014 edits limited to ${c}/ and .d360-writer/ (docs, capture specs, config); product source is read-only`});let u=s.authoritativeSourceFiles??[];t.push(u.length>0?{level:"ok",label:`Sources: docs grounded in ${u.length} path(s) (${u.slice(0,3).join(", ")}${u.length>3?", \u2026":""})`}:{level:"warn",label:"Sources: not set \u2014 docs are grounded in the whole repo",fix:"Run: /scope to choose which files/folders the docs are written from"});let g;try{g=ea(e),t.push({level:"ok",label:`Profile: ${g.name} (${g.connection.name})${g.production?" \u26A0 PRODUCTION":""}`})}catch(j){return t.push({level:"fail",label:`Profile config: ${j.message.split(".")[0]}`,fix:"Run: /init to scaffold the profiles map"}),t}let m=Kl(g.name);m?no(m)&&!m.refreshToken?t.push({level:"fail",label:"Document360: session expired (no refresh token)",fix:"/login"}):no(m)?t.push({level:"warn",label:"Document360: token expired \u2014 will auto-refresh on next call"}):t.push({level:"ok",label:`Document360: logged in (until ${new Date(m.expiresAt).toLocaleString()})`}):t.push({level:"fail",label:"Document360: not logged in",fix:`Run: /login (or d360-writer login --profile ${g.name})`}),t.push(g.project.workspaceId?{level:"ok",label:`Workspace: ${g.project.workspaceName??g.project.workspaceId}`}:{level:"warn",label:"No workspace selected",fix:"Run: /workspace"});let w=Jl(e,g.name);if(w?w.projectId&&g.project.projectId&&w.projectId!==g.project.projectId?t.push({level:"fail",label:`Category map projectId (${w.projectId}) \u2260 profile projectId (${g.project.projectId})`,fix:"The map section belongs to a different project \u2014 fix .d360-writer/config.json or the map before publishing"}):t.push({level:"ok",label:`Category map: ${Object.keys(w.articles).length} articles, ${Object.keys(w.categories).length} categories`}):t.push({level:"ok",label:`Category map: none yet for "${g.name}" (created on first /publish)`}),t.push(Yl(Gr())?{level:"ok",label:"Skills bundle present"}:{level:"fail",label:`Skills folder missing at ${Gr()}`,fix:"Reinstall document360-writer (broken install)"}),m&&(!no(m)||m.refreshToken)){let j={profile:g.name,connection:g.connection};try{await Vl(j);let b=await Xl(j,"/v3/projects");t.push({level:"ok",label:`API reachable (${g.connection.apiUrl}) \u2014 ${b.length} project(s) visible`})}catch(b){t.push({level:"fail",label:`API call failed: ${b.message.slice(0,120)}`,fix:"/login if auth-related; otherwise check the apiUrl/network"})}}return t}function Xr(e){let t=[""];for(let r of e){let s=r.level==="ok"?D("\u2713"):r.level==="warn"?L("\u26A0"):x("\u2717");t.push(` ${s} ${r.label}${r.detail?f(` \u2014 ${r.detail}`):""}`),r.fix&&t.push(` ${f("fix:")} ${R(r.fix)}`)}let n=e.filter(r=>r.level==="fail").length,o=e.filter(r=>r.level==="warn").length;return t.push(""),t.push(n===0?D(`\u2713 ${o===0?"All checks passed":`Healthy (${o} warning${o===1?"":"s"})`}`):x(`\u2717 ${n} problem${n===1?"":"s"} found`)),t.push(""),t}async function $t(e,t){console.log(f("Running checks\u2026"));for(let n of Xr(await Yr(t.cwd)))console.log(n);return{kind:"continue"}}var Zt=Ho(()=>{"use strict";H()});import{Command as Bc}from"commander";import{createRequire as qc}from"node:module";import{AUTH_MODES as zc}from"document360-engine";import{input as hi}from"@inquirer/prompts";import{loginPkce as ki,refreshTokens as yi,toStoredTokens as Yo,clearTokens as wi,decodeJwtClaims as Go,isExpired as $i,loadTokens as xi,saveTokens as Xo,resolveActiveProfile as Ot,setProfileProject as bi,readProjectConfig as vi}from"document360-engine";H();import{select as li}from"@inquirer/prompts";import{resolveActiveProfile as ai,setProfileProject as ci,resolveProjectId as ui,listWorkspaces as di}from"document360-engine";async function Nt(e,t){let n=ai(e,t),o={profile:n.name,connection:n.connection},r=n.project.projectId??ui(o);return{workspaces:await di(o,r),projectId:r,profile:n.name,environment:n.connection.name,current:n.project.workspaceId}}var qo=e=>`${e.name??e.id}${e.workspace_type?` \xB7 ${e.workspace_type}`:""}`;function Pn(e,t){let n=t.toLowerCase();return e.find(o=>(o.name??"").toLowerCase()===n)??e.find(o=>(o.name??"").toLowerCase().startsWith(n))??e.find(o=>o.id.startsWith(t))}function Lt(e,t,n,o,r){ci(e,t,{projectId:n,workspaceId:o,workspaceName:r})}async function zo(e,t,n){let o;try{o=await Nt(e,n)}catch(s){return console.log(x(`Could not list workspaces: ${s.message}`)),1}let r=Pn(o.workspaces,t);return r?(Lt(e,o.profile,o.projectId,r.id,r.name),console.log(D(`\u2713 Workspace set to "${r.name??r.id}" for profile "${o.profile}".`)),0):(console.log(x(`No workspace matches "${t}". Available: ${o.workspaces.map(s=>s.name??s.id).join(", ")}`)),1)}async function Ze(e,t){let n;try{n=await Nt(e,t)}catch(m){console.log(x(`Could not list workspaces: ${m.message}`));return}let{workspaces:o,projectId:r,profile:s,current:c}=n;if(o.length===0){console.log(f("No workspaces found in this project."));return}if(!process.stdin.isTTY){console.log("");for(let m of o)console.log(` ${m.id===c?R("\u25CF"):" "} ${qo(m)} ${f(m.id)}`);console.log(f("Run: d360-writer workspace use <name>"));return}let u=await li({message:"Select the Document360 workspace for this repo:",choices:o.map(m=>({name:`${qo(m)}${m.id===c?" (current)":""}`,value:m.id}))}),g=o.find(m=>m.id===u);Lt(e,s,r,u,g?.name),console.log(D(`\u2713 Workspace set to "${g?.name??u}" for profile "${s}".`))}H();import pi from"picocolors";function fi(e=process.env){return e.FORCE_HYPERLINK==="0"||!pi.isColorSupported?!1:e.FORCE_HYPERLINK?!0:!!(e.WT_SESSION||e.TERM_PROGRAM==="vscode"||e.TERM_PROGRAM==="iTerm.app"||e.TERM_PROGRAM==="WezTerm"||e.TERM_PROGRAM==="ghostty"||e.VTE_VERSION||e.KONSOLE_VERSION)}function mi(e,t=e,n){return fi(n)?`\x1B]8;;${e}\x07${t}\x1B]8;;\x07`:t}var gi=/https?:\/\/[^\s\x1b]+/g;function ft(e,t){return e.replace(gi,n=>mi(n,n,t))}function Vo(e){return{...Go(e.idToken)??{},...Go(e.accessToken)??{}}}function Ut(e){let t=Vo(e),n=t.email??t.preferred_username??t.sub??"unknown",o=t.doc360_project_id?` \xB7 project ${t.doc360_project_id}`:"";return`${n}${o}`}async function Wt(e){let t=Ot(process.cwd(),e.profile),n=t.connection;console.log(f(`Profile "${t.name}" \u2192 ${n.name} (${n.apiUrl})${t.production?" \u26A0 PRODUCTION":""}`));let o=await ki(n,{manual:e.manual,promptForRedirect:s=>hi({message:s})},s=>console.log(ft(s))),r=Yo(t.name,o);if(Xo(r),Sn(r,t.name,s=>console.log(f(s))),console.log(""),console.log(D(`\u2713 Logged in to "${t.name}" as ${Ut(r)}`)),console.log(f(` access token expires: ${r.expiresAt}`)),console.log(f(` refresh token: ${r.refreshToken?"yes":"NO \u2014 session ends at expiry"}`)),process.stdin.isTTY)try{vi(process.cwd())?.profiles?.[t.name]&&(console.log(""),await Ze(process.cwd(),t.name))}catch{}}function Sn(e,t,n){let r=Vo(e).doc360_project_id;if(!(typeof r!="string"||!r))try{if(Ot(process.cwd(),t).project.projectId)return;bi(process.cwd(),t,{projectId:r}),n(` Project ${r} written to profile "${t}".`)}catch{}}async function Jo(e){let t=Ot(process.cwd(),e.profile),n=t.connection,o=xi(t.name);if(!o){console.log(x(`Not logged in to Document360 (profile "${t.name}").`)),console.log(f(`Run: d360-writer login --profile ${t.name}`)),process.exitCode=1;return}if(console.log(`Profile ${R(t.name)}${t.production?" \u26A0 PRODUCTION":""}: ${Ut(o)}`),$i(o))if(o.refreshToken)try{let r=Yo(t.name,await yi(n,o.refreshToken));Xo(r),console.log(D(`\u2713 Session refreshed \u2014 expires ${r.expiresAt}`))}catch(r){console.log(L(`Session expired and refresh failed (${r.message.slice(0,120)})`)),console.log(f(`Run: d360-writer login --profile ${t.name}`)),process.exitCode=1}else console.log(L("Session expired (no refresh token).")),console.log(f(`Run: d360-writer login --profile ${t.name}`)),process.exitCode=1;else console.log(f(` expires: ${o.expiresAt}`))}async function Ko(e){let t=Ot(process.cwd(),e.profile);wi(t.name)?console.log(D(`\u2713 Logged out of Document360 (profile "${t.name}").`)):console.log(f(`No Document360 session for profile "${t.name}" \u2014 nothing to do.`))}H();import{readProjectConfig as Qo,writeProjectConfig as Ci,resolveActiveProfile as Pi,loadTokens as Si,isExpired as Ti}from"document360-engine";function Ft(e){let t=Qo(e);if(!t?.profiles||Object.keys(t.profiles).length===0){console.log(x("No profiles in .d360-writer.json. Run: d360-writer init")),process.exitCode=1;return}console.log("");for(let[n,o]of Object.entries(t.profiles)){let r=n===t.defaultProfile?R("\u25CF "):" ",s=o.production?L(" \u26A0 PRODUCTION"):"",c=o.connection.environment??"(inline)",u=Si(n),g=u?Ti(u)&&!u.refreshToken?L("expired"):f("logged in"):f("not logged in");console.log(`${r}${R(n)} \u2192 ${c}${s} [${g}]`)}console.log(""),console.log(f("\u25CF = default. Switch with: d360-writer profile use <name>")),console.log("")}function Ht(e,t){let n=Qo(e);if(!n?.profiles?.[t]){let r=n?.profiles?Object.keys(n.profiles).join(", "):"(none \u2014 run init)";console.log(x(`Unknown profile "${t}". Available: ${r}`)),process.exitCode=1;return}n.defaultProfile=t,Ci(n,e);let o=n.profiles[t].production?L(" \u26A0 PRODUCTION"):"";console.log(D(`\u2713 Default profile is now "${t}"${o}`))}function Bt(e,t){try{let n=Pi(e,t);console.log(""),console.log(`Profile ${R(n.name)}${n.production?L(" \u26A0 PRODUCTION"):""}`),console.log(f(` api: ${n.connection.apiUrl}`)),console.log(f(` identity: ${n.connection.authorizationUrl}`)),console.log(f(` clientId: ${n.connection.clientId}`)),console.log(f(` scopes: ${n.connection.scopes.join(" ")}`)),console.log(f(` project: ${n.project.projectId??"(set at login)"}`)),console.log(f(` workspace:${n.project.workspaceId?" "+n.project.workspaceId:" (none)"}`)),console.log("")}catch(n){console.log(x(n.message)),process.exitCode=1}}H();import{existsSync as Ri,readdirSync as Ai,statSync as ji}from"node:fs";import{join as Ei}from"node:path";import{apiLogDir as Di}from"document360-engine";function Zo(){let e=Di();if(console.log(""),console.log(`Document360 API logs: ${R(e)}`),!Ri(e)){console.log(f(" No logs yet \u2014 they appear after the first Document360 API call.")),console.log("");return}let t=Ai(e).filter(n=>n.endsWith(".jsonl")).sort().reverse();t.length===0&&console.log(f(" No logs yet \u2014 they appear after the first Document360 API call."));for(let n of t.slice(0,14)){let o=(ji(Ei(e,n)).size/1024).toFixed(1);console.log(` ${n} ${f(`${o} KB`)}`)}console.log(""),console.log(f("Failed calls include request/response bodies (tokens redacted, 4 KB cap).")),console.log(f("Set D360_LOG_BODIES=1 to also log bodies for successful calls.")),console.log("")}H();import{createSession as Ii,resolveAuth as _i,findByName as Mi,slugify as Ni,touchSession as Li,upsertSession as Oi,resolveActiveProfile as Ui}from"document360-engine";async function er(e,t,n,o,r,s){let c=_i(n);c.kind==="none"&&(console.error(""),console.error(x("ANTHROPIC_API_KEY is not set (required for --auth api).")),console.error(`Get a key at ${R("https://console.anthropic.com/settings/keys")}`),console.error(`Or use your Claude subscription instead: ${R("d360-writer --auth subscription")}`),process.exit(2)),c.kind==="subscription"&&console.error(f("Using your Claude subscription (no API key set)."));let u=null;try{u=Ui(e,r)}catch(b){console.error(x(`Document360 profile error: ${b.message}`)),process.exit(2)}u.production&&(console.error(L(`\u26A0 Profile "${u.name}" is PRODUCTION.`)),s||(console.error(x("Refusing to run against a production profile without --yes.")),process.exit(2)),console.error(f(" --yes given \u2014 proceeding against production.")));let g;if(o){let b=Mi(e,o);b||(console.error(x(`No saved session matches "${o}" in this repo.`)),console.error(f("List sessions inside the REPL with /resume.")),process.exit(2)),g=b.uuid,console.error(f(`Resuming "${b.name}"`))}let m=Ii({cwd:e,resume:g,profileName:r,allowProdWrites:s===!0}),w=g??null,j=1;for await(let b of m.send(t))switch(b.type){case"session":if(!w){w=b.sessionId;let v=new Date().toISOString();Oi({uuid:w,name:Ni(t),renamed:!1,titled:!1,cwd:e,firstPrompt:t,createdAt:v,updatedAt:v})}break;case"text":process.stdout.write(b.delta);break;case"tool":console.error(Q(` \u2699 ${b.name}`));break;case"result":j=b.ok?0:1,console.error(f(`(${b.inputTokens}\u2192${b.outputTokens} tokens`+(b.costUsd>0?`, $${b.costUsd<.01?b.costUsd.toFixed(4):b.costUsd.toFixed(2)}`:"")+")")),b.ok||console.error(x("agent finished with an error result"));break;case"error":console.error(""),console.error(x(`agent error: ${b.message}`)),process.exit(1)}w&&Li(w),process.stdout.write(`
|
|
3
|
+
`),process.exit(j)}import{createInterface as Aa}from"node:readline/promises";import{createSession as fo,resolveAuth as ja,getSession as Ea,setTitle as Da,slugify as Ia,touchSession as fs,upsertSession as _a,generateTitle as Ma,resolveActiveProfile as ms,resolveModelSetting as Na,readProjectConfig as La,decodeJwtClaims as ds,isExpired as Oa,loadTokens as Ua}from"document360-engine";var mt=[{name:"init",usage:"/init",desc:"Pick an environment & scaffold .d360-writer.json",group:"start"},{name:"login",usage:"/login",desc:"Sign in to Document360 (browser)",group:"start"},{name:"scope",usage:"/scope",desc:"Choose which repo folders back the docs (monorepos)",group:"start"},{name:"mcp",usage:"/mcp [list|add|remove]",desc:"Connect MCP servers (Notion, Linear, \u2026)",group:"start"},{name:"write",usage:"/write [--all|--scope <cat>|<path>] [--run]",desc:"Author the planned articles in parallel (bare = preview + cost; --run starts)",group:"docs"},{name:"screenshot",usage:"/screenshot [--list|id|--all|path]",desc:"--list: status; else author capture specs (bulk also refreshes the capture checklist; --no-setup skips)",group:"docs"},{name:"capture-setup",usage:"/capture-setup",desc:"Re-run the data-staging checklist + dev test-id requests (auto-runs after /screenshot --all)",group:"docs"},{name:"preview",usage:"/preview [path|id]",desc:"Render an article (no arg: pick from tracked)",group:"docs"},{name:"publish",usage:"/publish [path|--all]",desc:"Publish to Document360 (no arg: pick; --all: every candidate)",group:"publish"},{name:"audit",usage:"/audit",desc:"Gap analysis: code vs docs vs Document360 (what changed)",group:"publish"},{name:"sync",usage:"/sync [pull <path>|--all]",desc:"Drift report local vs Document360; pull portal edits",group:"publish"},{name:"convert",usage:"/convert [--scope <folder>] [--run]",desc:"Convert tracked articles to DFM (one-off legacy migration)",group:"publish"},{name:"profile",usage:"/profile [name|add <name> [env]]",desc:"Switch/create a Document360 connection (picker; s = session)",group:"setup"},{name:"workspace",usage:"/workspace [name]",desc:"Switch the Document360 workspace (picker)",group:"setup"},{name:"model",usage:"/model [name|default]",desc:"Set the Claude model for d360-writer",group:"setup"},{name:"allow-prod",usage:"/allow-prod",desc:"Authorize writes to a production profile",group:"setup"},{name:"doctor",usage:"/doctor",desc:"Health-check: auth, profile, workspace, map, API",group:"setup"},{name:"reset",usage:"/reset",desc:"[DANGER] Delete all d360-writer files (docs, config, screenshots); types repo name to confirm",group:"setup"},{name:"resume",usage:"/resume [name]",desc:"Resume a session (no arg lists them)",group:"session"},{name:"rename",usage:"/rename [name]",desc:"Name the session (no arg: suggest one)",group:"session"},{name:"clear",usage:"/clear",desc:"Reset the conversation (resumable)",group:"session"},{name:"help",usage:"/help",desc:"Show this help",group:"session"},{name:"exit",usage:"/exit",desc:"Quit",group:"session"}],Wi=[{key:"start",label:"Start here"},{key:"docs",label:"Write & screenshots"},{key:"publish",label:"Publish & keep in sync"},{key:"setup",label:"Setup & health"},{key:"session",label:"Session"}];function qt(){let e=Math.max(...mt.map(n=>n.usage.length))+2,t=["document360-writer \u2014 commands","",'New here? /init \u2192 "write the docs for this repo" \u2192 /publish',""," Screenshots are optional \u2014 add them anytime:"," /screenshot --all \u2192 d360-capture capture \u2192 re-/publish"];for(let{key:n,label:o}of Wi){t.push("",o);for(let r of mt.filter(s=>s.group===n))t.push(` ${r.usage.padEnd(e)}${r.desc}`)}return t.push("","Tip: anything not starting with / is sent to the agent."),t}function tr(e){if(!e.startsWith("/"))return[];let t=e.slice(1).toLowerCase().split(/\s/)[0]??"";return mt.filter(n=>n.name.startsWith(t))}function nr(e){return/<[^>]+>/.test(e.replace(/\[[^\]]*\]/g,""))}async function Tn(){console.log("");for(let e of qt())console.log(e);return console.log(""),console.log("Reporting a problem? Run `d360-writer logs` for the API log files."),console.log(""),{kind:"continue"}}H();import{getSession as Fi}from"document360-engine";async function or(e,t){let n=t.currentUuid(),o=n?Fi(n):void 0;return console.log(o?f(`
|
|
4
4
|
(conversation reset \u2014 "${o.name}" is still available via /resume)
|
|
5
5
|
`):f(`
|
|
6
6
|
(conversation reset \u2014 agent will start fresh on the next prompt)
|
|
7
|
-
`)),{kind:"clear"}}async function Rn(){return{kind:"exit"}}H();import{input as gt,confirm as
|
|
8
|
-
`),"utf8")}async function cr(){let e=process.cwd(),t=ir(e);if(et(t)&&!await
|
|
7
|
+
`)),{kind:"clear"}}async function Rn(){return{kind:"exit"}}H();import{input as gt,confirm as Hi}from"@inquirer/prompts";import{basename as rr,join as zt}from"node:path";import{existsSync as et,readFileSync as Bi,readdirSync as qi,writeFileSync as zi}from"node:fs";import{writeProjectConfig as sr,readProjectConfig as Gi,projectConfigPath as ir,writerDir as Yi}from"document360-engine";function lr(e,t="berlin"){let n=ir(e);if(et(n))return{created:!1,path:n,profileName:""};let o={projectId:ur(e)??rr(e),captureDir:"user-docs/_capture",outputDir:"user-docs/_screenshots",profiles:{[t]:{connection:{environment:t},production:!1}},defaultProfile:t,authoritativeSourceFiles:dr(e)};return sr(o,e),ar(e),{created:!0,path:n,profileName:t}}function ar(e){let t=zt(Yi(e),".gitignore");et(t)||zi(t,["# Local/transient \u2014 the config files here ARE meant to be committed.",".sessions/","cache/",""].join(`
|
|
8
|
+
`),"utf8")}async function cr(){let e=process.cwd(),t=ir(e);if(et(t)&&!await Hi({message:`${t} already exists. Overwrite?`,default:!1}))return console.log(f("init cancelled.")),{kind:"continue"};let n=ur(e)??rr(e),o=await gt({message:"Project ID (used to scope sessions, screenshots, etc.):",default:n}),r=await gt({message:"Capture directory (where document360-capture .spec.ts files live):",default:"user-docs/_capture"}),s=await gt({message:"Screenshot output directory:",default:"user-docs/_screenshots"}),c=await gt({message:"Default connection profile name:",default:"berlin"}),u=await gt({message:"Document360 environment for this profile (baked preset):",default:"berlin"}),g={projectId:o,captureDir:r,outputDir:s,profiles:{[c]:{connection:{environment:u},production:!1}},defaultProfile:c,authoritativeSourceFiles:dr(e)},m=Gi(e);return m?.terminologyGlossary&&(g.terminologyGlossary=m.terminologyGlossary),sr(g,e),ar(e),console.log(""),console.log(D(`\u2713 Wrote ${t}`)),console.log(""),console.log("Next:"),console.log(` ${R(`d360-writer login --profile ${c}`)} ${f("(sign in; pick the project)")}`),console.log(' Then ask the agent: "analyze this repo and propose a docs structure"'),console.log(""),{kind:"continue"}}function ur(e){let t=zt(e,"package.json");if(!et(t))return null;try{return JSON.parse(Bi(t,"utf8")).name??null}catch{return null}}function dr(e){let t=[];for(let n of["README.md","ARCHITECTURE.md","CLAUDE.md"])et(zt(e,n))&&t.push(n);for(let n of["src","api","docs"]){let o=zt(e,n);et(o)&&!Xi(o)&&t.push(n)}return t}function Xi(e){try{return qi(e,{withFileTypes:!0}).filter(n=>n.isDirectory()&&!n.name.startsWith(".")).length>6}catch{return!1}}H();import{readMcpConfig as An,writeMcpConfig as pr}from"document360-engine";async function Gt(e){let t=(e[0]??"").toLowerCase();return t==="list"||!t?(Vi(),{kind:"continue"}):t==="add"?(Ji(e.slice(1)),{kind:"continue"}):t==="remove"||t==="rm"?(Ki(e.slice(1)),{kind:"continue"}):(console.log(x(`Unknown /mcp subcommand: ${t}`)),console.log(f("Try: /mcp add <name> <stdio|http|sse> <command-or-url>, /mcp list, /mcp remove <name>")),{kind:"continue"})}function Vi(){let e=An(),t=Object.keys(e.servers);if(t.length===0){console.log(f(`
|
|
9
9
|
No MCP servers registered. Add one with /mcp add <name> <type> <ref>
|
|
10
|
-
`));return}console.log(""),console.log("Registered MCP servers (~/.document360-writer/mcp.json):");for(let n of t){let o=e.servers[n];if(o.type==="stdio")console.log(` ${R(n)} ${f("(stdio)")} ${o.command} ${(o.args??[]).join(" ")}`);else{let r=Object.keys(o.headers??{}),s=r.length>0?f(` [headers: ${r.join(", ")}]`):"";console.log(` ${R(n)} ${f(`(${o.type})`)} ${o.url}${s}`)}}console.log("")}function
|
|
11
|
-
`)}var mr={"local-ahead":"modified locally","untracked-local":"new (never published)",conflict:"\u26A0 conflict \u2014 publishing overwrites the portal edit"};function
|
|
12
|
-
`)}async function gr(e,t){let n=e[0];if(n==="--all"){console.log(f("Checking what needs publishing\u2026"));try{let o=
|
|
13
|
-
`),display:"/audit"}}H();import{checkbox as
|
|
10
|
+
`));return}console.log(""),console.log("Registered MCP servers (~/.document360-writer/mcp.json):");for(let n of t){let o=e.servers[n];if(o.type==="stdio")console.log(` ${R(n)} ${f("(stdio)")} ${o.command} ${(o.args??[]).join(" ")}`);else{let r=Object.keys(o.headers??{}),s=r.length>0?f(` [headers: ${r.join(", ")}]`):"";console.log(` ${R(n)} ${f(`(${o.type})`)} ${o.url}${s}`)}}console.log("")}function Ji(e){let[t,n,...o]=e;if(!t||!n||o.length===0){console.log(x("Usage: /mcp add <name> <stdio|http|sse> <command-or-url> [args...] [-H key:value ...]"));return}if(n!=="stdio"&&n!=="http"&&n!=="sse"){console.log(x(`Unknown transport: ${n}. Use stdio, http, or sse.`));return}let r=An(),s;if(n==="stdio")s={type:"stdio",command:o[0],args:o.slice(1)};else{let c={};for(let u=1;u<o.length;u++)if(o[u]==="-H"||o[u]==="--header"){let g=o[++u],m=g?.match(/^([^:=]+)[:=](.+)$/);if(!m){console.log(x(`-H expects key:value (no spaces). Got: ${g??"(nothing)"}`));return}c[m[1].trim()]=m[2].trim()}else{console.log(x(`Unexpected argument: ${o[u]}. After the URL, only -H key:value is allowed.`));return}s={type:n,url:o[0],headers:Object.keys(c).length>0?c:void 0}}r.servers[t]=s,pr(r),console.log(""),console.log(D(`\u2713 Registered "${t}" (${n})`)),console.log(L(" This server loads on your next prompt. The current agent session reads MCP config at startup.")),console.log(f(" Run /clear if you want the next turn to reload immediately.")),console.log("")}function Ki(e){let t=e[0];if(!t){console.log(x("Usage: /mcp remove <name>"));return}let n=An();if(!n.servers[t]){console.log(x(`No server named "${t}".`));return}delete n.servers[t],pr(n),console.log(D(`\u2713 Removed "${t}".`)),console.log(f(" Run /clear to drop it from the current session immediately."))}H();import{select as Qi}from"@inquirer/prompts";import{computeSyncStatus as fr}from"document360-engine";function Xt(e){return[`Run the publish-to-d360 skill for the article at: ${e}`,"","Steps you must follow:","1. Read the article markdown \u2014 use the repo-relative path exactly as given above (it resolves against the working directory; do not reconstruct an absolute path).","2. Compute the D360 publish form (strip the YAML frontmatter and the H1 title, strip every <!-- SCREENSHOT ... --> block while keeping the visible [Screenshot: ...] line, normalize cross-article links).","3. Look up the article ID in <repo>/d360-category-map.json. If present, call the document360 MCP update-article tool. If absent, call create-article with local_path set to the repo-relative .md path (the tool records the new ID + sync base in the category map itself \u2014 do not edit the articles map by hand).","4. Report what changed and remind me to publish the draft manually in the Document360 portal."].join(`
|
|
11
|
+
`)}var mr={"local-ahead":"modified locally","untracked-local":"new (never published)",conflict:"\u26A0 conflict \u2014 publishing overwrites the portal edit"};function Yt(e){return e.filter(t=>t.path!==null&&t.status in mr).map(t=>({path:t.path,label:mr[t.status]}))}function ht(e){return[`Run the publish-to-d360 skill for ALL of these ${e.length} articles, one by one:`,"",...e.map(t=>`- ${t}`),"","Use the repo-relative paths exactly as listed (they resolve against the working directory; do not reconstruct absolute paths). Apply the normal per-article publish flow (frontmatter/H1/screenshot-comment strips, link normalization; update when mapped, create with local_path when not). If one article fails, note it and continue. Finish with a summary table (article | created/updated | failures) and remind me drafts need review in the portal."].join(`
|
|
12
|
+
`)}async function gr(e,t){let n=e[0];if(n==="--all"){console.log(f("Checking what needs publishing\u2026"));try{let o=Yt((await fr({cwd:t?.cwd??process.cwd()})).entries);return o.length===0?(console.log(D("\u2713 Nothing is ahead of Document360 \u2014 no publish candidates.")),{kind:"continue"}):{kind:"forward-to-agent",prompt:ht(o.map(r=>r.path)),display:"/publish --all"}}catch(o){return console.log(x(`Could not compute sync status: ${o.message}`)),{kind:"continue"}}}if(!n){console.log(f("Checking what needs publishing\u2026"));let o;try{o=Yt((await fr({cwd:t?.cwd??process.cwd()})).entries)}catch(r){return console.log(x(`Could not compute sync status: ${r.message}`)),console.log(f("Publish a specific article: /publish <article-path>")),{kind:"continue"}}if(o.length===0)return console.log(D("\u2713 Nothing is ahead of Document360 \u2014 no publish candidates.")),console.log(f(" (Articles without a sync base are unverified \u2014 publish those by path if needed.)")),{kind:"continue"};if(!process.stdin.isTTY||!t){for(let r of o)console.log(` ${r.path} ${f(`(${r.label})`)}`);return console.log(f("Run: /publish <article-path>")),{kind:"continue"}}try{n=await t.withPausedInput(()=>Qi({message:"Publish which article?",choices:[...o.length>1?[{name:`All ${o.length} candidates`,value:"--all",description:"one agent run over every candidate"}]:[],...o.map(r=>({name:r.path,value:r.path,description:r.label}))]}))}catch{return console.log(f("Cancelled.")),{kind:"continue"}}if(n==="--all")return{kind:"forward-to-agent",prompt:ht(o.map(r=>r.path)),display:"/publish --all"}}return{kind:"forward-to-agent",prompt:Xt(n),display:`/publish ${n}`}}async function Vt(){return{kind:"forward-to-agent",prompt:["Run the gap-analysis skill against this repo.","","Follow its stages in order:","1. d360_sync_status first \u2014 stop and report if any article is in conflict or remote-ahead (the local copy cannot be trusted until resolved).","2. git diff since the lastAnalyzedCommit marker in d360-category-map.json (or last 30 days if no marker), filtered to the authoritativeSourceFiles paths.","3. Map changed files to articles via their `sources:` frontmatter; read only implicated articles and changed source files. If articles are missing `sources:`, this is the one-time bootstrap pass \u2014 backfill them.","4. Output the proposal table: | Article (path or proposed title) | Action (create | update | retire | adopt) | Reason | Evidence | Scope |, then advance lastAnalyzedCommit.","","Do not start writing or updating any article yet \u2014 the proposal table is the deliverable."].join(`
|
|
13
|
+
`),display:"/audit"}}H();import{checkbox as Zi}from"@inquirer/prompts";import{inventoryRepo as el,readProjectConfig as hr,writeProjectConfig as tl}from"document360-engine";function jn(e,t){let n=hr(e);n&&(n.authoritativeSourceFiles=t,tl(n,e))}function Jt(e){let t=[`${e.fileCount}${e.fileCount>=5e3?"+":""} files`];return e.stacks.length&&t.push(e.stacks.join("+")),t.push(e.reason),t.join(" \xB7 ")}async function kr(e,t){let n=t?.cwd??process.cwd();if(!hr(n))return console.log(x("No .d360-writer.json here. Run /init first.")),{kind:"continue"};let o=el(n);if(o.length===0)return console.log(f('No candidate source folders found. Set "authoritativeSourceFiles" in .d360-writer.json manually.')),{kind:"continue"};if(!process.stdin.isTTY||!t){console.log(""),console.log(R("Recommended documentation scope (run /scope in the REPL to choose):"));for(let s of o)console.log(` ${s.recommended?"\u25C9":"\u25CB"} ${s.path} ${f(Jt(s))}`);return console.log(""),{kind:"continue"}}let r;try{r=await t.withPausedInput(()=>Zi({message:"Which folders back the user docs? (space toggles, enter confirms)",choices:o.map(s=>({name:`${s.path} (${Jt(s)})`,value:s.path,checked:s.recommended})),pageSize:20}))}catch{return console.log(f("Cancelled.")),{kind:"continue"}}if(r.length===0)return console.log(f("Nothing selected \u2014 scope unchanged.")),{kind:"continue"};jn(n,r),console.log(D(`\u2713 Scoped to ${r.length} folder(s) \u2014 written to .d360-writer.json`));for(let s of r)console.log(` ${s}`);return console.log(""),{kind:"continue"}}H();import{confirm as il}from"@inquirer/prompts";import{applyPull as br,computeSyncStatus as vr,planPull as ll,D360AuthError as al}from"document360-engine";H();var yr=[{status:"conflict",header:"Conflicts \u2014 both sides changed; pick a direction (/sync pull <path> or /publish <path>):",paint:x,mark:"!"},{status:"local-ahead",header:"Local ahead \u2014 push with /publish <path>:",paint:L,mark:"M"},{status:"remote-ahead",header:"Remote ahead \u2014 pull with /sync pull <path>:",paint:R,mark:"M"},{status:"deleted-local",header:"Deleted locally \u2014 still on Document360 (pull to restore, or remove from the map):",paint:x,mark:"D"},{status:"deleted-remote",header:"Deleted on Document360 \u2014 still local (publish to recreate, or delete the file):",paint:x,mark:"D"},{status:"orphaned",header:"Orphaned map entries \u2014 gone on both sides (remove from d360-category-map.json):",paint:Q,mark:"X"},{status:"untracked-local",header:"Untracked local articles \u2014 publish to start tracking:",paint:f,mark:"?"},{status:"untracked-remote",header:"Untracked Document360 articles \u2014 no local file maps to them:",paint:f,mark:"?"},{status:"unknown-base",header:"No sync base recorded yet \u2014 the next /publish or /sync pull of each records one:",paint:Q,mark:"\xB7"}];function nl(e){return e.path?e.path:`${e.title??"(untitled)"} ${Q(`[${e.articleId}]`)}`}function Kt(e){let t=[];for(let c of yr){let u=e.entries.filter(g=>g.status===c.status);if(u.length!==0){t.push(""),t.push(ve(c.header));for(let g of u)t.push(` ${c.paint(c.mark)} ${c.paint(nl(g))}${g.detail?Q(` (${g.detail})`):""}`)}}let n=e.counts["in-sync"]??0,o=e.entries.length;t.push("");let r={"in-sync":"in sync","local-ahead":"local ahead","remote-ahead":"remote ahead",conflict:"conflicts","untracked-local":"untracked local","untracked-remote":"untracked remote","deleted-local":"deleted locally","deleted-remote":"deleted on D360",orphaned:"orphaned","unknown-base":"no base yet"},s=o===n?D("\u2713 everything in sync"):[n>0?D(`\u2713 ${n} in sync`):null,...yr.map(c=>{let u=e.counts[c.status]??0;return u>0?`${u} ${r[c.status]}`:null})].filter(Boolean).join(Q(" \xB7 "));return t.push(s+Q(` \xB7 ${o} tracked+seen \xB7 profile "${e.profile}" \xB7 docs root ${e.docsRoot}/`)),t}import{structuredPatch as ol}from"diff";import wr from"picocolors";var $r=80,rl="\x1B[48;2;74;28;28m",sl="\x1B[48;2;24;66;24m",xr="\x1B[49m",En=e=>String(e).padStart(5);function We(e,t,n){let o=b=>{let v=b.replace(/\r\n/g,`
|
|
14
14
|
`);return v.endsWith(`
|
|
15
15
|
`)||v===""?v:v+`
|
|
16
|
-
`},r=o(e),s=o(t);if(r===s)return null;let c=Math.max(20,n-10),u=
|
|
17
|
-
`),n=[],o=0;for(;o<t.length;){let r=t[o];if(/^\s*```/.test(r)){let u=[];for(o++;o<t.length&&!/^\s*```/.test(t[o]);)u.push(t[o++]);o++,n.push({kind:"code",lines:u});continue}if(Pr(r)){n.push({kind:"hr"}),o++;continue}if(r.includes("|")&&o+1<t.length&&Sr(t[o+1])){let u=Tr(r);o+=2;let g=[];for(;o<t.length&&t[o].includes("|")&&t[o].trim()!=="";)g.push(Tr(t[o++]));n.push({kind:"table",header:u,rows:g});continue}let s=r.match(/^(#{1,6})\s+(.*)$/);if(s){n.push({kind:"heading",level:s[1].length,text:s[2]}),o++;continue}if(/^\s*([-*]|\d+\.)\s+/.test(r)){let u=[];for(;o<t.length&&/^\s*([-*]|\d+\.)\s+/.test(t[o]);)u.push(t[o++].replace(/^\s*([-*]|\d+\.)\s+/,""));n.push({kind:"list",items:u});continue}if(r.trim()===""){o++;continue}let c=[];for(;o<t.length&&t[o].trim()!==""&&!/^\s*```/.test(t[o])&&!/^(#{1,6})\s/.test(t[o])&&!/^\s*([-*]|\d+\.)\s+/.test(t[o])&&!Pr(t[o])&&!(t[o].includes("|")&&o+1<t.length&&Sr(t[o+1]));)c.push(t[o++]);n.push({kind:"para",text:c.join(" ")})}return n}function _n(e){return e.replace(/(\*\*[^*]+\*\*|`[^`]+`|\*[^*]+\*)/g,t=>t.startsWith("**")?je.bold(t.slice(2,-2)):t.startsWith("`")?R(t.slice(1,-1)):je.italic(t.slice(1,-1)))}var
|
|
18
|
-
`)}),G=Math.max(...q.map(de=>de.length)),ie=[];for(let de=0;de<G;de++)ie.push(u.map((Pe,pe)=>`${j} ${
|
|
16
|
+
`},r=o(e),s=o(t);if(r===s)return null;let c=Math.max(20,n-10),u=ol("a","b",r,s,"","",{context:3}),g=0,m=0,w=[];u.hunks.forEach((b,v)=>{v>0&&w.push(wr.gray(" \u2026"));let $=b.oldStart,E=b.newStart;for(let q of b.lines){let G=q[0],ie=q.slice(1).slice(0,c);G==="-"?(m++,w.push(`${rl}${En($++)} - ${ie}${xr}`)):G==="+"?(g++,w.push(`${sl}${En(E++)} + ${ie}${xr}`)):(w.push(wr.gray(En(E))+" "+ie),$++,E++)}});let j=w.slice(0,$r);return{added:g,removed:m,lines:j,hidden:Math.max(0,w.length-$r)}}async function Cr(e,t){let n=(e[0]??"status").toLowerCase();try{if(n==="status")return await cl(t.cwd),{kind:"continue"};if(n==="pull")return await ul(t,e.slice(1)),{kind:"continue"};console.log(x(`Unknown subcommand: /sync ${n}`)),console.log(f("Usage: /sync drift report (local vs Document360)")),console.log(f(" /sync pull <path> pull portal edits into the local file")),console.log(f(" /sync pull --all pull every remote-ahead article"))}catch(o){o instanceof al?console.log(x(o.message)):console.log(x(`Sync failed: ${o.message}`))}return{kind:"continue"}}async function cl(e){console.log(f("Checking Document360 for drift\u2026"));let t=await vr({cwd:e});for(let n of Kt(t))console.log(n);console.log("")}async function ul(e,t){let n=t[0];if(!n){console.log(x("Usage: /sync pull <article-path> | --all"));return}let o;if(n==="--all"){if(console.log(f("Checking Document360 for drift\u2026")),o=(await vr({cwd:e.cwd})).entries.filter(s=>s.status==="remote-ahead"&&s.path).map(s=>s.path),o.length===0){console.log(D("\u2713 Nothing is remote-ahead \u2014 no pulls needed.")),console.log(f(" (conflicts are never bulk-pulled; pull them one by one: /sync pull <path>)"));return}console.log(`${ve(String(o.length))} article(s) are remote-ahead.`)}else o=[n.replace(/\\/g,"/")];for(let r of o){let s=await ll({cwd:e.cwd,relPath:r});console.log(""),console.log(`${R("\u25CF")} ${ve(s.title)} ${Q(`(${s.path})`)}`);for(let m of s.notes)console.log(L(` \u26A0 ${m}`));s.overwritesLocalChanges&&console.log(L(" \u26A0 This OVERWRITES local edits made since the last sync."));let c=We(s.oldContent,s.newContent,Math.max(40,(process.stdout.columns??80)-1));if(!c){console.log(f(" Local file already matches the remote content \u2014 advancing the sync base only.")),br({cwd:e.cwd},s);continue}let u=m=>m===1?"":"s";console.log(Q(` \u23BF Added ${c.added} line${u(c.added)}, removed ${c.removed} line${u(c.removed)}`));for(let m of c.lines)console.log(m);if(c.hidden>0&&console.log(f(` \u2026 +${c.hidden} more diff lines`)),!await e.withPausedInput(()=>il({message:`Write ${s.path}?`,default:!s.overwritesLocalChanges}))){console.log(f(" Skipped."));continue}br({cwd:e.cwd},s),console.log(D(` \u2713 Pulled ${s.path} (sync base advanced).`))}console.log("")}H();import{statSync as xl}from"node:fs";import{resolve as bl}from"node:path";import{estimateBulkCost as vl,planPartitions as Cl,readProjectConfig as Pl,resolveModelForOperation as Sl,runPartitioned as Tl,trackedArticlePaths as Rl}from"document360-engine";import B from"picocolors";import jr from"wrap-ansi";import Ln from"string-width";H();import je from"picocolors";import Dn from"wrap-ansi";import In from"string-width";var Pr=e=>/^\s*(-{3,}|\*{3,}|_{3,})\s*$/.test(e),Sr=e=>/^\s*\|?[\s:|-]*-[\s:|-]*\|?\s*$/.test(e)&&e.includes("-"),Tr=e=>e.replace(/^\s*\|/,"").replace(/\|\s*$/,"").split("|").map(t=>t.trim());function dl(e){let t=e.replace(/\r/g,"").split(`
|
|
17
|
+
`),n=[],o=0;for(;o<t.length;){let r=t[o];if(/^\s*```/.test(r)){let u=[];for(o++;o<t.length&&!/^\s*```/.test(t[o]);)u.push(t[o++]);o++,n.push({kind:"code",lines:u});continue}if(Pr(r)){n.push({kind:"hr"}),o++;continue}if(r.includes("|")&&o+1<t.length&&Sr(t[o+1])){let u=Tr(r);o+=2;let g=[];for(;o<t.length&&t[o].includes("|")&&t[o].trim()!=="";)g.push(Tr(t[o++]));n.push({kind:"table",header:u,rows:g});continue}let s=r.match(/^(#{1,6})\s+(.*)$/);if(s){n.push({kind:"heading",level:s[1].length,text:s[2]}),o++;continue}if(/^\s*([-*]|\d+\.)\s+/.test(r)){let u=[];for(;o<t.length&&/^\s*([-*]|\d+\.)\s+/.test(t[o]);)u.push(t[o++].replace(/^\s*([-*]|\d+\.)\s+/,""));n.push({kind:"list",items:u});continue}if(r.trim()===""){o++;continue}let c=[];for(;o<t.length&&t[o].trim()!==""&&!/^\s*```/.test(t[o])&&!/^(#{1,6})\s/.test(t[o])&&!/^\s*([-*]|\d+\.)\s+/.test(t[o])&&!Pr(t[o])&&!(t[o].includes("|")&&o+1<t.length&&Sr(t[o+1]));)c.push(t[o++]);n.push({kind:"para",text:c.join(" ")})}return n}function _n(e){return e.replace(/(\*\*[^*]+\*\*|`[^`]+`|\*[^*]+\*)/g,t=>t.startsWith("**")?je.bold(t.slice(2,-2)):t.startsWith("`")?R(t.slice(1,-1)):je.italic(t.slice(1,-1)))}var pl=(e,t)=>e+" ".repeat(Math.max(0,t-In(e)));function fl(e,t,n){let o=e.length,r=e.map(($,E)=>Math.max(In($),...t.map(q=>In(q[E]??"")))),s=Math.max(24,n),c=3*o+1,u=[...r],g=()=>u.reduce(($,E)=>$+E,0)+c,m=0;for(;g()>s&&m++<1e4;){let $=-1,E=6;for(let q=0;q<o;q++)u[q]>E&&(E=u[q],$=q);if($===-1)break;u[$]-=1}let w=($,E,q)=>je.gray($+u.map(G=>"\u2500".repeat(G+2)).join(E)+q),j=je.gray("\u2502"),b=($,E)=>{let q=u.map((de,Pe)=>{let pe=$[Pe]??"",fe=E?je.bold(pe):_n(pe);return Dn(fe,de,{hard:!0}).split(`
|
|
18
|
+
`)}),G=Math.max(...q.map(de=>de.length)),ie=[];for(let de=0;de<G;de++)ie.push(u.map((Pe,pe)=>`${j} ${pl(q[pe][de]??"",Pe)} `).join("")+j);return ie.join(`
|
|
19
19
|
`)},v=[w("\u250C","\u252C","\u2510"),b(e,!0)];return v.push(t.length===0?w("\u2514","\u2534","\u2518"):w("\u251C","\u253C","\u2524")),t.forEach(($,E)=>{v.push(b($,!1)),v.push(E===t.length-1?w("\u2514","\u2534","\u2518"):w("\u251C","\u253C","\u2524"))}),v.join(`
|
|
20
|
-
`)}function
|
|
20
|
+
`)}function ml(e,t){switch(e.kind){case"heading":return je.bold(e.text);case"hr":return je.gray("\u2500".repeat(t));case"para":return Dn(_n(e.text),t);case"list":return e.items.map(n=>{let[o="",...r]=Dn(_n(n),Math.max(10,t-4)).split(`
|
|
21
21
|
`);return" \u2022 "+o+r.map(s=>`
|
|
22
22
|
`+s).join("")}).join(`
|
|
23
23
|
`);case"code":return e.lines.map(n=>je.gray(" "+n)).join(`
|
|
24
|
-
`);case"table":return
|
|
24
|
+
`);case"table":return fl(e.header,e.rows,t)}}function Mn(e,t){let n=Math.max(20,t);return dl(e).map(o=>ml(o,n)).join(`
|
|
25
25
|
|
|
26
|
-
`)}H();import
|
|
26
|
+
`)}H();import gl from"picocolors";var hl=[127,86,217],kl=[22,38,43],Rr={T:hl,E:kl},kt=["..TTTTTT....","..TTTTTTT...","..TTTTTTTT..","..TTETTETT..","..TTETTETT..","..TTTTTTTT..","..TTTTTTT...","..TTTTTT....","...T..T....."],Nn=([e,t,n])=>`\x1B[38;2;${e};${t};${n}m`,yl=([e,t,n])=>`\x1B[48;2;${e};${t};${n}m`;function Ar(){if(!gl.isColorSupported)return[];let e=kt[0].length,t=[];for(let n=0;n<kt.length;n+=2){let o="";for(let r=0;r<e;r++){let s=Rr[kt[n][r]],c=n+1<kt.length?Rr[kt[n+1][r]]:void 0;s&&c?o+=`${Nn(s)}${yl(c)}\u2580\x1B[49m\x1B[39m`:s?o+=`${Nn(s)}\u2580\x1B[39m`:c?o+=`${Nn(c)}\u2584\x1B[39m`:o+=" "}t.push(o)}return t}function yt(e){return e<60?`${e}s`:`${Math.floor(e/60)}m ${e%60}s`}function ue(e){return e<=0?"$0.00":e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}function nt(e){return e<1e3?`${e} tokens`:e<1e6?`${(e/1e3).toFixed(1)}k tokens`:`${(e/1e6).toFixed(2)}M tokens`}var tt=(e,t)=>` ${e.padEnd(13)}${t}`;function wl(e,t){let n=[pt("\u270E document360-writer")+B.gray(` v${e.version}`),B.gray(" Reads your code, writes your docs."),"",tt("Claude:",`${e.claude}${B.gray(` \xB7 ${e.model}${e.modelSource?` (${e.modelSource})`:""}`)}`),tt("Document360:",e.configured?e.loggedOut?B.yellow("not logged in \u2014 run /login"):`${e.who??""}${e.sessionHint?B.gray(` (${e.sessionHint})`):""}`:B.yellow("not set up \u2014 run /init")),tt("Profile:",e.configured?`${e.profile}${B.gray(` (${e.apiUrl})`)}${e.prod?B.bold(B.yellow(" \u26A0 PRODUCTION")):""}`:B.gray("\u2014 (run /init)")),tt("Project:",e.project),tt("Mode:",B.gray(e.mode)),tt("cwd:",B.gray(e.cwd))],o=Ar();if(o.length===0)return n.join(`
|
|
27
27
|
`);let r=2,s=3,c=Ln(o[0]);if(!(t>=r+c+s+Math.max(...n.map(w=>Ln(w)))))return[...o.map(w=>" "+w),...n].join(`
|
|
28
28
|
`);let g=Math.max(0,Math.floor((n.length-o.length)/2)),m=[];for(let w=0;w<Math.max(o.length+g,n.length);w++){let j=o[w-g]??" ".repeat(c);m.push((" ".repeat(r)+j+" ".repeat(s)+(n[w]??"")).trimEnd())}return m.join(`
|
|
29
|
-
`)}var
|
|
29
|
+
`)}var $l={error:B.red,warn:B.yellow,ok:B.green,info:B.gray};function On(e,t){let n=Math.max(20,t);switch(e.kind){case"banner":return wl(e.info,n);case"user":{let o="\x1B[48;2;42;42;46m",r="\x1B[49m",s=Math.max(10,n-4),c=50,u=e.text.split(`
|
|
30
30
|
`).flatMap(m=>jr(m,s,{hard:!0}).split(`
|
|
31
31
|
`)),g=Math.max(0,u.length-c);return g>0&&(u=[...u.slice(0,c),B.dim(`\u2026 +${g} more lines`)]),`
|
|
32
32
|
`+u.map((m,w)=>o+(w===0?R(" \u276F "):" ")+m+" ".repeat(Math.max(0,s-Ln(m))+1)+r).join(`
|
|
@@ -39,15 +39,15 @@ No MCP servers registered. Add one with /mcp add <name> <type> <ref>
|
|
|
39
39
|
`+pt(`\u25A3 Preview \u2014 ${e.name}`)+`
|
|
40
40
|
|
|
41
41
|
`+Mn(e.text,n);case"note":return`
|
|
42
|
-
|
|
42
|
+
`+$l[e.tone](ft(e.text));case"done":return`
|
|
43
43
|
`+(e.ok?B.magenta("\u2736 "):B.red("\u2736 "))+B.gray(`Cooked for ${yt(e.seconds)} \xB7 ${e.tokens} tokens`+(e.costUsd>0?` \xB7 ${ue(e.costUsd)}`:""))}}function Er(e,t){return e.map(n=>On(n,t)).join(`
|
|
44
|
-
`)}var Un=3;function Wn(e){let t,n=!1;for(let r=0;r<e.length;r++){let s=e[r];s==="--run"||s==="--yes"?n=!0:s==="--scope"?t=e[++r]:s?.startsWith("--scope=")&&(t=s.slice(8))}return{scope:t?.replace(/\\/g,"/").replace(/\/+$/,"")||void 0,run:n}}function Fn(e,t){return t?e.filter(n=>{let o=n.replace(/\\/g,"/");return o===t||o.startsWith(`${t}/`)}):e}function Hn(e,t){return t.map(n=>{let o=0;try{o
|
|
44
|
+
`)}var Un=3;function Wn(e){let t,n=!1;for(let r=0;r<e.length;r++){let s=e[r];s==="--run"||s==="--yes"?n=!0:s==="--scope"?t=e[++r]:s?.startsWith("--scope=")&&(t=s.slice(8))}return{scope:t?.replace(/\\/g,"/").replace(/\/+$/,"")||void 0,run:n}}function Fn(e,t){return t?e.filter(n=>{let o=n.replace(/\\/g,"/");return o===t||o.startsWith(`${t}/`)}):e}function Hn(e,t){return t.map(n=>{let o=0;try{o=xl(bl(e,n)).size}catch{o=0}return{path:n,bytes:o}})}function Bn(e){return`Convert each of these articles to canonical Document360 Flavored Markdown (DFM) and re-publish each as a DRAFT. This is a mechanical syntax conversion, not a rewrite \u2014 be efficient:
|
|
45
45
|
- Read ONLY the article files listed below. Do NOT read source code, other articles, or fetch the live portal \u2014 you already have everything you need.
|
|
46
46
|
- Convert in place: wrap callouts, FAQs, tabs, accordions, and media embeds per the d360-markdown skill. Preserve all wording, headings, and structure; change only GFM\u2192DFM syntax.
|
|
47
47
|
- Publish each as a draft with a single update call. Do NOT re-read, re-verify, or polish after converting, and skip articles already in DFM.
|
|
48
48
|
- Work only on these files:
|
|
49
49
|
`+e.paths.map(t=>`- ${t}`).join(`
|
|
50
|
-
`)}function qn(e,t,n){let o=e.reduce((u,g)=>u+g.paths.length,0),[r,s]=t.usd;return[`Convert ${o} article${o===1?"":"s"} to DFM across ${e.length} partition${e.length===1?"":"s"} (\u2264${n} agents at once):`,...e.map(u=>` \u2022 ${u.label} \u2014 ${u.paths.length} article${u.paths.length===1?"":"s"}`),"",`Estimated cost: ${ue(r)}\u2013${ue(s)}. ${t.note}`,"","Each article is rewritten and re-published as a DRAFT. Run /convert --run to start."]}function zn(e,t,n){let o=$=>t[$.index]?.paths.length??0,r=e.filter($=>$.ok),s=e.filter($=>!$.ok),c=e.reduce(($,E)=>$+o(E),0),u=r.reduce(($,E)=>$+o(E),0),g=e.reduce(($,E)=>$+E.costUsd,0),m=e.reduce(($,E)=>$+E.outputTokens,0),w=n==="api"?`${ue(g)} total`:nt(m),j=`${r.length}/${e.length} partition${e.length===1?"":"s"} completed`,b=$=>`${$} article${$===1?"":"s"}`,v=[];if(s.length===0)v.push(`Converted ${b(c)} (${j}) successfully \xB7 ${w}.`);else{v.push(`Converted ${u}/${b(c)} (${j}) \xB7 ${w}.`),v.push(`${s.length} partition${s.length===1?"":"s"} failed \u2014 re-run /convert to retry:`);for(let $ of s)v.push(` \u2717 ${$.label}${$.error?` \u2014 ${$.error}`:""}`)}return v}async function Dr(e,t){if(!
|
|
50
|
+
`)}function qn(e,t,n){let o=e.reduce((u,g)=>u+g.paths.length,0),[r,s]=t.usd;return[`Convert ${o} article${o===1?"":"s"} to DFM across ${e.length} partition${e.length===1?"":"s"} (\u2264${n} agents at once):`,...e.map(u=>` \u2022 ${u.label} \u2014 ${u.paths.length} article${u.paths.length===1?"":"s"}`),"",`Estimated cost: ${ue(r)}\u2013${ue(s)}. ${t.note}`,"","Each article is rewritten and re-published as a DRAFT. Run /convert --run to start."]}function zn(e,t,n){let o=$=>t[$.index]?.paths.length??0,r=e.filter($=>$.ok),s=e.filter($=>!$.ok),c=e.reduce(($,E)=>$+o(E),0),u=r.reduce(($,E)=>$+o(E),0),g=e.reduce(($,E)=>$+E.costUsd,0),m=e.reduce(($,E)=>$+E.outputTokens,0),w=n==="api"?`${ue(g)} total`:nt(m),j=`${r.length}/${e.length} partition${e.length===1?"":"s"} completed`,b=$=>`${$} article${$===1?"":"s"}`,v=[];if(s.length===0)v.push(`Converted ${b(c)} (${j}) successfully \xB7 ${w}.`);else{v.push(`Converted ${u}/${b(c)} (${j}) \xB7 ${w}.`),v.push(`${s.length} partition${s.length===1?"":"s"} failed \u2014 re-run /convert to retry:`);for(let $ of s)v.push(` \u2717 ${$.label}${$.error?` \u2014 ${$.error}`:""}`)}return v}async function Dr(e,t){if(!Pl(t.cwd))return console.log(x("No d360-writer config here. Run /init first.")),{kind:"continue"};let{scope:n,run:o}=Wn(e),r=Rl(t.cwd,t.profileName);if(r.length===0)return console.log(x("No tracked articles in d360-category-map.json. Publish some first (/publish), then /convert.")),{kind:"continue"};let s=Fn(r,n);if(s.length===0)return console.log(x(`No tracked articles under "${n}". (${r.length} are tracked overall.)`)),{kind:"continue"};let c=Cl(s),u=`/convert${n?` --scope ${n}`:""} --run`,{model:g,forced:m}=Sl(t.cwd,"light");if(!o){let w=vl({files:Hn(t.cwd,s),op:"convert",model:g});n&&console.log(f(`Scope: ${n} (${s.length} of ${r.length} tracked articles).`));for(let j of qn(c,w,Un))console.log(j);return console.log(f(`Model: ${g}${m?" (forced)":" \u2014 mechanical work; /model to override"}.`)),console.log(f(`Run ${u} to start.`)),console.log(""),{kind:"continue"}}console.log(f(`Converting ${s.length} articles across ${c.length} partitions (\u2264${Un} agents at once) on ${g}\u2026`)),console.log(f(" (mid-run abort is TUI-only \u2014 Ctrl+C exits the REPL.)"));try{for await(let w of Tl({cwd:t.cwd,partitions:c,promptFor:Bn,concurrency:Un,profileName:t.profileName,allowProdWrites:t.allowProdWrites(),model:g}))if(w.type==="partition_status")w.status==="running"?console.log(f(` \u25B8 ${w.label} \u2014 converting\u2026`)):w.status==="done"?console.log(D(` \u2713 ${w.label}`)):console.log(x(` \u2717 ${w.label}`));else if(w.type==="run_done"){console.log("");let j=process.env.ANTHROPIC_API_KEY?"api":"subscription";for(let b of zn(w.results,c,j))console.log(w.ok?D(b):L(b))}}catch(w){console.log(x(`Convert run failed: ${w.message}`))}return console.log(""),{kind:"continue"}}H();import{statSync as Ir}from"node:fs";import{resolve as _r}from"node:path";import{estimateBulkCost as Al,planPartitions as jl,readDocsPlan as El,readProjectConfig as Mr,resolveModelForOperation as Dl,runPartitioned as Il}from"document360-engine";var Gn=5;function Yn(e){let t,n,o=!1;for(let s=0;s<e.length;s++){let c=e[s];if(c==="--run"||c==="--yes")o=!0;else{if(c==="--all")continue;c==="--scope"?t=e[++s]:c?.startsWith("--scope=")?t=c.slice(8):c&&!c.startsWith("--")&&(n=c)}}let r=s=>s?.replace(/\\/g,"/").replace(/\/+$/,"")||void 0;return{scope:r(t),path:r(n),run:o}}function _l(e,t){let n=e.replace(/\\/g,"/").replace(/\/+$/,""),o=`${t.replace(/\/+$/,"")}/`;return n.startsWith(o)?n.slice(o.length):n}function Ml(e,t){return t?e.filter(n=>{let o=n.replace(/\\/g,"/");return o===t||o.startsWith(`${t}/`)}):e}function Nl(e,t,n){return n.filter(o=>{try{return Ir(_r(e,t,o)).size===0}catch{return!0}})}function Xn(e,t,n){let o=new Map(t.map(r=>[r.path,r]));return n.map(r=>{let s=1;for(let c of o.get(r)?.sources??[])try{s+=Ir(_r(e,c)).size}catch{}return{path:r,bytes:s}})}function Vn(e,t){return`Run the write-article skill to author EACH documentation article listed below. For each path:
|
|
51
51
|
- It is relative to ${t}/. Look up its entry (matching "path") in .d360-writer/plan.json for its purpose and the source files it draws from (AGENT-PLAN.md has the same table).
|
|
52
52
|
- Read ONLY those source files plus any shared context you genuinely need, and ground every statement in them. Never invent UI labels, routes, or behaviour \u2014 if the source does not say it, omit it.
|
|
53
53
|
- Write the finished article to ${t}/<path>, following the write-article structure and the project terminologyGlossary. Add the \`sources:\` frontmatter listing the files you actually read.
|
|
@@ -55,41 +55,42 @@ No MCP servers registered. Add one with /mcp add <name> <type> <ref>
|
|
|
55
55
|
- Each article is independent. Do NOT write, edit, or publish any article not in this list, and do NOT publish to Document360 \u2014 these are local drafts.
|
|
56
56
|
Articles:
|
|
57
57
|
`+e.paths.map(n=>`- ${n}`).join(`
|
|
58
|
-
`)}function Jn(e,t,n){let o=e.reduce((c,u)=>c+u.paths.length,0),[r,s]=t.usd;return[`Write ${o} article${o===1?"":"s"} across ${e.length} partition${e.length===1?"":"s"} (\u2264${n} agents at once):`,...e.map(c=>` \u2022 ${c.label} \u2014 ${c.paths.length} article${c.paths.length===1?"":"s"}`),"",`Estimated cost: ${ue(r)}\u2013${ue(s)}. ${t.note}`,"","Articles are written as local drafts in the docs tree (nothing is published). Run /write --run to start."]}function Kn(e,t,n){let o=$=>t[$.index]?.paths.length??0,r=e.filter($=>$.ok),s=e.filter($=>!$.ok),c=e.reduce(($,E)=>$+o(E),0),u=r.reduce(($,E)=>$+o(E),0),g=e.reduce(($,E)=>$+E.costUsd,0),m=e.reduce(($,E)=>$+E.outputTokens,0),w=n==="api"?`${ue(g)} total`:nt(m),j=`${r.length}/${e.length} partition${e.length===1?"":"s"} completed`,b=$=>`${$} article${$===1?"":"s"}`,v=[];if(s.length===0)v.push(`Wrote ${b(c)} (${j}) successfully \xB7 ${w}.`),v.push("Review them in the docs tree, then /publish when ready.");else{v.push(`Wrote ${u}/${b(c)} (${j}) \xB7 ${w}.`),v.push(`${s.length} partition${s.length===1?"":"s"} failed \u2014 re-run /write to retry the rest:`);for(let $ of s)v.push(` \u2717 ${$.label}${$.error?` \u2014 ${$.error}`:""}`)}return v}function Qn(e,t,n){let o=(Mr(e)?.docsDir??"user-docs").replace(/\/+$/,""),r=t.map(u=>u.path);if(n.path){let u=Il(n.path,o);return r.includes(u)?{docsDir:o,targets:[u],planCount:r.length}:{docsDir:o,targets:[],planCount:r.length,reason:`"${u}" isn't in the docs plan (.d360-writer/plan.json).`}}let s=_l(r,n.scope);if(n.scope&&s.length===0)return{docsDir:o,targets:[],planCount:r.length,reason:`No planned articles under "${n.scope}".`};let c=Ml(e,o,s);if(c.length===0){let u=n.scope?` under "${n.scope}"`:"";return{docsDir:o,targets:[],planCount:r.length,reason:`All planned articles${u} are already written. Use /write <path> to rewrite one.`}}return{docsDir:o,targets:c,planCount:r.length}}async function Nr(e,t){if(!Mr(t.cwd))return console.log(x("No d360-writer config here. Run /init first.")),{kind:"continue"};let n=jl(t.cwd);if(n.length===0)return console.log(x("No docs plan found (.d360-writer/plan.json). Analyze the repo and propose a structure first.")),{kind:"continue"};let{scope:o,path:r,run:s}=Yn(e),{docsDir:c,targets:u,reason:g}=Qn(t.cwd,n,{scope:o,path:r});if(u.length===0)return console.log(g?L(g):L("Nothing to write.")),{kind:"continue"};let m=Al(u),{model:w,forced:j}=El(t.cwd,"standard");if(!s&&!!!r){let v=Rl({files:Xn(t.cwd,n,u),op:"write",model:w});o&&console.log(f(`Scope: ${o} (${u.length} pending).`));for(let $ of Jn(m,v,Gn))console.log($);return console.log(f(`Model: ${w}${j?" (forced)":" \u2014 authoring; /model to override"}.`)),console.log(f(`Run /write${o?` --scope ${o}`:" --all"} --run to start.`)),console.log(""),{kind:"continue"}}console.log(f(`Writing ${u.length} article${u.length===1?"":"s"} across ${m.length} partition${m.length===1?"":"s"} (\u2264${Gn} agents at once) on ${w}\u2026`)),console.log(f(" (mid-run abort is TUI-only \u2014 Ctrl+C exits the REPL.)"));try{for await(let v of Dl({cwd:t.cwd,partitions:m,promptFor:$=>Vn($,c),concurrency:Gn,profileName:t.profileName,allowProdWrites:t.allowProdWrites(),model:w}))if(v.type==="partition_status")v.status==="running"?console.log(f(` \u25B8 ${v.label} \u2014 writing\u2026`)):v.status==="done"?console.log(D(` \u2713 ${v.label}`)):console.log(x(` \u2717 ${v.label}`));else if(v.type==="run_done"){console.log("");let $=process.env.ANTHROPIC_API_KEY?"api":"subscription";for(let E of Kn(v.results,m,$))console.log(v.ok?D(E):L(E))}}catch(v){console.log(x(`Write run failed: ${v.message}`))}return console.log(""),{kind:"continue"}}H();import{search as Nl}from"@inquirer/prompts";import{findByName as Ll,getSession as Ol,listSessions as Ul,relativeTime as Or}from"document360-engine";async function Ur(e,t){let n=Ul(t.cwd).filter(o=>o.uuid!==t.currentUuid());if(n.length===0)return console.log(f("No saved sessions for this repo yet \u2014 sessions auto-save as you work.")),{kind:"continue"};if(e.length>0){let o=e.join(" "),r=Ll(t.cwd,o);return r?{kind:"resume",uuid:r.uuid,name:r.name}:(console.log(x(`No session matches "${o}".`)),Lr(n),{kind:"continue"})}if(!process.stdin.isTTY)return Lr(n),console.log(f("Run: /resume <name>")),{kind:"continue"};try{let o=await t.withPausedInput(()=>Nl({message:"Resume session (type to filter, \u2191\u2193 to navigate):",source:async s=>{let c=(s??"").toLowerCase();return n.filter(u=>!c||u.name.toLowerCase().includes(c)||u.firstPrompt.toLowerCase().includes(c)).map(u=>({name:`${u.name} ${Or(u.updatedAt)}`,value:u.uuid,description:u.firstPrompt.slice(0,100)}))}})),r=Ol(o);return r?{kind:"resume",uuid:r.uuid,name:r.name}:{kind:"continue"}}catch{return console.log(""),{kind:"continue"}}}function Lr(e){console.log("");for(let t of e.slice(0,15))console.log(` ${R(t.name)} ${f(Or(t.updatedAt))}`),console.log(` ${f(t.firstPrompt.slice(0,80))}`);console.log("")}H();import{renameSession as Wl}from"document360-engine";function Zn(e){let t=e.trim();return t.length>=2&&(t[0]==='"'&&t.endsWith('"')||t[0]==="'"&&t.endsWith("'"))?t.slice(1,-1).trim():t}async function Wr(e,t){let n=Zn(e.join(" "));if(!n)return console.log(x("Usage: /rename <new name>")),{kind:"continue"};let o=t.currentUuid();return o?(Wl(o,n)?console.log(D(`\u2713 Session renamed to "${n}"`)):console.log(x("Could not find the current session record.")),{kind:"continue"}):(console.log(x("Nothing to rename yet \u2014 send a message first; sessions auto-save once the agent replies.")),{kind:"continue"})}import{knownEnvironments as Fr,readProjectConfig as Fl,writeProjectConfig as Hl}from"document360-engine";H();function eo(e,t,n){if(!t)return"Usage: /profile add <name> [environment]";let o=Fl(e);if(!o)return"No .d360-writer.json \u2014 run /init first.";if(o.profiles?.[t])return`Profile "${t}" already exists.`;let r=n??t;return Fr().includes(r)?(o.profiles={...o.profiles,[t]:{connection:{environment:r},production:!1}},Hl(o,e),null):`Unknown environment "${r}". Known: ${Fr().join(", ")} (or add the profile with explicit URLs in .d360-writer.json).`}async function Hr(e,t){let n=e[0];if(!n)return Wt(t.cwd),{kind:"continue"};if(n==="add"){let o=eo(t.cwd,e[1],e[2]);return o?(console.log(x(o)),{kind:"continue"}):(console.log(D(`\u2713 Profile "${e[1]}" created (environment: ${e[2]??e[1]}).`)),console.log(` Switch + sign in: ${R(`/profile ${e[1]}`)} then ${R("/login")}`),{kind:"continue"})}return Ft(t.cwd,n),Ht(t.cwd,n),console.log(f(" Restarting agent for the new profile\u2026")),{kind:"clear"}}H();import{select as Bl}from"@inquirer/prompts";import{readProjectConfig as ql,readUserConfig as Br,resolveModelSetting as to,writeUserConfig as qr}from"document360-engine";var ge=[{value:null,label:"Auto",desc:"Engine right-sizes per task \u2014 Sonnet for routine work, Opus for analysis (recommended)"},{value:"claude-fable-5",label:"Fable",desc:"Fable 5 \xB7 most capable, for the hardest and longest-running tasks"},{value:"opus",label:"Opus",desc:"Opus 4.8 \xB7 best for everyday complex tasks"},{value:"sonnet",label:"Sonnet",desc:"Sonnet 4.6 \xB7 efficient for routine tasks"},{value:"haiku",label:"Haiku",desc:"Haiku 4.5 \xB7 fastest for quick answers"}];function Kt(e){if(e.model===null||e.source==="claude-settings")return 0;let t=e.model.toLowerCase(),n=ge.findIndex(o=>o.value!==null&&(o.value===t||o.label.toLowerCase()===t||t.includes(o.label.toLowerCase())));return n>=0?n:0}function zl(e){switch(e.source){case"project":return".d360-writer.json defaultModel (team setting)";case"user":return"~/.document360-writer/config.json (your /model setting)";case"env":return"ANTHROPIC_MODEL environment variable";case"claude-settings":return"Claude Code's own settings (~/.claude/settings.json)";case"claude-default":return"Claude Code default (no override configured)"}}function wt(e,t){let n=()=>{let s=to(e);return s.source==="project"||s.source==="user"||s.source==="env"?s.model??void 0:void 0};if(t==="default"){let s=Br();return s.defaultModel?(delete s.defaultModel,qr(s),{lines:[`\u2713 Personal model override cleared \u2014 now: ${to(e).model??"Claude Code default"} (applies from your next message)`],changed:!0,effective:n()}):{lines:["No personal model override set \u2014 nothing to clear."],changed:!1,effective:void 0}}qr({...Br(),defaultModel:t});let o=[`\u2713 Personal model set to "${t}" (applies from your next message \u2014 conversation continues)`],r=ql(e)?.defaultModel;return r&&o.push(`\u26A0 .d360-writer.json sets defaultModel "${r}" \u2014 the team setting overrides yours until it is removed.`),{lines:o,changed:!0,effective:n()}}async function zr(e,t){let n=e[0]?.trim();if(!n){let c=to(t.cwd);if(!process.stdin.isTTY)return console.log(`${ve("Model:")} ${R(c.model??"Claude Code default")}`),console.log(f(` source: ${zl(c)}`)),console.log(f(" change: /model <haiku|sonnet|opus|full-model-id> \xB7 reset: /model default")),{kind:"continue"};let u=Kt(c),g;try{g=await t.withPausedInput(()=>Bl({message:`Select model (current: ${c.model??"Claude Code default"})`,default:ge[u].value,choices:ge.map((b,v)=>({name:`${b.label}${v===u?" \u2714":""}`,value:b.value,description:b.desc}))}))}catch{return console.log(f("Cancelled.")),{kind:"continue"}}let{lines:m,changed:w,effective:j}=wt(t.cwd,g??"default");for(let b of m)console.log(b.startsWith("\u26A0")?L(b):b.startsWith("\u2713")?D(b):f(b));return w&&await t.setModel(j),{kind:"continue"}}let{lines:o,changed:r,effective:s}=wt(t.cwd,n);for(let c of o)console.log(c.startsWith("\u26A0")?L(c):c.startsWith("\u2713")?D(c):f(c));return r&&await t.setModel(s),{kind:"continue"}}Qt();async function Jr(e,t){return await t.withPausedInput(()=>Ze(t.cwd)),{kind:"clear"}}H();import{resolveActiveProfile as na}from"document360-engine";async function Kr(e,t){let n=!1;try{n=na(t.cwd).production}catch{}return n?(console.log(L("\u26A0 Authorizing writes to the PRODUCTION profile for this session.")),{kind:"allow-prod"}):(console.log(f("Current profile is not a production profile \u2014 writes are already allowed.")),{kind:"continue"})}H();var Qr=async(e,t)=>{try{await t.withPausedInput(()=>Ut({}))}catch(n){console.log(x(`Login failed: ${n.message}`))}return{kind:"continue"}};import{existsSync as Zr}from"node:fs";import{isAbsolute as oa,join as ra,resolve as sa}from"node:path";import{readProjectConfig as ia,screenshotPlaceholderIds as la}from"document360-engine";var es=e=>e.replace(/\\/g,"/").replace(/\/+$/,"");function oo(e){let t=!e.includes("--no-setup"),n=e.filter(r=>r!=="--no-setup");if(n[0]==="--list")return{mode:"list",scope:n[1]?es(n[1]):void 0};let o=n[0];return!o||o==="--all"?{mode:"all",setup:t}:/[\\/]/.test(o)||o.endsWith(".md")?{mode:"scope",scope:es(o),setup:t}:{mode:"single",id:o}}function ro(e,t){let n=ia(e),o=n?.captureDir??"user-docs/_capture",r=n?.outputDir??"user-docs/_screenshots",s=(c,u)=>oa(c)?ra(c,u):sa(e,c,u);return la(e,{scope:t}).map(({id:c,file:u})=>{let g=Zr(s(r,`${c}.png`))?"captured":Zr(s(o,`${c}.spec.ts`))?"spec":"placeholder";return{id:c,file:u,state:g}})}var aa={placeholder:"\u25CB",spec:"\u25D0",captured:"\u25CF"},ca={placeholder:"placeholder only",spec:"spec written, not captured",captured:"captured"};function so(e,t){if(e.length===0)return[t?`No screenshot placeholders under ${t}.`:"No screenshot placeholders found in the docs."];let n=[...new Set(e.map(s=>s.file))].sort(),o=e.filter(s=>s.state==="captured").length,r=[`Screenshots: ${e.length} placeholder${e.length===1?"":"s"} across ${n.length} article${n.length===1?"":"s"} \xB7 ${o} captured${t?` \xB7 scope ${t}`:""}`,""];for(let s of n){r.push(s);for(let c of e.filter(u=>u.file===s))r.push(` ${aa[c.state]} ${c.id.padEnd(34)} ${ca[c.state]}`)}return r.push("","\u25CB placeholder only \u25D0 spec written \u25CF captured"),r}function ts(e){return["Run the emit-screenshot-spec skill to author the document360-capture spec for EACH of these","SCREENSHOT placeholder ids:",e.paths.map(t=>`- ${t}`).join(`
|
|
58
|
+
`)}function Jn(e,t,n){let o=e.reduce((c,u)=>c+u.paths.length,0),[r,s]=t.usd;return[`Write ${o} article${o===1?"":"s"} across ${e.length} partition${e.length===1?"":"s"} (\u2264${n} agents at once):`,...e.map(c=>` \u2022 ${c.label} \u2014 ${c.paths.length} article${c.paths.length===1?"":"s"}`),"",`Estimated cost: ${ue(r)}\u2013${ue(s)}. ${t.note}`,"","Articles are written as local drafts in the docs tree (nothing is published). Run /write --run to start."]}function Kn(e,t,n){let o=$=>t[$.index]?.paths.length??0,r=e.filter($=>$.ok),s=e.filter($=>!$.ok),c=e.reduce(($,E)=>$+o(E),0),u=r.reduce(($,E)=>$+o(E),0),g=e.reduce(($,E)=>$+E.costUsd,0),m=e.reduce(($,E)=>$+E.outputTokens,0),w=n==="api"?`${ue(g)} total`:nt(m),j=`${r.length}/${e.length} partition${e.length===1?"":"s"} completed`,b=$=>`${$} article${$===1?"":"s"}`,v=[];if(s.length===0)v.push(`Wrote ${b(c)} (${j}) successfully \xB7 ${w}.`),v.push("Review them in the docs tree, then /publish when ready.");else{v.push(`Wrote ${u}/${b(c)} (${j}) \xB7 ${w}.`),v.push(`${s.length} partition${s.length===1?"":"s"} failed \u2014 re-run /write to retry the rest:`);for(let $ of s)v.push(` \u2717 ${$.label}${$.error?` \u2014 ${$.error}`:""}`)}return v}function Qn(e,t,n){let o=(Mr(e)?.docsDir??"user-docs").replace(/\/+$/,""),r=t.map(u=>u.path);if(n.path){let u=_l(n.path,o);return r.includes(u)?{docsDir:o,targets:[u],planCount:r.length}:{docsDir:o,targets:[],planCount:r.length,reason:`"${u}" isn't in the docs plan (.d360-writer/plan.json).`}}let s=Ml(r,n.scope);if(n.scope&&s.length===0)return{docsDir:o,targets:[],planCount:r.length,reason:`No planned articles under "${n.scope}".`};let c=Nl(e,o,s);if(c.length===0){let u=n.scope?` under "${n.scope}"`:"";return{docsDir:o,targets:[],planCount:r.length,reason:`All planned articles${u} are already written. Use /write <path> to rewrite one.`}}return{docsDir:o,targets:c,planCount:r.length}}async function Nr(e,t){if(!Mr(t.cwd))return console.log(x("No d360-writer config here. Run /init first.")),{kind:"continue"};let n=El(t.cwd);if(n.length===0)return console.log(x("No docs plan found (.d360-writer/plan.json). Analyze the repo and propose a structure first.")),{kind:"continue"};let{scope:o,path:r,run:s}=Yn(e),{docsDir:c,targets:u,reason:g}=Qn(t.cwd,n,{scope:o,path:r});if(u.length===0)return console.log(g?L(g):L("Nothing to write.")),{kind:"continue"};let m=jl(u),{model:w,forced:j}=Dl(t.cwd,"standard");if(!s&&!!!r){let v=Al({files:Xn(t.cwd,n,u),op:"write",model:w});o&&console.log(f(`Scope: ${o} (${u.length} pending).`));for(let $ of Jn(m,v,Gn))console.log($);return console.log(f(`Model: ${w}${j?" (forced)":" \u2014 authoring; /model to override"}.`)),console.log(f(`Run /write${o?` --scope ${o}`:" --all"} --run to start.`)),console.log(""),{kind:"continue"}}console.log(f(`Writing ${u.length} article${u.length===1?"":"s"} across ${m.length} partition${m.length===1?"":"s"} (\u2264${Gn} agents at once) on ${w}\u2026`)),console.log(f(" (mid-run abort is TUI-only \u2014 Ctrl+C exits the REPL.)"));try{for await(let v of Il({cwd:t.cwd,partitions:m,promptFor:$=>Vn($,c),concurrency:Gn,profileName:t.profileName,allowProdWrites:t.allowProdWrites(),model:w}))if(v.type==="partition_status")v.status==="running"?console.log(f(` \u25B8 ${v.label} \u2014 writing\u2026`)):v.status==="done"?console.log(D(` \u2713 ${v.label}`)):console.log(x(` \u2717 ${v.label}`));else if(v.type==="run_done"){console.log("");let $=process.env.ANTHROPIC_API_KEY?"api":"subscription";for(let E of Kn(v.results,m,$))console.log(v.ok?D(E):L(E))}}catch(v){console.log(x(`Write run failed: ${v.message}`))}return console.log(""),{kind:"continue"}}H();import{search as Ll}from"@inquirer/prompts";import{findByName as Ol,getSession as Ul,listSessions as Wl,relativeTime as Or}from"document360-engine";async function Ur(e,t){let n=Wl(t.cwd).filter(o=>o.uuid!==t.currentUuid());if(n.length===0)return console.log(f("No saved sessions for this repo yet \u2014 sessions auto-save as you work.")),{kind:"continue"};if(e.length>0){let o=e.join(" "),r=Ol(t.cwd,o);return r?{kind:"resume",uuid:r.uuid,name:r.name}:(console.log(x(`No session matches "${o}".`)),Lr(n),{kind:"continue"})}if(!process.stdin.isTTY)return Lr(n),console.log(f("Run: /resume <name>")),{kind:"continue"};try{let o=await t.withPausedInput(()=>Ll({message:"Resume session (type to filter, \u2191\u2193 to navigate):",source:async s=>{let c=(s??"").toLowerCase();return n.filter(u=>!c||u.name.toLowerCase().includes(c)||u.firstPrompt.toLowerCase().includes(c)).map(u=>({name:`${u.name} ${Or(u.updatedAt)}`,value:u.uuid,description:u.firstPrompt.slice(0,100)}))}})),r=Ul(o);return r?{kind:"resume",uuid:r.uuid,name:r.name}:{kind:"continue"}}catch{return console.log(""),{kind:"continue"}}}function Lr(e){console.log("");for(let t of e.slice(0,15))console.log(` ${R(t.name)} ${f(Or(t.updatedAt))}`),console.log(` ${f(t.firstPrompt.slice(0,80))}`);console.log("")}H();import{renameSession as Fl}from"document360-engine";function Zn(e){let t=e.trim();return t.length>=2&&(t[0]==='"'&&t.endsWith('"')||t[0]==="'"&&t.endsWith("'"))?t.slice(1,-1).trim():t}async function Wr(e,t){let n=Zn(e.join(" "));if(!n)return console.log(x("Usage: /rename <new name>")),{kind:"continue"};let o=t.currentUuid();return o?(Fl(o,n)?console.log(D(`\u2713 Session renamed to "${n}"`)):console.log(x("Could not find the current session record.")),{kind:"continue"}):(console.log(x("Nothing to rename yet \u2014 send a message first; sessions auto-save once the agent replies.")),{kind:"continue"})}import{knownEnvironments as Fr,readProjectConfig as Hl,writeProjectConfig as Bl}from"document360-engine";H();function eo(e,t,n){if(!t)return"Usage: /profile add <name> [environment]";let o=Hl(e);if(!o)return"No .d360-writer.json \u2014 run /init first.";if(o.profiles?.[t])return`Profile "${t}" already exists.`;let r=n??t;return Fr().includes(r)?(o.profiles={...o.profiles,[t]:{connection:{environment:r},production:!1}},Bl(o,e),null):`Unknown environment "${r}". Known: ${Fr().join(", ")} (or add the profile with explicit URLs in .d360-writer.json).`}async function Hr(e,t){let n=e[0];if(!n)return Ft(t.cwd),{kind:"continue"};if(n==="add"){let o=eo(t.cwd,e[1],e[2]);return o?(console.log(x(o)),{kind:"continue"}):(console.log(D(`\u2713 Profile "${e[1]}" created (environment: ${e[2]??e[1]}).`)),console.log(` Switch + sign in: ${R(`/profile ${e[1]}`)} then ${R("/login")}`),{kind:"continue"})}return Ht(t.cwd,n),Bt(t.cwd,n),console.log(f(" Restarting agent for the new profile\u2026")),{kind:"clear"}}H();import{select as ql}from"@inquirer/prompts";import{readProjectConfig as zl,readUserConfig as Br,resolveModelSetting as to,writeUserConfig as qr}from"document360-engine";var ge=[{value:null,label:"Auto",desc:"Engine right-sizes per task \u2014 Sonnet for routine work, Opus for analysis (recommended)"},{value:"claude-fable-5",label:"Fable",desc:"Fable 5 \xB7 most capable, for the hardest and longest-running tasks"},{value:"opus",label:"Opus",desc:"Opus 4.8 \xB7 best for everyday complex tasks"},{value:"sonnet",label:"Sonnet",desc:"Sonnet 4.6 \xB7 efficient for routine tasks"},{value:"haiku",label:"Haiku",desc:"Haiku 4.5 \xB7 fastest for quick answers"}];function Qt(e){if(e.model===null||e.source==="claude-settings")return 0;let t=e.model.toLowerCase(),n=ge.findIndex(o=>o.value!==null&&(o.value===t||o.label.toLowerCase()===t||t.includes(o.label.toLowerCase())));return n>=0?n:0}function Gl(e){switch(e.source){case"project":return".d360-writer.json defaultModel (team setting)";case"user":return"~/.document360-writer/config.json (your /model setting)";case"env":return"ANTHROPIC_MODEL environment variable";case"claude-settings":return"Claude Code's own settings (~/.claude/settings.json)";case"claude-default":return"Claude Code default (no override configured)"}}function wt(e,t){let n=()=>{let s=to(e);return s.source==="project"||s.source==="user"||s.source==="env"?s.model??void 0:void 0};if(t==="default"){let s=Br();return s.defaultModel?(delete s.defaultModel,qr(s),{lines:[`\u2713 Personal model override cleared \u2014 now: ${to(e).model??"Claude Code default"} (applies from your next message)`],changed:!0,effective:n()}):{lines:["No personal model override set \u2014 nothing to clear."],changed:!1,effective:void 0}}qr({...Br(),defaultModel:t});let o=[`\u2713 Personal model set to "${t}" (applies from your next message \u2014 conversation continues)`],r=zl(e)?.defaultModel;return r&&o.push(`\u26A0 .d360-writer.json sets defaultModel "${r}" \u2014 the team setting overrides yours until it is removed.`),{lines:o,changed:!0,effective:n()}}async function zr(e,t){let n=e[0]?.trim();if(!n){let c=to(t.cwd);if(!process.stdin.isTTY)return console.log(`${ve("Model:")} ${R(c.model??"Claude Code default")}`),console.log(f(` source: ${Gl(c)}`)),console.log(f(" change: /model <haiku|sonnet|opus|full-model-id> \xB7 reset: /model default")),{kind:"continue"};let u=Qt(c),g;try{g=await t.withPausedInput(()=>ql({message:`Select model (current: ${c.model??"Claude Code default"})`,default:ge[u].value,choices:ge.map((b,v)=>({name:`${b.label}${v===u?" \u2714":""}`,value:b.value,description:b.desc}))}))}catch{return console.log(f("Cancelled.")),{kind:"continue"}}let{lines:m,changed:w,effective:j}=wt(t.cwd,g??"default");for(let b of m)console.log(b.startsWith("\u26A0")?L(b):b.startsWith("\u2713")?D(b):f(b));return w&&await t.setModel(j),{kind:"continue"}}let{lines:o,changed:r,effective:s}=wt(t.cwd,n);for(let c of o)console.log(c.startsWith("\u26A0")?L(c):c.startsWith("\u2713")?D(c):f(c));return r&&await t.setModel(s),{kind:"continue"}}Zt();async function Jr(e,t){return await t.withPausedInput(()=>Ze(t.cwd)),{kind:"clear"}}H();import{resolveActiveProfile as oa}from"document360-engine";async function Kr(e,t){let n=!1;try{n=oa(t.cwd).production}catch{}return n?(console.log(L("\u26A0 Authorizing writes to the PRODUCTION profile for this session.")),{kind:"allow-prod"}):(console.log(f("Current profile is not a production profile \u2014 writes are already allowed.")),{kind:"continue"})}H();var Qr=async(e,t)=>{try{await t.withPausedInput(()=>Wt({}))}catch(n){console.log(x(`Login failed: ${n.message}`))}return{kind:"continue"}};import{existsSync as Zr}from"node:fs";import{isAbsolute as ra,join as sa,resolve as ia}from"node:path";import{readProjectConfig as la,screenshotPlaceholderIds as aa}from"document360-engine";var es=e=>e.replace(/\\/g,"/").replace(/\/+$/,"");function oo(e){let t=!e.includes("--no-setup"),n=e.filter(r=>r!=="--no-setup");if(n[0]==="--list")return{mode:"list",scope:n[1]?es(n[1]):void 0};let o=n[0];return!o||o==="--all"?{mode:"all",setup:t}:/[\\/]/.test(o)||o.endsWith(".md")?{mode:"scope",scope:es(o),setup:t}:{mode:"single",id:o}}function ro(e,t){let n=la(e),o=n?.captureDir??"user-docs/_capture",r=n?.outputDir??"user-docs/_screenshots",s=(c,u)=>ra(c)?sa(c,u):ia(e,c,u);return aa(e,{scope:t}).map(({id:c,file:u})=>{let g=Zr(s(r,`${c}.png`))?"captured":Zr(s(o,`${c}.spec.ts`))?"spec":"placeholder";return{id:c,file:u,state:g}})}var ca={placeholder:"\u25CB",spec:"\u25D0",captured:"\u25CF"},ua={placeholder:"placeholder only",spec:"spec written, not captured",captured:"captured"};function so(e,t){if(e.length===0)return[t?`No screenshot placeholders under ${t}.`:"No screenshot placeholders found in the docs."];let n=[...new Set(e.map(s=>s.file))].sort(),o=e.filter(s=>s.state==="captured").length,r=[`Screenshots: ${e.length} placeholder${e.length===1?"":"s"} across ${n.length} article${n.length===1?"":"s"} \xB7 ${o} captured${t?` \xB7 scope ${t}`:""}`,""];for(let s of n){r.push(s);for(let c of e.filter(u=>u.file===s))r.push(` ${ca[c.state]} ${c.id.padEnd(34)} ${ua[c.state]}`)}return r.push("","\u25CB placeholder only \u25D0 spec written \u25CF captured"),r}function ts(e){return["Run the emit-screenshot-spec skill to author the document360-capture spec for EACH of these","SCREENSHOT placeholder ids:",e.paths.map(t=>`- ${t}`).join(`
|
|
59
59
|
`),"","For each: locate its <!-- SCREENSHOT --> block in user-docs/**/*.md; read the product source for","EXACT routes + stable data-testid selectors (never guess); enter the prepared context via","captureScope(); guard data prerequisites with test.skip(reason); write <captureDir>/<id>.spec.ts","(skip-with-TODO if a stable selector is missing). Do NOT run other skills. Report the specs you","wrote and any TODO data-testids."].join(`
|
|
60
|
-
`)}async function
|
|
60
|
+
`)}async function en(e,t){let n=oo(e);if(n.mode==="list"){let c=t?.cwd??process.cwd();for(let u of so(ro(c,n.scope),n.scope))console.log(u);return{kind:"continue"}}if(n.mode==="single")return{kind:"forward-to-agent",prompt:[`Run the emit-screenshot-spec skill for the SCREENSHOT placeholder with id \`${n.id}\`.`,"Locate its <!-- SCREENSHOT --> block in user-docs/**/*.md, then follow that skill exactly: read the","product source for EXACT routes + stable data-testid selectors (never guess); enter the prepared","context via captureScope(); guard data prerequisites with test.skip(reason); write",`<captureDir>/${n.id}.spec.ts. Report the spec path and any TODO data-testids or data to stage.`].join(`
|
|
61
61
|
`),display:`/screenshot ${n.id}`};let r=[`Run the emit-screenshot-spec skill to (re)generate the document360-capture spec for ${n.mode==="scope"?`every <!-- SCREENSHOT --> placeholder in articles under ${n.scope}`:"every <!-- SCREENSHOT --> placeholder across user-docs/**/*.md"}.`,"Follow that skill exactly for each: read the SCREENSHOT block; read the product source for EXACT routes","and stable data-testid selectors (never guess); enter the prepared context via captureScope(); guard data",`prerequisites with test.skip(reason); write <captureDir>/<id>.spec.ts.${n.setup?" When done, run capture-setup-checklist to refresh CAPTURE-SETUP.md.":""} Report specs written, TODO data-testids, and data to stage.`].join(`
|
|
62
|
-
`),s=n.mode==="scope"?`/screenshot ${n.scope}`:`/screenshot${e[0]?` ${e[0]}`:""}`;return{kind:"forward-to-agent",prompt:r,display:s}}import{existsSync as
|
|
63
|
-
`),display:"/capture-setup"}}var ns="-".repeat(64);function io(e){let t="user-docs/_capture";try{let w=
|
|
64
|
-
`).trimEnd();if(!r)return{lines:["(no output)"],hidden:0};if(n?.startsWith("mcp__document360__")){let c=
|
|
65
|
-
`);return{lines:s.slice(0,t).map(c=>re(c,po)),hidden:Math.max(0,s.length-t)}}function
|
|
62
|
+
`),s=n.mode==="scope"?`/screenshot ${n.scope}`:`/screenshot${e[0]?` ${e[0]}`:""}`;return{kind:"forward-to-agent",prompt:r,display:s}}import{existsSync as da,readFileSync as pa}from"node:fs";import{isAbsolute as fa,join as ma,resolve as ga}from"node:path";import{readProjectConfig as ha}from"document360-engine";async function xt(){return{kind:"forward-to-agent",prompt:["Run the capture-setup-checklist skill.","","Scan every <!-- SCREENSHOT --> block across user-docs/**/*.md, read each block\u2019s prerequisites,","anchor them to the capture scope keys in .d360-capture.json, then synthesize a deduped, grouped","\u201Cstage this data\u201D checklist and write it to <captureDir>/CAPTURE-SETUP.md. Separate transient/manual","states, flag any spec whose prerequisites are vague, and report the path when done."].join(`
|
|
63
|
+
`),display:"/capture-setup"}}var ns="-".repeat(64);function io(e){let t="user-docs/_capture";try{let w=ha(e);w?.captureDir&&(t=w.captureDir.replace(/\\/g,"/").replace(/\/+$/,""))}catch{}let n=fa(t)?ma(t,"CAPTURE-TESTID-REQUESTS.json"):ga(e,t,"CAPTURE-TESTID-REQUESTS.json");if(!da(n))return null;let o;try{let w=JSON.parse(pa(n,"utf8").replace(/^/,""));o=Array.isArray(w?.requests)?w.requests:[]}catch{return null}if(o.length===0)return null;let r=new Set(o.map(w=>w.file).filter(Boolean)).size,s=o.length,c=`${s} data-testid attribute${s===1?"":"s"}`,u=`${r} source file${r===1?"":"s"}`,g=`${t}/CAPTURE-TESTID-REQUESTS.md`,m=`${t}/CAPTURE-TESTID-REQUESTS.json`;return[`\u{1F4CB} Developer hand-off \u2014 ${c} requested across ${u}.`,"\u26A0 Do NOT run this prompt here. d360-writer documents code; it does not change it \u2014"," these edits belong in your code repo. Open a SEPARATE terminal in:",` ${e}`," start Claude Code (or your coding agent), and paste everything between the lines."," Tip: run it in plan mode first \u2014 these are a hypothesis to verify, not a verified patch.","",ns,`Read ${g} and ${m}. They list ${c} that d360-writer THINKS this repo needs for screenshot automation. Treat them as a hypothesis to VERIFY against the source \u2014 not a verified patch list.`,"","For EACH request in the JSON:",'1. Locate the element in THIS repo. Trace it from the route/page, not the feature name. If "anchorVerified" is false, find it by the "element"/"reason" description; otherwise confirm the "anchor" snippet still exists in "file".',"2. If the element already has a data-testid, skip it and note the existing one.","3. Confirm the attribute will reach the DOM: the rendering component must forward unknown props (a {...rest} spread or explicit pass-through). If it is a shared wrapper (e.g. Modal, ContextMenu) that destructures a fixed prop list, a data-testid is silently dropped \u2014 thread it through the component, or report it as needing a code change instead of forcing it.",'4. Only then add data-testid="<testid>" to the verified element. Add nothing else; do not rename, restructure, reformat, or change behaviour.',"","When done, report: which testids you added (file + element), which were already present, which requests were wrong (wrong file/anchor/page) with the correction, and which need threading through a shared component. Never force a request that does not match the source \u2014 flag it instead.",ns]}H();import{existsSync as ka,rmSync as ya}from"node:fs";import{basename as os,resolve as rs}from"node:path";import{input as wa}from"@inquirer/prompts";import{readProjectConfig as $a}from"document360-engine";var xa=[".d360-writer.json",".d360-writer","d360-category-map.json",".d360-capture.json",".d360-capture-cache"];function lo(e){let t=null;try{t=$a(e)}catch{t=null}let n=s=>s?.replace(/\\/g,"/").replace(/\/+$/,""),o=n(t?.docsDir)??"user-docs",r=new Set([o]);for(let s of[n(t?.captureDir),n(t?.outputDir)])s&&s!==o&&!s.startsWith(`${o}/`)&&r.add(s);return[...r,...xa].filter(s=>ka(rs(e,s)))}function ao(e,t){let n=[],o=[];for(let r of t)try{ya(rs(e,r),{recursive:!0,force:!0}),n.push(r)}catch(s){o.push({path:r,error:s.message})}return{removed:n,failed:o}}function co(e,t){return t.length===0?["Nothing to reset \u2014 no d360-writer files found in this repo."]:["\u26A0 This permanently DELETES everything d360-writer created here:",...t.map(n=>` \u2022 ${n}`),"","Undo = git: committed files are restorable; untracked ones (most screenshots) are gone.",`To confirm, type the repo name: ${os(e)}`]}async function ss(e,t){let n=lo(t.cwd);for(let u of co(t.cwd,n))console.log(n.length===0?f(u):u);if(n.length===0)return{kind:"continue"};let o=os(t.cwd);if((await t.withPausedInput(()=>wa({message:`Type "${o}" to delete (anything else cancels):`}).catch(()=>""))).trim()!==o)return console.log(L("Reset cancelled \u2014 nothing deleted.")),{kind:"continue"};let{removed:s,failed:c}=ao(t.cwd,n);console.log(D(`\u2713 Reset complete \u2014 removed ${s.length} item${s.length===1?"":"s"}. The repo is back to its original state.`));for(let u of c)console.log(x(` \u2717 ${u.path}: ${u.error}`));return console.log(f("Set up d360-writer again with /init (then /login, /workspace).")),{kind:"continue"}}var is={help:Tn,"?":Tn,clear:or,exit:Rn,quit:Rn,init:cr,mcp:Gt,publish:gr,audit:Vt,scope:kr,sync:Cr,convert:Dr,write:Nr,resume:Ur,rename:Wr,profile:Hr,model:zr,doctor:$t,workspace:Jr,"allow-prod":Kr,login:Qr,screenshot:en,"capture-setup":xt,reset:ss};function ls(e){let t=e.trim();if(!t.startsWith("/"))return null;let n=t.slice(1).split(/\s+/),o=(n[0]??"").toLowerCase();return o?{name:o,args:n.slice(1)}:null}H();var ba={Bash:"command",PowerShell:"command",Read:"file_path",Write:"file_path",Edit:"file_path",NotebookEdit:"notebook_path",Glob:"pattern",Grep:"pattern",WebFetch:"url",WebSearch:"query",Agent:"description",Task:"description",Skill:"skill"},cs=160,po=200,us=40;function re(e,t){let n=e.replace(/\s+/g," ").trim();return n.length<=t?n:n.slice(0,t-1)+"\u2026"}function as(e){let t=Object.entries(e).filter(([,o])=>o!=null&&o!=="");if(t.length===0)return null;let n=t.slice(0,4).map(([o,r])=>`${o}: ${re(typeof r=="string"?r:JSON.stringify(r),us)}`);return t.length>4&&n.push("\u2026"),re(n.join(", "),cs)}var Ee=e=>typeof e=="string"&&e?e:null,uo=e=>typeof e=="string"&&e.length>=8?e.slice(0,8):null;function va(e){let t=Ee(e)?.replace(/\\/g,"/");if(!t)return null;let n=t.split("/").filter(Boolean);if(n.length<2)return null;let o=n[n.length-2],r=o.replace(/^\d+[-_.]/,"").split(/[-_]/).filter(Boolean);return r.length===0?o:r.map(s=>s.charAt(0).toUpperCase()+s.slice(1)).join(" ")}function Ca(e,t){let n=(o,r)=>({title:`Document360: ${o}`,sep:" ",arg:r});switch(e){case"d360_create_article":{let o=Ee(t.title);if(!o)return null;let r=va(t.local_path);return n("Create article",`"${re(o,60)}"${r?` in ${r}`:""}`)}case"d360_update_article":{let o=Ee(t.title),r=uo(t.article_id);return n("Update article",o?`"${re(o,60)}"`:r?`id ${r}\u2026`:null)}case"d360_fork_article":return n("Fork article (new draft)",uo(t.article_id)?`id ${uo(t.article_id)}\u2026`:null);case"d360_publish_article":{let o=t.version_number;return n("Publish article LIVE",typeof o=="number"?`v${o}`:null)}case"d360_unpublish_article":return n("Unpublish article",null);case"d360_create_category":return n("Create category",Ee(t.name)?`"${re(Ee(t.name),60)}"`:null);case"d360_upload_drive_file":{let o=Ee(t.file_path);return n("Upload image",o?re(o.replace(/\\/g,"/").split("/").pop()??o,60):null)}case"d360_sync_status":return n("Check sync status",null);default:return null}}function tn(e,t){if(e==="ToolSearch")return null;if(e.startsWith("mcp__")){let[,r="",...s]=e.split("__"),c=s.join("__");if(r==="document360"){let m=Ca(c,t);if(m)return m}let u=c.replace(/^d360_/,"").replace(/_/g," ");return{title:`${r==="document360"?"Document360":r.charAt(0).toUpperCase()+r.slice(1)}: ${u}`,sep:" ",arg:as(t)}}let n=ba[e],o=n?t[n]:void 0;return typeof o=="string"&&o?{title:e,sep:"",arg:re(o,cs)}:{title:e,sep:"",arg:as(t)}}function Pa(e){if(e===null||typeof e!="object")return typeof e=="string"?e:null;let t=e;for(let n of["name","title","slug","id"])if(typeof t[n]=="string"&&t[n])return t[n];return null}function Sa(e){if(!/^[[{]/.test(e))return null;let t;try{t=JSON.parse(e)}catch{return null}if(Array.isArray(t)){let n=t.map(Pa).filter(r=>r!==null),o=`${t.length} item${t.length===1?"":"s"}`;return n.length===0?[o]:[o,...n.map(r=>re(r,po))]}if(t!==null&&typeof t=="object"){let n=Object.entries(t).filter(([,o])=>o!==null&&(typeof o=="string"||typeof o=="number"||typeof o=="boolean")).slice(0,6).map(([o,r])=>`${o}: ${re(String(r),us)}`);return n.length>0?[re(n.join(" \xB7 "),po)]:null}return null}function Ta(e){let t=Ee(e)?.replace(/\\/g,"/");if(!t)return null;let n=t.split("/").filter(Boolean);return n.length>1?n.slice(1).join("/"):t}function Ra(e,t,n){switch(e){case"d360_create_article":{let o=Ta(t?.local_path);return[`\u2713 draft created${o?` \xB7 ${o}`:""}`]}case"d360_update_article":return["\u2713 draft updated"];case"d360_fork_article":return["\u2713 forked to a new draft"];case"d360_publish_article":return["\u2713 PUBLISHED LIVE \u2014 visible to readers"];case"d360_unpublish_article":return["\u2713 reverted to draft (removed from readers)"];case"d360_create_category":{let o=Ee(t?.name);return[`\u2713 category created${o?` \xB7 "${o}"`:""}`]}case"d360_upload_drive_file":{let o=n.match(/https?:\/\/\S+/);return[`\u2713 uploaded${o?` \xB7 ${re(o[0],120)}`:""}`]}default:return null}}function nn(e,t=4,n,o){let r=e.replace(/\r\n/g,`
|
|
64
|
+
`).trimEnd();if(!r)return{lines:["(no output)"],hidden:0};if(n?.startsWith("mcp__document360__")){let c=Ra(n.slice(18),o,r);if(c)return{lines:c,hidden:0}}let s=Sa(r)??r.split(`
|
|
65
|
+
`);return{lines:s.slice(0,t).map(c=>re(c,po)),hidden:Math.max(0,s.length-t)}}function on(e,t,n,o="en"){return`${e.replace(/\/$/,"")}/${t}/document/v1/${o}/${n}`}function rn(e,t){if(typeof e.article_id=="string"&&e.article_id)return e.article_id;try{let n=JSON.parse(t),r=(Array.isArray(n)?n[0]:n)?.id;return typeof r=="string"&&r?r:null}catch{return null}}function sn(e){try{let t=JSON.parse(e),o=(Array.isArray(t)?t[0]:t)?.url;return typeof o=="string"&&/^https?:\/\//.test(o)?o:null}catch{return null}}var Wa=/^mcp__document360__d360_(create_article|update_article|fork_article|publish_article)$/;function Fa(e,t,n,o){if(Wa.test(e))try{let r=ms(o),s=typeof t.project_id=="string"&&t.project_id||r.project.projectId,c=rn(t,n),u=sn(n);e.endsWith("publish_article")&&u&&console.log(R(` \u2B95 Live: ${u}`)),c&&s&&console.log(R(` \u2B95 Preview: ${on(r.connection.portalUrl,s,c,r.project.languageCode??"en")}`))}catch{}}async function gs(e=process.cwd(),t="auto",n){let o=ja(t);o.kind==="none"&&(console.error(""),console.error(x("ANTHROPIC_API_KEY is not set (required for --auth api).")),console.error(""),console.error(` ${R("export ANTHROPIC_API_KEY=sk-ant-...")} (macOS / Linux)`),console.error(` ${R('$env:ANTHROPIC_API_KEY="sk-ant-..."')} (PowerShell)`),console.error(""),console.error(`Get a key at ${R("https://console.anthropic.com/settings/keys")}`),console.error(`Or use your Claude subscription instead: ${R("d360-writer --auth subscription")}`),console.error(""),process.exit(2)),Ha(e,n),o.kind==="subscription"&&(o.stored?console.log(f(" Using your Claude subscription (no API key set).")):console.log(f(" No API key or stored Claude Code login found \u2014 trying your Claude session anyway.")),console.log(""));let r=!1,s=fo({cwd:e,profileName:n,allowProdWrites:r}),c={uuid:null,firstPrompt:null,titleFired:!1},u=Aa({input:process.stdin,output:process.stdout}),g=[],m=null,w=!1;u.on("line",v=>{if(m){let $=m;m=null,$(v)}else g.push(v)}),u.on("close",()=>{if(w=!0,m){let v=m;m=null,v(null)}});function j(){return g.length>0?Promise.resolve(g.shift()):w?Promise.resolve(null):(process.stdout.write(R("> ")),new Promise(v=>{m=v}))}let b={cwd:e,profileName:n,allowProdWrites:()=>r,restartAgent:()=>{s.close(),s=fo({cwd:e,profileName:n,allowProdWrites:r}),c={uuid:null,firstPrompt:null,titleFired:!1}},currentUuid:()=>c.uuid,setModel:async v=>s.setModel(v),withPausedInput:async v=>{u.pause();try{return await v()}finally{u.resume()}}};try{for(;;){let v=await j();if(v===null)break;let $=v.trim();if($){if($.startsWith("/")){let E=ls($);if(!E)continue;let q=is[E.name];if(!q){console.log(x(`Unknown command: /${E.name}`)),console.log(f("Type /help for the list."));continue}let G=await q(E.args,b);if(G.kind==="exit")break;if(G.kind==="clear"){b.restartAgent();continue}if(G.kind==="allow-prod"){r=!0,b.restartAgent(),console.log(D("\u2713 Production writes authorized for this session.")),console.log("");continue}if(G.kind==="resume"){s.close(),s=fo({cwd:e,resume:G.uuid,profileName:n,allowProdWrites:r});let ie=Ea(G.uuid);c={uuid:G.uuid,firstPrompt:ie?.firstPrompt??null,titleFired:!0},fs(G.uuid),console.log(D(`\u2713 Resumed "${G.name}"`)),console.log("");continue}G.kind==="forward-to-agent"&&(c.firstPrompt||(c.firstPrompt=G.display??G.prompt),await ps(s,G.prompt,o,c,e));continue}c.firstPrompt||(c.firstPrompt=$),await ps(s,$,o,c,e)}}}finally{s.close(),u.close()}}function Ha(e,t){console.log(""),console.log(pt("document360-writer")),console.log(f(` cwd: ${e}`));let n=Na(e);console.log(f(` model: ${n.model??"auto (engine right-sizes per task)"}${n.model?` (${n.source})`:""}`)),console.log(Ba(e,t)),La(e)||console.log(L(" First run: /init \u2192 /login \u2192 /workspace, then ask for a docs analysis.")),console.log(f(" Type a prompt, or /help for slash commands. /exit to quit.")),console.log("")}function Ba(e,t){try{let n=ms(e,t),o=n.production?L(" \u26A0 PRODUCTION"):"",r=Ua(n.name);if(!r)return f(` Document360: profile "${n.name}"${o} \u2014 not logged in (d360-writer login)`);let s={...ds(r.idToken)??{},...ds(r.accessToken)??{}},c=s.email??s.preferred_username??"signed in";return Oa(r)&&!r.refreshToken?L(` Document360: profile "${n.name}"${o} \u2014 session expired (d360-writer login)`):f(` Document360: ${c} \xB7 profile "${n.name}"${o}`)}catch(n){return f(` Document360: ${n.message.split(".")[0]}`)}}function qa(){console.error(""),console.error(`Sign in with your Claude subscription: run ${R("claude")} once, then retry.`),console.error(` (No Claude Code? ${R("npm install -g @anthropic-ai/claude-code")})`),console.error(`Or set an API key: ${R("https://console.anthropic.com/settings/keys")}`)}function za(e,t,n){e.uuid=t;let o=new Date().toISOString();_a({uuid:t,name:Ia(e.firstPrompt??"session"),renamed:!1,titled:!1,cwd:n,firstPrompt:e.firstPrompt??"",createdAt:o,updatedAt:o})}function Ga(e,t){e.titleFired=!0;let n=e.uuid,o=e.firstPrompt;!n||!o||Ma(o,t).then(r=>{r&&Da(n,r)}).catch(()=>{})}async function ps(e,t,n,o,r){let s=new Map;for await(let c of e.send(t))Ya(c,o,r,n,s)}function Ya(e,t,n,o,r){switch(e.type){case"session":t.uuid||za(t,e.sessionId,n);break;case"text":process.stdout.write(e.delta);break;case"tool":{let s=tn(e.name,e.input);s&&(process.stdout.write(`
|
|
66
66
|
|
|
67
|
-
`),console.log(`${D("\u25CF")} ${ve(s.title)}${s.arg!==null?Q(`${s.sep}(${s.arg})`):""}`),r.set(e.id,{name:e.name,input:e.input}));break}case"article_diff":{let s=We(e.oldContent,e.newContent,Math.max(40,(process.stdout.columns??80)-1));if(!s)break;let c=u=>u===1?"":"s";console.log(Q(` \u23BF Added ${s.added} line${c(s.added)}, removed ${s.removed} line${c(s.removed)}`));for(let u of s.lines)console.log(u);s.hidden>0&&console.log(f(` \u2026 +${s.hidden} more diff lines`));break}case"tool_result":{let s=r.get(e.id);if(!s)break;r.delete(e.id);let c=
|
|
68
|
-
`),console.log(f(` (${e.inputTokens}\u2192${e.outputTokens} tokens`+(e.costUsd>0?`, $${e.costUsd<.01?e.costUsd.toFixed(4):e.costUsd.toFixed(2)}`:"")+")")),console.log(""),t.uuid&&(fs(t.uuid),t.titleFired||
|
|
69
|
-
`)){let c=s.trim().replace(
|
|
67
|
+
`),console.log(`${D("\u25CF")} ${ve(s.title)}${s.arg!==null?Q(`${s.sep}(${s.arg})`):""}`),r.set(e.id,{name:e.name,input:e.input}));break}case"article_diff":{let s=We(e.oldContent,e.newContent,Math.max(40,(process.stdout.columns??80)-1));if(!s)break;let c=u=>u===1?"":"s";console.log(Q(` \u23BF Added ${s.added} line${c(s.added)}, removed ${s.removed} line${c(s.removed)}`));for(let u of s.lines)console.log(u);s.hidden>0&&console.log(f(` \u2026 +${s.hidden} more diff lines`));break}case"tool_result":{let s=r.get(e.id);if(!s)break;r.delete(e.id);let c=nn(e.output,4,e.isError?void 0:s.name,s.input),u=e.isError?x:Q;c.lines.forEach((g,m)=>console.log(u((m===0?" \u23BF ":" ")+g))),c.hidden>0&&console.log(f(` \u2026 +${c.hidden} lines`)),e.isError||Fa(s.name,s.input,e.output,n);break}case"result":process.stdout.write(`
|
|
68
|
+
`),console.log(f(` (${e.inputTokens}\u2192${e.outputTokens} tokens`+(e.costUsd>0?`, $${e.costUsd<.01?e.costUsd.toFixed(4):e.costUsd.toFixed(2)}`:"")+")")),console.log(""),t.uuid&&(fs(t.uuid),t.titleFired||Ga(t,n));break;case"error":console.error(""),console.error(x(`agent error: ${e.message}`)),o.kind==="subscription"&&e.kind==="auth"&&qa();break}}import{render as Wc}from"ink";import{resolveAuth as Fc}from"document360-engine";import{useCallback as X,useEffect as Ie,useMemo as dn,useRef as V,useState as W}from"react";import{Box as J,Text as P,useApp as oc,useInput as rc,useStdout as sc}from"ink";import{existsSync as Es,readFileSync as Ds,readdirSync as Hs}from"node:fs";import{basename as pn,isAbsolute as ic,join as vt}from"node:path";import{createSession as Is,loginPkce as lc,toStoredTokens as ac,saveTokens as cc,getAccessToken as uc,resolveActiveProfile as he,resolveProjectId as dc,getArticle as pc,decodeJwtClaims as ot,isExpired as De,loadTokens as Fe,setTitle as fc,slugify as mc,touchSession as ho,upsertSession as gc,generateTitle as _s,findByName as hc,listSessions as kc,renameSession as yc,suggestNextAction as wc,readProjectConfig as se,writeProjectConfig as $c,resolveModelSetting as xo,loadProfileMap as Ms,applyPull as xc,computeSyncStatus as ko,planPull as bc,inventoryRepo as vc,knownEnvironments as Cc,resolveEnvironment as Pc,planPartitions as Ns,partitionEvenly as Sc,screenshotPlaceholderIds as Tc,trackedArticlePaths as Rc,runPartitioned as yo,estimateBulkCost as Ls,resolveModelForOperation as wo,readDocsPlan as Ac}from"document360-engine";import{existsSync as Xa,mkdirSync as Va,readFileSync as Ja,writeFileSync as Ka}from"node:fs";import{join as hs}from"node:path";import{writerDir as Qa}from"document360-engine";function ks(e){return hs(Qa(e),".sessions")}function ys(e,t){return hs(ks(e),`${t}.json`)}function ws(e,t,n){try{Va(ks(e),{recursive:!0});let o=n.filter(r=>r.kind!=="banner");Ka(ys(e,t),JSON.stringify({v:1,items:o}),"utf8")}catch{}}function mo(e,t){try{let n=ys(e,t);if(!Xa(n))return[];let o=JSON.parse(Ja(n,"utf8"));return Array.isArray(o.items)?o.items:[]}catch{return[]}}var Za=e=>`\x1B]0;${e}\x07`,ec=e=>`\x1B]9;4;${e};${e===1?100:0}\x07`;function $s(e){process.stdout.isTTY&&process.stdout.write(e)}function bt(e){$s(Za(e))}function ln(e){$s(ec(e))}var an=["\xB7 "," \xB7"],go="\u{1F7E3}";Zt();var tc=/^(?:\d+[.)]|[-*•])\s+/;function xs(e,t,n=4){let o=new Set(t.map(s=>s.toLowerCase())),r=[];for(let s of e.split(`
|
|
69
|
+
`)){let c=s.trim().replace(tc,""),u=c.match(/^`([^`]+)`$/);u&&(c=u[1].trim());let g=c.match(/^\/([a-z?][a-z0-9-]*)(?:\s+(\S.*?))?\s*$/i);if(!g||!o.has(g[1].toLowerCase()))continue;let m=`/${g[1].toLowerCase()}${g[2]?` ${g[2]}`:""}`;if(r.includes(m)||r.push(m),r.length>=n)break}return r}H();var nc=/\[Pasted text #\d+ \+\d+ lines?\]/g;function bs(e){return e.replace(/\r\n?/g,`
|
|
70
70
|
`)}function vs(e){return e.includes(`
|
|
71
71
|
`)||e.length>200}function Cs(e,t){let n=t.split(`
|
|
72
|
-
`).length;return`[Pasted text #${e} +${n} line${n===1?"":"s"}]`}function Ps(e,t){return e.replace(
|
|
73
|
-
`)){if(s.length===0)o.push({start:r,end:r});else for(let c=0;c<s.length;c+=n)o.push({start:r+c,end:r+Math.min(c+n,s.length)});r+=s.length+1}return o.length>0?o:[{start:0,end:0}]}function
|
|
72
|
+
`).length;return`[Pasted text #${e} +${n} line${n===1?"":"s"}]`}function Ps(e,t){return e.replace(nc,n=>t.get(n)??n)}function Ss(e){let t=e.match(/\[Pasted text #\d+ \+\d+ lines?\]$/);return t?e.slice(0,-t[0].length):null}function cn(e,t){let n=Math.max(1,t),o=[],r=0;for(let s of e.split(`
|
|
73
|
+
`)){if(s.length===0)o.push({start:r,end:r});else for(let c=0;c<s.length;c+=n)o.push({start:r+c,end:r+Math.min(c+n,s.length)});r+=s.length+1}return o.length>0?o:[{start:0,end:0}]}function un(e,t){let n=0;for(let o=0;o<e.length&&e[o].start<=t;o++)n=o;return n}function Ts(e,t,n){let o=un(e,t),r=o+n;if(r<0||r>=e.length)return t;let s=Math.min(t,e[o].end)-e[o].start;return Math.min(e[r].start+s,e[r].end)}function Rs(e,t,n){let o=e[un(e,t)];return n==="start"?o.start:o.end}function As(e,t,n){let o=Math.max(1,n),r=e.split(`
|
|
74
74
|
`),s=0;for(let c=r.length-1;c>=0;c--){let u=r[c];if(s+=Math.max(1,Math.ceil(u.length/o)),s>=t){let g=s-t;return{text:[g>0?u.slice(g*o):u,...r.slice(c+1)].join(`
|
|
75
75
|
`),truncated:c>0||g>0}}}return{text:e,truncated:!1}}function js(e){let t=!1,n=0,o=0;for(let r of e.split(`
|
|
76
|
-
`)){let s=o+r.length;/^\s*```/.test(r)?t=!t:!t&&r.trim()===""&&s<e.length&&(n=s+1),o=s+1}return n}import{Fragment as $o,jsx as S,jsxs as F}from"react/jsx-runtime";var
|
|
77
|
-
1. /init \u2014 pick your Document360 environment & scaffold config
|
|
76
|
+
`)){let s=o+r.length;/^\s*```/.test(r)?t=!t:!t&&r.trim()===""&&s<e.length&&(n=s+1),o=s+1}return n}import{Fragment as $o,jsx as S,jsxs as F}from"react/jsx-runtime";var jc={project:".d360-writer.json",user:"/model",env:"ANTHROPIC_MODEL","claude-settings":"Claude Code settings","claude-default":""},Os=` 1. /init \u2014 pick your Document360 environment & scaffold config
|
|
78
77
|
2. /login signs in to that environment
|
|
79
78
|
3. /workspace picks where articles go
|
|
80
|
-
Press 1 to start
|
|
81
|
-
`
|
|
79
|
+
Press 1 to start.`;function Ec(e,t,n,o){let r=n.kind==="api"?"API key":n.kind==="subscription"?"subscription":"not configured",s=xo(e),c=se(e),u=(c?.docsDir??"user-docs").replace(/\/+$/,""),g=c?.mode==="engineer"?"engineer \xB7 full source access (dogfooding)":`writer \xB7 edits limited to ${u}/ + config`,m={version:t,claude:r,model:s.model??"Claude Code default model",modelSource:jc[s.source],who:null,sessionHint:null,profile:"\u2014",apiUrl:"\u2014",project:"\u2014",cwd:e,prod:!1,loggedOut:!0,configured:c!==null,mode:g};if(c===null)return m;try{let w=he(e,o);m.profile=w.name,m.apiUrl=w.connection.apiUrl,m.prod=w.production,m.project=w.project.projectId??"(chosen at login)";let j=Fe(w.name);if(j){let b={...ot(j.idToken)??{},...ot(j.accessToken)??{}},v=b.email??b.preferred_username??"signed in";De(j)?j.refreshToken&&(m.who=v,m.loggedOut=!1,m.sessionHint="session expired \u2014 refreshing\u2026"):(m.who=v,m.loggedOut=!1,m.sessionHint=`session valid until ${new Date(j.expiresAt).toLocaleString(void 0,{hour:"2-digit",minute:"2-digit",day:"2-digit",month:"short"})}`)}}catch{}return m}function Dc(e,t){try{let n=he(e,t),o=Fe(n.name);if(!o)return{text:`profile "${n.name}" \u2014 not logged in (/login)`,prod:n.production};let r={...ot(o.idToken)??{},...ot(o.accessToken)??{}},s=r.email??r.preferred_username??"signed in";return De(o)&&!o.refreshToken?{text:`profile "${n.name}" \u2014 session expired (/login)`,prod:n.production}:{text:`${s} \xB7 profile "${n.name}"`,prod:n.production}}catch(n){return{text:n.message.split(".")[0],prod:!1}}}var Us=["Drafting","Composing","Outlining","Researching","Documenting","Structuring","Polishing","Synthesizing","Curating","Distilling","Weaving","Wrangling","Pondering"],mn=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"],Ic="Ask me to write or update an article\u2026";function fn({ch:e,dim:t}){let[n,o]=W(!0);return Ie(()=>{let r=setInterval(()=>o(s=>!s),530);return()=>clearInterval(r)},[]),S(P,{inverse:n,color:t&&!n?"gray":void 0,children:e})}var _c=/^mcp__document360__d360_(create_article|update_article|fork_article|publish_article)$/;function Ws(e){let t=e.match(/^---\r?\n[\s\S]*?\r?\n---\r?\n/);return t?e.slice(t[0].length):e}var Mc=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function Fs(e){try{return Hs(e,{withFileTypes:!0}).filter(t=>t.isDirectory()&&!t.name.startsWith(".")).length>6}catch{return!1}}function Nc(e,t){let n=t??[];return n.length===0?["src","api","services","packages","modules"].some(o=>Fs(vt(e,o))):n.some(o=>!o.includes("/")&&!o.endsWith(".md")&&Fs(vt(e,o)))}function Lc({startTime:e,chars:t}){let[n,o]=W(0);Ie(()=>{let g=setInterval(()=>o(m=>m+1),120);return()=>clearInterval(g)},[]);let r=mn[n%mn.length],s=Us[Math.floor(n/16)%Us.length],c=Math.floor((Date.now()-e)/1e3),u=Math.round(t/4);return F(J,{children:[S(P,{color:z,children:` ${r} ${s}\u2026 `}),S(P,{color:"gray",children:`(${yt(c)} \xB7 ~${u} tokens \xB7 esc to interrupt)`})]})}var Oc=12e4;function Uc({p:e}){let[t,n]=W(0);Ie(()=>{let g=setInterval(()=>n(m=>m+1),150);return()=>clearInterval(g)},[]);let o=mn[t%mn.length],r=Math.floor((Date.now()-e.startedAt)/1e3),s=Math.floor((Date.now()-e.lastAt)/1e3),c=Math.round(e.chars/4),u=Date.now()-e.lastAt>=Oc;return F(J,{flexDirection:"column",children:[F(J,{children:[S(P,{color:z,children:` ${o} ${e.verb??"Converting"} `}),S(P,{color:"gray",children:`${e.done}/${e.total} \xB7 ${e.tools} tool call${e.tools===1?"":"s"} \xB7 ~${c} tokens \xB7 ${yt(r)} \xB7 esc to stop`})]}),e.active.length>0&&S(P,{dimColor:!0,children:` \u25B8 ${e.active.join(", ")} \xB7 last activity ${s}s ago`}),u&&S(P,{color:"yellow",children:` \u26A0 no activity for ${yt(s)} \u2014 press esc to stop if it's wedged`})]})}function Bs({cwd:e,auth:t,profileName:n,version:o}){let{exit:r}=oc(),[s,c]=W(n),[u,g]=W(null),[m,w]=W({text:"",pos:0}),j=m.text,b=X(a=>{w(l=>{let i=typeof a=="function"?a(l.text):a;return{text:i,pos:i.length}})},[]),v=X(a=>{w(l=>({text:l.text.slice(0,l.pos)+a+l.text.slice(l.pos),pos:l.pos+a.length}))},[]),$=X(()=>{w(a=>{if(a.pos===0)return a;let l=a.text.slice(0,a.pos),i=Ss(l)??l.slice(0,-1);return{text:i+a.text.slice(a.pos),pos:i.length}})},[]),[E,q]=W(!1),[G,ie]=W(!1),[de,Pe]=W(0),[pe,fe]=W(null),[rt,K]=W([]),Ct=V(0),[Ys,Pt]=W(!1),[Xs,st]=W(0),He=V(0),[it,Be]=W(0),[qe,St]=W(null),Co=V(new Map),Vs=V(0),ze=V([]),le=V(null);le.current===null&&(le.current=Is({cwd:e,profileName:s,allowProdWrites:!1}));let ke=V({uuid:null,firstPrompt:null,titleFired:!1}),Tt=V(new Map),lt=V(!1),gn=V([]),Se=V([]),hn=V(null),[Po,Ge]=W(null),[_e,Me]=W(null),[ye,Ye]=W(null),[Te,Xe]=W(null),[ne,Ve]=W(null),[we,Je]=W(null),[ae,Ne]=W(null),[oe,Ke]=W(null),[So,kn]=W([]),Le=V([]),Rt=V(!1),$e=V(null),[To,Z]=W(null),At=V(!1),jt=V(null),[ce,Oe]=W(null),[Ro,at]=W(0),[Ao,ct]=W(0),[Js,jo]=W(0),yn=dn(()=>{try{return xo(e).model??"auto"}catch{return null}},[e,Js]),{stdout:me}=sc(),[,Ks]=W(0),Eo=V(`${me.columns??80}x${me.rows??24}`),Re=X(()=>Math.max(20,(me.columns??80)-1),[me]),d=X(a=>{ze.current.push(a),console.log(On(a,Re()))},[Re]);Ie(()=>{let a=`d360-writer \xB7 ${Po??pn(e)}`;if(!E){ln(0),bt(`${go} ${a}`);return}ln(3);let l=0;bt(`${an[0]} ${a}`);let i=setInterval(()=>{l=(l+1)%an.length,bt(`${an[l]} ${a}`)},400);return()=>clearInterval(i)},[E,e,Po]),Ie(()=>()=>ln(0),[]),Ie(()=>{if(d({kind:"banner",info:Ec(e,o,t,s)}),!se(e)){d({kind:"note",tone:"info",text:`Welcome! This repo isn't set up for d360-writer yet \u2014 three steps and you're writing docs:
|
|
80
|
+
${Os}`}),K(["/init"]);return}try{let a=he(e,s),l=Fe(a.name);l&&De(l)&&l.refreshToken?uc({profile:a.name,connection:a.connection}).then(()=>{d({kind:"note",tone:"ok",text:"\u2713 Document360 session refreshed."}),Pe(i=>i+1)}).catch(()=>{d({kind:"note",tone:"warn",text:"Document360 session refresh failed \u2014 do you want to log in now? (press 1)"}),K(["/login"])}):(!l||De(l))&&(d({kind:"note",tone:"warn",text:`Profile "${a.name}" is not signed in \u2014 do you want to log in now? (press 1)`}),K(["/login"]))}catch{}try{let a=se(e),l=he(e,s),i=Fe(l.name);a&&i&&!De(i)&&Nc(e,a.authoritativeSourceFiles)&&(d({kind:"note",tone:"info",text:"Large repo \u2014 the docs scope isn\u2019t set yet. Run /scope to choose which folders back your docs."}),K(["/scope"]))}catch{}},[]),Ie(()=>{let a=null,l=null,i=()=>{a&&clearTimeout(a),a=setTimeout(()=>{a=null;let h=`${me.columns??80}x${me.rows??24}`;h!==Eo.current&&(Eo.current=h,Ks(p=>p+1),l&&clearTimeout(l),l=setTimeout(()=>{l=null,console.log("\x1B[?2026h\x1B[H\x1B[2J"+Er(ze.current,Re())+"\x1B[?2026l")},80))},400)};return me.on("resize",i),()=>{a&&clearTimeout(a),l&&clearTimeout(l),me.off("resize",i)}},[me,Re]);let Ue=Math.max(20,(me.columns??80)-1),Do=dn(()=>Dc(e,s),[e,s,de]),wn=dn(()=>{let a=se(e);if(!a)return{text:"Press 1 to set up this repo, or /help\u2026",isSetup:!0};try{let h=he(e,s),p=Fe(h.name);if(!(!!p&&!(De(p)&&!p.refreshToken)))return{text:`Press 1 to sign in to Document360 (profile "${h.name}")\u2026`,isSetup:!0};if(!h.project.workspaceId)return{text:"Press 1 to pick a workspace\u2026",isSetup:!0}}catch{}let l=vt(e,(a.docsDir??"user-docs").replace(/\/+$/,""));return(()=>{try{return Es(l)&&Hs(l).length>0}catch{return!1}})()?{text:Ic,isSetup:!1}:{text:"Let's get started \u2014 try: write the docs for this repo",isSetup:!1}},[e,s,de]),ut=tr(j),Io=ut.length>0&&!E,$n=u!==null?As(u,8,Ue):null,Et=ae?ae.paths.filter(a=>!ae.query||a.toLowerCase().includes(ae.query.toLowerCase())).slice(0,8):[],Dt=ce?ce.sessions.filter(a=>{let l=ce.query.toLowerCase();return!l||a.name.toLowerCase().includes(l)||a.firstPrompt.toLowerCase().includes(l)}).slice(0,8):[],xe=X((a,l)=>{le.current?.close(),le.current=Is({cwd:e,resume:a,profileName:l??s,allowProdWrites:lt.current}),a||(ke.current={uuid:null,firstPrompt:null,titleFired:!1},Ge(null)),at(0),ct(0)},[e,s]),_o=X((a,l,i)=>{if(_c.test(a))try{let h=he(e,s),p=typeof l.project_id=="string"&&l.project_id||h.project.projectId,k=rn(l,i),y=[],I=sn(i);a.endsWith("publish_article")&&I&&y.push(`Live: ${I}`),k&&p&&y.push(`Preview: ${on(h.connection.portalUrl,p,k,h.project.languageCode??"en")}`),y.length>0&&d({kind:"link",lines:y})}catch{}},[e,s,d]),be=X(async(a,l)=>{Pt(!0),fe(null),K([]);let i=++Ct.current;d({kind:"user",text:l?.echoDisplay&&l.display?l.display:a});let h=ke.current;h.firstPrompt||(h.firstPrompt=l?.display??a),He.current=Date.now(),st(0),q(!0),Tt.current.clear();let p="",k="",y=null,I=()=>{y||(y=setTimeout(()=>{y=null,g(k.length>0?k:null)},60))},M=()=>{y&&clearTimeout(y),y=null,g(null)},N=()=>{if(k.trim()){let A=k.trimEnd();d({kind:"assistant",text:A})}k="",M()};try{for await(let A of le.current.send(a))if(A.type==="session"){if(!h.uuid){h.uuid=A.sessionId;let _=new Date().toISOString(),C=mc(h.firstPrompt??"session");gc({uuid:A.sessionId,name:C,renamed:!1,titled:!1,cwd:e,firstPrompt:h.firstPrompt??"",createdAt:_,updatedAt:_}),Ge(C)}}else if(A.type==="text"){k+=A.delta,p+=A.delta;let _=js(k);if(_>0){let C=k.slice(0,_).trimEnd();C&&d({kind:"assistant",text:C}),k=k.slice(_)}I(),st(C=>C+A.delta.length)}else if(A.type==="tool"){let _=tn(A.name,A.input);_&&(N(),d({kind:"tool",title:_.title,sep:_.sep,arg:_.arg}),Tt.current.set(A.id,{name:A.name,input:A.input}))}else if(A.type==="article_diff"){let _=We(A.oldContent,A.newContent,Re());_&&(N(),d({kind:"diff",added:_.added,removed:_.removed,lines:_.lines,hidden:_.hidden}))}else if(A.type==="tool_result"){A.isError&&/run \/login|not logged in|session expired|rejected the token/i.test(A.output)&&(At.current=!0);let _=Tt.current.get(A.id);if(_){Tt.current.delete(A.id),N();let C=nn(A.output,4,A.isError?void 0:_.name,_.input);d({kind:"tool-result",lines:C.lines,hidden:C.hidden,isError:A.isError}),A.isError||_o(_.name,_.input,A.output)}}else if(A.type==="result"){N(),at(C=>C+A.outputTokens),ct(C=>C+A.costUsd),d({kind:"done",seconds:Math.round((Date.now()-He.current)/1e3),tokens:A.outputTokens,costUsd:A.costUsd,ok:A.ok});let _=A.ok?xs(p,mt.map(C=>C.name)):[];if(_.length>0?K(_):A.ok&&p.trim()&&wc(a,p,e).then(C=>{C&&Ct.current===i&&fe(C)}).catch(()=>{}),h.uuid&&(ho(h.uuid),!h.titleFired)){h.titleFired=!0;let C=h.uuid,T=h.firstPrompt;T&&_s(T,e).then(U=>{U&&(fc(C,U),Ge(U))}).catch(()=>{})}}else A.type==="error"&&(N(),A.kind==="auth"&&(At.current=!0),d({kind:"note",text:`agent error: ${A.message}`,tone:"error"}))}finally{q(!1),M(),ke.current.uuid&&ws(e,ke.current.uuid,ze.current),At.current&&(At.current=!1,jt.current=l?.display??a,K(["/login"])),Rt.current&&(Rt.current=!1,Le.current.length>0&&(d({kind:"note",tone:"info",text:`(${Le.current.length} queued message(s) discarded)`}),Le.current=[],kn([])),d({kind:"note",tone:"warn",text:"Interrupted. What do you want to do next?"}))}},[e,d,_o,Re]),xn=X(a=>{let l=Fe(a);if(!l||De(l)&&!l.refreshToken)return null;let i={...ot(l.idToken)??{},...ot(l.accessToken)??{}};return i.email??i.preferred_username??"signed in"},[]),bn=X((a,l)=>{if(l){let i=se(e);i&&(i.defaultProfile=a,$c(i,e))}c(a),xe(void 0,a),d({kind:"note",tone:"ok",text:`\u2713 Switched to profile "${a}"${l?" (saved as default)":" (this session only)"} \u2014 agent restarted.`}),xn(a)||(d({kind:"note",tone:"warn",text:`Profile "${a}" is not signed in \u2014 do you want to log in now? (press 1)`}),K(["/login"])),Pe(i=>i+1)},[e,d,xe,xn]),Mo=X((a,l,i)=>{Lt(e,a,l,i.id,i.name),d({kind:"note",tone:"ok",text:`Switched to workspace "${i.name??i.id}" (agent restarted).`}),xe(),Ms(e,a)||(d({kind:"note",tone:"info",text:"Setup complete. Press tab to start with a docs analysis."}),fe("analyze this repo and propose a docs structure"))},[e,d,xe]),It=X(()=>{let a=Se.current[0];if(!a)return;d({kind:"note",tone:"info",text:`\u25CF ${a.title} (${a.path})`});for(let i of a.notes)d({kind:"note",tone:"warn",text:`\u26A0 ${i}`});a.overwritesLocalChanges&&d({kind:"note",tone:"warn",text:"\u26A0 This OVERWRITES local edits made since the last sync."});let l=We(a.oldContent,a.newContent,Re());d(l?{kind:"diff",added:l.added,removed:l.removed,lines:l.lines,hidden:l.hidden}:{kind:"note",tone:"info",text:"Local file already matches the remote content \u2014 applying only advances the sync base."}),d({kind:"note",tone:"info",text:`Write ${a.path}? (y/n \u2014 anything else cancels)`})},[d,Re]),No=X(a=>{if(Se.current.length===0)return!1;let l=a.trim().toLowerCase();if(l==="y"||l==="yes"){let i=Se.current.shift();try{xc({cwd:e,profileName:s},i),d({kind:"note",tone:"ok",text:`\u2713 Pulled ${i.path} (sync base advanced).`}),Se.current.length===0&&K(h=>h.length>0?h:["/sync"])}catch(h){d({kind:"note",tone:"error",text:`Pull failed: ${h.message}`})}}else if(l==="n"||l==="no"){let i=Se.current.shift();d({kind:"note",tone:"info",text:`Skipped ${i.path}.`})}else{let i=Se.current.length;return Se.current=[],d({kind:"note",tone:"info",text:`Pull cancelled (${i} article(s) left untouched).`}),!0}return It(),!0},[e,s,It,d]),Lo=X(a=>{let l=hn.current;if(!l)return!1;if(hn.current=null,a.trim()!==l.repoName)return d({kind:"note",tone:"warn",text:"Reset cancelled \u2014 nothing deleted."}),!0;let{removed:i,failed:h}=ao(e,l.targets);d({kind:"note",tone:h.length?"warn":"ok",text:`\u2713 Reset complete \u2014 removed ${i.length} item${i.length===1?"":"s"}. The repo is back to its original state.`});for(let p of h)d({kind:"note",tone:"error",text:` \u2717 ${p.path}: ${p.error}`});return d({kind:"note",tone:"info",text:`Clean slate \u2014 set up d360-writer again whenever you're ready:
|
|
81
|
+
${Os}`}),K(["/init"]),Pt(!1),!0},[e,d]),Oo=X(async a=>{let l=a.slice(1).trim().split(/\s+/),i=(l[0]??"").toLowerCase(),h=l.slice(1);switch(Pt(!0),i){case"help":d({kind:"note",tone:"info",text:qt().join(`
|
|
82
|
+
`)});return;case"exit":case"quit":le.current?.close(),r();return;case"clear":xe(),ze.current=[],Pt(!1),fe(null),Ct.current++,d({kind:"note",tone:"info",text:"Conversation reset (the previous session is still resumable via /resume)."});return;case"login":{let p;try{p=he(e,s)}catch(k){d({kind:"note",tone:"error",text:k.message});return}d({kind:"note",tone:"info",text:`Profile "${p.name}" \u2192 ${p.connection.name} (${p.connection.apiUrl})${p.production?" \u26A0 PRODUCTION":""}`}),ie(!0);try{let k=await lc(p.connection,{promptForRedirect:()=>Promise.reject(new Error("Manual login is CLI-only. Run: d360-writer login --manual"))},I=>d({kind:"note",tone:"info",text:I})),y=ac(p.name,k);cc(y),Sn(y,p.name,I=>d({kind:"note",tone:"info",text:I})),d({kind:"note",tone:"ok",text:`\u2713 Logged in to "${p.name}" as ${Ut(y)}`}),p.project.workspaceId||(d({kind:"note",tone:"info",text:"Next: pick the workspace your articles publish to."}),K(["/workspace"])),jt.current&&(fe(jt.current),jt.current=null,d({kind:"note",tone:"info",text:"Press tab to re-send your last prompt."}))}catch(k){d({kind:"note",tone:"error",text:`Login failed: ${k.message}`})}finally{ie(!1),Pe(k=>k+1)}return}case"allow-prod":{let p=!1;try{p=he(e,s).production}catch{}if(!p){d({kind:"note",tone:"info",text:"Current profile is not production \u2014 writes are already allowed."});return}lt.current=!0,xe(),d({kind:"note",tone:"warn",text:"\u26A0 Production writes authorized for this session."});return}case"rename":{let p=Zn(h.join(" ")),k=ke.current.uuid;if(!k){d({kind:"note",tone:"error",text:"Send a message first \u2014 sessions save once the agent replies."});return}if(!p){d({kind:"note",tone:"info",text:"Thinking of a name\u2026"});let y=ke.current.firstPrompt??"";_s(y,e).then(I=>{I?(fe(`/rename ${I}`),d({kind:"note",tone:"info",text:`Suggestion: "${I}" \u2014 press tab to accept, or type /rename <your name>.`})):d({kind:"note",tone:"info",text:"Usage: /rename <name>"})}).catch(()=>d({kind:"note",tone:"info",text:"Usage: /rename <name>"}));return}yc(k,p),Ge(p),bt(`${go} d360-writer \xB7 ${p}`),d({kind:"note",tone:"ok",text:`Session renamed to "${p}".`});return}case"profile":{let p=h[0],k=se(e);if(!p){let y=Object.entries(k?.profiles??{});if(y.length===0){d({kind:"note",tone:"info",text:"No profiles. Run /init first."});return}let I=y.map(([A,_])=>({name:A,env:_.connection?.environment??"custom",prod:_.production===!0,who:xn(A)})),M=s??k?.defaultProfile,N=Math.max(0,I.findIndex(A=>A.name===M));Ye({cursor:N,current:N,rows:I});return}if(p==="add"){let y=eo(e,h[1],h[2]);if(y){d({kind:"note",tone:"error",text:y});return}d({kind:"note",tone:"ok",text:`\u2713 Profile "${h[1]}" created (environment: ${h[2]??h[1]}).`}),bn(h[1],!1);return}if(!k?.profiles?.[p]){d({kind:"note",tone:"error",text:`Unknown profile "${p}". Create it: /profile add ${p} <environment>`});return}bn(p,!0);return}case"doctor":await $t(h,{cwd:e});return;case"mcp":await Gt(h);return;case"init":{if(se(e)){d({kind:"note",tone:"info",text:"This repo is already set up \u2014 edit .d360-writer.json directly (or d360-writer init for the CLI wizard)."});return}let p=Cc().map(k=>({name:k,apiUrl:Pc(k).apiUrl}));Xe({cursor:0,rows:p});return}case"resume":{let p=h.join(" ").trim(),k=kc(e).filter(M=>M.uuid!==ke.current.uuid);if(!p){if(!k.length){d({kind:"note",tone:"info",text:"No saved sessions for this repo yet."});return}Oe({query:"",cursor:0,sessions:k});return}let y=hc(e,p);if(!y){d({kind:"note",tone:"error",text:`No session matches "${p}".`});return}xe(y.uuid),ke.current={uuid:y.uuid,firstPrompt:y.firstPrompt,titleFired:!0},Ge(y.name),ho(y.uuid),ze.current=[];let I=mo(e,y.uuid);for(let M of I)d(M);d({kind:"note",tone:"ok",text:I.length?`Resumed "${y.name}" \u2014 restored ${I.length} message(s); continue where you left off.`:`Resumed "${y.name}" (agent memory reconnected; no saved transcript to replay).`});return}case"workspace":{let p=h.join(" ").trim(),k;try{k=await Nt(e,s)}catch(I){d({kind:"note",tone:"error",text:`Could not list workspaces: ${I.message}`});return}if(!p){let I=k.workspaces.map(N=>({id:N.id,name:N.name??N.id,type:N.workspace_type}));if(I.length===0){d({kind:"note",tone:"info",text:"No workspaces in this project."});return}let M=Math.max(0,I.findIndex(N=>N.id===k.current));Ve({cursor:M,current:M,rows:I,profile:k.profile,projectId:k.projectId,environment:k.environment});return}let y=Pn(k.workspaces,p);if(!y){d({kind:"note",tone:"error",text:`No workspace matches "${p}".`});return}Mo(k.profile,k.projectId,y);return}case"publish":{if(h[0]&&h[0]!=="--all"){await be(Xt(h[0]),{display:`/publish ${h[0]}`,echoDisplay:!0});return}let p=h[0]==="--all";d({kind:"note",tone:"info",text:"Checking what needs publishing\u2026"});try{let k=await ko({cwd:e,profileName:s}),y=Yt(k.entries);if(y.length===0){d({kind:"note",tone:"ok",text:"\u2713 Nothing is ahead of Document360 \u2014 no publish candidates."});let M=k.counts["unknown-base"]??0;M>0&&d({kind:"note",tone:"info",text:`(${M} article(s) have no sync base yet \u2014 publish those by path if needed.)`});return}if(p){await be(ht(y.map(M=>M.path)),{display:"/publish --all",echoDisplay:!0});return}let I=y.length>1?[{path:"--all",label:`publish all ${y.length} candidates in one run`},...y]:y;Je({cursor:0,rows:I})}catch(k){d({kind:"note",tone:"error",text:`Could not compute sync status: ${k.message}`}),d({kind:"note",tone:"info",text:"Publish a specific article: /publish <article-path>"})}return}case"preview":{let p=h.join(" ").trim();if(!p){let y=[];try{y=Object.keys(Ms(e,he(e,s).name)?.articles??{})}catch{}if(y.length===0){d({kind:"note",tone:"info",text:"No tracked articles to pick from yet. Usage: /preview <path-to.md | article-id>"});return}Ne({query:"",cursor:0,paths:y});return}let k=ic(p)?p:vt(e,p);if(Es(k)){try{d({kind:"preview",name:pn(k),text:Ws(Ds(k,"utf8"))})}catch(y){d({kind:"note",tone:"error",text:`Could not read ${k}: ${y.message}`})}return}if(Mc.test(p)){try{let y=he(e,s),I={profile:y.name,connection:y.connection},M=y.project.projectId??dc(I),N=await pc(I,M,p);d({kind:"preview",name:N.title??p,text:N.content??"*(article has no content)*"})}catch(y){d({kind:"note",tone:"error",text:`Could not fetch article: ${y.message}`})}return}d({kind:"note",tone:"error",text:`"${p}" is neither a file (relative to ${e}) nor an article id.`});return}case"model":{let p=h[0]?.trim();if(!p){let M=Qt(xo(e));Me({cursor:M,current:M});return}let{lines:k,changed:y,effective:I}=wt(e,p);for(let M of k)d({kind:"note",tone:M.startsWith("\u26A0")?"warn":M.startsWith("\u2713")?"ok":"info",text:M});y&&(jo(M=>M+1),le.current?.setModel(I));return}case"convert":{if(!se(e)){d({kind:"note",tone:"error",text:"No d360-writer config here. Run /init first."});return}let{scope:p,run:k}=Wn(h),y=Rc(e,s);if(y.length===0){d({kind:"note",tone:"error",text:"No tracked articles in d360-category-map.json. Publish some first (/publish), then /convert."});return}let I=Fn(y,p);if(I.length===0){d({kind:"note",tone:"error",text:`No tracked articles under "${p}". (${y.length} are tracked overall.)`});return}let M=Ns(I),N=3,A=`/convert${p?` --scope ${p}`:""} --run`,_=wo(e,"light");if(!k){let T=Ls({files:Hn(e,I),op:"convert",model:_.model}),U=p?`Scope: ${p} (${I.length} of ${y.length} tracked)
|
|
82
83
|
`:"",ee=`
|
|
83
84
|
Model: ${_.model}${_.forced?" (forced)":" \u2014 mechanical work; /model to override"}`;d({kind:"note",tone:"info",text:U+qn(M,T,N).join(`
|
|
84
85
|
`)+ee}),K([A]);return}He.current=Date.now(),st(0),q(!0);let C=new AbortController;$e.current=C,Z({total:M.length,done:0,active:[],tools:0,chars:0,lastAt:Date.now(),startedAt:Date.now()}),d({kind:"note",tone:"info",text:`Converting ${I.length} articles across ${M.length} partitions (\u2264${N} agents at once) on ${_.model}\u2026 (esc to stop)`});try{for await(let T of yo({cwd:e,partitions:M,promptFor:Bn,concurrency:N,profileName:s,allowProdWrites:lt.current,model:_.model,signal:C.signal}))if(T.type==="partition_status")T.status==="running"?(Z(U=>U&&{...U,active:[...U.active,T.label],lastAt:Date.now()}),d({kind:"note",tone:"info",text:` \u25B8 ${T.label} \u2014 converting\u2026`})):(Z(U=>U&&{...U,active:U.active.filter(ee=>ee!==T.label),done:U.done+1,lastAt:Date.now()}),d({kind:"note",tone:T.status==="done"?"ok":"error",text:` ${T.status==="done"?"\u2713":"\u2717"} ${T.label}`}));else if(T.type==="partition_event")Z(U=>{if(!U)return U;let ee={...U,lastAt:Date.now()};return T.event.type==="tool"?ee.tools=U.tools+1:T.event.type==="text"&&(ee.chars=U.chars+T.event.delta.length),ee});else if(T.type==="run_done"){ct(O=>O+T.totalCostUsd),at(O=>O+T.results.reduce((Y,te)=>Y+te.outputTokens,0));let U=T.aborted?"Stopped. ":"",ee=t.kind==="api"?"api":"subscription";d({kind:"note",tone:T.aborted?"warn":T.ok?"ok":"warn",text:U+zn(T.results,M,ee).join(`
|
|
85
|
-
`)})}}catch(T){d({kind:"note",tone:"error",text:`Convert run failed: ${T.message}`})}finally{$e.current=null,Z(null),q(!1)}return}case"write":{if(!se(e)){d({kind:"note",tone:"error",text:"No d360-writer config here. Run /init first."});return}let p=
|
|
86
|
+
`)})}}catch(T){d({kind:"note",tone:"error",text:`Convert run failed: ${T.message}`})}finally{$e.current=null,Z(null),q(!1)}return}case"write":{if(!se(e)){d({kind:"note",tone:"error",text:"No d360-writer config here. Run /init first."});return}let p=Ac(e);if(p.length===0){d({kind:"note",tone:"error",text:"No docs plan found (.d360-writer/plan.json). Analyze the repo and propose a structure first \u2014 try: analyze this repo and propose a docs structure."});return}let{scope:k,path:y,run:I}=Yn(h),{docsDir:M,targets:N,reason:A}=Qn(e,p,{scope:k,path:y});if(N.length===0){d({kind:"note",tone:"warn",text:A??"Nothing to write."});return}let _=Ns(N),C=5,T=wo(e,"standard");if(!I&&!!!y){let O=Ls({files:Xn(e,p,N),op:"write",model:T.model}),Y=k?`Scope: ${k} (${N.length} pending)
|
|
86
87
|
`:"",te=`
|
|
87
88
|
Model: ${T.model}${T.forced?" (forced)":" \u2014 authoring; /model to override"}`;d({kind:"note",tone:"info",text:Y+Jn(_,O,C).join(`
|
|
88
|
-
`)+te}),K([`/write${k?` --scope ${k}`:" --all"} --run`]);return}He.current=Date.now(),st(0),q(!0);let ee=new AbortController;$e.current=ee,Z({verb:"Writing",total:_.length,done:0,active:[],tools:0,chars:0,lastAt:Date.now(),startedAt:Date.now()}),d({kind:"note",tone:"info",text:`Writing ${N.length} article${N.length===1?"":"s"} across ${_.length} partition${_.length===1?"":"s"} (\u2264${C} agents at once) on ${T.model}${T.forced?" (forced)":""}\u2026 (esc to stop)`});try{for await(let O of yo({cwd:e,partitions:_,promptFor:Y=>Vn(Y,M),concurrency:C,profileName:s,allowProdWrites:lt.current,model:T.model,signal:ee.signal}))if(O.type==="partition_status")O.status==="running"?(Z(Y=>Y&&{...Y,active:[...Y.active,O.label],lastAt:Date.now()}),d({kind:"note",tone:"info",text:` \u25B8 ${O.label} \u2014 writing\u2026`})):(Z(Y=>Y&&{...Y,active:Y.active.filter(te=>te!==O.label),done:Y.done+1,lastAt:Date.now()}),d({kind:"note",tone:O.status==="done"?"ok":"error",text:` ${O.status==="done"?"\u2713":"\u2717"} ${O.label}`}));else if(O.type==="partition_event")Z(Y=>{if(!Y)return Y;let te={...Y,lastAt:Date.now()};return O.event.type==="tool"?te.tools=Y.tools+1:O.event.type==="text"&&(te.chars=Y.chars+O.event.delta.length),te});else if(O.type==="run_done"){ct(Cn=>Cn+O.totalCostUsd),at(Cn=>Cn+O.results.reduce((
|
|
89
|
-
`)})}}catch(O){d({kind:"note",tone:"error",text:`Write run failed: ${O.message}`})}finally{$e.current=null,Z(null),q(!1)}return}case"sync":{let p=(h[0]??"status").toLowerCase();try{if(p==="status"){d({kind:"note",tone:"info",text:"Checking Document360 for drift\u2026"});let k=await ko({cwd:e,profileName:s});d({kind:"note",tone:"info",text:
|
|
90
|
-
`)});return}if(p==="pull"){let k=h[1];if(!k){d({kind:"note",tone:"error",text:"Usage: /sync pull <article-path> | --all"});return}let y;if(k==="--all"){if(d({kind:"note",tone:"info",text:"Checking Document360 for drift\u2026"}),y=(await ko({cwd:e,profileName:s})).entries.filter(N=>N.status==="remote-ahead"&&N.path).map(N=>N.path),y.length===0){d({kind:"note",tone:"ok",text:"\u2713 Nothing is remote-ahead \u2014 no pulls needed. (Conflicts are never bulk-pulled; pull them one by one.)"});return}}else y=[k.replace(/\\/g,"/")];let I=[];for(let M of y)I.push(await
|
|
89
|
+
`)+te}),K([`/write${k?` --scope ${k}`:" --all"} --run`]);return}He.current=Date.now(),st(0),q(!0);let ee=new AbortController;$e.current=ee,Z({verb:"Writing",total:_.length,done:0,active:[],tools:0,chars:0,lastAt:Date.now(),startedAt:Date.now()}),d({kind:"note",tone:"info",text:`Writing ${N.length} article${N.length===1?"":"s"} across ${_.length} partition${_.length===1?"":"s"} (\u2264${C} agents at once) on ${T.model}${T.forced?" (forced)":""}\u2026 (esc to stop)`});try{for await(let O of yo({cwd:e,partitions:_,promptFor:Y=>Vn(Y,M),concurrency:C,profileName:s,allowProdWrites:lt.current,model:T.model,signal:ee.signal}))if(O.type==="partition_status")O.status==="running"?(Z(Y=>Y&&{...Y,active:[...Y.active,O.label],lastAt:Date.now()}),d({kind:"note",tone:"info",text:` \u25B8 ${O.label} \u2014 writing\u2026`})):(Z(Y=>Y&&{...Y,active:Y.active.filter(te=>te!==O.label),done:Y.done+1,lastAt:Date.now()}),d({kind:"note",tone:O.status==="done"?"ok":"error",text:` ${O.status==="done"?"\u2713":"\u2717"} ${O.label}`}));else if(O.type==="partition_event")Z(Y=>{if(!Y)return Y;let te={...Y,lastAt:Date.now()};return O.event.type==="tool"?te.tools=Y.tools+1:O.event.type==="text"&&(te.chars=Y.chars+O.event.delta.length),te});else if(O.type==="run_done"){ct(Cn=>Cn+O.totalCostUsd),at(Cn=>Cn+O.results.reduce((ei,ti)=>ei+ti.outputTokens,0));let Y=O.aborted?"Stopped. ":"",te=t.kind==="api"?"api":"subscription";d({kind:"note",tone:O.aborted?"warn":O.ok?"ok":"warn",text:Y+Kn(O.results,_,te).join(`
|
|
90
|
+
`)})}}catch(O){d({kind:"note",tone:"error",text:`Write run failed: ${O.message}`})}finally{$e.current=null,Z(null),q(!1)}return}case"sync":{let p=(h[0]??"status").toLowerCase();try{if(p==="status"){d({kind:"note",tone:"info",text:"Checking Document360 for drift\u2026"});let k=await ko({cwd:e,profileName:s});d({kind:"note",tone:"info",text:Kt(k).join(`
|
|
91
|
+
`)});return}if(p==="pull"){let k=h[1];if(!k){d({kind:"note",tone:"error",text:"Usage: /sync pull <article-path> | --all"});return}let y;if(k==="--all"){if(d({kind:"note",tone:"info",text:"Checking Document360 for drift\u2026"}),y=(await ko({cwd:e,profileName:s})).entries.filter(N=>N.status==="remote-ahead"&&N.path).map(N=>N.path),y.length===0){d({kind:"note",tone:"ok",text:"\u2713 Nothing is remote-ahead \u2014 no pulls needed. (Conflicts are never bulk-pulled; pull them one by one.)"});return}}else y=[k.replace(/\\/g,"/")];let I=[];for(let M of y)I.push(await bc({cwd:e,profileName:s,relPath:M}));Se.current=I,It();return}d({kind:"note",tone:"error",text:`Unknown subcommand: /sync ${p} \u2014 use /sync or /sync pull <path>|--all.`})}catch(k){d({kind:"note",tone:"error",text:`Sync failed: ${k.message}`})}return}case"scope":{if(!se(e)){d({kind:"note",tone:"error",text:"No d360-writer config here. Run /init first."});return}let p=vc(e);if(p.length===0){d({kind:"note",tone:"info",text:'No candidate source folders found. Set "authoritativeSourceFiles" in .d360-writer.json manually.'});return}Ke({cursor:0,rows:p.map(k=>({...k,checked:k.recommended}))});return}case"audit":case"capture-setup":{let k=await(i==="audit"?Vt:xt)(h,void 0);if(k.kind==="forward-to-agent"&&k.prompt&&await be(k.prompt,{display:k.display,echoDisplay:!0}),i==="capture-setup"){let y=io(e);y&&d({kind:"note",tone:"info",text:y.join(`
|
|
91
92
|
`)})}return}case"screenshot":{let p=oo(h);if(p.mode==="list"){if(!se(e)){d({kind:"note",tone:"error",text:"No d360-writer config here. Run /init first."});return}d({kind:"note",tone:"info",text:so(ro(e,p.scope),p.scope).join(`
|
|
92
|
-
`)});return}if(p.mode==="single"){let C=await
|
|
93
|
-
`)})}return}case"reset":{let p=lo(e);if(p.length===0){d({kind:"note",tone:"info",text:"Nothing to reset \u2014 no d360-writer files found in this repo."});return}hn.current={repoName:
|
|
94
|
-
`)});return}default:d({kind:"note",tone:"error",text:`Unknown command: /${i} \u2014 type /help.`})}},[e,r,s,Dt,d,xe,be]),It=X(a=>{let l=(a??j).trim();if(b(""),Pt(null),Be(0),l.startsWith("/")){let h=k=>k.trim().split(/\s+/).slice(1).join(" "),p=h(l);K(k=>k.filter(y=>y.trim()!==l&&!(p&&h(y)===p)))}if(!l||Lo(l)||No(l))return;gn.current.push(l);let i=Ps(l,Co.current);l.startsWith("/")?Oo(i):be(i,{display:l})},[j,Lo,No,Oo,be]),Uo=X(a=>{if(a.length>1){if(a.includes("\x1B"))return;let l=bs(a);if(vs(l)){let i=Cs(++Xs.current,l);Co.current.set(i,l),v(i)}else v(l);return}v(a)},[v]),Qe=Math.max(10,Ue-6),Wo=un(()=>an(m.text,Qe),[m.text,Qe]),vn=X(a=>w(l=>({...l,pos:Math.max(0,Math.min(l.text.length,l.pos+a))})),[]),_t=X(a=>w(l=>({...l,pos:Ts(an(l.text,Qe),l.pos,a)})),[Qe]),dt=X(a=>w(l=>({...l,pos:Rs(an(l.text,Qe),l.pos,a)})),[Qe]),Ks=["\x1B[H","\x1B[1~","\x1BOH"],Qs=["\x1B[F","\x1B[4~","\x1BOF"],Fo=X((a,l)=>l.leftArrow?(vn(-1),!0):l.rightArrow?(vn(1),!0):a&&Ks.includes(a)?(dt("start"),!0):a&&Qs.includes(a)?(dt("end"),!0):l.ctrl&&a==="a"?(dt("start"),!0):l.ctrl&&a==="e"?(dt("end"),!0):!1,[vn,dt]);return oc((a,l)=>{if(l.ctrl&&a==="c"){le.current?.close(),r();return}if(!G){if(E){if(l.escape){if($e.current){$e.current.signal.aborted||(d({kind:"note",tone:"warn",text:"\u238B Stopping the convert run (finishing in-flight articles)\u2026"}),$e.current.abort());return}Tt.current||(Tt.current=!0,d({kind:"note",tone:"warn",text:"\u238B Interrupting\u2026"}),le.current?.interrupt());return}if(l.return){let i=j.trim();if(!i)return;Le.current.push(i),kn([...Le.current]),b("");return}if(Fo(a,l))return;if(l.upArrow){_t(-1);return}if(l.downArrow){_t(1);return}if(l.backspace||l.delete){$();return}a&&!l.ctrl&&!l.meta&&Uo(a);return}if(_e){if(l.upArrow){Me(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(l.downArrow){Me(i=>i&&{...i,cursor:Math.min(ge.length-1,i.cursor+1)});return}if(a&&/^[1-9]$/.test(a)&&Number(a)<=ge.length){Me(i=>i&&{...i,cursor:Number(a)-1});return}if(l.return){let i=ge[_e.cursor];Me(null);let{lines:h,changed:p,effective:k}=wt(e,i.value??"default");for(let y of h)d({kind:"note",tone:y.startsWith("\u26A0")?"warn":y.startsWith("\u2713")?"ok":"info",text:y});p&&(jo(y=>y+1),le.current?.setModel(k));return}if(a==="s"){let i=ge[_e.cursor];Me(null),le.current?.setModel(i.value??void 0),d({kind:"note",tone:"ok",text:`\u2713 Using ${i.label} for this session only (your saved default is unchanged).`});return}if(l.escape){Me(null);return}return}if(ye){if(l.upArrow){Ye(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(l.downArrow){Ye(i=>i&&{...i,cursor:Math.min(i.rows.length-1,i.cursor+1)});return}if(a&&/^[1-9]$/.test(a)&&Number(a)<=ye.rows.length){Ye(i=>i&&{...i,cursor:Number(a)-1});return}if(l.return||a==="s"){let i=ye.rows[ye.cursor];Ye(null),bn(i.name,l.return===!0);return}if(l.escape){Ye(null);return}return}if(Te){if(l.upArrow){Xe(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(l.downArrow){Xe(i=>i&&{...i,cursor:Math.min(i.rows.length-1,i.cursor+1)});return}if(a&&/^[1-9]$/.test(a)&&Number(a)<=Te.rows.length){Xe(i=>i&&{...i,cursor:Number(a)-1});return}if(l.return){let i=Te.rows[Te.cursor].name;if(Xe(null),!lr(e,i).created){d({kind:"note",tone:"error",text:"Could not scaffold \u2014 .d360-writer.json already exists."});return}d({kind:"note",tone:"ok",text:`\u2713 Wrote .d360-writer.json (environment "${i}").`});let p=!1;try{let k=Fe(i);p=!!k&&!(De(k)&&!k.refreshToken)}catch{}p?(d({kind:"note",tone:"info",text:`Already signed in to ${i} \u2014 next: pick a workspace.`}),K(["/workspace"])):(d({kind:"note",tone:"info",text:`Next: sign in to Document360 (${i}).`}),K(["/login"])),Pe(k=>k+1);return}if(l.escape){Xe(null);return}return}if(ne){if(l.upArrow){Ve(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(l.downArrow){Ve(i=>i&&{...i,cursor:Math.min(i.rows.length-1,i.cursor+1)});return}if(a&&/^[1-9]$/.test(a)&&Number(a)<=ne.rows.length){Ve(i=>i&&{...i,cursor:Number(a)-1});return}if(l.return){let i=ne.rows[ne.cursor],{profile:h,projectId:p}=ne;Ve(null),Mo(h,p,i);return}if(l.escape){Ve(null);return}return}if(oe){if(l.upArrow){Ke(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(l.downArrow){Ke(i=>i&&{...i,cursor:Math.min(i.rows.length-1,i.cursor+1)});return}if(a===" "){Ke(i=>i&&{...i,rows:i.rows.map((h,p)=>p===i.cursor?{...h,checked:!h.checked}:h)});return}if(l.return){let i=oe.rows.filter(h=>h.checked).map(h=>h.path);if(Ke(null),i.length===0){d({kind:"note",tone:"info",text:"Nothing selected \u2014 scope unchanged."});return}jn(e,i),d({kind:"note",tone:"ok",text:`\u2713 Scoped to ${i.length} folder(s) \u2014 written to .d360-writer.json`});for(let h of i)d({kind:"note",tone:"info",text:` ${h}`});d({kind:"note",tone:"info",text:"Next: ask me to analyze these folders and propose a docs structure."});return}if(l.escape){Ke(null);return}return}if(we){if(l.upArrow){Je(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(l.downArrow){Je(i=>i&&{...i,cursor:Math.min(i.rows.length-1,i.cursor+1)});return}if(a&&/^[1-9]$/.test(a)&&Number(a)<=we.rows.length){Je(i=>i&&{...i,cursor:Number(a)-1});return}if(l.return){let i=we.rows[we.cursor],h=we.rows.filter(p=>p.path!=="--all").map(p=>p.path);Je(null),be(i.path==="--all"?ht(h):Yt(i.path),{display:i.path==="--all"?"/publish --all":`/publish ${i.path}`,echoDisplay:!0});return}if(l.escape){Je(null);return}return}if(ae){if(l.escape){Ne(null);return}if(l.upArrow){Ne(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(l.downArrow){Ne(i=>i&&{...i,cursor:Math.min(Math.max(0,jt.length-1),i.cursor+1)});return}if(l.return){let i=jt[ae.cursor];if(i){Ne(null);try{d({kind:"preview",name:dn(i),text:Us(Ds(vt(e,i),"utf8"))})}catch(h){d({kind:"note",tone:"error",text:`Could not read ${i}: ${h.message}`})}}return}if(l.backspace||l.delete){Ne(i=>i&&{...i,query:i.query.slice(0,-1),cursor:0});return}if(a&&!l.ctrl&&!l.meta&&a.length===1){Ne(i=>i&&{...i,query:i.query+a,cursor:0});return}return}if(ce){if(l.escape){Oe(null);return}if(l.upArrow){Oe(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(l.downArrow){Oe(i=>i&&{...i,cursor:Math.min(Math.max(0,Et.length-1),i.cursor+1)});return}if(l.return){let i=Et[ce.cursor];if(i){Oe(null),xe(i.uuid),ke.current={uuid:i.uuid,firstPrompt:i.firstPrompt,titleFired:!0},Ge(i.name),ho(i.uuid),ze.current=[];let h=mo(e,i.uuid);for(let p of h)d(p);d({kind:"note",tone:"ok",text:h.length?`Resumed "${i.name}" \u2014 restored ${h.length} message(s); continue where you left off.`:`Resumed "${i.name}" (agent memory reconnected; no saved transcript to replay).`})}return}if(l.backspace||l.delete){Oe(i=>i&&{...i,query:i.query.slice(0,-1),cursor:0});return}if(a&&!l.ctrl&&!l.meta&&a.length===1){Oe(i=>i&&{...i,query:i.query+a,cursor:0});return}return}if(l.tab&&!j&&pe){b(pe),fe(null),Ct.current++;return}if(!j&&rt.length>0&&a&&/^[1-9]$/.test(a)){let i=rt[Number(a)-1];if(i){b(i);return}}if(!Fo(a,l)){if(Io){if(l.upArrow){Be(i=>Math.max(0,i-1));return}if(l.downArrow){Be(i=>Math.min(ut.length-1,i+1));return}if(l.tab){b("/"+(ut[it]?.name??"")+" "),Be(0);return}if(l.return){let i=ut[it];if(i){let h=j.trim().slice(1).split(/\s+/).slice(1).join(" ");if(nr(i.usage)&&!h){b("/"+i.name+" "),Be(0);return}It("/"+i.name+(h?" "+h:""));return}}}else{if(l.upArrow){if(j!==""&&qe===null){_t(-1);return}let i=gn.current;if(!i.length)return;let h=qe===null?i.length-1:Math.max(0,qe-1);Pt(h),b(i[h]??"");return}if(l.downArrow){if(j!==""&&qe===null){_t(1);return}let i=gn.current;if(qe===null)return;let h=qe+1;h>=i.length?(Pt(null),b("")):(Pt(h),b(i[h]??""));return}}if(l.return){It();return}if(l.backspace||l.delete){$();return}if(l.escape){b(""),Be(0),fe(null),K([]);return}a&&!l.ctrl&&!l.meta&&Uo(a)}}}),Ie(()=>{if(E||G)return;let a=Le.current.shift();a!==void 0&&(kn([...Le.current]),It(a))},[E,G,It]),F(J,{flexDirection:"column",width:Ue,children:[$n!==null&&F(J,{marginTop:1,flexDirection:"column",children:[$n.truncated&&S(P,{dimColor:!0,children:"\u2026"}),S(P,{children:$n.text})]}),E&&(To?S(Oc,{p:To}):S(Nc,{startTime:He.current,chars:Ys})),S(J,{borderStyle:"round",borderColor:Do.prod?"yellow":z,borderTop:!0,borderBottom:!0,borderLeft:!1,borderRight:!1,marginTop:1,flexDirection:"column",children:j?Wo.map((a,l)=>{let i=m.text.slice(a.start,a.end),h=l===cn(Wo,m.pos),p=Math.min(m.pos,a.end)-a.start;return F(P,{children:[S(P,{color:z,children:l===0?"> ":" "}),h?F($o,{children:[i.slice(0,p),S(pn,{ch:i[p]??" "}),i.slice(p+1)]}):i||" "]},`${l}-${a.start}`)}):F(P,{children:[S(P,{color:z,children:"> "}),pe&&!E?F($o,{children:[S(pn,{ch:pe[0],dim:!0}),S(P,{color:"gray",children:pe.slice(1)}),S(P,{dimColor:!0,children:" (tab)"})]}):wn.isSetup||!Gs?F($o,{children:[S(pn,{ch:wn.text[0],dim:!0}),S(P,{color:"gray",children:wn.text.slice(1)})]}):S(pn,{ch:" "})]})}),So.length>0&&S(J,{flexDirection:"column",paddingX:1,children:So.map((a,l)=>S(P,{color:"gray",children:`\u29D7 queued: ${a}`},`${l}-${a.slice(0,24)}`))}),_e?F(J,{flexDirection:"column",paddingX:1,children:[S(P,{color:z,bold:!0,children:"Select model"}),S(P,{color:"gray",children:"Your pick becomes your personal default for new sessions (team .d360-writer.json still wins)."}),ge.map((a,l)=>F(P,{color:l===_e.cursor?z:void 0,children:[l===_e.cursor?"\u276F ":" ",`${l+1}. ${a.label}${l===_e.current?" \u2714":""}`.padEnd(16),S(P,{color:"gray",children:a.desc})]},a.label)),S(P,{dimColor:!0,children:"enter set as default \xB7 s this session only \xB7 esc cancel"})]}):ye?F(J,{flexDirection:"column",paddingX:1,children:[S(P,{color:z,bold:!0,children:"Switch connection profile"}),ye.rows.map((a,l)=>F(P,{color:l===ye.cursor?z:void 0,children:[l===ye.cursor?"\u276F ":" ",`${l+1}. ${a.name}${l===ye.current?" \u2714":""}`.padEnd(20),S(P,{color:"gray",children:`${a.env} \xB7 ${a.who??"not signed in"}`}),a.prod?S(P,{color:"yellow",bold:!0,children:" \u26A0 PRODUCTION"}):null]},a.name)),S(P,{dimColor:!0,children:"enter switch (saved as default) \xB7 s this session only \xB7 esc cancel"})]}):Te?F(J,{flexDirection:"column",paddingX:1,children:[S(P,{color:z,bold:!0,children:"Pick your Document360 environment"}),Te.rows.map((a,l)=>F(P,{color:l===Te.cursor?z:void 0,children:[l===Te.cursor?"\u276F ":" ",`${l+1}. ${a.name}`.padEnd(16),S(P,{color:"gray",children:a.apiUrl})]},a.name)),S(P,{dimColor:!0,children:"enter select \xB7 esc cancel"})]}):ne?F(J,{flexDirection:"column",paddingX:1,children:[S(P,{color:z,bold:!0,children:"Switch workspace"}),S(P,{dimColor:!0,children:`environment ${ne.environment} \xB7 project ${ne.projectId.slice(0,8)}\u2026`}),ne.rows.map((a,l)=>F(P,{color:l===ne.cursor?z:void 0,children:[l===ne.cursor?"\u276F ":" ",`${l+1}. ${a.name}${l===ne.current?" \u2714":""}`.padEnd(30),S(P,{color:"gray",children:a.type??""})]},a.id)),S(P,{dimColor:!0,children:"enter switch \xB7 esc cancel"})]}):oe?(()=>{let l=Math.min(Math.max(0,oe.cursor-Math.floor(7)),Math.max(0,oe.rows.length-14)),i=oe.rows.slice(l,l+14),h=oe.rows.filter(p=>p.checked).length;return F(J,{flexDirection:"column",paddingX:1,children:[S(P,{color:z,bold:!0,children:`Which folders back the user docs? (${h} selected of ${oe.rows.length})`}),l>0?S(P,{dimColor:!0,children:` \u2191 ${l} more`}):null,i.map((p,k)=>{let y=l+k;return F(P,{color:y===oe.cursor?z:void 0,children:[y===oe.cursor?"\u276F ":" ",p.checked?"\u25C9 ":"\u25CB ",p.path.padEnd(Math.min(48,Ue-34)),S(P,{color:"gray",children:Vt(p)})]},p.path)}),l+14<oe.rows.length?S(P,{dimColor:!0,children:` \u2193 ${oe.rows.length-l-14} more`}):null,S(P,{dimColor:!0,children:"space toggle \xB7 enter save \xB7 esc cancel"})]})})():we?F(J,{flexDirection:"column",paddingX:1,children:[S(P,{color:z,bold:!0,children:"Publish which article?"}),we.rows.map((a,l)=>F(P,{color:l===we.cursor?z:void 0,children:[l===we.cursor?"\u276F ":" ",`${l+1}. ${a.path}`.padEnd(Math.min(56,Ue-30)),S(P,{color:"gray",children:a.label})]},a.path)),S(P,{dimColor:!0,children:"enter publish (draft) \xB7 esc cancel"})]}):ae?F(J,{flexDirection:"column",paddingX:1,children:[S(P,{color:z,bold:!0,children:`Preview article${ae.query?` \u2014 filter: ${ae.query}`:" (type to filter)"}`}),jt.length===0?S(P,{color:"gray",children:"no articles match"}):jt.map((a,l)=>F(P,{color:l===ae.cursor?z:void 0,children:[l===ae.cursor?"\u276F ":" ",a]},a)),S(P,{dimColor:!0,children:"enter preview \xB7 esc cancel"})]}):ce?F(J,{flexDirection:"column",paddingX:1,children:[S(P,{color:z,bold:!0,children:`Resume session${ce.query?` \u2014 filter: ${ce.query}`:" (type to filter)"}`}),Et.length===0?S(P,{color:"gray",children:"no sessions match"}):Et.map((a,l)=>F(P,{color:l===ce.cursor?z:void 0,children:[l===ce.cursor?"\u276F ":" ",a.name.slice(0,28).padEnd(30),S(P,{color:l===ce.cursor?z:"gray",children:a.firstPrompt.slice(0,Math.max(10,Ue-40))})]},a.uuid)),S(P,{dimColor:!0,children:"enter resume \xB7 esc cancel"})]}):Io?S(J,{flexDirection:"column",children:ut.map((a,l)=>F(P,{color:l===it?z:void 0,children:[l===it?"\u276F ":" ",a.usage.padEnd(22)," ",S(P,{color:l===it?z:"gray",children:a.name==="model"&&yn?`${a.desc} (currently ${yn})`:a.desc})]},a.name))}):!j&&rt.length>0?F(J,{flexDirection:"column",paddingX:1,children:[rt.map((a,l)=>F(P,{children:[S(P,{color:z,children:l+1})," ",a.slice(0,Math.max(20,Ue-5))]},a)),S(P,{dimColor:!0,children:`press 1-${rt.length} to fill the command \xB7 esc dismiss`})]}):S(J,{paddingX:1,children:F(P,{color:"gray",children:[Do.prod?"\u26A0 PRODUCTION \xB7 ":"",`/help \xB7 ${yn??"model n/a"}${t.kind==="api"?Ao>0?` \xB7 ${ue(Ao)}`:"":Ro>0?` \xB7 ${nt(Ro)}`:""} \xB7 \u2191 history \xB7 ctrl+c exit`]})})]})}H();import{jsx as Fc}from"react/jsx-runtime";async function Bs(e=process.cwd(),t="auto",n,o="0.0.0"){let r=Wc(t);r.kind==="none"&&(console.error(""),console.error(x("ANTHROPIC_API_KEY is not set (required for --auth api).")),console.error(`Get a key at ${R("https://console.anthropic.com/settings/keys")}`),console.error(`Or use your Claude subscription instead: ${R("d360-writer --auth subscription")}`),process.exit(2));let{waitUntilExit:s}=Uc(Fc(Hs,{cwd:e,auth:r,profileName:n,version:o}));await s(),process.stdout.write(`
|
|
95
|
-
`),process.exit(0)}var
|
|
93
|
+
`)});return}if(p.mode==="single"){let C=await en(h);C.kind==="forward-to-agent"&&C.prompt&&await be(C.prompt,{display:C.display,echoDisplay:!0});return}if(!se(e)){d({kind:"note",tone:"error",text:"No d360-writer config here. Run /init first."});return}let k=p.mode==="scope"?p.scope:void 0,y=Tc(e,{scope:k}).map(C=>C.id);if(y.length===0){d({kind:"note",tone:"info",text:k?`No screenshot placeholders under ${k}.`:"No screenshot placeholders found in the docs."});return}let I=6,M=Sc(y,3),N=wo(e,"standard");He.current=Date.now(),st(0),q(!0);let A=new AbortController;$e.current=A,Z({verb:"Authoring",total:M.length,done:0,active:[],tools:0,chars:0,lastAt:Date.now(),startedAt:Date.now()}),d({kind:"note",tone:"info",text:`Authoring ${y.length} screenshot spec${y.length===1?"":"s"} across ${M.length} partition${M.length===1?"":"s"} (\u2264${I} agents at once) on ${N.model}${N.forced?" (forced)":""}\u2026 (esc to stop)`});let _=!1;try{for await(let C of yo({cwd:e,partitions:M,promptFor:ts,concurrency:I,profileName:s,allowProdWrites:lt.current,model:N.model,signal:A.signal}))if(C.type==="partition_status")C.status==="running"?(Z(T=>T&&{...T,active:[...T.active,C.label],lastAt:Date.now()}),d({kind:"note",tone:"info",text:` \u25B8 ${C.label} \u2014 authoring\u2026`})):(Z(T=>T&&{...T,active:T.active.filter(U=>U!==C.label),done:T.done+1,lastAt:Date.now()}),d({kind:"note",tone:C.status==="done"?"ok":"error",text:` ${C.status==="done"?"\u2713":"\u2717"} ${C.label}`}));else if(C.type==="partition_event")Z(T=>{if(!T)return T;let U={...T,lastAt:Date.now()};return C.event.type==="tool"?U.tools=T.tools+1:C.event.type==="text"&&(U.chars=T.chars+C.event.delta.length),U});else if(C.type==="run_done"){ct(O=>O+C.totalCostUsd),at(O=>O+C.results.reduce((Y,te)=>Y+te.outputTokens,0));let T=C.results.filter(O=>O.ok).length,U=C.aborted?"Stopped. ":"";_=!C.aborted&&p.setup;let ee=C.aborted?"":_?" Refreshing the capture-setup checklist\u2026":" Next: /capture-setup, then d360-capture capture.";d({kind:"note",tone:C.aborted?"warn":C.ok?"ok":"warn",text:`${U}Authored specs \u2014 ${T}/${C.results.length} batches ok.${ee}`})}}catch(C){d({kind:"note",tone:"error",text:`Spec authoring failed: ${C.message}`})}finally{$e.current=null,Z(null),q(!1)}if(_){let C=await xt();C.kind==="forward-to-agent"&&C.prompt&&await be(C.prompt,{display:C.display,echoDisplay:!0});let T=io(e);T&&d({kind:"note",tone:"info",text:T.join(`
|
|
94
|
+
`)})}return}case"reset":{let p=lo(e);if(p.length===0){d({kind:"note",tone:"info",text:"Nothing to reset \u2014 no d360-writer files found in this repo."});return}hn.current={repoName:pn(e),targets:p},d({kind:"note",tone:"warn",text:co(e,p).join(`
|
|
95
|
+
`)});return}default:d({kind:"note",tone:"error",text:`Unknown command: /${i} \u2014 type /help.`})}},[e,r,s,It,d,xe,be]),_t=X(a=>{let l=(a??j).trim();if(b(""),St(null),Be(0),l.startsWith("/")){let h=k=>k.trim().split(/\s+/).slice(1).join(" "),p=h(l);K(k=>k.filter(y=>y.trim()!==l&&!(p&&h(y)===p)))}if(!l||Lo(l)||No(l))return;gn.current.push(l);let i=Ps(l,Co.current);l.startsWith("/")?Oo(i):be(i,{display:l})},[j,Lo,No,Oo,be]),Uo=X(a=>{if(a.length>1){if(a.includes("\x1B"))return;let l=bs(a);if(vs(l)){let i=Cs(++Vs.current,l);Co.current.set(i,l),v(i)}else v(l);return}v(a)},[v]),Qe=Math.max(10,Ue-6),Wo=dn(()=>cn(m.text,Qe),[m.text,Qe]),vn=X(a=>w(l=>({...l,pos:Math.max(0,Math.min(l.text.length,l.pos+a))})),[]),Mt=X(a=>w(l=>({...l,pos:Ts(cn(l.text,Qe),l.pos,a)})),[Qe]),dt=X(a=>w(l=>({...l,pos:Rs(cn(l.text,Qe),l.pos,a)})),[Qe]),Qs=["\x1B[H","\x1B[1~","\x1BOH"],Zs=["\x1B[F","\x1B[4~","\x1BOF"],Fo=X((a,l)=>l.leftArrow?(vn(-1),!0):l.rightArrow?(vn(1),!0):a&&Qs.includes(a)?(dt("start"),!0):a&&Zs.includes(a)?(dt("end"),!0):l.ctrl&&a==="a"?(dt("start"),!0):l.ctrl&&a==="e"?(dt("end"),!0):!1,[vn,dt]);return rc((a,l)=>{if(l.ctrl&&a==="c"){le.current?.close(),r();return}if(!G){if(E){if(l.escape){if($e.current){$e.current.signal.aborted||(d({kind:"note",tone:"warn",text:"\u238B Stopping the convert run (finishing in-flight articles)\u2026"}),$e.current.abort());return}Rt.current||(Rt.current=!0,d({kind:"note",tone:"warn",text:"\u238B Interrupting\u2026"}),le.current?.interrupt());return}if(l.return){let i=j.trim();if(!i)return;Le.current.push(i),kn([...Le.current]),b("");return}if(Fo(a,l))return;if(l.upArrow){Mt(-1);return}if(l.downArrow){Mt(1);return}if(l.backspace||l.delete){$();return}a&&!l.ctrl&&!l.meta&&Uo(a);return}if(_e){if(l.upArrow){Me(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(l.downArrow){Me(i=>i&&{...i,cursor:Math.min(ge.length-1,i.cursor+1)});return}if(a&&/^[1-9]$/.test(a)&&Number(a)<=ge.length){Me(i=>i&&{...i,cursor:Number(a)-1});return}if(l.return){let i=ge[_e.cursor];Me(null);let{lines:h,changed:p,effective:k}=wt(e,i.value??"default");for(let y of h)d({kind:"note",tone:y.startsWith("\u26A0")?"warn":y.startsWith("\u2713")?"ok":"info",text:y});p&&(jo(y=>y+1),le.current?.setModel(k));return}if(a==="s"){let i=ge[_e.cursor];Me(null),le.current?.setModel(i.value??void 0),d({kind:"note",tone:"ok",text:`\u2713 Using ${i.label} for this session only (your saved default is unchanged).`});return}if(l.escape){Me(null);return}return}if(ye){if(l.upArrow){Ye(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(l.downArrow){Ye(i=>i&&{...i,cursor:Math.min(i.rows.length-1,i.cursor+1)});return}if(a&&/^[1-9]$/.test(a)&&Number(a)<=ye.rows.length){Ye(i=>i&&{...i,cursor:Number(a)-1});return}if(l.return||a==="s"){let i=ye.rows[ye.cursor];Ye(null),bn(i.name,l.return===!0);return}if(l.escape){Ye(null);return}return}if(Te){if(l.upArrow){Xe(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(l.downArrow){Xe(i=>i&&{...i,cursor:Math.min(i.rows.length-1,i.cursor+1)});return}if(a&&/^[1-9]$/.test(a)&&Number(a)<=Te.rows.length){Xe(i=>i&&{...i,cursor:Number(a)-1});return}if(l.return){let i=Te.rows[Te.cursor].name;if(Xe(null),!lr(e,i).created){d({kind:"note",tone:"error",text:"Could not scaffold \u2014 .d360-writer.json already exists."});return}d({kind:"note",tone:"ok",text:`\u2713 Wrote .d360-writer.json (environment "${i}").`});let p=!1;try{let k=Fe(i);p=!!k&&!(De(k)&&!k.refreshToken)}catch{}p?(d({kind:"note",tone:"info",text:`Already signed in to ${i} \u2014 next: pick a workspace.`}),K(["/workspace"])):(d({kind:"note",tone:"info",text:`Next: sign in to Document360 (${i}).`}),K(["/login"])),Pe(k=>k+1);return}if(l.escape){Xe(null);return}return}if(ne){if(l.upArrow){Ve(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(l.downArrow){Ve(i=>i&&{...i,cursor:Math.min(i.rows.length-1,i.cursor+1)});return}if(a&&/^[1-9]$/.test(a)&&Number(a)<=ne.rows.length){Ve(i=>i&&{...i,cursor:Number(a)-1});return}if(l.return){let i=ne.rows[ne.cursor],{profile:h,projectId:p}=ne;Ve(null),Mo(h,p,i);return}if(l.escape){Ve(null);return}return}if(oe){if(l.upArrow){Ke(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(l.downArrow){Ke(i=>i&&{...i,cursor:Math.min(i.rows.length-1,i.cursor+1)});return}if(a===" "){Ke(i=>i&&{...i,rows:i.rows.map((h,p)=>p===i.cursor?{...h,checked:!h.checked}:h)});return}if(l.return){let i=oe.rows.filter(h=>h.checked).map(h=>h.path);if(Ke(null),i.length===0){d({kind:"note",tone:"info",text:"Nothing selected \u2014 scope unchanged."});return}jn(e,i),d({kind:"note",tone:"ok",text:`\u2713 Scoped to ${i.length} folder(s) \u2014 written to .d360-writer.json`});for(let h of i)d({kind:"note",tone:"info",text:` ${h}`});d({kind:"note",tone:"info",text:"Next: ask me to analyze these folders and propose a docs structure."});return}if(l.escape){Ke(null);return}return}if(we){if(l.upArrow){Je(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(l.downArrow){Je(i=>i&&{...i,cursor:Math.min(i.rows.length-1,i.cursor+1)});return}if(a&&/^[1-9]$/.test(a)&&Number(a)<=we.rows.length){Je(i=>i&&{...i,cursor:Number(a)-1});return}if(l.return){let i=we.rows[we.cursor],h=we.rows.filter(p=>p.path!=="--all").map(p=>p.path);Je(null),be(i.path==="--all"?ht(h):Xt(i.path),{display:i.path==="--all"?"/publish --all":`/publish ${i.path}`,echoDisplay:!0});return}if(l.escape){Je(null);return}return}if(ae){if(l.escape){Ne(null);return}if(l.upArrow){Ne(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(l.downArrow){Ne(i=>i&&{...i,cursor:Math.min(Math.max(0,Et.length-1),i.cursor+1)});return}if(l.return){let i=Et[ae.cursor];if(i){Ne(null);try{d({kind:"preview",name:pn(i),text:Ws(Ds(vt(e,i),"utf8"))})}catch(h){d({kind:"note",tone:"error",text:`Could not read ${i}: ${h.message}`})}}return}if(l.backspace||l.delete){Ne(i=>i&&{...i,query:i.query.slice(0,-1),cursor:0});return}if(a&&!l.ctrl&&!l.meta&&a.length===1){Ne(i=>i&&{...i,query:i.query+a,cursor:0});return}return}if(ce){if(l.escape){Oe(null);return}if(l.upArrow){Oe(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(l.downArrow){Oe(i=>i&&{...i,cursor:Math.min(Math.max(0,Dt.length-1),i.cursor+1)});return}if(l.return){let i=Dt[ce.cursor];if(i){Oe(null),xe(i.uuid),ke.current={uuid:i.uuid,firstPrompt:i.firstPrompt,titleFired:!0},Ge(i.name),ho(i.uuid),ze.current=[];let h=mo(e,i.uuid);for(let p of h)d(p);d({kind:"note",tone:"ok",text:h.length?`Resumed "${i.name}" \u2014 restored ${h.length} message(s); continue where you left off.`:`Resumed "${i.name}" (agent memory reconnected; no saved transcript to replay).`})}return}if(l.backspace||l.delete){Oe(i=>i&&{...i,query:i.query.slice(0,-1),cursor:0});return}if(a&&!l.ctrl&&!l.meta&&a.length===1){Oe(i=>i&&{...i,query:i.query+a,cursor:0});return}return}if(l.tab&&!j&&pe){b(pe),fe(null),Ct.current++;return}if(!j&&rt.length>0&&a&&/^[1-9]$/.test(a)){let i=rt[Number(a)-1];if(i){b(i);return}}if(!Fo(a,l)){if(Io){if(l.upArrow){Be(i=>Math.max(0,i-1));return}if(l.downArrow){Be(i=>Math.min(ut.length-1,i+1));return}if(l.tab){b("/"+(ut[it]?.name??"")+" "),Be(0);return}if(l.return){let i=ut[it];if(i){let h=j.trim().slice(1).split(/\s+/).slice(1).join(" ");if(nr(i.usage)&&!h){b("/"+i.name+" "),Be(0);return}_t("/"+i.name+(h?" "+h:""));return}}}else{if(l.upArrow){if(j!==""&&qe===null){Mt(-1);return}let i=gn.current;if(!i.length)return;let h=qe===null?i.length-1:Math.max(0,qe-1);St(h),b(i[h]??"");return}if(l.downArrow){if(j!==""&&qe===null){Mt(1);return}let i=gn.current;if(qe===null)return;let h=qe+1;h>=i.length?(St(null),b("")):(St(h),b(i[h]??""));return}}if(l.return){_t();return}if(l.backspace||l.delete){$();return}if(l.escape){b(""),Be(0),fe(null),K([]);return}a&&!l.ctrl&&!l.meta&&Uo(a)}}}),Ie(()=>{if(E||G)return;let a=Le.current.shift();a!==void 0&&(kn([...Le.current]),_t(a))},[E,G,_t]),F(J,{flexDirection:"column",width:Ue,children:[$n!==null&&F(J,{marginTop:1,flexDirection:"column",children:[$n.truncated&&S(P,{dimColor:!0,children:"\u2026"}),S(P,{children:$n.text})]}),E&&(To?S(Uc,{p:To}):S(Lc,{startTime:He.current,chars:Xs})),S(J,{borderStyle:"round",borderColor:Do.prod?"yellow":z,borderTop:!0,borderBottom:!0,borderLeft:!1,borderRight:!1,marginTop:1,flexDirection:"column",children:j?Wo.map((a,l)=>{let i=m.text.slice(a.start,a.end),h=l===un(Wo,m.pos),p=Math.min(m.pos,a.end)-a.start;return F(P,{children:[S(P,{color:z,children:l===0?"> ":" "}),h?F($o,{children:[i.slice(0,p),S(fn,{ch:i[p]??" "}),i.slice(p+1)]}):i||" "]},`${l}-${a.start}`)}):F(P,{children:[S(P,{color:z,children:"> "}),pe&&!E?F($o,{children:[S(fn,{ch:pe[0],dim:!0}),S(P,{color:"gray",children:pe.slice(1)}),S(P,{dimColor:!0,children:" (tab)"})]}):wn.isSetup||!Ys?F($o,{children:[S(fn,{ch:wn.text[0],dim:!0}),S(P,{color:"gray",children:wn.text.slice(1)})]}):S(fn,{ch:" "})]})}),So.length>0&&S(J,{flexDirection:"column",paddingX:1,children:So.map((a,l)=>S(P,{color:"gray",children:`\u29D7 queued: ${a}`},`${l}-${a.slice(0,24)}`))}),_e?F(J,{flexDirection:"column",paddingX:1,children:[S(P,{color:z,bold:!0,children:"Select model"}),S(P,{color:"gray",children:"Your pick becomes your personal default for new sessions (team .d360-writer.json still wins)."}),ge.map((a,l)=>F(P,{color:l===_e.cursor?z:void 0,children:[l===_e.cursor?"\u276F ":" ",`${l+1}. ${a.label}${l===_e.current?" \u2714":""}`.padEnd(16),S(P,{color:"gray",children:a.desc})]},a.label)),S(P,{dimColor:!0,children:"enter set as default \xB7 s this session only \xB7 esc cancel"})]}):ye?F(J,{flexDirection:"column",paddingX:1,children:[S(P,{color:z,bold:!0,children:"Switch connection profile"}),ye.rows.map((a,l)=>F(P,{color:l===ye.cursor?z:void 0,children:[l===ye.cursor?"\u276F ":" ",`${l+1}. ${a.name}${l===ye.current?" \u2714":""}`.padEnd(20),S(P,{color:"gray",children:`${a.env} \xB7 ${a.who??"not signed in"}`}),a.prod?S(P,{color:"yellow",bold:!0,children:" \u26A0 PRODUCTION"}):null]},a.name)),S(P,{dimColor:!0,children:"enter switch (saved as default) \xB7 s this session only \xB7 esc cancel"})]}):Te?F(J,{flexDirection:"column",paddingX:1,children:[S(P,{color:z,bold:!0,children:"Pick your Document360 environment"}),Te.rows.map((a,l)=>F(P,{color:l===Te.cursor?z:void 0,children:[l===Te.cursor?"\u276F ":" ",`${l+1}. ${a.name}`.padEnd(16),S(P,{color:"gray",children:a.apiUrl})]},a.name)),S(P,{dimColor:!0,children:"enter select \xB7 esc cancel"})]}):ne?F(J,{flexDirection:"column",paddingX:1,children:[S(P,{color:z,bold:!0,children:"Switch workspace"}),S(P,{dimColor:!0,children:`environment ${ne.environment} \xB7 project ${ne.projectId.slice(0,8)}\u2026`}),ne.rows.map((a,l)=>F(P,{color:l===ne.cursor?z:void 0,children:[l===ne.cursor?"\u276F ":" ",`${l+1}. ${a.name}${l===ne.current?" \u2714":""}`.padEnd(30),S(P,{color:"gray",children:a.type??""})]},a.id)),S(P,{dimColor:!0,children:"enter switch \xB7 esc cancel"})]}):oe?(()=>{let l=Math.min(Math.max(0,oe.cursor-Math.floor(7)),Math.max(0,oe.rows.length-14)),i=oe.rows.slice(l,l+14),h=oe.rows.filter(p=>p.checked).length;return F(J,{flexDirection:"column",paddingX:1,children:[S(P,{color:z,bold:!0,children:`Which folders back the user docs? (${h} selected of ${oe.rows.length})`}),l>0?S(P,{dimColor:!0,children:` \u2191 ${l} more`}):null,i.map((p,k)=>{let y=l+k;return F(P,{color:y===oe.cursor?z:void 0,children:[y===oe.cursor?"\u276F ":" ",p.checked?"\u25C9 ":"\u25CB ",p.path.padEnd(Math.min(48,Ue-34)),S(P,{color:"gray",children:Jt(p)})]},p.path)}),l+14<oe.rows.length?S(P,{dimColor:!0,children:` \u2193 ${oe.rows.length-l-14} more`}):null,S(P,{dimColor:!0,children:"space toggle \xB7 enter save \xB7 esc cancel"})]})})():we?F(J,{flexDirection:"column",paddingX:1,children:[S(P,{color:z,bold:!0,children:"Publish which article?"}),we.rows.map((a,l)=>F(P,{color:l===we.cursor?z:void 0,children:[l===we.cursor?"\u276F ":" ",`${l+1}. ${a.path}`.padEnd(Math.min(56,Ue-30)),S(P,{color:"gray",children:a.label})]},a.path)),S(P,{dimColor:!0,children:"enter publish (draft) \xB7 esc cancel"})]}):ae?F(J,{flexDirection:"column",paddingX:1,children:[S(P,{color:z,bold:!0,children:`Preview article${ae.query?` \u2014 filter: ${ae.query}`:" (type to filter)"}`}),Et.length===0?S(P,{color:"gray",children:"no articles match"}):Et.map((a,l)=>F(P,{color:l===ae.cursor?z:void 0,children:[l===ae.cursor?"\u276F ":" ",a]},a)),S(P,{dimColor:!0,children:"enter preview \xB7 esc cancel"})]}):ce?F(J,{flexDirection:"column",paddingX:1,children:[S(P,{color:z,bold:!0,children:`Resume session${ce.query?` \u2014 filter: ${ce.query}`:" (type to filter)"}`}),Dt.length===0?S(P,{color:"gray",children:"no sessions match"}):Dt.map((a,l)=>F(P,{color:l===ce.cursor?z:void 0,children:[l===ce.cursor?"\u276F ":" ",a.name.slice(0,28).padEnd(30),S(P,{color:l===ce.cursor?z:"gray",children:a.firstPrompt.slice(0,Math.max(10,Ue-40))})]},a.uuid)),S(P,{dimColor:!0,children:"enter resume \xB7 esc cancel"})]}):Io?S(J,{flexDirection:"column",children:ut.map((a,l)=>F(P,{color:l===it?z:void 0,children:[l===it?"\u276F ":" ",a.usage.padEnd(22)," ",S(P,{color:l===it?z:"gray",children:a.name==="model"&&yn?`${a.desc} (currently ${yn})`:a.desc})]},a.name))}):!j&&rt.length>0?F(J,{flexDirection:"column",paddingX:1,children:[rt.map((a,l)=>F(P,{children:[S(P,{color:z,children:l+1})," ",a.slice(0,Math.max(20,Ue-5))]},a)),S(P,{dimColor:!0,children:`press 1-${rt.length} to fill the command \xB7 esc dismiss`})]}):S(J,{paddingX:1,children:F(P,{color:"gray",children:[Do.prod?"\u26A0 PRODUCTION \xB7 ":"",`/help \xB7 ${yn??"model n/a"}${t.kind==="api"?Ao>0?` \xB7 ${ue(Ao)}`:"":Ro>0?` \xB7 ${nt(Ro)}`:""} \xB7 \u2191 history \xB7 ctrl+c exit`]})})]})}H();import{jsx as Hc}from"react/jsx-runtime";async function qs(e=process.cwd(),t="auto",n,o="0.0.0"){let r=Fc(t);r.kind==="none"&&(console.error(""),console.error(x("ANTHROPIC_API_KEY is not set (required for --auth api).")),console.error(`Get a key at ${R("https://console.anthropic.com/settings/keys")}`),console.error(`Or use your Claude subscription instead: ${R("d360-writer --auth subscription")}`),process.exit(2));let{waitUntilExit:s}=Wc(Hc(Bs,{cwd:e,auth:r,profileName:n,version:o}));await s(),process.stdout.write(`
|
|
96
|
+
`),process.exit(0)}var Gc=qc(import.meta.url),zs=Gc("../package.json"),Ce=new Bc;function bo(e){e.env&&(console.error("\u2717 --env was replaced by --profile (connection profiles). Use: --profile <name>"),process.exit(2))}Ce.command("login").description("Sign in to Document360 (browser OAuth; project chosen during login)").option("--profile <name>","Connection profile (defaults to the repo's defaultProfile)").option("--env <name>",!1).option("--manual","No local listener \u2014 paste the redirect URL instead (SSH/locked-down setups)").action(async e=>{bo(e),await Wt({profile:e.profile,manual:e.manual})});Ce.command("logout").description("Remove the stored Document360 session").option("--profile <name>","Connection profile").option("--env <name>",!1).action(async e=>{bo(e),await Ko({profile:e.profile})});Ce.command("whoami").description("Show the current Document360 identity (refreshes if expired)").option("--profile <name>","Connection profile").option("--env <name>",!1).action(async e=>{bo(e),await Jo({profile:e.profile})});var vo=Ce.command("profile").description("Manage connection profiles for the current repo");vo.command("list",{isDefault:!0}).description("List profiles (\u25CF = default)").action(()=>Ft(process.cwd()));vo.command("use <name>").description("Set the default profile for this repo").action(e=>Ht(process.cwd(),e));vo.command("show [name]").description("Print the resolved profile (connection + project)").action(e=>Bt(process.cwd(),e));var Gs=Ce.command("workspace").description("Choose the Document360 workspace for this repo (active profile's project)");Gs.command("select",{isDefault:!0}).description("Interactively pick the workspace (lists in non-TTY)").option("--profile <name>","Connection profile").action(e=>Ze(process.cwd(),e.profile));Gs.command("use <name>").description("Set the workspace by name (scriptable)").option("--profile <name>","Connection profile").action(async(e,t)=>{process.exitCode=await zo(process.cwd(),e,t.profile)});Ce.command("logs").description("Show the Document360 API log files (send these to support when reporting a problem)").action(()=>Zo());Ce.command("doctor").description("Health-check: node, Claude auth, Document360 login, profile/workspace, category map, API reachability").action(async()=>{let{renderDoctorChecks:e,runDoctorChecks:t}=await Promise.resolve().then(()=>(Zt(),Vr)),n=await t(process.cwd());for(let o of e(n))console.log(o);process.exitCode=n.some(o=>o.level==="fail")?1:0});Ce.name("d360-writer").description("Standalone documentation agent CLI. Reads your code, writes your docs.").version(zs.version,"-v, --version").option("-p, --prompt <text>","One-shot prompt mode (non-interactive)").option("-r, --resume <name>","Resume a saved session (with --prompt; use /resume inside the REPL)").option("-C, --cwd <dir>","Working directory",process.cwd()).option("--auth <mode>","Auth mode: auto | api | subscription","auto").option("--profile <name>","Connection profile (defaults to the repo's defaultProfile)").option("--yes","Skip the production write confirmation (for one-shot/CI)").option("--classic","Use the plain readline REPL instead of the Ink TUI").action(async e=>{if(zc.includes(e.auth)||(console.error(`\u2717 Invalid --auth mode: ${e.auth}`),console.error("Run: d360-writer --auth auto | api | subscription"),process.exit(2)),e.prompt){await er(e.cwd,e.prompt,e.auth,e.resume,e.profile,e.yes);return}e.resume&&(console.error("\u2717 --resume requires --prompt. In the interactive REPL, use /resume instead."),process.exit(2)),e.classic||!process.stdin.isTTY?await gs(e.cwd,e.auth,e.profile):await qs(e.cwd,e.auth,e.profile,zs.version)});Ce.parseAsync(process.argv).catch(e=>{console.error(""),console.error(`\u2717 ${e.message}`),process.exit(1)});
|
package/package.json
CHANGED