@stigmer/server 3.20.0 → 3.22.0

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 (257) hide show
  1. package/dist/authorization/evaluator.d.ts +7 -1
  2. package/dist/authorization/evaluator.d.ts.map +1 -1
  3. package/dist/authorization/evaluator.js.map +1 -1
  4. package/dist/authorization/list-read-scope.d.ts.map +1 -1
  5. package/dist/authorization/list-read-scope.js +19 -11
  6. package/dist/authorization/list-read-scope.js.map +1 -1
  7. package/dist/authorization/model/organization.d.ts.map +1 -1
  8. package/dist/authorization/model/organization.js +2 -0
  9. package/dist/authorization/model/organization.js.map +1 -1
  10. package/dist/boot/compose.d.ts.map +1 -1
  11. package/dist/boot/compose.js +0 -1
  12. package/dist/boot/compose.js.map +1 -1
  13. package/dist/boot/inprocess.d.ts +0 -2
  14. package/dist/boot/inprocess.d.ts.map +1 -1
  15. package/dist/boot/inprocess.js +0 -6
  16. package/dist/boot/inprocess.js.map +1 -1
  17. package/dist/domain/agent/controller.d.ts +2 -2
  18. package/dist/domain/agent/controller.d.ts.map +1 -1
  19. package/dist/domain/agent/controller.js +3 -17
  20. package/dist/domain/agent/controller.js.map +1 -1
  21. package/dist/domain/agent/steps.d.ts +0 -1
  22. package/dist/domain/agent/steps.d.ts.map +1 -1
  23. package/dist/domain/agent/steps.js +1 -40
  24. package/dist/domain/agent/steps.js.map +1 -1
  25. package/dist/domain/agentchannel/controller.d.ts.map +1 -1
  26. package/dist/domain/agentchannel/controller.js +6 -1
  27. package/dist/domain/agentchannel/controller.js.map +1 -1
  28. package/dist/domain/agentchannel/steps.d.ts +19 -0
  29. package/dist/domain/agentchannel/steps.d.ts.map +1 -1
  30. package/dist/domain/agentchannel/steps.js +32 -0
  31. package/dist/domain/agentchannel/steps.js.map +1 -1
  32. package/dist/domain/agentexecution/controller.d.ts.map +1 -1
  33. package/dist/domain/agentexecution/controller.js +7 -9
  34. package/dist/domain/agentexecution/controller.js.map +1 -1
  35. package/dist/domain/agentexecution/create-execution-context-step.d.ts +0 -2
  36. package/dist/domain/agentexecution/create-execution-context-step.d.ts.map +1 -1
  37. package/dist/domain/agentexecution/create-execution-context-step.js +179 -60
  38. package/dist/domain/agentexecution/create-execution-context-step.js.map +1 -1
  39. package/dist/domain/agentexecution/create-steps.d.ts +16 -31
  40. package/dist/domain/agentexecution/create-steps.d.ts.map +1 -1
  41. package/dist/domain/agentexecution/create-steps.js +36 -102
  42. package/dist/domain/agentexecution/create-steps.js.map +1 -1
  43. package/dist/domain/agentexecution/run-target.d.ts +7 -3
  44. package/dist/domain/agentexecution/run-target.d.ts.map +1 -1
  45. package/dist/domain/agentexecution/run-target.js.map +1 -1
  46. package/dist/domain/agentinstance/controller.d.ts +5 -5
  47. package/dist/domain/agentinstance/controller.d.ts.map +1 -1
  48. package/dist/domain/agentinstance/controller.js +6 -1
  49. package/dist/domain/agentinstance/controller.js.map +1 -1
  50. package/dist/domain/agentinstance/steps.d.ts +43 -8
  51. package/dist/domain/agentinstance/steps.d.ts.map +1 -1
  52. package/dist/domain/agentinstance/steps.js +71 -8
  53. package/dist/domain/agentinstance/steps.js.map +1 -1
  54. package/dist/domain/agentshare/controller.d.ts.map +1 -1
  55. package/dist/domain/agentshare/controller.js +7 -1
  56. package/dist/domain/agentshare/controller.js.map +1 -1
  57. package/dist/domain/agentshare/steps.d.ts +58 -0
  58. package/dist/domain/agentshare/steps.d.ts.map +1 -1
  59. package/dist/domain/agentshare/steps.js +109 -4
  60. package/dist/domain/agentshare/steps.js.map +1 -1
  61. package/dist/domain/artifact/controller.js +21 -25
  62. package/dist/domain/artifact/controller.js.map +1 -1
  63. package/dist/domain/channelapp/controller.d.ts.map +1 -1
  64. package/dist/domain/channelapp/controller.js +2 -0
  65. package/dist/domain/channelapp/controller.js.map +1 -1
  66. package/dist/domain/environment/controller.d.ts.map +1 -1
  67. package/dist/domain/environment/controller.js +2 -0
  68. package/dist/domain/environment/controller.js.map +1 -1
  69. package/dist/domain/environment/personal.d.ts +42 -0
  70. package/dist/domain/environment/personal.d.ts.map +1 -0
  71. package/dist/domain/environment/personal.js +96 -0
  72. package/dist/domain/environment/personal.js.map +1 -0
  73. package/dist/domain/executioncontext/controller.d.ts.map +1 -1
  74. package/dist/domain/executioncontext/controller.js +2 -0
  75. package/dist/domain/executioncontext/controller.js.map +1 -1
  76. package/dist/domain/executioncontext/steps.d.ts.map +1 -1
  77. package/dist/domain/executioncontext/steps.js +2 -1
  78. package/dist/domain/executioncontext/steps.js.map +1 -1
  79. package/dist/domain/mcpserver/connect.d.ts +0 -2
  80. package/dist/domain/mcpserver/connect.d.ts.map +1 -1
  81. package/dist/domain/mcpserver/connect.js +24 -79
  82. package/dist/domain/mcpserver/connect.js.map +1 -1
  83. package/dist/domain/mcpserver/controller.d.ts.map +1 -1
  84. package/dist/domain/mcpserver/controller.js +2 -0
  85. package/dist/domain/mcpserver/controller.js.map +1 -1
  86. package/dist/domain/mcpserver/start-connect.d.ts.map +1 -1
  87. package/dist/domain/mcpserver/start-connect.js +8 -7
  88. package/dist/domain/mcpserver/start-connect.js.map +1 -1
  89. package/dist/domain/memory/controller.d.ts.map +1 -1
  90. package/dist/domain/memory/controller.js +6 -1
  91. package/dist/domain/memory/controller.js.map +1 -1
  92. package/dist/domain/memory/steps.d.ts +23 -0
  93. package/dist/domain/memory/steps.d.ts.map +1 -1
  94. package/dist/domain/memory/steps.js +35 -0
  95. package/dist/domain/memory/steps.js.map +1 -1
  96. package/dist/domain/oauthapp/controller.d.ts.map +1 -1
  97. package/dist/domain/oauthapp/controller.js +2 -0
  98. package/dist/domain/oauthapp/controller.js.map +1 -1
  99. package/dist/domain/plugin/controller.d.ts.map +1 -1
  100. package/dist/domain/plugin/controller.js +5 -24
  101. package/dist/domain/plugin/controller.js.map +1 -1
  102. package/dist/domain/plugin/overlay/sanitize.js +2 -2
  103. package/dist/domain/schedule/controller.d.ts.map +1 -1
  104. package/dist/domain/schedule/controller.js +7 -1
  105. package/dist/domain/schedule/controller.js.map +1 -1
  106. package/dist/domain/schedule/steps.d.ts +19 -0
  107. package/dist/domain/schedule/steps.d.ts.map +1 -1
  108. package/dist/domain/schedule/steps.js +32 -0
  109. package/dist/domain/schedule/steps.js.map +1 -1
  110. package/dist/domain/session/controller.d.ts +0 -7
  111. package/dist/domain/session/controller.d.ts.map +1 -1
  112. package/dist/domain/session/controller.js +11 -16
  113. package/dist/domain/session/controller.js.map +1 -1
  114. package/dist/domain/session/run-target.d.ts +9 -8
  115. package/dist/domain/session/run-target.d.ts.map +1 -1
  116. package/dist/domain/session/run-target.js.map +1 -1
  117. package/dist/domain/session/steps.d.ts +8 -36
  118. package/dist/domain/session/steps.d.ts.map +1 -1
  119. package/dist/domain/session/steps.js +27 -172
  120. package/dist/domain/session/steps.js.map +1 -1
  121. package/dist/domain/skill/controller.d.ts.map +1 -1
  122. package/dist/domain/skill/controller.js +8 -17
  123. package/dist/domain/skill/controller.js.map +1 -1
  124. package/dist/domain/workflow/controller.d.ts.map +1 -1
  125. package/dist/domain/workflow/controller.js +30 -107
  126. package/dist/domain/workflow/controller.js.map +1 -1
  127. package/dist/domain/workflow/version-resolution.d.ts +5 -0
  128. package/dist/domain/workflow/version-resolution.d.ts.map +1 -0
  129. package/dist/domain/workflow/version-resolution.js +113 -0
  130. package/dist/domain/workflow/version-resolution.js.map +1 -0
  131. package/dist/domain/workflowexecution/create-steps.d.ts +4 -3
  132. package/dist/domain/workflowexecution/create-steps.d.ts.map +1 -1
  133. package/dist/domain/workflowexecution/create-steps.js +4 -3
  134. package/dist/domain/workflowexecution/create-steps.js.map +1 -1
  135. package/dist/domain/workflowinstance/controller.d.ts.map +1 -1
  136. package/dist/domain/workflowinstance/controller.js +6 -1
  137. package/dist/domain/workflowinstance/controller.js.map +1 -1
  138. package/dist/domain/workflowinstance/steps.d.ts +20 -0
  139. package/dist/domain/workflowinstance/steps.d.ts.map +1 -1
  140. package/dist/domain/workflowinstance/steps.js +39 -0
  141. package/dist/domain/workflowinstance/steps.js.map +1 -1
  142. package/dist/extensions/identity.d.ts +19 -0
  143. package/dist/extensions/identity.d.ts.map +1 -1
  144. package/dist/extensions/identity.js +22 -3
  145. package/dist/extensions/identity.js.map +1 -1
  146. package/dist/extensions/list-read-scope.d.ts +41 -7
  147. package/dist/extensions/list-read-scope.d.ts.map +1 -1
  148. package/dist/extensions/list-read-scope.js +13 -2
  149. package/dist/extensions/list-read-scope.js.map +1 -1
  150. package/dist/pipeline/apiresource-labels.d.ts +2 -2
  151. package/dist/pipeline/apiresource-labels.js +2 -2
  152. package/dist/pipeline/errors.d.ts +2 -2
  153. package/dist/pipeline/errors.js +2 -2
  154. package/dist/pipeline/steps/authorize-resolved-target.d.ts +88 -0
  155. package/dist/pipeline/steps/authorize-resolved-target.d.ts.map +1 -0
  156. package/dist/pipeline/steps/authorize-resolved-target.js +36 -0
  157. package/dist/pipeline/steps/authorize-resolved-target.js.map +1 -0
  158. package/dist/pipeline/steps/authorize.d.ts +27 -0
  159. package/dist/pipeline/steps/authorize.d.ts.map +1 -1
  160. package/dist/pipeline/steps/authorize.js +49 -10
  161. package/dist/pipeline/steps/authorize.js.map +1 -1
  162. package/dist/pipeline/steps/guard-memory-capture.d.ts.map +1 -1
  163. package/dist/pipeline/steps/guard-memory-capture.js +2 -1
  164. package/dist/pipeline/steps/guard-memory-capture.js.map +1 -1
  165. package/dist/pipeline/steps/guard-reserved-labels.d.ts.map +1 -1
  166. package/dist/pipeline/steps/guard-reserved-labels.js +12 -12
  167. package/dist/pipeline/steps/guard-reserved-labels.js.map +1 -1
  168. package/dist/pipeline/steps/helpers.d.ts +9 -5
  169. package/dist/pipeline/steps/helpers.d.ts.map +1 -1
  170. package/dist/pipeline/steps/helpers.js +11 -15
  171. package/dist/pipeline/steps/helpers.js.map +1 -1
  172. package/dist/pipeline/steps/version-history.d.ts +11 -0
  173. package/dist/pipeline/steps/version-history.d.ts.map +1 -1
  174. package/dist/pipeline/steps/version-history.js +26 -0
  175. package/dist/pipeline/steps/version-history.js.map +1 -1
  176. package/package.json +6 -6
  177. package/src/authorization/__tests__/list-read-scope.test.ts +23 -12
  178. package/src/authorization/__tests__/skip-lane-inventory.test.ts +160 -0
  179. package/src/authorization/__tests__/wire-permissions.test.ts +5 -5
  180. package/src/authorization/evaluator.ts +7 -0
  181. package/src/authorization/list-read-scope.ts +22 -11
  182. package/src/authorization/model/__tests__/registry.test.ts +2 -0
  183. package/src/authorization/model/organization.ts +2 -0
  184. package/src/boot/compose.ts +0 -1
  185. package/src/boot/inprocess.ts +0 -9
  186. package/src/domain/agent/__tests__/agent.test.ts +0 -68
  187. package/src/domain/agent/controller.ts +11 -36
  188. package/src/domain/agent/steps.ts +1 -60
  189. package/src/domain/agentchannel/__tests__/create-authorization.test.ts +58 -0
  190. package/src/domain/agentchannel/controller.ts +19 -0
  191. package/src/domain/agentchannel/steps.ts +40 -0
  192. package/src/domain/agentexecution/__tests__/create-execution-context-step.test.ts +216 -0
  193. package/src/domain/agentexecution/__tests__/create-steps.test.ts +70 -145
  194. package/src/domain/agentexecution/controller.ts +6 -10
  195. package/src/domain/agentexecution/create-execution-context-step.ts +271 -83
  196. package/src/domain/agentexecution/create-steps.ts +38 -138
  197. package/src/domain/agentexecution/run-target.ts +7 -3
  198. package/src/domain/agentinstance/__tests__/create-authorization.composed.test.ts +243 -0
  199. package/src/domain/agentinstance/__tests__/create-authorization.test.ts +144 -0
  200. package/src/domain/agentinstance/controller.ts +24 -5
  201. package/src/domain/agentinstance/steps.ts +82 -8
  202. package/src/domain/agentshare/__tests__/create-authorization.test.ts +86 -0
  203. package/src/domain/agentshare/__tests__/member-audience.test.ts +113 -0
  204. package/src/domain/agentshare/controller.ts +21 -0
  205. package/src/domain/agentshare/steps.ts +181 -15
  206. package/src/domain/artifact/controller.ts +18 -22
  207. package/src/domain/channelapp/controller.ts +10 -0
  208. package/src/domain/environment/__tests__/personal.test.ts +143 -0
  209. package/src/domain/environment/controller.ts +10 -0
  210. package/src/domain/environment/personal.ts +141 -0
  211. package/src/domain/executioncontext/__tests__/executioncontext.test.ts +1 -0
  212. package/src/domain/executioncontext/controller.ts +10 -0
  213. package/src/domain/executioncontext/steps.ts +2 -1
  214. package/src/domain/mcpserver/connect.ts +32 -92
  215. package/src/domain/mcpserver/controller.ts +13 -1
  216. package/src/domain/mcpserver/start-connect.ts +17 -11
  217. package/src/domain/memory/__tests__/create-authorization.test.ts +59 -0
  218. package/src/domain/memory/controller.ts +11 -0
  219. package/src/domain/memory/steps.ts +41 -0
  220. package/src/domain/oauthapp/controller.ts +10 -0
  221. package/src/domain/plugin/controller.ts +22 -36
  222. package/src/domain/plugin/overlay/sanitize.ts +2 -2
  223. package/src/domain/schedule/__tests__/create-authorization.test.ts +58 -0
  224. package/src/domain/schedule/controller.ts +20 -0
  225. package/src/domain/schedule/steps.ts +45 -2
  226. package/src/domain/session/__tests__/run-gate.test.ts +19 -52
  227. package/src/domain/session/__tests__/session.test.ts +27 -203
  228. package/src/domain/session/controller.ts +10 -30
  229. package/src/domain/session/run-target.ts +9 -8
  230. package/src/domain/session/steps.ts +33 -267
  231. package/src/domain/skill/controller.ts +24 -23
  232. package/src/domain/workflow/controller.ts +58 -145
  233. package/src/domain/workflow/version-resolution.ts +166 -0
  234. package/src/domain/workflowexecution/create-steps.ts +4 -3
  235. package/src/domain/workflowinstance/__tests__/create-authorization.test.ts +109 -0
  236. package/src/domain/workflowinstance/controller.ts +19 -0
  237. package/src/domain/workflowinstance/steps.ts +49 -1
  238. package/src/extensions/__tests__/composed-support.ts +38 -4
  239. package/src/extensions/__tests__/identity.test.ts +44 -1
  240. package/src/extensions/__tests__/list-read-scope-composed.test.ts +87 -1
  241. package/src/extensions/__tests__/list-read-scope.test.ts +63 -0
  242. package/src/extensions/identity.ts +23 -5
  243. package/src/extensions/list-read-scope.ts +47 -7
  244. package/src/pipeline/apiresource-labels.ts +2 -2
  245. package/src/pipeline/errors.ts +2 -2
  246. package/src/pipeline/steps/__tests__/authorize-resolved-target.test.ts +285 -0
  247. package/src/pipeline/steps/authorize-resolved-target.ts +129 -0
  248. package/src/pipeline/steps/authorize.ts +70 -13
  249. package/src/pipeline/steps/guard-memory-capture.ts +2 -1
  250. package/src/pipeline/steps/guard-reserved-labels.ts +12 -14
  251. package/src/pipeline/steps/helpers.ts +11 -15
  252. package/src/pipeline/steps/version-history.ts +34 -0
  253. package/dist/domain/agent/defaultagent.d.ts +0 -37
  254. package/dist/domain/agent/defaultagent.d.ts.map +0 -1
  255. package/dist/domain/agent/defaultagent.js +0 -104
  256. package/dist/domain/agent/defaultagent.js.map +0 -1
  257. package/src/domain/agent/defaultagent.ts +0 -135
