agentful 0.4.45 → 0.4.47
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 +35 -6
- package/THIRD-PARTY-LICENSES.txt +24 -0
- package/dist/engine-tools/imagegen.js +35 -0
- package/dist/index.cjs +435 -74
- package/package.json +8 -4
- package/assets/tools/imagegen.ts +0 -639
- package/assets/tools/package.json +0 -8
package/dist/index.cjs
CHANGED
|
@@ -3044,7 +3044,7 @@ var VERSION, brand, useColor, wrap, paint, tuiDesign, sym, ui;
|
|
|
3044
3044
|
var init_branding = __esm({
|
|
3045
3045
|
"src/branding.ts"() {
|
|
3046
3046
|
"use strict";
|
|
3047
|
-
VERSION = "0.4.
|
|
3047
|
+
VERSION = "0.4.47" ? "0.4.47" : null.version;
|
|
3048
3048
|
brand = {
|
|
3049
3049
|
name: "agentful",
|
|
3050
3050
|
// the command users type
|
|
@@ -4303,7 +4303,7 @@ var DEFAULT_RETRY = {
|
|
|
4303
4303
|
function isRetryableStatus(status) {
|
|
4304
4304
|
return RETRYABLE_STATUSES.has(status);
|
|
4305
4305
|
}
|
|
4306
|
-
var sleep = (ms) => new Promise((
|
|
4306
|
+
var sleep = (ms) => new Promise((resolve3) => setTimeout(resolve3, ms));
|
|
4307
4307
|
async function request(url, opts = {}) {
|
|
4308
4308
|
const attempts = Math.max(1, opts.retry?.attempts ?? (opts.retry ? DEFAULT_RETRY.attempts : 1));
|
|
4309
4309
|
const delayMs = opts.retry?.delayMs ?? DEFAULT_RETRY.delayMs;
|
|
@@ -7651,20 +7651,46 @@ ${cmd.template}
|
|
|
7651
7651
|
// src/lib/tools.ts
|
|
7652
7652
|
var import_node_fs9 = require("fs");
|
|
7653
7653
|
var import_node_path10 = require("path");
|
|
7654
|
-
|
|
7655
|
-
|
|
7656
|
-
|
|
7657
|
-
|
|
7654
|
+
var TOOLS_DIR = "engine-tools";
|
|
7655
|
+
function bundledToolsDir(entry) {
|
|
7656
|
+
let here;
|
|
7657
|
+
try {
|
|
7658
|
+
here = (0, import_node_path10.dirname)((0, import_node_fs9.realpathSync)(entry));
|
|
7659
|
+
} catch {
|
|
7660
|
+
return null;
|
|
7661
|
+
}
|
|
7662
|
+
for (const candidate of [(0, import_node_path10.join)(here, TOOLS_DIR), (0, import_node_path10.join)(here, "..", "dist", TOOLS_DIR)]) {
|
|
7663
|
+
if ((0, import_node_fs9.existsSync)((0, import_node_path10.join)(candidate, "imagegen.js"))) return candidate;
|
|
7658
7664
|
}
|
|
7659
7665
|
return null;
|
|
7660
7666
|
}
|
|
7661
|
-
function
|
|
7662
|
-
|
|
7663
|
-
|
|
7667
|
+
function removeUnbundledTool(target) {
|
|
7668
|
+
(0, import_node_fs9.rmSync)((0, import_node_path10.join)(target, "imagegen.ts"), { force: true });
|
|
7669
|
+
try {
|
|
7670
|
+
const manifest = (0, import_node_path10.join)(target, "package.json");
|
|
7671
|
+
if (JSON.parse((0, import_node_fs9.readFileSync)(manifest, "utf8")).name === "agentful-engine-tools") (0, import_node_fs9.rmSync)(manifest, { force: true });
|
|
7672
|
+
} catch {
|
|
7673
|
+
}
|
|
7674
|
+
}
|
|
7675
|
+
var ENGINE_PLUGIN = "@opencode-ai/plugin";
|
|
7676
|
+
function skipRegistryInstall(configDir2) {
|
|
7677
|
+
const lock = (0, import_node_path10.join)(configDir2, "package-lock.json");
|
|
7678
|
+
const manifest = (0, import_node_path10.join)(configDir2, "package.json");
|
|
7679
|
+
(0, import_node_fs9.mkdirSync)((0, import_node_path10.join)(configDir2, "node_modules"), { recursive: true });
|
|
7680
|
+
if ((0, import_node_fs9.existsSync)(lock)) return;
|
|
7681
|
+
const dependencies2 = { [ENGINE_PLUGIN]: "*" };
|
|
7682
|
+
(0, import_node_fs9.writeFileSync)(lock, JSON.stringify({ lockfileVersion: 3, requires: true, packages: { "": { dependencies: dependencies2 } } }, null, 2) + "\n");
|
|
7683
|
+
if (!(0, import_node_fs9.existsSync)(manifest)) (0, import_node_fs9.writeFileSync)(manifest, JSON.stringify({ private: true, dependencies: dependencies2 }, null, 2) + "\n");
|
|
7684
|
+
}
|
|
7685
|
+
function installEngineTools(configDir2, entry = process.argv[1] || "") {
|
|
7664
7686
|
const target = (0, import_node_path10.join)(configDir2, "tools");
|
|
7665
|
-
(0, import_node_fs9.mkdirSync)(target, { recursive: true });
|
|
7666
7687
|
try {
|
|
7667
|
-
(
|
|
7688
|
+
removeUnbundledTool(target);
|
|
7689
|
+
const source = bundledToolsDir(entry);
|
|
7690
|
+
if (!source) return false;
|
|
7691
|
+
(0, import_node_fs9.mkdirSync)(target, { recursive: true });
|
|
7692
|
+
for (const file of (0, import_node_fs9.readdirSync)(source)) (0, import_node_fs9.copyFileSync)((0, import_node_path10.join)(source, file), (0, import_node_path10.join)(target, file));
|
|
7693
|
+
skipRegistryInstall(configDir2);
|
|
7668
7694
|
return true;
|
|
7669
7695
|
} catch {
|
|
7670
7696
|
return false;
|
|
@@ -9409,7 +9435,7 @@ async function openCommand() {
|
|
|
9409
9435
|
// src/commands/tui.ts
|
|
9410
9436
|
var import_node_child_process6 = require("child_process");
|
|
9411
9437
|
var import_promises4 = require("readline/promises");
|
|
9412
|
-
var
|
|
9438
|
+
var import_node_path23 = require("path");
|
|
9413
9439
|
|
|
9414
9440
|
// src/lib/binWrapper.ts
|
|
9415
9441
|
var import_node_fs13 = require("fs");
|
|
@@ -9836,7 +9862,18 @@ var LEVELS = ["org", "department", "person"];
|
|
|
9836
9862
|
function asLevel(value) {
|
|
9837
9863
|
return LEVELS.includes(value) ? value : void 0;
|
|
9838
9864
|
}
|
|
9839
|
-
async function
|
|
9865
|
+
async function isPrivateProject(auth, projectId) {
|
|
9866
|
+
try {
|
|
9867
|
+
const res = await request(
|
|
9868
|
+
`${PB_URL}/api/llm/available-models?project=${encodeURIComponent(projectId)}`,
|
|
9869
|
+
{ token: auth.pb_token, timeoutMs: 1e4 }
|
|
9870
|
+
);
|
|
9871
|
+
return res?.org_policy?.has_org === false;
|
|
9872
|
+
} catch {
|
|
9873
|
+
return false;
|
|
9874
|
+
}
|
|
9875
|
+
}
|
|
9876
|
+
async function fetchLocalProviderPolicy(auth, projectId) {
|
|
9840
9877
|
try {
|
|
9841
9878
|
const me = await request(`${PB_URL}/api/org/me`, { token: auth.pb_token, timeoutMs: 1e4 });
|
|
9842
9879
|
if (!me?.has_org) return { hasOrg: false, allowedProviders: [] };
|
|
@@ -9845,6 +9882,9 @@ async function fetchLocalProviderPolicy(auth) {
|
|
|
9845
9882
|
const modelLevels = Array.isArray(sources.allowed_models) ? LEVELS.filter((l) => sources.allowed_models.includes(l)) : [];
|
|
9846
9883
|
return {
|
|
9847
9884
|
hasOrg: true,
|
|
9885
|
+
privateProject: projectId ? await isPrivateProject(auth, projectId) : false,
|
|
9886
|
+
regionCap: typeof policy.region_cap === "string" ? policy.region_cap : void 0,
|
|
9887
|
+
regionLevel: asLevel(sources.region_cap),
|
|
9848
9888
|
byokMode: policy.byok_mode || "allow",
|
|
9849
9889
|
allowedProviders: Array.isArray(policy.allowed_byok_providers) ? policy.allowed_byok_providers : [],
|
|
9850
9890
|
// /api/org/me reports the org as `org.id`; effective_policy carries no
|
|
@@ -9856,7 +9896,7 @@ async function fetchLocalProviderPolicy(auth) {
|
|
|
9856
9896
|
byokLevel: asLevel(sources.byok_mode)
|
|
9857
9897
|
};
|
|
9858
9898
|
} catch {
|
|
9859
|
-
return { hasOrg: true, byokMode: "disabled", allowedProviders: [] };
|
|
9899
|
+
return { hasOrg: true, unreadable: true, byokMode: "disabled", allowedProviders: [] };
|
|
9860
9900
|
}
|
|
9861
9901
|
}
|
|
9862
9902
|
function levelName(policy, level) {
|
|
@@ -9869,24 +9909,54 @@ function levelName(policy, level) {
|
|
|
9869
9909
|
function capitalize(text) {
|
|
9870
9910
|
return text.charAt(0).toUpperCase() + text.slice(1);
|
|
9871
9911
|
}
|
|
9872
|
-
function
|
|
9873
|
-
|
|
9912
|
+
function isOrganizationWork(policy) {
|
|
9913
|
+
return policy.hasOrg && !policy.privateProject;
|
|
9914
|
+
}
|
|
9915
|
+
var REGION_NAME = { de: "Germany", eu: "EU" };
|
|
9916
|
+
function decideProviders(policy) {
|
|
9917
|
+
const any = { limited: false, allowlist: [], allowLoopback: true };
|
|
9918
|
+
if (!isOrganizationWork(policy)) return any;
|
|
9919
|
+
if (policy.unreadable) {
|
|
9920
|
+
return {
|
|
9921
|
+
limited: true,
|
|
9922
|
+
allowlist: [],
|
|
9923
|
+
allowLoopback: false,
|
|
9924
|
+
reason: "Your organization's rules could not be read, so only Agentful models are available."
|
|
9925
|
+
};
|
|
9926
|
+
}
|
|
9874
9927
|
const who = capitalize(levelName(policy, policy.byokLevel));
|
|
9875
9928
|
if (policy.byokMode === "disabled") {
|
|
9876
9929
|
return {
|
|
9877
|
-
|
|
9930
|
+
limited: true,
|
|
9878
9931
|
allowlist: [],
|
|
9879
|
-
|
|
9932
|
+
allowLoopback: false,
|
|
9933
|
+
reason: `${who} has disabled bring-your-own-key, which includes local providers and direct connections.`
|
|
9880
9934
|
};
|
|
9881
9935
|
}
|
|
9882
9936
|
if (policy.byokMode === "provider_allowlist") {
|
|
9883
9937
|
return {
|
|
9884
|
-
|
|
9938
|
+
limited: true,
|
|
9885
9939
|
allowlist: policy.allowedProviders,
|
|
9940
|
+
allowLoopback: false,
|
|
9886
9941
|
reason: `${who} allows only these providers: ${policy.allowedProviders.join(", ") || "(none)"}`
|
|
9887
9942
|
};
|
|
9888
9943
|
}
|
|
9889
|
-
|
|
9944
|
+
if (policy.regionCap === "us_eu") return any;
|
|
9945
|
+
const region = REGION_NAME[policy.regionCap ?? ""];
|
|
9946
|
+
return {
|
|
9947
|
+
limited: true,
|
|
9948
|
+
allowlist: [],
|
|
9949
|
+
allowLoopback: true,
|
|
9950
|
+
reason: `${capitalize(levelName(policy, policy.regionLevel))} has set the data region${region ? ` ${region}` : ""}: only Agentful models and models on this machine are available.`
|
|
9951
|
+
};
|
|
9952
|
+
}
|
|
9953
|
+
function enabledProviders(decision, localProviderIds) {
|
|
9954
|
+
if (!decision.limited) return void 0;
|
|
9955
|
+
return Array.from(/* @__PURE__ */ new Set(["agentful", ...decision.allowlist, ...localProviderIds]));
|
|
9956
|
+
}
|
|
9957
|
+
function blockedConnections(decision, connected, localProviderIds) {
|
|
9958
|
+
const enabled2 = enabledProviders(decision, localProviderIds);
|
|
9959
|
+
return enabled2 ? connected.filter((id) => !enabled2.includes(id)) : [];
|
|
9890
9960
|
}
|
|
9891
9961
|
function policyRequestHint(policy) {
|
|
9892
9962
|
if (!policy.hasOrg) return void 0;
|
|
@@ -9924,21 +9994,31 @@ function readLocalProviders() {
|
|
|
9924
9994
|
}
|
|
9925
9995
|
return {};
|
|
9926
9996
|
}
|
|
9997
|
+
function isLoopbackProvider(config) {
|
|
9998
|
+
const baseURL = config.options?.baseURL;
|
|
9999
|
+
if (typeof baseURL !== "string") return false;
|
|
10000
|
+
let host;
|
|
10001
|
+
try {
|
|
10002
|
+
host = new URL(baseURL).hostname.toLowerCase();
|
|
10003
|
+
} catch {
|
|
10004
|
+
return false;
|
|
10005
|
+
}
|
|
10006
|
+
const loopback = host === "localhost" || host === "[::1]" || /^127(\.\d{1,3}){3}$/.test(host);
|
|
10007
|
+
if (!loopback) return false;
|
|
10008
|
+
const models = Object.values(config.models ?? {});
|
|
10009
|
+
return models.every((m) => !(m && typeof m === "object" && "provider" in m));
|
|
10010
|
+
}
|
|
9927
10011
|
function resolveLocalProviders(policy) {
|
|
9928
10012
|
const configured = readLocalProviders();
|
|
9929
10013
|
const ids = Object.keys(configured);
|
|
9930
10014
|
if (!ids.length) return { providers: {}, blocked: [] };
|
|
9931
|
-
const decision =
|
|
9932
|
-
if (!decision.
|
|
9933
|
-
return { providers: {}, blocked: ids, policyReason: decision.reason };
|
|
9934
|
-
}
|
|
9935
|
-
if (!decision.allowlist.length) {
|
|
9936
|
-
return { providers: configured, blocked: [] };
|
|
9937
|
-
}
|
|
10015
|
+
const decision = decideProviders(policy);
|
|
10016
|
+
if (!decision.limited) return { providers: configured, blocked: [] };
|
|
9938
10017
|
const providers = {};
|
|
9939
10018
|
const blocked = [];
|
|
9940
10019
|
for (const id of ids) {
|
|
9941
|
-
|
|
10020
|
+
const permitted = decision.allowlist.includes(id) || decision.allowLoopback && isLoopbackProvider(configured[id]);
|
|
10021
|
+
if (permitted) providers[id] = configured[id];
|
|
9942
10022
|
else blocked.push(id);
|
|
9943
10023
|
}
|
|
9944
10024
|
return { providers, blocked, policyReason: blocked.length ? decision.reason : void 0 };
|
|
@@ -10166,10 +10246,11 @@ function parseEngineModelsOutput(output) {
|
|
|
10166
10246
|
function modelProvider(model) {
|
|
10167
10247
|
return model.slice(0, model.indexOf("/"));
|
|
10168
10248
|
}
|
|
10169
|
-
async function listEngineModels(binPath, xdg, provider) {
|
|
10249
|
+
async function listEngineModels(binPath, xdg, provider, guardEnv) {
|
|
10170
10250
|
const { stdout } = await execFileAsync(binPath, ["models", provider], {
|
|
10171
10251
|
env: {
|
|
10172
10252
|
...process.env,
|
|
10253
|
+
...guardEnv,
|
|
10173
10254
|
XDG_CONFIG_HOME: xdg.configHome,
|
|
10174
10255
|
XDG_DATA_HOME: xdg.dataHome,
|
|
10175
10256
|
XDG_STATE_HOME: xdg.stateHome,
|
|
@@ -10181,10 +10262,11 @@ async function listEngineModels(binPath, xdg, provider) {
|
|
|
10181
10262
|
});
|
|
10182
10263
|
return parseEngineModelsOutput(stdout);
|
|
10183
10264
|
}
|
|
10184
|
-
async function refreshEngineModelCache(binPath, xdg) {
|
|
10265
|
+
async function refreshEngineModelCache(binPath, xdg, guardEnv) {
|
|
10185
10266
|
await execFileAsync(binPath, ["models", "--refresh"], {
|
|
10186
10267
|
env: {
|
|
10187
10268
|
...process.env,
|
|
10269
|
+
...guardEnv,
|
|
10188
10270
|
XDG_CONFIG_HOME: xdg.configHome,
|
|
10189
10271
|
XDG_DATA_HOME: xdg.dataHome,
|
|
10190
10272
|
XDG_STATE_HOME: xdg.stateHome,
|
|
@@ -10195,9 +10277,9 @@ async function refreshEngineModelCache(binPath, xdg) {
|
|
|
10195
10277
|
timeout: 6e4
|
|
10196
10278
|
});
|
|
10197
10279
|
}
|
|
10198
|
-
async function assertEngineModelAvailable(binPath, xdg, model, listModels = listEngineModels) {
|
|
10280
|
+
async function assertEngineModelAvailable(binPath, xdg, model, guardEnv, listModels = listEngineModels) {
|
|
10199
10281
|
const provider = modelProvider(model);
|
|
10200
|
-
const models = await listModels(binPath, xdg, provider);
|
|
10282
|
+
const models = await listModels(binPath, xdg, provider, guardEnv);
|
|
10201
10283
|
if (!models.includes(model)) {
|
|
10202
10284
|
const examples = models.slice(0, 5);
|
|
10203
10285
|
const hint = examples.length ? ` Available for ${provider}: ${examples.join(", ")}.` : "";
|
|
@@ -10237,8 +10319,183 @@ function describeModelRoute(model, catalog, localProviders, connectedProviders)
|
|
|
10237
10319
|
return "external engine route \u2014 provider setup and terms apply; no Agentful credits or region guarantee";
|
|
10238
10320
|
}
|
|
10239
10321
|
|
|
10240
|
-
// src/lib/
|
|
10322
|
+
// src/lib/engineGuard.ts
|
|
10241
10323
|
var import_node_crypto4 = require("crypto");
|
|
10324
|
+
var import_node_fs20 = require("fs");
|
|
10325
|
+
var import_node_os6 = require("os");
|
|
10326
|
+
var import_node_path22 = require("path");
|
|
10327
|
+
var TRUSTED_FOLDERS_FILE = "trusted-folders.json";
|
|
10328
|
+
var CONFIG_NAMES = ["opencode.json", "opencode.jsonc"];
|
|
10329
|
+
var TUI_NAMES = ["tui.json", "tui.jsonc"];
|
|
10330
|
+
var ENGINE_DIRS = [
|
|
10331
|
+
"agent",
|
|
10332
|
+
"agents",
|
|
10333
|
+
"command",
|
|
10334
|
+
"commands",
|
|
10335
|
+
"mode",
|
|
10336
|
+
"modes",
|
|
10337
|
+
"plugin",
|
|
10338
|
+
"plugins",
|
|
10339
|
+
"skill",
|
|
10340
|
+
"skills",
|
|
10341
|
+
"theme",
|
|
10342
|
+
"themes",
|
|
10343
|
+
"tool",
|
|
10344
|
+
"tools"
|
|
10345
|
+
];
|
|
10346
|
+
var MAX_FILES = 400;
|
|
10347
|
+
var MAX_DEPTH = 6;
|
|
10348
|
+
var INSTRUCTION_NAMES = ["AGENTS.md", "CLAUDE.md", "CONTEXT.md"];
|
|
10349
|
+
function ancestors(start, stop) {
|
|
10350
|
+
const out = [];
|
|
10351
|
+
let dir = start;
|
|
10352
|
+
for (; ; ) {
|
|
10353
|
+
out.push(dir);
|
|
10354
|
+
if (dir === stop) break;
|
|
10355
|
+
const parent = (0, import_node_path22.dirname)(dir);
|
|
10356
|
+
if (parent === dir) break;
|
|
10357
|
+
dir = parent;
|
|
10358
|
+
}
|
|
10359
|
+
return out;
|
|
10360
|
+
}
|
|
10361
|
+
function realFolder(cwd) {
|
|
10362
|
+
try {
|
|
10363
|
+
return (0, import_node_fs20.realpathSync)(cwd);
|
|
10364
|
+
} catch {
|
|
10365
|
+
return (0, import_node_path22.resolve)(cwd);
|
|
10366
|
+
}
|
|
10367
|
+
}
|
|
10368
|
+
function worktreeOf(dir) {
|
|
10369
|
+
return ancestors(dir).find((d) => (0, import_node_fs20.existsSync)((0, import_node_path22.join)(d, ".git")));
|
|
10370
|
+
}
|
|
10371
|
+
function isFile(path) {
|
|
10372
|
+
try {
|
|
10373
|
+
return (0, import_node_fs20.statSync)(path).isFile();
|
|
10374
|
+
} catch {
|
|
10375
|
+
return false;
|
|
10376
|
+
}
|
|
10377
|
+
}
|
|
10378
|
+
function isDirectory(path) {
|
|
10379
|
+
try {
|
|
10380
|
+
return (0, import_node_fs20.statSync)(path).isDirectory();
|
|
10381
|
+
} catch {
|
|
10382
|
+
return false;
|
|
10383
|
+
}
|
|
10384
|
+
}
|
|
10385
|
+
function filesBelow(dir, depth, out) {
|
|
10386
|
+
if (depth > MAX_DEPTH || out.length >= MAX_FILES) return;
|
|
10387
|
+
let names;
|
|
10388
|
+
try {
|
|
10389
|
+
names = (0, import_node_fs20.readdirSync)(dir).sort();
|
|
10390
|
+
} catch {
|
|
10391
|
+
return;
|
|
10392
|
+
}
|
|
10393
|
+
for (const name2 of names) {
|
|
10394
|
+
if (name2 === "node_modules" || name2 === ".git") continue;
|
|
10395
|
+
const path = (0, import_node_path22.join)(dir, name2);
|
|
10396
|
+
if (isDirectory(path)) filesBelow(path, depth + 1, out);
|
|
10397
|
+
else if (out.length < MAX_FILES) out.push(path);
|
|
10398
|
+
}
|
|
10399
|
+
}
|
|
10400
|
+
function findFolderSettings(cwd = process.cwd(), home = (0, import_node_os6.homedir)()) {
|
|
10401
|
+
const start = realFolder(cwd);
|
|
10402
|
+
const homeDir = realFolder(home);
|
|
10403
|
+
const stop = worktreeOf(start);
|
|
10404
|
+
const configDirs = new Set(ancestors(start, stop));
|
|
10405
|
+
const files = [];
|
|
10406
|
+
for (const dir of ancestors(start)) {
|
|
10407
|
+
if (configDirs.has(dir)) files.push(...CONFIG_NAMES.map((n) => (0, import_node_path22.join)(dir, n)).filter(isFile));
|
|
10408
|
+
files.push(...TUI_NAMES.map((n) => (0, import_node_path22.join)(dir, n)).filter(isFile));
|
|
10409
|
+
const dot = (0, import_node_path22.join)(dir, ".opencode");
|
|
10410
|
+
if (dir === homeDir || !isDirectory(dot)) continue;
|
|
10411
|
+
files.push(...[...CONFIG_NAMES, ...TUI_NAMES].map((n) => (0, import_node_path22.join)(dot, n)).filter(isFile));
|
|
10412
|
+
for (const name2 of ENGINE_DIRS) {
|
|
10413
|
+
const sub = (0, import_node_path22.join)(dot, name2);
|
|
10414
|
+
if (isDirectory(sub)) filesBelow(sub, 1, files);
|
|
10415
|
+
}
|
|
10416
|
+
}
|
|
10417
|
+
if (!files.length) return { files, fingerprint: "" };
|
|
10418
|
+
const hash = (0, import_node_crypto4.createHash)("sha256");
|
|
10419
|
+
for (const path of files) {
|
|
10420
|
+
hash.update(path).update("\0");
|
|
10421
|
+
try {
|
|
10422
|
+
hash.update((0, import_node_crypto4.createHash)("sha256").update((0, import_node_fs20.readFileSync)(path)).digest());
|
|
10423
|
+
} catch {
|
|
10424
|
+
hash.update("unreadable");
|
|
10425
|
+
}
|
|
10426
|
+
}
|
|
10427
|
+
if (files.length >= MAX_FILES) hash.update((0, import_node_crypto4.randomUUID)());
|
|
10428
|
+
return { files, fingerprint: hash.digest("hex") };
|
|
10429
|
+
}
|
|
10430
|
+
function findProjectInstructions(cwd = process.cwd()) {
|
|
10431
|
+
const start = realFolder(cwd);
|
|
10432
|
+
const dirs = ancestors(start, worktreeOf(start));
|
|
10433
|
+
for (const name2 of INSTRUCTION_NAMES) {
|
|
10434
|
+
const found = dirs.map((dir) => (0, import_node_path22.join)(dir, name2)).filter(isFile);
|
|
10435
|
+
if (found.length) return found;
|
|
10436
|
+
}
|
|
10437
|
+
return [];
|
|
10438
|
+
}
|
|
10439
|
+
function describeFolderFiles(files, cwd = process.cwd(), max = 6) {
|
|
10440
|
+
const start = realFolder(cwd);
|
|
10441
|
+
const shown = files.slice(0, max).map((path) => {
|
|
10442
|
+
const rel = (0, import_node_path22.relative)(start, path);
|
|
10443
|
+
return (rel.startsWith("..") ? path : rel).replace(/[\u0000-\u001f\u007f-\u009f]/g, "?");
|
|
10444
|
+
});
|
|
10445
|
+
if (files.length > max) shown.push(`\u2026 and ${files.length - max} more`);
|
|
10446
|
+
return shown;
|
|
10447
|
+
}
|
|
10448
|
+
function trustPath() {
|
|
10449
|
+
return (0, import_node_path22.join)(configDir(), TRUSTED_FOLDERS_FILE);
|
|
10450
|
+
}
|
|
10451
|
+
function readTrust() {
|
|
10452
|
+
try {
|
|
10453
|
+
const parsed = JSON.parse((0, import_node_fs20.readFileSync)(trustPath(), "utf8"));
|
|
10454
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
|
|
10455
|
+
} catch {
|
|
10456
|
+
return {};
|
|
10457
|
+
}
|
|
10458
|
+
}
|
|
10459
|
+
function rememberedFolderAnswer(settings, cwd = process.cwd()) {
|
|
10460
|
+
const store = readTrust();
|
|
10461
|
+
const key = realFolder(cwd);
|
|
10462
|
+
const entry = Object.hasOwn(store, key) ? store[key] : void 0;
|
|
10463
|
+
return entry && entry.fingerprint === settings.fingerprint && typeof entry.load === "boolean" ? entry.load : void 0;
|
|
10464
|
+
}
|
|
10465
|
+
function rememberFolderAnswer(settings, load, cwd = process.cwd()) {
|
|
10466
|
+
const store = readTrust();
|
|
10467
|
+
store[realFolder(cwd)] = { fingerprint: settings.fingerprint, load, answered_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
10468
|
+
(0, import_node_fs20.mkdirSync)(configDir(), { recursive: true });
|
|
10469
|
+
(0, import_node_fs20.writeFileSync)(trustPath(), JSON.stringify(store, null, 2) + "\n", { mode: 384 });
|
|
10470
|
+
try {
|
|
10471
|
+
(0, import_node_fs20.chmodSync)(trustPath(), 384);
|
|
10472
|
+
} catch {
|
|
10473
|
+
}
|
|
10474
|
+
}
|
|
10475
|
+
function decideFolderSettings(input) {
|
|
10476
|
+
if (!input.settings.files.length) return { kind: "nothing" };
|
|
10477
|
+
if (input.organizationWork) return { kind: "skip", reason: "organization" };
|
|
10478
|
+
if (input.remembered !== void 0 && !(input.askAgain && input.interactive)) {
|
|
10479
|
+
return input.remembered ? { kind: "load" } : { kind: "skip", reason: "declined" };
|
|
10480
|
+
}
|
|
10481
|
+
return input.interactive ? { kind: "ask" } : { kind: "skip", reason: "non_interactive" };
|
|
10482
|
+
}
|
|
10483
|
+
function engineGuardEnv(opts) {
|
|
10484
|
+
const instructions = opts.loadFolderSettings ? [] : findProjectInstructions(opts.cwd);
|
|
10485
|
+
const inline = {
|
|
10486
|
+
provider: { agentful: { options: { baseURL: opts.gatewayUrl } } },
|
|
10487
|
+
...opts.enabledProviders ? { enabled_providers: opts.enabledProviders } : {},
|
|
10488
|
+
...instructions.length ? { instructions } : {}
|
|
10489
|
+
};
|
|
10490
|
+
return {
|
|
10491
|
+
OPENCODE_CONFIG_CONTENT: JSON.stringify(inline),
|
|
10492
|
+
// Always explicit: a CLI started from inside a TUI inherits the outer value.
|
|
10493
|
+
OPENCODE_DISABLE_PROJECT_CONFIG: opts.loadFolderSettings ? "false" : "true"
|
|
10494
|
+
};
|
|
10495
|
+
}
|
|
10496
|
+
|
|
10497
|
+
// src/lib/engineEvents.ts
|
|
10498
|
+
var import_node_crypto5 = require("crypto");
|
|
10242
10499
|
var import_node_net = require("net");
|
|
10243
10500
|
function payloadOf(event) {
|
|
10244
10501
|
return event.payload && typeof event.payload === "object" ? event.payload : event;
|
|
@@ -10364,17 +10621,17 @@ var EngineLivenessPolicy = class {
|
|
|
10364
10621
|
function engineServerCredentials(env = process.env) {
|
|
10365
10622
|
return {
|
|
10366
10623
|
username: env.OPENCODE_SERVER_USERNAME || void 0,
|
|
10367
|
-
password: env.OPENCODE_SERVER_PASSWORD || (0,
|
|
10624
|
+
password: env.OPENCODE_SERVER_PASSWORD || (0, import_node_crypto5.randomUUID)()
|
|
10368
10625
|
};
|
|
10369
10626
|
}
|
|
10370
10627
|
async function reserveLoopbackPort() {
|
|
10371
|
-
return new Promise((
|
|
10628
|
+
return new Promise((resolve3, reject) => {
|
|
10372
10629
|
const server = (0, import_node_net.createServer)();
|
|
10373
10630
|
server.once("error", reject);
|
|
10374
10631
|
server.listen(0, "127.0.0.1", () => {
|
|
10375
10632
|
const address = server.address();
|
|
10376
10633
|
const port = address && typeof address === "object" ? address.port : 0;
|
|
10377
|
-
server.close((error) => error ? reject(error) :
|
|
10634
|
+
server.close((error) => error ? reject(error) : resolve3(port));
|
|
10378
10635
|
});
|
|
10379
10636
|
});
|
|
10380
10637
|
}
|
|
@@ -10410,11 +10667,11 @@ async function consumeSseStream(body, onEvent) {
|
|
|
10410
10667
|
}
|
|
10411
10668
|
async function delay(ms, signal) {
|
|
10412
10669
|
if (signal.aborted) return;
|
|
10413
|
-
await new Promise((
|
|
10414
|
-
const timer = setTimeout(
|
|
10670
|
+
await new Promise((resolve3) => {
|
|
10671
|
+
const timer = setTimeout(resolve3, ms);
|
|
10415
10672
|
signal.addEventListener("abort", () => {
|
|
10416
10673
|
clearTimeout(timer);
|
|
10417
|
-
|
|
10674
|
+
resolve3();
|
|
10418
10675
|
}, { once: true });
|
|
10419
10676
|
});
|
|
10420
10677
|
}
|
|
@@ -10495,6 +10752,43 @@ function startEngineEventMonitor(opts) {
|
|
|
10495
10752
|
}
|
|
10496
10753
|
|
|
10497
10754
|
// src/commands/tui.ts
|
|
10755
|
+
async function resolveFolderSettings(organizationWork, askAgain) {
|
|
10756
|
+
const settings = findFolderSettings();
|
|
10757
|
+
const decision = decideFolderSettings({
|
|
10758
|
+
settings,
|
|
10759
|
+
organizationWork,
|
|
10760
|
+
remembered: rememberedFolderAnswer(settings),
|
|
10761
|
+
interactive: Boolean(process.stdin.isTTY && process.stdout.isTTY),
|
|
10762
|
+
askAgain
|
|
10763
|
+
});
|
|
10764
|
+
if (decision.kind === "nothing") return false;
|
|
10765
|
+
const list = describeFolderFiles(settings.files);
|
|
10766
|
+
if (decision.kind === "load") {
|
|
10767
|
+
ui.info(paint.dim(`Engine settings from this folder are loaded (${list.join(", ")}). Change: agentful tui --folder-settings`));
|
|
10768
|
+
return true;
|
|
10769
|
+
}
|
|
10770
|
+
if (decision.kind === "skip") {
|
|
10771
|
+
const why = {
|
|
10772
|
+
organization: "not used for your organization's work",
|
|
10773
|
+
declined: "your choice; to change it: agentful tui --folder-settings",
|
|
10774
|
+
non_interactive: "there is no terminal to ask in"
|
|
10775
|
+
}[decision.reason];
|
|
10776
|
+
ui.info(`Engine settings in this folder are not loaded (${list.join(", ")}): ${why}.`);
|
|
10777
|
+
return false;
|
|
10778
|
+
}
|
|
10779
|
+
ui.warn("This folder brings its own engine settings:");
|
|
10780
|
+
for (const line of list) console.log(` ${line}`);
|
|
10781
|
+
ui.info("They can send your prompts and your session to another address and run code on this machine.");
|
|
10782
|
+
const rl = (0, import_promises4.createInterface)({ input: process.stdin, output: process.stdout });
|
|
10783
|
+
try {
|
|
10784
|
+
const answer = await rl.question("Load them? Only if you trust where this folder comes from. [y/N] ");
|
|
10785
|
+
const load = /^y(es)?$/i.test(answer.trim());
|
|
10786
|
+
rememberFolderAnswer(settings, load);
|
|
10787
|
+
return load;
|
|
10788
|
+
} finally {
|
|
10789
|
+
rl.close();
|
|
10790
|
+
}
|
|
10791
|
+
}
|
|
10498
10792
|
async function confirmSameSessionRecovery(sessionID) {
|
|
10499
10793
|
if (!process.stdin.isTTY || !process.stdout.isTTY) return false;
|
|
10500
10794
|
const rl = (0, import_promises4.createInterface)({ input: process.stdin, output: process.stdout });
|
|
@@ -10518,10 +10812,18 @@ async function tuiCommand(opts = {}) {
|
|
|
10518
10812
|
]);
|
|
10519
10813
|
const [catalog, policy, backendState] = await Promise.all([
|
|
10520
10814
|
fetchModelCatalog(auth, session),
|
|
10521
|
-
fetchLocalProviderPolicy(auth),
|
|
10815
|
+
fetchLocalProviderPolicy(auth, project?.projectId),
|
|
10522
10816
|
project ? fetchBackendSessionState(auth, project.userId, project.projectId) : Promise.resolve(void 0)
|
|
10523
10817
|
]);
|
|
10524
10818
|
const local = resolveLocalProviders(policy);
|
|
10819
|
+
const providerDecision = decideProviders(policy);
|
|
10820
|
+
const allowedProviders = enabledProviders(providerDecision, Object.keys(local.providers));
|
|
10821
|
+
const loadFolderSettings = await resolveFolderSettings(isOrganizationWork(policy), Boolean(opts.folderSettings));
|
|
10822
|
+
const guardEnv = engineGuardEnv({
|
|
10823
|
+
gatewayUrl: session.gateway_url,
|
|
10824
|
+
loadFolderSettings,
|
|
10825
|
+
enabledProviders: allowedProviders
|
|
10826
|
+
});
|
|
10525
10827
|
const framework = detectFramework(process.cwd());
|
|
10526
10828
|
const skills = skillsInstructionFor(framework, process.cwd());
|
|
10527
10829
|
const initialXdg = engineXdg();
|
|
@@ -10544,17 +10846,24 @@ async function tuiCommand(opts = {}) {
|
|
|
10544
10846
|
initialPin?.model
|
|
10545
10847
|
);
|
|
10546
10848
|
const binDir = ensureCliOnPath();
|
|
10547
|
-
const
|
|
10849
|
+
const allConnections = readConnectedEngineProviders(xdg);
|
|
10850
|
+
const hiddenConnections = blockedConnections(providerDecision, allConnections, Object.keys(local.providers));
|
|
10851
|
+
const connectedProviders = allConnections.filter((id) => !hiddenConnections.includes(id));
|
|
10548
10852
|
const validateAndApplyPin = async (pin) => {
|
|
10549
10853
|
if (!pin) return;
|
|
10550
10854
|
const provider = modelProvider(pin.model);
|
|
10855
|
+
if (allowedProviders && !allowedProviders.includes(provider)) {
|
|
10856
|
+
throw new Error(
|
|
10857
|
+
`${pin.model} is not available here. ${providerDecision.reason ?? ""} Choose another one with --model, for example agentful/` + catalog.defaultModel + "."
|
|
10858
|
+
);
|
|
10859
|
+
}
|
|
10551
10860
|
const hasProvider = provider === "agentful" || provider === "opencode" || Object.hasOwn(local.providers, provider) || connectedProviders.includes(provider);
|
|
10552
10861
|
if (!hasProvider) {
|
|
10553
10862
|
throw new Error(
|
|
10554
10863
|
`Provider ${provider} is not connected. Start without this pin, connect it in /models, then retry.`
|
|
10555
10864
|
);
|
|
10556
10865
|
}
|
|
10557
|
-
await assertEngineModelAvailable(binPath, xdg, pin.model);
|
|
10866
|
+
await assertEngineModelAvailable(binPath, xdg, pin.model, guardEnv);
|
|
10558
10867
|
if (pin.variant) writeEngineVariant(xdg, pin.model, pin.variant);
|
|
10559
10868
|
};
|
|
10560
10869
|
await validateAndApplyPin(initialPin);
|
|
@@ -10582,8 +10891,11 @@ async function tuiCommand(opts = {}) {
|
|
|
10582
10891
|
if (local.blocked.length) {
|
|
10583
10892
|
ui.warn(`Local provider(s) not loaded: ${local.blocked.join(", ")} \u2014 ${local.policyReason || "blocked by policy"}`);
|
|
10584
10893
|
}
|
|
10894
|
+
if (hiddenConnections.length) {
|
|
10895
|
+
ui.warn(`Direct connection(s) switched off: ${hiddenConnections.join(", ")} \u2014 ${providerDecision.reason}`);
|
|
10896
|
+
}
|
|
10585
10897
|
const modelNotice = modelLimitNotice(policy);
|
|
10586
|
-
if (modelNotice || local.blocked.length) {
|
|
10898
|
+
if (modelNotice || local.blocked.length || hiddenConnections.length) {
|
|
10587
10899
|
const hint = policyRequestHint(policy);
|
|
10588
10900
|
if (modelNotice) ui.info(paint.dim(modelNotice));
|
|
10589
10901
|
if (hint) ui.info(paint.dim(hint));
|
|
@@ -10634,7 +10946,7 @@ async function tuiCommand(opts = {}) {
|
|
|
10634
10946
|
username: serverAuth.username,
|
|
10635
10947
|
password: serverAuth.password
|
|
10636
10948
|
});
|
|
10637
|
-
code = await new Promise((
|
|
10949
|
+
code = await new Promise((resolve3) => {
|
|
10638
10950
|
const engineArgs = [
|
|
10639
10951
|
"--hostname",
|
|
10640
10952
|
"127.0.0.1",
|
|
@@ -10648,9 +10960,11 @@ async function tuiCommand(opts = {}) {
|
|
|
10648
10960
|
cwd: process.cwd(),
|
|
10649
10961
|
env: {
|
|
10650
10962
|
...process.env,
|
|
10963
|
+
// Provider list, pinned gateway address, folder settings (engineGuard).
|
|
10964
|
+
...guardEnv,
|
|
10651
10965
|
// Slash commands run `agentful …` through the agent's bash tool, which
|
|
10652
10966
|
// has no access to the user's shell aliases.
|
|
10653
|
-
PATH: `${binDir}${
|
|
10967
|
+
PATH: `${binDir}${import_node_path23.delimiter}${process.env.PATH || ""}`,
|
|
10654
10968
|
XDG_CONFIG_HOME: xdg.configHome,
|
|
10655
10969
|
XDG_DATA_HOME: xdg.dataHome,
|
|
10656
10970
|
XDG_STATE_HOME: xdg.stateHome,
|
|
@@ -10668,10 +10982,10 @@ async function tuiCommand(opts = {}) {
|
|
|
10668
10982
|
...session.image_model ? { IMAGE_MODEL: session.image_model } : {}
|
|
10669
10983
|
}
|
|
10670
10984
|
});
|
|
10671
|
-
child.on("exit", (childCode) =>
|
|
10985
|
+
child.on("exit", (childCode) => resolve3(childCode ?? 0));
|
|
10672
10986
|
child.on("error", (err2) => {
|
|
10673
10987
|
ui.fail(`Could not start the engine: ${err2.message}`);
|
|
10674
|
-
|
|
10988
|
+
resolve3(1);
|
|
10675
10989
|
});
|
|
10676
10990
|
});
|
|
10677
10991
|
monitor.stop();
|
|
@@ -10875,38 +11189,38 @@ async function shareCommand(opts) {
|
|
|
10875
11189
|
}
|
|
10876
11190
|
|
|
10877
11191
|
// src/commands/pull.ts
|
|
10878
|
-
var
|
|
10879
|
-
var
|
|
11192
|
+
var import_node_fs22 = require("fs");
|
|
11193
|
+
var import_node_path25 = require("path");
|
|
10880
11194
|
init_branding();
|
|
10881
11195
|
init_branding();
|
|
10882
11196
|
|
|
10883
11197
|
// src/lib/pullFiles.ts
|
|
10884
|
-
var
|
|
10885
|
-
var
|
|
11198
|
+
var import_node_fs21 = require("fs");
|
|
11199
|
+
var import_node_path24 = require("path");
|
|
10886
11200
|
var INLINE_BASE64_EXTENSIONS = /\.(?:png|jpe?g|gif|webp|avif|svg|ico|bmp|tiff?|woff2?|ttf|otf|eot|pdf|docx?|xlsx?|pptx?|zip|tar|gz|7z|rar|bz2|mp[34]|m4a|wav|ogg|avi|mov|mkv|flac|webm|exe|dll|so|dylib|bin|wasm)$/i;
|
|
10887
11201
|
function inlineContent(value) {
|
|
10888
11202
|
return typeof value === "object" && value !== null && "content" in value ? String(value.content) : String(value ?? "");
|
|
10889
11203
|
}
|
|
10890
11204
|
function writePulledWorkspaceEntry(root, rel, value) {
|
|
10891
|
-
const target = (0,
|
|
10892
|
-
(0,
|
|
11205
|
+
const target = (0, import_node_path24.join)(root, rel);
|
|
11206
|
+
(0, import_node_fs21.mkdirSync)((0, import_node_path24.dirname)(target), { recursive: true });
|
|
10893
11207
|
const content = inlineContent(value);
|
|
10894
11208
|
if (INLINE_BASE64_EXTENSIONS.test(rel)) {
|
|
10895
|
-
(0,
|
|
11209
|
+
(0, import_node_fs21.writeFileSync)(target, Buffer.from(content, "base64"));
|
|
10896
11210
|
return;
|
|
10897
11211
|
}
|
|
10898
|
-
(0,
|
|
11212
|
+
(0, import_node_fs21.writeFileSync)(target, content, "utf8");
|
|
10899
11213
|
}
|
|
10900
11214
|
function writePulledBackendDeclaration(root, declaration) {
|
|
10901
|
-
const target = (0,
|
|
10902
|
-
(0,
|
|
11215
|
+
const target = (0, import_node_path24.join)(root, ".agentful", "backend.json");
|
|
11216
|
+
(0, import_node_fs21.mkdirSync)((0, import_node_path24.dirname)(target), { recursive: true });
|
|
10903
11217
|
const {
|
|
10904
11218
|
source: _source,
|
|
10905
11219
|
received_at: _receivedAt,
|
|
10906
11220
|
last_sync: _lastSync,
|
|
10907
11221
|
...portableDeclaration
|
|
10908
11222
|
} = declaration;
|
|
10909
|
-
(0,
|
|
11223
|
+
(0, import_node_fs21.writeFileSync)(target, `${JSON.stringify(portableDeclaration, null, 2)}
|
|
10910
11224
|
`, "utf8");
|
|
10911
11225
|
}
|
|
10912
11226
|
function explainPullRefusal(err2) {
|
|
@@ -10923,7 +11237,7 @@ async function pullCommand(opts) {
|
|
|
10923
11237
|
console.log(banner());
|
|
10924
11238
|
const auth = await ensureAuth();
|
|
10925
11239
|
const project = requireProject();
|
|
10926
|
-
const nonHidden = (0,
|
|
11240
|
+
const nonHidden = (0, import_node_fs22.readdirSync)(process.cwd()).filter((n) => n !== ".agentful" && !n.startsWith("."));
|
|
10927
11241
|
if (nonHidden.length > 0 && !opts.force) {
|
|
10928
11242
|
throw new ApiError(
|
|
10929
11243
|
0,
|
|
@@ -10952,9 +11266,9 @@ async function pullCommand(opts) {
|
|
|
10952
11266
|
ui.warn(`Skipped ${rel} (HTTP ${resp.status})`);
|
|
10953
11267
|
continue;
|
|
10954
11268
|
}
|
|
10955
|
-
const target = (0,
|
|
10956
|
-
(0,
|
|
10957
|
-
(0,
|
|
11269
|
+
const target = (0, import_node_path25.join)(process.cwd(), rel);
|
|
11270
|
+
(0, import_node_fs22.mkdirSync)((0, import_node_path25.dirname)(target), { recursive: true });
|
|
11271
|
+
(0, import_node_fs22.writeFileSync)(target, Buffer.from(await resp.arrayBuffer()));
|
|
10958
11272
|
written++;
|
|
10959
11273
|
}
|
|
10960
11274
|
} else if (data.files) {
|
|
@@ -11083,6 +11397,30 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
11083
11397
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
11084
11398
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
11085
11399
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
11400
|
+
|
|
11401
|
+
### zod (https://github.com/colinhacks/zod)
|
|
11402
|
+
|
|
11403
|
+
MIT License
|
|
11404
|
+
|
|
11405
|
+
Copyright (c) 2025 Colin McDonnell
|
|
11406
|
+
|
|
11407
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11408
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
11409
|
+
in the Software without restriction, including without limitation the rights
|
|
11410
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11411
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11412
|
+
furnished to do so, subject to the following conditions:
|
|
11413
|
+
|
|
11414
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11415
|
+
copies or substantial portions of the Software.
|
|
11416
|
+
|
|
11417
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
11418
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
11419
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
11420
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
11421
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
11422
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
11423
|
+
SOFTWARE.
|
|
11086
11424
|
`;
|
|
11087
11425
|
|
|
11088
11426
|
// src/commands/licenses.ts
|
|
@@ -11106,7 +11444,7 @@ async function modelsCommand(opts) {
|
|
|
11106
11444
|
const session = await ensureGatewaySession(auth, project?.projectId);
|
|
11107
11445
|
const [catalog, policy] = await Promise.all([
|
|
11108
11446
|
fetchModelCatalog(auth, session),
|
|
11109
|
-
fetchLocalProviderPolicy(auth)
|
|
11447
|
+
fetchLocalProviderPolicy(auth, project?.projectId)
|
|
11110
11448
|
]);
|
|
11111
11449
|
console.log("");
|
|
11112
11450
|
console.log(paint.bold("Your Agentful models") + paint.dim(" (credits, region and org rules apply)"));
|
|
@@ -11118,8 +11456,20 @@ async function modelsCommand(opts) {
|
|
|
11118
11456
|
ui.info(modelNotice);
|
|
11119
11457
|
ui.info(policyRequestHint(policy));
|
|
11120
11458
|
}
|
|
11121
|
-
const decision =
|
|
11459
|
+
const decision = decideProviders(policy);
|
|
11122
11460
|
const resolved = resolveLocalProviders(policy);
|
|
11461
|
+
const localIds = Object.keys(resolved.providers);
|
|
11462
|
+
const folder = findFolderSettings();
|
|
11463
|
+
const guardEnv = engineGuardEnv({
|
|
11464
|
+
gatewayUrl: session.gateway_url,
|
|
11465
|
+
loadFolderSettings: decideFolderSettings({
|
|
11466
|
+
settings: folder,
|
|
11467
|
+
organizationWork: isOrganizationWork(policy),
|
|
11468
|
+
remembered: rememberedFolderAnswer(folder),
|
|
11469
|
+
interactive: false
|
|
11470
|
+
}).kind === "load",
|
|
11471
|
+
enabledProviders: enabledProviders(decision, localIds)
|
|
11472
|
+
});
|
|
11123
11473
|
const configured = Object.keys(readLocalProviders());
|
|
11124
11474
|
if (catalog.byokNotice) {
|
|
11125
11475
|
console.log("");
|
|
@@ -11139,7 +11489,7 @@ async function modelsCommand(opts) {
|
|
|
11139
11489
|
const binPath = await ensureEngine();
|
|
11140
11490
|
if (opts.refresh) {
|
|
11141
11491
|
try {
|
|
11142
|
-
await refreshEngineModelCache(binPath, xdg);
|
|
11492
|
+
await refreshEngineModelCache(binPath, xdg, guardEnv);
|
|
11143
11493
|
ui.step("Refreshed the engine model cache from models.dev.");
|
|
11144
11494
|
} catch {
|
|
11145
11495
|
ui.warn("Engine model cache could not be refreshed \u2014 listing the cached catalog.");
|
|
@@ -11147,9 +11497,14 @@ async function modelsCommand(opts) {
|
|
|
11147
11497
|
}
|
|
11148
11498
|
console.log("");
|
|
11149
11499
|
console.log(paint.bold("Direct TUI connections") + paint.dim(" (provider billing/terms; outside Agentful credits and region controls)"));
|
|
11500
|
+
const switchedOff = blockedConnections(decision, connectedProviders, localIds);
|
|
11150
11501
|
for (const provider of connectedProviders) {
|
|
11502
|
+
if (switchedOff.includes(provider)) {
|
|
11503
|
+
console.log(` ${paint.warn("\u2716")} ${provider} ${paint.dim("\u2014 switched off by your organization")}`);
|
|
11504
|
+
continue;
|
|
11505
|
+
}
|
|
11151
11506
|
try {
|
|
11152
|
-
const models = await listEngineModels(binPath, xdg, provider);
|
|
11507
|
+
const models = await listEngineModels(binPath, xdg, provider, guardEnv);
|
|
11153
11508
|
if (!models.length) {
|
|
11154
11509
|
console.log(` ${paint.warn("!")} ${provider} ${paint.dim("\u2014 connected, but no engine models found")}`);
|
|
11155
11510
|
continue;
|
|
@@ -11159,6 +11514,11 @@ async function modelsCommand(opts) {
|
|
|
11159
11514
|
console.log(` ${paint.warn("!")} ${provider} ${paint.dim("\u2014 catalog could not be read")}`);
|
|
11160
11515
|
}
|
|
11161
11516
|
}
|
|
11517
|
+
if (switchedOff.length) {
|
|
11518
|
+
if (decision.reason) ui.info(decision.reason);
|
|
11519
|
+
const hint = policyRequestHint(policy);
|
|
11520
|
+
if (hint) ui.info(hint);
|
|
11521
|
+
}
|
|
11162
11522
|
} else if (opts.refresh) {
|
|
11163
11523
|
console.log("");
|
|
11164
11524
|
ui.info("No provider is connected directly in the TUI, so nothing is cached \u2014");
|
|
@@ -11166,7 +11526,8 @@ async function modelsCommand(opts) {
|
|
|
11166
11526
|
}
|
|
11167
11527
|
console.log("");
|
|
11168
11528
|
console.log(paint.bold("Local providers") + paint.dim(" (your key, direct to the provider)"));
|
|
11169
|
-
|
|
11529
|
+
const noneAllowed = decision.limited && !decision.allowlist.length && !decision.allowLoopback;
|
|
11530
|
+
if (noneAllowed) {
|
|
11170
11531
|
ui.warn(decision.reason || "Local providers are not permitted for your account.");
|
|
11171
11532
|
const hint = policyRequestHint(policy);
|
|
11172
11533
|
if (hint) ui.info(hint);
|
|
@@ -11185,15 +11546,15 @@ async function modelsCommand(opts) {
|
|
|
11185
11546
|
if (hint) ui.info(hint);
|
|
11186
11547
|
}
|
|
11187
11548
|
}
|
|
11188
|
-
if (
|
|
11549
|
+
if (!noneAllowed) {
|
|
11189
11550
|
if (opts.addLocal || !configured.length) {
|
|
11190
11551
|
const path = writeLocalProvidersExample();
|
|
11191
11552
|
console.log("");
|
|
11192
11553
|
ui.step(`Edit ${paint.accent(path)} to add a provider with your own key.`);
|
|
11193
11554
|
ui.info("Those requests go straight to the provider: no Agentful credits,");
|
|
11194
11555
|
ui.info("no platform region guarantee, and no usage recorded on your account.");
|
|
11195
|
-
if (decision.
|
|
11196
|
-
ui.info(`Your organization permits: ${decision.allowlist.join(", ")}`);
|
|
11556
|
+
if (decision.limited) {
|
|
11557
|
+
ui.info(decision.reason ?? `Your organization permits: ${decision.allowlist.join(", ")}`);
|
|
11197
11558
|
}
|
|
11198
11559
|
} else {
|
|
11199
11560
|
console.log("");
|
|
@@ -11245,8 +11606,8 @@ async function upgradeCommand() {
|
|
|
11245
11606
|
|
|
11246
11607
|
// src/lib/commandOptions.ts
|
|
11247
11608
|
function tuiOptionsFrom(command) {
|
|
11248
|
-
const { session, model, variant } = command.optsWithGlobals();
|
|
11249
|
-
return { session, model, variant };
|
|
11609
|
+
const { session, model, variant, folderSettings } = command.optsWithGlobals();
|
|
11610
|
+
return { session, model, variant, ...folderSettings ? { folderSettings } : {} };
|
|
11250
11611
|
}
|
|
11251
11612
|
|
|
11252
11613
|
// src/index.ts
|
|
@@ -11263,7 +11624,7 @@ var run = (fn) => async (...args) => {
|
|
|
11263
11624
|
process.exitCode = 1;
|
|
11264
11625
|
}
|
|
11265
11626
|
};
|
|
11266
|
-
program2.name("agentful").description("Agentful in your terminal \u2014 local development with push-to-cloud previews").version(VERSION).option("-s, --session <id>", "resume a previous session (same as `tui -s`)").option("-m, --model <provider/model>", "pin an exact model from the final engine catalog").option("--variant <name>", "pin the provider-specific model variant (for example high)").action(run((opts, cmd) => {
|
|
11627
|
+
program2.name("agentful").description("Agentful in your terminal \u2014 local development with push-to-cloud previews").version(VERSION).option("-s, --session <id>", "resume a previous session (same as `tui -s`)").option("-m, --model <provider/model>", "pin an exact model from the final engine catalog").option("--variant <name>", "pin the provider-specific model variant (for example high)").option("--folder-settings", "ask again whether to load engine settings this folder brings along").action(run((opts, cmd) => {
|
|
11267
11628
|
const [unknown] = cmd.args;
|
|
11268
11629
|
if (unknown) {
|
|
11269
11630
|
throw new ApiError(
|
|
@@ -11282,7 +11643,7 @@ program2.command("push").description("Upload this project and get a live preview
|
|
|
11282
11643
|
program2.command("build-status").description("Show the cloud's record of the last build (the real error on failures)").action(run(buildStatusCommand));
|
|
11283
11644
|
program2.command("backend").description("Open this project's Backend tab (managed DB + server actions) in the browser").action(run(backendCommand));
|
|
11284
11645
|
program2.command("open").description("Open the live preview in the browser").action(run(openCommand));
|
|
11285
|
-
program2.command("tui").description("Start the Agentful coding TUI with your Agentful account").option("-s, --session <id>", "resume a previous session").option("-m, --model <provider/model>", "pin an exact model from the final engine catalog").option("--variant <name>", "pin the provider-specific model variant (for example high)").action(run((_opts, cmd) => tuiCommand(tuiOptionsFrom(cmd))));
|
|
11646
|
+
program2.command("tui").description("Start the Agentful coding TUI with your Agentful account").option("-s, --session <id>", "resume a previous session").option("-m, --model <provider/model>", "pin an exact model from the final engine catalog").option("--variant <name>", "pin the provider-specific model variant (for example high)").option("--folder-settings", "ask again whether to load engine settings this folder brings along").action(run((_opts, cmd) => tuiCommand(tuiOptionsFrom(cmd))));
|
|
11286
11647
|
program2.command("publish <subdomain>").description("Publish the built project at https://<subdomain>.agentful.page").option("--json", "print the address and the security check as JSON (for scripts and agents)").action(run(publishCommand));
|
|
11287
11648
|
program2.command("share").description("Make the live preview public (anyone with the link)").option("--private", "make the preview owner-only again").action(run((opts) => shareCommand(opts)));
|
|
11288
11649
|
program2.command("pull").description("Download the cloud workspace into this directory").option("--force", "overwrite files in a non-empty directory").action(run((opts) => pullCommand(opts)));
|