libretto 0.6.10 → 0.6.12

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 (119) hide show
  1. package/README.md +4 -0
  2. package/README.template.md +4 -0
  3. package/dist/cli/cli.js +4 -3
  4. package/dist/cli/commands/ai.js +3 -2
  5. package/dist/cli/commands/browser.js +17 -17
  6. package/dist/cli/commands/execution.js +254 -234
  7. package/dist/cli/commands/experiments.js +100 -0
  8. package/dist/cli/commands/setup.js +20 -34
  9. package/dist/cli/commands/shared.js +10 -0
  10. package/dist/cli/commands/snapshot.js +81 -9
  11. package/dist/cli/commands/status.js +5 -4
  12. package/dist/cli/core/ai-model.js +6 -3
  13. package/dist/cli/core/browser.js +300 -121
  14. package/dist/cli/core/config.js +4 -2
  15. package/dist/cli/core/context.js +4 -0
  16. package/dist/cli/core/daemon/config.js +0 -6
  17. package/dist/cli/core/daemon/daemon.js +535 -89
  18. package/dist/cli/core/daemon/ipc.js +170 -129
  19. package/dist/cli/core/daemon/snapshot.js +72 -6
  20. package/dist/cli/core/experiments.js +66 -0
  21. package/dist/cli/core/session.js +5 -4
  22. package/dist/cli/core/skill-version.js +2 -1
  23. package/dist/cli/core/snapshot-analyzer.js +4 -3
  24. package/dist/cli/core/workflow-runner/runner.js +147 -0
  25. package/dist/cli/core/workflow-runtime.js +60 -0
  26. package/dist/cli/router.js +4 -1
  27. package/dist/shared/debug/pause-handler.d.ts +9 -0
  28. package/dist/shared/debug/pause-handler.js +15 -0
  29. package/dist/shared/debug/pause.d.ts +1 -2
  30. package/dist/shared/debug/pause.js +13 -36
  31. package/dist/shared/ipc/child-process-transport.d.ts +7 -0
  32. package/dist/shared/ipc/child-process-transport.js +60 -0
  33. package/dist/shared/ipc/child-process-transport.spec.d.ts +2 -0
  34. package/dist/shared/ipc/child-process-transport.spec.js +68 -0
  35. package/dist/shared/ipc/ipc.d.ts +46 -0
  36. package/dist/shared/ipc/ipc.js +165 -0
  37. package/dist/shared/ipc/ipc.spec.d.ts +2 -0
  38. package/dist/shared/ipc/ipc.spec.js +114 -0
  39. package/dist/shared/ipc/socket-transport.d.ts +9 -0
  40. package/dist/shared/ipc/socket-transport.js +143 -0
  41. package/dist/shared/ipc/socket-transport.spec.d.ts +2 -0
  42. package/dist/shared/ipc/socket-transport.spec.js +117 -0
  43. package/dist/shared/package-manager.d.ts +7 -0
  44. package/dist/shared/package-manager.js +60 -0
  45. package/dist/shared/paths/paths.d.ts +1 -8
  46. package/dist/shared/paths/paths.js +1 -49
  47. package/dist/shared/snapshot/capture-snapshot.d.ts +9 -0
  48. package/dist/shared/snapshot/capture-snapshot.js +463 -0
  49. package/dist/shared/snapshot/diff-snapshots.d.ts +72 -0
  50. package/dist/shared/snapshot/diff-snapshots.js +358 -0
  51. package/dist/shared/snapshot/render-snapshot.d.ts +39 -0
  52. package/dist/shared/snapshot/render-snapshot.js +651 -0
  53. package/dist/shared/snapshot/snapshot.spec.d.ts +2 -0
  54. package/dist/shared/snapshot/snapshot.spec.js +333 -0
  55. package/dist/shared/snapshot/types.d.ts +40 -0
  56. package/dist/shared/snapshot/types.js +0 -0
  57. package/dist/shared/snapshot/wait-for-page-stable.d.ts +17 -0
  58. package/dist/shared/snapshot/wait-for-page-stable.js +281 -0
  59. package/dist/shared/state/session-state.d.ts +1 -0
  60. package/dist/shared/state/session-state.js +1 -0
  61. package/docs/experiments.md +67 -0
  62. package/package.json +4 -2
  63. package/skills/libretto/SKILL.md +3 -1
  64. package/skills/libretto-readonly/SKILL.md +1 -1
  65. package/src/cli/AGENTS.md +7 -0
  66. package/src/cli/cli.ts +4 -3
  67. package/src/cli/commands/ai.ts +3 -2
  68. package/src/cli/commands/browser.ts +13 -11
  69. package/src/cli/commands/execution.ts +303 -271
  70. package/src/cli/commands/experiments.ts +120 -0
  71. package/src/cli/commands/setup.ts +18 -36
  72. package/src/cli/commands/shared.ts +20 -0
  73. package/src/cli/commands/snapshot.ts +99 -11
  74. package/src/cli/commands/status.ts +5 -4
  75. package/src/cli/core/ai-model.ts +6 -3
  76. package/src/cli/core/browser.ts +369 -147
  77. package/src/cli/core/config.ts +3 -1
  78. package/src/cli/core/context.ts +4 -0
  79. package/src/cli/core/daemon/config.ts +35 -19
  80. package/src/cli/core/daemon/daemon.ts +686 -106
  81. package/src/cli/core/daemon/ipc.ts +330 -214
  82. package/src/cli/core/daemon/snapshot.ts +106 -8
  83. package/src/cli/core/experiments.ts +85 -0
  84. package/src/cli/core/session.ts +5 -4
  85. package/src/cli/core/skill-version.ts +2 -1
  86. package/src/cli/core/snapshot-analyzer.ts +4 -3
  87. package/src/cli/core/workflow-runner/runner.ts +237 -0
  88. package/src/cli/core/workflow-runtime.ts +85 -0
  89. package/src/cli/router.ts +4 -1
  90. package/src/shared/debug/pause-handler.ts +20 -0
  91. package/src/shared/debug/pause.ts +14 -48
  92. package/src/shared/ipc/AGENTS.md +24 -0
  93. package/src/shared/ipc/child-process-transport.spec.ts +86 -0
  94. package/src/shared/ipc/child-process-transport.ts +96 -0
  95. package/src/shared/ipc/ipc.spec.ts +161 -0
  96. package/src/shared/ipc/ipc.ts +288 -0
  97. package/src/shared/ipc/socket-transport.spec.ts +141 -0
  98. package/src/shared/ipc/socket-transport.ts +189 -0
  99. package/src/shared/package-manager.ts +76 -0
  100. package/src/shared/paths/paths.ts +0 -72
  101. package/src/shared/snapshot/capture-snapshot.ts +615 -0
  102. package/src/shared/snapshot/diff-snapshots.ts +579 -0
  103. package/src/shared/snapshot/render-snapshot.ts +962 -0
  104. package/src/shared/snapshot/snapshot.spec.ts +388 -0
  105. package/src/shared/snapshot/types.ts +43 -0
  106. package/src/shared/snapshot/wait-for-page-stable.ts +425 -0
  107. package/src/shared/state/session-state.ts +1 -0
  108. package/dist/cli/core/daemon/index.js +0 -16
  109. package/dist/cli/core/daemon/spawn.js +0 -90
  110. package/dist/cli/core/pause-signals.js +0 -29
  111. package/dist/cli/workers/run-integration-runtime.js +0 -235
  112. package/dist/cli/workers/run-integration-worker-protocol.js +0 -17
  113. package/dist/cli/workers/run-integration-worker.js +0 -64
  114. package/src/cli/core/daemon/index.ts +0 -24
  115. package/src/cli/core/daemon/spawn.ts +0 -171
  116. package/src/cli/core/pause-signals.ts +0 -35
  117. package/src/cli/workers/run-integration-runtime.ts +0 -326
  118. package/src/cli/workers/run-integration-worker-protocol.ts +0 -19
  119. package/src/cli/workers/run-integration-worker.ts +0 -72
