draftify-cli 1.0.90 → 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 +49 -22
  2. package/package.json +1 -1
package/dist/repl.js CHANGED
@@ -578,33 +578,60 @@ 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> ... </tool_call>) to translate them to FILE_CREATE/FILE_MODIFY
582
- const toolCallRegex = /<tool_call>([\s\S]*?)<\/(?:tool_call|tool)>/gi;
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
583
  let tcMatch;
584
584
  while ((tcMatch = toolCallRegex.exec(result)) !== null) {
585
- const block = tcMatch[1];
586
- // Find function name
587
- const funcMatch = block.match(/<function\s+name=['"]([^'"]+)['"]>/i);
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*"([^"]+)"/);
588
595
  if (funcMatch) {
589
596
  const funcName = funcMatch[1].toLowerCase();
590
- // Find path and content parameters
591
- const pathMatch = block.match(/<parameter\s+name=['"]path['"]>([\s\S]*?)<\/(?:parameter|param)>/i);
592
- const contentMatch = block.match(/<parameter\s+name=['"](?:content|code|file_content|patch)['"]>([\s\S]*?)<\/(?:parameter|param)>/i);
593
- if (pathMatch && contentMatch) {
594
- const filePath = pathMatch[1].trim();
595
- const content = contentMatch[1];
596
- let replacement = "";
597
- if (funcName.includes("create") || funcName.includes("write") || funcName.includes("new")) {
598
- replacement = `<FILE_CREATE path="${filePath}">${content}</FILE_CREATE>`;
599
- }
600
- else if (funcName.includes("modify") || funcName.includes("edit") || funcName.includes("patch") || funcName.includes("update")) {
601
- replacement = `<FILE_MODIFY path="${filePath}">${content}</FILE_MODIFY>`;
602
- }
603
- if (replacement) {
604
- result = result.replace(tcMatch[0], replacement);
605
- displayResult = displayResult.replace(tcMatch[0], replacement);
606
- }
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>`;
607
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);
608
635
  }
609
636
  }
610
637
  const isSafePath = (targetPath) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "draftify-cli",
3
- "version": "1.0.90",
3
+ "version": "1.0.91",
4
4
  "description": "Draftify AI CLI tool",
5
5
  "main": "dist/index.js",
6
6
  "bin": {