@unigent/cli 0.1.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.
Files changed (110) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +470 -0
  3. package/dist/cli.js +132 -0
  4. package/dist/cli.js.map +1 -0
  5. package/dist/command.js +44 -0
  6. package/dist/command.js.map +1 -0
  7. package/dist/environment.js +20 -0
  8. package/dist/environment.js.map +1 -0
  9. package/dist/error_message.js +59 -0
  10. package/dist/error_message.js.map +1 -0
  11. package/dist/format.js +38 -0
  12. package/dist/format.js.map +1 -0
  13. package/dist/node_version.js +9 -0
  14. package/dist/node_version.js.map +1 -0
  15. package/dist/protocol.js +72 -0
  16. package/dist/protocol.js.map +1 -0
  17. package/dist/register.js +78 -0
  18. package/dist/register.js.map +1 -0
  19. package/dist/script_runtime.js +29 -0
  20. package/dist/script_runtime.js.map +1 -0
  21. package/dist/tui/app.js +453 -0
  22. package/dist/tui/app.js.map +1 -0
  23. package/dist/tui/clipboard.js +31 -0
  24. package/dist/tui/clipboard.js.map +1 -0
  25. package/dist/tui/runner.js +116 -0
  26. package/dist/tui/runner.js.map +1 -0
  27. package/dist/tui/scroll.js +33 -0
  28. package/dist/tui/scroll.js.map +1 -0
  29. package/dist/tui/store.js +99 -0
  30. package/dist/tui/store.js.map +1 -0
  31. package/dist/tui/theme.js +35 -0
  32. package/dist/tui/theme.js.map +1 -0
  33. package/dist/tui/tree.js +267 -0
  34. package/dist/tui/tree.js.map +1 -0
  35. package/dist/tui.js +63 -0
  36. package/dist/tui.js.map +1 -0
  37. package/node_modules/@unigent/core/dist/adapter_process.d.ts +25 -0
  38. package/node_modules/@unigent/core/dist/adapter_process.d.ts.map +1 -0
  39. package/node_modules/@unigent/core/dist/adapter_process.js +46 -0
  40. package/node_modules/@unigent/core/dist/adapter_process.js.map +1 -0
  41. package/node_modules/@unigent/core/dist/args.d.ts +17 -0
  42. package/node_modules/@unigent/core/dist/args.d.ts.map +1 -0
  43. package/node_modules/@unigent/core/dist/args.js +233 -0
  44. package/node_modules/@unigent/core/dist/args.js.map +1 -0
  45. package/node_modules/@unigent/core/dist/backend.d.ts +83 -0
  46. package/node_modules/@unigent/core/dist/backend.d.ts.map +1 -0
  47. package/node_modules/@unigent/core/dist/backend.js +2 -0
  48. package/node_modules/@unigent/core/dist/backend.js.map +1 -0
  49. package/node_modules/@unigent/core/dist/checkpoint.d.ts +26 -0
  50. package/node_modules/@unigent/core/dist/checkpoint.d.ts.map +1 -0
  51. package/node_modules/@unigent/core/dist/checkpoint.js +107 -0
  52. package/node_modules/@unigent/core/dist/checkpoint.js.map +1 -0
  53. package/node_modules/@unigent/core/dist/checkpoint_fingerprint.d.ts +4 -0
  54. package/node_modules/@unigent/core/dist/checkpoint_fingerprint.d.ts.map +1 -0
  55. package/node_modules/@unigent/core/dist/checkpoint_fingerprint.js +41 -0
  56. package/node_modules/@unigent/core/dist/checkpoint_fingerprint.js.map +1 -0
  57. package/node_modules/@unigent/core/dist/completion.d.ts +9 -0
  58. package/node_modules/@unigent/core/dist/completion.d.ts.map +1 -0
  59. package/node_modules/@unigent/core/dist/completion.js +4 -0
  60. package/node_modules/@unigent/core/dist/completion.js.map +1 -0
  61. package/node_modules/@unigent/core/dist/errors.d.ts +43 -0
  62. package/node_modules/@unigent/core/dist/errors.d.ts.map +1 -0
  63. package/node_modules/@unigent/core/dist/errors.js +48 -0
  64. package/node_modules/@unigent/core/dist/errors.js.map +1 -0
  65. package/node_modules/@unigent/core/dist/events.d.ts +101 -0
  66. package/node_modules/@unigent/core/dist/events.d.ts.map +1 -0
  67. package/node_modules/@unigent/core/dist/events.js +105 -0
  68. package/node_modules/@unigent/core/dist/events.js.map +1 -0
  69. package/node_modules/@unigent/core/dist/index.d.ts +19 -0
  70. package/node_modules/@unigent/core/dist/index.d.ts.map +1 -0
  71. package/node_modules/@unigent/core/dist/index.js +10 -0
  72. package/node_modules/@unigent/core/dist/index.js.map +1 -0
  73. package/node_modules/@unigent/core/dist/json_schema_validator.d.ts +8 -0
  74. package/node_modules/@unigent/core/dist/json_schema_validator.d.ts.map +1 -0
  75. package/node_modules/@unigent/core/dist/json_schema_validator.js +27 -0
  76. package/node_modules/@unigent/core/dist/json_schema_validator.js.map +1 -0
  77. package/node_modules/@unigent/core/dist/mcp.d.ts +12 -0
  78. package/node_modules/@unigent/core/dist/mcp.d.ts.map +1 -0
  79. package/node_modules/@unigent/core/dist/mcp.js +117 -0
  80. package/node_modules/@unigent/core/dist/mcp.js.map +1 -0
  81. package/node_modules/@unigent/core/dist/runtime.d.ts +109 -0
  82. package/node_modules/@unigent/core/dist/runtime.d.ts.map +1 -0
  83. package/node_modules/@unigent/core/dist/runtime.js +976 -0
  84. package/node_modules/@unigent/core/dist/runtime.js.map +1 -0
  85. package/node_modules/@unigent/core/dist/schema.d.ts +15 -0
  86. package/node_modules/@unigent/core/dist/schema.d.ts.map +1 -0
  87. package/node_modules/@unigent/core/dist/schema.js +71 -0
  88. package/node_modules/@unigent/core/dist/schema.js.map +1 -0
  89. package/node_modules/@unigent/core/dist/source_tools.d.ts +7 -0
  90. package/node_modules/@unigent/core/dist/source_tools.d.ts.map +1 -0
  91. package/node_modules/@unigent/core/dist/source_tools.js +450 -0
  92. package/node_modules/@unigent/core/dist/source_tools.js.map +1 -0
  93. package/node_modules/@unigent/core/dist/tool.d.ts +41 -0
  94. package/node_modules/@unigent/core/dist/tool.d.ts.map +1 -0
  95. package/node_modules/@unigent/core/dist/tool.js +43 -0
  96. package/node_modules/@unigent/core/dist/tool.js.map +1 -0
  97. package/node_modules/@unigent/core/dist/tools.d.ts +7 -0
  98. package/node_modules/@unigent/core/dist/tools.d.ts.map +1 -0
  99. package/node_modules/@unigent/core/dist/tools.js +3 -0
  100. package/node_modules/@unigent/core/dist/tools.js.map +1 -0
  101. package/node_modules/@unigent/core/dist/trace.d.ts +82 -0
  102. package/node_modules/@unigent/core/dist/trace.d.ts.map +1 -0
  103. package/node_modules/@unigent/core/dist/trace.js +235 -0
  104. package/node_modules/@unigent/core/dist/trace.js.map +1 -0
  105. package/node_modules/@unigent/core/dist/usage.d.ts +26 -0
  106. package/node_modules/@unigent/core/dist/usage.d.ts.map +1 -0
  107. package/node_modules/@unigent/core/dist/usage.js +47 -0
  108. package/node_modules/@unigent/core/dist/usage.js.map +1 -0
  109. package/node_modules/@unigent/core/package.json +68 -0
  110. package/package.json +68 -0
