tokensafe 4.15.1 → 4.16.1
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.
- package/.claude-plugin/hooks.json +124 -0
- package/.claude-plugin/marketplace.json +15 -0
- package/.claude-plugin/plugin.json +21 -0
- package/.codex-plugin/plugin.json +1 -1
- package/.mcp.json +10 -0
- package/README.md +14 -0
- package/bin/tokensafe-acp.js +38 -0
- package/bin/tokensafe-claude-hook +18 -0
- package/bin/tokensafe-mcp +17 -0
- package/hooks/claude_code_hook.py +85 -0
- package/hooks/kimi_hook.py +27 -0
- package/hooks/post_tool_use.py +10 -0
- package/hooks/pre_invocation.py +45 -6
- package/hooks/pre_tool_use.py +22 -1
- package/hooks/session_start.py +21 -0
- package/kimi.plugin.json +1 -1
- package/package.json +7 -2
- package/plugin.json +1 -1
- package/server.json +3 -3
- package/src/adapter_core.py +151 -1
- package/src/agent_firewall.py +2 -1
- package/src/angular_cli.py +189 -0
- package/src/auto_inject.py +36 -2
- package/src/backend_release.py +1 -1
- package/src/batch_editor.py +181 -24
- package/src/bench/driver.py +54 -6
- package/src/bench/runner.py +58 -8
- package/src/build_parsers.py +35 -2
- package/src/burn_monitor.py +69 -1
- package/src/cache_normalizer.py +1 -1
- package/src/cli.py +203 -2
- package/src/command_sanitizer.py +39 -11
- package/src/compaction_recovery.py +335 -0
- package/src/dashboard.py +26 -0
- package/src/delegation.py +253 -0
- package/src/format_invariants.py +158 -0
- package/src/format_parsers/game_assets.py +259 -0
- package/src/fts_index.py +1 -1
- package/src/governor.py +54 -8
- package/src/graph_engine.py +48 -0
- package/src/host_capabilities.py +180 -0
- package/src/installer.py +40 -6
- package/src/mcp_server.py +463 -45
- package/src/metrics.py +180 -3
- package/src/session_brief.py +1 -1
- package/src/skeletonizer.py +51 -0
- package/src/statusline.py +44 -0
- package/src/telemetry_sync.py +1 -1
- package/src/transcript_recall.py +565 -0
- package/src/usage_ledger.py +346 -0
- package/src/version_checker.py +1 -1
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.
|
|
6
|
+
"version": "4.16.1",
|
|
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.
|
|
26
|
+
"version": "4.16.1",
|
|
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.
|
|
42
|
+
"version": "4.16.1",
|
|
43
43
|
"runtimeHint": "uvx",
|
|
44
44
|
"transport": {
|
|
45
45
|
"type": "stdio"
|
package/src/adapter_core.py
CHANGED
|
@@ -17,7 +17,7 @@ import sys
|
|
|
17
17
|
import re
|
|
18
18
|
import json
|
|
19
19
|
import time
|
|
20
|
-
from typing import Dict, Any, Optional, Tuple
|
|
20
|
+
from typing import Dict, Any, List, Optional, Tuple
|
|
21
21
|
|
|
22
22
|
from src.tokenizer import count_tokens
|
|
23
23
|
|
|
@@ -38,6 +38,7 @@ TOKENSAFE_DIRECTIVES = (
|
|
|
38
38
|
"• Deduplication & Cache Pointers: Never re-read unchanged files repeatedly; reuse earlier context or pointer references.\n"
|
|
39
39
|
"• Zero-Fluff Egress: Omit conversational filler, courtesy preambles, and wrap-ups. Format responses in dense, technical prose.\n"
|
|
40
40
|
"• Surgical Code Diffs: Never reprint full unmodified files or lengthy boilerplate; cite line ranges and provide targeted diffs (use apply_edits for multi-file edits and run_helper for sanitize/guard/deps/web/expand/image).\n"
|
|
41
|
+
"• apply_edits already runs the project's own test command and returns the verdict in the same call; do not re-read the edited file or run the suite again unless strict_verify=true was used.\n"
|
|
41
42
|
"• Compact Test Execution: Run unit tests with concise flags or via 'tokensafe tests [cmd]' so passing suites emit a 1-line summary.\n"
|
|
42
43
|
"• Mandatory Architecture Graph & God Nodes: For any codebase inquiry, navigation, or multi-component work, ALWAYS inspect God Nodes via 'tokensafe:repo_map(view=\"graph\", project_path=...)' first before diving into files (pass target project's absolute path in multi-repo setups).\n"
|
|
43
44
|
"• To inspect all exported types/interfaces or directory trees: call 'tokensafe:repo_map(view=\"api\"|\"tree\", project_path=...)'.\n"
|
|
@@ -431,6 +432,141 @@ def guard_write(file_path: str, content: str, append: bool = False, agent: str =
|
|
|
431
432
|
)
|
|
432
433
|
|
|
433
434
|
|
|
435
|
+
def _env_int(name: str, default: int) -> int:
|
|
436
|
+
try:
|
|
437
|
+
return int(os.environ.get(name, str(default)))
|
|
438
|
+
except (TypeError, ValueError):
|
|
439
|
+
return default
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
def _edit_replacements(tool_input: Dict[str, Any]) -> List[str]:
|
|
443
|
+
"""Collects the replacement text of Edit-like payloads (Edit/MultiEdit/
|
|
444
|
+
apply_edits/apply_patch-normalized shapes)."""
|
|
445
|
+
keys = ("new_string", "new_text", "replacement", "new_content", "content", "Content")
|
|
446
|
+
reps: List[str] = []
|
|
447
|
+
|
|
448
|
+
def _take(obj: Dict[str, Any]) -> None:
|
|
449
|
+
for key in keys:
|
|
450
|
+
val = obj.get(key)
|
|
451
|
+
if isinstance(val, str) and val:
|
|
452
|
+
reps.append(val)
|
|
453
|
+
return
|
|
454
|
+
|
|
455
|
+
_take(tool_input)
|
|
456
|
+
items = tool_input.get("edits")
|
|
457
|
+
if isinstance(items, list):
|
|
458
|
+
for item in items:
|
|
459
|
+
if isinstance(item, dict):
|
|
460
|
+
_take(item)
|
|
461
|
+
return reps
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
def guard_edit_rewrite(
|
|
465
|
+
file_path: str,
|
|
466
|
+
tool_input: Dict[str, Any],
|
|
467
|
+
agent: str = "",
|
|
468
|
+
session_id: str = "",
|
|
469
|
+
transcript_path: str = "",
|
|
470
|
+
) -> Dict[str, Any]:
|
|
471
|
+
"""Edit-path twin of guard_write: an Edit that re-emits most of an existing
|
|
472
|
+
file costs the same output tokens as a wholesale Write, so it earns the same
|
|
473
|
+
ask. Only asks; never denies. Kill switch: TOKENSAFE_EDIT_REWRITE_GUARD=0."""
|
|
474
|
+
result = {"decision": "allow", "reason": "", "saved_tokens": 0}
|
|
475
|
+
if os.environ.get("TOKENSAFE_EDIT_REWRITE_GUARD", "1").strip().lower() in ("0", "false", "no"):
|
|
476
|
+
return result
|
|
477
|
+
if not file_path or not os.path.isfile(file_path):
|
|
478
|
+
return result
|
|
479
|
+
replacements = _edit_replacements(tool_input)
|
|
480
|
+
if not replacements:
|
|
481
|
+
return result
|
|
482
|
+
try:
|
|
483
|
+
with open(file_path, "r", encoding="utf-8", errors="replace") as f:
|
|
484
|
+
existing_text = f.read()
|
|
485
|
+
except Exception:
|
|
486
|
+
return result
|
|
487
|
+
existing_lines = existing_text.splitlines()
|
|
488
|
+
if len(existing_lines) < _env_int("TOKENSAFE_EDIT_REWRITE_MIN_LINES", 40):
|
|
489
|
+
return result
|
|
490
|
+
|
|
491
|
+
replacement = "\n".join(replacements)
|
|
492
|
+
replacement_tokens = max(1, count_tokens(replacement))
|
|
493
|
+
file_tokens = max(1, count_tokens(existing_text))
|
|
494
|
+
ratio = replacement_tokens / file_tokens
|
|
495
|
+
if ratio < float(os.environ.get("TOKENSAFE_EDIT_REWRITE_RATIO", "0.6")):
|
|
496
|
+
return result
|
|
497
|
+
|
|
498
|
+
tracker = _get_tracker()
|
|
499
|
+
if tracker:
|
|
500
|
+
try:
|
|
501
|
+
tracker.record_event(
|
|
502
|
+
session_id=session_id or f"hook_{agent}",
|
|
503
|
+
event_type="OUTPUT_GUARD",
|
|
504
|
+
original_tokens=replacement_tokens,
|
|
505
|
+
optimized_tokens=max(1, replacement_tokens // 4),
|
|
506
|
+
details={
|
|
507
|
+
"agent": agent,
|
|
508
|
+
"target_file": os.path.basename(file_path),
|
|
509
|
+
"existing_lines": len(existing_lines),
|
|
510
|
+
"ratio": round(ratio, 2),
|
|
511
|
+
"decision": "ask_edit_rewrite",
|
|
512
|
+
"model": resolve_event_model(transcript_path, session_id),
|
|
513
|
+
},
|
|
514
|
+
)
|
|
515
|
+
except Exception:
|
|
516
|
+
pass
|
|
517
|
+
return {
|
|
518
|
+
"decision": "ask",
|
|
519
|
+
"reason": (
|
|
520
|
+
f"TokenSafe Output Guard: this Edit re-emits ~{ratio:.0%} of '{os.path.basename(file_path)}' "
|
|
521
|
+
f"({replacement_tokens} vs {file_tokens} tokens). Prefer apply_edits with narrow hunks "
|
|
522
|
+
f"(target + replacement); use a true rewrite only when the file really changes wholesale."
|
|
523
|
+
),
|
|
524
|
+
"saved_tokens": max(0, replacement_tokens - max(1, replacement_tokens // 4)),
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
def guard_batch_payload(
|
|
529
|
+
tool_input: Dict[str, Any],
|
|
530
|
+
agent: str = "",
|
|
531
|
+
session_id: str = "",
|
|
532
|
+
transcript_path: str = "",
|
|
533
|
+
) -> Dict[str, Any]:
|
|
534
|
+
"""PreToolUse cap for apply_edits/apply_patch payloads (defense in depth:
|
|
535
|
+
batch_editor enforces the same limits at execution time)."""
|
|
536
|
+
result = {"decision": "allow", "reason": ""}
|
|
537
|
+
max_chars = _env_int("TOKENSAFE_MAX_BATCH_CHARS", 600_000)
|
|
538
|
+
max_replacement = _env_int("TOKENSAFE_MAX_REPLACEMENT_CHARS", 200_000)
|
|
539
|
+
max_hunks = _env_int("TOKENSAFE_MAX_HUNKS_PER_FILE", 200)
|
|
540
|
+
|
|
541
|
+
patch = tool_input.get("patch") or tool_input.get("input")
|
|
542
|
+
if isinstance(patch, str) and len(patch) > max_chars:
|
|
543
|
+
return {"decision": "deny", "reason": f"TokenSafe Output Guard: patch payload is {len(patch):,} chars (cap {max_chars:,})."}
|
|
544
|
+
|
|
545
|
+
items = tool_input.get("edits")
|
|
546
|
+
if not isinstance(items, list):
|
|
547
|
+
return result
|
|
548
|
+
total = 0
|
|
549
|
+
for item in items:
|
|
550
|
+
if not isinstance(item, dict):
|
|
551
|
+
continue
|
|
552
|
+
path = str(item.get("path") or "?")
|
|
553
|
+
create = item.get("create")
|
|
554
|
+
if isinstance(create, str):
|
|
555
|
+
if len(create) > max_replacement:
|
|
556
|
+
return {"decision": "deny", "reason": f"TokenSafe Output Guard: 'create' for {path} is {len(create):,} chars (cap {max_replacement:,})."}
|
|
557
|
+
total += len(create)
|
|
558
|
+
hunks = item.get("hunks")
|
|
559
|
+
if isinstance(hunks, list):
|
|
560
|
+
if len(hunks) > max_hunks:
|
|
561
|
+
return {"decision": "deny", "reason": f"TokenSafe Output Guard: {len(hunks)} hunks for {path} (cap {max_hunks})."}
|
|
562
|
+
for hunk in hunks:
|
|
563
|
+
if isinstance(hunk, dict):
|
|
564
|
+
total += len(str(hunk.get("target") or "")) + len(str(hunk.get("replacement") or ""))
|
|
565
|
+
if total > max_chars:
|
|
566
|
+
return {"decision": "deny", "reason": f"TokenSafe Output Guard: batch payload exceeds {max_chars:,} chars."}
|
|
567
|
+
return result
|
|
568
|
+
|
|
569
|
+
|
|
434
570
|
_CODE_EXTS = {
|
|
435
571
|
".py", ".ts", ".tsx", ".js", ".jsx", ".go", ".rs", ".java", ".kt", ".swift",
|
|
436
572
|
".c", ".cpp", ".h", ".hpp", ".cs", ".rb", ".php", ".vue", ".svelte",
|
|
@@ -448,6 +584,11 @@ def canonical_tool_name(name: str) -> str:
|
|
|
448
584
|
return "edit"
|
|
449
585
|
if t in ("Read", "read_file", "view_file", "view_file_outline"):
|
|
450
586
|
return "read"
|
|
587
|
+
if t.lower() in (
|
|
588
|
+
"apply_edits", "tokensafe:apply_edits", "mcp__tokensafe__apply_edits",
|
|
589
|
+
"apply_patch", "applypatch",
|
|
590
|
+
):
|
|
591
|
+
return "batch_edit"
|
|
451
592
|
return t.lower()
|
|
452
593
|
|
|
453
594
|
|
|
@@ -691,6 +832,9 @@ def evaluate_cc_pre_tool_use(payload: Dict[str, Any], agent: str) -> Dict[str, A
|
|
|
691
832
|
)
|
|
692
833
|
except Exception:
|
|
693
834
|
pass
|
|
835
|
+
rewrite = guard_edit_rewrite(file_path, tool_input, agent, session_id, transcript_path=tp)
|
|
836
|
+
if rewrite["decision"] == "ask":
|
|
837
|
+
return _cc_decision("ask", rewrite["reason"])
|
|
694
838
|
# Advisory only, and only for hosts whose PreToolUse schema documents
|
|
695
839
|
# additionalContext (Claude Code): omitting permissionDecision keeps the
|
|
696
840
|
# normal permission flow, while returning "allow" used to auto-approve edits.
|
|
@@ -706,6 +850,12 @@ def evaluate_cc_pre_tool_use(payload: Dict[str, Any], agent: str) -> Dict[str, A
|
|
|
706
850
|
}
|
|
707
851
|
return {}
|
|
708
852
|
|
|
853
|
+
if canon == "batch_edit":
|
|
854
|
+
verdict = guard_batch_payload(tool_input, agent, session_id, transcript_path=tp)
|
|
855
|
+
if verdict["decision"] == "deny":
|
|
856
|
+
return _cc_decision("deny", verdict["reason"])
|
|
857
|
+
return {}
|
|
858
|
+
|
|
709
859
|
if canon == "read":
|
|
710
860
|
file_path = _extract_path(tool_input)
|
|
711
861
|
verdict = guard_read(file_path, agent, session_id, transcript_path=tp)
|
package/src/agent_firewall.py
CHANGED
|
@@ -203,9 +203,10 @@ class AgentFirewall:
|
|
|
203
203
|
|
|
204
204
|
if use_pointer:
|
|
205
205
|
sym_label = f"::{symbol_key}" if symbol_key else ""
|
|
206
|
+
mtime_iso = time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime(current_mtime))
|
|
206
207
|
payload = (
|
|
207
208
|
f"// [TokenSafe Subagent Firewall: Pointer Hit for '{os.path.basename(abs_path)}{sym_label}' "
|
|
208
|
-
f"(unchanged, sha256:{short_hash}) — reuse the content returned earlier in this session; "
|
|
209
|
+
f"(unchanged, sha256:{short_hash}, mtime={mtime_iso}) — reuse the content returned earlier in this session; "
|
|
209
210
|
f"if you are a fresh subagent or your context was compacted, re-call smart_read_file with force_full=true]\n"
|
|
210
211
|
)
|
|
211
212
|
opt_tokens = count_tokens(payload)
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"""Angular CLI injection: point a workspace's `serve` target at the TokenSafe builder.
|
|
2
|
+
|
|
3
|
+
`ng serve` is the only way into an Angular app that is not on Vite, and it has no
|
|
4
|
+
third-party plugin slot. What it does have is a configurable builder per project:
|
|
5
|
+
`projects.<name>.architect.serve.builder`. This module rewrites that value to
|
|
6
|
+
`tokensafe-ui:dev-server` (the builder registered by `tokensafe-ui/builders.json`)
|
|
7
|
+
and records the previous value so
|
|
8
|
+
`tokensafe inject --revert` restores byte-for-byte what was there.
|
|
9
|
+
|
|
10
|
+
Refusals are deliberate:
|
|
11
|
+
- no `angular.json` / no `architect.serve` → nothing to point at;
|
|
12
|
+
- the builder package is not installed in the workspace → `ng serve` would fail
|
|
13
|
+
while `tokensafe` claimed the app was wired, so the inject reports the install
|
|
14
|
+
command instead of writing a builder it cannot resolve.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
import json
|
|
18
|
+
import os
|
|
19
|
+
from typing import Any, Dict, Optional
|
|
20
|
+
|
|
21
|
+
BUILDER_ID = "tokensafe-ui:dev-server"
|
|
22
|
+
INSTALL_COMMAND = "npm install --save-dev tokensafe-ui"
|
|
23
|
+
STATE_REL_PATH = os.path.join(".tokensafe", "angular-cli.json")
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _angular_json(app_root: str) -> str:
|
|
27
|
+
return os.path.join(app_root, "angular.json")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _state_path(workspace: str) -> str:
|
|
31
|
+
return os.path.join(workspace, STATE_REL_PATH)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _load_state(workspace: str) -> Dict[str, Any]:
|
|
35
|
+
try:
|
|
36
|
+
with open(_state_path(workspace), "r", encoding="utf-8") as handle:
|
|
37
|
+
data = json.load(handle)
|
|
38
|
+
return data if isinstance(data, dict) else {}
|
|
39
|
+
except Exception:
|
|
40
|
+
return {}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _save_state(workspace: str, state: Dict[str, Any]) -> None:
|
|
44
|
+
from src.atomic_io import write_text_atomic
|
|
45
|
+
|
|
46
|
+
path = _state_path(workspace)
|
|
47
|
+
os.makedirs(os.path.dirname(path), exist_ok=True)
|
|
48
|
+
write_text_atomic(path, json.dumps(state, indent=2, ensure_ascii=False))
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _read_angular_json(app_root: str) -> Optional[Dict[str, Any]]:
|
|
52
|
+
try:
|
|
53
|
+
with open(_angular_json(app_root), "r", encoding="utf-8") as handle:
|
|
54
|
+
data = json.load(handle)
|
|
55
|
+
return data if isinstance(data, dict) else None
|
|
56
|
+
except Exception:
|
|
57
|
+
return None
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _ensure_tokensafe_gitignored(app_root: str) -> None:
|
|
61
|
+
try:
|
|
62
|
+
from src.paths import ensure_tokensafe_gitignore
|
|
63
|
+
|
|
64
|
+
ensure_tokensafe_gitignore(app_root)
|
|
65
|
+
except Exception:
|
|
66
|
+
pass
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def package_installed(app_root: str) -> bool:
|
|
70
|
+
"""The builder must be resolvable from the workspace or `ng serve` cannot load it.
|
|
71
|
+
|
|
72
|
+
The builder ships as `tokensafe-ui:dev-server` (subpath `tokensafe-ui/angular-builder`),
|
|
73
|
+
so the package itself and its `builders.json` must both be present: an older
|
|
74
|
+
`tokensafe-ui` without the builder must not look installed.
|
|
75
|
+
"""
|
|
76
|
+
package_root = os.path.join(app_root, "node_modules", "tokensafe-ui")
|
|
77
|
+
return os.path.isfile(os.path.join(package_root, "package.json")) and os.path.isfile(
|
|
78
|
+
os.path.join(package_root, "builders.json")
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def serve_targets(data: Dict[str, Any]) -> Dict[str, Dict[str, Any]]:
|
|
83
|
+
"""Project name → its `architect.serve` block (Angular keeps it under `architect`)."""
|
|
84
|
+
out: Dict[str, Dict[str, Any]] = {}
|
|
85
|
+
for name, project in (data.get("projects") or {}).items():
|
|
86
|
+
if not isinstance(project, dict):
|
|
87
|
+
continue
|
|
88
|
+
architect = project.get("architect") if isinstance(project.get("architect"), dict) else {}
|
|
89
|
+
serve = architect.get("serve") if isinstance(architect.get("serve"), dict) else {}
|
|
90
|
+
if serve:
|
|
91
|
+
out[name] = serve
|
|
92
|
+
return out
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def patch_state(app_root: str) -> Dict[str, Any]:
|
|
96
|
+
"""What `apply` would find: is there a target, is it already patched, is the package installed."""
|
|
97
|
+
data = _read_angular_json(app_root)
|
|
98
|
+
if data is None:
|
|
99
|
+
return {"patched": False, "projects": [], "reason": f"no readable angular.json in {app_root}"}
|
|
100
|
+
targets = serve_targets(data)
|
|
101
|
+
if not targets:
|
|
102
|
+
return {"patched": False, "projects": [], "reason": "angular.json has no architect.serve target"}
|
|
103
|
+
already = [name for name, serve in targets.items() if str(serve.get("builder") or "") == BUILDER_ID]
|
|
104
|
+
return {
|
|
105
|
+
"patched": len(already) == len(targets),
|
|
106
|
+
"projects": sorted(targets),
|
|
107
|
+
"patched_projects": sorted(already),
|
|
108
|
+
"installed": package_installed(app_root),
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def apply(workspace: str, app_root: str, dry_run: bool = False) -> Dict[str, Any]:
|
|
113
|
+
"""Rewrites `architect.serve.builder` for every project in the app."""
|
|
114
|
+
state = patch_state(app_root)
|
|
115
|
+
if state.get("reason"):
|
|
116
|
+
return {"status": "skipped", "kind": "angular_cli_builder", "reason": state["reason"]}
|
|
117
|
+
if not state.get("installed"):
|
|
118
|
+
return {
|
|
119
|
+
"status": "skipped",
|
|
120
|
+
"kind": "angular_cli_builder",
|
|
121
|
+
"reason": "the TokenSafe Angular builder is not installed in this workspace, so ng serve could not load it",
|
|
122
|
+
"install": INSTALL_COMMAND,
|
|
123
|
+
}
|
|
124
|
+
data = _read_angular_json(app_root) or {}
|
|
125
|
+
targets = serve_targets(data)
|
|
126
|
+
previous: Dict[str, str] = {}
|
|
127
|
+
for name, serve in targets.items():
|
|
128
|
+
previous[name] = str(serve.get("builder") or "")
|
|
129
|
+
serve["builder"] = BUILDER_ID
|
|
130
|
+
|
|
131
|
+
if not dry_run:
|
|
132
|
+
from src.atomic_io import write_text_atomic
|
|
133
|
+
|
|
134
|
+
write_text_atomic(_angular_json(app_root), json.dumps(data, indent=2, ensure_ascii=False) + "\n")
|
|
135
|
+
recorded = _load_state(workspace)
|
|
136
|
+
apps = recorded.get("apps") if isinstance(recorded.get("apps"), dict) else {}
|
|
137
|
+
apps[os.path.abspath(app_root)] = previous
|
|
138
|
+
recorded["apps"] = apps
|
|
139
|
+
_save_state(workspace, recorded)
|
|
140
|
+
_ensure_tokensafe_gitignored(app_root)
|
|
141
|
+
|
|
142
|
+
return {
|
|
143
|
+
"status": "ready",
|
|
144
|
+
"kind": "angular_cli_builder",
|
|
145
|
+
"builder": BUILDER_ID,
|
|
146
|
+
"projects": sorted(previous),
|
|
147
|
+
"previous": previous,
|
|
148
|
+
"dry_run": dry_run,
|
|
149
|
+
"run": "ng serve",
|
|
150
|
+
"note": "the bridge is served by the builder; no source file is touched",
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def revert_all(workspace: str) -> Dict[str, Any]:
|
|
155
|
+
"""Restores every recorded builder value and removes the state file."""
|
|
156
|
+
recorded = _load_state(workspace)
|
|
157
|
+
apps = recorded.get("apps") if isinstance(recorded.get("apps"), dict) else {}
|
|
158
|
+
restored: Dict[str, Any] = {}
|
|
159
|
+
for app_root, previous in apps.items():
|
|
160
|
+
if not isinstance(previous, dict):
|
|
161
|
+
continue
|
|
162
|
+
data = _read_angular_json(app_root)
|
|
163
|
+
if data is None:
|
|
164
|
+
restored[app_root] = {"status": "skipped", "reason": "angular.json is missing"}
|
|
165
|
+
continue
|
|
166
|
+
targets = serve_targets(data)
|
|
167
|
+
changed = []
|
|
168
|
+
for name, builder in previous.items():
|
|
169
|
+
serve = targets.get(name)
|
|
170
|
+
if not serve:
|
|
171
|
+
continue
|
|
172
|
+
if str(serve.get("builder") or "") != BUILDER_ID:
|
|
173
|
+
# Someone changed it after the inject: leave their value alone.
|
|
174
|
+
continue
|
|
175
|
+
serve["builder"] = builder
|
|
176
|
+
changed.append(name)
|
|
177
|
+
if changed:
|
|
178
|
+
from src.atomic_io import write_text_atomic
|
|
179
|
+
|
|
180
|
+
write_text_atomic(_angular_json(app_root), json.dumps(data, indent=2, ensure_ascii=False) + "\n")
|
|
181
|
+
restored[app_root] = {"status": "reverted", "projects": changed}
|
|
182
|
+
try:
|
|
183
|
+
if os.path.isfile(_state_path(workspace)):
|
|
184
|
+
os.unlink(_state_path(workspace))
|
|
185
|
+
except OSError:
|
|
186
|
+
pass
|
|
187
|
+
if not restored:
|
|
188
|
+
return {"status": "nothing-to-revert"}
|
|
189
|
+
return {"status": "reverted", "apps": restored}
|
package/src/auto_inject.py
CHANGED
|
@@ -28,6 +28,8 @@ import glob
|
|
|
28
28
|
import hashlib
|
|
29
29
|
import json
|
|
30
30
|
import os
|
|
31
|
+
|
|
32
|
+
from src import angular_cli
|
|
31
33
|
import re
|
|
32
34
|
import shutil
|
|
33
35
|
import subprocess
|
|
@@ -1937,12 +1939,12 @@ _SIDECARS = {
|
|
|
1937
1939
|
"spring": (
|
|
1938
1940
|
"java/src/dev/tokensafe/oumv/OumvSpring.java",
|
|
1939
1941
|
"OumvSpring.java",
|
|
1940
|
-
"
|
|
1942
|
+
"6d99e1165b62a8053dcb3ae08bebeb5f6dd7d092e9b39eb98deaf596afd3c4e7",
|
|
1941
1943
|
),
|
|
1942
1944
|
"php": (
|
|
1943
1945
|
"php/bin/oumv-php",
|
|
1944
1946
|
"oumv-php",
|
|
1945
|
-
"
|
|
1947
|
+
"a075372d575c394d42134b5af62f0f228c271a1ce95984bf4dae9811808945fd",
|
|
1946
1948
|
),
|
|
1947
1949
|
}
|
|
1948
1950
|
|
|
@@ -2191,6 +2193,27 @@ def plan(workspace: str) -> Dict[str, Any]:
|
|
|
2191
2193
|
}
|
|
2192
2194
|
actions.append(action)
|
|
2193
2195
|
continue
|
|
2196
|
+
if framework in ("angular", "angular-cli"):
|
|
2197
|
+
app_root = _app_root(workspace, root)
|
|
2198
|
+
angular_state = angular_cli.patch_state(app_root)
|
|
2199
|
+
if angular_state.get("projects"):
|
|
2200
|
+
actions.append({
|
|
2201
|
+
"kind": "angular_cli_builder",
|
|
2202
|
+
"profile": "frontend",
|
|
2203
|
+
"app": root,
|
|
2204
|
+
"framework": "angular",
|
|
2205
|
+
"writes_repo": True,
|
|
2206
|
+
"already_patched": angular_state["patched"],
|
|
2207
|
+
"projects": angular_state["projects"],
|
|
2208
|
+
"installed": angular_state.get("installed"),
|
|
2209
|
+
"install": angular_cli.INSTALL_COMMAND,
|
|
2210
|
+
"run": "ng serve",
|
|
2211
|
+
"description": (
|
|
2212
|
+
"points projects.*.architect.serve.builder at "
|
|
2213
|
+
f"{angular_cli.BUILDER_ID}; no source file is touched and --revert restores the previous builder"
|
|
2214
|
+
),
|
|
2215
|
+
})
|
|
2216
|
+
continue
|
|
2194
2217
|
if not app["supported"]:
|
|
2195
2218
|
reason = app["reason"] or f"no OUMV adapter for {framework} yet"
|
|
2196
2219
|
actions.append({
|
|
@@ -2388,6 +2411,16 @@ def apply(workspace: str, dry_run: bool = False, include_go: bool = True) -> Dic
|
|
|
2388
2411
|
"app": root,
|
|
2389
2412
|
**apply_next_patch(workspace, dry_run=dry_run, root=root),
|
|
2390
2413
|
})
|
|
2414
|
+
elif framework in ("angular", "angular-cli"):
|
|
2415
|
+
app_root = _app_root(workspace, root)
|
|
2416
|
+
if angular_cli.patch_state(app_root).get("projects"):
|
|
2417
|
+
results["actions"].append({
|
|
2418
|
+
"kind": "angular_cli_builder",
|
|
2419
|
+
"profile": "frontend",
|
|
2420
|
+
"app": root,
|
|
2421
|
+
**angular_cli.apply(workspace, app_root, dry_run=dry_run),
|
|
2422
|
+
})
|
|
2423
|
+
continue
|
|
2391
2424
|
elif not app["supported"]:
|
|
2392
2425
|
results["actions"].append({
|
|
2393
2426
|
"kind": "frontend_unsupported",
|
|
@@ -2555,4 +2588,5 @@ def revert(workspace: str) -> Dict[str, Any]:
|
|
|
2555
2588
|
results[kind] = _revert_manifest(workspace, kind, manifest)
|
|
2556
2589
|
|
|
2557
2590
|
results["config"] = revert_config(workspace)
|
|
2591
|
+
results["angular_cli_builder"] = angular_cli.revert_all(workspace)
|
|
2558
2592
|
return results
|
package/src/backend_release.py
CHANGED
|
@@ -10,7 +10,7 @@ from __future__ import annotations
|
|
|
10
10
|
|
|
11
11
|
# Backend tag (`vX.Y.Z`); the Go module resolves against the matching `go/vX.Y.Z`,
|
|
12
12
|
# which the backend release workflow creates alongside it.
|
|
13
|
-
BACKEND_RELEASE_TAG = "v0.
|
|
13
|
+
BACKEND_RELEASE_TAG = "v0.22.1"
|
|
14
14
|
|
|
15
15
|
# Wire version that tag speaks. Printed in briefs so an agent never mixes a
|
|
16
16
|
# backend release with an older protocol line.
|