codemie-cdk-python 0.1.0rc0__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 (38) hide show
  1. codemie_cdk_python-0.1.0rc0/PKG-INFO +840 -0
  2. codemie_cdk_python-0.1.0rc0/README.md +822 -0
  3. codemie_cdk_python-0.1.0rc0/pyproject.toml +31 -0
  4. codemie_cdk_python-0.1.0rc0/src/codemie_iac/__init__.py +49 -0
  5. codemie_cdk_python-0.1.0rc0/src/codemie_iac/cli/__init__.py +17 -0
  6. codemie_cdk_python-0.1.0rc0/src/codemie_iac/cli/__main__.py +24 -0
  7. codemie_cdk_python-0.1.0rc0/src/codemie_iac/cli/commands/__init__.py +17 -0
  8. codemie_cdk_python-0.1.0rc0/src/codemie_iac/cli/commands/apply.py +119 -0
  9. codemie_cdk_python-0.1.0rc0/src/codemie_iac/cli/commands/plan.py +72 -0
  10. codemie_cdk_python-0.1.0rc0/src/codemie_iac/cli/documents.py +59 -0
  11. codemie_cdk_python-0.1.0rc0/src/codemie_iac/cli/env_file.py +62 -0
  12. codemie_cdk_python-0.1.0rc0/src/codemie_iac/cli/exit_status.py +80 -0
  13. codemie_cdk_python-0.1.0rc0/src/codemie_iac/cli/main.py +118 -0
  14. codemie_cdk_python-0.1.0rc0/src/codemie_iac/cli/render.py +206 -0
  15. codemie_cdk_python-0.1.0rc0/src/codemie_iac/cli/target_config.py +230 -0
  16. codemie_cdk_python-0.1.0rc0/src/codemie_iac/cli/token_client.py +42 -0
  17. codemie_cdk_python-0.1.0rc0/src/codemie_iac/credentials.py +99 -0
  18. codemie_cdk_python-0.1.0rc0/src/codemie_iac/envelope.py +188 -0
  19. codemie_cdk_python-0.1.0rc0/src/codemie_iac/plan_apply/__init__.py +70 -0
  20. codemie_cdk_python-0.1.0rc0/src/codemie_iac/plan_apply/bulk_create.py +561 -0
  21. codemie_cdk_python-0.1.0rc0/src/codemie_iac/plan_apply/credentials.py +306 -0
  22. codemie_cdk_python-0.1.0rc0/src/codemie_iac/plan_apply/errors.py +223 -0
  23. codemie_cdk_python-0.1.0rc0/src/codemie_iac/plan_apply/field_policy.py +185 -0
  24. codemie_cdk_python-0.1.0rc0/src/codemie_iac/plan_apply/guards.py +221 -0
  25. codemie_cdk_python-0.1.0rc0/src/codemie_iac/plan_apply/kinds.py +815 -0
  26. codemie_cdk_python-0.1.0rc0/src/codemie_iac/plan_apply/lookup.py +313 -0
  27. codemie_cdk_python-0.1.0rc0/src/codemie_iac/plan_apply/ordering.py +177 -0
  28. codemie_cdk_python-0.1.0rc0/src/codemie_iac/plan_apply/single_apply.py +751 -0
  29. codemie_cdk_python-0.1.0rc0/src/codemie_iac/resolver.py +61 -0
  30. codemie_cdk_python-0.1.0rc0/src/codemie_iac/schema.py +106 -0
  31. codemie_cdk_python-0.1.0rc0/src/codemie_iac/serializer.py +64 -0
  32. codemie_cdk_python-0.1.0rc0/src/codemie_iac/specs/__init__.py +13 -0
  33. codemie_cdk_python-0.1.0rc0/src/codemie_iac/specs/assistant.py +509 -0
  34. codemie_cdk_python-0.1.0rc0/src/codemie_iac/specs/category.py +36 -0
  35. codemie_cdk_python-0.1.0rc0/src/codemie_iac/specs/datasource.py +595 -0
  36. codemie_cdk_python-0.1.0rc0/src/codemie_iac/specs/integration.py +103 -0
  37. codemie_cdk_python-0.1.0rc0/src/codemie_iac/specs/skill.py +51 -0
  38. codemie_cdk_python-0.1.0rc0/src/codemie_iac/specs/workflow.py +154 -0
