opencode-magi 0.9.0 → 0.11.0

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.
Files changed (126) hide show
  1. package/README.ja.md +254 -0
  2. package/README.md +37 -34
  3. package/dist/commands.js +11 -9
  4. package/dist/config/index.js +2 -0
  5. package/dist/config/resolve.js +120 -248
  6. package/dist/config/validate.js +103 -1100
  7. package/dist/constant.js +135 -0
  8. package/dist/graphql/index.generated.js +125 -0
  9. package/dist/graphql/index.js +49 -0
  10. package/dist/index.js +12 -800
  11. package/dist/magi.js +357 -0
  12. package/dist/permissions/common.json +22 -22
  13. package/dist/permissions/editor.json +12 -12
  14. package/dist/prompts/index.js +98 -0
  15. package/dist/prompts/merge/ci-classification/output-contract.md +22 -0
  16. package/dist/prompts/merge/ci-classification/task.md +10 -0
  17. package/dist/prompts/merge/ci-classification/validate.json +20 -0
  18. package/dist/prompts/merge/conflict/output-contract.md +12 -0
  19. package/dist/prompts/merge/conflict/task.md +9 -0
  20. package/dist/prompts/merge/conflict/validate.json +4 -0
  21. package/dist/prompts/merge/edit/output-contract.md +26 -0
  22. package/dist/prompts/merge/edit/task.md +10 -0
  23. package/dist/prompts/merge/edit/validate.json +60 -0
  24. package/dist/prompts/review/ci-classification/output-contract.md +21 -0
  25. package/dist/prompts/review/ci-classification/task.md +7 -0
  26. package/dist/prompts/review/ci-classification/validate.json +20 -0
  27. package/dist/prompts/review/close-reconsideration/output-contract.md +21 -0
  28. package/dist/prompts/review/close-reconsideration/task.md +6 -0
  29. package/dist/prompts/review/close-reconsideration/validate.json +44 -0
  30. package/dist/prompts/review/comment/output-contract.md +11 -0
  31. package/dist/prompts/review/comment/task.md +3 -0
  32. package/dist/prompts/review/comment/validate.json +8 -0
  33. package/dist/prompts/review/finding-validation/output-contract.md +25 -0
  34. package/dist/prompts/{templates/review/finding-validation.md → review/finding-validation/task.md} +2 -3
  35. package/dist/prompts/review/finding-validation/validate.json +21 -0
  36. package/dist/prompts/review/rereview/output-contract.md +30 -0
  37. package/dist/prompts/{templates/review/rereview.md → review/rereview/task.md} +8 -11
  38. package/dist/prompts/review/rereview/validate.json +87 -0
  39. package/dist/prompts/review/review/output-contract.md +25 -0
  40. package/dist/prompts/{templates/review/review.md → review/review/task.md} +2 -5
  41. package/dist/prompts/review/review/validate.json +54 -0
  42. package/dist/prompts/triage/acceptance/output-contract.md +16 -0
  43. package/dist/prompts/triage/acceptance/validate.json +23 -0
  44. package/dist/prompts/triage/category/output-contract.md +16 -0
  45. package/dist/prompts/triage/category/validate.json +23 -0
  46. package/dist/prompts/triage/comment-classification/output-contract.md +15 -0
  47. package/dist/prompts/triage/comment-classification/validate.json +28 -0
  48. package/dist/prompts/triage/create/output-contract.md +28 -0
  49. package/dist/prompts/triage/create/validate.json +73 -0
  50. package/dist/prompts/triage/deplicate/output-contract.md +16 -0
  51. package/dist/prompts/triage/deplicate/validate.json +20 -0
  52. package/dist/prompts/triage/existing/output-contract.md +16 -0
  53. package/dist/prompts/triage/existing/validate.json +13 -0
  54. package/dist/prompts/triage/reconsider/output-contract.md +16 -0
  55. package/dist/prompts/triage/reconsider/validate.json +23 -0
  56. package/dist/prompts/triage/signal/output-contract.md +19 -0
  57. package/dist/prompts/triage/signal/validate.json +18 -0
  58. package/dist/tools/clear/index.js +21 -0
  59. package/dist/tools/index.js +12 -0
  60. package/dist/tools/merge/action.js +47 -0
  61. package/dist/tools/merge/context.js +118 -0
  62. package/dist/tools/merge/editor.js +264 -0
  63. package/dist/tools/merge/index.js +151 -0
  64. package/dist/tools/merge/index.type.js +1 -0
  65. package/dist/tools/merge/merge.js +42 -0
  66. package/dist/tools/merge/report.js +73 -0
  67. package/dist/tools/review/action.js +429 -0
  68. package/dist/tools/review/check.js +295 -0
  69. package/dist/tools/review/context.js +258 -0
  70. package/dist/tools/review/index.js +104 -0
  71. package/dist/tools/review/index.type.js +1 -0
  72. package/dist/tools/review/report.js +143 -0
  73. package/dist/tools/review/review.js +145 -0
  74. package/dist/tools/review/reviewer.js +409 -0
  75. package/dist/tools/triage/index.js +16 -0
  76. package/dist/tools/validate/index.js +28 -0
  77. package/dist/utils/array.js +6 -0
  78. package/dist/utils/assertion.js +38 -0
  79. package/dist/utils/exec.js +14 -0
  80. package/dist/utils/fs.js +24 -0
  81. package/dist/utils/function.js +37 -0
  82. package/dist/utils/github.js +63 -0
  83. package/dist/utils/index.js +10 -0
  84. package/dist/utils/index.type.js +1 -0
  85. package/dist/utils/object.js +21 -0
  86. package/dist/utils/opencode.js +25 -0
  87. package/dist/utils/string.js +38 -0
  88. package/dist/utils/worker.js +30 -0
  89. package/package.json +20 -8
  90. package/schema.json +9 -7
  91. package/dist/config/load.js +0 -62
  92. package/dist/config/output.js +0 -25
  93. package/dist/config/worktree.js +0 -25
  94. package/dist/github/commands.js +0 -905
  95. package/dist/github/retry.js +0 -44
  96. package/dist/orchestrator/abort.js +0 -9
  97. package/dist/orchestrator/ci.js +0 -579
  98. package/dist/orchestrator/findings.js +0 -88
  99. package/dist/orchestrator/inline-comments.js +0 -73
  100. package/dist/orchestrator/majority.js +0 -62
  101. package/dist/orchestrator/merge.js +0 -1260
  102. package/dist/orchestrator/model.js +0 -216
  103. package/dist/orchestrator/pool.js +0 -15
  104. package/dist/orchestrator/report.js +0 -175
  105. package/dist/orchestrator/review-context.js +0 -342
  106. package/dist/orchestrator/review.js +0 -1478
  107. package/dist/orchestrator/run-manager.js +0 -2132
  108. package/dist/orchestrator/safety.js +0 -44
  109. package/dist/orchestrator/triage.js +0 -1370
  110. package/dist/prompts/compose.js +0 -473
  111. package/dist/prompts/contracts.js +0 -300
  112. package/dist/prompts/output.js +0 -401
  113. package/dist/prompts/templates/merge/ci-classification.md +0 -16
  114. package/dist/prompts/templates/merge/conflict.md +0 -10
  115. package/dist/prompts/templates/merge/edit.md +0 -15
  116. package/dist/prompts/templates/review/ci-classification.md +0 -9
  117. package/dist/prompts/templates/review/close-reconsideration.md +0 -6
  118. /package/dist/{types.js → config/index.type.js} +0 -0
  119. /package/dist/prompts/{templates/triage/acceptance.md → triage/acceptance/task.md} +0 -0
  120. /package/dist/prompts/{templates/triage/category.md → triage/category/task.md} +0 -0
  121. /package/dist/prompts/{templates/triage/comment-classification.md → triage/comment-classification/task.md} +0 -0
  122. /package/dist/prompts/{templates/triage/create.md → triage/create/task.md} +0 -0
  123. /package/dist/prompts/{templates/triage/duplicate.md → triage/deplicate/task.md} +0 -0
  124. /package/dist/prompts/{templates/triage/existing-pr.md → triage/existing/task.md} +0 -0
  125. /package/dist/prompts/{templates/triage/reconsider.md → triage/reconsider/task.md} +0 -0
  126. /package/dist/prompts/{templates/triage/signal.md → triage/signal/task.md} +0 -0
