agentic-runner 3.14.0__tar.gz → 3.15.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 (77) hide show
  1. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/PKG-INFO +1 -1
  2. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/__init__.py +1 -1
  3. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/activities.py +32 -10
  4. agentic_runner-3.15.0/src/agentic_runner/auth_mode.py +126 -0
  5. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/device_login_activities.py +19 -17
  6. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/service.py +32 -5
  7. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/workers/claude_sign_in.py +48 -3
  8. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/workers/contract_device_login.py +18 -7
  9. agentic_runner-3.14.0/src/agentic_runner/auth_mode.py +0 -86
  10. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/.gitignore +0 -0
  11. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/LICENSE +0 -0
  12. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/README.md +0 -0
  13. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/pyproject.toml +0 -0
  14. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/attempts.py +0 -0
  15. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/build.py +0 -0
  16. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/callback.py +0 -0
  17. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/child_watcher.py +0 -0
  18. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/cli.py +0 -0
  19. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/cli_floor.py +0 -0
  20. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/config.py +0 -0
  21. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/credentials.py +0 -0
  22. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/egress.py +0 -0
  23. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/harness_self_test.py +0 -0
  24. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/heartbeat_link.py +0 -0
  25. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/hooks.py +0 -0
  26. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/host_store.py +0 -0
  27. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/integrations/__init__.py +0 -0
  28. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/integrations/git/__init__.py +0 -0
  29. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/integrations/git/contracts.py +0 -0
  30. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/integrations/git/evidence.py +0 -0
  31. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/integrations/git/fake_workspace.py +0 -0
  32. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/integrations/git/workspace.py +0 -0
  33. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/integrations/github/__init__.py +0 -0
  34. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/integrations/github/auth.py +0 -0
  35. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/integrations/github/fake_client.py +0 -0
  36. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/integrations/github/gh_client.py +0 -0
  37. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/integrations/oauth/__init__.py +0 -0
  38. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/integrations/oauth/fake_provider.py +0 -0
  39. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/lifecycle.py +0 -0
  40. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/llm_proxy.py +0 -0
  41. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/mcp.py +0 -0
  42. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/message_store.py +0 -0
  43. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/oauth_connectors.py +0 -0
  44. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/private_state.py +0 -0
  45. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/py.typed +0 -0
  46. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/recipient_key_secret.py +0 -0
  47. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/registration.py +0 -0
  48. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/runtime/__init__.py +0 -0
  49. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/runtime/verifier_command.py +0 -0
  50. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/sealed_box.py +0 -0
  51. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/skill.py +0 -0
  52. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/skills/agentic-runner-setup/SKILL.md +0 -0
  53. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/testing/__init__.py +0 -0
  54. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/testing/__main__.py +0 -0
  55. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/testing/control_plane.py +0 -0
  56. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/testing/plugin.py +0 -0
  57. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/testing/test_conformance.py +0 -0
  58. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/testing/workflow.py +0 -0
  59. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/tiny_http.py +0 -0
  60. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/triage_activities.py +0 -0
  61. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/usage_windows.py +0 -0
  62. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/user_sources.py +0 -0
  63. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/workers/__init__.py +0 -0
  64. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/workers/_runtime_support.py +0 -0
  65. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/workers/acp_runtime.py +0 -0
  66. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/workers/agent_runtime.py +0 -0
  67. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/workers/claude_runtime.py +0 -0
  68. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/workers/codex_runtime.py +0 -0
  69. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/workers/command_policy.py +0 -0
  70. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/workers/contract_isolation.py +0 -0
  71. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/workers/fastapi_client.py +0 -0
  72. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/workers/harness_outcome.py +0 -0
  73. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/workers/harness_usage.py +0 -0
  74. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/workers/mcp_config.py +0 -0
  75. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/workers/settings.py +0 -0
  76. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/workers/skills.py +0 -0
  77. {agentic_runner-3.14.0 → agentic_runner-3.15.0}/src/agentic_runner/workstation.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: agentic-runner
3
- Version: 3.14.0
3
+ Version: 3.15.0
4
4
  Summary: The Agentic OS Runner: an activity-only Temporal executor for workspaces, Agent Runtimes and verb seams
5
5
  License-Expression: AGPL-3.0-only
6
6
  License-File: LICENSE
@@ -7,6 +7,6 @@ stay on the platform; this package imports none of them, and a CI partition test
7
7
  (``tests/test_package_partition.py``) fails the build if that changes.
