tencil 0.7.0 → 0.9.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/README.md +35 -6
- package/dist/cli.mjs +51 -471
- package/dist/{cloud-jOobzTY9.d.mts → cloud-dXtv3DCr.d.mts} +1 -1
- package/dist/{index-BRcZL2Ov.d.mts → index-CexSk5_J.d.mts} +29 -1
- package/dist/index.d.mts +77 -8
- package/dist/index.mjs +1 -1
- package/dist/{loader-BevujQ44.mjs → loader-th3V-C7L.mjs} +7 -2
- package/dist/next.d.mts +6 -3
- package/dist/next.mjs +17 -3
- package/dist/overlay.global.js +44 -23
- package/dist/react.d.mts +1 -1
- package/dist/react.mjs +2 -2
- package/dist/{server-1L4Fi2wN.mjs → server-4YposP38.mjs} +1798 -69
- package/dist/source-attributes-Cs2NvuxG.mjs +151 -0
- package/dist/vite.d.mts +1 -1
- package/dist/vite.mjs +3 -151
- package/package.json +7 -6
package/README.md
CHANGED
|
@@ -22,15 +22,17 @@ Think Vercel Comments, except the reviewer on the other side is an agent.
|
|
|
22
22
|
└─────────────┘
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
-
Tencil works with
|
|
25
|
+
Tencil works with three agents. With **T3 Code**, every pin is a real T3 Code thread
|
|
26
26
|
in the project that matches your dev site's folder, so you can continue any
|
|
27
27
|
conversation there. With **Claude Code**, the daemon runs Claude Code itself and
|
|
28
|
-
every pin is a Claude Code session you can resume in a terminal.
|
|
28
|
+
every pin is a Claude Code session you can resume in a terminal. With **Ensemble**,
|
|
29
|
+
every pin is a chat on the Ensemble thread serving your page.
|
|
29
30
|
|
|
30
31
|
## Quick start
|
|
31
32
|
|
|
32
|
-
You need [T3 Code](https://github.com/pingdotgg/t3code) (the desktop app, running)
|
|
33
|
-
[Claude Code](https://docs.claude.com/en/docs/claude-code) (installed and logged in)
|
|
33
|
+
You need [T3 Code](https://github.com/pingdotgg/t3code) (the desktop app, running),
|
|
34
|
+
[Claude Code](https://docs.claude.com/en/docs/claude-code) (installed and logged in) or
|
|
35
|
+
[Ensemble](https://tryensemble.co) (the desktop app, running).
|
|
34
36
|
|
|
35
37
|
```sh
|
|
36
38
|
cd your-app
|
|
@@ -90,7 +92,18 @@ up, and registers it with launchd on macOS, systemd on Linux or Task Scheduler o
|
|
|
90
92
|
Windows. Answer no and run `npx tencil start` after a restart instead.
|
|
91
93
|
|
|
92
94
|
`npx tencil stop` stops it until you next log in; `npx tencil service uninstall`
|
|
93
|
-
removes it.
|
|
95
|
+
removes it.
|
|
96
|
+
|
|
97
|
+
### Updates
|
|
98
|
+
|
|
99
|
+
The daemon looks for a new Tencil when it starts and about once a day. When one
|
|
100
|
+
is out, the overlay's settings show it, with an **Update** button: the daemon
|
|
101
|
+
installs the new version into its runtime copy, waits until no thread is running,
|
|
102
|
+
and restarts on it. If the new version doesn't start, the old one keeps running.
|
|
103
|
+
`npx tencil@latest setup` updates by hand.
|
|
104
|
+
|
|
105
|
+
Set `TENCIL_NO_UPDATE_CHECK=1` to stop the daemon and the CLI asking the npm
|
|
106
|
+
registry; they don't on CI either.
|
|
94
107
|
|
|
95
108
|
### Pairing
|
|
96
109
|
|
|
@@ -110,6 +123,22 @@ repository root. Each pin is a Claude Code session you can also pick up in a
|
|
|
110
123
|
terminal with `claude --resume <id>`. The first time, Tencil installs the Claude
|
|
111
124
|
Agent SDK into its config folder (it brings Claude Code along, about 250 MB).
|
|
112
125
|
|
|
126
|
+
### Ensemble
|
|
127
|
+
|
|
128
|
+
With `--provider ensemble` (or Ensemble picked in a project's settings), keep the
|
|
129
|
+
[Ensemble](https://tryensemble.co) app running. Pair from the overlay or during
|
|
130
|
+
setup and allow “Tencil” once in Ensemble. Tencil stores the token privately;
|
|
131
|
+
if you remove Tencil in Ensemble › Settings › Ensemble API, pair again.
|
|
132
|
+
|
|
133
|
+
Tencil uses the page's dev server port to find its Ensemble thread, including ports
|
|
134
|
+
forwarded from another machine. Each pin creates a separate chat on that thread's
|
|
135
|
+
checkout, so changes reload in the page. A dev server you run yourself, from a folder
|
|
136
|
+
of an Ensemble project (or a worktree of its repository), starts a new Ensemble
|
|
137
|
+
thread per pin instead; that thread works on its own branch, so its changes don't
|
|
138
|
+
reach your page until you merge them. Resolving or deleting the pin archives that
|
|
139
|
+
thread, and reopening the pin or replying to it brings it back. Threads you started
|
|
140
|
+
yourself stay open, and so does one you've added a chat to. If the folder isn't in Ensemble, the overlay names the repository to add.
|
|
141
|
+
|
|
113
142
|
Nobody is at a terminal to approve tool calls, so `--runtime-mode` decides up front:
|
|
114
143
|
`full-access` (the default) lets Claude Code run anything; with the stricter modes,
|
|
115
144
|
tools that would need approval are refused and Claude Code is told why. A turn that
|
|
@@ -148,7 +177,7 @@ tencil service uninstall Remove the login service
|
|
|
148
177
|
tencil connect [pairing-link] Pair with T3 Code (automatic for a local T3 Code)
|
|
149
178
|
|
|
150
179
|
--port <n> Port (default 4747, env TENCIL_PORT)
|
|
151
|
-
--provider <name> Agent for projects without their own: t3code (default) | claude-code
|
|
180
|
+
--provider <name> Agent for projects without their own: t3code (default) | claude-code | ensemble
|
|
152
181
|
--t3-url <url> T3 Code server (default: last paired, then http://127.0.0.1:3773)
|
|
153
182
|
--model <model> T3 Code: instance:model, e.g. claudeAgent:claude-fable-5-1
|
|
154
183
|
Claude Code: a model, e.g. claude-opus-5-5 (default: its default)
|
package/dist/cli.mjs
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { _ as
|
|
2
|
+
import { A as withoutNpmEnv, D as createLocalPairingCode, E as DEFAULT_T3_URL, F as EnsembleClient, O as exchangePairingCredential, P as EnsembleCredentialStore, S as defaultDataDir, T as CredentialStore, _ as detectAgents, a as readPlan, b as savedProvider, c as runtimeDir, d as uninstallService, f as startInBackground, g as PROVIDERS, h as updateNotice, i as finishUpdate, j as loadAgentSdk, k as parsePairingInput, l as isServiceInstalled, m as isNewerThanThis, n as probeDaemon, o as enableAutostart, p as stopDaemon, r as startDaemon, s as ensureDaemon, t as DEFAULT_PORT, u as stopService, v as providerLabel, w as VERSION, y as saveProvider } from "./server-4YposP38.mjs";
|
|
3
3
|
import { t as DEFAULT_CLOUD_URL } from "./cloud-CiwIrP1h.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import { existsSync,
|
|
4
|
+
import { spawnSync } from "node:child_process";
|
|
5
|
+
import { existsSync, rmSync } from "node:fs";
|
|
6
6
|
import { readFile, readdir, writeFile } from "node:fs/promises";
|
|
7
7
|
import { basename, dirname, join, relative, resolve } from "node:path";
|
|
8
8
|
import { parseArgs } from "node:util";
|
|
9
9
|
import { fileURLToPath } from "node:url";
|
|
10
|
-
import { homedir } from "node:os";
|
|
11
10
|
import pc from "picocolors";
|
|
12
11
|
import { createInterface } from "node:readline/promises";
|
|
13
12
|
//#region src/cli/format.ts
|
|
@@ -28,465 +27,6 @@ async function printUpdateNotice(notice, log) {
|
|
|
28
27
|
if (text) log(` ${pc.cyan("↑")} ${text}\n`);
|
|
29
28
|
}
|
|
30
29
|
//#endregion
|
|
31
|
-
//#region src/service/daemon-command.ts
|
|
32
|
-
function daemonArgs(command) {
|
|
33
|
-
return [
|
|
34
|
-
command.cli,
|
|
35
|
-
"daemon",
|
|
36
|
-
"--port",
|
|
37
|
-
String(command.port),
|
|
38
|
-
...command.args ?? []
|
|
39
|
-
];
|
|
40
|
-
}
|
|
41
|
-
//#endregion
|
|
42
|
-
//#region src/service/versions.ts
|
|
43
|
-
/** Compare dotted versions by number (pre-release tags ignored): below 0, 0 or above 0. */
|
|
44
|
-
function compareVersions(a, b) {
|
|
45
|
-
const parts = (version) => version.split("-")[0]?.split(".").map(Number) ?? [];
|
|
46
|
-
const [left, right] = [parts(a), parts(b)];
|
|
47
|
-
for (let i = 0; i < Math.max(left.length, right.length); i++) {
|
|
48
|
-
const difference = (left[i] ?? 0) - (right[i] ?? 0);
|
|
49
|
-
if (difference) return difference;
|
|
50
|
-
}
|
|
51
|
-
return 0;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* npx reuses what it cached for `npx tencil`, so an older Tencil can run after
|
|
55
|
-
* a newer one was set up. It must never replace that newer daemon.
|
|
56
|
-
*/
|
|
57
|
-
function isNewerThanThis(version) {
|
|
58
|
-
return version !== void 0 && compareVersions(version, VERSION) > 0;
|
|
59
|
-
}
|
|
60
|
-
var NewerDaemonError = class extends Error {
|
|
61
|
-
constructor(running) {
|
|
62
|
-
super(`Tencil ${running} is already running and this is ${VERSION}, which is older. Run \`npx tencil@latest\` instead.`);
|
|
63
|
-
this.name = "NewerDaemonError";
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
/** The newest published Tencil, or undefined when the registry doesn't answer quickly. */
|
|
67
|
-
async function latestVersion() {
|
|
68
|
-
const response = await fetch("https://registry.npmjs.org/tencil/latest", { signal: AbortSignal.timeout(1500) }).catch(() => void 0);
|
|
69
|
-
if (!response?.ok) return void 0;
|
|
70
|
-
return (await response.json().catch(() => void 0))?.version;
|
|
71
|
-
}
|
|
72
|
-
/** A one-line nudge when a newer Tencil is published. */
|
|
73
|
-
async function updateNotice() {
|
|
74
|
-
const latest = await latestVersion();
|
|
75
|
-
return latest && isNewerThanThis(latest) ? `Tencil ${latest} is out (this is ${VERSION}): npx tencil@latest` : void 0;
|
|
76
|
-
}
|
|
77
|
-
//#endregion
|
|
78
|
-
//#region src/service/background.ts
|
|
79
|
-
/**
|
|
80
|
-
* Start the daemon in the background unless it already runs. A daemon from an
|
|
81
|
-
* older Tencil version is replaced so pages always get the current overlay;
|
|
82
|
-
* so is one running with other flags than the ones given. Without flags of
|
|
83
|
-
* its own, a replacement keeps the running daemon's (`--listen`, `--t3-url`, …).
|
|
84
|
-
*/
|
|
85
|
-
async function startInBackground(command, dataDir) {
|
|
86
|
-
const running = await probeDaemon(command.port);
|
|
87
|
-
if (running && isNewerThanThis(running.version)) return {
|
|
88
|
-
status: "running",
|
|
89
|
-
pid: running.pid,
|
|
90
|
-
newer: running.version
|
|
91
|
-
};
|
|
92
|
-
const flags = command.args?.length ? command.args : running?.flags ?? [];
|
|
93
|
-
if (running && running.version === VERSION && sameFlags(running.flags, flags)) return {
|
|
94
|
-
status: "running",
|
|
95
|
-
pid: running.pid
|
|
96
|
-
};
|
|
97
|
-
if (running) await stopDaemon(command.port);
|
|
98
|
-
mkdirSync(dataDir, { recursive: true });
|
|
99
|
-
const logFile = openSync(join(dataDir, "daemon.log"), "a");
|
|
100
|
-
spawn(command.node, daemonArgs({
|
|
101
|
-
...command,
|
|
102
|
-
args: flags
|
|
103
|
-
}), {
|
|
104
|
-
detached: true,
|
|
105
|
-
stdio: [
|
|
106
|
-
"ignore",
|
|
107
|
-
logFile,
|
|
108
|
-
logFile
|
|
109
|
-
],
|
|
110
|
-
windowsHide: true
|
|
111
|
-
}).unref();
|
|
112
|
-
const health = await waitForDaemon(command.port, dataDir);
|
|
113
|
-
return {
|
|
114
|
-
status: running ? "restarted" : "started",
|
|
115
|
-
pid: health.pid
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
/** Wait for a daemon on `port` (optionally one of `version`) to answer. */
|
|
119
|
-
async function waitForDaemon(port, dataDir, version) {
|
|
120
|
-
for (let attempt = 0; attempt < 100; attempt++) {
|
|
121
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
122
|
-
const health = await probeDaemon(port);
|
|
123
|
-
if (health && (!version || health.version === version)) return health;
|
|
124
|
-
}
|
|
125
|
-
throw new Error(`The daemon didn't start. See ${join(dataDir, "daemon.log")}.`);
|
|
126
|
-
}
|
|
127
|
-
function sameFlags(a, b) {
|
|
128
|
-
return a.length === b.length && a.every((flag, i) => flag === b[i]);
|
|
129
|
-
}
|
|
130
|
-
/** Stop the daemon answering on `port`. Returns false when none was running. */
|
|
131
|
-
async function stopDaemon(port = DEFAULT_PORT) {
|
|
132
|
-
const running = await probeDaemon(port);
|
|
133
|
-
if (!running) return false;
|
|
134
|
-
try {
|
|
135
|
-
process.kill(running.pid, "SIGTERM");
|
|
136
|
-
} catch {
|
|
137
|
-
return false;
|
|
138
|
-
}
|
|
139
|
-
for (let attempt = 0; attempt < 50; attempt++) {
|
|
140
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
141
|
-
if (!await probeDaemon(port)) return true;
|
|
142
|
-
}
|
|
143
|
-
return true;
|
|
144
|
-
}
|
|
145
|
-
//#endregion
|
|
146
|
-
//#region src/service/login-service.ts
|
|
147
|
-
function serviceNames(port = DEFAULT_PORT) {
|
|
148
|
-
const own = port !== DEFAULT_PORT;
|
|
149
|
-
return {
|
|
150
|
-
label: own ? `dev.tencil.daemon.${port}` : "dev.tencil.daemon",
|
|
151
|
-
unit: own ? `tencil-${port}.service` : "tencil.service",
|
|
152
|
-
task: own ? `Tencil ${port}` : "Tencil"
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* What the daemon needs from the shell that installed it. launchd and systemd
|
|
157
|
-
* start it with a bare PATH (`/usr/bin:/bin`), where nvm's npm and npx, which
|
|
158
|
-
* it runs to pair and to install the Claude Agent SDK, can't be found; and a
|
|
159
|
-
* custom XDG_CONFIG_HOME must reach it, or it reads another data folder than
|
|
160
|
-
* the CLI. npx's and npm's own folders (anything in node_modules) are left out of PATH.
|
|
161
|
-
*/
|
|
162
|
-
function serviceEnvironment(command, env = process.env) {
|
|
163
|
-
const separator = process.platform === "win32" ? ";" : ":";
|
|
164
|
-
const entries = [dirname(command.node), ...(env.PATH ?? "").split(separator)].filter((entry) => entry && !/[\\/](?:_npx|node_modules)[\\/]/.test(entry));
|
|
165
|
-
const environment = { PATH: [...new Set(entries)].join(separator) };
|
|
166
|
-
if (env.XDG_CONFIG_HOME) environment.XDG_CONFIG_HOME = env.XDG_CONFIG_HOME;
|
|
167
|
-
return environment;
|
|
168
|
-
}
|
|
169
|
-
function launchdPlist(command, logPath, environment = {}) {
|
|
170
|
-
const args = [command.node, ...daemonArgs(command)].map((arg) => ` <string>${escapeXml(arg)}</string>`).join("\n");
|
|
171
|
-
const variables = Object.entries(environment).map(([key, value]) => ` <key>${escapeXml(key)}</key>\n <string>${escapeXml(value)}</string>`).join("\n");
|
|
172
|
-
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
173
|
-
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
174
|
-
<plist version="1.0">
|
|
175
|
-
<dict>
|
|
176
|
-
<key>Label</key>
|
|
177
|
-
<string>${serviceNames(command.port).label}</string>
|
|
178
|
-
<key>ProgramArguments</key>
|
|
179
|
-
<array>
|
|
180
|
-
${args}
|
|
181
|
-
</array>
|
|
182
|
-
<key>EnvironmentVariables</key>
|
|
183
|
-
<dict>
|
|
184
|
-
${variables}
|
|
185
|
-
</dict>
|
|
186
|
-
<key>RunAtLoad</key>
|
|
187
|
-
<true/>
|
|
188
|
-
<key>KeepAlive</key>
|
|
189
|
-
<true/>
|
|
190
|
-
<key>StandardOutPath</key>
|
|
191
|
-
<string>${escapeXml(logPath)}</string>
|
|
192
|
-
<key>StandardErrorPath</key>
|
|
193
|
-
<string>${escapeXml(logPath)}</string>
|
|
194
|
-
</dict>
|
|
195
|
-
</plist>
|
|
196
|
-
`;
|
|
197
|
-
}
|
|
198
|
-
function systemdUnit(command, environment = {}) {
|
|
199
|
-
return `[Unit]
|
|
200
|
-
Description=Tencil daemon
|
|
201
|
-
|
|
202
|
-
[Service]
|
|
203
|
-
${Object.entries(environment).map(([key, value]) => `Environment="${key}=${value}"\n`).join("")}ExecStart=${[command.node, ...daemonArgs(command)].map((arg) => `"${arg}"`).join(" ")}
|
|
204
|
-
Restart=on-failure
|
|
205
|
-
|
|
206
|
-
[Install]
|
|
207
|
-
WantedBy=default.target
|
|
208
|
-
`;
|
|
209
|
-
}
|
|
210
|
-
function windowsTaskCommand(command) {
|
|
211
|
-
return [command.node, ...daemonArgs(command)].map((arg) => `"${arg}"`).join(" ");
|
|
212
|
-
}
|
|
213
|
-
const launchAgent = (names) => join(homedir(), "Library", "LaunchAgents", `${names.label}.plist`);
|
|
214
|
-
const systemdUnitPath = (names) => join(homedir(), ".config", "systemd", "user", names.unit);
|
|
215
|
-
const launchdDomain = () => `gui/${process.getuid?.() ?? 501}`;
|
|
216
|
-
/** Whether Tencil is set up to start at login, serving `port`. */
|
|
217
|
-
function isServiceInstalled(port = DEFAULT_PORT) {
|
|
218
|
-
return servicePort(readServiceDefinition(serviceNames(port))) === port;
|
|
219
|
-
}
|
|
220
|
-
/** The daemon port in a launchd plist, systemd unit or scheduled task definition. */
|
|
221
|
-
function servicePort(definition) {
|
|
222
|
-
const match = definition?.match(/--port(?:<\/string>\s*<string>|"?\s+"?|"\s*")(\d+)/);
|
|
223
|
-
return match?.[1] ? Number(match[1]) : void 0;
|
|
224
|
-
}
|
|
225
|
-
/** The launchd plist, systemd unit or scheduled task behind `names`, if installed. */
|
|
226
|
-
function readServiceDefinition(names) {
|
|
227
|
-
try {
|
|
228
|
-
switch (process.platform) {
|
|
229
|
-
case "darwin": return readFileSync(launchAgent(names), "utf8");
|
|
230
|
-
case "linux": return readFileSync(systemdUnitPath(names), "utf8");
|
|
231
|
-
case "win32": return execFileSync("schtasks", [
|
|
232
|
-
"/Query",
|
|
233
|
-
"/TN",
|
|
234
|
-
names.task,
|
|
235
|
-
"/XML"
|
|
236
|
-
], {
|
|
237
|
-
encoding: "utf8",
|
|
238
|
-
stdio: [
|
|
239
|
-
"ignore",
|
|
240
|
-
"pipe",
|
|
241
|
-
"ignore"
|
|
242
|
-
]
|
|
243
|
-
});
|
|
244
|
-
default: return;
|
|
245
|
-
}
|
|
246
|
-
} catch {
|
|
247
|
-
return;
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
/** Install (or replace) the login service and start the daemon through it. */
|
|
251
|
-
async function installService(command, dataDir) {
|
|
252
|
-
const logPath = join(dataDir, "daemon.log");
|
|
253
|
-
const names = serviceNames(command.port);
|
|
254
|
-
const { unit: unitName, task } = names;
|
|
255
|
-
mkdirSync(dataDir, { recursive: true });
|
|
256
|
-
switch (process.platform) {
|
|
257
|
-
case "darwin": {
|
|
258
|
-
const plist = launchAgent(names);
|
|
259
|
-
quietly("launchctl", [
|
|
260
|
-
"bootout",
|
|
261
|
-
launchdDomain(),
|
|
262
|
-
plist
|
|
263
|
-
]);
|
|
264
|
-
await stopDaemon(command.port);
|
|
265
|
-
mkdirSync(join(homedir(), "Library", "LaunchAgents"), { recursive: true });
|
|
266
|
-
writeFileSync(plist, launchdPlist(command, logPath, serviceEnvironment(command)));
|
|
267
|
-
execFileSync("launchctl", [
|
|
268
|
-
"bootstrap",
|
|
269
|
-
launchdDomain(),
|
|
270
|
-
plist
|
|
271
|
-
]);
|
|
272
|
-
return plist;
|
|
273
|
-
}
|
|
274
|
-
case "linux": {
|
|
275
|
-
const unit = systemdUnitPath(names);
|
|
276
|
-
quietly("systemctl", [
|
|
277
|
-
"--user",
|
|
278
|
-
"stop",
|
|
279
|
-
unitName
|
|
280
|
-
]);
|
|
281
|
-
await stopDaemon(command.port);
|
|
282
|
-
mkdirSync(join(homedir(), ".config", "systemd", "user"), { recursive: true });
|
|
283
|
-
writeFileSync(unit, systemdUnit(command, serviceEnvironment(command)));
|
|
284
|
-
execFileSync("systemctl", ["--user", "daemon-reload"]);
|
|
285
|
-
execFileSync("systemctl", [
|
|
286
|
-
"--user",
|
|
287
|
-
"enable",
|
|
288
|
-
"--now",
|
|
289
|
-
unitName
|
|
290
|
-
], { stdio: [
|
|
291
|
-
"ignore",
|
|
292
|
-
"ignore",
|
|
293
|
-
"pipe"
|
|
294
|
-
] });
|
|
295
|
-
return unit;
|
|
296
|
-
}
|
|
297
|
-
case "win32":
|
|
298
|
-
quietly("schtasks", [
|
|
299
|
-
"/End",
|
|
300
|
-
"/TN",
|
|
301
|
-
task
|
|
302
|
-
]);
|
|
303
|
-
await stopDaemon(command.port);
|
|
304
|
-
execFileSync("schtasks", [
|
|
305
|
-
"/Create",
|
|
306
|
-
"/F",
|
|
307
|
-
"/SC",
|
|
308
|
-
"ONLOGON",
|
|
309
|
-
"/TN",
|
|
310
|
-
task,
|
|
311
|
-
"/TR",
|
|
312
|
-
windowsTaskCommand(command)
|
|
313
|
-
]);
|
|
314
|
-
execFileSync("schtasks", [
|
|
315
|
-
"/Run",
|
|
316
|
-
"/TN",
|
|
317
|
-
task
|
|
318
|
-
]);
|
|
319
|
-
return `Task Scheduler: ${task}`;
|
|
320
|
-
default: throw new Error(`Login service isn't supported on ${process.platform}; use \`tencil start\`.`);
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
/** Stop the service's daemon until the next login, without uninstalling it. */
|
|
324
|
-
async function stopService(port = DEFAULT_PORT) {
|
|
325
|
-
const names = serviceNames(port);
|
|
326
|
-
const { unit, task } = names;
|
|
327
|
-
switch (process.platform) {
|
|
328
|
-
case "darwin":
|
|
329
|
-
quietly("launchctl", [
|
|
330
|
-
"bootout",
|
|
331
|
-
launchdDomain(),
|
|
332
|
-
launchAgent(names)
|
|
333
|
-
]);
|
|
334
|
-
break;
|
|
335
|
-
case "linux":
|
|
336
|
-
quietly("systemctl", [
|
|
337
|
-
"--user",
|
|
338
|
-
"stop",
|
|
339
|
-
unit
|
|
340
|
-
]);
|
|
341
|
-
break;
|
|
342
|
-
case "win32": quietly("schtasks", [
|
|
343
|
-
"/End",
|
|
344
|
-
"/TN",
|
|
345
|
-
task
|
|
346
|
-
]);
|
|
347
|
-
}
|
|
348
|
-
await stopDaemon(port);
|
|
349
|
-
}
|
|
350
|
-
async function uninstallService(port = DEFAULT_PORT) {
|
|
351
|
-
removeService(serviceNames(port));
|
|
352
|
-
await stopDaemon(port);
|
|
353
|
-
}
|
|
354
|
-
/** Unload and delete the service behind `names`, wherever it is in its life. */
|
|
355
|
-
function removeService(names) {
|
|
356
|
-
switch (process.platform) {
|
|
357
|
-
case "darwin":
|
|
358
|
-
quietly("launchctl", [
|
|
359
|
-
"bootout",
|
|
360
|
-
launchdDomain(),
|
|
361
|
-
launchAgent(names)
|
|
362
|
-
]);
|
|
363
|
-
rmSync(launchAgent(names), { force: true });
|
|
364
|
-
break;
|
|
365
|
-
case "linux":
|
|
366
|
-
quietly("systemctl", [
|
|
367
|
-
"--user",
|
|
368
|
-
"disable",
|
|
369
|
-
"--now",
|
|
370
|
-
names.unit
|
|
371
|
-
]);
|
|
372
|
-
rmSync(systemdUnitPath(names), { force: true });
|
|
373
|
-
quietly("systemctl", ["--user", "daemon-reload"]);
|
|
374
|
-
break;
|
|
375
|
-
case "win32":
|
|
376
|
-
quietly("schtasks", [
|
|
377
|
-
"/End",
|
|
378
|
-
"/TN",
|
|
379
|
-
names.task
|
|
380
|
-
]);
|
|
381
|
-
quietly("schtasks", [
|
|
382
|
-
"/Delete",
|
|
383
|
-
"/F",
|
|
384
|
-
"/TN",
|
|
385
|
-
names.task
|
|
386
|
-
]);
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
/** Run a command whose failure only means "nothing to do" (not loaded, already gone). */
|
|
390
|
-
function quietly(command, args) {
|
|
391
|
-
try {
|
|
392
|
-
execFileSync(command, args, { stdio: "ignore" });
|
|
393
|
-
} catch {}
|
|
394
|
-
}
|
|
395
|
-
function escapeXml(value) {
|
|
396
|
-
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
397
|
-
}
|
|
398
|
-
//#endregion
|
|
399
|
-
//#region src/service/autostart.ts
|
|
400
|
-
/**
|
|
401
|
-
* Running from a package manager's install (npx's cache, a project, a global
|
|
402
|
-
* prefix) rather than a source checkout. Those can be cleaned up or upgraded
|
|
403
|
-
* under a login service, so it gets its own copy.
|
|
404
|
-
*/
|
|
405
|
-
function isPackageInstall(cliPath) {
|
|
406
|
-
return /[\\/]node_modules[\\/]/.test(cliPath);
|
|
407
|
-
}
|
|
408
|
-
/** The login service's own copy of Tencil; one per port, like the service. */
|
|
409
|
-
function runtimeDir(dataDir, port = DEFAULT_PORT) {
|
|
410
|
-
return join(dataDir, port === 4747 ? "runtime" : `runtime-${port}`);
|
|
411
|
-
}
|
|
412
|
-
function runtimeCli(dataDir, port = DEFAULT_PORT) {
|
|
413
|
-
return join(runtimeDir(dataDir, port), "node_modules", "tencil", "dist", "cli.mjs");
|
|
414
|
-
}
|
|
415
|
-
function runtimeInstallArgs(dataDir, spec, port = DEFAULT_PORT) {
|
|
416
|
-
return [
|
|
417
|
-
"install",
|
|
418
|
-
"--prefix",
|
|
419
|
-
runtimeDir(dataDir, port),
|
|
420
|
-
spec,
|
|
421
|
-
"--no-audit",
|
|
422
|
-
"--no-fund",
|
|
423
|
-
"--loglevel=error"
|
|
424
|
-
];
|
|
425
|
-
}
|
|
426
|
-
/**
|
|
427
|
-
* Start Tencil at login and now. Keeps the running daemon's flags unless new
|
|
428
|
-
* ones are given. `from` installs another package spec (a local tarball) as
|
|
429
|
-
* the service's copy instead of this version from npm.
|
|
430
|
-
*/
|
|
431
|
-
async function enableAutostart(command, dataDir, from) {
|
|
432
|
-
const running = await probeDaemon(command.port);
|
|
433
|
-
if (running && isNewerThanThis(running.version)) throw new NewerDaemonError(running.version);
|
|
434
|
-
const args = command.args?.length ? command.args : running?.flags ?? [];
|
|
435
|
-
let cli = command.cli;
|
|
436
|
-
if (isPackageInstall(cli)) {
|
|
437
|
-
const spec = from && existsSync(from) ? resolve(from) : from ?? `tencil@${VERSION}`;
|
|
438
|
-
const result = spawnSync(process.platform === "win32" ? "npm.cmd" : "npm", runtimeInstallArgs(dataDir, spec, command.port), {
|
|
439
|
-
encoding: "utf8",
|
|
440
|
-
stdio: [
|
|
441
|
-
"ignore",
|
|
442
|
-
"ignore",
|
|
443
|
-
"pipe"
|
|
444
|
-
],
|
|
445
|
-
shell: process.platform === "win32",
|
|
446
|
-
env: withoutNpmEnv()
|
|
447
|
-
});
|
|
448
|
-
if (result.status !== 0) throw new Error(`Couldn't install Tencil for the login service (npm ${result.status ?? "failed"}): ${result.stderr?.trim() ?? ""}`);
|
|
449
|
-
cli = runtimeCli(dataDir, command.port);
|
|
450
|
-
}
|
|
451
|
-
const where = await installService({
|
|
452
|
-
...command,
|
|
453
|
-
cli,
|
|
454
|
-
args
|
|
455
|
-
}, dataDir);
|
|
456
|
-
await waitForDaemon(command.port, dataDir);
|
|
457
|
-
return where;
|
|
458
|
-
}
|
|
459
|
-
/**
|
|
460
|
-
* Make sure this version of the daemon runs. With a login service it is
|
|
461
|
-
* updated in place, since stopping its daemon would only make it restart.
|
|
462
|
-
*/
|
|
463
|
-
async function ensureDaemon(command, dataDir) {
|
|
464
|
-
if (!isServiceInstalled(command.port)) {
|
|
465
|
-
const { status, newer } = await startInBackground(command, dataDir);
|
|
466
|
-
return {
|
|
467
|
-
status,
|
|
468
|
-
autostart: false,
|
|
469
|
-
newer
|
|
470
|
-
};
|
|
471
|
-
}
|
|
472
|
-
const running = await probeDaemon(command.port);
|
|
473
|
-
if (running && isNewerThanThis(running.version)) return {
|
|
474
|
-
status: "running",
|
|
475
|
-
autostart: true,
|
|
476
|
-
newer: running.version
|
|
477
|
-
};
|
|
478
|
-
const flags = command.args?.length ? command.args : running?.flags ?? [];
|
|
479
|
-
if (running && running.version === VERSION && sameFlags(running.flags, flags)) return {
|
|
480
|
-
status: "running",
|
|
481
|
-
autostart: true
|
|
482
|
-
};
|
|
483
|
-
await enableAutostart(command, dataDir);
|
|
484
|
-
return {
|
|
485
|
-
status: running ? "restarted" : "started",
|
|
486
|
-
autostart: true
|
|
487
|
-
};
|
|
488
|
-
}
|
|
489
|
-
//#endregion
|
|
490
30
|
//#region src/service/choose-provider.ts
|
|
491
31
|
/**
|
|
492
32
|
* The agent pins go to on this machine. Asked once: kept from an earlier run
|
|
@@ -508,14 +48,14 @@ async function chooseProvider(options) {
|
|
|
508
48
|
return provider;
|
|
509
49
|
}
|
|
510
50
|
if (options.yes || !process.stdin.isTTY) return "t3code";
|
|
511
|
-
const provider = await ask(installed
|
|
51
|
+
const provider = await ask(installed, options.log);
|
|
512
52
|
await saveProvider(provider);
|
|
513
53
|
options.log(` ${pc.green("✓")} Pins go to ${providerLabel(provider)}.`);
|
|
514
54
|
hint();
|
|
515
55
|
return provider;
|
|
516
56
|
}
|
|
517
|
-
async function ask(
|
|
518
|
-
log(
|
|
57
|
+
async function ask(installed, log) {
|
|
58
|
+
log(installed.length === 0 ? ` None of ${listOf(PROVIDERS)} was found. Which one will you use?` : ` ${listOf(installed)} are here. Which agent should pins go to?`);
|
|
519
59
|
PROVIDERS.forEach((id, index) => {
|
|
520
60
|
log(` ${pc.cyan(String(index + 1))} ${providerLabel(id)}`);
|
|
521
61
|
});
|
|
@@ -528,11 +68,16 @@ async function ask(noneFound, log) {
|
|
|
528
68
|
const index = Number.parseInt(answer.trim(), 10) - 1;
|
|
529
69
|
return PROVIDERS[index] ?? PROVIDERS[0];
|
|
530
70
|
}
|
|
71
|
+
function listOf(ids) {
|
|
72
|
+
const labels = ids.map(providerLabel);
|
|
73
|
+
return labels.length > 1 ? `${labels.slice(0, -1).join(", ")} and ${labels.at(-1)}` : labels[0] ?? "";
|
|
74
|
+
}
|
|
531
75
|
//#endregion
|
|
532
76
|
//#region src/service/pairing.ts
|
|
533
77
|
/** Get the agent ready now, so the first page load is ready to go. */
|
|
534
78
|
async function prepareProvider(provider, t3Url, log) {
|
|
535
79
|
if (provider === "claude-code") return prepareClaudeCode(log);
|
|
80
|
+
if (provider === "ensemble") return checkEnsemble(log);
|
|
536
81
|
return pairWithLocalT3(t3Url, log);
|
|
537
82
|
}
|
|
538
83
|
/** Pair with the local T3 Code. */
|
|
@@ -567,6 +112,29 @@ async function prepareClaudeCode(log) {
|
|
|
567
112
|
log(` ${pc.yellow("!")} ${error instanceof Error ? error.message : String(error)}`);
|
|
568
113
|
}
|
|
569
114
|
}
|
|
115
|
+
/** Ask the user once to allow Tencil in Ensemble, unless Tencil's token still works. */
|
|
116
|
+
async function checkEnsemble(log) {
|
|
117
|
+
const client = new EnsembleClient();
|
|
118
|
+
if (!await client.isRunning()) {
|
|
119
|
+
log(` ${pc.yellow("!")} Ensemble isn't running. Open the Ensemble app, then press Pair in the overlay.`);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const credentials = new EnsembleCredentialStore();
|
|
123
|
+
const token = await credentials.get(client.baseUrl);
|
|
124
|
+
const allowed = token !== void 0 && await new EnsembleClient({
|
|
125
|
+
baseUrl: client.baseUrl,
|
|
126
|
+
token
|
|
127
|
+
}).threads().then(() => true, () => false);
|
|
128
|
+
try {
|
|
129
|
+
if (!allowed) {
|
|
130
|
+
log(" Allow Tencil in the Ensemble app (one time)…");
|
|
131
|
+
await credentials.set(client.baseUrl, await client.connect());
|
|
132
|
+
}
|
|
133
|
+
log(` ${pc.green("✓")} Connected to Ensemble. Pins go to the Ensemble thread serving each page.`);
|
|
134
|
+
} catch (error) {
|
|
135
|
+
log(` ${pc.yellow("!")} ${error instanceof Error ? error.message : String(error)}`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
570
138
|
//#endregion
|
|
571
139
|
//#region src/init/codemods.ts
|
|
572
140
|
function detectStyle(source) {
|
|
@@ -1086,7 +654,7 @@ function parseModel(value) {
|
|
|
1086
654
|
}
|
|
1087
655
|
//#endregion
|
|
1088
656
|
//#region src/cli/commands/daemon.ts
|
|
1089
|
-
async function runDaemon(values, port, provider, t3Url, runtimeMode) {
|
|
657
|
+
async function runDaemon(values, port, provider, t3Url, runtimeMode, cli) {
|
|
1090
658
|
const model = values.model;
|
|
1091
659
|
const t3Model = model?.includes(":") ? model : void 0;
|
|
1092
660
|
const daemon = await startDaemon({
|
|
@@ -1105,7 +673,8 @@ async function runDaemon(values, port, provider, t3Url, runtimeMode) {
|
|
|
1105
673
|
createProjectIfMissing: !values["no-create-project"]
|
|
1106
674
|
},
|
|
1107
675
|
log: (message) => console.log(`${pc.dim(time())} ${message}`),
|
|
1108
|
-
flags: forwardedFlags(values)
|
|
676
|
+
flags: forwardedFlags(values),
|
|
677
|
+
cli
|
|
1109
678
|
}).catch((error) => {
|
|
1110
679
|
if (error.code === "EADDRINUSE") throw new Error(`Port ${port} is in use. Is Tencil already running? Try \`tencil status\`.`);
|
|
1111
680
|
throw error;
|
|
@@ -1118,6 +687,16 @@ async function runDaemon(values, port, provider, t3Url, runtimeMode) {
|
|
|
1118
687
|
process.once("SIGTERM", shutdown);
|
|
1119
688
|
}
|
|
1120
689
|
//#endregion
|
|
690
|
+
//#region src/cli/commands/finish-update.ts
|
|
691
|
+
/** Move the daemon to a staged version (see `service/self-update.ts`). Logs to daemon.log. */
|
|
692
|
+
async function finishUpdateCommand(planPath) {
|
|
693
|
+
if (!planPath) throw new Error("finish-update needs the update plan");
|
|
694
|
+
const plan = readPlan(planPath);
|
|
695
|
+
const log = (message) => console.log(`${pc.dim(time())} ${message}`);
|
|
696
|
+
log(`Updating the daemon on port ${plan.port} to Tencil ${plan.version}`);
|
|
697
|
+
log(await finishUpdate(plan) ? `Tencil ${plan.version} is running` : `Tencil ${plan.version} didn't start; went back to the previous version`);
|
|
698
|
+
}
|
|
699
|
+
//#endregion
|
|
1121
700
|
//#region src/cli/commands/setup.ts
|
|
1122
701
|
/** `tencil setup`: once per machine. Starts the daemon (at login, by default) and pairs. */
|
|
1123
702
|
async function setup(command, options = {}) {
|
|
@@ -1284,7 +863,7 @@ ${pc.dim("Usage")}
|
|
|
1284
863
|
|
|
1285
864
|
${pc.dim("Daemon options")}
|
|
1286
865
|
--port <n> Port (default ${DEFAULT_PORT}, env TENCIL_PORT)
|
|
1287
|
-
--provider <name> t3code | claude-code: this machine's agent (setup asks when unset)
|
|
866
|
+
--provider <name> t3code | claude-code | ensemble: this machine's agent (setup asks when unset)
|
|
1288
867
|
--t3-url <url> T3 Code server (default ${DEFAULT_T3_URL}, env TENCIL_T3_URL)
|
|
1289
868
|
--model <model> T3 Code: instance:model, e.g. claudeAgent:claude-fable-5-1
|
|
1290
869
|
Claude Code: a model, e.g. claude-opus-5-5 (default: its default)
|
|
@@ -1366,9 +945,9 @@ async function main() {
|
|
|
1366
945
|
from: values.from,
|
|
1367
946
|
t3Url
|
|
1368
947
|
});
|
|
1369
|
-
case "daemon": return runDaemon(values, port, provider, t3Url, runtimeMode);
|
|
948
|
+
case "daemon": return runDaemon(values, port, provider, t3Url, runtimeMode, daemonCommand.cli);
|
|
1370
949
|
case "start":
|
|
1371
|
-
if (values.foreground) return runDaemon(values, port, provider, t3Url, runtimeMode);
|
|
950
|
+
if (values.foreground) return runDaemon(values, port, provider, t3Url, runtimeMode, daemonCommand.cli);
|
|
1372
951
|
return start(daemonCommand);
|
|
1373
952
|
case "setup": return setup(daemonCommand, {
|
|
1374
953
|
yes: values.yes,
|
|
@@ -1387,6 +966,7 @@ async function main() {
|
|
|
1387
966
|
case "status": return status(port);
|
|
1388
967
|
case "service": return service(rest[0], daemonCommand, values.from);
|
|
1389
968
|
case "connect": return connect(rest[0], t3Url);
|
|
969
|
+
case "finish-update": return finishUpdateCommand(rest[0]);
|
|
1390
970
|
case "init": return runInit({
|
|
1391
971
|
root: resolve(values.root ?? process.cwd()),
|
|
1392
972
|
yes: values.yes,
|