@@ -1,16 +1,13 @@
1
1
  /**
2
2
  * Pins the session domain against Go's pkg/domain/session tests — through
3
3
  * the REAL stack: a composed server on an ephemeral port, a native gRPC
4
- * client, the full interceptor chain, and the DD-002 in-process
5
- * agentinstance CREATE edge (session create's default-instance self-heal
6
- * runs through the router transport).
4
+ * client, and the full interceptor chain.
7
5
  *
8
6
  * The load-bearing pins:
9
- * - ResolveDefaultAgentInstance fills the session's agent_instance_id
10
- * from the platform default agent (newState, not input — the persisted
11
- * session carries it); the on-the-fly default-instance creation path
12
- * writes the agent's status.default_instance_id; the not-configured /
13
- * not-public arms carry Go WrapError's exact double-wrapped copy;
7
+ * - an empty agent_instance_id is the built-in assistant: create stores
8
+ * it empty (nothing resolves it into an instance), an explicit id is
9
+ * kept as given, and a session may gain an agent or drop back to the
10
+ * assistant on update — the instance is not an immutable field;
14
11
  * - harness immutability locks only once harness_state_id is non-empty,
15
12
  * with UNSPECIFIED==NATIVE equivalence in both directions and the
16
13
  * exact FAILED_PRECONDITION copy;
@@ -39,11 +36,8 @@ import { createGrpcTransport } from "@connectrpc/connect-node";
39
36
  import { afterAll, beforeAll, describe, expect, it } from "vitest";
40
37
 
41
38
  import { AgentCommandController } from "@stigmer/protos/ai/stigmer/agentic/agent/v1/command_pb";
42
- import { AgentSchema } from "@stigmer/protos/ai/stigmer/agentic/agent/v1/api_pb";
43
39
  import { AgentExecutionSchema } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/api_pb";
44
40
  import { ExecutionPhase } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/enum_pb";
45
- import { AgentInstanceSchema } from "@stigmer/protos/ai/stigmer/agentic/agentinstance/v1/api_pb";
46
- import { AgentInstanceQueryController } from "@stigmer/protos/ai/stigmer/agentic/agentinstance/v1/query_pb";
47
41
  import { SessionCommandController } from "@stigmer/protos/ai/stigmer/agentic/session/v1/command_pb";
48
42
  import { SessionQueryController } from "@stigmer/protos/ai/stigmer/agentic/session/v1/query_pb";
49
43
  import { SessionSchema } from "@stigmer/protos/ai/stigmer/agentic/session/v1/api_pb";
@@ -53,7 +47,6 @@ import {
53
47
  ExecutionTarget,
54
48
  Harness,
55
49
  } from "@stigmer/protos/ai/stigmer/agentic/session/v1/enum_pb";
56
- import { ApiResourceVisibility } from "@stigmer/protos/ai/stigmer/commons/apiresource/enum_pb";
57
50
  import { ApiResourceKind } from "@stigmer/protos/ai/stigmer/commons/apiresource/apiresourcekind/api_resource_kind_pb";
58
51
 
59
52
  import { loadConfig } from "../../../boot/config.js";
@@ -70,10 +63,6 @@ import {
70
63
  ROUTING_GLOBAL,
71
64
  newConfigFromEnv,
72
65
  } from "../../agentexecution/temporal/config.js";
73
- import {
74
- DEFAULT_AGENT_LABEL,
75
- DEFAULT_AGENT_LABEL_VALUE,
76
- } from "../../agent/defaultagent.js";
77
66
  import { newValidateExecutionTargetImmutabilityStep } from "../steps.js";
78
67
 
79
68
  const silentLogger = createLogger({
@@ -92,7 +81,6 @@ let dir: string;
92
81
  let server: ComposedServer;
93
82
  let transport: Transport;
94
83
  let agentCommand: Client<typeof AgentCommandController>;
95
- let instanceQuery: Client<typeof AgentInstanceQueryController>;
96
84
  let command: Client<typeof SessionCommandController>;
97
85
  let query: Client<typeof SessionQueryController>;
98
86
 
@@ -120,7 +108,6 @@ beforeAll(async () => {
120
108
  const port = await server.start();
121
109
  transport = createGrpcTransport({ baseUrl: `http://127.0.0.1:${port}` });
122
110
  agentCommand = createClient(AgentCommandController, transport);
123
- instanceQuery = createClient(AgentInstanceQueryController, transport);
124
111
  command = createClient(SessionCommandController, transport);
125
112
  query = createClient(SessionQueryController, transport);
126
113
  });
@@ -141,33 +128,6 @@ async function createAgent(name: string) {
141
128
  });
142
129
  }
143
130
 
144
- /**
145
- * Stamps the default-agent label (and optionally visibility_public)
146
- * directly on the stored agent row — the reserved stigmer.ai/* label is
147
- * operator-seeded state, not something the OSS write path guards, and the
148
- * direct write keeps the test independent of create-time visibility rules.
149
- */
150
- async function markDefaultAgent(
151
- agentId: string,
152
- opts: { public: boolean },
153
- ): Promise<void> {
154
- const stored = await server.store.getResource(
155
- ApiResourceKind.agent,
156
- agentId,
157
- AgentSchema,
158
- );
159
- stored.metadata!.labels[DEFAULT_AGENT_LABEL] = DEFAULT_AGENT_LABEL_VALUE;
160
- if (opts.public) {
161
- stored.metadata!.visibility = ApiResourceVisibility.visibility_public;
162
- }
163
- await server.store.saveResource(
164
- ApiResourceKind.agent,
165
- agentId,
166
- AgentSchema,
167
- stored,
168
- );
169
- }
170
-
171
131
  let sessionCounter = 0;
