kodelet-sdk 0.3.0__tar.gz → 0.4.0__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 (46) hide show
  1. {kodelet_sdk-0.3.0 → kodelet_sdk-0.4.0}/PKG-INFO +24 -1
  2. {kodelet_sdk-0.3.0 → kodelet_sdk-0.4.0}/README.md +23 -0
  3. kodelet_sdk-0.4.0/VERSION.txt +1 -0
  4. {kodelet_sdk-0.3.0 → kodelet_sdk-0.4.0}/src/kodelet_sdk/api.py +55 -0
  5. {kodelet_sdk-0.3.0 → kodelet_sdk-0.4.0}/src/kodelet_sdk/context.py +1 -0
  6. {kodelet_sdk-0.3.0 → kodelet_sdk-0.4.0}/src/kodelet_sdk/execution.py +49 -3
  7. {kodelet_sdk-0.3.0 → kodelet_sdk-0.4.0}/tests/test_agent.py +59 -0
  8. {kodelet_sdk-0.3.0 → kodelet_sdk-0.4.0}/tests/test_api.py +320 -0
  9. kodelet_sdk-0.3.0/VERSION.txt +0 -1
  10. {kodelet_sdk-0.3.0 → kodelet_sdk-0.4.0}/.github/workflows/ci.yml +0 -0
  11. {kodelet_sdk-0.3.0 → kodelet_sdk-0.4.0}/.github/workflows/release.yml +0 -0
  12. {kodelet_sdk-0.3.0 → kodelet_sdk-0.4.0}/.gitignore +0 -0
  13. {kodelet_sdk-0.3.0 → kodelet_sdk-0.4.0}/AGENTS.md +0 -0
  14. {kodelet_sdk-0.3.0 → kodelet_sdk-0.4.0}/LICENSE +0 -0
  15. {kodelet_sdk-0.3.0 → kodelet_sdk-0.4.0}/Makefile +0 -0
  16. {kodelet_sdk-0.3.0 → kodelet_sdk-0.4.0}/examples/review/kodelet-extension-review +0 -0
  17. {kodelet_sdk-0.3.0 → kodelet_sdk-0.4.0}/examples/review/reviewer-prompt.md +0 -0
  18. {kodelet_sdk-0.3.0 → kodelet_sdk-0.4.0}/examples/sdk/README.md +0 -0
  19. {kodelet_sdk-0.3.0 → kodelet_sdk-0.4.0}/examples/sdk/basic-agent-session +0 -0
  20. {kodelet_sdk-0.3.0 → kodelet_sdk-0.4.0}/examples/sdk/inline-extension-session +0 -0
  21. {kodelet_sdk-0.3.0 → kodelet_sdk-0.4.0}/examples/sdk/streaming-agent-session +0 -0
  22. {kodelet_sdk-0.3.0 → kodelet_sdk-0.4.0}/examples/workspace/kodelet-extension-workspace +0 -0
  23. {kodelet_sdk-0.3.0 → kodelet_sdk-0.4.0}/pyproject.toml +0 -0
  24. {kodelet_sdk-0.3.0 → kodelet_sdk-0.4.0}/src/kodelet_sdk/__init__.py +0 -0
  25. {kodelet_sdk-0.3.0 → kodelet_sdk-0.4.0}/src/kodelet_sdk/_utils.py +0 -0
  26. {kodelet_sdk-0.3.0 → kodelet_sdk-0.4.0}/src/kodelet_sdk/agent/__init__.py +0 -0
  27. {kodelet_sdk-0.3.0 → kodelet_sdk-0.4.0}/src/kodelet_sdk/agent/client.py +0 -0
  28. {kodelet_sdk-0.3.0 → kodelet_sdk-0.4.0}/src/kodelet_sdk/agent/relay.py +0 -0
  29. {kodelet_sdk-0.3.0 → kodelet_sdk-0.4.0}/src/kodelet_sdk/agent/rpc.py +0 -0
  30. {kodelet_sdk-0.3.0 → kodelet_sdk-0.4.0}/src/kodelet_sdk/agent/session.py +0 -0
  31. {kodelet_sdk-0.3.0 → kodelet_sdk-0.4.0}/src/kodelet_sdk/agent/transport.py +0 -0
  32. {kodelet_sdk-0.3.0 → kodelet_sdk-0.4.0}/src/kodelet_sdk/agent/types.py +0 -0
  33. {kodelet_sdk-0.3.0 → kodelet_sdk-0.4.0}/src/kodelet_sdk/py.typed +0 -0
  34. {kodelet_sdk-0.3.0 → kodelet_sdk-0.4.0}/src/kodelet_sdk/runtime.py +0 -0
  35. {kodelet_sdk-0.3.0 → kodelet_sdk-0.4.0}/src/kodelet_sdk/schemas.py +0 -0
  36. {kodelet_sdk-0.3.0 → kodelet_sdk-0.4.0}/src/kodelet_sdk/task_progress.py +0 -0
  37. {kodelet_sdk-0.3.0 → kodelet_sdk-0.4.0}/src/kodelet_sdk/template.py +0 -0
  38. {kodelet_sdk-0.3.0 → kodelet_sdk-0.4.0}/src/kodelet_sdk/test_harness.py +0 -0
  39. {kodelet_sdk-0.3.0 → kodelet_sdk-0.4.0}/tests/fixtures/workspace_policy_extension.py +0 -0
  40. {kodelet_sdk-0.3.0 → kodelet_sdk-0.4.0}/tests/test_acp_transport.py +0 -0
  41. {kodelet_sdk-0.3.0 → kodelet_sdk-0.4.0}/tests/test_examples.py +0 -0
  42. {kodelet_sdk-0.3.0 → kodelet_sdk-0.4.0}/tests/test_execution.py +0 -0
  43. {kodelet_sdk-0.3.0 → kodelet_sdk-0.4.0}/tests/test_persistent_ui.py +0 -0
  44. {kodelet_sdk-0.3.0 → kodelet_sdk-0.4.0}/tests/test_runtime.py +0 -0
  45. {kodelet_sdk-0.3.0 → kodelet_sdk-0.4.0}/tests/test_task_progress.py +0 -0
  46. {kodelet_sdk-0.3.0 → kodelet_sdk-0.4.0}/uv.lock +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: kodelet-sdk
