inhuman 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/bin/inhuman.mjs +2 -20
  2. package/dist/bin.d.ts +6 -0
  3. package/dist/bin.d.ts.map +1 -0
  4. package/dist/bin.js +16 -0
  5. package/dist/bin.js.map +1 -0
  6. package/dist/cli/blobs-command.d.ts +31 -0
  7. package/dist/cli/blobs-command.d.ts.map +1 -0
  8. package/dist/cli/blobs-command.js +184 -0
  9. package/dist/cli/blobs-command.js.map +1 -0
  10. package/dist/cli/browser.d.ts +3 -0
  11. package/dist/cli/browser.d.ts.map +1 -0
  12. package/dist/cli/browser.js +10 -0
  13. package/dist/cli/browser.js.map +1 -0
  14. package/dist/cli/completion-command.d.ts +15 -0
  15. package/dist/cli/completion-command.d.ts.map +1 -0
  16. package/dist/cli/completion-command.js +201 -0
  17. package/dist/cli/completion-command.js.map +1 -0
  18. package/dist/cli/context.d.ts +23 -0
  19. package/dist/cli/context.d.ts.map +1 -0
  20. package/dist/cli/context.js +67 -0
  21. package/dist/cli/context.js.map +1 -0
  22. package/dist/cli/daemon.d.ts +22 -0
  23. package/dist/cli/daemon.d.ts.map +1 -0
  24. package/dist/cli/daemon.js +61 -0
  25. package/dist/cli/daemon.js.map +1 -0
  26. package/dist/cli/eval-command.d.ts +16 -0
  27. package/dist/cli/eval-command.d.ts.map +1 -0
  28. package/dist/cli/eval-command.js +114 -0
  29. package/dist/cli/eval-command.js.map +1 -0
  30. package/dist/cli/install-command.d.ts +8 -0
  31. package/dist/cli/install-command.d.ts.map +1 -0
  32. package/dist/cli/install-command.js +25 -0
  33. package/dist/cli/install-command.js.map +1 -0
  34. package/dist/cli/kernel-client.d.ts +3 -0
  35. package/dist/cli/kernel-client.d.ts.map +1 -0
  36. package/dist/cli/kernel-client.js +12 -0
  37. package/dist/cli/kernel-client.js.map +1 -0
  38. package/dist/cli/mcp-commands.d.ts +61 -0
  39. package/dist/cli/mcp-commands.d.ts.map +1 -0
  40. package/dist/cli/mcp-commands.js +139 -0
  41. package/dist/cli/mcp-commands.js.map +1 -0
  42. package/dist/cli/mcp.d.ts +25 -0
  43. package/dist/cli/mcp.d.ts.map +1 -0
  44. package/dist/cli/mcp.js +261 -0
  45. package/dist/cli/mcp.js.map +1 -0
  46. package/dist/cli/register.d.ts +12 -0
  47. package/dist/cli/register.d.ts.map +1 -0
  48. package/dist/cli/register.js +133 -0
  49. package/dist/cli/register.js.map +1 -0
  50. package/dist/cli/remote-commands.d.ts +49 -0
  51. package/dist/cli/remote-commands.d.ts.map +1 -0
  52. package/dist/cli/remote-commands.js +184 -0
  53. package/dist/cli/remote-commands.js.map +1 -0
  54. package/dist/cli/resume-complete.d.ts +24 -0
  55. package/dist/cli/resume-complete.d.ts.map +1 -0
  56. package/dist/cli/resume-complete.js +35 -0
  57. package/dist/cli/resume-complete.js.map +1 -0
  58. package/dist/cli/shell-import.d.ts +22 -0
  59. package/dist/cli/shell-import.d.ts.map +1 -0
  60. package/dist/cli/shell-import.js +32 -0
  61. package/dist/cli/shell-import.js.map +1 -0
  62. package/dist/cli/tui-command.d.ts +11 -0
  63. package/dist/cli/tui-command.d.ts.map +1 -0
  64. package/dist/cli/tui-command.js +41 -0
  65. package/dist/cli/tui-command.js.map +1 -0
  66. package/dist/cli/web-commands.d.ts +54 -0
  67. package/dist/cli/web-commands.d.ts.map +1 -0
  68. package/dist/cli/web-commands.js +106 -0
  69. package/dist/cli/web-commands.js.map +1 -0
  70. package/dist/cli/web-door-command.d.ts +11 -0
  71. package/dist/cli/web-door-command.d.ts.map +1 -0
  72. package/dist/cli/web-door-command.js +151 -0
  73. package/dist/cli/web-door-command.js.map +1 -0
  74. package/dist/cli/web-door.d.ts +25 -0
  75. package/dist/cli/web-door.d.ts.map +1 -0
  76. package/dist/cli/web-door.js +116 -0
  77. package/dist/cli/web-door.js.map +1 -0
  78. package/dist/cli/web-static.d.ts +8 -0
  79. package/dist/cli/web-static.d.ts.map +1 -0
  80. package/dist/cli/web-static.js +23 -0
  81. package/dist/cli/web-static.js.map +1 -0
  82. package/dist/eval/progress.d.ts +8 -0
  83. package/dist/eval/progress.d.ts.map +1 -0
  84. package/dist/eval/progress.js +64 -0
  85. package/dist/eval/progress.js.map +1 -0
  86. package/dist/eval/run.d.ts +20 -0
  87. package/dist/eval/run.d.ts.map +1 -0
  88. package/dist/eval/run.js +301 -0
  89. package/dist/eval/run.js.map +1 -0
  90. package/package.json +42 -5
