@zetaloop/chappie 0.3.2 → 0.4.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.
- package/README.md +11 -3
- package/docs/tools.md +51 -3
- package/package.json +1 -1
- package/src/activity.ts +21 -0
- package/src/broker.ts +459 -116
- package/src/config.ts +1 -1
- package/src/delivery.ts +3 -2
- package/src/history.ts +123 -0
- package/src/instructions.md +5 -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
|
+
Enable synchronization to resolve conflicting activity:
|
|
57
|
+
|
|
58
|
+
```json
|
|
59
|
+
{ "sync": true }
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Initialization returns a short name and a private code. `sync` pauses conflicting work for discussion through `chat` and `history`. The verified coordinator decides who continues, their tasks, and who exits, including retaining only one execution. See [synchronization](docs/tools.md#synchronization).
|
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` | Resolve conflicting activity under one coordinator. |
|
|
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,60 @@
|
|
|
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
|
-
|
|
24
|
+
Initialization returns the request suffix as `initialization.name` when available. Each execution retains its own name for coordination through `chat`.
|
|
23
25
|
|
|
24
|
-
|
|
26
|
+
`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.
|
|
27
|
+
|
|
28
|
+
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
29
|
|
|
26
30
|
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
31
|
|
|
32
|
+
## History
|
|
33
|
+
|
|
34
|
+
`history` reads the current branch of a Pi session. It uses the saved default or an explicit `sessionId`, independently of default-session selection.
|
|
35
|
+
|
|
36
|
+
```json
|
|
37
|
+
{ "sessionId": "<session-id>", "limit": 20, "before": "<entry-id>" }
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
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.
|
|
41
|
+
|
|
42
|
+
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 parallel executions. When participants report different goals, workflow timing helps identify possible work resumed from an earlier ChatGPT message. Reading leaves a short notice in Pi; the returned history remains separate from new input and pending result delivery.
|
|
43
|
+
|
|
44
|
+
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.
|
|
45
|
+
|
|
46
|
+
## Synchronization
|
|
47
|
+
|
|
48
|
+
Enable `sync` in the broker's `chappie.json`. Initialization returns a private `initialization.code` for its Pi session; a saved binding without a code receives one on its next execution.
|
|
49
|
+
|
|
50
|
+
When activity conflicts, start synchronization:
|
|
51
|
+
|
|
52
|
+
```json
|
|
53
|
+
{ "action": "start", "sessionId": "<session-id>" }
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
This locks ordinary tools and initialization for the Pi session and its bound conversations, cancelling their active ordinary requests. Bound conversations also pause work on other sessions; unrelated conversations continue. `chat`, `history`, and `sessions` remain available with existing bindings.
|
|
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 returns a replacement code to the coordinator. Everyone can discuss goals and progress through `chat` and `history`, including executions with missing or rejected codes. The coordinator decides who continues, their tasks, and who exits, and may retain only one execution.
|
|
65
|
+
|
|
66
|
+
Participants acknowledge the decision. Those directed to exit leave a chat handoff and end their responses. Only the coordinator can release, after these decisions and exits are confirmed:
|
|
67
|
+
|
|
68
|
+
```json
|
|
69
|
+
{ "action": "release", "code": "<verified-code>" }
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Remaining executions resume their assigned work. Pending input, webpage answers, and deferred results resume normal delivery. Webpage submissions and exported resource reads remain available throughout synchronization.
|
|
73
|
+
|
|
74
|
+
Codes persist per Pi session in `chappie.state.json`; locks last for the broker process and survive Pi-client or tunnel reconnections. Repeated `start` preserves the lock; `verify` with the current code, `sessions`, and `history` report its status.
|
|
75
|
+
|
|
28
76
|
## Pi tools
|
|
29
77
|
|
|
30
78
|
`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
|
+
}
|