interplane.Get Omega
Read in your language

synapse-mcp

aien-dev/synapse-mcp

Brought by drakestapleton

GitHub aien-dev/synapse-mcp#4 (code only)

closed derived a2b48547621a864e #4

Imported from GitHub aien-dev/synapse-mcp#4 (code only)

GitHub's metadata for this pull request is unavailable: its state is DERIVED from the commits (merged: the head is reachable from this project's main; open: GitHub kept a merge ref; else closed).

Base c496ff884b11b54c90868ed5e5421676d0da7c53 · Head 8d9830ba549f2fd7a3f12d2db45fdb002061bec7

Apply it

git checkout -b patch-a2b48547621a864e c496ff884b11b54c90868ed5e5421676d0da7c53
curl -fsSL https://interplane.io/drakestapleton/synapse-mcp/patches/a2b48547621a864e.patch | git am

Raw patch (mbox) · Diff

Provenance

This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record:

github-import 1
aien-dev/synapse-mcp
4
8d9830ba549f2fd7a3f12d2db45fdb002061bec7
{"kind":"github-import","owner":"aien-dev","repo":"synapse-mcp","number":4,"url":"https://github.com/aien-dev/synapse-mcp/pull/4","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:41:01Z","metadata":"unavailable","state_derived":true}

Changes

