@layernorm/overlay-agent-host 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/Dockerfile +19 -0
  2. package/README.md +136 -0
  3. package/dist/acp-adapter.d.ts +37 -0
  4. package/dist/acp-adapter.d.ts.map +1 -0
  5. package/dist/acp-adapter.js +218 -0
  6. package/dist/acp-adapter.js.map +1 -0
  7. package/dist/adapter-manifests.d.ts +47 -0
  8. package/dist/adapter-manifests.d.ts.map +1 -0
  9. package/dist/adapter-manifests.js +30 -0
  10. package/dist/adapter-manifests.js.map +1 -0
  11. package/dist/adapter.d.ts +32 -0
  12. package/dist/adapter.d.ts.map +1 -0
  13. package/dist/adapter.js +2 -0
  14. package/dist/adapter.js.map +1 -0
  15. package/dist/cli.d.ts +2 -0
  16. package/dist/cli.d.ts.map +1 -0
  17. package/dist/cli.js +203 -0
  18. package/dist/cli.js.map +1 -0
  19. package/dist/config.d.ts +177 -0
  20. package/dist/config.d.ts.map +1 -0
  21. package/dist/config.js +55 -0
  22. package/dist/config.js.map +1 -0
  23. package/dist/connection.d.ts +67 -0
  24. package/dist/connection.d.ts.map +1 -0
  25. package/dist/connection.js +30 -0
  26. package/dist/connection.js.map +1 -0
  27. package/dist/device-key.d.ts +6 -0
  28. package/dist/device-key.d.ts.map +1 -0
  29. package/dist/device-key.js +28 -0
  30. package/dist/device-key.js.map +1 -0
  31. package/dist/doctor.d.ts +9 -0
  32. package/dist/doctor.d.ts.map +1 -0
  33. package/dist/doctor.js +47 -0
  34. package/dist/doctor.js.map +1 -0
  35. package/dist/enrollment.d.ts +18 -0
  36. package/dist/enrollment.d.ts.map +1 -0
  37. package/dist/enrollment.js +76 -0
  38. package/dist/enrollment.js.map +1 -0
  39. package/dist/eve-adapter.d.ts +61 -0
  40. package/dist/eve-adapter.d.ts.map +1 -0
  41. package/dist/eve-adapter.js +315 -0
  42. package/dist/eve-adapter.js.map +1 -0
  43. package/dist/fake-adapter.d.ts +29 -0
  44. package/dist/fake-adapter.d.ts.map +1 -0
  45. package/dist/fake-adapter.js +41 -0
  46. package/dist/fake-adapter.js.map +1 -0
  47. package/dist/filesystem-policy.d.ts +7 -0
  48. package/dist/filesystem-policy.d.ts.map +1 -0
  49. package/dist/filesystem-policy.js +23 -0
  50. package/dist/filesystem-policy.js.map +1 -0
  51. package/dist/hermes-readiness.d.ts +6 -0
  52. package/dist/hermes-readiness.d.ts.map +1 -0
  53. package/dist/hermes-readiness.js +21 -0
  54. package/dist/hermes-readiness.js.map +1 -0
  55. package/dist/index.d.ts +17 -0
  56. package/dist/index.d.ts.map +1 -0
  57. package/dist/index.js +17 -0
  58. package/dist/index.js.map +1 -0
  59. package/dist/launchd.d.ts +15 -0
  60. package/dist/launchd.d.ts.map +1 -0
  61. package/dist/launchd.js +86 -0
  62. package/dist/launchd.js.map +1 -0
  63. package/dist/logger.d.ts +11 -0
  64. package/dist/logger.d.ts.map +1 -0
  65. package/dist/logger.js +24 -0
  66. package/dist/logger.js.map +1 -0
  67. package/dist/runtime-version.d.ts +3 -0
  68. package/dist/runtime-version.d.ts.map +1 -0
  69. package/dist/runtime-version.js +8 -0
  70. package/dist/runtime-version.js.map +1 -0
  71. package/dist/runtime.d.ts +54 -0
  72. package/dist/runtime.d.ts.map +1 -0
  73. package/dist/runtime.js +254 -0
  74. package/dist/runtime.js.map +1 -0
  75. package/dist/state.d.ts +39 -0
  76. package/dist/state.d.ts.map +1 -0
  77. package/dist/state.js +160 -0
  78. package/dist/state.js.map +1 -0
  79. package/dist/transport.d.ts +57 -0
  80. package/dist/transport.d.ts.map +1 -0
  81. package/dist/transport.js +119 -0
  82. package/dist/transport.js.map +1 -0
  83. package/docker-compose.example.yml +15 -0
  84. package/package.json +60 -0
  85. package/src/cli.mjs +9 -0
  86. package/systemd/agent-host.env.example +6 -0
  87. package/systemd/overlay-agent-host.service +32 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fake-adapter.js","s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MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,GAAG,OAAO,GAAG,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAA,CAAC,CAAC;YAC3H,MAAM,EAAE,KAAK,IAAI,EAAE,GAAG,OAAO,GAAG,KAAK,CAAC,CAAC,MAAM,IAAI,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,iBAAiB,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,CAAC,CAAA,CAAC,CAAC;YACvJ,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,GAAG,OAAO,GAAG,IAAI,CAAC,CAAC,IAAI,MAAM;gBAAE,SAAS,CAAC,GAAG,CAAC,aAAa,EAAE,MAAM,CAAC,CAAA,CAAC,CAAC;SAC7F,CAAA;IACH,CAAC;CACF"}
