tring-chat 0.1.18 → 0.1.21

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
@@ -430,6 +430,34 @@ Two things are deliberate:
430
430
  Auto-executing whatever was there last time is how four dev servers end up fighting
431
431
  over a port.
432
432
 
433
+ ### Claude conversations come back too
434
+
435
+ A tile that was running Claude Code reopens the same conversation after a restart
436
+ of tring or of the machine: tring types `claude --resume <id>` into the tile's shell
437
+ once it has started. Claude waits for your next prompt, so nothing runs that was not
438
+ already running. Quitting Claude still leaves you in that shell.
439
+
440
+ tring learns which conversation each tile is running from Claude Code's
441
+ `SessionStart` and `SessionEnd` hooks, which `tring hooks install` adds (run it again
442
+ if you installed the hooks before this, then restart your `claude` sessions once).
443
+ Ending a conversation yourself (`/exit`, Ctrl+D, `/clear`) forgets it. Stopping tring
444
+ or shutting down does not, since that is the conversation you want back. A tile that
445
+ was resumed runs plain `claude --resume`, so flags you started it with (`--model`,
446
+ a permission mode) fall back to your settings.
447
+
448
+ To have tring itself running after a reboot:
449
+
450
+ ```sh
451
+ tring autostart on # flags after `on` are passed to the daemon, e.g. --allow-origin …
452
+ tring autostart status
453
+ tring autostart off
454
+ ```
455
+
456
+ This writes a systemd user unit on Linux, a LaunchAgent on macOS, or a `.cmd` in the
457
+ Startup folder on Windows, with the `PATH` you ran it from so the tiles find `claude`
458
+ and your tools. It is enabled for your next login, not started, since tring is usually
459
+ running already. A file at that path that tring did not write is left alone.
460
+
433
461
  ## Dropping files on a terminal
434
462
 
435
463
  Drag a screenshot, a spreadsheet or any other file onto the centre terminal and its path is typed into the prompt,
@@ -512,6 +540,66 @@ publishing, deploys, `kubectl`/`terraform`, anything mentioning production, secr
512
540
  `.env` files, paths outside the session's directory, MCP tools and plan approvals.
513
541
  Every decision it makes is listed in the inbox with its reason.
514
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. Instead of
551
+ typing into each tile, you tell it what you want:
552
+
553
+ > *Which tiles are on which branch? Ask the api tile to run its tests, and start a new
554
+ > tile in web to update the changelog.*
555
+
556
+ It works the tiles through tring's own MCP server, `tring`:
557
+
558
+ | Tool | What it does | Asks you first |
559
+ |---|---|---|
560
+ | `list_sessions` | every project and tile: status, repository, worktree and branch, whether it runs Claude, what it waits on, what it last said | no |
561
+ | `list_worktrees` | every worktree of each project's repository, its branch, and which tiles are in it | no |
562
+ | `find_work` | which tiles have been working on a topic, ranked by name, branch, conversation title, prompts, answers and edited files | no |
563
+ | `session_history` | a tile's Claude conversation: the prompts it was given, its answers, the files it edited | no |
564
+ | `read_session` | the last lines of a tile's terminal | no |
565
+ | `session_changes` | the uncommitted changes in a tile's worktree | no |
566
+ | `send_prompt` | a prompt to the Claude in a tile, as if you typed it there | no |
567
+ | `wait_for` | waits until tiles finish, then reads their answers | no |
568
+ | `create_session` | a new tile running Claude, optionally in a worktree for a branch, with an optional first prompt | yes |
569
+
570
+ **Which tile?** Say what the work is, not where it is — *"make the reporting box
571
+ green"* — and it goes to the tile that has been working on the reporting box, which
572
+ already has the context. tring reads each tile's own Claude Code transcript (the path
573
+ every hook reports) for Claude's title for the conversation, the prompts it was given and
574
+ the files it edited, so a tile is found by what it has been doing even after its work is
575
+ committed and its screen has moved on. When two tiles match about equally, or none
576
+ clearly does, the agent asks you which rather than guessing.
577
+
578
+ **Worktrees.** The agent works one branch, one worktree, one agent. A tile is placed
579
+ where its *agent* is working — every Claude Code hook reports that directory — so a
580
+ Claude that moved into a worktree (`claude --worktree`, or its own `cd`) is seen there,
581
+ not in the directory its shell started in. Tiles sharing a worktree are flagged, and
582
+ sending work to one while another agent is busy there comes back with a warning.
583
+ `create_session` with a `branch` reuses the worktree that already has it checked out, or
584
+ runs `git worktree add` (checking out the branch, or creating it from `base`). New
585
+ worktrees go beside your existing ones; with none to copy, in `<repo>.worktrees/`
586
+ next to the repository. Tell the agent otherwise in its `CLAUDE.md` (below).
587
+
588
+ It talks to agents and nothing else. It never types into a plain shell, and never into a
589
+ tile that is waiting on a permission prompt or a question — those stay yours, in the
590
+ cards beside it, as before. What the agents in the tiles do is still governed by their
591
+ own permissions.
592
+
593
+ The agent lives in `~/.config/tring/orchestrator`, which tring rewrites on every start
594
+ (`TRING.md` holds its instructions; add your own to `CLAUDE.md` there, which is kept).
595
+ The first time it opens, Claude Code asks whether to trust that folder and lists the
596
+ eight tools it pre-approves; say yes. Its conversation survives a restart of tring. If you quit
597
+ its Claude, the panel offers *Start again* or *New conversation*. Untick **Agent** and the
598
+ Orchestrator is the inbox it always was.
599
+
600
+ It needs the hooks (`tring hooks install`): they are how it knows which tiles run Claude
601
+ and when an agent has finished.
602
+
515
603
  ## Claude Code
516
604
 
517
605
  `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));