@peakflo/agent-harness 0.2.23 → 0.2.24-rc.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.
- package/README.md +38 -15
- package/dist/connect/connect.d.ts +22 -6
- package/dist/connect/connect.js +280 -39
- package/dist/service.js +1 -1
- package/dist/types.d.ts +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -56,26 +56,49 @@ Optional flags include `--health-port <port>`, `--runtime <desktop|self-hosted>`
|
|
|
56
56
|
|
|
57
57
|
## Connect your own agent in one command
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
Choose **Connect this computer** in Spaces. Copy its command:
|
|
60
|
+
|
|
61
|
+
```sh
|
|
62
|
+
npx --yes @peakflo/agent-harness@<version> connect --connection <id>
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Approve the computer in the browser, using the account and company that made
|
|
66
|
+
the command. The runner checks Claude Code, Codex, Cursor, Pi, and OpenCode.
|
|
67
|
+
All usable supported harnesses connect automatically. There is no harness
|
|
68
|
+
selection during setup. Choose which harness an agent uses in the agent editor.
|
|
69
|
+
Agents allow actions by default. Change permissions in the editor, or add
|
|
70
|
+
`--ask` to the command to start in Ask mode. `--all` remains a compatibility
|
|
71
|
+
alias; it is no longer needed.
|
|
72
|
+
|
|
73
|
+
The terminal lists connected agents and skipped backends, with install or
|
|
74
|
+
sign-in help. Pi and OpenCode have no reliable subscription sign-in check;
|
|
75
|
+
their result means available, not proof of a vendor subscription.
|
|
76
|
+
|
|
77
|
+
The computer has one runner and service per API, company, and local account.
|
|
78
|
+
A saved random computer ID lets a new approved connection reuse that runner.
|
|
79
|
+
Repeating the same command uses its saved connection record and creates no
|
|
80
|
+
new token or runner. The command contains a connection ID, not a secret.
|
|
81
|
+
Enrolment uses browser approval and PKCE. The single-use enrolment token is
|
|
82
|
+
never saved. The runner credential is saved with file mode 0600.
|
|
83
|
+
|
|
84
|
+
While idle, the runner checks again every five minutes. Newly installed or
|
|
85
|
+
signed-in harnesses connect automatically on the same runner. Machines →
|
|
86
|
+
Detected backends shows status and install/sign-in help. No extra action,
|
|
87
|
+
connection token, or runner is needed. Existing agent settings stay unchanged.
|
|
88
|
+
|
|
89
|
+
The computer flow needs harness 0.2.23 or later on macOS or Linux. An older
|
|
90
|
+
pin keeps the vendor-specific fallback. The legacy per-vendor path also
|
|
91
|
+
keeps that path available:
|
|
62
92
|
|
|
63
93
|
```sh
|
|
64
94
|
npx --yes @peakflo/agent-harness@<version> connect claude-code --connection <id>
|
|
65
95
|
```
|
|
66
96
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
fetched only after the approval, with a PKCE verifier that never leaves the
|
|
73
|
-
process. If port 7777 or 7780 is in use, `connect` picks free ports.
|
|
74
|
-
|
|
75
|
-
Each vendor gets its own service and workspace under
|
|
76
|
-
`~/.pf-agent-harness/connect/<vendor>`. Check or remove one with
|
|
77
|
-
`service status --vendor <vendor>` or `service uninstall --vendor <vendor>`.
|
|
78
|
-
`connect` needs macOS or Linux.
|
|
97
|
+
The legacy vendor path has one service and workspace per vendor under
|
|
98
|
+
`~/.pf-agent-harness/connect/<vendor>`. The computer path uses a separate
|
|
99
|
+
account-scoped service. Existing vendor runners are not silently combined.
|
|
100
|
+
Use **Reconnect** on an old machine to move its agents to the new computer
|
|
101
|
+
connection while keeping their IDs, names, and history.
|
|
79
102
|
|
|
80
103
|
## Run after you close the terminal
|
|
81
104
|
|
|
@@ -28,14 +28,17 @@ export declare const VENDOR_SETUP: Record<VendorBackend, {
|
|
|
28
28
|
install: string;
|
|
29
29
|
login: string;
|
|
30
30
|
}>;
|
|
31
|
+
export type ConnectTarget = VendorBackend | 'computer';
|
|
31
32
|
export interface ConnectArgs {
|
|
32
|
-
vendor:
|
|
33
|
+
vendor: ConnectTarget;
|
|
34
|
+
all?: boolean;
|
|
35
|
+
askFirst?: boolean;
|
|
33
36
|
connection: string;
|
|
34
37
|
controlPlane: string;
|
|
35
38
|
appUrl?: string;
|
|
36
39
|
openBrowser: boolean;
|
|
37
40
|
}
|
|
38
|
-
export declare const CONNECT_USAGE = "Usage: pf-agent-harness connect
|
|
41
|
+
export declare const CONNECT_USAGE = "Usage: pf-agent-harness connect [codex|claude-code|cursor] [--all] [--ask] --connection <id> [--control-plane <url>]\n\nCopy this command from Agents \u2192 \"Connect this computer\" in Spaces (or\n\"Reconnect\" on your machine there). It approves this computer\nin your browser, connects all usable personal agents, and keeps the runner\nrunning in the background.";
|
|
39
42
|
export declare function parseConnectArgs(argv: string[], env?: NodeJS.ProcessEnv): ConnectArgs;
|
|
40
43
|
/** The machine name the approval page shows. Must match the API's rule. */
|
|
41
44
|
export declare function machineName(raw: string): string;
|
|
@@ -50,6 +53,14 @@ export interface ServicePorts {
|
|
|
50
53
|
healthPort: number;
|
|
51
54
|
proxyPort: number;
|
|
52
55
|
}
|
|
56
|
+
interface ComputerHarnessStatus {
|
|
57
|
+
name: string;
|
|
58
|
+
installed: boolean;
|
|
59
|
+
usable: boolean;
|
|
60
|
+
runnable: boolean;
|
|
61
|
+
transient?: boolean;
|
|
62
|
+
reason?: string;
|
|
63
|
+
}
|
|
53
64
|
export interface ConnectDeps {
|
|
54
65
|
fetchImpl: typeof fetch;
|
|
55
66
|
log: (message: string) => void;
|
|
@@ -67,30 +78,35 @@ export interface ConnectDeps {
|
|
|
67
78
|
register: (input: {
|
|
68
79
|
controlPlane: string;
|
|
69
80
|
enrolmentToken: string;
|
|
70
|
-
vendor:
|
|
81
|
+
vendor: ConnectTarget;
|
|
82
|
+
computerId?: string;
|
|
71
83
|
workspaceRoot: string;
|
|
72
84
|
}) => Promise<{
|
|
73
85
|
runnerId: string;
|
|
86
|
+
connectedBackends?: string[];
|
|
87
|
+
report?: ComputerHarnessStatus[];
|
|
74
88
|
}>;
|
|
75
89
|
/** Start args of an installed service, or null. `undefined` = default one. */
|
|
76
|
-
installedStartArgs: (instance?:
|
|
90
|
+
installedStartArgs: (instance?: string) => string[] | null;
|
|
91
|
+
installedInstances?: () => string[];
|
|
77
92
|
portOccupied: (port: number) => Promise<boolean>;
|
|
78
93
|
/** A copy of the harness outside the npx cache, so the service survives. */
|
|
79
94
|
stableInstall: () => {
|
|
80
95
|
nodePath: string;
|
|
81
96
|
cliPath: string;
|
|
82
97
|
};
|
|
83
|
-
installService: (instance:
|
|
98
|
+
installService: (instance: string, startArgs: string[], paths: {
|
|
84
99
|
nodePath: string;
|
|
85
100
|
cliPath: string;
|
|
86
101
|
}) => Promise<void>;
|
|
87
102
|
waitForHealth: (port: number) => Promise<boolean>;
|
|
88
103
|
}
|
|
89
104
|
/** Reuse this vendor's previous ports; otherwise pick free ones. */
|
|
90
|
-
export declare function choosePorts(vendor:
|
|
105
|
+
export declare function choosePorts(vendor: string, deps: Pick<ConnectDeps, 'installedStartArgs' | 'portOccupied' | 'installedInstances'>): Promise<ServicePorts>;
|
|
91
106
|
export declare function runConnect(args: ConnectArgs, deps: ConnectDeps): Promise<void>;
|
|
92
107
|
export declare function defaultConnectDeps(context: {
|
|
93
108
|
nodePath: string;
|
|
94
109
|
cliPath: string;
|
|
95
110
|
env: NodeJS.ProcessEnv;
|
|
96
111
|
}): ConnectDeps;
|
|
112
|
+
export {};
|
package/dist/connect/connect.js
CHANGED
|
@@ -42,11 +42,11 @@ const vendor_backends_1 = require("../vendor-backends");
|
|
|
42
42
|
const version_1 = require("../version");
|
|
43
43
|
exports.DEFAULT_CONTROL_PLANE = 'https://api.peakflo.ai';
|
|
44
44
|
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
45
|
-
const HEALTH_PORTS = [7777, 7778, 7779, ...range(7790, 7799)];
|
|
46
|
-
const PROXY_PORTS = range(7780, 7789);
|
|
47
45
|
function range(from, to) {
|
|
48
46
|
return Array.from({ length: to - from + 1 }, (_, index) => from + index);
|
|
49
47
|
}
|
|
48
|
+
const HEALTH_PORTS = [7777, 7778, 7779, ...range(7790, 7799)];
|
|
49
|
+
const PROXY_PORTS = range(7780, 7789);
|
|
50
50
|
/** Network text shown in a terminal: no control characters, bounded. */
|
|
51
51
|
function printable(text) {
|
|
52
52
|
// eslint-disable-next-line no-control-regex
|
|
@@ -73,11 +73,12 @@ exports.VENDOR_SETUP = {
|
|
|
73
73
|
login: 'cursor-agent login'
|
|
74
74
|
}
|
|
75
75
|
};
|
|
76
|
-
|
|
76
|
+
const COMPUTER_BACKENDS = ['claude-code', 'codex', 'cursor', 'pi', 'opencode'];
|
|
77
|
+
exports.CONNECT_USAGE = `Usage: pf-agent-harness connect [codex|claude-code|cursor] [--all] [--ask] --connection <id> [--control-plane <url>]
|
|
77
78
|
|
|
78
|
-
Copy this command from Agents → "Connect
|
|
79
|
+
Copy this command from Agents → "Connect this computer" in Spaces (or
|
|
79
80
|
"Reconnect" on your machine there). It approves this computer
|
|
80
|
-
in your browser, connects
|
|
81
|
+
in your browser, connects all usable personal agents, and keeps the runner
|
|
81
82
|
running in the background.`;
|
|
82
83
|
function flag(argv, name) {
|
|
83
84
|
const inline = argv.find((arg) => arg.startsWith(`--${name}=`));
|
|
@@ -111,25 +112,37 @@ function parseConnectArgs(argv, env = {}) {
|
|
|
111
112
|
'--connection',
|
|
112
113
|
'--control-plane',
|
|
113
114
|
'--app-url',
|
|
114
|
-
'--no-browser'
|
|
115
|
+
'--no-browser',
|
|
116
|
+
'--all',
|
|
117
|
+
'--ask'
|
|
115
118
|
]);
|
|
116
|
-
for (let index = 1; index < argv.length; index += 1) {
|
|
119
|
+
for (let index = argv[0]?.startsWith('--') ? 0 : 1; index < argv.length; index += 1) {
|
|
117
120
|
const name = argv[index].split('=')[0];
|
|
121
|
+
if (['--no-browser', '--all', '--ask'].includes(name) &&
|
|
122
|
+
argv[index].includes('='))
|
|
123
|
+
throw new ConnectError(`Use ${name} without a value.`);
|
|
118
124
|
if (!known.has(name))
|
|
119
125
|
throw new ConnectError(`Unknown option: ${name}\n\n${exports.CONNECT_USAGE}`);
|
|
120
|
-
if (
|
|
126
|
+
if (!['--no-browser', '--all', '--ask'].includes(name) &&
|
|
127
|
+
!argv[index].includes('='))
|
|
121
128
|
index += 1;
|
|
122
129
|
}
|
|
123
|
-
const vendor = argv[0];
|
|
124
|
-
if (
|
|
125
|
-
throw new ConnectError(`
|
|
130
|
+
const vendor = !argv[0] || argv[0].startsWith('--') ? 'computer' : argv[0];
|
|
131
|
+
if (vendor !== 'computer' && !(0, vendor_backends_1.isVendorBackend)(vendor))
|
|
132
|
+
throw new ConnectError(`Omit the vendor to connect this computer, or choose codex, claude-code, or cursor.\n\n${exports.CONNECT_USAGE}`);
|
|
133
|
+
if (vendor !== 'computer' &&
|
|
134
|
+
(argv.includes('--all') || argv.includes('--ask')))
|
|
135
|
+
throw new ConnectError('Use connect --all or connect --ask without a vendor.');
|
|
126
136
|
// `--token` is refused on purpose: this command never takes a secret.
|
|
127
137
|
const connection = flag(argv, 'connection');
|
|
128
138
|
if (!connection || !UUID.test(connection))
|
|
129
|
-
throw new ConnectError(`Copy the command from Agents → "Connect
|
|
139
|
+
throw new ConnectError(`Copy the command from Agents → "Connect this computer" in Spaces: it includes --connection <id>.\n\n${exports.CONNECT_USAGE}`);
|
|
130
140
|
const appUrl = flag(argv, 'app-url') ?? env.PF_APP_URL;
|
|
131
141
|
return {
|
|
132
142
|
vendor,
|
|
143
|
+
...(vendor === 'computer'
|
|
144
|
+
? { all: true, askFirst: argv.includes('--ask') }
|
|
145
|
+
: {}),
|
|
133
146
|
connection,
|
|
134
147
|
controlPlane: checkUrl(flag(argv, 'control-plane') ??
|
|
135
148
|
env.PF_CONTROL_PLANE_URL ??
|
|
@@ -162,7 +175,11 @@ async function choosePorts(vendor, deps) {
|
|
|
162
175
|
return { healthPort: priorHealth, proxyPort: priorProxy };
|
|
163
176
|
// Ports other services of ours were given, even if they are stopped now.
|
|
164
177
|
const reserved = new Set();
|
|
165
|
-
for (const other of [
|
|
178
|
+
for (const other of [
|
|
179
|
+
undefined,
|
|
180
|
+
...vendor_backends_1.VENDOR_BACKENDS,
|
|
181
|
+
...(deps.installedInstances?.() ?? [])
|
|
182
|
+
]) {
|
|
166
183
|
if (other === vendor)
|
|
167
184
|
continue;
|
|
168
185
|
const args = deps.installedStartArgs(other);
|
|
@@ -202,28 +219,114 @@ async function postJson(fetchImpl, url, body) {
|
|
|
202
219
|
const json = (await response.json().catch(() => ({})));
|
|
203
220
|
return { status: response.status, json };
|
|
204
221
|
}
|
|
205
|
-
|
|
222
|
+
function computerRoot(home, controlPlane) {
|
|
223
|
+
return (0, node_path_1.join)(home, '.pf-agent-harness', 'connect', 'computer', (0, node_crypto_1.createHash)('sha256').update(controlPlane).digest('hex').slice(0, 16));
|
|
224
|
+
}
|
|
225
|
+
function logComputerResult(deps, added, report) {
|
|
226
|
+
for (const name of added.filter((name) => COMPUTER_BACKENDS.includes(name)))
|
|
227
|
+
deps.log(`✓ Added ${name}.`);
|
|
228
|
+
for (const item of report.filter((h) => !added.includes(h.name))) {
|
|
229
|
+
const help = (0, vendor_backends_1.isVendorBackend)(item.name)
|
|
230
|
+
? exports.VENDOR_SETUP[item.name]
|
|
231
|
+
: {
|
|
232
|
+
install: item.name === 'pi'
|
|
233
|
+
? 'npm install -g @mariozechner/pi-coding-agent'
|
|
234
|
+
: 'npm install -g opencode-ai',
|
|
235
|
+
login: item.name === 'pi'
|
|
236
|
+
? 'Open pi and choose a model provider.'
|
|
237
|
+
: 'Open opencode and configure a model provider.'
|
|
238
|
+
};
|
|
239
|
+
const reason = item.transient
|
|
240
|
+
? 'check timed out. The runner retries while idle; open Machines for the result.'
|
|
241
|
+
: !item.installed
|
|
242
|
+
? `not installed. ${help.install}`
|
|
243
|
+
: !item.usable
|
|
244
|
+
? `${item.reason ? printable(item.reason) : 'not signed in.'} ${help.login}`
|
|
245
|
+
: !item.runnable
|
|
246
|
+
? 'runner support is unavailable. Reinstall the runner.'
|
|
247
|
+
: 'not ready. Check Machines for the next discovery result.';
|
|
248
|
+
deps.log(`— Skipped ${item.name}: ${reason}`);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
async function runConnectInner(args, deps) {
|
|
206
252
|
const { vendor, connection, controlPlane } = args;
|
|
207
|
-
const setup = exports.VENDOR_SETUP[vendor];
|
|
253
|
+
const setup = vendor === 'computer' ? { label: 'this computer' } : exports.VENDOR_SETUP[vendor];
|
|
254
|
+
const root = computerRoot(deps.home, controlPlane);
|
|
255
|
+
const receiptPath = (0, node_path_1.join)(root, `${connection}.json`);
|
|
256
|
+
if (vendor === 'computer' && (0, node_fs_1.existsSync)(receiptPath)) {
|
|
257
|
+
let prior;
|
|
258
|
+
try {
|
|
259
|
+
prior = JSON.parse((0, node_fs_1.readFileSync)(receiptPath, 'utf8'));
|
|
260
|
+
if (!prior ||
|
|
261
|
+
typeof prior !== 'object' ||
|
|
262
|
+
typeof prior.scope !== 'string' ||
|
|
263
|
+
typeof prior.company !== 'string' ||
|
|
264
|
+
!Array.isArray(prior.added) ||
|
|
265
|
+
!prior.added.every((name) => COMPUTER_BACKENDS.includes(name)) ||
|
|
266
|
+
!Array.isArray(prior.report) ||
|
|
267
|
+
!prior.report.every((item) => item &&
|
|
268
|
+
COMPUTER_BACKENDS.includes(item.name) &&
|
|
269
|
+
['installed', 'usable', 'runnable'].every((key) => typeof item[key] ===
|
|
270
|
+
'boolean') &&
|
|
271
|
+
(item.reason === undefined || typeof item.reason === 'string') &&
|
|
272
|
+
(item.transient === undefined ||
|
|
273
|
+
typeof item.transient === 'boolean')) ||
|
|
274
|
+
(prior.startArgs !== undefined &&
|
|
275
|
+
(!Array.isArray(prior.startArgs) ||
|
|
276
|
+
!prior.startArgs.every((arg) => typeof arg === 'string'))))
|
|
277
|
+
throw new Error('Invalid saved connection');
|
|
278
|
+
}
|
|
279
|
+
catch {
|
|
280
|
+
throw new ConnectError('The saved connection is damaged. Get a new command from Spaces.');
|
|
281
|
+
}
|
|
282
|
+
if (!/^[a-f0-9]{24}$/.test(prior.scope) ||
|
|
283
|
+
prior.all !== args.all ||
|
|
284
|
+
prior.askFirst !== args.askFirst)
|
|
285
|
+
throw new ConnectError('Get a new connection command from Spaces to change the connection options.');
|
|
286
|
+
const workspaceRoot = (0, node_path_1.join)(root, prior.scope, 'workspaces');
|
|
287
|
+
if (!new credential_store_1.FileCredentialStore(workspaceRoot).load())
|
|
288
|
+
throw new ConnectError('This connection has no saved runner credential. Get a new command from Spaces.');
|
|
289
|
+
const instance = `computer-${prior.scope}`;
|
|
290
|
+
const startArgs = deps.installedStartArgs(instance) ?? prior.startArgs;
|
|
291
|
+
const healthPort = argNumber(startArgs ?? null, '--health-port');
|
|
292
|
+
if (!startArgs || !healthPort)
|
|
293
|
+
throw new ConnectError('The saved service settings are missing. Get a new command from Spaces.');
|
|
294
|
+
if (!(await deps.waitForHealth(healthPort))) {
|
|
295
|
+
await deps.installService(instance, startArgs, deps.stableInstall());
|
|
296
|
+
if (!(await deps.waitForHealth(healthPort)))
|
|
297
|
+
throw new ConnectError('The saved connection could not resume. Get a new command from Spaces.');
|
|
298
|
+
}
|
|
299
|
+
deps.log(`✓ This computer is already connected to ${printable(prior.company)}. No new runner or token was created.`);
|
|
300
|
+
if (args.all) {
|
|
301
|
+
if (prior.summaryKnown === false)
|
|
302
|
+
deps.log('Agent setup is pending. Open Machines to confirm the result.');
|
|
303
|
+
else
|
|
304
|
+
logComputerResult(deps, prior.added, prior.report);
|
|
305
|
+
}
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
208
308
|
const log = deps.log;
|
|
209
309
|
if (deps.platform !== 'darwin' && deps.platform !== 'linux')
|
|
210
310
|
throw new ConnectError('connect needs macOS or Linux. On Windows, open Agents → "Connect your own agent" in Spaces and use "Ask my agent to do it instead".');
|
|
211
311
|
const machine = machineName(deps.hostname());
|
|
212
312
|
log(`Connecting ${setup.label} on ${machine}…`);
|
|
213
313
|
/* 1. The vendor CLI must be installed and signed in. */
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
314
|
+
if (vendor !== 'computer') {
|
|
315
|
+
const vendorSetup = exports.VENDOR_SETUP[vendor];
|
|
316
|
+
const check = await deps.checkVendor(vendor);
|
|
317
|
+
if (!check.installed)
|
|
318
|
+
throw new ConnectError(`${setup.label} is not installed on this computer.\n` +
|
|
319
|
+
` Install it: ${vendorSetup.install}\n` +
|
|
320
|
+
` Sign in: ${vendorSetup.login}\n` +
|
|
321
|
+
'Then run this command again.');
|
|
322
|
+
if (!check.usable && !check.transient)
|
|
323
|
+
throw new ConnectError(`${setup.label} is installed but not signed in.\n` +
|
|
324
|
+
` Sign in: ${vendorSetup.login}\n` +
|
|
325
|
+
'Then run this command again.');
|
|
326
|
+
log(check.usable
|
|
327
|
+
? `✓ ${setup.label} is installed and signed in.`
|
|
328
|
+
: `! ${setup.label} is installed; its sign-in check is slow and will be retried in the background.`);
|
|
329
|
+
}
|
|
227
330
|
/* 2. Browser approval, bound to this process by `state` and PKCE. */
|
|
228
331
|
const verifier = (0, node_crypto_1.randomBytes)(32).toString('base64url');
|
|
229
332
|
const challenge = (0, node_crypto_1.createHash)('sha256')
|
|
@@ -242,7 +345,10 @@ async function runConnect(args, deps) {
|
|
|
242
345
|
machine,
|
|
243
346
|
port: String(port),
|
|
244
347
|
state: callback.state,
|
|
245
|
-
challenge
|
|
348
|
+
challenge,
|
|
349
|
+
...(vendor === 'computer'
|
|
350
|
+
? { all: args.all ? '1' : '0', ask: args.askFirst ? '1' : '0' }
|
|
351
|
+
: {})
|
|
246
352
|
});
|
|
247
353
|
const approvalUrl = `${appOrigin}/connect-computer?${query.toString()}`;
|
|
248
354
|
log('');
|
|
@@ -269,13 +375,41 @@ async function runConnect(args, deps) {
|
|
|
269
375
|
? printable(exchange.json.error)
|
|
270
376
|
: `The approval could not be used (${exchange.status}). Open Agents → "Connect your own agent" in Spaces (or "Reconnect" on this machine) to get a new command.`);
|
|
271
377
|
const company = typeof exchange.json.companyName === 'string'
|
|
272
|
-
? exchange.json.companyName
|
|
378
|
+
? printable(exchange.json.companyName)
|
|
273
379
|
: 'your company';
|
|
274
380
|
log(`✓ Approved for ${company}.`);
|
|
275
381
|
/* 4. Enrol: a personal runner for this vendor only. */
|
|
276
|
-
const
|
|
277
|
-
|
|
278
|
-
|
|
382
|
+
const identity = `${exchange.json.tenantId}:${exchange.json.ownerUserId}`;
|
|
383
|
+
if (vendor === 'computer' &&
|
|
384
|
+
(!UUID.test(String(exchange.json.tenantId)) ||
|
|
385
|
+
!UUID.test(String(exchange.json.ownerUserId))))
|
|
386
|
+
throw new ConnectError('The approval did not identify the account. Get a new command from Spaces.');
|
|
387
|
+
const scope = (0, node_crypto_1.createHash)('sha256')
|
|
388
|
+
.update(`${controlPlane}:${identity}`)
|
|
389
|
+
.digest('hex')
|
|
390
|
+
.slice(0, 24);
|
|
391
|
+
const instance = vendor === 'computer' ? `computer-${scope}` : vendor;
|
|
392
|
+
const workspaceRoot = vendor === 'computer'
|
|
393
|
+
? (0, node_path_1.join)(root, scope, 'workspaces')
|
|
394
|
+
: (0, node_path_1.join)(deps.home, '.pf-agent-harness', 'connect', vendor, 'workspaces');
|
|
395
|
+
let computerId;
|
|
396
|
+
if (vendor === 'computer') {
|
|
397
|
+
const idPath = (0, node_path_1.join)(root, 'computer-id');
|
|
398
|
+
computerId = (0, node_fs_1.existsSync)(idPath)
|
|
399
|
+
? (0, node_fs_1.readFileSync)(idPath, 'utf8').trim()
|
|
400
|
+
: (0, node_crypto_1.randomUUID)();
|
|
401
|
+
if (!UUID.test(computerId))
|
|
402
|
+
throw new ConnectError('The saved computer identity is invalid. Contact support.');
|
|
403
|
+
(0, node_fs_1.writeFileSync)(idPath, computerId, { mode: 0o600 });
|
|
404
|
+
}
|
|
405
|
+
const ports = await choosePorts(instance, deps);
|
|
406
|
+
const registration = await deps.register({
|
|
407
|
+
controlPlane,
|
|
408
|
+
enrolmentToken,
|
|
409
|
+
vendor,
|
|
410
|
+
workspaceRoot,
|
|
411
|
+
...(computerId ? { computerId } : {})
|
|
412
|
+
});
|
|
279
413
|
log('✓ This computer is registered as your personal runner.');
|
|
280
414
|
/* 5. Background service, started from the saved credential. */
|
|
281
415
|
log('Setting up the background service…');
|
|
@@ -289,7 +423,7 @@ async function runConnect(args, deps) {
|
|
|
289
423
|
'--runtime',
|
|
290
424
|
'desktop',
|
|
291
425
|
'--vendor-harnesses',
|
|
292
|
-
vendor,
|
|
426
|
+
vendor === 'computer' ? vendor_backends_1.VENDOR_BACKENDS.join(',') : vendor,
|
|
293
427
|
'--workspace-root',
|
|
294
428
|
workspaceRoot,
|
|
295
429
|
'--health-port',
|
|
@@ -297,14 +431,76 @@ async function runConnect(args, deps) {
|
|
|
297
431
|
'--github-proxy-port',
|
|
298
432
|
String(ports.proxyPort)
|
|
299
433
|
];
|
|
300
|
-
|
|
434
|
+
if (vendor === 'computer')
|
|
435
|
+
(0, node_fs_1.writeFileSync)(receiptPath, JSON.stringify({
|
|
436
|
+
scope,
|
|
437
|
+
company,
|
|
438
|
+
all: args.all,
|
|
439
|
+
askFirst: args.askFirst,
|
|
440
|
+
added: registration.connectedBackends ?? [],
|
|
441
|
+
summaryKnown: registration.connectedBackends !== undefined,
|
|
442
|
+
report: registration.report ?? [],
|
|
443
|
+
startArgs
|
|
444
|
+
}), { mode: 0o600 });
|
|
445
|
+
await deps.installService(instance, startArgs, paths);
|
|
301
446
|
log('✓ Background service installed. It starts when you log in.');
|
|
302
447
|
const healthy = await deps.waitForHealth(ports.healthPort);
|
|
303
448
|
if (!healthy)
|
|
304
|
-
log(`! The service has not answered yet (it may still be starting, or a local port was taken). Check it with: npx @peakflo/agent-harness service status --vendor ${
|
|
449
|
+
log(`! The service has not answered yet (it may still be starting, or a local port was taken). Check it with: npx @peakflo/agent-harness service status --vendor ${instance}`);
|
|
450
|
+
if (!healthy && vendor === 'computer')
|
|
451
|
+
throw new ConnectError('The runner is registered, but its service has not started. Run this same command again to repair it.');
|
|
452
|
+
if (vendor === 'computer' && args.all) {
|
|
453
|
+
if (registration.connectedBackends === undefined)
|
|
454
|
+
log('Agent setup is pending. Open Machines to confirm the result.');
|
|
455
|
+
else
|
|
456
|
+
logComputerResult(deps, registration.connectedBackends, registration.report ?? []);
|
|
457
|
+
}
|
|
305
458
|
log('');
|
|
306
459
|
log(`✓ ${setup.label} is connected to ${company} on ${machine}. Return to Spaces.`);
|
|
307
460
|
}
|
|
461
|
+
async function runConnect(args, deps) {
|
|
462
|
+
if (args.vendor !== 'computer')
|
|
463
|
+
return runConnectInner(args, deps);
|
|
464
|
+
const root = computerRoot(deps.home, args.controlPlane);
|
|
465
|
+
(0, node_fs_1.mkdirSync)(root, { recursive: true, mode: 0o700 });
|
|
466
|
+
const lock = (0, node_path_1.join)(root, 'connecting.lock');
|
|
467
|
+
try {
|
|
468
|
+
(0, node_fs_1.mkdirSync)(lock, { mode: 0o700 });
|
|
469
|
+
}
|
|
470
|
+
catch {
|
|
471
|
+
let stale = false;
|
|
472
|
+
try {
|
|
473
|
+
const pid = Number((0, node_fs_1.readFileSync)((0, node_path_1.join)(lock, 'pid'), 'utf8'));
|
|
474
|
+
if (Number.isSafeInteger(pid) && pid > 0) {
|
|
475
|
+
try {
|
|
476
|
+
process.kill(pid, 0);
|
|
477
|
+
}
|
|
478
|
+
catch (error) {
|
|
479
|
+
stale = error.code === 'ESRCH';
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
catch {
|
|
484
|
+
/* A command may still be writing its lock. Do not steal it. */
|
|
485
|
+
}
|
|
486
|
+
if (!stale)
|
|
487
|
+
throw new ConnectError('A computer connection is already running. Finish it in the other terminal.');
|
|
488
|
+
(0, node_fs_1.rmSync)(lock, { recursive: true, force: true });
|
|
489
|
+
try {
|
|
490
|
+
(0, node_fs_1.mkdirSync)(lock, { mode: 0o700 });
|
|
491
|
+
}
|
|
492
|
+
catch {
|
|
493
|
+
throw new ConnectError('A computer connection is already running.');
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
(0, node_fs_1.writeFileSync)((0, node_path_1.join)(lock, 'pid'), String(process.pid), { mode: 0o600 });
|
|
497
|
+
try {
|
|
498
|
+
await runConnectInner(args, deps);
|
|
499
|
+
}
|
|
500
|
+
finally {
|
|
501
|
+
(0, node_fs_1.rmSync)(lock, { recursive: true, force: true });
|
|
502
|
+
}
|
|
503
|
+
}
|
|
308
504
|
/* -------------------------------------------------------------------------- */
|
|
309
505
|
/* Real dependencies */
|
|
310
506
|
/* -------------------------------------------------------------------------- */
|
|
@@ -346,11 +542,35 @@ function defaultConnectDeps(context) {
|
|
|
346
542
|
};
|
|
347
543
|
},
|
|
348
544
|
createCallback: () => new approval_callback_1.ApprovalCallback(),
|
|
349
|
-
register: async ({ controlPlane, enrolmentToken, vendor, workspaceRoot }) => {
|
|
545
|
+
register: async ({ controlPlane, enrolmentToken, vendor, workspaceRoot, computerId }) => {
|
|
350
546
|
const capabilities = await (0, capabilities_1.probeCapabilities)({
|
|
351
547
|
maxConcurrentSessions: 10
|
|
352
548
|
});
|
|
353
|
-
capabilities.vendorHarnesses =
|
|
549
|
+
capabilities.vendorHarnesses =
|
|
550
|
+
vendor === 'computer' ? [...vendor_backends_1.VENDOR_BACKENDS] : [vendor];
|
|
551
|
+
let report = [];
|
|
552
|
+
if (vendor === 'computer') {
|
|
553
|
+
Object.assign(capabilities, { computerId });
|
|
554
|
+
report = await (0, harness_discovery_1.discoverHarnesses)({
|
|
555
|
+
runnableBackends: COMPUTER_BACKENDS
|
|
556
|
+
});
|
|
557
|
+
for (const h of report) {
|
|
558
|
+
if (h.installed &&
|
|
559
|
+
h.usable &&
|
|
560
|
+
(0, vendor_backends_1.isVendorBackend)(h.name) &&
|
|
561
|
+
!(0, vendor_backends_1.vendorBackendBlocker)(h.name, 'desktop') &&
|
|
562
|
+
!capabilities.backends.some((b) => b.name === h.name))
|
|
563
|
+
capabilities.backends.push({
|
|
564
|
+
name: h.name,
|
|
565
|
+
version: h.version ?? null
|
|
566
|
+
});
|
|
567
|
+
h.runnable =
|
|
568
|
+
h.installed &&
|
|
569
|
+
h.usable &&
|
|
570
|
+
capabilities.backends.some((b) => b.name === h.name);
|
|
571
|
+
}
|
|
572
|
+
capabilities.harnesses = report;
|
|
573
|
+
}
|
|
354
574
|
const client = new control_plane_1.ControlPlaneClient(controlPlane);
|
|
355
575
|
const response = await client.register({
|
|
356
576
|
enrolmentToken,
|
|
@@ -368,9 +588,30 @@ function defaultConnectDeps(context) {
|
|
|
368
588
|
credentialExpiresAt: response.credentialExpiresAt ?? null,
|
|
369
589
|
savedAt: new Date().toISOString()
|
|
370
590
|
});
|
|
371
|
-
return {
|
|
591
|
+
return {
|
|
592
|
+
runnerId,
|
|
593
|
+
connectedBackends: response.connectedBackends,
|
|
594
|
+
report: report.map(({ name, installed, usable, runnable, transient, reason }) => ({
|
|
595
|
+
name,
|
|
596
|
+
installed,
|
|
597
|
+
usable,
|
|
598
|
+
runnable,
|
|
599
|
+
transient,
|
|
600
|
+
reason
|
|
601
|
+
}))
|
|
602
|
+
};
|
|
372
603
|
},
|
|
373
604
|
installedStartArgs: (instance) => manager(instance).installedStartArgs(),
|
|
605
|
+
installedInstances: () => {
|
|
606
|
+
try {
|
|
607
|
+
return (0, node_fs_1.readdirSync)((0, node_path_1.join)(home, '.pf-agent-harness'))
|
|
608
|
+
.filter((name) => /^service-computer-[a-f0-9]{24}\.json$/.test(name))
|
|
609
|
+
.map((name) => name.slice('service-'.length, -'.json'.length));
|
|
610
|
+
}
|
|
611
|
+
catch {
|
|
612
|
+
return [];
|
|
613
|
+
}
|
|
614
|
+
},
|
|
374
615
|
portOccupied: portInUse,
|
|
375
616
|
stableInstall: () => {
|
|
376
617
|
const inNpxCache = context.cliPath.includes('/_npx/') ||
|
package/dist/service.js
CHANGED
|
@@ -48,7 +48,7 @@ function serviceNames(instance) {
|
|
|
48
48
|
stateFile: 'service.json',
|
|
49
49
|
logDir: 'logs'
|
|
50
50
|
};
|
|
51
|
-
if (!(0, vendor_backends_1.isVendorBackend)(instance))
|
|
51
|
+
if (!(0, vendor_backends_1.isVendorBackend)(instance) && !/^computer-[a-f0-9]{24}$/.test(instance))
|
|
52
52
|
throw new Error('Use codex, claude-code, or cursor as the service name.');
|
|
53
53
|
return {
|
|
54
54
|
label: `${LABEL}.${instance}`,
|
package/dist/types.d.ts
CHANGED
|
@@ -348,6 +348,8 @@ export interface RunnerRegisterRequest extends ProtocolEnvelope {
|
|
|
348
348
|
}
|
|
349
349
|
export type RunnerRuntime = 'sandbox' | 'self-hosted' | 'desktop';
|
|
350
350
|
export interface RunnerRegisterResponse {
|
|
351
|
+
/** Agents created after an explicitly approved computer connect. */
|
|
352
|
+
connectedBackends?: string[];
|
|
351
353
|
/**
|
|
352
354
|
* The version gate. `false` is FINAL — never retried. The harness exits
|
|
353
355
|
* non-zero so the host is recycled onto a supported version. It must EXIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peakflo/agent-harness",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.24-rc.1",
|
|
4
4
|
"description": "Headless Peakflo coding-agent harness. One codebase, three hosting modes: a Daytona cloud sandbox, a customer VM, and the 20x desktop.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "commonjs",
|