8
8
  """
9
9
 
10
- __version__ = "3.14.0"
10
+ __version__ = "3.15.0"
11
11
 
12
12
  __all__ = ["__version__"]
@@ -137,7 +137,7 @@ from agentic_runner.workers.agent_runtime import (
137
137
  PermissionFallback,
138
138
  ResumableAgentRuntime,
139
139
  )
140
- from agentic_runner.workers.contract_device_login import login_file_counts
140
+ from agentic_runner.workers.contract_device_login import holds_login, login_file_counts
141
141
  from agentic_runner.workers.contract_isolation import (
142
142
  NO_CONTRACT,
143
143
  ContractIsolation,
@@ -2995,20 +2995,29 @@ class RunnerRalphActivities:
2995
2995
  """This Directive's auth mode, or a non-retryable refusal with Evidence naming the
2996
2996
  rule (local-agents 04).
2997
2997
 
2998
- Decided from the host party this process was registered with and from whether a
2999
- key is present for the Contract -- never from the payload. A runtime that declares
3000
- no modes (a test double built before the port grew the field) reads as
3001
- ``api_key``-only, and a kind this Runner does not serve reads the same way; that
3002
- Directive fails closed in :meth:`_agent_runtime_for` regardless.
2998
+ Decided from what this process can check -- the host party it was registered with,
2999
+ whether a key is present for the Contract, whether the Contract runs under its own
3000
+ uid here and whether its harness root holds a login (QTS-1450) -- never from the
3001
+ payload. A runtime that declares no modes (a test double built before the port
3002
+ grew the field) reads as ``api_key``-only, and a kind this Runner does not serve
3003
+ reads the same way; that Directive fails closed in :meth:`_agent_runtime_for`
3004
+ regardless.
3003
3005
  """
3004
3006
 
3005
3007
  runtime = self._agent_runtimes.get(state.cli_kind)
3006
3008
  host_party = self._routing_identity.host_party if self._routing_identity else None
3009
+ contract_uid = self._runs_under_contract_uid(state)
3007
3010
  try:
3008
3011
  return choose_auth_mode(
3009
3012
  host_party=host_party,
3010
3013
  key_present=self._api_key_present(state, runtime),
3011
3014
  runtime_modes=getattr(runtime, "auth_modes", frozenset({AuthMode.API_KEY})),
3015
+ contract_uid=contract_uid,
3016
+ harness_login=(
3017
+ contract_uid
3018
+ and self._contract_isolation is not None
3019
+ and holds_login(self._contract_isolation, state.contract_id, state.cli_kind)
3020
+ ),
3012
3021
  )
3013
3022
  except AuthModeRefusedError as refusal:
3014
3023
  await _raise_recorded(
@@ -3026,6 +3035,16 @@ class RunnerRalphActivities:
3026
3035
  },
3027
3036
  )
3028
3037
 
3038
+ def _runs_under_contract_uid(self, state: _RuntimeContextState) -> bool:
3039
+ """Whether this Directive spawns as its own Contract's uid. A Work Record with no
3040
+ Contract shares the one no-Contract tree, so it never does."""
3041
+
3042
+ return (
3043
+ self._contract_isolation is not None
3044
+ and self._contract_isolation.can_separate_uids
3045
+ and _optional_uuid(state.contract_id) is not None
3046
+ )
3047
+
3029
3048
  def _api_key_present(self, state: _RuntimeContextState, runtime: AgentRuntime | None) -> bool:
3030
3049
  """A delivered slot for the Contract (or its funder), or the host operator's key."""
3031
3050
 
@@ -3039,18 +3058,21 @@ class RunnerRalphActivities:
3039
3058
  )
3040
3059
 
3041
3060
  async def _report_login_residue(self, work_record_id: str, state: _RuntimeContextState) -> None:
3042
- """On a shared Runner, say once that a Contract's harness root holds a login.
3061
+ """On a shared Runner that cannot run a subscription, say once that a Contract's
3062
+ harness root holds a login.
3043
3063
 
3044
3064
  A count per harness, never a path or a byte of the file: the Runner does not open
