@wolpertingerlabs/drawlatch 1.0.0-alpha.9.1 → 1.0.0-alpha.9.3

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.
package/bin/drawlatch.js CHANGED
@@ -38,7 +38,7 @@ const { generateKeyBundle, saveKeyBundle, extractPublicKeys, fingerprint, loadKe
38
38
  );
39
39
 
40
40
  // Import connection template helpers
41
- const { listConnectionTemplates, listAvailableConnections } = await import(
41
+ const { listConnectionTemplates } = await import(
42
42
  join(PKG_ROOT, "dist/shared/connections.js")
43
43
  );
44
44
 
@@ -80,8 +80,6 @@ try {
80
80
  lines: { type: "string", short: "n", default: "50" },
81
81
  follow: { type: "boolean", default: false },
82
82
  path: { type: "boolean", default: false },
83
- connections: { type: "string" },
84
- alias: { type: "string" },
85
83
  full: { type: "boolean", default: false },
86
84
  ttl: { type: "string", default: "300" },
87
85
  },
@@ -105,7 +103,10 @@ if (values.version) {
105
103
  }
106
104
  if (values.help && !subcommand) {
107
105
  printHelp();
108
- const latestVersion = await updateCheckPromise;
106
+ const latestVersion = await Promise.race([
107
+ updateCheckPromise,
108
+ new Promise((r) => setTimeout(() => r(null), 100)),
109
+ ]);
109
110
  if (latestVersion) console.log(formatUpdateNotice(latestVersion));
110
111
  process.exit(0);
111
112
  }
@@ -187,7 +188,10 @@ switch (subcommand) {
187
188
  case "help":
188
189
  printHelp();
189
190
  {
190
- const latestVersion = await updateCheckPromise;
191
+ const latestVersion = await Promise.race([
192
+ updateCheckPromise,
193
+ new Promise((r) => setTimeout(() => r(null), 100)),
194
+ ]);
191
195
  if (latestVersion) console.log(formatUpdateNotice(latestVersion));
192
196
  }
193
197
  break;
@@ -207,28 +211,15 @@ async function cmdDefault() {
207
211
  console.log("Drawlatch remote server is not running.\n");
208
212
  printHelp();
209
213
  }
210
- const latestVersion = await updateCheckPromise;
214
+ // Show update notice only if the check already resolved (don't block on network)
215
+ const latestVersion = await Promise.race([
216
+ updateCheckPromise,
217
+ new Promise((r) => setTimeout(() => r(null), 100)),
218
+ ]);
211
219
  if (latestVersion) console.log(formatUpdateNotice(latestVersion));
212
220
  }
213
221
 
214
222
  async function cmdInit() {
215
- const alias = values.alias || "default";
216
- const connectionsList = values.connections
217
- ? values.connections.split(",").map((c) => c.trim()).filter(Boolean)
218
- : [];
219
-
220
- // Validate requested connections exist
221
- if (connectionsList.length > 0) {
222
- const available = listAvailableConnections();
223
- const availableSet = new Set(available);
224
- const invalid = connectionsList.filter((c) => !availableSet.has(c));
225
- if (invalid.length > 0) {
226
- console.error(`Unknown connection(s): ${invalid.join(", ")}`);
227
- console.error(`Available: ${available.join(", ")}`);
228
- process.exit(1);
229
- }
230
- }
231
-
232
223
  console.log(`\nDrawlatch Setup`);
233
224
  console.log(`===============\n`);
234
225
 
@@ -251,20 +242,7 @@ async function cmdInit() {
251
242
  steps.push(`Server keys: CREATED (${fp})`);
252
243
  }
253
244
 
254
- // Step 3: Generate caller keypair
255
- const callerKeysDir = join(getCallerKeysDir(), alias);
256
- if (existsSync(join(callerKeysDir, "signing.key.pem"))) {
257
- const existing = loadKeyBundle(callerKeysDir);
258
- const fp = fingerprint(extractPublicKeys(existing));
259
- steps.push(`Caller keys (${alias}): already exist (${fp})`);
260
- } else {
261
- const bundle = generateKeyBundle();
262
- saveKeyBundle(bundle, callerKeysDir);
263
- const fp = fingerprint(extractPublicKeys(bundle));
264
- steps.push(`Caller keys (${alias}): CREATED (${fp})`);
265
- }
266
-
267
- // Step 4: Scaffold proxy.config.json
245
+ // Step 3: Scaffold proxy.config.json
268
246
  const proxyConfigPath = getProxyConfigPath();
269
247
  if (existsSync(proxyConfigPath)) {
270
248
  steps.push(`Proxy config: already exists`);
@@ -278,7 +256,7 @@ async function cmdInit() {
278
256
  steps.push(`Proxy config: CREATED`);
279
257
  }
280
258
 
281
- // Step 5: Scaffold remote.config.json
259
+ // Step 4: Scaffold remote.config.json
282
260
  const remoteConfigPath = getRemoteConfigPath();
283
261
  if (existsSync(remoteConfigPath)) {
284
262
  steps.push(`Remote config: already exists`);
@@ -287,44 +265,22 @@ async function cmdInit() {
287
265
  host: "0.0.0.0",
288
266
  port: 9999,
289
267
  rateLimitPerMinute: 60,
290
- callers: {
291
- [alias]: {
292
- name: alias === "default" ? "Default Caller" : alias,
293
- connections: connectionsList,
294
- },
295
- },
268
+ callers: {},
296
269
  };
297
270
  writeFileSync(remoteConfigPath, JSON.stringify(remoteConfig, null, 2) + "\n", { mode: 0o600 });
298
- steps.push(`Remote config: CREATED (caller "${alias}" with ${connectionsList.length} connection(s))`);
271
+ steps.push(`Remote config: CREATED`);
299
272
  }
300
273
 
301
- // Step 7: Scaffold .env file
274
+ // Step 5: Scaffold .env file
302
275
  if (existsSync(ENV_FILE)) {
303
276
  steps.push(`.env file: already exists`);
304
277
  } else {
305
278
  const envLines = [
306
279
  "# Drawlatch environment secrets",
307
- "# Uncomment and set tokens for your enabled connections",
280
+ "# Set tokens for your enabled connections",
281
+ "# Secrets are prefixed per caller (e.g., DEFAULT_GITHUB_TOKEN)",
308
282
  "",
309
283
  ];
310
-
311
- // Get secret info for requested connections (or all if none specified)
312
- const templates = listConnectionTemplates();
313
- const relevantTemplates = connectionsList.length > 0
314
- ? templates.filter((t) => connectionsList.includes(t.alias))
315
- : templates.filter((t) => ["github", "slack", "discord-bot", "openai", "anthropic"].includes(t.alias));
316
-
317
- for (const t of relevantTemplates) {
318
- envLines.push(`# ${t.name}`);
319
- for (const s of t.requiredSecrets) {
320
- envLines.push(`# ${s}=`);
321
- }
322
- for (const s of t.optionalSecrets) {
323
- envLines.push(`# ${s}=`);
324
- }
325
- envLines.push("");
326
- }
327
-
328
284
  writeFileSync(ENV_FILE, envLines.join("\n") + "\n", { mode: 0o600 });
329
285
  steps.push(`.env file: CREATED`);
330
286
  }
@@ -335,25 +291,10 @@ async function cmdInit() {
335
291
  }
336
292
 
337
293
  console.log(`\nSetup complete! Next steps:\n`);
338
-
339
- if (connectionsList.length > 0) {
340
- const templates = listConnectionTemplates();
341
- const enabledTemplates = templates.filter((t) => connectionsList.includes(t.alias));
342
- const allSecrets = enabledTemplates.flatMap((t) => t.requiredSecrets);
343
- if (allSecrets.length > 0) {
344
- console.log(` 1. Set your API secrets in ${ENV_FILE}:`);
345
- for (const s of [...new Set(allSecrets)]) {
346
- console.log(` ${s}=your_token_here`);
347
- }
348
- console.log();
349
- }
350
- } else {
351
- console.log(` 1. Edit ${remoteConfigPath} to add connections (e.g., "github", "slack")`);
352
- console.log(` Then set the required secrets in ${ENV_FILE}\n`);
353
- }
354
-
355
- console.log(` 2. Start the remote server:`);
294
+ console.log(` 1. Start the remote server:`);
356
295
  console.log(` drawlatch start\n`);
296
+ console.log(` 2. Add callers via key sync:`);
297
+ console.log(` drawlatch sync\n`);
357
298
  console.log(` 3. Verify your setup:`);
358
299
  console.log(` drawlatch doctor\n`);
359
300
  }
@@ -869,14 +810,14 @@ async function cmdSync() {
869
810
  console.log(
870
811
  ` Keys saved to: ${join(CONFIG_DIR, "keys", "callers", status.callerAlias)}/`,
871
812
  );
872
- console.log(
873
- `\nAdd connections for this caller in remote.config.json:`,
874
- );
813
+ console.log(`\nThe caller can now connect (no server restart needed).`);
814
+ console.log(`\nTo grant API access, add connections in ${join(CONFIG_DIR, "remote.config.json")}:`);
875
815
  console.log(` "callers": {`);
876
816
  console.log(` "${status.callerAlias}": {`);
877
817
  console.log(` "connections": ["github", "slack", ...]`);
878
818
  console.log(` }`);
879
819
  console.log(` }`);
820
+ console.log(`\nThen set the required secrets in ${ENV_FILE}`);
880
821
  console.log();
881
822
  process.exit(0);
882
823
  }
@@ -944,11 +885,16 @@ function cleanPidFile() {
944
885
 
945
886
  // ── Health check utilities ────────────────────────────────────────
946
887
 
888
+ /** Resolve the host for client connections — 0.0.0.0 is a bind address, not connectable. */
889
+ function connectHost(host) {
890
+ return host === "0.0.0.0" ? "127.0.0.1" : host;
891
+ }
892
+
947
893
  async function healthCheck(host, port) {
948
894
  try {
949
895
  const controller = new AbortController();
950
896
  const timeout = setTimeout(() => controller.abort(), 3000);
951
- const res = await fetch(`http://${host}:${port}/health`, {
897
+ const res = await fetch(`http://${connectHost(host)}:${port}/health`, {
952
898
  signal: controller.signal,
953
899
  });
954
900
  clearTimeout(timeout);
@@ -962,7 +908,7 @@ async function healthCheckFull(host, port) {
962
908
  try {
963
909
  const controller = new AbortController();
964
910
  const timeout = setTimeout(() => controller.abort(), 3000);
965
- const res = await fetch(`http://${host}:${port}/health`, {
911
+ const res = await fetch(`http://${connectHost(host)}:${port}/health`, {
966
912
  signal: controller.signal,
967
913
  });
968
914
  clearTimeout(timeout);
@@ -1167,7 +1113,7 @@ drawlatch v${VERSION}
1167
1113
  Usage: drawlatch [command] [options]
1168
1114
 
1169
1115
  Commands:
1170
- init Set up drawlatch (keys, config, .env) in one step
1116
+ init Set up drawlatch server (keys, config, .env)
1171
1117
  start Start the remote server (background by default)
1172
1118
  stop Stop the background remote server
1173
1119
  restart Restart the background remote server
@@ -1185,9 +1131,7 @@ Options:
1185
1131
  Running 'drawlatch' with no arguments shows status (if running) or this help.
1186
1132
 
1187
1133
  Examples:
1188
- drawlatch init Set up everything with defaults
1189
- drawlatch init --connections github Set up with GitHub connection
1190
- drawlatch init --alias mybot Set up with custom caller alias
1134
+ drawlatch init Set up the remote server
1191
1135
  drawlatch start Start remote server in background
1192
1136
  drawlatch start -f Start remote server in foreground
1193
1137
  drawlatch start -f --tunnel Start with a public tunnel for webhooks
@@ -1304,23 +1248,18 @@ function printInitHelp() {
1304
1248
  console.log(`
1305
1249
  drawlatch init
1306
1250
 
1307
- Set up drawlatch for first-time use. Generates keys, creates config
1308
- files, exchanges public keys, and scaffolds a .env template.
1251
+ Set up the drawlatch remote server. Generates server keys, creates
1252
+ config files, and scaffolds a .env template.
1253
+
1254
+ Callers are added separately via 'drawlatch sync' after the server
1255
+ is running.
1309
1256
 
1310
1257
  Usage: drawlatch init [options]
1311
1258
 
1312
1259
  Options:
1313
- --connections <list> Comma-separated connections to enable (e.g., github,slack)
1314
- --alias <name> Name for the local identity (default: "default")
1315
- -h, --help Show this help message
1260
+ -h, --help Show this help message
1316
1261
 
1317
1262
  All steps are idempotent — safe to re-run without overwriting existing files.
1318
-
1319
- Examples:
1320
- drawlatch init Set up with defaults
1321
- drawlatch init --connections github Set up with GitHub enabled
1322
- drawlatch init --alias laptop Use "laptop" as the caller alias
1323
- drawlatch init --alias ci --connections github,slack
1324
1263
  `);
1325
1264
  }
1326
1265
 
@@ -1416,14 +1416,22 @@ export function main() {
1416
1416
  }
1417
1417
  const config = loadRemoteConfig();
1418
1418
  const serverKeysDirPath = getServerKeysDir();
1419
- if (!fs.existsSync(serverKeysDirPath)) {
1420
- console.error(`[remote] Error: Server keys not found at ${serverKeysDirPath}`);
1419
+ const requiredKeyFiles = ['signing.key.pem', 'signing.pub.pem', 'exchange.key.pem', 'exchange.pub.pem'];
1420
+ const missingKeyFiles = requiredKeyFiles.filter((f) => !fs.existsSync(path.join(serverKeysDirPath, f)));
1421
+ if (missingKeyFiles.length > 0) {
1422
+ if (!fs.existsSync(serverKeysDirPath)) {
1423
+ console.error(`[remote] Error: Server keys not found at ${serverKeysDirPath}`);
1424
+ }
1425
+ else {
1426
+ console.error(`[remote] Error: Incomplete server keys in ${serverKeysDirPath}`);
1427
+ console.error(`[remote] Missing: ${missingKeyFiles.join(', ')}`);
1428
+ }
1421
1429
  console.error('[remote] Run: drawlatch generate-keys server');
1422
1430
  process.exit(1);
1423
1431
  }
1424
1432
  if (Object.keys(config.callers).length === 0) {
1425
- console.error('[remote] Warning: No callers configured. No clients will be able to connect.');
1426
- console.error('[remote] Add callers to remote.config.json or run: drawlatch init');
1433
+ console.log('[remote] No callers configured server will accept sync requests.');
1434
+ console.log('[remote] To add callers, run: drawlatch sync');
1427
1435
  }
1428
1436
  const port = process.env.DRAWLATCH_PORT ? parseInt(process.env.DRAWLATCH_PORT, 10) : config.port;
1429
1437
  const host = process.env.DRAWLATCH_HOST ?? config.host;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wolpertingerlabs/drawlatch",
3
- "version": "1.0.0-alpha.9.1",
3
+ "version": "1.0.0-alpha.9.3",
4
4
  "description": "Encrypted MCP proxy with mutual authentication. Local MCP server forwards requests through an encrypted channel to a remote secrets-holding server.",
5
5
  "type": "module",
6
6
  "main": "./dist/mcp/server.js",