machina-cli 0.5.2__tar.gz → 0.5.3__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 (100) hide show
  1. {machina_cli-0.5.2 → machina_cli-0.5.3}/CHANGELOG.md +5 -0
  2. {machina_cli-0.5.2 → machina_cli-0.5.3}/PKG-INFO +1 -1
  3. machina_cli-0.5.3/docs-site/commands/update.md +35 -0
  4. {machina_cli-0.5.2 → machina_cli-0.5.3}/pyproject.toml +2 -2
  5. {machina_cli-0.5.2 → machina_cli-0.5.3}/src/machina_cli/__init__.py +1 -1
  6. {machina_cli-0.5.2 → machina_cli-0.5.3}/src/machina_cli/main.py +100 -39
  7. {machina_cli-0.5.2 → machina_cli-0.5.3}/src/machina_cli/repl.py +4 -0
  8. machina_cli-0.5.3/src/machina_cli/update_check.py +113 -0
  9. machina_cli-0.5.2/docs-site/commands/update.md +0 -21
  10. {machina_cli-0.5.2 → machina_cli-0.5.3}/.github/workflows/ci.yml +0 -0
  11. {machina_cli-0.5.2 → machina_cli-0.5.3}/.github/workflows/release.yml +0 -0
  12. {machina_cli-0.5.2 → machina_cli-0.5.3}/.gitignore +0 -0
  13. {machina_cli-0.5.2 → machina_cli-0.5.3}/CLAUDE.md +0 -0
  14. {machina_cli-0.5.2 → machina_cli-0.5.3}/README.md +0 -0
  15. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs/agentic-harness-loop.md +0 -0
  16. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs/credentials.md +0 -0
  17. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs/harness-loop-kit/PLAYBOOK-SCORECARD.md +0 -0
  18. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs/harness-loop-kit/README.md +0 -0
  19. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs/harness-loop-kit/VALIDATION.md +0 -0
  20. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs/harness-loop-kit/context-verify.py +0 -0
  21. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs/harness-loop-kit/provision.py +0 -0
  22. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs/harness-loop-kit/surface-verify.py +0 -0
  23. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs/loop-tools-connector.py +0 -0
  24. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs-site/.gitignore +0 -0
  25. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs-site/.vitepress/config.mts +0 -0
  26. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs-site/.vitepress/theme/custom.css +0 -0
  27. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs-site/.vitepress/theme/index.ts +0 -0
  28. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs-site/README.md +0 -0
  29. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs-site/commands/agent.md +0 -0
  30. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs-site/commands/config.md +0 -0
  31. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs-site/commands/connect.md +0 -0
  32. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs-site/commands/connector.md +0 -0
  33. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs-site/commands/context-graph.md +0 -0
  34. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs-site/commands/credentials.md +0 -0
  35. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs-site/commands/deploy.md +0 -0
  36. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs-site/commands/document.md +0 -0
  37. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs-site/commands/execution.md +0 -0
  38. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs-site/commands/factory.md +0 -0
  39. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs-site/commands/login.md +0 -0
  40. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs-site/commands/loop.md +0 -0
  41. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs-site/commands/mapping.md +0 -0
  42. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs-site/commands/mcp.md +0 -0
  43. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs-site/commands/org.md +0 -0
  44. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs-site/commands/project.md +0 -0
  45. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs-site/commands/prompt.md +0 -0
  46. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs-site/commands/skills.md +0 -0
  47. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs-site/commands/sports.md +0 -0
  48. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs-site/commands/template.md +0 -0
  49. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs-site/commands/workflow.md +0 -0
  50. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs-site/guide/authentication.md +0 -0
  51. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs-site/guide/configuration.md +0 -0
  52. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs-site/guide/installation.md +0 -0
  53. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs-site/guide/quickstart.md +0 -0
  54. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs-site/guide/repl.md +0 -0
  55. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs-site/guide/running.md +0 -0
  56. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs-site/index.md +0 -0
  57. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs-site/package-lock.json +0 -0
  58. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs-site/package.json +0 -0
  59. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs-site/public/favicon.ico +0 -0
  60. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs-site/public/machina-logo-dark.png +0 -0
  61. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs-site/public/machina-logo-light.png +0 -0
  62. {machina_cli-0.5.2 → machina_cli-0.5.3}/docs-site/vercel.json +0 -0
  63. {machina_cli-0.5.2 → machina_cli-0.5.3}/install.ps1 +0 -0
  64. {machina_cli-0.5.2 → machina_cli-0.5.3}/install.sh +0 -0
  65. {machina_cli-0.5.2 → machina_cli-0.5.3}/src/machina_cli/browser_auth.py +0 -0
  66. {machina_cli-0.5.2 → machina_cli-0.5.3}/src/machina_cli/client.py +0 -0
  67. {machina_cli-0.5.2 → machina_cli-0.5.3}/src/machina_cli/commands/__init__.py +0 -0
  68. {machina_cli-0.5.2 → machina_cli-0.5.3}/src/machina_cli/commands/agent.py +0 -0
  69. {machina_cli-0.5.2 → machina_cli-0.5.3}/src/machina_cli/commands/auth.py +0 -0
  70. {machina_cli-0.5.2 → machina_cli-0.5.3}/src/machina_cli/commands/config_cmd.py +0 -0
  71. {machina_cli-0.5.2 → machina_cli-0.5.3}/src/machina_cli/commands/connect.py +0 -0
  72. {machina_cli-0.5.2 → machina_cli-0.5.3}/src/machina_cli/commands/connector.py +0 -0
  73. {machina_cli-0.5.2 → machina_cli-0.5.3}/src/machina_cli/commands/context_graph.py +0 -0
  74. {machina_cli-0.5.2 → machina_cli-0.5.3}/src/machina_cli/commands/credentials.py +0 -0
  75. {machina_cli-0.5.2 → machina_cli-0.5.3}/src/machina_cli/commands/deploy.py +0 -0
  76. {machina_cli-0.5.2 → machina_cli-0.5.3}/src/machina_cli/commands/document.py +0 -0
  77. {machina_cli-0.5.2 → machina_cli-0.5.3}/src/machina_cli/commands/execution.py +0 -0
  78. {machina_cli-0.5.2 → machina_cli-0.5.3}/src/machina_cli/commands/factory.py +0 -0
  79. {machina_cli-0.5.2 → machina_cli-0.5.3}/src/machina_cli/commands/loop.py +0 -0
  80. {machina_cli-0.5.2 → machina_cli-0.5.3}/src/machina_cli/commands/mapping.py +0 -0
  81. {machina_cli-0.5.2 → machina_cli-0.5.3}/src/machina_cli/commands/mcp.py +0 -0
  82. {machina_cli-0.5.2 → machina_cli-0.5.3}/src/machina_cli/commands/org.py +0 -0
  83. {machina_cli-0.5.2 → machina_cli-0.5.3}/src/machina_cli/commands/project.py +0 -0
  84. {machina_cli-0.5.2 → machina_cli-0.5.3}/src/machina_cli/commands/prompt.py +0 -0
  85. {machina_cli-0.5.2 → machina_cli-0.5.3}/src/machina_cli/commands/skills.py +0 -0
  86. {machina_cli-0.5.2 → machina_cli-0.5.3}/src/machina_cli/commands/sports.py +0 -0
  87. {machina_cli-0.5.2 → machina_cli-0.5.3}/src/machina_cli/commands/template.py +0 -0
  88. {machina_cli-0.5.2 → machina_cli-0.5.3}/src/machina_cli/commands/workflow.py +0 -0
  89. {machina_cli-0.5.2 → machina_cli-0.5.3}/src/machina_cli/config.py +0 -0
  90. {machina_cli-0.5.2 → machina_cli-0.5.3}/src/machina_cli/factory_client.py +0 -0
  91. {machina_cli-0.5.2 → machina_cli-0.5.3}/src/machina_cli/loop_client.py +0 -0
  92. {machina_cli-0.5.2 → machina_cli-0.5.3}/src/machina_cli/models/__init__.py +0 -0
  93. {machina_cli-0.5.2 → machina_cli-0.5.3}/src/machina_cli/project_client.py +0 -0
  94. {machina_cli-0.5.2 → machina_cli-0.5.3}/src/machina_cli/updater.py +0 -0
  95. {machina_cli-0.5.2 → machina_cli-0.5.3}/tests/__init__.py +0 -0
  96. {machina_cli-0.5.2 → machina_cli-0.5.3}/tests/test_cli_output.py +0 -0
  97. {machina_cli-0.5.2 → machina_cli-0.5.3}/tests/test_connect.py +0 -0
  98. {machina_cli-0.5.2 → machina_cli-0.5.3}/tests/test_mcp_url.py +0 -0
  99. {machina_cli-0.5.2 → machina_cli-0.5.3}/tests/test_org_usage.py +0 -0
  100. {machina_cli-0.5.2 → machina_cli-0.5.3}/tests/test_sports_integration.py +0 -0
