Repository navigation
Expand file tree
/
Copy pathdev.html
More file actions
99 lines (84 loc) · 12.1 KB
/
Copy pathdev.html
File metadata and controls
99 lines (84 loc) · 12.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- This file is generated by Nim. -->
<html xmlns="https://www.w3.org/1999/xhtml" xml:lang="en" lang="en" data-theme="auto">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>3code - developer docs</title>
<!-- Google fonts -->
<link href='https://fonts.googleapis.com/css?family=Lato:400,600,900' rel='stylesheet' type='text/css'/>
<link href='https://fonts.googleapis.com/css?family=Source+Code+Pro:400,500,600' rel='stylesheet' type='text/css'/>
<!-- Favicon -->
<link rel="shortcut icon" href="data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAUAAAAF////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAIAAABbAAAAlQAAAKIAAACbAAAAmwAAAKIAAACVAAAAWwAAAAL///8A////AP///wD///8A////AAAAABQAAADAAAAAYwAAAA3///8A////AP///wD///8AAAAADQAAAGMAAADAAAAAFP///wD///8A////AP///wAAAACdAAAAOv///wD///8A////AP///wD///8A////AP///wD///8AAAAAOgAAAJ3///8A////AP///wAAAAAnAAAAcP///wAAAAAoAAAASv///wD///8A////AP///wAAAABKAAAAKP///wAAAABwAAAAJ////wD///8AAAAAgQAAABwAAACIAAAAkAAAAJMAAACtAAAAFQAAABUAAACtAAAAkwAAAJAAAACIAAAAHAAAAIH///8A////AAAAAKQAAACrAAAAaP///wD///8AAAAARQAAANIAAADSAAAARf///wD///8AAAAAaAAAAKsAAACk////AAAAADMAAACcAAAAnQAAABj///8A////AP///wAAAAAYAAAAGP///wD///8A////AAAAABgAAACdAAAAnAAAADMAAAB1AAAAwwAAAP8AAADpAAAAsQAAAE4AAAAb////AP///wAAAAAbAAAATgAAALEAAADpAAAA/wAAAMMAAAB1AAAAtwAAAOkAAAD/AAAA/wAAAP8AAADvAAAA3gAAAN4AAADeAAAA3gAAAO8AAAD/AAAA/wAAAP8AAADpAAAAtwAAAGUAAAA/AAAA3wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAADfAAAAPwAAAGX///8A////AAAAAEgAAADtAAAAvwAAAL0AAADGAAAA7wAAAO8AAADGAAAAvQAAAL8AAADtAAAASP///wD///8A////AP///wD///8AAAAAO////wD///8A////AAAAAIcAAACH////AP///wD///8AAAAAO////wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A//8AAP//AAD4HwAA7/cAAN/7AAD//wAAoYUAAJ55AACf+QAAh+EAAAAAAADAAwAA4AcAAP5/AAD//wAA//8AAA=="/>
<link rel="icon" type="image/png" sizes="32x32" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAAB3RJTUUH4QQQEwksSS9ZWwAAAk1JREFUWMPtll2ITVEUx39nn/O7Y5qR8f05wtCUUr6ZIS++8pEnkZInPImneaCQ5METNdOkeFBKUhMPRIkHKfEuUZSUlGlKPN2TrgfncpvmnntnmlEyq1Z7t89/rf9a6+y99oZxGZf/XeIq61EdtgKXgdXA0xrYAvBjOIF1AI9zvjcC74BSpndrJPkBWDScTF8Aa4E3wDlgHbASaANmVqlcCnwHvgDvgVfAJ+AikAAvgfVZwLnSVZHZaOuKoQi3ZOMi4NkYkpe1p4J7A8BpYAD49hfIy/oqG0+hLomiKP2L5L+1ubn5115S+3OAn4EnwBlgMzCjyt6ZAnQCJ4A7wOs88iRJHvw50HoujuPBoCKwHWiosy8MdfZnAdcHk8dxXFJ3VQbQlCTJvRBCGdRbD4M6uc5glpY3eAihpN5S5w12diSEcCCEcKUO4ljdr15T76ur1FDDLIQQ3qv71EdDOe3Kxj3leRXyk+pxdWnFWod6Wt2bY3de3aSuUHcPBVimHs7mK9WrmeOF6lR1o9qnzskh2ar2qm1qizpfXaPeVGdlmGN5pb09qMxz1Xb1kLqgzn1RyH7JUXW52lr5e/Kqi9qpto7V1atuUzfnARrV7jEib1T76gG2qxdGmXyiekkt1GswPTtek0aBfJp6YySGBfWg2tPQ0FAYgf1stUfdmdcjarbYJEniKIq6gY/Aw+zWHAC+p2labGpqiorFYgGYCEzN7oQdQClN07O1/EfDyGgC0ALMBdYAi4FyK+4H3gLPsxfR1zRNi+NP7nH5J+QntnXe5B5mpfQAAAAASUVORK5CYII=">
<!-- CSS -->
<link rel="stylesheet" type="text/css" href="nimdoc.out.css?v=2.4.0">
<!-- JS -->
<script type="text/javascript" src="dochack.js?v=2.4.0"></script>
</head>
<body>
<div class="document" id="documentId">
<input type="checkbox" id="nav-toggle" hidden>
<label for="nav-toggle" id="nav-burger">☰</label>
<label for="nav-toggle" id="nav-overlay"></label>
<div class="container">
<h1 class="title">3code - developer docs</h1>
<div class="row">
<div class="three columns" id="page-toc">
<div class="page-toc-title">Contents</div>
<ul class="page-toc-list">
<li><a href="#introduction">Introduction</a></li>
<li><a href="#embedding">Embedding</a></li>
<li><a href="#module-tour">Module tour</a></li>
<li><a href="#development-guidelines">Development guidelines</a><ul>
<li><a href="#a-system-command-must-never-block">A system command must never block</a></li>
</ul>
</li>
<li><a href="#regenerating">Regenerating</a></li>
</ul>
</div>
<div class="nine columns" id="content">
<div class="dev-kicker">developer docs</div>
<h2 id="introduction">Introduction</h2><p>These are the developer docs: the internal API of 3code as extracted from the source by <tt class="docutils literal"><span class="pre">nim doc</span></tt>, every module, type, and proc with its doc comment. Where the <a class="reference external" href="index.html">manual</a> shows you how to use the app and the <a class="reference external" href="reference.html">reference</a> lists every switch and config key, this half is for people embedding 3code in another program, writing a plugin, or changing 3code itself.</p>
<p>Start from the entry points:</p>
<ul class="simple"><li><a class="reference external" href="dev/threecode.html">threecode</a> - the root module: entry point, outer REPL loop, and the full module list</li>
<li><a class="reference external" href="dev/theindex.html">index of every symbol</a> - flat, alphabetical, one page</li>
</ul>
<h2 id="embedding">Embedding</h2><p>The headless frontend is <tt class="docutils literal"><span class="pre">threecode/library</span></tt>: it runs the same agent loop, tools, sandbox, and <tt class="docutils literal"><span class="pre">.3log</span></tt> sessions as the CLI, with the terminal replaced by return values and callbacks.</p>
<p><pre class="listing"><span class="Keyword">import</span> <span class="Identifier">threecode</span><span class="Operator">/</span><span class="Identifier">library</span>
<span class="Keyword">let</span> <span class="Identifier">s</span> <span class="Operator">=</span> <span class="Identifier">initAgentSession</span><span class="Punctuation">(</span><span class="Identifier">AgentOptions</span><span class="Punctuation">(</span><span class="Identifier">model</span><span class="Punctuation">:</span> <span class="StringLit">"deepinfra.deepseek-v3.2"</span><span class="Punctuation">)</span><span class="Punctuation">)</span>
<span class="Identifier">echo</span> <span class="Identifier">s</span><span class="Operator">.</span><span class="Identifier">prompt</span><span class="Punctuation">(</span><span class="StringLit">"what does this project do?"</span><span class="Punctuation">)</span>
<span class="Identifier">s</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre></p>
<h2 id="module-tour">Module tour</h2><p>The modules a host or contributor touches most, with their job in one line:</p>
<table border="1" class="docutils"><tr><th>module</th><th>what lives there</th></tr>
<tr><td><a class="reference external" href="dev/threecode/turns.html">turns</a></td><td>turn lifecycle orchestration</td></tr>
<tr><td><a class="reference external" href="dev/threecode/actions.html">actions</a></td><td>tool dispatch: model tool_call JSON into Actions, then execute</td></tr>
<tr><td><a class="reference external" href="dev/threecode/snap.html">snap</a></td><td>goal-mode tree manifest: arm at the mode, re-walk after bash, fold shell mutations into the change log</td></tr>
<tr><td><a class="reference external" href="dev/threecode/api.html">api</a></td><td>HTTP client and SSE parsing</td></tr>
<tr><td><a class="reference external" href="dev/threecode/session.html">session</a></td><td>session persistence in the <tt class="docutils literal"><span class="pre">.3log</span></tt> format</td></tr>
<tr><td><a class="reference external" href="dev/threecode/config.html">config</a></td><td>config file parsing and provider/profile resolution</td></tr>
<tr><td><a class="reference external" href="dev/threecode/types.html">types</a></td><td>shared types and process-level globals</td></tr>
<tr><td><a class="reference external" href="dev/threecode/engine.html">engine</a></td><td>stateful terminal layout engine</td></tr>
<tr><td><a class="reference external" href="dev/threecode/minline.html">minline</a></td><td>multiline line editor</td></tr>
<tr><td><a class="reference external" href="dev/threecode/display.html">display</a></td><td>transcript formatting: markdown, receipts, banners</td></tr>
<tr><td><a class="reference external" href="dev/threecode/web.html">web</a></td><td>fetch and search helpers exposed as native tools</td></tr>
</table><p>The root module's list also carries the newer surfaces (<tt class="docutils literal"><span class="pre">library</span></tt> for embedding, the plugin ABI, the sandbox and ACP frontends) and the long tail of wire translations, auth flows, and terminal internals.</p>
<h2 id="development-guidelines">Development guidelines</h2><p>Rules that keep the interactive front ends responsive. They bind every change that adds or touches a <tt class="docutils literal"><span class="pre">:</span></tt> command.</p>
<h3 id="a-system-command-must-never-block">A system command must never block</h3><p>A <tt class="docutils literal"><span class="pre">:</span></tt> command runs while the user waits at the prompt (or queued behind a running turn), so it must return immediately — no network call, no model call, no long local work on the controller or input thread. Anything slower than a file read or a config write runs on a separate thread, and its result is delivered asynchronously afterwards, exactly like a normal one: the answer is committed to scrollback whenever it lands, and the tokens it burned are added to the session ledger and the token bar (the sum of both requests), not dropped because the call was async.</p>
<p><tt class="docutils literal"><span class="pre">:btw</span></tt> is the pattern (see <tt class="docutils literal"><span class="pre">btwthread.nim</span></tt>): the command builds its request from the live history on the controller thread (the only place the history is stable), hands plain strings to a worker, and answers with no body of its own: the controller commits the <tt class="docutils literal"><span class="pre">?</span></tt>-led question item in place of the echoed command line. The controller polls the job from its input wait (<tt class="docutils literal"><span class="pre">ui.deliverFinishedBtw</span></tt>) and commits the answer — dim, under the aside's <tt class="docutils literal"><span class="pre">!</span></tt> icon, beneath the <tt class="docutils literal"><span class="pre">?</span></tt> question item that replaced the echoed command line — between keystrokes. The worker's wire policy (<tt class="docutils literal"><span class="pre">btwRequest</span></tt>) is the main transport's in miniature: 429/5xx/transport failures and an empty 200 back off and retry, and an interrupt cancels the aside by comparing <tt class="docutils literal"><span class="pre">interruptsSeen()</span></tt> counts (the flag itself is cleared when the next turn starts); a cancelled worker's blocked HTTP call runs out on the retired list so later answers never queue behind it. Synchronous-by-contract surfaces (the library's <tt class="docutils literal"><span class="pre">command()</span></tt>) are the one exception: they join the worker and fold the answer into their return value, because their whole API blocks by design.</p>
<h2 id="regenerating">Regenerating</h2><p>These pages are generated, never hand edited. The doc comment in the source is the text; <tt class="docutils literal"><span class="pre">nimble devdocs</span></tt> rewrites <tt class="docutils literal"><span class="pre">docs/dev/</span></tt> from <tt class="docutils literal"><span class="pre">src/</span></tt>:</p>
<p><pre class="listing">nimble devdocs</pre></p>
<div class="admonition admonition-info"><span class="admonition-info-text"><b>Note:</b></span>
The API here is internal. It serves readers of the source and embedders who accept churn; nothing on these pages is a compatibility promise.</div>
</div>
</div>
<div class="twelve-columns footer">
<span class="nim-sprite"></span>
<br>
<small style="color: var(--hint);">Made with Nim. Generated: 2026-11-25 09:49:53 UTC</small>
</div>
</div>
</div>
</body>
</html>