@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,80 @@
1
+ export class DefaultHumanActionService {
2
+ humanActionStore;
3
+ stateStore;
4
+ artifactEvaluator;
5
+ tickScheduler;
6
+ eventStore;
7
+ constructor(humanActionStore, stateStore, artifactEvaluator, tickScheduler, eventStore) {
8
+ this.humanActionStore = humanActionStore;
9
+ this.stateStore = stateStore;
10
+ this.artifactEvaluator = artifactEvaluator;
11
+ this.tickScheduler = tickScheduler;
12
+ this.eventStore = eventStore;
13
+ }
14
+ async answer(workflowId, answers) {
15
+ const current = await this.humanActionStore.getCurrent(workflowId);
16
+ if (current) {
17
+ await this.humanActionStore.markResponded(current.id);
18
+ await this.humanActionStore.markConsumed(current.id);
19
+ }
20
+ await this.artifactEvaluator.answerQuestions(workflowId, answers);
21
+ await this.stateStore.updateWorkflow(workflowId, {
22
+ status: "in_progress",
23
+ });
24
+ await this.stateStore.updateRuntime(workflowId, {
25
+ waitingHumanActionId: null,
26
+ refinementAttempts: 0,
27
+ refinementEscalationReason: null,
28
+ });
29
+ await this.eventStore.append({
30
+ workflowId,
31
+ type: "human_action.resolved",
32
+ at: new Date().toISOString(),
33
+ payload: { actionType: "need_answers" },
34
+ });
35
+ await this.tickScheduler.requestTick(workflowId, "human answered");
36
+ }
37
+ async approve(workflowId) {
38
+ const current = await this.humanActionStore.getCurrent(workflowId);
39
+ if (current) {
40
+ await this.humanActionStore.markResponded(current.id);
41
+ await this.humanActionStore.markConsumed(current.id);
42
+ }
43
+ await this.stateStore.updateWorkflow(workflowId, {
44
+ approved: true,
45
+ status: "pending",
46
+ });
47
+ await this.stateStore.updateRuntime(workflowId, {
48
+ waitingHumanActionId: null,
49
+ });
50
+ await this.eventStore.append({
51
+ workflowId,
52
+ type: "human_action.resolved",
53
+ at: new Date().toISOString(),
54
+ payload: { actionType: "need_approval" },
55
+ });
56
+ await this.tickScheduler.requestTick(workflowId, "human approved");
57
+ }
58
+ async resume(workflowId) {
59
+ const current = await this.humanActionStore.getCurrent(workflowId);
60
+ if (current) {
61
+ await this.humanActionStore.markResponded(current.id);
62
+ await this.humanActionStore.markConsumed(current.id);
63
+ }
64
+ await this.stateStore.updateWorkflow(workflowId, {
65
+ status: "pending",
66
+ blockReason: null,
67
+ });
68
+ await this.stateStore.updateRuntime(workflowId, {
69
+ waitingHumanActionId: null,
70
+ recoveryState: "idle",
71
+ });
72
+ await this.eventStore.append({
73
+ workflowId,
74
+ type: "human_action.resolved",
75
+ at: new Date().toISOString(),
76
+ payload: { actionType: "blocked" },
77
+ });
78
+ await this.tickScheduler.requestTick(workflowId, "manual resume");
79
+ }
80
+ }
@@ -0,0 +1,9 @@
1
+ import type { HumanAction } from "../../../core/src/human-actions/human-action";
2
+ import type { HumanActionRecord } from "../../../core/src/human-actions/human-action-record";
3
+ export interface HumanActionStore {
4
+ create(action: HumanAction): Promise<HumanActionRecord>;
5
+ getCurrent(workflowId: string): Promise<HumanActionRecord | null>;
6
+ markPresented(actionId: string): Promise<void>;
7
+ markResponded(actionId: string): Promise<void>;
8
+ markConsumed(actionId: string): Promise<void>;
9
+ }
@@ -0,0 +1,11 @@
1
+ import type { WorkflowRuntimeState } from "../../../core/src/state/workflow-runtime-state";
2
+ import type { WorkflowState } from "../../../core/src/state/workflow-state";
3
+ export interface WorkflowStateStore {
4
+ getWorkflow(workflowId: string): Promise<WorkflowState | null>;
5
+ saveWorkflow(state: WorkflowState): Promise<void>;
6
+ updateWorkflow(workflowId: string, patch: Partial<WorkflowState>): Promise<WorkflowState>;
7
+ listWorkflows?(): Promise<WorkflowState[]>;
8
+ getRuntime(workflowId: string): Promise<WorkflowRuntimeState | null>;
9
+ saveRuntime(state: WorkflowRuntimeState): Promise<void>;
10
+ updateRuntime(workflowId: string, patch: Partial<WorkflowRuntimeState>): Promise<WorkflowRuntimeState>;
11
+ }
@@ -0,0 +1,4 @@
1
+ import type { SubtaskTracker } from "./subtask-tracker";
2
+ export declare class NoopSubtaskTracker implements SubtaskTracker {
3
+ hasRunningSubtasks(_workflowId: string): Promise<boolean>;
4
+ }
@@ -0,0 +1,5 @@
1
+ export class NoopSubtaskTracker {
2
+ async hasRunningSubtasks(_workflowId) {
3
+ return false;
4
+ }
5
+ }
@@ -0,0 +1,3 @@
1
+ export interface SubtaskTracker {
2
+ hasRunningSubtasks(workflowId: string): Promise<boolean>;
3
+ }
@@ -0,0 +1,31 @@
1
+ import type { Phase } from "../../../core/src/state/phase";
2
+ export interface WorkflowWorkspace {
3
+ baseDir(): string;
4
+ workflowsRoot(): string;
5
+ workflowConfigFile(): string;
6
+ workflowDir(workflowId: string): string;
7
+ artifactStateFile(workflowId: string): string;
8
+ humanActionFile(workflowId: string): string;
9
+ workflowStateFile(workflowId: string): string;
10
+ workflowRuntimeStateFile(workflowId: string): string;
11
+ sessionsFile(workflowId: string): string;
12
+ eventsFile(workflowId: string): string;
13
+ eventsIndexFile(workflowId: string): string;
14
+ phaseArtifactFile(workflowId: string, phase: Phase): string;
15
+ }
16
+ export declare class DefaultWorkflowWorkspace implements WorkflowWorkspace {
17
+ private readonly root;
18
+ constructor(root: string);
19
+ baseDir(): string;
20
+ workflowsRoot(): string;
21
+ workflowConfigFile(): string;
22
+ workflowDir(workflowId: string): string;
23
+ artifactStateFile(workflowId: string): string;
24
+ humanActionFile(workflowId: string): string;
25
+ workflowStateFile(workflowId: string): string;
26
+ workflowRuntimeStateFile(workflowId: string): string;
27
+ sessionsFile(workflowId: string): string;
28
+ eventsFile(workflowId: string): string;
29
+ eventsIndexFile(workflowId: string): string;
30
+ phaseArtifactFile(workflowId: string, phase: Phase): string;
31
+ }
@@ -0,0 +1,43 @@
1
+ import { join } from "node:path";
2
+ export class DefaultWorkflowWorkspace {
3
+ root;
4
+ constructor(root) {
5
+ this.root = root;
6
+ }
7
+ baseDir() {
8
+ return this.root;
9
+ }
10
+ workflowsRoot() {
11
+ return join(this.root, "workflows");
12
+ }
13
+ workflowConfigFile() {
14
+ return join(this.root, "workflow.json");
15
+ }
16
+ workflowDir(workflowId) {
17
+ return join(this.workflowsRoot(), workflowId);
18
+ }
19
+ artifactStateFile(workflowId) {
20
+ return join(this.workflowDir(workflowId), "artifact-state.json");
21
+ }
22
+ humanActionFile(workflowId) {
23
+ return join(this.workflowDir(workflowId), "human-action.json");
24
+ }
25
+ workflowStateFile(workflowId) {
26
+ return join(this.workflowDir(workflowId), "workflow-state.json");
27
+ }
28
+ workflowRuntimeStateFile(workflowId) {
29
+ return join(this.workflowDir(workflowId), "workflow-runtime-state.json");
30
+ }
31
+ sessionsFile(workflowId) {
32
+ return join(this.workflowDir(workflowId), "sessions.json");
33
+ }
34
+ eventsFile(workflowId) {
35
+ return join(this.workflowDir(workflowId), "events.ndjson");
36
+ }
37
+ eventsIndexFile(workflowId) {
38
+ return join(this.workflowDir(workflowId), "events.json");
39
+ }
40
+ phaseArtifactFile(workflowId, phase) {
41
+ return join(this.workflowDir(workflowId), `${phase}.md`);
42
+ }
43
+ }
@@ -0,0 +1 @@
1
+ export { workflowPlugin as default } from "./packages/runtime/src/plugin/workflow-plugin-entry";
package/dist/plugin.js ADDED
@@ -0,0 +1 @@
1
+ export { workflowPlugin as default } from "./packages/runtime/src/plugin/workflow-plugin-entry";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,175 @@
1
+ import { join } from "node:path";
2
+ import { createHarness } from "../packages/runtime/src/bootstrap/create-harness";
3
+ import { initializeWorkflow } from "../packages/runtime/src/bootstrap/initialize-workflow";
4
+ import { DefaultWorkflowCommandRunner } from "../packages/runtime/src/commands/default-workflow-command-runner";
5
+ import { formatWorkflowDoctorResult, formatWorkflowInstallResult } from "../packages/runtime/src/diagnostics/workflow-diagnostics-format";
6
+ import { runWorkflowDoctor } from "../packages/runtime/src/diagnostics/workflow-doctor";
7
+ import { runWorkflowInstall } from "../packages/runtime/src/install/workflow-installer";
8
+ import { renderHumanActionBlock } from "../packages/runtime/src/presentation/human-action-renderer";
9
+ import { renderWatchFrame } from "../packages/runtime/src/presentation/watch-renderer";
10
+ import { homedir } from "node:os";
11
+ const WORKFLOW_COMMANDS = new Set([
12
+ "workflow-open",
13
+ "workflow-attach",
14
+ "workflow-status",
15
+ "workflow-answer",
16
+ "workflow-approve",
17
+ "workflow-resume",
18
+ "workflow-back",
19
+ "workflow-doctor",
20
+ "workflow-install",
21
+ ]);
22
+ function normalizeCommand(command) {
23
+ if (!WORKFLOW_COMMANDS.has(command)) {
24
+ return command;
25
+ }
26
+ switch (command) {
27
+ case "workflow-open":
28
+ return "start";
29
+ case "workflow-attach":
30
+ return "attach";
31
+ case "workflow-status":
32
+ return "status";
33
+ case "workflow-answer":
34
+ return "answer";
35
+ case "workflow-approve":
36
+ return "approve";
37
+ case "workflow-resume":
38
+ return "resume";
39
+ case "workflow-back":
40
+ return "back";
41
+ case "workflow-doctor":
42
+ return "doctor";
43
+ case "workflow-install":
44
+ return "install";
45
+ default:
46
+ return command;
47
+ }
48
+ }
49
+ async function printSnapshot(harness, workflowId) {
50
+ const workflow = await harness.stateStore.getWorkflow(workflowId);
51
+ const runtime = await harness.stateStore.getRuntime(workflowId);
52
+ const humanAction = await harness.humanActionStore.getCurrent(workflowId);
53
+ if (!workflow) {
54
+ throw new Error(`Workflow not found: ${workflowId}`);
55
+ }
56
+ console.log(renderHumanActionBlock({ workflow, runtime, humanAction }));
57
+ }
58
+ async function watchWorkflow(harness, workflowId) {
59
+ await harness.attachService.attach(workflowId);
60
+ let lastFingerprint = "";
61
+ while (true) {
62
+ const workflow = await harness.stateStore.getWorkflow(workflowId);
63
+ const runtime = await harness.stateStore.getRuntime(workflowId);
64
+ const humanAction = await harness.humanActionStore.getCurrent(workflowId);
65
+ if (!workflow) {
66
+ throw new Error(`Workflow not found: ${workflowId}`);
67
+ }
68
+ const events = await harness.eventStore.list(workflowId);
69
+ const fingerprint = JSON.stringify({
70
+ workflow,
71
+ runtime,
72
+ humanAction,
73
+ eventCount: events.length,
74
+ });
75
+ if (fingerprint !== lastFingerprint) {
76
+ console.clear();
77
+ console.log(renderWatchFrame({
78
+ workflow,
79
+ runtime,
80
+ humanAction,
81
+ recentEvents: events,
82
+ attached: true,
83
+ modeLabel: "Autopilot",
84
+ }));
85
+ lastFingerprint = fingerprint;
86
+ }
87
+ if (workflow.phase === "done" || workflow.phase === "blocked") {
88
+ return;
89
+ }
90
+ await new Promise((resolve) => setTimeout(resolve, 500));
91
+ }
92
+ }
93
+ async function main() {
94
+ const [, , command, workflowId, payload] = process.argv;
95
+ const normalizedCommand = command ? normalizeCommand(command) : command;
96
+ const baseDir = join(process.cwd(), ".workflow-harness");
97
+ const harnessOptions = {
98
+ ...(process.env.OPENCODE_BASE_URL ? { opencodeBaseUrl: process.env.OPENCODE_BASE_URL } : {}),
99
+ ...(process.env.OPENCODE_SERVER_PASSWORD
100
+ ? { opencodePassword: process.env.OPENCODE_SERVER_PASSWORD }
101
+ : {}),
102
+ };
103
+ const harness = await createHarness(baseDir, harnessOptions);
104
+ const commandRunner = new DefaultWorkflowCommandRunner();
105
+ if (!normalizedCommand) {
106
+ throw new Error("Usage: bun run cli <start|status|watch|attach|answer|approve|resume|doctor|install|workflow-open|workflow-attach|workflow-status|workflow-answer|workflow-approve|workflow-resume|workflow-back|workflow-doctor|workflow-install> <workflowId> [payload]");
107
+ }
108
+ if (normalizedCommand === "install") {
109
+ const result = await runWorkflowInstall({
110
+ cwd: process.cwd(),
111
+ homeDir: homedir(),
112
+ });
113
+ console.log(formatWorkflowInstallResult(result));
114
+ return;
115
+ }
116
+ if (normalizedCommand === "doctor") {
117
+ const result = await runWorkflowDoctor(harness.workspace);
118
+ console.log(formatWorkflowDoctorResult(result));
119
+ return;
120
+ }
121
+ if (!workflowId) {
122
+ throw new Error("Usage: bun run cli <start|status|watch|attach|answer|approve|resume|doctor|workflow-open|workflow-attach|workflow-status|workflow-answer|workflow-approve|workflow-resume|workflow-back|workflow-doctor|workflow-install> <workflowId> [payload]");
123
+ }
124
+ if (normalizedCommand === "start") {
125
+ await initializeWorkflow({
126
+ workflowId,
127
+ stateStore: harness.stateStore,
128
+ artifactEvaluator: harness.artifactEvaluator,
129
+ });
130
+ await harness.sessionActivityMonitor.start(workflowId);
131
+ await harness.tickScheduler.requestTick(workflowId, "workflow started");
132
+ }
133
+ else if (normalizedCommand === "status") {
134
+ await printSnapshot(harness, workflowId);
135
+ return;
136
+ }
137
+ else if (normalizedCommand === "watch") {
138
+ await watchWorkflow(harness, workflowId);
139
+ return;
140
+ }
141
+ else if (normalizedCommand === "attach") {
142
+ await watchWorkflow(harness, workflowId);
143
+ return;
144
+ }
145
+ else if (WORKFLOW_COMMANDS.has(command)) {
146
+ const commandArgs = {
147
+ harness,
148
+ command: command,
149
+ workflowId,
150
+ ...(payload !== undefined ? { payload } : {}),
151
+ };
152
+ const result = await commandRunner.run(commandArgs);
153
+ console.log(result.output);
154
+ return;
155
+ }
156
+ else if (normalizedCommand === "back") {
157
+ console.log(`Returned from workflow channel for ${workflowId}. Your workflow continues and can be re-attached later.`);
158
+ return;
159
+ }
160
+ else if (normalizedCommand === "answer") {
161
+ const answers = payload ? JSON.parse(payload) : {};
162
+ await harness.humanActionService.answer(workflowId, answers);
163
+ }
164
+ else if (normalizedCommand === "approve") {
165
+ await harness.humanActionService.approve(workflowId);
166
+ }
167
+ else if (normalizedCommand === "resume") {
168
+ await harness.humanActionService.resume(workflowId);
169
+ }
170
+ else {
171
+ throw new Error(`Unknown command: ${command}`);
172
+ }
173
+ await printSnapshot(harness, workflowId);
174
+ }
175
+ void main();
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@fkqfkq123/opencode-autopilot",
3
+ "private": false,
4
+ "version": "0.1.0",
5
+ "type": "module",
6
+ "packageManager": "bun@1.3.5",
7
+ "main": "./dist/plugin.js",
8
+ "module": "./dist/plugin.js",
9
+ "types": "./dist/plugin.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/plugin.d.ts",
13
+ "import": "./dist/plugin.js"
14
+ },
15
+ "./cli": {
16
+ "types": "./dist/src/cli.d.ts",
17
+ "import": "./dist/src/cli.js"
18
+ },
19
+ "./runtime": {
20
+ "types": "./dist/packages/runtime/src/index.d.ts",
21
+ "import": "./dist/packages/runtime/src/index.js"
22
+ }
23
+ },
24
+ "files": [
25
+ "dist",
26
+ "README.md"
27
+ ],
28
+ "publishConfig": {
29
+ "access": "public"
30
+ },
31
+ "scripts": {
32
+ "build": "tsc -p tsconfig.build.json",
33
+ "build:release": "bun run scripts/build-release.ts",
34
+ "typecheck": "tsc -p tsconfig.json --noEmit",
35
+ "test": "bun test",
36
+ "cli": "bun run src/cli.ts",
37
+ "smoke:plugin": "bun run scripts/plugin-smoke-test.ts",
38
+ "smoke:install": "bun run scripts/install-smoke-test.ts",
39
+ "prepublishOnly": "bun run typecheck && bun test && bun run build"
40
+ },
41
+ "devDependencies": {
42
+ "@types/bun": "1.3.4",
43
+ "@types/node": "22.13.9",
44
+ "typescript": "5.8.2"
45
+ },
46
+ "dependencies": {
47
+ "zod": "4.1.8"
48
+ },
49
+ "keywords": [
50
+ "workflow",
51
+ "opencode",
52
+ "plugin",
53
+ "agent",
54
+ "harness"
55
+ ]
56
+ }