@@ -0,0 +1,67 @@
1
+ # Experiments Framework
2
+
3
+ Use this reference when adding or changing Libretto experiment flags, wiring experiment checks through CLI or daemon internals, or debugging `libretto experiments` behavior.
4
+
5
+ ## Purpose and Scope
6
+
7
+ Experiments are boolean feature flags for Libretto internal machinery. They let maintainers enable in-progress CLI or daemon behavior in a workspace without exposing those flags to user workflow code.
8
+
9
+ Do not add experiments to `LibrettoWorkflowContext` in `packages/libretto/src/shared/workflow/workflow.ts`. User workflows should not branch on Libretto experiment flags.
10
+
11
+ ## Registry and Workspace State
12
+
13
+ The experiment registry lives in `packages/libretto/src/cli/core/experiments.ts`.
14
+
15
+ - Add each flag to `EXPERIMENTS` with a stable hyphenated slug, title, description, and `defaultValue`.
16
+ - Use the exported `ExperimentName` and `Experiments` types instead of duplicating flag shapes.
17
+ - Use `resolveExperiments()` to read the resolved boolean snapshot.
18
+ - Use `setExperimentEnabled()` to persist an override and reject unknown flag names.
19
+
20
+ Workspace overrides are stored in `.libretto/config.json` under the optional `experiments` record. The config schema is defined in `packages/libretto/src/cli/core/config.ts`; unknown config fields are still passed through.
21
+
22
+ Example workspace state:
23
+
24
+ ```json
25
+ {
26
+ "version": 1,
27
+ "experiments": {
28
+ "compact-snapshot-format": true
29
+ }
30
+ }
31
+ ```
32
+
33
+ ## CLI Behavior
34
+
35
+ `libretto experiments` is the CLI surface for inspecting and changing workspace experiment overrides.
36
+
37
+ ```bash
38
+ npx libretto experiments
39
+ npx libretto experiments describe <experiment>
40
+ npx libretto experiments enable <experiment>
41
+ npx libretto experiments disable <experiment>
42
+ ```
43
+
44
+ The command is implemented in `packages/libretto/src/cli/commands/experiments.ts` and registered as a top-level command. Listing prints registered experiments in registry order with their enabled/disabled state and description. `describe` prints the experiment status and full instructions. `enable` persists the override to `.libretto/config.json` and prints the full description with a prelude that the enabled experiment changes expected Libretto usage from the skill. `disable` persists the override and prints deterministic success text.
45
+
46
+ Invalid actions, missing experiment names, and unknown experiment names should fail with actionable usage that includes the available experiment names.
47
+
48
+ ## CLI and Daemon Plumbing
49
+
50
+ Use `withExperiments()` from `packages/libretto/src/cli/commands/shared.ts` when a command needs experiment values. It resolves one experiment snapshot for the CLI invocation and adds it to command context as `ctx.experiments`.
51
+
52
+ Daemon-backed startup paths must serialize that snapshot into `DaemonConfig.experiments` in `packages/libretto/src/cli/core/daemon/config.ts`. This currently applies to:
53
+
54
+ - daemon-backed `open`
55
+ - `connect`
56
+ - provider-backed `open`
57
+ - `run`
58
+
59
+ The daemon receives experiments at startup only. Changes made with `libretto experiments enable|disable` apply to new daemon sessions, not already-running sessions.
60
+
61
+ Inside the daemon, experiments are for Libretto machinery only. Keep them in daemon/controller internals; do not pass them into public workflow context objects.
62
+
63
+ ## Testing Notes
64
+
65
+ Before adding or changing tests, read `docs/tests-guide.md`.
66
+
67
+ Prefer user-level CLI behavior tests for `libretto experiments` listing and enable/disable flows. Keep a regression test that an enabled experiment is not visible on `LibrettoWorkflowContext` during `run`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libretto",
3
- "version": "0.6.10",
3
+ "version": "0.6.12",
4
4
  "description": "AI-powered browser automation library and CLI built on Playwright",
