@prohost/cli 0.15.0 → 0.16.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.
Files changed (59) hide show
  1. package/CHANGELOG.md +86 -0
  2. package/README.md +266 -1
  3. package/dist/agent/accounts.d.ts +11 -0
  4. package/dist/agent/accounts.js +12 -1
  5. package/dist/agent/api.d.ts +12 -0
  6. package/dist/agent/api.js +5 -0
  7. package/dist/agent/claude.d.ts +6 -0
  8. package/dist/agent/claude.js +2 -2
  9. package/dist/agent/daemon.d.ts +33 -0
  10. package/dist/agent/daemon.js +56 -0
  11. package/dist/agent/prompt.d.ts +12 -0
  12. package/dist/agent/prompt.js +5 -0
  13. package/dist/agent/run.d.ts +116 -1
  14. package/dist/agent/run.js +217 -29
  15. package/dist/codehost/host.d.ts +25 -0
  16. package/dist/codehost/host.js +16 -1
  17. package/dist/codehost/host_stats.d.ts +49 -2
  18. package/dist/codehost/host_stats.js +153 -2
  19. package/dist/codehost/relay.d.ts +10 -0
  20. package/dist/codehost/relay.js +17 -1
  21. package/dist/host/api.d.ts +82 -0
  22. package/dist/host/api.js +122 -0
  23. package/dist/host/capacity.d.ts +41 -0
  24. package/dist/host/capacity.js +48 -0
  25. package/dist/host/command.d.ts +59 -0
  26. package/dist/host/command.js +597 -0
  27. package/dist/host/computer.d.ts +120 -0
  28. package/dist/host/computer.js +291 -0
  29. package/dist/host/events.d.ts +24 -0
  30. package/dist/host/events.js +47 -0
  31. package/dist/host/install.d.ts +154 -0
  32. package/dist/host/install.js +784 -0
  33. package/dist/host/ledger.d.ts +52 -0
  34. package/dist/host/ledger.js +131 -0
  35. package/dist/host/legacy.d.ts +38 -0
  36. package/dist/host/legacy.js +115 -0
  37. package/dist/host/logins.d.ts +109 -0
  38. package/dist/host/logins.js +190 -0
  39. package/dist/host/migrate.d.ts +165 -0
  40. package/dist/host/migrate.js +364 -0
  41. package/dist/host/pair.d.ts +62 -0
  42. package/dist/host/pair.js +219 -0
  43. package/dist/host/peak_memory.d.ts +44 -0
  44. package/dist/host/peak_memory.js +139 -0
  45. package/dist/host/scheduler.d.ts +86 -0
  46. package/dist/host/scheduler.js +186 -0
  47. package/dist/host/service.d.ts +114 -0
  48. package/dist/host/service.js +1027 -0
  49. package/dist/host/session_move.d.ts +48 -0
  50. package/dist/host/session_move.js +106 -0
  51. package/dist/host/skills.d.ts +29 -0
  52. package/dist/host/skills.js +135 -0
  53. package/dist/host/status.d.ts +91 -0
  54. package/dist/host/status.js +130 -0
  55. package/dist/index.d.ts +4 -0
  56. package/dist/index.js +47 -3
  57. package/dist/version.d.ts +2 -2
  58. package/dist/version.js +1 -1
  59. package/package.json +1 -1
