mcp-server-opencode 1.1.5 → 1.3.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 (94) hide show
  1. package/CHANGELOG.md +127 -0
  2. package/README.md +34 -5
  3. package/build/src/index.js +32 -15
  4. package/build/src/index.js.map +1 -1
  5. package/build/src/modules/shared/execution-report.d.ts +66 -0
  6. package/build/src/modules/shared/execution-report.d.ts.map +1 -0
  7. package/build/src/modules/shared/execution-report.js +407 -0
  8. package/build/src/modules/shared/execution-report.js.map +1 -0
  9. package/build/src/modules/shared/execution-usage.d.ts +50 -0
  10. package/build/src/modules/shared/execution-usage.d.ts.map +1 -0
  11. package/build/src/modules/shared/execution-usage.js +89 -0
  12. package/build/src/modules/shared/execution-usage.js.map +1 -0
  13. package/build/src/modules/shared/git-workspace.d.ts +34 -0
  14. package/build/src/modules/shared/git-workspace.d.ts.map +1 -0
  15. package/build/src/modules/shared/git-workspace.js +193 -0
  16. package/build/src/modules/shared/git-workspace.js.map +1 -0
  17. package/build/src/modules/shared/instructions.d.ts +8 -1
  18. package/build/src/modules/shared/instructions.d.ts.map +1 -1
  19. package/build/src/modules/shared/instructions.js +32 -27
  20. package/build/src/modules/shared/instructions.js.map +1 -1
  21. package/build/src/modules/shared/message-id.d.ts +3 -0
  22. package/build/src/modules/shared/message-id.d.ts.map +1 -0
  23. package/build/src/modules/shared/message-id.js +6 -0
  24. package/build/src/modules/shared/message-id.js.map +1 -0
  25. package/build/src/modules/shared/opencode-client.d.ts +42 -4
  26. package/build/src/modules/shared/opencode-client.d.ts.map +1 -1
  27. package/build/src/modules/shared/opencode-client.js +214 -38
  28. package/build/src/modules/shared/opencode-client.js.map +1 -1
  29. package/build/src/modules/shared/permission-scopes.d.ts +6 -0
  30. package/build/src/modules/shared/permission-scopes.d.ts.map +1 -0
  31. package/build/src/modules/shared/permission-scopes.js +60 -0
  32. package/build/src/modules/shared/permission-scopes.js.map +1 -0
  33. package/build/src/modules/shared/permissions.d.ts +110 -0
  34. package/build/src/modules/shared/permissions.d.ts.map +1 -0
  35. package/build/src/modules/shared/permissions.js +214 -0
  36. package/build/src/modules/shared/permissions.js.map +1 -0
  37. package/build/src/modules/shared/prompt-dispatch.d.ts +13 -0
  38. package/build/src/modules/shared/prompt-dispatch.d.ts.map +1 -0
  39. package/build/src/modules/shared/prompt-dispatch.js +34 -0
  40. package/build/src/modules/shared/prompt-dispatch.js.map +1 -0
  41. package/build/src/modules/shared/run-observer.d.ts +5 -0
  42. package/build/src/modules/shared/run-observer.d.ts.map +1 -0
  43. package/build/src/modules/shared/run-observer.js +421 -0
  44. package/build/src/modules/shared/run-observer.js.map +1 -0
  45. package/build/src/modules/shared/server-registry.d.ts +4 -0
  46. package/build/src/modules/shared/server-registry.d.ts.map +1 -1
  47. package/build/src/modules/shared/server-registry.js.map +1 -1
  48. package/build/src/modules/shared/task-registry.d.ts +75 -0
  49. package/build/src/modules/shared/task-registry.d.ts.map +1 -1
  50. package/build/src/modules/shared/task-registry.js +85 -0
  51. package/build/src/modules/shared/task-registry.js.map +1 -1
  52. package/build/src/modules/shared/usage-limits.d.ts +70 -0
  53. package/build/src/modules/shared/usage-limits.d.ts.map +1 -0
  54. package/build/src/modules/shared/usage-limits.js +296 -0
  55. package/build/src/modules/shared/usage-limits.js.map +1 -0
  56. package/build/src/modules/shared/workspace-manager.d.ts +25 -0
  57. package/build/src/modules/shared/workspace-manager.d.ts.map +1 -0
  58. package/build/src/modules/shared/workspace-manager.js +105 -0
  59. package/build/src/modules/shared/workspace-manager.js.map +1 -0
  60. package/build/src/modules/tools/cancel_task.d.ts.map +1 -1
  61. package/build/src/modules/tools/cancel_task.js +30 -1
  62. package/build/src/modules/tools/cancel_task.js.map +1 -1
  63. package/build/src/modules/tools/cleanup_workspace.d.ts +3 -0
  64. package/build/src/modules/tools/cleanup_workspace.d.ts.map +1 -0
  65. package/build/src/modules/tools/cleanup_workspace.js +82 -0
  66. package/build/src/modules/tools/cleanup_workspace.js.map +1 -0
  67. package/build/src/modules/tools/continue_task.d.ts.map +1 -1
  68. package/build/src/modules/tools/continue_task.js +116 -6
  69. package/build/src/modules/tools/continue_task.js.map +1 -1
  70. package/build/src/modules/tools/get_task_result.d.ts.map +1 -1
  71. package/build/src/modules/tools/get_task_result.js +125 -22
  72. package/build/src/modules/tools/get_task_result.js.map +1 -1
  73. package/build/src/modules/tools/get_task_status.d.ts.map +1 -1
  74. package/build/src/modules/tools/get_task_status.js +69 -6
  75. package/build/src/modules/tools/get_task_status.js.map +1 -1
  76. package/build/src/modules/tools/index.d.ts.map +1 -1
  77. package/build/src/modules/tools/index.js +2 -0
  78. package/build/src/modules/tools/index.js.map +1 -1
  79. package/build/src/modules/tools/list_agents.d.ts.map +1 -1
  80. package/build/src/modules/tools/list_agents.js +48 -7
  81. package/build/src/modules/tools/list_agents.js.map +1 -1
  82. package/build/src/modules/tools/start_server.d.ts.map +1 -1
  83. package/build/src/modules/tools/start_server.js +21 -1
  84. package/build/src/modules/tools/start_server.js.map +1 -1
  85. package/build/src/modules/tools/start_task.d.ts.map +1 -1
  86. package/build/src/modules/tools/start_task.js +218 -13
  87. package/build/src/modules/tools/start_task.js.map +1 -1
  88. package/build/src/modules/tools/stop_server.d.ts.map +1 -1
  89. package/build/src/modules/tools/stop_server.js +17 -0
  90. package/build/src/modules/tools/stop_server.js.map +1 -1
  91. package/build/src/modules/tools/wait_for_task.d.ts.map +1 -1
  92. package/build/src/modules/tools/wait_for_task.js +110 -24
  93. package/build/src/modules/tools/wait_for_task.js.map +1 -1
  94. package/package.json +4 -2
