@joenandez/tldr 1.0.0 → 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 (41) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/bin/tldr-agent +11 -0
  4. package/hooks/tldr-agent-capture-session-identity.sh +3 -2
  5. package/install/tldr-agent-bootstrap.sh +7 -0
  6. package/package.json +10 -6
  7. package/release/activation-manifest.json +6 -6
  8. package/release/payloads/arm64/TldrAgentAegis.pkg +0 -0
  9. package/release/payloads/arm64/tldr-agent.tar.gz +0 -0
  10. package/release/starport-release.json +14 -9
  11. package/skills/tldr/SKILL.md +43 -31
  12. package/src/lib/aegis_native_distribution.mjs +1 -1
  13. package/src/lib/aegis_protocol.mjs +1 -1
  14. package/src/lib/starport_aegis_package.mjs +53 -6
  15. package/src/lib/starport_onboarding.mjs +303 -6
  16. package/src/lib/starport_orchestrator.mjs +21 -20
  17. package/src/lib/starport_release_contract.mjs +48 -10
  18. package/src/lib/starport_runtime.mjs +131 -13
  19. package/src/lib/tightbeam_channel.mjs +83 -123
  20. package/src/lib/tightbeam_channel_runtime.mjs +131 -33
  21. package/src/lib/tightbeam_email_adapter.mjs +10 -0
  22. package/src/lib/tightbeam_email_delivery_channel.mjs +107 -133
  23. package/src/lib/tightbeam_email_provider_map.mjs +337 -0
  24. package/src/lib/tightbeam_inbound_publish.mjs +84 -0
  25. package/src/lib/tightbeam_welcome_dispatch.mjs +129 -33
  26. package/src/lib/tldr_agent_daemon_health.mjs +2 -1
  27. package/src/lib/tldr_agent_daemon_phase_timeouts.mjs +3 -5
  28. package/src/lib/tldr_agent_diagnostic_schema.mjs +1 -0
  29. package/src/lib/tldr_agent_launchd_definition.mjs +2 -0
  30. package/src/lib/tldr_agent_launchd_lifecycle.mjs +41 -10
  31. package/src/lib/tldr_agent_runtime_identity.mjs +14 -2
  32. package/src/lib/tldr_agent_source_lifecycle.mjs +18 -4
  33. package/src/lib/transports/email/render/email.mjs +66 -180
  34. package/src/lib/transports/email/render/html.mjs +37 -80
  35. package/src/lib/transports/email/render/text.mjs +2 -2
  36. package/src/lib/transports/email/render/tldr.mjs +10 -88
  37. package/src/lib/transports/email/render/tokens.mjs +56 -75
  38. package/src/lib/transports/email/templates.mjs +38 -27
  39. package/src/lib/transports/email.mjs +21 -1
  40. package/src/starport.mjs +12 -0
  41. package/src/lib/transports/email/render/glyphs.mjs +0 -66
