ztile-cli 0.3.0 → 0.3.2
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/dist/cli.js
CHANGED
|
@@ -8,7 +8,7 @@ if (args[0] === "hook") {
|
|
|
8
8
|
process.exit(0);
|
|
9
9
|
}
|
|
10
10
|
if (args[0] === "login") {
|
|
11
|
-
const { login } = await import("./login-
|
|
11
|
+
const { login } = await import("./login-5E7FSVVL.js");
|
|
12
12
|
await login({
|
|
13
13
|
apiKey: findArg(args, "--api-key"),
|
|
14
14
|
serverUrl: findArg(args, "--server-url"),
|
|
@@ -29,7 +29,7 @@ if (args[0] === "install") {
|
|
|
29
29
|
process.exit(0);
|
|
30
30
|
}
|
|
31
31
|
if (args[0] === "connect") {
|
|
32
|
-
const { runConnect } = await import("./connect-
|
|
32
|
+
const { runConnect } = await import("./connect-CZ727ZOC.js");
|
|
33
33
|
const projectDir = findArg(args, "--project") ?? process.env["ZTILE_PROJECT"] ?? process.cwd();
|
|
34
34
|
const daemon = args.includes("--daemon") || args.includes("-d");
|
|
35
35
|
await runConnect({ projectDir, daemon });
|
|
@@ -107,6 +107,8 @@ async function sendStreamData(sessionId, workspaceId, data) {
|
|
|
107
107
|
|
|
108
108
|
// src/lib/session-manager.ts
|
|
109
109
|
import { spawn as ptySpawn } from "node-pty";
|
|
110
|
+
import { EventEmitter } from "events";
|
|
111
|
+
var sessionEvents = new EventEmitter();
|
|
110
112
|
var sessions = /* @__PURE__ */ new Map();
|
|
111
113
|
function log(msg) {
|
|
112
114
|
console.log(`[session] ${msg}`);
|
|
@@ -126,10 +128,39 @@ function attachStreamParser(pty, info, commandId) {
|
|
|
126
128
|
info.sessionId = msg.session_id;
|
|
127
129
|
info.status = "running";
|
|
128
130
|
log(`session started: ${info.sessionId}`);
|
|
131
|
+
sessionEvents.emit("message", { type: "init", sessionId: info.sessionId });
|
|
132
|
+
}
|
|
133
|
+
if (msg.type === "assistant" && msg.message) {
|
|
134
|
+
const content = msg.message;
|
|
135
|
+
const texts = content.content?.filter((c) => c.type === "text").map((c) => c.text).filter(Boolean) ?? [];
|
|
136
|
+
if (texts.length > 0) {
|
|
137
|
+
sessionEvents.emit("message", {
|
|
138
|
+
type: "assistant",
|
|
139
|
+
sessionId: info.sessionId,
|
|
140
|
+
text: texts.join("\n")
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (msg.type === "assistant" && msg.message) {
|
|
145
|
+
const content = msg.message;
|
|
146
|
+
const tools = content.content?.filter((c) => c.type === "tool_use").map((c) => c.name).filter(Boolean) ?? [];
|
|
147
|
+
for (const toolName of tools) {
|
|
148
|
+
sessionEvents.emit("message", {
|
|
149
|
+
type: "tool_use",
|
|
150
|
+
sessionId: info.sessionId,
|
|
151
|
+
toolName
|
|
152
|
+
});
|
|
153
|
+
}
|
|
129
154
|
}
|
|
130
155
|
if (msg.type === "result") {
|
|
131
156
|
info.status = "idle";
|
|
132
157
|
log(`session completed: ${info.sessionId} (${msg.duration_ms}ms, $${msg.total_cost_usd})`);
|
|
158
|
+
sessionEvents.emit("message", {
|
|
159
|
+
type: "result",
|
|
160
|
+
sessionId: info.sessionId,
|
|
161
|
+
durationMs: msg.duration_ms,
|
|
162
|
+
costUsd: msg.total_cost_usd
|
|
163
|
+
});
|
|
133
164
|
}
|
|
134
165
|
if (info.sessionId) {
|
|
135
166
|
sendStreamData(info.sessionId, info.workspaceId, msg).catch((err) => {
|
|
@@ -340,6 +371,21 @@ async function runConnect(options) {
|
|
|
340
371
|
log2("!", `Heartbeat failed, retrying...`, YELLOW);
|
|
341
372
|
}
|
|
342
373
|
}, HEARTBEAT_INTERVAL_MS);
|
|
374
|
+
sessionEvents.on("message", (evt) => {
|
|
375
|
+
switch (evt.type) {
|
|
376
|
+
case "assistant": {
|
|
377
|
+
const preview = (evt.text ?? "").split("\n")[0].slice(0, 120);
|
|
378
|
+
log2("\u25C0", `${preview}${(evt.text ?? "").length > 120 ? "..." : ""}`, CYAN);
|
|
379
|
+
break;
|
|
380
|
+
}
|
|
381
|
+
case "tool_use":
|
|
382
|
+
log2("\u2699", `Tool: ${evt.toolName}`, DIM);
|
|
383
|
+
break;
|
|
384
|
+
case "result":
|
|
385
|
+
log2("\u2713", `Done (${((evt.durationMs ?? 0) / 1e3).toFixed(1)}s, $${(evt.costUsd ?? 0).toFixed(4)})`, GREEN);
|
|
386
|
+
break;
|
|
387
|
+
}
|
|
388
|
+
});
|
|
343
389
|
let commandCount = 0;
|
|
344
390
|
const pollTimer = setInterval(async () => {
|
|
345
391
|
try {
|
|
@@ -3,9 +3,7 @@ import {
|
|
|
3
3
|
loadCredentials,
|
|
4
4
|
saveCredentials
|
|
5
5
|
} from "./chunk-XSAVKZSF.js";
|
|
6
|
-
import
|
|
7
|
-
__require
|
|
8
|
-
} from "./chunk-PDX44BCA.js";
|
|
6
|
+
import "./chunk-PDX44BCA.js";
|
|
9
7
|
|
|
10
8
|
// src/commands/login.ts
|
|
11
9
|
import { createInterface } from "readline";
|
|
@@ -19,8 +17,8 @@ async function prompt(question) {
|
|
|
19
17
|
});
|
|
20
18
|
});
|
|
21
19
|
}
|
|
22
|
-
function openBrowser(url) {
|
|
23
|
-
const { execSync } =
|
|
20
|
+
async function openBrowser(url) {
|
|
21
|
+
const { execSync } = await import("child_process");
|
|
24
22
|
try {
|
|
25
23
|
const platform = process.platform;
|
|
26
24
|
if (platform === "darwin") execSync(`open "${url}"`);
|