@@ -0,0 +1,193 @@
1
+ import { execFile } from "node:child_process";
2
+ import { randomUUID } from "node:crypto";
3
+ import { mkdir, realpath } from "node:fs/promises";
4
+ import { homedir } from "node:os";
5
+ import { join, relative, resolve } from "node:path";
6
+ import { promisify } from "node:util";
7
+ const execFileAsync = promisify(execFile);
8
+ const COMMAND_TIMEOUT_MS = 10_000;
9
+ const handles = new Map();
10
+ export class GitWorkspaceError extends Error {
11
+ code;
12
+ constructor(code, message) {
13
+ super(message);
14
+ this.code = code;
15
+ this.name = "GitWorkspaceError";
16
+ }
17
+ }
18
+ function gitRunner(executable) {
19
+ return async (cwd, args) => {
20
+ try {
21
+ const result = await execFileAsync(executable, args, {
22
+ cwd,
23
+ encoding: "utf8",
24
+ timeout: COMMAND_TIMEOUT_MS,
25
+ maxBuffer: 1024 * 1024,
26
+ windowsHide: true,
27
+ });
28
+ return result.stdout.trim();
29
+ }
30
+ catch (error) {
31
+ if (error.code === "ENOENT") {
32
+ throw new GitWorkspaceError("git_unavailable", "Git executable is unavailable");
33
+ }
34
+ throw error;
35
+ }
36
+ };
37
+ }
38
+ async function canonical(path) {
39
+ return realpath(resolve(path));
40
+ }
41
+ async function isDirty(directory, command) {
42
+ return (await command(directory, ["status", "--porcelain", "--untracked-files=all"])).length > 0;
43
+ }
44
+ function managedParent() {
45
+ return (process.env.OPENCODE_MCP_WORKSPACE_DIR ??
46
+ join(process.env.XDG_CACHE_HOME ?? join(homedir(), ".cache"), "opencode-mcp", "workspaces"));
47
+ }
48
+ export async function createGitWorkspace(sourcePath, options = {}) {
49
+ const command = options.gitRunner ?? gitRunner(options.gitExecutable ?? "git");
50
+ let sourceDirectory;
51
+ let repositoryDirectory;
52
+ try {
53
+ sourceDirectory = await canonical(sourcePath);
54
+ repositoryDirectory = await canonical(await command(sourceDirectory, ["rev-parse", "--show-toplevel"]));
55
+ }
56
+ catch (error) {
57
+ if (error instanceof GitWorkspaceError)
58
+ throw error;
59
+ if (error.code === "ENOENT") {
60
+ throw new GitWorkspaceError("not_repository", "Source directory does not exist or is not a Git repository");
61
+ }
62
+ throw new GitWorkspaceError("not_repository", "Source directory is not inside a Git repository");
63
+ }
64
+ const baseRef = options.baseRef ?? "HEAD";
65
+ let baseCommit;
66
+ try {
67
+ baseCommit = await command(repositoryDirectory, [
68
+ "rev-parse",
69
+ "--verify",
70
+ "--end-of-options",
71
+ `${baseRef}^{commit}`,
72
+ ]);
73
+ }
74
+ catch {
75
+ throw new GitWorkspaceError("invalid_base_ref", `Base ref is not a valid commit: ${baseRef}`);
76
+ }
77
+ const relativeExecutionDirectory = relative(repositoryDirectory, sourceDirectory);
78
+ if (relativeExecutionDirectory &&
79
+ !(await command(repositoryDirectory, [
80
+ "ls-tree",
81
+ "--full-tree",
82
+ baseCommit,
83
+ "--",
84
+ relativeExecutionDirectory,
85
+ ]))) {
86
+ throw new GitWorkspaceError("missing_execution_directory", `The selected base does not contain the requested source directory: ${relativeExecutionDirectory}`);
87
+ }
88
+ let sourceDirty;
89
+ let parentCanonical;
90
+ try {
91
+ sourceDirty = await isDirty(repositoryDirectory, command);
92
+ const parent = resolve(options.workspaceParent ?? managedParent());
93
+ await mkdir(parent, { recursive: true, mode: 0o700 });
94
+ parentCanonical = await canonical(parent);
95
+ }
96
+ catch (error) {
97
+ throw new GitWorkspaceError("provision_failed", `Unable to prepare managed workspace: ${String(error)}`);
98
+ }
99
+ const worktreeDirectory = join(parentCanonical, `workspace-${randomUUID()}`);
100
+ const executionDirectory = join(worktreeDirectory, relativeExecutionDirectory);
101
+ try {
102
+ await command(repositoryDirectory, [
103
+ "-c",
104
+ "core.hooksPath=/dev/null",
105
+ "worktree",
106
+ "add",
107
+ "--detach",
108
+ "--",
109
+ worktreeDirectory,
110
+ baseCommit,
111
+ ]);
112
+ const id = randomUUID();
113
+ const workspace = {
114
+ id,
115
+ sourceDirectory,
116
+ repositoryDirectory,
117
+ worktreeDirectory: await canonical(worktreeDirectory),
118
+ executionDirectory: await canonical(executionDirectory),
119
+ baseCommit,
120
+ sourceDirty,
121
+ managed: true,
122
+ };
123
+ handles.set(id, { workspace, runGit: command });
124
+ return workspace;
125
+ }
126
+ catch (error) {
127
+ // Leave any partial worktree for explicit inspection; never force-clean unknown state.
128
+ throw new GitWorkspaceError("provision_failed", `Unable to create managed worktree: ${String(error)}`);
129
+ }
130
+ }
131
+ export function describeGitWorkspace(handle) {
132
+ const record = handles.get(handle.id);
133
+ if (!record || record.workspace !== handle) {
134
+ throw new GitWorkspaceError("not_owned", "Workspace handle is not owned by this process");
135
+ }
136
+ return { ...record.workspace };
137
+ }
138
+ export async function removeGitWorkspace(handle, options = {}) {
139
+ const record = handles.get(handle.id);
140
+ if (!record || record.workspace !== handle) {
141
+ throw new GitWorkspaceError("not_owned", "Workspace handle is not owned by this process");
142
+ }
143
+ const owned = record.workspace;
144
+ const command = record.runGit;
145
+ try {
146
+ if ((await canonical(owned.sourceDirectory)) === owned.worktreeDirectory) {
147
+ throw new GitWorkspaceError("tampered", "Worktree path aliases the source directory");
148
+ }
149
+ let canonicalRepository;
150
+ let canonicalWorktree;
151
+ try {
152
+ canonicalRepository = await canonical(owned.repositoryDirectory);
153
+ canonicalWorktree = await canonical(owned.worktreeDirectory);
154
+ }
155
+ catch {
156
+ throw new GitWorkspaceError("tampered", "Workspace root or source repository is missing");
157
+ }
158
+ if (canonicalRepository !== owned.repositoryDirectory ||
159
+ canonicalWorktree !== owned.worktreeDirectory) {
160
+ throw new GitWorkspaceError("tampered", "Workspace paths changed since provisioning");
161
+ }
162
+ const common = await command(owned.worktreeDirectory, ["rev-parse", "--git-common-dir"]);
163
+ const sourceCommon = await command(owned.repositoryDirectory, [
164
+ "rev-parse",
165
+ "--git-common-dir",
166
+ ]);
167
+ const canonicalCommon = async (cwd, value) => canonical(resolve(cwd, value));
168
+ if ((await canonicalCommon(owned.worktreeDirectory, common)) !==
169
+ (await canonicalCommon(owned.repositoryDirectory, sourceCommon))) {
170
+ throw new GitWorkspaceError("tampered", "Worktree Git metadata no longer matches its source repository");
171
+ }
172
+ if (!options.discardChanges && (await isDirty(owned.worktreeDirectory, command))) {
173
+ throw new GitWorkspaceError("dirty", "Worktree has uncommitted or untracked changes");
174
+ }
175
+ await command(owned.repositoryDirectory, [
176
+ "-c",
177
+ "core.hooksPath=/dev/null",
178
+ "worktree",
179
+ "remove",
180
+ ...(options.discardChanges ? ["--force"] : []),
181
+ "--",
182
+ owned.worktreeDirectory,
183
+ ]);
184
+ handles.delete(owned.id);
185
+ return { status: "removed" };
186
+ }
187
+ catch (error) {
188
+ if (error instanceof GitWorkspaceError)
189
+ throw error;
190
+ throw new GitWorkspaceError("remove_failed", `Unable to safely remove worktree: ${String(error)}`);
191
+ }
192
+ }
193
+ //# sourceMappingURL=git-workspace.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git-workspace.js","sourceRoot":"","sources":["../../../../src/modules/shared/git-workspace.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAC1C,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAClC,MAAM,OAAO,GAAG,IAAI,GAAG,EAA0D,CAAC;AAqClF,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAExB,IAAI;IADtB,YACkB,IAA2B,EAC3C,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAC;oBAHC,IAAI;QAIpB,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAClC,CAAC;CACF;AAED,SAAS,SAAS,CAAC,UAAkB;IACnC,OAAO,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QACzB,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,UAAU,EAAE,IAAI,EAAE;gBACnD,GAAG;gBACH,QAAQ,EAAE,MAAM;gBAChB,OAAO,EAAE,kBAAkB;gBAC3B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YAC9C,IAAI;YACJ,KAAK,CAAC,iBAAiB;SACxB,CAAC,CAAC;QACH,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACzB,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;IAC/B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,iBAAiB;YAAE,MAAM,KAAK,CAAC;QACpD,MAAM,IAAI,iBAAiB,CACzB,eAAe,EACf,qCAAqC,MAAM,CAAC,KAAK,CAAC,EAAE,CACrD,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -1,2 +1,9 @@
1
- export declare const DELEGATE_TASK_INSTRUCTIONS = "You have access to the opencode-mcp server, which lets you delegate work to OpenCode agents. Follow this workflow whenever you delegate tasks:\n\nModel selection guide \u2014 pick the model per task via the optional \"model\" input of opencode_start_task ('providerID/modelID'). Match the model tier to the task's difficulty; do not burn a scarce frontier model on work a cheap model handles well. Usage quotas (requests per 5h) are noted as a scarcity signal \u2014 lower quota means reserve it for harder work.\n\nIMPORTANT \u2014 model IDs: the display names below are NOT model IDs. Never guess or construct a 'providerID/modelID' string from a display name. Always copy the exact provider id and model id verbatim from opencode_list_agents output (models.providers[].provider + '/' + an entry of its models list). The same model may be exposed under different providers (e.g. 'opencode-go/minimax-m3' vs 'opencode/some-other-model'), so the provider prefix cannot be inferred. If opencode_start_task returns status \"unknown_model\", pick a model from the available_models list it returns instead of retrying a guessed id.\n\nFrontier tier (scarce \u2014 architecture, hard debugging, critical decisions):\n- Grok 4.5 (~80 req/5h): top-end reasoning and coding; reserve for the hardest problems, cross-cutting refactors, and tasks where a wrong answer is expensive.\n- Kimi K3 (~140 req/5h): frontier reasoning with very strong agentic stability and tool calling over long sessions; best for long-horizon multi-step tasks that must not derail.\n\nHigh tier (strong daily drivers \u2014 feature implementation, non-trivial debugging, review):\n- GLM-5.2 (~880 req/5h): open-weight leader on coding and agentic-coding benchmarks (SWE-bench Pro ~62%); best default for substantial implementation and refactoring work.\n- Kimi K2.7 Code (~1,150 req/5h): coding-specialized; ~30% fewer thinking tokens, excellent precise tool invocation (MCP-heavy pipelines) and 4,000+ tool-call sequences; best for long agentic coding runs.\n\nMid tier (high volume \u2014 standard features, tests, medium complexity):\n- MiniMax M3 (~3,200 req/5h): frontier-adjacent coding plus 1M context and native multimodality; best for large-codebase context ingestion or tasks involving images/video.\n- MiMo-V2.5-Pro (~3,250 req/5h): strong general agentic capability and complex software engineering (high SWE-bench Pro rankings); good GLM alternative at higher volume.\n- DeepSeek V4 Pro (~3,450 req/5h): solid all-round flagship; good balance of capability and quota for everyday implementation tasks.\n- Qwen3.7 Plus (~4,300 req/5h): capable mid-range generalist; good for standard features and tests at volume.\n\nFast tier (near-unlimited \u2014 mechanical work, boilerplate, formatting, simple fixes, docs, exploration):\n- MiMo-V2.5 (~30,100 req/5h): lightweight reasoning model; better than Flash on agentic tasks, at some latency/token cost.\n- DeepSeek V4 Flash (~31,650 req/5h): cheapest and fastest, non-reasoning; best for mechanical edits, boilerplate, renames, doc updates, and quick lookups where latency matters.\n\nRule of thumb: exploration/mechanical \u2192 Fast tier; standard implementation \u2192 Mid tier; complex features and long agentic runs \u2192 High tier; architecture or hardest debugging \u2192 Frontier tier.\n\nWorkflow:\n1. Ensure an OpenCode server is running. If you don't already have a server_id from a previous opencode_start_server call, call opencode_start_server first.\n2. Call opencode_list_agents with the server_id to discover the available agents (native and custom) and the exact model ids. Agents may have a pre-assigned model (\"provider/model\"); you can still override it per task.\n3. For each task, call opencode_start_task with the server_id and the task's prompt. Optionally pass an agent name and/or a model override copied verbatim from opencode_list_agents \u2014 never a guessed id. Collect the returned task_id for every call.\n4. Wait for completion with opencode_wait_for_task:\n - Single task: mode \"all\" with the single task_id.\n - Multiple tasks, incremental results: call it repeatedly with mode \"any\", removing completed task_ids each time.\n - Multiple tasks, all at once: call it once with mode \"all\" and every task_id.\n5. Once a task is reported finished, call opencode_get_task_result for that task_id to retrieve its output.\n6. Use opencode_get_task_status only for quick, non-blocking checks on a task's progress (e.g. to report status to the user) \u2014 it does not replace opencode_wait_for_task or opencode_get_task_result.\n\nDo not call opencode_get_task_result before the task has finished, and prefer opencode_wait_for_task over polling opencode_get_task_status in a loop.";
1
+ /**
2
+ * Build the MCP server instructions.
3
+ *
4
+ * Only the spend budget is embedded from the daily snapshot: per-model quotas
5
+ * ride along with `opencode_list_agents`, keyed by the real model id, so they
6
+ * are deliberately not repeated here.
7
+ */
8
+ export declare function createDelegateTaskInstructions(): Promise<string>;
2
9
  //# sourceMappingURL=instructions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"instructions.d.ts","sourceRoot":"","sources":["../../../../src/modules/shared/instructions.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,0BAA0B,kpJAqC+G,CAAC"}
