@bonginkan/maria 4.3.34 → 4.3.36

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/cli.cjs CHANGED
@@ -19,12 +19,12 @@ var fs6 = require('fs-extra');
19
19
  var util = require('util');
20
20
  var promises = require('timers/promises');
21
21
  var dns = require('dns/promises');
22
+ var https = require('https');
22
23
  var zod = require('zod');
23
24
  var process6 = require('process');
24
25
  var readline = require('readline');
25
26
  var buffer = require('buffer');
26
27
  var net = require('net');
27
- var https = require('https');
28
28
  var zlib = require('zlib');
29
29
  var yaml = require('js-yaml');
30
30
  var neo4j = require('neo4j-driver');
@@ -66,9 +66,9 @@ var fsp__namespace = /*#__PURE__*/_interopNamespace(fsp);
66
66
  var Stream2__default = /*#__PURE__*/_interopDefault(Stream2);
67
67
  var fs6__namespace = /*#__PURE__*/_interopNamespace(fs6);
68
68
  var dns__default = /*#__PURE__*/_interopDefault(dns);
69
+ var https__default = /*#__PURE__*/_interopDefault(https);
69
70
  var process6__namespace = /*#__PURE__*/_interopNamespace(process6);
70
71
  var readline__namespace = /*#__PURE__*/_interopNamespace(readline);
71
- var https__default = /*#__PURE__*/_interopDefault(https);
72
72
  var zlib__default = /*#__PURE__*/_interopDefault(zlib);
73
73
  var yaml__namespace = /*#__PURE__*/_interopNamespace(yaml);
74
74
  var neo4j__default = /*#__PURE__*/_interopDefault(neo4j);
