agent-embassy 1.0.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 (145) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/CONTRIBUTING.md +122 -0
  3. package/LICENSE +21 -0
  4. package/README.md +185 -0
  5. package/README.zh-CN.md +185 -0
  6. package/SECURITY.md +224 -0
  7. package/assets/live-dashboard/app.css +1610 -0
  8. package/assets/mark-seal.svg +7 -0
  9. package/assets/mark.svg +7 -0
  10. package/assets/social-preview.png +0 -0
  11. package/assets/vendor/react/LICENSE +21 -0
  12. package/assets/vendor/react/react-dom.production.min.js +267 -0
  13. package/assets/vendor/react/react.production.min.js +31 -0
  14. package/dist/src/errors.d.ts +5 -0
  15. package/dist/src/errors.js +11 -0
  16. package/dist/src/errors.js.map +1 -0
  17. package/dist/src/gateway/claude-compatibility-scratch.d.ts +18 -0
  18. package/dist/src/gateway/claude-compatibility-scratch.js +158 -0
  19. package/dist/src/gateway/claude-compatibility-scratch.js.map +1 -0
  20. package/dist/src/gateway/claude-helper-client.d.ts +43 -0
  21. package/dist/src/gateway/claude-helper-client.js +212 -0
  22. package/dist/src/gateway/claude-helper-client.js.map +1 -0
  23. package/dist/src/gateway/claude-helper-protocol.d.ts +172 -0
  24. package/dist/src/gateway/claude-helper-protocol.js +373 -0
  25. package/dist/src/gateway/claude-helper-protocol.js.map +1 -0
  26. package/dist/src/gateway/claude-helper-supervisor.d.ts +74 -0
  27. package/dist/src/gateway/claude-helper-supervisor.js +497 -0
  28. package/dist/src/gateway/claude-helper-supervisor.js.map +1 -0
  29. package/dist/src/gateway/claude-helper.d.ts +1 -0
  30. package/dist/src/gateway/claude-helper.js +269 -0
  31. package/dist/src/gateway/claude-helper.js.map +1 -0
  32. package/dist/src/gateway/claude-peer.d.ts +273 -0
  33. package/dist/src/gateway/claude-peer.js +2359 -0
  34. package/dist/src/gateway/claude-peer.js.map +1 -0
  35. package/dist/src/gateway/claude-runtime.d.ts +40 -0
  36. package/dist/src/gateway/claude-runtime.js +302 -0
  37. package/dist/src/gateway/claude-runtime.js.map +1 -0
  38. package/dist/src/gateway/cli-copy.d.ts +8 -0
  39. package/dist/src/gateway/cli-copy.en.d.ts +13 -0
  40. package/dist/src/gateway/cli-copy.en.js +43 -0
  41. package/dist/src/gateway/cli-copy.en.js.map +1 -0
  42. package/dist/src/gateway/cli-copy.js +19 -0
  43. package/dist/src/gateway/cli-copy.js.map +1 -0
  44. package/dist/src/gateway/cli-copy.zh-CN.d.ts +13 -0
  45. package/dist/src/gateway/cli-copy.zh-CN.js +43 -0
  46. package/dist/src/gateway/cli-copy.zh-CN.js.map +1 -0
  47. package/dist/src/gateway/cli.d.ts +44 -0
  48. package/dist/src/gateway/cli.js +969 -0
  49. package/dist/src/gateway/cli.js.map +1 -0
  50. package/dist/src/gateway/codex-app-server.d.ts +310 -0
  51. package/dist/src/gateway/codex-app-server.js +1746 -0
  52. package/dist/src/gateway/codex-app-server.js.map +1 -0
  53. package/dist/src/gateway/codex-local-transport.d.ts +81 -0
  54. package/dist/src/gateway/codex-local-transport.js +617 -0
  55. package/dist/src/gateway/codex-local-transport.js.map +1 -0
  56. package/dist/src/gateway/codex-registration-generation.d.ts +5 -0
  57. package/dist/src/gateway/codex-registration-generation.js +19 -0
  58. package/dist/src/gateway/codex-registration-generation.js.map +1 -0
  59. package/dist/src/gateway/codex-registration-succession.d.ts +209 -0
  60. package/dist/src/gateway/codex-registration-succession.js +588 -0
  61. package/dist/src/gateway/codex-registration-succession.js.map +1 -0
  62. package/dist/src/gateway/compatibility.d.ts +70 -0
  63. package/dist/src/gateway/compatibility.js +252 -0
  64. package/dist/src/gateway/compatibility.js.map +1 -0
  65. package/dist/src/gateway/config.d.ts +24 -0
  66. package/dist/src/gateway/config.js +130 -0
  67. package/dist/src/gateway/config.js.map +1 -0
  68. package/dist/src/gateway/control.d.ts +308 -0
  69. package/dist/src/gateway/control.js +1573 -0
  70. package/dist/src/gateway/control.js.map +1 -0
  71. package/dist/src/gateway/dashboard-copy.d.ts +7 -0
  72. package/dist/src/gateway/dashboard-copy.en.d.ts +506 -0
  73. package/dist/src/gateway/dashboard-copy.en.js +507 -0
  74. package/dist/src/gateway/dashboard-copy.en.js.map +1 -0
  75. package/dist/src/gateway/dashboard-copy.js +516 -0
  76. package/dist/src/gateway/dashboard-copy.js.map +1 -0
  77. package/dist/src/gateway/dashboard-copy.zh-CN.d.ts +506 -0
  78. package/dist/src/gateway/dashboard-copy.zh-CN.js +507 -0
  79. package/dist/src/gateway/dashboard-copy.zh-CN.js.map +1 -0
  80. package/dist/src/gateway/dashboard-model.d.ts +207 -0
  81. package/dist/src/gateway/dashboard-model.js +720 -0
  82. package/dist/src/gateway/dashboard-model.js.map +1 -0
  83. package/dist/src/gateway/dashboard.d.ts +26 -0
  84. package/dist/src/gateway/dashboard.js +941 -0
  85. package/dist/src/gateway/dashboard.js.map +1 -0
  86. package/dist/src/gateway/delivery-machine.d.ts +235 -0
  87. package/dist/src/gateway/delivery-machine.js +540 -0
  88. package/dist/src/gateway/delivery-machine.js.map +1 -0
  89. package/dist/src/gateway/instance-lease.d.ts +21 -0
  90. package/dist/src/gateway/instance-lease.js +549 -0
  91. package/dist/src/gateway/instance-lease.js.map +1 -0
  92. package/dist/src/gateway/live-dashboard-app/app.js +2914 -0
  93. package/dist/src/gateway/live-dashboard-assets.d.ts +10 -0
  94. package/dist/src/gateway/live-dashboard-assets.js +73 -0
  95. package/dist/src/gateway/live-dashboard-assets.js.map +1 -0
  96. package/dist/src/gateway/live-dashboard-bootstrap.d.ts +36 -0
  97. package/dist/src/gateway/live-dashboard-bootstrap.js +176 -0
  98. package/dist/src/gateway/live-dashboard-bootstrap.js.map +1 -0
  99. package/dist/src/gateway/live-dashboard-command.d.ts +54 -0
  100. package/dist/src/gateway/live-dashboard-command.js +324 -0
  101. package/dist/src/gateway/live-dashboard-command.js.map +1 -0
  102. package/dist/src/gateway/live-dashboard-http.d.ts +41 -0
  103. package/dist/src/gateway/live-dashboard-http.js +445 -0
  104. package/dist/src/gateway/live-dashboard-http.js.map +1 -0
  105. package/dist/src/gateway/live-dashboard-protocol.d.ts +38 -0
  106. package/dist/src/gateway/live-dashboard-protocol.js +156 -0
  107. package/dist/src/gateway/live-dashboard-protocol.js.map +1 -0
  108. package/dist/src/gateway/live-dashboard-server.d.ts +33 -0
  109. package/dist/src/gateway/live-dashboard-server.js +130 -0
  110. package/dist/src/gateway/live-dashboard-server.js.map +1 -0
  111. package/dist/src/gateway/live-dashboard-stream.d.ts +46 -0
  112. package/dist/src/gateway/live-dashboard-stream.js +233 -0
  113. package/dist/src/gateway/live-dashboard-stream.js.map +1 -0
  114. package/dist/src/gateway/live-dashboard.d.ts +31 -0
  115. package/dist/src/gateway/live-dashboard.js +190 -0
  116. package/dist/src/gateway/live-dashboard.js.map +1 -0
  117. package/dist/src/gateway/locale.d.ts +4 -0
  118. package/dist/src/gateway/locale.js +10 -0
  119. package/dist/src/gateway/locale.js.map +1 -0
  120. package/dist/src/gateway/progress-watch-machine.d.ts +97 -0
  121. package/dist/src/gateway/progress-watch-machine.js +172 -0
  122. package/dist/src/gateway/progress-watch-machine.js.map +1 -0
  123. package/dist/src/gateway/providers.d.ts +287 -0
  124. package/dist/src/gateway/providers.js +2451 -0
  125. package/dist/src/gateway/providers.js.map +1 -0
  126. package/dist/src/gateway/server.d.ts +57 -0
  127. package/dist/src/gateway/server.js +264 -0
  128. package/dist/src/gateway/server.js.map +1 -0
  129. package/dist/src/gateway/service.d.ts +449 -0
  130. package/dist/src/gateway/service.js +4831 -0
  131. package/dist/src/gateway/service.js.map +1 -0
  132. package/dist/src/gateway/store.d.ts +340 -0
  133. package/dist/src/gateway/store.js +4047 -0
  134. package/dist/src/gateway/store.js.map +1 -0
  135. package/dist/src/gateway/types.d.ts +514 -0
  136. package/dist/src/gateway/types.js +414 -0
  137. package/dist/src/gateway/types.js.map +1 -0
  138. package/dist/src/mutex.d.ts +4 -0
  139. package/dist/src/mutex.js +23 -0
  140. package/dist/src/mutex.js.map +1 -0
  141. package/docs/DESIGN.md +134 -0
  142. package/docs/GATEWAY-ARCHITECTURE.md +858 -0
  143. package/package.json +80 -0
  144. package/skills/embassy-peer/SKILL.md +198 -0
  145. package/skills/embassy-peer/agents/openai.yaml +4 -0
