@cydm/pie 4.10.0 → 4.10.2
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/dist/builtin/extensions/im-forward/index.js +172 -53
- package/dist/builtin/extensions/mcp-adapter/index.js +216 -7
- package/dist/builtin/extensions/pie-proc/index.js +176 -146
- package/dist/chunks/chunk-BB7ETSJK.js +463 -0
- package/dist/chunks/chunk-Z2RT3P4F.js +251 -0
- package/dist/chunks/manager-allow-SF5ROGDM.js +21 -0
- package/dist/chunks/{manager-cli-Y6HM3MHA.js → manager-cli-BXI4UFTJ.js} +12 -55
- package/dist/chunks/{manager-upgrade-LSTOHBUV.js → manager-upgrade-XPFXKO7A.js} +64 -39
- package/dist/cli.js +295 -36
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -52204,6 +52204,9 @@ function installInteractiveConsoleInterception(runtimeLogger) {
|
|
|
52204
52204
|
};
|
|
52205
52205
|
}
|
|
52206
52206
|
|
|
52207
|
+
// src/commands/management.ts
|
|
52208
|
+
import { createInterface } from "node:readline/promises";
|
|
52209
|
+
|
|
52207
52210
|
// src/doctor.ts
|
|
52208
52211
|
import { spawnSync } from "node:child_process";
|
|
52209
52212
|
import { createRequire } from "node:module";
|
|
@@ -52354,6 +52357,7 @@ var SettingsManager = class {
|
|
|
52354
52357
|
* 'revert to load state = untouched'). */
|
|
52355
52358
|
settingsLastWritten;
|
|
52356
52359
|
legacyConfigLastWritten;
|
|
52360
|
+
settingsLoadError;
|
|
52357
52361
|
constructor() {
|
|
52358
52362
|
const configDir = getConfigDir();
|
|
52359
52363
|
this.settingsPath = getSettingsPath();
|
|
@@ -52364,16 +52368,23 @@ var SettingsManager = class {
|
|
|
52364
52368
|
this.legacyConfigLastWritten = cloneJsonDocument(this.legacyConfig);
|
|
52365
52369
|
this.managerScopedEnv = this.readManagerScopedEnv();
|
|
52366
52370
|
}
|
|
52367
|
-
|
|
52371
|
+
getSettingsLoadError() {
|
|
52372
|
+
return this.settingsLoadError;
|
|
52373
|
+
}
|
|
52374
|
+
readJson(filePath, onError) {
|
|
52368
52375
|
if (!fs2.existsSync(filePath)) return null;
|
|
52369
52376
|
try {
|
|
52370
52377
|
return JSON.parse(fs2.readFileSync(filePath, "utf-8"));
|
|
52371
|
-
} catch {
|
|
52378
|
+
} catch (error) {
|
|
52379
|
+
onError?.(error instanceof Error ? error.message : String(error));
|
|
52372
52380
|
return null;
|
|
52373
52381
|
}
|
|
52374
52382
|
}
|
|
52375
52383
|
loadSettingsFile() {
|
|
52376
|
-
|
|
52384
|
+
this.settingsLoadError = void 0;
|
|
52385
|
+
return this.readJson(this.settingsPath, (detail) => {
|
|
52386
|
+
this.settingsLoadError = `${this.settingsPath}: ${detail}`;
|
|
52387
|
+
}) || {};
|
|
52377
52388
|
}
|
|
52378
52389
|
loadLegacyConfigFile() {
|
|
52379
52390
|
return this.readJson(this.legacyConfigPath) || {};
|
|
@@ -52412,8 +52423,13 @@ var SettingsManager = class {
|
|
|
52412
52423
|
corrupt = true;
|
|
52413
52424
|
}
|
|
52414
52425
|
}
|
|
52426
|
+
if (corrupt) {
|
|
52427
|
+
const backupPath = `${filePath}.corrupt-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
52428
|
+
fs2.copyFileSync(filePath, backupPath, fs2.constants.COPYFILE_EXCL);
|
|
52429
|
+
}
|
|
52415
52430
|
const value = corrupt ? current : mergeSnapshotDelta(lastWritten, current, onDisk ?? {});
|
|
52416
52431
|
writeJsonAtomic(filePath, value);
|
|
52432
|
+
if (filePath === this.settingsPath) this.settingsLoadError = void 0;
|
|
52417
52433
|
return { value };
|
|
52418
52434
|
}
|
|
52419
52435
|
writeLegacyConfig() {
|
|
@@ -52934,6 +52950,15 @@ async function runDoctor() {
|
|
|
52934
52950
|
const registry = new ModelRegistry(authStorage);
|
|
52935
52951
|
const loadError = registry.getLoadError();
|
|
52936
52952
|
const models = registry.getAll();
|
|
52953
|
+
const settingsLoadError = settings.getSettingsLoadError();
|
|
52954
|
+
if (settingsLoadError) {
|
|
52955
|
+
checks.push({
|
|
52956
|
+
id: "settings_json",
|
|
52957
|
+
label: "settings.json",
|
|
52958
|
+
status: "fail",
|
|
52959
|
+
message: `Invalid settings.json (${settingsLoadError}). Fix the JSON syntax; Pie backs up corrupt files as *.corrupt-* before overwriting.`
|
|
52960
|
+
});
|
|
52961
|
+
}
|
|
52937
52962
|
const available = registry.getAvailable();
|
|
52938
52963
|
const routePurposes = ["web_search", "read_file.image", "read_file.video", "read_file.audio", "read_file.document"];
|
|
52939
52964
|
const toolRoutes = routePurposes.map((purpose) => registry.resolveToolModel(purpose));
|
|
@@ -52943,13 +52968,13 @@ async function runDoctor() {
|
|
|
52943
52968
|
id: "models_json",
|
|
52944
52969
|
label: "models.json",
|
|
52945
52970
|
status: loadError ? "fail" : models.length > 0 ? "pass" : "warn",
|
|
52946
|
-
message: loadError ? `Invalid models.json: ${loadError}` : models.length > 0 ? `Loaded ${models.length} model(s).` : "No models are configured. Run pie models
|
|
52971
|
+
message: loadError ? `Invalid models.json: ${loadError}` : models.length > 0 ? `Loaded ${models.length} model(s).` : "No models are configured. Run pie models add to configure a usable model (or pie models init for a template)."
|
|
52947
52972
|
});
|
|
52948
52973
|
checks.push({
|
|
52949
52974
|
id: "model_api_keys",
|
|
52950
52975
|
label: "Model API keys",
|
|
52951
52976
|
status: available.length > 0 ? "pass" : "warn",
|
|
52952
|
-
message: available.length > 0 ? `${available.length} configured model(s) have usable API keys.` : "No configured model has an available API key.
|
|
52977
|
+
message: available.length > 0 ? `${available.length} configured model(s) have usable API keys.` : "No configured model has an available API key. Run pie models add or export the profile's apiKeyEnv variable."
|
|
52953
52978
|
});
|
|
52954
52979
|
checks.push({
|
|
52955
52980
|
id: "web_search_mode",
|
|
@@ -53096,13 +53121,20 @@ ${toolLines}
|
|
|
53096
53121
|
|
|
53097
53122
|
Disable or narrow capabilities:
|
|
53098
53123
|
- Start from a trusted cwd.
|
|
53099
|
-
-
|
|
53100
|
-
-
|
|
53124
|
+
- Disable tools live in TUI with /tools/disable <name> (e.g. /tools/disable shell, /tools/disable write_file) or inspect with /tools/list (persisted per user).
|
|
53125
|
+
- Toggle extensions with pie extensions disable <name> [--project|--user] (or reset with pie extensions reset <name> --project).
|
|
53126
|
+
- Keep API keys in environment variables or via pie models add, not in prompts.`;
|
|
53101
53127
|
}
|
|
53102
53128
|
|
|
53103
53129
|
// src/commands/models-config.ts
|
|
53130
|
+
import { randomBytes } from "node:crypto";
|
|
53104
53131
|
import * as fs4 from "node:fs";
|
|
53105
53132
|
import * as path4 from "node:path";
|
|
53133
|
+
var SUPPORTED_MODEL_APIS = [
|
|
53134
|
+
"openai-completions",
|
|
53135
|
+
"openai-responses",
|
|
53136
|
+
"anthropic-messages"
|
|
53137
|
+
];
|
|
53106
53138
|
function getDefaultModelsPath() {
|
|
53107
53139
|
return path4.join(getConfigDir(), "models.json");
|
|
53108
53140
|
}
|
|
@@ -53214,13 +53246,129 @@ function initModelsConfig(options = {}) {
|
|
|
53214
53246
|
fs4.writeFileSync(targetPath, content, "utf8");
|
|
53215
53247
|
return { path: targetPath, content, wrote: true };
|
|
53216
53248
|
}
|
|
53249
|
+
function addModelProfile(options) {
|
|
53250
|
+
const targetPath = resolveModelsPath(options.path);
|
|
53251
|
+
const profile = options.profile.trim();
|
|
53252
|
+
const modelId = options.modelId.trim();
|
|
53253
|
+
const baseUrl = options.baseUrl.trim();
|
|
53254
|
+
if (!profile) throw new Error("Profile name is required (--profile).");
|
|
53255
|
+
if (!modelId) throw new Error("Model ID is required (--model).");
|
|
53256
|
+
if (!baseUrl || !/^https?:\/\//i.test(baseUrl)) {
|
|
53257
|
+
throw new Error(`Base URL must start with http:// or https:// (got "${baseUrl}").`);
|
|
53258
|
+
}
|
|
53259
|
+
if (!SUPPORTED_MODEL_APIS.includes(options.api)) {
|
|
53260
|
+
throw new Error(`Unsupported --api "${options.api}". Allowed: ${SUPPORTED_MODEL_APIS.join(", ")}.`);
|
|
53261
|
+
}
|
|
53262
|
+
const apiKey = options.apiKey?.trim();
|
|
53263
|
+
const apiKeyEnv = options.apiKeyEnv?.trim();
|
|
53264
|
+
if (!apiKey && !apiKeyEnv) {
|
|
53265
|
+
throw new Error("Provide either --api-key-env <ENV_VAR> or --api-key <key>.");
|
|
53266
|
+
}
|
|
53267
|
+
if (apiKey && apiKeyEnv) {
|
|
53268
|
+
throw new Error("Provide either --api-key-env or --api-key, not both.");
|
|
53269
|
+
}
|
|
53270
|
+
let doc = {};
|
|
53271
|
+
let backedUpTo;
|
|
53272
|
+
if (fs4.existsSync(targetPath)) {
|
|
53273
|
+
try {
|
|
53274
|
+
const parsed = JSON.parse(fs4.readFileSync(targetPath, "utf8"));
|
|
53275
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
53276
|
+
throw new Error("top-level JSON value must be an object");
|
|
53277
|
+
}
|
|
53278
|
+
doc = { ...parsed };
|
|
53279
|
+
} catch (error) {
|
|
53280
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
53281
|
+
if (!options.backupCorrupt) {
|
|
53282
|
+
throw new Error(
|
|
53283
|
+
`Cannot update ${targetPath}: invalid JSON (${detail}). Re-run with --backup-corrupt to back up the broken file first.`
|
|
53284
|
+
);
|
|
53285
|
+
}
|
|
53286
|
+
backedUpTo = `${targetPath}.corrupt-${Date.now()}-${randomBytes(3).toString("hex")}`;
|
|
53287
|
+
fs4.renameSync(targetPath, backedUpTo);
|
|
53288
|
+
doc = {};
|
|
53289
|
+
}
|
|
53290
|
+
}
|
|
53291
|
+
const profiles = doc.profiles && typeof doc.profiles === "object" && !Array.isArray(doc.profiles) ? { ...doc.profiles } : {};
|
|
53292
|
+
const existingProfile = profiles[profile] && typeof profiles[profile] === "object" && !Array.isArray(profiles[profile]) ? { ...profiles[profile] } : {};
|
|
53293
|
+
const existingModels = Array.isArray(existingProfile.models) ? existingProfile.models.filter((m2) => m2 && typeof m2 === "object") : [];
|
|
53294
|
+
const idx = existingModels.findIndex((m2) => m2.id === modelId);
|
|
53295
|
+
const mergedModels = idx >= 0 ? existingModels.map((m2, i) => {
|
|
53296
|
+
if (i !== idx) return m2;
|
|
53297
|
+
return {
|
|
53298
|
+
...m2,
|
|
53299
|
+
id: modelId,
|
|
53300
|
+
...options.modelName?.trim() ? { name: options.modelName.trim() } : {},
|
|
53301
|
+
...options.reasoning !== void 0 ? { reasoning: options.reasoning } : {}
|
|
53302
|
+
};
|
|
53303
|
+
}) : [
|
|
53304
|
+
...existingModels,
|
|
53305
|
+
{
|
|
53306
|
+
id: modelId,
|
|
53307
|
+
name: options.modelName?.trim() || modelId,
|
|
53308
|
+
reasoning: options.reasoning === true,
|
|
53309
|
+
input: ["text", "image"],
|
|
53310
|
+
contextWindow: 128e3,
|
|
53311
|
+
maxTokens: 16384,
|
|
53312
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 }
|
|
53313
|
+
}
|
|
53314
|
+
];
|
|
53315
|
+
const nextProfile = {
|
|
53316
|
+
...existingProfile,
|
|
53317
|
+
api: options.api,
|
|
53318
|
+
baseUrl,
|
|
53319
|
+
models: mergedModels
|
|
53320
|
+
};
|
|
53321
|
+
if (apiKeyEnv) {
|
|
53322
|
+
nextProfile.apiKeyEnv = apiKeyEnv;
|
|
53323
|
+
delete nextProfile.apiKey;
|
|
53324
|
+
} else if (apiKey) {
|
|
53325
|
+
nextProfile.apiKey = apiKey;
|
|
53326
|
+
delete nextProfile.apiKeyEnv;
|
|
53327
|
+
}
|
|
53328
|
+
profiles[profile] = nextProfile;
|
|
53329
|
+
doc.profiles = profiles;
|
|
53330
|
+
const existingDefaults = doc.defaults && typeof doc.defaults === "object" && !Array.isArray(doc.defaults) ? doc.defaults : void 0;
|
|
53331
|
+
const shouldSetDefault = options.setDefault === true || !existingDefaults?.provider || !existingDefaults?.modelId;
|
|
53332
|
+
if (shouldSetDefault) {
|
|
53333
|
+
doc.defaults = {
|
|
53334
|
+
...existingDefaults ?? {},
|
|
53335
|
+
provider: profile,
|
|
53336
|
+
modelId
|
|
53337
|
+
};
|
|
53338
|
+
}
|
|
53339
|
+
fs4.mkdirSync(path4.dirname(targetPath), { recursive: true });
|
|
53340
|
+
const tmpPath = path4.join(path4.dirname(targetPath), `.models-${process.pid}-${randomBytes(4).toString("hex")}.tmp`);
|
|
53341
|
+
try {
|
|
53342
|
+
fs4.writeFileSync(tmpPath, `${JSON.stringify(doc, null, 2)}
|
|
53343
|
+
`, { encoding: "utf8", mode: 384 });
|
|
53344
|
+
const check = validateModelsConfig({ path: tmpPath });
|
|
53345
|
+
if (!check.ok) {
|
|
53346
|
+
throw new Error(`Refused to write ${targetPath}: ${check.message}`);
|
|
53347
|
+
}
|
|
53348
|
+
fs4.renameSync(tmpPath, targetPath);
|
|
53349
|
+
} finally {
|
|
53350
|
+
try {
|
|
53351
|
+
fs4.rmSync(tmpPath, { force: true });
|
|
53352
|
+
} catch {
|
|
53353
|
+
}
|
|
53354
|
+
}
|
|
53355
|
+
return {
|
|
53356
|
+
path: targetPath,
|
|
53357
|
+
profile,
|
|
53358
|
+
modelId,
|
|
53359
|
+
api: options.api,
|
|
53360
|
+
baseUrl,
|
|
53361
|
+
isDefault: shouldSetDefault,
|
|
53362
|
+
...backedUpTo ? { backedUpTo } : {}
|
|
53363
|
+
};
|
|
53364
|
+
}
|
|
53217
53365
|
function validateModelsConfig(options = {}) {
|
|
53218
53366
|
const modelsPath = resolveModelsPath(options.path);
|
|
53219
53367
|
if (!fs4.existsSync(modelsPath)) {
|
|
53220
53368
|
return {
|
|
53221
53369
|
ok: false,
|
|
53222
53370
|
path: modelsPath,
|
|
53223
|
-
message: `models.json not found: ${modelsPath}. Run pie models init
|
|
53371
|
+
message: `models.json not found: ${modelsPath}. Run pie models add (or pie models init for a starter template).`,
|
|
53224
53372
|
profiles: [],
|
|
53225
53373
|
modelCount: 0
|
|
53226
53374
|
};
|
|
@@ -53613,6 +53761,26 @@ var MODELS_INIT_SPEC = {
|
|
|
53613
53761
|
],
|
|
53614
53762
|
positional: []
|
|
53615
53763
|
};
|
|
53764
|
+
var MODELS_ADD_SPEC = {
|
|
53765
|
+
path: "models add",
|
|
53766
|
+
summary: "Add or update a usable model profile in models.json (interactive in TTY or via flags).",
|
|
53767
|
+
usage: "models add [--profile <name>] [--api <openai-completions|openai-responses|anthropic-messages>] [--base-url <url>] [--model <id>] [--api-key-env <VAR> | --api-key <key>] [--reasoning] [--default] [--backup-corrupt] [--path <path>] [--json]",
|
|
53768
|
+
flags: [
|
|
53769
|
+
{ name: "--json", kind: "boolean", description: "Emit the machine envelope (compact JSON)." },
|
|
53770
|
+
{ name: "--path", kind: "string", description: "Target models.json path (default ~/.pie/models.json)." },
|
|
53771
|
+
{ name: "--profile", kind: "string", description: "Profile/provider name (e.g. openai, anthropic, deepseek)." },
|
|
53772
|
+
{ name: "--api", kind: "string", description: "Protocol: openai-completions (default), openai-responses, or anthropic-messages." },
|
|
53773
|
+
{ name: "--base-url", kind: "string", description: "Provider API base URL (https://...)." },
|
|
53774
|
+
{ name: "--model", kind: "string", description: "Model ID exposed by the provider." },
|
|
53775
|
+
{ name: "--name", kind: "string", description: "Optional display name for the model." },
|
|
53776
|
+
{ name: "--api-key-env", kind: "string", description: "Environment variable name holding the API key." },
|
|
53777
|
+
{ name: "--api-key", kind: "string", description: "Literal API key (written with 0600 permissions)." },
|
|
53778
|
+
{ name: "--reasoning", kind: "boolean", description: "Mark the model as reasoning-capable." },
|
|
53779
|
+
{ name: "--default", kind: "boolean", description: "Set this profile/model as the default." },
|
|
53780
|
+
{ name: "--backup-corrupt", kind: "boolean", description: "Back up corrupt models.json before rewriting." }
|
|
53781
|
+
],
|
|
53782
|
+
positional: []
|
|
53783
|
+
};
|
|
53616
53784
|
var MODELS_VALIDATE_SPEC = {
|
|
53617
53785
|
path: "models validate",
|
|
53618
53786
|
summary: "Validate models.json configuration.",
|
|
@@ -53638,9 +53806,9 @@ var EXTENSIONS_LIST_SPEC = {
|
|
|
53638
53806
|
positional: []
|
|
53639
53807
|
};
|
|
53640
53808
|
var EXTENSIONS_TOGGLE_SPEC = {
|
|
53641
|
-
path: "extensions enable/disable",
|
|
53642
|
-
summary: "Toggle extension enablement in user or project settings.",
|
|
53643
|
-
usage: "extensions <enable|disable> <name> [--project | --user] [--json]",
|
|
53809
|
+
path: "extensions enable/disable/reset",
|
|
53810
|
+
summary: "Toggle or reset extension enablement in user or project settings.",
|
|
53811
|
+
usage: "extensions <enable|disable|reset> <name> [--project | --user] [--json]",
|
|
53644
53812
|
flags: [
|
|
53645
53813
|
{ name: "--json", kind: "boolean", description: "Emit the machine envelope (compact JSON)." },
|
|
53646
53814
|
{ name: "--project", kind: "boolean", description: "Write ./.pie/settings.json (default is user scope)." },
|
|
@@ -53727,6 +53895,7 @@ var MANAGEMENT_COMMAND_SPECS = [
|
|
|
53727
53895
|
CHAT_SPEC,
|
|
53728
53896
|
DOCTOR_SPEC,
|
|
53729
53897
|
MODELS_INIT_SPEC,
|
|
53898
|
+
MODELS_ADD_SPEC,
|
|
53730
53899
|
MODELS_VALIDATE_SPEC,
|
|
53731
53900
|
MANAGER_SPEC,
|
|
53732
53901
|
MEMORY_SPEC,
|
|
@@ -53898,6 +54067,7 @@ async function runDoctorCommand(args) {
|
|
|
53898
54067
|
}
|
|
53899
54068
|
function printModelsUsage() {
|
|
53900
54069
|
console.log(`Usage:
|
|
54070
|
+
pie models add [--profile <name>] [--api <api>] [--base-url <url>] [--model <id>] [--api-key-env <VAR> | --api-key <key>] [--default] [--json]
|
|
53901
54071
|
pie models init [--path <path>] [--force] [--stdout] [--json]
|
|
53902
54072
|
pie models validate [--path <path>] [--probe web_search] [--json]`);
|
|
53903
54073
|
}
|
|
@@ -53908,6 +54078,10 @@ async function runModelsCommand(args) {
|
|
|
53908
54078
|
return;
|
|
53909
54079
|
}
|
|
53910
54080
|
const rest = args.slice(1);
|
|
54081
|
+
if (subcommand === "add") {
|
|
54082
|
+
await runModelsAdd(rest, args);
|
|
54083
|
+
return;
|
|
54084
|
+
}
|
|
53911
54085
|
if (subcommand === "init") {
|
|
53912
54086
|
await runModelsInit(rest, args);
|
|
53913
54087
|
return;
|
|
@@ -53918,6 +54092,72 @@ async function runModelsCommand(args) {
|
|
|
53918
54092
|
}
|
|
53919
54093
|
emitTopLevelUsageError("models", "unknown_command", `Unknown models command: ${subcommand}`, args);
|
|
53920
54094
|
}
|
|
54095
|
+
async function runModelsAdd(rest, allArgs) {
|
|
54096
|
+
const parsed = parseCommandArgs(rest, MODELS_ADD_SPEC);
|
|
54097
|
+
if (parsed.error) {
|
|
54098
|
+
emitTopLevelUsageError("models.add", parsed.error.code, `${parsed.error.message}
|
|
54099
|
+
${renderCommandUsage(MODELS_ADD_SPEC)}`, allArgs);
|
|
54100
|
+
return;
|
|
54101
|
+
}
|
|
54102
|
+
if (parsed.help) {
|
|
54103
|
+
console.log(renderCommandHelp(MODELS_ADD_SPEC));
|
|
54104
|
+
return;
|
|
54105
|
+
}
|
|
54106
|
+
const json = getFlagBool(parsed, "--json");
|
|
54107
|
+
let profile = getFlagString(parsed, "--profile");
|
|
54108
|
+
let api = getFlagString(parsed, "--api");
|
|
54109
|
+
let baseUrl = getFlagString(parsed, "--base-url");
|
|
54110
|
+
let modelId = getFlagString(parsed, "--model");
|
|
54111
|
+
let apiKeyEnv = getFlagString(parsed, "--api-key-env");
|
|
54112
|
+
let apiKey = getFlagString(parsed, "--api-key");
|
|
54113
|
+
let setDefault = getFlagBool(parsed, "--default");
|
|
54114
|
+
const reasoningExplicit = getFlagBool(parsed, "--reasoning") ? true : void 0;
|
|
54115
|
+
if (!json && process.stdin.isTTY && process.stdout.isTTY && (!profile || !baseUrl || !modelId || !apiKey && !apiKeyEnv)) {
|
|
54116
|
+
const rl = createInterface({ input: process.stdin, output: process.stderr });
|
|
54117
|
+
try {
|
|
54118
|
+
if (!profile) profile = (await rl.question("Profile name (e.g. openai, anthropic, custom): ")).trim();
|
|
54119
|
+
if (!api) {
|
|
54120
|
+
const ans = (await rl.question(`API protocol [${SUPPORTED_MODEL_APIS.join(" / ")}] (default openai-completions): `)).trim();
|
|
54121
|
+
api = ans || "openai-completions";
|
|
54122
|
+
}
|
|
54123
|
+
if (!baseUrl) baseUrl = (await rl.question("Base URL (e.g. https://api.openai.com/v1): ")).trim();
|
|
54124
|
+
if (!modelId) modelId = (await rl.question("Model ID (e.g. gpt-4.1, claude-sonnet-4-5): ")).trim();
|
|
54125
|
+
if (!apiKey && !apiKeyEnv) {
|
|
54126
|
+
const envAns = (await rl.question("API key env var name (recommended; leave blank to pass --api-key instead): ")).trim();
|
|
54127
|
+
if (envAns) apiKeyEnv = envAns;
|
|
54128
|
+
}
|
|
54129
|
+
if (!setDefault) {
|
|
54130
|
+
const defAns = (await rl.question("Set as default model? [Y/n]: ")).trim().toLowerCase();
|
|
54131
|
+
setDefault = defAns === "" || defAns === "y" || defAns === "yes";
|
|
54132
|
+
}
|
|
54133
|
+
} finally {
|
|
54134
|
+
rl.close();
|
|
54135
|
+
}
|
|
54136
|
+
}
|
|
54137
|
+
try {
|
|
54138
|
+
const result = addModelProfile({
|
|
54139
|
+
path: getFlagString(parsed, "--path"),
|
|
54140
|
+
profile: profile ?? "",
|
|
54141
|
+
api: api ?? "openai-completions",
|
|
54142
|
+
baseUrl: baseUrl ?? "",
|
|
54143
|
+
modelId: modelId ?? "",
|
|
54144
|
+
modelName: getFlagString(parsed, "--name"),
|
|
54145
|
+
apiKey,
|
|
54146
|
+
apiKeyEnv,
|
|
54147
|
+
reasoning: reasoningExplicit,
|
|
54148
|
+
setDefault,
|
|
54149
|
+
backupCorrupt: getFlagBool(parsed, "--backup-corrupt")
|
|
54150
|
+
});
|
|
54151
|
+
if (json) {
|
|
54152
|
+
printSuccessEnvelope("models.add", result);
|
|
54153
|
+
} else {
|
|
54154
|
+
if (result.backedUpTo) console.log(`Backed up corrupt models.json to: ${result.backedUpTo}`);
|
|
54155
|
+
console.log(`Saved ${result.profile}/${result.modelId} (${result.api}) to ${result.path}${result.isDefault ? " [default]" : ""}`);
|
|
54156
|
+
}
|
|
54157
|
+
} catch (error) {
|
|
54158
|
+
emitCommandError(error, { json, fallbackKind: "models.add" });
|
|
54159
|
+
}
|
|
54160
|
+
}
|
|
53921
54161
|
async function runModelsInit(rest, allArgs) {
|
|
53922
54162
|
const parsed = parseCommandArgs(rest, MODELS_INIT_SPEC);
|
|
53923
54163
|
if (parsed.error) {
|
|
@@ -56364,9 +56604,10 @@ function printExtensionsUsage() {
|
|
|
56364
56604
|
pie extensions list [--json] [--extension-path <dir>] [--fields <list>]
|
|
56365
56605
|
pie extensions enable <name> [--project|--user] [--json]
|
|
56366
56606
|
pie extensions disable <name> [--project|--user] [--json]
|
|
56607
|
+
pie extensions reset <name> [--project|--user] [--json]
|
|
56367
56608
|
|
|
56368
56609
|
Enablement overrides are stored sparsely; absent entries default to enabled.
|
|
56369
|
-
Project scope writes ./.pie/settings.json and overrides user scope.`);
|
|
56610
|
+
Project scope writes ./.pie/settings.json and overrides user scope; use reset --project to inherit the user default again.`);
|
|
56370
56611
|
}
|
|
56371
56612
|
async function runExtensionsCommand(args) {
|
|
56372
56613
|
const subcommand = args[0] || "list";
|
|
@@ -56380,13 +56621,13 @@ async function runExtensionsCommand(args) {
|
|
|
56380
56621
|
await runExtensionsList(rest);
|
|
56381
56622
|
return;
|
|
56382
56623
|
}
|
|
56383
|
-
if (subcommand === "enable" || subcommand === "disable") {
|
|
56624
|
+
if (subcommand === "enable" || subcommand === "disable" || subcommand === "reset") {
|
|
56384
56625
|
await runExtensionsToggle(subcommand, rest);
|
|
56385
56626
|
return;
|
|
56386
56627
|
}
|
|
56387
56628
|
throw new CommandError("extensions", "unknown_command", `Unknown extensions command: ${subcommand}`, {
|
|
56388
56629
|
usage: true,
|
|
56389
|
-
hint: "subcommands: list, enable, disable"
|
|
56630
|
+
hint: "subcommands: list, enable, disable, reset"
|
|
56390
56631
|
});
|
|
56391
56632
|
} catch (error) {
|
|
56392
56633
|
emitCommandError(error, { json: args.includes("--json"), fallbackKind: "extensions" });
|
|
@@ -56443,16 +56684,18 @@ async function runExtensionsToggle(subcommand, rest) {
|
|
|
56443
56684
|
throw new CommandError(`extensions.${subcommand}`, "invalid_argument", "Choose one scope: --project or --user.", { usage: true });
|
|
56444
56685
|
}
|
|
56445
56686
|
const scope = project ? "project" : "user";
|
|
56446
|
-
const enabled = subcommand === "enable";
|
|
56687
|
+
const enabled = subcommand === "reset" ? void 0 : subcommand === "enable";
|
|
56447
56688
|
const settingsManager = new SettingsManager();
|
|
56448
56689
|
settingsManager.setExtensionEnabled(name, enabled, scope);
|
|
56690
|
+
const effectiveEnabled = settingsManager.isExtensionEnabled(name);
|
|
56449
56691
|
if (json) {
|
|
56450
|
-
printSuccessEnvelope(`extensions.${subcommand}`, { identity: name, enabled, scope });
|
|
56692
|
+
printSuccessEnvelope(`extensions.${subcommand}`, { identity: name, enabled: enabled ?? null, effectiveEnabled, scope });
|
|
56451
56693
|
return;
|
|
56452
56694
|
}
|
|
56453
56695
|
const scopeLabel = scope === "project" ? "./.pie/settings.json" : "~/.pie/settings.json";
|
|
56696
|
+
const actionLabel = subcommand === "reset" ? `override cleared (effective: ${effectiveEnabled ? "enabled" : "disabled"})` : `${enabled ? "enabled" : "disabled"}${effectiveEnabled !== enabled ? ` (effective: ${effectiveEnabled ? "enabled" : "disabled"} due to project override)` : ""}`;
|
|
56454
56697
|
console.log(
|
|
56455
|
-
`Extension "${name}" ${
|
|
56698
|
+
`Extension "${name}" ${actionLabel} in ${scopeLabel}. Takes effect on next start.`
|
|
56456
56699
|
);
|
|
56457
56700
|
}
|
|
56458
56701
|
function parseExtensionFields(raw) {
|
|
@@ -63645,10 +63888,10 @@ var StdinBuffer = class extends EventEmitter {
|
|
|
63645
63888
|
|
|
63646
63889
|
// ../../packages/tui/src/terminal.ts
|
|
63647
63890
|
import * as fs11 from "node:fs";
|
|
63648
|
-
import
|
|
63891
|
+
import { createRequire as createRequire3 } from "node:module";
|
|
63649
63892
|
|
|
63650
63893
|
// ../../packages/tui/src/osc-5522.ts
|
|
63651
|
-
import { randomBytes } from "node:crypto";
|
|
63894
|
+
import { randomBytes as randomBytes2 } from "node:crypto";
|
|
63652
63895
|
var OSC = "\x1B]";
|
|
63653
63896
|
var ST = "\x1B\\";
|
|
63654
63897
|
var READ_TIMEOUT_MS = 8e3;
|
|
@@ -63795,7 +64038,7 @@ var Osc5522Client = class {
|
|
|
63795
64038
|
return { ok: false, kind: "busy", message: "Another OSC 5522 read is already in flight." };
|
|
63796
64039
|
}
|
|
63797
64040
|
const session = {
|
|
63798
|
-
id: `pie-${
|
|
64041
|
+
id: `pie-${randomBytes2(8).toString("hex")}`,
|
|
63799
64042
|
resolve: void 0,
|
|
63800
64043
|
timer: void 0,
|
|
63801
64044
|
chunks: [],
|
|
@@ -64028,6 +64271,7 @@ var ProcessTerminal = class _ProcessTerminal {
|
|
|
64028
64271
|
enableWindowsVTInput() {
|
|
64029
64272
|
if (process.platform !== "win32") return;
|
|
64030
64273
|
try {
|
|
64274
|
+
const koffi = createRequire3(import.meta.url)("koffi");
|
|
64031
64275
|
const k32 = koffi.load("kernel32.dll");
|
|
64032
64276
|
const GetStdHandle = k32.func("void* __stdcall GetStdHandle(int)");
|
|
64033
64277
|
const GetConsoleMode = k32.func("bool __stdcall GetConsoleMode(void*, _Out_ uint32_t*)");
|
|
@@ -64749,7 +64993,7 @@ function wrapToolsWithExtensions(tools, runner) {
|
|
|
64749
64993
|
}
|
|
64750
64994
|
|
|
64751
64995
|
// src/keybindings.ts
|
|
64752
|
-
import { existsSync as existsSync6, readFileSync as
|
|
64996
|
+
import { existsSync as existsSync6, readFileSync as readFileSync8 } from "fs";
|
|
64753
64997
|
import { join as join7 } from "path";
|
|
64754
64998
|
var DEFAULT_APP_KEYBINDINGS = {
|
|
64755
64999
|
interrupt: "escape",
|
|
@@ -64837,7 +65081,7 @@ var KeybindingsManager = class _KeybindingsManager {
|
|
|
64837
65081
|
static loadFromFile(path28) {
|
|
64838
65082
|
if (!existsSync6(path28)) return {};
|
|
64839
65083
|
try {
|
|
64840
|
-
return JSON.parse(
|
|
65084
|
+
return JSON.parse(readFileSync8(path28, "utf-8"));
|
|
64841
65085
|
} catch {
|
|
64842
65086
|
return {};
|
|
64843
65087
|
}
|
|
@@ -71226,7 +71470,7 @@ function trySetExtensionEnabled(host, identity, enabled, scope) {
|
|
|
71226
71470
|
if (scope === "user" && projectOverride !== void 0) {
|
|
71227
71471
|
return {
|
|
71228
71472
|
effectiveEnabled,
|
|
71229
|
-
message: `Saved user default for "${identity}" as ${desiredLabel}. This project's override keeps the effective state ${effectiveLabel}; use /
|
|
71473
|
+
message: `Saved user default for "${identity}" as ${desiredLabel}. This project's override keeps the effective state ${effectiveLabel}; use /extensions --project (or /extensions reset ` + identity + " --project) to change it. Takes effect on next start."
|
|
71230
71474
|
};
|
|
71231
71475
|
}
|
|
71232
71476
|
const settingsPath = scope === "project" ? "./.pie/settings.json" : "~/.pie/settings.json";
|
|
@@ -71262,7 +71506,7 @@ function handleExtensionsCommand(host, args) {
|
|
|
71262
71506
|
if (tokens.length === 0 || tokens[0]?.startsWith("-")) {
|
|
71263
71507
|
const scope = selectorScope(tokens);
|
|
71264
71508
|
if (!scope) {
|
|
71265
|
-
host.showError("Usage: /
|
|
71509
|
+
host.showError("Usage: /extensions [--project|--user]");
|
|
71266
71510
|
return;
|
|
71267
71511
|
}
|
|
71268
71512
|
showExtensionSelector(host, scope);
|
|
@@ -71282,20 +71526,35 @@ function handleExtensionsCommand(host, args) {
|
|
|
71282
71526
|
const description = info.description ? theme.fg("dim", ` \u2014 ${info.description}`) : "";
|
|
71283
71527
|
addLine(host, ` ${state} [${info.source}] ${identity}${description}`);
|
|
71284
71528
|
}
|
|
71285
|
-
addLine(host, theme.fg("dim", "Usage: /
|
|
71529
|
+
addLine(host, theme.fg("dim", "Usage: /extensions [--project] to open the toggle menu, or /extensions reset <name> --project to inherit."));
|
|
71286
71530
|
addLine(host, theme.fg("dim", "Toggles write settings and take effect on next start."));
|
|
71287
71531
|
host.ui.requestRender();
|
|
71288
71532
|
return;
|
|
71289
71533
|
}
|
|
71290
|
-
if (subcommand === "enable" || subcommand === "disable") {
|
|
71534
|
+
if (subcommand === "enable" || subcommand === "disable" || subcommand === "reset") {
|
|
71291
71535
|
const projectFlag = rest.includes("--project");
|
|
71292
71536
|
const name = rest.find((part) => !part.startsWith("-"));
|
|
71293
71537
|
if (!name) {
|
|
71294
|
-
host.showError(`Usage: /
|
|
71538
|
+
host.showError(`Usage: /extensions ${subcommand} <name> [--project|--user]`);
|
|
71295
71539
|
return;
|
|
71296
71540
|
}
|
|
71297
|
-
const enabled = subcommand === "enable";
|
|
71298
71541
|
const scope = projectFlag ? "project" : "user";
|
|
71542
|
+
if (subcommand === "reset") {
|
|
71543
|
+
const { cwd, settingsManager } = host.options;
|
|
71544
|
+
try {
|
|
71545
|
+
settingsManager.setExtensionEnabled(name, void 0, scope, cwd);
|
|
71546
|
+
} catch (error) {
|
|
71547
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
71548
|
+
host.showError(`Failed to reset extension "${name}": ${detail}`);
|
|
71549
|
+
return;
|
|
71550
|
+
}
|
|
71551
|
+
const effective = settingsManager.isExtensionEnabled(name, cwd) ? "enabled" : "disabled";
|
|
71552
|
+
const settingsPath = scope === "project" ? "./.pie/settings.json" : "~/.pie/settings.json";
|
|
71553
|
+
addLine(host, theme.fg("accent", `\u2713 Cleared "${name}" override in ${settingsPath} (effective: ${effective}). Takes effect on next start.`));
|
|
71554
|
+
host.ui.requestRender();
|
|
71555
|
+
return;
|
|
71556
|
+
}
|
|
71557
|
+
const enabled = subcommand === "enable";
|
|
71299
71558
|
const outcome = trySetExtensionEnabled(host, name, enabled, scope);
|
|
71300
71559
|
if (!outcome) return;
|
|
71301
71560
|
addLine(host, theme.fg("accent", `\u2713 ${outcome.message}`));
|
|
@@ -71303,7 +71562,7 @@ function handleExtensionsCommand(host, args) {
|
|
|
71303
71562
|
return;
|
|
71304
71563
|
}
|
|
71305
71564
|
host.showError(
|
|
71306
|
-
"Usage: /
|
|
71565
|
+
"Usage: /extensions [--project|--user] | list | enable <name> [--project] | disable <name> [--project] | reset <name> [--project]"
|
|
71307
71566
|
);
|
|
71308
71567
|
}
|
|
71309
71568
|
|
|
@@ -73962,7 +74221,7 @@ async function handleModelCommand(host, searchTerm) {
|
|
|
73962
74221
|
}
|
|
73963
74222
|
const availableModels = host.options.modelRegistry.listAvailableModels();
|
|
73964
74223
|
if (availableModels.length === 0) {
|
|
73965
|
-
host.showStatus("No configured models found.
|
|
74224
|
+
host.showStatus("No configured models found. Run `pie models add` to configure a model profile.");
|
|
73966
74225
|
return;
|
|
73967
74226
|
}
|
|
73968
74227
|
host.showSelector((done) => {
|
|
@@ -77435,7 +77694,7 @@ function setupInteractiveKeybindings(host) {
|
|
|
77435
77694
|
|
|
77436
77695
|
// src/clipboard/read-clipboard-image.ts
|
|
77437
77696
|
import { spawn as spawn3 } from "node:child_process";
|
|
77438
|
-
import { chmodSync, closeSync as closeSync2, existsSync as existsSync14, fchmodSync, mkdtempSync, openSync as openSync2, readFileSync as
|
|
77697
|
+
import { chmodSync, closeSync as closeSync2, existsSync as existsSync14, fchmodSync, mkdtempSync, openSync as openSync2, readFileSync as readFileSync15, rmdirSync, statSync as statSync5, unlinkSync as unlinkSync2, writeFileSync as writeFileSync7 } from "node:fs";
|
|
77439
77698
|
import { tmpdir } from "node:os";
|
|
77440
77699
|
import { join as join14 } from "node:path";
|
|
77441
77700
|
var MAX_IMAGE_BYTES = 50 * 1024 * 1024;
|
|
@@ -77767,7 +78026,7 @@ function finalizeTempImage(path28, mimeType) {
|
|
|
77767
78026
|
if (size > MAX_IMAGE_BYTES) {
|
|
77768
78027
|
return { ok: false, kind: "too-large", message: `Clipboard image is too large (${formatBytes2(size)}).` };
|
|
77769
78028
|
}
|
|
77770
|
-
bytes =
|
|
78029
|
+
bytes = readFileSync15(path28);
|
|
77771
78030
|
} catch (err) {
|
|
77772
78031
|
return { ok: false, kind: "failed", message: `Failed to read clipboard image: ${errorMessage4(err)}` };
|
|
77773
78032
|
}
|
|
@@ -77815,7 +78074,7 @@ function formatBytes2(bytes) {
|
|
|
77815
78074
|
}
|
|
77816
78075
|
|
|
77817
78076
|
// src/input/image-paste.ts
|
|
77818
|
-
import { mkdtempSync as mkdtempSync2, writeFileSync as writeFileSync8, rmSync as
|
|
78077
|
+
import { mkdtempSync as mkdtempSync2, writeFileSync as writeFileSync8, rmSync as rmSync3 } from "node:fs";
|
|
77819
78078
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
77820
78079
|
import { join as join15 } from "node:path";
|
|
77821
78080
|
var pastingHosts = /* @__PURE__ */ new WeakSet();
|
|
@@ -77851,7 +78110,7 @@ function terminalResultToClipboardResult(result) {
|
|
|
77851
78110
|
mimeType: result.mimeType,
|
|
77852
78111
|
cleanup: () => {
|
|
77853
78112
|
try {
|
|
77854
|
-
|
|
78113
|
+
rmSync3(dir, { recursive: true, force: true });
|
|
77855
78114
|
} catch {
|
|
77856
78115
|
}
|
|
77857
78116
|
}
|
|
@@ -77859,7 +78118,7 @@ function terminalResultToClipboardResult(result) {
|
|
|
77859
78118
|
} catch (err) {
|
|
77860
78119
|
if (dir) {
|
|
77861
78120
|
try {
|
|
77862
|
-
|
|
78121
|
+
rmSync3(dir, { recursive: true, force: true });
|
|
77863
78122
|
} catch {
|
|
77864
78123
|
}
|
|
77865
78124
|
}
|
|
@@ -86166,7 +86425,7 @@ async function main() {
|
|
|
86166
86425
|
if (sub === STABLE_CLI_COMMANDS.models || sub === STABLE_CLI_COMMANDS.manager) {
|
|
86167
86426
|
try {
|
|
86168
86427
|
if (sub === STABLE_CLI_COMMANDS.models) await runModelsCommand(subArgs);
|
|
86169
|
-
else await (await import("./chunks/manager-cli-
|
|
86428
|
+
else await (await import("./chunks/manager-cli-BXI4UFTJ.js")).runManagerCommand(subArgs);
|
|
86170
86429
|
} catch (error) {
|
|
86171
86430
|
console.error(error instanceof Error ? error.message : String(error));
|
|
86172
86431
|
process.exitCode = 1;
|