@dsh-enhanced/assistant-actions 0.1.30

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/LICENSE +21 -0
  2. package/README.md +247 -0
  3. package/cordis.patch.yml +3 -0
  4. package/lib/broker-cli.d.ts +70 -0
  5. package/lib/broker-cli.d.ts.map +1 -0
  6. package/lib/broker-cli.js +255 -0
  7. package/lib/broker-cli.js.map +1 -0
  8. package/lib/broker-client.d.ts +54 -0
  9. package/lib/broker-client.d.ts.map +1 -0
  10. package/lib/broker-client.js +266 -0
  11. package/lib/broker-client.js.map +1 -0
  12. package/lib/broker-core.d.ts +51 -0
  13. package/lib/broker-core.d.ts.map +1 -0
  14. package/lib/broker-core.js +441 -0
  15. package/lib/broker-core.js.map +1 -0
  16. package/lib/broker-ledger.d.ts +131 -0
  17. package/lib/broker-ledger.d.ts.map +1 -0
  18. package/lib/broker-ledger.js +925 -0
  19. package/lib/broker-ledger.js.map +1 -0
  20. package/lib/broker-peer-linux.d.ts +23 -0
  21. package/lib/broker-peer-linux.d.ts.map +1 -0
  22. package/lib/broker-peer-linux.js +68 -0
  23. package/lib/broker-peer-linux.js.map +1 -0
  24. package/lib/broker-protocol.d.ts +419 -0
  25. package/lib/broker-protocol.d.ts.map +1 -0
  26. package/lib/broker-protocol.js +786 -0
  27. package/lib/broker-protocol.js.map +1 -0
  28. package/lib/broker-server.d.ts +77 -0
  29. package/lib/broker-server.d.ts.map +1 -0
  30. package/lib/broker-server.js +467 -0
  31. package/lib/broker-server.js.map +1 -0
  32. package/lib/cli.d.ts +3 -0
  33. package/lib/cli.d.ts.map +1 -0
  34. package/lib/cli.js +36 -0
  35. package/lib/cli.js.map +1 -0
  36. package/lib/config.d.ts +54 -0
  37. package/lib/config.d.ts.map +1 -0
  38. package/lib/config.js +165 -0
  39. package/lib/config.js.map +1 -0
  40. package/lib/external-delivery-receipt.d.ts +11 -0
  41. package/lib/external-delivery-receipt.d.ts.map +1 -0
  42. package/lib/external-delivery-receipt.js +25 -0
  43. package/lib/external-delivery-receipt.js.map +1 -0
  44. package/lib/github.d.ts +78 -0
  45. package/lib/github.d.ts.map +1 -0
  46. package/lib/github.js +611 -0
  47. package/lib/github.js.map +1 -0
  48. package/lib/index.d.ts +19 -0
  49. package/lib/index.d.ts.map +1 -0
  50. package/lib/index.js +23 -0
  51. package/lib/index.js.map +1 -0
  52. package/lib/ledger.d.ts +78 -0
  53. package/lib/ledger.d.ts.map +1 -0
  54. package/lib/ledger.js +1064 -0
  55. package/lib/ledger.js.map +1 -0
  56. package/lib/repository-readback.d.ts +34 -0
  57. package/lib/repository-readback.d.ts.map +1 -0
  58. package/lib/repository-readback.js +193 -0
  59. package/lib/repository-readback.js.map +1 -0
  60. package/lib/service.d.ts +86 -0
  61. package/lib/service.d.ts.map +1 -0
  62. package/lib/service.js +1259 -0
  63. package/lib/service.js.map +1 -0
  64. package/lib/types.d.ts +174 -0
  65. package/lib/types.d.ts.map +1 -0
  66. package/lib/types.js +2 -0
  67. package/lib/types.js.map +1 -0
  68. package/lib/verified-delivery.d.ts +104 -0
  69. package/lib/verified-delivery.d.ts.map +1 -0
  70. package/lib/verified-delivery.js +262 -0
  71. package/lib/verified-delivery.js.map +1 -0
  72. package/lib/version.d.ts +2 -0
  73. package/lib/version.d.ts.map +1 -0
  74. package/lib/version.js +2 -0
  75. package/lib/version.js.map +1 -0
  76. package/package.json +123 -0
