@peakflo/agent-harness 0.2.22-rc.1 → 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/dist/harness.js CHANGED
@@ -30,6 +30,8 @@ const vendor_backends_1 = require("./vendor-backends");
30
30
  const version_1 = require("./version");
31
31
  /** Backoff after a lease poll fails, so an unreachable control plane is not hammered. */
32
32
  const LEASE_ERROR_BACKOFF_MS = 5_000;
33
+ /** The longest wait between heartbeat retries while the control plane is unreachable. */
34
+ const OFFLINE_RETRY_CAP_MS = 60_000;
33
35
  const LEASE_MIN_EMPTY_POLL_MS = 250;
34
36
  /**
35
37
  * How often the model catalogue is re-probed once the harness is running.
@@ -117,8 +119,8 @@ class VersionRefusedError extends Error {
117
119
  exports.VersionRefusedError = VersionRefusedError;
118
120
  /** A service cannot re-enrol without a new one-time token from a user. */
119
121
  class StoredCredentialUnavailableError extends Error {
120
- constructor() {
121
- super('No usable stored runner credential. For your own agent, open Agents in Spaces and use "Reconnect" on this machine (or "Connect your own agent") to get a new command, then run it here. For a self-hosted runner, start it once in a terminal to sign in again.');
122
+ constructor(reason) {
123
+ super(`${reason ? `${reason} ` : ''}No usable stored runner credential. For your own agent, open Agents in Spaces and use "Reconnect" on this machine (or "Connect your own agent") to get a new command, then run it here. For a self-hosted runner, start it once in a terminal to sign in again.`);
122
124
  this.name = 'StoredCredentialUnavailableError';
123
125
  }
124
126
  }
@@ -263,6 +265,13 @@ class Harness {
263
265
  lastHeartbeatAt = null;
264
266
  lastHeartbeatError = null;
265
267
  consecutiveHeartbeatFailures = 0;
268
+ /**
269
+ * True while the harness drains ONLY because heartbeats failed ("presumed
270
+ * offline"). It is not a drain the control plane asked for, so it ends on
271
+ * the first heartbeat that gets through, and the lease loop waits instead of
272
+ * exiting.
273
+ */
274
+ offlineDraining = false;
266
275
  stopping = false;
267
276
  /** Releases this Harness's reference to the process-wide generic wrappers. */
268
277
  releaseGitHubGuard = null;
@@ -706,6 +715,10 @@ class Harness {
706
715
  this.observeHarnessPin(response.harnessVersion);
707
716
  this.observeSandboxToolsPin(response.sandboxToolsVersion);
708
717
  this.applyCommandsSafely(response.sessionCommands ?? []);
718
+ // THE STORED-CREDENTIAL START MUST ROTATE TOO. This is the path every
719
+ // background service takes. Without a timer here the credential lived
720
+ // out its 24 h TTL and the service stopped for good.
721
+ this.scheduleRotation(stored.rotateAfter ?? undefined, stored.credentialExpiresAt ?? undefined);
709
722
  log('Reused stored runner credential', {
710
723
  runnerId: stored.runnerId,
711
724
  tenantId: stored.tenantId
@@ -731,6 +744,7 @@ class Harness {
731
744
  // a good credential over a momentary outage.
732
745
  this.tenantId = stored.tenantId;
733
746
  this.runnerId = stored.runnerId;
747
+ this.scheduleRotation(stored.rotateAfter ?? undefined, stored.credentialExpiresAt ?? undefined);
734
748
  log('Could not validate stored credential (transient); proceeding', {
735
749
  runnerId: stored.runnerId,
736
750
  error: error instanceof Error ? error.message : String(error)
@@ -753,6 +767,7 @@ class Harness {
753
767
  tenantId: this.tenantId,
754
768
  credential: response.runnerCredential,
755
769
  credentialExpiresAt: response.credentialExpiresAt ?? null,
770
+ rotateAfter: response.rotateAfter ?? null,
756
771
  savedAt: new Date().toISOString()
757
772
  });
758
773
  }
@@ -801,7 +816,7 @@ class Harness {
801
816
  */
802
817
  async rotateCredential() {
803
818
  if (this.stopping) {
804
- return;
819
+ return false;
805
820
  }
806
821
  try {
807
822
  const response = await this.client.rotateCredential((0, version_1.getHarnessVersion)());
@@ -811,6 +826,7 @@ class Harness {
811
826
  tenantId: this.tenantId,
812
827
  credential: response.runnerCredential,
813
828
  credentialExpiresAt: response.credentialExpiresAt ?? null,
829
+ rotateAfter: response.rotateAfter ?? null,
814
830
  savedAt: new Date().toISOString()
815
831
  });
816
832
  for (const renewal of this.activeRenewals) {
@@ -819,6 +835,7 @@ class Harness {
819
835
  }
820
836
  log('Rotated runner credential', { rotateAfter: response.rotateAfter });
821
837
  this.scheduleRotation(response.rotateAfter, response.credentialExpiresAt);
838
+ return true;
822
839
  }
823
840
  catch (error) {
824
841
  log('Credential rotation failed', {
@@ -831,8 +848,34 @@ class Harness {
831
848
  }, 30_000);
832
849
  this.rotateTimer.unref();
833
850
  }
851
+ return false;
834
852
  }
835
853
  }
854
+ /**
855
+ * The control plane answered 401/403 to the runner credential.
856
+ *
857
+ * Try ONE rotation first: a credential that is merely close to the edge (a
858
+ * clock skew, a heartbeat that raced the expiry) may still rotate. If it
859
+ * cannot, the credential is gone. A service has no token to enrol with, so
860
+ * retrying would loop for ever. Stop with a message that says what to do and
861
+ * a non-zero exit so launchd and systemd show a failure.
862
+ */
863
+ async handleCredentialRejected(error) {
864
+ if (await this.rotateCredential()) {
865
+ log('Runner credential was rejected; rotation succeeded', {
866
+ status: error.status
867
+ });
868
+ return true;
869
+ }
870
+ this.credentialStore.clear();
871
+ this.fatal = new StoredCredentialUnavailableError(`The control plane rejected this runner credential (HTTP ${error.status}${error.code ? `, ${error.code}` : ''}).`);
872
+ log('Runner credential rejected and cannot be rotated; stopping', {
873
+ status: error.status,
874
+ code: error.code
875
+ });
876
+ await this.stop();
877
+ return false;
878
+ }
836
879
  /* ------------------------------------------------------------------ */
837
880
  /* Heartbeat */
838
881
  /* ------------------------------------------------------------------ */
@@ -1187,13 +1230,13 @@ class Harness {
1187
1230
  }
1188
1231
  return Date.now() - this.modelProbeAt >= MODEL_PROBE_REFRESH_MS;
1189
1232
  }
1190
- scheduleHeartbeat() {
1233
+ scheduleHeartbeat(delayMs) {
1191
1234
  if (this.stopping) {
1192
1235
  return;
1193
1236
  }
1194
1237
  this.heartbeatTimer = setTimeout(() => {
1195
1238
  void this.sendHeartbeat();
1196
- }, this.heartbeatIntervalMs);
1239
+ }, delayMs ?? this.heartbeatIntervalMs);
1197
1240
  // Never hold the event loop open on the heartbeat alone.
1198
1241
  this.heartbeatTimer.unref();
1199
1242
  }
@@ -1258,6 +1301,15 @@ class Harness {
1258
1301
  this.lastHeartbeatAt = new Date().toISOString();
1259
1302
  this.lastHeartbeatError = null;
1260
1303
  this.consecutiveHeartbeatFailures = 0;
1304
+ if (this.offlineDraining) {
1305
+ // The network is back and the control plane still knows this runner:
1306
+ // take work again. No re-enrolment is needed, the credential is valid.
1307
+ this.offlineDraining = false;
1308
+ if (this.status === 'draining' && !this.stopping) {
1309
+ this.status = 'ready';
1310
+ log('Control plane reachable again, resuming');
1311
+ }
1312
+ }
1261
1313
  if (response.heartbeatIntervalMs) {
1262
1314
  this.heartbeatIntervalMs = response.heartbeatIntervalMs;
1263
1315
  }
@@ -1287,6 +1339,14 @@ class Harness {
1287
1339
  await this.stop();
1288
1340
  return;
1289
1341
  }
1342
+ if (error instanceof control_plane_1.ControlPlaneError &&
1343
+ (error.status === 401 || error.status === 403) &&
1344
+ !this.stopping) {
1345
+ if (await this.handleCredentialRejected(error)) {
1346
+ this.scheduleHeartbeat(1_000);
1347
+ }
1348
+ return;
1349
+ }
1290
1350
  this.consecutiveHeartbeatFailures += 1;
1291
1351
  this.lastHeartbeatError =
1292
1352
  error instanceof Error ? error.message : String(error);
@@ -1300,10 +1360,16 @@ class Harness {
1300
1360
  if (this.consecutiveHeartbeatFailures >= contract_1.MISSED_HEARTBEATS_BEFORE_OFFLINE &&
1301
1361
  this.status === 'ready') {
1302
1362
  this.status = 'draining';
1363
+ this.offlineDraining = true;
1303
1364
  log('Presumed offline by the control plane, draining');
1304
1365
  }
1305
1366
  }
1306
- this.scheduleHeartbeat();
1367
+ // Keep retrying while offline, with a capped back-off so a long outage is
1368
+ // not hammered. The first heartbeat that gets through resumes the runner.
1369
+ const failures = this.consecutiveHeartbeatFailures;
1370
+ this.scheduleHeartbeat(failures > 0
1371
+ ? Math.min(this.heartbeatIntervalMs * 2 ** Math.min(failures - 1, 4), OFFLINE_RETRY_CAP_MS)
1372
+ : undefined);
1307
1373
  }
1308
1374
  /** A bad command must not stop the others or fail a transcript ingest. */
1309
1375
  applyCommandsSafely(commands) {
@@ -1576,7 +1642,9 @@ class Harness {
1576
1642
  }
1577
1643
  if (this.status === 'draining') {
1578
1644
  // Draining means "finish what you hold, take nothing new".
1579
- if (this.active.size === 0) {
1645
+ // An OFFLINE drain is different: nothing asked this runner to leave, so
1646
+ // wait for the heartbeat to resume it instead of ending the process.
1647
+ if (this.active.size === 0 && !this.offlineDraining) {
1580
1648
  break;
1581
1649
  }
1582
1650
  await sleep(1_000);
@@ -1598,7 +1666,11 @@ class Harness {
1598
1666
  break;
1599
1667
  }
1600
1668
  if (error instanceof control_plane_1.ControlPlaneError && error.final) {
1601
- this.fatal = error;
1669
+ this.fatal =
1670
+ (error.status === 401 || error.status === 403) &&
1671
+ this.reusedStoredCredential
1672
+ ? new StoredCredentialUnavailableError(`The control plane rejected this runner credential (HTTP ${error.status}).`)
1673
+ : error;
1602
1674
  break;
1603
1675
  }
1604
1676
  log('Lease poll failed', {
@@ -17,8 +17,12 @@
17
17
  * adapter default. That is defect G1 — a Permission control that is recorded,
18
18
  * served, rendered, and enforced nowhere.
19
19
  *
20
- * A stored mode keeps the user's choice. Missing and unrecognised modes
21
- * fail closed onto 'ask'.
20
+ * A stored mode keeps the user's choice. A MISSING mode (null, undefined or
21
+ * '') means nobody chose one, so it gets the new-agent default,
22
+ * `bypassPermissions` → 'allow' (owner decision: "Allow by default", #1858,
23
+ * #1977; re-applied after #2012 reverted it). A NON-EMPTY mode this build does
24
+ * not recognise still fails closed onto 'ask': it may be a stricter mode from
25
+ * a newer control plane.
22
26
  *
23
27
  * ---------------------------------------------------------------------------
24
28
  * THE TABLE, AND WHAT IS AND IS NOT FAITHFUL
@@ -103,11 +107,21 @@ export declare function mapPermissionMode(mode: LeasePermissionMode | string | n
103
107
  * This is why the mapping is lossless there and lossy on Pi: the loss is
104
108
  * in the BACKEND, not in the wire.
105
109
  *
106
- * Absent `permissionMode` means the caller never set one. That is the pre-G1
107
- * state and it must NOT silently become `bypassPermissions` again, so it maps
108
- * to `'default'` — Claude Code's own asking mode.
110
+ * Absent `permissionMode` means the caller never set one, so it gets the
111
+ * new-agent default, `bypassPermissions` — the same as `mapPermissionMode`
112
+ * gives a missing lease mode. Only an explicit `'ask'` reaches Claude Code's
113
+ * asking modes.
109
114
  */
110
115
  export declare function claudeCodePermissionMode(config: {
111
116
  permissionMode?: AdapterPermissionMode;
112
117
  sandboxMode?: AdapterSandboxMode;
113
118
  }): LeasePermissionMode;
119
+ /**
120
+ * The mode an ADAPTER acts on. `'ask'` only for an explicit `'ask'`; a config
121
+ * with no `permissionMode` gets the new-agent default, `'allow'`. Every
122
+ * adapter decides "auto-approve or prompt" through this, so no backend picks
123
+ * its own fallback for a missing value.
124
+ */
125
+ export declare function effectivePermissionMode(config: {
126
+ permissionMode?: AdapterPermissionMode | string | null;
127
+ }): AdapterPermissionMode;
@@ -18,8 +18,12 @@
18
18
  * adapter default. That is defect G1 — a Permission control that is recorded,
19
19
  * served, rendered, and enforced nowhere.
20
20
  *
21
- * A stored mode keeps the user's choice. Missing and unrecognised modes
22
- * fail closed onto 'ask'.
21
+ * A stored mode keeps the user's choice. A MISSING mode (null, undefined or
22
+ * '') means nobody chose one, so it gets the new-agent default,
23
+ * `bypassPermissions` → 'allow' (owner decision: "Allow by default", #1858,
24
+ * #1977; re-applied after #2012 reverted it). A NON-EMPTY mode this build does
25
+ * not recognise still fails closed onto 'ask': it may be a stricter mode from
26
+ * a newer control plane.
23
27
  *
24
28
  * ---------------------------------------------------------------------------
25
29
  * THE TABLE, AND WHAT IS AND IS NOT FAITHFUL
@@ -83,6 +87,7 @@
83
87
  Object.defineProperty(exports, "__esModule", { value: true });
84
88
  exports.mapPermissionMode = mapPermissionMode;
85
89
  exports.claudeCodePermissionMode = claudeCodePermissionMode;
90
+ exports.effectivePermissionMode = effectivePermissionMode;
86
91
  /**
87
92
  * THE ONLY PLACE the four-valued lease mode becomes the two-valued adapter
88
93
  * mode. Deliberately total: an unknown value — a newer control plane, a hand-
@@ -91,6 +96,10 @@ exports.claudeCodePermissionMode = claudeCodePermissionMode;
91
96
  */
92
97
  function mapPermissionMode(mode) {
93
98
  switch (mode) {
99
+ // Missing: nobody chose. The new-agent default is "don't ask".
100
+ case null:
101
+ case undefined:
102
+ case '':
94
103
  case 'bypassPermissions':
95
104
  return {
96
105
  permissionMode: 'allow',
@@ -115,12 +124,13 @@ function mapPermissionMode(mode) {
115
124
  * This is why the mapping is lossless there and lossy on Pi: the loss is
116
125
  * in the BACKEND, not in the wire.
117
126
  *
118
- * Absent `permissionMode` means the caller never set one. That is the pre-G1
119
- * state and it must NOT silently become `bypassPermissions` again, so it maps
120
- * to `'default'` — Claude Code's own asking mode.
127
+ * Absent `permissionMode` means the caller never set one, so it gets the
128
+ * new-agent default, `bypassPermissions` — the same as `mapPermissionMode`
129
+ * gives a missing lease mode. Only an explicit `'ask'` reaches Claude Code's
130
+ * asking modes.
121
131
  */
122
132
  function claudeCodePermissionMode(config) {
123
- if (config.permissionMode === 'allow') {
133
+ if (config.permissionMode !== 'ask') {
124
134
  return 'bypassPermissions';
125
135
  }
126
136
  if (config.sandboxMode === 'read-only') {
@@ -141,3 +151,12 @@ function claudeCodePermissionMode(config) {
141
151
  }
142
152
  return 'default';
143
153
  }
154
+ /**
155
+ * The mode an ADAPTER acts on. `'ask'` only for an explicit `'ask'`; a config
156
+ * with no `permissionMode` gets the new-agent default, `'allow'`. Every
157
+ * adapter decides "auto-approve or prompt" through this, so no backend picks
158
+ * its own fallback for a missing value.
159
+ */
160
+ function effectivePermissionMode(config) {
161
+ return config.permissionMode === 'ask' ? 'ask' : 'allow';
162
+ }
@@ -693,4 +693,10 @@ export declare class SessionRunner {
693
693
  */
694
694
  private logMcpToolStore;
695
695
  private buildSessionConfig;
696
+ /**
697
+ * A MISSING lease mode runs as the new-agent default (allow). That is the
698
+ * owner's decision, but it is also what a dropped field would look like, so
699
+ * it is logged rather than taken silently.
700
+ */
701
+ private leasePermission;
696
702
  }
@@ -2935,8 +2935,20 @@ class SessionRunner {
2935
2935
  * ./permission-mode.ts. `sandboxMode` is set from the same call because
2936
2936
  * it is what carries the part of the intent 'ask' | 'allow' cannot.
2937
2937
  */
2938
- ...(0, permission_mode_1.mapPermissionMode)(session.agent.permissionMode)
2938
+ ...this.leasePermission(session)
2939
2939
  };
2940
2940
  }
2941
+ /**
2942
+ * A MISSING lease mode runs as the new-agent default (allow). That is the
2943
+ * owner's decision, but it is also what a dropped field would look like, so
2944
+ * it is logged rather than taken silently.
2945
+ */
2946
+ leasePermission(session) {
2947
+ const mode = session.agent.permissionMode;
2948
+ if (!mode) {
2949
+ this.logger.warn(`[SessionRunner] permission-mode-missing session=${session.sessionId} using=allow`);
2950
+ }
2951
+ return (0, permission_mode_1.mapPermissionMode)(mode);
2952
+ }
2941
2953
  }
2942
2954
  exports.SessionRunner = SessionRunner;
package/dist/service.d.ts CHANGED
@@ -17,6 +17,9 @@ export interface ServiceContext {
17
17
  output?: (message: string) => void;
18
18
  sleep?: (ms: number) => void;
19
19
  portOccupied?: (port: number) => Promise<boolean>;
20
+ /** Test hooks for stopping a leftover process. */
21
+ kill?: (pid: number, signal: 'SIGTERM' | 'SIGKILL') => void;
22
+ pidAlive?: (pid: number) => boolean;
20
23
  /**
21
24
  * A per-vendor service from `connect` (`ai.peakflo.agent-harness.<vendor>`),
22
25
  * so Claude Code, Codex and Cursor can each run as their own personal
@@ -69,7 +72,18 @@ export declare class ServiceManager {
69
72
  healthPort: number;
70
73
  }): void;
71
74
  status(): void;
72
- uninstall(): void;
75
+ /** Process ID of the running service, or 0 when it is not running. */
76
+ private runningPid;
77
+ private launchDomain;
78
+ private isLoaded;
79
+ /** Stop a process that outlived its service manager entry. */
80
+ private terminate;
81
+ /**
82
+ * Remove the service for good: stop the process, drop the manager entry,
83
+ * delete the unit file, and free the health port. Safe to run twice. It
84
+ * reports success only after the manager no longer lists the service.
85
+ */
86
+ uninstall(): Promise<void>;
73
87
  }
74
88
  export declare function runServiceCommand(input: string[], context: ServiceContext): Promise<void>;
75
89
  export {};
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}`,
@@ -558,25 +558,142 @@ class ServiceManager {
558
558
  this.output(`Status: stopped. Last error: ${savedError || 'service manager could not read status'}.`);
559
559
  }
560
560
  }
561
- uninstall() {
561
+ /** Process ID of the running service, or 0 when it is not running. */
562
+ runningPid() {
563
+ try {
564
+ if (this.platform === 'darwin') {
565
+ const info = this.run('launchctl', [
566
+ 'print',
567
+ `${this.launchDomain()}/${this.label}`
568
+ ]);
569
+ return Number(info.match(/\bpid = (\d+)/)?.[1] ?? 0);
570
+ }
571
+ const info = this.run('systemctl', [
572
+ '--user',
573
+ 'show',
574
+ this.unit,
575
+ '--property=MainPID'
576
+ ]);
577
+ return Number(info.match(/^MainPID=(\d+)$/m)?.[1] ?? 0);
578
+ }
579
+ catch {
580
+ return 0;
581
+ }
582
+ }
583
+ launchDomain() {
584
+ return `gui/${this.context.uid ?? process.getuid?.() ?? (0, node_os_1.userInfo)().uid}`;
585
+ }
586
+ isLoaded() {
587
+ try {
588
+ if (this.platform === 'darwin') {
589
+ this.run('launchctl', [
590
+ 'print',
591
+ `${this.launchDomain()}/${this.label}`
592
+ ]);
593
+ return true;
594
+ }
595
+ const info = this.run('systemctl', [
596
+ '--user',
597
+ 'show',
598
+ this.unit,
599
+ '--property=LoadState'
600
+ ]);
601
+ return /^LoadState=(?!not-found)/m.test(info);
602
+ }
603
+ catch {
604
+ return false;
605
+ }
606
+ }
607
+ /** Stop a process that outlived its service manager entry. */
608
+ terminate(pid) {
609
+ if (!pid || pid === process.pid)
610
+ return;
611
+ const alive = this.context.pidAlive ??
612
+ ((id) => {
613
+ try {
614
+ process.kill(id, 0);
615
+ return true;
616
+ }
617
+ catch {
618
+ return false;
619
+ }
620
+ });
621
+ const kill = this.context.kill ?? ((id, sig) => process.kill(id, sig));
622
+ const wait = this.context.sleep ?? sleep;
623
+ for (const signal of ['SIGTERM', 'SIGKILL']) {
624
+ if (!alive(pid))
625
+ return;
626
+ try {
627
+ kill(pid, signal);
628
+ }
629
+ catch {
630
+ return;
631
+ }
632
+ for (let tick = 0; tick < 10 && alive(pid); tick++)
633
+ wait(500);
634
+ }
635
+ }
636
+ /**
637
+ * Remove the service for good: stop the process, drop the manager entry,
638
+ * delete the unit file, and free the health port. Safe to run twice. It
639
+ * reports success only after the manager no longer lists the service.
640
+ */
641
+ async uninstall() {
562
642
  this.supported();
643
+ const pid = this.runningPid();
644
+ let healthPort = null;
645
+ try {
646
+ healthPort = Number(argValue(this.readConfig().startArgs, '--health-port') ?? '7777');
647
+ }
648
+ catch {
649
+ /* no saved settings */
650
+ }
563
651
  if (this.platform === 'darwin') {
564
- const domain = `gui/${this.context.uid ?? process.getuid?.() ?? (0, node_os_1.userInfo)().uid}`;
652
+ const target = `${this.launchDomain()}/${this.label}`;
565
653
  try {
566
- this.run('launchctl', ['bootout', `${domain}/${this.label}`]);
654
+ this.run('launchctl', ['bootout', target]);
567
655
  }
568
656
  catch {
569
- /* absent */
657
+ try {
658
+ this.run('launchctl', ['remove', this.label]);
659
+ }
660
+ catch {
661
+ /* absent */
662
+ }
663
+ }
664
+ }
665
+ else {
666
+ try {
667
+ this.run('systemctl', ['--user', 'disable', '--now', this.unit]);
668
+ }
669
+ catch {
670
+ /* absent or already stopped */
570
671
  }
571
672
  }
572
- else if ((0, node_fs_1.existsSync)(this.serviceFile)) {
573
- this.run('systemctl', ['--user', 'disable', '--now', this.unit]);
673
+ this.terminate(pid);
674
+ if (this.isLoaded() && (0, node_fs_1.existsSync)(this.serviceFile)) {
675
+ // Keep the unit file so that "service uninstall" can be run again.
676
+ throw new Error(`The service manager still lists ${this.platform === 'darwin' ? this.label : this.unit}. It was not removed. Run: ${this.platform === 'darwin'
677
+ ? `launchctl bootout ${this.launchDomain()}/${this.label}`
678
+ : `systemctl --user disable --now ${this.unit}`}, then run service uninstall again.`);
574
679
  }
575
680
  (0, node_fs_1.rmSync)(this.serviceFile, { force: true });
576
681
  (0, node_fs_1.rmSync)(this.stateFile, { force: true });
577
682
  clearServiceFailure(this.home);
578
- if (this.platform === 'linux')
579
- this.run('systemctl', ['--user', 'daemon-reload']);
683
+ if (this.platform === 'linux') {
684
+ try {
685
+ this.run('systemctl', ['--user', 'daemon-reload']);
686
+ this.run('systemctl', ['--user', 'reset-failed', this.unit]);
687
+ }
688
+ catch {
689
+ /* nothing to reload */
690
+ }
691
+ }
692
+ if (healthPort &&
693
+ (await (this.context.portOccupied ?? portOccupied)(healthPort))) {
694
+ this.output(`Service removed, but health port ${healthPort} is still in use by another process. Find it with: lsof -i :${healthPort}`);
695
+ return;
696
+ }
580
697
  this.output('Service removed. The saved runner credential remains in the workspace.');
581
698
  }
582
699
  }
@@ -609,7 +726,7 @@ async function runServiceCommand(input, context) {
609
726
  manager.repair(args.slice(1));
610
727
  break;
611
728
  case 'uninstall':
612
- manager.uninstall();
729
+ await manager.uninstall();
613
730
  break;
614
731
  default:
615
732
  throw new Error('Use service install, status, repair, or uninstall.');
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.22-rc.1",
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",