@kodocagent/cli 0.6.1 → 0.6.3

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/index.js CHANGED
@@ -9739,9 +9739,9 @@ var require_load = __commonJS({
9739
9739
  var require_lib3 = __commonJS({
9740
9740
  "../../node_modules/.pnpm/jszip@3.10.1/node_modules/jszip/lib/index.js"(exports, module) {
9741
9741
  "use strict";
9742
- function JSZip7() {
9743
- if (!(this instanceof JSZip7)) {
9744
- return new JSZip7();
9742
+ function JSZip8() {
9743
+ if (!(this instanceof JSZip8)) {
9744
+ return new JSZip8();
9745
9745
  }
9746
9746
  if (arguments.length) {
9747
9747
  throw new Error("The constructor with parameters has been removed in JSZip 3.0, please check the upgrade guide.");
@@ -9750,7 +9750,7 @@ var require_lib3 = __commonJS({
9750
9750
  this.comment = null;
9751
9751
  this.root = "";
9752
9752
  this.clone = function() {
9753
- var newObj = new JSZip7();
9753
+ var newObj = new JSZip8();
9754
9754
  for (var i in this) {
9755
9755
  if (typeof this[i] !== "function") {
9756
9756
  newObj[i] = this[i];
@@ -9759,16 +9759,16 @@ var require_lib3 = __commonJS({
9759
9759
  return newObj;
9760
9760
  };
9761
9761
  }
9762
- JSZip7.prototype = require_object();
9763
- JSZip7.prototype.loadAsync = require_load();
9764
- JSZip7.support = require_support();
9765
- JSZip7.defaults = require_defaults();
9766
- JSZip7.version = "3.10.1";
9767
- JSZip7.loadAsync = function(content, options) {
9768
- return new JSZip7().loadAsync(content, options);
9762
+ JSZip8.prototype = require_object();
9763
+ JSZip8.prototype.loadAsync = require_load();
9764
+ JSZip8.support = require_support();
9765
+ JSZip8.defaults = require_defaults();
9766
+ JSZip8.version = "3.10.1";
9767
+ JSZip8.loadAsync = function(content, options) {
9768
+ return new JSZip8().loadAsync(content, options);
9769
9769
  };
9770
- JSZip7.external = require_external();
9771
- module.exports = JSZip7;
9770
+ JSZip8.external = require_external();
9771
+ module.exports = JSZip8;
9772
9772
  }
9773
9773
  });
9774
9774
 
@@ -9925,6 +9925,7 @@ function buildSystemPrompt(ctx) {
9925
9925
  ROLE_SECTION,
9926
9926
  DOCUMENT_RULES_SECTION,
9927
9927
  EDIT_SAFETY_SECTION,
9928
+ buildCapabilitiesSection(ctx.toolNames),
9928
9929
  LAW_RULES_SECTION
9929
9930
  ].join("\n\n");
9930
9931
  const dynamic = buildDynamicContext(ctx);
@@ -9961,6 +9962,15 @@ var EDIT_SAFETY_SECTION = `## \uD3B8\uC9D1 \uC548\uC804 \uADDC\uCE59
9961
9962
  6. \uC758\uBBF8\uAC00 \uBC14\uB014 \uC218 \uC788\uB294 \uC218\uC815\uC740 \uC2E4\uD589 \uC804\uC5D0 \uADF8 \uC0AC\uC2E4\uC744 \uC0AC\uC6A9\uC790\uC5D0\uAC8C \uC54C\uB9AC\uACE0, \uC218\uC815 \uC81C\uC548\uC758 \uC694\uC57D(summary)\uC5D0\uB294 \uBB34\uC5C7\uC744\xB7\uC65C \uBC14\uAFB8\uB294\uC9C0 \uD568\uAED8 \uC801\uC2B5\uB2C8\uB2E4.
9962
9963
  7. \uAC1C\uC778\uC815\uBCF4(\uC8FC\uBBFC\uB4F1\uB85D\uBC88\uD638\xB7\uC804\uD654\uBC88\uD638\xB7\uC774\uBA54\uC77C\xB7\uACC4\uC88C\xB7\uCE74\uB4DC\uBC88\uD638 \uB4F1) \uCC98\uB9AC: \uC0AC\uC6A9\uC790\uAC00 **\uD655\uC778\xB7\uC810\uAC80\uB9CC** \uC6D0\uD558\uBA74 \`scan_pii\`(\uC77D\uAE30 \uC804\uC6A9)\uB85C \uBCF4\uC5EC\uC8FC\uACE0, **\uAC00\uB9AC\uAE30\xB7\uB9C8\uC2A4\uD0B9\xB7\uBE44\uC2DD\uBCC4\xB7\uAC1C\uC778\uC815\uBCF4 \uC0AD\uC81C**\uB97C \uC6D0\uD558\uBA74 \`scan_pii\`\uC5D0\uC11C \uBA48\uCD94\uC9C0 \uB9D0\uACE0 \`propose_redact_pii\`\uB85C \uBC14\uB85C \uC218\uC815\uC548\uC744 \uC81C\uC548\uD558\uC138\uC694(\uC774 \uB3C4\uAD6C\uB3C4 \uC2B9\uC778\uC744 \uAC70\uCE58\uBBC0\uB85C \uC548\uC804\uD569\uB2C8\uB2E4).
9963
9964
  8. \uC694\uCCAD\uC774 \uBAA8\uB378\uC774 \uD655\uC2E4\uD788 \uC54C \uC218 \uC5C6\uB294 \uC815\uBCF4\uC5D0 \uC758\uC874\uD558\uBA74(\uD559\uC2B5 \uC2DC\uC810 \uC774\uD6C4\uC758 \uCD5C\uC2E0 \uBC95\uB839\xB7\uAE30\uC900\xB7\uACE0\uC2DC\xB7\uD1B5\uACC4 \uB4F1 \uC2DC\uC810 \uC758\uC874 \uC815\uBCF4, \uB610\uB294 \uBB38\uC11C\uC5D0 \uC5C6\uACE0 \uC0AC\uC6A9\uC790\uAC00 \uC8FC\uC9C0 \uC54A\uC740 \uAE30\uAD00\uBA85\xB7\uC870\uC9C1\uAC1C\uD3B8\xB7\uAE08\uC561 \uB4F1) \uCD94\uCE21\uD574 \uC9C4\uD589\uD558\uC9C0 \uB9D0\uACE0 **\uBB34\uC5C7\uC774 \uD544\uC694\uD55C\uC9C0 \uC0AC\uC6A9\uC790\uC5D0\uAC8C \uBA3C\uC800 \uAD6C\uCCB4\uC801\uC73C\uB85C \uC9C8\uBB38**\uD558\uC138\uC694. \uD604\uD589 \uBC95\uB839\uC740 \`mcp__korean-law__*\`\uB85C, \uADF8 \uC678 \uC124\uC815\uB41C \uAC80\uC0C9 \uB3C4\uAD6C\uAC00 \uC788\uC73C\uBA74 \uADF8 \uB3C4\uAD6C\uB85C \uD655\uC778\uD574 \uCD9C\uCC98\uB97C \uBC1D\uD788\uACE0, \uD655\uC778 \uC218\uB2E8\uC774 \uC5C6\uC73C\uBA74 \uCD94\uC815\uC784\uC744 \uBA85\uC2DC\uD569\uB2C8\uB2E4. \uB418\uBB3C\uC744 \uC218 \uC5C6\uB294 \uBE44\uB300\uD654\uD615(\`-p\`) \uC2E4\uD589\uC5D0\uC120 \uAC00\uC815\uACFC \uBD88\uD655\uC2E4\uC131\uC744 \uACB0\uACFC\uC5D0 \uBA85\uC2DC\uD558\uC138\uC694.`;
9965
+ function buildCapabilitiesSection(toolNames) {
9966
+ const docTools = toolNames.filter((n) => !n.startsWith("mcp__"));
9967
+ const available = docTools.length > 0 ? docTools.map((n) => `\`${n}\``).join(", ") : "(\uC5C6\uC74C)";
9968
+ return `## \uB2A5\uB825\xB7\uD55C\uACC4 (\uD604\uC7AC \uB3C4\uAD6C\uB85C \uAC00\uB2A5\uD55C \uAC83\uACFC \uC544\uB2CC \uAC83)
9969
+
9970
+ \uAC00\uB2A5: **\uC544\uB798 \uB4F1\uB85D\uB41C \uB3C4\uAD6C\uAC00 \uB108\uC758 \uB2A5\uB825 \uC804\uBD80\uB2E4**(\uB808\uC9C0\uC2A4\uD2B8\uB9AC\uC5D0\uC11C \uC790\uB3D9 \uBC18\uC601) \u2014 ${available}. \uC5F0\uACB0\uB41C MCP \uB3C4\uAD6C\uAC00 \uC788\uC73C\uBA74 \uD568\uAED8 \uC0AC\uC6A9\uD558\uC138\uC694(\uC544\uB798 \uCEE8\uD14D\uC2A4\uD2B8 \uCC38\uC870).
9971
+ \uD604\uC7AC \uBD88\uAC00(\uC694\uCCAD\uBC1B\uC73C\uBA74 \uC194\uC9C1\uD788 \uC54C\uB9B4 \uAC83): \uC704 \uB3C4\uAD6C\uB85C \uCC98\uB9AC\uD560 \uC218 \uC5C6\uB294 \uC791\uC5C5 \u2014 \uAE00\uAF34\xB7\uAD75\uAC8C\xB7\uC904\uAC04\uACA9 \uB4F1 \uBB38\uC790/\uBB38\uB2E8 \uC11C\uC2DD\uACFC \uC81C\uBAA9 \uC2A4\uD0C0\uC77C \uC77C\uAD00\uD654, \uBA38\uB9AC\uB9D0/\uAF2C\uB9AC\uB9D0\xB7\uCABD\uBC88\uD638 \uB808\uC774\uC544\uC6C3/\uC11C\uC2DD, \uAC01\uC8FC \uC0BD\uC785\xB7\uD615\uC2DD, \uBAA9\uCC28\xB7\uAC1C\uC694\uBC88\uD638 \uC790\uB3D9 \uAC31\uC2E0, \uADF8\uB9BC\xB7\uD45C \uBC88\uD638 \uC0C1\uD638\uCC38\uC870, \uC774\uBBF8\uC9C0\xB7\uB3C4\uD615\xB7\uC870\uC9C1\uB3C4 \uD3B8\uC9D1, \uC911\uCCA9(\uBCF5\uD569)\uD45C \uC548\uCABD \uC140 \uC9C0\uC815.
9972
+ \uBCF5\uC7A1\uD558\uAC70\uB098 \uC5EC\uB7EC \uC791\uC5C5\uC774 \uC11E\uC778 \uC694\uCCAD\uC740 \uBA3C\uC800 \uBB34\uC5C7\uC744 \uC5B4\uB5A4 \uB3C4\uAD6C\uB85C \uD560\uC9C0 \uAC04\uB2E8\uD788 \uC815\uB9AC\uD558\uACE0, \uC704 \uB3C4\uAD6C\uB85C \uC548 \uB418\uB294 \uBD80\uBD84\uC774 \uC788\uC73C\uBA74 **\uCD94\uCE21\uD574 \uC5B4\uC124\uD504\uAC8C \uC2DC\uB3C4\uD558\uC9C0 \uB9D0\uACE0 \uADF8 \uC0AC\uC2E4\uC744 \uBA3C\uC800 \uC54C\uB9B0 \uB4A4** \uAC00\uB2A5\uD55C \uBD80\uBD84\uB9CC \uC9C4\uD589\uD558\uAC70\uB098 \uB300\uC548\uC744 \uC548\uB0B4\uD558\uC138\uC694. \uB2E8\uC21C\xB7\uB2E8\uC77C \uC694\uCCAD\uC740 \uACE7\uBC14\uB85C \uC9C4\uD589\uD569\uB2C8\uB2E4.`;
9973
+ }
9964
9974
  var LAW_RULES_SECTION = `## \uBC95\uB839 \uADDC\uCE59
9965
9975
 
9966
9976
  1. \uBC95\uB839 \uC778\uC6A9 \uD615\uC2DD: \u300C\uBC95\uB839\uBA85\u300D \uC81CN\uC870 \uC81CN\uD56D \uC81CN\uD638
@@ -10129,7 +10139,8 @@ var AgentSession = class {
10129
10139
  const system = buildSystemPrompt({
10130
10140
  cwd: this.opts.cwd,
10131
10141
  mcpServers: this.opts.mcpServers ?? [],
10132
- openDocuments: this.openDocuments
10142
+ openDocuments: this.openDocuments,
10143
+ toolNames: tools.toolNames
10133
10144
  });
10134
10145
  const aiSdkTools = tools.toAiSdkTools();
10135
10146
  this.messages = compactMessages(this.messages, config.maxContextTokens);
@@ -10932,6 +10943,7 @@ var import_jszip = __toESM(require_lib3(), 1);
10932
10943
  var import_jszip2 = __toESM(require_lib3(), 1);
10933
10944
  var import_jszip3 = __toESM(require_lib3(), 1);
10934
10945
  var import_jszip4 = __toESM(require_lib3(), 1);
10946
+ var import_jszip5 = __toESM(require_lib3(), 1);
10935
10947
  import { z as z3 } from "zod";
10936
10948
  import { readFile as readFile32 } from "fs/promises";
10937
10949
  import { blocksToMarkdown, compare } from "kordoc";
@@ -10948,10 +10960,12 @@ import { z as z5 } from "zod";
10948
10960
  import { readdir as readdir3, stat as stat3 } from "fs/promises";
10949
10961
  import { extname as extname6, join as join4, relative as relative2 } from "path";
10950
10962
  import { z as z6 } from "zod";
10951
- import { readFile as readFile7 } from "fs/promises";
10963
+ import { readFile as readFile8 } from "fs/promises";
10952
10964
  import { extname as extname7 } from "path";
10953
- import { compare as compare2, parse, patchHwp, patchHwpx } from "kordoc";
10965
+ import { compare as compare2, patchHwp, patchHwpx } from "kordoc";
10954
10966
  import { z as z7 } from "zod";
10967
+ import { readFile as readFile7 } from "fs/promises";
10968
+ import { parse as kordocParse } from "kordoc";
10955
10969
  import {
10956
10970
  Document,
10957
10971
  HeadingLevel,
@@ -10963,36 +10977,32 @@ import {
10963
10977
  TextRun,
10964
10978
  WidthType
10965
10979
  } from "docx";
10966
- import { readFile as readFile8 } from "fs/promises";
10980
+ import { readFile as readFile9 } from "fs/promises";
10967
10981
  import { extname as extname8 } from "path";
10968
- import { parse as parse2 } from "kordoc";
10969
10982
  import { z as z8 } from "zod";
10970
- import { readFile as readFile9 } from "fs/promises";
10983
+ import { readFile as readFile10 } from "fs/promises";
10971
10984
  import { extname as extname9 } from "path";
10972
- import { extractFormFields, parse as parse3, patchHwpx as patchHwpx2 } from "kordoc";
10985
+ import { extractFormFields, fillHwpx } from "kordoc";
10973
10986
  import { z as z9 } from "zod";
10974
- import { readFile as readFile10 } from "fs/promises";
10987
+ import { readFile as readFile11 } from "fs/promises";
10975
10988
  import { basename as basename4, extname as extname10 } from "path";
10976
- var import_jszip5 = __toESM(require_lib3(), 1);
10977
10989
  var import_jszip6 = __toESM(require_lib3(), 1);
10990
+ var import_jszip7 = __toESM(require_lib3(), 1);
10978
10991
  import { z as z10 } from "zod";
10979
- import { readFile as readFile11 } from "fs/promises";
10992
+ import { readFile as readFile12 } from "fs/promises";
10980
10993
  import { extname as extname11 } from "path";
10981
10994
  import ExcelJS from "exceljs";
10982
10995
  import { z as z11 } from "zod";
10983
- import { readFile as readFile12 } from "fs/promises";
10996
+ import { readFile as readFile13 } from "fs/promises";
10984
10997
  import { extname as extname12 } from "path";
10985
- import { parse as parse4 } from "kordoc";
10986
10998
  import { z as z12 } from "zod";
10987
- import { readFile as readFile13, stat as stat4 } from "fs/promises";
10999
+ import { readFile as readFile14, stat as stat4 } from "fs/promises";
10988
11000
  import { extname as extname13 } from "path";
10989
- import { parse as parse5 } from "kordoc";
10990
11001
  import { z as z13 } from "zod";
10991
11002
  import { readFile as fsReadFile, stat as stat5 } from "fs/promises";
10992
11003
  import { z as z14 } from "zod";
10993
- import { readFile as readFile14 } from "fs/promises";
11004
+ import { readFile as readFile15 } from "fs/promises";
10994
11005
  import { extname as extname14 } from "path";
10995
- import { parse as parse6 } from "kordoc";
10996
11006
  import { z as z15 } from "zod";
10997
11007
  import { stat as stat6 } from "fs/promises";
10998
11008
  import { extname as extname15 } from "path";
@@ -12986,6 +12996,146 @@ var listFilesTool = {
12986
12996
  return lines.join("\n") + truncateNotice;
12987
12997
  }
12988
12998
  };
12999
+ var SHAPE_ALT_KEYWORDS = [
13000
+ "\uC0AC\uAC01\uD615",
13001
+ "\uC9C1\uC0AC\uAC01\uD615",
13002
+ "\uC815\uC0AC\uAC01\uD615",
13003
+ "\uC6D0",
13004
+ "\uD0C0\uC6D0",
13005
+ "\uC0BC\uAC01\uD615",
13006
+ "\uC774\uB4F1\uBCC0 \uC0BC\uAC01\uD615",
13007
+ "\uC9C1\uAC01 \uC0BC\uAC01\uD615",
13008
+ "\uC120",
13009
+ "\uC9C1\uC120",
13010
+ "\uACE1\uC120",
13011
+ "\uD654\uC0B4\uD45C",
13012
+ "\uAD75\uC740 \uD654\uC0B4\uD45C",
13013
+ "\uC774\uC911 \uD654\uC0B4\uD45C",
13014
+ "\uC624\uAC01\uD615",
13015
+ "\uC721\uAC01\uD615",
13016
+ "\uD314\uAC01\uD615",
13017
+ "\uBCC4",
13018
+ "[4-8]\uC810\uBCC4",
13019
+ "\uC2ED\uC790",
13020
+ "\uC2ED\uC790\uD615",
13021
+ "\uAD6C\uB984",
13022
+ "\uAD6C\uB984\uD615",
13023
+ "\uB9C8\uB984\uBAA8",
13024
+ "\uB3C4\uB11B",
13025
+ "\uD3C9\uD589\uC0AC\uBCC0\uD615",
13026
+ "\uC0AC\uB2E4\uB9AC\uAF34",
13027
+ "\uBD80\uCC44\uAF34",
13028
+ "\uD638",
13029
+ "\uBC18\uC6D0",
13030
+ "\uBB3C\uACB0",
13031
+ "\uBC88\uAC1C",
13032
+ "\uD558\uD2B8",
13033
+ "\uBE57\uAE08",
13034
+ "\uBE14\uB85D \uD654\uC0B4\uD45C",
13035
+ "\uC218\uC2DD",
13036
+ "\uD45C",
13037
+ "\uADF8\uB9BC",
13038
+ "\uAC1C\uCCB4",
13039
+ "\uADF8\uB9AC\uAE30\\s?\uAC1C\uCCB4",
13040
+ "\uBB36\uC74C\\s?\uAC1C\uCCB4",
13041
+ "\uAE00\uC0C1\uC790",
13042
+ "\uC218\uC2DD\\s?\uAC1C\uCCB4",
13043
+ "OLE\\s?\uAC1C\uCCB4"
13044
+ ].join("|");
13045
+ var BUGGY_SHAPE_STRIP = new RegExp(
13046
+ `(?:\uBAA8\uC11C\uB9AC\uAC00 \uB465\uADFC |\uB465\uADFC )?(?:${SHAPE_ALT_KEYWORDS})\\s?\uC785\uB2C8\uB2E4\\.?`,
13047
+ "g"
13048
+ );
13049
+ var FIXED_SHAPE_STRIP = new RegExp(
13050
+ `(?<![\uAC00-\uD7A3])(?:\uBAA8\uC11C\uB9AC\uAC00 \uB465\uADFC |\uB465\uADFC )?(?:${SHAPE_ALT_KEYWORDS})\\s?\uC785\uB2C8\uB2E4\\.?`,
13051
+ "g"
13052
+ );
13053
+ function applyStrip(raw, re) {
13054
+ const normalized = raw.replace(/[ \t]+/g, " ").trim();
13055
+ return normalized.replace(re, "").trim();
13056
+ }
13057
+ function decodeXmlEntities(s) {
13058
+ return s.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&apos;/g, "'").replace(/&#x([0-9a-fA-F]+);/g, (_, h) => String.fromCodePoint(Number.parseInt(h, 16))).replace(/&#(\d+);/g, (_, d) => String.fromCodePoint(Number.parseInt(d, 10))).replace(/&amp;/g, "&");
13059
+ }
13060
+ async function extractHwpxParagraphTexts(bytes) {
13061
+ const zip = await import_jszip4.default.loadAsync(bytes);
13062
+ const out = [];
13063
+ for (const name of Object.keys(zip.files)) {
13064
+ if (!/^Contents\/section\d*\.xml$/i.test(name)) continue;
13065
+ const entry = zip.files[name];
13066
+ if (!entry) continue;
13067
+ const xml = await entry.async("string");
13068
+ for (const seg of xml.split(/(?=<hp:p\b)/)) {
13069
+ let para = "";
13070
+ for (const m of seg.matchAll(/<hp:t(?:\s[^>]*)?>([\s\S]*?)<\/hp:t>/g)) {
13071
+ para += decodeXmlEntities((m[1] ?? "").replace(/<[^>]+>/g, ""));
13072
+ }
13073
+ if (para.trim()) out.push(para);
13074
+ }
13075
+ }
13076
+ return out;
13077
+ }
13078
+ function splitDecoration(line) {
13079
+ const m = line.match(/^(\s*(?:#{1,6}\s+|[-*+]\s+|\d+\.\s+|>\s+)?)([\s\S]*)$/);
13080
+ if (!m) return { prefix: "", content: line };
13081
+ return { prefix: m[1] ?? "", content: m[2] ?? "" };
13082
+ }
13083
+ function restoreOverStrippedShapeText(markdown, paragraphTexts) {
13084
+ const lines = markdown.split("\n");
13085
+ const used = /* @__PURE__ */ new Set();
13086
+ let changed = false;
13087
+ for (const raw of paragraphTexts) {
13088
+ const buggy = applyStrip(raw, BUGGY_SHAPE_STRIP);
13089
+ const fixed = applyStrip(raw, FIXED_SHAPE_STRIP);
13090
+ if (buggy === fixed) continue;
13091
+ if (!fixed) continue;
13092
+ if (!buggy) continue;
13093
+ for (let i = 0; i < lines.length; i++) {
13094
+ if (used.has(i)) continue;
13095
+ const { prefix, content } = splitDecoration(lines[i] ?? "");
13096
+ if (content.trim() === buggy && content.trim() !== fixed) {
13097
+ lines[i] = prefix + fixed;
13098
+ used.add(i);
13099
+ changed = true;
13100
+ break;
13101
+ }
13102
+ }
13103
+ }
13104
+ return changed ? lines.join("\n") : markdown;
13105
+ }
13106
+ function isZip(bytes) {
13107
+ return bytes.length >= 4 && bytes[0] === 80 && bytes[1] === 75;
13108
+ }
13109
+ async function resolveHwpxBytes(input) {
13110
+ try {
13111
+ if (typeof input === "string") {
13112
+ if (!/\.hwpx$/i.test(input)) return null;
13113
+ return new Uint8Array(await readFile7(input));
13114
+ }
13115
+ const u8 = input instanceof Uint8Array ? input : new Uint8Array(input instanceof ArrayBuffer ? input : input);
13116
+ return isZip(u8) ? u8 : null;
13117
+ } catch {
13118
+ return null;
13119
+ }
13120
+ }
13121
+ async function parse(input, options) {
13122
+ const result = await kordocParse(input, options);
13123
+ if (!result.success || typeof result.markdown !== "string" || !result.markdown) {
13124
+ return result;
13125
+ }
13126
+ const bytes = await resolveHwpxBytes(input);
13127
+ if (!bytes) return result;
13128
+ try {
13129
+ const paragraphTexts = await extractHwpxParagraphTexts(bytes);
13130
+ if (paragraphTexts.length === 0) return result;
13131
+ const repaired = restoreOverStrippedShapeText(result.markdown, paragraphTexts);
13132
+ if (repaired !== result.markdown) {
13133
+ return { ...result, markdown: repaired };
13134
+ }
13135
+ } catch {
13136
+ }
13137
+ return result;
13138
+ }
12989
13139
  var HEADING_LEVELS = {
12990
13140
  1: HeadingLevel.HEADING_1,
12991
13141
  2: HeadingLevel.HEADING_2,
@@ -13126,7 +13276,7 @@ var proposeEditTool = {
13126
13276
  const ext = extname7(safePath).toLowerCase();
13127
13277
  let originalBuffer;
13128
13278
  try {
13129
- originalBuffer = await readFile7(safePath);
13279
+ originalBuffer = await readFile8(safePath);
13130
13280
  } catch {
13131
13281
  return `\uC624\uB958: \uD30C\uC77C\uC744 \uC77D\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4: ${input.path}. \uACBD\uB85C\uB97C \uD655\uC778\uD558\uAC70\uB098 read_document\uB85C \uBA3C\uC800 \uD655\uC778\uD558\uC138\uC694.`;
13132
13282
  }
@@ -13323,7 +13473,7 @@ function countOccurrences(str, sub) {
13323
13473
  return count;
13324
13474
  }
13325
13475
  async function applyFindReplaceToHwpx(hwpxBuffer, find, replace, caseSensitive, replaceAll) {
13326
- const zip = await import_jszip4.default.loadAsync(hwpxBuffer);
13476
+ const zip = await import_jszip5.default.loadAsync(hwpxBuffer);
13327
13477
  const sectionFiles = Object.keys(zip.files).filter((name) => /^Contents\/section\d+\.xml$/.test(name)).sort();
13328
13478
  const sectionXmls = [];
13329
13479
  for (const sf of sectionFiles) {
@@ -13367,7 +13517,7 @@ async function applyFindReplaceToHwpx(hwpxBuffer, find, replace, caseSensitive,
13367
13517
  samples.push(snip);
13368
13518
  }
13369
13519
  }
13370
- const out = new import_jszip4.default();
13520
+ const out = new import_jszip5.default();
13371
13521
  const mimetypeEntry = zip.file("mimetype");
13372
13522
  if (mimetypeEntry) {
13373
13523
  out.file("mimetype", await mimetypeEntry.async("uint8array"), { compression: "STORE" });
@@ -13404,7 +13554,7 @@ var proposeFindReplaceTool = {
13404
13554
  }
13405
13555
  let originalBuf;
13406
13556
  try {
13407
- originalBuf = await readFile8(safePath);
13557
+ originalBuf = await readFile9(safePath);
13408
13558
  } catch {
13409
13559
  return `\uC624\uB958: \uD30C\uC77C\uC744 \uC77D\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4: ${input.path}. \uACBD\uB85C\uB97C \uD655\uC778\uD558\uC138\uC694.`;
13410
13560
  }
@@ -13443,7 +13593,7 @@ var proposeFindReplaceTool = {
13443
13593
  }
13444
13594
  const warnings = [];
13445
13595
  try {
13446
- const exportedResult = await parse2(newBytes.buffer);
13596
+ const exportedResult = await parse(newBytes.buffer);
13447
13597
  if (exportedResult.success) {
13448
13598
  const exportedMd = exportedResult.markdown;
13449
13599
  const normAfter = input.caseSensitive ?? false ? exportedMd : exportedMd.toLowerCase();
@@ -13522,7 +13672,7 @@ var proposeFormFillTool = {
13522
13672
  }
13523
13673
  let originalBuffer;
13524
13674
  try {
13525
- originalBuffer = await readFile9(safePath);
13675
+ originalBuffer = await readFile10(safePath);
13526
13676
  } catch {
13527
13677
  return `\uC624\uB958: \uD30C\uC77C\uC744 \uC77D\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4: ${input.path}. \uACBD\uB85C\uB97C \uD655\uC778\uD558\uC138\uC694.`;
13528
13678
  }
@@ -13533,7 +13683,7 @@ var proposeFormFillTool = {
13533
13683
  if (structuralGuard !== null) {
13534
13684
  return structuralGuard;
13535
13685
  }
13536
- const parseResult = await parse3(originalBuffer.buffer);
13686
+ const parseResult = await parse(originalBuffer.buffer);
13537
13687
  if (!parseResult.success) {
13538
13688
  const msg = kordocErrorMessage(
13539
13689
  parseResult.code,
@@ -13543,40 +13693,31 @@ var proposeFormFillTool = {
13543
13693
  }
13544
13694
  const formResult = extractFormFields(parseResult.blocks);
13545
13695
  const existingFields = new Map(formResult.fields.map((f) => [f.label, f.value]));
13546
- const unknownLabels = Object.keys(input.fields).filter((label) => !existingFields.has(label));
13547
13696
  const warnings = [];
13548
- if (unknownLabels.length > 0) {
13549
- warnings.push(
13550
- `\uB2E4\uC74C \uB77C\uBCA8\uC744 \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4: ${unknownLabels.join(", ")}. read_document\uB85C \uD604\uC7AC \uD544\uB4DC \uBAA9\uB85D\uC744 \uD655\uC778\uD558\uC138\uC694.`
13551
- );
13552
- }
13553
- let newMarkdown = parseResult.markdown;
13554
13697
  const diffLines = ["| \uB77C\uBCA8 | \uC774\uC804 \uAC12 | \uC0C8 \uAC12 |", "| --- | --- | --- |"];
13555
13698
  for (const [label, newValue] of Object.entries(input.fields)) {
13556
13699
  const oldValue = existingFields.get(label) ?? "(\uC5C6\uC74C)";
13557
13700
  diffLines.push(`| ${label} | ${oldValue} | ${newValue} |`);
13558
- const escapedLabel = label.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
13559
- const escapedOld = oldValue.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
13560
- if (oldValue !== "(\uC5C6\uC74C)") {
13561
- newMarkdown = newMarkdown.replace(
13562
- new RegExp(`(\\|\\s*${escapedLabel}\\s*\\|\\s*)${escapedOld}(\\s*\\|)`, "g"),
13563
- `$1${newValue}$2`
13564
- );
13565
- }
13566
13701
  }
13567
13702
  const diff = diffLines.join("\n");
13568
- const origU8 = new Uint8Array(
13569
- originalBuffer.buffer,
13703
+ const origAB = originalBuffer.buffer.slice(
13570
13704
  originalBuffer.byteOffset,
13571
- originalBuffer.byteLength
13705
+ originalBuffer.byteOffset + originalBuffer.byteLength
13572
13706
  );
13573
- const patchResult = await patchHwpx2(origU8, newMarkdown);
13574
- if (!patchResult.success || !patchResult.data) {
13575
- return `\uC624\uB958: \uC591\uC2DD \uCC44\uC6B0\uAE30\uB97C \uC801\uC6A9\uD558\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4: ${patchResult.error ?? "\uC54C \uC218 \uC5C6\uB294 \uC624\uB958"}.`;
13576
- }
13577
- const stagedData = patchResult.data;
13578
- for (const s of patchResult.skipped) {
13579
- warnings.push(`\uC77C\uBD80 \uD56D\uBAA9\uC774 \uC801\uC6A9\uB418\uC9C0 \uC54A\uC558\uC2B5\uB2C8\uB2E4(${s.reason ?? "\uC0AC\uC720 \uBBF8\uC0C1"}).`);
13707
+ let stagedData;
13708
+ try {
13709
+ const fillResult = await fillHwpx(origAB, input.fields);
13710
+ if (fillResult.unmatched.length > 0) {
13711
+ warnings.push(
13712
+ `\uB2E4\uC74C \uB77C\uBCA8\uC744 \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4: ${fillResult.unmatched.join(", ")}. read_document\uB85C \uD604\uC7AC \uD544\uB4DC \uBAA9\uB85D\uC744 \uD655\uC778\uD558\uC138\uC694.`
13713
+ );
13714
+ }
13715
+ if (fillResult.filled.length === 0) {
13716
+ return `\uC624\uB958: \uCC44\uC6CC\uC9C4 \uC591\uC2DD \uD544\uB4DC\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4. \uB77C\uBCA8\uC774 \uBB38\uC11C\uC640 \uC77C\uCE58\uD558\uB294\uC9C0 read_document\uB85C \uD655\uC778\uD558\uC138\uC694${fillResult.unmatched.length > 0 ? ` (\uBBF8\uB9E4\uCE6D: ${fillResult.unmatched.join(", ")})` : ""}.`;
13717
+ }
13718
+ stagedData = new Uint8Array(fillResult.buffer);
13719
+ } catch (err) {
13720
+ return `\uC624\uB958: \uC591\uC2DD \uCC44\uC6B0\uAE30\uB97C \uC801\uC6A9\uD558\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4: ${err instanceof Error ? err.message : String(err)}.`;
13580
13721
  }
13581
13722
  const { outputPath, willConvertFormat } = resolveOutputPath(safePath);
13582
13723
  const stagedPath = await stageFile(ctx.sessionId, safePath, stagedData);
@@ -13625,7 +13766,7 @@ function mergeFindings(allFindings) {
13625
13766
  return [...map.values()];
13626
13767
  }
13627
13768
  async function applyRedactToHwpx(hwpxBuffer) {
13628
- const zip = await import_jszip5.default.loadAsync(hwpxBuffer);
13769
+ const zip = await import_jszip6.default.loadAsync(hwpxBuffer);
13629
13770
  const sectionFiles = Object.keys(zip.files).filter((name) => /^Contents\/section\d+\.xml$/.test(name)).sort();
13630
13771
  const sectionXmls = [];
13631
13772
  for (const sf of sectionFiles) {
@@ -13668,7 +13809,7 @@ async function applyRedactToHwpx(hwpxBuffer) {
13668
13809
  if (!anyChanged) {
13669
13810
  return { buffer: hwpxBuffer, findings: mergeFindings(allFindings), changed: false };
13670
13811
  }
13671
- const out = new import_jszip5.default();
13812
+ const out = new import_jszip6.default();
13672
13813
  const mimetypeEntry = zip.file("mimetype");
13673
13814
  if (mimetypeEntry) {
13674
13815
  out.file("mimetype", await mimetypeEntry.async("uint8array"), { compression: "STORE" });
@@ -13717,7 +13858,7 @@ var proposeRedactPiiTool = {
13717
13858
  if (ext === ".hwpx" || ext === ".hwp") {
13718
13859
  let originalBuf;
13719
13860
  try {
13720
- originalBuf = await readFile10(safePath);
13861
+ originalBuf = await readFile11(safePath);
13721
13862
  } catch {
13722
13863
  return `\uC624\uB958: \uD30C\uC77C\uC744 \uC77D\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4: ${input.path}`;
13723
13864
  }
@@ -13769,7 +13910,7 @@ var proposeRedactPiiTool = {
13769
13910
  }
13770
13911
  let originalText;
13771
13912
  try {
13772
- originalText = await readFile10(safePath, "utf-8");
13913
+ originalText = await readFile11(safePath, "utf-8");
13773
13914
  } catch {
13774
13915
  return `\uC624\uB958: \uD30C\uC77C\uC744 \uC77D\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4: ${input.path}`;
13775
13916
  }
@@ -13829,7 +13970,7 @@ var proposeSheetEditTool = {
13829
13970
  }
13830
13971
  let originalBuffer;
13831
13972
  try {
13832
- originalBuffer = await readFile11(safePath);
13973
+ originalBuffer = await readFile12(safePath);
13833
13974
  } catch {
13834
13975
  return `\uC624\uB958: \uD30C\uC77C\uC744 \uC77D\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4: ${input.path}. \uACBD\uB85C\uB97C \uD655\uC778\uD558\uC138\uC694.`;
13835
13976
  }
@@ -14519,7 +14660,7 @@ function getTblDims(tblXml) {
14519
14660
  return parseTblDimensions(tblXml, 0);
14520
14661
  }
14521
14662
  async function applyOpsToHwpx(hwpxBuffer, anchor, operations) {
14522
- const zip = await import_jszip6.default.loadAsync(hwpxBuffer);
14663
+ const zip = await import_jszip7.default.loadAsync(hwpxBuffer);
14523
14664
  const sectionFiles = Object.keys(zip.files).filter((name) => /^Contents\/section\d+\.xml$/.test(name)).sort();
14524
14665
  let targetSectionIdx = -1;
14525
14666
  let targetRange = null;
@@ -14578,7 +14719,7 @@ async function applyOpsToHwpx(hwpxBuffer, anchor, operations) {
14578
14719
  const afterDims = getTblDims(tblBlock);
14579
14720
  const newSectionXml = sectionXml.substring(0, targetRange.start) + tblBlock + sectionXml.substring(targetRange.end);
14580
14721
  sectionXmls[targetSectionIdx] = newSectionXml;
14581
- const out = new import_jszip6.default();
14722
+ const out = new import_jszip7.default();
14582
14723
  const mimetypeEntry = zip.file("mimetype");
14583
14724
  if (mimetypeEntry) {
14584
14725
  out.file("mimetype", await mimetypeEntry.async("uint8array"), { compression: "STORE" });
@@ -14602,7 +14743,7 @@ async function applyOpsToHwpx(hwpxBuffer, anchor, operations) {
14602
14743
  };
14603
14744
  }
14604
14745
  async function verifyOutputDims(newBytes, anchor, expectedRowCnt, expectedColCnt) {
14605
- const zip = await import_jszip6.default.loadAsync(newBytes);
14746
+ const zip = await import_jszip7.default.loadAsync(newBytes);
14606
14747
  const sectionFiles = Object.keys(zip.files).filter((name) => /^Contents\/section\d+\.xml$/.test(name)).sort();
14607
14748
  for (const sf of sectionFiles) {
14608
14749
  const entry = zip.file(sf);
@@ -14643,7 +14784,7 @@ var proposeTableStructureTool = {
14643
14784
  }
14644
14785
  let originalBuf;
14645
14786
  try {
14646
- originalBuf = await readFile12(safePath);
14787
+ originalBuf = await readFile13(safePath);
14647
14788
  } catch {
14648
14789
  return `\uC624\uB958: \uD30C\uC77C\uC744 \uC77D\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4: ${input.path}. \uACBD\uB85C\uB97C \uD655\uC778\uD558\uC138\uC694.`;
14649
14790
  }
@@ -14661,7 +14802,7 @@ var proposeTableStructureTool = {
14661
14802
  }
14662
14803
  let originalBlocks = null;
14663
14804
  try {
14664
- const origResult = await parse4(originalBuf.buffer);
14805
+ const origResult = await parse(originalBuf.buffer);
14665
14806
  if (origResult.success) {
14666
14807
  originalBlocks = origResult.blocks;
14667
14808
  }
@@ -14682,7 +14823,7 @@ var proposeTableStructureTool = {
14682
14823
  let kordocOk = false;
14683
14824
  let exportedBlocks = null;
14684
14825
  try {
14685
- const exportedResult = await parse4(newBytes.buffer);
14826
+ const exportedResult = await parse(newBytes.buffer);
14686
14827
  if (exportedResult.success) {
14687
14828
  exportedMd = exportedResult.markdown;
14688
14829
  exportedBlocks = exportedResult.blocks;
@@ -14880,7 +15021,7 @@ var readDocumentTool = {
14880
15021
  if (PLAIN_TEXT_EXTS.has(ext)) {
14881
15022
  let raw;
14882
15023
  try {
14883
- raw = await readFile13(safePath, "utf-8");
15024
+ raw = await readFile14(safePath, "utf-8");
14884
15025
  } catch (e) {
14885
15026
  const msg = e instanceof Error ? e.message : String(e);
14886
15027
  return `\uC624\uB958: \uD30C\uC77C\uC744 \uC77D\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4: ${msg}`;
@@ -14904,7 +15045,7 @@ var readDocumentTool = {
14904
15045
  \u26A0\uFE0F \uB0B4\uC6A9\uC774 \uB108\uBB34 \uAE38\uC5B4 \uC57D 80,000\uC790\uC5D0\uC11C \uC798\uB838\uC2B5\uB2C8\uB2E4. (\uD3C9\uBB38 \uD14D\uC2A4\uD2B8 \uD30C\uC77C\uC774\uB77C \uD398\uC774\uC9C0 \uB2E8\uC704 \uBD84\uD560 \uC77D\uAE30\uB294 \uC9C0\uC6D0\uB418\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4)` : "";
14905
15046
  return `${meta2}${body2}${truncationNotice2}`;
14906
15047
  }
14907
- const result = await parse5(safePath, input.pages ? { pages: input.pages } : void 0);
15048
+ const result = await parse(safePath, input.pages ? { pages: input.pages } : void 0);
14908
15049
  if (!result.success) {
14909
15050
  const msg = kordocErrorMessage(result.code, `\uBB38\uC11C\uB97C \uC77D\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4: ${result.error}`);
14910
15051
  return `\uC624\uB958: ${msg}`;
@@ -15044,7 +15185,7 @@ var scanPiiTool = {
15044
15185
  let text3;
15045
15186
  if (PLAIN_TEXT_EXTS2.has(ext)) {
15046
15187
  try {
15047
- text3 = await readFile14(safePath, "utf-8");
15188
+ text3 = await readFile15(safePath, "utf-8");
15048
15189
  } catch (e) {
15049
15190
  const msg = e instanceof Error ? e.message : String(e);
15050
15191
  return `\uC624\uB958: \uD30C\uC77C\uC744 \uC77D\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4: ${msg}`;
@@ -15052,7 +15193,7 @@ var scanPiiTool = {
15052
15193
  } else {
15053
15194
  let parseResult;
15054
15195
  try {
15055
- parseResult = await parse6(safePath);
15196
+ parseResult = await parse(safePath);
15056
15197
  } catch (e) {
15057
15198
  const msg = e instanceof Error ? e.message : String(e);
15058
15199
  return `\uC624\uB958: \uBB38\uC11C\uB97C \uD30C\uC2F1\uD560 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4: ${msg}`;
@@ -16042,10 +16183,10 @@ async function runOnboarding() {
16042
16183
 
16043
16184
  // src/update.ts
16044
16185
  import { spawn } from "child_process";
16045
- import { mkdir as mkdir4, readFile as readFile15, writeFile as writeFile3 } from "fs/promises";
16186
+ import { mkdir as mkdir4, readFile as readFile16, writeFile as writeFile3 } from "fs/promises";
16046
16187
  import { dirname as dirname3 } from "path";
16047
16188
  function compareSemver(a, b) {
16048
- const parse7 = (v) => {
16189
+ const parse2 = (v) => {
16049
16190
  const clean = v.replace(/^v/, "").split("-")[0] ?? "";
16050
16191
  const parts = clean.split(".").map((p) => {
16051
16192
  const n = parseInt(p, 10);
@@ -16053,8 +16194,8 @@ function compareSemver(a, b) {
16053
16194
  });
16054
16195
  return [parts[0] ?? 0, parts[1] ?? 0, parts[2] ?? 0];
16055
16196
  };
16056
- const [aMaj, aMin, aPat] = parse7(a);
16057
- const [bMaj, bMin, bPat] = parse7(b);
16197
+ const [aMaj, aMin, aPat] = parse2(a);
16198
+ const [bMaj, bMin, bPat] = parse2(b);
16058
16199
  if (aMaj !== bMaj) return aMaj < bMaj ? -1 : 1;
16059
16200
  if (aMin !== bMin) return aMin < bMin ? -1 : 1;
16060
16201
  if (aPat !== bPat) return aPat < bPat ? -1 : 1;
@@ -16063,7 +16204,7 @@ function compareSemver(a, b) {
16063
16204
  var CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
16064
16205
  async function readCache(cachePath) {
16065
16206
  try {
16066
- const raw = await readFile15(cachePath, "utf-8");
16207
+ const raw = await readFile16(cachePath, "utf-8");
16067
16208
  const parsed = JSON.parse(raw);
16068
16209
  if (parsed !== null && typeof parsed === "object" && "checkedAt" in parsed && "latest" in parsed && typeof parsed.checkedAt === "string" && typeof parsed.latest === "string") {
16069
16210
  return parsed;