kaiten-cli 0.3.3__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 (99) hide show
  1. kaiten_cli/__init__.py +5 -0
  2. kaiten_cli/__main__.py +9 -0
  3. kaiten_cli/agent_gateway.py +577 -0
  4. kaiten_cli/app.py +1636 -0
  5. kaiten_cli/completion.py +570 -0
  6. kaiten_cli/discovery.py +39 -0
  7. kaiten_cli/errors.py +79 -0
  8. kaiten_cli/i18n.py +92 -0
  9. kaiten_cli/locales/ru.json +2967 -0
  10. kaiten_cli/localized_click.py +160 -0
  11. kaiten_cli/models.py +202 -0
  12. kaiten_cli/profiles.py +316 -0
  13. kaiten_cli/registry/__init__.py +260 -0
  14. kaiten_cli/registry/addons.py +392 -0
  15. kaiten_cli/registry/audit_and_analytics.py +451 -0
  16. kaiten_cli/registry/automation_schema.py +44 -0
  17. kaiten_cli/registry/automation_schemas.json +7417 -0
  18. kaiten_cli/registry/automations.py +342 -0
  19. kaiten_cli/registry/base.py +62 -0
  20. kaiten_cli/registry/blockers.py +320 -0
  21. kaiten_cli/registry/boards.py +520 -0
  22. kaiten_cli/registry/card_relations.py +376 -0
  23. kaiten_cli/registry/card_types.py +363 -0
  24. kaiten_cli/registry/cards.py +1329 -0
  25. kaiten_cli/registry/charts.py +539 -0
  26. kaiten_cli/registry/checklists.py +600 -0
  27. kaiten_cli/registry/columns.py +558 -0
  28. kaiten_cli/registry/comments.py +224 -0
  29. kaiten_cli/registry/custom_directories.py +980 -0
  30. kaiten_cli/registry/custom_properties.py +1460 -0
  31. kaiten_cli/registry/dashboards.py +564 -0
  32. kaiten_cli/registry/documents.py +761 -0
  33. kaiten_cli/registry/external_links.py +128 -0
  34. kaiten_cli/registry/files.py +738 -0
  35. kaiten_cli/registry/github_addon.py +613 -0
  36. kaiten_cli/registry/iterations.py +397 -0
  37. kaiten_cli/registry/lanes.py +205 -0
  38. kaiten_cli/registry/live_contracts.py +361 -0
  39. kaiten_cli/registry/members.py +336 -0
  40. kaiten_cli/registry/module_docs.py +108 -0
  41. kaiten_cli/registry/projects.py +369 -0
  42. kaiten_cli/registry/query.py +129 -0
  43. kaiten_cli/registry/restrictions.py +249 -0
  44. kaiten_cli/registry/roles_and_groups.py +1102 -0
  45. kaiten_cli/registry/scim.py +263 -0
  46. kaiten_cli/registry/service_desk.py +1270 -0
  47. kaiten_cli/registry/snapshot.py +187 -0
  48. kaiten_cli/registry/spaces.py +272 -0
  49. kaiten_cli/registry/subscribers.py +168 -0
  50. kaiten_cli/registry/tags.py +193 -0
  51. kaiten_cli/registry/time_logs.py +353 -0
  52. kaiten_cli/registry/tree.py +352 -0
  53. kaiten_cli/registry/utilities.py +287 -0
  54. kaiten_cli/registry/webhooks.py +265 -0
  55. kaiten_cli/runtime/__init__.py +1 -0
  56. kaiten_cli/runtime/automation_validation.py +115 -0
  57. kaiten_cli/runtime/behaviors.py +787 -0
  58. kaiten_cli/runtime/cache.py +733 -0
  59. kaiten_cli/runtime/client.py +387 -0
  60. kaiten_cli/runtime/endpoints.py +59 -0
  61. kaiten_cli/runtime/executor.py +269 -0
  62. kaiten_cli/runtime/fs_security.py +168 -0
  63. kaiten_cli/runtime/input.py +310 -0
  64. kaiten_cli/runtime/output.py +59 -0
  65. kaiten_cli/runtime/public_validation.py +35 -0
  66. kaiten_cli/runtime/snapshot_build.py +527 -0
  67. kaiten_cli/runtime/snapshot_common.py +363 -0
  68. kaiten_cli/runtime/snapshot_query.py +306 -0
  69. kaiten_cli/runtime/snapshot_store.py +1192 -0
  70. kaiten_cli/runtime/snapshots.py +62 -0
  71. kaiten_cli/runtime/sqlite_errors.py +23 -0
  72. kaiten_cli/runtime/support/__init__.py +1 -0
  73. kaiten_cli/runtime/support/addons.py +953 -0
  74. kaiten_cli/runtime/support/audit.py +70 -0
  75. kaiten_cli/runtime/support/batch.py +234 -0
  76. kaiten_cli/runtime/support/card_move_url.py +213 -0
  77. kaiten_cli/runtime/support/cards.py +174 -0
  78. kaiten_cli/runtime/support/checklists.py +21 -0
  79. kaiten_cli/runtime/support/company_users.py +117 -0
  80. kaiten_cli/runtime/support/dashboards.py +35 -0
  81. kaiten_cli/runtime/support/documents.py +175 -0
  82. kaiten_cli/runtime/support/files.py +561 -0
  83. kaiten_cli/runtime/support/markdown_export.py +525 -0
  84. kaiten_cli/runtime/support/pagination.py +167 -0
  85. kaiten_cli/runtime/support/projects.py +66 -0
  86. kaiten_cli/runtime/support/relations.py +86 -0
  87. kaiten_cli/runtime/support/restrictions.py +62 -0
  88. kaiten_cli/runtime/support/spaces.py +20 -0
  89. kaiten_cli/runtime/support/time_logs.py +61 -0
  90. kaiten_cli/runtime/support/tree.py +140 -0
  91. kaiten_cli/runtime/support/tree_sharing.py +447 -0
  92. kaiten_cli/runtime/trace.py +500 -0
  93. kaiten_cli/runtime/transforms.py +128 -0
  94. kaiten_cli/schema_docs.py +22 -0
  95. kaiten_cli/update_check.py +519 -0
  96. kaiten_cli-0.3.3.dist-info/METADATA +1110 -0
  97. kaiten_cli-0.3.3.dist-info/RECORD +99 -0
  98. kaiten_cli-0.3.3.dist-info/WHEEL +4 -0
  99. kaiten_cli-0.3.3.dist-info/entry_points.txt +3 -0
