document360-writer 0.4.3 → 0.4.4

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 CHANGED
@@ -1,64 +1,64 @@
1
1
  #!/usr/bin/env node
2
- var Lr=Object.defineProperty;var qo=(e,t,o)=>()=>{if(o)throw o[0];try{return e&&(t=e(e=0)),t}catch(n){throw o=[n],n}};var Nr=(e,t)=>{for(var o in t)Lr(e,o,{get:t[o],enumerable:!0})};import he from"picocolors";var B,Or,Ur,Wr,zo,ze,c,x,E,T,y,z,te,M=qo(()=>{"use strict";B="#7f56d9",[Or,Ur,Wr]=[127,86,217],zo=e=>he.isColorSupported?`\x1B[38;2;${Or};${Ur};${Wr}m${e}\x1B[39m`:e,ze=e=>he.bold(zo(e)),c=e=>he.dim(e),x=e=>he.red(e),E=e=>he.yellow(e),T=e=>he.green(e),y=zo,z=e=>he.gray(e),te=e=>he.bold(e)});var Nn={};Nr(Nn,{doctorCommand:()=>Ke,renderDoctorChecks:()=>Ln,runDoctorChecks:()=>Mn});import{existsSync as Qs}from"node:fs";import{d360GetAll as Zs,getAccessToken as ei,isExpired as so,loadProfileMap as ti,loadTokens as oi,packageSkillsDir as _n,projectConfigPath as ni,readProjectConfig as ri,resolveActiveProfile as si,resolveAuth as ii,resolveModelSetting as li}from"document360-engine";async function Mn(e){let t=[],o=Number(process.versions.node.split(".")[0]);t.push(o>=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 n=ii("auto");t.push(n.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: ${n.kind==="api"?"API key":"subscription"}`});let r=li(e);t.push({level:"ok",label:`Model: ${r.model??"Claude Code default"} (${r.source})`});let i=ri(e);if(!i)return t.push({level:"fail",label:`No ${ni(e)}`,fix:"Run: /init (or d360-writer init)"}),t;t.push({level:"ok",label:`Project config: ${i.projectId}`});let u=(i.docsDir??"user-docs").replace(/\/+$/,"");t.push(i.mode==="engineer"?{level:"warn",label:"Mode: engineer \u2014 agent may modify any source file (dogfooding)",fix:'Remove "mode" from .d360-writer.json for the writer-mode boundary'}:{level:"ok",label:`Mode: writer \u2014 edits limited to ${u}/, markdown, capture specs, and d360 config`});let p=i.authoritativeSourceFiles??[];t.push(p.length>0?{level:"ok",label:`Docs scope: ${p.length} folder(s) (${p.slice(0,3).join(", ")}${p.length>3?", \u2026":""})`}:{level:"warn",label:"Docs scope not set (authoritativeSourceFiles empty)",fix:"Run: /scope to choose which folders back the docs"});let k;try{k=si(e),t.push({level:"ok",label:`Profile: ${k.name} (${k.connection.name})${k.production?" \u26A0 PRODUCTION":""}`})}catch(R){return t.push({level:"fail",label:`Profile config: ${R.message.split(".")[0]}`,fix:"Run: /init to scaffold the profiles map"}),t}let f=oi(k.name);f?so(f)&&!f.refreshToken?t.push({level:"fail",label:"Document360: session expired (no refresh token)",fix:"/login"}):so(f)?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(f.expiresAt).toLocaleString()})`}):t.push({level:"fail",label:"Document360: not logged in",fix:`Run: /login (or d360-writer login --profile ${k.name})`}),t.push(k.project.workspaceId?{level:"ok",label:`Workspace: ${k.project.workspaceId}`}:{level:"warn",label:"No workspace selected",fix:"Run: /workspace"});let b=ti(e,k.name);if(b?b.projectId&&k.project.projectId&&b.projectId!==k.project.projectId?t.push({level:"fail",label:`Category map projectId (${b.projectId}) \u2260 profile projectId (${k.project.projectId})`,fix:"The map section belongs to a different project \u2014 fix .d360-writer.json or the map before publishing"}):t.push({level:"ok",label:`Category map: ${Object.keys(b.articles).length} articles, ${Object.keys(b.categories).length} categories`}):t.push({level:"warn",label:`No d360-category-map.json section for "${k.name}" (created on first /publish)`}),t.push(Qs(_n())?{level:"ok",label:"Skills bundle present"}:{level:"fail",label:`Skills folder missing at ${_n()}`,fix:"Reinstall document360-writer (broken install)"}),f&&(!so(f)||f.refreshToken)){let R={profile:k.name,connection:k.connection};try{await ei(R);let $=await Zs(R,"/v3/projects");t.push({level:"ok",label:`API reachable (${k.connection.apiUrl}) \u2014 ${$.length} project(s) visible`})}catch($){t.push({level:"fail",label:`API call failed: ${$.message.slice(0,120)}`,fix:"/login if auth-related; otherwise check the apiUrl/network"})}}return t}function Ln(e){let t=[""];for(let r of e){let i=r.level==="ok"?T("\u2713"):r.level==="warn"?E("\u26A0"):x("\u2717");t.push(` ${i} ${r.label}${r.detail?c(` \u2014 ${r.detail}`):""}`),r.fix&&t.push(` ${c("fix:")} ${y(r.fix)}`)}let o=e.filter(r=>r.level==="fail").length,n=e.filter(r=>r.level==="warn").length;return t.push(""),t.push(o===0?T(`\u2713 ${n===0?"All checks passed":`Healthy (${n} warning${n===1?"":"s"})`}`):x(`\u2717 ${o} problem${o===1?"":"s"} found`)),t.push(""),t}async function Ke(e,t){console.log(c("Running checks\u2026"));for(let o of Ln(await Mn(t.cwd)))console.log(o);return{kind:"continue"}}var St=qo(()=>{"use strict";M()});import{Command as Sl}from"commander";import{createRequire as Rl}from"node:module";import{AUTH_MODES as jl}from"document360-engine";import{input as Jr}from"@inquirer/prompts";import{loginPkce as Kr,refreshTokens as Qr,toStoredTokens as Yo,clearTokens as Zr,decodeJwtClaims as Xo,isExpired as es,loadTokens as ts,saveTokens as Jo,resolveActiveProfile as ft,setProfileProject as os,readProjectConfig as ns}from"document360-engine";M();import{select as Br}from"@inquirer/prompts";import{resolveActiveProfile as Hr,setProfileProject as Fr,resolveProjectId as qr,listWorkspaces as zr}from"document360-engine";async function pt(e,t){let o=Hr(e,t),n={profile:o.name,connection:o.connection},r=o.project.projectId??qr(n);return{workspaces:await zr(n,r),projectId:r,profile:o.name,current:o.project.workspaceId}}var Go=e=>`${e.name??e.id}${e.workspace_type?` \xB7 ${e.workspace_type}`:""}`;function Yt(e,t){let o=t.toLowerCase();return e.find(n=>(n.name??"").toLowerCase()===o)??e.find(n=>(n.name??"").toLowerCase().startsWith(o))??e.find(n=>n.id.startsWith(t))}function mt(e,t,o,n){Fr(e,t,{projectId:o,workspaceId:n})}async function Vo(e,t,o){let n;try{n=await pt(e,o)}catch(i){return console.log(x(`Could not list workspaces: ${i.message}`)),1}let r=Yt(n.workspaces,t);return r?(mt(e,n.profile,n.projectId,r.id),console.log(T(`\u2713 Workspace set to "${r.name??r.id}" for profile "${n.profile}".`)),0):(console.log(x(`No workspace matches "${t}". Available: ${n.workspaces.map(i=>i.name??i.id).join(", ")}`)),1)}async function Oe(e,t){let o;try{o=await pt(e,t)}catch(f){console.log(x(`Could not list workspaces: ${f.message}`));return}let{workspaces:n,projectId:r,profile:i,current:u}=o;if(n.length===0){console.log(c("No workspaces found in this project."));return}if(!process.stdin.isTTY){console.log("");for(let f of n)console.log(` ${f.id===u?y("\u25CF"):" "} ${Go(f)} ${c(f.id)}`);console.log(c("Run: d360-writer workspace use <name>"));return}let p=await Br({message:"Select the Document360 workspace for this repo:",choices:n.map(f=>({name:`${Go(f)}${f.id===u?" (current)":""}`,value:f.id}))});mt(e,i,r,p);let k=n.find(f=>f.id===p);console.log(T(`\u2713 Workspace set to "${k?.name??p}" for profile "${i}".`))}M();import Gr from"picocolors";function Vr(e=process.env){return e.FORCE_HYPERLINK==="0"||!Gr.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 Xr(e,t=e,o){return Vr(o)?`\x1B]8;;${e}\x07${t}\x1B]8;;\x07`:t}var Yr=/https?:\/\/[^\s\x1b]+/g;function Ge(e,t){return e.replace(Yr,o=>Xr(o,o,t))}function Ko(e){return{...Xo(e.idToken)??{},...Xo(e.accessToken)??{}}}function gt(e){let t=Ko(e),o=t.email??t.preferred_username??t.sub??"unknown",n=t.doc360_project_id?` \xB7 project ${t.doc360_project_id}`:"";return`${o}${n}`}async function ht(e){let t=ft(process.cwd(),e.profile),o=t.connection;console.log(c(`Profile "${t.name}" \u2192 ${o.name} (${o.apiUrl})${t.production?" \u26A0 PRODUCTION":""}`));let n=await Kr(o,{manual:e.manual,promptForRedirect:i=>Jr({message:i})},i=>console.log(Ge(i))),r=Yo(t.name,n);if(Jo(r),Jt(r,t.name,i=>console.log(c(i))),console.log(""),console.log(T(`\u2713 Logged in to "${t.name}" as ${gt(r)}`)),console.log(c(` access token expires: ${r.expiresAt}`)),console.log(c(` refresh token: ${r.refreshToken?"yes":"NO \u2014 session ends at expiry"}`)),process.stdin.isTTY)try{ns(process.cwd())?.profiles?.[t.name]&&(console.log(""),await Oe(process.cwd(),t.name))}catch{}}function Jt(e,t,o){let r=Ko(e).doc360_project_id;if(!(typeof r!="string"||!r))try{if(ft(process.cwd(),t).project.projectId)return;os(process.cwd(),t,{projectId:r}),o(` Project ${r} written to profile "${t}".`)}catch{}}async function Qo(e){let t=ft(process.cwd(),e.profile),o=t.connection,n=ts(t.name);if(!n){console.log(x(`Not logged in to Document360 (profile "${t.name}").`)),console.log(c(`Run: d360-writer login --profile ${t.name}`)),process.exitCode=1;return}if(console.log(`Profile ${y(t.name)}${t.production?" \u26A0 PRODUCTION":""}: ${gt(n)}`),es(n))if(n.refreshToken)try{let r=Yo(t.name,await Qr(o,n.refreshToken));Jo(r),console.log(T(`\u2713 Session refreshed \u2014 expires ${r.expiresAt}`))}catch(r){console.log(E(`Session expired and refresh failed (${r.message.slice(0,120)})`)),console.log(c(`Run: d360-writer login --profile ${t.name}`)),process.exitCode=1}else console.log(E("Session expired (no refresh token).")),console.log(c(`Run: d360-writer login --profile ${t.name}`)),process.exitCode=1;else console.log(c(` expires: ${n.expiresAt}`))}async function Zo(e){let t=ft(process.cwd(),e.profile);Zr(t.name)?console.log(T(`\u2713 Logged out of Document360 (profile "${t.name}").`)):console.log(c(`No Document360 session for profile "${t.name}" \u2014 nothing to do.`))}M();import{readProjectConfig as en,writeProjectConfig as rs,resolveActiveProfile as ss,loadTokens as is,isExpired as ls}from"document360-engine";function kt(e){let t=en(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[o,n]of Object.entries(t.profiles)){let r=o===t.defaultProfile?y("\u25CF "):" ",i=n.production?E(" \u26A0 PRODUCTION"):"",u=n.connection.environment??"(inline)",p=is(o),k=p?ls(p)&&!p.refreshToken?E("expired"):c("logged in"):c("not logged in");console.log(`${r}${y(o)} \u2192 ${u}${i} [${k}]`)}console.log(""),console.log(c("\u25CF = default. Switch with: d360-writer profile use <name>")),console.log("")}function wt(e,t){let o=en(e);if(!o?.profiles?.[t]){let r=o?.profiles?Object.keys(o.profiles).join(", "):"(none \u2014 run init)";console.log(x(`Unknown profile "${t}". Available: ${r}`)),process.exitCode=1;return}o.defaultProfile=t,rs(o,e);let n=o.profiles[t].production?E(" \u26A0 PRODUCTION"):"";console.log(T(`\u2713 Default profile is now "${t}"${n}`))}function yt(e,t){try{let o=ss(e,t);console.log(""),console.log(`Profile ${y(o.name)}${o.production?E(" \u26A0 PRODUCTION"):""}`),console.log(c(` api: ${o.connection.apiUrl}`)),console.log(c(` identity: ${o.connection.authorizationUrl}`)),console.log(c(` clientId: ${o.connection.clientId}`)),console.log(c(` scopes: ${o.connection.scopes.join(" ")}`)),console.log(c(` project: ${o.project.projectId??"(set at login)"}`)),console.log(c(` workspace:${o.project.workspaceId?" "+o.project.workspaceId:" (none)"}`)),console.log("")}catch(o){console.log(x(o.message)),process.exitCode=1}}M();import{existsSync as as,readdirSync as cs,statSync as us}from"node:fs";import{join as ds}from"node:path";import{apiLogDir as ps}from"document360-engine";function tn(){let e=ps();if(console.log(""),console.log(`Document360 API logs: ${y(e)}`),!as(e)){console.log(c(" No logs yet \u2014 they appear after the first Document360 API call.")),console.log("");return}let t=cs(e).filter(o=>o.endsWith(".jsonl")).sort().reverse();t.length===0&&console.log(c(" No logs yet \u2014 they appear after the first Document360 API call."));for(let o of t.slice(0,14)){let n=(us(ds(e,o)).size/1024).toFixed(1);console.log(` ${o} ${c(`${n} KB`)}`)}console.log(""),console.log(c("Failed calls include request/response bodies (tokens redacted, 4 KB cap).")),console.log(c("Set D360_LOG_BODIES=1 to also log bodies for successful calls.")),console.log("")}M();import{createSession as ms,resolveAuth as fs,findByName as gs,slugify as hs,touchSession as ks,upsertSession as ws,resolveActiveProfile as ys}from"document360-engine";async function on(e,t,o,n,r,i){let u=fs(o);u.kind==="none"&&(console.error(""),console.error(x("ANTHROPIC_API_KEY is not set (required for --auth api).")),console.error(`Get a key at ${y("https://console.anthropic.com/settings/keys")}`),console.error(`Or use your Claude subscription instead: ${y("d360-writer --auth subscription")}`),process.exit(2)),u.kind==="subscription"&&console.error(c("Using your Claude subscription (no API key set)."));let p=null;try{p=ys(e,r)}catch($){console.error(x(`Document360 profile error: ${$.message}`)),process.exit(2)}p.production&&(console.error(E(`\u26A0 Profile "${p.name}" is PRODUCTION.`)),i||(console.error(x("Refusing to run against a production profile without --yes.")),process.exit(2)),console.error(c(" --yes given \u2014 proceeding against production.")));let k;if(n){let $=gs(e,n);$||(console.error(x(`No saved session matches "${n}" in this repo.`)),console.error(c("List sessions inside the REPL with /resume.")),process.exit(2)),k=$.uuid,console.error(c(`Resuming "${$.name}"`))}let f=ms({cwd:e,resume:k,profileName:r,allowProdWrites:i===!0}),b=k??null,R=1;for await(let $ of f.send(t))switch($.type){case"session":if(!b){b=$.sessionId;let S=new Date().toISOString();ws({uuid:b,name:hs(t),renamed:!1,titled:!1,cwd:e,firstPrompt:t,createdAt:S,updatedAt:S})}break;case"text":process.stdout.write($.delta);break;case"tool":console.error(z(` \u2699 ${$.name}`));break;case"result":R=$.ok?0:1,console.error(c(`(${$.inputTokens}\u2192${$.outputTokens} tokens)`)),$.ok||console.error(x("agent finished with an error result"));break;case"error":console.error(""),console.error(x(`agent error: ${$.message}`)),process.exit(1)}b&&ks(b),process.stdout.write(`
3
- `),process.exit(R)}import{createInterface as hi}from"node:readline/promises";import{createSession as ao,resolveAuth as ki,getSession as wi,setTitle as yi,slugify as xi,touchSession as Xn,upsertSession as $i,generateTitle as bi,resolveActiveProfile as Yn,resolveModelSetting as vi,readProjectConfig as Ci,decodeJwtClaims as Gn,isExpired as Pi,loadTokens as Ti}from"document360-engine";M();async function Kt(){let e=["",te("document360-writer \u2014 slash commands"),"",` ${y("/help")} ${c("Show this help")}`,` ${y("/init")} ${c("Scaffold .d360-writer.json in this repo")}`,` ${y("/mcp add <name> <type> <ref>")} ${c("Register an MCP server (stdio|http|sse; -H key:value for auth)")}`,` ${y("/mcp list")} ${c("Show registered MCP servers")}`,` ${y("/mcp remove <name>")} ${c("Unregister an MCP server")}`,` ${y("/publish [path|--all]")} ${c("Publish to Document360 (no arg: pick; --all: every candidate)")}`,` ${y("/sync")} ${c("Drift report: local docs vs Document360 (no tokens)")}`,` ${y("/sync pull <path>|--all")} ${c("Pull portal edits into local markdown (diff + confirm)")}`,` ${y("/scope")} ${c("Choose which repo folders back the docs (analyses + recommends)")}`,` ${y("/audit")} ${c("Gap analysis: code vs docs vs Document360 (incremental)")}`,` ${y("/screenshot <id>")} ${c("Emit a document360-capture-compatible spec")}`,` ${y("/resume [name]")} ${c("Resume a session (no arg: searchable picker)")}`,` ${y("/rename <name>")} ${c("Name the current session")}`,` ${y("/login")} ${c("Sign in to Document360 (browser) without leaving the session")}`,` ${y("/profile [name|add <name> [env]]")} ${c("Switch connection profile, or create one from a preset")}`,` ${y("/model [name|default]")} ${c("Show or set the Claude model (personal setting)")}`,` ${y("/doctor")} ${c("Health-check: auth, profile, workspace, map, API")}`,` ${y("/workspace [name]")} ${c("List or switch the Document360 workspace")}`,` ${y("/allow-prod")} ${c("Authorize writes to a production profile (this session)")}`,` ${y("/clear")} ${c("Reset conversation")}`,` ${y("/exit")} ${c("Quit")}`,"",c("Anything not starting with / is sent to the agent."),c("Reporting a problem? Run `d360-writer logs` from your shell for the API log files."),""];for(let t of e)console.log(t);return{kind:"continue"}}M();import{getSession as xs}from"document360-engine";async function nn(e,t){let o=t.currentUuid(),n=o?xs(o):void 0;return console.log(n?c(`
4
- (conversation reset \u2014 "${n.name}" is still available via /resume)
2
+ var Or=Object.defineProperty;var Gn=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(o){throw n=[o],o}};var Ur=(e,t)=>{for(var n in t)Or(e,n,{get:t[n],enumerable:!0})};import ke from"picocolors";var U,Wr,Br,Hr,Xn,Xe,c,x,E,T,w,z,ne,L=Gn(()=>{"use strict";U="#7f56d9",[Wr,Br,Hr]=[127,86,217],Xn=e=>ke.isColorSupported?`\x1B[38;2;${Wr};${Br};${Hr}m${e}\x1B[39m`:e,Xe=e=>ke.bold(Xn(e)),c=e=>ke.dim(e),x=e=>ke.red(e),E=e=>ke.yellow(e),T=e=>ke.green(e),w=Xn,z=e=>ke.gray(e),ne=e=>ke.bold(e)});var Uo={};Ur(Uo,{doctorCommand:()=>Ze,renderDoctorChecks:()=>Oo,runDoctorChecks:()=>No});import{existsSync as ei}from"node:fs";import{d360GetAll as ti,getAccessToken as ni,isExpired as an,loadProfileMap as oi,loadTokens as ri,packageSkillsDir as Lo,projectConfigPath as si,readProjectConfig as ii,resolveActiveProfile as li,resolveAuth as ai,resolveModelSetting as ci}from"document360-engine";async function No(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=ai("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=ci(e);t.push({level:"ok",label:`Model: ${r.model??"Claude Code default"} (${r.source})`});let l=ii(e);if(!l)return t.push({level:"fail",label:`No ${si(e)}`,fix:"Run: /init (or d360-writer init)"}),t;t.push({level:"ok",label:`Project config: ${l.projectId}`});let u=(l.docsDir??"user-docs").replace(/\/+$/,"");t.push(l.mode==="engineer"?{level:"warn",label:"Mode: engineer \u2014 agent may modify any source file (dogfooding)",fix:'Remove "mode" from .d360-writer.json for the writer-mode boundary'}:{level:"ok",label:`Mode: writer \u2014 edits limited to ${u}/, markdown, capture specs, and d360 config`});let p=l.authoritativeSourceFiles??[];t.push(p.length>0?{level:"ok",label:`Docs scope: ${p.length} folder(s) (${p.slice(0,3).join(", ")}${p.length>3?", \u2026":""})`}:{level:"warn",label:"Docs scope not set (authoritativeSourceFiles empty)",fix:"Run: /scope to choose which folders back the docs"});let k;try{k=li(e),t.push({level:"ok",label:`Profile: ${k.name} (${k.connection.name})${k.production?" \u26A0 PRODUCTION":""}`})}catch(R){return t.push({level:"fail",label:`Profile config: ${R.message.split(".")[0]}`,fix:"Run: /init to scaffold the profiles map"}),t}let f=ri(k.name);f?an(f)&&!f.refreshToken?t.push({level:"fail",label:"Document360: session expired (no refresh token)",fix:"/login"}):an(f)?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(f.expiresAt).toLocaleString()})`}):t.push({level:"fail",label:"Document360: not logged in",fix:`Run: /login (or d360-writer login --profile ${k.name})`}),t.push(k.project.workspaceId?{level:"ok",label:`Workspace: ${k.project.workspaceId}`}:{level:"warn",label:"No workspace selected",fix:"Run: /workspace"});let v=oi(e,k.name);if(v?v.projectId&&k.project.projectId&&v.projectId!==k.project.projectId?t.push({level:"fail",label:`Category map projectId (${v.projectId}) \u2260 profile projectId (${k.project.projectId})`,fix:"The map section belongs to a different project \u2014 fix .d360-writer.json or the map before publishing"}):t.push({level:"ok",label:`Category map: ${Object.keys(v.articles).length} articles, ${Object.keys(v.categories).length} categories`}):t.push({level:"warn",label:`No d360-category-map.json section for "${k.name}" (created on first /publish)`}),t.push(ei(Lo())?{level:"ok",label:"Skills bundle present"}:{level:"fail",label:`Skills folder missing at ${Lo()}`,fix:"Reinstall document360-writer (broken install)"}),f&&(!an(f)||f.refreshToken)){let R={profile:k.name,connection:k.connection};try{await ni(R);let b=await ti(R,"/v3/projects");t.push({level:"ok",label:`API reachable (${k.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 Oo(e){let t=[""];for(let r of e){let l=r.level==="ok"?T("\u2713"):r.level==="warn"?E("\u26A0"):x("\u2717");t.push(` ${l} ${r.label}${r.detail?c(` \u2014 ${r.detail}`):""}`),r.fix&&t.push(` ${c("fix:")} ${w(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?T(`\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 Ze(e,t){console.log(c("Running checks\u2026"));for(let n of Oo(await No(t.cwd)))console.log(n);return{kind:"continue"}}var jt=Gn(()=>{"use strict";L()});import{Command as Il}from"commander";import{createRequire as El}from"node:module";import{AUTH_MODES as Dl}from"document360-engine";import{input as Qr}from"@inquirer/prompts";import{loginPkce as Zr,refreshTokens as es,toStoredTokens as Kn,clearTokens as ts,decodeJwtClaims as Jn,isExpired as ns,loadTokens as os,saveTokens as Qn,resolveActiveProfile as ht,setProfileProject as rs,readProjectConfig as ss}from"document360-engine";L();import{select as Fr}from"@inquirer/prompts";import{resolveActiveProfile as qr,setProfileProject as zr,resolveProjectId as Gr,listWorkspaces as Xr}from"document360-engine";async function ft(e,t){let n=qr(e,t),o={profile:n.name,connection:n.connection},r=n.project.projectId??Gr(o);return{workspaces:await Xr(o,r),projectId:r,profile:n.name,environment:n.connection.name,current:n.project.workspaceId}}var Vn=e=>`${e.name??e.id}${e.workspace_type?` \xB7 ${e.workspace_type}`:""}`;function Kt(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 gt(e,t,n,o){zr(e,t,{projectId:n,workspaceId:o})}async function Yn(e,t,n){let o;try{o=await ft(e,n)}catch(l){return console.log(x(`Could not list workspaces: ${l.message}`)),1}let r=Kt(o.workspaces,t);return r?(gt(e,o.profile,o.projectId,r.id),console.log(T(`\u2713 Workspace set to "${r.name??r.id}" for profile "${o.profile}".`)),0):(console.log(x(`No workspace matches "${t}". Available: ${o.workspaces.map(l=>l.name??l.id).join(", ")}`)),1)}async function We(e,t){let n;try{n=await ft(e,t)}catch(f){console.log(x(`Could not list workspaces: ${f.message}`));return}let{workspaces:o,projectId:r,profile:l,current:u}=n;if(o.length===0){console.log(c("No workspaces found in this project."));return}if(!process.stdin.isTTY){console.log("");for(let f of o)console.log(` ${f.id===u?w("\u25CF"):" "} ${Vn(f)} ${c(f.id)}`);console.log(c("Run: d360-writer workspace use <name>"));return}let p=await Fr({message:"Select the Document360 workspace for this repo:",choices:o.map(f=>({name:`${Vn(f)}${f.id===u?" (current)":""}`,value:f.id}))});gt(e,l,r,p);let k=o.find(f=>f.id===p);console.log(T(`\u2713 Workspace set to "${k?.name??p}" for profile "${l}".`))}L();import Vr from"picocolors";function Yr(e=process.env){return e.FORCE_HYPERLINK==="0"||!Vr.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 Jr(e,t=e,n){return Yr(n)?`\x1B]8;;${e}\x07${t}\x1B]8;;\x07`:t}var Kr=/https?:\/\/[^\s\x1b]+/g;function Ve(e,t){return e.replace(Kr,n=>Jr(n,n,t))}function Zn(e){return{...Jn(e.idToken)??{},...Jn(e.accessToken)??{}}}function kt(e){let t=Zn(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=ht(process.cwd(),e.profile),n=t.connection;console.log(c(`Profile "${t.name}" \u2192 ${n.name} (${n.apiUrl})${t.production?" \u26A0 PRODUCTION":""}`));let o=await Zr(n,{manual:e.manual,promptForRedirect:l=>Qr({message:l})},l=>console.log(Ve(l))),r=Kn(t.name,o);if(Qn(r),Qt(r,t.name,l=>console.log(c(l))),console.log(""),console.log(T(`\u2713 Logged in to "${t.name}" as ${kt(r)}`)),console.log(c(` access token expires: ${r.expiresAt}`)),console.log(c(` refresh token: ${r.refreshToken?"yes":"NO \u2014 session ends at expiry"}`)),process.stdin.isTTY)try{ss(process.cwd())?.profiles?.[t.name]&&(console.log(""),await We(process.cwd(),t.name))}catch{}}function Qt(e,t,n){let r=Zn(e).doc360_project_id;if(!(typeof r!="string"||!r))try{if(ht(process.cwd(),t).project.projectId)return;rs(process.cwd(),t,{projectId:r}),n(` Project ${r} written to profile "${t}".`)}catch{}}async function eo(e){let t=ht(process.cwd(),e.profile),n=t.connection,o=os(t.name);if(!o){console.log(x(`Not logged in to Document360 (profile "${t.name}").`)),console.log(c(`Run: d360-writer login --profile ${t.name}`)),process.exitCode=1;return}if(console.log(`Profile ${w(t.name)}${t.production?" \u26A0 PRODUCTION":""}: ${kt(o)}`),ns(o))if(o.refreshToken)try{let r=Kn(t.name,await es(n,o.refreshToken));Qn(r),console.log(T(`\u2713 Session refreshed \u2014 expires ${r.expiresAt}`))}catch(r){console.log(E(`Session expired and refresh failed (${r.message.slice(0,120)})`)),console.log(c(`Run: d360-writer login --profile ${t.name}`)),process.exitCode=1}else console.log(E("Session expired (no refresh token).")),console.log(c(`Run: d360-writer login --profile ${t.name}`)),process.exitCode=1;else console.log(c(` expires: ${o.expiresAt}`))}async function to(e){let t=ht(process.cwd(),e.profile);ts(t.name)?console.log(T(`\u2713 Logged out of Document360 (profile "${t.name}").`)):console.log(c(`No Document360 session for profile "${t.name}" \u2014 nothing to do.`))}L();import{readProjectConfig as no,writeProjectConfig as is,resolveActiveProfile as ls,loadTokens as as,isExpired as cs}from"document360-engine";function yt(e){let t=no(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?w("\u25CF "):" ",l=o.production?E(" \u26A0 PRODUCTION"):"",u=o.connection.environment??"(inline)",p=as(n),k=p?cs(p)&&!p.refreshToken?E("expired"):c("logged in"):c("not logged in");console.log(`${r}${w(n)} \u2192 ${u}${l} [${k}]`)}console.log(""),console.log(c("\u25CF = default. Switch with: d360-writer profile use <name>")),console.log("")}function xt(e,t){let n=no(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,is(n,e);let o=n.profiles[t].production?E(" \u26A0 PRODUCTION"):"";console.log(T(`\u2713 Default profile is now "${t}"${o}`))}function $t(e,t){try{let n=ls(e,t);console.log(""),console.log(`Profile ${w(n.name)}${n.production?E(" \u26A0 PRODUCTION"):""}`),console.log(c(` api: ${n.connection.apiUrl}`)),console.log(c(` identity: ${n.connection.authorizationUrl}`)),console.log(c(` clientId: ${n.connection.clientId}`)),console.log(c(` scopes: ${n.connection.scopes.join(" ")}`)),console.log(c(` project: ${n.project.projectId??"(set at login)"}`)),console.log(c(` workspace:${n.project.workspaceId?" "+n.project.workspaceId:" (none)"}`)),console.log("")}catch(n){console.log(x(n.message)),process.exitCode=1}}L();import{existsSync as us,readdirSync as ds,statSync as ps}from"node:fs";import{join as ms}from"node:path";import{apiLogDir as fs}from"document360-engine";function oo(){let e=fs();if(console.log(""),console.log(`Document360 API logs: ${w(e)}`),!us(e)){console.log(c(" No logs yet \u2014 they appear after the first Document360 API call.")),console.log("");return}let t=ds(e).filter(n=>n.endsWith(".jsonl")).sort().reverse();t.length===0&&console.log(c(" No logs yet \u2014 they appear after the first Document360 API call."));for(let n of t.slice(0,14)){let o=(ps(ms(e,n)).size/1024).toFixed(1);console.log(` ${n} ${c(`${o} KB`)}`)}console.log(""),console.log(c("Failed calls include request/response bodies (tokens redacted, 4 KB cap).")),console.log(c("Set D360_LOG_BODIES=1 to also log bodies for successful calls.")),console.log("")}L();import{createSession as gs,resolveAuth as hs,findByName as ks,slugify as ws,touchSession as ys,upsertSession as xs,resolveActiveProfile as $s}from"document360-engine";async function ro(e,t,n,o,r,l){let u=hs(n);u.kind==="none"&&(console.error(""),console.error(x("ANTHROPIC_API_KEY is not set (required for --auth api).")),console.error(`Get a key at ${w("https://console.anthropic.com/settings/keys")}`),console.error(`Or use your Claude subscription instead: ${w("d360-writer --auth subscription")}`),process.exit(2)),u.kind==="subscription"&&console.error(c("Using your Claude subscription (no API key set)."));let p=null;try{p=$s(e,r)}catch(b){console.error(x(`Document360 profile error: ${b.message}`)),process.exit(2)}p.production&&(console.error(E(`\u26A0 Profile "${p.name}" is PRODUCTION.`)),l||(console.error(x("Refusing to run against a production profile without --yes.")),process.exit(2)),console.error(c(" --yes given \u2014 proceeding against production.")));let k;if(o){let b=ks(e,o);b||(console.error(x(`No saved session matches "${o}" in this repo.`)),console.error(c("List sessions inside the REPL with /resume.")),process.exit(2)),k=b.uuid,console.error(c(`Resuming "${b.name}"`))}let f=gs({cwd:e,resume:k,profileName:r,allowProdWrites:l===!0}),v=k??null,R=1;for await(let b of f.send(t))switch(b.type){case"session":if(!v){v=b.sessionId;let S=new Date().toISOString();xs({uuid:v,name:ws(t),renamed:!1,titled:!1,cwd:e,firstPrompt:t,createdAt:S,updatedAt:S})}break;case"text":process.stdout.write(b.delta);break;case"tool":console.error(z(` \u2699 ${b.name}`));break;case"result":R=b.ok?0:1,console.error(c(`(${b.inputTokens}\u2192${b.outputTokens} tokens)`)),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)}v&&ys(v),process.stdout.write(`
3
+ `),process.exit(R)}import{createInterface as wi}from"node:readline/promises";import{createSession as dn,resolveAuth as yi,getSession as xi,setTitle as $i,slugify as bi,touchSession as Jo,upsertSession as vi,generateTitle as Ci,resolveActiveProfile as Ko,resolveModelSetting as Pi,readProjectConfig as Ti,decodeJwtClaims as Vo,isExpired as Si,loadTokens as Ri}from"document360-engine";L();async function Zt(){let e=["",ne("document360-writer \u2014 slash commands"),"",` ${w("/help")} ${c("Show this help")}`,` ${w("/init")} ${c("Pick a Document360 environment & scaffold .d360-writer.json")}`,` ${w("/mcp add <name> <type> <ref>")} ${c("Register an MCP server (stdio|http|sse; -H key:value for auth)")}`,` ${w("/mcp list")} ${c("Show registered MCP servers")}`,` ${w("/mcp remove <name>")} ${c("Unregister an MCP server")}`,` ${w("/publish [path|--all]")} ${c("Publish to Document360 (no arg: pick; --all: every candidate)")}`,` ${w("/sync")} ${c("Drift report: local docs vs Document360 (no tokens)")}`,` ${w("/sync pull <path>|--all")} ${c("Pull portal edits into local markdown (diff + confirm)")}`,` ${w("/scope")} ${c("Choose which repo folders back the docs (analyses + recommends)")}`,` ${w("/audit")} ${c("Gap analysis: code vs docs vs Document360 (incremental)")}`,` ${w("/screenshot <id>")} ${c("Emit a document360-capture-compatible spec")}`,` ${w("/resume [name]")} ${c("Resume a session (no arg: searchable picker)")}`,` ${w("/rename <name>")} ${c("Name the current session")}`,` ${w("/login")} ${c("Sign in to Document360 (browser) without leaving the session")}`,` ${w("/profile [name|add <name> [env]]")} ${c("Switch connection profile, or create one from a preset")}`,` ${w("/model [name|default]")} ${c("Show or set the Claude model (personal setting)")}`,` ${w("/doctor")} ${c("Health-check: auth, profile, workspace, map, API")}`,` ${w("/workspace [name]")} ${c("List or switch the Document360 workspace")}`,` ${w("/allow-prod")} ${c("Authorize writes to a production profile (this session)")}`,` ${w("/clear")} ${c("Reset conversation")}`,` ${w("/exit")} ${c("Quit")}`,"",c("Anything not starting with / is sent to the agent."),c("Reporting a problem? Run `d360-writer logs` from your shell for the API log files."),""];for(let t of e)console.log(t);return{kind:"continue"}}L();import{getSession as bs}from"document360-engine";async function so(e,t){let n=t.currentUuid(),o=n?bs(n):void 0;return console.log(o?c(`
4
+ (conversation reset \u2014 "${o.name}" is still available via /resume)
5
5
  `):c(`
6
6
  (conversation reset \u2014 agent will start fresh on the next prompt)
7
- `)),{kind:"clear"}}async function Qt(){return{kind:"exit"}}M();import{input as Ve,confirm as $s}from"@inquirer/prompts";import{basename as rn,join as Zt}from"node:path";import{existsSync as Xe,readFileSync as bs,readdirSync as vs}from"node:fs";import{writeProjectConfig as sn,readProjectConfig as Cs,projectConfigPath as ln}from"document360-engine";function an(e){let t=ln(e);if(Xe(t))return{created:!1,path:t,profileName:""};let o={projectId:un(e)??rn(e),captureDir:"user-docs/_capture",outputDir:"user-docs/_screenshots",profiles:{berlin:{connection:{environment:"berlin"},production:!1}},defaultProfile:"berlin",authoritativeSourceFiles:dn(e)};return sn(o,e),{created:!0,path:t,profileName:"berlin"}}async function cn(){let e=process.cwd(),t=ln(e);if(Xe(t)&&!await $s({message:`${t} already exists. Overwrite?`,default:!1}))return console.log(c("init cancelled.")),{kind:"continue"};let o=un(e)??rn(e),n=await Ve({message:"Project ID (used to scope sessions, screenshots, etc.):",default:o}),r=await Ve({message:"Capture directory (where document360-capture .spec.ts files live):",default:"user-docs/_capture"}),i=await Ve({message:"Screenshot output directory:",default:"user-docs/_screenshots"}),u=await Ve({message:"Default connection profile name:",default:"berlin"}),p=await Ve({message:"Document360 environment for this profile (baked preset):",default:"berlin"}),k={projectId:n,captureDir:r,outputDir:i,profiles:{[u]:{connection:{environment:p},production:!1}},defaultProfile:u,authoritativeSourceFiles:dn(e)},f=Cs(e);return f?.terminologyGlossary&&(k.terminologyGlossary=f.terminologyGlossary),sn(k,e),console.log(""),console.log(T(`\u2713 Wrote ${t}`)),console.log(""),console.log("Next:"),console.log(` ${y(`d360-writer login --profile ${u}`)} ${c("(sign in; pick the project)")}`),console.log(' Then ask the agent: "analyze this repo and propose a docs structure"'),console.log(""),{kind:"continue"}}function un(e){let t=Zt(e,"package.json");if(!Xe(t))return null;try{return JSON.parse(bs(t,"utf8")).name??null}catch{return null}}function dn(e){let t=[];for(let o of["README.md","ARCHITECTURE.md","CLAUDE.md"])Xe(Zt(e,o))&&t.push(o);for(let o of["src","api","docs"]){let n=Zt(e,o);Xe(n)&&!Ps(n)&&t.push(o)}return t}function Ps(e){try{return vs(e,{withFileTypes:!0}).filter(o=>o.isDirectory()&&!o.name.startsWith(".")).length>6}catch{return!1}}M();import{readMcpConfig as eo,writeMcpConfig as pn}from"document360-engine";async function xt(e){let t=(e[0]??"").toLowerCase();return t==="list"||!t?(Ts(),{kind:"continue"}):t==="add"?(Ss(e.slice(1)),{kind:"continue"}):t==="remove"||t==="rm"?(Rs(e.slice(1)),{kind:"continue"}):(console.log(x(`Unknown /mcp subcommand: ${t}`)),console.log(c("Try: /mcp add <name> <stdio|http|sse> <command-or-url>, /mcp list, /mcp remove <name>")),{kind:"continue"})}function Ts(){let e=eo(),t=Object.keys(e.servers);if(t.length===0){console.log(c(`
7
+ `)),{kind:"clear"}}async function en(){return{kind:"exit"}}L();import{input as Ye,confirm as vs}from"@inquirer/prompts";import{basename as io,join as tn}from"node:path";import{existsSync as Je,readFileSync as Cs,readdirSync as Ps}from"node:fs";import{writeProjectConfig as lo,readProjectConfig as Ts,projectConfigPath as ao}from"document360-engine";function co(e,t="berlin"){let n=ao(e);if(Je(n))return{created:!1,path:n,profileName:""};let o={projectId:po(e)??io(e),captureDir:"user-docs/_capture",outputDir:"user-docs/_screenshots",profiles:{[t]:{connection:{environment:t},production:!1}},defaultProfile:t,authoritativeSourceFiles:mo(e)};return lo(o,e),{created:!0,path:n,profileName:t}}async function uo(){let e=process.cwd(),t=ao(e);if(Je(t)&&!await vs({message:`${t} already exists. Overwrite?`,default:!1}))return console.log(c("init cancelled.")),{kind:"continue"};let n=po(e)??io(e),o=await Ye({message:"Project ID (used to scope sessions, screenshots, etc.):",default:n}),r=await Ye({message:"Capture directory (where document360-capture .spec.ts files live):",default:"user-docs/_capture"}),l=await Ye({message:"Screenshot output directory:",default:"user-docs/_screenshots"}),u=await Ye({message:"Default connection profile name:",default:"berlin"}),p=await Ye({message:"Document360 environment for this profile (baked preset):",default:"berlin"}),k={projectId:o,captureDir:r,outputDir:l,profiles:{[u]:{connection:{environment:p},production:!1}},defaultProfile:u,authoritativeSourceFiles:mo(e)},f=Ts(e);return f?.terminologyGlossary&&(k.terminologyGlossary=f.terminologyGlossary),lo(k,e),console.log(""),console.log(T(`\u2713 Wrote ${t}`)),console.log(""),console.log("Next:"),console.log(` ${w(`d360-writer login --profile ${u}`)} ${c("(sign in; pick the project)")}`),console.log(' Then ask the agent: "analyze this repo and propose a docs structure"'),console.log(""),{kind:"continue"}}function po(e){let t=tn(e,"package.json");if(!Je(t))return null;try{return JSON.parse(Cs(t,"utf8")).name??null}catch{return null}}function mo(e){let t=[];for(let n of["README.md","ARCHITECTURE.md","CLAUDE.md"])Je(tn(e,n))&&t.push(n);for(let n of["src","api","docs"]){let o=tn(e,n);Je(o)&&!Ss(o)&&t.push(n)}return t}function Ss(e){try{return Ps(e,{withFileTypes:!0}).filter(n=>n.isDirectory()&&!n.name.startsWith(".")).length>6}catch{return!1}}L();import{readMcpConfig as nn,writeMcpConfig as fo}from"document360-engine";async function bt(e){let t=(e[0]??"").toLowerCase();return t==="list"||!t?(Rs(),{kind:"continue"}):t==="add"?(js(e.slice(1)),{kind:"continue"}):t==="remove"||t==="rm"?(As(e.slice(1)),{kind:"continue"}):(console.log(x(`Unknown /mcp subcommand: ${t}`)),console.log(c("Try: /mcp add <name> <stdio|http|sse> <command-or-url>, /mcp list, /mcp remove <name>")),{kind:"continue"})}function Rs(){let e=nn(),t=Object.keys(e.servers);if(t.length===0){console.log(c(`
8
8
  No MCP servers registered. Add one with /mcp add <name> <type> <ref>
9
- `));return}console.log(""),console.log("Registered MCP servers (~/.document360-writer/mcp.json):");for(let o of t){let n=e.servers[o];if(n.type==="stdio")console.log(` ${y(o)} ${c("(stdio)")} ${n.command} ${(n.args??[]).join(" ")}`);else{let r=Object.keys(n.headers??{}),i=r.length>0?c(` [headers: ${r.join(", ")}]`):"";console.log(` ${y(o)} ${c(`(${n.type})`)} ${n.url}${i}`)}}console.log("")}function Ss(e){let[t,o,...n]=e;if(!t||!o||n.length===0){console.log(x("Usage: /mcp add <name> <stdio|http|sse> <command-or-url> [args...] [-H key:value ...]"));return}if(o!=="stdio"&&o!=="http"&&o!=="sse"){console.log(x(`Unknown transport: ${o}. Use stdio, http, or sse.`));return}let r=eo(),i;if(o==="stdio")i={type:"stdio",command:n[0],args:n.slice(1)};else{let u={};for(let p=1;p<n.length;p++)if(n[p]==="-H"||n[p]==="--header"){let k=n[++p],f=k?.match(/^([^:=]+)[:=](.+)$/);if(!f){console.log(x(`-H expects key:value (no spaces). Got: ${k??"(nothing)"}`));return}u[f[1].trim()]=f[2].trim()}else{console.log(x(`Unexpected argument: ${n[p]}. After the URL, only -H key:value is allowed.`));return}i={type:o,url:n[0],headers:Object.keys(u).length>0?u:void 0}}r.servers[t]=i,pn(r),console.log(""),console.log(T(`\u2713 Registered "${t}" (${o})`)),console.log(E(" This server loads on your next prompt. The current agent session reads MCP config at startup.")),console.log(c(" Run /clear if you want the next turn to reload immediately.")),console.log("")}function Rs(e){let t=e[0];if(!t){console.log(x("Usage: /mcp remove <name>"));return}let o=eo();if(!o.servers[t]){console.log(x(`No server named "${t}".`));return}delete o.servers[t],pn(o),console.log(T(`\u2713 Removed "${t}".`)),console.log(c(" Run /clear to drop it from the current session immediately."))}M();import{select as js}from"@inquirer/prompts";import{computeSyncStatus as mn}from"document360-engine";function bt(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(`
10
- `)}var fn={"local-ahead":"modified locally","untracked-local":"new (never published)",conflict:"\u26A0 conflict \u2014 publishing overwrites the portal edit"};function $t(e){return e.filter(t=>t.path!==null&&t.status in fn).map(t=>({path:t.path,label:fn[t.status]}))}function Ye(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(`
11
- `)}async function gn(e,t){let o=e[0];if(o==="--all"){console.log(c("Checking what needs publishing\u2026"));try{let n=$t((await mn({cwd:t?.cwd??process.cwd()})).entries);return n.length===0?(console.log(T("\u2713 Nothing is ahead of Document360 \u2014 no publish candidates.")),{kind:"continue"}):{kind:"forward-to-agent",prompt:Ye(n.map(r=>r.path)),display:"/publish --all"}}catch(n){return console.log(x(`Could not compute sync status: ${n.message}`)),{kind:"continue"}}}if(!o){console.log(c("Checking what needs publishing\u2026"));let n;try{n=$t((await mn({cwd:t?.cwd??process.cwd()})).entries)}catch(r){return console.log(x(`Could not compute sync status: ${r.message}`)),console.log(c("Publish a specific article: /publish <article-path>")),{kind:"continue"}}if(n.length===0)return console.log(T("\u2713 Nothing is ahead of Document360 \u2014 no publish candidates.")),console.log(c(" (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 n)console.log(` ${r.path} ${c(`(${r.label})`)}`);return console.log(c("Run: /publish <article-path>")),{kind:"continue"}}try{o=await t.withPausedInput(()=>js({message:"Publish which article?",choices:[...n.length>1?[{name:`All ${n.length} candidates`,value:"--all",description:"one agent run over every candidate"}]:[],...n.map(r=>({name:r.path,value:r.path,description:r.label}))]}))}catch{return console.log(c("Cancelled.")),{kind:"continue"}}if(o==="--all")return{kind:"forward-to-agent",prompt:Ye(n.map(r=>r.path)),display:"/publish --all"}}return{kind:"forward-to-agent",prompt:bt(o),display:`/publish ${o}`}}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(`
12
- `),display:"/audit"}}M();import{checkbox as As}from"@inquirer/prompts";import{inventoryRepo as Is,readProjectConfig as hn,writeProjectConfig as Es}from"document360-engine";function to(e,t){let o=hn(e);o&&(o.authoritativeSourceFiles=t,Es(o,e))}function Ct(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 kn(e,t){let o=t?.cwd??process.cwd();if(!hn(o))return console.log(x("No .d360-writer.json here. Run /init first.")),{kind:"continue"};let n=Is(o);if(n.length===0)return console.log(c('No candidate source folders found. Set "authoritativeSourceFiles" in .d360-writer.json manually.')),{kind:"continue"};if(!process.stdin.isTTY||!t){console.log(""),console.log(y("Recommended documentation scope (run /scope in the REPL to choose):"));for(let i of n)console.log(` ${i.recommended?"\u25C9":"\u25CB"} ${i.path} ${c(Ct(i))}`);return console.log(""),{kind:"continue"}}let r;try{r=await t.withPausedInput(()=>As({message:"Which folders back the user docs? (space toggles, enter confirms)",choices:n.map(i=>({name:`${i.path} (${Ct(i)})`,value:i.path,checked:i.recommended})),pageSize:20}))}catch{return console.log(c("Cancelled.")),{kind:"continue"}}if(r.length===0)return console.log(c("Nothing selected \u2014 scope unchanged.")),{kind:"continue"};to(o,r),console.log(T(`\u2713 Scoped to ${r.length} folder(s) \u2014 written to .d360-writer.json`));for(let i of r)console.log(` ${i}`);return console.log(""),{kind:"continue"}}M();import{confirm as Ns}from"@inquirer/prompts";import{applyPull as bn,computeSyncStatus as vn,planPull as Os,D360AuthError as Us}from"document360-engine";M();var wn=[{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:E,mark:"M"},{status:"remote-ahead",header:"Remote ahead \u2014 pull with /sync pull <path>:",paint:y,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:z,mark:"X"},{status:"untracked-local",header:"Untracked local articles \u2014 publish to start tracking:",paint:c,mark:"?"},{status:"untracked-remote",header:"Untracked Document360 articles \u2014 no local file maps to them:",paint:c,mark:"?"},{status:"unknown-base",header:"No sync base recorded yet \u2014 the next /publish or /sync pull of each records one:",paint:z,mark:"\xB7"}];function Ds(e){return e.path?e.path:`${e.title??"(untitled)"} ${z(`[${e.articleId}]`)}`}function Pt(e){let t=[];for(let u of wn){let p=e.entries.filter(k=>k.status===u.status);if(p.length!==0){t.push(""),t.push(te(u.header));for(let k of p)t.push(` ${u.paint(u.mark)} ${u.paint(Ds(k))}${k.detail?z(` (${k.detail})`):""}`)}}let o=e.counts["in-sync"]??0,n=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"},i=n===o?T("\u2713 everything in sync"):[o>0?T(`\u2713 ${o} in sync`):null,...wn.map(u=>{let p=e.counts[u.status]??0;return p>0?`${p} ${r[u.status]}`:null})].filter(Boolean).join(z(" \xB7 "));return t.push(i+z(` \xB7 ${n} tracked+seen \xB7 profile "${e.profile}" \xB7 docs root ${e.docsRoot}/`)),t}import{structuredPatch as _s}from"diff";import yn from"picocolors";var xn=80,Ms="\x1B[48;2;74;28;28m",Ls="\x1B[48;2;24;66;24m",$n="\x1B[49m",oo=e=>String(e).padStart(5);function Re(e,t,o){let n=$=>{let S=$.replace(/\r\n/g,`
9
+ `));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(` ${w(n)} ${c("(stdio)")} ${o.command} ${(o.args??[]).join(" ")}`);else{let r=Object.keys(o.headers??{}),l=r.length>0?c(` [headers: ${r.join(", ")}]`):"";console.log(` ${w(n)} ${c(`(${o.type})`)} ${o.url}${l}`)}}console.log("")}function js(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=nn(),l;if(n==="stdio")l={type:"stdio",command:o[0],args:o.slice(1)};else{let u={};for(let p=1;p<o.length;p++)if(o[p]==="-H"||o[p]==="--header"){let k=o[++p],f=k?.match(/^([^:=]+)[:=](.+)$/);if(!f){console.log(x(`-H expects key:value (no spaces). Got: ${k??"(nothing)"}`));return}u[f[1].trim()]=f[2].trim()}else{console.log(x(`Unexpected argument: ${o[p]}. After the URL, only -H key:value is allowed.`));return}l={type:n,url:o[0],headers:Object.keys(u).length>0?u:void 0}}r.servers[t]=l,fo(r),console.log(""),console.log(T(`\u2713 Registered "${t}" (${n})`)),console.log(E(" This server loads on your next prompt. The current agent session reads MCP config at startup.")),console.log(c(" Run /clear if you want the next turn to reload immediately.")),console.log("")}function As(e){let t=e[0];if(!t){console.log(x("Usage: /mcp remove <name>"));return}let n=nn();if(!n.servers[t]){console.log(x(`No server named "${t}".`));return}delete n.servers[t],fo(n),console.log(T(`\u2713 Removed "${t}".`)),console.log(c(" Run /clear to drop it from the current session immediately."))}L();import{select as Is}from"@inquirer/prompts";import{computeSyncStatus as go}from"document360-engine";function Ct(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(`
10
+ `)}var ho={"local-ahead":"modified locally","untracked-local":"new (never published)",conflict:"\u26A0 conflict \u2014 publishing overwrites the portal edit"};function vt(e){return e.filter(t=>t.path!==null&&t.status in ho).map(t=>({path:t.path,label:ho[t.status]}))}function Ke(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(`
11
+ `)}async function ko(e,t){let n=e[0];if(n==="--all"){console.log(c("Checking what needs publishing\u2026"));try{let o=vt((await go({cwd:t?.cwd??process.cwd()})).entries);return o.length===0?(console.log(T("\u2713 Nothing is ahead of Document360 \u2014 no publish candidates.")),{kind:"continue"}):{kind:"forward-to-agent",prompt:Ke(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(c("Checking what needs publishing\u2026"));let o;try{o=vt((await go({cwd:t?.cwd??process.cwd()})).entries)}catch(r){return console.log(x(`Could not compute sync status: ${r.message}`)),console.log(c("Publish a specific article: /publish <article-path>")),{kind:"continue"}}if(o.length===0)return console.log(T("\u2713 Nothing is ahead of Document360 \u2014 no publish candidates.")),console.log(c(" (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} ${c(`(${r.label})`)}`);return console.log(c("Run: /publish <article-path>")),{kind:"continue"}}try{n=await t.withPausedInput(()=>Is({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(c("Cancelled.")),{kind:"continue"}}if(n==="--all")return{kind:"forward-to-agent",prompt:Ke(o.map(r=>r.path)),display:"/publish --all"}}return{kind:"forward-to-agent",prompt:Ct(n),display:`/publish ${n}`}}async function Pt(){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(`
12
+ `),display:"/audit"}}L();import{checkbox as Es}from"@inquirer/prompts";import{inventoryRepo as Ds,readProjectConfig as wo,writeProjectConfig as Ms}from"document360-engine";function on(e,t){let n=wo(e);n&&(n.authoritativeSourceFiles=t,Ms(n,e))}function Tt(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 yo(e,t){let n=t?.cwd??process.cwd();if(!wo(n))return console.log(x("No .d360-writer.json here. Run /init first.")),{kind:"continue"};let o=Ds(n);if(o.length===0)return console.log(c('No candidate source folders found. Set "authoritativeSourceFiles" in .d360-writer.json manually.')),{kind:"continue"};if(!process.stdin.isTTY||!t){console.log(""),console.log(w("Recommended documentation scope (run /scope in the REPL to choose):"));for(let l of o)console.log(` ${l.recommended?"\u25C9":"\u25CB"} ${l.path} ${c(Tt(l))}`);return console.log(""),{kind:"continue"}}let r;try{r=await t.withPausedInput(()=>Es({message:"Which folders back the user docs? (space toggles, enter confirms)",choices:o.map(l=>({name:`${l.path} (${Tt(l)})`,value:l.path,checked:l.recommended})),pageSize:20}))}catch{return console.log(c("Cancelled.")),{kind:"continue"}}if(r.length===0)return console.log(c("Nothing selected \u2014 scope unchanged.")),{kind:"continue"};on(n,r),console.log(T(`\u2713 Scoped to ${r.length} folder(s) \u2014 written to .d360-writer.json`));for(let l of r)console.log(` ${l}`);return console.log(""),{kind:"continue"}}L();import{confirm as Us}from"@inquirer/prompts";import{applyPull as Co,computeSyncStatus as Po,planPull as Ws,D360AuthError as Bs}from"document360-engine";L();var xo=[{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:E,mark:"M"},{status:"remote-ahead",header:"Remote ahead \u2014 pull with /sync pull <path>:",paint:w,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:z,mark:"X"},{status:"untracked-local",header:"Untracked local articles \u2014 publish to start tracking:",paint:c,mark:"?"},{status:"untracked-remote",header:"Untracked Document360 articles \u2014 no local file maps to them:",paint:c,mark:"?"},{status:"unknown-base",header:"No sync base recorded yet \u2014 the next /publish or /sync pull of each records one:",paint:z,mark:"\xB7"}];function _s(e){return e.path?e.path:`${e.title??"(untitled)"} ${z(`[${e.articleId}]`)}`}function St(e){let t=[];for(let u of xo){let p=e.entries.filter(k=>k.status===u.status);if(p.length!==0){t.push(""),t.push(ne(u.header));for(let k of p)t.push(` ${u.paint(u.mark)} ${u.paint(_s(k))}${k.detail?z(` (${k.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"},l=o===n?T("\u2713 everything in sync"):[n>0?T(`\u2713 ${n} in sync`):null,...xo.map(u=>{let p=e.counts[u.status]??0;return p>0?`${p} ${r[u.status]}`:null})].filter(Boolean).join(z(" \xB7 "));return t.push(l+z(` \xB7 ${o} tracked+seen \xB7 profile "${e.profile}" \xB7 docs root ${e.docsRoot}/`)),t}import{structuredPatch as Ls}from"diff";import $o from"picocolors";var bo=80,Ns="\x1B[48;2;74;28;28m",Os="\x1B[48;2;24;66;24m",vo="\x1B[49m",rn=e=>String(e).padStart(5);function Ae(e,t,n){let o=b=>{let S=b.replace(/\r\n/g,`
13
13
  `);return S.endsWith(`
14
14
  `)||S===""?S:S+`
15
- `},r=n(e),i=n(t);if(r===i)return null;let u=Math.max(20,o-10),p=_s("a","b",r,i,"","",{context:3}),k=0,f=0,b=[];p.hunks.forEach(($,S)=>{S>0&&b.push(yn.gray(" \u2026"));let _=$.oldStart,I=$.newStart;for(let H of $.lines){let U=H[0],K=H.slice(1).slice(0,u);U==="-"?(f++,b.push(`${Ms}${oo(_++)} - ${K}${$n}`)):U==="+"?(k++,b.push(`${Ls}${oo(I++)} + ${K}${$n}`)):(b.push(yn.gray(oo(I))+" "+K),_++,I++)}});let R=b.slice(0,xn);return{added:k,removed:f,lines:R,hidden:Math.max(0,b.length-xn)}}async function Cn(e,t){let o=(e[0]??"status").toLowerCase();try{if(o==="status")return await Ws(t.cwd),{kind:"continue"};if(o==="pull")return await Bs(t,e.slice(1)),{kind:"continue"};console.log(x(`Unknown subcommand: /sync ${o}`)),console.log(c("Usage: /sync drift report (local vs Document360)")),console.log(c(" /sync pull <path> pull portal edits into the local file")),console.log(c(" /sync pull --all pull every remote-ahead article"))}catch(n){n instanceof Us?console.log(x(n.message)):console.log(x(`Sync failed: ${n.message}`))}return{kind:"continue"}}async function Ws(e){console.log(c("Checking Document360 for drift\u2026"));let t=await vn({cwd:e});for(let o of Pt(t))console.log(o);console.log("")}async function Bs(e,t){let o=t[0];if(!o){console.log(x("Usage: /sync pull <article-path> | --all"));return}let n;if(o==="--all"){if(console.log(c("Checking Document360 for drift\u2026")),n=(await vn({cwd:e.cwd})).entries.filter(i=>i.status==="remote-ahead"&&i.path).map(i=>i.path),n.length===0){console.log(T("\u2713 Nothing is remote-ahead \u2014 no pulls needed.")),console.log(c(" (conflicts are never bulk-pulled; pull them one by one: /sync pull <path>)"));return}console.log(`${te(String(n.length))} article(s) are remote-ahead.`)}else n=[o.replace(/\\/g,"/")];for(let r of n){let i=await Os({cwd:e.cwd,relPath:r});console.log(""),console.log(`${y("\u25CF")} ${te(i.title)} ${z(`(${i.path})`)}`);for(let f of i.notes)console.log(E(` \u26A0 ${f}`));i.overwritesLocalChanges&&console.log(E(" \u26A0 This OVERWRITES local edits made since the last sync."));let u=Re(i.oldContent,i.newContent,Math.max(40,(process.stdout.columns??80)-1));if(!u){console.log(c(" Local file already matches the remote content \u2014 advancing the sync base only.")),bn({cwd:e.cwd},i);continue}let p=f=>f===1?"":"s";console.log(z(` \u23BF Added ${u.added} line${p(u.added)}, removed ${u.removed} line${p(u.removed)}`));for(let f of u.lines)console.log(f);if(u.hidden>0&&console.log(c(` \u2026 +${u.hidden} more diff lines`)),!await e.withPausedInput(()=>Ns({message:`Write ${i.path}?`,default:!i.overwritesLocalChanges}))){console.log(c(" Skipped."));continue}bn({cwd:e.cwd},i),console.log(T(` \u2713 Pulled ${i.path} (sync base advanced).`))}console.log("")}M();import{search as Hs}from"@inquirer/prompts";import{findByName as Fs,getSession as qs,listSessions as zs,relativeTime as Tn}from"document360-engine";async function Sn(e,t){let o=zs(t.cwd).filter(n=>n.uuid!==t.currentUuid());if(o.length===0)return console.log(c("No saved sessions for this repo yet \u2014 sessions auto-save as you work.")),{kind:"continue"};if(e.length>0){let n=e.join(" "),r=Fs(t.cwd,n);return r?{kind:"resume",uuid:r.uuid,name:r.name}:(console.log(x(`No session matches "${n}".`)),Pn(o),{kind:"continue"})}if(!process.stdin.isTTY)return Pn(o),console.log(c("Run: /resume <name>")),{kind:"continue"};try{let n=await t.withPausedInput(()=>Hs({message:"Resume session (type to filter, \u2191\u2193 to navigate):",source:async i=>{let u=(i??"").toLowerCase();return o.filter(p=>!u||p.name.toLowerCase().includes(u)||p.firstPrompt.toLowerCase().includes(u)).map(p=>({name:`${p.name} ${Tn(p.updatedAt)}`,value:p.uuid,description:p.firstPrompt.slice(0,100)}))}})),r=qs(n);return r?{kind:"resume",uuid:r.uuid,name:r.name}:{kind:"continue"}}catch{return console.log(""),{kind:"continue"}}}function Pn(e){console.log("");for(let t of e.slice(0,15))console.log(` ${y(t.name)} ${c(Tn(t.updatedAt))}`),console.log(` ${c(t.firstPrompt.slice(0,80))}`);console.log("")}M();import{renameSession as Gs}from"document360-engine";async function Rn(e,t){let o=e.join(" ").trim();if(!o)return console.log(x("Usage: /rename <new name>")),{kind:"continue"};let n=t.currentUuid();return n?(Gs(n,o)?console.log(T(`\u2713 Session renamed to "${o}"`)):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 jn,readProjectConfig as Vs,writeProjectConfig as Xs}from"document360-engine";M();function no(e,t,o){if(!t)return"Usage: /profile add <name> [environment]";let n=Vs(e);if(!n)return"No .d360-writer.json \u2014 run /init first.";if(n.profiles?.[t])return`Profile "${t}" already exists.`;let r=o??t;return jn().includes(r)?(n.profiles={...n.profiles,[t]:{connection:{environment:r},production:!1}},Xs(n,e),null):`Unknown environment "${r}". Known: ${jn().join(", ")} (or add the profile with explicit URLs in .d360-writer.json).`}async function An(e,t){let o=e[0];if(!o)return kt(t.cwd),{kind:"continue"};if(o==="add"){let n=no(t.cwd,e[1],e[2]);return n?(console.log(x(n)),{kind:"continue"}):(console.log(T(`\u2713 Profile "${e[1]}" created (environment: ${e[2]??e[1]}).`)),console.log(` Switch + sign in: ${y(`/profile ${e[1]}`)} then ${y("/login")}`),{kind:"continue"})}return wt(t.cwd,o),yt(t.cwd,o),console.log(c(" Restarting agent for the new profile\u2026")),{kind:"clear"}}M();import{select as Ys}from"@inquirer/prompts";import{readProjectConfig as Js,readUserConfig as In,resolveModelSetting as ro,writeUserConfig as En}from"document360-engine";var le=[{value:null,label:"Default",desc:"Claude Code's configured default \u2014 clears your personal override"},{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 Tt(e){if(e.model===null||e.source==="claude-settings")return 0;let t=e.model.toLowerCase(),o=le.findIndex(n=>n.value!==null&&(n.value===t||n.label.toLowerCase()===t||t.includes(n.label.toLowerCase())));return o>=0?o:0}function Ks(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 Je(e,t){let o=()=>{let i=ro(e);return i.source==="project"||i.source==="user"||i.source==="env"?i.model??void 0:void 0};if(t==="default"){let i=In();return i.defaultModel?(delete i.defaultModel,En(i),{lines:[`\u2713 Personal model override cleared \u2014 now: ${ro(e).model??"Claude Code default"} (applies from your next message)`],changed:!0,effective:o()}):{lines:["No personal model override set \u2014 nothing to clear."],changed:!1,effective:void 0}}En({...In(),defaultModel:t});let n=[`\u2713 Personal model set to "${t}" (applies from your next message \u2014 conversation continues)`],r=Js(e)?.defaultModel;return r&&n.push(`\u26A0 .d360-writer.json sets defaultModel "${r}" \u2014 the team setting overrides yours until it is removed.`),{lines:n,changed:!0,effective:o()}}async function Dn(e,t){let o=e[0]?.trim();if(!o){let u=ro(t.cwd);if(!process.stdin.isTTY)return console.log(`${te("Model:")} ${y(u.model??"Claude Code default")}`),console.log(c(` source: ${Ks(u)}`)),console.log(c(" change: /model <haiku|sonnet|opus|full-model-id> \xB7 reset: /model default")),{kind:"continue"};let p=Tt(u),k;try{k=await t.withPausedInput(()=>Ys({message:`Select model (current: ${u.model??"Claude Code default"})`,default:le[p].value,choices:le.map(($,S)=>({name:`${$.label}${S===p?" \u2714":""}`,value:$.value,description:$.desc}))}))}catch{return console.log(c("Cancelled.")),{kind:"continue"}}let{lines:f,changed:b,effective:R}=Je(t.cwd,k??"default");for(let $ of f)console.log($.startsWith("\u26A0")?E($):$.startsWith("\u2713")?T($):c($));return b&&await t.setModel(R),{kind:"continue"}}let{lines:n,changed:r,effective:i}=Je(t.cwd,o);for(let u of n)console.log(u.startsWith("\u26A0")?E(u):u.startsWith("\u2713")?T(u):c(u));return r&&await t.setModel(i),{kind:"continue"}}St();async function On(e,t){return await t.withPausedInput(()=>Oe(t.cwd)),{kind:"clear"}}M();import{resolveActiveProfile as ai}from"document360-engine";async function Un(e,t){let o=!1;try{o=ai(t.cwd).production}catch{}return o?(console.log(E("\u26A0 Authorizing writes to the PRODUCTION profile for this session.")),{kind:"allow-prod"}):(console.log(c("Current profile is not a production profile \u2014 writes are already allowed.")),{kind:"continue"})}M();var Wn=async(e,t)=>{try{await t.withPausedInput(()=>ht({}))}catch(o){console.log(x(`Login failed: ${o.message}`))}return{kind:"continue"}};M();async function Rt(e){let t=e[0];return t?{kind:"forward-to-agent",prompt:[`Run the emit-screenshot-spec skill for placeholder id: ${t}`,"","Steps you must follow:","1. Locate the SCREENSHOT HTML comment block with this id across user-docs/**/*.md.","2. Translate the placeholder.steps into Playwright actions using STABLE selectors only (data-testid > aria-label > role+name > visible text). If no stable selector is available for a required action, write `test.skip(...)` plus a TODO comment naming the React component that needs a data-testid.",'3. Write the spec file to <captureDir>/<id>.spec.ts. Use `import { test } from "@playwright/test"` and `import { waitPastLogin, dumpAnnotations, type Placeholder } from "document360-capture/helpers"`.',"4. Use process.env.CAPTURE_START_URL and process.env.CAPTURE_AUTH_BOUNDARY (these are injected at run time by document360-capture; do not hardcode them).","5. Report the path of the generated spec and any TODOs from missing selectors."].join(`
16
- `),display:`/screenshot ${t}`}:(console.log(x("Usage: /screenshot <placeholder-id>")),{kind:"continue"})}var Bn={help:Kt,"?":Kt,clear:nn,exit:Qt,quit:Qt,init:cn,mcp:xt,publish:gn,audit:vt,scope:kn,sync:Cn,resume:Sn,rename:Rn,profile:An,model:Dn,doctor:Ke,workspace:On,"allow-prod":Un,login:Wn,screenshot:Rt};function Hn(e){let t=e.trim();if(!t.startsWith("/"))return null;let o=t.slice(1).split(/\s+/),n=(o[0]??"").toLowerCase();return n?{name:n,args:o.slice(1)}:null}M();var ci={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"},qn=160,lo=200,zn=40;function J(e,t){let o=e.replace(/\s+/g," ").trim();return o.length<=t?o:o.slice(0,t-1)+"\u2026"}function Fn(e){let t=Object.entries(e).filter(([,n])=>n!=null&&n!=="");if(t.length===0)return null;let o=t.slice(0,4).map(([n,r])=>`${n}: ${J(typeof r=="string"?r:JSON.stringify(r),zn)}`);return t.length>4&&o.push("\u2026"),J(o.join(", "),qn)}var ke=e=>typeof e=="string"&&e?e:null,io=e=>typeof e=="string"&&e.length>=8?e.slice(0,8):null;function ui(e){let t=ke(e)?.replace(/\\/g,"/");if(!t)return null;let o=t.split("/").filter(Boolean);if(o.length<2)return null;let n=o[o.length-2],r=n.replace(/^\d+[-_.]/,"").split(/[-_]/).filter(Boolean);return r.length===0?n:r.map(i=>i.charAt(0).toUpperCase()+i.slice(1)).join(" ")}function di(e,t){let o=(n,r)=>({title:`Document360: ${n}`,sep:" ",arg:r});switch(e){case"d360_create_article":{let n=ke(t.title);if(!n)return null;let r=ui(t.local_path);return o("Create article",`"${J(n,60)}"${r?` in ${r}`:""}`)}case"d360_update_article":{let n=ke(t.title),r=io(t.article_id);return o("Update article",n?`"${J(n,60)}"`:r?`id ${r}\u2026`:null)}case"d360_fork_article":return o("Fork article (new draft)",io(t.article_id)?`id ${io(t.article_id)}\u2026`:null);case"d360_publish_article":{let n=t.version_number;return o("Publish article LIVE",typeof n=="number"?`v${n}`:null)}case"d360_unpublish_article":return o("Unpublish article",null);case"d360_create_category":return o("Create category",ke(t.name)?`"${J(ke(t.name),60)}"`:null);case"d360_upload_drive_file":{let n=ke(t.file_path);return o("Upload image",n?J(n.replace(/\\/g,"/").split("/").pop()??n,60):null)}case"d360_sync_status":return o("Check sync status",null);default:return null}}function jt(e,t){if(e==="ToolSearch")return null;if(e.startsWith("mcp__")){let[,r="",...i]=e.split("__"),u=i.join("__");if(r==="document360"){let f=di(u,t);if(f)return f}let p=u.replace(/^d360_/,"").replace(/_/g," ");return{title:`${r==="document360"?"Document360":r.charAt(0).toUpperCase()+r.slice(1)}: ${p}`,sep:" ",arg:Fn(t)}}let o=ci[e],n=o?t[o]:void 0;return typeof n=="string"&&n?{title:e,sep:"",arg:J(n,qn)}:{title:e,sep:"",arg:Fn(t)}}function pi(e){if(e===null||typeof e!="object")return typeof e=="string"?e:null;let t=e;for(let o of["name","title","slug","id"])if(typeof t[o]=="string"&&t[o])return t[o];return null}function mi(e){if(!/^[[{]/.test(e))return null;let t;try{t=JSON.parse(e)}catch{return null}if(Array.isArray(t)){let o=t.map(pi).filter(r=>r!==null),n=`${t.length} item${t.length===1?"":"s"}`;return o.length===0?[n]:[n,...o.map(r=>J(r,lo))]}if(t!==null&&typeof t=="object"){let o=Object.entries(t).filter(([,n])=>n!==null&&(typeof n=="string"||typeof n=="number"||typeof n=="boolean")).slice(0,6).map(([n,r])=>`${n}: ${J(String(r),zn)}`);return o.length>0?[J(o.join(" \xB7 "),lo)]:null}return null}function fi(e){let t=ke(e)?.replace(/\\/g,"/");if(!t)return null;let o=t.split("/").filter(Boolean);return o.length>1?o.slice(1).join("/"):t}function gi(e,t,o){switch(e){case"d360_create_article":{let n=fi(t?.local_path);return[`\u2713 draft created${n?` \xB7 ${n}`:""}`]}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 n=ke(t?.name);return[`\u2713 category created${n?` \xB7 "${n}"`:""}`]}case"d360_upload_drive_file":{let n=o.match(/https?:\/\/\S+/);return[`\u2713 uploaded${n?` \xB7 ${J(n[0],120)}`:""}`]}default:return null}}function At(e,t=4,o,n){let r=e.replace(/\r\n/g,`
17
- `).trimEnd();if(!r)return{lines:["(no output)"],hidden:0};if(o?.startsWith("mcp__document360__")){let u=gi(o.slice(18),n,r);if(u)return{lines:u,hidden:0}}let i=mi(r)??r.split(`
18
- `);return{lines:i.slice(0,t).map(u=>J(u,lo)),hidden:Math.max(0,i.length-t)}}function It(e,t,o,n="en"){return`${e.replace(/\/$/,"")}/${t}/document/v1/${n}/${o}`}function Et(e,t){if(typeof e.article_id=="string"&&e.article_id)return e.article_id;try{let o=JSON.parse(t),r=(Array.isArray(o)?o[0]:o)?.id;return typeof r=="string"&&r?r:null}catch{return null}}function Dt(e){try{let t=JSON.parse(e),n=(Array.isArray(t)?t[0]:t)?.url;return typeof n=="string"&&/^https?:\/\//.test(n)?n:null}catch{return null}}var Si=/^mcp__document360__d360_(create_article|update_article|fork_article|publish_article)$/;function Ri(e,t,o,n){if(Si.test(e))try{let r=Yn(n),i=typeof t.project_id=="string"&&t.project_id||r.project.projectId,u=Et(t,o),p=Dt(o);e.endsWith("publish_article")&&p&&console.log(y(` \u2B95 Live: ${p}`)),u&&i&&console.log(y(` \u2B95 Preview: ${It(r.connection.portalUrl,i,u,r.project.languageCode??"en")}`))}catch{}}async function Jn(e=process.cwd(),t="auto",o){let n=ki(t);n.kind==="none"&&(console.error(""),console.error(x("ANTHROPIC_API_KEY is not set (required for --auth api).")),console.error(""),console.error(` ${y("export ANTHROPIC_API_KEY=sk-ant-...")} (macOS / Linux)`),console.error(` ${y('$env:ANTHROPIC_API_KEY="sk-ant-..."')} (PowerShell)`),console.error(""),console.error(`Get a key at ${y("https://console.anthropic.com/settings/keys")}`),console.error(`Or use your Claude subscription instead: ${y("d360-writer --auth subscription")}`),console.error(""),process.exit(2)),ji(e,o),n.kind==="subscription"&&(n.stored?console.log(c(" Using your Claude subscription (no API key set).")):console.log(c(" No API key or stored Claude Code login found \u2014 trying your Claude session anyway.")),console.log(""));let r=!1,i=ao({cwd:e,profileName:o,allowProdWrites:r}),u={uuid:null,firstPrompt:null,titleFired:!1},p=hi({input:process.stdin,output:process.stdout}),k=[],f=null,b=!1;p.on("line",S=>{if(f){let _=f;f=null,_(S)}else k.push(S)}),p.on("close",()=>{if(b=!0,f){let S=f;f=null,S(null)}});function R(){return k.length>0?Promise.resolve(k.shift()):b?Promise.resolve(null):(process.stdout.write(y("> ")),new Promise(S=>{f=S}))}let $={cwd:e,restartAgent:()=>{i.close(),i=ao({cwd:e,profileName:o,allowProdWrites:r}),u={uuid:null,firstPrompt:null,titleFired:!1}},currentUuid:()=>u.uuid,setModel:async S=>i.setModel(S),withPausedInput:async S=>{p.pause();try{return await S()}finally{p.resume()}}};try{for(;;){let S=await R();if(S===null)break;let _=S.trim();if(_){if(_.startsWith("/")){let I=Hn(_);if(!I)continue;let H=Bn[I.name];if(!H){console.log(x(`Unknown command: /${I.name}`)),console.log(c("Type /help for the list."));continue}let U=await H(I.args,$);if(U.kind==="exit")break;if(U.kind==="clear"){$.restartAgent();continue}if(U.kind==="allow-prod"){r=!0,$.restartAgent(),console.log(T("\u2713 Production writes authorized for this session.")),console.log("");continue}if(U.kind==="resume"){i.close(),i=ao({cwd:e,resume:U.uuid,profileName:o,allowProdWrites:r});let K=wi(U.uuid);u={uuid:U.uuid,firstPrompt:K?.firstPrompt??null,titleFired:!0},Xn(U.uuid),console.log(T(`\u2713 Resumed "${U.name}"`)),console.log("");continue}U.kind==="forward-to-agent"&&(u.firstPrompt||(u.firstPrompt=U.display??U.prompt),await Vn(i,U.prompt,n,u,e));continue}u.firstPrompt||(u.firstPrompt=_),await Vn(i,_,n,u,e)}}}finally{i.close(),p.close()}}function ji(e,t){console.log(""),console.log(ze("document360-writer")),console.log(c(` cwd: ${e}`));let o=vi(e);console.log(c(` model: ${o.model??"Claude Code default"}${o.model?` (${o.source})`:""}`)),console.log(Ai(e,t)),Ci(e)||console.log(E(" First run: /init \u2192 /login \u2192 /workspace, then ask for a docs analysis.")),console.log(c(" Type a prompt, or /help for slash commands. /exit to quit.")),console.log("")}function Ai(e,t){try{let o=Yn(e,t),n=o.production?E(" \u26A0 PRODUCTION"):"",r=Ti(o.name);if(!r)return c(` Document360: profile "${o.name}"${n} \u2014 not logged in (d360-writer login)`);let i={...Gn(r.idToken)??{},...Gn(r.accessToken)??{}},u=i.email??i.preferred_username??"signed in";return Pi(r)&&!r.refreshToken?E(` Document360: profile "${o.name}"${n} \u2014 session expired (d360-writer login)`):c(` Document360: ${u} \xB7 profile "${o.name}"${n}`)}catch(o){return c(` Document360: ${o.message.split(".")[0]}`)}}function Ii(){console.error(""),console.error(`Sign in with your Claude subscription: run ${y("claude")} once, then retry.`),console.error(` (No Claude Code? ${y("npm install -g @anthropic-ai/claude-code")})`),console.error(`Or set an API key: ${y("https://console.anthropic.com/settings/keys")}`)}function Ei(e,t,o){e.uuid=t;let n=new Date().toISOString();$i({uuid:t,name:xi(e.firstPrompt??"session"),renamed:!1,titled:!1,cwd:o,firstPrompt:e.firstPrompt??"",createdAt:n,updatedAt:n})}function Di(e,t){e.titleFired=!0;let o=e.uuid,n=e.firstPrompt;!o||!n||bi(n,t).then(r=>{r&&yi(o,r)}).catch(()=>{})}async function Vn(e,t,o,n,r){let i=new Map;for await(let u of e.send(t))_i(u,n,r,o,i)}function _i(e,t,o,n,r){switch(e.type){case"session":t.uuid||Ei(t,e.sessionId,o);break;case"text":process.stdout.write(e.delta);break;case"tool":{let i=jt(e.name,e.input);i&&(process.stdout.write(`
15
+ `},r=o(e),l=o(t);if(r===l)return null;let u=Math.max(20,n-10),p=Ls("a","b",r,l,"","",{context:3}),k=0,f=0,v=[];p.hunks.forEach((b,S)=>{S>0&&v.push($o.gray(" \u2026"));let _=b.oldStart,I=b.newStart;for(let H of b.lines){let W=H[0],Q=H.slice(1).slice(0,u);W==="-"?(f++,v.push(`${Ns}${rn(_++)} - ${Q}${vo}`)):W==="+"?(k++,v.push(`${Os}${rn(I++)} + ${Q}${vo}`)):(v.push($o.gray(rn(I))+" "+Q),_++,I++)}});let R=v.slice(0,bo);return{added:k,removed:f,lines:R,hidden:Math.max(0,v.length-bo)}}async function To(e,t){let n=(e[0]??"status").toLowerCase();try{if(n==="status")return await Hs(t.cwd),{kind:"continue"};if(n==="pull")return await Fs(t,e.slice(1)),{kind:"continue"};console.log(x(`Unknown subcommand: /sync ${n}`)),console.log(c("Usage: /sync drift report (local vs Document360)")),console.log(c(" /sync pull <path> pull portal edits into the local file")),console.log(c(" /sync pull --all pull every remote-ahead article"))}catch(o){o instanceof Bs?console.log(x(o.message)):console.log(x(`Sync failed: ${o.message}`))}return{kind:"continue"}}async function Hs(e){console.log(c("Checking Document360 for drift\u2026"));let t=await Po({cwd:e});for(let n of St(t))console.log(n);console.log("")}async function Fs(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(c("Checking Document360 for drift\u2026")),o=(await Po({cwd:e.cwd})).entries.filter(l=>l.status==="remote-ahead"&&l.path).map(l=>l.path),o.length===0){console.log(T("\u2713 Nothing is remote-ahead \u2014 no pulls needed.")),console.log(c(" (conflicts are never bulk-pulled; pull them one by one: /sync pull <path>)"));return}console.log(`${ne(String(o.length))} article(s) are remote-ahead.`)}else o=[n.replace(/\\/g,"/")];for(let r of o){let l=await Ws({cwd:e.cwd,relPath:r});console.log(""),console.log(`${w("\u25CF")} ${ne(l.title)} ${z(`(${l.path})`)}`);for(let f of l.notes)console.log(E(` \u26A0 ${f}`));l.overwritesLocalChanges&&console.log(E(" \u26A0 This OVERWRITES local edits made since the last sync."));let u=Ae(l.oldContent,l.newContent,Math.max(40,(process.stdout.columns??80)-1));if(!u){console.log(c(" Local file already matches the remote content \u2014 advancing the sync base only.")),Co({cwd:e.cwd},l);continue}let p=f=>f===1?"":"s";console.log(z(` \u23BF Added ${u.added} line${p(u.added)}, removed ${u.removed} line${p(u.removed)}`));for(let f of u.lines)console.log(f);if(u.hidden>0&&console.log(c(` \u2026 +${u.hidden} more diff lines`)),!await e.withPausedInput(()=>Us({message:`Write ${l.path}?`,default:!l.overwritesLocalChanges}))){console.log(c(" Skipped."));continue}Co({cwd:e.cwd},l),console.log(T(` \u2713 Pulled ${l.path} (sync base advanced).`))}console.log("")}L();import{search as qs}from"@inquirer/prompts";import{findByName as zs,getSession as Gs,listSessions as Xs,relativeTime as Ro}from"document360-engine";async function jo(e,t){let n=Xs(t.cwd).filter(o=>o.uuid!==t.currentUuid());if(n.length===0)return console.log(c("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=zs(t.cwd,o);return r?{kind:"resume",uuid:r.uuid,name:r.name}:(console.log(x(`No session matches "${o}".`)),So(n),{kind:"continue"})}if(!process.stdin.isTTY)return So(n),console.log(c("Run: /resume <name>")),{kind:"continue"};try{let o=await t.withPausedInput(()=>qs({message:"Resume session (type to filter, \u2191\u2193 to navigate):",source:async l=>{let u=(l??"").toLowerCase();return n.filter(p=>!u||p.name.toLowerCase().includes(u)||p.firstPrompt.toLowerCase().includes(u)).map(p=>({name:`${p.name} ${Ro(p.updatedAt)}`,value:p.uuid,description:p.firstPrompt.slice(0,100)}))}})),r=Gs(o);return r?{kind:"resume",uuid:r.uuid,name:r.name}:{kind:"continue"}}catch{return console.log(""),{kind:"continue"}}}function So(e){console.log("");for(let t of e.slice(0,15))console.log(` ${w(t.name)} ${c(Ro(t.updatedAt))}`),console.log(` ${c(t.firstPrompt.slice(0,80))}`);console.log("")}L();import{renameSession as Vs}from"document360-engine";async function Ao(e,t){let n=e.join(" ").trim();if(!n)return console.log(x("Usage: /rename <new name>")),{kind:"continue"};let o=t.currentUuid();return o?(Vs(o,n)?console.log(T(`\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 Io,readProjectConfig as Ys,writeProjectConfig as Js}from"document360-engine";L();function sn(e,t,n){if(!t)return"Usage: /profile add <name> [environment]";let o=Ys(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 Io().includes(r)?(o.profiles={...o.profiles,[t]:{connection:{environment:r},production:!1}},Js(o,e),null):`Unknown environment "${r}". Known: ${Io().join(", ")} (or add the profile with explicit URLs in .d360-writer.json).`}async function Eo(e,t){let n=e[0];if(!n)return yt(t.cwd),{kind:"continue"};if(n==="add"){let o=sn(t.cwd,e[1],e[2]);return o?(console.log(x(o)),{kind:"continue"}):(console.log(T(`\u2713 Profile "${e[1]}" created (environment: ${e[2]??e[1]}).`)),console.log(` Switch + sign in: ${w(`/profile ${e[1]}`)} then ${w("/login")}`),{kind:"continue"})}return xt(t.cwd,n),$t(t.cwd,n),console.log(c(" Restarting agent for the new profile\u2026")),{kind:"clear"}}L();import{select as Ks}from"@inquirer/prompts";import{readProjectConfig as Qs,readUserConfig as Do,resolveModelSetting as ln,writeUserConfig as Mo}from"document360-engine";var le=[{value:null,label:"Default",desc:"Claude Code's configured default \u2014 clears your personal override"},{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 Rt(e){if(e.model===null||e.source==="claude-settings")return 0;let t=e.model.toLowerCase(),n=le.findIndex(o=>o.value!==null&&(o.value===t||o.label.toLowerCase()===t||t.includes(o.label.toLowerCase())));return n>=0?n:0}function Zs(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 Qe(e,t){let n=()=>{let l=ln(e);return l.source==="project"||l.source==="user"||l.source==="env"?l.model??void 0:void 0};if(t==="default"){let l=Do();return l.defaultModel?(delete l.defaultModel,Mo(l),{lines:[`\u2713 Personal model override cleared \u2014 now: ${ln(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}}Mo({...Do(),defaultModel:t});let o=[`\u2713 Personal model set to "${t}" (applies from your next message \u2014 conversation continues)`],r=Qs(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 _o(e,t){let n=e[0]?.trim();if(!n){let u=ln(t.cwd);if(!process.stdin.isTTY)return console.log(`${ne("Model:")} ${w(u.model??"Claude Code default")}`),console.log(c(` source: ${Zs(u)}`)),console.log(c(" change: /model <haiku|sonnet|opus|full-model-id> \xB7 reset: /model default")),{kind:"continue"};let p=Rt(u),k;try{k=await t.withPausedInput(()=>Ks({message:`Select model (current: ${u.model??"Claude Code default"})`,default:le[p].value,choices:le.map((b,S)=>({name:`${b.label}${S===p?" \u2714":""}`,value:b.value,description:b.desc}))}))}catch{return console.log(c("Cancelled.")),{kind:"continue"}}let{lines:f,changed:v,effective:R}=Qe(t.cwd,k??"default");for(let b of f)console.log(b.startsWith("\u26A0")?E(b):b.startsWith("\u2713")?T(b):c(b));return v&&await t.setModel(R),{kind:"continue"}}let{lines:o,changed:r,effective:l}=Qe(t.cwd,n);for(let u of o)console.log(u.startsWith("\u26A0")?E(u):u.startsWith("\u2713")?T(u):c(u));return r&&await t.setModel(l),{kind:"continue"}}jt();async function Wo(e,t){return await t.withPausedInput(()=>We(t.cwd)),{kind:"clear"}}L();import{resolveActiveProfile as ui}from"document360-engine";async function Bo(e,t){let n=!1;try{n=ui(t.cwd).production}catch{}return n?(console.log(E("\u26A0 Authorizing writes to the PRODUCTION profile for this session.")),{kind:"allow-prod"}):(console.log(c("Current profile is not a production profile \u2014 writes are already allowed.")),{kind:"continue"})}L();var Ho=async(e,t)=>{try{await t.withPausedInput(()=>wt({}))}catch(n){console.log(x(`Login failed: ${n.message}`))}return{kind:"continue"}};L();async function At(e){let t=e[0];return t?{kind:"forward-to-agent",prompt:[`Run the emit-screenshot-spec skill for placeholder id: ${t}`,"","Steps you must follow:","1. Locate the SCREENSHOT HTML comment block with this id across user-docs/**/*.md.","2. Translate the placeholder.steps into Playwright actions using STABLE selectors only (data-testid > aria-label > role+name > visible text). If no stable selector is available for a required action, write `test.skip(...)` plus a TODO comment naming the React component that needs a data-testid.",'3. Write the spec file to <captureDir>/<id>.spec.ts. Use `import { test } from "@playwright/test"` and `import { waitPastLogin, dumpAnnotations, type Placeholder } from "document360-capture/helpers"`.',"4. Use process.env.CAPTURE_START_URL and process.env.CAPTURE_AUTH_BOUNDARY (these are injected at run time by document360-capture; do not hardcode them).","5. Report the path of the generated spec and any TODOs from missing selectors."].join(`
16
+ `),display:`/screenshot ${t}`}:(console.log(x("Usage: /screenshot <placeholder-id>")),{kind:"continue"})}var Fo={help:Zt,"?":Zt,clear:so,exit:en,quit:en,init:uo,mcp:bt,publish:ko,audit:Pt,scope:yo,sync:To,resume:jo,rename:Ao,profile:Eo,model:_o,doctor:Ze,workspace:Wo,"allow-prod":Bo,login:Ho,screenshot:At};function qo(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}L();var di={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"},Go=160,un=200,Xo=40;function K(e,t){let n=e.replace(/\s+/g," ").trim();return n.length<=t?n:n.slice(0,t-1)+"\u2026"}function zo(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}: ${K(typeof r=="string"?r:JSON.stringify(r),Xo)}`);return t.length>4&&n.push("\u2026"),K(n.join(", "),Go)}var we=e=>typeof e=="string"&&e?e:null,cn=e=>typeof e=="string"&&e.length>=8?e.slice(0,8):null;function pi(e){let t=we(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(l=>l.charAt(0).toUpperCase()+l.slice(1)).join(" ")}function mi(e,t){let n=(o,r)=>({title:`Document360: ${o}`,sep:" ",arg:r});switch(e){case"d360_create_article":{let o=we(t.title);if(!o)return null;let r=pi(t.local_path);return n("Create article",`"${K(o,60)}"${r?` in ${r}`:""}`)}case"d360_update_article":{let o=we(t.title),r=cn(t.article_id);return n("Update article",o?`"${K(o,60)}"`:r?`id ${r}\u2026`:null)}case"d360_fork_article":return n("Fork article (new draft)",cn(t.article_id)?`id ${cn(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",we(t.name)?`"${K(we(t.name),60)}"`:null);case"d360_upload_drive_file":{let o=we(t.file_path);return n("Upload image",o?K(o.replace(/\\/g,"/").split("/").pop()??o,60):null)}case"d360_sync_status":return n("Check sync status",null);default:return null}}function It(e,t){if(e==="ToolSearch")return null;if(e.startsWith("mcp__")){let[,r="",...l]=e.split("__"),u=l.join("__");if(r==="document360"){let f=mi(u,t);if(f)return f}let p=u.replace(/^d360_/,"").replace(/_/g," ");return{title:`${r==="document360"?"Document360":r.charAt(0).toUpperCase()+r.slice(1)}: ${p}`,sep:" ",arg:zo(t)}}let n=di[e],o=n?t[n]:void 0;return typeof o=="string"&&o?{title:e,sep:"",arg:K(o,Go)}:{title:e,sep:"",arg:zo(t)}}function fi(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 gi(e){if(!/^[[{]/.test(e))return null;let t;try{t=JSON.parse(e)}catch{return null}if(Array.isArray(t)){let n=t.map(fi).filter(r=>r!==null),o=`${t.length} item${t.length===1?"":"s"}`;return n.length===0?[o]:[o,...n.map(r=>K(r,un))]}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}: ${K(String(r),Xo)}`);return n.length>0?[K(n.join(" \xB7 "),un)]:null}return null}function hi(e){let t=we(e)?.replace(/\\/g,"/");if(!t)return null;let n=t.split("/").filter(Boolean);return n.length>1?n.slice(1).join("/"):t}function ki(e,t,n){switch(e){case"d360_create_article":{let o=hi(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=we(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 ${K(o[0],120)}`:""}`]}default:return null}}function Et(e,t=4,n,o){let r=e.replace(/\r\n/g,`
17
+ `).trimEnd();if(!r)return{lines:["(no output)"],hidden:0};if(n?.startsWith("mcp__document360__")){let u=ki(n.slice(18),o,r);if(u)return{lines:u,hidden:0}}let l=gi(r)??r.split(`
18
+ `);return{lines:l.slice(0,t).map(u=>K(u,un)),hidden:Math.max(0,l.length-t)}}function Dt(e,t,n,o="en"){return`${e.replace(/\/$/,"")}/${t}/document/v1/${o}/${n}`}function Mt(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 _t(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 ji=/^mcp__document360__d360_(create_article|update_article|fork_article|publish_article)$/;function Ai(e,t,n,o){if(ji.test(e))try{let r=Ko(o),l=typeof t.project_id=="string"&&t.project_id||r.project.projectId,u=Mt(t,n),p=_t(n);e.endsWith("publish_article")&&p&&console.log(w(` \u2B95 Live: ${p}`)),u&&l&&console.log(w(` \u2B95 Preview: ${Dt(r.connection.portalUrl,l,u,r.project.languageCode??"en")}`))}catch{}}async function Qo(e=process.cwd(),t="auto",n){let o=yi(t);o.kind==="none"&&(console.error(""),console.error(x("ANTHROPIC_API_KEY is not set (required for --auth api).")),console.error(""),console.error(` ${w("export ANTHROPIC_API_KEY=sk-ant-...")} (macOS / Linux)`),console.error(` ${w('$env:ANTHROPIC_API_KEY="sk-ant-..."')} (PowerShell)`),console.error(""),console.error(`Get a key at ${w("https://console.anthropic.com/settings/keys")}`),console.error(`Or use your Claude subscription instead: ${w("d360-writer --auth subscription")}`),console.error(""),process.exit(2)),Ii(e,n),o.kind==="subscription"&&(o.stored?console.log(c(" Using your Claude subscription (no API key set).")):console.log(c(" No API key or stored Claude Code login found \u2014 trying your Claude session anyway.")),console.log(""));let r=!1,l=dn({cwd:e,profileName:n,allowProdWrites:r}),u={uuid:null,firstPrompt:null,titleFired:!1},p=wi({input:process.stdin,output:process.stdout}),k=[],f=null,v=!1;p.on("line",S=>{if(f){let _=f;f=null,_(S)}else k.push(S)}),p.on("close",()=>{if(v=!0,f){let S=f;f=null,S(null)}});function R(){return k.length>0?Promise.resolve(k.shift()):v?Promise.resolve(null):(process.stdout.write(w("> ")),new Promise(S=>{f=S}))}let b={cwd:e,restartAgent:()=>{l.close(),l=dn({cwd:e,profileName:n,allowProdWrites:r}),u={uuid:null,firstPrompt:null,titleFired:!1}},currentUuid:()=>u.uuid,setModel:async S=>l.setModel(S),withPausedInput:async S=>{p.pause();try{return await S()}finally{p.resume()}}};try{for(;;){let S=await R();if(S===null)break;let _=S.trim();if(_){if(_.startsWith("/")){let I=qo(_);if(!I)continue;let H=Fo[I.name];if(!H){console.log(x(`Unknown command: /${I.name}`)),console.log(c("Type /help for the list."));continue}let W=await H(I.args,b);if(W.kind==="exit")break;if(W.kind==="clear"){b.restartAgent();continue}if(W.kind==="allow-prod"){r=!0,b.restartAgent(),console.log(T("\u2713 Production writes authorized for this session.")),console.log("");continue}if(W.kind==="resume"){l.close(),l=dn({cwd:e,resume:W.uuid,profileName:n,allowProdWrites:r});let Q=xi(W.uuid);u={uuid:W.uuid,firstPrompt:Q?.firstPrompt??null,titleFired:!0},Jo(W.uuid),console.log(T(`\u2713 Resumed "${W.name}"`)),console.log("");continue}W.kind==="forward-to-agent"&&(u.firstPrompt||(u.firstPrompt=W.display??W.prompt),await Yo(l,W.prompt,o,u,e));continue}u.firstPrompt||(u.firstPrompt=_),await Yo(l,_,o,u,e)}}}finally{l.close(),p.close()}}function Ii(e,t){console.log(""),console.log(Xe("document360-writer")),console.log(c(` cwd: ${e}`));let n=Pi(e);console.log(c(` model: ${n.model??"Claude Code default"}${n.model?` (${n.source})`:""}`)),console.log(Ei(e,t)),Ti(e)||console.log(E(" First run: /init \u2192 /login \u2192 /workspace, then ask for a docs analysis.")),console.log(c(" Type a prompt, or /help for slash commands. /exit to quit.")),console.log("")}function Ei(e,t){try{let n=Ko(e,t),o=n.production?E(" \u26A0 PRODUCTION"):"",r=Ri(n.name);if(!r)return c(` Document360: profile "${n.name}"${o} \u2014 not logged in (d360-writer login)`);let l={...Vo(r.idToken)??{},...Vo(r.accessToken)??{}},u=l.email??l.preferred_username??"signed in";return Si(r)&&!r.refreshToken?E(` Document360: profile "${n.name}"${o} \u2014 session expired (d360-writer login)`):c(` Document360: ${u} \xB7 profile "${n.name}"${o}`)}catch(n){return c(` Document360: ${n.message.split(".")[0]}`)}}function Di(){console.error(""),console.error(`Sign in with your Claude subscription: run ${w("claude")} once, then retry.`),console.error(` (No Claude Code? ${w("npm install -g @anthropic-ai/claude-code")})`),console.error(`Or set an API key: ${w("https://console.anthropic.com/settings/keys")}`)}function Mi(e,t,n){e.uuid=t;let o=new Date().toISOString();vi({uuid:t,name:bi(e.firstPrompt??"session"),renamed:!1,titled:!1,cwd:n,firstPrompt:e.firstPrompt??"",createdAt:o,updatedAt:o})}function _i(e,t){e.titleFired=!0;let n=e.uuid,o=e.firstPrompt;!n||!o||Ci(o,t).then(r=>{r&&$i(n,r)}).catch(()=>{})}async function Yo(e,t,n,o,r){let l=new Map;for await(let u of e.send(t))Li(u,o,r,n,l)}function Li(e,t,n,o,r){switch(e.type){case"session":t.uuid||Mi(t,e.sessionId,n);break;case"text":process.stdout.write(e.delta);break;case"tool":{let l=It(e.name,e.input);l&&(process.stdout.write(`
19
19
 
20
- `),console.log(`${T("\u25CF")} ${te(i.title)}${i.arg!==null?z(`${i.sep}(${i.arg})`):""}`),r.set(e.id,{name:e.name,input:e.input}));break}case"article_diff":{let i=Re(e.oldContent,e.newContent,Math.max(40,(process.stdout.columns??80)-1));if(!i)break;let u=p=>p===1?"":"s";console.log(z(` \u23BF Added ${i.added} line${u(i.added)}, removed ${i.removed} line${u(i.removed)}`));for(let p of i.lines)console.log(p);i.hidden>0&&console.log(c(` \u2026 +${i.hidden} more diff lines`));break}case"tool_result":{let i=r.get(e.id);if(!i)break;r.delete(e.id);let u=At(e.output,4,e.isError?void 0:i.name,i.input),p=e.isError?x:z;u.lines.forEach((k,f)=>console.log(p((f===0?" \u23BF ":" ")+k))),u.hidden>0&&console.log(c(` \u2026 +${u.hidden} lines`)),e.isError||Ri(i.name,i.input,e.output,o);break}case"result":process.stdout.write(`
21
- `),console.log(c(` (${e.inputTokens}\u2192${e.outputTokens} tokens)`)),console.log(""),t.uuid&&(Xn(t.uuid),t.titleFired||Di(t,o));break;case"error":console.error(""),console.error(x(`agent error: ${e.message}`)),n.kind==="subscription"&&e.kind==="auth"&&Ii();break}}import{render as Cl}from"ink";import{resolveAuth as Pl}from"document360-engine";import{useCallback as F,useEffect as Ze,useMemo as Nt,useRef as G,useState as O}from"react";import{Box as V,Text as v,useApp as Vi,useInput as Xi,useStdout as Yi}from"ink";import{existsSync as Ji,readFileSync as hr,readdirSync as Ki}from"node:fs";import{basename as kr,isAbsolute as Qi,join as Ut}from"node:path";import{createSession as wr,loginPkce as Zi,toStoredTokens as el,saveTokens as tl,getAccessToken as ol,resolveActiveProfile as ae,resolveProjectId as nl,getArticle as rl,decodeJwtClaims as We,isExpired as ye,loadTokens as Ae,setTitle as sl,slugify as il,touchSession as wo,upsertSession as ll,generateTitle as yr,findByName as al,listSessions as cl,renameSession as ul,suggestNextAction as dl,readProjectConfig as je,writeProjectConfig as pl,resolveModelSetting as $o,loadProfileMap as xr,applyPull as ml,computeSyncStatus as yo,planPull as fl,inventoryRepo as gl}from"document360-engine";St();var _t=[{name:"help",usage:"/help",desc:"Show available commands"},{name:"login",usage:"/login",desc:"Sign in to Document360 (browser) without leaving the session"},{name:"resume",usage:"/resume [name]",desc:"Resume a session (no arg lists them)"},{name:"rename",usage:"/rename [name]",desc:"Name the session (no arg: suggest one)"},{name:"profile",usage:"/profile [name|add <name> [env]]",desc:"Switch connection (picker; s = session only)"},{name:"model",usage:"/model [name|default]",desc:"Set the Claude model for d360-writer"},{name:"workspace",usage:"/workspace [name]",desc:"Switch the Document360 workspace (picker)"},{name:"allow-prod",usage:"/allow-prod",desc:"Authorize writes to a production profile"},{name:"doctor",usage:"/doctor",desc:"Health-check: auth, profile, workspace, map, API"},{name:"init",usage:"/init",desc:"Scaffold .d360-writer.json (defaults; wizard via CLI)"},{name:"mcp",usage:"/mcp [list|add|remove]",desc:"Manage MCP servers"},{name:"preview",usage:"/preview [path|id]",desc:"Render an article (no arg: pick from tracked)"},{name:"publish",usage:"/publish [path|--all]",desc:"Publish to Document360 (no arg: pick; --all: every candidate)"},{name:"sync",usage:"/sync [pull <path>|--all]",desc:"Drift report local vs Document360; pull portal edits"},{name:"scope",usage:"/scope",desc:"Choose which repo folders back the docs (analyses + recommends)"},{name:"audit",usage:"/audit",desc:"Gap analysis: code vs docs vs Document360 (incremental)"},{name:"screenshot",usage:"/screenshot <id>",desc:"Emit a capture spec for a placeholder"},{name:"clear",usage:"/clear",desc:"Reset the conversation (resumable)"},{name:"exit",usage:"/exit",desc:"Quit"}];function Kn(e){if(!e.startsWith("/"))return[];let t=e.slice(1).toLowerCase().split(/\s/)[0]??"";return _t.filter(o=>o.name.startsWith(t))}function Qn(e){return/<[^>]+>/.test(e.replace(/\[[^\]]*\]/g,""))}var Mi=/^(?:\d+[.)]|[-*•])\s+/;function Zn(e,t,o=4){let n=new Set(t.map(i=>i.toLowerCase())),r=[];for(let i of e.split(`
22
- `)){let u=i.trim().replace(Mi,""),p=u.match(/^`([^`]+)`$/);p&&(u=p[1].trim());let k=u.match(/^\/([a-z?][a-z0-9-]*)(?:\s+(\S.*?))?\s*$/i);if(!k||!n.has(k[1].toLowerCase()))continue;let f=`/${k[1].toLowerCase()}${k[2]?` ${k[2]}`:""}`;if(r.includes(f)||r.push(f),r.length>=o)break}return r}M();var Li=/\[Pasted text #\d+ \+\d+ lines?\]/g;function er(e){return e.replace(/\r\n?/g,`
23
- `)}function tr(e){return e.includes(`
24
- `)||e.length>200}function or(e,t){let o=t.split(`
25
- `).length;return`[Pasted text #${e} +${o} line${o===1?"":"s"}]`}function nr(e,t){return e.replace(Li,o=>t.get(o)??o)}function rr(e){let t=e.match(/\[Pasted text #\d+ \+\d+ lines?\]$/);return t?e.slice(0,-t[0].length):null}function Mt(e,t){let o=Math.max(1,t),n=[],r=0;for(let i of e.split(`
26
- `)){if(i.length===0)n.push({start:r,end:r});else for(let u=0;u<i.length;u+=o)n.push({start:r+u,end:r+Math.min(u+o,i.length)});r+=i.length+1}return n.length>0?n:[{start:0,end:0}]}function Lt(e,t){let o=0;for(let n=0;n<e.length&&e[n].start<=t;n++)o=n;return o}function sr(e,t,o){let n=Lt(e,t),r=n+o;if(r<0||r>=e.length)return t;let i=Math.min(t,e[n].end)-e[n].start;return Math.min(e[r].start+i,e[r].end)}function ir(e,t,o){let n=e[Lt(e,t)];return o==="start"?n.start:n.end}import D from"picocolors";import pr from"wrap-ansi";import go from"string-width";M();import we from"picocolors";import co from"wrap-ansi";import uo from"string-width";var lr=e=>/^\s*(-{3,}|\*{3,}|_{3,})\s*$/.test(e),ar=e=>/^\s*\|?[\s:|-]*-[\s:|-]*\|?\s*$/.test(e)&&e.includes("-"),cr=e=>e.replace(/^\s*\|/,"").replace(/\|\s*$/,"").split("|").map(t=>t.trim());function Ni(e){let t=e.replace(/\r/g,"").split(`
27
- `),o=[],n=0;for(;n<t.length;){let r=t[n];if(/^\s*```/.test(r)){let p=[];for(n++;n<t.length&&!/^\s*```/.test(t[n]);)p.push(t[n++]);n++,o.push({kind:"code",lines:p});continue}if(lr(r)){o.push({kind:"hr"}),n++;continue}if(r.includes("|")&&n+1<t.length&&ar(t[n+1])){let p=cr(r);n+=2;let k=[];for(;n<t.length&&t[n].includes("|")&&t[n].trim()!=="";)k.push(cr(t[n++]));o.push({kind:"table",header:p,rows:k});continue}let i=r.match(/^(#{1,6})\s+(.*)$/);if(i){o.push({kind:"heading",level:i[1].length,text:i[2]}),n++;continue}if(/^\s*([-*]|\d+\.)\s+/.test(r)){let p=[];for(;n<t.length&&/^\s*([-*]|\d+\.)\s+/.test(t[n]);)p.push(t[n++].replace(/^\s*([-*]|\d+\.)\s+/,""));o.push({kind:"list",items:p});continue}if(r.trim()===""){n++;continue}let u=[];for(;n<t.length&&t[n].trim()!==""&&!/^\s*```/.test(t[n])&&!/^(#{1,6})\s/.test(t[n])&&!/^\s*([-*]|\d+\.)\s+/.test(t[n])&&!lr(t[n])&&!(t[n].includes("|")&&n+1<t.length&&ar(t[n+1]));)u.push(t[n++]);o.push({kind:"para",text:u.join(" ")})}return o}function po(e){return e.replace(/(\*\*[^*]+\*\*|`[^`]+`|\*[^*]+\*)/g,t=>t.startsWith("**")?we.bold(t.slice(2,-2)):t.startsWith("`")?y(t.slice(1,-1)):we.italic(t.slice(1,-1)))}var Oi=(e,t)=>e+" ".repeat(Math.max(0,t-uo(e)));function Ui(e,t,o){let n=e.length,r=e.map((_,I)=>Math.max(uo(_),...t.map(H=>uo(H[I]??"")))),i=Math.max(24,o),u=3*n+1,p=[...r],k=()=>p.reduce((_,I)=>_+I,0)+u,f=0;for(;k()>i&&f++<1e4;){let _=-1,I=6;for(let H=0;H<n;H++)p[H]>I&&(I=p[H],_=H);if(_===-1)break;p[_]-=1}let b=(_,I,H)=>we.gray(_+p.map(U=>"\u2500".repeat(U+2)).join(I)+H),R=we.gray("\u2502"),$=(_,I)=>{let H=p.map((oe,me)=>{let ne=_[me]??"",re=I?we.bold(ne):po(ne);return co(re,oe,{hard:!0}).split(`
28
- `)}),U=Math.max(...H.map(oe=>oe.length)),K=[];for(let oe=0;oe<U;oe++)K.push(p.map((me,ne)=>`${R} ${Oi(H[ne][oe]??"",me)} `).join("")+R);return K.join(`
29
- `)},S=[b("\u250C","\u252C","\u2510"),$(e,!0)];return S.push(t.length===0?b("\u2514","\u2534","\u2518"):b("\u251C","\u253C","\u2524")),t.forEach((_,I)=>{S.push($(_,!1)),S.push(I===t.length-1?b("\u2514","\u2534","\u2518"):b("\u251C","\u253C","\u2524"))}),S.join(`
30
- `)}function Wi(e,t){switch(e.kind){case"heading":return we.bold(e.text);case"hr":return we.gray("\u2500".repeat(t));case"para":return co(po(e.text),t);case"list":return e.items.map(o=>{let[n="",...r]=co(po(o),Math.max(10,t-4)).split(`
31
- `);return" \u2022 "+n+r.map(i=>`
32
- `+i).join("")}).join(`
33
- `);case"code":return e.lines.map(o=>we.gray(" "+o)).join(`
34
- `);case"table":return Ui(e.header,e.rows,t)}}function mo(e,t){let o=Math.max(20,t);return Ni(e).map(n=>Wi(n,o)).join(`
20
+ `),console.log(`${T("\u25CF")} ${ne(l.title)}${l.arg!==null?z(`${l.sep}(${l.arg})`):""}`),r.set(e.id,{name:e.name,input:e.input}));break}case"article_diff":{let l=Ae(e.oldContent,e.newContent,Math.max(40,(process.stdout.columns??80)-1));if(!l)break;let u=p=>p===1?"":"s";console.log(z(` \u23BF Added ${l.added} line${u(l.added)}, removed ${l.removed} line${u(l.removed)}`));for(let p of l.lines)console.log(p);l.hidden>0&&console.log(c(` \u2026 +${l.hidden} more diff lines`));break}case"tool_result":{let l=r.get(e.id);if(!l)break;r.delete(e.id);let u=Et(e.output,4,e.isError?void 0:l.name,l.input),p=e.isError?x:z;u.lines.forEach((k,f)=>console.log(p((f===0?" \u23BF ":" ")+k))),u.hidden>0&&console.log(c(` \u2026 +${u.hidden} lines`)),e.isError||Ai(l.name,l.input,e.output,n);break}case"result":process.stdout.write(`
21
+ `),console.log(c(` (${e.inputTokens}\u2192${e.outputTokens} tokens)`)),console.log(""),t.uuid&&(Jo(t.uuid),t.titleFired||_i(t,n));break;case"error":console.error(""),console.error(x(`agent error: ${e.message}`)),o.kind==="subscription"&&e.kind==="auth"&&Di();break}}import{render as Rl}from"ink";import{resolveAuth as jl}from"document360-engine";import{useCallback as F,useEffect as tt,useMemo as Ut,useRef as G,useState as O}from"react";import{Box as X,Text as $,useApp as Yi,useInput as Ji,useStdout as Ki}from"ink";import{existsSync as Qi,readFileSync as wr,readdirSync as Zi}from"node:fs";import{basename as yr,isAbsolute as el,join as Bt}from"node:path";import{createSession as xr,loginPkce as tl,toStoredTokens as nl,saveTokens as ol,getAccessToken as rl,resolveActiveProfile as ae,resolveProjectId as sl,getArticle as il,decodeJwtClaims as He,isExpired as $e,loadTokens as Ie,setTitle as ll,slugify as al,touchSession as xn,upsertSession as cl,generateTitle as $r,findByName as ul,listSessions as dl,renameSession as pl,suggestNextAction as ml,readProjectConfig as xe,writeProjectConfig as fl,resolveModelSetting as vn,loadProfileMap as br,applyPull as gl,computeSyncStatus as $n,planPull as hl,inventoryRepo as kl,knownEnvironments as wl,resolveEnvironment as yl}from"document360-engine";jt();var Lt=[{name:"help",usage:"/help",desc:"Show available commands"},{name:"login",usage:"/login",desc:"Sign in to Document360 (browser) without leaving the session"},{name:"resume",usage:"/resume [name]",desc:"Resume a session (no arg lists them)"},{name:"rename",usage:"/rename [name]",desc:"Name the session (no arg: suggest one)"},{name:"profile",usage:"/profile [name|add <name> [env]]",desc:"Switch connection (picker; s = session only)"},{name:"model",usage:"/model [name|default]",desc:"Set the Claude model for d360-writer"},{name:"workspace",usage:"/workspace [name]",desc:"Switch the Document360 workspace (picker)"},{name:"allow-prod",usage:"/allow-prod",desc:"Authorize writes to a production profile"},{name:"doctor",usage:"/doctor",desc:"Health-check: auth, profile, workspace, map, API"},{name:"init",usage:"/init",desc:"Pick an environment & scaffold .d360-writer.json"},{name:"mcp",usage:"/mcp [list|add|remove]",desc:"Manage MCP servers"},{name:"preview",usage:"/preview [path|id]",desc:"Render an article (no arg: pick from tracked)"},{name:"publish",usage:"/publish [path|--all]",desc:"Publish to Document360 (no arg: pick; --all: every candidate)"},{name:"sync",usage:"/sync [pull <path>|--all]",desc:"Drift report local vs Document360; pull portal edits"},{name:"scope",usage:"/scope",desc:"Choose which repo folders back the docs (analyses + recommends)"},{name:"audit",usage:"/audit",desc:"Gap analysis: code vs docs vs Document360 (incremental)"},{name:"screenshot",usage:"/screenshot <id>",desc:"Emit a capture spec for a placeholder"},{name:"clear",usage:"/clear",desc:"Reset the conversation (resumable)"},{name:"exit",usage:"/exit",desc:"Quit"}];function Zo(e){if(!e.startsWith("/"))return[];let t=e.slice(1).toLowerCase().split(/\s/)[0]??"";return Lt.filter(n=>n.name.startsWith(t))}function er(e){return/<[^>]+>/.test(e.replace(/\[[^\]]*\]/g,""))}var Ni=/^(?:\d+[.)]|[-*•])\s+/;function tr(e,t,n=4){let o=new Set(t.map(l=>l.toLowerCase())),r=[];for(let l of e.split(`
22
+ `)){let u=l.trim().replace(Ni,""),p=u.match(/^`([^`]+)`$/);p&&(u=p[1].trim());let k=u.match(/^\/([a-z?][a-z0-9-]*)(?:\s+(\S.*?))?\s*$/i);if(!k||!o.has(k[1].toLowerCase()))continue;let f=`/${k[1].toLowerCase()}${k[2]?` ${k[2]}`:""}`;if(r.includes(f)||r.push(f),r.length>=n)break}return r}L();var Oi=/\[Pasted text #\d+ \+\d+ lines?\]/g;function nr(e){return e.replace(/\r\n?/g,`
23
+ `)}function or(e){return e.includes(`
24
+ `)||e.length>200}function rr(e,t){let n=t.split(`
25
+ `).length;return`[Pasted text #${e} +${n} line${n===1?"":"s"}]`}function sr(e,t){return e.replace(Oi,n=>t.get(n)??n)}function ir(e){let t=e.match(/\[Pasted text #\d+ \+\d+ lines?\]$/);return t?e.slice(0,-t[0].length):null}function Nt(e,t){let n=Math.max(1,t),o=[],r=0;for(let l of e.split(`
26
+ `)){if(l.length===0)o.push({start:r,end:r});else for(let u=0;u<l.length;u+=n)o.push({start:r+u,end:r+Math.min(u+n,l.length)});r+=l.length+1}return o.length>0?o:[{start:0,end:0}]}function Ot(e,t){let n=0;for(let o=0;o<e.length&&e[o].start<=t;o++)n=o;return n}function lr(e,t,n){let o=Ot(e,t),r=o+n;if(r<0||r>=e.length)return t;let l=Math.min(t,e[o].end)-e[o].start;return Math.min(e[r].start+l,e[r].end)}function ar(e,t,n){let o=e[Ot(e,t)];return n==="start"?o.start:o.end}import D from"picocolors";import fr from"wrap-ansi";import kn from"string-width";L();import ye from"picocolors";import pn from"wrap-ansi";import mn from"string-width";var cr=e=>/^\s*(-{3,}|\*{3,}|_{3,})\s*$/.test(e),ur=e=>/^\s*\|?[\s:|-]*-[\s:|-]*\|?\s*$/.test(e)&&e.includes("-"),dr=e=>e.replace(/^\s*\|/,"").replace(/\|\s*$/,"").split("|").map(t=>t.trim());function Ui(e){let t=e.replace(/\r/g,"").split(`
27
+ `),n=[],o=0;for(;o<t.length;){let r=t[o];if(/^\s*```/.test(r)){let p=[];for(o++;o<t.length&&!/^\s*```/.test(t[o]);)p.push(t[o++]);o++,n.push({kind:"code",lines:p});continue}if(cr(r)){n.push({kind:"hr"}),o++;continue}if(r.includes("|")&&o+1<t.length&&ur(t[o+1])){let p=dr(r);o+=2;let k=[];for(;o<t.length&&t[o].includes("|")&&t[o].trim()!=="";)k.push(dr(t[o++]));n.push({kind:"table",header:p,rows:k});continue}let l=r.match(/^(#{1,6})\s+(.*)$/);if(l){n.push({kind:"heading",level:l[1].length,text:l[2]}),o++;continue}if(/^\s*([-*]|\d+\.)\s+/.test(r)){let p=[];for(;o<t.length&&/^\s*([-*]|\d+\.)\s+/.test(t[o]);)p.push(t[o++].replace(/^\s*([-*]|\d+\.)\s+/,""));n.push({kind:"list",items:p});continue}if(r.trim()===""){o++;continue}let u=[];for(;o<t.length&&t[o].trim()!==""&&!/^\s*```/.test(t[o])&&!/^(#{1,6})\s/.test(t[o])&&!/^\s*([-*]|\d+\.)\s+/.test(t[o])&&!cr(t[o])&&!(t[o].includes("|")&&o+1<t.length&&ur(t[o+1]));)u.push(t[o++]);n.push({kind:"para",text:u.join(" ")})}return n}function fn(e){return e.replace(/(\*\*[^*]+\*\*|`[^`]+`|\*[^*]+\*)/g,t=>t.startsWith("**")?ye.bold(t.slice(2,-2)):t.startsWith("`")?w(t.slice(1,-1)):ye.italic(t.slice(1,-1)))}var Wi=(e,t)=>e+" ".repeat(Math.max(0,t-mn(e)));function Bi(e,t,n){let o=e.length,r=e.map((_,I)=>Math.max(mn(_),...t.map(H=>mn(H[I]??"")))),l=Math.max(24,n),u=3*o+1,p=[...r],k=()=>p.reduce((_,I)=>_+I,0)+u,f=0;for(;k()>l&&f++<1e4;){let _=-1,I=6;for(let H=0;H<o;H++)p[H]>I&&(I=p[H],_=H);if(_===-1)break;p[_]-=1}let v=(_,I,H)=>ye.gray(_+p.map(W=>"\u2500".repeat(W+2)).join(I)+H),R=ye.gray("\u2502"),b=(_,I)=>{let H=p.map((oe,me)=>{let re=_[me]??"",se=I?ye.bold(re):fn(re);return pn(se,oe,{hard:!0}).split(`
28
+ `)}),W=Math.max(...H.map(oe=>oe.length)),Q=[];for(let oe=0;oe<W;oe++)Q.push(p.map((me,re)=>`${R} ${Wi(H[re][oe]??"",me)} `).join("")+R);return Q.join(`
29
+ `)},S=[v("\u250C","\u252C","\u2510"),b(e,!0)];return S.push(t.length===0?v("\u2514","\u2534","\u2518"):v("\u251C","\u253C","\u2524")),t.forEach((_,I)=>{S.push(b(_,!1)),S.push(I===t.length-1?v("\u2514","\u2534","\u2518"):v("\u251C","\u253C","\u2524"))}),S.join(`
30
+ `)}function Hi(e,t){switch(e.kind){case"heading":return ye.bold(e.text);case"hr":return ye.gray("\u2500".repeat(t));case"para":return pn(fn(e.text),t);case"list":return e.items.map(n=>{let[o="",...r]=pn(fn(n),Math.max(10,t-4)).split(`
31
+ `);return" \u2022 "+o+r.map(l=>`
32
+ `+l).join("")}).join(`
33
+ `);case"code":return e.lines.map(n=>ye.gray(" "+n)).join(`
34
+ `);case"table":return Bi(e.header,e.rows,t)}}function gn(e,t){let n=Math.max(20,t);return Ui(e).map(o=>Hi(o,n)).join(`
35
35
 
36
- `)}M();import Bi from"picocolors";var Hi=[127,86,217],Fi=[22,38,43],ur={T:Hi,E:Fi},Qe=["..TTTTTT....","..TTTTTTT...","..TTTTTTTT..","..TTETTETT..","..TTETTETT..","..TTTTTTTT..","..TTTTTTT...","..TTTTTT....","...T..T....."],fo=([e,t,o])=>`\x1B[38;2;${e};${t};${o}m`,qi=([e,t,o])=>`\x1B[48;2;${e};${t};${o}m`;function dr(){if(!Bi.isColorSupported)return[];let e=Qe[0].length,t=[];for(let o=0;o<Qe.length;o+=2){let n="";for(let r=0;r<e;r++){let i=ur[Qe[o][r]],u=o+1<Qe.length?ur[Qe[o+1][r]]:void 0;i&&u?n+=`${fo(i)}${qi(u)}\u2580\x1B[49m\x1B[39m`:i?n+=`${fo(i)}\u2580\x1B[39m`:u?n+=`${fo(u)}\u2584\x1B[39m`:n+=" "}t.push(n)}return t}function ho(e){return e<60?`${e}s`:`${Math.floor(e/60)}m ${e%60}s`}var Ue=(e,t)=>` ${e.padEnd(13)}${t}`;function zi(e,t){let o=[ze("\u270E document360-writer")+D.gray(` v${e.version}`),D.gray(" Reads your code, writes your docs."),"",Ue("Claude:",`${e.claude}${D.gray(` \xB7 ${e.model}${e.modelSource?` (${e.modelSource})`:""}`)}`),Ue("Document360:",e.configured?e.loggedOut?D.yellow("not logged in \u2014 run /login"):`${e.who??""}${e.sessionHint?D.gray(` (${e.sessionHint})`):""}`:D.yellow("not set up \u2014 run /init")),Ue("Profile:",e.configured?`${e.profile}${D.gray(` (${e.apiUrl})`)}${e.prod?D.bold(D.yellow(" \u26A0 PRODUCTION")):""}`:D.gray("\u2014 (run /init)")),Ue("Project:",e.project),Ue("Mode:",D.gray(e.mode)),Ue("cwd:",D.gray(e.cwd))],n=dr();if(n.length===0)return o.join(`
37
- `);let r=2,i=3,u=go(n[0]);if(!(t>=r+u+i+Math.max(...o.map(b=>go(b)))))return[...n.map(b=>" "+b),...o].join(`
38
- `);let k=Math.max(0,Math.floor((o.length-n.length)/2)),f=[];for(let b=0;b<Math.max(n.length+k,o.length);b++){let R=n[b-k]??" ".repeat(u);f.push((" ".repeat(r)+R+" ".repeat(i)+(o[b]??"")).trimEnd())}return f.join(`
39
- `)}var Gi={error:D.red,warn:D.yellow,ok:D.green,info:D.gray};function ko(e,t){let o=Math.max(20,t);switch(e.kind){case"banner":return zi(e.info,o);case"user":{let n="\x1B[48;2;42;42;46m",r="\x1B[49m",i=Math.max(10,o-4),u=50,p=e.text.split(`
40
- `).flatMap(f=>pr(f,i,{hard:!0}).split(`
36
+ `)}L();import Fi from"picocolors";var qi=[127,86,217],zi=[22,38,43],pr={T:qi,E:zi},et=["..TTTTTT....","..TTTTTTT...","..TTTTTTTT..","..TTETTETT..","..TTETTETT..","..TTTTTTTT..","..TTTTTTT...","..TTTTTT....","...T..T....."],hn=([e,t,n])=>`\x1B[38;2;${e};${t};${n}m`,Gi=([e,t,n])=>`\x1B[48;2;${e};${t};${n}m`;function mr(){if(!Fi.isColorSupported)return[];let e=et[0].length,t=[];for(let n=0;n<et.length;n+=2){let o="";for(let r=0;r<e;r++){let l=pr[et[n][r]],u=n+1<et.length?pr[et[n+1][r]]:void 0;l&&u?o+=`${hn(l)}${Gi(u)}\u2580\x1B[49m\x1B[39m`:l?o+=`${hn(l)}\u2580\x1B[39m`:u?o+=`${hn(u)}\u2584\x1B[39m`:o+=" "}t.push(o)}return t}function wn(e){return e<60?`${e}s`:`${Math.floor(e/60)}m ${e%60}s`}var Be=(e,t)=>` ${e.padEnd(13)}${t}`;function Xi(e,t){let n=[Xe("\u270E document360-writer")+D.gray(` v${e.version}`),D.gray(" Reads your code, writes your docs."),"",Be("Claude:",`${e.claude}${D.gray(` \xB7 ${e.model}${e.modelSource?` (${e.modelSource})`:""}`)}`),Be("Document360:",e.configured?e.loggedOut?D.yellow("not logged in \u2014 run /login"):`${e.who??""}${e.sessionHint?D.gray(` (${e.sessionHint})`):""}`:D.yellow("not set up \u2014 run /init")),Be("Profile:",e.configured?`${e.profile}${D.gray(` (${e.apiUrl})`)}${e.prod?D.bold(D.yellow(" \u26A0 PRODUCTION")):""}`:D.gray("\u2014 (run /init)")),Be("Project:",e.project),Be("Mode:",D.gray(e.mode)),Be("cwd:",D.gray(e.cwd))],o=mr();if(o.length===0)return n.join(`
37
+ `);let r=2,l=3,u=kn(o[0]);if(!(t>=r+u+l+Math.max(...n.map(v=>kn(v)))))return[...o.map(v=>" "+v),...n].join(`
38
+ `);let k=Math.max(0,Math.floor((n.length-o.length)/2)),f=[];for(let v=0;v<Math.max(o.length+k,n.length);v++){let R=o[v-k]??" ".repeat(u);f.push((" ".repeat(r)+R+" ".repeat(l)+(n[v]??"")).trimEnd())}return f.join(`
39
+ `)}var Vi={error:D.red,warn:D.yellow,ok:D.green,info:D.gray};function yn(e,t){let n=Math.max(20,t);switch(e.kind){case"banner":return Xi(e.info,n);case"user":{let o="\x1B[48;2;42;42;46m",r="\x1B[49m",l=Math.max(10,n-4),u=50,p=e.text.split(`
40
+ `).flatMap(f=>fr(f,l,{hard:!0}).split(`
41
41
  `)),k=Math.max(0,p.length-u);return k>0&&(p=[...p.slice(0,u),D.dim(`\u2026 +${k} more lines`)]),`
42
- `+p.map((f,b)=>n+(b===0?y(" \u276F "):" ")+f+" ".repeat(Math.max(0,i-go(f))+1)+r).join(`
42
+ `+p.map((f,v)=>o+(v===0?w(" \u276F "):" ")+f+" ".repeat(Math.max(0,l-kn(f))+1)+r).join(`
43
43
  `)}case"assistant":return`
44
- `+mo(e.text,o);case"tool":{let n=e.arg!==null?D.gray(`${e.sep}(${e.arg})`):"";return`
45
- `+pr(D.green("\u25CF ")+D.bold(e.title)+n,o)}case"tool-result":{let n=e.isError?D.red:D.gray,r=e.lines.map((i,u)=>n((u===0?" \u23BF ":" ")+i));return e.hidden>0&&r.push(D.dim(` \u2026 +${e.hidden} lines`)),r.join(`
46
- `)}case"diff":{let n=u=>u===1?"":"s",i=[D.gray(` \u23BF Added ${e.added} line${n(e.added)}, removed ${e.removed} line${n(e.removed)}`),...e.lines];return e.hidden>0&&i.push(D.dim(` \u2026 +${e.hidden} more diff lines`)),i.join(`
47
- `)}case"link":return e.lines.map(n=>y(Ge(` \u2B95 ${n}`))).join(`
44
+ `+gn(e.text,n);case"tool":{let o=e.arg!==null?D.gray(`${e.sep}(${e.arg})`):"";return`
45
+ `+fr(D.green("\u25CF ")+D.bold(e.title)+o,n)}case"tool-result":{let o=e.isError?D.red:D.gray,r=e.lines.map((l,u)=>o((u===0?" \u23BF ":" ")+l));return e.hidden>0&&r.push(D.dim(` \u2026 +${e.hidden} lines`)),r.join(`
46
+ `)}case"diff":{let o=u=>u===1?"":"s",l=[D.gray(` \u23BF Added ${e.added} line${o(e.added)}, removed ${e.removed} line${o(e.removed)}`),...e.lines];return e.hidden>0&&l.push(D.dim(` \u2026 +${e.hidden} more diff lines`)),l.join(`
47
+ `)}case"link":return e.lines.map(o=>w(Ve(` \u2B95 ${o}`))).join(`
48
48
  `);case"preview":return`
49
- `+ze(`\u25A3 Preview \u2014 ${e.name}`)+`
49
+ `+Xe(`\u25A3 Preview \u2014 ${e.name}`)+`
50
50
 
51
- `+mo(e.text,o);case"note":return`
52
- `+Gi[e.tone](Ge(e.text));case"done":return`
53
- `+(e.ok?D.magenta("\u2736 "):D.red("\u2736 "))+D.gray(`Cooked for ${ho(e.seconds)} \xB7 ${e.tokens} tokens`)}}function mr(e,t){return e.map(o=>ko(o,t)).join(`
54
- `)}function fr(e,t,o){let n=Math.max(1,o),r=e.split(`
55
- `),i=0;for(let u=r.length-1;u>=0;u--){let p=r[u];if(i+=Math.max(1,Math.ceil(p.length/n)),i>=t){let k=i-t;return{text:[k>0?p.slice(k*n):p,...r.slice(u+1)].join(`
56
- `),truncated:u>0||k>0}}}return{text:e,truncated:!1}}function gr(e){let t=!1,o=0,n=0;for(let r of e.split(`
57
- `)){let i=n+r.length;/^\s*```/.test(r)?t=!t:!t&&r.trim()===""&&i<e.length&&(o=i+1),n=i+1}return o}import{Fragment as xo,jsx as C,jsxs as N}from"react/jsx-runtime";var hl={project:".d360-writer.json",user:"/model",env:"ANTHROPIC_MODEL","claude-settings":"Claude Code settings","claude-default":""};function kl(e,t,o,n){let r=o.kind==="api"?"API key":o.kind==="subscription"?"subscription":"not configured",i=$o(e),u=je(e),p=(u?.docsDir??"user-docs").replace(/\/+$/,""),k=u?.mode==="engineer"?"engineer \xB7 full source access (dogfooding)":`writer \xB7 edits limited to ${p}/ + config`,f={version:t,claude:r,model:i.model??"Claude Code default model",modelSource:hl[i.source],who:null,sessionHint:null,profile:"\u2014",apiUrl:"\u2014",project:"\u2014",cwd:e,prod:!1,loggedOut:!0,configured:u!==null,mode:k};if(u===null)return f;try{let b=ae(e,n);f.profile=b.name,f.apiUrl=b.connection.apiUrl,f.prod=b.production,f.project=b.project.projectId??"(chosen at login)";let R=Ae(b.name);if(R){let $={...We(R.idToken)??{},...We(R.accessToken)??{}},S=$.email??$.preferred_username??"signed in";ye(R)?R.refreshToken&&(f.who=S,f.loggedOut=!1,f.sessionHint="session expired \u2014 refreshing\u2026"):(f.who=S,f.loggedOut=!1,f.sessionHint=`session valid until ${new Date(R.expiresAt).toLocaleString(void 0,{hour:"2-digit",minute:"2-digit",day:"2-digit",month:"short"})}`)}}catch{}return f}function wl(e,t){try{let o=ae(e,t),n=Ae(o.name);if(!n)return{text:`profile "${o.name}" \u2014 not logged in (/login)`,prod:o.production};let r={...We(n.idToken)??{},...We(n.accessToken)??{}},i=r.email??r.preferred_username??"signed in";return ye(n)&&!n.refreshToken?{text:`profile "${o.name}" \u2014 session expired (/login)`,prod:o.production}:{text:`${i} \xB7 profile "${o.name}"`,prod:o.production}}catch(o){return{text:o.message.split(".")[0],prod:!1}}}var $r=["Drafting","Composing","Outlining","Researching","Documenting","Structuring","Polishing","Synthesizing","Curating","Distilling","Weaving","Wrangling","Pondering"],br=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"],yl="Ask me to write or update an article\u2026";function Ot({ch:e,dim:t}){let[o,n]=O(!0);return Ze(()=>{let r=setInterval(()=>n(i=>!i),530);return()=>clearInterval(r)},[]),C(v,{inverse:o,color:t&&!o?"gray":void 0,children:e})}var xl=/^mcp__document360__d360_(create_article|update_article|fork_article|publish_article)$/;function vr(e){let t=e.match(/^---\r?\n[\s\S]*?\r?\n---\r?\n/);return t?e.slice(t[0].length):e}var $l=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function Cr(e){try{return Ki(e,{withFileTypes:!0}).filter(t=>t.isDirectory()&&!t.name.startsWith(".")).length>6}catch{return!1}}function bl(e,t){let o=t??[];return o.length===0?["src","api","services","packages","modules"].some(n=>Cr(Ut(e,n))):o.some(n=>!n.includes("/")&&!n.endsWith(".md")&&Cr(Ut(e,n)))}function vl({startTime:e,chars:t}){let[o,n]=O(0);Ze(()=>{let k=setInterval(()=>n(f=>f+1),120);return()=>clearInterval(k)},[]);let r=br[o%br.length],i=$r[Math.floor(o/16)%$r.length],u=Math.floor((Date.now()-e)/1e3),p=Math.round(t/4);return N(V,{children:[C(v,{color:B,children:` ${r} ${i}\u2026 `}),C(v,{color:"gray",children:`(${ho(u)} \xB7 ~${p} tokens \xB7 esc to interrupt)`})]})}function Pr({cwd:e,auth:t,profileName:o,version:n}){let{exit:r}=Vi(),[i,u]=O(o),[p,k]=O(null),[f,b]=O({text:"",pos:0}),R=f.text,$=F(a=>{b(s=>{let l=typeof a=="function"?a(s.text):a;return{text:l,pos:l.length}})},[]),S=F(a=>{b(s=>({text:s.text.slice(0,s.pos)+a+s.text.slice(s.pos),pos:s.pos+a.length}))},[]),_=F(()=>{b(a=>{if(a.pos===0)return a;let s=a.text.slice(0,a.pos),l=rr(s)??s.slice(0,-1);return{text:l+a.text.slice(a.pos),pos:l.length}})},[]),[I,H]=O(!1),[U,K]=O(!1),[oe,me]=O(0),[ne,re]=O(null),[Be,X]=O([]),et=G(0),[jr,Co]=O(!1),[Ar,Po]=O(0),Wt=G(0),[He,Ie]=O(0),[Ee,tt]=O(null),To=G(new Map),Ir=G(0),Bt=G([]),Q=G(null);Q.current===null&&(Q.current=wr({cwd:e,profileName:i,allowProdWrites:!1}));let xe=G({uuid:null,firstPrompt:null,titleFired:!1}),ot=G(new Map),So=G(!1),Ht=G([]),fe=G([]),[$e,be]=O(null),[ce,De]=O(null),[se,_e]=O(null),[ue,Me]=O(null),[Z,ve]=O(null),[Y,Le]=O(null),[Ro,Ft]=O([]),Ce=G([]),nt=G(!1),rt=G(!1),st=G(null),[ee,Pe]=O(null),[it,jo]=O(0),[Er,Ao]=O(0),qt=Nt(()=>{try{return $o(e).model??"Claude Code default"}catch{return null}},[e,Er]),{stdout:ie}=Yi(),[,Dr]=O(0),Io=G(`${ie.columns??80}x${ie.rows??24}`),ge=F(()=>Math.max(20,(ie.columns??80)-1),[ie]),d=F(a=>{Bt.current.push(a),console.log(ko(a,ge()))},[ge]);Ze(()=>{if(d({kind:"banner",info:kl(e,n,t,i)}),!je(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:
58
- 1. /init scaffolds the config
59
- 2. /login signs in to Document360
51
+ `+gn(e.text,n);case"note":return`
52
+ `+Vi[e.tone](Ve(e.text));case"done":return`
53
+ `+(e.ok?D.magenta("\u2736 "):D.red("\u2736 "))+D.gray(`Cooked for ${wn(e.seconds)} \xB7 ${e.tokens} tokens`)}}function gr(e,t){return e.map(n=>yn(n,t)).join(`
54
+ `)}function hr(e,t,n){let o=Math.max(1,n),r=e.split(`
55
+ `),l=0;for(let u=r.length-1;u>=0;u--){let p=r[u];if(l+=Math.max(1,Math.ceil(p.length/o)),l>=t){let k=l-t;return{text:[k>0?p.slice(k*o):p,...r.slice(u+1)].join(`
56
+ `),truncated:u>0||k>0}}}return{text:e,truncated:!1}}function kr(e){let t=!1,n=0,o=0;for(let r of e.split(`
57
+ `)){let l=o+r.length;/^\s*```/.test(r)?t=!t:!t&&r.trim()===""&&l<e.length&&(n=l+1),o=l+1}return n}import{Fragment as bn,jsx as C,jsxs as M}from"react/jsx-runtime";var xl={project:".d360-writer.json",user:"/model",env:"ANTHROPIC_MODEL","claude-settings":"Claude Code settings","claude-default":""};function $l(e,t,n,o){let r=n.kind==="api"?"API key":n.kind==="subscription"?"subscription":"not configured",l=vn(e),u=xe(e),p=(u?.docsDir??"user-docs").replace(/\/+$/,""),k=u?.mode==="engineer"?"engineer \xB7 full source access (dogfooding)":`writer \xB7 edits limited to ${p}/ + config`,f={version:t,claude:r,model:l.model??"Claude Code default model",modelSource:xl[l.source],who:null,sessionHint:null,profile:"\u2014",apiUrl:"\u2014",project:"\u2014",cwd:e,prod:!1,loggedOut:!0,configured:u!==null,mode:k};if(u===null)return f;try{let v=ae(e,o);f.profile=v.name,f.apiUrl=v.connection.apiUrl,f.prod=v.production,f.project=v.project.projectId??"(chosen at login)";let R=Ie(v.name);if(R){let b={...He(R.idToken)??{},...He(R.accessToken)??{}},S=b.email??b.preferred_username??"signed in";$e(R)?R.refreshToken&&(f.who=S,f.loggedOut=!1,f.sessionHint="session expired \u2014 refreshing\u2026"):(f.who=S,f.loggedOut=!1,f.sessionHint=`session valid until ${new Date(R.expiresAt).toLocaleString(void 0,{hour:"2-digit",minute:"2-digit",day:"2-digit",month:"short"})}`)}}catch{}return f}function bl(e,t){try{let n=ae(e,t),o=Ie(n.name);if(!o)return{text:`profile "${n.name}" \u2014 not logged in (/login)`,prod:n.production};let r={...He(o.idToken)??{},...He(o.accessToken)??{}},l=r.email??r.preferred_username??"signed in";return $e(o)&&!o.refreshToken?{text:`profile "${n.name}" \u2014 session expired (/login)`,prod:n.production}:{text:`${l} \xB7 profile "${n.name}"`,prod:n.production}}catch(n){return{text:n.message.split(".")[0],prod:!1}}}var vr=["Drafting","Composing","Outlining","Researching","Documenting","Structuring","Polishing","Synthesizing","Curating","Distilling","Weaving","Wrangling","Pondering"],Cr=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"],vl="Ask me to write or update an article\u2026";function Wt({ch:e,dim:t}){let[n,o]=O(!0);return tt(()=>{let r=setInterval(()=>o(l=>!l),530);return()=>clearInterval(r)},[]),C($,{inverse:n,color:t&&!n?"gray":void 0,children:e})}var Cl=/^mcp__document360__d360_(create_article|update_article|fork_article|publish_article)$/;function Pr(e){let t=e.match(/^---\r?\n[\s\S]*?\r?\n---\r?\n/);return t?e.slice(t[0].length):e}var Pl=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function Tr(e){try{return Zi(e,{withFileTypes:!0}).filter(t=>t.isDirectory()&&!t.name.startsWith(".")).length>6}catch{return!1}}function Tl(e,t){let n=t??[];return n.length===0?["src","api","services","packages","modules"].some(o=>Tr(Bt(e,o))):n.some(o=>!o.includes("/")&&!o.endsWith(".md")&&Tr(Bt(e,o)))}function Sl({startTime:e,chars:t}){let[n,o]=O(0);tt(()=>{let k=setInterval(()=>o(f=>f+1),120);return()=>clearInterval(k)},[]);let r=Cr[n%Cr.length],l=vr[Math.floor(n/16)%vr.length],u=Math.floor((Date.now()-e)/1e3),p=Math.round(t/4);return M(X,{children:[C($,{color:U,children:` ${r} ${l}\u2026 `}),C($,{color:"gray",children:`(${wn(u)} \xB7 ~${p} tokens \xB7 esc to interrupt)`})]})}function Sr({cwd:e,auth:t,profileName:n,version:o}){let{exit:r}=Yi(),[l,u]=O(n),[p,k]=O(null),[f,v]=O({text:"",pos:0}),R=f.text,b=F(a=>{v(i=>{let s=typeof a=="function"?a(i.text):a;return{text:s,pos:s.length}})},[]),S=F(a=>{v(i=>({text:i.text.slice(0,i.pos)+a+i.text.slice(i.pos),pos:i.pos+a.length}))},[]),_=F(()=>{v(a=>{if(a.pos===0)return a;let i=a.text.slice(0,a.pos),s=ir(i)??i.slice(0,-1);return{text:s+a.text.slice(a.pos),pos:s.length}})},[]),[I,H]=O(!1),[W,Q]=O(!1),[oe,me]=O(0),[re,se]=O(null),[Fe,V]=O([]),nt=G(0),[Ir,Tn]=O(!1),[Er,Sn]=O(0),Ht=G(0),[qe,Ee]=O(0),[De,ot]=O(null),Rn=G(new Map),Dr=G(0),Ft=G([]),Z=G(null);Z.current===null&&(Z.current=xr({cwd:e,profileName:l,allowProdWrites:!1}));let be=G({uuid:null,firstPrompt:null,titleFired:!1}),rt=G(new Map),jn=G(!1),qt=G([]),fe=G([]),[ve,Ce]=O(null),[ce,Me]=O(null),[ge,_e]=O(null),[Y,Le]=O(null),[ue,Ne]=O(null),[ee,Pe]=O(null),[J,Oe]=O(null),[An,zt]=O([]),Te=G([]),st=G(!1),it=G(!1),lt=G(null),[te,Se]=O(null),[at,In]=O(0),[Mr,En]=O(0),Gt=Ut(()=>{try{return vn(e).model??"Claude Code default"}catch{return null}},[e,Mr]),{stdout:ie}=Ki(),[,_r]=O(0),Dn=G(`${ie.columns??80}x${ie.rows??24}`),he=F(()=>Math.max(20,(ie.columns??80)-1),[ie]),d=F(a=>{Ft.current.push(a),console.log(yn(a,he()))},[he]);tt(()=>{if(d({kind:"banner",info:$l(e,o,t,l)}),!xe(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:
58
+ 1. /init \u2014 pick your Document360 environment & scaffold config
59
+ 2. /login signs in to that environment
60
60
  3. /workspace picks where articles go
61
- Press 1 to start.`}),X(["/init"]);return}try{let a=ae(e,i),s=Ae(a.name);s&&ye(s)&&s.refreshToken?ol({profile:a.name,connection:a.connection}).then(()=>{d({kind:"note",tone:"ok",text:"\u2713 Document360 session refreshed."}),me(l=>l+1)}).catch(()=>{d({kind:"note",tone:"warn",text:"Document360 session refresh failed \u2014 do you want to log in now? (press 1)"}),X(["/login"])}):(!s||ye(s))&&(d({kind:"note",tone:"warn",text:`Profile "${a.name}" is not signed in \u2014 do you want to log in now? (press 1)`}),X(["/login"]))}catch{}try{let a=je(e),s=ae(e,i),l=Ae(s.name);a&&l&&!ye(l)&&bl(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."}),X(["/scope"]))}catch{}},[]),Ze(()=>{let a=null,s=null,l=()=>{a&&clearTimeout(a),a=setTimeout(()=>{a=null;let g=`${ie.columns??80}x${ie.rows??24}`;g!==Io.current&&(Io.current=g,Dr(m=>m+1),s&&clearTimeout(s),s=setTimeout(()=>{s=null,console.log("\x1B[?2026h\x1B[H\x1B[2J"+mr(Bt.current,ge())+"\x1B[?2026l")},80))},400)};return ie.on("resize",l),()=>{a&&clearTimeout(a),s&&clearTimeout(s),ie.off("resize",l)}},[ie,ge]);let Te=Math.max(20,(ie.columns??80)-1),Eo=Nt(()=>wl(e,i),[e,i,oe]),Do=Nt(()=>{if(!je(e))return"Press 1 to set up this repo, or /help\u2026";try{let a=ae(e,i),s=Ae(a.name);if(!(!!s&&!(ye(s)&&!s.refreshToken)))return`Press 1 to sign in to Document360 (profile "${a.name}")\u2026`;if(!a.project.workspaceId)return"Press 1 to pick a workspace\u2026"}catch{}return yl},[e,i,oe]),Fe=Kn(R),_o=Fe.length>0&&!I,zt=p!==null?fr(p,8,Te):null,lt=Z?Z.paths.filter(a=>!Z.query||a.toLowerCase().includes(Z.query.toLowerCase())).slice(0,8):[],at=ee?ee.sessions.filter(a=>{let s=ee.query.toLowerCase();return!s||a.name.toLowerCase().includes(s)||a.firstPrompt.toLowerCase().includes(s)}).slice(0,8):[],de=F((a,s)=>{Q.current?.close(),Q.current=wr({cwd:e,resume:a,profileName:s??i,allowProdWrites:So.current}),a||(xe.current={uuid:null,firstPrompt:null,titleFired:!1}),jo(0)},[e,i]),Mo=F((a,s,l)=>{if(xl.test(a))try{let g=ae(e,i),m=typeof s.project_id=="string"&&s.project_id||g.project.projectId,h=Et(s,l),w=[],j=Dt(l);a.endsWith("publish_article")&&j&&w.push(`Live: ${j}`),h&&m&&w.push(`Preview: ${It(g.connection.portalUrl,m,h,g.project.languageCode??"en")}`),w.length>0&&d({kind:"link",lines:w})}catch{}},[e,i,d]),Se=F(async(a,s)=>{Co(!0),re(null),X([]);let l=++et.current;d({kind:"user",text:s?.echoDisplay&&s.display?s.display:a});let g=xe.current;g.firstPrompt||(g.firstPrompt=s?.display??a),Wt.current=Date.now(),Po(0),H(!0),ot.current.clear();let m="",h="",w=null,j=()=>{w||(w=setTimeout(()=>{w=null,k(h.length>0?h:null)},60))},L=()=>{w&&clearTimeout(w),w=null,k(null)},W=()=>{if(h.trim()){let P=h.trimEnd();d({kind:"assistant",text:P})}h="",L()};try{for await(let P of Q.current.send(a))if(P.type==="session"){if(!g.uuid){g.uuid=P.sessionId;let A=new Date().toISOString();ll({uuid:P.sessionId,name:il(g.firstPrompt??"session"),renamed:!1,titled:!1,cwd:e,firstPrompt:g.firstPrompt??"",createdAt:A,updatedAt:A})}}else if(P.type==="text"){h+=P.delta,m+=P.delta;let A=gr(h);if(A>0){let q=h.slice(0,A).trimEnd();q&&d({kind:"assistant",text:q}),h=h.slice(A)}j(),Po(q=>q+P.delta.length)}else if(P.type==="tool"){let A=jt(P.name,P.input);A&&(W(),d({kind:"tool",title:A.title,sep:A.sep,arg:A.arg}),ot.current.set(P.id,{name:P.name,input:P.input}))}else if(P.type==="article_diff"){let A=Re(P.oldContent,P.newContent,ge());A&&(W(),d({kind:"diff",added:A.added,removed:A.removed,lines:A.lines,hidden:A.hidden}))}else if(P.type==="tool_result"){P.isError&&/run \/login|not logged in|session expired|rejected the token/i.test(P.output)&&(rt.current=!0);let A=ot.current.get(P.id);if(A){ot.current.delete(P.id),W();let q=At(P.output,4,P.isError?void 0:A.name,A.input);d({kind:"tool-result",lines:q.lines,hidden:q.hidden,isError:P.isError}),P.isError||Mo(A.name,A.input,P.output)}}else if(P.type==="result"){W(),jo(q=>q+P.outputTokens),d({kind:"done",seconds:Math.round((Date.now()-Wt.current)/1e3),tokens:P.outputTokens,ok:P.ok});let A=P.ok?Zn(m,_t.map(q=>q.name)):[];if(A.length>0?X(A):P.ok&&m.trim()&&dl(a,m,e).then(q=>{q&&et.current===l&&re(q)}).catch(()=>{}),g.uuid&&(wo(g.uuid),!g.titleFired)){g.titleFired=!0;let q=g.uuid,Ho=g.firstPrompt;Ho&&yr(Ho,e).then(Fo=>Fo&&sl(q,Fo)).catch(()=>{})}}else P.type==="error"&&(W(),P.kind==="auth"&&(rt.current=!0),d({kind:"note",text:`agent error: ${P.message}`,tone:"error"}))}finally{H(!1),L(),rt.current&&(rt.current=!1,st.current=s?.display??a,X(["/login"])),nt.current&&(nt.current=!1,Ce.current.length>0&&(d({kind:"note",tone:"info",text:`(${Ce.current.length} queued message(s) discarded)`}),Ce.current=[],Ft([])),d({kind:"note",tone:"warn",text:"Interrupted. What do you want to do next?"}))}},[e,d,Mo,ge]),Gt=F(a=>{let s=Ae(a);if(!s||ye(s)&&!s.refreshToken)return null;let l={...We(s.idToken)??{},...We(s.accessToken)??{}};return l.email??l.preferred_username??"signed in"},[]),Vt=F((a,s)=>{if(s){let l=je(e);l&&(l.defaultProfile=a,pl(l,e))}u(a),de(void 0,a),d({kind:"note",tone:"ok",text:`\u2713 Switched to profile "${a}"${s?" (saved as default)":" (this session only)"} \u2014 agent restarted.`}),Gt(a)||(d({kind:"note",tone:"warn",text:`Profile "${a}" is not signed in \u2014 do you want to log in now? (press 1)`}),X(["/login"])),me(l=>l+1)},[e,d,de,Gt]),Lo=F((a,s,l)=>{mt(e,a,s,l.id),d({kind:"note",tone:"ok",text:`Switched to workspace "${l.name??l.id}" (agent restarted).`}),de(),xr(e,a)||(d({kind:"note",tone:"info",text:"Setup complete. Press tab to start with a docs analysis."}),re("analyze this repo and propose a docs structure"))},[e,d,de]),ct=F(()=>{let a=fe.current[0];if(!a)return;d({kind:"note",tone:"info",text:`\u25CF ${a.title} (${a.path})`});for(let l of a.notes)d({kind:"note",tone:"warn",text:`\u26A0 ${l}`});a.overwritesLocalChanges&&d({kind:"note",tone:"warn",text:"\u26A0 This OVERWRITES local edits made since the last sync."});let s=Re(a.oldContent,a.newContent,ge());d(s?{kind:"diff",added:s.added,removed:s.removed,lines:s.lines,hidden:s.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,ge]),No=F(a=>{if(fe.current.length===0)return!1;let s=a.trim().toLowerCase();if(s==="y"||s==="yes"){let l=fe.current.shift();try{ml({cwd:e,profileName:i},l),d({kind:"note",tone:"ok",text:`\u2713 Pulled ${l.path} (sync base advanced).`}),fe.current.length===0&&X(g=>g.length>0?g:["/sync"])}catch(g){d({kind:"note",tone:"error",text:`Pull failed: ${g.message}`})}}else if(s==="n"||s==="no"){let l=fe.current.shift();d({kind:"note",tone:"info",text:`Skipped ${l.path}.`})}else{let l=fe.current.length;return fe.current=[],d({kind:"note",tone:"info",text:`Pull cancelled (${l} article(s) left untouched).`}),!0}return ct(),!0},[e,i,ct,d]),Oo=F(async a=>{let s=a.slice(1).trim().split(/\s+/),l=(s[0]??"").toLowerCase(),g=s.slice(1);switch(l){case"help":d({kind:"note",tone:"info",text:_t.map(m=>` ${m.usage.padEnd(22)} ${m.desc}`).join(`
62
- `)});return;case"exit":case"quit":Q.current?.close(),r();return;case"clear":de(),Bt.current=[],Co(!1),re(null),et.current++,d({kind:"note",tone:"info",text:"Conversation reset (the previous session is still resumable via /resume)."});return;case"login":{let m;try{m=ae(e,i)}catch(h){d({kind:"note",tone:"error",text:h.message});return}d({kind:"note",tone:"info",text:`Profile "${m.name}" \u2192 ${m.connection.name} (${m.connection.apiUrl})${m.production?" \u26A0 PRODUCTION":""}`}),K(!0);try{let h=await Zi(m.connection,{promptForRedirect:()=>Promise.reject(new Error("Manual login is CLI-only. Run: d360-writer login --manual"))},j=>d({kind:"note",tone:"info",text:j})),w=el(m.name,h);tl(w),Jt(w,m.name,j=>d({kind:"note",tone:"info",text:j})),d({kind:"note",tone:"ok",text:`\u2713 Logged in to "${m.name}" as ${gt(w)}`}),m.project.workspaceId||(d({kind:"note",tone:"info",text:"Next: pick the workspace your articles publish to."}),X(["/workspace"])),st.current&&(re(st.current),st.current=null,d({kind:"note",tone:"info",text:"Press tab to re-send your last prompt."}))}catch(h){d({kind:"note",tone:"error",text:`Login failed: ${h.message}`})}finally{K(!1),me(h=>h+1)}return}case"allow-prod":{let m=!1;try{m=ae(e,i).production}catch{}if(!m){d({kind:"note",tone:"info",text:"Current profile is not production \u2014 writes are already allowed."});return}So.current=!0,de(),d({kind:"note",tone:"warn",text:"\u26A0 Production writes authorized for this session."});return}case"rename":{let m=g.join(" ").trim(),h=xe.current.uuid;if(!h){d({kind:"note",tone:"error",text:"Send a message first \u2014 sessions save once the agent replies."});return}if(!m){d({kind:"note",tone:"info",text:"Thinking of a name\u2026"});let w=xe.current.firstPrompt??"";yr(w,e).then(j=>{j?(re(`/rename ${j}`),d({kind:"note",tone:"info",text:`Suggestion: "${j}" \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}ul(h,m),d({kind:"note",tone:"ok",text:`Session renamed to "${m}".`});return}case"profile":{let m=g[0],h=je(e);if(!m){let w=Object.entries(h?.profiles??{});if(w.length===0){d({kind:"note",tone:"info",text:"No profiles. Run /init first."});return}let j=w.map(([P,A])=>({name:P,env:A.connection?.environment??"custom",prod:A.production===!0,who:Gt(P)})),L=i??h?.defaultProfile,W=Math.max(0,j.findIndex(P=>P.name===L));De({cursor:W,current:W,rows:j});return}if(m==="add"){let w=no(e,g[1],g[2]);if(w){d({kind:"note",tone:"error",text:w});return}d({kind:"note",tone:"ok",text:`\u2713 Profile "${g[1]}" created (environment: ${g[2]??g[1]}).`}),Vt(g[1],!1);return}if(!h?.profiles?.[m]){d({kind:"note",tone:"error",text:`Unknown profile "${m}". Create it: /profile add ${m} <environment>`});return}Vt(m,!0);return}case"doctor":await Ke(g,{cwd:e});return;case"mcp":await xt(g);return;case"init":{let m=an(e);if(!m.created){d({kind:"note",tone:"info",text:`${m.path} already exists \u2014 edit it directly (the interactive wizard lives in d360-writer init).`});return}d({kind:"note",tone:"ok",text:`\u2713 Wrote ${m.path} (profile "${m.profileName}", defaults \u2014 edit to taste).`});let h=!1;try{let w=Ae(m.profileName);h=!!w&&!(ye(w)&&!w.refreshToken)}catch{}h?(d({kind:"note",tone:"info",text:`Already signed in (profile "${m.profileName}") \u2014 next: pick a workspace.`}),X(["/workspace"])):(d({kind:"note",tone:"info",text:"Next: sign in to Document360."}),X(["/login"])),me(w=>w+1);return}case"resume":{let m=g.join(" ").trim(),h=cl(e).filter(j=>j.uuid!==xe.current.uuid);if(!m){if(!h.length){d({kind:"note",tone:"info",text:"No saved sessions for this repo yet."});return}Pe({query:"",cursor:0,sessions:h});return}let w=al(e,m);if(!w){d({kind:"note",tone:"error",text:`No session matches "${m}".`});return}de(w.uuid),xe.current={uuid:w.uuid,firstPrompt:w.firstPrompt,titleFired:!0},wo(w.uuid),d({kind:"note",tone:"ok",text:`Resumed "${w.name}".`});return}case"workspace":{let m=g.join(" ").trim(),h;try{h=await pt(e,i)}catch(j){d({kind:"note",tone:"error",text:`Could not list workspaces: ${j.message}`});return}if(!m){let j=h.workspaces.map(W=>({id:W.id,name:W.name??W.id,type:W.workspace_type}));if(j.length===0){d({kind:"note",tone:"info",text:"No workspaces in this project."});return}let L=Math.max(0,j.findIndex(W=>W.id===h.current));_e({cursor:L,current:L,rows:j,profile:h.profile,projectId:h.projectId});return}let w=Yt(h.workspaces,m);if(!w){d({kind:"note",tone:"error",text:`No workspace matches "${m}".`});return}Lo(h.profile,h.projectId,w);return}case"publish":{if(g[0]&&g[0]!=="--all"){await Se(bt(g[0]),{display:`/publish ${g[0]}`,echoDisplay:!0});return}let m=g[0]==="--all";d({kind:"note",tone:"info",text:"Checking what needs publishing\u2026"});try{let h=await yo({cwd:e,profileName:i}),w=$t(h.entries);if(w.length===0){d({kind:"note",tone:"ok",text:"\u2713 Nothing is ahead of Document360 \u2014 no publish candidates."});let L=h.counts["unknown-base"]??0;L>0&&d({kind:"note",tone:"info",text:`(${L} article(s) have no sync base yet \u2014 publish those by path if needed.)`});return}if(m){await Se(Ye(w.map(L=>L.path)),{display:"/publish --all",echoDisplay:!0});return}let j=w.length>1?[{path:"--all",label:`publish all ${w.length} candidates in one run`},...w]:w;Me({cursor:0,rows:j})}catch(h){d({kind:"note",tone:"error",text:`Could not compute sync status: ${h.message}`}),d({kind:"note",tone:"info",text:"Publish a specific article: /publish <article-path>"})}return}case"preview":{let m=g.join(" ").trim();if(!m){let w=[];try{w=Object.keys(xr(e,ae(e,i).name)?.articles??{})}catch{}if(w.length===0){d({kind:"note",tone:"info",text:"No tracked articles to pick from yet. Usage: /preview <path-to.md | article-id>"});return}ve({query:"",cursor:0,paths:w});return}let h=Qi(m)?m:Ut(e,m);if(Ji(h)){try{d({kind:"preview",name:kr(h),text:vr(hr(h,"utf8"))})}catch(w){d({kind:"note",tone:"error",text:`Could not read ${h}: ${w.message}`})}return}if($l.test(m)){try{let w=ae(e,i),j={profile:w.name,connection:w.connection},L=w.project.projectId??nl(j),W=await rl(j,L,m);d({kind:"preview",name:W.title??m,text:W.content??"*(article has no content)*"})}catch(w){d({kind:"note",tone:"error",text:`Could not fetch article: ${w.message}`})}return}d({kind:"note",tone:"error",text:`"${m}" is neither a file (relative to ${e}) nor an article id.`});return}case"model":{let m=g[0]?.trim();if(!m){let L=Tt($o(e));be({cursor:L,current:L});return}let{lines:h,changed:w,effective:j}=Je(e,m);for(let L of h)d({kind:"note",tone:L.startsWith("\u26A0")?"warn":L.startsWith("\u2713")?"ok":"info",text:L});w&&(Ao(L=>L+1),Q.current?.setModel(j));return}case"sync":{let m=(g[0]??"status").toLowerCase();try{if(m==="status"){d({kind:"note",tone:"info",text:"Checking Document360 for drift\u2026"});let h=await yo({cwd:e,profileName:i});d({kind:"note",tone:"info",text:Pt(h).join(`
63
- `)});return}if(m==="pull"){let h=g[1];if(!h){d({kind:"note",tone:"error",text:"Usage: /sync pull <article-path> | --all"});return}let w;if(h==="--all"){if(d({kind:"note",tone:"info",text:"Checking Document360 for drift\u2026"}),w=(await yo({cwd:e,profileName:i})).entries.filter(W=>W.status==="remote-ahead"&&W.path).map(W=>W.path),w.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 w=[h.replace(/\\/g,"/")];let j=[];for(let L of w)j.push(await fl({cwd:e,profileName:i,relPath:L}));fe.current=j,ct();return}d({kind:"note",tone:"error",text:`Unknown subcommand: /sync ${m} \u2014 use /sync or /sync pull <path>|--all.`})}catch(h){d({kind:"note",tone:"error",text:`Sync failed: ${h.message}`})}return}case"scope":{if(!je(e)){d({kind:"note",tone:"error",text:"No .d360-writer.json here. Run /init first."});return}let m=gl(e);if(m.length===0){d({kind:"note",tone:"info",text:'No candidate source folders found. Set "authoritativeSourceFiles" in .d360-writer.json manually.'});return}Le({cursor:0,rows:m.map(h=>({...h,checked:h.recommended}))});return}case"audit":case"screenshot":{if(l==="screenshot"&&!g[0]){d({kind:"note",tone:"error",text:"Usage: /screenshot <id>"});return}let h=await(l==="audit"?vt:Rt)(g,void 0);h.kind==="forward-to-agent"&&h.prompt&&await Se(h.prompt,{display:h.display,echoDisplay:!0});return}default:d({kind:"note",tone:"error",text:`Unknown command: /${l} \u2014 type /help.`})}},[e,r,i,ct,d,de,Se]),ut=F(a=>{let s=(a??R).trim();if($(""),tt(null),Ie(0),s.startsWith("/")){let g=h=>h.trim().split(/\s+/).slice(1).join(" "),m=g(s);X(h=>h.filter(w=>w.trim()!==s&&!(m&&g(w)===m)))}if(!s||No(s))return;Ht.current.push(s);let l=nr(s,To.current);s.startsWith("/")?Oo(l):Se(l,{display:s})},[R,No,Oo,Se]),Uo=F(a=>{if(a.length>1){if(a.includes("\x1B"))return;let s=er(a);if(tr(s)){let l=or(++Ir.current,s);To.current.set(l,s),S(l)}else S(s);return}S(a)},[S]),Ne=Math.max(10,Te-6),Wo=Nt(()=>Mt(f.text,Ne),[f.text,Ne]),Xt=F(a=>b(s=>({...s,pos:Math.max(0,Math.min(s.text.length,s.pos+a))})),[]),dt=F(a=>b(s=>({...s,pos:sr(Mt(s.text,Ne),s.pos,a)})),[Ne]),qe=F(a=>b(s=>({...s,pos:ir(Mt(s.text,Ne),s.pos,a)})),[Ne]),_r=["\x1B[H","\x1B[1~","\x1BOH"],Mr=["\x1B[F","\x1B[4~","\x1BOF"],Bo=F((a,s)=>s.leftArrow?(Xt(-1),!0):s.rightArrow?(Xt(1),!0):a&&_r.includes(a)?(qe("start"),!0):a&&Mr.includes(a)?(qe("end"),!0):s.ctrl&&a==="a"?(qe("start"),!0):s.ctrl&&a==="e"?(qe("end"),!0):!1,[Xt,qe]);return Xi((a,s)=>{if(s.ctrl&&a==="c"){Q.current?.close(),r();return}if(!U){if(I){if(s.escape){nt.current||(nt.current=!0,d({kind:"note",tone:"warn",text:"\u238B Interrupting\u2026"}),Q.current?.interrupt());return}if(s.return){let l=R.trim();if(!l)return;Ce.current.push(l),Ft([...Ce.current]),$("");return}if(Bo(a,s))return;if(s.upArrow){dt(-1);return}if(s.downArrow){dt(1);return}if(s.backspace||s.delete){_();return}a&&!s.ctrl&&!s.meta&&Uo(a);return}if($e){if(s.upArrow){be(l=>l&&{...l,cursor:Math.max(0,l.cursor-1)});return}if(s.downArrow){be(l=>l&&{...l,cursor:Math.min(le.length-1,l.cursor+1)});return}if(a&&/^[1-9]$/.test(a)&&Number(a)<=le.length){be(l=>l&&{...l,cursor:Number(a)-1});return}if(s.return){let l=le[$e.cursor];be(null);let{lines:g,changed:m,effective:h}=Je(e,l.value??"default");for(let w of g)d({kind:"note",tone:w.startsWith("\u26A0")?"warn":w.startsWith("\u2713")?"ok":"info",text:w});m&&(Ao(w=>w+1),Q.current?.setModel(h));return}if(a==="s"){let l=le[$e.cursor];be(null),Q.current?.setModel(l.value??void 0),d({kind:"note",tone:"ok",text:`\u2713 Using ${l.label} for this session only (your saved default is unchanged).`});return}if(s.escape){be(null);return}return}if(ce){if(s.upArrow){De(l=>l&&{...l,cursor:Math.max(0,l.cursor-1)});return}if(s.downArrow){De(l=>l&&{...l,cursor:Math.min(l.rows.length-1,l.cursor+1)});return}if(a&&/^[1-9]$/.test(a)&&Number(a)<=ce.rows.length){De(l=>l&&{...l,cursor:Number(a)-1});return}if(s.return||a==="s"){let l=ce.rows[ce.cursor];De(null),Vt(l.name,s.return===!0);return}if(s.escape){De(null);return}return}if(se){if(s.upArrow){_e(l=>l&&{...l,cursor:Math.max(0,l.cursor-1)});return}if(s.downArrow){_e(l=>l&&{...l,cursor:Math.min(l.rows.length-1,l.cursor+1)});return}if(a&&/^[1-9]$/.test(a)&&Number(a)<=se.rows.length){_e(l=>l&&{...l,cursor:Number(a)-1});return}if(s.return){let l=se.rows[se.cursor],{profile:g,projectId:m}=se;_e(null),Lo(g,m,l);return}if(s.escape){_e(null);return}return}if(Y){if(s.upArrow){Le(l=>l&&{...l,cursor:Math.max(0,l.cursor-1)});return}if(s.downArrow){Le(l=>l&&{...l,cursor:Math.min(l.rows.length-1,l.cursor+1)});return}if(a===" "){Le(l=>l&&{...l,rows:l.rows.map((g,m)=>m===l.cursor?{...g,checked:!g.checked}:g)});return}if(s.return){let l=Y.rows.filter(g=>g.checked).map(g=>g.path);if(Le(null),l.length===0){d({kind:"note",tone:"info",text:"Nothing selected \u2014 scope unchanged."});return}to(e,l),d({kind:"note",tone:"ok",text:`\u2713 Scoped to ${l.length} folder(s) \u2014 written to .d360-writer.json`});for(let g of l)d({kind:"note",tone:"info",text:` ${g}`});d({kind:"note",tone:"info",text:"Next: ask me to analyze these folders and propose a docs structure."});return}if(s.escape){Le(null);return}return}if(ue){if(s.upArrow){Me(l=>l&&{...l,cursor:Math.max(0,l.cursor-1)});return}if(s.downArrow){Me(l=>l&&{...l,cursor:Math.min(l.rows.length-1,l.cursor+1)});return}if(a&&/^[1-9]$/.test(a)&&Number(a)<=ue.rows.length){Me(l=>l&&{...l,cursor:Number(a)-1});return}if(s.return){let l=ue.rows[ue.cursor],g=ue.rows.filter(m=>m.path!=="--all").map(m=>m.path);Me(null),Se(l.path==="--all"?Ye(g):bt(l.path),{display:l.path==="--all"?"/publish --all":`/publish ${l.path}`,echoDisplay:!0});return}if(s.escape){Me(null);return}return}if(Z){if(s.escape){ve(null);return}if(s.upArrow){ve(l=>l&&{...l,cursor:Math.max(0,l.cursor-1)});return}if(s.downArrow){ve(l=>l&&{...l,cursor:Math.min(Math.max(0,lt.length-1),l.cursor+1)});return}if(s.return){let l=lt[Z.cursor];if(l){ve(null);try{d({kind:"preview",name:kr(l),text:vr(hr(Ut(e,l),"utf8"))})}catch(g){d({kind:"note",tone:"error",text:`Could not read ${l}: ${g.message}`})}}return}if(s.backspace||s.delete){ve(l=>l&&{...l,query:l.query.slice(0,-1),cursor:0});return}if(a&&!s.ctrl&&!s.meta&&a.length===1){ve(l=>l&&{...l,query:l.query+a,cursor:0});return}return}if(ee){if(s.escape){Pe(null);return}if(s.upArrow){Pe(l=>l&&{...l,cursor:Math.max(0,l.cursor-1)});return}if(s.downArrow){Pe(l=>l&&{...l,cursor:Math.min(Math.max(0,at.length-1),l.cursor+1)});return}if(s.return){let l=at[ee.cursor];l&&(Pe(null),de(l.uuid),xe.current={uuid:l.uuid,firstPrompt:l.firstPrompt,titleFired:!0},wo(l.uuid),d({kind:"note",tone:"ok",text:`Resumed "${l.name}".`}));return}if(s.backspace||s.delete){Pe(l=>l&&{...l,query:l.query.slice(0,-1),cursor:0});return}if(a&&!s.ctrl&&!s.meta&&a.length===1){Pe(l=>l&&{...l,query:l.query+a,cursor:0});return}return}if(s.tab&&!R&&ne){$(ne),re(null),et.current++;return}if(!R&&Be.length>0&&a&&/^[1-9]$/.test(a)){let l=Be[Number(a)-1];if(l){$(l);return}}if(!Bo(a,s)){if(_o){if(s.upArrow){Ie(l=>Math.max(0,l-1));return}if(s.downArrow){Ie(l=>Math.min(Fe.length-1,l+1));return}if(s.tab){$("/"+(Fe[He]?.name??"")+" "),Ie(0);return}if(s.return){let l=Fe[He];if(l){let g=R.trim().slice(1).split(/\s+/).slice(1).join(" ");if(Qn(l.usage)&&!g){$("/"+l.name+" "),Ie(0);return}ut("/"+l.name+(g?" "+g:""));return}}}else{if(s.upArrow){if(R!==""&&Ee===null){dt(-1);return}let l=Ht.current;if(!l.length)return;let g=Ee===null?l.length-1:Math.max(0,Ee-1);tt(g),$(l[g]??"");return}if(s.downArrow){if(R!==""&&Ee===null){dt(1);return}let l=Ht.current;if(Ee===null)return;let g=Ee+1;g>=l.length?(tt(null),$("")):(tt(g),$(l[g]??""));return}}if(s.return){ut();return}if(s.backspace||s.delete){_();return}if(s.escape){$(""),Ie(0),re(null),X([]);return}a&&!s.ctrl&&!s.meta&&Uo(a)}}}),Ze(()=>{if(I||U)return;let a=Ce.current.shift();a!==void 0&&(Ft([...Ce.current]),ut(a))},[I,U,ut]),N(V,{flexDirection:"column",width:Te,children:[zt!==null&&N(V,{marginTop:1,flexDirection:"column",children:[zt.truncated&&C(v,{dimColor:!0,children:"\u2026"}),C(v,{children:zt.text})]}),I&&C(vl,{startTime:Wt.current,chars:Ar}),C(V,{borderStyle:"round",borderColor:Eo.prod?"yellow":B,borderTop:!0,borderBottom:!0,borderLeft:!1,borderRight:!1,marginTop:1,flexDirection:"column",children:R?Wo.map((a,s)=>{let l=f.text.slice(a.start,a.end),g=s===Lt(Wo,f.pos),m=Math.min(f.pos,a.end)-a.start;return N(v,{children:[C(v,{color:B,children:s===0?"> ":" "}),g?N(xo,{children:[l.slice(0,m),C(Ot,{ch:l[m]??" "}),l.slice(m+1)]}):l||" "]},`${s}-${a.start}`)}):N(v,{children:[C(v,{color:B,children:"> "}),ne&&!I?N(xo,{children:[C(Ot,{ch:ne[0],dim:!0}),C(v,{color:"gray",children:ne.slice(1)}),C(v,{dimColor:!0,children:" (tab)"})]}):jr?C(Ot,{ch:" "}):N(xo,{children:[C(Ot,{ch:Do[0],dim:!0}),C(v,{color:"gray",children:Do.slice(1)})]})]})}),Ro.length>0&&C(V,{flexDirection:"column",paddingX:1,children:Ro.map((a,s)=>C(v,{color:"gray",children:`\u29D7 queued: ${a}`},`${s}-${a.slice(0,24)}`))}),$e?N(V,{flexDirection:"column",paddingX:1,children:[C(v,{color:B,bold:!0,children:"Select model"}),C(v,{color:"gray",children:"Your pick becomes your personal default for new sessions (team .d360-writer.json still wins)."}),le.map((a,s)=>N(v,{color:s===$e.cursor?B:void 0,children:[s===$e.cursor?"\u276F ":" ",`${s+1}. ${a.label}${s===$e.current?" \u2714":""}`.padEnd(16),C(v,{color:"gray",children:a.desc})]},a.label)),C(v,{dimColor:!0,children:"enter set as default \xB7 s this session only \xB7 esc cancel"})]}):ce?N(V,{flexDirection:"column",paddingX:1,children:[C(v,{color:B,bold:!0,children:"Switch connection profile"}),ce.rows.map((a,s)=>N(v,{color:s===ce.cursor?B:void 0,children:[s===ce.cursor?"\u276F ":" ",`${s+1}. ${a.name}${s===ce.current?" \u2714":""}`.padEnd(20),C(v,{color:"gray",children:`${a.env} \xB7 ${a.who??"not signed in"}`}),a.prod?C(v,{color:"yellow",bold:!0,children:" \u26A0 PRODUCTION"}):null]},a.name)),C(v,{dimColor:!0,children:"enter switch (saved as default) \xB7 s this session only \xB7 esc cancel"})]}):se?N(V,{flexDirection:"column",paddingX:1,children:[C(v,{color:B,bold:!0,children:"Switch workspace"}),se.rows.map((a,s)=>N(v,{color:s===se.cursor?B:void 0,children:[s===se.cursor?"\u276F ":" ",`${s+1}. ${a.name}${s===se.current?" \u2714":""}`.padEnd(30),C(v,{color:"gray",children:a.type??""})]},a.id)),C(v,{dimColor:!0,children:"enter switch \xB7 esc cancel"})]}):Y?(()=>{let s=Math.min(Math.max(0,Y.cursor-Math.floor(7)),Math.max(0,Y.rows.length-14)),l=Y.rows.slice(s,s+14),g=Y.rows.filter(m=>m.checked).length;return N(V,{flexDirection:"column",paddingX:1,children:[C(v,{color:B,bold:!0,children:`Which folders back the user docs? (${g} selected of ${Y.rows.length})`}),s>0?C(v,{dimColor:!0,children:` \u2191 ${s} more`}):null,l.map((m,h)=>{let w=s+h;return N(v,{color:w===Y.cursor?B:void 0,children:[w===Y.cursor?"\u276F ":" ",m.checked?"\u25C9 ":"\u25CB ",m.path.padEnd(Math.min(48,Te-34)),C(v,{color:"gray",children:Ct(m)})]},m.path)}),s+14<Y.rows.length?C(v,{dimColor:!0,children:` \u2193 ${Y.rows.length-s-14} more`}):null,C(v,{dimColor:!0,children:"space toggle \xB7 enter save \xB7 esc cancel"})]})})():ue?N(V,{flexDirection:"column",paddingX:1,children:[C(v,{color:B,bold:!0,children:"Publish which article?"}),ue.rows.map((a,s)=>N(v,{color:s===ue.cursor?B:void 0,children:[s===ue.cursor?"\u276F ":" ",`${s+1}. ${a.path}`.padEnd(Math.min(56,Te-30)),C(v,{color:"gray",children:a.label})]},a.path)),C(v,{dimColor:!0,children:"enter publish (draft) \xB7 esc cancel"})]}):Z?N(V,{flexDirection:"column",paddingX:1,children:[C(v,{color:B,bold:!0,children:`Preview article${Z.query?` \u2014 filter: ${Z.query}`:" (type to filter)"}`}),lt.length===0?C(v,{color:"gray",children:"no articles match"}):lt.map((a,s)=>N(v,{color:s===Z.cursor?B:void 0,children:[s===Z.cursor?"\u276F ":" ",a]},a)),C(v,{dimColor:!0,children:"enter preview \xB7 esc cancel"})]}):ee?N(V,{flexDirection:"column",paddingX:1,children:[C(v,{color:B,bold:!0,children:`Resume session${ee.query?` \u2014 filter: ${ee.query}`:" (type to filter)"}`}),at.length===0?C(v,{color:"gray",children:"no sessions match"}):at.map((a,s)=>N(v,{color:s===ee.cursor?B:void 0,children:[s===ee.cursor?"\u276F ":" ",a.name.slice(0,28).padEnd(30),C(v,{color:s===ee.cursor?B:"gray",children:a.firstPrompt.slice(0,Math.max(10,Te-40))})]},a.uuid)),C(v,{dimColor:!0,children:"enter resume \xB7 esc cancel"})]}):_o?C(V,{flexDirection:"column",children:Fe.map((a,s)=>N(v,{color:s===He?B:void 0,children:[s===He?"\u276F ":" ",a.usage.padEnd(22)," ",C(v,{color:s===He?B:"gray",children:a.name==="model"&&qt?`${a.desc} (currently ${qt})`:a.desc})]},a.name))}):!R&&Be.length>0?N(V,{flexDirection:"column",paddingX:1,children:[Be.map((a,s)=>N(v,{children:[C(v,{color:B,children:s+1})," ",a.slice(0,Math.max(20,Te-5))]},a)),C(v,{dimColor:!0,children:`press 1-${Be.length} to fill the command \xB7 esc dismiss`})]}):C(V,{paddingX:1,children:N(v,{color:"gray",children:[Eo.prod?"\u26A0 PRODUCTION \xB7 ":"",`/help \xB7 ${qt??"model n/a"}${it>0?` \xB7 ${it<1e3?`${it} tokens`:`${(it/1e3).toFixed(1)}k tokens`}`:""} \xB7 \u2191 history \xB7 ctrl+c exit`]})})]})}M();import{jsx as Tl}from"react/jsx-runtime";async function Tr(e=process.cwd(),t="auto",o,n="0.0.0"){let r=Pl(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 ${y("https://console.anthropic.com/settings/keys")}`),console.error(`Or use your Claude subscription instead: ${y("d360-writer --auth subscription")}`),process.exit(2));let{waitUntilExit:i}=Cl(Tl(Pr,{cwd:e,auth:r,profileName:o,version:n}));await i(),process.stdout.write(`
64
- `),process.exit(0)}var Al=Rl(import.meta.url),Sr=Al("../package.json"),pe=new Sl;function bo(e){e.env&&(console.error("\u2717 --env was replaced by --profile (connection profiles). Use: --profile <name>"),process.exit(2))}pe.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 ht({profile:e.profile,manual:e.manual})});pe.command("logout").description("Remove the stored Document360 session").option("--profile <name>","Connection profile").option("--env <name>",!1).action(async e=>{bo(e),await Zo({profile:e.profile})});pe.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 Qo({profile:e.profile})});var vo=pe.command("profile").description("Manage connection profiles for the current repo");vo.command("list",{isDefault:!0}).description("List profiles (\u25CF = default)").action(()=>kt(process.cwd()));vo.command("use <name>").description("Set the default profile for this repo").action(e=>wt(process.cwd(),e));vo.command("show [name]").description("Print the resolved profile (connection + project)").action(e=>yt(process.cwd(),e));var Rr=pe.command("workspace").description("Choose the Document360 workspace for this repo (active profile's project)");Rr.command("select",{isDefault:!0}).description("Interactively pick the workspace (lists in non-TTY)").option("--profile <name>","Connection profile").action(e=>Oe(process.cwd(),e.profile));Rr.command("use <name>").description("Set the workspace by name (scriptable)").option("--profile <name>","Connection profile").action(async(e,t)=>{process.exitCode=await Vo(process.cwd(),e,t.profile)});pe.command("logs").description("Show the Document360 API log files (send these to support when reporting a problem)").action(()=>tn());pe.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(()=>(St(),Nn)),o=await t(process.cwd());for(let n of e(o))console.log(n);process.exitCode=o.some(n=>n.level==="fail")?1:0});pe.name("d360-writer").description("Standalone documentation agent CLI. Reads your code, writes your docs.").version(Sr.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(jl.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 on(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 Jn(e.cwd,e.auth,e.profile):await Tr(e.cwd,e.auth,e.profile,Sr.version)});pe.parseAsync(process.argv).catch(e=>{console.error(""),console.error(`\u2717 ${e.message}`),process.exit(1)});
61
+ Press 1 to start.`}),V(["/init"]);return}try{let a=ae(e,l),i=Ie(a.name);i&&$e(i)&&i.refreshToken?rl({profile:a.name,connection:a.connection}).then(()=>{d({kind:"note",tone:"ok",text:"\u2713 Document360 session refreshed."}),me(s=>s+1)}).catch(()=>{d({kind:"note",tone:"warn",text:"Document360 session refresh failed \u2014 do you want to log in now? (press 1)"}),V(["/login"])}):(!i||$e(i))&&(d({kind:"note",tone:"warn",text:`Profile "${a.name}" is not signed in \u2014 do you want to log in now? (press 1)`}),V(["/login"]))}catch{}try{let a=xe(e),i=ae(e,l),s=Ie(i.name);a&&s&&!$e(s)&&Tl(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."}),V(["/scope"]))}catch{}},[]),tt(()=>{let a=null,i=null,s=()=>{a&&clearTimeout(a),a=setTimeout(()=>{a=null;let h=`${ie.columns??80}x${ie.rows??24}`;h!==Dn.current&&(Dn.current=h,_r(m=>m+1),i&&clearTimeout(i),i=setTimeout(()=>{i=null,console.log("\x1B[?2026h\x1B[H\x1B[2J"+gr(Ft.current,he())+"\x1B[?2026l")},80))},400)};return ie.on("resize",s),()=>{a&&clearTimeout(a),i&&clearTimeout(i),ie.off("resize",s)}},[ie,he]);let Re=Math.max(20,(ie.columns??80)-1),Mn=Ut(()=>bl(e,l),[e,l,oe]),_n=Ut(()=>{if(!xe(e))return"Press 1 to set up this repo, or /help\u2026";try{let a=ae(e,l),i=Ie(a.name);if(!(!!i&&!($e(i)&&!i.refreshToken)))return`Press 1 to sign in to Document360 (profile "${a.name}")\u2026`;if(!a.project.workspaceId)return"Press 1 to pick a workspace\u2026"}catch{}return vl},[e,l,oe]),ze=Zo(R),Ln=ze.length>0&&!I,Xt=p!==null?hr(p,8,Re):null,ct=ee?ee.paths.filter(a=>!ee.query||a.toLowerCase().includes(ee.query.toLowerCase())).slice(0,8):[],ut=te?te.sessions.filter(a=>{let i=te.query.toLowerCase();return!i||a.name.toLowerCase().includes(i)||a.firstPrompt.toLowerCase().includes(i)}).slice(0,8):[],de=F((a,i)=>{Z.current?.close(),Z.current=xr({cwd:e,resume:a,profileName:i??l,allowProdWrites:jn.current}),a||(be.current={uuid:null,firstPrompt:null,titleFired:!1}),In(0)},[e,l]),Nn=F((a,i,s)=>{if(Cl.test(a))try{let h=ae(e,l),m=typeof i.project_id=="string"&&i.project_id||h.project.projectId,g=Mt(i,s),y=[],j=_t(s);a.endsWith("publish_article")&&j&&y.push(`Live: ${j}`),g&&m&&y.push(`Preview: ${Dt(h.connection.portalUrl,m,g,h.project.languageCode??"en")}`),y.length>0&&d({kind:"link",lines:y})}catch{}},[e,l,d]),je=F(async(a,i)=>{Tn(!0),se(null),V([]);let s=++nt.current;d({kind:"user",text:i?.echoDisplay&&i.display?i.display:a});let h=be.current;h.firstPrompt||(h.firstPrompt=i?.display??a),Ht.current=Date.now(),Sn(0),H(!0),rt.current.clear();let m="",g="",y=null,j=()=>{y||(y=setTimeout(()=>{y=null,k(g.length>0?g:null)},60))},N=()=>{y&&clearTimeout(y),y=null,k(null)},B=()=>{if(g.trim()){let P=g.trimEnd();d({kind:"assistant",text:P})}g="",N()};try{for await(let P of Z.current.send(a))if(P.type==="session"){if(!h.uuid){h.uuid=P.sessionId;let A=new Date().toISOString();cl({uuid:P.sessionId,name:al(h.firstPrompt??"session"),renamed:!1,titled:!1,cwd:e,firstPrompt:h.firstPrompt??"",createdAt:A,updatedAt:A})}}else if(P.type==="text"){g+=P.delta,m+=P.delta;let A=kr(g);if(A>0){let q=g.slice(0,A).trimEnd();q&&d({kind:"assistant",text:q}),g=g.slice(A)}j(),Sn(q=>q+P.delta.length)}else if(P.type==="tool"){let A=It(P.name,P.input);A&&(B(),d({kind:"tool",title:A.title,sep:A.sep,arg:A.arg}),rt.current.set(P.id,{name:P.name,input:P.input}))}else if(P.type==="article_diff"){let A=Ae(P.oldContent,P.newContent,he());A&&(B(),d({kind:"diff",added:A.added,removed:A.removed,lines:A.lines,hidden:A.hidden}))}else if(P.type==="tool_result"){P.isError&&/run \/login|not logged in|session expired|rejected the token/i.test(P.output)&&(it.current=!0);let A=rt.current.get(P.id);if(A){rt.current.delete(P.id),B();let q=Et(P.output,4,P.isError?void 0:A.name,A.input);d({kind:"tool-result",lines:q.lines,hidden:q.hidden,isError:P.isError}),P.isError||Nn(A.name,A.input,P.output)}}else if(P.type==="result"){B(),In(q=>q+P.outputTokens),d({kind:"done",seconds:Math.round((Date.now()-Ht.current)/1e3),tokens:P.outputTokens,ok:P.ok});let A=P.ok?tr(m,Lt.map(q=>q.name)):[];if(A.length>0?V(A):P.ok&&m.trim()&&ml(a,m,e).then(q=>{q&&nt.current===s&&se(q)}).catch(()=>{}),h.uuid&&(xn(h.uuid),!h.titleFired)){h.titleFired=!0;let q=h.uuid,qn=h.firstPrompt;qn&&$r(qn,e).then(zn=>zn&&ll(q,zn)).catch(()=>{})}}else P.type==="error"&&(B(),P.kind==="auth"&&(it.current=!0),d({kind:"note",text:`agent error: ${P.message}`,tone:"error"}))}finally{H(!1),N(),it.current&&(it.current=!1,lt.current=i?.display??a,V(["/login"])),st.current&&(st.current=!1,Te.current.length>0&&(d({kind:"note",tone:"info",text:`(${Te.current.length} queued message(s) discarded)`}),Te.current=[],zt([])),d({kind:"note",tone:"warn",text:"Interrupted. What do you want to do next?"}))}},[e,d,Nn,he]),Vt=F(a=>{let i=Ie(a);if(!i||$e(i)&&!i.refreshToken)return null;let s={...He(i.idToken)??{},...He(i.accessToken)??{}};return s.email??s.preferred_username??"signed in"},[]),Yt=F((a,i)=>{if(i){let s=xe(e);s&&(s.defaultProfile=a,fl(s,e))}u(a),de(void 0,a),d({kind:"note",tone:"ok",text:`\u2713 Switched to profile "${a}"${i?" (saved as default)":" (this session only)"} \u2014 agent restarted.`}),Vt(a)||(d({kind:"note",tone:"warn",text:`Profile "${a}" is not signed in \u2014 do you want to log in now? (press 1)`}),V(["/login"])),me(s=>s+1)},[e,d,de,Vt]),On=F((a,i,s)=>{gt(e,a,i,s.id),d({kind:"note",tone:"ok",text:`Switched to workspace "${s.name??s.id}" (agent restarted).`}),de(),br(e,a)||(d({kind:"note",tone:"info",text:"Setup complete. Press tab to start with a docs analysis."}),se("analyze this repo and propose a docs structure"))},[e,d,de]),dt=F(()=>{let a=fe.current[0];if(!a)return;d({kind:"note",tone:"info",text:`\u25CF ${a.title} (${a.path})`});for(let s of a.notes)d({kind:"note",tone:"warn",text:`\u26A0 ${s}`});a.overwritesLocalChanges&&d({kind:"note",tone:"warn",text:"\u26A0 This OVERWRITES local edits made since the last sync."});let i=Ae(a.oldContent,a.newContent,he());d(i?{kind:"diff",added:i.added,removed:i.removed,lines:i.lines,hidden:i.hidden}:{kind:"note",tone:"info",text:"Local file already matches the remote content \u2014 applying only advances the sync base."}),d({kind:"note",tone:"info",text:`Write ${a.path}? (y/n \u2014 anything else cancels)`})},[d,he]),Un=F(a=>{if(fe.current.length===0)return!1;let i=a.trim().toLowerCase();if(i==="y"||i==="yes"){let s=fe.current.shift();try{gl({cwd:e,profileName:l},s),d({kind:"note",tone:"ok",text:`\u2713 Pulled ${s.path} (sync base advanced).`}),fe.current.length===0&&V(h=>h.length>0?h:["/sync"])}catch(h){d({kind:"note",tone:"error",text:`Pull failed: ${h.message}`})}}else if(i==="n"||i==="no"){let s=fe.current.shift();d({kind:"note",tone:"info",text:`Skipped ${s.path}.`})}else{let s=fe.current.length;return fe.current=[],d({kind:"note",tone:"info",text:`Pull cancelled (${s} article(s) left untouched).`}),!0}return dt(),!0},[e,l,dt,d]),Wn=F(async a=>{let i=a.slice(1).trim().split(/\s+/),s=(i[0]??"").toLowerCase(),h=i.slice(1);switch(s){case"help":d({kind:"note",tone:"info",text:Lt.map(m=>` ${m.usage.padEnd(22)} ${m.desc}`).join(`
62
+ `)});return;case"exit":case"quit":Z.current?.close(),r();return;case"clear":de(),Ft.current=[],Tn(!1),se(null),nt.current++,d({kind:"note",tone:"info",text:"Conversation reset (the previous session is still resumable via /resume)."});return;case"login":{let m;try{m=ae(e,l)}catch(g){d({kind:"note",tone:"error",text:g.message});return}d({kind:"note",tone:"info",text:`Profile "${m.name}" \u2192 ${m.connection.name} (${m.connection.apiUrl})${m.production?" \u26A0 PRODUCTION":""}`}),Q(!0);try{let g=await tl(m.connection,{promptForRedirect:()=>Promise.reject(new Error("Manual login is CLI-only. Run: d360-writer login --manual"))},j=>d({kind:"note",tone:"info",text:j})),y=nl(m.name,g);ol(y),Qt(y,m.name,j=>d({kind:"note",tone:"info",text:j})),d({kind:"note",tone:"ok",text:`\u2713 Logged in to "${m.name}" as ${kt(y)}`}),m.project.workspaceId||(d({kind:"note",tone:"info",text:"Next: pick the workspace your articles publish to."}),V(["/workspace"])),lt.current&&(se(lt.current),lt.current=null,d({kind:"note",tone:"info",text:"Press tab to re-send your last prompt."}))}catch(g){d({kind:"note",tone:"error",text:`Login failed: ${g.message}`})}finally{Q(!1),me(g=>g+1)}return}case"allow-prod":{let m=!1;try{m=ae(e,l).production}catch{}if(!m){d({kind:"note",tone:"info",text:"Current profile is not production \u2014 writes are already allowed."});return}jn.current=!0,de(),d({kind:"note",tone:"warn",text:"\u26A0 Production writes authorized for this session."});return}case"rename":{let m=h.join(" ").trim(),g=be.current.uuid;if(!g){d({kind:"note",tone:"error",text:"Send a message first \u2014 sessions save once the agent replies."});return}if(!m){d({kind:"note",tone:"info",text:"Thinking of a name\u2026"});let y=be.current.firstPrompt??"";$r(y,e).then(j=>{j?(se(`/rename ${j}`),d({kind:"note",tone:"info",text:`Suggestion: "${j}" \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}pl(g,m),d({kind:"note",tone:"ok",text:`Session renamed to "${m}".`});return}case"profile":{let m=h[0],g=xe(e);if(!m){let y=Object.entries(g?.profiles??{});if(y.length===0){d({kind:"note",tone:"info",text:"No profiles. Run /init first."});return}let j=y.map(([P,A])=>({name:P,env:A.connection?.environment??"custom",prod:A.production===!0,who:Vt(P)})),N=l??g?.defaultProfile,B=Math.max(0,j.findIndex(P=>P.name===N));Me({cursor:B,current:B,rows:j});return}if(m==="add"){let y=sn(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]}).`}),Yt(h[1],!1);return}if(!g?.profiles?.[m]){d({kind:"note",tone:"error",text:`Unknown profile "${m}". Create it: /profile add ${m} <environment>`});return}Yt(m,!0);return}case"doctor":await Ze(h,{cwd:e});return;case"mcp":await bt(h);return;case"init":{if(xe(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 m=wl().map(g=>({name:g,apiUrl:yl(g).apiUrl}));_e({cursor:0,rows:m});return}case"resume":{let m=h.join(" ").trim(),g=dl(e).filter(j=>j.uuid!==be.current.uuid);if(!m){if(!g.length){d({kind:"note",tone:"info",text:"No saved sessions for this repo yet."});return}Se({query:"",cursor:0,sessions:g});return}let y=ul(e,m);if(!y){d({kind:"note",tone:"error",text:`No session matches "${m}".`});return}de(y.uuid),be.current={uuid:y.uuid,firstPrompt:y.firstPrompt,titleFired:!0},xn(y.uuid),d({kind:"note",tone:"ok",text:`Resumed "${y.name}".`});return}case"workspace":{let m=h.join(" ").trim(),g;try{g=await ft(e,l)}catch(j){d({kind:"note",tone:"error",text:`Could not list workspaces: ${j.message}`});return}if(!m){let j=g.workspaces.map(B=>({id:B.id,name:B.name??B.id,type:B.workspace_type}));if(j.length===0){d({kind:"note",tone:"info",text:"No workspaces in this project."});return}let N=Math.max(0,j.findIndex(B=>B.id===g.current));Le({cursor:N,current:N,rows:j,profile:g.profile,projectId:g.projectId,environment:g.environment});return}let y=Kt(g.workspaces,m);if(!y){d({kind:"note",tone:"error",text:`No workspace matches "${m}".`});return}On(g.profile,g.projectId,y);return}case"publish":{if(h[0]&&h[0]!=="--all"){await je(Ct(h[0]),{display:`/publish ${h[0]}`,echoDisplay:!0});return}let m=h[0]==="--all";d({kind:"note",tone:"info",text:"Checking what needs publishing\u2026"});try{let g=await $n({cwd:e,profileName:l}),y=vt(g.entries);if(y.length===0){d({kind:"note",tone:"ok",text:"\u2713 Nothing is ahead of Document360 \u2014 no publish candidates."});let N=g.counts["unknown-base"]??0;N>0&&d({kind:"note",tone:"info",text:`(${N} article(s) have no sync base yet \u2014 publish those by path if needed.)`});return}if(m){await je(Ke(y.map(N=>N.path)),{display:"/publish --all",echoDisplay:!0});return}let j=y.length>1?[{path:"--all",label:`publish all ${y.length} candidates in one run`},...y]:y;Ne({cursor:0,rows:j})}catch(g){d({kind:"note",tone:"error",text:`Could not compute sync status: ${g.message}`}),d({kind:"note",tone:"info",text:"Publish a specific article: /publish <article-path>"})}return}case"preview":{let m=h.join(" ").trim();if(!m){let y=[];try{y=Object.keys(br(e,ae(e,l).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}Pe({query:"",cursor:0,paths:y});return}let g=el(m)?m:Bt(e,m);if(Qi(g)){try{d({kind:"preview",name:yr(g),text:Pr(wr(g,"utf8"))})}catch(y){d({kind:"note",tone:"error",text:`Could not read ${g}: ${y.message}`})}return}if(Pl.test(m)){try{let y=ae(e,l),j={profile:y.name,connection:y.connection},N=y.project.projectId??sl(j),B=await il(j,N,m);d({kind:"preview",name:B.title??m,text:B.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:`"${m}" is neither a file (relative to ${e}) nor an article id.`});return}case"model":{let m=h[0]?.trim();if(!m){let N=Rt(vn(e));Ce({cursor:N,current:N});return}let{lines:g,changed:y,effective:j}=Qe(e,m);for(let N of g)d({kind:"note",tone:N.startsWith("\u26A0")?"warn":N.startsWith("\u2713")?"ok":"info",text:N});y&&(En(N=>N+1),Z.current?.setModel(j));return}case"sync":{let m=(h[0]??"status").toLowerCase();try{if(m==="status"){d({kind:"note",tone:"info",text:"Checking Document360 for drift\u2026"});let g=await $n({cwd:e,profileName:l});d({kind:"note",tone:"info",text:St(g).join(`
63
+ `)});return}if(m==="pull"){let g=h[1];if(!g){d({kind:"note",tone:"error",text:"Usage: /sync pull <article-path> | --all"});return}let y;if(g==="--all"){if(d({kind:"note",tone:"info",text:"Checking Document360 for drift\u2026"}),y=(await $n({cwd:e,profileName:l})).entries.filter(B=>B.status==="remote-ahead"&&B.path).map(B=>B.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=[g.replace(/\\/g,"/")];let j=[];for(let N of y)j.push(await hl({cwd:e,profileName:l,relPath:N}));fe.current=j,dt();return}d({kind:"note",tone:"error",text:`Unknown subcommand: /sync ${m} \u2014 use /sync or /sync pull <path>|--all.`})}catch(g){d({kind:"note",tone:"error",text:`Sync failed: ${g.message}`})}return}case"scope":{if(!xe(e)){d({kind:"note",tone:"error",text:"No .d360-writer.json here. Run /init first."});return}let m=kl(e);if(m.length===0){d({kind:"note",tone:"info",text:'No candidate source folders found. Set "authoritativeSourceFiles" in .d360-writer.json manually.'});return}Oe({cursor:0,rows:m.map(g=>({...g,checked:g.recommended}))});return}case"audit":case"screenshot":{if(s==="screenshot"&&!h[0]){d({kind:"note",tone:"error",text:"Usage: /screenshot <id>"});return}let g=await(s==="audit"?Pt:At)(h,void 0);g.kind==="forward-to-agent"&&g.prompt&&await je(g.prompt,{display:g.display,echoDisplay:!0});return}default:d({kind:"note",tone:"error",text:`Unknown command: /${s} \u2014 type /help.`})}},[e,r,l,dt,d,de,je]),pt=F(a=>{let i=(a??R).trim();if(b(""),ot(null),Ee(0),i.startsWith("/")){let h=g=>g.trim().split(/\s+/).slice(1).join(" "),m=h(i);V(g=>g.filter(y=>y.trim()!==i&&!(m&&h(y)===m)))}if(!i||Un(i))return;qt.current.push(i);let s=sr(i,Rn.current);i.startsWith("/")?Wn(s):je(s,{display:i})},[R,Un,Wn,je]),Bn=F(a=>{if(a.length>1){if(a.includes("\x1B"))return;let i=nr(a);if(or(i)){let s=rr(++Dr.current,i);Rn.current.set(s,i),S(s)}else S(i);return}S(a)},[S]),Ue=Math.max(10,Re-6),Hn=Ut(()=>Nt(f.text,Ue),[f.text,Ue]),Jt=F(a=>v(i=>({...i,pos:Math.max(0,Math.min(i.text.length,i.pos+a))})),[]),mt=F(a=>v(i=>({...i,pos:lr(Nt(i.text,Ue),i.pos,a)})),[Ue]),Ge=F(a=>v(i=>({...i,pos:ar(Nt(i.text,Ue),i.pos,a)})),[Ue]),Lr=["\x1B[H","\x1B[1~","\x1BOH"],Nr=["\x1B[F","\x1B[4~","\x1BOF"],Fn=F((a,i)=>i.leftArrow?(Jt(-1),!0):i.rightArrow?(Jt(1),!0):a&&Lr.includes(a)?(Ge("start"),!0):a&&Nr.includes(a)?(Ge("end"),!0):i.ctrl&&a==="a"?(Ge("start"),!0):i.ctrl&&a==="e"?(Ge("end"),!0):!1,[Jt,Ge]);return Ji((a,i)=>{if(i.ctrl&&a==="c"){Z.current?.close(),r();return}if(!W){if(I){if(i.escape){st.current||(st.current=!0,d({kind:"note",tone:"warn",text:"\u238B Interrupting\u2026"}),Z.current?.interrupt());return}if(i.return){let s=R.trim();if(!s)return;Te.current.push(s),zt([...Te.current]),b("");return}if(Fn(a,i))return;if(i.upArrow){mt(-1);return}if(i.downArrow){mt(1);return}if(i.backspace||i.delete){_();return}a&&!i.ctrl&&!i.meta&&Bn(a);return}if(ve){if(i.upArrow){Ce(s=>s&&{...s,cursor:Math.max(0,s.cursor-1)});return}if(i.downArrow){Ce(s=>s&&{...s,cursor:Math.min(le.length-1,s.cursor+1)});return}if(a&&/^[1-9]$/.test(a)&&Number(a)<=le.length){Ce(s=>s&&{...s,cursor:Number(a)-1});return}if(i.return){let s=le[ve.cursor];Ce(null);let{lines:h,changed:m,effective:g}=Qe(e,s.value??"default");for(let y of h)d({kind:"note",tone:y.startsWith("\u26A0")?"warn":y.startsWith("\u2713")?"ok":"info",text:y});m&&(En(y=>y+1),Z.current?.setModel(g));return}if(a==="s"){let s=le[ve.cursor];Ce(null),Z.current?.setModel(s.value??void 0),d({kind:"note",tone:"ok",text:`\u2713 Using ${s.label} for this session only (your saved default is unchanged).`});return}if(i.escape){Ce(null);return}return}if(ce){if(i.upArrow){Me(s=>s&&{...s,cursor:Math.max(0,s.cursor-1)});return}if(i.downArrow){Me(s=>s&&{...s,cursor:Math.min(s.rows.length-1,s.cursor+1)});return}if(a&&/^[1-9]$/.test(a)&&Number(a)<=ce.rows.length){Me(s=>s&&{...s,cursor:Number(a)-1});return}if(i.return||a==="s"){let s=ce.rows[ce.cursor];Me(null),Yt(s.name,i.return===!0);return}if(i.escape){Me(null);return}return}if(ge){if(i.upArrow){_e(s=>s&&{...s,cursor:Math.max(0,s.cursor-1)});return}if(i.downArrow){_e(s=>s&&{...s,cursor:Math.min(s.rows.length-1,s.cursor+1)});return}if(a&&/^[1-9]$/.test(a)&&Number(a)<=ge.rows.length){_e(s=>s&&{...s,cursor:Number(a)-1});return}if(i.return){let s=ge.rows[ge.cursor].name;if(_e(null),!co(e,s).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 "${s}").`});let m=!1;try{let g=Ie(s);m=!!g&&!($e(g)&&!g.refreshToken)}catch{}m?(d({kind:"note",tone:"info",text:`Already signed in to ${s} \u2014 next: pick a workspace.`}),V(["/workspace"])):(d({kind:"note",tone:"info",text:`Next: sign in to Document360 (${s}).`}),V(["/login"])),me(g=>g+1);return}if(i.escape){_e(null);return}return}if(Y){if(i.upArrow){Le(s=>s&&{...s,cursor:Math.max(0,s.cursor-1)});return}if(i.downArrow){Le(s=>s&&{...s,cursor:Math.min(s.rows.length-1,s.cursor+1)});return}if(a&&/^[1-9]$/.test(a)&&Number(a)<=Y.rows.length){Le(s=>s&&{...s,cursor:Number(a)-1});return}if(i.return){let s=Y.rows[Y.cursor],{profile:h,projectId:m}=Y;Le(null),On(h,m,s);return}if(i.escape){Le(null);return}return}if(J){if(i.upArrow){Oe(s=>s&&{...s,cursor:Math.max(0,s.cursor-1)});return}if(i.downArrow){Oe(s=>s&&{...s,cursor:Math.min(s.rows.length-1,s.cursor+1)});return}if(a===" "){Oe(s=>s&&{...s,rows:s.rows.map((h,m)=>m===s.cursor?{...h,checked:!h.checked}:h)});return}if(i.return){let s=J.rows.filter(h=>h.checked).map(h=>h.path);if(Oe(null),s.length===0){d({kind:"note",tone:"info",text:"Nothing selected \u2014 scope unchanged."});return}on(e,s),d({kind:"note",tone:"ok",text:`\u2713 Scoped to ${s.length} folder(s) \u2014 written to .d360-writer.json`});for(let h of s)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(i.escape){Oe(null);return}return}if(ue){if(i.upArrow){Ne(s=>s&&{...s,cursor:Math.max(0,s.cursor-1)});return}if(i.downArrow){Ne(s=>s&&{...s,cursor:Math.min(s.rows.length-1,s.cursor+1)});return}if(a&&/^[1-9]$/.test(a)&&Number(a)<=ue.rows.length){Ne(s=>s&&{...s,cursor:Number(a)-1});return}if(i.return){let s=ue.rows[ue.cursor],h=ue.rows.filter(m=>m.path!=="--all").map(m=>m.path);Ne(null),je(s.path==="--all"?Ke(h):Ct(s.path),{display:s.path==="--all"?"/publish --all":`/publish ${s.path}`,echoDisplay:!0});return}if(i.escape){Ne(null);return}return}if(ee){if(i.escape){Pe(null);return}if(i.upArrow){Pe(s=>s&&{...s,cursor:Math.max(0,s.cursor-1)});return}if(i.downArrow){Pe(s=>s&&{...s,cursor:Math.min(Math.max(0,ct.length-1),s.cursor+1)});return}if(i.return){let s=ct[ee.cursor];if(s){Pe(null);try{d({kind:"preview",name:yr(s),text:Pr(wr(Bt(e,s),"utf8"))})}catch(h){d({kind:"note",tone:"error",text:`Could not read ${s}: ${h.message}`})}}return}if(i.backspace||i.delete){Pe(s=>s&&{...s,query:s.query.slice(0,-1),cursor:0});return}if(a&&!i.ctrl&&!i.meta&&a.length===1){Pe(s=>s&&{...s,query:s.query+a,cursor:0});return}return}if(te){if(i.escape){Se(null);return}if(i.upArrow){Se(s=>s&&{...s,cursor:Math.max(0,s.cursor-1)});return}if(i.downArrow){Se(s=>s&&{...s,cursor:Math.min(Math.max(0,ut.length-1),s.cursor+1)});return}if(i.return){let s=ut[te.cursor];s&&(Se(null),de(s.uuid),be.current={uuid:s.uuid,firstPrompt:s.firstPrompt,titleFired:!0},xn(s.uuid),d({kind:"note",tone:"ok",text:`Resumed "${s.name}".`}));return}if(i.backspace||i.delete){Se(s=>s&&{...s,query:s.query.slice(0,-1),cursor:0});return}if(a&&!i.ctrl&&!i.meta&&a.length===1){Se(s=>s&&{...s,query:s.query+a,cursor:0});return}return}if(i.tab&&!R&&re){b(re),se(null),nt.current++;return}if(!R&&Fe.length>0&&a&&/^[1-9]$/.test(a)){let s=Fe[Number(a)-1];if(s){b(s);return}}if(!Fn(a,i)){if(Ln){if(i.upArrow){Ee(s=>Math.max(0,s-1));return}if(i.downArrow){Ee(s=>Math.min(ze.length-1,s+1));return}if(i.tab){b("/"+(ze[qe]?.name??"")+" "),Ee(0);return}if(i.return){let s=ze[qe];if(s){let h=R.trim().slice(1).split(/\s+/).slice(1).join(" ");if(er(s.usage)&&!h){b("/"+s.name+" "),Ee(0);return}pt("/"+s.name+(h?" "+h:""));return}}}else{if(i.upArrow){if(R!==""&&De===null){mt(-1);return}let s=qt.current;if(!s.length)return;let h=De===null?s.length-1:Math.max(0,De-1);ot(h),b(s[h]??"");return}if(i.downArrow){if(R!==""&&De===null){mt(1);return}let s=qt.current;if(De===null)return;let h=De+1;h>=s.length?(ot(null),b("")):(ot(h),b(s[h]??""));return}}if(i.return){pt();return}if(i.backspace||i.delete){_();return}if(i.escape){b(""),Ee(0),se(null),V([]);return}a&&!i.ctrl&&!i.meta&&Bn(a)}}}),tt(()=>{if(I||W)return;let a=Te.current.shift();a!==void 0&&(zt([...Te.current]),pt(a))},[I,W,pt]),M(X,{flexDirection:"column",width:Re,children:[Xt!==null&&M(X,{marginTop:1,flexDirection:"column",children:[Xt.truncated&&C($,{dimColor:!0,children:"\u2026"}),C($,{children:Xt.text})]}),I&&C(Sl,{startTime:Ht.current,chars:Er}),C(X,{borderStyle:"round",borderColor:Mn.prod?"yellow":U,borderTop:!0,borderBottom:!0,borderLeft:!1,borderRight:!1,marginTop:1,flexDirection:"column",children:R?Hn.map((a,i)=>{let s=f.text.slice(a.start,a.end),h=i===Ot(Hn,f.pos),m=Math.min(f.pos,a.end)-a.start;return M($,{children:[C($,{color:U,children:i===0?"> ":" "}),h?M(bn,{children:[s.slice(0,m),C(Wt,{ch:s[m]??" "}),s.slice(m+1)]}):s||" "]},`${i}-${a.start}`)}):M($,{children:[C($,{color:U,children:"> "}),re&&!I?M(bn,{children:[C(Wt,{ch:re[0],dim:!0}),C($,{color:"gray",children:re.slice(1)}),C($,{dimColor:!0,children:" (tab)"})]}):Ir?C(Wt,{ch:" "}):M(bn,{children:[C(Wt,{ch:_n[0],dim:!0}),C($,{color:"gray",children:_n.slice(1)})]})]})}),An.length>0&&C(X,{flexDirection:"column",paddingX:1,children:An.map((a,i)=>C($,{color:"gray",children:`\u29D7 queued: ${a}`},`${i}-${a.slice(0,24)}`))}),ve?M(X,{flexDirection:"column",paddingX:1,children:[C($,{color:U,bold:!0,children:"Select model"}),C($,{color:"gray",children:"Your pick becomes your personal default for new sessions (team .d360-writer.json still wins)."}),le.map((a,i)=>M($,{color:i===ve.cursor?U:void 0,children:[i===ve.cursor?"\u276F ":" ",`${i+1}. ${a.label}${i===ve.current?" \u2714":""}`.padEnd(16),C($,{color:"gray",children:a.desc})]},a.label)),C($,{dimColor:!0,children:"enter set as default \xB7 s this session only \xB7 esc cancel"})]}):ce?M(X,{flexDirection:"column",paddingX:1,children:[C($,{color:U,bold:!0,children:"Switch connection profile"}),ce.rows.map((a,i)=>M($,{color:i===ce.cursor?U:void 0,children:[i===ce.cursor?"\u276F ":" ",`${i+1}. ${a.name}${i===ce.current?" \u2714":""}`.padEnd(20),C($,{color:"gray",children:`${a.env} \xB7 ${a.who??"not signed in"}`}),a.prod?C($,{color:"yellow",bold:!0,children:" \u26A0 PRODUCTION"}):null]},a.name)),C($,{dimColor:!0,children:"enter switch (saved as default) \xB7 s this session only \xB7 esc cancel"})]}):ge?M(X,{flexDirection:"column",paddingX:1,children:[C($,{color:U,bold:!0,children:"Pick your Document360 environment"}),ge.rows.map((a,i)=>M($,{color:i===ge.cursor?U:void 0,children:[i===ge.cursor?"\u276F ":" ",`${i+1}. ${a.name}`.padEnd(16),C($,{color:"gray",children:a.apiUrl})]},a.name)),C($,{dimColor:!0,children:"enter select \xB7 esc cancel"})]}):Y?M(X,{flexDirection:"column",paddingX:1,children:[C($,{color:U,bold:!0,children:"Switch workspace"}),C($,{dimColor:!0,children:`environment ${Y.environment} \xB7 project ${Y.projectId.slice(0,8)}\u2026`}),Y.rows.map((a,i)=>M($,{color:i===Y.cursor?U:void 0,children:[i===Y.cursor?"\u276F ":" ",`${i+1}. ${a.name}${i===Y.current?" \u2714":""}`.padEnd(30),C($,{color:"gray",children:a.type??""})]},a.id)),C($,{dimColor:!0,children:"enter switch \xB7 esc cancel"})]}):J?(()=>{let i=Math.min(Math.max(0,J.cursor-Math.floor(7)),Math.max(0,J.rows.length-14)),s=J.rows.slice(i,i+14),h=J.rows.filter(m=>m.checked).length;return M(X,{flexDirection:"column",paddingX:1,children:[C($,{color:U,bold:!0,children:`Which folders back the user docs? (${h} selected of ${J.rows.length})`}),i>0?C($,{dimColor:!0,children:` \u2191 ${i} more`}):null,s.map((m,g)=>{let y=i+g;return M($,{color:y===J.cursor?U:void 0,children:[y===J.cursor?"\u276F ":" ",m.checked?"\u25C9 ":"\u25CB ",m.path.padEnd(Math.min(48,Re-34)),C($,{color:"gray",children:Tt(m)})]},m.path)}),i+14<J.rows.length?C($,{dimColor:!0,children:` \u2193 ${J.rows.length-i-14} more`}):null,C($,{dimColor:!0,children:"space toggle \xB7 enter save \xB7 esc cancel"})]})})():ue?M(X,{flexDirection:"column",paddingX:1,children:[C($,{color:U,bold:!0,children:"Publish which article?"}),ue.rows.map((a,i)=>M($,{color:i===ue.cursor?U:void 0,children:[i===ue.cursor?"\u276F ":" ",`${i+1}. ${a.path}`.padEnd(Math.min(56,Re-30)),C($,{color:"gray",children:a.label})]},a.path)),C($,{dimColor:!0,children:"enter publish (draft) \xB7 esc cancel"})]}):ee?M(X,{flexDirection:"column",paddingX:1,children:[C($,{color:U,bold:!0,children:`Preview article${ee.query?` \u2014 filter: ${ee.query}`:" (type to filter)"}`}),ct.length===0?C($,{color:"gray",children:"no articles match"}):ct.map((a,i)=>M($,{color:i===ee.cursor?U:void 0,children:[i===ee.cursor?"\u276F ":" ",a]},a)),C($,{dimColor:!0,children:"enter preview \xB7 esc cancel"})]}):te?M(X,{flexDirection:"column",paddingX:1,children:[C($,{color:U,bold:!0,children:`Resume session${te.query?` \u2014 filter: ${te.query}`:" (type to filter)"}`}),ut.length===0?C($,{color:"gray",children:"no sessions match"}):ut.map((a,i)=>M($,{color:i===te.cursor?U:void 0,children:[i===te.cursor?"\u276F ":" ",a.name.slice(0,28).padEnd(30),C($,{color:i===te.cursor?U:"gray",children:a.firstPrompt.slice(0,Math.max(10,Re-40))})]},a.uuid)),C($,{dimColor:!0,children:"enter resume \xB7 esc cancel"})]}):Ln?C(X,{flexDirection:"column",children:ze.map((a,i)=>M($,{color:i===qe?U:void 0,children:[i===qe?"\u276F ":" ",a.usage.padEnd(22)," ",C($,{color:i===qe?U:"gray",children:a.name==="model"&&Gt?`${a.desc} (currently ${Gt})`:a.desc})]},a.name))}):!R&&Fe.length>0?M(X,{flexDirection:"column",paddingX:1,children:[Fe.map((a,i)=>M($,{children:[C($,{color:U,children:i+1})," ",a.slice(0,Math.max(20,Re-5))]},a)),C($,{dimColor:!0,children:`press 1-${Fe.length} to fill the command \xB7 esc dismiss`})]}):C(X,{paddingX:1,children:M($,{color:"gray",children:[Mn.prod?"\u26A0 PRODUCTION \xB7 ":"",`/help \xB7 ${Gt??"model n/a"}${at>0?` \xB7 ${at<1e3?`${at} tokens`:`${(at/1e3).toFixed(1)}k tokens`}`:""} \xB7 \u2191 history \xB7 ctrl+c exit`]})})]})}L();import{jsx as Al}from"react/jsx-runtime";async function Rr(e=process.cwd(),t="auto",n,o="0.0.0"){let r=jl(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 ${w("https://console.anthropic.com/settings/keys")}`),console.error(`Or use your Claude subscription instead: ${w("d360-writer --auth subscription")}`),process.exit(2));let{waitUntilExit:l}=Rl(Al(Sr,{cwd:e,auth:r,profileName:n,version:o}));await l(),process.stdout.write(`
64
+ `),process.exit(0)}var Ml=El(import.meta.url),jr=Ml("../package.json"),pe=new Il;function Cn(e){e.env&&(console.error("\u2717 --env was replaced by --profile (connection profiles). Use: --profile <name>"),process.exit(2))}pe.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=>{Cn(e),await wt({profile:e.profile,manual:e.manual})});pe.command("logout").description("Remove the stored Document360 session").option("--profile <name>","Connection profile").option("--env <name>",!1).action(async e=>{Cn(e),await to({profile:e.profile})});pe.command("whoami").description("Show the current Document360 identity (refreshes if expired)").option("--profile <name>","Connection profile").option("--env <name>",!1).action(async e=>{Cn(e),await eo({profile:e.profile})});var Pn=pe.command("profile").description("Manage connection profiles for the current repo");Pn.command("list",{isDefault:!0}).description("List profiles (\u25CF = default)").action(()=>yt(process.cwd()));Pn.command("use <name>").description("Set the default profile for this repo").action(e=>xt(process.cwd(),e));Pn.command("show [name]").description("Print the resolved profile (connection + project)").action(e=>$t(process.cwd(),e));var Ar=pe.command("workspace").description("Choose the Document360 workspace for this repo (active profile's project)");Ar.command("select",{isDefault:!0}).description("Interactively pick the workspace (lists in non-TTY)").option("--profile <name>","Connection profile").action(e=>We(process.cwd(),e.profile));Ar.command("use <name>").description("Set the workspace by name (scriptable)").option("--profile <name>","Connection profile").action(async(e,t)=>{process.exitCode=await Yn(process.cwd(),e,t.profile)});pe.command("logs").description("Show the Document360 API log files (send these to support when reporting a problem)").action(()=>oo());pe.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(()=>(jt(),Uo)),n=await t(process.cwd());for(let o of e(n))console.log(o);process.exitCode=n.some(o=>o.level==="fail")?1:0});pe.name("d360-writer").description("Standalone documentation agent CLI. Reads your code, writes your docs.").version(jr.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(Dl.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 ro(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 Qo(e.cwd,e.auth,e.profile):await Rr(e.cwd,e.auth,e.profile,jr.version)});pe.parseAsync(process.argv).catch(e=>{console.error(""),console.error(`\u2717 ${e.message}`),process.exit(1)});
@@ -1,7 +1,7 @@
1
1
  import type { SlashCommandResult } from './index.js';
2
2
  /** Non-interactive scaffold with sensible defaults — the TUI path (inquirer can't
3
3
  share stdin with Ink). The classic REPL/CLI keeps the interactive flow below. */
4
- export declare function scaffoldInit(cwd: string): {
4
+ export declare function scaffoldInit(cwd: string, env?: string): {
5
5
  created: boolean;
6
6
  path: string;
7
7
  profileName: string;
@@ -4,6 +4,7 @@ export declare function fetchWorkspaces(cwd: string, profileName?: string): Prom
4
4
  workspaces: D360Workspace[];
5
5
  projectId: string;
6
6
  profile: string;
7
+ environment: string;
7
8
  current?: string;
8
9
  }>;
9
10
  /** Match a workspace by exact name, name-prefix, or id-prefix (for `/workspace <name>`). */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "document360-writer",
3
- "version": "0.4.3",
3
+ "version": "0.4.4",
4
4
  "description": "Standalone documentation agent CLI. Reads your code, writes your docs. Specialized for Document360 publishing.",
5
5
  "type": "module",
6
6
  "bin": {