dsh-rwkv-plugin 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +50 -2
- package/cordis.patch.yml +59 -0
- package/lib/client.js +3148 -0
- package/lib/client.js.map +7 -0
- package/lib/index.js +6294 -0
- package/lib/index.js.map +7 -0
- package/lib/line-edit.js +1423 -0
- package/lib/line-edit.js.map +7 -0
- package/lib/todo.js +610 -0
- package/lib/todo.js.map +7 -0
- package/package.json +72 -4
- package/scripts/build.mjs +77 -0
- package/scripts/headless.ts +279 -0
- package/scripts/link-dsh.sh +31 -0
- package/scripts/relay-e2e.mjs +157 -0
- package/scripts/smoke.ts +116 -0
- package/scripts/state.ts +39 -0
- package/scripts/tokenizer-parity.ts +107 -0
- package/scripts/trace-stats.ts +33 -0
- package/src/adapter.ts +388 -0
- package/src/backend/generator.ts +221 -0
- package/src/backend/irwkv.ts +117 -0
- package/src/backend/lightning.ts +228 -0
- package/src/backend/stream.ts +97 -0
- package/src/client/AdapterPicker.tsx +264 -0
- package/src/client/DeveloperPanel.tsx +403 -0
- package/src/client/FoldNode.tsx +82 -0
- package/src/client/ModelCard.tsx +230 -0
- package/src/client/RwkvSettings.tsx +265 -0
- package/src/client/Segment.tsx +15 -0
- package/src/client/StatePicker.tsx +248 -0
- package/src/client/TraceFrames.tsx +462 -0
- package/src/client/TraceView.tsx +77 -0
- package/src/client/WirePanel.tsx +566 -0
- package/src/client/fields.tsx +362 -0
- package/src/client/index.tsx +109 -0
- package/src/client/styles.ts +277 -0
- package/src/client/traces-api.ts +222 -0
- package/src/client/url.ts +20 -0
- package/src/core/agent.ts +586 -0
- package/src/core/defaults.ts +51 -0
- package/src/core/dsh-prompt.ts +32 -0
- package/src/core/edit-modes/index.ts +108 -0
- package/src/core/edit-modes/line-edit.ts +793 -0
- package/src/core/edit-modes/literal.ts +26 -0
- package/src/core/edit-modes/shared.ts +213 -0
- package/src/core/edit-modes/tolerant.ts +558 -0
- package/src/core/fold-pairs.ts +407 -0
- package/src/core/fold-window.ts +563 -0
- package/src/core/line-edit.ts +33 -0
- package/src/core/parse.ts +290 -0
- package/src/core/policy.ts +500 -0
- package/src/core/prompt.ts +220 -0
- package/src/core/relay.ts +400 -0
- package/src/core/step-gates.ts +371 -0
- package/src/core/time-zone.ts +32 -0
- package/src/core/todo-state.ts +227 -0
- package/src/core/tolerant-edit.ts +14 -0
- package/src/core/tool-mappings.ts +209 -0
- package/src/core/tool-repairs.ts +255 -0
- package/src/core/tools.ts +162 -0
- package/src/core/worklist.ts +606 -0
- package/src/dsh-host.ts +48 -0
- package/src/edit-modes/folded-read-guard.ts +32 -0
- package/src/edit-modes/index.ts +26 -0
- package/src/edit-modes/line-edit.ts +154 -0
- package/src/edit-modes/literal.ts +9 -0
- package/src/edit-modes/observations.ts +234 -0
- package/src/edit-modes/syntax-check.ts +226 -0
- package/src/edit-modes/tolerant.ts +232 -0
- package/src/folded-read-guard.ts +6 -0
- package/src/history.ts +163 -0
- package/src/index.ts +287 -0
- package/src/line-edit.ts +15 -0
- package/src/live-wire.ts +133 -0
- package/src/paths.ts +91 -0
- package/src/relay-store.ts +59 -0
- package/src/result-budget.ts +225 -0
- package/src/routes.ts +324 -0
- package/src/session-setup.ts +150 -0
- package/src/syntax-check.ts +2 -0
- package/src/todo.ts +328 -0
- package/src/tokenizer.ts +48 -0
- package/src/tolerant-edit.ts +2 -0
- package/src/trace-stats.ts +225 -0
- package/src/traces.ts +289 -0
- package/vendor/rwkv-tokenizer/NOTICE.md +26 -0
- package/vendor/rwkv-tokenizer/package.json +5 -0
- package/vendor/rwkv-tokenizer/rwkv_tokenizer.d.ts +11 -0
- package/vendor/rwkv-tokenizer/rwkv_tokenizer.js +280 -0
- package/vendor/rwkv-tokenizer/rwkv_tokenizer_bg.wasm +0 -0
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
// One-shot headless run: RWKV as the root DSH agent, configured from flags
|
|
2
|
+
// instead of a hand-edited ~/.dsh profile. The entry eval harnesses call (the
|
|
3
|
+
// rwkv-agent-eval Harbor backend); stdout is DSH's `--json` event stream.
|
|
4
|
+
//
|
|
5
|
+
// node scripts/headless.ts --backend irwkv --base-url http://host:8000 \
|
|
6
|
+
// --model rwkv7-g1l-7.2b [--home DIR] [--max-steps 12] [--thinking full|off] \
|
|
7
|
+
// [--state ID] [--adapter ID] [--no-empty-think] [--installed] [--trace-dir DIR] [--session-id ID] [--model-id ID] [--extra-patch FILE]
|
|
8
|
+
// [--current-date [--time-zone ZONE]] [--native-edit] "task text" (or `-` / stdin)
|
|
9
|
+
//
|
|
10
|
+
// Edit tool: the line-range `edit_lines` is mounted by default (src/line-edit.ts),
|
|
11
|
+
// and the RWKV catalog then hides the literal `edit`. --native-edit (or
|
|
12
|
+
// --no-line-edit) leaves it out for A/B runs with DSH's own edit.
|
|
13
|
+
//
|
|
14
|
+
// --installed: the plugin was added to --home's headless profile with
|
|
15
|
+
// `dsh plugin --profile headless add <dir>` (how a container runs it); only
|
|
16
|
+
// its config is patched. Otherwise the plugin is inserted by file path, which
|
|
17
|
+
// needs DSH to resolve its @deepseek-ai/* imports from a source checkout.
|
|
18
|
+
//
|
|
19
|
+
// DSH is located by, in order: --dsh "<command prefix>", $DSH_ROOT (a source
|
|
20
|
+
// checkout, run through tsx), then `dsh` on PATH (the npm @deepseek-ai/dsh).
|
|
21
|
+
// The task runs in the current directory.
|
|
22
|
+
|
|
23
|
+
import { spawn, spawnSync } from 'node:child_process'
|
|
24
|
+
import { existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, writeFileSync } from 'node:fs'
|
|
25
|
+
import { tmpdir } from 'node:os'
|
|
26
|
+
import { dirname, join, resolve } from 'node:path'
|
|
27
|
+
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
28
|
+
import { parseArgs } from 'node:util'
|
|
29
|
+
|
|
30
|
+
const { values, positionals } = parseArgs({
|
|
31
|
+
allowPositionals: true,
|
|
32
|
+
allowNegative: true,
|
|
33
|
+
options: {
|
|
34
|
+
backend: { type: 'string', default: 'irwkv' },
|
|
35
|
+
'base-url': { type: 'string' },
|
|
36
|
+
model: { type: 'string' },
|
|
37
|
+
state: { type: 'string' },
|
|
38
|
+
adapter: { type: 'string' },
|
|
39
|
+
'empty-think': { type: 'boolean', default: true },
|
|
40
|
+
thinking: { type: 'string', default: 'full' },
|
|
41
|
+
'max-steps': { type: 'string', default: '30' },
|
|
42
|
+
'context-window': { type: 'string', default: '32768' },
|
|
43
|
+
home: { type: 'string' },
|
|
44
|
+
dsh: { type: 'string' },
|
|
45
|
+
installed: { type: 'boolean', default: false },
|
|
46
|
+
'trace-dir': { type: 'string' },
|
|
47
|
+
// Continue an earlier run's session (multi-turn evals: one process per user turn).
|
|
48
|
+
'session-id': { type: 'string' },
|
|
49
|
+
// Model id shown to the model (the persona says "powered by the <id> model").
|
|
50
|
+
'model-id': { type: 'string', default: 'rwkv' },
|
|
51
|
+
// YAML rows appended to the generated cordis.patch.yml (eval overlays: extra
|
|
52
|
+
// plugins, web provider selection). Top-level list items, same indentation.
|
|
53
|
+
'extra-patch': { type: 'string' },
|
|
54
|
+
// File edit mode: 'tolerant' (default), 'line-edit', or 'literal'.
|
|
55
|
+
'edit-mode': { type: 'string' },
|
|
56
|
+
// Mount the edit_lines tool (src/line-edit.ts); kept for --edit-mode line-edit or explicit --line-edit.
|
|
57
|
+
'line-edit': { type: 'boolean' },
|
|
58
|
+
// Native literal edit without tolerance: an explicit opt-out for A/B runs.
|
|
59
|
+
'native-edit': { type: 'boolean', default: false },
|
|
60
|
+
// Context management mode: 'auto-fold' (default), 'full', 'worklist', or 'relay'.
|
|
61
|
+
'history-mode': { type: 'string' },
|
|
62
|
+
'worklist-min-fold': { type: 'string' },
|
|
63
|
+
'worklist-budget': { type: 'string' },
|
|
64
|
+
'worklist-epoch-target': { type: 'string' },
|
|
65
|
+
'worklist-keep-recent': { type: 'string' },
|
|
66
|
+
'worklist-exempt-tokens': { type: 'string' },
|
|
67
|
+
'worklist-backbone-max': { type: 'string' },
|
|
68
|
+
'worklist-hard-cap': { type: 'string' },
|
|
69
|
+
// Mount the stateful worklist tools (src/todo.ts); shown to the model only when historyMode is 'worklist'.
|
|
70
|
+
todo: { type: 'boolean', default: true },
|
|
71
|
+
// System prompt ends with the current date (off: eval prompts match the training rows).
|
|
72
|
+
'current-date': { type: 'boolean', default: false },
|
|
73
|
+
// IANA zone for the date line and for DSH itself (TZ, so bash's `date` agrees).
|
|
74
|
+
'time-zone': { type: 'string' },
|
|
75
|
+
// Experiment only: JSON object of extra rwkv-llm config keys (e.g. taskContract, toolOverrides).
|
|
76
|
+
'plugin-config': { type: 'string' },
|
|
77
|
+
// Multi-session daemon plugin path/URL: disables one-shot runner and serves JSON-RPC on stdio.
|
|
78
|
+
daemon: { type: 'string' },
|
|
79
|
+
},
|
|
80
|
+
})
|
|
81
|
+
if (!values['base-url'] || !values.model) {
|
|
82
|
+
console.error('usage: node scripts/headless.ts --backend irwkv|lightning --base-url URL --model ID [options] "task" | -')
|
|
83
|
+
process.exit(2)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const pluginRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..')
|
|
87
|
+
|
|
88
|
+
// DSH command prefix, and whether it runs from source (then load src/ via tsx).
|
|
89
|
+
let command: string[]
|
|
90
|
+
let fromSource = false
|
|
91
|
+
if (values.dsh) {
|
|
92
|
+
command = values.dsh.split(' ').filter(Boolean)
|
|
93
|
+
fromSource = command.some(part => part.includes('tsx'))
|
|
94
|
+
} else if (process.env.DSH_ROOT) {
|
|
95
|
+
const root = resolve(process.env.DSH_ROOT)
|
|
96
|
+
const pnpmDir = join(root, 'node_modules/.pnpm')
|
|
97
|
+
const tsxDir = readdirSync(pnpmDir).find(name => name.startsWith('tsx@'))
|
|
98
|
+
if (!tsxDir) throw new Error(`tsx not found under ${pnpmDir}`)
|
|
99
|
+
const tsx = join(pnpmDir, tsxDir, 'node_modules/tsx/dist/esm/index.mjs')
|
|
100
|
+
command = ['node', '--import', pathToFileURL(tsx).href, join(root, 'apps/cli/src/bin.ts')]
|
|
101
|
+
process.env.TSX_TSCONFIG_PATH = join(root, 'tsconfig.json')
|
|
102
|
+
fromSource = true
|
|
103
|
+
} else {
|
|
104
|
+
command = ['dsh']
|
|
105
|
+
}
|
|
106
|
+
const [bin, ...binArgs] = command
|
|
107
|
+
if (!bin) throw new Error('empty --dsh command')
|
|
108
|
+
const entry = fromSource ? join(pluginRoot, 'src/index.ts') : join(pluginRoot, 'lib/index.js')
|
|
109
|
+
if (!values.installed && !existsSync(entry)) throw new Error(`plugin entry missing: ${entry} (run npm run build?)`)
|
|
110
|
+
if (values.installed && !values.home) throw new Error('--installed needs --home (the DSH_HOME the plugin was added to)')
|
|
111
|
+
|
|
112
|
+
const home = resolve(values.home ?? mkdtempSync(join(tmpdir(), 'dsh-rwkv-home-')))
|
|
113
|
+
const profileDir = join(home, 'profiles/headless')
|
|
114
|
+
mkdirSync(profileDir, { recursive: true })
|
|
115
|
+
const json = JSON.stringify // YAML is a superset of JSON, so quote every scalar this way.
|
|
116
|
+
// One model, id --model-id (default `rwkv`); rows are written relative to the `models:` key.
|
|
117
|
+
const modelRows = [
|
|
118
|
+
`- id: ${json(values['model-id'])}`,
|
|
119
|
+
` name: ${json(`RWKV · ${values.model}`)}`,
|
|
120
|
+
` backend: ${json(values.backend)}`,
|
|
121
|
+
` baseURL: ${json(values['base-url'])}`,
|
|
122
|
+
` model: ${json(values.model)}`,
|
|
123
|
+
` contextWindow: ${Number(values['context-window'])}`,
|
|
124
|
+
]
|
|
125
|
+
modelRows.push(` historyEmptyThink: ${values['empty-think']}`)
|
|
126
|
+
if (values.state) modelRows.push(` stateId: ${json(values.state)}`)
|
|
127
|
+
if (values.adapter) modelRows.push(` adapterId: ${json(values.adapter)}`)
|
|
128
|
+
// Installed: patch the row the plugin's own bundle layer inserted (same id,
|
|
129
|
+
// whole config replaced). Not installed: insert the row ourselves.
|
|
130
|
+
const pluginRows = values.installed
|
|
131
|
+
? ['- id: rwkv-llm', ' config:']
|
|
132
|
+
: ['- insert:', ' - id: rwkv-llm', ` name: ${json(pathToFileURL(entry).href)}`, ' config:']
|
|
133
|
+
const indent = values.installed ? ' ' : ' '
|
|
134
|
+
const extraPluginConfig = values['plugin-config'] ? JSON.parse(values['plugin-config']) as Record<string, unknown> : {}
|
|
135
|
+
const resolvedEditMode = values['edit-mode']
|
|
136
|
+
?? (typeof extraPluginConfig.editMode === 'string' ? extraPluginConfig.editMode : undefined)
|
|
137
|
+
?? (values['native-edit'] ? 'literal' : values['line-edit'] === true ? 'line-edit' : 'tolerant')
|
|
138
|
+
if (
|
|
139
|
+
resolvedEditMode !== 'tolerant' &&
|
|
140
|
+
resolvedEditMode !== 'line-edit' &&
|
|
141
|
+
resolvedEditMode !== 'literal'
|
|
142
|
+
) {
|
|
143
|
+
throw new Error(`--edit-mode must be tolerant, line-edit, or literal (got ${String(resolvedEditMode)})`)
|
|
144
|
+
}
|
|
145
|
+
const resolvedHistoryMode = values['history-mode']
|
|
146
|
+
?? (typeof extraPluginConfig.historyMode === 'string' ? extraPluginConfig.historyMode : undefined)
|
|
147
|
+
?? 'auto-fold'
|
|
148
|
+
if (resolvedHistoryMode !== 'auto-fold' && resolvedHistoryMode !== 'full' && resolvedHistoryMode !== 'worklist' && resolvedHistoryMode !== 'relay') {
|
|
149
|
+
throw new Error(`--history-mode must be auto-fold, full, worklist, or relay (got ${String(resolvedHistoryMode)})`)
|
|
150
|
+
}
|
|
151
|
+
const resolvedMinFold = values['worklist-min-fold'] !== undefined
|
|
152
|
+
? Number(values['worklist-min-fold'])
|
|
153
|
+
: typeof extraPluginConfig.worklistMinFoldTokens === 'number' ? extraPluginConfig.worklistMinFoldTokens : undefined
|
|
154
|
+
const resolvedBudget = values['worklist-budget'] !== undefined
|
|
155
|
+
? Number(values['worklist-budget'])
|
|
156
|
+
: typeof extraPluginConfig.worklistBudgetTokens === 'number' ? extraPluginConfig.worklistBudgetTokens : undefined
|
|
157
|
+
const resolvedEpochTarget = values['worklist-epoch-target'] !== undefined
|
|
158
|
+
? Number(values['worklist-epoch-target'])
|
|
159
|
+
: typeof extraPluginConfig.worklistEpochTargetTokens === 'number' ? extraPluginConfig.worklistEpochTargetTokens : undefined
|
|
160
|
+
const resolvedKeepRecent = values['worklist-keep-recent'] !== undefined
|
|
161
|
+
? Number(values['worklist-keep-recent'])
|
|
162
|
+
: typeof extraPluginConfig.worklistKeepRecentPairs === 'number' ? extraPluginConfig.worklistKeepRecentPairs : undefined
|
|
163
|
+
const resolvedExemptTokens = values['worklist-exempt-tokens'] !== undefined
|
|
164
|
+
? Number(values['worklist-exempt-tokens'])
|
|
165
|
+
: typeof extraPluginConfig.worklistExemptResultTokens === 'number' ? extraPluginConfig.worklistExemptResultTokens : undefined
|
|
166
|
+
const resolvedBackboneMax = values['worklist-backbone-max'] !== undefined
|
|
167
|
+
? Number(values['worklist-backbone-max'])
|
|
168
|
+
: typeof extraPluginConfig.worklistBackboneMaxTokens === 'number' ? extraPluginConfig.worklistBackboneMaxTokens : undefined
|
|
169
|
+
const resolvedHardCap = values['worklist-hard-cap'] !== undefined
|
|
170
|
+
? Number(values['worklist-hard-cap'])
|
|
171
|
+
: typeof extraPluginConfig.worklistHardCapTokens === 'number' ? extraPluginConfig.worklistHardCapTokens : undefined
|
|
172
|
+
if (resolvedMinFold !== undefined && (!Number.isInteger(resolvedMinFold) || resolvedMinFold < 0)) {
|
|
173
|
+
throw new Error(`--worklist-min-fold must be a non-negative integer (got ${String(resolvedMinFold)})`)
|
|
174
|
+
}
|
|
175
|
+
if (resolvedBudget !== undefined && (!Number.isInteger(resolvedBudget) || resolvedBudget <= 0)) {
|
|
176
|
+
throw new Error(`--worklist-budget must be a positive integer (got ${String(resolvedBudget)})`)
|
|
177
|
+
}
|
|
178
|
+
if (resolvedEpochTarget !== undefined && (!Number.isInteger(resolvedEpochTarget) || resolvedEpochTarget < 0)) {
|
|
179
|
+
throw new Error(`--worklist-epoch-target must be a non-negative integer (got ${String(resolvedEpochTarget)})`)
|
|
180
|
+
}
|
|
181
|
+
if (resolvedKeepRecent !== undefined && (!Number.isInteger(resolvedKeepRecent) || resolvedKeepRecent < 0)) {
|
|
182
|
+
throw new Error(`--worklist-keep-recent must be a non-negative integer (got ${String(resolvedKeepRecent)})`)
|
|
183
|
+
}
|
|
184
|
+
if (resolvedExemptTokens !== undefined && (!Number.isInteger(resolvedExemptTokens) || resolvedExemptTokens < 0)) {
|
|
185
|
+
throw new Error(`--worklist-exempt-tokens must be a non-negative integer (got ${String(resolvedExemptTokens)})`)
|
|
186
|
+
}
|
|
187
|
+
if (resolvedBackboneMax !== undefined && (!Number.isInteger(resolvedBackboneMax) || resolvedBackboneMax <= 0)) {
|
|
188
|
+
throw new Error(`--worklist-backbone-max must be a positive integer (got ${String(resolvedBackboneMax)})`)
|
|
189
|
+
}
|
|
190
|
+
if (resolvedHardCap !== undefined && (!Number.isInteger(resolvedHardCap) || resolvedHardCap < 0)) {
|
|
191
|
+
throw new Error(`--worklist-hard-cap must be a non-negative integer (got ${String(resolvedHardCap)})`)
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
writeFileSync(join(profileDir, 'cordis.patch.yml'), [
|
|
195
|
+
'# Generated by dsh-rwkv-plugin scripts/headless.ts; rewritten on every run.',
|
|
196
|
+
...pluginRows,
|
|
197
|
+
`${indent}providers: [ rwkv ]`,
|
|
198
|
+
`${indent}thinking: ${json(values.thinking)}`,
|
|
199
|
+
`${indent}maxSteps: ${Number(values['max-steps'])}`,
|
|
200
|
+
`${indent}currentDate: ${values['current-date']}`,
|
|
201
|
+
`${indent}editMode: ${json(resolvedEditMode)}`,
|
|
202
|
+
`${indent}historyMode: ${json(resolvedHistoryMode)}`,
|
|
203
|
+
...(resolvedMinFold === undefined ? [] : [`${indent}worklistMinFoldTokens: ${resolvedMinFold}`]),
|
|
204
|
+
...(resolvedBudget === undefined ? [] : [`${indent}worklistBudgetTokens: ${resolvedBudget}`]),
|
|
205
|
+
...(resolvedEpochTarget === undefined ? [] : [`${indent}worklistEpochTargetTokens: ${resolvedEpochTarget}`]),
|
|
206
|
+
...(resolvedKeepRecent === undefined ? [] : [`${indent}worklistKeepRecentPairs: ${resolvedKeepRecent}`]),
|
|
207
|
+
...(resolvedExemptTokens === undefined ? [] : [`${indent}worklistExemptResultTokens: ${resolvedExemptTokens}`]),
|
|
208
|
+
...(resolvedBackboneMax === undefined ? [] : [`${indent}worklistBackboneMaxTokens: ${resolvedBackboneMax}`]),
|
|
209
|
+
...(resolvedHardCap === undefined ? [] : [`${indent}worklistHardCapTokens: ${resolvedHardCap}`]),
|
|
210
|
+
...(values['time-zone'] ? [`${indent}timeZone: ${json(values['time-zone'])}`] : []),
|
|
211
|
+
...(values['trace-dir'] ? [`${indent}traceDir: ${json(resolve(values['trace-dir']))}`] : []),
|
|
212
|
+
...Object.entries(extraPluginConfig)
|
|
213
|
+
.filter(([key]) => ![
|
|
214
|
+
'editMode',
|
|
215
|
+
'historyMode',
|
|
216
|
+
'worklistMinFoldTokens',
|
|
217
|
+
'worklistBudgetTokens',
|
|
218
|
+
'worklistEpochTargetTokens',
|
|
219
|
+
'worklistKeepRecentPairs',
|
|
220
|
+
'worklistExemptResultTokens',
|
|
221
|
+
'worklistBackboneMaxTokens',
|
|
222
|
+
'worklistHardCapTokens',
|
|
223
|
+
].includes(key))
|
|
224
|
+
.map(([key, value]) => `${indent}${key}: ${json(value)}`),
|
|
225
|
+
`${indent}models:`,
|
|
226
|
+
...modelRows.map(row => `${indent} ${row}`),
|
|
227
|
+
...(resolvedEditMode === 'line-edit'
|
|
228
|
+
? ['- insert:', ' - id: rwkv-edit-lines', ` name: ${json(values.installed
|
|
229
|
+
? 'dsh-rwkv-plugin/line-edit'
|
|
230
|
+
: pathToFileURL(join(pluginRoot, fromSource ? 'src/line-edit.ts' : 'lib/line-edit.js')).href)}`]
|
|
231
|
+
: []),
|
|
232
|
+
...(values.todo && resolvedHistoryMode === 'worklist'
|
|
233
|
+
? ['- insert:', ' - id: rwkv-todo', ` name: ${json(values.installed
|
|
234
|
+
? 'dsh-rwkv-plugin/todo'
|
|
235
|
+
: pathToFileURL(join(pluginRoot, fromSource ? 'src/todo.ts' : 'lib/todo.js')).href)}`]
|
|
236
|
+
: []),
|
|
237
|
+
'- id: session-title-llm',
|
|
238
|
+
' disabled: true',
|
|
239
|
+
// The headless profile has no agent-presets service, so the plugin's preset
|
|
240
|
+
// and its rwkv_agent delegate tool cannot activate there; say so up front.
|
|
241
|
+
...(values.installed ? ['- id: preset-rwkv', ' disabled: true', '- id: tool-rwkv-agent', ' disabled: true'] : []),
|
|
242
|
+
'- id: agent-default-model',
|
|
243
|
+
" name: '@deepseek-ai/dsh-agent-default-model'",
|
|
244
|
+
' config:',
|
|
245
|
+
' provider: rwkv',
|
|
246
|
+
` model: ${json(values['model-id'])}`,
|
|
247
|
+
...(values['extra-patch'] ? [readFileSync(resolve(values['extra-patch']), 'utf8').trimEnd()] : []),
|
|
248
|
+
...(values.daemon ? [
|
|
249
|
+
'- id: headless-startup',
|
|
250
|
+
' disabled: true',
|
|
251
|
+
'- id: headless-runner',
|
|
252
|
+
' disabled: true',
|
|
253
|
+
'- insert:',
|
|
254
|
+
' - id: multi-session-daemon',
|
|
255
|
+
` name: ${json(values.daemon.includes('://') ? values.daemon : pathToFileURL(resolve(values.daemon)).href)}`,
|
|
256
|
+
] : []),
|
|
257
|
+
'',
|
|
258
|
+
].join('\n'))
|
|
259
|
+
|
|
260
|
+
// Older DSH releases (npm 0.2.1-rc.5) have no --approval-policy flag.
|
|
261
|
+
let approval: string[] = []
|
|
262
|
+
if (!values.daemon) {
|
|
263
|
+
const help = spawnSync(bin, [...binArgs, '--profile', 'headless', '--help'], {
|
|
264
|
+
encoding: 'utf8', env: { ...process.env, DSH_HOME: home, DSH_TELEMETRY_DISABLED: '1' },
|
|
265
|
+
})
|
|
266
|
+
approval = /--approval-policy/.test(help.stdout ?? '') ? ['--approval-policy', 'never'] : []
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const task = positionals.join(' ')
|
|
270
|
+
const session = values['session-id'] ? ['--session-id', values['session-id']] : []
|
|
271
|
+
const args = values.daemon
|
|
272
|
+
? [...binArgs, '--profile', 'headless']
|
|
273
|
+
: [...binArgs, '--profile', 'headless', '--json', ...approval, ...session, task === '' ? '-' : task]
|
|
274
|
+
const child = spawn(bin, args, {
|
|
275
|
+
stdio: 'inherit',
|
|
276
|
+
// Eval runs never report session content upstream, even on a feedback path.
|
|
277
|
+
env: { ...process.env, DSH_HOME: home, DSH_TELEMETRY_DISABLED: '1', ...values['time-zone'] ? { TZ: values['time-zone'] } : {} },
|
|
278
|
+
})
|
|
279
|
+
child.on('exit', code => process.exit(code ?? 1))
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Links the host packages this plugin imports into ./node_modules, pointing at
|
|
3
|
+
# the same physical directories the DSH checkout loads, so the plugin shares
|
|
4
|
+
# the host's module instances (LlmAdapter, LlmError) when loaded through a
|
|
5
|
+
# --patch overlay by absolute path. A profile install (`dsh plugin add`)
|
|
6
|
+
# resolves these as peers and does not need it.
|
|
7
|
+
set -euo pipefail
|
|
8
|
+
DSH_ROOT="${DSH_ROOT:-$(cd "$(dirname "$0")/../../deepseek-harness" && pwd)}"
|
|
9
|
+
cd "$(dirname "$0")/.."
|
|
10
|
+
mkdir -p node_modules/@deepseek-ai
|
|
11
|
+
link() { ln -sfn "$DSH_ROOT/$2" "node_modules/@deepseek-ai/$1"; echo "@deepseek-ai/$1 -> $DSH_ROOT/$2"; }
|
|
12
|
+
link cordis vendor/cordis
|
|
13
|
+
link schemastery vendor/schemastery
|
|
14
|
+
link dsh-brand packages/util/brand
|
|
15
|
+
link dsh-llm packages/llm/llm
|
|
16
|
+
link dsh-session packages/core/session
|
|
17
|
+
link dsh-tools packages/core/tools
|
|
18
|
+
|
|
19
|
+
react_pkg="$(ls -d "$DSH_ROOT"/node_modules/.pnpm/react@*/node_modules/react 2>/dev/null | tail -1 || true)"
|
|
20
|
+
react_types="$(ls -d "$DSH_ROOT"/node_modules/.pnpm/@types+react@*/node_modules/@types/react 2>/dev/null | tail -1 || true)"
|
|
21
|
+
csstype_pkg="$(ls -d "$DSH_ROOT"/node_modules/.pnpm/csstype@*/node_modules/csstype 2>/dev/null | tail -1 || true)"
|
|
22
|
+
if [[ -n "$react_pkg" ]]; then
|
|
23
|
+
ln -sfn "$react_pkg" node_modules/react
|
|
24
|
+
fi
|
|
25
|
+
if [[ -n "$react_types" ]]; then
|
|
26
|
+
mkdir -p node_modules/@types
|
|
27
|
+
ln -sfn "$react_types" node_modules/@types/react
|
|
28
|
+
fi
|
|
29
|
+
if [[ -n "$csstype_pkg" ]]; then
|
|
30
|
+
ln -sfn "$csstype_pkg" node_modules/csstype
|
|
31
|
+
fi
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
// End-to-end relay check without a model: a fake iRWKV server answers with
|
|
2
|
+
// scripted tool calls, a recap, and a final answer while DSH runs the real
|
|
3
|
+
// loop. Needs the sibling deepseek-harness checkout (it runs DSH from source).
|
|
4
|
+
//
|
|
5
|
+
// node scripts/relay-e2e.mjs
|
|
6
|
+
//
|
|
7
|
+
// Asserts: a mid-turn card and a turn-boundary card are generated, every recap
|
|
8
|
+
// request carries the nudge, the last prompt is turn 2 rendered as cards, the
|
|
9
|
+
// old tool output is gone from it, a step after the cut keeps the latest output
|
|
10
|
+
// verbatim, and the card sidecar exists. Exit code 0 = all checks passed.
|
|
11
|
+
|
|
12
|
+
import { spawn } from 'node:child_process'
|
|
13
|
+
import { createServer } from 'node:http'
|
|
14
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
|
15
|
+
import { tmpdir } from 'node:os'
|
|
16
|
+
import { dirname, join, resolve } from 'node:path'
|
|
17
|
+
import { fileURLToPath } from 'node:url'
|
|
18
|
+
|
|
19
|
+
const PLUGIN = resolve(dirname(fileURLToPath(import.meta.url)), '..')
|
|
20
|
+
const DSH = resolve(PLUGIN, '../deepseek-harness')
|
|
21
|
+
const ROOT = join(tmpdir(), 'rwkv-relay-e2e')
|
|
22
|
+
const PORT = 18099
|
|
23
|
+
const THINK_END = '</think>'
|
|
24
|
+
const MARKER_A = 'AAAA-observer-alpha'
|
|
25
|
+
const MARKER_B = 'BBBB-observer-beta'
|
|
26
|
+
|
|
27
|
+
if (!existsSync(join(DSH, 'apps/cli/src/bin.ts'))) {
|
|
28
|
+
console.error(`relay-e2e: no DSH source checkout at ${DSH} (needed to run DSH from source)`)
|
|
29
|
+
process.exit(2)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
rmSync(ROOT, { recursive: true, force: true })
|
|
33
|
+
mkdirSync(join(ROOT, 'ws'), { recursive: true })
|
|
34
|
+
mkdirSync(join(ROOT, 'home'), { recursive: true })
|
|
35
|
+
writeFileSync(join(ROOT, 'ws/a.txt'), `${MARKER_A}\n${'a'.repeat(700)}\n`)
|
|
36
|
+
writeFileSync(join(ROOT, 'ws/b.txt'), `${MARKER_B}\n${'b'.repeat(700)}\n`)
|
|
37
|
+
|
|
38
|
+
const prompts = []
|
|
39
|
+
let actions = 0
|
|
40
|
+
const server = createServer((request, response) => {
|
|
41
|
+
let body = ''
|
|
42
|
+
request.on('data', chunk => { body += chunk })
|
|
43
|
+
request.on('end', () => {
|
|
44
|
+
const prompt = JSON.parse(body).prompt
|
|
45
|
+
prompts.push(prompt)
|
|
46
|
+
let text
|
|
47
|
+
if (prompt.includes('Stop work. Write only a concise handoff recap')) {
|
|
48
|
+
text = `>Summarising.${THINK_END}1. Objective: summarise the work so far.\n`
|
|
49
|
+
+ '2. Established facts: one of a.txt / b.txt was read; it holds an observer marker.\n'
|
|
50
|
+
+ '3. Applied changes: none.\n4. Verification: none.\n5. Dead ends: none.\n6. Remaining plan: continue.'
|
|
51
|
+
} else if (++actions === 1) {
|
|
52
|
+
text = '>Look.</think><tool_call>{"name":"bash","arguments":{"command":"cat a.txt"}}</tool_call>'
|
|
53
|
+
} else if (actions === 2) {
|
|
54
|
+
text = '>Look again.</think><tool_call>{"name":"bash","arguments":{"command":"cat b.txt"}}</tool_call>'
|
|
55
|
+
} else {
|
|
56
|
+
text = '>Done.</think>Both files contain an alpha and a beta marker.'
|
|
57
|
+
}
|
|
58
|
+
const payload = {
|
|
59
|
+
choices: [{ index: 0, text, finish_reason: 'stop' }],
|
|
60
|
+
usage: { prompt_tokens: Math.ceil(prompt.length / 4), completion_tokens: 12 },
|
|
61
|
+
}
|
|
62
|
+
response.writeHead(200, { 'content-type': 'text/event-stream' })
|
|
63
|
+
response.write(`data: ${JSON.stringify(payload)}\n\n`)
|
|
64
|
+
response.write('data: [DONE]\n\n')
|
|
65
|
+
response.end()
|
|
66
|
+
})
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
function run(args, stdin) {
|
|
70
|
+
return new Promise((resolveRun, reject) => {
|
|
71
|
+
const child = spawn('node', [join(PLUGIN, 'scripts/headless.ts'), ...args], {
|
|
72
|
+
cwd: join(ROOT, 'ws'),
|
|
73
|
+
env: { ...process.env, DSH_ROOT: DSH, DSH_TELEMETRY_DISABLED: '1' },
|
|
74
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
75
|
+
})
|
|
76
|
+
let out = ''
|
|
77
|
+
let err = ''
|
|
78
|
+
const timer = setTimeout(() => { child.kill('SIGKILL'); reject(new Error(`headless timed out\n${err.slice(-2000)}`)) }, 180_000)
|
|
79
|
+
child.stdout.on('data', chunk => { out += chunk })
|
|
80
|
+
child.stderr.on('data', chunk => { err += chunk })
|
|
81
|
+
child.on('exit', code => {
|
|
82
|
+
clearTimeout(timer)
|
|
83
|
+
if (code !== 0) reject(new Error(`headless exited ${code}\n${err.slice(-2000)}`))
|
|
84
|
+
else resolveRun(out)
|
|
85
|
+
})
|
|
86
|
+
child.stdin.end(stdin)
|
|
87
|
+
})
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function sessionOf(output) {
|
|
91
|
+
for (const line of output.split('\n')) {
|
|
92
|
+
try {
|
|
93
|
+
const event = JSON.parse(line)
|
|
94
|
+
if (event.type === 'session' && event.sessionId) return String(event.sessionId)
|
|
95
|
+
} catch {
|
|
96
|
+
// not a JSON event
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return ''
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function traces(session) {
|
|
103
|
+
for (const workspace of readdirSync(join(ROOT, 'home/sessions'))) {
|
|
104
|
+
const file = join(ROOT, 'home/sessions', workspace, session, 'rwkv-trace.jsonl')
|
|
105
|
+
if (existsSync(file)) {
|
|
106
|
+
return { file, records: readFileSync(file, 'utf8').split('\n').filter(Boolean).map(line => JSON.parse(line)) }
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
throw new Error(`no trace for session ${session}`)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// One pair (~430 tokens) fits, two do not: a mid-turn card covers the first.
|
|
113
|
+
const config = JSON.stringify({ historyMode: 'relay', relayBudgetTokens: 800, relayCardMaxTokens: 256 })
|
|
114
|
+
const common = [
|
|
115
|
+
'--backend', 'irwkv',
|
|
116
|
+
'--base-url', `http://127.0.0.1:${PORT}`,
|
|
117
|
+
'--model', 'fake',
|
|
118
|
+
'--home', join(ROOT, 'home'),
|
|
119
|
+
'--plugin-config', config,
|
|
120
|
+
'--max-steps', '6',
|
|
121
|
+
]
|
|
122
|
+
|
|
123
|
+
try {
|
|
124
|
+
await new Promise(listen => server.listen(PORT, '127.0.0.1', listen))
|
|
125
|
+
const first = await run([...common, 'Read a.txt and b.txt and tell me what they contain.'], '')
|
|
126
|
+
const session = sessionOf(first)
|
|
127
|
+
if (!session) throw new Error('no session id in the first run')
|
|
128
|
+
const second = await run([...common, '--session-id', session, 'Now add a one-line note to README.md about it.'], '')
|
|
129
|
+
if (!sessionOf(second)) throw new Error('no session id in the second run')
|
|
130
|
+
|
|
131
|
+
const { file, records } = traces(session)
|
|
132
|
+
const cards = records.filter(record => record.stage === 'card')
|
|
133
|
+
const decisions = records.filter(record => record.stage === 'decision')
|
|
134
|
+
const last = decisions[decisions.length - 1]
|
|
135
|
+
console.log('trace:', file)
|
|
136
|
+
console.log('generations:', records.map(record => record.stage).join(','))
|
|
137
|
+
console.log('card count:', cards.length)
|
|
138
|
+
|
|
139
|
+
const checks = [
|
|
140
|
+
['a mid-turn and a turn-boundary recap were generated', cards.length >= 2],
|
|
141
|
+
['every recap prompt carries the nudge', cards.every(record => record.prompt.includes('Stop work. Write only a concise handoff recap'))],
|
|
142
|
+
['the last prompt is turn 2 rendered as cards', last.prompt.includes('[Handoff recap · turn 1 · part 1]')],
|
|
143
|
+
['the last prompt holds the new task', last.prompt.includes('Now add a one-line note')],
|
|
144
|
+
['the old tool output is gone', !last.prompt.includes(MARKER_A) && !last.prompt.includes(MARKER_B)],
|
|
145
|
+
['the first summary saw the first output only', cards.some(record => record.prompt.includes(MARKER_A) && !record.prompt.includes(MARKER_B))],
|
|
146
|
+
['a step kept the latest output verbatim', decisions.some(record => record.prompt.includes(MARKER_B) && !record.prompt.includes(MARKER_A))],
|
|
147
|
+
['the sidecar exists', existsSync(file.replace(/rwkv-trace\.jsonl$/, 'rwkv-relay.jsonl'))],
|
|
148
|
+
]
|
|
149
|
+
let failed = 0
|
|
150
|
+
for (const [name, ok] of checks) {
|
|
151
|
+
console.log(`${ok ? 'PASS' : 'FAIL'} ${name}`)
|
|
152
|
+
if (!ok) failed++
|
|
153
|
+
}
|
|
154
|
+
process.exitCode = failed === 0 ? 0 : 1
|
|
155
|
+
} finally {
|
|
156
|
+
server.close()
|
|
157
|
+
}
|
package/scripts/smoke.ts
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// Live smoke test without DSH: runs the outer agent loop DSH would run, with
|
|
2
|
+
// tiny local implementations of the DSH read/glob/grep/write tools on a temp
|
|
3
|
+
// workspace, against a real endpoint.
|
|
4
|
+
//
|
|
5
|
+
// node scripts/smoke.ts irwkv http://100.64.0.5:8103 rwkv7-g1l-7.2b
|
|
6
|
+
// node scripts/smoke.ts lightning http://100.64.0.9:8000 rwkv7-g1l-7.2b-20261031-ctx34304 --state <state id> [--adapter <adapter id>]
|
|
7
|
+
// add --task "..." to change the request, --off for agent-wire-v1.0 (no thinking)
|
|
8
|
+
|
|
9
|
+
import { mkdtempSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs'
|
|
10
|
+
import { tmpdir } from 'node:os'
|
|
11
|
+
import { join, relative } from 'node:path'
|
|
12
|
+
import { parseArgs } from 'node:util'
|
|
13
|
+
import type { Generator } from '../src/backend/generator.ts'
|
|
14
|
+
import { IRWKVClient } from '../src/backend/irwkv.ts'
|
|
15
|
+
import { LightningClient } from '../src/backend/lightning.ts'
|
|
16
|
+
import { decideStep, DEFAULT_HARNESS } from '../src/core/agent.ts'
|
|
17
|
+
import type { HistoryItem } from '../src/core/policy.ts'
|
|
18
|
+
import { buildCatalog, type Args } from '../src/core/tools.ts'
|
|
19
|
+
|
|
20
|
+
const { positionals, values } = parseArgs({
|
|
21
|
+
allowPositionals: true,
|
|
22
|
+
allowNegative: true,
|
|
23
|
+
options: {
|
|
24
|
+
state: { type: 'string' },
|
|
25
|
+
adapter: { type: 'string' },
|
|
26
|
+
task: { type: 'string', default: '读一下 config/app.json,告诉我服务监听的端口是多少,以及日志级别。' },
|
|
27
|
+
off: { type: 'boolean', default: false },
|
|
28
|
+
'empty-think': { type: 'boolean', default: false },
|
|
29
|
+
},
|
|
30
|
+
})
|
|
31
|
+
const [backend, baseURL, model] = positionals
|
|
32
|
+
if (!backend || !baseURL || !model) {
|
|
33
|
+
console.error('usage: node scripts/smoke.ts <irwkv|lightning> <baseURL> <model> [--state id] [--adapter id] [--task text] [--off] [--no-empty-think]')
|
|
34
|
+
process.exit(2)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const root = mkdtempSync(join(tmpdir(), 'rwkv-smoke-'))
|
|
38
|
+
mkdirSync(join(root, 'config'))
|
|
39
|
+
mkdirSync(join(root, 'src'))
|
|
40
|
+
writeFileSync(join(root, 'config/app.json'), '{\n "service": "tariff-calc",\n "port": 8443,\n "logLevel": "warn"\n}\n')
|
|
41
|
+
writeFileSync(join(root, 'src/main.ts'), 'import config from "../config/app.json"\nconsole.log(`listening on ${config.port}`)\n')
|
|
42
|
+
writeFileSync(join(root, 'README.md'), '# tariff-calc\nRuns the EU tariff calculator.\n')
|
|
43
|
+
|
|
44
|
+
function walk(dir: string): string[] {
|
|
45
|
+
return readdirSync(dir).flatMap(name => {
|
|
46
|
+
const path = join(dir, name)
|
|
47
|
+
return statSync(path).isDirectory() ? walk(path) : [relative(root, path)]
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Minimal stand-ins for the DSH fs tools, returning text as DSH does. */
|
|
52
|
+
function runDshTool(name: string, args: Args): { ok: boolean; text: string } {
|
|
53
|
+
try {
|
|
54
|
+
switch (name) {
|
|
55
|
+
case 'read': {
|
|
56
|
+
const lines = readFileSync(join(root, String(args.file_path)), 'utf8').split('\n')
|
|
57
|
+
const offset = Number(args.offset ?? 1)
|
|
58
|
+
const limit = Number(args.limit ?? 2000)
|
|
59
|
+
return { ok: true, text: lines.slice(offset - 1, offset - 1 + limit).map((line, index) => `${offset + index}\t${line}`).join('\n') }
|
|
60
|
+
}
|
|
61
|
+
case 'glob':
|
|
62
|
+
return { ok: true, text: walk(join(root, String(args.path ?? '.'))).join('\n') }
|
|
63
|
+
case 'grep': {
|
|
64
|
+
const pattern = new RegExp(String(args.pattern))
|
|
65
|
+
const hits = walk(root).flatMap(file => readFileSync(join(root, file), 'utf8').split('\n')
|
|
66
|
+
.flatMap((line, index) => pattern.test(line) ? [`${file}:${index + 1}:${line}`] : []))
|
|
67
|
+
return { ok: true, text: hits.join('\n') || 'No matches found' }
|
|
68
|
+
}
|
|
69
|
+
case 'write':
|
|
70
|
+
writeFileSync(join(root, String(args.file_path)), String(args.content))
|
|
71
|
+
return { ok: true, text: `Wrote ${String(args.file_path)}` }
|
|
72
|
+
default:
|
|
73
|
+
return { ok: false, text: `tool ${name} is not available in the smoke test` }
|
|
74
|
+
}
|
|
75
|
+
} catch (error) {
|
|
76
|
+
return { ok: false, text: error instanceof Error ? error.message : String(error) }
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const generator: Generator = backend === 'irwkv'
|
|
81
|
+
? new IRWKVClient({ baseURL, model })
|
|
82
|
+
: new LightningClient({
|
|
83
|
+
baseURL,
|
|
84
|
+
model,
|
|
85
|
+
...values.state ? { stateId: values.state } : {},
|
|
86
|
+
...values.adapter ? { adapterId: values.adapter } : {},
|
|
87
|
+
})
|
|
88
|
+
const tools = buildCatalog(['read', 'write', 'glob', 'grep'].map(name => ({ name, description: '', parameters: {} })), { mode: 'mapped' })
|
|
89
|
+
const config = { ...DEFAULT_HARNESS, thinking: values.off ? 'off' as const : 'full' as const, historyEmptyThink: values['empty-think'] }
|
|
90
|
+
const history: HistoryItem[] = [{ kind: 'user', text: values.task }]
|
|
91
|
+
|
|
92
|
+
console.log(`workspace ${root}\ntask: ${values.task}\n`)
|
|
93
|
+
const started = Date.now()
|
|
94
|
+
for (let step = 1; step <= config.maxSteps + 1; step++) {
|
|
95
|
+
let reasoning = ''
|
|
96
|
+
const result = await decideStep({
|
|
97
|
+
history, tools, config, generator,
|
|
98
|
+
sessionId: `smoke-${started}`,
|
|
99
|
+
hooks: {
|
|
100
|
+
reasoning: text => { reasoning += text },
|
|
101
|
+
attempt: label => { if (label !== 'decide') console.log(` [harness] ${label}`) },
|
|
102
|
+
},
|
|
103
|
+
})
|
|
104
|
+
if (reasoning) console.log(`step ${step} thinking: ${reasoning.trim().replace(/\s+/g, ' ').slice(0, 240)}`)
|
|
105
|
+
const { decision } = result
|
|
106
|
+
if (decision.type === 'final') {
|
|
107
|
+
console.log(`\nfinal (${decision.via}, ${result.generations} generations, ${((Date.now() - started) / 1000).toFixed(1)}s):\n${decision.text}`)
|
|
108
|
+
break
|
|
109
|
+
}
|
|
110
|
+
const dshArgs = decision.tool.toDsh(decision.args)
|
|
111
|
+
const outcome = runDshTool(decision.tool.dshName, dshArgs)
|
|
112
|
+
console.log(`step ${step} call ${decision.tool.name} ${JSON.stringify(decision.args)}${decision.repairs.length ? ` repairs=${decision.repairs.join(',')}` : ''} → ${decision.tool.dshName} ${outcome.ok ? 'ok' : 'error'}`)
|
|
113
|
+
const id = `call-${step}`
|
|
114
|
+
history.push({ kind: 'call', id, name: decision.tool.name, args: decision.args })
|
|
115
|
+
history.push({ kind: 'result', id, name: decision.tool.name, ok: outcome.ok, text: outcome.text })
|
|
116
|
+
}
|
package/scripts/state.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Initial-state management on an rwkv_lightning CUDA server (/v1/state/*).
|
|
2
|
+
//
|
|
3
|
+
// node scripts/state.ts list <baseURL>
|
|
4
|
+
// node scripts/state.ts upload <baseURL> <local .pth> prints the new state_id
|
|
5
|
+
// node scripts/state.ts delete <baseURL> <state-id>
|
|
6
|
+
//
|
|
7
|
+
// Password: RWKV_PASSWORD. Extra headers (Cloudflare Access):
|
|
8
|
+
// RWKV_HEADERS='{"CF-Access-Client-Id":"…","CF-Access-Client-Secret":"…"}'
|
|
9
|
+
|
|
10
|
+
import { LightningClient } from '../src/backend/lightning.ts'
|
|
11
|
+
|
|
12
|
+
const [command, baseURL, target] = process.argv.slice(2)
|
|
13
|
+
if (!command || !baseURL) {
|
|
14
|
+
console.error('usage: node scripts/state.ts <list|upload|delete> <baseURL> [file|state-id]')
|
|
15
|
+
process.exit(2)
|
|
16
|
+
}
|
|
17
|
+
const headers = process.env.RWKV_HEADERS ? JSON.parse(process.env.RWKV_HEADERS) as Record<string, string> : undefined
|
|
18
|
+
const password = process.env.RWKV_PASSWORD
|
|
19
|
+
const client = new LightningClient({ baseURL, model: '', ...headers ? { headers } : {}, ...password ? { password } : {} })
|
|
20
|
+
|
|
21
|
+
switch (command) {
|
|
22
|
+
case 'list':
|
|
23
|
+
for (const state of await client.listStates()) {
|
|
24
|
+
console.log(`${state.state_id}\t${state.original_filename ?? ''}\t${state.size_bytes ?? '?'} bytes\t${state.uploaded_at ?? ''}`)
|
|
25
|
+
}
|
|
26
|
+
break
|
|
27
|
+
case 'upload': {
|
|
28
|
+
if (!target) throw new Error('upload needs <local file>')
|
|
29
|
+
console.log((await client.uploadState(target)).state_id)
|
|
30
|
+
break
|
|
31
|
+
}
|
|
32
|
+
case 'delete':
|
|
33
|
+
if (!target) throw new Error('delete needs <state-id>')
|
|
34
|
+
await client.deleteState(target)
|
|
35
|
+
console.log(`${target} deleted`)
|
|
36
|
+
break
|
|
37
|
+
default:
|
|
38
|
+
throw new Error(`unknown command ${command}`)
|
|
39
|
+
}
|