@abelxiaoxing/cadence 2.0.27 → 2.0.29
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 -1
- package/README.es.md +2 -1
- package/README.fr.md +2 -1
- package/README.ja.md +3 -1
- package/README.ko.md +5 -1
- package/README.md +2 -1
- package/README.pt-BR.md +2 -1
- package/README.ru.md +2 -1
- package/README.zh-CN.md +2 -1
- package/docs/service-management.md +23 -1
- package/package.json +1 -1
- package/src/conversation-context.mjs +84 -19
- package/src/native-build.ts +1 -1
- package/src/sdk-worker.mjs +5 -4
- package/src/service/contracts/workbench.ts +89 -6
- package/src/service-cli.mjs +390 -64
- package/src/service-host.mjs +1632 -706
- package/web/dist/assets/cadence.css +1 -1
- package/web/dist/assets/cadence.js +16 -16
- package/web/dist/manifest.json +7 -7
package/README.de.md
CHANGED
|
@@ -88,11 +88,12 @@ Ihre tatsächlichen Ergebnisse bleiben von der automatischen Agent-Prüfung getr
|
|
|
88
88
|
```sh
|
|
89
89
|
cadence server status
|
|
90
90
|
cadence server restart # nach einem Upgrade oder einer .env / models.json-Änderung
|
|
91
|
+
cadence server upgrade # npm-Globalinstallation: laden, installieren, neu starten
|
|
91
92
|
cadence server stop # bleibt registriert und startet beim nächsten Boot oder Login erneut
|
|
92
93
|
cadence server uninstall # vor npm uninstall -g ausführen
|
|
93
94
|
```
|
|
94
95
|
|
|
95
|
-
Upgrade mit `
|
|
96
|
+
Upgrade mit `cadence server upgrade` oder im Cadence-Dienstdialog der WebUI: Die Version wird geladen, während Cadence weiterläuft, und die vorherige Version kommt zurück, wenn die neue nicht startet.
|
|
96
97
|
Restart, Stop und Uninstall stoppen laufende Arbeit geordnet, statt sie getrennt zurückzulassen.
|
|
97
98
|
Uninstall entfernt nur die Dienstdefinition; Projekte, Historie und Pi-Einstellungen bleiben.
|
|
98
99
|
Linux-Root- und benannte Dienste, entfernter HTTPS-Zugang und Wiederherstellung sind in [Dienstverwaltung](docs/service-management.md) und [Fernzugriff](docs/remote-access.md) beschrieben.
|
package/README.es.md
CHANGED
|
@@ -88,11 +88,12 @@ Sus resultados reales se mantienen separados de la revisión automática del age
|
|
|
88
88
|
```sh
|
|
89
89
|
cadence server status
|
|
90
90
|
cadence server restart # después de una actualización o un cambio de .env / models.json
|
|
91
|
+
cadence server upgrade # instalación global de npm: descargar, instalar y reiniciar
|
|
91
92
|
cadence server stop # permanece registrado y vuelve a iniciar en el próximo arranque o inicio de sesión
|
|
92
93
|
cadence server uninstall # ejecutar antes de npm uninstall -g
|
|
93
94
|
```
|
|
94
95
|
|
|
95
|
-
Actualiza con `
|
|
96
|
+
Actualiza con `cadence server upgrade` o desde el diálogo del servicio Cadence de la WebUI: descarga la versión mientras Cadence sigue en marcha y restaura la anterior si la nueva no arranca.
|
|
96
97
|
Restart, stop y uninstall detienen el trabajo en ejecución en orden en lugar de dejarlo desconectado.
|
|
97
98
|
Uninstall solo elimina la definición del servicio; los proyectos, el historial y la configuración de Pi permanecen.
|
|
98
99
|
Los servicios raíz de Linux y con nombre, el acceso HTTPS remoto y la recuperación se cubren en [gestión del servicio](docs/service-management.md) y [acceso remoto](docs/remote-access.md).
|
package/README.fr.md
CHANGED
|
@@ -88,11 +88,12 @@ Leurs résultats restent distincts de la revue automatique par un Agent.
|
|
|
88
88
|
```sh
|
|
89
89
|
cadence server status
|
|
90
90
|
cadence server restart # après une mise à niveau ou un changement de .env / models.json
|
|
91
|
+
cadence server upgrade # installation npm globale : télécharger, installer, redémarrer
|
|
91
92
|
cadence server stop # reste enregistré et redémarre au prochain boot ou connexion
|
|
92
93
|
cadence server uninstall # à exécuter avant npm uninstall -g
|
|
93
94
|
```
|
|
94
95
|
|
|
95
|
-
Mettez à niveau avec `
|
|
96
|
+
Mettez à niveau avec `cadence server upgrade` ou depuis la boîte de dialogue du service Cadence de la WebUI : la version est téléchargée pendant que Cadence continue de tourner, et la précédente est réinstallée si la nouvelle ne démarre pas.
|
|
96
97
|
Restart, stop et uninstall arrêtent le travail en cours dans l'ordre au lieu de le laisser déconnecté.
|
|
97
98
|
Uninstall supprime uniquement la définition du service ; les projets, l'historique et les réglages de Pi restent.
|
|
98
99
|
Les services racine Linux et nommés, l'accès HTTPS distant et la récupération sont couverts par [gestion du service](docs/service-management.md) et [accès distant](docs/remote-access.md).
|
package/README.ja.md
CHANGED
|
@@ -102,11 +102,13 @@ WebUI のフォルダピッカーも同じ方法でプロジェクトを開く
|
|
|
102
102
|
```sh
|
|
103
103
|
cadence server status
|
|
104
104
|
cadence server restart # アップグレードや .env / models.json の変更後
|
|
105
|
+
cadence server upgrade # npm グローバルインストール: 取得、インストール、再起動
|
|
105
106
|
cadence server stop # 登録は保持され、次の起動またはログイン時に再び起動する
|
|
106
107
|
cadence server uninstall # npm uninstall -g の前に実行
|
|
107
108
|
```
|
|
108
109
|
|
|
109
|
-
`
|
|
110
|
+
`cadence server upgrade` または WebUI の Cadence サービスダイアログでアップグレードします。
|
|
111
|
+
Cadence の実行中に新しいバージョンを取得し、新しいバージョンが起動しない場合は以前のバージョンに戻します。
|
|
110
112
|
restart、stop、uninstall はデタッチしたままにせずに、実行中の作業を順番に停止する。
|
|
111
113
|
uninstall はサービス定義のみを削除する。
|
|
112
114
|
プロジェクト、履歴、Pi の設定は残る。
|
package/README.ko.md
CHANGED
|
@@ -99,11 +99,15 @@ WebUI 폴더 선택기도 같은 방법으로 프로젝트를 엽니다.
|
|
|
99
99
|
```sh
|
|
100
100
|
cadence server status
|
|
101
101
|
cadence server restart # 업그레이드나 .env / models.json 변경 후
|
|
102
|
+
cadence server upgrade # npm 전역 설치: 받기, 설치, 재시작
|
|
102
103
|
cadence server stop # 등록은 유지되고 다음 부팅 또는 로그인 시 다시 시작
|
|
103
104
|
cadence server uninstall # npm uninstall -g 전에 실행
|
|
104
105
|
```
|
|
105
106
|
|
|
106
|
-
`
|
|
107
|
+
`cadence server upgrade` 또는 WebUI의 Cadence 서비스 대화 상자로 업그레이드합니다.
|
|
108
|
+
Cadence가 실행 중일 때 새 버전을 받아 두고, 새 버전이 시작되지 않으면 이전 버전으로 되돌립니다.
|
|
109
|
+
Restart, stop, uninstall는 작업이 연결 끊긴 채로 남지 않도록 실행 중인 작업을 순서대로 멈춥니다.
|
|
110
|
+
Uninstall은 서비스 정의만 제거합니다.
|
|
107
111
|
프로젝트, 역사, Pi 설정은 유지됩니다.
|
|
108
112
|
Linux 루트 및 이름 지정 서비스, 원격 HTTPS 액세스, 복구에는 [서비스 관리](docs/service-management.md)와 [원격 액세스](docs/remote-access.md)를 참조하세요.
|
|
109
113
|
|
package/README.md
CHANGED
|
@@ -87,6 +87,7 @@ Their actual outcomes remain separate from automatic Agent review.
|
|
|
87
87
|
```sh
|
|
88
88
|
cadence server status
|
|
89
89
|
cadence server restart # after an upgrade or a .env / models.json change
|
|
90
|
+
cadence server upgrade # npm global install: fetch, install and restart
|
|
90
91
|
cadence server stop # stays registered and starts again at the next boot or login
|
|
91
92
|
cadence server uninstall # run before npm uninstall -g
|
|
92
93
|
cadence doctor # what is left over or recently recovered; --fix for the rest
|
|
@@ -94,7 +95,7 @@ cadence doctor # what is left over or recently recovered; --fix for
|
|
|
94
95
|
|
|
95
96
|
A power loss, shutdown or crash needs no cleanup: the next start recovers automatically, marks interrupted work as interrupted and says what it did.
|
|
96
97
|
|
|
97
|
-
Upgrade with `
|
|
98
|
+
Upgrade with `cadence server upgrade` or from the WebUI's Cadence service dialog: it fetches the release while Cadence keeps running and puts the previous version back if the new one does not start.
|
|
98
99
|
Restart, stop and uninstall stop running work in order rather than leaving it detached.
|
|
99
100
|
Uninstall removes only the service definition; projects, history and Pi settings stay.
|
|
100
101
|
Linux root and named services, remote HTTPS access and automatic recovery are covered in [service management](docs/service-management.md) and [remote access](docs/remote-access.md).
|
package/README.pt-BR.md
CHANGED
|
@@ -88,11 +88,12 @@ Os resultados reais permanecem separados da revisão automática do agente.
|
|
|
88
88
|
```sh
|
|
89
89
|
cadence server status
|
|
90
90
|
cadence server restart # após um upgrade ou uma alteração de .env / models.json
|
|
91
|
+
cadence server upgrade # instalação global do npm: baixar, instalar e reiniciar
|
|
91
92
|
cadence server stop # permanece registrado e inicia de novo no próximo boot ou login
|
|
92
93
|
cadence server uninstall # executar antes de npm uninstall -g
|
|
93
94
|
```
|
|
94
95
|
|
|
95
|
-
Faça upgrade com `
|
|
96
|
+
Faça upgrade com `cadence server upgrade` ou pela caixa de diálogo do serviço Cadence na WebUI: a versão é baixada enquanto o Cadence continua em execução, e a anterior volta se a nova não iniciar.
|
|
96
97
|
Restart, stop e uninstall param o trabalho em execução em ordem, em vez de deixá-lo desconectado.
|
|
97
98
|
Uninstall remove apenas a definição do serviço; projetos, histórico e configurações do Pi permanecem.
|
|
98
99
|
Serviços root e nomeados do Linux, acesso HTTPS remoto e recuperação estão cobertos em [gerenciamento do serviço](docs/service-management.md) e [acesso remoto](docs/remote-access.md).
|
package/README.ru.md
CHANGED
|
@@ -88,11 +88,12 @@ cadence project open /absolute/new-project --create
|
|
|
88
88
|
```sh
|
|
89
89
|
cadence server status
|
|
90
90
|
cadence server restart # после обновления или изменения .env / models.json
|
|
91
|
+
cadence server upgrade # глобальная установка npm: загрузить, установить, перезапустить
|
|
91
92
|
cadence server stop # остаётся зарегистрированной и снова запускается при следующей загрузке или входе
|
|
92
93
|
cadence server uninstall # выполнить перед npm uninstall -g
|
|
93
94
|
```
|
|
94
95
|
|
|
95
|
-
Обновляйте с помощью `
|
|
96
|
+
Обновляйте с помощью `cadence server upgrade` или в диалоге службы Cadence в WebUI: новая версия загружается, пока Cadence продолжает работать, а если она не запускается, возвращается предыдущая.
|
|
96
97
|
Restart, stop и uninstall останавливают выполняемую работу по порядку, а не оставляют её отключённой.
|
|
97
98
|
Uninstall удаляет только определение службы; проекты, история и настройки Pi остаются.
|
|
98
99
|
Корневые и именованные службы Linux, удалённый HTTPS-доступ и восстановление описаны в [управлении службой](docs/service-management.md) и [удалённом доступе](docs/remote-access.md).
|
package/README.zh-CN.md
CHANGED
|
@@ -88,11 +88,12 @@ cadence project open /absolute/new-project --create
|
|
|
88
88
|
```sh
|
|
89
89
|
cadence server status
|
|
90
90
|
cadence server restart # 升级或修改 .env / models.json 之后
|
|
91
|
+
cadence server upgrade # npm 全局安装:下载、安装并重启
|
|
91
92
|
cadence server stop # 保持注册状态,并在下次启动或登录时再次启动
|
|
92
93
|
cadence server uninstall # 在 npm uninstall -g 之前运行
|
|
93
94
|
```
|
|
94
95
|
|
|
95
|
-
用 `
|
|
96
|
+
用 `cadence server upgrade` 或 WebUI 的 Cadence 服务对话框升级:它在 Cadence 继续运行时先下载新版本,新版本无法启动时会装回原版本。
|
|
96
97
|
restart、stop 和 uninstall 按顺序停止运行中的工作,而不是留下断开连接的工作。
|
|
97
98
|
uninstall 只删除服务定义;项目、历史和 Pi 设置保留。
|
|
98
99
|
Linux root 与命名服务、远程 HTTPS 访问和恢复见[服务管理](docs/service-management.md)和[远程访问](docs/remote-access.md)。
|
|
@@ -74,11 +74,12 @@ Changing to root changes the effective account and its private namespace: stop a
|
|
|
74
74
|
cadence server install [--workspace /absolute/project] [--system|--user] [--no-linger]
|
|
75
75
|
cadence server status
|
|
76
76
|
cadence server restart
|
|
77
|
+
cadence server upgrade [--to VERSION]
|
|
77
78
|
cadence server stop
|
|
78
79
|
cadence server uninstall
|
|
79
80
|
```
|
|
80
81
|
|
|
81
|
-
Only these explicit commands register, change or remove the service; no package install, update hook, `/cadence` or browser visit does.
|
|
82
|
+
Only these explicit commands and the WebUI's confirmed [restart and upgrade](#restart-and-upgrade-from-the-webui) register, change or remove the service; no package install, update hook, `/cadence` or browser visit does.
|
|
82
83
|
The package has no install script, so npm 12 and Bun skipping untrusted scripts by default changes nothing; the pinned Pi SDK's blocked `@google/genai` preinstall only echoes `no-op`, and its `protobufjs` postinstall only warns about version schemes.
|
|
83
84
|
Linux server commands accept `--system` or `--user` after the action; root defaults to system scope and other accounts to user scope.
|
|
84
85
|
`--system` requires root and never runs sudo itself; `--user` explicitly selects the legacy per-user manager, even when invoked by root.
|
|
@@ -97,6 +98,9 @@ A successful manager start request is not owner readiness: an unready owner repo
|
|
|
97
98
|
Status also retains the manager's `active`/`activating`/`failed` observation separately.
|
|
98
99
|
A definition whose project directory was removed gets a readable refusal (exit78, so the unit does not restart in a loop); `cadence server install` switches it to the workbench.
|
|
99
100
|
`restart` rewrites an existing definition with the current Node and package paths, keeping its workspace and the user's disable choices, and starts it; run it after an npm upgrade, a Node change or a `models.json` edit.
|
|
101
|
+
The `upgrade` command (Linux) installs the latest version, or exactly `--to VERSION`, with npm and restarts; see [Restart and upgrade from the WebUI](#restart-and-upgrade-from-the-webui) for its steps.
|
|
102
|
+
Commands that change the service (`install`, `restart`, `stop`, `uninstall`, `upgrade`) refuse with `inside-service` when they run inside the service they would stop, for example from a tool of its own agent: stopping a systemd unit ends every process in it, so the command would die before it started the service again.
|
|
103
|
+
Use the WebUI or a terminal outside the service instead.
|
|
100
104
|
`stop` joins the workbench's accepted openings and associated exact-epoch project owners, then closes the entry; unrelated project owners stay independent.
|
|
101
105
|
An associated owner that is not running (or whose directory is gone) has nothing to stop; one whose Stop is unconfirmed keeps its own state, and the workbench still stops.
|
|
102
106
|
Project-specific `stop --workspace <path>` remains scoped to that owner.
|
|
@@ -116,6 +120,24 @@ It is a warning rather than part of the info card because Pi's TUI replaces one
|
|
|
116
120
|
The readonly `/cadence-history` client names the same management command when no owner exists; daily `/cadence` instead uses explicit on-demand project startup, without requiring a boot service.
|
|
117
121
|
A machine without a supported user service manager and `CADENCE_AUTOSTART=0` keep both quiet; with `CADENCE_LINGER=0` they suggest `--no-linger`.
|
|
118
122
|
|
|
123
|
+
### Restart and upgrade from the WebUI
|
|
124
|
+
|
|
125
|
+
On Linux the workbench has a **Cadence service** dialog: the server button on the entry page, or **More → Cadence service** in a project.
|
|
126
|
+
It shows the running version and its systemd unit, asks npm for the latest version only when you press **Check for updates**, and offers **Restart service** and **Upgrade to VERSION**.
|
|
127
|
+
The confirmation names the running workflows and conversations the restart stops; they stop through the orderly Stop, never by a signal.
|
|
128
|
+
If work starts or ends before you confirm, the request is refused as stale and the dialog reads the service again.
|
|
129
|
+
|
|
130
|
+
The request runs outside the service, in a transient unit `cadence.maintenance.service` (`cadence-NAME.maintenance.service` for a named service), so closing or reloading the page does not interrupt it and one job runs at a time.
|
|
131
|
+
It runs the same `cadence server restart` or `cadence server upgrade`, then records its outcome; the page waits for that record and offers to reload.
|
|
132
|
+
If it reports nothing, see `journalctl --user -u cadence.maintenance.service` (without `--user` for a system service) and `cadence server status`.
|
|
133
|
+
|
|
134
|
+
An upgrade fetches the exact release while the service still runs, so an unreachable registry changes nothing.
|
|
135
|
+
Then it stops the service, installs the release with `npm install --global` and starts the new copy's own `server restart`.
|
|
136
|
+
A new version that does not become ready is replaced by the previous version again from npm's cache.
|
|
137
|
+
The npm calls use npm's own configuration (`~/.npmrc` registry, proxy and prefix).
|
|
138
|
+
Only a copy that `npm root --global` names, and that the service account can write, upgrades itself; the dialog says when another installation (Pi's own copy, a checkout, Bun, a root-owned prefix) has to be upgraded the way it was installed, followed by `cadence server restart`.
|
|
139
|
+
A workbench that was not started by its systemd service, and services on macOS and Windows, show the version only; restart and upgrade them in a terminal.
|
|
140
|
+
|
|
119
141
|
### One copy for Pi and the service
|
|
120
142
|
|
|
121
143
|
After `npm install -g`, `pi install "$(npm root -g)/@abelxiaoxing/cadence"` records that path and loads it in place, so an npm upgrade updates the service and native `/cadence` together.
|
package/package.json
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
/** Private ordinary-chat context. No Pi session import, hidden thinking or provider envelopes. */
|
|
2
|
-
import {
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import {
|
|
4
|
+
closeSync,
|
|
5
|
+
constants,
|
|
6
|
+
fstatSync,
|
|
7
|
+
lstatSync,
|
|
8
|
+
openSync,
|
|
9
|
+
readSync,
|
|
10
|
+
} from "node:fs";
|
|
11
|
+
import { dirname, join } from "node:path";
|
|
3
12
|
import {
|
|
4
13
|
canonicalJson,
|
|
5
14
|
closed,
|
|
6
15
|
integer,
|
|
16
|
+
LIMITS,
|
|
7
17
|
list,
|
|
8
18
|
oneOf,
|
|
9
19
|
parseWireJson,
|
|
@@ -12,14 +22,17 @@ import {
|
|
|
12
22
|
import { DetailSanitizer, sanitizeText } from "./worker-redaction.mjs";
|
|
13
23
|
|
|
14
24
|
export const CONTEXT_BYTES = 2 * 1024 * 1024;
|
|
15
|
-
|
|
25
|
+
// One message/pipe record, not the lifetime context. Same logical body bound as capture.
|
|
26
|
+
export const CONTEXT_RECORD_BYTES = LIMITS.detailBytes;
|
|
27
|
+
const clean = (s, secrets, max = CONTEXT_RECORD_BYTES) =>
|
|
16
28
|
sanitizeText(text(s, max), secrets);
|
|
17
29
|
function argumentsData(value, secrets) {
|
|
18
30
|
const sanitizer = new DetailSanitizer("canonical-json", secrets);
|
|
19
31
|
const source =
|
|
20
|
-
sanitizer.write(canonicalJson(value,
|
|
32
|
+
sanitizer.write(canonicalJson(value, CONTEXT_RECORD_BYTES)) +
|
|
33
|
+
sanitizer.end();
|
|
21
34
|
if (sanitizer.limited) throw new Error("Unsupported context arguments");
|
|
22
|
-
return parseWireJson(source,
|
|
35
|
+
return parseWireJson(source, CONTEXT_RECORD_BYTES);
|
|
23
36
|
}
|
|
24
37
|
function own(value, key) {
|
|
25
38
|
const d =
|
|
@@ -106,15 +119,14 @@ export function conversationMessages(messages, secrets = []) {
|
|
|
106
119
|
};
|
|
107
120
|
});
|
|
108
121
|
}
|
|
109
|
-
|
|
110
|
-
if (path === null) return [];
|
|
122
|
+
function readPrivateContext(path, maximum) {
|
|
111
123
|
const fd = openSync(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
|
|
112
124
|
try {
|
|
113
125
|
const st = fstatSync(fd);
|
|
114
126
|
if (
|
|
115
127
|
!st.isFile() ||
|
|
116
128
|
st.nlink !== 1 ||
|
|
117
|
-
st.size >
|
|
129
|
+
st.size > maximum ||
|
|
118
130
|
(process.platform !== "win32" &&
|
|
119
131
|
(st.mode & 0o077 || st.uid !== process.getuid()))
|
|
120
132
|
)
|
|
@@ -130,25 +142,78 @@ export function readConversationContext(path) {
|
|
|
130
142
|
if (
|
|
131
143
|
size !== st.size ||
|
|
132
144
|
after.size !== st.size ||
|
|
133
|
-
after.mtimeMs !== st.mtimeMs
|
|
145
|
+
after.mtimeMs !== st.mtimeMs ||
|
|
146
|
+
after.ctimeMs !== st.ctimeMs ||
|
|
147
|
+
lstatSync(path).ino !== st.ino
|
|
134
148
|
)
|
|
135
149
|
throw new Error("Changed context file");
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
new TextDecoder("utf-8", { fatal: true }).decode(
|
|
139
|
-
buffer.subarray(0, size),
|
|
140
|
-
),
|
|
141
|
-
CONTEXT_BYTES,
|
|
142
|
-
),
|
|
143
|
-
["schema", "messages"],
|
|
150
|
+
return new TextDecoder("utf-8", { fatal: true }).decode(
|
|
151
|
+
buffer.subarray(0, size),
|
|
144
152
|
);
|
|
145
|
-
if (o.schema !== "cadence-conversation-context/1")
|
|
146
|
-
throw new Error("Invalid context format");
|
|
147
|
-
return conversationMessages(o.messages);
|
|
148
153
|
} finally {
|
|
149
154
|
closeSync(fd);
|
|
150
155
|
}
|
|
151
156
|
}
|
|
157
|
+
/** Old checkpoints remain readable without migration. New checkpoints hash-chain
|
|
158
|
+
* private per-message records, so no aggregate JSON/pipe size is required. */
|
|
159
|
+
export function* iterateConversationContext(path) {
|
|
160
|
+
if (path === null) return;
|
|
161
|
+
const source = readPrivateContext(path, CONTEXT_BYTES);
|
|
162
|
+
const value = parseWireJson(source, CONTEXT_BYTES);
|
|
163
|
+
if (value.schema === "cadence-conversation-context/1") {
|
|
164
|
+
const o = closed(value, ["schema", "messages"]);
|
|
165
|
+
yield* conversationMessages(o.messages);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
const o = closed(value, ["schema", "messages", "head"]);
|
|
169
|
+
if (o.schema !== "cadence-conversation-context/2")
|
|
170
|
+
throw new Error("Invalid context format");
|
|
171
|
+
const count = integer(o.messages, 0);
|
|
172
|
+
let head = null;
|
|
173
|
+
for (let index = 0; index < count; index++) {
|
|
174
|
+
const body = readPrivateContext(
|
|
175
|
+
join(dirname(path), `context-${index}.json`),
|
|
176
|
+
CONTEXT_RECORD_BYTES,
|
|
177
|
+
);
|
|
178
|
+
const record = closed(parseWireJson(body, CONTEXT_RECORD_BYTES), [
|
|
179
|
+
"schema",
|
|
180
|
+
"index",
|
|
181
|
+
"previous",
|
|
182
|
+
"message",
|
|
183
|
+
]);
|
|
184
|
+
if (
|
|
185
|
+
record.schema !== "cadence-conversation-message/1" ||
|
|
186
|
+
record.index !== index ||
|
|
187
|
+
record.previous !== head
|
|
188
|
+
)
|
|
189
|
+
throw new Error("Invalid context chain");
|
|
190
|
+
head = createHash("sha256").update(body).digest("hex");
|
|
191
|
+
yield conversationMessages([record.message])[0];
|
|
192
|
+
}
|
|
193
|
+
if (o.head !== head) throw new Error("Changed context chain");
|
|
194
|
+
}
|
|
195
|
+
export function readConversationContext(path) {
|
|
196
|
+
return [...iterateConversationContext(path)];
|
|
197
|
+
}
|
|
198
|
+
/** Anonymous pipe framing: each message is bounded, the stream is not. The
|
|
199
|
+
* owner sanitizes each record again before persisting it and commits only on
|
|
200
|
+
* the end marker plus original successful process closure. */
|
|
201
|
+
export function* conversationContextRecords(messages, secrets = []) {
|
|
202
|
+
if (!Array.isArray(messages)) throw new Error("Invalid context");
|
|
203
|
+
let count = 0;
|
|
204
|
+
for (const message of messages) {
|
|
205
|
+
yield `${canonicalJson(
|
|
206
|
+
{
|
|
207
|
+
schema: "cadence-conversation-stream/1",
|
|
208
|
+
message: conversationMessages([message], secrets)[0],
|
|
209
|
+
},
|
|
210
|
+
CONTEXT_RECORD_BYTES - 4096,
|
|
211
|
+
)}\n`;
|
|
212
|
+
count++;
|
|
213
|
+
}
|
|
214
|
+
yield canonicalJson({ schema: "cadence-conversation-stream-end/1", count }) +
|
|
215
|
+
"\n";
|
|
216
|
+
}
|
|
152
217
|
export function encodeConversationContext(messages, secrets) {
|
|
153
218
|
return canonicalJson(
|
|
154
219
|
{
|
package/src/native-build.ts
CHANGED
package/src/sdk-worker.mjs
CHANGED
|
@@ -17,8 +17,8 @@ import {
|
|
|
17
17
|
VERSION,
|
|
18
18
|
} from "@earendil-works/pi-coding-agent";
|
|
19
19
|
import {
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
conversationContextRecords,
|
|
21
|
+
iterateConversationContext,
|
|
22
22
|
} from "./conversation-context.mjs";
|
|
23
23
|
import { conversationResources } from "./conversation-resources.mjs";
|
|
24
24
|
import { coordinatorTools } from "./coordinator-tools.mjs";
|
|
@@ -390,7 +390,7 @@ try {
|
|
|
390
390
|
const requestedThinkingLevel = thinkingLevel ?? "off";
|
|
391
391
|
const manager = SessionManager.inMemory(cwd);
|
|
392
392
|
if (conversation)
|
|
393
|
-
for (const message of
|
|
393
|
+
for (const message of iterateConversationContext(conversation.previous))
|
|
394
394
|
manager.appendMessage(message);
|
|
395
395
|
const coordinationTools = coordinator ? coordinatorTools() : undefined;
|
|
396
396
|
ownsCoordinatorChannel = coordinator;
|
|
@@ -583,7 +583,8 @@ try {
|
|
|
583
583
|
// any checkpoint reaches disk; worker output cannot contain owner credentials.
|
|
584
584
|
if (conversation) {
|
|
585
585
|
stage = "conversation-context";
|
|
586
|
-
|
|
586
|
+
for (const record of conversationContextRecords(session.messages, secrets))
|
|
587
|
+
writeFileSync(3, record);
|
|
587
588
|
}
|
|
588
589
|
await capture.final();
|
|
589
590
|
await emitter.drain();
|
|
@@ -72,7 +72,14 @@ export type WorkbenchRead =
|
|
|
72
72
|
| { kind: "workflow-detail"; id: string; stepId: string }
|
|
73
73
|
| { kind: "workflow-transcript"; id: string; stepId: string }
|
|
74
74
|
| { kind: "workflow"; id: string }
|
|
75
|
-
| {
|
|
75
|
+
| {
|
|
76
|
+
kind: "conversation-transcript";
|
|
77
|
+
id: string;
|
|
78
|
+
turnId: string;
|
|
79
|
+
page: number;
|
|
80
|
+
}
|
|
81
|
+
| { kind: "conversation-active" }
|
|
82
|
+
| { kind: "conversations"; after?: ChatCursor | null; scan?: string }
|
|
76
83
|
| { kind: "task-origin"; taskId: string }
|
|
77
84
|
| { kind: "conversation"; id: string; before: string | null }
|
|
78
85
|
| { kind: "files"; path: string }
|
|
@@ -160,10 +167,20 @@ export interface ChatTurn {
|
|
|
160
167
|
status: ChatStatus;
|
|
161
168
|
items: ChatItem[];
|
|
162
169
|
notice: string;
|
|
170
|
+
/** Immutable full-transcript pages; items above are only the latest preview. */
|
|
171
|
+
transcript?: { pages: number };
|
|
163
172
|
/** Content kinds observed and not retained; never written into `notice`.
|
|
164
173
|
* `other` is a block of a type Cadence does not recognize. */
|
|
165
174
|
omitted: { thinking: boolean; media: boolean; other: boolean };
|
|
166
175
|
}
|
|
176
|
+
export interface ChatCursor {
|
|
177
|
+
id: string;
|
|
178
|
+
updatedAt: number;
|
|
179
|
+
}
|
|
180
|
+
function decodeChatCursor(value: unknown): ChatCursor {
|
|
181
|
+
const o = closed(value, ["id", "updatedAt"]);
|
|
182
|
+
return { id: decodeId(o.id), updatedAt: integer(o.updatedAt, 0) };
|
|
183
|
+
}
|
|
167
184
|
export interface ChatSummary {
|
|
168
185
|
id: string;
|
|
169
186
|
title: string;
|
|
@@ -178,6 +195,12 @@ export interface FileEntry {
|
|
|
178
195
|
directory: boolean;
|
|
179
196
|
}
|
|
180
197
|
export type WorkbenchResult =
|
|
198
|
+
| {
|
|
199
|
+
kind: "conversation-transcript";
|
|
200
|
+
conversationId: string;
|
|
201
|
+
page: number;
|
|
202
|
+
turn: ChatTurn;
|
|
203
|
+
}
|
|
181
204
|
| { kind: "workflow-history-progress"; after: string | null; scan: string }
|
|
182
205
|
| {
|
|
183
206
|
kind: "workflow-history";
|
|
@@ -207,7 +230,9 @@ export type WorkbenchResult =
|
|
|
207
230
|
}
|
|
208
231
|
| { kind: "workflow"; commandId: string | null; response: WorkflowResponse }
|
|
209
232
|
| { kind: "task-origin"; taskId: string; conversationId: string | null }
|
|
210
|
-
| { kind: "
|
|
233
|
+
| { kind: "conversation-active"; entries: ChatSummary[] }
|
|
234
|
+
| { kind: "conversations-progress"; after: ChatCursor | null; scan: string }
|
|
235
|
+
| { kind: "conversations"; entries: ChatSummary[]; next?: ChatCursor | null }
|
|
211
236
|
| {
|
|
212
237
|
kind: "conversation";
|
|
213
238
|
summary: ChatSummary | null;
|
|
@@ -248,6 +273,15 @@ const statuses = [
|
|
|
248
273
|
export function decodeWorkbenchRead(v: unknown): WorkbenchRead {
|
|
249
274
|
const kind = Object.getOwnPropertyDescriptor(v ?? {}, "kind")?.value;
|
|
250
275
|
switch (kind) {
|
|
276
|
+
case "conversation-transcript": {
|
|
277
|
+
const o = closed(v, ["kind", "id", "turnId", "page"]);
|
|
278
|
+
return {
|
|
279
|
+
kind,
|
|
280
|
+
id: decodeId(o.id),
|
|
281
|
+
turnId: decodeId(o.turnId),
|
|
282
|
+
page: integer(o.page, 0),
|
|
283
|
+
};
|
|
284
|
+
}
|
|
251
285
|
case "cadence-conversation": {
|
|
252
286
|
const o = closed(v, ["kind", "id"]);
|
|
253
287
|
return { kind, id: decodeId(o.id) };
|
|
@@ -273,7 +307,21 @@ export function decodeWorkbenchRead(v: unknown): WorkbenchRead {
|
|
|
273
307
|
const o = closed(v, ["kind", "id"]);
|
|
274
308
|
return { kind, id: decodeId(o.id) };
|
|
275
309
|
}
|
|
276
|
-
case "conversations":
|
|
310
|
+
case "conversations": {
|
|
311
|
+
const after = Object.hasOwn(v as object, "after"),
|
|
312
|
+
scan = Object.hasOwn(v as object, "scan");
|
|
313
|
+
const o = closed(v, [
|
|
314
|
+
"kind",
|
|
315
|
+
...(after ? ["after"] : []),
|
|
316
|
+
...(scan ? ["scan"] : []),
|
|
317
|
+
]);
|
|
318
|
+
return {
|
|
319
|
+
kind,
|
|
320
|
+
...(after ? { after: nullable(o.after, decodeChatCursor) } : {}),
|
|
321
|
+
...(scan ? { scan: decodeId(o.scan) } : {}),
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
case "conversation-active":
|
|
277
325
|
case "projects":
|
|
278
326
|
closed(v, ["kind"]);
|
|
279
327
|
return { kind };
|
|
@@ -424,7 +472,14 @@ export function decodeChatTurn(v: unknown): ChatTurn {
|
|
|
424
472
|
const keys = ["id", "epoch", "status", "items", "notice"];
|
|
425
473
|
const current =
|
|
426
474
|
v !== null && typeof v === "object" && Object.hasOwn(v, "omitted");
|
|
427
|
-
const
|
|
475
|
+
const paged =
|
|
476
|
+
v !== null && typeof v === "object" && Object.hasOwn(v, "transcript");
|
|
477
|
+
const o = closed(v, [
|
|
478
|
+
...keys,
|
|
479
|
+
...(current ? ["omitted"] : []),
|
|
480
|
+
...(paged ? ["transcript"] : []),
|
|
481
|
+
]);
|
|
482
|
+
const transcript = paged ? closed(o.transcript, ["pages"]) : null;
|
|
428
483
|
const omitted = current
|
|
429
484
|
? closed(o.omitted, ["thinking", "media", "other"])
|
|
430
485
|
: null;
|
|
@@ -433,6 +488,9 @@ export function decodeChatTurn(v: unknown): ChatTurn {
|
|
|
433
488
|
epoch: decodeId(o.epoch),
|
|
434
489
|
status: oneOf(o.status, statuses),
|
|
435
490
|
notice: text(o.notice, 1024),
|
|
491
|
+
...(transcript
|
|
492
|
+
? { transcript: { pages: integer(transcript.pages, 0) } }
|
|
493
|
+
: {}),
|
|
436
494
|
omitted: {
|
|
437
495
|
thinking: omitted ? bool(omitted.thinking) : false,
|
|
438
496
|
media: omitted ? bool(omitted.media) : false,
|
|
@@ -474,6 +532,14 @@ export function decodeChatSummary(v: unknown): ChatSummary {
|
|
|
474
532
|
export function decodeWorkbenchResult(v: unknown): WorkbenchResult {
|
|
475
533
|
canonicalJson(v, 512 * 1024);
|
|
476
534
|
const k = Object.getOwnPropertyDescriptor(v ?? {}, "kind")?.value;
|
|
535
|
+
if (k === "conversation-transcript") {
|
|
536
|
+
const o = closed(v, ["kind", "conversationId", "page", "turn"]);
|
|
537
|
+
const turn = decodeChatTurn(o.turn),
|
|
538
|
+
page = integer(o.page, 0);
|
|
539
|
+
if (!turn.transcript || page >= turn.transcript.pages)
|
|
540
|
+
throw new ContractError("invalid");
|
|
541
|
+
return { kind: k, conversationId: decodeId(o.conversationId), page, turn };
|
|
542
|
+
}
|
|
477
543
|
if (k === "workflow-transcript") {
|
|
478
544
|
const o = closed(v, ["kind", "runId", "stepId", "turn"]);
|
|
479
545
|
return {
|
|
@@ -569,9 +635,26 @@ export function decodeWorkbenchResult(v: unknown): WorkbenchResult {
|
|
|
569
635
|
conversationId: nullable(o.conversationId, decodeId),
|
|
570
636
|
};
|
|
571
637
|
}
|
|
572
|
-
if (kind === "conversations") {
|
|
638
|
+
if (kind === "conversations-progress") {
|
|
639
|
+
const o = closed(v, ["kind", "after", "scan"]);
|
|
640
|
+
return {
|
|
641
|
+
kind,
|
|
642
|
+
after: nullable(o.after, decodeChatCursor),
|
|
643
|
+
scan: decodeId(o.scan),
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
if (kind === "conversation-active") {
|
|
573
647
|
const o = closed(v, ["kind", "entries"]);
|
|
574
|
-
return { kind, entries: list(o.entries,
|
|
648
|
+
return { kind, entries: list(o.entries, 8, decodeChatSummary) };
|
|
649
|
+
}
|
|
650
|
+
if (kind === "conversations") {
|
|
651
|
+
const paged = Object.hasOwn(v as object, "next");
|
|
652
|
+
const o = closed(v, ["kind", "entries", ...(paged ? ["next"] : [])]);
|
|
653
|
+
return {
|
|
654
|
+
kind,
|
|
655
|
+
entries: list(o.entries, 200, decodeChatSummary),
|
|
656
|
+
...(paged ? { next: nullable(o.next, decodeChatCursor) } : {}),
|
|
657
|
+
};
|
|
575
658
|
}
|
|
576
659
|
if (kind === "conversation") {
|
|
577
660
|
const o = closed(v, ["kind", "summary", "turns", "before"]);
|