cc-transcript 13.1.0__tar.gz → 13.2.0__tar.gz

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 (87) hide show
  1. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/PKG-INFO +1 -1
  2. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/__init__.py +1 -0
  3. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/command.py +134 -2
  4. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/pyproject.toml +1 -1
  5. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/Cargo.lock +0 -0
  6. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/Cargo.toml +0 -0
  7. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/LICENSE +0 -0
  8. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/README.md +0 -0
  9. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/__main__.py +0 -0
  10. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/_parser_rs.pyi +0 -0
  11. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/activity.py +0 -0
  12. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/activity_probe.py +0 -0
  13. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/backend.py +0 -0
  14. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/builders.py +0 -0
  15. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/cli.py +0 -0
  16. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/context.py +0 -0
  17. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/corrections.py +0 -0
  18. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/corrections_cli.py +0 -0
  19. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/cost.py +0 -0
  20. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/decisions.py +0 -0
  21. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/discovery.py +0 -0
  22. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/disktruth.py +0 -0
  23. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/evidence.py +0 -0
  24. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/extract/__init__.py +0 -0
  25. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/extract/correct.py +0 -0
  26. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/facts.py +0 -0
  27. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/filterspec.py +0 -0
  28. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/heartbeats.py +0 -0
  29. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/ids.py +0 -0
  30. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/judge/__init__.py +0 -0
  31. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/judge/llm.py +0 -0
  32. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/judge/similar.py +0 -0
  33. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/judge/verdicts.py +0 -0
  34. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/ledger.py +0 -0
  35. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/mining/__init__.py +0 -0
  36. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/mining/candidates.py +0 -0
  37. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/mining/confidence.py +0 -0
  38. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/mining/engine.py +0 -0
  39. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/mining/filterspec.py +0 -0
  40. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/mining/formats.py +0 -0
  41. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/mining/sampling.py +0 -0
  42. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/mining/signals.py +0 -0
  43. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/mining/sourcekind.py +0 -0
  44. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/mining/spec.py +0 -0
  45. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/mining/store.py +0 -0
  46. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/models.py +0 -0
  47. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/nlp.py +0 -0
  48. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/notifications.py +0 -0
  49. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/parser.py +0 -0
  50. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/py.typed +0 -0
  51. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/query.py +0 -0
  52. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/render.py +0 -0
  53. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/sentiment/__init__.py +0 -0
  54. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/sentiment/buckets.py +0 -0
  55. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/sentiment/data/afinn-en-165.tsv +0 -0
  56. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/sentiment/data/domain_overrides.tsv +0 -0
  57. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/sentiment/data/en-ewt.udpipe +0 -0
  58. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/sentiment/engine.py +0 -0
  59. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/sentiment/lexicon.py +0 -0
  60. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/sentiment/scorespec.py +0 -0
  61. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/store.py +0 -0
  62. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/tools.py +0 -0
  63. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/cc_transcript/watch.py +0 -0
  64. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/rust/Cargo.toml +0 -0
  65. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/rust/benches/parse.rs +0 -0
  66. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/rust/build.rs +0 -0
  67. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/rust/data/command_prefix_pins.tsv +0 -0
  68. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/rust/rustfmt.toml +0 -0
  69. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/rust/src/activity.rs +0 -0
  70. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/rust/src/command.rs +0 -0
  71. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/rust/src/event.rs +0 -0
  72. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/rust/src/filter.rs +0 -0
  73. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/rust/src/generated/command.rs +0 -0
  74. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/rust/src/generated/mining.rs +0 -0
  75. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/rust/src/generated/mod.rs +0 -0
  76. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/rust/src/generated/protocol.rs +0 -0
  77. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/rust/src/lexicon.rs +0 -0
  78. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/rust/src/lib.rs +0 -0
  79. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/rust/src/mining.rs +0 -0
  80. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/rust/src/model.rs +0 -0
  81. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/rust/src/nlp.rs +0 -0
  82. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/rust/src/parse.rs +0 -0
  83. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/rust/src/protocol.rs +0 -0
  84. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/rust/src/python.rs +0 -0
  85. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/rust/src/score.rs +0 -0
  86. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/rust/src/types.rs +0 -0
  87. {cc_transcript-13.1.0 → cc_transcript-13.2.0}/rust/src/value.rs +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cc-transcript
3
- Version: 13.1.0
3
+ Version: 13.2.0
4
4
  Classifier: Development Status :: 3 - Alpha
5
5
  Classifier: Environment :: Console
6
6
  Classifier: Intended Audience :: Developers