3
- Version: 0.3.0
3
+ Version: 0.4.0
4
4
  Summary: Python SDK for authoring Kodelet extensions
5
5
  Project-URL: Repository, https://github.com/jingkaihe/kodelet
6
6
  Author: Kodelet
@@ -110,6 +110,29 @@ Session options include:
110
110
 
111
111
  Pass an `ExecutionOptions` instance directly as `create_session(options=...)` for model settings, execution limits, and tool selection. The optional `profile="work"` selects a model profile already configured on the daemon; omit it to use the daemon's default. Inline settings cannot include provider secrets, endpoints, or local prompt paths.
112
112
 
113
+ ### Extension model profiles
114
+
115
+ ```python
116
+ ext = Extension()
117
+ SEARCH_PROFILE = ext.register_profile(
118
+ "code-search",
119
+ provider="openai",
120
+ model="gpt-5.6-luna",
121
+ reasoning_effort="none",
122
+ hidden=True,
123
+ )
124
+ CLAUDE_PROFILE = ext.register_profile(
125
+ "claude",
126
+ provider="anthropic",
127
+ model="claude-sonnet-4-6",
128
+ anthropic={"platform": "anthropic"},
129
+ anthropic_api_access="subscription",
130
+ )
131
+ session = await client.create_session(profile=SEARCH_PROFILE)
132
+ ```
133
+
134
+ `register_profile(name, *, provider, model, hidden=False, **options)` returns the flat name unchanged. Names are ASCII slugs (1–128 characters; `default` is reserved). `hidden=True` hides the profile from pickers.
135
+
113
136
  ### Inline extensions
114
137
 
115
138
  Pass `extensions=[ext]` to expose local Python callbacks as agent tools. This calculator runs in your Python process; the agent runs on the selected daemon and runner.
@@ -97,6 +97,29 @@ Session options include:
97
97
 
98
98
  Pass an `ExecutionOptions` instance directly as `create_session(options=...)` for model settings, execution limits, and tool selection. The optional `profile="work"` selects a model profile already configured on the daemon; omit it to use the daemon's default. Inline settings cannot include provider secrets, endpoints, or local prompt paths.
99
99
 