@@ -0,0 +1,7 @@
1
+ import type { FilesystemGrant } from '@layernorm/overlay-agent-bridge-protocol';
2
+ export type ResolvedFilesystemScope = {
3
+ workingDirectory: string;
4
+ additionalDirectories: string[];
5
+ };
6
+ export declare function resolveFilesystemScope(grant: FilesystemGrant, requestedDirectory: string): Promise<ResolvedFilesystemScope>;
7
+ //# sourceMappingURL=filesystem-policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filesystem-policy.d.ts","sourceRoot":"","sources":["../src/filesystem-policy.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0CAA0C,CAAA;AAE/E,MAAM,MAAM,uBAAuB,GAAG;IACpC,gBAAgB,EAAE,MAAM,CAAA;IACxB,qBAAqB,EAAE,MAAM,EAAE,CAAA;CAChC,CAAA;AAED,wBAAsB,sBAAsB,CAAC,KAAK,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAajI"}
@@ -0,0 +1,23 @@
1
+ import { realpath } from 'node:fs/promises';
2
+ import { isAbsolute, relative, resolve } from 'node:path';
3
+ export async function resolveFilesystemScope(grant, requestedDirectory) {
4
+ if (!isAbsolute(requestedDirectory))
5
+ throw new Error('working directory must be an absolute path');
6
+ const workingDirectory = await realpath(requestedDirectory);
7
+ if (grant.mode === 'all_user_files')
8
+ return { workingDirectory, additionalDirectories: [] };
9
+ const roots = await Promise.all(grant.roots.map(async (root) => {
10
+ if (!isAbsolute(root))
11
+ throw new Error(`filesystem root must be absolute: ${root}`);
12
+ return realpath(resolve(root));
13
+ }));
14
+ if (!roots.some((root) => isWithin(root, workingDirectory))) {
15
+ throw new Error('working directory is outside the environment filesystem grant');
16
+ }
17
+ return { workingDirectory, additionalDirectories: roots.filter((root) => root !== workingDirectory) };
18
+ }
19
+ function isWithin(root, candidate) {
20
+ const path = relative(root, candidate);
21
+ return path === '' || (!path.startsWith('..') && !isAbsolute(path));
22
+ }
23
+ //# sourceMappingURL=filesystem-policy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filesystem-policy.js","sourceRoot":"","sources":["../src/filesystem-policy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAQzD,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,KAAsB,EAAE,kBAA0B;IAC7F,IAAI,CAAC,UAAU,CAAC,kBAAkB,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAA;IAClG,MAAM,gBAAgB,GAAG,MAAM,QAAQ,CAAC,kBAAkB,CAAC,CAAA;IAC3D,IAAI,KAAK,CAAC,IAAI,KAAK,gBAAgB;QAAE,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,EAAE,EAAE,CAAA;IAE3F,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;QAC7D,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,qCAAqC,IAAI,EAAE,CAAC,CAAA;QACnF,OAAO,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA;IAChC,CAAC,CAAC,CAAC,CAAA;IACH,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC,EAAE,CAAC;QAC5D,MAAM,IAAI,KAAK,CAAC,+DAA+D,CAAC,CAAA;IAClF,CAAC;IACD,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,gBAAgB,CAAC,EAAE,CAAA;AACvG,CAAC;AAED,SAAS,QAAQ,CAAC,IAAY,EAAE,SAAiB;IAC/C,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,CAAA;IACtC,OAAO,IAAI,KAAK,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAA;AACrE,CAAC"}
@@ -0,0 +1,6 @@
1
+ type CheckRunner = () => Promise<{
2
+ stdout: string;
3
+ }>;
4
+ export declare function verifyHermesAcpReadiness(run?: CheckRunner): Promise<void>;
5
+ export {};
6
+ //# sourceMappingURL=hermes-readiness.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hermes-readiness.d.ts","sourceRoot":"","sources":["../src/hermes-readiness.ts"],"names":[],"mappings":"AAIA,KAAK,WAAW,GAAG,MAAM,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAAA;AAEpD,wBAAsB,wBAAwB,CAAC,GAAG,GAAE,WAOnD,iBAUA"}
@@ -0,0 +1,21 @@
1
+ import { execFile } from 'node:child_process';
2
+ import { promisify } from 'node:util';
3
+ const execFileAsync = promisify(execFile);
4
+ export async function verifyHermesAcpReadiness(run = async () => {
5
+ const result = await execFileAsync('hermes', ['acp', '--check'], {
6
+ timeout: 15_000,
7
+ maxBuffer: 64 * 1024,
8
+ windowsHide: true,
9
+ });
10
+ return { stdout: result.stdout };
11
+ }) {
12
+ try {
13
+ const result = await run();
14
+ if (!result.stdout.includes('Hermes ACP check OK'))
15
+ throw new Error('unexpected readiness response');
16
+ }
17
+ catch (error) {
18
+ throw new Error('Hermes ACP is not ready. Install Hermes Agent 0.20.6 or newer, run `hermes acp --setup`, then verify it with `hermes acp --check` before reconnecting.', { cause: error });
19
+ }
20
+ }
21
+ //# sourceMappingURL=hermes-readiness.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hermes-readiness.js","sourceRoot":"","sources":["../src/hermes-readiness.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAErC,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAA;AAGzC,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAAC,MAAmB,KAAK,IAAI,EAAE;IAC3E,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,SAAS,CAAC,EAAE;QAC/D,OAAO,EAAE,MAAM;QACf,SAAS,EAAE,EAAE,GAAG,IAAI;QACpB,WAAW,EAAE,IAAI;KAClB,CAAC,CAAA;IACF,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAA;AAClC,CAAC;IACC,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,GAAG,EAAE,CAAA;QAC1B,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,qBAAqB,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAA;IACtG,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CACb,wJAAwJ,EACxJ,EAAE,KAAK,EAAE,KAAK,EAAE,CACjB,CAAA;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,17 @@
1
+ export * from './acp-adapter.js';
2
+ export * from './adapter.js';
3
+ export * from './adapter-manifests.js';
4
+ export * from './hermes-readiness.js';
5
+ export * from './config.js';
6
+ export * from './connection.js';
7
+ export * from './device-key.js';
8
+ export * from './doctor.js';
9
+ export * from './enrollment.js';
10
+ export * from './eve-adapter.js';
11
+ export * from './fake-adapter.js';
12
+ export * from './filesystem-policy.js';
13
+ export * from './logger.js';
14
+ export * from './runtime.js';
15
+ export * from './state.js';
16
+ export * from './transport.js';
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,cAAc,CAAA;AAC5B,cAAc,wBAAwB,CAAA;AACtC,cAAc,uBAAuB,CAAA;AACrC,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA;AAChC,cAAc,mBAAmB,CAAA;AACjC,cAAc,wBAAwB,CAAA;AACtC,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,17 @@
1
+ export * from './acp-adapter.js';
2
+ export * from './adapter.js';
3
+ export * from './adapter-manifests.js';
4
+ export * from './hermes-readiness.js';
5
+ export * from './config.js';
6
+ export * from './connection.js';
7
+ export * from './device-key.js';
8
+ export * from './doctor.js';
9
+ export * from './enrollment.js';
10
+ export * from './eve-adapter.js';
11
+ export * from './fake-adapter.js';
12
+ export * from './filesystem-policy.js';
13
+ export * from './logger.js';
14
+ export * from './runtime.js';
15
+ export * from './state.js';
16
+ export * from './transport.js';
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,cAAc,CAAA;AAC5B,cAAc,wBAAwB,CAAA;AACtC,cAAc,uBAAuB,CAAA;AACrC,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA;AAChC,cAAc,mBAAmB,CAAA;AACjC,cAAc,wBAAwB,CAAA;AACtC,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA"}
@@ -0,0 +1,15 @@
1
+ export type LaunchAgentDefinition = {
2
+ environmentId: string;
3
+ configPath: string;
4
+ stateDirectory: string;
5
+ packageSpec: string;
6
+ };
7
+ export declare function launchAgentLabel(environmentId: string): string;
8
+ export declare function launchAgentPlist(input: LaunchAgentDefinition): string;
9
+ export declare function installLaunchAgent(input: LaunchAgentDefinition): Promise<string>;
10
+ export declare function uninstallLaunchAgent(environmentId: string): Promise<string>;
11
+ export declare function launchAgentStatus(environmentId: string): Promise<{
12
+ stdout: string;
13
+ stderr: string;
14
+ }>;
15
+ //# sourceMappingURL=launchd.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"launchd.d.ts","sourceRoot":"","sources":["../src/launchd.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,qBAAqB,GAAG;IAClC,aAAa,EAAE,MAAM,CAAA;IACrB,UAAU,EAAE,MAAM,CAAA;IAClB,cAAc,EAAE,MAAM,CAAA;IACtB,WAAW,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,wBAAgB,gBAAgB,CAAC,aAAa,EAAE,MAAM,UAErD;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,UAsB5D;AAED,wBAAsB,kBAAkB,CAAC,KAAK,EAAE,qBAAqB,mBAcpE;AAED,wBAAsB,oBAAoB,CAAC,aAAa,EAAE,MAAM,mBAQ/D;AAED,wBAAsB,iBAAiB,CAAC,aAAa,EAAE,MAAM;;;GAG5D"}
@@ -0,0 +1,86 @@
1
+ import { execFile } from 'node:child_process';
2
+ import { chmod, mkdir, rename, unlink, writeFile } from 'node:fs/promises';
3
+ import { homedir } from 'node:os';
4
+ import { dirname, join } from 'node:path';
5
+ import { promisify } from 'node:util';
6
+ const execFileAsync = promisify(execFile);
7
+ export function launchAgentLabel(environmentId) {
8
+ return `com.layernorm.overlay-agent-host.${environmentId.replace(/[^A-Za-z0-9.-]/g, '-')}`;
9
+ }
10
+ export function launchAgentPlist(input) {
11
+ const label = launchAgentLabel(input.environmentId);
12
+ const command = [
13
+ 'exec npx --yes --package node@24 --package',
14
+ shellQuote(input.packageSpec),
15
+ 'overlay-agent-host run --config',
16
+ shellQuote(input.configPath),
17
+ ].join(' ');
18
+ return `<?xml version="1.0" encoding="UTF-8"?>
19
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
20
+ <plist version="1.0">
21
+ <dict>
22
+ <key>Label</key><string>${xml(label)}</string>
23
+ <key>ProgramArguments</key>
24
+ <array><string>/bin/zsh</string><string>-lc</string><string>${xml(command)}</string></array>
25
+ <key>RunAtLoad</key><true/>
26
+ <key>KeepAlive</key><true/>
27
+ <key>StandardOutPath</key><string>${xml(join(input.stateDirectory, 'launchd.stdout.log'))}</string>
28
+ <key>StandardErrorPath</key><string>${xml(join(input.stateDirectory, 'launchd.stderr.log'))}</string>
29
+ </dict>
30
+ </plist>
31
+ `;
32
+ }
33
+ export async function installLaunchAgent(input) {
34
+ assertMacOS();
35
+ const path = launchAgentPath(input.environmentId);
36
+ await mkdir(dirname(path), { recursive: true });
37
+ await mkdir(input.stateDirectory, { recursive: true, mode: 0o700 });
38
+ const temporary = `${path}.${process.pid}.tmp`;
39
+ await writeFile(temporary, launchAgentPlist(input), { mode: 0o600, flag: 'wx' });
40
+ await rename(temporary, path);
41
+ await chmod(path, 0o600);
42
+ const domain = launchAgentDomain();
43
+ await execFileAsync('launchctl', ['bootout', domain, path]).catch(() => undefined);
44
+ await execFileAsync('launchctl', ['bootstrap', domain, path]);
45
+ await execFileAsync('launchctl', ['kickstart', '-k', `${domain}/${launchAgentLabel(input.environmentId)}`]);
46
+ return path;
47
+ }
48
+ export async function uninstallLaunchAgent(environmentId) {
49
+ assertMacOS();
50
+ const path = launchAgentPath(environmentId);
51
+ await execFileAsync('launchctl', ['bootout', launchAgentDomain(), path]).catch(() => undefined);
52
+ await unlink(path).catch((error) => {
53
+ if (!(error instanceof Error && 'code' in error && error.code === 'ENOENT'))
54
+ throw error;
55
+ });
56
+ return path;
57
+ }
58
+ export async function launchAgentStatus(environmentId) {
59
+ assertMacOS();
60
+ return await execFileAsync('launchctl', ['print', `${launchAgentDomain()}/${launchAgentLabel(environmentId)}`]);
61
+ }
62
+ function launchAgentPath(environmentId) {
63
+ return join(homedir(), 'Library', 'LaunchAgents', `${launchAgentLabel(environmentId)}.plist`);
64
+ }
65
+ function launchAgentDomain() {
66
+ const uid = process.getuid?.();
67
+ if (uid === undefined)
68
+ throw new Error('Could not determine the current macOS user');
69
+ return `gui/${uid}`;
70
+ }
71
+ function assertMacOS() {
72
+ if (process.platform !== 'darwin')
73
+ throw new Error('LaunchAgent service management is available only on macOS');
74
+ }
75
+ function shellQuote(value) {
76
+ return `'${value.replaceAll("'", `'"'"'`)}'`;
77
+ }
78
+ function xml(value) {
79
+ return value
80
+ .replaceAll('&', '&amp;')
81
+ .replaceAll('<', '&lt;')
82
+ .replaceAll('>', '&gt;')
83
+ .replaceAll('"', '&quot;')
84
+ .replaceAll("'", '&apos;');
85
+ }
86
+ //# sourceMappingURL=launchd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"launchd.js","sourceRoot":"","sources":["../src/launchd.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC1E,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAErC,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAA;AASzC,MAAM,UAAU,gBAAgB,CAAC,aAAqB;IACpD,OAAO,oCAAoC,aAAa,CAAC,OAAO,CAAC,iBAAiB,EAAE,GAAG,CAAC,EAAE,CAAA;AAC5F,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,KAA4B;IAC3D,MAAM,KAAK,GAAG,gBAAgB,CAAC,KAAK,CAAC,aAAa,CAAC,CAAA;IACnD,MAAM,OAAO,GAAG;QACd,4CAA4C;QAC5C,UAAU,CAAC,KAAK,CAAC,WAAW,CAAC;QAC7B,iCAAiC;QACjC,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC;KAC7B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IACX,OAAO;;;;4BAImB,GAAG,CAAC,KAAK,CAAC;;gEAE0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AA;AACrB,CAAC;AAED,SAAS,WAAW;IAClB,IAAI,OAAO,CAAC,QAAQ,KAAK,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAA;AACjH,CAAC;AAED,SAAS,UAAU,CAAC,KAAa;IAC/B,OAAO,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,CAAA;AAC9C,CAAC;AAED,SAAS,GAAG,CAAC,KAAa;IACxB,OAAO,KAAK;SACT,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC;SACxB,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC;SACvB,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC;SACvB,UAAU,CAAC,GAAG,EAAE,QAAQ,CAAC;SACzB,UAAU,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAA;AAC9B,CAAC"}
@@ -0,0 +1,11 @@
1
+ export type LogSink = (line: string) => void;
2
+ export declare class StructuredLogger {
3
+ private readonly sink;
4
+ constructor(sink?: LogSink);
5
+ info(message: string, fields?: Record<string, unknown>): void;
6
+ warn(message: string, fields?: Record<string, unknown>): void;
7
+ error(message: string, fields?: Record<string, unknown>): void;
8
+ private write;
9
+ }
10
+ export declare function redact(value: unknown, key?: string): unknown;
11
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,OAAO,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;AAE5C,qBAAa,gBAAgB;IACf,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,GAAE,OAAqD;IAExF,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GAAG,IAAI;IACjE,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GAAG,IAAI;IACjE,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GAAG,IAAI;IAElE,OAAO,CAAC,KAAK;CAGd;AAED,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,SAAK,GAAG,OAAO,CAOxD"}
package/dist/logger.js ADDED
@@ -0,0 +1,24 @@
1
+ const SECRET_KEY = /(authorization|credential|secret|token|private.?key|password)/i;
2
+ export class StructuredLogger {
3
+ sink;
4
+ constructor(sink = (line) => process.stderr.write(`${line}\n`)) {
5
+ this.sink = sink;
6
+ }
7
+ info(message, fields = {}) { this.write('info', message, fields); }
8
+ warn(message, fields = {}) { this.write('warn', message, fields); }
9
+ error(message, fields = {}) { this.write('error', message, fields); }
10
+ write(level, message, fields) {
11
+ this.sink(JSON.stringify({ timestamp: new Date().toISOString(), level, message, ...redact(fields) }));
12
+ }
13
+ }
14
+ export function redact(value, key = '') {
15
+ if (SECRET_KEY.test(key))
16
+ return '[REDACTED]';
17
+ if (Array.isArray(value))
18
+ return value.map((item) => redact(item));
19
+ if (value && typeof value === 'object') {
20
+ return Object.fromEntries(Object.entries(value).map(([nestedKey, nestedValue]) => [nestedKey, redact(nestedValue, nestedKey)]));
21
+ }
22
+ return value;
23
+ }
24
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,GAAG,gEAAgE,CAAA;AAInF,MAAM,OAAO,gBAAgB;IACE;IAA7B,YAA6B,OAAgB,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,IAAI,CAAC;QAA3D,SAAI,GAAJ,IAAI,CAAuD;IAAG,CAAC;IAE5F,IAAI,CAAC,OAAe,EAAE,SAAkC,EAAE,IAAU,I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+ export declare const MINIMUM_NODE_MAJOR = 24;
2
+ export declare function assertSupportedNodeVersion(version?: string): void;
3
+ //# sourceMappingURL=runtime-version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-version.d.ts","sourceRoot":"","sources":["../src/runtime-version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,KAAK,CAAA;AAEpC,wBAAgB,0BAA0B,CAAC,OAAO,SAAwB,GAAG,IAAI,CAOhF"}
@@ -0,0 +1,8 @@
1
+ export const MINIMUM_NODE_MAJOR = 24;
2
+ export function assertSupportedNodeVersion(version = process.versions.node) {
3
+ const major = Number.parseInt(version.split('.', 1)[0] ?? '', 10);
4
+ if (!Number.isFinite(major) || major < MINIMUM_NODE_MAJOR) {
5
+ throw new Error(`Overlay Agent Host requires Node.js ${MINIMUM_NODE_MAJOR} or newer; current version is ${version}. Regenerate the connection command in Overlay so it can launch with Node.js ${MINIMUM_NODE_MAJOR}.`);
6
+ }
7
+ }
8
+ //# sourceMappingURL=runtime-version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-version.js","sourceRoot":"","sources":["../src/runtime-version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,CAAA;AAEpC,MAAM,UAAU,0BAA0B,CAAC,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI;IACxE,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,EAAE,CAAC,CAAA;IACjE,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,kBAAkB,EAAE,CAAC;QAC1D,MAAM,IAAI,KAAK,CACb,uCAAuC,kBAAkB,iCAAiC,OAAO,gFAAgF,kBAAkB,GAAG,CACvM,CAAA;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,54 @@
1
+ import { type AgentHostCommand, type FilesystemGrant } from '@layernorm/overlay-agent-bridge-protocol';
2
+ import type { AgentAdapter } from './adapter.js';
3
+ import { StructuredLogger } from './logger.js';
4
+ import { SqliteHostStateStore } from './state.js';
5
+ import type { AgentControlPlaneClient } from './transport.js';
6
+ export type AgentHostRuntimeOptions = {
7
+ environmentId: string;
8
+ workspaceId: string;
9
+ filesystem: FilesystemGrant;
10
+ adapters: AgentAdapter[];
11
+ state: SqliteHostStateStore;
12
+ controlPlane: AgentControlPlaneClient;
13
+ logger?: StructuredLogger;
14
+ maxOutboxEvents?: number;
15
+ };
16
+ export declare class AgentHostRuntime {
17
+ private readonly options;
18
+ private readonly adapters;
19
+ private readonly sessions;
20
+ private readonly logger;
21
+ private flushing?;
22
+ private lastHeartbeatAt;
23
+ constructor(options: AgentHostRuntimeOptions);
24
+ discoverCapabilities(): Promise<{
25
+ id: string;
26
+ displayName: string;
27
+ protocol: "fake" | "acp" | "eve" | "native";
28
+ supports: {
29
+ prompt: boolean;
30
+ approval: boolean;
31
+ cancel: boolean;
32
+ resume: boolean;
33
+ };
34
+ version?: string | undefined;
35
+ }[]>;
36
+ pollOnce(waitMs?: number, signal?: AbortSignal): Promise<number>;
37
+ run(signal: AbortSignal): Promise<void>;
38
+ private refreshHostState;
39
+ private heartbeat;
40
+ processCommand(command: AgentHostCommand): Promise<void>;
41
+ uploadArtifact(runId: string, input: {
42
+ name: string;
43
+ mediaType: string;
44
+ bytes: Uint8Array;
45
+ }): Promise<string>;
46
+ flushOutbox(): Promise<void>;
47
+ private flushOutboxInternal;
48
+ private dispatch;
49
+ private requireSession;
50
+ private requireAdapter;
51
+ private emit;
52
+ private acknowledge;
53
+ }
54
+ //# sourceMappingURL=runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,gBAAgB,EAErB,KAAK,eAAe,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S,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,UAAU,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAe7G,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;YAMpB,mBAAmB;YA4BnB,QAAQ;YA0CR,cAAc;IAiB5B,OAAO,CAAC,cAAc;YAMR,IAAI;IAalB,OAAO,CAAC,WAAW;CASpB"}
@@ -0,0 +1,254 @@
1
+ import { createHash, randomUUID } from 'node:crypto';
2
+ import { platform, release } from 'node:os';
3
+ import { eventBatchSchema, OVERLAY_AGENT_PROTOCOL_VERSION, } from '@layernorm/overlay-agent-bridge-protocol';
4
+ import { resolveFilesystemScope } from './filesystem-policy.js';
5
+ import { StructuredLogger } from './logger.js';
6
+ import { nextReconnectDelay } from './transport.js';
7
+ export class AgentHostRuntime {
8
+ options;
9
+ adapters;
10
+ sessions = new Map();
11
+ logger;
12
+ flushing;
13
+ lastHeartbeatAt = 0;
14
+ constructor(options) {
15
+ this.options = options;
16
+ this.adapters = new Map(options.adapters.map((adapter) => [adapter.capability.id, adapter]));
17
+ this.logger = options.logger ?? new StructuredLogger();
18
+ }
19
+ async discoverCapabilities() {
20
+ return Promise.all([...this.adapters.values()].map((adapter) => adapter.discover()));
21
+ }
22
+ async pollOnce(waitMs = 25_000, signal) {
23
+ if (this.options.state.outboxSize() >= (this.options.maxOutboxEvents ?? 10_000)) {
24
+ await this.flushOutbox();
25
+ if (this.options.state.outboxSize() >= (this.options.maxOutboxEvents ?? 10_000))
26
+ throw new Error('event outbox backpressure limit reached');
27
+ }
28
+ const response = await this.options.controlPlane.pollCommands({ waitMs, ...(signal ? { signal } : {}) });
29
+ for (const command of response.commands)
30
+ await this.processCommand(command);
31
+ await this.flushOutbox();
32
+ return response.retryAfterMs ?? 0;
33
+ }
34
+ async run(signal) {
35
+ let attempt = 0;
36
+ await this.refreshHostState();
37
+ while (!signal.aborted) {
38
+ try {
39
+ if (Date.now() - this.lastHeartbeatAt >= 30_000)
40
+ await this.heartbeat();
41
+ const retryAfterMs = await this.pollOnce(25_000, signal);
42
+ attempt = 0;
43
+ if (retryAfterMs > 0)
44
+ await abortableDelay(retryAfterMs, signal);
45
+ }
46
+ catch (error) {
47
+ if (signal.aborted)
48
+ break;
49
+ const delay = nextReconnectDelay(attempt++);
50
+ this.logger.warn('agent host poll failed', { error: safeError(error), delay });
51
+ await abortableDelay(delay, signal);
52
+ }
53
+ }
54
+ }
55
+ async refreshHostState() {
56
+ if (this.options.controlPlane.updateCapabilities) {
57
+ await this.options.controlPlane.updateCapabilities({
58
+ protocolVersion: OVERLAY_AGENT_PROTOCOL_VERSION,
59
+ hostVersion: '0.0.1',
60
+ platform: `${platform()} ${release()}`,
61
+ adapters: await this.discoverCapabilities(),
62
+ filesystem: this.options.filesystem,
63
+ maxConcurrentRuns: Math.max(1, this.adapters.size),
64
+ });
65
+ }
66
+ await this.heartbeat();
67
+ }
68
+ async heartbeat() {
69
+ await this.options.controlPlane.heartbeat?.();
70
+ this.lastHeartbeatAt = Date.now();
71
+ }
72
+ async processCommand(command) {
73
+ if (command.environmentId !== this.options.environmentId || command.workspaceId !== this.options.workspaceId) {
74
+ throw new Error('command scope does not match this host');
75
+ }
76
+ const processed = this.options.state.getProcessedCommand(command.commandId);
77
+ if (processed) {
78
+ await this.acknowledge(command, processed.accepted, processed.errorMessage, processed.errorCode);
79
+ return;
80
+ }
81
+ const expectedSequence = this.options.state.commandCursor() + 1;
82
+ if (command.sequence !== expectedSequence) {
83
+ await this.acknowledge(command, false, `expected command sequence ${expectedSequence}`, 'command_sequence_gap');
84
+ throw new Error(`expected command sequence ${expectedSequence}, received ${command.sequence}`);
85
+ }
86
+ try {
87
+ await this.dispatch(command);
88
+ this.options.state.recordCommandResult(command.commandId, { sequence: command.sequence, accepted: true });
89
+ }
90
+ catch (error) {
91
+ const message = safeError(error);
92
+ this.options.state.recordCommandResult(command.commandId, { sequence: command.sequence, accepted: false, errorCode: 'command_rejected', errorMessage: message });
93
+ await this.acknowledge(command, false, message, 'command_rejected');
94
+ throw error;
95
+ }
96
+ await this.acknowledge(command, true);
97
+ }
98
+ async uploadArtifact(runId, input) {
99
+ const controlPlane = this.options.controlPlane;
100
+ if (!controlPlane.createArtifactUpload || !controlPlane.uploadArtifactBytes || !controlPlane.completeArtifactUpload) {
101
+ throw new Error('control plane does not support artifact uploads');
102
+ }
103
+ const sha256 = createHash('sha256').update(input.bytes).digest('hex');
104
+ const upload = await controlPlane.createArtifactUpload({ protocolVersion: OVERLAY_AGENT_PROTOCOL_VERSION,
105
+ runId, name: input.name, mediaType: input.mediaType, size: input.bytes.byteLength, sha256 });
106
+ await controlPlane.uploadArtifactBytes(upload, input.bytes);
107
+ await controlPlane.completeArtifactUpload(upload.artifactId);
108
+ await this.emit(runId, { type: 'artifact', payload: { name: input.name, mediaType: input.mediaType,
109
+ size: input.bytes.byteLength, sha256, uploadReference: upload.uploadReference } });
110
+ return upload.artifactId;
111
+ }
112
+ async flushOutbox() {
113
+ if (this.flushing)
114
+ return this.flushing;
115
+ this.flushing = this.flushOutboxInternal().finally(() => { this.flushing = undefined; });
116
+ return this.flushing;
117
+ }
118
+ async flushOutboxInternal() {
119
+ for (;;) {
120
+ const events = this.options.state.pendingEvents(100);
121
+ if (events.length === 0)
122
+ return;
123
+ const batch = eventBatchSchema.parse({
124
+ protocolVersion: OVERLAY_AGENT_PROTOCOL_VERSION,
125
+ environmentId: this.options.environmentId,
126
+ runId: events[0].runId,
127
+ events,
128
+ });
129
+ const acknowledgement = await this.options.controlPlane.uploadEvents(batch);
130
+ if (acknowledgement.accepted) {
131
+ const lastSentSequence = batch.events.at(-1).sourceSequence;
132
+ if (acknowledgement.acknowledgedSequence !== lastSentSequence) {
133
+ throw new Error(`server acknowledged ${acknowledgement.acknowledgedSequence}, expected ${lastSentSequence}`);
134
+ }
135
+ this.options.state.acknowledgeEvents(batch.runId, acknowledgement.acknowledgedSequence);
136
+ continue;
137
+ }
138
+ const lastSentSequence = batch.events.at(-1).sourceSequence;
139
+ if (acknowledgement.expectedSequence > events[0].sourceSequence && acknowledgement.expectedSequence <= lastSentSequence + 1) {
140
+ this.options.state.discardEventsBefore(batch.runId, acknowledgement.expectedSequence);
141
+ continue;
142
+ }
143
+ throw new Error(`server requested unavailable event sequence ${acknowledgement.expectedSequence}`);
144
+ }
145
+ }
146
+ async dispatch(command) {
147
+ if (command.type === 'start') {
148
+ if (command.payload.fresh) {
149
+ await this.sessions.get(command.runId)?.stop('Starting a fresh session');
150
+ this.sessions.delete(command.runId);
151
+ this.options.state.deleteSession(command.runId);
152
+ this.options.state.deleteAdapterSessionState(command.runId);
153
+ }
154
+ else if (this.sessions.has(command.runId))
155
+ return;
156
+ const adapter = this.requireAdapter(command.payload.adapterId);
157
+ const scope = await resolveFilesystemScope(this.options.filesystem, command.payload.workingDirectory);
158
+ const session = await adapter.start({
159
+ runId: command.runId,
160
+ workingDirectory: scope.workingDirectory,
161
+ additionalDirectories: scope.additionalDirectories,
162
+ prompt: command.payload.prompt,
163
+ ...(command.payload.sessionId ? { remoteSessionId: command.payload.sessionId } : {}),
164
+ metadata: command.payload.metadata,
165
+ adapterState: this.options.state.getAdapterSessionState(command.runId, command.payload.adapterId),
166
+ persistAdapterState: (state) => this.options.state.saveAdapterSessionState(command.runId, command.payload.adapterId, state),
167
+ }, (event) => this.emit(command.runId, event));
168
+ this.sessions.set(command.runId, session);
169
+ this.options.state.saveSession({ runId: command.runId, adapterId: command.payload.adapterId, remoteSessionId: session.remoteSessionId, workingDirectory: scope.workingDirectory });
170
+ await this.emit(command.runId, { type: 'session_started', payload: { remoteSessionId: session.remoteSessionId, adapterId: command.payload.adapterId } });
171
+ if (!session.initialPromptHandled) {
172
+ void session.prompt(command.payload.prompt).catch((error) => this.emit(command.runId, { type: 'failed', payload: { code: 'adapter_prompt_failed', message: safeError(error), retryable: true } }));
173
+ }
174
+ return;
175
+ }
176
+ if (command.type === 'shutdown') {
177
+ const session = this.sessions.get(command.runId);
178
+ if (session)
179
+ await session.stop(command.payload.reason);
180
+ this.sessions.delete(command.runId);
181
+ return;
182
+ }
183
+ const session = await this.requireSession(command.runId, command.type === 'reconnect' ? command.payload.remoteSessionId : undefined);
184
+ if (command.type === 'prompt')
185
+ await session.prompt(command.payload.prompt);
186
+ else if (command.type === 'approval_response')
187
+ await session.approve(command.payload.requestKey, command.payload.optionId);
188
+ else if (command.type === 'elicitation_response')
189
+ await session.elicit(command.payload.requestKey, command.payload.action, command.payload.content);
190
+ else if (command.type === 'cancel')
191
+ await session.cancel(command.payload.reason);
192
+ else if (command.type === 'reconnect')
193
+ await session.resume();
194
+ }
195
+ async requireSession(runId, requestedRemoteSessionId) {
196
+ const active = this.sessions.get(runId);
197
+ if (active)
198
+ return active;
199
+ const stored = this.options.state.getSession(runId);
200
+ if (!stored)
201
+ throw new Error(`remote session not found for run ${runId}`);
202
+ if (requestedRemoteSessionId && requestedRemoteSessionId !== stored.remoteSessionId)
203
+ throw new Error('reconnect session does not match persisted session');
204
+ const scope = await resolveFilesystemScope(this.options.filesystem, stored.workingDirectory);
205
+ const session = await this.requireAdapter(stored.adapterId).start({
206
+ runId, workingDirectory: scope.workingDirectory, additionalDirectories: scope.additionalDirectories,
207
+ prompt: '', remoteSessionId: stored.remoteSessionId, metadata: {},
208
+ adapterState: this.options.state.getAdapterSessionState(runId, stored.adapterId),
209
+ persistAdapterState: (state) => this.options.state.saveAdapterSessionState(runId, stored.adapterId, state),
210
+ }, (event) => this.emit(runId, event));
211
+ this.sessions.set(runId, session);
212
+ return session;
213
+ }
214
+ requireAdapter(adapterId) {
215
+ const adapter = this.adapters.get(adapterId);
216
+ if (!adapter)
217
+ throw new Error(`adapter is not installed: ${adapterId}`);
218
+ return adapter;
219
+ }
220
+ async emit(runId, event) {
221
+ if (this.options.state.outboxSize() >= (this.options.maxOutboxEvents ?? 10_000)) {
222
+ throw new Error('event outbox backpressure limit reached');
223
+ }
224
+ const stored = {
225
+ protocolVersion: OVERLAY_AGENT_PROTOCOL_VERSION,
226
+ eventId: randomUUID(), environmentId: this.options.environmentId, runId,
227
+ occurredAt: Date.now(), ...event,
228
+ };
229
+ this.options.state.appendEvent(stored);
230
+ try {
231
+ await this.flushOutbox();
232
+ }
233
+ catch (error) {
234
+ this.logger.warn('event upload deferred', { runId, error: safeError(error) });
235
+ }
236
+ }
237
+ acknowledge(command, accepted, message, errorCode = 'command_rejected') {
238
+ return this.options.controlPlane.acknowledgeCommand({
239
+ protocolVersion: OVERLAY_AGENT_PROTOCOL_VERSION,
240
+ commandId: command.commandId,
241
+ environmentId: this.options.environmentId,
242
+ accepted,
243
+ ...(!accepted ? { error: { code: errorCode, message: message ?? 'command rejected' } } : {}),
244
+ });
245
+ }
246
+ }
247
+ function safeError(error) { return error instanceof Error ? error.message.slice(0, 2_000) : 'Unknown host error'; }
248
+ function abortableDelay(milliseconds, signal) {
249
+ return new Promise((resolve, reject) => {
250
+ const timer = setTimeout(resolve, milliseconds);
251
+ signal.addEventListener('abort', () => { clearTimeout(timer); reject(signal.reason); }, { once: true });
252
+ });
253
+ }
254
+ //# sourceMappingURL=runtime.js.map