@@ -13,6 +13,7 @@ export function renderTldrAgentProductionPlist({
13
13
  home,
14
14
  statusPort,
15
15
  nodePath = process.execPath,
16
+ tightbeamBin = null,
16
17
  }) {
17
18
  const daemonScript = join(dirname(schedulerScriptPath), "helm-daemon.mjs");
18
19
  return `<?xml version="1.0" encoding="UTF-8"?>
@@ -27,6 +28,7 @@ export function renderTldrAgentProductionPlist({
27
28
  <key>TLDR_AGENT_DAEMON_MODE</key><string>poll-only</string>
28
29
  <key>HELM_CANONICAL_SQLITE</key><string>1</string>
29
30
  <key>HELM_STATUS_PORT</key><string>${statusPort}</string>
31
+ ${tightbeamBin ? `<key>TIGHTBEAM_BIN</key><string>${xmlEscape(tightbeamBin)}</string>` : ""}
30
32
  </dict>
31
33
  <key>StandardOutPath</key><string>/dev/null</string>
32
34
  <key>StandardErrorPath</key><string>/dev/null</string>
@@ -114,7 +114,19 @@ export function createTldrAgentInstallLifecycle({
114
114
  cleanupErrors.push(error);
115
115
  }
116
116
  try {
117
- await launchd.unload();
117
+ const requestedStop = await launchd.unload();
118
+ const stopped =
119
+ typeof launchd.waitForUnloaded === "function"
120
+ ? await launchd.waitForUnloaded(requestedStop)
121
+ : requestedStop;
122
+ if (stopped?.loaded || stopped?.running || stopped?.previous_running) {
123
+ cleanupErrors.push(
124
+ lifecycleError(
125
+ "DAEMON_QUIESCE_TIMEOUT",
126
+ "tldr; failed daemon did not quiesce before rollback",
127
+ ),
128
+ );
129
+ }
118
130
  } catch (error) {
119
131
  cleanupErrors.push(error);
120
132
  }
@@ -147,9 +159,9 @@ export function createTldrAgentInstallLifecycle({
147
159
  const requestedStop = await launchd.unload();
148
160
  const stopped =
149
161
  typeof launchd.waitForUnloaded === "function"
150
- ? await launchd.waitForUnloaded()
162
+ ? await launchd.waitForUnloaded(requestedStop)
151
163
  : requestedStop;
152
- if (stopped?.loaded || stopped?.running) {
164
+ if (stopped?.loaded || stopped?.running || stopped?.previous_running) {
153
165
  throw lifecycleError(
154
166
  "DAEMON_QUIESCE_TIMEOUT",
155
167
  "tldr; daemon did not quiesce before update",
@@ -279,17 +291,30 @@ export function createTldrAgentLaunchdLifecycle({
279
291
  return status();
280
292
  };
281
293
  const unload = () => {
282
- if (status().loaded) run(["bootout", target], [3]);
283
- return status();
294
+ const before = status();
295
+ if (before.loaded) run(["bootout", target], [3]);
296
+ return { ...status(), previous_pid: before.pid };
284
297
  };
285
- const waitForUnloaded = () => {
298
+ const waitForUnloaded = (requestedStop = null) => {
299
+ const previousPid = Number(requestedStop?.previous_pid);
300
+ const previousRunning = () =>
301
+ Number.isInteger(previousPid) &&
302
+ previousPid > 0 &&
303
+ isPidAlive(previousPid);
286
304
  const deadline = now() + quiesceTimeoutMs;
287
305
  let observed = status();
288
- while ((observed.loaded || observed.running) && now() < deadline) {
306
+ while (
307
+ (observed.loaded || observed.running || previousRunning()) &&
308
+ now() < deadline
309
+ ) {
289
310
  sleepSync(25);
290
311
  observed = status();
291
312
  }
292
- return observed;
313
+ return {
314
+ ...observed,
315
+ previous_pid: Number.isInteger(previousPid) ? previousPid : null,
316
+ previous_running: previousRunning(),
317
+ };
293
318
  };
294
319
  const load = () => {
295
320
  if (!existsSync(definitionPath)) install();
@@ -297,8 +322,14 @@ export function createTldrAgentLaunchdLifecycle({
297
322
  return status();
298
323
  };
299
324
  const reload = () => {
300
- unload();
301
- waitForUnloaded();
325
+ const requestedStop = unload();
326
+ const stopped = waitForUnloaded(requestedStop);
327
+ if (stopped.loaded || stopped.running || stopped.previous_running) {
328
+ throw lifecycleError(
329
+ "DAEMON_QUIESCE_TIMEOUT",
330
+ "tldr; daemon did not quiesce before reload",
331
+ );
332
+ }
302
333
  install();
303
334
  const deadline = now() + reloadTimeoutMs;
304
335
  let bootstrapped;
@@ -59,10 +59,21 @@ export function readTldrAgentRuntimeIdentity({
59
59
  const packagedRevision = FULL_REVISION.test(metadata.gitHead || "")
60
60
  ? metadata.gitHead
61
61
  : null;
62
+ const localSnapshot = metadata.tldrLocalSnapshot || null;
62
63
  return {
63
64
  package_version: String(metadata.version || "unknown"),
64
- source_revision: checkout?.revision || packagedRevision,
65
- source_dirty: checkout ? checkout.dirty : null,
65
+ source_revision: localSnapshot
66
+ ? packagedRevision
67
+ : checkout?.revision || packagedRevision,
68
+ source_dirty: localSnapshot
69
+ ? Boolean(localSnapshot.sourceDirty)
70
+ : checkout
71
+ ? checkout.dirty
72
+ : null,
73
+ source_digest:
74
+ typeof localSnapshot?.sourceDigest === "string"
75
+ ? localSnapshot.sourceDigest
76
+ : null,
66
77
  schema_version:
67
78
  Number.isInteger(Number(schemaVersion)) && schemaVersion !== null
68
79
  ? Number(schemaVersion)
@@ -79,6 +90,7 @@ export function tldrAgentSourceIdentity() {
79
90
  package_version: identity.package_version,
80
91
  source_revision: identity.source_revision,
81
92
  source_dirty: identity.source_dirty,
93
+ source_digest: identity.source_digest,
82
94
  });
83
95
  }
84
96
  return cachedSourceIdentity;
@@ -24,23 +24,30 @@ const ACTIVATABLE_AEGIS_STATES = new Set([
24
24
  "unconfigured",
25
25
  ]);
26
26
 
27
- export function requiresFreshPollForAegisStatus(status) {
27
+ export function requiresFreshPollForAegisStatus(status, override = null) {
28
28
  if (!ACTIVATABLE_AEGIS_STATES.has(status)) {
29
29
  throw new Error(
30
30
  `tldr; Aegis state ${JSON.stringify(status)} blocks source activation`,
31
31
  );
32
32
  }
33
+ if (typeof override === "boolean") return override;
33
34
  return status === "ready";
34
35
  }
35
36
 
36
37
  export function productionPlist(
37
38
  schedulerScriptPath,
38
- { home = getHelmHome() } = {},
39
+ {
40
+ home = getHelmHome(),
41
+ nodePath = process.execPath,
42
+ tightbeamBin = process.env.TIGHTBEAM_BIN || null,
43
+ } = {},
39
44
  ) {
40
45
  return renderTldrAgentProductionPlist({
41
46
  schedulerScriptPath,
42
47
  home,
43
48
  statusPort: TLDR_AGENT_STATUS_PORT,
49
+ nodePath,
50
+ tightbeamBin,
44
51
  });
45
52
  }
46
53
 
@@ -50,6 +57,9 @@ export function productionPlist(
50
57
  export function createTldrAgentSourceInstallLifecycle({
51
58
  home = getHelmHome(),
52
59
  pluginHooksOwned = false,
60
+ nodePath = process.execPath,
61
+ tightbeamBin = process.env.TIGHTBEAM_BIN || null,
62
+ requireFreshPoll = null,
53
63
  releaseOwnership = null,
54
64
  cleanupOwnedState = null,
55
65
  readAegisStatus = requestAegisStatusSafe,
@@ -61,7 +71,8 @@ export function createTldrAgentSourceInstallLifecycle({
61
71
  );
62
72
  const launchd = createTldrAgentLaunchdLifecycle({
63
73
  schedulerScriptPath,
64
- renderDefinition: (path) => productionPlist(path, { home }),
74
+ renderDefinition: (path) =>
75
+ productionPlist(path, { home, nodePath, tightbeamBin }),
65
76
  });
66
77
  return createTldrAgentInstallLifecycle({
67
78
  runtimes: pluginHooksOwned ? [] : undefined,
@@ -77,7 +88,10 @@ export function createTldrAgentSourceInstallLifecycle({
77
88
  observeDaemon,
78
89
  home,
79
90
  port: TLDR_AGENT_STATUS_PORT,
80
- requirePollFresh: requiresFreshPollForAegisStatus(aegisStatus),
91
+ requirePollFresh: requiresFreshPollForAegisStatus(
92
+ aegisStatus,
93
+ requireFreshPoll,
94
+ ),
81
95
  expectedRuntimeIdentity: {
82
96
  ...tldrAgentSourceIdentity(),
83
97
  schema_version: readTldrAgentRuntimeSchemaVersion(home),
@@ -1,25 +1,9 @@
1
- /* tldr; — the email envelope.
1
+ /* Quiet rich-text correspondence for owner and agent email.
2
2
  *
3
- * Four parts: the subject set as the TLDR block, the agent's Markdown, and a
4
- * context line closing the message. A system message adds a fifth above them
5
- * all, and it is an exception on purpose.
6
- *
7
- * THE TLDR BLOCK is the product's name made literal, and it is the one place
8
- * this system speaks above the agent. It carries the result, the owner action,
9
- * and the next moment — and it invents none of them. The subject's grammar is
10
- * already "state word, colon, the decision", so the state word becomes the
11
- * action and the decision becomes the result. The block sets a structure that
12
- * was always in the string; it does not add a claim to it.
13
- *
14
- * That is also why the subject is not printed twice. A card that repeats its own
15
- * subject above a summary of its own subject has spent the owner's first two
16
- * seconds saying one thing three times.
17
- *
18
- * THE LIVE EDGE is allocated here and only here. Citron means the point where
19
- * attention is active, so it appears on the action chip when the message needs
20
- * the owner, and nowhere at all when it does not — seeing citron in an inbox has
21
- * to mean something. No block renderer can emit the accent; html.mjs never
22
- * receives it.
3
+ * Normal messages begin with the agent's body. There is no product masthead,
4
+ * repeated subject, summary panel, action chip, or decorative mark. System mail
5
+ * identifies itself with a compact label and heading; all tldr; branding lives
6
+ * at the very end of the footer.
23
7
  */
24
8
 
25
9
  import {
@@ -27,20 +11,19 @@ import {
27
11
  CARD_WIDTH,
28
12
  DAY,
29
13
  DISPLAY,
14
+ GUTTER,
30
15
  MONO,
31
16
  NIGHT,
32
17
  TYPE,
33
18
  } from "./tokens.mjs";
34
19
  import { parseInline, parseMarkdown } from "./markdown.mjs";
35
20
  import { blocksHtml, esc, presentationTable as pt } from "./html.mjs";
36
- import { blocksText, COLUMNS, inlineText, wrap } from "./text.mjs";
37
- import { TEXT_GLYPH } from "./glyphs.mjs";
21
+ import { blocksText, inlineText, wrap } from "./text.mjs";
38
22
  import {
39
23
  ACTION,
40
24
  inlineMarkdownHtml,
41
25
  resolveAction,
42
26
  splitSubject,
43
- tldrHtml,
44
27
  } from "./tldr.mjs";
45
28
 
46
29
  export const AGENTS = Object.freeze({
@@ -54,89 +37,39 @@ const NOTICE_DEFAULT =
54
37
  "Only replies from your verified address reach the session.";
55
38
 
56
39
  export const WORDMARK = "tldr;";
57
-
58
- /* The twin resolves the same inline Markdown the HTML does, and shows the result
59
- * rather than the notation. */
60
40
  const footerInlineText = (value) => inlineText(parseInline(value));
61
41
 
62
- /* The wordmark, set as live text rather than loaded as an asset.
63
- *
64
- * DESIGN.md's identity rule is that the wordmark is an SVG and is never rebuilt
65
- * from type. Email is the declared exception, and it has to be: clients block
66
- * remote images, so an emailed wordmark that is an image is a wordmark most
67
- * owners never see.
68
- *
69
- * Proportions come off brand/logotype/wordmark.svg — the semicolon's dot sits at
70
- * the ascender line and its tail drops well below the baseline, about a quarter
71
- * taller overall than the letters beside it. The negative margin cancels the
72
- * tracking the `r` would otherwise carry, because the asset has the semicolon
73
- * hugging the `r` rather than sitting a letter away from it.
74
- *
75
- * All of it link blue, as the asset is. Blue without an underline cannot be
76
- * mistaken for a link here: in this system a link is always underlined. */
77
- function wordmarkHtml(t) {
42
+ function wordmarkHtml(tokens) {
78
43
  return (
79
- `<span class="tl-link" style="font-family:${BODY};font-size:17px;line-height:1;` +
80
- `letter-spacing:.16em;font-weight:400;color:${t.link};">tldr</span>` +
81
- `<span class="tl-link" style="font-family:${DISPLAY};font-size:25px;line-height:1;` +
82
- `font-weight:700;color:${t.link};margin-left:-1px;">;</span>`
44
+ `<span class="tl-muted" style="${TYPE.colophon}color:${tokens.muted};">Sent via tldr</span>` +
45
+ `<span class="tl-link" style="${TYPE.colophon}color:${tokens.link};">;</span>`
83
46
  );