1
+ {"version":3,"file":"instructions.d.ts","sourceRoot":"","sources":["../../../../src/modules/shared/instructions.ts"],"names":[],"mappings":"AAKA;;;;;;GAMG;AACH,wBAAsB,8BAA8B,IAAI,OAAO,CAAC,MAAM,CAAC,CAiCtE"}
@@ -1,33 +1,31 @@
1
- export const DELEGATE_TASK_INSTRUCTIONS = `You have access to the opencode-mcp server, which lets you delegate work to OpenCode agents. Follow this workflow whenever you delegate tasks:
2
-
3
- Model selection guide — pick the model per task via the optional "model" input of opencode_start_task ('providerID/modelID'). Match the model tier to the task's difficulty; do not burn a scarce frontier model on work a cheap model handles well. Usage quotas (requests per 5h) are noted as a scarcity signal — lower quota means reserve it for harder work.
4
-
5
- IMPORTANT — model IDs: the display names below are NOT model IDs. Never guess or construct a 'providerID/modelID' string from a display name. Always copy the exact provider id and model id verbatim from opencode_list_agents output (models.providers[].provider + '/' + an entry of its models list). The same model may be exposed under different providers (e.g. 'opencode-go/minimax-m3' vs 'opencode/some-other-model'), so the provider prefix cannot be inferred. If opencode_start_task returns status "unknown_model", pick a model from the available_models list it returns instead of retrying a guessed id.
6
-
7
- Frontier tier (scarce — architecture, hard debugging, critical decisions):
8
- - Grok 4.5 (~80 req/5h): top-end reasoning and coding; reserve for the hardest problems, cross-cutting refactors, and tasks where a wrong answer is expensive.
9
- - Kimi K3 (~140 req/5h): frontier reasoning with very strong agentic stability and tool calling over long sessions; best for long-horizon multi-step tasks that must not derail.
10
-
11
- High tier (strong daily drivers — feature implementation, non-trivial debugging, review):
12
- - GLM-5.2 (~880 req/5h): open-weight leader on coding and agentic-coding benchmarks (SWE-bench Pro ~62%); best default for substantial implementation and refactoring work.
13
- - Kimi K2.7 Code (~1,150 req/5h): coding-specialized; ~30% fewer thinking tokens, excellent precise tool invocation (MCP-heavy pipelines) and 4,000+ tool-call sequences; best for long agentic coding runs.
14
-
15
- Mid tier (high volume — standard features, tests, medium complexity):
16
- - MiniMax M3 (~3,200 req/5h): frontier-adjacent coding plus 1M context and native multimodality; best for large-codebase context ingestion or tasks involving images/video.
17
- - MiMo-V2.5-Pro (~3,250 req/5h): strong general agentic capability and complex software engineering (high SWE-bench Pro rankings); good GLM alternative at higher volume.
18
- - DeepSeek V4 Pro (~3,450 req/5h): solid all-round flagship; good balance of capability and quota for everyday implementation tasks.
19
- - Qwen3.7 Plus (~4,300 req/5h): capable mid-range generalist; good for standard features and tests at volume.
20
-
21
- Fast tier (near-unlimited — mechanical work, boilerplate, formatting, simple fixes, docs, exploration):
22
- - MiMo-V2.5 (~30,100 req/5h): lightweight reasoning model; better than Flash on agentic tasks, at some latency/token cost.
23
- - DeepSeek V4 Flash (~31,650 req/5h): cheapest and fastest, non-reasoning; best for mechanical edits, boilerplate, renames, doc updates, and quick lookups where latency matters.
24
-
25
- Rule of thumb: exploration/mechanical → Fast tier; standard implementation → Mid tier; complex features and long agentic runs → High tier; architecture or hardest debugging → Frontier tier.
1
+ import { formatTierGuide, formatUsageLimits, getUsageLimits } from "./usage-limits.js";
2
+ const QUOTA_FALLBACK = `OpenCode Go usage limits — unavailable right now (the docs could not be fetched and no cached snapshot exists).
3
+ All models share a single dollar budget per 5h / week / month, so an expensive model drains it in far fewer requests.`;
4
+ /**
5
+ * Build the MCP server instructions.
6
+ *
7
+ * Only the spend budget is embedded from the daily snapshot: per-model quotas
8
+ * ride along with `opencode_list_agents`, keyed by the real model id, so they
9
+ * are deliberately not repeated here.
10
+ */
11
+ export async function createDelegateTaskInstructions() {
12
+ const limits = await getUsageLimits();
13
+ const quotaBlock = limits ? formatUsageLimits(limits) : QUOTA_FALLBACK;
14
+ return `You have access to the opencode-mcp server, which lets you delegate work to OpenCode agents. Follow this workflow whenever you delegate tasks:
15
+
16
+ ${quotaBlock}
17
+ Burning a scarce model on work a cheap model handles well is how a session runs out of budget in one shot. Default to the cheapest tier that can do the job and escalate only when the task actually demands it.
18
+
19
+ Choosing a model — pass it per task via the optional "model" input of opencode_start_task as 'providerID/modelID'. Build that string only from opencode_list_agents output: models.providers[].provider + '/' + models.providers[].models[].id, both copied verbatim. Never derive an id from a model's display name, and never assume a provider prefix — read it from the same models.providers[] entry that supplied the id. If opencode_start_task returns status "unknown_model", pick one of the available_models it returns instead of retrying a guessed id.
20
+
21
+ Every model in that output carries a quota field: per_5h (estimated requests per 5 hours) and tier. Choose by tier:
22
+ ${formatTierGuide()}
23
+ Spread parallel tasks across models instead of firing every task at the same scarce one. models.providers[] is also the authority on what is actually enabled for the connected account.
26
24
 
