ticketlens 0.21.4 → 0.21.6

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.
@@ -37,6 +37,7 @@ import { checkForUpdate, getUpdateHint } from '../skills/jtb/scripts/lib/update-
37
37
  import { incrementInvocation, incrementCommand } from '../skills/jtb/scripts/lib/activity-counter.mjs';
38
38
  import { DEFAULT_CONFIG_DIR } from '../skills/jtb/scripts/lib/config.mjs';
39
39
  import { checkTeamJiraConfigUpdate } from '../skills/jtb/scripts/lib/team-jira-sync.mjs';
40
+ import { maybeAutoFlush } from '../skills/jtb/scripts/lib/recall-queue.mjs';
40
41
 
41
42
  const TRACKED_COMMANDS = new Set([
42
43
  'triage', 'fetch', 'get', 'compliance', 'review', 'standup',
@@ -60,6 +61,26 @@ revalidateIfStale();
60
61
  // Fire-and-forget: refresh the cached latest npm version once per 24h
61
62
  checkForUpdate();
62
63
 
64
+ // Best-effort: retry any Recall notes still queued from a prior failed push —
65
+ // on every command now, not just note add/recall, so a backlog from a burst
66
+ // of transient failures doesn't just sit until the user happens to run one
67
+ // of those two again. Cheap no-op when the queue is empty (one local file
68
+ // read); maybeAutoFlush's own cooldown still protects a down backend from
69
+ // being hit by every single command.
70
+ try {
71
+ const cliToken = readCliToken(DEFAULT_CONFIG_DIR);
72
+ if (cliToken) {
73
+ // Short timeout — this runs before every command, unrelated to Recall or
74
+ // not, so it must never be the reason an unrelated command feels slow.
75
+ const result = await maybeAutoFlush({ cliToken, configDir: DEFAULT_CONFIG_DIR, timeoutMs: 4000 });
76
+ if (result?.flushed) {
77
+ process.stderr.write(` ✔ Synced ${result.flushed} pending Recall note${result.flushed === 1 ? '' : 's'}.\n`);
78
+ }
79
+ }
80
+ } catch {
81
+ // Never let a background sync check break the actual command.
82
+ }
83
+
63
84
  // Show a one-line update hint on stderr after the command exits (never blocks stdout)
64
85
  process.on('exit', () => {
65
86
  try {
@@ -630,6 +651,16 @@ switch (command) {
630
651
  });
631
652
  break;
632
653
  }
654
+ if (cmdArgs[0] === 'delete') {
655
+ const { runNoteDelete } = await import('../skills/jtb/scripts/lib/note-command.mjs');
656
+ runNoteDelete(cmdArgs.slice(1)).then(({ deleted }) => {
657
+ if (!deleted) process.exitCode = 1;
658
+ }).catch(err => {
659
+ process.stderr.write(`Error: ${err.message}\n`);
660
+ process.exitCode = 1;
661
+ });
662
+ break;
663
+ }
633
664
  process.stderr.write('Usage: ticketlens note add --title="..." [--ticket=KEY] [--tags=a,b]\n');
634
665
  process.exitCode = 1;
635
666
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ticketlens",
3
- "version": "0.21.4",
3
+ "version": "0.21.6",
4
4
  "description": "Jira CLI for developers — fetch ticket context, triage your queue, and stop tab-switching. Zero dependencies, all local.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -520,6 +520,12 @@ export function printNoteHelp({ stream = process.stdout } = {}) {
520
520
  ` Code session — not typically invoked by hand. Every note it writes gets the`,
521
521
  ` same structural and secret-scan checks ${s.brand('note add')} applies to user input.`,
522
522
  '',
523
+ ` ${s.bold('ticketlens note delete')} ${s.dim('--id="..." [--ticket=KEY]')} ${s.dim('[Pro]')}`,
524
+ '',
525
+ ` Removes a note from your local vault. Local only — if this note was already`,
526
+ ` pushed to a team, teammates who pulled it keep their copy; deleting it there`,
527
+ ` too is a manager action from the Console (Admin > Recall).`,
528
+ '',
523
529
  ];
524
530
  stream.write(lines.join('\n') + '\n');
525
531
  }
@@ -11,7 +11,7 @@ import { DEFAULT_CONFIG_DIR } from './config.mjs';
11
11
  import { isLicensed, showUpgradePrompt } from './license.mjs';
12
12
  import { scanForSecrets } from './secret-scanner.mjs';
13
13
  import { checkNoteStructure } from './note-structural-check.mjs';
14
- import { writeNote, patchNoteBody } from './recall-vault.mjs';
14
+ import { writeNote, patchNoteBody, deleteNote } from './recall-vault.mjs';
15
15
  import { readCliToken } from './cli-auth.mjs';
16
16
  import { pushNote } from './recall-sync.mjs';
17
17
  import { enqueueNote, isRetryableFailure, maybeAutoFlush } from './recall-queue.mjs';
@@ -210,3 +210,45 @@ export async function runNotePatch(cmdArgs, {
210
210
  stream.write(patched ? ` Updated note (${id})\n` : ` Note not updated — (${id}) not found or already changed.\n`);
211
211
  return { patched };
212
212
  }
213
+
214
+ /**
215
+ * Implements `tl note delete` — removes a note from the local vault only.
216
+ *
217
+ * Local-only, same limitation `note patch` already documents: if this note
218
+ * was already pushed to a team (Team Recall enabled), teammates who already
219
+ * pulled it keep their copy — this does not push a tombstone. Deleting a
220
+ * note everywhere it's synced is a manager action from the Console today
221
+ * (Admin > Recall), which does propagate a tombstone on next pull.
222
+ *
223
+ * @param {string[]} cmdArgs
224
+ * @returns {Promise<{ deleted: boolean }>}
225
+ */
226
+ export async function runNoteDelete(cmdArgs, {
227
+ configDir = DEFAULT_CONFIG_DIR,
228
+ stream = process.stderr,
229
+ isLicensedFn = isLicensed,
230
+ deleteNoteFn = deleteNote,
231
+ } = {}) {
232
+ if (!isLicensedFn('pro', configDir)) {
233
+ showUpgradePrompt('pro', 'ticketlens note', { stream });
234
+ return { deleted: false };
235
+ }
236
+
237
+ const id = parseFlag(cmdArgs, 'id');
238
+ if (!id) {
239
+ stream.write('Usage: ticketlens note delete --id="..." [--ticket=KEY]\n');
240
+ return { deleted: false };
241
+ }
242
+
243
+ const ticketKey = parseFlag(cmdArgs, 'ticket');
244
+ if (ticketKey && !TICKET_KEY_PATTERN.test(ticketKey)) {
245
+ stream.write(` Invalid --ticket value "${ticketKey}" — expected a ticket key like PROJ-123.\n`);
246
+ return { deleted: false };
247
+ }
248
+
249
+ const { deleted } = deleteNoteFn({ external_id: id, tickets: ticketKey ? [ticketKey] : [] }, { configDir });
250
+ stream.write(deleted
251
+ ? ` Deleted note (${id}) — local vault only; see help for team-synced notes.\n`
252
+ : ` Note not deleted — (${id}) not found.\n`);
253
+ return { deleted };
254
+ }
@@ -141,6 +141,7 @@ export async function flushQueue({
141
141
  isRetryableFailureFn = isRetryableFailure,
142
142
  warn = () => {},
143
143
  now = () => Date.now(),
144
+ timeoutMs,
144
145
  } = {}) {
145
146
  const nowMs = now();
146
147
  const currentHash = hashToken(cliToken);
@@ -154,7 +155,9 @@ export async function flushQueue({
154
155
  continue;
155
156
  }
156
157
 
157
- const result = await pushNoteFn(entry.notePayload, { cliToken, configDir, warn });
158
+ const result = await pushNoteFn(entry.notePayload, {
159
+ cliToken, configDir, warn, ...(timeoutMs !== undefined ? { timeoutMs } : {}),
160
+ });
158
161
  if (result.ok) {
159
162
  flushed++;
160
163
  continue;
@@ -191,36 +194,52 @@ function writeLastFlushAttemptAt(configDir, isoTimestamp) {
191
194
  }
192
195
 
193
196
  /**
194
- * Time-gated background flush, attempted from the CLI's existing
195
- * Recall-touching entry points (note add's push, recall's pull) rather than
196
- * on every invocation — a no-op unless the queue is non-empty AND at least
197
- * AUTO_FLUSH_INTERVAL_MS has passed since the last attempt. The attempt
198
- * timestamp is recorded even on failure, so a down backend can't be hammered
199
- * once per command within the window.
197
+ * Time-gated background flush. Called from every command's entry point
198
+ * (bin/ticketlens.mjs), not just Recall-specific ones — a note added during
199
+ * a burst of failures (e.g. a debugging session) would otherwise sit queued
200
+ * until the user happens to run `note add`/`recall` again, or runs
201
+ * `recall sync` by hand. A no-op unless the queue is non-empty AND at least
202
+ * AUTO_FLUSH_INTERVAL_MS has passed since the last attempt — the interval is
203
+ * a single global cooldown, not per-entry, so a burst of failures in one
204
+ * short window still only gets one automatic retry pass, by design: this
205
+ * runs on every command now, so the next opportunity is never far away, and
206
+ * the cooldown exists specifically to stop a down backend from being hit by
207
+ * every single command in the meantime. The attempt timestamp is recorded
208
+ * even on failure, so a down backend can't be hammered once per command
209
+ * within the window.
200
210
  *
201
211
  * @param {object} opts
202
212
  * @param {string} opts.cliToken
203
213
  * @param {string} [opts.configDir]
204
214
  * @param {() => number} [opts.now]
205
215
  * @param {Function} [opts.flushQueueFn]
216
+ * @param {number} [opts.timeoutMs] - per-request timeout, passed through to
217
+ * pushNote. Callers running this unconditionally on every command (as
218
+ * opposed to an explicit `recall sync`) should pass something short — this
219
+ * must feel instant, not stall an unrelated command behind a slow network.
220
+ * @returns {Promise<{flushed: number, remaining: number}|null>} null if skipped
221
+ * (empty queue or still cooling down) — distinguishes "nothing to report"
222
+ * from "attempted, flushed 0" for a caller that wants to print a summary.
206
223
  */
207
224
  export async function maybeAutoFlush({
208
225
  cliToken,
209
226
  configDir = DEFAULT_CONFIG_DIR,
210
227
  now = () => Date.now(),
211
228
  flushQueueFn = flushQueue,
229
+ timeoutMs,
212
230
  } = {}) {
213
- if (readQueue(configDir).length === 0) return;
231
+ if (readQueue(configDir).length === 0) return null;
214
232
 
215
233
  const lastAttemptAt = readLastFlushAttemptAt(configDir);
216
234
  const nowMs = now();
217
- if (lastAttemptAt && nowMs - new Date(lastAttemptAt).getTime() < AUTO_FLUSH_INTERVAL_MS) return;
235
+ if (lastAttemptAt && nowMs - new Date(lastAttemptAt).getTime() < AUTO_FLUSH_INTERVAL_MS) return null;
218
236
 
219
237
  try {
220
- await flushQueueFn({ cliToken, configDir, now });
238
+ return await flushQueueFn({ cliToken, configDir, now, ...(timeoutMs !== undefined ? { timeoutMs } : {}) });
221
239
  } catch {
222
240
  // A down backend or a thrown network error must never crash the command
223
241
  // that opportunistically triggered this background attempt.
242
+ return null;
224
243
  } finally {
225
244
  writeLastFlushAttemptAt(configDir, new Date(nowMs).toISOString());
226
245
  }
@@ -101,25 +101,41 @@ function hasInternalCaseSwitch(token) {
101
101
  /**
102
102
  * True for a token that stops a joined-chunk run: either a recognized git/
103
103
  * checksum label word ("commit", "sha256", "md5sum", ...), or an ordinary
104
- * English word (letters only, no base64-style case switching). Anything else —
105
- * a fragment containing a digit/symbol, or an all-letter chunk that still reads
106
- * as random content — stays eligible to join, so a secret split by whitespace
107
- * can still be reassembled for the entropy check.
104
+ * English word (letters only, optionally with an internal possessive/
105
+ * contraction apostrophe — "relay's", "doesn't" — but no base64-style case
106
+ * switching). Anything else — a fragment containing a digit or other symbol,
107
+ * a hyphenated compound, or an all-letter chunk that still reads as random
108
+ * content — stays eligible to join, so a secret split by whitespace can still
109
+ * be reassembled for the entropy check.
108
110
  *
109
- * Known accepted gap: this can't tell a genuine dictionary word from one an
111
+ * The apostrophe allowance matters because without it, an ordinary possessive
112
+ * next to another non-label token (e.g. a hyphenated compound: "relay's
113
+ * decision-lookup") never gets a chance to stop the run — both fail to
114
+ * qualify, so they concatenate into one artificial blob whose mixed
115
+ * punctuation trips the entropy threshold. A real false positive, not a
116
+ * hypothetical one (see the regression test below). Hyphenated tokens are
117
+ * deliberately NOT given the same allowance: a short prefix + hyphen + long
118
+ * letter-run is indistinguishable from a real compound word by shape alone
119
+ * (e.g. "sk-abcdefghijklmnop", the letters-only half of a whitespace-split
120
+ * API key) — see the adjacent regression test for exactly this shape. Once
121
+ * the apostrophe fix lets "relay's" stop the run on its own, an adjacent
122
+ * hyphenated compound is short enough on its own to fall under
123
+ * MIN_RANDOM_TOKEN_LENGTH anyway, so it never needed the same allowance.
124
+ *
125
+ * Known accepted gap: this can't tell a genuine possessive from one an
110
126
  * attacker deliberately chose as a separator to defeat the scanner (e.g.
111
- * splitting a secret around the word "wall"). Closing that would require
112
- * treating ordinary prose words as joinable too, which in turn re-joins real
113
- * sentence text into false-positive "random" strings (verified empirically —
114
- * see the regression test for "PROD-123456 for background"). Entropy-based
115
- * detection is a safety net, not a cryptographic guarantee; the well-known
116
- * secret shapes in HARD_REJECT_PATTERNS are the layer that's fully whitespace-
117
- * and word-insertion-proof, since they match a specific literal prefix.
127
+ * splitting a secret around "user's"). Closing that would require treating
128
+ * ordinary prose words as joinable too, which in turn re-joins real sentence
129
+ * text into false-positive "random" strings (verified empirically — see the
130
+ * regression test for "PROD-123456 for background"). Entropy-based detection
131
+ * is a safety net, not a cryptographic guarantee; the well-known secret
132
+ * shapes in HARD_REJECT_PATTERNS are the layer that's fully whitespace- and
133
+ * word-insertion-proof, since they match a specific literal prefix.
118
134
  */
119
135
  function isLabelWord(token) {
120
136
  const stripped = stripEdgePunctuation(token);
121
137
  if (GIT_REFERENCE_WORD_RE.test(stripped)) return true;
122
- return /^[A-Za-z]+$/.test(stripped) && !hasInternalCaseSwitch(stripped);
138
+ return /^[A-Za-z]+(?:'[A-Za-z]+)*$/.test(stripped) && !hasInternalCaseSwitch(stripped);
123
139
  }
124
140
 
125
141
  /**