@hachej/boring-agent 0.1.99 → 0.1.101

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.
@@ -603,7 +603,7 @@ var PiSessionStore = class {
603
603
  sessionDir;
604
604
  allowLegacyUnscopedAccess;
605
605
  pathDerivedLegacyAccess;
606
- trustedNativeRuntimeScopeIdentity;
606
+ allowUnscopedNativeAccess;
607
607
  prefixCache = /* @__PURE__ */ new Map();
608
608
  listInFlight = /* @__PURE__ */ new Map();
609
609
  writerTails = /* @__PURE__ */ new Map();
@@ -613,25 +613,25 @@ var PiSessionStore = class {
613
613
  this.sessionDir = options;
614
614
  this.allowLegacyUnscopedAccess = true;
615
615
  this.pathDerivedLegacyAccess = false;
616
- this.trustedNativeRuntimeScopeIdentity = void 0;
616
+ this.allowUnscopedNativeAccess = false;
617
617
  return;
618
618
  }
619
619
  this.allowLegacyUnscopedAccess = true;
620
620
  this.pathDerivedLegacyAccess = options?.sessionDir === void 0 && options?.sessionNamespace === void 0;
621
- this.trustedNativeRuntimeScopeIdentity = options?.trustedNativeRuntimeScopeIdentity?.trim() || void 0;
621
+ this.allowUnscopedNativeAccess = options?.allowUnscopedNativeAccess === true;
622
622
  this.sessionDir = options?.sessionDir ?? (options?.sessionNamespace ? sessionDirForNamespace(options.sessionNamespace, options.sessionRoot) : defaultSessionDir(options?.storageCwd ?? cwd, options?.sessionRoot));
623
623
  }
624
624
  getSessionDir() {
625
625
  return this.sessionDir;
626
626
  }
