infixspeed-cli 0.0.16__py3-none-any.whl

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 (85) hide show
  1. infix_cli/__init__.py +5 -0
  2. infix_cli/__main__.py +6 -0
  3. infix_cli/agent-guide.txt +71 -0
  4. infix_cli/cli_framework.py +96 -0
  5. infix_cli/command_contract.py +157 -0
  6. infix_cli/commands/__init__.py +1 -0
  7. infix_cli/commands/_artifacts.py +142 -0
  8. infix_cli/commands/_comparison.py +443 -0
  9. infix_cli/commands/_confirm.py +26 -0
  10. infix_cli/commands/_control.py +290 -0
  11. infix_cli/commands/_create.py +351 -0
  12. infix_cli/commands/_create_output.py +139 -0
  13. infix_cli/commands/_delete.py +288 -0
  14. infix_cli/commands/_download.py +459 -0
  15. infix_cli/commands/_fusion_common.py +191 -0
  16. infix_cli/commands/_fusion_config.py +394 -0
  17. infix_cli/commands/_fusion_feedback.py +319 -0
  18. infix_cli/commands/_fusion_tasks.py +507 -0
  19. infix_cli/commands/_fusion_tensorboard.py +132 -0
  20. infix_cli/commands/_jobs.py +312 -0
  21. infix_cli/commands/_logs.py +210 -0
  22. infix_cli/commands/_publish.py +123 -0
  23. infix_cli/commands/_register.py +600 -0
  24. infix_cli/commands/_register_output.py +231 -0
  25. infix_cli/commands/_storage_tree.py +62 -0
  26. infix_cli/commands/admin.py +668 -0
  27. infix_cli/commands/asset.py +2012 -0
  28. infix_cli/commands/auth.py +246 -0
  29. infix_cli/commands/deploy.py +850 -0
  30. infix_cli/commands/evaluation.py +360 -0
  31. infix_cli/commands/examples.py +138 -0
  32. infix_cli/commands/fusion.py +1842 -0
  33. infix_cli/commands/merge.py +709 -0
  34. infix_cli/commands/resource.py +127 -0
  35. infix_cli/commands/spark.py +347 -0
  36. infix_cli/commands/storage.py +329 -0
  37. infix_cli/commands/training.py +748 -0
  38. infix_cli/config.py +311 -0
  39. infix_cli/config_input.py +217 -0
  40. infix_cli/context.py +84 -0
  41. infix_cli/discovery.py +459 -0
  42. infix_cli/domain/__init__.py +1 -0
  43. infix_cli/domain/dto/__init__.py +6 -0
  44. infix_cli/domain/dto/admin.py +413 -0
  45. infix_cli/domain/dto/asset.py +390 -0
  46. infix_cli/domain/dto/common.py +136 -0
  47. infix_cli/domain/dto/evaluation.py +296 -0
  48. infix_cli/domain/dto/logs.py +98 -0
  49. infix_cli/domain/dto/resource.py +108 -0
  50. infix_cli/domain/dto/serving.py +156 -0
  51. infix_cli/domain/dto/spark.py +241 -0
  52. infix_cli/domain/dto/storage.py +75 -0
  53. infix_cli/domain/dto/training.py +272 -0
  54. infix_cli/domain/enums.py +359 -0
  55. infix_cli/domain/hyperparams.py +190 -0
  56. infix_cli/domain/refs.py +108 -0
  57. infix_cli/domain/resolve.py +619 -0
  58. infix_cli/errors.py +158 -0
  59. infix_cli/example_data/__init__.py +1 -0
  60. infix_cli/example_data/fusion/README.md +128 -0
  61. infix_cli/example_data/fusion/fusion.json +149 -0
  62. infix_cli/example_data/fusion/prompts/code.jsonl +16 -0
  63. infix_cli/example_data/fusion/prompts/math.jsonl +16 -0
  64. infix_cli/example_data/fusion.zip +0 -0
  65. infix_cli/example_data/merge/README.md +89 -0
  66. infix_cli/example_data/merge/merge.json +26 -0
  67. infix_cli/example_data/merge.zip +0 -0
  68. infix_cli/http/__init__.py +1 -0
  69. infix_cli/http/browser_auth.py +160 -0
  70. infix_cli/http/client.py +575 -0
  71. infix_cli/http/pagination.py +84 -0
  72. infix_cli/http/upload.py +254 -0
  73. infix_cli/main.py +432 -0
  74. infix_cli/pipeline_config_schema.py +122 -0
  75. infix_cli/render/__init__.py +79 -0
  76. infix_cli/render/json_out.py +123 -0
  77. infix_cli/render/progress.py +62 -0
  78. infix_cli/render/text.py +233 -0
  79. infix_cli/update_check.py +177 -0
  80. infix_cli/waiter.py +93 -0
  81. infix_cli/workspace.py +158 -0
  82. infixspeed_cli-0.0.16.dist-info/METADATA +58 -0
  83. infixspeed_cli-0.0.16.dist-info/RECORD +85 -0
  84. infixspeed_cli-0.0.16.dist-info/WHEEL +4 -0
  85. infixspeed_cli-0.0.16.dist-info/entry_points.txt +2 -0
