@fkqfkq123/opencode-autopilot 0.1.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 (107) hide show
  1. package/README.md +462 -0
  2. package/README.zh-CN.md +464 -0
  3. package/dist/packages/adapters/opencode/src/opencode-session-client.d.ts +188 -0
  4. package/dist/packages/adapters/opencode/src/opencode-session-client.js +382 -0
  5. package/dist/packages/core/src/artifacts/artifact-evaluator.d.ts +17 -0
  6. package/dist/packages/core/src/artifacts/artifact-evaluator.js +1 -0
  7. package/dist/packages/core/src/artifacts/artifact.d.ts +7 -0
  8. package/dist/packages/core/src/artifacts/artifact.js +1 -0
  9. package/dist/packages/core/src/human-actions/human-action-record.d.ts +10 -0
  10. package/dist/packages/core/src/human-actions/human-action-record.js +1 -0
  11. package/dist/packages/core/src/human-actions/human-action.d.ts +13 -0
  12. package/dist/packages/core/src/human-actions/human-action.js +1 -0
  13. package/dist/packages/core/src/human-actions/question.d.ts +8 -0
  14. package/dist/packages/core/src/human-actions/question.js +1 -0
  15. package/dist/packages/core/src/state/phase.d.ts +2 -0
  16. package/dist/packages/core/src/state/phase.js +1 -0
  17. package/dist/packages/core/src/state/workflow-runtime-state.d.ts +14 -0
  18. package/dist/packages/core/src/state/workflow-runtime-state.js +1 -0
  19. package/dist/packages/core/src/state/workflow-state.d.ts +13 -0
  20. package/dist/packages/core/src/state/workflow-state.js +1 -0
  21. package/dist/packages/core/src/transitions/default-phase-transition.d.ts +5 -0
  22. package/dist/packages/core/src/transitions/default-phase-transition.js +195 -0
  23. package/dist/packages/core/src/transitions/phase-transition.d.ts +22 -0
  24. package/dist/packages/core/src/transitions/phase-transition.js +1 -0
  25. package/dist/packages/core/src/transitions/transition-action.d.ts +20 -0
  26. package/dist/packages/core/src/transitions/transition-action.js +1 -0
  27. package/dist/packages/runtime/src/artifacts/file-system-artifact-evaluator.d.ts +36 -0
  28. package/dist/packages/runtime/src/artifacts/file-system-artifact-evaluator.js +1213 -0
  29. package/dist/packages/runtime/src/attach/attach-service.d.ts +15 -0
  30. package/dist/packages/runtime/src/attach/attach-service.js +31 -0
  31. package/dist/packages/runtime/src/bootstrap/create-harness.d.ts +33 -0
  32. package/dist/packages/runtime/src/bootstrap/create-harness.js +79 -0
  33. package/dist/packages/runtime/src/bootstrap/initialize-workflow.d.ts +8 -0
  34. package/dist/packages/runtime/src/bootstrap/initialize-workflow.js +33 -0
  35. package/dist/packages/runtime/src/commands/create-opencode-workflow-commands.d.ts +12 -0
  36. package/dist/packages/runtime/src/commands/create-opencode-workflow-commands.js +24 -0
  37. package/dist/packages/runtime/src/commands/default-workflow-command-runner.d.ts +4 -0
  38. package/dist/packages/runtime/src/commands/default-workflow-command-runner.js +343 -0
  39. package/dist/packages/runtime/src/commands/opencode-plugin-command-adapter.d.ts +20 -0
  40. package/dist/packages/runtime/src/commands/opencode-plugin-command-adapter.js +22 -0
  41. package/dist/packages/runtime/src/commands/workflow-command-runner.d.ts +19 -0
  42. package/dist/packages/runtime/src/commands/workflow-command-runner.js +1 -0
  43. package/dist/packages/runtime/src/commands/workflow-open-request.d.ts +10 -0
  44. package/dist/packages/runtime/src/commands/workflow-open-request.js +220 -0
  45. package/dist/packages/runtime/src/config/skill-registry.d.ts +15 -0
  46. package/dist/packages/runtime/src/config/skill-registry.js +108 -0
  47. package/dist/packages/runtime/src/config/workflow-config.d.ts +17 -0
  48. package/dist/packages/runtime/src/config/workflow-config.js +51 -0
  49. package/dist/packages/runtime/src/diagnostics/workflow-diagnostics-format.d.ts +4 -0
  50. package/dist/packages/runtime/src/diagnostics/workflow-diagnostics-format.js +70 -0
  51. package/dist/packages/runtime/src/diagnostics/workflow-doctor.d.ts +23 -0
  52. package/dist/packages/runtime/src/diagnostics/workflow-doctor.js +120 -0
  53. package/dist/packages/runtime/src/engine/default-workflow-engine.d.ts +9 -0
  54. package/dist/packages/runtime/src/engine/default-workflow-engine.js +337 -0
  55. package/dist/packages/runtime/src/engine/workflow-engine.d.ts +28 -0
  56. package/dist/packages/runtime/src/engine/workflow-engine.js +1 -0
  57. package/dist/packages/runtime/src/events/file-system-workflow-event-store.d.ts +8 -0
  58. package/dist/packages/runtime/src/events/file-system-workflow-event-store.js +28 -0
  59. package/dist/packages/runtime/src/events/workflow-event-store.d.ts +10 -0
  60. package/dist/packages/runtime/src/events/workflow-event-store.js +1 -0
  61. package/dist/packages/runtime/src/index.d.ts +4 -0
  62. package/dist/packages/runtime/src/index.js +4 -0
  63. package/dist/packages/runtime/src/install/workflow-installer.d.ts +15 -0
  64. package/dist/packages/runtime/src/install/workflow-installer.js +111 -0
  65. package/dist/packages/runtime/src/plugin/workflow-plugin-entry.d.ts +167 -0
  66. package/dist/packages/runtime/src/plugin/workflow-plugin-entry.js +340 -0
  67. package/dist/packages/runtime/src/presentation/human-action-renderer.d.ts +13 -0
  68. package/dist/packages/runtime/src/presentation/human-action-renderer.js +161 -0
  69. package/dist/packages/runtime/src/presentation/watch-renderer.d.ts +12 -0
  70. package/dist/packages/runtime/src/presentation/watch-renderer.js +17 -0
  71. package/dist/packages/runtime/src/recovery/basic-recovery-classifier.d.ts +4 -0
  72. package/dist/packages/runtime/src/recovery/basic-recovery-classifier.js +12 -0
  73. package/dist/packages/runtime/src/recovery/recovery-classifier.d.ts +4 -0
  74. package/dist/packages/runtime/src/recovery/recovery-classifier.js +1 -0
  75. package/dist/packages/runtime/src/scheduling/immediate-tick-scheduler.d.ts +9 -0
  76. package/dist/packages/runtime/src/scheduling/immediate-tick-scheduler.js +28 -0
  77. package/dist/packages/runtime/src/scheduling/tick-scheduler.d.ts +3 -0
  78. package/dist/packages/runtime/src/scheduling/tick-scheduler.js +1 -0
  79. package/dist/packages/runtime/src/sessions/file-system-session-coordinator.d.ts +19 -0
  80. package/dist/packages/runtime/src/sessions/file-system-session-coordinator.js +132 -0
  81. package/dist/packages/runtime/src/sessions/session-activity-monitor.d.ts +22 -0
  82. package/dist/packages/runtime/src/sessions/session-activity-monitor.js +112 -0
  83. package/dist/packages/runtime/src/sessions/session-coordinator.d.ts +24 -0
  84. package/dist/packages/runtime/src/sessions/session-coordinator.js +1 -0
  85. package/dist/packages/runtime/src/shared/json-file.d.ts +2 -0
  86. package/dist/packages/runtime/src/shared/json-file.js +19 -0
  87. package/dist/packages/runtime/src/state/file-system-human-action-store.d.ts +15 -0
  88. package/dist/packages/runtime/src/state/file-system-human-action-store.js +69 -0
  89. package/dist/packages/runtime/src/state/file-system-workflow-state-store.d.ts +15 -0
  90. package/dist/packages/runtime/src/state/file-system-workflow-state-store.js +59 -0
  91. package/dist/packages/runtime/src/state/human-action-service.d.ts +21 -0
  92. package/dist/packages/runtime/src/state/human-action-service.js +80 -0
  93. package/dist/packages/runtime/src/state/human-action-store.d.ts +9 -0
  94. package/dist/packages/runtime/src/state/human-action-store.js +1 -0
  95. package/dist/packages/runtime/src/state/workflow-state-store.d.ts +11 -0
  96. package/dist/packages/runtime/src/state/workflow-state-store.js +1 -0
  97. package/dist/packages/runtime/src/subtasks/noop-subtask-tracker.d.ts +4 -0
  98. package/dist/packages/runtime/src/subtasks/noop-subtask-tracker.js +5 -0
  99. package/dist/packages/runtime/src/subtasks/subtask-tracker.d.ts +3 -0
  100. package/dist/packages/runtime/src/subtasks/subtask-tracker.js +1 -0
  101. package/dist/packages/runtime/src/workspace/workflow-workspace.d.ts +31 -0
  102. package/dist/packages/runtime/src/workspace/workflow-workspace.js +43 -0
  103. package/dist/plugin.d.ts +1 -0
  104. package/dist/plugin.js +1 -0
  105. package/dist/src/cli.d.ts +1 -0
  106. package/dist/src/cli.js +175 -0
  107. package/package.json +56 -0