627
- /** Reads the Host execution pin from authoritative session metadata. */
628
- async readRuntimeScopeIdentity(ctx, sessionId) {
629
- const filepath = await this.resolveSessionFile(sessionId, ctx);
630
- const entries = parseJsonlPrefixEntries2(await readJsonlPrefix2(filepath));
631
- const header = entries.find((entry) => entry.type === "session");
632
- const directNative = isTimestampNamedPiSessionFile(filepath, header?.id ?? sessionId);
633
- if (!this.headerBelongsToCtx(header, ctx, directNative)) throw new Error(`Session not found: ${sessionId}`);
634
- return readHeaderRuntimeScopeIdentity(header);
627
+ async has(ctx, sessionId) {
628
+ try {
629
+ await this.resolveSessionFile(sessionId, ctx);
630
+ return true;
631
+ } catch (error) {
632
+ if (error instanceof Error && error.message === `Session not found: ${sessionId}`) return false;
633
+ throw error;
634
+ }
635
635
  }
636
636
  async list(ctx, options) {
637
637
  const normalizedOptions = normalizeListOptions(options);
@@ -999,7 +999,7 @@ var PiSessionStore = class {
999
999
  if (ctx) await this.assertFileBelongsToCtx(matchedPath, ctx, sessionId);
1000
1000
  return matchedPath;
1001
1001
  }
1002
- if (ctx && (this.pathDerivedLegacyAccess || this.hasTrustedNativeRuntimeCapability(ctx) || await this.nativeFilePin(matchedPath) !== null)) {
1002
+ if (ctx && (this.pathDerivedLegacyAccess || this.allowUnscopedNativeAccess || await this.nativeFilePin(matchedPath) !== null)) {
1003
1003
  await this.assertFileBelongsToCtx(matchedPath, ctx, sessionId);
1004
1004
  return matchedPath;
1005
1005
  }
@@ -1284,22 +1284,16 @@ var PiSessionStore = class {
1284
1284
  }
1285
1285
  /**
1286
1286
  * A bare Pi transcript carries no tenancy, so only a path-derived trusted
1287
- * local store may reach it. Boring-created native transcripts carry an exact
1288
- * persisted tenancy/runtime pin and remain reachable by hosted/namespaced
1289
- * stores without minting a compatibility wrapper.
1287
+ * local store may reach it. Boring-created native transcripts carry exact
1288
+ * persisted tenancy and remain reachable by hosted/namespaced stores without
1289
+ * minting a compatibility wrapper.
1290
1290
  */
1291
1291
  nativeFileBelongsToCtx(header, ctx) {
1292
1292
  const pinned = readHeaderSessionCtx(header);
1293
- if (pinned === null && this.hasTrustedNativeRuntimeCapability(ctx)) return true;
1293
+ if (pinned === null && this.allowUnscopedNativeAccess) return true;
1294
1294
  if (this.pathDerivedLegacyAccess) return this.storedCtxBelongsToCtx(pinned, ctx);
1295
1295
  return pinned !== null && sameSessionCtx(pinned, ctx);
1296
1296
  }
1297
- hasTrustedNativeRuntimeCapability(ctx) {
1298
- const runtimeScopeIdentity = ctx.runtimeScopeIdentity?.trim();
1299
- return Boolean(
1300
- runtimeScopeIdentity && this.trustedNativeRuntimeScopeIdentity && runtimeScopeIdentity === this.trustedNativeRuntimeScopeIdentity
1301
- );
1302
- }
1303
1297
  /** The Boring tenancy pin on a native transcript, or null when unpinned. */
1304
1298
  async nativeFilePin(filepath) {
1305
1299
  try {
@@ -1368,19 +1362,11 @@ function readHeaderSessionCtx(header) {
1368
1362
  if (!raw || typeof raw !== "object") return {};
1369
1363
  return normalizeSessionCtx(raw) ?? {};
1370
1364
  }
1371
- function readHeaderRuntimeScopeIdentity(header) {
1372
- const raw = header?.boringSessionCtx?.runtimeScopeIdentity;
1373
- if (raw === void 0) return void 0;
1374
- if (typeof raw !== "string" || !raw.trim()) throw new Error("Session runtime scope identity is invalid");
1375
- return raw;
1376
- }
1377
1365
  function normalizeSessionCtx(ctx) {
1378
- const runtimeScopeIdentity = typeof ctx?.runtimeScopeIdentity === "string" && ctx.runtimeScopeIdentity.trim() ? ctx.runtimeScopeIdentity : "";
1379
- if (!ctx?.workspaceId && !ctx?.userId && !runtimeScopeIdentity) return void 0;
1366
+ if (!ctx?.workspaceId && !ctx?.userId) return void 0;
1380
1367
  return {
1381
- ...ctx?.workspaceId ? { workspaceId: ctx.workspaceId } : {},
1382
- ...ctx?.userId ? { userId: ctx.userId } : {},
1383
- ...runtimeScopeIdentity ? { runtimeScopeIdentity } : {}
1368
+ ...ctx.workspaceId ? { workspaceId: ctx.workspaceId } : {},
1369
+ ...ctx.userId ? { userId: ctx.userId } : {}
1384
1370
  };
1385
1371
  }
1386
1372
  function sameSessionCtx(a, b) {
@@ -1928,14 +1914,11 @@ function sessionCtxFromRunContext(ctx) {
1928
1914
  return normalizeSessionCtx2(ctx.sessionCtx ?? { workspaceId: ctx.workspaceId }) ?? {};
1929
1915
  }
1930
1916
  function normalizeSessionCtx2(ctx) {
1931
- if (!ctx?.workspaceId && !ctx?.runtimeScopeIdentity) return void 0;
1932
- return {
1933
- ...ctx.workspaceId ? { workspaceId: ctx.workspaceId } : {},
1934
- ...ctx.runtimeScopeIdentity ? { runtimeScopeIdentity: ctx.runtimeScopeIdentity } : {}
1935
- };
1917
+ if (!ctx?.workspaceId) return void 0;
1918
+ return { workspaceId: ctx.workspaceId };
1936
1919
  }
1937
1920
  function sessionCacheKey(sessionId, ctx) {
1938
- return JSON.stringify([sessionId, ctx.workspaceId ?? "", ctx.runtimeScopeIdentity ?? ""]);
1921
+ return JSON.stringify([sessionId, ctx.workspaceId ?? ""]);
1939
1922
  }
1940
1923
  async function applyRequestedSessionOptions(handle, input, options = {}) {
1941
1924
  const requestedModel = resolveRequestedModel(handle.modelRegistry, input, { strict: options.strictModelResolution });
@@ -47,7 +47,6 @@ var AgentGatewayErrorCode = {
47
47
  AGENT_REQUEST_OUTCOME_UNKNOWN: "AGENT_REQUEST_OUTCOME_UNKNOWN",
48
48
  AGENT_RUNTIME_RESTART_REQUIRED: "AGENT_RUNTIME_RESTART_REQUIRED",
49
49
  AGENT_COMMAND_INVALID_STATE: "AGENT_COMMAND_INVALID_STATE",
50
- AGENT_SESSION_RUNTIME_SCOPE_MISMATCH: "AGENT_SESSION_RUNTIME_SCOPE_MISMATCH",
51
50
  AGENT_SHARED_ENVIRONMENT_UNAVAILABLE: "AGENT_SHARED_ENVIRONMENT_UNAVAILABLE",
52
51
  AGENT_GATEWAY_CLOSED: "AGENT_GATEWAY_CLOSED"
53
52
  };
@@ -64,7 +63,6 @@ var AGENT_GATEWAY_ERROR_CODES = [
64
63
  AgentGatewayErrorCode.AGENT_REQUEST_OUTCOME_UNKNOWN,
65
64
  AgentGatewayErrorCode.AGENT_RUNTIME_RESTART_REQUIRED,
66
65
  AgentGatewayErrorCode.AGENT_COMMAND_INVALID_STATE,
67
- AgentGatewayErrorCode.AGENT_SESSION_RUNTIME_SCOPE_MISMATCH,
68
66
  AgentGatewayErrorCode.AGENT_SHARED_ENVIRONMENT_UNAVAILABLE,
69
67
  AgentGatewayErrorCode.AGENT_GATEWAY_CLOSED
70
68
  ];
@@ -7,7 +7,7 @@ import {
7
7
  readConfiguredDefaultModel,
8
8
  registerConfiguredModelProviders,
9
9
  withPiHarnessDefaults
10
- } from "./chunk-GRMDMWBW.js";
10
+ } from "./chunk-T37OVD6L.js";
11
11
  import {
12
12
  AGENT_KNOWLEDGE_FILESYSTEM_ID,
13
13
  AgentDefinitionValidationError,
@@ -41,7 +41,7 @@ import {
41
41
  AgentGatewayErrorCode,
42
42
  extractToolUiMetadata,
43
43
  sanitizeToolUiMetadata2 as sanitizeToolUiMetadata
44
- } from "./chunk-LSO2AO6Q.js";
44
+ } from "./chunk-XCZBICZS.js";
45
45
  import {
46
46
  AgentDefinitionErrorCode,
47
47
  AgentDeploymentErrorCode,
@@ -7334,11 +7334,7 @@ function toSessionCtx(ctx) {
7334
7334
  if (ctx.sessionAuthority !== "workspace-scope") {
7335
7335
  return { workspaceId: ctx.workspaceId, userId: ctx.authSubject };
7336
7336
  }
7337
- const sessionCtx = { workspaceId: ctx.storageScope ?? ctx.workspaceId };
7338
- if (ctx.runtimeScopeIdentity) {
7339
- Object.assign(sessionCtx, { runtimeScopeIdentity: ctx.runtimeScopeIdentity });
7340
- }
7341
- return sessionCtx;
7337
+ return { workspaceId: ctx.storageScope ?? ctx.workspaceId };
7342
7338
  }
7343
7339
  function liveAttachmentKey(sessionId, messageId, index) {
7344
7340
  return `${JSON.stringify(sessionId)}:${JSON.stringify(messageId)}:${index}`;
@@ -7732,18 +7728,7 @@ var AgentSessionInventory = class {
7732
7728
  async resolveSessionRuntime(agentTypeId, scope, claim, sessionId) {
7733
7729
  const resolved = await this.resolveStore(agentTypeId, scope, claim);
7734
7730
  if (!resolved) return void 0;
7735
- try {
7736
- return {
7737
- runtimeScope: resolved.runtimeScope,
7738
- runtimeScopeIdentity: await resolved.store.readRuntimeScopeIdentity(
7739
- { workspaceId: claim.workspaceScopeId },
7740
- sessionId
7741
- )
7742
- };
7743
- } catch (error) {
7744
- if (error instanceof Error && error.message === `Session not found: ${sessionId}`) return void 0;
7745
- throw error;
7746
- }
7731
+ return await resolved.store.has({ workspaceId: claim.workspaceScopeId }, sessionId) ? resolved.runtimeScope : void 0;
7747
7732
  }
7748
7733
  async resolveStore(agentTypeId, scope, claim) {
7749
7734
  const agent = this.compiledById.get(agentTypeId);
@@ -7931,7 +7916,7 @@ async function buildAgentComposition(input) {
7931
7916
  sessionNamespace: configuredNamespace,
7932
7917
  sessionDir: runtimeScope.sessionDir ?? factoryInput.sessionDir
7933
7918
  }) : async (factoryInput) => {
7934
- const { createPiCodingAgentHarness } = await import("./createHarness-5TEXLUYX.js");
7919
+ const { createPiCodingAgentHarness } = await import("./createHarness-7C2A5UVH.js");
7935
7920
  return createPiCodingAgentHarness({
7936
7921
  ...factoryInput,
7937
7922
  pi,
@@ -7973,7 +7958,6 @@ async function buildAgentComposition(input) {
7973
7958
  tools,
7974
7959
  runtimeBundle,
7975
7960
  readyTracker,
7976
- runtimeScopeIdentity: runtimeScope.identity,
7977
7961
  dispose() {
7978
7962
  disposed ??= service.dispose().finally(() => durableEventStore?.close());
7979
7963
  return disposed;
@@ -8059,13 +8043,12 @@ function gatewayError(dto) {
8059
8043
  function sessionTarget(ref) {
8060
8044
  return { kind: "session", ref };
8061
8045
  }
8062
- function context(claim, requestId, runtimeScopeIdentity) {
8046
+ function context(claim, requestId) {
8063
8047
  return {
8064
8048
  workspaceId: claim.workspaceScopeId,
8065
8049
  storageScope: claim.workspaceScopeId,
8066
8050
  authSubject: claim.authSubjectId,
8067
8051
  sessionAuthority: "workspace-scope",
8068
- ...runtimeScopeIdentity ? { runtimeScopeIdentity } : {},
8069
8052
  requestId
8070
8053
  };
8071
8054
  }
@@ -8094,10 +8077,8 @@ var EmbeddedAgentGateway = class {
8094
8077
  runtime;
8095
8078
  cursorSecret = randomUUID2();
8096
8079
  connections = /* @__PURE__ */ new Set();
8097
- pins = /* @__PURE__ */ new Map();
8098
- unpinnedSessionFallbackPins = /* @__PURE__ */ new Set();
8099
8080
  writerTails = /* @__PURE__ */ new Map();
8100
- sessionRuntimeResolutionObserver;
8081
+ knownSessions = /* @__PURE__ */ new Set();
8101
8082
  closed = false;
8102
8083
  /** Host-owned addressed runtime-capability effect seam. */
8103
8084
  async runHostEffect(input) {
@@ -8132,29 +8113,36 @@ var EmbeddedAgentGateway = class {
8132
8113
  const binding = await this.bindingForSession(scope, claim, ref);
8133
8114
  return { claim, binding };
8134
8115
  }
8135
- /** Side-effect-free reload lookup: validates persisted existence/pin and requires an already-published binding. */
8116
+ /** Side-effect-free reload lookup: validates session access and requires the current binding to be published. */
8136
8117
  async inspectPublishedSessionBinding(scope, ref) {
8137
8118
  const claim = await this.verify(scope);
8138
8119
  if (!this.runtime.compiledById.has(ref.agentTypeId)) {
8139
8120
  throw new AgentGatewayError(AgentGatewayErrorCode.AGENT_SESSION_NOT_FOUND, "session was not found");
8140
8121
  }
8141
- const authority = await this.runtime.resolveSessionRuntime(
8122
+ const sessionKey = agentSessionKey(claim.workspaceScopeId, ref);
8123
+ const persistedRuntime = await this.runtime.resolveSessionRuntime(
8142
8124
  ref.agentTypeId,
8143
8125
  scope,
8144
8126
  claim,
8145
8127
  ref.sessionId
8146
8128
  );
8147
- const cached = this.pins.get(agentSessionKey(claim.workspaceScopeId, ref));
8148
- if (!authority && !cached) {
8129
+ if (!persistedRuntime && !this.knownSessions.has(sessionKey)) {
8149
8130
  throw new AgentGatewayError(AgentGatewayErrorCode.AGENT_SESSION_NOT_FOUND, "session was not found");
8150
8131
  }
8151
- const runtimeScopeIdentity = authority?.runtimeScopeIdentity ?? cached ?? authority?.runtimeScope.identity;
8152
- const binding = this.runtime.findPublishedBinding(
8132
+ const resolved = persistedRuntime ?? await this.runtime.resolveAgentRuntimeScope(
8133
+ ref.agentTypeId,
8134
+ scope,
8135
+ claim,
8136
+ "existing-session",
8137
+ `session:${ref.sessionId}`,
8138
+ ref.sessionId
8139
+ );
8140
+ const binding = this.runtime.findPublishedCurrentBinding(
8153
8141
  ref.agentTypeId,
8154
8142
  claim.workspaceScopeId,
8155
- runtimeScopeIdentity,
8156
- authority?.runtimeScope.physicalBindingIdentity ?? authority?.runtimeScope.identity,
8157
- authority?.runtimeScope.environment.provisioningFingerprint
8143
+ resolved.physicalBindingIdentity ?? resolved.identity,
8144
+ resolved.identity,
8145
+ resolved.environment.provisioningFingerprint
8158
8146
  );
8159
8147
  if (!binding) {
8160
8148
  throw new AgentGatewayError(
@@ -8164,10 +8152,6 @@ var EmbeddedAgentGateway = class {
8164
8152
  }
8165
8153
  return { claim, binding };
8166
8154
  }
8167
- /** Server-only test observer for distinguishing runtime pin resolution paths. */
8168
- setSessionRuntimeResolutionObserverForTesting(observer) {
8169
- this.sessionRuntimeResolutionObserver = observer;
8170
- }
8171
8155
  /** Test-only activity seam used by the shared implementation conformance. */
8172
8156
  setActivityForTesting(workspaceScopeId, ref, activity) {
8173
8157
  this.runtime.activity.set(workspaceScopeId, ref, activity);
@@ -8234,31 +8218,31 @@ var EmbeddedAgentGateway = class {
8234
8218
  return await this.runtime.runBindingOperation(preparedBinding.key, async () => {
8235
8219
  if (input.resumeSessionId) {
8236
8220
  const candidateRef = { agentTypeId: input.agentTypeId, sessionId: input.resumeSessionId };
8237
- const authority = await this.runtime.resolveSessionRuntime(
8221
+ const resolved = await this.runtime.resolveSessionRuntime(
8238
8222
  input.agentTypeId,
8239
8223
  input.scope,
8240
8224
  claim,
8241
8225
  input.resumeSessionId
8242
8226
  ).catch(() => void 0);
8243
- if (authority?.runtimeScopeIdentity === preparedBinding.scope.identity) {
8227
+ if (resolved) {
8244
8228
  const rows = await preparedBinding.composition.service.listSessions?.(
8245
- context(claim, input.requestId, preparedBinding.scope.identity),
8229
+ context(claim, input.requestId),
8246
8230
  { includeId: input.resumeSessionId, includeEmpty: true }
8247
8231
  ) ?? [];
8248
8232
  const candidate = rows.find((row) => row.id === input.resumeSessionId);
8249
8233
  if (candidate?.turnCount === 0) {
8250
- this.pins.set(agentSessionKey(claim.workspaceScopeId, candidateRef), preparedBinding.scope.identity);
8234
+ this.knownSessions.add(agentSessionKey(claim.workspaceScopeId, candidateRef));
8251
8235
  this.runtime.activity.set(claim.workspaceScopeId, candidateRef, "idle");
8252
8236
  return candidateRef;
8253
8237
  }
8254
8238
  }
8255
8239
  }
8256
8240
  const created = await preparedBinding.composition.service.createSession(
8257
- context(claim, input.requestId, preparedBinding.scope.identity),
8241
+ context(claim, input.requestId),
8258
8242
  { title: input.title }
8259
8243
  );
8260
8244
  const ref = { agentTypeId: input.agentTypeId, sessionId: created.id };
8261
- this.pins.set(agentSessionKey(claim.workspaceScopeId, ref), preparedBinding.scope.identity);
8245
+ this.knownSessions.add(agentSessionKey(claim.workspaceScopeId, ref));
8262
8246
  this.runtime.activity.set(claim.workspaceScopeId, ref, "idle");
8263
8247
  return ref;
8264
8248
  });
@@ -8276,13 +8260,13 @@ var EmbeddedAgentGateway = class {
8276
8260
  let state;
8277
8261
  try {
8278
8262
  state = await binding.composition.service.readState(
8279
- context(claim, randomUUID2(), binding.scope.identity),
8263
+ context(claim, randomUUID2()),
8280
8264
  input.ref.sessionId
8281
8265
  );
8282
8266
  } catch {
8283
8267
  throw new AgentGatewayError(AgentGatewayErrorCode.AGENT_SESSION_NOT_FOUND, "session was not found");
8284
8268
  }
8285
- const loaded = await this.loadSummary(binding.composition.service, claim, input.ref, binding.scope.identity);
8269
+ const loaded = await this.loadSummary(binding.composition.service, claim, input.ref);
8286
8270
  const status = this.runtime.activity.get(claim.workspaceScopeId, input.ref);
8287
8271
  return {
8288
8272
  ref: input.ref,
@@ -8294,14 +8278,14 @@ var EmbeddedAgentGateway = class {
8294
8278
  async connectSession(input) {
8295
8279
  const claim = await this.verify(input.scope);
8296
8280
  const binding = await this.bindingForSession(input.scope, claim, input.ref);
8297
- await this.loadSummary(binding.composition.service, claim, input.ref, binding.scope.identity);
8281
+ await this.loadSummary(binding.composition.service, claim, input.ref);
8298
8282
  const queue = new AgentSessionEventQueue();
8299
8283
  const initialCursor = input.cursor ?? (await binding.composition.service.readState(
8300
- context(claim, randomUUID2(), binding.scope.identity),
8284
+ context(claim, randomUUID2()),
8301
8285
  input.ref.sessionId
8302
8286
  )).seq;
8303
8287
  const subscribed = await binding.composition.service.subscribe(
8304
- context(claim, randomUUID2(), binding.scope.identity),
8288
+ context(claim, randomUUID2()),
8305
8289
  input.ref.sessionId,
8306
8290
  initialCursor,
8307
8291
  (event) => {
@@ -8349,7 +8333,7 @@ var EmbeddedAgentGateway = class {
8349
8333
  const currentBinding = await this.bindingForSession(input.scope, current, input.ref);
8350
8334
  return await this.sessionEffect(input.ref, current, "session.interrupt", requestId, {}, async () => {
8351
8335
  const receipt = await currentBinding.composition.service.interrupt(
8352
- context(current, requestId, currentBinding.scope.identity),
8336
+ context(current, requestId),
8353
8337
  input.ref.sessionId,
8354
8338
  {}
8355
8339
  );
@@ -8364,7 +8348,7 @@ var EmbeddedAgentGateway = class {
8364
8348
  const currentBinding = await this.bindingForSession(input.scope, current, input.ref);
8365
8349
  return await this.sessionEffect(input.ref, current, "session.stop", requestId, {}, async () => {
8366
8350
  const receipt = await currentBinding.composition.service.stop(
8367
- context(current, requestId, currentBinding.scope.identity),
8351
+ context(current, requestId),
8368
8352
  input.ref.sessionId,
8369
8353
  {}
8370
8354
  );
@@ -8379,7 +8363,7 @@ var EmbeddedAgentGateway = class {
8379
8363
  clientNonce: clientNonce ?? null,
8380
8364
  clientSeq: clientSeq ?? null
8381
8365
  }, () => currentBinding.composition.service.clearQueue(
8382
- context(current, requestId, currentBinding.scope.identity),
8366
+ context(current, requestId),
8383
8367
  input.ref.sessionId,
8384
8368
  { ...clientNonce ? { clientNonce } : {}, ...clientSeq === void 0 ? {} : { clientSeq } }
8385
8369
  ), {
@@ -8389,7 +8373,6 @@ var EmbeddedAgentGateway = class {
8389
8373
  currentBinding.composition.service,
8390
8374
  current,
8391
8375
  input.ref,
8392
- currentBinding.scope.identity,
8393
8376
  requestId,
8394
8377
  clientNonce,
8395
8378
  clientSeq
@@ -8406,7 +8389,7 @@ var EmbeddedAgentGateway = class {
8406
8389
  const service = binding.composition.service;
8407
8390
  if (command.kind === "prompt") {
8408
8391
  return await this.sessionEffect(ref, claim, "session.prompt", command.requestId, command, async () => {
8409
- const receipt = await service.prompt(context(claim, command.requestId, binding.scope.identity), ref.sessionId, {
8392
+ const receipt = await service.prompt(context(claim, command.requestId), ref.sessionId, {
8410
8393
  message: command.content,
8411
8394
  displayMessage: command.displayContent,
8412
8395
  clientNonce: command.clientNonce,
@@ -8430,7 +8413,7 @@ var EmbeddedAgentGateway = class {
8430
8413
  });
8431
8414
  }
8432
8415
  return await this.sessionEffect(ref, claim, "session.followup", command.requestId, command, async () => {
8433
- const receipt = await service.followUp(context(claim, command.requestId, binding.scope.identity), ref.sessionId, {
8416
+ const receipt = await service.followUp(context(claim, command.requestId), ref.sessionId, {
8434
8417
  message: command.content,
8435
8418
  displayMessage: command.displayContent,
8436
8419
  clientNonce: command.clientNonce,
@@ -8464,7 +8447,7 @@ var EmbeddedAgentGateway = class {
8464
8447
  const binding = await this.bindingForSession(input.scope, claim, input.ref);
8465
8448
  await this.sessionEffect(input.ref, claim, "session.delete", input.requestId, {}, async () => {
8466
8449
  await binding.composition.service.deleteSession(
8467
- context(claim, input.requestId, binding.scope.identity),
8450
+ context(claim, input.requestId),
8468
8451
  input.ref.sessionId
8469
8452
  );
8470
8453
  this.runtime.activity.delete(claim.workspaceScopeId, input.ref);
@@ -8481,18 +8464,17 @@ var EmbeddedAgentGateway = class {
8481
8464
  if (!this.runtime.compiledById.has(ref.agentTypeId)) {
8482
8465
  throw new AgentGatewayError(AgentGatewayErrorCode.AGENT_SESSION_NOT_FOUND, "session was not found");
8483
8466
  }
8484
- const key = agentSessionKey(claim.workspaceScopeId, ref);
8485
- const authority = await this.runtime.resolveSessionRuntime(
8467
+ const sessionKey = agentSessionKey(claim.workspaceScopeId, ref);
8468
+ const persistedRuntime = await this.runtime.resolveSessionRuntime(
8486
8469
  ref.agentTypeId,
8487
8470
  scope,
8488
8471
  claim,
8489
8472
  ref.sessionId
8490
8473
  );
8491
- const cached = this.pins.get(key);
8492
- if (!authority && !cached) {
8474
+ if (!persistedRuntime && !this.knownSessions.has(sessionKey)) {
8493
8475
  throw new AgentGatewayError(AgentGatewayErrorCode.AGENT_SESSION_NOT_FOUND, "session was not found");
8494
8476
  }
8495
- const resolved = authority?.runtimeScope ?? await this.runtime.resolveAgentRuntimeScope(
8477
+ const currentRuntime = persistedRuntime ?? await this.runtime.resolveAgentRuntimeScope(
8496
8478
  ref.agentTypeId,
8497
8479
  scope,
8498
8480
  claim,
@@ -8500,45 +8482,11 @@ var EmbeddedAgentGateway = class {
8500
8482
  `session:${ref.sessionId}`,
8501
8483
  ref.sessionId
8502
8484
  );
8503
- const persistedPin = authority?.runtimeScopeIdentity;
8504
- const pinned = persistedPin ?? cached;
8505
- if (pinned && pinned !== resolved.identity) {
8506
- throw new AgentGatewayError(
8507
- AgentGatewayErrorCode.AGENT_SESSION_RUNTIME_SCOPE_MISMATCH,
8508
- "session is pinned to a different runtime scope"
8509
- );
8510
- }
8511
- const publishedPinned = pinned && typeof this.runtime.findPublishedBinding === "function" ? this.runtime.findPublishedBinding(
8512
- ref.agentTypeId,
8513
- claim.workspaceScopeId,
8514
- pinned
8515
- ) : void 0;
8516
- if (publishedPinned && !this.unpinnedSessionFallbackPins.has(key)) {
8517
- this.sessionRuntimeResolutionObserver?.({
8518
- source: persistedPin ? "persisted-runtime-pin" : "unpinned-session-fallback",
8519
- runtimeScopeIdentity: pinned
8520
- });
8521
- this.pins.set(key, pinned);
8522
- return publishedPinned;
8523
- }
8524
- const runtimeScopeIdentity = pinned ?? resolved.identity;
8525
- this.sessionRuntimeResolutionObserver?.({
8526
- source: persistedPin ? "persisted-runtime-pin" : "unpinned-session-fallback",
8527
- runtimeScopeIdentity
8528
- });
8529
- this.pins.set(key, runtimeScopeIdentity);
8530
- if (!pinned) this.unpinnedSessionFallbackPins.add(key);
8531
- return await this.runtime.resolveBinding(
8532
- ref.agentTypeId,
8533
- scope,
8534
- claim,
8535
- resolved,
8536
- pinned ? "pinned" : "current"
8537
- );
8485
+ return await this.runtime.resolveBinding(ref.agentTypeId, scope, claim, currentRuntime);
8538
8486
  }
8539
- async loadSummary(service, claim, ref, runtimeScopeIdentity) {
8487
+ async loadSummary(service, claim, ref) {
8540
8488
  const list = await service.listSessions?.(
8541
- context(claim, randomUUID2(), runtimeScopeIdentity),
8489
+ context(claim, randomUUID2()),
8542
8490
  { includeId: ref.sessionId, includeEmpty: true }
8543
8491
  ) ?? [];
8544
8492
  const summary = list.find((item) => item.id === ref.sessionId);
@@ -8758,7 +8706,7 @@ var EmbeddedAgentGateway = class {
8758
8706
  async promptAdmission(scope, claim, ref, requestId, requireIdle) {
8759
8707
  const binding = await this.bindingForSession(scope, claim, ref);
8760
8708
  const snapshot = await binding.composition.service.readState(
8761
- context(claim, requestId, binding.scope.identity),
8709
+ context(claim, requestId),
8762
8710
  ref.sessionId
8763
8711
  );
8764
8712
  const admissible = requireIdle ? snapshot.status === "idle" : snapshot.status === "idle" || snapshot.status === "error";
@@ -8769,10 +8717,10 @@ var EmbeddedAgentGateway = class {
8769
8717
  { status: snapshot.status }
8770
8718
  ).toJSON();
8771
8719
  }
8772
- async queueClearAdmission(service, claim, ref, runtimeScopeIdentity, requestId, clientNonce, clientSeq) {
8720
+ async queueClearAdmission(service, claim, ref, requestId, clientNonce, clientSeq) {
8773
8721
  if (clientNonce === void 0 || clientSeq === void 0) return void 0;
8774
8722
  const snapshot = await service.readState(
8775
- context(claim, requestId, runtimeScopeIdentity),
8723
+ context(claim, requestId),
8776
8724
  ref.sessionId
8777
8725
  );
8778
8726
  const byNonce = snapshot.queue.followUps.find((item) => item.clientNonce === clientNonce);
@@ -9596,8 +9544,7 @@ function createAgentHostRuntimeCapabilityProjection(input) {
9596
9544
  requestId: request.id,
9597
9545
  userId: claim.authSubjectId,
9598
9546
  sessionCtx: {
9599
- workspaceId: claim.workspaceScopeId,
9600
- runtimeScopeIdentity: binding.scope.identity
9547
+ workspaceId: claim.workspaceScopeId
9601
9548
  },
9602
9549
  ...typeof user?.email === "string" && user.email.trim() ? { userEmail: user.email.trim() } : {},
9603
9550
  userEmailVerified: user?.emailVerified === true
@@ -9659,8 +9606,7 @@ function createAgentHostRuntimeCapabilityProjection(input) {
9659
9606
  requestId,
9660
9607
  userId: scope.authSubjectId,
9661
9608
  sessionCtx: {
9662
- workspaceId: scope.workspaceScopeId,
9663
- runtimeScopeIdentity: binding.scope.identity
9609
+ workspaceId: scope.workspaceScopeId
9664
9610
  }
9665
9611
  });
9666
9612
  return { ok: true, sessionId, name };
@@ -9817,7 +9763,7 @@ function body(schema, request, reply) {
9817
9763
  function statusFor(error) {
9818
9764
  if (error.code === AgentGatewayErrorCode.AGENT_SCOPE_DENIED) return 403;
9819
9765
  if (error.code === AgentGatewayErrorCode.AGENT_TYPE_UNKNOWN || error.code === AgentGatewayErrorCode.AGENT_SESSION_NOT_FOUND) return 404;
9820
- if (error.code === AgentGatewayErrorCode.AGENT_REQUEST_CONFLICT || error.code === AgentGatewayErrorCode.AGENT_REQUEST_IN_PROGRESS || error.code === AgentGatewayErrorCode.AGENT_REQUEST_OUTCOME_UNKNOWN || error.code === AgentGatewayErrorCode.AGENT_RUNTIME_RESTART_REQUIRED || error.code === AgentGatewayErrorCode.AGENT_COMMAND_INVALID_STATE || error.code === AgentGatewayErrorCode.AGENT_SESSION_RUNTIME_SCOPE_MISMATCH) return 409;
9766
+ if (error.code === AgentGatewayErrorCode.AGENT_REQUEST_CONFLICT || error.code === AgentGatewayErrorCode.AGENT_REQUEST_IN_PROGRESS || error.code === AgentGatewayErrorCode.AGENT_REQUEST_OUTCOME_UNKNOWN || error.code === AgentGatewayErrorCode.AGENT_RUNTIME_RESTART_REQUIRED || error.code === AgentGatewayErrorCode.AGENT_COMMAND_INVALID_STATE) return 409;
9821
9767
  if (error.code === AgentGatewayErrorCode.AGENT_GATEWAY_CLOSED) return 503;
9822
9768
  return 400;
9823
9769
  }
@@ -10117,7 +10063,7 @@ function parseWithSchema(schema, value, reply, scope) {
10117
10063
  function statusForGatewayError(code) {
10118
10064
  if (code === AgentGatewayErrorCode.AGENT_SCOPE_DENIED) return 403;
10119
10065
  if (code === AgentGatewayErrorCode.AGENT_SESSION_NOT_FOUND || code === AgentGatewayErrorCode.AGENT_TYPE_UNKNOWN) return 404;
10120
- if (code === AgentGatewayErrorCode.AGENT_REQUEST_CONFLICT || code === AgentGatewayErrorCode.AGENT_REQUEST_IN_PROGRESS || code === AgentGatewayErrorCode.AGENT_REQUEST_OUTCOME_UNKNOWN || code === AgentGatewayErrorCode.AGENT_RUNTIME_RESTART_REQUIRED || code === AgentGatewayErrorCode.AGENT_COMMAND_INVALID_STATE || code === AgentGatewayErrorCode.AGENT_SESSION_RUNTIME_SCOPE_MISMATCH || code.includes("CURSOR") || code.includes("REPLAY")) return 409;
10066
+ if (code === AgentGatewayErrorCode.AGENT_REQUEST_CONFLICT || code === AgentGatewayErrorCode.AGENT_REQUEST_IN_PROGRESS || code === AgentGatewayErrorCode.AGENT_REQUEST_OUTCOME_UNKNOWN || code === AgentGatewayErrorCode.AGENT_RUNTIME_RESTART_REQUIRED || code === AgentGatewayErrorCode.AGENT_COMMAND_INVALID_STATE || code.includes("CURSOR") || code.includes("REPLAY")) return 409;
10121
10067
  if (code === AgentGatewayErrorCode.AGENT_GATEWAY_CLOSED || code === AgentGatewayErrorCode.AGENT_SHARED_ENVIRONMENT_UNAVAILABLE) return 503;
10122
10068
  return 400;
10123
10069
  }
@@ -11312,7 +11258,6 @@ function createRuntime(options, compiledAgents) {
11312
11258
  );
11313
11259
  const activity = new AgentSessionActivityIndex();
11314
11260
  const bindings = /* @__PURE__ */ new Map();
11315
- const publishedBindings = /* @__PURE__ */ new Map();
11316
11261
  const publishedCurrentBindings = /* @__PURE__ */ new Map();
11317
11262
  const currentBindingReservations = /* @__PURE__ */ new Map();
11318
11263
  const nextBindingGeneration = /* @__PURE__ */ new Map();
@@ -11395,20 +11340,12 @@ function createRuntime(options, compiledAgents) {
11395
11340
  },
11396
11341
  async resolveSessionRuntime(agentTypeId, scope, claim, sessionId) {
11397
11342
  runtime.assertOpen();
11398
- try {
11399
- const authority = await inventory.resolveSessionRuntime(agentTypeId, scope, claim, sessionId);
11400
- if (!authority) return void 0;
11401
- validateResolvedRuntimeScope(authority.runtimeScope);
11402
- return authority;
11403
- } catch {
11404
- throw new AgentGatewayError(
11405
- AgentGatewayErrorCode.AGENT_SESSION_RUNTIME_SCOPE_MISMATCH,
11406
- "session runtime scope metadata is unavailable"
11407
- );
11408
- }
11343
+ const resolved = await inventory.resolveSessionRuntime(agentTypeId, scope, claim, sessionId);
11344
+ if (resolved) validateResolvedRuntimeScope(resolved);
11345
+ return resolved;
11409
11346
  },
11410
11347
  resolveAgentRuntimeScope,
11411
- async resolveBinding(agentTypeId, scope, claim, resolvedRuntimeScope, purpose = "current") {
11348
+ async resolveBinding(agentTypeId, scope, claim, resolvedRuntimeScope) {
11412
11349
  runtime.assertOpen();
11413
11350
  const agent = compiledById.get(agentTypeId);
11414
11351
  if (!agent) throw new AgentGatewayError(AgentGatewayErrorCode.AGENT_TYPE_UNKNOWN, "agent type is not available");
@@ -11429,7 +11366,7 @@ function createRuntime(options, compiledAgents) {
11429
11366
  ]);
11430
11367
  const physicalBindingIdentity = resolved.physicalBindingIdentity ?? resolved.identity;
11431
11368
  const currentKey = JSON.stringify([agentTypeId, claim.workspaceScopeId, physicalBindingIdentity]);
11432
- const useCanonicalCurrent = purpose === "current" && options.resolveAuthorizedAgentRuntimeScope !== void 0;
11369
+ const useCanonicalCurrent = options.resolveAuthorizedAgentRuntimeScope !== void 0;
11433
11370
  if (useCanonicalCurrent) {
11434
11371
  const current = publishedCurrentBindings.get(currentKey);
11435
11372
  if (current) return current;
@@ -11481,7 +11418,6 @@ function createRuntime(options, compiledAgents) {
11481
11418
  await disposeBinding(binding2);
11482
11419
  throw new AgentGatewayError(AgentGatewayErrorCode.AGENT_GATEWAY_CLOSED, "agent host is closing");
11483
11420
  }
11484
- publishedBindings.set(key, binding2);
11485
11421
  if (useCanonicalCurrent && currentBindingReservations.get(currentKey) === key && !publishedCurrentBindings.has(currentKey)) {
11486
11422
  publishedCurrentBindings.set(currentKey, binding2);
11487
11423
  currentBindingReservations.delete(currentKey);
@@ -11514,18 +11450,14 @@ function createRuntime(options, compiledAgents) {
11514
11450
  }
11515
11451
  return binding;
11516
11452
  },
11517
- findPublishedBinding(agentTypeId, workspaceScopeId, runtimeScopeIdentity, physicalBindingIdentity, provisioningFingerprint) {
11518
- const matches = [...publishedBindings.values()].filter((binding) => binding.agentTypeId === agentTypeId && binding.workspaceScopeId === workspaceScopeId && (!runtimeScopeIdentity || binding.scope.identity === runtimeScopeIdentity) && (!physicalBindingIdentity || (binding.scope.physicalBindingIdentity ?? binding.scope.identity) === physicalBindingIdentity) && (!provisioningFingerprint || binding.scope.environment.provisioningFingerprint === provisioningFingerprint));
11519
- return matches.length === 1 ? matches[0] : void 0;
11520
- },
11521
- findPublishedCurrentBinding(agentTypeId, workspaceScopeId, physicalBindingIdentity, runtimeScopeIdentity, provisioningFingerprint) {
11453
+ findPublishedCurrentBinding(agentTypeId, workspaceScopeId, physicalBindingIdentity, bindingIdentity, provisioningFingerprint) {
11522
11454
  const exact = publishedCurrentBindings.get(JSON.stringify([
11523
11455
  agentTypeId,
11524
11456
  workspaceScopeId,
11525
11457
  physicalBindingIdentity
11526
11458
  ]));
11527
11459
  if (exact) return exact;
11528
- const matches = [...publishedCurrentBindings.values()].filter((binding) => binding.agentTypeId === agentTypeId && binding.workspaceScopeId === workspaceScopeId && (!runtimeScopeIdentity || binding.scope.identity === runtimeScopeIdentity) && (!provisioningFingerprint || binding.scope.environment.provisioningFingerprint === provisioningFingerprint));
11460
+ const matches = [...publishedCurrentBindings.values()].filter((binding) => binding.agentTypeId === agentTypeId && binding.workspaceScopeId === workspaceScopeId && (!bindingIdentity || binding.scope.identity === bindingIdentity) && (!provisioningFingerprint || binding.scope.environment.provisioningFingerprint === provisioningFingerprint));
11529
11461
  return matches.length === 1 ? matches[0] : void 0;
11530
11462
  },
11531
11463
  startDrain() {
@@ -11634,7 +11566,6 @@ function createRuntime(options, compiledAgents) {
11634
11566
  }
11635
11567
  const resolvedBindings = await Promise.allSettled([...bindings.values()]);
11636
11568
  bindings.clear();
11637
- publishedBindings.clear();
11638
11569
  publishedCurrentBindings.clear();
11639
11570
  nextBindingGeneration.clear();
11640
11571
  currentBindingReservations.clear();
@@ -1,8 +1,8 @@
1
- import { A as AgentHarness, a as AgentReadiness, b as Agent } from '../harness-DS8jLKIx.js';
2
- export { c as AGENT_NOT_IMPLEMENTED_UNTIL_T1, d as AgentActor, e as AgentCoreHarness, f as AgentCoreHarnessFactory, g as AgentCorePromptInput, h as AgentCoreSessionAdapter, i as AgentCoreSessionSnapshot, j as AgentEvent, k as AgentMessageContent, l as AgentMessagePart, m as AgentNotImplementedError, n as AgentReadinessStatus, o as AgentResolveInputResponse, p as AgentSendInput, q as AgentStartReceipt, r as AgentStreamOptions } from '../harness-DS8jLKIx.js';
3
- import { S as SessionStore } from '../piChatEvent-B3ehh9V0.js';
4
- import { A as AgentCoreSessionService, a as AgentEffectAdmission } from '../piChatSessionService-xnv8rcdh.js';
5
- export { b as AGENT_EFFECT_METHODS, c as AgentEffectAdmissionError, P as PiChatEventStreamResult, d as PiChatEventStreamSubscription, e as PiChatEventSubscriber, f as PiChatReplayRangeError, g as PiChatSessionService, h as PiSessionCreateInit, i as PiSessionRequestContext, w as withAgentEffectAdmission } from '../piChatSessionService-xnv8rcdh.js';
1
+ import { A as AgentHarness, a as AgentReadiness, b as Agent } from '../harness-s-kEgJkK.js';
2
+ export { c as AGENT_NOT_IMPLEMENTED_UNTIL_T1, d as AgentActor, e as AgentCoreHarness, f as AgentCoreHarnessFactory, g as AgentCorePromptInput, h as AgentCoreSessionAdapter, i as AgentCoreSessionSnapshot, j as AgentEvent, k as AgentMessageContent, l as AgentMessagePart, m as AgentNotImplementedError, n as AgentReadinessStatus, o as AgentResolveInputResponse, p as AgentSendInput, q as AgentStartReceipt, r as AgentStreamOptions } from '../harness-s-kEgJkK.js';
3
+ import { S as SessionStore } from '../piChatEvent-Bzof4IEy.js';
4
+ import { A as AgentCoreSessionService, a as AgentEffectAdmission } from '../piChatSessionService-BU4L5hxM.js';
5
+ export { b as AGENT_EFFECT_METHODS, c as AgentEffectAdmissionError, P as PiChatEventStreamResult, d as PiChatEventStreamSubscription, e as PiChatEventSubscriber, f as PiChatReplayRangeError, g as PiChatSessionService, h as PiSessionCreateInit, i as PiSessionRequestContext, w as withAgentEffectAdmission } from '../piChatSessionService-BU4L5hxM.js';
6
6
  import '@mariozechner/pi-coding-agent';
7
7
  import 'zod';
8
8
 
@@ -5,7 +5,7 @@ import {
5
5
  mergePiPackageSources,
6
6
  projectSkillResourceLocations,
7
7
  withPiHarnessDefaults
8
- } from "./chunk-GRMDMWBW.js";
8
+ } from "./chunk-T37OVD6L.js";
9
9
  import "./chunk-4IQ4HHBG.js";
10
10
  import "./chunk-VXF5DWS6.js";
11
11
  export {