Repository navigation
Expand file tree
/
Copy pathwasm-tool-guide.html
More file actions
919 lines (822 loc) · 29.9 KB
/
Copy pathwasm-tool-guide.html
File metadata and controls
919 lines (822 loc) · 29.9 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Co-do - WebAssembly Tool Packaging Guide</title>
<style>
:root {
--color-primary: #D97757;
--color-primary-hover: #C56643;
--color-primary-light: #F4E8E3;
--color-bg: #FAFAFA;
--color-surface: #FFFFFF;
--color-border: #E5E5E5;
--color-text-primary: #1A1A1A;
--color-text-secondary: #6B6B6B;
--color-text-tertiary: #999999;
--color-success: #4CAF50;
--color-info: #2196F3;
--color-warning: #FF9800;
--radius-md: 0.5rem;
--radius-lg: 0.75rem;
}
@media (prefers-color-scheme: dark) {
:root {
--color-bg: #1A1A1A;
--color-surface: #2A2A2A;
--color-border: #3A3A3A;
--color-text-primary: #F5F5F5;
--color-text-secondary: #B0B0B0;
--color-text-tertiary: #808080;
--color-primary-light: #3A2F2A;
}
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
line-height: 1.7;
color: var(--color-text-primary);
background: var(--color-bg);
-webkit-font-smoothing: antialiased;
}
.container {
max-width: 860px;
margin: 0 auto;
padding: 2rem 1.5rem 4rem;
}
header {
margin-bottom: 2.5rem;
padding-bottom: 1.5rem;
border-bottom: 2px solid var(--color-border);
}
header h1 {
font-size: 2rem;
font-weight: 700;
color: var(--color-primary);
margin-bottom: 0.5rem;
}
header p {
font-size: 1.125rem;
color: var(--color-text-secondary);
}
h2 {
font-size: 1.5rem;
font-weight: 600;
color: var(--color-text-primary);
margin-top: 2.5rem;
margin-bottom: 1rem;
padding-bottom: 0.5rem;
border-bottom: 1px solid var(--color-border);
}
h3 {
font-size: 1.125rem;
font-weight: 600;
color: var(--color-text-primary);
margin-top: 1.5rem;
margin-bottom: 0.75rem;
}
p {
margin-bottom: 1rem;
color: var(--color-text-secondary);
}
a {
color: var(--color-primary);
text-decoration: none;
font-weight: 500;
}
a:hover {
text-decoration: underline;
}
code {
font-family: 'SF Mono', Monaco, 'Courier New', monospace;
font-size: 0.875em;
background: var(--color-primary-light);
padding: 0.15em 0.4em;
border-radius: 4px;
color: var(--color-text-primary);
}
pre {
background: var(--color-surface);
border: 1px solid var(--color-border);
border-radius: var(--radius-lg);
padding: 1.25rem;
overflow-x: auto;
margin-bottom: 1.25rem;
line-height: 1.5;
}
pre code {
background: none;
padding: 0;
font-size: 0.875rem;
}
ul, ol {
margin-bottom: 1rem;
padding-left: 1.5rem;
color: var(--color-text-secondary);
}
li {
margin-bottom: 0.5rem;
}
li strong {
color: var(--color-text-primary);
}
.callout {
padding: 1rem 1.25rem;
border-radius: var(--radius-md);
margin-bottom: 1.25rem;
border-left: 4px solid;
}
.callout-info {
background: #E3F2FD;
border-color: var(--color-info);
color: #1565C0;
}
.callout-warning {
background: #FFF3E0;
border-color: var(--color-warning);
color: #E65100;
}
.callout-success {
background: #E8F5E9;
border-color: var(--color-success);
color: #2E7D32;
}
@media (prefers-color-scheme: dark) {
.callout-info {
background: #1E3A5F;
color: #90CAF9;
}
.callout-warning {
background: #3E2723;
color: #FFCC80;
}
.callout-success {
background: #1B4D3E;
color: #A5D6A7;
}
}
.callout p {
color: inherit;
margin-bottom: 0;
}
table {
width: 100%;
border-collapse: collapse;
margin-bottom: 1.25rem;
font-size: 0.9375rem;
}
th, td {
text-align: left;
padding: 0.75rem 1rem;
border: 1px solid var(--color-border);
}
th {
background: var(--color-primary-light);
font-weight: 600;
color: var(--color-text-primary);
}
td {
color: var(--color-text-secondary);
}
.file-tree {
font-family: 'SF Mono', Monaco, 'Courier New', monospace;
font-size: 0.875rem;
line-height: 1.6;
}
.toc {
background: var(--color-surface);
border: 1px solid var(--color-border);
border-radius: var(--radius-lg);
padding: 1.25rem 1.5rem;
margin-bottom: 2rem;
}
.toc h3 {
margin-top: 0;
margin-bottom: 0.75rem;
font-size: 1rem;
}
.toc ol {
margin-bottom: 0;
}
.toc li {
margin-bottom: 0.25rem;
}
.back-link {
display: inline-flex;
align-items: center;
gap: 0.5rem;
margin-bottom: 1rem;
font-size: 0.9375rem;
}
.source-link {
display: inline-flex;
align-items: center;
gap: 0.5rem;
padding: 0.5rem 1rem;
background: var(--color-surface);
border: 1px solid var(--color-border);
border-radius: var(--radius-md);
font-size: 0.9375rem;
transition: border-color 0.2s;
}
.source-link:hover {
border-color: var(--color-primary);
text-decoration: none;
}
@media (max-width: 600px) {
.container {
padding: 1rem 1rem 3rem;
}
header h1 {
font-size: 1.5rem;
}
pre {
font-size: 0.8125rem;
padding: 1rem;
}
table {
font-size: 0.8125rem;
}
th, td {
padding: 0.5rem;
}
}
</style>
</head>
<body>
<div class="container">
<a href="/" class="back-link">← Back to Co-do</a>
<header>
<h1>WebAssembly Tool Packaging Guide</h1>
<p>Learn how to create, compile, and package custom WebAssembly tools for use in Co-do.</p>
</header>
<nav class="toc">
<h3>Contents</h3>
<ol>
<li><a href="#overview">Overview</a></li>
<li><a href="#package-format">Package Format (ZIP)</a></li>
<li><a href="#manifest">The Manifest File</a></li>
<li><a href="#compiling">Compiling to WebAssembly</a></li>
<li><a href="#packaging">Creating the ZIP Package</a></li>
<li><a href="#installing">Installing in Co-do</a></li>
<li><a href="#execution">How Tools Run</a></li>
<li><a href="#pipeable">Pipeable Commands</a></li>
<li><a href="#limits">Limits & Security</a></li>
<li><a href="#examples">Example: Base64 Tool</a></li>
<li><a href="#source-code">Source Code</a></li>
</ol>
</nav>
<!-- Overview -->
<h2 id="overview">Overview</h2>
<p>
Co-do supports custom WebAssembly (WASM) tools that extend the AI assistant's capabilities.
Tools are packaged as <strong>ZIP files</strong> containing a compiled <code>.wasm</code> binary
and a <code>manifest.json</code> that describes the tool's interface. Once installed, the AI
can invoke your tool to perform operations like encoding, hashing, text processing, and more.
</p>
<p>
Tools are compiled using the <strong>WASI SDK</strong> (WebAssembly System Interface), which
means you can write standard C/C++ code that uses <code>stdio</code>, <code>string</code>, and
other standard library functions. Rust and Go are also supported via their respective WASM targets.
</p>
<!-- Package Format -->
<h2 id="package-format">Package Format (ZIP)</h2>
<p>A tool package is a standard ZIP file with the following structure:</p>
<pre><code class="file-tree">your-tool.zip
├── manifest.json # Required: tool metadata and interface definition
└── your-tool.wasm # Required: compiled WebAssembly binary</code></pre>
<div class="callout callout-info">
<p><strong>Key rules:</strong> The ZIP must contain exactly one <code>manifest.json</code> and exactly one <code>.wasm</code> file. Additional files are allowed but ignored. Files can be at any depth within the ZIP.</p>
</div>
<!-- Manifest -->
<h2 id="manifest">The Manifest File</h2>
<p>
The <code>manifest.json</code> tells Co-do what your tool does, what parameters it accepts,
and how to run it. Here is the full schema:
</p>
<pre><code>{
"name": "my-tool",
"version": "1.0.0",
"description": "A clear description of what the tool does (shown to the AI).",
"parameters": {
"type": "object",
"properties": {
"input": {
"type": "string",
"description": "The data to process"
},
"mode": {
"type": "string",
"enum": ["encode", "decode"],
"description": "Operation mode"
}
},
"required": ["input"]
},
"returns": {
"type": "string",
"description": "The processed output"
},
"execution": {
"argStyle": "positional",
"fileAccess": "none",
"timeout": 5000
},
"pipeable": true,
"category": "crypto",
"author": "Your Name",
"license": "MIT",
"homepage": "https://example.com"
}</code></pre>
<h3>Manifest Field Reference</h3>
<table>
<thead>
<tr>
<th>Field</th>
<th>Required</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>name</code></td>
<td>Yes</td>
<td>Tool identifier. Must start with a letter, lowercase, may contain hyphens/underscores. Pattern: <code>^[a-z][a-z0-9]*(?:[_-][a-z0-9]+)*$</code></td>
</tr>
<tr>
<td><code>version</code></td>
<td>Yes</td>
<td>Semantic version string (e.g. <code>"1.0.0"</code>)</td>
</tr>
<tr>
<td><code>description</code></td>
<td>Yes</td>
<td>What the tool does. This is shown to the AI so it knows when to use it.</td>
</tr>
<tr>
<td><code>parameters</code></td>
<td>Yes</td>
<td>JSON Schema object defining the tool's input parameters. Each property can have <code>type</code> (<code>string</code>, <code>number</code>, <code>boolean</code>, <code>array</code>), <code>description</code>, optional <code>enum</code>, and optional <code>default</code>.</td>
</tr>
<tr>
<td><code>returns</code></td>
<td>Yes</td>
<td>Object with <code>type</code> (<code>"string"</code> or <code>"object"</code>) and <code>description</code> of the output.</td>
</tr>
<tr>
<td><code>execution.argStyle</code></td>
<td>Yes</td>
<td>How arguments are passed: <code>"positional"</code> (ordered args), <code>"cli"</code> (--flag value), or <code>"json"</code> (JSON via stdin).</td>
</tr>
<tr>
<td><code>execution.fileAccess</code></td>
<td>Yes</td>
<td>File system access level: <code>"none"</code>, <code>"read"</code>, <code>"write"</code>, or <code>"readwrite"</code>.</td>
</tr>
<tr>
<td><code>execution.timeout</code></td>
<td>No</td>
<td>Maximum execution time in milliseconds (default: 30000).</td>
</tr>
<tr>
<td><code>execution.memoryLimit</code></td>
<td>No</td>
<td>Maximum WASM memory in pages (each page = 64 KB).</td>
</tr>
<tr>
<td><code>pipeable</code></td>
<td>No</td>
<td>If <code>true</code>, the tool is registered as a pipeable command and can participate in pipe chains. The primary text input parameter receives piped stdin. Default: <code>false</code>.</td>
</tr>
<tr>
<td><code>category</code></td>
<td>Yes</td>
<td>Tool category (e.g. <code>"crypto"</code>, <code>"text"</code>, <code>"data"</code>, <code>"file"</code>, <code>"code"</code>).</td>
</tr>
<tr>
<td><code>author</code></td>
<td>No</td>
<td>Author name.</td>
</tr>
<tr>
<td><code>license</code></td>
<td>No</td>
<td>License identifier (e.g. <code>"MIT"</code>).</td>
</tr>
<tr>
<td><code>homepage</code></td>
<td>No</td>
<td>URL for the tool's homepage or repository.</td>
</tr>
</tbody>
</table>
<h3>Argument Styles Explained</h3>
<ul>
<li><strong><code>positional</code></strong> — Arguments are passed as ordered command-line arguments: <code>[tool_name, arg1, arg2, ...]</code> based on the order defined in <code>required</code>.</li>
<li><strong><code>cli</code></strong> — Arguments are passed as CLI flags: <code>[tool_name, --key, value, --key, value]</code>.</li>
<li><strong><code>json</code></strong> — Arguments are serialized as a JSON object and passed via <strong>stdin</strong>.</li>
</ul>
<!-- Compiling -->
<h2 id="compiling">Compiling to WebAssembly</h2>
<h3>C/C++ with WASI SDK</h3>
<p>The recommended approach for C/C++ tools. Install the <a href="https://github.com/WebAssembly/wasi-sdk/releases/tag/wasi-sdk-24" target="_blank" rel="noopener">WASI SDK v24</a>:</p>
<pre><code># Download WASI SDK v24 (or check releases for newer versions)
# https://github.com/WebAssembly/wasi-sdk/releases/tag/wasi-sdk-24
export WASI_SDK_PATH=/path/to/wasi-sdk
# Compile a C program to WASM
$WASI_SDK_PATH/bin/clang \
--target=wasm32-wasi \
-O2 \
-o my-tool.wasm \
main.c</code></pre>
<div class="callout callout-warning">
<p><strong>Important:</strong> Do <em>not</em> use the <code>--no-entry</code> flag for WASI programs with a <code>main()</code> function. WASI programs export <code>_start</code> as the entry point, which calls <code>main()</code>.</p>
</div>
<h3>Example Makefile</h3>
<pre><code>WASI_SDK_PATH ?= /opt/wasi-sdk
CC = $(WASI_SDK_PATH)/bin/clang
CFLAGS = --target=wasm32-wasi -O2
LDFLAGS = -Wl,--export-all
OUTPUT_DIR = ../../binaries
all: $(OUTPUT_DIR)/my-tool.wasm
$(OUTPUT_DIR)/my-tool.wasm: main.c | $(OUTPUT_DIR)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $<
$(OUTPUT_DIR):
mkdir -p $(OUTPUT_DIR)
clean:
rm -f $(OUTPUT_DIR)/my-tool.wasm</code></pre>
<h3>Rust</h3>
<p>Rust has first-class WASM support via the <code>wasm32-wasi</code> target:</p>
<pre><code># Add the WASI target
rustup target add wasm32-wasi
# Build your project
cargo build --release --target wasm32-wasi
# The binary will be at:
# target/wasm32-wasi/release/your_tool.wasm</code></pre>
<h3>Go (via TinyGo)</h3>
<p>Co-do runs WebAssembly modules in a WASI runtime. To build Go tools that are compatible with WASI (and therefore with Co-do), use <a href="https://tinygo.org/" target="_blank" rel="noopener">TinyGo</a> with the WASI target:</p>
<pre><code># Build using TinyGo with the WASI target (required for Co-do)
tinygo build -o my-tool.wasm -target=wasi main.go</code></pre>
<div class="callout callout-warning">
<p><strong>Important:</strong> The standard Go WebAssembly target (<code>GOOS=js GOARCH=wasm</code>) produces binaries that require the <code>wasm_exec.js</code> JavaScript shim and are designed for browser/JavaScript environments, not WASI. These binaries will <strong>not</strong> run in Co-do's WASI runtime. Always use TinyGo with <code>-target=wasi</code> when building Go tools for Co-do.</p>
</div>
<!-- Packaging -->
<h2 id="packaging">Creating the ZIP Package</h2>
<p>Once you have your compiled <code>.wasm</code> binary and your <code>manifest.json</code>, create the ZIP:</p>
<pre><code># Create a ZIP containing both files
zip my-tool.zip manifest.json my-tool.wasm</code></pre>
<p>Or if you're using the Co-do build system:</p>
<pre><code># From the wasm-tools directory, the build script handles this automatically
./build.sh my-tool
# Packages are output to wasm-tools/dist/
# Each tool gets: my-tool.zip, my-tool.manifest.json</code></pre>
<div class="callout callout-success">
<p><strong>Tip:</strong> The Co-do repository includes a full build system at <code>wasm-tools/build.sh</code> that automatically downloads the WASI SDK, compiles tools, generates manifests, and creates ZIP packages.</p>
</div>
<!-- Installing -->
<h2 id="installing">Installing in Co-do</h2>
<ol>
<li>Open Co-do and click the <strong>Settings</strong> gear icon in the header.</li>
<li>Scroll to the <strong>WebAssembly Tools</strong> section.</li>
<li>Click the <strong>Install Tool</strong> button.</li>
<li>Select your <code>.zip</code> package file.</li>
<li>The tool is validated, stored in your browser's IndexedDB, and immediately available to the AI.</li>
</ol>
<p>
Installed tools appear in the WebAssembly Tools list where you can <strong>enable/disable</strong>
or <strong>delete</strong> them. Each tool's permission defaults to <em>"Ask Each Time"</em>,
meaning the AI will request your approval before running it.
</p>
<!-- Execution -->
<h2 id="execution">How Tools Run</h2>
<p>When the AI invokes your tool, Co-do executes it in one of two modes:</p>
<ul>
<li><strong>Web Worker (default)</strong> — For tools with <code>"fileAccess": "none"</code>. The WASM binary runs in an isolated Web Worker thread, keeping the UI responsive. Network access is blocked.</li>
<li><strong>Main Thread</strong> — For tools that need file system access (<code>"read"</code>, <code>"write"</code>, <code>"readwrite"</code>). These tools can access the opened project directory through a virtual file system bridge.</li>
</ul>
<h3>I/O Model</h3>
<ul>
<li><strong>stdout</strong> — Captured and returned to the AI as the tool result.</li>
<li><strong>stderr</strong> — Captured and included in the result for error reporting.</li>
<li><strong>stdin</strong> — Used to pass JSON input when <code>argStyle</code> is <code>"json"</code>.</li>
<li><strong>Exit code</strong> — A non-zero exit code indicates failure.</li>
</ul>
<h3>WASI Compatibility Notes</h3>
<ul>
<li>Use standard C library functions (<code>stdio.h</code>, <code>string.h</code>, <code>stdlib.h</code>, etc.).</li>
<li>File system access is sandboxed to the project directory only.</li>
<li>Network access is not available from within WASM tools.</li>
<li>Time functions work but may have limited resolution.</li>
</ul>
<!-- Pipeable Commands -->
<h2 id="pipeable">Pipeable Commands</h2>
<p>
WASM tools can participate in <strong>pipe chains</strong>, where the output of one command
flows as input to the next — just like Unix pipes. To make your tool pipeable, add
<code>"pipeable": true</code> to your <code>manifest.json</code>.
</p>
<div class="callout callout-info">
<p><strong>Not all tools are pipeable.</strong> Only tools that accept text input and produce
text output are good candidates. Tools that require multiple non-text inputs, produce binary
output, or have no natural stdin concept should omit this field (or set it to <code>false</code>).</p>
</div>
<h3>How It Works</h3>
<p>
When a tool is marked as pipeable, Co-do automatically registers it in the
<strong>pipe command registry</strong>. In a pipe chain, the output of the previous command
is injected as the tool's primary text input parameter (typically named <code>input</code>).
All other parameters can still be passed explicitly via <code>args</code>.
</p>
<h3>Manifest Example</h3>
<pre><code>{
"name": "base64",
"version": "1.0.0",
"description": "Encode or decode data using Base64 encoding.",
"parameters": {
"type": "object",
"properties": {
"mode": {
"type": "string",
"enum": ["encode", "decode"],
"description": "Whether to encode or decode"
},
"input": {
"type": "string",
"description": "The text to encode, or base64 string to decode"
}
},
"required": ["mode", "input"]
},
"returns": { "type": "string", "description": "The encoded or decoded result" },
"execution": { "argStyle": "positional", "fileAccess": "none", "timeout": 5000 },
<strong>"pipeable": true,</strong>
"category": "crypto"
}</code></pre>
<h3>Pipe Usage Example</h3>
<p>With <code>pipeable: true</code>, the AI can chain your tool with other commands:</p>
<pre><code>// Read a file, then base64-encode the content
{
"commands": [
{ "tool": "cat", "args": { "path": "secret.txt" } },
{ "tool": "base64", "args": { "mode": "encode" } }
]
}
// Decode base64 content, then count lines
{
"commands": [
{ "tool": "base64", "args": { "mode": "decode", "input": "SGVsbG8KV29ybGQ=" } },
{ "tool": "wc", "args": {} }
]
}</code></pre>
<h3>Stdin Parameter Resolution</h3>
<p>
Co-do determines which parameter receives piped input using these rules (in order):
</p>
<ol>
<li>A required <code>string</code> parameter named <code>input</code> or <code>text</code></li>
<li>The first required <code>string</code> parameter</li>
<li>An optional parameter named <code>input</code> or <code>text</code></li>
</ol>
<p>
When piped input is available and the resolved parameter is not explicitly provided
in <code>args</code>, the piped input is automatically injected.
</p>
<h3>When to Use <code>pipeable</code></h3>
<table>
<thead>
<tr>
<th>Good Candidates</th>
<th>Not Suitable</th>
</tr>
</thead>
<tbody>
<tr>
<td>Text processors (grep, sed, awk, sort)</td>
<td>Multi-input tools (diff requires two texts)</td>
</tr>
<tr>
<td>Encoders/decoders (base64, xxd)</td>
<td>Generators with no input (uuid)</td>
</tr>
<tr>
<td>Format converters (toml2json, markdown)</td>
<td>Binary I/O tools (gzip)</td>
</tr>
<tr>
<td>Code formatters (shfmt, minify)</td>
<td>Database engines (sqlite3)</td>
</tr>
<tr>
<td>Hash functions (md5sum, sha256sum)</td>
<td>File metadata tools (stat, du)</td>
</tr>
</tbody>
</table>
<!-- Limits -->
<h2 id="limits">Limits & Security</h2>
<table>
<thead>
<tr>
<th>Constraint</th>
<th>Limit</th>
</tr>
</thead>
<tbody>
<tr>
<td>Maximum ZIP file size</td>
<td>50 MB</td>
</tr>
<tr>
<td>Maximum WASM binary size</td>
<td>20 MB</td>
</tr>
<tr>
<td>Maximum files in ZIP</td>
<td>100</td>
</tr>
<tr>
<td>Default execution timeout</td>
<td>30 seconds (configurable per-tool)</td>
</tr>
<tr>
<td>WASM magic number</td>
<td>Must start with <code>00 61 73 6d</code> (<code>\0asm</code>)</td>
</tr>
</tbody>
</table>
<p>Additional security measures:</p>
<ul>
<li><strong>Path traversal protection</strong> — ZIP entries with <code>..</code> or absolute paths are rejected.</li>
<li><strong>Schema validation</strong> — Manifests are validated against a strict Zod schema before installation.</li>
<li><strong>Permission system</strong> — Users control per-tool execution permissions (<em>Always Allow</em>, <em>Ask Each Time</em>, or <em>Never Allow</em>).</li>
<li><strong>Worker isolation</strong> — Tools without file access run in isolated Web Workers.</li>
</ul>
<!-- Examples -->
<h2 id="examples">Example: Base64 Tool</h2>
<p>Here's a complete example of a simple base64 encode/decode tool written in C.</p>
<h3>Source Code (<code>main.c</code>)</h3>
<pre><code>#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static const char b64_table[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static int b64_index(char c) {
if (c >= 'A' && c <= 'Z') return c - 'A';
if (c >= 'a' && c <= 'z') return c - 'a' + 26;
if (c >= '0' && c <= '9') return c - '0' + 52;
if (c == '+') return 62;
if (c == '/') return 63;
return -1;
}
void encode(const char *input) {
size_t len = strlen(input);
for (size_t i = 0; i < len; i += 3) {
unsigned char b0 = input[i];
unsigned char b1 = (i + 1 < len) ? input[i + 1] : 0;
unsigned char b2 = (i + 2 < len) ? input[i + 2] : 0;
putchar(b64_table[b0 >> 2]);
putchar(b64_table[((b0 & 0x03) << 4) | (b1 >> 4)]);
putchar((i + 1 < len) ? b64_table[((b1 & 0x0f) << 2) | (b2 >> 6)] : '=');
putchar((i + 2 < len) ? b64_table[b2 & 0x3f] : '=');
}
putchar('\n');
}
void decode(const char *input) {
size_t len = strlen(input);
for (size_t i = 0; i < len; i += 4) {
int a = b64_index(input[i]);
int b = b64_index(input[i + 1]);
int c = (i + 2 < len && input[i + 2] != '=') ? b64_index(input[i + 2]) : 0;
int d = (i + 3 < len && input[i + 3] != '=') ? b64_index(input[i + 3]) : 0;
if (a < 0 || b < 0) break;
putchar((a << 2) | (b >> 4));
if (i + 2 < len && input[i + 2] != '=')
putchar(((b & 0x0f) << 4) | (c >> 2));
if (i + 3 < len && input[i + 3] != '=')
putchar(((c & 0x03) << 6) | d);
}
putchar('\n');
}
int main(int argc, char **argv) {
if (argc < 3) {
fprintf(stderr, "Usage: base64 <encode|decode> <input>\n");
return 1;
}
if (strcmp(argv[1], "encode") == 0) {
encode(argv[2]);
} else if (strcmp(argv[1], "decode") == 0) {
decode(argv[2]);
} else {
fprintf(stderr, "Unknown mode: %s\n", argv[1]);
return 1;
}
return 0;
}</code></pre>
<h3>Manifest (<code>manifest.json</code>)</h3>
<pre><code>{
"name": "base64",
"version": "1.0.0",
"description": "Encode or decode data using Base64 encoding. Use 'encode' to convert text to Base64, or 'decode' to convert Base64 back to text.",
"parameters": {
"type": "object",
"properties": {
"mode": {
"type": "string",
"enum": ["encode", "decode"],
"description": "Whether to encode or decode"
},
"input": {
"type": "string",
"description": "The text to encode, or base64 string to decode"
}
},
"required": ["mode", "input"]
},
"returns": {
"type": "string",
"description": "The encoded or decoded result"
},
"execution": {
"argStyle": "positional",
"fileAccess": "none",
"timeout": 5000
},
"category": "crypto",
"author": "Co-do",
"license": "MIT"
}</code></pre>
<h3>Build & Package</h3>
<pre><code># Compile
$WASI_SDK_PATH/bin/clang --target=wasm32-wasi -O2 -o base64.wasm main.c
# Package
zip base64.zip manifest.json base64.wasm
# Install via Co-do UI: Settings → WebAssembly Tools → Install Tool</code></pre>
<!-- Source Code -->
<h2 id="source-code">Source Code</h2>
<p>
Co-do is open source. The WebAssembly tool system's source code, including the loader,
runtime, and example tools, is available on GitHub:
</p>
<p>
<a href="https://github.com/PaulKinlan/Co-do" target="_blank" rel="noopener" class="source-link">
<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
<path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z"/>
</svg>
github.com/PaulKinlan/Co-do
</a>
</p>
<h3>Key Source Files</h3>
<table>
<thead>
<tr>
<th>File</th>
<th>Purpose</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>src/wasm-tools/loader.ts</code></td>
<td>ZIP loading, validation, and manifest parsing</td>
</tr>
<tr>
<td><code>src/wasm-tools/manager.ts</code></td>
<td>Tool lifecycle management and execution</td>
</tr>
<tr>
<td><code>src/wasm-tools/types.ts</code></td>
<td>TypeScript interfaces and Zod schemas</td>
</tr>
<tr>
<td><code>src/wasm-tools/runtime.ts</code></td>
<td>WASM execution runtime environment</td>
</tr>
<tr>
<td><code>src/wasm-tools/vfs.ts</code></td>
<td>Virtual file system for sandboxed I/O</td>
</tr>
<tr>
<td><code>src/wasm-tools/worker-manager.ts</code></td>
<td>Web Worker isolation for tool execution</td>
</tr>
<tr>
<td><code>wasm-tools/build.sh</code></td>
<td>Automated build script for all tools</td>
</tr>
<tr>
<td><code>wasm-tools/src/</code></td>
<td>Source code for built-in tools (C)</td>
</tr>
<tr>
<td><code>wasm-tools/manifests/</code></td>
<td>Manifest files for built-in tools</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>