totemlayer 0.1.42 → 0.1.59

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 (42) hide show
  1. package/README.md +48 -11
  2. package/bin/agent-memory.mjs +244 -0
  3. package/bin/agent-profile.mjs +26 -4
  4. package/bin/agent-runner.mjs +43 -9
  5. package/bin/agent-setup.mjs +136 -50
  6. package/bin/automatic-runtime.mjs +27 -8
  7. package/bin/chat-prompt-limit.mjs +67 -0
  8. package/bin/codex-chat-bridge.mjs +36 -8
  9. package/bin/codex-chat-readiness.mjs +7 -0
  10. package/bin/codex-human-chat-bridge.mjs +209 -0
  11. package/bin/collaboration-listener.mjs +2 -1
  12. package/bin/connected-agent-service.mjs +4 -1
  13. package/bin/inbox-queue.mjs +2 -1
  14. package/bin/installation.mjs +93 -44
  15. package/bin/local-mcp.mjs +43 -4
  16. package/bin/mcp-config.d.mts +11 -0
  17. package/bin/mcp-config.mjs +56 -0
  18. package/bin/mcp-install.mjs +143 -12
  19. package/bin/mcp-listener.d.mts +22 -0
  20. package/bin/mcp-listener.mjs +4 -0
  21. package/bin/mcp-runtime.mjs +3 -1
  22. package/bin/mcp.mjs +331 -94
  23. package/bin/mission-agent-service.mjs +2 -1
  24. package/bin/mission-worker.mjs +13 -2
  25. package/bin/model-adapter.mjs +1 -4
  26. package/bin/network-contract.mjs +254 -0
  27. package/bin/network-runtime.mjs +160 -25
  28. package/bin/network.mjs +30 -5
  29. package/bin/platform-client.mjs +25 -3
  30. package/bin/provider-detection.mjs +1 -4
  31. package/bin/runtime-diagnostics.mjs +1 -0
  32. package/bin/runtime-installation.mjs +57 -16
  33. package/bin/sdk/index.d.ts +50 -6
  34. package/bin/sdk/index.js +1 -1
  35. package/bin/sdk/listener.d.ts +57 -0
  36. package/bin/sdk/listener.js +1 -0
  37. package/bin/sdk/types.d.ts +62 -0
  38. package/bin/startup-diagnostics.mjs +168 -0
  39. package/bin/totem.mjs +17 -3
  40. package/bin/worker-core/adapters.mjs +4 -4
  41. package/package.json +1 -1
  42. package/scripts/prepare.mjs +28 -8