@@ -1709,7 +1709,7 @@ var init_AuthenticationManager = __esm({
1709
1709
  const response = await fetch(`${this.apiBase}/api/user/profile`, {
1710
1710
  headers: {
1711
1711
  "Authorization": `Bearer ${tokens2.accessToken}`,
1712
- "User-Agent": `maria-cli/${process.env.CLI_VERSION || "4.3.34"}`
1712
+ "User-Agent": `maria-cli/${process.env.CLI_VERSION || "4.3.36"}`
1713
1713
  }
1714
1714
  });
1715
1715
  if (response.status === 401) {
@@ -2390,6 +2390,17 @@ var init_esm_node = __esm({
2390
2390
  init_v4();
2391
2391
  }
2392
2392
  });
2393
+
2394
+ // src/services/cli-auth/api-client.ts
2395
+ var api_client_exports = {};
2396
+ __export(api_client_exports, {
2397
+ ERR: () => ERR,
2398
+ callApi: () => callApi,
2399
+ callApiJson: () => callApiJson,
2400
+ clientThrottle: () => clientThrottle,
2401
+ streamApi: () => streamApi,
2402
+ uploadFile: () => uploadFile
2403
+ });
2393
2404
  function getDeviceId() {
2394
2405
  if (!global.MARIA_DEVICE_ID) {
2395
2406
  global.MARIA_DEVICE_ID = v4_default();
@@ -2399,6 +2410,17 @@ function getDeviceId() {
2399
2410
  function getSessionId() {
2400
2411
  return global.MARIA_SESSION_ID;
2401
2412
  }
2413
+ function clientThrottle(endpoint) {
2414
+ const now2 = Date.now();
2415
+ const lastCall = rateLimitMap.get(endpoint) || 0;
2416
+ const wait = MIN_GAP_MS - (now2 - lastCall);
2417
+ if (wait > 0) {
2418
+ const waitSeconds = Math.ceil(wait / 1e3);
2419
+ console.log(chalk40__default.default.yellow(`\u23F1\uFE0F Rate limit: wait ${waitSeconds}s`));
2420
+ throw { ...ERR.RATE, waitTime: waitSeconds };
2421
+ }
2422
+ rateLimitMap.set(endpoint, now2);
2423
+ }
2402
2424
  async function callApi(path64, init3 = {}) {
2403
2425
  const apiBase = process.env.MARIA_API_BASE || "https://api.maria-code.ai";
2404
2426
  const fullUrl = `${apiBase}${path64}`;
@@ -2412,7 +2434,7 @@ async function callApi(path64, init3 = {}) {
2412
2434
  "Authorization": `Bearer ${token}`,
2413
2435
  "X-Device-Id": getDeviceId(),
2414
2436
  "X-Session-Id": getSessionId() || "",
2415
- "User-Agent": `maria-cli/${process.env.CLI_VERSION || "4.3.34"}`,
2437
+ "User-Agent": `maria-cli/${process.env.CLI_VERSION || "4.3.36"}`,
2416
2438
  "Content-Type": init3.headers?.["Content-Type"] || "application/json"
2417
2439
  });
2418
2440
  const doFetch = async (token) => {
@@ -2480,7 +2502,48 @@ async function callApiJson(path64, init3 = {}) {
2480
2502
  }
2481
2503
  return response.json();
2482
2504
  }
2483
- var ERR;
2505
+ async function* streamApi(path64, init3 = {}) {
2506
+ const response = await callApi(path64, {
2507
+ ...init3,
2508
+ headers: {
2509
+ ...init3.headers,
2510
+ "Accept": "text/event-stream"
2511
+ }
2512
+ });
2513
+ if (!response.ok) {
2514
+ throw new Error(`Stream error: ${response.status}`);
2515
+ }
2516
+ const reader = response.body?.getReader();
2517
+ if (!reader) {
2518
+ throw new Error("No response body");
2519
+ }
2520
+ const decoder = new TextDecoder();
2521
+ try {
2522
+ while (true) {
2523
+ const { done, value } = await reader.read();
2524
+ if (done) break;
2525
+ const chunk = decoder.decode(value, { stream: true });
2526
+ yield chunk;
2527
+ }
2528
+ } finally {
2529
+ reader.releaseLock();
2530
+ }
2531
+ }
2532
+ async function uploadFile(path64, file, metadata5 = {}) {
2533
+ const formData = new FormData();
2534
+ formData.append("file", new Blob([file]));
2535
+ Object.entries(metadata5).forEach(([key, value]) => {
2536
+ formData.append(key, String(value));
2537
+ });
2538
+ return callApiJson(path64, {
2539
+ method: "POST",
2540
+ body: formData,
2541
+ headers: {
2542
+ // Don't set Content-Type, let browser set it with boundary
2543
+ }
2544
+ });
2545
+ }
2546
+ var ERR, rateLimitMap, MIN_GAP_MS;
2484
2547
  var init_api_client = __esm({
2485
2548
  "src/services/cli-auth/api-client.ts"() {
2486
2549
  init_AuthenticationManager();
@@ -2493,6 +2556,8 @@ var init_api_client = __esm({
2493
2556
  NETWORK: { msg: "\u{1F310} Network error, check connection", code: 1 },
2494
2557
  RATE: { msg: "\u23F3 Rate limited, retrying...", code: 1 }
2495
2558
  };
2559
+ rateLimitMap = /* @__PURE__ */ new Map();
2560
+ MIN_GAP_MS = 3e3;
2496
2561
  }
2497
2562
  });
2498
2563
 
@@ -11961,6 +12026,7 @@ var init_clear_command = __esm({
11961
12026
  init_telemetry_helper();
11962
12027
  init_subscription_manager();
11963
12028
  init_terminal();
12029
+ init_chat_context_service();
11964
12030
  ClearCommand = class extends BaseCommand {
11965
12031
  name = "clear";
11966
12032
  category = "conversation";
@@ -11977,34 +12043,46 @@ var init_clear_command = __esm({
11977
12043
  async execute(args2, context2) {
11978
12044
  const startTime = Date.now();
11979
12045
  try {
12046
+ let mode = "session";
12047
+ const idx = Array.isArray(args2.raw) ? args2.raw.indexOf("--mode") : -1;
12048
+ if (idx >= 0) {
12049
+ const val = String(args2.raw[idx + 1] || "").toLowerCase();
12050
+ if (val === "display" || val === "session" || val === "all") mode = val;
12051
+ }
11980
12052
  clearTerminal();
11981
- if (context2.session) {
11982
- if (context2.session.conversationHistory) {
11983
- context2.session.conversationHistory = [];
11984
- }
11985
- if (context2.session.context) {
11986
- context2.session.context = {};
11987
- }
11988
- if (context2.session.messages) {
11989
- context2.session.messages = [];
11990
- }
12053
+ const chat = ChatContextService.getInstance();
12054
+ if (mode === "display") {
12055
+ chat.clearContext({ soft: true });
12056
+ } else {
12057
+ chat.clearContext();
11991
12058
  }
12059
+ const quotaLeft = (() => {
12060
+ const rec = context2;
12061
+ const v = rec && typeof rec["quotaLeft"] === "number" ? rec["quotaLeft"] : 999;
12062
+ return v;
12063
+ })();
11992
12064
  await trackCommand({
11993
12065
  cmd: "clear",
11994
12066
  status: "success",
11995
12067
  latencyMs: Date.now() - startTime,
11996
- plan: getUserPlan(),
11997
- quotaLeft: context2.quotaLeft || 999
12068
+ plan: await getUserPlan(),
12069
+ quotaLeft
11998
12070
  });
11999
- const message = chalk40__default.default.green("\u2705 Cleared") + chalk40__default.default.gray(" \xB7 context reset");
12000
- return this.success(withQuotaFooter(message, context2.quotaLeft));
12071
+ const suffix = mode === "display" ? "display only" : "context reset";
12072
+ const message = chalk40__default.default.green("\u2705 Cleared") + chalk40__default.default.gray(` \xB7 ${suffix}`);
12073
+ return this.success(withQuotaFooter(message, quotaLeft));
12001
12074
  } catch (error2) {
12075
+ const quotaLeft = (() => {
12076
+ const rec = context2;
12077
+ const v = rec && typeof rec["quotaLeft"] === "number" ? rec["quotaLeft"] : 999;
12078
+ return v;
12079
+ })();
12002
12080
  await trackCommand({
12003
12081
  cmd: "clear",
12004
12082
  status: "error",
12005
12083
  latencyMs: Date.now() - startTime,
12006
- plan: getUserPlan(),
12007
- quotaLeft: context2.quotaLeft || 999
12084
+ plan: await getUserPlan(),
12085
+ quotaLeft
12008
12086
  });
12009
12087
  clearTerminal();
12010
12088
  return this.success(chalk40__default.default.green("\u2705 Cleared"));
@@ -12237,8 +12315,10 @@ var init_ReadyCommandsService = __esm({
12237
12315
  category,
12238
12316
  aliases: [],
12239
12317
  description: cmd.description || descriptions[commandName] || "No description available",
12240
- usage: `/${commandName} [options]`,
12241
- examples: [`/${commandName}`],
12318
+ usage: typeof cmd.usage === "string" ? cmd.usage : `/${commandName} [options]`,
12319
+ examples: Array.isArray(cmd.examples) ? cmd.examples : [`/${commandName}`],
12320
+ // flags is optional; keep it if present to power /help details
12321
+ ...cmd.flags && typeof cmd.flags === "object" ? { flags: cmd.flags } : {},
12242
12322
  status: "READY" /* READY */,
12243
12323
  contract: {
12244
12324
  tty: true,
@@ -12745,40 +12825,30 @@ var init_HelpCommand = __esm({
12745
12825
  examples = [
12746
12826
  {
12747
12827
  input: "/help",
12748
- _description: "Show READY commands with GPU labels",
12828
+ description: "Show READY commands with GPU labels",
12749
12829
  output: "Contract-validated commands with performance info"
12750
12830
  },
12751
12831
  {
12752
12832
  input: "/help code",
12753
- _description: "Show detailed help for specific command",
12833
+ description: "Show detailed help for specific command",
12754
12834
  output: "Usage, examples, and contract info for /code"
12755
12835
  },
12756
12836
  {
12757
12837
  input: "/help --category ai",
12758
- _description: "Show all READY commands in AI category",
12838
+ description: "Show all READY commands in AI category",
12759
12839
  output: "List of AI READY commands with GPU labels"
12760
12840
  },
12761
12841
  {
12762
12842
  input: '/help --search "config"',
12763
- _description: "Search READY commands for configuration",
12843
+ description: "Search READY commands for configuration",
12764
12844
  output: 'READY commands matching "config" with match scores'
12765
- },
12766
- {
12767
- input: "/help --stats",
12768
- _description: "Show READY command statistics",
12769
- output: "Performance stats and command counts"
12770
- },
12771
- {
12772
- input: "/help --quickstart",
12773
- _description: "Show essential commands for getting started",
12774
- output: "Most important READY commands for new users"
12775
12845
  }
12776
12846
  ];
12777
12847
  async execute(args2, context2) {
12778
12848
  const startTime = Date.now();
12779
12849
  try {
12780
12850
  const { parsed, options } = args2;
12781
- const _positional = parsed["_positional"] || [];
12851
+ const _positional = parsed["positional"] || parsed["_positional"] || [];
12782
12852
  if (options && options["stats"]) {
12783
12853
  const result2 = await this.showStatistics();
12784
12854
  await this.trackSuccess(startTime, context2);
@@ -12803,7 +12873,9 @@ var init_HelpCommand = __esm({
12803
12873
  return result2;
12804
12874
  }
12805
12875
  if (options && options["search"]) {
12806
- const result2 = await this.searchCommands(options["search"]);
12876
+ const proxy = (process.env.HELP_SEARCH_PROXY ?? "1").toLowerCase();
12877
+ const shouldProxy = proxy !== "0" && proxy !== "false";
12878
+ const result2 = shouldProxy ? await this.showGeneralHelp() : await this.searchCommands(options["search"]);
12807
12879
  await this.trackSuccess(startTime, context2);
12808
12880
  return result2;
12809
12881
  }
@@ -12815,7 +12887,7 @@ var init_HelpCommand = __esm({
12815
12887
  cmd: "help",
12816
12888
  status: "error",
12817
12889
  latencyMs: Date.now() - startTime,
12818
- plan: getUserPlan(),
12890
+ plan: await getUserPlan(),
12819
12891
  quotaLeft: context2.quotaLeft || 999
12820
12892
  });
12821
12893
  return this.error(
@@ -12833,7 +12905,7 @@ var init_HelpCommand = __esm({
12833
12905
  cmd: "help",
12834
12906
  status: "success",
12835
12907
  latencyMs: Date.now() - startTime,
12836
- plan: getUserPlan(),
12908
+ plan: await getUserPlan(),
12837
12909
  quotaLeft: context2.quotaLeft || 999
12838
12910
  });
12839
12911
  }
@@ -12863,9 +12935,6 @@ var init_HelpCommand = __esm({
12863
12935
  lines.push("");
12864
12936
  lines.push(chalk40__default.default.bold("Quick Access:"));
12865
12937
  lines.push(" /help <command> - Detailed help for specific command");
12866
- lines.push(" /help --quickstart - Essential commands for new users");
12867
- lines.push(" /help --stats - Performance statistics");
12868
- lines.push(" /help --search <term> - Search with fuzzy matching");
12869
12938
  lines.push("");
12870
12939
  let globalMaxNameLength = 0;
12871
12940
  for (const category of categories2) {
@@ -12936,44 +13005,6 @@ var init_HelpCommand = __esm({
12936
13005
  * Show help for specific command
12937
13006
  */
12938
13007
  async showCommandHelp(commandName) {
12939
- if (commandName.replace(/^\//, "") === "code") {
12940
- const lines2 = [];
12941
- lines2.push("Usage: /code <request> [flags]");
12942
- lines2.push("");
12943
- lines2.push("Flags:");
12944
- lines2.push(" --plan-only|--sow Show plan only (no writes)");
12945
- lines2.push(" --apply Apply plan (use with --yes for non-interactive)");
12946
- lines2.push(" --dry-run No writes; render output and hints");
12947
- lines2.push(" --interactive Approve interactively (a=all s=skip v=view d=diff q=cancel)");
12948
- lines2.push(" --yes Approve all (including overwrites)");
12949
- lines2.push(" --max-files N Clamp number of files");
12950
- lines2.push(" --root DIR Output root directory");
12951
- lines2.push(" --rollback on|off Rollback on failure (default on)");
12952
- lines2.push(" --output names|summary|detail");
12953
- lines2.push(" --no-code Hide code blocks entirely");
12954
- lines2.push(" --preview-lines N Show head of code in detail mode");
12955
- lines2.push(" --git-guard on|off Check clean git tree before apply (CI default on)");
12956
- lines2.push(" --git-commit on|off Create a single git commit after apply");
12957
- lines2.push(" --git-branch <name> Create/switch branch before committing");
12958
- lines2.push(" --git-tag <name> Create an annotated tag after committing");
12959
- lines2.push(" --git-tag-prefix <pfx> Use standardized tag when --git-tag auto: <pfx><YYYYMMDD>-<shortsha>");
12960
- lines2.push(" --git-push on|off Push commit and tag to remote");
12961
- lines2.push(" --git-push-remote <name> Remote name for push (default origin)");
12962
- lines2.push(" --allow-dotfiles Allow writing dotfiles (default deny)");
12963
- lines2.push(" --confirm-overwrites <globs>");
12964
- lines2.push("");
12965
- lines2.push("Tips:");
12966
- lines2.push(' HINT: Try /code --plan-only "your request" before applying changes');
12967
- lines2.push(" Recipes:");
12968
- lines2.push(' \u2022 Plan only: /code --plan-only "create auth form + API"');
12969
- lines2.push(' \u2022 Apply with limit: /code --apply --yes --max-files 5 "react + test"');
12970
- lines2.push(' \u2022 Interactive: /code --interactive --output detail --preview-lines 20 "routes + guards"');
12971
- lines2.push(" \u2022 Apply + branch + auto tag + push:");
12972
- lines2.push(" /code --apply --yes --git-guard on --git-commit on \\");
12973
- lines2.push(" --git-branch feature/code-plan --git-tag auto --git-tag-prefix code-plan- \\");
12974
- lines2.push(' --git-push on --git-push-remote origin "implement auth + tests"');
12975
- return this.success(lines2.join("\n"));
12976
- }
12977
13008
  const command = await this.readyService.getCommand(commandName);
12978
13009
  if (!command) {
12979
13010
  const searchResults = await this.readyService.searchCommands(commandName, 3);
@@ -12987,49 +13018,50 @@ var init_HelpCommand = __esm({
12987
13018
  }
12988
13019
  );
12989
13020
  }
12990
- const lines = this.formatCommandHelp(command);
13021
+ const lines = this.formatMinimalUsage(command);
12991
13022
  return this.success(lines);
12992
13023
  }
12993
13024
  /**
12994
13025
  * Format detailed help for a command
12995
13026
  */
12996
- formatCommandHelp(command) {
13027
+ formatMinimalUsage(command) {
12997
13028
  const lines = [];
13029
+ lines.push(`Usage: ${command.usage}`);
12998
13030
  lines.push("");
12999
- lines.push(`\u{1F4D6} ${chalk40__default.default.bold(`/${command.name}`)} - ${command.description}`);
13000
- lines.push("\u2550".repeat(50));
13001
- lines.push("");
13002
- lines.push(chalk40__default.default.bold("\u2139\uFE0F Information:"));
13003
- lines.push(` Category: ${this.readyService["getCategoryEmoji"](command.category)} ${command.category}`);
13004
- lines.push(` Status: \u2705 READY (contract validated)`);
13005
- if (command.aliases && command.aliases.length > 0) {
13006
- lines.push(` Aliases: ${command.aliases.map((a) => `/${a}`).join(", ")}`);
13031
+ const flags = command.flags;
13032
+ const effective = flags && Object.keys(flags).length > 0 ? flags : this.extractFlagsFromUsage(command.usage);
13033
+ if (effective && Object.keys(effective).length > 0) {
13034
+ lines.push("Flags:");
13035
+ const entries = Object.entries(effective).sort(([a], [b]) => a.localeCompare(b));
13036
+ for (const [k, v] of entries) {
13037
+ const hint = v ? ` ${v}` : "";
13038
+ lines.push(` --${k}${hint}`);
13039
+ }
13007
13040
  }
13008
- lines.push("");
13009
- lines.push(chalk40__default.default.bold("\u{1F3AF} Usage:"));
13010
- lines.push(` ${command.usage}`);
13011
- lines.push("");
13012
- lines.push(chalk40__default.default.bold("\u{1F4CB} Contract Validation:"));
13013
- lines.push(` \u26A1 Performance: ${command.contract.maxResponseTime}ms (tested)`);
13014
- lines.push(` \u{1F4BB} TTY Mode: ${command.contract.tty ? "\u2705 Supported" : "\u274C Not supported"}`);
13015
- lines.push(` \u{1F527} Non-TTY Mode: ${command.contract.nonTty ? "\u2705 Supported" : "\u274C Not supported"}`);
13016
- lines.push(` \u{1F500} Pipe Mode: ${command.contract.pipe ? "\u2705 Supported" : "\u274C Not supported"}`);
13017
- lines.push("");
13018
- if (command.examples && command.examples.length > 0) {
13019
- lines.push(chalk40__default.default.bold("\u{1F4DD} Examples:"));
13020
- for (const example of command.examples) {
13021
- lines.push(` ${example}`);
13041
+ return lines.join("\n");
13042
+ }
13043
+ extractFlagsFromUsage(usage) {
13044
+ if (!usage || typeof usage !== "string") return void 0;
13045
+ const out = {};
13046
+ const pattern = /--([a-zA-Z0-9][a-zA-Z0-9\-]*)\s*([^\]\s][^\]]*)?/g;
13047
+ const blocks = usage.match(/\[[^\]]+\]/g) || [];
13048
+ for (const b of blocks) {
13049
+ let m3;
13050
+ pattern.lastIndex = 0;
13051
+ while ((m3 = pattern.exec(b)) !== null) {
13052
+ const key = m3[1];
13053
+ const hint = (m3[2] || "").trim();
13054
+ out[key] = hint;
13022
13055
  }
13023
- lines.push("");
13024
13056
  }
13025
- lines.push(chalk40__default.default.bold("\u{1F4A1} Quick Tips:"));
13026
- lines.push(` \u2022 This command is production-ready and fully tested`);
13027
- lines.push(` \u2022 Try /${command.name} --help for additional options`);
13028
- if (command.category !== "core") {
13029
- lines.push(` \u2022 See more ${command.category} commands: /help --category ${command.category}`);
13057
+ let m2;
13058
+ pattern.lastIndex = 0;
13059
+ while ((m2 = pattern.exec(usage)) !== null) {
13060
+ const key = m2[1];
13061
+ const hint = (m2[2] || "").trim();
13062
+ if (!(key in out)) out[key] = hint;
13030
13063
  }
13031
- lines.push("");
13032
- return lines.join("\n");
13064
+ return Object.keys(out).length ? out : void 0;
13033
13065
  }
13034
13066
  /**
13035
13067
  * Show category help
@@ -13163,8 +13195,6 @@ var init_HelpCommand = __esm({
13163
13195
  }
13164
13196
  lines.push("");
13165
13197
  lines.push(chalk40__default.default.bold("\u{1F4A1} Next Steps:"));
13166
- lines.push(" \u2022 /help --category <name> - Explore command categories");
13167
- lines.push(" \u2022 /help --search <term> - Find specific functionality");
13168
13198
  lines.push(" \u2022 /help <command> - Get detailed command help");
13169
13199
  lines.push("");
13170
13200
  return this.success(lines.join("\n"));
@@ -13218,9 +13248,7 @@ var init_HelpCommand = __esm({
13218
13248
  "/help",
13219
13249
  "/help code",
13220
13250
  "/help --category ai",
13221
- "/help --search config",
13222
- "/help --quickstart",
13223
- "/help --stats"
13251
+ "/help --search config"
13224
13252
  ],
13225
13253
  deps: []
13226
13254
  };
@@ -16180,8 +16208,8 @@ var require_package = __commonJS({
16180
16208
  "package.json"(exports, module) {
16181
16209
  module.exports = {
16182
16210
  name: "@bonginkan/maria",
16183
- version: "4.3.34",
16184
- description: "\u{1F680} MARIA v4.3.34 - Enterprise AI Development Platform with identity system and character voice implementation. Features 74 production-ready commands with comprehensive fallback implementation, local LLM support, and zero external dependencies. Includes natural language coding, AI safety evaluation, intelligent evolution system, episodic memory with PII masking, and real-time monitoring dashboard. Built with TypeScript AST-powered code generation, OAuth2.0 + PKCE authentication, quantum-resistant cryptography, and enterprise-grade performance.",
16211
+ version: "4.3.36",
16212
+ description: "\u{1F680} MARIA v4.3.36 - Enterprise AI Development Platform with identity system and character voice implementation. Features 74 production-ready commands with comprehensive fallback implementation, local LLM support, and zero external dependencies. Includes natural language coding, AI safety evaluation, intelligent evolution system, episodic memory with PII masking, and real-time monitoring dashboard. Built with TypeScript AST-powered code generation, OAuth2.0 + PKCE authentication, quantum-resistant cryptography, and enterprise-grade performance.",
16185
16213
  keywords: [
16186
16214
  "ai",
16187
16215
  "cli",
@@ -22275,6 +22303,333 @@ var init_types4 = __esm({
22275
22303
  ];
22276
22304
  }
22277
22305
  });
22306
+
22307
+ // src/services/media-orchestrator/NLInference.ts
22308
+ function clampSize(size) {
22309
+ const clamp = (n) => Math.min(2048, Math.max(256, Math.floor(n)));
22310
+ return [clamp(size[0]), clamp(size[1])];
22311
+ }
22312
+ function parseExplicitSize(text) {
22313
+ const m2 = /(\d{2,4})\s*[x×]\s*(\d{2,4})/i.exec(text);
22314
+ if (m2) {
22315
+ const w = Number(m2[1]);
22316
+ const h2 = Number(m2[2]);
22317
+ if (Number.isFinite(w) && Number.isFinite(h2)) return clampSize([w, h2]);
22318
+ }
22319
+ const p = /(2160|1440|1080|720)\s*p\b/i.exec(text);
22320
+ if (p) {
22321
+ const h2 = Number(p[1]);
22322
+ const map = {
22323
+ 2160: [3840, 2160],
22324
+ 1440: [2560, 1440],
22325
+ 1080: [1920, 1080],
22326
+ 720: [1280, 720]
22327
+ };
22328
+ return clampSize(map[h2]);
22329
+ }
22330
+ return void 0;
22331
+ }
22332
+ function parseAspect(text) {
22333
+ if (/16\s*:\s*9/.test(text)) return "16:9";
22334
+ if (/9\s*:\s*16/.test(text)) return "9:16";
22335
+ if (/1\s*:\s*1/.test(text)) return "1:1";
22336
+ if (/(wide|landscape)/i.test(text)) return "16:9";
22337
+ if (/(tall|portrait)/i.test(text)) return "9:16";
22338
+ if (/(landscape|横長|横向き)/i.test(text)) return "16:9";
22339
+ if (/(portrait|縦長|縦向き)/i.test(text)) return "9:16";
22340
+ if (/(square|正方形|スクエア)/i.test(text)) return "1:1";
22341
+ return void 0;
22342
+ }
22343
+ function deriveSizeFromAspect(aspect, base) {
22344
+ const side = 1024;
22345
+ if (aspect === "1:1") return clampSize([side, side]);
22346
+ if (aspect === "16:9") {
22347
+ const w2 = Math.max(side, 1280);
22348
+ const h3 = Math.round(w2 / 16 * 9);
22349
+ return clampSize([w2, h3]);
22350
+ }
22351
+ const h2 = Math.max(side, 1920);
22352
+ const w = Math.round(h2 / 16 * 9);
22353
+ return clampSize([w, h2]);
22354
+ }
22355
+ function parse4KHints(text, aspect) {
22356
+ if (/(\b4k\b|uhd|超高精細|超高解像度)/i.test(text)) {
22357
+ if (aspect === "1:1" || /square|正方形|スクエア/i.test(text)) return clampSize([2048, 2048]);
22358
+ if (aspect === "9:16" || /(portrait|縦長|縦向き)/i.test(text)) return clampSize([1152, 2048]);
22359
+ return clampSize([2048, 1152]);
22360
+ }
22361
+ if (/(2k|1440p)/i.test(text)) {
22362
+ if (aspect === "1:1") return clampSize([1440, 1440]);
22363
+ if (aspect === "9:16") return clampSize([810, 1440]);
22364
+ return clampSize([1440, 810]);
22365
+ }
22366
+ return void 0;
22367
+ }
22368
+ function parseUseCaseSize(text, aspectHint) {
22369
+ if (/(icon|アイコン)/i.test(text)) return [512, 512];
22370
+ if (/(thumbnail|サムネ)/i.test(text)) return [1280, 720];
22371
+ if (/(instagram\s*story|インスタ\s*ストーリー)/i.test(text)) return [1080, 1920];
22372
+ if (/(instagram\s*post|インスタ\s*投稿)/i.test(text)) return [1080, 1080];
22373
+ if (/(twitter\s*header|x\s*header)/i.test(text)) return [1500, 500];
22374
+ if (/(hd|フルhd)/i.test(text)) return [1920, 1080];
22375
+ if (aspectHint) return deriveSizeFromAspect(aspectHint);
22376
+ if (/(portrait|縦長|縦向き)/i.test(text)) return deriveSizeFromAspect("9:16");
22377
+ if (/(landscape|横長|横向き)/i.test(text)) return deriveSizeFromAspect("16:9");
22378
+ if (/(square|正方形|スクエア)/i.test(text)) return [1024, 1024];
22379
+ return void 0;
22380
+ }
22381
+ function inferFormat(text) {
22382
+ if (/(png|透過|alpha)/i.test(text)) return "png";
22383
+ if (/(webp|ウェブピー)/i.test(text)) return "webp";
22384
+ if (/(jpg|jpeg|写真|photo)/i.test(text)) return "jpg";
22385
+ return void 0;
22386
+ }
22387
+ function inferImageOptionsFromText(text) {
22388
+ const lower2 = text.toLowerCase();
22389
+ const aspect = parseAspect(lower2);
22390
+ const exp = parseExplicitSize(lower2);
22391
+ const k4 = parse4KHints(lower2, aspect);
22392
+ const use = parseUseCaseSize(lower2, aspect);
22393
+ const size = exp || k4 || use;
22394
+ const format = inferFormat(lower2);
22395
+ const out = {};
22396
+ if (size) out.size = size;
22397
+ if (format) out.format = format;
22398
+ return out;
22399
+ }
22400
+ var init_NLInference = __esm({
22401
+ "src/services/media-orchestrator/NLInference.ts"() {
22402
+ }
22403
+ });
22404
+
22405
+ // src/services/cli-auth/api-caller.ts
22406
+ var api_caller_exports = {};
22407
+ __export(api_caller_exports, {
22408
+ RateLimitError: () => RateLimitError2,
22409
+ callAPI: () => callAPI,
22410
+ executeAIProxy: () => executeAIProxy,
22411
+ executeChat: () => executeChat,
22412
+ executeCode: () => executeCode
22413
+ });
22414
+ async function callAPI(endpoint, options = {}) {
22415
+ const tokens2 = await authManager2.getValidTokens();
22416
+ if (!tokens2) {
22417
+ throw new Error("Authentication required. Please run /login first.");
22418
+ }
22419
+ const apiBase = process.env.MARIA_API_BASE || "https://api.maria-code.ai";
22420
+ const url2 = `${apiBase}${endpoint}`;
22421
+ const controller = new AbortController();
22422
+ const defaultMs = 6e5;
22423
+ const envMs = Number(process.env.MARIA_API_TIMEOUT_MS || process.env.MARIA_CODE_TIMEOUT_MS || defaultMs);
22424
+ const timeoutMs = Number.isFinite(envMs) && envMs > 0 ? envMs : defaultMs;
22425
+ const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
22426
+ try {
22427
+ const response = await fetch(url2, {
22428
+ method: options.method || "GET",
22429
+ headers: {
22430
+ "Authorization": `Bearer ${tokens2.accessToken}`,
22431
+ "Content-Type": "application/json",
22432
+ ...options.headers
22433
+ },
22434
+ body: options.body ? JSON.stringify(options.body) : void 0,
22435
+ // Note: fetch in Node doesn't accept 'agent' in our typing here; relying on global agent not necessary
22436
+ signal: controller.signal
22437
+ });
22438
+ clearTimeout(timeoutId);
22439
+ if (!response) {
22440
+ throw new Error("\u{1F310} Network error, check connection");
22441
+ }
22442
+ if (response.status === 401) {
22443
+ throw new Error("Session expired. Please run /login again.");
22444
+ }
22445
+ if (response.status === 402) {
22446
+ const data2 = await response.json().catch(() => ({}));
22447
+ throw new Error(`Quota exceeded: ${typeof data2?.message === "string" ? data2.message : "Please wait or /upgrade"}`);
22448
+ }
22449
+ if (response.status === 403) {
22450
+ const data2 = await response.json().catch(() => ({}));
22451
+ throw new Error(`Not available on Free plan: ${typeof data2?.message === "string" ? data2.message : "Run /upgrade"}`);
22452
+ }
22453
+ if (response.status === 429) {
22454
+ const h2 = response.headers;
22455
+ const ra = h2.get("Retry-After");
22456
+ const reset = h2.get("RateLimit-Reset") || h2.get("X-RateLimit-Reset");
22457
+ let waitSec = 3;
22458
+ if (ra && /^\d+$/.test(ra)) {
22459
+ waitSec = +ra;
22460
+ } else if (ra) {
22461
+ const t2 = Date.parse(ra);
22462
+ if (!isNaN(t2)) waitSec = Math.max(1, Math.ceil((t2 - Date.now()) / 1e3));
22463
+ } else if (reset) {
22464
+ waitSec = Math.max(1, Math.ceil((+reset - Date.now()) / 1e3));
22465
+ }
22466
+ throw new RateLimitError2(`\u23F1 Wait ${waitSec}s`, waitSec);
22467
+ }
22468
+ if (!response.ok) {
22469
+ const data2 = await response.json().catch(() => ({}));
22470
+ const msg = typeof data2?.error === "string" ? data2.error : `Request failed: ${response.statusText}`;
22471
+ throw new Error(msg);
22472
+ }
22473
+ const data = await response.json();
22474
+ return data;
22475
+ } catch (error2) {
22476
+ clearTimeout(timeoutId);
22477
+ const err = error2;
22478
+ if (err && err.name === "AbortError") {
22479
+ throw new Error("\u{1F310} Network error, check connection");
22480
+ }
22481
+ throw err;
22482
+ }
22483
+ }
22484
+ async function executeChat(messages) {
22485
+ const response = await callAPI("/v1/chat", {
22486
+ method: "POST",
22487
+ body: { messages }
22488
+ });
22489
+ return response;
22490
+ }
22491
+ async function executeCode(input3) {
22492
+ const isOptions = typeof input3 === "object";
22493
+ const prompt = isOptions ? input3.prompt : input3;
22494
+ const provider = isOptions ? input3.provider : void 0;
22495
+ const model = isOptions ? input3.model : void 0;
22496
+ const attachments = isOptions ? input3.attachments : void 0;
22497
+ const body = { prompt, taskType: "code" };
22498
+ if (provider) body.provider = provider;
22499
+ if (model) body.model = model;
22500
+ if (attachments && attachments.length > 0) {
22501
+ body.metadata = { attachments };
22502
+ }
22503
+ const response = await callAPI("/v1/ai-proxy", {
22504
+ method: "POST",
22505
+ body
22506
+ });
22507
+ if (response.data?.routedModel) {
22508
+ response.routedModel = response.data.routedModel;
22509
+ }
22510
+ if (response.data?.content) {
22511
+ response.output = response.data.content;
22512
+ }
22513
+ return response;
22514
+ }
22515
+ async function executeAIProxy(provider, model, messages, options) {
22516
+ return callAPI("/v1/ai-proxy", {
22517
+ method: "POST",
22518
+ body: { provider, model, messages, options }
22519
+ });
22520
+ }
22521
+ var authManager2, RateLimitError2;
22522
+ var init_api_caller = __esm({
22523
+ "src/services/cli-auth/api-caller.ts"() {
22524
+ init_AuthenticationManager();
22525
+ new https__default.default.Agent({ keepAlive: true });
22526
+ authManager2 = new AuthenticationManager();
22527
+ RateLimitError2 = class extends Error {
22528
+ constructor(message, retryAfter) {
22529
+ super(message);
22530
+ this.retryAfter = retryAfter;
22531
+ this.name = "RateLimitError";
22532
+ }
22533
+ };
22534
+ }
22535
+ });
22536
+
22537
+ // src/services/media-orchestrator/ImageArgumentInference.ts
22538
+ function extractFirstJson(text) {
22539
+ const fence = /```json\r?\n([\s\S]*?)```/i.exec(text);
22540
+ if (fence) return fence[1];
22541
+ const fencePlain = /```\s*\r?\n([\s\S]*?)```/i.exec(text);
22542
+ if (fencePlain) {
22543
+ try {
22544
+ JSON.parse(fencePlain[1]);
22545
+ return fencePlain[1];
22546
+ } catch {
22547
+ }
22548
+ }
22549
+ const start = text.indexOf("{");
22550
+ const end = text.lastIndexOf("}");
22551
+ if (start >= 0 && end > start) {
22552
+ const cand = text.slice(start, end + 1);
22553
+ try {
22554
+ JSON.parse(cand);
22555
+ return cand;
22556
+ } catch {
22557
+ }
22558
+ }
22559
+ return null;
22560
+ }
22561
+ function clampSize2(size) {
22562
+ const clamp = (n) => Math.min(4096, Math.max(256, Math.floor(n)));
22563
+ return [clamp(size[0]), clamp(size[1])];
22564
+ }
22565
+ function parseSizeAny(x2) {
22566
+ if (typeof x2 === "string") {
22567
+ const m2 = /^\s*(\d{2,4})x(\d{2,4})\s*$/i.exec(x2);
22568
+ if (m2) return clampSize2([Number(m2[1]), Number(m2[2])]);
22569
+ }
22570
+ if (x2 && typeof x2 === "object") {
22571
+ const any = x2;
22572
+ const w = Number(any.width ?? any.w);
22573
+ const h2 = Number(any.height ?? any.h);
22574
+ if (Number.isFinite(w) && Number.isFinite(h2)) return clampSize2([w, h2]);
22575
+ }
22576
+ return void 0;
22577
+ }
22578
+ function sanitizeFormat(fmt) {
22579
+ if (typeof fmt !== "string") return void 0;
22580
+ const f3 = fmt.toLowerCase();
22581
+ const mapped = f3 === "jpeg" ? "jpg" : f3;
22582
+ return ["png", "webp", "jpg"].includes(mapped) ? mapped : void 0;
22583
+ }
22584
+ async function inferImageArgsLLM(promptText) {
22585
+ const system = [
22586
+ "You extract image generation options from user natural language.",
22587
+ 'Return JSON only with keys: { "size"?: "WIDTHxHEIGHT", "format"?: "png|webp|jpg", "count"?: number }.',
22588
+ 'Only include "count" if the user explicitly specifies the number of images (e.g., "2 images"). Otherwise omit (default is 1).',
22589
+ 'Only include "format" if the user explicitly specifies a format (e.g., "png", "webp", "jpg", transparency). Otherwise omit (default is png).',
22590
+ 'Size must be a single string "WIDTHxHEIGHT". If the user implies aspect/resolution (e.g., "wide"/"landscape" => 16:9, "tall"/"portrait" => 9:16, "square" => 1:1, or 4K/UHD/1080p/720p), select a reasonable resolution within 256..4096 per side and return it as "WIDTHxHEIGHT".',
22591
+ "If size is not specified or implied, omit it (default is 1024x1024).",
22592
+ "Do NOT include model or keepExif unless the user explicitly specified them; otherwise omit.",
22593
+ "Do not include any explanation text; JSON only."
22594
+ ].join("\n");
22595
+ const user = promptText;
22596
+ const response = await callAPI("/v1/ai-proxy", {
22597
+ method: "POST",
22598
+ body: {
22599
+ prompt: `${system}
22600
+
22601
+ ---
22602
+
22603
+ ${user}`,
22604
+ taskType: "media"
22605
+ }
22606
+ });
22607
+ const raw = (response?.data?.content || response?.output || "").trim();
22608
+ const jsonText = extractFirstJson(raw) || raw;
22609
+ let parsed;
22610
+ try {
22611
+ parsed = JSON.parse(jsonText);
22612
+ } catch {
22613
+ return {};
22614
+ }
22615
+ const out = {};
22616
+ const size = parseSizeAny(parsed?.size);
22617
+ if (size) out.size = size;
22618
+ const fmt = sanitizeFormat(parsed?.format);
22619
+ if (fmt) out.format = fmt;
22620
+ if (Number.isFinite(Number(parsed?.count))) {
22621
+ const n = Math.max(1, Math.min(8, Math.floor(Number(parsed.count))));
22622
+ out.count = n;
22623
+ }
22624
+ if (typeof parsed?.model === "string" && parsed.model.trim()) out.model = String(parsed.model).trim();
22625
+ if (typeof parsed?.keepExif === "boolean") out.keepExif = parsed.keepExif;
22626
+ return out;
22627
+ }
22628
+ var init_ImageArgumentInference = __esm({
22629
+ "src/services/media-orchestrator/ImageArgumentInference.ts"() {
22630
+ init_api_caller();
22631
+ }
22632
+ });
22278
22633
  function parseSize(value) {
22279
22634
  const m2 = /^\s*(\d{2,4})x(\d{2,4})\s*$/i.exec(value || "");
22280
22635
  if (!m2) throw new Error(`invalid size: ${value}`);
@@ -22307,6 +22662,8 @@ function normalizeImageArgs(raw, root) {
22307
22662
  planOnly: false,
22308
22663
  dryRun: false
22309
22664
  };
22665
+ let explicitSize = false;
22666
+ let explicitFormat = false;
22310
22667
  while (args2.length) {
22311
22668
  const x2 = args2.shift();
22312
22669
  if (!x2.startsWith("--")) continue;
@@ -22315,12 +22672,14 @@ function normalizeImageArgs(raw, root) {
22315
22672
  switch (k) {
22316
22673
  case "size":
22317
22674
  out.size = parseSize(String(v));
22675
+ explicitSize = true;
22318
22676
  break;
22319
22677
  case "format": {
22320
22678
  const rawFmt = String(v).toLowerCase();
22321
22679
  const mapped = rawFmt === "jpeg" ? "jpg" : rawFmt;
22322
22680
  if (!["png", "webp", "jpg"].includes(mapped)) throw new Error("invalid format");
22323
22681
  out.format = mapped;
22682
+ explicitFormat = true;
22324
22683
  break;
22325
22684
  }
22326
22685
  case "count": {
@@ -22361,6 +22720,21 @@ function normalizeImageArgs(raw, root) {
22361
22720
  break;
22362
22721
  }
22363
22722
  }
22723
+ try {
22724
+ const inferred = inferImageOptionsFromText(prompt);
22725
+ if (!explicitSize && inferred.size) out.size = inferred.size;
22726
+ if (!explicitFormat && inferred.format) out.format = inferred.format;
22727
+ } catch {
22728
+ }
22729
+ try {
22730
+ if (String(process.env.MARIA_USE_LLM_INFER || "1") === "1" && (!explicitSize || !explicitFormat)) {
22731
+ global.__MARIA_IMAGE_LLM_INFER__ = async () => {
22732
+ const llm = await inferImageArgsLLM(prompt);
22733
+ return llm;
22734
+ };
22735
+ }
22736
+ } catch {
22737
+ }
22364
22738
  const pixels = out.size[0] * out.size[1] * out.count;
22365
22739
  if (pixels > (out.budgetPixels || 0)) throw new Error("budget exceeded");
22366
22740
  if (!out.apply && !out.planOnly && !out.dryRun) {
@@ -22393,7 +22767,8 @@ function normalizeVideoArgs(raw, root) {
22393
22767
  retry: 2,
22394
22768
  apply: false,
22395
22769
  planOnly: false,
22396
- dryRun: false
22770
+ dryRun: false,
22771
+ aspect: "16:9"
22397
22772
  };
22398
22773
  while (args2.length) {
22399
22774
  const x2 = args2.shift();
@@ -22407,9 +22782,43 @@ function normalizeVideoArgs(raw, root) {
22407
22782
  case "fps":
22408
22783
  out.fps = clampInt(v, 1, 60, "fps");
22409
22784
  break;
22410
- case "res":
22411
- out.size = parseSize(String(v));
22785
+ case "size": {
22786
+ const sz = parseSize(String(v));
22787
+ out.size = sz;
22788
+ out.aspect = sz[0] >= sz[1] ? "16:9" : "9:16";
22789
+ break;
22790
+ }
22791
+ case "res": {
22792
+ const sv = String(v).toLowerCase().replace(/p$/, "");
22793
+ if (/^\d+x\d+$/i.test(String(v))) {
22794
+ out.size = parseSize(String(v));
22795
+ out.aspect = out.size[0] >= out.size[1] ? "16:9" : "9:16";
22796
+ } else if (sv === "720") {
22797
+ out.size = out.aspect === "9:16" ? [720, 1280] : [1280, 720];
22798
+ } else if (sv === "1080") {
22799
+ out.size = out.aspect === "9:16" ? [1080, 1920] : [1920, 1080];
22800
+ } else {
22801
+ throw new Error("invalid res (use 720|1080 or WIDTHxHEIGHT)");
22802
+ }
22803
+ break;
22804
+ }
22805
+ case "aspect": {
22806
+ const a = String(v);
22807
+ if (a !== "16:9" && a !== "9:16") throw new Error("invalid aspect (use 16:9|9:16)");
22808
+ out.aspect = a;
22809
+ const [w, h2] = out.size;
22810
+ if (w === 1280 && h2 === 720 || w === 720 && h2 === 1280 || w === 1920 && h2 === 1080 || w === 1080 && h2 === 1920) {
22811
+ if (a === "9:16") {
22812
+ if (h2 === 720) out.size = [720, 1280];
22813
+ else if (h2 === 1080) out.size = [1080, 1920];
22814
+ } else {
22815
+ if (w === 720) out.size = [1280, 720];
22816
+ else if (w === 1080) out.size = [1920, 1080];
22817
+ if (w === 1080 && h2 === 1920) out.size = [1920, 1080];
22818
+ }
22819
+ }
22412
22820
  break;
22821
+ }
22413
22822
  case "format":
22414
22823
  if (!["mp4", "webm"].includes(String(v))) throw new Error("invalid format");
22415
22824
  out.format = v;
@@ -22445,7 +22854,11 @@ function normalizeVideoArgs(raw, root) {
22445
22854
  }
22446
22855
  const caps = chooseCaps("video", out.model);
22447
22856
  if (caps?.maxVideoSize) {
22448
- if (out.size[0] > caps.maxVideoSize[0] || out.size[1] > caps.maxVideoSize[1]) throw new Error("resolution exceeds model capability");
22857
+ const reqMax = Math.max(out.size[0], out.size[1]);
22858
+ const reqMin = Math.min(out.size[0], out.size[1]);
22859
+ const capMax = Math.max(caps.maxVideoSize[0], caps.maxVideoSize[1]);
22860
+ const capMin = Math.min(caps.maxVideoSize[0], caps.maxVideoSize[1]);
22861
+ if (reqMax > capMax || reqMin > capMin) throw new Error("resolution exceeds model capability");
22449
22862
  }
22450
22863
  if (caps?.maxDuration && out.duration > caps.maxDuration) throw new Error("duration exceeds model capability");
22451
22864
  if (caps?.maxFps && out.fps > caps.maxFps) throw new Error("fps exceeds model capability");
@@ -22473,6 +22886,8 @@ function sanitizeOut(outDir, root) {
22473
22886
  var init_Normalizer = __esm({
22474
22887
  "src/services/media-orchestrator/Normalizer.ts"() {
22475
22888
  init_types4();
22889
+ init_NLInference();
22890
+ init_ImageArgumentInference();
22476
22891
  }
22477
22892
  });
22478
22893
  function ensureDirSync(p) {
@@ -23334,6 +23749,19 @@ var init_image_command = __esm({
23334
23749
  const spinner = new ProcessAnimation();
23335
23750
  spinner.start();
23336
23751
  try {
23752
+ try {
23753
+ const hook = global.__MARIA_IMAGE_LLM_INFER__;
23754
+ if (hook) {
23755
+ const llm = await hook();
23756
+ if (llm) {
23757
+ if (llm.size && (!Array.isArray(cli.size) || cli.size.length !== 2)) cli.size = llm.size;
23758
+ if (llm.size && Array.isArray(llm.size)) cli.size = llm.size;
23759
+ if (llm.format) cli.format = llm.format;
23760
+ if (Number.isFinite(Number(llm.count))) cli.count = Math.max(1, Math.min(8, Math.floor(Number(llm.count))));
23761
+ }
23762
+ }
23763
+ } catch {
23764
+ }
23337
23765
  const useRemote = String(process.env.MARIA_USE_REMOTE_MEDIA || "").toLowerCase() === "1" && await authManager.isAuthenticated();
23338
23766
  if (useRemote) {
23339
23767
  try {
@@ -23645,12 +24073,18 @@ async function runVideoPipeline(params2, opts) {
23645
24073
  const { GoogleGenAI } = __require("@google/genai");
23646
24074
  const ai2 = new GoogleGenAI({ apiKey });
23647
24075
  const modelName = params2.model || "veo-3.0-generate-001";
23648
- const aspectRatio = params2.size[0] >= params2.size[1] ? "16:9" : "9:16";
24076
+ const aspectRatio = "16:9";
24077
+ const resolution = Math.max(params2.size[0], params2.size[1]) >= 1920 ? "1080p" : "720p";
23649
24078
  const effectiveDuration = 8;
23650
24079
  let operation = await ai2.models.generateVideos({
23651
24080
  model: modelName,
23652
24081
  prompt: String(params2.prompt),
23653
- config: { aspectRatio, durationSeconds: effectiveDuration, frameRate: params2.fps }
24082
+ config: {
24083
+ aspectRatio,
24084
+ /* resolution: resolution, */
24085
+ durationSeconds: effectiveDuration,
24086
+ frameRate: params2.fps
24087
+ }
23654
24088
  });
23655
24089
  const pollStart = Date.now();
23656
24090
  const maxWaitMs = 6 * 60 * 1e3;
@@ -23802,7 +24236,7 @@ var init_video_command = __esm({
23802
24236
  category = "media";
23803
24237
  description = "Generate videos using Gemini (frames fallback when mux unavailable)";
23804
24238
  aliases = [];
23805
- usage = '/video "prompt" [--duration 8] [--fps 24] [--res 1280x720] [--format mp4|webm] [--model gemini-...] [--seed N] [--out dir] [--apply|--plan-only|--dry-run] [--concurrency N] [--retry N]';
24239
+ usage = '/video "prompt" [--duration 8] [--fps 24] [--aspect 16:9|9:16] [--res 720|1080] [--format mp4|webm] [--model gemini-...] [--seed N] [--out dir] [--apply|--plan-only|--dry-run] [--concurrency N] [--retry N]';
23806
24240
  examples = [
23807
24241
  { input: '/video "product demo" --duration 8 --fps 24 --res 1280x720 --apply', description: "Generate a short demo video" }
23808
24242
  ];
@@ -23823,11 +24257,15 @@ var init_video_command = __esm({
23823
24257
  const useRemote = String(process.env.MARIA_USE_REMOTE_MEDIA || "").toLowerCase() === "1" && await authManager.isAuthenticated();
23824
24258
  if (useRemote) {
23825
24259
  try {
24260
+ const isPortrait = cli.size[1] > cli.size[0];
24261
+ const maxEdge = Math.max(cli.size[0], cli.size[1]);
24262
+ const discrete = maxEdge >= 1920 ? "1080" : maxEdge >= 1280 ? "720" : void 0;
23826
24263
  const body = {
23827
24264
  prompt: cli.prompt,
23828
24265
  duration: cli.duration,
23829
24266
  fps: cli.fps,
23830
- res: `${cli.size[0]}x${cli.size[1]}`,
24267
+ res: discrete ? discrete : `${cli.size[0]}x${cli.size[1]}`,
24268
+ aspect: isPortrait ? "9:16" : "16:9",
23831
24269
  format: cli.format,
23832
24270
  model: cli.model,
23833
24271
  seed: cli.seed
@@ -25909,7 +26347,7 @@ var init_about_command = __esm({
25909
26347
  async execute(args2, context2) {
25910
26348
  const output3 = [];
25911
26349
  output3.push("");
25912
- output3.push(chalk40__default.default.cyan.bold("\u{1F916} About MARIA v4.3.34"));
26350
+ output3.push(chalk40__default.default.cyan.bold("\u{1F916} About MARIA v4.3.36"));
25913
26351
  output3.push(chalk40__default.default.gray("\u2550".repeat(40)));
25914
26352
  output3.push("");
25915
26353
  output3.push(chalk40__default.default.white.bold("MARIA - Minimal API, Maximum Power"));
@@ -38335,7 +38773,8 @@ function formatPlan(summary, opts) {
38335
38773
  if (opts.requestText && opts.requestText.trim().length > 0) {
38336
38774
  lines.push(opts.requestText.trim(), "");
38337
38775
  }
38338
- lines.push(`Modified Artifacts (${summary.planned} files):`);
38776
+ const headerLabel = opts.planView ? "Planned Artifacts" : "Modified Artifacts";
38777
+ lines.push(`${headerLabel} (${summary.planned} files):`);
38339
38778
  const warnMap = buildPerFileWarnings(summary.files, opts.validated);
38340
38779
  const skippedSet = new Set(opts.validated?.skipped || []);
38341
38780
  for (const f3 of summary.files) {
@@ -38360,18 +38799,20 @@ function formatPlan(summary, opts) {
38360
38799
  lines.push(diff, "");
38361
38800
  }
38362
38801
  }
38363
- const created = summary.files.filter((f3) => f3.action === "create").length;
38364
- const modified = summary.files.filter((f3) => f3.action === "modify").length;
38365
- const skipped = opts.validated?.skipped?.length || 0;
38366
- const okPhrase = created > 0 ? `${created + modified} files created/modified` : `${modified} files modified`;
38367
- lines.push(`OK: ${okPhrase}`);
38368
- if (skipped > 0) lines.push(`WARN: ${skipped} file${skipped > 1 ? "s" : ""} skipped`);
38369
- lines.push("Next steps:");
38370
- if (large) {
38371
- lines.push('- Large output \u2013 previews suppressed. Use --output diff or press "d" in interactive mode');
38802
+ if (!opts.planView) {
38803
+ const created = summary.files.filter((f3) => f3.action === "create").length;
38804
+ const modified = summary.files.filter((f3) => f3.action === "modify").length;
38805
+ const skipped = opts.validated?.skipped?.length || 0;
38806
+ const okPhrase = created > 0 ? `${created + modified} files created/modified` : `${modified} files modified`;
38807
+ lines.push(`OK: ${okPhrase}`);
38808
+ if (skipped > 0) lines.push(`WARN: ${skipped} file${skipped > 1 ? "s" : ""} skipped`);
38809
+ lines.push("Next steps:");
38810
+ if (large) {
38811
+ lines.push('- Large output \u2013 previews suppressed. Use --output diff or press "d" in interactive mode');
38812
+ }
38813
+ lines.push("- If this looks correct, commit the changes");
38814
+ lines.push('- For a full diff: rerun with --output diff or press "d" in interactive mode');
38372
38815
  }
38373
- lines.push("- If this looks correct, commit the changes");
38374
- lines.push('- For a full diff: rerun with --output diff or press "d" in interactive mode');
38375
38816
  return lines.join("\n");
38376
38817
  }
38377
38818
  function okLine(text) {
@@ -38407,9 +38848,10 @@ function formatPlanAsDiff(files, opts) {
38407
38848
  bytesUsed += diffBytes;
38408
38849
  shownFiles++;
38409
38850
  }
38410
- if (files.length > shownFiles) {
38851
+ const totalDiffTargets = files.filter((f3) => f3.action === "modify").length;
38852
+ if (totalDiffTargets > shownFiles) {
38411
38853
  lines.push(`
38412
- [${files.length - shownFiles} more file(s) omitted; re-run with --output diff --diff-lines ${budget.diffLines ?? 200}]`);
38854
+ [${totalDiffTargets - shownFiles} more file(s) omitted; re-run with --output diff --diff-lines ${budget.diffLines ?? 200}]`);
38413
38855
  }
38414
38856
  return lines.join("\n");
38415
38857
  }
@@ -38651,129 +39093,6 @@ var init_InteractiveController = __esm({
38651
39093
  init_OutputFormatter();
38652
39094
  }
38653
39095
  });
38654
-
38655
- // src/services/cli-auth/api-caller.ts
38656
- var api_caller_exports = {};
38657
- __export(api_caller_exports, {
38658
- RateLimitError: () => RateLimitError2,
38659
- callAPI: () => callAPI,
38660
- executeAIProxy: () => executeAIProxy,
38661
- executeChat: () => executeChat,
38662
- executeCode: () => executeCode
38663
- });
38664
- async function callAPI(endpoint, options = {}) {
38665
- const tokens2 = await authManager2.getValidTokens();
38666
- if (!tokens2) {
38667
- throw new Error("Authentication required. Please run /login first.");
38668
- }
38669
- const apiBase = process.env.MARIA_API_BASE || "https://api.maria-code.ai";
38670
- const url2 = `${apiBase}${endpoint}`;
38671
- const controller = new AbortController();
38672
- const defaultMs = 6e5;
38673
- const envMs = Number(process.env.MARIA_API_TIMEOUT_MS || process.env.MARIA_CODE_TIMEOUT_MS || defaultMs);
38674
- const timeoutMs = Number.isFinite(envMs) && envMs > 0 ? envMs : defaultMs;
38675
- const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
38676
- try {
38677
- const response = await fetch(url2, {
38678
- method: options.method || "GET",
38679
- headers: {
38680
- "Authorization": `Bearer ${tokens2.accessToken}`,
38681
- "Content-Type": "application/json",
38682
- ...options.headers
38683
- },
38684
- body: options.body ? JSON.stringify(options.body) : void 0,
38685
- agent,
38686
- // Use keep-alive agent
38687
- signal: controller.signal
38688
- });
38689
- clearTimeout(timeoutId);
38690
- if (!response) {
38691
- throw new Error("\u{1F310} Network error, check connection");
38692
- }
38693
- if (response.status === 401) {
38694
- throw new Error("Session expired. Please run /login again.");
38695
- }
38696
- if (response.status === 402) {
38697
- const data2 = await response.json().catch(() => ({}));
38698
- throw new Error(`Quota exceeded: ${data2.message || "Please wait or /upgrade"}`);
38699
- }
38700
- if (response.status === 403) {
38701
- const data2 = await response.json().catch(() => ({}));
38702
- throw new Error(`Not available on Free plan: ${data2.message || "Run /upgrade"}`);
38703
- }
38704
- if (response.status === 429) {
38705
- const h2 = response.headers;
38706
- const ra = h2.get("Retry-After");
38707
- const reset = h2.get("RateLimit-Reset") || h2.get("X-RateLimit-Reset");
38708
- let waitSec = 3;
38709
- if (ra && /^\d+$/.test(ra)) {
38710
- waitSec = +ra;
38711
- } else if (ra) {
38712
- const t2 = Date.parse(ra);
38713
- if (!isNaN(t2)) waitSec = Math.max(1, Math.ceil((t2 - Date.now()) / 1e3));
38714
- } else if (reset) {
38715
- waitSec = Math.max(1, Math.ceil((+reset - Date.now()) / 1e3));
38716
- }
38717
- throw new RateLimitError2(`\u23F1 Wait ${waitSec}s`, waitSec);
38718
- }
38719
- if (!response.ok) {
38720
- const data2 = await response.json().catch(() => ({}));
38721
- throw new Error(data2.error || `Request failed: ${response.statusText}`);
38722
- }
38723
- const data = await response.json();
38724
- return data;
38725
- } catch (error2) {
38726
- clearTimeout(timeoutId);
38727
- if (error2.name === "AbortError") {
38728
- throw new Error("\u{1F310} Network error, check connection");
38729
- }
38730
- throw error2;
38731
- }
38732
- }
38733
- async function executeChat(messages) {
38734
- const response = await callAPI("/v1/chat", {
38735
- method: "POST",
38736
- body: { messages }
38737
- });
38738
- return response;
38739
- }
38740
- async function executeCode(prompt) {
38741
- const response = await callAPI("/v1/ai-proxy", {
38742
- method: "POST",
38743
- body: {
38744
- prompt,
38745
- taskType: "code"
38746
- }
38747
- });
38748
- if (response.data?.routedModel) {
38749
- response.routedModel = response.data.routedModel;
38750
- }
38751
- if (response.data?.content) {
38752
- response.output = response.data.content;
38753
- }
38754
- return response;
38755
- }
38756
- async function executeAIProxy(provider, model, messages, options) {
38757
- return callAPI("/v1/ai-proxy", {
38758
- method: "POST",
38759
- body: { provider, model, messages, options }
38760
- });
38761
- }
38762
- var agent, authManager2, RateLimitError2;
38763
- var init_api_caller = __esm({
38764
- "src/services/cli-auth/api-caller.ts"() {
38765
- init_AuthenticationManager();
38766
- agent = new https__default.default.Agent({ keepAlive: true });
38767
- authManager2 = new AuthenticationManager();
38768
- RateLimitError2 = class extends Error {
38769
- constructor(message, retryAfter) {
38770
- super(message);
38771
- this.retryAfter = retryAfter;
38772
- this.name = "RateLimitError";
38773
- }
38774
- };
38775
- }
38776
- });
38777
39096
  async function mapAttachmentsToTargets(attached, opts) {
38778
39097
  const warnings = [];
38779
39098
  const mapped = [];
@@ -39221,7 +39540,68 @@ ${requestPreamble}
39221
39540
  ${request}
39222
39541
 
39223
39542
  ${editContext}`;
39224
- const response = await executeCode(enriched);
39543
+ const ctxAttachments = Array.isArray(opts.attachedFiles) && opts.attachedFiles.length > 0 ? opts.attachedFiles.map((f3) => ({
39544
+ name: f3.originalName,
39545
+ path: f3.pathHint,
39546
+ mime: f3.mime || "text/plain",
39547
+ data_base64: f3.content ? Buffer.from(f3.content, "utf8").toString("base64") : void 0
39548
+ })).map((a) => a.data_base64 ? a : { ...a, data_base64: void 0 }) : [];
39549
+ const pathAttachments = [];
39550
+ if (explicitFiles.length > 0) {
39551
+ try {
39552
+ const fs51 = await import('fs/promises');
39553
+ const pathMod = await import('path');
39554
+ for (const rel of explicitFiles) {
39555
+ try {
39556
+ const full = explicitAbsMap[rel] || pathMod.join(opts.root, rel);
39557
+ const stat13 = await fs51.stat(full).catch(() => null);
39558
+ if (!stat13 || !stat13.isFile()) continue;
39559
+ const buf = await fs51.readFile(full);
39560
+ const ext2 = (pathMod.extname(full) || "").toLowerCase();
39561
+ const mime = ext2 === ".pdf" ? "application/pdf" : ext2 === ".png" ? "image/png" : ext2 === ".jpg" || ext2 === ".jpeg" ? "image/jpeg" : ext2 === ".webp" ? "image/webp" : ext2 === ".gif" ? "image/gif" : ext2 === ".bmp" ? "image/bmp" : ext2 === ".svg" ? "image/svg+xml" : ext2 === ".tif" || ext2 === ".tiff" ? "image/tiff" : ext2 === ".heic" ? "image/heic" : ext2 === ".heif" ? "image/heif" : "text/plain";
39562
+ pathAttachments.push({
39563
+ name: pathMod.basename(full),
39564
+ path: full,
39565
+ mime,
39566
+ data_base64: buf.toString("base64")
39567
+ });
39568
+ } catch {
39569
+ }
39570
+ }
39571
+ } catch {
39572
+ }
39573
+ }
39574
+ const hydratedCtx = [];
39575
+ if (ctxAttachments.length > 0) {
39576
+ try {
39577
+ const fs51 = await import('fs/promises');
39578
+ for (const a of ctxAttachments) {
39579
+ if (a.data_base64) {
39580
+ hydratedCtx.push(a);
39581
+ continue;
39582
+ }
39583
+ const p = a.path || "";
39584
+ if (!p) {
39585
+ continue;
39586
+ }
39587
+ try {
39588
+ const stat13 = await fs51.stat(p).catch(() => null);
39589
+ if (!stat13 || !stat13.isFile()) {
39590
+ hydratedCtx.push(a);
39591
+ continue;
39592
+ }
39593
+ const buf = await fs51.readFile(p);
39594
+ hydratedCtx.push({ ...a, data_base64: buf.toString("base64") });
39595
+ } catch {
39596
+ hydratedCtx.push(a);
39597
+ }
39598
+ }
39599
+ } catch {
39600
+ hydratedCtx.push(...ctxAttachments);
39601
+ }
39602
+ }
39603
+ const allAttachments = (hydratedCtx.length ? hydratedCtx : ctxAttachments).concat(pathAttachments);
39604
+ const response = await executeCode(allAttachments.length > 0 ? { prompt: enriched, provider: "google", model: "gemini-2.5-flash", attachments: allAttachments } : enriched);
39225
39605
  const raw = (response.output || response?.data?.content || "").trim();
39226
39606
  if (!raw) {
39227
39607
  return {
@@ -39350,6 +39730,7 @@ ${editContext}`;
39350
39730
  const remainingSkipped = (validated.skipped || []).filter((p) => !skippedPlans.some((sp) => sp.path === p)).map((p) => ({ path: p, kind: "source", action: "skip", description: "" }));
39351
39731
  const displayFiles = validated.files.concat(skippedPlans).concat(remainingSkipped);
39352
39732
  const summary = summarizePlan(displayFiles);
39733
+ const planView = opts.flags.planOnly || opts.flags.dryRun || !opts.flags.apply;
39353
39734
  const lines = [
39354
39735
  formatPlan(summary, {
39355
39736
  mode: outputMode,
@@ -39357,11 +39738,26 @@ ${editContext}`;
39357
39738
  diffBudget: collectDiffBudget(opts.flags),
39358
39739
  root: opts.root,
39359
39740
  requestText: request,
39360
- validated: { warnings: validated.warnings.slice(), skipped: validated.skipped.slice() }
39741
+ validated: { warnings: validated.warnings.slice(), skipped: validated.skipped.slice() },
39742
+ planView
39361
39743
  })
39362
39744
  ];
39363
39745
  if (opts.flags.planOnly || opts.flags.dryRun || !opts.flags.apply) {
39364
- return { plan: normalized, validated, summaryLines: withNotices(lines) };
39746
+ let specMarkdown;
39747
+ try {
39748
+ const prompt = buildSpecPrompt(request, normalized);
39749
+ const { callApiJson: callApiJson4 } = await Promise.resolve().then(() => (init_api_client(), api_client_exports));
39750
+ try {
39751
+ const resp = await callApiJson4("/v1/ai-proxy", { method: "POST", body: JSON.stringify({ prompt, taskType: "chat" }), headers: { "Content-Type": "application/json" } });
39752
+ const content = resp?.data?.content || resp?.content;
39753
+ if (content && typeof content === "string") specMarkdown = content;
39754
+ } catch {
39755
+ }
39756
+ } catch {
39757
+ }
39758
+ const res = { plan: normalized, validated, summaryLines: withNotices(lines) };
39759
+ if (specMarkdown && typeof specMarkdown === "string" && specMarkdown.trim()) res.specMarkdown = specMarkdown;
39760
+ return res;
39365
39761
  }
39366
39762
  if (opts.flags.interactive && !opts.flags.yes && !process.stdin.isTTY) {
39367
39763
  lines.push("", "WARN: Non-TTY interactive request downgraded to plan-only. Re-run with --yes to apply non-interactively.");
@@ -39441,6 +39837,36 @@ ${editContext}`;
39441
39837
  return { plan: normalized, validated, summaryLines: withNotices([errorLine(err)]) };
39442
39838
  }
39443
39839
  }
39840
+ function buildSpecPrompt(request, plan) {
39841
+ const tree = {};
39842
+ for (const f3 of plan) {
39843
+ const dir = f3.path.split("/").slice(0, -1).join("/") || ".";
39844
+ if (!tree[dir]) tree[dir] = [];
39845
+ tree[dir].push(`${f3.action} ${f3.path} ${f3.language ? "(" + f3.language + ")" : ""}`.trim());
39846
+ }
39847
+ const treeLines = [];
39848
+ for (const [dir, items] of Object.entries(tree)) {
39849
+ treeLines.push(`- ${dir}`);
39850
+ for (const it of items) treeLines.push(` - ${it}`);
39851
+ }
39852
+ return [
39853
+ "You are a senior staff engineer. Produce a concise, high-quality Markdown spec for the following code change plan.",
39854
+ "",
39855
+ "Sections:",
39856
+ "- Overview",
39857
+ "- File Tree",
39858
+ "- Per-file Rationale (what/why)",
39859
+ "- Next Steps",
39860
+ "",
39861
+ "Request:",
39862
+ "```",
39863
+ request,
39864
+ "```",
39865
+ "",
39866
+ "Planned files:",
39867
+ treeLines.join("\n")
39868
+ ].join("\n");
39869
+ }
39444
39870
  function normalizePreviewLines(n) {
39445
39871
  return typeof n === "number" && n > 0 ? n : void 0;
39446
39872
  }
@@ -39635,7 +40061,7 @@ function scanSoftIssues(files) {
39635
40061
  return { hasTrailingWhitespace: tw, hasConflictMarkers: cm };
39636
40062
  }
39637
40063
  function parseExplicitFilenames(request) {
39638
- const matches = request.match(/([\w.-]+\.(?:html|css|js|jsx|ts|tsx))/gi);
40064
+ const matches = request.match(/([\w\-./\\:]+\.[A-Za-z0-9]{1,10})/gi);
39639
40065
  if (!matches) return [];
39640
40066
  const seen = /* @__PURE__ */ new Set();
39641
40067
  const out = [];
@@ -39935,6 +40361,7 @@ var LANGUAGE_EXTENSIONS, CodeCommand, codeCommand, metadata3;
39935
40361
  var init_code_command = __esm({
39936
40362
  "src/slash-commands/categories/code/code.command.ts"() {
39937
40363
  init_base_command();
40364
+ init_api_caller();
39938
40365
  init_rate_limit_handler();
39939
40366
  init_animations();
39940
40367
  init_code_utils();
@@ -39956,7 +40383,7 @@ var init_code_command = __esm({
39956
40383
  name = "code";
39957
40384
  category = "implementation";
39958
40385
  description = "Generate code with AI";
39959
- usage = "<request> [--plan-only|--sow] [--apply] [--dry-run] [--interactive] [--yes] [--max-files N] [--root DIR] [--rollback on|off] [--output names|summary|detail|diff] [--no-code] [--preview-lines N] [--only-attached] [--attach-mode strict|assist] [--max-attachments N] [--diff-lines N] [--diff-bytes N] [--diff-hunks N]";
40386
+ usage = "<request> [--plan-only|--sow] [--apply] [--dry-run] [--interactive] [--yes] [--max-files N] [--root DIR] [--rollback on|off] [--output names|summary|detail|diff] [--no-code] [--preview-lines N] [--only-attached] [--attach-mode strict|assist] [--max-attachments N] [--diff-lines N] [--diff-bytes N] [--diff-hunks N] [--diff-global-max-files N] [--diff-global-max-bytes N]";
39960
40387
  aliases = ["c"];
39961
40388
  examples = [
39962
40389
  {
@@ -39971,12 +40398,21 @@ var init_code_command = __esm({
39971
40398
  }
39972
40399
  ];
39973
40400
  async execute(commandArgs, context2) {
39974
- const request = commandArgs.raw.join(" ").trim();
40401
+ const request = await this.ensureLanguageDefaults(commandArgs.raw.join(" ").trim());
39975
40402
  if (!request) {
39976
40403
  return this.error("Please provide a code request \xB7 Example: /code create button component\nTip: Use --plan-only to safely review the plan, or --output detail to preview snippet heads.");
39977
40404
  }
39978
40405
  try {
39979
40406
  const opts = this.parseV2Options(commandArgs.raw);
40407
+ if (opts.planOnly) {
40408
+ opts.apply = false;
40409
+ opts.dryRun = false;
40410
+ }
40411
+ if (opts.dryRun) {
40412
+ opts.apply = false;
40413
+ }
40414
+ if (opts.dryRun && !opts.output) opts.output = "detail";
40415
+ if (opts.dryRun && !opts.previewLines) opts.previewLines = 50;
39980
40416
  const root = opts.root || process.cwd();
39981
40417
  const { orchestrate: orchestrate2 } = await Promise.resolve().then(() => (init_Orchestrator(), Orchestrator_exports));
39982
40418
  const attachments = await this.collectAttachedFiles(context2).catch(() => []);
@@ -39986,8 +40422,57 @@ var init_code_command = __esm({
39986
40422
  const spinner = new ProcessAnimation();
39987
40423
  spinner.start();
39988
40424
  try {
39989
- const res = await orchestrate2(request, { root, flags: { planOnly: opts.planOnly, apply: opts.apply, dryRun: opts.dryRun, interactive: opts.interactive, yes: opts.yes, maxFiles: opts.maxFiles, output: opts.output, hideCode: opts.noCode, previewLines: this.normalizePreviewLines(opts.previewLines), verbose: opts.verbose, onlyAttached: opts.onlyAttached, attachMode: opts.attachMode, maxAttachments: opts.maxAttachments, diffLines: opts.diffLines, diffBytes: opts.diffBytes, diffHunks: opts.diffHunks, allowDotfiles: opts.allowDotfiles }, abortSignal: abort.signal, attachedFiles: attachments });
39990
- const out = res.summaryLines.join("\n");
40425
+ const res = await orchestrate2(request, { root, flags: { planOnly: opts.planOnly, apply: opts.apply, dryRun: opts.dryRun, interactive: opts.interactive, yes: opts.yes, maxFiles: opts.maxFiles, output: opts.output, hideCode: opts.noCode, previewLines: this.normalizePreviewLines(opts.previewLines), verbose: opts.verbose, onlyAttached: opts.onlyAttached, attachMode: opts.attachMode, maxAttachments: opts.maxAttachments, diffLines: opts.diffLines, diffBytes: opts.diffBytes, diffHunks: opts.diffHunks, diffGlobalMaxFiles: opts.diffGlobalMaxFiles, diffGlobalMaxBytes: opts.diffGlobalMaxBytes, allowDotfiles: opts.allowDotfiles }, abortSignal: abort.signal, attachedFiles: attachments });
40426
+ if (opts.planOnly) {
40427
+ const fs51 = await import('fs/promises');
40428
+ const path64 = await import('path');
40429
+ const spec = res?.specMarkdown;
40430
+ const lines = Array.isArray(res?.summaryLines) ? res.summaryLines : [];
40431
+ const planItems = [];
40432
+ for (const l of lines) {
40433
+ const s2 = String(l).trim();
40434
+ if (!s2) continue;
40435
+ if (/^Modified Artifacts/i.test(s2)) continue;
40436
+ if (/^OK:/i.test(s2)) continue;
40437
+ if (/^Next steps:/i.test(s2)) continue;
40438
+ const m2 = /^-\s+(create|modify)\s+(.+)$/i.exec(s2);
40439
+ if (m2) {
40440
+ planItems.push(`- [plan] ${m2[1].toLowerCase()} ${m2[2]}`);
40441
+ continue;
40442
+ }
40443
+ planItems.push(`- ${s2}`);
40444
+ }
40445
+ const md = [];
40446
+ if (spec && spec.trim()) {
40447
+ md.push(spec.trim());
40448
+ } else {
40449
+ md.push("# Code Plan");
40450
+ md.push("");
40451
+ md.push("## Request");
40452
+ md.push("");
40453
+ md.push("```");
40454
+ md.push(request);
40455
+ md.push("```");
40456
+ md.push("");
40457
+ md.push("## Proposed Changes");
40458
+ md.push("");
40459
+ if (planItems.length) md.push(...planItems);
40460
+ else md.push("- (no summary available)");
40461
+ }
40462
+ const plansDir = path64.join(root, ".maria", "plans");
40463
+ await fs51.mkdir(plansDir, { recursive: true });
40464
+ const ts = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
40465
+ const fileName = `code-plan-${ts}.md`;
40466
+ const outPath = path64.join(plansDir, fileName);
40467
+ await fs51.writeFile(outPath, md.join("\n") + "\n", "utf8");
40468
+ const rel = path64.relative(root, outPath);
40469
+ return this.success(`Code plan saved: ${rel}`);
40470
+ }
40471
+ const detail = res?.detailLines;
40472
+ if (opts.dryRun && Array.isArray(detail) && detail.length) {
40473
+ return this.success(detail.join("\n"));
40474
+ }
40475
+ const out = Array.isArray(res?.summaryLines) ? res.summaryLines.join("\n") : "";
39991
40476
  return this.success(out);
39992
40477
  } finally {
39993
40478
  try {
@@ -40037,9 +40522,68 @@ ${pretty}`);
40037
40522
  return this.error(parts.join("\n"));
40038
40523
  }
40039
40524
  }
40525
+ // Add default language hints when not specified by the user (LLM-assisted detection)
40526
+ async ensureLanguageDefaults(raw) {
40527
+ try {
40528
+ const system = [
40529
+ "You analyze a user's code-generation request.",
40530
+ "Decide if the user explicitly specified a programming language or framework/tooling (e.g., TypeScript, Python, Rust, Java, React, Vue, Node, etc.).",
40531
+ 'Return ONLY compact JSON with shape {"explicitLanguage": boolean, "language"?: string}.',
40532
+ "Do not add any commentary."
40533
+ ].join("\n");
40534
+ const user = `Request: ${raw}`;
40535
+ const resp = await callAPI("/v1/ai-proxy", {
40536
+ method: "POST",
40537
+ body: {
40538
+ provider: "google",
40539
+ model: "gemini-2.5-flash",
40540
+ taskType: "chat",
40541
+ prompt: `${system}
40542
+
40543
+ ${user}`
40544
+ }
40545
+ });
40546
+ const content = (resp?.data?.content || resp?.content || "").trim();
40547
+ const extractFirstJson3 = (text) => {
40548
+ const fence = /```\s*json\s*\r?\n([\s\S]*?)```/i.exec(text);
40549
+ if (fence) return fence[1];
40550
+ const generic = /```\s*\r?\n([\s\S]*?)```/i.exec(text);
40551
+ if (generic) {
40552
+ try {
40553
+ JSON.parse(generic[1]);
40554
+ return generic[1];
40555
+ } catch {
40556
+ }
40557
+ }
40558
+ const start = text.indexOf("{");
40559
+ const end = text.lastIndexOf("}");
40560
+ if (start >= 0 && end > start) {
40561
+ const cand = text.slice(start, end + 1);
40562
+ try {
40563
+ JSON.parse(cand);
40564
+ return cand;
40565
+ } catch {
40566
+ }
40567
+ }
40568
+ return null;
40569
+ };
40570
+ const jsonText = extractFirstJson3(content) || content;
40571
+ let parsed = {};
40572
+ try {
40573
+ parsed = JSON.parse(jsonText);
40574
+ } catch {
40575
+ parsed.explicitLanguage = /```\s*[a-zA-Z]/.test(raw) || /\.(ts|tsx|js|jsx|py|java|kt|go|rs|rb|swift|cs|c|cpp|hpp|php|scala|hs|ex|exs|dart|lua|zig|sol|sql)\b/i.test(raw);
40576
+ }
40577
+ if (parsed && parsed.explicitLanguage) return raw;
40578
+ } catch {
40579
+ }
40580
+ const hint = " (Use TypeScript and React; prefer functional components and node)";
40581
+ return raw + hint;
40582
+ }
40040
40583
  // v2.0 helpers
40041
40584
  parseV2Options(raw) {
40042
- const opts = { planOnly: false, apply: false, dryRun: false, interactive: false, yes: false, rollback: true, output: void 0, noCode: false, previewLines: 0, root: void 0, maxFiles: void 0, verbose: false, gitGuard: void 0, allowDotfiles: false, confirmOverwrites: [], gitCommit: void 0, gitBranch: void 0, gitTag: void 0, gitTagPrefix: void 0, gitPush: void 0, gitPushRemote: void 0, onlyAttached: false, attachMode: "assist", maxAttachments: 50, diffLines: void 0, diffBytes: void 0, diffHunks: void 0 };
40585
+ const opts = { planOnly: false, apply: false, dryRun: false, interactive: false, yes: false, rollback: true, output: void 0, noCode: false, previewLines: 0, root: void 0, maxFiles: void 0, verbose: false, gitGuard: void 0, allowDotfiles: false, confirmOverwrites: [], gitCommit: void 0, gitBranch: void 0, gitTag: void 0, gitTagPrefix: void 0, gitPush: void 0, gitPushRemote: void 0, onlyAttached: false, attachMode: "assist", maxAttachments: 50, diffLines: void 0, diffBytes: void 0, diffHunks: void 0, diffGlobalMaxFiles: void 0, diffGlobalMaxBytes: void 0 };
40586
+ const explicit = { apply: false, planOnly: false, dryRun: false };
40043
40587
  const a = raw.slice();
40044
40588
  while (a.length) {
40045
40589
  const x2 = a.shift();
@@ -40049,12 +40593,15 @@ ${pretty}`);
40049
40593
  case "plan-only":
40050
40594
  case "sow":
40051
40595
  opts.planOnly = true;
40596
+ explicit.planOnly = true;
40052
40597
  break;
40053
40598
  case "apply":
40054
40599
  opts.apply = true;
40600
+ explicit.apply = true;
40055
40601
  break;
40056
40602
  case "dry-run":
40057
40603
  opts.dryRun = true;
40604
+ explicit.dryRun = true;
40058
40605
  break;
40059
40606
  case "interactive":
40060
40607
  opts.interactive = true;
@@ -40114,6 +40661,12 @@ ${pretty}`);
40114
40661
  case "diff-hunks":
40115
40662
  opts.diffHunks = Number(v || a.shift());
40116
40663
  break;
40664
+ case "diff-global-max-files":
40665
+ opts.diffGlobalMaxFiles = Number(v || a.shift());
40666
+ break;
40667
+ case "diff-global-max-bytes":
40668
+ opts.diffGlobalMaxBytes = Number(v || a.shift());
40669
+ break;
40117
40670
  case "confirm-overwrites": {
40118
40671
  const list = (v || a.shift() || "").split(",").map((s2) => s2.trim()).filter(Boolean);
40119
40672
  opts.confirmOverwrites = list;
@@ -40147,8 +40700,16 @@ ${pretty}`);
40147
40700
  }
40148
40701
  }
40149
40702
  }
40150
- if (!opts.apply && !opts.planOnly && !opts.dryRun) {
40151
- opts.apply = true;
40703
+ if (explicit.planOnly || explicit.dryRun) {
40704
+ opts.apply = false;
40705
+ }
40706
+ if (explicit.planOnly) {
40707
+ opts.dryRun = false;
40708
+ }
40709
+ if (!explicit.apply && !explicit.planOnly && !explicit.dryRun) {
40710
+ if (!opts.apply && !opts.planOnly && !opts.dryRun) {
40711
+ opts.apply = true;
40712
+ }
40152
40713
  }
40153
40714
  return opts;
40154
40715
  }
@@ -57880,7 +58441,7 @@ ${user}`,
57880
58441
  };
57881
58442
  }
57882
58443
  });
57883
- function extractFirstJson(text) {
58444
+ function extractFirstJson2(text) {
57884
58445
  const fence = /```json\r?\n([\s\S]*?)```/i.exec(text);
57885
58446
  if (fence) return fence[1];
57886
58447
  const start = text.indexOf("{");
@@ -57927,7 +58488,7 @@ ${user}`,
57927
58488
  }
57928
58489
  });
57929
58490
  const raw = (response?.data?.content || response?.output || "").trim();
57930
- const jsonText = extractFirstJson(raw) || raw;
58491
+ const jsonText = extractFirstJson2(raw) || raw;
57931
58492
  let parsed = {};
57932
58493
  try {
57933
58494
  parsed = JSON.parse(jsonText);
@@ -59214,6 +59775,17 @@ var init_slash_commands = __esm({
59214
59775
  init_registry();
59215
59776
  }
59216
59777
  });
59778
+
59779
+ // src/cli/session-state.ts
59780
+ function clearSession() {
59781
+ while (session.length) session.pop();
59782
+ }
59783
+ var session;
59784
+ var init_session_state = __esm({
59785
+ "src/cli/session-state.ts"() {
59786
+ session = [];
59787
+ }
59788
+ });
59217
59789
  async function handleSlash(input3) {
59218
59790
  if (!input3.startsWith("/")) return false;
59219
59791
  const { cmd, args: args2, options, flags } = parseSlash(input3);
@@ -59222,7 +59794,10 @@ async function handleSlash(input3) {
59222
59794
  clearTerminal();
59223
59795
  } catch {
59224
59796
  }
59225
- return true;
59797
+ try {
59798
+ clearSession();
59799
+ } catch {
59800
+ }
59226
59801
  }
59227
59802
  if (cmd === "doctor") {
59228
59803
  console.log(chalk40__default.default.white("Run as subcommand: maria doctor"));
@@ -59274,6 +59849,7 @@ var init_handle_slash = __esm({
59274
59849
  init_slash_commands();
59275
59850
  init_cli_auth();
59276
59851
  init_terminal();
59852
+ init_session_state();
59277
59853
  }
59278
59854
  });
59279
59855
  function formatAnyError(err) {
@@ -61344,7 +61920,7 @@ var init_ai_response_service = __esm({
61344
61920
  */
61345
61921
  async callLLM(prompt, opts = {}) {
61346
61922
  const {
61347
- system = PLAIN_OUTPUT ? "Return ONLY the answer (or ONLY code). No menus, no lists, no guided flows. Always respond in English." : "You are a helpful senior engineer named Maria. Always respond in English. Provide direct, production-quality answers. Make sure you answer in plain text, as a natural chat. When asked about the model (not your name or who you are, but the model), say you are a large language model fully trained by Bonginkan.",
61923
+ system = PLAIN_OUTPUT ? "Return ONLY the answer (or ONLY code). No menus, no lists, no guided flows. Always respond in English. If a local file path is provided, make sure you read the uploaded file before taking any actions." : "You are a helpful senior engineer named Maria. Always respond in English. Provide direct, production-quality answers. Make sure you answer in plain text, as a natural chat. When asked about the model (not your name or who you are, but the model), say you are a large language model fully trained by Bonginkan. If a path is provided, return the path as a string. If a local file path is provided, make sure you read the uploaded/attached file (which is likely equivalent to the path) before taking any actions.",
61348
61924
  model = void 0,
61349
61925
  provider = DEFAULT_PROVIDER2,
61350
61926
  temperature = 0.2,
@@ -61352,14 +61928,63 @@ var init_ai_response_service = __esm({
61352
61928
  } = opts;
61353
61929
  process.env.MARIA_API_BASE || "https://api.maria-code.ai";
61354
61930
  const preferApi = String(process.env.MARIA_USE_API || "1") === "1";
61931
+ let effectiveAttachments = Array.isArray(opts.attachments) ? opts.attachments.slice() : [];
61355
61932
  if (preferApi) {
61356
61933
  try {
61357
61934
  const { callAPI: callAPI2 } = await Promise.resolve().then(() => (init_api_caller(), api_caller_exports));
61935
+ let autoAttachments = [];
61936
+ try {
61937
+ const pathPattern = /(?:^|\s)([\w\-\.\/\\:]+\.[A-Za-z0-9]{1,10})(?:\s|$)/gi;
61938
+ const candidates = /* @__PURE__ */ new Set();
61939
+ let m2;
61940
+ const textToScan = `${prompt}`;
61941
+ while ((m2 = pathPattern.exec(textToScan)) !== null) {
61942
+ const p = (m2[1] || "").trim();
61943
+ if (p) candidates.add(p);
61944
+ }
61945
+ if (candidates.size > 0) {
61946
+ const fs51 = await import('fs/promises');
61947
+ const pathMod = await import('path');
61948
+ const cwd2 = process.cwd();
61949
+ for (const cand of candidates) {
61950
+ try {
61951
+ const normalized = cand.replace(/^"|"$/g, "").replace(/^'|'$/g, "");
61952
+ const abs = pathMod.isAbsolute(normalized) ? normalized : pathMod.join(cwd2, normalized);
61953
+ const st = await fs51.stat(abs).catch(() => null);
61954
+ if (!st || !st.isFile()) continue;
61955
+ const buf = await fs51.readFile(abs);
61956
+ const ext2 = (pathMod.extname(abs) || "").toLowerCase();
61957
+ const mime = ext2 === ".pdf" ? "application/pdf" : ext2 === ".png" ? "image/png" : ext2 === ".jpg" || ext2 === ".jpeg" ? "image/jpeg" : ext2 === ".webp" ? "image/webp" : ext2 === ".gif" ? "image/gif" : ext2 === ".bmp" ? "image/bmp" : ext2 === ".svg" ? "image/svg+xml" : ext2 === ".tif" || ext2 === ".tiff" ? "image/tiff" : ext2 === ".heic" ? "image/heic" : ext2 === ".heif" ? "image/heif" : "text/plain";
61958
+ autoAttachments.push({ name: pathMod.basename(abs), path: abs, mime, data_base64: buf.toString("base64") });
61959
+ } catch {
61960
+ }
61961
+ }
61962
+ }
61963
+ } catch {
61964
+ }
61965
+ if (autoAttachments.length > 0) {
61966
+ const existing = new Set(effectiveAttachments.map((a) => (a.path || a.name || "").toLowerCase()));
61967
+ for (const a of autoAttachments) {
61968
+ const key = (a.path || a.name || "").toLowerCase();
61969
+ if (!existing.has(key)) {
61970
+ effectiveAttachments.push(a);
61971
+ existing.add(key);
61972
+ }
61973
+ }
61974
+ }
61975
+ const inlineSection = "";
61358
61976
  const r2 = await callAPI2("/v1/ai-proxy", {
61359
61977
  method: "POST",
61360
- body: { prompt: `${system}
61978
+ body: {
61979
+ // When attachments are present, force an attachments-capable route (mirror /evaluate)
61980
+ ...effectiveAttachments.length ? { provider: "google", model: "gemini-2.5-flash" } : {},
61981
+ prompt: `${system}
61361
61982
 
61362
- ${prompt}`, taskType: "chat" }
61983
+ ${prompt}${inlineSection}`,
61984
+ taskType: "chat",
61985
+ // mirror /evaluate: include attachments in metadata
61986
+ ...effectiveAttachments.length ? { metadata: { attachments: effectiveAttachments } } : {}
61987
+ }
61363
61988
  });
61364
61989
  const apiContent = r2?.data?.content || r2?.content;
61365
61990
  if (apiContent) return apiContent;
@@ -61372,10 +61997,42 @@ ${prompt}`, taskType: "chat" }
61372
61997
  } catch {
61373
61998
  }
61374
61999
  }
61375
- const res = await this.providerManager.complete({
61376
- prompt: `${system}
62000
+ let fallbackPrompt = `${system}
61377
62001
 
61378
- ${prompt}`,
62002
+ ${prompt}`;
62003
+ try {
62004
+ const attList = effectiveAttachments && effectiveAttachments.length ? effectiveAttachments : [];
62005
+ if (attList.length > 0) {
62006
+ const limitBytes = 128 * 1024;
62007
+ let used = 0;
62008
+ const sections = [];
62009
+ for (const a of attList) {
62010
+ if (!a?.data_base64) continue;
62011
+ try {
62012
+ const buf = Buffer.from(a.data_base64, "base64");
62013
+ const text = /^(application\/pdf)/i.test(String(a.mime || "")) ? "" : buf.toString("utf8");
62014
+ if (!text) continue;
62015
+ const remaining = Math.max(0, limitBytes - used);
62016
+ if (remaining <= 0) break;
62017
+ const slice = text.length > remaining ? text.slice(0, remaining) : text;
62018
+ used += Buffer.byteLength(slice, "utf8");
62019
+ sections.push(`[BEGIN file: ${a.path || a.name || "attachment.txt"}]
62020
+ ${slice}
62021
+ [END]`);
62022
+ } catch {
62023
+ }
62024
+ }
62025
+ if (sections.length > 0) {
62026
+ fallbackPrompt = `${fallbackPrompt}
62027
+
62028
+ [ATTACHMENTS]
62029
+ ${sections.join("\n\n")}`;
62030
+ }
62031
+ }
62032
+ } catch {
62033
+ }
62034
+ const res = await this.providerManager.complete({
62035
+ prompt: fallbackPrompt,
61379
62036
  model,
61380
62037
  temperature,
61381
62038
  maxTokens
@@ -75830,7 +76487,7 @@ async function init2() {
75830
76487
  ai = res.ai;
75831
76488
  res.ctx;
75832
76489
  store = res.store;
75833
- while (session.length) session.pop();
76490
+ clearSession();
75834
76491
  for (const m2 of res.session) session.push(m2);
75835
76492
  await loadServices2();
75836
76493
  }
@@ -75847,6 +76504,9 @@ async function streamAnswer(text, opts = {}) {
75847
76504
  s2 = s2.replace(/\[BEGIN\s+file:[^\]]+\][\s\S]*?\[END\]/g, "");
75848
76505
  return s2;
75849
76506
  };
76507
+ const removeAttachmentSections = (s2) => {
76508
+ return s2.replace(/\[ATTACHMENTS\][\s\S]*$/i, "");
76509
+ };
75850
76510
  const hasAnyCodeBlocks = (s2) => /```[\s\S]*?```|\[BEGIN\s+file:/i.test(s2);
75851
76511
  const envInt = (name2, def) => {
75852
76512
  const v = Number(process.env[name2]);
@@ -75872,10 +76532,11 @@ async function streamAnswer(text, opts = {}) {
75872
76532
  model: process.env.MARIA_MODEL || "gemini-2.5-flash"
75873
76533
  });
75874
76534
  animation.stop();
75875
- const containsCode = hasAnyCodeBlocks(resp || "");
75876
- if (containsCode) {
76535
+ const respForArtifactCheck = removeAttachmentSections(resp || "");
76536
+ const containsCode = hasAnyCodeBlocks(respForArtifactCheck);
76537
+ if (containsCode && opts.triage && opts.triage.type === "route-code") {
75877
76538
  try {
75878
- const artifacts = extractAllCodeInfos(resp);
76539
+ const artifacts = extractAllCodeInfos(respForArtifactCheck);
75879
76540
  const savedFiles = [];
75880
76541
  let okCount = 0, warnCount = 0, errCount = 0;
75881
76542
  for (const { language, code, extension, filename: suggested } of artifacts) {
@@ -75900,7 +76561,7 @@ async function streamAnswer(text, opts = {}) {
75900
76561
  console.log(chalk40__default.default.white(`ERROR: failed ${filepath} (${language}) - ${msg2}`));
75901
76562
  }
75902
76563
  }
75903
- const prose = stripMarkdownForPlainChat(removeCodeBlocks(resp)).trim();
76564
+ const prose = stripMarkdownForPlainChat(removeCodeBlocks(removeAttachmentSections(resp))).trim();
75904
76565
  if (prose) {
75905
76566
  console.log(chalk40__default.default.white(""));
75906
76567
  console.log(chalk40__default.default.white("Chat Response:"));
@@ -75985,7 +76646,10 @@ async function handleLine(line, options = {}) {
75985
76646
  locale: process.env.LANG,
75986
76647
  recentCommands: []
75987
76648
  });
75988
- if (triageResult.next?.route) {
76649
+ if (
76650
+ /*false && for debugging*/
76651
+ triageResult.next?.route
76652
+ ) {
75989
76653
  const commandParts = [
75990
76654
  triageResult.next.route,
75991
76655
  ...triageResult.next.args ?? []
@@ -76187,7 +76851,7 @@ MARIA v${getVersion()}
76187
76851
  registerDoctorSubcommand(program2);
76188
76852
  return program2;
76189
76853
  }
76190
- var InteractiveCLI, ai, store, session, commandManager, startupDisplayed, program;
76854
+ var InteractiveCLI, ai, store, commandManager, startupDisplayed, program;
76191
76855
  var init_cli = __esm({
76192
76856
  "src/cli.ts"() {
76193
76857
  init_env_loader();
@@ -76198,6 +76862,7 @@ var init_cli = __esm({
76198
76862
  init_choice_memory();
76199
76863
  init_triage_orchestrator();
76200
76864
  init_handle_slash();
76865
+ init_session_state();
76201
76866
  init_process_handlers();
76202
76867
  init_doctor();
76203
76868
  init_services_loader();
@@ -76205,7 +76870,6 @@ var init_cli = __esm({
76205
76870
  init_interactive_session();
76206
76871
  init_server();
76207
76872
  init_code_utils();
76208
- session = [];
76209
76873
  commandManager = null;
76210
76874
  startupDisplayed = false;
76211
76875
  if (!process.env.GOOGLE_AUTH_DISABLE_GCE_CHECK) {