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,160 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var sinks_exports = {};
30
- __export(sinks_exports, {
31
- createFileLogSink: () => createFileLogSink,
32
- jsonlConsoleSink: () => jsonlConsoleSink,
33
- prettyConsoleSink: () => prettyConsoleSink
34
- });
35
- module.exports = __toCommonJS(sinks_exports);
36
- var fs = __toESM(require("node:fs"), 1);
37
- var path = __toESM(require("node:path"), 1);
38
- function createFileLogSink({
39
- filePath
40
- }) {
41
- fs.mkdirSync(path.dirname(filePath), { recursive: true });
42
- const writeStream = fs.createWriteStream(filePath, { flags: "a" });
43
- return {
44
- write: ({ id, scope, level, event, data, options }) => {
45
- if (writeStream.destroyed || writeStream.writableEnded) {
46
- return;
47
- }
48
- const timestamp = options?.timestamp || /* @__PURE__ */ new Date();
49
- const logEntry = {
50
- timestamp: timestamp.toISOString(),
51
- id,
52
- level,
53
- scope,
54
- event,
55
- data
56
- };
57
- const jsonLine = JSON.stringify(logEntry) + "\n";
58
- try {
59
- writeStream.write(jsonLine, (error) => {
60
- if (error) {
61
- console.error("Failed to write to log file:", error);
62
- console[level]({ id, scope, event, data, timestamp });
63
- }
64
- });
65
- } catch (error) {
66
- console.error("Failed to write to log file:", error);
67
- console[level]({ id, scope, event, data, timestamp });
68
- }
69
- },
70
- flush: () => new Promise((resolve, reject) => {
71
- if (!writeStream.writable || writeStream.writableEnded || writeStream.destroyed) {
72
- resolve();
73
- return;
74
- }
75
- writeStream.write("", (error) => {
76
- if (error) {
77
- reject(error);
78
- } else {
79
- resolve();
80
- }
81
- });
82
- }),
83
- close: () => new Promise((resolve) => {
84
- if (writeStream.destroyed || writeStream.closed) {
85
- resolve();
86
- return;
87
- }
88
- let settled = false;
89
- const done = () => {
90
- if (settled) return;
91
- settled = true;
92
- resolve();
93
- };
94
- writeStream.once("finish", done);
95
- writeStream.once("close", done);
96
- writeStream.once("error", done);
97
- try {
98
- writeStream.end();
99
- } catch {
100
- done();
101
- }
102
- })
103
- };
104
- }
105
- const colors = {
106
- reset: "\x1B[0m",
107
- gray: "\x1B[90m",
108
- red: "\x1B[31m",
109
- yellow: "\x1B[33m",
110
- blue: "\x1B[34m",
111
- cyan: "\x1B[36m"
112
- };
113
- function formatTimestamp(date) {
114
- return date.toISOString().replace("T", " ").replace("Z", "");
115
- }
116
- const prettyConsoleSink = {
117
- write: ({ scope, level, event, data, options }) => {
118
- const timestamp = `${colors.gray}${formatTimestamp(options?.timestamp || /* @__PURE__ */ new Date())}${colors.reset}`;
119
- const levelColor = level === "error" ? colors.red : level === "warn" ? colors.yellow : colors.blue;
120
- const coloredScope = scope ? `${colors.cyan}[${scope}]${colors.reset}` : "";
121
- const logPrefix = `${timestamp} ${levelColor}${level.toUpperCase()}${colors.reset} ${coloredScope} ${event}`;
122
- if (level === "error" && data.error) {
123
- const { error, ...otherData } = data;
124
- console.error(logPrefix);
125
- if (error.stack) {
126
- console.error(` ${error.stack}`);
127
- } else if (error.type && error.message) {
128
- console.error(` ${error.type}: ${error.message}`);
129
- }
130
- if (Object.keys(otherData).length > 0) {
131
- console.error(JSON.stringify(otherData, null, 2));
132
- }
133
- } else {
134
- console[level](logPrefix);
135
- if (Object.keys(data).length > 0) {
136
- console[level](JSON.stringify(data, null, 2));
137
- }
138
- }
139
- }
140
- };
141
- const jsonlConsoleSink = {
142
- write: ({ id, scope, level, event, data, options }) => {
143
- const timestamp = options?.timestamp || /* @__PURE__ */ new Date();
144
- const logEntry = {
145
- timestamp: timestamp.toISOString(),
146
- id,
147
- level,
148
- scope: scope || void 0,
149
- event,
150
- data
151
- };
152
- console.log(JSON.stringify(logEntry));
153
- }
154
- };
155
- // Annotate the CommonJS export names for ESM import in node:
156
- 0 && (module.exports = {
157
- createFileLogSink,
158
- jsonlConsoleSink,
159
- prettyConsoleSink
160
- });
@@ -1,9 +0,0 @@
1
- import { LoggerSink } from './logger.cjs';
2
-
3
- declare function createFileLogSink({ filePath, }: {
4
- filePath: string;
5
- }): LoggerSink;
6
- declare const prettyConsoleSink: LoggerSink;
7
- declare const jsonlConsoleSink: LoggerSink;
8
-
9
- export { createFileLogSink, jsonlConsoleSink, prettyConsoleSink };
@@ -1,9 +0,0 @@
1
- import { LoggerSink } from './logger.js';
2
-
3
- declare function createFileLogSink({ filePath, }: {
4
- filePath: string;
5
- }): LoggerSink;
6
- declare const prettyConsoleSink: LoggerSink;
7
- declare const jsonlConsoleSink: LoggerSink;
8
-
9
- export { createFileLogSink, jsonlConsoleSink, prettyConsoleSink };
@@ -1,124 +0,0 @@
1
- import * as fs from "node:fs";
2
- import * as path from "node:path";
3
- function createFileLogSink({
4
- filePath
5
- }) {
6
- fs.mkdirSync(path.dirname(filePath), { recursive: true });
7
- const writeStream = fs.createWriteStream(filePath, { flags: "a" });
8
- return {
9
- write: ({ id, scope, level, event, data, options }) => {
10
- if (writeStream.destroyed || writeStream.writableEnded) {
11
- return;
12
- }
13
- const timestamp = options?.timestamp || /* @__PURE__ */ new Date();
14
- const logEntry = {
15
- timestamp: timestamp.toISOString(),
16
- id,
17
- level,
18
- scope,
19
- event,
20
- data
21
- };
22
- const jsonLine = JSON.stringify(logEntry) + "\n";
23
- try {
24
- writeStream.write(jsonLine, (error) => {
25
- if (error) {
26
- console.error("Failed to write to log file:", error);
27
- console[level]({ id, scope, event, data, timestamp });
28
- }
29
- });
30
- } catch (error) {
31
- console.error("Failed to write to log file:", error);
32
- console[level]({ id, scope, event, data, timestamp });
33
- }
34
- },
35
- flush: () => new Promise((resolve, reject) => {
36
- if (!writeStream.writable || writeStream.writableEnded || writeStream.destroyed) {
37
- resolve();
38
- return;
39
- }
40
- writeStream.write("", (error) => {
41
- if (error) {
42
- reject(error);
43
- } else {
44
- resolve();
45
- }
46
- });
47
- }),
48
- close: () => new Promise((resolve) => {
49
- if (writeStream.destroyed || writeStream.closed) {
50
- resolve();
51
- return;
52
- }
53
- let settled = false;
54
- const done = () => {
55
- if (settled) return;
56
- settled = true;
57
- resolve();
58
- };
59
- writeStream.once("finish", done);
60
- writeStream.once("close", done);
61
- writeStream.once("error", done);
62
- try {
63
- writeStream.end();
64
- } catch {
65
- done();
66
- }
67
- })
68
- };
69
- }
70
- const colors = {
71
- reset: "\x1B[0m",
72
- gray: "\x1B[90m",
73
- red: "\x1B[31m",
74
- yellow: "\x1B[33m",
75
- blue: "\x1B[34m",
76
- cyan: "\x1B[36m"
77
- };
78
- function formatTimestamp(date) {
79
- return date.toISOString().replace("T", " ").replace("Z", "");
80
- }
81
- const prettyConsoleSink = {
82
- write: ({ scope, level, event, data, options }) => {
83
- const timestamp = `${colors.gray}${formatTimestamp(options?.timestamp || /* @__PURE__ */ new Date())}${colors.reset}`;
84
- const levelColor = level === "error" ? colors.red : level === "warn" ? colors.yellow : colors.blue;
85
- const coloredScope = scope ? `${colors.cyan}[${scope}]${colors.reset}` : "";
86
- const logPrefix = `${timestamp} ${levelColor}${level.toUpperCase()}${colors.reset} ${coloredScope} ${event}`;
87
- if (level === "error" && data.error) {
88
- const { error, ...otherData } = data;
89
- console.error(logPrefix);
90
- if (error.stack) {
91
- console.error(` ${error.stack}`);
92
- } else if (error.type && error.message) {
93
- console.error(` ${error.type}: ${error.message}`);
94
- }
95
- if (Object.keys(otherData).length > 0) {
96
- console.error(JSON.stringify(otherData, null, 2));
97
- }
98
- } else {
99
- console[level](logPrefix);
100
- if (Object.keys(data).length > 0) {
101
- console[level](JSON.stringify(data, null, 2));
102
- }
103
- }
104
- }
105
- };
106
- const jsonlConsoleSink = {
107
- write: ({ id, scope, level, event, data, options }) => {
108
- const timestamp = options?.timestamp || /* @__PURE__ */ new Date();
109
- const logEntry = {
110
- timestamp: timestamp.toISOString(),
111
- id,
112
- level,
113
- scope: scope || void 0,
114
- event,
115
- data
116
- };
117
- console.log(JSON.stringify(logEntry));
118
- }
119
- };
120
- export {
121
- createFileLogSink,
122
- jsonlConsoleSink,
123
- prettyConsoleSink
124
- };
@@ -1,104 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var paths_exports = {};
20
- __export(paths_exports, {
21
- ensureLibrettoPauseSignalDir: () => ensureLibrettoPauseSignalDir,
22
- ensureLibrettoRunnerLogDir: () => ensureLibrettoRunnerLogDir,
23
- ensureLibrettoSessionStatePath: () => ensureLibrettoSessionStatePath,
24
- getLibrettoPauseSignalDir: () => getLibrettoPauseSignalDir,
25
- getLibrettoPausedSignalPath: () => getLibrettoPausedSignalPath,
26
- getLibrettoResumeSignalPath: () => getLibrettoResumeSignalPath,
27
- getPauseSignalPathForDir: () => getPauseSignalPathForDir,
28
- getRunnerLogPathForDir: () => getRunnerLogPathForDir
29
- });
30
- module.exports = __toCommonJS(paths_exports);
31
- var import_node_fs = require("node:fs");
32
- var import_node_path = require("node:path");
33
- const LIBRETTO_DIRNAME = ".libretto";
34
- const LIBRETTO_SESSIONS_DIRNAME = "sessions";
35
- const SESSION_STATE_FILENAME = "state.json";
36
- const RUNNER_LOG_DIRNAME = "logs";
37
- const RUNNER_LOG_FILENAME = "logs.jsonl";
38
- const PAUSED_SIGNAL_SUFFIX = "paused";
39
- const RESUME_SIGNAL_SUFFIX = "resume";
40
- function getLibrettoRoot(cwd = process.cwd()) {
41
- return (0, import_node_path.join)(cwd, LIBRETTO_DIRNAME);
42
- }
43
- function getLibrettoSessionsDir(cwd = process.cwd()) {
44
- return (0, import_node_path.join)(getLibrettoRoot(cwd), LIBRETTO_SESSIONS_DIRNAME);
45
- }
46
- function getLibrettoSessionDir(sessionName, cwd = process.cwd()) {
47
- return (0, import_node_path.join)(getLibrettoSessionsDir(cwd), sessionName);
48
- }
49
- function getLibrettoSessionStatePath(sessionName, cwd = process.cwd()) {
50
- return (0, import_node_path.join)(getLibrettoSessionDir(sessionName, cwd), SESSION_STATE_FILENAME);
51
- }
52
- function getLibrettoPauseSignalDir(sessionName, cwd = process.cwd()) {
53
- return getLibrettoSessionDir(sessionName, cwd);
54
- }
55
- function getLibrettoRunnerLogDir(sessionName, cwd = process.cwd()) {
56
- return (0, import_node_path.join)(getLibrettoSessionDir(sessionName, cwd), RUNNER_LOG_DIRNAME);
57
- }
58
- function getRunnerLogPathForDir(logDir) {
59
- return (0, import_node_path.join)(logDir, RUNNER_LOG_FILENAME);
60
- }
61
- function getPauseSignalPathForDir(signalDir, sessionName, signal) {
62
- const suffix = signal === "paused" ? PAUSED_SIGNAL_SUFFIX : RESUME_SIGNAL_SUFFIX;
63
- return (0, import_node_path.join)(signalDir, `${sessionName}.${suffix}`);
64
- }
65
- function getLibrettoPausedSignalPath(sessionName, cwd = process.cwd()) {
66
- return getPauseSignalPathForDir(
67
- getLibrettoPauseSignalDir(sessionName, cwd),
68
- sessionName,
69
- "paused"
70
- );
71
- }
72
- function getLibrettoResumeSignalPath(sessionName, cwd = process.cwd()) {
73
- return getPauseSignalPathForDir(
74
- getLibrettoPauseSignalDir(sessionName, cwd),
75
- sessionName,
76
- "resume"
77
- );
78
- }
79
- function ensureLibrettoSessionStatePath(sessionName, cwd = process.cwd()) {
80
- const filePath = getLibrettoSessionStatePath(sessionName, cwd);
81
- (0, import_node_fs.mkdirSync)((0, import_node_path.dirname)(filePath), { recursive: true });
82
- return filePath;
83
- }
84
- function ensureLibrettoPauseSignalDir(sessionName, cwd = process.cwd()) {
85
- const dir = getLibrettoPauseSignalDir(sessionName, cwd);
86
- (0, import_node_fs.mkdirSync)(dir, { recursive: true });
87
- return dir;
88
- }
89
- function ensureLibrettoRunnerLogDir(sessionName, cwd = process.cwd()) {
90
- const dir = getLibrettoRunnerLogDir(sessionName, cwd);
91
- (0, import_node_fs.mkdirSync)(dir, { recursive: true });
92
- return dir;
93
- }
94
- // Annotate the CommonJS export names for ESM import in node:
95
- 0 && (module.exports = {
96
- ensureLibrettoPauseSignalDir,
97
- ensureLibrettoRunnerLogDir,
98
- ensureLibrettoSessionStatePath,
99
- getLibrettoPauseSignalDir,
100
- getLibrettoPausedSignalPath,
101
- getLibrettoResumeSignalPath,
102
- getPauseSignalPathForDir,
103
- getRunnerLogPathForDir
104
- });
@@ -1,10 +0,0 @@
1
- declare function getLibrettoPauseSignalDir(sessionName: string, cwd?: string): string;
2
- declare function getRunnerLogPathForDir(logDir: string): string;
3
- declare function getPauseSignalPathForDir(signalDir: string, sessionName: string, signal: "paused" | "resume"): string;
4
- declare function getLibrettoPausedSignalPath(sessionName: string, cwd?: string): string;
5
- declare function getLibrettoResumeSignalPath(sessionName: string, cwd?: string): string;
6
- declare function ensureLibrettoSessionStatePath(sessionName: string, cwd?: string): string;
7
- declare function ensureLibrettoPauseSignalDir(sessionName: string, cwd?: string): string;
8
- declare function ensureLibrettoRunnerLogDir(sessionName: string, cwd?: string): string;
9
-
10
- export { ensureLibrettoPauseSignalDir, ensureLibrettoRunnerLogDir, ensureLibrettoSessionStatePath, getLibrettoPauseSignalDir, getLibrettoPausedSignalPath, getLibrettoResumeSignalPath, getPauseSignalPathForDir, getRunnerLogPathForDir };
@@ -1,10 +0,0 @@
1
- declare function getLibrettoPauseSignalDir(sessionName: string, cwd?: string): string;
2
- declare function getRunnerLogPathForDir(logDir: string): string;
3
- declare function getPauseSignalPathForDir(signalDir: string, sessionName: string, signal: "paused" | "resume"): string;
4
- declare function getLibrettoPausedSignalPath(sessionName: string, cwd?: string): string;
5
- declare function getLibrettoResumeSignalPath(sessionName: string, cwd?: string): string;
6
- declare function ensureLibrettoSessionStatePath(sessionName: string, cwd?: string): string;
7
- declare function ensureLibrettoPauseSignalDir(sessionName: string, cwd?: string): string;
8
- declare function ensureLibrettoRunnerLogDir(sessionName: string, cwd?: string): string;
9
-
10
- export { ensureLibrettoPauseSignalDir, ensureLibrettoRunnerLogDir, ensureLibrettoSessionStatePath, getLibrettoPauseSignalDir, getLibrettoPausedSignalPath, getLibrettoResumeSignalPath, getPauseSignalPathForDir, getRunnerLogPathForDir };
@@ -1,73 +0,0 @@
1
- import { mkdirSync } from "node:fs";
2
- import { dirname, join } from "node:path";
3
- const LIBRETTO_DIRNAME = ".libretto";
4
- const LIBRETTO_SESSIONS_DIRNAME = "sessions";
5
- const SESSION_STATE_FILENAME = "state.json";
6
- const RUNNER_LOG_DIRNAME = "logs";
7
- const RUNNER_LOG_FILENAME = "logs.jsonl";
8
- const PAUSED_SIGNAL_SUFFIX = "paused";
9
- const RESUME_SIGNAL_SUFFIX = "resume";
10
- function getLibrettoRoot(cwd = process.cwd()) {
11
- return join(cwd, LIBRETTO_DIRNAME);
12
- }
13
- function getLibrettoSessionsDir(cwd = process.cwd()) {
14
- return join(getLibrettoRoot(cwd), LIBRETTO_SESSIONS_DIRNAME);
15
- }
16
- function getLibrettoSessionDir(sessionName, cwd = process.cwd()) {
17
- return join(getLibrettoSessionsDir(cwd), sessionName);
18
- }
19
- function getLibrettoSessionStatePath(sessionName, cwd = process.cwd()) {
20
- return join(getLibrettoSessionDir(sessionName, cwd), SESSION_STATE_FILENAME);
21
- }
22
- function getLibrettoPauseSignalDir(sessionName, cwd = process.cwd()) {
23
- return getLibrettoSessionDir(sessionName, cwd);
24
- }
25
- function getLibrettoRunnerLogDir(sessionName, cwd = process.cwd()) {
26
- return join(getLibrettoSessionDir(sessionName, cwd), RUNNER_LOG_DIRNAME);
27
- }
28
- function getRunnerLogPathForDir(logDir) {
29
- return join(logDir, RUNNER_LOG_FILENAME);
30
- }
31
- function getPauseSignalPathForDir(signalDir, sessionName, signal) {
32
- const suffix = signal === "paused" ? PAUSED_SIGNAL_SUFFIX : RESUME_SIGNAL_SUFFIX;
33
- return join(signalDir, `${sessionName}.${suffix}`);
34
- }
35
- function getLibrettoPausedSignalPath(sessionName, cwd = process.cwd()) {
36
- return getPauseSignalPathForDir(
37
- getLibrettoPauseSignalDir(sessionName, cwd),
38
- sessionName,
39
- "paused"
40
- );
41
- }
42
- function getLibrettoResumeSignalPath(sessionName, cwd = process.cwd()) {
43
- return getPauseSignalPathForDir(
44
- getLibrettoPauseSignalDir(sessionName, cwd),
45
- sessionName,
46
- "resume"
47
- );
48
- }
49
- function ensureLibrettoSessionStatePath(sessionName, cwd = process.cwd()) {
50
- const filePath = getLibrettoSessionStatePath(sessionName, cwd);
51
- mkdirSync(dirname(filePath), { recursive: true });
52
- return filePath;
53
- }
54
- function ensureLibrettoPauseSignalDir(sessionName, cwd = process.cwd()) {
55
- const dir = getLibrettoPauseSignalDir(sessionName, cwd);
56
- mkdirSync(dir, { recursive: true });
57
- return dir;
58
- }
59
- function ensureLibrettoRunnerLogDir(sessionName, cwd = process.cwd()) {
60
- const dir = getLibrettoRunnerLogDir(sessionName, cwd);
61
- mkdirSync(dir, { recursive: true });
62
- return dir;
63
- }
64
- export {
65
- ensureLibrettoPauseSignalDir,
66
- ensureLibrettoRunnerLogDir,
67
- ensureLibrettoSessionStatePath,
68
- getLibrettoPauseSignalDir,
69
- getLibrettoPausedSignalPath,
70
- getLibrettoResumeSignalPath,
71
- getPauseSignalPathForDir,
72
- getRunnerLogPathForDir
73
- };
@@ -1,28 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var api_exports = {};
20
- __export(api_exports, {
21
- launchBrowser: () => import_browser.launchBrowser
22
- });
23
- module.exports = __toCommonJS(api_exports);
24
- var import_browser = require("./browser.js");
25
- // Annotate the CommonJS export names for ESM import in node:
26
- 0 && (module.exports = {
27
- launchBrowser
28
- });
@@ -1,2 +0,0 @@
1
- export { BrowserSession, LaunchBrowserArgs, launchBrowser } from './browser.cjs';
2
- import 'playwright';
@@ -1,2 +0,0 @@
1
- export { BrowserSession, LaunchBrowserArgs, launchBrowser } from './browser.js';
2
- import 'playwright';
@@ -1,4 +0,0 @@
1
- import { launchBrowser } from "./browser.js";
2
- export {
3
- launchBrowser
4
- };
@@ -1,98 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var browser_exports = {};
20
- __export(browser_exports, {
21
- launchBrowser: () => launchBrowser
22
- });
23
- module.exports = __toCommonJS(browser_exports);
24
- var import_playwright = require("playwright");
25
- var import_node_net = require("node:net");
26
- var import_node_fs = require("node:fs");
27
- var import_paths = require("../paths/paths.js");
28
- var import_session_state = require("../state/session-state.js");
29
- async function pickFreePort() {
30
- return await new Promise((resolve, reject) => {
31
- const server = (0, import_node_net.createServer)();
32
- server.unref();
33
- server.on("error", reject);
34
- server.listen(0, "127.0.0.1", () => {
35
- const addr = server.address();
36
- if (addr && typeof addr === "object") {
37
- server.close(() => resolve(addr.port));
38
- return;
39
- }
40
- server.close(() => reject(new Error("Failed to resolve debug port")));
41
- });
42
- });
43
- }
44
- async function launchBrowser({
45
- sessionName,
46
- headless = false,
47
- viewport = { width: 1366, height: 768 },
48
- storageStatePath
49
- }) {
50
- const debugPort = await pickFreePort();
51
- const browser = await import_playwright.chromium.launch({
52
- headless,
53
- args: [
54
- "--disable-blink-features=AutomationControlled",
55
- `--remote-debugging-port=${debugPort}`,
56
- "--no-focus-on-check"
57
- ]
58
- });
59
- const context = await browser.newContext({
60
- viewport,
61
- ...storageStatePath ? { storageState: storageStatePath } : {}
62
- });
63
- const page = await context.newPage();
64
- page.setDefaultTimeout(3e4);
65
- page.setDefaultNavigationTimeout(45e3);
66
- const metadataPath = (0, import_paths.ensureLibrettoSessionStatePath)(sessionName);
67
- const existingStateRaw = (0, import_node_fs.existsSync)(metadataPath) ? JSON.parse((0, import_node_fs.readFileSync)(metadataPath, "utf-8")) : void 0;
68
- const parsedExistingState = import_session_state.SessionStateFileSchema.safeParse(existingStateRaw);
69
- (0, import_node_fs.writeFileSync)(
70
- metadataPath,
71
- JSON.stringify(
72
- {
73
- version: parsedExistingState.success ? parsedExistingState.data.version : import_session_state.SESSION_STATE_VERSION,
74
- session: sessionName,
75
- port: debugPort,
76
- pid: process.pid,
77
- startedAt: (/* @__PURE__ */ new Date()).toISOString(),
78
- status: "active"
79
- },
80
- null,
81
- 2
82
- )
83
- );
84
- return {
85
- browser,
86
- context,
87
- page,
88
- debugPort,
89
- metadataPath,
90
- close: async () => {
91
- await browser.close();
92
- }
93
- };
94
- }
95
- // Annotate the CommonJS export names for ESM import in node:
96
- 0 && (module.exports = {
97
- launchBrowser
98
- });
@@ -1,22 +0,0 @@
1
- import { Browser, BrowserContext, Page } from 'playwright';
2
-
3
- type LaunchBrowserArgs = {
4
- sessionName: string;
5
- headless?: boolean;
6
- viewport?: {
7
- width: number;
8
- height: number;
9
- };
10
- storageStatePath?: string;
11
- };
12
- type BrowserSession = {
13
- browser: Browser;
14
- context: BrowserContext;
15
- page: Page;
16
- debugPort: number;
17
- metadataPath: string;
18
- close: () => Promise<void>;
19
- };
20
- declare function launchBrowser({ sessionName, headless, viewport, storageStatePath, }: LaunchBrowserArgs): Promise<BrowserSession>;
21
-
22
- export { type BrowserSession, type LaunchBrowserArgs, launchBrowser };