terminal-pilot 0.0.6 → 0.0.8

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.
Files changed (51) hide show
  1. package/dist/cli.js +5663 -1269
  2. package/dist/cli.js.map +4 -4
  3. package/dist/commands/close-session.js +268 -87
  4. package/dist/commands/close-session.js.map +4 -4
  5. package/dist/commands/create-session.js +268 -87
  6. package/dist/commands/create-session.js.map +4 -4
  7. package/dist/commands/fill.js +268 -87
  8. package/dist/commands/fill.js.map +4 -4
  9. package/dist/commands/get-session.js +268 -87
  10. package/dist/commands/get-session.js.map +4 -4
  11. package/dist/commands/index.js +2404 -279
  12. package/dist/commands/index.js.map +4 -4
  13. package/dist/commands/install.js +1372 -14
  14. package/dist/commands/install.js.map +4 -4
  15. package/dist/commands/installer.js +178 -15
  16. package/dist/commands/installer.js.map +4 -4
  17. package/dist/commands/list-sessions.js +268 -87
  18. package/dist/commands/list-sessions.js.map +4 -4
  19. package/dist/commands/press-key.js +268 -87
  20. package/dist/commands/press-key.js.map +4 -4
  21. package/dist/commands/read-history.js +268 -87
  22. package/dist/commands/read-history.js.map +4 -4
  23. package/dist/commands/read-screen.js +268 -87
  24. package/dist/commands/read-screen.js.map +4 -4
  25. package/dist/commands/resize.js +268 -87
  26. package/dist/commands/resize.js.map +4 -4
  27. package/dist/commands/runtime.js +27 -85
  28. package/dist/commands/runtime.js.map +4 -4
  29. package/dist/commands/screenshot.js +1033 -91
  30. package/dist/commands/screenshot.js.map +4 -4
  31. package/dist/commands/send-signal.js +268 -87
  32. package/dist/commands/send-signal.js.map +4 -4
  33. package/dist/commands/type.js +268 -87
  34. package/dist/commands/type.js.map +4 -4
  35. package/dist/commands/uninstall.js +419 -17
  36. package/dist/commands/uninstall.js.map +4 -4
  37. package/dist/commands/wait-for-exit.js +268 -87
  38. package/dist/commands/wait-for-exit.js.map +4 -4
  39. package/dist/commands/wait-for.js +268 -87
  40. package/dist/commands/wait-for.js.map +4 -4
  41. package/dist/index.js +19 -83
  42. package/dist/index.js.map +3 -3
  43. package/dist/terminal-pilot.js +19 -83
  44. package/dist/terminal-pilot.js.map +3 -3
  45. package/dist/terminal-session.js +19 -83
  46. package/dist/terminal-session.js.map +3 -3
  47. package/dist/testing/cli-repl.js +5598 -1203
  48. package/dist/testing/cli-repl.js.map +4 -4
  49. package/dist/testing/qa-cli.js +5601 -1206
  50. package/dist/testing/qa-cli.js.map +4 -4
  51. package/package.json +17 -8
@@ -1,15 +1,262 @@
1
- // src/commands/fill.ts
2
- import { defineCommand, S } from "@poe-code/cmdkit";
1
+ // ../cmdkit/src/index.ts
2
+ import { fileURLToPath } from "node:url";
3
3
 
