context-guardian-deepseek-harness 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +99 -0
- package/README.zh-CN.md +94 -0
- package/cordis.patch.yml +9 -0
- package/lib/bridge.d.ts +15 -0
- package/lib/bridge.d.ts.map +1 -0
- package/lib/bridge.js +155 -0
- package/lib/bridge.js.map +1 -0
- package/lib/host-model.d.ts +4 -0
- package/lib/host-model.d.ts.map +1 -0
- package/lib/host-model.js +54 -0
- package/lib/host-model.js.map +1 -0
- package/lib/index.d.ts +16 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +126 -0
- package/lib/index.js.map +1 -0
- package/lib/types.d.ts +43 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +2 -0
- package/lib/types.js.map +1 -0
- package/package.json +67 -0
- package/tsconfig.json +13 -0
package/README.md
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# Context Guardian for DeepSeek Harness
|
|
2
|
+
|
|
3
|
+
[English](README.md) · [简体中文](README.zh-CN.md)
|
|
4
|
+
|
|
5
|
+
This adapter adds a human review step before DeepSeek Harness's native context compaction:
|
|
6
|
+
|
|
7
|
+
```text
|
|
8
|
+
Harness history → Context Guardian inspection → Keep / Drop review → native Harness summary
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
It is a decorator over `dsh-compaction-basic`. DeepSeek Harness continues to own compaction range selection, token accounting, durable session events, summary framing, persistence, and the `/compact` command. If Python, the bridge, model extraction, or human review is unavailable, the adapter logs a warning and continues with native compaction.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
DeepSeek Harness is currently a developer preview, so this adapter is pinned to the `0.1.5-rc.x` API family.
|
|
16
|
+
|
|
17
|
+
The package is not published yet. Install the current checkout into the Web profile:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
dsh plugin --profile web add /absolute/path/to/ContextGuardian/adapters/deepseek-harness
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
This checkout command installs the local adapter tarball into the profile. After npm
|
|
24
|
+
publishing, the argument can be replaced with `context-guardian-deepseek-harness`.
|
|
25
|
+
|
|
26
|
+
After publishing, the intended end-user command is:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
dsh plugin --profile web add context-guardian-deepseek-harness
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Because DeepSeek Harness Web composes compaction inside the selected agent preset,
|
|
33
|
+
installing the package alone does not replace the `standard` preset's nested native
|
|
34
|
+
backend. Create a user preset based on `standard`, replace its `compaction-basic` row
|
|
35
|
+
with `context-guardian-deepseek-harness`, and select that preset (or make it the
|
|
36
|
+
default). The preset must contain this compaction group:
|
|
37
|
+
|
|
38
|
+
```yaml
|
|
39
|
+
- id: compaction
|
|
40
|
+
name: cordis:group
|
|
41
|
+
group: true
|
|
42
|
+
isolate:
|
|
43
|
+
compaction: true
|
|
44
|
+
toolResultPruner: true
|
|
45
|
+
config:
|
|
46
|
+
- id: context-guardian-compaction
|
|
47
|
+
name: context-guardian-deepseek-harness
|
|
48
|
+
- id: command-compact
|
|
49
|
+
name: '@deepseek-ai/dsh-command-compact'
|
|
50
|
+
- id: tool-result-pruner
|
|
51
|
+
name: '@deepseek-ai/dsh-compaction-tool-result-pruner'
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Keep the rest of the copied `standard` preset unchanged. This is required because
|
|
55
|
+
DeepSeek Harness mounts the preset in a per-session scope; a profile-level plugin row
|
|
56
|
+
cannot override the preset's own `compaction-basic` row.
|
|
57
|
+
|
|
58
|
+
Install the Python core in the same environment used by `dsh`, or point the adapter at an interpreter explicitly:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
python3 -m pip install -e /absolute/path/to/ContextGuardian
|
|
62
|
+
export CONTEXT_GUARDIAN_PYTHON=/absolute/path/to/python
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
The adapter does not receive or forward `DEEPSEEK_API_KEY`. Structured inspection calls go back through DeepSeek Harness's active `ctx.llm` route, so Harness remains the only process that resolves provider credentials.
|
|
66
|
+
|
|
67
|
+
Start the web profile and use a sufficiently long session or `/compact`:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
dsh --profile web
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Review candidates appear through Harness's user-question UI. In headless compositions without an answerer, uncertain candidates are conservatively kept. For deterministic local testing, `CONTEXT_GUARDIAN_REVIEW_MODE=keep` or `drop` bypasses the question UI.
|
|
74
|
+
|
|
75
|
+
For a repeatable end-to-end UI test that does not require a long real conversation:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
env PATH="/path/to/node-22.19/bin:$PATH" npm run dsh-fixture-smoke
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
The fixture creates an isolated Web profile, seeds a sufficiently large conversation,
|
|
82
|
+
opens the Harness UI, and pauses on a reviewable SQLite candidate. Select Keep or Drop,
|
|
83
|
+
then confirm the native `/compact` result. It uses a replay model, so no DeepSeek API
|
|
84
|
+
key is required. Exit the temporary Web process with Ctrl-C when finished.
|
|
85
|
+
|
|
86
|
+
## Local development
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
npm install
|
|
90
|
+
npm --workspace adapters/deepseek-harness run typecheck
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
To test a checkout before publishing, install the adapter into a Harness profile from the repository directory:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
dsh plugin --profile web add /absolute/path/to/ContextGuardian/adapters/deepseek-harness
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
The profile bundle disables the stock `compaction-basic` row and inserts the decorated backend. The adapter is intentionally separate from the Python distribution and from the Pi adapter, so each host can evolve against its own lifecycle and UI contract.
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# Context Guardian for DeepSeek Harness
|
|
2
|
+
|
|
3
|
+
[English](README.md) · 简体中文
|
|
4
|
+
|
|
5
|
+
这个适配器在 DeepSeek Harness 原生上下文压缩前增加人工审查:
|
|
6
|
+
|
|
7
|
+
```text
|
|
8
|
+
Harness 历史 → Context Guardian 检查 → Keep / Drop 审查 → Harness 原生摘要
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
它是 `dsh-compaction-basic` 的装饰器。DeepSeek Harness 继续负责压缩范围、
|
|
12
|
+
token 统计、会话事件、摘要格式、持久化和 `/compact` 命令。如果 Python、桥接、
|
|
13
|
+
模型抽取或人工审查不可用,适配器会记录 warning 并继续原生 compaction。
|
|
14
|
+
|
|
15
|
+
## 安装
|
|
16
|
+
|
|
17
|
+
DeepSeek Harness 目前仍是 developer preview,适配器锁定 `0.1.5-rc.x` API 系列。
|
|
18
|
+
当前包还没有发布,请从仓库安装本地适配器:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
dsh plugin --profile web add /absolute/path/to/ContextGuardian/adapters/deepseek-harness
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
正式发布后,目标命令是:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
dsh plugin --profile web add context-guardian-deepseek-harness
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
由于 DeepSeek Harness Web 会在选中的 agent preset 内组合 compaction,仅安装包
|
|
31
|
+
还不够。请复制 `standard` preset,保持其他内容不变,把其中的
|
|
32
|
+
`compaction-basic` 行替换为 `context-guardian-deepseek-harness`,然后选择该
|
|
33
|
+
preset 或将它设为默认。compaction 分组应包含:
|
|
34
|
+
|
|
35
|
+
```yaml
|
|
36
|
+
- id: compaction
|
|
37
|
+
name: cordis:group
|
|
38
|
+
group: true
|
|
39
|
+
isolate:
|
|
40
|
+
compaction: true
|
|
41
|
+
toolResultPruner: true
|
|
42
|
+
config:
|
|
43
|
+
- id: context-guardian-compaction
|
|
44
|
+
name: context-guardian-deepseek-harness
|
|
45
|
+
- id: command-compact
|
|
46
|
+
name: '@deepseek-ai/dsh-command-compact'
|
|
47
|
+
- id: tool-result-pruner
|
|
48
|
+
name: '@deepseek-ai/dsh-compaction-tool-result-pruner'
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
这是必须步骤,因为 Harness 会在每个 session scope 内挂载 preset,profile 级别
|
|
52
|
+
的插件行不能覆盖 preset 自己的 `compaction-basic` 行。
|
|
53
|
+
|
|
54
|
+
Python 核心需要安装在 `dsh` 使用的环境中,也可以显式指定解释器:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
python3 -m pip install -e /absolute/path/to/ContextGuardian
|
|
58
|
+
export CONTEXT_GUARDIAN_PYTHON=/absolute/path/to/python
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
适配器不会接收或转发 `DEEPSEEK_API_KEY`。结构化检查会通过 Harness 当前的
|
|
62
|
+
`ctx.llm` 路由执行,由 Harness 负责解析 Provider 凭证。
|
|
63
|
+
|
|
64
|
+
## 交互式验证
|
|
65
|
+
|
|
66
|
+
启动 Web profile:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
dsh --profile web
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
要验证完整流程而不进行很长的真实对话,在仓库根目录运行:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
env PATH="/path/to/node-22.19/bin:$PATH" npm run dsh-fixture-smoke
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
fixture 会创建隔离的 Web profile,预置足够长的会话,打开 Harness UI,并在
|
|
79
|
+
SQLite 候选上暂停,让你选择 Keep 或 Drop,随后确认原生 `/compact` 成功。它
|
|
80
|
+
使用 replay model,不需要 DeepSeek API Key。结束临时 Web 进程时按 Ctrl-C。
|
|
81
|
+
|
|
82
|
+
在没有 answerer 的无头模式中,未决候选会保守地 Keep;也可以用
|
|
83
|
+
`CONTEXT_GUARDIAN_REVIEW_MODE=keep` 或 `drop` 绕过询问 UI。
|
|
84
|
+
|
|
85
|
+
## 本地开发
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
npm install
|
|
89
|
+
npm --workspace adapters/deepseek-harness run typecheck
|
|
90
|
+
npm --workspace adapters/deepseek-harness run test
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
这个适配器与 Python distribution、Pi 适配器分别发布,因此每个宿主可以按自己
|
|
94
|
+
的生命周期和 UI 合同独立演进。
|
package/cordis.patch.yml
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Replace DeepSeek Harness's basic backend with Context Guardian's decorated
|
|
2
|
+
# backend. The native selection, transaction, persistence, and summary format
|
|
3
|
+
# remain owned by dsh-compaction-basic.
|
|
4
|
+
- id: compaction-basic
|
|
5
|
+
disabled: true
|
|
6
|
+
|
|
7
|
+
- insert:
|
|
8
|
+
- id: context-guardian-compaction
|
|
9
|
+
name: 'context-guardian-deepseek-harness'
|
package/lib/bridge.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
import type { Agent } from "@deepseek-ai/dsh-agent";
|
|
3
|
+
import type { Guidance, GuardianMessage, InspectionResult, MemoryCandidate } from "./types.js";
|
|
4
|
+
export declare class GuardianBridgeError extends Error {
|
|
5
|
+
}
|
|
6
|
+
export declare function normalizeDeepSeekMessages(_system: string | undefined, messages: readonly any[]): GuardianMessage[];
|
|
7
|
+
export declare class GuardianBridge {
|
|
8
|
+
inspect(ctx: Context, agent: Agent, messages: GuardianMessage[], signal: AbortSignal): Promise<InspectionResult>;
|
|
9
|
+
guidance(ctx: Context, agent: Agent, candidates: MemoryCandidate[], decisions: Array<{
|
|
10
|
+
candidate_id: string;
|
|
11
|
+
action: "keep" | "drop";
|
|
12
|
+
}>, signal: AbortSignal): Promise<Guidance>;
|
|
13
|
+
private request;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=bridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../src/bridge.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAEpD,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,gBAAgB,EAAE,eAAe,EAAiB,MAAM,YAAY,CAAC;AAK9G,qBAAa,mBAAoB,SAAQ,KAAK;CAAG;AAsBjD,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,QAAQ,EAAE,SAAS,GAAG,EAAE,GACvB,eAAe,EAAE,CA8BnB;AAED,qBAAa,cAAc;IACnB,OAAO,CACX,GAAG,EAAE,OAAO,EACZ,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,eAAe,EAAE,EAC3B,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,gBAAgB,CAAC;IAKtB,QAAQ,CACZ,GAAG,EAAE,OAAO,EACZ,KAAK,EAAE,KAAK,EACZ,UAAU,EAAE,eAAe,EAAE,EAC7B,SAAS,EAAE,KAAK,CAAC;QAAE,YAAY,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC,EACnE,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,QAAQ,CAAC;YASN,OAAO;CAmFtB"}
|
package/lib/bridge.js
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { createInterface } from "node:readline";
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import { randomUUID } from "node:crypto";
|
|
4
|
+
import { generateStructuredWithHost } from "./host-model.js";
|
|
5
|
+
const PROTOCOL_VERSION = 1;
|
|
6
|
+
const DEFAULT_TIMEOUT_MS = 30_000;
|
|
7
|
+
export class GuardianBridgeError extends Error {
|
|
8
|
+
}
|
|
9
|
+
function pythonCommand() {
|
|
10
|
+
return process.env.CONTEXT_GUARDIAN_PYTHON || "python3";
|
|
11
|
+
}
|
|
12
|
+
function timeoutMs() {
|
|
13
|
+
const value = Number(process.env.CONTEXT_GUARDIAN_TIMEOUT_MS ?? DEFAULT_TIMEOUT_MS);
|
|
14
|
+
return Number.isFinite(value) && value > 0 ? Math.min(Math.floor(value), 120_000) : DEFAULT_TIMEOUT_MS;
|
|
15
|
+
}
|
|
16
|
+
function pythonEnvironment() {
|
|
17
|
+
const environment = {};
|
|
18
|
+
for (const name of ["PATH", "LANG", "LC_ALL", "TMPDIR", "TMP", "TEMP"]) {
|
|
19
|
+
const value = process.env[name];
|
|
20
|
+
if (value !== undefined)
|
|
21
|
+
environment[name] = value;
|
|
22
|
+
}
|
|
23
|
+
const pythonPath = process.env.CONTEXT_GUARDIAN_PYTHONPATH;
|
|
24
|
+
if (pythonPath !== undefined)
|
|
25
|
+
environment.PYTHONPATH = pythonPath;
|
|
26
|
+
return environment;
|
|
27
|
+
}
|
|
28
|
+
export function normalizeDeepSeekMessages(_system, messages) {
|
|
29
|
+
const result = [];
|
|
30
|
+
for (const [index, message] of messages.entries()) {
|
|
31
|
+
if (message.role === "system")
|
|
32
|
+
continue;
|
|
33
|
+
const sourceKind = message.source?.kind;
|
|
34
|
+
const role = sourceKind === "tool" ? "tool" : String(message.role ?? "unknown");
|
|
35
|
+
const blocks = Array.isArray(message.content) ? message.content : [message.content];
|
|
36
|
+
const content = blocks.map((block) => {
|
|
37
|
+
if (typeof block === "string")
|
|
38
|
+
return block;
|
|
39
|
+
if (block?.type === "text" || block?.type === "reasoning")
|
|
40
|
+
return String(block.text ?? "");
|
|
41
|
+
if (block?.type === "tool-call")
|
|
42
|
+
return `Tool call ${String(block.name ?? "")}: ${String(block.arguments ?? "")}`;
|
|
43
|
+
if (block?.type === "tool-result") {
|
|
44
|
+
const inner = Array.isArray(block.content) ? block.content : [];
|
|
45
|
+
return inner.map((item) => item?.type === "text" ? String(item.text ?? "") : "").join("\n");
|
|
46
|
+
}
|
|
47
|
+
return "";
|
|
48
|
+
}).filter(Boolean).join("\n").trim();
|
|
49
|
+
if (!content)
|
|
50
|
+
continue;
|
|
51
|
+
const error = blocks.some((block) => block?.type === "tool-result" && block.isError === true);
|
|
52
|
+
result.push({
|
|
53
|
+
role,
|
|
54
|
+
content,
|
|
55
|
+
id: String(message.id ?? `dsh_message_${String(index + 1).padStart(4, "0")}`),
|
|
56
|
+
is_error: error,
|
|
57
|
+
metadata: { source: sourceKind },
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
export class GuardianBridge {
|
|
63
|
+
async inspect(ctx, agent, messages, signal) {
|
|
64
|
+
const result = await this.request(ctx, agent, "inspect", { messages, provider: "host" }, signal);
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
async guidance(ctx, agent, candidates, decisions, signal) {
|
|
68
|
+
const result = await this.request(ctx, agent, "guidance", {
|
|
69
|
+
candidates,
|
|
70
|
+
decisions,
|
|
71
|
+
provider: "rules",
|
|
72
|
+
}, signal);
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
async request(ctx, agent, operation, body, signal) {
|
|
76
|
+
const child = spawn(pythonCommand(), ["-m", "context_guardian", "bridge", "--stdio"], {
|
|
77
|
+
cwd: agent.session.header.cwd ?? process.cwd(),
|
|
78
|
+
shell: false,
|
|
79
|
+
env: pythonEnvironment(),
|
|
80
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
81
|
+
});
|
|
82
|
+
const requestId = randomUUID();
|
|
83
|
+
const readline = createInterface({ input: child.stdout });
|
|
84
|
+
let stderr = "";
|
|
85
|
+
child.stderr.on("data", (chunk) => { stderr = `${stderr}${String(chunk)}`.slice(-4000); });
|
|
86
|
+
const abort = () => child.kill("SIGTERM");
|
|
87
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
88
|
+
const timer = setTimeout(() => child.kill("SIGTERM"), timeoutMs());
|
|
89
|
+
try {
|
|
90
|
+
child.stdin.write(JSON.stringify({
|
|
91
|
+
protocol_version: PROTOCOL_VERSION,
|
|
92
|
+
type: "request",
|
|
93
|
+
request_id: requestId,
|
|
94
|
+
operation,
|
|
95
|
+
...body,
|
|
96
|
+
}) + "\n");
|
|
97
|
+
for await (const line of readline) {
|
|
98
|
+
if (!line.trim())
|
|
99
|
+
continue;
|
|
100
|
+
let frame;
|
|
101
|
+
try {
|
|
102
|
+
frame = JSON.parse(line);
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
throw new GuardianBridgeError("Context Guardian returned invalid JSON");
|
|
106
|
+
}
|
|
107
|
+
if (frame.protocol_version !== PROTOCOL_VERSION) {
|
|
108
|
+
throw new GuardianBridgeError("Context Guardian returned an unsupported protocol version");
|
|
109
|
+
}
|
|
110
|
+
if (frame.type === "error")
|
|
111
|
+
throw new GuardianBridgeError(frame.error ?? "Context Guardian protocol error");
|
|
112
|
+
if (frame.type === "provider_request") {
|
|
113
|
+
if (!frame.request_id || !frame.prompt || !frame.schema) {
|
|
114
|
+
throw new GuardianBridgeError("Context Guardian provider request is malformed");
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
const data = await generateStructuredWithHost(ctx, agent, frame.prompt, frame.schema, signal);
|
|
118
|
+
child.stdin.write(JSON.stringify({
|
|
119
|
+
protocol_version: PROTOCOL_VERSION,
|
|
120
|
+
type: "provider_response",
|
|
121
|
+
request_id: frame.request_id,
|
|
122
|
+
ok: true,
|
|
123
|
+
data,
|
|
124
|
+
}) + "\n");
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
child.stdin.write(JSON.stringify({
|
|
128
|
+
protocol_version: PROTOCOL_VERSION,
|
|
129
|
+
type: "provider_response",
|
|
130
|
+
request_id: frame.request_id,
|
|
131
|
+
ok: false,
|
|
132
|
+
error: error instanceof Error ? error.message : String(error),
|
|
133
|
+
}) + "\n");
|
|
134
|
+
}
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
if (frame.type !== "result" || frame.request_id !== requestId) {
|
|
138
|
+
throw new GuardianBridgeError("Context Guardian returned an unrelated response");
|
|
139
|
+
}
|
|
140
|
+
if (!frame.ok)
|
|
141
|
+
throw new GuardianBridgeError(frame.error ?? "Context Guardian request failed");
|
|
142
|
+
return frame.result;
|
|
143
|
+
}
|
|
144
|
+
throw new GuardianBridgeError(stderr || "Context Guardian process exited without a result");
|
|
145
|
+
}
|
|
146
|
+
finally {
|
|
147
|
+
clearTimeout(timer);
|
|
148
|
+
signal.removeEventListener("abort", abort);
|
|
149
|
+
readline.close();
|
|
150
|
+
if (!child.killed)
|
|
151
|
+
child.kill("SIGTERM");
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=bridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge.js","sourceRoot":"","sources":["../src/bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAG7D,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAC3B,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAElC,MAAM,OAAO,mBAAoB,SAAQ,KAAK;CAAG;AAEjD,SAAS,aAAa;IACpB,OAAO,OAAO,CAAC,GAAG,CAAC,uBAAuB,IAAI,SAAS,CAAC;AAC1D,CAAC;AAED,SAAS,SAAS;IAChB,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,2BAA2B,IAAI,kBAAkB,CAAC,CAAC;IACpF,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAA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C,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;yBAC9D,CAAC,GAAG,IAAI,CAAC,CAAC;oBACb,CAAC;oBACD,SAAS;gBACX,CAAC;gBAED,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;oBAC9D,MAAM,IAAI,mBAAmB,CAAC,iDAAiD,CAAC,CAAC;gBACnF,CAAC;gBACD,IAAI,CAAC,KAAK,CAAC,EAAE;oBAAE,MAAM,IAAI,mBAAmB,CAAC,KAAK,CAAC,KAAK,IAAI,iCAAiC,CAAC,CAAC;gBAC/F,OAAO,KAAK,CAAC,MAAM,CAAC;YACtB,CAAC;YACD,MAAM,IAAI,mBAAmB,CAAC,MAAM,IAAI,kDAAkD,CAAC,CAAC;QAC9F,CAAC;gBAAS,CAAC;YACT,YAAY,CAAC,KAAK,CAAC,CAAC;YACpB,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;YAC3C,QAAQ,CAAC,KAAK,EAAE,CAAC;YACjB,IAAI,CAAC,KAAK,CAAC,MAAM;gBAAE,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC3C,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
import type { Agent } from "@deepseek-ai/dsh-agent";
|
|
3
|
+
export declare function generateStructuredWithHost(ctx: Context, agent: Agent, prompt: string, schema: Record<string, unknown>, signal: AbortSignal): Promise<unknown>;
|
|
4
|
+
//# sourceMappingURL=host-model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host-model.d.ts","sourceRoot":"","sources":["../src/host-model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAyBpD,wBAAsB,0BAA0B,CAC9C,GAAG,EAAE,OAAO,EACZ,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,OAAO,CAAC,CAgClB"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { BlockAssembler, createUserMessage, LlmError } from "@deepseek-ai/dsh-llm";
|
|
2
|
+
function extractJson(text) {
|
|
3
|
+
const trimmed = text.trim();
|
|
4
|
+
const fenced = trimmed.match(/```(?:json)?\s*([\s\S]*?)\s*```/i);
|
|
5
|
+
return JSON.parse(fenced?.[1] ?? trimmed);
|
|
6
|
+
}
|
|
7
|
+
function routeFor(agent) {
|
|
8
|
+
const config = agent.session.requestHeader()?.config;
|
|
9
|
+
if (config === undefined || config.provider.length === 0 || config.model.length === 0) {
|
|
10
|
+
throw new Error("DeepSeek Harness has no active provider/model route");
|
|
11
|
+
}
|
|
12
|
+
return { provider: config.provider, model: config.model };
|
|
13
|
+
}
|
|
14
|
+
function textFromBlocks(blocks) {
|
|
15
|
+
return blocks
|
|
16
|
+
.filter((block) => block.type === "text" || block.type === "reasoning")
|
|
17
|
+
.map((block) => block.text ?? "")
|
|
18
|
+
.join("\n")
|
|
19
|
+
.trim();
|
|
20
|
+
}
|
|
21
|
+
export async function generateStructuredWithHost(ctx, agent, prompt, schema, signal) {
|
|
22
|
+
const route = routeFor(agent);
|
|
23
|
+
const assembler = new BlockAssembler();
|
|
24
|
+
const request = ctx.llm.stream({
|
|
25
|
+
provider: route.provider,
|
|
26
|
+
model: route.model,
|
|
27
|
+
system: "You are a structured extraction service. Return only valid JSON matching the supplied JSON Schema. Do not use tools.",
|
|
28
|
+
messages: [createUserMessage({
|
|
29
|
+
content: [{
|
|
30
|
+
type: "text",
|
|
31
|
+
text: `${prompt}\n\nJSON Schema:\n${JSON.stringify(schema)}`,
|
|
32
|
+
}],
|
|
33
|
+
source: { kind: "plugin", plugin: "context-guardian-deepseek-harness" },
|
|
34
|
+
})],
|
|
35
|
+
maxTokens: 4096,
|
|
36
|
+
sessionId: agent.session.id,
|
|
37
|
+
purpose: "compaction",
|
|
38
|
+
signal,
|
|
39
|
+
});
|
|
40
|
+
for await (const chunk of request)
|
|
41
|
+
assembler.push(chunk);
|
|
42
|
+
const finish = assembler.finish;
|
|
43
|
+
if (finish.kind === "error" || finish.kind === "aborted") {
|
|
44
|
+
throw new LlmError(finish.failure.message, finish.failure.code);
|
|
45
|
+
}
|
|
46
|
+
if (finish.kind === "max-tokens") {
|
|
47
|
+
throw new Error("structured Context Guardian extraction reached the token cap");
|
|
48
|
+
}
|
|
49
|
+
const text = textFromBlocks(assembler.blocks());
|
|
50
|
+
if (text.length === 0)
|
|
51
|
+
throw new Error("DeepSeek Harness returned no structured extraction text");
|
|
52
|
+
return extractJson(text);
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=host-model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host-model.js","sourceRoot":"","sources":["../src/host-model.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEnF,SAAS,WAAW,CAAC,IAAY;IAC/B,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;IAC5B,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,kCAAkC,CAAC,CAAC;IACjE,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC;AAC5C,CAAC;AAED,SAAS,QAAQ,CAAC,KAAY;IAC5B,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,aAAa,EAAE,EAAE,MAAM,CAAC;IACrD,IAAI,MAAM,KAAK,SAAS,IA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xE,CAAC,CAAC;QACH,SAAS,EAAE,IAAI;QACf,SAAS,EAAE,KAAK,CAAC,OAAO,CAAC,EAAE;QAC3B,OAAO,EAAE,YAAY;QACrB,MAAM;KACP,CAAC,CAAC;IAEH,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,OAAO;QAAE,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACzD,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC;IAChC,IAAI,MAAM,CAAC,IAAI,KAAK,OAAO,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QACzD,MAAM,IAAI,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAClE,CAAC;IACD,IAAI,MAAM,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;QACjC,MAAM,IAAI,KAAK,CAAC,8DAA8D,CAAC,CAAC;IAClF,CAAC;IAED,MAAM,IAAI,GAAG,cAAc,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC;IAChD,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;IAClG,OAAO,WAAW,CAAC,IAAI,CAAC,CAAC;AAC3B,CAAC"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BasicCompactionEngine } from "@deepseek-ai/dsh-compaction-basic";
|
|
2
|
+
import type { Agent } from "@deepseek-ai/dsh-agent";
|
|
3
|
+
export declare const name = "context-guardian-deepseek-harness";
|
|
4
|
+
type NativeSummarize = BasicCompactionEngine["summarize"];
|
|
5
|
+
type NativeSummarizeInput = Parameters<NativeSummarize>[0];
|
|
6
|
+
type NativeSummarizeResult = Awaited<ReturnType<NativeSummarize>>;
|
|
7
|
+
/**
|
|
8
|
+
* Decorates DeepSeek Harness's native backend with Context Guardian review.
|
|
9
|
+
* The inherited engine still owns selection, shrink checks, durable markers,
|
|
10
|
+
* session replacement, and the final structured checkpoint summary.
|
|
11
|
+
*/
|
|
12
|
+
export declare class ContextGuardianCompactionEngine extends BasicCompactionEngine {
|
|
13
|
+
protected summarize(input: NativeSummarizeInput, agent: Agent, signal?: AbortSignal): Promise<NativeSummarizeResult>;
|
|
14
|
+
}
|
|
15
|
+
export default ContextGuardianCompactionEngine;
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAMpD,eAAO,MAAM,IAAI,sCAAsC,CAAC;AAMxD,KAAK,eAAe,GAAG,qBAAqB,CAAC,WAAW,CAAC,CAAC;AAC1D,KAAK,oBAAoB,GAAG,UAAU,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3D,KAAK,qBAAqB,GAAG,OAAO,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC,CAAC;AAkGlE;;;;GAIG;AACH,qBAAa,+BAAgC,SAAQ,qBAAqB;cAC/C,SAAS,CAChC,KAAK,EAAE,oBAAoB,EAC3B,KAAK,EAAE,KAAK,EACZ,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,qBAAqB,CAAC;CA+BlC;AAED,eAAe,+BAA+B,CAAC"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { BasicCompactionEngine } from "@deepseek-ai/dsh-compaction-basic";
|
|
2
|
+
import { createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
3
|
+
import { GuardianBridge, normalizeDeepSeekMessages } from "./bridge.js";
|
|
4
|
+
export const name = "context-guardian-deepseek-harness";
|
|
5
|
+
if (process.env.CONTEXT_GUARDIAN_DEBUG === "1") {
|
|
6
|
+
console.error("context guardian: adapter module loaded");
|
|
7
|
+
}
|
|
8
|
+
const bridge = new GuardianBridge();
|
|
9
|
+
const KEEP = "Keep";
|
|
10
|
+
const DROP = "Drop";
|
|
11
|
+
function debug(ctx, message) {
|
|
12
|
+
if (process.env.CONTEXT_GUARDIAN_DEBUG === "1") {
|
|
13
|
+
const line = `context guardian: ${message}`;
|
|
14
|
+
console.error(line);
|
|
15
|
+
ctx.logger.info(line);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function candidateDetail(candidate) {
|
|
19
|
+
const reason = candidate.reason ? `\n\nReason: ${candidate.reason}` : "";
|
|
20
|
+
return `Category: ${candidate.category}\nImportance: ${candidate.importance.toFixed(2)} · Confidence: ${candidate.confidence.toFixed(2)}\n\n${candidate.content}${reason}`;
|
|
21
|
+
}
|
|
22
|
+
function reviewQuestions(candidates) {
|
|
23
|
+
return candidates.map((candidate) => ({
|
|
24
|
+
id: candidate.id,
|
|
25
|
+
header: `Context Guardian · ${candidate.category}`,
|
|
26
|
+
question: "Keep this memory in the compaction guidance?",
|
|
27
|
+
detail: candidateDetail(candidate),
|
|
28
|
+
options: [
|
|
29
|
+
{ label: KEEP, description: "Tell the native compactor to preserve this item." },
|
|
30
|
+
{ label: DROP, description: "Tell the native compactor this item may be discarded." },
|
|
31
|
+
],
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
function keepAll(candidates) {
|
|
35
|
+
return candidates.map((candidate) => ({ candidate_id: candidate.id, action: "keep" }));
|
|
36
|
+
}
|
|
37
|
+
function errorCode(error) {
|
|
38
|
+
return typeof error === "object" && error !== null && "code" in error
|
|
39
|
+
? String(error.code)
|
|
40
|
+
: undefined;
|
|
41
|
+
}
|
|
42
|
+
async function review(ctx, agent, candidates, signal) {
|
|
43
|
+
if (candidates.length === 0)
|
|
44
|
+
return [];
|
|
45
|
+
const mode = process.env.CONTEXT_GUARDIAN_REVIEW_MODE;
|
|
46
|
+
if (mode === "keep")
|
|
47
|
+
return keepAll(candidates);
|
|
48
|
+
if (mode === "drop")
|
|
49
|
+
return candidates.map((candidate) => ({ candidate_id: candidate.id, action: "drop" }));
|
|
50
|
+
const interaction = ctx.get("userQuestions");
|
|
51
|
+
debug(ctx, `reviewing ${String(candidates.length)} candidate(s); userQuestions=${interaction === undefined ? "unavailable" : "available"}`);
|
|
52
|
+
if (interaction === undefined)
|
|
53
|
+
return keepAll(candidates);
|
|
54
|
+
try {
|
|
55
|
+
const answer = await interaction.ask({
|
|
56
|
+
questions: reviewQuestions(candidates),
|
|
57
|
+
agent,
|
|
58
|
+
signal,
|
|
59
|
+
});
|
|
60
|
+
const byId = new Map(answer.answers.map((item) => [item.id, item]));
|
|
61
|
+
return candidates.map((candidate) => {
|
|
62
|
+
const item = byId.get(candidate.id);
|
|
63
|
+
if (item?.custom !== undefined || item?.selected.length !== 1) {
|
|
64
|
+
throw new Error(`Context Guardian received an invalid answer for ${candidate.id}`);
|
|
65
|
+
}
|
|
66
|
+
if (item.selected[0] === KEEP)
|
|
67
|
+
return { candidate_id: candidate.id, action: "keep" };
|
|
68
|
+
if (item.selected[0] === DROP)
|
|
69
|
+
return { candidate_id: candidate.id, action: "drop" };
|
|
70
|
+
throw new Error(`Context Guardian received an unknown answer for ${candidate.id}`);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
debug(ctx, `userQuestions failed with ${errorCode(error) ?? (error instanceof Error ? error.message : String(error))}`);
|
|
75
|
+
// Headless compositions commonly provide the service seam without a UI
|
|
76
|
+
// answerer. Treat that case conservatively; an explicit cancellation or
|
|
77
|
+
// protocol failure is allowed to fail open to native compaction below.
|
|
78
|
+
if (errorCode(error) === "NO_PROVIDER")
|
|
79
|
+
return keepAll(candidates);
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function nativeInputWithGuidance(input, text) {
|
|
84
|
+
const guidanceMessage = createUserMessage({
|
|
85
|
+
content: [{ type: "text", text }],
|
|
86
|
+
source: { kind: "plugin", plugin: name },
|
|
87
|
+
});
|
|
88
|
+
return {
|
|
89
|
+
...input,
|
|
90
|
+
messages: [...input.messages, guidanceMessage],
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function normalizeInput(input) {
|
|
94
|
+
const candidate = input;
|
|
95
|
+
return normalizeDeepSeekMessages(candidate.system, input.messages);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Decorates DeepSeek Harness's native backend with Context Guardian review.
|
|
99
|
+
* The inherited engine still owns selection, shrink checks, durable markers,
|
|
100
|
+
* session replacement, and the final structured checkpoint summary.
|
|
101
|
+
*/
|
|
102
|
+
export class ContextGuardianCompactionEngine extends BasicCompactionEngine {
|
|
103
|
+
async summarize(input, agent, signal) {
|
|
104
|
+
let guidedInput;
|
|
105
|
+
try {
|
|
106
|
+
const operationSignal = signal ?? new AbortController().signal;
|
|
107
|
+
const inspection = await bridge.inspect(this.ctx, agent, normalizeInput(input), operationSignal);
|
|
108
|
+
debug(this.ctx, `inspection returned ${String(inspection.candidates.length)} candidate(s), ${String(inspection.review.length)} for review`);
|
|
109
|
+
const decisions = [
|
|
110
|
+
...keepAll(inspection.auto_keep),
|
|
111
|
+
...inspection.auto_drop.map((candidate) => ({ candidate_id: candidate.id, action: "drop" })),
|
|
112
|
+
...await review(this.ctx, agent, inspection.review, operationSignal),
|
|
113
|
+
];
|
|
114
|
+
const guidance = await bridge.guidance(this.ctx, agent, inspection.candidates, decisions, operationSignal);
|
|
115
|
+
guidedInput = nativeInputWithGuidance(input, guidance.text);
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
119
|
+
this.ctx.logger.warn(`context guardian unavailable; continuing native compaction: ${message}`);
|
|
120
|
+
return super.summarize(input, agent, signal);
|
|
121
|
+
}
|
|
122
|
+
return super.summarize(guidedInput, agent, signal);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
export default ContextGuardianCompactionEngine;
|
|
126
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAE1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAGzD,OAAO,EAAE,cAAc,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAExE,MAAM,CAAC,MAAM,IAAI,GAAG,mCAAmC,CAAC;AAExD,IAAI,OAAO,CAAC,GAAG,CAAC,sBAAsB,KAAK,GAAG,EAAE,CAAC;IAC/C,OAAO,CAAC,KAAK,CAAC,yCAAyC,CAAC,CAAC;AAC3D,CAAC;AAMD,MAAM,MAAM,GAAG,IAAI,cAAc,EAAE,CAAC;AACpC,MAAM,IAAI,GAAG,MAAM,CAAC;AACpB,MAAM,IAAI,GAAG,MAAM,CAAC;AAEpB,SAAS,KAAK,CAAC,GAAY,EAAE,OAAe;IAC1C,IAAI,OAAO,CAAC,GAAG,CAAC,sBAAsB,KAAK,GAAG,EAAE,CAAC;QAC/C,MAAM,IAAI,GAAG,qBAAqB,OAAO,EAAE,CAAC;QAC5C,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACpB,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;AACH,CAAC;AAED,SAAS,eAAe,CAAC,SAA0B;IACjD,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,eAAe,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACzE,OAAO,aAAa,SAAS,CAAC,QAAQ,iBAAiB,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,kBAAkB,SAAS,CAAC,UAAU,C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C,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACvE,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,+DAA+D,OAAO,EAAE,CAAC,CAAC;YAC/F,OAAO,KAAK,CAAC,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;QAC/C,CAAC;QACD,OAAO,KAAK,CAAC,SAAS,CAAC,WAAW,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;IACrD,CAAC;CACF;AAED,eAAe,+BAA+B,CAAC"}
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export interface GuardianMessage {
|
|
2
|
+
role: string;
|
|
3
|
+
content: string;
|
|
4
|
+
id: string;
|
|
5
|
+
tool_name?: string;
|
|
6
|
+
is_error?: boolean;
|
|
7
|
+
metadata?: Record<string, unknown>;
|
|
8
|
+
}
|
|
9
|
+
export interface MemoryCandidate {
|
|
10
|
+
id: string;
|
|
11
|
+
content: string;
|
|
12
|
+
category: string;
|
|
13
|
+
importance: number;
|
|
14
|
+
confidence: number;
|
|
15
|
+
suggested_action: "keep" | "drop" | "review";
|
|
16
|
+
reason?: string | null;
|
|
17
|
+
source_message_ids: string[];
|
|
18
|
+
}
|
|
19
|
+
export interface InspectionResult {
|
|
20
|
+
candidates: MemoryCandidate[];
|
|
21
|
+
auto_keep: MemoryCandidate[];
|
|
22
|
+
auto_drop: MemoryCandidate[];
|
|
23
|
+
review: MemoryCandidate[];
|
|
24
|
+
mode: "rules" | "provider";
|
|
25
|
+
policy_version: string;
|
|
26
|
+
}
|
|
27
|
+
export interface Guidance {
|
|
28
|
+
must_preserve: string[];
|
|
29
|
+
can_discard: string[];
|
|
30
|
+
unresolved: string[];
|
|
31
|
+
text: string;
|
|
32
|
+
}
|
|
33
|
+
export interface ProtocolFrame {
|
|
34
|
+
protocol_version?: number;
|
|
35
|
+
type?: string;
|
|
36
|
+
request_id?: string;
|
|
37
|
+
ok?: boolean;
|
|
38
|
+
error?: string;
|
|
39
|
+
result?: unknown;
|
|
40
|
+
prompt?: string;
|
|
41
|
+
schema?: Record<string, unknown>;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,EAAE,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAC;IAC7C,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,kBAAkB,EAAE,MAAM,EAAE,CAAC;CAC9B;AAED,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,eAAe,EAAE,CAAC;IAC9B,SAAS,EAAE,eAAe,EAAE,CAAC;IAC7B,SAAS,EAAE,eAAe,EAAE,CAAC;IAC7B,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1B,IAAI,EAAE,OAAO,GAAG,UAAU,CAAC;IAC3B,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,QAAQ;IACvB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,aAAa;IAC5B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,EAAE,CAAC,EAAE,OAAO,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC"}
|
package/lib/types.js
ADDED
package/lib/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "context-guardian-deepseek-harness",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Human review before DeepSeek Harness context compaction",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"types": "lib/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./lib/index.d.ts",
|
|
11
|
+
"default": "./lib/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/deulofeu1/context-guardian.git"
|
|
19
|
+
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=22.19.0"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"lib",
|
|
28
|
+
"cordis.patch.yml",
|
|
29
|
+
"README.md",
|
|
30
|
+
"README.zh-CN.md",
|
|
31
|
+
"tsconfig.json"
|
|
32
|
+
],
|
|
33
|
+
"dsh": {
|
|
34
|
+
"bundle": {
|
|
35
|
+
"patch": "./cordis.patch.yml"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"@deepseek-ai/cordis": ">=4.0.2 <5",
|
|
40
|
+
"@deepseek-ai/dsh-agent": ">=0.1.5-rc.1 <0.1.6",
|
|
41
|
+
"@deepseek-ai/dsh-compaction-basic": ">=0.1.5-rc.1 <0.1.6",
|
|
42
|
+
"@deepseek-ai/dsh-llm": ">=0.1.5-rc.1 <0.1.6"
|
|
43
|
+
},
|
|
44
|
+
"peerDependenciesMeta": {
|
|
45
|
+
"@deepseek-ai/dsh-agent": { "optional": false },
|
|
46
|
+
"@deepseek-ai/dsh-llm": { "optional": false }
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "tsc -p tsconfig.build.json",
|
|
50
|
+
"typecheck": "tsc --noEmit",
|
|
51
|
+
"test": "npm run build && node --test scripts/bridge.test.mjs",
|
|
52
|
+
"fixture-smoke": "node scripts/interactive-fixture-smoke.mjs"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@deepseek-ai/cordis": "4.0.2",
|
|
56
|
+
"@deepseek-ai/dsh-agent": "0.1.5-rc.2",
|
|
57
|
+
"@deepseek-ai/dsh-compaction-basic": "0.1.5-rc.2",
|
|
58
|
+
"@deepseek-ai/dsh-llm": "0.1.5-rc.2",
|
|
59
|
+
"@deepseek-ai/dsh-llm-replay": "0.1.5-rc.2",
|
|
60
|
+
"@deepseek-ai/dsh-session": "0.1.5-rc.2",
|
|
61
|
+
"@deepseek-ai/dsh-session-persistence": "0.1.5-rc.2",
|
|
62
|
+
"@deepseek-ai/dsh-session-persistence-jsonl": "0.1.5-rc.2",
|
|
63
|
+
"@deepseek-ai/dsh-user-questions": "0.1.5-rc.2",
|
|
64
|
+
"@types/node": "^22.0.0",
|
|
65
|
+
"typescript": "^5.6.0"
|
|
66
|
+
}
|
|
67
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "NodeNext",
|
|
5
|
+
"moduleResolution": "NodeNext",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
"noEmit": true,
|
|
10
|
+
"forceConsistentCasingInFileNames": true
|
|
11
|
+
},
|
|
12
|
+
"include": ["src/**/*.ts"]
|
|
13
|
+
}
|