@abelxiaoxing/cadence 2.0.29 → 2.0.31
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.de.md +2 -0
- package/README.es.md +2 -0
- package/README.fr.md +2 -0
- package/README.ja.md +3 -0
- package/README.ko.md +3 -0
- package/README.md +2 -0
- package/README.pt-BR.md +2 -0
- package/README.ru.md +2 -0
- package/README.zh-CN.md +2 -0
- package/docs/conversation-mode.md +3 -1
- package/docs/history.md +25 -6
- package/docs/service-management.md +3 -2
- package/package.json +3 -2
- package/src/cadence-mode.ts +3 -1
- package/src/index.ts +3 -0
- package/src/native-build.ts +1 -1
- package/src/sdk-worker.mjs +79 -20
- package/src/service/contracts/workbench.ts +449 -88
- package/src/service/coordination.ts +1 -0
- package/src/service-cli.mjs +4 -3
- package/src/service-host.mjs +2104 -1057
- package/src/session-entries.mjs +7 -0
- package/src/session-sharing.ts +120 -0
- package/web/dist/assets/cadence.css +1 -1
- package/web/dist/assets/cadence.js +13 -13
- package/web/dist/manifest.json +7 -7
- package/src/conversation-context.mjs +0 -225
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Custom Pi session entry types Cadence writes, shared by the Pi extension,
|
|
2
|
+
* the SDK worker and the owner's session reader. */
|
|
3
|
+
|
|
4
|
+
/** Native Cadence mode state, appended by the terminal extension. */
|
|
5
|
+
export const CADENCE_MODE_ENTRY = "cadence-conversation-mode/1";
|
|
6
|
+
/** Marks a session the browser created; Pi ignores it in the model context. */
|
|
7
|
+
export const WEBUI_SESSION_ENTRY = "cadence-webui/1";
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/** Tells a terminal user when the browser continued the session Pi has open.
|
|
2
|
+
* Pi holds its own copy of an open session, so the browser's messages appear
|
|
3
|
+
* here only after the session is resumed again, and a message sent here first
|
|
4
|
+
* continues from where the terminal is, as a new branch. Readonly: it never
|
|
5
|
+
* writes the session or reloads it. */
|
|
6
|
+
import {
|
|
7
|
+
closeSync,
|
|
8
|
+
constants,
|
|
9
|
+
type FSWatcher,
|
|
10
|
+
fstatSync,
|
|
11
|
+
openSync,
|
|
12
|
+
readSync,
|
|
13
|
+
watch,
|
|
14
|
+
} from "node:fs";
|
|
15
|
+
import type {
|
|
16
|
+
ExtensionAPI,
|
|
17
|
+
ExtensionContext,
|
|
18
|
+
} from "@earendil-works/pi-coding-agent";
|
|
19
|
+
|
|
20
|
+
export const CONTINUED_ELSEWHERE =
|
|
21
|
+
"This session was continued in the Cadence WebUI. Run /resume and choose it again to see those messages; a message sent here first starts a new branch from where this terminal is.";
|
|
22
|
+
|
|
23
|
+
export function registerSessionSharing(pi: ExtensionAPI): void {
|
|
24
|
+
let current: ExtensionContext | undefined;
|
|
25
|
+
let watcher: FSWatcher | undefined;
|
|
26
|
+
let file: string | undefined;
|
|
27
|
+
let offset = 0,
|
|
28
|
+
foreign = 0,
|
|
29
|
+
told = 0;
|
|
30
|
+
const reset = () => {
|
|
31
|
+
watcher?.close();
|
|
32
|
+
watcher = undefined;
|
|
33
|
+
file = undefined;
|
|
34
|
+
offset = 0;
|
|
35
|
+
foreign = 0;
|
|
36
|
+
told = 0;
|
|
37
|
+
};
|
|
38
|
+
const check = () => {
|
|
39
|
+
try {
|
|
40
|
+
observe();
|
|
41
|
+
} catch {
|
|
42
|
+
// A notice only: an unexpected context never fails Pi's own event.
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const observe = () => {
|
|
46
|
+
const ctx = current;
|
|
47
|
+
const path =
|
|
48
|
+
typeof ctx?.sessionManager?.getSessionFile === "function"
|
|
49
|
+
? ctx.sessionManager.getSessionFile()
|
|
50
|
+
: undefined;
|
|
51
|
+
if (!ctx || !path) return;
|
|
52
|
+
if (path !== file) {
|
|
53
|
+
reset();
|
|
54
|
+
file = path;
|
|
55
|
+
try {
|
|
56
|
+
watcher = watch(path, { persistent: false }, () => check());
|
|
57
|
+
watcher.on("error", () => {
|
|
58
|
+
watcher?.close();
|
|
59
|
+
watcher = undefined;
|
|
60
|
+
});
|
|
61
|
+
} catch {
|
|
62
|
+
// Pi writes a new session only after its first reply; checked again then.
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
let fd: number | undefined;
|
|
66
|
+
try {
|
|
67
|
+
fd = openSync(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
|
|
68
|
+
const size = fstatSync(fd).size;
|
|
69
|
+
if (size < offset) offset = 0;
|
|
70
|
+
if (size === offset) return;
|
|
71
|
+
const buffer = Buffer.alloc(size - offset);
|
|
72
|
+
const read = readSync(fd, buffer, 0, buffer.length, offset);
|
|
73
|
+
const end = buffer.subarray(0, read).lastIndexOf(10);
|
|
74
|
+
if (end < 0) return;
|
|
75
|
+
for (const line of buffer.subarray(0, end).toString("utf8").split("\n"))
|
|
76
|
+
try {
|
|
77
|
+
const entry: unknown = JSON.parse(line);
|
|
78
|
+
const o =
|
|
79
|
+
entry && typeof entry === "object"
|
|
80
|
+
? (entry as Record<string, unknown>)
|
|
81
|
+
: {};
|
|
82
|
+
if (
|
|
83
|
+
o.type !== "session" &&
|
|
84
|
+
typeof o.id === "string" &&
|
|
85
|
+
!ctx.sessionManager.getEntry(o.id)
|
|
86
|
+
)
|
|
87
|
+
foreign++;
|
|
88
|
+
} catch {
|
|
89
|
+
// A torn or foreign line is not this session's entry.
|
|
90
|
+
}
|
|
91
|
+
offset += end + 1;
|
|
92
|
+
} catch {
|
|
93
|
+
return;
|
|
94
|
+
} finally {
|
|
95
|
+
if (fd !== undefined) closeSync(fd);
|
|
96
|
+
}
|
|
97
|
+
if (foreign > told && ctx.hasUI) {
|
|
98
|
+
told = foreign;
|
|
99
|
+
ctx.ui.notify(CONTINUED_ELSEWHERE, "warning");
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
pi.on("session_start", (_event, ctx) => {
|
|
103
|
+
current = ctx;
|
|
104
|
+
reset();
|
|
105
|
+
check();
|
|
106
|
+
});
|
|
107
|
+
pi.on("before_agent_start", (_event, ctx) => {
|
|
108
|
+
current = ctx;
|
|
109
|
+
check();
|
|
110
|
+
return undefined;
|
|
111
|
+
});
|
|
112
|
+
pi.on("agent_settled", (_event, ctx) => {
|
|
113
|
+
current = ctx;
|
|
114
|
+
check();
|
|
115
|
+
});
|
|
116
|
+
pi.on("session_shutdown", () => {
|
|
117
|
+
reset();
|
|
118
|
+
current = undefined;
|
|
119
|
+
});
|
|
120
|
+
}
|