@@ -78,6 +78,7 @@ EXPORTS: dict[str, str] = {
78
78
  "Command",
79
79
  "CommandLine",
80
80
  "CommandLineQuery",
81
+ "Occurrence",
81
82
  "Redirect",
82
83
  "command_prefixes",
83
84
  "parse_command_line",
@@ -10,7 +10,7 @@ prefix (``"git commit"``, ``"docker compose"``).
10
10
  from __future__ import annotations
11
11
 
12
12
  import re
13
- from dataclasses import dataclass
13
+ from dataclasses import dataclass, field
14
14
  from functools import cached_property, lru_cache
15
15
  from itertools import dropwhile
16
16
  from typing import TYPE_CHECKING
@@ -19,7 +19,7 @@ import tree_sitter_bash as tsbash
19
19
  from tree_sitter import Language, Node, Parser
20
20
 
21
21
  if TYPE_CHECKING:
22
- from collections.abc import Callable, Iterator, Sequence
22
+ from collections.abc import Callable, Iterator, Mapping, Sequence
23
23
 
24
24
  BASH_PARSER = Parser(Language(tsbash.language()))
25
25
 
@@ -52,6 +52,10 @@ WRAPPER_COMMANDS = frozenset({"sudo", "env", "time", "timeout", "nice", "nohup",
52
52
 
53
53
  ASSIGNMENT_RE = re.compile(r"^\w+=")
54
54
 
55
+ PIPE_GAP_RE = re.compile(r"\s*\|&?\s*")
56
+
57
+ REDIRECT_OP_TYPES = frozenset({"file_descriptor", ">", ">>", "<", "<<", ">&", "<&", ">|"})
58
+
55
59
 
56
60
  @dataclass(frozen=True)
57
61
  class Redirect:
@@ -74,6 +78,7 @@ class Command:
74
78
  args: tuple[str, ...]
75
79
  env: tuple[tuple[str, str], ...] = ()
76
80
  redirects: tuple[Redirect, ...] = ()
81
+ span: tuple[int, int] | None = field(default=None, compare=False, repr=False)
77
82
 
78
83
  @classmethod
79
84
  def parse(cls, raw: str) -> Command | None:
@@ -131,6 +136,7 @@ class Command:
131
136
  args=argv[1:],
132
137
  env=self.env,
133
138
  redirects=self.redirects,
139
+ span=self.span,
134
140
  )
135
141
 
136
142
  @property
@@ -252,6 +258,56 @@ class CommandLine:
252
258
  def q(self) -> CommandLineQuery:
253
259
  return CommandLineQuery(self)
254
260
 
261
+ @cached_property
262
+ def occurrences(self) -> tuple[Occurrence, ...]:
263
+ """One ``Occurrence`` per part, in line order."""
264
+ return tuple(Occurrence(self, index) for index in range(len(self.parts)))
265
+
266
+ def splice(self, replacements: Mapping[int, str]) -> str:
267
+ """Swap each indexed command's byte span for its replacement, preserving every other byte.
268
+
269
+ Args:
270
+ replacements: Command index → replacement text. Operates on
271
+ ``raw.encode()``; untouched bytes (operators, redirects,
272
+ heredoc bodies, comments) pass through verbatim.
273
+
274
+ Returns:
275
+ The rewritten line, decoded once at the end.
276
+
277
+ Raises:
278
+ ValueError: If an indexed command has no ``span``, or the spans are
279
+ out of order or overlap.
280
+ """
281
+ source = self.raw.encode()
282
+ out = bytearray()
283
+ cursor = 0
284
+ for index in sorted(replacements):
285
+ span = self.parts[index][0].span
286
+ if span is None:
287
+ raise ValueError(f"command at index {index} has no span")
288
+ start, end = span
289
+ if start < cursor:
290
+ raise ValueError(f"span {span} at index {index} overlaps or precedes cursor {cursor}")
291
+ out += source[cursor:start]
292
+ out += replacements[index].encode()
293
+ cursor = end
294
+ out += source[cursor:]
295
+ return out.decode()
296
+
297
+ def rewrite_occurrences(self, to: Callable[[Occurrence], str | None]) -> str | None:
298
+ """Map ``to`` over each occurrence and splice in its non-``None`` results.
299
+
300
+ Args:
301
+ to: Maps an ``Occurrence`` to replacement text, or ``None`` to leave
302
+ that command untouched.
303
+
304
+ Returns:
305
+ The spliced line, or ``None`` when ``to`` returned ``None`` for every
306
+ occurrence.
307
+ """
308
+ replacements = {occ.index: text for occ in self.occurrences if (text := to(occ)) is not None}
309
+ return self.splice(replacements) if replacements else None
310
+
255
311
  @staticmethod
256
312
  def node_text(node: Node) -> str:
257
313
  return node.text.decode() if node.text else ""
@@ -330,12 +386,16 @@ class CommandLine:
330
386
  case _:
331
387
  pass
332
388
 
389
+ content = [c for c in node.children if c.type != "file_redirect"]
390
+ span = (content[0].start_byte, content[-1].end_byte) if content else (node.start_byte, node.end_byte)
391
+
333
392
  return Command(
334
393
  raw=CommandLine.node_text(node),
335
394
  executable=executable,
336
395
  args=tuple(args),
337
396
  env=tuple(env),
338
397
  redirects=tuple(redirects),
398
+ span=span,
339
399
  )
340
400
 
341
401
  @staticmethod
@@ -352,13 +412,26 @@ class CommandLine:
352
412
  parts.extend(sub)
353
413
  return parts
354
414
 
415
+ @staticmethod
416
+ def redirect_absorbed_word(node: Node) -> bool:
417
+ """Whether a ``file_redirect`` swallowed a command word past its target.
418
+
419
+ Tree-sitter-bash folds a word that trails a redirect (the ``b`` in
420
+ ``echo a >out b``) into the ``file_redirect`` node beside the target, so
421
+ a redirect carrying more than one target word split the command's
422
+ arguments — leaving it no contiguous byte span to splice.
423
+ """
424
+ return sum(c.type not in REDIRECT_OP_TYPES for c in node.children) > 1
425
+
355
426
  @staticmethod
356
427
  def walk_redirected(node: Node) -> list[tuple[Command, str | None]]:
357
428
  redirects: list[Redirect] = []
358
429
  inner_parts: list[tuple[Command, str | None]] = []
430
+ broken = False
359
431
  for child in node.children:
360
432
  if child.type == "file_redirect":
361
433
  redirects.append(CommandLine.extract_redirect(child))
434
+ broken = broken or CommandLine.redirect_absorbed_word(child)
362
435
  else:
363
436
  inner_parts.extend(CommandLine.walk_node(child))
364
437
  if redirects and inner_parts:
@@ -370,6 +443,7 @@ class CommandLine:
370
443
  args=cmd.args,
371
444
  env=cmd.env,
372
445
  redirects=(*cmd.redirects, *redirects),
446
+ span=None if broken else cmd.span,
373
447
  ),
374
448
  op,
375
449
  )
