@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.
- package/CHANGELOG.md +115 -0
- package/dist/types/cli/append-system-prompt.d.ts +7 -0
- package/dist/types/cli/doctor/session-owners.d.ts +8 -2
- package/dist/types/cli/public-command-errors.d.ts +1 -0
- package/dist/types/cli/session-picker.d.ts +16 -3
- package/dist/types/cli/update-cli.d.ts +0 -2
- package/dist/types/cli-ordinary.d.ts +1 -1
- package/dist/types/commands/sdk.d.ts +2 -0
- package/dist/types/config/machine-identity.d.ts +11 -0
- package/dist/types/config/model-registry.d.ts +9 -0
- package/dist/types/config/settings-schema.d.ts +84 -4
- package/dist/types/lsp/client.d.ts +9 -0
- package/dist/types/lsp/types.d.ts +2 -0
- package/dist/types/main.d.ts +40 -3
- package/dist/types/modes/components/session-held-warning.d.ts +27 -0
- package/dist/types/modes/components/session-selector.d.ts +32 -1
- package/dist/types/modes/controllers/selector-controller.d.ts +8 -1
- package/dist/types/modes/interactive-mode.d.ts +12 -1
- package/dist/types/sdk/broker/broker.d.ts +3 -0
- package/dist/types/sdk/broker/lifecycle-ledger.d.ts +5 -2
- package/dist/types/sdk/broker/lifecycle.d.ts +2 -0
- package/dist/types/sdk/broker/session-index.d.ts +11 -0
- package/dist/types/sdk/bus/index.d.ts +1 -1
- package/dist/types/sdk/host/control/dispatch.d.ts +3 -0
- package/dist/types/sdk/host/registration-test-hold.d.ts +7 -0
- package/dist/types/sdk/index.d.ts +1 -0
- package/dist/types/sdk/lifecycle/service.d.ts +3 -0
- package/dist/types/sdk/session-api-key.d.ts +11 -4
- package/dist/types/sdk/session-readonly/format.d.ts +7 -0
- package/dist/types/sdk/session.d.ts +11 -0
- package/dist/types/sdk/startup-capability.d.ts +11 -2
- package/dist/types/session/agent-session.d.ts +1 -2
- package/dist/types/session/internal/managed-session-storage.d.ts +1 -1
- package/dist/types/session/internal/session-claim-set.d.ts +168 -13
- package/dist/types/session/session-handover.d.ts +62 -0
- package/dist/types/session/session-manager.d.ts +75 -15
- package/dist/types/session/session-owner-holder.d.ts +77 -0
- package/dist/types/session/session-ownership-mode.d.ts +45 -2
- package/dist/types/session/session-ownership.d.ts +25 -29
- package/dist/types/session/yield-queue.d.ts +13 -0
- package/dist/types/tools/bash.d.ts +7 -0
- package/dist/types/tools/browser/deferred-profile-cleanup.d.ts +3 -0
- package/dist/types/tools/browser/launch.d.ts +24 -1
- package/dist/types/tools/index.d.ts +6 -0
- package/dist/types/tools/output-meta.d.ts +17 -11
- package/dist/types/tools/tool-result.d.ts +1 -0
- package/package.json +9 -7
- package/scripts/compile-args.ts +6 -3
- package/scripts/run-acp-conformance.ts +36 -10
- package/scripts/verify-gjc-sdk-canonicalization.ts +2 -0
- package/src/cli/append-system-prompt.ts +34 -0
- package/src/cli/auth-broker-cli.ts +5 -1
- package/src/cli/doctor/session-owners.ts +8 -2
- package/src/cli/public-command-errors.ts +4 -0
- package/src/cli/session-picker.ts +57 -7
- package/src/cli/update-cli.ts +0 -22
- package/src/cli-ordinary.ts +2 -17
- package/src/commands/sdk.ts +37 -15
- package/src/config/machine-identity.ts +31 -2
- package/src/config/model-registry.ts +40 -6
- package/src/config/settings-schema.ts +50 -6
- package/src/config/settings.ts +65 -3
- package/src/gjc-runtime/launch-tmux.ts +4 -1
- package/src/internal-urls/docs-index.generated.ts +12 -12
- package/src/lsp/client.ts +60 -6
- package/src/lsp/index.ts +2 -6
- package/src/lsp/types.ts +2 -0
- package/src/main.ts +364 -93
- package/src/modes/DESIGN.md +36 -0
- package/src/modes/acp/acp-agent.ts +215 -31
- package/src/modes/components/session-held-warning.ts +62 -0
- package/src/modes/components/session-selector.ts +234 -11
- package/src/modes/controllers/goal-mode-controller.ts +14 -2
- package/src/modes/controllers/selector-controller.ts +192 -3
- package/src/modes/interactive-mode.ts +40 -2
- package/src/prompts/tools/bash.md +1 -1
- package/src/prompts/tools/monitor.md +1 -1
- package/src/runtime-mcp/manager.ts +5 -1
- package/src/sdk/acp/adapter.ts +2 -0
- package/src/sdk/broker/broker.ts +29 -2
- package/src/sdk/broker/lifecycle-ledger.ts +9 -7
- package/src/sdk/broker/lifecycle.ts +280 -39
- package/src/sdk/broker/session-index.ts +24 -0
- package/src/sdk/bus/index.ts +1 -0
- package/src/sdk/bus/lifecycle-commands.ts +4 -0
- package/src/sdk/cli/session-cli.ts +8 -0
- package/src/sdk/host/control/dispatch.ts +18 -0
- package/src/sdk/host/host.ts +5 -0
- package/src/sdk/host/registration-test-hold.ts +51 -0
- package/src/sdk/host/session-runtime.test.ts +42 -0
- package/src/sdk/index.ts +10 -0
- package/src/sdk/lifecycle/service.ts +33 -10
- package/src/sdk/prompt-failure.ts +4 -0
- package/src/sdk/protocol/operation-registry.ts +7 -1
- package/src/sdk/session-api-key.ts +31 -16
- package/src/sdk/session-readonly/format.ts +10 -0
- package/src/sdk/session-readonly/scope.ts +2 -1
- package/src/sdk/session.ts +60 -7
- package/src/sdk/startup-capability.ts +27 -2
- package/src/session/agent-session.ts +411 -58
- package/src/session/internal/managed-session-storage.ts +16 -2
- package/src/session/internal/session-claim-set.ts +527 -49
- package/src/session/session-handover.ts +283 -0
- package/src/session/session-manager.ts +907 -148
- package/src/session/session-owner-holder.ts +177 -0
- package/src/session/session-ownership-mode.ts +84 -12
- package/src/session/session-ownership.ts +115 -89
- package/src/session/yield-queue.ts +43 -0
- package/src/session-import/provider-service.ts +8 -0
- package/src/setup/provider-onboarding.ts +5 -5
- package/src/task/executor.ts +2 -0
- package/src/tools/bash.ts +10 -0
- package/src/tools/browser/deferred-profile-cleanup.ts +20 -0
- package/src/tools/browser/launch.ts +133 -14
- package/src/tools/browser/registry.ts +72 -19
- package/src/tools/index.ts +10 -1
- package/src/tools/monitor.ts +267 -29
- package/src/tools/output-meta.ts +61 -28
- package/src/tools/tool-catalog.generated.ts +2 -2
- package/src/tools/tool-result.ts +5 -0
- package/dist/types/cli/macos-community-app.d.ts +0 -41
- package/src/cli/macos-community-app.ts +0 -1449
package/src/sdk/session.ts
CHANGED
|
@@ -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
|
-
|
|
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<
|
|
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.
|
|
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
|
|
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
|
|
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 };
|