@@ -0,0 +1,114 @@
1
+ /**
2
+ * `prohost host run` — one service for every AI employee placed on this computer.
3
+ *
4
+ * It holds one event stream, authenticated as the computer. For each
5
+ * `agent.run_requested` frame it:
6
+ *
7
+ * 1. verifies the signature and queues the run (see `scheduler.ts` for the order);
8
+ * 2. when a slot is free and the run's AI login has room, **claims** it
9
+ * (`POST /v1/computers/{id}/runs/{run_id}/claim`) — exactly one computer
10
+ * gets it; a 409 means another did, and it is skipped;
11
+ * 3. writes the employee's skills into its workspace and runs it the way
12
+ * `agent run` would (`executeHostedRun`), as the employee, with the run's
13
+ * own token for the heartbeat, tool events, reply and completion.
14
+ *
15
+ * Every 30 s (and on any change) it reports the machine — memory, CPU,
16
+ * pressure, battery, slots, AI logins, what's running — and the answer is the
17
+ * computer's config: capacity, holds, sharing between logins, placements.
18
+ *
19
+ * Terminal sessions (Code threads) are hosted by the same service with the
20
+ * computer credential, when hosting is on for the code-host home.
21
+ *
22
+ * Stopping drains: no new run starts, runs going finish, then it returns. A
23
+ * newer CLI on disk (an update) drains the same way and exits for the service
24
+ * manager to restart it.
25
+ */
26
+ import type { spawn } from 'node:child_process';
27
+ import WebSocket from 'ws';
28
+ import type { CommandRunner } from '../agent/accounts.js';
29
+ import { executeHostedRun } from '../agent/run.js';
30
+ import type { AgentRunOptions } from '../agent/run.js';
31
+ import type { CodeHostLike } from '../codehost/host.js';
32
+ import type { HostStats } from '../codehost/host_stats.js';
33
+ import type { Workload } from './capacity.js';
34
+ import type { ComputerCredentials } from './computer.js';
35
+ import type { LoginInfo } from './logins.js';
36
+ import { PeakMemory } from './peak_memory.js';
37
+ import type { ComputerConfig } from './status.js';
38
+ /** Set by a dedicated install (`host install --dedicated`): reported as `dedicated` in the status. */
39
+ export declare const DEDICATED_ENV = "PROHOST_HOST_DEDICATED";
40
+ /** What a terminal start is answered with while the computer is paused. */
41
+ export declare const PAUSED_START_REASON = "This computer is paused: it opens no new terminal sessions until it is resumed.";
42
+ /** Declared in every status body: this is a `prohost host` service. */
43
+ export declare const COMPUTER_HOST_CAPABILITY = "computer_host_v1";
44
+ export declare const STATUS_INTERVAL_MS = 30000;
45
+ /** Status on change goes out at most this often. */
46
+ export declare const STATUS_MIN_SPACING_MS = 3000;
47
+ export declare const LOGIN_REFRESH_MS: number;
48
+ export declare const CONTROL_POLL_MS = 2000;
49
+ export declare const UPDATE_CHECK_MS = 60000;
50
+ /** A claim with no answer is tried again this many times before the run is left to the server. */
51
+ export declare const MAX_CLAIM_ATTEMPTS = 5;
52
+ /** How many times one run may move to another login after a usage limit. */
53
+ export declare const MAX_LOGIN_MOVES = 3;
54
+ /** Exit code that asks a service manager to restart (a newer CLI is installed). */
55
+ export declare const RESTART_EXIT_CODE = 75;
56
+ export interface HostServiceOptions {
57
+ computer: ComputerCredentials;
58
+ env?: NodeJS.ProcessEnv;
59
+ machine?: string;
60
+ log?: (line: string) => void;
61
+ /** Aborting it drains the service. */
62
+ signal?: AbortSignal;
63
+ /** Aborting it stops runs going too (a second Ctrl-C). */
64
+ hardStop?: AbortSignal;
65
+ /** Per-run wall clock (0 = none) and silence watchdog, as `agent run`. */
66
+ timeoutMs?: number;
67
+ idleTimeoutMs?: number;
68
+ allowUnverified?: boolean;
69
+ workload?: Workload;
70
+ /**
71
+ * An adopted employee's old working directory (`host migrate`): its
72
+ * sessions are filed under it, so its runs keep working there.
73
+ */
74
+ workdirFor?: (agentId: string) => string | undefined;
75
+ /** Called with each config the server sends (placements decide which adopted homes still run on their own). */
76
+ onConfig?: (config: ComputerConfig) => void;
77
+ webSocketCtor?: typeof WebSocket;
78
+ fetchImpl?: typeof fetch;
79
+ spawnImpl?: typeof spawn;
80
+ probeImpl?: AgentRunOptions['probeImpl'];
81
+ accountCommandRunner?: CommandRunner;
82
+ capabilityProbe?: AgentRunOptions['capabilityProbe'];
83
+ sleepImpl?: (ms: number) => Promise<void>;
84
+ stats?: {
85
+ sample(): Promise<HostStats>;
86
+ latest(): HostStats | undefined;
87
+ };
88
+ hardware?: {
89
+ memoryGb: number;
90
+ cores: number;
91
+ };
92
+ peak?: PeakMemory;
93
+ detectLogins?: () => Promise<LoginInfo[]>;
94
+ codeHost?: CodeHostLike | null;
95
+ executeRun?: typeof executeHostedRun;
96
+ updateAvailable?: () => boolean;
97
+ statusIntervalMs?: number;
98
+ updateCheckMs?: number;
99
+ heartbeatIntervalMs?: number;
100
+ livenessTimeoutMs?: number;
101
+ maxConnections?: number;
102
+ now?: () => number;
103
+ }
104
+ export interface HostServiceResult {
105
+ /** A newer CLI is on disk: exit with {@link RESTART_EXIT_CODE} so the service manager restarts it. */
106
+ restart: boolean;
107
+ /** Stopped for a reason retrying can't fix (the computer was removed, the key revoked). */
108
+ fatal?: string;
109
+ runsStarted: number;
110
+ runsSkipped: number;
111
+ }
112
+ /** The CLI's own entry file: when it changes on disk, an update was installed. */
113
+ export declare function entrypointStamp(entry?: string): () => boolean;
114
+ export declare function runHostService(options: HostServiceOptions): Promise<HostServiceResult>;