@@ -0,0 +1,139 @@
1
+ """Job-creation feedback, as the PRD writes it (§3.4).
2
+
3
+ Submitting reports what was accepted and where to look next; it is not the
4
+ detail view. The values echo the flags the caller just typed — prefixed asset
5
+ references, the method with its task — because this block answers "did it take
6
+ what I meant", while `get` answers "what is this job".
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ from typing import Any
12
+
13
+ _LABEL = {"training": "Training job", "evaluation": "Evaluation job", "spark": "Spark job"}
14
+
15
+
16
+ def created_title(module: str, name: str, *, waiting: bool) -> str:
17
+ label = _LABEL.get(module, f"{module.capitalize()} job")
18
+ if waiting:
19
+ return f'{label} "{name}" created. Waiting for completion...'
20
+ return f'{label} "{name}" created successfully.'
21
+
22
+
23
+ def created_rows(
24
+ module: str, dto: Any, *, method: str = "", task: str = "",
25
+ echo: dict[str, str] | None = None,
26
+ ) -> list[tuple[str, str]]:
27
+ """The block under the confirmation line, per module.
28
+
29
+ ``echo`` carries the references exactly as they were typed, including the
30
+ version pin. The response only reports the resolved name, so echoing is
31
+ what lets the caller see that "workspace/x:v1.0.0" was understood as such.
32
+ """
33
+ status = _status(dto.status)
34
+ echo = echo or {}
35
+ if module == "training":
36
+ return [
37
+ ("Status", status),
38
+ ("Method", _method_line(method or dto.method, task or dto.task)),
39
+ ("Base Model", echo.get("base_model") or dto.base_model or "--"),
40
+ ("Dataset", echo.get("dataset") or dto.dataset or "--"),
41
+ ("Workers", str(dto.workers)),
42
+ ("Hardware", dto.hardware or dto.resource_summary or "--"),
43
+ ]
44
+ if module == "evaluation":
45
+ rows = [
46
+ ("Status", status),
47
+ ("Model", echo.get("model") or dto.model or "--"),
48
+ ("Eval Type", dto.eval_type or "--"),
49
+ ]
50
+ if dto.custom_format:
51
+ rows.append(("Format", dto.custom_format))
52
+ rows.append(("Dataset", echo.get("dataset") or dto.dataset or "--"))
53
+ return rows
54
+ return [
55
+ ("Status", status),
56
+ ("Datasets", echo.get("datasets") or (", ".join(dto.datasets) if dto.datasets else "--")),
57
+ ("Main Script", dto.main_script or "--"),
58
+ ("Workers", str(dto.workers)),
59
+ ("Hardware", dto.hardware or "--"),
60
+ ]
61
+
62
+
63
+ def next_steps(module: str, name: str) -> list[str]:
64
+ """What to run next. Omitted after --wait, where the answer is already in."""
65
+ if module == "training":
66
+ return [
67
+ f'Use "infix training get {name}" to check progress.',
68
+ f'Use "infix training logs {name} -f" to follow logs.',
69
+ ]
70
+ if module == "evaluation":
71
+ return [f'Use "infix evaluation get {name}" to check results.']
72
+ return [
73
+ f'Use "infix spark get {name}" to check progress.',
74
+ f'Use "infix spark logs {name} -f" to follow logs.',
75
+ ]
76
+
77
+
78
+ def completion_title(duration_seconds: int | None) -> str:
79
+ from infix_cli.domain.dto.common import format_duration
80
+
81
+ if duration_seconds is None:
82
+ return "Job completed."
83
+ return f"Job completed in {format_duration(duration_seconds)}."
84
+
85
+
86
+ def completion_rows(module: str, dto: Any) -> list[tuple[str, str]]:
87
+ """What the run produced. Only spark's output path is defined by the PRD."""
88
+ output = getattr(dto, "output_path", None)
89
+ if not output:
90
+ return []
91
+ return [("Output", f"/mnt/output/ (Workspace Storage: {output})")]
92
+
93
+
94
+ def _status(status: str) -> str:
95
+ return status[:1].upper() + status[1:] if status else "--"
96
+
97
+
98
+ def _method_line(method: str | None, task: str | None) -> str:
99
+ """``FP8 (SFT)`` — the PRD pairs the method with the task it runs."""
100
+ if not method:
101
+ return "--"
102
+ shown = {"fp8": "FP8", "fp4-rl": "FP4-RL", "custom": "Custom"}.get(method, method)
103
+ return f"{shown} ({task.upper()})" if task else shown
104
+
105
+
106
+ class StatusTrail:
107
+ """Accumulates the states a waiting job passes through.
108
+
109
+ The PRD shows them on one line — ``Queued → Initializing → Running...`` —
110
+ which reads as progress on a terminal. Off a terminal each change gets its
111
+ own line instead, because a rewritten line is invisible in a log file.
112
+ """
113
+
114
+ def __init__(self, ctx: Any) -> None:
115
+ self.ctx = ctx
116
+ self.states: list[str] = []
117
+
118
+ def __call__(self, ctx: Any, status: str, _label: str) -> None:
119
+ import sys
120
+
121
+ if ctx.output == "json" or ctx.quiet:
122
+ return
123
+ shown = _status(status)
124
+ if shown in self.states:
125
+ return
126
+ self.states.append(shown)
127
+ line = " Status: " + " → ".join(self.states) + "..."
128
+ if sys.stdout.isatty():
129
+ sys.stdout.write("\r" + line)
130
+ sys.stdout.flush()
131
+ else:
132
+ print(line)
133
+
134
+ def close(self) -> None:
135
+ import sys
136
+
137
+ if self.states and sys.stdout.isatty() and self.ctx.output != "json" and not self.ctx.quiet:
138
+ sys.stdout.write("\n")
139
+ sys.stdout.flush()
@@ -0,0 +1,288 @@
1
+ """delete, shared by jobs, assets, images and storage.
2
+
3
+ The backend's delete endpoints check permissions and little else: a running job
4
+ is deleted as readily as a finished one, deleting an asset's last version takes
5
+ the whole asset with it, and a storage path that does not exist "deletes"
6
+ successfully. Each of those is caught here, before the request — the backend
7
+ is not going to.
8
+
9
+ Nothing deleted can be brought back (there is no recycle bin, and restore only
10
+ undoes an archive), so every command confirms first; see commands/_confirm.
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ from typing import Any
16
+
17
+ from infix_cli import render
18
+ from infix_cli.commands import _confirm, _jobs, _storage_tree
19
+ from infix_cli.domain import enums, resolve
20
+ from infix_cli.errors import ApiError, NotFoundError, UsageError
21
+
22
+ _JOB_DELETE_PATH = {
23
+ "training": "/training/jobs/{id}",
24
+ "evaluation": "/evaluation/jobs/{id}",
25
+ "spark": "/data-processing/{id}",
26
+ }
27
+
28
+ # Top-level Workspace Storage folders the backend refuses to delete
29
+ # (storage_service.py, standard directories). Their contents may go.
30
+ _PROTECTED_ROOTS = frozenset({
31
+ "Notebook_Storage", "Spark_Output", "Model_Training_Output",
32
+ "Model_Evaluation_Output", "Agent_Mode",
33
+ })
34
+
35
+ # DELETE /storage/items takes at most this many paths per call.
36
+ _STORAGE_BATCH = 50
37
+
38
+
39
+ # ── jobs ────────────────────────────────────────────────────────────────────
40
+
41
+
42
+ def delete_job(run: Any, module: str, name: str, *, force: bool, yes: bool) -> None:
43
+ client = run.client()
44
+ job = resolve.find_job(client, module, name)
45
+ job_id = str(job.get("id"))
46
+ job_name = str(job.get("name") or job_id)
47
+ status = enums.status_to_cli(job.get("status"))
48
+ label = f'{module.capitalize()} job "{job_name}"'
49
+
50
+ active = status not in _jobs.terminal_states(module)
51
+ if active and not force:
52
+ # Training would cancel it first; evaluation and Spark delete it
53
+ # mid-run without stopping it at all. Either way a delete is not how
54
+ # anyone expects a running job to end.
55
+ raise UsageError(
56
+ f"{label} is {status}; deleting it would also stop it.",
57
+ f'Stop it first with "infix {module} stop {job_name}", or pass --force.',
58
+ )
59
+
60
+ rows = [("Status", status or "--")]
61
+ rows += _job_side_effects(module, job, active=active)
62
+ _confirm.require(run, title=f"{label} will be deleted.", rows=rows, yes=yes)
63
+ client.delete(_JOB_DELETE_PATH[module].format(id=job_id))
64
+
65
+ done = "deletion requested" if module == "evaluation" else "deleted"
66
+ _report(run, [{"type": module, "id": job_id, "name": job_name}], f"{label} {done}.")
67
+
68
+
69
+ def _job_side_effects(module: str, job: dict, *, active: bool) -> list[tuple[str, str]]:
70
+ """What goes and what stays, as the backend actually does it."""
71
+ rows: list[tuple[str, str]] = []
72
+ if module == "training":
73
+ if active:
74
+ rows.append(("Running", "will be cancelled first"))
75
+ output = job.get("output_path")
76
+ rows.append(("Output", f"{output} (kept in Workspace Storage)" if output else "kept"))
77
+ elif module == "evaluation":
78
+ if active:
79
+ rows.append(("Running", "will be torn down; deletion completes asynchronously"))
80
+ rows.append(("Results", "deleted"))
81
+ else:
82
+ if active:
83
+ rows.append(("Running", "will be removed without stopping first"))
84
+ output = job.get("storage_path") or job.get("output_path")
85
+ rows.append(("Output", f"{output} (kept in Workspace Storage)" if output else "kept"))
86
+ return rows
87
+
88
+
89
+ # ── assets ──────────────────────────────────────────────────────────────────
90
+
91
+
92
+ def delete_asset(
93
+ run: Any,
94
+ kind: str,
95
+ plain: str,
96
+ *,
97
+ version: str | None,
98
+ all_versions: bool,
99
+ yes: bool,
100
+ ) -> None:
101
+ if bool(version) == all_versions:
102
+ raise UsageError(
103
+ "Say what to delete: --version V for one version, or --all for the "
104
+ "asset with every version.",
105
+ )
106
+ client = run.client()
107
+ asset = resolve.find_asset(client, kind, plain, "workspace")
108
+ asset_id = str(asset["id"])
109
+ label = f'{kind.capitalize()} "{plain}"'
110
+ live = [
111
+ v for v in resolve.list_versions(client, kind, asset_id)
112
+ if str(v.get("status") or "") != "Deleted"
113
+ ]
114
+
115
+ if all_versions:
116
+ numbers = ", ".join(str(v.get("version_number")) for v in live) or "--"
117
+ _confirm.require(
118
+ run,
119
+ title=f"{label} will be deleted with all {len(live)} version(s).",
120
+ rows=[("Versions", numbers), ("Files", "removed from asset storage")],
121
+ yes=yes,
122
+ type_to_confirm=plain,
123
+ )
124
+ client.delete(f"/assets/{resolve.asset_path(kind)}/{asset_id}")
125
+ _report(run, [{"type": kind, "id": asset_id, "name": plain}], f"{label} deleted.")
126
+ return
127
+
128
+ target = next((v for v in live if str(v.get("version_number")) == version), None)
129
+ if target is None:
130
+ raise NotFoundError(
131
+ f'{label} has no version "{version}".',
132
+ f'See "infix asset {kind} versions {plain}".',
133
+ )
134
+ if len(live) == 1:
135
+ # The backend does not refuse this: it purges the whole asset instead,
136
+ # which is not what "delete a version" says.
137
+ raise UsageError(
138
+ f'"{version}" is the only version of {label}; deleting it deletes the asset.',
139
+ f'To delete the asset, run "infix asset {kind} delete {plain} --all".',
140
+ )
141
+ status = enums.ASSET_STATUS.to_cli(target.get("status")) or "--"
142
+ rows = [("Status", status), ("Files", "removed from asset storage")]
143
+ if status == "registering":
144
+ rows.append(("Copy", "in progress; it will be cancelled"))
145
+ _confirm.require(
146
+ run, title=f'Version "{version}" of {label} will be deleted.', rows=rows, yes=yes,
147
+ )
148
+ version_id = str(target.get("id"))
149
+ client.delete(f"/assets/{resolve.asset_path(kind)}/{asset_id}/versions/{version_id}")
150
+ _report(
151
+ run,
152
+ [{"type": f"{kind}_version", "id": version_id, "name": f"{plain}:{version}"}],
153
+ f'Version "{version}" of {label} deleted.',
154
+ )
155
+
156
+
157
+ def delete_image(run: Any, image: dict, *, yes: bool) -> None:
158
+ image_id = str(image.get("id"))
159
+ name = str(image.get("display_name") or image_id)
160
+ _confirm.require(
161
+ run,
162
+ title=f'Image "{name}" will be deleted.',
163
+ rows=[("URI", str(image.get("image_url") or "--"))],
164
+ yes=yes,
165
+ )
166
+ run.client().delete(f"/images/{image_id}")
167
+ _report(run, [{"type": "image", "id": image_id, "name": name}], f'Image "{name}" deleted.')
168
+
169
+
170
+ # ── storage ─────────────────────────────────────────────────────────────────
171
+
172
+
173
+ def delete_storage(run: Any, paths: list[str], *, owner: str | None, yes: bool) -> None:
174
+ targets = _clean_storage_paths(paths)
175
+ client = run.client()
176
+
177
+ # /storage/list only browses the caller's own tree, so another member's
178
+ # paths cannot be checked up front; the backend still enforces access.
179
+ entries = {} if owner else {p: _storage_tree.stat(client, p) for p in targets}
180
+ missing = [p for p, entry in entries.items() if entry is None]
181
+ if missing:
182
+ raise NotFoundError(
183
+ "Not found: " + ", ".join(f'"{p}"' for p in missing) + ". Nothing was deleted.",
184
+ 'Run "infix storage list" to browse.',
185
+ )
186
+
187
+ dirs = [p for p, entry in entries.items() if entry and entry.get("is_dir")]
188
+ rows = [(("Folder" if p in dirs else "File"), _describe(p, entries.get(p))) for p in targets]
189
+ if owner:
190
+ rows.append(("Owner", owner))
191
+ title = (
192
+ f'"{targets[0]}" will be deleted.' if len(targets) == 1
193
+ else f"{len(targets)} paths will be deleted."
194
+ )
195
+ if dirs:
196
+ title += " Folders are deleted with everything in them."
197
+ _confirm.require(
198
+ run, title=title, rows=rows, yes=yes,
199
+ # A folder takes its whole tree: answering "y" by habit costs the most.
200
+ type_to_confirm=(targets[0] if len(targets) == 1 else "delete") if dirs else None,
201
+ )
202
+
203
+ deleted, errors = 0, []
204
+ batches = [targets[i:i + _STORAGE_BATCH] for i in range(0, len(targets), _STORAGE_BATCH)]
205
+ for batch in batches:
206
+ body = {"paths": batch}
207
+ if owner:
208
+ body["owner_user_id"] = owner
209
+ result = client.delete("/storage/items", json=body) or {}
210
+ deleted += int(result.get("deleted") or 0)
211
+ errors += list(result.get("errors") or [])
212
+
213
+ failed_paths = {str(e.get("path")) for e in errors}
214
+ ok = [{"type": "storage", "id": p, "name": p} for p in targets if p not in failed_paths]
215
+ if run.output == "json":
216
+ from infix_cli.render import json_out
217
+
218
+ json_out.print_raw({"deleted": ok, "failed": errors})
219
+ else:
220
+ for item in ok:
221
+ render.message(run, f'Deleted "{item["name"]}".')
222
+ for err in errors:
223
+ _print_storage_error(run, err)
224
+ if errors:
225
+ raise ApiError(
226
+ f"{len(errors)} of {len(targets)} path(s) could not be deleted.",
227
+ "Stop the jobs using them, then retry." if any(e.get("usages") for e in errors)
228
+ else None,
229
+ )
230
+
231
+
232
+ def _clean_storage_paths(paths: list[str]) -> list[str]:
233
+ targets: list[str] = []
234
+ for raw in paths:
235
+ path = raw.strip().strip("/")
236
+ if not path:
237
+ raise UsageError("Refusing to delete the storage root.")
238
+ if any(segment == ".." for segment in path.split("/")):
239
+ raise UsageError(f'Invalid path "{raw}": path segments may not be "..".')
240
+ if path in _PROTECTED_ROOTS:
241
+ raise UsageError(
242
+ f'"{path}" is a system folder and cannot be deleted.',
243
+ "Its contents can be: name a path inside it.",
244
+ )
245
+ if path not in targets:
246
+ targets.append(path)
247
+ return targets
248
+
249
+
250
+ def _describe(path: str, entry: dict | None) -> str:
251
+ from infix_cli.domain.dto.common import format_bytes
252
+
253
+ size = (entry or {}).get("size")
254
+ return f"{path} ({format_bytes(size)})" if size else path
255
+
256
+
257
+ def _print_storage_error(run: Any, err: dict) -> None:
258
+ from infix_cli.render import text
259
+
260
+ usages = err.get("usages") or []
261
+ hint = None
262
+ if usages:
263
+ hint = "In use by: " + ", ".join(_usage_label(u) for u in usages)
264
+ text.print_warning(run, f'Not deleted: "{err.get("path")}" — {err.get("error")}', hint)
265
+
266
+
267
+ def _usage_label(usage: Any) -> str:
268
+ if not isinstance(usage, dict):
269
+ return str(usage)
270
+ # StoragePathUsage (backend infrastructure/storage/path_usage.py).
271
+ kind = str(usage.get("source_type") or "")
272
+ name = str(usage.get("job_name") or usage.get("job_id") or "")
273
+ status = str(usage.get("status") or "")
274
+ label = f"{kind} {name}".strip()
275
+ return f"{label} ({status.lower()})" if status else label
276
+
277
+
278
+ # ── output ──────────────────────────────────────────────────────────────────
279
+
280
+
281
+ def _report(run: Any, deleted: list[dict], line: str) -> None:
282
+ """Single and bulk deletes share one JSON shape, so scripts parse one."""
283
+ if run.output == "json":
284
+ from infix_cli.render import json_out
285
+
286
+ json_out.print_raw({"deleted": deleted, "failed": []})
287
+ return
288
+ render.message(run, line)