@bonginkan/maria 4.3.39 → 4.3.40

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
@@ -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.39"}`
1712
+ "User-Agent": `maria-cli/${process.env.CLI_VERSION || "4.3.40"}`
1713
1713
  }
1714
1714
  });
1715
1715
  if (response.status === 401) {
@@ -2434,7 +2434,7 @@ async function callApi(path65, init3 = {}) {
2434
2434
  "Authorization": `Bearer ${token}`,
2435
2435
  "X-Device-Id": getDeviceId(),
2436
2436
  "X-Session-Id": getSessionId() || "",
2437
- "User-Agent": `maria-cli/${process.env.CLI_VERSION || "4.3.39"}`,
2437
+ "User-Agent": `maria-cli/${process.env.CLI_VERSION || "4.3.40"}`,
2438
2438
  "Content-Type": init3.headers?.["Content-Type"] || "application/json"
2439
2439
  });
2440
2440
  const doFetch = async (token) => {
@@ -16382,8 +16382,8 @@ var require_package = __commonJS({
16382
16382
  "package.json"(exports, module) {
16383
16383
  module.exports = {
16384
16384
  name: "@bonginkan/maria",
16385
- version: "4.3.39",
16386
- description: "\u{1F680} MARIA v4.3.39 - 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.",
16385
+ version: "4.3.40",
16386
+ description: "\u{1F680} MARIA v4.3.40 - 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.",
16387
16387
  keywords: [
16388
16388
  "ai",
16389
16389
  "cli",
@@ -26389,7 +26389,7 @@ var init_about_command = __esm({
26389
26389
  async execute(args2, context2) {
26390
26390
  const output3 = [];
26391
26391
  output3.push("");
26392
- output3.push(chalk40__default.default.cyan.bold("\u{1F916} About MARIA v4.3.39"));
26392
+ output3.push(chalk40__default.default.cyan.bold("\u{1F916} About MARIA v4.3.40"));
26393
26393
  output3.push(chalk40__default.default.gray("\u2550".repeat(40)));
26394
26394
  output3.push("");
26395
26395
  output3.push(chalk40__default.default.white.bold("MARIA - Minimal API, Maximum Power"));
@@ -39919,6 +39919,114 @@ function languageFromExt(ext2) {
39919
39919
  if (e2 === "yaml" || e2 === "yml") return "yaml";
39920
39920
  return void 0;
39921
39921
  }
39922
+ async function readHeadTail(root, rel, n) {
39923
+ try {
39924
+ const fs52 = await import('fs/promises');
39925
+ const pathMod = await import('path');
39926
+ const full = pathMod.join(root, rel);
39927
+ const buf = await fs52.readFile(full, "utf8");
39928
+ const lines = buf.split(/\r?\n/);
39929
+ const head2 = lines.slice(0, n).join("\n");
39930
+ const tail = lines.slice(Math.max(0, lines.length - n)).join("\n");
39931
+ return { head: head2, tail };
39932
+ } catch {
39933
+ return { head: "", tail: "" };
39934
+ }
39935
+ }
39936
+ async function llmSelectEditTargets(root, request, repoFiles) {
39937
+ try {
39938
+ const candidates = repoFiles.filter((p) => /\.(html|css|js|ts|tsx)$/i.test(p)).slice(0, 150);
39939
+ const samples = [];
39940
+ for (const p of candidates.slice(0, 60)) {
39941
+ const h2 = await readHeadTail(root, p, 5);
39942
+ samples.push(`- ${p}
39943
+ ${h2.head}`);
39944
+ }
39945
+ const system = [
39946
+ "You select existing repository files that should be EDITED to satisfy a user request.",
39947
+ "Consider path names and the first lines. Return JSON array of repo-relative paths to edit.",
39948
+ "Keep the list short (<= 10). If none are relevant, return []. Do not invent paths."
39949
+ ].join("\n");
39950
+ const user = [`Request: ${request}`, "Candidates:", samples.join("\n\n")].join("\n\n");
39951
+ const resp = await executeChat([
39952
+ { role: "system", content: system },
39953
+ { role: "user", content: user }
39954
+ ]);
39955
+ const raw = (resp?.output || "").trim();
39956
+ const jsonText = (() => {
39957
+ try {
39958
+ const m2 = raw.match(/\[[\s\S]*\]/);
39959
+ return m2 ? m2[0] : raw;
39960
+ } catch {
39961
+ return raw;
39962
+ }
39963
+ })();
39964
+ const arr = JSON.parse(jsonText);
39965
+ const set = new Set(candidates.map((c) => c.toLowerCase()));
39966
+ const out = [];
39967
+ if (Array.isArray(arr)) {
39968
+ for (const v of arr) {
39969
+ if (typeof v === "string" && set.has(v.toLowerCase())) out.push(v);
39970
+ if (out.length >= 10) break;
39971
+ }
39972
+ }
39973
+ return out;
39974
+ } catch {
39975
+ return [];
39976
+ }
39977
+ }
39978
+ async function llmMapBlockToFile(root, request, block, repoFiles) {
39979
+ try {
39980
+ const lang = (block.language || "").toLowerCase();
39981
+ const extFilter = lang.includes("html") ? /\.html$/i : /(ts|tsx)/.test(lang) ? /\.(ts|tsx)$/i : /(js|jsx)/.test(lang) ? /\.(js|jsx)$/i : /\.css$/i;
39982
+ const candidates = repoFiles.filter((p) => extFilter.test(p)).slice(0, 80);
39983
+ const head2 = block.code.split(/\r?\n/).slice(0, 20).join("\n");
39984
+ const samples = [];
39985
+ for (const p of candidates.slice(0, 40)) {
39986
+ const h2 = await readHeadTail(root, p, 8);
39987
+ samples.push(`- ${p}
39988
+ ${h2.head}`);
39989
+ }
39990
+ const system = [
39991
+ "Decide where to apply an EDIT vs CREATE for a code block within an existing repository.",
39992
+ 'Return JSON: { "action": "modify"|"create", "path": string }.',
39993
+ "If modify, path must be one of the candidate repo-relative paths. If create, propose a sensible repo-relative path."
39994
+ ].join("\n");
39995
+ const user = [
39996
+ `Request: ${request}`,
39997
+ "Block:",
39998
+ "```",
39999
+ head2,
40000
+ "```",
40001
+ "Candidates:",
40002
+ samples.join("\n\n")
40003
+ ].join("\n");
40004
+ const resp = await executeChat([
40005
+ { role: "system", content: system },
40006
+ { role: "user", content: user }
40007
+ ]);
40008
+ const raw = (resp?.output || "").trim();
40009
+ const jsonText = (() => {
40010
+ try {
40011
+ const m2 = raw.match(/\{[\s\S]*\}/);
40012
+ return m2 ? m2[0] : raw;
40013
+ } catch {
40014
+ return raw;
40015
+ }
40016
+ })();
40017
+ const parsed = JSON.parse(jsonText);
40018
+ if (parsed && (parsed.action === "modify" || parsed.action === "create") && typeof parsed.path === "string") {
40019
+ return { action: parsed.action, path: parsed.path.replace(/^\/+/, "") };
40020
+ }
40021
+ } catch {
40022
+ }
40023
+ const desired = typeof block.filename === "string" && block.filename.trim() ? block.filename.trim() : null;
40024
+ const fallback2 = desired || suggestName2(request, block.language, 0);
40025
+ return { action: "create", path: fallback2 };
40026
+ }
40027
+ function tokenizeRequest(text) {
40028
+ return Array.from(new Set(text.toLowerCase().replace(/[^a-z0-9_-]+/g, " ").split(/\s+/).filter((t2) => t2.length >= 3)));
40029
+ }
39922
40030
  async function ensureCodeFallbackManager() {
39923
40031
  const policy = await loadFallbackPolicy().catch(() => getDefaultFallbackPolicy());
39924
40032
  const signature = JSON.stringify(policy);
@@ -39964,8 +40072,8 @@ async function orchestrate(request, opts) {
39964
40072
  if (isEditIntent && editTargets.length === 0) {
39965
40073
  try {
39966
40074
  const repoFiles = await getRepoFiles(opts.root);
39967
- const likely = repoFiles.filter((p) => /\.(ts|tsx|js|jsx|html|css|scss|json|md)$/i.test(p));
39968
- editTargets = likely.slice(0, 20);
40075
+ const llmTargets = await llmSelectEditTargets(opts.root, request, repoFiles);
40076
+ editTargets = llmTargets;
39969
40077
  } catch {
39970
40078
  }
39971
40079
  }
@@ -40026,6 +40134,7 @@ ${editContext}`;
40026
40134
  data_base64: f3.content ? Buffer.from(f3.content, "utf8").toString("base64") : void 0
40027
40135
  })).map((a) => a.data_base64 ? a : { ...a, data_base64: void 0 }) : [];
40028
40136
  const pathAttachments = [];
40137
+ const attachedPathSet = /* @__PURE__ */ new Set();
40029
40138
  if (explicitFiles.length > 0) {
40030
40139
  try {
40031
40140
  const fs52 = await import('fs/promises');
@@ -40044,6 +40153,33 @@ ${editContext}`;
40044
40153
  mime,
40045
40154
  data_base64: buf.toString("base64")
40046
40155
  });
40156
+ attachedPathSet.add(full.toLowerCase());
40157
+ } catch {
40158
+ }
40159
+ }
40160
+ } catch {
40161
+ }
40162
+ }
40163
+ if (isEditIntent && Array.isArray(editTargets) && editTargets.length > 0) {
40164
+ try {
40165
+ const fs52 = await import('fs/promises');
40166
+ const pathMod = await import('path');
40167
+ for (const rel of editTargets) {
40168
+ try {
40169
+ const full = pathMod.isAbsolute(rel) ? rel : pathMod.join(opts.root, rel);
40170
+ const key = full.toLowerCase();
40171
+ if (attachedPathSet.has(key)) continue;
40172
+ const stat13 = await fs52.stat(full).catch(() => null);
40173
+ if (!stat13 || !stat13.isFile()) continue;
40174
+ const ext2 = (pathMod.extname(full) || "").toLowerCase();
40175
+ const buf = await fs52.readFile(full);
40176
+ pathAttachments.push({
40177
+ name: pathMod.basename(full),
40178
+ path: full,
40179
+ mime: "text/plain",
40180
+ data_base64: buf.toString("base64")
40181
+ });
40182
+ attachedPathSet.add(key);
40047
40183
  } catch {
40048
40184
  }
40049
40185
  }
@@ -40148,21 +40284,31 @@ ${editContext}`;
40148
40284
  return m2 >= 0 ? f3.slice(m2) : "";
40149
40285
  })();
40150
40286
  const lang = languageFromExt(ext2);
40151
- initial.push({ path: f3, absPath: absMap[f3], noNormalize: true, kind: "source", action: "modify", description: "Edit target", language: lang, preview: "" });
40287
+ const strongMatch = /pong|retro|game|index\.(html)$|script\.(js|ts)$|style\.css/i.test(f3) || tokenizeRequest(request).some((t2) => f3.toLowerCase().includes(t2));
40288
+ if (strongMatch) {
40289
+ initial.push({ path: f3, absPath: absMap[f3], noNormalize: true, kind: "source", action: "modify", description: "Edit target", language: lang, preview: "" });
40290
+ }
40152
40291
  }
40153
40292
  } else {
40154
- for (let i2 = 0; i2 < blocks.length; i2++) {
40155
- const b = blocks[i2];
40156
- const desired = typeof b.filename === "string" && b.filename.trim() ? b.filename.trim() : null;
40157
- const path65 = desired || suggestName2(request, b.language, i2);
40158
- initial.push({
40159
- path: path65,
40160
- kind: "source",
40161
- action: "create",
40162
- description: describe2(b.language, ""),
40163
- language: b.language,
40164
- preview: b.code
40165
- });
40293
+ try {
40294
+ const repoFiles = await getRepoFiles(opts.root);
40295
+ for (let i2 = 0; i2 < blocks.length; i2++) {
40296
+ const b = blocks[i2];
40297
+ const decision = await llmMapBlockToFile(opts.root, request, b, repoFiles);
40298
+ if (decision.action === "modify" && repoFiles.includes(decision.path)) {
40299
+ const lang = languageFromExt(decision.path.replace(/^.*(\.[a-z0-9]+)$/i, "$1"));
40300
+ initial.push({ path: decision.path, kind: "source", action: "modify", description: "Modify existing file", language: lang, preview: b.code });
40301
+ } else {
40302
+ const path65 = decision.path || suggestName2(request, b.language, i2);
40303
+ initial.push({ path: path65, kind: "source", action: "create", description: describe2(b.language, ""), language: b.language, preview: b.code });
40304
+ }
40305
+ }
40306
+ } catch {
40307
+ for (let i2 = 0; i2 < blocks.length; i2++) {
40308
+ const b = blocks[i2];
40309
+ const path65 = suggestName2(request, b.language, i2);
40310
+ initial.push({ path: path65, kind: "source", action: "create", description: describe2(b.language, ""), language: b.language, preview: b.code });
40311
+ }
40166
40312
  }
40167
40313
  }
40168
40314
  }
@@ -40202,6 +40348,9 @@ ${editContext}`;
40202
40348
  } catch {
40203
40349
  p.action = "create";
40204
40350
  }
40351
+ if (p.action === "modify" && (!p.preview || p.preview.length === 0)) {
40352
+ p.action = "skip";
40353
+ }
40205
40354
  }
40206
40355
  } catch {
40207
40356
  }