terminal-pilot 0.0.5 → 0.0.7

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 (86) hide show
  1. package/README.md +40 -0
  2. package/dist/ansi.js +68 -63
  3. package/dist/ansi.js.map +7 -0
  4. package/dist/cli.d.ts +2 -0
  5. package/dist/cli.js +6254 -0
  6. package/dist/cli.js.map +7 -0
  7. package/dist/commands/close-session.d.ts +12 -0
  8. package/dist/commands/close-session.js +1509 -0
  9. package/dist/commands/close-session.js.map +7 -0
  10. package/dist/commands/create-session.d.ts +26 -0
  11. package/dist/commands/create-session.js +1516 -0
  12. package/dist/commands/create-session.js.map +7 -0
  13. package/dist/commands/fill.d.ts +10 -0
  14. package/dist/commands/fill.js +1512 -0
  15. package/dist/commands/fill.js.map +7 -0
  16. package/dist/commands/get-session.d.ts +18 -0
  17. package/dist/commands/get-session.js +1514 -0
  18. package/dist/commands/get-session.js.map +7 -0
  19. package/dist/commands/index.d.ts +242 -0
  20. package/dist/commands/index.js +3973 -0
  21. package/dist/commands/index.js.map +7 -0
  22. package/dist/commands/install.d.ts +20 -0
  23. package/dist/commands/install.js +1480 -0
  24. package/dist/commands/install.js.map +7 -0
  25. package/dist/commands/installer.d.ts +43 -0
  26. package/dist/commands/installer.js +289 -0
  27. package/dist/commands/installer.js.map +7 -0
  28. package/dist/commands/list-sessions.d.ts +16 -0
  29. package/dist/commands/list-sessions.js +1513 -0
  30. package/dist/commands/list-sessions.js.map +7 -0
  31. package/dist/commands/press-key.d.ts +10 -0
  32. package/dist/commands/press-key.js +1512 -0
  33. package/dist/commands/press-key.js.map +7 -0
  34. package/dist/commands/read-history.d.ts +16 -0
  35. package/dist/commands/read-history.js +1511 -0
  36. package/dist/commands/read-history.js.map +7 -0
  37. package/dist/commands/read-screen.d.ts +21 -0
  38. package/dist/commands/read-screen.js +1515 -0
  39. package/dist/commands/read-screen.js.map +7 -0
  40. package/dist/commands/resize.d.ts +12 -0
  41. package/dist/commands/resize.js +1512 -0
  42. package/dist/commands/resize.js.map +7 -0
  43. package/dist/commands/runtime.d.ts +36 -0
  44. package/dist/commands/runtime.js +1262 -0
  45. package/dist/commands/runtime.js.map +7 -0
  46. package/dist/commands/screenshot.d.ts +14 -0
  47. package/dist/commands/screenshot.js +2280 -0
  48. package/dist/commands/screenshot.js.map +7 -0
  49. package/dist/commands/send-signal.d.ts +10 -0
  50. package/dist/commands/send-signal.js +1512 -0
  51. package/dist/commands/send-signal.js.map +7 -0
  52. package/dist/commands/type.d.ts +10 -0
  53. package/dist/commands/type.js +1512 -0
  54. package/dist/commands/type.js.map +7 -0
  55. package/dist/commands/uninstall.d.ts +14 -0
  56. package/dist/commands/uninstall.js +529 -0
  57. package/dist/commands/uninstall.js.map +7 -0
  58. package/dist/commands/wait-for-exit.d.ts +14 -0
  59. package/dist/commands/wait-for-exit.js +1513 -0
  60. package/dist/commands/wait-for-exit.js.map +7 -0
  61. package/dist/commands/wait-for.d.ts +20 -0
  62. package/dist/commands/wait-for.js +1520 -0
  63. package/dist/commands/wait-for.js.map +7 -0
  64. package/dist/exports.compile-check.js +1 -1
  65. package/dist/exports.compile-check.js.map +7 -0
  66. package/dist/index.js +1118 -5
  67. package/dist/index.js.map +7 -0
  68. package/dist/keys.js +58 -49
  69. package/dist/keys.js.map +7 -0
  70. package/dist/templates/terminal-pilot.md +45 -0
  71. package/dist/terminal-buffer.d.ts +9 -1
  72. package/dist/terminal-buffer.js +525 -425
  73. package/dist/terminal-buffer.js.map +7 -0
  74. package/dist/terminal-pilot.js +1105 -35
  75. package/dist/terminal-pilot.js.map +7 -0
  76. package/dist/terminal-screen.js +108 -26
  77. package/dist/terminal-screen.js.map +7 -0
  78. package/dist/terminal-session.js +1020 -292
  79. package/dist/terminal-session.js.map +7 -0
  80. package/dist/testing/cli-repl.d.ts +15 -0
  81. package/dist/testing/cli-repl.js +6359 -0
  82. package/dist/testing/cli-repl.js.map +7 -0
  83. package/dist/testing/qa-cli.d.ts +1 -0
  84. package/dist/testing/qa-cli.js +7276 -0
  85. package/dist/testing/qa-cli.js.map +7 -0
  86. package/package.json +37 -7
