[{"data":1,"prerenderedAt":722,"buildId":723},["ShallowReactive",2],{"docs:\u002Fintegrations\u002Fmarkdown-answers":3},{"page":4,"section":16,"document":17,"credits":10,"prev":714,"next":718},{"id":5,"path":6,"file":7,"title":8,"sourceTitle":8,"description":9,"tagline":9,"eyebrow":10,"credits":10,"keywords":11,"icon":12,"layout":13,"sidebar":14,"toc":14,"kind":10,"group":10,"navigation":14,"order":15},"markdown-answers","\u002Fintegrations\u002Fmarkdown-answers","integrations\u002Fmarkdown-answers.md","Markdown answers","Render a command's Markdown answer with @comark\u002Fansi for a person at a terminal, and pass it as is to coding agents, json and jsonl.",null,[],"i-simple-icons-markdown","article",true,6,"integrations",{"nodes":18,"toc":709},[19,32,40,52,301,315,330,354,360,363,395,405,408,445,453,466,473,483,654,667,691,697],[20,21,22,23,27,28,31],"p",{},"Some commands answer with a page, not findings: an ",[24,25,26],"code",{},"explain"," command, a help topic, a report. readerly doesn't render Markdown and has no dependencies. You render the page yourself for the reader who wants it styled, and hand readerly the string with ",[24,29,30],{},"out.write()",".",[33,34,39],"h2",{"id":35,"anchor":36},"the-recipe",{"label":37,"icon":38},"Section titled \"The recipe\"","#","The recipe",[20,41,42,47,48,51],{},[43,44,46],"a",{"href":45},"https:\u002F\u002Fwww.npmjs.com\u002Fpackage\u002F@comark\u002Fansi","@comark\u002Fansi"," turns Markdown into terminal text. Render only when the format is ",[24,49,50],{},"text",", and pass the Markdown as is to everyone else:",[53,54,58],"pre",{"language":55,"filename":56,"class":57,"wrap":14},"ts","explain.ts","shiki shiki-themes github-light-default github-dark-default dark:github-dark-default",[24,59,61,84,85,84,99,84,101,84,147,84,176,84,197,84,219,84,229,84,256,84,261,84,282,84,296],{"class":60},"language-ts",[62,63,66,70,74,77,81],"span",{"class":64,"style":65},"line","display: inline",[62,67,69],{"style":68},"color:#CF222E;--shiki-dark:#FF7B72","import",[62,71,73],{"style":72},"color:#1F2328;--shiki-dark:#E6EDF3"," { renderAnsi } ",[62,75,76],{"style":68},"from",[62,78,80],{"style":79},"color:#0A3069;--shiki-dark:#A5D6FF"," \"@comark\u002Fansi\"",[62,82,83],{"style":72},";","\n",[62,86,87,89,92,94,97],{"class":64,"style":65},[62,88,69],{"style":68},[62,90,91],{"style":72}," { createOut, readerFlags } ",[62,93,76],{"style":68},[62,95,96],{"style":79}," \"readerly\"",[62,98,83],{"style":72},[62,100],{"class":64,"style":65},[62,102,103,106,109,112,116,119,123,126,130,133,135,138,141,144],{"class":64,"style":65},[62,104,105],{"style":68},"export",[62,107,108],{"style":68}," async",[62,110,111],{"style":68}," function",[62,113,115],{"style":114},"color:#8250DF;--shiki-dark:#D2A8FF"," explain",[62,117,118],{"style":72},"(",[62,120,122],{"style":121},"color:#953800;--shiki-dark:#FFA657","argv",[62,124,125],{"style":68},":",[62,127,129],{"style":128},"color:#0550AE;--shiki-dark:#79C0FF"," string",[62,131,132],{"style":72},"[])",[62,134,125],{"style":68},[62,136,137],{"style":121}," Promise",[62,139,140],{"style":72},"\u003C",[62,142,143],{"style":128},"number",[62,145,146],{"style":72},"> {",[62,148,149,152,155,158,161,164,167,170,173],{"class":64,"style":65},[62,150,151],{"style":68},"  const",[62,153,154],{"style":128}," out",[62,156,157],{"style":68}," =",[62,159,160],{"style":114}," createOut",[62,162,163],{"style":72},"({ tool: ",[62,165,166],{"style":79},"\"acme\"",[62,168,169],{"style":72},", command: ",[62,171,172],{"style":79},"\"explain\"",[62,174,175],{"style":72},", argv });",[62,177,178,180,183,185,188,191,194],{"class":64,"style":65},[62,179,151],{"style":68},[62,181,182],{"style":72}," [",[62,184,24],{"style":128},[62,186,187],{"style":72},"] ",[62,189,190],{"style":68},"=",[62,192,193],{"style":114}," readerFlags",[62,195,196],{"style":72},"(argv).rest;",[62,198,199,201,204,206,209,212,215],{"class":64,"style":65},[62,200,151],{"style":68},[62,202,203],{"style":128}," page",[62,205,157],{"style":68},[62,207,208],{"style":68}," await",[62,210,211],{"style":114}," pageFor",[62,213,214],{"style":72},"(code); ",[62,216,218],{"style":217},"color:#6E7781;--shiki-dark:#8B949E","\u002F\u002F Markdown",[62,220,221,224,227],{"class":64,"style":65},[62,222,223],{"style":72},"  out.",[62,225,226],{"style":114},"write",[62,228,118],{"style":72},[62,230,231,234,237,240,243,245,248,251,253],{"class":64,"style":65},[62,232,233],{"style":72},"    out.profile.format ",[62,235,236],{"style":68},"===",[62,238,239],{"style":79}," \"text\"",[62,241,242],{"style":68}," ?",[62,244,208],{"style":68},[62,246,247],{"style":114}," renderAnsi",[62,249,250],{"style":72},"(page, { colors: out.profile.color }) ",[62,252,125],{"style":68},[62,254,255],{"style":72}," page,",[62,257,258],{"class":64,"style":65},[62,259,260],{"style":72},"  );",[62,262,263,265,268,270,273,276,279],{"class":64,"style":65},[62,264,223],{"style":72},[62,266,267],{"style":114},"next",[62,269,118],{"style":72},[62,271,272],{"style":79},"\"acme check\"",[62,274,275],{"style":72},", ",[62,277,278],{"style":79},"\"finds every ACME001\"",[62,280,281],{"style":72},");",[62,283,284,287,290,293],{"class":64,"style":65},[62,285,286],{"style":68},"  return",[62,288,289],{"style":72}," out.",[62,291,292],{"style":114},"end",[62,294,295],{"style":72},"();",[62,297,298],{"class":64,"style":65},[62,299,300],{"style":72},"}",[20,302,303,306,307,310,311,314],{},[24,304,305],{},"pageFor"," stands for your own lookup. ",[24,308,309],{},"readerFlags(argv).rest"," drops the reader flags, so ",[24,312,313],{},"acme explain --json ACME001"," still finds the code.",[20,316,317,320,321,324,325,329],{},[24,318,319],{},"renderAnsi"," is async, so it runs before ",[24,322,323],{},"out.write",", not inside a ",[43,326,328],{"href":327},"\u002Fguide\u002Frenderers","renderer",". Renderers are synchronous and pure.",[20,331,332,335,336,275,339,275,342,275,345,348,349,353],{},[24,333,334],{},"out.profile.color"," already follows ",[24,337,338],{},"--color",[24,340,341],{},"--no-color",[24,343,344],{},"FORCE_COLOR",[24,346,347],{},"NO_COLOR"," and the TTY, see ",[43,350,352],{"href":351},"\u002Fguide\u002Fcolor","color",". Passing it on keeps the page plain in a pipe or a CI log.",[33,355,359],{"id":356,"anchor":357},"what-each-reader-gets",{"label":358,"icon":38},"Section titled \"What each reader gets\"","What each reader gets",[20,361,362],{},"The page in these samples:",[53,364,366],{"language":365,"class":57,"wrap":14},"md",[24,367,369,84,375,84,377,84,388,84,390],{"class":368},"language-md",[62,370,371],{"class":64,"style":65},[62,372,374],{"style":373},"color:#0550AE;--shiki-light-font-weight:bold;--shiki-dark:#79C0FF;--shiki-dark-font-weight:bold","# ACME001",[62,376],{"class":64,"style":65},[62,378,379,382,385],{"class":64,"style":65},[62,380,381],{"style":72},"Route handler reads ",[62,383,384],{"style":128},"`process.env`",[62,386,387],{"style":72}," at module scope.",[62,389],{"class":64,"style":65},[62,391,392],{"class":64,"style":65},[62,393,394],{"style":72},"The value is fixed at build time. Read it inside the handler.",[20,396,397,398,400,401,404],{},"At a terminal, ",[24,399,50],{}," prints the verdict line, the rendered page, then the ",[24,402,403],{},"next:"," lines, separated by blank lines.",[20,406,407],{},"A coding agent gets the Markdown unchanged after the verdict line. Agents read Markdown well, and escape codes would only cost characters:",[53,409,410],{"language":50,"class":57,"wrap":14},[24,411,413,84,418,84,422,84,427,84,432,84,436,84,440],{"class":412},"language-text",[62,414,415],{"class":64,"style":65},[62,416,417],{},"acme explain: ok. no problems.",[62,419,420],{"class":64,"style":65},[62,421,374],{},[62,423,424],{"class":64,"style":65},[62,425,426],{},"",[62,428,429],{"class":64,"style":65},[62,430,431],{},"Route handler reads `process.env` at module scope.",[62,433,434],{"class":64,"style":65},[62,435,426],{},[62,437,438],{"class":64,"style":65},[62,439,394],{},[62,441,442],{"class":64,"style":65},[62,443,444],{},"next: acme check   (finds every ACME001)",[20,446,447,448,452],{},"The page counts against the agent's ",[43,449,451],{"href":450},"\u002Fguide\u002Fbudget","budget"," of 8,000 characters, line by line. A page of 400 lines kept 144 and ended with:",[53,454,455],{"language":50,"class":57,"wrap":14},[24,456,457,84,461],{"class":412},[62,458,459],{"class":64,"style":65},[62,460,444],{},[62,462,463],{"class":64,"style":65},[62,464,465],{},"hidden: 256 lines. rerun: acme explain ACME001 --full, or acme explain ACME001 --format json",[20,467,468,469,472],{},"When a command writes an answer, the agent format prints the answer in place of diagnostics and log lines. The verdict line still counts them, so ",[24,470,471],{},"acme explain: ok. 1 warning."," tells the agent there was one.",[20,474,475,478,479,482],{},[24,476,477],{},"--format json"," adds the page as ",[24,480,481],{},"answer"," to the document, next to the diagnostics:",[53,484,486],{"language":485,"class":57,"wrap":14},"json",[24,487,489,84,494,84,509,84,521,84,529,84,541,84,552,84,561,84,566,84,574,84,582,84,590,84,595,84,606,84,615,84,620,84,625,84,650],{"class":488},"language-json",[62,490,491],{"class":64,"style":65},[62,492,493],{"style":72},"{",[62,495,496,500,503,506],{"class":64,"style":65},[62,497,499],{"style":498},"color:#116329;--shiki-dark:#7EE787","  \"schema\"",[62,501,502],{"style":72},": ",[62,504,505],{"style":79},"\"acme.explain\u002Fv1\"",[62,507,508],{"style":72},",",[62,510,511,514,516,519],{"class":64,"style":65},[62,512,513],{"style":498},"  \"status\"",[62,515,502],{"style":72},[62,517,518],{"style":79},"\"ok\"",[62,520,508],{"style":72},[62,522,523,526],{"class":64,"style":65},[62,524,525],{"style":498},"  \"summary\"",[62,527,528],{"style":72},": {",[62,530,531,534,536,539],{"class":64,"style":65},[62,532,533],{"style":498},"    \"error\"",[62,535,502],{"style":72},[62,537,538],{"style":128},"0",[62,540,508],{"style":72},[62,542,543,546,548,550],{"class":64,"style":65},[62,544,545],{"style":498},"    \"warn\"",[62,547,502],{"style":72},[62,549,538],{"style":128},[62,551,508],{"style":72},[62,553,554,557,559],{"class":64,"style":65},[62,555,556],{"style":498},"    \"info\"",[62,558,502],{"style":72},[62,560,538],{"style":128},[62,562,563],{"class":64,"style":65},[62,564,565],{"style":72},"  },",[62,567,568,571],{"class":64,"style":65},[62,569,570],{"style":498},"  \"diagnostics\"",[62,572,573],{"style":72},": [],",[62,575,576,579],{"class":64,"style":65},[62,577,578],{"style":498},"  \"result\"",[62,580,581],{"style":72},": {},",[62,583,584,587],{"class":64,"style":65},[62,585,586],{"style":498},"  \"next\"",[62,588,589],{"style":72},": [",[62,591,592],{"class":64,"style":65},[62,593,594],{"style":72},"    {",[62,596,597,600,602,604],{"class":64,"style":65},[62,598,599],{"style":498},"      \"command\"",[62,601,502],{"style":72},[62,603,272],{"style":79},[62,605,508],{"style":72},[62,607,608,611,613],{"class":64,"style":65},[62,609,610],{"style":498},"      \"reason\"",[62,612,502],{"style":72},[62,614,278],{"style":79},[62,616,617],{"class":64,"style":65},[62,618,619],{"style":72},"    }",[62,621,622],{"class":64,"style":65},[62,623,624],{"style":72},"  ],",[62,626,627,630,632,635,638,640,642,644,647],{"class":64,"style":65},[62,628,629],{"style":498},"  \"answer\"",[62,631,502],{"style":72},[62,633,634],{"style":79},"\"# ACME001",[62,636,637],{"style":68},"\\n\\n",[62,639,431],{"style":79},[62,641,637],{"style":68},[62,643,394],{"style":79},[62,645,646],{"style":68},"\\n",[62,648,649],{"style":79},"\"",[62,651,652],{"class":64,"style":65},[62,653,300],{"style":72},[20,655,656,659,660,662,663,666],{},[24,657,658],{},"--format jsonl"," sends it as an ",[24,661,481],{}," record before the ",[24,664,665],{},"result"," record:",[53,668,669],{"language":50,"class":57,"wrap":14},[24,670,671,84,676,84,681,84,686],{"class":412},[62,672,673],{"class":64,"style":65},[62,674,675],{},"{\"type\":\"version\",\"schema\":\"acme.explain\u002Fv1\",\"tool\":\"acme\"}",[62,677,678],{"class":64,"style":65},[62,679,680],{},"{\"type\":\"next\",\"message\":\"acme check\",\"reason\":\"finds every ACME001\"}",[62,682,683],{"class":64,"style":65},[62,684,685],{},"{\"type\":\"answer\",\"message\":\"# ACME001\\n\\nRoute handler reads `process.env` at module scope.\\n\\nThe value is fixed at build time. Read it inside the handler.\\n\"}",[62,687,688],{"class":64,"style":65},[62,689,690],{},"{\"type\":\"result\",\"status\":\"ok\",\"message\":\"no problems\",\"data\":{}}",[33,692,696],{"id":693,"anchor":694},"calling-write-more-than-once",{"label":695,"icon":38},"Section titled \"Calling write more than once\"","Calling write more than once",[20,698,699,701,702,704,705,708],{},[24,700,30],{}," keeps one answer. A second call replaces the first. Build the whole page, then write it. Before a prompt, readerly prints what you wrote so far. A ",[24,703,226],{}," after the prompt prints again at ",[24,706,707],{},"end()",", even when the text is the same.",[710,712,713],{"id":35,"depth":711,"text":39},2,{"id":356,"depth":711,"text":359},{"id":693,"depth":711,"text":696},{"path":715,"title":716,"description":717},"\u002Fintegrations\u002Fprogress","Progress","How out.progress and createProgress show a long step: a live bar on a terminal, a line every 5 seconds in CI and pipes, nothing for agents or JSON.",{"path":719,"title":720,"description":721},"\u002Fintegrations\u002Fnostics","nostics","Send nostics diagnostics to createOut with nosticsReporter, or convert one with fromNostics. The bridge matches nostics by shape and doesn't depend on it.",1795985395698,"22ea5d7b-bce0-4e3b-bca3-1fbe3722fcf7"]