@@ -0,0 +1,310 @@
1
+ """Input merging and schema coercion."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ import re
7
+ import sys
8
+ from pathlib import Path
9
+ from typing import Any
10
+
11
+ from kaiten_cli.errors import ValidationError
12
+ from kaiten_cli.i18n import tr
13
+ from kaiten_cli.models import UNSET, ToolSpec
14
+
15
+
16
+ def _read_text_source(source: str, stdin_text: str | None) -> str:
17
+ if source == "-":
18
+ if stdin_text is not None:
19
+ return stdin_text
20
+ return sys.stdin.read()
21
+ if source.startswith("@"):
22
+ return Path(source[1:]).read_text(encoding="utf-8")
23
+ return source
24
+
25
+
26
+ def _json_value(source: str, stdin_text: str | None, label: str) -> Any:
27
+ text = _read_text_source(source, stdin_text)
28
+ try:
29
+ return json.loads(text)
30
+ except json.JSONDecodeError as exc:
31
+ raise ValidationError(
32
+ tr("Invalid JSON for {value_0}: {value_1}", value_0=label, value_1=exc.msg)
33
+ ) from exc
34
+
35
+
36
+ def _coerce_nullable_string(raw: str) -> str | None:
37
+ if raw == "null":
38
+ return None
39
+ return raw
40
+
41
+
42
+ def coerce_value(
43
+ raw: Any, schema: dict[str, Any], *, stdin_text: str | None = None, label: str
44
+ ) -> Any:
45
+ if raw is UNSET:
46
+ return UNSET
47
+
48
+ schema_type = schema.get("type")
49
+ type_list = schema_type if isinstance(schema_type, list) else [schema_type]
50
+ if raw is None:
51
+ return None
52
+ if "null" in type_list and isinstance(raw, str):
53
+ raw = _coerce_nullable_string(raw)
54
+ if raw is None:
55
+ return None
56
+ if "oneOf" in schema:
57
+ # Preserve already typed values before attempting CLI string coercion.
58
+ for variant in schema["oneOf"]:
59
+ try:
60
+ _validate_schema(raw, variant, path=label)
61
+ except ValidationError:
62
+ continue
63
+ return raw
64
+ for variant in schema["oneOf"]:
65
+ try:
66
+ candidate = coerce_value(raw, variant, stdin_text=stdin_text, label=label)
67
+ _validate_schema(candidate, variant, path=label)
68
+ except ValidationError:
69
+ continue
70
+ return candidate
71
+ return raw # Full validation reports the field and failed union.
72
+ if "array" in type_list or "object" in type_list:
73
+ if not isinstance(raw, str):
74
+ return raw
75
+ if "string" in type_list and raw != "-" and not raw.startswith("@"):
76
+ # Plain strings remain valid in a union. Explicit JSON structures
77
+ # and sources still fail loudly on malformed JSON.
78
+ if not raw.lstrip().startswith(("[", "{", '"')):
79
+ try:
80
+ parsed = json.loads(raw)
81
+ except json.JSONDecodeError:
82
+ return raw
83
+ return parsed if any(_type_matches(parsed, kind) for kind in type_list) else raw
84
+ return _json_value(raw, stdin_text, label)
85
+ if isinstance(raw, str) and "string" not in type_list:
86
+ if "integer" in type_list:
87
+ try:
88
+ return int(raw)
89
+ except ValueError as exc:
90
+ if "number" not in type_list:
91
+ raise ValidationError(
92
+ tr("Field {value_0} must be an integer or null.", value_0=label)
93
+ ) from exc
94
+ if "number" in type_list:
95
+ try:
96
+ return float(raw)
97
+ except ValueError as exc:
98
+ raise ValidationError(
99
+ tr("Field {value_0} must be a number or null.", value_0=label)
100
+ ) from exc
101
+ return raw
102
+
103
+
104
+ def merge_inputs(
105
+ tool: ToolSpec,
106
+ option_values: dict[str, Any],
107
+ *,
108
+ from_file: str | None = None,
109
+ stdin_json: bool = False,
110
+ stdin_text: str | None = None,
111
+ ) -> dict[str, Any]:
112
+ if stdin_json and from_file:
113
+ raise ValidationError(tr("Use either --stdin-json or --from-file, not both."))
114
+
115
+ base_payload: dict[str, Any] = {}
116
+ if from_file:
117
+ payload = _json_value(f"@{from_file}", stdin_text, "--from-file")
118
+ if not isinstance(payload, dict):
119
+ raise ValidationError(tr("--from-file must contain a JSON object."))
120
+ base_payload = payload
121
+ elif stdin_json:
122
+ payload = _json_value("-", stdin_text, "--stdin-json")
123
+ if not isinstance(payload, dict):
124
+ raise ValidationError(tr("--stdin-json must read a JSON object."))
125
+ base_payload = payload
126
+
127
+ properties = tool.input_schema.get("properties", {})
128
+ unknown = set(base_payload) - set(properties)
129
+ if unknown:
130
+ raise ValidationError(
131
+ tr("Unknown input field(s): {value_0}", value_0=", ".join(sorted(unknown)))
132
+ )
133
+
134
+ merged = dict(base_payload)
135
+ for field_name, raw_value in option_values.items():
136
+ if raw_value is UNSET:
137
+ continue
138
+ if raw_value is None:
139
+ continue
140
+ if field_name not in properties:
141
+ continue
142
+ schema = properties[field_name]
143
+ merged[field_name] = coerce_value(
144
+ raw_value, schema, stdin_text=stdin_text, label=field_name
145
+ )
146
+
147
+ validate_payload(tool, merged)
148
+ if tool.runtime_behavior.payload_validator is not None:
149
+ tool.runtime_behavior.payload_validator(tool, merged)
150
+ return merged
151
+
152
+
153
+ def _type_matches(value: Any, expected: str) -> bool:
154
+ if expected == "string":
155
+ return isinstance(value, str)
156
+ if expected == "integer":
157
+ return isinstance(value, int) and not isinstance(value, bool)
158
+ if expected == "number":
159
+ return isinstance(value, (int, float)) and not isinstance(value, bool)
160
+ if expected == "boolean":
161
+ return isinstance(value, bool)
162
+ if expected == "object":
163
+ return isinstance(value, dict)
164
+ if expected == "array":
165
+ return isinstance(value, list)
166
+ if expected == "null":
167
+ return value is None
168
+ return True
169
+
170
+
171
+ def _format_path(path: str) -> str:
172
+ return path or "payload"
173
+
174
+
175
+ def _enum_contains(enum_values: list[Any], value: Any) -> bool:
176
+ """Compare enum values without treating booleans as the integers 0 and 1."""
177
+ for candidate in enum_values:
178
+ if isinstance(candidate, bool) != isinstance(value, bool):
179
+ continue
180
+ if candidate == value:
181
+ return True
182
+ return False
183
+
184
+
185
+ def _validate_schema(value: Any, schema: dict[str, Any], *, path: str) -> None:
186
+ if "oneOf" in schema:
187
+ matches = 0
188
+ for variant in schema["oneOf"]:
189
+ try:
190
+ _validate_schema(value, variant, path=path)
191
+ except ValidationError:
192
+ continue
193
+ matches += 1
194
+ if matches != 1:
195
+ raise ValidationError(
196
+ tr(
197
+ "Field {value_0} must match exactly one schema in oneOf.",
198
+ value_0=_format_path(path),
199
+ )
200
+ )
201
+ schema_type = schema.get("type")
202
+ if schema_type is not None:
203
+ allowed_types = schema_type if isinstance(schema_type, list) else [schema_type]
204
+ if not any(_type_matches(value, expected) for expected in allowed_types):
205
+ expected = tr(" or ").join(str(item) for item in allowed_types)
206
+ raise ValidationError(
207
+ tr(
208
+ "Field {value_0} has invalid type; expected {value_1}.",
209
+ value_0=_format_path(path),
210
+ value_1=expected,
211
+ )
212
+ )
213
+
214
+ enum_values = schema.get("enum")
215
+ # Registry schemas use nullable types with a non-null enum as shorthand for
216
+ # "one of these values, or null". Preserve that established convention.
217
+ if enum_values is not None and value is not None and not _enum_contains(enum_values, value):
218
+ allowed = ", ".join(map(str, enum_values))
219
+ raise ValidationError(
220
+ tr(
221
+ "Field {value_0} must be one of: {value_1}",
222
+ value_0=_format_path(path),
223
+ value_1=allowed,
224
+ )
225
+ )
226
+
227
+ if isinstance(value, (int, float)) and not isinstance(value, bool):
228
+ minimum = schema.get("minimum")
229
+ maximum = schema.get("maximum")
230
+ if minimum is not None and value < minimum:
231
+ raise ValidationError(
232
+ tr(
233
+ "Field {value_0} must be greater than or equal to {value_1}.",
234
+ value_0=_format_path(path),
235
+ value_1=minimum,
236
+ )
237
+ )
238
+ if maximum is not None and value > maximum:
239
+ raise ValidationError(
240
+ tr(
241
+ "Field {value_0} must be less than or equal to {value_1}.",
242
+ value_0=_format_path(path),
243
+ value_1=maximum,
244
+ )
245
+ )
246
+
247
+ if isinstance(value, (str, list)):
248
+ limits = ("minLength", "maxLength") if isinstance(value, str) else ("minItems", "maxItems")
249
+ for keyword, compare in (
250
+ (limits[0], lambda n, bound: n < bound),
251
+ (limits[1], lambda n, bound: n > bound),
252
+ ):
253
+ bound = schema.get(keyword)
254
+ if bound is not None and compare(len(value), bound):
255
+ raise ValidationError(
256
+ tr(
257
+ "Field {value_0} violates {value_1}: {value_2}.",
258
+ value_0=_format_path(path),
259
+ value_1=keyword,
260
+ value_2=bound,
261
+ )
262
+ )
263
+
264
+ if isinstance(value, dict):
265
+ properties = schema.get("properties", {})
266
+ required = schema.get("required", [])
267
+ missing = [field for field in required if field not in value]
268
+ if missing:
269
+ location = tr(" at {path}", path=_format_path(path)) if path else ""
270
+ raise ValidationError(
271
+ tr(
272
+ "Missing required field(s){value_0}: {value_1}",
273
+ value_0=location,
274
+ value_1=", ".join(sorted(missing)),
275
+ )
276
+ )
277
+
278
+ pattern_matched = set()
279
+ for pattern, pattern_schema in schema.get("patternProperties", {}).items():
280
+ for field_name, field_value in value.items():
281
+ if re.search(pattern, field_name):
282
+ pattern_matched.add(field_name)
283
+ field_path = f"{path}.{field_name}" if path else field_name
284
+ _validate_schema(field_value, pattern_schema, path=field_path)
285
+ if schema.get("additionalProperties") is False:
286
+ unknown = set(value) - set(properties) - pattern_matched
287
+ if unknown:
288
+ raise ValidationError(
289
+ tr(
290
+ "Unknown field(s) at {value_0}: {value_1}",
291
+ value_0=_format_path(path),
292
+ value_1=", ".join(sorted(unknown)),
293
+ )
294
+ )
295
+
296
+ for field_name, field_schema in properties.items():
297
+ if field_name not in value:
298
+ continue
299
+ field_path = f"{path}.{field_name}" if path else field_name
300
+ _validate_schema(value[field_name], field_schema, path=field_path)
301
+
302
+ if isinstance(value, list) and isinstance(schema.get("items"), dict):
303
+ item_schema = schema["items"]
304
+ for index, item in enumerate(value):
305
+ item_path = f"{path}[{index}]" if path else f"[{index}]"
306
+ _validate_schema(item, item_schema, path=item_path)
307
+
308
+
309
+ def validate_payload(tool: ToolSpec, payload: dict[str, Any]) -> None:
310
+ _validate_schema(payload, tool.input_schema, path="")
@@ -0,0 +1,59 @@
1
+ """Rendering helpers."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ from typing import Any
7
+
8
+ from kaiten_cli.errors import CliError
9
+ from kaiten_cli.i18n import tr
10
+
11
+
12
+ def render_success(
13
+ command: str, data: Any, json_mode: bool, stats: dict[str, Any] | None = None
14
+ ) -> str:
15
+ if json_mode:
16
+ payload = {"success": True, "command": command, "data": data}
17
+ if stats is not None:
18
+ payload["stats"] = stats
19
+ return json.dumps(payload, ensure_ascii=False, default=str)
20
+ if data is None:
21
+ return tr("OK")
22
+ if isinstance(data, str):
23
+ return data
24
+ return json.dumps(data, ensure_ascii=False, indent=2, default=str)
25
+
26
+
27
+ def render_error(
28
+ command: str | None,
29
+ error: CliError,
30
+ json_mode: bool,
31
+ stats: dict[str, Any] | None = None,
32
+ ) -> str:
33
+ if json_mode:
34
+ payload = {"success": False, "command": command, "error": error.to_dict()}
35
+ if stats is not None:
36
+ payload["stats"] = stats
37
+ return json.dumps(payload, ensure_ascii=False, default=str)
38
+ prefix = tr(error.error_type.replace("_", " ").capitalize())
39
+ if hasattr(error, "status_code"):
40
+ headline = tr(
41
+ "{value_0} {value_1}: {value_2}",
42
+ value_0=prefix,
43
+ value_1=getattr(error, "status_code"),
44
+ value_2=error.message,
45
+ )
46
+ else:
47
+ headline = tr("{value_0}: {value_1}", value_0=prefix, value_1=error.message)
48
+ if not error.details:
49
+ return headline
50
+ lines = [headline]
51
+ if suggested_usage := error.details.get("suggested_usage"):
52
+ lines.append(tr("Suggested usage: {value_0}", value_0=suggested_usage))
53
+ if supported_options := error.details.get("supported_options"):
54
+ lines.append(tr("Supported options: {value_0}", value_0=", ".join(supported_options)))
55
+ if bulk_alternative := error.details.get("bulk_alternative"):
56
+ lines.append(tr("Bulk alternative: {value_0}", value_0=bulk_alternative))
57
+ if next_step := error.details.get("next"):
58
+ lines.append(tr("Next: {value_0}", value_0=next_step))
59
+ return "\n".join(lines)
@@ -0,0 +1,35 @@
1
+ """Small compatibility validators for alternate documented request forms."""
2
+
3
+ from kaiten_cli.errors import ValidationError
4
+ from kaiten_cli.i18n import tr
5
+
6
+
7
+ def validate_public_request(tool, payload):
8
+ name = tool.canonical_name
9
+ alternatives = {
10
+ "space-users.add": [("email",), ("user_id",)],
11
+ "blocker-categories.add": [("name",), ("category_uuid",)],
12
+ "custom-properties.create": [("name", "type"), ("formula", "formula_source_card")],
13
+ "custom-properties.collective-vote-values.create": [
14
+ ("value",),
15
+ ("emoji_vote",),
16
+ ("number_vote",),
17
+ ("payload",),
18
+ ],
19
+ }
20
+ if name in alternatives:
21
+ if not any(all(field in payload for field in fields) for fields in alternatives[name]):
22
+ choices = tr(" or ").join(" + ".join(fields) for fields in alternatives[name])
23
+ raise ValidationError(tr("Missing required input: {value_0}.", value_0=choices))
24
+ if name.startswith("private-") and payload.get("redirect") is True:
25
+ raise ValidationError(
26
+ tr(
27
+ "Field redirect=true returns binary/redirect content instead of JSON metadata. Use files.download to download restricted files safely."
28
+ )
29
+ )
30
+
31
+
32
+ def validate_nonempty_body(tool, payload):
33
+ """Require a body field while preserving explicit zero, false, and null values."""
34
+ if not any(field in payload for field in tool.operation.body_fields):
35
+ raise ValidationError(tr("Provide at least one field to update."))