document360-writer 0.4.12 → 0.4.14
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 +54 -53
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -1,69 +1,70 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var Jr=Object.defineProperty;var nn=(e,t,o)=>()=>{if(o)throw o[0];try{return e&&(t=e(e=0)),t}catch(n){throw o=[n],n}};var Kr=(e,t)=>{for(var o in t)Jr(e,o,{get:t[o],enumerable:!0})};import we from"picocolors";var F,Qr,Zr,es,rn,Je,c,x,D,T,y,G,oe,_=nn(()=>{"use strict";F="#7f56d9",[Qr,Zr,es]=[127,86,217],rn=e=>we.isColorSupported?`\x1B[38;2;${Qr};${Zr};${es}m${e}\x1B[39m`:e,Je=e=>we.bold(rn(e)),c=e=>we.dim(e),x=e=>we.red(e),D=e=>we.yellow(e),T=e=>we.green(e),y=rn,G=e=>we.gray(e),oe=e=>we.bold(e)});var rr={};Kr(rr,{doctorCommand:()=>nt,renderDoctorChecks:()=>nr,runDoctorChecks:()=>or});import{existsSync as Ai}from"node:fs";import{d360GetAll as Ii,getAccessToken as Ei,isExpired as Io,loadProfileMap as Di,loadTokens as Mi,packageSkillsDir as tr,projectConfigPath as _i,readProjectConfig as Li,resolveActiveProfile as Ni,resolveAuth as Ui,resolveModelSetting as Oi}from"document360-engine";async function or(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=Ui("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=Oi(e);t.push({level:"ok",label:`Model: ${r.model??"Claude Code default"} (${r.source})`});let s=Li(e);if(!s)return t.push({level:"fail",label:`No ${_i(e)}`,fix:"Run: /init (or d360-writer init)"}),t;t.push({level:"ok",label:`Project config: ${s.projectId}`});let u=(s.docsDir??"user-docs").replace(/\/+$/,"");t.push(s.mode==="engineer"?{level:"warn",label:"Mode: engineer \u2014 agent may modify any source file (dogfooding)",fix:'Remove "mode" from .d360-writer.json for the writer-mode boundary'}:{level:"ok",label:`Mode: writer \u2014 edits limited to ${u}/, markdown, capture specs, and d360 config`});let p=s.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 f;try{f=Ni(e),t.push({level:"ok",label:`Profile: ${f.name} (${f.connection.name})${f.production?" \u26A0 PRODUCTION":""}`})}catch(j){return t.push({level:"fail",label:`Profile config: ${j.message.split(".")[0]}`,fix:"Run: /init to scaffold the profiles map"}),t}let g=Mi(f.name);g?Io(g)&&!g.refreshToken?t.push({level:"fail",label:"Document360: session expired (no refresh token)",fix:"/login"}):Io(g)?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(g.expiresAt).toLocaleString()})`}):t.push({level:"fail",label:"Document360: not logged in",fix:`Run: /login (or d360-writer login --profile ${f.name})`}),t.push(f.project.workspaceId?{level:"ok",label:`Workspace: ${f.project.workspaceId}`}:{level:"warn",label:"No workspace selected",fix:"Run: /workspace"});let v=Di(e,f.name);if(v?v.projectId&&f.project.projectId&&v.projectId!==f.project.projectId?t.push({level:"fail",label:`Category map projectId (${v.projectId}) \u2260 profile projectId (${f.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 "${f.name}" (created on first /publish)`}),t.push(Ai(tr())?{level:"ok",label:"Skills bundle present"}:{level:"fail",label:`Skills folder missing at ${tr()}`,fix:"Reinstall document360-writer (broken install)"}),g&&(!Io(g)||g.refreshToken)){let j={profile:f.name,connection:f.connection};try{await Ei(j);let $=await Ii(j,"/v3/projects");t.push({level:"ok",label:`API reachable (${f.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 nr(e){let t=[""];for(let r of e){let s=r.level==="ok"?T("\u2713"):r.level==="warn"?D("\u26A0"):x("\u2717");t.push(` ${s} ${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 nt(e,t){console.log(c("Running checks\u2026"));for(let o of nr(await or(t.cwd)))console.log(o);return{kind:"continue"}}var Mt=nn(()=>{"use strict";_()});import{Command as ta}from"commander";import{createRequire as oa}from"node:module";import{AUTH_MODES as na}from"document360-engine";import{input as us}from"@inquirer/prompts";import{loginPkce as ds,refreshTokens as ps,toStoredTokens as cn,clearTokens as ms,decodeJwtClaims as an,isExpired as fs,loadTokens as gs,saveTokens as un,resolveActiveProfile as $t,setProfileProject as hs,readProjectConfig as ks}from"document360-engine";_();import{select as ts}from"@inquirer/prompts";import{resolveActiveProfile as os,setProfileProject as ns,resolveProjectId as rs,listWorkspaces as ss}from"document360-engine";async function yt(e,t){let o=os(e,t),n={profile:o.name,connection:o.connection},r=o.project.projectId??rs(n);return{workspaces:await ss(n,r),projectId:r,profile:o.name,environment:o.connection.name,current:o.project.workspaceId}}var sn=e=>`${e.name??e.id}${e.workspace_type?` \xB7 ${e.workspace_type}`:""}`;function so(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 xt(e,t,o,n){ns(e,t,{projectId:o,workspaceId:n})}async function ln(e,t,o){let n;try{n=await yt(e,o)}catch(s){return console.log(x(`Could not list workspaces: ${s.message}`)),1}let r=so(n.workspaces,t);return r?(xt(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(s=>s.name??s.id).join(", ")}`)),1)}async function Be(e,t){let o;try{o=await yt(e,t)}catch(g){console.log(x(`Could not list workspaces: ${g.message}`));return}let{workspaces:n,projectId:r,profile:s,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 g of n)console.log(` ${g.id===u?y("\u25CF"):" "} ${sn(g)} ${c(g.id)}`);console.log(c("Run: d360-writer workspace use <name>"));return}let p=await ts({message:"Select the Document360 workspace for this repo:",choices:n.map(g=>({name:`${sn(g)}${g.id===u?" (current)":""}`,value:g.id}))});xt(e,s,r,p);let f=n.find(g=>g.id===p);console.log(T(`\u2713 Workspace set to "${f?.name??p}" for profile "${s}".`))}_();import is from"picocolors";function ls(e=process.env){return e.FORCE_HYPERLINK==="0"||!is.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 as(e,t=e,o){return ls(o)?`\x1B]8;;${e}\x07${t}\x1B]8;;\x07`:t}var cs=/https?:\/\/[^\s\x1b]+/g;function Ke(e,t){return e.replace(cs,o=>as(o,o,t))}function dn(e){return{...an(e.idToken)??{},...an(e.accessToken)??{}}}function bt(e){let t=dn(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 vt(e){let t=$t(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 ds(o,{manual:e.manual,promptForRedirect:s=>us({message:s})},s=>console.log(Ke(s))),r=cn(t.name,n);if(un(r),io(r,t.name,s=>console.log(c(s))),console.log(""),console.log(T(`\u2713 Logged in to "${t.name}" as ${bt(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{ks(process.cwd())?.profiles?.[t.name]&&(console.log(""),await Be(process.cwd(),t.name))}catch{}}function io(e,t,o){let r=dn(e).doc360_project_id;if(!(typeof r!="string"||!r))try{if($t(process.cwd(),t).project.projectId)return;hs(process.cwd(),t,{projectId:r}),o(` Project ${r} written to profile "${t}".`)}catch{}}async function pn(e){let t=$t(process.cwd(),e.profile),o=t.connection,n=gs(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":""}: ${bt(n)}`),fs(n))if(n.refreshToken)try{let r=cn(t.name,await ps(o,n.refreshToken));un(r),console.log(T(`\u2713 Session refreshed \u2014 expires ${r.expiresAt}`))}catch(r){console.log(D(`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(D("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 mn(e){let t=$t(process.cwd(),e.profile);ms(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.`))}_();import{readProjectConfig as fn,writeProjectConfig as ws,resolveActiveProfile as ys,loadTokens as xs,isExpired as $s}from"document360-engine";function Ct(e){let t=fn(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 "):" ",s=n.production?D(" \u26A0 PRODUCTION"):"",u=n.connection.environment??"(inline)",p=xs(o),f=p?$s(p)&&!p.refreshToken?D("expired"):c("logged in"):c("not logged in");console.log(`${r}${y(o)} \u2192 ${u}${s} [${f}]`)}console.log(""),console.log(c("\u25CF = default. Switch with: d360-writer profile use <name>")),console.log("")}function Pt(e,t){let o=fn(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,ws(o,e);let n=o.profiles[t].production?D(" \u26A0 PRODUCTION"):"";console.log(T(`\u2713 Default profile is now "${t}"${n}`))}function Tt(e,t){try{let o=ys(e,t);console.log(""),console.log(`Profile ${y(o.name)}${o.production?D(" \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}}_();import{existsSync as bs,readdirSync as vs,statSync as Cs}from"node:fs";import{join as Ps}from"node:path";import{apiLogDir as Ts}from"document360-engine";function gn(){let e=Ts();if(console.log(""),console.log(`Document360 API logs: ${y(e)}`),!bs(e)){console.log(c(" No logs yet \u2014 they appear after the first Document360 API call.")),console.log("");return}let t=vs(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=(Cs(Ps(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("")}_();import{createSession as Ss,resolveAuth as Rs,findByName as js,slugify as As,touchSession as Is,upsertSession as Es,resolveActiveProfile as Ds}from"document360-engine";async function hn(e,t,o,n,r,s){let u=Rs(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=Ds(e,r)}catch($){console.error(x(`Document360 profile error: ${$.message}`)),process.exit(2)}p.production&&(console.error(D(`\u26A0 Profile "${p.name}" is PRODUCTION.`)),s||(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 f;if(n){let $=js(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)),f=$.uuid,console.error(c(`Resuming "${$.name}"`))}let g=Ss({cwd:e,resume:f,profileName:r,allowProdWrites:s===!0}),v=f??null,j=1;for await(let $ of g.send(t))switch($.type){case"session":if(!v){v=$.sessionId;let R=new Date().toISOString();Es({uuid:v,name:As(t),renamed:!1,titled:!1,cwd:e,firstPrompt:t,createdAt:R,updatedAt:R})}break;case"text":process.stdout.write($.delta);break;case"tool":console.error(G(` \u2699 ${$.name}`));break;case"result":j=$.ok?0:1,console.error(c(`(${$.inputTokens}\u2192${$.outputTokens} tokens`+($.costUsd>0?`, $${$.costUsd<.01?$.costUsd.toFixed(4):$.costUsd.toFixed(2)}`:"")+")")),$.ok||console.error(x("agent finished with an error result"));break;case"error":console.error(""),console.error(x(`agent error: ${$.message}`)),process.exit(1)}v&&Is(v),process.stdout.write(`
|
|
3
|
-
`),process.exit(
|
|
2
|
+
var Kr=Object.defineProperty;var rn=(e,t,o)=>()=>{if(o)throw o[0];try{return e&&(t=e(e=0)),t}catch(n){throw o=[n],n}};var Qr=(e,t)=>{for(var o in t)Kr(e,o,{get:t[o],enumerable:!0})};import ye from"picocolors";var W,Zr,es,ts,sn,Ke,c,$,E,S,y,Y,ne,M=rn(()=>{"use strict";W="#7f56d9",[Zr,es,ts]=[127,86,217],sn=e=>ye.isColorSupported?`\x1B[38;2;${Zr};${es};${ts}m${e}\x1B[39m`:e,Ke=e=>ye.bold(sn(e)),c=e=>ye.dim(e),$=e=>ye.red(e),E=e=>ye.yellow(e),S=e=>ye.green(e),y=sn,Y=e=>ye.gray(e),ne=e=>ye.bold(e)});var sr={};Qr(sr,{doctorCommand:()=>rt,renderDoctorChecks:()=>rr,runDoctorChecks:()=>nr});import{existsSync as Ii}from"node:fs";import{d360GetAll as Ei,getAccessToken as Di,isExpired as Do,loadProfileMap as Mi,loadTokens as _i,packageSkillsDir as or,projectConfigPath as Li,readProjectConfig as Ni,resolveActiveProfile as Oi,resolveAuth as Ui,resolveModelSetting as Wi}from"document360-engine";async function nr(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=Ui("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=Wi(e);t.push({level:"ok",label:`Model: ${r.model??"Claude Code default"} (${r.source})`});let s=Ni(e);if(!s)return t.push({level:"fail",label:`No ${Li(e)}`,fix:"Run: /init (or d360-writer init)"}),t;t.push({level:"ok",label:`Project config: ${s.projectId}`});let u=(s.docsDir??"user-docs").replace(/\/+$/,"");t.push(s.mode==="engineer"?{level:"warn",label:"Mode: engineer \u2014 agent may modify any source file (dogfooding)",fix:'Remove "mode" from .d360-writer.json for the writer-mode boundary'}:{level:"ok",label:`Mode: writer \u2014 edits limited to ${u}/, markdown, capture specs, and d360 config`});let p=s.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=Oi(e),t.push({level:"ok",label:`Profile: ${k.name} (${k.connection.name})${k.production?" \u26A0 PRODUCTION":""}`})}catch(T){return t.push({level:"fail",label:`Profile config: ${T.message.split(".")[0]}`,fix:"Run: /init to scaffold the profiles map"}),t}let f=_i(k.name);f?Do(f)&&!f.refreshToken?t.push({level:"fail",label:"Document360: session expired (no refresh token)",fix:"/login"}):Do(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 x=Mi(e,k.name);if(x?x.projectId&&k.project.projectId&&x.projectId!==k.project.projectId?t.push({level:"fail",label:`Category map projectId (${x.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(x.articles).length} articles, ${Object.keys(x.categories).length} categories`}):t.push({level:"warn",label:`No d360-category-map.json section for "${k.name}" (created on first /publish)`}),t.push(Ii(or())?{level:"ok",label:"Skills bundle present"}:{level:"fail",label:`Skills folder missing at ${or()}`,fix:"Reinstall document360-writer (broken install)"}),f&&(!Do(f)||f.refreshToken)){let T={profile:k.name,connection:k.connection};try{await Di(T);let b=await Ei(T,"/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 rr(e){let t=[""];for(let r of e){let s=r.level==="ok"?S("\u2713"):r.level==="warn"?E("\u26A0"):$("\u2717");t.push(` ${s} ${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?S(`\u2713 ${n===0?"All checks passed":`Healthy (${n} warning${n===1?"":"s"})`}`):$(`\u2717 ${o} problem${o===1?"":"s"} found`)),t.push(""),t}async function rt(e,t){console.log(c("Running checks\u2026"));for(let o of rr(await nr(t.cwd)))console.log(o);return{kind:"continue"}}var Mt=rn(()=>{"use strict";M()});import{Command as na}from"commander";import{createRequire as ra}from"node:module";import{AUTH_MODES as sa}from"document360-engine";import{input as ds}from"@inquirer/prompts";import{loginPkce as ps,refreshTokens as ms,toStoredTokens as un,clearTokens as fs,decodeJwtClaims as cn,isExpired as gs,loadTokens as hs,saveTokens as dn,resolveActiveProfile as $t,setProfileProject as ks,readProjectConfig as ws}from"document360-engine";M();import{select as os}from"@inquirer/prompts";import{resolveActiveProfile as ns,setProfileProject as rs,resolveProjectId as ss,listWorkspaces as is}from"document360-engine";async function yt(e,t){let o=ns(e,t),n={profile:o.name,connection:o.connection},r=o.project.projectId??ss(n);return{workspaces:await is(n,r),projectId:r,profile:o.name,environment:o.connection.name,current:o.project.workspaceId}}var ln=e=>`${e.name??e.id}${e.workspace_type?` \xB7 ${e.workspace_type}`:""}`;function lo(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 xt(e,t,o,n){rs(e,t,{projectId:o,workspaceId:n})}async function an(e,t,o){let n;try{n=await yt(e,o)}catch(s){return console.log($(`Could not list workspaces: ${s.message}`)),1}let r=lo(n.workspaces,t);return r?(xt(e,n.profile,n.projectId,r.id),console.log(S(`\u2713 Workspace set to "${r.name??r.id}" for profile "${n.profile}".`)),0):(console.log($(`No workspace matches "${t}". Available: ${n.workspaces.map(s=>s.name??s.id).join(", ")}`)),1)}async function He(e,t){let o;try{o=await yt(e,t)}catch(f){console.log($(`Could not list workspaces: ${f.message}`));return}let{workspaces:n,projectId:r,profile:s,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"):" "} ${ln(f)} ${c(f.id)}`);console.log(c("Run: d360-writer workspace use <name>"));return}let p=await os({message:"Select the Document360 workspace for this repo:",choices:n.map(f=>({name:`${ln(f)}${f.id===u?" (current)":""}`,value:f.id}))});xt(e,s,r,p);let k=n.find(f=>f.id===p);console.log(S(`\u2713 Workspace set to "${k?.name??p}" for profile "${s}".`))}M();import ls from"picocolors";function as(e=process.env){return e.FORCE_HYPERLINK==="0"||!ls.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 cs(e,t=e,o){return as(o)?`\x1B]8;;${e}\x07${t}\x1B]8;;\x07`:t}var us=/https?:\/\/[^\s\x1b]+/g;function Qe(e,t){return e.replace(us,o=>cs(o,o,t))}function pn(e){return{...cn(e.idToken)??{},...cn(e.accessToken)??{}}}function bt(e){let t=pn(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 vt(e){let t=$t(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 ps(o,{manual:e.manual,promptForRedirect:s=>ds({message:s})},s=>console.log(Qe(s))),r=un(t.name,n);if(dn(r),ao(r,t.name,s=>console.log(c(s))),console.log(""),console.log(S(`\u2713 Logged in to "${t.name}" as ${bt(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{ws(process.cwd())?.profiles?.[t.name]&&(console.log(""),await He(process.cwd(),t.name))}catch{}}function ao(e,t,o){let r=pn(e).doc360_project_id;if(!(typeof r!="string"||!r))try{if($t(process.cwd(),t).project.projectId)return;ks(process.cwd(),t,{projectId:r}),o(` Project ${r} written to profile "${t}".`)}catch{}}async function mn(e){let t=$t(process.cwd(),e.profile),o=t.connection,n=hs(t.name);if(!n){console.log($(`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":""}: ${bt(n)}`),gs(n))if(n.refreshToken)try{let r=un(t.name,await ms(o,n.refreshToken));dn(r),console.log(S(`\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 fn(e){let t=$t(process.cwd(),e.profile);fs(t.name)?console.log(S(`\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 gn,writeProjectConfig as ys,resolveActiveProfile as xs,loadTokens as $s,isExpired as bs}from"document360-engine";function Ct(e){let t=gn(e);if(!t?.profiles||Object.keys(t.profiles).length===0){console.log($("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 "):" ",s=n.production?E(" \u26A0 PRODUCTION"):"",u=n.connection.environment??"(inline)",p=$s(o),k=p?bs(p)&&!p.refreshToken?E("expired"):c("logged in"):c("not logged in");console.log(`${r}${y(o)} \u2192 ${u}${s} [${k}]`)}console.log(""),console.log(c("\u25CF = default. Switch with: d360-writer profile use <name>")),console.log("")}function Pt(e,t){let o=gn(e);if(!o?.profiles?.[t]){let r=o?.profiles?Object.keys(o.profiles).join(", "):"(none \u2014 run init)";console.log($(`Unknown profile "${t}". Available: ${r}`)),process.exitCode=1;return}o.defaultProfile=t,ys(o,e);let n=o.profiles[t].production?E(" \u26A0 PRODUCTION"):"";console.log(S(`\u2713 Default profile is now "${t}"${n}`))}function Tt(e,t){try{let o=xs(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($(o.message)),process.exitCode=1}}M();import{existsSync as vs,readdirSync as Cs,statSync as Ps}from"node:fs";import{join as Ts}from"node:path";import{apiLogDir as Ss}from"document360-engine";function hn(){let e=Ss();if(console.log(""),console.log(`Document360 API logs: ${y(e)}`),!vs(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=(Ps(Ts(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 Rs,resolveAuth as js,findByName as As,slugify as Is,touchSession as Es,upsertSession as Ds,resolveActiveProfile as Ms}from"document360-engine";async function kn(e,t,o,n,r,s){let u=js(o);u.kind==="none"&&(console.error(""),console.error($("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=Ms(e,r)}catch(b){console.error($(`Document360 profile error: ${b.message}`)),process.exit(2)}p.production&&(console.error(E(`\u26A0 Profile "${p.name}" is PRODUCTION.`)),s||(console.error($("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 b=As(e,n);b||(console.error($(`No saved session matches "${n}" 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=Rs({cwd:e,resume:k,profileName:r,allowProdWrites:s===!0}),x=k??null,T=1;for await(let b of f.send(t))switch(b.type){case"session":if(!x){x=b.sessionId;let j=new Date().toISOString();Ds({uuid:x,name:Is(t),renamed:!1,titled:!1,cwd:e,firstPrompt:t,createdAt:j,updatedAt:j})}break;case"text":process.stdout.write(b.delta);break;case"tool":console.error(Y(` \u2699 ${b.name}`));break;case"result":T=b.ok?0:1,console.error(c(`(${b.inputTokens}\u2192${b.outputTokens} tokens`+(b.costUsd>0?`, $${b.costUsd<.01?b.costUsd.toFixed(4):b.costUsd.toFixed(2)}`:"")+")")),b.ok||console.error($("agent finished with an error result"));break;case"error":console.error(""),console.error($(`agent error: ${b.message}`)),process.exit(1)}x&&Es(x),process.stdout.write(`
|
|
3
|
+
`),process.exit(T)}import{createInterface as Xi}from"node:readline/promises";import{createSession as Lo,resolveAuth as Ji,getSession as Ki,setTitle as Qi,slugify as Zi,touchSession as hr,upsertSession as el,generateTitle as tl,resolveActiveProfile as kr,resolveModelSetting as ol,readProjectConfig as nl,decodeJwtClaims as fr,isExpired as rl,loadTokens as sl}from"document360-engine";M();async function co(){let e=["",ne("document360-writer \u2014 slash commands"),"",` ${y("/help")} ${c("Show this help")}`,` ${y("/init")} ${c("Pick a Document360 environment & scaffold .d360-writer.json")}`,` ${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("/convert [--scope <f>] [--run]")} ${c("Convert tracked articles to DFM across parallel agents (--scope to limit; --run to start)")}`,` ${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 _s}from"document360-engine";async function wn(e,t){let o=t.currentUuid(),n=o?_s(o):void 0;return console.log(n?c(`
|
|
4
4
|
(conversation reset \u2014 "${n.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
|
|
7
|
+
`)),{kind:"clear"}}async function uo(){return{kind:"exit"}}M();import{input as Ze,confirm as Ls}from"@inquirer/prompts";import{basename as yn,join as po}from"node:path";import{existsSync as et,readFileSync as Ns,readdirSync as Os}from"node:fs";import{writeProjectConfig as xn,readProjectConfig as Us,projectConfigPath as $n}from"document360-engine";function bn(e,t="berlin"){let o=$n(e);if(et(o))return{created:!1,path:o,profileName:""};let n={projectId:Cn(e)??yn(e),captureDir:"user-docs/_capture",outputDir:"user-docs/_screenshots",profiles:{[t]:{connection:{environment:t},production:!1}},defaultProfile:t,authoritativeSourceFiles:Pn(e)};return xn(n,e),{created:!0,path:o,profileName:t}}async function vn(){let e=process.cwd(),t=$n(e);if(et(t)&&!await Ls({message:`${t} already exists. Overwrite?`,default:!1}))return console.log(c("init cancelled.")),{kind:"continue"};let o=Cn(e)??yn(e),n=await Ze({message:"Project ID (used to scope sessions, screenshots, etc.):",default:o}),r=await Ze({message:"Capture directory (where document360-capture .spec.ts files live):",default:"user-docs/_capture"}),s=await Ze({message:"Screenshot output directory:",default:"user-docs/_screenshots"}),u=await Ze({message:"Default connection profile name:",default:"berlin"}),p=await Ze({message:"Document360 environment for this profile (baked preset):",default:"berlin"}),k={projectId:n,captureDir:r,outputDir:s,profiles:{[u]:{connection:{environment:p},production:!1}},defaultProfile:u,authoritativeSourceFiles:Pn(e)},f=Us(e);return f?.terminologyGlossary&&(k.terminologyGlossary=f.terminologyGlossary),xn(k,e),console.log(""),console.log(S(`\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 Cn(e){let t=po(e,"package.json");if(!et(t))return null;try{return JSON.parse(Ns(t,"utf8")).name??null}catch{return null}}function Pn(e){let t=[];for(let o of["README.md","ARCHITECTURE.md","CLAUDE.md"])et(po(e,o))&&t.push(o);for(let o of["src","api","docs"]){let n=po(e,o);et(n)&&!Ws(n)&&t.push(o)}return t}function Ws(e){try{return Os(e,{withFileTypes:!0}).filter(o=>o.isDirectory()&&!o.name.startsWith(".")).length>6}catch{return!1}}M();import{readMcpConfig as mo,writeMcpConfig as Tn}from"document360-engine";async function St(e){let t=(e[0]??"").toLowerCase();return t==="list"||!t?(Fs(),{kind:"continue"}):t==="add"?(Bs(e.slice(1)),{kind:"continue"}):t==="remove"||t==="rm"?(Hs(e.slice(1)),{kind:"continue"}):(console.log($(`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 Fs(){let e=mo(),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??{}),s=r.length>0?c(` [headers: ${r.join(", ")}]`):"";console.log(` ${y(o)} ${c(`(${n.type})`)} ${n.url}${s}`)}}console.log("")}function
|
|
10
|
-
`)}var
|
|
11
|
-
`)}async function
|
|
12
|
-
`),display:"/audit"}}
|
|
13
|
-
`);return
|
|
14
|
-
`)||
|
|
15
|
-
`},r=n(e),s=n(t);if(r===s)return null;let u=Math.max(20,o-10),p=
|
|
16
|
-
`),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(Un(r)){o.push({kind:"hr"}),n++;continue}if(r.includes("|")&&n+1<t.length&&
|
|
17
|
-
`)}),
|
|
18
|
-
`)},
|
|
19
|
-
`)}function
|
|
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??{}),s=r.length>0?c(` [headers: ${r.join(", ")}]`):"";console.log(` ${y(o)} ${c(`(${n.type})`)} ${n.url}${s}`)}}console.log("")}function Bs(e){let[t,o,...n]=e;if(!t||!o||n.length===0){console.log($("Usage: /mcp add <name> <stdio|http|sse> <command-or-url> [args...] [-H key:value ...]"));return}if(o!=="stdio"&&o!=="http"&&o!=="sse"){console.log($(`Unknown transport: ${o}. Use stdio, http, or sse.`));return}let r=mo(),s;if(o==="stdio")s={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($(`-H expects key:value (no spaces). Got: ${k??"(nothing)"}`));return}u[f[1].trim()]=f[2].trim()}else{console.log($(`Unexpected argument: ${n[p]}. After the URL, only -H key:value is allowed.`));return}s={type:o,url:n[0],headers:Object.keys(u).length>0?u:void 0}}r.servers[t]=s,Tn(r),console.log(""),console.log(S(`\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 Hs(e){let t=e[0];if(!t){console.log($("Usage: /mcp remove <name>"));return}let o=mo();if(!o.servers[t]){console.log($(`No server named "${t}".`));return}delete o.servers[t],Tn(o),console.log(S(`\u2713 Removed "${t}".`)),console.log(c(" Run /clear to drop it from the current session immediately."))}M();import{select as qs}from"@inquirer/prompts";import{computeSyncStatus as Sn}from"document360-engine";function jt(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 Rn={"local-ahead":"modified locally","untracked-local":"new (never published)",conflict:"\u26A0 conflict \u2014 publishing overwrites the portal edit"};function Rt(e){return e.filter(t=>t.path!==null&&t.status in Rn).map(t=>({path:t.path,label:Rn[t.status]}))}function tt(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 jn(e,t){let o=e[0];if(o==="--all"){console.log(c("Checking what needs publishing\u2026"));try{let n=Rt((await Sn({cwd:t?.cwd??process.cwd()})).entries);return n.length===0?(console.log(S("\u2713 Nothing is ahead of Document360 \u2014 no publish candidates.")),{kind:"continue"}):{kind:"forward-to-agent",prompt:tt(n.map(r=>r.path)),display:"/publish --all"}}catch(n){return console.log($(`Could not compute sync status: ${n.message}`)),{kind:"continue"}}}if(!o){console.log(c("Checking what needs publishing\u2026"));let n;try{n=Rt((await Sn({cwd:t?.cwd??process.cwd()})).entries)}catch(r){return console.log($(`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(S("\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(()=>qs({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:tt(n.map(r=>r.path)),display:"/publish --all"}}return{kind:"forward-to-agent",prompt:jt(o),display:`/publish ${o}`}}async function At(){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 zs}from"@inquirer/prompts";import{inventoryRepo as Gs,readProjectConfig as An,writeProjectConfig as Ys}from"document360-engine";function fo(e,t){let o=An(e);o&&(o.authoritativeSourceFiles=t,Ys(o,e))}function It(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 In(e,t){let o=t?.cwd??process.cwd();if(!An(o))return console.log($("No .d360-writer.json here. Run /init first.")),{kind:"continue"};let n=Gs(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 s of n)console.log(` ${s.recommended?"\u25C9":"\u25CB"} ${s.path} ${c(It(s))}`);return console.log(""),{kind:"continue"}}let r;try{r=await t.withPausedInput(()=>zs({message:"Which folders back the user docs? (space toggles, enter confirms)",choices:n.map(s=>({name:`${s.path} (${It(s)})`,value:s.path,checked:s.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"};fo(o,r),console.log(S(`\u2713 Scoped to ${r.length} folder(s) \u2014 written to .d360-writer.json`));for(let s of r)console.log(` ${s}`);return console.log(""),{kind:"continue"}}M();import{confirm as Qs}from"@inquirer/prompts";import{applyPull as Ln,computeSyncStatus as Nn,planPull as Zs,D360AuthError as ei}from"document360-engine";M();var En=[{status:"conflict",header:"Conflicts \u2014 both sides changed; pick a direction (/sync pull <path> or /publish <path>):",paint:$,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:$,mark:"D"},{status:"deleted-remote",header:"Deleted on Document360 \u2014 still local (publish to recreate, or delete the file):",paint:$,mark:"D"},{status:"orphaned",header:"Orphaned map entries \u2014 gone on both sides (remove from d360-category-map.json):",paint:Y,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:Y,mark:"\xB7"}];function Vs(e){return e.path?e.path:`${e.title??"(untitled)"} ${Y(`[${e.articleId}]`)}`}function Et(e){let t=[];for(let u of En){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(Vs(k))}${k.detail?Y(` (${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"},s=n===o?S("\u2713 everything in sync"):[o>0?S(`\u2713 ${o} in sync`):null,...En.map(u=>{let p=e.counts[u.status]??0;return p>0?`${p} ${r[u.status]}`:null})].filter(Boolean).join(Y(" \xB7 "));return t.push(s+Y(` \xB7 ${n} tracked+seen \xB7 profile "${e.profile}" \xB7 docs root ${e.docsRoot}/`)),t}import{structuredPatch as Xs}from"diff";import Dn from"picocolors";var Mn=80,Js="\x1B[48;2;74;28;28m",Ks="\x1B[48;2;24;66;24m",_n="\x1B[49m",go=e=>String(e).padStart(5);function Ie(e,t,o){let n=b=>{let j=b.replace(/\r\n/g,`
|
|
13
|
+
`);return j.endsWith(`
|
|
14
|
+
`)||j===""?j:j+`
|
|
15
|
+
`},r=n(e),s=n(t);if(r===s)return null;let u=Math.max(20,o-10),p=Xs("a","b",r,s,"","",{context:3}),k=0,f=0,x=[];p.hunks.forEach((b,j)=>{j>0&&x.push(Dn.gray(" \u2026"));let N=b.oldStart,D=b.newStart;for(let B of b.lines){let F=B[0],Z=B.slice(1).slice(0,u);F==="-"?(f++,x.push(`${Js}${go(N++)} - ${Z}${_n}`)):F==="+"?(k++,x.push(`${Ks}${go(D++)} + ${Z}${_n}`)):(x.push(Dn.gray(go(D))+" "+Z),N++,D++)}});let T=x.slice(0,Mn);return{added:k,removed:f,lines:T,hidden:Math.max(0,x.length-Mn)}}async function On(e,t){let o=(e[0]??"status").toLowerCase();try{if(o==="status")return await ti(t.cwd),{kind:"continue"};if(o==="pull")return await oi(t,e.slice(1)),{kind:"continue"};console.log($(`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 ei?console.log($(n.message)):console.log($(`Sync failed: ${n.message}`))}return{kind:"continue"}}async function ti(e){console.log(c("Checking Document360 for drift\u2026"));let t=await Nn({cwd:e});for(let o of Et(t))console.log(o);console.log("")}async function oi(e,t){let o=t[0];if(!o){console.log($("Usage: /sync pull <article-path> | --all"));return}let n;if(o==="--all"){if(console.log(c("Checking Document360 for drift\u2026")),n=(await Nn({cwd:e.cwd})).entries.filter(s=>s.status==="remote-ahead"&&s.path).map(s=>s.path),n.length===0){console.log(S("\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(n.length))} article(s) are remote-ahead.`)}else n=[o.replace(/\\/g,"/")];for(let r of n){let s=await Zs({cwd:e.cwd,relPath:r});console.log(""),console.log(`${y("\u25CF")} ${ne(s.title)} ${Y(`(${s.path})`)}`);for(let f of s.notes)console.log(E(` \u26A0 ${f}`));s.overwritesLocalChanges&&console.log(E(" \u26A0 This OVERWRITES local edits made since the last sync."));let u=Ie(s.oldContent,s.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.")),Ln({cwd:e.cwd},s);continue}let p=f=>f===1?"":"s";console.log(Y(` \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(()=>Qs({message:`Write ${s.path}?`,default:!s.overwritesLocalChanges}))){console.log(c(" Skipped."));continue}Ln({cwd:e.cwd},s),console.log(S(` \u2713 Pulled ${s.path} (sync base advanced).`))}console.log("")}M();import{statSync as mi}from"node:fs";import{resolve as fi}from"node:path";import{estimateBulkCost as gi,planPartitions as hi,readProjectConfig as ki,resolveModelForOperation as wi,runPartitioned as yi,trackedArticlePaths as xi}from"document360-engine";import _ from"picocolors";import qn from"wrap-ansi";import $o from"string-width";M();import xe from"picocolors";import ho from"wrap-ansi";import ko from"string-width";var Un=e=>/^\s*(-{3,}|\*{3,}|_{3,})\s*$/.test(e),Wn=e=>/^\s*\|?[\s:|-]*-[\s:|-]*\|?\s*$/.test(e)&&e.includes("-"),Fn=e=>e.replace(/^\s*\|/,"").replace(/\|\s*$/,"").split("|").map(t=>t.trim());function ni(e){let t=e.replace(/\r/g,"").split(`
|
|
16
|
+
`),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(Un(r)){o.push({kind:"hr"}),n++;continue}if(r.includes("|")&&n+1<t.length&&Wn(t[n+1])){let p=Fn(r);n+=2;let k=[];for(;n<t.length&&t[n].includes("|")&&t[n].trim()!=="";)k.push(Fn(t[n++]));o.push({kind:"table",header:p,rows:k});continue}let s=r.match(/^(#{1,6})\s+(.*)$/);if(s){o.push({kind:"heading",level:s[1].length,text:s[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])&&!Un(t[n])&&!(t[n].includes("|")&&n+1<t.length&&Wn(t[n+1]));)u.push(t[n++]);o.push({kind:"para",text:u.join(" ")})}return o}function wo(e){return e.replace(/(\*\*[^*]+\*\*|`[^`]+`|\*[^*]+\*)/g,t=>t.startsWith("**")?xe.bold(t.slice(2,-2)):t.startsWith("`")?y(t.slice(1,-1)):xe.italic(t.slice(1,-1)))}var ri=(e,t)=>e+" ".repeat(Math.max(0,t-ko(e)));function si(e,t,o){let n=e.length,r=e.map((N,D)=>Math.max(ko(N),...t.map(B=>ko(B[D]??"")))),s=Math.max(24,o),u=3*n+1,p=[...r],k=()=>p.reduce((N,D)=>N+D,0)+u,f=0;for(;k()>s&&f++<1e4;){let N=-1,D=6;for(let B=0;B<n;B++)p[B]>D&&(D=p[B],N=B);if(N===-1)break;p[N]-=1}let x=(N,D,B)=>xe.gray(N+p.map(F=>"\u2500".repeat(F+2)).join(D)+B),T=xe.gray("\u2502"),b=(N,D)=>{let B=p.map((re,ge)=>{let se=N[ge]??"",ie=D?xe.bold(se):wo(se);return ho(ie,re,{hard:!0}).split(`
|
|
17
|
+
`)}),F=Math.max(...B.map(re=>re.length)),Z=[];for(let re=0;re<F;re++)Z.push(p.map((ge,se)=>`${T} ${ri(B[se][re]??"",ge)} `).join("")+T);return Z.join(`
|
|
18
|
+
`)},j=[x("\u250C","\u252C","\u2510"),b(e,!0)];return j.push(t.length===0?x("\u2514","\u2534","\u2518"):x("\u251C","\u253C","\u2524")),t.forEach((N,D)=>{j.push(b(N,!1)),j.push(D===t.length-1?x("\u2514","\u2534","\u2518"):x("\u251C","\u253C","\u2524"))}),j.join(`
|
|
19
|
+
`)}function ii(e,t){switch(e.kind){case"heading":return xe.bold(e.text);case"hr":return xe.gray("\u2500".repeat(t));case"para":return ho(wo(e.text),t);case"list":return e.items.map(o=>{let[n="",...r]=ho(wo(o),Math.max(10,t-4)).split(`
|
|
20
20
|
`);return" \u2022 "+n+r.map(s=>`
|
|
21
21
|
`+s).join("")}).join(`
|
|
22
|
-
`);case"code":return e.lines.map(o=>
|
|
23
|
-
`);case"table":return
|
|
22
|
+
`);case"code":return e.lines.map(o=>xe.gray(" "+o)).join(`
|
|
23
|
+
`);case"table":return si(e.header,e.rows,t)}}function yo(e,t){let o=Math.max(20,t);return ni(e).map(n=>ii(n,o)).join(`
|
|
24
24
|
|
|
25
|
-
`)}
|
|
26
|
-
`);let r=2,s=3,u
|
|
27
|
-
`);let
|
|
28
|
-
`)}var
|
|
29
|
-
`).flatMap(
|
|
30
|
-
`)),
|
|
31
|
-
`+p.map((
|
|
25
|
+
`)}M();import li from"picocolors";var ai=[127,86,217],ci=[22,38,43],Bn={T:ai,E:ci},ot=["..TTTTTT....","..TTTTTTT...","..TTTTTTTT..","..TTETTETT..","..TTETTETT..","..TTTTTTTT..","..TTTTTTT...","..TTTTTT....","...T..T....."],xo=([e,t,o])=>`\x1B[38;2;${e};${t};${o}m`,ui=([e,t,o])=>`\x1B[48;2;${e};${t};${o}m`;function Hn(){if(!li.isColorSupported)return[];let e=ot[0].length,t=[];for(let o=0;o<ot.length;o+=2){let n="";for(let r=0;r<e;r++){let s=Bn[ot[o][r]],u=o+1<ot.length?Bn[ot[o+1][r]]:void 0;s&&u?n+=`${xo(s)}${ui(u)}\u2580\x1B[49m\x1B[39m`:s?n+=`${xo(s)}\u2580\x1B[39m`:u?n+=`${xo(u)}\u2584\x1B[39m`:n+=" "}t.push(n)}return t}function bo(e){return e<60?`${e}s`:`${Math.floor(e/60)}m ${e%60}s`}function Ee(e){return e<=0?"$0.00":e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}var qe=(e,t)=>` ${e.padEnd(13)}${t}`;function di(e,t){let o=[Ke("\u270E document360-writer")+_.gray(` v${e.version}`),_.gray(" Reads your code, writes your docs."),"",qe("Claude:",`${e.claude}${_.gray(` \xB7 ${e.model}${e.modelSource?` (${e.modelSource})`:""}`)}`),qe("Document360:",e.configured?e.loggedOut?_.yellow("not logged in \u2014 run /login"):`${e.who??""}${e.sessionHint?_.gray(` (${e.sessionHint})`):""}`:_.yellow("not set up \u2014 run /init")),qe("Profile:",e.configured?`${e.profile}${_.gray(` (${e.apiUrl})`)}${e.prod?_.bold(_.yellow(" \u26A0 PRODUCTION")):""}`:_.gray("\u2014 (run /init)")),qe("Project:",e.project),qe("Mode:",_.gray(e.mode)),qe("cwd:",_.gray(e.cwd))],n=Hn();if(n.length===0)return o.join(`
|
|
26
|
+
`);let r=2,s=3,u=$o(n[0]);if(!(t>=r+u+s+Math.max(...o.map(x=>$o(x)))))return[...n.map(x=>" "+x),...o].join(`
|
|
27
|
+
`);let k=Math.max(0,Math.floor((o.length-n.length)/2)),f=[];for(let x=0;x<Math.max(n.length+k,o.length);x++){let T=n[x-k]??" ".repeat(u);f.push((" ".repeat(r)+T+" ".repeat(s)+(o[x]??"")).trimEnd())}return f.join(`
|
|
28
|
+
`)}var pi={error:_.red,warn:_.yellow,ok:_.green,info:_.gray};function vo(e,t){let o=Math.max(20,t);switch(e.kind){case"banner":return di(e.info,o);case"user":{let n="\x1B[48;2;42;42;46m",r="\x1B[49m",s=Math.max(10,o-4),u=50,p=e.text.split(`
|
|
29
|
+
`).flatMap(f=>qn(f,s,{hard:!0}).split(`
|
|
30
|
+
`)),k=Math.max(0,p.length-u);return k>0&&(p=[...p.slice(0,u),_.dim(`\u2026 +${k} more lines`)]),`
|
|
31
|
+
`+p.map((f,x)=>n+(x===0?y(" \u276F "):" ")+f+" ".repeat(Math.max(0,s-$o(f))+1)+r).join(`
|
|
32
32
|
`)}case"assistant":return`
|
|
33
|
-
`+
|
|
34
|
-
`+
|
|
35
|
-
`)}case"diff":{let n=u=>u===1?"":"s",s=[
|
|
36
|
-
`)}case"link":return e.lines.map(n=>y(
|
|
33
|
+
`+yo(e.text,o);case"tool":{let n=e.arg!==null?_.gray(`${e.sep}(${e.arg})`):"";return`
|
|
34
|
+
`+qn(_.green("\u25CF ")+_.bold(e.title)+n,o)}case"tool-result":{let n=e.isError?_.red:_.gray,r=e.lines.map((s,u)=>n((u===0?" \u23BF ":" ")+s));return e.hidden>0&&r.push(_.dim(` \u2026 +${e.hidden} lines`)),r.join(`
|
|
35
|
+
`)}case"diff":{let n=u=>u===1?"":"s",s=[_.gray(` \u23BF Added ${e.added} line${n(e.added)}, removed ${e.removed} line${n(e.removed)}`),...e.lines];return e.hidden>0&&s.push(_.dim(` \u2026 +${e.hidden} more diff lines`)),s.join(`
|
|
36
|
+
`)}case"link":return e.lines.map(n=>y(Qe(` \u2B95 ${n}`))).join(`
|
|
37
37
|
`);case"preview":return`
|
|
38
|
-
`+
|
|
38
|
+
`+Ke(`\u25A3 Preview \u2014 ${e.name}`)+`
|
|
39
39
|
|
|
40
|
-
`+
|
|
41
|
-
`+
|
|
42
|
-
`+(e.ok?
|
|
43
|
-
`)}var
|
|
40
|
+
`+yo(e.text,o);case"note":return`
|
|
41
|
+
`+pi[e.tone](Qe(e.text));case"done":return`
|
|
42
|
+
`+(e.ok?_.magenta("\u2736 "):_.red("\u2736 "))+_.gray(`Cooked for ${bo(e.seconds)} \xB7 ${e.tokens} tokens`+(e.costUsd>0?` \xB7 ${Ee(e.costUsd)}`:""))}}function zn(e,t){return e.map(o=>vo(o,t)).join(`
|
|
43
|
+
`)}var Co=3;function Po(e){let t,o=!1;for(let r=0;r<e.length;r++){let s=e[r];s==="--run"||s==="--yes"?o=!0:s==="--scope"?t=e[++r]:s?.startsWith("--scope=")&&(t=s.slice(8))}return{scope:t?.replace(/\\/g,"/").replace(/\/+$/,"")||void 0,run:o}}function To(e,t){return t?e.filter(o=>{let n=o.replace(/\\/g,"/");return n===t||n.startsWith(`${t}/`)}):e}function So(e,t){return t.map(o=>{let n=0;try{n=mi(fi(e,o)).size}catch{n=0}return{path:o,bytes:n}})}function Ro(e){return`Convert each of these articles to canonical Document360 Flavored Markdown (DFM) \u2014 wrap callouts, FAQs, tabs, accordions, and media embeds per the d360-markdown skill \u2014 then re-publish each as a DRAFT to Document360. Work ONLY on the files in this partition; do not read, touch, or convert any article outside this list:
|
|
44
44
|
`+e.paths.map(t=>`- ${t}`).join(`
|
|
45
|
-
`)}function
|
|
46
|
-
`),display:`/screenshot ${t}`}:(console.log(
|
|
47
|
-
`).trimEnd();if(!r)return{lines:["(no output)"],hidden:0};if(o?.startsWith("mcp__document360__")){let u=
|
|
48
|
-
`);return{lines:s.slice(0,t).map(u=>
|
|
45
|
+
`)}function jo(e,t,o){let n=e.reduce((p,k)=>p+k.paths.length,0),[r,s]=t.usd;return[`Convert ${n} article${n===1?"":"s"} to DFM across ${e.length} partition${e.length===1?"":"s"} (\u2264${o} agents at once):`,...e.map(p=>` \u2022 ${p.label} \u2014 ${p.paths.length} article${p.paths.length===1?"":"s"}`),"",`Estimated cost: ${Ee(r)}\u2013${Ee(s)}. ${t.note}`,"","Each article is rewritten and re-published as a DRAFT. Run /convert --run to start."]}function Ao(e,t){let o=e.filter(s=>s.ok),n=e.filter(s=>!s.ok),r=[`Converted ${o.length}/${e.length} partition${e.length===1?"":"s"} \xB7 ${Ee(t)} total.`];if(n.length>0){r.push(`${n.length} failed \u2014 re-run /convert to retry:`);for(let s of n)r.push(` \u2717 ${s.label}${s.error?` \u2014 ${s.error}`:""}`)}return r}async function Gn(e,t){if(!ki(t.cwd))return console.log($("No .d360-writer.json here. Run /init first.")),{kind:"continue"};let{scope:o,run:n}=Po(e),r=xi(t.cwd,t.profileName);if(r.length===0)return console.log($("No tracked articles in d360-category-map.json. Publish some first (/publish), then /convert.")),{kind:"continue"};let s=To(r,o);if(s.length===0)return console.log($(`No tracked articles under "${o}". (${r.length} are tracked overall.)`)),{kind:"continue"};let u=hi(s),p=`/convert${o?` --scope ${o}`:""} --run`,{model:k,forced:f}=wi(t.cwd,"light");if(!n){let x=gi({files:So(t.cwd,s),op:"convert",model:k});o&&console.log(c(`Scope: ${o} (${s.length} of ${r.length} tracked articles).`));for(let T of jo(u,x,Co))console.log(T);return console.log(c(`Model: ${k}${f?" (forced)":" \u2014 mechanical work; /model to override"}.`)),console.log(c(`Run ${p} to start.`)),console.log(""),{kind:"continue"}}console.log(c(`Converting ${s.length} articles across ${u.length} partitions (\u2264${Co} agents at once) on ${k}\u2026`)),console.log(c(" (mid-run abort is TUI-only \u2014 Ctrl+C exits the REPL.)"));try{for await(let x of yi({cwd:t.cwd,partitions:u,promptFor:Ro,concurrency:Co,profileName:t.profileName,allowProdWrites:t.allowProdWrites(),model:k}))if(x.type==="partition_status")x.status==="running"?console.log(c(` \u25B8 ${x.label} \u2014 converting\u2026`)):x.status==="done"?console.log(S(` \u2713 ${x.label}`)):console.log($(` \u2717 ${x.label}`));else if(x.type==="run_done"){console.log("");for(let T of Ao(x.results,x.totalCostUsd))console.log(x.ok?S(T):E(T))}}catch(x){console.log($(`Convert run failed: ${x.message}`))}return console.log(""),{kind:"continue"}}M();import{search as $i}from"@inquirer/prompts";import{findByName as bi,getSession as vi,listSessions as Ci,relativeTime as Vn}from"document360-engine";async function Xn(e,t){let o=Ci(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=bi(t.cwd,n);return r?{kind:"resume",uuid:r.uuid,name:r.name}:(console.log($(`No session matches "${n}".`)),Yn(o),{kind:"continue"})}if(!process.stdin.isTTY)return Yn(o),console.log(c("Run: /resume <name>")),{kind:"continue"};try{let n=await t.withPausedInput(()=>$i({message:"Resume session (type to filter, \u2191\u2193 to navigate):",source:async s=>{let u=(s??"").toLowerCase();return o.filter(p=>!u||p.name.toLowerCase().includes(u)||p.firstPrompt.toLowerCase().includes(u)).map(p=>({name:`${p.name} ${Vn(p.updatedAt)}`,value:p.uuid,description:p.firstPrompt.slice(0,100)}))}})),r=vi(n);return r?{kind:"resume",uuid:r.uuid,name:r.name}:{kind:"continue"}}catch{return console.log(""),{kind:"continue"}}}function Yn(e){console.log("");for(let t of e.slice(0,15))console.log(` ${y(t.name)} ${c(Vn(t.updatedAt))}`),console.log(` ${c(t.firstPrompt.slice(0,80))}`);console.log("")}M();import{renameSession as Pi}from"document360-engine";async function Jn(e,t){let o=e.join(" ").trim();if(!o)return console.log($("Usage: /rename <new name>")),{kind:"continue"};let n=t.currentUuid();return n?(Pi(n,o)?console.log(S(`\u2713 Session renamed to "${o}"`)):console.log($("Could not find the current session record.")),{kind:"continue"}):(console.log($("Nothing to rename yet \u2014 send a message first; sessions auto-save once the agent replies.")),{kind:"continue"})}import{knownEnvironments as Kn,readProjectConfig as Ti,writeProjectConfig as Si}from"document360-engine";M();function Io(e,t,o){if(!t)return"Usage: /profile add <name> [environment]";let n=Ti(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 Kn().includes(r)?(n.profiles={...n.profiles,[t]:{connection:{environment:r},production:!1}},Si(n,e),null):`Unknown environment "${r}". Known: ${Kn().join(", ")} (or add the profile with explicit URLs in .d360-writer.json).`}async function Qn(e,t){let o=e[0];if(!o)return Ct(t.cwd),{kind:"continue"};if(o==="add"){let n=Io(t.cwd,e[1],e[2]);return n?(console.log($(n)),{kind:"continue"}):(console.log(S(`\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 Pt(t.cwd,o),Tt(t.cwd,o),console.log(c(" Restarting agent for the new profile\u2026")),{kind:"clear"}}M();import{select as Ri}from"@inquirer/prompts";import{readProjectConfig as ji,readUserConfig as Zn,resolveModelSetting as Eo,writeUserConfig as er}from"document360-engine";var ae=[{value:null,label:"Auto",desc:"Engine right-sizes per task \u2014 Sonnet for routine work, Opus for analysis (recommended)"},{value:"claude-fable-5",label:"Fable",desc:"Fable 5 \xB7 most capable, for the hardest and longest-running tasks"},{value:"opus",label:"Opus",desc:"Opus 4.8 \xB7 best for everyday complex tasks"},{value:"sonnet",label:"Sonnet",desc:"Sonnet 4.6 \xB7 efficient for routine tasks"},{value:"haiku",label:"Haiku",desc:"Haiku 4.5 \xB7 fastest for quick answers"}];function Dt(e){if(e.model===null||e.source==="claude-settings")return 0;let t=e.model.toLowerCase(),o=ae.findIndex(n=>n.value!==null&&(n.value===t||n.label.toLowerCase()===t||t.includes(n.label.toLowerCase())));return o>=0?o:0}function Ai(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 nt(e,t){let o=()=>{let s=Eo(e);return s.source==="project"||s.source==="user"||s.source==="env"?s.model??void 0:void 0};if(t==="default"){let s=Zn();return s.defaultModel?(delete s.defaultModel,er(s),{lines:[`\u2713 Personal model override cleared \u2014 now: ${Eo(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}}er({...Zn(),defaultModel:t});let n=[`\u2713 Personal model set to "${t}" (applies from your next message \u2014 conversation continues)`],r=ji(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 tr(e,t){let o=e[0]?.trim();if(!o){let u=Eo(t.cwd);if(!process.stdin.isTTY)return console.log(`${ne("Model:")} ${y(u.model??"Claude Code default")}`),console.log(c(` source: ${Ai(u)}`)),console.log(c(" change: /model <haiku|sonnet|opus|full-model-id> \xB7 reset: /model default")),{kind:"continue"};let p=Dt(u),k;try{k=await t.withPausedInput(()=>Ri({message:`Select model (current: ${u.model??"Claude Code default"})`,default:ae[p].value,choices:ae.map((b,j)=>({name:`${b.label}${j===p?" \u2714":""}`,value:b.value,description:b.desc}))}))}catch{return console.log(c("Cancelled.")),{kind:"continue"}}let{lines:f,changed:x,effective:T}=nt(t.cwd,k??"default");for(let b of f)console.log(b.startsWith("\u26A0")?E(b):b.startsWith("\u2713")?S(b):c(b));return x&&await t.setModel(T),{kind:"continue"}}let{lines:n,changed:r,effective:s}=nt(t.cwd,o);for(let u of n)console.log(u.startsWith("\u26A0")?E(u):u.startsWith("\u2713")?S(u):c(u));return r&&await t.setModel(s),{kind:"continue"}}Mt();async function ir(e,t){return await t.withPausedInput(()=>He(t.cwd)),{kind:"clear"}}M();import{resolveActiveProfile as Fi}from"document360-engine";async function lr(e,t){let o=!1;try{o=Fi(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 ar=async(e,t)=>{try{await t.withPausedInput(()=>vt({}))}catch(o){console.log($(`Login failed: ${o.message}`))}return{kind:"continue"}};M();async function _t(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(`
|
|
46
|
+
`),display:`/screenshot ${t}`}:(console.log($("Usage: /screenshot <placeholder-id>")),{kind:"continue"})}var cr={help:co,"?":co,clear:wn,exit:uo,quit:uo,init:vn,mcp:St,publish:jn,audit:At,scope:In,sync:On,convert:Gn,resume:Xn,rename:Jn,profile:Qn,model:tr,doctor:rt,workspace:ir,"allow-prod":lr,login:ar,screenshot:_t};function ur(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 Bi={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"},pr=160,_o=200,mr=40;function Q(e,t){let o=e.replace(/\s+/g," ").trim();return o.length<=t?o:o.slice(0,t-1)+"\u2026"}function dr(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}: ${Q(typeof r=="string"?r:JSON.stringify(r),mr)}`);return t.length>4&&o.push("\u2026"),Q(o.join(", "),pr)}var $e=e=>typeof e=="string"&&e?e:null,Mo=e=>typeof e=="string"&&e.length>=8?e.slice(0,8):null;function Hi(e){let t=$e(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(s=>s.charAt(0).toUpperCase()+s.slice(1)).join(" ")}function qi(e,t){let o=(n,r)=>({title:`Document360: ${n}`,sep:" ",arg:r});switch(e){case"d360_create_article":{let n=$e(t.title);if(!n)return null;let r=Hi(t.local_path);return o("Create article",`"${Q(n,60)}"${r?` in ${r}`:""}`)}case"d360_update_article":{let n=$e(t.title),r=Mo(t.article_id);return o("Update article",n?`"${Q(n,60)}"`:r?`id ${r}\u2026`:null)}case"d360_fork_article":return o("Fork article (new draft)",Mo(t.article_id)?`id ${Mo(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",$e(t.name)?`"${Q($e(t.name),60)}"`:null);case"d360_upload_drive_file":{let n=$e(t.file_path);return o("Upload image",n?Q(n.replace(/\\/g,"/").split("/").pop()??n,60):null)}case"d360_sync_status":return o("Check sync status",null);default:return null}}function Lt(e,t){if(e==="ToolSearch")return null;if(e.startsWith("mcp__")){let[,r="",...s]=e.split("__"),u=s.join("__");if(r==="document360"){let f=qi(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:dr(t)}}let o=Bi[e],n=o?t[o]:void 0;return typeof n=="string"&&n?{title:e,sep:"",arg:Q(n,pr)}:{title:e,sep:"",arg:dr(t)}}function zi(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 Gi(e){if(!/^[[{]/.test(e))return null;let t;try{t=JSON.parse(e)}catch{return null}if(Array.isArray(t)){let o=t.map(zi).filter(r=>r!==null),n=`${t.length} item${t.length===1?"":"s"}`;return o.length===0?[n]:[n,...o.map(r=>Q(r,_o))]}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}: ${Q(String(r),mr)}`);return o.length>0?[Q(o.join(" \xB7 "),_o)]:null}return null}function Yi(e){let t=$e(e)?.replace(/\\/g,"/");if(!t)return null;let o=t.split("/").filter(Boolean);return o.length>1?o.slice(1).join("/"):t}function Vi(e,t,o){switch(e){case"d360_create_article":{let n=Yi(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=$e(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 ${Q(n[0],120)}`:""}`]}default:return null}}function Nt(e,t=4,o,n){let r=e.replace(/\r\n/g,`
|
|
47
|
+
`).trimEnd();if(!r)return{lines:["(no output)"],hidden:0};if(o?.startsWith("mcp__document360__")){let u=Vi(o.slice(18),n,r);if(u)return{lines:u,hidden:0}}let s=Gi(r)??r.split(`
|
|
48
|
+
`);return{lines:s.slice(0,t).map(u=>Q(u,_o)),hidden:Math.max(0,s.length-t)}}function Ot(e,t,o,n="en"){return`${e.replace(/\/$/,"")}/${t}/document/v1/${n}/${o}`}function Ut(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 Wt(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 il=/^mcp__document360__d360_(create_article|update_article|fork_article|publish_article)$/;function ll(e,t,o,n){if(il.test(e))try{let r=kr(n),s=typeof t.project_id=="string"&&t.project_id||r.project.projectId,u=Ut(t,o),p=Wt(o);e.endsWith("publish_article")&&p&&console.log(y(` \u2B95 Live: ${p}`)),u&&s&&console.log(y(` \u2B95 Preview: ${Ot(r.connection.portalUrl,s,u,r.project.languageCode??"en")}`))}catch{}}async function wr(e=process.cwd(),t="auto",o){let n=Ji(t);n.kind==="none"&&(console.error(""),console.error($("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)),al(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,s=Lo({cwd:e,profileName:o,allowProdWrites:r}),u={uuid:null,firstPrompt:null,titleFired:!1},p=Xi({input:process.stdin,output:process.stdout}),k=[],f=null,x=!1;p.on("line",j=>{if(f){let N=f;f=null,N(j)}else k.push(j)}),p.on("close",()=>{if(x=!0,f){let j=f;f=null,j(null)}});function T(){return k.length>0?Promise.resolve(k.shift()):x?Promise.resolve(null):(process.stdout.write(y("> ")),new Promise(j=>{f=j}))}let b={cwd:e,profileName:o,allowProdWrites:()=>r,restartAgent:()=>{s.close(),s=Lo({cwd:e,profileName:o,allowProdWrites:r}),u={uuid:null,firstPrompt:null,titleFired:!1}},currentUuid:()=>u.uuid,setModel:async j=>s.setModel(j),withPausedInput:async j=>{p.pause();try{return await j()}finally{p.resume()}}};try{for(;;){let j=await T();if(j===null)break;let N=j.trim();if(N){if(N.startsWith("/")){let D=ur(N);if(!D)continue;let B=cr[D.name];if(!B){console.log($(`Unknown command: /${D.name}`)),console.log(c("Type /help for the list."));continue}let F=await B(D.args,b);if(F.kind==="exit")break;if(F.kind==="clear"){b.restartAgent();continue}if(F.kind==="allow-prod"){r=!0,b.restartAgent(),console.log(S("\u2713 Production writes authorized for this session.")),console.log("");continue}if(F.kind==="resume"){s.close(),s=Lo({cwd:e,resume:F.uuid,profileName:o,allowProdWrites:r});let Z=Ki(F.uuid);u={uuid:F.uuid,firstPrompt:Z?.firstPrompt??null,titleFired:!0},hr(F.uuid),console.log(S(`\u2713 Resumed "${F.name}"`)),console.log("");continue}F.kind==="forward-to-agent"&&(u.firstPrompt||(u.firstPrompt=F.display??F.prompt),await gr(s,F.prompt,n,u,e));continue}u.firstPrompt||(u.firstPrompt=N),await gr(s,N,n,u,e)}}}finally{s.close(),p.close()}}function al(e,t){console.log(""),console.log(Ke("document360-writer")),console.log(c(` cwd: ${e}`));let o=ol(e);console.log(c(` model: ${o.model??"auto (engine right-sizes per task)"}${o.model?` (${o.source})`:""}`)),console.log(cl(e,t)),nl(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 cl(e,t){try{let o=kr(e,t),n=o.production?E(" \u26A0 PRODUCTION"):"",r=sl(o.name);if(!r)return c(` Document360: profile "${o.name}"${n} \u2014 not logged in (d360-writer login)`);let s={...fr(r.idToken)??{},...fr(r.accessToken)??{}},u=s.email??s.preferred_username??"signed in";return rl(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 ul(){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 dl(e,t,o){e.uuid=t;let n=new Date().toISOString();el({uuid:t,name:Zi(e.firstPrompt??"session"),renamed:!1,titled:!1,cwd:o,firstPrompt:e.firstPrompt??"",createdAt:n,updatedAt:n})}function pl(e,t){e.titleFired=!0;let o=e.uuid,n=e.firstPrompt;!o||!n||tl(n,t).then(r=>{r&&Qi(o,r)}).catch(()=>{})}async function gr(e,t,o,n,r){let s=new Map;for await(let u of e.send(t))ml(u,n,r,o,s)}function ml(e,t,o,n,r){switch(e.type){case"session":t.uuid||dl(t,e.sessionId,o);break;case"text":process.stdout.write(e.delta);break;case"tool":{let s=Lt(e.name,e.input);s&&(process.stdout.write(`
|
|
49
49
|
|
|
50
|
-
`),console.log(`${
|
|
51
|
-
`),console.log(c(` (${e.inputTokens}\u2192${e.outputTokens} tokens`+(e.costUsd>0?`, $${e.costUsd<.01?e.costUsd.toFixed(4):e.costUsd.toFixed(2)}`:"")+")")),console.log(""),t.uuid&&(
|
|
52
|
-
`)){let u=s.trim().replace(
|
|
53
|
-
`)}function
|
|
54
|
-
`)||e.length>200}function
|
|
55
|
-
`).length;return`[Pasted text #${e} +${o} line${o===1?"":"s"}]`}function
|
|
56
|
-
`)){if(s.length===0)n.push({start:r,end:r});else for(let u=0;u<s.length;u+=o)n.push({start:r+u,end:r+Math.min(u+o,s.length)});r+=s.length+1}return n.length>0?n:[{start:0,end:0}]}function Ht(e,t){let o=0;for(let n=0;n<e.length&&e[n].start<=t;n++)o=n;return o}function
|
|
57
|
-
`),s=0;for(let u=r.length-1;u>=0;u--){let p=r[u];if(s+=Math.max(1,Math.ceil(p.length/n)),s>=t){let
|
|
58
|
-
`),truncated:u>0||
|
|
59
|
-
`)){let s=n+r.length;/^\s*```/.test(r)?t=!t:!t&&r.trim()===""&&s<e.length&&(o=s+1),n=s+1}return o}import{Fragment as
|
|
50
|
+
`),console.log(`${S("\u25CF")} ${ne(s.title)}${s.arg!==null?Y(`${s.sep}(${s.arg})`):""}`),r.set(e.id,{name:e.name,input:e.input}));break}case"article_diff":{let s=Ie(e.oldContent,e.newContent,Math.max(40,(process.stdout.columns??80)-1));if(!s)break;let u=p=>p===1?"":"s";console.log(Y(` \u23BF Added ${s.added} line${u(s.added)}, removed ${s.removed} line${u(s.removed)}`));for(let p of s.lines)console.log(p);s.hidden>0&&console.log(c(` \u2026 +${s.hidden} more diff lines`));break}case"tool_result":{let s=r.get(e.id);if(!s)break;r.delete(e.id);let u=Nt(e.output,4,e.isError?void 0:s.name,s.input),p=e.isError?$:Y;u.lines.forEach((k,f)=>console.log(p((f===0?" \u23BF ":" ")+k))),u.hidden>0&&console.log(c(` \u2026 +${u.hidden} lines`)),e.isError||ll(s.name,s.input,e.output,o);break}case"result":process.stdout.write(`
|
|
51
|
+
`),console.log(c(` (${e.inputTokens}\u2192${e.outputTokens} tokens`+(e.costUsd>0?`, $${e.costUsd<.01?e.costUsd.toFixed(4):e.costUsd.toFixed(2)}`:"")+")")),console.log(""),t.uuid&&(hr(t.uuid),t.titleFired||pl(t,o));break;case"error":console.error(""),console.error($(`agent error: ${e.message}`)),n.kind==="subscription"&&e.kind==="auth"&&ul();break}}import{render as ea}from"ink";import{resolveAuth as ta}from"document360-engine";import{useCallback as z,useEffect as st,useMemo as qt,useRef as G,useState as U}from"react";import{Box as V,Text as v,useApp as hl,useInput as kl,useStdout as wl}from"ink";import{existsSync as yl,readFileSync as Ir,readdirSync as xl}from"node:fs";import{basename as Er,isAbsolute as $l,join as Gt}from"node:path";import{createSession as Dr,loginPkce as bl,toStoredTokens as vl,saveTokens as Cl,getAccessToken as Pl,resolveActiveProfile as ce,resolveProjectId as Tl,getArticle as Sl,decodeJwtClaims as ze,isExpired as be,loadTokens as De,setTitle as Rl,slugify as jl,touchSession as No,upsertSession as Al,generateTitle as Mr,findByName as Il,listSessions as El,renameSession as Dl,suggestNextAction as Ml,readProjectConfig as me,writeProjectConfig as _l,resolveModelSetting as Wo,loadProfileMap as _r,applyPull as Ll,computeSyncStatus as Oo,planPull as Nl,inventoryRepo as Ol,knownEnvironments as Ul,resolveEnvironment as Wl,planPartitions as Fl,trackedArticlePaths as Bl,runPartitioned as Hl,estimateBulkCost as ql,resolveModelForOperation as zl}from"document360-engine";Mt();var Ft=[{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:"convert",usage:"/convert [--scope <folder>] [--run]",desc:"Convert tracked articles to DFM across parallel agents (preview; --scope to limit; --run to start)"},{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 yr(e){if(!e.startsWith("/"))return[];let t=e.slice(1).toLowerCase().split(/\s/)[0]??"";return Ft.filter(o=>o.name.startsWith(t))}function xr(e){return/<[^>]+>/.test(e.replace(/\[[^\]]*\]/g,""))}var fl=/^(?:\d+[.)]|[-*•])\s+/;function $r(e,t,o=4){let n=new Set(t.map(s=>s.toLowerCase())),r=[];for(let s of e.split(`
|
|
52
|
+
`)){let u=s.trim().replace(fl,""),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 gl=/\[Pasted text #\d+ \+\d+ lines?\]/g;function br(e){return e.replace(/\r\n?/g,`
|
|
53
|
+
`)}function vr(e){return e.includes(`
|
|
54
|
+
`)||e.length>200}function Cr(e,t){let o=t.split(`
|
|
55
|
+
`).length;return`[Pasted text #${e} +${o} line${o===1?"":"s"}]`}function Pr(e,t){return e.replace(gl,o=>t.get(o)??o)}function Tr(e){let t=e.match(/\[Pasted text #\d+ \+\d+ lines?\]$/);return t?e.slice(0,-t[0].length):null}function Bt(e,t){let o=Math.max(1,t),n=[],r=0;for(let s of e.split(`
|
|
56
|
+
`)){if(s.length===0)n.push({start:r,end:r});else for(let u=0;u<s.length;u+=o)n.push({start:r+u,end:r+Math.min(u+o,s.length)});r+=s.length+1}return n.length>0?n:[{start:0,end:0}]}function Ht(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=Ht(e,t),r=n+o;if(r<0||r>=e.length)return t;let s=Math.min(t,e[n].end)-e[n].start;return Math.min(e[r].start+s,e[r].end)}function Rr(e,t,o){let n=e[Ht(e,t)];return o==="start"?n.start:n.end}function jr(e,t,o){let n=Math.max(1,o),r=e.split(`
|
|
57
|
+
`),s=0;for(let u=r.length-1;u>=0;u--){let p=r[u];if(s+=Math.max(1,Math.ceil(p.length/n)),s>=t){let k=s-t;return{text:[k>0?p.slice(k*n):p,...r.slice(u+1)].join(`
|
|
58
|
+
`),truncated:u>0||k>0}}}return{text:e,truncated:!1}}function Ar(e){let t=!1,o=0,n=0;for(let r of e.split(`
|
|
59
|
+
`)){let s=n+r.length;/^\s*```/.test(r)?t=!t:!t&&r.trim()===""&&s<e.length&&(o=s+1),n=s+1}return o}import{Fragment as Uo,jsx as C,jsxs as L}from"react/jsx-runtime";var Gl={project:".d360-writer.json",user:"/model",env:"ANTHROPIC_MODEL","claude-settings":"Claude Code settings","claude-default":""};function Yl(e,t,o,n){let r=o.kind==="api"?"API key":o.kind==="subscription"?"subscription":"not configured",s=Wo(e),u=me(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:s.model??"Claude Code default model",modelSource:Gl[s.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 x=ce(e,n);f.profile=x.name,f.apiUrl=x.connection.apiUrl,f.prod=x.production,f.project=x.project.projectId??"(chosen at login)";let T=De(x.name);if(T){let b={...ze(T.idToken)??{},...ze(T.accessToken)??{}},j=b.email??b.preferred_username??"signed in";be(T)?T.refreshToken&&(f.who=j,f.loggedOut=!1,f.sessionHint="session expired \u2014 refreshing\u2026"):(f.who=j,f.loggedOut=!1,f.sessionHint=`session valid until ${new Date(T.expiresAt).toLocaleString(void 0,{hour:"2-digit",minute:"2-digit",day:"2-digit",month:"short"})}`)}}catch{}return f}function Vl(e,t){try{let o=ce(e,t),n=De(o.name);if(!n)return{text:`profile "${o.name}" \u2014 not logged in (/login)`,prod:o.production};let r={...ze(n.idToken)??{},...ze(n.accessToken)??{}},s=r.email??r.preferred_username??"signed in";return be(n)&&!n.refreshToken?{text:`profile "${o.name}" \u2014 session expired (/login)`,prod:o.production}:{text:`${s} \xB7 profile "${o.name}"`,prod:o.production}}catch(o){return{text:o.message.split(".")[0],prod:!1}}}var Lr=["Drafting","Composing","Outlining","Researching","Documenting","Structuring","Polishing","Synthesizing","Curating","Distilling","Weaving","Wrangling","Pondering"],Nr=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"],Xl="Ask me to write or update an article\u2026";function zt({ch:e,dim:t}){let[o,n]=U(!0);return st(()=>{let r=setInterval(()=>n(s=>!s),530);return()=>clearInterval(r)},[]),C(v,{inverse:o,color:t&&!o?"gray":void 0,children:e})}var Jl=/^mcp__document360__d360_(create_article|update_article|fork_article|publish_article)$/;function Or(e){let t=e.match(/^---\r?\n[\s\S]*?\r?\n---\r?\n/);return t?e.slice(t[0].length):e}var Kl=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function Ur(e){try{return xl(e,{withFileTypes:!0}).filter(t=>t.isDirectory()&&!t.name.startsWith(".")).length>6}catch{return!1}}function Ql(e,t){let o=t??[];return o.length===0?["src","api","services","packages","modules"].some(n=>Ur(Gt(e,n))):o.some(n=>!n.includes("/")&&!n.endsWith(".md")&&Ur(Gt(e,n)))}function Zl({startTime:e,chars:t}){let[o,n]=U(0);st(()=>{let k=setInterval(()=>n(f=>f+1),120);return()=>clearInterval(k)},[]);let r=Nr[o%Nr.length],s=Lr[Math.floor(o/16)%Lr.length],u=Math.floor((Date.now()-e)/1e3),p=Math.round(t/4);return L(V,{children:[C(v,{color:W,children:` ${r} ${s}\u2026 `}),C(v,{color:"gray",children:`(${bo(u)} \xB7 ~${p} tokens \xB7 esc to interrupt)`})]})}function Wr({cwd:e,auth:t,profileName:o,version:n}){let{exit:r}=hl(),[s,u]=U(o),[p,k]=U(null),[f,x]=U({text:"",pos:0}),T=f.text,b=z(a=>{x(l=>{let i=typeof a=="function"?a(l.text):a;return{text:i,pos:i.length}})},[]),j=z(a=>{x(l=>({text:l.text.slice(0,l.pos)+a+l.text.slice(l.pos),pos:l.pos+a.length}))},[]),N=z(()=>{x(a=>{if(a.pos===0)return a;let l=a.text.slice(0,a.pos),i=Tr(l)??l.slice(0,-1);return{text:i+a.text.slice(a.pos),pos:i.length}})},[]),[D,B]=U(!1),[F,Z]=U(!1),[re,ge]=U(0),[se,ie]=U(null),[Ge,X]=U([]),it=G(0),[qr,Yt]=U(!1),[zr,Vt]=U(0),lt=G(0),[Ye,Me]=U(0),[_e,at]=U(null),Ho=G(new Map),Gr=G(0),Xt=G([]),ee=G(null);ee.current===null&&(ee.current=Dr({cwd:e,profileName:s,allowProdWrites:!1}));let ve=G({uuid:null,firstPrompt:null,titleFired:!1}),ct=G(new Map),Jt=G(!1),Kt=G([]),he=G([]),[Ce,Pe]=U(null),[ue,Le]=U(null),[ke,Ne]=U(null),[J,Oe]=U(null),[de,Ue]=U(null),[te,Te]=U(null),[K,We]=U(null),[qo,Qt]=U([]),Se=G([]),ut=G(!1),Ve=G(null),dt=G(!1),pt=G(null),[oe,Re]=U(null),[mt,zo]=U(0),[Go,Zt]=U(0),[Yr,Yo]=U(0),eo=qt(()=>{try{return Wo(e).model??"auto"}catch{return null}},[e,Yr]),{stdout:le}=wl(),[,Vr]=U(0),Vo=G(`${le.columns??80}x${le.rows??24}`),we=z(()=>Math.max(20,(le.columns??80)-1),[le]),d=z(a=>{Xt.current.push(a),console.log(vo(a,we()))},[we]);st(()=>{if(d({kind:"banner",info:Yl(e,n,t,s)}),!me(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:
|
|
60
60
|
1. /init \u2014 pick your Document360 environment & scaffold config
|
|
61
61
|
2. /login signs in to that environment
|
|
62
62
|
3. /workspace picks where articles go
|
|
63
|
-
Press 1 to start.`}),
|
|
64
|
-
`)});return;case"exit":case"quit":
|
|
65
|
-
`:""
|
|
66
|
-
|
|
67
|
-
`)})}
|
|
68
|
-
`)});return}if(m==="pull"){let h=k[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 Lo({cwd:e,profileName:s})).entries.filter(O=>O.status==="remote-ahead"&&O.path).map(O=>O.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 S=[];for(let E of w)S.push(await Ll({cwd:e,profileName:s,relPath:E}));ge.current=S,gt();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(!pe(e)){d({kind:"note",tone:"error",text:"No .d360-writer.json here. Run /init first."});return}let m=Nl(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(h=>({...h,checked:h.recommended}))});return}case"audit":case"screenshot":{if(i==="screenshot"&&!k[0]){d({kind:"note",tone:"error",text:"Usage: /screenshot <id>"});return}let h=await(i==="audit"?At:_t)(k,void 0);h.kind==="forward-to-agent"&&h.prompt&&await je(h.prompt,{display:h.display,echoDisplay:!0});return}default:d({kind:"note",tone:"error",text:`Unknown command: /${i} \u2014 type /help.`})}},[e,r,s,gt,d,de,je]),ht=q(a=>{let l=(a??j).trim();if($(""),lt(null),De(0),l.startsWith("/")){let k=h=>h.trim().split(/\s+/).slice(1).join(" "),m=k(l);V(h=>h.filter(w=>w.trim()!==l&&!(m&&k(w)===m)))}if(!l||Qo(l))return;Kt.current.push(l);let i=Cr(l,Fo.current);l.startsWith("/")?Zo(i):je(i,{display:l})},[j,Qo,Zo,je]),en=q(a=>{if(a.length>1){if(a.includes("\x1B"))return;let l=$r(a);if(br(l)){let i=vr(++zr.current,l);Fo.current.set(i,l),R(i)}else R(l);return}R(a)},[R]),We=Math.max(10,Re-6),tn=qt(()=>Bt(g.text,We),[g.text,We]),ro=q(a=>v(l=>({...l,pos:Math.max(0,Math.min(l.text.length,l.pos+a))})),[]),kt=q(a=>v(l=>({...l,pos:Tr(Bt(l.text,We),l.pos,a)})),[We]),Xe=q(a=>v(l=>({...l,pos:Sr(Bt(l.text,We),l.pos,a)})),[We]),Vr=["\x1B[H","\x1B[1~","\x1BOH"],Xr=["\x1B[F","\x1B[4~","\x1BOF"],on=q((a,l)=>l.leftArrow?(ro(-1),!0):l.rightArrow?(ro(1),!0):a&&Vr.includes(a)?(Xe("start"),!0):a&&Xr.includes(a)?(Xe("end"),!0):l.ctrl&&a==="a"?(Xe("start"),!0):l.ctrl&&a==="e"?(Xe("end"),!0):!1,[ro,Xe]);return hl((a,l)=>{if(l.ctrl&&a==="c"){Z.current?.close(),r();return}if(!B){if(M){if(l.escape){if(Ye.current){Ye.current.signal.aborted||(d({kind:"note",tone:"warn",text:"\u238B Stopping the convert run (finishing in-flight articles)\u2026"}),Ye.current.abort());return}ct.current||(ct.current=!0,d({kind:"note",tone:"warn",text:"\u238B Interrupting\u2026"}),Z.current?.interrupt());return}if(l.return){let i=j.trim();if(!i)return;Te.current.push(i),Qt([...Te.current]),$("");return}if(on(a,l))return;if(l.upArrow){kt(-1);return}if(l.downArrow){kt(1);return}if(l.backspace||l.delete){U();return}a&&!l.ctrl&&!l.meta&&en(a);return}if(ve){if(l.upArrow){Ce(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(l.downArrow){Ce(i=>i&&{...i,cursor:Math.min(le.length-1,i.cursor+1)});return}if(a&&/^[1-9]$/.test(a)&&Number(a)<=le.length){Ce(i=>i&&{...i,cursor:Number(a)-1});return}if(l.return){let i=le[ve.cursor];Ce(null);let{lines:k,changed:m,effective:h}=ot(e,i.value??"default");for(let w of k)d({kind:"note",tone:w.startsWith("\u26A0")?"warn":w.startsWith("\u2713")?"ok":"info",text:w});m&&(zo(w=>w+1),Z.current?.setModel(h));return}if(a==="s"){let i=le[ve.cursor];Ce(null),Z.current?.setModel(i.value??void 0),d({kind:"note",tone:"ok",text:`\u2713 Using ${i.label} for this session only (your saved default is unchanged).`});return}if(l.escape){Ce(null);return}return}if(ce){if(l.upArrow){_e(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(l.downArrow){_e(i=>i&&{...i,cursor:Math.min(i.rows.length-1,i.cursor+1)});return}if(a&&/^[1-9]$/.test(a)&&Number(a)<=ce.rows.length){_e(i=>i&&{...i,cursor:Number(a)-1});return}if(l.return||a==="s"){let i=ce.rows[ce.cursor];_e(null),no(i.name,l.return===!0);return}if(l.escape){_e(null);return}return}if(he){if(l.upArrow){Le(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(l.downArrow){Le(i=>i&&{...i,cursor:Math.min(i.rows.length-1,i.cursor+1)});return}if(a&&/^[1-9]$/.test(a)&&Number(a)<=he.rows.length){Le(i=>i&&{...i,cursor:Number(a)-1});return}if(l.return){let i=he.rows[he.cursor].name;if(Le(null),!$n(e,i).created){d({kind:"note",tone:"error",text:"Could not scaffold \u2014 .d360-writer.json already exists."});return}d({kind:"note",tone:"ok",text:`\u2713 Wrote .d360-writer.json (environment "${i}").`});let m=!1;try{let h=Ee(i);m=!!h&&!($e(h)&&!h.refreshToken)}catch{}m?(d({kind:"note",tone:"info",text:`Already signed in to ${i} \u2014 next: pick a workspace.`}),V(["/workspace"])):(d({kind:"note",tone:"info",text:`Next: sign in to Document360 (${i}).`}),V(["/login"])),fe(h=>h+1);return}if(l.escape){Le(null);return}return}if(X){if(l.upArrow){Ne(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(l.downArrow){Ne(i=>i&&{...i,cursor:Math.min(i.rows.length-1,i.cursor+1)});return}if(a&&/^[1-9]$/.test(a)&&Number(a)<=X.rows.length){Ne(i=>i&&{...i,cursor:Number(a)-1});return}if(l.return){let i=X.rows[X.cursor],{profile:k,projectId:m}=X;Ne(null),Ko(k,m,i);return}if(l.escape){Ne(null);return}return}if(J){if(l.upArrow){Oe(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(l.downArrow){Oe(i=>i&&{...i,cursor:Math.min(i.rows.length-1,i.cursor+1)});return}if(a===" "){Oe(i=>i&&{...i,rows:i.rows.map((k,m)=>m===i.cursor?{...k,checked:!k.checked}:k)});return}if(l.return){let i=J.rows.filter(k=>k.checked).map(k=>k.path);if(Oe(null),i.length===0){d({kind:"note",tone:"info",text:"Nothing selected \u2014 scope unchanged."});return}po(e,i),d({kind:"note",tone:"ok",text:`\u2713 Scoped to ${i.length} folder(s) \u2014 written to .d360-writer.json`});for(let k of i)d({kind:"note",tone:"info",text:` ${k}`});d({kind:"note",tone:"info",text:"Next: ask me to analyze these folders and propose a docs structure."});return}if(l.escape){Oe(null);return}return}if(ue){if(l.upArrow){Ue(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(l.downArrow){Ue(i=>i&&{...i,cursor:Math.min(i.rows.length-1,i.cursor+1)});return}if(a&&/^[1-9]$/.test(a)&&Number(a)<=ue.rows.length){Ue(i=>i&&{...i,cursor:Number(a)-1});return}if(l.return){let i=ue.rows[ue.cursor],k=ue.rows.filter(m=>m.path!=="--all").map(m=>m.path);Ue(null),je(i.path==="--all"?et(k):jt(i.path),{display:i.path==="--all"?"/publish --all":`/publish ${i.path}`,echoDisplay:!0});return}if(l.escape){Ue(null);return}return}if(ee){if(l.escape){Pe(null);return}if(l.upArrow){Pe(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(l.downArrow){Pe(i=>i&&{...i,cursor:Math.min(Math.max(0,mt.length-1),i.cursor+1)});return}if(l.return){let i=mt[ee.cursor];if(i){Pe(null);try{d({kind:"preview",name:Ir(i),text:Nr(Ar(Yt(e,i),"utf8"))})}catch(k){d({kind:"note",tone:"error",text:`Could not read ${i}: ${k.message}`})}}return}if(l.backspace||l.delete){Pe(i=>i&&{...i,query:i.query.slice(0,-1),cursor:0});return}if(a&&!l.ctrl&&!l.meta&&a.length===1){Pe(i=>i&&{...i,query:i.query+a,cursor:0});return}return}if(te){if(l.escape){Se(null);return}if(l.upArrow){Se(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(l.downArrow){Se(i=>i&&{...i,cursor:Math.min(Math.max(0,ft.length-1),i.cursor+1)});return}if(l.return){let i=ft[te.cursor];i&&(Se(null),de(i.uuid),be.current={uuid:i.uuid,firstPrompt:i.firstPrompt,titleFired:!0},_o(i.uuid),d({kind:"note",tone:"ok",text:`Resumed "${i.name}".`}));return}if(l.backspace||l.delete){Se(i=>i&&{...i,query:i.query.slice(0,-1),cursor:0});return}if(a&&!l.ctrl&&!l.meta&&a.length===1){Se(i=>i&&{...i,query:i.query+a,cursor:0});return}return}if(l.tab&&!j&&re){$(re),se(null),st.current++;return}if(!j&&ze.length>0&&a&&/^[1-9]$/.test(a)){let i=ze[Number(a)-1];if(i){$(i);return}}if(!on(a,l)){if(Xo){if(l.upArrow){De(i=>Math.max(0,i-1));return}if(l.downArrow){De(i=>Math.min(Ve.length-1,i+1));return}if(l.tab){$("/"+(Ve[Ge]?.name??"")+" "),De(0);return}if(l.return){let i=Ve[Ge];if(i){let k=j.trim().slice(1).split(/\s+/).slice(1).join(" ");if(yr(i.usage)&&!k){$("/"+i.name+" "),De(0);return}ht("/"+i.name+(k?" "+k:""));return}}}else{if(l.upArrow){if(j!==""&&Me===null){kt(-1);return}let i=Kt.current;if(!i.length)return;let k=Me===null?i.length-1:Math.max(0,Me-1);lt(k),$(i[k]??"");return}if(l.downArrow){if(j!==""&&Me===null){kt(1);return}let i=Kt.current;if(Me===null)return;let k=Me+1;k>=i.length?(lt(null),$("")):(lt(k),$(i[k]??""));return}}if(l.return){ht();return}if(l.backspace||l.delete){U();return}if(l.escape){$(""),De(0),se(null),V([]);return}a&&!l.ctrl&&!l.meta&&en(a)}}}),rt(()=>{if(M||B)return;let a=Te.current.shift();a!==void 0&&(Qt([...Te.current]),ht(a))},[M,B,ht]),N(Y,{flexDirection:"column",width:Re,children:[to!==null&&N(Y,{marginTop:1,flexDirection:"column",children:[to.truncated&&C(b,{dimColor:!0,children:"\u2026"}),C(b,{children:to.text})]}),M&&C(Kl,{startTime:it.current,chars:qr}),C(Y,{borderStyle:"round",borderColor:Yo.prod?"yellow":F,borderTop:!0,borderBottom:!0,borderLeft:!1,borderRight:!1,marginTop:1,flexDirection:"column",children:j?tn.map((a,l)=>{let i=g.text.slice(a.start,a.end),k=l===Ht(tn,g.pos),m=Math.min(g.pos,a.end)-a.start;return N(b,{children:[C(b,{color:F,children:l===0?"> ":" "}),k?N(No,{children:[i.slice(0,m),C(zt,{ch:i[m]??" "}),i.slice(m+1)]}):i||" "]},`${l}-${a.start}`)}):N(b,{children:[C(b,{color:F,children:"> "}),re&&!M?N(No,{children:[C(zt,{ch:re[0],dim:!0}),C(b,{color:"gray",children:re.slice(1)}),C(b,{dimColor:!0,children:" (tab)"})]}):Hr?C(zt,{ch:" "}):N(No,{children:[C(zt,{ch:Vo[0],dim:!0}),C(b,{color:"gray",children:Vo.slice(1)})]})]})}),Bo.length>0&&C(Y,{flexDirection:"column",paddingX:1,children:Bo.map((a,l)=>C(b,{color:"gray",children:`\u29D7 queued: ${a}`},`${l}-${a.slice(0,24)}`))}),ve?N(Y,{flexDirection:"column",paddingX:1,children:[C(b,{color:F,bold:!0,children:"Select model"}),C(b,{color:"gray",children:"Your pick becomes your personal default for new sessions (team .d360-writer.json still wins)."}),le.map((a,l)=>N(b,{color:l===ve.cursor?F:void 0,children:[l===ve.cursor?"\u276F ":" ",`${l+1}. ${a.label}${l===ve.current?" \u2714":""}`.padEnd(16),C(b,{color:"gray",children:a.desc})]},a.label)),C(b,{dimColor:!0,children:"enter set as default \xB7 s this session only \xB7 esc cancel"})]}):ce?N(Y,{flexDirection:"column",paddingX:1,children:[C(b,{color:F,bold:!0,children:"Switch connection profile"}),ce.rows.map((a,l)=>N(b,{color:l===ce.cursor?F:void 0,children:[l===ce.cursor?"\u276F ":" ",`${l+1}. ${a.name}${l===ce.current?" \u2714":""}`.padEnd(20),C(b,{color:"gray",children:`${a.env} \xB7 ${a.who??"not signed in"}`}),a.prod?C(b,{color:"yellow",bold:!0,children:" \u26A0 PRODUCTION"}):null]},a.name)),C(b,{dimColor:!0,children:"enter switch (saved as default) \xB7 s this session only \xB7 esc cancel"})]}):he?N(Y,{flexDirection:"column",paddingX:1,children:[C(b,{color:F,bold:!0,children:"Pick your Document360 environment"}),he.rows.map((a,l)=>N(b,{color:l===he.cursor?F:void 0,children:[l===he.cursor?"\u276F ":" ",`${l+1}. ${a.name}`.padEnd(16),C(b,{color:"gray",children:a.apiUrl})]},a.name)),C(b,{dimColor:!0,children:"enter select \xB7 esc cancel"})]}):X?N(Y,{flexDirection:"column",paddingX:1,children:[C(b,{color:F,bold:!0,children:"Switch workspace"}),C(b,{dimColor:!0,children:`environment ${X.environment} \xB7 project ${X.projectId.slice(0,8)}\u2026`}),X.rows.map((a,l)=>N(b,{color:l===X.cursor?F:void 0,children:[l===X.cursor?"\u276F ":" ",`${l+1}. ${a.name}${l===X.current?" \u2714":""}`.padEnd(30),C(b,{color:"gray",children:a.type??""})]},a.id)),C(b,{dimColor:!0,children:"enter switch \xB7 esc cancel"})]}):J?(()=>{let l=Math.min(Math.max(0,J.cursor-Math.floor(7)),Math.max(0,J.rows.length-14)),i=J.rows.slice(l,l+14),k=J.rows.filter(m=>m.checked).length;return N(Y,{flexDirection:"column",paddingX:1,children:[C(b,{color:F,bold:!0,children:`Which folders back the user docs? (${k} selected of ${J.rows.length})`}),l>0?C(b,{dimColor:!0,children:` \u2191 ${l} more`}):null,i.map((m,h)=>{let w=l+h;return N(b,{color:w===J.cursor?F:void 0,children:[w===J.cursor?"\u276F ":" ",m.checked?"\u25C9 ":"\u25CB ",m.path.padEnd(Math.min(48,Re-34)),C(b,{color:"gray",children:It(m)})]},m.path)}),l+14<J.rows.length?C(b,{dimColor:!0,children:` \u2193 ${J.rows.length-l-14} more`}):null,C(b,{dimColor:!0,children:"space toggle \xB7 enter save \xB7 esc cancel"})]})})():ue?N(Y,{flexDirection:"column",paddingX:1,children:[C(b,{color:F,bold:!0,children:"Publish which article?"}),ue.rows.map((a,l)=>N(b,{color:l===ue.cursor?F:void 0,children:[l===ue.cursor?"\u276F ":" ",`${l+1}. ${a.path}`.padEnd(Math.min(56,Re-30)),C(b,{color:"gray",children:a.label})]},a.path)),C(b,{dimColor:!0,children:"enter publish (draft) \xB7 esc cancel"})]}):ee?N(Y,{flexDirection:"column",paddingX:1,children:[C(b,{color:F,bold:!0,children:`Preview article${ee.query?` \u2014 filter: ${ee.query}`:" (type to filter)"}`}),mt.length===0?C(b,{color:"gray",children:"no articles match"}):mt.map((a,l)=>N(b,{color:l===ee.cursor?F:void 0,children:[l===ee.cursor?"\u276F ":" ",a]},a)),C(b,{dimColor:!0,children:"enter preview \xB7 esc cancel"})]}):te?N(Y,{flexDirection:"column",paddingX:1,children:[C(b,{color:F,bold:!0,children:`Resume session${te.query?` \u2014 filter: ${te.query}`:" (type to filter)"}`}),ft.length===0?C(b,{color:"gray",children:"no sessions match"}):ft.map((a,l)=>N(b,{color:l===te.cursor?F:void 0,children:[l===te.cursor?"\u276F ":" ",a.name.slice(0,28).padEnd(30),C(b,{color:l===te.cursor?F:"gray",children:a.firstPrompt.slice(0,Math.max(10,Re-40))})]},a.uuid)),C(b,{dimColor:!0,children:"enter resume \xB7 esc cancel"})]}):Xo?C(Y,{flexDirection:"column",children:Ve.map((a,l)=>N(b,{color:l===Ge?F:void 0,children:[l===Ge?"\u276F ":" ",a.usage.padEnd(22)," ",C(b,{color:l===Ge?F:"gray",children:a.name==="model"&&eo?`${a.desc} (currently ${eo})`:a.desc})]},a.name))}):!j&&ze.length>0?N(Y,{flexDirection:"column",paddingX:1,children:[ze.map((a,l)=>N(b,{children:[C(b,{color:F,children:l+1})," ",a.slice(0,Math.max(20,Re-5))]},a)),C(b,{dimColor:!0,children:`press 1-${ze.length} to fill the command \xB7 esc dismiss`})]}):C(Y,{paddingX:1,children:N(b,{color:"gray",children:[Yo.prod?"\u26A0 PRODUCTION \xB7 ":"",`/help \xB7 ${eo??"model n/a"}${pt>0?` \xB7 ${pt<1e3?`${pt} tokens`:`${(pt/1e3).toFixed(1)}k tokens`}`:""}${qo>0?` \xB7 ${Ie(qo)}`:""} \xB7 \u2191 history \xB7 ctrl+c exit`]})})]})}_();import{jsx as ea}from"react/jsx-runtime";async function Wr(e=process.cwd(),t="auto",o,n="0.0.0"){let r=Zl(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:s}=Ql(ea(Or,{cwd:e,auth:r,profileName:o,version:n}));await s(),process.stdout.write(`
|
|
69
|
-
`),process.exit(0)}var ra=oa(import.meta.url),Fr=ra("../package.json"),me=new ta;function Uo(e){e.env&&(console.error("\u2717 --env was replaced by --profile (connection profiles). Use: --profile <name>"),process.exit(2))}me.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=>{Uo(e),await vt({profile:e.profile,manual:e.manual})});me.command("logout").description("Remove the stored Document360 session").option("--profile <name>","Connection profile").option("--env <name>",!1).action(async e=>{Uo(e),await mn({profile:e.profile})});me.command("whoami").description("Show the current Document360 identity (refreshes if expired)").option("--profile <name>","Connection profile").option("--env <name>",!1).action(async e=>{Uo(e),await pn({profile:e.profile})});var Oo=me.command("profile").description("Manage connection profiles for the current repo");Oo.command("list",{isDefault:!0}).description("List profiles (\u25CF = default)").action(()=>Ct(process.cwd()));Oo.command("use <name>").description("Set the default profile for this repo").action(e=>Pt(process.cwd(),e));Oo.command("show [name]").description("Print the resolved profile (connection + project)").action(e=>Tt(process.cwd(),e));var Br=me.command("workspace").description("Choose the Document360 workspace for this repo (active profile's project)");Br.command("select",{isDefault:!0}).description("Interactively pick the workspace (lists in non-TTY)").option("--profile <name>","Connection profile").action(e=>Be(process.cwd(),e.profile));Br.command("use <name>").description("Set the workspace by name (scriptable)").option("--profile <name>","Connection profile").action(async(e,t)=>{process.exitCode=await ln(process.cwd(),e,t.profile)});me.command("logs").description("Show the Document360 API log files (send these to support when reporting a problem)").action(()=>gn());me.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(()=>(Mt(),rr)),o=await t(process.cwd());for(let n of e(o))console.log(n);process.exitCode=o.some(n=>n.level==="fail")?1:0});me.name("d360-writer").description("Standalone documentation agent CLI. Reads your code, writes your docs.").version(Fr.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(na.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 hn(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 kr(e.cwd,e.auth,e.profile):await Wr(e.cwd,e.auth,e.profile,Fr.version)});me.parseAsync(process.argv).catch(e=>{console.error(""),console.error(`\u2717 ${e.message}`),process.exit(1)});
|
|
63
|
+
Press 1 to start.`}),X(["/init"]);return}try{let a=ce(e,s),l=De(a.name);l&&be(l)&&l.refreshToken?Pl({profile:a.name,connection:a.connection}).then(()=>{d({kind:"note",tone:"ok",text:"\u2713 Document360 session refreshed."}),ge(i=>i+1)}).catch(()=>{d({kind:"note",tone:"warn",text:"Document360 session refresh failed \u2014 do you want to log in now? (press 1)"}),X(["/login"])}):(!l||be(l))&&(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=me(e),l=ce(e,s),i=De(l.name);a&&i&&!be(i)&&Ql(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{}},[]),st(()=>{let a=null,l=null,i=()=>{a&&clearTimeout(a),a=setTimeout(()=>{a=null;let h=`${le.columns??80}x${le.rows??24}`;h!==Vo.current&&(Vo.current=h,Vr(m=>m+1),l&&clearTimeout(l),l=setTimeout(()=>{l=null,console.log("\x1B[?2026h\x1B[H\x1B[2J"+zn(Xt.current,we())+"\x1B[?2026l")},80))},400)};return le.on("resize",i),()=>{a&&clearTimeout(a),l&&clearTimeout(l),le.off("resize",i)}},[le,we]);let je=Math.max(20,(le.columns??80)-1),Xo=qt(()=>Vl(e,s),[e,s,re]),to=qt(()=>{if(!me(e))return{text:"Press 1 to set up this repo, or /help\u2026",isSetup:!0};try{let a=ce(e,s),l=De(a.name);if(!(!!l&&!(be(l)&&!l.refreshToken)))return{text:`Press 1 to sign in to Document360 (profile "${a.name}")\u2026`,isSetup:!0};if(!a.project.workspaceId)return{text:"Press 1 to pick a workspace\u2026",isSetup:!0}}catch{}return{text:Xl,isSetup:!1}},[e,s,re]),Xe=yr(T),Jo=Xe.length>0&&!D,oo=p!==null?jr(p,8,je):null,ft=te?te.paths.filter(a=>!te.query||a.toLowerCase().includes(te.query.toLowerCase())).slice(0,8):[],gt=oe?oe.sessions.filter(a=>{let l=oe.query.toLowerCase();return!l||a.name.toLowerCase().includes(l)||a.firstPrompt.toLowerCase().includes(l)}).slice(0,8):[],pe=z((a,l)=>{ee.current?.close(),ee.current=Dr({cwd:e,resume:a,profileName:l??s,allowProdWrites:Jt.current}),a||(ve.current={uuid:null,firstPrompt:null,titleFired:!1}),zo(0),Zt(0)},[e,s]),Ko=z((a,l,i)=>{if(Jl.test(a))try{let h=ce(e,s),m=typeof l.project_id=="string"&&l.project_id||h.project.projectId,g=Ut(l,i),w=[],R=Wt(i);a.endsWith("publish_article")&&R&&w.push(`Live: ${R}`),g&&m&&w.push(`Preview: ${Ot(h.connection.portalUrl,m,g,h.project.languageCode??"en")}`),w.length>0&&d({kind:"link",lines:w})}catch{}},[e,s,d]),Ae=z(async(a,l)=>{Yt(!0),ie(null),X([]);let i=++it.current;d({kind:"user",text:l?.echoDisplay&&l.display?l.display:a});let h=ve.current;h.firstPrompt||(h.firstPrompt=l?.display??a),lt.current=Date.now(),Vt(0),B(!0),ct.current.clear();let m="",g="",w=null,R=()=>{w||(w=setTimeout(()=>{w=null,k(g.length>0?g:null)},60))},I=()=>{w&&clearTimeout(w),w=null,k(null)},O=()=>{if(g.trim()){let P=g.trimEnd();d({kind:"assistant",text:P})}g="",I()};try{for await(let P of ee.current.send(a))if(P.type==="session"){if(!h.uuid){h.uuid=P.sessionId;let A=new Date().toISOString();Al({uuid:P.sessionId,name:jl(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=Ar(g);if(A>0){let H=g.slice(0,A).trimEnd();H&&d({kind:"assistant",text:H}),g=g.slice(A)}R(),Vt(H=>H+P.delta.length)}else if(P.type==="tool"){let A=Lt(P.name,P.input);A&&(O(),d({kind:"tool",title:A.title,sep:A.sep,arg:A.arg}),ct.current.set(P.id,{name:P.name,input:P.input}))}else if(P.type==="article_diff"){let A=Ie(P.oldContent,P.newContent,we());A&&(O(),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)&&(dt.current=!0);let A=ct.current.get(P.id);if(A){ct.current.delete(P.id),O();let H=Nt(P.output,4,P.isError?void 0:A.name,A.input);d({kind:"tool-result",lines:H.lines,hidden:H.hidden,isError:P.isError}),P.isError||Ko(A.name,A.input,P.output)}}else if(P.type==="result"){O(),zo(H=>H+P.outputTokens),Zt(H=>H+P.costUsd),d({kind:"done",seconds:Math.round((Date.now()-lt.current)/1e3),tokens:P.outputTokens,costUsd:P.costUsd,ok:P.ok});let A=P.ok?$r(m,Ft.map(H=>H.name)):[];if(A.length>0?X(A):P.ok&&m.trim()&&Ml(a,m,e).then(H=>{H&&it.current===i&&ie(H)}).catch(()=>{}),h.uuid&&(No(h.uuid),!h.titleFired)){h.titleFired=!0;let H=h.uuid,q=h.firstPrompt;q&&Mr(q,e).then(Be=>Be&&Rl(H,Be)).catch(()=>{})}}else P.type==="error"&&(O(),P.kind==="auth"&&(dt.current=!0),d({kind:"note",text:`agent error: ${P.message}`,tone:"error"}))}finally{B(!1),I(),dt.current&&(dt.current=!1,pt.current=l?.display??a,X(["/login"])),ut.current&&(ut.current=!1,Se.current.length>0&&(d({kind:"note",tone:"info",text:`(${Se.current.length} queued message(s) discarded)`}),Se.current=[],Qt([])),d({kind:"note",tone:"warn",text:"Interrupted. What do you want to do next?"}))}},[e,d,Ko,we]),no=z(a=>{let l=De(a);if(!l||be(l)&&!l.refreshToken)return null;let i={...ze(l.idToken)??{},...ze(l.accessToken)??{}};return i.email??i.preferred_username??"signed in"},[]),ro=z((a,l)=>{if(l){let i=me(e);i&&(i.defaultProfile=a,_l(i,e))}u(a),pe(void 0,a),d({kind:"note",tone:"ok",text:`\u2713 Switched to profile "${a}"${l?" (saved as default)":" (this session only)"} \u2014 agent restarted.`}),no(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"])),ge(i=>i+1)},[e,d,pe,no]),Qo=z((a,l,i)=>{xt(e,a,l,i.id),d({kind:"note",tone:"ok",text:`Switched to workspace "${i.name??i.id}" (agent restarted).`}),pe(),_r(e,a)||(d({kind:"note",tone:"info",text:"Setup complete. Press tab to start with a docs analysis."}),ie("analyze this repo and propose a docs structure"))},[e,d,pe]),ht=z(()=>{let a=he.current[0];if(!a)return;d({kind:"note",tone:"info",text:`\u25CF ${a.title} (${a.path})`});for(let i of a.notes)d({kind:"note",tone:"warn",text:`\u26A0 ${i}`});a.overwritesLocalChanges&&d({kind:"note",tone:"warn",text:"\u26A0 This OVERWRITES local edits made since the last sync."});let l=Ie(a.oldContent,a.newContent,we());d(l?{kind:"diff",added:l.added,removed:l.removed,lines:l.lines,hidden:l.hidden}:{kind:"note",tone:"info",text:"Local file already matches the remote content \u2014 applying only advances the sync base."}),d({kind:"note",tone:"info",text:`Write ${a.path}? (y/n \u2014 anything else cancels)`})},[d,we]),Zo=z(a=>{if(he.current.length===0)return!1;let l=a.trim().toLowerCase();if(l==="y"||l==="yes"){let i=he.current.shift();try{Ll({cwd:e,profileName:s},i),d({kind:"note",tone:"ok",text:`\u2713 Pulled ${i.path} (sync base advanced).`}),he.current.length===0&&X(h=>h.length>0?h:["/sync"])}catch(h){d({kind:"note",tone:"error",text:`Pull failed: ${h.message}`})}}else if(l==="n"||l==="no"){let i=he.current.shift();d({kind:"note",tone:"info",text:`Skipped ${i.path}.`})}else{let i=he.current.length;return he.current=[],d({kind:"note",tone:"info",text:`Pull cancelled (${i} article(s) left untouched).`}),!0}return ht(),!0},[e,s,ht,d]),en=z(async a=>{let l=a.slice(1).trim().split(/\s+/),i=(l[0]??"").toLowerCase(),h=l.slice(1);switch(Yt(!0),i){case"help":d({kind:"note",tone:"info",text:Ft.map(m=>` ${m.usage.padEnd(22)} ${m.desc}`).join(`
|
|
64
|
+
`)});return;case"exit":case"quit":ee.current?.close(),r();return;case"clear":pe(),Xt.current=[],Yt(!1),ie(null),it.current++,d({kind:"note",tone:"info",text:"Conversation reset (the previous session is still resumable via /resume)."});return;case"login":{let m;try{m=ce(e,s)}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":""}`}),Z(!0);try{let g=await bl(m.connection,{promptForRedirect:()=>Promise.reject(new Error("Manual login is CLI-only. Run: d360-writer login --manual"))},R=>d({kind:"note",tone:"info",text:R})),w=vl(m.name,g);Cl(w),ao(w,m.name,R=>d({kind:"note",tone:"info",text:R})),d({kind:"note",tone:"ok",text:`\u2713 Logged in to "${m.name}" as ${bt(w)}`}),m.project.workspaceId||(d({kind:"note",tone:"info",text:"Next: pick the workspace your articles publish to."}),X(["/workspace"])),pt.current&&(ie(pt.current),pt.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{Z(!1),ge(g=>g+1)}return}case"allow-prod":{let m=!1;try{m=ce(e,s).production}catch{}if(!m){d({kind:"note",tone:"info",text:"Current profile is not production \u2014 writes are already allowed."});return}Jt.current=!0,pe(),d({kind:"note",tone:"warn",text:"\u26A0 Production writes authorized for this session."});return}case"rename":{let m=h.join(" ").trim(),g=ve.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 w=ve.current.firstPrompt??"";Mr(w,e).then(R=>{R?(ie(`/rename ${R}`),d({kind:"note",tone:"info",text:`Suggestion: "${R}" \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}Dl(g,m),d({kind:"note",tone:"ok",text:`Session renamed to "${m}".`});return}case"profile":{let m=h[0],g=me(e);if(!m){let w=Object.entries(g?.profiles??{});if(w.length===0){d({kind:"note",tone:"info",text:"No profiles. Run /init first."});return}let R=w.map(([P,A])=>({name:P,env:A.connection?.environment??"custom",prod:A.production===!0,who:no(P)})),I=s??g?.defaultProfile,O=Math.max(0,R.findIndex(P=>P.name===I));Le({cursor:O,current:O,rows:R});return}if(m==="add"){let w=Io(e,h[1],h[2]);if(w){d({kind:"note",tone:"error",text:w});return}d({kind:"note",tone:"ok",text:`\u2713 Profile "${h[1]}" created (environment: ${h[2]??h[1]}).`}),ro(h[1],!1);return}if(!g?.profiles?.[m]){d({kind:"note",tone:"error",text:`Unknown profile "${m}". Create it: /profile add ${m} <environment>`});return}ro(m,!0);return}case"doctor":await rt(h,{cwd:e});return;case"mcp":await St(h);return;case"init":{if(me(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=Ul().map(g=>({name:g,apiUrl:Wl(g).apiUrl}));Ne({cursor:0,rows:m});return}case"resume":{let m=h.join(" ").trim(),g=El(e).filter(R=>R.uuid!==ve.current.uuid);if(!m){if(!g.length){d({kind:"note",tone:"info",text:"No saved sessions for this repo yet."});return}Re({query:"",cursor:0,sessions:g});return}let w=Il(e,m);if(!w){d({kind:"note",tone:"error",text:`No session matches "${m}".`});return}pe(w.uuid),ve.current={uuid:w.uuid,firstPrompt:w.firstPrompt,titleFired:!0},No(w.uuid),d({kind:"note",tone:"ok",text:`Resumed "${w.name}".`});return}case"workspace":{let m=h.join(" ").trim(),g;try{g=await yt(e,s)}catch(R){d({kind:"note",tone:"error",text:`Could not list workspaces: ${R.message}`});return}if(!m){let R=g.workspaces.map(O=>({id:O.id,name:O.name??O.id,type:O.workspace_type}));if(R.length===0){d({kind:"note",tone:"info",text:"No workspaces in this project."});return}let I=Math.max(0,R.findIndex(O=>O.id===g.current));Oe({cursor:I,current:I,rows:R,profile:g.profile,projectId:g.projectId,environment:g.environment});return}let w=lo(g.workspaces,m);if(!w){d({kind:"note",tone:"error",text:`No workspace matches "${m}".`});return}Qo(g.profile,g.projectId,w);return}case"publish":{if(h[0]&&h[0]!=="--all"){await Ae(jt(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 Oo({cwd:e,profileName:s}),w=Rt(g.entries);if(w.length===0){d({kind:"note",tone:"ok",text:"\u2713 Nothing is ahead of Document360 \u2014 no publish candidates."});let I=g.counts["unknown-base"]??0;I>0&&d({kind:"note",tone:"info",text:`(${I} article(s) have no sync base yet \u2014 publish those by path if needed.)`});return}if(m){await Ae(tt(w.map(I=>I.path)),{display:"/publish --all",echoDisplay:!0});return}let R=w.length>1?[{path:"--all",label:`publish all ${w.length} candidates in one run`},...w]:w;Ue({cursor:0,rows:R})}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 w=[];try{w=Object.keys(_r(e,ce(e,s).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}Te({query:"",cursor:0,paths:w});return}let g=$l(m)?m:Gt(e,m);if(yl(g)){try{d({kind:"preview",name:Er(g),text:Or(Ir(g,"utf8"))})}catch(w){d({kind:"note",tone:"error",text:`Could not read ${g}: ${w.message}`})}return}if(Kl.test(m)){try{let w=ce(e,s),R={profile:w.name,connection:w.connection},I=w.project.projectId??Tl(R),O=await Sl(R,I,m);d({kind:"preview",name:O.title??m,text:O.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=h[0]?.trim();if(!m){let I=Dt(Wo(e));Pe({cursor:I,current:I});return}let{lines:g,changed:w,effective:R}=nt(e,m);for(let I of g)d({kind:"note",tone:I.startsWith("\u26A0")?"warn":I.startsWith("\u2713")?"ok":"info",text:I});w&&(Yo(I=>I+1),ee.current?.setModel(R));return}case"convert":{if(!me(e)){d({kind:"note",tone:"error",text:"No .d360-writer.json here. Run /init first."});return}let{scope:m,run:g}=Po(h),w=Bl(e,s);if(w.length===0){d({kind:"note",tone:"error",text:"No tracked articles in d360-category-map.json. Publish some first (/publish), then /convert."});return}let R=To(w,m);if(R.length===0){d({kind:"note",tone:"error",text:`No tracked articles under "${m}". (${w.length} are tracked overall.)`});return}let I=Fl(R),O=3,P=`/convert${m?` --scope ${m}`:""} --run`,A=zl(e,"light");if(!g){let q=ql({files:So(e,R),op:"convert",model:A.model}),Be=m?`Scope: ${m} (${R.length} of ${w.length} tracked)
|
|
65
|
+
`:"",io=`
|
|
66
|
+
Model: ${A.model}${A.forced?" (forced)":" \u2014 mechanical work; /model to override"}`;d({kind:"note",tone:"info",text:Be+jo(I,q,O).join(`
|
|
67
|
+
`)+io}),X([P]);return}lt.current=Date.now(),Vt(0),B(!0);let H=new AbortController;Ve.current=H,d({kind:"note",tone:"info",text:`Converting ${R.length} articles across ${I.length} partitions (\u2264${O} agents at once) on ${A.model}\u2026 (esc to stop)`});try{for await(let q of Hl({cwd:e,partitions:I,promptFor:Ro,concurrency:O,profileName:s,allowProdWrites:Jt.current,model:A.model,signal:H.signal}))if(q.type==="partition_status")q.status==="running"?d({kind:"note",tone:"info",text:` \u25B8 ${q.label} \u2014 converting\u2026`}):q.status==="done"?d({kind:"note",tone:"ok",text:` \u2713 ${q.label}`}):d({kind:"note",tone:"error",text:` \u2717 ${q.label}`});else if(q.type==="run_done"){Zt(io=>io+q.totalCostUsd);let Be=q.aborted?"Stopped. ":"";d({kind:"note",tone:q.aborted?"warn":q.ok?"ok":"warn",text:Be+Ao(q.results,q.totalCostUsd).join(`
|
|
68
|
+
`)})}}catch(q){d({kind:"note",tone:"error",text:`Convert run failed: ${q.message}`})}finally{Ve.current=null,B(!1)}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 Oo({cwd:e,profileName:s});d({kind:"note",tone:"info",text:Et(g).join(`
|
|
69
|
+
`)});return}if(m==="pull"){let g=h[1];if(!g){d({kind:"note",tone:"error",text:"Usage: /sync pull <article-path> | --all"});return}let w;if(g==="--all"){if(d({kind:"note",tone:"info",text:"Checking Document360 for drift\u2026"}),w=(await Oo({cwd:e,profileName:s})).entries.filter(O=>O.status==="remote-ahead"&&O.path).map(O=>O.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=[g.replace(/\\/g,"/")];let R=[];for(let I of w)R.push(await Nl({cwd:e,profileName:s,relPath:I}));he.current=R,ht();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(!me(e)){d({kind:"note",tone:"error",text:"No .d360-writer.json here. Run /init first."});return}let m=Ol(e);if(m.length===0){d({kind:"note",tone:"info",text:'No candidate source folders found. Set "authoritativeSourceFiles" in .d360-writer.json manually.'});return}We({cursor:0,rows:m.map(g=>({...g,checked:g.recommended}))});return}case"audit":case"screenshot":{if(i==="screenshot"&&!h[0]){d({kind:"note",tone:"error",text:"Usage: /screenshot <id>"});return}let g=await(i==="audit"?At:_t)(h,void 0);g.kind==="forward-to-agent"&&g.prompt&&await Ae(g.prompt,{display:g.display,echoDisplay:!0});return}default:d({kind:"note",tone:"error",text:`Unknown command: /${i} \u2014 type /help.`})}},[e,r,s,ht,d,pe,Ae]),kt=z(a=>{let l=(a??T).trim();if(b(""),at(null),Me(0),l.startsWith("/")){let h=g=>g.trim().split(/\s+/).slice(1).join(" "),m=h(l);X(g=>g.filter(w=>w.trim()!==l&&!(m&&h(w)===m)))}if(!l||Zo(l))return;Kt.current.push(l);let i=Pr(l,Ho.current);l.startsWith("/")?en(i):Ae(i,{display:l})},[T,Zo,en,Ae]),tn=z(a=>{if(a.length>1){if(a.includes("\x1B"))return;let l=br(a);if(vr(l)){let i=Cr(++Gr.current,l);Ho.current.set(i,l),j(i)}else j(l);return}j(a)},[j]),Fe=Math.max(10,je-6),on=qt(()=>Bt(f.text,Fe),[f.text,Fe]),so=z(a=>x(l=>({...l,pos:Math.max(0,Math.min(l.text.length,l.pos+a))})),[]),wt=z(a=>x(l=>({...l,pos:Sr(Bt(l.text,Fe),l.pos,a)})),[Fe]),Je=z(a=>x(l=>({...l,pos:Rr(Bt(l.text,Fe),l.pos,a)})),[Fe]),Xr=["\x1B[H","\x1B[1~","\x1BOH"],Jr=["\x1B[F","\x1B[4~","\x1BOF"],nn=z((a,l)=>l.leftArrow?(so(-1),!0):l.rightArrow?(so(1),!0):a&&Xr.includes(a)?(Je("start"),!0):a&&Jr.includes(a)?(Je("end"),!0):l.ctrl&&a==="a"?(Je("start"),!0):l.ctrl&&a==="e"?(Je("end"),!0):!1,[so,Je]);return kl((a,l)=>{if(l.ctrl&&a==="c"){ee.current?.close(),r();return}if(!F){if(D){if(l.escape){if(Ve.current){Ve.current.signal.aborted||(d({kind:"note",tone:"warn",text:"\u238B Stopping the convert run (finishing in-flight articles)\u2026"}),Ve.current.abort());return}ut.current||(ut.current=!0,d({kind:"note",tone:"warn",text:"\u238B Interrupting\u2026"}),ee.current?.interrupt());return}if(l.return){let i=T.trim();if(!i)return;Se.current.push(i),Qt([...Se.current]),b("");return}if(nn(a,l))return;if(l.upArrow){wt(-1);return}if(l.downArrow){wt(1);return}if(l.backspace||l.delete){N();return}a&&!l.ctrl&&!l.meta&&tn(a);return}if(Ce){if(l.upArrow){Pe(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(l.downArrow){Pe(i=>i&&{...i,cursor:Math.min(ae.length-1,i.cursor+1)});return}if(a&&/^[1-9]$/.test(a)&&Number(a)<=ae.length){Pe(i=>i&&{...i,cursor:Number(a)-1});return}if(l.return){let i=ae[Ce.cursor];Pe(null);let{lines:h,changed:m,effective:g}=nt(e,i.value??"default");for(let w of h)d({kind:"note",tone:w.startsWith("\u26A0")?"warn":w.startsWith("\u2713")?"ok":"info",text:w});m&&(Yo(w=>w+1),ee.current?.setModel(g));return}if(a==="s"){let i=ae[Ce.cursor];Pe(null),ee.current?.setModel(i.value??void 0),d({kind:"note",tone:"ok",text:`\u2713 Using ${i.label} for this session only (your saved default is unchanged).`});return}if(l.escape){Pe(null);return}return}if(ue){if(l.upArrow){Le(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(l.downArrow){Le(i=>i&&{...i,cursor:Math.min(i.rows.length-1,i.cursor+1)});return}if(a&&/^[1-9]$/.test(a)&&Number(a)<=ue.rows.length){Le(i=>i&&{...i,cursor:Number(a)-1});return}if(l.return||a==="s"){let i=ue.rows[ue.cursor];Le(null),ro(i.name,l.return===!0);return}if(l.escape){Le(null);return}return}if(ke){if(l.upArrow){Ne(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(l.downArrow){Ne(i=>i&&{...i,cursor:Math.min(i.rows.length-1,i.cursor+1)});return}if(a&&/^[1-9]$/.test(a)&&Number(a)<=ke.rows.length){Ne(i=>i&&{...i,cursor:Number(a)-1});return}if(l.return){let i=ke.rows[ke.cursor].name;if(Ne(null),!bn(e,i).created){d({kind:"note",tone:"error",text:"Could not scaffold \u2014 .d360-writer.json already exists."});return}d({kind:"note",tone:"ok",text:`\u2713 Wrote .d360-writer.json (environment "${i}").`});let m=!1;try{let g=De(i);m=!!g&&!(be(g)&&!g.refreshToken)}catch{}m?(d({kind:"note",tone:"info",text:`Already signed in to ${i} \u2014 next: pick a workspace.`}),X(["/workspace"])):(d({kind:"note",tone:"info",text:`Next: sign in to Document360 (${i}).`}),X(["/login"])),ge(g=>g+1);return}if(l.escape){Ne(null);return}return}if(J){if(l.upArrow){Oe(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(l.downArrow){Oe(i=>i&&{...i,cursor:Math.min(i.rows.length-1,i.cursor+1)});return}if(a&&/^[1-9]$/.test(a)&&Number(a)<=J.rows.length){Oe(i=>i&&{...i,cursor:Number(a)-1});return}if(l.return){let i=J.rows[J.cursor],{profile:h,projectId:m}=J;Oe(null),Qo(h,m,i);return}if(l.escape){Oe(null);return}return}if(K){if(l.upArrow){We(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(l.downArrow){We(i=>i&&{...i,cursor:Math.min(i.rows.length-1,i.cursor+1)});return}if(a===" "){We(i=>i&&{...i,rows:i.rows.map((h,m)=>m===i.cursor?{...h,checked:!h.checked}:h)});return}if(l.return){let i=K.rows.filter(h=>h.checked).map(h=>h.path);if(We(null),i.length===0){d({kind:"note",tone:"info",text:"Nothing selected \u2014 scope unchanged."});return}fo(e,i),d({kind:"note",tone:"ok",text:`\u2713 Scoped to ${i.length} folder(s) \u2014 written to .d360-writer.json`});for(let h of i)d({kind:"note",tone:"info",text:` ${h}`});d({kind:"note",tone:"info",text:"Next: ask me to analyze these folders and propose a docs structure."});return}if(l.escape){We(null);return}return}if(de){if(l.upArrow){Ue(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(l.downArrow){Ue(i=>i&&{...i,cursor:Math.min(i.rows.length-1,i.cursor+1)});return}if(a&&/^[1-9]$/.test(a)&&Number(a)<=de.rows.length){Ue(i=>i&&{...i,cursor:Number(a)-1});return}if(l.return){let i=de.rows[de.cursor],h=de.rows.filter(m=>m.path!=="--all").map(m=>m.path);Ue(null),Ae(i.path==="--all"?tt(h):jt(i.path),{display:i.path==="--all"?"/publish --all":`/publish ${i.path}`,echoDisplay:!0});return}if(l.escape){Ue(null);return}return}if(te){if(l.escape){Te(null);return}if(l.upArrow){Te(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(l.downArrow){Te(i=>i&&{...i,cursor:Math.min(Math.max(0,ft.length-1),i.cursor+1)});return}if(l.return){let i=ft[te.cursor];if(i){Te(null);try{d({kind:"preview",name:Er(i),text:Or(Ir(Gt(e,i),"utf8"))})}catch(h){d({kind:"note",tone:"error",text:`Could not read ${i}: ${h.message}`})}}return}if(l.backspace||l.delete){Te(i=>i&&{...i,query:i.query.slice(0,-1),cursor:0});return}if(a&&!l.ctrl&&!l.meta&&a.length===1){Te(i=>i&&{...i,query:i.query+a,cursor:0});return}return}if(oe){if(l.escape){Re(null);return}if(l.upArrow){Re(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(l.downArrow){Re(i=>i&&{...i,cursor:Math.min(Math.max(0,gt.length-1),i.cursor+1)});return}if(l.return){let i=gt[oe.cursor];i&&(Re(null),pe(i.uuid),ve.current={uuid:i.uuid,firstPrompt:i.firstPrompt,titleFired:!0},No(i.uuid),d({kind:"note",tone:"ok",text:`Resumed "${i.name}".`}));return}if(l.backspace||l.delete){Re(i=>i&&{...i,query:i.query.slice(0,-1),cursor:0});return}if(a&&!l.ctrl&&!l.meta&&a.length===1){Re(i=>i&&{...i,query:i.query+a,cursor:0});return}return}if(l.tab&&!T&&se){b(se),ie(null),it.current++;return}if(!T&&Ge.length>0&&a&&/^[1-9]$/.test(a)){let i=Ge[Number(a)-1];if(i){b(i);return}}if(!nn(a,l)){if(Jo){if(l.upArrow){Me(i=>Math.max(0,i-1));return}if(l.downArrow){Me(i=>Math.min(Xe.length-1,i+1));return}if(l.tab){b("/"+(Xe[Ye]?.name??"")+" "),Me(0);return}if(l.return){let i=Xe[Ye];if(i){let h=T.trim().slice(1).split(/\s+/).slice(1).join(" ");if(xr(i.usage)&&!h){b("/"+i.name+" "),Me(0);return}kt("/"+i.name+(h?" "+h:""));return}}}else{if(l.upArrow){if(T!==""&&_e===null){wt(-1);return}let i=Kt.current;if(!i.length)return;let h=_e===null?i.length-1:Math.max(0,_e-1);at(h),b(i[h]??"");return}if(l.downArrow){if(T!==""&&_e===null){wt(1);return}let i=Kt.current;if(_e===null)return;let h=_e+1;h>=i.length?(at(null),b("")):(at(h),b(i[h]??""));return}}if(l.return){kt();return}if(l.backspace||l.delete){N();return}if(l.escape){b(""),Me(0),ie(null),X([]);return}a&&!l.ctrl&&!l.meta&&tn(a)}}}),st(()=>{if(D||F)return;let a=Se.current.shift();a!==void 0&&(Qt([...Se.current]),kt(a))},[D,F,kt]),L(V,{flexDirection:"column",width:je,children:[oo!==null&&L(V,{marginTop:1,flexDirection:"column",children:[oo.truncated&&C(v,{dimColor:!0,children:"\u2026"}),C(v,{children:oo.text})]}),D&&C(Zl,{startTime:lt.current,chars:zr}),C(V,{borderStyle:"round",borderColor:Xo.prod?"yellow":W,borderTop:!0,borderBottom:!0,borderLeft:!1,borderRight:!1,marginTop:1,flexDirection:"column",children:T?on.map((a,l)=>{let i=f.text.slice(a.start,a.end),h=l===Ht(on,f.pos),m=Math.min(f.pos,a.end)-a.start;return L(v,{children:[C(v,{color:W,children:l===0?"> ":" "}),h?L(Uo,{children:[i.slice(0,m),C(zt,{ch:i[m]??" "}),i.slice(m+1)]}):i||" "]},`${l}-${a.start}`)}):L(v,{children:[C(v,{color:W,children:"> "}),se&&!D?L(Uo,{children:[C(zt,{ch:se[0],dim:!0}),C(v,{color:"gray",children:se.slice(1)}),C(v,{dimColor:!0,children:" (tab)"})]}):to.isSetup||!qr?L(Uo,{children:[C(zt,{ch:to.text[0],dim:!0}),C(v,{color:"gray",children:to.text.slice(1)})]}):C(zt,{ch:" "})]})}),qo.length>0&&C(V,{flexDirection:"column",paddingX:1,children:qo.map((a,l)=>C(v,{color:"gray",children:`\u29D7 queued: ${a}`},`${l}-${a.slice(0,24)}`))}),Ce?L(V,{flexDirection:"column",paddingX:1,children:[C(v,{color:W,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)."}),ae.map((a,l)=>L(v,{color:l===Ce.cursor?W:void 0,children:[l===Ce.cursor?"\u276F ":" ",`${l+1}. ${a.label}${l===Ce.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"})]}):ue?L(V,{flexDirection:"column",paddingX:1,children:[C(v,{color:W,bold:!0,children:"Switch connection profile"}),ue.rows.map((a,l)=>L(v,{color:l===ue.cursor?W:void 0,children:[l===ue.cursor?"\u276F ":" ",`${l+1}. ${a.name}${l===ue.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"})]}):ke?L(V,{flexDirection:"column",paddingX:1,children:[C(v,{color:W,bold:!0,children:"Pick your Document360 environment"}),ke.rows.map((a,l)=>L(v,{color:l===ke.cursor?W:void 0,children:[l===ke.cursor?"\u276F ":" ",`${l+1}. ${a.name}`.padEnd(16),C(v,{color:"gray",children:a.apiUrl})]},a.name)),C(v,{dimColor:!0,children:"enter select \xB7 esc cancel"})]}):J?L(V,{flexDirection:"column",paddingX:1,children:[C(v,{color:W,bold:!0,children:"Switch workspace"}),C(v,{dimColor:!0,children:`environment ${J.environment} \xB7 project ${J.projectId.slice(0,8)}\u2026`}),J.rows.map((a,l)=>L(v,{color:l===J.cursor?W:void 0,children:[l===J.cursor?"\u276F ":" ",`${l+1}. ${a.name}${l===J.current?" \u2714":""}`.padEnd(30),C(v,{color:"gray",children:a.type??""})]},a.id)),C(v,{dimColor:!0,children:"enter switch \xB7 esc cancel"})]}):K?(()=>{let l=Math.min(Math.max(0,K.cursor-Math.floor(7)),Math.max(0,K.rows.length-14)),i=K.rows.slice(l,l+14),h=K.rows.filter(m=>m.checked).length;return L(V,{flexDirection:"column",paddingX:1,children:[C(v,{color:W,bold:!0,children:`Which folders back the user docs? (${h} selected of ${K.rows.length})`}),l>0?C(v,{dimColor:!0,children:` \u2191 ${l} more`}):null,i.map((m,g)=>{let w=l+g;return L(v,{color:w===K.cursor?W:void 0,children:[w===K.cursor?"\u276F ":" ",m.checked?"\u25C9 ":"\u25CB ",m.path.padEnd(Math.min(48,je-34)),C(v,{color:"gray",children:It(m)})]},m.path)}),l+14<K.rows.length?C(v,{dimColor:!0,children:` \u2193 ${K.rows.length-l-14} more`}):null,C(v,{dimColor:!0,children:"space toggle \xB7 enter save \xB7 esc cancel"})]})})():de?L(V,{flexDirection:"column",paddingX:1,children:[C(v,{color:W,bold:!0,children:"Publish which article?"}),de.rows.map((a,l)=>L(v,{color:l===de.cursor?W:void 0,children:[l===de.cursor?"\u276F ":" ",`${l+1}. ${a.path}`.padEnd(Math.min(56,je-30)),C(v,{color:"gray",children:a.label})]},a.path)),C(v,{dimColor:!0,children:"enter publish (draft) \xB7 esc cancel"})]}):te?L(V,{flexDirection:"column",paddingX:1,children:[C(v,{color:W,bold:!0,children:`Preview article${te.query?` \u2014 filter: ${te.query}`:" (type to filter)"}`}),ft.length===0?C(v,{color:"gray",children:"no articles match"}):ft.map((a,l)=>L(v,{color:l===te.cursor?W:void 0,children:[l===te.cursor?"\u276F ":" ",a]},a)),C(v,{dimColor:!0,children:"enter preview \xB7 esc cancel"})]}):oe?L(V,{flexDirection:"column",paddingX:1,children:[C(v,{color:W,bold:!0,children:`Resume session${oe.query?` \u2014 filter: ${oe.query}`:" (type to filter)"}`}),gt.length===0?C(v,{color:"gray",children:"no sessions match"}):gt.map((a,l)=>L(v,{color:l===oe.cursor?W:void 0,children:[l===oe.cursor?"\u276F ":" ",a.name.slice(0,28).padEnd(30),C(v,{color:l===oe.cursor?W:"gray",children:a.firstPrompt.slice(0,Math.max(10,je-40))})]},a.uuid)),C(v,{dimColor:!0,children:"enter resume \xB7 esc cancel"})]}):Jo?C(V,{flexDirection:"column",children:Xe.map((a,l)=>L(v,{color:l===Ye?W:void 0,children:[l===Ye?"\u276F ":" ",a.usage.padEnd(22)," ",C(v,{color:l===Ye?W:"gray",children:a.name==="model"&&eo?`${a.desc} (currently ${eo})`:a.desc})]},a.name))}):!T&&Ge.length>0?L(V,{flexDirection:"column",paddingX:1,children:[Ge.map((a,l)=>L(v,{children:[C(v,{color:W,children:l+1})," ",a.slice(0,Math.max(20,je-5))]},a)),C(v,{dimColor:!0,children:`press 1-${Ge.length} to fill the command \xB7 esc dismiss`})]}):C(V,{paddingX:1,children:L(v,{color:"gray",children:[Xo.prod?"\u26A0 PRODUCTION \xB7 ":"",`/help \xB7 ${eo??"model n/a"}${mt>0?` \xB7 ${mt<1e3?`${mt} tokens`:`${(mt/1e3).toFixed(1)}k tokens`}`:""}${Go>0?` \xB7 ${Ee(Go)}`:""} \xB7 \u2191 history \xB7 ctrl+c exit`]})})]})}M();import{jsx as oa}from"react/jsx-runtime";async function Fr(e=process.cwd(),t="auto",o,n="0.0.0"){let r=ta(t);r.kind==="none"&&(console.error(""),console.error($("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:s}=ea(oa(Wr,{cwd:e,auth:r,profileName:o,version:n}));await s(),process.stdout.write(`
|
|
70
|
+
`),process.exit(0)}var ia=ra(import.meta.url),Br=ia("../package.json"),fe=new na;function Fo(e){e.env&&(console.error("\u2717 --env was replaced by --profile (connection profiles). Use: --profile <name>"),process.exit(2))}fe.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=>{Fo(e),await vt({profile:e.profile,manual:e.manual})});fe.command("logout").description("Remove the stored Document360 session").option("--profile <name>","Connection profile").option("--env <name>",!1).action(async e=>{Fo(e),await fn({profile:e.profile})});fe.command("whoami").description("Show the current Document360 identity (refreshes if expired)").option("--profile <name>","Connection profile").option("--env <name>",!1).action(async e=>{Fo(e),await mn({profile:e.profile})});var Bo=fe.command("profile").description("Manage connection profiles for the current repo");Bo.command("list",{isDefault:!0}).description("List profiles (\u25CF = default)").action(()=>Ct(process.cwd()));Bo.command("use <name>").description("Set the default profile for this repo").action(e=>Pt(process.cwd(),e));Bo.command("show [name]").description("Print the resolved profile (connection + project)").action(e=>Tt(process.cwd(),e));var Hr=fe.command("workspace").description("Choose the Document360 workspace for this repo (active profile's project)");Hr.command("select",{isDefault:!0}).description("Interactively pick the workspace (lists in non-TTY)").option("--profile <name>","Connection profile").action(e=>He(process.cwd(),e.profile));Hr.command("use <name>").description("Set the workspace by name (scriptable)").option("--profile <name>","Connection profile").action(async(e,t)=>{process.exitCode=await an(process.cwd(),e,t.profile)});fe.command("logs").description("Show the Document360 API log files (send these to support when reporting a problem)").action(()=>hn());fe.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(()=>(Mt(),sr)),o=await t(process.cwd());for(let n of e(o))console.log(n);process.exitCode=o.some(n=>n.level==="fail")?1:0});fe.name("d360-writer").description("Standalone documentation agent CLI. Reads your code, writes your docs.").version(Br.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(sa.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 kn(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 wr(e.cwd,e.auth,e.profile):await Fr(e.cwd,e.auth,e.profile,Br.version)});fe.parseAsync(process.argv).catch(e=>{console.error(""),console.error(`\u2717 ${e.message}`),process.exit(1)});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "document360-writer",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.14",
|
|
4
4
|
"description": "Standalone documentation agent CLI. Reads your code, writes your docs. Specialized for Document360 publishing.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"@inquirer/prompts": "^8.4.3",
|
|
35
35
|
"commander": "^14.0.3",
|
|
36
36
|
"diff": "^8.0.4",
|
|
37
|
-
"document360-engine": "^0.2.
|
|
37
|
+
"document360-engine": "^0.2.8",
|
|
38
38
|
"ink": "^5.2.1",
|
|
39
39
|
"picocolors": "^1.1.1",
|
|
40
40
|
"react": "^18.3.1",
|