open-think 0.1.9 → 0.1.11

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 +160 -58
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -297,6 +297,10 @@ function getEngrams(cortexName, params) {
297
297
  conditions.push("created_at >= ?");
298
298
  values.push(params.since.toISOString());
299
299
  }
300
+ if (params.until) {
301
+ conditions.push("created_at <= ?");
302
+ values.push(params.until.toISOString());
303
+ }
300
304
  const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
301
305
  const limit = params.limit ?? 1e3;
302
306
  return db2.prepare(
@@ -479,6 +483,7 @@ var syncCommand = new Command("sync").description("Log a sync/work-log entry (sh
479
483
  // src/commands/list.ts
480
484
  import { Command as Command2 } from "commander";
481
485
  import chalk2 from "chalk";
486
+ import { subWeeks as subWeeks2, startOfWeek as startOfWeek2, endOfWeek as endOfWeek2 } from "date-fns";
482
487
  var categoryColors = {
483
488
  note: chalk2.blue,
484
489
  sync: chalk2.green,
@@ -492,31 +497,72 @@ function formatEntry(entry) {
492
497
  const badge = colorFn(`[${entry.category}]`.padEnd(12));
493
498
  return `${chalk2.gray(ts)} ${badge} ${entry.content}`;
494
499
  }
495
- var listCommand = new Command2("list").description("List entries with optional filters").option("--since <date>", "Show entries since date (ISO or YYYY-MM-DD)").option("--until <date>", "Show entries until date (ISO or YYYY-MM-DD)").option("-c, --category <category>", "Filter by category").option("-t, --tag <tag>", "Filter by tag").option("-n, --limit <n>", "Max entries to show", "20").option("-w, --week", "Show current week").option("--last-week", "Show last week").action((opts) => {
496
- let entries;
497
- if (opts.week) {
498
- entries = getEntriesByWeek(0);
499
- } else if (opts.lastWeek) {
500
- entries = getEntriesByWeek(1);
501
- } else {
502
- entries = getEntries({
503
- since: opts.since ? new Date(opts.since) : void 0,
504
- until: opts.until ? new Date(opts.until) : void 0,
505
- category: opts.category,
506
- tag: opts.tag,
500
+ function formatEngram(engram) {
501
+ const ts = engram.created_at.slice(0, 16).replace("T", " ");
502
+ const badge = chalk2.green("[engram]".padEnd(12));
503
+ return `${chalk2.gray(ts)} ${badge} ${engram.content}`;
504
+ }
505
+ var listCommand = new Command2("list").description("List entries with optional filters").option("--since <date>", "Show entries since date (ISO or YYYY-MM-DD)").option("--until <date>", "Show entries until date (ISO or YYYY-MM-DD)").option("-c, --category <category>", "Filter by category").option("-t, --tag <tag>", "Filter by tag").option("-n, --limit <n>", "Max entries to show", "20").option("-w, --week", "Show current week").option("--last-week", "Show last week").action(function(opts) {
506
+ const globalOpts = this.optsWithGlobals();
507
+ const config = getConfig();
508
+ const cortex = globalOpts.cortex ?? config.cortex?.active;
509
+ if (cortex) {
510
+ if (opts.category || opts.tag) {
511
+ console.log(chalk2.yellow("Note: --category and --tag filters are not supported for cortex engrams."));
512
+ }
513
+ let since;
514
+ let until;
515
+ if (opts.week) {
516
+ since = startOfWeek2(/* @__PURE__ */ new Date(), { weekStartsOn: 1 });
517
+ } else if (opts.lastWeek) {
518
+ const lastWeekDate = subWeeks2(/* @__PURE__ */ new Date(), 1);
519
+ since = startOfWeek2(lastWeekDate, { weekStartsOn: 1 });
520
+ until = endOfWeek2(lastWeekDate, { weekStartsOn: 1 });
521
+ } else {
522
+ if (opts.since) since = new Date(opts.since);
523
+ if (opts.until) until = new Date(opts.until);
524
+ }
525
+ const engrams = getEngrams(cortex, {
526
+ since,
527
+ until,
507
528
  limit: parseInt(opts.limit, 10)
508
529
  });
509
- }
510
- if (entries.length === 0) {
511
- console.log(chalk2.dim("No entries found."));
530
+ if (engrams.length === 0) {
531
+ console.log(chalk2.dim("No engrams found."));
532
+ } else {
533
+ for (const engram of engrams) {
534
+ console.log(formatEngram(engram));
535
+ }
536
+ console.log(chalk2.dim(`
537
+ ${engrams.length} engrams`));
538
+ }
539
+ closeEngramsDb(cortex);
512
540
  } else {
513
- for (const entry of entries) {
514
- console.log(formatEntry(entry));
541
+ let entries;
542
+ if (opts.week) {
543
+ entries = getEntriesByWeek(0);
544
+ } else if (opts.lastWeek) {
545
+ entries = getEntriesByWeek(1);
546
+ } else {
547
+ entries = getEntries({
548
+ since: opts.since ? new Date(opts.since) : void 0,
549
+ until: opts.until ? new Date(opts.until) : void 0,
550
+ category: opts.category,
551
+ tag: opts.tag,
552
+ limit: parseInt(opts.limit, 10)
553
+ });
515
554
  }
516
- console.log(chalk2.dim(`
555
+ if (entries.length === 0) {
556
+ console.log(chalk2.dim("No entries found."));
557
+ } else {
558
+ for (const entry of entries) {
559
+ console.log(formatEntry(entry));
560
+ }
561
+ console.log(chalk2.dim(`
517
562
  ${entries.length} entries`));
563
+ }
564
+ closeDb();
518
565
  }
519
- closeDb();
520
566
  });
521
567
 
522
568
  // src/commands/summary.ts
@@ -568,6 +614,7 @@ Please create a well-organized summary suitable for a 1:1 meeting.`;
568
614
  }
569
615
 
570
616
  // src/commands/summary.ts
617
+ import { subWeeks as subWeeks3, startOfWeek as startOfWeek3 } from "date-fns";
571
618
  function formatRaw(entries) {
572
619
  return entries.map((e) => {
573
620
  const ts = e.timestamp.slice(0, 16).replace("T", " ");
@@ -575,49 +622,104 @@ function formatRaw(entries) {
575
622
  return `${ts} [${e.category}] ${e.content}${tags}`;
576
623
  }).join("\n");
577
624
  }
578
- var summaryCommand = new Command3("summary").description("Generate a summary of entries (AI-powered or raw)").option("-w, --week", "Current week (default)").option("--last-week", "Last week").option("--since <date>", "Start date (ISO or YYYY-MM-DD)").option("--until <date>", "End date (ISO or YYYY-MM-DD)").option("-c, --category <category>", "Filter by category").option("-t, --tag <tag>", "Filter by tag").option("--raw", "Skip AI formatting, just dump entries").action(async (opts) => {
579
- let entries;
580
- if (opts.lastWeek) {
581
- entries = getEntriesByWeek(1);
582
- } else if (opts.since || opts.until) {
583
- entries = getEntries({
584
- since: opts.since ? new Date(opts.since) : void 0,
585
- until: opts.until ? new Date(opts.until) : void 0,
586
- category: opts.category,
587
- tag: opts.tag
588
- });
589
- } else {
590
- entries = getEntriesByWeek(0);
591
- }
592
- if ((opts.week || opts.lastWeek || !opts.since && !opts.until) && (opts.category || opts.tag)) {
593
- entries = entries.filter((e) => {
594
- if (opts.category && e.category !== opts.category) return false;
595
- if (opts.tag && !e.tags.includes(`"${opts.tag}"`)) return false;
596
- return true;
597
- });
598
- }
599
- if (entries.length === 0) {
600
- console.log(chalk3.dim("No entries found for the specified period."));
601
- closeDb();
602
- return;
603
- }
604
- if (opts.raw) {
605
- console.log(formatRaw(entries));
606
- console.log(chalk3.dim(`
607
- ${entries.length} entries`));
608
- } else {
625
+ function formatRawEngrams(engrams) {
626
+ return engrams.map((e) => {
627
+ const ts = e.created_at.slice(0, 16).replace("T", " ");
628
+ return `${ts} [engram] ${e.content}`;
629
+ }).join("\n");
630
+ }
631
+ function engramsToEntries(engrams) {
632
+ return engrams.map((e) => ({
633
+ id: e.id,
634
+ timestamp: e.created_at,
635
+ source: "manual",
636
+ category: "note",
637
+ content: e.content,
638
+ tags: "[]"
639
+ }));
640
+ }
641
+ var summaryCommand = new Command3("summary").description("Generate a summary of entries (AI-powered or raw)").option("-w, --week", "Current week (default)").option("--last-week", "Last week").option("--since <date>", "Start date (ISO or YYYY-MM-DD)").option("--until <date>", "End date (ISO or YYYY-MM-DD)").option("-c, --category <category>", "Filter by category").option("-t, --tag <tag>", "Filter by tag").option("--raw", "Skip AI formatting, just dump entries").action(async function(opts) {
642
+ const globalOpts = this.optsWithGlobals();
643
+ const config = getConfig();
644
+ const cortex = globalOpts.cortex ?? config.cortex?.active;
645
+ if (cortex) {
646
+ let since;
647
+ if (opts.lastWeek) {
648
+ since = startOfWeek3(subWeeks3(/* @__PURE__ */ new Date(), 1), { weekStartsOn: 1 });
649
+ } else if (opts.since) {
650
+ since = new Date(opts.since);
651
+ } else {
652
+ since = startOfWeek3(/* @__PURE__ */ new Date(), { weekStartsOn: 1 });
653
+ }
654
+ const engrams = getEngrams(cortex, { since });
609
655
  try {
610
- console.log(chalk3.dim("Generating summary..."));
611
- const summary = await generateSummary(entries);
612
- console.log(summary);
613
- } catch (err) {
614
- const msg = err instanceof Error ? err.message : String(err);
615
- console.error(chalk3.red(`Error generating summary: ${msg}`));
616
- console.log(chalk3.dim("\nFalling back to raw output:\n"));
656
+ if (engrams.length === 0) {
657
+ console.log(chalk3.dim("No engrams found for the specified period."));
658
+ return;
659
+ }
660
+ if (opts.raw) {
661
+ console.log(formatRawEngrams(engrams));
662
+ console.log(chalk3.dim(`
663
+ ${engrams.length} engrams`));
664
+ } else {
665
+ try {
666
+ console.log(chalk3.dim("Generating summary..."));
667
+ const summary = await generateSummary(engramsToEntries(engrams));
668
+ console.log(summary);
669
+ } catch (err) {
670
+ const msg = err instanceof Error ? err.message : String(err);
671
+ console.error(chalk3.red(`Error generating summary: ${msg}`));
672
+ console.log(chalk3.dim("\nFalling back to raw output:\n"));
673
+ console.log(formatRawEngrams(engrams));
674
+ }
675
+ }
676
+ } finally {
677
+ closeEngramsDb(cortex);
678
+ }
679
+ } else {
680
+ let entries;
681
+ if (opts.lastWeek) {
682
+ entries = getEntriesByWeek(1);
683
+ } else if (opts.since || opts.until) {
684
+ entries = getEntries({
685
+ since: opts.since ? new Date(opts.since) : void 0,
686
+ until: opts.until ? new Date(opts.until) : void 0,
687
+ category: opts.category,
688
+ tag: opts.tag
689
+ });
690
+ } else {
691
+ entries = getEntriesByWeek(0);
692
+ }
693
+ if ((opts.week || opts.lastWeek || !opts.since && !opts.until) && (opts.category || opts.tag)) {
694
+ entries = entries.filter((e) => {
695
+ if (opts.category && e.category !== opts.category) return false;
696
+ if (opts.tag && !e.tags.includes(`"${opts.tag}"`)) return false;
697
+ return true;
698
+ });
699
+ }
700
+ if (entries.length === 0) {
701
+ console.log(chalk3.dim("No entries found for the specified period."));
702
+ closeDb();
703
+ return;
704
+ }
705
+ if (opts.raw) {
617
706
  console.log(formatRaw(entries));
707
+ console.log(chalk3.dim(`
708
+ ${entries.length} entries`));
709
+ } else {
710
+ try {
711
+ console.log(chalk3.dim("Generating summary..."));
712
+ const summary = await generateSummary(entries);
713
+ console.log(summary);
714
+ } catch (err) {
715
+ const msg = err instanceof Error ? err.message : String(err);
716
+ console.error(chalk3.red(`Error generating summary: ${msg}`));
717
+ console.log(chalk3.dim("\nFalling back to raw output:\n"));
718
+ console.log(formatRaw(entries));
719
+ }
618
720
  }
721
+ closeDb();
619
722
  }
620
- closeDb();
621
723
  });
622
724
 
623
725
  // src/commands/delete.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "open-think",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "type": "module",
5
5
  "description": "Local-first CLI that gives AI agents persistent, curated memory",
6
6
  "bin": {