@google/jules-merge 0.0.1

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 (67) hide show
  1. package/README.md +201 -0
  2. package/dist/cli/check-conflicts.command.mjs +387 -0
  3. package/dist/cli/index.mjs +28 -0
  4. package/dist/cli/init.command.mjs +159 -0
  5. package/dist/core/src/activities/client.d.ts +131 -0
  6. package/dist/core/src/activities/summary.d.ts +22 -0
  7. package/dist/core/src/activities/types.d.ts +79 -0
  8. package/dist/core/src/api.d.ts +49 -0
  9. package/dist/core/src/artifacts.d.ts +105 -0
  10. package/dist/core/src/caching.d.ts +31 -0
  11. package/dist/core/src/client.d.ts +180 -0
  12. package/dist/core/src/errors.d.ts +97 -0
  13. package/dist/core/src/index.d.ts +49 -0
  14. package/dist/core/src/mappers.d.ts +53 -0
  15. package/dist/core/src/network/adapter.d.ts +47 -0
  16. package/dist/core/src/platform/node.d.ts +45 -0
  17. package/dist/core/src/platform/types.d.ts +88 -0
  18. package/dist/core/src/polling.d.ts +43 -0
  19. package/dist/core/src/query/computed.d.ts +86 -0
  20. package/dist/core/src/query/projection.d.ts +80 -0
  21. package/dist/core/src/query/schema.d.ts +124 -0
  22. package/dist/core/src/query/select.d.ts +21 -0
  23. package/dist/core/src/query/validate.d.ts +68 -0
  24. package/dist/core/src/session.d.ts +195 -0
  25. package/dist/core/src/sessions.d.ts +87 -0
  26. package/dist/core/src/snapshot.d.ts +46 -0
  27. package/dist/core/src/sources.d.ts +23 -0
  28. package/dist/core/src/storage/cache-info.d.ts +43 -0
  29. package/dist/core/src/storage/memory.d.ts +69 -0
  30. package/dist/core/src/storage/node-fs.d.ts +95 -0
  31. package/dist/core/src/storage/root.d.ts +17 -0
  32. package/dist/core/src/storage/types.d.ts +115 -0
  33. package/dist/core/src/streaming.d.ts +47 -0
  34. package/dist/core/src/types.d.ts +1418 -0
  35. package/dist/core/src/utils/page-token.d.ts +55 -0
  36. package/dist/core/src/utils.d.ts +27 -0
  37. package/dist/index.mjs +395 -0
  38. package/dist/merge/src/__tests__/conflicts/git-handler.test.d.ts +1 -0
  39. package/dist/merge/src/__tests__/conflicts/git-spec.test.d.ts +1 -0
  40. package/dist/merge/src/__tests__/conflicts/session-handler.test.d.ts +1 -0
  41. package/dist/merge/src/__tests__/conflicts/session-spec.test.d.ts +1 -0
  42. package/dist/merge/src/__tests__/init/init-handler.test.d.ts +1 -0
  43. package/dist/merge/src/__tests__/init/init-spec.test.d.ts +1 -0
  44. package/dist/merge/src/__tests__/init/templates.test.d.ts +1 -0
  45. package/dist/merge/src/__tests__/shared/git.test.d.ts +1 -0
  46. package/dist/merge/src/__tests__/shared/github.test.d.ts +1 -0
  47. package/dist/merge/src/__tests__/shared/session.test.d.ts +1 -0
  48. package/dist/merge/src/cli/check-conflicts.command.d.ts +24 -0
  49. package/dist/merge/src/cli/index.d.ts +2 -0
  50. package/dist/merge/src/cli/init.command.d.ts +23 -0
  51. package/dist/merge/src/conflicts/git-handler.d.ts +4 -0
  52. package/dist/merge/src/conflicts/git-spec.d.ts +43 -0
  53. package/dist/merge/src/conflicts/index.d.ts +4 -0
  54. package/dist/merge/src/conflicts/session-handler.d.ts +9 -0
  55. package/dist/merge/src/conflicts/session-spec.d.ts +43 -0
  56. package/dist/merge/src/index.d.ts +5 -0
  57. package/dist/merge/src/init/index.d.ts +4 -0
  58. package/dist/merge/src/init/init-handler.d.ts +4 -0
  59. package/dist/merge/src/init/init-spec.d.ts +41 -0
  60. package/dist/merge/src/init/templates.d.ts +10 -0
  61. package/dist/merge/src/mcp/index.d.ts +1 -0
  62. package/dist/merge/src/mcp/server.d.ts +2 -0
  63. package/dist/merge/src/shared/git.d.ts +17 -0
  64. package/dist/merge/src/shared/github.d.ts +18 -0
  65. package/dist/merge/src/shared/result.d.ts +19 -0
  66. package/dist/merge/src/shared/session.d.ts +16 -0
  67. package/package.json +60 -0
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Copyright 2026 Google LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /**
17
+ * Computed Fields for Jules Query Language
18
+ *
19
+ * Computed fields are derived at query time, not stored.
20
+ * They can be selected but not filtered.
21
+ */
22
+ import { Activity } from '../types.js';
23
+ /**
24
+ * List of computed field names for activities
25
+ */
26
+ export declare const ACTIVITY_COMPUTED_FIELDS: readonly ["artifactCount", "summary"];
27
+ /**
28
+ * List of computed field names for sessions
29
+ */
30
+ export declare const SESSION_COMPUTED_FIELDS: readonly ["durationMs"];
31
+ /**
32
+ * Check if a field name is a computed field for activities
33
+ */
34
+ export declare function isActivityComputedField(field: string): boolean;
35
+ /**
36
+ * Check if a field name is a computed field for sessions
37
+ */
38
+ export declare function isSessionComputedField(field: string): boolean;
39
+ /**
40
+ * Compute the artifactCount for an activity
41
+ */
42
+ export declare function computeArtifactCount(activity: Activity): number;
43
+ /**
44
+ * Compute the summary for an activity
45
+ * Delegates to existing toSummary implementation
46
+ */
47
+ export declare function computeSummary(activity: Activity): string;
48
+ /**
49
+ * Compute the duration in milliseconds for a session
50
+ */
51
+ export declare function computeDurationMs(session: {
52
+ createTime?: string;
53
+ updateTime?: string;
54
+ }): number;
55
+ /**
56
+ * Inject computed fields into an activity based on selected fields
57
+ *
58
+ * @param activity The activity to augment
59
+ * @param selectFields The fields being selected (or undefined for default)
60
+ * @returns Activity with computed fields added
61
+ */
62
+ export declare function injectActivityComputedFields(activity: Activity, selectFields?: string[]): Activity & {
63
+ artifactCount?: number;
64
+ summary?: string;
65
+ };
66
+ /**
67
+ * Inject computed fields into a session based on selected fields
68
+ *
69
+ * @param session The session to augment
70
+ * @param selectFields The fields being selected (or undefined for default)
71
+ * @returns Session with computed fields added
72
+ */
73
+ export declare function injectSessionComputedFields<T extends {
74
+ createTime?: string;
75
+ updateTime?: string;
76
+ }>(session: T, selectFields?: string[]): T & {
77
+ durationMs?: number;
78
+ };
79
+ /**
80
+ * Default projection fields for activities (includes computed fields)
81
+ */
82
+ export declare const DEFAULT_ACTIVITY_PROJECTION: string[];
83
+ /**
84
+ * Default projection fields for sessions
85
+ */
86
+ export declare const DEFAULT_SESSION_PROJECTION: string[];
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Copyright 2026 Google LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /**
17
+ * Projection Engine for Jules Query Language
18
+ *
19
+ * Supports:
20
+ * - Dot notation field paths: "plan.steps.title"
21
+ * - Wildcard inclusion: "*"
22
+ * - Exclusion prefix: "-artifacts.data"
23
+ * - Implicit array traversal: "artifacts.type" works on arrays
24
+ */
25
+ /**
26
+ * Parsed select expression
27
+ */
28
+ export interface SelectExpression {
29
+ path: string[];
30
+ exclude: boolean;
31
+ wildcard: boolean;
32
+ }
33
+ /**
34
+ * Parse a select expression string into structured form
35
+ *
36
+ * Examples:
37
+ * - "id" → { path: ["id"], exclude: false, wildcard: false }
38
+ * - "plan.steps.title" → { path: ["plan", "steps", "title"], exclude: false, wildcard: false }
39
+ * - "-artifacts.data" → { path: ["artifacts", "data"], exclude: true, wildcard: false }
40
+ * - "*" → { path: [], exclude: false, wildcard: true }
41
+ */
42
+ export declare function parseSelectExpression(expr: string): SelectExpression;
43
+ /**
44
+ * Get a value at a nested path, handling arrays transparently
45
+ *
46
+ * For paths that traverse arrays, returns an array of values from each element.
47
+ *
48
+ * Examples:
49
+ * - getPath({a: {b: 1}}, ["a", "b"]) → 1
50
+ * - getPath({items: [{x: 1}, {x: 2}]}, ["items", "x"]) → [1, 2]
51
+ */
52
+ export declare function getPath(obj: unknown, path: string[]): unknown;
53
+ /**
54
+ * Set a value at a nested path, creating intermediate objects as needed
55
+ *
56
+ * For array paths, preserves array structure.
57
+ */
58
+ export declare function setPath(obj: Record<string, unknown>, path: string[], value: unknown): void;
59
+ /**
60
+ * Delete a value at a nested path
61
+ *
62
+ * For paths ending in array elements, removes the field from each element.
63
+ */
64
+ export declare function deletePath(obj: unknown, path: string[]): void;
65
+ /**
66
+ * Deep clone an object
67
+ */
68
+ export declare function deepClone<T>(obj: T): T;
69
+ /**
70
+ * Project a document according to select expressions
71
+ *
72
+ * @param doc The source document
73
+ * @param selects Array of select expression strings
74
+ * @returns Projected document with only selected fields
75
+ */
76
+ export declare function projectDocument(doc: Record<string, unknown>, selects: string[]): Record<string, unknown>;
77
+ /**
78
+ * Check if a path is a prefix of another path
79
+ */
80
+ export declare function isPathPrefix(prefix: string[], path: string[]): boolean;
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Copyright 2026 Google LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /**
17
+ * Schema Introspection for Jules Query Language
18
+ *
19
+ * Provides TypeScript type definitions and field metadata for LLM discoverability.
20
+ * These schemas help LLMs understand the shape of Session, Activity, and related types
21
+ * to translate natural language queries into proper JQL.
22
+ */
23
+ /**
24
+ * Field metadata for schema introspection
25
+ */
26
+ export interface FieldMeta {
27
+ /** Field name */
28
+ name: string;
29
+ /** TypeScript type representation */
30
+ type: string;
31
+ /** Human-readable description */
32
+ description: string;
33
+ /** Whether field is optional */
34
+ optional?: boolean;
35
+ /** Whether field is computed (not stored, derived at query time) */
36
+ computed?: boolean;
37
+ /** Whether field can be filtered in where clause */
38
+ filterable?: boolean;
39
+ /** Whether field can be used in select projection */
40
+ selectable?: boolean;
41
+ /** Nested fields if this is an object or array type */
42
+ fields?: FieldMeta[];
43
+ }
44
+ /**
45
+ * Schema definition for a domain
46
+ */
47
+ export interface DomainSchema {
48
+ /** Domain name */
49
+ domain: 'sessions' | 'activities';
50
+ /** Human-readable description */
51
+ description: string;
52
+ /** All fields in this domain */
53
+ fields: FieldMeta[];
54
+ /** Example queries for this domain */
55
+ examples: QueryExample[];
56
+ }
57
+ /**
58
+ * Example query for documentation
59
+ */
60
+ export interface QueryExample {
61
+ /** Natural language description */
62
+ description: string;
63
+ /** JQL query */
64
+ query: Record<string, unknown>;
65
+ }
66
+ /**
67
+ * Schema for SessionResource
68
+ */
69
+ export declare const SESSION_SCHEMA: DomainSchema;
70
+ /**
71
+ * Schema for Activity types
72
+ */
73
+ export declare const ACTIVITY_SCHEMA: DomainSchema;
74
+ /**
75
+ * FilterOp schema for where clause operators
76
+ */
77
+ export declare const FILTER_OP_SCHEMA: {
78
+ description: string;
79
+ operators: {
80
+ name: string;
81
+ description: string;
82
+ example: string;
83
+ }[];
84
+ dotNotation: {
85
+ description: string;
86
+ examples: string[];
87
+ };
88
+ };
89
+ /**
90
+ * Projection schema for select clause
91
+ */
92
+ export declare const PROJECTION_SCHEMA: {
93
+ description: string;
94
+ syntax: {
95
+ name: string;
96
+ description: string;
97
+ example: string;
98
+ }[];
99
+ defaults: {
100
+ sessions: string[];
101
+ activities: string[];
102
+ };
103
+ };
104
+ /**
105
+ * Get the full schema for a domain
106
+ */
107
+ export declare function getSchema(domain: 'sessions' | 'activities'): DomainSchema;
108
+ /**
109
+ * Get all schemas with filter and projection documentation
110
+ */
111
+ export declare function getAllSchemas(): {
112
+ sessions: DomainSchema;
113
+ activities: DomainSchema;
114
+ filterOps: typeof FILTER_OP_SCHEMA;
115
+ projection: typeof PROJECTION_SCHEMA;
116
+ };
117
+ /**
118
+ * Generate TypeScript type definition string for a domain
119
+ */
120
+ export declare function generateTypeDefinition(domain: 'sessions' | 'activities'): string;
121
+ /**
122
+ * Generate markdown documentation for LLM consumption
123
+ */
124
+ export declare function generateMarkdownDocs(): string;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Copyright 2026 Google LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { JulesClient, JulesQuery, JulesDomain, QueryResult } from '../types.js';
17
+ /**
18
+ * Standalone query engine function.
19
+ * Handles planning, index scanning, and hydration.
20
+ */
21
+ export declare function select<T extends JulesDomain>(client: JulesClient, query: JulesQuery<T>): Promise<QueryResult<T>[]>;
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Copyright 2026 Google LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export interface ValidationError {
17
+ /** Error code for programmatic handling */
18
+ code: ValidationErrorCode;
19
+ /** JSON path to the error location (e.g., "where.artifacts.type") */
20
+ path: string;
21
+ /** Human-readable error message */
22
+ message: string;
23
+ /** Suggested fix or valid alternatives */
24
+ suggestion?: string;
25
+ }
26
+ export interface ValidationWarning {
27
+ /** Warning code */
28
+ code: string;
29
+ /** JSON path to the warning location */
30
+ path: string;
31
+ /** Human-readable warning message */
32
+ message: string;
33
+ }
34
+ export interface ValidationResult {
35
+ /** Whether the query is valid */
36
+ valid: boolean;
37
+ /** Validation errors (if any) */
38
+ errors: ValidationError[];
39
+ /** Validation warnings (non-blocking issues) */
40
+ warnings: ValidationWarning[];
41
+ /** Auto-corrected query (if corrections were possible) */
42
+ correctedQuery?: Record<string, unknown>;
43
+ }
44
+ export type ValidationErrorCode = 'INVALID_STRUCTURE' | 'MISSING_REQUIRED_FIELD' | 'INVALID_DOMAIN' | 'INVALID_FIELD_PATH' | 'INVALID_OPERATOR' | 'INVALID_OPERATOR_VALUE' | 'COMPUTED_FIELD_FILTER' | 'INVALID_ORDER' | 'INVALID_LIMIT' | 'INVALID_SELECT_EXPRESSION';
45
+ /**
46
+ * Validate a Jules Query Language query
47
+ *
48
+ * @param query - The query object to validate
49
+ * @returns Validation result with errors, warnings, and optional corrections
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * const result = validateQuery({
54
+ * from: 'activities',
55
+ * where: { type: 'agentMessaged' },
56
+ * select: ['id', 'message']
57
+ * });
58
+ *
59
+ * if (!result.valid) {
60
+ * console.log('Errors:', result.errors);
61
+ * }
62
+ * ```
63
+ */
64
+ export declare function validateQuery(query: unknown): ValidationResult;
65
+ /**
66
+ * Format validation result as a human-readable string
67
+ */
68
+ export declare function formatValidationResult(result: ValidationResult): string;
@@ -0,0 +1,195 @@
1
+ /**
2
+ * Copyright 2026 Google LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { ActivityClient, SelectOptions } from './activities/types.js';
17
+ import { ApiClient } from './api.js';
18
+ import { InternalConfig } from './client.js';
19
+ import { ActivityStorage, SessionStorage } from './storage/types.js';
20
+ import { StreamActivitiesOptions } from './streaming.js';
21
+ import { Activity, ActivityAgentMessaged, SessionOutcome, SessionClient, SessionResource, SessionState } from './types.js';
22
+ import { SessionSnapshot } from './types.js';
23
+ /**
24
+ * Implementation of the SessionClient interface.
25
+ * Manages an interactive session with the Jules agent.
26
+ */
27
+ export declare class SessionClientImpl implements SessionClient {
28
+ readonly id: string;
29
+ private apiClient;
30
+ private config;
31
+ private sessionStorage;
32
+ private _activities;
33
+ private platform;
34
+ /**
35
+ * Creates a new instance of SessionClientImpl.
36
+ *
37
+ * @param sessionId The ID of the session.
38
+ * @param apiClient The API client to use for network requests.
39
+ * @param config The configuration options.
40
+ * @param activityStorage The storage engine for activities.
41
+ * @param sessionStorage The storage engine for sessions.
42
+ * @param platform The platform adapter.
43
+ */
44
+ constructor(sessionId: string, apiClient: ApiClient, config: InternalConfig, activityStorage: ActivityStorage, sessionStorage: SessionStorage, // Injected dependency
45
+ platform: any);
46
+ private request;
47
+ /**
48
+ * COLD STREAM: Yields all known past activities from local storage.
49
+ * If local cache is empty, fetches from network first.
50
+ */
51
+ history(): AsyncIterable<Activity>;
52
+ /**
53
+ * Forces a full sync of activities from the network to local cache.
54
+ * @returns The number of new activities synced.
55
+ */
56
+ hydrate(): Promise<number>;
57
+ /**
58
+ * HOT STREAM: Yields ONLY future activities as they arrive from the network.
59
+ */
60
+ updates(): AsyncIterable<Activity>;
61
+ /**
62
+ * LOCAL QUERY: Performs rich filtering against local storage only.
63
+ *
64
+ * @deprecated Use `session.activities.select()` instead.
65
+ */
66
+ select(options?: SelectOptions): Promise<Activity[]>;
67
+ /**
68
+ * Scoped access to activity-specific operations.
69
+ */
70
+ get activities(): ActivityClient;
71
+ /**
72
+ * Provides a real-time stream of activities for the session.
73
+ *
74
+ * @param options Options to control the stream.
75
+ */
76
+ stream(options?: StreamActivitiesOptions): AsyncIterable<Activity>;
77
+ /**
78
+ * Approves the currently pending plan.
79
+ * Only valid if the session state is `awaitingPlanApproval`.
80
+ *
81
+ * **Side Effects:**
82
+ * - Sends a POST request to `sessions/{id}:approvePlan`.
83
+ * - Transitions the session state from `awaitingPlanApproval` to `inProgress` (eventually).
84
+ *
85
+ * @throws {InvalidStateError} If the session is not in the `awaitingPlanApproval` state.
86
+ *
87
+ * @example
88
+ * await session.waitFor('awaitingPlanApproval');
89
+ * await session.approve();
90
+ */
91
+ approve(): Promise<void>;
92
+ /**
93
+ * Sends a message (prompt) to the agent in the context of the current session.
94
+ * This is a fire-and-forget operation. To see the response, use `stream()` or `ask()`.
95
+ *
96
+ * **Side Effects:**
97
+ * - Sends a POST request to `sessions/{id}:sendMessage`.
98
+ * - Appends a new `userMessaged` activity to the session history.
99
+ *
100
+ * @param prompt The message to send.
101
+ *
102
+ * @example
103
+ * await session.send("Please clarify step 2.");
104
+ */
105
+ send(prompt: string): Promise<void>;
106
+ /**
107
+ * Sends a message to the agent and waits specifically for the agent's immediate reply.
108
+ * This provides a convenient request/response flow for conversational interactions.
109
+ *
110
+ * **Behavior:**
111
+ * - Sends the prompt using `send()`.
112
+ * - Subscribes to the activity stream.
113
+ * - Resolves with the first `agentMessaged` activity that appears *after* the prompt was sent.
114
+ *
115
+ * @param prompt The message to send.
116
+ * @returns The agent's reply activity.
117
+ * @throws {JulesError} If the session terminates before the agent replies.
118
+ *
119
+ * @example
120
+ * const reply = await session.ask("What is the status?");
121
+ * console.log(reply.message);
122
+ */
123
+ ask(prompt: string): Promise<ActivityAgentMessaged>;
124
+ /**
125
+ * Waits for the session to reach a terminal state and returns the result.
126
+ *
127
+ * **Behavior:**
128
+ * - Polls the session API until state is 'completed' or 'failed'.
129
+ * - Maps the final session resource to a friendly `Outcome` object.
130
+ *
131
+ * @param options Optional configuration for the operation.
132
+ * @param options.timeoutMs Maximum time in milliseconds to wait for the session to complete.
133
+ * @returns The final outcome of the session.
134
+ * @throws {AutomatedSessionFailedError} If the session ends in a 'failed' state.
135
+ * @throws {TimeoutError} If the operation times out.
136
+ */
137
+ result(options?: {
138
+ timeoutMs?: number;
139
+ }): Promise<SessionOutcome>;
140
+ /**
141
+ * Pauses execution and waits until the session reaches a specific state.
142
+ * Also returns if the session reaches a terminal state ('completed' or 'failed')
143
+ * to prevent infinite waiting.
144
+ *
145
+ * **Behavior:**
146
+ * - Polls the session API at the configured interval.
147
+ * - Resolves immediately if the session is already in the target state (or terminal).
148
+ *
149
+ * @param targetState The target state to wait for.
150
+ * @param options Optional configuration for the operation.
151
+ * @param options.timeoutMs Maximum time in milliseconds to wait for the state.
152
+ * @throws {TimeoutError} If the operation times out.
153
+ *
154
+ * @example
155
+ * await session.waitFor('awaitingPlanApproval');
156
+ */
157
+ waitFor(targetState: SessionState, options?: {
158
+ timeoutMs?: number;
159
+ }): Promise<void>;
160
+ /**
161
+ * Archives the session.
162
+ * This removes the session from the default list view and marks it as archived.
163
+ * Archived sessions can still be accessed by ID or by filtering for `archived = true`.
164
+ *
165
+ * **Side Effects:**
166
+ * - Sends a POST request to `sessions/{id}:archive`.
167
+ * - Updates the local cache to mark the session as archived.
168
+ */
169
+ archive(): Promise<void>;
170
+ /**
171
+ * Unarchives the session.
172
+ * This restores the session to the default list view.
173
+ *
174
+ * **Side Effects:**
175
+ * - Sends a POST request to `sessions/{id}:unarchive`.
176
+ * - Updates the local cache to mark the session as not archived.
177
+ */
178
+ unarchive(): Promise<void>;
179
+ /**
180
+ * Retrieves the latest state of the underlying session resource.
181
+ * Implements "Iceberg" Read-Through caching.
182
+ */
183
+ info(): Promise<SessionResource>;
184
+ /**
185
+ * Creates a point-in-time snapshot of the session.
186
+ * This is a network operation that fetches the latest session info and all activities.
187
+ *
188
+ * @param options Optional configuration for the snapshot.
189
+ * @param options.activities If true, includes all activities in the snapshot. Defaults to true.
190
+ * @returns A `SessionSnapshot` instance.
191
+ */
192
+ snapshot(options?: {
193
+ activities?: boolean;
194
+ }): Promise<SessionSnapshot>;
195
+ }
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Copyright 2026 Google LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { ApiClient } from './api.js';
17
+ import { SessionResource } from './types.js';
18
+ import { SessionStorage } from './storage/types.js';
19
+ export type ListSessionsOptions = {
20
+ pageSize?: number;
21
+ pageToken?: string;
22
+ /**
23
+ * Hard limit on the number of items to yield when iterating.
24
+ * Useful if you want "The last 50" without manual counting.
25
+ */
26
+ limit?: number;
27
+ /**
28
+ * Whether to persist fetched sessions to local storage.
29
+ * Defaults to `true` (Write-Through Caching).
30
+ * Set to `false` to disable side effects.
31
+ */
32
+ persist?: boolean;
33
+ /**
34
+ * Filter expression to restrict the sessions returned.
35
+ * The syntax follows the AIP-160 standard (e.g., `archived = true`).
36
+ * By default, archived sessions are excluded.
37
+ */
38
+ filter?: string;
39
+ };
40
+ export type ListSessionsResponse = {
41
+ sessions: SessionResource[];
42
+ nextPageToken?: string;
43
+ };
44
+ /**
45
+ * The SessionCursor handles the complexity of pagination state.
46
+ * It is "Thenable" (acts like a Promise) and "AsyncIterable".
47
+ *
48
+ * This allows two usage patterns:
49
+ * 1. `await jules.sessions()` - Get the first page (Promise behavior).
50
+ * 2. `for await (const session of jules.sessions())` - Stream all sessions (AsyncIterable behavior).
51
+ *
52
+ * **Design Notes:**
53
+ * - **Pagination:** Handles `nextPageToken` automatically during iteration. For manual control,
54
+ * access the `nextPageToken` property on the promised response.
55
+ * - **Limiting:** The `limit` option hard-stops the iteration after N items, preventing over-fetching.
56
+ * - **Write-Through Caching:** Fetched sessions are automatically persisted to local storage
57
+ * using `storage.upsertMany()`. This ensures the local graph is populated during listing.
58
+ * - **Platform:** Fully platform-agnostic (Node.js/Browser/GAS) via the injected `ApiClient`.
59
+ */
60
+ export declare class SessionCursor implements PromiseLike<ListSessionsResponse>, AsyncIterable<SessionResource> {
61
+ private apiClient;
62
+ private storage;
63
+ private platform;
64
+ private options;
65
+ constructor(apiClient: ApiClient, storage: SessionStorage, platform: any, options?: ListSessionsOptions);
66
+ /**
67
+ * DX Feature: Promise Compatibility.
68
+ * Allows `const page = await jules.sessions()` to just get the first page.
69
+ * This is great for UIs that render a list and a "Load More" button.
70
+ */
71
+ then<TResult1 = ListSessionsResponse, TResult2 = never>(onfulfilled?: ((value: ListSessionsResponse) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): PromiseLike<TResult1 | TResult2>;
72
+ /**
73
+ * DX Feature: Async Iterator.
74
+ * Allows `for await (const s of jules.sessions())` to stream ALL items.
75
+ * Automatically handles page tokens and fetching behind the scenes.
76
+ */
77
+ [Symbol.asyncIterator](): AsyncIterator<SessionResource>;
78
+ /**
79
+ * Helper to fetch all pages into a single array.
80
+ * WARNING: Use with caution on large datasets.
81
+ */
82
+ all(): Promise<SessionResource[]>;
83
+ /**
84
+ * Internal fetcher that maps the options to the REST parameters.
85
+ */
86
+ private fetchPage;
87
+ }