100
+ ### Extension model profiles
101
+
102
+ ```python
103
+ ext = Extension()
104
+ SEARCH_PROFILE = ext.register_profile(
105
+ "code-search",
106
+ provider="openai",
107
+ model="gpt-5.6-luna",
108
+ reasoning_effort="none",
109
+ hidden=True,
110
+ )
111
+ CLAUDE_PROFILE = ext.register_profile(
112
+ "claude",
113
+ provider="anthropic",
114
+ model="claude-sonnet-4-6",
115
+ anthropic={"platform": "anthropic"},
116
+ anthropic_api_access="subscription",
117
+ )
118
+ session = await client.create_session(profile=SEARCH_PROFILE)
119
+ ```
120
+
121
+ `register_profile(name, *, provider, model, hidden=False, **options)` returns the flat name unchanged. Names are ASCII slugs (1–128 characters; `default` is reserved). `hidden=True` hides the profile from pickers.
122
+
100
123
  ### Inline extensions
101
124
 
102
125
  Pass `extensions=[ext]` to expose local Python callbacks as agent tools. This calculator runs in your Python process; the agent runs on the selected daemon and runner.
@@ -0,0 +1 @@
1
+ 0.4.0
@@ -1,6 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import inspect
4
+ import re
4
5
  from collections.abc import Awaitable, Callable, Mapping, Sequence
5
6
  from dataclasses import dataclass
