@zetaloop/chappie 0.3.2 → 0.4.0
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/README.md +11 -3
- package/docs/tools.md +49 -3
- package/package.json +1 -1
- package/src/activity.ts +21 -0
- package/src/broker.ts +453 -116
- package/src/config.ts +1 -1
- package/src/delivery.ts +3 -2
- package/src/history.ts +123 -0
- package/src/instructions.md +3 -1
- package/src/ipc.ts +14 -1
- package/src/provider.ts +2 -1
- package/src/server.ts +140 -34
- package/src/session.ts +49 -7
- package/src/state.ts +13 -32
- package/src/tools.ts +10 -1
package/README.md
CHANGED
|
@@ -29,9 +29,9 @@ Call `init` from ChatGPT to connect the conversation to Pi. A conversation can r
|
|
|
29
29
|
|
|
30
30
|
## Usage
|
|
31
31
|
|
|
32
|
-
Chappie exposes common coding tools directly and every active Pi tool through `tools` and `call`. `chat` sends an assistant message to Pi, Pi input accompanies later tool results, and `transfer` moves files in either direction. `ask` can present a persistent question in ChatGPT when webpage questions are enabled.
|
|
32
|
+
Chappie exposes common coding tools directly and every active Pi tool through `tools` and `call`. `chat` sends an assistant message to Pi, Pi input accompanies later tool results, and `transfer` moves files in either direction. `history` reads recent Pi messages and activity with timestamps. `ask` can present a persistent question in ChatGPT when webpage questions are enabled.
|
|
33
33
|
|
|
34
|
-
See the [tool guide](docs/tools.md) for session selection, Pi tools, webpage questions, and file transfer.
|
|
34
|
+
See the [tool guide](docs/tools.md) for session selection, history, synchronization, Pi tools, webpage questions, and file transfer.
|
|
35
35
|
|
|
36
36
|
## Configuration
|
|
37
37
|
|
|
@@ -51,4 +51,12 @@ Remote Pi sessions connect through the broker device's mDNS name:
|
|
|
51
51
|
|
|
52
52
|
The default port is `24274`. Set `listen` to a port number or append `:port` to `connect` to use another one. Only the broker device runs otunnel; local and remote sessions appear in the same session list.
|
|
53
53
|
|
|
54
|
-
Set `ask` to `false` to disable webpage questions.
|
|
54
|
+
Set `ask` to `false` to disable webpage questions.
|
|
55
|
+
|
|
56
|
+
Optional session synchronization ends duplicate executions so one execution continues:
|
|
57
|
+
|
|
58
|
+
```json
|
|
59
|
+
{ "sync": true }
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
With synchronization enabled, initialization returns a fresh code. `sync` locks a Pi session and its bound conversations while executions verify their codes. Rejected executions announce their exit and end their responses; the verified execution confirms those exits through `chat` and `history`, then releases the lock. Codes persist in broker state; locks last for the broker process. See [synchronization](docs/tools.md#synchronization) for the tool sequence.
|
package/docs/tools.md
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
| Tool | Purpose |
|
|
4
4
|
|---|---|
|
|
5
5
|
| `init` | Select this ChatGPT conversation's default Pi session and read its environment. |
|
|
6
|
+
| `history` | Read the current Pi branch with timestamps and entry IDs. |
|
|
7
|
+
| `sync` | End duplicate executions so one execution continues. |
|
|
6
8
|
| `sessions` | List connected Pi sessions and the current default. |
|
|
7
9
|
| `tools` | Read full definitions of active Pi tools for `call`. |
|
|
8
10
|
| `chat` | Send an assistant message to Pi. |
|
|
@@ -17,14 +19,58 @@
|
|
|
17
19
|
|
|
18
20
|
## Sessions
|
|
19
21
|
|
|
20
|
-
Call `init` at the start of local work. Without `sessionId`, it reuses the conversation's saved default or selects an online Pi session with no saved ChatGPT binding. Pass a Pi session ID to resume a specific task, including from another ChatGPT conversation or branch.
|
|
22
|
+
Call `init` at the start of local work. Without `sessionId`, it reuses the conversation's saved default or selects an online Pi session with no saved ChatGPT binding. Pass a Pi session ID to resume a specific task, including from another ChatGPT conversation or branch. Read recent `history` to recover progress before continuing the current task.
|
|
21
23
|
|
|
22
|
-
`sessions` lists connected sessions with their ID, device, working directory, name, execution status, and binding count. The first
|
|
24
|
+
`sessions` lists connected sessions with their ID, device, working directory, name, execution status, and binding count. The first execution tool call establishes the default using its `sessionId` or an online session with no saved bindings. During synchronization, `chat` and `history` use the requested session solely for communication. Once a default exists, another tool's `sessionId` selects only that operation's target; `init({ sessionId })` changes the default.
|
|
23
25
|
|
|
24
|
-
Several ChatGPT conversations can use the same Pi session. One conversation can also operate on several Pi sessions explicitly. Requests already assigned to a session continue there even if the conversation later changes its default.
|
|
26
|
+
Several ChatGPT conversations can use the same Pi session. One conversation can also operate on several Pi sessions explicitly. Requests already assigned to a session continue there even if the conversation later changes its default. Synchronization can cancel ordinary requests for the locked session or its bound conversations.
|
|
25
27
|
|
|
26
28
|
Remote Pi sessions appear in the same list when they connect to a broker exposed through `listen` and `connect`. Their tools, global `AGENTS.md`, files, images, and Pi interfaces come from the remote device.
|
|
27
29
|
|
|
30
|
+
## History
|
|
31
|
+
|
|
32
|
+
`history` reads the current branch of a Pi session. It uses the saved default or an explicit `sessionId`, independently of default-session selection.
|
|
33
|
+
|
|
34
|
+
```json
|
|
35
|
+
{ "sessionId": "<session-id>", "limit": 20, "before": "<entry-id>" }
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Omit `before` for the latest entries. Use `after` to read forward from an entry. Both fields can delimit a range, with the named entries outside the returned range. The default limit is 20 readable entries. Results follow branch order and contain each entry's original ID and timestamp. `hasMore` indicates additional entries in the requested direction.
|
|
39
|
+
|
|
40
|
+
Messages, tool calls and results, summaries, images, file links, and Chappie activity records use their saved contents, including Pi's existing truncation notices and full-output paths. Assistant messages carry their originating `chatId` and optional full `requestId` in `message.chappie`. Tool results inherit the source of their `toolCallId`, including when the call falls outside the requested page. Activity records carry the same source fields. Request-specific notices display a compact label such as `ChatGPT Zxbs(fd44) joined`; the workflow suffix is for log correlation and can be shared by duplicate executions. Reading leaves a short notice in Pi; the returned history remains separate from new input and pending result delivery.
|
|
41
|
+
|
|
42
|
+
Pi user input, webpage answers, connection status, and deferred delivery target sessions or conversations. A deferred result's `requestId` identifies the original operation; the result can reach another execution in that conversation.
|
|
43
|
+
|
|
44
|
+
## Synchronization
|
|
45
|
+
|
|
46
|
+
Set `sync` to `true` in the broker's `chappie.json` to enable the `sync` tool. Each explicit initialization and first execution that establishes a default returns `initialization.code`. Retain the code in the ChatGPT context alongside its Pi session ID. Ordinary calls use the existing binding; a saved binding without a code receives one on its next execution.
|
|
47
|
+
|
|
48
|
+
When activity conflicts, start synchronization for the session:
|
|
49
|
+
|
|
50
|
+
```json
|
|
51
|
+
{ "action": "start", "sessionId": "<session-id>" }
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
This locks ordinary tools and initialization for that Pi session and every conversation currently bound to it. Existing ordinary requests in that scope are cancelled through Pi's cancellation path. Bound conversations also pause their operations on other sessions. Other conversations continue using unrelated sessions. Automatic session selection considers unlocked sessions.
|
|
55
|
+
|
|
56
|
+
`chat`, `history`, and `sessions` remain available to establish which executions must exit. A rejected execution uses `chat` for one final message with its task, entry time, and explicit exit statement, then immediately ends its ChatGPT response and all tool use. Unlocking leaves that execution finished; it must not wait, poll, reinitialize, or resume the task. The verified execution remains responsible for completing the current task. Communication tools keep existing bindings during synchronization. Pending input, webpage answers, and deferred results for the affected work remain available for normal delivery after release. Webpage components can still submit answers and the host can read exported resources.
|
|
57
|
+
|
|
58
|
+
Verify using the code from the most recent initialization:
|
|
59
|
+
|
|
60
|
+
```json
|
|
61
|
+
{ "action": "verify", "code": "<initialization-code>" }
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
The first successful verification replaces the code and returns it to that call. Verification leaves the session locked. A missing, incorrect, or older code identifies an accidental duplicate that must exit as described above. This applies to the execution, even when other executions share its conversation ID. Repeating `start` preserves the current synchronization; repeating `verify` with the verified code reads its status.
|
|
65
|
+
|
|
66
|
+
The holder of the verified code uses `chat` and `history` to identify every observed conflicting execution, require an explicit final exit message, and confirm it has ended its response. A promise to pause ordinary tools, idle Pi status, or a quiet history page alone is insufficient. After those final exits and resolution of conflicting activity, the surviving execution explicitly releases the session:
|
|
67
|
+
|
|
68
|
+
```json
|
|
69
|
+
{ "action": "release", "code": "<verified-code>" }
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Current codes are saved per Pi session in `chappie.state.json`. Activity records contain coordination details; codes stay in initialization and synchronization exchanges. Lock and verification state live in the broker process, so restarting the broker restores ordinary operation. Pi-client and tunnel reconnections retain the running broker's locks. `sessions` and `history` report the current synchronization state.
|
|
73
|
+
|
|
28
74
|
## Pi tools
|
|
29
75
|
|
|
30
76
|
`read`, `bash`, `edit`, `write`, and `transfer` are available directly. `init` includes a short catalog of the active Pi tools; use `tools` for their complete definitions and `call` to invoke extension tools.
|
package/package.json
CHANGED
package/src/activity.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface Source {
|
|
2
|
+
chatId: string;
|
|
3
|
+
requestId?: string;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface Activity extends Partial<Source> {
|
|
7
|
+
event?: string;
|
|
8
|
+
initialization?: "explicit" | "implicit";
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function source(chatId: string, requestId: unknown): Source {
|
|
12
|
+
return {
|
|
13
|
+
chatId,
|
|
14
|
+
...(typeof requestId === "string" ? { requestId } : {}),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function chatLabel({ chatId, requestId }: Source): string {
|
|
19
|
+
const workflow = requestId?.match(/^wfr_([^/]+)\//)?.[1];
|
|
20
|
+
return `ChatGPT ${chatId.slice(-4)}${workflow ? `(${workflow.slice(-4)})` : ""}`;
|
|
21
|
+
}
|