@gajae-code/coding-agent 0.22.2 → 0.22.3

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 (122) hide show
  1. package/CHANGELOG.md +115 -0
  2. package/dist/types/cli/append-system-prompt.d.ts +7 -0
  3. package/dist/types/cli/doctor/session-owners.d.ts +8 -2
  4. package/dist/types/cli/public-command-errors.d.ts +1 -0
  5. package/dist/types/cli/session-picker.d.ts +16 -3
  6. package/dist/types/cli/update-cli.d.ts +0 -2
  7. package/dist/types/cli-ordinary.d.ts +1 -1
  8. package/dist/types/commands/sdk.d.ts +2 -0
  9. package/dist/types/config/machine-identity.d.ts +11 -0
  10. package/dist/types/config/model-registry.d.ts +9 -0
  11. package/dist/types/config/settings-schema.d.ts +84 -4
  12. package/dist/types/lsp/client.d.ts +9 -0
  13. package/dist/types/lsp/types.d.ts +2 -0
  14. package/dist/types/main.d.ts +40 -3
  15. package/dist/types/modes/components/session-held-warning.d.ts +27 -0
  16. package/dist/types/modes/components/session-selector.d.ts +32 -1
  17. package/dist/types/modes/controllers/selector-controller.d.ts +8 -1
  18. package/dist/types/modes/interactive-mode.d.ts +12 -1
  19. package/dist/types/sdk/broker/broker.d.ts +3 -0
  20. package/dist/types/sdk/broker/lifecycle-ledger.d.ts +5 -2
  21. package/dist/types/sdk/broker/lifecycle.d.ts +2 -0
  22. package/dist/types/sdk/broker/session-index.d.ts +11 -0
  23. package/dist/types/sdk/bus/index.d.ts +1 -1
  24. package/dist/types/sdk/host/control/dispatch.d.ts +3 -0
  25. package/dist/types/sdk/host/registration-test-hold.d.ts +7 -0
  26. package/dist/types/sdk/index.d.ts +1 -0
  27. package/dist/types/sdk/lifecycle/service.d.ts +3 -0
  28. package/dist/types/sdk/session-api-key.d.ts +11 -4
  29. package/dist/types/sdk/session-readonly/format.d.ts +7 -0
  30. package/dist/types/sdk/session.d.ts +11 -0
  31. package/dist/types/sdk/startup-capability.d.ts +11 -2
  32. package/dist/types/session/agent-session.d.ts +1 -2
  33. package/dist/types/session/internal/managed-session-storage.d.ts +1 -1
  34. package/dist/types/session/internal/session-claim-set.d.ts +168 -13
  35. package/dist/types/session/session-handover.d.ts +62 -0
  36. package/dist/types/session/session-manager.d.ts +75 -15
  37. package/dist/types/session/session-owner-holder.d.ts +77 -0
  38. package/dist/types/session/session-ownership-mode.d.ts +45 -2
  39. package/dist/types/session/session-ownership.d.ts +25 -29
  40. package/dist/types/session/yield-queue.d.ts +13 -0
  41. package/dist/types/tools/bash.d.ts +7 -0
  42. package/dist/types/tools/browser/deferred-profile-cleanup.d.ts +3 -0
  43. package/dist/types/tools/browser/launch.d.ts +24 -1
  44. package/dist/types/tools/index.d.ts +6 -0
  45. package/dist/types/tools/output-meta.d.ts +17 -11
  46. package/dist/types/tools/tool-result.d.ts +1 -0
  47. package/package.json +9 -7
  48. package/scripts/compile-args.ts +6 -3
  49. package/scripts/run-acp-conformance.ts +36 -10
  50. package/scripts/verify-gjc-sdk-canonicalization.ts +2 -0
  51. package/src/cli/append-system-prompt.ts +34 -0
  52. package/src/cli/auth-broker-cli.ts +5 -1
  53. package/src/cli/doctor/session-owners.ts +8 -2
  54. package/src/cli/public-command-errors.ts +4 -0
  55. package/src/cli/session-picker.ts +57 -7
  56. package/src/cli/update-cli.ts +0 -22
  57. package/src/cli-ordinary.ts +2 -17
  58. package/src/commands/sdk.ts +37 -15
  59. package/src/config/machine-identity.ts +31 -2
  60. package/src/config/model-registry.ts +40 -6
  61. package/src/config/settings-schema.ts +50 -6
  62. package/src/config/settings.ts +65 -3
  63. package/src/gjc-runtime/launch-tmux.ts +4 -1
  64. package/src/internal-urls/docs-index.generated.ts +12 -12
  65. package/src/lsp/client.ts +60 -6
  66. package/src/lsp/index.ts +2 -6
  67. package/src/lsp/types.ts +2 -0
  68. package/src/main.ts +364 -93
  69. package/src/modes/DESIGN.md +36 -0
  70. package/src/modes/acp/acp-agent.ts +215 -31
  71. package/src/modes/components/session-held-warning.ts +62 -0
  72. package/src/modes/components/session-selector.ts +234 -11
  73. package/src/modes/controllers/goal-mode-controller.ts +14 -2
  74. package/src/modes/controllers/selector-controller.ts +192 -3
  75. package/src/modes/interactive-mode.ts +40 -2
  76. package/src/prompts/tools/bash.md +1 -1
  77. package/src/prompts/tools/monitor.md +1 -1
  78. package/src/runtime-mcp/manager.ts +5 -1
  79. package/src/sdk/acp/adapter.ts +2 -0
  80. package/src/sdk/broker/broker.ts +29 -2
  81. package/src/sdk/broker/lifecycle-ledger.ts +9 -7
  82. package/src/sdk/broker/lifecycle.ts +280 -39
  83. package/src/sdk/broker/session-index.ts +24 -0
  84. package/src/sdk/bus/index.ts +1 -0
  85. package/src/sdk/bus/lifecycle-commands.ts +4 -0
  86. package/src/sdk/cli/session-cli.ts +8 -0
  87. package/src/sdk/host/control/dispatch.ts +18 -0
  88. package/src/sdk/host/host.ts +5 -0
  89. package/src/sdk/host/registration-test-hold.ts +51 -0
  90. package/src/sdk/host/session-runtime.test.ts +42 -0
  91. package/src/sdk/index.ts +10 -0
  92. package/src/sdk/lifecycle/service.ts +33 -10
  93. package/src/sdk/prompt-failure.ts +4 -0
  94. package/src/sdk/protocol/operation-registry.ts +7 -1
  95. package/src/sdk/session-api-key.ts +31 -16
  96. package/src/sdk/session-readonly/format.ts +10 -0
  97. package/src/sdk/session-readonly/scope.ts +2 -1
  98. package/src/sdk/session.ts +60 -7
  99. package/src/sdk/startup-capability.ts +27 -2
  100. package/src/session/agent-session.ts +411 -58
  101. package/src/session/internal/managed-session-storage.ts +16 -2
  102. package/src/session/internal/session-claim-set.ts +527 -49
  103. package/src/session/session-handover.ts +283 -0
  104. package/src/session/session-manager.ts +907 -148
  105. package/src/session/session-owner-holder.ts +177 -0
  106. package/src/session/session-ownership-mode.ts +84 -12
  107. package/src/session/session-ownership.ts +115 -89
  108. package/src/session/yield-queue.ts +43 -0
  109. package/src/session-import/provider-service.ts +8 -0
  110. package/src/setup/provider-onboarding.ts +5 -5
  111. package/src/task/executor.ts +2 -0
  112. package/src/tools/bash.ts +10 -0
  113. package/src/tools/browser/deferred-profile-cleanup.ts +20 -0
  114. package/src/tools/browser/launch.ts +133 -14
  115. package/src/tools/browser/registry.ts +72 -19
  116. package/src/tools/index.ts +10 -1
  117. package/src/tools/monitor.ts +267 -29
  118. package/src/tools/output-meta.ts +61 -28
  119. package/src/tools/tool-catalog.generated.ts +2 -2
  120. package/src/tools/tool-result.ts +5 -0
  121. package/dist/types/cli/macos-community-app.d.ts +0 -41
  122. package/src/cli/macos-community-app.ts +0 -1449
