modjules 0.1.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.
@@ -0,0 +1,40 @@
1
+ import { Activity } from '../types.js';
2
+ import { ActivityStorage } from './types.js';
3
+ /**
4
+ * In-memory implementation of ActivityStorage.
5
+ * Useful for testing or environments where persistence is not required.
6
+ */
7
+ export declare class MemoryStorage implements ActivityStorage {
8
+ private activities;
9
+ /**
10
+ * Initializes the storage. No-op for memory storage.
11
+ */
12
+ init(): Promise<void>;
13
+ /**
14
+ * Closes the storage and clears memory.
15
+ */
16
+ close(): Promise<void>;
17
+ /**
18
+ * Appends an activity to the in-memory list.
19
+ *
20
+ * **Guarantee:**
21
+ * - Idempotent: If an activity with the same ID exists, it updates it in place.
22
+ * - Append-only: New activities are always added to the end.
23
+ *
24
+ * **Side Effects:**
25
+ * - Modifies the internal `activities` array.
26
+ */
27
+ append(activity: Activity): Promise<void>;
28
+ /**
29
+ * Retrieves an activity by ID.
30
+ */
31
+ get(activityId: string): Promise<Activity | undefined>;
32
+ /**
33
+ * Retrieves the latest activity.
34
+ */
35
+ latest(): Promise<Activity | undefined>;
36
+ /**
37
+ * Yields all activities in chronological order.
38
+ */
39
+ scan(): AsyncIterable<Activity>;
40
+ }
@@ -0,0 +1,54 @@
1
+ import { Activity } from '../types.js';
2
+ import { ActivityStorage } from './types.js';
3
+ /**
4
+ * Node.js filesystem implementation of ActivityStorage.
5
+ * Stores activities in a JSONL file located at `.jules/cache/<sessionId>/activities.jsonl`.
6
+ */
7
+ export declare class NodeFileStorage implements ActivityStorage {
8
+ private filePath;
9
+ private initialized;
10
+ constructor(sessionId: string, rootDir?: string);
11
+ /**
12
+ * Initializes the storage by ensuring the cache directory exists.
13
+ *
14
+ * **Side Effects:**
15
+ * - Creates the `.jules/cache/<sessionId>` directory if it does not exist.
16
+ * - Sets the internal `initialized` flag.
17
+ */
18
+ init(): Promise<void>;
19
+ /**
20
+ * Closes the storage.
21
+ */
22
+ close(): Promise<void>;
23
+ /**
24
+ * Appends an activity to the file.
25
+ *
26
+ * **Side Effects:**
27
+ * - Appends a new line containing the JSON representation of the activity to `activities.jsonl`.
28
+ * - Implicitly calls `init()` if not already initialized.
29
+ */
30
+ append(activity: Activity): Promise<void>;
31
+ /**
32
+ * Retrieves an activity by ID.
33
+ * Uses a linear scan of the file.
34
+ */
35
+ get(activityId: string): Promise<Activity | undefined>;
36
+ /**
37
+ * Retrieves the latest activity.
38
+ * Scans the entire file to find the last entry.
39
+ */
40
+ latest(): Promise<Activity | undefined>;
41
+ /**
42
+ * Yields all activities in the file.
43
+ *
44
+ * **Behavior:**
45
+ * - Opens a read stream to `activities.jsonl`.
46
+ * - Reads line-by-line using `readline`.
47
+ * - Parses each line as JSON.
48
+ *
49
+ * **Edge Cases:**
50
+ * - Logs a warning and skips lines if JSON parsing fails (corrupt data).
51
+ * - Returns immediately (yields nothing) if the file does not exist.
52
+ */
53
+ scan(): AsyncIterable<Activity>;
54
+ }
@@ -0,0 +1,38 @@
1
+ import { Activity } from '../types.js';
2
+ /**
3
+ * Abstract interface for the isomorphic storage layer.
4
+ * Implementations handle the specifics of persisting immutable activities
5
+ * to the available medium (Filesystem, IndexedDB, Memory, etc.).
6
+ */
7
+ export interface ActivityStorage {
8
+ /**
9
+ * Lifecycle method to initialize the storage (e.g., open DB connection, ensure storage directory exists).
10
+ * Must be called before any other method.
11
+ */
12
+ init(): Promise<void>;
13
+ /**
14
+ * Lifecycle method to close connections or flush buffers.
15
+ */
16
+ close(): Promise<void>;
17
+ /**
18
+ * Persists a single activity.
19
+ * Implementations MUST guarantee this is an append-only operation (or upsert if ID matches).
20
+ * It should NEVER delete or modify a different activity.
21
+ */
22
+ append(activity: Activity): Promise<void>;
23
+ /**
24
+ * Retrieves a specific activity by its ID.
25
+ * @returns The activity if found, or undefined.
26
+ */
27
+ get(activityId: string): Promise<Activity | undefined>;
28
+ /**
29
+ * Retrieves the most recently appended activity.
30
+ * Crucial for determining the high-water mark for network synchronization.
31
+ */
32
+ latest(): Promise<Activity | undefined>;
33
+ /**
34
+ * Yields all stored activities in chronological order (insertion order).
35
+ * Must support standard 'for await...of' loops.
36
+ */
37
+ scan(): AsyncIterable<Activity>;
38
+ }
@@ -0,0 +1,16 @@
1
+ import { ApiClient } from './api.js';
2
+ import { Activity, Origin } from './types.js';
3
+ import { Platform } from './platform/types.js';
4
+ /**
5
+ * Options for controlling the activity stream.
6
+ * @internal
7
+ */
8
+ export type StreamActivitiesOptions = {
9
+ /**
10
+ * Filters to exclude certain activities.
11
+ */
12
+ exclude?: {
13
+ originator: Origin;
14
+ };
15
+ };
16
+ export declare function streamActivities(sessionId: string, apiClient: ApiClient, pollingInterval: number, platform: Platform, options?: StreamActivitiesOptions): AsyncGenerator<Activity>;