agent-relay 6.0.21 → 6.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.
- package/dist/index.cjs +360 -61
- package/dist/src/cli/bootstrap.d.ts.map +1 -1
- package/dist/src/cli/bootstrap.js +62 -0
- package/dist/src/cli/bootstrap.js.map +1 -1
- package/dist/src/cli/commands/agent-management.d.ts +9 -0
- package/dist/src/cli/commands/agent-management.d.ts.map +1 -1
- package/dist/src/cli/commands/agent-management.js +80 -6
- package/dist/src/cli/commands/agent-management.js.map +1 -1
- package/dist/src/cli/commands/core.d.ts.map +1 -1
- package/dist/src/cli/commands/core.js +2 -0
- package/dist/src/cli/commands/core.js.map +1 -1
- package/dist/src/cli/commands/drive.d.ts +222 -0
- package/dist/src/cli/commands/drive.d.ts.map +1 -0
- package/dist/src/cli/commands/drive.js +565 -0
- package/dist/src/cli/commands/drive.js.map +1 -0
- package/dist/src/cli/commands/messaging.d.ts +25 -0
- package/dist/src/cli/commands/messaging.d.ts.map +1 -1
- package/dist/src/cli/commands/messaging.js +702 -138
- package/dist/src/cli/commands/messaging.js.map +1 -1
- package/dist/src/cli/commands/new.d.ts +112 -0
- package/dist/src/cli/commands/new.d.ts.map +1 -0
- package/dist/src/cli/commands/new.js +189 -0
- package/dist/src/cli/commands/new.js.map +1 -0
- package/dist/src/cli/commands/on/provision.d.ts +1 -1
- package/dist/src/cli/commands/on/provision.d.ts.map +1 -1
- package/dist/src/cli/commands/on/provision.js +1 -1
- package/dist/src/cli/commands/on/provision.js.map +1 -1
- package/dist/src/cli/commands/on/start.d.ts +1 -1
- package/dist/src/cli/commands/on/start.d.ts.map +1 -1
- package/dist/src/cli/commands/on/start.js +2 -2
- package/dist/src/cli/commands/on/start.js.map +1 -1
- package/dist/src/cli/commands/passthrough.d.ts +142 -0
- package/dist/src/cli/commands/passthrough.d.ts.map +1 -0
- package/dist/src/cli/commands/passthrough.js +398 -0
- package/dist/src/cli/commands/passthrough.js.map +1 -0
- package/dist/src/cli/commands/rm.d.ts +52 -0
- package/dist/src/cli/commands/rm.d.ts.map +1 -0
- package/dist/src/cli/commands/rm.js +96 -0
- package/dist/src/cli/commands/rm.js.map +1 -0
- package/dist/src/cli/commands/view.d.ts +98 -0
- package/dist/src/cli/commands/view.d.ts.map +1 -0
- package/dist/src/cli/commands/view.js +238 -0
- package/dist/src/cli/commands/view.js.map +1 -0
- package/dist/src/cli/lib/agent-management-listing.d.ts +35 -7
- package/dist/src/cli/lib/agent-management-listing.d.ts.map +1 -1
- package/dist/src/cli/lib/agent-management-listing.js +188 -40
- package/dist/src/cli/lib/agent-management-listing.js.map +1 -1
- package/dist/src/cli/lib/attach.d.ts +56 -0
- package/dist/src/cli/lib/attach.d.ts.map +1 -0
- package/dist/src/cli/lib/attach.js +73 -0
- package/dist/src/cli/lib/attach.js.map +1 -0
- package/dist/src/cli/lib/broker-connection.d.ts +40 -0
- package/dist/src/cli/lib/broker-connection.d.ts.map +1 -0
- package/dist/src/cli/lib/broker-connection.js +82 -0
- package/dist/src/cli/lib/broker-connection.js.map +1 -0
- package/dist/src/cli/lib/broker-lifecycle.d.ts +2 -0
- package/dist/src/cli/lib/broker-lifecycle.d.ts.map +1 -1
- package/dist/src/cli/lib/broker-lifecycle.js +263 -69
- package/dist/src/cli/lib/broker-lifecycle.js.map +1 -1
- package/dist/src/cli/lib/formatting.d.ts +4 -0
- package/dist/src/cli/lib/formatting.d.ts.map +1 -1
- package/dist/src/cli/lib/formatting.js +31 -1
- package/dist/src/cli/lib/formatting.js.map +1 -1
- package/dist/src/cli/lib/sdk-client.d.ts +9 -0
- package/dist/src/cli/lib/sdk-client.d.ts.map +1 -0
- package/dist/src/cli/lib/sdk-client.js +28 -0
- package/dist/src/cli/lib/sdk-client.js.map +1 -0
- package/dist/src/cli/lib/spawn-and-attach.d.ts +132 -0
- package/dist/src/cli/lib/spawn-and-attach.d.ts.map +1 -0
- package/dist/src/cli/lib/spawn-and-attach.js +334 -0
- package/dist/src/cli/lib/spawn-and-attach.js.map +1 -0
- package/dist/src/cost/pricing.d.ts.map +1 -1
- package/dist/src/cost/pricing.js +5 -3
- package/dist/src/cost/pricing.js.map +1 -1
- package/package.json +12 -10
- package/dist/packages/cloud/src/api-client.d.ts +0 -33
- package/dist/packages/cloud/src/api-client.d.ts.map +0 -1
- package/dist/packages/cloud/src/api-client.js +0 -123
- package/dist/packages/cloud/src/api-client.js.map +0 -1
- package/dist/packages/cloud/src/auth.d.ts +0 -13
- package/dist/packages/cloud/src/auth.d.ts.map +0 -1
- package/dist/packages/cloud/src/auth.js +0 -299
- package/dist/packages/cloud/src/auth.js.map +0 -1
- package/dist/packages/cloud/src/connect.d.ts +0 -45
- package/dist/packages/cloud/src/connect.d.ts.map +0 -1
- package/dist/packages/cloud/src/connect.js +0 -166
- package/dist/packages/cloud/src/connect.js.map +0 -1
- package/dist/packages/cloud/src/index.d.ts +0 -10
- package/dist/packages/cloud/src/index.d.ts.map +0 -1
- package/dist/packages/cloud/src/index.js +0 -10
- package/dist/packages/cloud/src/index.js.map +0 -1
- package/dist/packages/cloud/src/lib/ssh-interactive.d.ts +0 -70
- package/dist/packages/cloud/src/lib/ssh-interactive.d.ts.map +0 -1
- package/dist/packages/cloud/src/lib/ssh-interactive.js +0 -440
- package/dist/packages/cloud/src/lib/ssh-interactive.js.map +0 -1
- package/dist/packages/cloud/src/lib/ssh-runtime.d.ts +0 -35
- package/dist/packages/cloud/src/lib/ssh-runtime.d.ts.map +0 -1
- package/dist/packages/cloud/src/lib/ssh-runtime.js +0 -52
- package/dist/packages/cloud/src/lib/ssh-runtime.js.map +0 -1
- package/dist/packages/cloud/src/proactive-runtime.d.ts +0 -24
- package/dist/packages/cloud/src/proactive-runtime.d.ts.map +0 -1
- package/dist/packages/cloud/src/proactive-runtime.js +0 -315
- package/dist/packages/cloud/src/proactive-runtime.js.map +0 -1
- package/dist/packages/cloud/src/types.d.ts +0 -200
- package/dist/packages/cloud/src/types.d.ts.map +0 -1
- package/dist/packages/cloud/src/types.js +0 -12
- package/dist/packages/cloud/src/types.js.map +0 -1
- package/dist/packages/cloud/src/workflows.d.ts +0 -65
- package/dist/packages/cloud/src/workflows.d.ts.map +0 -1
- package/dist/packages/cloud/src/workflows.js +0 -892
- package/dist/packages/cloud/src/workflows.js.map +0 -1
- package/dist/packages/cloud/src/workspaces.d.ts +0 -11
- package/dist/packages/cloud/src/workspaces.d.ts.map +0 -1
- package/dist/packages/cloud/src/workspaces.js +0 -146
- package/dist/packages/cloud/src/workspaces.js.map +0 -1
- package/dist/packages/sdk/src/provisioner/local-jwks.d.ts +0 -25
- package/dist/packages/sdk/src/provisioner/local-jwks.d.ts.map +0 -1
- package/dist/packages/sdk/src/provisioner/local-jwks.js +0 -70
- package/dist/packages/sdk/src/provisioner/local-jwks.js.map +0 -1
- package/dist/packages/sdk/src/provisioner/seeder.d.ts +0 -17
- package/dist/packages/sdk/src/provisioner/seeder.d.ts.map +0 -1
- package/dist/packages/sdk/src/provisioner/seeder.js +0 -419
- package/dist/packages/sdk/src/provisioner/seeder.js.map +0 -1
- package/dist/packages/sdk/src/provisioner/token.d.ts +0 -41
- package/dist/packages/sdk/src/provisioner/token.d.ts.map +0 -1
- package/dist/packages/sdk/src/provisioner/token.js +0 -77
- package/dist/packages/sdk/src/provisioner/token.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatting.d.ts","sourceRoot":"","sources":["../../../../src/cli/lib/formatting.ts"],"names":[],"mappings":"AAAA,wBAAgB,kBAAkB,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAavD;AAED,wBAAgB,UAAU,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"formatting.d.ts","sourceRoot":"","sources":["../../../../src/cli/lib/formatting.ts"],"names":[],"mappings":"AAAA,wBAAgB,kBAAkB,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAavD;AAED,6EAA6E;AAC7E,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAS1D;AAED,wBAAgB,UAAU,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CA6B7D;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CASzD;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE7D;AAED,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,WAAW,EAAE,GAAG,MAAM,CAI7D"}
|
|
@@ -17,13 +17,27 @@ export function formatRelativeTime(iso) {
|
|
|
17
17
|
const diffDays = Math.floor(diffHours / 24);
|
|
18
18
|
return `${diffDays}d ago`;
|
|
19
19
|
}
|
|
20
|
+
/** Format an uptime expressed in whole seconds as a compact `1h 02m 03s`. */
|
|
21
|
+
export function formatUptimeSecs(totalSecs) {
|
|
22
|
+
if (!Number.isFinite(totalSecs) || totalSecs < 0)
|
|
23
|
+
return '-';
|
|
24
|
+
const secs = Math.floor(totalSecs);
|
|
25
|
+
const h = Math.floor(secs / 3600);
|
|
26
|
+
const m = Math.floor((secs % 3600) / 60);
|
|
27
|
+
const s = secs % 60;
|
|
28
|
+
if (h > 0)
|
|
29
|
+
return `${h}h ${String(m).padStart(2, '0')}m ${String(s).padStart(2, '0')}s`;
|
|
30
|
+
if (m > 0)
|
|
31
|
+
return `${m}m ${String(s).padStart(2, '0')}s`;
|
|
32
|
+
return `${s}s`;
|
|
33
|
+
}
|
|
20
34
|
export function parseSince(input) {
|
|
21
35
|
if (!input)
|
|
22
36
|
return undefined;
|
|
23
37
|
const trimmed = String(input).trim();
|
|
24
38
|
if (!trimmed)
|
|
25
39
|
return undefined;
|
|
26
|
-
const durationMatch = trimmed.match(/^(
|
|
40
|
+
const durationMatch = trimmed.match(/^(\d+)([smhd])$/i);
|
|
27
41
|
if (durationMatch) {
|
|
28
42
|
const value = Number(durationMatch[1]);
|
|
29
43
|
const unit = durationMatch[2].toLowerCase();
|
|
@@ -35,11 +49,27 @@ export function parseSince(input) {
|
|
|
35
49
|
};
|
|
36
50
|
return Date.now() - value * multipliers[unit];
|
|
37
51
|
}
|
|
52
|
+
if (!/^\d{4}-\d{2}-\d{2}(?:[Tt ][0-2]\d:[0-5]\d(?::[0-5]\d(?:\.\d{1,9})?)?(?:[Zz]|[+-][0-2]\d:?[0-5]\d)?)?$/.test(trimmed)) {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
38
55
|
const parsed = Date.parse(trimmed);
|
|
39
56
|
if (Number.isNaN(parsed))
|
|
40
57
|
return undefined;
|
|
41
58
|
return parsed;
|
|
42
59
|
}
|
|
60
|
+
export function sanitizeForTerminal(input) {
|
|
61
|
+
/* eslint-disable no-control-regex -- intentionally matching ANSI/control bytes to strip them */
|
|
62
|
+
return input
|
|
63
|
+
.replace(/\x1B\][^\x07]*(?:\x07|\x1B\\)/g, '')
|
|
64
|
+
.replace(/\x1B\[[0-?]*[ -/]*[@-~]/g, '')
|
|
65
|
+
.replace(/\x9B[0-?]*[ -/]*[@-~]/g, '')
|
|
66
|
+
.replace(/\x1B[@-Z\\-_]/g, '')
|
|
67
|
+
.replace(/[\x00-\x08\x0B\x0C\x0D\x0E-\x1F\x7F-\x9F]/g, '');
|
|
68
|
+
/* eslint-enable no-control-regex */
|
|
69
|
+
}
|
|
70
|
+
export function sanitizeForTerminalLine(input) {
|
|
71
|
+
return sanitizeForTerminal(input.replace(/[\r\n\t]+/g, ' '));
|
|
72
|
+
}
|
|
43
73
|
export function formatTableRow(columns) {
|
|
44
74
|
return columns
|
|
45
75
|
.map((column) => (typeof column.width === 'number' ? column.value.padEnd(column.width) : column.value))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatting.js","sourceRoot":"","sources":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ACD,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACnC,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC;QAAE,OAAO,SAAS,CAAC;IAC3C,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,KAAa;IAC/C,gGAAgG;IAChG,OAAO,KAAK;SACT,OAAO,CAAC,gCAAgC,EAAE,EAAE,CAAC;SAC7C,OAAO,CAAC,0BAA0B,EAAE,EAAE,CAAC;SACvC,OAAO,CAAC,wBAAwB,EAAE,EAAE,CAAC;SACrC,OAAO,CAAC,gBAAgB,EAAE,EAAE,CAAC;SAC7B,OAAO,CAAC,4CAA4C,EAAE,EAAE,CAAC,CAAC;IAC7D,oCAAoC;AACtC,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,KAAa;IACnD,OAAO,mBAAmB,CAAC,KAAK,CAAC,OAAO,CAAC,YAAY,EAAE,GAAG,CAAC,CAAC,CAAC;AAC/D,CAAC;AAOD,MAAM,UAAU,cAAc,CAAC,OAAsB;IACnD,OAAO,OAAO;SACX,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,MAAM,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;SACtG,IAAI,CAAC,GAAG,CAAC,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AgentRelayClient } from '@agent-relay/sdk';
|
|
2
|
+
import type { BrokerConnection } from './broker-connection.js';
|
|
3
|
+
export declare function createBrokerClient(connection: BrokerConnection, fetchFn?: typeof globalThis.fetch): AgentRelayClient;
|
|
4
|
+
export interface BrokerSdkFailure {
|
|
5
|
+
status: number;
|
|
6
|
+
message: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function mapBrokerSdkFailure(error: unknown): BrokerSdkFailure;
|
|
9
|
+
//# sourceMappingURL=sdk-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk-client.d.ts","sourceRoot":"","sources":["../../../../src/cli/lib/sdk-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAA2B,MAAM,kBAAkB,CAAC;AAE7E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE/D,wBAAgB,kBAAkB,CAChC,UAAU,EAAE,gBAAgB,EAC5B,OAAO,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,GAChC,gBAAgB,CAMlB;AAED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,gBAAgB,CAWpE"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { AgentRelayClient, AgentRelayProtocolError } from '@agent-relay/sdk';
|
|
2
|
+
export function createBrokerClient(connection, fetchFn) {
|
|
3
|
+
return new AgentRelayClient({
|
|
4
|
+
baseUrl: connection.url,
|
|
5
|
+
apiKey: connection.apiKey,
|
|
6
|
+
fetch: fetchFn,
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
export function mapBrokerSdkFailure(error) {
|
|
10
|
+
if (error instanceof AgentRelayProtocolError) {
|
|
11
|
+
return {
|
|
12
|
+
status: error.status ?? parseHttpStatus(error.code) ?? 0,
|
|
13
|
+
message: error.message,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
status: 0,
|
|
18
|
+
message: error instanceof Error ? error.message : String(error),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function parseHttpStatus(code) {
|
|
22
|
+
const match = /^http_(\d{3})$/.exec(code);
|
|
23
|
+
if (!match)
|
|
24
|
+
return undefined;
|
|
25
|
+
const status = Number(match[1]);
|
|
26
|
+
return Number.isInteger(status) ? status : undefined;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=sdk-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk-client.js","sourceRoot":"","sources":["../../../../src/cli/lib/sdk-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAI7E,MAAM,UAAU,kBAAkB,CAChC,UAA4B,EAC5B,OAAiC;IAEjC,OAAO,IAAI,gBAAgB,CAAC;QAC1B,OAAO,EAAE,UAAU,CAAC,GAAG;QACvB,MAAM,EAAE,UAAU,CAAC,MAAM;QACzB,KAAK,EAAE,OAAO;KACf,CAAC,CAAC;AACL,CAAC;AAOD,MAAM,UAAU,mBAAmB,CAAC,KAAc;IAChD,IAAI,KAAK,YAAY,uBAAuB,EAAE,CAAC;QAC7C,OAAO;YACL,MAAM,EAAE,KAAK,CAAC,MAAM,IAAI,eAAe,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC;YACxD,OAAO,EAAE,KAAK,CAAC,OAAO;SACvB,CAAC;IACJ,CAAC;IACD,OAAO;QACL,MAAM,EAAE,CAAC;QACT,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;KAChE,CAAC;AACJ,CAAC;AAED,SAAS,eAAe,CAAC,IAAY;IACnC,MAAM,KAAK,GAAG,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1C,IAAI,CAAC,KAAK;QAAE,OAAO,SAAS,CAAC;IAC7B,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAChC,OAAO,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;AACvD,CAAC"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared spawn-and-attach helper.
|
|
3
|
+
*
|
|
4
|
+
* Two entry points compose `new` + a session verb:
|
|
5
|
+
*
|
|
6
|
+
* 1. `agent-relay new NAME CLI --attach [--mode …] [--ephemeral]`
|
|
7
|
+
* — the explicit, flag-driven path.
|
|
8
|
+
* 2. `agent-relay -n NAME CLI [args...]` — the bare `-n` shorthand,
|
|
9
|
+
* hardcoded to `--mode passthrough --ephemeral`.
|
|
10
|
+
*
|
|
11
|
+
* Both call `runSpawnAndAttach()` here. There is one function that does
|
|
12
|
+
* the work, and the only difference between the two entry points is
|
|
13
|
+
* which `SpawnAndAttachOptions` they construct — so the shorthand and
|
|
14
|
+
* the explicit form produce identical broker calls and teardown
|
|
15
|
+
* behaviour by construction.
|
|
16
|
+
*
|
|
17
|
+
* This module lives in `src/cli/lib/` (not `src/cli/commands/`) because
|
|
18
|
+
* it's a helper consumed by multiple commands (`new --attach` action)
|
|
19
|
+
* and the bootstrap-layer alias dispatcher, not a verb registration in
|
|
20
|
+
* its own right.
|
|
21
|
+
*/
|
|
22
|
+
import { type BrokerConnection } from './broker-connection.js';
|
|
23
|
+
import { type NewDependencies } from '../commands/new.js';
|
|
24
|
+
import { type DriveDependencies } from '../commands/drive.js';
|
|
25
|
+
import { type PassthroughDependencies } from '../commands/passthrough.js';
|
|
26
|
+
import { type ViewDependencies } from '../commands/view.js';
|
|
27
|
+
export type AttachMode = 'view' | 'drive' | 'passthrough';
|
|
28
|
+
/** Options the composition layer understands. */
|
|
29
|
+
export interface SpawnAndAttachOptions {
|
|
30
|
+
name: string;
|
|
31
|
+
cli: string;
|
|
32
|
+
args?: string[];
|
|
33
|
+
mode?: AttachMode;
|
|
34
|
+
ephemeral?: boolean;
|
|
35
|
+
task?: string;
|
|
36
|
+
channels?: string;
|
|
37
|
+
cwd?: string;
|
|
38
|
+
team?: string;
|
|
39
|
+
model?: string;
|
|
40
|
+
brokerUrl?: string;
|
|
41
|
+
apiKey?: string;
|
|
42
|
+
stateDir?: string;
|
|
43
|
+
}
|
|
44
|
+
/** Shared dependencies the composition needs. */
|
|
45
|
+
export interface SpawnAndAttachDependencies {
|
|
46
|
+
/** For the spawn step. */
|
|
47
|
+
newDeps: NewDependencies;
|
|
48
|
+
/** For `--mode drive` attach. */
|
|
49
|
+
driveDeps: DriveDependencies;
|
|
50
|
+
/** For `--mode passthrough` attach. */
|
|
51
|
+
passthroughDeps: PassthroughDependencies;
|
|
52
|
+
/** For `--mode view` attach. */
|
|
53
|
+
viewDeps: ViewDependencies;
|
|
54
|
+
/** Issue a release on ephemeral teardown. Default delegates to `rm.releaseAgent`. */
|
|
55
|
+
releaseAgent: (connection: BrokerConnection, name: string, fetchFn: typeof globalThis.fetch) => Promise<{
|
|
56
|
+
ok: boolean;
|
|
57
|
+
status: number;
|
|
58
|
+
message?: string;
|
|
59
|
+
}>;
|
|
60
|
+
/** Signal registrar so the ephemeral teardown fires on SIGINT/SIGTERM. */
|
|
61
|
+
onSignal: (signal: NodeJS.Signals, handler: () => void | Promise<void>) => void;
|
|
62
|
+
log: (...args: unknown[]) => void;
|
|
63
|
+
error: (...args: unknown[]) => void;
|
|
64
|
+
}
|
|
65
|
+
/** Bundle of child-module deps used by the production default factory. */
|
|
66
|
+
export interface AttachChildDependencies {
|
|
67
|
+
newDeps: NewDependencies;
|
|
68
|
+
driveDeps: DriveDependencies;
|
|
69
|
+
passthroughDeps: PassthroughDependencies;
|
|
70
|
+
viewDeps: ViewDependencies;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Build the default child-module deps (`new` / `drive` / `passthrough` /
|
|
74
|
+
* `view`) using the production defaults — global `fetch`, real
|
|
75
|
+
* WebSocket, real signal registration, real stdin/stdout. Exported so
|
|
76
|
+
* bootstrap-layer callers can wire production defaults without
|
|
77
|
+
* re-encoding every detail.
|
|
78
|
+
*/
|
|
79
|
+
export declare function buildDefaultAttachChildDeps(): AttachChildDependencies;
|
|
80
|
+
/**
|
|
81
|
+
* Build the full `SpawnAndAttachDependencies` bundle from the child
|
|
82
|
+
* deps. Exposed so callers that already have child deps (e.g. tests)
|
|
83
|
+
* can opt into the default `releaseAgent` / `onSignal` wiring without
|
|
84
|
+
* re-implementing it.
|
|
85
|
+
*/
|
|
86
|
+
export declare function buildSpawnAndAttachDeps(childDeps?: AttachChildDependencies): SpawnAndAttachDependencies;
|
|
87
|
+
/**
|
|
88
|
+
* Spawn an agent and immediately attach to it via the chosen session
|
|
89
|
+
* verb. Single code path for both `new -n NAME CLI --attach …` and the
|
|
90
|
+
* verbless `-n NAME CLI` alias.
|
|
91
|
+
*
|
|
92
|
+
* Returns the exit code the CLI should propagate.
|
|
93
|
+
*/
|
|
94
|
+
export declare function runSpawnAndAttach(options: SpawnAndAttachOptions, deps: SpawnAndAttachDependencies): Promise<number>;
|
|
95
|
+
/**
|
|
96
|
+
* Tiny standalone entry point for the verbless `-n NAME CLI` shorthand
|
|
97
|
+
* dispatcher in `bootstrap.ts`. Hands off to `runSpawnAndAttach` with
|
|
98
|
+
* the shorthand's hardcoded preset (`--mode passthrough`, `--ephemeral`).
|
|
99
|
+
*/
|
|
100
|
+
export declare function runVerblessAliasDispatch(parsedArgs: {
|
|
101
|
+
name: string;
|
|
102
|
+
cli: string;
|
|
103
|
+
args: string[];
|
|
104
|
+
}, childDeps?: AttachChildDependencies): Promise<number>;
|
|
105
|
+
/**
|
|
106
|
+
* Pre-parse `argv.slice(2)` to detect the `-n NAME CLI [args...]`
|
|
107
|
+
* shorthand. Returns the parsed shape when the arguments unambiguously
|
|
108
|
+
* fit the shorthand, or `null` to let Commander parse normally.
|
|
109
|
+
*
|
|
110
|
+
* Recognised forms:
|
|
111
|
+
*
|
|
112
|
+
* agent-relay -n NAME CLI [args...]
|
|
113
|
+
* agent-relay --name NAME CLI [args...]
|
|
114
|
+
* agent-relay -nNAME CLI [args...] (joined short flag)
|
|
115
|
+
* agent-relay --name=NAME CLI [args...] (equals form)
|
|
116
|
+
*
|
|
117
|
+
* Rejected (returns null — fall through to Commander):
|
|
118
|
+
* - any of the registered subcommand names ('view', 'drive', etc.)
|
|
119
|
+
* appears as the first non-flag token, even after `-n`
|
|
120
|
+
* - `-h`/`--help`/`-V`/`--version` present
|
|
121
|
+
* - `-n` without a CLI positional
|
|
122
|
+
*
|
|
123
|
+
* Exported for unit testing alongside the byte-equivalence test that
|
|
124
|
+
* proves the shorthand parse matches what `new NAME CLI --attach --mode passthrough --ephemeral`
|
|
125
|
+
* decomposes into at the action layer.
|
|
126
|
+
*/
|
|
127
|
+
export declare function parseVerblessAlias(args: string[], knownVerbs: ReadonlySet<string>): {
|
|
128
|
+
name: string;
|
|
129
|
+
cli: string;
|
|
130
|
+
args: string[];
|
|
131
|
+
} | null;
|
|
132
|
+
//# sourceMappingURL=spawn-and-attach.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spawn-and-attach.d.ts","sourceRoot":"","sources":["../../../../src/cli/lib/spawn-and-attach.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AASH,OAAO,EAIL,KAAK,gBAAgB,EACtB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAAc,KAAK,eAAe,EAAyB,MAAM,oBAAoB,CAAC;AAE7F,OAAO,EAEL,KAAK,iBAAiB,EAIvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAEL,KAAK,uBAAuB,EAE7B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAkB,KAAK,gBAAgB,EAAsB,MAAM,qBAAqB,CAAC;AAEhG,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,OAAO,GAAG,aAAa,CAAC;AAE1D,iDAAiD;AACjD,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,GAA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AAC1E,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,eAAe,CAAC;IACzB,SAAS,EAAE,iBAAiB,CAAC;IAC7B,eAAe,EAAE,uBAAuB,CAAC;IACzC,QAAQ,EAAE,gBAAgB,CAAC;CAC5B;AAED;;;;;;GAMG;AACH,wBAAgB,2BAA2B,IAAI,uBAAuB,CAwFrE;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,SAAS,GAAE,uBAAuD,GACjE,0BAA0B,CAW5B;AAmBD;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,qBAAqB,EAC9B,IAAI,EAAE,0BAA0B,GAC/B,OAAO,CAAC,MAAM,CAAC,CAwGjB;AAED;;;;GAIG;AACH,wBAAsB,wBAAwB,CAC5C,UAAU,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,EACzD,SAAS,GAAE,uBAAuD,GACjE,OAAO,CAAC,MAAM,CAAC,CAWjB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,EAAE,EACd,UAAU,EAAE,WAAW,CAAC,MAAM,CAAC,GAC9B;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,GAAG,IAAI,CA6CtD"}
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared spawn-and-attach helper.
|
|
3
|
+
*
|
|
4
|
+
* Two entry points compose `new` + a session verb:
|
|
5
|
+
*
|
|
6
|
+
* 1. `agent-relay new NAME CLI --attach [--mode …] [--ephemeral]`
|
|
7
|
+
* — the explicit, flag-driven path.
|
|
8
|
+
* 2. `agent-relay -n NAME CLI [args...]` — the bare `-n` shorthand,
|
|
9
|
+
* hardcoded to `--mode passthrough --ephemeral`.
|
|
10
|
+
*
|
|
11
|
+
* Both call `runSpawnAndAttach()` here. There is one function that does
|
|
12
|
+
* the work, and the only difference between the two entry points is
|
|
13
|
+
* which `SpawnAndAttachOptions` they construct — so the shorthand and
|
|
14
|
+
* the explicit form produce identical broker calls and teardown
|
|
15
|
+
* behaviour by construction.
|
|
16
|
+
*
|
|
17
|
+
* This module lives in `src/cli/lib/` (not `src/cli/commands/`) because
|
|
18
|
+
* it's a helper consumed by multiple commands (`new --attach` action)
|
|
19
|
+
* and the bootstrap-layer alias dispatcher, not a verb registration in
|
|
20
|
+
* its own right.
|
|
21
|
+
*/
|
|
22
|
+
import WebSocket from 'ws';
|
|
23
|
+
import { captureAndRenderSnapshot, } from './attach.js';
|
|
24
|
+
import { defaultStateDir, readConnectionFileFromDisk, resolveBrokerConnection, } from './broker-connection.js';
|
|
25
|
+
import { defaultExit, runSignalHandler } from './exit.js';
|
|
26
|
+
import { spawnAgent } from '../commands/new.js';
|
|
27
|
+
import { releaseAgent } from '../commands/rm.js';
|
|
28
|
+
import { runDriveSession, } from '../commands/drive.js';
|
|
29
|
+
import { runPassthroughSession, } from '../commands/passthrough.js';
|
|
30
|
+
import { runViewSession } from '../commands/view.js';
|
|
31
|
+
/**
|
|
32
|
+
* Build the default child-module deps (`new` / `drive` / `passthrough` /
|
|
33
|
+
* `view`) using the production defaults — global `fetch`, real
|
|
34
|
+
* WebSocket, real signal registration, real stdin/stdout. Exported so
|
|
35
|
+
* bootstrap-layer callers can wire production defaults without
|
|
36
|
+
* re-encoding every detail.
|
|
37
|
+
*/
|
|
38
|
+
export function buildDefaultAttachChildDeps() {
|
|
39
|
+
const sharedConnectionDeps = {
|
|
40
|
+
readConnectionFile: readConnectionFileFromDisk,
|
|
41
|
+
getDefaultStateDir: defaultStateDir,
|
|
42
|
+
env: process.env,
|
|
43
|
+
};
|
|
44
|
+
const sharedFetch = (input, init) => fetch(input, init);
|
|
45
|
+
const sharedLog = (...args) => console.error(...args);
|
|
46
|
+
const sharedError = (...args) => console.error(...args);
|
|
47
|
+
const sharedExit = defaultExit;
|
|
48
|
+
const sharedWriteChunk = (chunk) => {
|
|
49
|
+
process.stdout.write(chunk);
|
|
50
|
+
};
|
|
51
|
+
const sharedOnSignal = (signal, handler) => {
|
|
52
|
+
process.on(signal, () => runSignalHandler(handler));
|
|
53
|
+
};
|
|
54
|
+
const sharedSnapshot = (connection, agentName, snapshotDeps) => captureAndRenderSnapshot(connection, agentName, snapshotDeps);
|
|
55
|
+
const stdinHandle = process.stdin;
|
|
56
|
+
const terminalHandle = {
|
|
57
|
+
getSize: () => {
|
|
58
|
+
const stdout = process.stdout;
|
|
59
|
+
if (!stdout.isTTY)
|
|
60
|
+
return null;
|
|
61
|
+
const rows = stdout.rows;
|
|
62
|
+
const cols = stdout.columns;
|
|
63
|
+
if (typeof rows !== 'number' || typeof cols !== 'number')
|
|
64
|
+
return null;
|
|
65
|
+
return { rows, cols };
|
|
66
|
+
},
|
|
67
|
+
onResize: (handler) => {
|
|
68
|
+
process.stdout.on('resize', handler);
|
|
69
|
+
return () => process.stdout.off('resize', handler);
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
const newDeps = {
|
|
73
|
+
...sharedConnectionDeps,
|
|
74
|
+
fetch: sharedFetch,
|
|
75
|
+
log: (...args) => console.log(...args),
|
|
76
|
+
error: sharedError,
|
|
77
|
+
exit: sharedExit,
|
|
78
|
+
};
|
|
79
|
+
const driveDeps = {
|
|
80
|
+
...sharedConnectionDeps,
|
|
81
|
+
createWebSocket: (url, headers) => new WebSocket(url, { headers }),
|
|
82
|
+
writeChunk: sharedWriteChunk,
|
|
83
|
+
onSignal: sharedOnSignal,
|
|
84
|
+
log: sharedLog,
|
|
85
|
+
error: sharedError,
|
|
86
|
+
exit: sharedExit,
|
|
87
|
+
fetch: sharedFetch,
|
|
88
|
+
captureAndRenderSnapshot: sharedSnapshot,
|
|
89
|
+
stdin: stdinHandle,
|
|
90
|
+
terminal: terminalHandle,
|
|
91
|
+
};
|
|
92
|
+
const passthroughDeps = {
|
|
93
|
+
...sharedConnectionDeps,
|
|
94
|
+
createWebSocket: (url, headers) => new WebSocket(url, { headers }),
|
|
95
|
+
writeChunk: sharedWriteChunk,
|
|
96
|
+
onSignal: sharedOnSignal,
|
|
97
|
+
log: sharedLog,
|
|
98
|
+
error: sharedError,
|
|
99
|
+
exit: sharedExit,
|
|
100
|
+
fetch: sharedFetch,
|
|
101
|
+
captureAndRenderSnapshot: sharedSnapshot,
|
|
102
|
+
stdin: stdinHandle,
|
|
103
|
+
terminal: terminalHandle,
|
|
104
|
+
};
|
|
105
|
+
const viewDeps = {
|
|
106
|
+
...sharedConnectionDeps,
|
|
107
|
+
createWebSocket: (url, headers) => new WebSocket(url, { headers }),
|
|
108
|
+
writeChunk: sharedWriteChunk,
|
|
109
|
+
onSignal: sharedOnSignal,
|
|
110
|
+
log: sharedLog,
|
|
111
|
+
error: sharedError,
|
|
112
|
+
exit: sharedExit,
|
|
113
|
+
fetch: sharedFetch,
|
|
114
|
+
captureAndRenderSnapshot: sharedSnapshot,
|
|
115
|
+
};
|
|
116
|
+
return { newDeps, driveDeps, passthroughDeps, viewDeps };
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Build the full `SpawnAndAttachDependencies` bundle from the child
|
|
120
|
+
* deps. Exposed so callers that already have child deps (e.g. tests)
|
|
121
|
+
* can opt into the default `releaseAgent` / `onSignal` wiring without
|
|
122
|
+
* re-implementing it.
|
|
123
|
+
*/
|
|
124
|
+
export function buildSpawnAndAttachDeps(childDeps = buildDefaultAttachChildDeps()) {
|
|
125
|
+
return {
|
|
126
|
+
newDeps: childDeps.newDeps,
|
|
127
|
+
driveDeps: childDeps.driveDeps,
|
|
128
|
+
passthroughDeps: childDeps.passthroughDeps,
|
|
129
|
+
viewDeps: childDeps.viewDeps,
|
|
130
|
+
releaseAgent: (conn, name, fetchFn) => releaseAgent(conn, name, fetchFn),
|
|
131
|
+
onSignal: childDeps.driveDeps.onSignal,
|
|
132
|
+
log: childDeps.driveDeps.log,
|
|
133
|
+
error: childDeps.driveDeps.error,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
function buildSpawnBody(options) {
|
|
137
|
+
const channels = options.channels
|
|
138
|
+
?.split(',')
|
|
139
|
+
.map((c) => c.trim())
|
|
140
|
+
.filter((c) => c.length > 0);
|
|
141
|
+
return {
|
|
142
|
+
name: options.name,
|
|
143
|
+
cli: options.cli,
|
|
144
|
+
...(options.args && options.args.length > 0 ? { args: options.args } : {}),
|
|
145
|
+
...(options.task !== undefined ? { task: options.task } : {}),
|
|
146
|
+
...(channels && channels.length > 0 ? { channels } : {}),
|
|
147
|
+
...(options.cwd !== undefined ? { cwd: options.cwd } : {}),
|
|
148
|
+
...(options.team !== undefined ? { team: options.team } : {}),
|
|
149
|
+
...(options.model !== undefined ? { model: options.model } : {}),
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Spawn an agent and immediately attach to it via the chosen session
|
|
154
|
+
* verb. Single code path for both `new -n NAME CLI --attach …` and the
|
|
155
|
+
* verbless `-n NAME CLI` alias.
|
|
156
|
+
*
|
|
157
|
+
* Returns the exit code the CLI should propagate.
|
|
158
|
+
*/
|
|
159
|
+
export async function runSpawnAndAttach(options, deps) {
|
|
160
|
+
const name = options.name?.trim();
|
|
161
|
+
if (!name) {
|
|
162
|
+
deps.error('Error: agent name is required');
|
|
163
|
+
return 1;
|
|
164
|
+
}
|
|
165
|
+
const cli = options.cli?.trim();
|
|
166
|
+
if (!cli) {
|
|
167
|
+
deps.error(`Error: CLI is required, e.g. \`agent-relay new ${name} claude --attach\``);
|
|
168
|
+
return 1;
|
|
169
|
+
}
|
|
170
|
+
const mode = options.mode ?? 'drive';
|
|
171
|
+
if (mode !== 'view' && mode !== 'drive' && mode !== 'passthrough') {
|
|
172
|
+
deps.error(`Error: --mode must be one of view|drive|passthrough (got '${String(options.mode)}')`);
|
|
173
|
+
return 1;
|
|
174
|
+
}
|
|
175
|
+
// Resolve the broker connection once. All three steps (spawn, attach,
|
|
176
|
+
// ephemeral teardown) need it and we don't want the file/env to be
|
|
177
|
+
// re-read between them.
|
|
178
|
+
const connection = resolveBrokerConnection(options, deps.newDeps);
|
|
179
|
+
if (!connection) {
|
|
180
|
+
deps.error('Error: could not locate broker connection. Pass --broker-url, set RELAY_BROKER_URL, ' +
|
|
181
|
+
'or run from a directory containing .agent-relay/connection.json.');
|
|
182
|
+
return 1;
|
|
183
|
+
}
|
|
184
|
+
// Step 1: spawn.
|
|
185
|
+
const spawnResult = await spawnAgent(connection, buildSpawnBody({ ...options, name, cli }), deps.newDeps.fetch);
|
|
186
|
+
if (!spawnResult.ok) {
|
|
187
|
+
deps.error(`Error: could not spawn '${name}': ${spawnResult.message ?? 'unknown error'}`);
|
|
188
|
+
return 1;
|
|
189
|
+
}
|
|
190
|
+
deps.log(`Spawned agent: ${name}`);
|
|
191
|
+
// Step 2: register --ephemeral teardown BEFORE attach. The attach
|
|
192
|
+
// call blocks until detach, so signal handlers wired here are what
|
|
193
|
+
// fire on Ctrl+C / SIGTERM mid-session. The handlers are idempotent
|
|
194
|
+
// (best-effort releaseAgent → if it 404s, fine; the agent is gone).
|
|
195
|
+
const fireEphemeralRelease = async () => {
|
|
196
|
+
try {
|
|
197
|
+
const result = await deps.releaseAgent(connection, name, deps.newDeps.fetch);
|
|
198
|
+
if (!result.ok && result.status !== 404) {
|
|
199
|
+
deps.log(`[attach] ephemeral release of '${name}' returned ${result.status}: ${result.message ?? 'unknown'}`);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
catch (err) {
|
|
203
|
+
// Never let teardown noise drown out whatever the user is trying to read.
|
|
204
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
205
|
+
deps.log(`[attach] ephemeral release of '${name}' threw: ${message}`);
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
if (options.ephemeral) {
|
|
209
|
+
// Signal-based teardowns: in addition to the attach-runner's own
|
|
210
|
+
// SIGINT handler (which detaches cleanly), we want the ephemeral
|
|
211
|
+
// delete to also fire. The attach client closes the WS first and
|
|
212
|
+
// then we follow up with the DELETE.
|
|
213
|
+
deps.onSignal('SIGINT', () => fireEphemeralRelease());
|
|
214
|
+
deps.onSignal('SIGTERM', () => fireEphemeralRelease());
|
|
215
|
+
}
|
|
216
|
+
// Step 3: attach via the chosen mode runner. Inherit the same
|
|
217
|
+
// connection-resolution flags so the attach runner doesn't go re-read
|
|
218
|
+
// disk and get a different answer.
|
|
219
|
+
const attachOptions = {
|
|
220
|
+
brokerUrl: connection.url,
|
|
221
|
+
apiKey: connection.apiKey,
|
|
222
|
+
// Intentionally NOT passing stateDir — once we have a resolved URL
|
|
223
|
+
// we want the attach client to use it directly, not fall back to
|
|
224
|
+
// disk on a transient flag-parsing accident.
|
|
225
|
+
};
|
|
226
|
+
let attachCode = 0;
|
|
227
|
+
try {
|
|
228
|
+
switch (mode) {
|
|
229
|
+
case 'drive':
|
|
230
|
+
attachCode = await runDriveSession(name, attachOptions, deps.driveDeps);
|
|
231
|
+
break;
|
|
232
|
+
case 'passthrough':
|
|
233
|
+
attachCode = await runPassthroughSession(name, attachOptions, deps.passthroughDeps);
|
|
234
|
+
break;
|
|
235
|
+
case 'view':
|
|
236
|
+
attachCode = await runViewSession(name, attachOptions, deps.viewDeps);
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
finally {
|
|
241
|
+
// Step 4: ephemeral teardown after clean detach. The attach runner
|
|
242
|
+
// returned (clean or otherwise); release the agent so the client's
|
|
243
|
+
// exit also ends the agent. Signal-path teardowns above are
|
|
244
|
+
// additive — `fireEphemeralRelease` is idempotent (broker returns
|
|
245
|
+
// 404 the second time, which we swallow).
|
|
246
|
+
if (options.ephemeral) {
|
|
247
|
+
await fireEphemeralRelease();
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return attachCode;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Tiny standalone entry point for the verbless `-n NAME CLI` shorthand
|
|
254
|
+
* dispatcher in `bootstrap.ts`. Hands off to `runSpawnAndAttach` with
|
|
255
|
+
* the shorthand's hardcoded preset (`--mode passthrough`, `--ephemeral`).
|
|
256
|
+
*/
|
|
257
|
+
export async function runVerblessAliasDispatch(parsedArgs, childDeps = buildDefaultAttachChildDeps()) {
|
|
258
|
+
return runSpawnAndAttach({
|
|
259
|
+
name: parsedArgs.name,
|
|
260
|
+
cli: parsedArgs.cli,
|
|
261
|
+
args: parsedArgs.args,
|
|
262
|
+
mode: 'passthrough',
|
|
263
|
+
ephemeral: true,
|
|
264
|
+
}, buildSpawnAndAttachDeps(childDeps));
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Pre-parse `argv.slice(2)` to detect the `-n NAME CLI [args...]`
|
|
268
|
+
* shorthand. Returns the parsed shape when the arguments unambiguously
|
|
269
|
+
* fit the shorthand, or `null` to let Commander parse normally.
|
|
270
|
+
*
|
|
271
|
+
* Recognised forms:
|
|
272
|
+
*
|
|
273
|
+
* agent-relay -n NAME CLI [args...]
|
|
274
|
+
* agent-relay --name NAME CLI [args...]
|
|
275
|
+
* agent-relay -nNAME CLI [args...] (joined short flag)
|
|
276
|
+
* agent-relay --name=NAME CLI [args...] (equals form)
|
|
277
|
+
*
|
|
278
|
+
* Rejected (returns null — fall through to Commander):
|
|
279
|
+
* - any of the registered subcommand names ('view', 'drive', etc.)
|
|
280
|
+
* appears as the first non-flag token, even after `-n`
|
|
281
|
+
* - `-h`/`--help`/`-V`/`--version` present
|
|
282
|
+
* - `-n` without a CLI positional
|
|
283
|
+
*
|
|
284
|
+
* Exported for unit testing alongside the byte-equivalence test that
|
|
285
|
+
* proves the shorthand parse matches what `new NAME CLI --attach --mode passthrough --ephemeral`
|
|
286
|
+
* decomposes into at the action layer.
|
|
287
|
+
*/
|
|
288
|
+
export function parseVerblessAlias(args, knownVerbs) {
|
|
289
|
+
if (args.length === 0)
|
|
290
|
+
return null;
|
|
291
|
+
// Bail on help/version — let commander show its built-in output.
|
|
292
|
+
for (const token of args) {
|
|
293
|
+
if (token === '-h' || token === '--help' || token === '-V' || token === '--version') {
|
|
294
|
+
return null;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
let name = null;
|
|
298
|
+
let i = 0;
|
|
299
|
+
while (i < args.length) {
|
|
300
|
+
const token = args[i];
|
|
301
|
+
if (token === '-n' || token === '--name') {
|
|
302
|
+
if (i + 1 >= args.length)
|
|
303
|
+
return null;
|
|
304
|
+
name = args[i + 1];
|
|
305
|
+
// Splice out the flag + value and restart from the same index.
|
|
306
|
+
args = [...args.slice(0, i), ...args.slice(i + 2)];
|
|
307
|
+
continue;
|
|
308
|
+
}
|
|
309
|
+
if (token.startsWith('-n') && token.length > 2 && !token.startsWith('--')) {
|
|
310
|
+
name = token.slice(2);
|
|
311
|
+
args = [...args.slice(0, i), ...args.slice(i + 1)];
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
if (token.startsWith('--name=')) {
|
|
315
|
+
name = token.slice('--name='.length);
|
|
316
|
+
args = [...args.slice(0, i), ...args.slice(i + 1)];
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
i += 1;
|
|
320
|
+
}
|
|
321
|
+
if (!name || name.trim() === '')
|
|
322
|
+
return null;
|
|
323
|
+
if (args.length === 0)
|
|
324
|
+
return null;
|
|
325
|
+
// The first remaining positional must NOT be one of the known verbs
|
|
326
|
+
// — if it is, the user invoked e.g. `agent-relay -n foo drive bar`
|
|
327
|
+
// which we can't sanely route. Let commander show the error.
|
|
328
|
+
const cli = args[0];
|
|
329
|
+
if (knownVerbs.has(cli))
|
|
330
|
+
return null;
|
|
331
|
+
const rest = args.slice(1);
|
|
332
|
+
return { name: name.trim(), cli, args: rest };
|
|
333
|
+
}
|
|
334
|
+
//# sourceMappingURL=spawn-and-attach.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"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IACnE,6DAA6D;IAC7D,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,IAAI,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IACrC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAE3B,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AAChD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pricing.d.ts","sourceRoot":"","sources":["../../../src/cost/pricing.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;CACtB;AAKD,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"pricing.d.ts","sourceRoot":"","sources":["../../../src/cost/pricing.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;CACtB;AAKD,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CA6CtD,CAAC;AAGF,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAwB,CAAC;AAO9E;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAqCpD;AAED,wBAAgB,0BAA0B,CAAC,UAAU,EAAE,MAAM,GAAG,aAAa,CAW5E;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,CAY7F"}
|
package/dist/src/cost/pricing.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DefaultModels } from '@agent-relay/config';
|
|
2
2
|
// Per-1M token pricing. Model IDs match @agent-relay/config cli-registry.
|
|
3
3
|
// Pricing is approximate and should be updated as providers change rates.
|
|
4
|
-
// Last verified: 2026-
|
|
4
|
+
// Last verified: 2026-05-15
|
|
5
5
|
export const MODEL_PRICING = {
|
|
6
6
|
// ── Anthropic (Claude Code, Cursor, Droid) ──────────────────────
|
|
7
7
|
sonnet: { inputPer1M: 3, outputPer1M: 15 },
|
|
@@ -18,7 +18,8 @@ export const MODEL_PRICING = {
|
|
|
18
18
|
'sonnet-4.5-thinking': { inputPer1M: 3, outputPer1M: 15 },
|
|
19
19
|
'haiku-4.5': { inputPer1M: 0.8, outputPer1M: 4 },
|
|
20
20
|
// ── OpenAI (Codex, Cursor, OpenCode) ────────────────────────────
|
|
21
|
-
'gpt-5.
|
|
21
|
+
'gpt-5.5': { inputPer1M: 5, outputPer1M: 30 },
|
|
22
|
+
'gpt-5.4': { inputPer1M: 2.5, outputPer1M: 15 },
|
|
22
23
|
'gpt-5.3-codex': { inputPer1M: 2.5, outputPer1M: 10 },
|
|
23
24
|
'gpt-5.3-codex-spark': { inputPer1M: 1.5, outputPer1M: 6 },
|
|
24
25
|
'gpt-5.2-codex': { inputPer1M: 2.5, outputPer1M: 10 },
|
|
@@ -26,7 +27,8 @@ export const MODEL_PRICING = {
|
|
|
26
27
|
'gpt-5.1-codex-max': { inputPer1M: 2.5, outputPer1M: 10 },
|
|
27
28
|
'gpt-5.1-codex-mini': { inputPer1M: 0.75, outputPer1M: 3 },
|
|
28
29
|
'openai/gpt-5.2': { inputPer1M: 2.5, outputPer1M: 10 },
|
|
29
|
-
'openai/gpt-5.4': { inputPer1M: 2.5, outputPer1M:
|
|
30
|
+
'openai/gpt-5.4': { inputPer1M: 2.5, outputPer1M: 15 },
|
|
31
|
+
'openai/gpt-5.5': { inputPer1M: 5, outputPer1M: 30 },
|
|
30
32
|
'openai/o3': { inputPer1M: 1, outputPer1M: 4 },
|
|
31
33
|
'openai/o3-mini': { inputPer1M: 0.55, outputPer1M: 2.2 },
|
|
32
34
|
'openai/o4-mini': { inputPer1M: 0.55, outputPer1M: 2.2 },
|