@linxin666/dsh-liangshen 0.4.14 → 0.4.16
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 +10 -9
- package/README.zh.md +10 -9
- package/lib/client.js +2 -2
- package/lib/client.js.map +1 -1
- package/lib/index.js +9 -6
- package/lib/types/client/plugin-card-seat.d.ts +1 -1
- package/package.json +18 -18
- package/presets/liangshen/agent.cordis.yml +46 -34
- package/presets/liangshen/dispatch-guard.mjs +471 -0
- package/presets/liangshen/dispatcher-rules.mjs +295 -118
- package/presets/liangshen/fact-ledger.mjs +47 -11
- package/presets/liangshen/tool-catalog.mjs +149 -326
- package/src/client/plugin-card-seat.ts +2 -2
- package/src/composition.test.ts +5 -5
- package/src/composition.ts +8 -6
|
@@ -13,12 +13,13 @@
|
|
|
13
13
|
* renders the current facts as one of its fields, republished only on change.
|
|
14
14
|
*
|
|
15
15
|
* The register itself is a list of single-line facts, newest last, rebuilt by
|
|
16
|
-
* replaying
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
16
|
+
* replaying this tool's calls out of the session log — exactly the way the
|
|
17
|
+
* paging activation state replays, and from both wire shapes a session records
|
|
18
|
+
* them in ({@link factRegisterCall}). A fact is a string the model writes;
|
|
19
|
+
* registering a new fact APPENDS, and registering one already present is a
|
|
20
|
+
* no-op report. REVOCATION is append-only too: a `revoke` entry removes every
|
|
21
|
+
* earlier fact carrying the same tag, so the fold stays deterministic after
|
|
22
|
+
* resume and compaction without any process memory.
|
|
22
23
|
*
|
|
23
24
|
* The tool is deliberately small: it validates and reports, it does not edit
|
|
24
25
|
* the context itself. The projection the model sees next step is the fold of
|
|
@@ -53,17 +54,52 @@ export const MAX_FACT_CHARS = 160
|
|
|
53
54
|
/** Cap the register so the ledger cannot itself flood the local window. */
|
|
54
55
|
export const MAX_FACTS = 12
|
|
55
56
|
|
|
57
|
+
/**
|
|
58
|
+
* The call one event contributes to the fold, or undefined when the event is
|
|
59
|
+
* not a `fact_register` call that took effect.
|
|
60
|
+
*
|
|
61
|
+
* The session records the call in one of two shapes, and which one depends on
|
|
62
|
+
* the presentation the session runs. `native` records a top-level `tool/call`
|
|
63
|
+
* whose `arguments` is the JSON string the model emitted. `ptc` — the shipped
|
|
64
|
+
* default — collapses the wire to `run_code` and reaches every other tool from
|
|
65
|
+
* inside a program, which the runtime records as `tool/ptc-dispatch`: its
|
|
66
|
+
* `arguments` is already an object, and a dispatch that failed carries its own
|
|
67
|
+
* `isError` on the dispatch record (`event.data.isError`), not on the event
|
|
68
|
+
* envelope. Reading only `tool/call` therefore folded an empty register in
|
|
69
|
+
* every factory-default session — pin and revoke both reported success while no
|
|
70
|
+
* `key facts` field ever rendered — which is the same gap `paging.mjs` replays
|
|
71
|
+
* both shapes to avoid.
|
|
72
|
+
*
|
|
73
|
+
* A dispatch that reported an error never took effect, so it contributes
|
|
74
|
+
* nothing: a failed pin must not pin, and a failed revoke must not drop a fact
|
|
75
|
+
* that still stands. `tool/ptc-dispatch-start` only announces a dispatch that
|
|
76
|
+
* has not settled yet, so the event-type check below leaves it out. The
|
|
77
|
+
* `native` half keeps its existing semantics untouched: a `tool/call` is read
|
|
78
|
+
* whatever its `tool/result` later reported, exactly as before this change.
|
|
79
|
+
*/
|
|
80
|
+
function factRegisterCall(event) {
|
|
81
|
+
if (event?.type === 'tool/ptc-dispatch') {
|
|
82
|
+
const dispatch = event.data
|
|
83
|
+
if (dispatch?.name !== FACT_LEDGER_TOOL || dispatch?.isError === true) return undefined
|
|
84
|
+
return dispatch
|
|
85
|
+
}
|
|
86
|
+
if (event?.type !== 'tool/call' || event.data?.name !== FACT_LEDGER_TOOL) return undefined
|
|
87
|
+
return event.data
|
|
88
|
+
}
|
|
89
|
+
|
|
56
90
|
/**
|
|
57
91
|
* Fold the current fact register from the event stream: every successful
|
|
58
|
-
* `fact_register` call appends its fact (or revokes by tag)
|
|
59
|
-
* ids — revocation matches on the optional
|
|
60
|
-
* only be revoked by revoking its exact text as
|
|
92
|
+
* `fact_register` call appends its fact (or revokes by tag), whichever wire
|
|
93
|
+
* shape recorded it. Facts carry no ids — revocation matches on the optional
|
|
94
|
+
* `tag`, and an untagged fact can only be revoked by revoking its exact text as
|
|
95
|
+
* the tag of last resort.
|
|
61
96
|
*/
|
|
62
97
|
export function foldFactLedger(events) {
|
|
63
98
|
const facts = []
|
|
64
99
|
for (const event of Array.isArray(events) ? events : []) {
|
|
65
|
-
|
|
66
|
-
|
|
100
|
+
const data = factRegisterCall(event)
|
|
101
|
+
if (data === undefined) continue
|
|
102
|
+
let args = data.arguments
|
|
67
103
|
if (typeof args === 'string') {
|
|
68
104
|
try { args = JSON.parse(args) } catch { args = undefined }
|
|
69
105
|
}
|