diff --git a/README.md b/README.md
index 10c0db6..0c1b546 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@ Part of [aien-dev/synapse](https://github.com/aien-dev/synapse) (pinned in `syna
 
 # synapse-mcp
 
-WIP (parked 2026-10-27): MCP stdio server in seeded Omega (`src/*.om`) exposing the coordination CLIs as tools. Not yet compiled; tests not written. See AGENTS.md.
+WIP (parked 2026-10-27): MCP stdio server in seeded Omega (`src/*.om`) exposing the coordination CLIs as tools. Compiles with the pinned omc (`sh build.sh OMEGA_SRC OUT`); `OMEGA_SRC=… sh tests/run.sh` drives it over stdio against the fake CLIs in `tests/fake` and compares every response byte for byte. Not yet run against the real synapse-* CLIs. See AGENTS.md.
 
 ## Connected repos
 - Parent: aien-dev/synapse
diff --git a/src/00base.om b/src/00base.om
index 9a12ae6..e369086 100644
--- a/src/00base.om
+++ b/src/00base.om
@@ -54,7 +54,7 @@ d = new uchar 24 0
 k = ulong 0
 x = v
 while true bound 24
-put d k uchar add 48 mod x 10
+put d k uchar add 48 rem x 10
 k = add k 1
 x = div x 10
 if eq x 0
@@ -202,6 +202,16 @@ end
 ret k
 end
 
+note syn_rderr: first stderr bytes of fd e into gerrb, count in gerrn 0 (a global cannot be an argument)
+fn syn_rderr e int to void
+eb = new uchar 8192 0
+k = syn_rdall e eb len eb
+for i ulong k
+put gerrb i get eb i
+end
+put gerrn 0 k
+end
+
 note syn_run: run the packed list in gav (first record an absolute path, never a shell)
 note child stdin /dev/null, stdout and stderr captured in memfds; out gets up to len out bytes.
 note gxs 0: exit code 0..255, 300+signal, 400 timeout (killed), 401 fork or memfd failure
@@ -261,8 +271,7 @@ put gxs 1 sz
 r = fseek m 0 0
 n = syn_rdall m obf len obf
 r = fseek e 0 0
-k = syn_rdall e gerrb len gerrb
-put gerrn 0 k
+syn_rderr e
 r = fclose m
 r = fclose e
 ret n
@@ -281,7 +290,9 @@ if gt m 2
 mm = sub m 3
 end
 doy = add div add mul 153 mm 2 5 sub d 1
-doe = add sub add mul yoe 365 div yoe 4 div yoe 100 doy
+doe = add mul yoe 365 div yoe 4
+doe = sub doe div yoe 100
+doe = add doe doy
 ret sub add mul era 146097 doe 719468
 end
 
@@ -310,18 +321,20 @@ put gxs 2 0
 ret 0
 end
 dd = syn_days y mo d
-ret add add add mul dd 86400 mul h 3600 mul mi 60 s
+r = add mul dd 86400 mul h 3600
+r = add r mul mi 60
+ret add r s
 end
 
 fn syn_p2 v ulong to void
 syn_pb uchar add 48 div v 10
-syn_pb uchar add 48 mod v 10
+syn_pb uchar add 48 rem v 10
 end
 
 note syn_tsw: append epoch seconds t as YYYY-MM-DDTHH:MM:SSZ to the pool
 fn syn_tsw t ulong to void
 z = add div t 86400 719468
-sd = mod t 86400
+sd = rem t 86400
 era = div z 146097
 doe = sub z mul era 146097
 yoe = div sub add sub doe div doe 1460 div doe 36524 div doe 146096 365
@@ -344,16 +357,16 @@ syn_p2 d
 syn_pb 84
 syn_p2 div sd 3600
 syn_pb 58
-syn_p2 div mod sd 3600 60
+syn_p2 div rem sd 3600 60
 syn_pb 58
-syn_p2 mod sd 60
+syn_p2 rem sd 60
 syn_pb 90
 end
 
 note syn_arg: copy argument i into the pool; returns its offset, gxs 2 its length
 fn syn_arg i ulong to ulong
 b = new uchar 4096 0
-n = argread int i b 0 len b
+n = argread i b 0 len b
 if lt n 0
 put gxs 2 0
 ret get gspn 0
diff --git a/src/10mcp.om b/src/10mcp.om
index dd6a613..0bc7480 100644
--- a/src/10mcp.om
+++ b/src/10mcp.om
@@ -5,6 +5,12 @@ global gopl ulong 4
 global gid ulong 2
 global gbad ulong 2
 global gq ulong 4
+note gobj 0: JSON object token searched by mc_get and pu_memb2; gv 0: value token found by mc_get
+note gnm 0: offset of the tool name for mc_build (omc allows six parameter slots; a sized-* view takes two)
+global gobj ulong 1
+global gv ulong 1
+global gnm ulong 1
+global gln ulong 2
 
 text musage "usage: synapse-mcp --bin-dir DIR [--home DIR]"
 text mbindir "--bin-dir"
@@ -14,7 +20,7 @@ text menvhm "HOME="
 text mdhome "/.local/state/aien-coord"
 text mnohome "synapse-mcp: no --home, AIEN_COORD_HOME or HOME"
 text mnobin "synapse-mcp: --bin-dir must be an absolute directory"
-text mempty ""
+text mtrunc "[stdout truncated at 1048576 bytes]\n"
 text mkjrpc "jsonrpc"
 text mk20 "2.0"
 text mkid "id"
@@ -48,7 +54,7 @@ text mmeinv "Invalid Request"
 text mmenome "Method not found"
 text mmeparm "Invalid params"
 text mmetool "Unknown tool"
-text mbadarg "Invalid params: bad or missing argument "
+text mbadarg "Invalid params: bad or missing argument"
 text mbadunk "Invalid params: unknown argument"
 text mbadlong "Invalid params: arguments too long"
 text mbadobj "Invalid params: arguments must be an object"
@@ -112,6 +118,7 @@ text mslbcl "/board/claims.jsonl"
 text mslmap "/map.jsonl"
 text mslfind "/pulse/findings.jsonl"
 text mlisterr "synapse-mcp: synapse-claims list --all failed; board not rendered"
+text mwrerr "synapse-mcp: could not write HOME/board/claims.jsonl; board not rendered"
 
 text mtn01 "coord_where"
 text mtn02 "coord_tree"
@@ -206,6 +213,13 @@ mc_qb get a add o i
 end
 end
 
+note mc_qerr: JSON-escape the captured stderr (gerrb, gerrn 0 bytes); a global cannot be an argument
+fn mc_qerr to void
+for i ulong get gerrn 0
+mc_qb get gerrb i
+end
+end
+
 fn mc_qt t view uchar * to void
 for i ulong len t
 mc_qb get t i
@@ -334,46 +348,63 @@ syn_at f
 ret true
 end
 
-note mc_get: value token for key in args object a, or jsnone; counts the key as consumed
-fn mc_get src view uchar * tape view uint * a ulong key view uchar * to ulong
+note mc_get: gv 0 = value token for key in args object gobj 0, or jsnone; counts the key as consumed
+fn mc_get src view uchar * tape view uint * key view uchar * to void
+put gv 0 jsnone
+a = get gobj 0
 if eq a jsnone
-ret jsnone
+ret
 end
 k = js_first tape a
 while ne k jsnone bound 999999
 if js_streq src js_off tape k key
 put gq 0 add get gq 0 1
-ret add k 1
+put gv 0 add k 1
+ret
 end
 k = js_mnext tape k
 end
-ret jsnone
 end
 
-note mc_str: string argument key as option flag (or positional when flag is empty); req: must be present
-fn mc_str src view uchar * tape view uint * a ulong tmp edit uchar * key view uchar * flag view uchar * to void
-v = mc_get src tape a key
+note mc_sval: string value of gv 0 into tmp; its length, or -1 when absent or refused; req: must be present
+fn mc_sval src view uchar * tape view uint * tmp edit uchar * to long
+v = get gv 0
 if eq v jsnone
 if eq get gq 1 1
 mc_bad 0 1
 end
 put gq 1 0
-ret
+ret -1
 end
 put gq 1 0
 if ne js_type tape v jsstr
 mc_bad 0 1
-ret
+ret -1
 end
 n = js_sget src js_off tape v tmp
 if lt n 0
 mc_bad 0 1
+ret -1
+end
+ret n
+end
+
+note mc_semit: string argument from mc_sval (n bytes of tmp) as option flag + value
+fn mc_semit tmp view uchar * n long flag view uchar * to void
+if lt n 0
 ret
 end
-if gt len flag 0
 if not mc_flag flag
 ret
 end
+mc_spos tmp n
+end
+
+note mc_spos: string argument from mc_sval as one positional record (omc e5b32567 gives an empty text a
+note wrong length, omega-mv #775, so positionals do not pass an empty flag text)
+fn mc_spos tmp view uchar * n long to void
+if lt n 0
+ret
 end
 if not mc_val tmp ulong n
 mc_bad 0 1
@@ -381,8 +412,8 @@ end
 end
 
 note mc_int: integer argument (JSON unsigned integer >= 1) as option flag
-fn mc_int src view uchar * tape view uint * a ulong key view uchar * flag view uchar * to void
-v = mc_get src tape a key
+fn mc_int src view uchar * tape view uint * flag view uchar * to void
+v = get gv 0
 if eq v jsnone
 ret
 end
@@ -409,8 +440,8 @@ syn_rew m
 end
 
 note mc_bool: boolean argument; true adds the flag
-fn mc_bool src view uchar * tape view uint * a ulong key view uchar * flag view uchar * to void
-v = mc_get src tape a key
+fn mc_bool tape view uint * flag view uchar * to void
+v = get gv 0
 if eq v jsnone
 ret
 end
@@ -424,9 +455,9 @@ mc_bad 0 1
 end
 end
 
-note mc_arr: array of strings; each element becomes flag + value
-fn mc_arr src view uchar * tape view uint * a ulong tmp edit uchar * key view uchar * flag view uchar * to void
-v = mc_get src tape a key
+note mc_evid: array of strings; each element becomes --evidence-style flag mfevid + value
+fn mc_evid src view uchar * tape view uint * tmp edit uchar * to void
+v = get gv 0
 if eq v jsnone
 ret
 end
@@ -445,7 +476,7 @@ if lt n 0
 mc_bad 0 1
 ret
 end
-if not mc_flag flag
+if not mc_flag mfevid
 ret
 end
 if not mc_val tmp ulong n
@@ -456,7 +487,7 @@ e = js_enext tape e
 end
 end
 
-note mc_req1: mark the next mc_str as required
+note mc_req1: mark the next mc_sval as required
 fn mc_req1 to void
 put gq 1 1
 end
@@ -510,22 +541,34 @@ note mc_runap: run gav, append stdout, exit line and (on failure) stderr, all JS
 fn mc_runap obf edit uchar * to ulong
 n = syn_run obf 300000000000
 c = ulong get gxs 0
-mc_qa obf 0 n
-if and gt n 0 ne get obf sub n 1 10
-mc_qb 10
+mc_rout obf n c
+ret c
 end
+
+note mc_rout: append n bytes of stdout, the exit line and (on failure) stderr of the last syn_run
+fn mc_rout obf view uchar * n ulong c ulong to void
+mc_qnl obf n
 mc_qt mexitc
 syn_pd c
 mc_qt mcl
 mc_qb 10
 if gt get gxs 1 long n
-text mtrunc "[stdout truncated at 1048576 bytes]\n"
 mc_qt mtrunc
 end
 if ne c 0
-mc_qa gerrb 0 get gerrn 0
+mc_qerr
+end
+end
+
+note mc_qnl: append obf[0..n) JSON-escaped, ending with a newline when it is not empty
+note (and is eager in Omega, so the n > 0 guard is a separate if)
+fn mc_qnl obf view uchar * n ulong to void
+mc_qa obf 0 n
+if gt n 0
+if ne get obf sub n 1 10
+mc_qb 10
+end
 end
-ret c
 end
 
 fn mc_tail c ulong to void
@@ -535,7 +578,7 @@ syn_pt mtrue
 else
 syn_pt mfalse
 end
-syn_pt mrclose
+syn_pb 125
 syn_pb 125
 syn_pb 10
 end
@@ -552,51 +595,77 @@ mc_flush m
 end
 
 note coord_where: map where, then claims who repo:R for the first three result repos
-fn mc_where src view uchar * tape edit uint * a ulong tmp edit uchar * to void
+fn mc_where src view uchar * tape edit uint * tmp edit uchar * to void
+a = get gobj 0
 mc_bin mbmap true
 syn_at mcwhere
 mc_req1
-mc_str src tape a tmp maktask mempty
-mc_int src tape a maklimit mflimit
+mc_get src tape maktask
+sv = mc_sval src tape tmp
+mc_spos tmp sv
+mc_get src tape maklimit
+mc_int src tape mflimit
 if not mc_done tape a
 ret
 end
+mc_wrun tape tmp
+end
+
+note mc_wrun: second half of coord_where (split out to stay within omc's 16 registers). The who targets are
+note collected in the pool before the response starts, so they never land inside it.
+fn mc_wrun tape edit uint * tmp edit uchar * to void
 obf = new uchar 1048576 0
+n = syn_run obf 300000000000
+c = ulong get gxs 0
+r = js_init tape 65536 16
+rp = syn_mark
+k = mc_wscan part obf 0 n tape tmp
 m = mc_head
 syn_pt mrres
 syn_pt mrtext
-c = mc_runap obf
-n = ulong get gxs 1
-if gt n len obf
-n = len obf
+mc_rout obf n c
+mc_who3 obf rp k
+mc_tail c
+mc_flush m
+syn_rew rp
 end
-r = js_init tape 65536 16
-rp = syn_mark
+
+note mc_wscan: per newline-terminated line of out (first three with a repo), mc_wrepo; returns how many appended
+fn mc_wscan lns view uchar * tape edit uint * tmp edit uchar * to ulong
+n = len lns
 k = ulong 0
 s = ulong 0
 for i ulong add n 1
-if or eq i n eq get obf min i sub len obf 1 10
+nl = eq i n
+if not nl
+nl = eq get lns i 10
+end
+if nl
 if and gt i s lt k 3
-q = js_parse part obf s sub i s tape sub i s
+k = add k mc_wrepo part lns s sub i s tape tmp
+end
+s = add i 1
+end
+end
+ret k
+end
+
+note mc_wrepo: when line ln parses and has a string "repo", append "claims who repo:R" target; 1 if appended
+fn mc_wrepo ln view uchar * tape edit uint * tmp edit uchar * to ulong
+q = js_parse ln tape len ln
 if gt q 0
-v = pu_rmemb part obf s sub i s tape mkrepo
+v = pu_rmemb ln tape mkrepo
 if and ne v jsnone eq js_type tape v jsstr
-x = js_sget part obf s sub i s js_off tape v tmp
+x = js_sget ln js_off tape v tmp
 if gt x 0
 syn_pt mrepoc
 syn_pa tmp 0 ulong x
 syn_pb 10
-k = add k 1
-end
+ret 1
 end
 end
 end
-s = add i 1
-end
-end
-mc_who3 obf rp k
-mc_tail c
-mc_flush m
+ret 0
 end
 
 note pu_rmemb: value token of key in the root object, or jsnone
@@ -632,10 +701,7 @@ end
 fn mc_who1 obf edit uchar * p ulong e ulong to void
 n = syn_run obf 300000000000
 c = ulong get gxs 0
-mc_qa obf 0 n
-if and gt n 0 ne get obf sub n 1 10
-mc_qb 10
-end
+mc_qnl obf n
 mc_qt mwhoc
 mc_qp p e
 mc_qt mwhoe
@@ -643,7 +709,7 @@ syn_pd c
 mc_qt mcl
 mc_qb 10
 if ne c 0
-mc_qa gerrb 0 get gerrn 0
+mc_qerr
 end
 end
 
@@ -664,7 +730,7 @@ c = ulong get gxs 0
 if or ne c 0 gt get gxs 1 long n
 mc_qt mlisterr
 mc_qb 10
-mc_qa gerrb 0 get gerrn 0
+mc_qerr
 mc_tail 70
 mc_flush m
 ret
@@ -674,31 +740,26 @@ syn_ps get gop 1 get gopl 1
 syn_pt mslboard
 r = syn_mkdir d syn_len d
 syn_rew d
-mc_bpath mslbcl
-fd = syn_wbeg get gq 2 get gq 3
-if ge fd 0
-w = write int fd obf 0 n
-r = syn_wend fd get gq 2 get gq 3
+if not mc_bwrite obf n
+mc_qt mwrerr
+mc_qb 10
+mc_tail 70
+mc_flush m
+ret
 end
 mc_bin mbboard false
 syn_at mcrender
-syn_at mfclaims
-syn_ap get gq 2 get gq 3
-syn_at mfmap
-mc_bpath mslmap
-syn_ap get gq 2 get gq 3
-syn_at mffind
-mc_bpath mslfind
-syn_ap get gq 2 get gq 3
-syn_at mfout
-mc_bpath mslboard
-syn_ap get gq 2 get gq 3
+mc_barg mfclaims mslbcl
+mc_barg mfmap mslmap
+mc_barg mffind mslfind
+mc_barg mfout mslboard
 c = mc_runap obf
 mc_tail c
 mc_flush m
 end
 
-note mc_bpath: HOME + suffix t appended to the pool; gq 2, 3 = offset, length
+note mc_bpath: HOME + suffix t appended to the pool; gq 2, 3 = offset, length. The pool also holds the
+note response being built, so every caller rewinds to gq 2 once the path is used.
 fn mc_bpath t view uchar * to void
 p = syn_mark
 syn_ps get gop 1 get gopl 1
@@ -707,8 +768,31 @@ put gq 2 p
 put gq 3 syn_len p
 end
 
+note mc_barg: argv records flag f and HOME + suffix t
+fn mc_barg f view uchar * t view uchar * to void
+syn_at f
+mc_bpath t
+syn_ap get gq 2 get gq 3
+syn_rew get gq 2
+end
+
+note mc_bwrite: write obf[0..n) to HOME/board/claims.jsonl (temp file, sync, rename); false on any failure
+fn mc_bwrite obf view uchar * n ulong to bool
+mc_bpath mslbcl
+fd = syn_wbeg get gq 2 get gq 3
+if lt fd 0
+syn_rew get gq 2
+ret false
+end
+w = write int fd obf 0 n
+r = syn_wend fd get gq 2 get gq 3
+syn_rew get gq 2
+ret and eq w long n eq r 0
+end
+
 note ======== tools/call ========
-fn mc_call src view uchar * tape edit uint * p ulong tmp edit uchar * to void
+fn mc_call src view uchar * tape edit uint * tmp edit uchar * to void
+p = get gobj 0
 put gbad 0 0
 put gq 0 0
 put gq 1 0
@@ -716,12 +800,14 @@ if or eq p jsnone ne js_type tape p jsobj
 mc_err 32602 mmeparm
 ret
 end
-nt = pu_memb2 src tape p mkname
+put gobj 0 p
+nt = pu_memb2 src tape mkname
 if or eq nt jsnone ne js_type tape nt jsstr
 mc_err 32602 mmeparm
 ret
 end
-a = pu_memb2 src tape p mkargs
+a = pu_memb2 src tape mkargs
+put gobj 0 a
 if ne a jsnone
 if ne js_type tape a jsobj
 mc_err 32602 mbadobj
@@ -730,14 +816,15 @@ end
 end
 o = js_off tape nt
 if js_streq src o mtn01
-mc_where src tape a tmp
+mc_where src tape tmp
 ret
 end
 if js_streq src o mtn13
 mc_board tape a
 ret
 end
-if not mc_build src tape a tmp o
+put gnm 0 o
+if not mc_build src tape tmp
 mc_err 32602 mmetool
 ret
 end
@@ -746,7 +833,9 @@ mc_exec
 end
 end
 
-fn pu_memb2 src view uchar * tape view uint * o ulong key view uchar * to ulong
+note pu_memb2: value token of key in object gobj 0, or jsnone
+fn pu_memb2 src view uchar * tape view uint * key view uchar * to ulong
+o = get gobj 0
 k = js_first tape o
 while ne k jsnone bound 999999
 if js_streq src js_off tape k key
@@ -758,11 +847,13 @@ ret jsnone
 end
 
 note mc_build: argv for the single-exec tools; false for an unknown tool name
-fn mc_build src view uchar * tape view uint * a ulong tmp edit uchar * o ulong to bool
+fn mc_build src view uchar * tape view uint * tmp edit uchar * to bool
+o = get gnm 0
 if js_streq src o mtn02
 mc_bin mbmap true
 syn_at mctree
-mc_bool src tape a maktext mftext
+mc_get src tape maktext
+mc_bool tape mftext
 ret true
 end
 if js_streq src o mtn03
@@ -774,62 +865,98 @@ if js_streq src o mtn04
 mc_bin mbclaims true
 syn_at mcclaim
 mc_req1
-mc_str src tape a tmp makagent mfagent
+mc_get src tape makagent
+sv = mc_sval src tape tmp
+mc_semit tmp sv mfagent
 mc_req1
-mc_str src tape a tmp maksess mfsess
+mc_get src tape maksess
+sv = mc_sval src tape tmp
+mc_semit tmp sv mfsess
 mc_req1
-mc_str src tape a tmp maktarg mftarg
-mc_int src tape a makttl mfttl
-mc_str src tape a tmp makmode mfmode
-mc_str src tape a tmp makstate mfstate
-mc_str src tape a tmp makint mfint
-mc_arr src tape a tmp makevid mfevid
+mc_get src tape maktarg
+sv = mc_sval src tape tmp
+mc_semit tmp sv mftarg
+mc_get src tape makttl
+mc_int src tape mfttl
+mc_get src tape makmode
+sv = mc_sval src tape tmp
+mc_semit tmp sv mfmode
+mc_get src tape makstate
+sv = mc_sval src tape tmp
+mc_semit tmp sv mfstate
+mc_get src tape makint
+sv = mc_sval src tape tmp
+mc_semit tmp sv mfint
+mc_get src tape makevid
+mc_evid src tape tmp
 ret true
 end
 if js_streq src o mtn05
 mc_bin mbclaims true
 syn_at mcrenew
 mc_req1
-mc_str src tape a tmp makagent mfagent
+mc_get src tape makagent
+sv = mc_sval src tape tmp
+mc_semit tmp sv mfagent
 mc_req1
-mc_str src tape a tmp makid mfid
-mc_int src tape a makttl mfttl
+mc_get src tape makid
+sv = mc_sval src tape tmp
+mc_semit tmp sv mfid
+mc_get src tape makttl
+mc_int src tape mfttl
 ret true
 end
 if js_streq src o mtn06
 mc_bin mbclaims true
 syn_at mcrel
 mc_req1
-mc_str src tape a tmp makagent mfagent
+mc_get src tape makagent
+sv = mc_sval src tape tmp
+mc_semit tmp sv mfagent
 mc_req1
-mc_str src tape a tmp makid mfid
-mc_str src tape a tmp makstate mfstate
-mc_arr src tape a tmp makevid mfevid
+mc_get src tape makid
+sv = mc_sval src tape tmp
+mc_semit tmp sv mfid
+mc_get src tape makstate
+sv = mc_sval src tape tmp
+mc_semit tmp sv mfstate
+mc_get src tape makevid
+mc_evid src tape tmp
 ret true
 end
 if js_streq src o mtn07
 mc_bin mbclaims true
 syn_at mcstate
 mc_req1
-mc_str src tape a tmp makagent mfagent
+mc_get src tape makagent
+sv = mc_sval src tape tmp
+mc_semit tmp sv mfagent
 mc_req1
-mc_str src tape a tmp makid mfid
+mc_get src tape makid
+sv = mc_sval src tape tmp
+mc_semit tmp sv mfid
 mc_req1
-mc_str src tape a tmp makstate mfstate
-mc_arr src tape a tmp makevid mfevid
+mc_get src tape makstate
+sv = mc_sval src tape tmp
+mc_semit tmp sv mfstate
+mc_get src tape makevid
+mc_evid src tape tmp
 ret true
 end
 if js_streq src o mtn08
 mc_bin mbclaims true
 syn_at mcwho
 mc_req1
-mc_str src tape a tmp maktarg mempty
+mc_get src tape maktarg
+sv = mc_sval src tape tmp
+mc_spos tmp sv
 ret true
 end
 if js_streq src o mtn09
 mc_bin mbclaims true
 syn_at mclist
-mc_bool src tape a makall mfall
+mc_get src tape makall
+mc_bool tape mfall
 ret true
 end
 if js_streq src o mtn10
@@ -851,7 +978,8 @@ syn_ps get gop 0 get gopl 0
 syn_pt mbclaims
 syn_ap m syn_len m
 syn_rew m
-mc_bool src tape a makalert mfalert
+mc_get src tape makalert
+mc_bool tape mfalert
 ret true
 end
 if js_streq src o mtn14
@@ -859,7 +987,9 @@ mc_bin mbclaims true
 syn_at mclist
 syn_at mfprefix
 mc_req1
-mc_str src tape a tmp maklane mempty
+mc_get src tape maklane
+sv = mc_sval src tape tmp
+mc_spos tmp sv
 ret true
 end
 ret false
@@ -920,7 +1050,8 @@ mc_list
 else
 if js_streq src o mmcall
 pv = pu_rmemb src tape mkpar
-mc_call src tape pv tmp
+put gobj 0 pv
+mc_call src tape tmp
 else
 mc_err 32601 mmenome
 end
@@ -931,21 +1062,25 @@ syn_rew base
 end
 
 note ======== main ========
-fn mc_envopt i ulong t view uchar * s view uchar * to bool
-b = new uchar 8192 0
-for e ulong envcnt
-n = envread e b 0 len b
-if gt n long len t
-ok = true
+note mc_pre: b starts with t (caller checks the length)
+fn mc_pre b view uchar * t view uchar * to bool
 for j ulong len t
 if ne get b j get t j
-ok = false
+ret false
 end
 end
-if ok
+ret true
+end
+
+note mc_envopt: option i = the environment value after prefix t; false when no variable has that prefix
+fn mc_envopt i ulong t view uchar * to bool
+b = new uchar 8192 0
+for e ulong ulong envcnt
+n = envread e b 0 len b
+if gt n long len t
+if mc_pre b t
 m = syn_mark
 syn_pa b len t sub ulong n len t
-syn_pt s
 put gop i m
 put gopl i syn_len m
 ret true
@@ -956,11 +1091,11 @@ ret false
 end
 
 fn mc_args to void
-n = argcnt
+n = ulong argcnt
 i = ulong 1
 while lt i n bound 1000
 o = syn_arg i
-l = get gxs 2
+l = ulong get gxs 2
 k = ulong 99
 if syn_seq o l mbindir
 k = 0
@@ -972,7 +1107,7 @@ if or eq k 99 ge add i 1 n
 syn_die musage 64
 end
 v = syn_arg add i 1
-vl = get gxs 2
+vl = ulong get gxs 2
 if or eq vl 0 ne get gsp v 47
 syn_die musage 64
 end
@@ -984,10 +1119,12 @@ if eq get gopl 0 0
 syn_die mnobin 64
 end
 if eq get gopl 1 0
-if not mc_envopt 1 menvh mempty
-if not mc_envopt 1 menvhm mdhome
+if not mc_envopt 1 menvh
+if not mc_envopt 1 menvhm
 syn_die mnohome 64
 end
+syn_pt mdhome
+put gopl 1 syn_len get gop 1
 end
 end
 if eq get gopl 1 0
@@ -997,13 +1134,28 @@ end
 
 fn mc_loop to void
 buf = new uchar 1048576 0
-rd = new uchar 65536 0
 tape = new uint 524288 0
 tmp = new uchar 65536 0
-bl = ulong 0
-over = false
+put gln 0 0
+put gln 1 0
+eof = false
+note bound is 1..999999 per loop; 4295 x 999999 reads keeps the original 4294967295 limit
+while not eof bound 4295
+while not eof bound 999999
+eof = mc_chunk buf tape tmp
+end
+end
+bl = get gln 0
+if and gt bl 0 eq get gln 1 0
+mc_line part buf 0 bl tape tmp
+end
+end
+
+note mc_chunk: read one block of stdin and answer each complete line; true at end of input
+note gln 0: bytes of the pending line in buf; gln 1: 1 when that line overflowed buf
+fn mc_chunk buf edit uchar * tape edit uint * tmp edit uchar * to bool
+rd = new uchar 65536 0
 eof = false
-while not eof bound 4294967295
 r = read 0 rd 0 len rd
 if le r 0
 eof = true
@@ -1011,36 +1163,36 @@ r = 0
 end
 for i ulong ulong r
 c = get rd i
+bl = get gln 0
 if eq c 10
-if over
+if eq get gln 1 1
 put gid 1 0
 mc_err 32700 mmeparse
 else
-mc_line buf bl tape tmp
+mc_line part buf 0 bl tape tmp
 end
-bl = 0
-over = false
+put gln 0 0
+put gln 1 0
 else
 if lt bl len buf
 put buf bl c
-bl = add bl 1
+put gln 0 add bl 1
 else
-over = true
+put gln 1 1
 end
 end
 end
-end
-if and gt bl 0 not over
-mc_line buf bl tape tmp
-end
+ret eof
 end
 
 note mc_line: strip a trailing CR, skip blank lines, parse and answer
-fn mc_line buf view uchar * bl ulong tape edit uint * tmp edit uchar * to void
-n = bl
-if and gt n 0 eq get buf sub n 1 13
+fn mc_line buf view uchar * tape edit uint * tmp edit uchar * to void
+n = len buf
+if gt n 0
+if eq get buf sub n 1 13
 n = sub n 1
 end
+end
 blank = true
 for i ulong n
 c = get buf i
diff --git a/tests/expected.jsonl b/tests/expected.jsonl
new file mode 100644
index 0000000..04247a3
--- /dev/null
+++ b/tests/expected.jsonl
@@ -0,0 +1,37 @@
+{"jsonrpc":"2.0","id":1,"result":{"protocolVersion":"2025-06-18","capabilities":{"tools":{"listChanged":false}},"serverInfo":{"name":"synapse-mcp","version":"0.1.0"},"instructions":"AIEN coordination tools: claim before you work, check who holds a target, read drift findings."}}
+{"jsonrpc":"2.0","id":"p","result":{}}
+{"jsonrpc":"2.0","id":2,"result":{"tools":[{"name":"coord_where","description":"Rank aien-dev repositories for a task (synapse-map where) and show who holds claims on the top 3 (synapse-claims who repo:R).","inputSchema":{"type":"object","properties":{"task":{"type":"string","description":"plain-words task"},"limit":{"type":"integer","minimum":1}},"required":["task"],"additionalProperties":false}},{"name":"coord_tree","description":"Repository parent tree (synapse-map tree).","inputSchema":{"type":"object","properties":{"text":{"type":"boolean"}},"additionalProperties":false}},{"name":"coord_check","description":"Repository map findings: orphans, missing or archived parents, duplicate purposes (synapse-map check).","inputSchema":{"type":"object","properties":{},"additionalProperties":false}},{"name":"coord_claim","description":"Claim a target before working on it. Exit 2 means another agent holds it; the holder is returned.","inputSchema":{"type":"object","properties":{"agent":{"type":"string"},"session":{"type":"string"},"target":{"type":"string","description":"repo:O/R | branch:O/R#ref | path:O/R:glob | pr:O/R#N | ext:..."},"ttl":{"type":"integer","minimum":1},"mode":{"type":"string","enum":["excl","shared"]},"state":{"type":"string"},"intent":{"type":"string"},"evidence":{"type":"array","items":{"type":"string"}}},"required":["agent","session","target"],"additionalProperties":false}},{"name":"coord_renew","description":"Extend a claim lease you hold.","inputSchema":{"type":"object","properties":{"agent":{"type":"string"},"id":{"type":"string"},"ttl":{"type":"integer","minimum":1}},"required":["agent","id"],"additionalProperties":false}},{"name":"coord_release","description":"Release a claim you hold, optionally with a final state and evidence.","inputSchema":{"type":"object","properties":{"agent":{"type":"string"},"id":{"type":"string"},"state":{"type":"string"},"evidence":{"type":"array","items":{"type":"string"}}},"required":["agent","id"],"additionalProperties":false}},{"name":"coord_state","description":"Record a state change (e.g. PR_OPEN, MERGED) on a claim you hold.","inputSchema":{"type":"object","properties":{"agent":{"type":"string"},"id":{"type":"string"},"state":{"type":"string"},"evidence":{"type":"array","items":{"type":"string"}}},"required":["agent","id","state"],"additionalProperties":false}},{"name":"coord_who","description":"Active claims overlapping a target.","inputSchema":{"type":"object","properties":{"target":{"type":"string"}},"required":["target"],"additionalProperties":false}},{"name":"coord_list","description":"Active claims (all claims with all=true).","inputSchema":{"type":"object","properties":{"all":{"type":"boolean"}},"additionalProperties":false}},{"name":"coord_conflicts","description":"Conflicting active claim pairs.","inputSchema":{"type":"object","properties":{},"additionalProperties":false}},{"name":"coord_verify","description":"Verify the claims ledger hash chain and signatures.","inputSchema":{"type":"object","properties":{},"additionalProperties":false}},{"name":"coord_pulse","description":"Reconcile claims with GitHub and live sessions; returns drift findings (synapse-pulse run).","inputSchema":{"type":"object","properties":{"alert":{"type":"boolean"}},"additionalProperties":false}},{"name":"coord_board","description":"Render the generated board (BOARD.md, index.html) from claims, map and findings.","inputSchema":{"type":"object","properties":{},"additionalProperties":false}},{"name":"coord_lane","description":"Agents in a lane: active claims whose agent id starts with the lane prefix. Message these agents (parent and children) instead of agent://all.","inputSchema":{"type":"object","properties":{"lane":{"type":"string","description":"agent id prefix, e.g. Coordination"}},"required":["lane"],"additionalProperties":false}}]}}
+{"jsonrpc":"2.0","id":3,"result":{"content":[{"type":"text","text":"map [--home] [@HOME@] [where] [fix the json reader] [--limit] [5]\n{\"repo\":\"aien-dev/a\",\"score\":3}\n{\"score\":2}\n{\"repo\":\"aien-dev/b\"}\nnot json\n{\"repo\":\"aien-dev/c\"}\n{\"repo\":\"aien-dev/d\"}\n{\"exit_code\":0}\nclaims [--home] [@HOME@] [who] [repo:aien-dev/a]\n{\"who\":\"repo:aien-dev/a\",\"exit_code\":0}\nclaims [--home] [@HOME@] [who] [repo:aien-dev/b]\n{\"who\":\"repo:aien-dev/b\",\"exit_code\":0}\nclaims [--home] [@HOME@] [who] [repo:aien-dev/c]\n{\"who\":\"repo:aien-dev/c\",\"exit_code\":0}\n"}],"isError":false}}
+{"jsonrpc":"2.0","id":4,"result":{"content":[{"type":"text","text":"map [--home] [@HOME@] [tree] [--text]\n{\"exit_code\":0}\n"}],"isError":false}}
+{"jsonrpc":"2.0","id":5,"result":{"content":[{"type":"text","text":"map [--home] [@HOME@] [check]\n{\"exit_code\":0}\n"}],"isError":false}}
+{"jsonrpc":"2.0","id":6,"result":{"content":[{"type":"text","text":"claims [--home] [@HOME@] [claim] [--agent] [A1] [--session] [S1] [--target] [repo:aien-dev/a] [--ttl] [60] [--mode] [excl] [--state] [WIP] [--intent] [fix it] [--evidence] [e1] [--evidence] [e 2]\n{\"exit_code\":0}\n"}],"isError":false}}
+{"jsonrpc":"2.0","id":7,"result":{"content":[{"type":"text","text":"claims [--home] [@HOME@] [renew] [--agent] [A1] [--id] [c1] [--ttl] [120]\n{\"exit_code\":0}\n"}],"isError":false}}
+{"jsonrpc":"2.0","id":8,"result":{"content":[{"type":"text","text":"claims [--home] [@HOME@] [release] [--agent] [A1] [--id] [c1] [--state] [MERGED] [--evidence] [pr:aien-dev/a#4]\n{\"exit_code\":0}\n"}],"isError":false}}
+{"jsonrpc":"2.0","id":9,"result":{"content":[{"type":"text","text":"claims [--home] [@HOME@] [state] [--agent] [A1] [--id] [c1] [--state] [PR_OPEN]\n{\"exit_code\":0}\n"}],"isError":false}}
+{"jsonrpc":"2.0","id":10,"result":{"content":[{"type":"text","text":"claims [--home] [@HOME@] [who] [repo:aien-dev/a]\n{\"exit_code\":0}\n"}],"isError":false}}
+{"jsonrpc":"2.0","id":11,"result":{"content":[{"type":"text","text":"claims [--home] [@HOME@] [list] [--all]\n{\"exit_code\":0}\n"}],"isError":false}}
+{"jsonrpc":"2.0","id":12,"result":{"content":[{"type":"text","text":"claims [--home] [@HOME@] [conflicts]\n{\"exit_code\":0}\n"}],"isError":false}}
+{"jsonrpc":"2.0","id":13,"result":{"content":[{"type":"text","text":"claims [--home] [@HOME@] [verify]\n{\"exit_code\":0}\n"}],"isError":false}}
+{"jsonrpc":"2.0","id":14,"result":{"content":[{"type":"text","text":"pulse [--home] [@HOME@] [run] [--claims-bin] [@BIN@/synapse-claims] [--alert]\n{\"exit_code\":0}\n"}],"isError":false}}
+{"jsonrpc":"2.0","id":15,"result":{"content":[{"type":"text","text":"board [render] [--claims] [@HOME@/board/claims.jsonl] [--map] [@HOME@/map.jsonl] [--findings] [@HOME@/pulse/findings.jsonl] [--out] [@HOME@/board]\nclaims [--home] [@HOME@] [list] [--all]\n{\"exit_code\":0}\n"}],"isError":false}}
+{"jsonrpc":"2.0","id":16,"result":{"content":[{"type":"text","text":"claims [--home] [@HOME@] [list] [--agent-prefix] [Coordination]\n{\"exit_code\":0}\n"}],"isError":false}}
+{"jsonrpc":"2.0","id":17,"result":{"content":[{"type":"text","text":"claims [--home] [@HOME@] [claim] [--agent] [A2] [--session] [S2] [--target] [repo:busy/x]\n{\"holder\":\"B1\"}\n{\"exit_code\":2}\nheld by B1\n"}],"isError":false}}
+{"jsonrpc":"2.0","id":18,"result":{"content":[{"type":"text","text":"claims [--home] [@HOME@] [who] [repo:boom/x]\n{\"exit_code\":3}\ntab\there \"q\" back\\slash\n"}],"isError":true}}
+{"jsonrpc":"2.0","id":19,"result":{"content":[{"type":"text","text":"claims [--home] [@HOME@] [list]\n{\"exit_code\":0}\n"}],"isError":false}}
+{"jsonrpc":"2.0","id":null,"error":{"code":-32700,"message":"Parse error"}}
+{"jsonrpc":"2.0","id":null,"error":{"code":-32600,"message":"Invalid Request"}}
+{"jsonrpc":"2.0","id":20,"error":{"code":-32600,"message":"Invalid Request"}}
+{"jsonrpc":"2.0","id":null,"error":{"code":-32600,"message":"Invalid Request"}}
+{"jsonrpc":"2.0","id":21,"error":{"code":-32601,"message":"Method not found"}}
+{"jsonrpc":"2.0","id":22,"error":{"code":-32602,"message":"Invalid params"}}
+{"jsonrpc":"2.0","id":23,"error":{"code":-32602,"message":"Unknown tool"}}
+{"jsonrpc":"2.0","id":24,"error":{"code":-32602,"message":"Invalid params: bad or missing argument"}}
+{"jsonrpc":"2.0","id":25,"error":{"code":-32602,"message":"Invalid params: unknown argument"}}
+{"jsonrpc":"2.0","id":26,"error":{"code":-32602,"message":"Invalid params: bad or missing argument"}}
+{"jsonrpc":"2.0","id":27,"error":{"code":-32602,"message":"Invalid params: bad or missing argument"}}
+{"jsonrpc":"2.0","id":28,"error":{"code":-32602,"message":"Invalid params: bad or missing argument"}}
+{"jsonrpc":"2.0","id":29,"error":{"code":-32602,"message":"Invalid params: bad or missing argument"}}
+{"jsonrpc":"2.0","id":30,"error":{"code":-32602,"message":"Invalid params: bad or missing argument"}}
+{"jsonrpc":"2.0","id":31,"error":{"code":-32602,"message":"Invalid params: bad or missing argument"}}
+{"jsonrpc":"2.0","id":32,"error":{"code":-32602,"message":"Invalid params: arguments must be an object"}}
+{"jsonrpc":"2.0","id":33,"result":{}}
diff --git a/tests/fake/synapse-board b/tests/fake/synapse-board
new file mode 100755
index 0000000..c075f61
--- /dev/null
+++ b/tests/fake/synapse-board
@@ -0,0 +1,5 @@
+#!/bin/sh
+# Fake synapse-board for tests/run.sh: prints its argv and the claims file the server wrote.
+printf 'board'; for a in "$@"; do printf ' [%s]' "$a"; done; printf '\n'
+cat "$3"
+exit 0
diff --git a/tests/fake/synapse-claims b/tests/fake/synapse-claims
new file mode 100755
index 0000000..f2c84b8
--- /dev/null
+++ b/tests/fake/synapse-claims
@@ -0,0 +1,10 @@
+#!/bin/sh
+# Fake synapse-claims for tests/run.sh: prints its argv; a few targets select exit codes.
+printf 'claims'; for a in "$@"; do printf ' [%s]' "$a"; done; printf '\n'
+for a in "$@"; do
+  case $a in
+    repo:busy/x) printf '{"holder":"B1"}\n'; echo 'held by B1' >&2; exit 2 ;;
+    repo:boom/x) printf 'tab\there "q" back\\slash\n' >&2; exit 3 ;;
+  esac
+done
+exit 0
diff --git a/tests/fake/synapse-map b/tests/fake/synapse-map
new file mode 100755
index 0000000..47834ff
--- /dev/null
+++ b/tests/fake/synapse-map
@@ -0,0 +1,7 @@
+#!/bin/sh
+# Fake synapse-map for tests/run.sh: prints its argv; `where` adds ranked JSONL lines with repos.
+printf 'map'; for a in "$@"; do printf ' [%s]' "$a"; done; printf '\n'
+if [ "${3:-}" = where ]; then
+  printf '%s\n' '{"repo":"aien-dev/a","score":3}' '{"score":2}' '{"repo":"aien-dev/b"}' 'not json' '{"repo":"aien-dev/c"}' '{"repo":"aien-dev/d"}'
+fi
+exit 0
diff --git a/tests/fake/synapse-pulse b/tests/fake/synapse-pulse
new file mode 100755
index 0000000..8b8558d
--- /dev/null
+++ b/tests/fake/synapse-pulse
@@ -0,0 +1,4 @@
+#!/bin/sh
+# Fake synapse-pulse for tests/run.sh: prints its argv.
+printf 'pulse'; for a in "$@"; do printf ' [%s]' "$a"; done; printf '\n'
+exit 0
diff --git a/tests/requests.jsonl b/tests/requests.jsonl
new file mode 100644
index 0000000..d3acaf0
--- /dev/null
+++ b/tests/requests.jsonl
@@ -0,0 +1,39 @@
+{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"run.sh","version":"0"}}}
+{"jsonrpc":"2.0","method":"notifications/initialized"}
+{"jsonrpc":"2.0","id":"p","method":"ping"}
+{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}
+{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"coord_where","arguments":{"task":"fix the json reader","limit":5}}}
+{"jsonrpc":"2.0","id":4,"method":"tools/call","params":{"name":"coord_tree","arguments":{"text":true}}}
+{"jsonrpc":"2.0","id":5,"method":"tools/call","params":{"name":"coord_check","arguments":{}}}
+{"jsonrpc":"2.0","id":6,"method":"tools/call","params":{"name":"coord_claim","arguments":{"agent":"A1","session":"S1","target":"repo:aien-dev/a","ttl":60,"mode":"excl","state":"WIP","intent":"fix it","evidence":["e1","e 2"]}}}
+{"jsonrpc":"2.0","id":7,"method":"tools/call","params":{"name":"coord_renew","arguments":{"agent":"A1","id":"c1","ttl":120}}}
+{"jsonrpc":"2.0","id":8,"method":"tools/call","params":{"name":"coord_release","arguments":{"agent":"A1","id":"c1","state":"MERGED","evidence":["pr:aien-dev/a#4"]}}}
+{"jsonrpc":"2.0","id":9,"method":"tools/call","params":{"name":"coord_state","arguments":{"agent":"A1","id":"c1","state":"PR_OPEN"}}}
+{"jsonrpc":"2.0","id":10,"method":"tools/call","params":{"name":"coord_who","arguments":{"target":"repo:aien-dev/a"}}}
+{"jsonrpc":"2.0","id":11,"method":"tools/call","params":{"name":"coord_list","arguments":{"all":true}}}
+{"jsonrpc":"2.0","id":12,"method":"tools/call","params":{"name":"coord_conflicts"}}
+{"jsonrpc":"2.0","id":13,"method":"tools/call","params":{"name":"coord_verify","arguments":{}}}
+{"jsonrpc":"2.0","id":14,"method":"tools/call","params":{"name":"coord_pulse","arguments":{"alert":true}}}
+{"jsonrpc":"2.0","id":15,"method":"tools/call","params":{"name":"coord_board","arguments":{}}}
+{"jsonrpc":"2.0","id":16,"method":"tools/call","params":{"name":"coord_lane","arguments":{"lane":"Coordination"}}}
+{"jsonrpc":"2.0","id":17,"method":"tools/call","params":{"name":"coord_claim","arguments":{"agent":"A2","session":"S2","target":"repo:busy/x"}}}
+{"jsonrpc":"2.0","id":18,"method":"tools/call","params":{"name":"coord_who","arguments":{"target":"repo:boom/x"}}}
+{"jsonrpc":"2.0","id":19,"method":"tools/call","params":{"name":"coord_list","arguments":{"all":false}}}
+not json
+[1,2]
+
+{"jsonrpc":"1.0","id":20,"method":"ping"}
+{"jsonrpc":"2.0","id":{"x":1},"method":"ping"}
+{"jsonrpc":"2.0","id":21,"method":"no/such"}
+{"jsonrpc":"2.0","id":22,"method":"tools/call"}
+{"jsonrpc":"2.0","id":23,"method":"tools/call","params":{"name":"coord_nope","arguments":{}}}
+{"jsonrpc":"2.0","id":24,"method":"tools/call","params":{"name":"coord_who","arguments":{}}}
+{"jsonrpc":"2.0","id":25,"method":"tools/call","params":{"name":"coord_who","arguments":{"target":"repo:a/b","extra":1}}}
+{"jsonrpc":"2.0","id":26,"method":"tools/call","params":{"name":"coord_who","arguments":{"target":"--all"}}}
+{"jsonrpc":"2.0","id":27,"method":"tools/call","params":{"name":"coord_who","arguments":{"target":""}}}
+{"jsonrpc":"2.0","id":28,"method":"tools/call","params":{"name":"coord_who","arguments":{"target":"a\u0000b"}}}
+{"jsonrpc":"2.0","id":29,"method":"tools/call","params":{"name":"coord_renew","arguments":{"agent":"A1","id":"c1","ttl":0}}}
+{"jsonrpc":"2.0","id":30,"method":"tools/call","params":{"name":"coord_list","arguments":{"all":"yes"}}}
+{"jsonrpc":"2.0","id":31,"method":"tools/call","params":{"name":"coord_claim","arguments":{"agent":"A1","session":"S1","target":"repo:a/b","evidence":"e1"}}}
+{"jsonrpc":"2.0","id":32,"method":"tools/call","params":{"name":"coord_who","arguments":["repo:a/b"]}}
+{"jsonrpc":"2.0","id":33,"method":"ping"}
diff --git a/tests/run.sh b/tests/run.sh
index d43f576..b9b7b1e 100755
--- a/tests/run.sh
+++ b/tests/run.sh
@@ -1,3 +1,129 @@
 #!/bin/sh
-# tests/run.sh: NOT_RUN (parked before tests were written)
-echo "NOT_RUN synapse-mcp tests not written"; exit 1
+# tests/run.sh: build synapse-mcp with the pinned omc, then drive it over stdio with MCP JSON-RPC against the
+# fake CLIs in tests/fake (shell scripts that print their argv). Every response is compared byte for byte.
+# Env: OMEGA_SRC (omega-mv checkout at the omega.pin sha, required), TEST_ROOT (scratch dir, default a
+# fresh mktemp directory). Exit 1 on any FAIL.
+set -u
+here=$(cd "$(dirname "$0")/.." && pwd)
+: "${OMEGA_SRC:?set OMEGA_SRC to the pinned omega-mv checkout}"
+TEST_ROOT=${TEST_ROOT:-$(mktemp -d "${TMPDIR:-/tmp}/synapse-mcp-test.XXXXXX")}
+fake=$here/tests/fake
+pass=0 fail=0
+
+ok() { pass=$((pass + 1)); echo "PASS $1"; }
+bad() { fail=$((fail + 1)); echo "FAIL $1"; }
+
+rm -rf "$TEST_ROOT"
+mkdir -p "$TEST_ROOT"
+bin=$TEST_ROOT/synapse-mcp
+if ! sh "$here/build.sh" "$OMEGA_SRC" "$bin" 2> "$TEST_ROOT/build.err"; then
+  cat "$TEST_ROOT/build.err"
+  echo "FAIL build"
+  exit 1
+fi
+ok build
+out=$TEST_ROOT/out
+err=$TEST_ROOT/err
+want=$TEST_ROOT/want
+
+# same NAME WANT_RC: exit status $rc, stdout $out equal to $want byte for byte, stderr empty
+same() {
+  if [ "$rc" -ne "$2" ]; then bad "$1: exit $rc, want $2"; sed 's/^/  stderr: /' "$err" | head -5; return; fi
+  if [ -s "$err" ]; then bad "$1: stderr not empty"; sed 's/^/  stderr: /' "$err" | head -5; return; fi
+  if cmp -s "$want" "$out"; then ok "$1"; else bad "$1: stdout differs"; diff "$want" "$out" | cut -c1-300 | head -20; fi
+}
+
+# usage NAME WANT_RC WANT_STDERR: exit status, empty stdout, exact one-line stderr
+usage() {
+  if [ "$rc" -eq "$2" ] && [ ! -s "$out" ] && [ "$(cat "$err")" = "$3" ]; then ok "$1"; else
+    bad "$1: exit $rc, want $2; stderr: $(head -c 200 "$err")"
+  fi
+}
+
+# 1. One session: initialize, ping, tools/list, one tools/call per tool (14), exit-code mapping, JSON
+# escaping of child output, and every JSON-RPC refusal (parse error, invalid request, unknown method,
+# invalid params, unknown tool, bad arguments). Notifications and blank lines get no response.
+H=$TEST_ROOT/home
+mkdir -p "$H"
+"$bin" --bin-dir "$fake" --home "$H" < "$here/tests/requests.jsonl" > "$out" 2> "$err"
+rc=$?
+sed -e "s|@HOME@|$H|g" -e "s|@BIN@|$fake|g" "$here/tests/expected.jsonl" > "$want"
+same session 0
+if [ "$(cat "$H/board/claims.jsonl" 2> /dev/null)" = "claims [--home] [$H] [list] [--all]" ]; then
+  ok "board claims.jsonl written"
+else
+  bad "board claims.jsonl written"
+fi
+
+# Negative control: the comparison must reject a transcript that differs in one byte.
+sed 's/"id":33,"result":{}/"id":33,"result":{ }/' "$want" > "$TEST_ROOT/want.nc"
+if cmp -s "$TEST_ROOT/want.nc" "$out"; then bad "negative control: altered expectation accepted"; else ok "negative control"; fi
+
+# 2. Line limits. A 1048576-byte line buffer feeds a JSON reader limited to 983040 bytes and a tape of
+# 131068 tokens; each refusal is a -32700 response and the server keeps answering.
+pad() { dd if=/dev/zero bs=1000 count="$1" 2> /dev/null | tr '\0' a; }
+zeros() { i=0; while [ $i -lt "$1" ]; do printf '0,0,0,0,0,0,0,0,0,0,'; i=$((i + 1)); done; }
+{
+  printf '{"jsonrpc":"2.0","id":1,"method":"ping","params":{"p":"'; pad 900; printf '"}}\n'
+  printf '{"jsonrpc":"2.0","id":2,"method":"ping","params":{"p":"'; pad 984; printf '"}}\n'
+  printf '{"jsonrpc":"2.0","id":3,"method":"ping","params":{"p":"'; pad 1100; printf '"}}\n'
+  printf '{"jsonrpc":"2.0","id":4,"method":"ping","params":{"p":['; zeros 14000; printf '0]}}\n'
+  printf '{"jsonrpc":"2.0","id":5,"method":"ping"}\r\n'
+  printf '{"jsonrpc":"2.0","id":6,"method":"ping"}'
+} > "$TEST_ROOT/limits.jsonl"
+"$bin" --bin-dir "$fake" --home "$H" < "$TEST_ROOT/limits.jsonl" > "$out" 2> "$err"
+rc=$?
+cat > "$want" << 'EOF'
+{"jsonrpc":"2.0","id":1,"result":{}}
+{"jsonrpc":"2.0","id":null,"error":{"code":-32700,"message":"Parse error"}}
+{"jsonrpc":"2.0","id":null,"error":{"code":-32700,"message":"Parse error"}}
+{"jsonrpc":"2.0","id":null,"error":{"code":-32700,"message":"Parse error"}}
+{"jsonrpc":"2.0","id":5,"result":{}}
+{"jsonrpc":"2.0","id":6,"result":{}}
+EOF
+same "line limits (900000 B ok, 984000 B, 1100000 B, 140001 tokens refused, CRLF, no final newline)" 0
+
+# 3. Home resolution: AIEN_COORD_HOME, then HOME/.local/state/aien-coord; --home wins over both.
+req='{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"coord_verify"}}'
+resp() {
+  printf '{"jsonrpc":"2.0","id":1,"result":{"content":[{"type":"text","text":"claims [--home] [%s] [verify]\\n{\\"exit_code\\":0}\\n"}],"isError":false}}\n' "$1"
+}
+echo "$req" | env -i AIEN_COORD_HOME=/x/coord HOME=/x/u "$bin" --bin-dir "$fake" > "$out" 2> "$err"
+rc=$?
+resp /x/coord > "$want"
+same "home from AIEN_COORD_HOME" 0
+echo "$req" | env -i HOME=/x/u "$bin" --bin-dir "$fake" > "$out" 2> "$err"
+rc=$?
+resp /x/u/.local/state/aien-coord > "$want"
+same "home from HOME" 0
+echo "$req" | env -i AIEN_COORD_HOME=/x/coord "$bin" --home /x/h --bin-dir "$fake" > "$out" 2> "$err"
+rc=$?
+resp /x/h > "$want"
+same "--home wins" 0
+
+# 4. coord_board refuses to render when it cannot write HOME/board/claims.jsonl.
+echo '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"coord_board"}}' |
+  "$bin" --bin-dir "$fake" --home "$TEST_ROOT/missing" > "$out" 2> "$err"
+rc=$?
+printf '%s\n' '{"jsonrpc":"2.0","id":1,"result":{"content":[{"type":"text","text":"synapse-mcp: could not write HOME/board/claims.jsonl; board not rendered\n"}],"isError":true}}' > "$want"
+same "board without a writable home" 0
+
+# 5. Command-line refusals (exit 64, nothing on stdout).
+"$bin" < /dev/null > "$out" 2> "$err"
+rc=$?
+usage "no --bin-dir" 64 "synapse-mcp: --bin-dir must be an absolute directory"
+"$bin" --bin-dir tests/fake --home /x < /dev/null > "$out" 2> "$err"
+rc=$?
+usage "relative --bin-dir" 64 "usage: synapse-mcp --bin-dir DIR [--home DIR]"
+"$bin" --bin-dir "$fake" --bogus x < /dev/null > "$out" 2> "$err"
+rc=$?
+usage "unknown option" 64 "usage: synapse-mcp --bin-dir DIR [--home DIR]"
+"$bin" --bin-dir "$fake" --home < /dev/null > "$out" 2> "$err"
+rc=$?
+usage "option without value" 64 "usage: synapse-mcp --bin-dir DIR [--home DIR]"
+env -i "$bin" --bin-dir "$fake" < /dev/null > "$out" 2> "$err"
+rc=$?
+usage "no home anywhere" 64 "synapse-mcp: no --home, AIEN_COORD_HOME or HOME"
+
+echo "synapse-mcp tests: $pass passed, $fail failed"
+[ "$fail" -eq 0 ]