@@ -22,6 +22,7 @@ import {
22
22
  type Message,
23
23
  type Model,
24
24
  type ProviderSessionState,
25
+ type ResolvedApiKey,
25
26
  resolveOAuthStorageProvider,
26
27
  type SimpleStreamOptions,
27
28
  streamSimple,
@@ -193,9 +194,12 @@ import {
193
194
  type SessionMcpDeclaredServer,
194
195
  } from "../session/agent-session";
195
196
  import { AuthBrokerClient, AuthStorage, RemoteAuthCredentialStore } from "../session/auth-storage";
197
+ import { sessionClaimSetOf } from "../session/internal/session-claim-set";
196
198
  import { type CustomMessage, convertToLlm } from "../session/messages";
197
199
  import { primaryControlSurfaceFor } from "../session/primary-control-surface";
198
200
  import { createReadonlySessionManager, SessionManager, sessionArtifactCapability } from "../session/session-manager";
201
+ import { type SessionOwnerSurface, sessionOwnerSurface } from "../session/session-ownership";
202
+ import { sessionOwnershipModeFor } from "../session/session-ownership-mode";
199
203
  import {
200
204
  parsePersistedCredentialSelector,
201
205
  resolveStartupAuthConfig,
@@ -203,6 +207,7 @@ import {
203
207
  startupAuthConfigError,
204
208
  } from "../session/startup-auth-config";
205
209
  import {
210
+ classifyOwnedEnvelope,
206
211
  isOwnedCompletionEnvelopeAllowed,
207
212
  lookupOwnedRegistration,
208
213
  type OwnedCompletionEnvelope,
@@ -272,6 +277,8 @@ type AsyncResultEntry = {
272
277
  durationMs: number | undefined;
273
278
  /** Exact owned-completion origin when the job is registered left-running work of a terminal turn. */
274
279
  ownedCompletion?: OwnedCompletionEnvelope;
280
+ /** The result carries a fold receipt for the wake turn that completes the folded task. */
281
+ foldReceipt?: boolean;
275
282
  };
276
283
 
277
284
  type AsyncResultJobDetails = {
@@ -684,6 +691,15 @@ export interface CreateAgentSessionOptions {
684
691
  /** Session manager. Default: session stored under the configured agentDir sessions root */
685
692
  sessionManager?: SessionManager;
686
693
 
694
+ /**
695
+ * How this process is named to others while it holds the session it creates (design §3.4).
696
+ * Default: `sdk`. A supplied `sessionManager` keeps the surface its factory claimed under; pass
697
+ * the same `{ surface }` as that factory's ownership argument. When the session is open for
698
+ * writing in another process, under `session.ownership.mode: enforce`, the factories and this
699
+ * function throw `SessionHeldError`.
700
+ */
701
+ owner?: { readonly surface: SessionOwnerSurface };
702
+
687
703
  /** Override local:// protocol options for subagent local:// sharing. Default: uses the session's own artifacts dir and session ID. */
688
704
  localProtocolOptions?: LocalProtocolOptions;
689
705
 
@@ -1691,6 +1707,11 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
1691
1707
  // Default factory-created managers remain on the existing fresh bootstrap path.
1692
1708
  const suppliedSessionManager = options.sessionManager;
1693
1709
  if (suppliedSessionManager) {
1710
+ // Enforce's refusal comes before the pending rewrite below, the first write to the transcript.
1711
+ // The caller's manager stays the caller's: it holds no claim for a refused session.
1712
+ const suppliedClaims = sessionClaimSetOf(suppliedSessionManager);
1713
+ const refusal = suppliedClaims.claiming ? await suppliedClaims.refusal() : undefined;
1714
+ if (refusal) throw refusal;
1694
1715
  const writableOpen = await suppliedSessionManager.finalizePendingWritableOpen();
1695
1716
  switch (writableOpen) {
1696
1717
  case "published":
@@ -2085,9 +2106,25 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
2085
2106
  sessionManager =
2086
2107
  suppliedSessionManager ??
2087
2108
  (await logger.time("sessionManager", async () => {
2088
- return SessionManager.create(cwd, SessionManager.managedDestination(cwd, agentDir));
2109
+ // The mode comes from this session's settings, like createSessionManager's: a broker-launched
2110
+ // host or an embedding may have no global Settings.
2111
+ return SessionManager.create(cwd, SessionManager.managedDestination(cwd, agentDir), undefined, {
2112
+ surface: options.owner?.surface ?? sessionOwnerSurface(),
2113
+ mode: sessionOwnershipModeFor(settings.getGlobal("session.ownership.mode")),
2114
+ });
2089
2115
  }));
2090
2116
  liveSessionManager = sessionManager;
2117
+ // The claim gate for the manager created here (a supplied one was checked on entry): `create`
2118
+ // claims its fresh id in the background, and enforce refuses a failed claim now, before any
2119
+ // write. The manager is ours, so it is closed; `create` wrote nothing.
2120
+ const createdClaims = sessionClaimSetOf(sessionManager);
2121
+ if (!suppliedSessionManager && createdClaims.claiming) {
2122
+ const refusal = await createdClaims.refusal();
2123
+ if (refusal) {
2124
+ await sessionManager.close();
2125
+ throw refusal;
2126
+ }
2127
+ }
2091
2128
  const logicalSessionId = sessionManager.getSessionId();
2092
2129
  // Fork-context seeds carry conversation content only, never provider identity:
2093
2130
  // a shared continuity id would make concurrent subagents present the same
@@ -2829,6 +2866,7 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
2829
2866
  result: deliveredResult,
2830
2867
  job,
2831
2868
  durationMs,
2869
+ ...(foldDisposition.kind === "receipt" ? { foldReceipt: true } : {}),
2832
2870
  ...(ownedCompletion
2833
2871
  ? {
2834
2872
  ownedCompletion: {
@@ -3494,6 +3532,7 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
3494
3532
  return promise;
3495
3533
  },
3496
3534
  getSessionId: () => sessionManager.getSessionId(),
3535
+ getSessionIdentityGeneration: () => sessionManager.getSessionIdentityGeneration(),
3497
3536
  // Subagents inherit the parent's manager; its registered endpoint is
3498
3537
  // authoritative for owned-registration keying and endpoint-first
3499
3538
  // manager lookup (the child's own id is never registered), so tools
@@ -3547,6 +3586,7 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
3547
3586
  getSdkPermissionMode: () => session?.sdkPermissionMode ?? "allow",
3548
3587
  getSdkPermissionProvider: () => session?.getSdkPermissionProvider(),
3549
3588
  getClientBridge: () => session?.clientBridge,
3589
+ isSessionDisposed: () => session?.isDisposed ?? false,
3550
3590
  getCompactContext: () => session.formatCompactContext(),
3551
3591
  getTodoPhases: () => session.getTodoPhases(),
3552
3592
  setTodoPhases: phases => session.setTodoPhases(phases),
@@ -5592,7 +5632,7 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
5592
5632
  }
5593
5633
 
5594
5634
  const resolvedCredentialScopes = new Map<string, string | undefined>();
5595
- const resolveAgentApiKey = async (provider: string, signal?: AbortSignal): Promise<string> => {
5635
+ const resolveAgentApiKey = async (provider: string, signal?: AbortSignal): Promise<ResolvedApiKey> => {
5596
5636
  const liveModel = resolveLiveSessionApiKeyModel(sessionAgent?.state.model, model, provider);
5597
5637
  const hasExplicitScopePolicy =
5598
5638
  modelRegistry.authStorage.hasSessionCredentialSelector(provider, credentialSessionId) ||
@@ -5606,7 +5646,9 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
5606
5646
  signal,
5607
5647
  );
5608
5648
  resolvedCredentialScopes.set(provider, resolution.credentialSessionId);
5609
- return resolution.apiKey;
5649
+ return resolution.credentialRowId === undefined
5650
+ ? { apiKey: resolution.apiKey }
5651
+ : { apiKey: resolution.apiKey, credentialId: resolution.credentialRowId };
5610
5652
  };
5611
5653
  const resolvedCredentialType = (provider: string): "api_key" | "oauth" | undefined => {
5612
5654
  const scope = resolvedCredentialScopes.has(provider)
@@ -5681,7 +5723,7 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
5681
5723
  provider,
5682
5724
  error: error instanceof Error ? error.message : String(error),
5683
5725
  });
5684
- const replacementApiKey = await resolveAgentApiKey(provider, streamOptions?.signal);
5726
+ const replacement = await resolveAgentApiKey(provider, streamOptions?.signal);
5685
5727
  if (
5686
5728
  !isStableSessionApiKeyCredentialType(
5687
5729
  streamOptions?.authCredentialType,
@@ -5690,7 +5732,7 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
5690
5732
  ) {
5691
5733
  return undefined;
5692
5734
  }
5693
- return replacementApiKey;
5735
+ return replacement;
5694
5736
  },
5695
5737
  });
5696
5738
  try {
@@ -5922,8 +5964,6 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
5922
5964
 
5923
5965
  session = new AgentSession({
5924
5966
  agent,
5925
- rootInteractiveSharedAppend:
5926
- primaryControlSurface === "cli" && options.hasUI === true && !isCanonicalSubSession,
5927
5967
  thinkingLevel,
5928
5968
  sessionManager,
5929
5969
  settings,
@@ -6114,6 +6154,18 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
6114
6154
  entry.ownedCompletion
6115
6155
  ? `${entry.ownedCompletion.lineageIdHash}\u0000${entry.ownedCompletion.promptAttemptEpoch}`
6116
6156
  : "ordinary",
6157
+ // Completions that classify "ordinary" reach a running turn at its next
6158
+ // tool step. That includes jobs launched by a tool call of a turn that
6159
+ // was never terminal-aborted: they carry an ownership envelope whose
6160
+ // terminal scope does not exist. A "fresh" envelope needs the follow-up
6161
+ // path's resume admission (new lineage), a "drop" envelope must never
6162
+ // reach the agent, and a fold receipt belongs to the wake turn, so
6163
+ // those stay on the before-yield/idle path. The classification is
6164
+ // read in the same synchronous tick in which the loop commits the
6165
+ // built message, so it cannot change before delivery.
6166
+ deliverAtStepBoundary: entry =>
6167
+ entry.foldReceipt !== true &&
6168
+ (entry.ownedCompletion === undefined || classifyOwnedEnvelope(entry.ownedCompletion) === "ordinary"),
6117
6169
  build: entries => {
6118
6170
  try {
6119
6171
  return buildAsyncResultBatchMessage(entries);
@@ -6124,6 +6176,7 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
6124
6176
  });
6125
6177
  }
6126
6178
  session.yieldQueue.register<McpNotificationEntry>("mcp-notification", {
6179
+ deliverAtStepBoundary: () => true,
6127
6180
  build: buildMcpNotificationBatchMessage,
6128
6181
  });
6129
6182
 
@@ -3,8 +3,23 @@ import {
3
3
  type ModelProfileErrorCode,
4
4
  type ModelProfileErrorDetails,
5
5
  } from "../config/model-profile-contract";
6
+ import {
7
+ SessionHeldError,
8
+ type SessionOwnerHolderSummary,
9
+ sessionOwnerHolderSummary,
10
+ } from "../session/session-owner-holder";
6
11
  export type SdkStartupPhase = "registration" | "startup";
7
12
 
13
+ /**
14
+ * A lifecycle host refused to open its session because another process holds it (single-owner,
15
+ * `enforce`). The broker reports it as the same `live_session` outcome its resume wait ends in.
16
+ */
17
+ export const SDK_STARTUP_SESSION_HELD_CODE = "session_held";
18
+
19
+ export interface SdkStartupSessionHeldDetails {
20
+ holder?: SessionOwnerHolderSummary;
21
+ }
22
+
8
23
  export type SdkStartupReason =
9
24
  | "disabled"
10
25
  | "ineligible"
@@ -18,8 +33,8 @@ export interface SdkStartupFailure {
18
33
  phase: SdkStartupPhase;
19
34
  reason: SdkStartupReason;
20
35
  message: string;
21
- code?: ModelProfileErrorCode;
22
- details?: ModelProfileErrorDetails;
36
+ code?: ModelProfileErrorCode | typeof SDK_STARTUP_SESSION_HELD_CODE;
37
+ details?: ModelProfileErrorDetails | SdkStartupSessionHeldDetails;
23
38
  }
24
39
 
25
40
  export type SdkStartupResult = { status: "started" } | { status: "failed"; failure: SdkStartupFailure };
@@ -155,6 +170,16 @@ export function normalizeSdkStartupFailure(
155
170
  : reason === "pending"
156
171
  ? "SDK startup did not complete before readiness cutoff."
157
172
  : FALLBACK_MESSAGE;
173
+ if (error instanceof SessionHeldError) {
174
+ const holder = sessionOwnerHolderSummary(error.holder);
175
+ return {
176
+ phase,
177
+ reason,
178
+ message: sanitizeSdkStartupMessage(error.operatorMessage, knownSecrets),
179
+ code: SDK_STARTUP_SESSION_HELD_CODE,
180
+ details: holder ? { holder } : {},
181
+ };
182
+ }
158
183
  const message = sanitizeSdkStartupMessage(error, knownSecrets);
159
184
  const profileError = isModelProfileError(error) ? { code: error.code, details: error.details } : {};
160
185
  return { phase, reason, message: message === FALLBACK_MESSAGE ? fallback : message, ...profileError };