@linxin666/dsh-liangshen 0.3.24 → 0.4.1
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.i18n.yaml +2 -2
- package/README.md +24 -17
- package/README.zh.md +25 -18
- package/cordis.patch.yml +3 -2
- package/icon.svg +3 -0
- package/lib/client.js +381 -77
- package/lib/client.js.map +1 -1
- package/lib/index.js +594 -428
- package/lib/types/announce.test.d.ts +10 -0
- package/lib/types/client/LiangShenSettingsCard.d.ts +27 -10
- package/lib/types/client/PluginSettingsCard.d.ts +4 -0
- package/lib/types/client/index.d.ts +32 -13
- package/lib/types/client/lever-controller.d.ts +16 -2
- package/lib/types/client/locales.d.ts +13 -0
- package/lib/types/client/main-session.d.ts +32 -0
- package/lib/types/client/plugin-card-seat.d.ts +23 -16
- package/lib/types/client/settings-form.d.ts +17 -17
- package/lib/types/composition.d.ts +116 -0
- package/lib/types/composition.test.d.ts +7 -0
- package/lib/types/index.d.ts +146 -31
- package/lib/types/index.test.d.ts +5 -0
- package/package.json +25 -20
- package/presets/liangshen/agent.cordis.yml +44 -10
- package/presets/liangshen/fact-ledger.mjs +141 -0
- package/presets/liangshen/guard.mjs +426 -0
- package/presets/liangshen/minimal-prompt.mjs +2 -2
- package/presets/liangshen/tool-catalog.mjs +24 -20
- package/presets/liangshen/working-context.mjs +10 -2
- package/src/announce.test.ts +248 -55
- package/src/client/LiangShenLever.module.css +2 -0
- package/src/client/LiangShenLever.tsx +37 -9
- package/src/client/LiangShenSettingsCard.tsx +96 -12
- package/src/client/PluginSettingsCard.tsx +7 -2
- package/src/client/index.ts +61 -23
- package/src/client/lever-controller.ts +76 -9
- package/src/client/locales.ts +30 -4
- package/src/client/main-session.ts +43 -0
- package/src/client/plugin-card-seat.ts +24 -17
- package/src/client/settings-form.ts +34 -31
- package/src/composition.test.ts +294 -0
- package/src/composition.ts +554 -0
- package/src/index.test.ts +68 -1
- package/src/index.ts +278 -107
- package/tools/benchmark-live-run.mjs +171 -32
- package/lib/types/schema.d.ts +0 -18
- package/lib/types/schema.test.d.ts +0 -1
- package/lib/types/sync.d.ts +0 -74
- package/lib/types/sync.test.d.ts +0 -1
- package/src/schema.test.ts +0 -64
- package/src/schema.ts +0 -110
- package/src/sync.test.ts +0 -303
- package/src/sync.ts +0 -324
package/lib/types/index.d.ts
CHANGED
|
@@ -1,21 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* dsh-liangshen — LiangShen (梁神) agent preset plugin.
|
|
3
3
|
*
|
|
4
|
-
* Host half only:
|
|
5
|
-
* harness
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
4
|
+
* Host half only: at activation it DECLARES the bundled LiangShen agent preset
|
|
5
|
+
* to the harness's agent-preset registry (`ctx.agentPresets`), reading the
|
|
6
|
+
* composition rows of `presets/liangshen/agent.cordis.yml` and handing the
|
|
7
|
+
* registry a definition whose relative module paths resolve inside the bundled
|
|
8
|
+
* preset directory. Declare = enabled: the registry mounts the preset's rows
|
|
9
|
+
* eagerly and hands back a disposer this plugin owns, so disabling the plugin
|
|
10
|
+
* (or the row unloading) unmounts them, and nothing is written to the harness
|
|
11
|
+
* home. The registration is released in `ctx.effect`; the plugin's own Config
|
|
12
|
+
* is the settings page the Host generates for this profile entry, and a
|
|
13
|
+
* settings write re-declares the preset with the new values instead of
|
|
14
|
+
* remounting the row. The capability announcement is a system-prompt section
|
|
15
|
+
* that ships OFF by default (`announceToAgent: false`) and can be enabled in
|
|
16
|
+
* the web settings surface (plugin config) or the profile patch. No browser
|
|
17
|
+
* routes, no agent tools — the preset itself provides the tools.
|
|
11
18
|
*
|
|
12
19
|
* The preset combines a minimal persona with a lifetime-declared tool
|
|
13
20
|
* presentation: the system prompt keeps a minimal persona with standing
|
|
14
21
|
* working discipline and workspace instructions, and the wire runs the SDK's
|
|
15
|
-
* '
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* ('native' and '
|
|
22
|
+
* 'both' presentation by default — the assembled native roster stays on the
|
|
23
|
+
* wire for ordinary work and the `run_code` transport sits co-resident for
|
|
24
|
+
* programmatic batch computation and wide fan-out, declared once per session
|
|
25
|
+
* instead of staged across a turn boundary ('native' and 'ptc' are one-line
|
|
26
|
+
* opt-outs). High-fan-out tool families
|
|
19
27
|
* (default `mcp__*`) stay paged out of the executed surface through the
|
|
20
28
|
* host's scoped tool restriction until the preset's own `tool_activate` tool
|
|
21
29
|
* loads their namespace (LRU cap three), with the activation state replayed
|
|
@@ -24,43 +32,150 @@
|
|
|
24
32
|
* one-line working-context projection travel as durable user messages,
|
|
25
33
|
* republished only on change.
|
|
26
34
|
*/
|
|
27
|
-
import type { Context } from '@deepseek-ai/cordis';
|
|
35
|
+
import type { Context, Volatile } from '@deepseek-ai/cordis';
|
|
28
36
|
import type { SettingsNamespace } from '@deepseek-ai/dsh-settings';
|
|
29
|
-
import z from 'schemastery';
|
|
37
|
+
import z from '@deepseek-ai/schemastery';
|
|
30
38
|
/** Stable cordis plugin name. */
|
|
31
39
|
export declare const name = "liangshen";
|
|
32
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
* Settings namespace of the plugin. Under the 0.1.7 settings contract a
|
|
42
|
+
* plugin's own Config IS its settings page and the namespace IS the profile
|
|
43
|
+
* entry id, so this is the row id the standalone bundle patch inserts; the
|
|
44
|
+
* aggregate install names the generated `web-ui-liangshen` row and the family
|
|
45
|
+
* binder resolves between the two.
|
|
46
|
+
*/
|
|
33
47
|
export declare const LIANGSHEN_SETTINGS_NAMESPACE: SettingsNamespace;
|
|
34
48
|
/** Prompt assembly must exist before the announcement section can register. */
|
|
35
49
|
export declare const inject: string[];
|
|
36
50
|
/** The wire presentations the preset's tool catalog accepts. */
|
|
37
51
|
export declare const PRESENTATION_OPTIONS: readonly ["ptc", "native", "both"];
|
|
38
|
-
/**
|
|
52
|
+
/** Sensitivity presets for the circuit breaker's adaptive thresholds. */
|
|
53
|
+
export declare const SENSITIVITY_OPTIONS: readonly ["conservative", "balanced", "aggressive"];
|
|
54
|
+
/** One wire presentation. */
|
|
55
|
+
export type Presentation = (typeof PRESENTATION_OPTIONS)[number];
|
|
56
|
+
/** One circuit-breaker sensitivity preset. */
|
|
57
|
+
export type GuardSensitivity = (typeof SENSITIVITY_OPTIONS)[number];
|
|
58
|
+
/**
|
|
59
|
+
* One activation field as the Host hands it over: a stable reference whose
|
|
60
|
+
* `get()` reads the value committed for this instance (a settings write updates
|
|
61
|
+
* it in place, without remounting the row), or the plain value a profile patch
|
|
62
|
+
* or a hand-built test context passes.
|
|
63
|
+
*/
|
|
64
|
+
export type ConfigField<T> = Volatile<T> | T | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* Plugin config, validated by the same-named schemastery schema.
|
|
67
|
+
*
|
|
68
|
+
* Every field is `volatile()`: the Host serves exactly the volatile fields of a
|
|
69
|
+
* Config as this entry's settings form and refuses writes anywhere else, and a
|
|
70
|
+
* volatile write is committed into the references this activation holds instead
|
|
71
|
+
* of remounting the row.
|
|
72
|
+
*/
|
|
39
73
|
export interface Config {
|
|
40
|
-
/** Master switch: when false, neither
|
|
41
|
-
enabled?: boolean
|
|
74
|
+
/** Master switch: when false, neither the preset declaration nor the announcement runs. */
|
|
75
|
+
enabled?: ConfigField<boolean>;
|
|
42
76
|
/** When true, a system-prompt section announces the plugin (default false — keep prompts clean unless the user opts in). */
|
|
43
|
-
announceToAgent?: boolean
|
|
77
|
+
announceToAgent?: ConfigField<boolean>;
|
|
44
78
|
/**
|
|
45
|
-
* Wire presentation written into the
|
|
46
|
-
* `
|
|
47
|
-
* keeps the
|
|
79
|
+
* Wire presentation written into the declared preset's tool-catalog row.
|
|
80
|
+
* `both` (default) keeps the assembled roster and the `run_code` transport
|
|
81
|
+
* co-resident; `native` keeps only the roster; `ptc` collapses the wire to
|
|
82
|
+
* the transport.
|
|
48
83
|
*/
|
|
49
|
-
presentation?:
|
|
84
|
+
presentation?: ConfigField<Presentation>;
|
|
85
|
+
/** Master switch for the runtime degeneration circuit breaker (default true). */
|
|
86
|
+
guardEnabled?: ConfigField<boolean>;
|
|
87
|
+
/**
|
|
88
|
+
* Sensitivity preset scaling the breaker's adaptive thresholds
|
|
89
|
+
* (default 'balanced'). 'conservative' interrupts less, 'aggressive' fires earlier.
|
|
90
|
+
*/
|
|
91
|
+
guardSensitivity?: ConfigField<GuardSensitivity>;
|
|
92
|
+
/**
|
|
93
|
+
* Reasoning characters one zero-output step must reach for the per-step
|
|
94
|
+
* ladder to fire (default 8000, calibrated against V4.1's 384K max output).
|
|
95
|
+
*/
|
|
96
|
+
guardStallReasoningChars?: ConfigField<number>;
|
|
97
|
+
/**
|
|
98
|
+
* Consecutive output-free reasoning steps that trip the slow-burn ladder
|
|
99
|
+
* (default 4).
|
|
100
|
+
*/
|
|
101
|
+
guardGlobalStallCap?: ConfigField<number>;
|
|
102
|
+
/** Identical-argument tool failures in a row that trip the echo ladder (default 3). */
|
|
103
|
+
guardEchoFailures?: ConfigField<number>;
|
|
50
104
|
}
|
|
51
|
-
export declare const Config: z<
|
|
105
|
+
export declare const Config: z<Schemastery.ObjectS<NoInfer<{
|
|
106
|
+
enabled: z<boolean, boolean, "volatile-defined">;
|
|
107
|
+
announceToAgent: z<boolean, boolean, "volatile-defined">;
|
|
108
|
+
presentation: z<"ptc" | "native" | "both", "ptc" | "native" | "both", "volatile-defined">;
|
|
109
|
+
guardEnabled: z<boolean, boolean, "volatile-defined">;
|
|
110
|
+
guardSensitivity: z<"conservative" | "balanced" | "aggressive", "conservative" | "balanced" | "aggressive", "volatile-defined">;
|
|
111
|
+
guardStallReasoningChars: z<number, number, "volatile-defined">;
|
|
112
|
+
guardGlobalStallCap: z<number, number, "volatile-defined">;
|
|
113
|
+
guardEchoFailures: z<number, number, "volatile-defined">;
|
|
114
|
+
}>>, Schemastery.ObjectT<NoInfer<{
|
|
115
|
+
enabled: z<boolean, boolean, "volatile-defined">;
|
|
116
|
+
announceToAgent: z<boolean, boolean, "volatile-defined">;
|
|
117
|
+
presentation: z<"ptc" | "native" | "both", "ptc" | "native" | "both", "volatile-defined">;
|
|
118
|
+
guardEnabled: z<boolean, boolean, "volatile-defined">;
|
|
119
|
+
guardSensitivity: z<"conservative" | "balanced" | "aggressive", "conservative" | "balanced" | "aggressive", "volatile-defined">;
|
|
120
|
+
guardStallReasoningChars: z<number, number, "volatile-defined">;
|
|
121
|
+
guardGlobalStallCap: z<number, number, "volatile-defined">;
|
|
122
|
+
guardEchoFailures: z<number, number, "volatile-defined">;
|
|
123
|
+
}>>, "plain">;
|
|
124
|
+
/** The settings the runtime acts on, every field read at its use site. */
|
|
125
|
+
export interface ResolvedConfig {
|
|
126
|
+
/** Whether the preset is declared at all. */
|
|
127
|
+
enabled: boolean;
|
|
128
|
+
/** Whether the announcement section registers. */
|
|
129
|
+
announceToAgent: boolean;
|
|
130
|
+
/** Wire presentation the declared preset's tool-catalog row carries. */
|
|
131
|
+
presentation: Presentation;
|
|
132
|
+
/** Breaker master switch written into the declared preset's guard row. */
|
|
133
|
+
guardEnabled: boolean;
|
|
134
|
+
/** Breaker sensitivity written into the declared preset's guard row. */
|
|
135
|
+
guardSensitivity: GuardSensitivity;
|
|
136
|
+
/** Per-step reasoning-character floor written into the guard row. */
|
|
137
|
+
guardStallReasoningChars: number;
|
|
138
|
+
/** Slow-burn step cap written into the guard row. */
|
|
139
|
+
guardGlobalStallCap: number;
|
|
140
|
+
/** Echo-ladder failure count written into the guard row. */
|
|
141
|
+
guardEchoFailures: number;
|
|
142
|
+
}
|
|
143
|
+
/** Schema defaults, re-read for hand-built test contexts. */
|
|
144
|
+
export declare const DEFAULT_CONFIG: ResolvedConfig;
|
|
145
|
+
/**
|
|
146
|
+
* Read the effective settings of this activation.
|
|
147
|
+
* @param config - the config the Host passed to the activation.
|
|
148
|
+
* @returns every field resolved against the schema defaults.
|
|
149
|
+
*/
|
|
150
|
+
export declare function resolveConfig(config?: Config): ResolvedConfig;
|
|
52
151
|
/** Model-facing announcement: plugin presence, principle, and limits. */
|
|
53
|
-
export declare const LIANGSHEN_GUIDANCE = "\u672C\u673A\u5DF2\u5B89\u88C5 dsh-liangshen \u63D2\u4EF6\uFF08\u6881\u795E\u6A21\u5F0F agent preset\uFF09\uFF1A\u65B0\u5EFA\u4F1A\u8BDD\u7684\u9884\u8BBE\u9009\u62E9\u5668\u4E2D\u53EF\u9009\u300C\u6881\u795E\u6A21\u5F0F\u300D\u3002\u539F\u7406\uFF1A\u7CFB\u7EDF\u63D0\u793A\u8BCD\u4FDD\u6301\u6781\u7B80 persona\uFF08minimal-prompt \u653E\u884C\u8BE5\u6BB5\u4E0E plan \u6A21\u5F0F\u7684 plan:policy\uFF09\uFF0Cpersona \u5185\u7F6E\u672C\u6A21\u5F0F\u5DE5\u4F5C\u7EAA\u5F8B\uFF08\u53CD\u601D\u7194\u65AD\u2014\u2014\u540C\u4E00\u5047\u8BBE\u63A8\u6F14\u4E0D\u8D85\u8FC7\u4E24\u8F6E\u3001\u7F3A\u4E8B\u5B9E\u7ACB\u5373\u95ED\u5408\u601D\u8003\u5E76\u8C03\u7528\u539F\u751F\u68C0\u6D4B\u5DE5\u5177\uFF1B\u884C\u52A8\u5BFC\u5411\u2014\u2014\u601D\u8003\u53EA\u51B3\u5B9A\u4E0B\u4E00\u6B65\u5177\u4F53\u64CD\u4F5C\u3001\u4E0D\u5728\u601D\u8003\u4E2D\u9884\u6F14\u4EE3\u7801\u5B9E\u73B0\uFF1B\u5E76\u53D1\u63A2\u7D22\u2014\u2014\u591A\u5904\u72EC\u7ACB\u68C0\u67E5\u6216\u641C\u7D22\u5728\u5355\u8F6E\u5185\u5E76\u53D1\u53D1\u5C04\u591A\u4E2A\u5DE5\u5177\u8C03\u7528\uFF1BYAGNI/PDCA\u2014\u2014\u5355\u6B65\u9A8C\u8BC1\u5355\u4E00\u5047\u8BBE\u3001\u4E0D\u5199\u5197\u4F59\u6CE8\u91CA\uFF09\uFF0C\u5E76\u5728\u7EC4\u88C5\u65F6\u8FFD\u52A0\u5DE5\u4F5C\u533A\u76EE\u5F55\u884C Your working directory is <cwd>.\u3002AGENTS.md \u5DE5\u4F5C\u533A\u6307\u4EE4\u9ED8\u8BA4\u4EA4\u8FD8\u5BBF\u4E3B\u81EA\u8EAB\u7684 agent-instructions \u884C\uFF0C\u4EE5 user \u89D2\u8272\u6CE8\u5165\uFF0C\u672C\u63D2\u4EF6\u4E0D\u8FFD\u52A0\u4EFB\u4F55\u7CFB\u7EDF\u63D0\u793A\u8BCD\u6BB5\u3001\u4E5F\u4E0D\u6539\u52A8 pre-step \u7684\u6D88\u606F\u6279\u6B21\uFF1B\u53EF\u9009 instructionSource: system-prompt \u624D\u7531\u672C\u63D2\u4EF6\u5728\u7EC4\u88C5\u65F6\u8BFB\u53D6 AGENTS.md \u94FE\u5E76\u8FFD\u52A0 workspace-instructions \u6BB5\uFF0865536 \u5B57\u8282\u9884\u7B97\uFF0C\u6BCF\u6B21\u7EC4\u88C5\u91CD\u8BFB\uFF09\u3002wire \u5448\u73B0\u7531 tool-catalog \u6309\u4F1A\u8BDD\u4E00\u6B21\u58F0\u660E\uFF0C\u53D6\u503C '
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
152
|
+
export declare const LIANGSHEN_GUIDANCE = "\u672C\u673A\u5DF2\u5B89\u88C5 dsh-liangshen \u63D2\u4EF6\uFF08\u6881\u795E\u6A21\u5F0F agent preset\uFF09\uFF1A\u65B0\u5EFA\u4F1A\u8BDD\u7684\u9884\u8BBE\u9009\u62E9\u5668\u4E2D\u53EF\u9009\u300C\u6881\u795E\u6A21\u5F0F\u300D\u3002\u539F\u7406\uFF1A\u7CFB\u7EDF\u63D0\u793A\u8BCD\u4FDD\u6301\u6781\u7B80 persona\uFF08minimal-prompt \u653E\u884C\u8BE5\u6BB5\u4E0E plan \u6A21\u5F0F\u7684 plan:policy\uFF09\uFF0Cpersona \u5185\u7F6E\u672C\u6A21\u5F0F\u5DE5\u4F5C\u7EAA\u5F8B\uFF08\u53CD\u601D\u7194\u65AD\u2014\u2014\u540C\u4E00\u5047\u8BBE\u63A8\u6F14\u4E0D\u8D85\u8FC7\u4E24\u8F6E\u3001\u7F3A\u4E8B\u5B9E\u7ACB\u5373\u95ED\u5408\u601D\u8003\u5E76\u8C03\u7528\u539F\u751F\u68C0\u6D4B\u5DE5\u5177\uFF1B\u884C\u52A8\u5BFC\u5411\u2014\u2014\u601D\u8003\u53EA\u51B3\u5B9A\u4E0B\u4E00\u6B65\u5177\u4F53\u64CD\u4F5C\u3001\u4E0D\u5728\u601D\u8003\u4E2D\u9884\u6F14\u4EE3\u7801\u5B9E\u73B0\uFF1B\u5E76\u53D1\u63A2\u7D22\u2014\u2014\u591A\u5904\u72EC\u7ACB\u68C0\u67E5\u6216\u641C\u7D22\u5728\u5355\u8F6E\u5185\u5E76\u53D1\u53D1\u5C04\u591A\u4E2A\u5DE5\u5177\u8C03\u7528\uFF1BYAGNI/PDCA\u2014\u2014\u5355\u6B65\u9A8C\u8BC1\u5355\u4E00\u5047\u8BBE\u3001\u4E0D\u5199\u5197\u4F59\u6CE8\u91CA\uFF1B\u6709\u754C\u6536\u655B\u2014\u2014\u4E0D\u65E0\u9650\u4E0B\u94BB\u4F9D\u8D56\u94FE\u3001\u524D\u7F6E\u68C0\u67E5\u6700\u591A2-3\u8F6E\u540E\u7ACB\u5373\u6536\u655B\u5E76\u4F5C\u7B54\u6216\u7F16\u8F91\uFF09\uFF0C\u5E76\u5728\u7EC4\u88C5\u65F6\u8FFD\u52A0\u5DE5\u4F5C\u533A\u76EE\u5F55\u884C Your working directory is <cwd>.\u3002AGENTS.md \u5DE5\u4F5C\u533A\u6307\u4EE4\u9ED8\u8BA4\u4EA4\u8FD8\u5BBF\u4E3B\u81EA\u8EAB\u7684 agent-instructions \u884C\uFF0C\u4EE5 user \u89D2\u8272\u6CE8\u5165\uFF0C\u672C\u63D2\u4EF6\u4E0D\u8FFD\u52A0\u4EFB\u4F55\u7CFB\u7EDF\u63D0\u793A\u8BCD\u6BB5\u3001\u4E5F\u4E0D\u6539\u52A8 pre-step \u7684\u6D88\u606F\u6279\u6B21\uFF1B\u53EF\u9009 instructionSource: system-prompt \u624D\u7531\u672C\u63D2\u4EF6\u5728\u7EC4\u88C5\u65F6\u8BFB\u53D6 AGENTS.md \u94FE\u5E76\u8FFD\u52A0 workspace-instructions \u6BB5\uFF0865536 \u5B57\u8282\u9884\u7B97\uFF0C\u6BCF\u6B21\u7EC4\u88C5\u91CD\u8BFB\uFF09\u3002wire \u5448\u73B0\u7531 tool-catalog \u6309\u4F1A\u8BDD\u4E00\u6B21\u58F0\u660E\uFF0C\u53D6\u503C 'both'\uFF08\u9ED8\u8BA4\uFF1A\u539F\u751F\u6E05\u5355\u4E0E run_code \u540C\u9A7B\uFF0C\u539F\u751F\u76F4\u8C03\u4F18\u5148\u3001run_code \u7528\u4E8E\u7A0B\u5E8F\u5316\u6279\u5904\u7406\u4E0E\u5E76\u53D1\u6247\u51FA\uFF09\u3001'native'\uFF08\u7EC4\u88C5\u51FA\u7684\u539F\u751F\u6E05\u5355\uFF09\u6216 'ptc'\uFF08wire \u6536\u62E2\u4E3A\u552F\u4E00\u7684 run_code\uFF09\uFF0C\u5E76\u53EF\u5728\u63D2\u4EF6\u8BBE\u7F6E\u754C\u9762\u5207\u6362\uFF08\u5199\u5165\u6240\u58F0\u660E\u9884\u8BBE\u7684 tool-catalog \u884C\uFF09\uFF1B\u672A\u6302\u8F7D code runtime \u65F6\u4E0D\u505A\u58F0\u660E\uFF0C\u4F1A\u8BDD\u8FD0\u884C\u539F\u751F\u5DE5\u5177\u9762\u3002\u6E29\u548C\u5DE5\u5177\u5206\u9875\u51FA\u5382\u5F00\u542F\uFF08pagedToolPatterns \u9ED8\u8BA4 ['mcp__*']\uFF09\uFF1A\u5339\u914D\u5DE5\u5177\u5728\u6FC0\u6D3B\u524D\u88AB\u4F5C\u7528\u57DF\u7EA7\u5DE5\u5177\u9650\u5236\u79FB\u51FA\u53EF\u89C1\u9762\uFF08\u65E2\u4E0D\u5728 wire\uFF0C\u4E5F\u4E0D\u5728\u751F\u6210\u7684 SDK \u58F0\u660E\u4E2D\uFF09\uFF0C\u76EE\u5F55\u6D88\u606F\u5217\u51FA\u5E38\u9A7B\u5DE5\u5177\u7B7E\u540D\u4E0E\u672A\u6FC0\u6D3B\u547D\u540D\u7A7A\u95F4\u6458\u8981\uFF0C\u8C03\u7528 tool_activate({ namespace }) \u6309\u9700\u6FC0\u6D3B\uFF08LRU \u4E0A\u9650 3 \u4E2A\u6D3B\u8DC3\u547D\u540D\u7A7A\u95F4\uFF0C\u9A71\u9010\u6700\u4E45\u672A\u7528\uFF09\uFF1B\u6FC0\u6D3B\u72B6\u6001\u4ECE\u6301\u4E45\u4F1A\u8BDD\u4E8B\u4EF6\u6D41\u91CD\u5EFA\uFF0Cresume/\u538B\u7F29\u540E\u81EA\u7136\u6062\u590D\u3002\u8FD0\u884C\u65F6\u9000\u5316\u7194\u65AD\u5668\uFF08guard\uFF09\u4ECE\u4E8B\u4EF6\u6D41\u6298\u53E0\u505C\u6446\uFF08\u8FDE\u7EED\u96F6\u4EA7\u51FA\u957F\u601D\u8003\uFF09\u4E0E\u7A7A\u8F6C\uFF08\u540C\u53C2\u91CD\u590D\u5931\u8D25\uFF09\u4FE1\u53F7\uFF0C\u6BCF episode \u89E6\u53D1\u4E00\u6B21\uFF1A\u6CE8\u5165\u7194\u65AD\u6D88\u606F\u5E76\u628A\u63A8\u7406\u6863\u4F4D\u4E34\u65F6\u4E0B\u8C03\u4E00\u6863\uFF08max\u2192high\u2192low\uFF0C\u7A97\u53E3 3 \u4E2A\u8BF7\u6C42\uFF09\uFF1B\u65E0\u4FE1\u53F7\u65F6\u4ECE\u4E0D\u6539\u5199\u8BF7\u6C42\u3002\u5173\u952E\u4E8B\u5B9E\u767B\u8BB0\u7C3F\uFF08fact_register\uFF09\u8BA9\u6A21\u578B\u628A\u786C\u7EA6\u675F/\u5DF2\u786E\u8BA4\u51B3\u7B56/\u5931\u8D25\u8DEF\u5F84\u767B\u8BB0\u4E3A\u5355\u884C\u4E8B\u5B9E\uFF0C\u968F working-context \u884C\u6BCF\u6B65\u6295\u5C04\u8FDB\u5C40\u90E8\u6CE8\u610F\u529B\u7A97\u53E3\u3002working-context \u63D2\u4EF6\u5728 pre-step \u6CE8\u5165\u5355\u884C [Working Context: ...] \u5C31\u8FD1\u72B6\u6001\u6295\u5C04\uFF08plan \u6A21\u5F0F\u3001\u6D3B\u8DC3\u547D\u540D\u7A7A\u95F4\u3001\u8FDB\u884C\u4E2D todo\u3001\u767B\u8BB0\u4E8B\u5B9E\uFF0C\u5168\u90E8\u4ECE\u4E8B\u4EF6\u6D41\u6298\u53E0\uFF0C\u8BFB\u4E0D\u5230\u5219\u7701\u7565\uFF0C\u5168\u90E8\u4E3A\u7A7A\u5219\u4E0D\u6CE8\u5165\uFF09\u3002\u5386\u53F2\u5DE5\u5177\u7ED3\u679C\u4FEE\u526A\u4E3A 4096 \u5B57\u7B26\u9608\u503C\uFF08head 2048 / tail 1024\uFF09\u3002\u6587\u4EF6\u64CD\u4F5C\u53D7\u5BBF\u4E3B\u6C99\u7BB1\u7EA6\u675F\uFF1Bshell \u5728\u6BCF\u4E2A\u5E73\u53F0\u90FD\u6302\u4E0A\u6E38\u6807\u51C6 Stdio \u6808\uFF08POSIX \u4E3A bash\uFF0CWindows \u4E3A pwsh\uFF09\uFF0C\u5E26\u7B80\u77ED\u63CF\u8FF0\u6807\u9898\u5361\u7247\u4E0E\u786E\u5B9A\u6027\u9000\u51FA\u7801\u3002\u771F\u5B9E\u63A8\u7406\u63A2\u9488\u901A\u8FC7\u4E0D\u7B49\u4E8E\u6A21\u5F0F\u96C6\u6210\u901A\u8FC7\uFF0C\u66F4\u4E0D\u7B49\u4E8E\u7EDF\u8BA1\u6548\u679C\u63D0\u5347\u3002\u9884\u8BBE\u7531\u63D2\u4EF6\u5728\u6FC0\u6D3B\u65F6\u5411 agent-preset registry \u76F4\u63A5\u6CE8\u518C\uFF08\u4E0D\u5199\u4EFB\u4F55\u9884\u8BBE\u76EE\u5F55\uFF09\uFF0C\u63D2\u4EF6\u505C\u7528\u5373\u6CE8\u9500\uFF1B\u9ED8\u8BA4\u9884\u8BBE\u7531\u7528\u6237\u81EA\u884C\u9009\u62E9\u3002\u7528\u6237\u63D0\u5230\u300C\u6881\u795E\u6A21\u5F0F / \u951A\u5B9A\u6A21\u5F0F / anchored standard\u300D\u65F6\u5373\u6307\u672C\u63D2\u4EF6\uFF0C\u8BF7\u636E\u6B64\u534F\u4F5C\u3002";
|
|
153
|
+
/**
|
|
154
|
+
* Absolute path of the bundled LiangShen preset directory: the composition,
|
|
155
|
+
* the display map, and the preset-local `.mjs` plugins this plugin declares.
|
|
156
|
+
* @returns the preset directory as a filesystem path.
|
|
157
|
+
*/
|
|
158
|
+
export declare function bundledPresetDir(): string;
|
|
57
159
|
/**
|
|
58
|
-
* Mount the plugin:
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* (off by default).
|
|
160
|
+
* Mount the plugin: declare the bundled preset, register the announcement
|
|
161
|
+
* section when announceToAgent is on (off by default), and re-declare on every
|
|
162
|
+
* committed settings write.
|
|
62
163
|
* @param ctx - host plugin context carrying systemPrompt.
|
|
63
164
|
* @param config - resolved plugin config (schema defaults applied by the loader).
|
|
64
165
|
*/
|
|
65
166
|
export declare const apply: typeof applyImpl;
|
|
66
167
|
declare function applyImpl(ctx: Context, config?: Config): void;
|
|
168
|
+
declare module '@deepseek-ai/cordis' {
|
|
169
|
+
interface Events {
|
|
170
|
+
/**
|
|
171
|
+
* Volatile config values were committed into the running fiber without a
|
|
172
|
+
* remount; dispatched to the owning fiber only. Spelled here because the
|
|
173
|
+
* Loader package is not a dependency of this plugin, with the Loader's own
|
|
174
|
+
* shape so the two declarations merge when a Host program carries both.
|
|
175
|
+
* @param paths - changed config paths as key arrays; every value is committed before dispatch.
|
|
176
|
+
* @mode emit
|
|
177
|
+
*/
|
|
178
|
+
'loader/volatile-update'(paths: readonly (readonly string[])[]): void;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@linxin666/dsh-liangshen",
|
|
3
|
-
"description": "LiangShen (梁神) agent preset plus its composer lever for the dsh web GUI. The preset keeps a minimal persona with standing working discipline while the harness's own user-role agent-instructions injection delivers the workspace instructions (the optional `instructionSource: system-prompt` mode lifts them into the prompt instead), and declares one tool presentation for the session's whole lifetime (default `presentation: '
|
|
4
|
-
"version": "0.
|
|
3
|
+
"description": "LiangShen (梁神) agent preset plus its composer lever for the dsh web GUI. The host half declares the bundled preset to the harness's agent-preset registry at activation (declare = enabled), so the preset is selectable for new sessions without writing anything into the harness home; the preset keeps a minimal persona with standing working discipline while the harness's own user-role agent-instructions injection delivers the workspace instructions (the optional `instructionSource: system-prompt` mode lifts them into the prompt instead), and declares one tool presentation for the session's whole lifetime (default `presentation: 'both'`, where the wire collapses to the `run_code` transport and every other tool is reached through the generated SDK; `native` keeps the assembled roster, `ptc` keeps only the transport). High-fan-out tool families (default `mcp__*`) stay paged out of the wire until the preset's own `tool_activate` tool loads their namespace (LRU cap three, state replayed from the durable session event stream), and the tool catalog — exactly the on-wire tools plus paged-out namespace summaries — and a one-line working-context projection travel as durable user messages republished only on change. The browser half adds a slot-machine lever left of the model selector on the new-session screen to toggle the mode. Hot-pluggable via cordis.patch.yml + profile symlink, no dsh source changes.",
|
|
4
|
+
"version": "0.4.1",
|
|
5
|
+
"icon": "icon.svg",
|
|
5
6
|
"type": "module",
|
|
6
7
|
"engines": {
|
|
7
8
|
"node": "^22.19.0 || >=24.0.0"
|
|
@@ -22,7 +23,7 @@
|
|
|
22
23
|
},
|
|
23
24
|
"dsh": {
|
|
24
25
|
"engines": {
|
|
25
|
-
"dsh": ">=0.1.
|
|
26
|
+
"dsh": ">=0.1.7-rc.1"
|
|
26
27
|
},
|
|
27
28
|
"bundle": {
|
|
28
29
|
"patch": "./cordis.patch.yml"
|
|
@@ -38,34 +39,37 @@
|
|
|
38
39
|
"platform": "web"
|
|
39
40
|
}
|
|
40
41
|
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"@deepseek-ai/dsh": ">=0.1.7-rc.1"
|
|
44
|
+
},
|
|
41
45
|
"dependencies": {
|
|
42
|
-
"schemastery": "^3.18.
|
|
46
|
+
"@deepseek-ai/schemastery": "^3.18.4"
|
|
43
47
|
},
|
|
44
48
|
"devDependencies": {
|
|
45
|
-
"@deepseek-ai/cordis": "^4.0.
|
|
46
|
-
"@deepseek-ai/dsh-agent-
|
|
47
|
-
"@deepseek-ai/dsh-api-remotes": "^0.1.
|
|
48
|
-
"@deepseek-ai/dsh-api-session-controller": "^0.1.
|
|
49
|
-
"@deepseek-ai/dsh-client-connection": "^0.1.
|
|
50
|
-
"@deepseek-ai/dsh-client-locale": "^0.1.
|
|
51
|
-
"@deepseek-ai/dsh-client-store": "^0.1.
|
|
52
|
-
"@deepseek-ai/dsh-client-ui-conversation": "^0.1.
|
|
53
|
-
"@deepseek-ai/dsh-client-ui-renderer": "^0.1.
|
|
54
|
-
"@deepseek-ai/dsh-client-ui-settings": "^0.1.
|
|
55
|
-
"@deepseek-ai/dsh-client-ui-slots": "^0.1.
|
|
56
|
-
"@deepseek-ai/dsh-settings": "^0.1.
|
|
57
|
-
"@deepseek-ai/dsh-system-prompt": "^0.1.
|
|
49
|
+
"@deepseek-ai/cordis": "^4.0.4",
|
|
50
|
+
"@deepseek-ai/dsh-agent-preset-registry": "^0.1.7-rc.1",
|
|
51
|
+
"@deepseek-ai/dsh-api-remotes": "^0.1.7-rc.1",
|
|
52
|
+
"@deepseek-ai/dsh-api-session-controller": "^0.1.7-rc.1",
|
|
53
|
+
"@deepseek-ai/dsh-client-connection": "^0.1.7-rc.1",
|
|
54
|
+
"@deepseek-ai/dsh-client-locale": "^0.1.7-rc.1",
|
|
55
|
+
"@deepseek-ai/dsh-client-store": "^0.1.7-rc.1",
|
|
56
|
+
"@deepseek-ai/dsh-client-ui-conversation": "^0.1.7-rc.1",
|
|
57
|
+
"@deepseek-ai/dsh-client-ui-renderer": "^0.1.7-rc.1",
|
|
58
|
+
"@deepseek-ai/dsh-client-ui-settings": "^0.1.7-rc.1",
|
|
59
|
+
"@deepseek-ai/dsh-client-ui-slots": "^0.1.7-rc.1",
|
|
60
|
+
"@deepseek-ai/dsh-settings": "^0.1.7-rc.1",
|
|
61
|
+
"@deepseek-ai/dsh-system-prompt": "^0.1.7-rc.1",
|
|
58
62
|
"@testing-library/react": "^16.1.0",
|
|
59
63
|
"@types/node": "^22.20.0",
|
|
60
64
|
"@types/react": "~18.3.1",
|
|
61
65
|
"@types/react-dom": "~18.3.1",
|
|
62
|
-
"@vitest/coverage-v8": "^
|
|
66
|
+
"@vitest/coverage-v8": "^4.1.11",
|
|
63
67
|
"jsdom": "^25.0.0",
|
|
64
68
|
"react": "^18.3.1",
|
|
65
69
|
"react-dom": "^18.3.1",
|
|
66
70
|
"tsdown": "0.22.2",
|
|
67
71
|
"typescript": "~5.7.2",
|
|
68
|
-
"vitest": "^
|
|
72
|
+
"vitest": "^4.1.11"
|
|
69
73
|
},
|
|
70
74
|
"files": [
|
|
71
75
|
"lib/**/*.js",
|
|
@@ -78,7 +82,8 @@
|
|
|
78
82
|
"cordis.patch.yml",
|
|
79
83
|
"README.md",
|
|
80
84
|
"README.zh.md",
|
|
81
|
-
"LICENSE"
|
|
85
|
+
"LICENSE",
|
|
86
|
+
"icon.svg"
|
|
82
87
|
],
|
|
83
88
|
"license": "Apache-2.0",
|
|
84
89
|
"repository": {
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
# turn boundary.
|
|
7
7
|
#
|
|
8
8
|
# The presentation is the SDK's ToolPresentationMode, picked by the
|
|
9
|
-
# tool-catalog row's `presentation` key (default `'
|
|
9
|
+
# tool-catalog row's `presentation` key (default `'ptc'`): `'native'` keeps
|
|
10
10
|
# the assembled roster on the wire, `'ptc'` collapses the wire to the single
|
|
11
11
|
# `run_code` transport, and `'both'` keeps the full native roster AND the
|
|
12
12
|
# `run_code` transport co-resident — native calls carry ordinary work while
|
|
@@ -86,11 +86,12 @@
|
|
|
86
86
|
prefix: |-
|
|
87
87
|
You are a helpful software engineer assistant.
|
|
88
88
|
|
|
89
|
-
- Thinking Disruption:
|
|
90
|
-
- Action-Oriented:
|
|
91
|
-
- Parallel Inspection: When
|
|
89
|
+
- Thinking Disruption: Never reason through the same hypothesis more than twice. When a fact is missing, stop thinking and call a native inspection tool (read, grep, bash/pwsh) to settle it — no speculation without new evidence.
|
|
90
|
+
- Action-Oriented: Use thinking only to pick the next concrete operation. Do not pre-rehearse implementations in thought; verify every claim against real tool output during execution.
|
|
91
|
+
- Parallel Inspection: When several independent inspections, searches, or checks are needed, emit all of their tool calls in a single turn rather than across sequential rounds. The harness executes independent read-only calls in parallel.
|
|
92
92
|
- Shell Discipline: Shell processes are ephemeral; directory changes do not persist across tool calls. Use compound commands (e.g. cd <path> && <cmd>) or pass workdir explicitly for operations in subdirectories.
|
|
93
93
|
- Development Standard: Follow YAGNI and the PDCA loop. Each step verifies a single assumption. Do not write redundant comments.
|
|
94
|
+
- Bounded Inspection & Convergence: Do not traverse dependency chains unbounded. Limit pre-action inspection to immediate target files (at most 2-3 inspection turns). Once core context is understood, immediately converge and begin answering or making edits. Verify edge cases during post-edit testing rather than over-reading upfront.
|
|
94
95
|
- Bounded Output: never dump a large or unbounded command output into the conversation. Filter at the source with grep/head/tail/wc and read the narrow range you actually need; the model's long-range attention is a bounded budget and raw logs evict the session's own constraints from it.
|
|
95
96
|
|
|
96
97
|
# The mode's preset-local plugins:
|
|
@@ -165,12 +166,45 @@
|
|
|
165
166
|
config:
|
|
166
167
|
descriptionMaxLength: 200
|
|
167
168
|
presentation: 'both'
|
|
168
|
-
pagedToolPatterns: []
|
|
169
|
-
maxResidentTokens:
|
|
169
|
+
pagedToolPatterns: ['mcp__*']
|
|
170
|
+
maxResidentTokens: 8000
|
|
170
171
|
|
|
171
172
|
- id: working-context
|
|
172
173
|
name: ./working-context.mjs
|
|
173
174
|
|
|
175
|
+
# The runtime degeneration circuit breaker: folds a stall (consecutive zero-
|
|
176
|
+
# output long-reasoning steps) or echo (identical-argument tool failures)
|
|
177
|
+
# signal from the durable session event stream and fires once per episode —
|
|
178
|
+
# injecting a breaker message at pre-step and stepping the reasoning effort
|
|
179
|
+
# one notch down for the next few requests. With no signal it never rewrites
|
|
180
|
+
# a request, so the route's explicit effort and the prefix cache stay
|
|
181
|
+
# untouched. This is the outside force the persona's reflection fuse cannot
|
|
182
|
+
# be: see DSH discussion #5976 and the Agent Note that constrains dynamic
|
|
183
|
+
# reasoning effort to this triggered-only form.
|
|
184
|
+
- id: guard
|
|
185
|
+
name: ./guard.mjs
|
|
186
|
+
config:
|
|
187
|
+
enabled: true
|
|
188
|
+
sensitivity: 'balanced'
|
|
189
|
+
stallReasoningChars: 8000
|
|
190
|
+
globalStallCap: 4
|
|
191
|
+
echoFailures: 3
|
|
192
|
+
|
|
193
|
+
# The paging activation handle the catalog points at: with `pagedToolPatterns`
|
|
194
|
+
# non-empty this row is what lets `tool_activate({ namespace })` bring one
|
|
195
|
+
# paged namespace back onto the wire (and the generated SDK) for the session.
|
|
196
|
+
- id: tool-activate
|
|
197
|
+
name: ./tool-activate.mjs
|
|
198
|
+
|
|
199
|
+
# The key-fact register: the model pins a hard constraint / confirmed decision /
|
|
200
|
+
# failed path with `fact_register`, the fold rebuilds the register from the
|
|
201
|
+
# durable event stream, and working-context renders it as one field of the
|
|
202
|
+
# [Working Context: ...] line — the surface that lands inside the guaranteed
|
|
203
|
+
# local attention window every step. The counter to V4.1's long-session
|
|
204
|
+
# forgetting; the fold replays identically after resume and compaction.
|
|
205
|
+
- id: fact-ledger
|
|
206
|
+
name: ./fact-ledger.mjs
|
|
207
|
+
|
|
174
208
|
# The harness's workspace-instruction loader. Under the default
|
|
175
209
|
# `instructionSource: host` this row owns the channel: its baseline and dynamic
|
|
176
210
|
# user-role messages reach the model untouched. Under
|
|
@@ -310,8 +344,8 @@
|
|
|
310
344
|
- id: tool-result-pruner
|
|
311
345
|
name: '@deepseek-ai/dsh-compaction-tool-result-pruner'
|
|
312
346
|
config:
|
|
313
|
-
thresholdChars:
|
|
314
|
-
headChars:
|
|
347
|
+
thresholdChars: 4096
|
|
348
|
+
headChars: 2048
|
|
315
349
|
tailChars: 1024
|
|
316
350
|
|
|
317
351
|
# ── delegation and workflows ────────────────────────────────────────────────
|
|
@@ -378,8 +412,8 @@
|
|
|
378
412
|
enableRunInBackground: false
|
|
379
413
|
maxDepth: provider-managed
|
|
380
414
|
|
|
381
|
-
- id: workflow-
|
|
382
|
-
name: '@deepseek-ai/dsh-workflow-
|
|
415
|
+
- id: workflow-ptc
|
|
416
|
+
name: '@deepseek-ai/dsh-workflow-ptc'
|
|
383
417
|
config:
|
|
384
418
|
provider: spawn
|
|
385
419
|
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* fact-ledger — the LiangShen preset's key-fact register: a lightweight tool
|
|
3
|
+
* the model uses to pin the facts that must survive a long session, and a
|
|
4
|
+
* fold that re-derives the current register from the durable event stream.
|
|
5
|
+
*
|
|
6
|
+
* Why this exists: community feedback on DeepSeek-V4.1 (r/DeepSeek 1wlssvo,
|
|
7
|
+
* and the architecture's own numbers) is that long conversations forget —
|
|
8
|
+
* CSA2's sparse index only guarantees a query the most recent local window,
|
|
9
|
+
* and a hard constraint the user stated eighty turns ago competes for Top-K
|
|
10
|
+
* slots with every tool schema and log line since. The working-context
|
|
11
|
+
* projection is the one surface that lands inside that guaranteed window
|
|
12
|
+
* every step, so the register rides it: the sibling working-context plugin
|
|
13
|
+
* renders the current facts as one of its fields, republished only on change.
|
|
14
|
+
*
|
|
15
|
+
* The register itself is a list of single-line facts, newest last, rebuilt by
|
|
16
|
+
* replaying `tool/call` events for this tool from the session log — exactly
|
|
17
|
+
* the way the paging activation state replays. A fact is a string the model
|
|
18
|
+
* writes; registering a new fact APPENDS, and registering one already present
|
|
19
|
+
* is a no-op report. REVOCATION is append-only too: a `revoke` entry removes
|
|
20
|
+
* every earlier fact carrying the same tag, so the fold stays deterministic
|
|
21
|
+
* after resume and compaction without any process memory.
|
|
22
|
+
*
|
|
23
|
+
* The tool is deliberately small: it validates and reports, it does not edit
|
|
24
|
+
* the context itself. The projection the model sees next step is the fold of
|
|
25
|
+
* the log the runtime appended for this call.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/** Cordis plugin name used by loader diagnostics. */
|
|
29
|
+
export const name = 'liangshen-fact-ledger'
|
|
30
|
+
|
|
31
|
+
/** The tools registry must exist before the ledger tool can register. */
|
|
32
|
+
export const inject = ['tools']
|
|
33
|
+
|
|
34
|
+
/** The model-facing registration tool this plugin mounts. */
|
|
35
|
+
export const FACT_LEDGER_TOOL = 'fact_register'
|
|
36
|
+
|
|
37
|
+
/** Cap one fact so a single entry stays a glance, not a paragraph. */
|
|
38
|
+
export const MAX_FACT_CHARS = 160
|
|
39
|
+
|
|
40
|
+
/** Cap the register so the ledger cannot itself flood the local window. */
|
|
41
|
+
export const MAX_FACTS = 12
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Fold the current fact register from the event stream: every successful
|
|
45
|
+
* `fact_register` call appends its fact (or revokes by tag). Facts carry no
|
|
46
|
+
* ids — revocation matches on the optional `tag`, and an untagged fact can
|
|
47
|
+
* only be revoked by revoking its exact text as the tag of last resort.
|
|
48
|
+
*/
|
|
49
|
+
export function foldFactLedger(events) {
|
|
50
|
+
const facts = []
|
|
51
|
+
for (const event of Array.isArray(events) ? events : []) {
|
|
52
|
+
if (event?.type !== 'tool/call' || event.data?.name !== FACT_LEDGER_TOOL) continue
|
|
53
|
+
let args = event.data?.arguments
|
|
54
|
+
if (typeof args === 'string') {
|
|
55
|
+
try { args = JSON.parse(args) } catch { args = undefined }
|
|
56
|
+
}
|
|
57
|
+
if (args === undefined || args === null) continue
|
|
58
|
+
if (typeof args.revoke === 'string' && args.revoke.trim() !== '') {
|
|
59
|
+
const tag = args.revoke.trim()
|
|
60
|
+
for (let index = facts.length - 1; index >= 0; index -= 1) {
|
|
61
|
+
if (facts[index].tag === tag || facts[index].text === tag) facts.splice(index, 1)
|
|
62
|
+
}
|
|
63
|
+
continue
|
|
64
|
+
}
|
|
65
|
+
if (typeof args.fact !== 'string' || args.fact.trim() === '') continue
|
|
66
|
+
const text = args.fact.trim().slice(0, MAX_FACT_CHARS)
|
|
67
|
+
if (facts.some(entry => entry.text === text)) continue
|
|
68
|
+
const tag = typeof args.tag === 'string' && args.tag.trim() !== '' ? args.tag.trim() : undefined
|
|
69
|
+
facts.push({ text, tag })
|
|
70
|
+
if (facts.length > MAX_FACTS) facts.splice(0, facts.length - MAX_FACTS)
|
|
71
|
+
}
|
|
72
|
+
return facts
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Render the register as the working-context field value, or undefined when
|
|
77
|
+
* the register is empty. Tags annotate their fact inline.
|
|
78
|
+
*/
|
|
79
|
+
export function renderLedgerField(facts) {
|
|
80
|
+
if (!Array.isArray(facts) || facts.length === 0) return undefined
|
|
81
|
+
const rendered = facts.map(entry => entry.tag === undefined ? entry.text : `${entry.text} [${entry.tag}]`)
|
|
82
|
+
return `key facts: ${rendered.join(' ; ')}`
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Register the `fact_register` tool. */
|
|
86
|
+
export function apply(ctx) {
|
|
87
|
+
ctx.tools.register({
|
|
88
|
+
name: FACT_LEDGER_TOOL,
|
|
89
|
+
description: [
|
|
90
|
+
'Pin one key fact into this session working context — the line the runtime projects next to the newest message every step. Use it for the facts a long session must not lose: a hard user constraint, a confirmed architecture decision, a path that already failed.',
|
|
91
|
+
`A fact is one short line (<= ${MAX_FACT_CHARS} chars); at most ${MAX_FACTS} stay pinned, the oldest dropping off. Pass the same text again to no-op; pass the revoke field with a fact tag (or its exact text) to unpin everything under it.`,
|
|
92
|
+
'Pin sparingly: the register rides the guaranteed-attention window, and flooding it dilutes every other fact.',
|
|
93
|
+
].join('\n'),
|
|
94
|
+
parameters: {
|
|
95
|
+
type: 'object',
|
|
96
|
+
properties: {
|
|
97
|
+
fact: {
|
|
98
|
+
type: 'string',
|
|
99
|
+
description: 'The single-line fact to pin (for example "User requires TypeScript strict mode, no any"). Omit when revoking.',
|
|
100
|
+
},
|
|
101
|
+
tag: {
|
|
102
|
+
type: 'string',
|
|
103
|
+
description: 'An optional short tag naming the fact\'s topic (for example "constraints", "auth-decision") so it can be revoked by tag later.',
|
|
104
|
+
},
|
|
105
|
+
revoke: {
|
|
106
|
+
type: 'string',
|
|
107
|
+
description: 'Revoke every pinned fact under this tag (or matching this exact text). When set, the fact field is ignored.',
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
additionalProperties: false,
|
|
111
|
+
},
|
|
112
|
+
output: {
|
|
113
|
+
schema: {
|
|
114
|
+
type: 'object',
|
|
115
|
+
additionalProperties: false,
|
|
116
|
+
properties: {
|
|
117
|
+
text: { type: 'string' },
|
|
118
|
+
},
|
|
119
|
+
required: ['text'],
|
|
120
|
+
},
|
|
121
|
+
render: (_args, value) => [{ type: 'text', text: value.text }],
|
|
122
|
+
},
|
|
123
|
+
/**
|
|
124
|
+
* Concurrency-safe: the handler only validates and reports; the register
|
|
125
|
+
* itself is the fold of the durable log the runtime appends for the call,
|
|
126
|
+
* so overlapping registrations cannot corrupt shared state.
|
|
127
|
+
*/
|
|
128
|
+
isConcurrencySafe: () => true,
|
|
129
|
+
async execute(args) {
|
|
130
|
+
if (typeof args?.revoke === 'string' && args.revoke.trim() !== '') {
|
|
131
|
+
return { text: `Revocation recorded for "${args.revoke.trim()}": every pinned fact under that tag (or matching that text) is dropped from the next step\'s working context.` }
|
|
132
|
+
}
|
|
133
|
+
if (typeof args?.fact !== 'string' || args.fact.trim() === '') {
|
|
134
|
+
throw new Error('fact_register requires either a non-empty `fact` to pin or a non-empty `revoke` tag/text to unpin')
|
|
135
|
+
}
|
|
136
|
+
const text = args.fact.trim().slice(0, MAX_FACT_CHARS)
|
|
137
|
+
const tagged = typeof args?.tag === 'string' && args.tag.trim() !== '' ? ` under tag "${args.tag.trim()}"` : ''
|
|
138
|
+
return { text: `Pinned${tagged}: "${text}". It rides the working-context line from the next step on.` }
|
|
139
|
+
},
|
|
140
|
+
})
|
|
141
|
+
}
|