tring-chat 0.1.19 → 0.1.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -540,6 +540,70 @@ publishing, deploys, `kubectl`/`terraform`, anything mentioning production, secr
540
540
  `.env` files, paths outside the session's directory, MCP tools and plan approvals.
541
541
  Every decision it makes is listed in the inbox with its reason.
542
542
 
543
+ Agents' messages, plans and questions are shown as formatted Markdown — bold, lists,
544
+ code, tables and links — never as raw asterisks. On a phone the Orchestrator also has a
545
+ button of its own in the bar under the tabs, with the count of cards waiting.
546
+
547
+ ### Orchestrator agent
548
+
549
+ Optional, off by default. Tick **Agent** in the Orchestrator's header and the centre
550
+ becomes a Claude Code session of its own, with the cards in a column beside it. Drag
551
+ the bar between them to make the column wider or narrower; the width is remembered. A
552
+ long reply or plan on a card folds behind **Show all**. Instead of
553
+ typing into each tile, you tell it what you want:
554
+
555
+ > *Which tiles are on which branch? Ask the api tile to run its tests, and start a new
556
+ > tile in web to update the changelog.*
557
+
558
+ It works the tiles through tring's own MCP server, `tring`:
559
+
560
+ | Tool | What it does | Asks you first |
561
+ |---|---|---|
562
+ | `list_sessions` | every project and tile: status, repository, worktree and branch, whether it runs Claude, what it waits on, what it last said | no |
563
+ | `list_worktrees` | every worktree of each project's repository, its branch, and which tiles are in it | no |
564
+ | `find_work` | which tiles have been working on a topic, ranked by name, branch, conversation title, prompts, answers and edited files | no |
565
+ | `session_history` | a tile's Claude conversation: the prompts it was given, its answers, the files it edited | no |
566
+ | `read_session` | the last lines of a tile's terminal | no |
567
+ | `session_changes` | the uncommitted changes in a tile's worktree | no |
568
+ | `send_prompt` | a prompt to the Claude in a tile, as if you typed it there | no |
569
+ | `wait_for` | waits until tiles finish, then reads their answers | no |
570
+ | `create_session` | a new tile running Claude, optionally in a worktree for a branch, with an optional first prompt | yes |
571
+
572
+ **Which tile?** Say what the work is, not where it is — *"make the reporting box
573
+ green"* — and it goes to the tile that has been working on the reporting box, which
574
+ already has the context. tring reads each tile's own Claude Code transcript (the path
575
+ every hook reports) for Claude's title for the conversation, the prompts it was given and
576
+ the files it edited, so a tile is found by what it has been doing even after its work is
577
+ committed and its screen has moved on. The repositories an agent has edited and read in
578
+ count too, so a Claude started in your home directory that has spent the day in one
579
+ repository is found as working in that repository. When two tiles match about equally, or none
580
+ clearly does, the agent asks you which rather than guessing.
581
+
582
+ **Worktrees.** The agent works one branch, one worktree, one agent. A tile is placed
583
+ where its *agent* is working — every Claude Code hook reports that directory — so a
584
+ Claude that moved into a worktree (`claude --worktree`, or its own `cd`) is seen there,
585
+ not in the directory its shell started in. Tiles sharing a worktree are flagged, and
586
+ sending work to one while another agent is busy there comes back with a warning.
587
+ `create_session` with a `branch` reuses the worktree that already has it checked out, or
588
+ runs `git worktree add` (checking out the branch, or creating it from `base`). New
589
+ worktrees go beside your existing ones; with none to copy, in `<repo>.worktrees/`
590
+ next to the repository. Tell the agent otherwise in its `CLAUDE.md` (below).
591
+
592
+ It talks to agents and nothing else. It never types into a plain shell, and never into a
593
+ tile that is waiting on a permission prompt or a question — those stay yours, in the
594
+ cards beside it, as before. What the agents in the tiles do is still governed by their
595
+ own permissions.
596
+
597
+ The agent lives in `~/.config/tring/orchestrator`, which tring rewrites on every start
598
+ (`TRING.md` holds its instructions; add your own to `CLAUDE.md` there, which is kept).
599
+ The first time it opens, Claude Code asks whether to trust that folder and lists the
600
+ eight tools it pre-approves; say yes. Its conversation survives a restart of tring. If you quit
601
+ its Claude, the panel offers *Start again* or *New conversation*. Untick **Agent** and the
602
+ Orchestrator is the inbox it always was.
603
+
604
+ It needs the hooks (`tring hooks install`): they are how it knows which tiles run Claude
605
+ and when an agent has finished.
606
+
543
607
  ## Claude Code
544
608
 