@@ -0,0 +1,19 @@
1
+ import { randomBytes } from "node:crypto";
2
+ const CODEX_REGISTRATION_GENERATION_PATTERN = /^[A-Za-z0-9][A-Za-z0-9_-]{0,31}$/u;
3
+ /** Closed grammar for opaque Codex listener and succession generations. */
4
+ export function isCodexRegistrationGeneration(value) {
5
+ return (typeof value === "string" &&
6
+ CODEX_REGISTRATION_GENERATION_PATTERN.test(value));
7
+ }
8
+ export function assertCodexRegistrationGeneration(value, label = "Codex registration generation") {
9
+ if (!isCodexRegistrationGeneration(value)) {
10
+ throw new TypeError(`${label} must match the bounded opaque generation grammar.`);
11
+ }
12
+ }
13
+ /** A fresh 128-bit token that is safe in the closed generation grammar. */
14
+ export function createCodexRegistrationGeneration() {
15
+ const generation = `g_${randomBytes(16).toString("base64url")}`;
16
+ assertCodexRegistrationGeneration(generation);
17
+ return generation;
18
+ }
19
+ //# sourceMappingURL=codex-registration-generation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codex-registration-generation.js","sourceRoot":"","sources":["../../../src/gateway/codex-registration-generation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,MAAM,qCAAqC,GACzC,mCAAmC,CAAC;AAEtC,2EAA2E;AAC3E,MAAM,UAAU,6BAA6B,CAC3C,KAAc;IAEd,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,qCAAqC,CAAC,IAAI,CAAC,KAAK,CAAC,CAClD,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,iCAAiC,CAC/C,KAAc,EACd,KAAK,GAAG,+BAA+B;IAEvC,IAAI,CAAC,6BAA6B,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1C,MAAM,IAAI,SAAS,CACjB,GAAG,KAAK,oDAAoD,CAC7D,CAAC;IACJ,CAAC;AACH,CAAC;AAED,2EAA2E;AAC3E,MAAM,UAAU,iCAAiC;IAC/C,MAAM,UAAU,GAAG,KAAK,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;IAChE,iCAAiC,CAAC,UAAU,CAAC,CAAC;IAC9C,OAAO,UAAU,CAAC;AACpB,CAAC"}
@@ -0,0 +1,209 @@
1
+ /**
2
+ * Pure lifecycle for replacing one registered Codex task with another.
3
+ *
4
+ * The reducer owns no sockets, registry files, message bodies, conversations,
5
+ * timers, or provider clients. A controller executes the returned effects and
6
+ * feeds the resulting observations back as events. Listener generations are
7
+ * deliberately opaque; this module never derives a socket path or assumes a
8
+ * suffixed-socket naming scheme.
9
+ *
10
+ * Publication arming is the conservative irreversible boundary: the reducer
11
+ * enters it before emitting any durable-journal or registry-write effect.
12
+ * Cleanup may restore the old registration only before arming, or after a
13
+ * controller positively proves that neither the arm nor registry write was
14
+ * persisted. At or after any armed/published/unknown observation, the old
15
+ * registration can never be restored by this machine.
16
+ */
17
+ export declare const codexRegistrationSuccessionPhases: readonly ["active_old", "freezing", "prepared_new", "published_new", "active_new", "offline_poisoned", "recovery_required", "resuming_old"];
18
+ export type CodexRegistrationSuccessionPhase = (typeof codexRegistrationSuccessionPhases)[number];
19
+ export type CodexRegistrationIdentity = Readonly<{
20
+ alias: string;
21
+ threadId: string;
22
+ hostId: string;
23
+ generation: string;
24
+ }>;
25
+ type StablePhase = "active_old" | "active_new";
26
+ type FreezingStage = "barrier_pending" | "listener_pending" | "store_pending";
27
+ type PublicationBoundary = "not_armed" | "armed_or_unknown" | "published";
28
+ export declare const codexSuccessionFailurePhases: readonly ["freeze", "barrier", "listener", "store", "publication_arm", "registry", "activation", "retirement", "cleanup", "resume"];
29
+ export type CodexSuccessionFailurePhase = (typeof codexSuccessionFailurePhases)[number];
30
+ type SuccessionContext = Readonly<{
31
+ oldRegistration: CodexRegistrationIdentity;
32
+ newRegistration: CodexRegistrationIdentity;
33
+ priorStablePhase: StablePhase;
34
+ }>;
35
+ export type ActiveOldSuccessionState = Readonly<{
36
+ phase: "active_old";
37
+ active: CodexRegistrationIdentity;
38
+ }>;
39
+ export type ActiveNewSuccessionState = Readonly<{
40
+ phase: "active_new";
41
+ active: CodexRegistrationIdentity;
42
+ /** At most one prior listener generation may await confirmed retirement. */
43
+ retired: CodexRegistrationIdentity | null;
44
+ }>;
45
+ export type FreezingSuccessionState = SuccessionContext & Readonly<{
46
+ phase: "freezing";
47
+ stage: FreezingStage;
48
+ }>;
49
+ export type PreparedNewSuccessionState = SuccessionContext & Readonly<{
50
+ phase: "prepared_new";
51
+ /**
52
+ * `publication_arming` begins the rollback-forbidden window before the
53
+ * durable journal effect is executed. `registry_publishing` means the arm
54
+ * was confirmed and the registry write may be in flight.
55
+ */
56
+ stage: "publication_arming" | "registry_publishing";
57
+ }>;
58
+ export type PublishedNewSuccessionState = SuccessionContext & Readonly<{
59
+ phase: "published_new";
60
+ }>;
61
+ export type OfflinePoisonedSuccessionState = SuccessionContext & Readonly<{
62
+ phase: "offline_poisoned";
63
+ failedPhase: CodexSuccessionFailurePhase | "abort" | "barrier_busy";
64
+ safeErrorCode: string;
65
+ rollback: "old_allowed" | "forbidden";
66
+ publicationBoundary: PublicationBoundary;
67
+ }>;
68
+ export type RecoveryRequiredSuccessionState = SuccessionContext & Readonly<{
69
+ phase: "recovery_required";
70
+ failedPhase: CodexSuccessionFailurePhase | "abort" | "barrier_busy";
71
+ safeErrorCode: string;
72
+ rollback: "old_allowed" | "forbidden";
73
+ publicationBoundary: PublicationBoundary;
74
+ }>;
75
+ export type ResumingOldSuccessionState = SuccessionContext & Readonly<{
76
+ phase: "resuming_old";
77
+ failedPhase: CodexSuccessionFailurePhase | "abort" | "barrier_busy";
78
+ safeErrorCode: string;
79
+ }>;
80
+ export type CodexRegistrationSuccessionState = ActiveOldSuccessionState | ActiveNewSuccessionState | FreezingSuccessionState | PreparedNewSuccessionState | PublishedNewSuccessionState | OfflinePoisonedSuccessionState | RecoveryRequiredSuccessionState | ResumingOldSuccessionState;
81
+ type CorrelatedEvent = Readonly<{
82
+ generation: string;
83
+ }>;
84
+ export type CodexRegistrationSuccessionEvent = Readonly<{
85
+ type: "begin";
86
+ registration: CodexRegistrationIdentity;
87
+ }> | (CorrelatedEvent & Readonly<{
88
+ type: "barrier_clean";
89
+ }>) | (CorrelatedEvent & Readonly<{
90
+ type: "barrier_busy";
91
+ safeErrorCode: string;
92
+ }>) | (CorrelatedEvent & Readonly<{
93
+ type: "listener_prepared";
94
+ }>) | (CorrelatedEvent & Readonly<{
95
+ type: "store_prepared";
96
+ }>) | (CorrelatedEvent & Readonly<{
97
+ type: "publication_armed";
98
+ }>) | (CorrelatedEvent & Readonly<{
99
+ type: "publication_absence_confirmed";
100
+ }>) | (CorrelatedEvent & Readonly<{
101
+ type: "registry_published";
102
+ }>) | (CorrelatedEvent & Readonly<{
103
+ type: "activate";
104
+ }>) | (CorrelatedEvent & Readonly<{
105
+ type: "cleanup_confirmed";
106
+ }>) | (CorrelatedEvent & Readonly<{
107
+ type: "resume_confirmed";
108
+ }>) | (CorrelatedEvent & Readonly<{
109
+ type: "abort";
110
+ safeErrorCode: string;
111
+ }>) | (CorrelatedEvent & Readonly<{
112
+ type: "phase_failed";
113
+ phase: CodexSuccessionFailurePhase;
114
+ safeErrorCode: string;
115
+ }>) | (CorrelatedEvent & Readonly<{
116
+ type: "restart_evidence";
117
+ publication: "absent" | "armed" | "published" | "unknown";
118
+ safeErrorCode: string;
119
+ }>);
120
+ export type CodexRegistrationSuccessionEffect = Readonly<{
121
+ type: "freeze_old_ingress";
122
+ registration: CodexRegistrationIdentity;
123
+ }> | Readonly<{
124
+ type: "freeze_old_dispatch";
125
+ registration: CodexRegistrationIdentity;
126
+ }> | Readonly<{
127
+ type: "quiesce_and_join_old";
128
+ registration: CodexRegistrationIdentity;
129
+ }> | Readonly<{
130
+ type: "verify_full_barrier";
131
+ registration: CodexRegistrationIdentity;
132
+ }> | Readonly<{
133
+ type: "create_fresh_listener_generation";
134
+ registration: CodexRegistrationIdentity;
135
+ }> | Readonly<{
136
+ type: "purge_old_conversations";
137
+ registration: CodexRegistrationIdentity;
138
+ }> | Readonly<{
139
+ type: "purge_old_reply_capabilities";
140
+ registration: CodexRegistrationIdentity;
141
+ }> | Readonly<{
142
+ type: "prepare_new_store";
143
+ registration: CodexRegistrationIdentity;
144
+ }> | Readonly<{
145
+ /**
146
+ * Persist the irreversible publication intent. The controller must
147
+ * durably save the returned `publication_arming` machine state before
148
+ * executing this effect.
149
+ */
150
+ type: "arm_publication_journal";
151
+ registration: CodexRegistrationIdentity;
152
+ }> | Readonly<{
153
+ type: "publish_new_registry";
154
+ registration: CodexRegistrationIdentity;
155
+ }> | Readonly<{
156
+ type: "activate_new_registration";
157
+ registration: CodexRegistrationIdentity;
158
+ }> | Readonly<{
159
+ type: "retire_old_generation";
160
+ registration: CodexRegistrationIdentity;
161
+ }> | Readonly<{
162
+ type: "close_old_listener";
163
+ registration: CodexRegistrationIdentity;
164
+ /**
165
+ * Registry cleanup is a generation-owned compare-and-delete. It may
166
+ * unlink only the retired record and must preserve the active record.
167
+ */
168
+ registryUnlink: Readonly<{
169
+ onlyIfOwnedGeneration: string;
170
+ protectedActiveGeneration: string;
171
+ }>;
172
+ }> | Readonly<{
173
+ type: "cleanup_unpublished_generation";
174
+ registration: CodexRegistrationIdentity;
175
+ }> | Readonly<{
176
+ type: "resume_old_ingress";
177
+ registration: CodexRegistrationIdentity;
178
+ }> | Readonly<{
179
+ type: "resume_old_dispatch";
180
+ registration: CodexRegistrationIdentity;
181
+ }> | Readonly<{
182
+ type: "poison_new_generation";
183
+ registration: CodexRegistrationIdentity;
184
+ }> | Readonly<{
185
+ type: "take_registrations_offline";
186
+ oldRegistration: CodexRegistrationIdentity;
187
+ newRegistration: CodexRegistrationIdentity;
188
+ }> | Readonly<{
189
+ type: "cleanup_poisoned_generations";
190
+ oldRegistration: CodexRegistrationIdentity;
191
+ newRegistration: CodexRegistrationIdentity;
192
+ }> | Readonly<{
193
+ type: "manual_recovery_required";
194
+ registration: CodexRegistrationIdentity;
195
+ safeErrorCode: string;
196
+ }>;
197
+ export type CodexRegistrationSuccessionTransition = Readonly<{
198
+ state: CodexRegistrationSuccessionState;
199
+ effects: readonly CodexRegistrationSuccessionEffect[];
200
+ }>;
201
+ export declare function createCodexRegistrationSuccession(active: CodexRegistrationIdentity): ActiveOldSuccessionState;
202
+ export declare function transitionCodexRegistrationSuccession(state: CodexRegistrationSuccessionState, event: CodexRegistrationSuccessionEvent): CodexRegistrationSuccessionTransition;
203
+ /**
204
+ * Runtime assertion for controller boundaries and exhaustive state-machine
205
+ * tests. It intentionally validates identities without interpreting their
206
+ * opaque generation strings.
207
+ */
208
+ export declare function assertCodexRegistrationSuccessionInvariant(state: CodexRegistrationSuccessionState): void;
209
+ export {};