@@ -0,0 +1,135 @@
1
+ import { homedir } from "node:os";
2
+ import { join } from "node:path";
3
+ import commonPermissions from "./permissions/common.json" with { type: "json" };
4
+ export const CONFIG_PATH = {
5
+ GLOBAL: join(homedir(), ".config", "opencode", "magi.json"),
6
+ PROJECT: join(".opencode", "magi.json"),
7
+ };
8
+ export const DEFAULT_CONFIG = {
9
+ agents: {
10
+ permissions: commonPermissions,
11
+ },
12
+ clear: {
13
+ branch: true,
14
+ output: true,
15
+ session: true,
16
+ worktree: true,
17
+ },
18
+ github: {
19
+ host: "github.com",
20
+ owner: "",
21
+ repo: "",
22
+ retryApiAttempts: 3,
23
+ url: "",
24
+ },
25
+ language: "en",
26
+ merge: {
27
+ automation: {
28
+ close: false,
29
+ conflict: false,
30
+ merge: true,
31
+ },
32
+ checks: {
33
+ wait: true,
34
+ },
35
+ maxThreadResolutionCycles: 5,
36
+ },
37
+ mode: "single",
38
+ output: {
39
+ repairAttempts: 3,
40
+ },
41
+ review: {
42
+ automation: {
43
+ close: false,
44
+ merge: true,
45
+ },
46
+ checks: {
47
+ exclude: [],
48
+ retryFailedJobs: 3,
49
+ wait: true,
50
+ },
51
+ concurrency: {
52
+ reviewers: 3,
53
+ runs: 3,
54
+ },
55
+ merge: {
56
+ approvalPolicy: "majority",
57
+ auto: true,
58
+ deleteBranch: true,
59
+ method: "squash",
60
+ queue: false,
61
+ },
62
+ output: ".magi/runs/pr",
63
+ safety: {
64
+ allowAuthors: [],
65
+ blockedPaths: [],
66
+ requiredLabels: [],
67
+ },
68
+ worktree: ".magi/worktrees/pr",
69
+ },
70
+ triage: {
71
+ automation: {
72
+ close: false,
73
+ create: false,
74
+ label: [
75
+ { remove: ["triage"], when: { disposition: "accepted" } },
76
+ {
77
+ add: ["duplicate"],
78
+ remove: ["triage"],
79
+ when: { disposition: "duplicate" },
80
+ },
81
+ {
82
+ add: ["duplicate"],
83
+ remove: ["triage"],
84
+ when: { disposition: "already_handled" },
85
+ },
86
+ {
87
+ add: ["wontfix"],
88
+ remove: ["triage"],
89
+ when: { disposition: "rejected" },
90
+ },
91
+ {
92
+ add: ["invalid"],
93
+ remove: ["triage"],
94
+ when: { disposition: "invalid" },
95
+ },
96
+ { add: ["question"], when: { disposition: "needs_category" } },
97
+ { add: ["question"], when: { disposition: "needs_acceptance" } },
98
+ ],
99
+ merge: false,
100
+ review: false,
101
+ },
102
+ categories: [
103
+ {
104
+ description: "Something is broken or behaves incorrectly.",
105
+ id: "bug",
106
+ labels: ["bug"],
107
+ types: ["Bug"],
108
+ },
109
+ {
110
+ description: "Maintenance, refactoring, chores, or planned work.",
111
+ id: "task",
112
+ labels: ["task"],
113
+ types: ["Task"],
114
+ },
115
+ {
116
+ description: "New or improved user-facing capability.",
117
+ id: "feature",
118
+ labels: ["enhancement"],
119
+ types: ["Feature"],
120
+ },
121
+ ],
122
+ concurrency: {
123
+ runs: 3,
124
+ },
125
+ output: ".magi/runs/issue",
126
+ safety: {
127
+ allowAuthors: [],
128
+ allowMentionActors: [],
129
+ allowMentionRoles: ["AUTHOR", "OWNER", "MEMBER", "COLLABORATOR"],
130
+ blockedLabels: [],
131
+ requiredLabels: ["triage"],
132
+ },
133
+ worktree: ".magi/worktrees/issue",
134
+ },
135
+ };
@@ -0,0 +1,125 @@
1
+ import gql from 'graphql-tag';
2
+ export const ClosingIssuesDocument = gql `
3
+ query closingIssues($cursor: String, $owner: String!, $repo: String!, $pr: Int!) {
4
+ repository(owner: $owner, name: $repo) {
5
+ pullRequest(number: $pr) {
6
+ closingIssuesReferences(first: 50, after: $cursor) {
7
+ nodes {
8
+ author {
9
+ login
10
+ }
11
+ body
12
+ comments(last: 50) {
13
+ nodes {
14
+ author {
15
+ login
16
+ }
17
+ body
18
+ createdAt
19
+ databaseId
20
+ url
21
+ }
22
+ }
23
+ number
24
+ state
25
+ title
26
+ url
27
+ }
28
+ pageInfo {
29
+ endCursor
30
+ hasNextPage
31
+ }
32
+ }
33
+ }
34
+ }
35
+ }
36
+ `;
37
+ export const EnqueuePullRequestDocument = gql `
38
+ mutation enqueuePullRequest($id: ID!) {
39
+ enqueuePullRequest(input: {pullRequestId: $id}) {
40
+ mergeQueueEntry {
41
+ id
42
+ }
43
+ }
44
+ }
45
+ `;
46
+ export const MergeQueueStatusDocument = gql `
47
+ query mergeQueueStatus($owner: String!, $repo: String!, $pr: Int!) {
48
+ repository(owner: $owner, name: $repo) {
49
+ pullRequest(number: $pr) {
50
+ state
51
+ isInMergeQueue
52
+ mergeQueueEntry {
53
+ id
54
+ }
55
+ timelineItems(last: 1, itemTypes: REMOVED_FROM_MERGE_QUEUE_EVENT) {
56
+ nodes {
57
+ ... on RemovedFromMergeQueueEvent {
58
+ createdAt
59
+ reason
60
+ }
61
+ }
62
+ }
63
+ }
64
+ }
65
+ }
66
+ `;
67
+ export const ResolveReviewThreadDocument = gql `
68
+ mutation resolveReviewThread($threadId: ID!) {
69
+ resolveReviewThread(input: {threadId: $threadId}) {
70
+ thread {
71
+ id
72
+ }
73
+ }
74
+ }
75
+ `;
76
+ export const ReviewThreadsDocument = gql `
77
+ query reviewThreads($cursor: String, $owner: String!, $repo: String!, $pr: Int!) {
78
+ repository(owner: $owner, name: $repo) {
79
+ pullRequest(number: $pr) {
80
+ reviewThreads(first: 50, after: $cursor) {
81
+ nodes {
82
+ comments(last: 50) {
83
+ nodes {
84
+ author {
85
+ login
86
+ }
87
+ body
88
+ createdAt
89
+ databaseId
90
+ url
91
+ }
92
+ }
93
+ id
94
+ isResolved
95
+ line
96
+ path
97
+ }
98
+ pageInfo {
99
+ endCursor
100
+ hasNextPage
101
+ }
102
+ }
103
+ }
104
+ }
105
+ }
106
+ `;
107
+ export function getSdk(requester) {
108
+ return {
109
+ closingIssues(variables, options) {
110
+ return requester(ClosingIssuesDocument, variables, options);
111
+ },
112
+ enqueuePullRequest(variables, options) {
113
+ return requester(EnqueuePullRequestDocument, variables, options);
114
+ },
115
+ mergeQueueStatus(variables, options) {
116
+ return requester(MergeQueueStatusDocument, variables, options);
117
+ },
118
+ resolveReviewThread(variables, options) {
119
+ return requester(ResolveReviewThreadDocument, variables, options);
120
+ },
121
+ reviewThreads(variables, options) {
122
+ return requester(ReviewThreadsDocument, variables, options);
123
+ }
124
+ };
125
+ }
@@ -0,0 +1,49 @@
1
+ import { isObject } from "@/utils";
2
+ import { getSdk } from "./index.generated";
3
+ function isConnection(value) {
4
+ if (!value || !isObject(value))
5
+ return false;
6
+ return "nodes" in value && "pageInfo" in value;
7
+ }
8
+ function findConnection(value) {
9
+ if (isConnection(value))
10
+ return value;
11
+ if (!value || !isObject(value))
12
+ return undefined;
13
+ for (const child of Object.values(value)) {
14
+ const connection = findConnection(child);
15
+ if (connection)
16
+ return connection;
17
+ }
18
+ return undefined;
19
+ }
20
+ export function graphql(requester) {
21
+ const sdk = getSdk(requester);
22
+ const bound = Object.fromEntries(Object.entries(sdk).map(([key, req]) => [key, req.bind(sdk)]));
23
+ async function paginate(req, params) {
24
+ let cursor = params.cursor ?? null;
25
+ let result;
26
+ for (;;) {
27
+ const page = (await req({
28
+ ...params,
29
+ cursor,
30
+ }));
31
+ const connection = findConnection(page);
32
+ if (!connection)
33
+ return page;
34
+ if (!result) {
35
+ result = page;
36
+ }
37
+ else {
38
+ const target = findConnection(result);
39
+ target?.nodes?.push(...(connection.nodes ?? []));
40
+ }
41
+ if (!connection.pageInfo?.hasNextPage)
42
+ return result;
43
+ cursor = connection.pageInfo.endCursor ?? null;
44
+ if (!cursor)
45
+ throw new Error("GraphQL page was truncated");
46
+ }
47
+ }
48
+ return { ...bound, paginate };
49
+ }