172
132
  async function createSession(
173
133
  spec: Partial<Omit<SessionSpec, "$typeName">> = {},
@@ -252,108 +212,36 @@ async function grpcError(run: () => Promise<unknown>): Promise<ConnectError> {
252
212
  }
253
213
  }
254
214
 
255
- // The resolve tests run FIRST: the not-configured arm requires that no
256
- // agent carries the default-agent label yet, and later tests only create
257
- // unlabeled agents (or clean their labeled ones up).
258
- describe("session create — ResolveDefaultAgentInstance", () => {
259
- it("rejects a create with no default agent configured (exact NotFound copy, Go's double wrap)", async () => {
260
- const error = await grpcError(() => createSession({}));
261
- expect(error.code).toBe(Code.NotFound);
262
- expect(error.rawMessage).toBe(
263
- "No default agent available. Ensure an agent with label " +
264
- "stigmer.ai/default-agent=true and visibility_public exists: " +
265
- "no default agent available on this platform: " +
266
- "no agent labeled stigmer.ai/default-agent=true",
267
- );
215
+ describe("session create and update — the built-in assistant", () => {
216
+ it("stores an empty agent_instance_id as given: no agent is resolved for the session", async () => {
217
+ const session = await createSession({});
218
+ expect(session.spec?.agentInstanceId).toBe("");
219
+ const fetched = await query.get({ value: session.metadata!.id });
220
+ expect(fetched.spec?.agentInstanceId).toBe("");
221
+ await command.delete({ value: session.metadata!.id });
268
222
  });
269
223
 
270
- it("rejects when the labeled default agent is not visibility_public (exact FailedPrecondition copy)", async () => {
271
- const agent = await createAgent("Non Public Default Agent");
272
- await markDefaultAgent(agent.metadata!.id, { public: false });
273
- try {
274
- const error = await grpcError(() => createSession({}));
275
- expect(error.code).toBe(Code.FailedPrecondition);
276
- expect(error.rawMessage).toBe(
277
- "Default agent exists but is not visibility_public: " +
278
- "agents labeled stigmer.ai/default-agent=true exist but none is visibility_public",
279
- );
280
- } finally {
281
- await agentCommand.delete({ value: agent.metadata!.id });
282
- }
224
+ it("keeps an explicit agent_instance_id as given", async () => {
225
+ const session = await createSession({ agentInstanceId: "ain_explicit" });
226
+ expect(session.spec?.agentInstanceId).toBe("ain_explicit");
227
+ await command.delete({ value: session.metadata!.id });
283
228
  });
284
229
 
285
- it("fills the persisted session's agent_instance_id from the default agent's existing default instance", async () => {
286
- const agent = await createAgent("Configured Default Agent");
287
- const defaultInstanceId = agent.status!.defaultInstanceId;
288
- expect(defaultInstanceId).not.toBe("");
289
- await markDefaultAgent(agent.metadata!.id, { public: true });
290
- try {
291
- const session = await createSession({});
292
- // The resolve step wrote newState.spec (the clone Persist saves) —
293
- // the id survives the round trip to storage.
294
- expect(session.spec?.agentInstanceId).toBe(defaultInstanceId);
295
- const fetched = await query.get({ value: session.metadata!.id });
296
- expect(fetched.spec?.agentInstanceId).toBe(defaultInstanceId);
297
- await command.delete({ value: session.metadata!.id });
298
- } finally {
299
- await agentCommand.delete({ value: agent.metadata!.id });
300
- }
301
- });
230
+ it("lets a conversation gain an agent and drop back to the assistant on update", async () => {
231
+ const session = await createSession({});
302
232
 
303
- it("creates the default instance on the fly and writes the agent's status.default_instance_id", async () => {
304
- // Seeded directly: a labeled public agent with NO default instance —
305
- // the legacy shape the self-heal path exists for.
306
- const agentId = "agt_sessiontest_selfheal";
307
- const seeded = create(AgentSchema, {
308
- apiVersion: API_VERSION,
309
- kind: "Agent",
310
- metadata: {
311
- id: agentId,
312
- name: "Self Heal Default Agent",
313
- slug: "self-heal-default-agent",
314
- org: ORG,
315
- visibility: ApiResourceVisibility.visibility_public,
316
- labels: { [DEFAULT_AGENT_LABEL]: DEFAULT_AGENT_LABEL_VALUE },
317
- },
318
- spec: { instructions: "seeded for the self-heal path" },
319
- });
320
- await server.store.saveResource(
321
- ApiResourceKind.agent,
322
- agentId,
323
- AgentSchema,
324
- seeded,
233
+ const withAgent = await command.update(
234
+ updateInput(session, { agentInstanceId: "ain_picked" }),
325
235
  );
326
- try {
327
- const session = await createSession({});
328
- const resolvedId = session.spec?.agentInstanceId ?? "";
329
- expect(resolvedId).not.toBe("");
330
-
331
- // The created instance is real (rode the in-process CREATE edge and
332
- // its full pipeline) and follows the defaultinstance factory shape.
333
- const instance = await instanceQuery.get({ value: resolvedId });
334
- expect(instance.spec?.agentId).toBe(agentId);
335
- expect(instance.metadata?.slug).toBe("self-heal-default-agent-default");
336
-
337
- // The agent's server-owned pointer was persisted (explicit agent
338
- // kind — the pipeline's own ctx kind is session).
339
- const storedAgent = await server.store.getResource(
340
- ApiResourceKind.agent,
341
- agentId,
342
- AgentSchema,
343
- );
344
- expect(storedAgent.status?.defaultInstanceId).toBe(resolvedId);
236
+ expect(withAgent.spec?.agentInstanceId).toBe("ain_picked");
345
237
 
346
- await command.delete({ value: session.metadata!.id });
347
- } finally {
348
- await agentCommand.delete({ value: agentId });
349
- }
350
- });
238
+ const dropped = await command.update(
239
+ updateInput(withAgent, { agentInstanceId: "" }),
240
+ );
241
+ expect(dropped.spec?.agentInstanceId).toBe("");
242
+ const fetched = await query.get({ value: session.metadata!.id });
243
+ expect(fetched.spec?.agentInstanceId).toBe("");
351
244
 
352
- it("is a no-op when agent_instance_id is provided (no default agent needed)", async () => {
353
- // No labeled agent exists at this point; an explicit id must not
354
- // trigger resolution.
355
- const session = await createSession({ agentInstanceId: "ain_explicit" });
356
- expect(session.spec?.agentInstanceId).toBe("ain_explicit");
357
245
  await command.delete({ value: session.metadata!.id });
358
246
  });
359
247
  });
@@ -716,67 +604,3 @@ describe("session delete — active-execution guard and cascade", () => {
716
604
  await command.delete({ value: survivor.metadata!.id });
717
605
  });
718
606
  });
719
-
720
- describe("session create — CreateAsSystem failure wire contract (oss#852)", () => {
721
- it("answers the inner code with Go's %w-wrapped transport-formatted message", async () => {
722
- // A labeled public default agent with NO status.default_instance_id
723
- // (the self-heal shape) whose deterministic default-instance slug is
724
- // already occupied: the in-process CreateAsSystem hits CheckDuplicate's
725
- // AlreadyExists. Go wraps that error with fmt.Errorf("%w"), so the
726
- // wire message embeds grpc-go's `rpc error: code = X desc = ...`
727
- // rendering of the inner error — the leak filed as stigmer/stigmer#852,
728
- // mirrored byte-for-byte until the both-editions post-cutover fix.
729
- const agentId = "agt_wrap_session";
730
- const seeded = create(AgentSchema, {
731
- apiVersion: API_VERSION,
732
- kind: "Agent",
733
- metadata: {
734
- id: agentId,
735
- name: "Wrap Mirror Default Agent",
736
- slug: "wrap-mirror-default-agent",
737
- org: ORG,
738
- visibility: ApiResourceVisibility.visibility_public,
739
- labels: { [DEFAULT_AGENT_LABEL]: DEFAULT_AGENT_LABEL_VALUE },
740
- },
741
- spec: { instructions: "seeded for the wrapped-error mirror test" },
742
- });
743
- await server.store.saveResource(
744
- ApiResourceKind.agent,
745
- agentId,
746
- AgentSchema,
747
- seeded,
748
- );
749
- const occupier = create(AgentInstanceSchema, {
750
- apiVersion: API_VERSION,
751
- kind: "AgentInstance",
752
- metadata: {
753
- id: "ain_wrap_occupied",
754
- name: "wrap-mirror-default-agent-default",
755
- slug: "wrap-mirror-default-agent-default",
756
- org: ORG,
757
- },
758
- spec: { agentId },
759
- });
760
- await server.store.saveResource(
761
- ApiResourceKind.agent_instance,
762
- "ain_wrap_occupied",
763
- AgentInstanceSchema,
764
- occupier,
765
- );
766
-
767
- try {
768
- const error = await grpcError(() => createSession({}));
769
- expect(error.code).toBe(Code.AlreadyExists);
770
- expect(error.rawMessage).toBe(
771
- "failed to create default instance for default agent: rpc error: " +
772
- "code = AlreadyExists desc = AgentInstance already exists: slug " +
773
- "'wrap-mirror-default-agent-default' in org 'acme' " +
774
- "(id: ain_wrap_occupied)",
775
- );
776
- } finally {
777
- // The cascade sweeps the occupying instance (spec.agent_id match)
778
- // and removes the default-agent label with the agent.
779
- await agentCommand.delete({ value: agentId });
780
- }
781
- });
782
- });
@@ -110,11 +110,9 @@ import {
110
110
  newListAllSessionsStep,
111
111
  newRecordHarnessStateHistoryStep,
112
112
  newRejectDeleteWithActiveExecutionsStep,
113
- newResolveDefaultAgentInstanceStep,
114
113
  newValidateExecutionTargetImmutabilityStep,
115
114
  newValidateHarnessImmutabilityStep,
116
115
  } from "./steps.js";
117
- import type { AgentInstanceCreatorProvider } from "./steps.js";
118
116
 
119
117
  export interface SessionControllerDeps {
120
118
  readonly store: Store;
@@ -129,12 +127,6 @@ export interface SessionControllerDeps {
129
127
  * same deployment default dispatch uses (oss#397).
130
128
  */
131
129
  readonly temporalConfig: AgentExecutionTemporalConfig;
132
- /**
133
- * The agentinstance in-process CREATE edge — a lazy provider because the
134
- * routes↔clients definition cycle resolves at request time (the ratified
135
- * DI story, DD-002).
136
- */
137
- readonly agentInstanceCreator: AgentInstanceCreatorProvider;
138
130
  /** The composed slot registrations — this domain's create slot (O4). */
139
131
  readonly gateSteps: ResolvedGateSteps;
140
132
  /**
@@ -177,23 +169,19 @@ function kindOf(ctx: HandlerContext): ApiResourceKind {
177
169
  }
178
170
 
179
171
  /**
180
- * Create — chain per Go buildCreatePipeline. ResolveDefaultAgentInstance
181
- * runs BEFORE ValidateProto: when agent_instance_id is omitted, the
182
- * resolution fills it in before validation sees the spec.
183
- *
184
- * AuthorizeRunTarget (the run gate, P1 sp.run-gate) follows it directly:
185
- * the first step after the instance the session binds to is known, so a
186
- * caller who may not run that instance is refused before validation reads
187
- * anything further and before any step the chain owns side-effects. The
188
- * default-instance creation INSIDE the resolution step still precedes it —
189
- * the inherited pre-gate side effect recorded below, unchanged here.
172
+ * Create — chain per Go buildCreatePipeline. AuthorizeRunTarget (the run
173
+ * gate, P1 sp.run-gate) runs right after Authorize: the instance the
174
+ * session binds to is the caller's own spec, so a caller who may not run
175
+ * that instance is refused before validation reads anything further and
176
+ * before any step the chain owns side-effects. An empty agent_instance_id
177
+ * is the built-in assistant, for which the gate makes no target check:
178
+ * Authorize's can_create_session on the organization already admitted the
179
+ * conversation (sessionRunTarget's header).
190
180
  *
191
181
  * The pre-side-effect gate slot splices before Persist, after the last
192
182
  * pure step (O4 plan-gate ruling Q2, mirroring the Java baseline's
193
- * post-resolution gate position). The default-instance resolution above
194
- * it side-effects PRE-gate in BOTH editions — a gate refusal can leave a
195
- * created default instance behind; inherited Java semantics, not a new
196
- * compromise.
183
+ * post-resolution gate position). Every step above it is pure, so a gate
184
+ * refusal leaves nothing behind.
197
185
  */
198
186
  async function createSession(
199
187
  deps: SessionControllerDeps,
@@ -213,14 +201,6 @@ async function createSession(
213
201
  .addStep(
214
202
  newAuthorizeStep(SessionCommandController.method.create, deps.authorizer),
215
203
  )
216
- .addStep(
217
- newResolveDefaultAgentInstanceStep(
218
- deps.store,
219
- deps.agentInstanceCreator,
220
- deps.logger,
221
- deps.authorizationLifecycle,
222
- ),
223
- )
224
204
  .addStep(newAuthorizeRunTargetStep(deps.authorizer, sessionRunTarget))
225
205
  .addStep(newValidateProtoStep())
226
206
  .addStep(newValidateVisibilityStep())
@@ -1,13 +1,14 @@
1
1
  /**
2
- * The session run-target resolver (P1 sp.run-gate): a session is a
3
- * conversation bound to ONE agent instance, so its run target is that
4
- * instance — agent_instance#can_execute on spec.agent_instance_id.
2
+ * The session run-target resolver (P1 sp.run-gate): a session bound to an
3
+ * agent instance has that instance as its run target —
4
+ * agent_instance#can_execute on spec.agent_instance_id.
5
5
  *
6
- * Pure over the record being built. ResolveDefaultAgentInstance runs before
7
- * the gate and guarantees the id (the caller's, or the platform default
8
- * agent's default instance), so an empty id here is that step's own
9
- * refusal already thrown, never a check to make. Read from newState, where
10
- * the resolution writes — the same clone gotcha steps.ts records.
6
+ * Pure over the record being built. An empty id is the built-in assistant
7
+ * (session/v1/spec.proto): there is no blueprint to spend, so the answer is
8
+ * "no target" and the gate makes no check. What admits the conversation is
9
+ * the Authorize step ahead of the gate — can_create_session on the
10
+ * organization — and each turn is admitted by the session's own
11
+ * can_create_execution_in on the execution chain.
11
12
  */
12
13
  import type { Session } from "@stigmer/protos/ai/stigmer/agentic/session/v1/api_pb";
13
14