agent-embassy 2.0.1 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/CONTRIBUTING.md +23 -36
  3. package/README.md +123 -222
  4. package/SECURITY.md +72 -93
  5. package/dist/src/errors.d.ts +10 -1
  6. package/dist/src/errors.js +3 -1
  7. package/dist/src/errors.js.map +1 -1
  8. package/dist/src/gateway/claude-helper-protocol.d.ts +8 -11
  9. package/dist/src/gateway/claude-helper-protocol.js +12 -11
  10. package/dist/src/gateway/claude-helper-protocol.js.map +1 -1
  11. package/dist/src/gateway/claude-helper-supervisor.d.ts +1 -5
  12. package/dist/src/gateway/claude-helper-supervisor.js +45 -17
  13. package/dist/src/gateway/claude-helper-supervisor.js.map +1 -1
  14. package/dist/src/gateway/claude-helper.js +6 -6
  15. package/dist/src/gateway/claude-helper.js.map +1 -1
  16. package/dist/src/gateway/claude-peer.d.ts +0 -3
  17. package/dist/src/gateway/claude-peer.js +7 -19
  18. package/dist/src/gateway/claude-peer.js.map +1 -1
  19. package/dist/src/gateway/cli.d.ts +17 -7
  20. package/dist/src/gateway/cli.js +945 -265
  21. package/dist/src/gateway/cli.js.map +1 -1
  22. package/dist/src/gateway/codex-socket-holder.d.ts +26 -0
  23. package/dist/src/gateway/codex-socket-holder.js +76 -0
  24. package/dist/src/gateway/codex-socket-holder.js.map +1 -0
  25. package/dist/src/gateway/codex-stateless-transport.js +1 -1
  26. package/dist/src/gateway/codex-stateless-transport.js.map +1 -1
  27. package/dist/src/gateway/config.d.ts +1 -10
  28. package/dist/src/gateway/config.js +4 -10
  29. package/dist/src/gateway/config.js.map +1 -1
  30. package/dist/src/gateway/control.d.ts +66 -80
  31. package/dist/src/gateway/control.js +92 -147
  32. package/dist/src/gateway/control.js.map +1 -1
  33. package/dist/src/gateway/federation-nodes.d.ts +29 -2
  34. package/dist/src/gateway/federation-nodes.js +177 -7
  35. package/dist/src/gateway/federation-nodes.js.map +1 -1
  36. package/dist/src/gateway/peer-client.d.ts +4 -3
  37. package/dist/src/gateway/peer-client.js +22 -13
  38. package/dist/src/gateway/peer-client.js.map +1 -1
  39. package/dist/src/gateway/peer-protocol.d.ts +13 -11
  40. package/dist/src/gateway/peer-protocol.js +14 -12
  41. package/dist/src/gateway/peer-protocol.js.map +1 -1
  42. package/dist/src/gateway/provenance-envelope.d.ts +0 -1
  43. package/dist/src/gateway/provenance-envelope.js +4 -19
  44. package/dist/src/gateway/provenance-envelope.js.map +1 -1
  45. package/dist/src/gateway/providers.d.ts +11 -7
  46. package/dist/src/gateway/providers.js +49 -50
  47. package/dist/src/gateway/providers.js.map +1 -1
  48. package/dist/src/gateway/server.d.ts +4 -14
  49. package/dist/src/gateway/server.js +32 -54
  50. package/dist/src/gateway/server.js.map +1 -1
  51. package/dist/src/gateway/service-agent.d.ts +187 -0
  52. package/dist/src/gateway/service-agent.js +758 -0
  53. package/dist/src/gateway/service-agent.js.map +1 -0
  54. package/dist/src/gateway/service.d.ts +119 -38
  55. package/dist/src/gateway/service.js +754 -798
  56. package/dist/src/gateway/service.js.map +1 -1
  57. package/dist/src/gateway/status-view.d.ts +119 -0
  58. package/dist/src/gateway/status-view.js +484 -0
  59. package/dist/src/gateway/status-view.js.map +1 -0
  60. package/dist/src/gateway/store.d.ts +106 -21
  61. package/dist/src/gateway/store.js +463 -537
  62. package/dist/src/gateway/store.js.map +1 -1
  63. package/dist/src/gateway/types.d.ts +64 -102
  64. package/dist/src/gateway/types.js +40 -86
  65. package/dist/src/gateway/types.js.map +1 -1
  66. package/docs/CONFIGURATION.md +174 -45
  67. package/docs/DELIVERY.md +11 -11
  68. package/docs/GATEWAY-ARCHITECTURE.md +292 -384
  69. package/package.json +4 -12
  70. package/skills/embassy-peer/SKILL.md +69 -92
  71. package/skills/embassy-peer/agents/openai.yaml +1 -1
  72. package/README.zh-CN.md +0 -275
  73. package/assets/live-dashboard/app.css +0 -1619
  74. package/assets/vendor/react/LICENSE +0 -21
  75. package/assets/vendor/react/react-dom.production.min.js +0 -267
  76. package/assets/vendor/react/react.production.min.js +0 -31
  77. package/dist/src/gateway/acp-client.d.ts +0 -110
  78. package/dist/src/gateway/acp-client.js +0 -407
  79. package/dist/src/gateway/acp-client.js.map +0 -1
  80. package/dist/src/gateway/acp-provider.d.ts +0 -66
  81. package/dist/src/gateway/acp-provider.js +0 -275
  82. package/dist/src/gateway/acp-provider.js.map +0 -1
  83. package/dist/src/gateway/claude-helper-client.d.ts +0 -2
  84. package/dist/src/gateway/claude-helper-client.js +0 -2
  85. package/dist/src/gateway/claude-helper-client.js.map +0 -1
  86. package/dist/src/gateway/cli-copy.d.ts +0 -8
  87. package/dist/src/gateway/cli-copy.en.d.ts +0 -22
  88. package/dist/src/gateway/cli-copy.en.js +0 -62
  89. package/dist/src/gateway/cli-copy.en.js.map +0 -1
  90. package/dist/src/gateway/cli-copy.js +0 -27
  91. package/dist/src/gateway/cli-copy.js.map +0 -1
  92. package/dist/src/gateway/cli-copy.zh-CN.d.ts +0 -22
  93. package/dist/src/gateway/cli-copy.zh-CN.js +0 -62
  94. package/dist/src/gateway/cli-copy.zh-CN.js.map +0 -1
  95. package/dist/src/gateway/codex-doctor.d.ts +0 -36
  96. package/dist/src/gateway/codex-doctor.js +0 -127
  97. package/dist/src/gateway/codex-doctor.js.map +0 -1
  98. package/dist/src/gateway/dashboard-copy.d.ts +0 -7
  99. package/dist/src/gateway/dashboard-copy.en.d.ts +0 -504
  100. package/dist/src/gateway/dashboard-copy.en.js +0 -505
  101. package/dist/src/gateway/dashboard-copy.en.js.map +0 -1
  102. package/dist/src/gateway/dashboard-copy.js +0 -514
  103. package/dist/src/gateway/dashboard-copy.js.map +0 -1
  104. package/dist/src/gateway/dashboard-copy.zh-CN.d.ts +0 -504
  105. package/dist/src/gateway/dashboard-copy.zh-CN.js +0 -505
  106. package/dist/src/gateway/dashboard-copy.zh-CN.js.map +0 -1
  107. package/dist/src/gateway/dashboard-model.d.ts +0 -343
  108. package/dist/src/gateway/dashboard-model.js +0 -1061
  109. package/dist/src/gateway/dashboard-model.js.map +0 -1
  110. package/dist/src/gateway/dashboard.d.ts +0 -20
  111. package/dist/src/gateway/dashboard.js +0 -874
  112. package/dist/src/gateway/dashboard.js.map +0 -1
  113. package/dist/src/gateway/deepseek-detect.d.ts +0 -14
  114. package/dist/src/gateway/deepseek-detect.js +0 -41
  115. package/dist/src/gateway/deepseek-detect.js.map +0 -1
  116. package/dist/src/gateway/live-dashboard-app/app.js +0 -2385
  117. package/dist/src/gateway/live-dashboard-assets.d.ts +0 -10
  118. package/dist/src/gateway/live-dashboard-assets.js +0 -74
  119. package/dist/src/gateway/live-dashboard-assets.js.map +0 -1
  120. package/dist/src/gateway/live-dashboard-command.d.ts +0 -60
  121. package/dist/src/gateway/live-dashboard-command.js +0 -334
  122. package/dist/src/gateway/live-dashboard-command.js.map +0 -1
  123. package/dist/src/gateway/live-dashboard-http.d.ts +0 -39
  124. package/dist/src/gateway/live-dashboard-http.js +0 -383
  125. package/dist/src/gateway/live-dashboard-http.js.map +0 -1
  126. package/dist/src/gateway/live-dashboard-protocol.d.ts +0 -34
  127. package/dist/src/gateway/live-dashboard-protocol.js +0 -114
  128. package/dist/src/gateway/live-dashboard-protocol.js.map +0 -1
  129. package/dist/src/gateway/live-dashboard-server.d.ts +0 -33
  130. package/dist/src/gateway/live-dashboard-server.js +0 -144
  131. package/dist/src/gateway/live-dashboard-server.js.map +0 -1
  132. package/dist/src/gateway/live-dashboard-stream.d.ts +0 -46
  133. package/dist/src/gateway/live-dashboard-stream.js +0 -234
  134. package/dist/src/gateway/live-dashboard-stream.js.map +0 -1
  135. package/dist/src/gateway/live-dashboard.d.ts +0 -28
  136. package/dist/src/gateway/live-dashboard.js +0 -154
  137. package/dist/src/gateway/live-dashboard.js.map +0 -1
  138. package/dist/src/gateway/locale.d.ts +0 -4
  139. package/dist/src/gateway/locale.js +0 -10
  140. package/dist/src/gateway/locale.js.map +0 -1
  141. package/dist/src/gateway/progress-watch-machine.d.ts +0 -45
  142. package/dist/src/gateway/progress-watch-machine.js +0 -70
  143. package/dist/src/gateway/progress-watch-machine.js.map +0 -1
  144. package/docs/CONFIGURATION.zh-CN.md +0 -97
  145. package/docs/DASHBOARD.md +0 -98
  146. package/docs/DASHBOARD.zh-CN.md +0 -49
  147. package/docs/DELIVERY.zh-CN.md +0 -55