@@ -0,0 +1,168 @@
1
+ // Public diagnostics contain fixed descriptions only. Never log exception messages,
2
+ // provider output, command arguments, paths, or credentials from a failed startup.
3
+ export const HOST_APPROVAL_RECOVERY =
4
+ "Stop retrying. Ask the owner to inspect this command in the host app's approval or automatic review controls. If no approval path is available, contact the host's support with the denial. Resume once after the owner resolves it; do not bypass the policy or change agents.";
5
+
6
+ const causes = {
7
+ HOST_APPROVAL_DENIED: [
8
+ "The host denied approval to execute the startup command.",
9
+ HOST_APPROVAL_RECOVERY,
10
+ false,
11
+ ],
12
+ EADDRINUSE: [
13
+ "The listener could not bind because its port or socket is already in use.",
14
+ "Inspect the process using the configured port or socket; stop a duplicate listener or choose an available endpoint before starting this profile again.",
15
+ ],
16
+ EACCES: [
17
+ "The operating system denied access to a startup resource.",
18
+ "Check the owner's access to the executable, private state directory, and configured port; repair the specific permission before restarting.",
19
+ ],
20
+ EPERM: [
21
+ "The operating system denied the startup operation.",
22
+ "Inspect the host's process and filesystem restrictions and have the owner resolve the denied operation before restarting.",
23
+ ],
24
+ ENOENT: [
25
+ "A required startup executable or file was not found.",
26
+ "Check the selected executable and private configuration paths; install or restore the missing resource before restarting.",
27
+ ],
28
+ ECONNREFUSED: [
29
+ "The configured service refused the connection.",
30
+ "Start the configured model or service and check its endpoint before restarting this profile.",
31
+ ],
32
+ ENOTFOUND: [
33
+ "The configured service hostname could not be resolved.",
34
+ "Check the configured hostname and network DNS, then restart this profile.",
35
+ ],
36
+ ETIMEDOUT: [
37
+ "The startup connection timed out.",
38
+ "Check the service endpoint and network availability before restarting this profile.",
39
+ ],
40
+ RUN_TIMEOUT: [
41
+ "The executor did not finish the controlled readiness reply before its deadline.",
42
+ "Check the selected executor and model availability before restarting this profile.",
43
+ ],
44
+ PROVIDER_AUTH_REQUIRED: [
45
+ "The selected inference provider credential is missing or unavailable.",
46
+ "Restore the selected provider credential in this host's secret environment before restarting. Never copy another agent's key.",
47
+ ],
48
+ RUNTIME_AUTHORIZATION_REJECTED: [
49
+ "Totem rejected the profile's credential or access.",
50
+ "Reauthorize this agent with totem login --reauthorize. Never copy another agent's key.",
51
+ ],
52
+ AGENT_IDENTITY_MISMATCH: [
53
+ "The authenticated agent does not match the saved profile.",
54
+ "Inspect this profile's agent and origin; reconnect the intended agent without replacing another agent's configuration.",
55
+ ],
56
+ ISOLATION_UNAVAILABLE: [
57
+ "The selected executor's required process isolation is unavailable.",
58
+ "Repair the supported isolation backend on this host before restarting; do not disable containment.",
59
+ ],
60
+ PRIVACY_BOUNDARY_UNAVAILABLE: [
61
+ "The executor's required privacy boundary is unavailable.",
62
+ "Repair the configured privacy boundary before restarting; do not bypass it.",
63
+ ],
64
+ AGENT_AUTH_REQUIRED: [
65
+ "The selected agent client is not authenticated.",
66
+ "Sign in to the selected client on this host, then explicitly start this profile once.",
67
+ ],
68
+ AGENT_QUOTA_EXCEEDED: [
69
+ "The selected agent provider rejected startup because its usage quota is exhausted.",
70
+ "Inspect the selected provider's usage limits and resume once capacity is available.",
71
+ ],
72
+ AGENT_CLI_INCOMPATIBLE: [
73
+ "The installed agent CLI does not support the required startup contract.",
74
+ "Install a supported version of the selected client, then start this profile once.",
75
+ ],
76
+ HARNESS_SETUP_REQUIRED: [
77
+ "The selected host has not completed its native receiver setup.",
78
+ "Complete the selected host's supported setup and inspect its approval controls before starting this profile.",
79
+ ],
80
+ READINESS_UNSUPPORTED: [
81
+ "The installed adapter cannot verify the controlled readiness check.",
82
+ "Update the selected adapter to a version that supports receive, wake, and reply verification before claiming readiness.",
83
+ ],
84
+ AGENT_NOT_INSTALLED: [
85
+ "The selected agent executable is not installed or cannot be located.",
86
+ "Install the selected agent client and check this host's executable path before restarting.",
87
+ ],
88
+ AGENT_START_FAILED: [
89
+ "The executor process could not be launched.",
90
+ "Check that the selected executable exists and the owner can run it on this host.",
91
+ ],
92
+ AGENT_EXIT_FAILED: [
93
+ "The executor exited with a nonzero status during startup.",
94
+ "Inspect the selected executor's local diagnostics and sign-in state before restarting; do not share credentials or raw provider output.",
95
+ ],
96
+ INVALID_AGENT_RESULT: [
97
+ "The executor returned an invalid readiness response.",
98
+ "Check the selected adapter's response format and configured model before restarting.",
99
+ ],
100
+ READINESS_CHALLENGE_FAILED: [
101
+ "Totem could not supply a valid controlled readiness challenge.",
102
+ "Check Totem connectivity and the installed receiver version before restarting this profile.",
103
+ ],
104
+ READINESS_GENERATION_FAILED: [
105
+ "The selected executor failed while generating the controlled readiness reply; it supplied no recognized cause.",
106
+ "Inspect the selected executor's local diagnostics and authorization before restarting this profile.",
107
+ ],
108
+ READINESS_REPLY_REJECTED: [
109
+ "Totem did not accept the controlled readiness reply.",
110
+ "Check that the selected executor returns the exact readiness challenge response and that the runtime session is current before restarting.",
111
+ ],
112
+ READINESS_REPLY_INVALID: [
113
+ "The executor did not return the exact controlled readiness response.",
114
+ "Check the selected adapter's output contract and repeat the readiness check once after repair.",
115
+ ],
116
+ READINESS_EXPIRED: [
117
+ "The controlled readiness challenge expired before it completed.",
118
+ "Check executor latency and start a fresh runtime session to obtain a new challenge.",
119
+ ],
120
+ RUNTIME_SUPERSEDED: [
121
+ "Another runtime session owns this connection credential.",
122
+ "Inspect the existing listener and use its session; stop it explicitly before replacing it. Do not start duplicate workers.",
123
+ ],
124
+ BACKGROUND_START_TIMEOUT: [
125
+ "The background worker did not confirm startup before its deadline.",
126
+ "Inspect totem status for this profile and the selected executor's local diagnostics before starting it again.",
127
+ ],
128
+ STARTUP_CAUSE_UNAVAILABLE: [
129
+ "Startup failed without a recognized underlying cause.",
130
+ "Inspect this profile with totem status and the selected executor's local diagnostics before restarting. Share error codes, not credentials or raw provider output.",
131
+ ],
132
+ };
133
+
134
+ const known = (code) => typeof code === "string" && Object.hasOwn(causes, code);
135
+
136
+ export function startupDiagnostic(error) {
137
+ const chain = [];
138
+ const seen = new Set();
139
+ for (
140
+ let item = error;
141
+ item && typeof item === "object" && chain.length < 8 && !seen.has(item);
142
+ item = item.cause
143
+ ) {
144
+ seen.add(item);
145
+ chain.push(item);
146
+ }
147
+ const denied = chain.some(
148
+ (item) =>
149
+ ["HOST_APPROVAL_DENIED", "APPROVAL_DENIED", "POLICY_DENIED"].includes(item.code) ||
150
+ /(?:rejected:\s*)?blocked by policy|automatic (?:approval )?review rejected|approval (?:was )?denied/i.test(
151
+ String(item.message ?? ""),
152
+ ),
153
+ );
154
+ const match = chain
155
+ .toReversed()
156
+ .find((item) => known(item.code) || known(item.causeCode) || [401, 403].includes(item.status));
157
+ const causeCode = denied
158
+ ? "HOST_APPROVAL_DENIED"
159
+ : match
160
+ ? known(match.code)
161
+ ? match.code
162
+ : known(match.causeCode)
163
+ ? match.causeCode
164
+ : "RUNTIME_AUTHORIZATION_REJECTED"
165
+ : "STARTUP_CAUSE_UNAVAILABLE";
166
+ const [cause, recovery, retryable = true] = causes[causeCode];
167
+ return { causeCode, cause, recovery, retryable };
168
+ }
package/bin/totem.mjs CHANGED
@@ -239,9 +239,9 @@ function compactDigest(value) {
239
239
  function help() {
240
240
  writeBrand();
241
241
  writeHelpBody(`Start here
242
- Install once npm install --global https://totemlayer.com/downloads/totemlayer-0.1.42.tgz
242
+ Install once npm install --global https://totemlayer.com/downloads/totemlayer-0.1.59.tgz
243
243
  Confirm installation totem --version
244
- Run one-off npx --yes --package https://totemlayer.com/downloads/totemlayer-0.1.42.tgz totem --help
244
+ Run one-off npx --yes --package https://totemlayer.com/downloads/totemlayer-0.1.59.tgz totem --help
245
245
 
246
246
  Connect once and receive messages and approved Mission work
247
247
  Select Codex, Claude, a local model, or an owner-configured CLI/HTTP agent.
@@ -255,7 +255,9 @@ Agent messaging and local runtime
255
255
  totem network --help
256
256
  totem network run --provider qwen-local --model qwen3.5-9b
257
257
 
258
- Connect an AI app through MCP
258
+ Connect any AI agent or personal assistant through MCP
259
+ totem mcp config
260
+ totem mcp config --transport stdio --key-file /absolute/path/to/agent.key
259
261
  totem mcp
260
262
 
261
263
  Authorization handshake
@@ -1781,6 +1783,18 @@ async function main() {
1781
1783
  return;
1782
1784
  }
1783
1785
  if (process.argv[2] === "mcp") {
1786
+ if (process.argv[3] === "config") {
1787
+ const { configureTotemMcp } = await import("./mcp-install.mjs");
1788
+ try {
1789
+ process.stdout.write(await configureTotemMcp(process.argv.slice(4)));
1790
+ } catch (error) {
1791
+ process.stderr.write(
1792
+ `${error instanceof Error ? error.message : "Could not export MCP settings."}\n`,
1793
+ );
1794
+ process.exitCode = 1;
1795
+ }
1796
+ return;
1797
+ }
1784
1798
  if (process.argv[3] === "install" || process.argv[3] === "--help" || process.argv[3] === "-h") {
1785
1799
  const { installTotemMcp } = await import("./mcp-install.mjs");
1786
1800
  try {
@@ -127,8 +127,8 @@ export function createCommandAdapter(config) {
127
127
  windowsHide: true,
128
128
  stdio: ["pipe", "pipe", "pipe"],
129
129
  });
130
- } catch {
131
- reject(new WorkerError("AGENT_START_FAILED"));
130
+ } catch (error) {
131
+ reject(Object.assign(new WorkerError("AGENT_START_FAILED"), { cause: error }));
132
132
  return;
133
133
  }
134
134
  const timeout = setTimeout(() => stop("RUN_TIMEOUT"), timeoutMs);
@@ -149,8 +149,8 @@ export function createCommandAdapter(config) {
149
149
  child.stdin.on("error", () => {
150
150
  /* A failed child can close stdin early. */
151
151
  });
152
- child.on("error", () => {
153
- failure ??= new WorkerError("AGENT_START_FAILED");
152
+ child.on("error", (error) => {
153
+ failure ??= Object.assign(new WorkerError("AGENT_START_FAILED"), { cause: error });
154
154
  });
155
155
  child.on("close", (code) => {
156
156
  clearTimeout(timeout);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "totemlayer",
3
- "version": "0.1.42",
3
+ "version": "0.1.59",
4
4
  "description": "Cross-platform CLI for TotemLayer agent identity and authorization",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,13 +1,27 @@
1
1
  import { access, readdir, readFile, writeFile } from "node:fs/promises";
2
2
  import { transform } from "esbuild";
3
+ import { generateNetworkContract } from "../../../scripts/generate-network-contract.mjs";
4
+ await generateNetworkContract();
3
5
  // This candidate rebases coordination on the immutable published 0.1.21 bundle.
4
6
  // Its bundled SDK is the release source; do not rebuild it from an older sibling checkout.
5
7
  for (const name of [
6
- "totem.mjs", "mission-worker.mjs", "mission-coordination.mjs",
7
- "sdk/index.js", "sdk/index.d.ts", "sdk/types.d.ts",
8
- "network-retry.mjs", "runtime-diagnostics.mjs", "codex-chat-bridge.mjs",
9
- "worker-core/adapters.mjs", "worker-core/errors.mjs",
10
- ]) await access(new URL(`../bin/${name}`, import.meta.url));
8
+ "totem.mjs",
9
+ "mission-worker.mjs",
10
+ "mission-coordination.mjs",
11
+ "sdk/index.js",
12
+ "sdk/index.d.ts",
13
+ "sdk/listener.js",
14
+ "sdk/listener.d.ts",
15
+ "sdk/types.d.ts",
16
+ "network-retry.mjs",
17
+ "runtime-diagnostics.mjs",
18
+ "codex-chat-bridge.mjs",
19
+ "codex-human-chat-bridge.mjs",
20
+ "chat-prompt-limit.mjs",
21
+ "worker-core/adapters.mjs",
22
+ "worker-core/errors.mjs",
23
+ ])
24
+ await access(new URL(`../bin/${name}`, import.meta.url));
11
25
 
12
26
  // Compact the release SDK without rebuilding it from an older sibling source.
13
27
  // Retain every module, export, name and declaration; no feature code is removed.
@@ -16,9 +30,15 @@ for (const name of await readdir(sdk)) {
16
30
  if (!name.endsWith(".js")) continue;
17
31
  const path = new URL(name, sdk);
18
32
  const result = await transform(await readFile(path, "utf8"), {
19
- loader: "js", target: "es2022", format: "esm",
20
- minifyWhitespace: true, minifyIdentifiers: false, minifySyntax: false,
21
- treeShaking: false, keepNames: false, legalComments: "eof",
33
+ loader: "js",
34
+ target: "es2022",
35
+ format: "esm",
36
+ minifyWhitespace: true,
37
+ minifyIdentifiers: false,
38
+ minifySyntax: false,
39
+ treeShaking: false,
40
+ keepNames: false,
41
+ legalComments: "eof",
22
42
  });
23
43
  await writeFile(path, result.code);
24
44
  }