@joenandez/tldr 1.0.0 → 1.0.1

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.
@@ -12,7 +12,7 @@
12
12
  "source": {
13
13
  "source": "npm",
14
14
  "package": "@joenandez/tldr",
15
- "version": "1.0.0"
15
+ "version": "1.0.1"
16
16
  },
17
17
  "category": "productivity",
18
18
  "homepage": "https://github.com/joenandez/tldr#readme"
@@ -2,7 +2,7 @@
2
2
  "$schema": "https://json.schemastore.org/claude-code-plugin-manifest.json",
3
3
  "name": "tldr",
4
4
  "displayName": "tldr;",
5
- "version": "1.0.0",
5
+ "version": "1.0.1",
6
6
  "description": "Set up private owner email for Claude Code and continue the same session when the owner replies.",
7
7
  "author": {
8
8
  "name": "Codename, Inc."
package/bin/tldr-agent CHANGED
@@ -26,6 +26,16 @@ operation=${1:-$(tldr_default_operation)}
26
26
  case "$operation" in
27
27
  setup|status|configure|repair|uninstall)
28
28
  if [ "$#" -gt 0 ]; then shift; fi
29
+ if [ -f "${plugin_root}/LOCAL-SNAPSHOT-MANIFEST.json" ]; then
30
+ tldr_agent_home=${TLDR_AGENT_HOME:-${HOME}/.tldr-agent}
31
+ runtime_node="${tldr_agent_home}/install/runtime/bin/node"
32
+ if [ ! -x "${runtime_node}" ]; then
33
+ printf '%s\n' '{"ok":false,"data":null,"error":{"code":"LOCAL_SNAPSHOT_UNAVAILABLE","message":"tldr; local snapshot runtime is unavailable.","retryable":false,"remediation":"Run npm run local:update."}}'
34
+ exit 1
35
+ fi
36
+ exec "${runtime_node}" "${plugin_root}/src/lib/local_snapshot_front_door.mjs" \
37
+ "${operation}" "$@"
38
+ fi
29
39
  exec "${plugin_root}/install/tldr-agent-bootstrap.sh" \
30
40
  --package-root "${plugin_root}" \
31
41
  --operation "${operation}" "$@"
@@ -129,8 +129,9 @@ fi
129
129
  /usr/bin/plutil -insert launch_source -string "${LAUNCH_SOURCE}" "${IDENTITY_TMP}"
130
130
  /usr/bin/plutil -insert session_started_at -string "${NOW}" "${IDENTITY_TMP}"
131
131
  PLUGIN_RELEASE=${CLAUDE_PLUGIN_VERSION:-unknown}
132
- if [ -n "${CLAUDE_PLUGIN_ROOT:-}" ] && [ -f "${CLAUDE_PLUGIN_ROOT}/.claude-plugin/plugin.json" ]; then
133
- PLUGIN_RELEASE=$(/usr/bin/plutil -extract version raw -o - "${CLAUDE_PLUGIN_ROOT}/.claude-plugin/plugin.json" 2>/dev/null || printf '%s' "${PLUGIN_RELEASE}")
132
+ PLUGIN_INSTALL_ROOT=${PLUGIN_ROOT:-${CLAUDE_PLUGIN_ROOT:-}}
133
+ if [ -n "${PLUGIN_INSTALL_ROOT}" ] && [ -f "${PLUGIN_INSTALL_ROOT}/.claude-plugin/plugin.json" ]; then
134
+ PLUGIN_RELEASE=$(/usr/bin/plutil -extract version raw -o - "${PLUGIN_INSTALL_ROOT}/.claude-plugin/plugin.json" 2>/dev/null || printf '%s' "${PLUGIN_RELEASE}")
134
135
  fi
135
136
  /usr/bin/plutil -insert plugin_release -string "${PLUGIN_RELEASE}" "${IDENTITY_TMP}"
136
137
  /usr/bin/plutil -remove _tldr_agent_identity "${IDENTITY_TMP}"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joenandez/tldr",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "os": [
5
5
  "darwin"
6
6
  ],
@@ -200,6 +200,9 @@
200
200
  "release:public:export": "node scripts/export-public-release.mjs",
201
201
  "release:source-archive": "node scripts/build-starport-source-archive.mjs",
202
202
  "qa:aegis:candidate": "node scripts/prepare-aegis-qa-candidate.mjs",
203
+ "local:update": "node scripts/local-update.mjs",
204
+ "local:rollback": "node scripts/local-rollback.mjs",
205
+ "test:local-update": "node --test tests/test_local_update.mjs",
203
206
  "preflight": "scripts/preflight.sh"
