libretto 0.1.5 → 0.2.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.
Files changed (183) hide show
  1. package/README.md +213 -17
  2. package/bin/libretto.mjs +18 -0
  3. package/dist/cli/cli.js +201 -0
  4. package/dist/cli/commands/ai.js +21 -0
  5. package/dist/cli/commands/browser.js +56 -0
  6. package/dist/cli/commands/execution.js +407 -0
  7. package/dist/cli/commands/logs.js +65 -0
  8. package/dist/cli/commands/snapshot.js +99 -0
  9. package/dist/cli/core/ai-config.js +149 -0
  10. package/dist/cli/core/browser.js +687 -0
  11. package/dist/cli/core/context.js +113 -0
  12. package/dist/cli/core/pause-signals.js +29 -0
  13. package/dist/cli/core/session.js +183 -0
  14. package/dist/cli/core/snapshot-analyzer.js +492 -0
  15. package/dist/cli/core/telemetry.js +350 -0
  16. package/dist/cli/index.js +13 -0
  17. package/dist/cli/workers/run-integration-runtime.js +204 -0
  18. package/dist/cli/workers/run-integration-worker-protocol.js +0 -0
  19. package/dist/cli/workers/run-integration-worker.js +83 -0
  20. package/dist/index.cjs +127 -0
  21. package/dist/index.d.cts +22 -0
  22. package/dist/index.d.ts +22 -0
  23. package/dist/index.js +110 -0
  24. package/dist/runtime/download/download.cjs +70 -0
  25. package/dist/runtime/download/download.d.cts +35 -0
  26. package/dist/runtime/download/download.d.ts +35 -0
  27. package/dist/runtime/download/download.js +45 -0
  28. package/dist/runtime/download/index.cjs +30 -0
  29. package/dist/runtime/download/index.d.cts +3 -0
  30. package/dist/runtime/download/index.d.ts +3 -0
  31. package/dist/runtime/download/index.js +8 -0
  32. package/dist/runtime/extract/extract.cjs +87 -0
  33. package/dist/runtime/extract/extract.d.cts +23 -0
  34. package/dist/runtime/extract/extract.d.ts +23 -0
  35. package/dist/runtime/extract/extract.js +63 -0
  36. package/dist/runtime/extract/index.cjs +28 -0
  37. package/dist/runtime/extract/index.d.cts +5 -0
  38. package/dist/runtime/extract/index.d.ts +5 -0
  39. package/dist/runtime/extract/index.js +4 -0
  40. package/dist/runtime/network/index.cjs +28 -0
  41. package/dist/runtime/network/index.d.cts +4 -0
  42. package/dist/runtime/network/index.d.ts +4 -0
  43. package/dist/runtime/network/index.js +6 -0
  44. package/dist/runtime/network/network.cjs +91 -0
  45. package/dist/runtime/network/network.d.cts +28 -0
  46. package/dist/runtime/network/network.d.ts +28 -0
  47. package/dist/runtime/network/network.js +67 -0
  48. package/dist/runtime/recovery/agent.cjs +218 -0
  49. package/dist/runtime/recovery/agent.d.cts +13 -0
  50. package/dist/runtime/recovery/agent.d.ts +13 -0
  51. package/dist/runtime/recovery/agent.js +194 -0
  52. package/dist/runtime/recovery/errors.cjs +122 -0
  53. package/dist/runtime/recovery/errors.d.cts +31 -0
  54. package/dist/runtime/recovery/errors.d.ts +31 -0
  55. package/dist/runtime/recovery/errors.js +98 -0
  56. package/dist/runtime/recovery/index.cjs +34 -0
  57. package/dist/runtime/recovery/index.d.cts +7 -0
  58. package/dist/runtime/recovery/index.d.ts +7 -0
  59. package/dist/runtime/recovery/index.js +10 -0
  60. package/dist/runtime/recovery/recovery.cjs +53 -0
  61. package/dist/runtime/recovery/recovery.d.cts +12 -0
  62. package/dist/runtime/recovery/recovery.d.ts +12 -0
  63. package/dist/runtime/recovery/recovery.js +29 -0
  64. package/dist/runtime/step/index.cjs +31 -0
  65. package/dist/runtime/step/index.d.cts +7 -0
  66. package/dist/runtime/step/index.d.ts +7 -0
  67. package/dist/runtime/step/index.js +6 -0
  68. package/dist/runtime/step/runner.cjs +208 -0
  69. package/dist/runtime/step/runner.d.cts +16 -0
  70. package/dist/runtime/step/runner.d.ts +16 -0
  71. package/dist/runtime/step/runner.js +187 -0
  72. package/dist/runtime/step/step.cjs +67 -0
  73. package/dist/runtime/step/step.d.cts +23 -0
  74. package/dist/runtime/step/step.d.ts +23 -0
  75. package/dist/runtime/step/step.js +43 -0
  76. package/dist/runtime/step/types.cjs +16 -0
  77. package/dist/runtime/step/types.d.cts +72 -0
  78. package/dist/runtime/step/types.d.ts +72 -0
  79. package/dist/runtime/step/types.js +0 -0
  80. package/dist/shared/config/config.cjs +44 -0
  81. package/dist/shared/config/config.d.cts +10 -0
  82. package/dist/shared/config/config.d.ts +10 -0
  83. package/dist/shared/config/config.js +18 -0
  84. package/dist/shared/config/index.cjs +32 -0
  85. package/dist/shared/config/index.d.cts +1 -0
  86. package/dist/shared/config/index.d.ts +1 -0
  87. package/dist/shared/config/index.js +10 -0
  88. package/dist/shared/debug/index.cjs +32 -0
  89. package/dist/shared/debug/index.d.cts +2 -0
  90. package/dist/shared/debug/index.d.ts +2 -0
  91. package/dist/shared/debug/index.js +10 -0
  92. package/dist/shared/debug/pause.cjs +56 -0
  93. package/dist/shared/debug/pause.d.cts +23 -0
  94. package/dist/shared/debug/pause.d.ts +23 -0
  95. package/dist/shared/debug/pause.js +30 -0
  96. package/dist/shared/instrumentation/errors.cjs +81 -0
  97. package/dist/shared/instrumentation/errors.d.cts +12 -0
  98. package/dist/shared/instrumentation/errors.d.ts +12 -0
  99. package/dist/shared/instrumentation/errors.js +57 -0
  100. package/dist/shared/instrumentation/index.cjs +35 -0
  101. package/dist/shared/instrumentation/index.d.cts +6 -0
  102. package/dist/shared/instrumentation/index.d.ts +6 -0
  103. package/dist/shared/instrumentation/index.js +12 -0
  104. package/dist/shared/instrumentation/instrument.cjs +206 -0
  105. package/dist/shared/instrumentation/instrument.d.cts +32 -0
  106. package/dist/shared/instrumentation/instrument.d.ts +32 -0
  107. package/dist/shared/instrumentation/instrument.js +190 -0
  108. package/dist/shared/llm/client.cjs +139 -0
  109. package/dist/shared/llm/client.d.cts +6 -0
  110. package/dist/shared/llm/client.d.ts +6 -0
  111. package/dist/shared/llm/client.js +115 -0
  112. package/dist/shared/llm/index.cjs +28 -0
  113. package/dist/shared/llm/index.d.cts +3 -0
  114. package/dist/shared/llm/index.d.ts +3 -0
  115. package/dist/shared/llm/index.js +4 -0
  116. package/dist/shared/llm/types.cjs +16 -0
  117. package/dist/shared/llm/types.d.cts +34 -0
  118. package/dist/shared/llm/types.d.ts +34 -0
  119. package/dist/shared/llm/types.js +0 -0
  120. package/dist/shared/logger/index.cjs +35 -0
  121. package/dist/shared/logger/index.d.cts +2 -0
  122. package/dist/shared/logger/index.d.ts +2 -0
  123. package/dist/shared/logger/index.js +12 -0
  124. package/dist/shared/logger/logger.cjs +200 -0
  125. package/dist/shared/logger/logger.d.cts +70 -0
  126. package/dist/shared/logger/logger.d.ts +70 -0
  127. package/dist/shared/logger/logger.js +176 -0
  128. package/dist/shared/logger/sinks.cjs +160 -0
  129. package/dist/shared/logger/sinks.d.cts +9 -0
  130. package/dist/shared/logger/sinks.d.ts +9 -0
  131. package/dist/shared/logger/sinks.js +124 -0
  132. package/dist/shared/paths/paths.cjs +104 -0
  133. package/dist/shared/paths/paths.d.cts +10 -0
  134. package/dist/shared/paths/paths.d.ts +10 -0
  135. package/dist/shared/paths/paths.js +73 -0
  136. package/dist/shared/run/api.cjs +35 -0
  137. package/dist/shared/run/api.d.cts +3 -0
  138. package/dist/shared/run/api.d.ts +3 -0
  139. package/dist/shared/run/api.js +12 -0
  140. package/dist/shared/run/browser.cjs +98 -0
  141. package/dist/shared/run/browser.d.cts +22 -0
  142. package/dist/shared/run/browser.d.ts +22 -0
  143. package/dist/shared/run/browser.js +74 -0
  144. package/dist/shared/state/index.cjs +38 -0
  145. package/dist/shared/state/index.d.cts +2 -0
  146. package/dist/shared/state/index.d.ts +2 -0
  147. package/dist/shared/state/index.js +16 -0
  148. package/dist/shared/state/session-state.cjs +85 -0
  149. package/dist/shared/state/session-state.d.cts +34 -0
  150. package/dist/shared/state/session-state.d.ts +34 -0
  151. package/dist/shared/state/session-state.js +56 -0
  152. package/dist/shared/visualization/ghost-cursor.cjs +174 -0
  153. package/dist/shared/visualization/ghost-cursor.d.cts +37 -0
  154. package/dist/shared/visualization/ghost-cursor.d.ts +37 -0
  155. package/dist/shared/visualization/ghost-cursor.js +145 -0
  156. package/dist/shared/visualization/highlight.cjs +134 -0
  157. package/dist/shared/visualization/highlight.d.cts +22 -0
  158. package/dist/shared/visualization/highlight.d.ts +22 -0
  159. package/dist/shared/visualization/highlight.js +108 -0
  160. package/dist/shared/visualization/index.cjs +45 -0
  161. package/dist/shared/visualization/index.d.cts +3 -0
  162. package/dist/shared/visualization/index.d.ts +3 -0
  163. package/dist/shared/visualization/index.js +24 -0
  164. package/dist/shared/workflow/workflow.cjs +47 -0
  165. package/dist/shared/workflow/workflow.d.cts +33 -0
  166. package/dist/shared/workflow/workflow.d.ts +33 -0
  167. package/dist/shared/workflow/workflow.js +21 -0
  168. package/package.json +123 -26
  169. package/.npmignore +0 -2
  170. package/bin/libretto +0 -31
  171. package/lib/connect.js +0 -34
  172. package/lib/export.js +0 -224
  173. package/lib/import.js +0 -166
  174. package/lib/index.js +0 -8
  175. package/lib/log.js +0 -9
  176. package/lib/validate.js +0 -20
  177. package/makefile +0 -8
  178. package/src/connect.coffee +0 -25
  179. package/src/export.coffee +0 -222
  180. package/src/import.coffee +0 -166
  181. package/src/index.coffee +0 -3
  182. package/src/log.coffee +0 -3
  183. package/src/validate.coffee +0 -10