5
5
  "license": "MIT",
6
6
  "homepage": "https://libretto.sh",
@@ -38,7 +38,8 @@
38
38
  "check:skills": "pnpm run check:mirrors",
39
39
  "build": "tsup --config tsup.config.ts",
40
40
  "type-check": "tsc --noEmit",
41
- "test": "vitest run",
41
+ "test": "turbo run test:vitest --filter=libretto --log-order=grouped",
42
+ "test:vitest": "vitest run",
42
43
  "test:watch": "vitest",
43
44
  "cli": "node dist/index.js",
44
45
  "generate-changelog": "tsx scripts/generate-changelog.ts",
@@ -78,6 +79,7 @@
78
79
  "glimpseui": "^0.5.1",
79
80
  "google-auth-library": "^10.6.1",
80
81
  "openai": "^6.29.0",
82
+ "outdent": "^0.8.0",
81
83
  "tsup": "^8.5.1",
82
84
  "typescript": "^5.9.3",
83
85
  "vitest": "^4.1.5"
@@ -4,7 +4,7 @@ description: "Browser automation CLI for building, maintaining, and running brow
4
4
  license: MIT
5
5
  metadata:
6
6
  author: saffron-health
7
- version: "0.6.10"
7
+ version: "0.6.12"
8
8
  ---