@@ -382,6 +456,7 @@ class CommandLine:
382
456
  executable="",
383
457
  args=(),
384
458
  redirects=tuple(redirects),
459
+ span=(node.start_byte, node.end_byte),
385
460
  ),
386
461
  None,
387
462
  )
@@ -407,6 +482,63 @@ class CommandLine:
407
482
  return parts
408
483
 
409
484
 
485
+ @dataclass(frozen=True)
486
+ class Occurrence:
487
+ """One command of a ``CommandLine`` with its position and joining context.
488
+
489
+ Pairs the ``line`` with this command's ``index`` into ``line.parts``,
490
+ exposing the command, the operators on either side, and whether it sits in a
491
+ pipeline. Hook packs map over ``CommandLine.occurrences`` and return
492
+ replacement text per occurrence to rewrite individual commands in place.
493
+ """
494
+
495
+ line: CommandLine
496
+ index: int
497
+
498
+ @property
499
+ def command(self) -> Command:
500
+ """The command at this occurrence's index."""
501
+ return self.line.parts[self.index][0]
502
+
503
+ @property
504
+ def prev_op(self) -> str | None:
505
+ """The operator joining the previous command to this one; ``None`` at index 0."""
506
+ return self.line.parts[self.index - 1][1] if self.index > 0 else None
507
+
508
+ @property
509
+ def next_op(self) -> str | None:
510
+ """The operator joining this command to the next; ``None`` for the final command."""
511
+ return self.line.parts[self.index][1]
512
+
513
+ @cached_property
514
+ def piped(self) -> bool:
515
+ """Whether this command sits on either side of a pipe.
516
+
517
+ ``True`` when a neighboring operator is ``|``. Tree-sitter records no
518
+ operator token for ``|&``, and newline-separated statements also carry a
519
+ ``None`` operator, so a ``None`` neighbor falls back to inspecting the
520
+ decoded source gap toward that neighbor: it counts as piped only when the
521
+ gap is exactly one pipe operator token (``|`` or ``|&``) surrounded by
522
+ whitespace. Anything else in the gap — a comment, a redirect target, a
523
+ heredoc body, ``||``, an intervening statement — is not a pipe.
524
+ """
525
+ if self.prev_op == "|" or self.next_op == "|":
526
+ return True
527
+ span = self.command.span
528
+ if span is None:
529
+ return False
530
+ source = self.line.raw.encode()
531
+ if self.next_op is None and self.index + 1 < len(self.line.parts):
532
+ nxt = self.line.parts[self.index + 1][0].span
533
+ if nxt is not None and PIPE_GAP_RE.fullmatch(source[span[1] : nxt[0]].decode()):
534
+ return True
535
+ if self.prev_op is None and self.index > 0:
536
+ prev = self.line.parts[self.index - 1][0].span
537
+ if prev is not None and PIPE_GAP_RE.fullmatch(source[prev[1] : span[0]].decode()):
538
+ return True
539
+ return False
540
+
541
+
410
542
  @dataclass(frozen=True)
411
543
  class CommandLineQuery:
412
544
  """Predicate helpers for inspecting a parsed ``CommandLine``.
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "cc-transcript"
3
- version = "13.1.0"
3
+ version = "13.2.0"
4
4
  description = "Grep every Claude Code session you've ever run."
5
5
  readme = "README.md"
6
6
  license = "PolyForm-Noncommercial-1.0.0"
File without changes
File without changes