package/bin/inhuman.mjs CHANGED
@@ -1,25 +1,7 @@
1
1
  #!/usr/bin/env node
2
- import { run } from "@inhuman.tools/harness-cli/run";
2
+ import { run } from "../dist/bin.js";
3
3
 
4
- const OPEN_VALUE_FLAGS = new Set(["--kernel", "--port"]);
5
-
6
- /** True for no arguments, or only the flags `harness open` takes: `inhuman --kernel /k --no-browser`. */
7
- function isBareOpen(args) {
8
- for (let i = 0; i < args.length; i += 1) {
9
- const arg = args[i];
10
- if (arg === "--no-browser" || /^--(?:kernel|port)=/.test(arg)) continue;
11
- if (OPEN_VALUE_FLAGS.has(arg)) {
12
- i += 1;
13
- continue;
14
- }
15
- return false;
16
- }
17
- return true;
18
- }
19
-
20
- // `inhuman` opens the web client; any other command line is the harness CLI, verbatim.
21
- const args = process.argv.slice(2);
22
- const result = await run(isBareOpen(args) ? ["open", ...args] : args, {
4
+ const result = await run(process.argv.slice(2), {
23
5
  stdin: process.stdin,
24
6
  stdout: process.stdout,
25
7
  stderr: process.stderr,
package/dist/bin.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ import type { Streams } from "./cli/context.js";
3
+ export declare function run(argv: readonly string[], streams: Streams): Promise<{
4
+ readonly code: number;
5
+ }>;
6
+ //# sourceMappingURL=bin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAGhD,wBAAsB,GAAG,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAEvG"}
package/dist/bin.js ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env node
2
+ import { realpathSync } from "node:fs";
3
+ import { pathToFileURL } from "node:url";
4
+ import { runCli } from "./cli/register.js";
5
+ export async function run(argv, streams) {
6
+ return { code: await runCli(argv, streams) };
7
+ }
8
+ if (process.argv[1] !== undefined && import.meta.url === pathToFileURL(realpathSync(process.argv[1])).href) {
9
+ const result = await run(process.argv.slice(2), {
10
+ stdin: process.stdin,
11
+ stdout: process.stdout,
12
+ stderr: process.stderr,
13
+ });
14
+ process.exit(result.code);
15
+ }
16
+ //# sourceMappingURL=bin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAGzC,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,MAAM,CAAC,KAAK,UAAU,GAAG,CAAC,IAAuB,EAAE,OAAgB;IACjE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,CAAC;AAC/C,CAAC;AAED,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,aAAa,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAC3G,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;QAC9C,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,MAAM,EAAE,OAAO,CAAC,MAAM;KACvB,CAAC,CAAC;IACH,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAC5B,CAAC"}
@@ -0,0 +1,31 @@
1
+ import { KernelCommand, type ShellContext } from "./context.js";
2
+ export declare class BlobsCommand extends KernelCommand {
3
+ static paths: string[][];
4
+ static usage: import("clipanion").Usage;
5
+ execute(): Promise<number>;
6
+ }
7
+ export declare class BlobsVacuumCommand extends KernelCommand {
8
+ static paths: string[][];
9
+ static usage: import("clipanion").Usage;
10
+ session: string;
11
+ dryRun: boolean;
12
+ execute(): Promise<number>;
13
+ }
14
+ export type BlobsVacuumArgv = {
15
+ readonly kernel: string;
16
+ readonly session: string;
17
+ readonly dryRun: boolean;
18
+ };
19
+ /** The one thing the vacuum asks of a restored session. */
20
+ export type SessionRpc = {
21
+ request(method: string, params?: unknown): Promise<unknown>;
22
+ [Symbol.asyncDispose](): Promise<void>;
23
+ };
24
+ export type BlobsDeps = {
25
+ /** Attach to a stored session. Defaults to ensuring the daemon, then `Client.restore`. */
26
+ readonly open?: (kernel: string, session: string, phase: (label: string) => void) => Promise<SessionRpc>;
27
+ };
28
+ export declare function runBlobsVacuum(args: BlobsVacuumArgv, streams: ShellContext, deps?: BlobsDeps): Promise<{
29
+ code: number;
30
+ }>;
31
+ //# sourceMappingURL=blobs-command.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blobs-command.d.ts","sourceRoot":"","sources":["../../src/cli/blobs-command.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,aAAa,EAAE,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AAEhE,qBAAa,YAAa,SAAQ,aAAa;IAC7C,MAAM,CAAC,KAAK,aAAe;IAC3B,MAAM,CAAC,KAAK,4BAGT;IAEG,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;CAMjC;AAED,qBAAa,kBAAmB,SAAQ,aAAa;IACnD,MAAM,CAAC,KAAK,aAAyB;IACrC,MAAM,CAAC,KAAK,4BAeT;IAEH,OAAO,SAA6E;IACpF,MAAM,UAA+F;IAE/F,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;CASjC;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;CAC1B,CAAC;AAEF,2DAA2D;AAC3D,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC5D,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,0FAA0F;IAC1F,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;CAC1G,CAAC;AAaF,wBAAsB,cAAc,CAClC,IAAI,EAAE,eAAe,EACrB,OAAO,EAAE,YAAY,EACrB,IAAI,GAAE,SAAc,GACnB,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAgB3B"}
@@ -0,0 +1,184 @@
1
+ var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
2
+ if (value !== null && value !== void 0) {
3
+ if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
4
+ var dispose, inner;
5
+ if (async) {
6
+ if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
7
+ dispose = value[Symbol.asyncDispose];
8
+ }
9
+ if (dispose === void 0) {
10
+ if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
11
+ dispose = value[Symbol.dispose];
12
+ if (async) inner = dispose;
13
+ }
14
+ if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
15
+ if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
16
+ env.stack.push({ value: value, dispose: dispose, async: async });
17
+ }
18
+ else if (async) {
19
+ env.stack.push({ async: true });
20
+ }
21
+ return value;
22
+ };
23
+ var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
24
+ return function (env) {
25
+ function fail(e) {
26
+ env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
27
+ env.hasError = true;
28
+ }
29
+ var r, s = 0;
30
+ function next() {
31
+ while (r = env.stack.pop()) {
32
+ try {
33
+ if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
34
+ if (r.dispose) {
35
+ var result = r.dispose.call(r.value);
36
+ if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
37
+ }
38
+ else s |= 1;
39
+ }
40
+ catch (e) {
41
+ fail(e);
42
+ }
43
+ }
44
+ if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
45
+ if (env.hasError) throw env.error;
46
+ }
47
+ return next();
48
+ };
49
+ })(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
50
+ var e = new Error(message);
51
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
52
+ });
53
+ /**
54
+ * `inhuman blobs vacuum`: move a stored session's large text into the kernel's blob bucket.
55
+ *
56
+ * A session written before large bodies left the document keeps a file's prior text and an isolated
57
+ * completion's prompt in its stored image, and the daemon never rewrites an image to convert it. This attaches
58
+ * to the stored session the way a restore does and asks the daemon to do it, then prints what moved and how much
59
+ * the stored image shrank.
60
+ */
61
+ import { ensure } from "@inhuman.tools/harness";
62
+ import { Client, RestoreNotFound } from "@inhuman.tools/harness-sdk";
63
+ import { Command, Option } from "clipanion";
64
+ import { KernelCommand } from "./context.js";
65
+ export class BlobsCommand extends KernelCommand {
66
+ static paths = [["blobs"]];
67
+ static usage = Command.Usage({
68
+ category: "Blobs",
69
+ description: "manage the large text stored beside session documents",
70
+ });
71
+ async execute() {
72
+ const blocked = this.rejectUnsupportedAgentFlags("inhuman blobs");
73
+ if (blocked !== undefined)
74
+ return blocked;
75
+ this.context.stderr.write("Specify a blobs command: vacuum\n");
76
+ return 2;
77
+ }
78
+ }
79
+ export class BlobsVacuumCommand extends KernelCommand {
80
+ static paths = [["blobs", "vacuum"]];
81
+ static usage = Command.Usage({
82
+ category: "Blobs",
83
+ description: "move a stored session's large text into the blob bucket",
84
+ details: `
85
+ A session written before large bodies left the document carries them in its stored image: a file's prior
86
+ text, and the prompt of every summarizer it ran. This moves every such body over the inline limit into the
87
+ blob bucket under the kernel folder, leaves a short head and a reference in its place, and rewrites the
88
+ stored image as one snapshot. Nothing is lost: the wire and the shells read the references.
89
+
90
+ A completion that is still running is skipped. Run it with --dry-run first to see what would move.
91
+ `,
92
+ examples: [
93
+ ["Count what would move", "$0 blobs vacuum --session <id> --dry-run"],
94
+ ["Vacuum one session", "$0 blobs vacuum --session <id>"],
95
+ ],
96
+ });
97
+ session = Option.String("--session", { description: "session id", required: true });
98
+ dryRun = Option.Boolean("--dry-run", false, { description: "count what would move; write nothing" });
99
+ async execute() {
100
+ const blocked = this.rejectUnsupportedAgentFlags("inhuman blobs vacuum");
101
+ if (blocked !== undefined)
102
+ return blocked;
103
+ const { code } = await runBlobsVacuum({ kernel: this.kernelPath(), session: this.session, dryRun: this.dryRun }, this.context);
104
+ return code;
105
+ }
106
+ }
107
+ export async function runBlobsVacuum(args, streams, deps = {}) {
108
+ const session = args.session.trim();
109
+ if (session === "") {
110
+ streams.writeErr("--session is required");
111
+ return { code: 2 };
112
+ }
113
+ const open = deps.open ?? openRestored;
114
+ try {
115
+ const env_1 = { stack: [], error: void 0, hasError: false };
116
+ try {
117
+ const rpc = __addDisposableResource(env_1, await open(args.kernel, session, (label) => streams.stderr.write(`${label}\n`)), true);
118
+ const reply = vacuumReply(await rpc.request("blob/vacuum", { dryRun: args.dryRun }));
119
+ streams.stdout.write(`${render(session, reply)}\n`);
120
+ return { code: 0 };
121
+ }
122
+ catch (e_1) {
123
+ env_1.error = e_1;
124
+ env_1.hasError = true;
125
+ }
126
+ finally {
127
+ const result_1 = __disposeResources(env_1);
128
+ if (result_1)
129
+ await result_1;
130
+ }
131
+ }
132
+ catch (error) {
133
+ streams.writeErr(error instanceof RestoreNotFound ? `session not found: ${session}` : error);
134
+ return { code: 1 };
135
+ }
136
+ }
137
+ async function openRestored(kernel, session, phase) {
138
+ await ensure(kernel);
139
+ return await Client.restore(kernel, session, phase);
140
+ }
141
+ function vacuumReply(value) {
142
+ if (typeof value !== "object" || value === null)
143
+ throw new Error("blob/vacuum answered nothing");
144
+ const record = value;
145
+ const count = (key) => {
146
+ const found = record[key];
147
+ if (typeof found !== "number" || !Number.isFinite(found))
148
+ throw new Error(`blob/vacuum: ${key} is missing`);
149
+ return found;
150
+ };
151
+ return {
152
+ dryRun: record.dryRun === true,
153
+ fileMutates: count("fileMutates"),
154
+ promptMessages: count("promptMessages"),
155
+ promptTexts: count("promptTexts"),
156
+ bytesMoved: count("bytesMoved"),
157
+ imageBytesBefore: count("imageBytesBefore"),
158
+ imageBytesAfter: count("imageBytesAfter"),
159
+ };
160
+ }
161
+ const grouped = (value) => value.toLocaleString("en-US");
162
+ function megabytes(value) {
163
+ return `${(value / 1_000_000).toFixed(1)} MB`;
164
+ }
165
+ function render(session, reply) {
166
+ const rows = [
167
+ ["file prior texts", grouped(reply.fileMutates)],
168
+ ["prompt messages", grouped(reply.promptMessages)],
169
+ ["prompt lines", grouped(reply.promptTexts)],
170
+ [reply.dryRun ? "would move" : "moved", `${megabytes(reply.bytesMoved)} (${grouped(reply.bytesMoved)} bytes)`],
171
+ reply.dryRun
172
+ ? ["stored image", `${megabytes(reply.imageBytesBefore)} (${grouped(reply.imageBytesBefore)} bytes), unchanged`]
173
+ : [
174
+ "stored image",
175
+ `${megabytes(reply.imageBytesBefore)} -> ${megabytes(reply.imageBytesAfter)} (${grouped(reply.imageBytesBefore)} -> ${grouped(reply.imageBytesAfter)} bytes)`,
176
+ ],
177
+ ];
178
+ const width = Math.max(...rows.map(([label]) => label.length));
179
+ return [
180
+ `${reply.dryRun ? "dry run: " : ""}vacuum ${session}`,
181
+ ...rows.map(([label, value]) => ` ${label.padEnd(width)} ${value}`),
182
+ ].join("\n");
183
+ }
184
+ //# sourceMappingURL=blobs-command.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blobs-command.js","sourceRoot":"","sources":["../../src/cli/blobs-command.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAE5C,OAAO,EAAE,aAAa,EAAqB,MAAM,cAAc,CAAC;AAEhE,MAAM,OAAO,YAAa,SAAQ,aAAa;IAC7C,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;IAC3B,MAAM,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,QAAQ,EAAE,OAAO;QACjB,WAAW,EAAE,uDAAuD;KACrE,CAAC,CAAC;IAEH,KAAK,CAAC,OAAO;QACX,MAAM,OAAO,GAAG,IAAI,CAAC,2BAA2B,CAAC,eAAe,CAAC,CAAC;QAClE,IAAI,OAAO,KAAK,SAAS;YAAE,OAAO,OAAO,CAAC;QAC1C,IAAI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CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QAC5C,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,OAAO,EAAE,GAAG,SAAS,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC;QAC9G,KAAK,CAAC,MAAM;YACV,CAAC,CAAC,CAAC,cAAc,EAAE,GAAG,SAAS,CAAC,KAAK,CAAC,gBAAgB,CAAC,KAAK,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC,oBAAoB,CAAC;YAChH,CAAC,CAAC;gBACE,cAAc;gBACd,GAAG,SAAS,CAAC,KAAK,CAAC,gBAAgB,CAAC,OAAO,SAAS,CAAC,KAAK,CAAC,eAAe,CAAC,KAAK,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC,OAAO,OAAO,CAAC,KAAK,CAAC,eAAe,CAAC,SAAS;aAC9J;KACN,CAAC;IACF,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;IAC/D,OAAO;QACL,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,UAAU,OAAO,EAAE;QACrD,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,KAAK,EAAE,CAAC;KACtE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC"}
@@ -0,0 +1,3 @@
1
+ /** Hand a URL to the desktop's default browser. Fire and forget: a missing opener is not an error. */
2
+ export declare function openBrowser(url: string): void;
3
+ //# sourceMappingURL=browser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../src/cli/browser.ts"],"names":[],"mappings":"AAEA,sGAAsG;AACtG,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAM7C"}
@@ -0,0 +1,10 @@
1
+ import { spawn } from "node:child_process";
2
+ /** Hand a URL to the desktop's default browser. Fire and forget: a missing opener is not an error. */
3
+ export function openBrowser(url) {
4
+ const command = process.platform === "darwin" ? "open" : process.platform === "win32" ? "cmd" : "xdg-open";
5
+ const args = process.platform === "win32" ? ["/c", "start", "", url] : [url];
6
+ const child = spawn(command, args, { detached: true, stdio: "ignore" });
7
+ child.on("error", () => undefined);
8
+ child.unref();
9
+ }
10
+ //# sourceMappingURL=browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.js","sourceRoot":"","sources":["../../src/cli/browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,sGAAsG;AACtG,MAAM,UAAU,WAAW,CAAC,GAAW;IACrC,MAAM,OAAO,GAAG,OAAO,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC;IAC3G,MAAM,IAAI,GAAG,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAC7E,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;IACxE,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IACnC,KAAK,CAAC,KAAK,EAAE,CAAC;AAChB,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { Command } from "clipanion";
2
+ import { KernelCommand, type ShellContext } from "./context.js";
3
+ export declare class CompletionCommand extends Command<ShellContext> {
4
+ static paths: string[][];
5
+ static usage: import("clipanion").Usage;
6
+ shell: "zsh" | "bash" | "fish";
7
+ execute(): Promise<number>;
8
+ }
9
+ export declare class CompleteCommand extends KernelCommand {
10
+ static paths: string[][];
11
+ static usage: import("clipanion").Usage;
12
+ query: string | undefined;
13
+ execute(): Promise<number>;
14
+ }
15
+ //# sourceMappingURL=completion-command.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"completion-command.d.ts","sourceRoot":"","sources":["../../src/cli/completion-command.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,OAAO,EAAU,MAAM,WAAW,CAAC;AAG5C,OAAO,EAAE,aAAa,EAAE,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AAehE,qBAAa,iBAAkB,SAAQ,OAAO,CAAC,YAAY,CAAC;IAC1D,MAAM,CAAC,KAAK,aAAoB;IAChC,MAAM,CAAC,KAAK,4BAST;IAEH,KAAK,0BAAwE;IAEvE,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;CAIjC;AAED,qBAAa,eAAgB,SAAQ,aAAa;IAChD,MAAM,CAAC,KAAK,aAAkB;IAC9B,MAAM,CAAC,KAAK,4BAET;IAEH,KAAK,qBAAqD;IAEpD,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;CA4BjC"}
@@ -0,0 +1,201 @@
1
+ var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
2
+ if (value !== null && value !== void 0) {
3
+ if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
4
+ var dispose, inner;
5
+ if (async) {
6
+ if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
7
+ dispose = value[Symbol.asyncDispose];
8
+ }
9
+ if (dispose === void 0) {
10
+ if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
11
+ dispose = value[Symbol.dispose];
12
+ if (async) inner = dispose;
13
+ }
14
+ if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
15
+ if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
16
+ env.stack.push({ value: value, dispose: dispose, async: async });
17
+ }
18
+ else if (async) {
19
+ env.stack.push({ async: true });
20
+ }
21
+ return value;
22
+ };
23
+ var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
24
+ return function (env) {
25
+ function fail(e) {
26
+ env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
27
+ env.hasError = true;
28
+ }
29
+ var r, s = 0;
30
+ function next() {
31
+ while (r = env.stack.pop()) {
32
+ try {
33
+ if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
34
+ if (r.dispose) {
35
+ var result = r.dispose.call(r.value);
36
+ if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
37
+ }
38
+ else s |= 1;
39
+ }
40
+ catch (e) {
41
+ fail(e);
42
+ }
43
+ }
44
+ if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
45
+ if (env.hasError) throw env.error;
46
+ }
47
+ return next();
48
+ };
49
+ })(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
50
+ var e = new Error(message);
51
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
52
+ });
53
+ /**
54
+ * Shell completion for `--resume` / `--session`. Live kernel only — never `ensure()`.
55
+ */
56
+ import { existsSync } from "node:fs";
57
+ import { join } from "node:path";
58
+ import { occupiedSessionIds } from "@inhuman.tools/harness-model";
59
+ import { Client } from "@inhuman.tools/harness-sdk";
60
+ import { Command, Option } from "clipanion";
61
+ import { makeValidator } from "typanion";
62
+ import { KernelCommand } from "./context.js";
63
+ import { formatResumeCompletion, listResumeCompletions } from "./resume-complete.js";
64
+ /** Tab-complete must not wait sdk defaults or hang the shell. */
65
+ const COMPLETE_SYNC_MS = 400;
66
+ const COMPLETE_AWARENESS_MS = 200;
67
+ const isShell = makeValidator({
68
+ test: (value, state) => {
69
+ if (value === "zsh" || value === "bash" || value === "fish")
70
+ return true;
71
+ state?.errors?.push(`Expected one of "zsh", "bash", or "fish" (got ${JSON.stringify(value)})`);
72
+ return false;
73
+ },
74
+ });
75
+ export class CompletionCommand extends Command {
76
+ static paths = [["completion"]];
77
+ static usage = Command.Usage({
78
+ description: "print a shell completion script",
79
+ details: 'Eval from the shell rc: `eval "$(inhuman completion zsh)"`. Completing `--resume` does not start the daemon.',
80
+ examples: [
81
+ ["zsh", 'eval "$(inhuman completion zsh)"'],
82
+ ["bash", 'eval "$(inhuman completion bash)"'],
83
+ ["fish", "inhuman completion fish | source"],
84
+ ],
85
+ });
86
+ shell = Option.String({ required: true, validator: isShell, name: "shell" });
87
+ async execute() {
88
+ this.context.stdout.write(scriptFor(this.shell));
89
+ return 0;
90
+ }
91
+ }
92
+ export class CompleteCommand extends KernelCommand {
93
+ static paths = [["complete"]];
94
+ static usage = Command.Usage({
95
+ description: "print --resume candidates (id<TAB>title · used|orphaned)",
96
+ });
97
+ query = Option.String({ required: false, name: "query" });
98
+ async execute() {
99
+ const blocked = this.rejectUnsupportedAgentFlags("inhuman complete");
100
+ if (blocked !== undefined)
101
+ return blocked;
102
+ const kernel = this.kernelPath();
103
+ const socket = join(kernel, "daemon.sock");
104
+ if (!existsSync(socket))
105
+ return 0;
106
+ try {
107
+ const env_1 = { stack: [], error: void 0, hasError: false };
108
+ try {
109
+ const handle = __addDisposableResource(env_1, await Client.kernel(kernel, {
110
+ reconnect: false,
111
+ syncTimeoutMs: COMPLETE_SYNC_MS,
112
+ awarenessWaitMs: COMPLETE_AWARENESS_MS,
113
+ }), true);
114
+ const sessions = {};
115
+ for (const [id, glance] of Object.entries(handle.plexus.root.sessions)) {
116
+ if (glance == null)
117
+ continue;
118
+ sessions[id] = { title: glance.title, lastMessageAt: glance.lastMessageAt ?? 0 };
119
+ }
120
+ const rows = listResumeCompletions({
121
+ sessions,
122
+ occupied: occupiedSessionIds(handle.plexus.awareness),
123
+ prefix: this.query,
124
+ });
125
+ for (const row of rows)
126
+ this.context.stdout.write(`${formatResumeCompletion(row)}\n`);
127
+ return 0;
128
+ }
129
+ catch (e_1) {
130
+ env_1.error = e_1;
131
+ env_1.hasError = true;
132
+ }
133
+ finally {
134
+ const result_1 = __disposeResources(env_1);
135
+ if (result_1)
136
+ await result_1;
137
+ }
138
+ }
139
+ catch {
140
+ return 0;
141
+ }
142
+ }
143
+ }
144
+ function scriptFor(shell) {
145
+ if (shell === "zsh") {
146
+ return `#compdef inhuman
147
+ _inhuman_sessions() {
148
+ local -a sessions
149
+ local id desc
150
+ while IFS=$'\\t' read -r id desc; do
151
+ [[ -n $id ]] || continue
152
+ sessions+=("\${id}:\${desc}")
153
+ done < <(inhuman complete -- "\${words[CURRENT]}" 2>/dev/null)
154
+ _describe -t sessions 'session' sessions
155
+ }
156
+ _inhuman() {
157
+ if [[ \${words[CURRENT-1]} == --resume || \${words[CURRENT-1]} == --session ]]; then
158
+ _inhuman_sessions
159
+ return
160
+ fi
161
+ _arguments \\
162
+ '--kernel[system folder]:path:_directories' \\
163
+ '--resume[session id]:session:_inhuman_sessions' \\
164
+ '--session[session id]:session:_inhuman_sessions' \\
165
+ '--connection[completion connection id]:connection:' \\
166
+ '--model[model id]:model:' \\
167
+ '(--continue -c)'{--continue,-c}'[restore this tab last session]' \\
168
+ '--restart-daemon[stop a live daemon before attach]' \\
169
+ '1:command:(start web login logout remote mcp daemon blobs install eval completion complete help)'
170
+ }
171
+ compdef _inhuman inhuman
172
+ `;
173
+ }
174
+ if (shell === "bash") {
175
+ return `_inhuman() {
176
+ local cur prev
177
+ COMPREPLY=()
178
+ cur="\${COMP_WORDS[COMP_CWORD]}"
179
+ prev="\${COMP_WORDS[COMP_CWORD-1]}"
180
+ if [[ $prev == --resume || $prev == --session ]]; then
181
+ local ids
182
+ ids=$(inhuman complete -- "$cur" 2>/dev/null | cut -f1)
183
+ COMPREPLY=($(compgen -W "$ids" -- "$cur"))
184
+ return
185
+ fi
186
+ COMPREPLY=($(compgen -W "start web login logout remote mcp daemon blobs install eval completion complete help --resume --session --continue --connection --model --kernel --restart-daemon" -- "$cur"))
187
+ }
188
+ complete -F _inhuman inhuman
189
+ `;
190
+ }
191
+ return `complete -c inhuman -l resume -r -f -a '(inhuman complete -- (commandline -ct) 2>/dev/null)'
192
+ complete -c inhuman -l session -r -f -a '(inhuman complete -- (commandline -ct) 2>/dev/null)'
193
+ complete -c inhuman -l continue -s c
194
+ complete -c inhuman -l connection -r
195
+ complete -c inhuman -l model -r
196
+ complete -c inhuman -l kernel -r
197
+ complete -c inhuman -l restart-daemon
198
+ complete -c inhuman -n '__fish_use_subcommand' -a 'start web login logout remote mcp daemon blobs install eval completion complete help'
199
+ `;
200
+ }
201
+ //# sourceMappingURL=completion-command.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"completion-command.js","sourceRoot":"","sources":["../../src/cli/completion-command.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;GAEG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,aAAa,EAAqB,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAErF,iEAAiE;AACjE,MAAM,gBAAgB,GA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iBACnB,CAAC,CAAC;gBACH,KAAK,MAAM,GAAG,IAAI,IAAI;oBAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,sBAAsB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;gBACtF,OAAO,CAAC,CAAC;;;;;;;;;;;SACV;QAAC,MAAM,CAAC;YACP,OAAO,CAAC,CAAC;QACX,CAAC;IACH,CAAC;;AAGH,SAAS,SAAS,CAAC,KAA8B;IAC/C,IAAI,KAAK,KAAK,KAAK,EAAE,CAAC;QACpB,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;CA0BV,CAAC;IACA,CAAC;IACD,IAAI,KAAK,KAAK,MAAM,EAAE,CAAC;QACrB,OAAO;;;;;;;;;;;;;;CAcV,CAAC;IACA,CAAC;IACD,OAAO;;;;;;;;CAQR,CAAC;AACF,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { type CliAgentFlags, type ShellStreams, type Streams } from "@inhuman.tools/harness-sdk/launch";
2
+ import { Command, type BaseContext } from "clipanion";
3
+ export type { Streams } from "@inhuman.tools/harness-sdk/launch";
4
+ export declare class ShellContext implements BaseContext, ShellStreams {
5
+ #private;
6
+ readonly stdin: NodeJS.ReadStream;
7
+ readonly stdout: NodeJS.WriteStream;
8
+ readonly stderr: NodeJS.WriteStream;
9
+ readonly cwd: string;
10
+ readonly env: NodeJS.ProcessEnv;
11
+ readonly colorDepth: number;
12
+ readonly writeErr: (error: unknown) => void;
13
+ constructor(streams: Streams);
14
+ }
15
+ export declare abstract class KernelCommand extends Command<ShellContext> {
16
+ kernel: string;
17
+ connection: string | undefined;
18
+ model: string | undefined;
19
+ kernelPath(): string;
20
+ cliAgentFlags(): CliAgentFlags;
21
+ rejectUnsupportedAgentFlags(surface: string): number | undefined;
22
+ }
23
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/cli/context.ts"],"names":[],"mappings":"AAGA,OAAO,EAGL,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,OAAO,EACb,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAU,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AAE9D,YAAY,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAEjE,qBAAa,YAAa,YAAW,WAAW,EAAE,YAAY;;IAC5D,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,UAAU,CAAC;IAClC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC;IACpC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC;IACpC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC;IAChC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAK5B,QAAQ,CAAC,QAAQ,GAAI,OAAO,OAAO,KAAG,IAAI,CAGxC;gBAEU,OAAO,EAAE,OAAO;CAmB7B;AAED,8BAAsB,aAAc,SAAQ,OAAO,CAAC,YAAY,CAAC;IAC/D,MAAM,SAEH;IACH,UAAU,qBAGP;IACH,KAAK,qBAGF;IAEH,UAAU,IAAI,MAAM;IAIpB,aAAa,IAAI,aAAa;IAO9B,2BAA2B,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;CAKjE"}
@@ -0,0 +1,67 @@
1
+ import { homedir } from "node:os";
2
+ import { join, resolve } from "node:path";
3
+ import { hasCliAgentFlags, unsupportedAgentFlagsError, } from "@inhuman.tools/harness-sdk/launch";
4
+ import { Command, Option } from "clipanion";
5
+ export class ShellContext {
6
+ stdin;
7
+ stdout;
8
+ stderr;
9
+ cwd;
10
+ env;
11
+ colorDepth;
12
+ // Own field, not a prototype method. Clipanion's Cli.process and Cli.run
13
+ // replace the context with `{ ...defaultContext, ...context }`, which drops
14
+ // the prototype. A method here is undefined on `this.context` inside commands.
15
+ writeErr = (error) => {
16
+ const message = error instanceof Error ? error.message : String(error);
17
+ this.stderr.write(message.endsWith("\n") ? message : `${message}\n`);
18
+ };
19
+ constructor(streams) {
20
+ this.stdin = streams.stdin;
21
+ this.stdout = streams.stdout;
22
+ this.stderr = streams.stderr;
23
+ this.cwd = streams.cwd ?? process.cwd();
24
+ this.env = process.env;
25
+ this.colorDepth = this.#colorDepth();
26
+ }
27
+ #colorDepth() {
28
+ if (typeof this.stdout.getColorDepth === "function") {
29
+ try {
30
+ return this.stdout.getColorDepth();
31
+ }
32
+ catch {
33
+ /* NODE_COLOR_DEPTH: WriteStream.getColorDepth() throws off-TTY */
34
+ }
35
+ }
36
+ return 1;
37
+ }
38
+ }
39
+ export class KernelCommand extends Command {
40
+ kernel = Option.String("--kernel", join(homedir(), ".harness"), {
41
+ description: "system folder",
42
+ });
43
+ connection = Option.String("--connection", {
44
+ description: "completion connection id",
45
+ required: false,
46
+ });
47
+ model = Option.String("--model", {
48
+ description: "model id (unique across connections unless --connection)",
49
+ required: false,
50
+ });
51
+ kernelPath() {
52
+ return resolve(this.kernel);
53
+ }
54
+ cliAgentFlags() {
55
+ return {
56
+ ...(this.connection == null ? {} : { connection: this.connection }),
57
+ ...(this.model == null ? {} : { model: this.model }),
58
+ };
59
+ }
60
+ rejectUnsupportedAgentFlags(surface) {
61
+ if (!hasCliAgentFlags(this.cliAgentFlags()))
62
+ return undefined;
63
+ this.context.writeErr(unsupportedAgentFlagsError(surface));
64
+ return 2;
65
+ }
66
+ }
67
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/cli/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE1C,OAAO,EACL,gBAAgB,EAChB,0BAA0B,GAI3B,MAAM,mCAAmC,CAAC;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