navcli 0.2.3__tar.gz → 0.2.4__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 (45) hide show
  1. {navcli-0.2.3 → navcli-0.2.4}/PKG-INFO +1 -1
  2. {navcli-0.2.3 → navcli-0.2.4}/navcli/server/__init__.py +7 -1
  3. {navcli-0.2.3 → navcli-0.2.4}/navcli/server/browser.py +34 -0
  4. {navcli-0.2.3 → navcli-0.2.4}/navcli/server/routes/navigation.py +13 -1
  5. {navcli-0.2.3 → navcli-0.2.4}/navcli.egg-info/PKG-INFO +1 -1
  6. {navcli-0.2.3 → navcli-0.2.4}/pyproject.toml +1 -1
  7. {navcli-0.2.3 → navcli-0.2.4}/README.md +0 -0
  8. {navcli-0.2.3 → navcli-0.2.4}/docs/README.md +0 -0
  9. {navcli-0.2.3 → navcli-0.2.4}/navcli/cli/__init__.py +0 -0
  10. {navcli-0.2.3 → navcli-0.2.4}/navcli/cli/app.py +0 -0
  11. {navcli-0.2.3 → navcli-0.2.4}/navcli/cli/client.py +0 -0
  12. {navcli-0.2.3 → navcli-0.2.4}/navcli/cli/commands/__init__.py +0 -0
  13. {navcli-0.2.3 → navcli-0.2.4}/navcli/cli/commands/base.py +0 -0
  14. {navcli-0.2.3 → navcli-0.2.4}/navcli/cli/commands/control.py +0 -0
  15. {navcli-0.2.3 → navcli-0.2.4}/navcli/cli/commands/explore.py +0 -0
  16. {navcli-0.2.3 → navcli-0.2.4}/navcli/cli/commands/interaction.py +0 -0
  17. {navcli-0.2.3 → navcli-0.2.4}/navcli/cli/commands/navigation.py +0 -0
  18. {navcli-0.2.3 → navcli-0.2.4}/navcli/cli/commands/query.py +0 -0
  19. {navcli-0.2.3 → navcli-0.2.4}/navcli/core/__init__.py +0 -0
  20. {navcli-0.2.3 → navcli-0.2.4}/navcli/core/models/__init__.py +0 -0
  21. {navcli-0.2.3 → navcli-0.2.4}/navcli/core/models/dom.py +0 -0
  22. {navcli-0.2.3 → navcli-0.2.4}/navcli/core/models/element.py +0 -0
  23. {navcli-0.2.3 → navcli-0.2.4}/navcli/core/models/feedback.py +0 -0
  24. {navcli-0.2.3 → navcli-0.2.4}/navcli/core/models/state.py +0 -0
  25. {navcli-0.2.3 → navcli-0.2.4}/navcli/server/app.py +0 -0
  26. {navcli-0.2.3 → navcli-0.2.4}/navcli/server/middleware/__init__.py +0 -0
  27. {navcli-0.2.3 → navcli-0.2.4}/navcli/server/routes/__init__.py +0 -0
  28. {navcli-0.2.3 → navcli-0.2.4}/navcli/server/routes/control.py +0 -0
  29. {navcli-0.2.3 → navcli-0.2.4}/navcli/server/routes/explore.py +0 -0
  30. {navcli-0.2.3 → navcli-0.2.4}/navcli/server/routes/interaction.py +0 -0
  31. {navcli-0.2.3 → navcli-0.2.4}/navcli/server/routes/query.py +0 -0
  32. {navcli-0.2.3 → navcli-0.2.4}/navcli/server/routes/session.py +0 -0
  33. {navcli-0.2.3 → navcli-0.2.4}/navcli/utils/__init__.py +0 -0
  34. {navcli-0.2.3 → navcli-0.2.4}/navcli/utils/image.py +0 -0
  35. {navcli-0.2.3 → navcli-0.2.4}/navcli/utils/js.py +0 -0
  36. {navcli-0.2.3 → navcli-0.2.4}/navcli/utils/selector.py +0 -0
  37. {navcli-0.2.3 → navcli-0.2.4}/navcli/utils/text.py +0 -0
  38. {navcli-0.2.3 → navcli-0.2.4}/navcli/utils/time.py +0 -0
  39. {navcli-0.2.3 → navcli-0.2.4}/navcli/utils/url.py +0 -0
  40. {navcli-0.2.3 → navcli-0.2.4}/navcli.egg-info/SOURCES.txt +0 -0
  41. {navcli-0.2.3 → navcli-0.2.4}/navcli.egg-info/dependency_links.txt +0 -0
  42. {navcli-0.2.3 → navcli-0.2.4}/navcli.egg-info/entry_points.txt +0 -0
  43. {navcli-0.2.3 → navcli-0.2.4}/navcli.egg-info/requires.txt +0 -0
  44. {navcli-0.2.3 → navcli-0.2.4}/navcli.egg-info/top_level.txt +0 -0
  45. {navcli-0.2.3 → navcli-0.2.4}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: navcli
3
- Version: 0.2.3
3
+ Version: 0.2.4
4
4
  Summary: 可交互、可探索的浏览器命令行工具,专为 AI Agent 设计
5
5
  Author: NavCLI Team
6
6
  License: MIT
@@ -10,7 +10,7 @@ import uvicorn
10
10
  from uvicorn.config import Config
11
11
 
12
12
  from navcli.server.app import create_app
13
- from navcli.server.browser import start_browser, close_browser
13
+ from navcli.server.browser import start_browser, close_browser, _SNAPSHOT_PATH
14
14
 
15
15
  __version__ = "0.1.0"
