@polka-codes/cli 0.9.94 → 0.9.96

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/index.js +198 -25
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -42611,8 +42611,6 @@ function loadConfigAtPath(path) {
42611
42611
  } catch (error48) {
42612
42612
  if (error48 instanceof ZodError) {
42613
42613
  console.warn(`Config validation failed for ${path}: ${error48.message}`);
42614
- } else {
42615
- console.debug(`Could not load config from ${path}: ${error48 instanceof Error ? error48.message : String(error48)}`);
42616
42614
  }
42617
42615
  return;
42618
42616
  }
@@ -42709,11 +42707,13 @@ ${error48}`);
42709
42707
  const config3 = readConfig(path);
42710
42708
  configs.push(config3);
42711
42709
  } catch (error48) {
42712
- if (error48 instanceof ZodError) {
42713
- console.error(`Error in config file: ${path}
42714
- ${error48}`);
42715
- throw error48;
42710
+ const errorCode = error48?.code;
42711
+ if (errorCode === "ENOENT") {
42712
+ continue;
42716
42713
  }
42714
+ console.error(`Error loading config file: ${path}
42715
+ ${error48}`);
42716
+ throw error48;
42717
42717
  }
42718
42718
  }
42719
42719
  } else {
@@ -94128,7 +94128,7 @@ function createGitReadBinaryFile(commit2) {
94128
94128
  };
94129
94129
  }
94130
94130
  const isWindows2 = process.platform === "win32";
94131
- const command = isWindows2 ? `cmd /c "git show ${quotedCommit}:${quotedUrl} | base64 -w 0 2>&1"` : `sh -c "git show ${quotedCommit}:${quotedUrl} | base64 2>&1"`;
94131
+ const command = isWindows2 ? `cmd /c "git show ${quotedCommit}:${quotedUrl} | base64 -w 0"` : `sh -c "git show ${quotedCommit}:${quotedUrl} | base64"`;
94132
94132
  const result = await provider3.executeCommand(command, false);
94133
94133
  if (result.exitCode === 0) {
94134
94134
  const base64Data = result.stdout.replace(/\n/g, "");
@@ -112342,7 +112342,7 @@ var {
112342
112342
  Help
112343
112343
  } = import__.default;
112344
112344
  // package.json
112345
- var version = "0.9.94";
112345
+ var version = "0.9.96";
112346
112346
 
112347
112347
  // src/commands/agent.ts
112348
112348
  init_src();
@@ -120274,6 +120274,15 @@ async function executeWorkflow(workflow3, input2, commandName, logger, providerO
120274
120274
  }
120275
120275
  }
120276
120276
  function createPolkaCodesServerTools(logger) {
120277
+ function escapeRegexPattern(pattern) {
120278
+ return pattern.replace(/[.+*?^${}()|[\]\\]/g, "\\$&");
120279
+ }
120280
+ function createWildcardRegex(pattern) {
120281
+ const withWildcardsPlaceholders = pattern.replace(/\*/g, "\x00STAR\x00").replace(/\?/g, "\x00QUEST\x00");
120282
+ const escaped = escapeRegexPattern(withWildcardsPlaceholders);
120283
+ const withWildcards = escaped.replace(/\0STAR\0/g, ".*").replace(/\0QUEST\0/g, ".");
120284
+ return new RegExp(`^${withWildcards}$`);
120285
+ }
120277
120286
  return [
120278
120287
  {
120279
120288
  name: "code",
@@ -120597,33 +120606,92 @@ between different operations.
120597
120606
 
120598
120607
  Parameters:
120599
120608
  - operation (required): The operation to perform. Use "append" to add content, "replace" to overwrite all content, or "remove" to delete the topic.
120600
- - topic (optional): The memory topic to update. Defaults to ":default:".
120601
- - content (optional): The content to store (required for "append" and "replace" operations).
120609
+ - topics (optional): Array of topic names for batch operations. Content can be an array (one per topic) or a single string (broadcast to all topics).
120610
+ - topic (optional): Single memory topic to update. Defaults to ":default:".
120611
+ - content (optional): The content to store (required for "append" and "replace" operations). For batch operations with topics, provide an array of the same length or a single string to broadcast.
120612
+
120613
+ Supports wildcards in topic name for remove operation:
120614
+ - Use "*" to remove all topics (e.g., topic ":plan:*")
120615
+ - Use pattern matching like ":plan:*" to remove all topics starting with ":plan:"
120602
120616
 
120603
120617
  Returns a message confirming the operation performed.`,
