@linguacode/cli 1.2.0 → 1.3.0
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 +13 -1
- package/bin/lingua.cjs +850 -528
- package/package.json +1 -1
package/bin/lingua.cjs
CHANGED
|
@@ -410,6 +410,100 @@ var MAX_STDIN_WRITE_BYTES = 256 * 1024;
|
|
|
410
410
|
var MAX_COMPILE_OUTPUT_BYTES = 1024 * 1024;
|
|
411
411
|
var MAX_GO_WASM_BYTES = 10 * 1024 * 1024;
|
|
412
412
|
|
|
413
|
+
// src/cli/runtime/runtimeRecovery.ts
|
|
414
|
+
var import_node_path = __toESM(require("node:path"));
|
|
415
|
+
var CLI_RUNTIME_HELP_URL = "https://linguacode.dev/cli/troubleshooting#missing-runtimes";
|
|
416
|
+
var RUNTIMES = {
|
|
417
|
+
python: {
|
|
418
|
+
name: "Python",
|
|
419
|
+
verifyExecutable: "python3",
|
|
420
|
+
homebrewFormula: "python",
|
|
421
|
+
installGuide: "https://www.python.org/downloads/"
|
|
422
|
+
},
|
|
423
|
+
go: {
|
|
424
|
+
name: "Go",
|
|
425
|
+
verifyExecutable: "go",
|
|
426
|
+
homebrewFormula: "go",
|
|
427
|
+
installGuide: "https://go.dev/doc/install"
|
|
428
|
+
},
|
|
429
|
+
rust: {
|
|
430
|
+
name: "Rust",
|
|
431
|
+
verifyExecutable: "rustc",
|
|
432
|
+
homebrewFormula: "rust",
|
|
433
|
+
installGuide: "https://www.rust-lang.org/tools/install"
|
|
434
|
+
},
|
|
435
|
+
ruby: {
|
|
436
|
+
name: "Ruby",
|
|
437
|
+
verifyExecutable: "ruby",
|
|
438
|
+
homebrewFormula: "ruby",
|
|
439
|
+
installGuide: "https://www.ruby-lang.org/en/documentation/installation/"
|
|
440
|
+
},
|
|
441
|
+
lua: {
|
|
442
|
+
name: "Lua",
|
|
443
|
+
verifyExecutable: "lua",
|
|
444
|
+
homebrewFormula: "lua",
|
|
445
|
+
installGuide: "https://www.lua.org/download.html"
|
|
446
|
+
},
|
|
447
|
+
node: {
|
|
448
|
+
name: "Node.js",
|
|
449
|
+
verifyExecutable: "node",
|
|
450
|
+
homebrewFormula: "node@24",
|
|
451
|
+
installGuide: "https://nodejs.org/en/download"
|
|
452
|
+
}
|
|
453
|
+
};
|
|
454
|
+
function buildMissingRuntimeRecovery(command, runtime, platform = process.platform) {
|
|
455
|
+
const executable = executableName(command);
|
|
456
|
+
const key = runtimeKey(executable, runtime);
|
|
457
|
+
const descriptor = RUNTIMES[key] ?? {
|
|
458
|
+
name: runtime || executable,
|
|
459
|
+
verifyExecutable: executable,
|
|
460
|
+
installGuide: CLI_RUNTIME_HELP_URL
|
|
461
|
+
};
|
|
462
|
+
const installCommand = platform === "darwin" && descriptor.homebrewFormula ? `brew install ${descriptor.homebrewFormula}` : void 0;
|
|
463
|
+
const verifyCommand = `${descriptor.verifyExecutable} --version`;
|
|
464
|
+
const recovery = {
|
|
465
|
+
runtime: descriptor.name,
|
|
466
|
+
executable,
|
|
467
|
+
...installCommand ? { installCommand } : {},
|
|
468
|
+
installGuide: descriptor.installGuide,
|
|
469
|
+
verifyCommand
|
|
470
|
+
};
|
|
471
|
+
const install = installCommand ? `Install on macOS with Homebrew:
|
|
472
|
+
${installCommand}` : `Install ${descriptor.name} for your operating system:
|
|
473
|
+
${descriptor.installGuide}`;
|
|
474
|
+
const guide = descriptor.installGuide === CLI_RUNTIME_HELP_URL ? "" : `
|
|
475
|
+
Setup guide:
|
|
476
|
+
${descriptor.installGuide}`;
|
|
477
|
+
return {
|
|
478
|
+
detail: [
|
|
479
|
+
`${descriptor.name} is required for this run, but Lingua could not find \`${executable}\` on PATH.`,
|
|
480
|
+
install,
|
|
481
|
+
`Verify the setup:
|
|
482
|
+
${verifyCommand}`,
|
|
483
|
+
`Then retry the same Lingua command.${guide}`,
|
|
484
|
+
`Lingua runtime help:
|
|
485
|
+
${CLI_RUNTIME_HELP_URL}`
|
|
486
|
+
].join("\n\n"),
|
|
487
|
+
recovery
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
function executableName(command) {
|
|
491
|
+
const basename = import_node_path.default.basename(command).toLowerCase();
|
|
492
|
+
return basename.replace(/\.exe$/u, "").replace(/\.cmd$/u, "");
|
|
493
|
+
}
|
|
494
|
+
function runtimeKey(executable, runtime) {
|
|
495
|
+
const normalizedRuntime = runtime.toLowerCase();
|
|
496
|
+
if (executable.startsWith("python") || normalizedRuntime.startsWith("python")) return "python";
|
|
497
|
+
if (executable === "go" || normalizedRuntime.startsWith("go")) return "go";
|
|
498
|
+
if (["rustc", "cargo"].includes(executable) || normalizedRuntime.startsWith("rust")) return "rust";
|
|
499
|
+
if (executable === "ruby" || normalizedRuntime.startsWith("ruby")) return "ruby";
|
|
500
|
+
if (executable === "lua" || normalizedRuntime.startsWith("lua")) return "lua";
|
|
501
|
+
if (["node", "npm", "npx"].includes(executable) || normalizedRuntime.startsWith("node")) {
|
|
502
|
+
return "node";
|
|
503
|
+
}
|
|
504
|
+
return normalizedRuntime;
|
|
505
|
+
}
|
|
506
|
+
|
|
413
507
|
// src/cli/runtime/execution.ts
|
|
414
508
|
var DEFAULT_CLI_RUN_TIMEOUT_MS = 3e4;
|
|
415
509
|
var MIN_CLI_RUN_TIMEOUT_MS = 100;
|
|
@@ -439,9 +533,11 @@ async function executeCliPlan(plan, options) {
|
|
|
439
533
|
});
|
|
440
534
|
if (result.spawnError) {
|
|
441
535
|
const missing = result.spawnError.code === "ENOENT";
|
|
536
|
+
const missingRuntime = missing ? buildMissingRuntimeRecovery(step.command, plan.runtime) : void 0;
|
|
442
537
|
return finish(plan, startedAt, result, stdout.value, stderr.value, "error", {
|
|
443
538
|
reason: missing ? "missing-runtime" : "spawn-failed",
|
|
444
|
-
detail:
|
|
539
|
+
detail: missingRuntime?.detail ?? `Failed to start ${step.command}: ${result.spawnError.message}`,
|
|
540
|
+
...missingRuntime ? { recovery: missingRuntime.recovery } : {}
|
|
445
541
|
});
|
|
446
542
|
}
|
|
447
543
|
if (result.timedOut) {
|
|
@@ -640,7 +736,7 @@ function killProcessTree(child, signal) {
|
|
|
640
736
|
// src/cli/runtime/targets.ts
|
|
641
737
|
var import_promises2 = require("node:fs/promises");
|
|
642
738
|
var import_node_os = __toESM(require("node:os"));
|
|
643
|
-
var
|
|
739
|
+
var import_node_path2 = __toESM(require("node:path"));
|
|
644
740
|
|
|
645
741
|
// node_modules/acorn/dist/acorn.mjs
|
|
646
742
|
var astralIdentifierCodes = [509, 0, 227, 0, 150, 4, 294, 9, 1368, 2, 2, 1, 6, 3, 41, 2, 5, 0, 166, 1, 574, 3, 9, 9, 7, 9, 32, 4, 318, 1, 78, 5, 71, 10, 50, 3, 123, 2, 54, 14, 32, 10, 3, 1, 11, 3, 46, 10, 8, 0, 46, 9, 7, 2, 37, 13, 2, 9, 6, 1, 45, 0, 13, 2, 49, 13, 9, 3, 2, 11, 83, 11, 7, 0, 3, 0, 158, 11, 6, 9, 7, 3, 56, 1, 2, 6, 3, 1, 3, 2, 10, 0, 11, 1, 3, 6, 4, 4, 68, 8, 2, 0, 3, 0, 2, 3, 2, 4, 2, 0, 15, 1, 83, 17, 10, 9, 5, 0, 82, 19, 13, 9, 214, 6, 3, 8, 28, 1, 83, 16, 16, 9, 82, 12, 9, 9, 7, 19, 58, 14, 5, 9, 243, 14, 166, 9, 71, 5, 2, 1, 3, 3, 2, 0, 2, 1, 13, 9, 120, 6, 3, 6, 4, 0, 29, 9, 41, 6, 2, 3, 9, 0, 10, 10, 47, 15, 199, 7, 137, 9, 54, 7, 2, 7, 17, 9, 57, 21, 2, 13, 123, 5, 4, 0, 2, 1, 2, 6, 2, 0, 9, 9, 49, 4, 2, 1, 2, 4, 9, 9, 55, 9, 266, 3, 10, 1, 2, 0, 49, 6, 4, 4, 14, 10, 5350, 0, 7, 14, 11465, 27, 2343, 9, 87, 9, 39, 4, 60, 6, 26, 9, 535, 9, 470, 0, 2, 54, 8, 3, 82, 0, 12, 1, 19628, 1, 4178, 9, 519, 45, 3, 22, 543, 4, 4, 5, 9, 7, 3, 6, 31, 3, 149, 2, 1418, 49, 513, 54, 5, 49, 9, 0, 15, 0, 23, 4, 2, 14, 1361, 6, 2, 16, 3, 6, 2, 1, 2, 4, 101, 0, 161, 6, 10, 9, 357, 0, 62, 13, 499, 13, 245, 1, 2, 9, 233, 0, 3, 0, 8, 1, 6, 0, 475, 6, 110, 6, 6, 9, 4759, 9, 787719, 239];
|
|
@@ -6347,7 +6443,7 @@ var ExecutionTargetError = class extends Error {
|
|
|
6347
6443
|
reason;
|
|
6348
6444
|
};
|
|
6349
6445
|
async function resolveExecutionTarget(target, programArgs) {
|
|
6350
|
-
const absolute =
|
|
6446
|
+
const absolute = import_node_path2.default.resolve(target);
|
|
6351
6447
|
let targetStat;
|
|
6352
6448
|
try {
|
|
6353
6449
|
targetStat = await (0, import_promises2.stat)(absolute);
|
|
@@ -6415,7 +6511,7 @@ async function resolveCapsuleSource(input, programArgs) {
|
|
|
6415
6511
|
}
|
|
6416
6512
|
}
|
|
6417
6513
|
async function planProject(root, displayTarget, programArgs) {
|
|
6418
|
-
const packageJson =
|
|
6514
|
+
const packageJson = import_node_path2.default.join(root, "package.json");
|
|
6419
6515
|
if (await exists(packageJson)) {
|
|
6420
6516
|
let manifest;
|
|
6421
6517
|
try {
|
|
@@ -6437,18 +6533,18 @@ async function planProject(root, displayTarget, programArgs) {
|
|
|
6437
6533
|
]);
|
|
6438
6534
|
}
|
|
6439
6535
|
if (isRecord2(manifest) && typeof manifest.main === "string") {
|
|
6440
|
-
const mainPath =
|
|
6536
|
+
const mainPath = import_node_path2.default.resolve(root, manifest.main);
|
|
6441
6537
|
if (await isFile(mainPath)) return planFile(mainPath, displayTarget, programArgs);
|
|
6442
6538
|
}
|
|
6443
6539
|
}
|
|
6444
|
-
if (await exists(
|
|
6540
|
+
if (await exists(import_node_path2.default.join(root, "go.mod"))) {
|
|
6445
6541
|
return singleStep(displayTarget, "go-project", root, commandName("go"), [
|
|
6446
6542
|
"run",
|
|
6447
6543
|
".",
|
|
6448
6544
|
...programArgs
|
|
6449
6545
|
]);
|
|
6450
6546
|
}
|
|
6451
|
-
if (await exists(
|
|
6547
|
+
if (await exists(import_node_path2.default.join(root, "Cargo.toml"))) {
|
|
6452
6548
|
return singleStep(displayTarget, "cargo", root, commandName("cargo"), [
|
|
6453
6549
|
"run",
|
|
6454
6550
|
"--quiet",
|
|
@@ -6457,7 +6553,7 @@ async function planProject(root, displayTarget, programArgs) {
|
|
|
6457
6553
|
]);
|
|
6458
6554
|
}
|
|
6459
6555
|
for (const candidate of PROJECT_ENTRY_CANDIDATES) {
|
|
6460
|
-
const entry =
|
|
6556
|
+
const entry = import_node_path2.default.join(root, candidate);
|
|
6461
6557
|
if (await isFile(entry)) return planFile(entry, displayTarget, programArgs);
|
|
6462
6558
|
}
|
|
6463
6559
|
throw new ExecutionTargetError(
|
|
@@ -6484,8 +6580,8 @@ var PROJECT_ENTRY_CANDIDATES = [
|
|
|
6484
6580
|
"src/index.ts"
|
|
6485
6581
|
];
|
|
6486
6582
|
async function planFile(absolute, displayTarget, programArgs) {
|
|
6487
|
-
const cwd =
|
|
6488
|
-
const extension =
|
|
6583
|
+
const cwd = import_node_path2.default.dirname(absolute);
|
|
6584
|
+
const extension = import_node_path2.default.extname(absolute).toLowerCase();
|
|
6489
6585
|
switch (extension) {
|
|
6490
6586
|
case ".js":
|
|
6491
6587
|
case ".mjs":
|
|
@@ -6518,8 +6614,8 @@ async function planFile(absolute, displayTarget, programArgs) {
|
|
|
6518
6614
|
case ".lua":
|
|
6519
6615
|
return singleStep(displayTarget, "lua", cwd, commandName("lua"), [absolute, ...programArgs]);
|
|
6520
6616
|
case ".rs": {
|
|
6521
|
-
const temporaryRoot = await (0, import_promises2.mkdtemp)(
|
|
6522
|
-
const binary =
|
|
6617
|
+
const temporaryRoot = await (0, import_promises2.mkdtemp)(import_node_path2.default.join(import_node_os.default.tmpdir(), "lingua-cli-rust-"));
|
|
6618
|
+
const binary = import_node_path2.default.join(
|
|
6523
6619
|
temporaryRoot,
|
|
6524
6620
|
process.platform === "win32" ? "program.exe" : "program"
|
|
6525
6621
|
);
|
|
@@ -6546,8 +6642,8 @@ async function planFile(absolute, displayTarget, programArgs) {
|
|
|
6546
6642
|
}
|
|
6547
6643
|
}
|
|
6548
6644
|
async function stageCompiledSource(displayTarget, language, filename, source, programArgs) {
|
|
6549
|
-
const temporaryRoot = await (0, import_promises2.mkdtemp)(
|
|
6550
|
-
const sourcePath =
|
|
6645
|
+
const temporaryRoot = await (0, import_promises2.mkdtemp)(import_node_path2.default.join(import_node_os.default.tmpdir(), `lingua-cli-${language}-`));
|
|
6646
|
+
const sourcePath = import_node_path2.default.join(temporaryRoot, filename);
|
|
6551
6647
|
await (0, import_promises2.writeFile)(sourcePath, source, "utf8");
|
|
6552
6648
|
if (language === "go") {
|
|
6553
6649
|
return {
|
|
@@ -6564,7 +6660,7 @@ async function stageCompiledSource(displayTarget, language, filename, source, pr
|
|
|
6564
6660
|
]
|
|
6565
6661
|
};
|
|
6566
6662
|
}
|
|
6567
|
-
const binary =
|
|
6663
|
+
const binary = import_node_path2.default.join(temporaryRoot, process.platform === "win32" ? "program.exe" : "program");
|
|
6568
6664
|
return {
|
|
6569
6665
|
displayTarget,
|
|
6570
6666
|
runtime: "rust",
|
|
@@ -6631,9 +6727,9 @@ function planJavaScriptCapsule(displayTarget, cwd, input, programArgs, typescrip
|
|
|
6631
6727
|
async function findPython(startDirectory) {
|
|
6632
6728
|
let current2 = startDirectory;
|
|
6633
6729
|
while (true) {
|
|
6634
|
-
const local = process.platform === "win32" ?
|
|
6730
|
+
const local = process.platform === "win32" ? import_node_path2.default.join(current2, ".venv", "Scripts", "python.exe") : import_node_path2.default.join(current2, ".venv", "bin", "python");
|
|
6635
6731
|
if (await isFile(local)) return local;
|
|
6636
|
-
const parent =
|
|
6732
|
+
const parent = import_node_path2.default.dirname(current2);
|
|
6637
6733
|
if (parent === current2) break;
|
|
6638
6734
|
current2 = parent;
|
|
6639
6735
|
}
|
|
@@ -6743,7 +6839,8 @@ function emitExecution(args, io, result, extra = {}, label = "lingua run", strea
|
|
|
6743
6839
|
if (args.json) {
|
|
6744
6840
|
const failure = result.status === "success" ? {} : {
|
|
6745
6841
|
reason: result.reason ?? result.status,
|
|
6746
|
-
detail: result.detail ?? `Run failed with status ${result.status}
|
|
6842
|
+
detail: result.detail ?? `Run failed with status ${result.status}.`,
|
|
6843
|
+
...result.recovery ? { recovery: result.recovery } : {}
|
|
6747
6844
|
};
|
|
6748
6845
|
io.writeStdout(
|
|
6749
6846
|
`${JSON.stringify({ ok: result.status === "success", ...extra, ...failure, run: result })}
|
|
@@ -6938,6 +7035,24 @@ function errorMessage3(error) {
|
|
|
6938
7035
|
return error instanceof Error ? error.message : String(error);
|
|
6939
7036
|
}
|
|
6940
7037
|
|
|
7038
|
+
// src/cli/commands/completionInstall.ts
|
|
7039
|
+
var import_node_fs = require("node:fs");
|
|
7040
|
+
var import_promises3 = require("node:fs/promises");
|
|
7041
|
+
var import_node_os2 = __toESM(require("node:os"));
|
|
7042
|
+
var import_node_path3 = __toESM(require("node:path"));
|
|
7043
|
+
|
|
7044
|
+
// src/cli/commandModel.ts
|
|
7045
|
+
var CLI_COLOR_MODES = ["auto", "always", "never"];
|
|
7046
|
+
var CLI_COMPLETION_SHELLS = ["bash", "zsh", "fish"];
|
|
7047
|
+
var CLI_COMPLETION_TARGETS = [...CLI_COMPLETION_SHELLS, "install"];
|
|
7048
|
+
var CLI_TOP_LEVEL_COMMANDS = ["utility", "run", "capsule", "list", "completion"];
|
|
7049
|
+
function isCliColorMode(value) {
|
|
7050
|
+
return CLI_COLOR_MODES.includes(value);
|
|
7051
|
+
}
|
|
7052
|
+
function isCliCompletionShell(value) {
|
|
7053
|
+
return CLI_COMPLETION_SHELLS.includes(value);
|
|
7054
|
+
}
|
|
7055
|
+
|
|
6941
7056
|
// src/shared/utilities/types.ts
|
|
6942
7057
|
var UTILITY_ADAPTER_IDS = [
|
|
6943
7058
|
"json-format",
|
|
@@ -6980,121 +7095,620 @@ var UTILITY_ADAPTER_IDS = [
|
|
|
6980
7095
|
"cron-phrase"
|
|
6981
7096
|
];
|
|
6982
7097
|
|
|
6983
|
-
// src/
|
|
6984
|
-
|
|
6985
|
-
|
|
6986
|
-
|
|
6987
|
-
|
|
7098
|
+
// src/cli/completion.ts
|
|
7099
|
+
var commandWords = CLI_TOP_LEVEL_COMMANDS.join(" ");
|
|
7100
|
+
var colorWords = CLI_COLOR_MODES.join(" ");
|
|
7101
|
+
var shellWords = CLI_COMPLETION_TARGETS.join(" ");
|
|
7102
|
+
var utilityWords = [...UTILITY_ADAPTER_IDS].sort().join(" ");
|
|
7103
|
+
function renderCompletion(shell) {
|
|
7104
|
+
switch (shell) {
|
|
7105
|
+
case "bash":
|
|
7106
|
+
return renderBashCompletion();
|
|
7107
|
+
case "zsh":
|
|
7108
|
+
return renderZshCompletion();
|
|
7109
|
+
case "fish":
|
|
7110
|
+
return renderFishCompletion();
|
|
6988
7111
|
}
|
|
6989
|
-
return btoa(binary);
|
|
6990
|
-
}
|
|
6991
|
-
function base64ToBytes(value) {
|
|
6992
|
-
const binary = atob(value);
|
|
6993
|
-
return Uint8Array.from(binary, (char) => char.charCodeAt(0));
|
|
6994
|
-
}
|
|
6995
|
-
function parseEmptyOptions(raw) {
|
|
6996
|
-
if (raw === void 0 || raw === null) return {};
|
|
6997
|
-
if (typeof raw !== "object" || Array.isArray(raw)) return null;
|
|
6998
|
-
return {};
|
|
6999
7112
|
}
|
|
7000
|
-
|
|
7001
|
-
|
|
7002
|
-
|
|
7003
|
-
|
|
7004
|
-
|
|
7005
|
-
|
|
7006
|
-
|
|
7007
|
-
|
|
7008
|
-
|
|
7009
|
-
|
|
7010
|
-
|
|
7011
|
-
|
|
7012
|
-
|
|
7013
|
-
}
|
|
7014
|
-
|
|
7015
|
-
|
|
7016
|
-
|
|
7017
|
-
|
|
7018
|
-
|
|
7019
|
-
|
|
7020
|
-
|
|
7021
|
-
|
|
7022
|
-
|
|
7023
|
-
|
|
7024
|
-
|
|
7025
|
-
|
|
7026
|
-
|
|
7027
|
-
outputKind: "text",
|
|
7028
|
-
optionsSchema: [],
|
|
7029
|
-
defaultOptions: () => ({}),
|
|
7030
|
-
parseOptions: parseEmptyOptions,
|
|
7031
|
-
run: async (input) => {
|
|
7032
|
-
if (input.trim().length === 0) {
|
|
7033
|
-
return { ok: true, value: "" };
|
|
7034
|
-
}
|
|
7035
|
-
try {
|
|
7036
|
-
const sanitized = input.replace(/\s+/gu, "");
|
|
7037
|
-
const bytes = base64ToBytes(sanitized);
|
|
7038
|
-
const value = new TextDecoder().decode(bytes);
|
|
7039
|
-
return { ok: true, value };
|
|
7040
|
-
} catch (err) {
|
|
7041
|
-
return {
|
|
7042
|
-
ok: false,
|
|
7043
|
-
reason: "invalid-input",
|
|
7044
|
-
detail: err instanceof Error ? err.message : "invalid base64"
|
|
7045
|
-
};
|
|
7046
|
-
}
|
|
7047
|
-
}
|
|
7048
|
-
};
|
|
7113
|
+
function renderBashCompletion() {
|
|
7114
|
+
return `# lingua bash completion
|
|
7115
|
+
_lingua() {
|
|
7116
|
+
local cur prev command command_index index relative word
|
|
7117
|
+
COMPREPLY=()
|
|
7118
|
+
cur="\${COMP_WORDS[COMP_CWORD]}"
|
|
7119
|
+
prev=""
|
|
7120
|
+
if (( COMP_CWORD > 0 )); then
|
|
7121
|
+
prev="\${COMP_WORDS[COMP_CWORD-1]}"
|
|
7122
|
+
fi
|
|
7123
|
+
command=""
|
|
7124
|
+
command_index=0
|
|
7125
|
+
for (( index=1; index<COMP_CWORD; index++ )); do
|
|
7126
|
+
word="\${COMP_WORDS[index]}"
|
|
7127
|
+
case "$word" in
|
|
7128
|
+
--color)
|
|
7129
|
+
(( index++ ))
|
|
7130
|
+
;;
|
|
7131
|
+
--color=*)
|
|
7132
|
+
;;
|
|
7133
|
+
utility|run|capsule|list|completion)
|
|
7134
|
+
command="$word"
|
|
7135
|
+
command_index=$index
|
|
7136
|
+
break
|
|
7137
|
+
;;
|
|
7138
|
+
esac
|
|
7139
|
+
done
|
|
7049
7140
|
|
|
7050
|
-
|
|
7051
|
-
|
|
7052
|
-
|
|
7053
|
-
|
|
7054
|
-
|
|
7141
|
+
case "$cur" in
|
|
7142
|
+
--color=*)
|
|
7143
|
+
local value="\${cur#--color=}"
|
|
7144
|
+
COMPREPLY=( $(compgen -W "${colorWords}" -- "$value") )
|
|
7145
|
+
COMPREPLY=( "\${COMPREPLY[@]/#/--color=}" )
|
|
7146
|
+
return
|
|
7147
|
+
;;
|
|
7148
|
+
esac
|
|
7149
|
+
|
|
7150
|
+
case "$prev" in
|
|
7151
|
+
--color)
|
|
7152
|
+
COMPREPLY=( $(compgen -W "${colorWords}" -- "$cur") )
|
|
7153
|
+
return
|
|
7154
|
+
;;
|
|
7155
|
+
--input|--stdin)
|
|
7156
|
+
compopt -o filenames 2>/dev/null || true
|
|
7157
|
+
COMPREPLY=( $(compgen -f -- "$cur") )
|
|
7158
|
+
return
|
|
7159
|
+
;;
|
|
7160
|
+
--timeout)
|
|
7161
|
+
return
|
|
7162
|
+
;;
|
|
7163
|
+
--env|--option)
|
|
7164
|
+
return
|
|
7165
|
+
;;
|
|
7166
|
+
esac
|
|
7167
|
+
|
|
7168
|
+
if [[ -z "$command" ]]; then
|
|
7169
|
+
COMPREPLY=( $(compgen -W "${commandWords} --help --version --color" -- "$cur") )
|
|
7170
|
+
return
|
|
7171
|
+
fi
|
|
7172
|
+
|
|
7173
|
+
case "$command" in
|
|
7174
|
+
utility)
|
|
7175
|
+
relative=$(( COMP_CWORD - command_index ))
|
|
7176
|
+
if (( relative == 1 )); then
|
|
7177
|
+
COMPREPLY=( $(compgen -W "${utilityWords}" -- "$cur") )
|
|
7178
|
+
elif [[ "$cur" == -* ]]; then
|
|
7179
|
+
COMPREPLY=( $(compgen -W "--input --option --json --quiet --color --help" -- "$cur") )
|
|
7180
|
+
fi
|
|
7181
|
+
;;
|
|
7182
|
+
run)
|
|
7183
|
+
if [[ "$cur" == -* ]]; then
|
|
7184
|
+
COMPREPLY=( $(compgen -W "--stdin --timeout --env --json --quiet --color --help --" -- "$cur") )
|
|
7185
|
+
else
|
|
7186
|
+
compopt -o filenames 2>/dev/null || true
|
|
7187
|
+
COMPREPLY=( $(compgen -f -- "$cur") )
|
|
7188
|
+
fi
|
|
7189
|
+
;;
|
|
7190
|
+
capsule)
|
|
7191
|
+
relative=$(( COMP_CWORD - command_index ))
|
|
7192
|
+
if (( relative == 1 )); then
|
|
7193
|
+
COMPREPLY=( $(compgen -W "validate replay" -- "$cur") )
|
|
7194
|
+
elif [[ "$cur" == -* ]]; then
|
|
7195
|
+
COMPREPLY=( $(compgen -W "--timeout --env --json --quiet --color --help" -- "$cur") )
|
|
7196
|
+
else
|
|
7197
|
+
compopt -o filenames 2>/dev/null || true
|
|
7198
|
+
COMPREPLY=( $(compgen -f -- "$cur") )
|
|
7199
|
+
fi
|
|
7200
|
+
;;
|
|
7201
|
+
list)
|
|
7202
|
+
relative=$(( COMP_CWORD - command_index ))
|
|
7203
|
+
if (( relative == 1 )); then
|
|
7204
|
+
COMPREPLY=( $(compgen -W "utilities" -- "$cur") )
|
|
7205
|
+
else
|
|
7206
|
+
COMPREPLY=( $(compgen -W "--json --quiet --color --help" -- "$cur") )
|
|
7207
|
+
fi
|
|
7208
|
+
;;
|
|
7209
|
+
completion)
|
|
7210
|
+
relative=$(( COMP_CWORD - command_index ))
|
|
7211
|
+
if (( relative == 1 )); then
|
|
7212
|
+
COMPREPLY=( $(compgen -W "${shellWords}" -- "$cur") )
|
|
7213
|
+
else
|
|
7214
|
+
COMPREPLY=( $(compgen -W "--yes --dry-run --color --help" -- "$cur") )
|
|
7215
|
+
fi
|
|
7216
|
+
;;
|
|
7217
|
+
esac
|
|
7055
7218
|
}
|
|
7056
|
-
|
|
7057
|
-
|
|
7219
|
+
complete -F _lingua lingua
|
|
7220
|
+
`;
|
|
7058
7221
|
}
|
|
7059
|
-
function
|
|
7060
|
-
|
|
7061
|
-
|
|
7062
|
-
|
|
7063
|
-
|
|
7064
|
-
|
|
7065
|
-
|
|
7066
|
-
|
|
7067
|
-
|
|
7068
|
-
|
|
7069
|
-
|
|
7070
|
-
|
|
7071
|
-
|
|
7072
|
-
|
|
7073
|
-
|
|
7074
|
-
|
|
7075
|
-
|
|
7076
|
-
|
|
7077
|
-
|
|
7078
|
-
|
|
7079
|
-
|
|
7080
|
-
|
|
7081
|
-
|
|
7082
|
-
|
|
7083
|
-
|
|
7084
|
-
|
|
7085
|
-
|
|
7086
|
-
|
|
7087
|
-
|
|
7088
|
-
|
|
7089
|
-
|
|
7090
|
-
|
|
7091
|
-
|
|
7092
|
-
|
|
7093
|
-
|
|
7094
|
-
|
|
7095
|
-
|
|
7096
|
-
|
|
7097
|
-
|
|
7222
|
+
function renderZshCompletion() {
|
|
7223
|
+
return `#compdef lingua
|
|
7224
|
+
# lingua zsh completion
|
|
7225
|
+
_lingua() {
|
|
7226
|
+
local context state state_descr line
|
|
7227
|
+
typeset -A opt_args
|
|
7228
|
+
local -a commands utilities color_modes completion_targets
|
|
7229
|
+
local command_index index
|
|
7230
|
+
commands=(
|
|
7231
|
+
'utility:Run a shared utility adapter'
|
|
7232
|
+
'run:Execute a source file or project root'
|
|
7233
|
+
'capsule:Validate or replay a Run Capsule'
|
|
7234
|
+
'list:List available capabilities'
|
|
7235
|
+
'completion:Generate a shell completion script'
|
|
7236
|
+
)
|
|
7237
|
+
utilities=(${utilityWords})
|
|
7238
|
+
color_modes=(${colorWords})
|
|
7239
|
+
completion_targets=(${shellWords})
|
|
7240
|
+
|
|
7241
|
+
_arguments -C \\
|
|
7242
|
+
'(-h --help)'{-h,--help}'[Show help]' \\
|
|
7243
|
+
'(-v --version)'{-v,--version}'[Print the CLI version]' \\
|
|
7244
|
+
'--color=[Control diagnostic color]:mode:(auto always never)' \\
|
|
7245
|
+
'1:command:->command' \\
|
|
7246
|
+
'*::argument:->arguments'
|
|
7247
|
+
|
|
7248
|
+
case "$state" in
|
|
7249
|
+
command)
|
|
7250
|
+
_describe -t commands 'lingua command' commands
|
|
7251
|
+
;;
|
|
7252
|
+
arguments)
|
|
7253
|
+
command_index=0
|
|
7254
|
+
for (( index=2; index<CURRENT; index++ )); do
|
|
7255
|
+
case "\${words[index]}" in
|
|
7256
|
+
--color)
|
|
7257
|
+
(( index++ ))
|
|
7258
|
+
;;
|
|
7259
|
+
--color=*)
|
|
7260
|
+
;;
|
|
7261
|
+
utility|run|capsule|list|completion)
|
|
7262
|
+
command_index=$index
|
|
7263
|
+
break
|
|
7264
|
+
;;
|
|
7265
|
+
esac
|
|
7266
|
+
done
|
|
7267
|
+
if (( command_index == 0 )); then
|
|
7268
|
+
return 0
|
|
7269
|
+
fi
|
|
7270
|
+
words=("\${(@)words[$command_index,-1]}")
|
|
7271
|
+
(( CURRENT -= command_index - 1 ))
|
|
7272
|
+
case "\${words[1]}" in
|
|
7273
|
+
utility)
|
|
7274
|
+
if (( CURRENT == 2 )); then
|
|
7275
|
+
_describe -t utilities 'utility' utilities
|
|
7276
|
+
else
|
|
7277
|
+
_arguments \\
|
|
7278
|
+
'--input=[Read input from a file]:file:_files' \\
|
|
7279
|
+
'*--option=[Pass an adapter key=value option]:option:' \\
|
|
7280
|
+
'--json[Emit structured JSON]' \\
|
|
7281
|
+
'--quiet[Suppress Lingua diagnostics]' \\
|
|
7282
|
+
'--color=[Control diagnostic color]:mode:(auto always never)' \\
|
|
7283
|
+
'(-h --help)'{-h,--help}'[Show help]'
|
|
7284
|
+
fi
|
|
7285
|
+
;;
|
|
7286
|
+
run)
|
|
7287
|
+
_arguments \\
|
|
7288
|
+
'1:source file or project:_files' \\
|
|
7289
|
+
'--stdin=[Forward a file as program stdin]:file:_files' \\
|
|
7290
|
+
'--timeout=[Set wall-clock timeout in milliseconds]:milliseconds:' \\
|
|
7291
|
+
'*--env=[Add an explicit NAME=value environment entry]:environment:' \\
|
|
7292
|
+
'--json[Emit structured JSON]' \\
|
|
7293
|
+
'--quiet[Suppress Lingua diagnostics]' \\
|
|
7294
|
+
'--color=[Control diagnostic color]:mode:(auto always never)' \\
|
|
7295
|
+
'(-h --help)'{-h,--help}'[Show help]' \\
|
|
7296
|
+
'*::program argument:'
|
|
7297
|
+
;;
|
|
7298
|
+
capsule)
|
|
7299
|
+
if (( CURRENT == 2 )); then
|
|
7300
|
+
_values 'capsule action' validate replay
|
|
7301
|
+
else
|
|
7302
|
+
_arguments \\
|
|
7303
|
+
'2:capsule file:_files' \\
|
|
7304
|
+
'--timeout=[Set replay timeout in milliseconds]:milliseconds:' \\
|
|
7305
|
+
'*--env=[Add an explicit NAME=value environment entry]:environment:' \\
|
|
7306
|
+
'--json[Emit structured JSON]' \\
|
|
7307
|
+
'--quiet[Suppress Lingua diagnostics]' \\
|
|
7308
|
+
'--color=[Control diagnostic color]:mode:(auto always never)' \\
|
|
7309
|
+
'(-h --help)'{-h,--help}'[Show help]'
|
|
7310
|
+
fi
|
|
7311
|
+
;;
|
|
7312
|
+
list)
|
|
7313
|
+
_values 'list target' utilities
|
|
7314
|
+
;;
|
|
7315
|
+
completion)
|
|
7316
|
+
_arguments '1:completion target:(bash zsh fish install)' '--yes[Install without an interactive confirmation]' '--dry-run[Show detected shells and target files without writing]' '--color=[Control diagnostic color]:mode:(auto always never)' '(-h --help)'{-h,--help}'[Show help]'
|
|
7317
|
+
;;
|
|
7318
|
+
esac
|
|
7319
|
+
;;
|
|
7320
|
+
esac
|
|
7321
|
+
}
|
|
7322
|
+
if (( $+functions[compdef] )); then
|
|
7323
|
+
compdef _lingua lingua
|
|
7324
|
+
fi
|
|
7325
|
+
`;
|
|
7326
|
+
}
|
|
7327
|
+
function renderFishCompletion() {
|
|
7328
|
+
const utilityLines = [...UTILITY_ADAPTER_IDS].sort().map((id) => `complete -c lingua -n '__fish_lingua_needs_first_argument utility' -a '${id}'`).join("\n");
|
|
7329
|
+
return `# lingua fish completion
|
|
7330
|
+
function __fish_lingua_needs_command
|
|
7331
|
+
set -l command_index (__fish_lingua_command_index)
|
|
7332
|
+
test -z "$command_index"
|
|
7333
|
+
end
|
|
7334
|
+
|
|
7335
|
+
function __fish_lingua_command_index
|
|
7336
|
+
set -l tokens (commandline -opc)
|
|
7337
|
+
set -l skip_next 0
|
|
7338
|
+
for index in (seq 2 (count $tokens))
|
|
7339
|
+
set -l token $tokens[$index]
|
|
7340
|
+
if test $skip_next -eq 1
|
|
7341
|
+
set skip_next 0
|
|
7342
|
+
continue
|
|
7343
|
+
end
|
|
7344
|
+
switch $token
|
|
7345
|
+
case --color
|
|
7346
|
+
set skip_next 1
|
|
7347
|
+
case '--color=*' --json --quiet --help -h --version -v
|
|
7348
|
+
continue
|
|
7349
|
+
case utility run capsule list completion
|
|
7350
|
+
echo $index
|
|
7351
|
+
return 0
|
|
7352
|
+
end
|
|
7353
|
+
end
|
|
7354
|
+
return 1
|
|
7355
|
+
end
|
|
7356
|
+
|
|
7357
|
+
function __fish_lingua_using_command
|
|
7358
|
+
set -l tokens (commandline -opc)
|
|
7359
|
+
set -l command_index (__fish_lingua_command_index)
|
|
7360
|
+
test -n "$command_index"; and test "$tokens[$command_index]" = "$argv[1]"
|
|
7361
|
+
end
|
|
7362
|
+
|
|
7363
|
+
function __fish_lingua_needs_first_argument
|
|
7364
|
+
set -l tokens (commandline -opc)
|
|
7365
|
+
set -l command_index (__fish_lingua_command_index)
|
|
7366
|
+
if test -z "$command_index"; or test "$tokens[$command_index]" != "$argv[1]"
|
|
7367
|
+
return 1
|
|
7368
|
+
end
|
|
7369
|
+
set -l skip_next 0
|
|
7370
|
+
for index in (seq (math $command_index + 1) (count $tokens))
|
|
7371
|
+
set -l token $tokens[$index]
|
|
7372
|
+
if test $skip_next -eq 1
|
|
7373
|
+
set skip_next 0
|
|
7374
|
+
continue
|
|
7375
|
+
end
|
|
7376
|
+
switch $token
|
|
7377
|
+
case --color --input --option --stdin --timeout --env
|
|
7378
|
+
set skip_next 1
|
|
7379
|
+
case '--color=*' '--input=*' '--option=*' '--stdin=*' '--timeout=*' '--env=*' --json --quiet --help -h
|
|
7380
|
+
continue
|
|
7381
|
+
case '*'
|
|
7382
|
+
return 1
|
|
7383
|
+
end
|
|
7384
|
+
end
|
|
7385
|
+
return 0
|
|
7386
|
+
end
|
|
7387
|
+
|
|
7388
|
+
complete -c lingua -f -n __fish_lingua_needs_command -a 'utility' -d 'Run a shared utility adapter'
|
|
7389
|
+
complete -c lingua -f -n __fish_lingua_needs_command -a 'run' -d 'Execute a source file or project root'
|
|
7390
|
+
complete -c lingua -f -n __fish_lingua_needs_command -a 'capsule' -d 'Validate or replay a Run Capsule'
|
|
7391
|
+
complete -c lingua -f -n __fish_lingua_needs_command -a 'list' -d 'List available capabilities'
|
|
7392
|
+
complete -c lingua -f -n __fish_lingua_needs_command -a 'completion' -d 'Generate a shell completion script'
|
|
7393
|
+
|
|
7394
|
+
complete -c lingua -l help -s h -d 'Show help'
|
|
7395
|
+
complete -c lingua -l version -s v -d 'Print the CLI version'
|
|
7396
|
+
complete -c lingua -l color -r -f -a '${colorWords}' -d 'Control diagnostic color'
|
|
7397
|
+
complete -c lingua -l json -d 'Emit structured JSON'
|
|
7398
|
+
complete -c lingua -l quiet -d 'Suppress Lingua diagnostics'
|
|
7399
|
+
|
|
7400
|
+
${utilityLines}
|
|
7401
|
+
complete -c lingua -n '__fish_lingua_using_command utility' -l input -r -F -d 'Read input from a file'
|
|
7402
|
+
complete -c lingua -n '__fish_lingua_using_command utility' -l option -r -d 'Pass an adapter key=value option'
|
|
7403
|
+
|
|
7404
|
+
complete -c lingua -n '__fish_lingua_using_command run' -l stdin -r -F -d 'Forward a file as program stdin'
|
|
7405
|
+
complete -c lingua -n '__fish_lingua_using_command run' -l timeout -r -d 'Set wall-clock timeout in milliseconds'
|
|
7406
|
+
complete -c lingua -n '__fish_lingua_using_command run' -l env -r -d 'Add an explicit NAME=value environment entry'
|
|
7407
|
+
|
|
7408
|
+
complete -c lingua -n '__fish_lingua_needs_first_argument capsule' -a 'validate replay'
|
|
7409
|
+
complete -c lingua -n '__fish_lingua_using_command capsule' -l timeout -r -d 'Set replay timeout in milliseconds'
|
|
7410
|
+
complete -c lingua -n '__fish_lingua_using_command capsule' -l env -r -d 'Add an explicit NAME=value environment entry'
|
|
7411
|
+
|
|
7412
|
+
complete -c lingua -n '__fish_lingua_needs_first_argument list' -a 'utilities'
|
|
7413
|
+
complete -c lingua -n '__fish_lingua_needs_first_argument completion' -a '${shellWords}'
|
|
7414
|
+
complete -c lingua -n '__fish_lingua_using_command completion' -l yes -d 'Install without interactive confirmation'
|
|
7415
|
+
complete -c lingua -n '__fish_lingua_using_command completion' -l dry-run -d 'Show the install plan without writing files'
|
|
7416
|
+
`;
|
|
7417
|
+
}
|
|
7418
|
+
|
|
7419
|
+
// src/cli/commands/completionInstall.ts
|
|
7420
|
+
var ZSH_BLOCK_START = "# >>> lingua completion >>>";
|
|
7421
|
+
var ZSH_BLOCK_END = "# <<< lingua completion <<<";
|
|
7422
|
+
var ZSH_BLOCK = `${ZSH_BLOCK_START}
|
|
7423
|
+
fpath=("\${ZDOTDIR:-$HOME}/.zfunc" $fpath)
|
|
7424
|
+
autoload -Uz compinit
|
|
7425
|
+
compinit
|
|
7426
|
+
${ZSH_BLOCK_END}`;
|
|
7427
|
+
var defaultDependencies = {
|
|
7428
|
+
homedir: import_node_os2.default.homedir,
|
|
7429
|
+
async isExecutable(filePath) {
|
|
7430
|
+
try {
|
|
7431
|
+
await (0, import_promises3.access)(filePath, import_node_fs.constants.X_OK);
|
|
7432
|
+
return true;
|
|
7433
|
+
} catch {
|
|
7434
|
+
return false;
|
|
7435
|
+
}
|
|
7436
|
+
},
|
|
7437
|
+
async mkdir(directoryPath) {
|
|
7438
|
+
await (0, import_promises3.mkdir)(directoryPath, { recursive: true });
|
|
7439
|
+
},
|
|
7440
|
+
async writeFile(filePath, contents) {
|
|
7441
|
+
await (0, import_promises3.writeFile)(filePath, contents, "utf8");
|
|
7442
|
+
},
|
|
7443
|
+
async readFileIfPresent(filePath) {
|
|
7444
|
+
try {
|
|
7445
|
+
return await (0, import_promises3.readFile)(filePath, "utf8");
|
|
7446
|
+
} catch (error) {
|
|
7447
|
+
if (error.code === "ENOENT") return null;
|
|
7448
|
+
throw error;
|
|
7449
|
+
}
|
|
7450
|
+
},
|
|
7451
|
+
async appendFile(filePath, contents) {
|
|
7452
|
+
await (0, import_promises3.appendFile)(filePath, contents, "utf8");
|
|
7453
|
+
}
|
|
7454
|
+
};
|
|
7455
|
+
function shellFromExecutable(executablePath) {
|
|
7456
|
+
if (!executablePath) return void 0;
|
|
7457
|
+
const name = import_node_path3.default.basename(executablePath);
|
|
7458
|
+
return CLI_COMPLETION_SHELLS.includes(name) ? name : void 0;
|
|
7459
|
+
}
|
|
7460
|
+
function completionPathForShell(shell, io, dependencies) {
|
|
7461
|
+
const home = io.getEnvironmentValue("HOME") || dependencies.homedir();
|
|
7462
|
+
switch (shell) {
|
|
7463
|
+
case "bash": {
|
|
7464
|
+
const dataHome = io.getEnvironmentValue("XDG_DATA_HOME") || import_node_path3.default.join(home, ".local/share");
|
|
7465
|
+
return {
|
|
7466
|
+
completionPath: import_node_path3.default.join(dataHome, "bash-completion/completions/lingua")
|
|
7467
|
+
};
|
|
7468
|
+
}
|
|
7469
|
+
case "zsh": {
|
|
7470
|
+
const zshHome = io.getEnvironmentValue("ZDOTDIR") || home;
|
|
7471
|
+
return {
|
|
7472
|
+
completionPath: import_node_path3.default.join(zshHome, ".zfunc/_lingua"),
|
|
7473
|
+
activationPath: import_node_path3.default.join(zshHome, ".zshrc")
|
|
7474
|
+
};
|
|
7475
|
+
}
|
|
7476
|
+
case "fish": {
|
|
7477
|
+
const configHome = io.getEnvironmentValue("XDG_CONFIG_HOME") || import_node_path3.default.join(home, ".config");
|
|
7478
|
+
return {
|
|
7479
|
+
completionPath: import_node_path3.default.join(configHome, "fish/completions/lingua.fish")
|
|
7480
|
+
};
|
|
7481
|
+
}
|
|
7482
|
+
}
|
|
7483
|
+
}
|
|
7484
|
+
async function resolveExecutable(shell, io, dependencies) {
|
|
7485
|
+
const currentShellPath = io.getEnvironmentValue("SHELL");
|
|
7486
|
+
if (shellFromExecutable(currentShellPath) === shell && currentShellPath !== void 0 && await dependencies.isExecutable(currentShellPath)) {
|
|
7487
|
+
return currentShellPath;
|
|
7488
|
+
}
|
|
7489
|
+
const pathEntries = (io.getEnvironmentValue("PATH") || "").split(import_node_path3.default.delimiter).filter(Boolean);
|
|
7490
|
+
for (const directory of pathEntries) {
|
|
7491
|
+
const candidate = import_node_path3.default.join(directory, shell);
|
|
7492
|
+
if (await dependencies.isExecutable(candidate)) return candidate;
|
|
7493
|
+
}
|
|
7494
|
+
return void 0;
|
|
7495
|
+
}
|
|
7496
|
+
async function detectCompletionTargets(io, dependencies = defaultDependencies) {
|
|
7497
|
+
const currentShell = shellFromExecutable(io.getEnvironmentValue("SHELL"));
|
|
7498
|
+
const targets = [];
|
|
7499
|
+
for (const shell of CLI_COMPLETION_SHELLS) {
|
|
7500
|
+
const executablePath = await resolveExecutable(shell, io, dependencies);
|
|
7501
|
+
if (!executablePath) continue;
|
|
7502
|
+
const paths = completionPathForShell(shell, io, dependencies);
|
|
7503
|
+
targets.push({
|
|
7504
|
+
shell,
|
|
7505
|
+
executablePath,
|
|
7506
|
+
completionPath: paths.completionPath,
|
|
7507
|
+
current: shell === currentShell,
|
|
7508
|
+
...paths.activationPath ? { activationPath: paths.activationPath } : {}
|
|
7509
|
+
});
|
|
7510
|
+
}
|
|
7511
|
+
return targets;
|
|
7512
|
+
}
|
|
7513
|
+
function renderPlan(targets) {
|
|
7514
|
+
const lines = ["Lingua detected these supported shells:"];
|
|
7515
|
+
for (const target of targets) {
|
|
7516
|
+
lines.push(
|
|
7517
|
+
` ${target.current ? "\u25CF" : "\u25CB"} ${target.shell}${target.current ? " (current)" : ""}`,
|
|
7518
|
+
` completion: ${target.completionPath}`
|
|
7519
|
+
);
|
|
7520
|
+
if (target.activationPath) lines.push(` activation: ${target.activationPath}`);
|
|
7521
|
+
}
|
|
7522
|
+
return `${lines.join("\n")}
|
|
7523
|
+
`;
|
|
7524
|
+
}
|
|
7525
|
+
async function ensureZshActivation(rcPath, dependencies) {
|
|
7526
|
+
const current2 = await dependencies.readFileIfPresent(rcPath);
|
|
7527
|
+
if (current2?.includes(ZSH_BLOCK_START) && current2.includes(ZSH_BLOCK_END)) {
|
|
7528
|
+
const start = current2.indexOf(ZSH_BLOCK_START);
|
|
7529
|
+
const end = current2.indexOf(ZSH_BLOCK_END, start) + ZSH_BLOCK_END.length;
|
|
7530
|
+
const updated = `${current2.slice(0, start)}${ZSH_BLOCK}${current2.slice(end)}`;
|
|
7531
|
+
if (updated !== current2) await dependencies.writeFile(rcPath, updated);
|
|
7532
|
+
return;
|
|
7533
|
+
}
|
|
7534
|
+
const prefix = current2 && !current2.endsWith("\n") ? "\n" : "";
|
|
7535
|
+
await dependencies.appendFile(rcPath, `${prefix}${ZSH_BLOCK}
|
|
7536
|
+
`);
|
|
7537
|
+
}
|
|
7538
|
+
async function runCompletionInstallCommand(options, io, dependencies = defaultDependencies) {
|
|
7539
|
+
try {
|
|
7540
|
+
const targets = await detectCompletionTargets(io, dependencies);
|
|
7541
|
+
if (targets.length === 0) {
|
|
7542
|
+
emitCliFailure(io, { json: false, quiet: false, color: "auto" }, {
|
|
7543
|
+
label: "lingua completion",
|
|
7544
|
+
reason: "no-supported-shells",
|
|
7545
|
+
detail: "Lingua could not find bash, zsh, or fish on PATH. Install a supported shell or run `lingua completion <shell>` to print its script."
|
|
7546
|
+
});
|
|
7547
|
+
return CLI_EXIT_CODES.unsupportedCapability;
|
|
7548
|
+
}
|
|
7549
|
+
io.writeStdout(renderPlan(targets));
|
|
7550
|
+
if (options.dryRun) {
|
|
7551
|
+
io.writeStdout("Dry run: no files were changed.\n");
|
|
7552
|
+
return CLI_EXIT_CODES.ok;
|
|
7553
|
+
}
|
|
7554
|
+
if (!options.assumeYes) {
|
|
7555
|
+
const shellNames = targets.map((target) => target.shell).join(", ");
|
|
7556
|
+
const confirmed = await io.confirm(
|
|
7557
|
+
`Install completion support for ${shellNames}?`,
|
|
7558
|
+
true
|
|
7559
|
+
);
|
|
7560
|
+
if (confirmed === null) {
|
|
7561
|
+
emitCliFailure(io, { json: false, quiet: false, color: "auto" }, {
|
|
7562
|
+
label: "lingua completion",
|
|
7563
|
+
reason: "confirmation-required",
|
|
7564
|
+
detail: "Interactive confirmation is unavailable. Re-run `lingua completion install --yes` to approve these changes, or use `--dry-run` to inspect them."
|
|
7565
|
+
});
|
|
7566
|
+
return CLI_EXIT_CODES.userInputError;
|
|
7567
|
+
}
|
|
7568
|
+
if (!confirmed) {
|
|
7569
|
+
io.writeStdout("Cancelled. No files were changed.\n");
|
|
7570
|
+
return CLI_EXIT_CODES.ok;
|
|
7571
|
+
}
|
|
7572
|
+
}
|
|
7573
|
+
for (const target of targets) {
|
|
7574
|
+
await dependencies.mkdir(import_node_path3.default.dirname(target.completionPath));
|
|
7575
|
+
await dependencies.writeFile(target.completionPath, renderCompletion(target.shell));
|
|
7576
|
+
if (target.shell === "zsh" && target.activationPath) {
|
|
7577
|
+
await ensureZshActivation(target.activationPath, dependencies);
|
|
7578
|
+
}
|
|
7579
|
+
}
|
|
7580
|
+
io.writeStdout(
|
|
7581
|
+
`Installed completion support for ${targets.map((target) => target.shell).join(", ")}.
|
|
7582
|
+
Start a new shell session to load it.
|
|
7583
|
+
`
|
|
7584
|
+
);
|
|
7585
|
+
return CLI_EXIT_CODES.ok;
|
|
7586
|
+
} catch (error) {
|
|
7587
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
7588
|
+
emitCliFailure(io, { json: false, quiet: false, color: "auto" }, {
|
|
7589
|
+
label: "lingua completion",
|
|
7590
|
+
reason: "completion-install-failed",
|
|
7591
|
+
detail: `Could not install shell completion: ${detail}`
|
|
7592
|
+
});
|
|
7593
|
+
return CLI_EXIT_CODES.runtimeError;
|
|
7594
|
+
}
|
|
7595
|
+
}
|
|
7596
|
+
|
|
7597
|
+
// src/shared/utilities/base64.ts
|
|
7598
|
+
function bytesToBase64(bytes) {
|
|
7599
|
+
let binary = "";
|
|
7600
|
+
for (let i2 = 0; i2 < bytes.byteLength; i2 += 1) {
|
|
7601
|
+
binary += String.fromCharCode(bytes[i2] ?? 0);
|
|
7602
|
+
}
|
|
7603
|
+
return btoa(binary);
|
|
7604
|
+
}
|
|
7605
|
+
function base64ToBytes(value) {
|
|
7606
|
+
const binary = atob(value);
|
|
7607
|
+
return Uint8Array.from(binary, (char) => char.charCodeAt(0));
|
|
7608
|
+
}
|
|
7609
|
+
function parseEmptyOptions(raw) {
|
|
7610
|
+
if (raw === void 0 || raw === null) return {};
|
|
7611
|
+
if (typeof raw !== "object" || Array.isArray(raw)) return null;
|
|
7612
|
+
return {};
|
|
7613
|
+
}
|
|
7614
|
+
var base64EncodeAdapter = {
|
|
7615
|
+
id: "base64-encode",
|
|
7616
|
+
titleKey: "utilityPipeline.adapter.base64Encode.title",
|
|
7617
|
+
descriptionKey: "utilityPipeline.adapter.base64Encode.description",
|
|
7618
|
+
inputKind: "text",
|
|
7619
|
+
outputKind: "text",
|
|
7620
|
+
optionsSchema: [],
|
|
7621
|
+
defaultOptions: () => ({}),
|
|
7622
|
+
parseOptions: parseEmptyOptions,
|
|
7623
|
+
run: async (input) => {
|
|
7624
|
+
try {
|
|
7625
|
+
const value = bytesToBase64(new TextEncoder().encode(input));
|
|
7626
|
+
return { ok: true, value };
|
|
7627
|
+
} catch (err) {
|
|
7628
|
+
return {
|
|
7629
|
+
ok: false,
|
|
7630
|
+
reason: "execution-error",
|
|
7631
|
+
detail: err instanceof Error ? err.message : "encode failed"
|
|
7632
|
+
};
|
|
7633
|
+
}
|
|
7634
|
+
}
|
|
7635
|
+
};
|
|
7636
|
+
var base64DecodeAdapter = {
|
|
7637
|
+
id: "base64-decode",
|
|
7638
|
+
titleKey: "utilityPipeline.adapter.base64Decode.title",
|
|
7639
|
+
descriptionKey: "utilityPipeline.adapter.base64Decode.description",
|
|
7640
|
+
inputKind: "text",
|
|
7641
|
+
outputKind: "text",
|
|
7642
|
+
optionsSchema: [],
|
|
7643
|
+
defaultOptions: () => ({}),
|
|
7644
|
+
parseOptions: parseEmptyOptions,
|
|
7645
|
+
run: async (input) => {
|
|
7646
|
+
if (input.trim().length === 0) {
|
|
7647
|
+
return { ok: true, value: "" };
|
|
7648
|
+
}
|
|
7649
|
+
try {
|
|
7650
|
+
const sanitized = input.replace(/\s+/gu, "");
|
|
7651
|
+
const bytes = base64ToBytes(sanitized);
|
|
7652
|
+
const value = new TextDecoder().decode(bytes);
|
|
7653
|
+
return { ok: true, value };
|
|
7654
|
+
} catch (err) {
|
|
7655
|
+
return {
|
|
7656
|
+
ok: false,
|
|
7657
|
+
reason: "invalid-input",
|
|
7658
|
+
detail: err instanceof Error ? err.message : "invalid base64"
|
|
7659
|
+
};
|
|
7660
|
+
}
|
|
7661
|
+
}
|
|
7662
|
+
};
|
|
7663
|
+
|
|
7664
|
+
// src/shared/utilities/colorConvert.ts
|
|
7665
|
+
function parseEmptyOptions2(raw) {
|
|
7666
|
+
if (raw === void 0 || raw === null) return {};
|
|
7667
|
+
if (typeof raw !== "object" || Array.isArray(raw)) return null;
|
|
7668
|
+
return {};
|
|
7669
|
+
}
|
|
7670
|
+
function clampByte(value) {
|
|
7671
|
+
return Math.max(0, Math.min(255, Math.round(value)));
|
|
7672
|
+
}
|
|
7673
|
+
function parseColor(input) {
|
|
7674
|
+
const trimmed = input.trim().toLowerCase();
|
|
7675
|
+
const hexMatch = /^#([0-9a-f]{3,8})$/u.exec(trimmed);
|
|
7676
|
+
if (hexMatch) {
|
|
7677
|
+
const hex = hexMatch[1];
|
|
7678
|
+
if (hex.length === 3 || hex.length === 4) {
|
|
7679
|
+
const r = parseInt(hex[0] + hex[0], 16);
|
|
7680
|
+
const g = parseInt(hex[1] + hex[1], 16);
|
|
7681
|
+
const b = parseInt(hex[2] + hex[2], 16);
|
|
7682
|
+
const a = hex.length === 4 ? parseInt(hex[3] + hex[3], 16) / 255 : 1;
|
|
7683
|
+
return { r, g, b, a };
|
|
7684
|
+
}
|
|
7685
|
+
if (hex.length === 6 || hex.length === 8) {
|
|
7686
|
+
const r = parseInt(hex.slice(0, 2), 16);
|
|
7687
|
+
const g = parseInt(hex.slice(2, 4), 16);
|
|
7688
|
+
const b = parseInt(hex.slice(4, 6), 16);
|
|
7689
|
+
const a = hex.length === 8 ? parseInt(hex.slice(6, 8), 16) / 255 : 1;
|
|
7690
|
+
return { r, g, b, a };
|
|
7691
|
+
}
|
|
7692
|
+
return null;
|
|
7693
|
+
}
|
|
7694
|
+
const rgbMatch = /^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/u.exec(
|
|
7695
|
+
trimmed
|
|
7696
|
+
);
|
|
7697
|
+
if (rgbMatch) {
|
|
7698
|
+
const r = Number(rgbMatch[1]);
|
|
7699
|
+
const g = Number(rgbMatch[2]);
|
|
7700
|
+
const b = Number(rgbMatch[3]);
|
|
7701
|
+
if (r > 255 || g > 255 || b > 255) return null;
|
|
7702
|
+
return { r, g, b, a: 1 };
|
|
7703
|
+
}
|
|
7704
|
+
const rgbaMatch = /^rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*([+-]?(?:\d+|\d*\.\d+))\s*\)$/u.exec(
|
|
7705
|
+
trimmed
|
|
7706
|
+
);
|
|
7707
|
+
if (rgbaMatch) {
|
|
7708
|
+
const r = Number(rgbaMatch[1]);
|
|
7709
|
+
const g = Number(rgbaMatch[2]);
|
|
7710
|
+
const b = Number(rgbaMatch[3]);
|
|
7711
|
+
const a = Number(rgbaMatch[4]);
|
|
7098
7712
|
if (r > 255 || g > 255 || b > 255 || !Number.isFinite(a) || a < 0 || a > 1) {
|
|
7099
7713
|
return null;
|
|
7100
7714
|
}
|
|
@@ -9544,387 +10158,57 @@ async function runUtilityCommand(args, io) {
|
|
|
9544
10158
|
function buildOptionsBlob(adapter, cliOptions) {
|
|
9545
10159
|
const blob = {
|
|
9546
10160
|
...adapter.defaultOptions()
|
|
9547
|
-
};
|
|
9548
|
-
const allowedKeys = new Set(adapter.optionsSchema.map((field) => field.key));
|
|
9549
|
-
for (const { key, value } of cliOptions) {
|
|
9550
|
-
if (!allowedKeys.has(key)) {
|
|
9551
|
-
throw new Error(
|
|
9552
|
-
`Adapter "${adapter.id}" has no option "${key}". Allowed: ${[...allowedKeys].sort().join(", ") || "(none)"}`
|
|
9553
|
-
);
|
|
9554
|
-
}
|
|
9555
|
-
blob[key] = coerceOptionValue(adapter, key, value);
|
|
9556
|
-
}
|
|
9557
|
-
return blob;
|
|
9558
|
-
}
|
|
9559
|
-
function coerceOptionValue(adapter, key, raw) {
|
|
9560
|
-
const field = adapter.optionsSchema.find((entry) => entry.key === key);
|
|
9561
|
-
if (!field) return raw;
|
|
9562
|
-
switch (field.type) {
|
|
9563
|
-
case "text":
|
|
9564
|
-
case "textarea":
|
|
9565
|
-
case "select":
|
|
9566
|
-
return raw;
|
|
9567
|
-
case "boolean": {
|
|
9568
|
-
if (raw === "true" || raw === "1" || raw === "yes") return true;
|
|
9569
|
-
if (raw === "false" || raw === "0" || raw === "no") return false;
|
|
9570
|
-
throw new Error(`Option "${key}" expects a boolean (true|false|1|0|yes|no); got "${raw}"`);
|
|
9571
|
-
}
|
|
9572
|
-
}
|
|
9573
|
-
}
|
|
9574
|
-
function emitError(io, args, reason, detail) {
|
|
9575
|
-
emitCliFailure(io, args, { label: "lingua utility", reason, detail });
|
|
9576
|
-
}
|
|
9577
|
-
function runListUtilitiesCommand(args, io) {
|
|
9578
|
-
const entries = listAdapters().map((adapter) => ({
|
|
9579
|
-
id: adapter.id,
|
|
9580
|
-
inputKind: adapter.inputKind,
|
|
9581
|
-
outputKind: adapter.outputKind,
|
|
9582
|
-
titleKey: adapter.titleKey,
|
|
9583
|
-
descriptionKey: adapter.descriptionKey,
|
|
9584
|
-
optionKeys: adapter.optionsSchema.map((field) => field.key)
|
|
9585
|
-
}));
|
|
9586
|
-
if (args.json) {
|
|
9587
|
-
io.writeStdout(`${JSON.stringify({ utilities: entries }, null, 2)}
|
|
9588
|
-
`);
|
|
9589
|
-
return CLI_EXIT_CODES.ok;
|
|
9590
|
-
}
|
|
9591
|
-
if (args.quiet) return CLI_EXIT_CODES.ok;
|
|
9592
|
-
for (const entry of entries) {
|
|
9593
|
-
io.writeStdout(
|
|
9594
|
-
`${entry.id} ${entry.inputKind} \u2192 ${entry.outputKind}` + (entry.optionKeys.length > 0 ? ` options: ${entry.optionKeys.join(", ")}` : "") + "\n"
|
|
9595
|
-
);
|
|
9596
|
-
}
|
|
9597
|
-
return CLI_EXIT_CODES.ok;
|
|
9598
|
-
}
|
|
9599
|
-
|
|
9600
|
-
// src/cli/commandModel.ts
|
|
9601
|
-
var CLI_COLOR_MODES = ["auto", "always", "never"];
|
|
9602
|
-
var CLI_COMPLETION_SHELLS = ["bash", "zsh", "fish"];
|
|
9603
|
-
var CLI_TOP_LEVEL_COMMANDS = ["utility", "run", "capsule", "list", "completion"];
|
|
9604
|
-
function isCliColorMode(value) {
|
|
9605
|
-
return CLI_COLOR_MODES.includes(value);
|
|
9606
|
-
}
|
|
9607
|
-
function isCliCompletionShell(value) {
|
|
9608
|
-
return CLI_COMPLETION_SHELLS.includes(value);
|
|
9609
|
-
}
|
|
9610
|
-
|
|
9611
|
-
// src/cli/completion.ts
|
|
9612
|
-
var commandWords = CLI_TOP_LEVEL_COMMANDS.join(" ");
|
|
9613
|
-
var colorWords = CLI_COLOR_MODES.join(" ");
|
|
9614
|
-
var shellWords = CLI_COMPLETION_SHELLS.join(" ");
|
|
9615
|
-
var utilityWords = [...UTILITY_ADAPTER_IDS].sort().join(" ");
|
|
9616
|
-
function renderCompletion(shell) {
|
|
9617
|
-
switch (shell) {
|
|
9618
|
-
case "bash":
|
|
9619
|
-
return renderBashCompletion();
|
|
9620
|
-
case "zsh":
|
|
9621
|
-
return renderZshCompletion();
|
|
9622
|
-
case "fish":
|
|
9623
|
-
return renderFishCompletion();
|
|
9624
|
-
}
|
|
9625
|
-
}
|
|
9626
|
-
function renderBashCompletion() {
|
|
9627
|
-
return `# lingua bash completion
|
|
9628
|
-
_lingua() {
|
|
9629
|
-
local cur prev command command_index index relative word
|
|
9630
|
-
COMPREPLY=()
|
|
9631
|
-
cur="\${COMP_WORDS[COMP_CWORD]}"
|
|
9632
|
-
prev=""
|
|
9633
|
-
if (( COMP_CWORD > 0 )); then
|
|
9634
|
-
prev="\${COMP_WORDS[COMP_CWORD-1]}"
|
|
9635
|
-
fi
|
|
9636
|
-
command=""
|
|
9637
|
-
command_index=0
|
|
9638
|
-
for (( index=1; index<COMP_CWORD; index++ )); do
|
|
9639
|
-
word="\${COMP_WORDS[index]}"
|
|
9640
|
-
case "$word" in
|
|
9641
|
-
--color)
|
|
9642
|
-
(( index++ ))
|
|
9643
|
-
;;
|
|
9644
|
-
--color=*)
|
|
9645
|
-
;;
|
|
9646
|
-
utility|run|capsule|list|completion)
|
|
9647
|
-
command="$word"
|
|
9648
|
-
command_index=$index
|
|
9649
|
-
break
|
|
9650
|
-
;;
|
|
9651
|
-
esac
|
|
9652
|
-
done
|
|
9653
|
-
|
|
9654
|
-
case "$cur" in
|
|
9655
|
-
--color=*)
|
|
9656
|
-
local value="\${cur#--color=}"
|
|
9657
|
-
COMPREPLY=( $(compgen -W "${colorWords}" -- "$value") )
|
|
9658
|
-
COMPREPLY=( "\${COMPREPLY[@]/#/--color=}" )
|
|
9659
|
-
return
|
|
9660
|
-
;;
|
|
9661
|
-
esac
|
|
9662
|
-
|
|
9663
|
-
case "$prev" in
|
|
9664
|
-
--color)
|
|
9665
|
-
COMPREPLY=( $(compgen -W "${colorWords}" -- "$cur") )
|
|
9666
|
-
return
|
|
9667
|
-
;;
|
|
9668
|
-
--input|--stdin)
|
|
9669
|
-
compopt -o filenames 2>/dev/null || true
|
|
9670
|
-
COMPREPLY=( $(compgen -f -- "$cur") )
|
|
9671
|
-
return
|
|
9672
|
-
;;
|
|
9673
|
-
--timeout)
|
|
9674
|
-
return
|
|
9675
|
-
;;
|
|
9676
|
-
--env|--option)
|
|
9677
|
-
return
|
|
9678
|
-
;;
|
|
9679
|
-
esac
|
|
9680
|
-
|
|
9681
|
-
if [[ -z "$command" ]]; then
|
|
9682
|
-
COMPREPLY=( $(compgen -W "${commandWords} --help --version --color" -- "$cur") )
|
|
9683
|
-
return
|
|
9684
|
-
fi
|
|
9685
|
-
|
|
9686
|
-
case "$command" in
|
|
9687
|
-
utility)
|
|
9688
|
-
relative=$(( COMP_CWORD - command_index ))
|
|
9689
|
-
if (( relative == 1 )); then
|
|
9690
|
-
COMPREPLY=( $(compgen -W "${utilityWords}" -- "$cur") )
|
|
9691
|
-
elif [[ "$cur" == -* ]]; then
|
|
9692
|
-
COMPREPLY=( $(compgen -W "--input --option --json --quiet --color --help" -- "$cur") )
|
|
9693
|
-
fi
|
|
9694
|
-
;;
|
|
9695
|
-
run)
|
|
9696
|
-
if [[ "$cur" == -* ]]; then
|
|
9697
|
-
COMPREPLY=( $(compgen -W "--stdin --timeout --env --json --quiet --color --help --" -- "$cur") )
|
|
9698
|
-
else
|
|
9699
|
-
compopt -o filenames 2>/dev/null || true
|
|
9700
|
-
COMPREPLY=( $(compgen -f -- "$cur") )
|
|
9701
|
-
fi
|
|
9702
|
-
;;
|
|
9703
|
-
capsule)
|
|
9704
|
-
relative=$(( COMP_CWORD - command_index ))
|
|
9705
|
-
if (( relative == 1 )); then
|
|
9706
|
-
COMPREPLY=( $(compgen -W "validate replay" -- "$cur") )
|
|
9707
|
-
elif [[ "$cur" == -* ]]; then
|
|
9708
|
-
COMPREPLY=( $(compgen -W "--timeout --env --json --quiet --color --help" -- "$cur") )
|
|
9709
|
-
else
|
|
9710
|
-
compopt -o filenames 2>/dev/null || true
|
|
9711
|
-
COMPREPLY=( $(compgen -f -- "$cur") )
|
|
9712
|
-
fi
|
|
9713
|
-
;;
|
|
9714
|
-
list)
|
|
9715
|
-
relative=$(( COMP_CWORD - command_index ))
|
|
9716
|
-
if (( relative == 1 )); then
|
|
9717
|
-
COMPREPLY=( $(compgen -W "utilities" -- "$cur") )
|
|
9718
|
-
else
|
|
9719
|
-
COMPREPLY=( $(compgen -W "--json --quiet --color --help" -- "$cur") )
|
|
9720
|
-
fi
|
|
9721
|
-
;;
|
|
9722
|
-
completion)
|
|
9723
|
-
relative=$(( COMP_CWORD - command_index ))
|
|
9724
|
-
if (( relative == 1 )); then
|
|
9725
|
-
COMPREPLY=( $(compgen -W "${shellWords}" -- "$cur") )
|
|
9726
|
-
else
|
|
9727
|
-
COMPREPLY=( $(compgen -W "--color --help" -- "$cur") )
|
|
9728
|
-
fi
|
|
9729
|
-
;;
|
|
9730
|
-
esac
|
|
9731
|
-
}
|
|
9732
|
-
complete -F _lingua lingua
|
|
9733
|
-
`;
|
|
10161
|
+
};
|
|
10162
|
+
const allowedKeys = new Set(adapter.optionsSchema.map((field) => field.key));
|
|
10163
|
+
for (const { key, value } of cliOptions) {
|
|
10164
|
+
if (!allowedKeys.has(key)) {
|
|
10165
|
+
throw new Error(
|
|
10166
|
+
`Adapter "${adapter.id}" has no option "${key}". Allowed: ${[...allowedKeys].sort().join(", ") || "(none)"}`
|
|
10167
|
+
);
|
|
10168
|
+
}
|
|
10169
|
+
blob[key] = coerceOptionValue(adapter, key, value);
|
|
10170
|
+
}
|
|
10171
|
+
return blob;
|
|
9734
10172
|
}
|
|
9735
|
-
function
|
|
9736
|
-
|
|
9737
|
-
|
|
9738
|
-
|
|
9739
|
-
|
|
9740
|
-
|
|
9741
|
-
|
|
9742
|
-
|
|
9743
|
-
|
|
9744
|
-
|
|
9745
|
-
|
|
9746
|
-
|
|
9747
|
-
|
|
9748
|
-
|
|
9749
|
-
)
|
|
9750
|
-
utilities=(${utilityWords})
|
|
9751
|
-
color_modes=(${colorWords})
|
|
9752
|
-
shells=(${shellWords})
|
|
9753
|
-
|
|
9754
|
-
_arguments -C \\
|
|
9755
|
-
'(-h --help)'{-h,--help}'[Show help]' \\
|
|
9756
|
-
'(-v --version)'{-v,--version}'[Print the CLI version]' \\
|
|
9757
|
-
'--color=[Control diagnostic color]:mode:(auto always never)' \\
|
|
9758
|
-
'1:command:->command' \\
|
|
9759
|
-
'*::argument:->arguments'
|
|
9760
|
-
|
|
9761
|
-
case "$state" in
|
|
9762
|
-
command)
|
|
9763
|
-
_describe -t commands 'lingua command' commands
|
|
9764
|
-
;;
|
|
9765
|
-
arguments)
|
|
9766
|
-
command_index=0
|
|
9767
|
-
for (( index=2; index<CURRENT; index++ )); do
|
|
9768
|
-
case "\${words[index]}" in
|
|
9769
|
-
--color)
|
|
9770
|
-
(( index++ ))
|
|
9771
|
-
;;
|
|
9772
|
-
--color=*)
|
|
9773
|
-
;;
|
|
9774
|
-
utility|run|capsule|list|completion)
|
|
9775
|
-
command_index=$index
|
|
9776
|
-
break
|
|
9777
|
-
;;
|
|
9778
|
-
esac
|
|
9779
|
-
done
|
|
9780
|
-
if (( command_index == 0 )); then
|
|
9781
|
-
return 0
|
|
9782
|
-
fi
|
|
9783
|
-
words=("\${(@)words[$command_index,-1]}")
|
|
9784
|
-
(( CURRENT -= command_index - 1 ))
|
|
9785
|
-
case "\${words[1]}" in
|
|
9786
|
-
utility)
|
|
9787
|
-
if (( CURRENT == 2 )); then
|
|
9788
|
-
_describe -t utilities 'utility' utilities
|
|
9789
|
-
else
|
|
9790
|
-
_arguments \\
|
|
9791
|
-
'--input=[Read input from a file]:file:_files' \\
|
|
9792
|
-
'*--option=[Pass an adapter key=value option]:option:' \\
|
|
9793
|
-
'--json[Emit structured JSON]' \\
|
|
9794
|
-
'--quiet[Suppress Lingua diagnostics]' \\
|
|
9795
|
-
'--color=[Control diagnostic color]:mode:(auto always never)' \\
|
|
9796
|
-
'(-h --help)'{-h,--help}'[Show help]'
|
|
9797
|
-
fi
|
|
9798
|
-
;;
|
|
9799
|
-
run)
|
|
9800
|
-
_arguments \\
|
|
9801
|
-
'1:source file or project:_files' \\
|
|
9802
|
-
'--stdin=[Forward a file as program stdin]:file:_files' \\
|
|
9803
|
-
'--timeout=[Set wall-clock timeout in milliseconds]:milliseconds:' \\
|
|
9804
|
-
'*--env=[Add an explicit NAME=value environment entry]:environment:' \\
|
|
9805
|
-
'--json[Emit structured JSON]' \\
|
|
9806
|
-
'--quiet[Suppress Lingua diagnostics]' \\
|
|
9807
|
-
'--color=[Control diagnostic color]:mode:(auto always never)' \\
|
|
9808
|
-
'(-h --help)'{-h,--help}'[Show help]' \\
|
|
9809
|
-
'*::program argument:'
|
|
9810
|
-
;;
|
|
9811
|
-
capsule)
|
|
9812
|
-
if (( CURRENT == 2 )); then
|
|
9813
|
-
_values 'capsule action' validate replay
|
|
9814
|
-
else
|
|
9815
|
-
_arguments \\
|
|
9816
|
-
'2:capsule file:_files' \\
|
|
9817
|
-
'--timeout=[Set replay timeout in milliseconds]:milliseconds:' \\
|
|
9818
|
-
'*--env=[Add an explicit NAME=value environment entry]:environment:' \\
|
|
9819
|
-
'--json[Emit structured JSON]' \\
|
|
9820
|
-
'--quiet[Suppress Lingua diagnostics]' \\
|
|
9821
|
-
'--color=[Control diagnostic color]:mode:(auto always never)' \\
|
|
9822
|
-
'(-h --help)'{-h,--help}'[Show help]'
|
|
9823
|
-
fi
|
|
9824
|
-
;;
|
|
9825
|
-
list)
|
|
9826
|
-
_values 'list target' utilities
|
|
9827
|
-
;;
|
|
9828
|
-
completion)
|
|
9829
|
-
_describe -t shells 'shell' shells
|
|
9830
|
-
;;
|
|
9831
|
-
esac
|
|
9832
|
-
;;
|
|
9833
|
-
esac
|
|
10173
|
+
function coerceOptionValue(adapter, key, raw) {
|
|
10174
|
+
const field = adapter.optionsSchema.find((entry) => entry.key === key);
|
|
10175
|
+
if (!field) return raw;
|
|
10176
|
+
switch (field.type) {
|
|
10177
|
+
case "text":
|
|
10178
|
+
case "textarea":
|
|
10179
|
+
case "select":
|
|
10180
|
+
return raw;
|
|
10181
|
+
case "boolean": {
|
|
10182
|
+
if (raw === "true" || raw === "1" || raw === "yes") return true;
|
|
10183
|
+
if (raw === "false" || raw === "0" || raw === "no") return false;
|
|
10184
|
+
throw new Error(`Option "${key}" expects a boolean (true|false|1|0|yes|no); got "${raw}"`);
|
|
10185
|
+
}
|
|
10186
|
+
}
|
|
9834
10187
|
}
|
|
9835
|
-
|
|
9836
|
-
|
|
9837
|
-
fi
|
|
9838
|
-
`;
|
|
10188
|
+
function emitError(io, args, reason, detail) {
|
|
10189
|
+
emitCliFailure(io, args, { label: "lingua utility", reason, detail });
|
|
9839
10190
|
}
|
|
9840
|
-
function
|
|
9841
|
-
const
|
|
9842
|
-
|
|
9843
|
-
|
|
9844
|
-
|
|
9845
|
-
|
|
9846
|
-
|
|
9847
|
-
|
|
9848
|
-
|
|
9849
|
-
|
|
9850
|
-
|
|
9851
|
-
|
|
9852
|
-
|
|
9853
|
-
|
|
9854
|
-
|
|
9855
|
-
|
|
9856
|
-
|
|
9857
|
-
|
|
9858
|
-
|
|
9859
|
-
|
|
9860
|
-
|
|
9861
|
-
continue
|
|
9862
|
-
case utility run capsule list completion
|
|
9863
|
-
echo $index
|
|
9864
|
-
return 0
|
|
9865
|
-
end
|
|
9866
|
-
end
|
|
9867
|
-
return 1
|
|
9868
|
-
end
|
|
9869
|
-
|
|
9870
|
-
function __fish_lingua_using_command
|
|
9871
|
-
set -l tokens (commandline -opc)
|
|
9872
|
-
set -l command_index (__fish_lingua_command_index)
|
|
9873
|
-
test -n "$command_index"; and test "$tokens[$command_index]" = "$argv[1]"
|
|
9874
|
-
end
|
|
9875
|
-
|
|
9876
|
-
function __fish_lingua_needs_first_argument
|
|
9877
|
-
set -l tokens (commandline -opc)
|
|
9878
|
-
set -l command_index (__fish_lingua_command_index)
|
|
9879
|
-
if test -z "$command_index"; or test "$tokens[$command_index]" != "$argv[1]"
|
|
9880
|
-
return 1
|
|
9881
|
-
end
|
|
9882
|
-
set -l skip_next 0
|
|
9883
|
-
for index in (seq (math $command_index + 1) (count $tokens))
|
|
9884
|
-
set -l token $tokens[$index]
|
|
9885
|
-
if test $skip_next -eq 1
|
|
9886
|
-
set skip_next 0
|
|
9887
|
-
continue
|
|
9888
|
-
end
|
|
9889
|
-
switch $token
|
|
9890
|
-
case --color --input --option --stdin --timeout --env
|
|
9891
|
-
set skip_next 1
|
|
9892
|
-
case '--color=*' '--input=*' '--option=*' '--stdin=*' '--timeout=*' '--env=*' --json --quiet --help -h
|
|
9893
|
-
continue
|
|
9894
|
-
case '*'
|
|
9895
|
-
return 1
|
|
9896
|
-
end
|
|
9897
|
-
end
|
|
9898
|
-
return 0
|
|
9899
|
-
end
|
|
9900
|
-
|
|
9901
|
-
complete -c lingua -f -n __fish_lingua_needs_command -a 'utility' -d 'Run a shared utility adapter'
|
|
9902
|
-
complete -c lingua -f -n __fish_lingua_needs_command -a 'run' -d 'Execute a source file or project root'
|
|
9903
|
-
complete -c lingua -f -n __fish_lingua_needs_command -a 'capsule' -d 'Validate or replay a Run Capsule'
|
|
9904
|
-
complete -c lingua -f -n __fish_lingua_needs_command -a 'list' -d 'List available capabilities'
|
|
9905
|
-
complete -c lingua -f -n __fish_lingua_needs_command -a 'completion' -d 'Generate a shell completion script'
|
|
9906
|
-
|
|
9907
|
-
complete -c lingua -l help -s h -d 'Show help'
|
|
9908
|
-
complete -c lingua -l version -s v -d 'Print the CLI version'
|
|
9909
|
-
complete -c lingua -l color -r -f -a '${colorWords}' -d 'Control diagnostic color'
|
|
9910
|
-
complete -c lingua -l json -d 'Emit structured JSON'
|
|
9911
|
-
complete -c lingua -l quiet -d 'Suppress Lingua diagnostics'
|
|
9912
|
-
|
|
9913
|
-
${utilityLines}
|
|
9914
|
-
complete -c lingua -n '__fish_lingua_using_command utility' -l input -r -F -d 'Read input from a file'
|
|
9915
|
-
complete -c lingua -n '__fish_lingua_using_command utility' -l option -r -d 'Pass an adapter key=value option'
|
|
9916
|
-
|
|
9917
|
-
complete -c lingua -n '__fish_lingua_using_command run' -l stdin -r -F -d 'Forward a file as program stdin'
|
|
9918
|
-
complete -c lingua -n '__fish_lingua_using_command run' -l timeout -r -d 'Set wall-clock timeout in milliseconds'
|
|
9919
|
-
complete -c lingua -n '__fish_lingua_using_command run' -l env -r -d 'Add an explicit NAME=value environment entry'
|
|
9920
|
-
|
|
9921
|
-
complete -c lingua -n '__fish_lingua_needs_first_argument capsule' -a 'validate replay'
|
|
9922
|
-
complete -c lingua -n '__fish_lingua_using_command capsule' -l timeout -r -d 'Set replay timeout in milliseconds'
|
|
9923
|
-
complete -c lingua -n '__fish_lingua_using_command capsule' -l env -r -d 'Add an explicit NAME=value environment entry'
|
|
9924
|
-
|
|
9925
|
-
complete -c lingua -n '__fish_lingua_needs_first_argument list' -a 'utilities'
|
|
9926
|
-
complete -c lingua -n '__fish_lingua_needs_first_argument completion' -a '${shellWords}'
|
|
9927
|
-
`;
|
|
10191
|
+
function runListUtilitiesCommand(args, io) {
|
|
10192
|
+
const entries = listAdapters().map((adapter) => ({
|
|
10193
|
+
id: adapter.id,
|
|
10194
|
+
inputKind: adapter.inputKind,
|
|
10195
|
+
outputKind: adapter.outputKind,
|
|
10196
|
+
titleKey: adapter.titleKey,
|
|
10197
|
+
descriptionKey: adapter.descriptionKey,
|
|
10198
|
+
optionKeys: adapter.optionsSchema.map((field) => field.key)
|
|
10199
|
+
}));
|
|
10200
|
+
if (args.json) {
|
|
10201
|
+
io.writeStdout(`${JSON.stringify({ utilities: entries }, null, 2)}
|
|
10202
|
+
`);
|
|
10203
|
+
return CLI_EXIT_CODES.ok;
|
|
10204
|
+
}
|
|
10205
|
+
if (args.quiet) return CLI_EXIT_CODES.ok;
|
|
10206
|
+
for (const entry of entries) {
|
|
10207
|
+
io.writeStdout(
|
|
10208
|
+
`${entry.id} ${entry.inputKind} \u2192 ${entry.outputKind}` + (entry.optionKeys.length > 0 ? ` options: ${entry.optionKeys.join(", ")}` : "") + "\n"
|
|
10209
|
+
);
|
|
10210
|
+
}
|
|
10211
|
+
return CLI_EXIT_CODES.ok;
|
|
9928
10212
|
}
|
|
9929
10213
|
|
|
9930
10214
|
// src/cli/helpCatalog.ts
|
|
@@ -10015,14 +10299,18 @@ var CLI_HELP_CATALOG = {
|
|
|
10015
10299
|
{
|
|
10016
10300
|
id: "completion",
|
|
10017
10301
|
topLevel: "completion",
|
|
10018
|
-
invocation: "lingua completion bash|zsh|fish",
|
|
10019
|
-
summary: "
|
|
10020
|
-
description: "
|
|
10021
|
-
flags: ["color", "help"],
|
|
10302
|
+
invocation: "lingua completion [bash|zsh|fish|install] [--yes] [--dry-run]",
|
|
10303
|
+
summary: "Install completions interactively or print one shell script.",
|
|
10304
|
+
description: "With no target or with install, detects Bash, Zsh, and Fish, shows the target files, and asks before writing. A shell target prints deterministic network-free source.",
|
|
10305
|
+
flags: ["yes", "dry-run", "color", "help"],
|
|
10022
10306
|
examples: [
|
|
10023
10307
|
{
|
|
10024
|
-
command: "lingua completion
|
|
10025
|
-
description: "
|
|
10308
|
+
command: "lingua completion",
|
|
10309
|
+
description: "Detect supported shells and offer to install their completions."
|
|
10310
|
+
},
|
|
10311
|
+
{
|
|
10312
|
+
command: "lingua completion install --yes",
|
|
10313
|
+
description: "Install every detected completion without prompting."
|
|
10026
10314
|
}
|
|
10027
10315
|
]
|
|
10028
10316
|
}
|
|
@@ -10035,6 +10323,8 @@ var CLI_HELP_CATALOG = {
|
|
|
10035
10323
|
{ id: "option", syntax: "--option key=value", summary: "Repeat to pass an adapter option.", commands: ["utility"] },
|
|
10036
10324
|
{ id: "json", syntax: "--json", summary: "Emit a stable structured JSON body instead of plain text.", commands: ["utility", "capsule-validate", "capsule-replay", "run", "list-utilities"] },
|
|
10037
10325
|
{ id: "quiet", syntax: "--quiet", summary: "Suppress Lingua diagnostics while preserving command output.", commands: ["utility", "capsule-validate", "capsule-replay", "run", "list-utilities"] },
|
|
10326
|
+
{ id: "yes", syntax: "--yes", summary: "Approve detected shell-completion changes without prompting.", commands: ["completion"] },
|
|
10327
|
+
{ id: "dry-run", syntax: "--dry-run", summary: "Show detected shells and target files without writing.", commands: ["completion"] },
|
|
10038
10328
|
{ id: "color", syntax: "--color <auto|always|never>", summary: "Control diagnostic color. The default is auto.", commands: ["utility", "capsule-validate", "capsule-replay", "run", "list-utilities", "completion"] },
|
|
10039
10329
|
{ id: "separator", syntax: "--", summary: "Forward every remaining token to the executed program unchanged.", commands: ["run"] },
|
|
10040
10330
|
{ id: "help", syntax: "--help, -h", summary: "Show help.", commands: ["utility", "capsule-validate", "capsule-replay", "run", "list-utilities", "completion"] },
|
|
@@ -10079,7 +10369,8 @@ ${examples}
|
|
|
10079
10369
|
}
|
|
10080
10370
|
|
|
10081
10371
|
// src/cli/io.ts
|
|
10082
|
-
var
|
|
10372
|
+
var import_promises4 = require("node:fs/promises");
|
|
10373
|
+
var import_promises5 = require("node:readline/promises");
|
|
10083
10374
|
function createDefaultIo() {
|
|
10084
10375
|
return {
|
|
10085
10376
|
stdoutSupportsColor: process.stdout.isTTY === true && (typeof process.stdout.hasColors !== "function" || process.stdout.hasColors()),
|
|
@@ -10087,14 +10378,28 @@ function createDefaultIo() {
|
|
|
10087
10378
|
getEnvironmentValue(name) {
|
|
10088
10379
|
return process.env[name];
|
|
10089
10380
|
},
|
|
10381
|
+
async confirm(message, defaultAnswer) {
|
|
10382
|
+
if (process.stdin.isTTY !== true || process.stdout.isTTY !== true) {
|
|
10383
|
+
return null;
|
|
10384
|
+
}
|
|
10385
|
+
const choices = defaultAnswer ? "Y/n" : "y/N";
|
|
10386
|
+
const readline = (0, import_promises5.createInterface)({ input: process.stdin, output: process.stdout });
|
|
10387
|
+
try {
|
|
10388
|
+
const answer = (await readline.question(`${message} [${choices}] `)).trim().toLowerCase();
|
|
10389
|
+
if (answer.length === 0) return defaultAnswer;
|
|
10390
|
+
return answer === "y" || answer === "yes";
|
|
10391
|
+
} finally {
|
|
10392
|
+
readline.close();
|
|
10393
|
+
}
|
|
10394
|
+
},
|
|
10090
10395
|
writeStdout(text) {
|
|
10091
10396
|
process.stdout.write(text);
|
|
10092
10397
|
},
|
|
10093
10398
|
writeStderr(text) {
|
|
10094
10399
|
process.stderr.write(text);
|
|
10095
10400
|
},
|
|
10096
|
-
async readFile(
|
|
10097
|
-
return (0,
|
|
10401
|
+
async readFile(path4) {
|
|
10402
|
+
return (0, import_promises4.readFile)(path4, "utf8");
|
|
10098
10403
|
},
|
|
10099
10404
|
async readStdin() {
|
|
10100
10405
|
if (process.stdin.isTTY) {
|
|
@@ -10163,7 +10468,9 @@ function freshFlags(color = "auto") {
|
|
|
10163
10468
|
options: [],
|
|
10164
10469
|
env: [],
|
|
10165
10470
|
programArgs: [],
|
|
10166
|
-
help: false
|
|
10471
|
+
help: false,
|
|
10472
|
+
yes: false,
|
|
10473
|
+
dryRun: false
|
|
10167
10474
|
};
|
|
10168
10475
|
}
|
|
10169
10476
|
function finalize(command, positionals, flags) {
|
|
@@ -10180,7 +10487,9 @@ function finalize(command, positionals, flags) {
|
|
|
10180
10487
|
options: flags.options,
|
|
10181
10488
|
env: flags.env,
|
|
10182
10489
|
programArgs: flags.programArgs,
|
|
10183
|
-
help: flags.help
|
|
10490
|
+
help: flags.help,
|
|
10491
|
+
yes: flags.yes,
|
|
10492
|
+
dryRun: flags.dryRun
|
|
10184
10493
|
}
|
|
10185
10494
|
};
|
|
10186
10495
|
}
|
|
@@ -10420,30 +10729,37 @@ function parseCompletion(rest, color) {
|
|
|
10420
10729
|
flags.help = true;
|
|
10421
10730
|
continue;
|
|
10422
10731
|
}
|
|
10732
|
+
if (arg === "--yes") {
|
|
10733
|
+
flags.yes = true;
|
|
10734
|
+
continue;
|
|
10735
|
+
}
|
|
10736
|
+
if (arg === "--dry-run") {
|
|
10737
|
+
flags.dryRun = true;
|
|
10738
|
+
continue;
|
|
10739
|
+
}
|
|
10423
10740
|
if (arg.startsWith("-")) {
|
|
10424
10741
|
throw new CliUsageError(
|
|
10425
|
-
`Unknown flag "${arg}" for "lingua completion". Allowed: --color, --help`
|
|
10742
|
+
`Unknown flag "${arg}" for "lingua completion". Allowed: --yes, --dry-run, --color, --help`
|
|
10426
10743
|
);
|
|
10427
10744
|
}
|
|
10428
10745
|
positionals.push(arg);
|
|
10429
10746
|
}
|
|
10430
|
-
if (!flags.help && positionals.length === 0) {
|
|
10431
|
-
throw new CliUsageError(
|
|
10432
|
-
`lingua completion requires a <shell> positional. Available: ${CLI_COMPLETION_SHELLS.join(", ")}`
|
|
10433
|
-
);
|
|
10434
|
-
}
|
|
10435
10747
|
if (positionals.length > 1) {
|
|
10436
10748
|
throw new CliUsageError(
|
|
10437
10749
|
`lingua completion accepts one <shell>; got ${positionals.length}: ${positionals.join(", ")}`
|
|
10438
10750
|
);
|
|
10439
10751
|
}
|
|
10440
10752
|
const shell = positionals[0];
|
|
10441
|
-
if (!flags.help && shell !== void 0 && !isCliCompletionShell(shell)) {
|
|
10753
|
+
if (!flags.help && shell !== void 0 && shell !== "install" && !isCliCompletionShell(shell)) {
|
|
10442
10754
|
throw new CliUsageError(
|
|
10443
|
-
`Unknown completion
|
|
10755
|
+
`Unknown completion target "${shell}". Available: install, ${CLI_COMPLETION_SHELLS.join(", ")}`
|
|
10444
10756
|
);
|
|
10445
10757
|
}
|
|
10446
|
-
|
|
10758
|
+
const installing = shell === void 0 || shell === "install";
|
|
10759
|
+
if (!installing && (flags.yes || flags.dryRun)) {
|
|
10760
|
+
throw new CliUsageError("--yes and --dry-run are only valid for completion installation");
|
|
10761
|
+
}
|
|
10762
|
+
return finalize(installing ? "completion-install" : "completion", positionals, flags);
|
|
10447
10763
|
}
|
|
10448
10764
|
function extractColorFlag(argv) {
|
|
10449
10765
|
const separator = argv.indexOf("--");
|
|
@@ -10554,8 +10870,8 @@ function assertSingleTarget(command, positionals, help, label) {
|
|
|
10554
10870
|
|
|
10555
10871
|
// src/cli/lingua.ts
|
|
10556
10872
|
function resolveCliVersion() {
|
|
10557
|
-
if ("1.
|
|
10558
|
-
return "1.
|
|
10873
|
+
if ("1.3.0".length > 0) {
|
|
10874
|
+
return "1.3.0";
|
|
10559
10875
|
}
|
|
10560
10876
|
return "0.0.0-dev";
|
|
10561
10877
|
}
|
|
@@ -10610,6 +10926,12 @@ async function dispatch(argv, io) {
|
|
|
10610
10926
|
io.writeStdout(renderCompletion(shell));
|
|
10611
10927
|
return CLI_EXIT_CODES.ok;
|
|
10612
10928
|
}
|
|
10929
|
+
if (parsed.command === "completion-install") {
|
|
10930
|
+
return runCompletionInstallCommand(
|
|
10931
|
+
{ assumeYes: parsed.flags.yes, dryRun: parsed.flags.dryRun },
|
|
10932
|
+
io
|
|
10933
|
+
);
|
|
10934
|
+
}
|
|
10613
10935
|
if (parsed.command === "utility") {
|
|
10614
10936
|
const utilityId = parsed.positionals[0];
|
|
10615
10937
|
if (utilityId === void 0) {
|