4
- // src/commands/runtime.ts
5
- import { UserError } from "@poe-code/cmdkit";
4
+ // ../cmdkit-schema/src/index.ts
5
+ function assertValidEnumValues(values) {
6
+ if (values.length === 0) {
7
+ throw new Error("Enum schema requires at least one value");
8
+ }
9
+ const uniqueValues = new Set(values);
10
+ if (uniqueValues.size !== values.length) {
11
+ throw new Error("Enum schema values must be unique");
12
+ }
13
+ }
14
+ var S = {
15
+ String(options = {}) {
16
+ return {
17
+ kind: "string",
18
+ ...options
19
+ };
20
+ },
21
+ Number(options = {}) {
22
+ return {
23
+ kind: "number",
24
+ ...options
25
+ };
26
+ },
27
+ Boolean(options = {}) {
28
+ return {
29
+ kind: "boolean",
30
+ ...options
31
+ };
32
+ },
33
+ Enum(values, options = {}) {
34
+ assertValidEnumValues(values);
35
+ return {
36
+ kind: "enum",
37
+ values,
38
+ ...options
39
+ };
40
+ },
41
+ Array(item, options = {}) {
42
+ return {
43
+ kind: "array",
44
+ item,
45
+ ...options
46
+ };
47
+ },
48
+ Object(shape) {
49
+ return {
50
+ kind: "object",
51
+ shape
52
+ };
53
+ },
54
+ Optional(inner) {
55
+ return {
56
+ kind: "optional",
57
+ inner
58
+ };
59
+ }
60
+ };
61
+
62
+ // ../cmdkit/src/index.ts
63
+ var commandConfigSymbol = /* @__PURE__ */ Symbol("cmdkit.command.config");
64
+ var commandSourcePathSymbol = /* @__PURE__ */ Symbol("cmdkit.command.sourcePath");
65
+ var UserError = class extends Error {
66
+ constructor(message) {
67
+ super(message);
68
+ this.name = "UserError";
69
+ }
70
+ };
71
+ function cloneScope(scope) {
72
+ return scope === void 0 ? void 0 : [...scope];
73
+ }
74
+ function cloneSecretDefinition(secret) {
75
+ return {
76
+ env: secret.env,
77
+ description: secret.description,
78
+ optional: secret.optional
79
+ };
80
+ }
81
+ function cloneSecrets(secrets) {
82
+ if (secrets === void 0) {
83
+ return {};
84
+ }
85
+ return Object.fromEntries(
86
+ Object.entries(secrets).map(([key, secret]) => [key, cloneSecretDefinition(secret)])
87
+ );
88
+ }
89
+ function cloneRequires(requires) {
90
+ if (requires === void 0) {
91
+ return void 0;
92
+ }
93
+ return {
94
+ auth: requires.auth,
95
+ apiVersion: requires.apiVersion,
96
+ check: requires.check
97
+ };
98
+ }
99
+ function parseStackPath(candidate) {
100
+ if (candidate.startsWith("file://")) {
101
+ try {
102
+ return fileURLToPath(candidate);
103
+ } catch {
104
+ return void 0;
105
+ }
106
+ }
107
+ if (candidate.startsWith("/")) {
108
+ return candidate;
109
+ }
110
+ return void 0;
111
+ }
112
+ function extractStackPath(line) {
113
+ const trimmed = line.trim();
114
+ const fileIndex = trimmed.indexOf("file://");
115
+ if (fileIndex >= 0) {
116
+ const location2 = trimmed.slice(fileIndex);
117
+ const separatorIndex2 = location2.lastIndexOf(":");
118
+ const previousSeparatorIndex2 = separatorIndex2 >= 0 ? location2.lastIndexOf(":", separatorIndex2 - 1) : -1;
119
+ const candidate2 = separatorIndex2 >= 0 && previousSeparatorIndex2 >= 0 ? location2.slice(0, previousSeparatorIndex2) : location2;
120
+ return parseStackPath(candidate2);
121
+ }
122
+ const slashIndex = trimmed.indexOf("/");
123
+ if (slashIndex < 0) {
124
+ return void 0;
125
+ }
126
+ const location = trimmed.slice(slashIndex);
127
+ const separatorIndex = location.lastIndexOf(":");
128
+ const previousSeparatorIndex = separatorIndex >= 0 ? location.lastIndexOf(":", separatorIndex - 1) : -1;
129
+ const candidate = separatorIndex >= 0 && previousSeparatorIndex >= 0 ? location.slice(0, previousSeparatorIndex) : location;
130
+ return parseStackPath(candidate);
131
+ }
132
+ function inferCommandSourcePath() {
133
+ const stack = new Error().stack;
134
+ if (typeof stack !== "string") {
135
+ return void 0;
136
+ }
137
+ for (const line of stack.split("\n").slice(1)) {
138
+ const candidate = extractStackPath(line);
139
+ if (candidate === void 0) {
140
+ continue;
141
+ }
142
+ if (candidate.includes("/packages/cmdkit/src/index.ts") || candidate.includes("/packages/cmdkit/dist/index.js")) {
143
+ continue;
144
+ }
145
+ return candidate;
146
+ }
147
+ return void 0;
148
+ }
149
+ function composeChecks(parentCheck, childCheck) {
150
+ if (parentCheck === void 0) {
151
+ return childCheck;
152
+ }
153
+ if (childCheck === void 0) {
154
+ return parentCheck;
155
+ }
156
+ return async (ctx) => {
157
+ const parentResult = await parentCheck(ctx);
158
+ if (!parentResult.ok) {
159
+ return parentResult;
160
+ }
161
+ return childCheck(ctx);
162
+ };
163
+ }
164
+ function mergeRequires(parent, child) {
165
+ if (parent === void 0 && child === void 0) {
166
+ return void 0;
167
+ }
168
+ const merged = {
169
+ auth: child?.auth ?? parent?.auth,
170
+ apiVersion: child?.apiVersion ?? parent?.apiVersion,
171
+ check: composeChecks(parent?.check, child?.check)
172
+ };
173
+ if (merged.auth === void 0 && merged.apiVersion === void 0 && merged.check === void 0) {
174
+ return void 0;
175
+ }
176
+ return merged;
177
+ }
178
+ function mergeSecrets(parent, child) {
179
+ return cloneSecrets({
180
+ ...parent,
181
+ ...child
182
+ });
183
+ }
184
+ function resolveCommandScope(ownScope, inheritedScope) {
185
+ return cloneScope(ownScope ?? inheritedScope) ?? ["cli", "sdk"];
186
+ }
187
+ function createBaseCommand(config) {
188
+ const command = {
189
+ kind: "command",
190
+ name: config.name,
191
+ description: config.description,
192
+ aliases: [...config.aliases ?? []],
193
+ positional: [...config.positional ?? []],
194
+ params: config.params,
195
+ secrets: cloneSecrets(config.secrets),
196
+ scope: resolveCommandScope(config.scope, void 0),
197
+ confirm: config.confirm ?? false,
198
+ requires: cloneRequires(config.requires),
199
+ handler: config.handler,
200
+ render: config.render
201
+ };
202
+ Object.defineProperty(command, commandConfigSymbol, {
203
+ value: {
204
+ scope: cloneScope(config.scope),
205
+ secrets: cloneSecrets(config.secrets),
206
+ requires: cloneRequires(config.requires),
207
+ sourcePath: inferCommandSourcePath()
208
+ }
209
+ });
210
+ return command;
211
+ }
212
+ function getInternalCommandConfig(command) {
213
+ return command[commandConfigSymbol];
214
+ }
215
+ function materializeCommand(command, inherited) {
216
+ const internal = getInternalCommandConfig(command);
217
+ const materialized = {
218
+ kind: "command",
219
+ name: command.name,
220
+ description: command.description,
221
+ aliases: [...command.aliases],
222
+ positional: [...command.positional],
223
+ params: command.params,
224
+ secrets: mergeSecrets(inherited.secrets, internal.secrets),
225
+ scope: resolveCommandScope(internal.scope, inherited.scope),
226
+ confirm: command.confirm,
227
+ requires: mergeRequires(inherited.requires, internal.requires),
228
+ handler: command.handler,
229
+ render: command.render
230
+ };
231
+ Object.defineProperty(materialized, commandConfigSymbol, {
232
+ value: {
233
+ scope: cloneScope(internal.scope),
234
+ secrets: cloneSecrets(internal.secrets),
235
+ requires: cloneRequires(internal.requires),
236
+ sourcePath: internal.sourcePath
237
+ }
238
+ });
239
+ Object.defineProperty(materialized, commandSourcePathSymbol, {
240
+ value: internal.sourcePath
241
+ });
242
+ return materialized;
243
+ }
244
+ function defineCommand(config) {
245
+ return materializeCommand(createBaseCommand(config), {
246
+ scope: void 0,
247
+ secrets: {},
248
+ requires: void 0
249
+ });
250
+ }
6
251
 
