document360-writer 0.4.54 → 0.4.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -1,53 +1,53 @@
1
1
  #!/usr/bin/env node
2
- var Xi=Object.defineProperty;var wr=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(o){throw n=[o],o}};var Ki=(e,t)=>{for(var n in t)Xi(e,n,{get:t[n],enumerable:!0})};import De from"picocolors";var G,Ji,Qi,Zi,kr,ht,f,x,O,A,E,ee,Ce,q=wr(()=>{"use strict";G="#7f56d9",[Ji,Qi,Zi]=[127,86,217],kr=e=>De.isColorSupported?`\x1B[38;2;${Ji};${Qi};${Zi}m${e}\x1B[39m`:e,ht=e=>De.bold(kr(e)),f=e=>De.dim(e),x=e=>De.red(e),O=e=>De.yellow(e),A=e=>De.green(e),E=kr,ee=e=>De.gray(e),Ce=e=>De.bold(e)});var Es={};Ki(Es,{doctorCommand:()=>Tt,renderDoctorChecks:()=>As,runDoctorChecks:()=>Ds});import{existsSync as Kl}from"node:fs";import{d360GetAll as Jl,getAccessToken as Ql,isExpired as Co,loadProfileMap as Zl,loadTokens as ec,packageSkillsDir as js,projectConfigPath as tc,readProjectConfig as nc,DEFAULT_DOCS_DIR as oc,resolveActiveProfile as rc,resolveAuth as sc,resolveModelSetting as ic}from"document360-engine";async function Ds(e){let t=[],n=Number(process.versions.node.split(".")[0]);t.push(n>=20?{level:"ok",label:`Node ${process.versions.node}`}:{level:"fail",label:`Node ${process.versions.node} \u2014 20+ required`,fix:"Install Node 20 or later (nodejs.org)"});let o=sc("auto");t.push(o.kind==="none"?{level:"fail",label:"Claude auth: not configured",fix:"Set ANTHROPIC_API_KEY, or sign in to Claude Code once (subscription reuse)"}:{level:"ok",label:`Claude auth: ${o.kind==="api"?"API key":"subscription"}`});let r=ic(e);t.push({level:"ok",label:`Model: ${r.model??"Claude Code default"} (${r.source})`});let s=nc(e);if(!s)return t.push({level:"fail",label:`No ${tc(e)}`,fix:"Run: /init (or d360-writer init)"}),t;t.push({level:"ok",label:`Project config: ${s.projectId}`});let c=(s.docsDir??oc).replace(/\/+$/,"");t.push(s.mode==="engineer"?{level:"warn",label:"Mode: engineer \u2014 agent may modify any source file (dogfooding)",fix:'Remove "mode" from .d360-writer/config.json for the writer-mode boundary'}:{level:"ok",label:`Mode: writer \u2014 edits limited to ${c}/ and .d360-writer/ (docs, capture specs, config); product source is read-only`});let d=s.authoritativeSourceFiles??[];t.push(d.length>0?{level:"ok",label:`Sources: docs grounded in ${d.length} path(s) (${d.slice(0,3).join(", ")}${d.length>3?", \u2026":""})`}:{level:"warn",label:"Sources: not set \u2014 docs are grounded in the whole repo",fix:"Run: /scope to choose which files/folders the docs are written from"});let g;try{g=rc(e),t.push({level:"ok",label:`Profile: ${g.name} (${g.connection.name})${g.production?" \u26A0 PRODUCTION":""}`})}catch(R){return t.push({level:"fail",label:`Profile config: ${R.message.split(".")[0]}`,fix:"Run: /init to scaffold the profiles map"}),t}let w=ec(g.name);w?Co(w)&&!w.refreshToken?t.push({level:"fail",label:"Document360: session expired (no refresh token)",fix:"/login"}):Co(w)?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(w.expiresAt).toLocaleString()})`}):t.push({level:"fail",label:"Document360: not logged in",fix:`Run: /login (or d360-writer login --profile ${g.name})`}),t.push(g.project.workspaceId?{level:"ok",label:`Workspace: ${g.project.workspaceName??g.project.workspaceId}`}:{level:"warn",label:"No workspace selected",fix:"Run: /workspace"});let $=Zl(e,g.name);if($?$.projectId&&g.project.projectId&&$.projectId!==g.project.projectId?t.push({level:"fail",label:`Category map projectId (${$.projectId}) \u2260 profile projectId (${g.project.projectId})`,fix:"The map section belongs to a different project \u2014 fix .d360-writer/config.json or the map before publishing"}):t.push({level:"ok",label:`Category map: ${Object.keys($.articles).length} articles, ${Object.keys($.categories).length} categories`}):t.push({level:"ok",label:`Category map: none yet for "${g.name}" (created on first /publish)`}),t.push(Kl(js())?{level:"ok",label:"Skills bundle present"}:{level:"fail",label:`Skills folder missing at ${js()}`,fix:"Reinstall document360-writer (broken install)"}),w&&(!Co(w)||w.refreshToken)){let R={profile:g.name,connection:g.connection};try{await Ql(R);let y=await Jl(R,"/v3/projects");t.push({level:"ok",label:`API reachable (${g.connection.apiUrl}) \u2014 ${y.length} project(s) visible`})}catch(y){t.push({level:"fail",label:`API call failed: ${y.message.slice(0,120)}`,fix:"/login if auth-related; otherwise check the apiUrl/network"})}}return t}function As(e){let t=[""];for(let r of e){let s=r.level==="ok"?A("\u2713"):r.level==="warn"?O("\u26A0"):x("\u2717");t.push(` ${s} ${r.label}${r.detail?f(` \u2014 ${r.detail}`):""}`),r.fix&&t.push(` ${f("fix:")} ${E(r.fix)}`)}let n=e.filter(r=>r.level==="fail").length,o=e.filter(r=>r.level==="warn").length;return t.push(""),t.push(n===0?A(`\u2713 ${o===0?"All checks passed":`Healthy (${o} warning${o===1?"":"s"})`}`):x(`\u2717 ${n} problem${n===1?"":"s"} found`)),t.push(""),t}async function Tt(e,t){console.log(f("Running checks\u2026"));for(let n of As(await Ds(t.cwd)))console.log(n);return{kind:"continue"}}var un=wr(()=>{"use strict";q()});import{Command as hd}from"commander";import{createRequire as wd}from"node:module";import{AUTH_MODES as kd}from"document360-engine";import{input as ca}from"@inquirer/prompts";import{loginPkce as ua,refreshTokens as da,toStoredTokens as br,clearTokens as pa,decodeJwtClaims as xr,isExpired as fa,loadTokens as ma,saveTokens as vr,resolveActiveProfile as Yt,setProfileProject as ga,readProjectConfig as ha}from"document360-engine";q();import{select as ea}from"@inquirer/prompts";import{resolveActiveProfile as ta,setProfileProject as na,resolveProjectId as oa,listWorkspaces as ra}from"document360-engine";async function wt(e,t){let n=ta(e,t),o={profile:n.name,connection:n.connection},r=n.project.projectId??oa(o);return{workspaces:await ra(o,r),projectId:r,profile:n.name,environment:n.connection.name,current:n.project.workspaceId}}var yr=e=>`${e.name??e.id}${e.workspace_type?` \xB7 ${e.workspace_type}`:""}`;function Un(e,t){let n=t.toLowerCase();return e.find(o=>(o.name??"").toLowerCase()===n)??e.find(o=>(o.name??"").toLowerCase().startsWith(n))??e.find(o=>o.id.startsWith(t))}function zt(e,t,n,o,r){na(e,t,{projectId:n,workspaceId:o,workspaceName:r})}async function $r(e,t,n){let o;try{o=await wt(e,n)}catch(s){return console.log(x(`Could not list workspaces: ${s.message}`)),1}let r=Un(o.workspaces,t);return r?(zt(e,o.profile,o.projectId,r.id,r.name),console.log(A(`\u2713 Workspace set to "${r.name??r.id}" for profile "${o.profile}".`)),0):(console.log(x(`No workspace matches "${t}". Available: ${o.workspaces.map(s=>s.name??s.id).join(", ")}`)),1)}async function lt(e,t){let n;try{n=await wt(e,t)}catch(w){console.log(x(`Could not list workspaces: ${w.message}`));return}let{workspaces:o,projectId:r,profile:s,current:c}=n;if(o.length===0){console.log(f("No workspaces found in this project."));return}if(!process.stdin.isTTY){console.log("");for(let w of o)console.log(` ${w.id===c?E("\u25CF"):" "} ${yr(w)} ${f(w.id)}`);console.log(f("Run: d360-writer workspace use <name>"));return}let d=await ea({message:"Select the Document360 workspace for this repo:",choices:o.map(w=>({name:`${yr(w)}${w.id===c?" (current)":""}`,value:w.id}))}),g=o.find(w=>w.id===d);zt(e,s,r,d,g?.name),console.log(A(`\u2713 Workspace set to "${g?.name??d}" for profile "${s}".`))}q();import sa from"picocolors";function ia(e=process.env){return e.FORCE_HYPERLINK==="0"||!sa.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 aa(e,t=e,n){return ia(n)?`\x1B]8;;${e}\x07${t}\x1B]8;;\x07`:t}var la=/https?:\/\/[^\s\x1b]+/g;function kt(e,t){return e.replace(la,n=>aa(n,n,t))}function Cr(e){return{...xr(e.idToken)??{},...xr(e.accessToken)??{}}}function Vt(e){let t=Cr(e),n=t.email??t.preferred_username??t.sub??"unknown",o=t.doc360_project_id?` \xB7 project ${t.doc360_project_id}`:"";return`${n}${o}`}async function Xt(e){let t=Yt(process.cwd(),e.profile),n=t.connection;console.log(f(`Profile "${t.name}" \u2192 ${n.name} (${n.apiUrl})${t.production?" \u26A0 PRODUCTION":""}`));let o=await ua(n,{manual:e.manual,promptForRedirect:s=>ca({message:s})},s=>console.log(kt(s))),r=br(t.name,o);if(vr(r),Wn(r,t.name,s=>console.log(f(s))),console.log(""),console.log(A(`\u2713 Logged in to "${t.name}" as ${Vt(r)}`)),console.log(f(` access token expires: ${r.expiresAt}`)),console.log(f(` refresh token: ${r.refreshToken?"yes":"NO \u2014 session ends at expiry"}`)),process.stdin.isTTY)try{ha(process.cwd())?.profiles?.[t.name]&&(console.log(""),await lt(process.cwd(),t.name))}catch{}}function Wn(e,t,n){let r=Cr(e).doc360_project_id;if(!(typeof r!="string"||!r))try{if(Yt(process.cwd(),t).project.projectId)return;ga(process.cwd(),t,{projectId:r}),n(` Project ${r} written to profile "${t}".`)}catch{}}async function Pr(e){let t=Yt(process.cwd(),e.profile),n=t.connection,o=ma(t.name);if(!o){console.log(x(`Not logged in to Document360 (profile "${t.name}").`)),console.log(f(`Run: d360-writer login --profile ${t.name}`)),process.exitCode=1;return}if(console.log(`Profile ${E(t.name)}${t.production?" \u26A0 PRODUCTION":""}: ${Vt(o)}`),fa(o))if(o.refreshToken)try{let r=br(t.name,await da(n,o.refreshToken));vr(r),console.log(A(`\u2713 Session refreshed \u2014 expires ${r.expiresAt}`))}catch(r){console.log(O(`Session expired and refresh failed (${r.message.slice(0,120)})`)),console.log(f(`Run: d360-writer login --profile ${t.name}`)),process.exitCode=1}else console.log(O("Session expired (no refresh token).")),console.log(f(`Run: d360-writer login --profile ${t.name}`)),process.exitCode=1;else console.log(f(` expires: ${o.expiresAt}`))}async function Tr(e){let t=Yt(process.cwd(),e.profile);pa(t.name)?console.log(A(`\u2713 Logged out of Document360 (profile "${t.name}").`)):console.log(f(`No Document360 session for profile "${t.name}" \u2014 nothing to do.`))}q();import{readProjectConfig as Sr,writeProjectConfig as wa,resolveActiveProfile as ka,loadTokens as ya,isExpired as $a}from"document360-engine";function Kt(e){let t=Sr(e);if(!t?.profiles||Object.keys(t.profiles).length===0){console.log(x("No profiles in .d360-writer.json. Run: d360-writer init")),process.exitCode=1;return}console.log("");for(let[n,o]of Object.entries(t.profiles)){let r=n===t.defaultProfile?E("\u25CF "):" ",s=o.production?O(" \u26A0 PRODUCTION"):"",c=o.connection.environment??"(inline)",d=ya(n),g=d?$a(d)&&!d.refreshToken?O("expired"):f("logged in"):f("not logged in");console.log(`${r}${E(n)} \u2192 ${c}${s} [${g}]`)}console.log(""),console.log(f("\u25CF = default. Switch with: d360-writer profile use <name>")),console.log("")}function Jt(e,t){let n=Sr(e);if(!n?.profiles?.[t]){let r=n?.profiles?Object.keys(n.profiles).join(", "):"(none \u2014 run init)";console.log(x(`Unknown profile "${t}". Available: ${r}`)),process.exitCode=1;return}n.defaultProfile=t,wa(n,e);let o=n.profiles[t].production?O(" \u26A0 PRODUCTION"):"";console.log(A(`\u2713 Default profile is now "${t}"${o}`))}function Qt(e,t){try{let n=ka(e,t);console.log(""),console.log(`Profile ${E(n.name)}${n.production?O(" \u26A0 PRODUCTION"):""}`),console.log(f(` api: ${n.connection.apiUrl}`)),console.log(f(` identity: ${n.connection.authorizationUrl}`)),console.log(f(` clientId: ${n.connection.clientId}`)),console.log(f(` scopes: ${n.connection.scopes.join(" ")}`)),console.log(f(` project: ${n.project.projectId??"(set at login)"}`)),console.log(f(` workspace:${n.project.workspaceId?" "+n.project.workspaceId:" (none)"}`)),console.log("")}catch(n){console.log(x(n.message)),process.exitCode=1}}q();import{existsSync as xa,readdirSync as ba,statSync as va}from"node:fs";import{join as Ca}from"node:path";import{apiLogDir as Pa}from"document360-engine";function Rr(){let e=Pa();if(console.log(""),console.log(`Document360 API logs: ${E(e)}`),!xa(e)){console.log(f(" No logs yet \u2014 they appear after the first Document360 API call.")),console.log("");return}let t=ba(e).filter(n=>n.endsWith(".jsonl")).sort().reverse();t.length===0&&console.log(f(" No logs yet \u2014 they appear after the first Document360 API call."));for(let n of t.slice(0,14)){let o=(va(Ca(e,n)).size/1024).toFixed(1);console.log(` ${n} ${f(`${o} KB`)}`)}console.log(""),console.log(f("Failed calls include request/response bodies (tokens redacted, 4 KB cap).")),console.log(f("Set D360_LOG_BODIES=1 to also log bodies for successful calls.")),console.log("")}q();import{createSession as Ta,resolveAuth as Sa,findByName as Ra,slugify as ja,touchSession as Da,upsertSession as Aa,resolveActiveProfile as Ea}from"document360-engine";async function jr(e,t,n,o,r,s){let c=Sa(n);c.kind==="none"&&(console.error(""),console.error(x("ANTHROPIC_API_KEY is not set (required for --auth api).")),console.error(`Get a key at ${E("https://console.anthropic.com/settings/keys")}`),console.error(`Or use your Claude subscription instead: ${E("d360-writer --auth subscription")}`),process.exit(2)),c.kind==="subscription"&&console.error(f("Using your Claude subscription (no API key set)."));let d=null;try{d=Ea(e,r)}catch(y){console.error(x(`Document360 profile error: ${y.message}`)),process.exit(2)}d.production&&(console.error(O(`\u26A0 Profile "${d.name}" is PRODUCTION.`)),s||(console.error(x("Refusing to run against a production profile without --yes.")),process.exit(2)),console.error(f(" --yes given \u2014 proceeding against production.")));let g;if(o){let y=Ra(e,o);y||(console.error(x(`No saved session matches "${o}" in this repo.`)),console.error(f("List sessions inside the REPL with /resume.")),process.exit(2)),g=y.uuid,console.error(f(`Resuming "${y.name}"`))}let w=Ta({cwd:e,resume:g,profileName:r,allowProdWrites:s===!0}),$=g??null,R=1;for await(let y of w.send(t))switch(y.type){case"session":if(!$){$=y.sessionId;let b=new Date().toISOString();Aa({uuid:$,name:ja(t),renamed:!1,titled:!1,cwd:e,firstPrompt:t,createdAt:b,updatedAt:b})}break;case"text":process.stdout.write(y.delta);break;case"tool":console.error(ee(` \u2699 ${y.name}`));break;case"result":R=y.ok?0:1,console.error(f(`(${y.inputTokens}\u2192${y.outputTokens} tokens`+(y.costUsd>0?`, $${y.costUsd<.01?y.costUsd.toFixed(4):y.costUsd.toFixed(2)}`:"")+")")),y.ok||console.error(x("agent finished with an error result"));break;case"error":console.error(""),console.error(x(`agent error: ${y.message}`)),process.exit(1)}$&&Da($),process.stdout.write(`
3
- `),process.exit(R)}import{createInterface as Kc}from"node:readline/promises";import{createSession as Uo,resolveAuth as Jc,getSession as Qc,setTitle as Zc,slugify as eu,touchSession as si,upsertSession as tu,generateTitle as nu,resolveActiveProfile as ii,resolveModelSetting as ou,readProjectConfig as ru,decodeJwtClaims as oi,isExpired as su,loadTokens as iu}from"document360-engine";var yt=[{name:"init",usage:"/init",desc:"Pick an environment & scaffold .d360-writer.json",group:"start"},{name:"login",usage:"/login",desc:"Sign in to Document360 (browser)",group:"start"},{name:"project",usage:"/project [name]",desc:"Choose the Document360 project (picker; lists all you can access)",group:"start"},{name:"devhints",usage:"/devhints",desc:"Set up the dev\u2192docs hint channel (guide + paste block for your repo agent)",group:"start"},{name:"scope",usage:"/scope",desc:"Choose which repo folders back the docs (monorepos)",group:"start"},{name:"mcp",usage:"/mcp [list|add|remove]",desc:"Connect MCP servers (Notion, Linear, \u2026)",group:"start"},{name:"draft",usage:"/draft [<feature>]",desc:"Draft a feature's articles from its PRDs/specs in .d360-writer/input/ + the code",group:"docs"},{name:"write",usage:"/write [--all|--scope <cat>|<path>] [--run]",desc:"Author the planned articles in parallel (bare = preview + cost; --run starts)",group:"docs"},{name:"screenshot",usage:"/screenshot [--list|id|--all|path]",desc:"--list: status; else author capture specs (bulk also refreshes the capture checklist; --no-setup skips)",group:"docs"},{name:"capture-setup",usage:"/capture-setup",desc:"Re-run the data-staging checklist + dev test-id requests (auto-runs after /screenshot --all)",group:"docs"},{name:"preview",usage:"/preview [path|id]",desc:"Render an article (no arg: pick from tracked)",group:"docs"},{name:"publish",usage:"/publish [path|--all]",desc:"Publish to Document360 (no arg: pick; --all: every candidate)",group:"publish"},{name:"audit",usage:"/audit",desc:"Gap analysis: code vs docs vs Document360 (what changed)",group:"publish"},{name:"sync",usage:"/sync [pull <path>|--all]",desc:"Drift report local vs Document360; pull portal edits",group:"publish"},{name:"convert",usage:"/convert [--scope <folder>] [--run]",desc:"Convert tracked articles to DFM (one-off legacy migration)",group:"publish"},{name:"profile",usage:"/profile [name|add <name> [env]]",desc:"Switch/create a Document360 connection (picker; s = session)",group:"setup"},{name:"workspace",usage:"/workspace [name]",desc:"Switch the Document360 workspace (picker)",group:"setup"},{name:"model",usage:"/model [name|default]",desc:"Set the Claude model for d360-writer",group:"setup"},{name:"logout",usage:"/logout",desc:"Sign out + clear project/workspace selection (then /login to re-pick)",group:"setup"},{name:"allow-prod",usage:"/allow-prod",desc:"Authorize writes to a production profile",group:"setup"},{name:"doctor",usage:"/doctor",desc:"Health-check: auth, profile, workspace, map, API",group:"setup"},{name:"reset",usage:"/reset",desc:"[DANGER] Delete all d360-writer files (docs, config, screenshots); types repo name to confirm",group:"setup"},{name:"resume",usage:"/resume [name]",desc:"Resume a session (no arg lists them)",group:"session"},{name:"rename",usage:"/rename [name]",desc:"Name the session (no arg: suggest one)",group:"session"},{name:"clear",usage:"/clear",desc:"Reset the conversation (resumable)",group:"session"},{name:"help",usage:"/help",desc:"Show this help",group:"session"},{name:"exit",usage:"/exit",desc:"Quit",group:"session"}],Ia=[{key:"start",label:"Start here"},{key:"docs",label:"Write & screenshots"},{key:"publish",label:"Publish & keep in sync"},{key:"setup",label:"Setup & health"},{key:"session",label:"Session"}];function Zt(){let e=Math.max(...yt.map(n=>n.usage.length))+2,t=["document360-writer \u2014 commands","",'New here? /init \u2192 "write the docs for this repo" \u2192 /publish',""," Screenshots are optional \u2014 add them anytime:"," /screenshot --all \u2192 d360-capture capture \u2192 re-/publish"];for(let{key:n,label:o}of Ia){t.push("",o);for(let r of yt.filter(s=>s.group===n))t.push(` ${r.usage.padEnd(e)}${r.desc}`)}return t.push("","Tip: anything not starting with / is sent to the agent."),t}function Dr(e){if(!e.startsWith("/"))return[];let t=e.slice(1).toLowerCase().split(/\s/)[0]??"";return yt.filter(n=>n.name.startsWith(t))}function Ar(e){return/<[^>]+>/.test(e.replace(/\[[^\]]*\]/g,""))}async function Fn(){console.log("");for(let e of Zt())console.log(e);return console.log(""),console.log("Reporting a problem? Run `d360-writer logs` for the API log files."),console.log(""),{kind:"continue"}}q();import{getSession as _a}from"document360-engine";async function Er(e,t){let n=t.currentUuid(),o=n?_a(n):void 0;return console.log(o?f(`
2
+ var na=Object.defineProperty;var yr=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(o){throw n=[o],o}};var oa=(e,t)=>{for(var n in t)na(e,n,{get:t[n],enumerable:!0})};import De from"picocolors";var G,ra,sa,ia,$r,ht,f,x,L,A,E,ee,Ce,q=yr(()=>{"use strict";G="#7f56d9",[ra,sa,ia]=[127,86,217],$r=e=>De.isColorSupported?`\x1B[38;2;${ra};${sa};${ia}m${e}\x1B[39m`:e,ht=e=>De.bold($r(e)),f=e=>De.dim(e),x=e=>De.red(e),L=e=>De.yellow(e),A=e=>De.green(e),E=$r,ee=e=>De.gray(e),Ce=e=>De.bold(e)});var Ns={};oa(Ns,{doctorCommand:()=>Tt,renderDoctorChecks:()=>Is,runDoctorChecks:()=>Es});import{existsSync as oc}from"node:fs";import{d360GetAll as rc,getAccessToken as sc,isExpired as Co,loadProfileMap as ic,loadTokens as ac,packageSkillsDir as As,projectConfigPath as lc,readProjectConfig as cc,DEFAULT_DOCS_DIR as uc,resolveActiveProfile as dc,resolveAuth as pc,resolveModelSetting as fc}from"document360-engine";async function Es(e){let t=[],n=Number(process.versions.node.split(".")[0]);t.push(n>=20?{level:"ok",label:`Node ${process.versions.node}`}:{level:"fail",label:`Node ${process.versions.node} \u2014 20+ required`,fix:"Install Node 20 or later (nodejs.org)"});let o=pc("auto");t.push(o.kind==="none"?{level:"fail",label:"Claude auth: not configured",fix:"Set ANTHROPIC_API_KEY, or sign in to Claude Code once (subscription reuse)"}:{level:"ok",label:`Claude auth: ${o.kind==="api"?"API key":"subscription"}`});let r=fc(e);t.push({level:"ok",label:`Model: ${r.model??"Claude Code default"} (${r.source})`});let s=cc(e);if(!s)return t.push({level:"fail",label:`No ${lc(e)}`,fix:"Run: /init (or d360-writer init)"}),t;t.push({level:"ok",label:`Project config: ${s.projectId}`});let c=(s.docsDir??uc).replace(/\/+$/,"");t.push(s.mode==="engineer"?{level:"warn",label:"Mode: engineer \u2014 agent may modify any source file (dogfooding)",fix:'Remove "mode" from .d360-writer/config.json for the writer-mode boundary'}:{level:"ok",label:`Mode: writer \u2014 edits limited to ${c}/ and .d360-writer/ (docs, capture specs, config); product source is read-only`});let d=s.authoritativeSourceFiles??[];t.push(d.length>0?{level:"ok",label:`Sources: docs grounded in ${d.length} path(s) (${d.slice(0,3).join(", ")}${d.length>3?", \u2026":""})`}:{level:"warn",label:"Sources: not set \u2014 docs are grounded in the whole repo",fix:"Run: /scope to choose which files/folders the docs are written from"});let g;try{g=dc(e),t.push({level:"ok",label:`Profile: ${g.name} (${g.connection.name})${g.production?" \u26A0 PRODUCTION":""}`})}catch(R){return t.push({level:"fail",label:`Profile config: ${R.message.split(".")[0]}`,fix:"Run: /init to scaffold the profiles map"}),t}let w=ac(g.name);w?Co(w)&&!w.refreshToken?t.push({level:"fail",label:"Document360: session expired (no refresh token)",fix:"/login"}):Co(w)?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(w.expiresAt).toLocaleString()})`}):t.push({level:"fail",label:"Document360: not logged in",fix:`Run: /login (or d360-writer login --profile ${g.name})`}),t.push(g.project.workspaceId?{level:"ok",label:`Workspace: ${g.project.workspaceName??g.project.workspaceId}`}:{level:"warn",label:"No workspace selected",fix:"Run: /workspace"});let $=ic(e,g.name);if($?$.projectId&&g.project.projectId&&$.projectId!==g.project.projectId?t.push({level:"fail",label:`Category map projectId (${$.projectId}) \u2260 profile projectId (${g.project.projectId})`,fix:"The map section belongs to a different project \u2014 fix .d360-writer/config.json or the map before publishing"}):t.push({level:"ok",label:`Category map: ${Object.keys($.articles).length} articles, ${Object.keys($.categories).length} categories`}):t.push({level:"ok",label:`Category map: none yet for "${g.name}" (created on first /publish)`}),t.push(oc(As())?{level:"ok",label:"Skills bundle present"}:{level:"fail",label:`Skills folder missing at ${As()}`,fix:"Reinstall document360-writer (broken install)"}),w&&(!Co(w)||w.refreshToken)){let R={profile:g.name,connection:g.connection};try{await sc(R);let y=await rc(R,"/v3/projects");t.push({level:"ok",label:`API reachable (${g.connection.apiUrl}) \u2014 ${y.length} project(s) visible`})}catch(y){t.push({level:"fail",label:`API call failed: ${y.message.slice(0,120)}`,fix:"/login if auth-related; otherwise check the apiUrl/network"})}}return t}function Is(e){let t=[""];for(let r of e){let s=r.level==="ok"?A("\u2713"):r.level==="warn"?L("\u26A0"):x("\u2717");t.push(` ${s} ${r.label}${r.detail?f(` \u2014 ${r.detail}`):""}`),r.fix&&t.push(` ${f("fix:")} ${E(r.fix)}`)}let n=e.filter(r=>r.level==="fail").length,o=e.filter(r=>r.level==="warn").length;return t.push(""),t.push(n===0?A(`\u2713 ${o===0?"All checks passed":`Healthy (${o} warning${o===1?"":"s"})`}`):x(`\u2717 ${n} problem${n===1?"":"s"} found`)),t.push(""),t}async function Tt(e,t){console.log(f("Running checks\u2026"));for(let n of Is(await Es(t.cwd)))console.log(n);return{kind:"continue"}}var un=yr(()=>{"use strict";q()});import{Command as bd}from"commander";import{createRequire as vd}from"node:module";import{AUTH_MODES as Cd}from"document360-engine";import{input as ha}from"@inquirer/prompts";import{loginPkce as wa,refreshTokens as ka,toStoredTokens as Cr,clearTokens as ya,decodeJwtClaims as vr,isExpired as $a,loadTokens as xa,saveTokens as Pr,resolveActiveProfile as Yt,setProfileProject as ba,readProjectConfig as va}from"document360-engine";q();import{select as aa}from"@inquirer/prompts";import{resolveActiveProfile as la,setProfileProject as ca,resolveProjectId as ua,listWorkspaces as da}from"document360-engine";async function wt(e,t){let n=la(e,t),o={profile:n.name,connection:n.connection},r=n.project.projectId??ua(o);return{workspaces:await da(o,r),projectId:r,profile:n.name,environment:n.connection.name,current:n.project.workspaceId}}var xr=e=>`${e.name??e.id}${e.workspace_type?` \xB7 ${e.workspace_type}`:""}`;function Un(e,t){let n=t.toLowerCase();return e.find(o=>(o.name??"").toLowerCase()===n)??e.find(o=>(o.name??"").toLowerCase().startsWith(n))??e.find(o=>o.id.startsWith(t))}function zt(e,t,n,o,r){ca(e,t,{projectId:n,workspaceId:o,workspaceName:r})}async function br(e,t,n){let o;try{o=await wt(e,n)}catch(s){return console.log(x(`Could not list workspaces: ${s.message}`)),1}let r=Un(o.workspaces,t);return r?(zt(e,o.profile,o.projectId,r.id,r.name),console.log(A(`\u2713 Workspace set to "${r.name??r.id}" for profile "${o.profile}".`)),0):(console.log(x(`No workspace matches "${t}". Available: ${o.workspaces.map(s=>s.name??s.id).join(", ")}`)),1)}async function lt(e,t){let n;try{n=await wt(e,t)}catch(w){console.log(x(`Could not list workspaces: ${w.message}`));return}let{workspaces:o,projectId:r,profile:s,current:c}=n;if(o.length===0){console.log(f("No workspaces found in this project."));return}if(!process.stdin.isTTY){console.log("");for(let w of o)console.log(` ${w.id===c?E("\u25CF"):" "} ${xr(w)} ${f(w.id)}`);console.log(f("Run: d360-writer workspace use <name>"));return}let d=await aa({message:"Select the Document360 workspace for this repo:",choices:o.map(w=>({name:`${xr(w)}${w.id===c?" (current)":""}`,value:w.id}))}),g=o.find(w=>w.id===d);zt(e,s,r,d,g?.name),console.log(A(`\u2713 Workspace set to "${g?.name??d}" for profile "${s}".`))}q();import pa from"picocolors";function fa(e=process.env){return e.FORCE_HYPERLINK==="0"||!pa.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 ma(e,t=e,n){return fa(n)?`\x1B]8;;${e}\x07${t}\x1B]8;;\x07`:t}var ga=/https?:\/\/[^\s\x1b]+/g;function kt(e,t){return e.replace(ga,n=>ma(n,n,t))}function Tr(e){return{...vr(e.idToken)??{},...vr(e.accessToken)??{}}}function Vt(e){let t=Tr(e),n=t.email??t.preferred_username??t.sub??"unknown",o=t.doc360_project_id?` \xB7 project ${t.doc360_project_id}`:"";return`${n}${o}`}async function Xt(e){let t=Yt(process.cwd(),e.profile),n=t.connection;console.log(f(`Profile "${t.name}" \u2192 ${n.name} (${n.apiUrl})${t.production?" \u26A0 PRODUCTION":""}`));let o=await wa(n,{manual:e.manual,promptForRedirect:s=>ha({message:s})},s=>console.log(kt(s))),r=Cr(t.name,o);if(Pr(r),Wn(r,t.name,s=>console.log(f(s))),console.log(""),console.log(A(`\u2713 Logged in to "${t.name}" as ${Vt(r)}`)),console.log(f(` access token expires: ${r.expiresAt}`)),console.log(f(` refresh token: ${r.refreshToken?"yes":"NO \u2014 session ends at expiry"}`)),process.stdin.isTTY)try{va(process.cwd())?.profiles?.[t.name]&&(console.log(""),await lt(process.cwd(),t.name))}catch{}}function Wn(e,t,n){let r=Tr(e).doc360_project_id;if(!(typeof r!="string"||!r))try{if(Yt(process.cwd(),t).project.projectId)return;ba(process.cwd(),t,{projectId:r}),n(` Project ${r} written to profile "${t}".`)}catch{}}async function Sr(e){let t=Yt(process.cwd(),e.profile),n=t.connection,o=xa(t.name);if(!o){console.log(x(`Not logged in to Document360 (profile "${t.name}").`)),console.log(f(`Run: d360-writer login --profile ${t.name}`)),process.exitCode=1;return}if(console.log(`Profile ${E(t.name)}${t.production?" \u26A0 PRODUCTION":""}: ${Vt(o)}`),$a(o))if(o.refreshToken)try{let r=Cr(t.name,await ka(n,o.refreshToken));Pr(r),console.log(A(`\u2713 Session refreshed \u2014 expires ${r.expiresAt}`))}catch(r){console.log(L(`Session expired and refresh failed (${r.message.slice(0,120)})`)),console.log(f(`Run: d360-writer login --profile ${t.name}`)),process.exitCode=1}else console.log(L("Session expired (no refresh token).")),console.log(f(`Run: d360-writer login --profile ${t.name}`)),process.exitCode=1;else console.log(f(` expires: ${o.expiresAt}`))}async function Rr(e){let t=Yt(process.cwd(),e.profile);ya(t.name)?console.log(A(`\u2713 Logged out of Document360 (profile "${t.name}").`)):console.log(f(`No Document360 session for profile "${t.name}" \u2014 nothing to do.`))}q();import{readProjectConfig as jr,writeProjectConfig as Ca,resolveActiveProfile as Pa,loadTokens as Ta,isExpired as Sa}from"document360-engine";function Kt(e){let t=jr(e);if(!t?.profiles||Object.keys(t.profiles).length===0){console.log(x("No profiles in .d360-writer.json. Run: d360-writer init")),process.exitCode=1;return}console.log("");for(let[n,o]of Object.entries(t.profiles)){let r=n===t.defaultProfile?E("\u25CF "):" ",s=o.production?L(" \u26A0 PRODUCTION"):"",c=o.connection.environment??"(inline)",d=Ta(n),g=d?Sa(d)&&!d.refreshToken?L("expired"):f("logged in"):f("not logged in");console.log(`${r}${E(n)} \u2192 ${c}${s} [${g}]`)}console.log(""),console.log(f("\u25CF = default. Switch with: d360-writer profile use <name>")),console.log("")}function Jt(e,t){let n=jr(e);if(!n?.profiles?.[t]){let r=n?.profiles?Object.keys(n.profiles).join(", "):"(none \u2014 run init)";console.log(x(`Unknown profile "${t}". Available: ${r}`)),process.exitCode=1;return}n.defaultProfile=t,Ca(n,e);let o=n.profiles[t].production?L(" \u26A0 PRODUCTION"):"";console.log(A(`\u2713 Default profile is now "${t}"${o}`))}function Qt(e,t){try{let n=Pa(e,t);console.log(""),console.log(`Profile ${E(n.name)}${n.production?L(" \u26A0 PRODUCTION"):""}`),console.log(f(` api: ${n.connection.apiUrl}`)),console.log(f(` identity: ${n.connection.authorizationUrl}`)),console.log(f(` clientId: ${n.connection.clientId}`)),console.log(f(` scopes: ${n.connection.scopes.join(" ")}`)),console.log(f(` project: ${n.project.projectId??"(set at login)"}`)),console.log(f(` workspace:${n.project.workspaceId?" "+n.project.workspaceId:" (none)"}`)),console.log("")}catch(n){console.log(x(n.message)),process.exitCode=1}}q();import{existsSync as Ra,readdirSync as ja,statSync as Da}from"node:fs";import{join as Aa}from"node:path";import{apiLogDir as Ea}from"document360-engine";function Dr(){let e=Ea();if(console.log(""),console.log(`Document360 API logs: ${E(e)}`),!Ra(e)){console.log(f(" No logs yet \u2014 they appear after the first Document360 API call.")),console.log("");return}let t=ja(e).filter(n=>n.endsWith(".jsonl")).sort().reverse();t.length===0&&console.log(f(" No logs yet \u2014 they appear after the first Document360 API call."));for(let n of t.slice(0,14)){let o=(Da(Aa(e,n)).size/1024).toFixed(1);console.log(` ${n} ${f(`${o} KB`)}`)}console.log(""),console.log(f("Failed calls include request/response bodies (tokens redacted, 4 KB cap).")),console.log(f("Set D360_LOG_BODIES=1 to also log bodies for successful calls.")),console.log("")}q();import{createSession as Ia,resolveAuth as Na,findByName as _a,slugify as Ma,touchSession as Oa,upsertSession as La,resolveActiveProfile as Ua}from"document360-engine";async function Ar(e,t,n,o,r,s){let c=Na(n);c.kind==="none"&&(console.error(""),console.error(x("ANTHROPIC_API_KEY is not set (required for --auth api).")),console.error(`Get a key at ${E("https://console.anthropic.com/settings/keys")}`),console.error(`Or use your Claude subscription instead: ${E("d360-writer --auth subscription")}`),process.exit(2)),c.kind==="subscription"&&console.error(f("Using your Claude subscription (no API key set)."));let d=null;try{d=Ua(e,r)}catch(y){console.error(x(`Document360 profile error: ${y.message}`)),process.exit(2)}d.production&&(console.error(L(`\u26A0 Profile "${d.name}" is PRODUCTION.`)),s||(console.error(x("Refusing to run against a production profile without --yes.")),process.exit(2)),console.error(f(" --yes given \u2014 proceeding against production.")));let g;if(o){let y=_a(e,o);y||(console.error(x(`No saved session matches "${o}" in this repo.`)),console.error(f("List sessions inside the REPL with /resume.")),process.exit(2)),g=y.uuid,console.error(f(`Resuming "${y.name}"`))}let w=Ia({cwd:e,resume:g,profileName:r,allowProdWrites:s===!0}),$=g??null,R=1;for await(let y of w.send(t))switch(y.type){case"session":if(!$){$=y.sessionId;let b=new Date().toISOString();La({uuid:$,name:Ma(t),renamed:!1,titled:!1,cwd:e,firstPrompt:t,createdAt:b,updatedAt:b})}break;case"text":process.stdout.write(y.delta);break;case"tool":console.error(ee(` \u2699 ${y.name}`));break;case"result":R=y.ok?0:1,console.error(f(`(${y.inputTokens}\u2192${y.outputTokens} tokens`+(y.costUsd>0?`, $${y.costUsd<.01?y.costUsd.toFixed(4):y.costUsd.toFixed(2)}`:"")+")")),y.ok||console.error(x("agent finished with an error result"));break;case"error":console.error(""),console.error(x(`agent error: ${y.message}`)),process.exit(1)}$&&Oa($),process.stdout.write(`
3
+ `),process.exit(R)}import{createInterface as ou}from"node:readline/promises";import{createSession as Wo,resolveAuth as ru,getSession as su,setTitle as iu,slugify as au,touchSession as ui,upsertSession as lu,generateTitle as cu,resolveActiveProfile as di,resolveModelSetting as uu,readProjectConfig as du,decodeJwtClaims as li,isExpired as pu,loadTokens as fu}from"document360-engine";var yt=[{name:"init",usage:"/init",desc:"Pick an environment & scaffold .d360-writer.json",group:"start"},{name:"login",usage:"/login",desc:"Sign in to Document360 (browser)",group:"start"},{name:"project",usage:"/project [name]",desc:"Choose the Document360 project (picker; lists all you can access)",group:"start"},{name:"devhints",usage:"/devhints",desc:"Set up the dev\u2192docs hint channel (guide + paste block for your repo agent)",group:"start"},{name:"scope",usage:"/scope",desc:"Choose which repo folders back the docs (monorepos)",group:"start"},{name:"mcp",usage:"/mcp [list|add|remove]",desc:"Connect MCP servers (Notion, Linear, \u2026)",group:"start"},{name:"draft",usage:"/draft [<feature>]",desc:"Draft a feature's articles from its PRDs/specs in .d360-writer/input/ + the code",group:"docs"},{name:"write",usage:"/write [--all|--scope <cat>|<path>] [--run]",desc:"Author the planned articles in parallel (bare = preview + cost; --run starts)",group:"docs"},{name:"screenshot",usage:"/screenshot [--list|id|--all|path]",desc:"--list: status; else author capture specs (bulk also refreshes the capture checklist; --no-setup skips)",group:"docs"},{name:"capture-setup",usage:"/capture-setup",desc:"Re-run the data-staging checklist + dev test-id requests (auto-runs after /screenshot --all)",group:"docs"},{name:"preview",usage:"/preview [path|id]",desc:"Render an article (no arg: pick from tracked)",group:"docs"},{name:"publish",usage:"/publish [path|--all]",desc:"Publish to Document360 (no arg: pick; --all: every candidate)",group:"publish"},{name:"audit",usage:"/audit",desc:"Gap analysis: code vs docs vs Document360 (what changed)",group:"publish"},{name:"sync",usage:"/sync [pull <path>|--all]",desc:"Drift report local vs Document360; pull portal edits",group:"publish"},{name:"convert",usage:"/convert [--scope <folder>] [--run]",desc:"Convert tracked articles to DFM (one-off legacy migration)",group:"publish"},{name:"profile",usage:"/profile [name|add <name> [env]]",desc:"Switch/create a Document360 connection (picker; s = session)",group:"setup"},{name:"workspace",usage:"/workspace [name]",desc:"Switch the Document360 workspace (picker)",group:"setup"},{name:"model",usage:"/model [name|default]",desc:"Set the Claude model for d360-writer",group:"setup"},{name:"logout",usage:"/logout",desc:"Sign out + clear project/workspace selection (then /login to re-pick)",group:"setup"},{name:"allow-prod",usage:"/allow-prod",desc:"Authorize writes to a production profile",group:"setup"},{name:"doctor",usage:"/doctor",desc:"Health-check: auth, profile, workspace, map, API",group:"setup"},{name:"reset",usage:"/reset",desc:"[DANGER] Delete all d360-writer files (docs, config, screenshots); types repo name to confirm",group:"setup"},{name:"resume",usage:"/resume [name]",desc:"Resume a session (no arg lists them)",group:"session"},{name:"rename",usage:"/rename [name]",desc:"Name the session (no arg: suggest one)",group:"session"},{name:"clear",usage:"/clear",desc:"Reset the conversation (resumable)",group:"session"},{name:"help",usage:"/help",desc:"Show this help",group:"session"},{name:"exit",usage:"/exit",desc:"Quit",group:"session"}],Wa=[{key:"start",label:"Start here"},{key:"docs",label:"Write & screenshots"},{key:"publish",label:"Publish & keep in sync"},{key:"setup",label:"Setup & health"},{key:"session",label:"Session"}];function Zt(){let e=Math.max(...yt.map(n=>n.usage.length))+2,t=["document360-writer \u2014 commands","",'New here? /init \u2192 "write the docs for this repo" \u2192 /publish',""," Screenshots are optional \u2014 add them anytime:"," /screenshot --all \u2192 d360-capture capture \u2192 re-/publish"];for(let{key:n,label:o}of Wa){t.push("",o);for(let r of yt.filter(s=>s.group===n))t.push(` ${r.usage.padEnd(e)}${r.desc}`)}return t.push("","Tip: anything not starting with / is sent to the agent."),t}function Er(e){if(!e.startsWith("/"))return[];let t=e.slice(1).toLowerCase().split(/\s/)[0]??"";return yt.filter(n=>n.name.startsWith(t))}function Ir(e){return/<[^>]+>/.test(e.replace(/\[[^\]]*\]/g,""))}async function Fn(){console.log("");for(let e of Zt())console.log(e);return console.log(""),console.log("Reporting a problem? Run `d360-writer logs` for the API log files."),console.log(""),{kind:"continue"}}q();import{getSession as Fa}from"document360-engine";async function Nr(e,t){let n=t.currentUuid(),o=n?Fa(n):void 0;return console.log(o?f(`
4
4
  (conversation reset \u2014 "${o.name}" is still available via /resume)
5
5
  `):f(`
6
6
  (conversation reset \u2014 agent will start fresh on the next prompt)
7
- `)),{kind:"clear"}}async function Hn(){return{kind:"exit"}}q();import{input as $t,confirm as Na}from"@inquirer/prompts";import{basename as Ir,join as en}from"node:path";import{existsSync as ct,readFileSync as Ma,readdirSync as La,writeFileSync as Oa}from"node:fs";import{writeProjectConfig as _r,readProjectConfig as Ua,projectConfigPath as Nr,writerDir as Wa,DEFAULT_DOCS_DIR as Mr,DEFAULT_CAPTURE_DIR as Lr,DEFAULT_OUTPUT_DIR as Or}from"document360-engine";function Ur(e,t="berlin"){let n=Nr(e);if(ct(n))return{created:!1,path:n,profileName:""};let o={projectId:Hr(e)??Ir(e),docsDir:Mr,captureDir:Lr,outputDir:Or,profiles:{[t]:{connection:{environment:t},production:!1}},defaultProfile:t,authoritativeSourceFiles:Br(e)};return _r(o,e),Wr(e),{created:!0,path:n,profileName:t}}function Wr(e){let t=en(Wa(e),".gitignore");ct(t)||Oa(t,["# Local/transient \u2014 the config files here ARE meant to be committed.",".sessions/","cache/",""].join(`
8
- `),"utf8")}async function Fr(){let e=process.cwd(),t=Nr(e);if(ct(t)&&!await Na({message:`${t} already exists. Overwrite?`,default:!1}))return console.log(f("init cancelled.")),{kind:"continue"};let n=Hr(e)??Ir(e),o=await $t({message:"Project ID (used to scope sessions, screenshots, etc.):",default:n}),r=await $t({message:"Capture directory (where document360-capture .spec.ts files live):",default:Lr}),s=await $t({message:"Screenshot output directory:",default:Or}),c=await $t({message:"Default connection profile name:",default:"berlin"}),d=await $t({message:"Document360 environment for this profile (baked preset):",default:"berlin"}),g={projectId:o,docsDir:Mr,captureDir:r,outputDir:s,profiles:{[c]:{connection:{environment:d},production:!1}},defaultProfile:c,authoritativeSourceFiles:Br(e)},w=Ua(e);return w?.terminologyGlossary&&(g.terminologyGlossary=w.terminologyGlossary),_r(g,e),Wr(e),console.log(""),console.log(A(`\u2713 Wrote ${t}`)),console.log(""),console.log("Next:"),console.log(` ${E(`d360-writer login --profile ${c}`)} ${f("(sign in; pick the project)")}`),console.log(' Then ask the agent: "analyze this repo and propose a docs structure"'),console.log(""),{kind:"continue"}}function Hr(e){let t=en(e,"package.json");if(!ct(t))return null;try{return JSON.parse(Ma(t,"utf8")).name??null}catch{return null}}function Br(e){let t=[];for(let n of["README.md","ARCHITECTURE.md","CLAUDE.md"])ct(en(e,n))&&t.push(n);for(let n of["src","api","docs"]){let o=en(e,n);ct(o)&&!Fa(o)&&t.push(n)}return t}function Fa(e){try{return La(e,{withFileTypes:!0}).filter(n=>n.isDirectory()&&!n.name.startsWith(".")).length>6}catch{return!1}}q();import{readMcpConfig as Bn,writeMcpConfig as qr}from"document360-engine";async function tn(e){let t=(e[0]??"").toLowerCase();return t==="list"||!t?(Ha(),{kind:"continue"}):t==="add"?(Ba(e.slice(1)),{kind:"continue"}):t==="remove"||t==="rm"?(qa(e.slice(1)),{kind:"continue"}):(console.log(x(`Unknown /mcp subcommand: ${t}`)),console.log(f("Try: /mcp add <name> <stdio|http|sse> <command-or-url>, /mcp list, /mcp remove <name>")),{kind:"continue"})}function Ha(){let e=Bn(),t=Object.keys(e.servers);if(t.length===0){console.log(f(`
7
+ `)),{kind:"clear"}}async function Hn(){return{kind:"exit"}}q();import{input as $t,confirm as Ha}from"@inquirer/prompts";import{basename as _r,join as en}from"node:path";import{existsSync as ct,readFileSync as Ba,readdirSync as qa,writeFileSync as Ga}from"node:fs";import{writeProjectConfig as Mr,readProjectConfig as za,projectConfigPath as Or,writerDir as Ya,DEFAULT_DOCS_DIR as Lr,DEFAULT_CAPTURE_DIR as Ur,DEFAULT_OUTPUT_DIR as Wr}from"document360-engine";function Fr(e,t="berlin"){let n=Or(e);if(ct(n))return{created:!1,path:n,profileName:""};let o={projectId:qr(e)??_r(e),docsDir:Lr,captureDir:Ur,outputDir:Wr,profiles:{[t]:{connection:{environment:t},production:!1}},defaultProfile:t,authoritativeSourceFiles:Gr(e)};return Mr(o,e),Hr(e),{created:!0,path:n,profileName:t}}function Hr(e){let t=en(Ya(e),".gitignore");ct(t)||Ga(t,["# Local/transient \u2014 the config files here ARE meant to be committed.",".sessions/","cache/",""].join(`
8
+ `),"utf8")}async function Br(){let e=process.cwd(),t=Or(e);if(ct(t)&&!await Ha({message:`${t} already exists. Overwrite?`,default:!1}))return console.log(f("init cancelled.")),{kind:"continue"};let n=qr(e)??_r(e),o=await $t({message:"Project ID (used to scope sessions, screenshots, etc.):",default:n}),r=await $t({message:"Capture directory (where document360-capture .spec.ts files live):",default:Ur}),s=await $t({message:"Screenshot output directory:",default:Wr}),c=await $t({message:"Default connection profile name:",default:"berlin"}),d=await $t({message:"Document360 environment for this profile (baked preset):",default:"berlin"}),g={projectId:o,docsDir:Lr,captureDir:r,outputDir:s,profiles:{[c]:{connection:{environment:d},production:!1}},defaultProfile:c,authoritativeSourceFiles:Gr(e)},w=za(e);return w?.terminologyGlossary&&(g.terminologyGlossary=w.terminologyGlossary),Mr(g,e),Hr(e),console.log(""),console.log(A(`\u2713 Wrote ${t}`)),console.log(""),console.log("Next:"),console.log(` ${E(`d360-writer login --profile ${c}`)} ${f("(sign in; pick the project)")}`),console.log(' Then ask the agent: "analyze this repo and propose a docs structure"'),console.log(""),{kind:"continue"}}function qr(e){let t=en(e,"package.json");if(!ct(t))return null;try{return JSON.parse(Ba(t,"utf8")).name??null}catch{return null}}function Gr(e){let t=[];for(let n of["README.md","ARCHITECTURE.md","CLAUDE.md"])ct(en(e,n))&&t.push(n);for(let n of["src","api","docs"]){let o=en(e,n);ct(o)&&!Va(o)&&t.push(n)}return t}function Va(e){try{return qa(e,{withFileTypes:!0}).filter(n=>n.isDirectory()&&!n.name.startsWith(".")).length>6}catch{return!1}}q();import{readMcpConfig as Bn,writeMcpConfig as zr}from"document360-engine";async function tn(e){let t=(e[0]??"").toLowerCase();return t==="list"||!t?(Xa(),{kind:"continue"}):t==="add"?(Ka(e.slice(1)),{kind:"continue"}):t==="remove"||t==="rm"?(Ja(e.slice(1)),{kind:"continue"}):(console.log(x(`Unknown /mcp subcommand: ${t}`)),console.log(f("Try: /mcp add <name> <stdio|http|sse> <command-or-url>, /mcp list, /mcp remove <name>")),{kind:"continue"})}function Xa(){let e=Bn(),t=Object.keys(e.servers);if(t.length===0){console.log(f(`
9
9
  No MCP servers registered. Add one with /mcp add <name> <type> <ref>
10
- `));return}console.log(""),console.log("Registered MCP servers (~/.document360-writer/mcp.json):");for(let n of t){let o=e.servers[n];if(o.type==="stdio")console.log(` ${E(n)} ${f("(stdio)")} ${o.command} ${(o.args??[]).join(" ")}`);else{let r=Object.keys(o.headers??{}),s=r.length>0?f(` [headers: ${r.join(", ")}]`):"";console.log(` ${E(n)} ${f(`(${o.type})`)} ${o.url}${s}`)}}console.log("")}function Ba(e){let[t,n,...o]=e;if(!t||!n||o.length===0){console.log(x("Usage: /mcp add <name> <stdio|http|sse> <command-or-url> [args...] [-H key:value ...]"));return}if(n!=="stdio"&&n!=="http"&&n!=="sse"){console.log(x(`Unknown transport: ${n}. Use stdio, http, or sse.`));return}let r=Bn(),s;if(n==="stdio")s={type:"stdio",command:o[0],args:o.slice(1)};else{let c={};for(let d=1;d<o.length;d++)if(o[d]==="-H"||o[d]==="--header"){let g=o[++d],w=g?.match(/^([^:=]+)[:=](.+)$/);if(!w){console.log(x(`-H expects key:value (no spaces). Got: ${g??"(nothing)"}`));return}c[w[1].trim()]=w[2].trim()}else{console.log(x(`Unexpected argument: ${o[d]}. After the URL, only -H key:value is allowed.`));return}s={type:n,url:o[0],headers:Object.keys(c).length>0?c:void 0}}r.servers[t]=s,qr(r),console.log(""),console.log(A(`\u2713 Registered "${t}" (${n})`)),console.log(O(" This server loads on your next prompt. The current agent session reads MCP config at startup.")),console.log(f(" Run /clear if you want the next turn to reload immediately.")),console.log("")}function qa(e){let t=e[0];if(!t){console.log(x("Usage: /mcp remove <name>"));return}let n=Bn();if(!n.servers[t]){console.log(x(`No server named "${t}".`));return}delete n.servers[t],qr(n),console.log(A(`\u2713 Removed "${t}".`)),console.log(f(" Run /clear to drop it from the current session immediately."))}q();import{select as tl}from"@inquirer/prompts";import{computeSyncStatus as Qn,planPartitions as nl,relatedArticlePaths as ol,resolveModelForOperation as rl,runPartitioned as sl}from"document360-engine";import z from"picocolors";import Kr from"wrap-ansi";import Xn from"string-width";q();import Ae from"picocolors";import qn from"wrap-ansi";import Gn from"string-width";var Gr=e=>/^\s*(-{3,}|\*{3,}|_{3,})\s*$/.test(e),zr=e=>/^\s*\|?[\s:|-]*-[\s:|-]*\|?\s*$/.test(e)&&e.includes("-"),Yr=e=>e.replace(/^\s*\|/,"").replace(/\|\s*$/,"").split("|").map(t=>t.trim());function Ga(e){let t=e.replace(/\r/g,"").split(`
11
- `),n=[],o=0;for(;o<t.length;){let r=t[o];if(/^\s*```/.test(r)){let d=[];for(o++;o<t.length&&!/^\s*```/.test(t[o]);)d.push(t[o++]);o++,n.push({kind:"code",lines:d});continue}if(Gr(r)){n.push({kind:"hr"}),o++;continue}if(r.includes("|")&&o+1<t.length&&zr(t[o+1])){let d=Yr(r);o+=2;let g=[];for(;o<t.length&&t[o].includes("|")&&t[o].trim()!=="";)g.push(Yr(t[o++]));n.push({kind:"table",header:d,rows:g});continue}let s=r.match(/^(#{1,6})\s+(.*)$/);if(s){n.push({kind:"heading",level:s[1].length,text:s[2]}),o++;continue}if(/^\s*([-*]|\d+\.)\s+/.test(r)){let d=[];for(;o<t.length&&/^\s*([-*]|\d+\.)\s+/.test(t[o]);)d.push(t[o++].replace(/^\s*([-*]|\d+\.)\s+/,""));n.push({kind:"list",items:d});continue}if(r.trim()===""){o++;continue}let c=[];for(;o<t.length&&t[o].trim()!==""&&!/^\s*```/.test(t[o])&&!/^(#{1,6})\s/.test(t[o])&&!/^\s*([-*]|\d+\.)\s+/.test(t[o])&&!Gr(t[o])&&!(t[o].includes("|")&&o+1<t.length&&zr(t[o+1]));)c.push(t[o++]);n.push({kind:"para",text:c.join(" ")})}return n}function zn(e){return e.replace(/(\*\*[^*]+\*\*|`[^`]+`|\*[^*]+\*)/g,t=>t.startsWith("**")?Ae.bold(t.slice(2,-2)):t.startsWith("`")?E(t.slice(1,-1)):Ae.italic(t.slice(1,-1)))}var za=(e,t)=>e+" ".repeat(Math.max(0,t-Gn(e)));function Ya(e,t,n){let o=e.length,r=e.map((v,N)=>Math.max(Gn(v),...t.map(M=>Gn(M[N]??"")))),s=Math.max(24,n),c=3*o+1,d=[...r],g=()=>d.reduce((v,N)=>v+N,0)+c,w=0;for(;g()>s&&w++<1e4;){let v=-1,N=6;for(let M=0;M<o;M++)d[M]>N&&(N=d[M],v=M);if(v===-1)break;d[v]-=1}let $=(v,N,M)=>Ae.gray(v+d.map(H=>"\u2500".repeat(H+2)).join(N)+M),R=Ae.gray("\u2502"),y=(v,N)=>{let M=d.map(($e,te)=>{let we=v[te]??"",re=N?Ae.bold(we):zn(we);return qn(re,$e,{hard:!0}).split(`
12
- `)}),H=Math.max(...M.map($e=>$e.length)),Z=[];for(let $e=0;$e<H;$e++)Z.push(d.map((te,we)=>`${R} ${za(M[we][$e]??"",te)} `).join("")+R);return Z.join(`
13
- `)},b=[$("\u250C","\u252C","\u2510"),y(e,!0)];return b.push(t.length===0?$("\u2514","\u2534","\u2518"):$("\u251C","\u253C","\u2524")),t.forEach((v,N)=>{b.push(y(v,!1)),b.push(N===t.length-1?$("\u2514","\u2534","\u2518"):$("\u251C","\u253C","\u2524"))}),b.join(`
14
- `)}function Va(e,t){switch(e.kind){case"heading":return Ae.bold(e.text);case"hr":return Ae.gray("\u2500".repeat(t));case"para":return qn(zn(e.text),t);case"list":return e.items.map(n=>{let[o="",...r]=qn(zn(n),Math.max(10,t-4)).split(`
10
+ `));return}console.log(""),console.log("Registered MCP servers (~/.document360-writer/mcp.json):");for(let n of t){let o=e.servers[n];if(o.type==="stdio")console.log(` ${E(n)} ${f("(stdio)")} ${o.command} ${(o.args??[]).join(" ")}`);else{let r=Object.keys(o.headers??{}),s=r.length>0?f(` [headers: ${r.join(", ")}]`):"";console.log(` ${E(n)} ${f(`(${o.type})`)} ${o.url}${s}`)}}console.log("")}function Ka(e){let[t,n,...o]=e;if(!t||!n||o.length===0){console.log(x("Usage: /mcp add <name> <stdio|http|sse> <command-or-url> [args...] [-H key:value ...]"));return}if(n!=="stdio"&&n!=="http"&&n!=="sse"){console.log(x(`Unknown transport: ${n}. Use stdio, http, or sse.`));return}let r=Bn(),s;if(n==="stdio")s={type:"stdio",command:o[0],args:o.slice(1)};else{let c={};for(let d=1;d<o.length;d++)if(o[d]==="-H"||o[d]==="--header"){let g=o[++d],w=g?.match(/^([^:=]+)[:=](.+)$/);if(!w){console.log(x(`-H expects key:value (no spaces). Got: ${g??"(nothing)"}`));return}c[w[1].trim()]=w[2].trim()}else{console.log(x(`Unexpected argument: ${o[d]}. After the URL, only -H key:value is allowed.`));return}s={type:n,url:o[0],headers:Object.keys(c).length>0?c:void 0}}r.servers[t]=s,zr(r),console.log(""),console.log(A(`\u2713 Registered "${t}" (${n})`)),console.log(L(" This server loads on your next prompt. The current agent session reads MCP config at startup.")),console.log(f(" Run /clear if you want the next turn to reload immediately.")),console.log("")}function Ja(e){let t=e[0];if(!t){console.log(x("Usage: /mcp remove <name>"));return}let n=Bn();if(!n.servers[t]){console.log(x(`No server named "${t}".`));return}delete n.servers[t],zr(n),console.log(A(`\u2713 Removed "${t}".`)),console.log(f(" Run /clear to drop it from the current session immediately."))}q();import{select as ll}from"@inquirer/prompts";import{computeSyncStatus as Qn,planPartitions as cl,relatedArticlePaths as ul,resolveModelForOperation as dl,runPartitioned as pl}from"document360-engine";import z from"picocolors";import Qr from"wrap-ansi";import Xn from"string-width";q();import Ae from"picocolors";import qn from"wrap-ansi";import Gn from"string-width";var Yr=e=>/^\s*(-{3,}|\*{3,}|_{3,})\s*$/.test(e),Vr=e=>/^\s*\|?[\s:|-]*-[\s:|-]*\|?\s*$/.test(e)&&e.includes("-"),Xr=e=>e.replace(/^\s*\|/,"").replace(/\|\s*$/,"").split("|").map(t=>t.trim());function Qa(e){let t=e.replace(/\r/g,"").split(`
11
+ `),n=[],o=0;for(;o<t.length;){let r=t[o];if(/^\s*```/.test(r)){let d=[];for(o++;o<t.length&&!/^\s*```/.test(t[o]);)d.push(t[o++]);o++,n.push({kind:"code",lines:d});continue}if(Yr(r)){n.push({kind:"hr"}),o++;continue}if(r.includes("|")&&o+1<t.length&&Vr(t[o+1])){let d=Xr(r);o+=2;let g=[];for(;o<t.length&&t[o].includes("|")&&t[o].trim()!=="";)g.push(Xr(t[o++]));n.push({kind:"table",header:d,rows:g});continue}let s=r.match(/^(#{1,6})\s+(.*)$/);if(s){n.push({kind:"heading",level:s[1].length,text:s[2]}),o++;continue}if(/^\s*([-*]|\d+\.)\s+/.test(r)){let d=[];for(;o<t.length&&/^\s*([-*]|\d+\.)\s+/.test(t[o]);)d.push(t[o++].replace(/^\s*([-*]|\d+\.)\s+/,""));n.push({kind:"list",items:d});continue}if(r.trim()===""){o++;continue}let c=[];for(;o<t.length&&t[o].trim()!==""&&!/^\s*```/.test(t[o])&&!/^(#{1,6})\s/.test(t[o])&&!/^\s*([-*]|\d+\.)\s+/.test(t[o])&&!Yr(t[o])&&!(t[o].includes("|")&&o+1<t.length&&Vr(t[o+1]));)c.push(t[o++]);n.push({kind:"para",text:c.join(" ")})}return n}function zn(e){return e.replace(/(\*\*[^*]+\*\*|`[^`]+`|\*[^*]+\*)/g,t=>t.startsWith("**")?Ae.bold(t.slice(2,-2)):t.startsWith("`")?E(t.slice(1,-1)):Ae.italic(t.slice(1,-1)))}var Za=(e,t)=>e+" ".repeat(Math.max(0,t-Gn(e)));function el(e,t,n){let o=e.length,r=e.map((v,_)=>Math.max(Gn(v),...t.map(M=>Gn(M[_]??"")))),s=Math.max(24,n),c=3*o+1,d=[...r],g=()=>d.reduce((v,_)=>v+_,0)+c,w=0;for(;g()>s&&w++<1e4;){let v=-1,_=6;for(let M=0;M<o;M++)d[M]>_&&(_=d[M],v=M);if(v===-1)break;d[v]-=1}let $=(v,_,M)=>Ae.gray(v+d.map(H=>"\u2500".repeat(H+2)).join(_)+M),R=Ae.gray("\u2502"),y=(v,_)=>{let M=d.map(($e,te)=>{let we=v[te]??"",re=_?Ae.bold(we):zn(we);return qn(re,$e,{hard:!0}).split(`
12
+ `)}),H=Math.max(...M.map($e=>$e.length)),Z=[];for(let $e=0;$e<H;$e++)Z.push(d.map((te,we)=>`${R} ${Za(M[we][$e]??"",te)} `).join("")+R);return Z.join(`
13
+ `)},b=[$("\u250C","\u252C","\u2510"),y(e,!0)];return b.push(t.length===0?$("\u2514","\u2534","\u2518"):$("\u251C","\u253C","\u2524")),t.forEach((v,_)=>{b.push(y(v,!1)),b.push(_===t.length-1?$("\u2514","\u2534","\u2518"):$("\u251C","\u253C","\u2524"))}),b.join(`
14
+ `)}function tl(e,t){switch(e.kind){case"heading":return Ae.bold(e.text);case"hr":return Ae.gray("\u2500".repeat(t));case"para":return qn(zn(e.text),t);case"list":return e.items.map(n=>{let[o="",...r]=qn(zn(n),Math.max(10,t-4)).split(`
15
15
  `);return" \u2022 "+o+r.map(s=>`
16
16
  `+s).join("")}).join(`
17
17
  `);case"code":return e.lines.map(n=>Ae.gray(" "+n)).join(`
18
- `);case"table":return Ya(e.header,e.rows,t)}}function Yn(e,t){let n=Math.max(20,t);return Ga(e).map(o=>Va(o,n)).join(`
18
+ `);case"table":return el(e.header,e.rows,t)}}function Yn(e,t){let n=Math.max(20,t);return Qa(e).map(o=>tl(o,n)).join(`
19
19
 
20
- `)}q();import Xa from"picocolors";var Ka=[127,86,217],Ja=[22,38,43],Vr={T:Ka,E:Ja},xt=["..TTTTTT....","..TTTTTTT...","..TTTTTTTT..","..TTETTETT..","..TTETTETT..","..TTTTTTTT..","..TTTTTTT...","..TTTTTT....","...T..T....."],Vn=([e,t,n])=>`\x1B[38;2;${e};${t};${n}m`,Qa=([e,t,n])=>`\x1B[48;2;${e};${t};${n}m`;function Xr(){if(!Xa.isColorSupported)return[];let e=xt[0].length,t=[];for(let n=0;n<xt.length;n+=2){let o="";for(let r=0;r<e;r++){let s=Vr[xt[n][r]],c=n+1<xt.length?Vr[xt[n+1][r]]:void 0;s&&c?o+=`${Vn(s)}${Qa(c)}\u2580\x1B[49m\x1B[39m`:s?o+=`${Vn(s)}\u2580\x1B[39m`:c?o+=`${Vn(c)}\u2584\x1B[39m`:o+=" "}t.push(o)}return t}function bt(e){return e<60?`${e}s`:`${Math.floor(e/60)}m ${e%60}s`}function ie(e){return e<=0?"$0.00":e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}function Ee(e){return e<1e3?`${e} tokens`:e<1e6?`${(e/1e3).toFixed(1)}k tokens`:`${(e/1e6).toFixed(2)}M tokens`}var ut=(e,t)=>` ${e.padEnd(13)}${t}`;function Za(e,t){let n=[ht("\u270E document360-writer")+z.gray(` v${e.version}`),z.gray(" Reads your code, writes your docs."),"",ut("Claude:",`${e.claude}${z.gray(` \xB7 ${e.model}${e.modelSource?` (${e.modelSource})`:""}`)}`),ut("Document360:",e.configured?e.loggedOut?z.yellow("not logged in \u2014 run /login"):`${e.who??""}${e.sessionHint?z.gray(` (${e.sessionHint})`):""}`:z.yellow("not set up \u2014 run /init")),ut("Profile:",e.configured?`${e.profile}${z.gray(` (${e.apiUrl})`)}${e.prod?z.bold(z.yellow(" \u26A0 PRODUCTION")):""}`:z.gray("\u2014 (run /init)")),ut("Project:",e.project),ut("Mode:",z.gray(e.mode)),ut("cwd:",z.gray(e.cwd))],o=Xr();if(o.length===0)return n.join(`
20
+ `)}q();import nl from"picocolors";var ol=[127,86,217],rl=[22,38,43],Kr={T:ol,E:rl},xt=["..TTTTTT....","..TTTTTTT...","..TTTTTTTT..","..TTETTETT..","..TTETTETT..","..TTTTTTTT..","..TTTTTTT...","..TTTTTT....","...T..T....."],Vn=([e,t,n])=>`\x1B[38;2;${e};${t};${n}m`,sl=([e,t,n])=>`\x1B[48;2;${e};${t};${n}m`;function Jr(){if(!nl.isColorSupported)return[];let e=xt[0].length,t=[];for(let n=0;n<xt.length;n+=2){let o="";for(let r=0;r<e;r++){let s=Kr[xt[n][r]],c=n+1<xt.length?Kr[xt[n+1][r]]:void 0;s&&c?o+=`${Vn(s)}${sl(c)}\u2580\x1B[49m\x1B[39m`:s?o+=`${Vn(s)}\u2580\x1B[39m`:c?o+=`${Vn(c)}\u2584\x1B[39m`:o+=" "}t.push(o)}return t}function bt(e){return e<60?`${e}s`:`${Math.floor(e/60)}m ${e%60}s`}function ie(e){return e<=0?"$0.00":e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}function Ee(e){return e<1e3?`${e} tokens`:e<1e6?`${(e/1e3).toFixed(1)}k tokens`:`${(e/1e6).toFixed(2)}M tokens`}var ut=(e,t)=>` ${e.padEnd(13)}${t}`;function il(e,t){let n=[ht("\u270E document360-writer")+z.gray(` v${e.version}`),z.gray(" Reads your code, writes your docs."),"",ut("Claude:",`${e.claude}${z.gray(` \xB7 ${e.model}${e.modelSource?` (${e.modelSource})`:""}`)}`),ut("Document360:",e.configured?e.loggedOut?z.yellow("not logged in \u2014 run /login"):`${e.who??""}${e.sessionHint?z.gray(` (${e.sessionHint})`):""}`:z.yellow("not set up \u2014 run /init")),ut("Profile:",e.configured?`${e.profile}${z.gray(` (${e.apiUrl})`)}${e.prod?z.bold(z.yellow(" \u26A0 PRODUCTION")):""}`:z.gray("\u2014 (run /init)")),ut("Project:",e.project),ut("Mode:",z.gray(e.mode)),ut("cwd:",z.gray(e.cwd))],o=Jr();if(o.length===0)return n.join(`
21
21
  `);let r=2,s=3,c=Xn(o[0]);if(!(t>=r+c+s+Math.max(...n.map($=>Xn($)))))return[...o.map($=>" "+$),...n].join(`
22
22
  `);let g=Math.max(0,Math.floor((n.length-o.length)/2)),w=[];for(let $=0;$<Math.max(o.length+g,n.length);$++){let R=o[$-g]??" ".repeat(c);w.push((" ".repeat(r)+R+" ".repeat(s)+(n[$]??"")).trimEnd())}return w.join(`
23
- `)}var el={error:z.red,warn:z.yellow,ok:z.green,info:z.gray};function Kn(e,t){let n=Math.max(20,t);switch(e.kind){case"banner":return Za(e.info,n);case"user":{let o="\x1B[48;2;42;42;46m",r="\x1B[49m",s=Math.max(10,n-4),c=50,d=e.text.split(`
24
- `).flatMap(w=>Kr(w,s,{hard:!0}).split(`
23
+ `)}var al={error:z.red,warn:z.yellow,ok:z.green,info:z.gray};function Kn(e,t){let n=Math.max(20,t);switch(e.kind){case"banner":return il(e.info,n);case"user":{let o="\x1B[48;2;42;42;46m",r="\x1B[49m",s=Math.max(10,n-4),c=50,d=e.text.split(`
24
+ `).flatMap(w=>Qr(w,s,{hard:!0}).split(`
25
25
  `)),g=Math.max(0,d.length-c);return g>0&&(d=[...d.slice(0,c),z.dim(`\u2026 +${g} more lines`)]),`
26
26
  `+d.map((w,$)=>o+($===0?E(" \u276F "):" ")+w+" ".repeat(Math.max(0,s-Xn(w))+1)+r).join(`
27
27
  `)}case"assistant":return`
28
28
  `+Yn(e.text,n);case"tool":{let o=e.arg!==null?z.gray(`${e.sep}(${e.arg})`):"";return`
29
- `+Kr(z.green("\u25CF ")+z.bold(e.title)+o,n)}case"tool-result":{let o=e.isError?z.red:z.gray,r=e.lines.map((s,c)=>o((c===0?" \u23BF ":" ")+s));return e.hidden>0&&r.push(z.dim(` \u2026 +${e.hidden} lines`)),r.join(`
29
+ `+Qr(z.green("\u25CF ")+z.bold(e.title)+o,n)}case"tool-result":{let o=e.isError?z.red:z.gray,r=e.lines.map((s,c)=>o((c===0?" \u23BF ":" ")+s));return e.hidden>0&&r.push(z.dim(` \u2026 +${e.hidden} lines`)),r.join(`
30
30
  `)}case"diff":{let o=c=>c===1?"":"s",s=[z.gray(` \u23BF Added ${e.added} line${o(e.added)}, removed ${e.removed} line${o(e.removed)}`),...e.lines];return e.hidden>0&&s.push(z.dim(` \u2026 +${e.hidden} more diff lines`)),s.join(`
31
31
  `)}case"link":return e.lines.map(o=>E(kt(` \u2B95 ${o}`))).join(`
32
32
  `);case"preview":return`
33
33
  `+ht(`\u25A3 Preview \u2014 ${e.name}`)+`
34
34
 
35
35
  `+Yn(e.text,n);case"note":return`
36
- `+el[e.tone](kt(e.text));case"done":return`
37
- `+(e.ok?z.magenta("\u2736 "):z.red("\u2736 "))+z.gray(`Cooked for ${bt(e.seconds)} \xB7 ${e.tokens} tokens`+(e.costUsd>0?` \xB7 ${ie(e.costUsd)}`:""))}}function Jr(e,t){return e.map(n=>Kn(n,t)).join(`
36
+ `+al[e.tone](kt(e.text));case"done":return`
37
+ `+(e.ok?z.magenta("\u2736 "):z.red("\u2736 "))+z.gray(`Cooked for ${bt(e.seconds)} \xB7 ${e.tokens} tokens`+(e.costUsd>0?` \xB7 ${ie(e.costUsd)}`:""))}}function Zr(e,t){return e.map(n=>Kn(n,t)).join(`
38
38
  `)}var vt=3;function Zn(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(`
39
- `)}var Qr={"local-ahead":"modified locally","untracked-local":"new (never published)",conflict:"\u26A0 conflict \u2014 publishing overwrites the portal edit"};function Ct(e){return e.filter(t=>t.path!==null&&t.status in Qr).map(t=>({path:t.path,label:Qr[t.status]}))}function il(e){let t=e.replace(/\\/g,"/").split("/").pop()??e,n=t.replace(/^\d+[-_]/,"").replace(/[-_]+/g," ").trim();return n?n.charAt(0).toUpperCase()+n.slice(1):t}function Zr(e){let t=[];e.length>1&&t.push({kind:"all",label:`Publish all ${e.length} articles`,paths:e.map(o=>o.path),indent:!1});let n=new Map;for(let o of e){let r=o.path.replace(/\\/g,"/").split("/").slice(0,-1).join("/"),s=n.get(r);s?s.push(o):n.set(r,[o])}for(let o of[...n.keys()].sort()){let r=n.get(o).sort((s,c)=>s.path.localeCompare(c.path));t.push({kind:"category",label:`${il(o)} (${r.length})`,paths:r.map(s=>s.path),indent:!1});for(let s of r){let c=s.path.replace(/\\/g,"/").split("/").pop()??s.path;t.push({kind:"article",label:c,paths:[s.path],indent:!0,note:s.label})}}return t}function nn(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(`
40
- `)}function eo(e,t,n){let o=y=>t[y.index]?.paths.length??0,r=e.filter(y=>y.ok),s=e.filter(y=>!y.ok),c=e.reduce((y,b)=>y+o(b),0),d=r.reduce((y,b)=>y+o(b),0),g=n==="api"?`${ie(e.reduce((y,b)=>y+b.costUsd,0))} total`:Ee(e.reduce((y,b)=>y+b.outputTokens,0)),w=`${r.length}/${e.length} partition${e.length===1?"":"s"}`,$=y=>`${y} article${y===1?"":"s"}`,R=[];if(s.length===0)R.push(`Published ${$(c)} (${w}) successfully \xB7 ${g}.`),R.push("All are DRAFTS \u2014 review and publish them in the Document360 portal.");else{R.push(`Published ${d}/${$(c)} (${w}) \xB7 ${g}.`),R.push(`${s.length} partition${s.length===1?"":"s"} failed \u2014 re-run /publish --all to retry just the rest (published articles are skipped):`);for(let y of s)R.push(` \u2717 ${y.label}${y.error?` \u2014 ${y.error}`:""}`)}return R}async function Jn(e,t){let n=nl(t),{model:o}=rl(e.cwd,"standard");console.log(f(`Publishing ${t.length} article${t.length===1?"":"s"} across ${n.length} partition${n.length===1?"":"s"} (\u2264${vt} agents at once) on ${o}\u2026`)),console.log(f(" (mid-run abort is TUI-only \u2014 Ctrl+C exits the REPL.)"));try{for await(let r of sl({cwd:e.cwd,partitions:n,promptFor:s=>nn(s.paths),concurrency:vt,profileName:e.profileName,allowProdWrites:e.allowProdWrites(),model:o}))if(r.type==="partition_status")r.status==="running"?console.log(f(` \u25B8 ${r.label} \u2014 publishing\u2026`)):r.status==="done"?console.log(A(` \u2713 ${r.label}`)):console.log(x(` \u2717 ${r.label}`));else if(r.type==="run_done"){console.log("");let s=process.env.ANTHROPIC_API_KEY?"api":"subscription";for(let c of eo(r.results,n,s))console.log(r.ok?A(c):O(c))}}catch(r){console.log(x(`Publish run failed: ${r.message}`))}return console.log(""),{kind:"continue"}}async function on(e,t,n){let o=ol(e,n);if(o.length===0)return[];let r=new Set(Ct((await Qn({cwd:e,profileName:t})).entries).map(s=>s.path));return o.filter(s=>r.has(s))}async function es(e,t){let n=e[0];if(n==="--related"&&e[1]){if(!t)return{kind:"continue"};let o=await on(t.cwd,t.profileName,e[1].replace(/\\/g,"/"));return o.length===0?(console.log(A("\u2713 All related articles are already published.")),{kind:"continue"}):await Jn(t,o)}if(n==="--all"){console.log(f("Checking what needs publishing\u2026"));try{let o=Ct((await Qn({cwd:t?.cwd??process.cwd()})).entries);return o.length===0?(console.log(A("\u2713 Nothing is ahead of Document360 \u2014 no publish candidates.")),{kind:"continue"}):t?await Jn(t,o.map(r=>r.path)):{kind:"forward-to-agent",prompt:nn(o.map(r=>r.path)),display:"/publish --all"}}catch(o){return console.log(x(`Could not compute sync status: ${o.message}`)),{kind:"continue"}}}if(!n){console.log(f("Checking what needs publishing\u2026"));let o;try{o=Ct((await Qn({cwd:t?.cwd??process.cwd()})).entries)}catch(r){return console.log(x(`Could not compute sync status: ${r.message}`)),console.log(f("Publish a specific article: /publish <article-path>")),{kind:"continue"}}if(o.length===0)return console.log(A("\u2713 Nothing is ahead of Document360 \u2014 no publish candidates.")),console.log(f(" (Articles without a sync base are unverified \u2014 publish those by path if needed.)")),{kind:"continue"};if(!process.stdin.isTTY||!t){for(let r of o)console.log(` ${r.path} ${f(`(${r.label})`)}`);return console.log(f("Run: /publish <article-path>")),{kind:"continue"}}try{n=await t.withPausedInput(()=>tl({message:"Publish which article?",choices:[...o.length>1?[{name:`All ${o.length} candidates`,value:"--all",description:"one agent run over every candidate"}]:[],...o.map(r=>({name:r.path,value:r.path,description:r.label}))]}))}catch{return console.log(f("Cancelled.")),{kind:"continue"}}if(n==="--all")return await Jn(t,o.map(r=>r.path))}return{kind:"forward-to-agent",prompt:Zn(n),display:`/publish ${n}`}}async function rn(){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.","2.5. d360_pending_hints \u2014 the source agent's own notes on what it shipped. Verify each (sources exist, commit is an ancestor of HEAD, source shows the surface) before trusting; fold verified ones into the table, flag the rest.","3. Map changes (diff + hints) 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 and stamp consumed hints.","","Do not start writing or updating any article yet \u2014 the proposal table is the deliverable."].join(`
41
- `),display:"/audit"}}q();import{checkbox as al}from"@inquirer/prompts";import{inventoryRepo as ll,readProjectConfig as ts,writeProjectConfig as cl}from"document360-engine";function to(e,t){let n=ts(e);n&&(n.authoritativeSourceFiles=t,cl(n,e))}function sn(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 ns(e,t){let n=t?.cwd??process.cwd();if(!ts(n))return console.log(x("No .d360-writer.json here. Run /init first.")),{kind:"continue"};let o=ll(n);if(o.length===0)return console.log(f('No candidate source folders found. Set "authoritativeSourceFiles" in .d360-writer.json manually.')),{kind:"continue"};if(!process.stdin.isTTY||!t){console.log(""),console.log(E("Recommended documentation scope (run /scope in the REPL to choose):"));for(let s of o)console.log(` ${s.recommended?"\u25C9":"\u25CB"} ${s.path} ${f(sn(s))}`);return console.log(""),{kind:"continue"}}let r;try{r=await t.withPausedInput(()=>al({message:"Which folders back the user docs? (space toggles, enter confirms)",choices:o.map(s=>({name:`${s.path} (${sn(s)})`,value:s.path,checked:s.recommended})),pageSize:20}))}catch{return console.log(f("Cancelled.")),{kind:"continue"}}if(r.length===0)return console.log(f("Nothing selected \u2014 scope unchanged.")),{kind:"continue"};to(n,r),console.log(A(`\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"}}q();import{confirm as ml}from"@inquirer/prompts";import{applyPull as as,computeSyncStatus as ls,planPull as gl,D360AuthError as hl}from"document360-engine";q();var os=[{status:"conflict",header:"Conflicts \u2014 both sides changed; pick a direction (/sync pull <path> or /publish <path>):",paint:x,mark:"!"},{status:"local-ahead",header:"Local ahead \u2014 push with /publish <path>:",paint:O,mark:"M"},{status:"remote-ahead",header:"Remote ahead \u2014 pull with /sync pull <path>:",paint:E,mark:"M"},{status:"deleted-local",header:"Deleted locally \u2014 still on Document360 (pull to restore, or remove from the map):",paint:x,mark:"D"},{status:"deleted-remote",header:"Deleted on Document360 \u2014 still local (publish to recreate, or delete the file):",paint:x,mark:"D"},{status:"orphaned",header:"Orphaned map entries \u2014 gone on both sides (remove from d360-category-map.json):",paint:ee,mark:"X"},{status:"untracked-local",header:"Untracked local articles \u2014 publish to start tracking:",paint:f,mark:"?"},{status:"untracked-remote",header:"Untracked Document360 articles \u2014 no local file maps to them:",paint:f,mark:"?"},{status:"unknown-base",header:"No sync base recorded yet \u2014 the next /publish or /sync pull of each records one:",paint:ee,mark:"\xB7"}];function ul(e){return e.path?e.path:`${e.title??"(untitled)"} ${ee(`[${e.articleId}]`)}`}function an(e){let t=[];for(let c of os){let d=e.entries.filter(g=>g.status===c.status);if(d.length!==0){t.push(""),t.push(Ce(c.header));for(let g of d)t.push(` ${c.paint(c.mark)} ${c.paint(ul(g))}${g.detail?ee(` (${g.detail})`):""}`)}}let n=e.counts["in-sync"]??0,o=e.entries.length;t.push("");let r={"in-sync":"in sync","local-ahead":"local ahead","remote-ahead":"remote ahead",conflict:"conflicts","untracked-local":"untracked local","untracked-remote":"untracked remote","deleted-local":"deleted locally","deleted-remote":"deleted on D360",orphaned:"orphaned","unknown-base":"no base yet"},s=o===n?A("\u2713 everything in sync"):[n>0?A(`\u2713 ${n} in sync`):null,...os.map(c=>{let d=e.counts[c.status]??0;return d>0?`${d} ${r[c.status]}`:null})].filter(Boolean).join(ee(" \xB7 "));return t.push(s+ee(` \xB7 ${o} tracked+seen \xB7 profile "${e.profile}" \xB7 docs root ${e.docsRoot}/`)),t}import{structuredPatch as dl}from"diff";import rs from"picocolors";var ss=80,pl="\x1B[48;2;74;28;28m",fl="\x1B[48;2;24;66;24m",is="\x1B[49m",no=e=>String(e).padStart(5);function qe(e,t,n){let o=y=>{let b=y.replace(/\r\n/g,`
39
+ `)}var es={"local-ahead":"modified locally","untracked-local":"new (never published)",conflict:"\u26A0 conflict \u2014 publishing overwrites the portal edit"};function Ct(e){return e.filter(t=>t.path!==null&&t.status in es).map(t=>({path:t.path,label:es[t.status]}))}function fl(e){let t=e.replace(/\\/g,"/").split("/").pop()??e,n=t.replace(/^\d+[-_]/,"").replace(/[-_]+/g," ").trim();return n?n.charAt(0).toUpperCase()+n.slice(1):t}function ts(e){let t=[];e.length>1&&t.push({kind:"all",label:`Publish all ${e.length} articles`,paths:e.map(o=>o.path),indent:!1});let n=new Map;for(let o of e){let r=o.path.replace(/\\/g,"/").split("/").slice(0,-1).join("/"),s=n.get(r);s?s.push(o):n.set(r,[o])}for(let o of[...n.keys()].sort()){let r=n.get(o).sort((s,c)=>s.path.localeCompare(c.path));t.push({kind:"category",label:`${fl(o)} (${r.length})`,paths:r.map(s=>s.path),indent:!1});for(let s of r){let c=s.path.replace(/\\/g,"/").split("/").pop()??s.path;t.push({kind:"article",label:c,paths:[s.path],indent:!0,note:s.label})}}return t}function nn(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(`
40
+ `)}function eo(e,t,n){let o=y=>t[y.index]?.paths.length??0,r=e.filter(y=>y.ok),s=e.filter(y=>!y.ok),c=e.reduce((y,b)=>y+o(b),0),d=r.reduce((y,b)=>y+o(b),0),g=n==="api"?`${ie(e.reduce((y,b)=>y+b.costUsd,0))} total`:Ee(e.reduce((y,b)=>y+b.outputTokens,0)),w=`${r.length}/${e.length} partition${e.length===1?"":"s"}`,$=y=>`${y} article${y===1?"":"s"}`,R=[];if(s.length===0)R.push(`Published ${$(c)} (${w}) successfully \xB7 ${g}.`),R.push("All are DRAFTS \u2014 review and publish them in the Document360 portal.");else{R.push(`Published ${d}/${$(c)} (${w}) \xB7 ${g}.`),R.push(`${s.length} partition${s.length===1?"":"s"} failed \u2014 re-run /publish --all to retry just the rest (published articles are skipped):`);for(let y of s)R.push(` \u2717 ${y.label}${y.error?` \u2014 ${y.error}`:""}`)}return R}async function Jn(e,t){let n=cl(t),{model:o}=dl(e.cwd,"standard");console.log(f(`Publishing ${t.length} article${t.length===1?"":"s"} across ${n.length} partition${n.length===1?"":"s"} (\u2264${vt} agents at once) on ${o}\u2026`)),console.log(f(" (mid-run abort is TUI-only \u2014 Ctrl+C exits the REPL.)"));try{for await(let r of pl({cwd:e.cwd,partitions:n,promptFor:s=>nn(s.paths),concurrency:vt,profileName:e.profileName,allowProdWrites:e.allowProdWrites(),model:o}))if(r.type==="partition_status")r.status==="running"?console.log(f(` \u25B8 ${r.label} \u2014 publishing\u2026`)):r.status==="done"?console.log(A(` \u2713 ${r.label}`)):console.log(x(` \u2717 ${r.label}`));else if(r.type==="run_done"){console.log("");let s=process.env.ANTHROPIC_API_KEY?"api":"subscription";for(let c of eo(r.results,n,s))console.log(r.ok?A(c):L(c))}}catch(r){console.log(x(`Publish run failed: ${r.message}`))}return console.log(""),{kind:"continue"}}async function on(e,t,n){let o=ul(e,n);if(o.length===0)return[];let r=new Set(Ct((await Qn({cwd:e,profileName:t})).entries).map(s=>s.path));return o.filter(s=>r.has(s))}async function ns(e,t){let n=e[0];if(n==="--related"&&e[1]){if(!t)return{kind:"continue"};let o=await on(t.cwd,t.profileName,e[1].replace(/\\/g,"/"));return o.length===0?(console.log(A("\u2713 All related articles are already published.")),{kind:"continue"}):await Jn(t,o)}if(n==="--all"){console.log(f("Checking what needs publishing\u2026"));try{let o=Ct((await Qn({cwd:t?.cwd??process.cwd()})).entries);return o.length===0?(console.log(A("\u2713 Nothing is ahead of Document360 \u2014 no publish candidates.")),{kind:"continue"}):t?await Jn(t,o.map(r=>r.path)):{kind:"forward-to-agent",prompt:nn(o.map(r=>r.path)),display:"/publish --all"}}catch(o){return console.log(x(`Could not compute sync status: ${o.message}`)),{kind:"continue"}}}if(!n){console.log(f("Checking what needs publishing\u2026"));let o;try{o=Ct((await Qn({cwd:t?.cwd??process.cwd()})).entries)}catch(r){return console.log(x(`Could not compute sync status: ${r.message}`)),console.log(f("Publish a specific article: /publish <article-path>")),{kind:"continue"}}if(o.length===0)return console.log(A("\u2713 Nothing is ahead of Document360 \u2014 no publish candidates.")),console.log(f(" (Articles without a sync base are unverified \u2014 publish those by path if needed.)")),{kind:"continue"};if(!process.stdin.isTTY||!t){for(let r of o)console.log(` ${r.path} ${f(`(${r.label})`)}`);return console.log(f("Run: /publish <article-path>")),{kind:"continue"}}try{n=await t.withPausedInput(()=>ll({message:"Publish which article?",choices:[...o.length>1?[{name:`All ${o.length} candidates`,value:"--all",description:"one agent run over every candidate"}]:[],...o.map(r=>({name:r.path,value:r.path,description:r.label}))]}))}catch{return console.log(f("Cancelled.")),{kind:"continue"}}if(n==="--all")return await Jn(t,o.map(r=>r.path))}return{kind:"forward-to-agent",prompt:Zn(n),display:`/publish ${n}`}}async function rn(){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.","2.5. d360_pending_hints \u2014 the source agent's own notes on what it shipped. Verify each (sources exist, commit is an ancestor of HEAD, source shows the surface) before trusting; fold verified ones into the table, flag the rest.","3. Map changes (diff + hints) 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 and stamp consumed hints.","","Do not start writing or updating any article yet \u2014 the proposal table is the deliverable."].join(`
41
+ `),display:"/audit"}}q();import{checkbox as ml}from"@inquirer/prompts";import{inventoryRepo as gl,readProjectConfig as os,writeProjectConfig as hl}from"document360-engine";function to(e,t){let n=os(e);n&&(n.authoritativeSourceFiles=t,hl(n,e))}function sn(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 rs(e,t){let n=t?.cwd??process.cwd();if(!os(n))return console.log(x("No .d360-writer.json here. Run /init first.")),{kind:"continue"};let o=gl(n);if(o.length===0)return console.log(f('No candidate source folders found. Set "authoritativeSourceFiles" in .d360-writer.json manually.')),{kind:"continue"};if(!process.stdin.isTTY||!t){console.log(""),console.log(E("Recommended documentation scope (run /scope in the REPL to choose):"));for(let s of o)console.log(` ${s.recommended?"\u25C9":"\u25CB"} ${s.path} ${f(sn(s))}`);return console.log(""),{kind:"continue"}}let r;try{r=await t.withPausedInput(()=>ml({message:"Which folders back the user docs? (space toggles, enter confirms)",choices:o.map(s=>({name:`${s.path} (${sn(s)})`,value:s.path,checked:s.recommended})),pageSize:20}))}catch{return console.log(f("Cancelled.")),{kind:"continue"}}if(r.length===0)return console.log(f("Nothing selected \u2014 scope unchanged.")),{kind:"continue"};to(n,r),console.log(A(`\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"}}q();import{confirm as xl}from"@inquirer/prompts";import{applyPull as cs,computeSyncStatus as us,planPull as bl,D360AuthError as vl}from"document360-engine";q();var ss=[{status:"conflict",header:"Conflicts \u2014 both sides changed; pick a direction (/sync pull <path> or /publish <path>):",paint:x,mark:"!"},{status:"local-ahead",header:"Local ahead \u2014 push with /publish <path>:",paint:L,mark:"M"},{status:"remote-ahead",header:"Remote ahead \u2014 pull with /sync pull <path>:",paint:E,mark:"M"},{status:"deleted-local",header:"Deleted locally \u2014 still on Document360 (pull to restore, or remove from the map):",paint:x,mark:"D"},{status:"deleted-remote",header:"Deleted on Document360 \u2014 still local (publish to recreate, or delete the file):",paint:x,mark:"D"},{status:"orphaned",header:"Orphaned map entries \u2014 gone on both sides (remove from d360-category-map.json):",paint:ee,mark:"X"},{status:"untracked-local",header:"Untracked local articles \u2014 publish to start tracking:",paint:f,mark:"?"},{status:"untracked-remote",header:"Untracked Document360 articles \u2014 no local file maps to them:",paint:f,mark:"?"},{status:"unknown-base",header:"No sync base recorded yet \u2014 the next /publish or /sync pull of each records one:",paint:ee,mark:"\xB7"}];function wl(e){return e.path?e.path:`${e.title??"(untitled)"} ${ee(`[${e.articleId}]`)}`}function an(e){let t=[];for(let c of ss){let d=e.entries.filter(g=>g.status===c.status);if(d.length!==0){t.push(""),t.push(Ce(c.header));for(let g of d)t.push(` ${c.paint(c.mark)} ${c.paint(wl(g))}${g.detail?ee(` (${g.detail})`):""}`)}}let n=e.counts["in-sync"]??0,o=e.entries.length;t.push("");let r={"in-sync":"in sync","local-ahead":"local ahead","remote-ahead":"remote ahead",conflict:"conflicts","untracked-local":"untracked local","untracked-remote":"untracked remote","deleted-local":"deleted locally","deleted-remote":"deleted on D360",orphaned:"orphaned","unknown-base":"no base yet"},s=o===n?A("\u2713 everything in sync"):[n>0?A(`\u2713 ${n} in sync`):null,...ss.map(c=>{let d=e.counts[c.status]??0;return d>0?`${d} ${r[c.status]}`:null})].filter(Boolean).join(ee(" \xB7 "));return t.push(s+ee(` \xB7 ${o} tracked+seen \xB7 profile "${e.profile}" \xB7 docs root ${e.docsRoot}/`)),t}import{structuredPatch as kl}from"diff";import is from"picocolors";var as=80,yl="\x1B[48;2;74;28;28m",$l="\x1B[48;2;24;66;24m",ls="\x1B[49m",no=e=>String(e).padStart(5);function qe(e,t,n){let o=y=>{let b=y.replace(/\r\n/g,`
42
42
  `);return b.endsWith(`
43
43
  `)||b===""?b:b+`
44
- `},r=o(e),s=o(t);if(r===s)return null;let c=Math.max(20,n-10),d=dl("a","b",r,s,"","",{context:3}),g=0,w=0,$=[];d.hunks.forEach((y,b)=>{b>0&&$.push(rs.gray(" \u2026"));let v=y.oldStart,N=y.newStart;for(let M of y.lines){let H=M[0],Z=M.slice(1).slice(0,c);H==="-"?(w++,$.push(`${pl}${no(v++)} - ${Z}${is}`)):H==="+"?(g++,$.push(`${fl}${no(N++)} + ${Z}${is}`)):($.push(rs.gray(no(N))+" "+Z),v++,N++)}});let R=$.slice(0,ss);return{added:g,removed:w,lines:R,hidden:Math.max(0,$.length-ss)}}async function cs(e,t){let n=(e[0]??"status").toLowerCase();try{if(n==="status")return await wl(t.cwd),{kind:"continue"};if(n==="pull")return await kl(t,e.slice(1)),{kind:"continue"};console.log(x(`Unknown subcommand: /sync ${n}`)),console.log(f("Usage: /sync drift report (local vs Document360)")),console.log(f(" /sync pull <path> pull portal edits into the local file")),console.log(f(" /sync pull --all pull every remote-ahead article"))}catch(o){o instanceof hl?console.log(x(o.message)):console.log(x(`Sync failed: ${o.message}`))}return{kind:"continue"}}async function wl(e){console.log(f("Checking Document360 for drift\u2026"));let t=await ls({cwd:e});for(let n of an(t))console.log(n);console.log("")}async function kl(e,t){let n=t[0];if(!n){console.log(x("Usage: /sync pull <article-path> | --all"));return}let o;if(n==="--all"){if(console.log(f("Checking Document360 for drift\u2026")),o=(await ls({cwd:e.cwd})).entries.filter(s=>s.status==="remote-ahead"&&s.path).map(s=>s.path),o.length===0){console.log(A("\u2713 Nothing is remote-ahead \u2014 no pulls needed.")),console.log(f(" (conflicts are never bulk-pulled; pull them one by one: /sync pull <path>)"));return}console.log(`${Ce(String(o.length))} article(s) are remote-ahead.`)}else o=[n.replace(/\\/g,"/")];for(let r of o){let s=await gl({cwd:e.cwd,relPath:r});console.log(""),console.log(`${E("\u25CF")} ${Ce(s.title)} ${ee(`(${s.path})`)}`);for(let w of s.notes)console.log(O(` \u26A0 ${w}`));s.overwritesLocalChanges&&console.log(O(" \u26A0 This OVERWRITES local edits made since the last sync."));let c=qe(s.oldContent,s.newContent,Math.max(40,(process.stdout.columns??80)-1));if(!c){console.log(f(" Local file already matches the remote content \u2014 advancing the sync base only.")),as({cwd:e.cwd},s);continue}let d=w=>w===1?"":"s";console.log(ee(` \u23BF Added ${c.added} line${d(c.added)}, removed ${c.removed} line${d(c.removed)}`));for(let w of c.lines)console.log(w);if(c.hidden>0&&console.log(f(` \u2026 +${c.hidden} more diff lines`)),!await e.withPausedInput(()=>ml({message:`Write ${s.path}?`,default:!s.overwritesLocalChanges}))){console.log(f(" Skipped."));continue}as({cwd:e.cwd},s),console.log(A(` \u2713 Pulled ${s.path} (sync base advanced).`))}console.log("")}q();import{statSync as yl}from"node:fs";import{resolve as $l}from"node:path";import{estimateBulkCost as xl,planPartitions as bl,readProjectConfig as vl,resolveModelForOperation as Cl,runPartitioned as Pl,trackedArticlePaths as Tl}from"document360-engine";var oo=3;function ro(e){let t,n=!1;for(let r=0;r<e.length;r++){let s=e[r];s==="--run"||s==="--yes"?n=!0:s==="--scope"?t=e[++r]:s?.startsWith("--scope=")&&(t=s.slice(8))}return{scope:t?.replace(/\\/g,"/").replace(/\/+$/,"")||void 0,run:n}}function so(e,t){return t?e.filter(n=>{let o=n.replace(/\\/g,"/");return o===t||o.startsWith(`${t}/`)}):e}function io(e,t){return t.map(n=>{let o=0;try{o=yl($l(e,n)).size}catch{o=0}return{path:n,bytes:o}})}function ao(e){return`Convert each of these articles to canonical Document360 Flavored Markdown (DFM) and re-publish each as a DRAFT. This is a mechanical syntax conversion, not a rewrite \u2014 be efficient:
44
+ `},r=o(e),s=o(t);if(r===s)return null;let c=Math.max(20,n-10),d=kl("a","b",r,s,"","",{context:3}),g=0,w=0,$=[];d.hunks.forEach((y,b)=>{b>0&&$.push(is.gray(" \u2026"));let v=y.oldStart,_=y.newStart;for(let M of y.lines){let H=M[0],Z=M.slice(1).slice(0,c);H==="-"?(w++,$.push(`${yl}${no(v++)} - ${Z}${ls}`)):H==="+"?(g++,$.push(`${$l}${no(_++)} + ${Z}${ls}`)):($.push(is.gray(no(_))+" "+Z),v++,_++)}});let R=$.slice(0,as);return{added:g,removed:w,lines:R,hidden:Math.max(0,$.length-as)}}async function ds(e,t){let n=(e[0]??"status").toLowerCase();try{if(n==="status")return await Cl(t.cwd),{kind:"continue"};if(n==="pull")return await Pl(t,e.slice(1)),{kind:"continue"};console.log(x(`Unknown subcommand: /sync ${n}`)),console.log(f("Usage: /sync drift report (local vs Document360)")),console.log(f(" /sync pull <path> pull portal edits into the local file")),console.log(f(" /sync pull --all pull every remote-ahead article"))}catch(o){o instanceof vl?console.log(x(o.message)):console.log(x(`Sync failed: ${o.message}`))}return{kind:"continue"}}async function Cl(e){console.log(f("Checking Document360 for drift\u2026"));let t=await us({cwd:e});for(let n of an(t))console.log(n);console.log("")}async function Pl(e,t){let n=t[0];if(!n){console.log(x("Usage: /sync pull <article-path> | --all"));return}let o;if(n==="--all"){if(console.log(f("Checking Document360 for drift\u2026")),o=(await us({cwd:e.cwd})).entries.filter(s=>s.status==="remote-ahead"&&s.path).map(s=>s.path),o.length===0){console.log(A("\u2713 Nothing is remote-ahead \u2014 no pulls needed.")),console.log(f(" (conflicts are never bulk-pulled; pull them one by one: /sync pull <path>)"));return}console.log(`${Ce(String(o.length))} article(s) are remote-ahead.`)}else o=[n.replace(/\\/g,"/")];for(let r of o){let s=await bl({cwd:e.cwd,relPath:r});console.log(""),console.log(`${E("\u25CF")} ${Ce(s.title)} ${ee(`(${s.path})`)}`);for(let w of s.notes)console.log(L(` \u26A0 ${w}`));s.overwritesLocalChanges&&console.log(L(" \u26A0 This OVERWRITES local edits made since the last sync."));let c=qe(s.oldContent,s.newContent,Math.max(40,(process.stdout.columns??80)-1));if(!c){console.log(f(" Local file already matches the remote content \u2014 advancing the sync base only.")),cs({cwd:e.cwd},s);continue}let d=w=>w===1?"":"s";console.log(ee(` \u23BF Added ${c.added} line${d(c.added)}, removed ${c.removed} line${d(c.removed)}`));for(let w of c.lines)console.log(w);if(c.hidden>0&&console.log(f(` \u2026 +${c.hidden} more diff lines`)),!await e.withPausedInput(()=>xl({message:`Write ${s.path}?`,default:!s.overwritesLocalChanges}))){console.log(f(" Skipped."));continue}cs({cwd:e.cwd},s),console.log(A(` \u2713 Pulled ${s.path} (sync base advanced).`))}console.log("")}q();import{statSync as Tl}from"node:fs";import{resolve as Sl}from"node:path";import{estimateBulkCost as Rl,planPartitions as jl,readProjectConfig as Dl,resolveModelForOperation as Al,runPartitioned as El,trackedArticlePaths as Il}from"document360-engine";var oo=3;function ro(e){let t,n=!1;for(let r=0;r<e.length;r++){let s=e[r];s==="--run"||s==="--yes"?n=!0:s==="--scope"?t=e[++r]:s?.startsWith("--scope=")&&(t=s.slice(8))}return{scope:t?.replace(/\\/g,"/").replace(/\/+$/,"")||void 0,run:n}}function so(e,t){return t?e.filter(n=>{let o=n.replace(/\\/g,"/");return o===t||o.startsWith(`${t}/`)}):e}function io(e,t){return t.map(n=>{let o=0;try{o=Tl(Sl(e,n)).size}catch{o=0}return{path:n,bytes:o}})}function ao(e){return`Convert each of these articles to canonical Document360 Flavored Markdown (DFM) and re-publish each as a DRAFT. This is a mechanical syntax conversion, not a rewrite \u2014 be efficient:
45
45
  - Read ONLY the article files listed below. Do NOT read source code, other articles, or fetch the live portal \u2014 you already have everything you need.
46
46
  - Convert in place: wrap callouts, FAQs, tabs, accordions, and media embeds per the d360-markdown skill. Preserve all wording, headings, and structure; change only GFM\u2192DFM syntax.
47
47
  - Publish each as a draft with a single update call. Do NOT re-read, re-verify, or polish after converting, and skip articles already in DFM.
48
48
  - Work only on these files:
49
49
  `+e.paths.map(t=>`- ${t}`).join(`
50
- `)}function lo(e,t,n){let o=e.reduce((d,g)=>d+g.paths.length,0),[r,s]=t.usd;return[`Convert ${o} article${o===1?"":"s"} to DFM across ${e.length} partition${e.length===1?"":"s"} (\u2264${n} agents at once):`,...e.map(d=>` \u2022 ${d.label} \u2014 ${d.paths.length} article${d.paths.length===1?"":"s"}`),"",`Estimated cost: ${ie(r)}\u2013${ie(s)}. ${t.note}`,"","Each article is rewritten and re-published as a DRAFT. Run /convert --run to start."]}function co(e,t,n){let o=v=>t[v.index]?.paths.length??0,r=e.filter(v=>v.ok),s=e.filter(v=>!v.ok),c=e.reduce((v,N)=>v+o(N),0),d=r.reduce((v,N)=>v+o(N),0),g=e.reduce((v,N)=>v+N.costUsd,0),w=e.reduce((v,N)=>v+N.outputTokens,0),$=n==="api"?`${ie(g)} total`:Ee(w),R=`${r.length}/${e.length} partition${e.length===1?"":"s"} completed`,y=v=>`${v} article${v===1?"":"s"}`,b=[];if(s.length===0)b.push(`Converted ${y(c)} (${R}) successfully \xB7 ${$}.`);else{b.push(`Converted ${d}/${y(c)} (${R}) \xB7 ${$}.`),b.push(`${s.length} partition${s.length===1?"":"s"} failed \u2014 re-run /convert to retry:`);for(let v of s)b.push(` \u2717 ${v.label}${v.error?` \u2014 ${v.error}`:""}`)}return b}async function us(e,t){if(!vl(t.cwd))return console.log(x("No d360-writer config here. Run /init first.")),{kind:"continue"};let{scope:n,run:o}=ro(e),r=Tl(t.cwd,t.profileName);if(r.length===0)return console.log(x("No tracked articles in d360-category-map.json. Publish some first (/publish), then /convert.")),{kind:"continue"};let s=so(r,n);if(s.length===0)return console.log(x(`No tracked articles under "${n}". (${r.length} are tracked overall.)`)),{kind:"continue"};let c=bl(s),d=`/convert${n?` --scope ${n}`:""} --run`,{model:g,forced:w}=Cl(t.cwd,"light");if(!o){let $=xl({files:io(t.cwd,s),op:"convert",model:g});n&&console.log(f(`Scope: ${n} (${s.length} of ${r.length} tracked articles).`));for(let R of lo(c,$,oo))console.log(R);return console.log(f(`Model: ${g}${w?" (forced)":" \u2014 mechanical work; /model to override"}.`)),console.log(f(`Run ${d} to start.`)),console.log(""),{kind:"continue"}}console.log(f(`Converting ${s.length} articles across ${c.length} partitions (\u2264${oo} agents at once) on ${g}\u2026`)),console.log(f(" (mid-run abort is TUI-only \u2014 Ctrl+C exits the REPL.)"));try{for await(let $ of Pl({cwd:t.cwd,partitions:c,promptFor:ao,concurrency:oo,profileName:t.profileName,allowProdWrites:t.allowProdWrites(),model:g}))if($.type==="partition_status")$.status==="running"?console.log(f(` \u25B8 ${$.label} \u2014 converting\u2026`)):$.status==="done"?console.log(A(` \u2713 ${$.label}`)):console.log(x(` \u2717 ${$.label}`));else if($.type==="run_done"){console.log("");let R=process.env.ANTHROPIC_API_KEY?"api":"subscription";for(let y of co($.results,c,R))console.log($.ok?A(y):O(y))}}catch($){console.log(x(`Convert run failed: ${$.message}`))}return console.log(""),{kind:"continue"}}q();import{statSync as ds}from"node:fs";import{resolve as ps}from"node:path";import{estimateBulkCost as Sl,planPartitions as Rl,readDocsPlan as jl,readProjectConfig as fs,DEFAULT_DOCS_DIR as Dl,resolveModelForOperation as Al,runPartitioned as El}from"document360-engine";var uo=5;function po(e){let t,n,o=!1;for(let s=0;s<e.length;s++){let c=e[s];if(c==="--run"||c==="--yes")o=!0;else{if(c==="--all")continue;c==="--scope"?t=e[++s]:c?.startsWith("--scope=")?t=c.slice(8):c&&!c.startsWith("--")&&(n=c)}}let r=s=>s?.replace(/\\/g,"/").replace(/\/+$/,"")||void 0;return{scope:r(t),path:r(n),run:o}}function Il(e,t){let n=e.replace(/\\/g,"/").replace(/\/+$/,""),o=`${t.replace(/\/+$/,"")}/`;return n.startsWith(o)?n.slice(o.length):n}function _l(e,t){return t?e.filter(n=>{let o=n.replace(/\\/g,"/");return o===t||o.startsWith(`${t}/`)}):e}function Nl(e,t,n){return n.filter(o=>{try{return ds(ps(e,t,o)).size===0}catch{return!0}})}function fo(e,t,n){let o=new Map(t.map(r=>[r.path,r]));return n.map(r=>{let s=1;for(let c of o.get(r)?.sources??[])try{s+=ds(ps(e,c)).size}catch{}return{path:r,bytes:s}})}function mo(e,t){return`Run the write-article skill to author EACH documentation article listed below. For each path:
50
+ `)}function lo(e,t,n){let o=e.reduce((d,g)=>d+g.paths.length,0),[r,s]=t.usd;return[`Convert ${o} article${o===1?"":"s"} to DFM across ${e.length} partition${e.length===1?"":"s"} (\u2264${n} agents at once):`,...e.map(d=>` \u2022 ${d.label} \u2014 ${d.paths.length} article${d.paths.length===1?"":"s"}`),"",`Estimated cost: ${ie(r)}\u2013${ie(s)}. ${t.note}`,"","Each article is rewritten and re-published as a DRAFT. Run /convert --run to start."]}function co(e,t,n){let o=v=>t[v.index]?.paths.length??0,r=e.filter(v=>v.ok),s=e.filter(v=>!v.ok),c=e.reduce((v,_)=>v+o(_),0),d=r.reduce((v,_)=>v+o(_),0),g=e.reduce((v,_)=>v+_.costUsd,0),w=e.reduce((v,_)=>v+_.outputTokens,0),$=n==="api"?`${ie(g)} total`:Ee(w),R=`${r.length}/${e.length} partition${e.length===1?"":"s"} completed`,y=v=>`${v} article${v===1?"":"s"}`,b=[];if(s.length===0)b.push(`Converted ${y(c)} (${R}) successfully \xB7 ${$}.`);else{b.push(`Converted ${d}/${y(c)} (${R}) \xB7 ${$}.`),b.push(`${s.length} partition${s.length===1?"":"s"} failed \u2014 re-run /convert to retry:`);for(let v of s)b.push(` \u2717 ${v.label}${v.error?` \u2014 ${v.error}`:""}`)}return b}async function ps(e,t){if(!Dl(t.cwd))return console.log(x("No d360-writer config here. Run /init first.")),{kind:"continue"};let{scope:n,run:o}=ro(e),r=Il(t.cwd,t.profileName);if(r.length===0)return console.log(x("No tracked articles in d360-category-map.json. Publish some first (/publish), then /convert.")),{kind:"continue"};let s=so(r,n);if(s.length===0)return console.log(x(`No tracked articles under "${n}". (${r.length} are tracked overall.)`)),{kind:"continue"};let c=jl(s),d=`/convert${n?` --scope ${n}`:""} --run`,{model:g,forced:w}=Al(t.cwd,"light");if(!o){let $=Rl({files:io(t.cwd,s),op:"convert",model:g});n&&console.log(f(`Scope: ${n} (${s.length} of ${r.length} tracked articles).`));for(let R of lo(c,$,oo))console.log(R);return console.log(f(`Model: ${g}${w?" (forced)":" \u2014 mechanical work; /model to override"}.`)),console.log(f(`Run ${d} to start.`)),console.log(""),{kind:"continue"}}console.log(f(`Converting ${s.length} articles across ${c.length} partitions (\u2264${oo} agents at once) on ${g}\u2026`)),console.log(f(" (mid-run abort is TUI-only \u2014 Ctrl+C exits the REPL.)"));try{for await(let $ of El({cwd:t.cwd,partitions:c,promptFor:ao,concurrency:oo,profileName:t.profileName,allowProdWrites:t.allowProdWrites(),model:g}))if($.type==="partition_status")$.status==="running"?console.log(f(` \u25B8 ${$.label} \u2014 converting\u2026`)):$.status==="done"?console.log(A(` \u2713 ${$.label}`)):console.log(x(` \u2717 ${$.label}`));else if($.type==="run_done"){console.log("");let R=process.env.ANTHROPIC_API_KEY?"api":"subscription";for(let y of co($.results,c,R))console.log($.ok?A(y):L(y))}}catch($){console.log(x(`Convert run failed: ${$.message}`))}return console.log(""),{kind:"continue"}}q();import{statSync as fs}from"node:fs";import{resolve as ms}from"node:path";import{estimateBulkCost as Nl,planPartitions as _l,readDocsPlan as Ml,readProjectConfig as gs,DEFAULT_DOCS_DIR as Ol,resolveModelForOperation as Ll,runPartitioned as Ul}from"document360-engine";var uo=5;function po(e){let t,n,o=!1;for(let s=0;s<e.length;s++){let c=e[s];if(c==="--run"||c==="--yes")o=!0;else{if(c==="--all")continue;c==="--scope"?t=e[++s]:c?.startsWith("--scope=")?t=c.slice(8):c&&!c.startsWith("--")&&(n=c)}}let r=s=>s?.replace(/\\/g,"/").replace(/\/+$/,"")||void 0;return{scope:r(t),path:r(n),run:o}}function Wl(e,t){let n=e.replace(/\\/g,"/").replace(/\/+$/,""),o=`${t.replace(/\/+$/,"")}/`;return n.startsWith(o)?n.slice(o.length):n}function Fl(e,t){return t?e.filter(n=>{let o=n.replace(/\\/g,"/");return o===t||o.startsWith(`${t}/`)}):e}function Hl(e,t,n){return n.filter(o=>{try{return fs(ms(e,t,o)).size===0}catch{return!0}})}function fo(e,t,n){let o=new Map(t.map(r=>[r.path,r]));return n.map(r=>{let s=1;for(let c of o.get(r)?.sources??[])try{s+=fs(ms(e,c)).size}catch{}return{path:r,bytes:s}})}function mo(e,t){return`Run the write-article skill to author EACH documentation article listed below. For each path:
51
51
  - It is relative to ${t}/. Look up its entry (matching "path") in .d360-writer/plan.json for its purpose and the source files it draws from (AGENT-PLAN.md has the same table).
52
52
  - Read ONLY those source files plus any shared context you genuinely need, and ground every statement in them. Never invent UI labels, routes, or behaviour \u2014 if the source does not say it, omit it.
53
53
  - Write the finished article to ${t}/<path>, following the write-article structure and the project terminologyGlossary. Add the \`sources:\` frontmatter listing the files you actually read.
@@ -55,39 +55,67 @@ No MCP servers registered. Add one with /mcp add <name> <type> <ref>
55
55
  - Each article is independent. Do NOT write, edit, or publish any article not in this list, and do NOT publish to Document360 \u2014 these are local drafts.
56
56
  Articles:
57
57
  `+e.paths.map(n=>`- ${n}`).join(`
58
- `)}function go(e,t,n){let o=e.reduce((c,d)=>c+d.paths.length,0),[r,s]=t.usd;return[`Write ${o} article${o===1?"":"s"} across ${e.length} partition${e.length===1?"":"s"} (\u2264${n} agents at once):`,...e.map(c=>` \u2022 ${c.label} \u2014 ${c.paths.length} article${c.paths.length===1?"":"s"}`),"",`Estimated cost: ${ie(r)}\u2013${ie(s)}. ${t.note}`,"","Articles are written as local drafts in the docs tree (nothing is published). Run /write --run to start."]}function ho(e,t,n){let o=v=>t[v.index]?.paths.length??0,r=e.filter(v=>v.ok),s=e.filter(v=>!v.ok),c=e.reduce((v,N)=>v+o(N),0),d=r.reduce((v,N)=>v+o(N),0),g=e.reduce((v,N)=>v+N.costUsd,0),w=e.reduce((v,N)=>v+N.outputTokens,0),$=n==="api"?`${ie(g)} total`:Ee(w),R=`${r.length}/${e.length} partition${e.length===1?"":"s"} completed`,y=v=>`${v} article${v===1?"":"s"}`,b=[];if(s.length===0)b.push(`Wrote ${y(c)} (${R}) successfully \xB7 ${$}.`),b.push("Next \u2014 push them to Document360:"),b.push("/publish --all"),b.push("Or add screenshots first with /screenshot --all. Drafts are reviewable in the portal after publishing.");else{b.push(`Wrote ${d}/${y(c)} (${R}) \xB7 ${$}.`),b.push(`${s.length} partition${s.length===1?"":"s"} failed \u2014 re-run /write to retry the rest:`);for(let v of s)b.push(` \u2717 ${v.label}${v.error?` \u2014 ${v.error}`:""}`)}return b}function wo(e,t,n){let o=(fs(e)?.docsDir??Dl).replace(/\/+$/,""),r=t.map(d=>d.path);if(n.path){let d=Il(n.path,o);return r.includes(d)?{docsDir:o,targets:[d],planCount:r.length}:{docsDir:o,targets:[],planCount:r.length,reason:`"${d}" isn't in the docs plan (.d360-writer/plan.json).`}}let s=_l(r,n.scope);if(n.scope&&s.length===0)return{docsDir:o,targets:[],planCount:r.length,reason:`No planned articles under "${n.scope}".`};let c=Nl(e,o,s);if(c.length===0){let d=n.scope?` under "${n.scope}"`:"";return{docsDir:o,targets:[],planCount:r.length,reason:`All planned articles${d} are already written. Use /write <path> to rewrite one.`}}return{docsDir:o,targets:c,planCount:r.length}}async function ms(e,t){if(!fs(t.cwd))return console.log(x("No d360-writer config here. Run /init first.")),{kind:"continue"};let n=jl(t.cwd);if(n.length===0)return console.log(x("No docs plan found (.d360-writer/plan.json). Analyze the repo and propose a structure first.")),{kind:"continue"};let{scope:o,path:r,run:s}=po(e),{docsDir:c,targets:d,reason:g}=wo(t.cwd,n,{scope:o,path:r});if(d.length===0)return console.log(g?O(g):O("Nothing to write.")),{kind:"continue"};let w=Rl(d),{model:$,forced:R}=Al(t.cwd,"standard");if(!s&&!!!r){let b=Sl({files:fo(t.cwd,n,d),op:"write",model:$});o&&console.log(f(`Scope: ${o} (${d.length} pending).`));for(let v of go(w,b,uo))console.log(v);return console.log(f(`Model: ${$}${R?" (forced)":" \u2014 authoring; /model to override"}.`)),console.log(f(`Run /write${o?` --scope ${o}`:" --all"} --run to start.`)),console.log(""),{kind:"continue"}}console.log(f(`Writing ${d.length} article${d.length===1?"":"s"} across ${w.length} partition${w.length===1?"":"s"} (\u2264${uo} agents at once) on ${$}\u2026`)),console.log(f(" (mid-run abort is TUI-only \u2014 Ctrl+C exits the REPL.)"));try{for await(let b of El({cwd:t.cwd,partitions:w,promptFor:v=>mo(v,c),concurrency:uo,profileName:t.profileName,allowProdWrites:t.allowProdWrites(),model:$}))if(b.type==="partition_status")b.status==="running"?console.log(f(` \u25B8 ${b.label} \u2014 writing\u2026`)):b.status==="done"?console.log(A(` \u2713 ${b.label}`)):console.log(x(` \u2717 ${b.label}`));else if(b.type==="run_done"){console.log("");let v=process.env.ANTHROPIC_API_KEY?"api":"subscription";for(let N of ho(b.results,w,v))console.log(b.ok?A(N):O(N))}}catch(b){console.log(x(`Write run failed: ${b.message}`))}return console.log(""),{kind:"continue"}}q();import{existsSync as Ml,readdirSync as gs,statSync as hs}from"node:fs";import{join as ws}from"node:path";import{inputDir as Ll,readProjectConfig as Ol}from"document360-engine";var ks=/\.(md|markdown|pdf|txt)$/i;function ko(e){let t=Ll(e);if(!Ml(t))return{features:[],looseDocs:0};let n=[],o=0;for(let r of gs(t)){let s=ws(t,r),c=!1;try{c=hs(s).isDirectory()}catch{continue}if(c){if(r.startsWith("."))continue;let d=Ul(s);d>0&&n.push({name:r,docCount:d})}else ks.test(r)&&o++}return n.sort((r,s)=>r.name.localeCompare(s.name)),{features:n,looseDocs:o}}function Ul(e){let t=0;for(let n of gs(e))try{hs(ws(e,n)).isFile()&&ks.test(n)&&t++}catch{}return t}function yo(e,t){let n=t.trim().toLowerCase();return n?e.find(o=>o.name.toLowerCase()===n)?.name??e.find(o=>o.name.toLowerCase().startsWith(n))?.name??e.find(o=>o.name.toLowerCase().includes(n))?.name??null:null}function ln(e,t){return["Run the draft-from-prd skill.","",`Target scope: ${e?`the feature documents in .d360-writer/input/${e}/`:t?`the input docs in .d360-writer/input/ relevant to: "${t}"`:"the input docs in .d360-writer/input/"}.`,t&&!e?`Use "${t}" as the feature framing.`:"","","Follow the skill: (1) read those PRDs/specs as the primary source (intent, user-facing surface,","terminology, user stories, prerequisites); (2) locate and read the CODE that implements that surface","to pin exact UI strings/routes/states \u2014 never fabricate; flag anything the PRD claims that you","cannot find in source; (3) propose a tight feature-scoped article set (\u22483\u20135) and pin it to",".d360-writer/plan.json + AGENT-PLAN.md, with each article's `sources` listing BOTH the PRD file(s)","AND the grounding code files; (4) flag overlaps with existing articles (do not merge). Then stop and","offer /write --all. Do NOT write the articles in this turn."].filter(Boolean).join(`
59
- `)}var $o="No input docs found. Drop this feature's PRDs/specs in .d360-writer/input/<feature>/ (.md or .pdf), then run /draft.";async function ys(e,t){let n=t?.cwd??process.cwd();if(!Ol(n))return console.log(x("No d360-writer config here. Run /init first.")),{kind:"continue"};let{features:o,looseDocs:r}=ko(n);if(o.length===0&&r===0)return console.log(f($o)),{kind:"continue"};let s=e.join(" ").trim();if(!s){if(o.length>1){console.log(f("Multiple features in .d360-writer/input/ \u2014 draft which one? Run: /draft <feature>"));for(let g of o)console.log(` ${g.name} ${f(`(${g.docCount} doc${g.docCount===1?"":"s"})`)}`);return{kind:"continue"}}let d=o[0]?.name??"";return{kind:"forward-to-agent",prompt:ln(d),display:d?`/draft ${d}`:"/draft"}}let c=yo(o,s);return{kind:"forward-to-agent",prompt:ln(c??"",c?void 0:s),display:`/draft ${s}`}}q();import{search as Wl}from"@inquirer/prompts";import{findByName as Fl,getSession as Hl,listSessions as Bl,relativeTime as xs}from"document360-engine";async function bs(e,t){let n=Bl(t.cwd).filter(o=>o.uuid!==t.currentUuid());if(n.length===0)return console.log(f("No saved sessions for this repo yet \u2014 sessions auto-save as you work.")),{kind:"continue"};if(e.length>0){let o=e.join(" "),r=Fl(t.cwd,o);return r?{kind:"resume",uuid:r.uuid,name:r.name}:(console.log(x(`No session matches "${o}".`)),$s(n),{kind:"continue"})}if(!process.stdin.isTTY)return $s(n),console.log(f("Run: /resume <name>")),{kind:"continue"};try{let o=await t.withPausedInput(()=>Wl({message:"Resume session (type to filter, \u2191\u2193 to navigate):",source:async s=>{let c=(s??"").toLowerCase();return n.filter(d=>!c||d.name.toLowerCase().includes(c)||d.firstPrompt.toLowerCase().includes(c)).map(d=>({name:`${d.name} ${xs(d.updatedAt)}`,value:d.uuid,description:d.firstPrompt.slice(0,100)}))}})),r=Hl(o);return r?{kind:"resume",uuid:r.uuid,name:r.name}:{kind:"continue"}}catch{return console.log(""),{kind:"continue"}}}function $s(e){console.log("");for(let t of e.slice(0,15))console.log(` ${E(t.name)} ${f(xs(t.updatedAt))}`),console.log(` ${f(t.firstPrompt.slice(0,80))}`);console.log("")}q();import{renameSession as ql}from"document360-engine";function xo(e){let t=e.trim();return t.length>=2&&(t[0]==='"'&&t.endsWith('"')||t[0]==="'"&&t.endsWith("'"))?t.slice(1,-1).trim():t}async function vs(e,t){let n=xo(e.join(" "));if(!n)return console.log(x("Usage: /rename <new name>")),{kind:"continue"};let o=t.currentUuid();return o?(ql(o,n)?console.log(A(`\u2713 Session renamed to "${n}"`)):console.log(x("Could not find the current session record.")),{kind:"continue"}):(console.log(x("Nothing to rename yet \u2014 send a message first; sessions auto-save once the agent replies.")),{kind:"continue"})}import{knownEnvironments as Cs,readProjectConfig as Gl,writeProjectConfig as zl}from"document360-engine";q();function bo(e,t,n){if(!t)return"Usage: /profile add <name> [environment]";let o=Gl(e);if(!o)return"No .d360-writer.json \u2014 run /init first.";if(o.profiles?.[t])return`Profile "${t}" already exists.`;let r=n??t;return Cs().includes(r)?(o.profiles={...o.profiles,[t]:{connection:{environment:r},production:!1}},zl(o,e),null):`Unknown environment "${r}". Known: ${Cs().join(", ")} (or add the profile with explicit URLs in .d360-writer.json).`}async function Ps(e,t){let n=e[0];if(!n)return Kt(t.cwd),{kind:"continue"};if(n==="add"){let o=bo(t.cwd,e[1],e[2]);return o?(console.log(x(o)),{kind:"continue"}):(console.log(A(`\u2713 Profile "${e[1]}" created (environment: ${e[2]??e[1]}).`)),console.log(` Switch + sign in: ${E(`/profile ${e[1]}`)} then ${E("/login")}`),{kind:"continue"})}return Jt(t.cwd,n),Qt(t.cwd,n),console.log(f(" Restarting agent for the new profile\u2026")),{kind:"clear"}}q();import{select as Yl}from"@inquirer/prompts";import{readProjectConfig as Vl,readUserConfig as Ts,resolveModelSetting as vo,writeUserConfig as Ss}from"document360-engine";var ye=[{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 cn(e){if(e.model===null||e.source==="claude-settings")return 0;let t=e.model.toLowerCase(),n=ye.findIndex(o=>o.value!==null&&(o.value===t||o.label.toLowerCase()===t||t.includes(o.label.toLowerCase())));return n>=0?n:0}function Xl(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 Pt(e,t){let n=()=>{let s=vo(e);return s.source==="project"||s.source==="user"||s.source==="env"?s.model??void 0:void 0};if(t==="default"){let s=Ts();return s.defaultModel?(delete s.defaultModel,Ss(s),{lines:[`\u2713 Personal model override cleared \u2014 now: ${vo(e).model??"Claude Code default"} (applies from your next message)`],changed:!0,effective:n()}):{lines:["No personal model override set \u2014 nothing to clear."],changed:!1,effective:void 0}}Ss({...Ts(),defaultModel:t});let o=[`\u2713 Personal model set to "${t}" (applies from your next message \u2014 conversation continues)`],r=Vl(e)?.defaultModel;return r&&o.push(`\u26A0 .d360-writer.json sets defaultModel "${r}" \u2014 the team setting overrides yours until it is removed.`),{lines:o,changed:!0,effective:n()}}async function Rs(e,t){let n=e[0]?.trim();if(!n){let c=vo(t.cwd);if(!process.stdin.isTTY)return console.log(`${Ce("Model:")} ${E(c.model??"Claude Code default")}`),console.log(f(` source: ${Xl(c)}`)),console.log(f(" change: /model <haiku|sonnet|opus|full-model-id> \xB7 reset: /model default")),{kind:"continue"};let d=cn(c),g;try{g=await t.withPausedInput(()=>Yl({message:`Select model (current: ${c.model??"Claude Code default"})`,default:ye[d].value,choices:ye.map((y,b)=>({name:`${y.label}${b===d?" \u2714":""}`,value:y.value,description:y.desc}))}))}catch{return console.log(f("Cancelled.")),{kind:"continue"}}let{lines:w,changed:$,effective:R}=Pt(t.cwd,g??"default");for(let y of w)console.log(y.startsWith("\u26A0")?O(y):y.startsWith("\u2713")?A(y):f(y));return $&&await t.setModel(R),{kind:"continue"}}let{lines:o,changed:r,effective:s}=Pt(t.cwd,n);for(let c of o)console.log(c.startsWith("\u26A0")?O(c):c.startsWith("\u2713")?A(c):f(c));return r&&await t.setModel(s),{kind:"continue"}}un();async function Is(e,t){return await t.withPausedInput(()=>lt(t.cwd)),{kind:"clear"}}q();import{select as ac}from"@inquirer/prompts";import{resolveActiveProfile as lc,setProfileProject as cc,listProjects as uc}from"document360-engine";async function Po(e,t){let n=lc(e,t),o={profile:n.name,connection:n.connection};return{projects:await uc(o),profile:n.name,environment:n.connection.name,current:n.project.projectId}}var _s=e=>`${e.name??e.id}${e.sub_domain?` \xB7 ${e.sub_domain}`:""}`;function Ns(e,t){let n=t.toLowerCase();return e.find(o=>(o.name??"").toLowerCase()===n)??e.find(o=>(o.name??"").toLowerCase().startsWith(n))??e.find(o=>o.id.startsWith(t))}function To(e,t,n){cc(e,t,{projectId:n,workspaceId:void 0,workspaceName:void 0})}async function Ms(e,t){let n;try{n=await Po(e,t)}catch(g){console.log(x(`Could not list projects: ${g.message}`));return}let{projects:o,profile:r,current:s}=n;if(o.length===0){console.log(f("No projects found for this identity."));return}if(!process.stdin.isTTY){console.log("");for(let g of o)console.log(` ${g.id===s?E("\u25CF"):" "} ${_s(g)} ${f(g.id)}`);console.log(f("Run: d360-writer project use <name>"));return}let c=await ac({message:"Select the Document360 project for this repo:",choices:o.map(g=>({name:`${_s(g)}${g.id===s?" (current)":""}`,value:g.id}))});To(e,r,c);let d=o.find(g=>g.id===c);console.log(A(`\u2713 Project set to "${d?.name??c}" for profile "${r}". Next: pick a workspace.`))}async function Ls(e,t){return await t.withPausedInput(()=>Ms(t.cwd,t.profileName)),{kind:"clear"}}q();import{resolveActiveProfile as dc}from"document360-engine";async function Os(e,t){let n=!1;try{n=dc(t.cwd).production}catch{}return n?(console.log(O("\u26A0 Authorizing writes to the PRODUCTION profile for this session.")),{kind:"allow-prod"}):(console.log(f("Current profile is not a production profile \u2014 writes are already allowed.")),{kind:"continue"})}q();var Us=async(e,t)=>{try{await t.withPausedInput(()=>Xt({}))}catch(n){console.log(x(`Login failed: ${n.message}`))}return{kind:"continue"}};q();import{resolveActiveProfile as pc,clearTokens as fc,clearProfileProject as mc}from"document360-engine";async function Ws(e,t){let n;try{n=pc(t.cwd,t.profileName).name}catch(r){return console.log(x(r.message)),{kind:"continue"}}let o=fc(n);return mc(t.cwd,n),console.log(o?A(`\u2713 Signed out of "${n}" and cleared its project/workspace selection.`):f(`Profile "${n}" was not signed in. Cleared any project/workspace selection.`)),console.log(f("Run /login to sign in and pick a project.")),{kind:"continue"}}import{existsSync as Fs}from"node:fs";import{isAbsolute as gc,join as hc,resolve as wc}from"node:path";import{readProjectConfig as kc,screenshotPlaceholderIds as yc,DEFAULT_CAPTURE_DIR as $c,DEFAULT_OUTPUT_DIR as xc}from"document360-engine";var Hs=e=>e.replace(/\\/g,"/").replace(/\/+$/,"");function So(e){let t=!e.includes("--no-setup"),n=e.filter(r=>r!=="--no-setup");if(n[0]==="--list")return{mode:"list",scope:n[1]?Hs(n[1]):void 0};let o=n[0];return!o||o==="--all"?{mode:"all",setup:t}:/[\\/]/.test(o)||o.endsWith(".md")?{mode:"scope",scope:Hs(o),setup:t}:{mode:"single",id:o}}function Ro(e,t){let n=kc(e),o=n?.captureDir??$c,r=n?.outputDir??xc,s=(c,d)=>gc(c)?hc(c,d):wc(e,c,d);return yc(e,{scope:t}).map(({id:c,file:d})=>{let g=Fs(s(r,`${c}.png`))?"captured":Fs(s(o,`${c}.spec.ts`))?"spec":"placeholder";return{id:c,file:d,state:g}})}var bc={placeholder:"\u25CB",spec:"\u25D0",captured:"\u25CF"},vc={placeholder:"placeholder only",spec:"spec written, not captured",captured:"captured"};function jo(e,t){if(e.length===0)return[t?`No screenshot placeholders under ${t}.`:"No screenshot placeholders found in the docs."];let n=[...new Set(e.map(s=>s.file))].sort(),o=e.filter(s=>s.state==="captured").length,r=[`Screenshots: ${e.length} placeholder${e.length===1?"":"s"} across ${n.length} article${n.length===1?"":"s"} \xB7 ${o} captured${t?` \xB7 scope ${t}`:""}`,""];for(let s of n){r.push(s);for(let c of e.filter(d=>d.file===s))r.push(` ${bc[c.state]} ${c.id.padEnd(34)} ${vc[c.state]}`)}return r.push("","\u25CB placeholder only \u25D0 spec written \u25CF captured"),r}function Bs(e){return["Run the emit-screenshot-spec skill to author the document360-capture spec for EACH of these","SCREENSHOT placeholder ids:",e.paths.map(t=>`- ${t}`).join(`
58
+ `)}function go(e,t,n){let o=e.reduce((c,d)=>c+d.paths.length,0),[r,s]=t.usd;return[`Write ${o} article${o===1?"":"s"} across ${e.length} partition${e.length===1?"":"s"} (\u2264${n} agents at once):`,...e.map(c=>` \u2022 ${c.label} \u2014 ${c.paths.length} article${c.paths.length===1?"":"s"}`),"",`Estimated cost: ${ie(r)}\u2013${ie(s)}. ${t.note}`,"","Articles are written as local drafts in the docs tree (nothing is published). Run /write --run to start."]}function ho(e,t,n){let o=v=>t[v.index]?.paths.length??0,r=e.filter(v=>v.ok),s=e.filter(v=>!v.ok),c=e.reduce((v,_)=>v+o(_),0),d=r.reduce((v,_)=>v+o(_),0),g=e.reduce((v,_)=>v+_.costUsd,0),w=e.reduce((v,_)=>v+_.outputTokens,0),$=n==="api"?`${ie(g)} total`:Ee(w),R=`${r.length}/${e.length} partition${e.length===1?"":"s"} completed`,y=v=>`${v} article${v===1?"":"s"}`,b=[];if(s.length===0)b.push(`Wrote ${y(c)} (${R}) successfully \xB7 ${$}.`),b.push("Next \u2014 push them to Document360:"),b.push("/publish --all"),b.push("Or add screenshots first with /screenshot --all. Drafts are reviewable in the portal after publishing.");else{b.push(`Wrote ${d}/${y(c)} (${R}) \xB7 ${$}.`),b.push(`${s.length} partition${s.length===1?"":"s"} failed \u2014 re-run /write to retry the rest:`);for(let v of s)b.push(` \u2717 ${v.label}${v.error?` \u2014 ${v.error}`:""}`)}return b}function wo(e,t,n){let o=(gs(e)?.docsDir??Ol).replace(/\/+$/,""),r=t.map(d=>d.path);if(n.path){let d=Wl(n.path,o);return r.includes(d)?{docsDir:o,targets:[d],planCount:r.length}:{docsDir:o,targets:[],planCount:r.length,reason:`"${d}" isn't in the docs plan (.d360-writer/plan.json).`}}let s=Fl(r,n.scope);if(n.scope&&s.length===0)return{docsDir:o,targets:[],planCount:r.length,reason:`No planned articles under "${n.scope}".`};let c=Hl(e,o,s);if(c.length===0){let d=n.scope?` under "${n.scope}"`:"";return{docsDir:o,targets:[],planCount:r.length,reason:`All planned articles${d} are already written. Use /write <path> to rewrite one.`}}return{docsDir:o,targets:c,planCount:r.length}}async function hs(e,t){if(!gs(t.cwd))return console.log(x("No d360-writer config here. Run /init first.")),{kind:"continue"};let n=Ml(t.cwd);if(n.length===0)return console.log(x("No docs plan found (.d360-writer/plan.json). Analyze the repo and propose a structure first.")),{kind:"continue"};let{scope:o,path:r,run:s}=po(e),{docsDir:c,targets:d,reason:g}=wo(t.cwd,n,{scope:o,path:r});if(d.length===0)return console.log(g?L(g):L("Nothing to write.")),{kind:"continue"};let w=_l(d),{model:$,forced:R}=Ll(t.cwd,"standard");if(!s&&!!!r){let b=Nl({files:fo(t.cwd,n,d),op:"write",model:$});o&&console.log(f(`Scope: ${o} (${d.length} pending).`));for(let v of go(w,b,uo))console.log(v);return console.log(f(`Model: ${$}${R?" (forced)":" \u2014 authoring; /model to override"}.`)),console.log(f(`Run /write${o?` --scope ${o}`:" --all"} --run to start.`)),console.log(""),{kind:"continue"}}console.log(f(`Writing ${d.length} article${d.length===1?"":"s"} across ${w.length} partition${w.length===1?"":"s"} (\u2264${uo} agents at once) on ${$}\u2026`)),console.log(f(" (mid-run abort is TUI-only \u2014 Ctrl+C exits the REPL.)"));try{for await(let b of Ul({cwd:t.cwd,partitions:w,promptFor:v=>mo(v,c),concurrency:uo,profileName:t.profileName,allowProdWrites:t.allowProdWrites(),model:$}))if(b.type==="partition_status")b.status==="running"?console.log(f(` \u25B8 ${b.label} \u2014 writing\u2026`)):b.status==="done"?console.log(A(` \u2713 ${b.label}`)):console.log(x(` \u2717 ${b.label}`));else if(b.type==="run_done"){console.log("");let v=process.env.ANTHROPIC_API_KEY?"api":"subscription";for(let _ of ho(b.results,w,v))console.log(b.ok?A(_):L(_))}}catch(b){console.log(x(`Write run failed: ${b.message}`))}return console.log(""),{kind:"continue"}}q();import{existsSync as Bl,readdirSync as ws,statSync as ks}from"node:fs";import{join as ys}from"node:path";import{inputDir as ql,readProjectConfig as Gl}from"document360-engine";var $s=/\.(md|markdown|pdf|txt)$/i;function ko(e){let t=ql(e);if(!Bl(t))return{features:[],looseDocs:0};let n=[],o=0;for(let r of ws(t)){let s=ys(t,r),c=!1;try{c=ks(s).isDirectory()}catch{continue}if(c){if(r.startsWith("."))continue;let d=zl(s);d>0&&n.push({name:r,docCount:d})}else $s.test(r)&&o++}return n.sort((r,s)=>r.name.localeCompare(s.name)),{features:n,looseDocs:o}}function zl(e){let t=0;for(let n of ws(e))try{ks(ys(e,n)).isFile()&&$s.test(n)&&t++}catch{}return t}function yo(e,t){let n=t.trim().toLowerCase();return n?e.find(o=>o.name.toLowerCase()===n)?.name??e.find(o=>o.name.toLowerCase().startsWith(n))?.name??e.find(o=>o.name.toLowerCase().includes(n))?.name??null:null}function ln(e,t){return["Run the draft-from-prd skill.","",`Target scope: ${e?`the feature documents in .d360-writer/input/${e}/`:t?`the input docs in .d360-writer/input/ relevant to: "${t}"`:"the input docs in .d360-writer/input/"}.`,t&&!e?`Use "${t}" as the feature framing.`:"","","Follow the skill: (1) read those PRDs/specs as the primary source (intent, user-facing surface,","terminology, user stories, prerequisites); (2) locate and read the CODE that implements that surface","to pin exact UI strings/routes/states \u2014 never fabricate; flag anything the PRD claims that you","cannot find in source; (3) propose a tight feature-scoped article set (\u22483\u20135) and pin it to",".d360-writer/plan.json + AGENT-PLAN.md, with each article's `sources` listing BOTH the PRD file(s)","AND the grounding code files; (4) flag overlaps with existing articles (do not merge). Then stop and","offer /write --all. Do NOT write the articles in this turn."].filter(Boolean).join(`
59
+ `)}var $o="No input docs found. Drop this feature's PRDs/specs in .d360-writer/input/<feature>/ (.md or .pdf), then run /draft.";async function xs(e,t){let n=t?.cwd??process.cwd();if(!Gl(n))return console.log(x("No d360-writer config here. Run /init first.")),{kind:"continue"};let{features:o,looseDocs:r}=ko(n);if(o.length===0&&r===0)return console.log(f($o)),{kind:"continue"};let s=e.join(" ").trim();if(!s){if(o.length>1){console.log(f("Multiple features in .d360-writer/input/ \u2014 draft which one? Run: /draft <feature>"));for(let g of o)console.log(` ${g.name} ${f(`(${g.docCount} doc${g.docCount===1?"":"s"})`)}`);return{kind:"continue"}}let d=o[0]?.name??"";return{kind:"forward-to-agent",prompt:ln(d),display:d?`/draft ${d}`:"/draft"}}let c=yo(o,s);return{kind:"forward-to-agent",prompt:ln(c??"",c?void 0:s),display:`/draft ${s}`}}q();import{search as Yl}from"@inquirer/prompts";import{findByName as Vl,getSession as Xl,listSessions as Kl,relativeTime as vs}from"document360-engine";async function Cs(e,t){let n=Kl(t.cwd).filter(o=>o.uuid!==t.currentUuid());if(n.length===0)return console.log(f("No saved sessions for this repo yet \u2014 sessions auto-save as you work.")),{kind:"continue"};if(e.length>0){let o=e.join(" "),r=Vl(t.cwd,o);return r?{kind:"resume",uuid:r.uuid,name:r.name}:(console.log(x(`No session matches "${o}".`)),bs(n),{kind:"continue"})}if(!process.stdin.isTTY)return bs(n),console.log(f("Run: /resume <name>")),{kind:"continue"};try{let o=await t.withPausedInput(()=>Yl({message:"Resume session (type to filter, \u2191\u2193 to navigate):",source:async s=>{let c=(s??"").toLowerCase();return n.filter(d=>!c||d.name.toLowerCase().includes(c)||d.firstPrompt.toLowerCase().includes(c)).map(d=>({name:`${d.name} ${vs(d.updatedAt)}`,value:d.uuid,description:d.firstPrompt.slice(0,100)}))}})),r=Xl(o);return r?{kind:"resume",uuid:r.uuid,name:r.name}:{kind:"continue"}}catch{return console.log(""),{kind:"continue"}}}function bs(e){console.log("");for(let t of e.slice(0,15))console.log(` ${E(t.name)} ${f(vs(t.updatedAt))}`),console.log(` ${f(t.firstPrompt.slice(0,80))}`);console.log("")}q();import{renameSession as Jl}from"document360-engine";function xo(e){let t=e.trim();return t.length>=2&&(t[0]==='"'&&t.endsWith('"')||t[0]==="'"&&t.endsWith("'"))?t.slice(1,-1).trim():t}async function Ps(e,t){let n=xo(e.join(" "));if(!n)return console.log(x("Usage: /rename <new name>")),{kind:"continue"};let o=t.currentUuid();return o?(Jl(o,n)?console.log(A(`\u2713 Session renamed to "${n}"`)):console.log(x("Could not find the current session record.")),{kind:"continue"}):(console.log(x("Nothing to rename yet \u2014 send a message first; sessions auto-save once the agent replies.")),{kind:"continue"})}import{knownEnvironments as Ts,readProjectConfig as Ql,writeProjectConfig as Zl}from"document360-engine";q();function bo(e,t,n){if(!t)return"Usage: /profile add <name> [environment]";let o=Ql(e);if(!o)return"No .d360-writer.json \u2014 run /init first.";if(o.profiles?.[t])return`Profile "${t}" already exists.`;let r=n??t;return Ts().includes(r)?(o.profiles={...o.profiles,[t]:{connection:{environment:r},production:!1}},Zl(o,e),null):`Unknown environment "${r}". Known: ${Ts().join(", ")} (or add the profile with explicit URLs in .d360-writer.json).`}async function Ss(e,t){let n=e[0];if(!n)return Kt(t.cwd),{kind:"continue"};if(n==="add"){let o=bo(t.cwd,e[1],e[2]);return o?(console.log(x(o)),{kind:"continue"}):(console.log(A(`\u2713 Profile "${e[1]}" created (environment: ${e[2]??e[1]}).`)),console.log(` Switch + sign in: ${E(`/profile ${e[1]}`)} then ${E("/login")}`),{kind:"continue"})}return Jt(t.cwd,n),Qt(t.cwd,n),console.log(f(" Restarting agent for the new profile\u2026")),{kind:"clear"}}q();import{select as ec}from"@inquirer/prompts";import{readProjectConfig as tc,readUserConfig as Rs,resolveModelSetting as vo,writeUserConfig as js}from"document360-engine";var ye=[{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 cn(e){if(e.model===null||e.source==="claude-settings")return 0;let t=e.model.toLowerCase(),n=ye.findIndex(o=>o.value!==null&&(o.value===t||o.label.toLowerCase()===t||t.includes(o.label.toLowerCase())));return n>=0?n:0}function nc(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 Pt(e,t){let n=()=>{let s=vo(e);return s.source==="project"||s.source==="user"||s.source==="env"?s.model??void 0:void 0};if(t==="default"){let s=Rs();return s.defaultModel?(delete s.defaultModel,js(s),{lines:[`\u2713 Personal model override cleared \u2014 now: ${vo(e).model??"Claude Code default"} (applies from your next message)`],changed:!0,effective:n()}):{lines:["No personal model override set \u2014 nothing to clear."],changed:!1,effective:void 0}}js({...Rs(),defaultModel:t});let o=[`\u2713 Personal model set to "${t}" (applies from your next message \u2014 conversation continues)`],r=tc(e)?.defaultModel;return r&&o.push(`\u26A0 .d360-writer.json sets defaultModel "${r}" \u2014 the team setting overrides yours until it is removed.`),{lines:o,changed:!0,effective:n()}}async function Ds(e,t){let n=e[0]?.trim();if(!n){let c=vo(t.cwd);if(!process.stdin.isTTY)return console.log(`${Ce("Model:")} ${E(c.model??"Claude Code default")}`),console.log(f(` source: ${nc(c)}`)),console.log(f(" change: /model <haiku|sonnet|opus|full-model-id> \xB7 reset: /model default")),{kind:"continue"};let d=cn(c),g;try{g=await t.withPausedInput(()=>ec({message:`Select model (current: ${c.model??"Claude Code default"})`,default:ye[d].value,choices:ye.map((y,b)=>({name:`${y.label}${b===d?" \u2714":""}`,value:y.value,description:y.desc}))}))}catch{return console.log(f("Cancelled.")),{kind:"continue"}}let{lines:w,changed:$,effective:R}=Pt(t.cwd,g??"default");for(let y of w)console.log(y.startsWith("\u26A0")?L(y):y.startsWith("\u2713")?A(y):f(y));return $&&await t.setModel(R),{kind:"continue"}}let{lines:o,changed:r,effective:s}=Pt(t.cwd,n);for(let c of o)console.log(c.startsWith("\u26A0")?L(c):c.startsWith("\u2713")?A(c):f(c));return r&&await t.setModel(s),{kind:"continue"}}un();async function _s(e,t){return await t.withPausedInput(()=>lt(t.cwd)),{kind:"clear"}}q();import{select as mc}from"@inquirer/prompts";import{resolveActiveProfile as gc,setProfileProject as hc,listProjects as wc}from"document360-engine";async function Po(e,t){let n=gc(e,t),o={profile:n.name,connection:n.connection};return{projects:await wc(o),profile:n.name,environment:n.connection.name,current:n.project.projectId}}var Ms=e=>`${e.name??e.id}${e.sub_domain?` \xB7 ${e.sub_domain}`:""}`;function Os(e,t){let n=t.toLowerCase();return e.find(o=>(o.name??"").toLowerCase()===n)??e.find(o=>(o.name??"").toLowerCase().startsWith(n))??e.find(o=>o.id.startsWith(t))}function To(e,t,n){hc(e,t,{projectId:n,workspaceId:void 0,workspaceName:void 0})}async function Ls(e,t){let n;try{n=await Po(e,t)}catch(g){console.log(x(`Could not list projects: ${g.message}`));return}let{projects:o,profile:r,current:s}=n;if(o.length===0){console.log(f("No projects found for this identity."));return}if(!process.stdin.isTTY){console.log("");for(let g of o)console.log(` ${g.id===s?E("\u25CF"):" "} ${Ms(g)} ${f(g.id)}`);console.log(f("Run: d360-writer project use <name>"));return}let c=await mc({message:"Select the Document360 project for this repo:",choices:o.map(g=>({name:`${Ms(g)}${g.id===s?" (current)":""}`,value:g.id}))});To(e,r,c);let d=o.find(g=>g.id===c);console.log(A(`\u2713 Project set to "${d?.name??c}" for profile "${r}". Next: pick a workspace.`))}async function Us(e,t){return await t.withPausedInput(()=>Ls(t.cwd,t.profileName)),{kind:"clear"}}q();import{resolveActiveProfile as kc}from"document360-engine";async function Ws(e,t){let n=!1;try{n=kc(t.cwd).production}catch{}return n?(console.log(L("\u26A0 Authorizing writes to the PRODUCTION profile for this session.")),{kind:"allow-prod"}):(console.log(f("Current profile is not a production profile \u2014 writes are already allowed.")),{kind:"continue"})}q();var Fs=async(e,t)=>{try{await t.withPausedInput(()=>Xt({}))}catch(n){console.log(x(`Login failed: ${n.message}`))}return{kind:"continue"}};q();import{resolveActiveProfile as yc,clearTokens as $c,clearProfileProject as xc}from"document360-engine";async function Hs(e,t){let n;try{n=yc(t.cwd,t.profileName).name}catch(r){return console.log(x(r.message)),{kind:"continue"}}let o=$c(n);return xc(t.cwd,n),console.log(o?A(`\u2713 Signed out of "${n}" and cleared its project/workspace selection.`):f(`Profile "${n}" was not signed in. Cleared any project/workspace selection.`)),console.log(f("Run /login to sign in and pick a project.")),{kind:"continue"}}import{existsSync as Bs}from"node:fs";import{isAbsolute as bc,join as vc,resolve as Cc}from"node:path";import{readProjectConfig as Pc,screenshotPlaceholderIds as Tc,DEFAULT_CAPTURE_DIR as Sc,DEFAULT_OUTPUT_DIR as Rc}from"document360-engine";var qs=e=>e.replace(/\\/g,"/").replace(/\/+$/,"");function So(e){let t=!e.includes("--no-setup"),n=e.filter(r=>r!=="--no-setup");if(n[0]==="--list")return{mode:"list",scope:n[1]?qs(n[1]):void 0};let o=n[0];return!o||o==="--all"?{mode:"all",setup:t}:/[\\/]/.test(o)||o.endsWith(".md")?{mode:"scope",scope:qs(o),setup:t}:{mode:"single",id:o}}function Ro(e,t){let n=Pc(e),o=n?.captureDir??Sc,r=n?.outputDir??Rc,s=(c,d)=>bc(c)?vc(c,d):Cc(e,c,d);return Tc(e,{scope:t}).map(({id:c,file:d})=>{let g=Bs(s(r,`${c}.png`))?"captured":Bs(s(o,`${c}.spec.ts`))?"spec":"placeholder";return{id:c,file:d,state:g}})}var jc={placeholder:"\u25CB",spec:"\u25D0",captured:"\u25CF"},Dc={placeholder:"placeholder only",spec:"spec written, not captured",captured:"captured"};function jo(e,t){if(e.length===0)return[t?`No screenshot placeholders under ${t}.`:"No screenshot placeholders found in the docs."];let n=[...new Set(e.map(s=>s.file))].sort(),o=e.filter(s=>s.state==="captured").length,r=[`Screenshots: ${e.length} placeholder${e.length===1?"":"s"} across ${n.length} article${n.length===1?"":"s"} \xB7 ${o} captured${t?` \xB7 scope ${t}`:""}`,""];for(let s of n){r.push(s);for(let c of e.filter(d=>d.file===s))r.push(` ${jc[c.state]} ${c.id.padEnd(34)} ${Dc[c.state]}`)}return r.push("","\u25CB placeholder only \u25D0 spec written \u25CF captured"),r}function Gs(e){return["Run the emit-screenshot-spec skill to author the document360-capture spec for EACH of these","SCREENSHOT placeholder ids:",e.paths.map(t=>`- ${t}`).join(`
60
60
  `),"","For each: locate its <!-- SCREENSHOT --> block in the docs tree (the configured docsDir); read the product source for","EXACT routes + stable data-testid selectors (never guess); enter the prepared context via","captureScope(); guard data prerequisites with test.skip(reason); write <captureDir>/<id>.spec.ts","(skip-with-TODO if a stable selector is missing). Do NOT run other skills. Report the specs you","wrote and any TODO data-testids."].join(`
61
61
  `)}async function dn(e,t){let n=So(e);if(n.mode==="list"){let c=t?.cwd??process.cwd();for(let d of jo(Ro(c,n.scope),n.scope))console.log(d);return{kind:"continue"}}if(n.mode==="single")return{kind:"forward-to-agent",prompt:[`Run the emit-screenshot-spec skill for the SCREENSHOT placeholder with id \`${n.id}\`.`,"Locate its <!-- SCREENSHOT --> block in the docs tree (the configured docsDir), then follow that skill exactly: read the","product source for EXACT routes + stable data-testid selectors (never guess); enter the prepared","context via captureScope(); guard data prerequisites with test.skip(reason); write",`<captureDir>/${n.id}.spec.ts. Report the spec path and any TODO data-testids or data to stage.`].join(`
62
62
  `),display:`/screenshot ${n.id}`};let r=[`Run the emit-screenshot-spec skill to (re)generate the document360-capture spec for ${n.mode==="scope"?`every <!-- SCREENSHOT --> placeholder in articles under ${n.scope}`:"every <!-- SCREENSHOT --> placeholder across the docs tree (the configured docsDir)"}.`,"Follow that skill exactly for each: read the SCREENSHOT block; read the product source for EXACT routes","and stable data-testid selectors (never guess); enter the prepared context via captureScope(); guard data",`prerequisites with test.skip(reason); write <captureDir>/<id>.spec.ts.${n.setup?" When done, run capture-setup-checklist to refresh CAPTURE-SETUP.md.":""} Report specs written, TODO data-testids, and data to stage.`].join(`
63
- `),s=n.mode==="scope"?`/screenshot ${n.scope}`:`/screenshot${e[0]?` ${e[0]}`:""}`;return{kind:"forward-to-agent",prompt:r,display:s}}import{existsSync as Cc,readFileSync as Pc}from"node:fs";import{isAbsolute as Tc,join as Sc,resolve as Rc}from"node:path";import{readProjectConfig as jc,DEFAULT_CAPTURE_DIR as Dc}from"document360-engine";async function St(){return{kind:"forward-to-agent",prompt:["Run the capture-setup-checklist skill.","","Scan every <!-- SCREENSHOT --> block across the docs tree (the configured docsDir), read each block\u2019s prerequisites,","anchor them to the capture scope keys in .d360-capture.json, then synthesize a deduped, grouped","\u201Cstage this data\u201D checklist and write it to <captureDir>/CAPTURE-SETUP.md. Separate transient/manual","states, flag any spec whose prerequisites are vague, and report the path when done."].join(`
64
- `),display:"/capture-setup"}}var qs="-".repeat(64);function Do(e){let t=Dc;try{let $=jc(e);$?.captureDir&&(t=$.captureDir.replace(/\\/g,"/").replace(/\/+$/,""))}catch{}let n=Tc(t)?Sc(t,"CAPTURE-TESTID-REQUESTS.json"):Rc(e,t,"CAPTURE-TESTID-REQUESTS.json");if(!Cc(n))return null;let o;try{let $=JSON.parse(Pc(n,"utf8").replace(/^/,""));o=Array.isArray($?.requests)?$.requests:[]}catch{return null}if(o.length===0)return null;let r=new Set(o.map($=>$.file).filter(Boolean)).size,s=o.length,c=`${s} data-testid attribute${s===1?"":"s"}`,d=`${r} source file${r===1?"":"s"}`,g=`${t}/CAPTURE-TESTID-REQUESTS.md`,w=`${t}/CAPTURE-TESTID-REQUESTS.json`;return[`\u{1F4CB} Developer hand-off \u2014 ${c} requested across ${d}.`,"\u26A0 Do NOT run this prompt here. d360-writer documents code; it does not change it \u2014"," these edits belong in your code repo. Open a SEPARATE terminal in:",` ${e}`," start Claude Code (or your coding agent), and paste everything between the lines."," Tip: run it in plan mode first \u2014 these are a hypothesis to verify, not a verified patch.","",qs,`Read ${g} and ${w}. They list ${c} that d360-writer THINKS this repo needs for screenshot automation. Treat them as a hypothesis to VERIFY against the source \u2014 not a verified patch list.`,"","For EACH request in the JSON:",'1. Locate the element in THIS repo. Trace it from the route/page, not the feature name. If "anchorVerified" is false, find it by the "element"/"reason" description; otherwise confirm the "anchor" snippet still exists in "file".',"2. If the element already has a data-testid, skip it and note the existing one.","3. Confirm the attribute will reach the DOM: the rendering component must forward unknown props (a {...rest} spread or explicit pass-through). If it is a shared wrapper (e.g. Modal, ContextMenu) that destructures a fixed prop list, a data-testid is silently dropped \u2014 thread it through the component, or report it as needing a code change instead of forcing it.",'4. Only then add data-testid="<testid>" to the verified element. Add nothing else; do not rename, restructure, reformat, or change behaviour.',"","When done, report: which testids you added (file + element), which were already present, which requests were wrong (wrong file/anchor/page) with the correction, and which need threading through a shared component. Never force a request that does not match the source \u2014 flag it instead.",qs]}import{writeFileSync as Ac}from"node:fs";import{devHintsGuidePath as Ec,hintsDir as Ic,ensureDir as _c}from"document360-engine";var Gs="-".repeat(64),Nc=1;function Ao(){return`# Dev \u2192 Docs hints \u2014 protocol guide
63
+ `),s=n.mode==="scope"?`/screenshot ${n.scope}`:`/screenshot${e[0]?` ${e[0]}`:""}`;return{kind:"forward-to-agent",prompt:r,display:s}}import{existsSync as Ac,readFileSync as Ec}from"node:fs";import{isAbsolute as Ic,join as Nc,resolve as _c}from"node:path";import{readProjectConfig as Mc,DEFAULT_CAPTURE_DIR as Oc}from"document360-engine";async function St(){return{kind:"forward-to-agent",prompt:["Run the capture-setup-checklist skill.","","Scan every <!-- SCREENSHOT --> block across the docs tree (the configured docsDir), read each block\u2019s prerequisites,","anchor them to the capture scope keys in .d360-capture.json, then synthesize a deduped, grouped","\u201Cstage this data\u201D checklist and write it to <captureDir>/CAPTURE-SETUP.md. Separate transient/manual","states, flag any spec whose prerequisites are vague, and report the path when done."].join(`
64
+ `),display:"/capture-setup"}}var zs="-".repeat(64);function Do(e){let t=Oc;try{let $=Mc(e);$?.captureDir&&(t=$.captureDir.replace(/\\/g,"/").replace(/\/+$/,""))}catch{}let n=Ic(t)?Nc(t,"CAPTURE-TESTID-REQUESTS.json"):_c(e,t,"CAPTURE-TESTID-REQUESTS.json");if(!Ac(n))return null;let o;try{let $=JSON.parse(Ec(n,"utf8").replace(/^/,""));o=Array.isArray($?.requests)?$.requests:[]}catch{return null}if(o.length===0)return null;let r=new Set(o.map($=>$.file).filter(Boolean)).size,s=o.length,c=`${s} data-testid attribute${s===1?"":"s"}`,d=`${r} source file${r===1?"":"s"}`,g=`${t}/CAPTURE-TESTID-REQUESTS.md`,w=`${t}/CAPTURE-TESTID-REQUESTS.json`;return[`\u{1F4CB} Developer hand-off \u2014 ${c} requested across ${d}.`,"\u26A0 Do NOT run this prompt here. d360-writer documents code; it does not change it \u2014"," these edits belong in your code repo. Open a SEPARATE terminal in:",` ${e}`," start Claude Code (or your coding agent), and paste everything between the lines."," Tip: run it in plan mode first \u2014 these are a hypothesis to verify, not a verified patch.","",zs,`Read ${g} and ${w}. They list ${c} that d360-writer THINKS this repo needs for screenshot automation. Treat them as a hypothesis to VERIFY against the source \u2014 not a verified patch list.`,"","For EACH request in the JSON:",'1. Locate the element in THIS repo. Trace it from the route/page, not the feature name. If "anchorVerified" is false, find it by the "element"/"reason" description; otherwise confirm the "anchor" snippet still exists in "file".',"2. If the element already has a data-testid, skip it and note the existing one.","3. Confirm the attribute will reach the DOM: the rendering component must forward unknown props (a {...rest} spread or explicit pass-through). If it is a shared wrapper (e.g. Modal, ContextMenu) that destructures a fixed prop list, a data-testid is silently dropped \u2014 thread it through the component, or report it as needing a code change instead of forcing it.",'4. Only then add data-testid="<testid>" to the verified element. Add nothing else; do not rename, restructure, reformat, or change behaviour.',"","When done, report: which testids you added (file + element), which were already present, which requests were wrong (wrong file/anchor/page) with the correction, and which need threading through a shared component. Never force a request that does not match the source \u2014 flag it instead.",zs]}import{existsSync as Lc,writeFileSync as Ys}from"node:fs";import{devHintsGuidePath as Uc,hintsDir as Wc,architectureDir as Fc,creatorNotesPath as Vs,ensureDir as Xs}from"document360-engine";var Ks="-".repeat(64),Hc=2;function Ao(){return`# Dev \u2192 Docs hand-off \u2014 protocol guide
65
65
 
66
- <!-- Guide version: ${Nc} \xB7 maintained by document360-writer (/devhints). -->
66
+ <!-- Guide version: ${Hc} \xB7 maintained by document360-writer (/devhints). -->
67
67
 
68
- This repo's user documentation is written by **document360-writer**, a separate documentation agent.
69
- It can read your code, but it can't read your *intent* \u2014 why a change matters to an end user, the
70
- gotchas, the role-gating. You (the coding agent building features here) know that at the moment you
71
- build it. A **doc hint** captures it so the docs agent can update the help center later.
68
+ This repo's user documentation is written by **document360-writer** ("the docs agent"), a separate agent.
69
+ It can read your code, but code alone can't tell it the *intent* \u2014 WHY a feature exists, which of a
70
+ thousand code paths is the one a user touches, the conceptual model, the terminology, what's new. You
71
+ (the coding agent that built this product) hold that context. This guide is how you hand it over.
72
72
 
73
- ## When to write a hint
73
+ Think of it as onboarding a newly-hired technical writer: first you give them a briefing (Part 1), then
74
+ you keep them in the loop as you ship (Part 2).
74
75
 
75
- Write one when you ship a change with a **user-facing effect**:
76
+ ---
77
+
78
+ ## Part 1 \u2014 Architecture brief (do this ONCE, now)
79
+
80
+ Write a **user-doc-enabling brief** into \`.d360-writer/architecture/\` \u2014 one or more \`.md\` files. This
81
+ is NOT an engineering design doc. It is everything a *technical writer* needs to document the product for
82
+ END USERS. Steer hard toward the user-facing story; deprioritize internals.
83
+
84
+ **0. First, read \`.d360-writer/architecture/CREATOR-NOTES.md\`** \u2014 the original human creator's notes.
85
+ Treat anything there as **authoritative** (a human's "folder X is the admin UI; skip src/Services" beats
86
+ any inference). It may be empty \u2014 that's fine. **Never modify CREATOR-NOTES.md** (it's human-owned);
87
+ write your brief to OTHER files in the folder.
88
+
89
+ **Cover (every claim citing the source file(s) that prove it, so the docs agent can verify + ground):**
90
+ - **Product overview** \u2014 what it is, who it's for, the core user problem it solves (the WHY).
91
+ - **User-facing surfaces** \u2014 the screens, flows, settings, dialogs, public APIs, or CLI a user actually
92
+ touches. For each, name the source file(s).
93
+ - **Features + intent** \u2014 what each does and *why a user reaches for it / when*.
94
+ - **User roles / personas**, and any **permission or plan gating**.
95
+ - **Core workflows / journeys** \u2014 the end-to-end tasks a user performs.
96
+ - **Terminology / glossary** \u2014 the exact product names and labels (authoritative).
97
+ - **Intentionally internal** \u2014 name what is plumbing (services, data access, infra, build/CI, tests) so
98
+ the writer knows what to SKIP.
99
+
100
+ **Honesty:** describe what the code actually does. If you're unsure, say so rather than inventing \u2014 the
101
+ docs agent grounds every concrete claim (UI strings, routes) in the code and flags conflicts.
102
+
103
+ ---
104
+
105
+ ## Part 2 \u2014 Ongoing doc hints (as you keep building)
76
106
 
77
- - a new or changed screen, button, menu, flow, dialog, or setting
107
+ After the brief, record a **doc hint** whenever you ship a change with a **user-facing effect**:
108
+ - a new/changed/removed screen, button, menu, flow, dialog, or setting
78
109
  - a new/changed/removed API field, endpoint, CLI flag, or permission
79
110
  - a behavior change a user would notice, or a **deprecation/removal**
80
111
 
81
- **Do NOT** write one for internal-only work (refactors, test changes, build/CI, dependency bumps,
82
- performance tweaks with no visible effect). One hint per shippable user-facing surface. When unsure,
83
- write it \u2014 a spurious hint is cheap; a missed feature is an undocumented feature.
112
+ **Do NOT** hint for internal-only work (refactors, tests, build/CI, dep bumps, invisible perf). Also keep
113
+ the architecture brief current when a change makes it stale. One hint per shippable user-facing surface.
84
114
 
85
- ## How to write a hint
86
-
87
- Create **one new file** under \`.d360-writer/hints/\` named
88
- \`<YYYY-MM-DD>-<short-slug>-<random>.md\` (e.g. \`2026-06-17-export-csv-button-a1b2c3.md\`).
89
- One file per hint \u2014 never append to an existing one (distinct files merge cleanly across branches).
90
- The file is markdown with a YAML frontmatter header:
115
+ ### How to write a hint
116
+ Create **one new file** under \`.d360-writer/hints/\` named \`<YYYY-MM-DD>-<short-slug>-<random>.md\`
117
+ (e.g. \`2026-06-17-export-csv-button-a1b2c3.md\`). One file per hint \u2014 never append (distinct files merge
118
+ cleanly across branches). Markdown with a YAML frontmatter header:
91
119
 
92
120
  \`\`\`markdown
93
121
  ---
@@ -108,54 +136,64 @@ Prose: what you built and the gotchas a code diff would miss \u2014 e.g. "the bu
108
136
  "the toast fires only on the second save", "CSV uses the workspace's locale, not the user's".
109
137
  \`\`\`
110
138
 
111
- ### Field rules
112
- - \`sources\` is **required** and must be real repo-relative paths \u2014 the docs agent verifies the
113
- change against them, so a wrong path means your hint gets flagged, not trusted.
114
- - \`commit\` = your current HEAD. \`kind\`: \`new\` (new feature/article), \`update\` (changed existing
115
- surface), \`deprecate\` (removed/sunset).
116
- - \`target\` is a free-text nudge only ("probably the Exports guide"). **Never invent an article path** \u2014
117
- you can't see the docs tree; the docs agent resolves the right article from \`sources\`.
118
- - Leave \`status: open\` and omit the \`consumed_*\` fields \u2014 the docs agent fills those when it
119
- documents your hint.
120
- - Keep the body about user-facing intent, not implementation. Don't propose docs structure.
139
+ #### Field rules
140
+ - \`sources\` is **required** and must be real repo-relative paths \u2014 the docs agent verifies against them.
141
+ - \`commit\` = your current HEAD. \`kind\`: \`new\` / \`update\` / \`deprecate\`.
142
+ - \`target\` is a free-text nudge only \u2014 **never invent an article path** (you can't see the docs tree).
143
+ - Leave \`status: open\`; the docs agent flips it to consumed.
144
+ - Keep the body about user-facing intent, not implementation.
121
145
 
122
146
  That's it \u2014 drop the file and keep building. The docs agent picks it up on its next analysis run.
123
- `}async function zs(e,t){_c(Ic(t.cwd)),Ac(Ec(t.cwd),Ao());for(let n of Eo())console.log(n);return{kind:"continue"}}function Eo(){return["\u2713 Wrote .d360-writer/DEV-HINTS-GUIDE.md and created the .d360-writer/hints/ inbox.","","\u{1F4CB} One-time setup \u2014 connect this repo's coding agent to the docs agent."," Add the block below to your SOURCE repo's agent memory (CLAUDE.md / AGENTS.md), then commit"," .d360-writer/DEV-HINTS-GUIDE.md so teammates' agents get the same instruction:","",Gs,"## Documentation hints (for the docs agent)","","When you ship a user-facing change (new/changed/removed screen, button, flow, setting, API field,","CLI flag, or permission), record a doc hint so the documentation team's agent can update the help","center. How: read `.d360-writer/DEV-HINTS-GUIDE.md` and follow it \u2014 create one markdown file under","`.d360-writer/hints/`. Do this as part of finishing the feature. Skip it only for changes with no","user-visible effect (refactors, tests, build, deps).",Gs,"","Then keep building as usual. On its next analysis run (/audit), the docs agent reads open hints,","verifies each against your code, writes/updates the docs, and marks the hint consumed."]}q();import{existsSync as Ys,rmSync as Mc}from"node:fs";import{basename as Vs,resolve as Io}from"node:path";import{execFileSync as Lc}from"node:child_process";import{input as Oc}from"@inquirer/prompts";import{readProjectConfig as Uc}from"document360-engine";var Wc=[".d360-writer.json",".d360-writer","d360-category-map.json",".d360-capture.json",".d360-capture-cache"],Fc=new Set([".d360-writer.json","d360-category-map.json",".d360-capture.json",".d360-capture-cache"]),pn=e=>(e??"").replace(/\\/g,"/").replace(/\/+$/,""),Xs=e=>e===".d360-writer"||e.startsWith(".d360-writer/");function Ks(e){let t=pn(e);return t===""||t.startsWith("..")||t.startsWith("/")||/^[a-zA-Z]:/.test(t)?!1:Xs(t)?!0:Fc.has(t)}function _o(e){let t=null;try{t=Uc(e)}catch{t=null}let n=new Set(Wc);for(let o of[pn(t?.docsDir),pn(t?.captureDir),pn(t?.outputDir)])o&&Xs(o)&&n.add(o);return[...n].filter(o=>Ks(o)&&Ys(Io(e,o)))}function No(e,t){let n=[],o=[];for(let r of t){if(!Ks(r)){o.push({path:r,error:"refused \u2014 outside .d360-writer/ (protected)"});continue}try{Mc(Io(e,r),{recursive:!0,force:!0}),n.push(r)}catch(s){o.push({path:r,error:s.message})}}return{removed:n,failed:o}}function Hc(e){try{return Lc("git",["status","--porcelain","--",".d360-writer/hints"],{cwd:e,encoding:"utf8",stdio:["ignore","pipe","ignore"]}).split(`
124
- `).filter(n=>n.trim()&&/\.md\s*$/.test(n)).length}catch{return 0}}function Mo(e,t){if(t.length===0)return["Nothing to reset \u2014 no d360-writer files found in this repo."];let n=Hc(e),o=Ys(Io(e,"user-docs"));return["\u26A0 This permanently DELETES everything d360-writer created here:",...t.map(r=>` \u2022 ${r}`),"",...n>0?[`\u26A0 ${n} doc hint(s) under .d360-writer/hints/ are not committed \u2014 commit them first or they're gone.`]:[],...o?["Protected: root user-docs/ is NOT touched (only .d360-writer/ is removed)."]:[],"Undo = git: committed files are restorable; untracked ones (most screenshots) are gone.",`To confirm, type the repo name: ${Vs(e)}`]}async function Js(e,t){let n=_o(t.cwd);for(let d of Mo(t.cwd,n))console.log(n.length===0?f(d):d);if(n.length===0)return{kind:"continue"};let o=Vs(t.cwd);if((await t.withPausedInput(()=>Oc({message:`Type "${o}" to delete (anything else cancels):`}).catch(()=>""))).trim()!==o)return console.log(O("Reset cancelled \u2014 nothing deleted.")),{kind:"continue"};let{removed:s,failed:c}=No(t.cwd,n);console.log(A(`\u2713 Reset complete \u2014 removed ${s.length} item${s.length===1?"":"s"}. The repo is back to its original state.`));for(let d of c)console.log(x(` \u2717 ${d.path}: ${d.error}`));return console.log(f("Set up d360-writer again with /init (then /login, /workspace).")),{kind:"continue"}}var Qs={help:Fn,"?":Fn,clear:Er,exit:Hn,quit:Hn,init:Fr,mcp:tn,publish:es,audit:rn,scope:ns,sync:cs,convert:us,write:ms,draft:ys,resume:bs,rename:vs,profile:Ps,model:Rs,doctor:Tt,workspace:Is,project:Ls,"allow-prod":Os,login:Us,logout:Ws,screenshot:dn,"capture-setup":St,devhints:zs,reset:Js};function Zs(e){let t=e.trim();if(!t.startsWith("/"))return null;let n=t.slice(1).split(/\s+/),o=(n[0]??"").toLowerCase();return o?{name:o,args:n.slice(1)}:null}q();var Bc={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"},ti=160,Oo=200,ni=40;function ue(e,t){let n=e.replace(/\s+/g," ").trim();return n.length<=t?n:n.slice(0,t-1)+"\u2026"}function ei(e){let t=Object.entries(e).filter(([,o])=>o!=null&&o!=="");if(t.length===0)return null;let n=t.slice(0,4).map(([o,r])=>`${o}: ${ue(typeof r=="string"?r:JSON.stringify(r),ni)}`);return t.length>4&&n.push("\u2026"),ue(n.join(", "),ti)}var Ie=e=>typeof e=="string"&&e?e:null,Lo=e=>typeof e=="string"&&e.length>=8?e.slice(0,8):null;function qc(e){let t=Ie(e)?.replace(/\\/g,"/");if(!t)return null;let n=t.split("/").filter(Boolean);if(n.length<2)return null;let o=n[n.length-2],r=o.replace(/^\d+[-_.]/,"").split(/[-_]/).filter(Boolean);return r.length===0?o:r.map(s=>s.charAt(0).toUpperCase()+s.slice(1)).join(" ")}function Gc(e,t){let n=(o,r)=>({title:`Document360: ${o}`,sep:" ",arg:r});switch(e){case"d360_create_article":{let o=Ie(t.title);if(!o)return null;let r=qc(t.local_path);return n("Create article",`"${ue(o,60)}"${r?` in ${r}`:""}`)}case"d360_update_article":{let o=Ie(t.title),r=Lo(t.article_id);return n("Update article",o?`"${ue(o,60)}"`:r?`id ${r}\u2026`:null)}case"d360_fork_article":return n("Fork article (new draft)",Lo(t.article_id)?`id ${Lo(t.article_id)}\u2026`:null);case"d360_publish_article":{let o=t.version_number;return n("Publish article LIVE",typeof o=="number"?`v${o}`:null)}case"d360_unpublish_article":return n("Unpublish article",null);case"d360_create_category":return n("Create category",Ie(t.name)?`"${ue(Ie(t.name),60)}"`:null);case"d360_upload_drive_file":{let o=Ie(t.file_path);return n("Upload image",o?ue(o.replace(/\\/g,"/").split("/").pop()??o,60):null)}case"d360_sync_status":return n("Check sync status",null);default:return null}}function fn(e,t){if(e==="ToolSearch")return null;if(e.startsWith("mcp__")){let[,r="",...s]=e.split("__"),c=s.join("__");if(r==="document360"){let w=Gc(c,t);if(w)return w}let d=c.replace(/^d360_/,"").replace(/_/g," ");return{title:`${r==="document360"?"Document360":r.charAt(0).toUpperCase()+r.slice(1)}: ${d}`,sep:" ",arg:ei(t)}}let n=Bc[e],o=n?t[n]:void 0;return typeof o=="string"&&o?{title:e,sep:"",arg:ue(o,ti)}:{title:e,sep:"",arg:ei(t)}}function zc(e){if(e===null||typeof e!="object")return typeof e=="string"?e:null;let t=e;for(let n of["name","title","slug","id"])if(typeof t[n]=="string"&&t[n])return t[n];return null}function Yc(e){if(!/^[[{]/.test(e))return null;let t;try{t=JSON.parse(e)}catch{return null}if(Array.isArray(t)){let n=t.map(zc).filter(r=>r!==null),o=`${t.length} item${t.length===1?"":"s"}`;return n.length===0?[o]:[o,...n.map(r=>ue(r,Oo))]}if(t!==null&&typeof t=="object"){let n=Object.entries(t).filter(([,o])=>o!==null&&(typeof o=="string"||typeof o=="number"||typeof o=="boolean")).slice(0,6).map(([o,r])=>`${o}: ${ue(String(r),ni)}`);return n.length>0?[ue(n.join(" \xB7 "),Oo)]:null}return null}function Vc(e){let t=Ie(e)?.replace(/\\/g,"/");if(!t)return null;let n=t.split("/").filter(Boolean);return n.length>1?n.slice(1).join("/"):t}function Xc(e,t,n){switch(e){case"d360_create_article":{let o=Vc(t?.local_path);return[`\u2713 draft created${o?` \xB7 ${o}`:""}`]}case"d360_update_article":return["\u2713 draft updated"];case"d360_fork_article":return["\u2713 forked to a new draft"];case"d360_publish_article":return["\u2713 PUBLISHED LIVE \u2014 visible to readers"];case"d360_unpublish_article":return["\u2713 reverted to draft (removed from readers)"];case"d360_create_category":{let o=Ie(t?.name);return[`\u2713 category created${o?` \xB7 "${o}"`:""}`]}case"d360_upload_drive_file":{let o=n.match(/https?:\/\/\S+/);return[`\u2713 uploaded${o?` \xB7 ${ue(o[0],120)}`:""}`]}default:return null}}function mn(e,t=4,n,o){let r=e.replace(/\r\n/g,`
125
- `).trimEnd();if(!r)return{lines:["(no output)"],hidden:0};if(n?.startsWith("mcp__document360__")){let c=Xc(n.slice(18),o,r);if(c)return{lines:c,hidden:0}}let s=Yc(r)??r.split(`
126
- `);return{lines:s.slice(0,t).map(c=>ue(c,Oo)),hidden:Math.max(0,s.length-t)}}function gn(e,t,n,o="en"){return`${e.replace(/\/$/,"")}/${t}/document/v1/${o}/${n}`}function hn(e,t){if(typeof e.article_id=="string"&&e.article_id)return e.article_id;try{let n=JSON.parse(t),r=(Array.isArray(n)?n[0]:n)?.id;return typeof r=="string"&&r?r:null}catch{return null}}function wn(e){try{let t=JSON.parse(e),o=(Array.isArray(t)?t[0]:t)?.url;return typeof o=="string"&&/^https?:\/\//.test(o)?o:null}catch{return null}}var au=/^mcp__document360__d360_(create_article|update_article|fork_article|publish_article)$/;function lu(e,t,n,o){if(au.test(e))try{let r=ii(o),s=typeof t.project_id=="string"&&t.project_id||r.project.projectId,c=hn(t,n),d=wn(n);e.endsWith("publish_article")&&d&&console.log(E(` \u2B95 Live: ${d}`)),c&&s&&console.log(E(` \u2B95 Preview: ${gn(r.connection.portalUrl,s,c,r.project.languageCode??"en")}`))}catch{}}async function ai(e=process.cwd(),t="auto",n){let o=Jc(t);o.kind==="none"&&(console.error(""),console.error(x("ANTHROPIC_API_KEY is not set (required for --auth api).")),console.error(""),console.error(` ${E("export ANTHROPIC_API_KEY=sk-ant-...")} (macOS / Linux)`),console.error(` ${E('$env:ANTHROPIC_API_KEY="sk-ant-..."')} (PowerShell)`),console.error(""),console.error(`Get a key at ${E("https://console.anthropic.com/settings/keys")}`),console.error(`Or use your Claude subscription instead: ${E("d360-writer --auth subscription")}`),console.error(""),process.exit(2)),cu(e,n),o.kind==="subscription"&&(o.stored?console.log(f(" Using your Claude subscription (no API key set).")):console.log(f(" No API key or stored Claude Code login found \u2014 trying your Claude session anyway.")),console.log(""));let r=!1,s=Uo({cwd:e,profileName:n,allowProdWrites:r}),c={uuid:null,firstPrompt:null,titleFired:!1},d=Kc({input:process.stdin,output:process.stdout}),g=[],w=null,$=!1;d.on("line",b=>{if(w){let v=w;w=null,v(b)}else g.push(b)}),d.on("close",()=>{if($=!0,w){let b=w;w=null,b(null)}});function R(){return g.length>0?Promise.resolve(g.shift()):$?Promise.resolve(null):(process.stdout.write(E("> ")),new Promise(b=>{w=b}))}let y={cwd:e,profileName:n,allowProdWrites:()=>r,restartAgent:()=>{s.close(),s=Uo({cwd:e,profileName:n,allowProdWrites:r}),c={uuid:null,firstPrompt:null,titleFired:!1}},currentUuid:()=>c.uuid,setModel:async b=>s.setModel(b),withPausedInput:async b=>{d.pause();try{return await b()}finally{d.resume()}}};try{for(;;){let b=await R();if(b===null)break;let v=b.trim();if(v){if(v.startsWith("/")){let N=Zs(v);if(!N)continue;let M=Qs[N.name];if(!M){console.log(x(`Unknown command: /${N.name}`)),console.log(f("Type /help for the list."));continue}let H=await M(N.args,y);if(H.kind==="exit")break;if(H.kind==="clear"){y.restartAgent();continue}if(H.kind==="allow-prod"){r=!0,y.restartAgent(),console.log(A("\u2713 Production writes authorized for this session.")),console.log("");continue}if(H.kind==="resume"){s.close(),s=Uo({cwd:e,resume:H.uuid,profileName:n,allowProdWrites:r});let Z=Qc(H.uuid);c={uuid:H.uuid,firstPrompt:Z?.firstPrompt??null,titleFired:!0},si(H.uuid),console.log(A(`\u2713 Resumed "${H.name}"`)),console.log("");continue}H.kind==="forward-to-agent"&&(c.firstPrompt||(c.firstPrompt=H.display??H.prompt),await ri(s,H.prompt,o,c,e));continue}c.firstPrompt||(c.firstPrompt=v),await ri(s,v,o,c,e)}}}finally{s.close(),d.close()}}function cu(e,t){console.log(""),console.log(ht("document360-writer")),console.log(f(` cwd: ${e}`));let n=ou(e);console.log(f(` model: ${n.model??"auto (engine right-sizes per task)"}${n.model?` (${n.source})`:""}`)),console.log(uu(e,t)),ru(e)||console.log(O(" First run: /init \u2192 /login \u2192 /workspace, then ask for a docs analysis.")),console.log(f(" Type a prompt, or /help for slash commands. /exit to quit.")),console.log("")}function uu(e,t){try{let n=ii(e,t),o=n.production?O(" \u26A0 PRODUCTION"):"",r=iu(n.name);if(!r)return f(` Document360: profile "${n.name}"${o} \u2014 not logged in (d360-writer login)`);let s={...oi(r.idToken)??{},...oi(r.accessToken)??{}},c=s.email??s.preferred_username??"signed in";return su(r)&&!r.refreshToken?O(` Document360: profile "${n.name}"${o} \u2014 session expired (d360-writer login)`):f(` Document360: ${c} \xB7 profile "${n.name}"${o}`)}catch(n){return f(` Document360: ${n.message.split(".")[0]}`)}}function du(){console.error(""),console.error(`Sign in with your Claude subscription: run ${E("claude")} once, then retry.`),console.error(` (No Claude Code? ${E("npm install -g @anthropic-ai/claude-code")})`),console.error(`Or set an API key: ${E("https://console.anthropic.com/settings/keys")}`)}function pu(e,t,n){e.uuid=t;let o=new Date().toISOString();tu({uuid:t,name:eu(e.firstPrompt??"session"),renamed:!1,titled:!1,cwd:n,firstPrompt:e.firstPrompt??"",createdAt:o,updatedAt:o})}function fu(e,t){e.titleFired=!0;let n=e.uuid,o=e.firstPrompt;!n||!o||nu(o,t).then(r=>{r&&Zc(n,r)}).catch(()=>{})}async function ri(e,t,n,o,r){let s=new Map;for await(let c of e.send(t))mu(c,o,r,n,s)}function mu(e,t,n,o,r){switch(e.type){case"session":t.uuid||pu(t,e.sessionId,n);break;case"text":process.stdout.write(e.delta);break;case"tool":{let s=fn(e.name,e.input);s&&(process.stdout.write(`
127
-
128
- `),console.log(`${A("\u25CF")} ${Ce(s.title)}${s.arg!==null?ee(`${s.sep}(${s.arg})`):""}`),r.set(e.id,{name:e.name,input:e.input}));break}case"article_diff":{let s=qe(e.oldContent,e.newContent,Math.max(40,(process.stdout.columns??80)-1));if(!s)break;let c=d=>d===1?"":"s";console.log(ee(` \u23BF Added ${s.added} line${c(s.added)}, removed ${s.removed} line${c(s.removed)}`));for(let d of s.lines)console.log(d);s.hidden>0&&console.log(f(` \u2026 +${s.hidden} more diff lines`));break}case"tool_result":{let s=r.get(e.id);if(!s)break;r.delete(e.id);let c=mn(e.output,4,e.isError?void 0:s.name,s.input),d=e.isError?x:ee;c.lines.forEach((g,w)=>console.log(d((w===0?" \u23BF ":" ")+g))),c.hidden>0&&console.log(f(` \u2026 +${c.hidden} lines`)),e.isError||lu(s.name,s.input,e.output,n);break}case"result":process.stdout.write(`
129
- `),console.log(f(` (${e.inputTokens}\u2192${e.outputTokens} tokens`+(e.costUsd>0?`, $${e.costUsd<.01?e.costUsd.toFixed(4):e.costUsd.toFixed(2)}`:"")+")")),console.log(""),t.uuid&&(si(t.uuid),t.titleFired||fu(t,n));break;case"error":console.error(""),console.error(x(`agent error: ${e.message}`)),o.kind==="subscription"&&e.kind==="auth"&&du();break}}import{render as fd}from"ink";import{resolveAuth as md}from"document360-engine";import{useCallback as V,useEffect as Ne,useMemo as qo,useRef as Q,useState as B}from"react";import{Box as J,Text as C,useApp as Cu,useInput as Pu,useStdout as Tu}from"ink";import{existsSync as Pi,readFileSync as Ti,readdirSync as Ni,writeFileSync as Su}from"node:fs";import{basename as Dt,isAbsolute as Ru,join as At}from"node:path";import{createSession as Si,loginPkce as ju,toStoredTokens as Du,saveTokens as Au,getAccessToken as Eu,resolveActiveProfile as de,resolveProjectId as Iu,getArticle as _u,decodeJwtClaims as dt,isExpired as _e,loadTokens as Ge,clearTokens as Nu,clearProfileProject as Mu,setTitle as Lu,slugify as Ou,touchSession as Go,upsertSession as Uu,generateTitle as Ri,findByName as Wu,listSessions as Fu,renameSession as Hu,suggestNextAction as Bu,readProjectConfig as oe,writeProjectConfig as qu,resolveModelSetting as Xo,loadProfileMap as ji,applyPull as Gu,computeSyncStatus as zo,planPull as zu,inventoryRepo as Yu,knownEnvironments as Vu,resolveEnvironment as Xu,planPartitions as Yo,partitionEvenly as Ku,screenshotPlaceholderIds as Ju,trackedArticlePaths as Qu,runPartitioned as vn,estimateBulkCost as Di,resolveModelForOperation as Cn,readDocsPlan as Zu,ensureDir as ed,hintsDir as td,devHintsGuidePath as nd}from"document360-engine";import{existsSync as gu,mkdirSync as hu,readFileSync as wu,writeFileSync as ku}from"node:fs";import{join as li}from"node:path";import{writerDir as yu}from"document360-engine";function ci(e){return li(yu(e),".sessions")}function ui(e,t){return li(ci(e),`${t}.json`)}function di(e,t,n){try{hu(ci(e),{recursive:!0});let o=n.filter(r=>r.kind!=="banner");ku(ui(e,t),JSON.stringify({v:1,items:o}),"utf8")}catch{}}function Wo(e,t){try{let n=ui(e,t);if(!gu(n))return[];let o=JSON.parse(wu(n,"utf8"));return Array.isArray(o.items)?o.items:[]}catch{return[]}}var $u=e=>`\x1B]0;${e}\x07`,xu=e=>`\x1B]9;4;${e};${e===1?100:0}\x07`;function pi(e){process.stdout.isTTY&&process.stdout.write(e)}function Rt(e){pi($u(e))}function kn(e){pi(xu(e))}var yn=["\xB7 "," \xB7"],Fo="\u{1F7E3}";un();var bu=/^(?:\d+[.)]|[-*•])\s+/;function fi(e,t,n=4){let o=new Set(t.map(s=>s.toLowerCase())),r=[];for(let s of e.split(`
130
- `)){let c=s.trim().replace(bu,""),d=c.match(/^`([^`]+)`$/);d&&(c=d[1].trim());let g=c.match(/^\/([a-z?][a-z0-9-]*)(?:\s+(\S.*?))?\s*$/i);if(!g||!o.has(g[1].toLowerCase()))continue;let w=`/${g[1].toLowerCase()}${g[2]?` ${g[2]}`:""}`;if(r.includes(w)||r.push(w),r.length>=n)break}return r}q();function jt(e){return e.map(t=>({label:t.label,items:t.paths.length,status:"pending"}))}function Pe(e,t,n){return e.map(o=>o.label===t?{...o,status:n}:o)}function Ho(e){return e.replace(/^[\w.-]+\//,"")}var $n=16,mi={pending:"\u25CB",active:"\u25A0",done:"\u2714",failed:"\u2717"};function Bo(e){return e.trim().split(/\s+/).slice(1).join(" ")}function gi(e,t){let n=Bo(t);return e.some(r=>r.trim()===t.trim()||!!n&&Bo(r)===n)?e.filter(r=>r.trim()!==t.trim()&&!(n&&Bo(r)===n)):[]}var vu=/\[Pasted text #\d+ \+\d+ lines?\]/g;function hi(e){return e.replace(/\r\n?/g,`
131
- `)}function wi(e){return e.includes(`
132
- `)||e.length>200}function ki(e,t){let n=t.split(`
133
- `).length;return`[Pasted text #${e} +${n} line${n===1?"":"s"}]`}function yi(e,t){return e.replace(vu,n=>t.get(n)??n)}function $i(e){let t=e.match(/\[Pasted text #\d+ \+\d+ lines?\]$/);return t?e.slice(0,-t[0].length):null}function xn(e,t){let n=Math.max(1,t),o=[],r=0;for(let s of e.split(`
134
- `)){if(s.length===0)o.push({start:r,end:r});else for(let c=0;c<s.length;c+=n)o.push({start:r+c,end:r+Math.min(c+n,s.length)});r+=s.length+1}return o.length>0?o:[{start:0,end:0}]}function bn(e,t){let n=0;for(let o=0;o<e.length&&e[o].start<=t;o++)n=o;return n}function xi(e,t,n){let o=bn(e,t),r=o+n;if(r<0||r>=e.length)return t;let s=Math.min(t,e[o].end)-e[o].start;return Math.min(e[r].start+s,e[r].end)}function bi(e,t,n){let o=e[bn(e,t)];return n==="start"?o.start:o.end}function vi(e,t,n){let o=Math.max(1,n),r=e.split(`
147
+ `}function Eo(){return`# Creator notes (optional \u2014 for the docs agent and the builder)
148
+
149
+ <!-- The ORIGINAL CREATOR's context. Most repos leave this empty \u2014 that's fine.
150
+ The builder agent reads this FIRST and treats it as authoritative when writing the architecture
151
+ brief. document360-writer (the docs agent) also reads it as authoritative intent.
152
+ This file is HUMAN-OWNED: the builder never overwrites it. -->
153
+
154
+ Anything only a human knows that would help document this product. For example:
155
+ - Folder / module map: "src/Web/Admin is the admin UI; src/Services/* are internal \u2014 skip them."
156
+ - Terminology / conventions: "we say 'workspace', never 'project'."
157
+ - What to prioritize or skip in the user docs.
158
+ - Gotchas or non-obvious behavior.
159
+
160
+ (Replace these examples with your notes, or leave the file as-is to skip \u2014 it's optional.)
161
+ `}async function Js(e,t){Xs(Wc(t.cwd)),Xs(Fc(t.cwd)),Lc(Vs(t.cwd))||Ys(Vs(t.cwd),Eo()),Ys(Uc(t.cwd),Ao());for(let n of Io())console.log(n);return{kind:"continue"}}function Io(){return["\u2713 Wrote .d360-writer/DEV-HINTS-GUIDE.md + the .d360-writer/architecture/ (brief) and .d360-writer/hints/ inboxes."," Optional: add anything only you know to .d360-writer/architecture/CREATOR-NOTES.md (folder map,"," conventions, what to skip) \u2014 most repos leave it empty.","","\u{1F4CB} One-time setup \u2014 connect this repo's coding agent to the docs agent."," Paste the block below into your SOURCE repo's agent memory (CLAUDE.md / AGENTS.md), then commit"," .d360-writer/ so teammates' agents get the same instruction:","",Ks,"## Documentation hand-off (for the docs agent, document360-writer)","","Read `.d360-writer/DEV-HINTS-GUIDE.md` and follow it. In order:","1. Read `.d360-writer/architecture/CREATOR-NOTES.md` (the creator's notes \u2014 authoritative; may be"," empty; never modify it).","2. ONE-TIME: write the architecture brief into `.d360-writer/architecture/` per the guide \u2014 a"," user-doc-enabling brief (product intent, user-facing surfaces, features, roles, workflows,"," terminology; cite source files; skip internals). Do this now if it doesn't exist yet.","3. ONGOING: when you ship a user-facing change, drop a doc hint in `.d360-writer/hints/` (per the"," guide) and keep the architecture brief current. Skip internal-only changes.","4. (Optional) If you want screenshots automated later, add stable `data-testid`s to the user-facing"," elements as you build \u2014 see the guide.",Ks,"","Then keep building as usual. document360-writer reads the brief to onboard, and the hints to stay","current \u2014 grounding every concrete claim in your code."]}q();import{existsSync as Qs,rmSync as Bc}from"node:fs";import{basename as Zs,resolve as No}from"node:path";import{execFileSync as qc}from"node:child_process";import{input as Gc}from"@inquirer/prompts";import{readProjectConfig as zc}from"document360-engine";var Yc=[".d360-writer.json",".d360-writer","d360-category-map.json",".d360-capture.json",".d360-capture-cache"],Vc=new Set([".d360-writer.json","d360-category-map.json",".d360-capture.json",".d360-capture-cache"]),pn=e=>(e??"").replace(/\\/g,"/").replace(/\/+$/,""),ei=e=>e===".d360-writer"||e.startsWith(".d360-writer/");function ti(e){let t=pn(e);return t===""||t.startsWith("..")||t.startsWith("/")||/^[a-zA-Z]:/.test(t)?!1:ei(t)?!0:Vc.has(t)}function _o(e){let t=null;try{t=zc(e)}catch{t=null}let n=new Set(Yc);for(let o of[pn(t?.docsDir),pn(t?.captureDir),pn(t?.outputDir)])o&&ei(o)&&n.add(o);return[...n].filter(o=>ti(o)&&Qs(No(e,o)))}function Mo(e,t){let n=[],o=[];for(let r of t){if(!ti(r)){o.push({path:r,error:"refused \u2014 outside .d360-writer/ (protected)"});continue}try{Bc(No(e,r),{recursive:!0,force:!0}),n.push(r)}catch(s){o.push({path:r,error:s.message})}}return{removed:n,failed:o}}function Xc(e){try{return qc("git",["status","--porcelain","--",".d360-writer/hints"],{cwd:e,encoding:"utf8",stdio:["ignore","pipe","ignore"]}).split(`
162
+ `).filter(n=>n.trim()&&/\.md\s*$/.test(n)).length}catch{return 0}}function Oo(e,t){if(t.length===0)return["Nothing to reset \u2014 no d360-writer files found in this repo."];let n=Xc(e),o=Qs(No(e,"user-docs"));return["\u26A0 This permanently DELETES everything d360-writer created here:",...t.map(r=>` \u2022 ${r}`),"",...n>0?[`\u26A0 ${n} doc hint(s) under .d360-writer/hints/ are not committed \u2014 commit them first or they're gone.`]:[],...o?["Protected: root user-docs/ is NOT touched (only .d360-writer/ is removed)."]:[],"Undo = git: committed files are restorable; untracked ones (most screenshots) are gone.",`To confirm, type the repo name: ${Zs(e)}`]}async function ni(e,t){let n=_o(t.cwd);for(let d of Oo(t.cwd,n))console.log(n.length===0?f(d):d);if(n.length===0)return{kind:"continue"};let o=Zs(t.cwd);if((await t.withPausedInput(()=>Gc({message:`Type "${o}" to delete (anything else cancels):`}).catch(()=>""))).trim()!==o)return console.log(L("Reset cancelled \u2014 nothing deleted.")),{kind:"continue"};let{removed:s,failed:c}=Mo(t.cwd,n);console.log(A(`\u2713 Reset complete \u2014 removed ${s.length} item${s.length===1?"":"s"}. The repo is back to its original state.`));for(let d of c)console.log(x(` \u2717 ${d.path}: ${d.error}`));return console.log(f("Set up d360-writer again with /init (then /login, /workspace).")),{kind:"continue"}}var oi={help:Fn,"?":Fn,clear:Nr,exit:Hn,quit:Hn,init:Br,mcp:tn,publish:ns,audit:rn,scope:rs,sync:ds,convert:ps,write:hs,draft:xs,resume:Cs,rename:Ps,profile:Ss,model:Ds,doctor:Tt,workspace:_s,project:Us,"allow-prod":Ws,login:Fs,logout:Hs,screenshot:dn,"capture-setup":St,devhints:Js,reset:ni};function ri(e){let t=e.trim();if(!t.startsWith("/"))return null;let n=t.slice(1).split(/\s+/),o=(n[0]??"").toLowerCase();return o?{name:o,args:n.slice(1)}:null}q();var Kc={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"},ii=160,Uo=200,ai=40;function ue(e,t){let n=e.replace(/\s+/g," ").trim();return n.length<=t?n:n.slice(0,t-1)+"\u2026"}function si(e){let t=Object.entries(e).filter(([,o])=>o!=null&&o!=="");if(t.length===0)return null;let n=t.slice(0,4).map(([o,r])=>`${o}: ${ue(typeof r=="string"?r:JSON.stringify(r),ai)}`);return t.length>4&&n.push("\u2026"),ue(n.join(", "),ii)}var Ie=e=>typeof e=="string"&&e?e:null,Lo=e=>typeof e=="string"&&e.length>=8?e.slice(0,8):null;function Jc(e){let t=Ie(e)?.replace(/\\/g,"/");if(!t)return null;let n=t.split("/").filter(Boolean);if(n.length<2)return null;let o=n[n.length-2],r=o.replace(/^\d+[-_.]/,"").split(/[-_]/).filter(Boolean);return r.length===0?o:r.map(s=>s.charAt(0).toUpperCase()+s.slice(1)).join(" ")}function Qc(e,t){let n=(o,r)=>({title:`Document360: ${o}`,sep:" ",arg:r});switch(e){case"d360_create_article":{let o=Ie(t.title);if(!o)return null;let r=Jc(t.local_path);return n("Create article",`"${ue(o,60)}"${r?` in ${r}`:""}`)}case"d360_update_article":{let o=Ie(t.title),r=Lo(t.article_id);return n("Update article",o?`"${ue(o,60)}"`:r?`id ${r}\u2026`:null)}case"d360_fork_article":return n("Fork article (new draft)",Lo(t.article_id)?`id ${Lo(t.article_id)}\u2026`:null);case"d360_publish_article":{let o=t.version_number;return n("Publish article LIVE",typeof o=="number"?`v${o}`:null)}case"d360_unpublish_article":return n("Unpublish article",null);case"d360_create_category":return n("Create category",Ie(t.name)?`"${ue(Ie(t.name),60)}"`:null);case"d360_upload_drive_file":{let o=Ie(t.file_path);return n("Upload image",o?ue(o.replace(/\\/g,"/").split("/").pop()??o,60):null)}case"d360_sync_status":return n("Check sync status",null);default:return null}}function fn(e,t){if(e==="ToolSearch")return null;if(e.startsWith("mcp__")){let[,r="",...s]=e.split("__"),c=s.join("__");if(r==="document360"){let w=Qc(c,t);if(w)return w}let d=c.replace(/^d360_/,"").replace(/_/g," ");return{title:`${r==="document360"?"Document360":r.charAt(0).toUpperCase()+r.slice(1)}: ${d}`,sep:" ",arg:si(t)}}let n=Kc[e],o=n?t[n]:void 0;return typeof o=="string"&&o?{title:e,sep:"",arg:ue(o,ii)}:{title:e,sep:"",arg:si(t)}}function Zc(e){if(e===null||typeof e!="object")return typeof e=="string"?e:null;let t=e;for(let n of["name","title","slug","id"])if(typeof t[n]=="string"&&t[n])return t[n];return null}function eu(e){if(!/^[[{]/.test(e))return null;let t;try{t=JSON.parse(e)}catch{return null}if(Array.isArray(t)){let n=t.map(Zc).filter(r=>r!==null),o=`${t.length} item${t.length===1?"":"s"}`;return n.length===0?[o]:[o,...n.map(r=>ue(r,Uo))]}if(t!==null&&typeof t=="object"){let n=Object.entries(t).filter(([,o])=>o!==null&&(typeof o=="string"||typeof o=="number"||typeof o=="boolean")).slice(0,6).map(([o,r])=>`${o}: ${ue(String(r),ai)}`);return n.length>0?[ue(n.join(" \xB7 "),Uo)]:null}return null}function tu(e){let t=Ie(e)?.replace(/\\/g,"/");if(!t)return null;let n=t.split("/").filter(Boolean);return n.length>1?n.slice(1).join("/"):t}function nu(e,t,n){switch(e){case"d360_create_article":{let o=tu(t?.local_path);return[`\u2713 draft created${o?` \xB7 ${o}`:""}`]}case"d360_update_article":return["\u2713 draft updated"];case"d360_fork_article":return["\u2713 forked to a new draft"];case"d360_publish_article":return["\u2713 PUBLISHED LIVE \u2014 visible to readers"];case"d360_unpublish_article":return["\u2713 reverted to draft (removed from readers)"];case"d360_create_category":{let o=Ie(t?.name);return[`\u2713 category created${o?` \xB7 "${o}"`:""}`]}case"d360_upload_drive_file":{let o=n.match(/https?:\/\/\S+/);return[`\u2713 uploaded${o?` \xB7 ${ue(o[0],120)}`:""}`]}default:return null}}function mn(e,t=4,n,o){let r=e.replace(/\r\n/g,`
163
+ `).trimEnd();if(!r)return{lines:["(no output)"],hidden:0};if(n?.startsWith("mcp__document360__")){let c=nu(n.slice(18),o,r);if(c)return{lines:c,hidden:0}}let s=eu(r)??r.split(`
164
+ `);return{lines:s.slice(0,t).map(c=>ue(c,Uo)),hidden:Math.max(0,s.length-t)}}function gn(e,t,n,o="en"){return`${e.replace(/\/$/,"")}/${t}/document/v1/${o}/${n}`}function hn(e,t){if(typeof e.article_id=="string"&&e.article_id)return e.article_id;try{let n=JSON.parse(t),r=(Array.isArray(n)?n[0]:n)?.id;return typeof r=="string"&&r?r:null}catch{return null}}function wn(e){try{let t=JSON.parse(e),o=(Array.isArray(t)?t[0]:t)?.url;return typeof o=="string"&&/^https?:\/\//.test(o)?o:null}catch{return null}}var mu=/^mcp__document360__d360_(create_article|update_article|fork_article|publish_article)$/;function gu(e,t,n,o){if(mu.test(e))try{let r=di(o),s=typeof t.project_id=="string"&&t.project_id||r.project.projectId,c=hn(t,n),d=wn(n);e.endsWith("publish_article")&&d&&console.log(E(` \u2B95 Live: ${d}`)),c&&s&&console.log(E(` \u2B95 Preview: ${gn(r.connection.portalUrl,s,c,r.project.languageCode??"en")}`))}catch{}}async function pi(e=process.cwd(),t="auto",n){let o=ru(t);o.kind==="none"&&(console.error(""),console.error(x("ANTHROPIC_API_KEY is not set (required for --auth api).")),console.error(""),console.error(` ${E("export ANTHROPIC_API_KEY=sk-ant-...")} (macOS / Linux)`),console.error(` ${E('$env:ANTHROPIC_API_KEY="sk-ant-..."')} (PowerShell)`),console.error(""),console.error(`Get a key at ${E("https://console.anthropic.com/settings/keys")}`),console.error(`Or use your Claude subscription instead: ${E("d360-writer --auth subscription")}`),console.error(""),process.exit(2)),hu(e,n),o.kind==="subscription"&&(o.stored?console.log(f(" Using your Claude subscription (no API key set).")):console.log(f(" No API key or stored Claude Code login found \u2014 trying your Claude session anyway.")),console.log(""));let r=!1,s=Wo({cwd:e,profileName:n,allowProdWrites:r}),c={uuid:null,firstPrompt:null,titleFired:!1},d=ou({input:process.stdin,output:process.stdout}),g=[],w=null,$=!1;d.on("line",b=>{if(w){let v=w;w=null,v(b)}else g.push(b)}),d.on("close",()=>{if($=!0,w){let b=w;w=null,b(null)}});function R(){return g.length>0?Promise.resolve(g.shift()):$?Promise.resolve(null):(process.stdout.write(E("> ")),new Promise(b=>{w=b}))}let y={cwd:e,profileName:n,allowProdWrites:()=>r,restartAgent:()=>{s.close(),s=Wo({cwd:e,profileName:n,allowProdWrites:r}),c={uuid:null,firstPrompt:null,titleFired:!1}},currentUuid:()=>c.uuid,setModel:async b=>s.setModel(b),withPausedInput:async b=>{d.pause();try{return await b()}finally{d.resume()}}};try{for(;;){let b=await R();if(b===null)break;let v=b.trim();if(v){if(v.startsWith("/")){let _=ri(v);if(!_)continue;let M=oi[_.name];if(!M){console.log(x(`Unknown command: /${_.name}`)),console.log(f("Type /help for the list."));continue}let H=await M(_.args,y);if(H.kind==="exit")break;if(H.kind==="clear"){y.restartAgent();continue}if(H.kind==="allow-prod"){r=!0,y.restartAgent(),console.log(A("\u2713 Production writes authorized for this session.")),console.log("");continue}if(H.kind==="resume"){s.close(),s=Wo({cwd:e,resume:H.uuid,profileName:n,allowProdWrites:r});let Z=su(H.uuid);c={uuid:H.uuid,firstPrompt:Z?.firstPrompt??null,titleFired:!0},ui(H.uuid),console.log(A(`\u2713 Resumed "${H.name}"`)),console.log("");continue}H.kind==="forward-to-agent"&&(c.firstPrompt||(c.firstPrompt=H.display??H.prompt),await ci(s,H.prompt,o,c,e));continue}c.firstPrompt||(c.firstPrompt=v),await ci(s,v,o,c,e)}}}finally{s.close(),d.close()}}function hu(e,t){console.log(""),console.log(ht("document360-writer")),console.log(f(` cwd: ${e}`));let n=uu(e);console.log(f(` model: ${n.model??"auto (engine right-sizes per task)"}${n.model?` (${n.source})`:""}`)),console.log(wu(e,t)),du(e)||console.log(L(" First run: /init \u2192 /login \u2192 /workspace, then ask for a docs analysis.")),console.log(f(" Type a prompt, or /help for slash commands. /exit to quit.")),console.log("")}function wu(e,t){try{let n=di(e,t),o=n.production?L(" \u26A0 PRODUCTION"):"",r=fu(n.name);if(!r)return f(` Document360: profile "${n.name}"${o} \u2014 not logged in (d360-writer login)`);let s={...li(r.idToken)??{},...li(r.accessToken)??{}},c=s.email??s.preferred_username??"signed in";return pu(r)&&!r.refreshToken?L(` Document360: profile "${n.name}"${o} \u2014 session expired (d360-writer login)`):f(` Document360: ${c} \xB7 profile "${n.name}"${o}`)}catch(n){return f(` Document360: ${n.message.split(".")[0]}`)}}function ku(){console.error(""),console.error(`Sign in with your Claude subscription: run ${E("claude")} once, then retry.`),console.error(` (No Claude Code? ${E("npm install -g @anthropic-ai/claude-code")})`),console.error(`Or set an API key: ${E("https://console.anthropic.com/settings/keys")}`)}function yu(e,t,n){e.uuid=t;let o=new Date().toISOString();lu({uuid:t,name:au(e.firstPrompt??"session"),renamed:!1,titled:!1,cwd:n,firstPrompt:e.firstPrompt??"",createdAt:o,updatedAt:o})}function $u(e,t){e.titleFired=!0;let n=e.uuid,o=e.firstPrompt;!n||!o||cu(o,t).then(r=>{r&&iu(n,r)}).catch(()=>{})}async function ci(e,t,n,o,r){let s=new Map;for await(let c of e.send(t))xu(c,o,r,n,s)}function xu(e,t,n,o,r){switch(e.type){case"session":t.uuid||yu(t,e.sessionId,n);break;case"text":process.stdout.write(e.delta);break;case"tool":{let s=fn(e.name,e.input);s&&(process.stdout.write(`
165
+
166
+ `),console.log(`${A("\u25CF")} ${Ce(s.title)}${s.arg!==null?ee(`${s.sep}(${s.arg})`):""}`),r.set(e.id,{name:e.name,input:e.input}));break}case"article_diff":{let s=qe(e.oldContent,e.newContent,Math.max(40,(process.stdout.columns??80)-1));if(!s)break;let c=d=>d===1?"":"s";console.log(ee(` \u23BF Added ${s.added} line${c(s.added)}, removed ${s.removed} line${c(s.removed)}`));for(let d of s.lines)console.log(d);s.hidden>0&&console.log(f(` \u2026 +${s.hidden} more diff lines`));break}case"tool_result":{let s=r.get(e.id);if(!s)break;r.delete(e.id);let c=mn(e.output,4,e.isError?void 0:s.name,s.input),d=e.isError?x:ee;c.lines.forEach((g,w)=>console.log(d((w===0?" \u23BF ":" ")+g))),c.hidden>0&&console.log(f(` \u2026 +${c.hidden} lines`)),e.isError||gu(s.name,s.input,e.output,n);break}case"result":process.stdout.write(`
167
+ `),console.log(f(` (${e.inputTokens}\u2192${e.outputTokens} tokens`+(e.costUsd>0?`, $${e.costUsd<.01?e.costUsd.toFixed(4):e.costUsd.toFixed(2)}`:"")+")")),console.log(""),t.uuid&&(ui(t.uuid),t.titleFired||$u(t,n));break;case"error":console.error(""),console.error(x(`agent error: ${e.message}`)),o.kind==="subscription"&&e.kind==="auth"&&ku();break}}import{render as yd}from"ink";import{resolveAuth as $d}from"document360-engine";import{useCallback as V,useEffect as _e,useMemo as Go,useRef as Q,useState as B}from"react";import{Box as J,Text as C,useApp as Au,useInput as Eu,useStdout as Iu}from"ink";import{existsSync as zo,readFileSync as Di,readdirSync as Hi,writeFileSync as Ai}from"node:fs";import{basename as Dt,isAbsolute as Nu,join as At}from"node:path";import{createSession as Ei,loginPkce as _u,toStoredTokens as Mu,saveTokens as Ou,getAccessToken as Lu,resolveActiveProfile as de,resolveProjectId as Uu,getArticle as Wu,decodeJwtClaims as dt,isExpired as Ne,loadTokens as Ge,clearTokens as Fu,clearProfileProject as Hu,setTitle as Bu,slugify as qu,touchSession as Yo,upsertSession as Gu,generateTitle as Ii,findByName as zu,listSessions as Yu,renameSession as Vu,suggestNextAction as Xu,readProjectConfig as oe,writeProjectConfig as Ku,resolveModelSetting as Jo,loadProfileMap as Ni,applyPull as Ju,computeSyncStatus as Vo,planPull as Qu,inventoryRepo as Zu,knownEnvironments as ed,resolveEnvironment as td,planPartitions as Xo,partitionEvenly as nd,screenshotPlaceholderIds as od,trackedArticlePaths as rd,runPartitioned as vn,estimateBulkCost as _i,resolveModelForOperation as Cn,readDocsPlan as sd,ensureDir as Mi,hintsDir as id,architectureDir as ad,creatorNotesPath as Oi,devHintsGuidePath as ld}from"document360-engine";import{existsSync as bu,mkdirSync as vu,readFileSync as Cu,writeFileSync as Pu}from"node:fs";import{join as fi}from"node:path";import{writerDir as Tu}from"document360-engine";function mi(e){return fi(Tu(e),".sessions")}function gi(e,t){return fi(mi(e),`${t}.json`)}function hi(e,t,n){try{vu(mi(e),{recursive:!0});let o=n.filter(r=>r.kind!=="banner");Pu(gi(e,t),JSON.stringify({v:1,items:o}),"utf8")}catch{}}function Fo(e,t){try{let n=gi(e,t);if(!bu(n))return[];let o=JSON.parse(Cu(n,"utf8"));return Array.isArray(o.items)?o.items:[]}catch{return[]}}var Su=e=>`\x1B]0;${e}\x07`,Ru=e=>`\x1B]9;4;${e};${e===1?100:0}\x07`;function wi(e){process.stdout.isTTY&&process.stdout.write(e)}function Rt(e){wi(Su(e))}function kn(e){wi(Ru(e))}var yn=["\xB7 "," \xB7"],Ho="\u{1F7E3}";un();var ju=/^(?:\d+[.)]|[-*•])\s+/;function ki(e,t,n=4){let o=new Set(t.map(s=>s.toLowerCase())),r=[];for(let s of e.split(`
168
+ `)){let c=s.trim().replace(ju,""),d=c.match(/^`([^`]+)`$/);d&&(c=d[1].trim());let g=c.match(/^\/([a-z?][a-z0-9-]*)(?:\s+(\S.*?))?\s*$/i);if(!g||!o.has(g[1].toLowerCase()))continue;let w=`/${g[1].toLowerCase()}${g[2]?` ${g[2]}`:""}`;if(r.includes(w)||r.push(w),r.length>=n)break}return r}q();function jt(e){return e.map(t=>({label:t.label,items:t.paths.length,status:"pending"}))}function Pe(e,t,n){return e.map(o=>o.label===t?{...o,status:n}:o)}function Bo(e){return e.replace(/^[\w.-]+\//,"")}var $n=16,yi={pending:"\u25CB",active:"\u25A0",done:"\u2714",failed:"\u2717"};function qo(e){return e.trim().split(/\s+/).slice(1).join(" ")}function $i(e,t){let n=qo(t);return e.some(r=>r.trim()===t.trim()||!!n&&qo(r)===n)?e.filter(r=>r.trim()!==t.trim()&&!(n&&qo(r)===n)):[]}var Du=/\[Pasted text #\d+ \+\d+ lines?\]/g;function xi(e){return e.replace(/\r\n?/g,`
169
+ `)}function bi(e){return e.includes(`
170
+ `)||e.length>200}function vi(e,t){let n=t.split(`
171
+ `).length;return`[Pasted text #${e} +${n} line${n===1?"":"s"}]`}function Ci(e,t){return e.replace(Du,n=>t.get(n)??n)}function Pi(e){let t=e.match(/\[Pasted text #\d+ \+\d+ lines?\]$/);return t?e.slice(0,-t[0].length):null}function xn(e,t){let n=Math.max(1,t),o=[],r=0;for(let s of e.split(`
172
+ `)){if(s.length===0)o.push({start:r,end:r});else for(let c=0;c<s.length;c+=n)o.push({start:r+c,end:r+Math.min(c+n,s.length)});r+=s.length+1}return o.length>0?o:[{start:0,end:0}]}function bn(e,t){let n=0;for(let o=0;o<e.length&&e[o].start<=t;o++)n=o;return n}function Ti(e,t,n){let o=bn(e,t),r=o+n;if(r<0||r>=e.length)return t;let s=Math.min(t,e[o].end)-e[o].start;return Math.min(e[r].start+s,e[r].end)}function Si(e,t,n){let o=e[bn(e,t)];return n==="start"?o.start:o.end}function Ri(e,t,n){let o=Math.max(1,n),r=e.split(`
135
173
  `),s=0;for(let c=r.length-1;c>=0;c--){let d=r[c];if(s+=Math.max(1,Math.ceil(d.length/o)),s>=t){let g=s-t;return{text:[g>0?d.slice(g*o):d,...r.slice(c+1)].join(`
136
- `),truncated:c>0||g>0}}}return{text:e,truncated:!1}}function Ci(e){let t=!1,n=0,o=0;for(let r of e.split(`
137
- `)){let s=o+r.length;/^\s*```/.test(r)?t=!t:!t&&r.trim()===""&&s<e.length&&(n=s+1),o=s+1}return n}import{Fragment as Vo,jsx as S,jsxs as F}from"react/jsx-runtime";var od={project:".d360-writer.json",user:"/model",env:"ANTHROPIC_MODEL","claude-settings":"Claude Code settings","claude-default":""},Ai=` 1. /init \u2014 pick your Document360 environment & scaffold config
174
+ `),truncated:c>0||g>0}}}return{text:e,truncated:!1}}function ji(e){let t=!1,n=0,o=0;for(let r of e.split(`
175
+ `)){let s=o+r.length;/^\s*```/.test(r)?t=!t:!t&&r.trim()===""&&s<e.length&&(n=s+1),o=s+1}return n}import{Fragment as Ko,jsx as S,jsxs as F}from"react/jsx-runtime";var cd={project:".d360-writer.json",user:"/model",env:"ANTHROPIC_MODEL","claude-settings":"Claude Code settings","claude-default":""},Li=` 1. /init \u2014 pick your Document360 environment & scaffold config
138
176
  2. /login signs in to that environment
139
177
  3. /project then /workspace \u2014 pick the project and where articles go
140
- Press 1 to start.`;function rd(e,t,n,o){let r=n.kind==="api"?"API key":n.kind==="subscription"?"subscription":"not configured",s=Xo(e),c=oe(e),d=(c?.docsDir??"user-docs").replace(/\/+$/,""),g=c?.mode==="engineer"?"engineer \xB7 full source access (dogfooding)":`writer \xB7 edits limited to ${d}/ + config`,w={version:t,claude:r,model:s.model??"Claude Code default model",modelSource:od[s.source],who:null,sessionHint:null,profile:"\u2014",apiUrl:"\u2014",project:"\u2014",cwd:e,prod:!1,loggedOut:!0,configured:c!==null,mode:g};if(c===null)return w;try{let $=de(e,o);w.profile=$.name,w.apiUrl=$.connection.apiUrl,w.prod=$.production,w.project=$.project.projectId??"(chosen at login)";let R=Ge($.name);if(R){let y={...dt(R.idToken)??{},...dt(R.accessToken)??{}},b=y.email??y.preferred_username??"signed in";_e(R)?R.refreshToken&&(w.who=b,w.loggedOut=!1,w.sessionHint="session expired \u2014 refreshing\u2026"):(w.who=b,w.loggedOut=!1,w.sessionHint=`session valid until ${new Date(R.expiresAt).toLocaleString(void 0,{hour:"2-digit",minute:"2-digit",day:"2-digit",month:"short"})}`)}}catch{}return w}function sd(e,t){try{let n=de(e,t),o=Ge(n.name);if(!o)return{text:`profile "${n.name}" \u2014 not logged in (/login)`,prod:n.production};let r={...dt(o.idToken)??{},...dt(o.accessToken)??{}},s=r.email??r.preferred_username??"signed in";return _e(o)&&!o.refreshToken?{text:`profile "${n.name}" \u2014 session expired (/login)`,prod:n.production}:{text:`${s} \xB7 profile "${n.name}"`,prod:n.production}}catch(n){return{text:n.message.split(".")[0],prod:!1}}}var Ei=["Drafting","Composing","Outlining","Researching","Documenting","Structuring","Polishing","Synthesizing","Curating","Distilling","Weaving","Wrangling","Pondering"],Tn=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"],id="Ask me to write or update an article\u2026";function Pn({ch:e,dim:t}){let[n,o]=B(!0);return Ne(()=>{let r=setInterval(()=>o(s=>!s),530);return()=>clearInterval(r)},[]),S(C,{inverse:n,color:t&&!n?"gray":void 0,children:e})}var ad=/^mcp__document360__d360_(create_article|update_article|fork_article|publish_article)$/;function Ii(e){let t=e.match(/^---\r?\n[\s\S]*?\r?\n---\r?\n/);return t?e.slice(t[0].length):e}var ld=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function _i(e){try{return Ni(e,{withFileTypes:!0}).filter(t=>t.isDirectory()&&!t.name.startsWith(".")).length>6}catch{return!1}}function cd(e,t){let n=t??[];return n.length===0?["src","api","services","packages","modules"].some(o=>_i(At(e,o))):n.some(o=>!o.includes("/")&&!o.endsWith(".md")&&_i(At(e,o)))}function ud({startTime:e,chars:t}){let[n,o]=B(0);Ne(()=>{let g=setInterval(()=>o(w=>w+1),120);return()=>clearInterval(g)},[]);let r=Tn[n%Tn.length],s=Ei[Math.floor(n/16)%Ei.length],c=Math.floor((Date.now()-e)/1e3),d=Math.round(t/4);return F(J,{children:[S(C,{color:G,children:` ${r} ${s}\u2026 `}),S(C,{color:"gray",children:`(${bt(c)} \xB7 ~${d} tokens \xB7 esc to interrupt)`})]})}var dd=12e4;function pd({p:e}){let[t,n]=B(0);Ne(()=>{let M=setInterval(()=>n(H=>H+1),150);return()=>clearInterval(M)},[]);let o=Tn[t%Tn.length],r=Math.floor((Date.now()-e.startedAt)/1e3),s=Math.floor((Date.now()-e.lastAt)/1e3),c=Math.round(e.chars/4),d=Date.now()-e.lastAt>=dd,g=e.verb??"Converting",w=e.unit??"article",$=e.rows.reduce((M,H)=>M+H.items,0),R=g.toLowerCase(),y=e.rows,b=0;if(y.length>$n){let M=y.findIndex(Z=>Z.status==="active"||Z.status==="pending"),H=Math.max(0,Math.min(M-2,y.length-$n));b=y.slice(0,H).filter(Z=>Z.status==="done").length,y=y.slice(H,H+$n)}let v=Math.min(40,Math.max(...y.map(M=>Ho(M.label).length),0)),N=M=>M==="failed"?"red":M==="active"?G:void 0;return F(J,{flexDirection:"column",children:[F(J,{children:[S(C,{color:G,children:` ${o} ${g} ${$} ${w}${$===1?"":"s"} `}),S(C,{color:"gray",children:`\xB7 ${e.done}/${e.total} \xB7 ${e.tools} tool call${e.tools===1?"":"s"} \xB7 ~${c} tokens \xB7 ${bt(r)} \xB7 esc to stop`})]}),b>0&&S(C,{dimColor:!0,children:` \u2714 +${b} done`}),y.map(M=>F(C,{color:N(M.status),dimColor:M.status==="done"||M.status==="pending",children:[` ${mi[M.status]} ${Ho(M.label).padEnd(v)}`,M.status!=="pending"?` (${M.items} ${w}${M.items===1?"":"s"})`:"",M.status==="active"?` \u2190 ${R}\u2026`:""]},M.label)),d&&S(C,{color:"yellow",children:` \u26A0 no activity for ${bt(s)} \u2014 press esc to stop if it's wedged`})]})}function Mi({cwd:e,auth:t,profileName:n,version:o}){let{exit:r}=Cu(),[s,c]=B(n),[d,g]=B(null),[w,$]=B({text:"",pos:0}),R=w.text,y=V(l=>{$(a=>{let i=typeof l=="function"?l(a.text):l;return{text:i,pos:i.length}})},[]),b=V(l=>{$(a=>({text:a.text.slice(0,a.pos)+l+a.text.slice(a.pos),pos:a.pos+l.length}))},[]),v=V(()=>{$(l=>{if(l.pos===0)return l;let a=l.text.slice(0,l.pos),i=$i(a)??a.slice(0,-1);return{text:i+l.text.slice(l.pos),pos:i.length}})},[]),[N,M]=B(!1),[H,Z]=B(!1),[$e,te]=B(0),[we,re]=B(null),[pt,X]=B([]),ze=Q(0),[Wi,Et]=B(!1),[Fi,Ye]=B(0),Me=Q(0),[ft,Ve]=B(0),[Xe,It]=B(null),Qo=Q(new Map),Hi=Q(0),Ke=Q([]),pe=Q(null);pe.current===null&&(pe.current=Si({cwd:e,profileName:s,allowProdWrites:!1}));let xe=Q({uuid:null,firstPrompt:null,titleFired:!1}),_t=Q(new Map),Je=Q(!1),Sn=Q([]),Se=Q([]),Rn=Q(null),[Zo,Qe]=B(null),[Le,Oe]=B(null),[be,Ze]=B(null),[Re,et]=B(null),[ae,tt]=B(null),[fe,nt]=B(null),[Ue,ot]=B(null),[er,Nt]=B(null),[me,We]=B(null),[le,rt]=B(null),[tr,jn]=B([]),Fe=Q([]),Mt=Q(!1),ge=Q(null),[nr,K]=B(null),Lt=Q(!1),Ot=Q(null),[he,He]=B(null),[or,st]=B(0),[rr,it]=B(0),[Bi,sr]=B(0),Dn=qo(()=>{try{return Xo(e).model??"auto"}catch{return null}},[e,Bi]),{stdout:ke}=Tu(),[,qi]=B(0),ir=Q(`${ke.columns??80}x${ke.rows??24}`),je=V(()=>Math.max(20,(ke.columns??80)-1),[ke]),p=V(l=>{Ke.current.push(l),console.log(Kn(l,je()))},[je]);Ne(()=>{let l=`d360-writer \xB7 ${Zo??Dt(e)}`;if(!N){kn(0),Rt(`${Fo} ${l}`);return}kn(3);let a=0;Rt(`${yn[0]} ${l}`);let i=setInterval(()=>{a=(a+1)%yn.length,Rt(`${yn[a]} ${l}`)},400);return()=>clearInterval(i)},[N,e,Zo]),Ne(()=>()=>kn(0),[]),Ne(()=>{if(p({kind:"banner",info:rd(e,o,t,s)}),!oe(e)){p({kind:"note",tone:"info",text:`Welcome! This repo isn't set up for d360-writer yet \u2014 three steps and you're writing docs:
141
- ${Ai}`}),X(["/init"]);return}try{let l=de(e,s),a=Ge(l.name);a&&_e(a)&&a.refreshToken?Eu({profile:l.name,connection:l.connection}).then(()=>{p({kind:"note",tone:"ok",text:"\u2713 Document360 session refreshed."}),te(i=>i+1)}).catch(()=>{p({kind:"note",tone:"warn",text:"Document360 session refresh failed \u2014 do you want to log in now? (press 1)"}),X(["/login"])}):(!a||_e(a))&&(p({kind:"note",tone:"warn",text:`Profile "${l.name}" is not signed in \u2014 do you want to log in now? (press 1)`}),X(["/login"]))}catch{}try{let l=oe(e),a=de(e,s),i=Ge(a.name);l&&i&&!_e(i)&&cd(e,l.authoritativeSourceFiles)&&(p({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{}},[]),Ne(()=>{let l=null,a=null,i=()=>{l&&clearTimeout(l),l=setTimeout(()=>{l=null;let h=`${ke.columns??80}x${ke.rows??24}`;h!==ir.current&&(ir.current=h,qi(u=>u+1),a&&clearTimeout(a),a=setTimeout(()=>{a=null,console.log("\x1B[?2026h\x1B[H\x1B[2J"+Jr(Ke.current,je())+"\x1B[?2026l")},80))},400)};return ke.on("resize",i),()=>{l&&clearTimeout(l),a&&clearTimeout(a),ke.off("resize",i)}},[ke,je]);let Be=Math.max(20,(ke.columns??80)-1),ar=qo(()=>sd(e,s),[e,s,$e]),An=(()=>{let l=oe(e);if(!l)return{text:"Press 1 to set up this repo, or /help\u2026",isSetup:!0};let a=At(e,(l.docsDir??"user-docs").replace(/\/+$/,"")),i=(()=>{try{return Pi(a)&&Ni(a).length>0}catch{return!1}})();try{let h=de(e,s),u=Ge(h.name);if(!(!!u&&!(_e(u)&&!u.refreshToken)))return{text:`Press 1 to sign in to Document360 (profile "${h.name}")\u2026`,isSetup:!0};if(!h.project.workspaceId&&!i)return{text:"Press 1 to pick a workspace\u2026",isSetup:!0}}catch{}return i?{text:id,isSetup:!1}:{text:"Let's get started \u2014 try: write the docs for this repo",isSetup:!1}})(),mt=Dr(R),lr=mt.length>0&&!N,En=d!==null?vi(d,8,Be):null,Ut=me?me.paths.filter(l=>!me.query||l.toLowerCase().includes(me.query.toLowerCase())).slice(0,8):[],Wt=he?he.sessions.filter(l=>{let a=he.query.toLowerCase();return!a||l.name.toLowerCase().includes(a)||l.firstPrompt.toLowerCase().includes(a)}).slice(0,8):[],ce=V((l,a)=>{pe.current?.close(),pe.current=Si({cwd:e,resume:l,profileName:a??s,allowProdWrites:Je.current}),l||(xe.current={uuid:null,firstPrompt:null,titleFired:!1},Qe(null)),st(0),it(0)},[e,s]),cr=V((l,a,i)=>{if(ad.test(l))try{let h=de(e,s),u=typeof a.project_id=="string"&&a.project_id||h.project.projectId,m=hn(a,i),k=[],P=wn(i);l.endsWith("publish_article")&&P&&k.push(`Live: ${P}`),m&&u&&k.push(`Preview: ${gn(h.connection.portalUrl,u,m,h.project.languageCode??"en")}`),k.length>0&&p({kind:"link",lines:k})}catch{}},[e,s,p]),ve=V(async(l,a)=>{Et(!0),re(null),X([]),Nt(null);let i=++ze.current;p({kind:"user",text:a?.echoDisplay&&a.display?a.display:l});let h=xe.current;h.firstPrompt||(h.firstPrompt=a?.display??l),Me.current=Date.now(),Ye(0),M(!0),_t.current.clear();let u="",m="",k=null,P=()=>{k||(k=setTimeout(()=>{k=null,g(m.length>0?m:null)},60))},_=()=>{k&&clearTimeout(k),k=null,g(null)},j=()=>{if(m.trim()){let I=m.trimEnd();p({kind:"assistant",text:I})}m="",_()};try{for await(let I of pe.current.send(l))if(I.type==="session"){if(!h.uuid){h.uuid=I.sessionId;let L=new Date().toISOString(),T=Ou(h.firstPrompt??"session");Uu({uuid:I.sessionId,name:T,renamed:!1,titled:!1,cwd:e,firstPrompt:h.firstPrompt??"",createdAt:L,updatedAt:L}),Qe(T)}}else if(I.type==="text"){m+=I.delta,u+=I.delta;let L=Ci(m);if(L>0){let T=m.slice(0,L).trimEnd();T&&p({kind:"assistant",text:T}),m=m.slice(L)}P(),Ye(T=>T+I.delta.length)}else if(I.type==="tool"){let L=fn(I.name,I.input);L&&(j(),p({kind:"tool",title:L.title,sep:L.sep,arg:L.arg}),_t.current.set(I.id,{name:I.name,input:I.input}))}else if(I.type==="article_diff"){let L=qe(I.oldContent,I.newContent,je());L&&(j(),p({kind:"diff",added:L.added,removed:L.removed,lines:L.lines,hidden:L.hidden}))}else if(I.type==="tool_result"){I.isError&&/run \/login|not logged in|session expired|rejected the token/i.test(I.output)&&(Lt.current=!0);let L=_t.current.get(I.id);if(L){_t.current.delete(I.id),j();let T=mn(I.output,4,I.isError?void 0:L.name,L.input);p({kind:"tool-result",lines:T.lines,hidden:T.hidden,isError:I.isError}),I.isError||cr(L.name,L.input,I.output)}}else if(I.type==="result"){j(),st(T=>T+I.outputTokens),it(T=>T+I.costUsd),p({kind:"done",seconds:Math.round((Date.now()-Me.current)/1e3),tokens:I.outputTokens,costUsd:I.costUsd,ok:I.ok});let L=I.ok?fi(u,yt.map(T=>T.name)):[];if(L.length>0?X(L):I.ok&&u.trim()&&Bu(l,u,e).then(T=>{T&&ze.current===i&&re(T)}).catch(()=>{}),h.uuid&&(Go(h.uuid),!h.titleFired)){h.titleFired=!0;let T=h.uuid,D=h.firstPrompt;D&&Ri(D,e).then(W=>{W&&(Lu(T,W),Qe(W))}).catch(()=>{})}}else I.type==="error"&&(j(),I.kind==="auth"&&(Lt.current=!0),p({kind:"note",text:`agent error: ${I.message}`,tone:"error"}))}finally{M(!1),_(),te(I=>I+1),xe.current.uuid&&di(e,xe.current.uuid,Ke.current),Lt.current&&(Lt.current=!1,Ot.current=a?.display??l,X(["/login"])),Mt.current&&(Mt.current=!1,Fe.current.length>0&&(p({kind:"note",tone:"info",text:`(${Fe.current.length} queued message(s) discarded)`}),Fe.current=[],jn([])),p({kind:"note",tone:"warn",text:"Interrupted. What do you want to do next?"}))}},[e,p,cr,je]),Ft=V(async l=>{let a=Yo(l),i=Cn(e,"standard");Me.current=Date.now(),Ye(0),M(!0);let h=new AbortController;ge.current=h,K({verb:"Publishing",total:a.length,done:0,active:[],rows:jt(a),tools:0,chars:0,lastAt:Date.now(),startedAt:Date.now()}),p({kind:"note",tone:"info",text:`Publishing ${l.length} article${l.length===1?"":"s"} across ${a.length} partition${a.length===1?"":"s"} (\u2264${vt} agents at once) on ${i.model}\u2026 (esc to stop)`});try{for await(let u of vn({cwd:e,partitions:a,promptFor:m=>nn(m.paths),concurrency:vt,profileName:s,allowProdWrites:Je.current,model:i.model,signal:h.signal}))if(u.type==="partition_status")u.status==="running"?K(m=>m&&{...m,active:[...m.active,u.label],rows:Pe(m.rows,u.label,"active"),lastAt:Date.now()}):K(m=>m&&{...m,active:m.active.filter(k=>k!==u.label),done:m.done+1,rows:Pe(m.rows,u.label,u.status==="done"?"done":"failed"),lastAt:Date.now()});else if(u.type==="partition_event")K(m=>{if(!m)return m;let k={...m,lastAt:Date.now()};return u.event.type==="tool"?k.tools=m.tools+1:u.event.type==="text"&&(k.chars=m.chars+u.event.delta.length),k});else if(u.type==="run_done"){it(P=>P+u.totalCostUsd),st(P=>P+u.results.reduce((_,j)=>_+j.outputTokens,0));let m=u.aborted?"Stopped. ":"",k=t.kind==="api"?"api":"subscription";p({kind:"note",tone:u.aborted?"warn":u.ok?"ok":"warn",text:m+eo(u.results,a,k).join(`
142
- `)})}}catch(u){p({kind:"note",tone:"error",text:`Publish run failed: ${u.message}`})}finally{ge.current=null,K(null),M(!1),te(u=>u+1)}},[e,s,p,t]),In=V(async l=>{await ve(Zn(l),{display:`/publish ${l}`,echoDisplay:!0});try{let a=await on(e,s,l.replace(/\\/g,"/"));a.length>0&&(Nt(`Related articles not yet published (${a.length}):`),X([`/publish --related ${l}`,...a.map(i=>`/publish ${i}`)]))}catch{}},[e,s,ve]),_n=V(l=>{let a=Ge(l);if(!a||_e(a)&&!a.refreshToken)return null;let i={...dt(a.idToken)??{},...dt(a.accessToken)??{}};return i.email??i.preferred_username??"signed in"},[]),Nn=V((l,a)=>{if(a){let i=oe(e);i&&(i.defaultProfile=l,qu(i,e))}c(l),ce(void 0,l),p({kind:"note",tone:"ok",text:`\u2713 Switched to profile "${l}"${a?" (saved as default)":" (this session only)"} \u2014 agent restarted.`}),_n(l)||(p({kind:"note",tone:"warn",text:`Profile "${l}" is not signed in \u2014 do you want to log in now? (press 1)`}),X(["/login"])),te(i=>i+1)},[e,p,ce,_n]),Ht=V((l,a,i)=>{zt(e,l,a,i.id,i.name),p({kind:"note",tone:"ok",text:`Switched to workspace "${i.name??i.id}" (agent restarted).`}),ce(),ji(e,l)||(p({kind:"note",tone:"info",text:"Setup complete. Press tab to start with a docs analysis."}),re("analyze this repo and propose a docs structure"))},[e,p,ce]),Mn=V(async l=>{let a;try{a=await wt(e,l)}catch{p({kind:"note",tone:"info",text:"Next: pick a workspace \u2014 run /workspace."}),X(["/workspace"]);return}if(a.workspaces.length===0){p({kind:"note",tone:"warn",text:"This project has no workspaces yet. Create one in Document360, then run /workspace."});return}let i=a.workspaces.filter(u=>(u.workspace_type??"").toLowerCase()!=="apidocumentation"),h=i.length>0?i:a.workspaces;if(h.length===1){let u=h[0],m=a.workspaces.length-h.length;p({kind:"note",tone:"ok",text:`Selected the "${u.name??u.id}" workspace${m>0?" (skipped the API-documentation workspace)":""}.`}),Ht(a.profile,a.projectId,u);return}p({kind:"note",tone:"info",text:`Next: pick the workspace your articles publish to (${h.length} available).`}),X(["/workspace"])},[e,p,Ht]),ur=V((l,a)=>{To(e,l,a.id),p({kind:"note",tone:"ok",text:`Project set to "${a.name??a.id}" (agent restarted).`}),ce(),Mn(l)},[e,p,ce,Mn]),Bt=V(()=>{let l=Se.current[0];if(!l)return;p({kind:"note",tone:"info",text:`\u25CF ${l.title} (${l.path})`});for(let i of l.notes)p({kind:"note",tone:"warn",text:`\u26A0 ${i}`});l.overwritesLocalChanges&&p({kind:"note",tone:"warn",text:"\u26A0 This OVERWRITES local edits made since the last sync."});let a=qe(l.oldContent,l.newContent,je());p(a?{kind:"diff",added:a.added,removed:a.removed,lines:a.lines,hidden:a.hidden}:{kind:"note",tone:"info",text:"Local file already matches the remote content \u2014 applying only advances the sync base."}),p({kind:"note",tone:"info",text:`Write ${l.path}? (y/n \u2014 anything else cancels)`})},[p,je]),dr=V(l=>{if(Se.current.length===0)return!1;let a=l.trim().toLowerCase();if(a==="y"||a==="yes"){let i=Se.current.shift();try{Gu({cwd:e,profileName:s},i),p({kind:"note",tone:"ok",text:`\u2713 Pulled ${i.path} (sync base advanced).`}),Se.current.length===0&&X(h=>h.length>0?h:["/sync"])}catch(h){p({kind:"note",tone:"error",text:`Pull failed: ${h.message}`})}}else if(a==="n"||a==="no"){let i=Se.current.shift();p({kind:"note",tone:"info",text:`Skipped ${i.path}.`})}else{let i=Se.current.length;return Se.current=[],p({kind:"note",tone:"info",text:`Pull cancelled (${i} article(s) left untouched).`}),!0}return Bt(),!0},[e,s,Bt,p]),pr=V(l=>{let a=Rn.current;if(!a)return!1;if(Rn.current=null,re(null),ze.current++,l.trim()!==a.repoName)return p({kind:"note",tone:"warn",text:"Reset cancelled \u2014 nothing deleted."}),!0;let{removed:i,failed:h}=No(e,a.targets);p({kind:"note",tone:h.length?"warn":"ok",text:`\u2713 Reset complete \u2014 removed ${i.length} item${i.length===1?"":"s"}. The repo is back to its original state.`});for(let u of h)p({kind:"note",tone:"error",text:` \u2717 ${u.path}: ${u.error}`});return p({kind:"note",tone:"info",text:`Clean slate \u2014 set up d360-writer again whenever you're ready:
143
- ${Ai}`}),X(["/init"]),Et(!1),!0},[e,p]),fr=V(async l=>{let a=l.slice(1).trim().split(/\s+/),i=(a[0]??"").toLowerCase(),h=a.slice(1);switch(Et(!0),i){case"help":p({kind:"note",tone:"info",text:Zt().join(`
144
- `)});return;case"exit":case"quit":pe.current?.close(),r();return;case"clear":ce(),Ke.current=[],Et(!1),re(null),ze.current++,p({kind:"note",tone:"info",text:"Conversation reset (the previous session is still resumable via /resume)."});return;case"login":{let u;try{u=de(e,s)}catch(m){p({kind:"note",tone:"error",text:m.message});return}p({kind:"note",tone:"info",text:`Profile "${u.name}" \u2192 ${u.connection.name} (${u.connection.apiUrl})${u.production?" \u26A0 PRODUCTION":""}`}),Z(!0);try{let m=await ju(u.connection,{promptForRedirect:()=>Promise.reject(new Error("Manual login is CLI-only. Run: d360-writer login --manual"))},_=>p({kind:"note",tone:"info",text:_})),k=Du(u.name,m);Au(k),Wn(k,u.name,_=>p({kind:"note",tone:"info",text:_})),p({kind:"note",tone:"ok",text:`\u2713 Logged in to "${u.name}" as ${Vt(k)}`});let P=(()=>{try{return de(e,s)}catch{return u}})();P.project.workspaceId||(P.project.projectId?await Mn(P.name):(p({kind:"note",tone:"info",text:"Next: pick the Document360 project."}),X(["/project"]))),Ot.current&&(re(Ot.current),Ot.current=null,p({kind:"note",tone:"info",text:"Press tab to re-send your last prompt."}))}catch(m){p({kind:"note",tone:"error",text:`Login failed: ${m.message}`})}finally{Z(!1),te(m=>m+1)}return}case"allow-prod":{let u=!1;try{u=de(e,s).production}catch{}if(!u){p({kind:"note",tone:"info",text:"Current profile is not production \u2014 writes are already allowed."});return}Je.current=!0,ce(),p({kind:"note",tone:"warn",text:"\u26A0 Production writes authorized for this session."});return}case"rename":{let u=xo(h.join(" ")),m=xe.current.uuid;if(!m){p({kind:"note",tone:"error",text:"Send a message first \u2014 sessions save once the agent replies."});return}if(!u){p({kind:"note",tone:"info",text:"Thinking of a name\u2026"});let k=xe.current.firstPrompt??"";Ri(k,e).then(P=>{P?(re(`/rename ${P}`),p({kind:"note",tone:"info",text:`Suggestion: "${P}" \u2014 press tab to accept, or type /rename <your name>.`})):p({kind:"note",tone:"info",text:"Usage: /rename <name>"})}).catch(()=>p({kind:"note",tone:"info",text:"Usage: /rename <name>"}));return}Hu(m,u),Qe(u),Rt(`${Fo} d360-writer \xB7 ${u}`),p({kind:"note",tone:"ok",text:`Session renamed to "${u}".`});return}case"profile":{let u=h[0],m=oe(e);if(!u){let k=Object.entries(m?.profiles??{});if(k.length===0){p({kind:"note",tone:"info",text:"No profiles. Run /init first."});return}let P=k.map(([I,L])=>({name:I,env:L.connection?.environment??"custom",prod:L.production===!0,who:_n(I)})),_=s??m?.defaultProfile,j=Math.max(0,P.findIndex(I=>I.name===_));Ze({cursor:j,current:j,rows:P});return}if(u==="add"){let k=bo(e,h[1],h[2]);if(k){p({kind:"note",tone:"error",text:k});return}p({kind:"note",tone:"ok",text:`\u2713 Profile "${h[1]}" created (environment: ${h[2]??h[1]}).`}),Nn(h[1],!1);return}if(!m?.profiles?.[u]){p({kind:"note",tone:"error",text:`Unknown profile "${u}". Create it: /profile add ${u} <environment>`});return}Nn(u,!0);return}case"doctor":await Tt(h,{cwd:e});return;case"mcp":await tn(h);return;case"init":{if(oe(e)){p({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 u=Vu().map(m=>({name:m,apiUrl:Xu(m).apiUrl}));et({cursor:0,rows:u});return}case"resume":{let u=h.join(" ").trim(),m=Fu(e).filter(_=>_.uuid!==xe.current.uuid);if(!u){if(!m.length){p({kind:"note",tone:"info",text:"No saved sessions for this repo yet."});return}He({query:"",cursor:0,sessions:m});return}let k=Wu(e,u);if(!k){p({kind:"note",tone:"error",text:`No session matches "${u}".`});return}ce(k.uuid),xe.current={uuid:k.uuid,firstPrompt:k.firstPrompt,titleFired:!0},Qe(k.name),Go(k.uuid),Ke.current=[];let P=Wo(e,k.uuid);for(let _ of P)p(_);p({kind:"note",tone:"ok",text:P.length?`Resumed "${k.name}" \u2014 restored ${P.length} message(s); continue where you left off.`:`Resumed "${k.name}" (agent memory reconnected; no saved transcript to replay).`});return}case"workspace":{let u=h.join(" ").trim(),m;try{m=await wt(e,s)}catch(P){p({kind:"note",tone:"error",text:`Could not list workspaces: ${P.message}`});return}if(!u){let P=m.workspaces.map(j=>({id:j.id,name:j.name??j.id,type:j.workspace_type}));if(P.length===0){p({kind:"note",tone:"info",text:"No workspaces in this project."});return}let _=Math.max(0,P.findIndex(j=>j.id===m.current));tt({cursor:_,current:_,rows:P,profile:m.profile,projectId:m.projectId,environment:m.environment});return}let k=Un(m.workspaces,u);if(!k){p({kind:"note",tone:"error",text:`No workspace matches "${u}".`});return}Ht(m.profile,m.projectId,k);return}case"project":{let u=h.join(" ").trim(),m;try{m=await Po(e,s)}catch(P){p({kind:"note",tone:"error",text:`Could not list projects: ${P.message} (signed in? try /login)`});return}if(!u){let P=m.projects.map(j=>({id:j.id,name:j.name??j.id,sub:j.sub_domain}));if(P.length===0){p({kind:"note",tone:"info",text:"No projects found for this identity."});return}let _=P.findIndex(j=>j.id===m.current);nt({cursor:Math.max(0,_),current:_,rows:P,profile:m.profile,environment:m.environment});return}let k=Ns(m.projects,u);if(!k){p({kind:"note",tone:"error",text:`No project matches "${u}". Available: ${m.projects.map(P=>P.name??P.id).join(", ")}`});return}ur(m.profile,k);return}case"logout":{let u;try{u=de(e,s).name}catch(k){p({kind:"note",tone:"error",text:k.message});return}let m=Nu(u);Mu(e,u),ce(),te(k=>k+1),p({kind:"note",tone:m?"ok":"info",text:m?`\u2713 Signed out of "${u}" and cleared its project/workspace selection.`:`Profile "${u}" was not signed in. Cleared any project/workspace selection.`}),p({kind:"note",tone:"info",text:"Run /login to sign in and pick a project."}),X(["/login"]);return}case"publish":{if(h[0]==="--related"&&h[1]){let m=await on(e,s,h[1].replace(/\\/g,"/"));if(m.length===0){p({kind:"note",tone:"ok",text:"\u2713 All related articles are already published."});return}await Ft(m);return}if(h[0]&&h[0]!=="--all"){await In(h[0]);return}let u=h[0]==="--all";p({kind:"note",tone:"info",text:"Checking what needs publishing\u2026"});try{let m=await zo({cwd:e,profileName:s}),k=Ct(m.entries);if(k.length===0){p({kind:"note",tone:"ok",text:"\u2713 Nothing is ahead of Document360 \u2014 no publish candidates."});let P=m.counts["unknown-base"]??0;P>0&&p({kind:"note",tone:"info",text:`(${P} article(s) have no sync base yet \u2014 publish those by path if needed.)`});return}if(u){await Ft(k.map(P=>P.path));return}ot({cursor:0,rows:Zr(k)})}catch(m){p({kind:"note",tone:"error",text:`Could not compute sync status: ${m.message}`}),p({kind:"note",tone:"info",text:"Publish a specific article: /publish <article-path>"})}return}case"preview":{let u=h.join(" ").trim();if(!u){let k=[];try{k=Object.keys(ji(e,de(e,s).name)?.articles??{})}catch{}if(k.length===0){p({kind:"note",tone:"info",text:"No tracked articles to pick from yet. Usage: /preview <path-to.md | article-id>"});return}We({query:"",cursor:0,paths:k});return}let m=Ru(u)?u:At(e,u);if(Pi(m)){try{p({kind:"preview",name:Dt(m),text:Ii(Ti(m,"utf8"))})}catch(k){p({kind:"note",tone:"error",text:`Could not read ${m}: ${k.message}`})}return}if(ld.test(u)){try{let k=de(e,s),P={profile:k.name,connection:k.connection},_=k.project.projectId??Iu(P),j=await _u(P,_,u);p({kind:"preview",name:j.title??u,text:j.content??"*(article has no content)*"})}catch(k){p({kind:"note",tone:"error",text:`Could not fetch article: ${k.message}`})}return}p({kind:"note",tone:"error",text:`"${u}" is neither a file (relative to ${e}) nor an article id.`});return}case"model":{let u=h[0]?.trim();if(!u){let _=cn(Xo(e));Oe({cursor:_,current:_});return}let{lines:m,changed:k,effective:P}=Pt(e,u);for(let _ of m)p({kind:"note",tone:_.startsWith("\u26A0")?"warn":_.startsWith("\u2713")?"ok":"info",text:_});k&&(sr(_=>_+1),pe.current?.setModel(P));return}case"convert":{if(!oe(e)){p({kind:"note",tone:"error",text:"No d360-writer config here. Run /init first."});return}let{scope:u,run:m}=ro(h),k=Qu(e,s);if(k.length===0){p({kind:"note",tone:"error",text:"No tracked articles in d360-category-map.json. Publish some first (/publish), then /convert."});return}let P=so(k,u);if(P.length===0){p({kind:"note",tone:"error",text:`No tracked articles under "${u}". (${k.length} are tracked overall.)`});return}let _=Yo(P),j=3,I=`/convert${u?` --scope ${u}`:""} --run`,L=Cn(e,"light");if(!m){let D=Di({files:io(e,P),op:"convert",model:L.model}),W=u?`Scope: ${u} (${P.length} of ${k.length} tracked)
178
+ Press 1 to start.`;function ud(e,t,n,o){let r=n.kind==="api"?"API key":n.kind==="subscription"?"subscription":"not configured",s=Jo(e),c=oe(e),d=(c?.docsDir??"user-docs").replace(/\/+$/,""),g=c?.mode==="engineer"?"engineer \xB7 full source access (dogfooding)":`writer \xB7 edits limited to ${d}/ + config`,w={version:t,claude:r,model:s.model??"Claude Code default model",modelSource:cd[s.source],who:null,sessionHint:null,profile:"\u2014",apiUrl:"\u2014",project:"\u2014",cwd:e,prod:!1,loggedOut:!0,configured:c!==null,mode:g};if(c===null)return w;try{let $=de(e,o);w.profile=$.name,w.apiUrl=$.connection.apiUrl,w.prod=$.production,w.project=$.project.projectId??"(chosen at login)";let R=Ge($.name);if(R){let y={...dt(R.idToken)??{},...dt(R.accessToken)??{}},b=y.email??y.preferred_username??"signed in";Ne(R)?R.refreshToken&&(w.who=b,w.loggedOut=!1,w.sessionHint="session expired \u2014 refreshing\u2026"):(w.who=b,w.loggedOut=!1,w.sessionHint=`session valid until ${new Date(R.expiresAt).toLocaleString(void 0,{hour:"2-digit",minute:"2-digit",day:"2-digit",month:"short"})}`)}}catch{}return w}function dd(e,t){try{let n=de(e,t),o=Ge(n.name);if(!o)return{text:`profile "${n.name}" \u2014 not logged in (/login)`,prod:n.production};let r={...dt(o.idToken)??{},...dt(o.accessToken)??{}},s=r.email??r.preferred_username??"signed in";return Ne(o)&&!o.refreshToken?{text:`profile "${n.name}" \u2014 session expired (/login)`,prod:n.production}:{text:`${s} \xB7 profile "${n.name}"`,prod:n.production}}catch(n){return{text:n.message.split(".")[0],prod:!1}}}var Ui=["Drafting","Composing","Outlining","Researching","Documenting","Structuring","Polishing","Synthesizing","Curating","Distilling","Weaving","Wrangling","Pondering"],Tn=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"],pd="Ask me to write or update an article\u2026";function Pn({ch:e,dim:t}){let[n,o]=B(!0);return _e(()=>{let r=setInterval(()=>o(s=>!s),530);return()=>clearInterval(r)},[]),S(C,{inverse:n,color:t&&!n?"gray":void 0,children:e})}var fd=/^mcp__document360__d360_(create_article|update_article|fork_article|publish_article)$/;function Wi(e){let t=e.match(/^---\r?\n[\s\S]*?\r?\n---\r?\n/);return t?e.slice(t[0].length):e}var md=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function Fi(e){try{return Hi(e,{withFileTypes:!0}).filter(t=>t.isDirectory()&&!t.name.startsWith(".")).length>6}catch{return!1}}function gd(e,t){let n=t??[];return n.length===0?["src","api","services","packages","modules"].some(o=>Fi(At(e,o))):n.some(o=>!o.includes("/")&&!o.endsWith(".md")&&Fi(At(e,o)))}function hd({startTime:e,chars:t}){let[n,o]=B(0);_e(()=>{let g=setInterval(()=>o(w=>w+1),120);return()=>clearInterval(g)},[]);let r=Tn[n%Tn.length],s=Ui[Math.floor(n/16)%Ui.length],c=Math.floor((Date.now()-e)/1e3),d=Math.round(t/4);return F(J,{children:[S(C,{color:G,children:` ${r} ${s}\u2026 `}),S(C,{color:"gray",children:`(${bt(c)} \xB7 ~${d} tokens \xB7 esc to interrupt)`})]})}var wd=12e4;function kd({p:e}){let[t,n]=B(0);_e(()=>{let M=setInterval(()=>n(H=>H+1),150);return()=>clearInterval(M)},[]);let o=Tn[t%Tn.length],r=Math.floor((Date.now()-e.startedAt)/1e3),s=Math.floor((Date.now()-e.lastAt)/1e3),c=Math.round(e.chars/4),d=Date.now()-e.lastAt>=wd,g=e.verb??"Converting",w=e.unit??"article",$=e.rows.reduce((M,H)=>M+H.items,0),R=g.toLowerCase(),y=e.rows,b=0;if(y.length>$n){let M=y.findIndex(Z=>Z.status==="active"||Z.status==="pending"),H=Math.max(0,Math.min(M-2,y.length-$n));b=y.slice(0,H).filter(Z=>Z.status==="done").length,y=y.slice(H,H+$n)}let v=Math.min(40,Math.max(...y.map(M=>Bo(M.label).length),0)),_=M=>M==="failed"?"red":M==="active"?G:void 0;return F(J,{flexDirection:"column",children:[F(J,{children:[S(C,{color:G,children:` ${o} ${g} ${$} ${w}${$===1?"":"s"} `}),S(C,{color:"gray",children:`\xB7 ${e.done}/${e.total} \xB7 ${e.tools} tool call${e.tools===1?"":"s"} \xB7 ~${c} tokens \xB7 ${bt(r)} \xB7 esc to stop`})]}),b>0&&S(C,{dimColor:!0,children:` \u2714 +${b} done`}),y.map(M=>F(C,{color:_(M.status),dimColor:M.status==="done"||M.status==="pending",children:[` ${yi[M.status]} ${Bo(M.label).padEnd(v)}`,M.status!=="pending"?` (${M.items} ${w}${M.items===1?"":"s"})`:"",M.status==="active"?` \u2190 ${R}\u2026`:""]},M.label)),d&&S(C,{color:"yellow",children:` \u26A0 no activity for ${bt(s)} \u2014 press esc to stop if it's wedged`})]})}function Bi({cwd:e,auth:t,profileName:n,version:o}){let{exit:r}=Au(),[s,c]=B(n),[d,g]=B(null),[w,$]=B({text:"",pos:0}),R=w.text,y=V(l=>{$(a=>{let i=typeof l=="function"?l(a.text):l;return{text:i,pos:i.length}})},[]),b=V(l=>{$(a=>({text:a.text.slice(0,a.pos)+l+a.text.slice(a.pos),pos:a.pos+l.length}))},[]),v=V(()=>{$(l=>{if(l.pos===0)return l;let a=l.text.slice(0,l.pos),i=Pi(a)??a.slice(0,-1);return{text:i+l.text.slice(l.pos),pos:i.length}})},[]),[_,M]=B(!1),[H,Z]=B(!1),[$e,te]=B(0),[we,re]=B(null),[pt,X]=B([]),ze=Q(0),[Yi,Et]=B(!1),[Vi,Ye]=B(0),Me=Q(0),[ft,Ve]=B(0),[Xe,It]=B(null),er=Q(new Map),Xi=Q(0),Ke=Q([]),pe=Q(null);pe.current===null&&(pe.current=Ei({cwd:e,profileName:s,allowProdWrites:!1}));let xe=Q({uuid:null,firstPrompt:null,titleFired:!1}),Nt=Q(new Map),Je=Q(!1),Sn=Q([]),Se=Q([]),Rn=Q(null),[tr,Qe]=B(null),[Oe,Le]=B(null),[be,Ze]=B(null),[Re,et]=B(null),[ae,tt]=B(null),[fe,nt]=B(null),[Ue,ot]=B(null),[nr,_t]=B(null),[me,We]=B(null),[le,rt]=B(null),[or,jn]=B([]),Fe=Q([]),Mt=Q(!1),ge=Q(null),[rr,K]=B(null),Ot=Q(!1),Lt=Q(null),[he,He]=B(null),[sr,st]=B(0),[ir,it]=B(0),[Ki,ar]=B(0),Dn=Go(()=>{try{return Jo(e).model??"auto"}catch{return null}},[e,Ki]),{stdout:ke}=Iu(),[,Ji]=B(0),lr=Q(`${ke.columns??80}x${ke.rows??24}`),je=V(()=>Math.max(20,(ke.columns??80)-1),[ke]),p=V(l=>{Ke.current.push(l),console.log(Kn(l,je()))},[je]);_e(()=>{let l=`d360-writer \xB7 ${tr??Dt(e)}`;if(!_){kn(0),Rt(`${Ho} ${l}`);return}kn(3);let a=0;Rt(`${yn[0]} ${l}`);let i=setInterval(()=>{a=(a+1)%yn.length,Rt(`${yn[a]} ${l}`)},400);return()=>clearInterval(i)},[_,e,tr]),_e(()=>()=>kn(0),[]),_e(()=>{if(p({kind:"banner",info:ud(e,o,t,s)}),!oe(e)){p({kind:"note",tone:"info",text:`Welcome! This repo isn't set up for d360-writer yet \u2014 three steps and you're writing docs:
179
+ ${Li}`}),X(["/init"]);return}try{let l=de(e,s),a=Ge(l.name);a&&Ne(a)&&a.refreshToken?Lu({profile:l.name,connection:l.connection}).then(()=>{p({kind:"note",tone:"ok",text:"\u2713 Document360 session refreshed."}),te(i=>i+1)}).catch(()=>{p({kind:"note",tone:"warn",text:"Document360 session refresh failed \u2014 do you want to log in now? (press 1)"}),X(["/login"])}):(!a||Ne(a))&&(p({kind:"note",tone:"warn",text:`Profile "${l.name}" is not signed in \u2014 do you want to log in now? (press 1)`}),X(["/login"]))}catch{}try{let l=oe(e),a=de(e,s),i=Ge(a.name);l&&i&&!Ne(i)&&gd(e,l.authoritativeSourceFiles)&&(p({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{}},[]),_e(()=>{let l=null,a=null,i=()=>{l&&clearTimeout(l),l=setTimeout(()=>{l=null;let h=`${ke.columns??80}x${ke.rows??24}`;h!==lr.current&&(lr.current=h,Ji(u=>u+1),a&&clearTimeout(a),a=setTimeout(()=>{a=null,console.log("\x1B[?2026h\x1B[H\x1B[2J"+Zr(Ke.current,je())+"\x1B[?2026l")},80))},400)};return ke.on("resize",i),()=>{l&&clearTimeout(l),a&&clearTimeout(a),ke.off("resize",i)}},[ke,je]);let Be=Math.max(20,(ke.columns??80)-1),cr=Go(()=>dd(e,s),[e,s,$e]),An=(()=>{let l=oe(e);if(!l)return{text:"Press 1 to set up this repo, or /help\u2026",isSetup:!0};let a=At(e,(l.docsDir??"user-docs").replace(/\/+$/,"")),i=(()=>{try{return zo(a)&&Hi(a).length>0}catch{return!1}})();try{let h=de(e,s),u=Ge(h.name);if(!(!!u&&!(Ne(u)&&!u.refreshToken)))return{text:`Press 1 to sign in to Document360 (profile "${h.name}")\u2026`,isSetup:!0};if(!h.project.workspaceId&&!i)return{text:"Press 1 to pick a workspace\u2026",isSetup:!0}}catch{}return i?{text:pd,isSetup:!1}:{text:"Let's get started \u2014 try: write the docs for this repo",isSetup:!1}})(),mt=Er(R),ur=mt.length>0&&!_,En=d!==null?Ri(d,8,Be):null,Ut=me?me.paths.filter(l=>!me.query||l.toLowerCase().includes(me.query.toLowerCase())).slice(0,8):[],Wt=he?he.sessions.filter(l=>{let a=he.query.toLowerCase();return!a||l.name.toLowerCase().includes(a)||l.firstPrompt.toLowerCase().includes(a)}).slice(0,8):[],ce=V((l,a)=>{pe.current?.close(),pe.current=Ei({cwd:e,resume:l,profileName:a??s,allowProdWrites:Je.current}),l||(xe.current={uuid:null,firstPrompt:null,titleFired:!1},Qe(null)),st(0),it(0)},[e,s]),dr=V((l,a,i)=>{if(fd.test(l))try{let h=de(e,s),u=typeof a.project_id=="string"&&a.project_id||h.project.projectId,m=hn(a,i),k=[],P=wn(i);l.endsWith("publish_article")&&P&&k.push(`Live: ${P}`),m&&u&&k.push(`Preview: ${gn(h.connection.portalUrl,u,m,h.project.languageCode??"en")}`),k.length>0&&p({kind:"link",lines:k})}catch{}},[e,s,p]),ve=V(async(l,a)=>{Et(!0),re(null),X([]),_t(null);let i=++ze.current;p({kind:"user",text:a?.echoDisplay&&a.display?a.display:l});let h=xe.current;h.firstPrompt||(h.firstPrompt=a?.display??l),Me.current=Date.now(),Ye(0),M(!0),Nt.current.clear();let u="",m="",k=null,P=()=>{k||(k=setTimeout(()=>{k=null,g(m.length>0?m:null)},60))},N=()=>{k&&clearTimeout(k),k=null,g(null)},j=()=>{if(m.trim()){let I=m.trimEnd();p({kind:"assistant",text:I})}m="",N()};try{for await(let I of pe.current.send(l))if(I.type==="session"){if(!h.uuid){h.uuid=I.sessionId;let O=new Date().toISOString(),T=qu(h.firstPrompt??"session");Gu({uuid:I.sessionId,name:T,renamed:!1,titled:!1,cwd:e,firstPrompt:h.firstPrompt??"",createdAt:O,updatedAt:O}),Qe(T)}}else if(I.type==="text"){m+=I.delta,u+=I.delta;let O=ji(m);if(O>0){let T=m.slice(0,O).trimEnd();T&&p({kind:"assistant",text:T}),m=m.slice(O)}P(),Ye(T=>T+I.delta.length)}else if(I.type==="tool"){let O=fn(I.name,I.input);O&&(j(),p({kind:"tool",title:O.title,sep:O.sep,arg:O.arg}),Nt.current.set(I.id,{name:I.name,input:I.input}))}else if(I.type==="article_diff"){let O=qe(I.oldContent,I.newContent,je());O&&(j(),p({kind:"diff",added:O.added,removed:O.removed,lines:O.lines,hidden:O.hidden}))}else if(I.type==="tool_result"){I.isError&&/run \/login|not logged in|session expired|rejected the token/i.test(I.output)&&(Ot.current=!0);let O=Nt.current.get(I.id);if(O){Nt.current.delete(I.id),j();let T=mn(I.output,4,I.isError?void 0:O.name,O.input);p({kind:"tool-result",lines:T.lines,hidden:T.hidden,isError:I.isError}),I.isError||dr(O.name,O.input,I.output)}}else if(I.type==="result"){j(),st(T=>T+I.outputTokens),it(T=>T+I.costUsd),p({kind:"done",seconds:Math.round((Date.now()-Me.current)/1e3),tokens:I.outputTokens,costUsd:I.costUsd,ok:I.ok});let O=I.ok?ki(u,yt.map(T=>T.name)):[];if(O.length>0?X(O):I.ok&&u.trim()&&Xu(l,u,e).then(T=>{T&&ze.current===i&&re(T)}).catch(()=>{}),h.uuid&&(Yo(h.uuid),!h.titleFired)){h.titleFired=!0;let T=h.uuid,D=h.firstPrompt;D&&Ii(D,e).then(W=>{W&&(Bu(T,W),Qe(W))}).catch(()=>{})}}else I.type==="error"&&(j(),I.kind==="auth"&&(Ot.current=!0),p({kind:"note",text:`agent error: ${I.message}`,tone:"error"}))}finally{M(!1),N(),te(I=>I+1),xe.current.uuid&&hi(e,xe.current.uuid,Ke.current),Ot.current&&(Ot.current=!1,Lt.current=a?.display??l,X(["/login"])),Mt.current&&(Mt.current=!1,Fe.current.length>0&&(p({kind:"note",tone:"info",text:`(${Fe.current.length} queued message(s) discarded)`}),Fe.current=[],jn([])),p({kind:"note",tone:"warn",text:"Interrupted. What do you want to do next?"}))}},[e,p,dr,je]),Ft=V(async l=>{let a=Xo(l),i=Cn(e,"standard");Me.current=Date.now(),Ye(0),M(!0);let h=new AbortController;ge.current=h,K({verb:"Publishing",total:a.length,done:0,active:[],rows:jt(a),tools:0,chars:0,lastAt:Date.now(),startedAt:Date.now()}),p({kind:"note",tone:"info",text:`Publishing ${l.length} article${l.length===1?"":"s"} across ${a.length} partition${a.length===1?"":"s"} (\u2264${vt} agents at once) on ${i.model}\u2026 (esc to stop)`});try{for await(let u of vn({cwd:e,partitions:a,promptFor:m=>nn(m.paths),concurrency:vt,profileName:s,allowProdWrites:Je.current,model:i.model,signal:h.signal}))if(u.type==="partition_status")u.status==="running"?K(m=>m&&{...m,active:[...m.active,u.label],rows:Pe(m.rows,u.label,"active"),lastAt:Date.now()}):K(m=>m&&{...m,active:m.active.filter(k=>k!==u.label),done:m.done+1,rows:Pe(m.rows,u.label,u.status==="done"?"done":"failed"),lastAt:Date.now()});else if(u.type==="partition_event")K(m=>{if(!m)return m;let k={...m,lastAt:Date.now()};return u.event.type==="tool"?k.tools=m.tools+1:u.event.type==="text"&&(k.chars=m.chars+u.event.delta.length),k});else if(u.type==="run_done"){it(P=>P+u.totalCostUsd),st(P=>P+u.results.reduce((N,j)=>N+j.outputTokens,0));let m=u.aborted?"Stopped. ":"",k=t.kind==="api"?"api":"subscription";p({kind:"note",tone:u.aborted?"warn":u.ok?"ok":"warn",text:m+eo(u.results,a,k).join(`
180
+ `)})}}catch(u){p({kind:"note",tone:"error",text:`Publish run failed: ${u.message}`})}finally{ge.current=null,K(null),M(!1),te(u=>u+1)}},[e,s,p,t]),In=V(async l=>{await ve(Zn(l),{display:`/publish ${l}`,echoDisplay:!0});try{let a=await on(e,s,l.replace(/\\/g,"/"));a.length>0&&(_t(`Related articles not yet published (${a.length}):`),X([`/publish --related ${l}`,...a.map(i=>`/publish ${i}`)]))}catch{}},[e,s,ve]),Nn=V(l=>{let a=Ge(l);if(!a||Ne(a)&&!a.refreshToken)return null;let i={...dt(a.idToken)??{},...dt(a.accessToken)??{}};return i.email??i.preferred_username??"signed in"},[]),_n=V((l,a)=>{if(a){let i=oe(e);i&&(i.defaultProfile=l,Ku(i,e))}c(l),ce(void 0,l),p({kind:"note",tone:"ok",text:`\u2713 Switched to profile "${l}"${a?" (saved as default)":" (this session only)"} \u2014 agent restarted.`}),Nn(l)||(p({kind:"note",tone:"warn",text:`Profile "${l}" is not signed in \u2014 do you want to log in now? (press 1)`}),X(["/login"])),te(i=>i+1)},[e,p,ce,Nn]),Ht=V((l,a,i)=>{zt(e,l,a,i.id,i.name),p({kind:"note",tone:"ok",text:`Switched to workspace "${i.name??i.id}" (agent restarted).`}),ce(),Ni(e,l)||(p({kind:"note",tone:"info",text:"Setup complete. Press tab to start with a docs analysis."}),re("analyze this repo and propose a docs structure"))},[e,p,ce]),Mn=V(async l=>{let a;try{a=await wt(e,l)}catch{p({kind:"note",tone:"info",text:"Next: pick a workspace \u2014 run /workspace."}),X(["/workspace"]);return}if(a.workspaces.length===0){p({kind:"note",tone:"warn",text:"This project has no workspaces yet. Create one in Document360, then run /workspace."});return}let i=a.workspaces.filter(u=>(u.workspace_type??"").toLowerCase()!=="apidocumentation"),h=i.length>0?i:a.workspaces;if(h.length===1){let u=h[0],m=a.workspaces.length-h.length;p({kind:"note",tone:"ok",text:`Selected the "${u.name??u.id}" workspace${m>0?" (skipped the API-documentation workspace)":""}.`}),Ht(a.profile,a.projectId,u);return}p({kind:"note",tone:"info",text:`Next: pick the workspace your articles publish to (${h.length} available).`}),X(["/workspace"])},[e,p,Ht]),pr=V((l,a)=>{To(e,l,a.id),p({kind:"note",tone:"ok",text:`Project set to "${a.name??a.id}" (agent restarted).`}),ce(),Mn(l)},[e,p,ce,Mn]),Bt=V(()=>{let l=Se.current[0];if(!l)return;p({kind:"note",tone:"info",text:`\u25CF ${l.title} (${l.path})`});for(let i of l.notes)p({kind:"note",tone:"warn",text:`\u26A0 ${i}`});l.overwritesLocalChanges&&p({kind:"note",tone:"warn",text:"\u26A0 This OVERWRITES local edits made since the last sync."});let a=qe(l.oldContent,l.newContent,je());p(a?{kind:"diff",added:a.added,removed:a.removed,lines:a.lines,hidden:a.hidden}:{kind:"note",tone:"info",text:"Local file already matches the remote content \u2014 applying only advances the sync base."}),p({kind:"note",tone:"info",text:`Write ${l.path}? (y/n \u2014 anything else cancels)`})},[p,je]),fr=V(l=>{if(Se.current.length===0)return!1;let a=l.trim().toLowerCase();if(a==="y"||a==="yes"){let i=Se.current.shift();try{Ju({cwd:e,profileName:s},i),p({kind:"note",tone:"ok",text:`\u2713 Pulled ${i.path} (sync base advanced).`}),Se.current.length===0&&X(h=>h.length>0?h:["/sync"])}catch(h){p({kind:"note",tone:"error",text:`Pull failed: ${h.message}`})}}else if(a==="n"||a==="no"){let i=Se.current.shift();p({kind:"note",tone:"info",text:`Skipped ${i.path}.`})}else{let i=Se.current.length;return Se.current=[],p({kind:"note",tone:"info",text:`Pull cancelled (${i} article(s) left untouched).`}),!0}return Bt(),!0},[e,s,Bt,p]),mr=V(l=>{let a=Rn.current;if(!a)return!1;if(Rn.current=null,re(null),ze.current++,l.trim()!==a.repoName)return p({kind:"note",tone:"warn",text:"Reset cancelled \u2014 nothing deleted."}),!0;let{removed:i,failed:h}=Mo(e,a.targets);p({kind:"note",tone:h.length?"warn":"ok",text:`\u2713 Reset complete \u2014 removed ${i.length} item${i.length===1?"":"s"}. The repo is back to its original state.`});for(let u of h)p({kind:"note",tone:"error",text:` \u2717 ${u.path}: ${u.error}`});return p({kind:"note",tone:"info",text:`Clean slate \u2014 set up d360-writer again whenever you're ready:
181
+ ${Li}`}),X(["/init"]),Et(!1),!0},[e,p]),gr=V(async l=>{let a=l.slice(1).trim().split(/\s+/),i=(a[0]??"").toLowerCase(),h=a.slice(1);switch(Et(!0),i){case"help":p({kind:"note",tone:"info",text:Zt().join(`
182
+ `)});return;case"exit":case"quit":pe.current?.close(),r();return;case"clear":ce(),Ke.current=[],Et(!1),re(null),ze.current++,p({kind:"note",tone:"info",text:"Conversation reset (the previous session is still resumable via /resume)."});return;case"login":{let u;try{u=de(e,s)}catch(m){p({kind:"note",tone:"error",text:m.message});return}p({kind:"note",tone:"info",text:`Profile "${u.name}" \u2192 ${u.connection.name} (${u.connection.apiUrl})${u.production?" \u26A0 PRODUCTION":""}`}),Z(!0);try{let m=await _u(u.connection,{promptForRedirect:()=>Promise.reject(new Error("Manual login is CLI-only. Run: d360-writer login --manual"))},N=>p({kind:"note",tone:"info",text:N})),k=Mu(u.name,m);Ou(k),Wn(k,u.name,N=>p({kind:"note",tone:"info",text:N})),p({kind:"note",tone:"ok",text:`\u2713 Logged in to "${u.name}" as ${Vt(k)}`});let P=(()=>{try{return de(e,s)}catch{return u}})();P.project.workspaceId||(P.project.projectId?await Mn(P.name):(p({kind:"note",tone:"info",text:"Next: pick the Document360 project."}),X(["/project"]))),Lt.current&&(re(Lt.current),Lt.current=null,p({kind:"note",tone:"info",text:"Press tab to re-send your last prompt."}))}catch(m){p({kind:"note",tone:"error",text:`Login failed: ${m.message}`})}finally{Z(!1),te(m=>m+1)}return}case"allow-prod":{let u=!1;try{u=de(e,s).production}catch{}if(!u){p({kind:"note",tone:"info",text:"Current profile is not production \u2014 writes are already allowed."});return}Je.current=!0,ce(),p({kind:"note",tone:"warn",text:"\u26A0 Production writes authorized for this session."});return}case"rename":{let u=xo(h.join(" ")),m=xe.current.uuid;if(!m){p({kind:"note",tone:"error",text:"Send a message first \u2014 sessions save once the agent replies."});return}if(!u){p({kind:"note",tone:"info",text:"Thinking of a name\u2026"});let k=xe.current.firstPrompt??"";Ii(k,e).then(P=>{P?(re(`/rename ${P}`),p({kind:"note",tone:"info",text:`Suggestion: "${P}" \u2014 press tab to accept, or type /rename <your name>.`})):p({kind:"note",tone:"info",text:"Usage: /rename <name>"})}).catch(()=>p({kind:"note",tone:"info",text:"Usage: /rename <name>"}));return}Vu(m,u),Qe(u),Rt(`${Ho} d360-writer \xB7 ${u}`),p({kind:"note",tone:"ok",text:`Session renamed to "${u}".`});return}case"profile":{let u=h[0],m=oe(e);if(!u){let k=Object.entries(m?.profiles??{});if(k.length===0){p({kind:"note",tone:"info",text:"No profiles. Run /init first."});return}let P=k.map(([I,O])=>({name:I,env:O.connection?.environment??"custom",prod:O.production===!0,who:Nn(I)})),N=s??m?.defaultProfile,j=Math.max(0,P.findIndex(I=>I.name===N));Ze({cursor:j,current:j,rows:P});return}if(u==="add"){let k=bo(e,h[1],h[2]);if(k){p({kind:"note",tone:"error",text:k});return}p({kind:"note",tone:"ok",text:`\u2713 Profile "${h[1]}" created (environment: ${h[2]??h[1]}).`}),_n(h[1],!1);return}if(!m?.profiles?.[u]){p({kind:"note",tone:"error",text:`Unknown profile "${u}". Create it: /profile add ${u} <environment>`});return}_n(u,!0);return}case"doctor":await Tt(h,{cwd:e});return;case"mcp":await tn(h);return;case"init":{if(oe(e)){p({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 u=ed().map(m=>({name:m,apiUrl:td(m).apiUrl}));et({cursor:0,rows:u});return}case"resume":{let u=h.join(" ").trim(),m=Yu(e).filter(N=>N.uuid!==xe.current.uuid);if(!u){if(!m.length){p({kind:"note",tone:"info",text:"No saved sessions for this repo yet."});return}He({query:"",cursor:0,sessions:m});return}let k=zu(e,u);if(!k){p({kind:"note",tone:"error",text:`No session matches "${u}".`});return}ce(k.uuid),xe.current={uuid:k.uuid,firstPrompt:k.firstPrompt,titleFired:!0},Qe(k.name),Yo(k.uuid),Ke.current=[];let P=Fo(e,k.uuid);for(let N of P)p(N);p({kind:"note",tone:"ok",text:P.length?`Resumed "${k.name}" \u2014 restored ${P.length} message(s); continue where you left off.`:`Resumed "${k.name}" (agent memory reconnected; no saved transcript to replay).`});return}case"workspace":{let u=h.join(" ").trim(),m;try{m=await wt(e,s)}catch(P){p({kind:"note",tone:"error",text:`Could not list workspaces: ${P.message}`});return}if(!u){let P=m.workspaces.map(j=>({id:j.id,name:j.name??j.id,type:j.workspace_type}));if(P.length===0){p({kind:"note",tone:"info",text:"No workspaces in this project."});return}let N=Math.max(0,P.findIndex(j=>j.id===m.current));tt({cursor:N,current:N,rows:P,profile:m.profile,projectId:m.projectId,environment:m.environment});return}let k=Un(m.workspaces,u);if(!k){p({kind:"note",tone:"error",text:`No workspace matches "${u}".`});return}Ht(m.profile,m.projectId,k);return}case"project":{let u=h.join(" ").trim(),m;try{m=await Po(e,s)}catch(P){p({kind:"note",tone:"error",text:`Could not list projects: ${P.message} (signed in? try /login)`});return}if(!u){let P=m.projects.map(j=>({id:j.id,name:j.name??j.id,sub:j.sub_domain}));if(P.length===0){p({kind:"note",tone:"info",text:"No projects found for this identity."});return}let N=P.findIndex(j=>j.id===m.current);nt({cursor:Math.max(0,N),current:N,rows:P,profile:m.profile,environment:m.environment});return}let k=Os(m.projects,u);if(!k){p({kind:"note",tone:"error",text:`No project matches "${u}". Available: ${m.projects.map(P=>P.name??P.id).join(", ")}`});return}pr(m.profile,k);return}case"logout":{let u;try{u=de(e,s).name}catch(k){p({kind:"note",tone:"error",text:k.message});return}let m=Fu(u);Hu(e,u),ce(),te(k=>k+1),p({kind:"note",tone:m?"ok":"info",text:m?`\u2713 Signed out of "${u}" and cleared its project/workspace selection.`:`Profile "${u}" was not signed in. Cleared any project/workspace selection.`}),p({kind:"note",tone:"info",text:"Run /login to sign in and pick a project."}),X(["/login"]);return}case"publish":{if(h[0]==="--related"&&h[1]){let m=await on(e,s,h[1].replace(/\\/g,"/"));if(m.length===0){p({kind:"note",tone:"ok",text:"\u2713 All related articles are already published."});return}await Ft(m);return}if(h[0]&&h[0]!=="--all"){await In(h[0]);return}let u=h[0]==="--all";p({kind:"note",tone:"info",text:"Checking what needs publishing\u2026"});try{let m=await Vo({cwd:e,profileName:s}),k=Ct(m.entries);if(k.length===0){p({kind:"note",tone:"ok",text:"\u2713 Nothing is ahead of Document360 \u2014 no publish candidates."});let P=m.counts["unknown-base"]??0;P>0&&p({kind:"note",tone:"info",text:`(${P} article(s) have no sync base yet \u2014 publish those by path if needed.)`});return}if(u){await Ft(k.map(P=>P.path));return}ot({cursor:0,rows:ts(k)})}catch(m){p({kind:"note",tone:"error",text:`Could not compute sync status: ${m.message}`}),p({kind:"note",tone:"info",text:"Publish a specific article: /publish <article-path>"})}return}case"preview":{let u=h.join(" ").trim();if(!u){let k=[];try{k=Object.keys(Ni(e,de(e,s).name)?.articles??{})}catch{}if(k.length===0){p({kind:"note",tone:"info",text:"No tracked articles to pick from yet. Usage: /preview <path-to.md | article-id>"});return}We({query:"",cursor:0,paths:k});return}let m=Nu(u)?u:At(e,u);if(zo(m)){try{p({kind:"preview",name:Dt(m),text:Wi(Di(m,"utf8"))})}catch(k){p({kind:"note",tone:"error",text:`Could not read ${m}: ${k.message}`})}return}if(md.test(u)){try{let k=de(e,s),P={profile:k.name,connection:k.connection},N=k.project.projectId??Uu(P),j=await Wu(P,N,u);p({kind:"preview",name:j.title??u,text:j.content??"*(article has no content)*"})}catch(k){p({kind:"note",tone:"error",text:`Could not fetch article: ${k.message}`})}return}p({kind:"note",tone:"error",text:`"${u}" is neither a file (relative to ${e}) nor an article id.`});return}case"model":{let u=h[0]?.trim();if(!u){let N=cn(Jo(e));Le({cursor:N,current:N});return}let{lines:m,changed:k,effective:P}=Pt(e,u);for(let N of m)p({kind:"note",tone:N.startsWith("\u26A0")?"warn":N.startsWith("\u2713")?"ok":"info",text:N});k&&(ar(N=>N+1),pe.current?.setModel(P));return}case"convert":{if(!oe(e)){p({kind:"note",tone:"error",text:"No d360-writer config here. Run /init first."});return}let{scope:u,run:m}=ro(h),k=rd(e,s);if(k.length===0){p({kind:"note",tone:"error",text:"No tracked articles in d360-category-map.json. Publish some first (/publish), then /convert."});return}let P=so(k,u);if(P.length===0){p({kind:"note",tone:"error",text:`No tracked articles under "${u}". (${k.length} are tracked overall.)`});return}let N=Xo(P),j=3,I=`/convert${u?` --scope ${u}`:""} --run`,O=Cn(e,"light");if(!m){let D=_i({files:io(e,P),op:"convert",model:O.model}),W=u?`Scope: ${u} (${P.length} of ${k.length} tracked)
145
183
  `:"",ne=`
146
- Model: ${L.model}${L.forced?" (forced)":" \u2014 mechanical work; /model to override"}`;p({kind:"note",tone:"info",text:W+lo(_,D,j).join(`
147
- `)+ne}),X([I]);return}Me.current=Date.now(),Ye(0),M(!0);let T=new AbortController;ge.current=T,K({verb:"Converting",total:_.length,done:0,active:[],rows:jt(_),tools:0,chars:0,lastAt:Date.now(),startedAt:Date.now()}),p({kind:"note",tone:"info",text:`Converting ${P.length} articles across ${_.length} partitions (\u2264${j} agents at once) on ${L.model}\u2026 (esc to stop)`});try{for await(let D of vn({cwd:e,partitions:_,promptFor:ao,concurrency:j,profileName:s,allowProdWrites:Je.current,model:L.model,signal:T.signal}))if(D.type==="partition_status")D.status==="running"?K(W=>W&&{...W,active:[...W.active,D.label],rows:Pe(W.rows,D.label,"active"),lastAt:Date.now()}):K(W=>W&&{...W,active:W.active.filter(ne=>ne!==D.label),done:W.done+1,rows:Pe(W.rows,D.label,D.status==="done"?"done":"failed"),lastAt:Date.now()});else if(D.type==="partition_event")K(W=>{if(!W)return W;let ne={...W,lastAt:Date.now()};return D.event.type==="tool"?ne.tools=W.tools+1:D.event.type==="text"&&(ne.chars=W.chars+D.event.delta.length),ne});else if(D.type==="run_done"){it(U=>U+D.totalCostUsd),st(U=>U+D.results.reduce((Y,se)=>Y+se.outputTokens,0));let W=D.aborted?"Stopped. ":"",ne=t.kind==="api"?"api":"subscription";p({kind:"note",tone:D.aborted?"warn":D.ok?"ok":"warn",text:W+co(D.results,_,ne).join(`
148
- `)})}}catch(D){p({kind:"note",tone:"error",text:`Convert run failed: ${D.message}`})}finally{ge.current=null,K(null),M(!1),te(D=>D+1)}return}case"write":{if(!oe(e)){p({kind:"note",tone:"error",text:"No d360-writer config here. Run /init first."});return}let u=Zu(e);if(u.length===0){p({kind:"note",tone:"error",text:"No docs plan found (.d360-writer/plan.json). Analyze the repo and propose a structure first \u2014 try: analyze this repo and propose a docs structure."});return}let{scope:m,path:k,run:P}=po(h),{docsDir:_,targets:j,reason:I}=wo(e,u,{scope:m,path:k});if(j.length===0){p({kind:"note",tone:"warn",text:I??"Nothing to write."});return}let L=Yo(j),T=5,D=Cn(e,"standard");if(!P&&!!!k){let U=Di({files:fo(e,u,j),op:"write",model:D.model}),Y=m?`Scope: ${m} (${j.length} pending)
184
+ Model: ${O.model}${O.forced?" (forced)":" \u2014 mechanical work; /model to override"}`;p({kind:"note",tone:"info",text:W+lo(N,D,j).join(`
185
+ `)+ne}),X([I]);return}Me.current=Date.now(),Ye(0),M(!0);let T=new AbortController;ge.current=T,K({verb:"Converting",total:N.length,done:0,active:[],rows:jt(N),tools:0,chars:0,lastAt:Date.now(),startedAt:Date.now()}),p({kind:"note",tone:"info",text:`Converting ${P.length} articles across ${N.length} partitions (\u2264${j} agents at once) on ${O.model}\u2026 (esc to stop)`});try{for await(let D of vn({cwd:e,partitions:N,promptFor:ao,concurrency:j,profileName:s,allowProdWrites:Je.current,model:O.model,signal:T.signal}))if(D.type==="partition_status")D.status==="running"?K(W=>W&&{...W,active:[...W.active,D.label],rows:Pe(W.rows,D.label,"active"),lastAt:Date.now()}):K(W=>W&&{...W,active:W.active.filter(ne=>ne!==D.label),done:W.done+1,rows:Pe(W.rows,D.label,D.status==="done"?"done":"failed"),lastAt:Date.now()});else if(D.type==="partition_event")K(W=>{if(!W)return W;let ne={...W,lastAt:Date.now()};return D.event.type==="tool"?ne.tools=W.tools+1:D.event.type==="text"&&(ne.chars=W.chars+D.event.delta.length),ne});else if(D.type==="run_done"){it(U=>U+D.totalCostUsd),st(U=>U+D.results.reduce((Y,se)=>Y+se.outputTokens,0));let W=D.aborted?"Stopped. ":"",ne=t.kind==="api"?"api":"subscription";p({kind:"note",tone:D.aborted?"warn":D.ok?"ok":"warn",text:W+co(D.results,N,ne).join(`
186
+ `)})}}catch(D){p({kind:"note",tone:"error",text:`Convert run failed: ${D.message}`})}finally{ge.current=null,K(null),M(!1),te(D=>D+1)}return}case"write":{if(!oe(e)){p({kind:"note",tone:"error",text:"No d360-writer config here. Run /init first."});return}let u=sd(e);if(u.length===0){p({kind:"note",tone:"error",text:"No docs plan found (.d360-writer/plan.json). Analyze the repo and propose a structure first \u2014 try: analyze this repo and propose a docs structure."});return}let{scope:m,path:k,run:P}=po(h),{docsDir:N,targets:j,reason:I}=wo(e,u,{scope:m,path:k});if(j.length===0){p({kind:"note",tone:"warn",text:I??"Nothing to write."});return}let O=Xo(j),T=5,D=Cn(e,"standard");if(!P&&!!!k){let U=_i({files:fo(e,u,j),op:"write",model:D.model}),Y=m?`Scope: ${m} (${j.length} pending)
149
187
  `:"",se=`
150
- Model: ${D.model}${D.forced?" (forced)":" \u2014 authoring; /model to override"}`;p({kind:"note",tone:"info",text:Y+go(L,U,T).join(`
151
- `)+se}),X([`/write${m?` --scope ${m}`:" --all"} --run`]);return}Me.current=Date.now(),Ye(0),M(!0);let ne=new AbortController;ge.current=ne,K({verb:"Writing",total:L.length,done:0,active:[],rows:jt(L),tools:0,chars:0,lastAt:Date.now(),startedAt:Date.now()}),p({kind:"note",tone:"info",text:`Writing ${j.length} article${j.length===1?"":"s"} across ${L.length} partition${L.length===1?"":"s"} (\u2264${T} agents at once) on ${D.model}${D.forced?" (forced)":""}\u2026 (esc to stop)`});try{for await(let U of vn({cwd:e,partitions:L,promptFor:Y=>mo(Y,_),concurrency:T,profileName:s,allowProdWrites:Je.current,model:D.model,signal:ne.signal}))if(U.type==="partition_status")U.status==="running"?K(Y=>Y&&{...Y,active:[...Y.active,U.label],rows:Pe(Y.rows,U.label,"active"),lastAt:Date.now()}):K(Y=>Y&&{...Y,active:Y.active.filter(se=>se!==U.label),done:Y.done+1,rows:Pe(Y.rows,U.label,U.status==="done"?"done":"failed"),lastAt:Date.now()});else if(U.type==="partition_event")K(Y=>{if(!Y)return Y;let se={...Y,lastAt:Date.now()};return U.event.type==="tool"?se.tools=Y.tools+1:U.event.type==="text"&&(se.chars=Y.chars+U.event.delta.length),se});else if(U.type==="run_done"){it(On=>On+U.totalCostUsd),st(On=>On+U.results.reduce((Yi,Vi)=>Yi+Vi.outputTokens,0));let Y=U.aborted?"Stopped. ":"",se=t.kind==="api"?"api":"subscription";p({kind:"note",tone:U.aborted?"warn":U.ok?"ok":"warn",text:Y+ho(U.results,L,se).join(`
188
+ Model: ${D.model}${D.forced?" (forced)":" \u2014 authoring; /model to override"}`;p({kind:"note",tone:"info",text:Y+go(O,U,T).join(`
189
+ `)+se}),X([`/write${m?` --scope ${m}`:" --all"} --run`]);return}Me.current=Date.now(),Ye(0),M(!0);let ne=new AbortController;ge.current=ne,K({verb:"Writing",total:O.length,done:0,active:[],rows:jt(O),tools:0,chars:0,lastAt:Date.now(),startedAt:Date.now()}),p({kind:"note",tone:"info",text:`Writing ${j.length} article${j.length===1?"":"s"} across ${O.length} partition${O.length===1?"":"s"} (\u2264${T} agents at once) on ${D.model}${D.forced?" (forced)":""}\u2026 (esc to stop)`});try{for await(let U of vn({cwd:e,partitions:O,promptFor:Y=>mo(Y,N),concurrency:T,profileName:s,allowProdWrites:Je.current,model:D.model,signal:ne.signal}))if(U.type==="partition_status")U.status==="running"?K(Y=>Y&&{...Y,active:[...Y.active,U.label],rows:Pe(Y.rows,U.label,"active"),lastAt:Date.now()}):K(Y=>Y&&{...Y,active:Y.active.filter(se=>se!==U.label),done:Y.done+1,rows:Pe(Y.rows,U.label,U.status==="done"?"done":"failed"),lastAt:Date.now()});else if(U.type==="partition_event")K(Y=>{if(!Y)return Y;let se={...Y,lastAt:Date.now()};return U.event.type==="tool"?se.tools=Y.tools+1:U.event.type==="text"&&(se.chars=Y.chars+U.event.delta.length),se});else if(U.type==="run_done"){it(Ln=>Ln+U.totalCostUsd),st(Ln=>Ln+U.results.reduce((ea,ta)=>ea+ta.outputTokens,0));let Y=U.aborted?"Stopped. ":"",se=t.kind==="api"?"api":"subscription";p({kind:"note",tone:U.aborted?"warn":U.ok?"ok":"warn",text:Y+ho(U.results,O,se).join(`
152
190
  `)}),!U.aborted&&U.ok&&X(["/publish --all","/screenshot --all"])}}catch(U){p({kind:"note",tone:"error",text:`Write run failed: ${U.message}`})}finally{ge.current=null,K(null),M(!1),te(U=>U+1)}return}case"draft":{if(!oe(e)){p({kind:"note",tone:"error",text:"No d360-writer config here. Run /init first."});return}let{features:u,looseDocs:m}=ko(e);if(u.length===0&&m===0){p({kind:"note",tone:"info",text:$o});return}let k=h.join(" ").trim();if(!k&&u.length>1){p({kind:"note",tone:"info",text:`Multiple features in .d360-writer/input/ \u2014 draft which one?
153
191
  ${u.map(j=>` \u2022 ${j.name} (${j.docCount} doc${j.docCount===1?"":"s"})`).join(`
154
- `)}`}),X(u.map(j=>`/draft ${j.name}`));return}let P="",_;if(k){let j=yo(u,k);j?P=j:_=k}else P=u[0]?.name??"";await ve(ln(P,_),{display:k?`/draft ${k}`:"/draft",echoDisplay:!0});return}case"sync":{let u=(h[0]??"status").toLowerCase();try{if(u==="status"){p({kind:"note",tone:"info",text:"Checking Document360 for drift\u2026"});let m=await zo({cwd:e,profileName:s});p({kind:"note",tone:"info",text:an(m).join(`
155
- `)});return}if(u==="pull"){let m=h[1];if(!m){p({kind:"note",tone:"error",text:"Usage: /sync pull <article-path> | --all"});return}let k;if(m==="--all"){if(p({kind:"note",tone:"info",text:"Checking Document360 for drift\u2026"}),k=(await zo({cwd:e,profileName:s})).entries.filter(j=>j.status==="remote-ahead"&&j.path).map(j=>j.path),k.length===0){p({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 k=[m.replace(/\\/g,"/")];let P=[];for(let _ of k)P.push(await zu({cwd:e,profileName:s,relPath:_}));Se.current=P,Bt();return}p({kind:"note",tone:"error",text:`Unknown subcommand: /sync ${u} \u2014 use /sync or /sync pull <path>|--all.`})}catch(m){p({kind:"note",tone:"error",text:`Sync failed: ${m.message}`})}return}case"scope":{if(!oe(e)){p({kind:"note",tone:"error",text:"No d360-writer config here. Run /init first."});return}let u=Yu(e);if(u.length===0){p({kind:"note",tone:"info",text:'No candidate source folders found. Set "authoritativeSourceFiles" in .d360-writer.json manually.'});return}rt({cursor:0,rows:u.map(m=>({...m,checked:m.recommended}))});return}case"audit":case"capture-setup":{let m=await(i==="audit"?rn:St)(h,void 0);if(m.kind==="forward-to-agent"&&m.prompt&&await ve(m.prompt,{display:m.display,echoDisplay:!0}),i==="capture-setup"){let k=Do(e);k&&p({kind:"note",tone:"info",text:k.join(`
156
- `)})}return}case"devhints":{if(!oe(e)){p({kind:"note",tone:"error",text:"No d360-writer config here. Run /init first."});return}ed(td(e)),Su(nd(e),Ao()),p({kind:"note",tone:"info",text:Eo().join(`
192
+ `)}`}),X(u.map(j=>`/draft ${j.name}`));return}let P="",N;if(k){let j=yo(u,k);j?P=j:N=k}else P=u[0]?.name??"";await ve(ln(P,N),{display:k?`/draft ${k}`:"/draft",echoDisplay:!0});return}case"sync":{let u=(h[0]??"status").toLowerCase();try{if(u==="status"){p({kind:"note",tone:"info",text:"Checking Document360 for drift\u2026"});let m=await Vo({cwd:e,profileName:s});p({kind:"note",tone:"info",text:an(m).join(`
193
+ `)});return}if(u==="pull"){let m=h[1];if(!m){p({kind:"note",tone:"error",text:"Usage: /sync pull <article-path> | --all"});return}let k;if(m==="--all"){if(p({kind:"note",tone:"info",text:"Checking Document360 for drift\u2026"}),k=(await Vo({cwd:e,profileName:s})).entries.filter(j=>j.status==="remote-ahead"&&j.path).map(j=>j.path),k.length===0){p({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 k=[m.replace(/\\/g,"/")];let P=[];for(let N of k)P.push(await Qu({cwd:e,profileName:s,relPath:N}));Se.current=P,Bt();return}p({kind:"note",tone:"error",text:`Unknown subcommand: /sync ${u} \u2014 use /sync or /sync pull <path>|--all.`})}catch(m){p({kind:"note",tone:"error",text:`Sync failed: ${m.message}`})}return}case"scope":{if(!oe(e)){p({kind:"note",tone:"error",text:"No d360-writer config here. Run /init first."});return}let u=Zu(e);if(u.length===0){p({kind:"note",tone:"info",text:'No candidate source folders found. Set "authoritativeSourceFiles" in .d360-writer.json manually.'});return}rt({cursor:0,rows:u.map(m=>({...m,checked:m.recommended}))});return}case"audit":case"capture-setup":{let m=await(i==="audit"?rn:St)(h,void 0);if(m.kind==="forward-to-agent"&&m.prompt&&await ve(m.prompt,{display:m.display,echoDisplay:!0}),i==="capture-setup"){let k=Do(e);k&&p({kind:"note",tone:"info",text:k.join(`
194
+ `)})}return}case"devhints":{if(!oe(e)){p({kind:"note",tone:"error",text:"No d360-writer config here. Run /init first."});return}Mi(id(e)),Mi(ad(e)),zo(Oi(e))||Ai(Oi(e),Eo()),Ai(ld(e),Ao()),p({kind:"note",tone:"info",text:Io().join(`
157
195
  `)});return}case"screenshot":{let u=So(h);if(u.mode==="list"){if(!oe(e)){p({kind:"note",tone:"error",text:"No d360-writer config here. Run /init first."});return}p({kind:"note",tone:"info",text:jo(Ro(e,u.scope),u.scope).join(`
158
- `)});return}if(u.mode==="single"){let T=await dn(h);T.kind==="forward-to-agent"&&T.prompt&&await ve(T.prompt,{display:T.display,echoDisplay:!0});return}if(!oe(e)){p({kind:"note",tone:"error",text:"No d360-writer config here. Run /init first."});return}let m=u.mode==="scope"?u.scope:void 0,k=Ju(e,{scope:m}).map(T=>T.id);if(k.length===0){p({kind:"note",tone:"info",text:m?`No screenshot placeholders under ${m}.`:"No screenshot placeholders found in the docs."});return}let P=6,_=Ku(k,3),j=Cn(e,"standard");Me.current=Date.now(),Ye(0),M(!0);let I=new AbortController;ge.current=I,K({verb:"Authoring",unit:"spec",total:_.length,done:0,active:[],rows:jt(_),tools:0,chars:0,lastAt:Date.now(),startedAt:Date.now()}),p({kind:"note",tone:"info",text:`Authoring ${k.length} screenshot spec${k.length===1?"":"s"} across ${_.length} partition${_.length===1?"":"s"} (\u2264${P} agents at once) on ${j.model}${j.forced?" (forced)":""}\u2026 (esc to stop)`});let L=!1;try{for await(let T of vn({cwd:e,partitions:_,promptFor:Bs,concurrency:P,profileName:s,allowProdWrites:Je.current,model:j.model,signal:I.signal}))if(T.type==="partition_status")T.status==="running"?K(D=>D&&{...D,active:[...D.active,T.label],rows:Pe(D.rows,T.label,"active"),lastAt:Date.now()}):K(D=>D&&{...D,active:D.active.filter(W=>W!==T.label),done:D.done+1,rows:Pe(D.rows,T.label,T.status==="done"?"done":"failed"),lastAt:Date.now()});else if(T.type==="partition_event")K(D=>{if(!D)return D;let W={...D,lastAt:Date.now()};return T.event.type==="tool"?W.tools=D.tools+1:T.event.type==="text"&&(W.chars=D.chars+T.event.delta.length),W});else if(T.type==="run_done"){it(U=>U+T.totalCostUsd),st(U=>U+T.results.reduce((Y,se)=>Y+se.outputTokens,0));let D=T.results.filter(U=>U.ok).length,W=T.aborted?"Stopped. ":"";L=!T.aborted&&u.setup;let ne=T.aborted?"":L?" Refreshing the capture-setup checklist\u2026":" Next: /capture-setup, then d360-capture capture.";p({kind:"note",tone:T.aborted?"warn":T.ok?"ok":"warn",text:`${W}Authored specs \u2014 ${D}/${T.results.length} batches ok.${ne}`})}}catch(T){p({kind:"note",tone:"error",text:`Spec authoring failed: ${T.message}`})}finally{ge.current=null,K(null),M(!1),te(T=>T+1)}if(L){let T=await St();T.kind==="forward-to-agent"&&T.prompt&&await ve(T.prompt,{display:T.display,echoDisplay:!0});let D=Do(e);D&&p({kind:"note",tone:"info",text:D.join(`
159
- `)})}return}case"reset":{let u=_o(e);if(u.length===0){p({kind:"note",tone:"info",text:"Nothing to reset \u2014 no d360-writer files found in this repo."});return}Rn.current={repoName:Dt(e),targets:u},p({kind:"note",tone:"warn",text:Mo(e,u).join(`
160
- `)}),re(Dt(e));return}default:p({kind:"note",tone:"error",text:`Unknown command: /${i} \u2014 type /help.`})}},[e,r,s,Bt,p,ce,ve,Ft,In]),qt=V(l=>{let a=(l??R).trim();if(y(""),It(null),Ve(0),a.startsWith("/")&&(re(null),ze.current++,Nt(null),X(h=>gi(h,a))),!a||pr(a)||dr(a))return;Sn.current.push(a);let i=yi(a,Qo.current);a.startsWith("/")?fr(i):ve(i,{display:a})},[R,pr,dr,fr,ve]),mr=V(l=>{if(l.length>1){if(l.includes("\x1B"))return;let a=hi(l);if(wi(a)){let i=ki(++Hi.current,a);Qo.current.set(i,a),b(i)}else b(a);return}b(l)},[b]),at=Math.max(10,Be-6),gr=qo(()=>xn(w.text,at),[w.text,at]),Ln=V(l=>$(a=>({...a,pos:Math.max(0,Math.min(a.text.length,a.pos+l))})),[]),Gt=V(l=>$(a=>({...a,pos:xi(xn(a.text,at),a.pos,l)})),[at]),gt=V(l=>$(a=>({...a,pos:bi(xn(a.text,at),a.pos,l)})),[at]),Gi=["\x1B[H","\x1B[1~","\x1BOH"],zi=["\x1B[F","\x1B[4~","\x1BOF"],hr=V((l,a)=>a.leftArrow?(Ln(-1),!0):a.rightArrow?(Ln(1),!0):l&&Gi.includes(l)?(gt("start"),!0):l&&zi.includes(l)?(gt("end"),!0):a.ctrl&&l==="a"?(gt("start"),!0):a.ctrl&&l==="e"?(gt("end"),!0):!1,[Ln,gt]);return Pu((l,a)=>{if(a.ctrl&&l==="c"){pe.current?.close(),r();return}if(!H){if(N){if(a.escape){if(ge.current){ge.current.signal.aborted||(p({kind:"note",tone:"warn",text:"\u238B Stopping the convert run (finishing in-flight articles)\u2026"}),ge.current.abort());return}Mt.current||(Mt.current=!0,p({kind:"note",tone:"warn",text:"\u238B Interrupting\u2026"}),pe.current?.interrupt());return}if(a.return){let i=R.trim();if(!i)return;Fe.current.push(i),jn([...Fe.current]),y("");return}if(hr(l,a))return;if(a.upArrow){Gt(-1);return}if(a.downArrow){Gt(1);return}if(a.backspace||a.delete){v();return}l&&!a.ctrl&&!a.meta&&mr(l);return}if(Le){if(a.upArrow){Oe(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(a.downArrow){Oe(i=>i&&{...i,cursor:Math.min(ye.length-1,i.cursor+1)});return}if(l&&/^[1-9]$/.test(l)&&Number(l)<=ye.length){Oe(i=>i&&{...i,cursor:Number(l)-1});return}if(a.return){let i=ye[Le.cursor];Oe(null);let{lines:h,changed:u,effective:m}=Pt(e,i.value??"default");for(let k of h)p({kind:"note",tone:k.startsWith("\u26A0")?"warn":k.startsWith("\u2713")?"ok":"info",text:k});u&&(sr(k=>k+1),pe.current?.setModel(m));return}if(l==="s"){let i=ye[Le.cursor];Oe(null),pe.current?.setModel(i.value??void 0),p({kind:"note",tone:"ok",text:`\u2713 Using ${i.label} for this session only (your saved default is unchanged).`});return}if(a.escape){Oe(null);return}return}if(be){if(a.upArrow){Ze(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(a.downArrow){Ze(i=>i&&{...i,cursor:Math.min(i.rows.length-1,i.cursor+1)});return}if(l&&/^[1-9]$/.test(l)&&Number(l)<=be.rows.length){Ze(i=>i&&{...i,cursor:Number(l)-1});return}if(a.return||l==="s"){let i=be.rows[be.cursor];Ze(null),Nn(i.name,a.return===!0);return}if(a.escape){Ze(null);return}return}if(Re){if(a.upArrow){et(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(a.downArrow){et(i=>i&&{...i,cursor:Math.min(i.rows.length-1,i.cursor+1)});return}if(l&&/^[1-9]$/.test(l)&&Number(l)<=Re.rows.length){et(i=>i&&{...i,cursor:Number(l)-1});return}if(a.return){let i=Re.rows[Re.cursor].name;if(et(null),!Ur(e,i).created){p({kind:"note",tone:"error",text:"Could not scaffold \u2014 .d360-writer.json already exists."});return}p({kind:"note",tone:"ok",text:`\u2713 Wrote .d360-writer.json (environment "${i}").`});let u=!1;try{let m=Ge(i);u=!!m&&!(_e(m)&&!m.refreshToken)}catch{}u?(p({kind:"note",tone:"info",text:`Already signed in to ${i} \u2014 next: pick a workspace.`}),X(["/workspace"])):(p({kind:"note",tone:"info",text:`Next: sign in to Document360 (${i}).`}),X(["/login"])),te(m=>m+1);return}if(a.escape){et(null);return}return}if(ae){if(a.upArrow){tt(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(a.downArrow){tt(i=>i&&{...i,cursor:Math.min(i.rows.length-1,i.cursor+1)});return}if(l&&/^[1-9]$/.test(l)&&Number(l)<=ae.rows.length){tt(i=>i&&{...i,cursor:Number(l)-1});return}if(a.return){let i=ae.rows[ae.cursor],{profile:h,projectId:u}=ae;tt(null),Ht(h,u,i);return}if(a.escape){tt(null);return}return}if(fe){if(a.upArrow){nt(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(a.downArrow){nt(i=>i&&{...i,cursor:Math.min(i.rows.length-1,i.cursor+1)});return}if(l&&/^[1-9]$/.test(l)&&Number(l)<=fe.rows.length){nt(i=>i&&{...i,cursor:Number(l)-1});return}if(a.return){let i=fe.rows[fe.cursor],{profile:h}=fe;nt(null),ur(h,i);return}if(a.escape){nt(null);return}return}if(le){if(a.upArrow){rt(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(a.downArrow){rt(i=>i&&{...i,cursor:Math.min(i.rows.length-1,i.cursor+1)});return}if(l===" "){rt(i=>i&&{...i,rows:i.rows.map((h,u)=>u===i.cursor?{...h,checked:!h.checked}:h)});return}if(a.return){let i=le.rows.filter(h=>h.checked).map(h=>h.path);if(rt(null),i.length===0){p({kind:"note",tone:"info",text:"Nothing selected \u2014 scope unchanged."});return}to(e,i),p({kind:"note",tone:"ok",text:`\u2713 Scoped to ${i.length} folder(s) \u2014 written to .d360-writer.json`});for(let h of i)p({kind:"note",tone:"info",text:` ${h}`});p({kind:"note",tone:"info",text:"Next: ask me to analyze these folders and propose a docs structure."});return}if(a.escape){rt(null);return}return}if(Ue){if(a.upArrow){ot(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(a.downArrow){ot(i=>i&&{...i,cursor:Math.min(i.rows.length-1,i.cursor+1)});return}if(l&&/^[1-9]$/.test(l)&&Number(l)<=Ue.rows.length){ot(i=>i&&{...i,cursor:Number(l)-1});return}if(a.return){let i=Ue.rows[Ue.cursor];ot(null),i.kind==="article"?In(i.paths[0]):Ft(i.paths);return}if(a.escape){ot(null);return}return}if(me){if(a.escape){We(null);return}if(a.upArrow){We(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(a.downArrow){We(i=>i&&{...i,cursor:Math.min(Math.max(0,Ut.length-1),i.cursor+1)});return}if(a.return){let i=Ut[me.cursor];if(i){We(null);try{p({kind:"preview",name:Dt(i),text:Ii(Ti(At(e,i),"utf8"))})}catch(h){p({kind:"note",tone:"error",text:`Could not read ${i}: ${h.message}`})}}return}if(a.backspace||a.delete){We(i=>i&&{...i,query:i.query.slice(0,-1),cursor:0});return}if(l&&!a.ctrl&&!a.meta&&l.length===1){We(i=>i&&{...i,query:i.query+l,cursor:0});return}return}if(he){if(a.escape){He(null);return}if(a.upArrow){He(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(a.downArrow){He(i=>i&&{...i,cursor:Math.min(Math.max(0,Wt.length-1),i.cursor+1)});return}if(a.return){let i=Wt[he.cursor];if(i){He(null),ce(i.uuid),xe.current={uuid:i.uuid,firstPrompt:i.firstPrompt,titleFired:!0},Qe(i.name),Go(i.uuid),Ke.current=[];let h=Wo(e,i.uuid);for(let u of h)p(u);p({kind:"note",tone:"ok",text:h.length?`Resumed "${i.name}" \u2014 restored ${h.length} message(s); continue where you left off.`:`Resumed "${i.name}" (agent memory reconnected; no saved transcript to replay).`})}return}if(a.backspace||a.delete){He(i=>i&&{...i,query:i.query.slice(0,-1),cursor:0});return}if(l&&!a.ctrl&&!a.meta&&l.length===1){He(i=>i&&{...i,query:i.query+l,cursor:0});return}return}if(a.tab&&!R&&we){y(we),re(null),ze.current++;return}if(!R&&pt.length>0&&l&&/^[1-9]$/.test(l)){let i=pt[Number(l)-1];if(i){y(i);return}}if(!hr(l,a)){if(lr){if(a.upArrow){Ve(i=>Math.max(0,i-1));return}if(a.downArrow){Ve(i=>Math.min(mt.length-1,i+1));return}if(a.tab){y("/"+(mt[ft]?.name??"")+" "),Ve(0);return}if(a.return){let i=mt[ft];if(i){let h=R.trim().slice(1).split(/\s+/).slice(1).join(" ");if(Ar(i.usage)&&!h){y("/"+i.name+" "),Ve(0);return}qt("/"+i.name+(h?" "+h:""));return}}}else{if(a.upArrow){if(R!==""&&Xe===null){Gt(-1);return}let i=Sn.current;if(!i.length)return;let h=Xe===null?i.length-1:Math.max(0,Xe-1);It(h),y(i[h]??"");return}if(a.downArrow){if(R!==""&&Xe===null){Gt(1);return}let i=Sn.current;if(Xe===null)return;let h=Xe+1;h>=i.length?(It(null),y("")):(It(h),y(i[h]??""));return}}if(a.return){qt();return}if(a.backspace||a.delete){v();return}if(a.escape){y(""),Ve(0),re(null),X([]),Nt(null);return}l&&!a.ctrl&&!a.meta&&mr(l)}}}),Ne(()=>{if(N||H)return;let l=Fe.current.shift();l!==void 0&&(jn([...Fe.current]),qt(l))},[N,H,qt]),F(J,{flexDirection:"column",width:Be,children:[En!==null&&F(J,{marginTop:1,flexDirection:"column",children:[En.truncated&&S(C,{dimColor:!0,children:"\u2026"}),S(C,{children:En.text})]}),N&&(nr?S(pd,{p:nr}):S(ud,{startTime:Me.current,chars:Fi})),S(J,{borderStyle:"round",borderColor:ar.prod?"yellow":G,borderTop:!0,borderBottom:!0,borderLeft:!1,borderRight:!1,marginTop:1,flexDirection:"column",children:R?gr.map((l,a)=>{let i=w.text.slice(l.start,l.end),h=a===bn(gr,w.pos),u=Math.min(w.pos,l.end)-l.start;return F(C,{children:[S(C,{color:G,children:a===0?"> ":" "}),h?F(Vo,{children:[i.slice(0,u),S(Pn,{ch:i[u]??" "}),i.slice(u+1)]}):i||" "]},`${a}-${l.start}`)}):F(C,{children:[S(C,{color:G,children:"> "}),we&&!N?F(Vo,{children:[S(Pn,{ch:we[0],dim:!0}),S(C,{color:"gray",children:we.slice(1)}),S(C,{dimColor:!0,children:" (tab)"})]}):An.isSetup||!Wi?F(Vo,{children:[S(Pn,{ch:An.text[0],dim:!0}),S(C,{color:"gray",children:An.text.slice(1)})]}):S(Pn,{ch:" "})]})}),tr.length>0&&S(J,{flexDirection:"column",paddingX:1,children:tr.map((l,a)=>S(C,{color:"gray",children:`\u29D7 queued: ${l}`},`${a}-${l.slice(0,24)}`))}),Le?F(J,{flexDirection:"column",paddingX:1,children:[S(C,{color:G,bold:!0,children:"Select model"}),S(C,{color:"gray",children:"Your pick becomes your personal default for new sessions (team .d360-writer.json still wins)."}),ye.map((l,a)=>F(C,{color:a===Le.cursor?G:void 0,children:[a===Le.cursor?"\u276F ":" ",`${a+1}. ${l.label}${a===Le.current?" \u2714":""}`.padEnd(16),S(C,{color:"gray",children:l.desc})]},l.label)),S(C,{dimColor:!0,children:"enter set as default \xB7 s this session only \xB7 esc cancel"})]}):be?F(J,{flexDirection:"column",paddingX:1,children:[S(C,{color:G,bold:!0,children:"Switch connection profile"}),be.rows.map((l,a)=>F(C,{color:a===be.cursor?G:void 0,children:[a===be.cursor?"\u276F ":" ",`${a+1}. ${l.name}${a===be.current?" \u2714":""}`.padEnd(20),S(C,{color:"gray",children:`${l.env} \xB7 ${l.who??"not signed in"}`}),l.prod?S(C,{color:"yellow",bold:!0,children:" \u26A0 PRODUCTION"}):null]},l.name)),S(C,{dimColor:!0,children:"enter switch (saved as default) \xB7 s this session only \xB7 esc cancel"})]}):Re?F(J,{flexDirection:"column",paddingX:1,children:[S(C,{color:G,bold:!0,children:"Pick your Document360 environment"}),Re.rows.map((l,a)=>F(C,{color:a===Re.cursor?G:void 0,children:[a===Re.cursor?"\u276F ":" ",`${a+1}. ${l.name}`.padEnd(16),S(C,{color:"gray",children:l.apiUrl})]},l.name)),S(C,{dimColor:!0,children:"enter select \xB7 esc cancel"})]}):ae?F(J,{flexDirection:"column",paddingX:1,children:[S(C,{color:G,bold:!0,children:"Switch workspace"}),S(C,{dimColor:!0,children:`environment ${ae.environment} \xB7 project ${ae.projectId.slice(0,8)}\u2026`}),ae.rows.map((l,a)=>F(C,{color:a===ae.cursor?G:void 0,children:[a===ae.cursor?"\u276F ":" ",`${a+1}. ${l.name}${a===ae.current?" \u2714":""}`.padEnd(30),S(C,{color:"gray",children:l.type??""})]},l.id)),S(C,{dimColor:!0,children:"enter switch \xB7 esc cancel"})]}):fe?F(J,{flexDirection:"column",paddingX:1,children:[S(C,{color:G,bold:!0,children:"Choose project"}),S(C,{dimColor:!0,children:`environment ${fe.environment}`}),fe.rows.map((l,a)=>F(C,{color:a===fe.cursor?G:void 0,children:[a===fe.cursor?"\u276F ":" ",`${a+1}. ${l.name}${a===fe.current?" \u2714":""}`.padEnd(30),S(C,{color:"gray",children:l.sub??""})]},l.id)),S(C,{dimColor:!0,children:"enter select \xB7 esc cancel"})]}):le?(()=>{let a=Math.min(Math.max(0,le.cursor-Math.floor(7)),Math.max(0,le.rows.length-14)),i=le.rows.slice(a,a+14),h=le.rows.filter(u=>u.checked).length;return F(J,{flexDirection:"column",paddingX:1,children:[S(C,{color:G,bold:!0,children:`Which folders back the user docs? (${h} selected of ${le.rows.length})`}),a>0?S(C,{dimColor:!0,children:` \u2191 ${a} more`}):null,i.map((u,m)=>{let k=a+m;return F(C,{color:k===le.cursor?G:void 0,children:[k===le.cursor?"\u276F ":" ",u.checked?"\u25C9 ":"\u25CB ",u.path.padEnd(Math.min(48,Be-34)),S(C,{color:"gray",children:sn(u)})]},u.path)}),a+14<le.rows.length?S(C,{dimColor:!0,children:` \u2193 ${le.rows.length-a-14} more`}):null,S(C,{dimColor:!0,children:"space toggle \xB7 enter save \xB7 esc cancel"})]})})():Ue?F(J,{flexDirection:"column",paddingX:1,children:[S(C,{color:G,bold:!0,children:"Publish to Document360 \u2014 pick a category (whole) or an article:"}),Ue.rows.map((l,a)=>{let i=a===Ue.cursor,h=l.indent?" ":" ",u=`${a+1}.`.padEnd(3);return F(C,{color:i?G:void 0,bold:l.kind==="category"&&!i,children:[i?"\u276F ":" ",`${h}${u} ${l.label}`.padEnd(Math.min(56,Be-24)),l.note?S(C,{color:"gray",children:l.note}):null]},`${l.kind}:${l.paths.join(",")}`)}),S(C,{dimColor:!0,children:"\u2191\u2193 move \xB7 1-9 jump \xB7 enter publish (draft) \xB7 esc cancel"})]}):me?F(J,{flexDirection:"column",paddingX:1,children:[S(C,{color:G,bold:!0,children:`Preview article${me.query?` \u2014 filter: ${me.query}`:" (type to filter)"}`}),Ut.length===0?S(C,{color:"gray",children:"no articles match"}):Ut.map((l,a)=>F(C,{color:a===me.cursor?G:void 0,children:[a===me.cursor?"\u276F ":" ",l]},l)),S(C,{dimColor:!0,children:"enter preview \xB7 esc cancel"})]}):he?F(J,{flexDirection:"column",paddingX:1,children:[S(C,{color:G,bold:!0,children:`Resume session${he.query?` \u2014 filter: ${he.query}`:" (type to filter)"}`}),Wt.length===0?S(C,{color:"gray",children:"no sessions match"}):Wt.map((l,a)=>F(C,{color:a===he.cursor?G:void 0,children:[a===he.cursor?"\u276F ":" ",l.name.slice(0,28).padEnd(30),S(C,{color:a===he.cursor?G:"gray",children:l.firstPrompt.slice(0,Math.max(10,Be-40))})]},l.uuid)),S(C,{dimColor:!0,children:"enter resume \xB7 esc cancel"})]}):lr?S(J,{flexDirection:"column",children:mt.map((l,a)=>F(C,{color:a===ft?G:void 0,children:[a===ft?"\u276F ":" ",l.usage.padEnd(22)," ",S(C,{color:a===ft?G:"gray",children:l.name==="model"&&Dn?`${l.desc} (currently ${Dn})`:l.desc})]},l.name))}):!R&&pt.length>0?F(J,{flexDirection:"column",paddingX:1,children:[er?S(C,{color:G,children:er}):null,pt.map((l,a)=>F(C,{children:[S(C,{color:G,children:a+1})," ",l.slice(0,Math.max(20,Be-5))]},l)),S(C,{dimColor:!0,children:`press 1-${pt.length} to fill the command \xB7 esc dismiss`})]}):S(J,{paddingX:1,children:F(C,{color:"gray",children:[ar.prod?"\u26A0 PRODUCTION \xB7 ":"",`/help \xB7 ${Dn??"model n/a"}${t.kind==="api"?rr>0?` \xB7 ${ie(rr)}`:"":or>0?` \xB7 ${Ee(or)}`:""} \xB7 \u2191 history \xB7 ctrl+c exit`]})})]})}q();import{jsx as gd}from"react/jsx-runtime";async function Li(e=process.cwd(),t="auto",n,o="0.0.0"){let r=md(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 ${E("https://console.anthropic.com/settings/keys")}`),console.error(`Or use your Claude subscription instead: ${E("d360-writer --auth subscription")}`),process.exit(2));let{waitUntilExit:s}=fd(gd(Mi,{cwd:e,auth:r,profileName:n,version:o}));await s(),process.stdout.write(`
161
- `),process.exit(0)}var yd=wd(import.meta.url),Oi=yd("../package.json"),Te=new hd;function Ko(e){e.env&&(console.error("\u2717 --env was replaced by --profile (connection profiles). Use: --profile <name>"),process.exit(2))}Te.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=>{Ko(e),await Xt({profile:e.profile,manual:e.manual})});Te.command("logout").description("Remove the stored Document360 session").option("--profile <name>","Connection profile").option("--env <name>",!1).action(async e=>{Ko(e),await Tr({profile:e.profile})});Te.command("whoami").description("Show the current Document360 identity (refreshes if expired)").option("--profile <name>","Connection profile").option("--env <name>",!1).action(async e=>{Ko(e),await Pr({profile:e.profile})});var Jo=Te.command("profile").description("Manage connection profiles for the current repo");Jo.command("list",{isDefault:!0}).description("List profiles (\u25CF = default)").action(()=>Kt(process.cwd()));Jo.command("use <name>").description("Set the default profile for this repo").action(e=>Jt(process.cwd(),e));Jo.command("show [name]").description("Print the resolved profile (connection + project)").action(e=>Qt(process.cwd(),e));var Ui=Te.command("workspace").description("Choose the Document360 workspace for this repo (active profile's project)");Ui.command("select",{isDefault:!0}).description("Interactively pick the workspace (lists in non-TTY)").option("--profile <name>","Connection profile").action(e=>lt(process.cwd(),e.profile));Ui.command("use <name>").description("Set the workspace by name (scriptable)").option("--profile <name>","Connection profile").action(async(e,t)=>{process.exitCode=await $r(process.cwd(),e,t.profile)});Te.command("logs").description("Show the Document360 API log files (send these to support when reporting a problem)").action(()=>Rr());Te.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(()=>(un(),Es)),n=await t(process.cwd());for(let o of e(n))console.log(o);process.exitCode=n.some(o=>o.level==="fail")?1:0});Te.name("d360-writer").description("Standalone documentation agent CLI. Reads your code, writes your docs.").version(Oi.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(kd.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 jr(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 ai(e.cwd,e.auth,e.profile):await Li(e.cwd,e.auth,e.profile,Oi.version)});Te.parseAsync(process.argv).catch(e=>{console.error(""),console.error(`\u2717 ${e.message}`),process.exit(1)});
196
+ `)});return}if(u.mode==="single"){let T=await dn(h);T.kind==="forward-to-agent"&&T.prompt&&await ve(T.prompt,{display:T.display,echoDisplay:!0});return}if(!oe(e)){p({kind:"note",tone:"error",text:"No d360-writer config here. Run /init first."});return}let m=u.mode==="scope"?u.scope:void 0,k=od(e,{scope:m}).map(T=>T.id);if(k.length===0){p({kind:"note",tone:"info",text:m?`No screenshot placeholders under ${m}.`:"No screenshot placeholders found in the docs."});return}let P=6,N=nd(k,3),j=Cn(e,"standard");Me.current=Date.now(),Ye(0),M(!0);let I=new AbortController;ge.current=I,K({verb:"Authoring",unit:"spec",total:N.length,done:0,active:[],rows:jt(N),tools:0,chars:0,lastAt:Date.now(),startedAt:Date.now()}),p({kind:"note",tone:"info",text:`Authoring ${k.length} screenshot spec${k.length===1?"":"s"} across ${N.length} partition${N.length===1?"":"s"} (\u2264${P} agents at once) on ${j.model}${j.forced?" (forced)":""}\u2026 (esc to stop)`});let O=!1;try{for await(let T of vn({cwd:e,partitions:N,promptFor:Gs,concurrency:P,profileName:s,allowProdWrites:Je.current,model:j.model,signal:I.signal}))if(T.type==="partition_status")T.status==="running"?K(D=>D&&{...D,active:[...D.active,T.label],rows:Pe(D.rows,T.label,"active"),lastAt:Date.now()}):K(D=>D&&{...D,active:D.active.filter(W=>W!==T.label),done:D.done+1,rows:Pe(D.rows,T.label,T.status==="done"?"done":"failed"),lastAt:Date.now()});else if(T.type==="partition_event")K(D=>{if(!D)return D;let W={...D,lastAt:Date.now()};return T.event.type==="tool"?W.tools=D.tools+1:T.event.type==="text"&&(W.chars=D.chars+T.event.delta.length),W});else if(T.type==="run_done"){it(U=>U+T.totalCostUsd),st(U=>U+T.results.reduce((Y,se)=>Y+se.outputTokens,0));let D=T.results.filter(U=>U.ok).length,W=T.aborted?"Stopped. ":"";O=!T.aborted&&u.setup;let ne=T.aborted?"":O?" Refreshing the capture-setup checklist\u2026":" Next: /capture-setup, then d360-capture capture.";p({kind:"note",tone:T.aborted?"warn":T.ok?"ok":"warn",text:`${W}Authored specs \u2014 ${D}/${T.results.length} batches ok.${ne}`})}}catch(T){p({kind:"note",tone:"error",text:`Spec authoring failed: ${T.message}`})}finally{ge.current=null,K(null),M(!1),te(T=>T+1)}if(O){let T=await St();T.kind==="forward-to-agent"&&T.prompt&&await ve(T.prompt,{display:T.display,echoDisplay:!0});let D=Do(e);D&&p({kind:"note",tone:"info",text:D.join(`
197
+ `)})}return}case"reset":{let u=_o(e);if(u.length===0){p({kind:"note",tone:"info",text:"Nothing to reset \u2014 no d360-writer files found in this repo."});return}Rn.current={repoName:Dt(e),targets:u},p({kind:"note",tone:"warn",text:Oo(e,u).join(`
198
+ `)}),re(Dt(e));return}default:p({kind:"note",tone:"error",text:`Unknown command: /${i} \u2014 type /help.`})}},[e,r,s,Bt,p,ce,ve,Ft,In]),qt=V(l=>{let a=(l??R).trim();if(y(""),It(null),Ve(0),a.startsWith("/")&&(re(null),ze.current++,_t(null),X(h=>$i(h,a))),!a||mr(a)||fr(a))return;Sn.current.push(a);let i=Ci(a,er.current);a.startsWith("/")?gr(i):ve(i,{display:a})},[R,mr,fr,gr,ve]),hr=V(l=>{if(l.length>1){if(l.includes("\x1B"))return;let a=xi(l);if(bi(a)){let i=vi(++Xi.current,a);er.current.set(i,a),b(i)}else b(a);return}b(l)},[b]),at=Math.max(10,Be-6),wr=Go(()=>xn(w.text,at),[w.text,at]),On=V(l=>$(a=>({...a,pos:Math.max(0,Math.min(a.text.length,a.pos+l))})),[]),Gt=V(l=>$(a=>({...a,pos:Ti(xn(a.text,at),a.pos,l)})),[at]),gt=V(l=>$(a=>({...a,pos:Si(xn(a.text,at),a.pos,l)})),[at]),Qi=["\x1B[H","\x1B[1~","\x1BOH"],Zi=["\x1B[F","\x1B[4~","\x1BOF"],kr=V((l,a)=>a.leftArrow?(On(-1),!0):a.rightArrow?(On(1),!0):l&&Qi.includes(l)?(gt("start"),!0):l&&Zi.includes(l)?(gt("end"),!0):a.ctrl&&l==="a"?(gt("start"),!0):a.ctrl&&l==="e"?(gt("end"),!0):!1,[On,gt]);return Eu((l,a)=>{if(a.ctrl&&l==="c"){pe.current?.close(),r();return}if(!H){if(_){if(a.escape){if(ge.current){ge.current.signal.aborted||(p({kind:"note",tone:"warn",text:"\u238B Stopping the convert run (finishing in-flight articles)\u2026"}),ge.current.abort());return}Mt.current||(Mt.current=!0,p({kind:"note",tone:"warn",text:"\u238B Interrupting\u2026"}),pe.current?.interrupt());return}if(a.return){let i=R.trim();if(!i)return;Fe.current.push(i),jn([...Fe.current]),y("");return}if(kr(l,a))return;if(a.upArrow){Gt(-1);return}if(a.downArrow){Gt(1);return}if(a.backspace||a.delete){v();return}l&&!a.ctrl&&!a.meta&&hr(l);return}if(Oe){if(a.upArrow){Le(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(a.downArrow){Le(i=>i&&{...i,cursor:Math.min(ye.length-1,i.cursor+1)});return}if(l&&/^[1-9]$/.test(l)&&Number(l)<=ye.length){Le(i=>i&&{...i,cursor:Number(l)-1});return}if(a.return){let i=ye[Oe.cursor];Le(null);let{lines:h,changed:u,effective:m}=Pt(e,i.value??"default");for(let k of h)p({kind:"note",tone:k.startsWith("\u26A0")?"warn":k.startsWith("\u2713")?"ok":"info",text:k});u&&(ar(k=>k+1),pe.current?.setModel(m));return}if(l==="s"){let i=ye[Oe.cursor];Le(null),pe.current?.setModel(i.value??void 0),p({kind:"note",tone:"ok",text:`\u2713 Using ${i.label} for this session only (your saved default is unchanged).`});return}if(a.escape){Le(null);return}return}if(be){if(a.upArrow){Ze(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(a.downArrow){Ze(i=>i&&{...i,cursor:Math.min(i.rows.length-1,i.cursor+1)});return}if(l&&/^[1-9]$/.test(l)&&Number(l)<=be.rows.length){Ze(i=>i&&{...i,cursor:Number(l)-1});return}if(a.return||l==="s"){let i=be.rows[be.cursor];Ze(null),_n(i.name,a.return===!0);return}if(a.escape){Ze(null);return}return}if(Re){if(a.upArrow){et(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(a.downArrow){et(i=>i&&{...i,cursor:Math.min(i.rows.length-1,i.cursor+1)});return}if(l&&/^[1-9]$/.test(l)&&Number(l)<=Re.rows.length){et(i=>i&&{...i,cursor:Number(l)-1});return}if(a.return){let i=Re.rows[Re.cursor].name;if(et(null),!Fr(e,i).created){p({kind:"note",tone:"error",text:"Could not scaffold \u2014 .d360-writer.json already exists."});return}p({kind:"note",tone:"ok",text:`\u2713 Wrote .d360-writer.json (environment "${i}").`});let u=!1;try{let m=Ge(i);u=!!m&&!(Ne(m)&&!m.refreshToken)}catch{}u?(p({kind:"note",tone:"info",text:`Already signed in to ${i} \u2014 next: pick a workspace.`}),X(["/workspace"])):(p({kind:"note",tone:"info",text:`Next: sign in to Document360 (${i}).`}),X(["/login"])),te(m=>m+1);return}if(a.escape){et(null);return}return}if(ae){if(a.upArrow){tt(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(a.downArrow){tt(i=>i&&{...i,cursor:Math.min(i.rows.length-1,i.cursor+1)});return}if(l&&/^[1-9]$/.test(l)&&Number(l)<=ae.rows.length){tt(i=>i&&{...i,cursor:Number(l)-1});return}if(a.return){let i=ae.rows[ae.cursor],{profile:h,projectId:u}=ae;tt(null),Ht(h,u,i);return}if(a.escape){tt(null);return}return}if(fe){if(a.upArrow){nt(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(a.downArrow){nt(i=>i&&{...i,cursor:Math.min(i.rows.length-1,i.cursor+1)});return}if(l&&/^[1-9]$/.test(l)&&Number(l)<=fe.rows.length){nt(i=>i&&{...i,cursor:Number(l)-1});return}if(a.return){let i=fe.rows[fe.cursor],{profile:h}=fe;nt(null),pr(h,i);return}if(a.escape){nt(null);return}return}if(le){if(a.upArrow){rt(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(a.downArrow){rt(i=>i&&{...i,cursor:Math.min(i.rows.length-1,i.cursor+1)});return}if(l===" "){rt(i=>i&&{...i,rows:i.rows.map((h,u)=>u===i.cursor?{...h,checked:!h.checked}:h)});return}if(a.return){let i=le.rows.filter(h=>h.checked).map(h=>h.path);if(rt(null),i.length===0){p({kind:"note",tone:"info",text:"Nothing selected \u2014 scope unchanged."});return}to(e,i),p({kind:"note",tone:"ok",text:`\u2713 Scoped to ${i.length} folder(s) \u2014 written to .d360-writer.json`});for(let h of i)p({kind:"note",tone:"info",text:` ${h}`});p({kind:"note",tone:"info",text:"Next: ask me to analyze these folders and propose a docs structure."});return}if(a.escape){rt(null);return}return}if(Ue){if(a.upArrow){ot(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(a.downArrow){ot(i=>i&&{...i,cursor:Math.min(i.rows.length-1,i.cursor+1)});return}if(l&&/^[1-9]$/.test(l)&&Number(l)<=Ue.rows.length){ot(i=>i&&{...i,cursor:Number(l)-1});return}if(a.return){let i=Ue.rows[Ue.cursor];ot(null),i.kind==="article"?In(i.paths[0]):Ft(i.paths);return}if(a.escape){ot(null);return}return}if(me){if(a.escape){We(null);return}if(a.upArrow){We(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(a.downArrow){We(i=>i&&{...i,cursor:Math.min(Math.max(0,Ut.length-1),i.cursor+1)});return}if(a.return){let i=Ut[me.cursor];if(i){We(null);try{p({kind:"preview",name:Dt(i),text:Wi(Di(At(e,i),"utf8"))})}catch(h){p({kind:"note",tone:"error",text:`Could not read ${i}: ${h.message}`})}}return}if(a.backspace||a.delete){We(i=>i&&{...i,query:i.query.slice(0,-1),cursor:0});return}if(l&&!a.ctrl&&!a.meta&&l.length===1){We(i=>i&&{...i,query:i.query+l,cursor:0});return}return}if(he){if(a.escape){He(null);return}if(a.upArrow){He(i=>i&&{...i,cursor:Math.max(0,i.cursor-1)});return}if(a.downArrow){He(i=>i&&{...i,cursor:Math.min(Math.max(0,Wt.length-1),i.cursor+1)});return}if(a.return){let i=Wt[he.cursor];if(i){He(null),ce(i.uuid),xe.current={uuid:i.uuid,firstPrompt:i.firstPrompt,titleFired:!0},Qe(i.name),Yo(i.uuid),Ke.current=[];let h=Fo(e,i.uuid);for(let u of h)p(u);p({kind:"note",tone:"ok",text:h.length?`Resumed "${i.name}" \u2014 restored ${h.length} message(s); continue where you left off.`:`Resumed "${i.name}" (agent memory reconnected; no saved transcript to replay).`})}return}if(a.backspace||a.delete){He(i=>i&&{...i,query:i.query.slice(0,-1),cursor:0});return}if(l&&!a.ctrl&&!a.meta&&l.length===1){He(i=>i&&{...i,query:i.query+l,cursor:0});return}return}if(a.tab&&!R&&we){y(we),re(null),ze.current++;return}if(!R&&pt.length>0&&l&&/^[1-9]$/.test(l)){let i=pt[Number(l)-1];if(i){y(i);return}}if(!kr(l,a)){if(ur){if(a.upArrow){Ve(i=>Math.max(0,i-1));return}if(a.downArrow){Ve(i=>Math.min(mt.length-1,i+1));return}if(a.tab){y("/"+(mt[ft]?.name??"")+" "),Ve(0);return}if(a.return){let i=mt[ft];if(i){let h=R.trim().slice(1).split(/\s+/).slice(1).join(" ");if(Ir(i.usage)&&!h){y("/"+i.name+" "),Ve(0);return}qt("/"+i.name+(h?" "+h:""));return}}}else{if(a.upArrow){if(R!==""&&Xe===null){Gt(-1);return}let i=Sn.current;if(!i.length)return;let h=Xe===null?i.length-1:Math.max(0,Xe-1);It(h),y(i[h]??"");return}if(a.downArrow){if(R!==""&&Xe===null){Gt(1);return}let i=Sn.current;if(Xe===null)return;let h=Xe+1;h>=i.length?(It(null),y("")):(It(h),y(i[h]??""));return}}if(a.return){qt();return}if(a.backspace||a.delete){v();return}if(a.escape){y(""),Ve(0),re(null),X([]),_t(null);return}l&&!a.ctrl&&!a.meta&&hr(l)}}}),_e(()=>{if(_||H)return;let l=Fe.current.shift();l!==void 0&&(jn([...Fe.current]),qt(l))},[_,H,qt]),F(J,{flexDirection:"column",width:Be,children:[En!==null&&F(J,{marginTop:1,flexDirection:"column",children:[En.truncated&&S(C,{dimColor:!0,children:"\u2026"}),S(C,{children:En.text})]}),_&&(rr?S(kd,{p:rr}):S(hd,{startTime:Me.current,chars:Vi})),S(J,{borderStyle:"round",borderColor:cr.prod?"yellow":G,borderTop:!0,borderBottom:!0,borderLeft:!1,borderRight:!1,marginTop:1,flexDirection:"column",children:R?wr.map((l,a)=>{let i=w.text.slice(l.start,l.end),h=a===bn(wr,w.pos),u=Math.min(w.pos,l.end)-l.start;return F(C,{children:[S(C,{color:G,children:a===0?"> ":" "}),h?F(Ko,{children:[i.slice(0,u),S(Pn,{ch:i[u]??" "}),i.slice(u+1)]}):i||" "]},`${a}-${l.start}`)}):F(C,{children:[S(C,{color:G,children:"> "}),we&&!_?F(Ko,{children:[S(Pn,{ch:we[0],dim:!0}),S(C,{color:"gray",children:we.slice(1)}),S(C,{dimColor:!0,children:" (tab)"})]}):An.isSetup||!Yi?F(Ko,{children:[S(Pn,{ch:An.text[0],dim:!0}),S(C,{color:"gray",children:An.text.slice(1)})]}):S(Pn,{ch:" "})]})}),or.length>0&&S(J,{flexDirection:"column",paddingX:1,children:or.map((l,a)=>S(C,{color:"gray",children:`\u29D7 queued: ${l}`},`${a}-${l.slice(0,24)}`))}),Oe?F(J,{flexDirection:"column",paddingX:1,children:[S(C,{color:G,bold:!0,children:"Select model"}),S(C,{color:"gray",children:"Your pick becomes your personal default for new sessions (team .d360-writer.json still wins)."}),ye.map((l,a)=>F(C,{color:a===Oe.cursor?G:void 0,children:[a===Oe.cursor?"\u276F ":" ",`${a+1}. ${l.label}${a===Oe.current?" \u2714":""}`.padEnd(16),S(C,{color:"gray",children:l.desc})]},l.label)),S(C,{dimColor:!0,children:"enter set as default \xB7 s this session only \xB7 esc cancel"})]}):be?F(J,{flexDirection:"column",paddingX:1,children:[S(C,{color:G,bold:!0,children:"Switch connection profile"}),be.rows.map((l,a)=>F(C,{color:a===be.cursor?G:void 0,children:[a===be.cursor?"\u276F ":" ",`${a+1}. ${l.name}${a===be.current?" \u2714":""}`.padEnd(20),S(C,{color:"gray",children:`${l.env} \xB7 ${l.who??"not signed in"}`}),l.prod?S(C,{color:"yellow",bold:!0,children:" \u26A0 PRODUCTION"}):null]},l.name)),S(C,{dimColor:!0,children:"enter switch (saved as default) \xB7 s this session only \xB7 esc cancel"})]}):Re?F(J,{flexDirection:"column",paddingX:1,children:[S(C,{color:G,bold:!0,children:"Pick your Document360 environment"}),Re.rows.map((l,a)=>F(C,{color:a===Re.cursor?G:void 0,children:[a===Re.cursor?"\u276F ":" ",`${a+1}. ${l.name}`.padEnd(16),S(C,{color:"gray",children:l.apiUrl})]},l.name)),S(C,{dimColor:!0,children:"enter select \xB7 esc cancel"})]}):ae?F(J,{flexDirection:"column",paddingX:1,children:[S(C,{color:G,bold:!0,children:"Switch workspace"}),S(C,{dimColor:!0,children:`environment ${ae.environment} \xB7 project ${ae.projectId.slice(0,8)}\u2026`}),ae.rows.map((l,a)=>F(C,{color:a===ae.cursor?G:void 0,children:[a===ae.cursor?"\u276F ":" ",`${a+1}. ${l.name}${a===ae.current?" \u2714":""}`.padEnd(30),S(C,{color:"gray",children:l.type??""})]},l.id)),S(C,{dimColor:!0,children:"enter switch \xB7 esc cancel"})]}):fe?F(J,{flexDirection:"column",paddingX:1,children:[S(C,{color:G,bold:!0,children:"Choose project"}),S(C,{dimColor:!0,children:`environment ${fe.environment}`}),fe.rows.map((l,a)=>F(C,{color:a===fe.cursor?G:void 0,children:[a===fe.cursor?"\u276F ":" ",`${a+1}. ${l.name}${a===fe.current?" \u2714":""}`.padEnd(30),S(C,{color:"gray",children:l.sub??""})]},l.id)),S(C,{dimColor:!0,children:"enter select \xB7 esc cancel"})]}):le?(()=>{let a=Math.min(Math.max(0,le.cursor-Math.floor(7)),Math.max(0,le.rows.length-14)),i=le.rows.slice(a,a+14),h=le.rows.filter(u=>u.checked).length;return F(J,{flexDirection:"column",paddingX:1,children:[S(C,{color:G,bold:!0,children:`Which folders back the user docs? (${h} selected of ${le.rows.length})`}),a>0?S(C,{dimColor:!0,children:` \u2191 ${a} more`}):null,i.map((u,m)=>{let k=a+m;return F(C,{color:k===le.cursor?G:void 0,children:[k===le.cursor?"\u276F ":" ",u.checked?"\u25C9 ":"\u25CB ",u.path.padEnd(Math.min(48,Be-34)),S(C,{color:"gray",children:sn(u)})]},u.path)}),a+14<le.rows.length?S(C,{dimColor:!0,children:` \u2193 ${le.rows.length-a-14} more`}):null,S(C,{dimColor:!0,children:"space toggle \xB7 enter save \xB7 esc cancel"})]})})():Ue?F(J,{flexDirection:"column",paddingX:1,children:[S(C,{color:G,bold:!0,children:"Publish to Document360 \u2014 pick a category (whole) or an article:"}),Ue.rows.map((l,a)=>{let i=a===Ue.cursor,h=l.indent?" ":" ",u=`${a+1}.`.padEnd(3);return F(C,{color:i?G:void 0,bold:l.kind==="category"&&!i,children:[i?"\u276F ":" ",`${h}${u} ${l.label}`.padEnd(Math.min(56,Be-24)),l.note?S(C,{color:"gray",children:l.note}):null]},`${l.kind}:${l.paths.join(",")}`)}),S(C,{dimColor:!0,children:"\u2191\u2193 move \xB7 1-9 jump \xB7 enter publish (draft) \xB7 esc cancel"})]}):me?F(J,{flexDirection:"column",paddingX:1,children:[S(C,{color:G,bold:!0,children:`Preview article${me.query?` \u2014 filter: ${me.query}`:" (type to filter)"}`}),Ut.length===0?S(C,{color:"gray",children:"no articles match"}):Ut.map((l,a)=>F(C,{color:a===me.cursor?G:void 0,children:[a===me.cursor?"\u276F ":" ",l]},l)),S(C,{dimColor:!0,children:"enter preview \xB7 esc cancel"})]}):he?F(J,{flexDirection:"column",paddingX:1,children:[S(C,{color:G,bold:!0,children:`Resume session${he.query?` \u2014 filter: ${he.query}`:" (type to filter)"}`}),Wt.length===0?S(C,{color:"gray",children:"no sessions match"}):Wt.map((l,a)=>F(C,{color:a===he.cursor?G:void 0,children:[a===he.cursor?"\u276F ":" ",l.name.slice(0,28).padEnd(30),S(C,{color:a===he.cursor?G:"gray",children:l.firstPrompt.slice(0,Math.max(10,Be-40))})]},l.uuid)),S(C,{dimColor:!0,children:"enter resume \xB7 esc cancel"})]}):ur?S(J,{flexDirection:"column",children:mt.map((l,a)=>F(C,{color:a===ft?G:void 0,children:[a===ft?"\u276F ":" ",l.usage.padEnd(22)," ",S(C,{color:a===ft?G:"gray",children:l.name==="model"&&Dn?`${l.desc} (currently ${Dn})`:l.desc})]},l.name))}):!R&&pt.length>0?F(J,{flexDirection:"column",paddingX:1,children:[nr?S(C,{color:G,children:nr}):null,pt.map((l,a)=>F(C,{children:[S(C,{color:G,children:a+1})," ",l.slice(0,Math.max(20,Be-5))]},l)),S(C,{dimColor:!0,children:`press 1-${pt.length} to fill the command \xB7 esc dismiss`})]}):S(J,{paddingX:1,children:F(C,{color:"gray",children:[cr.prod?"\u26A0 PRODUCTION \xB7 ":"",`/help \xB7 ${Dn??"model n/a"}${t.kind==="api"?ir>0?` \xB7 ${ie(ir)}`:"":sr>0?` \xB7 ${Ee(sr)}`:""} \xB7 \u2191 history \xB7 ctrl+c exit`]})})]})}q();import{jsx as xd}from"react/jsx-runtime";async function qi(e=process.cwd(),t="auto",n,o="0.0.0"){let r=$d(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 ${E("https://console.anthropic.com/settings/keys")}`),console.error(`Or use your Claude subscription instead: ${E("d360-writer --auth subscription")}`),process.exit(2));let{waitUntilExit:s}=yd(xd(Bi,{cwd:e,auth:r,profileName:n,version:o}));await s(),process.stdout.write(`
199
+ `),process.exit(0)}var Pd=vd(import.meta.url),Gi=Pd("../package.json"),Te=new bd;function Qo(e){e.env&&(console.error("\u2717 --env was replaced by --profile (connection profiles). Use: --profile <name>"),process.exit(2))}Te.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=>{Qo(e),await Xt({profile:e.profile,manual:e.manual})});Te.command("logout").description("Remove the stored Document360 session").option("--profile <name>","Connection profile").option("--env <name>",!1).action(async e=>{Qo(e),await Rr({profile:e.profile})});Te.command("whoami").description("Show the current Document360 identity (refreshes if expired)").option("--profile <name>","Connection profile").option("--env <name>",!1).action(async e=>{Qo(e),await Sr({profile:e.profile})});var Zo=Te.command("profile").description("Manage connection profiles for the current repo");Zo.command("list",{isDefault:!0}).description("List profiles (\u25CF = default)").action(()=>Kt(process.cwd()));Zo.command("use <name>").description("Set the default profile for this repo").action(e=>Jt(process.cwd(),e));Zo.command("show [name]").description("Print the resolved profile (connection + project)").action(e=>Qt(process.cwd(),e));var zi=Te.command("workspace").description("Choose the Document360 workspace for this repo (active profile's project)");zi.command("select",{isDefault:!0}).description("Interactively pick the workspace (lists in non-TTY)").option("--profile <name>","Connection profile").action(e=>lt(process.cwd(),e.profile));zi.command("use <name>").description("Set the workspace by name (scriptable)").option("--profile <name>","Connection profile").action(async(e,t)=>{process.exitCode=await br(process.cwd(),e,t.profile)});Te.command("logs").description("Show the Document360 API log files (send these to support when reporting a problem)").action(()=>Dr());Te.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(()=>(un(),Ns)),n=await t(process.cwd());for(let o of e(n))console.log(o);process.exitCode=n.some(o=>o.level==="fail")?1:0});Te.name("d360-writer").description("Standalone documentation agent CLI. Reads your code, writes your docs.").version(Gi.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(Cd.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 Ar(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 pi(e.cwd,e.auth,e.profile):await qi(e.cwd,e.auth,e.profile,Gi.version)});Te.parseAsync(process.argv).catch(e=>{console.error(""),console.error(`\u2717 ${e.message}`),process.exit(1)});
@@ -1,20 +1,25 @@
1
1
  import type { SlashCommandResult } from './index.js';
2
2
  import type { ReplContext } from '../repl.js';
3
3
  /** Bump when the guide content changes — lets a future check detect a stale committed guide. */
4
- export declare const DEV_HINTS_GUIDE_VERSION = 1;
4
+ export declare const DEV_HINTS_GUIDE_VERSION = 2;
5
5
  /**
6
- * The committed protocol guide the SOURCE repo's coding agent follows to write doc hints. It is
7
- * self-contained because that agent has none of d360-writer's context (no tools, no system prompt)
8
- * everything it needs to produce a valid hint is here. The /devhints command writes this to
9
- * `.d360-writer/DEV-HINTS-GUIDE.md`; the paste block (below) just points the source agent at it.
6
+ * The committed protocol guide the SOURCE repo's coding agent follows. Self-contained because that
7
+ * agent has none of d360-writer's context. Two parts: (1) a ONE-TIME architecture brief that onboards
8
+ * the docs agent the builder, who holds the full intent, hands over what code alone can't tell a
9
+ * writer; (2) ONGOING per-change doc hints. The /devhints command writes this to
10
+ * `.d360-writer/DEV-HINTS-GUIDE.md`; the paste block points the source agent at it.
10
11
  */
11
12
  export declare function devHintsGuide(): string;
12
- /** `/devhints` scaffold the hint channel: write the committed guide + emit a paste-ready block the
13
- user adds to their SOURCE repo's CLAUDE.md/AGENTS.md so its coding agent starts leaving hints. */
13
+ /** The human-owned creator-notes template (scaffolded once, never overwritten). The builder reads it
14
+ first as authoritative; the docs agent reads it as authoritative intent. */
15
+ export declare function creatorNotesTemplate(): string;
16
+ /** `/devhints` — scaffold the dev→docs hand-off: write the committed guide + the architecture inbox
17
+ (with a human creator-notes template) + the hints inbox, then emit a paste-ready block for the
18
+ SOURCE repo's CLAUDE.md/AGENTS.md so its coding agent onboards the docs agent and keeps it current. */
14
19
  export declare function devhintsCommand(_args: string[], ctx: ReplContext): Promise<SlashCommandResult>;
15
20
  /**
16
21
  * The paste-ready block for the user to add to their SOURCE repo's agent memory (CLAUDE.md/AGENTS.md).
17
- * A ONE-LINE pointer to the committed guide — not the protocol inline — so their memory stays lean and
18
- * we can improve the guide without anyone re-pasting. Mirrors renderTestidHandoff's bracketed shape.
22
+ * A pointer to the committed guide plus the ordered marching orders — not the protocol inline — so their
23
+ * memory stays lean and we can improve the guide without re-pasting. Mirrors renderTestidHandoff's shape.
19
24
  */
20
25
  export declare function renderDevHintsHandoff(): string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "document360-writer",
3
- "version": "0.4.54",
3
+ "version": "0.4.55",
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.31",
37
+ "document360-engine": "^0.2.32",
38
38
  "ink": "^5.2.1",
39
39
  "picocolors": "^1.1.1",
40
40
  "react": "^18.3.1",