draftify-cli 1.0.89 → 1.0.91

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.
Files changed (2) hide show
  1. package/dist/repl.js +56 -0
  2. package/package.json +1 -1
package/dist/repl.js CHANGED
@@ -578,6 +578,62 @@ async function startRepl(initialUsername) {
578
578
  // 3. AI Chat Prompt (default)
579
579
  async function applyFileOperations(result) {
580
580
  let displayResult = result;
581
+ // Pre-process native tool calls (<tool_call> and <longcat_tool_call>) to translate them to standard XML tags
582
+ const toolCallRegex = /<(?:tool_call|longcat_tool_call)>([\s\S]*?)<\/(?:tool_call|tool|longcat_tool_call)>/gi;
583
+ let tcMatch;
584
+ while ((tcMatch = toolCallRegex.exec(result)) !== null) {
585
+ const block = tcMatch[1].trim();
586
+ // Check if the block is raw XML-like without opening angle bracket (e.g. LIST_DIR path="..." />)
587
+ if (block.startsWith("LIST_DIR") || block.startsWith("READ_FILE") || block.startsWith("FILE_CREATE") || block.startsWith("FILE_MODIFY") || block.startsWith("RUN_COMMAND")) {
588
+ const replacement = `<${block}`;
589
+ result = result.replace(tcMatch[0], replacement);
590
+ displayResult = displayResult.replace(tcMatch[0], replacement);
591
+ continue;
592
+ }
593
+ // Find function name (XML function tag or JSON name key)
594
+ const funcMatch = block.match(/<function\s+name=['"]([^'"]+)['"]>/i) || block.match(/"name"\s*:\s*"([^"]+)"/);
595
+ if (funcMatch) {
596
+ const funcName = funcMatch[1].toLowerCase();
597
+ // Find path, content, and command parameters (XML or JSON)
598
+ const pathMatch = block.match(/<parameter\s+name=['"]path['"]>([\s\S]*?)<\/(?:parameter|param)>/i) || block.match(/"path"\s*:\s*"([^"]+)"/);
599
+ const contentMatch = block.match(/<parameter\s+name=['"](?:content|code|file_content|patch)['"]>([\s\S]*?)<\/(?:parameter|param)>/i) || block.match(/"content"\s*:\s*"([\s\S]*?)"/);
600
+ const cmdMatch = block.match(/<parameter\s+name=['"]command['"]>([\s\S]*?)<\/(?:parameter|param)>/i) || block.match(/"command"\s*:\s*"([^"]+)"/);
601
+ const filePath = pathMatch ? pathMatch[1].trim() : "";
602
+ const content = contentMatch ? contentMatch[1] : "";
603
+ const cmd = cmdMatch ? cmdMatch[1].trim() : "";
604
+ let replacement = "";
605
+ if (funcName.includes("create") || funcName.includes("write") || funcName.includes("new")) {
606
+ replacement = `<FILE_CREATE path="${filePath}">${content}</FILE_CREATE>`;
607
+ }
608
+ else if (funcName.includes("modify") || funcName.includes("edit") || funcName.includes("patch") || funcName.includes("update")) {
609
+ replacement = `<FILE_MODIFY path="${filePath}">${content}</FILE_MODIFY>`;
610
+ }
611
+ else if (funcName.includes("read") || funcName.includes("view")) {
612
+ replacement = `<READ_FILE path="${filePath}" />`;
613
+ }
614
+ else if (funcName.includes("list") || funcName.includes("dir")) {
615
+ replacement = `<LIST_DIR path="${filePath || "."}" />`;
616
+ }
617
+ else if (funcName.includes("command") || funcName.includes("run") || funcName.includes("execute") || funcName.includes("shell")) {
618
+ replacement = `<RUN_COMMAND>${cmd}</RUN_COMMAND>`;
619
+ }
620
+ if (replacement) {
621
+ result = result.replace(tcMatch[0], replacement);
622
+ displayResult = displayResult.replace(tcMatch[0], replacement);
623
+ }
624
+ }
625
+ }
626
+ // Handle unclosed <longcat_tool_call> or <tool_call> (e.g. <longcat_tool_call>LIST_DIR path="." />)
627
+ const unclosedRegex = /<(?:tool_call|longcat_tool_call)>([\s\S]*?)$/i;
628
+ const unclosedMatch = result.match(unclosedRegex);
629
+ if (unclosedMatch) {
630
+ const block = unclosedMatch[1].trim();
631
+ if (block.startsWith("LIST_DIR") || block.startsWith("READ_FILE") || block.startsWith("FILE_CREATE") || block.startsWith("FILE_MODIFY") || block.startsWith("RUN_COMMAND")) {
632
+ const replacement = `<${block}`;
633
+ result = result.replace(unclosedMatch[0], replacement);
634
+ displayResult = displayResult.replace(unclosedMatch[0], replacement);
635
+ }
636
+ }
581
637
  const isSafePath = (targetPath) => {
582
638
  const relative = path_1.default.relative(process.cwd(), targetPath);
583
639
  return !relative.startsWith('..') && !path_1.default.isAbsolute(relative);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "draftify-cli",
3
- "version": "1.0.89",
3
+ "version": "1.0.91",
4
4
  "description": "Draftify AI CLI tool",
5
5
  "main": "dist/index.js",
6
6
  "bin": {