Prototype agent session start in Shopify CLI#7584
Closed
dmerand wants to merge 2 commits into
Closed
Conversation
81ecf37 to
17c8c0a
Compare
5387c2e to
8a8489a
Compare
Contributor
Differences in type declarationsWe detected differences in the type declarations generated by Typescript for this branch compared to the baseline ('main' branch). Please, review them to ensure they are backward-compatible. Here are some important things to keep in mind:
New type declarationspackages/cli-kit/dist/public/node/agent.d.tsimport { LocalStorage } from './local-storage.js';
import { AgentSession, ConfSchema } from '../../private/node/conf-store.js';
export type { AgentSession };
export interface StartAgentSessionOptions {
sessionId: string;
agentName: string;
agentVersion: string;
agentProvider: string;
metricsMode?: 'on' | 'off';
defaultNonInteractive?: boolean;
}
/**
* Start a new agent session.
*
* Persists the agent session state to the CLI kit config store.
*
* @param options - Agent session configuration.
* @param config - Optional config store for testing.
* @returns The persisted session value.
*/
export declare function startAgentSession(options: StartAgentSessionOptions, config?: LocalStorage<ConfSchema>): AgentSession;
/**
* Get the current agent session.
*
* @param config - Optional config store for testing.
* @returns Current agent session, or undefined if no session is active.
*/
export declare function getCurrentAgentSession(config?: LocalStorage<ConfSchema>): AgentSession | undefined;
/**
* Clear the current agent session.
*
* Removes the persisted agent session state from the CLI kit config store.
*
* @param config - Optional config store for testing.
*/
export declare function clearAgentSession(config?: LocalStorage<ConfSchema>): void;
/**
* Pack SHOPIFY_CLI_AGENT_INFO environment variable value from agent session.
*
* The format is a tagged string with agent metadata:
* n:<name>|v:<version>|p:<provider>.
*
* Precedence: explicit process.env.SHOPIFY_CLI_AGENT_INFO takes priority over
* persisted session state.
*
* @param session - Optional session to pack from. If not provided, uses current session.
* @param config - Optional config store for testing.
* @returns Tagged string for SHOPIFY_CLI_AGENT_INFO, or undefined if no data available.
*/
export declare function packAgentInfo(session?: AgentSession, config?: LocalStorage<ConfSchema>): string | undefined;
/**
* Pack SHOPIFY_CLI_AGENT_IDS environment variable value from agent session.
*
* The format is a tagged string with session identifier:
* s:<sessionId>.
*
* Precedence: explicit process.env.SHOPIFY_CLI_AGENT_IDS takes priority over
* persisted session state.
*
* @param session - Optional session to pack from. If not provided, uses current session.
* @param config - Optional config store for testing.
* @returns Tagged string for SHOPIFY_CLI_AGENT_IDS, or undefined if no data available.
*/
export declare function packAgentIds(session?: AgentSession, config?: LocalStorage<ConfSchema>): string | undefined;
Existing type declarationspackages/cli-kit/dist/private/node/conf-store.d.ts@@ -18,11 +18,22 @@ interface Cache {
[mostRecentOccurrenceKey: MostRecentOccurrenceKey]: CacheValue<boolean>;
[rateLimitKey: RateLimitKey]: CacheValue<number[]>;
}
+export interface AgentSession {
+ sessionId: string;
+ startedAt: string;
+ agentName: string;
+ agentVersion: string;
+ agentProvider: string;
+ metricsMode: 'on' | 'off';
+ defaultNonInteractive: boolean;
+}
export interface ConfSchema {
sessionStore: string;
currentSessionId?: string;
devSessionStore?: string;
currentDevSessionId?: string;
+ currentAgentSession?: AgentSession;
+ devAgentSession?: AgentSession;
cache?: Cache;
autoUpgradeEnabled?: boolean;
}
@@ -128,7 +139,8 @@ interface RunWithRateLimitOptions {
export declare function runWithRateLimit(options: RunWithRateLimitOptions, config?: LocalStorage<ConfSchema>): Promise<boolean>;
/**
* Get auto-upgrade preference.
- * Defaults to true if the preference has never been explicitly set.
+ *
+ * Auto-upgrade is enabled by default when the preference has never been set.
*
* @returns Whether auto-upgrade is enabled.
*/
@@ -145,4 +157,20 @@ export declare function getConfigStoreForPartnerStatus(): LocalStorage<Record<st
}>>;
export declare function getCachedPartnerAccountStatus(partnersToken: string): true | null;
export declare function setCachedPartnerAccountStatus(partnersToken: string): void;
+/**
+ * Get current agent session.
+ *
+ * @returns Current agent session.
+ */
+export declare function getAgentSession(config?: LocalStorage<ConfSchema>): AgentSession | undefined;
+/**
+ * Set current agent session.
+ *
+ * @param session - Agent session.
+ */
+export declare function setAgentSession(session: AgentSession, config?: LocalStorage<ConfSchema>): void;
+/**
+ * Remove current agent session.
+ */
+export declare function removeAgentSession(config?: LocalStorage<ConfSchema>): void;
export {};
\ No newline at end of file
|
Contributor
|
This PR seems inactive. If it's still relevant, please add a comment saying so. Otherwise, take no action. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Prototype CLI-owned agent session state.
This PR adds:
shopify agent session startcli-kitSHOPIFY_CLI_AGENT_*env vars are absentmetricsMode=offapp releaseWhy
ai-toolkit-sourcecurrently attributes agent-run Shopify CLI commands by prefixing each command withSHOPIFY_CLI_AGENT_INFOandSHOPIFY_CLI_AGENT_IDS. That works, but it is noisy, token-expensive, and harness-specific.This prototype tests a different shape: start one agent session in Shopify CLI, persist it there, and let later CLI commands reuse that state for attribution and behavior.
app releaseis the default-mode proof because it already has an established non-interactive path through--allow-updates. Reusing that seam makes the prototype easier to evaluate: it shows that agent session state can affect later CLI behavior without inventing a new global--no-inputcontract or taking on a larger command surface likeapp init.Behavior
shopify agent session startpersists:defaultNonInteractiveSHOPIFY_CLI_AGENT_INFO/SHOPIFY_CLI_AGENT_IDSfrom persisted session state when explicit env vars are absentmetricsMode=offsuppresses command analytics for this prototype pathdefaultNonInteractive=trueand the user passed no explicit release-control flags,app releasefollows its existing non-interactive--allow-updatespathBoundaries
This PR does not:
--no-inputcontractThe goal is to demonstrate the value of CLI-owned agent session state clearly.
Manual testing
Start a session and inspect the stored shape:
Confirm later CLI analytics can pick up packed agent attribution without explicit
SHOPIFY_CLI_AGENT_*env vars.Then start a non-interactive session:
Then verify:
uses the prototype agent-mode path without requiring an explicit
--allow-updates.