@meitouai/mem-note-cli 0.0.1 → 0.0.2

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.
@@ -1,11 +1,20 @@
1
- "use strict";
1
+ #!/usr/bin/env node
2
+ import { createRequire } from 'node:module';
3
+ const require = createRequire(import.meta.url);
2
4
  var __create = Object.create;
3
5
  var __defProp = Object.defineProperty;
4
6
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
7
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
8
  var __getProtoOf = Object.getPrototypeOf;
7
9
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __commonJS = (cb, mod) => function __require() {
10
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
11
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
12
+ }) : x)(function(x) {
13
+ if (typeof require !== "undefined")
14
+ return require.apply(this, arguments);
15
+ throw Error('Dynamic require of "' + x + '" is not supported');
16
+ });
17
+ var __commonJS = (cb, mod) => function __require2() {
9
18
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
19
  };
11
20
  var __copyProps = (to, from, except, desc) => {
@@ -94,7 +103,7 @@ var require_argument = __commonJS({
94
103
  this._name = name;
95
104
  break;
96
105
  }
97
- if (this._name.length > 3 && this._name.slice(-3) === "...") {
106
+ if (this._name.endsWith("...")) {
98
107
  this.variadic = true;
99
108
  this._name = this._name.slice(0, -3);
100
109
  }
@@ -110,11 +119,12 @@ var require_argument = __commonJS({
110
119
  /**
111
120
  * @package
112
121
  */
113
- _concatValue(value, previous) {
122
+ _collectValue(value, previous) {
114
123
  if (previous === this.defaultValue || !Array.isArray(previous)) {
115
124
  return [value];
116
125
  }
117
- return previous.concat(value);
126
+ previous.push(value);
127
+ return previous;
118
128
  }
119
129
  /**
120
130
  * Set the default value, and optionally supply the description to be displayed in the help.
@@ -153,7 +163,7 @@ var require_argument = __commonJS({
153
163
  );
154
164
  }
155
165
  if (this.variadic) {
156
- return this._concatValue(arg, previous);
166
+ return this._collectValue(arg, previous);
157
167
  }
158
168
  return arg;
159
169
  };
@@ -467,7 +477,11 @@ var require_help = __commonJS({
467
477
  extraInfo.push(`env: ${option.envVar}`);
468
478
  }
469
479
  if (extraInfo.length > 0) {
470
- return `${option.description} (${extraInfo.join(", ")})`;
480
+ const extraDescription = `(${extraInfo.join(", ")})`;
481
+ if (option.description) {
482
+ return `${option.description} ${extraDescription}`;
483
+ }
484
+ return extraDescription;
471
485
  }
472
486
  return option.description;
473
487
  }
@@ -499,6 +513,43 @@ var require_help = __commonJS({
499
513
  }
500
514
  return argument.description;
501
515
  }
516
+ /**
517
+ * Format a list of items, given a heading and an array of formatted items.
518
+ *
519
+ * @param {string} heading
520
+ * @param {string[]} items
521
+ * @param {Help} helper
522
+ * @returns string[]
523
+ */
524
+ formatItemList(heading, items, helper) {
525
+ if (items.length === 0)
526
+ return [];
527
+ return [helper.styleTitle(heading), ...items, ""];
528
+ }
529
+ /**
530
+ * Group items by their help group heading.
531
+ *
532
+ * @param {Command[] | Option[]} unsortedItems
533
+ * @param {Command[] | Option[]} visibleItems
534
+ * @param {Function} getGroup
535
+ * @returns {Map<string, Command[] | Option[]>}
536
+ */
537
+ groupItems(unsortedItems, visibleItems, getGroup) {
538
+ const result = /* @__PURE__ */ new Map();
539
+ unsortedItems.forEach((item) => {
540
+ const group = getGroup(item);
541
+ if (!result.has(group))
542
+ result.set(group, []);
543
+ });
544
+ visibleItems.forEach((item) => {
545
+ const group = getGroup(item);
546
+ if (!result.has(group)) {
547
+ result.set(group, []);
548
+ }
549
+ result.get(group).push(item);
550
+ });
551
+ return result;
552
+ }
502
553
  /**
503
554
  * Generate the built-in help text.
504
555
  *
@@ -532,26 +583,23 @@ var require_help = __commonJS({
532
583
  helper.styleArgumentDescription(helper.argumentDescription(argument))
533
584
  );
534
585
  });
535
- if (argumentList.length > 0) {
536
- output = output.concat([
537
- helper.styleTitle("Arguments:"),
538
- ...argumentList,
539
- ""
540
- ]);
541
- }
542
- const optionList = helper.visibleOptions(cmd).map((option) => {
543
- return callFormatItem(
544
- helper.styleOptionTerm(helper.optionTerm(option)),
545
- helper.styleOptionDescription(helper.optionDescription(option))
546
- );
586
+ output = output.concat(
587
+ this.formatItemList("Arguments:", argumentList, helper)
588
+ );
589
+ const optionGroups = this.groupItems(
590
+ cmd.options,
591
+ helper.visibleOptions(cmd),
592
+ (option) => option.helpGroupHeading ?? "Options:"
593
+ );
594
+ optionGroups.forEach((options2, group) => {
595
+ const optionList = options2.map((option) => {
596
+ return callFormatItem(
597
+ helper.styleOptionTerm(helper.optionTerm(option)),
598
+ helper.styleOptionDescription(helper.optionDescription(option))
599
+ );
600
+ });
601
+ output = output.concat(this.formatItemList(group, optionList, helper));
547
602
  });
548
- if (optionList.length > 0) {
549
- output = output.concat([
550
- helper.styleTitle("Options:"),
551
- ...optionList,
552
- ""
553
- ]);
554
- }
555
603
  if (helper.showGlobalOptions) {
556
604
  const globalOptionList = helper.visibleGlobalOptions(cmd).map((option) => {
557
605
  return callFormatItem(
@@ -559,27 +607,24 @@ var require_help = __commonJS({
559
607
  helper.styleOptionDescription(helper.optionDescription(option))
560
608
  );
561
609
  });
562
- if (globalOptionList.length > 0) {
563
- output = output.concat([
564
- helper.styleTitle("Global Options:"),
565
- ...globalOptionList,
566
- ""
567
- ]);
568
- }
569
- }
570
- const commandList = helper.visibleCommands(cmd).map((cmd2) => {
571
- return callFormatItem(
572
- helper.styleSubcommandTerm(helper.subcommandTerm(cmd2)),
573
- helper.styleSubcommandDescription(helper.subcommandDescription(cmd2))
610
+ output = output.concat(
611
+ this.formatItemList("Global Options:", globalOptionList, helper)
574
612
  );
575
- });
576
- if (commandList.length > 0) {
577
- output = output.concat([
578
- helper.styleTitle("Commands:"),
579
- ...commandList,
580
- ""
581
- ]);
582
613
  }
614
+ const commandGroups = this.groupItems(
615
+ cmd.commands,
616
+ helper.visibleCommands(cmd),
617
+ (sub) => sub.helpGroup() || "Commands:"
618
+ );
619
+ commandGroups.forEach((commands, group) => {
620
+ const commandList = commands.map((sub) => {
621
+ return callFormatItem(
622
+ helper.styleSubcommandTerm(helper.subcommandTerm(sub)),
623
+ helper.styleSubcommandDescription(helper.subcommandDescription(sub))
624
+ );
625
+ });
626
+ output = output.concat(this.formatItemList(group, commandList, helper));
627
+ });
583
628
  return output.join("\n");
584
629
  }
585
630
  /**
@@ -796,6 +841,7 @@ var require_option = __commonJS({
796
841
  this.argChoices = void 0;
797
842
  this.conflictsWith = [];
798
843
  this.implied = void 0;
844
+ this.helpGroupHeading = void 0;
799
845
  }
800
846
  /**
801
847
  * Set the default value, and optionally supply the description to be displayed in the help.
@@ -906,11 +952,12 @@ var require_option = __commonJS({
906
952
  /**
907
953
  * @package
908
954
  */
909
- _concatValue(value, previous) {
955
+ _collectValue(value, previous) {
910
956
  if (previous === this.defaultValue || !Array.isArray(previous)) {
911
957
  return [value];
912
958
  }
913
- return previous.concat(value);
959
+ previous.push(value);
960
+ return previous;
914
961
  }
915
962
  /**
916
963
  * Only allow option value to be one of choices.
@@ -927,7 +974,7 @@ var require_option = __commonJS({
927
974
  );
928
975
  }
929
976
  if (this.variadic) {
930
- return this._concatValue(arg, previous);
977
+ return this._collectValue(arg, previous);
931
978
  }
932
979
  return arg;
933
980
  };
@@ -956,6 +1003,16 @@ var require_option = __commonJS({
956
1003
  }
957
1004
  return camelcase(this.name());
958
1005
  }
1006
+ /**
1007
+ * Set the help group heading.
1008
+ *
1009
+ * @param {string} heading
1010
+ * @return {Option}
1011
+ */
1012
+ helpGroup(heading) {
1013
+ this.helpGroupHeading = heading;
1014
+ return this;
1015
+ }
959
1016
  /**
960
1017
  * Check if `arg` matches the short or long flag.
961
1018
  *
@@ -1151,11 +1208,11 @@ var require_suggestSimilar = __commonJS({
1151
1208
  // apps/mem-note-cli/node_modules/commander/lib/command.js
1152
1209
  var require_command = __commonJS({
1153
1210
  "apps/mem-note-cli/node_modules/commander/lib/command.js"(exports2) {
1154
- var EventEmitter = require("node:events").EventEmitter;
1155
- var childProcess = require("node:child_process");
1156
- var path = require("node:path");
1157
- var fs = require("node:fs");
1158
- var process2 = require("node:process");
1211
+ var EventEmitter = __require("node:events").EventEmitter;
1212
+ var childProcess = __require("node:child_process");
1213
+ var path = __require("node:path");
1214
+ var fs = __require("node:fs");
1215
+ var process2 = __require("node:process");
1159
1216
  var { Argument: Argument2, humanReadableArgName } = require_argument();
1160
1217
  var { CommanderError: CommanderError2 } = require_error();
1161
1218
  var { Help: Help2, stripColor } = require_help();
@@ -1216,6 +1273,9 @@ var require_command = __commonJS({
1216
1273
  this._addImplicitHelpCommand = void 0;
1217
1274
  this._helpCommand = void 0;
1218
1275
  this._helpConfiguration = {};
1276
+ this._helpGroupHeading = void 0;
1277
+ this._defaultCommandGroup = void 0;
1278
+ this._defaultOptionGroup = void 0;
1219
1279
  }
1220
1280
  /**
1221
1281
  * Copy settings that are useful to have in common across root command and subcommands.
@@ -1360,7 +1420,10 @@ var require_command = __commonJS({
1360
1420
  configureOutput(configuration) {
1361
1421
  if (configuration === void 0)
1362
1422
  return this._outputConfiguration;
1363
- Object.assign(this._outputConfiguration, configuration);
1423
+ this._outputConfiguration = {
1424
+ ...this._outputConfiguration,
1425
+ ...configuration
1426
+ };
1364
1427
  return this;
1365
1428
  }
1366
1429
  /**
@@ -1434,16 +1497,16 @@ var require_command = __commonJS({
1434
1497
  *
1435
1498
  * @param {string} name
1436
1499
  * @param {string} [description]
1437
- * @param {(Function|*)} [fn] - custom argument processing function
1500
+ * @param {(Function|*)} [parseArg] - custom argument processing function or default value
1438
1501
  * @param {*} [defaultValue]
1439
1502
  * @return {Command} `this` command for chaining
1440
1503
  */
1441
- argument(name, description, fn, defaultValue) {
1504
+ argument(name, description, parseArg, defaultValue) {
1442
1505
  const argument = this.createArgument(name, description);
1443
- if (typeof fn === "function") {
1444
- argument.default(defaultValue).argParser(fn);
1506
+ if (typeof parseArg === "function") {
1507
+ argument.default(defaultValue).argParser(parseArg);
1445
1508
  } else {
1446
- argument.default(fn);
1509
+ argument.default(parseArg);
1447
1510
  }
1448
1511
  this.addArgument(argument);
1449
1512
  return this;
@@ -1473,7 +1536,7 @@ var require_command = __commonJS({
1473
1536
  */
1474
1537
  addArgument(argument) {
1475
1538
  const previousArgument = this.registeredArguments.slice(-1)[0];
1476
- if (previousArgument && previousArgument.variadic) {
1539
+ if (previousArgument?.variadic) {
1477
1540
  throw new Error(
1478
1541
  `only the last argument can be variadic '${previousArgument.name()}'`
1479
1542
  );
@@ -1502,10 +1565,13 @@ var require_command = __commonJS({
1502
1565
  helpCommand(enableOrNameAndArgs, description) {
1503
1566
  if (typeof enableOrNameAndArgs === "boolean") {
1504
1567
  this._addImplicitHelpCommand = enableOrNameAndArgs;
1568
+ if (enableOrNameAndArgs && this._defaultCommandGroup) {
1569
+ this._initCommandGroup(this._getHelpCommand());
1570
+ }
1505
1571
  return this;
1506
1572
  }
1507
- enableOrNameAndArgs = enableOrNameAndArgs ?? "help [command]";
1508
- const [, helpName, helpArgs] = enableOrNameAndArgs.match(/([^ ]+) *(.*)/);
1573
+ const nameAndArgs = enableOrNameAndArgs ?? "help [command]";
1574
+ const [, helpName, helpArgs] = nameAndArgs.match(/([^ ]+) *(.*)/);
1509
1575
  const helpDescription = description ?? "display help for command";
1510
1576
  const helpCommand = this.createCommand(helpName);
1511
1577
  helpCommand.helpOption(false);
@@ -1515,6 +1581,8 @@ var require_command = __commonJS({
1515
1581
  helpCommand.description(helpDescription);
1516
1582
  this._addImplicitHelpCommand = true;
1517
1583
  this._helpCommand = helpCommand;
1584
+ if (enableOrNameAndArgs || description)
1585
+ this._initCommandGroup(helpCommand);
1518
1586
  return this;
1519
1587
  }
1520
1588
  /**
@@ -1531,6 +1599,7 @@ var require_command = __commonJS({
1531
1599
  }
1532
1600
  this._addImplicitHelpCommand = true;
1533
1601
  this._helpCommand = helpCommand;
1602
+ this._initCommandGroup(helpCommand);
1534
1603
  return this;
1535
1604
  }
1536
1605
  /**
@@ -1679,6 +1748,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
1679
1748
  throw new Error(`Cannot add option '${option.flags}'${this._name && ` to command '${this._name}'`} due to conflicting flag '${matchingFlag}'
1680
1749
  - already used by option '${matchingOption.flags}'`);
1681
1750
  }
1751
+ this._initOptionGroup(option);
1682
1752
  this.options.push(option);
1683
1753
  }
1684
1754
  /**
@@ -1702,6 +1772,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
1702
1772
  `cannot add command '${newCmd}' as already have command '${existingCmd}'`
1703
1773
  );
1704
1774
  }
1775
+ this._initCommandGroup(command);
1705
1776
  this.commands.push(command);
1706
1777
  }
1707
1778
  /**
@@ -1734,7 +1805,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
1734
1805
  if (val !== null && option.parseArg) {
1735
1806
  val = this._callParseArg(option, val, oldValue, invalidValueMessage);
1736
1807
  } else if (val !== null && option.variadic) {
1737
- val = option._concatValue(val, oldValue);
1808
+ val = option._collectValue(val, oldValue);
1738
1809
  }
1739
1810
  if (val == null) {
1740
1811
  if (option.negate) {
@@ -2391,7 +2462,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
2391
2462
  * @private
2392
2463
  */
2393
2464
  _chainOrCall(promise, fn) {
2394
- if (promise && promise.then && typeof promise.then === "function") {
2465
+ if (promise?.then && typeof promise.then === "function") {
2395
2466
  return promise.then(() => fn());
2396
2467
  }
2397
2468
  return fn();
@@ -2496,7 +2567,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
2496
2567
  promiseChain = this._chainOrCallHooks(promiseChain, "postAction");
2497
2568
  return promiseChain;
2498
2569
  }
2499
- if (this.parent && this.parent.listenerCount(commandEvent)) {
2570
+ if (this.parent?.listenerCount(commandEvent)) {
2500
2571
  checkForUnknownOptions();
2501
2572
  this._processArguments();
2502
2573
  this.parent.emit(commandEvent, operands, unknown);
@@ -2608,27 +2679,36 @@ Expecting one of '${allowedValues.join("', '")}'`);
2608
2679
  * sub --unknown uuu op => [sub], [--unknown uuu op]
2609
2680
  * sub -- --unknown uuu op => [sub --unknown uuu op], []
2610
2681
  *
2611
- * @param {string[]} argv
2682
+ * @param {string[]} args
2612
2683
  * @return {{operands: string[], unknown: string[]}}
2613
2684
  */
2614
- parseOptions(argv) {
2685
+ parseOptions(args) {
2615
2686
  const operands = [];
2616
2687
  const unknown = [];
2617
2688
  let dest = operands;
2618
- const args = argv.slice();
2619
2689
  function maybeOption(arg) {
2620
2690
  return arg.length > 1 && arg[0] === "-";
2621
2691
  }
2692
+ const negativeNumberArg = (arg) => {
2693
+ if (!/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(arg))
2694
+ return false;
2695
+ return !this._getCommandAndAncestors().some(
2696
+ (cmd) => cmd.options.map((opt) => opt.short).some((short) => /^-\d$/.test(short))
2697
+ );
2698
+ };
2622
2699
  let activeVariadicOption = null;
2623
- while (args.length) {
2624
- const arg = args.shift();
2700
+ let activeGroup = null;
2701
+ let i = 0;
2702
+ while (i < args.length || activeGroup) {
2703
+ const arg = activeGroup ?? args[i++];
2704
+ activeGroup = null;
2625
2705
  if (arg === "--") {
2626
2706
  if (dest === unknown)
2627
2707
  dest.push(arg);
2628
- dest.push(...args);
2708
+ dest.push(...args.slice(i));
2629
2709
  break;
2630
2710
  }
2631
- if (activeVariadicOption && !maybeOption(arg)) {
2711
+ if (activeVariadicOption && (!maybeOption(arg) || negativeNumberArg(arg))) {
2632
2712
  this.emit(`option:${activeVariadicOption.name()}`, arg);
2633
2713
  continue;
2634
2714
  }
@@ -2637,14 +2717,14 @@ Expecting one of '${allowedValues.join("', '")}'`);
2637
2717
  const option = this._findOption(arg);
2638
2718
  if (option) {
2639
2719
  if (option.required) {
2640
- const value = args.shift();
2720
+ const value = args[i++];
2641
2721
  if (value === void 0)
2642
2722
  this.optionMissingArgument(option);
2643
2723
  this.emit(`option:${option.name()}`, value);
2644
2724
  } else if (option.optional) {
2645
2725
  let value = null;
2646
- if (args.length > 0 && !maybeOption(args[0])) {
2647
- value = args.shift();
2726
+ if (i < args.length && (!maybeOption(args[i]) || negativeNumberArg(args[i]))) {
2727
+ value = args[i++];
2648
2728
  }
2649
2729
  this.emit(`option:${option.name()}`, value);
2650
2730
  } else {
@@ -2661,7 +2741,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
2661
2741
  this.emit(`option:${option.name()}`, arg.slice(2));
2662
2742
  } else {
2663
2743
  this.emit(`option:${option.name()}`);
2664
- args.unshift(`-${arg.slice(2)}`);
2744
+ activeGroup = `-${arg.slice(2)}`;
2665
2745
  }
2666
2746
  continue;
2667
2747
  }
@@ -2674,31 +2754,24 @@ Expecting one of '${allowedValues.join("', '")}'`);
2674
2754
  continue;
2675
2755
  }
2676
2756
  }
2677
- if (maybeOption(arg)) {
2757
+ if (dest === operands && maybeOption(arg) && !(this.commands.length === 0 && negativeNumberArg(arg))) {
2678
2758
  dest = unknown;
2679
2759
  }
2680
2760
  if ((this._enablePositionalOptions || this._passThroughOptions) && operands.length === 0 && unknown.length === 0) {
2681
2761
  if (this._findCommand(arg)) {
2682
2762
  operands.push(arg);
2683
- if (args.length > 0)
2684
- unknown.push(...args);
2763
+ unknown.push(...args.slice(i));
2685
2764
  break;
2686
2765
  } else if (this._getHelpCommand() && arg === this._getHelpCommand().name()) {
2687
- operands.push(arg);
2688
- if (args.length > 0)
2689
- operands.push(...args);
2766
+ operands.push(arg, ...args.slice(i));
2690
2767
  break;
2691
2768
  } else if (this._defaultCommandName) {
2692
- unknown.push(arg);
2693
- if (args.length > 0)
2694
- unknown.push(...args);
2769
+ unknown.push(arg, ...args.slice(i));
2695
2770
  break;
2696
2771
  }
2697
2772
  }
2698
2773
  if (this._passThroughOptions) {
2699
- dest.push(arg);
2700
- if (args.length > 0)
2701
- dest.push(...args);
2774
+ dest.push(arg, ...args.slice(i));
2702
2775
  break;
2703
2776
  }
2704
2777
  dest.push(arg);
@@ -3059,6 +3132,72 @@ Expecting one of '${allowedValues.join("', '")}'`);
3059
3132
  this._name = str2;
3060
3133
  return this;
3061
3134
  }
3135
+ /**
3136
+ * Set/get the help group heading for this subcommand in parent command's help.
3137
+ *
3138
+ * @param {string} [heading]
3139
+ * @return {Command | string}
3140
+ */
3141
+ helpGroup(heading) {
3142
+ if (heading === void 0)
3143
+ return this._helpGroupHeading ?? "";
3144
+ this._helpGroupHeading = heading;
3145
+ return this;
3146
+ }
3147
+ /**
3148
+ * Set/get the default help group heading for subcommands added to this command.
3149
+ * (This does not override a group set directly on the subcommand using .helpGroup().)
3150
+ *
3151
+ * @example
3152
+ * program.commandsGroup('Development Commands:);
3153
+ * program.command('watch')...
3154
+ * program.command('lint')...
3155
+ * ...
3156
+ *
3157
+ * @param {string} [heading]
3158
+ * @returns {Command | string}
3159
+ */
3160
+ commandsGroup(heading) {
3161
+ if (heading === void 0)
3162
+ return this._defaultCommandGroup ?? "";
3163
+ this._defaultCommandGroup = heading;
3164
+ return this;
3165
+ }
3166
+ /**
3167
+ * Set/get the default help group heading for options added to this command.
3168
+ * (This does not override a group set directly on the option using .helpGroup().)
3169
+ *
3170
+ * @example
3171
+ * program
3172
+ * .optionsGroup('Development Options:')
3173
+ * .option('-d, --debug', 'output extra debugging')
3174
+ * .option('-p, --profile', 'output profiling information')
3175
+ *
3176
+ * @param {string} [heading]
3177
+ * @returns {Command | string}
3178
+ */
3179
+ optionsGroup(heading) {
3180
+ if (heading === void 0)
3181
+ return this._defaultOptionGroup ?? "";
3182
+ this._defaultOptionGroup = heading;
3183
+ return this;
3184
+ }
3185
+ /**
3186
+ * @param {Option} option
3187
+ * @private
3188
+ */
3189
+ _initOptionGroup(option) {
3190
+ if (this._defaultOptionGroup && !option.helpGroupHeading)
3191
+ option.helpGroup(this._defaultOptionGroup);
3192
+ }
3193
+ /**
3194
+ * @param {Command} cmd
3195
+ * @private
3196
+ */
3197
+ _initCommandGroup(cmd) {
3198
+ if (this._defaultCommandGroup && !cmd.helpGroup())
3199
+ cmd.helpGroup(this._defaultCommandGroup);
3200
+ }
3062
3201
  /**
3063
3202
  * Set the name of the command from script filename, such as process.argv[1],
3064
3203
  * or require.main.filename, or __filename.
@@ -3196,15 +3335,22 @@ Expecting one of '${allowedValues.join("', '")}'`);
3196
3335
  helpOption(flags, description) {
3197
3336
  if (typeof flags === "boolean") {
3198
3337
  if (flags) {
3199
- this._helpOption = this._helpOption ?? void 0;
3338
+ if (this._helpOption === null)
3339
+ this._helpOption = void 0;
3340
+ if (this._defaultOptionGroup) {
3341
+ this._initOptionGroup(this._getHelpOption());
3342
+ }
3200
3343
  } else {
3201
3344
  this._helpOption = null;
3202
3345
  }
3203
3346
  return this;
3204
3347
  }
3205
- flags = flags ?? "-h, --help";
3206
- description = description ?? "display help for command";
3207
- this._helpOption = this.createOption(flags, description);
3348
+ this._helpOption = this.createOption(
3349
+ flags ?? "-h, --help",
3350
+ description ?? "display help for command"
3351
+ );
3352
+ if (flags || description)
3353
+ this._initOptionGroup(this._helpOption);
3208
3354
  return this;
3209
3355
  }
3210
3356
  /**
@@ -3229,6 +3375,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
3229
3375
  */
3230
3376
  addHelpOption(option) {
3231
3377
  this._helpOption = option;
3378
+ this._initOptionGroup(option);
3232
3379
  return this;
3233
3380
  }
3234
3381
  /**
@@ -4429,7 +4576,7 @@ var require_binary = __commonJS({
4429
4576
  "use strict";
4430
4577
  var NodeBuffer;
4431
4578
  try {
4432
- _require = require;
4579
+ _require = __require;
4433
4580
  NodeBuffer = _require("buffer").Buffer;
4434
4581
  } catch (__) {
4435
4582
  }
@@ -4743,7 +4890,7 @@ var require_function = __commonJS({
4743
4890
  "use strict";
4744
4891
  var esprima;
4745
4892
  try {
4746
- _require = require;
4893
+ _require = __require;
4747
4894
  esprima = _require("esprima");
4748
4895
  } catch (_) {
4749
4896
  if (typeof window !== "undefined")
@@ -6820,7 +6967,7 @@ var require_parse = __commonJS({
6820
6967
  var require_gray_matter = __commonJS({
6821
6968
  "node_modules/gray-matter/index.js"(exports2, module2) {
6822
6969
  "use strict";
6823
- var fs = require("fs");
6970
+ var fs = __require("fs");
6824
6971
  var sections = require_section_matter();
6825
6972
  var defaults = require_defaults();
6826
6973
  var stringify = require_stringify();
@@ -6934,10 +7081,16 @@ var require_gray_matter = __commonJS({
6934
7081
  });
6935
7082
 
6936
7083
  // apps/mem-note-cli/dist/main.js
6937
- var import_node_os = require("node:os");
6938
- var import_node_path6 = require("node:path");
6939
- var import_node_url = require("node:url");
6940
- var import_promises6 = require("node:fs/promises");
7084
+ import { homedir } from "node:os";
7085
+ import { basename as basename3, dirname as dirname3, join as join22, resolve } from "node:path";
7086
+ import { fileURLToPath } from "node:url";
7087
+ import {
7088
+ access as access2,
7089
+ copyFile,
7090
+ readFile as readFile4,
7091
+ readdir as readdir3,
7092
+ writeFile as writeFile22
7093
+ } from "node:fs/promises";
6941
7094
 
6942
7095
  // apps/mem-note-cli/node_modules/commander/esm.mjs
6943
7096
  var import_index = __toESM(require_commander(), 1);
@@ -6957,8 +7110,8 @@ var {
6957
7110
  } = import_index.default;
6958
7111
 
6959
7112
  // packages/mem-note/dist/storage/data-dir.js
6960
- var import_promises = require("node:fs/promises");
6961
- var import_node_path = require("node:path");
7113
+ import { mkdir } from "node:fs/promises";
7114
+ import { join } from "node:path";
6962
7115
  var DataDir = class {
6963
7116
  root;
6964
7117
  constructor(root) {
@@ -6981,43 +7134,43 @@ var DataDir = class {
6981
7134
  this.insightsDir(),
6982
7135
  this.reportsDir()
6983
7136
  ];
6984
- await Promise.all(dirs.map((d) => (0, import_promises.mkdir)(d, { recursive: true })));
7137
+ await Promise.all(dirs.map((d) => mkdir(d, { recursive: true })));
6985
7138
  }
6986
7139
  /** `<root>/notes/` — permanent, groomed notes. */
6987
7140
  notesDir() {
6988
- return (0, import_node_path.join)(this.root, "notes");
7141
+ return join(this.root, "notes");
6989
7142
  }
6990
7143
  /** `<root>/notes/_archived/` — archived notes (excluded from normal Glob scans). */
6991
7144
  archivedDir() {
6992
- return (0, import_node_path.join)(this.root, "notes", "_archived");
7145
+ return join(this.root, "notes", "_archived");
6993
7146
  }
6994
7147
  /** `<root>/inbox/` — raw input pending groom. */
6995
7148
  inboxDir() {
6996
- return (0, import_node_path.join)(this.root, "inbox");
7149
+ return join(this.root, "inbox");
6997
7150
  }
6998
7151
  /** `<root>/inbox/.processed/` — soft-deleted inbox entries. */
6999
7152
  processedInboxDir() {
7000
- return (0, import_node_path.join)(this.root, "inbox", ".processed");
7153
+ return join(this.root, "inbox", ".processed");
7001
7154
  }
7002
7155
  /** `<root>/insights/` — groom-produced insights. */
7003
7156
  insightsDir() {
7004
- return (0, import_node_path.join)(this.root, "insights");
7157
+ return join(this.root, "insights");
7005
7158
  }
7006
7159
  /** `<root>/.context/` — compiled context for SessionStart / PreCompact hooks. */
7007
7160
  contextDir() {
7008
- return (0, import_node_path.join)(this.root, ".context");
7161
+ return join(this.root, ".context");
7009
7162
  }
7010
7163
  /** `<root>/.context/index.md` — the single context file injected by hooks. */
7011
7164
  contextIndexPath() {
7012
- return (0, import_node_path.join)(this.contextDir(), "index.md");
7165
+ return join(this.contextDir(), "index.md");
7013
7166
  }
7014
7167
  /** `<root>/.reports/` — append-only audit log directory. */
7015
7168
  reportsDir() {
7016
- return (0, import_node_path.join)(this.root, ".reports");
7169
+ return join(this.root, ".reports");
7017
7170
  }
7018
7171
  /** `<root>/CONVENTIONS.md` — written by `mem-note init`, read by Claude in skills. */
7019
7172
  conventionsPath() {
7020
- return (0, import_node_path.join)(this.root, "CONVENTIONS.md");
7173
+ return join(this.root, "CONVENTIONS.md");
7021
7174
  }
7022
7175
  /** The absolute root path. */
7023
7176
  get rootDir() {
@@ -7026,9 +7179,9 @@ var DataDir = class {
7026
7179
  };
7027
7180
 
7028
7181
  // packages/mem-note/dist/storage/inbox-storage.js
7029
- var import_promises2 = require("node:fs/promises");
7030
- var import_node_path2 = require("node:path");
7031
7182
  var import_gray_matter = __toESM(require_gray_matter(), 1);
7183
+ import { access, mkdir as mkdir2, readFile, readdir, unlink, writeFile } from "node:fs/promises";
7184
+ import { join as join2 } from "node:path";
7032
7185
  var InboxStorage = class {
7033
7186
  dataDir;
7034
7187
  constructor(dataDir) {
@@ -7047,8 +7200,8 @@ var InboxStorage = class {
7047
7200
  async writeEntry(input) {
7048
7201
  const inboxDir = this.dataDir.inboxDir();
7049
7202
  const processedDir = this.dataDir.processedInboxDir();
7050
- await (0, import_promises2.mkdir)(inboxDir, { recursive: true });
7051
- await (0, import_promises2.mkdir)(processedDir, { recursive: true });
7203
+ await mkdir2(inboxDir, { recursive: true });
7204
+ await mkdir2(processedDir, { recursive: true });
7052
7205
  if (input.source) {
7053
7206
  const existing = await findBySource([inboxDir, processedDir], input.source);
7054
7207
  if (existing) {
@@ -7072,7 +7225,7 @@ var InboxStorage = class {
7072
7225
  if (input.source)
7073
7226
  frontmatter["source"] = input.source;
7074
7227
  const raw = import_gray_matter.default.stringify(input.content, frontmatter);
7075
- await (0, import_promises2.writeFile)(fullPath, raw, "utf-8");
7228
+ await writeFile(fullPath, raw, "utf-8");
7076
7229
  return {
7077
7230
  path: fullPath,
7078
7231
  relativePath: this.toRelative(fullPath),
@@ -7086,14 +7239,14 @@ var InboxStorage = class {
7086
7239
  async processEntry(input) {
7087
7240
  const inboxDir = this.dataDir.inboxDir();
7088
7241
  const processedDir = this.dataDir.processedInboxDir();
7089
- const sourcePath = (0, import_node_path2.join)(inboxDir, input.filename);
7090
- const destPath = (0, import_node_path2.join)(processedDir, input.filename);
7091
- const raw = await (0, import_promises2.readFile)(sourcePath, "utf-8");
7242
+ const sourcePath = join2(inboxDir, input.filename);
7243
+ const destPath = join2(processedDir, input.filename);
7244
+ const raw = await readFile(sourcePath, "utf-8");
7092
7245
  const parsed = (0, import_gray_matter.default)(raw);
7093
7246
  const status = input.status ?? "processed";
7094
7247
  const at = formatTimestamp(input.processedAt ?? /* @__PURE__ */ new Date());
7095
7248
  const reason = normalizeProcessedReason(status, input.reason);
7096
- await (0, import_promises2.mkdir)(processedDir, { recursive: true });
7249
+ await mkdir2(processedDir, { recursive: true });
7097
7250
  const nextRaw = import_gray_matter.default.stringify(parsed.content, {
7098
7251
  ...parsed.data,
7099
7252
  processed: {
@@ -7102,8 +7255,8 @@ var InboxStorage = class {
7102
7255
  ...reason ? { reason } : {}
7103
7256
  }
7104
7257
  });
7105
- await (0, import_promises2.writeFile)(destPath, nextRaw, "utf-8");
7106
- await (0, import_promises2.unlink)(sourcePath);
7258
+ await writeFile(destPath, nextRaw, "utf-8");
7259
+ await unlink(sourcePath);
7107
7260
  return {
7108
7261
  path: destPath,
7109
7262
  relativePath: this.toRelative(destPath),
@@ -7132,9 +7285,9 @@ function normalizeProcessedReason(status, reason) {
7132
7285
  async function pickUniqueFilename(inboxDir, timestamp, slug) {
7133
7286
  for (let i = 0; i < 1e3; i++) {
7134
7287
  const filename = i === 0 ? `${timestamp}_${slug}.md` : `${timestamp}_${slug}-${i}.md`;
7135
- const fullPath = (0, import_node_path2.join)(inboxDir, filename);
7288
+ const fullPath = join2(inboxDir, filename);
7136
7289
  try {
7137
- await (0, import_promises2.access)(fullPath);
7290
+ await access(fullPath);
7138
7291
  } catch {
7139
7292
  return { filename, fullPath };
7140
7293
  }
@@ -7154,16 +7307,16 @@ async function findBySource(dirs, sourceKey) {
7154
7307
  for (const dir of dirs) {
7155
7308
  let entries;
7156
7309
  try {
7157
- entries = await (0, import_promises2.readdir)(dir, { withFileTypes: true });
7310
+ entries = await readdir(dir, { withFileTypes: true });
7158
7311
  } catch {
7159
7312
  continue;
7160
7313
  }
7161
7314
  for (const entry of entries) {
7162
7315
  if (!entry.isFile() || !entry.name.endsWith(".md"))
7163
7316
  continue;
7164
- const fullPath = (0, import_node_path2.join)(dir, entry.name);
7317
+ const fullPath = join2(dir, entry.name);
7165
7318
  try {
7166
- const raw = await (0, import_promises2.readFile)(fullPath, "utf-8");
7319
+ const raw = await readFile(fullPath, "utf-8");
7167
7320
  const parsed = (0, import_gray_matter.default)(raw);
7168
7321
  const data = parsed.data;
7169
7322
  if (data["source"] === sourceKey) {
@@ -7177,9 +7330,9 @@ async function findBySource(dirs, sourceKey) {
7177
7330
  }
7178
7331
 
7179
7332
  // packages/mem-note/dist/doctor/doctor-engine.js
7180
- var import_promises3 = require("node:fs/promises");
7181
- var import_node_path3 = require("node:path");
7182
7333
  var import_gray_matter2 = __toESM(require_gray_matter(), 1);
7334
+ import { readFile as readFile2, readdir as readdir2 } from "node:fs/promises";
7335
+ import { basename, dirname, join as join3, relative } from "node:path";
7183
7336
  var REQUIRED_NOTE_FIELDS = [
7184
7337
  "type",
7185
7338
  "title",
@@ -7203,8 +7356,8 @@ var DoctorEngine = class {
7203
7356
  const indexFiles = [];
7204
7357
  const archivedNotes = [];
7205
7358
  for (const fullPath of allNoteFiles) {
7206
- const rel = (0, import_node_path3.relative)(notesRoot, fullPath);
7207
- if ((0, import_node_path3.basename)(fullPath) === "NOTES.md") {
7359
+ const rel = relative(notesRoot, fullPath);
7360
+ if (basename(fullPath) === "NOTES.md") {
7208
7361
  indexFiles.push(fullPath);
7209
7362
  } else if (rel.startsWith("_archived")) {
7210
7363
  archivedNotes.push(fullPath);
@@ -7228,12 +7381,12 @@ var DoctorEngine = class {
7228
7381
  indexFilesChecked = indexFiles.length;
7229
7382
  findings.push(...indexFindings);
7230
7383
  for (const archivedPath of archivedNotes) {
7231
- const name = (0, import_node_path3.basename)(archivedPath);
7384
+ const name = basename(archivedPath);
7232
7385
  if (!ARCHIVED_NAME_RE.test(name)) {
7233
7386
  findings.push({
7234
7387
  severity: "warning",
7235
7388
  category: "archived-naming",
7236
- path: (0, import_node_path3.relative)(this.dataDir.rootDir, archivedPath),
7389
+ path: relative(this.dataDir.rootDir, archivedPath),
7237
7390
  message: `Archived file "${name}" does not match YYYY-MM-DD_<slug>.md`
7238
7391
  });
7239
7392
  }
@@ -7255,13 +7408,13 @@ var DoctorEngine = class {
7255
7408
  async function walkMarkdown(dir) {
7256
7409
  let entries;
7257
7410
  try {
7258
- entries = await (0, import_promises3.readdir)(dir, { withFileTypes: true });
7411
+ entries = await readdir2(dir, { withFileTypes: true });
7259
7412
  } catch {
7260
7413
  return [];
7261
7414
  }
7262
7415
  const results = [];
7263
7416
  for (const entry of entries) {
7264
- const fullPath = (0, import_node_path3.join)(dir, entry.name);
7417
+ const fullPath = join3(dir, entry.name);
7265
7418
  if (entry.isDirectory()) {
7266
7419
  results.push(...await walkMarkdown(fullPath));
7267
7420
  } else if (entry.name.endsWith(".md")) {
@@ -7272,10 +7425,10 @@ async function walkMarkdown(dir) {
7272
7425
  }
7273
7426
  async function checkNoteFrontmatter(notePath, notesRoot) {
7274
7427
  const findings = [];
7275
- const relPath = `notes/${(0, import_node_path3.relative)(notesRoot, notePath)}`.replace(/\\/g, "/");
7428
+ const relPath = `notes/${relative(notesRoot, notePath)}`.replace(/\\/g, "/");
7276
7429
  let raw;
7277
7430
  try {
7278
- raw = await (0, import_promises3.readFile)(notePath, "utf-8");
7431
+ raw = await readFile2(notePath, "utf-8");
7279
7432
  } catch (err) {
7280
7433
  findings.push({
7281
7434
  severity: "error",
@@ -7333,7 +7486,7 @@ async function checkNotesIndexes(indexFiles, regularNotes, notesRoot) {
7333
7486
  const findings = [];
7334
7487
  const notesByDir = /* @__PURE__ */ new Map();
7335
7488
  for (const notePath of regularNotes) {
7336
- const dir = (0, import_node_path3.dirname)(notePath);
7489
+ const dir = dirname(notePath);
7337
7490
  const notesInDir = notesByDir.get(dir);
7338
7491
  if (notesInDir) {
7339
7492
  notesInDir.push(notePath);
@@ -7342,11 +7495,11 @@ async function checkNotesIndexes(indexFiles, regularNotes, notesRoot) {
7342
7495
  notesByDir.set(dir, [notePath]);
7343
7496
  }
7344
7497
  for (const [dir, notes] of notesByDir.entries()) {
7345
- const expectedIndex = (0, import_node_path3.join)(dir, "NOTES.md");
7346
- const relDir = `notes/${(0, import_node_path3.relative)(notesRoot, dir) || "."}`.replace(/\\/g, "/");
7498
+ const expectedIndex = join3(dir, "NOTES.md");
7499
+ const relDir = `notes/${relative(notesRoot, dir) || "."}`.replace(/\\/g, "/");
7347
7500
  let indexRaw = null;
7348
7501
  try {
7349
- indexRaw = await (0, import_promises3.readFile)(expectedIndex, "utf-8");
7502
+ indexRaw = await readFile2(expectedIndex, "utf-8");
7350
7503
  } catch {
7351
7504
  findings.push({
7352
7505
  severity: "warning",
@@ -7366,7 +7519,7 @@ async function checkNotesIndexes(indexFiles, regularNotes, notesRoot) {
7366
7519
  }
7367
7520
  linkedFiles.add(href);
7368
7521
  }
7369
- const actualFilenames = new Set(notes.map((p) => (0, import_node_path3.basename)(p)));
7522
+ const actualFilenames = new Set(notes.map((p) => basename(p)));
7370
7523
  for (const filename of actualFilenames) {
7371
7524
  if (!linkedFiles.has(filename)) {
7372
7525
  findings.push({
@@ -7394,7 +7547,7 @@ async function checkContextIndex(dataDir) {
7394
7547
  const indexPath = dataDir.contextIndexPath();
7395
7548
  let raw;
7396
7549
  try {
7397
- raw = await (0, import_promises3.readFile)(indexPath, "utf-8");
7550
+ raw = await readFile2(indexPath, "utf-8");
7398
7551
  } catch {
7399
7552
  return [
7400
7553
  {
@@ -7419,14 +7572,14 @@ async function checkContextIndex(dataDir) {
7419
7572
  }
7420
7573
 
7421
7574
  // packages/mem-note/dist/archive/archive.js
7422
- var import_promises4 = require("node:fs/promises");
7423
- var import_node_path4 = require("node:path");
7424
7575
  var import_gray_matter3 = __toESM(require_gray_matter(), 1);
7576
+ import { mkdir as mkdir3, readFile as readFile3, writeFile as writeFile2 } from "node:fs/promises";
7577
+ import { basename as basename2, dirname as dirname2, join as join4 } from "node:path";
7425
7578
  async function archiveNote(dataDir, notePath) {
7426
7579
  const absFrom = resolveNotePath(dataDir, notePath);
7427
- const sourceDir = (0, import_node_path4.dirname)(absFrom);
7428
- const originalName = (0, import_node_path4.basename)(absFrom);
7429
- const raw = await (0, import_promises4.readFile)(absFrom, "utf-8");
7580
+ const sourceDir = dirname2(absFrom);
7581
+ const originalName = basename2(absFrom);
7582
+ const raw = await readFile3(absFrom, "utf-8");
7430
7583
  const parsed = (0, import_gray_matter3.default)(raw);
7431
7584
  const today = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
7432
7585
  const newFrontmatter = {
@@ -7435,10 +7588,10 @@ async function archiveNote(dataDir, notePath) {
7435
7588
  };
7436
7589
  const updatedRaw = import_gray_matter3.default.stringify(parsed.content, newFrontmatter);
7437
7590
  const archivedDir = dataDir.archivedDir();
7438
- await (0, import_promises4.mkdir)(archivedDir, { recursive: true });
7591
+ await mkdir3(archivedDir, { recursive: true });
7439
7592
  const archivedName = `${today}_${originalName}`;
7440
- const absTo = (0, import_node_path4.join)(archivedDir, archivedName);
7441
- await (0, import_promises4.writeFile)(absTo, updatedRaw, "utf-8");
7593
+ const absTo = join4(archivedDir, archivedName);
7594
+ await writeFile2(absTo, updatedRaw, "utf-8");
7442
7595
  const { unlink: unlink2 } = await import("node:fs/promises");
7443
7596
  await unlink2(absFrom);
7444
7597
  const notesIndexUpdated = await removeFromNotesIndex(sourceDir, originalName);
@@ -7453,14 +7606,14 @@ function resolveNotePath(dataDir, input) {
7453
7606
  return input;
7454
7607
  const root = dataDir.rootDir;
7455
7608
  if (input.startsWith("notes/"))
7456
- return (0, import_node_path4.join)(root, input);
7457
- return (0, import_node_path4.join)(dataDir.notesDir(), input);
7609
+ return join4(root, input);
7610
+ return join4(dataDir.notesDir(), input);
7458
7611
  }
7459
7612
  async function removeFromNotesIndex(dir, filename) {
7460
- const indexPath = (0, import_node_path4.join)(dir, "NOTES.md");
7613
+ const indexPath = join4(dir, "NOTES.md");
7461
7614
  let raw;
7462
7615
  try {
7463
- raw = await (0, import_promises4.readFile)(indexPath, "utf-8");
7616
+ raw = await readFile3(indexPath, "utf-8");
7464
7617
  } catch {
7465
7618
  return false;
7466
7619
  }
@@ -7476,7 +7629,7 @@ async function removeFromNotesIndex(dir, filename) {
7476
7629
  outLines.push(line);
7477
7630
  }
7478
7631
  if (removed) {
7479
- await (0, import_promises4.writeFile)(indexPath, outLines.join("\n"), "utf-8");
7632
+ await writeFile2(indexPath, outLines.join("\n"), "utf-8");
7480
7633
  }
7481
7634
  return removed;
7482
7635
  }
@@ -7503,19 +7656,22 @@ function parseMarkdownNote(raw) {
7503
7656
  return { metadata: data, body: content, wikilinks };
7504
7657
  }
7505
7658
 
7506
- // apps/mem-note-cli/dist/git.js
7507
- var import_node_child_process = require("node:child_process");
7508
- var import_promises5 = require("node:fs/promises");
7509
- var import_node_path5 = require("node:path");
7659
+ // apps/mem-note-cli/dist/main.js
7660
+ import { spawn } from "node:child_process";
7661
+ import { writeFile as writeFile3, access as access3 } from "node:fs/promises";
7662
+ import { join as join5 } from "node:path";
7510
7663
  function run(cmd, args, cwd) {
7511
7664
  return new Promise((resolvePromise) => {
7512
- const child = (0, import_node_child_process.spawn)(cmd, args, { cwd, stdio: ["ignore", "pipe", "pipe"] });
7665
+ const child = spawn(cmd, args, { cwd, stdio: ["ignore", "pipe", "pipe"] });
7513
7666
  let stdout = "";
7514
7667
  let stderr = "";
7515
7668
  child.stdout.on("data", (d) => stdout += d.toString());
7516
7669
  child.stderr.on("data", (d) => stderr += d.toString());
7517
7670
  child.on("error", () => resolvePromise({ ok: false, stdout, stderr }));
7518
- child.on("close", (code) => resolvePromise({ ok: code === 0, stdout, stderr }));
7671
+ child.on(
7672
+ "close",
7673
+ (code) => resolvePromise({ ok: code === 0, stdout, stderr })
7674
+ );
7519
7675
  });
7520
7676
  }
7521
7677
  async function isGitAvailable() {
@@ -7524,7 +7680,7 @@ async function isGitAvailable() {
7524
7680
  }
7525
7681
  async function isGitRepo(cwd) {
7526
7682
  try {
7527
- await (0, import_promises5.access)((0, import_node_path5.join)(cwd, ".git"));
7683
+ await access3(join5(cwd, ".git"));
7528
7684
  return true;
7529
7685
  } catch {
7530
7686
  return false;
@@ -7538,9 +7694,13 @@ var GITIGNORE_CONTENT = `.snapshots/
7538
7694
  `;
7539
7695
  async function gitInitDataDir(cwd) {
7540
7696
  await run("git", ["init", "-q", "-b", "main"], cwd);
7541
- await (0, import_promises5.writeFile)((0, import_node_path5.join)(cwd, ".gitignore"), GITIGNORE_CONTENT, "utf-8");
7697
+ await writeFile3(join5(cwd, ".gitignore"), GITIGNORE_CONTENT, "utf-8");
7542
7698
  await run("git", ["add", "-A"], cwd);
7543
- await run("git", ["commit", "-q", "-m", "mem-note init", "--allow-empty"], cwd);
7699
+ await run(
7700
+ "git",
7701
+ ["commit", "-q", "-m", "mem-note init", "--allow-empty"],
7702
+ cwd
7703
+ );
7544
7704
  }
7545
7705
  async function gitCommitIfPossible(cwd, message) {
7546
7706
  if (!await isGitRepo(cwd))
@@ -7568,11 +7728,8 @@ function printInstallGuidance() {
7568
7728
  for (const l of lines)
7569
7729
  console.error(l);
7570
7730
  }
7571
-
7572
- // apps/mem-note-cli/dist/main.js
7573
- var import_meta = {};
7574
7731
  function resolveDataRoot() {
7575
- return process.env["MEM_NOTE_DATA_DIR"] ?? (0, import_node_path6.join)((0, import_node_os.homedir)(), ".aibox-mem-note");
7732
+ return process.env["MEM_NOTE_DATA_DIR"] ?? join22(homedir(), ".aibox-mem-note");
7576
7733
  }
7577
7734
  async function getDataDir() {
7578
7735
  const dd = new DataDir(resolveDataRoot());
@@ -7582,11 +7739,11 @@ async function getDataDir() {
7582
7739
  function resolveConventionsResource() {
7583
7740
  let here;
7584
7741
  try {
7585
- here = (0, import_node_path6.dirname)((0, import_node_url.fileURLToPath)(import_meta.url));
7742
+ here = dirname3(fileURLToPath(import.meta.url));
7586
7743
  } catch {
7587
7744
  here = __dirname;
7588
7745
  }
7589
- return (0, import_node_path6.resolve)(here, "conventions.md");
7746
+ return resolve(here, "conventions.md");
7590
7747
  }
7591
7748
  async function readStdin() {
7592
7749
  if (process.stdin.isTTY)
@@ -7599,23 +7756,27 @@ async function readStdin() {
7599
7756
  }
7600
7757
  var program2 = new Command();
7601
7758
  program2.name("mem-note").description("AI-enhanced personal knowledge base \u2014 minimal CLI surface").version("0.2.0");
7602
- program2.command("init").description("Create the data directory tree and write CONVENTIONS.md (idempotent \u2014 does not overwrite an existing CONVENTIONS.md)").action(async () => {
7759
+ program2.command("init").description(
7760
+ "Create the data directory tree and write CONVENTIONS.md (idempotent \u2014 does not overwrite an existing CONVENTIONS.md)"
7761
+ ).action(async () => {
7603
7762
  const dd = await getDataDir();
7604
7763
  const conventionsDest = dd.conventionsPath();
7605
7764
  let conventionsExisted = false;
7606
7765
  try {
7607
- await (0, import_promises6.access)(conventionsDest);
7766
+ await access2(conventionsDest);
7608
7767
  conventionsExisted = true;
7609
7768
  } catch {
7610
7769
  }
7611
7770
  if (!conventionsExisted) {
7612
7771
  const source = resolveConventionsResource();
7613
7772
  try {
7614
- await (0, import_promises6.copyFile)(source, conventionsDest);
7773
+ await copyFile(source, conventionsDest);
7615
7774
  } catch (err) {
7616
7775
  const fallback = "# mem-note CONVENTIONS\n\nFull conventions document missing from this installation. See apps/mem-note-cli/src/conventions.md in the source repo.\n";
7617
- await (0, import_promises6.writeFile)(conventionsDest, fallback, "utf-8");
7618
- console.warn(`[mem-note init] Warning: could not read ${source}: ${String(err)}`);
7776
+ await writeFile22(conventionsDest, fallback, "utf-8");
7777
+ console.warn(
7778
+ `[mem-note init] Warning: could not read ${source}: ${String(err)}`
7779
+ );
7619
7780
  }
7620
7781
  }
7621
7782
  let gitStatus = "skipped-no-git";
@@ -7629,55 +7790,80 @@ program2.command("init").description("Create the data directory tree and write C
7629
7790
  } else {
7630
7791
  printInstallGuidance();
7631
7792
  }
7632
- console.log(JSON.stringify({
7633
- ok: true,
7634
- root: dd.rootDir,
7635
- conventions: conventionsExisted ? "already-present" : conventionsDest,
7636
- git: gitStatus
7637
- }));
7793
+ console.log(
7794
+ JSON.stringify({
7795
+ ok: true,
7796
+ root: dd.rootDir,
7797
+ conventions: conventionsExisted ? "already-present" : conventionsDest,
7798
+ git: gitStatus
7799
+ })
7800
+ );
7638
7801
  });
7639
- program2.command("save").description("Save a new inbox entry. Accepts content as argument or stdin.").argument("[content]", "Content to save (omit to read from stdin)").option("--type <type>", "Preliminary type hint (optional; groom may rewrite)").option("--tags <tags>", "Comma-separated tags (optional)", (val) => val.split(",").map((t) => t.trim()).filter(Boolean)).option("--source <key>", "Deduplication key \u2014 if an entry with this source exists, reuse it").action(async (contentArg, opts) => {
7640
- const content = (contentArg?.trim() || await readStdin()).trim();
7641
- if (!content) {
7642
- console.error("mem-note save: no content provided (argument or stdin)");
7643
- process.exitCode = 1;
7644
- return;
7645
- }
7646
- const dd = await getDataDir();
7647
- const inbox = new InboxStorage(dd);
7648
- const result = await inbox.writeEntry({
7649
- content,
7650
- type: opts.type,
7651
- tags: opts.tags,
7652
- source: opts.source
7653
- });
7654
- if (result.created) {
7655
- await gitCommitIfPossible(dd.rootDir, `save: ${(0, import_node_path6.basename)(result.relativePath, ".md")}`);
7802
+ program2.command("save").description("Save a new inbox entry. Accepts content as argument or stdin.").argument("[content]", "Content to save (omit to read from stdin)").option("--type <type>", "Preliminary type hint (optional; groom may rewrite)").option(
7803
+ "--tags <tags>",
7804
+ "Comma-separated tags (optional)",
7805
+ (val) => val.split(",").map((t) => t.trim()).filter(Boolean)
7806
+ ).option(
7807
+ "--source <key>",
7808
+ "Deduplication key \u2014 if an entry with this source exists, reuse it"
7809
+ ).action(
7810
+ async (contentArg, opts) => {
7811
+ const content = (contentArg?.trim() || await readStdin()).trim();
7812
+ if (!content) {
7813
+ console.error("mem-note save: no content provided (argument or stdin)");
7814
+ process.exitCode = 1;
7815
+ return;
7816
+ }
7817
+ const dd = await getDataDir();
7818
+ const inbox = new InboxStorage(dd);
7819
+ const result = await inbox.writeEntry({
7820
+ content,
7821
+ type: opts.type,
7822
+ tags: opts.tags,
7823
+ source: opts.source
7824
+ });
7825
+ if (result.created) {
7826
+ await gitCommitIfPossible(
7827
+ dd.rootDir,
7828
+ `save: ${basename3(result.relativePath, ".md")}`
7829
+ );
7830
+ }
7831
+ console.log(
7832
+ JSON.stringify({
7833
+ ok: true,
7834
+ path: result.relativePath,
7835
+ created: result.created
7836
+ })
7837
+ );
7656
7838
  }
7657
- console.log(JSON.stringify({
7658
- ok: true,
7659
- path: result.relativePath,
7660
- created: result.created
7661
- }));
7662
- });
7663
- program2.command("archive <path>").description("Archive a note: add archived date, move to notes/_archived/<date>_<slug>.md, remove link from directory NOTES.md").action(async (notePath) => {
7839
+ );
7840
+ program2.command("archive <path>").description(
7841
+ "Archive a note: add archived date, move to notes/_archived/<date>_<slug>.md, remove link from directory NOTES.md"
7842
+ ).action(async (notePath) => {
7664
7843
  const dd = await getDataDir();
7665
7844
  try {
7666
7845
  const result = await archiveNote(dd, notePath);
7667
7846
  const relTo = result.to.slice(dd.rootDir.length + 1);
7668
- await gitCommitIfPossible(dd.rootDir, `archive: ${(0, import_node_path6.basename)(notePath, ".md")}`);
7669
- console.log(JSON.stringify({
7670
- ok: true,
7671
- from: notePath,
7672
- to: relTo,
7673
- notesIndexUpdated: result.notesIndexUpdated
7674
- }));
7847
+ await gitCommitIfPossible(
7848
+ dd.rootDir,
7849
+ `archive: ${basename3(notePath, ".md")}`
7850
+ );
7851
+ console.log(
7852
+ JSON.stringify({
7853
+ ok: true,
7854
+ from: notePath,
7855
+ to: relTo,
7856
+ notesIndexUpdated: result.notesIndexUpdated
7857
+ })
7858
+ );
7675
7859
  } catch (err) {
7676
7860
  console.error(`mem-note archive: ${String(err)}`);
7677
7861
  process.exitCode = 1;
7678
7862
  }
7679
7863
  });
7680
- program2.command("doctor").description("Check data directory consistency: frontmatter schema, NOTES.md drift, archived naming, .context/index.md").option("-f, --format <format>", "Output format: text | json", "text").action(async (opts) => {
7864
+ program2.command("doctor").description(
7865
+ "Check data directory consistency: frontmatter schema, NOTES.md drift, archived naming, .context/index.md"
7866
+ ).option("-f, --format <format>", "Output format: text | json", "text").action(async (opts) => {
7681
7867
  const dd = await getDataDir();
7682
7868
  const engine = new DoctorEngine(dd);
7683
7869
  const report = await engine.run();
@@ -7692,7 +7878,9 @@ program2.command("doctor").description("Check data directory consistency: frontm
7692
7878
  });
7693
7879
  function printDoctorReportText(findings, counts) {
7694
7880
  if (findings.length === 0) {
7695
- console.log(`\u2713 mem-note doctor: no issues (${counts.notesChecked} notes, ${counts.indexFilesChecked} NOTES.md)`);
7881
+ console.log(
7882
+ `\u2713 mem-note doctor: no issues (${counts.notesChecked} notes, ${counts.indexFilesChecked} NOTES.md)`
7883
+ );
7696
7884
  return;
7697
7885
  }
7698
7886
  const icon = (s) => s === "error" ? "\u2717" : s === "warning" ? "\u26A0" : "\u2139";
@@ -7700,22 +7888,26 @@ function printDoctorReportText(findings, counts) {
7700
7888
  console.log(`${icon(f.severity)} [${f.category}] ${f.path}: ${f.message}`);
7701
7889
  }
7702
7890
  console.log();
7703
- console.log(` ${counts.errors} error(s), ${counts.warnings} warning(s), ${counts.infos} info (${counts.notesChecked} notes, ${counts.indexFilesChecked} NOTES.md checked)`);
7891
+ console.log(
7892
+ ` ${counts.errors} error(s), ${counts.warnings} warning(s), ${counts.infos} info (${counts.notesChecked} notes, ${counts.indexFilesChecked} NOTES.md checked)`
7893
+ );
7704
7894
  }
7705
- program2.command("quick-context").description("Print the contents of .context/index.md (SessionStart and PreCompact hooks call this)").action(async () => {
7895
+ program2.command("quick-context").description(
7896
+ "Print the contents of .context/index.md (SessionStart and PreCompact hooks call this)"
7897
+ ).action(async () => {
7706
7898
  const dd = await getDataDir();
7707
7899
  const indexPath = dd.contextIndexPath();
7708
7900
  try {
7709
- const content = await (0, import_promises6.readFile)(indexPath, "utf-8");
7901
+ const content = await readFile4(indexPath, "utf-8");
7710
7902
  process.stdout.write(content);
7711
7903
  } catch {
7712
7904
  }
7713
7905
  });
7714
7906
  async function walkNotes(dir) {
7715
7907
  const results = [];
7716
- const entries = await (0, import_promises6.readdir)(dir, { withFileTypes: true }).catch(() => []);
7908
+ const entries = await readdir3(dir, { withFileTypes: true }).catch(() => []);
7717
7909
  for (const entry of entries) {
7718
- const full = (0, import_node_path6.join)(dir, entry.name);
7910
+ const full = join22(dir, entry.name);
7719
7911
  if (entry.isDirectory()) {
7720
7912
  if (entry.name !== "_archived") {
7721
7913
  results.push(...await walkNotes(full));
@@ -7726,7 +7918,9 @@ async function walkNotes(dir) {
7726
7918
  }
7727
7919
  return results;
7728
7920
  }
7729
- program2.command("ui-exec", { hidden: true }).description("Internal-only UI bridge command").action(async () => {
7921
+ program2.command("ui-exec", { hidden: true }).description(
7922
+ "Internal-only UI bridge command"
7923
+ ).action(async () => {
7730
7924
  const raw = await readStdin();
7731
7925
  if (!raw) {
7732
7926
  process.stderr.write("ui-exec: no input received on stdin\n");
@@ -7745,44 +7939,48 @@ program2.command("ui-exec", { hidden: true }).description("Internal-only UI brid
7745
7939
  switch (command) {
7746
7940
  case "list-notes": {
7747
7941
  const paths = await walkNotes(dd.notesDir());
7748
- const notes = await Promise.all(paths.map(async (absPath) => {
7749
- const raw2 = await (0, import_promises6.readFile)(absPath, "utf-8");
7750
- const { metadata } = parseMarkdownNote(raw2);
7751
- return {
7752
- // path relative to data root for portable display
7753
- path: absPath.slice(dd.rootDir.length + 1),
7754
- type: metadata["type"] ?? null,
7755
- title: metadata["title"] ?? null,
7756
- description: metadata["description"] ?? null,
7757
- tags: metadata["tags"] ?? [],
7758
- updated: metadata["updated"] ?? null
7759
- };
7760
- }));
7942
+ const notes = await Promise.all(
7943
+ paths.map(async (absPath) => {
7944
+ const raw2 = await readFile4(absPath, "utf-8");
7945
+ const { metadata } = parseMarkdownNote(raw2);
7946
+ return {
7947
+ // path relative to data root for portable display
7948
+ path: absPath.slice(dd.rootDir.length + 1),
7949
+ type: metadata["type"] ?? null,
7950
+ title: metadata["title"] ?? null,
7951
+ description: metadata["description"] ?? null,
7952
+ tags: metadata["tags"] ?? [],
7953
+ updated: metadata["updated"] ?? null
7954
+ };
7955
+ })
7956
+ );
7761
7957
  process.stdout.write(JSON.stringify({ ok: true, data: { notes } }));
7762
7958
  break;
7763
7959
  }
7764
7960
  case "list-inbox": {
7765
7961
  const inboxDir = dd.inboxDir();
7766
- const entries = await (0, import_promises6.readdir)(inboxDir, { withFileTypes: true }).catch(() => []);
7767
- const items = await Promise.all(entries.filter((e) => e.isFile() && e.name.endsWith(".md")).map(async (e) => {
7768
- const absPath = (0, import_node_path6.join)(inboxDir, e.name);
7769
- const raw2 = await (0, import_promises6.readFile)(absPath, "utf-8");
7770
- const { metadata, body } = parseMarkdownNote(raw2);
7771
- return {
7772
- filename: e.name,
7773
- created: metadata["created"] ?? null,
7774
- type: metadata["type"] ?? null,
7775
- tags: metadata["tags"] ?? [],
7776
- content: body.trim()
7777
- };
7778
- }));
7962
+ const entries = await readdir3(inboxDir, { withFileTypes: true }).catch(() => []);
7963
+ const items = await Promise.all(
7964
+ entries.filter((e) => e.isFile() && e.name.endsWith(".md")).map(async (e) => {
7965
+ const absPath = join22(inboxDir, e.name);
7966
+ const raw2 = await readFile4(absPath, "utf-8");
7967
+ const { metadata, body } = parseMarkdownNote(raw2);
7968
+ return {
7969
+ filename: e.name,
7970
+ created: metadata["created"] ?? null,
7971
+ type: metadata["type"] ?? null,
7972
+ tags: metadata["tags"] ?? [],
7973
+ content: body.trim()
7974
+ };
7975
+ })
7976
+ );
7779
7977
  process.stdout.write(JSON.stringify({ ok: true, data: { items } }));
7780
7978
  break;
7781
7979
  }
7782
7980
  case "get-context": {
7783
7981
  let content = "";
7784
7982
  try {
7785
- content = await (0, import_promises6.readFile)(dd.contextIndexPath(), "utf-8");
7983
+ content = await readFile4(dd.contextIndexPath(), "utf-8");
7786
7984
  } catch {
7787
7985
  }
7788
7986
  process.stdout.write(JSON.stringify({ ok: true, data: { content } }));
@@ -7792,7 +7990,7 @@ program2.command("ui-exec", { hidden: true }).description("Internal-only UI brid
7792
7990
  const date = typeof input["date"] === "string" ? input["date"] : (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
7793
7991
  let content = "";
7794
7992
  try {
7795
- content = await (0, import_promises6.readFile)((0, import_node_path6.join)(dd.reportsDir(), `${date}.md`), "utf-8");
7993
+ content = await readFile4(join22(dd.reportsDir(), `${date}.md`), "utf-8");
7796
7994
  } catch {
7797
7995
  }
7798
7996
  process.stdout.write(JSON.stringify({ ok: true, data: { content, date } }));
@@ -7802,13 +8000,15 @@ program2.command("ui-exec", { hidden: true }).description("Internal-only UI brid
7802
8000
  const rawFilename = typeof input["filename"] === "string" ? input["filename"] : "";
7803
8001
  const rawStatus = typeof input["status"] === "string" ? input["status"] : "processed";
7804
8002
  const reason = typeof input["reason"] === "string" ? input["reason"] : void 0;
7805
- const filename = (0, import_node_path6.basename)(rawFilename);
8003
+ const filename = basename3(rawFilename);
7806
8004
  if (!filename || !filename.endsWith(".md") || filename !== rawFilename) {
7807
8005
  process.stderr.write("ui-exec: process-inbox requires a plain .md filename\n");
7808
8006
  process.exit(1);
7809
8007
  }
7810
8008
  if (rawStatus !== "processed" && rawStatus !== "user-ignored") {
7811
- process.stderr.write('ui-exec: process-inbox status must be "processed" or "user-ignored"\n');
8009
+ process.stderr.write(
8010
+ 'ui-exec: process-inbox status must be "processed" or "user-ignored"\n'
8011
+ );
7812
8012
  process.exit(1);
7813
8013
  }
7814
8014
  const inbox = new InboxStorage(dd);