agentful 0.4.44 → 0.4.46
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 +34 -6
- package/dist/index.cjs +389 -65
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -36,6 +36,7 @@ agentful open # open the preview
|
|
|
36
36
|
| `licenses` | Licences of the software shipped with this CLI |
|
|
37
37
|
| `-s, --session <id>` | Resume a previous coding session without changing its model |
|
|
38
38
|
| `-m, --model <provider/model> [--variant <name>]` | Pin an exact engine model and optional provider-specific variant (`agentful` and `agentful tui`) |
|
|
39
|
+
| `--folder-settings` | Ask again whether to load engine settings this folder brings along (`agentful` and `agentful tui`) |
|
|
39
40
|
|
|
40
41
|
Inside the interface, `/` lists the Agentful commands (`/setup`, `/push`,
|
|
41
42
|
`/preview`, `/publish`, `/share`, `/status`) alongside the built-in ones.
|
|
@@ -198,11 +199,36 @@ suspends the silence timer.
|
|
|
198
199
|
- recovery requires an explicit `y` and only reopens the same session. It does
|
|
199
200
|
not continue automatically, so completed tool calls are not replayed by the CLI.
|
|
200
201
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
202
|
+
## Provider rules in organizations
|
|
203
|
+
|
|
204
|
+
For an organization's work the same rule covers local providers, direct TUI
|
|
205
|
+
connections and the engine's built-in providers (`/api/org/me`, `src/lib/orgPolicy.ts`):
|
|
206
|
+
|
|
207
|
+
| Organization setting | Available besides Agentful models |
|
|
208
|
+
| --- | --- |
|
|
209
|
+
| BYOK `disabled` | nothing |
|
|
210
|
+
| BYOK `provider_allowlist` | the listed provider ids |
|
|
211
|
+
| BYOK `allow`, data region Germany or EU | local providers on this machine (`localhost`, `127.0.0.1`, `::1`) |
|
|
212
|
+
| BYOK `allow`, data region EU + USA | everything |
|
|
213
|
+
| rules not readable | nothing |
|
|
214
|
+
|
|
215
|
+
A linked project in the member's private area and accounts without an
|
|
216
|
+
organization are not limited; without a linked project a member works for the
|
|
217
|
+
organization. Connections are hidden, not deleted. `agentful models` and the TUI
|
|
218
|
+
start name what is switched off, why, and where to ask. The check is done by the
|
|
219
|
+
CLI, so it is a cooperative control, not a cryptographic one — the config lives
|
|
220
|
+
on the user's machine.
|
|
221
|
+
|
|
222
|
+
## Engine settings in a folder
|
|
223
|
+
|
|
224
|
+
`opencode.json`, `tui.json` and `.opencode/` in a folder (or above it) can
|
|
225
|
+
redirect model requests and run code when the engine starts. The CLI therefore
|
|
226
|
+
starts the engine with folder settings off, pins the gateway address, and asks
|
|
227
|
+
once per folder and state of those files whether to load them (default: no). For
|
|
228
|
+
an organization's work they are never loaded. `agentful tui --folder-settings`
|
|
229
|
+
asks again. `AGENTS.md`, `CLAUDE.md` and `CONTEXT.md` are read either way. The
|
|
230
|
+
answers are kept in `~/.config/agentful/trusted-folders.json`
|
|
231
|
+
(`src/lib/engineGuard.ts`).
|
|
206
232
|
|
|
207
233
|
## Personal data check
|
|
208
234
|
|
|
@@ -223,7 +249,9 @@ fail-open); if it cannot be installed at all, the TUI says so in a toast. Not
|
|
|
223
249
|
covered: attachments, shell mode, IDE editor context, free-text answers to the
|
|
224
250
|
agent's questions. Like the BYOK lock it is a cooperative control on the
|
|
225
251
|
user's machine. On every engine bump run `npm run check-pii` (real TUI against
|
|
226
|
-
a stub model, no login, no credits) next to `npm run check-engine
|
|
252
|
+
a stub model, no login, no credits) next to `npm run check-engine` and
|
|
253
|
+
`npm run check-guard` (folder settings and provider rules, real engine and real
|
|
254
|
+
CLI against stubs).
|
|
227
255
|
|
|
228
256
|
## Known limitation: the engine's exit banner
|
|
229
257
|
|
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.46" ? "0.4.46" : 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;
|
|
@@ -6367,6 +6367,10 @@ function requireProject(cwd = process.cwd()) {
|
|
|
6367
6367
|
return config;
|
|
6368
6368
|
}
|
|
6369
6369
|
var PROJECT_ID = /^[a-z0-9]{10,20}$/i;
|
|
6370
|
+
function printable(text, max) {
|
|
6371
|
+
const clean = text.replace(/[\u0000-\u001f\u007f-\u009f]/g, " ").replace(/\s+/g, " ").trim();
|
|
6372
|
+
return clean.length > max ? `${clean.slice(0, max - 1)}\u2026` : clean;
|
|
6373
|
+
}
|
|
6370
6374
|
async function linkProject(auth, projectId, title, cwd = process.cwd()) {
|
|
6371
6375
|
if (!PROJECT_ID.test(projectId)) {
|
|
6372
6376
|
throw new ApiError(
|
|
@@ -6396,6 +6400,15 @@ async function linkProject(auth, projectId, title, cwd = process.cwd()) {
|
|
|
6396
6400
|
`The platform returned no owner for project ${projectId}; nothing was linked.`
|
|
6397
6401
|
);
|
|
6398
6402
|
}
|
|
6403
|
+
if (record.role === "guest") {
|
|
6404
|
+
const org = typeof record.org_name === "string" ? printable(record.org_name, 80) : "";
|
|
6405
|
+
const link = `${APP_URL}/shared/${encodeURIComponent(storageUserId)}/${projectId}`;
|
|
6406
|
+
throw new ApiError(
|
|
6407
|
+
403,
|
|
6408
|
+
"guest_preview_only",
|
|
6409
|
+
`Project ${projectId} is shared with you as a guest${org ? ` by ${org}` : ""}. Guests see only the preview, in the app; nothing was linked. Open it at ${link}`
|
|
6410
|
+
);
|
|
6411
|
+
}
|
|
6399
6412
|
await request(`${API_URL}/api/workspaces/${encodeURIComponent(storageUserId)}/${projectId}/tree`, { token: auth.pb_token });
|
|
6400
6413
|
const config = {
|
|
6401
6414
|
projectId,
|
|
@@ -9396,7 +9409,7 @@ async function openCommand() {
|
|
|
9396
9409
|
// src/commands/tui.ts
|
|
9397
9410
|
var import_node_child_process6 = require("child_process");
|
|
9398
9411
|
var import_promises4 = require("readline/promises");
|
|
9399
|
-
var
|
|
9412
|
+
var import_node_path23 = require("path");
|
|
9400
9413
|
|
|
9401
9414
|
// src/lib/binWrapper.ts
|
|
9402
9415
|
var import_node_fs13 = require("fs");
|
|
@@ -9823,7 +9836,18 @@ var LEVELS = ["org", "department", "person"];
|
|
|
9823
9836
|
function asLevel(value) {
|
|
9824
9837
|
return LEVELS.includes(value) ? value : void 0;
|
|
9825
9838
|
}
|
|
9826
|
-
async function
|
|
9839
|
+
async function isPrivateProject(auth, projectId) {
|
|
9840
|
+
try {
|
|
9841
|
+
const res = await request(
|
|
9842
|
+
`${PB_URL}/api/llm/available-models?project=${encodeURIComponent(projectId)}`,
|
|
9843
|
+
{ token: auth.pb_token, timeoutMs: 1e4 }
|
|
9844
|
+
);
|
|
9845
|
+
return res?.org_policy?.has_org === false;
|
|
9846
|
+
} catch {
|
|
9847
|
+
return false;
|
|
9848
|
+
}
|
|
9849
|
+
}
|
|
9850
|
+
async function fetchLocalProviderPolicy(auth, projectId) {
|
|
9827
9851
|
try {
|
|
9828
9852
|
const me = await request(`${PB_URL}/api/org/me`, { token: auth.pb_token, timeoutMs: 1e4 });
|
|
9829
9853
|
if (!me?.has_org) return { hasOrg: false, allowedProviders: [] };
|
|
@@ -9832,6 +9856,9 @@ async function fetchLocalProviderPolicy(auth) {
|
|
|
9832
9856
|
const modelLevels = Array.isArray(sources.allowed_models) ? LEVELS.filter((l) => sources.allowed_models.includes(l)) : [];
|
|
9833
9857
|
return {
|
|
9834
9858
|
hasOrg: true,
|
|
9859
|
+
privateProject: projectId ? await isPrivateProject(auth, projectId) : false,
|
|
9860
|
+
regionCap: typeof policy.region_cap === "string" ? policy.region_cap : void 0,
|
|
9861
|
+
regionLevel: asLevel(sources.region_cap),
|
|
9835
9862
|
byokMode: policy.byok_mode || "allow",
|
|
9836
9863
|
allowedProviders: Array.isArray(policy.allowed_byok_providers) ? policy.allowed_byok_providers : [],
|
|
9837
9864
|
// /api/org/me reports the org as `org.id`; effective_policy carries no
|
|
@@ -9843,7 +9870,7 @@ async function fetchLocalProviderPolicy(auth) {
|
|
|
9843
9870
|
byokLevel: asLevel(sources.byok_mode)
|
|
9844
9871
|
};
|
|
9845
9872
|
} catch {
|
|
9846
|
-
return { hasOrg: true, byokMode: "disabled", allowedProviders: [] };
|
|
9873
|
+
return { hasOrg: true, unreadable: true, byokMode: "disabled", allowedProviders: [] };
|
|
9847
9874
|
}
|
|
9848
9875
|
}
|
|
9849
9876
|
function levelName(policy, level) {
|
|
@@ -9856,24 +9883,54 @@ function levelName(policy, level) {
|
|
|
9856
9883
|
function capitalize(text) {
|
|
9857
9884
|
return text.charAt(0).toUpperCase() + text.slice(1);
|
|
9858
9885
|
}
|
|
9859
|
-
function
|
|
9860
|
-
|
|
9886
|
+
function isOrganizationWork(policy) {
|
|
9887
|
+
return policy.hasOrg && !policy.privateProject;
|
|
9888
|
+
}
|
|
9889
|
+
var REGION_NAME = { de: "Germany", eu: "EU" };
|
|
9890
|
+
function decideProviders(policy) {
|
|
9891
|
+
const any = { limited: false, allowlist: [], allowLoopback: true };
|
|
9892
|
+
if (!isOrganizationWork(policy)) return any;
|
|
9893
|
+
if (policy.unreadable) {
|
|
9894
|
+
return {
|
|
9895
|
+
limited: true,
|
|
9896
|
+
allowlist: [],
|
|
9897
|
+
allowLoopback: false,
|
|
9898
|
+
reason: "Your organization's rules could not be read, so only Agentful models are available."
|
|
9899
|
+
};
|
|
9900
|
+
}
|
|
9861
9901
|
const who = capitalize(levelName(policy, policy.byokLevel));
|
|
9862
9902
|
if (policy.byokMode === "disabled") {
|
|
9863
9903
|
return {
|
|
9864
|
-
|
|
9904
|
+
limited: true,
|
|
9865
9905
|
allowlist: [],
|
|
9866
|
-
|
|
9906
|
+
allowLoopback: false,
|
|
9907
|
+
reason: `${who} has disabled bring-your-own-key, which includes local providers and direct connections.`
|
|
9867
9908
|
};
|
|
9868
9909
|
}
|
|
9869
9910
|
if (policy.byokMode === "provider_allowlist") {
|
|
9870
9911
|
return {
|
|
9871
|
-
|
|
9912
|
+
limited: true,
|
|
9872
9913
|
allowlist: policy.allowedProviders,
|
|
9914
|
+
allowLoopback: false,
|
|
9873
9915
|
reason: `${who} allows only these providers: ${policy.allowedProviders.join(", ") || "(none)"}`
|
|
9874
9916
|
};
|
|
9875
9917
|
}
|
|
9876
|
-
|
|
9918
|
+
if (policy.regionCap === "us_eu") return any;
|
|
9919
|
+
const region = REGION_NAME[policy.regionCap ?? ""];
|
|
9920
|
+
return {
|
|
9921
|
+
limited: true,
|
|
9922
|
+
allowlist: [],
|
|
9923
|
+
allowLoopback: true,
|
|
9924
|
+
reason: `${capitalize(levelName(policy, policy.regionLevel))} has set the data region${region ? ` ${region}` : ""}: only Agentful models and models on this machine are available.`
|
|
9925
|
+
};
|
|
9926
|
+
}
|
|
9927
|
+
function enabledProviders(decision, localProviderIds) {
|
|
9928
|
+
if (!decision.limited) return void 0;
|
|
9929
|
+
return Array.from(/* @__PURE__ */ new Set(["agentful", ...decision.allowlist, ...localProviderIds]));
|
|
9930
|
+
}
|
|
9931
|
+
function blockedConnections(decision, connected, localProviderIds) {
|
|
9932
|
+
const enabled2 = enabledProviders(decision, localProviderIds);
|
|
9933
|
+
return enabled2 ? connected.filter((id) => !enabled2.includes(id)) : [];
|
|
9877
9934
|
}
|
|
9878
9935
|
function policyRequestHint(policy) {
|
|
9879
9936
|
if (!policy.hasOrg) return void 0;
|
|
@@ -9911,21 +9968,31 @@ function readLocalProviders() {
|
|
|
9911
9968
|
}
|
|
9912
9969
|
return {};
|
|
9913
9970
|
}
|
|
9971
|
+
function isLoopbackProvider(config) {
|
|
9972
|
+
const baseURL = config.options?.baseURL;
|
|
9973
|
+
if (typeof baseURL !== "string") return false;
|
|
9974
|
+
let host;
|
|
9975
|
+
try {
|
|
9976
|
+
host = new URL(baseURL).hostname.toLowerCase();
|
|
9977
|
+
} catch {
|
|
9978
|
+
return false;
|
|
9979
|
+
}
|
|
9980
|
+
const loopback = host === "localhost" || host === "[::1]" || /^127(\.\d{1,3}){3}$/.test(host);
|
|
9981
|
+
if (!loopback) return false;
|
|
9982
|
+
const models = Object.values(config.models ?? {});
|
|
9983
|
+
return models.every((m) => !(m && typeof m === "object" && "provider" in m));
|
|
9984
|
+
}
|
|
9914
9985
|
function resolveLocalProviders(policy) {
|
|
9915
9986
|
const configured = readLocalProviders();
|
|
9916
9987
|
const ids = Object.keys(configured);
|
|
9917
9988
|
if (!ids.length) return { providers: {}, blocked: [] };
|
|
9918
|
-
const decision =
|
|
9919
|
-
if (!decision.
|
|
9920
|
-
return { providers: {}, blocked: ids, policyReason: decision.reason };
|
|
9921
|
-
}
|
|
9922
|
-
if (!decision.allowlist.length) {
|
|
9923
|
-
return { providers: configured, blocked: [] };
|
|
9924
|
-
}
|
|
9989
|
+
const decision = decideProviders(policy);
|
|
9990
|
+
if (!decision.limited) return { providers: configured, blocked: [] };
|
|
9925
9991
|
const providers = {};
|
|
9926
9992
|
const blocked = [];
|
|
9927
9993
|
for (const id of ids) {
|
|
9928
|
-
|
|
9994
|
+
const permitted = decision.allowlist.includes(id) || decision.allowLoopback && isLoopbackProvider(configured[id]);
|
|
9995
|
+
if (permitted) providers[id] = configured[id];
|
|
9929
9996
|
else blocked.push(id);
|
|
9930
9997
|
}
|
|
9931
9998
|
return { providers, blocked, policyReason: blocked.length ? decision.reason : void 0 };
|
|
@@ -10153,10 +10220,11 @@ function parseEngineModelsOutput(output) {
|
|
|
10153
10220
|
function modelProvider(model) {
|
|
10154
10221
|
return model.slice(0, model.indexOf("/"));
|
|
10155
10222
|
}
|
|
10156
|
-
async function listEngineModels(binPath, xdg, provider) {
|
|
10223
|
+
async function listEngineModels(binPath, xdg, provider, guardEnv) {
|
|
10157
10224
|
const { stdout } = await execFileAsync(binPath, ["models", provider], {
|
|
10158
10225
|
env: {
|
|
10159
10226
|
...process.env,
|
|
10227
|
+
...guardEnv,
|
|
10160
10228
|
XDG_CONFIG_HOME: xdg.configHome,
|
|
10161
10229
|
XDG_DATA_HOME: xdg.dataHome,
|
|
10162
10230
|
XDG_STATE_HOME: xdg.stateHome,
|
|
@@ -10168,10 +10236,11 @@ async function listEngineModels(binPath, xdg, provider) {
|
|
|
10168
10236
|
});
|
|
10169
10237
|
return parseEngineModelsOutput(stdout);
|
|
10170
10238
|
}
|
|
10171
|
-
async function refreshEngineModelCache(binPath, xdg) {
|
|
10239
|
+
async function refreshEngineModelCache(binPath, xdg, guardEnv) {
|
|
10172
10240
|
await execFileAsync(binPath, ["models", "--refresh"], {
|
|
10173
10241
|
env: {
|
|
10174
10242
|
...process.env,
|
|
10243
|
+
...guardEnv,
|
|
10175
10244
|
XDG_CONFIG_HOME: xdg.configHome,
|
|
10176
10245
|
XDG_DATA_HOME: xdg.dataHome,
|
|
10177
10246
|
XDG_STATE_HOME: xdg.stateHome,
|
|
@@ -10182,9 +10251,9 @@ async function refreshEngineModelCache(binPath, xdg) {
|
|
|
10182
10251
|
timeout: 6e4
|
|
10183
10252
|
});
|
|
10184
10253
|
}
|
|
10185
|
-
async function assertEngineModelAvailable(binPath, xdg, model, listModels = listEngineModels) {
|
|
10254
|
+
async function assertEngineModelAvailable(binPath, xdg, model, guardEnv, listModels = listEngineModels) {
|
|
10186
10255
|
const provider = modelProvider(model);
|
|
10187
|
-
const models = await listModels(binPath, xdg, provider);
|
|
10256
|
+
const models = await listModels(binPath, xdg, provider, guardEnv);
|
|
10188
10257
|
if (!models.includes(model)) {
|
|
10189
10258
|
const examples = models.slice(0, 5);
|
|
10190
10259
|
const hint = examples.length ? ` Available for ${provider}: ${examples.join(", ")}.` : "";
|
|
@@ -10224,8 +10293,183 @@ function describeModelRoute(model, catalog, localProviders, connectedProviders)
|
|
|
10224
10293
|
return "external engine route \u2014 provider setup and terms apply; no Agentful credits or region guarantee";
|
|
10225
10294
|
}
|
|
10226
10295
|
|
|
10227
|
-
// src/lib/
|
|
10296
|
+
// src/lib/engineGuard.ts
|
|
10228
10297
|
var import_node_crypto4 = require("crypto");
|
|
10298
|
+
var import_node_fs20 = require("fs");
|
|
10299
|
+
var import_node_os6 = require("os");
|
|
10300
|
+
var import_node_path22 = require("path");
|
|
10301
|
+
var TRUSTED_FOLDERS_FILE = "trusted-folders.json";
|
|
10302
|
+
var CONFIG_NAMES = ["opencode.json", "opencode.jsonc"];
|
|
10303
|
+
var TUI_NAMES = ["tui.json", "tui.jsonc"];
|
|
10304
|
+
var ENGINE_DIRS = [
|
|
10305
|
+
"agent",
|
|
10306
|
+
"agents",
|
|
10307
|
+
"command",
|
|
10308
|
+
"commands",
|
|
10309
|
+
"mode",
|
|
10310
|
+
"modes",
|
|
10311
|
+
"plugin",
|
|
10312
|
+
"plugins",
|
|
10313
|
+
"skill",
|
|
10314
|
+
"skills",
|
|
10315
|
+
"theme",
|
|
10316
|
+
"themes",
|
|
10317
|
+
"tool",
|
|
10318
|
+
"tools"
|
|
10319
|
+
];
|
|
10320
|
+
var MAX_FILES = 400;
|
|
10321
|
+
var MAX_DEPTH = 6;
|
|
10322
|
+
var INSTRUCTION_NAMES = ["AGENTS.md", "CLAUDE.md", "CONTEXT.md"];
|
|
10323
|
+
function ancestors(start, stop) {
|
|
10324
|
+
const out = [];
|
|
10325
|
+
let dir = start;
|
|
10326
|
+
for (; ; ) {
|
|
10327
|
+
out.push(dir);
|
|
10328
|
+
if (dir === stop) break;
|
|
10329
|
+
const parent = (0, import_node_path22.dirname)(dir);
|
|
10330
|
+
if (parent === dir) break;
|
|
10331
|
+
dir = parent;
|
|
10332
|
+
}
|
|
10333
|
+
return out;
|
|
10334
|
+
}
|
|
10335
|
+
function realFolder(cwd) {
|
|
10336
|
+
try {
|
|
10337
|
+
return (0, import_node_fs20.realpathSync)(cwd);
|
|
10338
|
+
} catch {
|
|
10339
|
+
return (0, import_node_path22.resolve)(cwd);
|
|
10340
|
+
}
|
|
10341
|
+
}
|
|
10342
|
+
function worktreeOf(dir) {
|
|
10343
|
+
return ancestors(dir).find((d) => (0, import_node_fs20.existsSync)((0, import_node_path22.join)(d, ".git")));
|
|
10344
|
+
}
|
|
10345
|
+
function isFile(path) {
|
|
10346
|
+
try {
|
|
10347
|
+
return (0, import_node_fs20.statSync)(path).isFile();
|
|
10348
|
+
} catch {
|
|
10349
|
+
return false;
|
|
10350
|
+
}
|
|
10351
|
+
}
|
|
10352
|
+
function isDirectory(path) {
|
|
10353
|
+
try {
|
|
10354
|
+
return (0, import_node_fs20.statSync)(path).isDirectory();
|
|
10355
|
+
} catch {
|
|
10356
|
+
return false;
|
|
10357
|
+
}
|
|
10358
|
+
}
|
|
10359
|
+
function filesBelow(dir, depth, out) {
|
|
10360
|
+
if (depth > MAX_DEPTH || out.length >= MAX_FILES) return;
|
|
10361
|
+
let names;
|
|
10362
|
+
try {
|
|
10363
|
+
names = (0, import_node_fs20.readdirSync)(dir).sort();
|
|
10364
|
+
} catch {
|
|
10365
|
+
return;
|
|
10366
|
+
}
|
|
10367
|
+
for (const name2 of names) {
|
|
10368
|
+
if (name2 === "node_modules" || name2 === ".git") continue;
|
|
10369
|
+
const path = (0, import_node_path22.join)(dir, name2);
|
|
10370
|
+
if (isDirectory(path)) filesBelow(path, depth + 1, out);
|
|
10371
|
+
else if (out.length < MAX_FILES) out.push(path);
|
|
10372
|
+
}
|
|
10373
|
+
}
|
|
10374
|
+
function findFolderSettings(cwd = process.cwd(), home = (0, import_node_os6.homedir)()) {
|
|
10375
|
+
const start = realFolder(cwd);
|
|
10376
|
+
const homeDir = realFolder(home);
|
|
10377
|
+
const stop = worktreeOf(start);
|
|
10378
|
+
const configDirs = new Set(ancestors(start, stop));
|
|
10379
|
+
const files = [];
|
|
10380
|
+
for (const dir of ancestors(start)) {
|
|
10381
|
+
if (configDirs.has(dir)) files.push(...CONFIG_NAMES.map((n) => (0, import_node_path22.join)(dir, n)).filter(isFile));
|
|
10382
|
+
files.push(...TUI_NAMES.map((n) => (0, import_node_path22.join)(dir, n)).filter(isFile));
|
|
10383
|
+
const dot = (0, import_node_path22.join)(dir, ".opencode");
|
|
10384
|
+
if (dir === homeDir || !isDirectory(dot)) continue;
|
|
10385
|
+
files.push(...[...CONFIG_NAMES, ...TUI_NAMES].map((n) => (0, import_node_path22.join)(dot, n)).filter(isFile));
|
|
10386
|
+
for (const name2 of ENGINE_DIRS) {
|
|
10387
|
+
const sub = (0, import_node_path22.join)(dot, name2);
|
|
10388
|
+
if (isDirectory(sub)) filesBelow(sub, 1, files);
|
|
10389
|
+
}
|
|
10390
|
+
}
|
|
10391
|
+
if (!files.length) return { files, fingerprint: "" };
|
|
10392
|
+
const hash = (0, import_node_crypto4.createHash)("sha256");
|
|
10393
|
+
for (const path of files) {
|
|
10394
|
+
hash.update(path).update("\0");
|
|
10395
|
+
try {
|
|
10396
|
+
hash.update((0, import_node_crypto4.createHash)("sha256").update((0, import_node_fs20.readFileSync)(path)).digest());
|
|
10397
|
+
} catch {
|
|
10398
|
+
hash.update("unreadable");
|
|
10399
|
+
}
|
|
10400
|
+
}
|
|
10401
|
+
if (files.length >= MAX_FILES) hash.update((0, import_node_crypto4.randomUUID)());
|
|
10402
|
+
return { files, fingerprint: hash.digest("hex") };
|
|
10403
|
+
}
|
|
10404
|
+
function findProjectInstructions(cwd = process.cwd()) {
|
|
10405
|
+
const start = realFolder(cwd);
|
|
10406
|
+
const dirs = ancestors(start, worktreeOf(start));
|
|
10407
|
+
for (const name2 of INSTRUCTION_NAMES) {
|
|
10408
|
+
const found = dirs.map((dir) => (0, import_node_path22.join)(dir, name2)).filter(isFile);
|
|
10409
|
+
if (found.length) return found;
|
|
10410
|
+
}
|
|
10411
|
+
return [];
|
|
10412
|
+
}
|
|
10413
|
+
function describeFolderFiles(files, cwd = process.cwd(), max = 6) {
|
|
10414
|
+
const start = realFolder(cwd);
|
|
10415
|
+
const shown = files.slice(0, max).map((path) => {
|
|
10416
|
+
const rel = (0, import_node_path22.relative)(start, path);
|
|
10417
|
+
return (rel.startsWith("..") ? path : rel).replace(/[\u0000-\u001f\u007f-\u009f]/g, "?");
|
|
10418
|
+
});
|
|
10419
|
+
if (files.length > max) shown.push(`\u2026 and ${files.length - max} more`);
|
|
10420
|
+
return shown;
|
|
10421
|
+
}
|
|
10422
|
+
function trustPath() {
|
|
10423
|
+
return (0, import_node_path22.join)(configDir(), TRUSTED_FOLDERS_FILE);
|
|
10424
|
+
}
|
|
10425
|
+
function readTrust() {
|
|
10426
|
+
try {
|
|
10427
|
+
const parsed = JSON.parse((0, import_node_fs20.readFileSync)(trustPath(), "utf8"));
|
|
10428
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
|
|
10429
|
+
} catch {
|
|
10430
|
+
return {};
|
|
10431
|
+
}
|
|
10432
|
+
}
|
|
10433
|
+
function rememberedFolderAnswer(settings, cwd = process.cwd()) {
|
|
10434
|
+
const store = readTrust();
|
|
10435
|
+
const key = realFolder(cwd);
|
|
10436
|
+
const entry = Object.hasOwn(store, key) ? store[key] : void 0;
|
|
10437
|
+
return entry && entry.fingerprint === settings.fingerprint && typeof entry.load === "boolean" ? entry.load : void 0;
|
|
10438
|
+
}
|
|
10439
|
+
function rememberFolderAnswer(settings, load, cwd = process.cwd()) {
|
|
10440
|
+
const store = readTrust();
|
|
10441
|
+
store[realFolder(cwd)] = { fingerprint: settings.fingerprint, load, answered_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
10442
|
+
(0, import_node_fs20.mkdirSync)(configDir(), { recursive: true });
|
|
10443
|
+
(0, import_node_fs20.writeFileSync)(trustPath(), JSON.stringify(store, null, 2) + "\n", { mode: 384 });
|
|
10444
|
+
try {
|
|
10445
|
+
(0, import_node_fs20.chmodSync)(trustPath(), 384);
|
|
10446
|
+
} catch {
|
|
10447
|
+
}
|
|
10448
|
+
}
|
|
10449
|
+
function decideFolderSettings(input) {
|
|
10450
|
+
if (!input.settings.files.length) return { kind: "nothing" };
|
|
10451
|
+
if (input.organizationWork) return { kind: "skip", reason: "organization" };
|
|
10452
|
+
if (input.remembered !== void 0 && !(input.askAgain && input.interactive)) {
|
|
10453
|
+
return input.remembered ? { kind: "load" } : { kind: "skip", reason: "declined" };
|
|
10454
|
+
}
|
|
10455
|
+
return input.interactive ? { kind: "ask" } : { kind: "skip", reason: "non_interactive" };
|
|
10456
|
+
}
|
|
10457
|
+
function engineGuardEnv(opts) {
|
|
10458
|
+
const instructions = opts.loadFolderSettings ? [] : findProjectInstructions(opts.cwd);
|
|
10459
|
+
const inline = {
|
|
10460
|
+
provider: { agentful: { options: { baseURL: opts.gatewayUrl } } },
|
|
10461
|
+
...opts.enabledProviders ? { enabled_providers: opts.enabledProviders } : {},
|
|
10462
|
+
...instructions.length ? { instructions } : {}
|
|
10463
|
+
};
|
|
10464
|
+
return {
|
|
10465
|
+
OPENCODE_CONFIG_CONTENT: JSON.stringify(inline),
|
|
10466
|
+
// Always explicit: a CLI started from inside a TUI inherits the outer value.
|
|
10467
|
+
OPENCODE_DISABLE_PROJECT_CONFIG: opts.loadFolderSettings ? "false" : "true"
|
|
10468
|
+
};
|
|
10469
|
+
}
|
|
10470
|
+
|
|
10471
|
+
// src/lib/engineEvents.ts
|
|
10472
|
+
var import_node_crypto5 = require("crypto");
|
|
10229
10473
|
var import_node_net = require("net");
|
|
10230
10474
|
function payloadOf(event) {
|
|
10231
10475
|
return event.payload && typeof event.payload === "object" ? event.payload : event;
|
|
@@ -10351,17 +10595,17 @@ var EngineLivenessPolicy = class {
|
|
|
10351
10595
|
function engineServerCredentials(env = process.env) {
|
|
10352
10596
|
return {
|
|
10353
10597
|
username: env.OPENCODE_SERVER_USERNAME || void 0,
|
|
10354
|
-
password: env.OPENCODE_SERVER_PASSWORD || (0,
|
|
10598
|
+
password: env.OPENCODE_SERVER_PASSWORD || (0, import_node_crypto5.randomUUID)()
|
|
10355
10599
|
};
|
|
10356
10600
|
}
|
|
10357
10601
|
async function reserveLoopbackPort() {
|
|
10358
|
-
return new Promise((
|
|
10602
|
+
return new Promise((resolve3, reject) => {
|
|
10359
10603
|
const server = (0, import_node_net.createServer)();
|
|
10360
10604
|
server.once("error", reject);
|
|
10361
10605
|
server.listen(0, "127.0.0.1", () => {
|
|
10362
10606
|
const address = server.address();
|
|
10363
10607
|
const port = address && typeof address === "object" ? address.port : 0;
|
|
10364
|
-
server.close((error) => error ? reject(error) :
|
|
10608
|
+
server.close((error) => error ? reject(error) : resolve3(port));
|
|
10365
10609
|
});
|
|
10366
10610
|
});
|
|
10367
10611
|
}
|
|
@@ -10397,11 +10641,11 @@ async function consumeSseStream(body, onEvent) {
|
|
|
10397
10641
|
}
|
|
10398
10642
|
async function delay(ms, signal) {
|
|
10399
10643
|
if (signal.aborted) return;
|
|
10400
|
-
await new Promise((
|
|
10401
|
-
const timer = setTimeout(
|
|
10644
|
+
await new Promise((resolve3) => {
|
|
10645
|
+
const timer = setTimeout(resolve3, ms);
|
|
10402
10646
|
signal.addEventListener("abort", () => {
|
|
10403
10647
|
clearTimeout(timer);
|
|
10404
|
-
|
|
10648
|
+
resolve3();
|
|
10405
10649
|
}, { once: true });
|
|
10406
10650
|
});
|
|
10407
10651
|
}
|
|
@@ -10482,6 +10726,43 @@ function startEngineEventMonitor(opts) {
|
|
|
10482
10726
|
}
|
|
10483
10727
|
|
|
10484
10728
|
// src/commands/tui.ts
|
|
10729
|
+
async function resolveFolderSettings(organizationWork, askAgain) {
|
|
10730
|
+
const settings = findFolderSettings();
|
|
10731
|
+
const decision = decideFolderSettings({
|
|
10732
|
+
settings,
|
|
10733
|
+
organizationWork,
|
|
10734
|
+
remembered: rememberedFolderAnswer(settings),
|
|
10735
|
+
interactive: Boolean(process.stdin.isTTY && process.stdout.isTTY),
|
|
10736
|
+
askAgain
|
|
10737
|
+
});
|
|
10738
|
+
if (decision.kind === "nothing") return false;
|
|
10739
|
+
const list = describeFolderFiles(settings.files);
|
|
10740
|
+
if (decision.kind === "load") {
|
|
10741
|
+
ui.info(paint.dim(`Engine settings from this folder are loaded (${list.join(", ")}). Change: agentful tui --folder-settings`));
|
|
10742
|
+
return true;
|
|
10743
|
+
}
|
|
10744
|
+
if (decision.kind === "skip") {
|
|
10745
|
+
const why = {
|
|
10746
|
+
organization: "not used for your organization's work",
|
|
10747
|
+
declined: "your choice; to change it: agentful tui --folder-settings",
|
|
10748
|
+
non_interactive: "there is no terminal to ask in"
|
|
10749
|
+
}[decision.reason];
|
|
10750
|
+
ui.info(`Engine settings in this folder are not loaded (${list.join(", ")}): ${why}.`);
|
|
10751
|
+
return false;
|
|
10752
|
+
}
|
|
10753
|
+
ui.warn("This folder brings its own engine settings:");
|
|
10754
|
+
for (const line of list) console.log(` ${line}`);
|
|
10755
|
+
ui.info("They can send your prompts and your session to another address and run code on this machine.");
|
|
10756
|
+
const rl = (0, import_promises4.createInterface)({ input: process.stdin, output: process.stdout });
|
|
10757
|
+
try {
|
|
10758
|
+
const answer = await rl.question("Load them? Only if you trust where this folder comes from. [y/N] ");
|
|
10759
|
+
const load = /^y(es)?$/i.test(answer.trim());
|
|
10760
|
+
rememberFolderAnswer(settings, load);
|
|
10761
|
+
return load;
|
|
10762
|
+
} finally {
|
|
10763
|
+
rl.close();
|
|
10764
|
+
}
|
|
10765
|
+
}
|
|
10485
10766
|
async function confirmSameSessionRecovery(sessionID) {
|
|
10486
10767
|
if (!process.stdin.isTTY || !process.stdout.isTTY) return false;
|
|
10487
10768
|
const rl = (0, import_promises4.createInterface)({ input: process.stdin, output: process.stdout });
|
|
@@ -10505,10 +10786,18 @@ async function tuiCommand(opts = {}) {
|
|
|
10505
10786
|
]);
|
|
10506
10787
|
const [catalog, policy, backendState] = await Promise.all([
|
|
10507
10788
|
fetchModelCatalog(auth, session),
|
|
10508
|
-
fetchLocalProviderPolicy(auth),
|
|
10789
|
+
fetchLocalProviderPolicy(auth, project?.projectId),
|
|
10509
10790
|
project ? fetchBackendSessionState(auth, project.userId, project.projectId) : Promise.resolve(void 0)
|
|
10510
10791
|
]);
|
|
10511
10792
|
const local = resolveLocalProviders(policy);
|
|
10793
|
+
const providerDecision = decideProviders(policy);
|
|
10794
|
+
const allowedProviders = enabledProviders(providerDecision, Object.keys(local.providers));
|
|
10795
|
+
const loadFolderSettings = await resolveFolderSettings(isOrganizationWork(policy), Boolean(opts.folderSettings));
|
|
10796
|
+
const guardEnv = engineGuardEnv({
|
|
10797
|
+
gatewayUrl: session.gateway_url,
|
|
10798
|
+
loadFolderSettings,
|
|
10799
|
+
enabledProviders: allowedProviders
|
|
10800
|
+
});
|
|
10512
10801
|
const framework = detectFramework(process.cwd());
|
|
10513
10802
|
const skills = skillsInstructionFor(framework, process.cwd());
|
|
10514
10803
|
const initialXdg = engineXdg();
|
|
@@ -10531,17 +10820,24 @@ async function tuiCommand(opts = {}) {
|
|
|
10531
10820
|
initialPin?.model
|
|
10532
10821
|
);
|
|
10533
10822
|
const binDir = ensureCliOnPath();
|
|
10534
|
-
const
|
|
10823
|
+
const allConnections = readConnectedEngineProviders(xdg);
|
|
10824
|
+
const hiddenConnections = blockedConnections(providerDecision, allConnections, Object.keys(local.providers));
|
|
10825
|
+
const connectedProviders = allConnections.filter((id) => !hiddenConnections.includes(id));
|
|
10535
10826
|
const validateAndApplyPin = async (pin) => {
|
|
10536
10827
|
if (!pin) return;
|
|
10537
10828
|
const provider = modelProvider(pin.model);
|
|
10829
|
+
if (allowedProviders && !allowedProviders.includes(provider)) {
|
|
10830
|
+
throw new Error(
|
|
10831
|
+
`${pin.model} is not available here. ${providerDecision.reason ?? ""} Choose another one with --model, for example agentful/` + catalog.defaultModel + "."
|
|
10832
|
+
);
|
|
10833
|
+
}
|
|
10538
10834
|
const hasProvider = provider === "agentful" || provider === "opencode" || Object.hasOwn(local.providers, provider) || connectedProviders.includes(provider);
|
|
10539
10835
|
if (!hasProvider) {
|
|
10540
10836
|
throw new Error(
|
|
10541
10837
|
`Provider ${provider} is not connected. Start without this pin, connect it in /models, then retry.`
|
|
10542
10838
|
);
|
|
10543
10839
|
}
|
|
10544
|
-
await assertEngineModelAvailable(binPath, xdg, pin.model);
|
|
10840
|
+
await assertEngineModelAvailable(binPath, xdg, pin.model, guardEnv);
|
|
10545
10841
|
if (pin.variant) writeEngineVariant(xdg, pin.model, pin.variant);
|
|
10546
10842
|
};
|
|
10547
10843
|
await validateAndApplyPin(initialPin);
|
|
@@ -10569,8 +10865,11 @@ async function tuiCommand(opts = {}) {
|
|
|
10569
10865
|
if (local.blocked.length) {
|
|
10570
10866
|
ui.warn(`Local provider(s) not loaded: ${local.blocked.join(", ")} \u2014 ${local.policyReason || "blocked by policy"}`);
|
|
10571
10867
|
}
|
|
10868
|
+
if (hiddenConnections.length) {
|
|
10869
|
+
ui.warn(`Direct connection(s) switched off: ${hiddenConnections.join(", ")} \u2014 ${providerDecision.reason}`);
|
|
10870
|
+
}
|
|
10572
10871
|
const modelNotice = modelLimitNotice(policy);
|
|
10573
|
-
if (modelNotice || local.blocked.length) {
|
|
10872
|
+
if (modelNotice || local.blocked.length || hiddenConnections.length) {
|
|
10574
10873
|
const hint = policyRequestHint(policy);
|
|
10575
10874
|
if (modelNotice) ui.info(paint.dim(modelNotice));
|
|
10576
10875
|
if (hint) ui.info(paint.dim(hint));
|
|
@@ -10621,7 +10920,7 @@ async function tuiCommand(opts = {}) {
|
|
|
10621
10920
|
username: serverAuth.username,
|
|
10622
10921
|
password: serverAuth.password
|
|
10623
10922
|
});
|
|
10624
|
-
code = await new Promise((
|
|
10923
|
+
code = await new Promise((resolve3) => {
|
|
10625
10924
|
const engineArgs = [
|
|
10626
10925
|
"--hostname",
|
|
10627
10926
|
"127.0.0.1",
|
|
@@ -10635,9 +10934,11 @@ async function tuiCommand(opts = {}) {
|
|
|
10635
10934
|
cwd: process.cwd(),
|
|
10636
10935
|
env: {
|
|
10637
10936
|
...process.env,
|
|
10937
|
+
// Provider list, pinned gateway address, folder settings (engineGuard).
|
|
10938
|
+
...guardEnv,
|
|
10638
10939
|
// Slash commands run `agentful …` through the agent's bash tool, which
|
|
10639
10940
|
// has no access to the user's shell aliases.
|
|
10640
|
-
PATH: `${binDir}${
|
|
10941
|
+
PATH: `${binDir}${import_node_path23.delimiter}${process.env.PATH || ""}`,
|
|
10641
10942
|
XDG_CONFIG_HOME: xdg.configHome,
|
|
10642
10943
|
XDG_DATA_HOME: xdg.dataHome,
|
|
10643
10944
|
XDG_STATE_HOME: xdg.stateHome,
|
|
@@ -10655,10 +10956,10 @@ async function tuiCommand(opts = {}) {
|
|
|
10655
10956
|
...session.image_model ? { IMAGE_MODEL: session.image_model } : {}
|
|
10656
10957
|
}
|
|
10657
10958
|
});
|
|
10658
|
-
child.on("exit", (childCode) =>
|
|
10959
|
+
child.on("exit", (childCode) => resolve3(childCode ?? 0));
|
|
10659
10960
|
child.on("error", (err2) => {
|
|
10660
10961
|
ui.fail(`Could not start the engine: ${err2.message}`);
|
|
10661
|
-
|
|
10962
|
+
resolve3(1);
|
|
10662
10963
|
});
|
|
10663
10964
|
});
|
|
10664
10965
|
monitor.stop();
|
|
@@ -10862,38 +11163,38 @@ async function shareCommand(opts) {
|
|
|
10862
11163
|
}
|
|
10863
11164
|
|
|
10864
11165
|
// src/commands/pull.ts
|
|
10865
|
-
var
|
|
10866
|
-
var
|
|
11166
|
+
var import_node_fs22 = require("fs");
|
|
11167
|
+
var import_node_path25 = require("path");
|
|
10867
11168
|
init_branding();
|
|
10868
11169
|
init_branding();
|
|
10869
11170
|
|
|
10870
11171
|
// src/lib/pullFiles.ts
|
|
10871
|
-
var
|
|
10872
|
-
var
|
|
11172
|
+
var import_node_fs21 = require("fs");
|
|
11173
|
+
var import_node_path24 = require("path");
|
|
10873
11174
|
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;
|
|
10874
11175
|
function inlineContent(value) {
|
|
10875
11176
|
return typeof value === "object" && value !== null && "content" in value ? String(value.content) : String(value ?? "");
|
|
10876
11177
|
}
|
|
10877
11178
|
function writePulledWorkspaceEntry(root, rel, value) {
|
|
10878
|
-
const target = (0,
|
|
10879
|
-
(0,
|
|
11179
|
+
const target = (0, import_node_path24.join)(root, rel);
|
|
11180
|
+
(0, import_node_fs21.mkdirSync)((0, import_node_path24.dirname)(target), { recursive: true });
|
|
10880
11181
|
const content = inlineContent(value);
|
|
10881
11182
|
if (INLINE_BASE64_EXTENSIONS.test(rel)) {
|
|
10882
|
-
(0,
|
|
11183
|
+
(0, import_node_fs21.writeFileSync)(target, Buffer.from(content, "base64"));
|
|
10883
11184
|
return;
|
|
10884
11185
|
}
|
|
10885
|
-
(0,
|
|
11186
|
+
(0, import_node_fs21.writeFileSync)(target, content, "utf8");
|
|
10886
11187
|
}
|
|
10887
11188
|
function writePulledBackendDeclaration(root, declaration) {
|
|
10888
|
-
const target = (0,
|
|
10889
|
-
(0,
|
|
11189
|
+
const target = (0, import_node_path24.join)(root, ".agentful", "backend.json");
|
|
11190
|
+
(0, import_node_fs21.mkdirSync)((0, import_node_path24.dirname)(target), { recursive: true });
|
|
10890
11191
|
const {
|
|
10891
11192
|
source: _source,
|
|
10892
11193
|
received_at: _receivedAt,
|
|
10893
11194
|
last_sync: _lastSync,
|
|
10894
11195
|
...portableDeclaration
|
|
10895
11196
|
} = declaration;
|
|
10896
|
-
(0,
|
|
11197
|
+
(0, import_node_fs21.writeFileSync)(target, `${JSON.stringify(portableDeclaration, null, 2)}
|
|
10897
11198
|
`, "utf8");
|
|
10898
11199
|
}
|
|
10899
11200
|
function explainPullRefusal(err2) {
|
|
@@ -10910,7 +11211,7 @@ async function pullCommand(opts) {
|
|
|
10910
11211
|
console.log(banner());
|
|
10911
11212
|
const auth = await ensureAuth();
|
|
10912
11213
|
const project = requireProject();
|
|
10913
|
-
const nonHidden = (0,
|
|
11214
|
+
const nonHidden = (0, import_node_fs22.readdirSync)(process.cwd()).filter((n) => n !== ".agentful" && !n.startsWith("."));
|
|
10914
11215
|
if (nonHidden.length > 0 && !opts.force) {
|
|
10915
11216
|
throw new ApiError(
|
|
10916
11217
|
0,
|
|
@@ -10939,9 +11240,9 @@ async function pullCommand(opts) {
|
|
|
10939
11240
|
ui.warn(`Skipped ${rel} (HTTP ${resp.status})`);
|
|
10940
11241
|
continue;
|
|
10941
11242
|
}
|
|
10942
|
-
const target = (0,
|
|
10943
|
-
(0,
|
|
10944
|
-
(0,
|
|
11243
|
+
const target = (0, import_node_path25.join)(process.cwd(), rel);
|
|
11244
|
+
(0, import_node_fs22.mkdirSync)((0, import_node_path25.dirname)(target), { recursive: true });
|
|
11245
|
+
(0, import_node_fs22.writeFileSync)(target, Buffer.from(await resp.arrayBuffer()));
|
|
10945
11246
|
written++;
|
|
10946
11247
|
}
|
|
10947
11248
|
} else if (data.files) {
|
|
@@ -11093,7 +11394,7 @@ async function modelsCommand(opts) {
|
|
|
11093
11394
|
const session = await ensureGatewaySession(auth, project?.projectId);
|
|
11094
11395
|
const [catalog, policy] = await Promise.all([
|
|
11095
11396
|
fetchModelCatalog(auth, session),
|
|
11096
|
-
fetchLocalProviderPolicy(auth)
|
|
11397
|
+
fetchLocalProviderPolicy(auth, project?.projectId)
|
|
11097
11398
|
]);
|
|
11098
11399
|
console.log("");
|
|
11099
11400
|
console.log(paint.bold("Your Agentful models") + paint.dim(" (credits, region and org rules apply)"));
|
|
@@ -11105,8 +11406,20 @@ async function modelsCommand(opts) {
|
|
|
11105
11406
|
ui.info(modelNotice);
|
|
11106
11407
|
ui.info(policyRequestHint(policy));
|
|
11107
11408
|
}
|
|
11108
|
-
const decision =
|
|
11409
|
+
const decision = decideProviders(policy);
|
|
11109
11410
|
const resolved = resolveLocalProviders(policy);
|
|
11411
|
+
const localIds = Object.keys(resolved.providers);
|
|
11412
|
+
const folder = findFolderSettings();
|
|
11413
|
+
const guardEnv = engineGuardEnv({
|
|
11414
|
+
gatewayUrl: session.gateway_url,
|
|
11415
|
+
loadFolderSettings: decideFolderSettings({
|
|
11416
|
+
settings: folder,
|
|
11417
|
+
organizationWork: isOrganizationWork(policy),
|
|
11418
|
+
remembered: rememberedFolderAnswer(folder),
|
|
11419
|
+
interactive: false
|
|
11420
|
+
}).kind === "load",
|
|
11421
|
+
enabledProviders: enabledProviders(decision, localIds)
|
|
11422
|
+
});
|
|
11110
11423
|
const configured = Object.keys(readLocalProviders());
|
|
11111
11424
|
if (catalog.byokNotice) {
|
|
11112
11425
|
console.log("");
|
|
@@ -11126,7 +11439,7 @@ async function modelsCommand(opts) {
|
|
|
11126
11439
|
const binPath = await ensureEngine();
|
|
11127
11440
|
if (opts.refresh) {
|
|
11128
11441
|
try {
|
|
11129
|
-
await refreshEngineModelCache(binPath, xdg);
|
|
11442
|
+
await refreshEngineModelCache(binPath, xdg, guardEnv);
|
|
11130
11443
|
ui.step("Refreshed the engine model cache from models.dev.");
|
|
11131
11444
|
} catch {
|
|
11132
11445
|
ui.warn("Engine model cache could not be refreshed \u2014 listing the cached catalog.");
|
|
@@ -11134,9 +11447,14 @@ async function modelsCommand(opts) {
|
|
|
11134
11447
|
}
|
|
11135
11448
|
console.log("");
|
|
11136
11449
|
console.log(paint.bold("Direct TUI connections") + paint.dim(" (provider billing/terms; outside Agentful credits and region controls)"));
|
|
11450
|
+
const switchedOff = blockedConnections(decision, connectedProviders, localIds);
|
|
11137
11451
|
for (const provider of connectedProviders) {
|
|
11452
|
+
if (switchedOff.includes(provider)) {
|
|
11453
|
+
console.log(` ${paint.warn("\u2716")} ${provider} ${paint.dim("\u2014 switched off by your organization")}`);
|
|
11454
|
+
continue;
|
|
11455
|
+
}
|
|
11138
11456
|
try {
|
|
11139
|
-
const models = await listEngineModels(binPath, xdg, provider);
|
|
11457
|
+
const models = await listEngineModels(binPath, xdg, provider, guardEnv);
|
|
11140
11458
|
if (!models.length) {
|
|
11141
11459
|
console.log(` ${paint.warn("!")} ${provider} ${paint.dim("\u2014 connected, but no engine models found")}`);
|
|
11142
11460
|
continue;
|
|
@@ -11146,6 +11464,11 @@ async function modelsCommand(opts) {
|
|
|
11146
11464
|
console.log(` ${paint.warn("!")} ${provider} ${paint.dim("\u2014 catalog could not be read")}`);
|
|
11147
11465
|
}
|
|
11148
11466
|
}
|
|
11467
|
+
if (switchedOff.length) {
|
|
11468
|
+
if (decision.reason) ui.info(decision.reason);
|
|
11469
|
+
const hint = policyRequestHint(policy);
|
|
11470
|
+
if (hint) ui.info(hint);
|
|
11471
|
+
}
|
|
11149
11472
|
} else if (opts.refresh) {
|
|
11150
11473
|
console.log("");
|
|
11151
11474
|
ui.info("No provider is connected directly in the TUI, so nothing is cached \u2014");
|
|
@@ -11153,7 +11476,8 @@ async function modelsCommand(opts) {
|
|
|
11153
11476
|
}
|
|
11154
11477
|
console.log("");
|
|
11155
11478
|
console.log(paint.bold("Local providers") + paint.dim(" (your key, direct to the provider)"));
|
|
11156
|
-
|
|
11479
|
+
const noneAllowed = decision.limited && !decision.allowlist.length && !decision.allowLoopback;
|
|
11480
|
+
if (noneAllowed) {
|
|
11157
11481
|
ui.warn(decision.reason || "Local providers are not permitted for your account.");
|
|
11158
11482
|
const hint = policyRequestHint(policy);
|
|
11159
11483
|
if (hint) ui.info(hint);
|
|
@@ -11172,15 +11496,15 @@ async function modelsCommand(opts) {
|
|
|
11172
11496
|
if (hint) ui.info(hint);
|
|
11173
11497
|
}
|
|
11174
11498
|
}
|
|
11175
|
-
if (
|
|
11499
|
+
if (!noneAllowed) {
|
|
11176
11500
|
if (opts.addLocal || !configured.length) {
|
|
11177
11501
|
const path = writeLocalProvidersExample();
|
|
11178
11502
|
console.log("");
|
|
11179
11503
|
ui.step(`Edit ${paint.accent(path)} to add a provider with your own key.`);
|
|
11180
11504
|
ui.info("Those requests go straight to the provider: no Agentful credits,");
|
|
11181
11505
|
ui.info("no platform region guarantee, and no usage recorded on your account.");
|
|
11182
|
-
if (decision.
|
|
11183
|
-
ui.info(`Your organization permits: ${decision.allowlist.join(", ")}`);
|
|
11506
|
+
if (decision.limited) {
|
|
11507
|
+
ui.info(decision.reason ?? `Your organization permits: ${decision.allowlist.join(", ")}`);
|
|
11184
11508
|
}
|
|
11185
11509
|
} else {
|
|
11186
11510
|
console.log("");
|
|
@@ -11232,8 +11556,8 @@ async function upgradeCommand() {
|
|
|
11232
11556
|
|
|
11233
11557
|
// src/lib/commandOptions.ts
|
|
11234
11558
|
function tuiOptionsFrom(command) {
|
|
11235
|
-
const { session, model, variant } = command.optsWithGlobals();
|
|
11236
|
-
return { session, model, variant };
|
|
11559
|
+
const { session, model, variant, folderSettings } = command.optsWithGlobals();
|
|
11560
|
+
return { session, model, variant, ...folderSettings ? { folderSettings } : {} };
|
|
11237
11561
|
}
|
|
11238
11562
|
|
|
11239
11563
|
// src/index.ts
|
|
@@ -11250,7 +11574,7 @@ var run = (fn) => async (...args) => {
|
|
|
11250
11574
|
process.exitCode = 1;
|
|
11251
11575
|
}
|
|
11252
11576
|
};
|
|
11253
|
-
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) => {
|
|
11577
|
+
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) => {
|
|
11254
11578
|
const [unknown] = cmd.args;
|
|
11255
11579
|
if (unknown) {
|
|
11256
11580
|
throw new ApiError(
|
|
@@ -11269,7 +11593,7 @@ program2.command("push").description("Upload this project and get a live preview
|
|
|
11269
11593
|
program2.command("build-status").description("Show the cloud's record of the last build (the real error on failures)").action(run(buildStatusCommand));
|
|
11270
11594
|
program2.command("backend").description("Open this project's Backend tab (managed DB + server actions) in the browser").action(run(backendCommand));
|
|
11271
11595
|
program2.command("open").description("Open the live preview in the browser").action(run(openCommand));
|
|
11272
|
-
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))));
|
|
11596
|
+
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))));
|
|
11273
11597
|
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));
|
|
11274
11598
|
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)));
|
|
11275
11599
|
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)));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agentful",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.46",
|
|
4
4
|
"description": "Agentful in your terminal — local development with push-to-cloud previews",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://agentful.dev",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"typecheck": "tsc --noEmit",
|
|
27
27
|
"check-engine": "node scripts/check-engine-contract.mjs",
|
|
28
28
|
"check-pii": "node scripts/check-pii-guard.mjs",
|
|
29
|
+
"check-guard": "node scripts/check-engine-guard.mjs",
|
|
29
30
|
"dev": "tsx src/index.ts",
|
|
30
31
|
"sync-theme": "cp src/branding/agentful-theme.json ../frontend/public/cli/theme.json",
|
|
31
32
|
"test": "node --import tsx --test src/lib/*.test.ts"
|