dsh-compact-pi 0.2.3-b2 → 0.2.3-b3
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 +6 -0
- package/README.md +16 -5
- package/bin/dcp-session.ts +17 -5
- package/dist/dcp-session.mjs +318 -241
- package/dist/index.js +5 -3
- package/docs/compatibility.md +1 -1
- package/docs/help.md +14 -3
- package/docs/publishing.md +9 -9
- package/docs/testing.md +5 -4
- package/package.json +5 -3
- package/scripts/test-resume.mjs +96 -31
- package/skills/dcp-migrate-to-dsh/SKILL.md +14 -0
- package/src/dsh/import.ts +79 -0
- package/test/convert.test.ts +26 -1
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-b3",
|
|
30635
|
+
dcpVersion: "0.2.3b3",
|
|
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",
|
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-b3
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Restart pi or run `/reload` while idle. `/dcp-status` should show DCP `0.2.3b3` 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
|
|
|
@@ -22,11 +28,16 @@ If a historical summary model is unavailable in pi, use the picker to select an
|
|
|
22
28
|
Use the CLI from the unpacked package or a development checkout with `node dist/dcp-session.mjs --help`. npm installs also expose the `dcp-session` command. Exit the active session or work from a copy and choose a separate output path.
|
|
23
29
|
|
|
24
30
|
```bash
|
|
31
|
+
dcp-session pi2dsh-import session.pi.jsonl
|
|
25
32
|
dcp-session pi2dsh session.pi.jsonl exported.dsh.jsonl
|
|
26
33
|
dcp-session dsh2pi exported.dsh.jsonl imported.pi.jsonl
|
|
27
34
|
pi --session imported.pi.jsonl
|
|
28
35
|
```
|
|
29
36
|
|
|
37
|
+
`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.
|
|
38
|
+
|
|
39
|
+
The package includes [dcp-migrate-to-dsh](../skills/dcp-migrate-to-dsh/SKILL.md). In Pi, request a migration using the skill or run `/skill:dcp-migrate-to-dsh`. To invoke it from DSH, copy its directory into `$DSH_HOME/skills` (default `~/.dsh/skills`). Both hosts need access to the converter and source file.
|
|
40
|
+
|
|
30
41
|
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
42
|
|
|
32
43
|
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.
|
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-b3` corresponds to the displayed version `0.2.3b3`. 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-b3.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-b3
|
|
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-b3
|
|
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,10 @@ 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
|
+
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
21
|
|
|
21
22
|
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
23
|
|
|
23
|
-
The **Pi session compatibility** workflow runs on
|
|
24
|
+
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-b3",
|
|
4
|
+
"dcpVersion": "0.2.3b3",
|
|
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,14 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: dcp-migrate-to-dsh
|
|
3
|
+
description: Migrate a selected pi conversation into DeepSeek Harness so the user can resume it, including DCP summaries, retained messages, and images. Use when asked to continue a pi session in DSH or to export it for a DSH host.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Migrate a pi session to DSH
|
|
7
|
+
|
|
8
|
+
1. Resolve the source to one native pi session JSONL file. Use the path the user or host provides. If given a session ID, match the ID in a pi session header under the relevant pi agent directory (`PI_CODING_AGENT_DIR` or `~/.pi/agent`). When only the project is specified, match its `cwd` and ask which session to use if there are multiple candidates. Read header metadata only for selection. Let DCP read the conversation.
|
|
9
|
+
2. Find the converter. Use `dcp-session` if available, or run `node <dsh-compact-pi-package>/dist/dcp-session.mjs`. When loading this bundled skill, the package root is two directories above this skill folder. In a standard pi npm install it is also under `<pi-agent-dir>/npm/node_modules/dsh-compact-pi`. Check `--help` for `pi2dsh-import` before importing.
|
|
10
|
+
3. Verify the target DSH version and session store. This importer targets the DSH 0.2.3-alpha.2 V4 JSONL layout. Use the target DSH process's `DSH_HOME` for attachments and the target profile's JSONL session root and compression. The defaults are `$DSH_HOME/sessions` (or `~/.dsh/sessions`) and Zstandard. Use `--plain` only when the profile uses plaintext.
|
|
11
|
+
4. Import with `dcp-session pi2dsh-import "<pi-jsonl>"`. Append the configured session root when it differs from the default. Append `--plain` for plaintext. If DCP reports an existing session ID, preserve the existing session and report the conflict. If the target runs on a different machine, run the import there using a securely copied source and a target workspace path valid on that machine. For a portable export, use `dcp-session pi2dsh "<pi-jsonl>" "<new-export.jsonl>"` and keep the corresponding DSH attachment store with it.
|
|
12
|
+
5. Report the returned session ID and project path. Resume from that project using the target UI's session picker or its explicit resume option, for example `dsh-tui --resume "<session-id>"` for the DSH TUI. The import creates a separate DSH session. The current agent session stays open. Ask before sending a first prompt in the imported session.
|
|
13
|
+
|
|
14
|
+
DCP projects the persisted pi branch into DSH and archives the original pi entries. A portable export and an immediate reverse conversion preserve the pi archive. A continued DSH session imports back as the effective DSH context. Avoid printing raw session rows or attachment data in tool output.
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { promises as fs } from 'node:fs'
|
|
2
|
+
import { homedir, tmpdir } from 'node:os'
|
|
3
|
+
import * as path from 'node:path'
|
|
4
|
+
import { promisify } from 'node:util'
|
|
5
|
+
import { constants, zstdCompress } from 'node:zlib'
|
|
6
|
+
import { piToDsh } from './convert.ts'
|
|
7
|
+
import { DSH_FORMAT_VERSION, type DshHeader } from './session.ts'
|
|
8
|
+
|
|
9
|
+
const compress = promisify(zstdCompress)
|
|
10
|
+
const zstdOptions = { params: { [constants.ZSTD_c_checksumFlag]: 1 } }
|
|
11
|
+
|
|
12
|
+
// Match the JSONL persistence layout at the vendored DSH revision.
|
|
13
|
+
function escapeSegment(value: string): string {
|
|
14
|
+
return value.replace(/[^A-Za-z0-9._-]/g, (char) =>
|
|
15
|
+
'~' + char.charCodeAt(0).toString(16).toUpperCase().padStart(4, '0'),
|
|
16
|
+
)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function projectKey(cwd: string): string {
|
|
20
|
+
const readable = escapeSegment(cwd.replace(/[/\\:]+/g, '-')).replace(/^-+/, '')
|
|
21
|
+
return `--${(readable || 'root').slice(0, 251)}--`
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function importPiToDsh(
|
|
25
|
+
input: string,
|
|
26
|
+
root = path.join(process.env.DSH_HOME || path.join(homedir(), '.dsh'), 'sessions'),
|
|
27
|
+
plaintext = false,
|
|
28
|
+
) {
|
|
29
|
+
root = path.resolve(root)
|
|
30
|
+
const stage = await fs.mkdtemp(path.join(tmpdir(), 'dcp-import-'))
|
|
31
|
+
try {
|
|
32
|
+
const raw = path.join(stage, 'session.jsonl')
|
|
33
|
+
const report = await piToDsh(input, raw)
|
|
34
|
+
const bytes = await fs.readFile(raw)
|
|
35
|
+
const headerEnd = bytes.indexOf(0x0a) + 1
|
|
36
|
+
const header = JSON.parse(bytes.subarray(0, headerEnd).toString('utf8')) as DshHeader
|
|
37
|
+
if (header.version !== DSH_FORMAT_VERSION || !header.id || !header.cwd || !path.isAbsolute(header.cwd))
|
|
38
|
+
throw new Error('Import requires a native pi session with an ID and an absolute local project path')
|
|
39
|
+
const id = header.id === '.' || header.id === '..'
|
|
40
|
+
? header.id.replaceAll('.', '~002E')
|
|
41
|
+
: escapeSegment(header.id)
|
|
42
|
+
for await (const existing of fs.glob('*/*/session{,.v*}.jsonl{,.zstd}', { cwd: root })) {
|
|
43
|
+
const filename = path.basename(existing)
|
|
44
|
+
if (!/^session(?:\.v[1-9]\d*)?\.jsonl(?:\.zstd)?$/.test(filename)) continue
|
|
45
|
+
if (filename.endsWith('.zstd') === plaintext)
|
|
46
|
+
throw new Error(`DSH session root uses a different encoding: ${root}`)
|
|
47
|
+
if (path.basename(path.dirname(existing)) === id)
|
|
48
|
+
throw new Error(`DSH session already exists: ${header.id} (${path.join(root, existing)})`)
|
|
49
|
+
}
|
|
50
|
+
const project = path.join(root, projectKey(header.cwd))
|
|
51
|
+
const destination = path.join(project, id)
|
|
52
|
+
const output = path.join(destination, `session.v${header.version}.jsonl${plaintext ? '' : '.zstd'}`)
|
|
53
|
+
// DSH reads the first frame independently when listing session headers.
|
|
54
|
+
const stored = plaintext ? bytes : Buffer.concat(await Promise.all([
|
|
55
|
+
compress(bytes.subarray(0, headerEnd), zstdOptions),
|
|
56
|
+
compress(bytes.subarray(headerEnd), zstdOptions),
|
|
57
|
+
]))
|
|
58
|
+
await fs.mkdir(project, { recursive: true, mode: 0o700 })
|
|
59
|
+
try {
|
|
60
|
+
await fs.mkdir(destination, { mode: 0o700 })
|
|
61
|
+
} catch (error) {
|
|
62
|
+
if ((error as NodeJS.ErrnoException).code === 'EEXIST')
|
|
63
|
+
throw new Error(`DSH session already exists: ${header.id} (${destination})`)
|
|
64
|
+
throw error
|
|
65
|
+
}
|
|
66
|
+
const pending = path.join(destination, '.dcp-import.tmp')
|
|
67
|
+
try {
|
|
68
|
+
await fs.writeFile(pending, stored, { flag: 'wx', mode: 0o600 })
|
|
69
|
+
await fs.rename(pending, output)
|
|
70
|
+
} catch (error) {
|
|
71
|
+
await fs.rm(pending, { force: true })
|
|
72
|
+
await fs.rmdir(destination)
|
|
73
|
+
throw error
|
|
74
|
+
}
|
|
75
|
+
return { ...report, output, sessionId: header.id, cwd: header.cwd }
|
|
76
|
+
} finally {
|
|
77
|
+
await fs.rm(stage, { recursive: true, force: true })
|
|
78
|
+
}
|
|
79
|
+
}
|
package/test/convert.test.ts
CHANGED
|
@@ -4,7 +4,9 @@ import assert from 'node:assert/strict'
|
|
|
4
4
|
import { promises as fs } from 'node:fs'
|
|
5
5
|
import os from 'node:os'
|
|
6
6
|
import path from 'node:path'
|
|
7
|
+
import { zstdDecompressSync } from 'node:zlib'
|
|
7
8
|
import { dshToPi, piToDsh, readPiSession } from '../src/dsh/convert.ts'
|
|
9
|
+
import { importPiToDsh } from '../src/dsh/import.ts'
|
|
8
10
|
import { readDshFile } from '../src/dsh/store.ts'
|
|
9
11
|
|
|
10
12
|
const long = (label: string) => `${label} `.repeat(200)
|
|
@@ -19,7 +21,7 @@ const piRows = [
|
|
|
19
21
|
version: 3,
|
|
20
22
|
id: 'convert-test',
|
|
21
23
|
timestamp: new Date().toISOString(),
|
|
22
|
-
cwd: '
|
|
24
|
+
cwd: path.join(dir, '项目'),
|
|
23
25
|
},
|
|
24
26
|
{
|
|
25
27
|
type: 'message',
|
|
@@ -71,6 +73,29 @@ assert.equal(back.entries.length, 2)
|
|
|
71
73
|
assert.equal(back.entries[0].message.role, 'user')
|
|
72
74
|
assert.equal(back.entries[1].message.role, 'assistant')
|
|
73
75
|
|
|
76
|
+
function sessionRows(bytes: Buffer) {
|
|
77
|
+
return bytes.toString('utf8').trimEnd().split('\n').map((line) => {
|
|
78
|
+
const { time: _time, ...row } = JSON.parse(line)
|
|
79
|
+
return row
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
for (const plain of [false, true]) {
|
|
84
|
+
const root = path.join(dir, plain ? 'plain' : 'zstd')
|
|
85
|
+
const imported = await importPiToDsh(piFile, root, plain)
|
|
86
|
+
assert.equal(imported.sessionId, piRows[0].id)
|
|
87
|
+
assert.equal(imported.cwd, piRows[0].cwd)
|
|
88
|
+
assert.match(path.basename(path.dirname(path.dirname(imported.output))), /~9879~76EE--$/)
|
|
89
|
+
const bytes = await fs.readFile(imported.output)
|
|
90
|
+
assert.deepEqual(
|
|
91
|
+
sessionRows(plain ? bytes : zstdDecompressSync(bytes)),
|
|
92
|
+
sessionRows(await fs.readFile(dshFile)),
|
|
93
|
+
)
|
|
94
|
+
await assert.rejects(importPiToDsh(piFile, root, plain), /session already exists/)
|
|
95
|
+
await assert.rejects(importPiToDsh(piFile, root, !plain), /different encoding/)
|
|
96
|
+
assert.deepEqual(await fs.readFile(imported.output), bytes)
|
|
97
|
+
}
|
|
98
|
+
|
|
74
99
|
console.log('convert ok', {
|
|
75
100
|
dshEvents: dsh!.events.length,
|
|
76
101
|
backEntries: back.entries.length,
|