@a5c-ai/config-adapter 5.1.1-staging.52898ebfc24f

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.
package/dist/config.js ADDED
@@ -0,0 +1,221 @@
1
+ /**
2
+ * `adapters config` subcommands.
3
+ *
4
+ * @see docs/10-cli-reference.md Section 16
5
+ */
6
+ import { AgentMuxError } from '@a5c-ai/comm-adapter';
7
+ import { flagBool, flagStr } from './cli-helpers.js';
8
+ import { ExitCode, errorCodeToExitCode } from './cli-helpers.js';
9
+ import { printJson, printJsonOk, printJsonError, printError, toPlain, } from './cli-helpers.js';
10
+ export async function configCommand(client, args) {
11
+ const sub = args.subcommand;
12
+ const jsonMode = flagBool(args.flags, 'json') === true;
13
+ if (sub === 'get') {
14
+ const agent = args.positionals[0] ?? flagStr(args.flags, 'agent');
15
+ if (!agent) {
16
+ if (jsonMode) {
17
+ printJsonError('VALIDATION_ERROR', 'Missing required argument: <agent>');
18
+ }
19
+ else {
20
+ printError('Missing required argument: <agent>');
21
+ }
22
+ return ExitCode.USAGE_ERROR;
23
+ }
24
+ const field = args.positionals[1];
25
+ return configGet(client, agent, field, jsonMode);
26
+ }
27
+ if (sub === 'set') {
28
+ const agent = args.positionals[0];
29
+ const field = args.positionals[1];
30
+ const value = args.positionals[2];
31
+ if (!agent || !field || value === undefined) {
32
+ if (jsonMode) {
33
+ printJsonError('VALIDATION_ERROR', 'Usage: adapters config set <agent> <field> <value>');
34
+ }
35
+ else {
36
+ printError('Usage: adapters config set <agent> <field> <value>');
37
+ }
38
+ return ExitCode.USAGE_ERROR;
39
+ }
40
+ return configSet(client, agent, field, value, jsonMode);
41
+ }
42
+ if (sub === 'schema') {
43
+ const agent = args.positionals[0] ?? flagStr(args.flags, 'agent');
44
+ if (!agent) {
45
+ if (jsonMode) {
46
+ printJsonError('VALIDATION_ERROR', 'Missing required argument: <agent>');
47
+ }
48
+ else {
49
+ printError('Missing required argument: <agent>');
50
+ }
51
+ return ExitCode.USAGE_ERROR;
52
+ }
53
+ return configSchema(client, agent, jsonMode);
54
+ }
55
+ if (sub === 'validate') {
56
+ const agent = args.positionals[0] ?? flagStr(args.flags, 'agent');
57
+ if (!agent) {
58
+ if (jsonMode) {
59
+ printJsonError('VALIDATION_ERROR', 'Missing required argument: <agent>');
60
+ }
61
+ else {
62
+ printError('Missing required argument: <agent>');
63
+ }
64
+ return ExitCode.USAGE_ERROR;
65
+ }
66
+ return configValidate(client, agent, jsonMode);
67
+ }
68
+ if (sub === 'reload') {
69
+ const agent = args.positionals[0] ?? flagStr(args.flags, 'agent');
70
+ return configReload(client, agent, jsonMode);
71
+ }
72
+ if (!sub) {
73
+ if (jsonMode) {
74
+ printJsonError('VALIDATION_ERROR', 'Missing subcommand. Available: get, set, schema, validate, reload');
75
+ }
76
+ else {
77
+ printError('Missing subcommand. Available: get, set, schema, validate, reload');
78
+ }
79
+ return ExitCode.USAGE_ERROR;
80
+ }
81
+ if (jsonMode) {
82
+ printJsonError('VALIDATION_ERROR', `Unknown subcommand: config ${sub}`);
83
+ }
84
+ else {
85
+ printError(`Unknown subcommand: config ${sub}`);
86
+ }
87
+ return ExitCode.USAGE_ERROR;
88
+ }
89
+ async function configGet(client, agent, field, jsonMode) {
90
+ try {
91
+ let result;
92
+ if (field) {
93
+ result = await client.config.getField(agent, field);
94
+ }
95
+ else {
96
+ result = await client.config.get(agent);
97
+ }
98
+ if (jsonMode) {
99
+ // Ensure `data` key is present even when the field is missing, so
100
+ // consumers can rely on a consistent { ok, data } shape.
101
+ printJsonOk(result === undefined ? null : result);
102
+ }
103
+ else if (typeof result === 'object' && result !== null) {
104
+ printJson(result);
105
+ }
106
+ else {
107
+ process.stdout.write(String(result) + '\n');
108
+ }
109
+ return ExitCode.SUCCESS;
110
+ }
111
+ catch (err) {
112
+ return handleError(err, jsonMode);
113
+ }
114
+ }
115
+ async function configSet(client, agent, field, rawValue, jsonMode) {
116
+ try {
117
+ // Parse value: JSON if it starts with {, [, ", or is a number/boolean
118
+ let value = rawValue;
119
+ if (rawValue.startsWith('{') || rawValue.startsWith('[') || rawValue.startsWith('"') ||
120
+ rawValue === 'true' || rawValue === 'false' || rawValue === 'null' ||
121
+ !Number.isNaN(Number(rawValue))) {
122
+ try {
123
+ value = JSON.parse(rawValue);
124
+ }
125
+ catch {
126
+ // Keep as string
127
+ }
128
+ }
129
+ await client.config.setField(agent, field, value);
130
+ if (jsonMode) {
131
+ printJsonOk({ agent, field, value });
132
+ }
133
+ else {
134
+ process.stdout.write(`Set ${agent}.${field} = ${JSON.stringify(value)}\n`);
135
+ }
136
+ return ExitCode.SUCCESS;
137
+ }
138
+ catch (err) {
139
+ return handleError(err, jsonMode);
140
+ }
141
+ }
142
+ async function configSchema(client, agent, jsonMode) {
143
+ try {
144
+ const schema = await client.config.schema(agent);
145
+ if (jsonMode) {
146
+ printJsonOk(schema);
147
+ }
148
+ else {
149
+ printJson(schema);
150
+ }
151
+ return ExitCode.SUCCESS;
152
+ }
153
+ catch (err) {
154
+ return handleError(err, jsonMode);
155
+ }
156
+ }
157
+ async function configValidate(client, agent, jsonMode) {
158
+ try {
159
+ const config = await client.config.get(agent);
160
+ const result = await client.config.validate(agent, config);
161
+ if (jsonMode) {
162
+ printJsonOk(result);
163
+ }
164
+ else {
165
+ const r = toPlain(result);
166
+ if (r['valid']) {
167
+ process.stdout.write('Configuration is valid.\n');
168
+ }
169
+ else {
170
+ const errors = (r['errors'] ?? []);
171
+ for (const e of errors) {
172
+ process.stderr.write(` ${e['field']}: ${e['message']}\n`);
173
+ }
174
+ }
175
+ }
176
+ return ExitCode.SUCCESS;
177
+ }
178
+ catch (err) {
179
+ return handleError(err, jsonMode);
180
+ }
181
+ }
182
+ async function configReload(client, agent, jsonMode) {
183
+ try {
184
+ if (agent) {
185
+ await client.config.reload(agent);
186
+ }
187
+ else {
188
+ await client.config.reload();
189
+ }
190
+ if (jsonMode) {
191
+ printJsonOk({ reloaded: agent ?? 'all' });
192
+ }
193
+ else {
194
+ process.stdout.write(`Configuration reloaded${agent ? ` for ${agent}` : ''}.\n`);
195
+ }
196
+ return ExitCode.SUCCESS;
197
+ }
198
+ catch (err) {
199
+ return handleError(err, jsonMode);
200
+ }
201
+ }
202
+ function handleError(err, jsonMode) {
203
+ if (err instanceof AgentMuxError) {
204
+ if (jsonMode) {
205
+ printJsonError(err.code, err.message, err.recoverable);
206
+ }
207
+ else {
208
+ printError(err.message);
209
+ }
210
+ return errorCodeToExitCode(err.code);
211
+ }
212
+ const message = err instanceof Error ? err.message : String(err);
213
+ if (jsonMode) {
214
+ printJsonError('INTERNAL', message);
215
+ }
216
+ else {
217
+ printError(message);
218
+ }
219
+ return ExitCode.GENERAL_ERROR;
220
+ }
221
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EACL,SAAS,EAAE,WAAW,EAAE,cAAc,EAAE,UAAU,EAAiB,OAAO,GAC3E,MAAM,kBAAkB,CAAC;AAE1B,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,MAAsB,EAAE,IAAgB;IAC1E,MAAM,GAAG,GAAG,IAAI,CAAC,UAAU,CAAC;IAC5B,MAAM,QAAQ,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,CAAC;IAEvD,IAAI,GAAG,KAAK,KAAK,EAAE,CAAC;QAClB,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAClE,IAAI,CA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cAAc,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IACtC,CAAC;SAAM,CAAC;QACN,UAAU,CAAC,OAAO,CAAC,CAAC;IACtB,CAAC;IACD,OAAO,QAAQ,CAAC,aAAa,CAAC;AAChC,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * `adapters detect-host` — detect whether the current process is running
3
+ * under a supported agent harness.
4
+ */
5
+ import type { AgentMuxClient } from '@a5c-ai/comm-adapter';
6
+ import type { ParsedArgs } from './cli-helpers.js';
7
+ export declare function detectHostCommand(client: AgentMuxClient, args: ParsedArgs): Promise<number>;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detect-host.d.ts","sourceRoot":"","sources":["../src/detect-host.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAKnD,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,cAAc,EACtB,IAAI,EAAE,UAAU,GACf,OAAO,CAAC,MAAM,CAAC,CAuBjB"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * `adapters detect-host` — detect whether the current process is running
3
+ * under a supported agent harness.
4
+ */
5
+ import { flagBool } from './cli-helpers.js';
6
+ import { ExitCode } from './cli-helpers.js';
7
+ import { printJsonOk, printKeyValue } from './cli-helpers.js';
8
+ export async function detectHostCommand(client, args) {
9
+ const jsonMode = flagBool(args.flags, 'json') === true;
10
+ const info = client.detectHost();
11
+ if (jsonMode) {
12
+ printJsonOk({
13
+ detected: info !== null,
14
+ agent: info?.agent ?? null,
15
+ confidence: info?.confidence ?? null,
16
+ source: info?.source ?? null,
17
+ matchedSignals: info?.matchedSignals ?? [],
18
+ });
19
+ }
20
+ else if (info === null) {
21
+ process.stdout.write('No host harness detected. This process appears to be running from a shell.\n');
22
+ }
23
+ else {
24
+ printKeyValue([
25
+ ['Host agent:', info.agent],
26
+ ['Confidence:', info.confidence],
27
+ ['Source:', info.source],
28
+ ['Signals:', info.matchedSignals.join(', ') || '--'],
29
+ ]);
30
+ }
31
+ return ExitCode.SUCCESS;
32
+ }
33
+ //# sourceMappingURL=detect-host.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detect-host.js","sourceRoot":"","sources":["../src/detect-host.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAE9D,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,MAAsB,EACtB,IAAgB;IAEhB,MAAM,QAAQ,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,CAAC;IACvD,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;IAEjC,IAAI,QAAQ,EAAE,CAAC;QACb,WAAW,CAAC;YACV,QAAQ,EAAE,IAAI,KAAK,IAAI;YACvB,KAAK,EAAE,IAAI,EAAE,KAAK,IAAI,IAAI;YAC1B,UAAU,EAAE,IAAI,EAAE,UAAU,IAAI,IAAI;YACpC,MAAM,EAAE,IAAI,EAAE,MAAM,IAAI,IAAI;YAC5B,cAAc,EAAE,IAAI,EAAE,cAAc,IAAI,EAAE;SAC3C,CAAC,CAAC;IACL,CAAC;SAAM,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QACzB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,8EAA8E,CAAC,CAAC;IACvG,CAAC;SAAM,CAAC;QACN,aAAa,CAAC;YACZ,CAAC,aAAa,EAAE,IAAI,CAAC,KAAK,CAAC;YAC3B,CAAC,aAAa,EAAE,IAAI,CAAC,UAAU,CAAC;YAChC,CAAC,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC;YACxB,CAAC,UAAU,EAAE,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC;SACrD,CAAC,CAAC;IACL,CAAC;IACD,OAAO,QAAQ,CAAC,OAAO,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @a5c-ai/config-adapter
3
+ *
4
+ * Install, config, auth, host-detection, and adapter-listing logic
5
+ * for adapters. Extracted from the CLI package so these capabilities
6
+ * can be consumed programmatically without pulling in the full CLI.
7
+ */
8
+ export { installCommand, INSTALL_FLAGS, } from './install.js';
9
+ export type { InstallCommandDeps, SpawnRunner, } from './install.js';
10
+ export { makeSpawnRunner, defaultSpawnRunner, silentSpawnRunner, runSilently, } from './install-helpers.js';
11
+ export { configCommand } from './config.js';
12
+ export { authCommand } from './auth.js';
13
+ export { detectHostCommand } from './detect-host.js';
14
+ export { adaptersCommand } from './adapters.js';
15
+ export { ExitCode, errorCodeToExitCode, flagStr, flagBool, printTable, printKeyValue, printJson, printJsonOk, printJsonError, printError, toPlain, setColorEnabled, } from './cli-helpers.js';
16
+ export type { ParsedArgs, FlagDef, ExitCodeValue, } from './cli-helpers.js';
17
+ export type { InstallResult, DetectInstallationResult, AgentMuxClient, AgentAdapter, Spawner, } from './types.js';
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EACL,cAAc,EACd,aAAa,GACd,MAAM,cAAc,CAAC;AAEtB,YAAY,EACV,kBAAkB,EAClB,WAAW,GACZ,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,iBAAiB,EACjB,WAAW,GACZ,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG5C,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAGxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGrD,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAGhD,OAAO,EACL,QAAQ,EACR,mBAAmB,EACnB,OAAO,EACP,QAAQ,EACR,UAAU,EACV,aAAa,EACb,SAAS,EACT,WAAW,EACX,cAAc,EACd,UAAU,EACV,OAAO,EACP,eAAe,GAChB,MAAM,kBAAkB,CAAC;AAG1B,YAAY,EACV,UAAU,EACV,OAAO,EACP,aAAa,GACd,MAAM,kBAAkB,CAAC;AAE1B,YAAY,EACV,aAAa,EACb,wBAAwB,EACxB,cAAc,EACd,YAAY,EACZ,OAAO,GACR,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @a5c-ai/config-adapter
3
+ *
4
+ * Install, config, auth, host-detection, and adapter-listing logic
5
+ * for adapters. Extracted from the CLI package so these capabilities
6
+ * can be consumed programmatically without pulling in the full CLI.
7
+ */
8
+ // Install command
9
+ export { installCommand, INSTALL_FLAGS, } from './install.js';
10
+ // Install helpers
11
+ export { makeSpawnRunner, defaultSpawnRunner, silentSpawnRunner, runSilently, } from './install-helpers.js';
12
+ // Config command
13
+ export { configCommand } from './config.js';
14
+ // Auth command
15
+ export { authCommand } from './auth.js';
16
+ // Detect-host command
17
+ export { detectHostCommand } from './detect-host.js';
18
+ // Adapters command
19
+ export { adaptersCommand } from './adapters.js';
20
+ // CLI helpers (exit codes, flag utilities, output)
21
+ export { ExitCode, errorCodeToExitCode, flagStr, flagBool, printTable, printKeyValue, printJson, printJsonOk, printJsonError, printError, toPlain, setColorEnabled, } from './cli-helpers.js';
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,kBAAkB;AAClB,OAAO,EACL,cAAc,EACd,aAAa,GACd,MAAM,cAAc,CAAC;AAOtB,kBAAkB;AAClB,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,iBAAiB,EACjB,WAAW,GACZ,MAAM,sBAAsB,CAAC;AAE9B,iBAAiB;AACjB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,eAAe;AACf,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC,sBAAsB;AACtB,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,mBAAmB;AACnB,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,mDAAmD;AACnD,OAAO,EACL,QAAQ,EACR,mBAAmB,EACnB,OAAO,EACP,QAAQ,EACR,UAAU,EACV,aAAa,EACb,SAAS,EACT,WAAW,EACX,cAAc,EACd,UAAU,EACV,OAAO,EACP,eAAe,GAChB,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Internal helpers for the install/update/detect/uninstall commands.
3
+ * Split out to keep `install.ts` under the max-file-lines budget.
4
+ */
5
+ export type SpawnRunner = (command: string, args: string[]) => Promise<{
6
+ code: number;
7
+ stdout: string;
8
+ stderr: string;
9
+ }>;
10
+ /**
11
+ * Create a SpawnRunner. When `echo` is true, child output is mirrored to
12
+ * the CLI's stdout/stderr (useful for long-running install commands in
13
+ * human mode). When false (default for JSON/detect), child output is
14
+ * captured silently so it doesn't contaminate structured output.
15
+ */
16
+ export declare function makeSpawnRunner(echo: boolean): SpawnRunner;
17
+ export declare const defaultSpawnRunner: SpawnRunner;
18
+ export declare const silentSpawnRunner: SpawnRunner;
19
+ /**
20
+ * Temporarily swallow writes to process.stdout/stderr while `fn` runs.
21
+ * Used to suppress per-agent JSON envelopes when `--all --json` aggregates
22
+ * results into a single response.
23
+ */
24
+ export declare function runSilently<T>(fn: () => Promise<T>): Promise<T>;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"install-helpers.d.ts","sourceRoot":"","sources":["../src/install-helpers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,MAAM,MAAM,WAAW,GAAG,CACxB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EAAE,KACX,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAE/D;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,OAAO,GAAG,WAAW,CAuB1D;AAED,eAAO,MAAM,kBAAkB,EAAE,WAAmC,CAAC;AACrE,eAAO,MAAM,iBAAiB,EAAE,WAAoC,CAAC;AAErE;;;;GAIG;AACH,wBAAsB,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAYrE"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Internal helpers for the install/update/detect/uninstall commands.
3
+ * Split out to keep `install.ts` under the max-file-lines budget.
4
+ */
5
+ import { spawn } from 'node:child_process';
6
+ /**
7
+ * Create a SpawnRunner. When `echo` is true, child output is mirrored to
8
+ * the CLI's stdout/stderr (useful for long-running install commands in
9
+ * human mode). When false (default for JSON/detect), child output is
10
+ * captured silently so it doesn't contaminate structured output.
11
+ */
12
+ export function makeSpawnRunner(echo) {
13
+ return (command, args) => new Promise((resolve, reject) => {
14
+ const child = spawn(command, args, {
15
+ stdio: ['ignore', 'pipe', 'pipe'],
16
+ shell: process.platform === 'win32',
17
+ windowsHide: true,
18
+ });
19
+ let stdout = '';
20
+ let stderr = '';
21
+ child.stdout?.setEncoding('utf8');
22
+ child.stderr?.setEncoding('utf8');
23
+ child.stdout?.on('data', (c) => {
24
+ stdout += c;
25
+ if (echo)
26
+ process.stdout.write(c);
27
+ });
28
+ child.stderr?.on('data', (c) => {
29
+ stderr += c;
30
+ if (echo)
31
+ process.stderr.write(c);
32
+ });
33
+ child.on('error', (err) => reject(err));
34
+ child.on('exit', (code) => resolve({ code: code ?? 1, stdout, stderr }));
35
+ });
36
+ }
37
+ export const defaultSpawnRunner = makeSpawnRunner(true);
38
+ export const silentSpawnRunner = makeSpawnRunner(false);
39
+ /**
40
+ * Temporarily swallow writes to process.stdout/stderr while `fn` runs.
41
+ * Used to suppress per-agent JSON envelopes when `--all --json` aggregates
42
+ * results into a single response.
43
+ */
44
+ export async function runSilently(fn) {
45
+ const origOut = process.stdout.write.bind(process.stdout);
46
+ const origErr = process.stderr.write.bind(process.stderr);
47
+ const noop = ((..._a) => true);
48
+ process.stdout.write = noop;
49
+ process.stderr.write = noop;
50
+ try {
51
+ return await fn();
52
+ }
53
+ finally {
54
+ process.stdout.write = origOut;
55
+ process.stderr.write = origErr;
56
+ }
57
+ }
58
+ //# sourceMappingURL=install-helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"install-helpers.js","sourceRoot":"","sources":["../src/install-helpers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAO3C;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,IAAa;IAC3C,OAAO,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,CACvB,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC9B,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE;YACjC,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC;YACjC,KAAK,EAAE,OAAO,CAAC,QAAQ,KAAK,OAAO;YACnC,WAAW,EAAE,IAAI;SAClB,CAAC,CAAC;QACH,IAAI,MAAM,GAAG,EAAE,CAAC;QAChB,IAAI,MAAM,GAAG,EAAE,CAAC;QAChB,KAAK,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;QAClC,KAAK,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;QAClC,KAAK,CAAC,MA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C,CAAC,KAAK,GAAG,IAAI,CAAC;IACrE,OAAO,CAAC,MAA+C,CAAC,KAAK,GAAG,IAAI,CAAC;IACtE,IAAI,CAAC;QACH,OAAO,MAAM,EAAE,EAAE,CAAC;IACpB,CAAC;YAAS,CAAC;QACR,OAAO,CAAC,MAA+C,CAAC,KAAK,GAAG,OAAO,CAAC;QACxE,OAAO,CAAC,MAA+C,CAAC,KAAK,GAAG,OAAO,CAAC;IAC3E,CAAC;AACH,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * `adapters install <agent>`, `adapters update <agent>`, `adapters detect <agent>`,
3
+ * and `adapters uninstall <agent>` commands.
4
+ *
5
+ * Dispatches to the adapter's per-agent install/update/detect methods,
6
+ * so each harness may override behavior.
7
+ *
8
+ * @see docs/10-cli-reference.md
9
+ */
10
+ import type { AgentMuxClient } from '@a5c-ai/comm-adapter';
11
+ import type { ParsedArgs, FlagDef } from './cli-helpers.js';
12
+ import { type SpawnRunner as HelperSpawnRunner } from './install-helpers.js';
13
+ /** Flags recognized by the install/uninstall/update/detect commands. */
14
+ export declare const INSTALL_FLAGS: Record<string, FlagDef>;
15
+ export type SpawnRunner = HelperSpawnRunner;
16
+ export interface InstallCommandDeps {
17
+ /** Back-compat: overrides the adapter's internal Spawner for this run. */
18
+ spawnRunner?: SpawnRunner;
19
+ }
20
+ /**
21
+ * Handle `adapters install [<agent>] [--all]`, `adapters update [<agent>] [--all]`,
22
+ * `adapters detect [<agent>] [--all]`, and `adapters uninstall <agent>`.
23
+ */
24
+ export declare function installCommand(client: AgentMuxClient, args: ParsedArgs, deps?: InstallCommandDeps): Promise<number>;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../src/install.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EACV,cAAc,EAKf,MAAM,sBAAsB,CAAC;AAG9B,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAO5D,OAAO,EAEL,KAAK,WAAW,IAAI,iBAAiB,EACtC,MAAM,sBAAsB,CAAC;AAE9B,wEAAwE;AACxE,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAKjD,CAAC;AAOF,MAAM,MAAM,WAAW,GAAG,iBAAiB,CAAC;AAM5C,MAAM,WAAW,kBAAkB;IACjC,0EAA0E;IAC1E,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,cAAc,EACtB,IAAI,EAAE,UAAU,EAChB,IAAI,GAAE,kBAAuB,GAC5B,OAAO,CAAC,MAAM,CAAC,CA+CjB"}