@@ -0,0 +1,149 @@
1
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
+ import { dirname, join } from "node:path";
3
+ import { homedir } from "node:os";
4
+ import { z } from "zod";
5
+ import { LIBRETTO_CONFIG_PATH } from "./context.js";
6
+ const CURRENT_CONFIG_VERSION = 1;
7
+ const AiPresetSchema = z.enum(["codex", "claude", "gemini"]);
8
+ const AiConfigSchema = z.object({
9
+ preset: AiPresetSchema,
10
+ commandPrefix: z.array(z.string()).min(1),
11
+ updatedAt: z.string()
12
+ }).strict();
13
+ const LibrettoConfigSchema = z.object({
14
+ version: z.literal(CURRENT_CONFIG_VERSION),
15
+ ai: AiConfigSchema.optional()
16
+ }).passthrough();
17
+ const AI_CONFIG_PRESETS = {
18
+ codex: ["codex", "exec", "--skip-git-repo-check", "--sandbox", "read-only"],
19
+ claude: [join(homedir(), ".claude", "local", "claude"), "-p"],
20
+ gemini: ["gemini", "--output-format", "json"]
21
+ };
22
+ function invalidConfigError(configPath) {
23
+ return new Error(
24
+ `AI config is invalid at ${configPath}. Fix the file to match the expected schema or delete it.`
25
+ );
26
+ }
27
+ function parseConfig(raw, configPath) {
28
+ try {
29
+ return LibrettoConfigSchema.parse(JSON.parse(raw));
30
+ } catch {
31
+ throw invalidConfigError(configPath);
32
+ }
33
+ }
34
+ function readLibrettoConfig(configPath = LIBRETTO_CONFIG_PATH) {
35
+ if (!existsSync(configPath)) {
36
+ return { version: CURRENT_CONFIG_VERSION };
37
+ }
38
+ return parseConfig(readFileSync(configPath, "utf-8"), configPath);
39
+ }
40
+ function writeLibrettoConfig(config, configPath = LIBRETTO_CONFIG_PATH) {
41
+ const parsed = LibrettoConfigSchema.parse(config);
42
+ mkdirSync(dirname(configPath), { recursive: true });
43
+ writeFileSync(configPath, JSON.stringify(parsed, null, 2), "utf-8");
44
+ return parsed;
45
+ }
46
+ function readAiConfig(configPath = LIBRETTO_CONFIG_PATH) {
47
+ return readLibrettoConfig(configPath).ai ?? null;
48
+ }
49
+ function quoteShellArg(value) {
50
+ if (/^[a-zA-Z0-9_./:@=-]+$/.test(value)) return value;
51
+ return JSON.stringify(value);
52
+ }
53
+ function formatCommandPrefix(prefix) {
54
+ return prefix.map((arg) => quoteShellArg(arg)).join(" ");
55
+ }
56
+ function writeAiConfig(preset, commandPrefix, configPath = LIBRETTO_CONFIG_PATH) {
57
+ const librettoConfig = readLibrettoConfig(configPath);
58
+ const ai = AiConfigSchema.parse({
59
+ preset,
60
+ commandPrefix,
61
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
62
+ });
63
+ writeLibrettoConfig(
64
+ {
65
+ ...librettoConfig,
66
+ version: CURRENT_CONFIG_VERSION,
67
+ ai
68
+ },
69
+ configPath
70
+ );
71
+ return ai;
72
+ }
73
+ function clearAiConfig(configPath = LIBRETTO_CONFIG_PATH) {
74
+ const librettoConfig = readLibrettoConfig(configPath);
75
+ if (!librettoConfig.ai) return false;
76
+ writeLibrettoConfig(
77
+ {
78
+ version: librettoConfig.version
79
+ },
80
+ configPath
81
+ );
82
+ return true;
83
+ }
84
+ function printAiConfig(config, configPath) {
85
+ console.log(`AI preset: ${config.preset}`);
86
+ console.log(`Command prefix: ${formatCommandPrefix(config.commandPrefix)}`);
87
+ console.log(`Config file: ${configPath}`);
88
+ console.log(`Updated at: ${config.updatedAt}`);
89
+ }
90
+ function printConfigureUsage(commandName) {
91
+ console.log(
92
+ `Usage: ${commandName} <codex|claude|gemini> [-- <command prefix...>]
93
+ ${commandName}
94
+ ${commandName} --clear`
95
+ );
96
+ }
97
+ function runAiConfigure(input, options = {}) {
98
+ const configureCommandName = options.configureCommandName ?? "libretto-cli ai configure";
99
+ const configPath = options.configPath ?? LIBRETTO_CONFIG_PATH;
100
+ const presetArg = input.preset?.trim();
101
+ const customPrefix = (input.customPrefix ?? []).filter(Boolean);
102
+ if (!presetArg && customPrefix.length === 0 && !input.clear) {
103
+ const config2 = readAiConfig(configPath);
104
+ if (!config2) {
105
+ console.log(`No AI config set. Run '${configureCommandName} codex' to set one.`);
106
+ return;
107
+ }
108
+ printAiConfig(config2, configPath);
109
+ return;
110
+ }
111
+ if (input.clear) {
112
+ const removed = clearAiConfig(configPath);
113
+ if (removed) {
114
+ console.log(`Cleared AI config: ${configPath}`);
115
+ } else {
116
+ console.log("No AI config was set.");
117
+ }
118
+ return;
119
+ }
120
+ const parsedPreset = AiPresetSchema.safeParse(presetArg);
121
+ if (!parsedPreset.success) {
122
+ printConfigureUsage(configureCommandName);
123
+ throw new Error(
124
+ "Missing or invalid preset. Use one of: codex, claude, gemini."
125
+ );
126
+ }
127
+ if (input.customPrefix && input.customPrefix.length > 0 && customPrefix.length === 0) {
128
+ throw new Error("Custom command prefix cannot be empty.");
129
+ }
130
+ const preset = parsedPreset.data;
131
+ const commandPrefix = customPrefix.length > 0 ? customPrefix : AI_CONFIG_PRESETS[preset];
132
+ const config = writeAiConfig(preset, commandPrefix, configPath);
133
+ console.log("AI config saved.");
134
+ printAiConfig(config, configPath);
135
+ }
136
+ export {
137
+ AI_CONFIG_PRESETS,
138
+ AiConfigSchema,
139
+ AiPresetSchema,
140
+ CURRENT_CONFIG_VERSION,
141
+ LibrettoConfigSchema,
142
+ clearAiConfig,
143
+ formatCommandPrefix,
144
+ readAiConfig,
145
+ readLibrettoConfig,
146
+ runAiConfigure,
147
+ writeAiConfig,
148
+ writeLibrettoConfig
149
+ };