@telsoncc/opencode-commandcode 1.2.33 → 1.2.35

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 (48) hide show
  1. package/CHANGELOG.md +6 -222
  2. package/_version.txt +1 -1
  3. package/dist/_version.txt +1 -0
  4. package/dist/index.d.ts +11 -0
  5. package/dist/index.js +19 -0
  6. package/dist/manifest.json +28 -0
  7. package/dist/models.json +3447 -0
  8. package/dist/plugin-opencode2.d.ts +30 -0
  9. package/dist/plugin-opencode2.js +127 -0
  10. package/dist/plugin.d.ts +27 -0
  11. package/dist/plugin.js +192 -0
  12. package/dist/src/auth.d.ts +5 -0
  13. package/dist/src/auth.js +38 -0
  14. package/dist/src/catalog-break.d.ts +12 -0
  15. package/dist/src/catalog-break.js +33 -0
  16. package/dist/src/catalog-release-notes.d.ts +30 -0
  17. package/dist/src/catalog-release-notes.js +106 -0
  18. package/dist/src/catalog.d.ts +160 -0
  19. package/dist/src/catalog.js +786 -0
  20. package/dist/src/convert.d.ts +71 -0
  21. package/dist/src/convert.js +154 -0
  22. package/dist/src/costs-docs.d.ts +13 -0
  23. package/dist/src/costs-docs.js +170 -0
  24. package/dist/src/costs-models-dev.d.ts +68 -0
  25. package/dist/src/costs-models-dev.js +303 -0
  26. package/dist/src/cut-changelog.d.ts +1 -0
  27. package/dist/src/cut-changelog.js +43 -0
  28. package/dist/src/manifest.d.ts +72 -0
  29. package/dist/src/manifest.js +111 -0
  30. package/dist/src/model.d.ts +18 -0
  31. package/dist/src/model.js +138 -0
  32. package/dist/src/opencode2.d.ts +179 -0
  33. package/dist/src/opencode2.js +386 -0
  34. package/dist/src/pack-contract.d.ts +25 -0
  35. package/dist/src/pack-contract.js +42 -0
  36. package/dist/src/publish-policy.d.ts +18 -0
  37. package/dist/src/publish-policy.js +16 -0
  38. package/dist/src/startup.d.ts +18 -0
  39. package/dist/src/startup.js +31 -0
  40. package/dist/src/stream.d.ts +2 -0
  41. package/dist/src/stream.js +203 -0
  42. package/manifest.json +7 -7
  43. package/models.json +155 -42
  44. package/package.json +12 -7
  45. package/plugin.ts +14 -3
  46. package/src/cut-changelog.ts +6 -1
  47. package/src/opencode2.ts +14 -3
  48. package/src/pack-contract.ts +51 -0
@@ -0,0 +1,31 @@
1
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
2
+ import { homedir } from "os";
3
+ import { join } from "path";
4
+ export function pluginStateDir() {
5
+ const override = process.env.COMMANDCODE_PROVIDER_STATE_DIR?.trim();
6
+ if (override)
7
+ return override;
8
+ return join(homedir(), ".local/state/opencode/commandcode-provider");
9
+ }
10
+ export function readCatalogCache(dir = pluginStateDir()) {
11
+ const path = join(dir, "catalog-cache.json");
12
+ if (!existsSync(path))
13
+ return null;
14
+ try {
15
+ const parsed = JSON.parse(readFileSync(path, "utf-8"));
16
+ if (!Array.isArray(parsed) || parsed.length === 0)
17
+ return null;
18
+ return parsed;
19
+ }
20
+ catch {
21
+ return null;
22
+ }
23
+ }
24
+ export function writeCatalogCache(dir, models) {
25
+ mkdirSync(dir, { recursive: true });
26
+ writeFileSync(join(dir, "catalog-cache.json"), JSON.stringify(models) + "\n", "utf-8");
27
+ }
28
+ export function writeStartupSummary(dir, summary) {
29
+ mkdirSync(dir, { recursive: true });
30
+ writeFileSync(join(dir, "startup.json"), JSON.stringify(summary) + "\n", "utf-8");
31
+ }
@@ -0,0 +1,2 @@
1
+ import type { LanguageModelV3StreamPart } from "@ai-sdk/provider";
2
+ export declare function parseStreamEvents(body: ReadableStream<Uint8Array>): ReadableStream<LanguageModelV3StreamPart>;
@@ -0,0 +1,203 @@
1
+ function mapFinishReason(raw) {
2
+ switch (raw) {
3
+ case "stop":
4
+ case "end_turn":
5
+ return "stop";
6
+ case "tool_calls":
7
+ case "tool-calls":
8
+ return "tool-calls";
9
+ case "length":
10
+ case "max_tokens":
11
+ case "max-tokens":
12
+ case "max_output_tokens":
13
+ return "length";
14
+ case "content_filter":
15
+ return "content-filter";
16
+ default:
17
+ return "other";
18
+ }
19
+ }
20
+ function mapUsage(raw) {
21
+ const inputDetails = (raw.inputTokenDetails ?? raw.input_token_details ?? {});
22
+ const outputDetails = (raw.outputTokenDetails ?? raw.output_token_details ?? {});
23
+ return {
24
+ inputTokens: {
25
+ total: typeof raw.inputTokens === "number"
26
+ ? raw.inputTokens
27
+ : typeof raw.prompt_tokens === "number"
28
+ ? raw.prompt_tokens
29
+ : undefined,
30
+ noCache: typeof inputDetails.noCacheTokens === "number" ? inputDetails.noCacheTokens : undefined,
31
+ cacheRead: typeof inputDetails.cacheReadTokens === "number" ? inputDetails.cacheReadTokens : undefined,
32
+ cacheWrite: typeof inputDetails.cacheWriteTokens === "number"
33
+ ? inputDetails.cacheWriteTokens
34
+ : undefined,
35
+ },
36
+ outputTokens: {
37
+ total: typeof raw.outputTokens === "number"
38
+ ? raw.outputTokens
39
+ : typeof raw.completion_tokens === "number"
40
+ ? raw.completion_tokens
41
+ : undefined,
42
+ text: typeof outputDetails.textTokens === "number" ? outputDetails.textTokens : undefined,
43
+ reasoning: typeof outputDetails.reasoningTokens === "number"
44
+ ? outputDetails.reasoningTokens
45
+ : undefined,
46
+ },
47
+ };
48
+ }
49
+ function toStreamPart(event) {
50
+ switch (event.type) {
51
+ case "start":
52
+ return { type: "stream-start", warnings: [] };
53
+ case "text-start":
54
+ return { type: "text-start", id: event.id };
55
+ case "text-delta":
56
+ return {
57
+ type: "text-delta",
58
+ id: event.id,
59
+ delta: (event.text ?? event.delta ?? ""),
60
+ };
61
+ case "text-end":
62
+ return { type: "text-end", id: event.id };
63
+ case "reasoning-start":
64
+ return { type: "reasoning-start", id: event.id };
65
+ case "reasoning-delta":
66
+ return {
67
+ type: "reasoning-delta",
68
+ id: event.id,
69
+ delta: (event.text ?? event.delta ?? ""),
70
+ };
71
+ case "reasoning-end":
72
+ return { type: "reasoning-end", id: event.id };
73
+ case "tool-input-start":
74
+ return {
75
+ type: "tool-input-start",
76
+ id: event.id,
77
+ toolName: event.toolName,
78
+ dynamic: event.dynamic,
79
+ };
80
+ case "tool-input-delta":
81
+ return {
82
+ type: "tool-input-delta",
83
+ id: event.id,
84
+ delta: (event.delta ?? ""),
85
+ };
86
+ case "tool-input-end":
87
+ return { type: "tool-input-end", id: event.id };
88
+ case "tool-call": {
89
+ const input = event.input ?? event.args ?? event.arguments;
90
+ return {
91
+ type: "tool-call",
92
+ toolCallId: (event.toolCallId ?? event.id ?? ""),
93
+ toolName: event.toolName,
94
+ input: typeof input === "string" ? input : JSON.stringify(input ?? {}),
95
+ };
96
+ }
97
+ case "finish-step": {
98
+ const usage = event.usage ?? event.totalUsage ?? {};
99
+ const rawReason = (event.finishReason ?? event.rawFinishReason ?? "stop");
100
+ return {
101
+ type: "finish",
102
+ finishReason: { unified: mapFinishReason(rawReason), raw: rawReason },
103
+ usage: mapUsage(typeof usage === "object" && usage !== null ? usage : {}),
104
+ };
105
+ }
106
+ case "finish":
107
+ return null;
108
+ case "response-metadata":
109
+ return {
110
+ type: "response-metadata",
111
+ id: event.id,
112
+ modelId: event.modelId,
113
+ };
114
+ case "error":
115
+ return { type: "error", error: event.error ?? event.message ?? "Unknown error" };
116
+ default:
117
+ return null;
118
+ }
119
+ }
120
+ // Assumes line-delimited JSON over SSE: one JSON object per `data:` line.
121
+ // Multi-line `data:` fields are not supported — the buffer splits on `\n`.
122
+ export function parseStreamEvents(body) {
123
+ const reader = body.getReader();
124
+ const decoder = new TextDecoder();
125
+ let buffer = "";
126
+ return new ReadableStream({
127
+ async pull(controller) {
128
+ try {
129
+ while (true) {
130
+ const lines = buffer.split("\n");
131
+ // Strip trailing \r from Windows-style \r\n line endings
132
+ for (let i = 0; i < lines.length; i++) {
133
+ const line = lines[i];
134
+ if (line !== undefined && line.endsWith("\r"))
135
+ lines[i] = line.slice(0, -1);
136
+ }
137
+ buffer = lines.pop() ?? "";
138
+ for (const line of lines) {
139
+ const trimmed = line.trim();
140
+ if (!trimmed || trimmed.startsWith(":") || trimmed === "[DONE]")
141
+ continue;
142
+ let jsonStr = trimmed;
143
+ if (jsonStr.startsWith("data: "))
144
+ jsonStr = jsonStr.slice(6);
145
+ if (jsonStr.startsWith("data:"))
146
+ jsonStr = jsonStr.slice(5);
147
+ if (!jsonStr || jsonStr === "[DONE]")
148
+ continue;
149
+ let parsed;
150
+ try {
151
+ parsed = JSON.parse(jsonStr);
152
+ }
153
+ catch {
154
+ // intentionally silent: skip malformed SSE lines
155
+ continue;
156
+ }
157
+ if (typeof parsed !== "object" || parsed === null || typeof parsed.type !== "string")
158
+ continue;
159
+ const part = toStreamPart(parsed);
160
+ if (part)
161
+ controller.enqueue(part);
162
+ }
163
+ const { done, value } = await reader.read();
164
+ if (done) {
165
+ if (buffer.trim()) {
166
+ const trimmed = buffer.trim();
167
+ if (trimmed && trimmed !== "[DONE]" && !trimmed.startsWith(":")) {
168
+ let jsonStr = trimmed;
169
+ if (jsonStr.startsWith("data: "))
170
+ jsonStr = jsonStr.slice(6);
171
+ if (jsonStr.startsWith("data:"))
172
+ jsonStr = jsonStr.slice(5);
173
+ try {
174
+ const parsed = JSON.parse(jsonStr);
175
+ if (typeof parsed === "object" &&
176
+ parsed !== null &&
177
+ typeof parsed.type === "string") {
178
+ const part = toStreamPart(parsed);
179
+ if (part)
180
+ controller.enqueue(part);
181
+ }
182
+ }
183
+ catch {
184
+ // intentionally silent: skip malformed final buffer
185
+ }
186
+ }
187
+ }
188
+ controller.close();
189
+ return;
190
+ }
191
+ buffer += decoder.decode(value, { stream: true });
192
+ }
193
+ }
194
+ catch (err) {
195
+ controller.enqueue({ type: "error", error: err });
196
+ controller.close();
197
+ }
198
+ },
199
+ cancel() {
200
+ reader.cancel();
201
+ },
202
+ });
203
+ }
package/manifest.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
- "generatedAt": "2026-11-09T18:34:31.627Z",
4
- "pluginVersion": "1.2.33",
5
- "commandCodeVersion": "1.88.5",
6
- "commandCodeTarball": "https://registry.npmjs.org/command-code/-/command-code-1.88.5.tgz",
7
- "modelCount": 95,
8
- "reasoningModelCount": 84,
3
+ "generatedAt": "2026-11-13T23:16:11.283Z",
4
+ "pluginVersion": "1.2.35",
5
+ "commandCodeVersion": "1.89.1",
6
+ "commandCodeTarball": "https://registry.npmjs.org/command-code/-/command-code-1.89.1.tgz",
7
+ "modelCount": 98,
8
+ "reasoningModelCount": 87,
9
9
  "extraction": {
10
10
  "modelCatalog": "ok",
11
11
  "costCatalog": "docs",
@@ -13,7 +13,7 @@
13
13
  },
14
14
  "costSources": {
15
15
  "cli": 0,
16
- "officialDocs": 95,
16
+ "officialDocs": 98,
17
17
  "thirdParty": 0,
18
18
  "free": 0,
19
19
  "fallback": 0,
package/models.json CHANGED
@@ -75,6 +75,44 @@
75
75
  "/messages"
76
76
  ]
77
77
  },
78
+ {
79
+ "id": "claude-fable-5-2",
80
+ "name": "Claude Fable 5.2",
81
+ "tier": "premium",
82
+ "reasoning": true,
83
+ "reasoningEfforts": [
84
+ "low",
85
+ "medium",
86
+ "high",
87
+ "xhigh",
88
+ "max"
89
+ ],
90
+ "tool_call": true,
91
+ "cost": {
92
+ "input": 8,
93
+ "output": 40,
94
+ "cache_read": 0.2,
95
+ "cache_write": 10
96
+ },
97
+ "limit": {
98
+ "context": 1000000,
99
+ "output": 65536
100
+ },
101
+ "attachment": true,
102
+ "modalities": {
103
+ "input": [
104
+ "text",
105
+ "image",
106
+ "pdf"
107
+ ],
108
+ "output": [
109
+ "text"
110
+ ]
111
+ },
112
+ "supportedEndpoints": [
113
+ "/messages"
114
+ ]
115
+ },
78
116
  {
79
117
  "id": "claude-haiku-4-5-20251001",
80
118
  "name": "Claude Haiku 4.5",
@@ -750,45 +788,6 @@
750
788
  "/responses"
751
789
  ]