6
7
  from typing import (
@@ -36,6 +37,7 @@ from .context import (
36
37
  create_shortcut_context,
37
38
  create_tool_context,
38
39
  )
40
+ from .execution import ExtensionProfileOptions
39
41
  from .schemas import SchemaAdapter, SchemaLike, infer_schema_from_callable
40
42
 
41
43
  _MISSING = object()
@@ -325,6 +327,7 @@ class Extension:
325
327
  self._metadata["name"] = name
326
328
  if version is not None:
327
329
  self._metadata["version"] = version
330
+ self._profiles: dict[str, dict[str, Any]] = {}
328
331
  self._tools: dict[str, ToolRegistration] = {}
329
332
  self._commands_by_name: dict[str, CommandRegistration] = {}
330
333
  self._command_registrations: list[CommandRegistration] = []
@@ -350,6 +353,49 @@ class Extension:
350
353
  if value is not None:
351
354
  self._metadata[key] = value
352
355
 
356
+ def register_profile(
357
+ self,
358
+ name: str,
359
+ *,
360
+ provider: Literal["openai", "anthropic"],
361
+ model: str,
362
+ hidden: bool = False,
363
+ **options: Any,
364
+ ) -> str:
365
+ """Declare a model profile and return its name unchanged.
366
+
367
+ Names are 1–128-character ASCII slugs; default is reserved (case-insensitive).
368
+ Requires host acceptance before ACP selection.
369
+ Optional settings: weak_model, max_tokens, weak_model_max_tokens,
370
+ thinking_budget_tokens, reasoning_effort, openai, anthropic, and
371
+ anthropic_api_access (camelCase also accepted at the top level).
372
+ Provider blocks use daemon config keys unchanged; the daemon validates them.
373
+ """
374
+ if not isinstance(name, str) or not re.fullmatch(
375
+ r"[A-Za-z0-9][A-Za-z0-9._-]{0,127}", name,
376
+ ):
377
+ raise ValueError(
378
+ "Extension profile names must be ASCII slugs "
379
+ "matching [A-Za-z0-9][A-Za-z0-9._-]* (1–128 characters)"
380
+ )
381
+ if name.lower() == "default":
382
+ raise ValueError('Extension profile name "default" is reserved')
383
+ if name in self._profiles:
384
+ raise ValueError(f"Duplicate extension profile registration: {name}")
385
+ if not isinstance(hidden, bool):
386
+ raise ValueError("Extension profile hidden must be a boolean")
387
+ validated = ExtensionProfileOptions.model_validate({
388
+ "provider": provider,
389
+ "model": model,
390
+ **options,
391
+ })
392
+ self._profiles[name] = {
393
+ "name": name,
394
+ "options": validated.to_wire(),
395
+ "hidden": hidden,
396
+ }
397
+ return name
398
+
353
399
  def register_tool(
354
400
  self,
355
401
  *,
@@ -659,6 +705,13 @@ class Extension:
659
705
  registrations, shortcut registrations, and event subscriptions.
660
706
  """
661
707
 
708
+ capabilities = _mapping_or_empty(params.get("capabilities"))
709
+ profiles_capability = _mapping_or_empty(capabilities.get("profiles"))
710
+ if self._profiles and profiles_capability.get("remote") is not True:
711
+ raise RuntimeError(
712
+ "Remote extension profiles are not supported by this host; update the Kodelet "
713
+ "daemon and runner (capabilities.profiles.remote is required)"
714
+ )
662
715
  self._init_params = params
663
716
  extension = params.get("extension")
664
717
  extension_id = extension.get("id") if isinstance(extension, Mapping) else None
@@ -675,6 +728,8 @@ class Extension:
675
728
  }
676
729
  if version := self._metadata.get("version"):
677
730
  result["version"] = version
731
+ if self._profiles:
732
+ result["profiles"] = json_clone(list(self._profiles.values()))
678
733
  return result
679
734
 
680
735
  async def execute_tool(self, params: Mapping[str, Any]) -> dict[str, Any]:
@@ -1430,6 +1430,7 @@ class SharedContext:
1430
1430
  )
1431
1431
  data_dir = Path(str(data_dir_value)).resolve(strict=False)
1432
1432
  self.session_id = _optional_str(context.get("sessionId"))
1433
+ self.runner_id = _optional_str(extension.get("runnerId"))
1433
1434
  self.conversation_id = _optional_str(context.get("conversationId"))
1434
1435
  self.ui_scope_id = _normalize_ui_scope_id(context.get("uiScopeId")) or None
1435
1436
  self.cwd = str(cwd)
@@ -1,4 +1,4 @@
1
- """Typed, credential-free ACP execution options."""
1
+ """Typed ACP execution and extension profile options."""
2
2
 
3
3
  from __future__ import annotations
4
4
 
@@ -6,9 +6,9 @@ import csv
6
6
  import io
7
7
  import re
8
8
  from collections.abc import Mapping
9
- from typing import Annotated, Any, Literal
9
+ from typing import Annotated, Any, Literal, Self
10
10
 
11
- from pydantic import BaseModel, ConfigDict, Field, model_validator
11
+ from pydantic import BaseModel, ConfigDict, Field, JsonValue, model_validator
12
12
  from pydantic.alias_generators import to_camel
13
13
 
14
14
 
@@ -45,6 +45,52 @@ class ExecutionOptions(BaseModel):
45
45
  return self.model_dump(by_alias=True, exclude_none=True)
46
46
 
47
47
 
48
+ class ExtensionProfileOptions(BaseModel):
49
+ """Registration-only settings; nested provider configuration is validated by the daemon."""
50
+
51
+ model_config = ConfigDict(
52
+ extra="forbid",
53
+ strict=True,
54
+ alias_generator=to_camel,
55
+ populate_by_name=True,
56
+ )
57
+
58
+ provider: Literal["openai", "anthropic"]
59
+ model: str = Field(min_length=1)
60
+ weak_model: str | None = Field(default=None, min_length=1)
61
+ max_tokens: int | None = Field(default=None, gt=0)
62
+ weak_model_max_tokens: int | None = Field(default=None, gt=0)
63
+ thinking_budget_tokens: int | None = Field(default=None, ge=0)
64
+ reasoning_effort: str | None = Field(default=None, min_length=1)
65
+ openai: dict[str, JsonValue] | None = None
66
+ anthropic: dict[str, JsonValue] | None = None
67
+ anthropic_api_access: Literal["auto", "subscription", "api-key"] | None = Field(
68
+ default=None,
69
+ alias="anthropicAPIAccess",
70
+ )
71
+
72
+ @model_validator(mode="before")
73
+ @classmethod
74
+ def reject_null(cls, value: Any) -> Any:
75
+ if isinstance(value, Mapping) and any(item is None for item in value.values()):
76
+ raise ValueError("Omit absent profile settings; null is not inheritance")
77
+ return value
78
+
79
+ @model_validator(mode="after")
80
+ def validate_provider_settings(self) -> Self:
81
+ if self.provider != "openai" and self.openai is not None:
82
+ raise ValueError("openai settings require the openai provider")
83
+ if self.provider != "anthropic" and (
84
+ self.anthropic is not None or self.anthropic_api_access is not None
85
+ ):
86
+ raise ValueError("anthropic settings require the anthropic provider")
87
+ return self
88
+
89
+ def to_wire(self) -> dict[str, Any]:
90
+ """Return an independent wire snapshot, preserving nested provider config keys."""
91
+ return self.model_dump(by_alias=True, exclude_none=True)
92
+
93
+
48
94
  def execution_args(options: ExecutionOptions) -> list[str]:
49
95
  """Encode typed options for the daemon-only ACP client, including empty/false values."""
50
96
  args: list[str] = []
@@ -329,6 +329,56 @@ async def test_session_preserves_typed_execution_options_with_named_profile() ->
329
329
  await client.close()
330
330
 
331
331
 
332
+ @pytest.mark.asyncio
333
+ @pytest.mark.parametrize("registration", [
334
+ {
335
+ "name": "code-search",
336
+ "provider": "openai",
337
+ "model": "gpt-5.6-luna",
338
+ "reasoning_effort": "none",
339
+ "openai": {
340
+ "platform": "codex",
341
+ "api_mode": "responses",
342
+ "service_tier": "fast",
343
+ },
344
+ "hidden": True,
345
+ },
346
+ {
347
+ "name": "claude",
348
+ "provider": "anthropic",
349
+ "model": "claude-sonnet-4-6",
350
+ "anthropic": {"platform": "anthropic"},
351
+ "anthropic_api_access": "subscription",
352
+ },
353
+ ])
354
+ async def test_registered_profile_name_reaches_acp_without_expanding_model_options(
355
+ registration: dict[str, Any],
356
+ ) -> None:
357
+ ext = Extension()
358
+ profile = ext.register_profile(**registration)
359
+ manifest = ext.initialize({"capabilities": {"profiles": {"remote": True}}})
360
+ assert profile == registration["name"]
361
+ assert profile == manifest["profiles"][0]["name"]
362
+ calls: list[list[str]] = []
363
+ process = FakeACPProcess()
364
+
365
+ def spawn(_command: str, args: Sequence[str], _options: SpawnOptions) -> FakeACPProcess:
366
+ calls.append(list(args))
367
+ return process
368
+
369
+ client = Client(server="http://daemon", runner="runner-one", spawn=spawn)
370
+ try:
371
+ await client.create_session(profile=profile, cwd="/only/on/runner")
372
+ assert calls == [[
373
+ "acp", "--server", "http://daemon", "--runner", "runner-one",
374
+ f"--profile={registration['name']}",
375
+ ]]
376
+ assert process.requests[1]["method"] == "session/new"
377
+ assert process.requests[1]["params"] == {"cwd": "/only/on/runner"}
378
+ finally:
379
+ await client.close()
380
+
381
+
332
382
  def test_profile_maps_early_profiler_spelling_and_nested_config() -> None:
333
383
  profile = Profile(
334
384
  {
@@ -1715,6 +1765,15 @@ async def test_session_runs_kodelet_acp_json_rpc_and_emits_stream_events() -> No
1715
1765
  id="provider-config",
1716
1766
  ),
1717
1767
  pytest.param({"options": None}, None, id="null-options"),
1768
+ *[
1769
+ pytest.param({key: settings}, None, id=f"{key}-{name}")
1770
+ for key in ("profile", "options")
1771
+ for name, settings in (
1772
+ ("openai", {"openai": {"platform": "codex"}}),
1773
+ ("anthropic", {"anthropic": {"platform": "anthropic"}}),
1774
+ ("anthropic-access", {"anthropic_api_access": "subscription"}),
1775
+ )
1776
+ ],
1718
1777
  ],
1719
1778
  )
1720
1779
  async def test_session_rejects_unsupported_options_before_spawning(
@@ -65,6 +65,320 @@ def test_empty_extension_registration_shape() -> None:
65
65
  }
66
66
 
67
67
 
68
+ def test_remote_profile_manifest_roundtrip_and_snapshot_isolation() -> None:
69
+ ext = Extension(name="code-search")
70
+ options: dict[str, Any] = {
71
+ "provider": "openai",
72
+ "model": "gpt-5.6-luna",
73
+ "reasoning_effort": "none",
74
+ "weak_model": "gpt-5.6-luna",
75
+ "max_tokens": 4096,
76
+ "weak_model_max_tokens": 1024,
77
+ "thinking_budget_tokens": 0,
78
+ "openai": {
79
+ "platform": "codex",
80
+ "api_mode": "responses",
81
+ "service_tier": "fast",
82
+ },
83
+ "hidden": True,
84
+ }
85
+ assert ext.register_profile("search", **options) == "search"
86
+ options["model"] = "changed"
87
+ options["openai"]["service_tier"] = "scale"
88
+ anthropic = {"platform": "anthropic"}
89
+ assert ext.register_profile(
90
+ "visible",
91
+ provider="anthropic",
92
+ model="claude-sonnet-4-6",
93
+ anthropic=anthropic,
94
+ anthropic_api_access="subscription",
95
+ hidden=False,
96
+ ) == "visible"
97
+ anthropic["platform"] = "copilot"
98
+ ext.register_profile(
99
+ "standard",
100
+ provider="openai",
101
+ model="gpt-5.6-luna",
102
+ )
103
+ params = {"capabilities": {"profiles": {"remote": True}}}
104
+ manifest = ext.initialize(params)
105
+ expected = [
106
+ {
107
+ "name": "search",
108
+ "options": {
109
+ "provider": "openai",
110
+ "model": "gpt-5.6-luna",
111
+ "reasoningEffort": "none",
112
+ "weakModel": "gpt-5.6-luna",
113
+ "maxTokens": 4096,
114
+ "weakModelMaxTokens": 1024,
115
+ "thinkingBudgetTokens": 0,
116
+ "openai": {
117
+ "platform": "codex",
118
+ "api_mode": "responses",
119
+ "service_tier": "fast",
120
+ },
121
+ },
122
+ "hidden": True,
123
+ },
124
+ {
125
+ "name": "visible",
126
+ "options": {
127
+ "provider": "anthropic",
128
+ "model": "claude-sonnet-4-6",
129
+ "anthropic": {"platform": "anthropic"},
130
+ "anthropicAPIAccess": "subscription",
131
+ },
132
+ "hidden": False,
133
+ },
134
+ {
135
+ "name": "standard",
136
+ "options": {
137
+ "provider": "openai",
138
+ "model": "gpt-5.6-luna",
139
+ },
140
+ "hidden": False,
141
+ },
142
+ ]
143
+ assert json.loads(json.dumps(manifest))["profiles"] == expected
144
+ assert manifest["name"] == "code-search"
145
+ manifest["profiles"][0]["options"]["model"] = "mutated"
146
+ manifest["profiles"][0]["options"]["openai"]["platform"] = "openai"
147
+ manifest["profiles"][1]["options"]["anthropic"]["platform"] = "copilot"
148
+ manifest["profiles"][0]["hidden"] = False
149
+ manifest["profiles"].pop()
150
+ assert ext.initialize(params)["profiles"] == expected
151
+
152
+
153
+ @pytest.mark.parametrize("provider", ["openai", "anthropic"])
154
+ def test_remote_profiles_preserve_arbitrary_provider_dictionaries(provider: str) -> None:
155
+ ext = Extension()
156
+ settings: dict[str, Any] = {
157
+ "platform": "codex" if provider == "openai" else "copilot",
158
+ "api_mode": "chat_completions",
159
+ "service_tier": "custom-tier",
160
+ "base_url": "https://provider.invalid",
161
+ "api_key": "test-key",
162
+ "api_key_env_var": "PROVIDER_KEY",
163
+ "account": "work",
164
+ "future_setting": {"values": [True, None, 1.5, "value"]},
165
+ }
166
+ expected_settings = json.loads(json.dumps(settings))
167
+ arguments: dict[str, Any] = {
168
+ "provider": provider,
169
+ "model": "test-model",
170
+ provider: settings,
171
+ }
172
+ if provider == "anthropic":
173
+ arguments["anthropicAPIAccess"] = "subscription"
174
+ assert ext.register_profile("search", **arguments) == "search"
175
+ settings["future_setting"]["values"].append("mutated-input")
176
+ params = {"capabilities": {"profiles": {"remote": True}}}
177
+ manifest = ext.initialize(params)
178
+ expected = [{
179
+ "name": "search",
180
+ "options": {
181
+ **arguments,
182
+ provider: expected_settings,
183
+ },
184
+ "hidden": False,
185
+ }]
186
+ assert json.loads(json.dumps(manifest))["profiles"] == expected
187
+ manifest["profiles"][0]["options"][provider]["future_setting"]["values"].append("mutated-output")
188
+ assert ext.initialize(params)["profiles"] == expected
189
+ arguments[provider] = {}
190
+ ext.register_profile("empty", **arguments)
191
+ assert ext.initialize(params)["profiles"][1]["options"][provider] == {}
192
+
193
+
194
+ @pytest.mark.parametrize("camel_case", [False, True])
195
+ def test_remote_profiles_accept_subscription_settings_and_top_level_alias(camel_case: bool) -> None:
196
+ ext = Extension()
197
+ openai = {
198
+ "platform": "codex",
199
+ "api_mode": "responses",
200
+ "service_tier": "fast",
201
+ }
202
+ assert ext.register_profile(
203
+ "search",
204
+ provider="openai",
205
+ model="gpt-5.6-luna",
206
+ openai=openai,
207
+ ) == "search"
208
+ access: dict[str, Any] = {
209
+ "anthropicAPIAccess" if camel_case else "anthropic_api_access": "subscription",
210
+ }
211
+ assert ext.register_profile(
212
+ "claude",
213
+ provider="anthropic",
214
+ model="claude-sonnet-4-6",
215
+ anthropic={"platform": "anthropic"},
216
+ **access,
217
+ ) == "claude"
218
+ profiles = ext.initialize({"capabilities": {"profiles": {"remote": True}}})["profiles"]
219
+ assert profiles[0]["options"]["openai"] == {
220
+ "platform": "codex",
221
+ "api_mode": "responses",
222
+ "service_tier": "fast",
223
+ }
224
+ assert profiles[1]["options"] == {
225
+ "provider": "anthropic",
226
+ "model": "claude-sonnet-4-6",
227
+ "anthropic": {"platform": "anthropic"},
228
+ "anthropicAPIAccess": "subscription",
229
+ }
230
+
231
+
232
+ @pytest.mark.parametrize("options", [
233
+ *[{"openai": value} for value in (
234
+ None, [], "codex", True, 3, {"value": object()}, {1: "non-string-key"},
235
+ )],
236
+ *[{"provider": "anthropic", "anthropic": value} for value in (
237
+ None, [], "anthropic", True, 3, {"value": object()}, {1: "non-string-key"},
238
+ )],
239
+ {"anthropic": {}},
240
+ {"anthropic_api_access": "subscription"},
241
+ {"provider": "anthropic", "openai": {}},
242
+ {"provider": "anthropic", "anthropic_api_access": None},
243
+ {"provider": "anthropic", "anthropicAPIAccess": None},
244
+ {"provider": "anthropic", "anthropic_api_access": "oauth"},
245
+ {"provider": "anthropic", "anthropic_account": "work"},
246
+ {"provider": "anthropic", "anthropicAccount": "work"},
247
+ ])
248
+ def test_remote_profiles_reject_invalid_blocks_and_provider_mismatches(
249
+ options: dict[str, Any],
250
+ ) -> None:
251
+ ext = Extension()
252
+ arguments: dict[str, Any] = {
253
+ "provider": "openai",
254
+ "model": "test-model",
255
+ **options,
256
+ }
257
+ with pytest.raises(ValueError):
258
+ ext.register_profile("search", **arguments)
259
+ assert "profiles" not in ext.initialize({})
260
+
261
+
262
+ @pytest.mark.parametrize("name", ["", "a/b", "a b", "-search", "_search", ".search",
263
+ "écho", "search\n", "a\x00b", "a" * 129])
264
+ def test_remote_profiles_reject_invalid_names(name: str) -> None:
265
+ with pytest.raises(ValueError, match="slug"):
266
+ Extension().register_profile(
267
+ name,
268
+ provider="openai",
269
+ model="gpt-5.6-luna",
270
+ )
271
+
272
+
273
+ @pytest.mark.parametrize("name", ["default", "DEFAULT", "Default"])
274
+ def test_remote_profiles_reject_reserved_names(name: str) -> None:
275
+ with pytest.raises(ValueError, match="reserved"):
276
+ Extension().register_profile(
277
+ name,
278
+ provider="openai",
279
+ model="gpt-5.6-luna",
280
+ )
281
+
282
+
283
+ def test_remote_profiles_are_independent_of_extension_metadata() -> None:
284
+ ext = Extension()
285
+ profile = ext.register_profile(
286
+ "search",
287
+ provider="openai",
288
+ model="gpt-5.6-luna",
289
+ )
290
+ assert profile == "search"
291
+ params = {"capabilities": {"profiles": {"remote": True}}}
292
+ manifest = ext.initialize(params)
293
+ for name in ("code-search", "default", "renamed extension"):
294
+ ext.set_metadata(
295
+ name=name,
296
+ version="2",
297
+ )
298
+ updated = ext.initialize(params)
299
+ assert updated["name"] == name
300
+ assert updated["version"] == "2"
301
+ assert updated["profiles"] == manifest["profiles"]
302
+ assert updated["profiles"][0]["name"] == profile
303
+ with pytest.raises(ValueError, match="Duplicate"):
304
+ ext.register_profile(
305
+ "search",
306
+ provider="openai",
307
+ model="different",
308
+ )
309
+ assert ext.initialize(params)["profiles"] == manifest["profiles"]
310
+
311
+
312
+ @pytest.mark.parametrize("name", ["A", "A" + "a" * 127, "0" + "._-" * 42 + "z"])
313
+ def test_remote_profiles_accept_slug_boundaries_and_camel_case_options(name: str) -> None:
314
+ ext = Extension()
315
+ assert ext.register_profile(
316
+ name,
317
+ provider="openai",
318
+ model="gpt-5.6-luna",
319
+ reasoningEffort="none",
320
+ ) == name
321
+ assert ext.initialize({"capabilities": {"profiles": {"remote": True}}})["profiles"] == [
322
+ {
323
+ "name": name,
324
+ "options": {
325
+ "provider": "openai",
326
+ "model": "gpt-5.6-luna",
327
+ "reasoningEffort": "none",
328
+ },
329
+ "hidden": False,
330
+ },
331
+ ]
332
+
333
+
334
+ @pytest.mark.parametrize("options", [
335
+ {"provider": "unknown"}, {"provider": None}, {"model": ""}, {"model": None},
336
+ {"weak_model": ""}, {"reasoning_effort": None}, {"reasoning_effort": ""},
337
+ {"max_tokens": 0}, {"max_tokens": True}, {"weak_model_max_tokens": -1},
338
+ {"thinking_budget_tokens": -1}, {"max_tokens": "100"}, {"hidden": "false"},
339
+ {"hidden": 0}, {"hidden": None}, {"max_turns": 0}, {"use_weak_model": False},
340
+ {"no_tools": False}, {"no_extensions": False}, {"no_skills": False},
341
+ {"allowed_tools": []}, {"allowed_commands": []}, {"enable_fs_search_tools": False},
342
+ {"allowedTools": []}, {"useWeakModel": False}, {"maxTurns": 0},
343
+ {"api_key": "secret"}, {"base_url": "https://example.invalid"},
344
+ {"allowed_reasoning_efforts": ["none"]},
345
+ ])
346
+ def test_remote_profiles_reject_non_model_or_invalid_options(options: dict[str, Any]) -> None:
347
+ ext = Extension(name="code-search")
348
+ arguments: dict[str, Any] = {
349
+ "provider": "openai",
350
+ "model": "gpt-5.6-luna",
351
+ **options,
352
+ }
353
+ with pytest.raises(ValueError):
354
+ ext.register_profile("search", **arguments)
355
+ assert "profiles" not in ext.initialize({})
356
+
357
+
358
+ @pytest.mark.parametrize("options", [{}, {"provider": "openai"}, {"model": "gpt-5.6-luna"}])
359
+ def test_remote_profiles_require_provider_and_model(options: dict[str, Any]) -> None:
360
+ with pytest.raises(TypeError):
361
+ Extension(name="code-search").register_profile("search", **options)
362
+
363
+
364
+ @pytest.mark.parametrize("capabilities", [
365
+ None, {}, {"profiles": None}, {"profiles": {}}, {"profiles": []},
366
+ {"profiles": {"remote": False}}, {"profiles": {"remote": "true"}},
367
+ {"profiles": {"remote": 1}},
368
+ ])
369
+ def test_remote_profiles_require_explicit_host_support(capabilities: Any) -> None:
370
+ params = {} if capabilities is None else {"capabilities": capabilities}
371
+ ext = Extension(name="code-search")
372
+ ext.register_profile(
373
+ "search",
374
+ provider="openai",
375
+ model="gpt-5.6-luna",
376
+ )
377
+ with pytest.raises(RuntimeError, match="update the Kodelet daemon and runner"):
378
+ ext.initialize(params)
379
+ assert "profiles" not in Extension(name="ordinary").initialize(params)
380
+
381
+
68
382
  def test_reexports_pydantic_and_jinja2() -> None:
69
383
  class Model(Pydantic.BaseModel):
70
384
  name: str = Pydantic.Field(min_length=1)
@@ -608,6 +922,12 @@ async def test_tool_update_handler_can_replace_accumulated_snapshot() -> None:
608
922
  assert result == {"output": {"content": "[redacted]"}}
609
923
 
610
924
 
925
+ def test_tool_context_runner_identity_comes_from_initialize_metadata() -> None:
926
+ assert ToolContext(None).runner_id is None
927
+ context = ToolContext({"extension": {"runnerId": "selected-runner"}})
928
+ assert context.runner_id == "selected-runner"
929
+
930
+
611
931
  @pytest.mark.asyncio
612
932
  async def test_agent_init_can_disable_tools_using_invoked_by_context() -> None:
613
933
  ext = Extension()
@@ -1 +0,0 @@
1
- 0.3.0
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes