@devkitvault/recall 1.2.9 → 1.2.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.
@@ -5,6 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.LastCommandError = void 0;
7
7
  exports.isSelfSaveCommand = isSelfSaveCommand;
8
+ exports.isSkippedHistoryCommand = isSkippedHistoryCommand;
9
+ exports.normalizeHistoryLine = normalizeHistoryLine;
10
+ exports.extractSaveableCommands = extractSaveableCommands;
11
+ exports.readHistoryCommands = readHistoryCommands;
8
12
  exports.stripZshExtendedPrefix = stripZshExtendedPrefix;
9
13
  exports.findLastSaveableCommand = findLastSaveableCommand;
10
14
  exports.detectShellKind = detectShellKind;
@@ -19,6 +23,96 @@ function isSelfSaveCommand(line) {
19
23
  const t = line.trim();
20
24
  return /^(recall|rec)\s+save(\s|$)/.test(t);
21
25
  }
26
+ /** Skip trivial / meta lines when bulk-importing history. */
27
+ function isSkippedHistoryCommand(line) {
28
+ const t = line.trim();
29
+ if (!t)
30
+ return true;
31
+ if (isSelfSaveCommand(t))
32
+ return true;
33
+ if (/^(recall|rec)(\s|$)/.test(t))
34
+ return true;
35
+ if (t.length < 2)
36
+ return true;
37
+ const first = t.split(/\s+/)[0]?.toLowerCase() ?? '';
38
+ const trivial = new Set([
39
+ 'cd', 'ls', 'll', 'la', 'pwd', 'clear', 'cls', 'exit', 'logout',
40
+ 'history', 'true', 'false', ':',
41
+ ]);
42
+ if (trivial.has(first) && t.split(/\s+/).length <= 2)
43
+ return true;
44
+ return false;
45
+ }
46
+ /** Normalize one history file line into a bare command, or null if not usable. */
47
+ function normalizeHistoryLine(rawLine) {
48
+ let raw = rawLine.replace(/\r$/, '');
49
+ if (!raw.trim())
50
+ return null;
51
+ if (/^#\d+$/.test(raw.trim()))
52
+ return null;
53
+ raw = stripZshExtendedPrefix(raw).trim();
54
+ if (!raw)
55
+ return null;
56
+ return raw;
57
+ }
58
+ /**
59
+ * Walk history lines (oldest → newest) and return unique saveable commands, newest first.
60
+ */
61
+ function extractSaveableCommands(lines, opts = {}) {
62
+ const minLength = opts.minLength ?? 3;
63
+ const seen = new Set();
64
+ const out = [];
65
+ for (let i = lines.length - 1; i >= 0; i--) {
66
+ const cmd = normalizeHistoryLine(lines[i] ?? '');
67
+ if (!cmd)
68
+ continue;
69
+ if (cmd.length < minLength)
70
+ continue;
71
+ if (isSkippedHistoryCommand(cmd))
72
+ continue;
73
+ if (seen.has(cmd))
74
+ continue;
75
+ seen.add(cmd);
76
+ out.push(cmd);
77
+ if (opts.limit !== undefined && out.length >= opts.limit)
78
+ break;
79
+ }
80
+ return out;
81
+ }
82
+ function readHistoryCommands(opts = {}) {
83
+ const env = opts.env ?? process.env;
84
+ const platform = opts.platform ?? process.platform;
85
+ const home = opts.home ?? os_1.default.homedir();
86
+ const shell = detectShellKind(env, platform);
87
+ if (shell === 'cmd') {
88
+ throw new LastCommandError('import history is not supported in cmd.exe. Use PowerShell, Git Bash, or WSL.', 'unsupported');
89
+ }
90
+ if (shell === 'unknown') {
91
+ throw new LastCommandError('Could not detect your shell. Use zsh, bash, or PowerShell.', 'unsupported');
92
+ }
93
+ const files = historyFileCandidates(shell, env, home);
94
+ for (const file of files) {
95
+ try {
96
+ if (!fs_1.default.existsSync(file))
97
+ continue;
98
+ const text = fs_1.default.readFileSync(file, 'utf8');
99
+ const commands = extractSaveableCommands(text.split('\n'), {
100
+ limit: opts.limit,
101
+ minLength: opts.minLength,
102
+ });
103
+ if (commands.length) {
104
+ return { commands, source: file, shell };
105
+ }
106
+ }
107
+ catch {
108
+ // try next
109
+ }
110
+ }
111
+ const tip = shell === 'bash'
112
+ ? ' If history looks empty, try: history -a && recall import history'
113
+ : '';
114
+ throw new LastCommandError(`No importable commands found in shell history.${tip}`, 'not_found');
115
+ }
22
116
  /** Strip zsh extended-history prefix `: <unix>:<duration>;`. */
23
117
  function stripZshExtendedPrefix(line) {
24
118
  const m = line.match(/^:\s*\d+:\d+;(.*)$/);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devkitvault/recall",
3
- "version": "1.2.9",
3
+ "version": "1.2.11",
4
4
  "description": "recall CLI — personal command vault for your terminal (local-first)",
5
5
  "keywords": [
6
6
  "cli",
@@ -19,11 +19,11 @@
19
19
  "license": "MIT",
20
20
  "homepage": "https://recall.devkitvault.com",
21
21
  "bugs": {
22
- "url": "https://github.com/devkitvault/recall-cli/issues"
22
+ "url": "https://github.com/devkitvaultorg/recall-cli/issues"
23
23
  },
24
24
  "repository": {
25
25
  "type": "git",
26
- "url": "git+https://github.com/devkitvault/recall-cli.git"
26
+ "url": "git+https://github.com/devkitvaultorg/recall-cli.git"
27
27
  },
28
28
  "bin": {
29
29
  "recall": "dist/index.js",