204
207
  },
205
208
  "devDependencies": {
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "schema_version": 1,
3
- "release": "1.0.0",
3
+ "release": "1.0.1",
4
4
  "plugin_manifest": {
5
5
  "path": ".claude-plugin/plugin.json",
6
6
  "bytes": 618,
7
- "sha256": "ba58f90334018e3543e53805f4d925887f2b819e93e996db8d640225edf1e68d"
7
+ "sha256": "c70a39f6a330c3700ceeead93380de3740352ba39a1c212c973024a305392502"
8
8
  },
9
9
  "hook_manifest": {
10
10
  "path": "hooks/hooks.json",
@@ -25,13 +25,13 @@
25
25
  },
26
26
  "tldr_agent": {
27
27
  "path": "release/payloads/arm64/tldr-agent.tar.gz",
28
- "bytes": 367350,
29
- "sha256": "e1e6ccd8a694682fc750d6ee89d1f2897b769124fea237d204005cc137cbee8a"
28
+ "bytes": 369860,
29
+ "sha256": "6e53dbe587d2e6d8ddc0ebd63a43c7c10b77dc82df44d8d2ab8d48a5de981ed1"
30
30
  },
31
31
  "aegis": {
32
32
  "path": "release/payloads/arm64/TldrAgentAegis.pkg",
33
- "bytes": 291376,
34
- "sha256": "c5a6be015c87f2b71ace1c41d8f6eb1b2f2a2db7afbe97b945872b80ba729c87"
33
+ "bytes": 291409,
34
+ "sha256": "84dfad75baaa6ef2908fa46ff6dd0d976be4e72dd78b4d67a9536e7cddcb6dab"
35
35
  }
36
36
  }
37
37
  }
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "schema_version": 1,
3
3
  "phase": "source",
4
- "release": "1.0.0",
4
+ "release": "1.0.1",
5
5
  "source_commit": null,
