Skip to content

Instantly share code, notes, and snippets.

@domenkozar
Last active September 13, 2024 12:54
Show Gist options
  • Save domenkozar/f8fde21396762c0022b26afb1b6b986f to your computer and use it in GitHub Desktop.
Save domenkozar/f8fde21396762c0022b26afb1b6b986f to your computer and use it in GitHub Desktop.
Task Server Protocol

Task Server Protocol

https://devenv.sh allows defining tasks in your favorite language using JSON-RPC protocol and exposing them as an executable :

{
  task.serverProtocol = [ "myexecutable" ];
}

Listing tasks

Which would launch myexecutable /tmp/rando.sock and devenv would on startup immediately ask for a list of tasks:

{
  "jsonrpc": "2.0",
  "method": "initialize",
  "params": {},
  "id": 1
}

And the server responds:

{
  "jsonrpc": "2.0",
  "result": {
    "tasks": [{
      "name": "prefix:custom",
      "depends": []
    }]
  },
  "id": 1
}

Running tasks

Then the client can ask the server to run a task:

{
  "jsonrpc": "2.0",
  "method": "run",
  "params": {
    "task": "prefix:name",
    "inputs": {},
    "outputs": {}
  },
  "id": 2
}

And server streams updates about stdout/stderr:

{
  "jsonrpc": "2.0",
  "method": "log",
  "params": {
    "task": "prefix:name",
    "line": "some text",
    "stderr": false,
    "time": "20240828T212611.11Z",
  }
}

Until the final response from the server with outputs and the final status of the task.

{
  "jsonrpc": "2.0",
  "result": {
    "task": "prefix:name",
    "outputs": {},
    "status": "succeeded"
  },
  "id": 2
}

Deliverables

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment