codiedev 0.9.26 → 0.9.28
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.
- package/README.md +15 -3
- package/assets/opencode-plugin.mjs +54 -0
- package/assets/tui-brand-plugin.tsx +63 -0
- package/dist/backup/cache.js +2 -2
- package/dist/captureLog.js +6 -3
- package/dist/cli.js +7 -0
- package/dist/codie.d.ts +2 -0
- package/dist/codie.js +233 -0
- package/dist/codieLauncher.d.ts +41 -0
- package/dist/codieLauncher.js +352 -0
- package/dist/codieRuntime.d.ts +19 -0
- package/dist/codieRuntime.js +91 -0
- package/dist/codieRuntimeInstall.d.ts +27 -0
- package/dist/codieRuntimeInstall.js +145 -0
- package/dist/configDir.d.ts +1 -0
- package/dist/configDir.js +54 -0
- package/dist/connect.js +8 -2
- package/dist/hook.js +39 -41
- package/dist/upgradeNudge.js +6 -5
- package/dist/utils.d.ts +23 -3
- package/dist/utils.js +288 -20
- package/package.json +13 -5
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Pure launcher logic for the Codie harness.
|
|
3
|
+
//
|
|
4
|
+
// Ported from codiedev-gateway-cli/npm/lib/launcher.js when the harness folded
|
|
5
|
+
// into this package so `npm i -g codiedev` is the only install a developer
|
|
6
|
+
// needs — Claude Code, Codex, Cursor, and Codie all come from one package and
|
|
7
|
+
// share the one token `codiedev connect` stored.
|
|
8
|
+
//
|
|
9
|
+
// Everything here is pure (no fs/network side effects beyond an injected
|
|
10
|
+
// fetch) so the governance rules can be tested without a live gateway.
|
|
11
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
14
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
15
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
16
|
+
}
|
|
17
|
+
Object.defineProperty(o, k2, desc);
|
|
18
|
+
}) : (function(o, m, k, k2) {
|
|
19
|
+
if (k2 === undefined) k2 = k;
|
|
20
|
+
o[k2] = m[k];
|
|
21
|
+
}));
|
|
22
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
23
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
24
|
+
}) : function(o, v) {
|
|
25
|
+
o["default"] = v;
|
|
26
|
+
});
|
|
27
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
28
|
+
var ownKeys = function(o) {
|
|
29
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
30
|
+
var ar = [];
|
|
31
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
32
|
+
return ar;
|
|
33
|
+
};
|
|
34
|
+
return ownKeys(o);
|
|
35
|
+
};
|
|
36
|
+
return function (mod) {
|
|
37
|
+
if (mod && mod.__esModule) return mod;
|
|
38
|
+
var result = {};
|
|
39
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
40
|
+
__setModuleDefault(result, mod);
|
|
41
|
+
return result;
|
|
42
|
+
};
|
|
43
|
+
})();
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.HIDDEN_WORDMARK = exports.CODIEDEV_WORDMARK = exports.LEGACY_CODIEDEV_WORDMARK = exports.STOCK_WORDMARK = exports.BRAND_PLUGIN_SPEC = void 0;
|
|
46
|
+
exports.bareModel = bareModel;
|
|
47
|
+
exports.buildCodieConfig = buildCodieConfig;
|
|
48
|
+
exports.withBrandPlugin = withBrandPlugin;
|
|
49
|
+
exports.patchBrandWordmark = patchBrandWordmark;
|
|
50
|
+
exports.resolveCapturePlugin = resolveCapturePlugin;
|
|
51
|
+
exports.fetchApprovedCatalog = fetchApprovedCatalog;
|
|
52
|
+
exports.parseCodieArgs = parseCodieArgs;
|
|
53
|
+
exports.validateCodieArgs = validateCodieArgs;
|
|
54
|
+
const path = __importStar(require("path"));
|
|
55
|
+
const url_1 = require("url");
|
|
56
|
+
const DEFAULT_NAMES = {
|
|
57
|
+
"openai/gpt-5.3-codex": "GPT-5.3 Codex",
|
|
58
|
+
"openai/gpt-5.2-codex": "GPT-5.2 Codex",
|
|
59
|
+
"openai/gpt-5.1-codex-mini": "GPT-5.1 Codex Mini",
|
|
60
|
+
"anthropic/claude-sonnet-4.6": "Claude Sonnet 4.6",
|
|
61
|
+
"z-ai/glm-5.2": "GLM 5.2 · Fireworks ZDR",
|
|
62
|
+
"moonshotai/kimi-k2.7-code": "Kimi K2.7 Code · Fireworks ZDR",
|
|
63
|
+
};
|
|
64
|
+
function cleanBaseUrl(value) {
|
|
65
|
+
return String(value || "https://gateway.codiedev.com/api/v1").replace(/\/+$/, "");
|
|
66
|
+
}
|
|
67
|
+
function bareModel(value) {
|
|
68
|
+
return String(value || "").trim().replace(/^codiedev\//, "");
|
|
69
|
+
}
|
|
70
|
+
function governedModel(value, approved, fallback, label) {
|
|
71
|
+
const model = bareModel(value || fallback);
|
|
72
|
+
if (!approved.has(model)) {
|
|
73
|
+
throw new Error(`${label} model is not approved for this Codiedev account: ${model || "(empty)"}`);
|
|
74
|
+
}
|
|
75
|
+
return `codiedev/${model}`;
|
|
76
|
+
}
|
|
77
|
+
function economicalModel(catalog, primary) {
|
|
78
|
+
// Catalog ids arrive already normalized through bareModel(), so the
|
|
79
|
+
// gateway's `codiedev/fast` alias appears here as plain "fast".
|
|
80
|
+
const preferred = ["openai/gpt-5.1-codex-mini", "fast", "z-ai/glm-5.2"];
|
|
81
|
+
return preferred.find((id) => catalog.some((model) => model.id === id)) || primary;
|
|
82
|
+
}
|
|
83
|
+
function normalizeAgentModels(agents, approved, fallback) {
|
|
84
|
+
const normalized = {};
|
|
85
|
+
for (const [name, definition] of Object.entries(agents || {})) {
|
|
86
|
+
const next = definition && typeof definition === "object" ? { ...definition } : definition;
|
|
87
|
+
if (next && typeof next === "object" && next.model) {
|
|
88
|
+
next.model = governedModel(next.model, approved, fallback, `Agent “${name}”`);
|
|
89
|
+
}
|
|
90
|
+
normalized[name] = next;
|
|
91
|
+
}
|
|
92
|
+
return normalized;
|
|
93
|
+
}
|
|
94
|
+
function buildCodieConfig({ existing = {}, catalog, env = {}, plugin, plugins = [], }) {
|
|
95
|
+
if (!Array.isArray(catalog) || catalog.length === 0) {
|
|
96
|
+
throw new Error("No company-approved models were returned by Codiedev");
|
|
97
|
+
}
|
|
98
|
+
const approved = new Set(catalog.map((model) => bareModel(model.id)).filter(Boolean));
|
|
99
|
+
const first = bareModel(catalog[0].id);
|
|
100
|
+
const requestedPrimary = env.CODIEDEV_PRIMARY_MODEL || env.CODIEDEV_MODEL || existing.model || first;
|
|
101
|
+
const primary = bareModel(requestedPrimary);
|
|
102
|
+
const fast = economicalModel(catalog, primary);
|
|
103
|
+
const requestedSubagent = env.CODIEDEV_SUBAGENT_MODEL || fast;
|
|
104
|
+
const requestedPlan = env.CODIEDEV_PLAN_MODEL || requestedSubagent;
|
|
105
|
+
const agents = normalizeAgentModels(existing.agent, approved, primary);
|
|
106
|
+
const subagentModel = governedModel(requestedSubagent, approved, fast, "Subagent");
|
|
107
|
+
const planModel = governedModel(requestedPlan, approved, fast, "Plan agent");
|
|
108
|
+
const existingPlugins = Array.isArray(existing.plugin) ? existing.plugin : [];
|
|
109
|
+
const requiredPlugins = [...plugins, plugin].filter(Boolean);
|
|
110
|
+
const models = Object.fromEntries(catalog.map((model) => [
|
|
111
|
+
bareModel(model.id),
|
|
112
|
+
{ name: model.name || DEFAULT_NAMES[bareModel(model.id)] || bareModel(model.id) },
|
|
113
|
+
]));
|
|
114
|
+
return {
|
|
115
|
+
...existing,
|
|
116
|
+
model: governedModel(primary, approved, first, "Primary agent"),
|
|
117
|
+
enabled_providers: ["codiedev"],
|
|
118
|
+
share: "disabled",
|
|
119
|
+
provider: {
|
|
120
|
+
...(existing.provider || {}),
|
|
121
|
+
codiedev: {
|
|
122
|
+
npm: "@ai-sdk/openai-compatible",
|
|
123
|
+
name: "Codiedev Models",
|
|
124
|
+
options: {
|
|
125
|
+
baseURL: cleanBaseUrl(env.CODIEDEV_GATEWAY_URL),
|
|
126
|
+
apiKey: "{env:CODIEDEV_GATEWAY_KEY}",
|
|
127
|
+
},
|
|
128
|
+
models,
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
agent: {
|
|
132
|
+
...agents,
|
|
133
|
+
plan: { ...(agents.plan || {}), model: agents.plan?.model || planModel },
|
|
134
|
+
general: { ...(agents.general || {}), model: agents.general?.model || subagentModel },
|
|
135
|
+
explore: { ...(agents.explore || {}), model: agents.explore?.model || subagentModel },
|
|
136
|
+
scout: { ...(agents.scout || {}), model: agents.scout?.model || subagentModel },
|
|
137
|
+
},
|
|
138
|
+
plugin: [...existingPlugins.filter((item) => !requiredPlugins.includes(item)), ...requiredPlugins],
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
exports.BRAND_PLUGIN_SPEC = "./plugins/codiedev-brand.tsx";
|
|
142
|
+
// Pure merge for ~/.config/opencode/tui.json: TUI plugins load from tui.json,
|
|
143
|
+
// not the opencode.json we inject via OPENCODE_CONFIG_CONTENT.
|
|
144
|
+
function withBrandPlugin(existing) {
|
|
145
|
+
const config = existing && typeof existing === "object" && !Array.isArray(existing) ? existing : {};
|
|
146
|
+
const plugins = Array.isArray(config.plugin) ? config.plugin : [];
|
|
147
|
+
const present = plugins.some((item) => (Array.isArray(item) ? item[0] : item) === exports.BRAND_PLUGIN_SPEC);
|
|
148
|
+
if (present)
|
|
149
|
+
return { config, changed: false };
|
|
150
|
+
return { config: { ...config, plugin: [...plugins, exports.BRAND_PLUGIN_SPEC] }, changed: true };
|
|
151
|
+
}
|
|
152
|
+
// ── Engine wordmark suppression ─────────────────────────────────────────
|
|
153
|
+
// The OpenCode engine prints a block-letter "opencode" wordmark to terminal
|
|
154
|
+
// scrollback around each session (the boot/exit banner). A four-row terminal
|
|
155
|
+
// raster cannot reproduce the real Codiedev wordmark cleanly, so leave that
|
|
156
|
+
// surface blank and keep the proper brand mark on the plugin-driven home
|
|
157
|
+
// screen. The bundled JS table is replaced byte-for-byte so binary offsets do
|
|
158
|
+
// not move.
|
|
159
|
+
function escapeJsSource(row) {
|
|
160
|
+
let out = "";
|
|
161
|
+
for (const ch of row) {
|
|
162
|
+
const code = ch.codePointAt(0);
|
|
163
|
+
out += code > 127 ? `\\u${code.toString(16).padStart(4, "0")}` : ch;
|
|
164
|
+
}
|
|
165
|
+
return out;
|
|
166
|
+
}
|
|
167
|
+
function wordmarkRegion(left, right, { escapeUnicode = true } = {}) {
|
|
168
|
+
const rows = (list) => list.map((row) => `"${escapeUnicode ? escapeJsSource(row) : row}"`).join(",");
|
|
169
|
+
return `var vn={left:[${rows(left)}],right:[${rows(right)}]};`;
|
|
170
|
+
}
|
|
171
|
+
// o p e n | c o d e — must match the engine's bundle byte-for-byte.
|
|
172
|
+
exports.STOCK_WORDMARK = wordmarkRegion([
|
|
173
|
+
" ",
|
|
174
|
+
"█▀▀█ █▀▀█ █▀▀█ █▀▀▄",
|
|
175
|
+
"█__█ █__█ █^^^ █__█",
|
|
176
|
+
"▀▀▀▀ █▀▀▀ ▀▀▀▀ ▀~~▀",
|
|
177
|
+
], [
|
|
178
|
+
" ▄ ",
|
|
179
|
+
"█▀▀▀ █▀▀█ █▀▀█ █▀▀█",
|
|
180
|
+
"█___ █__█ █__█ █^^^",
|
|
181
|
+
"▀▀▀▀ ▀▀▀▀ ▀▀▀▀ ▀▀▀▀",
|
|
182
|
+
]);
|
|
183
|
+
// c o d i | e d e v, rasterized from public/codiedevlogo.svg at eight vertical
|
|
184
|
+
// pixels and packed into four terminal rows with half-block characters. This
|
|
185
|
+
// preserves the real mark's round lowercase bowls, linked c/o, ascenders, and
|
|
186
|
+
// compact v instead of approximating the letters with OpenCode's square font.
|
|
187
|
+
// The engine inserts one column between left and right, so the blank source
|
|
188
|
+
// column at the codi/edev boundary is intentionally omitted.
|
|
189
|
+
const CODIE_LEFT = [
|
|
190
|
+
" ▄ ▄",
|
|
191
|
+
" ▄▄█▄▄ ▄▄█▄▄ ▄████ █",
|
|
192
|
+
" █ ▄██ █ █ ██ █",
|
|
193
|
+
" ▀▀█▀▀ ▀▀█▀▀ ▀▀▀▀ ▀",
|
|
194
|
+
];
|
|
195
|
+
const CODIE_RIGHT = [
|
|
196
|
+
" ▄ ",
|
|
197
|
+
"▄▄█▄▄ ▄▄█▄█ ▄██▄▄▄ ▄▄ ",
|
|
198
|
+
"██▀▀█ █ █ ██▄▀█ ▀█▄█ ",
|
|
199
|
+
"▀▀█▀▀ ▀▀▀▀▀ ▀▀▀▀ ▀▀ ",
|
|
200
|
+
];
|
|
201
|
+
// Migration source for the first hand-drawn banner shipped during development.
|
|
202
|
+
// Recognizing it lets an existing install upgrade in place instead of keeping
|
|
203
|
+
// the old square letterforms until OpenCode happens to reinstall its binary.
|
|
204
|
+
const LEGACY_CODIE_LEFT = [
|
|
205
|
+
" ▄ ▄ ",
|
|
206
|
+
"█▀▀▀ █▀▀█ █▀▀█ █ ",
|
|
207
|
+
"█___ █__█ █__█ █ ",
|
|
208
|
+
"▀▀▀▀ ▀▀▀▀ ▀▀▀▀ ▀ ",
|
|
209
|
+
];
|
|
210
|
+
const LEGACY_CODIE_RIGHT = [
|
|
211
|
+
" ▄ ",
|
|
212
|
+
"█▀▀█ █▀▀█ █▀▀█ █__█",
|
|
213
|
+
"█^^^ █__█ █^^^ █__█",
|
|
214
|
+
"▀▀▀▀ ▀▀▀▀ ▀▀▀▀ ▀▀ ",
|
|
215
|
+
];
|
|
216
|
+
exports.LEGACY_CODIEDEV_WORDMARK = (() => {
|
|
217
|
+
const unpadded = wordmarkRegion(LEGACY_CODIE_LEFT, LEGACY_CODIE_RIGHT);
|
|
218
|
+
const deficit = Buffer.byteLength(exports.STOCK_WORDMARK) - Buffer.byteLength(unpadded);
|
|
219
|
+
const share = Math.floor(deficit / LEGACY_CODIE_RIGHT.length);
|
|
220
|
+
const extra = deficit % LEGACY_CODIE_RIGHT.length;
|
|
221
|
+
const padded = LEGACY_CODIE_RIGHT.map((row, index) => row + " ".repeat(share + (index < extra ? 1 : 0)));
|
|
222
|
+
return wordmarkRegion(LEGACY_CODIE_LEFT, padded);
|
|
223
|
+
})();
|
|
224
|
+
exports.CODIEDEV_WORDMARK = (() => {
|
|
225
|
+
// Raw Unicode is valid JavaScript and costs fewer source bytes than \uXXXX.
|
|
226
|
+
// Put the remaining byte padding outside the strings so it cannot widen the
|
|
227
|
+
// rendered banner or shift its centering.
|
|
228
|
+
const unpadded = wordmarkRegion(CODIE_LEFT, CODIE_RIGHT, { escapeUnicode: false });
|
|
229
|
+
const deficit = Buffer.byteLength(exports.STOCK_WORDMARK) - Buffer.byteLength(unpadded);
|
|
230
|
+
if (deficit < 0)
|
|
231
|
+
throw new Error("Codiedev wordmark is larger than the stock region");
|
|
232
|
+
const region = `${unpadded.slice(0, -1)}${" ".repeat(deficit)};`;
|
|
233
|
+
if (Buffer.byteLength(region) !== Buffer.byteLength(exports.STOCK_WORDMARK)) {
|
|
234
|
+
throw new Error("Codiedev wordmark does not match the stock region byte length");
|
|
235
|
+
}
|
|
236
|
+
return region;
|
|
237
|
+
})();
|
|
238
|
+
exports.HIDDEN_WORDMARK = (() => {
|
|
239
|
+
const unpadded = wordmarkRegion([], [], { escapeUnicode: false });
|
|
240
|
+
const deficit = Buffer.byteLength(exports.STOCK_WORDMARK) - Buffer.byteLength(unpadded);
|
|
241
|
+
if (deficit < 0)
|
|
242
|
+
throw new Error("Hidden wordmark is larger than the stock region");
|
|
243
|
+
const region = `${unpadded.slice(0, -1)}${" ".repeat(deficit)};`;
|
|
244
|
+
if (Buffer.byteLength(region) !== Buffer.byteLength(exports.STOCK_WORDMARK)) {
|
|
245
|
+
throw new Error("Hidden wordmark does not match the stock region byte length");
|
|
246
|
+
}
|
|
247
|
+
return region;
|
|
248
|
+
})();
|
|
249
|
+
// Pure: locate the stock or an earlier Codiedev wordmark in an engine binary.
|
|
250
|
+
// Refuses to touch the file unless exactly one known region appears; an
|
|
251
|
+
// already-hidden or reshaped upstream bundle is left alone.
|
|
252
|
+
function patchBrandWordmark(binary) {
|
|
253
|
+
const stock = Buffer.from(exports.STOCK_WORDMARK);
|
|
254
|
+
const candidates = [stock, Buffer.from(exports.LEGACY_CODIEDEV_WORDMARK), Buffer.from(exports.CODIEDEV_WORDMARK)];
|
|
255
|
+
const matches = candidates.flatMap((candidate) => {
|
|
256
|
+
const offset = binary.indexOf(candidate);
|
|
257
|
+
if (offset === -1)
|
|
258
|
+
return [];
|
|
259
|
+
if (binary.indexOf(candidate, offset + 1) !== -1)
|
|
260
|
+
return [offset, offset];
|
|
261
|
+
return [offset];
|
|
262
|
+
});
|
|
263
|
+
if (matches.length !== 1) {
|
|
264
|
+
return { changed: false, offset: -1, stock, replacement: null };
|
|
265
|
+
}
|
|
266
|
+
return { changed: true, offset: matches[0], stock, replacement: Buffer.from(exports.HIDDEN_WORDMARK) };
|
|
267
|
+
}
|
|
268
|
+
function resolveCapturePlugin({ homeDir, existsSync, }) {
|
|
269
|
+
const capturePath = path.join(homeDir, ".config", "opencode", "plugins", "codiedev.js");
|
|
270
|
+
if (!existsSync(capturePath)) {
|
|
271
|
+
throw new Error("Codiedev session capture is not installed. Run `codiedev connect` first");
|
|
272
|
+
}
|
|
273
|
+
return (0, url_1.pathToFileURL)(capturePath).href;
|
|
274
|
+
}
|
|
275
|
+
async function fetchApprovedCatalog({ baseUrl, key, fetchImpl = fetch, }) {
|
|
276
|
+
const controller = new AbortController();
|
|
277
|
+
const timeout = setTimeout(() => controller.abort(), 5000);
|
|
278
|
+
try {
|
|
279
|
+
const response = await fetchImpl(`${cleanBaseUrl(baseUrl)}/models`, {
|
|
280
|
+
headers: { Authorization: `Bearer ${key}` },
|
|
281
|
+
signal: controller.signal,
|
|
282
|
+
});
|
|
283
|
+
// The `codie` bin ships to every connected machine, including companies
|
|
284
|
+
// whose gateway is still switched off. Those developers must get an
|
|
285
|
+
// answer, not an HTTP status.
|
|
286
|
+
if (response.status === 403) {
|
|
287
|
+
throw new Error("The Codie harness is not enabled for your company yet. Ask your Codiedev admin to turn it on — " +
|
|
288
|
+
"your session capture keeps working in the meantime.");
|
|
289
|
+
}
|
|
290
|
+
if (response.status === 401) {
|
|
291
|
+
throw new Error("Your Codiedev token was rejected. Run `codiedev connect` to relink this machine.");
|
|
292
|
+
}
|
|
293
|
+
if (!response.ok)
|
|
294
|
+
throw new Error(`model catalog returned ${response.status}`);
|
|
295
|
+
const payload = (await response.json());
|
|
296
|
+
if (!Array.isArray(payload?.data) || payload.data.length === 0) {
|
|
297
|
+
throw new Error("model catalog is empty");
|
|
298
|
+
}
|
|
299
|
+
return payload.data.map((model) => ({
|
|
300
|
+
id: bareModel(model.id),
|
|
301
|
+
name: typeof model.name === "string" && model.name ? model.name : DEFAULT_NAMES[bareModel(model.id)],
|
|
302
|
+
}));
|
|
303
|
+
}
|
|
304
|
+
finally {
|
|
305
|
+
clearTimeout(timeout);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
function parseCodieArgs(argv) {
|
|
309
|
+
const args = [];
|
|
310
|
+
const overrides = {};
|
|
311
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
312
|
+
const value = argv[index];
|
|
313
|
+
const next = argv[index + 1];
|
|
314
|
+
if (["--primary-model", "--subagent-model", "--plan-model"].includes(value)) {
|
|
315
|
+
if (!next)
|
|
316
|
+
throw new Error(`${value} requires a model`);
|
|
317
|
+
const envKey = value === "--primary-model"
|
|
318
|
+
? "CODIEDEV_PRIMARY_MODEL"
|
|
319
|
+
: value === "--subagent-model"
|
|
320
|
+
? "CODIEDEV_SUBAGENT_MODEL"
|
|
321
|
+
: "CODIEDEV_PLAN_MODEL";
|
|
322
|
+
overrides[envKey] = bareModel(next);
|
|
323
|
+
index += 1;
|
|
324
|
+
continue;
|
|
325
|
+
}
|
|
326
|
+
if ((value === "-m" || value === "--model") && next) {
|
|
327
|
+
args.push(value, `codiedev/${bareModel(next)}`);
|
|
328
|
+
index += 1;
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
if (value.startsWith("--model=")) {
|
|
332
|
+
args.push(`--model=codiedev/${bareModel(value.slice("--model=".length))}`);
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
args.push(value);
|
|
336
|
+
}
|
|
337
|
+
return { args, overrides };
|
|
338
|
+
}
|
|
339
|
+
function validateCodieArgs(args, catalog) {
|
|
340
|
+
const approved = new Set((catalog || []).map((model) => bareModel(model.id)).filter(Boolean));
|
|
341
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
342
|
+
const value = args[index];
|
|
343
|
+
const model = value === "-m" || value === "--model"
|
|
344
|
+
? args[index + 1]
|
|
345
|
+
: value.startsWith("--model=")
|
|
346
|
+
? value.slice("--model=".length)
|
|
347
|
+
: "";
|
|
348
|
+
if (model && !approved.has(bareModel(model))) {
|
|
349
|
+
throw new Error(`Requested model is not approved for this Codiedev account: ${bareModel(model)}`);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare const OPENCODE_RUNTIME_SPEC = "opencode-ai@1.18.4";
|
|
2
|
+
export declare const CODIE_MIN_NODE_MAJOR = 20;
|
|
3
|
+
export type CodieRuntime = {
|
|
4
|
+
kind: "ready";
|
|
5
|
+
binary: string;
|
|
6
|
+
} | {
|
|
7
|
+
kind: "missing";
|
|
8
|
+
installDir: string;
|
|
9
|
+
binary: string;
|
|
10
|
+
spec: string;
|
|
11
|
+
};
|
|
12
|
+
export declare function codieRuntimeDir(stateDir: string): string;
|
|
13
|
+
export declare function resolveCodieRuntime({ env, stateDir, existsSync, resolveBundled, }: {
|
|
14
|
+
env: Record<string, string | undefined>;
|
|
15
|
+
stateDir: string;
|
|
16
|
+
existsSync: (candidate: string) => boolean;
|
|
17
|
+
resolveBundled: () => string | null;
|
|
18
|
+
}): CodieRuntime;
|
|
19
|
+
export declare function assertCodieNodeVersion(version: string): void;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Where the Codie harness gets its engine.
|
|
3
|
+
//
|
|
4
|
+
// The engine (`opencode-ai`) is a ~132MB platform binary. It is deliberately
|
|
5
|
+
// NOT a dependency of this package: the overwhelming majority of installs are
|
|
6
|
+
// capture-only (Claude Code, Codex, Cursor) and must not pay for a harness
|
|
7
|
+
// they never launch. So `npm i -g codiedev` stays small, and the first `codie`
|
|
8
|
+
// run downloads the engine into the Codiedev state dir.
|
|
9
|
+
//
|
|
10
|
+
// Resolution is pure and injectable so the precedence can be tested without
|
|
11
|
+
// touching the network or a real 132MB install.
|
|
12
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
15
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
16
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
17
|
+
}
|
|
18
|
+
Object.defineProperty(o, k2, desc);
|
|
19
|
+
}) : (function(o, m, k, k2) {
|
|
20
|
+
if (k2 === undefined) k2 = k;
|
|
21
|
+
o[k2] = m[k];
|
|
22
|
+
}));
|
|
23
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
24
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
25
|
+
}) : function(o, v) {
|
|
26
|
+
o["default"] = v;
|
|
27
|
+
});
|
|
28
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
29
|
+
var ownKeys = function(o) {
|
|
30
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
31
|
+
var ar = [];
|
|
32
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
33
|
+
return ar;
|
|
34
|
+
};
|
|
35
|
+
return ownKeys(o);
|
|
36
|
+
};
|
|
37
|
+
return function (mod) {
|
|
38
|
+
if (mod && mod.__esModule) return mod;
|
|
39
|
+
var result = {};
|
|
40
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
41
|
+
__setModuleDefault(result, mod);
|
|
42
|
+
return result;
|
|
43
|
+
};
|
|
44
|
+
})();
|
|
45
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
+
exports.CODIE_MIN_NODE_MAJOR = exports.OPENCODE_RUNTIME_SPEC = void 0;
|
|
47
|
+
exports.codieRuntimeDir = codieRuntimeDir;
|
|
48
|
+
exports.resolveCodieRuntime = resolveCodieRuntime;
|
|
49
|
+
exports.assertCodieNodeVersion = assertCodieNodeVersion;
|
|
50
|
+
const path = __importStar(require("path"));
|
|
51
|
+
// Pinned exactly, not a range. patchBrandWordmark() only rewrites bundles it
|
|
52
|
+
// recognizes byte-for-byte, so a floating version would silently regress the
|
|
53
|
+
// terminal branding whenever OpenCode ships a new build.
|
|
54
|
+
exports.OPENCODE_RUNTIME_SPEC = "opencode-ai@1.18.4";
|
|
55
|
+
// The harness needs 20; capture does not. package.json `engines` stays >=18 so
|
|
56
|
+
// `codiedev connect` still installs for Node 18 users — this floor is enforced
|
|
57
|
+
// at `codie` launch instead.
|
|
58
|
+
exports.CODIE_MIN_NODE_MAJOR = 20;
|
|
59
|
+
function codieRuntimeDir(stateDir) {
|
|
60
|
+
return path.join(stateDir, "runtime");
|
|
61
|
+
}
|
|
62
|
+
function installedBinary(stateDir) {
|
|
63
|
+
return path.join(codieRuntimeDir(stateDir), "node_modules", "opencode-ai", "bin", "opencode.exe");
|
|
64
|
+
}
|
|
65
|
+
function resolveCodieRuntime({ env, stateDir, existsSync, resolveBundled, }) {
|
|
66
|
+
// 1. Explicit override — the air-gapped / pre-provisioned escape hatch.
|
|
67
|
+
const override = env.CODIEDEV_OPENCODE_BINARY?.trim();
|
|
68
|
+
if (override) {
|
|
69
|
+
if (!existsSync(override)) {
|
|
70
|
+
throw new Error(`CODIEDEV_OPENCODE_BINARY points at a missing file: ${override}`);
|
|
71
|
+
}
|
|
72
|
+
return { kind: "ready", binary: override };
|
|
73
|
+
}
|
|
74
|
+
// 2. A bundled engine, if this package was installed with one (dev checkout,
|
|
75
|
+
// or a future vendored distribution).
|
|
76
|
+
const bundled = resolveBundled();
|
|
77
|
+
if (bundled)
|
|
78
|
+
return { kind: "ready", binary: bundled };
|
|
79
|
+
// 3. The lazily installed engine.
|
|
80
|
+
const binary = installedBinary(stateDir);
|
|
81
|
+
if (existsSync(binary))
|
|
82
|
+
return { kind: "ready", binary };
|
|
83
|
+
return { kind: "missing", installDir: codieRuntimeDir(stateDir), binary, spec: exports.OPENCODE_RUNTIME_SPEC };
|
|
84
|
+
}
|
|
85
|
+
function assertCodieNodeVersion(version) {
|
|
86
|
+
const major = Number.parseInt(String(version).split(".")[0], 10);
|
|
87
|
+
if (Number.isFinite(major) && major < exports.CODIE_MIN_NODE_MAJOR) {
|
|
88
|
+
throw new Error(`The Codie harness needs Node ${exports.CODIE_MIN_NODE_MAJOR} or newer (found ${version}). ` +
|
|
89
|
+
`Session capture still works on this version — only \`codie\` requires the upgrade.`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { CodieRuntime } from "./codieRuntime";
|
|
2
|
+
export declare function buildRuntimeInstallArgs(stagingDir: string, spec: string): string[];
|
|
3
|
+
export interface InstallDeps {
|
|
4
|
+
runtime: Extract<CodieRuntime, {
|
|
5
|
+
kind: "missing";
|
|
6
|
+
}>;
|
|
7
|
+
makeStagingDir: () => string;
|
|
8
|
+
run: (args: string[]) => {
|
|
9
|
+
status: number | null;
|
|
10
|
+
stderr: string;
|
|
11
|
+
};
|
|
12
|
+
exists: (candidate: string) => boolean;
|
|
13
|
+
rename: (from: string, to: string) => void;
|
|
14
|
+
remove: (target: string) => void;
|
|
15
|
+
log: (message: string) => void;
|
|
16
|
+
}
|
|
17
|
+
export declare function installCodieRuntime(deps: InstallDeps): void;
|
|
18
|
+
export declare function ensureCodieRuntimeBinary({ resolve, install, }: {
|
|
19
|
+
resolve: () => CodieRuntime;
|
|
20
|
+
install: (runtime: Extract<CodieRuntime, {
|
|
21
|
+
kind: "missing";
|
|
22
|
+
}>) => void;
|
|
23
|
+
}): string;
|
|
24
|
+
export declare function installCodieRuntimeOnDisk(runtime: Extract<CodieRuntime, {
|
|
25
|
+
kind: "missing";
|
|
26
|
+
}>, stateDir: string): void;
|
|
27
|
+
export declare function defaultStagingRoot(): string;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// First-run install of the OpenCode engine for the Codie harness.
|
|
3
|
+
//
|
|
4
|
+
// Staged then renamed: npm writes into a sibling staging directory and only an
|
|
5
|
+
// install that actually produced the engine binary gets promoted to the real
|
|
6
|
+
// runtime path. An interrupted or half-finished download therefore never
|
|
7
|
+
// leaves a directory that resolveCodieRuntime() would report as "ready".
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
+
}) : function(o, v) {
|
|
22
|
+
o["default"] = v;
|
|
23
|
+
});
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.buildRuntimeInstallArgs = buildRuntimeInstallArgs;
|
|
43
|
+
exports.installCodieRuntime = installCodieRuntime;
|
|
44
|
+
exports.ensureCodieRuntimeBinary = ensureCodieRuntimeBinary;
|
|
45
|
+
exports.installCodieRuntimeOnDisk = installCodieRuntimeOnDisk;
|
|
46
|
+
exports.defaultStagingRoot = defaultStagingRoot;
|
|
47
|
+
const fs = __importStar(require("fs"));
|
|
48
|
+
const os = __importStar(require("os"));
|
|
49
|
+
const path = __importStar(require("path"));
|
|
50
|
+
const child_process_1 = require("child_process");
|
|
51
|
+
const codieRuntime_1 = require("./codieRuntime");
|
|
52
|
+
function buildRuntimeInstallArgs(stagingDir, spec) {
|
|
53
|
+
// No --registry / --proxy: inherit whatever npm config the developer's
|
|
54
|
+
// machine already has so an internal mirror keeps working.
|
|
55
|
+
return [
|
|
56
|
+
"install",
|
|
57
|
+
"--prefix",
|
|
58
|
+
stagingDir,
|
|
59
|
+
"--no-audit",
|
|
60
|
+
"--no-fund",
|
|
61
|
+
"--omit=dev",
|
|
62
|
+
"--loglevel=error",
|
|
63
|
+
spec,
|
|
64
|
+
];
|
|
65
|
+
}
|
|
66
|
+
function installCodieRuntime(deps) {
|
|
67
|
+
const { runtime, makeStagingDir, run, exists, rename, remove, log } = deps;
|
|
68
|
+
const staging = makeStagingDir();
|
|
69
|
+
log(`Installing the Codie engine (${runtime.spec}). This runs once, and only for \`codie\`.`);
|
|
70
|
+
let result;
|
|
71
|
+
try {
|
|
72
|
+
result = run(buildRuntimeInstallArgs(staging, runtime.spec));
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
remove(staging);
|
|
76
|
+
throw installFailure(error instanceof Error ? error.message : String(error));
|
|
77
|
+
}
|
|
78
|
+
if (result.status !== 0) {
|
|
79
|
+
remove(staging);
|
|
80
|
+
throw installFailure(result.stderr?.trim() || `npm exited with ${result.status}`);
|
|
81
|
+
}
|
|
82
|
+
// Trust the artifact, not the exit code — a misconfigured mirror can succeed
|
|
83
|
+
// with nothing useful in the tarball.
|
|
84
|
+
const stagedBinary = path.join(staging, "node_modules", "opencode-ai", "bin", "opencode.exe");
|
|
85
|
+
if (!exists(stagedBinary)) {
|
|
86
|
+
remove(staging);
|
|
87
|
+
throw new Error(`The Codie engine install did not produce a runtime binary. ` +
|
|
88
|
+
`Check that ${runtime.spec} is available from your npm registry.`);
|
|
89
|
+
}
|
|
90
|
+
try {
|
|
91
|
+
rename(staging, runtime.installDir);
|
|
92
|
+
}
|
|
93
|
+
finally {
|
|
94
|
+
// No-op after a successful promote (rmSync is force: true); after a failed
|
|
95
|
+
// one it keeps a ~132MB staging dir from being orphaned — mkdtemp mints a
|
|
96
|
+
// fresh sibling every attempt, so leaks would accumulate.
|
|
97
|
+
remove(staging);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
// Resolve the engine, downloading it once if this is the first `codie` run.
|
|
101
|
+
function ensureCodieRuntimeBinary({ resolve, install, }) {
|
|
102
|
+
const runtime = resolve();
|
|
103
|
+
if (runtime.kind === "ready")
|
|
104
|
+
return runtime.binary;
|
|
105
|
+
install(runtime);
|
|
106
|
+
return runtime.binary;
|
|
107
|
+
}
|
|
108
|
+
function installFailure(detail) {
|
|
109
|
+
return new Error(`Could not download the Codie engine: ${detail}\n` +
|
|
110
|
+
`If you are behind a proxy or an internal registry, make sure npm can reach it. ` +
|
|
111
|
+
`To use a pre-provisioned engine instead, set CODIEDEV_OPENCODE_BINARY to its path.`);
|
|
112
|
+
}
|
|
113
|
+
// ── Real-world wiring ───────────────────────────────────────────────────
|
|
114
|
+
// Kept separate from the pure logic above so tests never shell out to npm.
|
|
115
|
+
function installCodieRuntimeOnDisk(runtime, stateDir) {
|
|
116
|
+
installCodieRuntime({
|
|
117
|
+
runtime,
|
|
118
|
+
makeStagingDir: () => {
|
|
119
|
+
// Sibling of the final dir so the promote is a same-filesystem rename.
|
|
120
|
+
fs.mkdirSync(path.dirname((0, codieRuntime_1.codieRuntimeDir)(stateDir)), { recursive: true });
|
|
121
|
+
return fs.mkdtempSync(path.join(path.dirname((0, codieRuntime_1.codieRuntimeDir)(stateDir)), ".runtime-staging-"));
|
|
122
|
+
},
|
|
123
|
+
run: (args) => {
|
|
124
|
+
const npm = process.platform === "win32" ? "npm.cmd" : "npm";
|
|
125
|
+
const result = (0, child_process_1.spawnSync)(npm, args, {
|
|
126
|
+
encoding: "utf8",
|
|
127
|
+
stdio: ["ignore", "inherit", "pipe"],
|
|
128
|
+
env: { ...process.env, npm_config_yes: "true" },
|
|
129
|
+
});
|
|
130
|
+
if (result.error)
|
|
131
|
+
throw result.error;
|
|
132
|
+
return { status: result.status, stderr: result.stderr || "" };
|
|
133
|
+
},
|
|
134
|
+
exists: (candidate) => fs.existsSync(candidate),
|
|
135
|
+
rename: (from, to) => {
|
|
136
|
+
fs.rmSync(to, { recursive: true, force: true });
|
|
137
|
+
fs.renameSync(from, to);
|
|
138
|
+
},
|
|
139
|
+
remove: (target) => fs.rmSync(target, { recursive: true, force: true }),
|
|
140
|
+
log: (message) => console.error(message),
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
function defaultStagingRoot() {
|
|
144
|
+
return os.tmpdir();
|
|
145
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function codiedevStateDir(): string;
|