27
25
  Workflow:
28
26
  1. Ensure an OpenCode server is running. If you don't already have a server_id from a previous opencode_start_server call, call opencode_start_server first.
29
- 2. Call opencode_list_agents with the server_id to discover the available agents (native and custom) and the exact model ids. Agents may have a pre-assigned model ("provider/model"); you can still override it per task.
30
- 3. For each task, call opencode_start_task with the server_id and the task's prompt. Optionally pass an agent name and/or a model override copied verbatim from opencode_list_agents — never a guessed id. Collect the returned task_id for every call.
27
+ 2. Call opencode_list_agents with the server_id to discover the available agents (native and custom), the exact model ids and their quotas. Pass its optional directory when the task targets a different project so discovery matches task configuration. Agents may have a pre-assigned model ("provider/model"); you can still override it per task.
28
+ 3. For each task, call opencode_start_task with the server_id and the task's prompt, optionally with an agent/model override, a directory relative to the server directory, and workspace_mode='shared'|'worktree'. Shared mode is the backward-compatible default. Worktree mode uses a detached committed base_ref (default HEAD), does not copy source changes, and returns workspace metadata including workspace_id.
31
29
  4. Wait for completion with opencode_wait_for_task:
32
30
  - Single task: mode "all" with the single task_id.
33
31
  - Multiple tasks, incremental results: call it repeatedly with mode "any", removing completed task_ids each time.