9
9
 
10
10
  ## How Libretto Works
@@ -142,6 +142,7 @@ npx libretto exec --session debug-example --page <page-id> "return await page.ur
142
142
 
143
143
  - Use `run` to verify a workflow file after creating it or editing it, preferring `run --headless` for the normal fix/verify loop.
144
144
  - Plain `run` defaults to headed mode.
145
+ - Successful runs close the browser by default. Pass `--stay-open-on-success` when you need to inspect the completed state with `pages`, `snapshot`, or `exec`.
145
146
  - Pass `--read-only` if the preserved session should come back locked for follow-up terminal inspection after the workflow run.
146
147
  - If the workflow fails, Libretto keeps the browser open. Inspect the failed state with `snapshot` and `exec` before editing code.
147
148
  - Insert `await pause(session)` statements in the workflow file when you need to stop at specific states for interactive debugging, like breakpoints in the browser flow.
@@ -151,6 +152,7 @@ npx libretto exec --session debug-example --page <page-id> "return await page.ur
151
152
  ```bash
152
153
  npx libretto run ./integration.ts --headless --params '{"status":"open"}'
153
154
  npx libretto run ./integration.ts --headless --read-only
155
+ npx libretto run ./integration.ts --headless --stay-open-on-success
154
156
  npx libretto run ./integration.ts --auth-profile app.example.com
155
157
  ```
156
158
 
@@ -4,7 +4,7 @@ description: "Read-only Libretto workflow for diagnosing live browser state with
4
4
  license: MIT
5
5
  metadata:
6
6
  author: saffron-health
7
- version: "0.6.10"
7
+ version: "0.6.12"
8
8
  ---
9
9
 
10
10
  ## How Libretto Read-Only Works
@@ -0,0 +1,7 @@
1
+ # CLI Source
2
+
3
+ ## Experiments
4
+
5
+ When adding or changing Libretto experiment flags, read `../../docs/experiments.md` for the registry, CLI command, config, and daemon plumbing conventions.
6
+
7
+ Experiments are internal Libretto machinery. Do not expose them on `LibrettoWorkflowContext` or user workflow APIs.
package/src/cli/cli.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { resolveAiSetupStatus } from "./core/ai-model.js";
2
2
  import { ensureLibrettoSetup } from "./core/context.js";
3
+ import { librettoCommand } from "../shared/package-manager.js";
3
4
  import { createCLIApp } from "./router.js";
