         throw new Server.NotFoundError message
 
 
+    ## POST /eval
+    #
+    #   Allows running arbitrary JS/CoffeeScript. Useful for facilitating
+    #   building a REPL to introspect/debug at runtime.
+    #
+    #   script - a String of code to run
+    #   type   - a String representing the MIME type of script
+    #            (default: text/javascript)
+    #   color  - a Boolean that, if true, makes the response string use ANSI
+    #            color escapes (default: false)
+    #
+    #   Examples
+    #
+    #     # Request
+    #     POST /eval HTTP/1.0
+    #     Content-Type: application/json
+    #
+    #     {"script": "(-> 3+4)()", "type": "text/coffeescript"}
+    #
+    #
+    #     # Response
+    #     HTTP/1.0 200 OK
+    #     Content-Type: application/json
+    #
+    #     {"result": "7"}
+    #
+    # Returns a REPL-friendly stringified version of the result.
     @server.post '/eval', =>
       params = @server.request.json
       script = params.script


      @server.deliver {result: inspect(result, undefined, undefined, color: params.color)}

    return true

  job_start: (data, respond) ->
    try
      throw new Error "Got unexpected type: #{typeof data}" if typeof data isnt 'object'

      @job = new Job data.jobid, data.fid, data.creds, data.options

      cookies.restore data.cookies if data.cookies

      if data.callback
        callbacks = if type.isString data.callback
                      [data.callback]
                    else
                      data.callback

        if callbacks.length
          @job.on 'update', =>
            params =
              status: @job.status
              result: @job.result
              data: json.render @job.data
              completed: @job.done
              cookies: cookies.dump()
              timestamp: new Date().getTime()
              version: @job.version

            for callback in callbacks
              xhr.put callback, params

      @job.start()
    catch e
      logger.error 'job.start: ', e

    respond response:
              status: 'ok'

  job_resume: (data, respond) ->
    if @job
      try
        @job.resume data.creds
        respond response:
                  status: 'ok'

      catch e
        respond response:
                  status: 'error'
                  error: e.toString()

    else
      respond response:
                status: 'error'
                error: "No running jobs"

  job_status: (data, respond) ->
    unless @job
      respond response:
                status: 'error'
                error: "No running jobs"
    else
      respond response:
                status: 'ok'
                'job.status':
                  id: @job.id
                  status: @job.status
                  result: @job.result
                  data: @job.data
                  fid: @job.fid
                  completed: @job.done
                  cookies: cookies.dump()
                  timestamp: new Date().getTime()
                  version: @job.version

  window_open: (data, respond) ->
    index = @windows.length++

{tryCatch, tryThrow} = require 'util/try'

class Controller
  constructor: ->
    @jobs = []

  start: (port) ->
    @windows ||= length: 1
    @windows[window.name] = window