6
6
  "npm": {
7
7
  "package": "@joenandez/tldr",
8
- "version": "1.0.0",
8
+ "version": "1.0.1",
9
9
  "publication": {
10
10
  "status": "pending",
11
11
  "dist_integrity": null,
@@ -45,14 +45,19 @@
45
45
  "source_commit": null
46
46
  },
47
47
  "tightbeam": {
48
- "package": "tightbeam",
49
- "version": "0.2.0",
50
- "protocol": {
51
- "min": "1.0",
52
- "max": "1"
48
+ "compatibility": {
49
+ "protocol": {
50
+ "min": "1.0",
51
+ "max": "1"
52
+ },
53
+ "requiredCapabilities": ["channels.v1"]
53
54
  },
54
- "state_schema_version": 14,
55
- "required_capability": "channels.v1"
55
+ "qualification": {
56
+ "version": "0.2.0",
57
+ "sourceCommit": "70ef86da746e59d650d8b02109715fb32b438d5e",
58
+ "treeDigest": "sha256:b7d2bddbd4f2b9c8bcc449b79cf062ee653b7e0c64d5a8d50ebf9830d79d3474",
59
+ "tarballSha256": "18390c9a25ed95e2aac206a15168c5e27d6308e6bcc6c39ed9f356596d807675"
60
+ }
56
61
  },
57
62
  "dependencies": {
58
63
  "yaml": "2.8.3",
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: tldr
3
- description: "Use tldr; to set up, check, configure, repair, or uninstall the Claude plugin. It handles signed Aegis enrollment and Tightbeam email-channel registration without exposing private identity settings."
3
+ description: "Use tldr; to set up, check, configure, repair, or uninstall the installed plugin. It handles signed Aegis enrollment and Tightbeam email-channel registration without exposing private identity settings."
4
4
  version: 3
5
5
  ---
6
6
 
@@ -13,7 +13,7 @@ message and delivery authority.
13
13
 
14
14
  ## Lifecycle front door
15
15
 
16
- Run only the bundled plugin launcher:
16
+ Run only the bundled plugin launcher. Claude Code resolves its own plugin root:
17
17
 
18
18
  ```bash
19
19
  "${CLAUDE_PLUGIN_ROOT}/bin/tldr-agent" setup --json
@@ -23,12 +23,23 @@ Run only the bundled plugin launcher:
23
23
  "${CLAUDE_PLUGIN_ROOT}/bin/tldr-agent" uninstall --json
24
24
  ```
25
25
 
26
+ Codex resolves its own plugin root:
27
+
28
+ ```bash
29
+ "${PLUGIN_ROOT}/bin/tldr-agent" setup --json
30
+ "${PLUGIN_ROOT}/bin/tldr-agent" status --json
31
+ "${PLUGIN_ROOT}/bin/tldr-agent" configure --json
32
+ "${PLUGIN_ROOT}/bin/tldr-agent" repair --json
33
+ "${PLUGIN_ROOT}/bin/tldr-agent" uninstall --json
34
+ ```
35
+
26
36
  Map `set up` and `Continue setting up tldr;` to `setup`; `check` and “is
27
37
  tldr; ready?” to `status`; owner or provider changes to `configure`; broken,
28
38
  unavailable, or explicit repair requests to `repair`; and removal to
29
39
  `uninstall`. Report the returned safe state and its single remediation. Do not
30
40
  probe private files, invent a second recovery path, or invoke a globally
31
- installed executable.
41
+ installed executable. If the host cannot resolve its plugin root, report that
42
+ the bundled launcher context is unavailable and stop.
32
43
 
33
44
  Setup acquires and verifies the app-owned runtime, then hands private enrollment
34
45
  to the signed Aegis app. Tell the user before Aegis opens. Email and AgentMail
@@ -15,7 +15,7 @@ import {
15
15
  requestAegisStatusSafe,
16
16
  } from "./aegis_client.mjs";
17
17
  import { sanitizeInstallerEnvironment } from "./aegis_installer_environment.mjs";
18
- const PACKAGE_RELEASE = "1.0.0";
18
+ const PACKAGE_RELEASE = "1.0.1";
19
19
  const RELEASE_MANIFEST_SCHEMA = 2;
20
20
  const BROKER_PROTOCOL_VERSION = 2;
21
21
  const SETUP_STATE_SCHEMA_VERSION = 2;
@@ -19,18 +19,48 @@ function lifecycleError(code, message, cause) {
19
19
  }
20
20
 
21
21
  function inspectInstalledAegis({ artifact }) {
22
- if (!existsSync(FIXED_AEGIS_APP)) return false;
22
+ const appVisible = existsSync(FIXED_AEGIS_APP);
23
23
  const receipt = spawnSync(
24
24
  "/usr/sbin/pkgutil",
25
25
  ["--pkg-info", artifact.package_identifier],
26
26
  { stdio: "ignore", timeout: 5_000 },
27
27
  );
28
- if (receipt.status !== 0) return false;
29
28
  const service = spawnSync("/bin/launchctl", ["print", BROKER_LABEL], {
30
29
  stdio: "ignore",
31
30
  timeout: 5_000,
32
31
  });
33
- return service.status === 0;
32
+ return Object.freeze({
33
+ app_visible: appVisible,
34
+ receipt_present: receipt.status === 0,
35
+ broker_ready: service.status === 0,
36
+ });
37
+ }
38
+
39
+ function installationSignals(value) {
40
+ if (value && typeof value === "object") {
41
+ return Object.freeze({
42
+ app_visible: value.app_visible === true,
43
+ receipt_present: value.receipt_present === true,
44
+ broker_ready: value.broker_ready === true,
45
+ });
46
+ }
47
+ const healthy = value === true;
48
+ return Object.freeze({
49
+ app_visible: healthy,
50
+ receipt_present: healthy,
51
+ broker_ready: healthy,
52
+ });
53
+ }
54
+
55
+ function logInstallationVisibility(signals) {
56
+ const fields = Object.entries(signals)
57
+ .map(([name, value]) => `${name}=${value}`)
58
+ .join(" ");
59
+ spawnSync(
60
+ "/usr/bin/logger",
61
+ ["-t", "TldrAgentAegis", `[🪳 TEMP AEGIS_INSTALL_VISIBILITY] ${fields}`],
62
+ { stdio: "ignore", timeout: 5_000 },
63
+ );
34
64
  }
35
65
 
36
66
  export async function installVerifiedLocalAegisPackage({
@@ -39,6 +69,7 @@ export async function installVerifiedLocalAegisPackage({
39
69
  verifyPackage = verifyPackageWithMacOS,
40
70
  installPackage = openInstallerAndWait,
41
71
  inspectInstallation = inspectInstalledAegis,
72
+ logInstallation = logInstallationVisibility,
42
73
  } = {}) {
43
74
  if (
44
75
  typeof packagePath !== "string" ||
@@ -66,12 +97,11 @@ export async function installVerifiedLocalAegisPackage({
66
97
  error,
67
98
  );
68
99
  }
100
+ let signals;
69
101
  try {
70
102
  requireGuiSession();
71
103
  await installPackage(packagePath, artifact);
72
- if (!(await inspectInstallation({ artifact }))) {
73
- throw new Error("Aegis installer closed without a healthy installation");
74
- }
104
+ signals = installationSignals(await inspectInstallation({ artifact }));
75
105
  } catch (error) {
76
106
  throw lifecycleError(
77
107
  "STARPORT_INSTALLATION_INCOMPLETE",
@@ -79,6 +109,23 @@ export async function installVerifiedLocalAegisPackage({
79
109
  error,
80
110
  );
81
111
  }
112
+ try {
113
+ logInstallation(signals);
114
+ } catch {
115
+ // Diagnostics must never alter the verified installation result.
116
+ }
117
+ if (!signals.app_visible && signals.receipt_present && signals.broker_ready) {
118
+ throw lifecycleError(
119
+ "STARPORT_INSTALLATION_INACCESSIBLE",
120
+ "tldr; secure setup is installed but unavailable.",
121
+ );
122
+ }
123
+ if (!Object.values(signals).every(Boolean)) {
124
+ throw lifecycleError(
125
+ "STARPORT_INSTALLATION_INCOMPLETE",
126
+ "tldr; installation did not complete.",
127
+ );
128
+ }
82
129
  return Object.freeze({
83
130
  ok: true,
84
131
  architecture: artifact.architecture,
@@ -1,8 +1,13 @@
1
1
  import { createHash } from "node:crypto";
2
+ import { TIGHTBEAM_COMPATIBILITY } from "./tightbeam_channel_runtime.mjs";
2
3
 
3
4
  const SHA256 = /^[a-f0-9]{64}$/;
4
5
  const SEMVER = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
5
6
 
7
+ // The target-only release lane updates this explicit source contract together
8
+ // with the runtime and release descriptor; a literal avoids a hidden pin.
9
+ export const TIGHTBEAM_TARGET_VERSION = "0.2.0";
10
+
6
11
  export const STARPORT_ACCEPTANCE_STEPS = Object.freeze([
7
12
  "marketplace-add",
8
13
  "plugin-install",
@@ -32,18 +37,37 @@ function sameVersion(packageJson, plugin, marketplace, release) {
32
37
  );
33
38
  }
34
39
 
35
- function tightbeamContractComplete(tightbeam) {
40
+ function tightbeamContractComplete(
41
+ tightbeam,
42
+ expectedTargetVersion,
43
+ expectedQualification,
44
+ ) {
45
+ const compatibility = tightbeam?.compatibility;
46
+ const qualification = tightbeam?.qualification;
36
47
  return Boolean(
37
- tightbeam?.package === "tightbeam" &&
38
- tightbeam.version === "0.2.0" &&
39
- tightbeam.protocol?.min === "1.0" &&
40
- tightbeam.protocol?.max === "1" &&
41
- tightbeam.state_schema_version === 14 &&
42
- tightbeam.required_capability === "channels.v1",
48
+ compatibility?.protocol?.min === TIGHTBEAM_COMPATIBILITY.minProtocol &&
49
+ compatibility.protocol.max === TIGHTBEAM_COMPATIBILITY.maxProtocol &&
50
+ JSON.stringify(compatibility.requiredCapabilities) ===
51
+ JSON.stringify(TIGHTBEAM_COMPATIBILITY.requiredCapabilities) &&
52
+ qualification?.version === expectedTargetVersion &&
53
+ /^[a-f0-9]{40}$/.test(qualification.sourceCommit ?? "") &&
54
+ /^sha256:[a-f0-9]{64}$/.test(qualification.treeDigest ?? "") &&
55
+ SHA256.test(qualification.tarballSha256 ?? "") &&
56
+ (expectedQualification === undefined ||
57
+ JSON.stringify(qualification) ===
58
+ JSON.stringify(expectedQualification)),
43
59
  );
44
60
  }
45
61
 
46
- function sourceContractComplete({ packageJson, plugin, marketplace, release }) {
62
+ function sourceContractComplete({
63
+ packageJson,
64
+ packageLock,
65
+ plugin,
66
+ marketplace,
67
+ release,
68
+ expectedTargetVersion,
69
+ expectedQualification,
70
+ }) {
47
71
  const source = marketplace.plugins?.[0]?.source;
48
72
  return Boolean(
49
73
  packageJson.name === "@joenandez/tldr" &&
@@ -59,6 +83,9 @@ function sourceContractComplete({ packageJson, plugin, marketplace, release }) {
59
83
  source?.source === "npm" &&
60
84
  source.package === packageJson.name &&
61
85
  release.npm?.package === packageJson.name &&
86
+ (packageLock === undefined ||
87
+ (packageLock?.version === packageJson.version &&
88
+ packageLock?.packages?.[""]?.version === packageJson.version)) &&
62
89
  sameVersion(packageJson, plugin, marketplace, release) &&
63
90
  release.schema_version === 1 &&
64
91
  release.phase === "source" &&
@@ -76,7 +103,11 @@ function sourceContractComplete({ packageJson, plugin, marketplace, release }) {
76
103
  release.aegis?.minimum_macos === "13.0" &&
77
104
  JSON.stringify(release.aegis?.architectures) ===
78
105
  JSON.stringify(["arm64"]) &&
79
- tightbeamContractComplete(release.tightbeam) &&
106
+ tightbeamContractComplete(
107
+ release.tightbeam,
108
+ expectedTargetVersion,
109
+ expectedQualification,
110
+ ) &&
80
111
  release.dependencies?.yaml === "2.8.3" &&
81
112
  release.dependencies?.agentmail === "0.4.20" &&
82
113
  release.dependencies?.c8 === "10.1.3",
@@ -100,7 +131,14 @@ function publicationComplete(release) {
100
131
  }
101
132
 
102
133
  export function validateStarportReleaseContract(input = {}) {
103
- if (!sourceContractComplete(input)) refuse("source coordinates unresolved");
134
+ const expectedTargetVersion =
135
+ input.expectedTargetVersion ?? TIGHTBEAM_TARGET_VERSION;
136
+ if (
137
+ !SEMVER.test(expectedTargetVersion) ||
138
+ !sourceContractComplete({ ...input, expectedTargetVersion })
139
+ ) {
140
+ refuse("source coordinates unresolved");
141
+ }
104
142
  if (input.requirePublished === true && !publicationComplete(input.release)) {
105
143
  refuse("publication evidence unresolved");
106
144
  }
@@ -1,5 +1,5 @@
1
1
  import { createHash } from "node:crypto";
2
- import { existsSync, readFileSync, statSync } from "node:fs";
2
+ import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
3
3
  import { homedir } from "node:os";
4
4
  import { basename, join, resolve } from "node:path";
5
5
 
@@ -57,6 +57,30 @@ function matchesFileRecord(root, record) {
57
57
  }
58
58
  }
59
59
 
60
+ function matchesLocalFileRecord(root, record) {
61
+ if (
62
+ !root ||
63
+ !record ||
64
+ typeof record.path !== "string" ||
65
+ record.path.startsWith("/") ||
66
+ record.path.split("/").includes("..")
67
+ ) {
68
+ return false;
69
+ }
70
+ try {
71
+ const path = resolve(root, record.path);
72
+ if (!path.startsWith(`${resolve(root)}/`) || !statSync(path).isFile()) {
73
+ return false;
74
+ }
75
+ return (
76
+ createHash("sha256").update(readFileSync(path)).digest("hex") ===
77
+ record.sha256
78
+ );
79
+ } catch {
80
+ return false;
81
+ }
82
+ }
83
+
60
84
  function releaseMatchesSource(sourceRoot, release) {
61
85
  const packageJson = safeJson(join(sourceRoot, "package.json"));
62
86
  return (
@@ -64,6 +88,34 @@ function releaseMatchesSource(sourceRoot, release) {
64
88
  );
65
89
  }
66
90
 
91
+ function localSnapshotMatches(root) {
92
+ const manifest = safeJson(join(root || "", "LOCAL-SNAPSHOT-MANIFEST.json"));
93
+ if (!manifest?.sourceDigest || !Array.isArray(manifest.files)) return false;
94
+ try {
95
+ for (const entry of manifest.files) {
96
+ if (!matchesLocalFileRecord(root, entry)) return false;
97
+ }
98
+ const listed = manifest.files.map((entry) => entry.path).sort();
99
+ const walk = (path, base = path) =>
100
+ readdirSync(path, { withFileTypes: true })
101
+ .flatMap((entry) => {
102
+ const child = join(path, entry.name);
103
+ return entry.isDirectory()
104
+ ? walk(child, base)
105
+ : entry.isFile() || entry.isSymbolicLink()
106
+ ? [child.slice(base.length + 1)]
107
+ : [];
108
+ })
109
+ .sort();
110
+ const actual = walk(root).filter(
111
+ (path) => path !== "LOCAL-SNAPSHOT-MANIFEST.json",
112
+ );
113
+ return JSON.stringify(actual) === JSON.stringify(listed);
114
+ } catch {
115
+ return false;
116
+ }
117
+ }
118
+
67
119
  function resolveSetupSession(env = process.env) {
68
120
  const explicit = String(env.CLAUDE_CODE_SESSION_ID ?? "").trim();
69
121
  if (explicit) {
@@ -148,6 +200,40 @@ export function createStarportComponentInspector({
148
200
  };
149
201
  }
150
202
 
203
+ export function createLocalSnapshotComponentInspector({
204
+ home,
205
+ sourceRoot,
206
+ pluginRoot,
207
+ aegisApp = AEGIS_APP,
208
+ launchAgent = join(
209
+ homedir(),
210
+ "Library",
211
+ "LaunchAgents",
212
+ "ai.tldr-agent.daemon.plist",
213
+ ),
214
+ nodeExecutable = process.execPath,
215
+ } = {}) {
216
+ return async () => {
217
+ const snapshotHealthy =
218
+ localSnapshotMatches(pluginRoot) &&
219
+ resolve(pluginRoot) === resolve(sourceRoot);
220
+ const installedNode = join(home, "install", "runtime", "bin", "node");
221
+ const nativeInstalled = existsSync(aegisApp);
222
+ return Object.freeze({
223
+ plugin: snapshotHealthy,
224
+ runtime:
225
+ snapshotHealthy && resolve(nodeExecutable) === resolve(installedNode),
226
+ hooks: snapshotHealthy,
227
+ service:
228
+ snapshotHealthy &&
229
+ existsSync(launchAgent) &&
230
+ readFileSync(launchAgent, "utf8").includes(resolve(sourceRoot)),
231
+ aegis: nativeInstalled,
232
+ outbound: nativeInstalled,
233
+ });
234
+ };
235
+ }
236
+
151
237
  function bundledAegisInstaller({
152
238
  home,
153
239
  architecture = normalizedArchitecture(),
@@ -196,7 +282,10 @@ export async function createProductionStarportRuntime({
196
282
  env.HELM_CANONICAL_SQLITE = "1";
197
283
  delete env.HELM_CANONICAL_SQLITE_KILL_SWITCH;
198
284
 
199
- const sourceRoot = join(home, "install", "tldr-agent");
285
+ const localSnapshotRoot = env.TLDR_AGENT_LOCAL_SNAPSHOT_ROOT
286
+ ? resolve(env.TLDR_AGENT_LOCAL_SNAPSHOT_ROOT)
287
+ : null;
288
+ const sourceRoot = localSnapshotRoot || join(home, "install", "tldr-agent");
200
289
  const activationManifest = join(home, "install", "activation-manifest.json");
201
290
  const activePluginRoot = env.TLDR_AGENT_PLUGIN_ROOT
202
291
  ? resolve(env.TLDR_AGENT_PLUGIN_ROOT)
@@ -241,12 +330,18 @@ export async function createProductionStarportRuntime({
241
330
  : unavailableOnboarding());
242
331
  const inspector =
243
332
  inspectComponents ??
244
- createStarportComponentInspector({
245
- home,
246
- sourceRoot,
247
- pluginRoot: activePluginRoot,
248
- activationManifest,
249
- });
333
+ (localSnapshotRoot
334
+ ? createLocalSnapshotComponentInspector({
335
+ home,
336
+ sourceRoot,
337
+ pluginRoot: activePluginRoot,
338
+ })
339
+ : createStarportComponentInspector({
340
+ home,
341
+ sourceRoot,
342
+ pluginRoot: activePluginRoot,
343
+ activationManifest,
344
+ }));
250
345
  return createStarportOrchestrator({
251
346
  inspectComponents: inspector,
252
347
  native: nativeService,
@@ -6,11 +6,12 @@ import {
6
6
  AUTHORITY,
7
7
  ENDPOINT_SESSION,
8
8
  PRINCIPAL_REF,
9
- TIGHTBEAM_CONTRACT,
9
+ TIGHTBEAM_COMPATIBILITY,
10
10
  commandFailure,
11
11
  defaultIdentityStore,
12
12
  expectedPreflightArgs,
13
13
  inboundKey,
14
+ launcherUnavailable,
14
15
  productionRun,
15
16
  unavailable,
16
17
  } from "./tightbeam_channel_runtime.mjs";
@@ -20,7 +21,14 @@ export function createTightbeamChannel({
20
21
  run = productionRun,
21
22
  loadIdentity,
22
23
  saveIdentity,
23
- command = process.env.TIGHTBEAM_BIN || "tightbeam",
24
+ command = process.env.TIGHTBEAM_BIN ||
25
+ join(
26
+ process.env.HOME ?? homedir(),
27
+ ".tightbeam",
28
+ "install",
29
+ "bin",
30
+ "tightbeam",
31
+ ),
24
32
  home = resolve(process.env.TLDR_AGENT_HOME || join(homedir(), ".tldr-agent")),
25
33
  } = {}) {
26
34
  const store = defaultIdentityStore(home);
@@ -34,7 +42,15 @@ export function createTightbeamChannel({
34
42
  credentials: null,
35
43
  args: expectedPreflightArgs(),
36
44
  });
37
- return commandFailure(result) ? unavailable() : Object.freeze({ ok: true });
45
+ if (result === null) return launcherUnavailable();
46
+ if (result?.result?.compatible === false) {
47
+ return unavailable(
48
+ (result.result.checks ?? [])
49
+ .filter((check) => check?.ok === false)
50
+ .map((check) => check.field),
51
+ );
52
+ }
53
+ return result?.ok === true ? Object.freeze({ ok: true }) : result;
38
54
  }
39
55
 
40
56
  async function registerEmailChannel(route) {
@@ -306,5 +322,5 @@ export const _internals = Object.freeze({
306
322
  AUTHORITY,
307
323
  ENDPOINT_SESSION,
308
324
  PRINCIPAL_REF,
309
- TIGHTBEAM_CONTRACT,
325
+ TIGHTBEAM_COMPATIBILITY,
310
326
  });
@@ -6,20 +6,27 @@ import { promisify } from "node:util";
6
6
 
7
7
  const execFileAsync = promisify(execFile);
8
8
 
9
- export const TIGHTBEAM_CONTRACT = Object.freeze({
10
- package: "tightbeam",
11
- version: "0.2.0",
9
+ export const TIGHTBEAM_COMPATIBILITY = Object.freeze({
12
10
  minProtocol: "1.0",
13
11
  maxProtocol: "1",
14
- schemaVersion: 14,
15
- capability: "channels.v1",
12
+ requiredCapabilities: Object.freeze(["channels.v1"]),
16
13
  });
17
14
  export const AUTHORITY = "tldr-email";
18
15
  export const APPLICATION = "tldr-email";
19
16
  export const PRINCIPAL_REF = "verified-owner";
20
17
  export const ENDPOINT_SESSION = "tldr-email-owner";
21
18
 
22
- export function unavailable() {
19
+ export function unavailable(failedDimensions = []) {
20
+ const dimensions = [
21
+ ...new Set(
22
+ failedDimensions.filter(
23
+ (dimension) => typeof dimension === "string" && dimension.length > 0,
24
+ ),
25
+ ),
26
+ ];
27
+ const diagnostic = dimensions.length
28
+ ? ` Failed compatibility dimension${dimensions.length === 1 ? "" : "s"}: ${dimensions.join(", ")}.`
29
+ : "";
23
30
  return Object.freeze({
24
31
  ok: false,
25
32
  data: null,
@@ -27,8 +34,21 @@ export function unavailable() {
27
34
  code: "TIGHTBEAM_INCOMPATIBLE",
28
35
  message: "tldr; requires a compatible Tightbeam installation.",
29
36
  retryable: false,
37
+ remediation: `Install Tightbeam with supported protocol ${TIGHTBEAM_COMPATIBILITY.minProtocol} through ${TIGHTBEAM_COMPATIBILITY.maxProtocol} and required capability ${TIGHTBEAM_COMPATIBILITY.requiredCapabilities.join(", ")}, then rerun setup.${diagnostic}`,
38
+ }),
39
+ });
40
+ }
41
+
42
+ export function launcherUnavailable() {
43
+ return Object.freeze({
44
+ ok: false,
45
+ data: null,
46
+ error: Object.freeze({
47
+ code: "TIGHTBEAM_UNAVAILABLE",
48
+ message: "tldr; cannot launch the activated Tightbeam installation.",
49
+ retryable: false,
30
50
  remediation:
31
- "Install Tightbeam 0.2.0 with channels.v1 support, then rerun setup.",
51
+ "Activate Tightbeam, approve plugin trust, or start a new session, then rerun setup.",
32
52
  }),
33
53
  });
34
54
  }
@@ -87,7 +107,28 @@ export async function productionRun({ command, admin, credentials, args }) {
87
107
  ) {
88
108
  return { ok: true, result: { already_registered: true } };
89
109
  }
90
- return null;
110
+ if (typeof error?.stdout === "string" && error.stdout.trim().length > 0) {
111
+ try {
112
+ return JSON.parse(error.stdout);
113
+ } catch {
114
+ // A launched command that emits malformed data is not a missing launcher.
115
+ }
116
+ }
117
+ if (
118
+ ["ENOENT", "EACCES", "EPERM"].includes(error?.code) ||
119
+ (error?.errno && !error?.stdout)
120
+ )
121
+ return null;
122
+ return {
123
+ ok: false,
124
+ data: null,
125
+ error: {
126
+ code: "TIGHTBEAM_OPERATION_FAILED",
127
+ message:
128
+ "tldr; launched Tightbeam but it did not return a valid response.",
129
+ retryable: false,
130
+ },
131
+ };
91
132
  }
92
133
  }
93
134
 
@@ -95,15 +136,13 @@ export function expectedPreflightArgs() {
95
136
  return [
96
137
  "preflight",
97
138
  "--min-protocol",
98
- TIGHTBEAM_CONTRACT.minProtocol,
139
+ TIGHTBEAM_COMPATIBILITY.minProtocol,
99
140
  "--max-protocol",
100
- TIGHTBEAM_CONTRACT.maxProtocol,
101
- "--expect-schema",
102
- String(TIGHTBEAM_CONTRACT.schemaVersion),
103
- "--require-capability",
104
- TIGHTBEAM_CONTRACT.capability,
105
- "--expect-daemon-version",
106
- TIGHTBEAM_CONTRACT.version,
141
+ TIGHTBEAM_COMPATIBILITY.maxProtocol,
142
+ ...TIGHTBEAM_COMPATIBILITY.requiredCapabilities.flatMap((capability) => [
143
+ "--require-capability",
144
+ capability,
145
+ ]),
107
146
  ];
108
147
  }
109
148
 
@@ -317,7 +317,7 @@ export async function waitForTldrAgentHealth({
317
317
  observeDaemon = null,
318
318
  home,
319
319
  port,
320
- timeoutMs = 5_000,
320
+ timeoutMs = 30_000,
321
321
  requirePollFresh = true,
322
322
  fetchImpl = globalThis.fetch,
323
323
  now = Date.now,
@@ -356,6 +356,7 @@ export async function waitForTldrAgentHealth({
356
356
  "package_version",
357
357
  "source_revision",
358
358
  "source_dirty",
359
+ "source_digest",
359
360
  "schema_version",
360
361
  ].every(
361
362
  (key) => body?.runtime?.[key] === expectedRuntimeIdentity?.[key],
@@ -1,10 +1,8 @@
1
1
  export const DEFAULT_TLDR_AGENT_PHASE_TIMEOUT_MS = 5000;
2
2
  export const DEFAULT_TLDR_AGENT_CHILD_GRACE_MS = 5000;
3
- export const TLDR_AGENT_MAIL_PHASE_SEQUENCE = Object.freeze([
4
- "inbox_poll",
5
- "reply_obligation_sla",
6
- "comms_dispatcher",
7
- ]);
3
+ // Tightbeam owns reply obligations and dispatch. The tldr; daemon retains only
4
+ // the provider-to-channel bridge poll.
5
+ export const TLDR_AGENT_MAIL_PHASE_SEQUENCE = Object.freeze(["inbox_poll"]);
8
6
 
9
7
  function numericTimeout(value, fallback) {
10
8
  const timeout = Number(value);
@@ -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),
package/src/starport.mjs CHANGED
@@ -32,6 +32,18 @@ function unsupported() {
32
32
  }
33
33
 
34
34
  function unavailable(error) {
35
+ if (error?.code === "STARPORT_INSTALLATION_INACCESSIBLE") {
36
+ return Object.freeze({
37
+ ok: false,
38
+ data: null,
39
+ error: Object.freeze({
40
+ code: "STARPORT_INSTALLATION_INACCESSIBLE",
41
+ message: "tldr; secure setup is installed but unavailable.",
42
+ retryable: false,
43
+ remediation: "Reinstall tldr;",
44
+ }),
45
+ });
46
+ }
35
47
  if (error?.code === "STARPORT_INSTALLATION_INCOMPLETE") {
36
48
  return Object.freeze({
37
49
  ok: false,