traintrack 2.0.0
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/LICENSE +201 -0
- package/README.md +158 -0
- package/dist/channel/channel.js +64 -0
- package/dist/channel/resolve.js +43 -0
- package/dist/cli.js +164 -0
- package/dist/index.js +6 -0
- package/dist/mcp/server.js +198 -0
- package/dist/mcp/tools.js +207 -0
- package/dist/mcp-server.js +8 -0
- package/dist/onboarding/briefing.js +24 -0
- package/dist/runner/argv.js +47 -0
- package/dist/runner/event-parser.js +165 -0
- package/dist/runner/turn-runner.js +81 -0
- package/dist/setup/blocks.js +251 -0
- package/dist/setup/configure.js +179 -0
- package/dist/setup/detect.js +53 -0
- package/dist/setup/harness.js +61 -0
- package/dist/setup/prompt.js +218 -0
- package/dist/setup/setup.js +106 -0
- package/dist/setup/types.js +9 -0
- package/dist/spawn/spawn.js +90 -0
- package/dist/ui/banner.js +76 -0
- package/dist/worker/worker.js +190 -0
- package/hooks/hooks-codex.json +16 -0
- package/hooks/hooks-cursor.json +10 -0
- package/hooks/hooks.json +16 -0
- package/hooks/run-hook.cmd +46 -0
- package/hooks/session-start +44 -0
- package/hooks/session-start-codex +28 -0
- package/package.json +52 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 traintrack
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="assets/banner.svg" alt="traintrack" width="660">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<p align="center">
|
|
6
|
+
<b>Your coding agents, working as a team — in the terminals you already use.</b><br>
|
|
7
|
+
Run <code>claude</code> and <code>codex</code> like you always do. After one <code>traintrack setup</code>, every session auto-joins a shared team: they see each other and talk, or one becomes a foreman that spawns the rest.
|
|
8
|
+
</p>
|
|
9
|
+
|
|
10
|
+
<p align="center">
|
|
11
|
+
<code>npm i -g traintrack</code> · <code>traintrack setup</code> · Apache-2.0 · <b>beta</b> (Claude Code · Codex) · <b>pre-pre-alpha</b> (OpenCode · Cursor)
|
|
12
|
+
</p>
|
|
13
|
+
|
|
14
|
+
<p align="center">
|
|
15
|
+
<i>No daemon · no wrapper command · no new app · just a SQLite file at your repo root.</i>
|
|
16
|
+
</p>
|
|
17
|
+
|
|
18
|
+
> [!WARNING]
|
|
19
|
+
> **Alpha.** traintrack is brand new and moving fast — commands, config formats, and the wire protocol can change between versions. Claude Code & Codex are live-verified; expect rough edges, and pin a version if you depend on it.
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Why traintrack is different
|
|
24
|
+
|
|
25
|
+
There are many ways to run several agents at once. traintrack is the one that disappears into your existing setup:
|
|
26
|
+
|
|
27
|
+
- **No wrapper, no relaunch.** You don't start agents *through* traintrack. Set up once, and your normal `claude` / `codex` sessions — however you launch them, even from your IDE's terminal — are already on the team. Nothing to remember at launch time.
|
|
28
|
+
- **Both modes in one install.** A leaderless **peer mesh** (sessions you open by hand discover + message each other) *and* a **foreman** that spawns headless workers into isolated git worktrees. Most tools do one or the other; traintrack does both, and the peer→lead transition is seamless.
|
|
29
|
+
- **Zero infrastructure.** No background daemon, no tmux, no cloud relay, no Electron app. The message bus is a SQLite file at your git repo root; install is a single `npm i -g`.
|
|
30
|
+
- **Native tools, not a prompt blob.** Agents get real MCP tools — `list_team`, `send_message`, `spawn_worker`, `await_results` — not a wall of injected instructions.
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Install
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npm install -g traintrack
|
|
38
|
+
traintrack setup
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
`traintrack setup` detects which agent CLIs you actually have (**Claude Code**, **Codex**, **OpenCode**, **Cursor**), lets you pick, and wires each one up:
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
› ◉ Claude Code found 'claude' on PATH
|
|
45
|
+
◉ Codex found 'codex' on PATH
|
|
46
|
+
◉ OpenCode found 'opencode' on PATH
|
|
47
|
+
◉ Cursor found 'cursor' on PATH
|
|
48
|
+
↑/↓ move · space toggle · a all/none · enter confirm · esc cancel
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
For each tool it (a) **registers the MCP server** in that tool's config and (b) **injects a short team-awareness note** into its instructions file. From then on you just launch your CLI normally. It's idempotent (safe to re-run), and `traintrack setup --uninstall` reverses it cleanly.
|
|
52
|
+
|
|
53
|
+
> Installs the `traintrack` command globally.
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## Try it
|
|
58
|
+
|
|
59
|
+
### Mesh: open a few sessions, watch them connect
|
|
60
|
+
|
|
61
|
+
In one project, open two or three `claude` / `codex` sessions the way you always do (any subdirectory is fine — no special command). Then:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
traintrack team # see everyone on this project's team
|
|
65
|
+
```
|
|
66
|
+
```
|
|
67
|
+
Team channel: /your/repo/.traintrack/channel.db
|
|
68
|
+
- claude-3f9a (claude, role: lead, live, active)
|
|
69
|
+
- codex-7c12 (codex, role: lead, live, active)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Tell one session: *"send a message to `codex-7c12`: what are you working on?"* — the other surfaces it on its next turn (a `📨 1 unread` nudge), reads it with `check_messages`, and replies.
|
|
73
|
+
|
|
74
|
+
### Lead: blabber, get a team
|
|
75
|
+
|
|
76
|
+
In one session:
|
|
77
|
+
|
|
78
|
+
> "Build a CSV parser, a test suite for it, and a short README — split it up."
|
|
79
|
+
|
|
80
|
+
It proposes which worker takes which part, then on your OK spawns headless workers, collects their results, and hands you the finished work.
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## Commands
|
|
85
|
+
|
|
86
|
+
| Command | What it does |
|
|
87
|
+
| --- | --- |
|
|
88
|
+
| `traintrack setup` | Detect + wire your agent CLIs (interactive). |
|
|
89
|
+
| `traintrack team` | Show this project's team (handles, agent, role, online status). |
|
|
90
|
+
| `traintrack inbox --handle <h>` | Print unread messages for a handle. |
|
|
91
|
+
| `traintrack join --handle <h> --role <r> [--agent claude\|codex]` | Run a headless auto-responding member that joins the team. |
|
|
92
|
+
| `traintrack init` | Create the `.traintrack/` channel for the current project. |
|
|
93
|
+
| `traintrack worker --agent <a> --role <r> --handle <h>` | Run a single headless worker bound to the channel. |
|
|
94
|
+
|
|
95
|
+
**`setup` flags:** `--all`, `--yes`, `--dry-run`, `--tools-only`, `--uninstall`, `--home <path>`.
|
|
96
|
+
**Channel selection (any command):** `--channel <path>`, or `--room <name>` for a shared room across projects (`~/.traintrack/rooms/<name>.db`). The default is your **git repo root** (`<repo>/.traintrack/channel.db`).
|
|
97
|
+
|
|
98
|
+
### The coordination tools your agent gets
|
|
99
|
+
|
|
100
|
+
`list_team` · `check_messages` · `send_message` · `spawn_worker` · `delegate_task` · `await_results` · `join_team`
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## How it works
|
|
105
|
+
|
|
106
|
+
- **The channel is a SQLite file** (WAL) resolved at the **git repo root**, so every session opened in a project shares one team automatically. `--room` gives a shared cross-project bus.
|
|
107
|
+
- **Auto-presence:** each session's MCP server registers itself as a live member on startup and flips to offline when it ends — that's how teammates appear with zero setup.
|
|
108
|
+
- **Auto-receive:** spawned **headless workers** truly auto-respond (they run a drain→turn→reply loop). Hand-driven sessions can't be interrupted mid-task (a CLI limit), so they pick up messages at their next turn — every tool result carries a `📨 N unread` nudge so nothing is missed.
|
|
109
|
+
- **Spawning** = `git worktree add` + a child process, so each worker has an isolated tree and its own provider session.
|
|
110
|
+
- **No daemon, no server, no telemetry.** It's a library + an MCP server + a CLI.
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## Supported CLIs
|
|
115
|
+
|
|
116
|
+
| CLI | Mesh (talk to teammates) | Spawn as a headless worker |
|
|
117
|
+
| --- | --- | --- |
|
|
118
|
+
| Claude Code | ✅ | ✅ |
|
|
119
|
+
| Codex | ✅ | ✅ |
|
|
120
|
+
| OpenCode | ⚠️ wired by `setup`, not yet verified | ⏳ planned |
|
|
121
|
+
| Cursor | ⚠️ wired by `setup`, not yet verified | ⏳ planned |
|
|
122
|
+
|
|
123
|
+
Claude Code and Codex are first-class and live-verified end-to-end. OpenCode and Cursor are wired by `setup` and can join the mesh, but spawning them as headless workers is on the roadmap.
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## Manual setup (advanced)
|
|
128
|
+
|
|
129
|
+
If you'd rather not run the wizard, register the MCP server yourself. Resolve the absolute path with `node -e "console.log(require.resolve('traintrack/dist/mcp-server.js'))"`.
|
|
130
|
+
|
|
131
|
+
- **Claude Code** — add to `~/.claude.json`:
|
|
132
|
+
```json
|
|
133
|
+
{ "mcpServers": { "traintrack": { "command": "node", "args": ["<abs>/dist/mcp-server.js"], "env": { "TRAINTRACK_AGENT": "claude" } } } }
|
|
134
|
+
```
|
|
135
|
+
- **Codex** — add to `~/.codex/config.toml`:
|
|
136
|
+
```toml
|
|
137
|
+
[mcp_servers.traintrack]
|
|
138
|
+
command = "node"
|
|
139
|
+
args = ["<abs>/dist/mcp-server.js"]
|
|
140
|
+
env = { TRAINTRACK_AGENT = "codex" }
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
(Setup also writes a short awareness note into each tool's instructions file — see `traintrack setup --dry-run` for exactly what it would change.)
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## Status
|
|
148
|
+
|
|
149
|
+
Two tiers of maturity:
|
|
150
|
+
|
|
151
|
+
- **Claude Code + Codex — alpha/beta.** The engine (spawn → work → collect, multi-round delegation, live members, the peer mesh, and the one-command installer) is built and **live-verified with real `claude`/`codex` agents** — see `scripts/verify-*.mjs` and [`docs/ARCHITECTURE.md`](docs/ARCHITECTURE.md).
|
|
152
|
+
- **OpenCode + Cursor — pre-pre-alpha.** Wired by `setup` so their sessions join the mesh, but not yet verified end-to-end; spawning them as headless workers is next.
|
|
153
|
+
|
|
154
|
+
Things will change under you while it's early.
|
|
155
|
+
|
|
156
|
+
## License
|
|
157
|
+
|
|
158
|
+
[Apache-2.0](LICENSE) · © 2026 traintrack
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import Database from 'better-sqlite3';
|
|
2
|
+
import { mkdirSync } from 'node:fs';
|
|
3
|
+
import { dirname } from 'node:path';
|
|
4
|
+
export class Channel {
|
|
5
|
+
db;
|
|
6
|
+
dbPath;
|
|
7
|
+
constructor(dbPath) {
|
|
8
|
+
this.dbPath = dbPath;
|
|
9
|
+
mkdirSync(dirname(dbPath), { recursive: true });
|
|
10
|
+
this.db = new Database(dbPath);
|
|
11
|
+
this.db.pragma('journal_mode = WAL');
|
|
12
|
+
this.db.pragma('busy_timeout = 5000');
|
|
13
|
+
this.db.exec(`
|
|
14
|
+
CREATE TABLE IF NOT EXISTS messages (
|
|
15
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
16
|
+
from_handle TEXT NOT NULL, to_handle TEXT NOT NULL,
|
|
17
|
+
body TEXT NOT NULL, type TEXT NOT NULL DEFAULT 'message',
|
|
18
|
+
read INTEGER NOT NULL DEFAULT 0,
|
|
19
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
20
|
+
);
|
|
21
|
+
CREATE TABLE IF NOT EXISTS members (
|
|
22
|
+
handle TEXT PRIMARY KEY, agent TEXT NOT NULL, role TEXT NOT NULL,
|
|
23
|
+
kind TEXT NOT NULL, status TEXT NOT NULL, worktree TEXT
|
|
24
|
+
);`);
|
|
25
|
+
}
|
|
26
|
+
insertMessage(m) {
|
|
27
|
+
const r = this.db.prepare(`INSERT INTO messages (from_handle,to_handle,body,type) VALUES (?,?,?,?)`).run(m.from, m.to, m.body, m.type ?? 'message');
|
|
28
|
+
return Number(r.lastInsertRowid);
|
|
29
|
+
}
|
|
30
|
+
getUnread(handle) {
|
|
31
|
+
return this.db.prepare(`SELECT id, from_handle as "from", to_handle as "to", body, type, read, created_at as createdAt
|
|
32
|
+
FROM messages WHERE to_handle = ? AND read = 0 ORDER BY id`).all(handle);
|
|
33
|
+
}
|
|
34
|
+
/** The last `limit` messages across the whole channel, oldest→newest (for a timeline view). */
|
|
35
|
+
getRecentMessages(limit = 100) {
|
|
36
|
+
return this.db.prepare(`SELECT id, "from", "to", body, type, read, createdAt FROM (
|
|
37
|
+
SELECT id, from_handle as "from", to_handle as "to", body, type, read, created_at as createdAt
|
|
38
|
+
FROM messages ORDER BY id DESC LIMIT ?
|
|
39
|
+
) ORDER BY id ASC`).all(limit);
|
|
40
|
+
}
|
|
41
|
+
markRead(ids) {
|
|
42
|
+
if (ids.length === 0) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const stmt = this.db.prepare(`UPDATE messages SET read = 1 WHERE id = ?`);
|
|
46
|
+
const tx = this.db.transaction((xs) => { for (const x of xs) {
|
|
47
|
+
stmt.run(x);
|
|
48
|
+
} });
|
|
49
|
+
tx(ids);
|
|
50
|
+
}
|
|
51
|
+
addMember(m) {
|
|
52
|
+
this.db.prepare(`INSERT OR REPLACE INTO members (handle,agent,role,kind,status,worktree) VALUES (?,?,?,?,?,?)`).run(m.handle, m.agent, m.role, m.kind, m.status, m.worktree);
|
|
53
|
+
}
|
|
54
|
+
listMembers() {
|
|
55
|
+
return this.db.prepare(`SELECT * FROM members ORDER BY rowid`).all();
|
|
56
|
+
}
|
|
57
|
+
getMember(handle) {
|
|
58
|
+
return this.db.prepare(`SELECT * FROM members WHERE handle = ?`).get(handle) ?? null;
|
|
59
|
+
}
|
|
60
|
+
setStatus(handle, status) {
|
|
61
|
+
this.db.prepare(`UPDATE members SET status = ? WHERE handle = ?`).run(status, handle);
|
|
62
|
+
}
|
|
63
|
+
close() { this.db.close(); }
|
|
64
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Resolve WHICH channel db a traintrack process should attach to. The key design
|
|
2
|
+
// point: default to the GIT REPO ROOT (not cwd) so every session opened anywhere
|
|
3
|
+
// inside a project auto-lands in the SAME team — no flags, no path fiddling.
|
|
4
|
+
//
|
|
5
|
+
// Order of precedence:
|
|
6
|
+
// 1. explicit `channel` (a --channel path)
|
|
7
|
+
// 2. `room` → a shared cross-project room at ~/.traintrack/rooms/<room>.db
|
|
8
|
+
// 3. TRAINTRACK_CHANNEL env
|
|
9
|
+
// 4. git repo root → <root>/.traintrack/channel.db (the common case)
|
|
10
|
+
// 5. cwd → <cwd>/.traintrack/channel.db (non-git fallback)
|
|
11
|
+
import { execFileSync } from 'node:child_process';
|
|
12
|
+
import { join } from 'node:path';
|
|
13
|
+
import { homedir } from 'node:os';
|
|
14
|
+
/** The git repo root for `cwd`, or null if not inside a work tree. */
|
|
15
|
+
export function gitRoot(cwd) {
|
|
16
|
+
try {
|
|
17
|
+
const out = execFileSync('git', ['rev-parse', '--show-toplevel'], {
|
|
18
|
+
cwd,
|
|
19
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
20
|
+
});
|
|
21
|
+
return out.toString().trim() || null;
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** Resolve the channel db path per the precedence above. */
|
|
28
|
+
export function resolveChannelPath(opts = {}) {
|
|
29
|
+
const env = opts.env ?? process.env;
|
|
30
|
+
const cwd = opts.cwd ?? process.cwd();
|
|
31
|
+
if (opts.channel)
|
|
32
|
+
return opts.channel;
|
|
33
|
+
if (opts.room)
|
|
34
|
+
return join(homedir(), '.traintrack', 'rooms', `${sanitizeRoom(opts.room)}.db`);
|
|
35
|
+
if (env['TRAINTRACK_CHANNEL'])
|
|
36
|
+
return env['TRAINTRACK_CHANNEL'];
|
|
37
|
+
const root = (opts.gitRootImpl ?? gitRoot)(cwd);
|
|
38
|
+
return join(root ?? cwd, '.traintrack', 'channel.db');
|
|
39
|
+
}
|
|
40
|
+
/** Room names become a file name; keep them filesystem-safe. */
|
|
41
|
+
function sanitizeRoom(room) {
|
|
42
|
+
return room.replace(/[^a-zA-Z0-9_-]/g, '_') || 'global';
|
|
43
|
+
}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// ─── traintrack CLI ──────────────────────────────────────────────────────────
|
|
3
|
+
// The `traintrack` binary (package.json "bin"). Two subcommands:
|
|
4
|
+
//
|
|
5
|
+
// traintrack init [--channel <path>]
|
|
6
|
+
// Create .traintrack/ and an empty channel db so the workspace is ready for the
|
|
7
|
+
// lead's MCP server and any workers to attach to.
|
|
8
|
+
//
|
|
9
|
+
// traintrack worker --agent <claude|codex> --role <role> --handle <handle> [--channel <path>]
|
|
10
|
+
// Run a long-lived headless worker loop bound to the channel — it drains its
|
|
11
|
+
// inbox, runs a headless agent turn per batch, and replies over the channel.
|
|
12
|
+
//
|
|
13
|
+
// Flag parsing mirrors traintrack-desktop's `headless-worker` block: a small
|
|
14
|
+
// `flag(name)` helper over argv, with the agent validated to the two providers.
|
|
15
|
+
import { Channel } from './channel/channel.js';
|
|
16
|
+
import { resolveChannelPath } from './channel/resolve.js';
|
|
17
|
+
import { runWorker } from './worker/worker.js';
|
|
18
|
+
import { runSetup } from './setup/setup.js';
|
|
19
|
+
import { renderBanner, bannerColorEnabled } from './ui/banner.js';
|
|
20
|
+
import { VERSION } from './index.js';
|
|
21
|
+
const USAGE = `Usage:
|
|
22
|
+
traintrack setup [--all] [--yes] [--dry-run] [--tools-only] [--uninstall] [--home <path>]
|
|
23
|
+
traintrack team [--room <name>] [--channel <path>]
|
|
24
|
+
traintrack inbox --handle <handle> [--room <name>] [--channel <path>]
|
|
25
|
+
traintrack init [--room <name>] [--channel <path>]
|
|
26
|
+
traintrack worker --agent <claude|codex> --role <role> --handle <handle> [--channel <path>]
|
|
27
|
+
traintrack join --handle <handle> --role <role> [--agent <claude|codex>] [--room <name>] [--channel <path>]`;
|
|
28
|
+
/** Read the value following a `--name` flag in argv, or undefined if absent. */
|
|
29
|
+
function flag(args, name) {
|
|
30
|
+
const i = args.indexOf(name);
|
|
31
|
+
return i >= 0 && i + 1 < args.length ? args[i + 1] : undefined;
|
|
32
|
+
}
|
|
33
|
+
/** True if a boolean `--name` flag is present in argv. */
|
|
34
|
+
function has(args, name) {
|
|
35
|
+
return args.includes(name);
|
|
36
|
+
}
|
|
37
|
+
/** Resolve the channel db path from --channel / --room flags, else the git-root
|
|
38
|
+
* default (so sessions in a project auto-share a team). */
|
|
39
|
+
function channelFromArgs(args) {
|
|
40
|
+
return resolveChannelPath({ channel: flag(args, '--channel'), room: flag(args, '--room') });
|
|
41
|
+
}
|
|
42
|
+
function fail(message) {
|
|
43
|
+
process.stderr.write(`${message}\n`);
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
/** Print the branded banner to stdout (colorized only on a real terminal). */
|
|
47
|
+
function showBanner() {
|
|
48
|
+
process.stdout.write(renderBanner({ version: VERSION, color: bannerColorEnabled(process.stdout) }));
|
|
49
|
+
}
|
|
50
|
+
async function main(argv) {
|
|
51
|
+
const command = argv[0];
|
|
52
|
+
const args = argv.slice(1);
|
|
53
|
+
if (!command || command === 'help' || command === '--help' || command === '-h') {
|
|
54
|
+
showBanner();
|
|
55
|
+
process.stdout.write(`${USAGE}\n`);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (command === 'setup') {
|
|
59
|
+
showBanner();
|
|
60
|
+
// TRAINTRACK_SETUP_NO_PATH=1 forces config-hint-only detection (ignores the
|
|
61
|
+
// real PATH) so the hermetic verify script exercises exactly the seeded HOME.
|
|
62
|
+
const noPath = process.env['TRAINTRACK_SETUP_NO_PATH'] === '1';
|
|
63
|
+
await runSetup({
|
|
64
|
+
all: has(args, '--all'),
|
|
65
|
+
yes: has(args, '--yes'),
|
|
66
|
+
dryRun: has(args, '--dry-run'),
|
|
67
|
+
toolsOnly: has(args, '--tools-only'),
|
|
68
|
+
uninstall: has(args, '--uninstall'),
|
|
69
|
+
home: flag(args, '--home'),
|
|
70
|
+
...(noPath ? { onPath: () => false } : {}),
|
|
71
|
+
});
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (command === 'init') {
|
|
75
|
+
// Opening a Channel creates .traintrack/ (mkdir recursive) and the db file with
|
|
76
|
+
// its schema; close it immediately — init just provisions the workspace.
|
|
77
|
+
const channelPath = channelFromArgs(args);
|
|
78
|
+
new Channel(channelPath).close();
|
|
79
|
+
process.stdout.write(`Initialized traintrack channel at ${channelPath}\n`);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (command === 'team') {
|
|
83
|
+
// Show everyone on this project's team and where the channel lives.
|
|
84
|
+
const channelPath = channelFromArgs(args);
|
|
85
|
+
const channel = new Channel(channelPath);
|
|
86
|
+
const members = channel.listMembers();
|
|
87
|
+
channel.close();
|
|
88
|
+
process.stdout.write(`Team channel: ${channelPath}\n`);
|
|
89
|
+
if (members.length === 0) {
|
|
90
|
+
process.stdout.write('No members yet. Open a traintrack-aware session here, or spawn a worker.\n');
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
for (const m of members) {
|
|
94
|
+
process.stdout.write(` - ${m.handle} (${m.agent}, role: ${m.role}, ${m.kind}, ${m.status})\n`);
|
|
95
|
+
}
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (command === 'inbox') {
|
|
99
|
+
// Print the unread messages addressed to a handle (does NOT mark them read).
|
|
100
|
+
const handle = flag(args, '--handle') ?? process.env['TRAINTRACK_HANDLE'];
|
|
101
|
+
if (!handle) {
|
|
102
|
+
fail('inbox: --handle is required (or set TRAINTRACK_HANDLE)');
|
|
103
|
+
}
|
|
104
|
+
const channel = new Channel(channelFromArgs(args));
|
|
105
|
+
const msgs = channel.getUnread(handle);
|
|
106
|
+
channel.close();
|
|
107
|
+
if (msgs.length === 0) {
|
|
108
|
+
process.stdout.write(`No unread messages for ${handle}.\n`);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
process.stdout.write(`${msgs.length} unread for ${handle}:\n`);
|
|
112
|
+
for (const m of msgs) {
|
|
113
|
+
process.stdout.write(` [${m.id}] from ${m.from}: ${m.body}\n`);
|
|
114
|
+
}
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (command === 'worker') {
|
|
118
|
+
const agentRaw = flag(args, '--agent');
|
|
119
|
+
if (agentRaw !== 'claude' && agentRaw !== 'codex') {
|
|
120
|
+
fail('worker: --agent must be "claude" or "codex"');
|
|
121
|
+
}
|
|
122
|
+
const agent = agentRaw;
|
|
123
|
+
const role = flag(args, '--role');
|
|
124
|
+
if (!role) {
|
|
125
|
+
fail('worker: --role is required');
|
|
126
|
+
}
|
|
127
|
+
const handle = flag(args, '--handle');
|
|
128
|
+
if (!handle) {
|
|
129
|
+
fail('worker: --handle is required');
|
|
130
|
+
}
|
|
131
|
+
const channel = new Channel(channelFromArgs(args));
|
|
132
|
+
await runWorker({ channel, handle, agent, role, cwd: process.cwd() });
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
if (command === 'join') {
|
|
136
|
+
const agentRaw = flag(args, '--agent') ?? 'codex';
|
|
137
|
+
if (agentRaw !== 'claude' && agentRaw !== 'codex') {
|
|
138
|
+
fail('join: --agent must be "claude" or "codex"');
|
|
139
|
+
}
|
|
140
|
+
const agent = agentRaw;
|
|
141
|
+
const role = flag(args, '--role');
|
|
142
|
+
if (!role) {
|
|
143
|
+
fail('join: --role is required');
|
|
144
|
+
}
|
|
145
|
+
const handle = flag(args, '--handle');
|
|
146
|
+
if (!handle) {
|
|
147
|
+
fail('join: --handle is required');
|
|
148
|
+
}
|
|
149
|
+
const channel = new Channel(channelFromArgs(args));
|
|
150
|
+
// Reject a duplicate handle rather than clobber the existing member (addMember
|
|
151
|
+
// is INSERT OR REPLACE). Handles must be unique on the team.
|
|
152
|
+
if (channel.getMember(handle)) {
|
|
153
|
+
fail(`join: handle "${handle}" is already on the team — pick a unique --handle`);
|
|
154
|
+
}
|
|
155
|
+
// A LIVE member the user launched and joined to an existing team. It auto-checks
|
|
156
|
+
// its inbox on the same responsive loop as a worker, so it never misses a message.
|
|
157
|
+
await runWorker({ channel, handle, agent, role, cwd: process.cwd(), kind: 'live' });
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
fail(USAGE);
|
|
161
|
+
}
|
|
162
|
+
main(process.argv.slice(2)).catch((err) => {
|
|
163
|
+
fail(err instanceof Error ? err.message : String(err));
|
|
164
|
+
});
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export const VERSION = '0.0.1';
|
|
2
|
+
// Public API — so host apps (e.g. the Traintrack desktop studio) and the
|
|
3
|
+
// ecosystem can consume the channel directly. The CLI/MCP server remain the
|
|
4
|
+
// primary writers; readers (a Coordination Room UI) can open the same channel.
|
|
5
|
+
export { Channel } from './channel/channel.js';
|
|
6
|
+
export { resolveChannelPath, gitRoot } from './channel/resolve.js';
|