@@ -2,6 +2,11 @@
2
2
 
3
3
  All notable changes to machina-cli are documented here.
4
4
 
5
+ ## [0.5.3] - 2026-07-01
6
+
7
+ ### Added
8
+ - **A "new version available" notice, shown automatically.** Any `machina` command now checks (at most once a day, cached in `~/.machina/update_check.json`) whether a newer release exists, and prints a one-line notice after the command's own output if so — pointing at `machina update`. Zero added latency on ~everything: a fresh cache is a local file read; a stale one kicks off the real GitHub check in a background thread with a 1.5s budget, so a slow network degrades to "check again next time" instead of a hang. Never blocks, never raises, never shows twice in one process, and is suppressed for `--json` output and piped/non-tty stdout so it can never corrupt a script. The REPL shows it once at startup too.
9
+
5
10
  ## [0.5.2] - 2026-07-01
6
11
 
7
12
  ### Added
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: machina-cli
3
- Version: 0.5.2
3
+ Version: 0.5.3
4
4
  Summary: CLI for the Machina AI Agent platform
5
5
  Project-URL: Homepage, https://machina.gg
6
6
  Project-URL: Repository, https://github.com/machina-sports/machina-cli
@@ -0,0 +1,35 @@
1
+ # update
2
+
3
+ Keep the CLI current, and check which version you're running.
4
+
5
+ ## Usage
6
+
7
+ ```bash
8
+ machina update # update to the latest version
9
+ machina update --force # force a re-install even if current
10
+ machina version # show the installed version
11
+ ```
12
+
13
+ ## Options
14
+
15
+ | Flag | Short | Description |
16
+ |------|-------|-------------|
17
+ | `--force` | `-f` | Update even if already on the latest version |
18
+
19
+ ::: tip
20
+ Installed from PyPI? You can also update with `pip install --upgrade machina-cli` (or `pipx upgrade machina-cli`). `machina update` works regardless of how you installed.
21
+ :::
22
+
23
+ ## Automatic update notices
24
+
25
+ You don't have to remember to check. Any `machina` command opportunistically checks for a newer release (at most once a day) and prints a one-line notice after its own output if one is available:
26
+
27
+ ```text
28
+ $ machina workflow list
29
+ ...
30
+
31
+ A new version of machina-cli is available: 0.5.2 → 0.5.3
32
+ Run machina update to upgrade.
33
+ ```
34
+
35
+ This never slows a command down — a fresh check is cached locally (`~/.machina/update_check.json`); a stale cache refreshes in the background with a short budget, so a slow network just means "check again next time" instead of a delay. It's automatically silent for `--json` output and piped/non-interactive usage, so it never lands in a script's output.
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "machina-cli"
7
- version = "0.5.2"
7
+ version = "0.5.3"
8
8
  description = "CLI for the Machina AI Agent platform"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -38,7 +38,7 @@ Repository = "https://github.com/machina-sports/machina-cli"
