Skip to content

Commit 8fc0635

Browse files
committed
bugfix-319-setup-crash-on-repository-with-no-issues: Refactor agent documentation by moving use case flows to a dedicated file and enhancing Bugbot details with key paths and configuration.
1 parent 3deee7c commit 8fc0635

8 files changed

Lines changed: 240 additions & 116 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
Full documentation: **[docs.page/vypdev/copilot](https://docs.page/vypdev/copilot)**
1212

13+
*Maintains state and configuration persisted in issue descriptions for seamless workflow automation.*
14+
1315
---
1416

1517
## Documentation index

_agent/docs/architecture.md

Lines changed: 0 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -35,112 +35,3 @@ description: Project architecture, entry points, and use case flows.
3535
| Repos | `src/data/repository/` | branch_repository, issue_repository, workflow_repository, ai_repository (OpenCode), file_repository, project_repository |
3636
| Config | `src/utils/constants.ts` | INPUT_KEYS, ACTIONS, defaults |
3737
| Metadata | `action.yml` | Action inputs and defaults |
38-
39-
## Schematic overview of use case flows
40-
41-
Entry point: `mainRun(execution)` in `src/actions/common_action.ts`. After `execution.setup()` and optionally `waitForPreviousRuns`, the dispatch is:
42-
43-
```
44-
mainRun
45-
├── runnedByToken && singleAction → SingleActionUseCase (only if validSingleAction)
46-
├── issueNumber === -1 → SingleActionUseCase (only if isSingleActionWithoutIssue) or skip
47-
├── welcome → log boxen and continue
48-
└── try:
49-
├── isSingleAction → SingleActionUseCase
50-
├── isIssue → issue.isIssueComment ? IssueCommentUseCase : IssueUseCase
51-
├── isPullRequest → pullRequest.isPullRequestReviewComment ? PullRequestReviewCommentUseCase : PullRequestUseCase
52-
├── isPush → CommitUseCase
53-
└── else → core.setFailed
54-
```
55-
56-
### 1. IssueUseCase (`on: issues`, not a comment)
57-
58-
**Step order:**
59-
60-
1. **CheckPermissionsUseCase** → if it fails (not allowed): CloseNotAllowedIssueUseCase and return.
61-
2. **RemoveIssueBranchesUseCase** (only if `cleanIssueBranches`).
62-
3. **AssignMemberToIssueUseCase**
63-
4. **UpdateTitleUseCase**
64-
5. **UpdateIssueTypeUseCase**
65-
6. **LinkIssueProjectUseCase**
66-
7. **CheckPriorityIssueSizeUseCase**
67-
8. **PrepareBranchesUseCase** (if `isBranched`) **or** **RemoveIssueBranchesUseCase** (if not).
68-
9. **RemoveNotNeededBranchesUseCase**
69-
10. **DeployAddedUseCase** (deploy label)
70-
11. **DeployedAddedUseCase** (deployed label)
71-
12. If **issue.opened**:
72-
- If not release and not question/help → **RecommendStepsUseCase**
73-
- If question or help → **AnswerIssueHelpUseCase**
74-
75-
### 2. IssueCommentUseCase (`on: issue_comment`)
76-
77-
**Step order:**
78-
79-
1. **CheckIssueCommentLanguageUseCase** (translation)
80-
2. **DetectBugbotFixIntentUseCase** → payload: `isFixRequest`, `isDoRequest`, `targetFindingIds`, `context`, `branchOverride`
81-
3. **ProjectRepository.isActorAllowedToModifyFiles(owner, actor, token)** (permission to modify files)
82-
4. Branch A – **if runAutofix && allowed**:
83-
- **BugbotAutofixUseCase****runBugbotAutofixCommitAndPush** → if committed: **markFindingsResolved**
84-
5. Branch B – **if !runAutofix && canRunDoUserRequest && allowed**:
85-
- **DoUserRequestUseCase****runUserRequestCommitAndPush**
86-
6. **If no file-modifying action ran****ThinkUseCase**
87-
88-
### 3. PullRequestReviewCommentUseCase (`on: pull_request_review_comment`)
89-
90-
Same flow as **IssueCommentUseCase**, with:
91-
92-
- CheckIssueCommentLanguageUseCase → **CheckPullRequestCommentLanguageUseCase**
93-
- User comment: `param.pullRequest.commentBody`
94-
- DetectBugbotFixIntentUseCase may use **parent comment** (commentInReplyToId) in the prompt.
95-
96-
### 4. PullRequestUseCase (`on: pull_request`, not a review comment)
97-
98-
**Branches by PR state:**
99-
100-
- **pullRequest.isOpened**:
101-
1. UpdateTitleUseCase
102-
2. AssignMemberToIssueUseCase
103-
3. AssignReviewersToIssueUseCase
104-
4. LinkPullRequestProjectUseCase
105-
5. LinkPullRequestIssueUseCase
106-
6. SyncSizeAndProgressLabelsFromIssueToPrUseCase
107-
7. CheckPriorityPullRequestSizeUseCase
108-
8. If AI PR description: **UpdatePullRequestDescriptionUseCase**
109-
110-
- **pullRequest.isSynchronize** (new pushes):
111-
- If AI PR description: **UpdatePullRequestDescriptionUseCase**
112-
113-
- **pullRequest.isClosed && isMerged**:
114-
- **CloseIssueAfterMergingUseCase**
115-
116-
### 5. CommitUseCase (`on: push`)
117-
118-
**Precondition:** `param.commit.commits.length > 0` (if 0, return with no steps).
119-
120-
**Order:**
121-
122-
1. **NotifyNewCommitOnIssueUseCase**
123-
2. **CheckChangesIssueSizeUseCase**
124-
3. **CheckProgressUseCase** (OpenCode: progress + size labels on issue and PRs)
125-
4. **DetectPotentialProblemsUseCase** (Bugbot: detection, publish to issue/PR, resolved markers)
126-
127-
### 6. SingleActionUseCase
128-
129-
Invoked when:
130-
- `runnedByToken && isSingleAction && validSingleAction`, or
131-
- `issueNumber === -1 && isSingleAction && isSingleActionWithoutIssue`, or
132-
- `isSingleAction` in the main try block.
133-
134-
**Dispatch by action (one per run):**
135-
136-
| Action | Use case |
137-
|--------|----------|
138-
| `deployed_action` | DeployedActionUseCase |
139-
| `publish_github_action` | PublishGithubActionUseCase |
140-
| `create_release` | CreateReleaseUseCase |
141-
| `create_tag` | CreateTagUseCase |
142-
| `think_action` | ThinkUseCase |
143-
| `initial_setup` | InitialSetupUseCase |
144-
| `check_progress_action` | CheckProgressUseCase |
145-
| `detect_potential_problems_action` | DetectPotentialProblemsUseCase |
146-
| `recommend_steps_action` | RecommendStepsUseCase |

_agent/docs/bugbot.md

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
---
22
name: Bugbot
3-
description: Detailed technical reference for Bugbot (detection, markers, context, intent, autofix, do user request, permissions).
3+
description: Detailed technical reference for Bugbot (detection, markers, context, intent, autofix, do user request, permissions)
44
---
55

66
# Bugbot – technical reference
77

88
Bugbot has two main modes: **detection** (on push or single action) and **fix/do** (on issue comment or PR review comment). All Bugbot code lives under `src/usecase/steps/commit/bugbot/` and `src/usecase/steps/commit/` (DetectPotentialProblemsUseCase, user_request_use_case).
99

10+
---
11+
1012
## 1. Detection flow (push or single action)
1113

1214
**Entry:** `CommitUseCase` (on push) calls `DetectPotentialProblemsUseCase`; or `SingleActionUseCase` when action is `detect_potential_problems_action`.
@@ -21,6 +23,19 @@ Bugbot has two main modes: **detection** (on push or single action) and **fix/do
2123
6. **Mark resolved:** `markFindingsResolved(execution, context, resolvedFindingIds, normalizedResolvedIds)` – for each existing finding in context whose id is in resolved set, update issue comment (and PR review comment if any) via `replaceMarkerInBody` to set `resolved:true`; if PR comment, call `resolveReviewThread` when applicable.
2224
7. **Publish:** `publishFindings(execution, context, toPublish, overflowCount?, overflowTitles?)` – for each finding: add or update **issue comment** (always); add or update **PR review comment** only when `finding.file` is in `prContext.prFiles` (using `pathToFirstDiffLine` when finding has no line). Each comment body is built with `buildCommentBody(finding, resolved)` and includes the **marker** `<!-- copilot-bugbot finding_id:"id" resolved:false -->`. Overflow: one extra issue comment summarizing excess findings.
2325

26+
**Key paths (detection):**
27+
28+
- `detect_potential_problems_use_case.ts` – orchestration
29+
- `load_bugbot_context_use_case.ts` – issue/PR comments, markers, previousFindingsBlock, prContext
30+
- `build_bugbot_prompt.ts` – prompt for plan agent (task 1: new findings, task 2: resolved ids)
31+
- `schema.ts` – BUGBOT_RESPONSE_SCHEMA (findings, resolved_finding_ids)
32+
- `marker.ts` – BUGBOT_MARKER_PREFIX, buildMarker, parseMarker, replaceMarkerInBody, extractTitleFromBody, buildCommentBody
33+
- `publish_findings_use_case.ts` – add/update issue comment, create/update PR review comment
34+
- `mark_findings_resolved_use_case.ts` – update comment body with resolved marker, resolve PR thread
35+
- `severity.ts`, `file_ignore.ts`, `path_validation.ts`, `limit_comments.ts`, `deduplicate_findings.ts`
36+
37+
---
38+
2439
## 2. Marker format and context
2540

2641
**Marker:** Hidden HTML comment in every finding comment (issue and PR):
@@ -31,6 +46,14 @@ Bugbot has two main modes: **detection** (on push or single action) and **fix/do
3146
- **Build:** `buildMarker(findingId, resolved)`. IDs are sanitized (`sanitizeFindingIdForMarker`) so they cannot break HTML (no `-->`, `<`, `>`, newlines, etc.).
3247
- **Update:** `replaceMarkerInBody(body, findingId, newResolved)` – used when marking a finding as resolved (same comment, body updated with `resolved:true`).
3348

49+
**Context (`BugbotContext`):**
50+
51+
- `existingByFindingId[id]`: `{ issueCommentId?, prCommentId?, prNumber?, resolved }` – from parsing all issue + PR comments for markers.
52+
- `issueComments`: raw list from API (for body when building previousFindingsBlock / unresolvedFindingsWithBody).
53+
- `openPrNumbers`, `previousFindingsBlock`, `prContext` (prHeadSha, prFiles, pathToFirstDiffLine), `unresolvedFindingsWithBody`: `{ id, fullBody }[]` for findings that are not resolved (body truncated to MAX_FINDING_BODY_LENGTH when loading).
54+
55+
---
56+
3457
## 3. Fix intent and file-modifying actions (issue comment / PR review comment)
3558

3659
**Entry:** `IssueCommentUseCase` or `PullRequestReviewCommentUseCase` (after language check).
@@ -62,3 +85,44 @@ Bugbot has two main modes: **detection** (on push or single action) and **fix/do
6285
- If success: `runUserRequestCommitAndPush(execution, { branchOverride })` – same verify/checkout/add/commit/push with message `chore(#N): apply user request` or `chore: apply user request`.
6386

6487
5. **Think** (when no file-modifying action ran): `ThinkUseCase.invoke(param)` – answers the user (e.g. question).
88+
89+
**Key paths (fix/do):**
90+
91+
- `detect_bugbot_fix_intent_use_case.ts` – intent detection, branch resolution for issue_comment
92+
- `build_bugbot_fix_intent_prompt.ts` – prompt for is_fix_request / is_do_request / target_finding_ids
93+
- `bugbot_fix_intent_payload.ts` – getBugbotFixIntentPayload, canRunBugbotAutofix, canRunDoUserRequest
94+
- `schema.ts` – BUGBOT_FIX_INTENT_RESPONSE_SCHEMA (is_fix_request, target_finding_ids, is_do_request)
95+
- `bugbot_autofix_use_case.ts` – build prompt, copilotMessage (build agent)
96+
- `build_bugbot_fix_prompt.ts` – fix prompt (findings block, verify commands, truncate finding body to MAX_FINDING_BODY_LENGTH)
97+
- `bugbot_autofix_commit.ts` – runBugbotAutofixCommitAndPush, runUserRequestCommitAndPush (checkout, verify commands max 20, git config, add, commit, push)
98+
- `user_request_use_case.ts` – DoUserRequestUseCase, buildUserRequestPrompt
99+
- `mark_findings_resolved_use_case.ts` – update issue/PR comment with resolved marker
100+
- `project_repository.ts` – isActorAllowedToModifyFiles
101+
102+
---
103+
104+
## 4. Configuration (inputs / Ai model)
105+
106+
- **bugbot-severity:** Minimum severity to publish (info, low, medium, high). Default low. `getBugbotMinSeverity()`, `normalizeMinSeverity`, `meetsMinSeverity`.
107+
- **bugbot-comment-limit:** Max individual finding comments per issue/PR (overflow gets one summary). Default 20. `getBugbotCommentLimit()`, `applyCommentLimit`.
108+
- **bugbot-fix-verify-commands:** Comma-separated commands run after autofix (and do user request) before commit. `getBugbotFixVerifyCommands()`, parsed with shell-quote; max 20 executed. Stored in `Ai` model; read in `github_action.ts` / `local_action.ts`.
109+
- **ai-ignore-files:** Exclude paths from detection (and from reporting). Used in buildBugbotPrompt and in filtering findings.
110+
111+
---
112+
113+
## 5. Constants and types
114+
115+
- `BUGBOT_MARKER_PREFIX`: `'copilot-bugbot'`
116+
- `BUGBOT_MAX_COMMENTS`: 20 (default limit)
117+
- `MAX_FINDING_BODY_LENGTH`: 12000 (truncation when loading context and in build_bugbot_fix_prompt)
118+
- `MAX_VERIFY_COMMANDS`: 20 (in bugbot_autofix_commit)
119+
- Types: `BugbotContext`, `BugbotFinding` (id, title, description, file?, line?, severity?, suggestion?), `UnresolvedFindingSummary`, `BugbotFixIntentPayload`.
120+
121+
---
122+
123+
## 6. Sanitization and safety
124+
125+
- **User comment in prompts:** `sanitizeUserCommentForPrompt(raw)` – trim, escape backslashes, replace `"""`, truncate 4000 with no lone trailing backslash.
126+
- **Finding body in prompts:** `truncateFindingBody(body, MAX_FINDING_BODY_LENGTH)` with suffix `[... truncated for length ...]` (used in load_bugbot_context and build_bugbot_fix_prompt).
127+
- **Verify commands:** Parsed with shell-quote; no shell operators (;, |, etc.); max 20 run.
128+
- **Path:** `isSafeFindingFilePath` (no null byte, no `..`, no absolute); PR review comment only if file in `prFiles`.

_agent/docs/code-conventions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
name: CodeConventions
3-
description: Coding standards, logging, and adding new inputs.
2+
name: Code Conventions
3+
description: Copilot – coding conventions and where to change things
44
---
55

66
# Code Conventions

_agent/docs/commit-messages.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
name: CommitMessages
3-
description: Specific nomenclature and branch-prefix requirements for commits.
2+
name: Commit Messages
3+
description: Commit message nomenclature (prefix = current branch)
44
---
55

66
# Commit messages

_agent/docs/project-context.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
name: ProjectContext
3-
description: High-level overview, common commands, and ignore paths.
2+
name: Project Context
3+
description: Copilot – quick read, commands, and where to find more
44
---
55

66
# Copilot – Project Context
@@ -33,3 +33,8 @@ npm run lint:fix
3333

3434
- **`build/`** – Generated output; do not edit or run tests/lint against it.
3535
- **`.agent-sessions/`** – Session data; ignore unless debugging.
36+
37+
## Other rules
38+
39+
- **Architecture & paths**: see `architecture.md` (entry points, use cases, single actions, key files).
40+
- **Code conventions**: see `code-conventions.md` (logger, constants, adding inputs, ncc).

0 commit comments

Comments
 (0)