@agent-deck/cli 1.11.9 → 2.1.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 (76) hide show
  1. package/dist/agent-harness.d.ts +9 -2
  2. package/dist/agent-harness.d.ts.map +1 -1
  3. package/dist/agent-harness.js +90 -23
  4. package/dist/agent-harness.js.map +1 -1
  5. package/dist/codex-plugin.d.ts +27 -0
  6. package/dist/codex-plugin.d.ts.map +1 -1
  7. package/dist/codex-plugin.js +111 -6
  8. package/dist/codex-plugin.js.map +1 -1
  9. package/dist/daemon-logs.d.ts +1 -1
  10. package/dist/daemon-logs.d.ts.map +1 -1
  11. package/dist/daemon-logs.js +49 -1
  12. package/dist/daemon-logs.js.map +1 -1
  13. package/dist/index.d.ts +1 -0
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +97 -3
  16. package/dist/index.js.map +1 -1
  17. package/dist/mcp-bridge.d.ts +83 -1
  18. package/dist/mcp-bridge.d.ts.map +1 -1
  19. package/dist/mcp-bridge.js +252 -7
  20. package/dist/mcp-bridge.js.map +1 -1
  21. package/dist/mcp-config.d.ts +13 -1
  22. package/dist/mcp-config.d.ts.map +1 -1
  23. package/dist/mcp-config.js +49 -1
  24. package/dist/mcp-config.js.map +1 -1
  25. package/dist/muse-skills/agent-deck-playbooks/SKILL.md +24 -0
  26. package/dist/muse-skills/agent-deck-run/SKILL.md +69 -0
  27. package/dist/muse-skills/agent-deck-session/SKILL.md +59 -0
  28. package/dist/muse-skills/agent-deck-setup/SKILL.md +28 -0
  29. package/dist/muse-skills.d.ts +42 -0
  30. package/dist/muse-skills.d.ts.map +1 -0
  31. package/dist/muse-skills.js +149 -0
  32. package/dist/muse-skills.js.map +1 -0
  33. package/dist/run-adapter.d.ts +100 -0
  34. package/dist/run-adapter.d.ts.map +1 -0
  35. package/dist/run-adapter.js +73 -0
  36. package/dist/run-adapter.js.map +1 -0
  37. package/dist/run-claude.d.ts +41 -0
  38. package/dist/run-claude.d.ts.map +1 -0
  39. package/dist/run-claude.js +91 -0
  40. package/dist/run-claude.js.map +1 -0
  41. package/dist/run-codex.d.ts +75 -0
  42. package/dist/run-codex.d.ts.map +1 -0
  43. package/dist/run-codex.js +337 -0
  44. package/dist/run-codex.js.map +1 -0
  45. package/dist/run-cursor.d.ts +79 -0
  46. package/dist/run-cursor.d.ts.map +1 -0
  47. package/dist/run-cursor.js +455 -0
  48. package/dist/run-cursor.js.map +1 -0
  49. package/dist/run-detach.d.ts +36 -0
  50. package/dist/run-detach.d.ts.map +1 -0
  51. package/dist/run-detach.js +233 -0
  52. package/dist/run-detach.js.map +1 -0
  53. package/dist/run-muse.d.ts +127 -0
  54. package/dist/run-muse.d.ts.map +1 -0
  55. package/dist/run-muse.js +499 -0
  56. package/dist/run-muse.js.map +1 -0
  57. package/dist/run-status.d.ts +62 -0
  58. package/dist/run-status.d.ts.map +1 -0
  59. package/dist/run-status.js +552 -0
  60. package/dist/run-status.js.map +1 -0
  61. package/dist/run.d.ts +191 -0
  62. package/dist/run.d.ts.map +1 -0
  63. package/dist/run.js +680 -0
  64. package/dist/run.js.map +1 -0
  65. package/dist/setup.d.ts.map +1 -1
  66. package/dist/setup.js +51 -10
  67. package/dist/setup.js.map +1 -1
  68. package/dist/terminal-style.d.ts +9 -0
  69. package/dist/terminal-style.d.ts.map +1 -0
  70. package/dist/terminal-style.js +34 -0
  71. package/dist/terminal-style.js.map +1 -0
  72. package/dist/use.d.ts +1 -1
  73. package/dist/use.d.ts.map +1 -1
  74. package/dist/use.js +16 -15
  75. package/dist/use.js.map +1 -1
  76. package/package.json +5 -4
@@ -0,0 +1,233 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.DETACH_FIRST_LINE_TIMEOUT_MS = void 0;
7
+ exports.resolveRunOutPath = resolveRunOutPath;
8
+ exports.buildDetachedChildArgs = buildDetachedChildArgs;
9
+ exports.startDetachedRun = startDetachedRun;
10
+ /**
11
+ * `agent-deck run --detach` — start the same run in a new session (NOT-401).
12
+ *
13
+ * The starter validates the launch exactly like a foreground run, allocates the
14
+ * run id and log path, then re-executes the CLI as a detached child (`detached:
15
+ * true` calls setsid on POSIX, so the child survives the calling shell, SSH
16
+ * session, or tool call going away) with stdin from /dev/null and stdout/stderr
17
+ * to `run.out` next to the log. Every flag of the starter is passed through
18
+ * unchanged, so a `--tools edit` run cannot silently run as readonly.
19
+ *
20
+ * The starter prints `runId`, child `pid`, and the log path, then exits 0
21
+ * within DETACH_FIRST_LINE_TIMEOUT_MS. Only one outcome is a starter failure:
22
+ * the child died before writing its first log line — that surfaces as exit 1
23
+ * with the tail of the child's captured output.
24
+ */
25
+ const node_child_process_1 = require("node:child_process");
26
+ const node_fs_1 = __importDefault(require("node:fs"));
27
+ const node_path_1 = __importDefault(require("node:path"));
28
+ const daemon_logs_1 = require("./daemon-logs");
29
+ const paths_1 = require("./managed/paths");
30
+ const run_1 = require("./run");
31
+ /** Bounded starter return: never wait longer than this for the first log line. */
32
+ exports.DETACH_FIRST_LINE_TIMEOUT_MS = 5000;
33
+ /** How often the starter polls for the first log line / child exit. */
34
+ const DETACH_POLL_MS = 50;
35
+ /** Stderr lines shown when the child dies before its first log line. */
36
+ const DETACH_TAIL_LINES = 20;
37
+ /** Child stdout/stderr sink, always next to the JSONL log. */
38
+ function resolveRunOutPath(logPath) {
39
+ return node_path_1.default.join(node_path_1.default.dirname(logPath), 'run.out');
40
+ }
41
+ /** run.ts flags that consume the following argv token as their value. */
42
+ const RUN_VALUE_FLAGS = new Set([
43
+ '--client',
44
+ '--cwd',
45
+ '--prompt',
46
+ '--prompt-file',
47
+ '--tools',
48
+ '--log',
49
+ '--resume',
50
+ '--_run-id',
51
+ ]);
52
+ /**
53
+ * Child argv for the re-exec: the starter's own tokens verbatim (so a `--prompt`
54
+ * value that happens to read `--detach` still arrives intact), minus `--detach`
55
+ * itself, plus an explicit `--log` when the starter relied on the default and
56
+ * the allocated `--_run-id` so the child reuses the same run record.
57
+ */
58
+ function buildDetachedChildArgs(originalArgs, runId, logPath) {
59
+ const child = [];
60
+ let hasLog = false;
61
+ for (let i = 0; i < originalArgs.length; i += 1) {
62
+ const arg = originalArgs[i];
63
+ if (arg === '--detach') {
64
+ continue;
65
+ }
66
+ if (arg === '--_run-id') {
67
+ // A stale override never survives: the starter's allocation always wins.
68
+ i += 1;
69
+ continue;
70
+ }
71
+ child.push(arg);
72
+ if (arg === '--log') {
73
+ hasLog = true;
74
+ }
75
+ if (RUN_VALUE_FLAGS.has(arg)) {
76
+ i += 1;
77
+ if (i < originalArgs.length) {
78
+ child.push(originalArgs[i]);
79
+ }
80
+ }
81
+ }
82
+ if (!hasLog) {
83
+ child.push('--log', logPath);
84
+ }
85
+ child.push('--_run-id', runId);
86
+ return child;
87
+ }
88
+ function logHasFirstLine(logPath) {
89
+ try {
90
+ return node_fs_1.default.readFileSync(logPath, 'utf8').trim().length > 0;
91
+ }
92
+ catch {
93
+ return false;
94
+ }
95
+ }
96
+ function readOutTail(outPath, maxLines) {
97
+ try {
98
+ return node_fs_1.default
99
+ .readFileSync(outPath, 'utf8')
100
+ .split('\n')
101
+ .map((line) => line.trimEnd())
102
+ .filter((line) => line.length > 0)
103
+ .slice(-maxLines);
104
+ }
105
+ catch {
106
+ return [];
107
+ }
108
+ }
109
+ function describeChildEnd(code, signal) {
110
+ if (signal) {
111
+ return `signal ${signal}`;
112
+ }
113
+ return `code ${code ?? 1}`;
114
+ }
115
+ async function startDetachedRun(originalArgs, options, deps = {}) {
116
+ const prereq = await (0, run_1.validateRunPrereqs)(options, deps);
117
+ if ('error' in prereq) {
118
+ console.error(prereq.error);
119
+ return 1;
120
+ }
121
+ const { deck } = prereq;
122
+ const homeDir = deps.homeDir ?? (0, paths_1.agentDeckHome)();
123
+ const runId = (0, run_1.newRunId)();
124
+ const logPath = options.log ?? node_path_1.default.join(homeDir, 'runs', runId, 'run.jsonl');
125
+ const metaPath = node_path_1.default.join(node_path_1.default.dirname(logPath), 'meta.json');
126
+ const outPath = resolveRunOutPath(logPath);
127
+ node_fs_1.default.mkdirSync(node_path_1.default.dirname(logPath), { recursive: true });
128
+ const childArgs = buildDetachedChildArgs(originalArgs, runId, logPath);
129
+ const spawnFn = deps.spawnFn ?? node_child_process_1.spawn;
130
+ const cliEntry = deps.cliEntry ?? (0, daemon_logs_1.resolveCliEntry)();
131
+ const timeoutMs = deps.firstLineTimeoutMs ?? exports.DETACH_FIRST_LINE_TIMEOUT_MS;
132
+ const outFd = node_fs_1.default.openSync(outPath, 'a');
133
+ node_fs_1.default.writeSync(outFd, `\n--- run ${runId} ${new Date().toISOString()} ---\n`);
134
+ let child;
135
+ try {
136
+ child = spawnFn(process.execPath, [cliEntry, 'run', ...childArgs], {
137
+ detached: true,
138
+ stdio: ['ignore', outFd, outFd],
139
+ });
140
+ }
141
+ catch (error) {
142
+ node_fs_1.default.closeSync(outFd);
143
+ console.error(`Failed to start the detached run: ${error instanceof Error ? error.message : error}`);
144
+ return 1;
145
+ }
146
+ // The stdio fds are dup'd into the child at spawn; the starter's copies can go.
147
+ node_fs_1.default.closeSync(outFd);
148
+ let spawnError = null;
149
+ let childEnd = null;
150
+ child.on('error', (error) => {
151
+ spawnError = error;
152
+ childEnd = { code: null, signal: null };
153
+ });
154
+ child.on('exit', (code, signal) => {
155
+ childEnd = { code, signal };
156
+ });
157
+ const pid = child.pid;
158
+ if (!pid) {
159
+ console.error('Failed to start the detached run: no child pid');
160
+ return 1;
161
+ }
162
+ child.unref();
163
+ const meta = {
164
+ runId,
165
+ deck: deck.id,
166
+ client: options.client,
167
+ tools: options.tools,
168
+ cwd: options.cwd,
169
+ pid,
170
+ startedAt: new Date().toISOString(),
171
+ state: 'running',
172
+ };
173
+ (0, run_1.writeRunMeta)(metaPath, meta);
174
+ const deadline = Date.now() + timeoutMs;
175
+ for (;;) {
176
+ if (logHasFirstLine(logPath)) {
177
+ break;
178
+ }
179
+ if (childEnd !== null || spawnError !== null) {
180
+ break;
181
+ }
182
+ if (Date.now() >= deadline) {
183
+ break;
184
+ }
185
+ await new Promise((resolve) => setTimeout(resolve, DETACH_POLL_MS));
186
+ }
187
+ if (logHasFirstLine(logPath)) {
188
+ console.log(`run ${runId} detached: pid ${pid} log ${logPath}`);
189
+ return 0;
190
+ }
191
+ if (childEnd === null && spawnError === null) {
192
+ // Slow first token, but the child is alive: the launch succeeded and the
193
+ // starter must still return within its bound.
194
+ console.log(`run ${runId} detached: pid ${pid} log ${logPath}`);
195
+ return 0;
196
+ }
197
+ // The child died before writing its first log line: surface its last words
198
+ // instead of reporting a launch that never happened.
199
+ // `as` defeats narrowing: both are only assigned from event callbacks, which
200
+ // control flow cannot see, so without it they read as still-null here.
201
+ const failure = spawnError;
202
+ const end = childEnd;
203
+ if (failure !== null) {
204
+ console.error(`Detached run ${runId} failed to spawn: ${failure.message}`);
205
+ }
206
+ else {
207
+ console.error(`Detached run ${runId} (pid ${pid}) died before its first log line (${describeChildEnd(end?.code ?? null, end?.signal ?? null)})`);
208
+ }
209
+ // Console output to a file fd flushes asynchronously; give the tail a beat.
210
+ await new Promise((resolve) => setTimeout(resolve, 200));
211
+ const tail = readOutTail(outPath, DETACH_TAIL_LINES);
212
+ if (tail.length === 0) {
213
+ console.error(`[agent-deck] ${outPath} had no output to show`);
214
+ }
215
+ else {
216
+ console.error(`[agent-deck] --- last ${tail.length} line(s) of ${outPath} ---`);
217
+ for (const line of tail) {
218
+ console.error(`[agent-deck] run.out| ${line}`);
219
+ }
220
+ }
221
+ try {
222
+ const current = JSON.parse(node_fs_1.default.readFileSync(metaPath, 'utf8'));
223
+ if (current.runId === runId && current.state === 'running') {
224
+ current.state = 'error';
225
+ (0, run_1.writeRunMeta)(metaPath, current);
226
+ }
227
+ }
228
+ catch {
229
+ // The diagnostic above is the deliverable; meta bookkeeping never fails it.
230
+ }
231
+ return 1;
232
+ }
233
+ //# sourceMappingURL=run-detach.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-detach.js","sourceRoot":"","sources":["../src/run-detach.ts"],"names":[],"mappings":";;;;;;AAwCA,8CAEC;AAoBD,wDAiCC;AAyCD,4CAoIC;AA5QD;;;;;;;;;;;;;;GAcG;AACH,2DAAiF;AACjF,sDAAyB;AACzB,0DAA6B;AAE7B,+CAAgD;AAChD,2CAAgD;AAChD,+BAOe;AAEf,kFAAkF;AACrE,QAAA,4BAA4B,GAAG,IAAI,CAAC;AAEjD,uEAAuE;AACvE,MAAM,cAAc,GAAG,EAAE,CAAC;AAE1B,wEAAwE;AACxE,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAE7B,8DAA8D;AAC9D,SAAgB,iBAAiB,CAAC,OAAe;IAC/C,OAAO,mBAAI,CAAC,IAAI,CAAC,mBAAI,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,CAAC;AACrD,CAAC;AAED,yEAAyE;AACzE,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC;IAC9B,UAAU;IACV,OAAO;IACP,UAAU;IACV,eAAe;IACf,SAAS;IACT,OAAO;IACP,UAAU;IACV,WAAW;CACZ,CAAC,CAAC;AAEH;;;;;GAKG;AACH,SAAgB,sBAAsB,CACpC,YAAsB,EACtB,KAAa,EACb,OAAe;IAEf,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAI,MAAM,GAAG,KAAK,CAAC;IACnB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QAChD,MAAM,GAAG,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;QAC5B,IAAI,GAAG,KAAK,UAAU,EAAE,CAAC;YACvB,SAAS;QACX,CAAC;QACD,IAAI,GAAG,KAAK,WAAW,EAAE,CAAC;YACxB,yEAAyE;YACzE,CAAC,IAAI,CAAC,CAAC;YACP,SAA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K,CAAC,yBAAyB,IAAI,EAAE,CAAC,CAAC;QACjD,CAAC;IACH,CAAC;IACD,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,iBAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAY,CAAC;QACzE,IAAI,OAAO,CAAC,KAAK,KAAK,KAAK,IAAI,OAAO,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YAC3D,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC;YACxB,IAAA,kBAAY,EAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAClC,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,4EAA4E;IAC9E,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC"}
@@ -0,0 +1,127 @@
1
+ import { type ClientAdapter, type NormalizedEvent, type RunToolsProfile } from './run-adapter';
2
+ /**
3
+ * readonly: Muse's own read-only enforcement — `--disable-write` blocks
4
+ * non-shell workspace file writes and `--disable-shell` blocks workspace
5
+ * shell execution, so a readonly run cannot modify the checkout.
6
+ */
7
+ export declare const MUSE_READONLY_FLAGS: readonly string[];
8
+ /**
9
+ * edit: default bounded permissions (approval on-request, sandbox on) with
10
+ * no extra flags — there is no named profile to select, and the default
11
+ * never disables checks.
12
+ */
13
+ export declare const MUSE_EDIT_FLAGS: readonly string[];
14
+ export declare const MUSE_FLAGS_FOR_PROFILE: Record<RunToolsProfile, readonly string[]>;
15
+ /** Flags that must never appear in generated argv (bypass checks or trust). */
16
+ export declare const MUSE_FORBIDDEN_FLAGS: readonly string[];
17
+ export declare function resolveMuseBin(): string;
18
+ /**
19
+ * Readonly enforcement is structural AND verified: the flags exist in
20
+ * `muse exec --help` output (Muse Code 1.4.4), and planStart fails closed
21
+ * when the installed muse does not list them, so readonly never silently
22
+ * runs under default permissions. Help text, not a model call.
23
+ */
24
+ export declare function museReadonlyFlagsSupported(probe: (bin: string, argv: string[]) => {
25
+ code: number;
26
+ stdout: string;
27
+ stderr: string;
28
+ }, bin: string): boolean;
29
+ export type MuseArgvArgs = {
30
+ prompt: string;
31
+ tools: RunToolsProfile;
32
+ resumeId?: string;
33
+ };
34
+ /**
35
+ * Resume ids are muse session ids (UUIDs); a leading `-` is never legitimate
36
+ * and would be parsed as an exec option, so it fails closed in planStart and
37
+ * throws here.
38
+ */
39
+ export declare function assertSafeMuseResumeId(resumeId: string): void;
40
+ /**
41
+ * Pure argv builder (everything after the `muse` binary). Start:
42
+ * `exec --json [--disable-write --disable-shell] -- <prompt>`; resume:
43
+ * `exec --json --session-id <id> [--disable-write --disable-shell] -- <prompt>`.
44
+ * The `--` terminator (accepted by `muse exec`, verified with the echo
45
+ * provider) keeps dash-leading prompts from being parsed as muse options.
46
+ */
47
+ export declare function buildMuseArgv(args: MuseArgvArgs): string[];
48
+ export type MuseProbeResult = {
49
+ code: number;
50
+ stdout: string;
51
+ stderr: string;
52
+ };
53
+ export type MuseProbe = (bin: string, argv: string[]) => MuseProbeResult;
54
+ export declare function defaultMuseProbe(bin: string, argv: string[]): MuseProbeResult;
55
+ export type MuseChild = {
56
+ /** Stdout split into lines (without line terminators). */
57
+ stdout: AsyncIterable<string>;
58
+ /** Stderr split into lines (without line terminators). */
59
+ stderr: AsyncIterable<string>;
60
+ wait: () => Promise<{
61
+ code: number | null;
62
+ stderrTail: string;
63
+ }>;
64
+ };
65
+ export type MuseSpawn = (bin: string, argv: string[], opts: {
66
+ cwd: string;
67
+ }) => MuseChild;
68
+ export declare function defaultMuseSpawn(bin: string, argv: string[], opts: {
69
+ cwd: string;
70
+ }): MuseChild;
71
+ export type MuseLineContext = {
72
+ sessionId: string | null;
73
+ };
74
+ /**
75
+ * Map one `muse exec --json` stdout line onto normalized events. The session
76
+ * id is captured from `stream: {kind: "session", id}` on every record (no
77
+ * log line); `run.output.delta` becomes `text`; `tool_batch.effect.started`
78
+ * becomes `tool`; `run.terminal.completed` becomes `result` (subtype
79
+ * `success`, result text); any other `run.terminal.*` becomes `result`
80
+ * (subtype `failed`). Unknown kinds are ignored so a newer CLI cannot break
81
+ * the log. Never throws: unparseable lines become `notice`.
82
+ */
83
+ export declare function museEventsFromLine(line: string, ctx: MuseLineContext): NormalizedEvent[];
84
+ /** Stderr lines matching this surface as `notice` events; others are ignored. */
85
+ export declare const MUSE_STDERR_NOTICE_PATTERN: RegExp;
86
+ /**
87
+ * Map one stderr line onto a `notice` message. Muse prints startup warnings
88
+ * (`muse: Agent delegation: auto unavailable: workspace is untrusted.`,
89
+ * `muse: warning: rules file ... skipped ...`) to stderr; those surface as
90
+ * notices while routine diagnostics (`muse: workspace root: ...`, plugin
91
+ * lines) stay out of the log. Returns null for ignored lines. Never throws.
92
+ */
93
+ export declare function museNoticeFromStderr(line: string): string | null;
94
+ type MergedLine = {
95
+ source: 'out' | 'err';
96
+ line: string;
97
+ };
98
+ /**
99
+ * Merge stdout and stderr line iterables by arrival so startup warnings
100
+ * (stderr) land in the log in real order ahead of the streamed answer. Both
101
+ * sides are always consumed (no pipe deadlock); a rejection on either side
102
+ * throws, and the other side's pending read can never reject unobserved.
103
+ */
104
+ export declare function mergeMuseLines(stdout: AsyncIterable<string>, stderr: AsyncIterable<string>): AsyncGenerator<MergedLine>;
105
+ export type MuseFileReader = (path: string) => string | null;
106
+ export declare function defaultMuseFileReader(filePath: string): string | null;
107
+ /**
108
+ * Non-model signed-in check: META_API_KEY takes priority over the account
109
+ * login (`muse login --help`), otherwise the auth file must record a `meta`
110
+ * provider (token itself lives in the keychain; only the metadata is read).
111
+ */
112
+ export declare function isMuseSignedIn(readFile: MuseFileReader): boolean;
113
+ /**
114
+ * The agent-deck MCP entry must exist in the global Muse settings or the
115
+ * cwd's project `.mcp.json` (whichever `agent-deck use --client muse` wrote);
116
+ * without it no session receipt can ever appear in the log.
117
+ */
118
+ export declare function hasMuseMcpEntry(cwd: string, readFile: MuseFileReader): boolean;
119
+ export type MuseAdapterDeps = {
120
+ bin?: string;
121
+ probe?: MuseProbe;
122
+ spawn?: MuseSpawn;
123
+ readFile?: MuseFileReader;
124
+ };
125
+ export declare function createMuseAdapter(deps?: MuseAdapterDeps): ClientAdapter;
126
+ export {};
127
+ //# sourceMappingURL=run-muse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-muse.d.ts","sourceRoot":"","sources":["../src/run-muse.ts"],"names":[],"mappings":"AAoDA,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,eAAe,EACrB,MAAM,eAAe,CAAC;AAEvB;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,EAAE,SAAS,MAAM,EAA2C,CAAC;AAE7F;;;;GAIG;AACH,eAAO,MAAM,eAAe,EAAE,SAAS,MAAM,EAAO,CAAC;AAErD,eAAO,MAAM,sBAAsB,EAAE,MAAM,CAAC,eAAe,EAAE,SAAS,MAAM,EAAE,CAG7E,CAAC;AAEF,+EAA+E;AAC/E,eAAO,MAAM,oBAAoB,EAAE,SAAS,MAAM,EAMjD,CAAC;AAEF,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EACxF,GAAG,EAAE,MAAM,GACV,OAAO,CAOT;AAED,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,eAAe,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAO7D;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM,EAAE,CAS1D;AAED,MAAM,MAAM,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