38
38
  Issues = "https://github.com/machina-sports/machina-cli/issues"
39
39
 
40
40
  [project.scripts]
41
- machina = "machina_cli.main:app"
41
+ machina = "machina_cli.main:run"
42
42
 
43
43
  [project.optional-dependencies]
44
44
  dev = ["pytest>=8.0", "ruff>=0.4"]
@@ -1,3 +1,3 @@
1
1
  """Machina CLI - Command line interface for the Machina AI Agent platform."""
2
2
 
3
- __version__ = "0.5.2"
3
+ __version__ = "0.5.3"
@@ -8,9 +8,26 @@ from rich.text import Text
8
8
 
9
9
  from machina_cli import __version__
10
10
  from machina_cli.commands import (
11
- auth, org, project, credentials, deploy, config_cmd,
12
- workflow, agent, template, execution, skills,
13
- connector, mapping, prompt, document, sports, factory, loop, mcp, connect,
11
+ auth,
12
+ org,
13
+ project,
14
+ credentials,
15
+ deploy,
16
+ config_cmd,
17
+ workflow,
18
+ agent,
19
+ template,
20
+ execution,
21
+ skills,
22
+ connector,
23
+ mapping,
24
+ prompt,
25
+ document,
26
+ sports,
27
+ factory,
28
+ loop,
29
+ mcp,
30
+ connect,
14
31
  context_graph,
15
32
  )
16
33
  from machina_cli.commands.auth import do_login
@@ -18,32 +35,41 @@ from machina_cli.commands.auth import do_login
18
35
  console = Console()
19
36
 
20
37
  CMD_GROUPS = [
21
- ("Platform", [
22
- ("login", "Authenticate"),
23
- ("org", "Organizations"),
24
- ("project", "Projects"),
25
- ("credentials", "API keys"),
26
- ("connect", "Connect an agent to a project's MCP"),
27
- ]),
28
- ("Resources", [
29
- ("workflow", "Workflows"),
30
- ("agent", "Agents"),
31
- ("connector", "Connectors"),
32
- ("mapping", "Mappings"),
33
- ("prompt", "Prompts"),
34
- ("document", "Documents"),
35
- ]),
36
- ("Operations", [
37
- ("execution", "Executions"),
38
- ("skills", "Skills"),
39
- ("loop", "Agentic turn loop (harness)"),
40
- ("factory", "Build apps (Factory)"),
41
- ("sports", "Sports-skills passthrough"),
42
- ("template", "Templates (compat)"),
43
- ("deploy", "Deployments"),
44
- ("mcp", "MCP connection"),
45
- ("update", "Self-update"),
46
- ]),
38
+ (
39
+ "Platform",
40
+ [
41
+ ("login", "Authenticate"),
42
+ ("org", "Organizations"),
43
+ ("project", "Projects"),
44
+ ("credentials", "API keys"),
45
+ ("connect", "Connect an agent to a project's MCP"),
46
+ ],
47
+ ),
48
+ (
49
+ "Resources",
50
+ [
51
+ ("workflow", "Workflows"),
52
+ ("agent", "Agents"),
53
+ ("connector", "Connectors"),
54
+ ("mapping", "Mappings"),
55
+ ("prompt", "Prompts"),
56
+ ("document", "Documents"),
57
+ ],
58
+ ),
59
+ (
60
+ "Operations",
61
+ [
62
+ ("execution", "Executions"),
63
+ ("skills", "Skills"),
64
+ ("loop", "Agentic turn loop (harness)"),
65
+ ("factory", "Build apps (Factory)"),
66
+ ("sports", "Sports-skills passthrough"),
67
+ ("template", "Templates (compat)"),
68
+ ("deploy", "Deployments"),
69
+ ("mcp", "MCP connection"),
70
+ ("update", "Self-update"),
71
+ ],
72
+ ),
47
73
  ]
