@joenandez/tldr 1.0.1 → 1.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 (31) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/bin/tldr-agent +3 -2
  4. package/install/tldr-agent-bootstrap.sh +7 -0
  5. package/package.json +7 -6
  6. package/release/activation-manifest.json +6 -6
  7. package/release/payloads/arm64/TldrAgentAegis.pkg +0 -0
  8. package/release/payloads/arm64/tldr-agent.tar.gz +0 -0
  9. package/release/starport-release.json +2 -2
  10. package/skills/tldr/SKILL.md +37 -36
  11. package/src/lib/aegis_native_distribution.mjs +1 -1
  12. package/src/lib/aegis_protocol.mjs +1 -1
  13. package/src/lib/starport_onboarding.mjs +303 -6
  14. package/src/lib/starport_orchestrator.mjs +21 -20
  15. package/src/lib/starport_runtime.mjs +28 -5
  16. package/src/lib/tightbeam_channel.mjs +63 -119
  17. package/src/lib/tightbeam_channel_runtime.mjs +76 -17
  18. package/src/lib/tightbeam_email_adapter.mjs +10 -0
  19. package/src/lib/tightbeam_email_delivery_channel.mjs +107 -133
  20. package/src/lib/tightbeam_email_provider_map.mjs +337 -0
  21. package/src/lib/tightbeam_inbound_publish.mjs +84 -0
  22. package/src/lib/tightbeam_welcome_dispatch.mjs +129 -33
  23. package/src/lib/tldr_agent_diagnostic_schema.mjs +1 -0
  24. package/src/lib/transports/email/render/email.mjs +66 -180
  25. package/src/lib/transports/email/render/html.mjs +37 -80
  26. package/src/lib/transports/email/render/text.mjs +2 -2
  27. package/src/lib/transports/email/render/tldr.mjs +10 -88
  28. package/src/lib/transports/email/render/tokens.mjs +56 -75
  29. package/src/lib/transports/email/templates.mjs +38 -27
  30. package/src/lib/transports/email.mjs +21 -1
  31. package/src/lib/transports/email/render/glyphs.mjs +0 -66
