testingterm 0.0.0-stage → 0.0.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/AGENT-DOCS.md +77 -0
- package/LICENSE +21 -0
- package/dist/ai.d.ts +24 -0
- package/dist/attach.d.ts +6 -0
- package/dist/capabilities.d.ts +6 -0
- package/dist/chunks/ai-MISD5ZKB.js +260 -0
- package/dist/chunks/args-FJPX5SKE.js +8 -0
- package/dist/chunks/attach-STVPRW4U.js +30 -0
- package/dist/chunks/chunk-66N3P624.js +44 -0
- package/dist/chunks/chunk-IJ5VA4HN.js +41 -0
- package/dist/chunks/chunk-INTJPVJZ.js +191 -0
- package/dist/chunks/chunk-NM755IGG.js +658 -0
- package/dist/chunks/chunk-PA67Y4XN.js +65 -0
- package/dist/chunks/chunk-U52LFC23.js +68 -0
- package/dist/chunks/chunk-YFGNBX2I.js +229 -0
- package/dist/chunks/chunk-YHQYNBAN.js +801 -0
- package/dist/chunks/commands-IWTFRW33.js +540 -0
- package/dist/chunks/context-QML5TP36.js +14 -0
- package/dist/chunks/help-I5WIJHZM.js +359 -0
- package/dist/chunks/paths-X3C4P67K.js +18 -0
- package/dist/chunks/run-RNFQMMXD.js +95 -0
- package/dist/chunks/setup-WIZULKES.js +106 -0
- package/dist/chunks/themes.gen-E3CTYIQE.js +8 -0
- package/dist/chunks/upgrade-43JWCQ63.js +143 -0
- package/dist/chunks/verify-55DFXJOY.js +37 -0
- package/dist/cli/args.d.ts +13 -0
- package/dist/cli/commands.d.ts +5 -0
- package/dist/cli/help.d.ts +2 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +83 -0
- package/dist/cli/run.d.ts +2 -0
- package/dist/cli/setup.d.ts +6 -0
- package/dist/cli/upgrade.d.ts +19 -0
- package/dist/cli/verify.d.ts +2 -0
- package/dist/context.d.ts +33 -0
- package/dist/engine.d.ts +56 -0
- package/dist/errors.d.ts +4 -0
- package/dist/expect.d.ts +62 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +205 -0
- package/dist/install.d.ts +13 -0
- package/dist/instances.d.ts +23 -0
- package/dist/locator.d.ts +49 -0
- package/dist/paths.d.ts +7 -0
- package/dist/runner.d.ts +56 -0
- package/dist/sync.d.ts +8 -0
- package/dist/terminal.d.ts +146 -0
- package/dist/themes.gen.d.ts +4 -0
- package/dist/types.d.ts +214 -0
- package/package.json +41 -4
- package/skill/testingterm/SKILL.md +138 -0
- package/README.md +0 -3
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// src/cli/args.ts
|
|
2
|
+
var Args = class {
|
|
3
|
+
rest;
|
|
4
|
+
passthrough;
|
|
5
|
+
constructor(argv) {
|
|
6
|
+
const dash = argv.indexOf("--");
|
|
7
|
+
this.rest = dash === -1 ? [...argv] : argv.slice(0, dash);
|
|
8
|
+
this.passthrough = dash === -1 ? [] : argv.slice(dash + 1);
|
|
9
|
+
}
|
|
10
|
+
flag(...names) {
|
|
11
|
+
let found = false;
|
|
12
|
+
for (const name of names) {
|
|
13
|
+
let at = this.rest.indexOf(name);
|
|
14
|
+
while (at !== -1) {
|
|
15
|
+
found = true;
|
|
16
|
+
this.rest.splice(at, 1);
|
|
17
|
+
at = this.rest.indexOf(name);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return found;
|
|
21
|
+
}
|
|
22
|
+
value(...names) {
|
|
23
|
+
for (const name of names) {
|
|
24
|
+
const at = this.rest.indexOf(name);
|
|
25
|
+
if (at === -1) continue;
|
|
26
|
+
const value = this.rest[at + 1];
|
|
27
|
+
if (value === void 0) throw new UsageError(`${name} needs a value`);
|
|
28
|
+
this.rest.splice(at, 2);
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
return void 0;
|
|
32
|
+
}
|
|
33
|
+
optional(name) {
|
|
34
|
+
const at = this.rest.indexOf(name);
|
|
35
|
+
if (at === -1) return void 0;
|
|
36
|
+
const value = this.rest[at + 1];
|
|
37
|
+
if (value === void 0 || value.startsWith("--")) {
|
|
38
|
+
this.rest.splice(at, 1);
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
this.rest.splice(at, 2);
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
values(name) {
|
|
45
|
+
const out = [];
|
|
46
|
+
for (let value = this.value(name); value !== void 0; value = this.value(name)) out.push(value);
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
number(...names) {
|
|
50
|
+
const raw = this.value(...names);
|
|
51
|
+
if (raw === void 0) return void 0;
|
|
52
|
+
const value = Number(raw);
|
|
53
|
+
if (!Number.isFinite(value)) throw new UsageError(`${names[0]} needs a number, got ${raw}`);
|
|
54
|
+
return value;
|
|
55
|
+
}
|
|
56
|
+
positional() {
|
|
57
|
+
const unknown = this.rest.find((arg) => /^--?[a-zA-Z]/.test(arg) && !/^-\d/.test(arg));
|
|
58
|
+
if (unknown) throw new UsageError(`unknown option ${unknown}`);
|
|
59
|
+
return this.rest;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
var UsageError = class extends Error {
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export {
|
|
66
|
+
Args,
|
|
67
|
+
UsageError
|
|
68
|
+
};
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import {
|
|
2
|
+
INSTANCES_DIR,
|
|
3
|
+
SOCKETS_DIR,
|
|
4
|
+
engineBinary
|
|
5
|
+
} from "./chunk-PA67Y4XN.js";
|
|
6
|
+
|
|
7
|
+
// src/errors.ts
|
|
8
|
+
var EngineError = class extends Error {
|
|
9
|
+
screen;
|
|
10
|
+
constructor(message, screen) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = "EngineError";
|
|
13
|
+
this.screen = screen;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// src/engine.ts
|
|
18
|
+
import { spawn } from "node:child_process";
|
|
19
|
+
import net from "node:net";
|
|
20
|
+
var Connection = class {
|
|
21
|
+
next = 1;
|
|
22
|
+
pending = /* @__PURE__ */ new Map();
|
|
23
|
+
buffer = "";
|
|
24
|
+
closed = null;
|
|
25
|
+
exit = null;
|
|
26
|
+
onExit = null;
|
|
27
|
+
onBusy = null;
|
|
28
|
+
write;
|
|
29
|
+
end;
|
|
30
|
+
constructor(write, end) {
|
|
31
|
+
this.write = write;
|
|
32
|
+
this.end = end;
|
|
33
|
+
}
|
|
34
|
+
data(chunk) {
|
|
35
|
+
this.buffer += chunk;
|
|
36
|
+
let newline = this.buffer.indexOf("\n");
|
|
37
|
+
while (newline !== -1) {
|
|
38
|
+
const line = this.buffer.slice(0, newline);
|
|
39
|
+
this.buffer = this.buffer.slice(newline + 1);
|
|
40
|
+
newline = this.buffer.indexOf("\n");
|
|
41
|
+
if (!line) continue;
|
|
42
|
+
let message;
|
|
43
|
+
try {
|
|
44
|
+
message = JSON.parse(line);
|
|
45
|
+
} catch {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (message.event === "exit") {
|
|
49
|
+
this.exit = { exitCode: message.exitCode ?? null, signal: message.signal ?? null };
|
|
50
|
+
this.onExit?.(this.exit);
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const id = message.id;
|
|
54
|
+
const waiter = this.pending.get(id);
|
|
55
|
+
if (!waiter) continue;
|
|
56
|
+
this.pending.delete(id);
|
|
57
|
+
if (this.pending.size === 0) this.onBusy?.(false);
|
|
58
|
+
if (message.ok === false) waiter.reject(new EngineError(String(message.error), message.screen));
|
|
59
|
+
else waiter.resolve(message);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
fail(error) {
|
|
63
|
+
this.closed = error;
|
|
64
|
+
for (const waiter of this.pending.values()) waiter.reject(error);
|
|
65
|
+
this.pending.clear();
|
|
66
|
+
}
|
|
67
|
+
request(op, params = {}) {
|
|
68
|
+
if (this.closed) return Promise.reject(this.closed);
|
|
69
|
+
const id = this.next++;
|
|
70
|
+
return new Promise((resolve, reject) => {
|
|
71
|
+
if (this.pending.size === 0) this.onBusy?.(true);
|
|
72
|
+
this.pending.set(id, { resolve, reject });
|
|
73
|
+
this.write(`${JSON.stringify({ id, op, ...params })}
|
|
74
|
+
`);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
close() {
|
|
78
|
+
this.end();
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
var live = /* @__PURE__ */ new Set();
|
|
82
|
+
process.once("exit", () => {
|
|
83
|
+
for (const child of live) child.stdin?.end();
|
|
84
|
+
});
|
|
85
|
+
function startEngine(config) {
|
|
86
|
+
const child = spawn(engineBinary(config.headed), ["--config", JSON.stringify(config)], {
|
|
87
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
88
|
+
env: process.env
|
|
89
|
+
});
|
|
90
|
+
let stderr = "";
|
|
91
|
+
const connection = new Connection(
|
|
92
|
+
(line) => child.stdin.write(line),
|
|
93
|
+
() => child.stdin.end()
|
|
94
|
+
);
|
|
95
|
+
child.stdout.setEncoding("utf8");
|
|
96
|
+
child.stdout.on("data", (chunk) => connection.data(chunk));
|
|
97
|
+
child.stderr.setEncoding("utf8");
|
|
98
|
+
const debug = Boolean(process.env.TESTINGTERM_DEBUG);
|
|
99
|
+
child.stderr.on("data", (chunk) => {
|
|
100
|
+
if (debug) process.stderr.write(chunk);
|
|
101
|
+
stderr = (stderr + chunk).slice(-4e3);
|
|
102
|
+
});
|
|
103
|
+
child.stdin.on("error", () => {
|
|
104
|
+
});
|
|
105
|
+
const handles = [child.stdout, child.stderr, child.stdin];
|
|
106
|
+
const idle = () => {
|
|
107
|
+
for (const handle of handles) handle.unref?.();
|
|
108
|
+
child.unref();
|
|
109
|
+
};
|
|
110
|
+
connection.onBusy = (busy) => {
|
|
111
|
+
if (!busy) return idle();
|
|
112
|
+
for (const handle of handles) handle.ref?.();
|
|
113
|
+
child.ref();
|
|
114
|
+
};
|
|
115
|
+
idle();
|
|
116
|
+
live.add(child);
|
|
117
|
+
child.on("error", (error) => connection.fail(error));
|
|
118
|
+
child.on("exit", (code) => {
|
|
119
|
+
live.delete(child);
|
|
120
|
+
const detail = stderr.trim().split("\n").at(-1);
|
|
121
|
+
connection.fail(new EngineError(detail && code ? `the terminal stopped: ${detail}` : "the terminal is closed"));
|
|
122
|
+
});
|
|
123
|
+
return { connection, process: child };
|
|
124
|
+
}
|
|
125
|
+
function connectSocket(socketPath2) {
|
|
126
|
+
return new Promise((resolve, reject) => {
|
|
127
|
+
const socket = net.connect(socketPath2);
|
|
128
|
+
const connection = new Connection(
|
|
129
|
+
(line) => socket.write(line),
|
|
130
|
+
() => socket.end()
|
|
131
|
+
);
|
|
132
|
+
socket.setEncoding("utf8");
|
|
133
|
+
socket.on("data", (chunk) => connection.data(chunk));
|
|
134
|
+
socket.once("connect", () => resolve(connection));
|
|
135
|
+
socket.once("error", (error) => {
|
|
136
|
+
reject(error);
|
|
137
|
+
connection.fail(error);
|
|
138
|
+
});
|
|
139
|
+
socket.on("close", () => connection.fail(new EngineError("the terminal is closed")));
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// src/instances.ts
|
|
144
|
+
import fs from "node:fs";
|
|
145
|
+
import path from "node:path";
|
|
146
|
+
function newId() {
|
|
147
|
+
return Math.random().toString(36).slice(2, 6);
|
|
148
|
+
}
|
|
149
|
+
function socketPath(id) {
|
|
150
|
+
return path.join(SOCKETS_DIR, `${id}.sock`);
|
|
151
|
+
}
|
|
152
|
+
function writeInstance(record) {
|
|
153
|
+
fs.mkdirSync(INSTANCES_DIR, { recursive: true });
|
|
154
|
+
fs.writeFileSync(path.join(INSTANCES_DIR, `${record.id}.json`), JSON.stringify(record));
|
|
155
|
+
}
|
|
156
|
+
function removeInstance(id) {
|
|
157
|
+
fs.rmSync(path.join(INSTANCES_DIR, `${id}.json`), { force: true });
|
|
158
|
+
fs.rmSync(socketPath(id), { force: true });
|
|
159
|
+
}
|
|
160
|
+
function alive(pid) {
|
|
161
|
+
try {
|
|
162
|
+
process.kill(pid, 0);
|
|
163
|
+
return true;
|
|
164
|
+
} catch (error) {
|
|
165
|
+
return error.code === "EPERM";
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
function listInstances() {
|
|
169
|
+
let names;
|
|
170
|
+
try {
|
|
171
|
+
names = fs.readdirSync(INSTANCES_DIR);
|
|
172
|
+
} catch {
|
|
173
|
+
return [];
|
|
174
|
+
}
|
|
175
|
+
const records = [];
|
|
176
|
+
for (const name of names) {
|
|
177
|
+
if (!name.endsWith(".json")) continue;
|
|
178
|
+
try {
|
|
179
|
+
const record = JSON.parse(fs.readFileSync(path.join(INSTANCES_DIR, name), "utf8"));
|
|
180
|
+
if (alive(record.pid)) records.push(record);
|
|
181
|
+
else removeInstance(record.id);
|
|
182
|
+
} catch {
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return records.sort((a, b) => a.createdAt - b.createdAt);
|
|
186
|
+
}
|
|
187
|
+
function findInstance(selector) {
|
|
188
|
+
const all = listInstances();
|
|
189
|
+
const chosen = selector ?? process.env.TESTINGTERM_ID;
|
|
190
|
+
if (chosen) {
|
|
191
|
+
const match = all.find((record) => record.id === chosen) ?? all.filter((record) => record.name === chosen).at(-1);
|
|
192
|
+
if (!match) throw new Error(`no terminal ${chosen}${all.length ? `
|
|
193
|
+
|
|
194
|
+
running:
|
|
195
|
+
${all.map(describe).join("\n")}` : " (none are running; start one with testingterm new)"}`);
|
|
196
|
+
return match;
|
|
197
|
+
}
|
|
198
|
+
if (all.length === 0) throw new Error("no terminals are running; start one with: testingterm new -- <command>");
|
|
199
|
+
if (all.length === 1) return all[0];
|
|
200
|
+
throw new Error(`several terminals are running; pass --id <id>
|
|
201
|
+
|
|
202
|
+
running:
|
|
203
|
+
${all.map(describe).join("\n")}`);
|
|
204
|
+
}
|
|
205
|
+
function age(ms) {
|
|
206
|
+
const s = Math.round(ms / 1e3);
|
|
207
|
+
if (s < 60) return `${s}s`;
|
|
208
|
+
if (s < 3600) return `${Math.round(s / 60)}m`;
|
|
209
|
+
return `${Math.round(s / 3600)}h`;
|
|
210
|
+
}
|
|
211
|
+
function describe(record) {
|
|
212
|
+
const size = `${record.cols}x${record.rows}`;
|
|
213
|
+
return ` ${record.id.padEnd(6)}${record.name.slice(0, 14).padEnd(16)}${size.padEnd(9)}${age(Date.now() - record.createdAt).padEnd(6)}${record.owner.padEnd(8)}${record.command.join(" ") || "shell"}`;
|
|
214
|
+
}
|
|
215
|
+
var DESCRIBE_HEADER = ` ${"id".padEnd(6)}${"name".padEnd(16)}${"size".padEnd(9)}${"age".padEnd(6)}${"owner".padEnd(8)}command`;
|
|
216
|
+
|
|
217
|
+
export {
|
|
218
|
+
EngineError,
|
|
219
|
+
startEngine,
|
|
220
|
+
connectSocket,
|
|
221
|
+
newId,
|
|
222
|
+
socketPath,
|
|
223
|
+
writeInstance,
|
|
224
|
+
removeInstance,
|
|
225
|
+
listInstances,
|
|
226
|
+
findInstance,
|
|
227
|
+
describe,
|
|
228
|
+
DESCRIBE_HEADER
|
|
229
|
+
};
|