Skip to content

The Unified and Autonomous Development Platform

chore: Remove build investigation from build page

Robin Shen65ad1f1421c6
diff --git a/server-core/src/main/java/io/onedev/server/web/page/project/builds/detail/BuildDetailPage.html b/server-core/src/main/java/io/onedev/server/web/page/project/builds/detail/BuildDetailPage.html
index 4475da7059..964b6945b2 100644
--- a/server-core/src/main/java/io/onedev/server/web/page/project/builds/detail/BuildDetailPage.html
+++ b/server-core/src/main/java/io/onedev/server/web/page/project/builds/detail/BuildDetailPage.html
@@ -15,7 +15,6 @@
<a wicket:id="setDescription" class="btn btn-icon btn-light btn-hover-primary btn-xs mr-1" t:data-tippy-content="Set description"><wicket:svg href="info" class="icon"/></a>
<a wicket:id="uploadArtifacts" class="btn btn-icon btn-light btn-hover-primary btn-xs mr-1" t:data-tippy-content="Upload artifacts"><wicket:svg href="upload" class="icon"/></a>
<a wicket:id="terminal" t:data-tippy-content="Open terminal of current running step" class="subscription-required btn btn-icon btn-light btn-hover-primary btn-xs mr-1"><wicket:svg href="terminal" class="icon"/></a>
- <a wicket:id="errorInvestigation" t:data-tippy-content="Investigate build error with AI" class="btn btn-xs btn-light btn-hover-primary btn-icon mr-1"><wicket:svg href="research" class="icon"></wicket:svg></a>
</div>
</div>
<div class="card-toolbar">
diff --git a/server-core/src/main/java/io/onedev/server/web/page/project/builds/detail/BuildDetailPage.java b/server-core/src/main/java/io/onedev/server/web/page/project/builds/detail/BuildDetailPage.java
index fa5e902e12..936133e5bf 100644
--- a/server-core/src/main/java/io/onedev/server/web/page/project/builds/detail/BuildDetailPage.java
+++ b/server-core/src/main/java/io/onedev/server/web/page/project/builds/detail/BuildDetailPage.java
@@ -1,10 +1,6 @@
package io.onedev.server.web.page.project.builds.detail;
-import static io.onedev.server.ai.BuildHelper.getDetail;
-import static io.onedev.server.ai.ToolUtils.convertToJson;
-import static io.onedev.server.ai.ToolUtils.wrapForChat;
import static io.onedev.server.web.translation.Translation._T;
-import static java.util.concurrent.CompletableFuture.completedFuture;
import java.io.Serializable;
import java.text.MessageFormat;
@@ -12,16 +8,12 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
-import java.util.Map;
import java.util.Set;
-import java.util.concurrent.CompletableFuture;
import javax.inject.Inject;
import javax.persistence.EntityNotFoundException;
import org.apache.commons.lang3.StringUtils;
-import org.apache.shiro.authz.UnauthorizedException;
-import org.apache.shiro.subject.Subject;
import org.apache.wicket.Component;
import org.apache.wicket.Page;
import org.apache.wicket.RestartResponseException;
@@ -43,34 +35,20 @@ import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.request.flow.RedirectToUrlException;
import org.apache.wicket.request.mapper.parameter.PageParameters;
-import org.eclipse.jgit.lib.FileMode;
-import org.eclipse.jgit.lib.ObjectId;
-import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.collect.Sets;
-import dev.langchain4j.agent.tool.ToolSpecification;
-import io.onedev.server.ai.ChatTool;
-import io.onedev.server.ai.ChatToolAware;
-import io.onedev.server.ai.ToolExecutionResult;
-import io.onedev.server.ai.tools.GetBuildSpecEditInstructions;
-import io.onedev.server.ai.tools.code.GetFileContent;
-import io.onedev.server.ai.tools.code.QueryFilePaths;
-import io.onedev.server.buildspec.BuildSpec;
import io.onedev.server.buildspec.job.Job;
import io.onedev.server.buildspec.job.JobDependency;
import io.onedev.server.buildspec.param.spec.ParamSpec;
import io.onedev.server.buildspecmodel.inputspec.InputContext;
import io.onedev.server.data.migration.VersionedXmlDoc;
import io.onedev.server.event.project.build.BuildUpdated;
-import io.onedev.server.git.BlobIdent;
-import io.onedev.server.git.service.GitService;
import io.onedev.server.job.JobAuthorizationContext;
import io.onedev.server.job.JobAuthorizationContextAware;
import io.onedev.server.job.JobContext;
import io.onedev.server.job.JobService;
import io.onedev.server.job.JobTerminalService;
-import io.onedev.server.logging.LogService;
import io.onedev.server.model.Build;
import io.onedev.server.model.Build.Status;
import io.onedev.server.model.Project;
@@ -118,9 +96,7 @@ import io.onedev.server.web.util.Cursor;
import io.onedev.server.web.util.CursorSupport;
public abstract class BuildDetailPage extends ProjectPage
- implements InputContext, BuildAware, JobAuthorizationContextAware, ChatToolAware {
-
- private static final int MAX_PATCH_SIZE = 1024 * 1024;
+ implements InputContext, BuildAware, JobAuthorizationContextAware {
public static final String PARAM_BUILD = "build";
@@ -133,12 +109,6 @@ public abstract class BuildDetailPage extends ProjectPage
@Inject
private JobTerminalService terminalService;
- @Inject
- private LogService logService;
-
- @Inject
- private GitService gitService;
-
@Inject
private Set<PackSupport> packSupports;
@@ -365,23 +335,6 @@ public abstract class BuildDetailPage extends ProjectPage
}.setOutputMarkupId(true));
- add(new AjaxLink<Void>("errorInvestigation") {
-
- @Override
- public void onClick(AjaxRequestTarget target) {
- getAssistant().show(target, "Investigate why this build failed. Display in " + getSession().getLocale().getDisplayLanguage());
- }
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- setVisible(getBuild().isFailed()
- && SecurityUtils.canReadCode(getProject())
- && !getAssistant().getEntitledAis().isEmpty());
- }
-
- });
-
add(new DropdownLink("promotions") {
@Override
@@ -756,159 +709,5 @@ public abstract class BuildDetailPage extends ProjectPage
public JobAuthorizationContext getJobAuthorizationContext() {
return new JobAuthorizationContext(getProject(), getBuild().getCommitId(), getBuild().getRequest());
}
-
- @Override
- public List<ChatTool> getChatTools() {
- var projectId = getProject().getId();
- var tools = new ArrayList<ChatTool>();
- tools.add(new ChatTool() {
-
- @Override
- public ToolSpecification getSpecification() {
- return ToolSpecification.builder()
- .name("getCurrentBuild")
- .description("Get info of current build in json format")
- .build();
- }
-
- @Override
- public CompletableFuture<ToolExecutionResult> execute(IPartialPageRequestHandler handler, Subject subject, JsonNode arguments) {
- return completedFuture(new ToolExecutionResult(convertToJson(getDetail(getProject(), getBuild())), false));
- }
-
- });
- if (getBuild().isFailed()) {
- var previousSuccessfulSimilarBuild = buildService.findPreviousSuccessfulSimilar(getBuild());
- tools.add(new ChatTool() {
-
- @Override
- public ToolSpecification getSpecification() {
- return ToolSpecification.builder()
- .name("getBuildFailureInvestigationInstructions")
- .description("Get instructions to investigate build failure")
- .build();
- }
-
- @Override
- public CompletableFuture<ToolExecutionResult> execute(IPartialPageRequestHandler handler, Subject subject, JsonNode arguments) {
- var instructions = """
- Follow below steps when investigate build failure:
- - Call 'getCurrentBuild' tool to get detail of current build
- - Call 'getBuildLog' tool to get the build log
- - Call 'getBuildSpec' tool to get content of CI/CD spec used to run the build
- """;
-
- if (previousSuccessfulSimilarBuild != null)
- instructions += "- If necessary, use tool 'getChangesSincePreviousSuccessfulBuild' to understand what has been changed since the previous successful build\n";
- instructions += "- If necessary, use tools 'queryFilePaths' and 'getFileContent' to search and read files mentioned in build log\n";
- instructions += "- If necessary, use tool 'getBuildSpecEditInstructions' to get instructions on how to edit CI/CD spec";
-
- return completedFuture(new ToolExecutionResult(instructions, true));
- }
-
- });
-
- if (previousSuccessfulSimilarBuild != null) {
- tools.add(new ChatTool() {
-
- @Override
- public ToolSpecification getSpecification() {
- return ToolSpecification.builder()
- .name("getChangesSincePreviousSuccessfulBuild")
- .description("Get file changes since previous successful build in json format")
- .build();
- }
-
- @Override
- public CompletableFuture<ToolExecutionResult> execute(IPartialPageRequestHandler handler, Subject subject, JsonNode arguments) {
- if (!SecurityUtils.canReadCode(subject, getProject()))
- throw new UnauthorizedException();
- var oldCommitId = previousSuccessfulSimilarBuild.getCommitId();
- var newCommitId = getBuild().getCommitId();
- var patch = gitService.getPatch(getProject(), oldCommitId, newCommitId);
- if (patch.length() > MAX_PATCH_SIZE)
- return completedFuture(new ToolExecutionResult(convertToJson(Map.of("successful", false, "failReason", "Patch is too large")), false));
- else
- return completedFuture(new ToolExecutionResult(convertToJson(Map.of("successful", true, "patch", patch)), false));
- }
-
- });
- }
- }
- if (getBuild().isFinished()) {
- tools.add(new ChatTool() {
-
- private static final int MAX_LOG_ENTRIES = 2000;
-
- @Override
- public ToolSpecification getSpecification() {
- return ToolSpecification.builder()
- .name("getBuildLog")
- .description("Get log of finished build. Will truncate to show recent lines if it is too long")
- .build();
- }
-
- @Override
- public CompletableFuture<ToolExecutionResult> execute(IPartialPageRequestHandler handler, Subject subject, JsonNode arguments) {
- if (!SecurityUtils.canAccessLog(subject, getBuild()))
- throw new UnauthorizedException();
- var snippet = logService.readLogSnippetReversely(getBuild().getLoggingSupport(), MAX_LOG_ENTRIES);
- var builder = new StringBuilder();
- for (var entry : snippet.entries) {
- builder.append(entry.render()).append("\n");
- }
- return completedFuture(new ToolExecutionResult(builder.toString(), false));
- }
-
- });
- }
- tools.add(new ChatTool() {
-
- @Override
- public ToolSpecification getSpecification() {
- return ToolSpecification.builder()
- .name("getBuildSpec")
- .description("Get content of CI/CD spec used to run the build")
- .build();
- }
-
- @Override
- public CompletableFuture<ToolExecutionResult> execute(IPartialPageRequestHandler handler, Subject subject, JsonNode arguments) {
- if (!SecurityUtils.canReadCode(subject, getProject()))
- throw new UnauthorizedException();
- var blobIdent = new BlobIdent(getBuild().getCommitId().name(), BuildSpec.BLOB_PATH, FileMode.REGULAR_FILE.getBits());
- return completedFuture(new ToolExecutionResult(getProject().getBlob(blobIdent, true).getText().getContent(), false));
- }
-
- });
- tools.add(wrapForChat(new GetBuildSpecEditInstructions(false)));
- tools.add(wrapForChat(new QueryFilePaths() {
-
- @Override
- protected Long getProjectId() {
- return projectId;
- }
-
- @Override
- protected ObjectId getCommitId() {
- return getBuild().getCommitId();
- }
-
- }));
- tools.add(wrapForChat(new GetFileContent(false) {
-
- @Override
- protected Long getProjectId() {
- return projectId;
- }
-
- @Override
- protected ObjectId getCommitId(boolean oldRevision) {
- return getBuild().getCommitId();
- }
-
- }));
- return tools;
- }
}