4
5
  import { warnIfInstalledSkillOutOfDate } from "./core/skill-version.js";
5
6
  import { loadEnv } from "../shared/env/load-env.js";
@@ -24,17 +25,17 @@ function printSetupAudit(): void {
24
25
  break;
25
26
  case "configured-missing-credentials":
26
27
  console.log(
27
- `✗ ${status.provider} configured (model: ${status.model}), but credentials are missing. Run \`npx libretto setup\` to repair.`,
28
+ `✗ ${status.provider} configured (model: ${status.model}), but credentials are missing. Run \`${librettoCommand("setup")}\` to repair.`,
28
29
  );
29
30
  break;
30
31
  case "invalid-config":
31
32
  console.log(
32
- `✗ AI config is invalid. Run \`npx libretto setup\` to reconfigure.`,
33
+ `✗ AI config is invalid. Run \`${librettoCommand("setup")}\` to reconfigure.`,
33
34
  );
34
35
  break;
35
36
  case "unconfigured":
36
37
  console.log(
37
- `✗ No AI model configured. Run \`npx libretto setup\` or \`npx libretto ai configure\` to set up.`,
38
+ `✗ No AI model configured. Run \`${librettoCommand("setup")}\` or \`${librettoCommand("ai configure")}\` to set up.`,
38
39
  );
39
40
  break;
40
41
  }
@@ -7,6 +7,7 @@ import {
7
7
  } from "../core/config.js";
8
8
  import { LIBRETTO_CONFIG_PATH } from "../core/context.js";
9
9
  import { DEFAULT_SNAPSHOT_MODELS } from "../core/ai-model.js";
10
+ import { librettoCommand } from "../../shared/package-manager.js";
10
11
  import { SimpleCLI } from "../framework/simple-cli.js";
11
12
 
12
13
  const PROVIDER_ALIASES: Record<string, string> = {
@@ -63,7 +64,7 @@ export function runAiConfigure(
63
64
  } = {},
64
65
  ): void {
65
66
  const configureCommandName =
66
- options.configureCommandName ?? "npx libretto ai configure";
67
+ options.configureCommandName ?? librettoCommand("ai configure");
67
68
  const configPath = options.configPath ?? LIBRETTO_CONFIG_PATH;
68
69
 
69
70
  const presetArg = input.preset?.trim();
@@ -135,7 +136,7 @@ export const aiCommands = SimpleCLI.group({
135
136
  preset: input.preset,
136
137
  },
137
138
  {
138
- configureCommandName: `libretto ai configure`,
139
+ configureCommandName: librettoCommand("ai configure"),
139
140
  },
140
141
  );
141
142
  }),
@@ -9,12 +9,10 @@ import {
9
9
  runPages,
10
10
  runSave,
11
11
  } from "../core/browser.js";
12
- import {
13
- resolveProviderName,
14
- getCloudProviderApi,
15
- } from "../core/providers/index.js";
12
+ import { resolveProviderName } from "../core/providers/index.js";
16
13
  import { readLibrettoConfig } from "../core/config.js";
17
14
  import { createLoggerForSession, withSessionLogger } from "../core/context.js";