48
74
 
49
75
 
@@ -109,7 +135,9 @@ def show_banner():
109
135
  console.print()
110
136
  console.print(layout)
111
137
  console.print()
112
- console.print(" [dim]Run[/] [bold]machina[/] [bold magenta]<command>[/] [bold]--help[/] [dim]for more info[/]")
138
+ console.print(
139
+ " [dim]Run[/] [bold]machina[/] [bold magenta]<command>[/] [bold]--help[/] [dim]for more info[/]"
140
+ )
113
141
  console.print()
114
142
 
115
143
 
@@ -123,7 +151,9 @@ app = typer.Typer(
123
151
  @app.callback(invoke_without_command=True)
124
152
  def main(
125
153
  ctx: typer.Context,
126
- no_interactive: bool = typer.Option(False, "--no-interactive", hidden=True, help="Show banner instead of REPL"),
154
+ no_interactive: bool = typer.Option(
155
+ False, "--no-interactive", hidden=True, help="Show banner instead of REPL"
156
+ ),
127
157
  ):
128
158
  """CLI for the Machina AI Agent platform."""
129
159
  if not ctx.invoked_subcommand:
@@ -131,6 +161,7 @@ def main(
131
161
  show_banner()
132
162
  else:
133
163
  from machina_cli.repl import start_repl
164
+
134
165
  start_repl()
135
166
 
136
167
 
@@ -144,7 +175,9 @@ app.add_typer(template.app, name="template", help="Template management")
144
175
  app.add_typer(skills.app, name="skills", help="Skills management")
145
176
  app.add_typer(execution.app, name="execution", help="Execution management")
146
177
  app.add_typer(loop.app, name="loop", help="Durable agentic turn loop (harness)")
147
- app.add_typer(context_graph.app, name="context-graph", help="Self-healing / monitoring status across projects")
178
+ app.add_typer(
179
+ context_graph.app, name="context-graph", help="Self-healing / monitoring status across projects"
180
+ )
148
181
  app.add_typer(factory.app, name="factory", help="Trigger Factory coding-agent builds")
149
182
  app.add_typer(connector.app, name="connector", help="Connector management")
150
183
  app.add_typer(mapping.app, name="mapping", help="Mapping management")
@@ -192,8 +225,12 @@ def shell_prompt():
192
225
  @app.command()
193
226
  def login(
194
227
  api_key: str = typer.Option(None, "--api-key", "-k", help="Authenticate with an API key"),
195
- with_credentials: bool = typer.Option(False, "--with-credentials", help="Use username/password instead of browser"),
196
- no_interactive: bool = typer.Option(False, "--no-interactive", hidden=True, help="Don't start REPL after login"),
228
+ with_credentials: bool = typer.Option(
229
+ False, "--with-credentials", help="Use username/password instead of browser"
230
+ ),
231
+ no_interactive: bool = typer.Option(
232
+ False, "--no-interactive", hidden=True, help="Don't start REPL after login"
233
+ ),
197
234
  ):
198
235
  """Login to the Machina platform. Opens browser by default."""
199
236
  do_login(api_key=api_key, with_credentials=with_credentials)
@@ -201,6 +238,7 @@ def login(
201
238
  # After successful login, start the REPL so the user lands inside the CLI
202
239
  if not no_interactive:
203
240
  from machina_cli.repl import start_repl
241
+
204
242
  start_repl()
205
243
 
206
244
 
@@ -210,9 +248,15 @@ def connect_command(
210
248
  json_output: bool = typer.Option(False, "--json", "-j", help="Output as JSON"),
211
249
  reveal: bool = typer.Option(False, "--reveal", help="Show the auth token (masked by default)"),
212
250
  probe: bool = typer.Option(False, "--probe", help="Verify the SSE endpoint is reachable"),
213
- name: str = typer.Option(None, "--name", "-n", help="Server name for the agent (defaults to project id)"),
214
- mint: bool = typer.Option(False, "--mint", help="Reuse or create a dedicated project API key for a durable connection"),
215
- org: str = typer.Option(None, "--org", "-o", help="Organization ID for --mint (defaults to the selected org)"),
251
+ name: str = typer.Option(
252
+ None, "--name", "-n", help="Server name for the agent (defaults to project id)"
253
+ ),
254
+ mint: bool = typer.Option(
255
+ False, "--mint", help="Reuse or create a dedicated project API key for a durable connection"
256
+ ),
257
+ org: str = typer.Option(
258
+ None, "--org", "-o", help="Organization ID for --mint (defaults to the selected org)"
259
+ ),
216
260
  ):
217
261
  """Resolve a project's MCP connection for an external agent (e.g. sportsclaw)."""
218
262
  connect.run(project_id, json_output, reveal, probe, name, mint, org)
@@ -220,10 +264,13 @@ def connect_command(
220
264
 
221
265
  @app.command()
222
266
  def update(
223
- force: bool = typer.Option(False, "--force", "-f", help="Force update even if already on latest"),
267
+ force: bool = typer.Option(
268
+ False, "--force", "-f", help="Force update even if already on latest"
269
+ ),
224
270
  ):
225
271
  """Update machina-cli to the latest version."""
226
272
  from machina_cli.updater import do_update
273
+
227
274
  do_update(force=force)
228
275
 
229
276
 
@@ -233,5 +280,19 @@ def version():
233
280
  console.print(f"machina-cli v{get_version()}")
234
281
 
235
282
 
283
+ def run():
284
+ """Real entrypoint for both the pip console-script and the PyInstaller
285
+ binary (which freezes this file and runs it as __main__ -- see
286
+ if __name__ == "__main__" below). Click/Typer's standalone_mode raises
287
+ SystemExit from app() on every path (success, error, --help), so the
288
+ update check needs `finally`, not code placed after a plain call."""
289
+ try:
290
+ app()
291
+ finally:
292
+ from machina_cli.update_check import maybe_notify_update
293
+
294
+ maybe_notify_update()
295
+
296
+
236
297
  if __name__ == "__main__":
237
- app()
298
+ run()
@@ -334,6 +334,10 @@ def start_repl():
334
334
 
335
335
  _show_repl_banner()
336
336
 
337
+ from machina_cli.update_check import maybe_notify_update
338
+
339
+ maybe_notify_update()
340
+
337
341
  try:
338
342
  while True:
339
343
  try:
@@ -0,0 +1,113 @@
1
+ """Opportunistic "a new version is available" notice.
2
+
3
+ Checked at most once a day, cached in ~/.machina/update_check.json (separate
4
+ from config.json, which holds user settings, not internal state). Never
5
+ blocks a command for more than a fraction of a second: a stale cache kicks
6
+ off the real network check in a background thread with a short join budget,
7
+ so slow networks degrade to "check again next time" instead of a hang. Never
8
+ raises -- an update notice is a nicety, not something that should ever break
9
+ a command. Printed at most once per process, and suppressed for --json
10
+ output / non-tty stdout so it can never corrupt a script or a pipe.
11
+ """
12
+
13
+ import json
14
+ import sys
15
+ import threading
16
+ import time
17
+
18
+ from machina_cli import __version__
19
+ from machina_cli.config import CONFIG_DIR
20
+
21
+ CACHE_FILE = CONFIG_DIR / "update_check.json"
22
+ CHECK_INTERVAL_SECONDS = 24 * 60 * 60 # once a day
23
+ NETWORK_BUDGET_SECONDS = 1.5 # never make a command wait longer than this
24
+
25
+ _shown = False # per-process guard -- never print the banner twice (e.g. once
26
+ # at REPL start, once again when the process later exits)
27
+
28
+
29
+ def _parse_version(v: str) -> tuple:
30
+ parts = []
31
+ for p in v.split("."):
32
+ digits = "".join(c for c in p if c.isdigit())
33
+ parts.append(int(digits) if digits else 0)
34
+ return tuple(parts)
35
+
36
+
37
+ def _is_newer(latest: str, current: str) -> bool:
38
+ try:
39
+ return _parse_version(latest) > _parse_version(current)
40
+ except Exception:
41
+ return False
42
+
43
+
44
+ def _read_cache() -> dict:
45
+ try:
46
+ return json.loads(CACHE_FILE.read_text())
47
+ except Exception:
48
+ return {}
49
+
50
+
51
+ def _write_cache(data: dict) -> None:
52
+ try:
53
+ CONFIG_DIR.mkdir(parents=True, exist_ok=True)
54
+ CACHE_FILE.write_text(json.dumps(data))
55
+ except Exception:
56
+ pass
57
+
58
+
59
+ def _refresh_in_background(result: dict) -> None:
60
+ """Runs in a daemon thread: the real network call + cache write. If the
61
+ process exits before this finishes, it's simply abandoned -- the next
62
+ invocation's stale-cache branch tries again, so nothing gets corrupted."""
63
+ try:
64
+ from machina_cli.updater import get_latest_version
65
+
66
+ latest = get_latest_version()
67
+ except Exception:
68
+ latest = None
69
+ if latest:
70
+ result["latest_version"] = latest
71
+ result["fetched"] = True
72
+ _write_cache({"last_checked": time.time(), "latest_version": latest})
73
+
74
+
75
+ def _should_show() -> bool:
76
+ """Suppress in non-tty (piped/scripted) or --json contexts, and for the
77
+ `update` command itself (it already does its own explicit check)."""
78
+ if not sys.stdout.isatty():
79
+ return False
80
+ if any(a in ("--json", "-j") for a in sys.argv):
81
+ return False
82
+ if "update" in sys.argv:
83
+ return False
84
+ return True
85
+
86
+
87
+ def maybe_notify_update() -> None:
88
+ global _shown
89
+ if _shown or not _should_show():
90
+ return
91
+
92
+ cache = _read_cache()
93
+ stale = (time.time() - cache.get("last_checked", 0)) > CHECK_INTERVAL_SECONDS
94
+ latest = cache.get("latest_version")
95
+
96
+ if stale:
97
+ result = {}
98
+ t = threading.Thread(target=_refresh_in_background, args=(result,), daemon=True)
99
+ t.start()
100
+ t.join(timeout=NETWORK_BUDGET_SECONDS)
101
+ if result.get("fetched"):
102
+ latest = result["latest_version"]
103
+
104
+ if latest and _is_newer(latest, __version__):
105
+ _shown = True
106
+ from rich.console import Console
107
+
108
+ console = Console(highlight=False)
109
+ console.print(
110
+ f"\n[dim]A new version of machina-cli is available:[/dim] "
111
+ f"[bold]{__version__}[/bold][dim] → [/dim][bold green]{latest}[/bold green]"
112
+ )
113
+ console.print("[dim]Run[/dim] [bold]machina update[/bold] [dim]to upgrade.[/dim]")
@@ -1,21 +0,0 @@
1
- # update
2
-
3
- Keep the CLI current, and check which version you're running.
4
-
5
- ## Usage
6
-
7
- ```bash
8
- machina update # update to the latest version
9
- machina update --force # force a re-install even if current
10
- machina version # show the installed version
11
- ```
12
-
13
- ## Options
14
-
15
- | Flag | Short | Description |
16
- |------|-------|-------------|
17
- | `--force` | `-f` | Update even if already on the latest version |
18
-
19
- ::: tip
20
- Installed from PyPI? You can also update with `pip install --upgrade machina-cli` (or `pipx upgrade machina-cli`). `machina update` works regardless of how you installed.
21
- :::
File without changes
File without changes
File without changes
File without changes
File without changes