libretto 0.4.4 → 0.5.1
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 +106 -36
- package/dist/cli/cli.js +39 -113
- package/dist/cli/commands/ai.js +1 -1
- package/dist/cli/commands/browser.js +87 -60
- package/dist/cli/commands/execution.js +201 -88
- package/dist/cli/commands/init.js +30 -8
- package/dist/cli/commands/logs.js +5 -6
- package/dist/cli/commands/shared.js +30 -29
- package/dist/cli/commands/snapshot.js +26 -39
- package/dist/cli/core/ai-config.js +9 -2
- package/dist/cli/core/api-snapshot-analyzer.js +15 -5
- package/dist/cli/core/browser.js +141 -33
- package/dist/cli/core/context.js +7 -18
- package/dist/cli/core/session-telemetry.js +5 -2
- package/dist/cli/core/session.js +23 -10
- package/dist/cli/core/snapshot-analyzer.js +16 -33
- package/dist/cli/core/snapshot-api-config.js +2 -6
- package/dist/cli/core/telemetry.js +10 -2
- package/dist/cli/framework/simple-cli.js +45 -25
- package/dist/cli/router.js +14 -21
- package/dist/cli/workers/run-integration-runtime.js +26 -7
- package/dist/cli/workers/run-integration-worker-protocol.js +3 -1
- package/dist/cli/workers/run-integration-worker.js +1 -4
- package/dist/index.d.ts +1 -2
- package/dist/index.js +7 -10
- package/dist/runtime/download/download.js +5 -1
- package/dist/runtime/extract/extract.js +11 -2
- package/dist/runtime/network/network.js +8 -1
- package/dist/runtime/recovery/agent.js +6 -2
- package/dist/runtime/recovery/errors.js +3 -1
- package/dist/runtime/recovery/recovery.js +3 -1
- package/dist/shared/condense-dom/condense-dom.js +6 -13
- package/dist/shared/config/config.d.ts +1 -9
- package/dist/shared/config/config.js +0 -18
- package/dist/shared/config/index.d.ts +2 -1
- package/dist/shared/config/index.js +0 -10
- package/dist/shared/debug/pause.js +9 -3
- package/dist/shared/instrumentation/instrument.js +101 -5
- package/dist/shared/llm/ai-sdk-adapter.js +3 -1
- package/dist/shared/llm/client.js +3 -1
- package/dist/shared/logger/index.js +4 -1
- package/dist/shared/paths/paths.js +2 -1
- package/dist/shared/paths/repo-root.d.ts +3 -0
- package/dist/shared/paths/repo-root.js +24 -0
- package/dist/shared/run/api.js +3 -1
- package/dist/shared/run/browser.js +7 -2
- package/dist/shared/state/session-state.d.ts +2 -1
- package/dist/shared/state/session-state.js +5 -2
- package/dist/shared/visualization/ghost-cursor.js +19 -10
- package/dist/shared/visualization/highlight.js +9 -6
- package/dist/shared/workflow/workflow.d.ts +4 -5
- package/dist/shared/workflow/workflow.js +3 -5
- package/package.json +11 -8
- package/scripts/check-skills-sync.mjs +25 -0
- package/scripts/compare-eval-summary.mjs +47 -0
- package/scripts/postinstall.mjs +26 -17
- package/scripts/prepare-release.sh +97 -0
- package/scripts/skills-libretto.mjs +103 -0
- package/scripts/summarize-evals.mjs +135 -0
- package/scripts/sync-skills.mjs +12 -0
- package/skills/libretto/SKILL.md +130 -377
- package/skills/libretto/references/auth-profiles.md +30 -0
- package/skills/libretto/{code-generation-rules.md → references/code-generation-rules.md} +27 -42
- package/skills/libretto/references/configuration-file-reference.md +53 -0
- package/skills/libretto/references/pages-and-page-targeting.md +29 -0
- package/skills/libretto/references/site-security-review.md +143 -0
- package/src/cli/cli.ts +86 -0
- package/src/cli/commands/ai.ts +35 -0
- package/src/cli/commands/browser.ts +189 -0
- package/src/cli/commands/execution.ts +822 -0
- package/src/cli/commands/init.ts +350 -0
- package/src/cli/commands/logs.ts +128 -0
- package/src/cli/commands/shared.ts +69 -0
- package/src/cli/commands/snapshot.ts +312 -0
- package/src/cli/core/ai-config.ts +264 -0
- package/src/cli/core/api-snapshot-analyzer.ts +108 -0
- package/src/cli/core/browser.ts +976 -0
- package/src/cli/core/context.ts +127 -0
- package/src/cli/core/pause-signals.ts +35 -0
- package/src/cli/core/session-telemetry.ts +564 -0
- package/src/cli/core/session.ts +223 -0
- package/src/cli/core/snapshot-analyzer.ts +855 -0
- package/src/cli/core/snapshot-api-config.ts +231 -0
- package/src/cli/core/telemetry.ts +459 -0
- package/src/cli/framework/simple-cli.ts +1340 -0
- package/src/cli/index.ts +13 -0
- package/src/cli/router.ts +20 -0
- package/src/cli/workers/run-integration-runtime.ts +338 -0
- package/src/cli/workers/run-integration-worker-protocol.ts +16 -0
- package/src/cli/workers/run-integration-worker.ts +72 -0
- package/src/index.ts +127 -0
- package/src/runtime/download/download.ts +104 -0
- package/src/runtime/download/index.ts +7 -0
- package/src/runtime/extract/extract.ts +102 -0
- package/src/runtime/extract/index.ts +1 -0
- package/src/runtime/network/index.ts +5 -0
- package/src/runtime/network/network.ts +119 -0
- package/{dist/runtime/recovery/agent.cjs → src/runtime/recovery/agent.ts} +114 -76
- package/src/runtime/recovery/errors.ts +155 -0
- package/src/runtime/recovery/index.ts +7 -0
- package/src/runtime/recovery/recovery.ts +53 -0
- package/{dist/shared/condense-dom/condense-dom.cjs → src/shared/condense-dom/condense-dom.ts} +249 -124
- package/src/shared/config/config.ts +3 -0
- package/src/shared/config/index.ts +0 -0
- package/src/shared/debug/index.ts +1 -0
- package/src/shared/debug/pause.ts +91 -0
- package/src/shared/instrumentation/errors.ts +84 -0
- package/src/shared/instrumentation/index.ts +9 -0
- package/src/shared/instrumentation/instrument.ts +406 -0
- package/src/shared/llm/ai-sdk-adapter.ts +81 -0
- package/{dist/shared/llm/client.cjs → src/shared/llm/client.ts} +86 -80
- package/src/shared/llm/index.ts +3 -0
- package/src/shared/llm/types.ts +63 -0
- package/src/shared/logger/index.ts +13 -0
- package/src/shared/logger/logger.ts +358 -0
- package/src/shared/logger/sinks.ts +148 -0
- package/src/shared/paths/paths.ts +110 -0
- package/src/shared/paths/repo-root.ts +27 -0
- package/src/shared/run/api.ts +6 -0
- package/src/shared/run/browser.ts +107 -0
- package/src/shared/state/index.ts +11 -0
- package/src/shared/state/session-state.ts +77 -0
- package/src/shared/visualization/ghost-cursor.ts +213 -0
- package/src/shared/visualization/highlight.ts +149 -0
- package/src/shared/visualization/index.ts +18 -0
- package/src/shared/workflow/workflow.ts +36 -0
- package/dist/index.cjs +0 -144
- package/dist/index.d.cts +0 -21
- package/dist/runtime/download/download.cjs +0 -70
- package/dist/runtime/download/download.d.cts +0 -35
- package/dist/runtime/download/index.cjs +0 -30
- package/dist/runtime/download/index.d.cts +0 -3
- package/dist/runtime/extract/extract.cjs +0 -88
- package/dist/runtime/extract/extract.d.cts +0 -23
- package/dist/runtime/extract/index.cjs +0 -28
- package/dist/runtime/extract/index.d.cts +0 -5
- package/dist/runtime/network/index.cjs +0 -28
- package/dist/runtime/network/index.d.cts +0 -4
- package/dist/runtime/network/network.cjs +0 -91
- package/dist/runtime/network/network.d.cts +0 -28
- package/dist/runtime/recovery/agent.d.cts +0 -13
- package/dist/runtime/recovery/errors.cjs +0 -124
- package/dist/runtime/recovery/errors.d.cts +0 -31
- package/dist/runtime/recovery/index.cjs +0 -34
- package/dist/runtime/recovery/index.d.cts +0 -7
- package/dist/runtime/recovery/recovery.cjs +0 -55
- package/dist/runtime/recovery/recovery.d.cts +0 -12
- package/dist/shared/condense-dom/condense-dom.d.cts +0 -34
- package/dist/shared/config/config.cjs +0 -44
- package/dist/shared/config/config.d.cts +0 -10
- package/dist/shared/config/index.cjs +0 -32
- package/dist/shared/config/index.d.cts +0 -1
- package/dist/shared/debug/index.cjs +0 -28
- package/dist/shared/debug/index.d.cts +0 -1
- package/dist/shared/debug/pause.cjs +0 -86
- package/dist/shared/debug/pause.d.cts +0 -12
- package/dist/shared/instrumentation/errors.cjs +0 -81
- package/dist/shared/instrumentation/errors.d.cts +0 -12
- package/dist/shared/instrumentation/index.cjs +0 -35
- package/dist/shared/instrumentation/index.d.cts +0 -6
- package/dist/shared/instrumentation/instrument.cjs +0 -206
- package/dist/shared/instrumentation/instrument.d.cts +0 -32
- package/dist/shared/llm/ai-sdk-adapter.cjs +0 -71
- package/dist/shared/llm/ai-sdk-adapter.d.cts +0 -22
- package/dist/shared/llm/client.d.cts +0 -13
- package/dist/shared/llm/index.cjs +0 -31
- package/dist/shared/llm/index.d.cts +0 -5
- package/dist/shared/llm/types.cjs +0 -16
- package/dist/shared/llm/types.d.cts +0 -67
- package/dist/shared/logger/index.cjs +0 -37
- package/dist/shared/logger/index.d.cts +0 -2
- package/dist/shared/logger/logger.cjs +0 -232
- package/dist/shared/logger/logger.d.cts +0 -86
- package/dist/shared/logger/sinks.cjs +0 -160
- package/dist/shared/logger/sinks.d.cts +0 -9
- package/dist/shared/paths/paths.cjs +0 -104
- package/dist/shared/paths/paths.d.cts +0 -10
- package/dist/shared/run/api.cjs +0 -28
- package/dist/shared/run/api.d.cts +0 -2
- package/dist/shared/run/browser.cjs +0 -98
- package/dist/shared/run/browser.d.cts +0 -22
- package/dist/shared/state/index.cjs +0 -38
- package/dist/shared/state/index.d.cts +0 -2
- package/dist/shared/state/session-state.cjs +0 -92
- package/dist/shared/state/session-state.d.cts +0 -40
- package/dist/shared/visualization/ghost-cursor.cjs +0 -174
- package/dist/shared/visualization/ghost-cursor.d.cts +0 -37
- package/dist/shared/visualization/highlight.cjs +0 -134
- package/dist/shared/visualization/highlight.d.cts +0 -22
- package/dist/shared/visualization/index.cjs +0 -45
- package/dist/shared/visualization/index.d.cts +0 -3
- package/dist/shared/workflow/workflow.cjs +0 -47
- package/dist/shared/workflow/workflow.d.cts +0 -21
- package/skills/libretto/integration-approach-selection.md +0 -174
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { Logger, createFileLogSink } from "../../shared/logger/index.js";
|
|
2
|
+
import type { LLMClient } from "../../shared/llm/index.js";
|
|
3
|
+
import type { LoggerApi } from "../../shared/logger/index.js";
|
|
4
|
+
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { resolveLibrettoRepoRoot } from "../../shared/paths/repo-root.js";
|
|
7
|
+
import { validateSessionName } from "./session.js";
|
|
8
|
+
|
|
9
|
+
export const REPO_ROOT = resolveLibrettoRepoRoot();
|
|
10
|
+
export const LIBRETTO_CONFIG_DIR = join(REPO_ROOT, ".libretto");
|
|
11
|
+
export const LIBRETTO_CONFIG_PATH = join(LIBRETTO_CONFIG_DIR, "config.json");
|
|
12
|
+
export const PROFILES_DIR = join(LIBRETTO_CONFIG_DIR, "profiles");
|
|
13
|
+
export const LIBRETTO_SESSIONS_DIR = join(LIBRETTO_CONFIG_DIR, "sessions");
|
|
14
|
+
export const LIBRETTO_GITIGNORE_PATH = join(LIBRETTO_CONFIG_DIR, ".gitignore");
|
|
15
|
+
|
|
16
|
+
const LIBRETTO_GITIGNORE_CONTENT = [
|
|
17
|
+
"# Local libretto runtime state",
|
|
18
|
+
"sessions/",
|
|
19
|
+
"profiles/",
|
|
20
|
+
"",
|
|
21
|
+
].join("\n");
|
|
22
|
+
|
|
23
|
+
export function getSessionDir(session: string): string {
|
|
24
|
+
return join(LIBRETTO_SESSIONS_DIR, session);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function getSessionStatePath(session: string): string {
|
|
28
|
+
return join(getSessionDir(session), "state.json");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function getSessionLogsPath(session: string): string {
|
|
32
|
+
return join(getSessionDir(session), "logs.jsonl");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function getSessionNetworkLogPath(session: string): string {
|
|
36
|
+
return join(getSessionDir(session), "network.jsonl");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function getSessionActionsLogPath(session: string): string {
|
|
40
|
+
return join(getSessionDir(session), "actions.jsonl");
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function getSessionSnapshotsDir(session: string): string {
|
|
44
|
+
return join(getSessionDir(session), "snapshots");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function getSessionSnapshotRunDir(
|
|
48
|
+
session: string,
|
|
49
|
+
snapshotRunId: string,
|
|
50
|
+
): string {
|
|
51
|
+
return join(getSessionSnapshotsDir(session), snapshotRunId);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function ensureLibrettoSetup(): void {
|
|
55
|
+
mkdirSync(LIBRETTO_CONFIG_DIR, { recursive: true });
|
|
56
|
+
mkdirSync(LIBRETTO_SESSIONS_DIR, { recursive: true });
|
|
57
|
+
mkdirSync(PROFILES_DIR, { recursive: true });
|
|
58
|
+
|
|
59
|
+
if (!existsSync(LIBRETTO_GITIGNORE_PATH)) {
|
|
60
|
+
writeFileSync(LIBRETTO_GITIGNORE_PATH, LIBRETTO_GITIGNORE_CONTENT, "utf-8");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function createLoggerForSession(session: string): Logger {
|
|
65
|
+
validateSessionName(session);
|
|
66
|
+
const sessionDir = getSessionDir(session);
|
|
67
|
+
mkdirSync(sessionDir, { recursive: true });
|
|
68
|
+
const logFilePath = getSessionLogsPath(session);
|
|
69
|
+
return new Logger(
|
|
70
|
+
["libretto"],
|
|
71
|
+
[createFileLogSink({ filePath: logFilePath })],
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export async function closeLogger(
|
|
76
|
+
logger: Logger | null | undefined,
|
|
77
|
+
): Promise<void> {
|
|
78
|
+
if (!logger) return;
|
|
79
|
+
await logger.close();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export async function withSessionLogger<T>(
|
|
83
|
+
session: string,
|
|
84
|
+
run: (logger: Logger) => Promise<T>,
|
|
85
|
+
): Promise<T> {
|
|
86
|
+
const logger = createLoggerForSession(session);
|
|
87
|
+
try {
|
|
88
|
+
return await run(logger);
|
|
89
|
+
} finally {
|
|
90
|
+
await closeLogger(logger);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
let llmClientFactory:
|
|
95
|
+
| ((logger: LoggerApi, model: string) => Promise<LLMClient>)
|
|
96
|
+
| null = null;
|
|
97
|
+
|
|
98
|
+
export function setLLMClientFactory(
|
|
99
|
+
factory: (logger: LoggerApi, model: string) => Promise<LLMClient>,
|
|
100
|
+
): void {
|
|
101
|
+
llmClientFactory = factory;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function getLLMClientFactory():
|
|
105
|
+
| ((logger: LoggerApi, model: string) => Promise<LLMClient>)
|
|
106
|
+
| null {
|
|
107
|
+
return llmClientFactory;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function maybeConfigureLLMClientFactoryFromEnv(): void {
|
|
111
|
+
if (llmClientFactory) return;
|
|
112
|
+
|
|
113
|
+
const hasAnyCreds =
|
|
114
|
+
process.env.GOOGLE_CLOUD_PROJECT ||
|
|
115
|
+
process.env.GCLOUD_PROJECT ||
|
|
116
|
+
process.env.ANTHROPIC_API_KEY ||
|
|
117
|
+
process.env.OPENAI_API_KEY ||
|
|
118
|
+
process.env.GEMINI_API_KEY ||
|
|
119
|
+
process.env.GOOGLE_GENERATIVE_AI_API_KEY;
|
|
120
|
+
|
|
121
|
+
if (!hasAnyCreds) return;
|
|
122
|
+
|
|
123
|
+
setLLMClientFactory(async (_logger, model) => {
|
|
124
|
+
const { createLLMClient } = await import("../../shared/llm/index.js");
|
|
125
|
+
return createLLMClient(model);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { unlink } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { getSessionDir } from "./context.js";
|
|
5
|
+
|
|
6
|
+
export type PauseSignalPaths = {
|
|
7
|
+
pausedSignalPath: string;
|
|
8
|
+
resumeSignalPath: string;
|
|
9
|
+
completedSignalPath: string;
|
|
10
|
+
failedSignalPath: string;
|
|
11
|
+
outputSignalPath: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export function getPauseSignalPaths(session: string): PauseSignalPaths {
|
|
15
|
+
const sessionDir = getSessionDir(session);
|
|
16
|
+
return {
|
|
17
|
+
pausedSignalPath: join(sessionDir, `${session}.paused`),
|
|
18
|
+
resumeSignalPath: join(sessionDir, `${session}.resume`),
|
|
19
|
+
completedSignalPath: join(sessionDir, `${session}.completed`),
|
|
20
|
+
failedSignalPath: join(sessionDir, `${session}.failed`),
|
|
21
|
+
outputSignalPath: join(sessionDir, `${session}.output`),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export async function removeSignalIfExists(path: string): Promise<void> {
|
|
26
|
+
if (!existsSync(path)) return;
|
|
27
|
+
try {
|
|
28
|
+
await unlink(path);
|
|
29
|
+
} catch (error) {
|
|
30
|
+
const code = (error as NodeJS.ErrnoException).code;
|
|
31
|
+
if (code !== "ENOENT") {
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|