codemie-cdk-python 0.1.0rc0__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 (39) hide show
  1. codemie_cdk_python-0.1.0rc0.dist-info/METADATA +840 -0
  2. codemie_cdk_python-0.1.0rc0.dist-info/RECORD +39 -0
  3. codemie_cdk_python-0.1.0rc0.dist-info/WHEEL +4 -0
  4. codemie_cdk_python-0.1.0rc0.dist-info/entry_points.txt +3 -0
  5. codemie_iac/__init__.py +49 -0
  6. codemie_iac/cli/__init__.py +17 -0
  7. codemie_iac/cli/__main__.py +24 -0
  8. codemie_iac/cli/commands/__init__.py +17 -0
  9. codemie_iac/cli/commands/apply.py +119 -0
  10. codemie_iac/cli/commands/plan.py +72 -0
  11. codemie_iac/cli/documents.py +59 -0
  12. codemie_iac/cli/env_file.py +62 -0
  13. codemie_iac/cli/exit_status.py +80 -0
  14. codemie_iac/cli/main.py +118 -0
  15. codemie_iac/cli/render.py +206 -0
  16. codemie_iac/cli/target_config.py +230 -0
  17. codemie_iac/cli/token_client.py +42 -0
  18. codemie_iac/credentials.py +99 -0
  19. codemie_iac/envelope.py +188 -0
  20. codemie_iac/plan_apply/__init__.py +70 -0
  21. codemie_iac/plan_apply/bulk_create.py +561 -0
  22. codemie_iac/plan_apply/credentials.py +306 -0
  23. codemie_iac/plan_apply/errors.py +223 -0
  24. codemie_iac/plan_apply/field_policy.py +185 -0
  25. codemie_iac/plan_apply/guards.py +221 -0
  26. codemie_iac/plan_apply/kinds.py +815 -0
  27. codemie_iac/plan_apply/lookup.py +313 -0
  28. codemie_iac/plan_apply/ordering.py +177 -0
  29. codemie_iac/plan_apply/single_apply.py +751 -0
  30. codemie_iac/resolver.py +61 -0
  31. codemie_iac/schema.py +106 -0
  32. codemie_iac/serializer.py +64 -0
  33. codemie_iac/specs/__init__.py +13 -0
  34. codemie_iac/specs/assistant.py +509 -0
  35. codemie_iac/specs/category.py +36 -0
  36. codemie_iac/specs/datasource.py +595 -0
  37. codemie_iac/specs/integration.py +103 -0
  38. codemie_iac/specs/skill.py +51 -0
  39. codemie_iac/specs/workflow.py +154 -0