@@ -0,0 +1,195 @@
1
+ const MAX_SPEC_REFINEMENT_SELF_REPAIR_ATTEMPTS = 1;
2
+ function nextPhaseFor(current) {
3
+ if (current === "spec_refinement")
4
+ return "plan";
5
+ if (current === "plan")
6
+ return "develop";
7
+ if (current === "develop")
8
+ return "review";
9
+ if (current === "review")
10
+ return "test";
11
+ if (current === "test")
12
+ return "done";
13
+ return null;
14
+ }
15
+ function buildHumanAction(input) {
16
+ const { workflow, runtime, artifact } = input;
17
+ const createdAt = new Date().toISOString();
18
+ if (artifact.questions && artifact.questions.length > 0) {
19
+ const action = {
20
+ type: "need_answers",
21
+ workflowId: workflow.workflowId,
22
+ phase: workflow.phase,
23
+ reason: "Questions must be answered before continuing",
24
+ required: true,
25
+ questions: artifact.questions,
26
+ createdAt,
27
+ };
28
+ const summary = artifact.summary;
29
+ if (workflow.phase === "spec_refinement" && (runtime.refinementAttempts ?? 0) >= MAX_SPEC_REFINEMENT_SELF_REPAIR_ATTEMPTS) {
30
+ action.summary = summary
31
+ ? `${summary} | Autonomous refinement retry budget exhausted; human clarification required.`
32
+ : "Autonomous refinement retry budget exhausted; human clarification required.";
33
+ }
34
+ else if (summary) {
35
+ action.summary = summary;
36
+ }
37
+ return action;
38
+ }
39
+ if (workflow.phase === "plan" && artifact.requiresApproval && !workflow.approved) {
40
+ const action = {
41
+ type: "need_approval",
42
+ workflowId: workflow.workflowId,
43
+ phase: workflow.phase,
44
+ reason: "Plan is ready and requires approval before development",
45
+ required: true,
46
+ createdAt,
47
+ };
48
+ if (artifact.summary) {
49
+ action.summary = artifact.summary;
50
+ }
51
+ return action;
52
+ }
53
+ return null;
54
+ }
55
+ export class DefaultPhaseTransition {
56
+ async decide(input) {
57
+ const { workflow, runtime, currentHumanAction, session, artifact, hasRunningSubtasks } = input;
58
+ if (workflow.phase === "done" || workflow.status === "completed") {
59
+ return { type: "stop", reason: "Workflow already completed" };
60
+ }
61
+ if (workflow.phase === "blocked" || workflow.status === "blocked") {
62
+ return { type: "stop", reason: workflow.blockReason ?? "Workflow is blocked" };
63
+ }
64
+ if (currentHumanAction && currentHumanAction.status !== "consumed") {
65
+ return { type: "stop", reason: "Waiting for existing human action" };
66
+ }
67
+ if (hasRunningSubtasks) {
68
+ return { type: "stop", reason: "Background work still in progress" };
69
+ }
70
+ if (session.status === "failed") {
71
+ return { type: "recover", reason: "Relevant session failed" };
72
+ }
73
+ if (workflow.phase === "spec_refinement"
74
+ && artifact.questions
75
+ && artifact.questions.length > 0
76
+ && (runtime.refinementAttempts ?? 0) < MAX_SPEC_REFINEMENT_SELF_REPAIR_ATTEMPTS
77
+ && (session.status === "missing" || session.status === "idle" || session.status === "stale")) {
78
+ return {
79
+ type: "dispatch",
80
+ phase: workflow.phase,
81
+ reason: `Refinement self-repair attempt ${(runtime.refinementAttempts ?? 0) + 1}`,
82
+ };
83
+ }
84
+ if (workflow.phase === "plan" && workflow.status === "pending" && !workflow.approved) {
85
+ return {
86
+ type: "dispatch",
87
+ phase: workflow.phase,
88
+ reason: "Draft plan from approved refinement artifact",
89
+ };
90
+ }
91
+ const humanAction = buildHumanAction(input);
92
+ if (humanAction) {
93
+ return { type: "wait_human", action: humanAction };
94
+ }
95
+ if (workflow.phase === "plan" && workflow.approved) {
96
+ return {
97
+ type: "advance_phase",
98
+ nextPhase: "develop",
99
+ reason: "Plan was approved",
100
+ };
101
+ }
102
+ if (workflow.phase === "review") {
103
+ if (artifact.reportStatus === "pass") {
104
+ return {
105
+ type: "advance_phase",
106
+ nextPhase: "test",
107
+ reason: "Review passed",
108
+ };
109
+ }
110
+ if (artifact.reportStatus === "fail") {
111
+ if (artifact.hasBlockingSeverity) {
112
+ if (workflow.iteration + 1 >= workflow.maxIterations) {
113
+ return {
114
+ type: "recover",
115
+ reason: "Exceeded maxIterations while fixing review issues",
116
+ };
117
+ }
118
+ return {
119
+ type: "advance_phase",
120
+ nextPhase: "develop",
121
+ reason: "Review failed with blocker severity; loop back to develop",
122
+ };
123
+ }
124
+ const action = {
125
+ type: "blocked",
126
+ workflowId: workflow.workflowId,
127
+ phase: workflow.phase,
128
+ reason: "Review failed without blocker severity and needs human decision",
129
+ required: true,
130
+ createdAt: new Date().toISOString(),
131
+ };
132
+ if (artifact.summary) {
133
+ action.summary = artifact.summary;
134
+ }
135
+ return { type: "wait_human", action };
136
+ }
137
+ if (workflow.status === "pending") {
138
+ return {
139
+ type: "dispatch",
140
+ phase: workflow.phase,
141
+ reason: `Continue phase ${workflow.phase}`,
142
+ };
143
+ }
144
+ }
145
+ if (workflow.phase === "test") {
146
+ if (artifact.valid && artifact.missing.length === 0 && artifact.reportStatus === "pass") {
147
+ return {
148
+ type: "advance_phase",
149
+ nextPhase: "done",
150
+ reason: "Test passed",
151
+ };
152
+ }
153
+ if (artifact.reportStatus === "fail") {
154
+ const action = {
155
+ type: "blocked",
156
+ workflowId: workflow.workflowId,
157
+ phase: workflow.phase,
158
+ reason: "Test failed and needs human decision",
159
+ required: true,
160
+ createdAt: new Date().toISOString(),
161
+ };
162
+ if (artifact.summary) {
163
+ action.summary = artifact.summary;
164
+ }
165
+ return { type: "wait_human", action };
166
+ }
167
+ if (workflow.status === "pending") {
168
+ return {
169
+ type: "dispatch",
170
+ phase: workflow.phase,
171
+ reason: `Continue phase ${workflow.phase}`,
172
+ };
173
+ }
174
+ }
175
+ if (artifact.readyForNextPhase) {
176
+ const nextPhase = nextPhaseFor(workflow.phase);
177
+ if (nextPhase) {
178
+ return {
179
+ type: "advance_phase",
180
+ nextPhase,
181
+ reason: `${workflow.phase} is complete`,
182
+ };
183
+ }
184
+ return { type: "stop", reason: "No further phase available" };
185
+ }
186
+ if (session.status === "missing" || session.status === "idle" || session.status === "stale") {
187
+ return {
188
+ type: "dispatch",
189
+ phase: workflow.phase,
190
+ reason: `Continue phase ${workflow.phase}`,
191
+ };
192
+ }
193
+ return { type: "stop", reason: "Relevant session already running" };
194
+ }
195
+ }
@@ -0,0 +1,22 @@
1
+ import type { ArtifactEvaluation } from "../artifacts/artifact-evaluator";
2
+ import type { HumanActionRecord } from "../human-actions/human-action-record";
3
+ import type { WorkflowRuntimeState } from "../state/workflow-runtime-state";
4
+ import type { WorkflowState } from "../state/workflow-state";
5
+ import type { TransitionAction } from "./transition-action";
6
+ export interface RelevantSessionState {
7
+ sessionId: string | null;
8
+ relevant: boolean;
9
+ status: "missing" | "running" | "idle" | "failed" | "stale";
10
+ phaseMatches: boolean;
11
+ }
12
+ export interface PhaseTransitionInput {
13
+ workflow: WorkflowState;
14
+ runtime: WorkflowRuntimeState;
15
+ artifact: ArtifactEvaluation;
16
+ currentHumanAction: HumanActionRecord | null;
17
+ session: RelevantSessionState;
18
+ hasRunningSubtasks: boolean;
19
+ }
20
+ export interface PhaseTransition {
21
+ decide(input: PhaseTransitionInput): Promise<TransitionAction>;
22
+ }
@@ -0,0 +1,20 @@
1
+ import type { HumanAction } from "../human-actions/human-action";
2
+ import type { Phase } from "../state/phase";
3
+ export type TransitionAction = {
4
+ type: "dispatch";
5
+ phase: Phase;
6
+ reason: string;
7
+ } | {
8
+ type: "wait_human";
9
+ action: HumanAction;
10
+ } | {
11
+ type: "advance_phase";
12
+ nextPhase: Phase;
13
+ reason: string;
14
+ } | {
15
+ type: "recover";
16
+ reason: string;
17
+ } | {
18
+ type: "stop";
19
+ reason: string;
20
+ };
@@ -0,0 +1,36 @@
1
+ import type { ArtifactEvaluation, ArtifactEvaluator } from "../../../core/src/artifacts/artifact-evaluator";
2
+ import type { Phase } from "../../../core/src/state/phase";
3
+ import type { WorkflowState } from "../../../core/src/state/workflow-state";
4
+ import type { WorkflowWorkspace } from "../workspace/workflow-workspace";
5
+ export declare class FileSystemArtifactEvaluator implements ArtifactEvaluator {
6
+ private readonly workspace;
7
+ constructor(workspace: WorkflowWorkspace);
8
+ private normalizeUserRequest;
9
+ private buildRefinementClarification;
10
+ private buildRefinementConstraints;
11
+ private buildQuestionChecklist;
12
+ private defaultSpecSectionBodies;
13
+ private readSpecSectionBodies;
14
+ private buildSpecRefinementQuestionsFromSections;
15
+ private finalizeSpecSectionBodies;
16
+ private buildRefinementArtifactFromSections;
17
+ private autoFillSpecRefinementContent;
18
+ private buildRefinementArtifact;
19
+ private buildPlanArtifactFromRefinementContent;
20
+ private buildDevelopArtifactFromPlanContent;
21
+ private buildReviewArtifactFromDevelopContent;
22
+ private buildTestArtifactFromReviewContent;
23
+ private parseAnswerFromArtifact;
24
+ prepareForPhase(workflowId: string, phase: Phase, _previousPhase: Phase): Promise<void>;
25
+ ensureDefault(workflowId: string, userRequest?: string): Promise<void>;
26
+ evaluate(state: WorkflowState): Promise<ArtifactEvaluation>;
27
+ answerQuestions(workflowId: string, answers: Record<string, string>): Promise<void>;
28
+ markDevelopmentComplete(workflowId: string): Promise<void>;
29
+ setReviewReport(workflowId: string, status: "pass" | "fail", blocking?: boolean): Promise<void>;
30
+ setTestReport(workflowId: string, status: "pass" | "fail"): Promise<void>;
31
+ private getPhaseState;
32
+ private updatePhaseState;
33
+ private readPhaseArtifact;
34
+ private writePhaseArtifact;
35
+ private evaluatePhaseContent;
36
+ }