@@ -0,0 +1,255 @@
1
+ #!/usr/bin/env node
2
+ import { createPrivateKey, createPublicKey } from 'node:crypto';
3
+ import { constants } from 'node:fs';
4
+ import { lstat, open, realpath } from 'node:fs/promises';
5
+ import { pathToFileURL } from 'node:url';
6
+ import { dirname, isAbsolute, resolve } from 'node:path';
7
+ import { requestGitHubBrokerAdmin } from './broker-client.js';
8
+ import { createExternalBrokerCore, normalizeExternalBrokerCoreConfig } from './broker-core.js';
9
+ import { inspectLinuxPeerCredentials, linuxPeerCredentialsAvailable } from './broker-peer-linux.js';
10
+ import { startGitHubBrokerServer } from './broker-server.js';
11
+ const DIGEST = /^[0-9a-f]{64}$/u;
12
+ const IDENTIFIER = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/u;
13
+ const STOP_REASONS = new Set(['operator-request', 'security-response', 'maintenance']);
14
+ const REVOKE_REASONS = new Set(['operator-request', 'security-response', 'grant-replaced', 'grant-expired']);
15
+ const FAILURE = 'assistant-actions broker: command failed or invalid arguments\n';
16
+ function plain(value) {
17
+ return value !== null && typeof value === 'object' && !Array.isArray(value) && Object.getPrototypeOf(value) === Object.prototype;
18
+ }
19
+ function integer(value, minimum = 0, maximum = Number.MAX_SAFE_INTEGER) {
20
+ return typeof value === 'number' && Number.isSafeInteger(value) && value >= minimum && value <= maximum;
21
+ }
22
+ function canonicalPath(value) {
23
+ return typeof value === 'string' && isAbsolute(value) && resolve(value) === value && value !== '/' && !value.includes('\0');
24
+ }
25
+ function exact(input, allowed, required) {
26
+ if (Object.keys(input).some(key => !allowed.includes(key)) || required.some(key => !Object.hasOwn(input, key)))
27
+ throw new Error('invalid config');
28
+ }
29
+ async function privateFile(path, mode = 0o600, maximumBytes = 2 * 1024 * 1024) {
30
+ const currentUid = BigInt(process.getuid?.() ?? -1), currentGid = BigInt(process.getgid?.() ?? -1), parentPath = resolve(path, '..');
31
+ await safeAncestorChain(parentPath, Number(currentUid), Number(currentGid), true);
32
+ const [canonicalParent, parent] = await Promise.all([realpath(parentPath), lstat(parentPath, { bigint: true })]);
33
+ if (canonicalParent !== parentPath || parent.isSymbolicLink() || !parent.isDirectory() || parent.uid !== currentUid || parent.gid !== currentGid || Number(parent.mode & 63n) !== 0)
34
+ throw new Error('unsafe private file parent');
35
+ const descriptor = await open(path, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
36
+ try {
37
+ const before = await descriptor.stat({ bigint: true });
38
+ if (!before.isFile() || before.nlink !== 1n || before.size > BigInt(maximumBytes) || Number(before.mode & 4095n) !== mode || before.uid !== currentUid || before.gid !== currentGid)
39
+ throw new Error('unsafe private file');
40
+ const value = await descriptor.readFile();
41
+ const [after, linked] = await Promise.all([descriptor.stat({ bigint: true }), lstat(path, { bigint: true })]);
42
+ if (before.dev !== after.dev || before.ino !== after.ino || before.size !== after.size || before.mtimeNs !== after.mtimeNs || after.dev !== linked.dev || after.ino !== linked.ino || linked.isSymbolicLink())
43
+ throw new Error('private file changed');
44
+ return value;
45
+ }
46
+ finally {
47
+ await descriptor.close();
48
+ }
49
+ }
50
+ async function safeAncestorChain(path, expectedLeafUid, expectedLeafGid, privateLeaf) {
51
+ let cursor = path, leaf = true;
52
+ for (;;) {
53
+ const [canonical, stat] = await Promise.all([realpath(cursor), lstat(cursor, { bigint: true })]);
54
+ const mode = Number(stat.mode & 4095n), uid = Number(stat.uid), gid = Number(stat.gid);
55
+ const stickyRoot = uid === 0 && (mode & 0o1000) !== 0 && (mode & 0o022) !== 0;
56
+ if (canonical !== cursor || stat.isSymbolicLink() || !stat.isDirectory() || !stickyRoot && (mode & 0o022) !== 0
57
+ || leaf && privateLeaf && (uid !== expectedLeafUid || gid !== expectedLeafGid || (mode & 0o077) !== 0))
58
+ throw new Error('unsafe path ancestry');
59
+ const parent = dirname(cursor);
60
+ if (parent === cursor)
61
+ return;
62
+ cursor = parent;
63
+ leaf = false;
64
+ }
65
+ }
66
+ function normalizedConfig(value, serve) {
67
+ if (!plain(value))
68
+ throw new Error('invalid config');
69
+ const operator = ['adminSocketPath', 'brokerId', 'minimumBrokerGeneration', 'brokerPublicKeyPath', 'adminKeyId', 'adminPrivateKeyPath', 'adminInstanceId', 'adminGeneration', 'expectedAdminSocketUid', 'expectedAdminSocketGid', 'expectedAdminSocketMode', 'expectedAdminParentUid', 'expectedAdminParentGid', 'expectedAdminParentMode', 'expectedBrokerPeerUid', 'expectedBrokerPeerGid', 'requestTimeoutMs', 'helloTtlMs'];
70
+ const daemon = ['actionSocketPath', 'adminSocketPath', 'brokerId', 'minimumBrokerGeneration', 'serverPrivateKeyPath', 'clientKeyId', 'clientPublicKeyPath', 'adminKeyId', 'adminPublicKeyPath', 'statePath', 'expectedClientPeerUid', 'expectedClientPeerGid', 'expectedAdminPeerUid', 'expectedAdminPeerGid', 'expectedActionSocketUid', 'expectedActionSocketGid', 'expectedActionParentMode', 'expectedActionSocketMode', 'expectedAdminSocketUid', 'expectedAdminSocketGid', 'expectedAdminParentMode', 'expectedAdminSocketMode', 'maxActionConnections', 'maxAdminConnections', 'maxConcurrentRequests', 'requestTimeoutMs', 'helloTtlMs', 'drainTimeoutMs', 'credentials', 'grants', 'policyEpoch', 'controllerTtlMs', 'credentialMaxBytes'];
71
+ exact(value, serve ? daemon : operator, serve ? daemon.filter(key => key !== 'controllerTtlMs' && key !== 'credentialMaxBytes') : operator);
72
+ if (!IDENTIFIER.test(String(value.brokerId)) || !integer(value.minimumBrokerGeneration, 1) || !integer(value.requestTimeoutMs, 1, 300_000) || !integer(value.helloTtlMs, 1, 300_000))
73
+ throw new Error('invalid config');
74
+ if (!serve && (!canonicalPath(value.adminSocketPath) || Buffer.byteLength(value.adminSocketPath) > 100 || !canonicalPath(value.brokerPublicKeyPath)
75
+ || !IDENTIFIER.test(String(value.adminKeyId)) || !canonicalPath(value.adminPrivateKeyPath) || !IDENTIFIER.test(String(value.adminInstanceId)) || !integer(value.adminGeneration, 1)
76
+ || !integer(value.expectedAdminSocketUid, 0, 0x7fffffff) || !integer(value.expectedAdminSocketGid, 0, 0x7fffffff) || !integer(value.expectedAdminSocketMode, 0, 0o777)
77
+ || !integer(value.expectedAdminParentUid, 0, 0x7fffffff) || !integer(value.expectedAdminParentGid, 0, 0x7fffffff) || !integer(value.expectedAdminParentMode, 0, 0o777)
78
+ || !integer(value.expectedBrokerPeerUid, 0, 0x7fffffff) || !integer(value.expectedBrokerPeerGid, 0, 0x7fffffff)))
79
+ throw new Error('invalid operator config');
80
+ if (serve && (!canonicalPath(value.serverPrivateKeyPath) || !IDENTIFIER.test(String(value.clientKeyId)) || !canonicalPath(value.clientPublicKeyPath) || !canonicalPath(value.adminPublicKeyPath)
81
+ || !IDENTIFIER.test(String(value.adminKeyId)) || value.clientKeyId === value.adminKeyId || value.clientPublicKeyPath === value.adminPublicKeyPath
82
+ || value.serverPrivateKeyPath === value.clientPublicKeyPath || value.serverPrivateKeyPath === value.adminPublicKeyPath
83
+ || !canonicalPath(value.actionSocketPath) || !canonicalPath(value.adminSocketPath) || value.actionSocketPath === value.adminSocketPath || Buffer.byteLength(value.actionSocketPath) > 100 || Buffer.byteLength(value.adminSocketPath) > 100
84
+ || !canonicalPath(value.statePath) || !integer(value.expectedClientPeerUid, 0, 0x7fffffff) || !integer(value.expectedClientPeerGid, 0, 0x7fffffff)
85
+ || !integer(value.expectedAdminPeerUid, 0, 0x7fffffff) || !integer(value.expectedAdminPeerGid, 0, 0x7fffffff)
86
+ || !integer(value.expectedActionSocketUid, 0, 0x7fffffff) || !integer(value.expectedActionSocketGid, 0, 0x7fffffff) || !integer(value.expectedActionParentMode, 0, 0o777) || !integer(value.expectedActionSocketMode, 0, 0o777)
87
+ || !integer(value.expectedAdminSocketUid, 0, 0x7fffffff) || !integer(value.expectedAdminSocketGid, 0, 0x7fffffff) || !integer(value.expectedAdminParentMode, 0, 0o777) || !integer(value.expectedAdminSocketMode, 0, 0o777)
88
+ || !integer(value.maxActionConnections, 1, 1_024) || !integer(value.maxAdminConnections, 1, 64) || !integer(value.maxConcurrentRequests, 1, value.maxActionConnections)
89
+ || !integer(value.drainTimeoutMs, 1, 300_000) || !Array.isArray(value.credentials) || !Array.isArray(value.grants) || !integer(value.policyEpoch, 0)
90
+ || value.controllerTtlMs !== undefined && !integer(value.controllerTtlMs, 1_000, 300_000)
91
+ || value.credentialMaxBytes !== undefined && !integer(value.credentialMaxBytes, 1, 65_536)))
92
+ throw new Error('invalid serve config');
93
+ return Object.freeze({ ...value });
94
+ }
95
+ export async function loadBrokerCliConfig(path, serve = false) {
96
+ if (!canonicalPath(path))
97
+ throw new Error('invalid config path');
98
+ const bytes = await privateFile(path);
99
+ const source = bytes.toString('utf8');
100
+ if (!Buffer.from(source, 'utf8').equals(bytes))
101
+ throw new Error('invalid config UTF-8');
102
+ let parsed;
103
+ try {
104
+ parsed = JSON.parse(source);
105
+ }
106
+ catch {
107
+ throw new Error('invalid config JSON');
108
+ }
109
+ return normalizedConfig(parsed, serve);
110
+ }
111
+ function positive(value) {
112
+ if (!value || !/^[1-9][0-9]*$/u.test(value))
113
+ throw new Error('positive integer required');
114
+ const result = Number(value);
115
+ if (!Number.isSafeInteger(result))
116
+ throw new Error('positive integer required');
117
+ return result;
118
+ }
119
+ function epoch(value) {
120
+ if (!value || !/^(?:0|[1-9][0-9]*)$/u.test(value))
121
+ throw new Error('non-negative integer required');
122
+ const result = Number(value);
123
+ if (!Number.isSafeInteger(result))
124
+ throw new Error('non-negative integer required');
125
+ return result;
126
+ }
127
+ function adminIntent(command, args, now, timeoutMs) {
128
+ const deadline = now + timeoutMs;
129
+ if (!Number.isSafeInteger(deadline))
130
+ throw new Error('deadline overflow');
131
+ if (command === 'status' && args.length === 0)
132
+ return { operation: 'status', body: {}, deadline };
133
+ if (command === 'stop' && (args.length === 1 || args.length === 2)) {
134
+ const reason = args[1] ?? 'operator-request';
135
+ if (!STOP_REASONS.has(reason))
136
+ throw new Error('invalid stop reason');
137
+ return { operation: 'stop', body: { expectedControlVersion: epoch(args[0]), drainDeadline: deadline, reason: reason }, deadline };
138
+ }
139
+ if (command === 'resume' && args.length === 2)
140
+ return { operation: 'resume', body: { expectedControlVersion: epoch(args[0]), expectedGeneration: positive(args[1]) }, deadline };
141
+ if (command === 'revoke' && (args.length === 6 || args.length === 7)) {
142
+ const reason = args[6] ?? 'operator-request';
143
+ if (!IDENTIFIER.test(args[1] ?? '') || !DIGEST.test(args[3] ?? '') || !REVOKE_REASONS.has(reason))
144
+ throw new Error('invalid revoke arguments');
145
+ return { operation: 'revoke', body: { expectedControlVersion: epoch(args[0]), grantId: args[1], grantRevision: positive(args[2]), grantDigest: args[3], policyEpoch: epoch(args[4]), emergencyEpoch: epoch(args[5]), reason: reason }, deadline };
146
+ }
147
+ throw new Error('invalid command');
148
+ }
149
+ async function key(path, kind) {
150
+ const bytes = await privateFile(path);
151
+ try {
152
+ const result = kind === 'private' ? createPrivateKey(bytes) : createPublicKey(bytes);
153
+ if (result.type !== kind || result.asymmetricKeyType !== 'ed25519')
154
+ throw new Error('Ed25519 key required');
155
+ return result;
156
+ }
157
+ finally {
158
+ bytes.fill(0);
159
+ }
160
+ }
161
+ function safeOutput(response) {
162
+ return JSON.stringify({ status: response.status, state: response.state, ...(response.error === null ? {} : { error: response.error }) }) + '\n';
163
+ }
164
+ async function admin(command, config, args) {
165
+ if (!config.adminPrivateKeyPath || !config.adminKeyId || !config.adminInstanceId || !config.adminGeneration)
166
+ throw new Error('operator credentials required');
167
+ const [serverPublicKey, adminPrivateKey] = await Promise.all([key(config.brokerPublicKeyPath, 'public'), key(config.adminPrivateKeyPath, 'private')]);
168
+ const intent = adminIntent(command, args, Date.now(), config.requestTimeoutMs);
169
+ return await requestGitHubBrokerAdmin({
170
+ socketPath: config.adminSocketPath, serverPublicKey, timeoutMs: config.requestTimeoutMs, maxHelloTtlMs: config.helloTtlMs, expectedSocketUid: config.expectedAdminSocketUid, expectedSocketGid: config.expectedAdminSocketGid,
171
+ expectedSocketMode: config.expectedAdminSocketMode, expectedSocketParentUid: config.expectedAdminParentUid, expectedSocketParentGid: config.expectedAdminParentGid, expectedSocketParentMode: config.expectedAdminParentMode,
172
+ inspectPeerCredentials: inspectLinuxPeerCredentials, expectedBrokerPeerUid: config.expectedBrokerPeerUid, expectedBrokerPeerGid: config.expectedBrokerPeerGid,
173
+ expectedServerInstanceId: config.brokerId, minimumServerGeneration: config.minimumBrokerGeneration,
174
+ }, intent, { kind: 'assistant-actions-admin', instanceId: config.adminInstanceId, generation: config.adminGeneration }, config.adminKeyId, adminPrivateKey);
175
+ }
176
+ function productionCore(config) {
177
+ return createExternalBrokerCore(normalizeExternalBrokerCoreConfig({ instanceId: config.brokerId, statePath: config.statePath, credentials: config.credentials, grants: config.grants, policyEpoch: config.policyEpoch,
178
+ ...(config.controllerTtlMs === undefined ? {} : { controllerTtlMs: config.controllerTtlMs }),
179
+ ...(config.credentialMaxBytes === undefined ? {} : { credentialMaxBytes: config.credentialMaxBytes }) }));
180
+ }
181
+ async function serve(config, dependencies) {
182
+ const createCore = dependencies.createCore ?? productionCore;
183
+ const available = dependencies.peerCredentialsAvailable?.() ?? (dependencies.peerInspector === undefined && linuxPeerCredentialsAvailable());
184
+ if (!available && dependencies.peerInspector === undefined)
185
+ throw new Error('Linux peer credentials unavailable');
186
+ const peer = dependencies.peerInspector ?? inspectLinuxPeerCredentials;
187
+ const [serverPrivateKey, clientPublicKey, adminPublicKey] = await Promise.all([key(config.serverPrivateKeyPath, 'private'), key(config.clientPublicKeyPath, 'public'), key(config.adminPublicKeyPath, 'public')]);
188
+ const serverPublicKey = createPublicKey(serverPrivateKey);
189
+ if (config.clientKeyId === config.adminKeyId || serverPublicKey.equals(clientPublicKey) || serverPublicKey.equals(adminPublicKey) || clientPublicKey.equals(adminPublicKey))
190
+ throw new Error('broker signing keys must be distinct');
191
+ const core = await createCore(config);
192
+ let server;
193
+ try {
194
+ const generation = core.snapshot().generation;
195
+ if (!integer(generation, config.minimumBrokerGeneration, Number.MAX_SAFE_INTEGER))
196
+ throw new Error('broker generation regressed');
197
+ const options = {
198
+ actionSocketPath: config.actionSocketPath, adminSocketPath: config.adminSocketPath, instanceId: config.brokerId, generation, serverPrivateKey, clientPublicKey, clientKeyId: config.clientKeyId,
199
+ adminPublicKey, adminKeyId: config.adminKeyId, core, inspectPeerCredentials: peer,
200
+ expectedClientPeerUid: config.expectedClientPeerUid, expectedClientPeerGid: config.expectedClientPeerGid, expectedAdminPeerUid: config.expectedAdminPeerUid, expectedAdminPeerGid: config.expectedAdminPeerGid,
201
+ expectedActionSocketUid: config.expectedActionSocketUid, expectedActionSocketGid: config.expectedActionSocketGid, expectedActionParentMode: config.expectedActionParentMode, expectedActionSocketMode: config.expectedActionSocketMode,
202
+ expectedAdminSocketUid: config.expectedAdminSocketUid, expectedAdminSocketGid: config.expectedAdminSocketGid, expectedAdminParentMode: config.expectedAdminParentMode, expectedAdminSocketMode: config.expectedAdminSocketMode,
203
+ maxActionConnections: config.maxActionConnections, maxAdminConnections: config.maxAdminConnections, maxConcurrentRequests: config.maxConcurrentRequests,
204
+ firstByteTimeoutMs: Math.min(2_000, config.requestTimeoutMs), frameTimeoutMs: Math.min(10_000, config.requestTimeoutMs),
205
+ totalTimeoutMs: config.requestTimeoutMs, helloTtlMs: config.helloTtlMs, drainTimeoutMs: config.drainTimeoutMs,
206
+ };
207
+ dependencies.onServerReady?.(options);
208
+ server = await startGitHubBrokerServer(options);
209
+ }
210
+ catch (error) {
211
+ await Promise.resolve(core.close()).catch(() => undefined);
212
+ throw error;
213
+ }
214
+ await new Promise((resolveServe, rejectServe) => {
215
+ let stopping = false;
216
+ const removeSignals = () => { process.off('SIGTERM', onTerm); process.off('SIGINT', onInterrupt); };
217
+ const stop = (reason) => {
218
+ if (stopping)
219
+ return;
220
+ stopping = true;
221
+ removeSignals();
222
+ void server.stop(reason).then(resolveServe, rejectServe);
223
+ };
224
+ const onTerm = () => stop('sigterm');
225
+ const onInterrupt = () => stop('sigint');
226
+ process.once('SIGTERM', onTerm);
227
+ process.once('SIGINT', onInterrupt);
228
+ });
229
+ }
230
+ export async function runBrokerCli(argv, dependencies = {}) {
231
+ const stdout = dependencies.stdout ?? process.stdout, stderr = dependencies.stderr ?? process.stderr;
232
+ try {
233
+ const [command, configPath, ...args] = argv;
234
+ if (!command || !configPath || !['serve', 'status', 'stop', 'resume', 'revoke'].includes(command))
235
+ throw new Error('invalid command');
236
+ const config = await loadBrokerCliConfig(configPath, command === 'serve');
237
+ if (command === 'serve') {
238
+ if (args.length !== 0)
239
+ throw new Error('invalid arguments');
240
+ await serve(config, dependencies);
241
+ return 0;
242
+ }
243
+ const response = await admin(command, config, args);
244
+ stdout.write(safeOutput(response));
245
+ return response.status === 'succeeded' ? 0 : 1;
246
+ }
247
+ catch {
248
+ stderr.write(FAILURE);
249
+ return 1;
250
+ }
251
+ }
252
+ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
253
+ process.exitCode = await runBrokerCli(process.argv.slice(2));
254
+ }
255
+ //# sourceMappingURL=broker-cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"broker-cli.js","sourceRoot":"","sources":["../src/broker-cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAkB,MAAM,aAAa,CAAA;AAC/E,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AACnC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACxD,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAA;AAC7D,OAAO,EAAE,wBAAwB,EAAE,iCAAiC,EAAsC,MAAM,kBAAkB,CAAA;AAElI,OAAO,EAAE,2BAA2B,EAAE,6BAA6B,EAAE,MAAM,wBAAwB,CAAA;AAEnG,OAAO,EAAE,uBAAuB,EAAiG,MAAM,oBAAoB,CAAA;AAE3J,MAAM,MAAM,GAAG,iBAAiB,CAAA;AAChC,MAAM,UAAU,GAAG,sCAAsC,CAAA;AACzD,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,kBAAkB,EAAE,mBAAmB,EAAE,aAAa,CAAC,CAAC,CAAA;AACtF,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,kBAAkB,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,eAAe,CAAC,CAAC,CAAA;AAC5G,MAAM,OAAO,GAAG,iEAAiE,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AAK,CAAC,OAAO,CAAC,CAAC;QAAC,OAAO,CAAC,CAAA;IAAC,CAAC;AAC7C,CAAC;AAED,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAC/E,OAAO,CAAC,QAAQ,GAAG,MAAM,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;AAC9D,CAAC"}
@@ -0,0 +1,54 @@
1
+ import { type Socket } from 'node:net';
2
+ import type { KeyObject } from 'node:crypto';
3
+ import { type BrokerAdminEndpoint, type BrokerAdminIntent, type BrokerAdminResponse, type BrokerClientRequest, type BrokerEndpoint, type BrokerRequestIntent, type BrokerServerHello, type BrokerServerResponse } from './broker-protocol.js';
4
+ type KeyInput = KeyObject | string | Buffer;
5
+ export type BrokerDispatchState = 'not-dispatched' | 'post-dispatch-unknown';
6
+ export type BrokerClientErrorCode = 'invalid-config' | 'socket-invalid' | 'socket-changed' | 'connect-failed' | 'timeout' | 'aborted' | 'authorization-rejected' | 'disconnected' | 'protocol-error';
7
+ export declare class BrokerClientError extends Error {
8
+ readonly code: BrokerClientErrorCode;
9
+ readonly dispatchState: BrokerDispatchState;
10
+ readonly retryable = false;
11
+ constructor(code: BrokerClientErrorCode, dispatchState: BrokerDispatchState, message: string, options?: ErrorOptions);
12
+ get postDispatchUnknown(): boolean;
13
+ }
14
+ export declare class BrokerPostDispatchUnknownError extends BrokerClientError {
15
+ constructor(code: BrokerClientErrorCode, message: string, options?: ErrorOptions);
16
+ }
17
+ export interface GitHubBrokerConnectionOptions {
18
+ socketPath: string;
19
+ serverPublicKey: KeyInput;
20
+ timeoutMs?: number;
21
+ maxHelloTtlMs?: number;
22
+ expectedSocketUid?: number;
23
+ expectedSocketGid?: number;
24
+ expectedSocketMode?: number;
25
+ expectedSocketParentUid?: number;
26
+ expectedSocketParentGid?: number;
27
+ expectedSocketParentMode?: number;
28
+ inspectPeerCredentials?: (socket: Socket, signal: AbortSignal) => {
29
+ uid: number;
30
+ gid: number;
31
+ pid?: number;
32
+ } | undefined | Promise<{
33
+ uid: number;
34
+ gid: number;
35
+ pid?: number;
36
+ } | undefined>;
37
+ expectedBrokerPeerUid: number;
38
+ expectedBrokerPeerGid: number;
39
+ expectedServerInstanceId?: string;
40
+ minimumServerGeneration?: number;
41
+ }
42
+ export interface GitHubBrokerClientOptions extends GitHubBrokerConnectionOptions {
43
+ clientPrivateKey: KeyInput;
44
+ clientKeyId: string;
45
+ source: Extract<BrokerEndpoint, {
46
+ kind: 'assistant-actions-host';
47
+ }>;
48
+ beforeWrite?: (hello: BrokerServerHello, request: BrokerClientRequest, signal: AbortSignal) => void | Promise<void>;
49
+ }
50
+ export declare function requestGitHubBroker(options: GitHubBrokerClientOptions, intent: BrokerRequestIntent, signal?: AbortSignal): Promise<BrokerServerResponse>;
51
+ /** Signed operator control request over the same one-request UDS transport. */
52
+ export declare function requestGitHubBrokerAdmin(options: GitHubBrokerConnectionOptions, intent: BrokerAdminIntent, source: BrokerAdminEndpoint, adminKeyId: string, adminPrivateKey: KeyInput, signal?: AbortSignal): Promise<BrokerAdminResponse>;
53
+ export {};
54
+ //# sourceMappingURL=broker-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"broker-client.d.ts","sourceRoot":"","sources":["../src/broker-client.ts"],"names":[],"mappings":"AACA,OAAO,EAAoB,KAAK,MAAM,EAAE,MAAM,UAAU,CAAA;AAExD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAE5C,OAAO,EAGL,KAAK,mBAAmB,EAAE,KAAK,iBAAiB,EAAE,KAAK,mBAAmB,EAAE,KAAK,mBAAmB,EAAE,KAAK,cAAc,EAAE,KAAK,mBAAmB,EAAE,KAAK,iBAAiB,EAAE,KAAK,oBAAoB,EACvM,MA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olve } from 'node:path';
4
+ import { inspectLinuxPeerCredentials } from './broker-peer-linux.js';
5
+ import { BrokerFrameDecoder, BrokerProtocolError, GITHUB_BROKER_DEFAULT_HELLO_TTL_MS, GITHUB_BROKER_REQUEST_MAX_BYTES, GITHUB_BROKER_RESPONSE_MAX_BYTES, createBrokerAdminRequest, createBrokerClientRequest, encodeBrokerFrame, verifyBrokerAdminResponse, verifyBrokerServerHello, verifyBrokerServerResponse, } from './broker-protocol.js';
6
+ export class BrokerClientError extends Error {
7
+ code;
8
+ dispatchState;
9
+ retryable = false;
10
+ constructor(code, dispatchState, message, options) {
11
+ super(`assistant-actions broker client: ${message}`, options);
12
+ this.name = dispatchState === 'post-dispatch-unknown' ? 'BrokerPostDispatchUnknownError' : 'BrokerClientError';
13
+ this.code = code;
14
+ this.dispatchState = dispatchState;
15
+ }
16
+ get postDispatchUnknown() { return this.dispatchState === 'post-dispatch-unknown'; }
17
+ }
18
+ export class BrokerPostDispatchUnknownError extends BrokerClientError {
19
+ constructor(code, message, options) { super(code, 'post-dispatch-unknown', message, options); }
20
+ }
21
+ function fail(code, dispatched, message, cause) {
22
+ const options = cause === undefined ? undefined : { cause };
23
+ return dispatched ? new BrokerPostDispatchUnknownError(code, message, options) : new BrokerClientError(code, 'not-dispatched', message, options);
24
+ }
25
+ function integer(value, minimum, maximum) { return typeof value === 'number' && Number.isSafeInteger(value) && value >= minimum && value <= maximum; }
26
+ async function inspectSocket(options) {
27
+ const path = options.socketPath;
28
+ if (!isAbsolute(path) || resolve(path) !== path || path === '/')
29
+ throw fail('invalid-config', false, 'canonical absolute socket path required');
30
+ const parentPath = dirname(path);
31
+ let canonical, canonicalParent, stat, after, parent, parentAfter;
32
+ try {
33
+ stat = await lstat(path, { bigint: true });
34
+ parent = await lstat(parentPath, { bigint: true });
35
+ canonical = await realpath(path);
36
+ canonicalParent = await realpath(parentPath);
37
+ after = await lstat(path, { bigint: true });
38
+ parentAfter = await lstat(parentPath, { bigint: true });
39
+ }
40
+ catch (error) {
41
+ throw fail('socket-invalid', false, 'socket cannot be inspected', error);
42
+ }
43
+ if (canonical !== path || stat.isSymbolicLink() || !stat.isSocket() || after.isSymbolicLink() || !after.isSocket()
44
+ || stat.dev !== after.dev || stat.ino !== after.ino || stat.uid !== after.uid || stat.gid !== after.gid || stat.mode !== after.mode)
45
+ throw fail('socket-invalid', false, 'socket path must name one stable canonical Unix socket directly');
46
+ const uid = BigInt(options.expectedSocketUid ?? process.getuid?.() ?? -1);
47
+ const gid = BigInt(options.expectedSocketGid ?? process.getgid?.() ?? -1);
48
+ const mode = options.expectedSocketMode ?? 0o600;
49
+ const parentUid = BigInt(options.expectedSocketParentUid ?? options.expectedSocketUid ?? process.getuid?.() ?? -1);
50
+ const parentGid = BigInt(options.expectedSocketParentGid ?? options.expectedSocketGid ?? process.getgid?.() ?? -1);
51
+ const parentMode = options.expectedSocketParentMode ?? 0o700;
52
+ if (!integer(mode, 0, 0o777) || (mode & 0o007) !== 0 || !integer(parentMode, 0, 0o777) || (parentMode & 0o022) !== 0 || stat.uid !== uid || stat.gid !== gid || Number(stat.mode & 4095n) !== mode
53
+ || canonicalParent !== parentPath || !parent.isDirectory() || parent.isSymbolicLink() || !parentAfter.isDirectory() || parentAfter.isSymbolicLink()
54
+ || parent.dev !== parentAfter.dev || parent.ino !== parentAfter.ino || parent.uid !== parentAfter.uid || parent.gid !== parentAfter.gid || parent.mode !== parentAfter.mode
55
+ || parent.uid !== parentUid || parent.gid !== parentGid || Number(parent.mode & 4095n) !== parentMode)
56
+ throw fail('socket-invalid', false, 'socket or parent ownership and mode do not match the pinned identity');
57
+ return { dev: stat.dev, ino: stat.ino, uid: stat.uid, gid: stat.gid, mode: Number(stat.mode & 4095n), parentDev: parent.dev, parentIno: parent.ino, parentUid: parent.uid, parentGid: parent.gid, parentMode: Number(parent.mode & 4095n) };
58
+ }
59
+ async function assertSameSocket(options, before) {
60
+ let after;
61
+ try {
62
+ after = await inspectSocket(options);
63
+ }
64
+ catch (error) {
65
+ throw fail('socket-changed', false, 'socket changed while connecting', error);
66
+ }
67
+ if (after.dev !== before.dev || after.ino !== before.ino || after.uid !== before.uid || after.gid !== before.gid || after.mode !== before.mode
68
+ || after.parentDev !== before.parentDev || after.parentIno !== before.parentIno || after.parentUid !== before.parentUid || after.parentGid !== before.parentGid || after.parentMode !== before.parentMode)
69
+ throw fail('socket-changed', false, 'socket identity changed while connecting');
70
+ }
71
+ function validateConnectionOptions(options) {
72
+ if (!isAbsolute(options.socketPath) || resolve(options.socketPath) !== options.socketPath || options.socketPath === '/' || options.socketPath.includes('\0') || Buffer.byteLength(options.socketPath) > 100
73
+ || !integer(options.timeoutMs ?? 30_000, 1, 300_000) || !integer(options.maxHelloTtlMs ?? GITHUB_BROKER_DEFAULT_HELLO_TTL_MS, 1, 300_000)
74
+ || options.expectedSocketUid !== undefined && !integer(options.expectedSocketUid, 0, 0x7fffffff)
75
+ || options.expectedSocketGid !== undefined && !integer(options.expectedSocketGid, 0, 0x7fffffff)
76
+ || options.expectedSocketMode !== undefined && (!integer(options.expectedSocketMode, 0, 0o777) || (options.expectedSocketMode & 0o007) !== 0)
77
+ || options.expectedSocketParentUid !== undefined && !integer(options.expectedSocketParentUid, 0, 0x7fffffff)
78
+ || options.expectedSocketParentGid !== undefined && !integer(options.expectedSocketParentGid, 0, 0x7fffffff)
79
+ || options.expectedSocketParentMode !== undefined && (!integer(options.expectedSocketParentMode, 0, 0o777) || (options.expectedSocketParentMode & 0o022) !== 0)
80
+ || options.inspectPeerCredentials !== undefined && typeof options.inspectPeerCredentials !== 'function' || !integer(options.expectedBrokerPeerUid, 0, 0x7fffffff) || !integer(options.expectedBrokerPeerGid, 0, 0x7fffffff)
81
+ || options.expectedServerInstanceId !== undefined && (!/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/.test(options.expectedServerInstanceId))
82
+ || options.minimumServerGeneration !== undefined && !integer(options.minimumServerGeneration, 1, Number.MAX_SAFE_INTEGER))
83
+ throw fail('invalid-config', false, 'client options are invalid');
84
+ }
85
+ /**
86
+ * Perform exactly one authenticated request on a fresh Unix-domain connection.
87
+ * No error is retried. Once the request frame starts writing, every local
88
+ * failure is conservatively reported as a post-dispatch unknown outcome.
89
+ */
90
+ async function requestBroker(options, deadline, makeRequest, verifyResponse, beforeWrite, signal) {
91
+ validateConnectionOptions(options);
92
+ if (signal?.aborted)
93
+ throw fail('aborted', false, 'request was aborted before connect', signal.reason);
94
+ const before = await inspectSocket(options);
95
+ if (signal?.aborted)
96
+ throw fail('aborted', false, 'request was aborted before connect', signal.reason);
97
+ const decoder = new BrokerFrameDecoder(GITHUB_BROKER_RESPONSE_MAX_BYTES, 2);
98
+ return await new Promise((resolvePromise, rejectPromise) => {
99
+ let socket;
100
+ let settled = false, connected = false, requestStarted = false, ended = false;
101
+ let hello, request, response;
102
+ const operationController = new AbortController();
103
+ const timer = setTimeout(() => stop('timeout', 'broker request timed out'), options.timeoutMs ?? 30_000);
104
+ timer.unref();
105
+ const cleanup = () => {
106
+ clearTimeout(timer);
107
+ operationController.abort(new Error('broker request settled'));
108
+ signal?.removeEventListener('abort', onAbort);
109
+ socket?.removeAllListeners();
110
+ if (!socket?.destroyed)
111
+ socket?.destroy();
112
+ };
113
+ const finish = (value) => { if (!settled) {
114
+ settled = true;
115
+ cleanup();
116
+ resolvePromise(value);
117
+ } };
118
+ const stop = (code, message, cause) => {
119
+ if (settled)
120
+ return;
121
+ settled = true;
122
+ cleanup();
123
+ rejectPromise(fail(code, requestStarted, message, cause));
124
+ };
125
+ const onAbort = () => stop('aborted', 'broker request was aborted', signal?.reason);
126
+ const acceptHello = (value) => {
127
+ try {
128
+ const verifiedHello = verifyBrokerServerHello(value, options.serverPublicKey, {
129
+ ...(options.maxHelloTtlMs === undefined ? {} : { maxTtlMs: options.maxHelloTtlMs }),
130
+ ...(options.expectedServerInstanceId === undefined ? {} : { expectedInstanceId: options.expectedServerInstanceId }),
131
+ ...(options.minimumServerGeneration === undefined ? {} : { minimumGeneration: options.minimumServerGeneration }),
132
+ });
133
+ if (Date.now() >= deadline)
134
+ throw new BrokerProtocolError('expired-request', 'request deadline expired');
135
+ const verifiedRequest = makeRequest(verifiedHello);
136
+ hello = verifiedHello;
137
+ request = verifiedRequest;
138
+ socket.pause();
139
+ void runBeforeWrite(beforeWrite, verifiedHello, verifiedRequest, operationController.signal).then(() => {
140
+ if (settled)
141
+ return;
142
+ if (signal?.aborted) {
143
+ stop('aborted', 'broker request was aborted before dispatch', signal.reason);
144
+ return;
145
+ }
146
+ if (Date.now() >= deadline || Date.now() >= verifiedHello.expiresAt) {
147
+ stop('timeout', 'broker request or hello expired before dispatch');
148
+ return;
149
+ }
150
+ let frame;
151
+ try {
152
+ frame = encodeBrokerFrame(verifiedRequest, GITHUB_BROKER_REQUEST_MAX_BYTES);
153
+ }
154
+ catch (error) {
155
+ stop('protocol-error', 'broker request encoding failed', error);
156
+ return;
157
+ }
158
+ requestStarted = true;
159
+ try {
160
+ socket.write(frame, error => { if (error)
161
+ stop('disconnected', 'request frame write failed', error); });
162
+ }
163
+ catch (error) {
164
+ stop('disconnected', 'request frame write failed', error);
165
+ return;
166
+ }
167
+ socket.resume();
168
+ }, error => { if (!settled)
169
+ stop('authorization-rejected', 'pre-dispatch authorization changed', error); });
170
+ }
171
+ catch (error) {
172
+ stop('protocol-error', 'broker message validation failed', error);
173
+ }
174
+ };
175
+ const onData = (chunk) => {
176
+ try {
177
+ const values = decoder.push(chunk);
178
+ if (!hello) {
179
+ if (values.length === 0)
180
+ return;
181
+ if (values.length !== 1)
182
+ throw new BrokerProtocolError('trailing-data', 'broker sent data before receiving a request');
183
+ acceptHello(values[0]);
184
+ return;
185
+ }
186
+ for (const value of values) {
187
+ if (response || !request)
188
+ throw new BrokerProtocolError('trailing-data', 'unexpected extra broker frame');
189
+ response = verifyResponse(value, request, hello);
190
+ }
191
+ }
192
+ catch (error) {
193
+ stop('protocol-error', 'broker frame validation failed', error);
194
+ }
195
+ };
196
+ const onEnd = () => {
197
+ ended = true;
198
+ try {
199
+ decoder.finish();
200
+ }
201
+ catch (error) {
202
+ stop('protocol-error', 'broker connection ended with an invalid frame', error);
203
+ return;
204
+ }
205
+ if (decoder.frameCount !== 2 || !response) {
206
+ stop('disconnected', 'broker disconnected before a complete signed response');
207
+ return;
208
+ }
209
+ finish(response);
210
+ };
211
+ signal?.addEventListener('abort', onAbort, { once: true });
212
+ try {
213
+ socket = createConnection({ path: options.socketPath });
214
+ // The peer may send immediately after accept. Buffer it until the second
215
+ // pathname identity check succeeds; no authenticated request is written
216
+ // while a replacement race is unresolved.
217
+ socket.pause();
218
+ socket.on('data', onData);
219
+ socket.once('error', error => stop(connected ? 'disconnected' : 'connect-failed', connected ? 'broker connection failed' : 'broker connect failed', error));
220
+ socket.once('end', onEnd);
221
+ socket.once('close', hadError => { if (!settled && !ended)
222
+ stop('disconnected', hadError ? 'broker connection closed with an error' : 'broker connection closed without a complete response'); });
223
+ socket.once('connect', () => {
224
+ connected = true;
225
+ const inspectPeer = options.inspectPeerCredentials ?? inspectLinuxPeerCredentials;
226
+ void Promise.all([assertSameSocket(options, before), Promise.resolve(inspectPeer(socket, operationController.signal))]).then(([, peer]) => {
227
+ if (!peer || !integer(peer.uid, 0, 0x7fffffff) || !integer(peer.gid, 0, 0x7fffffff) || peer.pid !== undefined && !integer(peer.pid, 1, 0x7fffffff)
228
+ || peer.uid !== options.expectedBrokerPeerUid || peer.gid !== options.expectedBrokerPeerGid) {
229
+ stop('socket-changed', 'connected broker peer identity does not match');
230
+ return;
231
+ }
232
+ if (!settled)
233
+ socket?.resume();
234
+ }, error => stop('socket-changed', 'socket or broker peer identity changed while connecting', error));
235
+ });
236
+ }
237
+ catch (error) {
238
+ stop('connect-failed', 'broker connect failed', error);
239
+ }
240
+ });
241
+ }
242
+ async function runBeforeWrite(hook, hello, request, signal) {
243
+ if (!hook)
244
+ return;
245
+ if (signal.aborted)
246
+ throw signal.reason;
247
+ const operation = Promise.resolve().then(() => hook(hello, request, signal));
248
+ operation.catch(() => { });
249
+ await new Promise((resolveGate, rejectGate) => {
250
+ const onAbort = () => { signal.removeEventListener('abort', onAbort); rejectGate(signal.reason); };
251
+ signal.addEventListener('abort', onAbort, { once: true });
252
+ operation.then(() => { signal.removeEventListener('abort', onAbort); resolveGate(); }, error => { signal.removeEventListener('abort', onAbort); rejectGate(error); });
253
+ });
254
+ }
255
+ export async function requestGitHubBroker(options, intent, signal) {
256
+ if (options.source.kind !== 'assistant-actions-host' || !integer(options.source.generation, 1, Number.MAX_SAFE_INTEGER))
257
+ throw fail('invalid-config', false, 'client identity is invalid');
258
+ return await requestBroker(options, intent.deadline, hello => createBrokerClientRequest(intent, hello, options.source, options.clientKeyId, options.clientPrivateKey), (value, request, hello) => verifyBrokerServerResponse(value, request, hello, options.serverPublicKey), options.beforeWrite, signal);
259
+ }
260
+ /** Signed operator control request over the same one-request UDS transport. */
261
+ export async function requestGitHubBrokerAdmin(options, intent, source, adminKeyId, adminPrivateKey, signal) {
262
+ if (source.kind !== 'assistant-actions-admin' || !integer(source.generation, 1, Number.MAX_SAFE_INTEGER))
263
+ throw fail('invalid-config', false, 'admin identity is invalid');
264
+ return await requestBroker(options, intent.deadline, hello => createBrokerAdminRequest(intent, hello, source, adminKeyId, adminPrivateKey), (value, request, hello) => verifyBrokerAdminResponse(value, request, hello, options.serverPublicKey), undefined, signal);
265
+ }
266
+ //# sourceMappingURL=broker-client.js.map