@@ -0,0 +1,187 @@
1
+ export declare const SERVICE_AGENT_LABEL = "com.agent-embassy.broker";
2
+ export type LaunchAgentPlistOptions = Readonly<{
3
+ label: string;
4
+ programArguments: readonly string[];
5
+ logPath: string;
6
+ /** Already-captured, already-validated agent environment (see captureAgentEnvironment). */
7
+ environment: Readonly<Record<string, string>>;
8
+ }>;
9
+ /**
10
+ * Render the launchd agent plist.
11
+ *
12
+ * `KeepAlive` is `{ Crashed: true }`, never plain `true`. Per launchd.plist(5)
13
+ * `Crashed` relaunches the job only when it died from a signal typically
14
+ * associated with a crash — SIGSEGV, SIGBUS, SIGILL, SIGABRT. Nothing else
15
+ * brings it back: not a clean exit, not a non-zero exit, not a plain `kill`
16
+ * (SIGTERM), and not one of the broker's deliberate boot refusals (an
17
+ * unsupported state schema, another instance already holding the lease).
18
+ * Under plain `KeepAlive` every one of those refusals would relaunch forever,
19
+ * throttled to once every 5 seconds, into one log file that nothing rotates.
20
+ * A refusal now exits once and stays down, where `embassy service status` and
21
+ * the log can explain it. ThrottleInterval still bounds a genuine crash loop.
22
+ *
23
+ * EnvironmentVariables carries exactly the captured configuration keys and
24
+ * nothing else — see captureAgentEnvironment for the rule. PATH is not
25
+ * needed (every child process this broker spawns — the codex standalone
26
+ * binary, /bin/ps, /usr/bin/lockf, /bin/cat — is invoked by an absolute path
27
+ * already; see codex-local-transport.ts, claude-peer.ts, and
28
+ * instance-lease.ts).
29
+ */
30
+ export declare function renderLaunchAgentPlist(options: LaunchAgentPlistOptions): string;
31
+ export type RunLaunchctlResult = Readonly<{
32
+ code: number;
33
+ stdout: string;
34
+ stderr: string;
35
+ }>;
36
+ export type RunLaunchctl = (args: readonly string[]) => RunLaunchctlResult | Promise<RunLaunchctlResult>;
37
+ export type ServiceAgentDependencies = Readonly<{
38
+ homeDir: string;
39
+ runLaunchctl: RunLaunchctl;
40
+ env: NodeJS.ProcessEnv;
41
+ execPath: string;
42
+ cliPath: string;
43
+ uid: number;
44
+ /** Bounded waits for launchd to finish unloading; injected by tests. */
45
+ delay?: (milliseconds: number) => Promise<void>;
46
+ now?: () => number;
47
+ /**
48
+ * The host-lease probe. The default spawns /usr/bin/lockf through
49
+ * instance-lease.ts and so only answers on macOS; tests inject a fake.
50
+ */
51
+ probeHostLease?: ProbeHostLease;
52
+ }>;
53
+ export type ServiceAgentPaths = Readonly<{
54
+ launchAgentsDir: string;
55
+ logsDir: string;
56
+ plistPath: string;
57
+ logPath: string;
58
+ }>;
59
+ export declare function serviceAgentPaths(homeDir: string): ServiceAgentPaths;
60
+ /**
61
+ * stderr only, trimmed, and capped — never launchctl's stdout. Everything the
62
+ * service path puts on the CLI's stderr goes through this, including the
63
+ * errno text of a filesystem failure the CLI itself renders.
64
+ */
65
+ export declare function boundedServiceDetail(text: string): string;
66
+ /**
67
+ * The environment the installed agent runs with. launchd agents inherit
68
+ * almost nothing, so Embassy's own configuration has to be copied into the
69
+ * plist: every `EMBASSY_*` variable (EMBASSY_STATE_DIR included) plus
70
+ * XDG_STATE_HOME, which decides the state root when EMBASSY_STATE_DIR is
71
+ * unset. These are configuration, not secrets — but nothing else is copied,
72
+ * so an inherited API key or token cannot reach the plist.
73
+ *
74
+ * Both state roots must be absolute here, before capture: a relative value
75
+ * resolves against the installing shell's working directory, and the agent
76
+ * would silently resolve it somewhere else.
77
+ */
78
+ export declare function captureAgentEnvironment(env: NodeJS.ProcessEnv): Readonly<Record<string, string>>;
79
+ /**
80
+ * Read the lease holder's pid under the same discipline instance-lease.ts
81
+ * applies in readPrivateFile: lstat first, regular file only, this user's
82
+ * own, size-bounded, opened O_NOFOLLOW and re-verified against the same
83
+ * inode. This value only decorates a refusal message, but it is read out of
84
+ * a file another process writes, so it gets the same care.
85
+ */
86
+ /**
87
+ * Read a small private record this user owns, or nothing at all. Never
88
+ * throws, and never follows anything: the path is lstat'd, refused unless it
89
+ * is a regular file this uid owns within the byte bound, opened O_NOFOLLOW,
90
+ * and re-verified through the open handle by (dev, ino, uid, size) so the
91
+ * file that was checked is the file that was read. A uid of `undefined` — a
92
+ * platform with no `getuid` — skips only the ownership half.
93
+ *
94
+ * Both readers of a private record go through here: the host lease's pid
95
+ * below, and `readGatewayControllerPid` in cli.ts.
96
+ */
97
+ export declare function readOwnedSmallFile(filePath: string, uid: number | undefined, maximumBytes: number): Promise<string | undefined>;
98
+ /** The pid recorded in a JSON record, or nothing when it names none. */
99
+ export declare function recordedPid(raw: string | undefined): number | undefined;
100
+ /**
101
+ * What the host-wide lease says right now. `pid` is present only when a
102
+ * *live* holder was identified; `message` is the lease's own words for why it
103
+ * could not be taken.
104
+ */
105
+ export type HostLeaseProbe = Readonly<{
106
+ held: false;
107
+ }> | Readonly<{
108
+ held: true;
109
+ pid?: number;
110
+ message: string;
111
+ }>;
112
+ export type ProbeHostLease = (homeDir: string, uid: number) => Promise<HostLeaseProbe>;
113
+ /**
114
+ * The production probe, and the reason this is an injected dependency at all.
115
+ * It reuses the exact detection the broker relies on for single-instance
116
+ * correctness — a non-blocking acquire of the host-wide advisory lease
117
+ * (acquireGatewayInstanceLease, unmodified), released immediately when nobody
118
+ * holds it. That helper spawns /usr/bin/lockf, which exists only on macOS, so
119
+ * on any other platform it reports contention that is really a missing
120
+ * binary. The product is macOS-only and that is correct in production, but it
121
+ * makes every install path untestable off darwin; tests inject a fake probe
122
+ * and one darwin-only test drives this default.
123
+ *
124
+ * `GATEWAY_INSTANCE_IN_USE` is not only contention: instance-lease.ts throws
125
+ * it for roughly ten conditions that have nothing to do with another broker
126
+ * (a symlinked path component, a non-empty unmarked lease root, a mode or
127
+ * owner drift). So its message is always carried out of here unchanged, and a
128
+ * pid is reported only when the recorded holder is genuinely alive — the lock
129
+ * record keeps the *last* holder, and a successful probe writes its own pid
130
+ * there, so an unchecked pid is routinely stale. Never tell someone to stop
131
+ * a dead process.
132
+ */
133
+ export declare function defaultProbeHostLease(homeDir: string, uid: number): Promise<HostLeaseProbe>;
134
+ export type ServiceAgentInstallResult = Readonly<{
135
+ label: string;
136
+ plistPath: string;
137
+ logPath: string;
138
+ /** Names only: the configuration keys copied into the plist at install time. */
139
+ capturedEnv: readonly string[];
140
+ }>;
141
+ /**
142
+ * Register the broker as this user's launchd agent. Re-running it over a
143
+ * prior install — including one that is loaded and running right now — is
144
+ * the supported way to change what the agent runs with.
145
+ */
146
+ export declare function installServiceAgent(deps: ServiceAgentDependencies): Promise<ServiceAgentInstallResult>;
147
+ export type ServiceAgentUninstallResult = Readonly<{
148
+ label: string;
149
+ plistPath: string;
150
+ logPath: string;
151
+ }>;
152
+ /**
153
+ * Boot the agent out, confirm that launchctl reports the label as *not
154
+ * found*, and only then unlink the plist. The confirmation must be that exact
155
+ * answer: treating any launchctl error (a missing binary, a gui domain that
156
+ * is not up, a timeout) as "gone" would unlink the plist while the agent is
157
+ * still loaded — invisible to `install`, unstoppable by `uninstall`. Logs are
158
+ * left in place.
159
+ */
160
+ export declare function uninstallServiceAgent(deps: ServiceAgentDependencies): Promise<ServiceAgentUninstallResult>;
161
+ export type ServiceAgentStatusState = "loaded" | "not loaded" | "unknown";
162
+ export type ServiceAgentStatus = Readonly<{
163
+ label: string;
164
+ plistPath: string;
165
+ logPath: string;
166
+ plistExists: boolean;
167
+ state: ServiceAgentStatusState;
168
+ pid?: number;
169
+ launchdState?: string;
170
+ lastExitStatus?: number;
171
+ /** ProgramArguments[0]/[1] that are no longer on disk (a version manager moved node). */
172
+ programMissing?: readonly string[];
173
+ /** launchctl's stderr, trimmed and capped at 512 bytes; its stdout is never quoted. */
174
+ launchctlStderr?: string;
175
+ note: string;
176
+ }>;
177
+ /**
178
+ * Report what is actually knowable. A launchctl that cannot run, or output
179
+ * this version does not recognize, is `unknown` with the reason quoted — not
180
+ * "not loaded", and not "loaded" with blank fields. The plist's own
181
+ * ProgramArguments are checked against the filesystem too: a node binary
182
+ * under a version manager can be removed out from under an installed agent,
183
+ * which launchd otherwise reports only as a repeated spawn failure.
184
+ */
185
+ export declare function serviceAgentStatus(deps: ServiceAgentDependencies): Promise<ServiceAgentStatus>;
186
+ /** The one production launchctl call site; every other reference to it in this module is through this runner. */
187
+ export declare function defaultRunLaunchctl(args: readonly string[]): Promise<RunLaunchctlResult>;