120604
120618
  inputSchema: exports_external.object({
120605
- operation: exports_external.enum(["append", "replace", "remove"]).describe("The operation: append (add content), replace (overwrite), or remove (delete topic)"),
120606
- topic: exports_external.string().optional().describe('The memory topic to update (defaults to ":default:")'),
120607
- content: exports_external.string().optional().describe("Content to store (required for append/replace, must be omitted for remove)")
120619
+ operation: exports_external.enum(["append", "replace", "remove"]).describe("The operation: append (add content), replace (overwrite), or remove (delete topic(s))"),
120620
+ topic: exports_external.string().optional().describe('Single memory topic to update (defaults to ":default:")'),
120621
+ topics: exports_external.array(exports_external.string()).min(1).optional().describe("Array of topics for batch operations"),
120622
+ content: exports_external.union([exports_external.string(), exports_external.array(exports_external.string())]).optional().describe("Content to store (string or array for batch). Required for append/replace, omitted for remove")
120623
+ }).refine((data) => {
120624
+ if (data.topics && data.content) {
120625
+ if (Array.isArray(data.content)) {
120626
+ return data.content.length === data.topics.length;
120627
+ }
120628
+ return true;
120629
+ }
120630
+ if (!data.topics && data.content !== undefined && Array.isArray(data.content)) {
120631
+ return false;
120632
+ }
120633
+ return true;
120634
+ }, {
120635
+ message: "For single topic mode, content must be a string. For batch mode with topics array, content can be an array (same length) or a string (broadcast to all topics)"
120608
120636
  }),
