libretto 0.2.7 → 0.3.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 (160) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +21 -15
  3. package/skill/SKILL.md +20 -18
  4. package/skill/code-generation-rules.md +3 -3
  5. package/skill/integration-approach-selection.md +3 -3
  6. package/dist/cli/cli.js +0 -209
  7. package/dist/cli/commands/ai.js +0 -21
  8. package/dist/cli/commands/browser.js +0 -82
  9. package/dist/cli/commands/execution.js +0 -461
  10. package/dist/cli/commands/init.js +0 -95
  11. package/dist/cli/commands/logs.js +0 -93
  12. package/dist/cli/commands/snapshot.js +0 -106
  13. package/dist/cli/core/ai-config.js +0 -149
  14. package/dist/cli/core/browser.js +0 -648
  15. package/dist/cli/core/context.js +0 -118
  16. package/dist/cli/core/pause-signals.js +0 -29
  17. package/dist/cli/core/session-telemetry.js +0 -491
  18. package/dist/cli/core/session.js +0 -183
  19. package/dist/cli/core/snapshot-analyzer.js +0 -492
  20. package/dist/cli/core/telemetry.js +0 -362
  21. package/dist/cli/index.js +0 -13
  22. package/dist/cli/workers/run-integration-runtime.js +0 -227
  23. package/dist/cli/workers/run-integration-worker-protocol.js +0 -12
  24. package/dist/cli/workers/run-integration-worker.js +0 -66
  25. package/dist/index.cjs +0 -116
  26. package/dist/index.d.cts +0 -21
  27. package/dist/index.d.ts +0 -21
  28. package/dist/index.js +0 -97
  29. package/dist/runtime/download/download.cjs +0 -70
  30. package/dist/runtime/download/download.d.cts +0 -35
  31. package/dist/runtime/download/download.d.ts +0 -35
  32. package/dist/runtime/download/download.js +0 -45
  33. package/dist/runtime/download/index.cjs +0 -30
  34. package/dist/runtime/download/index.d.cts +0 -3
  35. package/dist/runtime/download/index.d.ts +0 -3
  36. package/dist/runtime/download/index.js +0 -8
  37. package/dist/runtime/extract/extract.cjs +0 -88
  38. package/dist/runtime/extract/extract.d.cts +0 -23
  39. package/dist/runtime/extract/extract.d.ts +0 -23
  40. package/dist/runtime/extract/extract.js +0 -64
  41. package/dist/runtime/extract/index.cjs +0 -28
  42. package/dist/runtime/extract/index.d.cts +0 -5
  43. package/dist/runtime/extract/index.d.ts +0 -5
  44. package/dist/runtime/extract/index.js +0 -4
  45. package/dist/runtime/network/index.cjs +0 -28
  46. package/dist/runtime/network/index.d.cts +0 -4
  47. package/dist/runtime/network/index.d.ts +0 -4
  48. package/dist/runtime/network/index.js +0 -6
  49. package/dist/runtime/network/network.cjs +0 -91
  50. package/dist/runtime/network/network.d.cts +0 -28
  51. package/dist/runtime/network/network.d.ts +0 -28
  52. package/dist/runtime/network/network.js +0 -67
  53. package/dist/runtime/recovery/agent.cjs +0 -223
  54. package/dist/runtime/recovery/agent.d.cts +0 -13
  55. package/dist/runtime/recovery/agent.d.ts +0 -13
  56. package/dist/runtime/recovery/agent.js +0 -199
  57. package/dist/runtime/recovery/errors.cjs +0 -124
  58. package/dist/runtime/recovery/errors.d.cts +0 -31
  59. package/dist/runtime/recovery/errors.d.ts +0 -31
  60. package/dist/runtime/recovery/errors.js +0 -100
  61. package/dist/runtime/recovery/index.cjs +0 -34
  62. package/dist/runtime/recovery/index.d.cts +0 -7
  63. package/dist/runtime/recovery/index.d.ts +0 -7
  64. package/dist/runtime/recovery/index.js +0 -10
  65. package/dist/runtime/recovery/recovery.cjs +0 -55
  66. package/dist/runtime/recovery/recovery.d.cts +0 -12
  67. package/dist/runtime/recovery/recovery.d.ts +0 -12
  68. package/dist/runtime/recovery/recovery.js +0 -31
  69. package/dist/shared/config/config.cjs +0 -44
  70. package/dist/shared/config/config.d.cts +0 -10
  71. package/dist/shared/config/config.d.ts +0 -10
  72. package/dist/shared/config/config.js +0 -18
  73. package/dist/shared/config/index.cjs +0 -32
  74. package/dist/shared/config/index.d.cts +0 -1
  75. package/dist/shared/config/index.d.ts +0 -1
  76. package/dist/shared/config/index.js +0 -10
  77. package/dist/shared/debug/index.cjs +0 -30
  78. package/dist/shared/debug/index.d.cts +0 -1
  79. package/dist/shared/debug/index.d.ts +0 -1
  80. package/dist/shared/debug/index.js +0 -5
  81. package/dist/shared/debug/pause.cjs +0 -90
  82. package/dist/shared/debug/pause.d.cts +0 -16
  83. package/dist/shared/debug/pause.d.ts +0 -16
  84. package/dist/shared/debug/pause.js +0 -55
  85. package/dist/shared/instrumentation/errors.cjs +0 -81
  86. package/dist/shared/instrumentation/errors.d.cts +0 -12
  87. package/dist/shared/instrumentation/errors.d.ts +0 -12
  88. package/dist/shared/instrumentation/errors.js +0 -57
  89. package/dist/shared/instrumentation/index.cjs +0 -35
  90. package/dist/shared/instrumentation/index.d.cts +0 -6
  91. package/dist/shared/instrumentation/index.d.ts +0 -6
  92. package/dist/shared/instrumentation/index.js +0 -12
  93. package/dist/shared/instrumentation/instrument.cjs +0 -206
  94. package/dist/shared/instrumentation/instrument.d.cts +0 -32
  95. package/dist/shared/instrumentation/instrument.d.ts +0 -32
  96. package/dist/shared/instrumentation/instrument.js +0 -190
  97. package/dist/shared/llm/ai-sdk-adapter.cjs +0 -67
  98. package/dist/shared/llm/ai-sdk-adapter.d.cts +0 -22
  99. package/dist/shared/llm/ai-sdk-adapter.d.ts +0 -22
  100. package/dist/shared/llm/ai-sdk-adapter.js +0 -43
  101. package/dist/shared/llm/client.cjs +0 -139
  102. package/dist/shared/llm/client.d.cts +0 -6
  103. package/dist/shared/llm/client.d.ts +0 -6
  104. package/dist/shared/llm/client.js +0 -115
  105. package/dist/shared/llm/index.cjs +0 -31
  106. package/dist/shared/llm/index.d.cts +0 -5
  107. package/dist/shared/llm/index.d.ts +0 -5
  108. package/dist/shared/llm/index.js +0 -6
  109. package/dist/shared/llm/types.cjs +0 -16
  110. package/dist/shared/llm/types.d.cts +0 -66
  111. package/dist/shared/llm/types.d.ts +0 -66
  112. package/dist/shared/llm/types.js +0 -0
  113. package/dist/shared/logger/index.cjs +0 -37
  114. package/dist/shared/logger/index.d.cts +0 -2
  115. package/dist/shared/logger/index.d.ts +0 -2
  116. package/dist/shared/logger/index.js +0 -13
  117. package/dist/shared/logger/logger.cjs +0 -232
  118. package/dist/shared/logger/logger.d.cts +0 -86
  119. package/dist/shared/logger/logger.d.ts +0 -86
  120. package/dist/shared/logger/logger.js +0 -207
  121. package/dist/shared/logger/sinks.cjs +0 -160
  122. package/dist/shared/logger/sinks.d.cts +0 -9
  123. package/dist/shared/logger/sinks.d.ts +0 -9
  124. package/dist/shared/logger/sinks.js +0 -124
  125. package/dist/shared/paths/paths.cjs +0 -104
  126. package/dist/shared/paths/paths.d.cts +0 -10
  127. package/dist/shared/paths/paths.d.ts +0 -10
  128. package/dist/shared/paths/paths.js +0 -73
  129. package/dist/shared/run/api.cjs +0 -28
  130. package/dist/shared/run/api.d.cts +0 -2
  131. package/dist/shared/run/api.d.ts +0 -2
  132. package/dist/shared/run/api.js +0 -4
  133. package/dist/shared/run/browser.cjs +0 -98
  134. package/dist/shared/run/browser.d.cts +0 -22
  135. package/dist/shared/run/browser.d.ts +0 -22
  136. package/dist/shared/run/browser.js +0 -74
  137. package/dist/shared/state/index.cjs +0 -38
  138. package/dist/shared/state/index.d.cts +0 -2
  139. package/dist/shared/state/index.d.ts +0 -2
  140. package/dist/shared/state/index.js +0 -16
  141. package/dist/shared/state/session-state.cjs +0 -85
  142. package/dist/shared/state/session-state.d.cts +0 -34
  143. package/dist/shared/state/session-state.d.ts +0 -34
  144. package/dist/shared/state/session-state.js +0 -56
  145. package/dist/shared/visualization/ghost-cursor.cjs +0 -174
  146. package/dist/shared/visualization/ghost-cursor.d.cts +0 -37
  147. package/dist/shared/visualization/ghost-cursor.d.ts +0 -37
  148. package/dist/shared/visualization/ghost-cursor.js +0 -145
  149. package/dist/shared/visualization/highlight.cjs +0 -134
  150. package/dist/shared/visualization/highlight.d.cts +0 -22
  151. package/dist/shared/visualization/highlight.d.ts +0 -22
  152. package/dist/shared/visualization/highlight.js +0 -108
  153. package/dist/shared/visualization/index.cjs +0 -45
  154. package/dist/shared/visualization/index.d.cts +0 -3
  155. package/dist/shared/visualization/index.d.ts +0 -3
  156. package/dist/shared/visualization/index.js +0 -24
  157. package/dist/shared/workflow/workflow.cjs +0 -47
  158. package/dist/shared/workflow/workflow.d.cts +0 -21
  159. package/dist/shared/workflow/workflow.d.ts +0 -21
  160. package/dist/shared/workflow/workflow.js +0 -21
@@ -1,106 +0,0 @@
1
- import { mkdirSync } from "node:fs";
2
- import { connect, disconnectBrowser } from "../core/browser.js";
3
- import { getSessionSnapshotRunDir } from "../core/context.js";
4
- import {
5
- canAnalyzeSnapshots,
6
- runInterpret
7
- } from "../core/snapshot-analyzer.js";
8
- const DEFAULT_SNAPSHOT_CONTEXT = "No additional user context provided.";
9
- function generateSnapshotRunId() {
10
- return `snapshot-${Date.now()}`;
11
- }
12
- async function captureScreenshot(session, logger, pageId) {
13
- logger.info("screenshot-start", { session, pageId });
14
- const snapshotRunId = generateSnapshotRunId();
15
- const snapshotRunDir = getSessionSnapshotRunDir(session, snapshotRunId);
16
- mkdirSync(snapshotRunDir, { recursive: true });
17
- const { browser, page } = await connect(session, logger, 1e4, {
18
- pageId,
19
- requireSinglePage: true
20
- });
21
- try {
22
- const title = await page.title();
23
- const pageUrl = page.url();
24
- const pngPath = `${snapshotRunDir}/page.png`;
25
- const htmlPath = `${snapshotRunDir}/page.html`;
26
- await page.screenshot({ path: pngPath });
27
- const htmlContent = await page.content();
28
- const fs = await import("node:fs/promises");
29
- await fs.writeFile(htmlPath, htmlContent);
30
- logger.info("screenshot-success", {
31
- session,
32
- pageUrl,
33
- title,
34
- pngPath,
35
- htmlPath,
36
- snapshotRunId
37
- });
38
- return { pngPath, htmlPath, baseName: snapshotRunId };
39
- } catch (err) {
40
- let pageAlive = false;
41
- let browserConnected = false;
42
- try {
43
- browserConnected = browser.isConnected();
44
- pageAlive = !page.isClosed();
45
- } catch {
46
- }
47
- logger.error("screenshot-error", {
48
- error: err,
49
- session,
50
- pageAlive,
51
- browserConnected,
52
- pageUrl: page.url()
53
- });
54
- throw err;
55
- } finally {
56
- disconnectBrowser(browser, logger, session);
57
- }
58
- }
59
- async function runSnapshot(session, logger, pageId, objective, context) {
60
- const { pngPath, htmlPath } = await captureScreenshot(session, logger, pageId);
61
- console.log("Screenshot saved:");
62
- console.log(` PNG: ${pngPath}`);
63
- console.log(` HTML: ${htmlPath}`);
64
- const normalizedObjective = objective?.trim();
65
- const normalizedContext = context?.trim();
66
- if (!normalizedObjective && !normalizedContext) {
67
- console.log("Use --objective flag to analyze snapshots.");
68
- return;
69
- }
70
- if (!normalizedObjective) {
71
- throw new Error(
72
- "Couldn't run analysis: --objective is required when providing --context."
73
- );
74
- }
75
- if (!canAnalyzeSnapshots()) {
76
- throw new Error(
77
- "Couldn't run analysis: no AI config set. Run 'libretto-cli ai configure codex' (or claude/gemini) to enable analysis."
78
- );
79
- }
80
- await runInterpret({
81
- objective: normalizedObjective,
82
- session,
83
- context: normalizedContext ?? DEFAULT_SNAPSHOT_CONTEXT,
84
- pngPath,
85
- htmlPath
86
- }, logger);
87
- }
88
- function registerSnapshotCommands(yargs, logger) {
89
- return yargs.command(
90
- "snapshot",
91
- "Capture PNG + HTML; analyze when --objective is provided (--context optional)",
92
- (cmd) => cmd.option("page", { type: "string" }).option("objective", { type: "string" }).option("context", { type: "string" }),
93
- async (argv) => {
94
- await runSnapshot(
95
- String(argv.session),
96
- logger,
97
- argv.page ? String(argv.page) : void 0,
98
- argv.objective,
99
- argv.context
100
- );
101
- }
102
- );
103
- }
104
- export {
105
- registerSnapshotCommands
106
- };
@@ -1,149 +0,0 @@
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
- };