ctxtree 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/ctxtree.py +15 -7
  2. package/package.json +1 -1
package/ctxtree.py CHANGED
@@ -30,7 +30,7 @@ such as 30k. --level beats CTXTREE_LEVEL, which beats the level saved with `ctxt
30
30
  """
31
31
  import argparse, glob, json, os, re, shlex, shutil, subprocess, sys, time
32
32
 
33
- __version__ = "0.2.2"
33
+ __version__ = "0.2.3"
34
34
  from datetime import datetime
35
35
 
36
36
  ROOT = os.path.expanduser("~/.claude/projects")
@@ -753,7 +753,8 @@ def make_titles(s, run=None):
753
753
  # no tools and no MCP servers: with tools off, Claude Code sends every MCP tool's full description instead of
754
754
  # loading them on demand (measured here: 247k tokens for a two-word prompt, 4.5k without them)
755
755
  ["claude", "-p", "--model", "claude-haiku-5-5", "--no-session-persistence", "--tools", "", "--strict-mcp-config",
756
- "--mcp-config", '{"mcpServers":{}}', "--output-format", "json"], input=text, capture_output=True, text=True, timeout=300, cwd=os.path.expanduser("~")).stdout)
756
+ "--mcp-config", '{"mcpServers":{}}', "--output-format", "json"],
757
+ input=text, capture_output=True, text=True, timeout=300, cwd=os.path.expanduser("~")).stdout)
757
758
  reply = json.loads(run(ask))
758
759
  text = reply.get("result") or ""
759
760
  got = json.loads(text[text.index("{"):text.rindex("}") + 1])
@@ -764,9 +765,9 @@ def make_titles(s, run=None):
764
765
  except (OSError, ValueError):
765
766
  everything = {}
766
767
  everything.setdefault(s.id, {}).update(new)
767
- os.makedirs(os.path.dirname(titles_file()), exist_ok=True)
768
- with open(titles_file(), "w", encoding="utf-8") as f:
769
- json.dump(everything, f)
768
+ os.makedirs(os.path.dirname(titles_file()), mode=0o700, exist_ok=True)
769
+ with os.fdopen(os.open(titles_file(), os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600), "w", encoding="utf-8") as f:
770
+ json.dump(everything, f) # titles say what was worked on: for you only
770
771
  return everything[s.id], len(new), reply.get("usage") or {}
771
772
 
772
773
 
@@ -912,8 +913,15 @@ SECRETS = re.compile("|".join([
912
913
  r"\bgithub_pat_[A-Za-z0-9_]{40,}", r"\bAKIA[0-9A-Z]{16}\b", r"\bxox[abprs]-[A-Za-z0-9\-]{10,}",
913
914
  r"\b[rs]k_live_[A-Za-z0-9]{20,}", r"\bAIza[0-9A-Za-z_\-]{35}\b", r"\bnpm_[A-Za-z0-9]{36}\b",
914
915
  r"\bpypi-[A-Za-z0-9_\-]{50,}", r"\beyJ[A-Za-z0-9_\-]{10,}\.eyJ[A-Za-z0-9_\-]{10,}\.[A-Za-z0-9_\-]{10,}",
916
+ # more services' own shapes: GitLab, Hugging Face, Doppler, Tailscale, SendGrid, Vercel, and GitHub's server tokens
917
+ r"\bglpat-[A-Za-z0-9_\-]{20,}", r"\bhf_[A-Za-z0-9]{30,}", r"\bdp\.[a-z]{2,5}\.[A-Za-z0-9]{40,}",
918
+ r"\btskey-[a-z]+-[A-Za-z0-9\-]{20,}", r"\bSG\.[A-Za-z0-9_\-]{16,}\.[A-Za-z0-9_\-]{16,}",
919
+ r"\bvc[a-z]_[A-Za-z0-9]{24,}", r"\bghs_[A-Za-z0-9]{30,}",
915
920
  r"-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]*?(?:-----END [A-Z ]*PRIVATE KEY-----|$)",
916
- r"(?i:(?<=password=)|(?<=secret=)|(?<=token=))[^\s'\"&]{8,}"]))
921
+ # by where it stands, whatever its shape: after Bearer, as the password in an address, as a named value
922
+ r"(?i:(?<=bearer ))[A-Za-z0-9._~+/=\-]{20,}", r"(?<=://)[^\s/:@'\"]+:[^\s/@'\"]{6,}(?=@)",
923
+ r"(?i:(?<=password=)|(?<=secret=)|(?<=token=)|(?<=api_key=)|(?<=apikey=))[^\s'\"&]{8,}",
924
+ r"(?i:(?<=\"password\": \")|(?<=\"secret\": \")|(?<=\"token\": \")|(?<=\"api_key\": \"))[^\"\s]{8,}"]))
917
925
 
918
926
 
919
927
  def masked(text):
@@ -1384,7 +1392,7 @@ def report(days=7, root=None, now=None):
1384
1392
  u, t, p = r["usage"], r["t"], prices(r["model"])
1385
1393
  if not u or t is None or not p:
1386
1394
  continue
1387
- num = lambda k: u.get(k) if isinstance(u.get(k), (int, float)) else 0
1395
+ num = lambda k, u=u: u.get(k) if isinstance(u.get(k), (int, float)) else 0
1388
1396
  made = u.get("cache_creation") if isinstance(u.get("cache_creation"), dict) else {}
1389
1397
  write, read = num("cache_creation_input_tokens"), num("cache_read_input_tokens")
1390
1398
  hour = min(write, made.get("ephemeral_1h_input_tokens") or 0)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ctxtree",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Pick up a Claude Code session from a folded, lossless view of its history, instead of re-caching its whole window",
5
5
  "bin": {
6
6
  "ctxtree": "ctxtree.py"