@@ -0,0 +1,185 @@
1
+ # Copyright 2026 EPAM Systems, Inc. ("EPAM")
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """Hand-written, explicit field policies for the single-entity diff.
16
+
17
+ For every kind (and every datasource ``type``) each field of the live SDK
18
+ response is classified exactly once:
19
+
20
+ - ``deny``: server-managed or otherwise not authored by the IaC document
21
+ (ids, audit stamps, counters, indexing state, ciphertext...). Ignored by
22
+ the diff.
23
+ - ``comparable``: a candidate for comparison against the document spec.
24
+
25
+ The lists are written by hand on purpose, not derived from the SDK write
26
+ models: a new server-managed response field must be classified explicitly
27
+ rather than silently become a perpetual "difference".
28
+
29
+ Names refer to the *flattened* live view built by ``single_apply`` (datasource
30
+ sub-objects such as ``jira``/``code`` are merged into the top level, and
31
+ ``google_doc_link`` is also exposed as ``google_doc``). The sub-object keys
32
+ themselves are therefore in ``deny``.
33
+ """
34
+
35
+ from pydantic import BaseModel, ConfigDict
36
+
37
+ from ..envelope import Document, DocumentKind
38
+
39
+ __all__ = ["FIELD_POLICIES", "FieldPolicy", "policy_for"]
40
+
41
+
42
+ class FieldPolicy(BaseModel):
43
+ model_config = ConfigDict(extra="forbid", frozen=True)
44
+
45
+ deny: frozenset[str]
46
+ comparable: frozenset[str]
47
+
48
+
49
+ def _policy(deny: str, comparable: str) -> FieldPolicy:
50
+ return FieldPolicy(
51
+ deny=frozenset(deny.split()), comparable=frozenset(comparable.split())
52
+ )
53
+
54
+
55
+ _ASSISTANT = _policy(
56
+ # Assistant response: ids, audit stamps, usage statistics, derived values.
57
+ deny="id created_by system_prompt_history created_date updated_date creator "
58
+ "user_abilities display_name version_count unique_users_count "
59
+ "unique_likes_count unique_dislikes_count clone_count",
60
+ comparable="name description icon_url system_prompt project llm_model_type "
61
+ "toolkits conversation_starters shared is_react is_global slug temperature "
62
+ "top_p tools_tokens_size_limit context mcp_servers assistant_ids "
63
+ "skill_ids enabled_builtin_subagents prompt_variables categories tool_permissions "
64
+ "hedging_config interactive_enabled enable_image_generation "
65
+ "file_attachment_enabled",
66
+ )
67
+
68
+ _SKILL = _policy(
69
+ # slug/icon_url/mcp_servers/display_name are not authored by SkillSpec;
70
+ # bundle_warning is a server note about the skill bundle.
71
+ deny="id display_name created_date created_by updated_date is_attached "
72
+ "reactions_count assistants_count mcp_servers slug icon_url bundle_warning",
73
+ comparable="name description project visibility categories "
74
+ "enabled_builtin_subagents content",
75
+ )
76
+
77
+ _WORKFLOW = _policy(
78
+ deny="id created_date update_date created_by display_name required_variables",
79
+ comparable="project name description yaml_config mode shared icon_url start_hint",
80
+ )
81
+
82
+ _CATEGORY = _policy(
83
+ deny="id marketplace_count project_count",
84
+ comparable="name description",
85
+ )
86
+
87
+ _INTEGRATION = _policy(
88
+ deny="id date update_date user_id",
89
+ comparable="project_name alias default is_global credential_type "
90
+ "credential_values setting_type",
91
+ )
92
+
93
+ # Server-managed datasource state shared by every type. ``error``,
94
+ # ``updated_by`` and ``ciphertext`` are raw backend keys the SDK model ignores
95
+ # but which may still reach a dict-based live view.
96
+ _DS_DENY = (
97
+ "id status created_date created_by update_date updated_date "
98
+ "last_reindex_date error_message user_abilities processing_info "
99
+ "processed_documents tokens_usage completed complete_state current_state "
100
+ "ciphertext code git_faq jira confluence azure_devops_wiki "
101
+ "azure_devops_work_item xwiki svn sharepoint xray provider"
102
+ )
103
+ # ``timezone`` is only exposed alongside a ``cron_expression`` (see
104
+ # ``_datasource_view``): without a schedule the backend reports a default.
105
+ _DS_COMMON = (
106
+ "project_name name description type embeddings_model setting_id "
107
+ "shared_with_project cron_expression timezone"
108
+ )
109
+
110
+
111
+ def _datasource(
112
+ comparable: str = "", extra_deny: str = "", not_comparable: str = ""
113
+ ) -> FieldPolicy:
114
+ """``not_comparable`` names common fields the type's update cannot carry:
115
+ they leave the comparable set and join the deny list."""
116
+ dropped = set(not_comparable.split())
117
+ deny = f"{_DS_DENY} {extra_deny} {not_comparable}".split()
118
+ # Only Google datasources author a document link (and its ``google_doc``
119
+ # alias, which the flattened live view derives from ``google_doc_link``).
120
+ if "google_doc_link" not in comparable.split():
121
+ deny.extend(("google_doc_link", "google_doc"))
122
+ return _policy(
123
+ deny=" ".join(deny),
124
+ comparable=" ".join(
125
+ [t for t in _DS_COMMON.split() if t not in dropped] + comparable.split()
126
+ ),
127
+ )
128
+
129
+
130
+ # Fields only the create request accepts (or the backend does not store) are
131
+ # not compared: an update cannot change them, so they would differ forever.
132
+ # That is the Confluence ``include_*``/``keep_*`` flags, the code
133
+ # ``index_type``/``summarization_model``, the Git FAQ ``embedding_model`` and
134
+ # the Azure DevOps ``organization``/``project``.
135
+ _CONFLUENCE = "cql"
136
+
137
+ FIELD_POLICIES: dict[str, FieldPolicy] = {
138
+ DocumentKind.ASSISTANT.value: _ASSISTANT,
139
+ DocumentKind.SKILL.value: _SKILL,
140
+ DocumentKind.WORKFLOW.value: _WORKFLOW,
141
+ DocumentKind.CATEGORY.value: _CATEGORY,
142
+ DocumentKind.INTEGRATION.value: _INTEGRATION,
143
+ # Datasource types, keyed by spec ``type``.
144
+ "code": _datasource("link branch files_filter prompt docs_generation"),
145
+ "knowledge_base_git_faq": _datasource(
146
+ "link branch files_filter", extra_deny="error"
147
+ ),
148
+ "knowledge_base_jira": _datasource("jql custom_fields"),
149
+ "knowledge_base_confluence": _datasource(_CONFLUENCE),
150
+ "llm_routing_google": _datasource("google_doc google_doc_link", extra_deny="error"),
151
+ "knowledge_base_azure_devops_wiki": _datasource("wiki_query wiki_name"),
152
+ "knowledge_base_azure_devops_work_item": _datasource("wiql_query"),
153
+ "knowledge_base_xwiki": _datasource("space wiki"),
154
+ # The SVN update request cannot change the index type: create-only.
155
+ "svn": _datasource(
156
+ "link branch files_filter prompt docs_generation", extra_deny="index_type"
157
+ ),
158
+ "knowledge_base_sharepoint": _datasource(
159
+ "site_url include_pages include_documents include_lists max_file_size_mb "
160
+ "files_filter embedding_model auth_type oauth_client_id oauth_tenant_id",
161
+ # The OAuth access token is transient: the platform never returns it.
162
+ extra_deny="access_token",
163
+ ),
164
+ # The Xray update route does not store an embedding model: create-only.
165
+ "knowledge_base_xray": _datasource(
166
+ "jql", extra_deny="embedding_model", not_comparable="embeddings_model"
167
+ ),
168
+ # ``settings`` is derived from the live provider base/create params (see
169
+ # ``single_apply._flatten_live``); the raw params and provider id are
170
+ # server-shaped and denied.
171
+ "provider": _datasource(
172
+ "settings",
173
+ extra_deny="toolkit_id provider_name provider_id base_params create_params",
174
+ # The provider request takes no schedule.
175
+ not_comparable="cron_expression timezone",
176
+ ),
177
+ "knowledge_base_file": _datasource(extra_deny="error updated_by"),
178
+ }
179
+
180
+
181
+ def policy_for(document: Document) -> FieldPolicy:
182
+ """The policy for a document: by datasource ``type``, else by kind."""
183
+ kind = document.meta.kind
184
+ key = document.spec.type if kind is DocumentKind.DATASOURCE else kind.value
185
+ return FIELD_POLICIES[key]
@@ -0,0 +1,221 @@
1
+ # Copyright 2026 EPAM Systems, Inc. ("EPAM")
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """Guards for operations that are not supported on datasources.
16
+
17
+ ``guard_supported`` rejects file datasources before any adapter lookup;
18
+ ``guard_datasource_identity`` rejects a rename or a move to another project
19
+ by comparing the document with the live datasource, before any write.
20
+ """
21
+
22
+ from collections.abc import Mapping
23
+ from typing import Any
24
+
25
+ from codemie_sdk.models.assistant import (
26
+ Assistant,
27
+ AssistantCreateRequest,
28
+ AssistantUpdateRequest,
29
+ )
30
+
31
+ from ..envelope import Document, DocumentKind
32
+ from .errors import ApplyError
33
+
34
+ __all__ = [
35
+ "SPEC_PROJECT_FIELDS",
36
+ "with_default_project",
37
+ "guard_datasource_identity",
38
+ "guard_name",
39
+ "guard_project",
40
+ "guard_supported",
41
+ ]
42
+
43
+ #: kind -> name of the spec field that carries the entity's project (``None``
44
+ #: when the document omits it). Workflows
45
+ #: take the target project when written and categories are global, so neither
46
+ #: has one.
47
+ SPEC_PROJECT_FIELDS = {
48
+ DocumentKind.ASSISTANT: "project",
49
+ DocumentKind.SKILL: "project",
50
+ DocumentKind.INTEGRATION: "project_name",
51
+ DocumentKind.DATASOURCE: "project_name",
52
+ }
53
+
54
+ #: kind -> the spec field the platform knows the entity by. References resolve
55
+ #: through ``meta.name``, so it has to be the same string.
56
+ _SPEC_NAME_FIELDS = {
57
+ DocumentKind.ASSISTANT: lambda spec: spec.name,
58
+ DocumentKind.SKILL: lambda spec: spec.name,
59
+ DocumentKind.CATEGORY: lambda spec: spec.name,
60
+ DocumentKind.DATASOURCE: lambda spec: spec.name,
61
+ DocumentKind.WORKFLOW: lambda spec: spec.workflow.name,
62
+ DocumentKind.INTEGRATION: lambda spec: spec.alias,
63
+ }
64
+
65
+ _FILE_TYPE = "knowledge_base_file"
66
+
67
+
68
+ def _is_datasource(document: Document) -> bool:
69
+ return document.meta.kind is DocumentKind.DATASOURCE
70
+
71
+
72
+ def _error(document: Document, error_type: str, reason: str) -> ApplyError:
73
+ return ApplyError(error_type, document.meta.kind.value, document.meta.name, reason)
74
+
75
+
76
+ def _sdk_carries_assistant_skills() -> bool:
77
+ """Whether the installed SDK's assistant requests and the live assistant
78
+ model have a ``skill_ids`` field. Older SDKs ignore unknown fields, so
79
+ skills would be dropped on write and missing from the plan diff."""
80
+ return all(
81
+ "skill_ids" in cls.model_fields
82
+ for cls in (Assistant, AssistantCreateRequest, AssistantUpdateRequest)
83
+ )
84
+
85
+
86
+ def guard_supported(document: Document) -> None:
87
+ """Raise ``ApplyError`` for what cannot be written: a file datasource (no
88
+ adapter is consulted), a workflow without a description (the platform
89
+ requires one, and the update request rejects an empty one), or an assistant
90
+ with ``skill_ids`` (even an empty list, which detaches skills) when the
91
+ installed SDK cannot send them."""
92
+ if document.meta.kind is DocumentKind.WORKFLOW:
93
+ if not (document.spec.workflow.description or "").strip():
94
+ raise _error(
95
+ document,
96
+ "invalid_workflow",
97
+ "a workflow needs a non-empty description",
98
+ )
99
+ if _is_datasource(document) and document.spec.type == _FILE_TYPE:
100
+ raise _error(
101
+ document,
102
+ "unsupported_datasource_type",
103
+ f"datasource type {_FILE_TYPE!r}: file datasources are not supported",
104
+ )
105
+ if (
106
+ document.meta.kind is DocumentKind.ASSISTANT
107
+ and document.spec.skill_ids is not None
108
+ and not _sdk_carries_assistant_skills()
109
+ ):
110
+ raise _error(
111
+ document,
112
+ "unsupported_sdk",
113
+ "skill_ids: the installed codemie-sdk assistant request has no "
114
+ "skill_ids field, so the skills would be dropped silently; upgrade "
115
+ "codemie-sdk-python or remove skill_ids from the document",
116
+ )
117
+
118
+
119
+ def _live_value(live: Any, key: str) -> Any:
120
+ if isinstance(live, Mapping):
121
+ return live.get(key)
122
+ return getattr(live, key, None)
123
+
124
+
125
+ def _live_toolkit_id(live: Any) -> Any:
126
+ provider = _live_value(live, "provider")
127
+ return _live_value(provider, "toolkit_id") if provider is not None else None
128
+
129
+
130
+ def guard_datasource_identity(document: Document, live: Any) -> None:
131
+ """Raise ``ApplyError`` if the live datasource has another name, project
132
+ or (provider) toolkit."""
133
+ if not _is_datasource(document):
134
+ return
135
+ spec = document.spec
136
+ live_toolkit = _live_toolkit_id(live)
137
+ if (
138
+ spec.type == "provider"
139
+ and live_toolkit is not None
140
+ and live_toolkit != spec.toolkit_id
141
+ ):
142
+ raise _error(
143
+ document,
144
+ "datasource_identity_mismatch",
145
+ f"toolkit_id cannot change (document {spec.toolkit_id!r}, live "
146
+ f"{live_toolkit!r}); recreate the datasource",
147
+ )
148
+ live_name = _live_value(live, "name")
149
+ live_project = _live_value(live, "project_name")
150
+ if live_name == spec.name and live_project == spec.project_name:
151
+ _guard_google_document(document, live)
152
+ return
153
+ raise _error(
154
+ document,
155
+ "datasource_identity_mismatch",
156
+ "renaming or moving a datasource is not supported: document is "
157
+ f"{spec.name!r} in project {spec.project_name!r}, live is "
158
+ f"{live_name!r} in project {live_project!r}",
159
+ )
160
+
161
+
162
+ def _guard_google_document(document: Document, live: Any) -> None:
163
+ """The Google update route reindexes from the stored link and cannot take a
164
+ new one, so a changed document would be reported as applied and never be."""
165
+ if document.spec.type != "llm_routing_google":
166
+ return
167
+ live_doc = _live_value(live, "google_doc_link")
168
+ if live_doc is not None and live_doc != document.spec.google_doc:
169
+ raise _error(
170
+ document,
171
+ "unsupported_datasource_change",
172
+ "changing the document of a Google datasource is not supported: "
173
+ "create a new datasource for the new document",
174
+ )
175
+
176
+
177
+ def with_default_project(document: Document, target: str) -> Document:
178
+ """Return ``document`` with an omitted project set to ``target``.
179
+
180
+ A document that names a project is returned as is, so ``guard_project``
181
+ still refuses one that differs from the target.
182
+ """
183
+ field = SPEC_PROJECT_FIELDS.get(document.meta.kind)
184
+ if field is None or getattr(document.spec, field, None) is not None:
185
+ return document
186
+ spec = document.spec.model_copy(update={field: target})
187
+ return document.model_copy(update={"spec": spec})
188
+
189
+
190
+ def guard_project(document: Document, target: str) -> None:
191
+ """Raise ``ApplyError`` if the document names a project other than ``target``.
192
+
193
+ The request body takes its project from the document, so an entity would
194
+ otherwise be created in (or moved to) a project the run does not target.
195
+ """
196
+ field = SPEC_PROJECT_FIELDS.get(document.meta.kind)
197
+ project = getattr(document.spec, field, None) if field else None
198
+ if project is not None and project != target:
199
+ raise _error(
200
+ document,
201
+ "project_mismatch",
202
+ f"document is in project {project!r}, not target {target!r}",
203
+ )
204
+
205
+
206
+ def guard_name(document: Document) -> None:
207
+ """Raise ``ApplyError`` if ``meta.name`` differs from the entity's own name.
208
+
209
+ Bundle matching and the live lookup use ``meta.name``, while the platform
210
+ (and the names other entities reference) use the spec name, so the two
211
+ must be equal or a reference by either would miss.
212
+ """
213
+ spec_name = _SPEC_NAME_FIELDS[document.meta.kind](document.spec)
214
+ if spec_name != document.meta.name:
215
+ raise _error(
216
+ document,
217
+ "name_mismatch",
218
+ f"meta.name {document.meta.name!r} differs from the "
219
+ f"{'alias' if document.meta.kind is DocumentKind.INTEGRATION else 'name'}"
220
+ f" in the spec {spec_name!r}; they must be equal",
221
+ )