dsh-compact-pi 0.2.3-b2 → 0.2.3-b4
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/CHANGELOG.md +12 -0
- package/README.md +18 -5
- package/bin/dcp-session.ts +33 -14
- package/dist/codec.mjs +45 -9
- package/dist/dcp-session.mjs +969 -436
- package/dist/index.js +12 -4
- package/docs/compatibility.md +1 -1
- package/docs/help.md +25 -4
- package/docs/publishing.md +9 -9
- package/docs/testing.md +7 -4
- package/package.json +5 -3
- package/scripts/test-resume.mjs +96 -31
- package/skills/dcp-migrate-to-dsh/SKILL.md +16 -0
- package/skills/dcp-migrate-to-dsh/references/commands.md +29 -0
- package/src/codec.ts +40 -6
- package/src/dsh/convert.ts +11 -5
- package/src/dsh/import.ts +108 -0
- package/src/dsh/migration-cli.ts +129 -0
- package/src/dsh/migration-web.ts +44 -0
- package/src/dsh/migration.ts +216 -0
- package/src/dsh/sync.ts +9 -1
- package/test/convert.test.ts +63 -1
- package/test/migration.test.ts +72 -0
package/dist/index.js
CHANGED
|
@@ -30631,8 +30631,8 @@ var SessionProjectionRegistry = class extends Service {
|
|
|
30631
30631
|
// package.json
|
|
30632
30632
|
var package_default = {
|
|
30633
30633
|
name: "dsh-compact-pi",
|
|
30634
|
-
version: "0.2.3-
|
|
30635
|
-
dcpVersion: "0.2.
|
|
30634
|
+
version: "0.2.3-b4",
|
|
30635
|
+
dcpVersion: "0.2.3b4",
|
|
30636
30636
|
type: "module",
|
|
30637
30637
|
description: "DeepSeek Harness context compaction for pi: upstream engine, policy, token meter and pruner",
|
|
30638
30638
|
repository: {
|
|
@@ -30648,7 +30648,7 @@ var package_default = {
|
|
|
30648
30648
|
build: "node scripts/check-vendor.mjs && node scripts/build-vendor.mjs && npm run build:plugin && npm run build:codec && npm run build:cli",
|
|
30649
30649
|
"build:plugin": "esbuild src/index.ts --bundle --platform=node --format=esm --target=node22 --outfile=dist/index.js --external:@earendil-works/pi-coding-agent",
|
|
30650
30650
|
"build:codec": "esbuild src/codec.ts --bundle --platform=node --format=esm --target=node22 --outfile=dist/codec.mjs",
|
|
30651
|
-
"build:cli":
|
|
30651
|
+
"build:cli": 'esbuild bin/dcp-session.ts bin/dcp.ts --bundle --platform=node --format=esm --target=node22 --outdir=dist --out-extension:.js=.mjs --banner:js="#!/usr/bin/env node"',
|
|
30652
30652
|
test: "tsx --test test/*.test.ts",
|
|
30653
30653
|
convert: "node dist/dcp-session.mjs",
|
|
30654
30654
|
unpatch: "node scripts/patch-pi.mjs --restore",
|
|
@@ -30661,6 +30661,7 @@ var package_default = {
|
|
|
30661
30661
|
"vendor:verify": "node scripts/check-vendor.mjs --upstream"
|
|
30662
30662
|
},
|
|
30663
30663
|
pi: {
|
|
30664
|
+
skills: ["./skills"],
|
|
30664
30665
|
extensions: [
|
|
30665
30666
|
"./dist/index.js"
|
|
30666
30667
|
]
|
|
@@ -30675,6 +30676,7 @@ var package_default = {
|
|
|
30675
30676
|
"src",
|
|
30676
30677
|
"bin",
|
|
30677
30678
|
"scripts",
|
|
30679
|
+
"skills",
|
|
30678
30680
|
"docs",
|
|
30679
30681
|
"README.md",
|
|
30680
30682
|
"CHANGELOG.md",
|
|
@@ -34857,13 +34859,14 @@ function dshMessageToPi(message, time3, toolNames, imageToPi) {
|
|
|
34857
34859
|
}
|
|
34858
34860
|
|
|
34859
34861
|
// src/dsh/sync.ts
|
|
34860
|
-
function createSyncState() {
|
|
34862
|
+
function createSyncState({ persistent = false } = {}) {
|
|
34861
34863
|
return {
|
|
34862
34864
|
turn: 1,
|
|
34863
34865
|
step: 0,
|
|
34864
34866
|
turnStarted: false,
|
|
34865
34867
|
systemSeq: void 0,
|
|
34866
34868
|
stepOpen: false,
|
|
34869
|
+
persistent,
|
|
34867
34870
|
seen: /* @__PURE__ */ new Set(),
|
|
34868
34871
|
toolCalls: /* @__PURE__ */ new Map(),
|
|
34869
34872
|
appended: 0
|
|
@@ -34886,6 +34889,11 @@ function ensureTurn(session, state) {
|
|
|
34886
34889
|
function appendSystem(session, state, entry, message, systemPrompt) {
|
|
34887
34890
|
if (state.systemSeq !== void 0) return;
|
|
34888
34891
|
ensureTurn(session, state);
|
|
34892
|
+
if (state.persistent && !state.stepOpen) {
|
|
34893
|
+
state.step += 1;
|
|
34894
|
+
append(session, "step/start", { turn: state.turn, step: state.step });
|
|
34895
|
+
state.stepOpen = true;
|
|
34896
|
+
}
|
|
34889
34897
|
let content = piContentToDsh(
|
|
34890
34898
|
systemPrompt && systemPrompt.trim().length > 0 ? systemPrompt : typeof message.content === "string" ? message.content : []
|
|
34891
34899
|
);
|
package/docs/compatibility.md
CHANGED
package/docs/help.md
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
# DCP usage and troubleshooting
|
|
2
2
|
|
|
3
|
-
Install the [
|
|
3
|
+
Install from the [Pi package catalog](https://pi.dev/packages/dsh-compact-pi) with:
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
|
-
pi install
|
|
6
|
+
pi install npm:dsh-compact-pi@latest
|
|
7
7
|
```
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Use the explicit tag while the npm release has a prerelease version. The GitHub tag is also available:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pi install git:github.com/HanqingTony/dsh-compact-pi@v0.2.3-b4
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Restart pi or run `/reload` while idle. `/dcp-status` should show DCP `0.2.3b4` and DSH `0.2.3-alpha.2`. DCP is tested with pi 1.5.2 and 1.6.1 and needs Node.js `^24.22.3 || >=26.13.1`. Check `pi list` for duplicate installations if commands or warnings appear twice. See the [update instructions](../README.md#updating-an-existing-installation) for pinned tags and branch installs.
|
|
10
16
|
|
|
11
17
|
## Compaction and model selection
|
|
12
18
|
|
|
@@ -19,16 +25,31 @@ If a historical summary model is unavailable in pi, use the picker to select an
|
|
|
19
25
|
|
|
20
26
|
## Move a session between pi and DSH
|
|
21
27
|
|
|
22
|
-
|
|
28
|
+
Run `dcp-session migrate` in a terminal, or ask the `dcp-migrate-to-dsh` skill to guide you. The wizard asks for a source and target, shows the exact output and attachment paths, then waits for confirmation. Agents use `migrate plan` and `migrate apply` so you can review the same information before any session or image is written. See the [command examples](../skills/dcp-migrate-to-dsh/references/commands.md).
|
|
29
|
+
|
|
30
|
+
- **Portable export** writes a new folder under the export directory you choose. Move that whole folder to keep the JSONL and images together.
|
|
31
|
+
- **Direct import** uses the target backend's version, profile, data home, session directory, workspace, and encoding. Run on the target machine. On Windows, use Windows Node.js and Windows paths. On Linux, use the data paths of the backend your desktop client actually connects to.
|
|
32
|
+
- **Conflicts** stop the default plan. You can explicitly choose a new session ID while preserving the existing one, or recover the Pi entries from a recognized mixed log while preserving the original file. Encoding mismatches require a corrected target configuration.
|
|
33
|
+
|
|
34
|
+
The import receipt confirms a write. Open the imported history in the chosen Desktop or TUI, or run `migrate verify-web` to check both the list and history of the approved Web instance.
|
|
35
|
+
|
|
36
|
+
The CLI can also run low-level conversions for scripts. In a checkout use `node dist/dcp-session.mjs --help`. Exit the active source session or work from a copy.
|
|
23
37
|
|
|
24
38
|
```bash
|
|
39
|
+
dcp-session pi2dsh-import session.pi.jsonl
|
|
25
40
|
dcp-session pi2dsh session.pi.jsonl exported.dsh.jsonl
|
|
26
41
|
dcp-session dsh2pi exported.dsh.jsonl imported.pi.jsonl
|
|
27
42
|
pi --session imported.pi.jsonl
|
|
28
43
|
```
|
|
29
44
|
|
|
45
|
+
`pi2dsh-import` writes a new session into the DSH 0.2.3-alpha.2 V4 store and prints its ID and working directory. Open it in DSH's session picker or run `dsh-tui --resume <session-id>` from that directory. The default store is `$DSH_HOME/sessions` with Zstandard encoding. Pass the configured session root as the second argument for a custom profile. Add `--plain` for profiles using plaintext JSONL. An existing session with the same ID and workspace is left intact.
|
|
46
|
+
|
|
47
|
+
In Pi, request a migration or run `/skill:dcp-migrate-to-dsh`. To invoke it from DSH, copy the [skill directory](../skills/dcp-migrate-to-dsh) into `$DSH_HOME/skills` (default `~/.dsh/skills`). Both hosts need access to the converter and source file.
|
|
48
|
+
|
|
30
49
|
The export archives pi entries, including the branch tree, and gives DSH the active compacted context. Reimporting an unchanged export restores the archived pi entries. Reimporting a session after continuing in DSH uses the live DSH context as a linear pi session. Keep the original file for its full history and host-specific metadata.
|
|
31
50
|
|
|
51
|
+
The CLI report counts archived source messages, which may exceed the number shown in DSH. Incomplete tool exchanges are kept in the Pi archive and omitted from the DSH active context.
|
|
52
|
+
|
|
32
53
|
Image references use `DSH_HOME`, which defaults to `~/.dsh`. Keep that attachment store with the logs when moving them across machines. If image import reports a missing object, point `DSH_HOME` at the corresponding store. For compressed DSH input, install the `zstd` command.
|
|
33
54
|
|
|
34
55
|
If old messages seem to disappear after a pi upgrade, confirm that the session path and branch are correct. A standard pi session shows the latest active summary and retained messages while the raw JSONL still holds the earlier entries. Files written by the v0.1 core patch need [legacy migration](native-session-codec.md). A file containing both DSH events and appended pi entries requires separate recovery of each part.
|
package/docs/publishing.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Publishing dsh-compact-pi
|
|
2
2
|
|
|
3
|
-
Use Node.js `^24.22.3 || >=26.13.1`. The package version `0.2.3-
|
|
3
|
+
Use Node.js `^24.22.3 || >=26.13.1`. The package version `0.2.3-b4` corresponds to the displayed version `0.2.3b4`. Keep the upstream DSH base version and increment the DCP build suffix for subsequent releases.
|
|
4
4
|
|
|
5
5
|
## Verify a release
|
|
6
6
|
|
|
@@ -9,7 +9,7 @@ npm ci
|
|
|
9
9
|
npm run check
|
|
10
10
|
npm run test:package
|
|
11
11
|
npm run test:resume -- 1.5.2
|
|
12
|
-
npm run test:resume -- 1.6.
|
|
12
|
+
npm run test:resume -- 1.6.1
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
`test:package` creates the tarball and checks an isolated production installation, a rebuild from the included upstream source and loading through pi. Review the packed file list before publication; credentials and session data must not be included.
|
|
@@ -21,28 +21,28 @@ See [testing](testing.md) for the resume and migration matrix. If the source sna
|
|
|
21
21
|
Authenticate interactively with `npm login`, then verify the intended publisher with `npm whoami`. Do not put authentication tokens in this repository.
|
|
22
22
|
|
|
23
23
|
```bash
|
|
24
|
-
npm publish --access public --tag
|
|
24
|
+
npm publish ./dsh-compact-pi-0.2.3-b4.tgz --access public --tag latest
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
The package's `publishConfig` defaults to the public npm registry and the `beta` tag
|
|
27
|
+
The package's `publishConfig` defaults to the public npm registry and the `beta` tag for candidate builds. Use the tested tarball and set `--tag latest` for the public release. Verify with `npm view dsh-compact-pi dist-tags`. Users can install with `pi install npm:dsh-compact-pi@latest` or pin the exact version.
|
|
28
28
|
|
|
29
29
|
```bash
|
|
30
|
-
pi install npm:dsh-compact-pi@0.2.3-
|
|
30
|
+
pi install npm:dsh-compact-pi@0.2.3-b4
|
|
31
31
|
```
|
|
32
32
|
|
|
33
33
|
Restart pi or run `/reload`, then `/dcp-status`. Remove a previous local DCP package entry before loading the published package to avoid registering the extension twice. Run `pi list` to identify the installed source and `pi remove <source>` to remove it.
|
|
34
34
|
|
|
35
|
-
The `pi-package` keyword
|
|
35
|
+
The package is listed in the [Pi package catalog](https://pi.dev/packages/dsh-compact-pi). The `pi-package` keyword keeps future releases eligible for discovery. Check the registry tag and the gallery page after publishing.
|
|
36
36
|
|
|
37
37
|
## Git
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
GitHub also hosts tagged releases:
|
|
40
40
|
|
|
41
41
|
```bash
|
|
42
|
-
pi install git:github.com/HanqingTony/dsh-compact-pi@v0.2.3-
|
|
42
|
+
pi install git:github.com/HanqingTony/dsh-compact-pi@v0.2.3-b4
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
-
A Git release must include `dist/`, `vendor/` and the package manifest so installing it does not require development dependencies or an upstream checkout. Tag only the verified release commit. Keep source provenance and third-party licenses in the repository and tarball.
|
|
45
|
+
A Git release must include `dist/`, `vendor/` and the package manifest so installing it does not require development dependencies or an upstream checkout. Tag only the verified release commit. Keep source provenance and third-party licenses in the repository and tarball.
|
|
46
46
|
|
|
47
47
|
Tags pin installations: publishing a new tag does not upgrade users pinned to an older one. Tell users to install the new tag explicitly, or omit the ref to follow `main`. In pi 1.5.2, `pi update` updates pi itself; package updates use `pi update --extensions` or `pi update <source>`. Document the reload and version check with each release. See [Updating an existing installation](../README.md#updating-an-existing-installation) for the user-facing commands.
|
|
48
48
|
|
package/docs/testing.md
CHANGED
|
@@ -6,8 +6,7 @@ Clone the repository with its Git history and install dependencies with `npm ci`
|
|
|
6
6
|
|---|---|
|
|
7
7
|
| `npm run check` | Type checks, verifies and rebuilds the vendored runtime, builds the extension and CLI, and runs the regression suite |
|
|
8
8
|
| `npm run test:package` | Packs the release, installs it in isolation, verifies bundled upstream sources, rebuilds them, and exercises image handling and the pi loader |
|
|
9
|
-
| `npm run test:resume -- 1.
|
|
10
|
-
| `npm run test:resume -- 1.6.0` | Repeats the same checks on pi 1.6.0. Pass another exact version to check a candidate upgrade |
|
|
9
|
+
| `npm run test:resume -- 1.6.1` | Installs the DCP tarball, tests automatic and manual image compaction on pi 1.6.1, and checks resume and DSH migration from released DCP 0.2.2b3 sessions. Pass another exact version to check a candidate upgrade |
|
|
11
10
|
| `npm run vendor:verify -- /path/to/deepseek-harness` | Compares the vendored source closure byte for byte with the matching upstream checkout and dependencies |
|
|
12
11
|
|
|
13
12
|
The normal regression suite covers DSH pressure and overflow policy, Esc cancellation, signed thinking and tool schemas, summary model selection, journal replay, native checkpoints, attachment handling, and a native DSH checkpoint import. To rerun the image migration and upstream differential tests after a build, use:
|
|
@@ -16,8 +15,12 @@ The normal regression suite covers DSH pressure and overflow policy, Esc cancell
|
|
|
16
15
|
node --import tsx --test test/images-convert.test.ts test/differential.test.ts
|
|
17
16
|
```
|
|
18
17
|
|
|
19
|
-
The resume test
|
|
18
|
+
The resume test installs the built npm tarball in a temporary directory and loads its extension in the candidate pi SDK. It exercises automatic compaction and pi's manual compaction path with a retained PNG. Both paths must save a native compaction checkpoint and image assets, continue with the summary and retained image, and preserve them when the session is reopened.
|
|
19
|
+
|
|
20
|
+
Run `node --import tsx --test test/migration.test.ts` on Windows or Linux to test explicit destination selection, read-only planning, stale plans, duplicate IDs, encoding conflicts, and opt-in recovery of Pi entries. The GitHub Actions matrix runs this test on both hosts. For desktop release checks, also open a synthetic imported session in the target app and verify its history.
|
|
21
|
+
|
|
22
|
+
The test also generates a native pi checkpoint and a separate snapshot cut at the DCP journal commit using an earlier DCP release. On the candidate pi it checks that the next provider request contains the old summary, a retained message and the new user request. It disables fresh summarization during replay so a lost checkpoint fails the test. It runs the CLI in both directions, checking for inactive branch leakage, native context edits, archive fidelity and continued work after adding a message in DSH.
|
|
20
23
|
|
|
21
24
|
The baseline bundle comes from Git commit `1f43099c0273a3edcbe5353a4aaf32884efd1fc9`. The candidate pi package is installed from npm into a temporary directory. If a shallow clone lacks the baseline, fetch the `v0.2.2-b3` tag before running the test. Other builds and the unit suite can run without that Git history.
|
|
22
25
|
|
|
23
|
-
The **Pi session compatibility** workflow runs on
|
|
26
|
+
The **Pi session compatibility** workflow runs the same test on Ubuntu and native Windows for pi 1.5.2 and the candidate version. Run it manually with an exact candidate pi version before extending the supported matrix. On Windows, run `npm ci` and `npm run test:resume -- 1.6.1` in a native terminal with Windows Node.js and Git for Windows available on `PATH`. Both platforms use stubbed provider responses to verify session behavior. Summary quality with a live model is outside the test's scope.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-compact-pi",
|
|
3
|
-
"version": "0.2.3-
|
|
4
|
-
"dcpVersion": "0.2.
|
|
3
|
+
"version": "0.2.3-b4",
|
|
4
|
+
"dcpVersion": "0.2.3b4",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "DeepSeek Harness context compaction for pi: upstream engine, policy, token meter and pruner",
|
|
7
7
|
"repository": {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"build": "node scripts/check-vendor.mjs && node scripts/build-vendor.mjs && npm run build:plugin && npm run build:codec && npm run build:cli",
|
|
18
18
|
"build:plugin": "esbuild src/index.ts --bundle --platform=node --format=esm --target=node22 --outfile=dist/index.js --external:@earendil-works/pi-coding-agent",
|
|
19
19
|
"build:codec": "esbuild src/codec.ts --bundle --platform=node --format=esm --target=node22 --outfile=dist/codec.mjs",
|
|
20
|
-
"build:cli": "esbuild bin/dcp-session.ts bin/dcp.ts --bundle --platform=node --format=esm --target=node22 --outdir=dist --out-extension:.js=.mjs --banner:js
|
|
20
|
+
"build:cli": "esbuild bin/dcp-session.ts bin/dcp.ts --bundle --platform=node --format=esm --target=node22 --outdir=dist --out-extension:.js=.mjs --banner:js=\"#!/usr/bin/env node\"",
|
|
21
21
|
"test": "tsx --test test/*.test.ts",
|
|
22
22
|
"convert": "node dist/dcp-session.mjs",
|
|
23
23
|
"unpatch": "node scripts/patch-pi.mjs --restore",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"vendor:verify": "node scripts/check-vendor.mjs --upstream"
|
|
31
31
|
},
|
|
32
32
|
"pi": {
|
|
33
|
+
"skills": ["./skills"],
|
|
33
34
|
"extensions": [
|
|
34
35
|
"./dist/index.js"
|
|
35
36
|
]
|
|
@@ -44,6 +45,7 @@
|
|
|
44
45
|
"src",
|
|
45
46
|
"bin",
|
|
46
47
|
"scripts",
|
|
48
|
+
"skills",
|
|
47
49
|
"docs",
|
|
48
50
|
"README.md",
|
|
49
51
|
"CHANGELOG.md",
|
package/scripts/test-resume.mjs
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** Exercise the packaged plugin and replay released sessions on a candidate pi host. */
|
|
2
2
|
import assert from 'node:assert/strict'
|
|
3
|
-
import { execFileSync } from 'node:child_process'
|
|
4
|
-
import { mkdtempSync, mkdirSync, readFileSync, rmSync, symlinkSync, writeFileSync } from 'node:fs'
|
|
3
|
+
import { execFileSync, spawnSync } from 'node:child_process'
|
|
4
|
+
import { mkdtempSync, mkdirSync, readFileSync, readdirSync, rmSync, symlinkSync, writeFileSync } from 'node:fs'
|
|
5
5
|
import os from 'node:os'
|
|
6
6
|
import path from 'node:path'
|
|
7
7
|
import { pathToFileURL } from 'node:url'
|
|
8
|
+
import sharp from 'sharp'
|
|
8
9
|
import { Session, imageOffloadProjection } from '../vendor/dsh-runtime.mjs'
|
|
9
10
|
|
|
10
11
|
const root = path.resolve(import.meta.dirname, '..')
|
|
11
12
|
const piPackage = '@earendil-works/pi-coding-agent'
|
|
12
13
|
const baselinePi = '1.5.2'
|
|
13
14
|
const baselineRevision = '1f43099c0273a3edcbe5353a4aaf32884efd1fc9' // DCP 0.2.2b3
|
|
14
|
-
const candidate = process.argv[2] ?? process.env.DCP_TEST_PI_VERSION ?? '1.6.
|
|
15
|
+
const candidate = process.argv[2] ?? process.env.DCP_TEST_PI_VERSION ?? '1.6.1'
|
|
15
16
|
assert.match(candidate, /^\d+\.\d+\.\d+(?:-[a-zA-Z0-9.-]+)?$/, 'Pass an exact pi version')
|
|
16
17
|
const summary = 'DCP_RESUME_SUMMARY'
|
|
17
18
|
const tail = 'DCP_RETAINED_TAIL'
|
|
@@ -22,7 +23,13 @@ const usage = {
|
|
|
22
23
|
input: 0, output: 0, cacheRead: 0, cacheWrite: 0, totalTokens: 0,
|
|
23
24
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
|
24
25
|
}
|
|
25
|
-
const dir =
|
|
26
|
+
const dir = process.env.DCP_TEST_WORK_DIR
|
|
27
|
+
|
|
28
|
+
function npm(args, options) {
|
|
29
|
+
// npm.cmd cannot be launched directly by execFile on Windows.
|
|
30
|
+
assert.ok(process.env.npm_execpath, 'Run this test with npm run test:resume')
|
|
31
|
+
return execFileSync(process.execPath, [process.env.npm_execpath, ...args], options)
|
|
32
|
+
}
|
|
26
33
|
|
|
27
34
|
async function host(prefix, expectedVersion) {
|
|
28
35
|
const packageDir = path.join(prefix, 'node_modules', piPackage)
|
|
@@ -35,15 +42,15 @@ async function host(prefix, expectedVersion) {
|
|
|
35
42
|
return { ...sdk, ...ai }
|
|
36
43
|
}
|
|
37
44
|
|
|
38
|
-
async function run(pi, kind, extension, source, expected = []) {
|
|
45
|
+
async function run(pi, kind, extension, { source, expected = [], manual = false, image } = {}) {
|
|
39
46
|
const cwd = path.join(dir, kind)
|
|
40
47
|
mkdirSync(path.join(cwd, '.pi'), { recursive: true })
|
|
41
48
|
writeFileSync(path.join(cwd, '.pi/dcp.json'), JSON.stringify({
|
|
42
49
|
audit: false,
|
|
43
|
-
policy: { auto: !source, headroomTokens: 512, retainTokens: 256, maxTokens: 1024 },
|
|
50
|
+
policy: { auto: !source && !manual, headroomTokens: 512, retainTokens: 256, maxTokens: 1024 },
|
|
44
51
|
}))
|
|
45
52
|
const settings = pi.SettingsManager.inMemory({
|
|
46
|
-
compaction: { enabled: false },
|
|
53
|
+
compaction: { enabled: false, keepRecentTokens: 256 },
|
|
47
54
|
retry: { enabled: false },
|
|
48
55
|
})
|
|
49
56
|
const loader = new pi.DefaultResourceLoader({
|
|
@@ -64,7 +71,7 @@ async function run(pi, kind, extension, source, expected = []) {
|
|
|
64
71
|
runtime.registerProvider('dcp-resume-test', {
|
|
65
72
|
api: 'dcp-resume-test', apiKey: 'stub', baseUrl: 'https://unused.invalid',
|
|
66
73
|
models: [{
|
|
67
|
-
id: 'stub', name: 'stub', reasoning: false, input: ['text'],
|
|
74
|
+
id: 'stub', name: 'stub', reasoning: false, input: ['text', 'image'],
|
|
68
75
|
contextWindow: 8000, maxTokens: 1024, cost: usage.cost,
|
|
69
76
|
}],
|
|
70
77
|
streamSimple(model, context) {
|
|
@@ -87,12 +94,18 @@ async function run(pi, kind, extension, source, expected = []) {
|
|
|
87
94
|
? pi.SessionManager.open(source)
|
|
88
95
|
: pi.SessionManager.create(cwd, cwd)
|
|
89
96
|
const model = runtime.getModel('dcp-resume-test', 'stub')
|
|
97
|
+
const tailText = tail.repeat(80)
|
|
90
98
|
if (!source) {
|
|
91
99
|
manager.appendMessage({ role: 'user', content: oldHistory.repeat(2200), timestamp: 1 })
|
|
92
100
|
manager.appendMessage({
|
|
93
101
|
role: 'assistant', api: model.api, provider: model.provider, model: model.id,
|
|
94
102
|
content: [{ type: 'text', text: 'Earlier answer' }], timestamp: 2, usage, stopReason: 'stop',
|
|
95
103
|
})
|
|
104
|
+
if (manual) {
|
|
105
|
+
manager.appendMessage({
|
|
106
|
+
role: 'user', content: [{ type: 'text', text: tailText }, image], timestamp: 3,
|
|
107
|
+
})
|
|
108
|
+
}
|
|
96
109
|
}
|
|
97
110
|
const { session } = await pi.createAgentSession({
|
|
98
111
|
cwd, agentDir: cwd, modelRuntime: runtime, model, sessionManager: manager,
|
|
@@ -101,7 +114,9 @@ async function run(pi, kind, extension, source, expected = []) {
|
|
|
101
114
|
const errors = []
|
|
102
115
|
try {
|
|
103
116
|
await session.bindExtensions({ mode: 'print', onError: (error) => errors.push(error) })
|
|
104
|
-
|
|
117
|
+
if (manual) await session.compact()
|
|
118
|
+
const options = image && !source && !manual ? { images: [image] } : undefined
|
|
119
|
+
await session.prompt(source || manual ? next : tailText, options)
|
|
105
120
|
assert.deepEqual(errors, [], `${kind}: extension errors`)
|
|
106
121
|
const request = calls.at(-1)
|
|
107
122
|
assert.ok(request && !request.isSummary, `${kind}: model request missing`)
|
|
@@ -111,30 +126,38 @@ async function run(pi, kind, extension, source, expected = []) {
|
|
|
111
126
|
assert.ok(!input.includes(oldHistory), `${kind}: compacted prefix reappeared`)
|
|
112
127
|
assert.ok(!input.includes('DCP_ABANDONED_BRANCH'), `${kind}: inactive branch leaked`)
|
|
113
128
|
for (const marker of expected) assert.ok(input.includes(marker), `${kind}: ${marker} missing`)
|
|
114
|
-
if (source) {
|
|
115
|
-
assert.equal(calls.length, 1, `${kind}: recovery must reuse the existing summary`)
|
|
129
|
+
if (source || manual) {
|
|
116
130
|
assert.equal(request.messages.at(-1)?.role, 'user')
|
|
117
131
|
assert.ok(JSON.stringify(request.messages.at(-1)).includes(next), `${kind}: latest prompt missing`)
|
|
132
|
+
}
|
|
133
|
+
if (image) {
|
|
134
|
+
const images = request.messages.flatMap((message) =>
|
|
135
|
+
Array.isArray(message.content) ? message.content.filter((part) => part.type === 'image') : [],
|
|
136
|
+
)
|
|
137
|
+
assert.deepEqual(images, [image], `${kind}: retained image missing or changed`)
|
|
138
|
+
}
|
|
139
|
+
if (source) {
|
|
140
|
+
assert.equal(calls.length, 1, `${kind}: recovery must reuse the existing summary`)
|
|
118
141
|
} else {
|
|
119
142
|
assert.equal(calls.filter((call) => call.isSummary).length, 1)
|
|
120
|
-
return
|
|
143
|
+
return manager.getSessionFile()
|
|
121
144
|
}
|
|
122
145
|
} finally {
|
|
123
146
|
session.dispose()
|
|
124
147
|
}
|
|
125
148
|
}
|
|
126
149
|
|
|
127
|
-
function convert(command, input, output) {
|
|
128
|
-
execFileSync(process.execPath, [
|
|
129
|
-
path.join(
|
|
130
|
-
|
|
150
|
+
function convert(cli, command, input, output) {
|
|
151
|
+
execFileSync(process.execPath, [cli, command, input, output], {
|
|
152
|
+
env: { ...process.env, DSH_HOME: path.join(dir, 'dsh-home') },
|
|
153
|
+
})
|
|
131
154
|
}
|
|
132
155
|
|
|
133
|
-
async function verifyMigration(pi, kind, extension, input, expected) {
|
|
156
|
+
async function verifyMigration(pi, kind, { extension, cli }, input, expected) {
|
|
134
157
|
const exportFile = path.join(dir, `${kind}.dsh.jsonl`)
|
|
135
158
|
const roundTrip = path.join(dir, `${kind}-roundtrip.pi.jsonl`)
|
|
136
|
-
convert('pi2dsh', input, exportFile)
|
|
137
|
-
convert('dsh2pi', exportFile, roundTrip)
|
|
159
|
+
convert(cli, 'pi2dsh', input, exportFile)
|
|
160
|
+
convert(cli, 'dsh2pi', exportFile, roundTrip)
|
|
138
161
|
const read = (file) => readFileSync(file, 'utf8').trimEnd().split('\n').map(JSON.parse)
|
|
139
162
|
assert.deepEqual(read(roundTrip), read(input), `${kind}: pi archive round trip`)
|
|
140
163
|
|
|
@@ -157,11 +180,11 @@ async function verifyMigration(pi, kind, extension, input, expected) {
|
|
|
157
180
|
}, { surfaceOp: 'append' })
|
|
158
181
|
writeFileSync(exportFile, [header, ...dsh.snapshotEvents()].map(JSON.stringify).join('\n') + '\n')
|
|
159
182
|
const returned = path.join(dir, `${kind}-continued.pi.jsonl`)
|
|
160
|
-
convert('dsh2pi', exportFile, returned)
|
|
161
|
-
await run(pi, `${kind}-after-dsh`, extension, returned, [continued, ...expected])
|
|
183
|
+
convert(cli, 'dsh2pi', exportFile, returned)
|
|
184
|
+
await run(pi, `${kind}-after-dsh`, extension, { source: returned, expected: [continued, ...expected] })
|
|
162
185
|
}
|
|
163
186
|
|
|
164
|
-
|
|
187
|
+
async function verify() {
|
|
165
188
|
const baselinePackage = path.join(dir, 'baseline-package')
|
|
166
189
|
for (const file of ['package.json', 'vendor/manifest.json', 'dist/index.js']) {
|
|
167
190
|
const destination = path.join(baselinePackage, file)
|
|
@@ -173,7 +196,8 @@ try {
|
|
|
173
196
|
const baselineExtension = path.join(baselinePackage, 'dist/index.js')
|
|
174
197
|
symlinkSync(path.join(root, 'node_modules'), path.join(dir, 'node_modules'), 'junction')
|
|
175
198
|
const baseline = await host(root, baselinePi)
|
|
176
|
-
const
|
|
199
|
+
const baselineFile = await run(baseline, 'baseline', baselineExtension)
|
|
200
|
+
const rows = readFileSync(baselineFile, 'utf8').trimEnd().split('\n')
|
|
177
201
|
const entries = rows.map((row) => JSON.parse(row))
|
|
178
202
|
const journal = entries.findIndex((entry) =>
|
|
179
203
|
entry.customType === 'dcp/transaction-v1' && entry.data?.info?.summaries > 0,
|
|
@@ -181,13 +205,39 @@ try {
|
|
|
181
205
|
assert.ok(journal > 0, 'baseline did not persist a summary transaction')
|
|
182
206
|
assert.ok(entries.slice(journal + 1).some((entry) => entry.type === 'compaction'),
|
|
183
207
|
'baseline did not commit a native compaction')
|
|
208
|
+
const packed = JSON.parse(npm(
|
|
209
|
+
['pack', '--json', '--ignore-scripts', '--pack-destination', dir], { cwd: root, encoding: 'utf8' },
|
|
210
|
+
))
|
|
211
|
+
const [tarball] = Object.values(packed)
|
|
184
212
|
const candidateDir = path.join(dir, 'candidate')
|
|
185
|
-
|
|
213
|
+
npm([
|
|
186
214
|
'install', '--prefix', candidateDir, '--no-audit', '--no-fund', '--ignore-scripts',
|
|
187
|
-
`${piPackage}@${candidate}`,
|
|
215
|
+
`${piPackage}@${candidate}`, path.join(dir, tarball.filename),
|
|
188
216
|
], { stdio: 'inherit' })
|
|
189
217
|
const upgraded = await host(candidateDir, candidate)
|
|
190
|
-
const
|
|
218
|
+
const installed = path.join(candidateDir, 'node_modules/dsh-compact-pi')
|
|
219
|
+
const manifest = JSON.parse(readFileSync(path.join(installed, 'package.json'), 'utf8'))
|
|
220
|
+
const extension = path.join(installed, manifest.pi.extensions[0])
|
|
221
|
+
const cli = path.join(installed, manifest.bin['dcp-session'])
|
|
222
|
+
const image = {
|
|
223
|
+
type: 'image', mimeType: 'image/png',
|
|
224
|
+
data: (await sharp({
|
|
225
|
+
create: { width: 24, height: 16, channels: 3, background: 'red' },
|
|
226
|
+
}).png().toBuffer()).toString('base64'),
|
|
227
|
+
}
|
|
228
|
+
for (const [mode, trigger] of [['automatic', 'pressure'], ['manual', 'manual']]) {
|
|
229
|
+
const file = await run(upgraded, mode, extension, { image, manual: trigger === 'manual' })
|
|
230
|
+
const session = readFileSync(file, 'utf8').trimEnd().split('\n').map(JSON.parse)
|
|
231
|
+
const checkpoint = session.find((entry) => entry.type === 'compaction' && entry.summary.includes(summary))
|
|
232
|
+
assert.equal(checkpoint?.details?.engine, 'deepseek-harness', `${mode}: no DCP checkpoint persisted`)
|
|
233
|
+
assert.equal(checkpoint.details.dcp?.trigger, trigger)
|
|
234
|
+
const assets = readdirSync(path.join(path.dirname(file), '.dcp-assets'), {
|
|
235
|
+
recursive: true, withFileTypes: true,
|
|
236
|
+
})
|
|
237
|
+
assert.ok(assets.some((entry) => entry.isFile()), `${mode}: no image assets saved`)
|
|
238
|
+
await run(upgraded, `${mode}-reopen`, extension, { source: file, image })
|
|
239
|
+
console.log(`${process.platform}: pi ${candidate} ${mode} compaction and image resume passed`)
|
|
240
|
+
}
|
|
191
241
|
for (const [kind, snapshot] of [['native', rows], ['journal-only', rows.slice(0, journal + 1)]]) {
|
|
192
242
|
const file = path.join(dir, `${kind}.jsonl`)
|
|
193
243
|
writeFileSync(file, snapshot.join('\n') + '\n')
|
|
@@ -210,10 +260,25 @@ try {
|
|
|
210
260
|
}))
|
|
211
261
|
}
|
|
212
262
|
writeFileSync(migrationInput, migrationRows.join('\n') + '\n')
|
|
213
|
-
await verifyMigration(upgraded, kind, extension, migrationInput, expected)
|
|
214
|
-
await run(upgraded, kind, extension, file)
|
|
263
|
+
await verifyMigration(upgraded, kind, { extension, cli }, migrationInput, expected)
|
|
264
|
+
await run(upgraded, kind, extension, { source: file })
|
|
215
265
|
console.log(`pi ${baselinePi} → ${candidate}: ${kind} resume and DSH round trip passed`)
|
|
216
266
|
}
|
|
217
|
-
}
|
|
218
|
-
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
if (dir) {
|
|
270
|
+
await verify()
|
|
271
|
+
} else {
|
|
272
|
+
const temporary = mkdtempSync(path.join(os.tmpdir(), 'dcp-pi-resume-'))
|
|
273
|
+
try {
|
|
274
|
+
const result = spawnSync(process.execPath, [import.meta.filename, candidate], {
|
|
275
|
+
env: { ...process.env, DCP_TEST_WORK_DIR: temporary },
|
|
276
|
+
stdio: 'inherit',
|
|
277
|
+
})
|
|
278
|
+
if (result.error) throw result.error
|
|
279
|
+
process.exitCode = result.status ?? 1
|
|
280
|
+
} finally {
|
|
281
|
+
// Windows holds native modules open until the test process exits.
|
|
282
|
+
rmSync(temporary, { recursive: true, force: true, maxRetries: 5 })
|
|
283
|
+
}
|
|
219
284
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: dcp-migrate-to-dsh
|
|
3
|
+
description: Guide a user through exporting a selected Pi session or importing it into a confirmed DeepSeek Harness Desktop, Web, or TUI target. Use for Pi-to-DSH session migration and portable exports.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Migrate a Pi session to DSH
|
|
7
|
+
|
|
8
|
+
Use `dcp-session migrate` or `node <package-root>/dist/dcp-session.mjs migrate`. Check `--help`. The bundled skill is two directories below the package root. When installed under a skill home, resolve its symlink or locate the DCP package from Pi's package list.
|
|
9
|
+
|
|
10
|
+
1. Ask the user to identify the source and the destination. Use `migrate sources --id <id>` or `migrate sources --cwd <absolute-project>` to show candidate headers when the source path is unclear. Let the user choose when more than one matches.
|
|
11
|
+
2. Confirm the target on the machine that will write it. For a portable export, ask for the export directory. For direct import, ask for Windows Desktop, Linux Desktop, Web, or TUI, the instance or profile name, DSH backend version, DSH home (images), session directory, workspace, and storage encoding. `migrate environment` supplies host information and suggestions to confirm. Run Windows Desktop imports with Windows Node.js. A WSL shell describes a separate environment.
|
|
12
|
+
3. Run `migrate plan` with the confirmed fields and a fresh `--plan-file`. Show the exact output and attachment paths, destination session ID, and any conflict. See [command examples](references/commands.md). For a duplicate, offer to stop or create a separate ID with `--on-conflict copy`. For a mixed Pi/DSH log, offer to stop, select another file, or explicitly recover just the Pi entries with `--recover-pi-entries`. Recovery leaves the original file intact. Encoding and unsupported-format errors need corrected input.
|
|
13
|
+
4. After the user approves the resulting plan, call `migrate apply --plan-file <file> --confirm <code>`. Only use the approved plan and code. If the source or destination changed, rerun the preview and confirm again. For a local interactive terminal, the user can run `dcp-session migrate` and answer the same questions directly.
|
|
14
|
+
5. Report the receipt. For Web, use `migrate verify-web` with an approved launch-URL file when available. For Desktop or TUI, verify that the selected app can open the imported history using its session picker. If app access is unavailable, report the write as complete with UI verification pending. Leave an imported session idle until the user asks to send a prompt.
|
|
15
|
+
|
|
16
|
+
The scripts handle reading, recovery, paths, conflict checks, attachments, and conversion. Keep session contents and Web credentials out of the conversation.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Migration commands
|
|
2
|
+
|
|
3
|
+
Run from the target OS, using an absolute path to the source copy accessible there. A Windows destination uses Windows paths and Windows Node.js. Quote paths with spaces.
|
|
4
|
+
|
|
5
|
+
## Direct import
|
|
6
|
+
|
|
7
|
+
```text
|
|
8
|
+
dcp-session migrate plan --source "<pi.jsonl>" --target windows-desktop --profile desktop --dsh-version 0.2.2-rc.5 --dsh-home "<DSH home>" --session-root "<session directory>" --workspace "<existing workspace>" --encoding zstd --plan-file "<new plan.json>"
|
|
9
|
+
dcp-session migrate apply --plan-file "<plan.json>" --confirm "<code>"
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Use `linux-desktop` for a Linux desktop client on the same machine as its compatible DSH backend. Use the backend's version and storage settings. For Web or TUI use that instance or profile's settings. Distribution version and backend version can differ.
|
|
13
|
+
|
|
14
|
+
For Desktop and Web, choose a workspace already shown in the target app. Refresh the session list if the app was already open when the file was written.
|
|
15
|
+
|
|
16
|
+
## Portable export
|
|
17
|
+
|
|
18
|
+
```text
|
|
19
|
+
dcp-session migrate plan --source "<pi.jsonl>" --target portable --export-dir "<existing directory>" --plan-file "<new plan.json>"
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
After approval, use the same apply command. Move the complete output folder to keep the DSH JSONL and attachments together. Its directory is the attachment home for that copy.
|
|
23
|
+
|
|
24
|
+
## Checks
|
|
25
|
+
|
|
26
|
+
- `migrate sources` reads only headers. Use `--pi-home` when the source uses a non-default Pi agent directory.
|
|
27
|
+
- `migrate environment` shows the script's current host and paths to use as suggestions.
|
|
28
|
+
- `migrate verify-web --url-file "<launch URL file>" --session-id "<id>" --events <count>` checks the list and history. Use the receipt's event count. The private file contains one launch URL belonging to the confirmed Web instance.
|
|
29
|
+
- `written` confirms the disk write. `verified` confirms both Web reads.
|
package/src/codec.ts
CHANGED
|
@@ -79,6 +79,38 @@ export function projectPiForDsh(entries: readonly SessionEntry[]) {
|
|
|
79
79
|
return convertToLlm(system ? [system, ...conversation] : conversation)
|
|
80
80
|
.map((message, index) => ({ type: 'message', id: `projected-${index}`, message }))
|
|
81
81
|
}
|
|
82
|
+
|
|
83
|
+
/** A native DSH step can only carry tools with both an advertised call and a result. */
|
|
84
|
+
function settledTools(projected: ReturnType<typeof projectPiForDsh>) {
|
|
85
|
+
const result: typeof projected = []
|
|
86
|
+
const pending = new Set<string>()
|
|
87
|
+
for (const [index, entry] of projected.entries()) {
|
|
88
|
+
const { message } = entry
|
|
89
|
+
if (message.role === 'toolResult') {
|
|
90
|
+
if (pending.delete(message.toolCallId)) result.push(entry)
|
|
91
|
+
continue
|
|
92
|
+
}
|
|
93
|
+
pending.clear()
|
|
94
|
+
if (message.role !== 'assistant' || message.stopReason === 'error' || message.stopReason === 'aborted') {
|
|
95
|
+
result.push(entry)
|
|
96
|
+
continue
|
|
97
|
+
}
|
|
98
|
+
const followingResults = new Set<string>()
|
|
99
|
+
for (let next = index + 1; next < projected.length; next++) {
|
|
100
|
+
const following = projected[next]!.message
|
|
101
|
+
if (following.role !== 'toolResult') break
|
|
102
|
+
followingResults.add(following.toolCallId)
|
|
103
|
+
}
|
|
104
|
+
const content = message.content.filter((block) => {
|
|
105
|
+
if (block.type !== 'toolCall') return true
|
|
106
|
+
if (!block.id || !followingResults.delete(block.id)) return false
|
|
107
|
+
pending.add(block.id)
|
|
108
|
+
return true
|
|
109
|
+
})
|
|
110
|
+
if (content.length) result.push({ ...entry, message: { ...message, content } })
|
|
111
|
+
}
|
|
112
|
+
return result
|
|
113
|
+
}
|
|
82
114
|
function piHeader(header: DshHeader): PiHeader {
|
|
83
115
|
return {
|
|
84
116
|
type: 'session',
|
|
@@ -128,21 +160,22 @@ export function dshRowsFromPi(
|
|
|
128
160
|
_file?: string,
|
|
129
161
|
imageToDsh?: (image: any) => any,
|
|
130
162
|
projected = projectPiForDsh(entries),
|
|
163
|
+
destination?: Pick<DshHeader, 'id' | 'cwd'>,
|
|
131
164
|
): string {
|
|
132
165
|
const header: DshHeader = {
|
|
133
166
|
type: 'session',
|
|
134
167
|
version: SESSION_FORMAT_VERSION,
|
|
135
|
-
id: pi.id,
|
|
168
|
+
id: destination?.id ?? pi.id,
|
|
136
169
|
createdAt: Date.parse(pi.timestamp),
|
|
137
|
-
cwd: pi.cwd,
|
|
170
|
+
cwd: destination?.cwd ?? pi.cwd,
|
|
138
171
|
isSeeded: false,
|
|
139
172
|
delegationDepth: 0,
|
|
140
|
-
...(pi.parentSession ? { parentSession: pi.parentSession } : {}),
|
|
173
|
+
...(!destination && pi.parentSession ? { parentSession: pi.parentSession } : {}),
|
|
141
174
|
}
|
|
142
175
|
const session = Session.create(header.id, [], headerForSession(header))
|
|
143
176
|
appendPluginRecord(session, PI_HEADER, JSON.parse(JSON.stringify(pi)))
|
|
144
|
-
const state = createSyncState()
|
|
145
|
-
syncPiEntries(session, projected, state, { imageToDsh })
|
|
177
|
+
const state = createSyncState({ persistent: true })
|
|
178
|
+
syncPiEntries(session, settledTools(projected), state, { imageToDsh })
|
|
146
179
|
closeTurn(session, state)
|
|
147
180
|
// Preserve every entry, its original id, parent and metadata. DSH's message
|
|
148
181
|
// surface is an export view; pi resumes from the lossless archive records.
|
|
@@ -162,9 +195,10 @@ export function writeDshFromPi(
|
|
|
162
195
|
entries: readonly any[],
|
|
163
196
|
imageToDsh?: (image: any) => any,
|
|
164
197
|
projected?: ReturnType<typeof projectPiForDsh>,
|
|
198
|
+
destination?: Pick<DshHeader, 'id' | 'cwd'>,
|
|
165
199
|
): void {
|
|
166
200
|
mkdirSync(path.dirname(file), { recursive: true })
|
|
167
|
-
const body = dshRowsFromPi(header, entries, file, imageToDsh, projected)
|
|
201
|
+
const body = dshRowsFromPi(header, entries, file, imageToDsh, projected, destination)
|
|
168
202
|
const tmp = `${file}.${process.pid}.tmp`
|
|
169
203
|
writeFileSync(tmp, body)
|
|
170
204
|
renameSync(tmp, file)
|