@@ -35,5 +33,12 @@ Workflow:
35
33
  5. Once a task is reported finished, call opencode_get_task_result for that task_id to retrieve its output.
36
34
  6. Use opencode_get_task_status only for quick, non-blocking checks on a task's progress (e.g. to report status to the user) — it does not replace opencode_wait_for_task or opencode_get_task_result.
37
35
 
36
+ Execution reports: start_task and continue_task optionally accept expected_changes [{path, change: created|modified|deleted}] and checks [{executable, argv, cwd?, timeout_ms?}]. Status and result accept an optional run_id for historical retrieval. Use wait_for_task until='report' when the final report is required. Reports label filesystem evidence workspace_delta; concurrent writers can make attribution uncertain. Verified runs require an exclusive overlapping-workspace lease and return workspace_busy on conflict. Checks execute directly (no shell) and run once per accepted run. Final text/progress and reports are cached; getters never rerun checks. The recursive inventory excludes .git and node_modules but explicitly checks caller-declared paths. Prompt IDs must use OpenCode's msg_ prefix. If a prompt response ACK is lost, start_task/continue_task return dispatch_uncertain with trackable IDs while retaining the lease; poll or cancel that task rather than retrying the prompt as a new run. Definite HTTP 4xx rejection rolls back the provisional run. Evidence limits, failures, and output truncation are disclosed in the report.
37
+
38
+ Managed worktrees are retained when tasks finish; they are never automatically cleaned up. After a task's reports finalize, call opencode_cleanup_workspace with its workspace_id. Cleanup refuses active/pending reports and dirty worktrees unless discard_changes=true; it removes only an owned worktree and preserves cached results and history. Workspace metadata appears in task and wait responses, including historical runs. Permission responders route through the selected directory and approve only registered task sessions.
39
+
40
+ Usage reports aggregate only direct assistant-message INFO metrics (input, output, reasoning, cache read/write, and OpenCode-reported cost); step-finish parts are excluded to avoid double counting. Run and session metrics are independent, based on all direct assistant messages in the session snapshot, and do not include descendant or subagent sessions. Missing/invalid metrics remain unknown and make completeness explicit. Cost has no verified currency and is not an invoice total. Historical results retain the usage snapshot captured at run finalization; its session summary is historical, not the latest session total. Live status may expose a partial snapshot with its capture time, or a diagnostic when message data is unavailable.
41
+
38
42
  Do not call opencode_get_task_result before the task has finished, and prefer opencode_wait_for_task over polling opencode_get_task_status in a loop.`;
43
+ }
39
44
  //# sourceMappingURL=instructions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"instructions.js","sourceRoot":"","sources":["../../../../src/modules/shared/instructions.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,0BAA0B,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sJAqC4G,CAAC"}
1
+ {"version":3,"file":"instructions.js","sourceRoot":"","sources":["../../../../src/modules/shared/instructions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEvF,MAAM,cAAc,GAAG;sHAC+F,CAAC;AAEvH;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,8BAA8B;IAClD,MAAM,MAAM,GAAG,MAAM,cAAc,EAAE,CAAC;IACtC,MAAM,UAAU,GAAG,MAAM,CAAC,CAAC,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC;IAEvE,OAAO;;EAEP,UAAU;;;;;;EAMV,eAAe,EAAE;;;;;;;;;;;;;;;;;;;;sJAoBmI,CAAC;AACvJ,CAAC"}
@@ -0,0 +1,3 @@
1
+ /** OpenCode 1.18.x requires caller-supplied message IDs to use its msg_ namespace. */
2
+ export declare function createMessageId(): string;
3
+ //# sourceMappingURL=message-id.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message-id.d.ts","sourceRoot":"","sources":["../../../../src/modules/shared/message-id.ts"],"names":[],"mappings":"AAEA,sFAAsF;AACtF,wBAAgB,eAAe,IAAI,MAAM,CAExC"}
@@ -0,0 +1,6 @@
1
+ import { randomUUID } from "node:crypto";
2
+ /** OpenCode 1.18.x requires caller-supplied message IDs to use its msg_ namespace. */
3
+ export function createMessageId() {
4
+ return `msg_${randomUUID()}`;
5
+ }
6
+ //# sourceMappingURL=message-id.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message-id.js","sourceRoot":"","sources":["../../../../src/modules/shared/message-id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,sFAAsF;AACtF,MAAM,UAAU,eAAe;IAC7B,OAAO,OAAO,UAAU,EAAE,EAAE,CAAC;AAC/B,CAAC"}
@@ -1,6 +1,8 @@
1
1
  import { type AssistantMessage, type OpencodeClient, type Part } from "@opencode-ai/sdk";
2
+ import { type ExecutionUsageSnapshot } from "./execution-usage.js";
3
+ export declare function fetchWithDeadline(request: Request): Promise<Response>;
2
4
  /** Build an HTTP client for a tracked server, or undefined if the id is unknown. */
3
- export declare function clientForServer(serverId: string): OpencodeClient | undefined;
5
+ export declare function clientForServer(serverId: string, directory?: string): OpencodeClient | undefined;
4
6
  /** Resolve a task to its server client and session id, or undefined if unknown. */
5
7
  export declare function clientForTask(taskId: string): {
6
8
  client: OpencodeClient;
@@ -10,14 +12,25 @@ export interface AssistantEntry {
10
12
  info: AssistantMessage;
11
13
  parts: Part[];
12
14
  }
15
+ export declare function isTerminalTaskStatus(status: string): boolean;
16
+ export declare function sdkResponseError(response: unknown): unknown;
17
+ /** Fetch every assistant message (with its parts) for a session, oldest first. */
18
+ export declare function assistantEntries(client: OpencodeClient, sessionId: string, signal?: AbortSignal): Promise<AssistantEntry[]>;
19
+ export declare function currentRunEntries(client: OpencodeClient, sessionId: string, taskId: string): Promise<AssistantEntry[]>;
20
+ /** Every part the assistant emitted across the whole session, oldest first. */
21
+ export declare function sessionParts(entries: AssistantEntry[]): Part[];
13
22
  /** Fetch the most recent assistant message (with its parts) for a session. */
14
23
  export declare function lastAssistantEntry(client: OpencodeClient, sessionId: string): Promise<AssistantEntry | undefined>;
15
- export type TaskStatus = "pending" | "running" | "completed" | "failed";
24
+ export type TaskStatus = "pending" | "running" | "completed" | "failed" | "empty" | "cancelled";
16
25
  export interface TaskProgress {
17
26
  /** Last ~500 chars of concatenated TextPart text from the last assistant message. */
18
27
  text_snippet: string;
19
28
  /** Count of ToolPart parts whose state.status is "completed". */
20
29
  tool_calls_completed: number;
30
+ /** Completed tool calls that can mutate the workspace. */
31
+ mutating_tool_calls: number;
32
+ /** Distinct file paths touched by completed mutating tool calls. */
33
+ files_touched: string[];
21
34
  /** Tool name of the last ToolPart whose state.status is "running" or "pending". */
22
35
  current_tool?: string;
23
36
  /** state.status of that tool part. */
@@ -28,17 +41,42 @@ export interface TaskStatusResult {
28
41
  status: TaskStatus;
29
42
  error?: string;
30
43
  progress?: TaskProgress;
44
+ usage?: ExecutionUsageSnapshot;
31
45
  }
46
+ /**
47
+ * Whether an assistant turn actually produced anything.
48
+ *
49
+ * A completed timestamp only says the turn ended, not that it did work: an
50
+ * aborted or rejected turn carries a completed timestamp with no parts at all,
51
+ * which is byte-for-byte indistinguishable from a task that succeeded quietly.
52
+ */
53
+ export declare function hasWork(parts: Part[]): boolean;
32
54
  /**
33
55
  * How long an idle session may stay without any assistant message before the
34
56
  * task is considered dead (e.g. the fire-and-forget prompt was rejected).
35
57
  */
36
58
  export declare const PENDING_STALL_MS = 15000;
37
- /** Build a TaskProgress summary from a message's parts. */
38
- export declare function buildProgress(parts: Part[]): TaskProgress;
59
+ /**
60
+ * Build a TaskProgress summary.
61
+ *
62
+ * `latest` is the current assistant turn — it drives the text snippet and the
63
+ * in-flight tool. `whole` is every assistant part in the session and drives the
64
+ * side-effect evidence, because an agent's edits land in earlier turns while
65
+ * the final turn is usually just "DONE". Reading evidence off the last message
66
+ * alone reports `files_touched: []` for a task that rewrote the workspace.
67
+ */
68
+ export declare function buildProgress(latest: Part[], whole?: Part[]): TaskProgress;
69
+ /** Message returned alongside the `cancelled` status, shared by status and result. */
70
+ export declare const CANCELLED_TASK_MESSAGE = "the task was cancelled via opencode_cancel_task; any output below is whatever the agent produced before the abort";
71
+ /** Message returned alongside the `empty` status, shared by status and result. */
72
+ export declare const EMPTY_TURN_MESSAGE = "the session finished without producing any text or tool calls; the prompt was likely rejected or the turn was aborted";
39
73
  export interface DeriveTaskStatusOptions {
40
74
  includeProgress?: boolean;
75
+ includeUsage?: boolean;
76
+ usageMessageID?: string;
77
+ signal?: AbortSignal;
41
78
  }
79
+ export declare function deriveAssistantTurnStatus(entry: AssistantEntry | undefined): Pick<TaskStatusResult, "status" | "error">;
42
80
  /**
43
81
  * Derive the current status of a task by inspecting session busy state and
44
82
  * the last assistant message. Shared by opencode_get_task_status and
@@ -1 +1 @@
1
- {"version":3,"file":"opencode-client.d.ts","sourceRoot":"","sources":["../../../../src/modules/shared/opencode-client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,gBAAgB,EAErB,KAAK,cAAc,EACnB,KAAK,IAAI,EACV,MAAM,kBAAkB,CAAC;AAI1B,oFAAoF;AACpF,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,CAI5E;AAED,mFAAmF;AACnF,wBAAgB,aAAa,CAC3B,MAAM,EAAE,MAAM,GACb;IAAE,MAAM,EAAE,cAAc,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAM3D;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,gBAAgB,CAAC;IACvB,KAAK,EAAE,IAAI,EAAE,CAAC;CACf;AAED,8EAA8E;AAC9E,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,cAAc,EACtB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC,CAUrC;AAED,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,CAAC;AAExE,MAAM,WAAW,YAAY;IAC3B,qFAAqF;IACrF,YAAY,EAAE,MAAM,CAAC;IACrB,iEAAiE;IACjE,oBAAoB,EAAE,MAAM,CAAC;IAC7B,mFAAmF;IACnF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,sCAAsC;IACtC,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,UAAU,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,YAAY,CAAC;CACzB;AAID;;;GAGG;AACH,eAAO,MAAM,gBAAgB,QAAS,CAAC;AAEvC,2DAA2D;AAC3D,wBAAgB,aAAa,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,YAAY,CA2BzD;AAED,MAAM,WAAW,uBAAuB;IACtC,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,cAAc,EACtB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,uBAAuB,GAChC,OAAO,CAAC,gBAAgB,CAAC,CA8C3B"}
1
+ {"version":3,"file":"opencode-client.d.ts","sourceRoot":"","sources":["../../../../src/modules/shared/opencode-client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,gBAAgB,EAErB,KAAK,cAAc,EACnB,KAAK,IAAI,EACV,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAuB,KAAK,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAMxF,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAe3E;AAED,oFAAoF;AACpF,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,CAShG;AAED,mFAAmF;AACnF,wBAAgB,aAAa,CAC3B,MAAM,EAAE,MAAM,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