7
252
  // src/terminal-pilot.ts
8
253
  import { randomUUID } from "node:crypto";
9
254
 
10
255
  // src/terminal-session.ts
11
- import { spawn as spawnChildProcess } from "node:child_process";
12
256
  import { EventEmitter } from "node:events";
257
+ import { accessSync, chmodSync, constants } from "node:fs";
258
+ import { createRequire } from "node:module";
259
+ import { dirname, join } from "node:path";
13
260
  import * as nodePty from "node-pty";
14
261
 
15
262
  // src/ansi.ts
@@ -920,93 +1167,27 @@ function createPtyProcess({
920
1167
  cols,
921
1168
  rows
922
1169
  }) {
923
- try {
924
- return nodePty.spawn(command, args, {
925
- cwd,
926
- env,
927
- cols,
928
- rows,
929
- encoding: "utf8"
930
- });
931
- } catch {
932
- return createChildProcessFallback({ command, args, cwd, env });
933
- }
934
- }
935
- function createChildProcessFallback({
936
- command,
937
- args,
938
- cwd,
939
- env
940
- }) {
941
- const child = spawnChildProcess(command, args, {
1170
+ ensureSpawnHelperExecutable();
1171
+ return nodePty.spawn(command, args, {
942
1172
  cwd,
943
1173
  env,
944
- stdio: ["pipe", "pipe", "pipe"]
1174
+ cols,
1175
+ rows,
1176
+ encoding: "utf8"
945
1177
  });
946
- return new ChildProcessFallback(child);
947
1178
  }
948
- var ChildProcessFallback = class {
949
- pid;
950
- child;
951
- dataEmitter = new EventEmitter();
952
- exitEmitter = new EventEmitter();
953
- constructor(child) {
954
- this.child = child;
955
- this.pid = child.pid ?? -1;
956
- child.stdout.setEncoding("utf8");
957
- child.stderr.setEncoding("utf8");
958
- child.stdout.on("data", this.handleData);
959
- child.stderr.on("data", this.handleData);
960
- child.on("exit", (exitCode, signal) => {
961
- this.exitEmitter.emit("exit", {
962
- exitCode: exitCode ?? signalToExitCode(signal),
963
- signal: void 0
964
- });
965
- });
966
- }
967
- write(data) {
968
- this.child.stdin.write(data);
969
- }
970
- resize() {
971
- }
972
- kill(signal) {
973
- this.child.kill(signal);
974
- }
975
- onData(listener) {
976
- this.dataEmitter.on("data", listener);
977
- return {
978
- dispose: () => {
979
- this.dataEmitter.off("data", listener);
980
- }
981
- };
982
- }
983
- onExit(listener) {
984
- this.exitEmitter.on("exit", listener);
985
- return {
986
- dispose: () => {
987
- this.exitEmitter.off("exit", listener);
988
- }
989
- };
990
- }
991
- handleData = (chunk) => {
992
- this.dataEmitter.emit("data", String(chunk));
993
- };
994
- };
995
- function signalToExitCode(signal) {
996
- if (signal === null) {
997
- return 0;
998
- }
999
- const signalNumbers = {
1000
- SIGTERM: 15,
1001
- SIGINT: 2,
1002
- SIGHUP: 1,
1003
- SIGKILL: 9
1004
- };
1005
- const signalNumber = signalNumbers[signal];
1006
- if (signalNumber === void 0) {
1007
- return 1;
1179
+ var spawnHelperChecked = false;
1180
+ function ensureSpawnHelperExecutable() {
1181
+ if (spawnHelperChecked) return;
1182
+ spawnHelperChecked = true;
1183
+ const require2 = createRequire(import.meta.url);
1184
+ const nodePtyDir = dirname(require2.resolve("node-pty"));
1185
+ const helper = join(nodePtyDir, "..", "prebuilds", `${process.platform}-${process.arch}`, "spawn-helper");
1186
+ try {
1187
+ accessSync(helper, constants.X_OK);
1188
+ } catch {
1189
+ chmodSync(helper, 493);
1008
1190
  }
1009
- return 128 + signalNumber;
1010
1191
  }
1011
1192
  function matchPattern(buffer, pattern) {
1012
1193
  const clean = normalizeHistoryBuffer(stripAnsi(buffer));