16
16
 
@@ -115,6 +115,12 @@ def main():
115
115
  print(' nav load_session <name>')
116
116
  else:
117
117
  print("No saved sessions found.")
118
+
119
+ # Auto-save snapshot info
120
+ print(f"\nAuto-save snapshot: {_SNAPSHOT_PATH}")
121
+ if os.path.exists(_SNAPSHOT_PATH):
122
+ print("Session snapshot: Will be loaded on startup (auto)")
123
+
118
124
  print("\nTo save a session after manual login:")
119
125
  print(' curl -X POST "http://localhost:8765/cmd/session/save?name=<name>"')
120
126
  print(' nav save_session <name>')
@@ -23,6 +23,8 @@ _dom_version: int = 0
23
23
  _NAVCLI_HOME = os.path.expanduser("~/.navcli")
24
24
  _NAVCLI_SESSIONS_DIR = os.path.join(_NAVCLI_HOME, "sessions")
25
25
  _storage_state_path: str = os.path.join(_NAVCLI_SESSIONS_DIR, "session.json") # Default session file
26
+ # Auto-save snapshot path
27
+ _SNAPSHOT_PATH: str = os.path.join(_NAVCLI_HOME, "session_snapshot.json")
26
28
 
27
29
 
28
30
  async def start_browser(headless: bool = True, args: Optional[list] = None):
@@ -66,6 +68,14 @@ async def start_browser(headless: bool = True, args: Optional[list] = None):
66
68
  _context = await _browser.new_context()
67
69
  _page = await _context.new_page()
68
70
 
71
+ # Auto-load session snapshot on startup
72
+ if os.path.exists(_SNAPSHOT_PATH):
73
+ try:
74
+ await load_session(_SNAPSHOT_PATH)
75
+ print(f"[SESSION] Loaded snapshot from {_SNAPSHOT_PATH}")
76
+ except Exception as e:
77
+ print(f"[SESSION] Failed to load snapshot: {e}")
78
+
69
79
 
70
80
  async def close_browser():
71
81
  """Close the browser."""
@@ -119,6 +129,30 @@ async def save_session(path: str = None) -> Dict[str, Any]:
119
129
  return storage_state
120
130
 
121
131
 
132
+ async def auto_save_snapshot() -> None:
133
+ """Auto-save session snapshot to the snapshot file.
134
+
135
+ This is called automatically after page navigation.
136
+ """
137
+ global _SNAPSHOT_PATH
138
+
139
+ if _context is None:
140
+ return
141
+
142
+ try:
143
+ # Ensure directory exists
144
+ os.makedirs(os.path.dirname(_SNAPSHOT_PATH), exist_ok=True)
145
+
146
+ # Get storage state from Playwright
147
+ storage_state = await _context.storage_state()
148
+
149
+ # Save to snapshot file
150
+ with open(_SNAPSHOT_PATH, "w") as f:
151
+ json.dump(storage_state, f, indent=2)
152
+ except Exception:
153
+ pass # Silently fail - session snapshot is not critical
154
+
155
+
122
156
  async def load_session(path: str = None) -> None:
123
157
  """Load session (cookies, localStorage, sessionStorage) from file.
124
158
 
@@ -5,7 +5,7 @@ from typing import Optional
5
5
  from fastapi import APIRouter, HTTPException, Query
6
6
 
7
7
  from navcli.core.models import CommandResult, Feedback
8
- from navcli.server.browser import get_page, get_current_state, start_browser, wait_for_network_idle
8
+ from navcli.server.browser import get_page, get_current_state, start_browser, wait_for_network_idle, auto_save_snapshot
9
9
  from navcli.utils import normalize_url
10
10
 
11
11
  router = APIRouter()
@@ -47,6 +47,9 @@ async def goto(
47
47
  state = await get_current_state()
48
48
  log_progress(f"Page title: {state.title}")
49
49
 
50
+ # Auto-save session snapshot
51
+ await auto_save_snapshot()
52
+
50
53
  return CommandResult(
51
54
  success=True,
52
55
  command="goto",
@@ -77,6 +80,9 @@ async def back() -> CommandResult:
77
80
  state = await get_current_state()
78
81
  log_progress(f"Back to: {state.url}")
79
82
 
83
+ # Auto-save session snapshot
84
+ await auto_save_snapshot()
85
+
80
86
  return CommandResult(
81
87
  success=True,
82
88
  command="back",
@@ -107,6 +113,9 @@ async def forward() -> CommandResult:
107
113
  state = await get_current_state()
108
114
  log_progress(f"Forward to: {state.url}")
109
115
 
116
+ # Auto-save session snapshot
117
+ await auto_save_snapshot()
118
+
110
119
  return CommandResult(
111
120
  success=True,
112
121
  command="forward",
@@ -137,6 +146,9 @@ async def reload() -> CommandResult:
137
146
  state = await get_current_state()
138
147
  log_progress(f"Reloaded: {state.url}")
139
148
 
149
+ # Auto-save session snapshot
150
+ await auto_save_snapshot()
151
+
140
152
  return CommandResult(
141
153
  success=True,
142
154
  command="reload",
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: navcli
3
- Version: 0.2.3
3
+ Version: 0.2.4
4
4
  Summary: 可交互、可探索的浏览器命令行工具,专为 AI Agent 设计
5
5
  Author: NavCLI Team
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "navcli"
7
- version = "0.2.3"
7
+ version = "0.2.4"
8
8
  description = "可交互、可探索的浏览器命令行工具,专为 AI Agent 设计"
9
9
  readme = "docs/README.md"
10
10
  requires-python = ">=3.9"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes