@blogic-cz/agent-tools 0.15.6 → 0.15.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blogic-cz/agent-tools",
3
- "version": "0.15.6",
3
+ "version": "0.15.7",
4
4
  "description": "CLI tools for AI coding agent workflows — GitHub, database, Kubernetes, Azure DevOps, logs, sessions, and audit",
5
5
  "keywords": [
6
6
  "agent",
@@ -120,8 +120,10 @@ const executeK8sCommand = (command: string, options: CommonK8sCommandOptions) =>
120
120
  const errorResult: CommandResult = {
121
121
  success: false,
122
122
  error: error.message,
123
- hint: `Verify cluster ID "${k8sConfig.clusterId}" matches a context in kubectl config. Run: kubectl config get-contexts`,
124
- nextCommand: "kubectl config get-contexts",
123
+ hint:
124
+ error.hint ??
125
+ `Verify cluster ID "${k8sConfig.clusterId}" matches a context in kubectl config. Run: kubectl config get-contexts`,
126
+ ...(error.hint ? {} : { nextCommand: "kubectl config get-contexts" }),
125
127
  executionTimeMs: 0,
126
128
  };
127
129
  return Effect.succeed(errorResult);
@@ -16,6 +16,7 @@ import type { K8sConfig } from "#config";
16
16
  import { collectProcessOutput, quoteShellArg } from "#shared/exec";
17
17
  import { resolveEnvTemplate } from "#shared/env-template";
18
18
  import { isPrerequisiteRunError } from "#shared/prerequisites/errors";
19
+ import { normalizeProfilePrerequisites } from "#shared/prerequisites/config";
19
20
  import { runWithProfilePrerequisites } from "#shared/prerequisites/runtime";
20
21
  import { buildApiProbeArgs } from "#shared/k8s-probe";
21
22
  import { isKubectlCommandAllowed, isSafeLogPath } from "./security";
@@ -275,14 +276,23 @@ export class K8sService extends Context.Service<
275
276
  const k8sConfig = yield* requireK8sConfig(profile);
276
277
  const timeoutMs = k8sConfig.timeoutMs ?? 60000;
277
278
  const apiProbeTimeoutMs = k8sConfig.apiProbeTimeoutMs ?? 2000;
279
+ const { context, kubeconfig } = yield* resolveContext(profile, k8sConfig);
280
+ const reachableWithoutPrerequisites = yield* probeApiReachable(
281
+ context,
282
+ kubeconfig,
283
+ apiProbeTimeoutMs,
284
+ );
285
+ const vpnGated = normalizeProfilePrerequisites(k8sConfig).some(
286
+ (prerequisite) => prerequisite.type === "vpn",
287
+ );
278
288
  return yield* runWithProfilePrerequisites(
279
289
  config ?? {},
280
290
  k8sConfig,
281
291
  runPrerequisiteCommand,
282
292
  Effect.gen(function* () {
283
- const { context, kubeconfig } = yield* resolveContext(profile, k8sConfig);
284
-
285
- const reachable = yield* probeApiReachable(context, kubeconfig, apiProbeTimeoutMs);
293
+ const reachable =
294
+ reachableWithoutPrerequisites ||
295
+ (vpnGated && (yield* probeApiReachable(context, kubeconfig, apiProbeTimeoutMs)));
286
296
  if (!reachable) {
287
297
  return yield* new K8sContextError({
288
298
  message: `Kubernetes API server (${k8sConfig.clusterId}) not reachable within ${apiProbeTimeoutMs}ms. VPN likely not connected, or the cluster API is degraded.`,
@@ -332,6 +342,7 @@ export class K8sService extends Context.Service<
332
342
  command: fullCommand,
333
343
  };
334
344
  }),
345
+ { alreadySatisfied: apiProbeTimeoutMs > 0 && reachableWithoutPrerequisites },
335
346
  ).pipe(
336
347
  Effect.mapError((error) =>
337
348
  isPrerequisiteRunError(error)
@@ -78,32 +78,38 @@ export async function stopWhenIdle(
78
78
  const deadline = now() + init.disconnectTimeoutMs;
79
79
  let evidence = "VPN stop did not produce confirmed disconnected status.";
80
80
  try {
81
- let remaining = deadline - now();
81
+ const remaining = deadline - now();
82
82
  if (remaining > 0) {
83
83
  const stop = await runCommand("stop", remaining);
84
- remaining = deadline - now();
85
84
  if (stop.exitCode !== 0) {
86
- evidence = "VPN stop command failed; ownership is unknown and stop will not be retried.";
85
+ evidence = `VPN stop command failed (exit ${stop.exitCode}); ownership is unknown and stop will not be retried.`;
87
86
  } else {
88
- const confirmDisconnected = async (): Promise<boolean> => {
87
+ const stillConnected =
88
+ "VPN still reported connected after stop when the disconnect deadline expired.";
89
+ const confirmDisconnected = async (): Promise<true | string> => {
89
90
  const statusRemaining = deadline - now();
90
- if (statusRemaining <= 0) return false;
91
+ if (statusRemaining <= 0) {
92
+ return "VPN stop was dispatched, but the disconnect deadline expired before status could be confirmed.";
93
+ }
91
94
  const status = await runCommand("status", statusRemaining);
92
- remaining = deadline - now();
93
95
  const connected = parseVpnStatus(init.driver, status);
94
96
  if (connected === false) return true;
95
- if (connected === undefined || remaining <= 0) return false;
97
+ if (connected === undefined) {
98
+ return status.exitCode === 0
99
+ ? "VPN status output after stop was unparseable; ownership is unknown."
100
+ : `VPN status command after stop failed (exit ${status.exitCode}); ownership is unknown.`;
101
+ }
96
102
  const sleepRemaining = deadline - now();
97
- if (sleepRemaining <= 0) return false;
103
+ if (sleepRemaining <= 0) return stillConnected;
98
104
  await sleep(Math.min(250, sleepRemaining));
99
- remaining = deadline - now();
100
- return remaining > 0 && confirmDisconnected();
105
+ return deadline - now() > 0 ? confirmDisconnected() : stillConnected;
101
106
  };
102
- if (await confirmDisconnected()) {
107
+ const confirmed = await confirmDisconnected();
108
+ if (confirmed === true) {
103
109
  store.commitStop(guard, true, "VPN stop confirmed disconnected.", now());
104
110
  return;
105
111
  }
106
- evidence = "VPN status failed, stayed connected, or was unparseable after stop.";
112
+ evidence = confirmed;
107
113
  }
108
114
  } else {
109
115
  evidence = "VPN disconnect deadline expired before a command could safely start.";
@@ -742,6 +742,8 @@ export const runWithProfilePrerequisites = <A, E, CommandError>(
742
742
  runCommand: PrerequisiteCommandRunner<CommandError>,
743
743
  effect: Effect.Effect<A, E, never>,
744
744
  options?: {
745
+ /** Caller proved the target is already reachable: skip the VPN entirely (no status, no lease). */
746
+ alreadySatisfied?: boolean;
745
747
  tryWithoutPrerequisites?: boolean;
746
748
  runGuardianInProcess?: boolean;
747
749
  guardianSpawn?: GuardianSpawner;
@@ -750,7 +752,7 @@ export const runWithProfilePrerequisites = <A, E, CommandError>(
750
752
  const vpnPrerequisites = normalizeProfilePrerequisites(profile).filter(
751
753
  (prerequisite) => prerequisite.type === "vpn",
752
754
  );
753
- if (vpnPrerequisites.length === 0) return effect;
755
+ if (vpnPrerequisites.length === 0 || options?.alreadySatisfied === true) return effect;
754
756
 
755
757
  return Effect.gen(function* () {
756
758
  const tryDirect = () => effect.pipe(Effect.result);