3045
- it, a shared Runner never runs on it, and ``wipe_contract_residue`` removes it with
3046
- the Contract. Saying so is what turns a sign-in made before local-agents 03 (or by
3047
- hand) into something the Organisation can see and act on.
3065
+ it, a shared Runner without Contract uids never runs on it (QTS-1450), and
3066
+ ``wipe_contract_residue`` removes it with the Contract. Saying so is what turns a
3067
+ sign-in made before local-agents 03 (or by hand) into something the Organisation
3068
+ can see and act on.
3048
3069
  """
3049
3070
 
3050
3071
  host_party = self._routing_identity.host_party if self._routing_identity else None
3051
3072
  if (
3052
3073
  self._contract_isolation is None
3053
3074
  or not is_shared_runner(host_party)
3075
+ or self._runs_under_contract_uid(state)
3054
3076
  or state.contract_id in self._residue_checked
3055
3077
  ):
3056
3078
  return
@@ -0,0 +1,126 @@
1
+ """Which auth mode one Directive runs in, decided on the Runner before spawn (local-agents 04).
2
+
3
+ Subscriptions follow the person and the actual operator, not the host party (QTS-1349,
4
+ QTS-1450). A harness runs on a subscription login where the Runner can verify that the
5
+ login is the Contract's alone:
6
+
7
+ * on the Contract person's own Runner -- host party ``user``, which routing has already
8
+ tied to the Contract's person (``assert_routed`` here, the platform's
9
+ ``_subscription_bound`` there);
10
+ * on a shared Runner (``organisation`` or ``account``, e.g. a customer-operated cluster)
11
+ only when the Directive runs as its Contract's own uid and that Contract's harness root
12
+ holds a login. The uid is what keeps one Contract's login out of every other
13
+ Contract's reach on the same host; the login is what the person made there themselves.
14
+
15
+ The platform decides who may use a subscription at the door (the Subscription Principal
16
+ and the Organisation's opt-in, QTS-1350); this module is the backstop, so it decides from
17
+ what the Runner itself can check and never from the payload.
18
+ """
19
+
20
+ from __future__ import annotations
21
+
22
+ from collections.abc import Collection
23
+ from typing import Final
24
+
25
+ from agentic_runner.workers.agent_runtime import AuthMode
26
+
27
+ __all__ = [
28
+ "NO_RUNTIME_SUBSCRIPTION_RULE",
29
+ "SETUP_TOKEN_REFUSED_RULE",
30
+ "SHARED_HOST_PARTIES",
31
+ "SIGN_IN_NEEDS_CONTRACT_UID_RULE",
32
+ "SUBSCRIPTION_NEEDS_CONTRACT_UID_RULE",
33
+ "SUBSCRIPTION_NEEDS_HARNESS_LOGIN_RULE",
34
+ "AuthModeRefusedError",
35
+ "choose_auth_mode",
36
+ "is_setup_token",
37
+ "is_shared_runner",
38
+ "runs_subscriptions",
39
+ ]
40
+
41
+ SHARED_HOST_PARTIES: Final[frozenset[str]] = frozenset({"organisation", "account"})
42
+
43
+ # The rule names a refusal's Evidence carries, so a support read can say which line held.
44
+ SUBSCRIPTION_NEEDS_CONTRACT_UID_RULE: Final[str] = "subscription_needs_contract_uid"
45
+ SUBSCRIPTION_NEEDS_HARNESS_LOGIN_RULE: Final[str] = "subscription_needs_harness_login"
46
+ NO_RUNTIME_SUBSCRIPTION_RULE: Final[str] = "runtime_has_no_subscription_mode"
47
+ SIGN_IN_NEEDS_CONTRACT_UID_RULE: Final[str] = "sign_in_needs_contract_uid"
48
+ SETUP_TOKEN_REFUSED_RULE: Final[str] = "setup_token_refused"
49
+ # `claude setup-token` mints an OAuth bearer under this prefix; an Anthropic API key is
50
+ # `sk-ant-api…`. The sealed wire carries no mode, so the value's own shape is what the
51
+ # Runner can refuse on.
52
+ _SETUP_TOKEN_PREFIX: Final[str] = "sk-ant-oat"
53
+
54
+
55
+ class AuthModeRefusedError(RuntimeError):
56
+ """A Directive or sign-in this Runner will not run; ``rule`` is the stable code."""
57
+
58
+ def __init__(self, rule: str, message: str) -> None:
59
+ super().__init__(message)
60
+ self.rule = rule
61
+
62
+
63
+ def is_shared_runner(host_party: str | None) -> bool:
64
+ return host_party in SHARED_HOST_PARTIES
65
+
66
+
67
+ def runs_subscriptions(host_party: str | None, *, separates_contract_uids: bool) -> bool:
68
+ """Whether a subscription login made on this Runner could ever run a Directive.
69
+
70
+ What a sign-in is checked against: one made where no Directive could use it would
71
+ only leave a login lying in a harness root. An unregistered process (no host party)
72
+ makes no routing assertion, so it is nobody's own Runner and never qualifies.
73
+ """
74
+
75
+ return host_party == "user" or (is_shared_runner(host_party) and separates_contract_uids)
76
+
77
+
78
+ def choose_auth_mode(
79
+ *,
80
+ host_party: str | None,
81
+ key_present: bool,
82
+ runtime_modes: Collection[AuthMode],
83
+ contract_uid: bool,
84
+ harness_login: bool,
85
+ ) -> AuthMode:
86
+ """``api_key`` whenever a key is present; otherwise ``subscription`` where the Runner
87
+ can verify the login is this Contract's, and a refusal on a shared Runner where it
88
+ cannot.
89
+
90
+ ``contract_uid`` says the Directive runs as its own Contract's uid (never the shared
91
+ no-Contract tree's); ``harness_login`` that this Contract's harness root for the
92
+ Directive's kind holds a login. A shared Runner with no key and either one missing has
93
+ nothing left that could authenticate the harness, so it refuses, naming the missing
94
+ one. An unregistered process (``host_party`` ``None``) never runs a subscription; it
95
+ runs on a key or fails at the proxy for want of one.
96
+ """
97
+
98
+ if key_present:
99
+ return AuthMode.API_KEY
100
+ if host_party == "user":
101
+ return AuthMode.SUBSCRIPTION if AuthMode.SUBSCRIPTION in runtime_modes else AuthMode.API_KEY
102
+ if not is_shared_runner(host_party):
103
+ return AuthMode.API_KEY
104
+ if not contract_uid:
105
+ raise AuthModeRefusedError(
106
+ SUBSCRIPTION_NEEDS_CONTRACT_UID_RULE,
107
+ f"this Runner is hosted by {host_party!r} and does not run this Contract under its "
108
+ "own uid, so it runs API keys only, and no API key is present for this Contract",
109
+ )
110
+ if not harness_login:
111
+ raise AuthModeRefusedError(
112
+ SUBSCRIPTION_NEEDS_HARNESS_LOGIN_RULE,
113
+ "no API key is present for this Contract and its harness root on this Runner holds "
114
+ "no login; sign it in on this Runner with `agentic-runner sign-in`",
115
+ )
116
+ if AuthMode.SUBSCRIPTION not in runtime_modes:
117
+ raise AuthModeRefusedError(
118
+ NO_RUNTIME_SUBSCRIPTION_RULE,
119
+ "no API key is present for this Contract and this Runner's runtime for its CLI "
120
+ "kind runs on API keys only",
121
+ )
122
+ return AuthMode.SUBSCRIPTION
123
+
124
+
125
+ def is_setup_token(value: str) -> bool:
126
+ return value.strip().startswith(_SETUP_TOKEN_PREFIX)
@@ -13,7 +13,7 @@ from datetime import UTC, datetime
13
13
  from temporalio import activity
14
14
  from temporalio.exceptions import ApplicationError
15
15
 
16
- from agentic_runner.auth_mode import SHARED_RUNNER_SIGN_IN_RULE, is_shared_runner
16
+ from agentic_runner.auth_mode import SIGN_IN_NEEDS_CONTRACT_UID_RULE, runs_subscriptions
17
17
  from agentic_runner.workers.contract_device_login import ContractDeviceLogin
18
18
  from agentic_runner.workers.contract_isolation import ContractIsolation
19
19
  from agentic_runner_contracts.activity_io import (
@@ -36,9 +36,9 @@ class ContractDeviceLoginActivities:
36
36
  host_party: str | None = None,
37
37
  ) -> None:
38
38
  self._contract_isolation = contract_isolation
39
- # The party this process was registered as hosted by. A shared Runner starts no
40
- # device login and reports only Claude Code's sign-in (local-agents 04, amended by
41
- # 21); a person signs Claude Code in on the Runner itself (QTS-1448).
39
+ # The party this process was registered as hosted by. A shared Runner signs in only
40
+ # where its Directives run as each Contract's own uid (QTS-1450); a person signs
41
+ # Claude Code in on the Runner itself (QTS-1448).
42
42
  self._host_party = host_party
43
43
  # Injectable for tests; None falls through to the real vendor CLIs.
44
44
  self._device_login = device_login or ContractDeviceLogin(contract_isolation)
@@ -53,7 +53,7 @@ class ContractDeviceLoginActivities:
53
53
  async def sign_in_contract_device_login(
54
54
  self, request: ContractDeviceLoginInput
55
55
  ) -> ContractDeviceLoginResult:
56
- self._refuse_on_shared_runner()
56
+ self._refuse_where_no_subscription_runs()
57
57
  prompt = await self._device_login.sign_in(
58
58
  request.contract_id, runtime_kind=request.runtime_kind
59
59
  )
@@ -70,7 +70,7 @@ class ContractDeviceLoginActivities:
70
70
  self, request: ContractDeviceLoginStatusInput
71
71
  ) -> ContractDeviceLoginStatusResult:
72
72
  if request.runtime_kind == "claude_code":
73
- self._refuse_on_shared_runner(allow=True)
73
+ self._refuse_where_no_subscription_runs()
74
74
  status = await self._device_login.claude.status(request.contract_id)
75
75
  return ContractDeviceLoginStatusResult(
76
76
  contract_id=request.contract_id,
@@ -80,7 +80,7 @@ class ContractDeviceLoginActivities:
80
80
  auth_method=status.auth_method,
81
81
  subscription_type=status.subscription_type,
82
82
  )
83
- self._refuse_on_shared_runner()
83
+ self._refuse_where_no_subscription_runs()
84
84
  present = self._device_login.token_present(
85
85
  request.contract_id, runtime_kind=request.runtime_kind
86
86
  )
@@ -98,20 +98,22 @@ class ContractDeviceLoginActivities:
98
98
  delivered_at=delivered_at,
99
99
  )
100
100
 
101
- def _refuse_on_shared_runner(self, *, allow: bool = False) -> None:
101
+ def _refuse_where_no_subscription_runs(self) -> None:
102
102
  """Non-retryable, and typed by the rule: there is no Work Record to write Evidence
103
103
  on here, so the failure the platform's sign-in workflow receives names it.
104
104
 
105
- Only a Runner known to be the person's own signs in, except that a shared Runner
106
- may report (``allow``) a Claude Code long-lived token (local-agents 21). One whose
107
- state names no host party (registered before issue 42) is refused either way, as
108
- `choose_auth_mode` never runs a subscription on it."""
105
+ A sign-in, or a read of one, only where a Directive could run on it
106
+ (``auth_mode.runs_subscriptions``): the person's own Runner, or a shared one that
107
+ runs each Contract as its own uid. One whose state names no host party (registered
108
+ before issue 42) is refused, as `choose_auth_mode` never runs a subscription on it.
109
+ """
109
110
 
110
- if self._host_party != "user" and not (allow and is_shared_runner(self._host_party)):
111
+ if not runs_subscriptions(
112
+ self._host_party, separates_contract_uids=self._contract_isolation.can_separate_uids
113
+ ):
111
114
  raise ApplicationError(
112
- f"this Runner is hosted by {self._host_party!r}; only a person's own Runner "
113
- "signs in, a shared Runner runs API keys and Claude Code long-lived tokens "
114
- "only",
115
- type=SHARED_RUNNER_SIGN_IN_RULE,
115
+ f"this Runner is hosted by {self._host_party!r} and does not run each Contract "
116
+ "under its own uid, so no subscription runs on it and it signs nothing in",
117
+ type=SIGN_IN_NEEDS_CONTRACT_UID_RULE,
116
118
  non_retryable=True,
117
119
  )
@@ -48,6 +48,7 @@ from temporalio.worker import (
48
48
  from agentic_runner import __version__ as runner_version
49
49
  from agentic_runner.activities import RunnerRalphActivities
50
50
  from agentic_runner.attempts import AttemptRecords
51
+ from agentic_runner.auth_mode import SIGN_IN_NEEDS_CONTRACT_UID_RULE, runs_subscriptions
51
52
  from agentic_runner.child_watcher import install_stop_tolerant_child_watcher
52
53
  from agentic_runner.config import RunnerConfig
53
54
  from agentic_runner.config import load as load_config
@@ -997,6 +998,10 @@ async def sign_in_claude(contract_id: str, *, method: str) -> int:
997
998
  so the Contract gets the uid and the harness root its Directives already run under.
998
999
  Nothing reaches the control plane: the console only reads the outcome back through
999
1000
  ``claude auth status`` (QTS-1448).
1001
+
1002
+ Refused up front where no Directive could run on the login (``runs_subscriptions``,
1003
+ QTS-1450), and confirmed at a prompt for a Contract this Runner holds no harness root
1004
+ for yet: a mistyped id would otherwise get a uid and a signed-in tree of its own.
1000
1005
  """
1001
1006
 
1002
1007
  mode = isolation_mode()
@@ -1018,7 +1023,21 @@ async def sign_in_claude(contract_id: str, *, method: str) -> int:
1018
1023
  file=sys.stderr,
1019
1024
  )
1020
1025
  return 2
1026
+ state = load_state(load_config().state_dir)
1027
+ host_party = (state.host_party if state is not None else "") or None
1028
+ if not runs_subscriptions(host_party, separates_contract_uids=can):
1029
+ runner = f"hosted by {host_party!r}" if host_party else "not registered"
1030
+ print(
1031
+ f"refusing to sign in ({SIGN_IN_NEEDS_CONTRACT_UID_RULE}): this Runner is {runner} "
1032
+ "and does not run each Contract under its own uid, so no Directive would run on "
1033
+ "the login",
1034
+ file=sys.stderr,
1035
+ )
1036
+ return 1
1021
1037
  sign_ins = ClaudeSignIns(build_contract_isolation(settings, can_separate_uids=can))
1038
+ if not sign_ins.has_harness_root(contract_id) and not _confirm_new_contract(contract_id):
1039
+ print("not signed in", file=sys.stderr)
1040
+ return 1
1022
1041
  try:
1023
1042
  return await sign_ins.sign_in(contract_id, method=method)
1024
1043
  except ClaudeSignInError as error:
@@ -1026,6 +1045,15 @@ async def sign_in_claude(contract_id: str, *, method: str) -> int:
1026
1045
  return 1
1027
1046
 
1028
1047
 
1048
+ def _confirm_new_contract(contract_id: str) -> bool:
1049
+ answer = input(
1050
+ f"This Runner holds no Claude Code harness root for Contract {contract_id} yet. Check "
1051
+ "the id against the console: a mistyped one signs in a Contract no Directive runs as. "
1052
+ "Sign it in? [y/N] "
1053
+ )
1054
+ return answer.strip().lower() in {"y", "yes"}
1055
+
1056
+
1029
1057
  async def _serve(
1030
1058
  *,
1031
1059
  config: RunnerConfig,
@@ -1349,13 +1377,12 @@ def build_usage_windows(
1349
1377
  isolation: ContractIsolation,
1350
1378
  in_flight: DirectivesInFlight,
1351
1379
  ) -> UsageWindows | None:
1352
- """A probe per served harness, or None off a user-hosted Runner (local-agents 10).
1353
-
1354
- Subscriptions follow the person (local-agents 04): only a user-hosted Runner runs one,
1355
- so only there is a usage window anyone's to read.
1380
+ """A probe per served harness, or None on a Runner that runs no subscription
1381
+ (local-agents 10): only where one can run is there a usage window anyone's to read
1382
+ (``auth_mode.runs_subscriptions``, QTS-1450).
1356
1383
  """
1357
1384
 
1358
- if host_party != "user":
1385
+ if not runs_subscriptions(host_party, separates_contract_uids=isolation.can_separate_uids):
1359
1386
  return None
1360
1387
  probes: dict[str, UsageWindowProbe] = {
1361
1388
  "codex_cli": CodexRateLimitsProbe(),
@@ -180,6 +180,12 @@ class ClaudeSignIns:
180
180
  self._status_argv = list(status_argv)
181
181
  self._platform = platform
182
182
 
183
+ def has_harness_root(self, contract_id: str) -> bool:
184
+ """Whether this Contract already has its Claude Code harness root (and, under
185
+ Contract uids, its uid) here. Never the one to create either."""
186
+
187
+ return self._isolation.existing_sandbox(contract_id, runtime_kind=RUNTIME_KIND) is not None
188
+
183
189
  async def sign_in(
184
190
  self, contract_id: str, *, method: str = OAUTH_TOKEN, stdin_fd: int = 0, stdout_fd: int = 1
185
191
  ) -> int:
@@ -298,8 +304,7 @@ async def _run_attached(
298
304
 
299
305
  master_fd, slave_fd = pty.openpty()
300
306
  try:
301
- rows = os.get_terminal_size(stdout_fd).lines if os.isatty(stdout_fd) else _PTY_ROWS
302
- fcntl.ioctl(slave_fd, termios.TIOCSWINSZ, struct.pack("HHHH", rows, _PTY_COLUMNS, 0, 0))
307
+ _copy_rows(stdout_fd, slave_fd)
303
308
  os.set_blocking(master_fd, False)
304
309
  try:
305
310
  process = await asyncio.create_subprocess_exec(
@@ -338,15 +343,43 @@ async def _run_attached(
338
343
  _write_all(stdout_fd, chunk)
339
344
  _keep_tail(output, chunk)
340
345
 
346
+ # What the person typed that the pty has not taken yet. A large paste fills its input
347
+ # queue and the non-blocking master refuses the rest, so stop reading the keyboard until
348
+ # the CLI has drained it: the paste arrives whole and this buffer stays one read long.
349
+ pending = bytearray()
350
+ keyboard_open = True
351
+
341
352
  def from_person() -> None:
353
+ nonlocal keyboard_open
342
354
  typed = os.read(stdin_fd, 1024)
343
355
  if not typed:
356
+ keyboard_open = False
357
+ loop.remove_reader(stdin_fd)
358
+ return
359
+ pending.extend(typed)
360
+ to_cli()
361
+
362
+ def to_cli() -> None:
363
+ try:
364
+ del pending[: os.write(master_fd, pending)]
365
+ except BlockingIOError:
366
+ pass
367
+ except OSError:
368
+ # EIO: the CLI is gone, and `from_cli` ends the session.
369
+ pending.clear()
370
+ if pending:
344
371
  loop.remove_reader(stdin_fd)
372
+ loop.add_writer(master_fd, to_cli)
345
373
  return
346
- os.write(master_fd, typed)
374
+ loop.remove_writer(master_fd)
375
+ if keyboard_open:
376
+ loop.add_reader(stdin_fd, from_person)
347
377
 
378
+ resizes = os.isatty(stdout_fd)
348
379
  loop.add_reader(master_fd, from_cli)
349
380
  loop.add_reader(stdin_fd, from_person)
381
+ if resizes:
382
+ loop.add_signal_handler(signal.SIGWINCH, _copy_rows, stdout_fd, master_fd)
350
383
  try:
351
384
  with _raw(stdin_fd):
352
385
  await exited.wait()
@@ -356,11 +389,23 @@ async def _run_attached(
356
389
  os.killpg(process.pid, signal.SIGKILL)
357
390
  raise
358
391
  finally:
392
+ if resizes:
393
+ loop.remove_signal_handler(signal.SIGWINCH)
359
394
  loop.remove_reader(master_fd)
395
+ loop.remove_writer(master_fd)
360
396
  loop.remove_reader(stdin_fd)
397
+ pending.clear()
361
398
  os.close(master_fd)
362
399
 
363
400
 
401
+ def _copy_rows(caller_fd: int, pty_fd: int) -> None:
402
+ """The caller's row count onto the CLI's pty, at ``_PTY_COLUMNS`` wide. Setting it on
403
+ a pty that already has one is what sends the CLI its own ``SIGWINCH``."""
404
+
405
+ rows = os.get_terminal_size(caller_fd).lines if os.isatty(caller_fd) else _PTY_ROWS
406
+ fcntl.ioctl(pty_fd, termios.TIOCSWINSZ, struct.pack("HHHH", rows, _PTY_COLUMNS, 0, 0))
407
+
408
+
364
409
  @contextlib.contextmanager
365
410
  def _raw(fd: int) -> Iterator[None]:
366
411
  """The caller's terminal in raw mode, so each key reaches the CLI as the CLI's own
@@ -41,13 +41,15 @@ __all__ = [
41
41
  "ContractDeviceLoginPromptError",
42
42
  "DeviceLoginPrompt",
43
43
  "UnknownHarnessError",
44
+ "holds_login",
44
45
  "login_file_counts",
45
46
  ]
46
47
 
47
48
  # The login files each harness's own sign-in writes, relative to its config root
48
49
  # (research/29 §1.1, §2.1). Read only with `Path.stat`/`Path.is_file` below, never opened.
49
50
  # Claude's `claude_ai` login on macOS is a Keychain item, not a file: its presence is
50
- # `ClaudeSignIns.status`, and this table serves only the residue count.
51
+ # `ClaudeSignIns.status`. So a shared Runner on macOS runs a Claude subscription on the
52
+ # long-lived token only; a person's own Runner does not consult this table.
51
53
  _TOKEN_FILES_BY_RUNTIME: Final[dict[str, tuple[str, ...]]] = {
52
54
  "codex_cli": ("auth.json",),
53
55
  "claude_code": (".credentials.json", OAUTH_TOKEN_FILE),
@@ -186,12 +188,21 @@ def login_file_counts(isolation: ContractIsolation, contract_id: str | None) ->
186
188
  a login is there, not where or what it is (local-agents 04).
187
189
  """
188
190
 
189
- counts: dict[str, int] = {}
190
- for runtime_kind, filenames in _TOKEN_FILES_BY_RUNTIME.items():
191
- root = isolation.harness_config_dir(contract_id, runtime_kind)
192
- if any((root / filename).is_file() for filename in filenames):
193
- counts[runtime_kind] = 1
194
- return counts
191
+ return {
192
+ runtime_kind: 1
193
+ for runtime_kind in _TOKEN_FILES_BY_RUNTIME
194
+ if holds_login(isolation, contract_id, runtime_kind)
195
+ }
196
+
197
+
198
+ def holds_login(isolation: ContractIsolation, contract_id: str | None, runtime_kind: str) -> bool:
199
+ """Whether this Contract's harness root for ``runtime_kind`` holds a login file, by
200
+ ``stat`` alone. A kind with no known login file holds none: the shared Runner's
201
+ subscription check (``auth_mode.choose_auth_mode``) fails closed on it."""
202
+
203
+ filenames = _TOKEN_FILES_BY_RUNTIME.get(runtime_kind, ())
204
+ root = isolation.harness_config_dir(contract_id, runtime_kind)
205
+ return any((root / filename).is_file() for filename in filenames)
195
206
 
196
207
 
197
208
  def _prompt_has_verification(raw: str) -> bool:
@@ -1,86 +0,0 @@
1
- """Which auth mode one Directive runs in, decided on the Runner before spawn (local-agents 04).
2
-
3
- Subscriptions follow the person, not the host (owner, 2026-09-26): a harness runs on a
4
- subscription login only on the Contract person's own Runner -- host party ``user``, which
5
- routing has already tied to the Contract's person (``assert_routed`` here, the platform's
6
- ``_subscription_bound`` there) -- whatever channel the Runner was installed by. A shared
7
- Runner (``organisation`` or ``account``) runs every Directive through the LLM proxy on an
8
- API key and refuses sign-in. The platform refuses an ineligible sign-in at the door
9
- (local-agents 03); this module is the backstop, so it decides from what the Runner itself
10
- knows and never from the payload.
11
- """
12
-
13
- from __future__ import annotations
14
-
15
- from collections.abc import Collection
16
- from typing import Final
17
-
18
- from agentic_runner.workers.agent_runtime import AuthMode
19
-
20
- __all__ = [
21
- "SETUP_TOKEN_REFUSED_RULE",
22
- "SHARED_HOST_PARTIES",
23
- "SHARED_RUNNER_SIGN_IN_RULE",
24
- "SHARED_RUNNER_SUBSCRIPTION_RULE",
25
- "AuthModeRefusedError",
26
- "choose_auth_mode",
27
- "is_setup_token",
28
- "is_shared_runner",
29
- ]
30
-
31
- SHARED_HOST_PARTIES: Final[frozenset[str]] = frozenset({"organisation", "account"})
32
-
33
- # The rule names a refusal's Evidence carries, so a support read can say which line held.
34
- SHARED_RUNNER_SUBSCRIPTION_RULE: Final[str] = "shared_runner_api_key_only"
35
- SHARED_RUNNER_SIGN_IN_RULE: Final[str] = "shared_runner_sign_in_refused"
36
- SETUP_TOKEN_REFUSED_RULE: Final[str] = "setup_token_refused"
37
-
38
- # `claude setup-token` mints an OAuth bearer under this prefix; an Anthropic API key is
39
- # `sk-ant-api…`. The sealed wire carries no mode, so the value's own shape is what the
40
- # Runner can refuse on.
41
- _SETUP_TOKEN_PREFIX: Final[str] = "sk-ant-oat"
42
-
43
-
44
- class AuthModeRefusedError(RuntimeError):
45
- """A Directive or sign-in this Runner will not run; ``rule`` is the stable code."""
46
-
47
- def __init__(self, rule: str, message: str) -> None:
48
- super().__init__(message)
49
- self.rule = rule
50
-
51
-
52
- def is_shared_runner(host_party: str | None) -> bool:
53
- return host_party in SHARED_HOST_PARTIES
54
-
55
-
56
- def choose_auth_mode(
57
- *,
58
- host_party: str | None,
59
- key_present: bool,
60
- runtime_modes: Collection[AuthMode],
61
- ) -> AuthMode:
62
- """``api_key`` whenever a key is present; otherwise ``subscription`` on a user-hosted
63
- Runner whose runtime can run one, and a refusal on a shared Runner.
64
-
65
- The refusal is the shared Runner's "subscription case": with no key there is nothing
66
- for the proxy to spend, and the only thing left that could authenticate the harness is
67
- a login, which a shared Runner never uses. An unregistered process (``host_party``
68
- ``None``) is not user-hosted either, so it never runs a subscription; it runs on a key
69
- or fails at the proxy for want of one, as it would today.
70
- """
71
-
72
- if key_present:
73
- return AuthMode.API_KEY
74
- if is_shared_runner(host_party):
75
- raise AuthModeRefusedError(
76
- SHARED_RUNNER_SUBSCRIPTION_RULE,
77
- f"this Runner is hosted by {host_party!r}, so it runs API keys only, and no API "
78
- "key is present for this Contract",
79
- )
80
- if host_party == "user" and AuthMode.SUBSCRIPTION in runtime_modes:
81
- return AuthMode.SUBSCRIPTION
82
- return AuthMode.API_KEY
83
-
84
-
85
- def is_setup_token(value: str) -> bool:
86
- return value.strip().startswith(_SETUP_TOKEN_PREFIX)
File without changes