@hamedb89/localghost 0.1.13 → 0.1.15

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/dist/index.d.ts CHANGED
@@ -70,6 +70,9 @@ declare function unregisterLocalghostSetup(options: {
70
70
  declare function renderLocalghostBanner(): string;
71
71
  declare function renderCompactLocalghostBanner(): string;
72
72
 
73
+ declare const LOCALGHOST_AGENT_GUIDE = "# Localghost agent guide\n\nLocalghost owns the local development proxy and the app process boundary.\n\n## Preferred repository setup\n\nFor a normal repository, use this package script:\n\n \"dev\": \"localghost\"\n\nFor an explicit app command, keep the raw command separate:\n\n \"dev\": \"localghost run -- vite\"\n \"dev:raw\": \"vite\"\n\nUse `localghost dev` only when the Caddy proxy should run without starting the app.\n\n## Useful commands\n\n- `localghost`: detect and run the repository development command.\n- `localghost run -- <command>`: wrap an explicit app command.\n- `localghost dev`: run only the local Caddy proxy.\n- `localghost status --ready`: check project setup.\n- `localghost repair`: repair managed hosts and Caddy setup.\n- `localghost ps --json`: inspect Localghost-managed repositories, instances, and ports.\n- `localghost routes`: inspect hostname-to-port routing.\n- `localghost doctor`: check machine prerequisites.\n\n## Configuration\n\n- Commit repository defaults in `localghost.config.mjs`.\n- Keep hostname and requested-port routes in `.localghost`.\n- CLI flags override repository configuration for one invocation.\n- Localghost remembers active project and instance port assignments in user state under `~/.localghost`.\n- Do not edit the registry manually and do not start Caddy separately.\n\n## Port behavior\n\nLocalghost remembers ports by canonical repository path and instance key. Concurrent Localghost instances receive distinct ports. The operating-system bind check remains authoritative when another tool already owns a port.\n";
74
+ declare function formatLocalghostAgentGuide(format?: "text" | "json"): string;
75
+
73
76
  declare const LOCALGHOST_GHOST_TUNNEL_FILE = ".ghosttunnel";
74
77
  type ReadGhostTunnelOptions = ReadDevHostsOptions;
75
78
  declare function resolveGhostTunnelPath(options?: ReadGhostTunnelOptions | string): ResolvedDevHostsPath;
@@ -318,6 +321,15 @@ declare function resolveGhostTunnelIpRedirect(input: ResolveGhostTunnelIpRedirec
318
321
  type CaddyModeOptions = {
319
322
  https?: boolean;
320
323
  };
324
+ type CaddyProcessStopResult = {
325
+ stopped: number[];
326
+ alreadyExited: number[];
327
+ failed: Array<{
328
+ pid: number;
329
+ error: unknown;
330
+ }>;
331
+ };
332
+ type CaddyProcessKiller = (pid: number, signal: NodeJS.Signals) => void;
321
333
  declare function getCaddyfilePath(cwd?: string): string;
322
334
  declare function renderCaddyfile(entries: DevHostEntry[], options?: CaddyModeOptions): string;
323
335
  declare function writeCaddyfile(entries: DevHostEntry[], cwd?: string, options?: CaddyModeOptions): Promise<string>;
@@ -327,6 +339,7 @@ declare function startCaddy(path: string): execa.ResultPromise<{
327
339
  cwd: string;
328
340
  stdio: "inherit" | "pipe";
329
341
  }>;
342
+ declare function stopCaddyProcesses(pids: Iterable<number>, killProcess?: CaddyProcessKiller): CaddyProcessStopResult;
330
343
  declare function trustCaddy(path: string): Promise<void>;
331
344
 
332
345
  type ResolveGhostTunnelRequestInput = {
@@ -402,6 +415,10 @@ type LocalghostContextOptions = {
402
415
  bindHost?: string | boolean;
403
416
  primaryHost?: string;
404
417
  dynamicPort?: boolean;
418
+ reservePort?: boolean;
419
+ instanceKey?: string;
420
+ reservedPorts?: Iterable<number>;
421
+ registryOwnerToken?: string;
405
422
  autoRepair?: boolean;
406
423
  command?: string[];
407
424
  services?: LocalghostServiceOptions[];
@@ -427,6 +444,7 @@ type LocalghostContext = {
427
444
  wwwAlias: boolean;
428
445
  ghostTunnel: GhostTunnelConfig;
429
446
  projectConfigPath?: string;
447
+ releasePort?: () => Promise<boolean>;
430
448
  };
431
449
  type LocalghostProjectConfig = Omit<LocalghostContextOptions, "cwd" | "localghostConfig">;
432
450
  type LocalghostProjectConfigResult = {
@@ -504,6 +522,66 @@ type FindAvailablePortOptions = {
504
522
  declare function isPortAvailable(port: number, host?: string): Promise<boolean>;
505
523
  declare function findAvailablePort(startPort: number, options?: FindAvailablePortOptions): Promise<number>;
506
524
 
525
+ declare const LOCALGHOST_REGISTRY_FILE = "registry.json";
526
+ declare const LOCALGHOST_REGISTRY_LOCK_FILE = "registry.lock";
527
+ type PortAvailabilityCheck = (port: number, host?: string) => boolean | Promise<boolean>;
528
+ type LocalghostRegistryEntry = {
529
+ projectCwd: string;
530
+ instanceKey: string;
531
+ port: number;
532
+ updatedAt: number;
533
+ };
534
+ type LocalghostLease = {
535
+ projectCwd: string;
536
+ instanceKey: string;
537
+ port: number;
538
+ pid: number;
539
+ acquiredAt: number;
540
+ expiresAt: number;
541
+ ownerToken: string;
542
+ };
543
+ type LocalghostRegistryData = {
544
+ version: 1;
545
+ allocations: LocalghostRegistryEntry[];
546
+ leases: LocalghostLease[];
547
+ };
548
+ type LocalghostRegistryOptions = {
549
+ stateRoot?: string;
550
+ cwd?: string;
551
+ pid?: number;
552
+ ownerToken?: string;
553
+ now?: () => number;
554
+ isProcessRunning?: (pid: number) => boolean;
555
+ availabilityCheck?: PortAvailabilityCheck;
556
+ lockTimeoutMs?: number;
557
+ lockRetryMs?: number;
558
+ lockStaleMs?: number;
559
+ };
560
+ type AcquireLocalghostPortOptions = {
561
+ projectCwd?: string;
562
+ instanceKey: string;
563
+ startPort?: number;
564
+ maxAttempts?: number;
565
+ reservedPorts?: Iterable<number>;
566
+ leaseTtlMs?: number;
567
+ host?: string;
568
+ };
569
+ type LocalghostRegistry = {
570
+ root: string;
571
+ registryPath: string;
572
+ lockPath: string;
573
+ ownerToken: string;
574
+ acquirePort(options: AcquireLocalghostPortOptions): Promise<LocalghostLease>;
575
+ releasePort(options: {
576
+ projectCwd?: string;
577
+ instanceKey: string;
578
+ }): Promise<boolean>;
579
+ read(): Promise<LocalghostRegistryData>;
580
+ };
581
+ declare function getLocalghostRegistryRoot(env?: NodeJS.ProcessEnv): string;
582
+ declare function canonicalizeLocalghostProjectCwd(cwd?: string): string;
583
+ declare function createLocalghostRegistry(options?: LocalghostRegistryOptions): LocalghostRegistry;
584
+
507
585
  type DomainRoute = {
508
586
  host: string;
509
587
  port: number;
@@ -571,7 +649,7 @@ type CreateVercelGhostTunnelHandlerOptions = {
571
649
  declare function createVercelGhostTunnelHandler(options: CreateVercelGhostTunnelHandlerOptions): (request: VercelGhostTunnelRequestLike, response: VercelGhostTunnelResponseLike) => Promise<void>;
572
650
 
573
651
  declare const LOCALGHOST_PACKAGE_NAME = "@hamedb89/localghost";
574
- declare const LOCALGHOST_VERSION = "0.1.13";
652
+ declare const LOCALGHOST_VERSION = "0.1.15";
575
653
  declare const UPDATE_CHECK_CACHE_TTL_MS: number;
576
654
  declare const UPDATE_CHECK_NOTIFY_TTL_MS: number;
577
655
  declare const UPDATE_CHECK_TIMEOUT_MS = 900;
@@ -608,4 +686,4 @@ declare function maybeNotifyAboutUpdate(options?: {
608
686
  disabled?: boolean;
609
687
  }): Promise<void>;
610
688
 
611
- export { type ActiveRelayRoute, type CaddyModeOptions, ConfigPattern, type ConstructGhostTunnelIpUrlInput, ConstructGhostTunnelUrlInput, type CreateVercelGhostTunnelHandlerOptions, DEFAULT_GHOST_TUNNEL_IP_TRANSPORT_TTL_SECONDS, DEFAULT_GHOST_TUNNEL_RESPONSE_TTL_SECONDS, DEFAULT_GHOST_TUNNEL_TRANSPORT_QUERY_PARAM, DEFAULT_RELAY_ALLOWED_TARGET_HOSTS, DEFAULT_RELAY_BLOCKED_PORTS, DEFAULT_RELAY_LIMITS, DEFAULT_RELAY_TARGET_POLICY, type DetectedDevCommand, type DetectedDevService, DevHostEntry, type DoctorResult, type DomainRoute, type DomainRouteOptions, type FindAvailablePortOptions, type GhostTunnelAgent, type GhostTunnelAgentOptions, GhostTunnelConfig, type GhostTunnelHttpResponse, type GhostTunnelIpTransportClaim, GhostTunnelOptions, type GhostTunnelQueuedRequest, type GhostTunnelQueuedResponse, GhostTunnelRoute, type GhostTunnelRouteHeartbeat, type GhostTunnelStore, type GhostTunnelStoreEnv, GhostTunnelTransportConfig, GhostTunnelTransportOptions, type InitOptions, type InitResult, LOCALGHOST_ACTIVITY_VERSION, LOCALGHOST_GHOST_TUNNEL_FILE, LOCALGHOST_PACKAGE_NAME, LOCALGHOST_STATE_FILE, LOCALGHOST_VERSION, type LocalghostActivity, type LocalghostContext, type LocalghostContextOptions, type LocalghostEnvironment, type LocalghostPackageManager, type LocalghostProjectConfig, type LocalghostProjectConfigResult, type LocalghostRunMode, type LocalghostRunRecord, type LocalghostServiceOptions, type LocalghostSetupRecord, type LocalghostState, type LocalghostStateAction, type PackageManager, ReadDevHostsOptions, type ReadGhostTunnelOptions, type RedisGhostTunnelEnvResolution, type RedisGhostTunnelStoreOptions, type RegisterLocalghostRunInput, type RegisterLocalghostSetupInput, type RelayAccessMode, type RelayLimits, type RelayLocalTarget, type RelayOfflineResponse, type RelayProtocol, type RelayRouteClaim, type RelayRouteRegistrationInput, type RelayTargetPolicy, type RemoveSystemHostsResult, type ResolveGhostTunnelIpRedirectInput, type ResolveGhostTunnelRequestInput, ResolvedDevHostsPath, type ResolvedGhostTunnelIpRedirect, type ResolvedGhostTunnelRequest, type ServeGhostTunnelLocalRequestInput, type SignedGhostTunnelIpTransportClaim, type SignedRelayRouteClaim, UPDATE_CHECK_CACHE_TTL_MS, UPDATE_CHECK_NOTIFY_TTL_MS, UPDATE_CHECK_TIMEOUT_MS, type UpdateCheckCache, type UpdateCheckResult, type UpdateSystemHostsResult, type VercelGhostTunnelRequestLike, type VercelGhostTunnelResponseLike, type WriteLocalghostStateInput, assertExactRelayHost, assertLocalDevelopment, assertRelayLocalTarget, authenticateRelayAgentToken, checkCaddy, checkForUpdate, compareVersions, constructGhostTunnelIpUrl, createGhostTunnelQueuedRequest, createGhostTunnelRouteHeartbeat, createMemoryGhostTunnelStore, createRedisGhostTunnelStore, createRedisGhostTunnelStoreFromEnv, createRelayRouteRegistration, createVercelGhostTunnelHandler, decodeGhostTunnelBody, defineLocalghostConfig, detectDevCommand, detectDevPackageManager, detectDevServices, detectPackageManager, encodeGhostTunnelBody, findAvailablePort, findGhostTunnelEntry, formatDetectedDevCommand, formatDetectedDevServices, formatDomainRoutes, formatGhostTunnel, formatUpdateMessage, getCaddyfilePath, getDomainRoutes, getGhostTunnelPath, getLocalghostActivityPath, getLocalghostStatePath, getProductionEnvKeys, getProductionReason, getSystemHostsPath, getUpdateCheckCachePath, initLocalghost, isNewerVersion, isPortAvailable, isProcessRunning, isProductionLike, isRelayRouteActive, isUpdateCheckDisabled, listGhostTunnelEntries, listLocalghostRuns, listLocalghostSetups, markUpdateNotified, maybeNotifyAboutUpdate, packageAddCommand, packageRunCommand, patchLocalghostState, pruneLocalghostActivity, readGhostTunnelEntries, readLocalghostActivity, readLocalghostProjectConfig, readLocalghostState, redactRelayHeaders, redactRelayLogUrl, registerLocalghostRun, registerLocalghostSetup, removeManagedBlock, removeSystemHosts, renderCaddyfile, renderCompactLocalghostBanner, renderGhostTunnelRelayOfflineResponse, renderGhostTunnelRouteMissingResponse, renderHostsBlock, renderLocalghostBanner, renderRelayOfflineResponse, resolveGhostTunnelIpRedirect, resolveGhostTunnelPath, resolveGhostTunnelRequest, resolveLocalghostContext, resolveRedisGhostTunnelEnv, runCaddy, runDoctor, serveGhostTunnelLocalRequest, shouldNotifyAboutUpdate, signGhostTunnelIpTransportClaim, signRelayRouteClaim, startCaddy, startGhostTunnelAgent, stripRelayForwardHeaders, trustCaddy, unregisterLocalghostRun, unregisterLocalghostSetup, updateSystemHosts, upsertManagedBlock, validateCaddyfile, verifyGhostTunnelIpTransportClaim, verifyRelayRouteClaim, writeCaddyfile, writeLocalghostActivity, writeLocalghostState };
689
+ export { type AcquireLocalghostPortOptions, type ActiveRelayRoute, type CaddyModeOptions, type CaddyProcessKiller, type CaddyProcessStopResult, ConfigPattern, type ConstructGhostTunnelIpUrlInput, ConstructGhostTunnelUrlInput, type CreateVercelGhostTunnelHandlerOptions, DEFAULT_GHOST_TUNNEL_IP_TRANSPORT_TTL_SECONDS, DEFAULT_GHOST_TUNNEL_RESPONSE_TTL_SECONDS, DEFAULT_GHOST_TUNNEL_TRANSPORT_QUERY_PARAM, DEFAULT_RELAY_ALLOWED_TARGET_HOSTS, DEFAULT_RELAY_BLOCKED_PORTS, DEFAULT_RELAY_LIMITS, DEFAULT_RELAY_TARGET_POLICY, type DetectedDevCommand, type DetectedDevService, DevHostEntry, type DoctorResult, type DomainRoute, type DomainRouteOptions, type FindAvailablePortOptions, type GhostTunnelAgent, type GhostTunnelAgentOptions, GhostTunnelConfig, type GhostTunnelHttpResponse, type GhostTunnelIpTransportClaim, GhostTunnelOptions, type GhostTunnelQueuedRequest, type GhostTunnelQueuedResponse, GhostTunnelRoute, type GhostTunnelRouteHeartbeat, type GhostTunnelStore, type GhostTunnelStoreEnv, GhostTunnelTransportConfig, GhostTunnelTransportOptions, type InitOptions, type InitResult, LOCALGHOST_ACTIVITY_VERSION, LOCALGHOST_AGENT_GUIDE, LOCALGHOST_GHOST_TUNNEL_FILE, LOCALGHOST_PACKAGE_NAME, LOCALGHOST_REGISTRY_FILE, LOCALGHOST_REGISTRY_LOCK_FILE, LOCALGHOST_STATE_FILE, LOCALGHOST_VERSION, type LocalghostActivity, type LocalghostContext, type LocalghostContextOptions, type LocalghostEnvironment, type LocalghostLease, type LocalghostPackageManager, type LocalghostProjectConfig, type LocalghostProjectConfigResult, type LocalghostRegistry, type LocalghostRegistryData, type LocalghostRegistryEntry, type LocalghostRegistryOptions, type LocalghostRunMode, type LocalghostRunRecord, type LocalghostServiceOptions, type LocalghostSetupRecord, type LocalghostState, type LocalghostStateAction, type PackageManager, type PortAvailabilityCheck, ReadDevHostsOptions, type ReadGhostTunnelOptions, type RedisGhostTunnelEnvResolution, type RedisGhostTunnelStoreOptions, type RegisterLocalghostRunInput, type RegisterLocalghostSetupInput, type RelayAccessMode, type RelayLimits, type RelayLocalTarget, type RelayOfflineResponse, type RelayProtocol, type RelayRouteClaim, type RelayRouteRegistrationInput, type RelayTargetPolicy, type RemoveSystemHostsResult, type ResolveGhostTunnelIpRedirectInput, type ResolveGhostTunnelRequestInput, ResolvedDevHostsPath, type ResolvedGhostTunnelIpRedirect, type ResolvedGhostTunnelRequest, type ServeGhostTunnelLocalRequestInput, type SignedGhostTunnelIpTransportClaim, type SignedRelayRouteClaim, UPDATE_CHECK_CACHE_TTL_MS, UPDATE_CHECK_NOTIFY_TTL_MS, UPDATE_CHECK_TIMEOUT_MS, type UpdateCheckCache, type UpdateCheckResult, type UpdateSystemHostsResult, type VercelGhostTunnelRequestLike, type VercelGhostTunnelResponseLike, type WriteLocalghostStateInput, assertExactRelayHost, assertLocalDevelopment, assertRelayLocalTarget, authenticateRelayAgentToken, canonicalizeLocalghostProjectCwd, checkCaddy, checkForUpdate, compareVersions, constructGhostTunnelIpUrl, createGhostTunnelQueuedRequest, createGhostTunnelRouteHeartbeat, createLocalghostRegistry, createMemoryGhostTunnelStore, createRedisGhostTunnelStore, createRedisGhostTunnelStoreFromEnv, createRelayRouteRegistration, createVercelGhostTunnelHandler, decodeGhostTunnelBody, defineLocalghostConfig, detectDevCommand, detectDevPackageManager, detectDevServices, detectPackageManager, encodeGhostTunnelBody, findAvailablePort, findGhostTunnelEntry, formatDetectedDevCommand, formatDetectedDevServices, formatDomainRoutes, formatGhostTunnel, formatLocalghostAgentGuide, formatUpdateMessage, getCaddyfilePath, getDomainRoutes, getGhostTunnelPath, getLocalghostActivityPath, getLocalghostRegistryRoot, getLocalghostStatePath, getProductionEnvKeys, getProductionReason, getSystemHostsPath, getUpdateCheckCachePath, initLocalghost, isNewerVersion, isPortAvailable, isProcessRunning, isProductionLike, isRelayRouteActive, isUpdateCheckDisabled, listGhostTunnelEntries, listLocalghostRuns, listLocalghostSetups, markUpdateNotified, maybeNotifyAboutUpdate, packageAddCommand, packageRunCommand, patchLocalghostState, pruneLocalghostActivity, readGhostTunnelEntries, readLocalghostActivity, readLocalghostProjectConfig, readLocalghostState, redactRelayHeaders, redactRelayLogUrl, registerLocalghostRun, registerLocalghostSetup, removeManagedBlock, removeSystemHosts, renderCaddyfile, renderCompactLocalghostBanner, renderGhostTunnelRelayOfflineResponse, renderGhostTunnelRouteMissingResponse, renderHostsBlock, renderLocalghostBanner, renderRelayOfflineResponse, resolveGhostTunnelIpRedirect, resolveGhostTunnelPath, resolveGhostTunnelRequest, resolveLocalghostContext, resolveRedisGhostTunnelEnv, runCaddy, runDoctor, serveGhostTunnelLocalRequest, shouldNotifyAboutUpdate, signGhostTunnelIpTransportClaim, signRelayRouteClaim, startCaddy, startGhostTunnelAgent, stopCaddyProcesses, stripRelayForwardHeaders, trustCaddy, unregisterLocalghostRun, unregisterLocalghostSetup, updateSystemHosts, upsertManagedBlock, validateCaddyfile, verifyGhostTunnelIpTransportClaim, verifyRelayRouteClaim, writeCaddyfile, writeLocalghostActivity, writeLocalghostState };