84
47
  }
85
48
 
86
- /* The system bar: a solid identity plane across the head of the card, the
87
- * wordmark on the left and the kind of message on the right.
88
- *
89
- * It is the loudest piece of chrome in the system, spent on the one distinction
90
- * that matters at 3am: an agent's message says a thing about your code, a system
91
- * message says a thing about tldr;, and the owner has to be able to tell which
92
- * before reading a word. Never citron — it is a label, not an ask. */
93
- function systemBarHtml(kind, t) {
94
- const cell =
95
- `class="tl-solid" style="background:${t.solid};color:${t.onSolid};${TYPE.stamp}` +
96
- `line-height:1.2;white-space:nowrap;vertical-align:middle;`;
97
-
98
- /* The kind is uppercased; the wordmark is not. The name is lowercase and it
99
- * stays lowercase in the one place the product signs itself loudest. */
49
+ function systemHeaderHtml(spec, tokens) {
50
+ const { result } = splitSubject(spec.subject);
100
51
  return pt(
101
- `<tr>` +
102
- `<td ${cell}padding:12px 10px 12px 24px;font-size:14px;letter-spacing:.04em;">${WORDMARK}</td>` +
103
- `<td align="right" ${cell}padding:12px 24px 12px 10px;text-transform:uppercase;">${esc(kind)}</td>` +
104
- `</tr>`,
52
+ `<tr><td class="tl-muted" style="${TYPE.systemLabel}color:${tokens.muted};">` +
53
+ `tldr; <span class="tl-line" style="color:${tokens.line};">&middot;</span> ${esc(spec.system)}` +
54
+ `</td></tr>` +
55
+ `<tr><td class="tl-ink" style="${TYPE.systemTitle}color:${tokens.ink};padding:10px 0 0 0;">${esc(result)}</td></tr>`,
105
56
  );
106
57
  }
107
58
 
108
- /* A value the owner has to read off the screen and type somewhere else.
109
- *
110
- * It gets the mono face at display size rather than the 13px a fenced block
111
- * would give it, because this is the one string in the system whose whole job is
112
- * to be transcribed correctly at arm's length. The subject carries it too, so it
113
- * reaches the lock screen without the email being opened; that repetition is the
114
- * point rather than an oversight. */
115
- function codePlateHtml(code, t) {
59
+ function codePlateHtml(code, tokens) {
116
60
  return pt(
117
- `<tr><td class="tl-raised" style="border:1px solid ${t.line};border-radius:2px;` +
118
- `background:${t.raised};padding:20px 24px;font-family:${MONO};font-size:30px;` +
119
- `line-height:1.2;font-weight:500;letter-spacing:.16em;color:${t.ink};` +
61
+ `<tr><td class="tl-raised" style="border:1px solid ${tokens.line};border-radius:4px;` +
62
+ `background:${tokens.raised};padding:18px 20px;${TYPE.codePlate}color:${tokens.ink};` +
120
63
  `white-space:nowrap;">${esc(code)}</td></tr>`,
121
64
  );
122
65
  }
123
66
 
124
- /* Provenance is useful, not important enough to be a form. One line, fixed
125
- * order, widest scope inward — across a thread of six messages the values have
126
- * to be in the same places or the line stops being scannable and becomes
127
- * something to read. */
128
67
  const CONTEXT_ORDER = ["DIRECTORY", "AGENT", "BRANCH", "SESSION"];
129
-
130
68
  const contextRank = (label) => {
131
69
  const index = CONTEXT_ORDER.indexOf(label);
132
70
  return index === -1 ? CONTEXT_ORDER.length : index;
133
71
  };
134
72
 
135
- /* Labels stay, lowercased. Dropping them makes the line shorter and the values
136
- * ambiguous — `rate-limit` beside `1f4a9c2` is a branch and a session only if
137
- * you already knew that, and the owner reading this is half awake. The label
138
- * recedes to muted and the value holds the ink, so the pairs scan without the
139
- * separators having to do all the work. */
140
73
  export const contextPairs = (spec) =>
141
74
  [
142
75
  ...(spec.statePanel ?? []),
@@ -146,98 +79,87 @@ export const contextPairs = (spec) =>
146
79
  .sort(([a], [b]) => contextRank(a) - contextRank(b))
147
80
  .map(([label, value]) => [String(label).toLowerCase(), String(value)]);
148
81
 
149
- function footerHtml(spec, t) {
82
+ function footerHtml(spec, tokens) {
150
83
  const context = contextPairs(spec);
151
84
  const contextRow = context.length
152
- ? `<tr><td style="${TYPE.context}padding:16px 0 0 0;word-break:break-word;">` +
85
+ ? `<tr><td class="tl-muted" style="${TYPE.context}color:${tokens.muted};padding:10px 0 0 0;word-break:break-word;">` +
153
86
  context
154
87
  .map(
155
88
  ([label, value]) =>
156
- `<span class="tl-muted" style="color:${t.muted};">${esc(label)}</span>` +
157
- `<span class="tl-ink" style="color:${t.ink};"> ${esc(value)}</span>`,
89
+ `<span style="font-weight:600;">${esc(label)}</span> ${esc(value)}`,
158
90
  )
159
91
  .join(
160
- `<span class="tl-line" style="color:${t.line};"> &middot; </span>`,
92
+ `<span class="tl-line" style="color:${tokens.line};"> &middot; </span>`,
161
93
  ) +
162
94
  `</td></tr>`
163
95
  : "";
164
96
 
165
97
  return pt(
166
- `<tr><td style="padding:0 24px;">` +
98
+ `<tr><td style="padding:0 ${GUTTER}px;">` +
167
99
  pt(
168
- `<tr><td style="padding:0;"><div class="tl-hair" style="height:1px;background:${t.line};font-size:0;line-height:1px;">&nbsp;</div></td></tr>` +
100
+ `<tr><td style="padding:0;"><div class="tl-hair" style="height:1px;background:${tokens.line};font-size:0;line-height:1px;">&nbsp;</div></td></tr>` +
101
+ `<tr><td class="tl-muted" style="${TYPE.small}color:${tokens.muted};padding:14px 0 0 0;">` +
102
+ `${inlineMarkdownHtml(spec.reply ?? REPLY_DEFAULT, tokens)}</td></tr>` +
169
103
  contextRow +
170
- `<tr><td style="padding:22px 0 0 0;">${wordmarkHtml(t)}</td></tr>` +
171
- `<tr><td class="tl-muted" style="${TYPE.context}color:${t.muted};padding:10px 0 0 0;">` +
172
- `${inlineMarkdownHtml(spec.notice ?? NOTICE_DEFAULT, t)}</td></tr>`,
104
+ `<tr><td class="tl-muted" style="${TYPE.context}color:${tokens.muted};padding:7px 0 0 0;">` +
105
+ `${inlineMarkdownHtml(spec.notice ?? NOTICE_DEFAULT, tokens)}</td></tr>` +
106
+ `<tr><td style="padding:18px 0 0 0;">${wordmarkHtml(tokens)}</td></tr>`,
173
107
  ) +
174
108
  `</td></tr>`,
175
109
  );
176
110
  }
177
111
 
178
- /* Night lighting. Day values are hard-coded inline above this block, so a client
179
- * that strips <style> still renders the document correctly. Every day colour
180
- * this renderer emits sits on one of these classes. */
181
112
  function nightCss() {
182
113
  const n = NIGHT;
183
- return `@media (prefers-color-scheme: dark){
114
+ /* The :root declaration is what Apple Mail 13+ actually reads for scheme
115
+ * opt-in; the meta tags cover Mail 12 and signal intent to inverting
116
+ * clients. Both ship because neither alone covers the version range. */
117
+ return `:root{color-scheme:light dark;supported-color-schemes:light dark;}
118
+ @media (prefers-color-scheme: dark){
184
119
  .tl-page,.tl-card{background:${n.stock}!important;}
185
120
  .tl-ink,.tl-ink a{color:${n.ink}!important;}
186
121
  .tl-muted,.tl-muted a{color:${n.muted}!important;}
187
122
  .tl-link,.tl-link a,a.tl-link{color:${n.link}!important;}
188
123
  .tl-line{color:${n.line}!important;}
189
124
  .tl-hair{background:${n.line}!important;}
190
- .tl-hair-link{background:${n.link}!important;}
191
- .tl-bar{background:${n.link}!important;}
192
125
  .tl-ruled{border-bottom-color:${n.line}!important;}
193
- .tl-field{background:${n.field}!important;}
194
126
  .tl-raised{background:${n.raised}!important;border-color:${n.line}!important;color:${n.ink}!important;}
195
- .tl-code{background:${n.field}!important;color:${n.ink}!important;}
196
- .tl-tab,.tl-solid,.tl-chip-wait{background:${n.solid}!important;color:${n.onSolid}!important;}
197
- .tl-chip-live{background:${n.accent}!important;color:${n.onAccent}!important;}
198
- .tl-check-on{background:${n.solid}!important;color:${n.onSolid}!important;}
199
- .tl-check-off{border-color:${n.line}!important;}
200
- .tl-fill-link{background:${n.link}!important;}
127
+ .tl-code{background:${n.raised}!important;color:${n.ink}!important;}
128
+ .tl-check-on{background:${n.ink}!important;color:${n.stock}!important;}
129
+ .tl-check-off{border-color:${n.strongLine}!important;}
201
130
  }`;
202
131
  }
203
132
 
204
- /* The card only — used by the gallery, which needs day and night side by side
205
- * and therefore cannot rely on a media query. */
206
133
  export function renderCard(spec, mode = "day") {
207
- const t = mode === "night" ? NIGHT : DAY;
134
+ const tokens = mode === "night" ? NIGHT : DAY;
208
135
  const body = parseMarkdown(spec.body ?? "");
209
136
 
210
137
  return (
211
138
  `<table role="presentation" cellpadding="0" cellspacing="0" border="0" width="100%" class="tl-card" ` +
212
- `style="border-collapse:collapse;width:100%;max-width:${CARD_WIDTH}px;background:${t.stock};">` +
213
- (spec.system
214
- ? `<tr><td style="padding:0;">${systemBarHtml(spec.system, t)}</td></tr>`
139
+ `style="border-collapse:collapse;table-layout:fixed;width:100%;max-width:${CARD_WIDTH}px;background:${tokens.stock};">` +
140
+ (spec.system && !spec.code
141
+ ? `<tr><td style="padding:30px ${GUTTER}px 0 ${GUTTER}px;">${systemHeaderHtml(spec, tokens)}</td></tr>`
215
142
  : "") +
216
- `<tr><td style="padding:${spec.system ? 24 : 28}px 24px 0 24px;">${tldrHtml(spec, t, spec.reply ?? REPLY_DEFAULT)}</td></tr>` +
217
143
  (spec.code
218
- ? `<tr><td style="padding:20px 24px 0 24px;">${codePlateHtml(spec.code, t)}</td></tr>`
144
+ ? `<tr><td style="padding:30px ${GUTTER}px 0 ${GUTTER}px;">${codePlateHtml(spec.code, tokens)}</td></tr>`
219
145
  : "") +
220
146
  (body.length
221
- ? `<tr><td style="padding:32px 24px 0 24px;">${blocksHtml(body, t)}</td></tr>`
147
+ ? `<tr><td style="padding:${spec.system || spec.code ? 22 : 30}px ${GUTTER}px 0 ${GUTTER}px;">${blocksHtml(body, tokens)}</td></tr>`
222
148
  : "") +
223
- `<tr><td style="padding:36px 0 0 0;">${footerHtml(spec, t)}</td></tr>` +
149
+ `<tr><td style="padding:34px 0 0 0;">${footerHtml(spec, tokens)}</td></tr>` +
224
150
  `<tr><td style="height:28px;line-height:28px;font-size:0;">&nbsp;</td></tr>` +
225
151
  `</table>`
226
152
  );
227
153
  }
228
154
 
229
- /* The line the inbox shows under the subject. The subject already carries the
230
- * result, so the preheader spends itself on what the subject cannot say: what
231
- * this means for the owner, then the first sentence of the message. */
232
155
  function preheader(spec) {
233
156
  const first = parseMarkdown(spec.body ?? "").find(
234
- (n) => n.type === "paragraph",
235
- );
236
- const lead = (first?.text ?? "").replace(/\s+/g, " ").trim();
237
- return `${ACTION[resolveAction(spec)]}${lead ? ` — ${lead}` : ""}`.slice(
238
- 0,
239
- 140,
157
+ (node) => node.type === "paragraph",
240
158
  );
159
+ return (first?.text ?? spec.subject ?? "")
160
+ .replace(/\s+/g, " ")
161
+ .trim()
162
+ .slice(0, 140);
241
163
  }
242
164
 
243
165
  export function renderHtml(spec) {
@@ -250,79 +172,43 @@ export function renderHtml(spec) {
250
172
  <title>${esc(spec.subject)}</title>
251
173
  <style>${nightCss()}</style>
252
174
  </head>
253
- <body class="tl-page" style="margin:0;padding:0;background:${DAY.stock};">
175
+ <body class="tl-page" style="margin:0;padding:0;background:${DAY.page};">
254
176
  <div style="display:none;max-height:0;overflow:hidden;opacity:0;">${esc(preheader(spec))}</div>
255
- <table role="presentation" cellpadding="0" cellspacing="0" border="0" width="100%" class="tl-page" style="background:${DAY.stock};">
256
- <tr><td align="center" style="padding:28px 12px 40px 12px;">${renderCard(spec, "day")}</td></tr>
177
+ <table role="presentation" cellpadding="0" cellspacing="0" border="0" width="100%" class="tl-page" style="table-layout:fixed;background:${DAY.page};">
178
+ <tr><td align="center" style="padding:20px 12px 32px 12px;">${renderCard(spec, "day")}</td></tr>
257
179
  </table>
258
180
  </body></html>
259
181
  `;
260
182
  }
261
183
 
262
- /* ------------------------------------------------------------------ text */
263
-
264
184
  export function renderText(spec) {
265
185
  const out = [];
266
- const { result } = splitSubject(spec.subject);
267
- const action = ACTION[resolveAction(spec)].toUpperCase();
268
186
 
269
- /* The twin carries the same distinctions in the material it has: a rule above
270
- * and below, which is the heaviest thing 72 columns of ASCII can say. */
271
- if (spec.system) {
272
- const kind = spec.system.toUpperCase();
273
- out.push(
274
- "=".repeat(COLUMNS),
275
- `${WORDMARK}${" ".repeat(Math.max(COLUMNS - WORDMARK.length - kind.length, 1))}${kind}`,
276
- "=".repeat(COLUMNS),
277
- "",
278
- );
187
+ if (spec.system && !spec.code) {
188
+ const { result } = splitSubject(spec.subject);
189
+ out.push(`${WORDMARK} · ${spec.system.toUpperCase()}`, "", ...wrap(result));
279
190
  }
280
191
 
281
- out.push(
282
- `TLDR${" ".repeat(Math.max(COLUMNS - 4 - action.length, 1))}${action}`,
283
- "",
284
- ...wrap(result),
285
- "",
286
- );
287
-
288
- /* The reply mark owns a gutter in the twin too, so a wrapped instruction stays
289
- * visibly attached to it. The twin is an equal document, not a dump: it
290
- * resolves the same inline Markdown the HTML does and shows the result rather
291
- * than the notation. */
292
- const reply = wrap(
293
- footerInlineText(spec.reply ?? REPLY_DEFAULT),
294
- COLUMNS - 3,
295
- );
296
- out.push(
297
- `${TEXT_GLYPH.reply} ${reply[0]}`,
298
- ...reply.slice(1).map((l) => ` ${l}`),
299
- );
300
-
301
- /* The twin gives the code its own indented line and nothing else on it. There
302
- * is no type size to reach for here, so isolation does the work instead. */
303
192
  if (spec.code) out.push("", ` ${spec.code}`);
304
-
305
193
  if (spec.body?.trim()) {
306
- out.push(
307
- "",
308
- "-".repeat(COLUMNS),
309
- "",
310
- ...blocksText(parseMarkdown(spec.body)),
311
- );
194
+ if (out.length) out.push("");
195
+ out.push(...blocksText(parseMarkdown(spec.body)));
312
196
  }
313
197
 
314
- out.push("", "-".repeat(COLUMNS), "");
198
+ out.push("", "--", ...wrap(footerInlineText(spec.reply ?? REPLY_DEFAULT)));
315
199
 
316
200
  const context = contextPairs(spec);
317
- if (context.length)
201
+ if (context.length) {
318
202
  out.push(
319
203
  ...wrap(context.map(([label, value]) => `${label} ${value}`).join(" · ")),
320
- "",
321
204
  );
205
+ }
322
206
 
323
- out.push(WORDMARK);
324
- out.push(...wrap(footerInlineText(spec.notice ?? NOTICE_DEFAULT)), "");
325
-
207
+ out.push(
208
+ ...wrap(footerInlineText(spec.notice ?? NOTICE_DEFAULT)),
209
+ "Sent via tldr;",
210
+ "",
211
+ );
326
212
  return out.join("\n");
327
213
  }
328
214