package/dist/tui.js ADDED
@@ -0,0 +1,63 @@
1
+ import { jsx as _jsx } from "@opentui/react/jsx-runtime";
2
+ import { isAbsolute, resolve } from "node:path";
3
+ import process from "node:process";
4
+ import { parseArgs } from "node:util";
5
+ import { createCliRenderer } from "@opentui/core";
6
+ import { createRoot } from "@opentui/react";
7
+ import { detectScriptRuntime, runtimeInvocation } from "./script_runtime.js";
8
+ import { App } from "./tui/app.js";
9
+ import { createScriptRunner } from "./tui/runner.js";
10
+ import { createTuiStore } from "./tui/store.js";
11
+ import { paletteFor } from "./tui/theme.js";
12
+ const THEME_QUERY_TIMEOUT_MILLISECONDS = 300;
13
+ const TUI_ARGUMENTS = {
14
+ allowPositionals: true,
15
+ options: {
16
+ node: { type: "string" },
17
+ register: { type: "string" },
18
+ developmentLoader: { type: "string" },
19
+ theme: { type: "string" },
20
+ },
21
+ };
22
+ async function detectTheme(override, renderer) {
23
+ if (override === "light" || override === "dark") {
24
+ return override;
25
+ }
26
+ const detected = await Promise.race([
27
+ renderer.waitForThemeMode(),
28
+ new Promise((resolveTheme) => setTimeout(() => resolveTheme(undefined), THEME_QUERY_TIMEOUT_MILLISECONDS)),
29
+ ]);
30
+ return detected ?? "dark";
31
+ }
32
+ async function main() {
33
+ const { values, positionals } = parseArgs(TUI_ARGUMENTS);
34
+ const [source] = positionals;
35
+ if (source === undefined || values.node === undefined || values.register === undefined) {
36
+ throw new Error("unigent tui: internal launch arguments are incomplete");
37
+ }
38
+ const sourceFile = isAbsolute(source) ? source : resolve(process.cwd(), source);
39
+ const scriptArguments = positionals.slice(1);
40
+ const runtime = runtimeInvocation(await detectScriptRuntime(sourceFile), values.node);
41
+ const store = createTuiStore(sourceFile);
42
+ const renderer = await createCliRenderer({ useMouse: true, exitOnCtrlC: false, targetFps: 30 });
43
+ const theme = await detectTheme(values.theme, renderer);
44
+ renderer.setBackgroundColor(paletteFor(theme).background);
45
+ const runner = createScriptRunner({
46
+ runtime,
47
+ registerEntry: values.register,
48
+ developmentLoader: values.developmentLoader,
49
+ sourceFile,
50
+ scriptArguments,
51
+ }, store);
52
+ const quit = () => {
53
+ runner.dispose();
54
+ renderer.destroy();
55
+ };
56
+ createRoot(renderer).render(_jsx(App, { store: store, initialTheme: theme, onAbort: runner.abort, onRerun: runner.start, onQuit: quit }));
57
+ runner.start();
58
+ }
59
+ main().catch((error) => {
60
+ process.stderr.write(`unigent tui: ${error instanceof Error ? error.message : String(error)}\n`);
61
+ process.exitCode = 1;
62
+ });
63
+ //# sourceMappingURL=tui.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tui.js","sourceRoot":"","sources":["../src/tui.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC7E,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAkB,MAAM,gBAAgB,CAAC;AAE5D,MAAM,gCAAgC,GAAG,GAAG,CAAC;AAE7C,MAAM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K,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACjG,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;AACvB,CAAC,CAAC,CAAC","sourcesContent":["import { isAbsolute, resolve } from \"node:path\";\nimport process from \"node:process\";\nimport { parseArgs } from \"node:util\";\nimport { createCliRenderer } from \"@opentui/core\";\nimport { createRoot } from \"@opentui/react\";\nimport { detectScriptRuntime, runtimeInvocation } from \"./script_runtime.js\";\nimport { App } from \"./tui/app.js\";\nimport { createScriptRunner } from \"./tui/runner.js\";\nimport { createTuiStore } from \"./tui/store.js\";\nimport { paletteFor, type ThemeMode } from \"./tui/theme.js\";\n\nconst THEME_QUERY_TIMEOUT_MILLISECONDS = 300;\n\nconst TUI_ARGUMENTS = {\n allowPositionals: true,\n options: {\n node: { type: \"string\" },\n register: { type: \"string\" },\n developmentLoader: { type: \"string\" },\n theme: { type: \"string\" },\n },\n} as const;\n\nasync function detectTheme(\n override: string | undefined,\n renderer: Awaited<ReturnType<typeof createCliRenderer>>,\n): Promise<ThemeMode> {\n if (override === \"light\" || override === \"dark\") {\n return override;\n }\n const detected = await Promise.race([\n renderer.waitForThemeMode(),\n new Promise<undefined>((resolveTheme) =>\n setTimeout(() => resolveTheme(undefined), THEME_QUERY_TIMEOUT_MILLISECONDS),\n ),\n ]);\n return detected ?? \"dark\";\n}\n\nasync function main(): Promise<void> {\n const { values, positionals } = parseArgs(TUI_ARGUMENTS);\n const [source] = positionals;\n if (source === undefined || values.node === undefined || values.register === undefined) {\n throw new Error(\"unigent tui: internal launch arguments are incomplete\");\n }\n const sourceFile = isAbsolute(source) ? source : resolve(process.cwd(), source);\n const scriptArguments = positionals.slice(1);\n const runtime = runtimeInvocation(await detectScriptRuntime(sourceFile), values.node);\n const store = createTuiStore(sourceFile);\n const renderer = await createCliRenderer({ useMouse: true, exitOnCtrlC: false, targetFps: 30 });\n const theme = await detectTheme(values.theme, renderer);\n renderer.setBackgroundColor(paletteFor(theme).background);\n const runner = createScriptRunner(\n {\n runtime,\n registerEntry: values.register,\n developmentLoader: values.developmentLoader,\n sourceFile,\n scriptArguments,\n },\n store,\n );\n const quit = (): void => {\n runner.dispose();\n renderer.destroy();\n };\n createRoot(renderer).render(\n <App\n store={store}\n initialTheme={theme}\n onAbort={runner.abort}\n onRerun={runner.start}\n onQuit={quit}\n />,\n );\n runner.start();\n}\n\nmain().catch((error: unknown) => {\n process.stderr.write(`unigent tui: ${error instanceof Error ? error.message : String(error)}\\n`);\n process.exitCode = 1;\n});\n"]}
@@ -0,0 +1,25 @@
1
+ /** Settlement metadata for a harness CLI child process. */
2
+ interface AdapterProcessCompletion {
3
+ readonly exitCode: number | null;
4
+ readonly signal: NodeJS.Signals | null;
5
+ }
6
+ /** Harness CLI process with replay-safe diagnostics and explicit lifecycle control. */
7
+ interface AdapterProcess {
8
+ readonly lines: AsyncIterable<string>;
9
+ readonly stderr: () => string;
10
+ readonly completion: Promise<AdapterProcessCompletion>;
11
+ readonly kill: () => void;
12
+ }
13
+ /** Complete launch request for a harness CLI child process. */
14
+ interface AdapterProcessOptions {
15
+ readonly binary: string;
16
+ readonly args: readonly string[];
17
+ readonly signal: AbortSignal;
18
+ readonly stdin: string;
19
+ readonly environment: Readonly<Record<string, string>>;
20
+ }
21
+ /** Spawn one harness CLI with bounded stderr and a completion signal that waits for pipe closure. */
22
+ declare function spawnAdapterProcess(options: AdapterProcessOptions): AdapterProcess;
23
+ export type { AdapterProcess, AdapterProcessCompletion, AdapterProcessOptions };
24
+ export { spawnAdapterProcess };
25
+ //# sourceMappingURL=adapter_process.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter_process.d.ts","sourceRoot":"","sources":["../src/adapter_process.ts"],"names":[],"mappings":"AAOA,2DAA2D;AAC3D,UAAU,wBAAwB;IAChC,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC;CACxC;AAED,uFAAuF;AACvF,UAAU,cAAc;IACtB,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACtC,QAAQ,CAAC,MAAM,EAAE,MAAM,MAAM,CAAC;IAC9B,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC,wBAAwB,CAAC,CAAC;IACvD,QAAQ,CAAC,IAAI,EAAE,MAAM,IAAI,CAAC;CAC3B;AAED,+DAA+D;AAC/D,UAAU,qBAAqB;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACxD;AAED,qGAAqG;AACrG,iBAAS,mBAAmB,CAAC,OAAO,EAAE,qBAAqB,GAAG,cAAc,CAoC3E;AAED,YAAY,EAAE,cAAc,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,CAAC;AAChF,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
@@ -0,0 +1,46 @@
1
+ import { spawn } from "node:child_process";
2
+ import process from "node:process";
3
+ import { createInterface } from "node:readline";
4
+ import { Readable } from "node:stream";
5
+ const MAXIMUM_STDERR_CHARACTERS = 65_536;
6
+ /** Spawn one harness CLI with bounded stderr and a completion signal that waits for pipe closure. */
7
+ function spawnAdapterProcess(options) {
8
+ let child;
9
+ let stderr = "";
10
+ try {
11
+ child = spawn(options.binary, [...options.args], {
12
+ stdio: ["pipe", "pipe", "pipe"],
13
+ signal: options.signal,
14
+ // biome-ignore lint/style/noProcessEnv: child must inherit the authenticated CLI environment.
15
+ env: { ...process.env, ...options.environment },
16
+ });
17
+ child.stdin.end(options.stdin);
18
+ }
19
+ catch (error) {
20
+ const message = error instanceof Error ? error.message : String(error);
21
+ return {
22
+ lines: createInterface({ input: Readable.from([]) }),
23
+ stderr: () => message,
24
+ completion: Promise.resolve({ exitCode: null, signal: null }),
25
+ kill: () => undefined,
26
+ };
27
+ }
28
+ const appendStderr = (text) => {
29
+ stderr = `${stderr}${text}`.slice(-MAXIMUM_STDERR_CHARACTERS);
30
+ };
31
+ child.on("error", (error) => appendStderr(error.message));
32
+ child.stderr.on("data", (chunk) => appendStderr(chunk.toString()));
33
+ const completion = new Promise((resolve) => {
34
+ child.once("close", (exitCode, closeSignal) => resolve({ exitCode, signal: closeSignal }));
35
+ });
36
+ return {
37
+ lines: createInterface({ input: child.stdout }),
38
+ stderr: () => stderr,
39
+ completion,
40
+ kill: () => {
41
+ child.kill();
42
+ },
43
+ };
44
+ }
45
+ export { spawnAdapterProcess };
46
+ //# sourceMappingURL=adapter_process.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter_process.js","sourceRoot":"","sources":["../src/adapter_process.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACrE,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAiB,MAAM,aAAa,CAAC;AAEtD,MAAM,yBAAyB,GAAG,MAAM,CAAC;AAyBzC,qGAAqG;AACrG,SAAS,mBAAmB,CAAC,OAA8B;IACzD,IAAI,KAAwD,CAAC;IAC7D,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,CAAC;QACH,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,EAAE;YAC/C,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;YAC/B,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,8FAA8F;YA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C,OAAO,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC;IAC7F,CAAC,CAAC,CAAC;IACH,OAAO;QACL,KAAK,EAAE,eAAe,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC;QAC/C,MAAM,EAAE,GAAG,EAAE,CAAC,MAAM;QACpB,UAAU;QACV,IAAI,EAAE,GAAS,EAAE;YACf,KAAK,CAAC,IAAI,EAAE,CAAC;QACf,CAAC;KACF,CAAC;AACJ,CAAC;AAGD,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { type OutputSchema } from "./schema.js";
2
+ type InputPair = readonly [string, string | boolean];
3
+ interface ArgsOptions {
4
+ /** One-line explanation shown before usage. */
5
+ readonly description?: string;
6
+ /** Arguments appended to the detected script name in usage output. */
7
+ readonly usage?: string;
8
+ }
9
+ /** Parse an explicit argv array as typed named arguments or scalar positional input. */
10
+ declare function parseArgs(arguments_: readonly string[]): Promise<Record<string, unknown>>;
11
+ declare function parseArgs<Output>(arguments_: readonly string[], schema: OutputSchema<Output>): Promise<Output>;
12
+ /** Parse `process.argv`, print standardized help/errors, and exit when no value can be returned. */
13
+ declare function args(options?: ArgsOptions): Promise<Record<string, unknown>>;
14
+ declare function args<Output>(schema: OutputSchema<Output>, options?: ArgsOptions): Promise<Output>;
15
+ export type { ArgsOptions, InputPair };
16
+ export { args, parseArgs };
17
+ //# sourceMappingURL=args.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"args.d.ts","sourceRoot":"","sources":["../src/args.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,YAAY,EAAe,MAAM,aAAa,CAAC;AAE7D,KAAK,SAAS,GAAG,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC;AACrD,UAAU,WAAW;IACnB,+CAA+C;IAC/C,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,sEAAsE;IACtE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB;AAwMD,wFAAwF;AACxF,iBAAe,SAAS,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAC1F,iBAAe,SAAS,CAAC,MAAM,EAC7B,UAAU,EAAE,SAAS,MAAM,EAAE,EAC7B,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC,GAC3B,OAAO,CAAC,MAAM,CAAC,CAAC;AAiDnB,oGAAoG;AACpG,iBAAe,IAAI,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAC7E,iBAAe,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAyBlG,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC"}
@@ -0,0 +1,233 @@
1
+ import { basename } from "node:path";
2
+ import process from "node:process";
3
+ import { AgentInputError } from "./errors.js";
4
+ import { parseSchema } from "./schema.js";
5
+ const NEGATION_PREFIX = "no-";
6
+ const UNSAFE_PATH_SEGMENTS = new Set([
7
+ "__proto__",
8
+ "constructor",
9
+ "prototype",
10
+ ]);
11
+ function flagPair(name, inline, next) {
12
+ if (name.length === 0) {
13
+ throw new AgentInputError("argument names must not be empty");
14
+ }
15
+ if (name.startsWith(NEGATION_PREFIX) && inline === undefined) {
16
+ return { pair: [name.slice(NEGATION_PREFIX.length), false], consumedNext: false };
17
+ }
18
+ if (inline !== undefined) {
19
+ return { pair: [name, inline], consumedNext: false };
20
+ }
21
+ if (next === undefined || next.startsWith("--")) {
22
+ return { pair: [name, true], consumedNext: false };
23
+ }
24
+ return { pair: [name, next], consumedNext: true };
25
+ }
26
+ function pairsFromArguments(arguments_) {
27
+ const pairs = [];
28
+ let index = 0;
29
+ while (index < arguments_.length) {
30
+ const token = arguments_[index] ?? "";
31
+ if (token === "--") {
32
+ index += 1;
33
+ continue;
34
+ }
35
+ if (!token.startsWith("--")) {
36
+ throw new AgentInputError(`unexpected positional argument: ${token}`);
37
+ }
38
+ const equals = token.indexOf("=");
39
+ const name = equals < 0 ? token.slice(2) : token.slice(2, equals);
40
+ const inline = equals < 0 ? undefined : token.slice(equals + 1);
41
+ const parsed = flagPair(name, inline, arguments_[index + 1]);
42
+ pairs.push(parsed.pair);
43
+ index += parsed.consumedNext ? 2 : 1;
44
+ }
45
+ return pairs;
46
+ }
47
+ function coerceScalar(raw) {
48
+ try {
49
+ const parsed = JSON.parse(raw);
50
+ if (parsed === null || typeof parsed === "number" || typeof parsed === "boolean") {
51
+ return parsed;
52
+ }
53
+ }
54
+ catch {
55
+ // Non-JSON scalars remain strings.
56
+ }
57
+ return raw;
58
+ }
59
+ async function parsePositional(arguments_, schema) {
60
+ const named = arguments_.find((token) => token.startsWith("--"));
61
+ if (named !== undefined) {
62
+ throw new AgentInputError(`cannot mix positional input with named argument: ${named}`);
63
+ }
64
+ const raw = arguments_.join(" ");
65
+ const coerced = coerceScalar(raw);
66
+ const coercedResult = await schema["~standard"].validate(coerced);
67
+ if (coercedResult.issues === undefined) {
68
+ return coercedResult.value;
69
+ }
70
+ if (!Object.is(coerced, raw)) {
71
+ const rawResult = await schema["~standard"].validate(raw);
72
+ if (rawResult.issues === undefined) {
73
+ return rawResult.value;
74
+ }
75
+ }
76
+ const parsed = await parseSchema(schema, raw);
77
+ throw new AgentInputError(parsed.error ?? "positional script input is invalid");
78
+ }
79
+ function pathSegments(path) {
80
+ const segments = path.split(".");
81
+ if (segments.some((segment) => segment.length === 0 || UNSAFE_PATH_SEGMENTS.has(segment))) {
82
+ throw new AgentInputError(`unsafe or empty argument path: ${path}`);
83
+ }
84
+ return segments;
85
+ }
86
+ function readContainer(container, key) {
87
+ return Array.isArray(container) ? container[Number(key)] : container[key];
88
+ }
89
+ function writeContainer(container, key, value) {
90
+ if (Array.isArray(container)) {
91
+ container[Number(key)] = value;
92
+ }
93
+ else {
94
+ container[key] = value;
95
+ }
96
+ }
97
+ function isInputContainer(value) {
98
+ return typeof value === "object" && value !== null;
99
+ }
100
+ function setPath(root, path, value) {
101
+ let cursor = root;
102
+ for (const segment of path.slice(0, -1)) {
103
+ const existing = readContainer(cursor, segment);
104
+ if (existing !== undefined && !isInputContainer(existing)) {
105
+ throw new AgentInputError(`argument path conflicts at ${path.join(".")}`);
106
+ }
107
+ const next = existing ?? {};
108
+ writeContainer(cursor, segment, next);
109
+ cursor = next;
110
+ }
111
+ writeContainer(cursor, path.at(-1) ?? "", value);
112
+ }
113
+ function getPath(root, path) {
114
+ let cursor = root;
115
+ for (const segment of path) {
116
+ if (!isInputContainer(cursor)) {
117
+ return;
118
+ }
119
+ cursor = readContainer(cursor, segment);
120
+ }
121
+ return cursor;
122
+ }
123
+ function assemble(pairs, coerce) {
124
+ const grouped = new Map();
125
+ for (const [name, value] of pairs) {
126
+ const values = grouped.get(name);
127
+ if (values === undefined) {
128
+ grouped.set(name, [value]);
129
+ }
130
+ else {
131
+ values.push(value);
132
+ }
133
+ }
134
+ const root = {};
135
+ const convert = (value) => coerce && typeof value === "string" ? coerceScalar(value) : value;
136
+ for (const [name, values] of grouped) {
137
+ const value = values.length === 1 ? convert(values[0] ?? "") : values.map(convert);
138
+ setPath(root, pathSegments(name), value);
139
+ }
140
+ return root;
141
+ }
142
+ function issuePath(path) {
143
+ if (!Array.isArray(path)) {
144
+ return [];
145
+ }
146
+ return path.map((segment) => typeof segment === "object" && segment !== null && "key" in segment
147
+ ? String(segment.key)
148
+ : String(segment));
149
+ }
150
+ async function uncoerceRejectedFields(schema, candidate, raw, pairCount) {
151
+ for (let attempt = 0; attempt <= pairCount; attempt += 1) {
152
+ const result = await schema["~standard"].validate(candidate);
153
+ if (result.issues === undefined) {
154
+ return result.value;
155
+ }
156
+ let changed = false;
157
+ for (const issue of result.issues) {
158
+ const path = issuePath(issue.path);
159
+ if (path.length === 0) {
160
+ continue;
161
+ }
162
+ const current = getPath(candidate, path);
163
+ const original = getPath(raw, path);
164
+ if (typeof original === "string" && current !== original) {
165
+ setPath(candidate, path, original);
166
+ changed = true;
167
+ }
168
+ }
169
+ if (!changed) {
170
+ break;
171
+ }
172
+ }
173
+ const parsed = await parseSchema(schema, candidate);
174
+ throw new AgentInputError(parsed.error ?? "script arguments are invalid");
175
+ }
176
+ async function parseArgs(arguments_, schema) {
177
+ const normalized = arguments_[0] === "--" ? arguments_.slice(1) : arguments_;
178
+ if (normalized.length === 0 && schema !== undefined) {
179
+ const emptyNamedResult = await schema["~standard"].validate({});
180
+ if (emptyNamedResult.issues === undefined) {
181
+ return emptyNamedResult.value;
182
+ }
183
+ if (emptyNamedResult.issues.every((issue) => issuePath(issue.path).length === 0)) {
184
+ return await parsePositional(normalized, schema);
185
+ }
186
+ }
187
+ const [first] = normalized;
188
+ if (first !== undefined && !first.startsWith("--")) {
189
+ if (schema === undefined) {
190
+ throw new AgentInputError(`unexpected positional argument: ${first}`);
191
+ }
192
+ return await parsePositional(normalized, schema);
193
+ }
194
+ const pairs = pairsFromArguments(normalized);
195
+ const candidate = assemble(pairs, true);
196
+ if (schema === undefined) {
197
+ return candidate;
198
+ }
199
+ return await uncoerceRejectedFields(schema, candidate, assemble(pairs, false), pairs.length);
200
+ }
201
+ function argsHelp(options) {
202
+ const [, scriptPath] = process.argv;
203
+ const scriptName = basename(scriptPath ?? "script");
204
+ const usage = options.usage ?? "[arguments]";
205
+ const description = options.description === undefined ? "" : `${options.description}\n\n`;
206
+ return `${description}Usage: ${scriptName} ${usage}\n`;
207
+ }
208
+ function exitWithArgsMessage(message, code, stream) {
209
+ stream.write(message);
210
+ process.exit(code);
211
+ }
212
+ function isOutputSchema(value) {
213
+ return value !== undefined && "~standard" in value;
214
+ }
215
+ async function args(schemaOrOptions, suppliedOptions = {}) {
216
+ const schema = isOutputSchema(schemaOrOptions) ? schemaOrOptions : undefined;
217
+ const options = isOutputSchema(schemaOrOptions) ? suppliedOptions : (schemaOrOptions ?? {});
218
+ const arguments_ = process.argv.slice(2);
219
+ if (arguments_.includes("--help") || arguments_.includes("-h")) {
220
+ return exitWithArgsMessage(argsHelp(options), 0, process.stdout);
221
+ }
222
+ try {
223
+ return schema === undefined ? await parseArgs(arguments_) : await parseArgs(arguments_, schema);
224
+ }
225
+ catch (error) {
226
+ if (error instanceof AgentInputError) {
227
+ return exitWithArgsMessage(`unigent: ${error.message}\n\n${argsHelp(options)}`, 1, process.stderr);
228
+ }
229
+ throw error;
230
+ }
231
+ }
232
+ export { args, parseArgs };
233
+ //# sourceMappingURL=args.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"args.js","sourceRoot":"","sources":["../src/args.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,OAAO,MAAM,cAAc,CAAC;AAEnC,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAqB,WAAW,EAAE,MAAM,aAAa,CAAC;AAS7D,MAAM,eAAe,GAAG,KAAK,CAAC;AAC9B,MAAM,oBAAoB,GAAwB,IAAI,GAAG,CAAC;IACxD,WAAW;IACX,aAAa;IACb,WAAW;CACZ,CAAC,CAAC;AAEH,SAAS,QAAQ,CACf,IAAY,EACZ,MAA0B,EAC1B,IAAwB;IAExB,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,MAAM,IAAI,eAAe,CAAC,kCAAkC,CAAC,CAAC;IAChE,CAAC;IACD,IAAI,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QAC7D,OAAO,EAAE,IAAI,EAAE,CAAC,IAAI,CAAC,KA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AAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,SAAS,CAAC;IAC7E,MAAM,OAAO,GAAG,cAAc,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,eAAe,IAAI,EAAE,CAAC,CAAC;IAC5F,MAAM,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACzC,IAAI,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QAC/D,OAAO,mBAAmB,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IACnE,CAAC;IACD,IAAI,CAAC;QACH,OAAO,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,MAAM,SAAS,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAClG,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,eAAe,EAAE,CAAC;YACrC,OAAO,mBAAmB,CACxB,YAAY,KAAK,CAAC,OAAO,OAAO,QAAQ,CAAC,OAAO,CAAC,EAAE,EACnD,CAAC,EACD,OAAO,CAAC,MAAM,CACf,CAAC;QACJ,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAGD,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC"}
@@ -0,0 +1,83 @@
1
+ /** JSON Schema advertised to an agent backend. */
2
+ export type JsonSchema = Readonly<Record<string, unknown>>;
3
+ /** Result returned by a tool to the backend-owned agent loop. */
4
+ export interface BackendToolResult {
5
+ readonly content: string;
6
+ readonly isError: boolean;
7
+ readonly terminate?: boolean;
8
+ }
9
+ /** Backend-neutral tool definition. */
10
+ export interface BackendTool {
11
+ readonly name: string;
12
+ readonly description: string;
13
+ readonly promptSnippet?: string;
14
+ readonly promptGuidelines?: readonly string[];
15
+ readonly parameters: JsonSchema;
16
+ readonly execute: (input: unknown) => Promise<BackendToolResult>;
17
+ }
18
+ /** Raw usage reported by one backend turn. */
19
+ export interface BackendUsage {
20
+ readonly inputTokens: number;
21
+ readonly outputTokens: number;
22
+ readonly totalTokens: number;
23
+ readonly cachedInputTokens?: number;
24
+ readonly reasoningTokens?: number;
25
+ readonly costUsd?: number;
26
+ }
27
+ /** Normalized incremental events emitted by a backend. */
28
+ export type BackendEvent = {
29
+ readonly type: "text";
30
+ readonly text: string;
31
+ } | {
32
+ readonly type: "reasoning";
33
+ readonly text: string;
34
+ } | {
35
+ readonly type: "tool_call";
36
+ readonly callId: string;
37
+ readonly name: string;
38
+ readonly input: unknown;
39
+ } | {
40
+ readonly type: "tool_result";
41
+ readonly callId: string;
42
+ readonly name: string;
43
+ readonly output: unknown;
44
+ readonly isError: boolean;
45
+ };
46
+ /** Request for one backend-owned agent turn. */
47
+ export interface BackendTurnRequest {
48
+ readonly systemPrompt: string;
49
+ readonly systemPromptMode: "append" | "replace";
50
+ readonly prompt: string;
51
+ readonly tools: readonly BackendTool[];
52
+ readonly thinking?: string;
53
+ readonly signal: AbortSignal;
54
+ readonly onEvent: (event: BackendEvent) => void;
55
+ }
56
+ /** Settled backend turn. */
57
+ export interface BackendTurnResult {
58
+ readonly text: string;
59
+ readonly usage: BackendUsage;
60
+ }
61
+ /** One stateful backend conversation. */
62
+ export interface BackendSession {
63
+ readonly runTurn: (request: BackendTurnRequest) => Promise<BackendTurnResult>;
64
+ readonly fork?: () => BackendSession;
65
+ }
66
+ /** Configuration fixed when a backend conversation opens. */
67
+ export interface BackendSessionOptions {
68
+ readonly model: string;
69
+ }
70
+ /** Capabilities whose absence must reject dependent Unigent configuration. */
71
+ export interface BackendCapabilities {
72
+ readonly reportsCost: boolean;
73
+ readonly supportsSessionFork: boolean;
74
+ }
75
+ /** Universal port implemented by Pi, Claude CLI, and future backends. */
76
+ export interface Backend {
77
+ readonly name: string;
78
+ /** Stable adapter configuration identity included in checkpoint fingerprints. */
79
+ readonly checkpointKey?: string;
80
+ readonly capabilities: BackendCapabilities;
81
+ readonly openSession: (options: BackendSessionOptions) => BackendSession | Promise<BackendSession>;
82
+ }
83
+ //# sourceMappingURL=backend.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backend.d.ts","sourceRoot":"","sources":["../src/backend.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,MAAM,MAAM,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAE3D,iEAAiE;AACjE,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,uCAAuC;AACvC,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC9C,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,QAAQ,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC,iBAAiB,CAAC,CAAC;CAClE;AAED,8CAA8C;AAC9C,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IACpC,QAAQ,CAAC,eAAe,CAAC,EAAE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B,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;CAC9B;AAED,yCAAyC;AACzC,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,OAAO,EAAE,CAAC,OAAO,EAAE,kBAAkB,KAAK,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAC9E,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,cAAc,CAAC;CACtC;AAED,6DAA6D;AAC7D,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED,8EAA8E;AAC9E,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAC9B,QAAQ,CAAC,mBAAmB,EAAE,OAAO,CAAC;CACvC;AAED,yEAAyE;AACzE,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,iFAAiF;IACjF,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,YAAY,EAAE,mBAAmB,CAAC;IAC3C,QAAQ,CAAC,WAAW,EAAE,CACpB,OAAO,EAAE,qBAAqB,KAC3B,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;CAC/C"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=backend.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backend.js","sourceRoot":"","sources":["../src/backend.ts"],"names":[],"mappings":""}
@@ -0,0 +1,26 @@
1
+ import type { AgentUsage } from "./usage.js";
2
+ /** Serializable output retained for one successful stateless run. */
3
+ type CheckpointValue = {
4
+ readonly kind: "output";
5
+ readonly value: unknown;
6
+ } | {
7
+ readonly kind: "done";
8
+ };
9
+ /** One successful stateless run retained for restart and live deduplication. */
10
+ interface CheckpointRecord {
11
+ readonly version: 1;
12
+ readonly value: CheckpointValue;
13
+ readonly usage: AgentUsage;
14
+ }
15
+ /** Content-addressed checkpoint boundary. */
16
+ interface CheckpointStore {
17
+ readonly get: (key: string) => CheckpointRecord | undefined | Promise<CheckpointRecord | undefined>;
18
+ readonly set: (key: string, record: CheckpointRecord) => void | Promise<void>;
19
+ }
20
+ /** Create an ephemeral checkpoint store. */
21
+ declare function createMemoryCheckpointStore(): CheckpointStore;
22
+ /** Create a crash-tolerant JSONL checkpoint store. */
23
+ declare function createFileCheckpointStore(filePath: string): CheckpointStore;
24
+ export type { CheckpointRecord, CheckpointStore, CheckpointValue };
25
+ export { createFileCheckpointStore, createMemoryCheckpointStore };
26
+ //# sourceMappingURL=checkpoint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkpoint.d.ts","sourceRoot":"","sources":["../src/checkpoint.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,qEAAqE;AACrE,KAAK,eAAe,GAChB;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GACpD;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAE9B,gFAAgF;AAChF,UAAU,gBAAgB;IACxB,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,eAAe,CAAC;IAChC,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;CAC5B;AAED,6CAA6C;AAC7C,UAAU,eAAe;IACvB,QAAQ,CAAC,GAAG,EAAE,CACZ,GAAG,EAAE,MAAM,KACR,gBAAgB,GAAG,SAAS,GAAG,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC,CAAC;IAC1E,QAAQ,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/E;AAwED,4CAA4C;AAC5C,iBAAS,2BAA2B,IAAI,eAAe,CAQtD;AAED,sDAAsD;AACtD,iBAAS,yBAAyB,CAAC,QAAQ,EAAE,MAAM,GAAG,eAAe,CA6BpE;AAED,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE,eAAe,EAAE,CAAC;AACnE,OAAO,EAAE,yBAAyB,EAAE,2BAA2B,EAAE,CAAC"}