752
790
  },
753
- {
754
- "id": "stealth/crouton-alpha",
755
- "name": "Crouton Alpha",
756
- "tier": "open-source",
757
- "reasoning": true,
758
- "reasoningEfforts": [
759
- "low",
760
- "medium",
761
- "high",
762
- "xhigh",
763
- "max"
764
- ],
765
- "tool_call": true,
766
- "cost": {
767
- "input": 0,
768
- "output": 0,
769
- "cache_read": 0
770
- },
771
- "limit": {
772
- "context": 1048576,
773
- "output": 943718
774
- },
775
- "attachment": true,
776
- "modalities": {
777
- "input": [
778
- "text",
779
- "image",
780
- "video",
781
- "pdf",
782
- "audio"
783
- ],
784
- "output": [
785
- "text"
786
- ]
787
- },
788
- "supportedEndpoints": [
789
- "/chat/completions"
790
- ]
791
- },
792
791
  {
793
792
  "id": "deepseek/deepseek-v4-flash",
794
793
  "name": "DeepSeek V4 Flash (latest)",
@@ -1333,6 +1332,44 @@
1333
1332
  "/responses"
1334
1333
  ]
1335
1334
  },
1335
+ {
1336
+ "id": "google/gemini-4-carbon",
1337
+ "name": "Gemini 4 Carbon",
1338
+ "tier": "open-source",
1339
+ "reasoning": true,
1340
+ "reasoningEfforts": [
1341
+ "low",
1342
+ "medium",
1343
+ "high"
1344
+ ],
1345
+ "tool_call": true,
1346
+ "cost": {
1347
+ "input": 2,
1348
+ "output": 10,
1349
+ "cache_read": 0.1
1350
+ },
1351
+ "limit": {
1352
+ "context": 1000000,
1353
+ "output": 65536
1354
+ },
1355
+ "attachment": true,
1356
+ "modalities": {
1357
+ "input": [
1358
+ "text",
1359
+ "image",
1360
+ "video",
1361
+ "audio",
1362
+ "pdf"
1363
+ ],
1364
+ "output": [
1365
+ "text"
1366
+ ]
1367
+ },
1368
+ "supportedEndpoints": [
1369
+ "/chat/completions",
1370
+ "/responses"
1371
+ ]
1372
+ },
1336
1373
  {
1337
1374
  "id": "zai-org/GLM-5",
1338
1375
  "name": "GLM-5",
@@ -1484,7 +1521,8 @@
1484
1521
  ]
1485
1522
  },
1486
1523
  "supportedEndpoints": [
1487
- "/chat/completions"
1524
+ "/chat/completions",
1525
+ "/responses"
1488
1526
  ]
1489
1527
  },
1490
1528
  {
@@ -1850,6 +1888,41 @@
1850
1888
  "/responses"
1851
1889
  ]
1852
1890
  },
1891
+ {
1892
+ "id": "thinkingmachines/inkling-2-small:free",
1893
+ "name": "Inkling 2 Small",
1894
+ "tier": "open-source",
1895
+ "reasoning": true,
1896
+ "reasoningEfforts": [
1897
+ "low",
1898
+ "medium",
1899
+ "high",
1900
+ "max"
1901
+ ],
1902
+ "tool_call": true,
1903
+ "cost": {
1904
+ "input": 0,
1905
+ "output": 0,
1906
+ "cache_read": 0
1907
+ },
1908
+ "limit": {
1909
+ "context": 1048576,
1910
+ "output": 131072
1911
+ },
1912
+ "attachment": true,
1913
+ "modalities": {
1914
+ "input": [
1915
+ "text",
1916
+ "image"
1917
+ ],
1918
+ "output": [
1919
+ "text"
1920
+ ]
1921
+ },
1922
+ "supportedEndpoints": [
1923
+ "/chat/completions"
1924
+ ]
1925
+ },
1853
1926
  {
1854
1927
  "id": "thinkingmachines/inkling-small",
1855
1928
  "name": "Inkling Small",
@@ -2433,6 +2506,47 @@
2433
2506
  "/responses"
2434
2507
  ]
2435
2508
  },
2509
+ {
2510
+ "id": "meta/muse-ember",
2511
+ "name": "Muse Ember",
2512
+ "tier": "open-source",
2513
+ "reasoning": true,
2514
+ "reasoningEfforts": [
2515
+ "low",
2516
+ "medium",
2517
+ "high",
2518
+ "xhigh",
2519
+ "max"
2520
+ ],
2521
+ "tool_call": true,
2522
+ "cost": {
2523
+ "input": 0.1,
2524
+ "output": 0.5,
2525
+ "cache_read": 0.004
2526
+ },
2527
+ "limit": {
2528
+ "context": 1048576,
2529
+ "output": 65536
2530
+ },
2531
+ "attachment": true,
2532
+ "modalities": {
2533
+ "input": [
2534
+ "text",
2535
+ "image",
2536
+ "file",
2537
+ "video",
2538
+ "pdf",
2539
+ "audio"
2540
+ ],
2541
+ "output": [
2542
+ "text"
2543
+ ]
2544
+ },
2545
+ "supportedEndpoints": [
2546
+ "/chat/completions",
2547
+ "/responses"
2548
+ ]
2549
+ },
2436
2550
  {
2437
2551
  "id": "meta/muse-spark-1.1",
2438
2552
  "name": "Muse Spark 1.1",
@@ -3088,8 +3202,7 @@
3088
3202
  "input": [
3089
3203
  "text",
3090
3204
  "image",
3091
- "video",
3092
- "pdf"
3205
+ "video"
3093
3206
  ],
3094
3207
  "output": [
3095
3208
  "text"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telsoncc/opencode-commandcode",
3
- "version": "1.2.33",
3
+ "version": "1.2.35",
4
4
  "description": "Command Code API provider for opencode — use Claude, GPT, Gemini, DeepSeek, Qwen, Kimi, GLM, MiniMax, and Step models via Command Code",
5
5
  "keywords": [
6
6
  "ai",
@@ -29,6 +29,7 @@
29
29
  "url": "git+https://github.com/telsoncc/opencode-commandcode.git"
30
30
  },
31
31
  "files": [
32
+ "dist/",
32
33
  "index.ts",
33
34
  "plugin.ts",
34
35
  "plugin-opencode2.ts",
@@ -40,17 +41,20 @@
40
41
  "src/"
41
42
  ],
42
43
  "type": "module",
43
- "main": "index.ts",
44
- "types": "index.ts",
44
+ "main": "dist/index.js",
45
+ "types": "dist/index.d.ts",
45
46
  "exports": {
46
47
  ".": {
47
- "import": "./index.ts"
48
+ "types": "./dist/index.d.ts",
49
+ "import": "./dist/index.js"
48
50
  },
49
51
  "./server": {
50
- "import": "./plugin-opencode2.ts"
52
+ "types": "./dist/plugin-opencode2.d.ts",
53
+ "import": "./dist/plugin-opencode2.js"
51
54
  },
52
55
  "./plugin/opencode2": {
53
- "import": "./plugin-opencode2.ts"
56
+ "types": "./dist/plugin-opencode2.d.ts",
57
+ "import": "./dist/plugin-opencode2.js"
54
58
  }
55
59
  },
56
60
  "publishConfig": {
@@ -66,7 +70,8 @@
66
70
  "test:integration": "bun test tests/integration/",
67
71
  "test:all": "bun test",
68
72
  "typecheck": "tsc --noEmit",
69
- "prepack": "bun run scripts/verify-manifest-version.ts",
73
+ "build": "bun run scripts/build.ts",
74
+ "prepack": "bun run build && bun run scripts/verify-manifest-version.ts",
70
75
  "verify:release-candidate": "bun run scripts/verify-release-candidate.ts",
71
76
  "generate-readme": "bun run scripts/generate-readme.ts",
72
77
  "sync": "bun run scripts/sync-models.ts",
package/plugin.ts CHANGED
@@ -16,9 +16,20 @@ import {
16
16
  import type { CatalogManifest } from "./src/manifest.js";
17
17
 
18
18
  const __dirname = dirname(fileURLToPath(import.meta.url));
19
- const MODELS_PATH = join(__dirname, "models.json");
20
- const VERSION_PATH = join(__dirname, "_version.txt");
21
- const MANIFEST_PATH = join(__dirname, "manifest.json");
19
+
20
+ // Repo layout keeps the catalog next to plugin.ts; published builds emit
21
+ // dist/plugin.js and ship the catalog inside dist/ (and at the package root).
22
+ function resolveAsset(name: string): string {
23
+ for (const dir of [__dirname, dirname(__dirname)]) {
24
+ const candidate = join(dir, name);
25
+ if (existsSync(candidate)) return candidate;
26
+ }
27
+ return join(__dirname, name);
28
+ }
29
+
30
+ const MODELS_PATH = resolveAsset("models.json");
31
+ const VERSION_PATH = resolveAsset("_version.txt");
32
+ const MANIFEST_PATH = resolveAsset("manifest.json");
22
33
 
23
34
  interface PluginFileConfig {
24
35
  disableModelSync?: boolean;
@@ -26,11 +26,16 @@ export function cutKeepAChangelog(markdown: string, version: string, date: strin
26
26
  }
27
27
  }
28
28
 
29
- const before = lines.slice(0, start + 1).join("");
30
29
  const body = lines
31
30
  .slice(start + 1, end)
32
31
  .join("")
33
32
  .replace(/^\n+/, "\n");
33
+ // Nothing was written under [Unreleased] since the last cut: emitting a
34
+ // heading here would only add an empty version section. Releases are also
35
+ // described on GitHub (semantic-release catalog notes), so skip the cut.
36
+ if (body.trim() === "") return markdown;
37
+
38
+ const before = lines.slice(0, start + 1).join("");
34
39
  const after = lines.slice(end).join("");
35
40
  return `${before}\n## [${version}] - ${date}\n${body}${after}`;
36
41
  }
package/src/opencode2.ts CHANGED
@@ -43,9 +43,20 @@ export const COMMANDCODE_ANTHROPIC_PACKAGE = "@opencode/ai/providers/anthropic-c
43
43
  export const COMMANDCODE_ENV_NAMES = ["COMMANDCODE_API_KEY"];
44
44
 
45
45
  const MODULE_DIR = dirname(fileURLToPath(import.meta.url));
46
- const MODELS_PATH = join(MODULE_DIR, "..", "models.json");
47
- const VERSION_PATH = join(MODULE_DIR, "..", "_version.txt");
48
- const MANIFEST_PATH = join(MODULE_DIR, "..", "manifest.json");
46
+
47
+ // Repo layout: src/../ is the package root. Published builds: dist/src/../ is
48
+ // dist/ (catalog copied at build time) with the package root one level above.
49
+ function resolveAsset(name: string): string {
50
+ for (const dir of [join(MODULE_DIR, ".."), join(MODULE_DIR, "..", "..")]) {
51
+ const candidate = join(dir, name);
52
+ if (existsSync(candidate)) return candidate;
53
+ }
54
+ return join(MODULE_DIR, "..", name);
55
+ }
56
+
57
+ const MODELS_PATH = resolveAsset("models.json");
58
+ const VERSION_PATH = resolveAsset("_version.txt");
59
+ const MANIFEST_PATH = resolveAsset("manifest.json");
49
60
 
50
61
  export type V2Cost = {
51
62
  tier?: { type: "context"; size: number };
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Contract between `package.json` and the files a `npm pack` tarball actually
3
+ * ships. The published entrypoints point at compiled output (`dist/`), so a
4
+ * pack that skips the build — or a `files` list that drops `dist/` — produces
5
+ * a package whose imports fail at runtime on hosts without a TypeScript
6
+ * loader (the opencode IDE server runs plain Node inside Electron).
7
+ */
8
+
9
+ export type PackPackageJson = {
10
+ main?: string;
11
+ types?: string;
12
+ exports?: Record<string, string | { import?: string; types?: string }>;
13
+ };
14
+
15
+ /** Normalize `tar -tzf` output, which uses CRLF on Windows and LF on Linux. */
16
+ export function parseTarListing(listing: string): string[] {
17
+ return listing
18
+ .split(/\r?\n/)
19
+ .filter(Boolean)
20
+ .map((entry) => entry.replace(/^package\//, ""));
21
+ }
22
+
23
+ /**
24
+ * Every file `package.json` promises to resolve, relative to the package root.
25
+ * `main` and each `exports` target are included so a build regression cannot
26
+ * ship silently.
27
+ */
28
+ export function declaredEntrypoints(pkg: PackPackageJson): string[] {
29
+ const targets: string[] = [];
30
+ const push = (value: string | undefined): void => {
31
+ if (typeof value !== "string") return;
32
+ targets.push(value.replace(/^\.\//, ""));
33
+ };
34
+
35
+ push(pkg.main);
36
+ for (const entry of Object.values(pkg.exports ?? {})) {
37
+ if (typeof entry === "string") {
38
+ push(entry);
39
+ continue;
40
+ }
41
+ push(entry.import);
42
+ push(entry.types);
43
+ }
44
+ return [...new Set(targets)];
45
+ }
46
+
47
+ /** Entrypoints declared by `package.json` but absent from the tarball. */
48
+ export function missingEntrypoints(packageJson: PackPackageJson, packed: string[]): string[] {
49
+ const present = new Set(packed);
50
+ return declaredEntrypoints(packageJson).filter((entry) => !present.has(entry));
51
+ }