@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,46 @@
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 { Activity, PullRequest, SessionInsights, SessionResource, SessionSnapshot, SessionState, SerializedSnapshot, TimelineEntry, GeneratedFiles, ChangeSet, ToJSONOptions } from './types.js';
17
+ export interface SessionSnapshotOptions {
18
+ data: {
19
+ session: SessionResource;
20
+ activities?: Activity[];
21
+ };
22
+ }
23
+ export declare class SessionSnapshotImpl implements SessionSnapshot {
24
+ readonly id: string;
25
+ readonly state: SessionState;
26
+ readonly url: string;
27
+ readonly createdAt: Date;
28
+ readonly updatedAt: Date;
29
+ readonly durationMs: number;
30
+ readonly prompt: string;
31
+ readonly title: string;
32
+ readonly pr?: PullRequest;
33
+ readonly activities: readonly Activity[];
34
+ readonly activityCounts: Readonly<Record<string, number>>;
35
+ readonly timeline: readonly TimelineEntry[];
36
+ readonly insights: SessionInsights;
37
+ readonly generatedFiles: GeneratedFiles;
38
+ readonly changeSet: () => ChangeSet | undefined;
39
+ constructor(options: SessionSnapshotOptions);
40
+ private computeActivityCounts;
41
+ private computeTimeline;
42
+ private generateSummary;
43
+ private computeInsights;
44
+ toJSON(options?: ToJSONOptions): Partial<SerializedSnapshot>;
45
+ toMarkdown(): string;
46
+ }
@@ -0,0 +1,23 @@
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 { SourceManager } from './types.js';
18
+ /**
19
+ * Creates a SourceManager instance.
20
+ * The SourceManager is a callable object (an async iterator) with a `get` method attached.
21
+ * @internal
22
+ */
23
+ export declare function createSourceManager(apiClient: ApiClient): SourceManager;
@@ -0,0 +1,43 @@
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 { Activity } from '../types.js';
17
+ /**
18
+ * Represents the cache information for a single session.
19
+ */
20
+ export type SessionCacheInfo = {
21
+ sessionId: string;
22
+ activityCount: number;
23
+ lastSyncedAt: Date;
24
+ };
25
+ /**
26
+ * Represents global cache information.
27
+ */
28
+ export type GlobalCacheInfo = {
29
+ lastSyncedAt: Date;
30
+ sessionCount: number;
31
+ };
32
+ /**
33
+ * Retrieves cache information for a specific session.
34
+ *
35
+ * @param sessionId - The ID of the session.
36
+ * @returns A promise that resolves with the session's cache information, or null if not found.
37
+ */
38
+ export declare function getSessionCacheInfo(sessionId: string, rootDirOverride?: string): Promise<SessionCacheInfo | null>;
39
+ export declare function updateGlobalCacheMetadata(rootDirOverride?: string): Promise<void>;
40
+ export declare function getCacheInfo(rootDirOverride?: string): Promise<GlobalCacheInfo>;
41
+ export declare function getSessionCount(rootDirOverride?: string): Promise<number>;
42
+ export declare function getActivityCount(sessionId: string, rootDirOverride?: string): Promise<number>;
43
+ export declare function getLatestActivities(sessionId: string, n: number, rootDirOverride?: string): Promise<Activity[]>;
@@ -0,0 +1,69 @@
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 { Activity, SessionResource } from '../types.js';
17
+ import { ActivityStorage, SessionStorage, CachedSession, SessionIndexEntry } from './types.js';
18
+ /**
19
+ * In-memory implementation of ActivityStorage.
20
+ * Useful for testing or environments where persistence is not required.
21
+ */
22
+ export declare class MemoryStorage implements ActivityStorage {
23
+ private activities;
24
+ private indices;
25
+ /**
26
+ * Initializes the storage. No-op for memory storage.
27
+ */
28
+ init(): Promise<void>;
29
+ /**
30
+ * Closes the storage and clears memory.
31
+ */
32
+ close(): Promise<void>;
33
+ /**
34
+ * Appends an activity to the in-memory list.
35
+ *
36
+ * **Guarantee:**
37
+ * - Idempotent: If an activity with the same ID exists, it updates it in place.
38
+ * - Append-only: New activities are always added to the end.
39
+ *
40
+ * **Side Effects:**
41
+ * - Modifies the internal `activities` array.
42
+ */
43
+ append(activity: Activity): Promise<void>;
44
+ /**
45
+ * Retrieves an activity by ID.
46
+ */
47
+ get(activityId: string): Promise<Activity | undefined>;
48
+ /**
49
+ * Retrieves the latest activity.
50
+ */
51
+ latest(): Promise<Activity | undefined>;
52
+ /**
53
+ * Yields all activities in chronological order.
54
+ */
55
+ scan(): AsyncIterable<Activity>;
56
+ }
57
+ /**
58
+ * In-memory implementation of SessionStorage.
59
+ */
60
+ export declare class MemorySessionStorage implements SessionStorage {
61
+ private sessions;
62
+ private index;
63
+ init(): Promise<void>;
64
+ upsert(session: SessionResource): Promise<void>;
65
+ upsertMany(sessions: SessionResource[]): Promise<void>;
66
+ get(sessionId: string): Promise<CachedSession | undefined>;
67
+ delete(sessionId: string): Promise<void>;
68
+ scanIndex(): AsyncIterable<SessionIndexEntry>;
69
+ }
@@ -0,0 +1,95 @@
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 { Activity, SessionResource } from '../types.js';
17
+ import { ActivityStorage, SessionStorage, CachedSession, SessionIndexEntry } from './types.js';
18
+ /**
19
+ * Node.js filesystem implementation of ActivityStorage.
20
+ * Stores activities in a JSONL file located at `.jules/cache/<sessionId>/activities.jsonl`.
21
+ */
22
+ export declare class NodeFileStorage implements ActivityStorage {
23
+ private filePath;
24
+ private metadataPath;
25
+ private initialized;
26
+ private writeStream;
27
+ private index;
28
+ private indexBuilt;
29
+ private indexBuildPromise;
30
+ private currentFileSize;
31
+ constructor(sessionId: string, rootDir: string);
32
+ /**
33
+ * Initializes the storage by ensuring the cache directory exists.
34
+ *
35
+ * **Side Effects:**
36
+ * - Creates the `.jules/cache/<sessionId>` directory if it does not exist.
37
+ * - Sets the internal `initialized` flag.
38
+ */
39
+ init(): Promise<void>;
40
+ /**
41
+ * Closes the storage.
42
+ */
43
+ close(): Promise<void>;
44
+ private _readMetadata;
45
+ private _writeMetadata;
46
+ /**
47
+ * Appends an activity to the file.
48
+ *
49
+ * **Side Effects:**
50
+ * - Appends a new line containing the JSON representation of the activity to `activities.jsonl`.
51
+ * - Implicitly calls `init()` if not already initialized.
52
+ */
53
+ append(activity: Activity): Promise<void>;
54
+ /**
55
+ * Builds the in-memory index by scanning the file once.
56
+ * Handles concurrency by coalescing multiple calls into a single promise.
57
+ */
58
+ private buildIndex;
59
+ /**
60
+ * Retrieves an activity by ID.
61
+ * Uses an in-memory index (ID -> Offset) to seek directly to the line.
62
+ */
63
+ get(activityId: string): Promise<Activity | undefined>;
64
+ /**
65
+ * Retrieves the latest activity.
66
+ * Efficiently reads the file backwards to find the last valid entry.
67
+ */
68
+ latest(): Promise<Activity | undefined>;
69
+ /**
70
+ * Yields all activities in the file.
71
+ *
72
+ * **Behavior:**
73
+ * - Opens a read stream to `activities.jsonl`.
74
+ * - Reads line-by-line using `readline`.
75
+ * - Parses each line as JSON.
76
+ *
77
+ * **Edge Cases:**
78
+ * - Logs a warning and skips lines if JSON parsing fails (corrupt data).
79
+ * - Returns immediately (yields nothing) if the file does not exist.
80
+ */
81
+ scan(): AsyncIterable<Activity>;
82
+ }
83
+ export declare class NodeSessionStorage implements SessionStorage {
84
+ private cacheDir;
85
+ private indexFilePath;
86
+ private initialized;
87
+ constructor(rootDir: string);
88
+ init(): Promise<void>;
89
+ private getSessionPath;
90
+ upsert(session: SessionResource): Promise<void>;
91
+ upsertMany(sessions: SessionResource[]): Promise<void>;
92
+ get(sessionId: string): Promise<CachedSession | undefined>;
93
+ delete(sessionId: string): Promise<void>;
94
+ scanIndex(): AsyncIterable<SessionIndexEntry>;
95
+ }
@@ -0,0 +1,17 @@
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 declare function isWritable(dir: string): boolean;
17
+ export declare function getRootDir(): string;
@@ -0,0 +1,115 @@
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 { Activity, SessionResource } from '../types.js';
17
+ /**
18
+ * Represents the wrapper around the raw resource, adding local metadata.
19
+ */
20
+ export type CachedSession = {
21
+ resource: SessionResource;
22
+ _lastSyncedAt: number;
23
+ };
24
+ /**
25
+ * Subset of session fields required for the high-speed index.
26
+ * These are the fields we can filter on without opening the heavy session file.
27
+ */
28
+ export type SessionIndexEntry = {
29
+ id: string;
30
+ title: string;
31
+ state: string;
32
+ createTime: string;
33
+ source: string;
34
+ _updatedAt: number;
35
+ };
36
+ /**
37
+ * Ephemeral (but persisted) metadata about a session's cache state.
38
+ * Stored separately from the main session.json to allow for frequent updates
39
+ * without rewriting the larger session object.
40
+ */
41
+ export type SessionMetadata = {
42
+ activityCount: number;
43
+ };
44
+ export interface SessionStorage {
45
+ /**
46
+ * Initializes the storage (ensure directories exist).
47
+ */
48
+ init(): Promise<void>;
49
+ /**
50
+ * Persists a session state.
51
+ * 1. Writes the full resource to atomic storage (.jules/cache/<id>/session.json).
52
+ * 2. Appends metadata to the high-speed index (.jules/cache/sessions.jsonl).
53
+ */
54
+ upsert(session: SessionResource): Promise<void>;
55
+ /**
56
+ * Bulk optimization for upserting pages from the API.
57
+ */
58
+ upsertMany(sessions: SessionResource[]): Promise<void>;
59
+ /**
60
+ * Retrieves a specific session by ID.
61
+ * Returns undefined if not found or if the file is corrupt.
62
+ */
63
+ get(sessionId: string): Promise<CachedSession | undefined>;
64
+ /**
65
+ * Deletes a session and its associated artifacts from local cache.
66
+ */
67
+ delete(sessionId: string): Promise<void>;
68
+ /**
69
+ * Scans the high-speed index.
70
+ * Implementation MUST handle deduplication (Last-Write-Wins) because the
71
+ * index is an append-only log.
72
+ */
73
+ scanIndex(): AsyncIterable<SessionIndexEntry>;
74
+ }
75
+ /**
76
+ * Abstract interface for the isomorphic storage layer.
77
+ * Implementations handle the specifics of persisting immutable activities
78
+ * to the available medium (Filesystem, IndexedDB, Memory, etc.).
79
+ */
80
+ export interface ActivityStorage {
81
+ /**
82
+ * Lifecycle method to initialize the storage (e.g., open DB connection, ensure storage directory exists).
83
+ * Must be called before any other method.
84
+ */
85
+ init(): Promise<void>;
86
+ /**
87
+ * Lifecycle method to close connections or flush buffers.
88
+ */
89
+ close(): Promise<void>;
90
+ /**
91
+ * Persists a single activity.
92
+ * Implementations MUST guarantee this is an append-only operation (or upsert if ID matches).
93
+ * It should NEVER delete or modify a different activity.
94
+ */
95
+ append(activity: Activity): Promise<void>;
96
+ /**
97
+ * Retrieves a specific activity by its ID.
98
+ * @returns The activity if found, or undefined.
99
+ */
100
+ get(activityId: string): Promise<Activity | undefined>;
101
+ /**
102
+ * Retrieves the most recently appended activity.
103
+ * Crucial for determining the high-water mark for network synchronization.
104
+ */
105
+ latest(): Promise<Activity | undefined>;
106
+ /**
107
+ * Yields all stored activities in chronological order (insertion order).
108
+ * Must support standard 'for await...of' loops.
109
+ */
110
+ scan(): AsyncIterable<Activity>;
111
+ }
112
+ export interface GlobalCacheMetadata {
113
+ lastSyncedAt: number;
114
+ sessionCount: number;
115
+ }
@@ -0,0 +1,47 @@
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 { Activity, Origin } from './types.js';
18
+ /**
19
+ * Options for controlling the activity stream.
20
+ * @internal
21
+ */
22
+ export type StreamActivitiesOptions = {
23
+ /**
24
+ * Filters to exclude certain activities.
25
+ */
26
+ exclude?: {
27
+ originator: Origin;
28
+ };
29
+ /**
30
+ * Number of retries for initial 404 errors when session is not yet ready.
31
+ * @default 10
32
+ */
33
+ initialRetries?: number;
34
+ };
35
+ /**
36
+ * An async generator that implements a hybrid pagination/polling strategy
37
+ * to stream activities for a given session.
38
+ *
39
+ * @param sessionId The ID of the session to stream activities for.
40
+ * @param apiClient The API client to use for requests.
41
+ * @param pollingInterval The time in milliseconds to wait before polling for new activities.
42
+ * @param platform The platform adapter.
43
+ * @param options Streaming options, including filters.
44
+ * @internal
45
+ */
46
+ import { Platform } from './platform/types.js';
47
+ export declare function streamActivities(sessionId: string, apiClient: ApiClient, pollingInterval: number, platform: Platform, options?: StreamActivitiesOptions): AsyncGenerator<Activity>;