545
609
  `tring hooks install` (see [Orchestrator](#orchestrator)) includes a Stop hook, so
@@ -0,0 +1,129 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/mcp-cli.ts
4
+ import { readFileSync } from "node:fs";
5
+ import { request as httpRequest } from "node:http";
6
+ import { request as httpsRequest } from "node:https";
7
+ var LOOPBACK = /* @__PURE__ */ new Set(["127.0.0.1", "localhost", "::1", "[::1]"]);
8
+ var PROTOCOL = "2025-06-18";
9
+ function flag(name) {
10
+ const i = process.argv.indexOf(name);
11
+ return i >= 0 ? process.argv[i + 1] : void 0;
12
+ }
13
+ var urlFlag = flag("--url");
14
+ var base = urlFlag ?? process.env["TRING_URL"] ?? "";
15
+ var token = (() => {
16
+ const file = flag("--token-file");
17
+ if (file) {
18
+ try {
19
+ return readFileSync(file, "utf8").trim() || void 0;
20
+ } catch {
21
+ return void 0;
22
+ }
23
+ }
24
+ return urlFlag ? void 0 : process.env["TRING_TOKEN"];
25
+ })();
26
+ function call(method, route, payload, signal) {
27
+ return new Promise((resolve, reject) => {
28
+ let url;
29
+ try {
30
+ url = new URL(route, base);
31
+ } catch {
32
+ return reject(new Error(`bad daemon URL ${base}`));
33
+ }
34
+ const body = payload === void 0 ? void 0 : JSON.stringify(payload);
35
+ const https = url.protocol === "https:";
36
+ const req = (https ? httpsRequest : httpRequest)(url, {
37
+ method,
38
+ headers: {
39
+ ...body ? { "content-type": "application/json", "content-length": Buffer.byteLength(body) } : {},
40
+ ...token ? { authorization: `Bearer ${token}` } : {}
41
+ },
42
+ // A self-signed --tls-cert on this machine is still our daemon.
43
+ ...https && LOOPBACK.has(url.hostname) ? { rejectUnauthorized: false } : {},
44
+ ...signal ? { signal } : {}
45
+ }, (res) => {
46
+ const chunks = [];
47
+ res.on("data", (c) => chunks.push(c));
48
+ res.on("end", () => resolve({ status: res.statusCode ?? 0, body: Buffer.concat(chunks).toString("utf8") }));
49
+ res.on("error", reject);
50
+ });
51
+ req.on("error", reject);
52
+ req.end(body);
53
+ });
54
+ }
55
+ function send(msg) {
56
+ process.stdout.write(JSON.stringify(msg) + "\n");
57
+ }
58
+ var pending = /* @__PURE__ */ new Map();
59
+ async function handle(req) {
60
+ const { id, method, params } = req;
61
+ const reply = (result) => {
62
+ if (id !== void 0) send({ jsonrpc: "2.0", id, result });
63
+ };
64
+ const fail = (code, message) => {
65
+ if (id !== void 0) send({ jsonrpc: "2.0", id, error: { code, message } });
66
+ };
67
+ switch (method) {
68
+ case "initialize":
69
+ return reply({
70
+ protocolVersion: typeof params?.["protocolVersion"] === "string" ? params["protocolVersion"] : PROTOCOL,
71
+ capabilities: { tools: {} },
72
+ serverInfo: { name: "tring", version: "1" },
73
+ instructions: "Tools for the tiles in tring: list them, read them, prompt their agents, start new ones, wait for them."
74
+ });
75
+ case "ping":
76
+ return reply({});
77
+ case "notifications/cancelled": {
78
+ const target = params?.["requestId"];
79
+ if (target !== void 0) pending.get(target)?.abort();
80
+ return;
81
+ }
82
+ case "tools/list": {
83
+ try {
84
+ const r = await call("GET", "/api/orchestrator/tools");
85
+ if (r.status !== 200) return fail(-32603, `tring answered ${r.status}`);
86
+ return reply({ tools: JSON.parse(r.body).tools });
87
+ } catch (err) {
88
+ return fail(-32603, `cannot reach tring at ${base}: ${err.message}`);
89
+ }
90
+ }
91
+ case "tools/call": {
92
+ const abort = new AbortController();
93
+ if (id !== void 0) pending.set(id, abort);
94
+ try {
95
+ const r = await call("POST", "/api/orchestrator/call", { name: params?.["name"], arguments: params?.["arguments"] ?? {} }, abort.signal);
96
+ const parsed = r.status === 200 ? JSON.parse(r.body) : null;
97
+ const text = parsed?.text ?? `tring answered ${r.status}: ${r.body.slice(0, 300)}`;
98
+ return reply({ content: [{ type: "text", text }], isError: parsed?.isError ?? true });
99
+ } catch (err) {
100
+ if (abort.signal.aborted) return;
101
+ return reply({ content: [{ type: "text", text: `cannot reach tring at ${base}: ${err.message}. Is the daemon running?` }], isError: true });
102
+ } finally {
103
+ if (id !== void 0) pending.delete(id);
104
+ }
105
+ }
106
+ }
107
+ if (method.startsWith("notifications/")) return;
108
+ fail(-32601, `method not found: ${method}`);
109
+ }
110
+ var buffer = "";
111
+ process.stdin.setEncoding("utf8");
112
+ process.stdin.on("data", (chunk) => {
113
+ buffer += chunk;
114
+ let nl;
115
+ while ((nl = buffer.indexOf("\n")) >= 0) {
116
+ const line = buffer.slice(0, nl).trim();
117
+ buffer = buffer.slice(nl + 1);
118
+ if (!line) continue;
119
+ let req;
120
+ try {
121
+ req = JSON.parse(line);
122
+ } catch {
123
+ send({ jsonrpc: "2.0", id: null, error: { code: -32700, message: "parse error" } });
124
+ continue;
125
+ }
126
+ void handle(req);
127
+ }
128
+ });
129
+ process.stdin.on("end", () => process.exit(0));