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.
- package/README.md +213 -17
- package/bin/libretto.mjs +18 -0
- package/dist/cli/cli.js +201 -0
- package/dist/cli/commands/ai.js +21 -0
- package/dist/cli/commands/browser.js +56 -0
- package/dist/cli/commands/execution.js +407 -0
- package/dist/cli/commands/logs.js +65 -0
- package/dist/cli/commands/snapshot.js +99 -0
- package/dist/cli/core/ai-config.js +149 -0
- package/dist/cli/core/browser.js +687 -0
- package/dist/cli/core/context.js +113 -0
- package/dist/cli/core/pause-signals.js +29 -0
- package/dist/cli/core/session.js +183 -0
- package/dist/cli/core/snapshot-analyzer.js +492 -0
- package/dist/cli/core/telemetry.js +350 -0
- package/dist/cli/index.js +13 -0
- package/dist/cli/workers/run-integration-runtime.js +204 -0
- package/dist/cli/workers/run-integration-worker-protocol.js +0 -0
- package/dist/cli/workers/run-integration-worker.js +83 -0
- package/dist/index.cjs +127 -0
- package/dist/index.d.cts +22 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +110 -0
- package/dist/runtime/download/download.cjs +70 -0
- package/dist/runtime/download/download.d.cts +35 -0
- package/dist/runtime/download/download.d.ts +35 -0
- package/dist/runtime/download/download.js +45 -0
- package/dist/runtime/download/index.cjs +30 -0
- package/dist/runtime/download/index.d.cts +3 -0
- package/dist/runtime/download/index.d.ts +3 -0
- package/dist/runtime/download/index.js +8 -0
- package/dist/runtime/extract/extract.cjs +87 -0
- package/dist/runtime/extract/extract.d.cts +23 -0
- package/dist/runtime/extract/extract.d.ts +23 -0
- package/dist/runtime/extract/extract.js +63 -0
- package/dist/runtime/extract/index.cjs +28 -0
- package/dist/runtime/extract/index.d.cts +5 -0
- package/dist/runtime/extract/index.d.ts +5 -0
- package/dist/runtime/extract/index.js +4 -0
- package/dist/runtime/network/index.cjs +28 -0
- package/dist/runtime/network/index.d.cts +4 -0
- package/dist/runtime/network/index.d.ts +4 -0
- package/dist/runtime/network/index.js +6 -0
- package/dist/runtime/network/network.cjs +91 -0
- package/dist/runtime/network/network.d.cts +28 -0
- package/dist/runtime/network/network.d.ts +28 -0
- package/dist/runtime/network/network.js +67 -0
- package/dist/runtime/recovery/agent.cjs +218 -0
- package/dist/runtime/recovery/agent.d.cts +13 -0
- package/dist/runtime/recovery/agent.d.ts +13 -0
- package/dist/runtime/recovery/agent.js +194 -0
- package/dist/runtime/recovery/errors.cjs +122 -0
- package/dist/runtime/recovery/errors.d.cts +31 -0
- package/dist/runtime/recovery/errors.d.ts +31 -0
- package/dist/runtime/recovery/errors.js +98 -0
- package/dist/runtime/recovery/index.cjs +34 -0
- package/dist/runtime/recovery/index.d.cts +7 -0
- package/dist/runtime/recovery/index.d.ts +7 -0
- package/dist/runtime/recovery/index.js +10 -0
- package/dist/runtime/recovery/recovery.cjs +53 -0
- package/dist/runtime/recovery/recovery.d.cts +12 -0
- package/dist/runtime/recovery/recovery.d.ts +12 -0
- package/dist/runtime/recovery/recovery.js +29 -0
- package/dist/runtime/step/index.cjs +31 -0
- package/dist/runtime/step/index.d.cts +7 -0
- package/dist/runtime/step/index.d.ts +7 -0
- package/dist/runtime/step/index.js +6 -0
- package/dist/runtime/step/runner.cjs +208 -0
- package/dist/runtime/step/runner.d.cts +16 -0
- package/dist/runtime/step/runner.d.ts +16 -0
- package/dist/runtime/step/runner.js +187 -0
- package/dist/runtime/step/step.cjs +67 -0
- package/dist/runtime/step/step.d.cts +23 -0
- package/dist/runtime/step/step.d.ts +23 -0
- package/dist/runtime/step/step.js +43 -0
- package/dist/runtime/step/types.cjs +16 -0
- package/dist/runtime/step/types.d.cts +72 -0
- package/dist/runtime/step/types.d.ts +72 -0
- package/dist/runtime/step/types.js +0 -0
- package/dist/shared/config/config.cjs +44 -0
- package/dist/shared/config/config.d.cts +10 -0
- package/dist/shared/config/config.d.ts +10 -0
- package/dist/shared/config/config.js +18 -0
- package/dist/shared/config/index.cjs +32 -0
- package/dist/shared/config/index.d.cts +1 -0
- package/dist/shared/config/index.d.ts +1 -0
- package/dist/shared/config/index.js +10 -0
- package/dist/shared/debug/index.cjs +32 -0
- package/dist/shared/debug/index.d.cts +2 -0
- package/dist/shared/debug/index.d.ts +2 -0
- package/dist/shared/debug/index.js +10 -0
- package/dist/shared/debug/pause.cjs +56 -0
- package/dist/shared/debug/pause.d.cts +23 -0
- package/dist/shared/debug/pause.d.ts +23 -0
- package/dist/shared/debug/pause.js +30 -0
- package/dist/shared/instrumentation/errors.cjs +81 -0
- package/dist/shared/instrumentation/errors.d.cts +12 -0
- package/dist/shared/instrumentation/errors.d.ts +12 -0
- package/dist/shared/instrumentation/errors.js +57 -0
- package/dist/shared/instrumentation/index.cjs +35 -0
- package/dist/shared/instrumentation/index.d.cts +6 -0
- package/dist/shared/instrumentation/index.d.ts +6 -0
- package/dist/shared/instrumentation/index.js +12 -0
- package/dist/shared/instrumentation/instrument.cjs +206 -0
- package/dist/shared/instrumentation/instrument.d.cts +32 -0
- package/dist/shared/instrumentation/instrument.d.ts +32 -0
- package/dist/shared/instrumentation/instrument.js +190 -0
- package/dist/shared/llm/client.cjs +139 -0
- package/dist/shared/llm/client.d.cts +6 -0
- package/dist/shared/llm/client.d.ts +6 -0
- package/dist/shared/llm/client.js +115 -0
- package/dist/shared/llm/index.cjs +28 -0
- package/dist/shared/llm/index.d.cts +3 -0
- package/dist/shared/llm/index.d.ts +3 -0
- package/dist/shared/llm/index.js +4 -0
- package/dist/shared/llm/types.cjs +16 -0
- package/dist/shared/llm/types.d.cts +34 -0
- package/dist/shared/llm/types.d.ts +34 -0
- package/dist/shared/llm/types.js +0 -0
- package/dist/shared/logger/index.cjs +35 -0
- package/dist/shared/logger/index.d.cts +2 -0
- package/dist/shared/logger/index.d.ts +2 -0
- package/dist/shared/logger/index.js +12 -0
- package/dist/shared/logger/logger.cjs +200 -0
- package/dist/shared/logger/logger.d.cts +70 -0
- package/dist/shared/logger/logger.d.ts +70 -0
- package/dist/shared/logger/logger.js +176 -0
- package/dist/shared/logger/sinks.cjs +160 -0
- package/dist/shared/logger/sinks.d.cts +9 -0
- package/dist/shared/logger/sinks.d.ts +9 -0
- package/dist/shared/logger/sinks.js +124 -0
- package/dist/shared/paths/paths.cjs +104 -0
- package/dist/shared/paths/paths.d.cts +10 -0
- package/dist/shared/paths/paths.d.ts +10 -0
- package/dist/shared/paths/paths.js +73 -0
- package/dist/shared/run/api.cjs +35 -0
- package/dist/shared/run/api.d.cts +3 -0
- package/dist/shared/run/api.d.ts +3 -0
- package/dist/shared/run/api.js +12 -0
- package/dist/shared/run/browser.cjs +98 -0
- package/dist/shared/run/browser.d.cts +22 -0
- package/dist/shared/run/browser.d.ts +22 -0
- package/dist/shared/run/browser.js +74 -0
- package/dist/shared/state/index.cjs +38 -0
- package/dist/shared/state/index.d.cts +2 -0
- package/dist/shared/state/index.d.ts +2 -0
- package/dist/shared/state/index.js +16 -0
- package/dist/shared/state/session-state.cjs +85 -0
- package/dist/shared/state/session-state.d.cts +34 -0
- package/dist/shared/state/session-state.d.ts +34 -0
- package/dist/shared/state/session-state.js +56 -0
- package/dist/shared/visualization/ghost-cursor.cjs +174 -0
- package/dist/shared/visualization/ghost-cursor.d.cts +37 -0
- package/dist/shared/visualization/ghost-cursor.d.ts +37 -0
- package/dist/shared/visualization/ghost-cursor.js +145 -0
- package/dist/shared/visualization/highlight.cjs +134 -0
- package/dist/shared/visualization/highlight.d.cts +22 -0
- package/dist/shared/visualization/highlight.d.ts +22 -0
- package/dist/shared/visualization/highlight.js +108 -0
- package/dist/shared/visualization/index.cjs +45 -0
- package/dist/shared/visualization/index.d.cts +3 -0
- package/dist/shared/visualization/index.d.ts +3 -0
- package/dist/shared/visualization/index.js +24 -0
- package/dist/shared/workflow/workflow.cjs +47 -0
- package/dist/shared/workflow/workflow.d.cts +33 -0
- package/dist/shared/workflow/workflow.d.ts +33 -0
- package/dist/shared/workflow/workflow.js +21 -0
- package/package.json +123 -26
- package/.npmignore +0 -2
- package/bin/libretto +0 -31
- package/lib/connect.js +0 -34
- package/lib/export.js +0 -224
- package/lib/import.js +0 -166
- package/lib/index.js +0 -8
- package/lib/log.js +0 -9
- package/lib/validate.js +0 -20
- package/makefile +0 -8
- package/src/connect.coffee +0 -25
- package/src/export.coffee +0 -222
- package/src/import.coffee +0 -166
- package/src/index.coffee +0 -3
- package/src/log.coffee +0 -3
- 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
|
+
};
|