@@ -0,0 +1,840 @@
1
+ Metadata-Version: 2.4
2
+ Name: codemie-cdk-python
3
+ Version: 0.1.0rc0
4
+ Summary: CodeMie IaC document envelope (Python)
5
+ Author: EPAM Systems
6
+ Requires-Python: >=3.12,<4.0
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: Programming Language :: Python :: 3.12
9
+ Classifier: Programming Language :: Python :: 3.13
10
+ Classifier: Programming Language :: Python :: 3.14
11
+ Classifier: Programming Language :: Python :: 3.15
12
+ Requires-Dist: codemie-sdk-python (==0.1.707)
13
+ Requires-Dist: jsonschema (>=4.23.0,<5.0.0)
14
+ Requires-Dist: pydantic (>=2.12.2,<3.0.0)
15
+ Requires-Dist: pyyaml (>=6.0.2,<7.0.0)
16
+ Description-Content-Type: text/markdown
17
+
18
+ # codemie-cdk-python
19
+
20
+ A small Python package that turns CodeMie resources (assistants, datasources,
21
+ integrations, skills, categories, workflows) into plain YAML documents you can
22
+ commit to a repo, and reads those documents back.
23
+
24
+ Most of the library works offline, with no network and no running backend. The
25
+ one exception is `codemie_iac.plan_apply`, which talks to the platform, and only
26
+ through the `codemie_sdk` services (see "Plan and apply against the platform"
27
+ below). Nothing else in the package makes a network call.
28
+
29
+ ## Why this exists
30
+
31
+ Today the only way to describe a CodeMie resource outside the UI is to hand-write
32
+ YAML or call the API directly. This package gives you typed, validated building
33
+ blocks for that YAML instead, plus two safety rules baked in:
34
+
35
+ - **No secrets in the file, for the fields this package recognizes as
36
+ credential-shaped.** Those are stored as references (`env:SOME_NAME`),
37
+ never as real values — and a handful of them (`auth_token`,
38
+ `Integration.credential_values`) are *typed* that way, so a literal value
39
+ can't be constructed at all. A few others (`env`, `headers`, `args`, `url`,
40
+ `arguments`, `mcp_connect_url` on an MCP server) are best-effort,
41
+ whole-value matches only: a value already shaped like a reference is
42
+ recognized, but this package does not scan arbitrary strings for secrets,
43
+ so one embedded inside a larger value (e.g. `--token=sk-live-...` in an
44
+ `args` entry, or a signed query parameter on a `url`) is written to the
45
+ file as plain text. See "Credential narrowing for inline MCP servers"
46
+ below for the exact fields.
47
+ - **No silent typos.** An unknown or misspelled field fails loudly, naming the
48
+ field, instead of being quietly dropped.
49
+
50
+ ## What it can do right now
51
+
52
+ - Build a `Document` for one resource (assistant, datasource, integration,
53
+ skill, category, or workflow) — always a single file, workflows included.
54
+ - Group several documents into a `Bundle`.
55
+ - Write a `Bundle` to YAML and read it back, byte-for-byte stable.
56
+ - Validate a YAML document against a packaged JSON Schema, offline.
57
+ - Resolve a reference like "the integration named X" within a bundle.
58
+ - Create a whole bundle on the platform, in dependency order, and plan or
59
+ apply a single document against one existing entity
60
+ (`codemie_iac.plan_apply`).
61
+
62
+ ## What it can't do yet
63
+
64
+ - No command-line tool. This is a library you import, not something you run
65
+ from a terminal (a CLI is planned for a later release).
66
+ - `apply` never deletes anything, and bulk apply only creates. See "Plan and
67
+ apply against the platform" and "Not supported" below.
68
+
69
+ ## Install
70
+
71
+ The IaC needs `codemie-sdk-python` 0.3.0 or newer (svn, SharePoint, Xray and
72
+ provider datasource support).
73
+
74
+ This package lives next to the Node IaC tool, under `iac/codemie-iac-python`.
75
+ It depends on the local `codemie-sdk-python` package, so install both from
76
+ this repo with Poetry:
77
+
78
+ ```bash
79
+ cd iac/codemie-iac-python
80
+ poetry install
81
+ ```
82
+
83
+ ## Documents and bundles
84
+
85
+ Three types tie everything together:
86
+
87
+ - **`Spec`** — one class per resource kind (`CategorySpec`, `AssistantSpec`, ...).
88
+ This holds the resource's actual fields — the same data you'd send to the
89
+ platform to create it. Build one with `SomeSpec.from_entity(entity)` from
90
+ the matching `codemie_sdk` model, or with plain keyword arguments. See
91
+ "One example per asset kind" below for how to build each one.
92
+ - **`Document`** — wraps one `Spec` plus `meta`. This is the unit that gets
93
+ saved to disk.
94
+ - **`Bundle`** — an ordered list of `Document`s. It can mix kinds — an
95
+ assistant, a datasource, a skill, all in one list.
96
+
97
+ ### `DocumentMeta`: a label, not platform data
98
+
99
+ `meta` is a small `DocumentMeta` object with two fields: `kind` (which
100
+ `Spec` type this document holds) and `name`. `name` here is **not** a
101
+ resource field — it's just a label you pick so this document can be found
102
+ inside a `Bundle`. `ReferenceResolver.resolve(kind, name)` matches on it;
103
+ nothing else reads it, and nothing checks it against anything inside `spec`.
104
+
105
+ `kind` is a `DocumentKind` enum (`DocumentKind.CATEGORY`,
106
+ `DocumentKind.ASSISTANT`, ...) — one of the six fixed values, used in every
107
+ example below. You can pass the plain string instead (`kind="category"`);
108
+ pydantic converts it to the matching `DocumentKind` member for you, and an
109
+ unrecognized string is rejected the same way either form would be.
110
+
111
+ In most examples below, `meta.name` is set to the same string as the
112
+ resource's own name (`spec.name`), simply because that's the clearest thing
113
+ to do — not because the code requires it. The Integration example makes the
114
+ difference concrete: `IntegrationSpec` has no `name` field at all (it uses
115
+ `alias` instead), so `meta.name` is set from `integration.alias` there.
116
+ Pick whatever label makes the document easy to find; `spec` is what actually
117
+ describes the resource.
118
+
119
+ The rest of this section covers what you can do once you have a `Bundle`.
120
+
121
+ ### Save to YAML, and read it back
122
+
123
+ ```python
124
+ from codemie_iac import to_yaml, from_yaml
125
+
126
+ text = to_yaml(bundle)
127
+ bundle_again = from_yaml(text)
128
+ assert bundle_again == bundle
129
+ ```
130
+
131
+ Writing the same bundle twice always produces the exact same text, so diffs
132
+ in version control only show real changes.
133
+
134
+ ### Validate a document offline
135
+
136
+ ```python
137
+ from codemie_iac import validate_document, DocumentValidationError
138
+
139
+ try:
140
+ validate_document({"version": "v1", "meta": {"kind": "category", "name": "x"}})
141
+ except DocumentValidationError as exc:
142
+ print(exc.errors) # every problem found, not just the first one
143
+ ```
144
+
145
+ No network call is made — the schema ships inside the package.
146
+
147
+ ### Credentials are references, never values
148
+
149
+ A credential field never holds a secret. It holds a reference such as
150
+ `env:JIRA_PROD_TOKEN`, built by `CredentialRef.from_entity(identifier,
151
+ credential_key)`. That function never reads the real secret value — only the
152
+ identifier and the key — so the same two inputs always produce the same
153
+ reference. See the Integration example below for it in context.
154
+
155
+ ### Finding things by name inside a bundle
156
+
157
+ ```python
158
+ from codemie_iac import ReferenceResolver
159
+
160
+ resolver = ReferenceResolver(bundle)
161
+ support_category = resolver.resolve("category", "support")
162
+ ```
163
+
164
+ This only looks inside the bundle you pass in — it never reaches the
165
+ platform or other files.
166
+
167
+ ## One example per asset kind
168
+
169
+ Each example below does the same two steps: describe the asset with its
170
+ `codemie_sdk` model (the same model you'd use to call the platform), then
171
+ convert it to the matching IaC `Spec` with that `Spec`'s own
172
+ `from_entity(...)` classmethod, and render it to YAML.
173
+
174
+ `from_entity` does the field mapping once, inside the package, instead of
175
+ every caller re-deriving it. For the credential-bearing kinds (Integration,
176
+ and Assistant's MCP/toolkit integration references) it does the same
177
+ narrowing shown explicitly elsewhere in this README — it just does it
178
+ internally, never reading an actual secret value. If you'd rather build a
179
+ `Spec` by hand (no entity object, or a one-off that doesn't map cleanly to
180
+ an existing SDK model), every field is still a plain, settable keyword
181
+ argument — `from_entity` is a convenience, not the only way in.
182
+
183
+ ### Category
184
+
185
+ ```python
186
+ from codemie_sdk.models.categories import CategoryCreateRequest
187
+ from codemie_iac import Document, DocumentMeta, DocumentKind, Bundle, to_yaml
188
+ from codemie_iac.specs.category import CategorySpec
189
+
190
+ category = CategoryCreateRequest(name="support", description="Support team resources")
191
+
192
+ doc = Document(
193
+ version="v1",
194
+ meta=DocumentMeta(kind=DocumentKind.CATEGORY, name=category.name),
195
+ spec=CategorySpec.from_entity(category),
196
+ )
197
+ print(to_yaml(Bundle([doc])))
198
+ ```
199
+
200
+ ### Skill
201
+
202
+ ```python
203
+ from codemie_sdk.models.skill import SkillCreateRequest
204
+ from codemie_iac import Document, DocumentMeta, DocumentKind, Bundle, to_yaml
205
+ from codemie_iac.specs.skill import SkillSpec
206
+
207
+ skill = SkillCreateRequest(
208
+ name="changelog-writer",
209
+ description="Writes a changelog entry from a diff",
210
+ content="Summarize the given diff as one changelog line.",
211
+ project="my-project",
212
+ )
213
+
214
+ doc = Document(
215
+ version="v1",
216
+ meta=DocumentMeta(kind=DocumentKind.SKILL, name=skill.name),
217
+ spec=SkillSpec.from_entity(skill),
218
+ )
219
+ print(to_yaml(Bundle([doc])))
220
+ ```
221
+
222
+ ### Integration
223
+
224
+ `IntegrationSpec.from_entity` never reads the real credential value — it
225
+ only ever sees the integration's `alias` and each credential entry's `key`,
226
+ the same two inputs you'd pass to `CredentialRef.from_entity` by hand:
227
+
228
+ ```python
229
+ from codemie_sdk.models.integration import Integration, CredentialTypes, CredentialValues
230
+ from codemie_iac import Document, DocumentMeta, DocumentKind, Bundle, to_yaml
231
+ from codemie_iac.specs.integration import IntegrationSpec
232
+
233
+ integration = Integration(
234
+ project_name="my-project",
235
+ alias="jira-prod",
236
+ credential_type=CredentialTypes.JIRA,
237
+ credential_values=[
238
+ CredentialValues(key="url", value="https://jira.example.com"),
239
+ CredentialValues(key="username", value="<kept out of the document>"),
240
+ CredentialValues(key="token", value="<kept out of the document>"),
241
+ ],
242
+ )
243
+
244
+ doc = Document(
245
+ version="v1",
246
+ meta=DocumentMeta(kind=DocumentKind.INTEGRATION, name=integration.alias),
247
+ spec=IntegrationSpec.from_entity(integration),
248
+ )
249
+ print(to_yaml(Bundle([doc])))
250
+ ```
251
+
252
+ **A credential `key` must be the platform's own setting name.** The package
253
+ does not check keys: an unknown key is stored as written, and the platform then
254
+ shows the setting as empty and the tool fails at runtime. Some types use
255
+ prefixed names, for example:
256
+
257
+ | `credential_type` | Keys |
258
+ |---|---|
259
+ | `Jira` | `url`, `username`, `token`, `cloud` |
260
+ | `Git` | `url`, `token` |
261
+ | `Elastic` | `url`, `elastic_api_key_id`, `elastic_api_key` |
262
+ | `OpenAPI` | `openapi_spec`, `openapi_api_key`, `openapi_username`, `is_basic_auth`, `timeout`, `auth_header_name` |
263
+
264
+ The reference for a key is `env:<ALIAS>_<KEY>`, upper-cased with `-` turned
265
+ into `_` (`openapi-answers` + `openapi_spec` is `env:OPENAPI_ANSWERS_OPENAPI_SPEC`).
266
+
267
+ ### Datasource
268
+
269
+ A datasource is one of thirteen kinds (code, Jira, Confluence, svn, SharePoint,
270
+ Xray, provider, ...), each with
271
+ its own `*Spec` class. This example uses the code-repository kind:
272
+
273
+ ```python
274
+ from codemie_sdk.models.datasource import CodeDataSourceRequest
275
+ from codemie_iac import Document, DocumentMeta, DocumentKind, Bundle, to_yaml
276
+ from codemie_iac.specs.datasource import CodeDatasourceSpec
277
+
278
+ datasource = CodeDataSourceRequest(
279
+ name="my_code_kb",
280
+ project_name="my-project",
281
+ description="Code knowledge base",
282
+ link="https://github.com/org/repo",
283
+ branch="main",
284
+ )
285
+
286
+ doc = Document(
287
+ version="v1",
288
+ meta=DocumentMeta(kind=DocumentKind.DATASOURCE, name=datasource.name),
289
+ spec=CodeDatasourceSpec.from_entity(datasource),
290
+ )
291
+ print(to_yaml(Bundle([doc])))
292
+ ```
293
+
294
+ Each of the other kinds has the matching `*DatasourceSpec.from_entity(request)`.
295
+
296
+ The svn, SharePoint, Xray and provider kinds in document form (svn,
297
+ SharePoint and Xray may carry a `setting_id`, the alias of an integration in
298
+ the bundle or live in the target project; a provider datasource may not, as the
299
+ platform does not store one):
300
+
301
+ ```yaml
302
+ spec: {type: svn, name: svn_kb, project_name: my-project, description: d,
303
+ link: "https://svn.example.com/repo", branch: trunk, index_type: code}
304
+ spec: {type: knowledge_base_sharepoint, name: sp_kb, project_name: my-project,
305
+ description: d, site_url: "https://example.sharepoint.com/sites/x",
306
+ auth_type: integration, setting_id: my-sharepoint-integration}
307
+ spec: {type: knowledge_base_xray, name: xray_kb, project_name: my-project,
308
+ description: d, jql: "project = X"}
309
+ spec: {type: provider, name: prov_kb, project_name: my-project, description: d,
310
+ provider_name: my-provider, toolkit_id: my-toolkit,
311
+ settings: {region: eu, api_key: "env:PROVIDER_API_KEY"}}
312
+ ```
313
+
314
+ The `region` literal above passes the offline name check and is accepted at plan/apply only when `provider_secret_lookup=`
315
+ reports that `region` is not secret (see below); without a lookup it must be an
316
+ `env:` reference too.
317
+
318
+ - **SharePoint OAuth uses an `access_token` reference.** The `oauth_codemie`
319
+ and `oauth_custom` auth types need an access token, which the platform never
320
+ stores or returns. A document carries it as `access_token: env:NAME`. The
321
+ token is optional in a document (an exported one has none), but creating such a
322
+ datasource, or updating it with a reindex, fails without it; a literal token
323
+ is rejected without echoing it. The value is read from the environment on
324
+ create and update. It is listed as not comparable in a plan.
325
+ `auth_type`, `oauth_client_id` and `oauth_tenant_id` are compared.
326
+ - **Provider secret settings are `env:` references.** Two checks apply.
327
+ Offline, `ProviderDatasourceSpec` makes a best-effort, name-based check: a
328
+ literal string under a secret-looking setting name (a whole name part such as
329
+ `password`, `secret`, `token`, `apikey`, `credential`, `passphrase`, or
330
+ `api`/`private`/`access`/`secret`/`auth` + `key`, or `client` + `secret`,
331
+ after splitting on punctuation and camelCase) is rejected, naming the
332
+ document and the setting path such as `settings.auth.api_key`, never the
333
+ value. `key_prefix`, `tokenizer` and `region` are not flagged, and `env:`
334
+ references, empty strings and non-strings pass. At plan or apply, before any
335
+ write, the platform's provider schema decides authoritatively which settings
336
+ are secret; a literal value in such a setting is rejected, naming the field,
337
+ including under names the offline check does not recognise. The value is read from the
338
+ environment only when writing and never appears in plans, errors or logs.
339
+ Pass `provider_secret_lookup=` to `BulkCreator` / `SingleEntityPlanner` (a
340
+ callable `(provider_name, toolkit_id) -> secret setting names`, normally
341
+ built from the provider schema). The lookup belongs to that planner or
342
+ creator only. Without one, or if it fails or returns something other than a
343
+ collection of names (a bare string, non-string names), the check fails
344
+ closed: every non-empty string provider setting must be an `env:`
345
+ reference, and the error says the schema lookup was unavailable and why (no
346
+ lookup configured, or the exception type the lookup raised). Settings without
347
+ a string (numbers, booleans, lists of numbers) are not checked; a list or map
348
+ is checked per string it contains. A lookup that returns an empty collection
349
+ is an answer, not a failure: the schema marks no setting secret. No caller
350
+ in this package supplies a lookup, so unless you pass one, a literal such as
351
+ `region: eu` is refused and must be an `env:` reference.
352
+ `name`, `project_name`, `setting_id`, `description` and
353
+ `project_space_visible` are reserved and rejected inside `settings`.
354
+ Every `env:` reference in the settings is checked before the first write,
355
+ not only the ones the schema calls secret.
356
+ - **Provider settings are compared key by key.** A key holding an `env:`
357
+ reference, or masked on the platform, is reported as not comparable
358
+ (`settings.<key>`); changes to the other keys still show in the plan.
359
+ `toolkit_id` cannot change: a different one is refused, recreate the
360
+ datasource.
361
+ On update, settings the document leaves out keep their stored values: the
362
+ non-secret ones are sent back (the platform would otherwise reset them to the
363
+ schema default), and the secret ones are left out, which keeps them (a read
364
+ returns a secret encrypted, and sending that back would encrypt it again).
365
+ Which ones are secret comes from `provider_secret_lookup`; without it, an
366
+ update that leaves out any stored setting is refused, naming the settings, so
367
+ list them in the document or pass a lookup. A provider
368
+ document takes no `cron_expression` or `timezone`, and a setting value that
369
+ starts with `env:` but is not a valid reference (`env:my-region`, `ENV:FOO`)
370
+ is rejected.
371
+ - **Create-only and optional fields.** An Xray `embedding_model` is used on
372
+ create only (the update route does not store it) and is not compared. An svn
373
+ `branch` left out is `trunk` on create and the stored branch on update.
374
+ - **Reindexing follows the plan.** As for code and Git FAQ datasources, an svn
375
+ update that changes only metadata (description, visibility, schedule) is sent
376
+ with `skip_reindex`. A SharePoint or Xray update that changes a source field
377
+ (`site_url`, `include_*`, `files_filter`, `jql`, auth fields, embedding model,
378
+ `setting_id`) is sent with `full_reindex`; for an OAuth SharePoint datasource
379
+ that needs the `access_token`. A forced write that changes no source field
380
+ reindexes nothing.
381
+ - **Provider settings are validated at plan time, not offline.** The settings
382
+ are free-form and schema-driven, so offline validation covers only the
383
+ envelope and that secret settings are `env:` references. Unknown or missing
384
+ provider settings are reported at plan time from the platform's provider
385
+ schema. svn, SharePoint and Xray are fully validated offline.
386
+ - **Skill categories are values.** A skill's `categories` are entries of the
387
+ platform's fixed list (at most 3), sent as written; unlike an assistant's
388
+ categories they are not Category documents and create no dependency.
389
+ - **Fields of the export round trip.** Documents also carry toolkit and tool
390
+ `auto_credentials_lookup`, an assistant's `hedging_config`,
391
+ `interactive_enabled`, `enable_image_generation` and `file_attachment_enabled`
392
+ (left out of a document, they keep the stored value),
393
+ an inline MCP config's `audience` and `auth_config` (an entry named
394
+ `client_secret`, `refresh_token`, `access_token`, `password`, `private_key`
395
+ and the like must be an `env:` reference; fields such as `token_url` or
396
+ `token_delivery` are plain values), a workflow's `start_hint` and its engine
397
+ switches (compared through `yaml_config`).
398
+ - A datasource create answers with a message only, so apply looks the new
399
+ datasource up by project and name and returns its id. If the platform does
400
+ not list it yet, the page cap (20 pages of 100) is exhausted, or the lookup
401
+ fails, the datasource is reported as created without an id and a warning is
402
+ logged (datasource, project and exception type only); the apply does not fail.
403
+ A provider datasource is updated by its platform id.
404
+
405
+ ### Assistant
406
+
407
+ ```python
408
+ from codemie_sdk.models.assistant import AssistantCreateRequest
409
+ from codemie_iac import Document, DocumentMeta, DocumentKind, Bundle, to_yaml
410
+ from codemie_iac.specs.assistant import AssistantSpec
411
+
412
+ assistant = AssistantCreateRequest(
413
+ name="release-notes-writer",
414
+ description="Writes release notes from merged PRs",
415
+ system_prompt="You write concise, user-facing release notes.",
416
+ project="my-project",
417
+ llm_model_type="gpt-4o",
418
+ )
419
+
420
+ doc = Document(
421
+ version="v1",
422
+ meta=DocumentMeta(kind=DocumentKind.ASSISTANT, name=assistant.name),
423
+ spec=AssistantSpec.from_entity(assistant),
424
+ )
425
+ print(to_yaml(Bundle([doc])))
426
+ ```
427
+
428
+ `AssistantSpec` has more fields than this (toolkits, MCP servers, prompt
429
+ variables, ...). `from_entity` narrows all of them: a toolkit's or MCP
430
+ server's referenced `Integration` becomes just its name, and an MCP
431
+ server's `auth_token` becomes a `CredentialRef` keyed by that server's own
432
+ name — the same narrowing shown in the Integration example, just applied
433
+ automatically.
434
+
435
+ `AssistantSpec.skill_ids` lists the skills attached to the assistant. Each
436
+ entry is a reference resolved when the document is applied (see below), and
437
+ an omitted field leaves the skills attached on the platform untouched (they
438
+ are neither compared nor sent), while `skill_ids: []` detaches them all. The installed
439
+ `codemie-sdk-python` must carry `skill_ids` on the assistant create, update
440
+ and read models; if it does not, applying an assistant that sets `skill_ids`
441
+ (even `skill_ids: []`) fails (`unsupported_sdk`) before anything is written,
442
+ instead of silently dropping the skills. No `codemie-sdk-python` release up
443
+ to 0.1.711 carries it, so assistant `skill_ids` works once a release that
444
+ includes the change is installed and the pin in `pyproject.toml` is raised to
445
+ it.
446
+
447
+ **Resolving skill and datasource references.** An assistant's `skill_ids` and
448
+ a workflow agent's `skill_ids` and `datasource_ids` are written as names. Each
449
+ value is resolved in this order: (1) a document with that name in the bundle
450
+ wins, even if the value looks like an id; (2) otherwise the name is looked up
451
+ in the target project; (3) otherwise a value shaped like a platform id (UUID)
452
+ is sent unchanged, so documents holding raw ids keep working; (4) otherwise,
453
+ or when a name matches more than one entity, the apply fails with an error
454
+ naming the reference and the document holding it, before anything is written.
455
+ In-bundle skills and datasources are created before the assistant or workflow
456
+ that uses them. A value that falls under (3) is not checked against the
457
+ platform, so a mistyped, deleted or other-project id is only rejected when the
458
+ platform uses it; the apply logs a warning for each one. One failure can
459
+ happen after writes: a datasource or integration created earlier in the same
460
+ apply must show up in the platform's listing within about 30 seconds before a
461
+ document that references it by name can be created. If it does not, that
462
+ document fails with `unresolved_reference` and the entities already created
463
+ stay (apply the remaining documents again, not the whole bundle).
464
+
465
+ ### Workflow
466
+
467
+ A workflow is built with the SDK's own `WorkflowBuilder`, not hand-filled
468
+ field by field like the other five kinds. `WorkflowSpec` wraps the resulting
469
+ `WorkflowDefinition` directly — one file, same as every other kind:
470
+
471
+ ```python
472
+ from codemie_sdk.builders.workflow.builder import WorkflowBuilder
473
+ from codemie_sdk.builders.workflow.definition import WorkflowNextState
474
+ from codemie_sdk.models.workflow import WorkflowMode
475
+ from codemie_iac import Document, DocumentMeta, DocumentKind, Bundle, to_yaml
476
+ from codemie_iac.specs.workflow import WorkflowSpec
477
+
478
+ workflow = (
479
+ WorkflowBuilder("release-notes")
480
+ .with_description("Generate release notes from merged PRs")
481
+ .with_mode(WorkflowMode.SEQUENTIAL)
482
+ .add_assistant("writer", system_prompt="Summarize the given PRs as release notes.")
483
+ .add_state("draft", "writer", "Draft the release notes", next=WorkflowNextState())
484
+ .render()
485
+ )
486
+
487
+ doc = Document(
488
+ version="v1",
489
+ meta=DocumentMeta(kind=DocumentKind.WORKFLOW, name=workflow.name),
490
+ spec=WorkflowSpec.from_entity(workflow),
491
+ )
492
+ print(to_yaml(Bundle([doc])))
493
+ ```
494
+
495
+ `name`, `description`, `shared`, and `icon_url` all come from `workflow`
496
+ itself — nothing is copied onto a sibling field, so nothing can drift out of
497
+ sync with it. The platform's own flattened `yaml_config` text
498
+ (`workflow.to_yaml_config()`) is not generated here at all; that happens
499
+ later, when `plan_apply` publishes the workflow.
500
+
501
+ **Credential narrowing for inline MCP servers.** An inline assistant's MCP
502
+ server config (`WorkflowMCPServer.config`) is typed `MCPServerConfig` — the
503
+ same model `MCPServerDetails.config` already uses on `AssistantCreateRequest`
504
+ — so `WorkflowSpec.from_entity` narrows it by reusing
505
+ `MCPServerConfigSpec.from_entity` wholesale: `auth_token` becomes a
506
+ `CredentialRef` (also listed in `credential_values`, same `{key, ref}` shape
507
+ as `IntegrationSpec.credential_values`), and any `env`/`headers`/`args`/
508
+ `url` value already shaped like a reference (`"env:SOME_REF"`) is recognized
509
+ too — the same narrowing `AssistantSpec` gets for its own MCP servers,
510
+ nothing weaker. `auth_token` is also re-checked on every `WorkflowSpec`,
511
+ including one built directly from model instances or loaded from a file, not
512
+ just one produced by `from_entity` — a literal value there is always
513
+ rejected. The `env`/`headers`/`args`/`url` fields are not: as noted above,
514
+ narrowing them is a best-effort, whole-value match, never an enforced
515
+ guarantee.
516
+
517
+ ## Plan and apply against the platform
518
+
519
+ `codemie_iac.plan_apply` is the only part of this package that talks to the
520
+ platform. It does so by calling `codemie_sdk` services (you pass in the SDK
521
+ client); the rest of the library stays offline. Ground rules:
522
+
523
+ - **Platform ids are passed in and returned, never stored.** A document never
524
+ contains a platform id and nothing is written to a file. Ids are held in
525
+ memory for one run, substituted into request bodies, and handed back in the
526
+ result.
527
+ - **Apply never deletes anything.** Not in bulk, not for a single entity.
528
+ - **Bulk apply is create-only and dependency-ordered.** An entity whose name
529
+ or content equals an existing one is still created; there is no dedupe, no
530
+ update, and no scoped apply. All checks (dependency cycles, unsupported
531
+ kinds, unresolved references, unresolvable credentials) run before the first
532
+ write, so a bad bundle fails without creating anything.
533
+ - **Single-entity plan/apply works by id.** You give the id of the live
534
+ entity; `plan` diffs the document against it with no writes, and `apply`
535
+ updates it (or creates it when no id is given).
536
+ - Credential references (`env:NAME`) are resolved from the environment at
537
+ apply time (`plan` does not need them: an unset variable is reported as an
538
+ unresolvable `CannotCompare`). Masked live values are reported as
539
+ `CannotCompare`, never as a difference, and no secret value appears in any
540
+ result.
541
+ - **An empty plan sends no write.** Fields that cannot be compared (a rotated
542
+ secret, a masked value) do not make a plan non-empty; `apply` lists them in
543
+ `ApplyResult.uncomparable`. Pass `force=True` to write the full document
544
+ anyway, e.g. to rotate a secret.
545
+ - **A field the document leaves unset is not compared.** The platform may fill
546
+ it (an assistant's slug, a datasource's default timezone) and a write never
547
+ sends it. To clear a value, author it empty (`""`, `[]`). The one exception is
548
+ `icon_url` on an assistant or workflow: omitting it clears an icon set on the
549
+ platform, and `plan` reports the difference first.
550
+ - **A document's `meta.name` must equal the entity's own name** (the spec
551
+ `name`, the workflow's `name`, or the integration's `alias`). References and
552
+ the live lookup go by `meta.name`, while the platform uses the spec name, so
553
+ a difference is refused with `name_mismatch` before anything is written.
554
+ - **Updates reindex only when the source changed.** A code datasource whose
555
+ plan differs only in metadata (description, visibility, schedule) is updated
556
+ with `skip_reindex`. For Git FAQ, Jira, Confluence, Azure DevOps and xWiki
557
+ datasources a changed source (for example `jql`, `cql`, `link`, `branch`)
558
+ is sent with `full_reindex`, because those routes store a new source and
559
+ keep the old index otherwise. A Git FAQ update without a source change
560
+ leaves its source fields out, as the backend rejects them without a full
561
+ reindex. `force=True` re-sends the document but follows the same rule: a
562
+ forced write that only pushes a rotated secret reindexes nothing.
563
+ - **Fields an update cannot change are not compared.** The create-only
564
+ settings (Confluence `include_*` and `keep_*` flags, a code datasource's
565
+ `index_type` and `summarization_model`, a Git FAQ `embedding_model`) and the
566
+ Azure DevOps `organization`/`project` (not stored by the platform) are
567
+ written on create and never reported as a difference. Changing the
568
+ document of a Google datasource is refused (`unsupported_datasource_change`),
569
+ as its route cannot take a new one.
570
+ - **An assistant the platform declines is a failure.** When a tool has no
571
+ integration the platform can use, it answers HTTP 200 with a validation
572
+ result and saves nothing; that is reported as `integration_missing`, in
573
+ bulk create (nothing is recorded as created) and in single apply.
574
+ - **Skill categories are values.** They are the platform's fixed list, sent as
575
+ written and checked before the first write; assistant categories still
576
+ reference Category documents by name.
577
+ - **Rejected calls are scrubbed.** A platform rejection (the SDK raises
578
+ `requests.HTTPError`) becomes a `PlatformRejectionError` holding only the
579
+ status, a scrubbed message and the parsed field errors; the original
580
+ exception, whose request holds the resolved credentials, is not kept.
581
+ Secrets are also replaced in their JSON-escaped, URL-encoded, YAML-quoted
582
+ and base64 forms. The SDK logs request bodies at `DEBUG` level, credentials
583
+ included; the engine raises the `codemie_sdk.utils.http` logger to `INFO`
584
+ while it sends a write.
585
+
586
+ ```python
587
+ from codemie_sdk import CodeMieClient
588
+ from codemie_iac import from_yaml
589
+ from codemie_iac.plan_apply import BulkCreator, SingleEntityPlanner
590
+
591
+ client = CodeMieClient(...) # your usual SDK client
592
+ bundle = from_yaml(open("bundle.yaml").read())
593
+
594
+ # Create everything in the bundle, dependencies first.
595
+ report = BulkCreator(client).create_all(bundle, target="my-project")
596
+ for item in report.created:
597
+ print(item.kind, item.name, item.id) # None for datasources and integrations
598
+ if report.failed: # stops at the first failure
599
+ print(report.failed.error_type, report.failed.reason)
600
+
601
+ # One entity, by id.
602
+ planner = SingleEntityPlanner(client)
603
+ document = next(iter(bundle))
604
+ plan = planner.plan(document, entity_id="<platform id>", target="my-project")
605
+ for d in plan.differences:
606
+ print(d.field, d.document_value, d.live_value)
607
+ if not plan.is_empty:
608
+ result = planner.apply(document, entity_id="<platform id>", target="my-project")
609
+ print(result.id, result.created)
610
+ ```
611
+
612
+ Bulk create is not idempotent: it never looks for an existing entity, so
613
+ running it again after a partial failure creates the first entities a second
614
+ time (the report lists what was created, so rerun only the rest). A timeout or
615
+ connection error on a create is reported as `apply_failed`, but the entity may
616
+ exist; check before retrying. Datasource and integration ids are not returned
617
+ (the backend answers a create with a message only); referenced ones are found
618
+ by name afterwards.
619
+
620
+ `target` is the project the entities live in. Failures raise or report an
621
+ `ApplyError` (`PlatformRejectionError`, `UnresolvedReferenceError`,
622
+ `UnresolvableCredentialError`) that names the entity kind and name.
623
+
624
+ ## Not supported
625
+
626
+ Some things are refused up front, with a clear error, before anything is
627
+ written.
628
+
629
+ **Workflow state references are not resolved by name.** A workflow's
630
+ `states[].workflow_id` is not resolved by name or ordered (its agents'
631
+ `skill_ids` and `datasource_ids` are, see above), and a workflow needs a
632
+ non-empty description. `from_entity` copies the ids and names an entity
633
+ carries; it does not turn platform ids into the names this tool resolves, so
634
+ build documents with names.
635
+
636
+ **A datasource cannot be renamed or moved to another project.** If the
637
+ document's datasource name or project differs from the live datasource you
638
+ point `plan`/`apply` at, you get:
639
+
640
+ ```
641
+ datasource/<name>: renaming or moving a datasource is not supported: document is '<name>' in project '<project>', live is '<live name>' in project '<live project>'
642
+ ```
643
+
644
+ (error type `datasource_identity_mismatch`). Instead, create a new datasource
645
+ with the new name or project, then update the assistants that use the old one
646
+ so they point at the new one.
647
+
648
+ **File datasources cannot be created or updated.** A document carries no file
649
+ content, so there is nothing to upload. You get:
650
+
651
+ ```
652
+ datasource/<name>: datasource type 'knowledge_base_file': file datasources are not supported
653
+ ```
654
+
655
+ (error type `unsupported_datasource_type`). In a bulk run this is caught
656
+ before the first write, so nothing is created.
657
+
658
+ A datasource's `setting_id` is read as the alias of an integration (in the
659
+ bundle or live in the target project) and replaced by its platform id on
660
+ write.
661
+
662
+ **An entity in another project is never overwritten.** Planning or applying an
663
+ update to an entity whose live project differs from the target fails with
664
+ `project_mismatch` (for a datasource it is `datasource_identity_mismatch`, see
665
+ above), and so does a document (assistant, skill, integration, datasource)
666
+ whose own project is not the target, in single apply and in bulk preflight.
667
+
668
+ **The project of a document is optional.** `AssistantSpec.project`,
669
+ `SkillSpec.project`, `IntegrationSpec.project_name` and every datasource's
670
+ `project_name` default to `None`. The engine (`BulkCreator`,
671
+ `SingleEntityPlanner`) fills an omitted one with the target project before
672
+ planning or applying, for the CLI and library callers alike. A project that is
673
+ named and differs from the target is refused (`project_mismatch`).
674
+
675
+ **Required fields mirror the platform.** A code datasource document needs
676
+ `link`, `branch` and `index_type` (the platform's create request requires all
677
+ three), on update as well as create, because the document is the full desired
678
+ state. A skill's `name` must be kebab-case (`^[a-z0-9][a-z0-9-]{1,62}[a-z0-9]$`),
679
+ its `description` 10 to 1000 characters, its `content` at least 100 characters,
680
+ and it takes at most 3 `categories`. A document that breaks these is rejected
681
+ before anything is sent.
682
+
683
+ ## Where things live
684
+
685
+ ```
686
+ src/codemie_iac/
687
+ envelope.py # Document, DocumentMeta, DocumentKind, Bundle
688
+ credentials.py # CredentialRef
689
+ resolver.py # ReferenceResolver
690
+ serializer.py # to_yaml / from_yaml
691
+ schema.py # document_json_schema, validate_document
692
+ specs/ # one Spec class per resource kind
693
+ plan_apply/ # bulk create and single-entity plan/apply (uses codemie_sdk)
694
+ ```
695
+
696
+ ## CLI
697
+
698
+ ```
699
+ codemie-iac [--project NAME] [-c/--config codemie.yaml] [--env-file PATH] plan <file> --id <id> [--json]
700
+ codemie-iac [--project NAME] [-c/--config codemie.yaml] [--env-file PATH] apply <path> [--id <id>] [--json]
701
+ ```
702
+
703
+ Global flags `--project`, `-c/--config` and `--env-file` go BEFORE the
704
+ subcommand; `--json` goes after it.
705
+
706
+ The `project` of a document (`project_name` for integrations and datasources)
707
+ is optional and defaults to the target project. A different explicit value is
708
+ refused with `project_mismatch`.
709
+
710
+ `.env`: if `./.env` exists in the current directory it is read (a missing one is
711
+ ignored); `--env-file PATH` reads that file instead (missing or unreadable is a
712
+ config error, exit 4). Lines are `KEY=VALUE`; blank lines, `#` comments and an
713
+ optional `export ` prefix are handled, matching single/double quotes around the
714
+ value are stripped, an inline ` # comment` after a value is dropped, `${}` is not expanded, and lines with an invalid key are
715
+ skipped. Variables already set in the real environment always win; `.env` only
716
+ fills in unset ones (nothing is written to `os.environ`). `${NAME}` references
717
+ in `codemie.yaml` see the merged values, and so do `env:NAME` credential references
718
+ in `plan` and `apply` (so a secret like `JIRA_PROD_API_TOKEN` can live in `.env`;
719
+ `plan` only checks that the name is set, it never reads the value).
720
+
721
+ Exit codes: 0 success / nothing to do, 1 changes pending, 2 apply failed,
722
+ 3 unresolved input, 4 config error, 5 invalid document.
723
+
724
+ Environment variables: `CODEMIE_API_URL`, `CODEMIE_AUTH_URL`, `CODEMIE_REALM`,
725
+ `CODEMIE_CLIENT_ID`, `CODEMIE_CLIENT_SECRET`, `CODEMIE_USERNAME`,
726
+ `CODEMIE_PASSWORD`, `CODEMIE_JWT_TOKEN`, `CODEMIE_PROJECT`,
727
+ `CODEMIE_VERIFY_SSL` (default `true`; `false` disables TLS verification).
728
+
729
+ `codemie.yaml` keys: `project.name`; an `environment:` mapping with
730
+ `codemie_api_url`, `auth_server_url`, `auth_realm_name`, `client_id`,
731
+ `client_secret`, `username`, `password`, `jwt_token`; and the legacy `api:`
732
+ mapping (`url`, `auth_url`, `realm`) as a fallback. Precedence per key: flag >
733
+ environment variable (real environment, then `.env`) > `environment:` > `api:`.
734
+
735
+ String values may reference environment variables: `${NAME}` or
736
+ `${NAME:-default}`. An unset or empty `${NAME}` without a default is a config
737
+ error (exit 4) naming the variable; write `${NAME:-}` where an empty value is
738
+ fine. A `$` not followed by `{` is left as is.
739
+
740
+ ```yaml
741
+ environment:
742
+ codemie_api_url: ${CODEMIE_API_URL:-}
743
+ jwt_token: ${CODEMIE_JWT_TOKEN:-}
744
+ ```
745
+
746
+ With a JWT (`CODEMIE_JWT_TOKEN` / `jwt_token`) the token is sent as a static
747
+ bearer token and only the API URL is required. Without one, the API URL, auth
748
+ URL and realm are required, plus client credentials or username/password.
749
+
750
+ ### Examples
751
+
752
+ Example documents live in [`examples`](examples). Each file in
753
+ the groups below is one document, except that `batch/` is a folder meant to
754
+ be applied together.
755
+
756
+ **Single mode: one file, one document.**
757
+
758
+ ```
759
+ codemie-iac --project my-project plan examples/simple/assistant.yaml --id <id>
760
+ codemie-iac --project my-project apply examples/simple/assistant.yaml
761
+ ```
762
+
763
+ **Batch mode: a directory.** `apply <dir>` creates every `*.yaml` / `*.yml`
764
+ file directly in that directory (not recursive), in dependency order, so
765
+ documents may reference each other by name (the `batch/` example:
766
+ integration, datasource, category, assistant).
767
+
768
+ ```
769
+ codemie-iac --project my-project apply examples/batch
770
+ ```
771
+
772
+ **Create:** `apply <file>` without `--id`, or `apply <dir>`.
773
+
774
+ ```
775
+ codemie-iac --project my-project apply examples/simple/skill.yaml
776
+ ```
777
+
778
+ **Update:** `apply <file> --id <id>` updates the existing asset with that
779
+ platform id. `plan <file> --id <id>` shows the changes without applying them
780
+ (exit code 1 when changes are pending); add `--json` for machine-readable
781
+ output.
782
+
783
+ ```
784
+ codemie-iac --project my-project apply examples/simple/skill.yaml --id <id>
785
+ codemie-iac --project my-project plan examples/simple/skill.yaml --id <id>
786
+ codemie-iac --project my-project plan examples/simple/skill.yaml --id <id> --json
787
+ ```
788
+
789
+ Global flags (`--project`, `-c`) go before the subcommand, `--json` after it.
790
+ Credentials in the examples are `env:NAME` references; export those variables
791
+ before applying. IDs inside workflows (`workflow_id`, `datasource_ids`,
792
+ `skill_ids`) are placeholders, or names of skills and datasources that are
793
+ resolved at apply time.
794
+
795
+ **Example files**
796
+
797
+ Simple (one per asset type):
798
+
799
+ - [`simple/assistant.yaml`](examples/simple/assistant.yaml)
800
+ - [`simple/category.yaml`](examples/simple/category.yaml)
801
+ - [`simple/datasource.yaml`](examples/simple/datasource.yaml)
802
+ - [`simple/integration.yaml`](examples/simple/integration.yaml)
803
+ - [`simple/integration_openapi.yaml`](examples/simple/integration_openapi.yaml) (prefixed credential keys)
804
+ - [`simple/skill.yaml`](examples/simple/skill.yaml)
805
+ - [`simple/workflow.yaml`](examples/simple/workflow.yaml)
806
+
807
+ Assistant with one integration:
808
+
809
+ - [`assistant-integrations/assistant_with_datasource.yaml`](examples/assistant-integrations/assistant_with_datasource.yaml)
810
+ - [`assistant-integrations/assistant_with_mcp_server.yaml`](examples/assistant-integrations/assistant_with_mcp_server.yaml)
811
+ - [`assistant-integrations/assistant_with_tool.yaml`](examples/assistant-integrations/assistant_with_tool.yaml)
812
+
813
+ Workflow node types:
814
+
815
+ - [`workflow-nodes/assistant_state.yaml`](examples/workflow-nodes/assistant_state.yaml)
816
+ - [`workflow-nodes/sub_workflow_state.yaml`](examples/workflow-nodes/sub_workflow_state.yaml)
817
+ - [`workflow-nodes/tool_state.yaml`](examples/workflow-nodes/tool_state.yaml)
818
+ - [`workflow-nodes/transform_node.yaml`](examples/workflow-nodes/transform_node.yaml)
819
+
820
+ Workflow routing styles:
821
+
822
+ - [`workflow-routing/condition.yaml`](examples/workflow-routing/condition.yaml)
823
+ - [`workflow-routing/iterator.yaml`](examples/workflow-routing/iterator.yaml)
824
+ - [`workflow-routing/next_state.yaml`](examples/workflow-routing/next_state.yaml)
825
+ - [`workflow-routing/parallel_next_states.yaml`](examples/workflow-routing/parallel_next_states.yaml)
826
+ - [`workflow-routing/switch.yaml`](examples/workflow-routing/switch.yaml)
827
+
828
+ Workflow inline assistants:
829
+
830
+ - [`workflow-assistants/with_datasource_ids.yaml`](examples/workflow-assistants/with_datasource_ids.yaml)
831
+ - [`workflow-assistants/with_skill_ids.yaml`](examples/workflow-assistants/with_skill_ids.yaml)
832
+ - [`workflow-assistants/with_tools.yaml`](examples/workflow-assistants/with_tools.yaml)
833
+
834
+ Batch folder (related documents):
835
+
836
+ - [`batch/01-integration.yaml`](examples/batch/01-integration.yaml)
837
+ - [`batch/02-datasource.yaml`](examples/batch/02-datasource.yaml)
838
+ - [`batch/03-category.yaml`](examples/batch/03-category.yaml)
839
+ - [`batch/04-assistant.yaml`](examples/batch/04-assistant.yaml)
840
+