@@ -0,0 +1,529 @@
1
+ // ../cmdkit/src/index.ts
2
+ import { fileURLToPath } from "node:url";
3
+
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
+ }
251
+
252
+ // src/commands/installer.ts
253
+ import os2 from "node:os";
254
+ import path3 from "node:path";
255
+ import * as nodeFs from "node:fs/promises";
256
+ import { readFile as readFile2 } from "node:fs/promises";
257
+
258
+ // ../agent-skill-config/src/configs.ts
259
+ import os from "node:os";
260
+ import path from "node:path";
261
+
262
+ // ../agent-defs/src/agents/claude-code.ts
263
+ var claudeCodeAgent = {
264
+ id: "claude-code",
265
+ name: "claude-code",
266
+ label: "Claude Code",
267
+ summary: "Configure Claude Code to route through Poe.",
268
+ aliases: ["claude"],
269
+ binaryName: "claude",
270
+ configPath: "~/.claude/settings.json",
271
+ branding: {
272
+ colors: {
273
+ dark: "#C15F3C",
274
+ light: "#C15F3C"
275
+ }
276
+ }
277
+ };
278
+
279
+ // ../agent-defs/src/agents/claude-desktop.ts
280
+ var claudeDesktopAgent = {
281
+ id: "claude-desktop",
282
+ name: "claude-desktop",
283
+ label: "Claude Desktop",
284
+ summary: "Anthropic's official desktop application for Claude",
285
+ configPath: "~/.claude/settings.json",
286
+ branding: {
287
+ colors: {
288
+ dark: "#D97757",
289
+ light: "#D97757"
290
+ }
291
+ }
292
+ };
293
+
294
+ // ../agent-defs/src/agents/codex.ts
295
+ var codexAgent = {
296
+ id: "codex",
297
+ name: "codex",
298
+ label: "Codex",
299
+ summary: "Configure Codex to use Poe as the model provider.",
300
+ binaryName: "codex",
301
+ configPath: "~/.codex/config.toml",
302
+ branding: {
303
+ colors: {
304
+ dark: "#D5D9DF",
305
+ light: "#7A7F86"
306
+ }
307
+ }
308
+ };
309
+
310
+ // ../agent-defs/src/agents/opencode.ts
311
+ var openCodeAgent = {
312
+ id: "opencode",
313
+ name: "opencode",
314
+ label: "OpenCode CLI",
315
+ summary: "Configure OpenCode CLI to use the Poe API.",
316
+ binaryName: "opencode",
317
+ configPath: "~/.config/opencode/config.json",
318
+ branding: {
319
+ colors: {
320
+ dark: "#4A4F55",
321
+ light: "#2F3338"
322
+ }
323
+ }
324
+ };
325
+
326
+ // ../agent-defs/src/agents/kimi.ts
327
+ var kimiAgent = {
328
+ id: "kimi",
329
+ name: "kimi",
330
+ label: "Kimi",
331
+ summary: "Configure Kimi CLI to use Poe API",
332
+ aliases: ["kimi-cli"],
333
+ binaryName: "kimi",
334
+ configPath: "~/.kimi/config.toml",
335
+ branding: {
336
+ colors: {
337
+ dark: "#7B68EE",
338
+ light: "#6A5ACD"
339
+ }
340
+ }
341
+ };
342
+
343
+ // ../agent-defs/src/registry.ts
344
+ var allAgents = [
345
+ claudeCodeAgent,
346
+ claudeDesktopAgent,
347
+ codexAgent,
348
+ openCodeAgent,
349
+ kimiAgent
350
+ ];
351
+ var lookup = /* @__PURE__ */ new Map();
352
+ for (const agent of allAgents) {
353
+ const values = [agent.id, agent.name, ...agent.aliases ?? []];
354
+ for (const value of values) {
355
+ const normalized = value.toLowerCase();
356
+ if (!lookup.has(normalized)) {
357
+ lookup.set(normalized, agent.id);
358
+ }
359
+ }
360
+ }
361
+ function resolveAgentId(input) {
362
+ if (!input) {
363
+ return void 0;
364
+ }
365
+ return lookup.get(input.toLowerCase());
366
+ }
367
+
368
+ // ../agent-skill-config/src/configs.ts
369
+ var agentSkillConfigs = {
370
+ "claude-code": {
371
+ globalSkillDir: "~/.claude/skills",
372
+ localSkillDir: ".claude/skills"
373
+ },
374
+ codex: {
375
+ globalSkillDir: "~/.codex/skills",
376
+ localSkillDir: ".codex/skills"
377
+ },
378
+ opencode: {
379
+ globalSkillDir: "~/.config/opencode/skills",
380
+ localSkillDir: ".opencode/skills"
381
+ }
382
+ };
383
+ var supportedAgents = Object.keys(agentSkillConfigs);
384
+ function resolveAgentSupport(input, registry = agentSkillConfigs) {
385
+ const resolvedId = resolveAgentId(input);
386
+ if (!resolvedId) {
387
+ return { status: "unknown", input };
388
+ }
389
+ const config = registry[resolvedId];
390
+ if (!config) {
391
+ return { status: "unsupported", input, id: resolvedId };
392
+ }
393
+ return { status: "supported", input, id: resolvedId, config };
394
+ }
395
+ function getAgentConfig(agentId) {
396
+ const support = resolveAgentSupport(agentId);
397
+ return support.status === "supported" ? support.config : void 0;
398
+ }
399
+
400
+ // ../config-mutations/src/execution/apply-mutation.ts
401
+ import Mustache from "mustache";
402
+
403
+ // ../config-mutations/src/formats/json.ts
404
+ import * as jsonc from "jsonc-parser";
405
+
406
+ // ../config-mutations/src/formats/toml.ts
407
+ import { parse as parseToml, stringify as stringifyToml } from "smol-toml";
408
+
409
+ // ../config-mutations/src/execution/path-utils.ts
410
+ import path2 from "node:path";
411
+
412
+ // ../config-mutations/src/template/render.ts
413
+ import Mustache2 from "mustache";
414
+ var originalEscape = Mustache2.escape;
415
+
416
+ // ../agent-skill-config/src/templates.ts
417
+ import { readFile } from "node:fs/promises";
418
+
419
+ // src/commands/installer.ts
420
+ var DEFAULT_INSTALL_AGENT = "claude-code";
421
+ var TERMINAL_PILOT_SKILL_NAME = "terminal-pilot";
422
+ var installableAgents = supportedAgents;
423
+ function isNotFoundError(error) {
424
+ return typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
425
+ }
426
+ function resolveInstallerServices(installer) {
427
+ return {
428
+ fs: installer?.fs ?? nodeFs,
429
+ cwd: installer?.cwd ?? process.cwd(),
430
+ homeDir: installer?.homeDir ?? os2.homedir(),
431
+ platform: installer?.platform ?? process.platform
432
+ };
433
+ }
434
+ function throwUnsupportedAgent(agent) {
435
+ throw new UserError(`Unsupported agent: ${agent}`);
436
+ }
437
+ function resolveInstallableAgent(agent) {
438
+ const skillSupport = resolveAgentSupport(agent);
439
+ if (skillSupport.status !== "supported" || !skillSupport.id) {
440
+ throwUnsupportedAgent(agent);
441
+ }
442
+ return skillSupport.id;
443
+ }
444
+ function resolveHomeRelativePath(targetPath, homeDir) {
445
+ if (targetPath === "~") {
446
+ return homeDir;
447
+ }
448
+ if (targetPath.startsWith("~/")) {
449
+ return path3.join(homeDir, targetPath.slice(2));
450
+ }
451
+ return targetPath;
452
+ }
453
+ function getSkillFolderWithHome(agent, scope, cwd, homeDir) {
454
+ const config = getAgentConfig(agent);
455
+ if (!config) {
456
+ throwUnsupportedAgent(agent);
457
+ }
458
+ return {
459
+ displayPath: path3.join(
460
+ scope === "global" ? config.globalSkillDir : config.localSkillDir,
461
+ TERMINAL_PILOT_SKILL_NAME
462
+ ),
463
+ fullPath: path3.join(
464
+ scope === "global" ? resolveHomeRelativePath(config.globalSkillDir, homeDir) : path3.resolve(cwd, config.localSkillDir),
465
+ TERMINAL_PILOT_SKILL_NAME
466
+ )
467
+ };
468
+ }
469
+ async function removeSkillFolder(fs, folderPath) {
470
+ try {
471
+ await fs.stat(folderPath);
472
+ } catch (error) {
473
+ if (isNotFoundError(error)) {
474
+ return false;
475
+ }
476
+ throw error;
477
+ }
478
+ if (typeof fs.rm !== "function") {
479
+ throw new UserError("The configured filesystem does not support removing directories.");
480
+ }
481
+ await fs.rm(folderPath, { recursive: true, force: true });
482
+ return true;
483
+ }
484
+
485
+ // src/commands/uninstall.ts
486
+ var params = S.Object({
487
+ agent: S.Enum(installableAgents, {
488
+ description: "Agent to uninstall terminal-pilot from",
489
+ default: DEFAULT_INSTALL_AGENT
490
+ })
491
+ });
492
+ var uninstall = defineCommand({
493
+ name: "uninstall",
494
+ description: "Remove the terminal-pilot CLI skill.",
495
+ scope: ["cli"],
496
+ positional: ["agent"],
497
+ params,
498
+ handler: async ({ params: params2, terminalPilotInstaller }) => {
499
+ const services = resolveInstallerServices(terminalPilotInstaller);
500
+ const agent = resolveInstallableAgent(params2.agent);
501
+ const localSkill = getSkillFolderWithHome(
502
+ agent,
503
+ "local",
504
+ services.cwd,
505
+ services.homeDir
506
+ );
507
+ const globalSkill = getSkillFolderWithHome(
508
+ agent,
509
+ "global",
510
+ services.cwd,
511
+ services.homeDir
512
+ );
513
+ const removedSkillPaths = [];
514
+ if (await removeSkillFolder(services.fs, localSkill.fullPath)) {
515
+ removedSkillPaths.push(localSkill.displayPath);
516
+ }
517
+ if (await removeSkillFolder(services.fs, globalSkill.fullPath)) {
518
+ removedSkillPaths.push(globalSkill.displayPath);
519
+ }
520
+ return {
521
+ agent,
522
+ removedSkillPaths
523
+ };
524
+ }
525
+ });
526
+ export {
527
+ uninstall
528
+ };
529
+ //# sourceMappingURL=uninstall.js.map