tokensafe 4.16.1 → 4.16.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.
@@ -9,7 +9,7 @@
9
9
  "name": "tokensafe",
10
10
  "source": "./",
11
11
  "description": "Enforced context optimization for Claude Code: blocking guards, PostToolUse output compaction, symbol/AST slicing, post-compaction recovery, and measured savings.",
12
- "version": "4.16.0"
12
+ "version": "4.16.3"
13
13
  }
14
14
  ]
15
15
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tokensafe",
3
- "version": "4.16.0",
3
+ "version": "4.16.3",
4
4
  "description": "Local runtime firewall and zero-loss context optimizer for AI coding agents: enforced tool-output compaction, symbol/AST slicing, post-compaction recovery, and measured savings.",
5
5
  "author": {
6
6
  "name": "TokenSafe",
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "4.16.1",
2
+ "version": "4.16.3",
3
3
  "name": "tokensafe",
4
4
  "description": "Your AI agent is smart enough to code all day. Now it actually can. Local runtime firewall & zero-loss context optimizer for AI coding agents.",
5
5
  "author": {
package/README.md CHANGED
@@ -211,14 +211,19 @@ Why TokenSafe agents ship working code on the first pass without burning quotas
211
211
 
212
212
  Deeper mechanics (language matrix, AST syntax trees, cache tiers, governor) live in [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md).
213
213
 
214
- ## Context survival, recall, and host coverage
214
+ ## Reads, ingress, recovery, and host coverage
215
215
 
216
- Compaction is the most expensive event in a long session: the host rewrites the prompt, re-bills it uncached, and drops turns the task still depends on. TokenSafe now survives it explicitly.
216
+ Compaction is the most expensive event in a long session, and a full re-read after every edit is the most common one. TokenSafe now handles both explicitly.
217
217
 
218
218
  | Feature | Surface | What it does |
219
219
  |---|---|---|
220
+ | **Diff-on-change reads** | `smart_read_file(path, diff_since=<mtime\|sha256>)` | A changed file returns only bounded unified-diff hunks (≤5 hunks, ≤40% of the file); a rewrite falls back to a normal read. A session-scoped raw baseline makes the diff possible. |
220
221
  | **Post-compaction recovery** | Claude Code `PreCompact` / `PostCompact`; fallback detector on every host with a transcript | Reinjects a small digest: goal, last state, next focus, and up to five ranked pointers to the turns the compaction dropped. Each pointer expands with `tokensafe recall --id <session>:<index>`. |
221
222
  | **Transcript recall** | CLI `tokensafe recall '<query>' [--sessions this\|project\|all]`, MCP `session_context(action='recall_transcript')` | BM25F search over prior Claude/Codex/Kimi/ZCode/Cursor/Antigravity transcripts. No index copy; snippets are secret-redacted and output is budget-capped. |
223
+ | **Lossless ingress staging** | `TOKENSAFE_INGRESS_THRESHOLD` (default 8000 tokens), MCP `session_context(action='ingress_show')`, CLI `tokensafe ingress show` | A long prompt is stored redacted with a recovery handle; the model gets a TOCP summary plus a section index and reads exact sections on demand. `tokensafe ingress stats` reports the fetch rate. |
224
+ | **Blast-radius hint** | `apply_edits` result | After a successful edit on a warm graph, one advisory line names direct importers and static callers; no crawl, no mandatory follow-up call. |
225
+ | **Out-of-context compute** | `run_helper(action='compute')` | A restricted Python program runs over repository files (AST import/name allowlist, repo path jail, rlimits, 5 s budget) and returns only its JSON result. Inputs never enter the context. |
226
+ | **Image peek** | `smart_read_file(path='shot.png', include_image=true)` | Returns a downscaled (≤1024 px, ≤512 KiB base64) MCP image block plus one metadata line; hosts without vision keep the text. |
222
227
  | **Zero-token statusline** | Claude Code | `tokensafe statusline` renders today's measured savings in the host status bar. The line never enters the conversation. |
223
228
  | **Claude Code plugin** | `/plugin marketplace add <owner>/tokensafe` then `/plugin install tokensafe@tokensafe` | Marketplace manifest, nine lifecycle hooks (including compact events), and an MCP entry. The plugin fails open if the Python engine is absent. |
224
229
  | **Host capability matrix** | `tokensafe doctor` | States exactly which host supports hooks, compact events, context injection, statusline, and transcript parsing, so partial coverage is never sold as full. |
package/kimi.plugin.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tokensafe",
3
- "version": "4.16.1",
3
+ "version": "4.16.3",
4
4
  "description": "Your AI agent is smart enough to code all day. Now it actually can. Local runtime firewall & zero-loss context optimizer for AI coding agents.",
5
5
  "homepage": "https://tokensafe.dev",
6
6
  "license": "Apache-2.0",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tokensafe",
3
3
  "mcpName": "dev.tokensafe/tokensafe",
4
- "version": "4.16.1",
4
+ "version": "4.16.3",
5
5
  "description": "Your AI agent is smart enough to code all day. Now it actually can. Local runtime firewall & zero-loss context optimizer for AI coding agents.",
6
6
  "main": "bin/tokensafe.js",
7
7
  "bin": {
package/plugin.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tokensafe",
3
3
  "displayName": "TokenSafe",
4
- "version": "4.16.1",
4
+ "version": "4.16.3",
5
5
  "license": "Apache-2.0",
6
6
  "description": "Your AI agent is smart enough to code all day. Now it actually can. Local runtime firewall & zero-loss context optimizer for AI coding agents.",
7
7
  "logo": "assets/logo.png",
package/server.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "name": "dev.tokensafe/tokensafe",
4
4
  "title": "TokenSafe",
5
5
  "description": "Your AI agent is smart enough to code all day. Local firewall & zero-loss runtime.",
6
- "version": "4.16.1",
6
+ "version": "4.16.3",
7
7
  "websiteUrl": "https://tokensafe.dev",
8
8
  "repository": {
9
9
  "url": "https://github.com/tokensafe-dev/tokensafe",
@@ -23,7 +23,7 @@
23
23
  "registryType": "npm",
24
24
  "registryBaseUrl": "https://registry.npmjs.org",
25
25
  "identifier": "tokensafe",
26
- "version": "4.16.1",
26
+ "version": "4.16.3",
27
27
  "runtimeHint": "npx",
28
28
  "transport": {
29
29
  "type": "stdio"
@@ -39,7 +39,7 @@
39
39
  "registryType": "pypi",
40
40
  "registryBaseUrl": "https://pypi.org",
41
41
  "identifier": "tokensafe",
42
- "version": "4.16.1",
42
+ "version": "4.16.3",
43
43
  "runtimeHint": "uvx",
44
44
  "transport": {
45
45
  "type": "stdio"
@@ -182,6 +182,28 @@ def compact_for_injection(prompt: str, agent: str, session_id: str, transcript_p
182
182
  meta: Dict[str, Any] = {"agent": agent, "compacted": False}
183
183
  if not prompt or len(prompt.strip()) < 5:
184
184
  return "", meta
185
+ # Lossless ingress staging: a long prompt gets a compact summary plus a
186
+ # recovery handle, so the exact text stays retrievable instead of being
187
+ # irreversibly summarized.
188
+ try:
189
+ from src.ingress_staging import stage as _stage_ingress
190
+
191
+ staged = _stage_ingress(prompt, agent=agent, session_id=session_id)
192
+ if staged:
193
+ meta.update({
194
+ "compacted": True,
195
+ "ingress_staged": True,
196
+ "ingress_hash": staged["hash"],
197
+ "ingress_sections": len(staged["sections"]),
198
+ "original_tokens": staged["original_tokens"],
199
+ "injected_tokens": staged["injected_tokens"],
200
+ "saved_tokens": staged["saved_tokens"],
201
+ "reduction_pct": staged["reduction_pct"],
202
+ "tier": "INGRESS",
203
+ })
204
+ return staged["context_text"], meta
205
+ except Exception:
206
+ pass
185
207
  try:
186
208
  from src.compactor import PromptCompactor
187
209
  from src.tokenizer import count_tokens
@@ -251,6 +251,24 @@ class AgentFirewall:
251
251
 
252
252
  return False, None, 0
253
253
 
254
+ @classmethod
255
+ def was_delivered(cls, session_id: str, file_path: str, tracker: MetricsTracker = None) -> bool:
256
+ """Cheap read-history probe (no metrics, no hit increments)."""
257
+ if not session_id or not file_path or not os.path.exists(file_path):
258
+ return False
259
+ try:
260
+ tracker = tracker or MetricsTracker()
261
+ cls._ensure_table(tracker)
262
+ with tracker._get_connection() as conn:
263
+ row = conn.execute(
264
+ "SELECT 1 FROM subagent_file_cache "
265
+ "WHERE session_id = ? AND file_path = ? LIMIT 1",
266
+ (session_id, os.path.abspath(file_path)),
267
+ ).fetchone()
268
+ return row is not None
269
+ except Exception:
270
+ return False
271
+
254
272
  @classmethod
255
273
  def record_cache(
256
274
  cls,