15
+ import { librettoCommand } from "../../shared/package-manager.js";
18
16
  import {
19
17
  type SessionAccessMode,
20
18
  assertSessionAvailableForStart,
@@ -26,6 +24,7 @@ import { SimpleCLI } from "../framework/simple-cli.js";
26
24
  import {
27
25
  sessionOption,
28
26
  withAutoSession,
27
+ withExperiments,
29
28
  withRequiredSession,
30
29
  } from "./shared.js";
31
30
 
@@ -95,7 +94,7 @@ export const openInput = SimpleCLI.input({
95
94
  })
96
95
  .refine(
97
96
  (input) => Boolean(input.url),
98
- `Usage: libretto open <url> [--headless] [--read-only|--write-access] [--auth-profile <domain>] [--viewport WxH] [--session <name>]`,
97
+ `Usage: ${librettoCommand("open <url> [--headless] [--read-only|--write-access] [--auth-profile <domain>] [--viewport WxH] [--session <name>]")}`,
99
98
  )
100
99
  .refine(
101
100
  (input) => !(input.headed && input.headless),
@@ -112,6 +111,7 @@ export const openCommand = SimpleCLI.command({
112
111
  })
113
112
  .input(openInput)
114
113
  .use(withAutoSession())
114
+ .use(withExperiments())
115
115
  .handle(async ({ input, ctx }) => {
116
116
  warnIfInstalledSkillOutOfDate();
117
117
  assertSessionAvailableForStart(ctx.session, ctx.logger);
@@ -126,16 +126,16 @@ export const openCommand = SimpleCLI.command({
126
126
  input.writeAccess,
127
127
  ),
128
128
  authProfileDomain: input.authProfile,
129
+ experiments: ctx.experiments,
129
130
  });
130
131
  } else {
131
- const provider = getCloudProviderApi(providerName);
132
132
  await runOpenWithProvider(
133
133
  input.url!,
134
134
  providerName,
135
- provider,
136
135
  ctx.session,
137
136
  ctx.logger,
138
137
  resolveRequestedSessionMode(input.readOnly, input.writeAccess),
138
+ ctx.experiments,
139
139
  );
140
140
  }
141
141
  });
@@ -160,7 +160,7 @@ export const connectInput = SimpleCLI.input({
160
160
  })
161
161
  .refine(
162
162
  (input) => Boolean(input.cdpUrl),
163
- `Usage: libretto connect <cdp-url> [--read-only|--write-access] --session <name>`,
163
+ `Usage: ${librettoCommand("connect <cdp-url> [--read-only|--write-access] --session <name>")}`,
164
164
  )
165
165
  .refine(
166
166
  (input) => !(input.readOnly && input.writeAccess),
@@ -172,6 +172,7 @@ export const connectCommand = SimpleCLI.command({
172
172
  })
173
173
  .input(connectInput)
174
174
  .use(withAutoSession())
175
+ .use(withExperiments())
175
176
  .handle(async ({ input, ctx }) => {
176
177
  warnIfInstalledSkillOutOfDate();
177
178
  await runConnectWithLogger(
@@ -179,6 +180,7 @@ export const connectCommand = SimpleCLI.command({
179
180
  ctx.session,
180
181
  ctx.logger,
181
182
  resolveRequestedSessionMode(input.readOnly, input.writeAccess),
183
+ ctx.experiments,
182
184
  );
183
185
  });
184
186
 
@@ -193,7 +195,7 @@ export const saveInput = SimpleCLI.input({
193
195
  },
194
196
  }).refine(
195
197
  (input) => Boolean(input.urlOrDomain),
196
- `Usage: libretto save <url|domain> --session <name>`,
198
+ `Usage: ${librettoCommand("save <url|domain> --session <name>")}`,
197
199
  );
198
200
 
199
201
  export const saveCommand = SimpleCLI.command({
@@ -264,7 +266,7 @@ export const closeInput = SimpleCLI.input({
264
266
  },
265
267
  }).refine(
266
268
  (input) => input.all || input.session,
267
- `Usage: libretto close <session>\nUsage: libretto close --all [--force]`,
269
+ `Usage: ${librettoCommand("close <session>")}\nUsage: ${librettoCommand("close --all [--force]")}`,
268
270
  );
269
271
 
270
272
  export const closeCommand = SimpleCLI.command({
@@ -273,7 +275,7 @@ export const closeCommand = SimpleCLI.command({
273
275
  .input(closeInput)
274
276
  .handle(async ({ input }) => {
275
277
  if (input.force && !input.all) {
276
- throw new Error(`Usage: libretto close --all [--force]`);
278
+ throw new Error(`Usage: ${librettoCommand("close --all [--force]")}`);
277
279
  }
278
280
  if (input.all) {
279
281
  const logger = createLoggerForSession("cli");