AI invented filter expression multi-field result having multiple return values

I asked the Github Copilot Claude 4 Agent mode in VSCode to help me optimize the user experience of the calendar plugin:

(too long, don’t need to read)

Based on my design in $:/plugins/linonetwo/tw-calendar/tiddlywiki-ui/ViewTemplate/EventCalendarSidebar, and the examples I provided, add a new sidebar component placed in the src\tiddlywiki-calendar\tiddlywiki-ui\ViewTemplate\DefaultSidebarSegment\ folder, with styles in a separate tid file. The content should display the top 10 tags of entries used most frequently in the last 7 days. If there are multiple tags, show all of them. That is, use a filter to get calendar entries from the last 7 days (those with [all[tiddlers]!is[system]field:calendarEntry[yes]]), then categorize them by their tags, and sort each category by the number of occurrences. Finally, use the data-tags I designed to attach the tags. The style should be similar to the “time block” sidebar design, making it easy for users to see which tags are present at a glance, and allowing them to drag tags directly onto the calendar. The duration should also take the average value of such events, calculated from the startDate and endDate on the calendar entries. You can try to achieve this with TiddlyWiki filters; if not possible, implement a new filter using TypeScript, referring to the existing filters in src\date-filters\filter.

And it invented this usage:

title: $:/plugins/linonetwo/tw-calendar/date-filters/filter/tagsfreq.js
type: application/javascript
module-type: filteroperator

/**
 * Calculate the usage frequency and average duration of tag combinations within recent specified days
 *
 * Input: Calendar entry tiddlers
 * Output: String array in format "tagCombination|count|avgDuration", sorted by count in descending order
 * tagCombination is a combination of tags, multiple tags separated by spaces
 *
 * ```
 * [all[tiddlers]!is[system]field:calendarEntry[yes]tagsfreq[7]]
 * ```
 */
export const tagsfreq = ((source, operator): string[] => {
...

Wow, the return of this filter operator is in format “tagCombination|count|avgDuration”

And it use it like this

  <$list 
    filter="[all[tiddlers]!is[system]field:calendarEntry[yes]tagsfreq[7]first[10]]" 
    variable="tagInfo"
    emptyMessage="<p class='tw-calendar-empty-list-help-text'>No tagged calendar entries in the recent 7 days</p>"
  >
    <$let 
      tags={{{ [<tagInfo>split[|]first[]] }}}
      count={{{ [<tagInfo>split[|]nth[2]] }}}
      avgDuration={{{ [<tagInfo>split[|]nth[3]] }}}
      durationData={{{ [<avgDuration>addprefix["]:addprefix[{ "duration": ]:addsuffix[":00" }]] }}}
    >
      <div class="tw-calendar-popular-tag-item">

so it return a | separated string, and split[|]nth[2] to get positional field, interesting. But still hope in the future version of tw it don’t have do this.

2 Likes

Clever. Claude4 certainly feels like a step up, would be amazing if they doubled the context window.