120609
120637
  handler: async (args, toolContext) => {
120610
120638
  const {
120611
120639
  operation,
120612
- topic = ":default:",
120613
- content
120640
+ topic: singleTopic,
120641
+ topics,
120642
+ content: contentInput
120614
120643
  } = args;
120615
- toolContext.logger.info(`MCP: Memory operation "${operation}" on topic "${topic}"`);
120644
+ toolContext.logger.info(`MCP: Memory operation "${operation}" on ${topics ? `${topics.length} topics` : `topic "${singleTopic}"`}`);
120616
120645
  const memoryStore = await getMemoryStore(toolContext.logger);
120617
120646
  if (!memoryStore) {
120618
120647
  return "Error: Memory store is not enabled. Configure it in your .polkacodes.yml with memory.enabled: true";
120619
120648
  }
120620
120649
  try {
120621
- if ((operation === "append" || operation === "replace") && !content) {
120650
+ if (topics) {
120651
+ if (operation === "remove" && contentInput !== undefined) {
120652
+ return 'Error: Content must not be provided for "remove" operation';
120653
+ }
120654
+ if ((operation === "append" || operation === "replace") && contentInput === undefined) {
120655
+ return 'Error: Content is required for "append" and "replace" operations';
120656
+ }
120657
+ const contents = Array.isArray(contentInput) ? contentInput : topics.map(() => contentInput);
120658
+ const operations = topics.map((topic2, index) => ({
120659
+ operation,
120660
+ name: topic2,
120661
+ content: operation === "remove" ? undefined : contents[index]
120662
+ }));
120663
+ await memoryStore.store.batchUpdateMemory(operations);
120664
+ return `Batch operation "${operation}" completed on ${topics.length} topics:
120665
+ ${topics.join(`
120666
+ `)}`;
120667
+ }
120668
+ const topic = singleTopic || ":default:";
120669
+ if (operation === "remove" && (topic.includes("*") || topic.includes("?"))) {
120670
+ const allEntries = await memoryStore.store.queryMemory({ scope: "auto" }, { operation: "select" });
120671
+ if (!Array.isArray(allEntries)) {
120672
+ return "Error: Unable to query memory entries";
120673
+ }
120674
+ const regex2 = createWildcardRegex(topic);
120675
+ const matchingTopics = allEntries.filter((e2) => regex2.test(e2.name)).map((e2) => e2.name);
120676
+ if (matchingTopics.length === 0) {
120677
+ return `No topics found matching pattern "${topic}"`;
120678
+ }
120679
+ const operations = matchingTopics.map((matchingTopic) => ({
120680
+ operation: "remove",
120681
+ name: matchingTopic
120682
+ }));
120683
+ await memoryStore.store.batchUpdateMemory(operations);
120684
+ return `Removed ${matchingTopics.length} topic(s) matching pattern "${topic}":
120685
+ ${matchingTopics.join(`
120686
+ `)}`;
120687
+ }
120688
+ if ((operation === "append" || operation === "replace") && contentInput === undefined) {
120622
120689
  return 'Error: Content is required for "append" and "replace" operations';
120623
120690
  }
120624
- if (operation === "remove" && content !== undefined) {
120691
+ if (operation === "remove" && contentInput !== undefined) {
120625
120692
  return 'Error: Content must not be provided for "remove" operation';
120626
120693
  }
120694
+ const content = typeof contentInput === "string" ? contentInput : undefined;
120627
120695
  await memoryStore.store.updateMemory(operation, topic, content);
120628
120696
  const messages = {
120629
120697
  append: `Content appended to memory topic "${topic}"`,
@@ -120641,22 +120709,127 @@ Returns a message confirming the operation performed.`,
120641
120709
  description: `List all available memory topics.
120642
120710
 
120643
120711
  Use this to see what information has been stored and which topics are
120644
- available to read from. Returns a list of topic names that have content.`,
120645
- inputSchema: exports_external.object({}),
120646
- handler: async (_args, toolContext) => {
120647
- toolContext.logger.info("MCP: Listing memory topics");
120712
+ available to read from. Returns a list of topic names that have content.
120713
+
120714
+ Parameters:
120715
+ - pattern (optional): Filter topics by wildcard pattern (e.g., ":plan:*" for all plan topics)
120716
+ - scope (optional): Filter by scope ("auto", "project", or "global")`,
120717
+ inputSchema: exports_external.object({
120718
+ pattern: exports_external.string().optional().describe('Filter topics by wildcard pattern (e.g., ":plan:*")'),
120719
+ scope: exports_external.enum(["auto", "project", "global"]).optional().describe('Filter by scope (defaults to "auto")')
120720
+ }),
120721
+ handler: async (args, toolContext) => {
120722
+ const { pattern, scope } = args;
120723
+ toolContext.logger.info(`MCP: Listing memory topics${pattern ? ` with pattern "${pattern}"` : ""}`);
120648
120724
  const memoryStore = await getMemoryStore(toolContext.logger);
120649
120725
  if (!memoryStore) {
120650
120726
  return "Error: Memory store is not enabled. Configure it in your .polkacodes.yml with memory.enabled: true";
120651
120727
  }
120652
120728
  try {
120653
- const entries = await memoryStore.store.queryMemory({ scope: "auto" }, { operation: "select" });
120729
+ const query = {};
120730
+ query.scope = scope ?? "auto";
120731
+ const entries = await memoryStore.store.queryMemory(query, { operation: "select" });
120654
120732
  if (!entries || !Array.isArray(entries) || entries.length === 0) {
120655
120733
  return "No memory topics found.";
120656
120734
  }
120657
- const topics = [...new Set(entries.map((e2) => e2.name))];
120658
- return `Memory topics:
120735
+ let topics = [...new Set(entries.map((e2) => e2.name))];
120736
+ if (pattern) {
120737
+ const regex2 = createWildcardRegex(pattern);
120738
+ topics = topics.filter((t2) => regex2.test(t2));
120739
+ }
120740
+ if (topics.length === 0) {
120741
+ return pattern ? `No memory topics found matching pattern "${pattern}"` : "No memory topics found.";
120742
+ }
120743
+ return `Memory topics (${topics.length}):
120659
120744
  ${topics.join(`
120745
+ `)}`;
120746
+ } catch (error48) {
120747
+ return `Error: ${error48 instanceof Error ? error48.message : String(error48)}`;
120748
+ }
120749
+ }
120750
+ },
120751
+ {
120752
+ name: "memory_query",
120753
+ description: `Query memory with advanced filters.
120754
+
120755
+ Use this to search memory entries by content, metadata, or other criteria.
120756
+ Returns detailed entry information with metadata.
120757
+
120758
+ Parameters:
120759
+ - search (optional): Search text to find in content
120760
+ - type (optional): Filter by entry type (note, todo, plan, etc.)
120761
+ - status (optional): Filter by status (open, completed, closed, etc.)
120762
+ - priority (optional): Filter by priority (null, low, medium, high)
120763
+ - tags (optional): Filter by tags
120764
+ - scope (optional): Filter by scope ("auto", "project", or "global")
120765
+ - operation (optional): Query operation - "select" returns entries, "count" returns count
120766
+
120767
+ Returns matching entries with full metadata.`,
120768
+ inputSchema: exports_external.object({
120769
+ search: exports_external.string().optional().describe("Search text to find in content"),
120770
+ type: exports_external.string().optional().describe("Filter by entry type (note, todo, plan, etc.)"),
120771
+ status: exports_external.string().optional().describe("Filter by status (open, completed, closed, etc.)"),
120772
+ priority: exports_external.string().optional().describe("Filter by priority (null, low, medium, high)"),
120773
+ tags: exports_external.string().optional().describe("Filter by tags"),
120774
+ scope: exports_external.enum(["auto", "project", "global"]).optional().describe('Filter by scope (defaults to "auto")'),
120775
+ operation: exports_external.enum(["select", "count"]).optional().describe('Query operation (defaults to "select")')
120776
+ }),
120777
+ handler: async (args, toolContext) => {
120778
+ const {
120779
+ search,
120780
+ type,
120781
+ status,
120782
+ priority,
120783
+ tags,
120784
+ scope,
120785
+ operation = "select"
120786
+ } = args;
120787
+ toolContext.logger.info(`MCP: Querying memory - operation: "${operation}"`);
120788
+ const memoryStore = await getMemoryStore(toolContext.logger);
120789
+ if (!memoryStore) {
120790
+ return "Error: Memory store is not enabled. Configure it in your .polkacodes.yml with memory.enabled: true";
120791
+ }
120792
+ try {
120793
+ const memoryQuery = {};
120794
+ memoryQuery.scope = scope ?? "auto";
120795
+ if (search)
120796
+ memoryQuery.search = search;
120797
+ if (type)
120798
+ memoryQuery.type = type;
120799
+ if (status)
120800
+ memoryQuery.status = status;
120801
+ if (priority)
120802
+ memoryQuery.priority = priority;
120803
+ if (tags)
120804
+ memoryQuery.tags = tags;
120805
+ const result = await memoryStore.store.queryMemory(memoryQuery, { operation });
120806
+ if (operation === "count") {
120807
+ return `Found ${typeof result === "number" ? result : 0} matching entries`;
120808
+ }
120809
+ if (!Array.isArray(result) || result.length === 0) {
120810
+ return "No matching entries found.";
120811
+ }
120812
+ const formatted = result.map((entry) => {
120813
+ const lines = [];
120814
+ lines.push(`Topic: ${entry.name}`);
120815
+ if (entry.entry_type)
120816
+ lines.push(` Type: ${entry.entry_type}`);
120817
+ if (entry.status)
120818
+ lines.push(` Status: ${entry.status}`);
120819
+ if (entry.priority)
120820
+ lines.push(` Priority: ${entry.priority}`);
120821
+ if (entry.tags)
120822
+ lines.push(` Tags: ${entry.tags}`);
120823
+ if (entry.created_at)
120824
+ lines.push(` Created: ${new Date(entry.created_at).toISOString()}`);
120825
+ lines.push(` Content: ${entry.content?.substring(0, 100)}${entry.content && entry.content.length > 100 ? "..." : ""}`);
120826
+ return lines.join(`
120827
+ `);
120828
+ });
120829
+ return `Found ${result.length} entries:
120830
+
120831
+ ${formatted.join(`
120832
+
120660
120833
  `)}`;
120661
120834
  } catch (error48) {
120662
120835
  return `Error: ${error48 instanceof Error ? error48.message : String(error48)}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/cli",
3
- "version": "0.9.94",
3
+ "version": "0.9.96",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "github@polka.codes",
6
6
  "type": "module",