@@ -0,0 +1,84 @@
1
+ const RAW_REPLY_AUTHORITY_FIELDS = Object.freeze([
2
+ "conversation_id",
3
+ "route_id",
4
+ "origin_endpoint_id",
5
+ "origin_session_id",
6
+ ]);
7
+
8
+ function hasRawReplyAuthority(binding) {
9
+ return RAW_REPLY_AUTHORITY_FIELDS.some((field) => field in binding);
10
+ }
11
+
12
+ export function createTightbeamInboundPublisher({
13
+ execute,
14
+ readIdentity,
15
+ commandFailure,
16
+ delivery,
17
+ }) {
18
+ return async function publishInboundEmail({
19
+ binding,
20
+ provider_message_id: providerMessageId,
21
+ provider_thread_id: providerThreadId,
22
+ body,
23
+ }) {
24
+ const hasReplyBinding =
25
+ binding &&
26
+ typeof binding.reply_binding === "string" &&
27
+ binding.reply_binding.length > 0;
28
+ if (hasReplyBinding && hasRawReplyAuthority(binding)) {
29
+ return Object.freeze({ ok: false, code: "invalid_binding" });
30
+ }
31
+ if (hasReplyBinding) {
32
+ if (typeof providerMessageId !== "string" || typeof body !== "string") {
33
+ return Object.freeze({ ok: false, code: "thread_unmapped" });
34
+ }
35
+ const identity = await readIdentity();
36
+ if (!identity)
37
+ return Object.freeze({ ok: false, code: "not_configured" });
38
+ const published = await execute({
39
+ admin: false,
40
+ credentials: identity,
41
+ args: [
42
+ "channel",
43
+ "reply",
44
+ "publish",
45
+ "--reply-binding",
46
+ binding.reply_binding,
47
+ "--body",
48
+ body,
49
+ "--external-event-id",
50
+ providerMessageId,
51
+ "--provider-metadata-json",
52
+ JSON.stringify({ channel: "email" }),
53
+ ],
54
+ });
55
+ if (
56
+ commandFailure(published) ||
57
+ typeof published.result?.message_id !== "string"
58
+ ) {
59
+ return Object.freeze({ ok: false, code: "publish_failed" });
60
+ }
61
+ try {
62
+ await delivery.recordInboundProviderAcceptance({
63
+ binding,
64
+ provider_message_id: providerMessageId,
65
+ provider_thread_id: providerThreadId,
66
+ tightbeam_message_id: published.result.message_id,
67
+ tightbeam_conversation_id: published.result.conversation_id,
68
+ });
69
+ } catch {
70
+ return Object.freeze({
71
+ ok: false,
72
+ code: "reply_parent_persist_failed",
73
+ });
74
+ }
75
+ // Tightbeam owns canonical routing and delivery choice. Preserve its
76
+ // result verbatim; the adapter only advances provider reply continuity.
77
+ return Object.freeze({ ok: true, ...published.result });
78
+ }
79
+ return Object.freeze({
80
+ ok: false,
81
+ code: binding ? "invalid_binding" : "thread_unmapped",
82
+ });
83
+ };
84
+ }
@@ -1,15 +1,101 @@
1
+ export function createTightbeamWelcomeIdentityManager({
2
+ readIdentity,
3
+ persistIdentity,
4
+ execute,
5
+ commandFailure,
6
+ unavailable,
7
+ identityInvalid,
8
+ debugIdentity,
9
+ acquireApplicationCredential,
10
+ application,
11
+ authority,
12
+ }) {
13
+ return async function ensureWelcomeIdentity() {
14
+ let identity;
15
+ try {
16
+ identity = await readIdentity();
17
+ } catch (error) {
18
+ if (error?.code !== "TLDR_EMAIL_IDENTITY_INVALID") throw error;
19
+ debugIdentity("identity_integrity_failed", { code: error.code });
20
+ return identityInvalid();
21
+ }
22
+ if (!identity) return unavailable();
23
+
24
+ if (!identity.welcome) {
25
+ const acquisition = await acquireApplicationCredential(
26
+ application,
27
+ "welcome_sender",
28
+ );
29
+ const created = acquisition.result;
30
+ if (
31
+ commandFailure(created) ||
32
+ typeof created.result?.app_id !== "string" ||
33
+ typeof created.result?.app_secret !== "string"
34
+ ) {
35
+ if (acquisition.reregistered && created?.ok === false) return created;
36
+ return unavailable();
37
+ }
38
+ identity = {
39
+ ...identity,
40
+ welcome: {
41
+ app_id: created.result.app_id,
42
+ app_secret: created.result.app_secret,
43
+ },
44
+ };
45
+ await persistIdentity(identity);
46
+ }
47
+
48
+ const grants = await execute({
49
+ admin: true,
50
+ credentials: null,
51
+ args: [
52
+ "app",
53
+ "set-permissions",
54
+ identity.welcome.app_id,
55
+ "--permissions-json",
56
+ JSON.stringify([
57
+ {
58
+ permission: "register_endpoints",
59
+ allowed_authorities: [authority],
60
+ },
61
+ {
62
+ permission: "send_as_principal",
63
+ allowed_authorities: [authority],
64
+ },
65
+ ]),
66
+ ],
67
+ });
68
+ if (commandFailure(grants)) return unavailable();
69
+ debugIdentity("welcome_sender_ready", { application });
70
+ return Object.freeze({ ok: true, identity: identity.welcome });
71
+ };
72
+ }
73
+
1
74
  export function createTightbeamWelcomeDispatcher({
2
75
  registerEmailChannel,
76
+ ensureWelcomeIdentity,
3
77
  readIdentity,
4
78
  execute,
5
79
  commandFailure,
6
80
  unavailable,
7
81
  authority,
8
82
  principalRef,
9
- endpointSession,
83
+ welcomeEndpointSession,
10
84
  }) {
11
- return async function dispatchWelcome({ body, idempotencyKey }) {
12
- if (typeof body !== "string" || typeof idempotencyKey !== "string") {
85
+ return async function dispatchWelcome({
86
+ subject,
87
+ reason,
88
+ body,
89
+ idempotencyKey,
90
+ }) {
91
+ if (
92
+ typeof subject !== "string" ||
93
+ subject.trim().length === 0 ||
94
+ typeof reason !== "string" ||
95
+ reason.trim().length === 0 ||
96
+ typeof body !== "string" ||
97
+ typeof idempotencyKey !== "string"
98
+ ) {
13
99
  return Object.freeze({ ok: false, error: { code: "welcome_invalid" } });
14
100
  }
15
101
  const registered = await registerEmailChannel({
@@ -18,11 +104,13 @@ export function createTightbeamWelcomeDispatcher({
18
104
  capabilities: ["send", "reply"],
19
105
  });
20
106
  if (registered.ok !== true) return registered;
21
- const identity = await readIdentity();
22
- if (!identity) return unavailable();
107
+ const welcomeIdentity = await ensureWelcomeIdentity();
108
+ if (welcomeIdentity.ok !== true) return welcomeIdentity;
109
+ const bridgeIdentity = await readIdentity();
110
+ if (!bridgeIdentity) return unavailable();
23
111
  const owner = await execute({
24
112
  admin: false,
25
- credentials: identity,
113
+ credentials: bridgeIdentity,
26
114
  args: [
27
115
  "principal",
28
116
  "register",
@@ -34,27 +122,9 @@ export function createTightbeamWelcomeDispatcher({
34
122
  "Owner",
35
123
  ],
36
124
  });
37
- const endpoint = await execute({
38
- admin: false,
39
- credentials: identity,
40
- args: [
41
- "endpoint",
42
- "register",
43
- "--authority",
44
- authority,
45
- "--principal",
46
- owner.result?.principal_id,
47
- "--runtime",
48
- "reference",
49
- "--session",
50
- endpointSession,
51
- "--reference",
52
- authority,
53
- ],
54
- });
55
125
  const routes = await execute({
56
126
  admin: false,
57
- credentials: identity,
127
+ credentials: bridgeIdentity,
58
128
  args: ["channel", "route", "list"],
59
129
  });
60
130
  const route = routes?.result?.routes?.find(
@@ -62,16 +132,15 @@ export function createTightbeamWelcomeDispatcher({
62
132
  );
63
133
  if (
64
134
  commandFailure(owner) ||
65
- commandFailure(endpoint) ||
66
135
  commandFailure(routes) ||
67
- typeof endpoint.result?.process_generation !== "number" ||
136
+ typeof owner.result?.principal_id !== "string" ||
68
137
  !route
69
138
  ) {
70
139
  return unavailable();
71
140
  }
72
141
  const welcome = await execute({
73
142
  admin: false,
74
- credentials: identity,
143
+ credentials: welcomeIdentity.identity,
75
144
  args: [
76
145
  "principal",
77
146
  "register",
@@ -89,14 +158,43 @@ export function createTightbeamWelcomeDispatcher({
89
158
  ) {
90
159
  return unavailable();
91
160
  }
161
+ const endpoint = await execute({
162
+ admin: false,
163
+ credentials: welcomeIdentity.identity,
164
+ args: [
165
+ "endpoint",
166
+ "register",
167
+ "--authority",
168
+ authority,
169
+ "--principal",
170
+ welcome.result.principal_id,
171
+ "--runtime",
172
+ "reference",
173
+ "--session",
174
+ welcomeEndpointSession,
175
+ "--reference",
176
+ authority,
177
+ ],
178
+ });
179
+ if (
180
+ commandFailure(endpoint) ||
181
+ typeof endpoint.result?.endpoint_id !== "string" ||
182
+ !Number.isInteger(endpoint.result?.process_generation)
183
+ ) {
184
+ return unavailable();
185
+ }
92
186
  const conversation = await execute({
93
187
  admin: false,
94
- credentials: identity,
188
+ credentials: welcomeIdentity.identity,
95
189
  args: [
96
190
  "conversation",
97
191
  "create",
98
192
  "--participants",
99
193
  `${owner.result.principal_id},${welcome.result.principal_id}`,
194
+ "--subject",
195
+ subject,
196
+ "--reason",
197
+ reason,
100
198
  ],
101
199
  });
102
200
  if (
@@ -107,20 +205,18 @@ export function createTightbeamWelcomeDispatcher({
107
205
  }
108
206
  const committed = await execute({
109
207
  admin: false,
110
- credentials: identity,
208
+ credentials: welcomeIdentity.identity,
111
209
  args: [
112
210
  "message",
113
211
  "commit",
114
212
  "--conversation",
115
213
  conversation.result.conversation_id,
116
214
  "--from",
117
- owner.result.principal_id,
215
+ welcome.result.principal_id,
118
216
  "--body",
119
217
  body,
120
218
  "--key",
121
219
  idempotencyKey,
122
- "--origin-channel-route",
123
- route.route_id,
124
220
  "--channel-selector",
125
221
  "email",
126
222
  "--effect",
@@ -120,6 +120,7 @@ const ERROR_CODES = new Set([
120
120
  "obligation_persist_failed",
121
121
  "owner_not_ready",
122
122
  "provider_send_failed",
123
+ "reply_parent_unauthorized",
123
124
  "sender_not_authorized",
124
125
  "stale_listener",
125
126
  "status_port_bind_failed",