@shuind/dsh-codex-harness 0.2.16 → 0.2.18
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/docs/preset-library.md +20 -18
- package/lib/client.js +300 -177
- package/lib/index.js +266 -13
- package/lib/typert.js +117 -0
- package/lib/types/client/index.d.ts +28 -2
- package/lib/types/client/index.js +32 -62
- package/lib/types/client/preset-copy.d.ts +12 -0
- package/lib/types/client/preset-copy.js +24 -0
- package/lib/types/client/preset-manager.js +70 -9
- package/lib/types/client/preset-requests.d.ts +4 -0
- package/lib/types/client/preset-requests.js +19 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +3 -1
- package/lib/types/preset-contract.d.ts +11 -0
- package/lib/types/preset-editor-remote.js +4 -3
- package/lib/types/preset-editor.d.ts +12 -1
- package/lib/types/preset-editor.js +234 -9
- package/lib/types/prompt-sections.d.ts +15 -0
- package/lib/types/prompt-sections.js +23 -0
- package/lib/types/typert.host.d.ts +47 -0
- package/lib/types/typert.host.js +99 -0
- package/package.json +296 -285
|
@@ -3,7 +3,7 @@ import { readFile, realpath, stat, unlink } from 'node:fs/promises';
|
|
|
3
3
|
import { dirname, isAbsolute, relative, resolve } from 'node:path';
|
|
4
4
|
import { Remote, TypertRemoteService } from '@deepseek-ai/dsh-typert-protocol';
|
|
5
5
|
import { isMap, isScalar, isSeq, parseDocument, Scalar, YAMLMap } from 'yaml';
|
|
6
|
-
import { DEFAULT_CODEX_SYSTEM_PROMPT } from "./prompt.js";
|
|
6
|
+
import { DEFAULT_CODEX_PERSONA, DEFAULT_CODEX_SYSTEM_PROMPT, DEFAULT_DSH_CORE_SOURCE_PROMPT, DEFAULT_DSH_CORE_WEB_PROMPT } from "./prompt.js";
|
|
7
7
|
let atomicWriteModule;
|
|
8
8
|
function loadAtomicWrite() {
|
|
9
9
|
return atomicWriteModule ??= import('@deepseek-ai/dsh-atomic-write');
|
|
@@ -53,6 +53,184 @@ function explicitPrompt(content) {
|
|
|
53
53
|
throw new Error('unsupported-prompt-expression');
|
|
54
54
|
return node.value;
|
|
55
55
|
}
|
|
56
|
+
const SECTION_PLUGIN = '@shuind/dsh-codex-harness/prompt-sections';
|
|
57
|
+
function promptFile(node) {
|
|
58
|
+
if (!node.tag || typeof node.value !== 'string')
|
|
59
|
+
return undefined;
|
|
60
|
+
// Recognize this literal file reference only. Never evaluate arbitrary JS.
|
|
61
|
+
return node.value.match(/^process\.getBuiltinModule\(['"]node:fs['"]\)\.readFileSync\(new URL\(['"]([^'"]+)['"],\s*baseUrl\),\s*['"]utf8['"]\)$/)?.[1];
|
|
62
|
+
}
|
|
63
|
+
/** Read the actual literal prompt fields, including nested groups, without evaluating YAML tags. */
|
|
64
|
+
function promptFields(doc) {
|
|
65
|
+
const fields = [];
|
|
66
|
+
function visit(sequence, parents = []) {
|
|
67
|
+
if (!isSeq(sequence))
|
|
68
|
+
return;
|
|
69
|
+
for (const row of sequence.items) {
|
|
70
|
+
if (!isMap(row) || row.get('disabled') === true)
|
|
71
|
+
continue;
|
|
72
|
+
const path = [...parents, String(row.get('id'))];
|
|
73
|
+
const config = row.get('config', true);
|
|
74
|
+
if (isSeq(config)) {
|
|
75
|
+
visit(config, path);
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (!isMap(config))
|
|
79
|
+
continue;
|
|
80
|
+
const plugin = String(row.get('name'));
|
|
81
|
+
// Plan-mode instructions are mode-specific policy, not preset prompt customization.
|
|
82
|
+
if (plugin === '@deepseek-ai/dsh-plan-mode')
|
|
83
|
+
continue;
|
|
84
|
+
const keys = plugin === '@deepseek-ai/dsh-persona' ? ['prefix', 'text', 'suffix']
|
|
85
|
+
: plugin === '@shuind/dsh-codex-harness' || plugin === SECTION_PLUGIN ? []
|
|
86
|
+
: ['prefix', 'suffix', 'text', 'section', 'prompt', 'systemPrompt', 'instructions'];
|
|
87
|
+
for (const key of keys) {
|
|
88
|
+
const node = config.get(key, true);
|
|
89
|
+
if (!isScalar(node))
|
|
90
|
+
continue;
|
|
91
|
+
fields.push({ id: JSON.stringify([...path, key]), label: plugin === '@deepseek-ai/dsh-persona'
|
|
92
|
+
? (key === 'suffix' ? 'Persona · suffix' : 'Persona') : `${path.join(' / ')} · ${key}`, node, row: config, key });
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
visit(doc.contents);
|
|
97
|
+
return fields;
|
|
98
|
+
}
|
|
99
|
+
function sectionConfig(content) {
|
|
100
|
+
if (supportsCodex(content)) {
|
|
101
|
+
const value = harnessConfig(content).config.get('presetSections', true);
|
|
102
|
+
return isMap(value) ? value : undefined;
|
|
103
|
+
}
|
|
104
|
+
const doc = yaml(content);
|
|
105
|
+
if (!isSeq(doc.contents))
|
|
106
|
+
return undefined;
|
|
107
|
+
const row = doc.contents.items.find(row => isMap(row) && row.get('name') === SECTION_PLUGIN);
|
|
108
|
+
const config = isMap(row) ? row.get('config', true) : undefined;
|
|
109
|
+
return isMap(config) ? config : undefined;
|
|
110
|
+
}
|
|
111
|
+
/** Some presets intentionally shadow host prompt sections with empty entries. */
|
|
112
|
+
function suppressesHostSections(content) {
|
|
113
|
+
const doc = yaml(content);
|
|
114
|
+
let suppressed = false;
|
|
115
|
+
function visit(sequence) {
|
|
116
|
+
if (!isSeq(sequence))
|
|
117
|
+
return;
|
|
118
|
+
for (const row of sequence.items) {
|
|
119
|
+
if (!isMap(row))
|
|
120
|
+
continue;
|
|
121
|
+
const id = String(row.get('id') ?? '');
|
|
122
|
+
const plugin = String(row.get('name') ?? '');
|
|
123
|
+
if (id === 'story-prompt-clean-slate' || plugin === './tools/prompt/clean-slate.mjs' || /(?:^|[\\/])clean-slate\.mjs$/u.test(plugin)) {
|
|
124
|
+
suppressed = true;
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const config = row.get('config', true);
|
|
128
|
+
if (isSeq(config))
|
|
129
|
+
visit(config);
|
|
130
|
+
if (suppressed)
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
visit(doc.contents);
|
|
135
|
+
return suppressed;
|
|
136
|
+
}
|
|
137
|
+
export function readPromptSections(content, shared = {}) {
|
|
138
|
+
const codex = supportsCodex(content);
|
|
139
|
+
const overrides = sectionConfig(content);
|
|
140
|
+
const fields = promptFields(yaml(content));
|
|
141
|
+
const sections = fields.map(({ id, label, node }) => ({ id, label, text: String(node.value ?? ''), editable: !node.tag && typeof node.value === 'string' }));
|
|
142
|
+
// Legacy Codex global overrides remain visible until the preset is saved locally.
|
|
143
|
+
const persona = sections.find(section => section.label === 'Persona');
|
|
144
|
+
const personaOverride = !overrides?.has('persona') && codex ? shared.persona : undefined;
|
|
145
|
+
if (persona && typeof personaOverride === 'string' && personaOverride !== DEFAULT_CODEX_PERSONA)
|
|
146
|
+
persona.text = personaOverride;
|
|
147
|
+
const complete = fields.some(field => field.label.startsWith('Persona') && field.row.get('complete') === true);
|
|
148
|
+
// These are host prompt sections, not Codex capability toggles. The Web
|
|
149
|
+
// host registers them for non-complete agents unless the composition
|
|
150
|
+
// explicitly shadows them (Story's clean-slate plugin does exactly that).
|
|
151
|
+
const hostSections = !complete && !suppressesHostSections(content)
|
|
152
|
+
? [
|
|
153
|
+
...(overrides?.get('harnessSourcePrompt') === '' ? [] : [{ id: 'harness:source', label: 'DSH Core 源码说明', text: String(overrides?.get('harnessSourcePrompt') ?? (codex ? shared.harnessSourcePrompt : undefined) ?? DEFAULT_DSH_CORE_SOURCE_PROMPT), editable: true }]),
|
|
154
|
+
...(overrides?.get('webSurfacePrompt') === '' ? [] : [{ id: 'app:web-surface', label: 'DSH Core Web 说明', text: String(overrides?.get('webSurfacePrompt') ?? (codex ? shared.webSurfacePrompt : undefined) ?? DEFAULT_DSH_CORE_WEB_PROMPT), editable: true }]),
|
|
155
|
+
]
|
|
156
|
+
: [];
|
|
157
|
+
if (hostSections.length)
|
|
158
|
+
sections.splice(persona ? 1 : 0, 0, ...hostSections);
|
|
159
|
+
if (codex) {
|
|
160
|
+
const index = persona ? hostSections.length + 1 : hostSections.length;
|
|
161
|
+
sections.splice(index, 0, { id: 'codex:base', label: 'Codex 操作提示词', text: explicitPrompt(content) ?? shared.systemPrompt ?? DEFAULT_CODEX_SYSTEM_PROMPT, editable: true });
|
|
162
|
+
}
|
|
163
|
+
return sections;
|
|
164
|
+
}
|
|
165
|
+
/** Patch the contributing fields, not a disconnected secondary prompt. */
|
|
166
|
+
export function patchPromptSections(content, sections) {
|
|
167
|
+
const doc = yaml(content);
|
|
168
|
+
const fields = promptFields(doc);
|
|
169
|
+
const known = new Map(readPromptSections(content).map(section => [section.id, section]));
|
|
170
|
+
const overrides = {};
|
|
171
|
+
const seen = new Set();
|
|
172
|
+
for (const section of sections) {
|
|
173
|
+
const field = fields.find(field => field.id === section.id);
|
|
174
|
+
if (seen.has(section.id) || (!known.get(section.id)?.editable && !(field && promptFile(field.node))) || typeof section.text !== 'string' || section.text.length > 1_000_000)
|
|
175
|
+
throw new Error('invalid-prompt-section');
|
|
176
|
+
seen.add(section.id);
|
|
177
|
+
if (field) {
|
|
178
|
+
const node = new Scalar(section.text);
|
|
179
|
+
node.type = Scalar.BLOCK_LITERAL;
|
|
180
|
+
field.row.set(field.key, node);
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
// Merely saving a generic preset must not freeze inherited DSH defaults or
|
|
184
|
+
// install an override plugin. An actual edit is enough; it never needs Codex.
|
|
185
|
+
if (!supportsCodex(content) && known.get(section.id)?.text === section.text)
|
|
186
|
+
continue;
|
|
187
|
+
if (section.id === 'harness:source')
|
|
188
|
+
overrides.harnessSourcePrompt = section.text;
|
|
189
|
+
if (section.id === 'app:web-surface')
|
|
190
|
+
overrides.webSurfacePrompt = section.text;
|
|
191
|
+
}
|
|
192
|
+
// Persona is edited at its original source. Override legacy shared settings with
|
|
193
|
+
// that same value in Codex scopes, without touching another preset's identity.
|
|
194
|
+
const personaFields = fields.filter(field => known.get(field.id)?.label.startsWith('Persona'));
|
|
195
|
+
if (supportsCodex(content) && personaFields.length)
|
|
196
|
+
overrides.persona = personaFields.map(field => sections.find(section => section.id === field.id)?.text ?? String(field.node.value)).join('\n\n');
|
|
197
|
+
let result = doc.toString({ lineWidth: 0 });
|
|
198
|
+
if (supportsCodex(result)) {
|
|
199
|
+
const { doc: next, config } = harnessConfig(result);
|
|
200
|
+
const previous = config.get('presetSections', true);
|
|
201
|
+
const merged = isMap(previous) ? previous : new YAMLMap();
|
|
202
|
+
for (const [key, value] of Object.entries(overrides))
|
|
203
|
+
merged.set(key, value);
|
|
204
|
+
config.set('presetSections', merged);
|
|
205
|
+
result = next.toString({ lineWidth: 0 });
|
|
206
|
+
const operating = sections.find(section => section.id === 'codex:base');
|
|
207
|
+
if (operating)
|
|
208
|
+
result = patchPresetComposition(result, operating.text);
|
|
209
|
+
}
|
|
210
|
+
else if (Object.keys(overrides).length) {
|
|
211
|
+
const next = yaml(result);
|
|
212
|
+
if (!isSeq(next.contents))
|
|
213
|
+
throw new Error('invalid-preset-yaml');
|
|
214
|
+
let row = next.contents.items.find(row => isMap(row) && row.get('name') === SECTION_PLUGIN);
|
|
215
|
+
if (!isMap(row)) {
|
|
216
|
+
const created = new YAMLMap();
|
|
217
|
+
created.set('id', `prompt-sections-${randomUUID().slice(0, 8)}`);
|
|
218
|
+
created.set('name', SECTION_PLUGIN);
|
|
219
|
+
next.add(created);
|
|
220
|
+
row = created;
|
|
221
|
+
}
|
|
222
|
+
const map = row;
|
|
223
|
+
let config = map.get('config', true);
|
|
224
|
+
if (!isMap(config)) {
|
|
225
|
+
config = new YAMLMap();
|
|
226
|
+
map.set('config', config);
|
|
227
|
+
}
|
|
228
|
+
for (const [key, value] of Object.entries(overrides))
|
|
229
|
+
config.set(key, value);
|
|
230
|
+
result = next.toString({ lineWidth: 0 });
|
|
231
|
+
}
|
|
232
|
+
return result;
|
|
233
|
+
}
|
|
56
234
|
export function readCodexPresetOptions(content) {
|
|
57
235
|
try {
|
|
58
236
|
const { config } = harnessConfig(content);
|
|
@@ -109,15 +287,21 @@ export function enhanceComposition(content) {
|
|
|
109
287
|
throw new Error('ambiguous-harness-row');
|
|
110
288
|
// A complete persona suppresses all contributed sections, including Codex's.
|
|
111
289
|
// Keep its identity text while allowing the enhanced copy to compose prompts.
|
|
290
|
+
let wasCompletePersona = false;
|
|
112
291
|
for (const row of doc.contents.items) {
|
|
113
292
|
if (!isMap(row) || row.get('name') !== '@deepseek-ai/dsh-persona')
|
|
114
293
|
continue;
|
|
115
294
|
const persona = row.get('config', true);
|
|
116
|
-
if (isMap(persona) && persona.get('complete') === true)
|
|
295
|
+
if (isMap(persona) && persona.get('complete') === true) {
|
|
296
|
+
wasCompletePersona = true;
|
|
117
297
|
persona.set('complete', false);
|
|
298
|
+
}
|
|
118
299
|
}
|
|
300
|
+
const config = { globalEnhancements: false, codexCore: true };
|
|
301
|
+
if (wasCompletePersona)
|
|
302
|
+
config.presetSections = { harnessSourcePrompt: '', webSurfacePrompt: '' };
|
|
119
303
|
doc.add(doc.createNode({ id: `codex-harness-${randomUUID().slice(0, 8)}`,
|
|
120
|
-
name: '@shuind/dsh-codex-harness', config
|
|
304
|
+
name: '@shuind/dsh-codex-harness', config }));
|
|
121
305
|
return doc.toString({ lineWidth: 0 });
|
|
122
306
|
}
|
|
123
307
|
export function readPresetSystemPrompt(content) {
|
|
@@ -206,13 +390,25 @@ async function assertWithinRoot(path, roots) {
|
|
|
206
390
|
throw new Error('preset-outside-user-root');
|
|
207
391
|
}
|
|
208
392
|
export class CodexPresetEditor extends TypertRemoteService {
|
|
209
|
-
static inject = ['agentPresets'];
|
|
393
|
+
static inject = ['agentPresets', 'settings'];
|
|
210
394
|
agentPresets;
|
|
395
|
+
sharedSettings;
|
|
396
|
+
indexed;
|
|
211
397
|
constructor(ctx, _config) {
|
|
212
398
|
super(ctx, 'codexPresetEditor');
|
|
213
399
|
this.agentPresets = ctx.get('agentPresets');
|
|
400
|
+
const settings = ctx.get('settings');
|
|
401
|
+
this.sharedSettings = () => settings?.get('codex') ?? {};
|
|
214
402
|
}
|
|
215
403
|
async catalog() {
|
|
404
|
+
if (this.agentPresets.list) {
|
|
405
|
+
const rows = await this.agentPresets.list();
|
|
406
|
+
this.indexed = new Map(rows.map(row => [row.id, row]));
|
|
407
|
+
return { presets: rows.filter(row => row.broken === undefined).map(row => ({
|
|
408
|
+
id: row.id, name: row.name || row.id, description: row.description ?? '',
|
|
409
|
+
editable: row.trust === 'user', isDefault: row.id === this.agentPresets.defaultId,
|
|
410
|
+
})), authorable: this.agentPresets.authorable ?? false, excludedCount: rows.filter(row => row.broken !== undefined).length };
|
|
411
|
+
}
|
|
216
412
|
const roster = await this.agentPresets.remoteExportList();
|
|
217
413
|
// Listing must not read/resolve every composition: each host read rescans roots.
|
|
218
414
|
const presets = roster.presets.filter(row => row.broken === undefined).map(row => ({
|
|
@@ -222,17 +418,41 @@ export class CodexPresetEditor extends TypertRemoteService {
|
|
|
222
418
|
return { presets, authorable: roster.authorable, excludedCount: roster.presets.length - presets.length };
|
|
223
419
|
}
|
|
224
420
|
async read(id) {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
const
|
|
421
|
+
// The catalog owns path discovery. Re-read the selected files on every cache
|
|
422
|
+
// miss, and rebuild paths on Refresh; elapsed time must not trigger a full scan.
|
|
423
|
+
const cached = this.indexed?.get(id);
|
|
424
|
+
const preset = cached ?? await this.preset(id);
|
|
425
|
+
if (preset.broken !== undefined)
|
|
426
|
+
throw new Error('invalid-preset');
|
|
427
|
+
const [composition, metadata] = await Promise.all([readFile(preset.path, 'utf8'), optionalFile(resolve(dirname(preset.path), 'preset.yml'))]);
|
|
228
428
|
const meta = metadata ? yaml(metadata) : undefined;
|
|
229
429
|
validateComposition(composition);
|
|
230
430
|
const codex = supportsCodex(composition);
|
|
231
431
|
const prompt = codex ? explicitPrompt(composition) : undefined;
|
|
432
|
+
const shared = this.sharedSettings?.() ?? {};
|
|
433
|
+
const promptSections = readPromptSections(composition, shared);
|
|
434
|
+
for (const field of promptFields(yaml(composition))) {
|
|
435
|
+
const reference = promptFile(field.node);
|
|
436
|
+
if (!reference)
|
|
437
|
+
continue;
|
|
438
|
+
const section = promptSections.find(section => section.id === field.id);
|
|
439
|
+
try {
|
|
440
|
+
const root = await realpath(dirname(preset.path));
|
|
441
|
+
const target = await realpath(resolve(root, reference));
|
|
442
|
+
const rel = relative(root, target);
|
|
443
|
+
if (isAbsolute(rel) || rel === '..' || rel.startsWith('../') || rel.startsWith('..\\'))
|
|
444
|
+
continue;
|
|
445
|
+
if ((await stat(target)).size > 1_000_000)
|
|
446
|
+
continue;
|
|
447
|
+
section.text = await readFile(target, 'utf8');
|
|
448
|
+
section.editable = true;
|
|
449
|
+
}
|
|
450
|
+
catch { /* Unavailable references remain visible and read-only, with their expression intact. */ }
|
|
451
|
+
}
|
|
232
452
|
return { id, name: String(meta?.get('name') ?? id), description: String(meta?.get('description') ?? ''),
|
|
233
|
-
systemPrompt: prompt ?? DEFAULT_CODEX_SYSTEM_PROMPT, inheritPrompt: prompt === undefined,
|
|
453
|
+
systemPrompt: prompt ?? shared.systemPrompt ?? DEFAULT_CODEX_SYSTEM_PROMPT, inheritPrompt: prompt === undefined,
|
|
234
454
|
revision: revision(composition, metadata), editable: preset.trust === 'user', codex,
|
|
235
|
-
codexOptions: readCodexPresetOptions(composition), composition };
|
|
455
|
+
codexOptions: readCodexPresetOptions(composition), composition, promptSections };
|
|
236
456
|
}
|
|
237
457
|
async create(rawInput) {
|
|
238
458
|
const input = validate(rawInput);
|
|
@@ -282,6 +502,8 @@ export class CodexPresetEditor extends TypertRemoteService {
|
|
|
282
502
|
if (input.codexOptions !== undefined)
|
|
283
503
|
nextComposition = patchCodexPresetOptions(nextComposition, input.codexOptions);
|
|
284
504
|
}
|
|
505
|
+
if (input.promptSections)
|
|
506
|
+
nextComposition = patchPromptSections(nextComposition, input.promptSections);
|
|
285
507
|
validateComposition(nextComposition);
|
|
286
508
|
const nextMetadata = patchPresetMetadata(oldMetadata ?? '', input.name, input.description);
|
|
287
509
|
const compositionMode = await mode(composition);
|
|
@@ -293,6 +515,7 @@ export class CodexPresetEditor extends TypertRemoteService {
|
|
|
293
515
|
const result = await this.agentPresets.resolve(input.id);
|
|
294
516
|
if (result.broken !== undefined)
|
|
295
517
|
throw new Error('invalid-preset-after-save');
|
|
518
|
+
this.indexed?.set(input.id, result);
|
|
296
519
|
return await this.read(input.id);
|
|
297
520
|
}
|
|
298
521
|
catch (error) {
|
|
@@ -312,6 +535,8 @@ export class CodexPresetEditor extends TypertRemoteService {
|
|
|
312
535
|
const preset = await this.agentPresets.resolve(id);
|
|
313
536
|
if (preset.broken !== undefined)
|
|
314
537
|
throw new Error('invalid-preset');
|
|
538
|
+
this.indexed ??= new Map();
|
|
539
|
+
this.indexed.set(id, preset);
|
|
315
540
|
return preset;
|
|
316
541
|
}
|
|
317
542
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
2
|
+
import type { PromptAssembly } from '@deepseek-ai/dsh-system-prompt';
|
|
3
|
+
import z from '@deepseek-ai/schemastery';
|
|
4
|
+
export interface Config {
|
|
5
|
+
persona?: string;
|
|
6
|
+
harnessSourcePrompt?: string;
|
|
7
|
+
webSurfacePrompt?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare const Config: z<Config>;
|
|
10
|
+
export declare const name = "preset-prompt-sections";
|
|
11
|
+
export declare const inject: string[];
|
|
12
|
+
/** Override only existing sections; dynamic runtime context and tool guidance remain host-owned. */
|
|
13
|
+
export declare function applyPromptSections(assembly: PromptAssembly, config: Config): PromptAssembly;
|
|
14
|
+
export declare function apply(ctx: Context, config: Config): void;
|
|
15
|
+
//# sourceMappingURL=prompt-sections.d.ts.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import z from '@deepseek-ai/schemastery';
|
|
2
|
+
export const Config = z.object({ persona: z.string(), harnessSourcePrompt: z.string(), webSurfacePrompt: z.string() });
|
|
3
|
+
export const name = 'preset-prompt-sections';
|
|
4
|
+
export const inject = ['systemPrompt'];
|
|
5
|
+
/** Override only existing sections; dynamic runtime context and tool guidance remain host-owned. */
|
|
6
|
+
export function applyPromptSections(assembly, config) {
|
|
7
|
+
const variables = { ...assembly.variables };
|
|
8
|
+
variables.sourceRoot ??= assembly.sections.find(s => s.name === 'harness:source')?.text.match(/^The DeepSeek Harness implementation checkout is at (.+?)\. The checkout location/u)?.[1];
|
|
9
|
+
variables.webUrl ??= assembly.sections.find(s => s.name === 'app:web-surface')?.text.match(/^You are interacting with the user through the DeepSeek Harness Web GUI at (.+?)\. When/u)?.[1];
|
|
10
|
+
const values = {
|
|
11
|
+
'deployment:persona': config.persona,
|
|
12
|
+
'harness:source': config.harnessSourcePrompt,
|
|
13
|
+
'app:web-surface': config.webSurfacePrompt,
|
|
14
|
+
};
|
|
15
|
+
return { ...assembly, sections: assembly.sections.map(section => {
|
|
16
|
+
const text = values[section.name];
|
|
17
|
+
return text === undefined ? section : { ...section, text: text.replace(/\{\{([\w.-]+)\}\}/g, (whole, key) => variables[key] ?? whole) };
|
|
18
|
+
}) };
|
|
19
|
+
}
|
|
20
|
+
export function apply(ctx, config) {
|
|
21
|
+
ctx.on('system-prompt/assemble', async (_assembly, _context, next) => applyPromptSections(await next(), config));
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=prompt-sections.js.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** Host-side Remote contract consumed by the browser's preset editor. */
|
|
3
|
+
export declare const TYPERT: {
|
|
4
|
+
package: string;
|
|
5
|
+
face: "host";
|
|
6
|
+
schemas: never[];
|
|
7
|
+
invocations: {
|
|
8
|
+
id: string;
|
|
9
|
+
service: string;
|
|
10
|
+
namespace: string;
|
|
11
|
+
method: string;
|
|
12
|
+
invocation: {
|
|
13
|
+
kind: "direct";
|
|
14
|
+
};
|
|
15
|
+
parameters: {
|
|
16
|
+
name: string;
|
|
17
|
+
wire: string;
|
|
18
|
+
source: "json";
|
|
19
|
+
codec: {
|
|
20
|
+
mode: "strict";
|
|
21
|
+
typeSymbol: string;
|
|
22
|
+
schema: z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
|
|
23
|
+
};
|
|
24
|
+
}[];
|
|
25
|
+
result: {
|
|
26
|
+
mode: "strict";
|
|
27
|
+
typeSymbol: string;
|
|
28
|
+
schema: z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
|
|
29
|
+
};
|
|
30
|
+
}[];
|
|
31
|
+
model: {
|
|
32
|
+
services: {
|
|
33
|
+
description: string;
|
|
34
|
+
summary: string;
|
|
35
|
+
tags: never[];
|
|
36
|
+
jsDoc: string;
|
|
37
|
+
key: string;
|
|
38
|
+
exportName: string;
|
|
39
|
+
members: never[];
|
|
40
|
+
types: never[];
|
|
41
|
+
}[];
|
|
42
|
+
events: never[];
|
|
43
|
+
objects: never[];
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
export default TYPERT;
|
|
47
|
+
//# sourceMappingURL=typert.host.d.ts.map
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
const PACKAGE = '@shuind/dsh-codex-harness';
|
|
3
|
+
const SERVICE = 'codexPresetEditor';
|
|
4
|
+
const promptSections = z.array(z.object({ id: z.string(), label: z.string(), text: z.string().max(1_000_000), editable: z.boolean(), suppressed: z.boolean().optional() })).max(200);
|
|
5
|
+
const fields = {
|
|
6
|
+
name: z.string().max(200),
|
|
7
|
+
description: z.string().max(4000),
|
|
8
|
+
systemPrompt: z.string().max(1_000_000),
|
|
9
|
+
inheritPrompt: z.boolean(),
|
|
10
|
+
};
|
|
11
|
+
const codexOptions = z.object({
|
|
12
|
+
promptEnabled: z.boolean(),
|
|
13
|
+
terminalToolsEnabled: z.boolean(),
|
|
14
|
+
patchToolEnabled: z.boolean(),
|
|
15
|
+
planToolEnabled: z.boolean(),
|
|
16
|
+
hostedWebSearchEnabled: z.boolean(),
|
|
17
|
+
remoteCompactionEnabled: z.boolean(),
|
|
18
|
+
});
|
|
19
|
+
const document = z.object({
|
|
20
|
+
...fields,
|
|
21
|
+
id: z.string(),
|
|
22
|
+
revision: z.string(),
|
|
23
|
+
editable: z.boolean(),
|
|
24
|
+
codex: z.boolean(),
|
|
25
|
+
codexOptions,
|
|
26
|
+
promptSections, composition: z.string(),
|
|
27
|
+
});
|
|
28
|
+
const catalog = z.object({
|
|
29
|
+
presets: z.array(z.object({
|
|
30
|
+
id: z.string(),
|
|
31
|
+
name: z.string(),
|
|
32
|
+
description: z.string(),
|
|
33
|
+
editable: z.boolean(),
|
|
34
|
+
isDefault: z.boolean(),
|
|
35
|
+
})),
|
|
36
|
+
authorable: z.boolean(),
|
|
37
|
+
excludedCount: z.number(),
|
|
38
|
+
});
|
|
39
|
+
const codexOptionsPatch = codexOptions.partial();
|
|
40
|
+
function descriptor(method, parameter, input, output) {
|
|
41
|
+
const id = `${PACKAGE}#${SERVICE}/${method}`;
|
|
42
|
+
return {
|
|
43
|
+
id,
|
|
44
|
+
service: SERVICE,
|
|
45
|
+
namespace: SERVICE,
|
|
46
|
+
method,
|
|
47
|
+
invocation: { kind: 'direct' },
|
|
48
|
+
parameters: parameter === undefined ? [] : [{
|
|
49
|
+
name: parameter,
|
|
50
|
+
wire: parameter,
|
|
51
|
+
source: 'json',
|
|
52
|
+
codec: { mode: 'strict', typeSymbol: `${id}:${parameter}`, schema: input },
|
|
53
|
+
}],
|
|
54
|
+
result: { mode: 'strict', typeSymbol: `${id}:result`, schema: output },
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
const updateInput = z.object({
|
|
58
|
+
...fields,
|
|
59
|
+
id: z.string(),
|
|
60
|
+
revision: z.string().optional(),
|
|
61
|
+
composition: z.string().max(1_000_000).optional(),
|
|
62
|
+
enableCodex: z.boolean().optional(),
|
|
63
|
+
promptSections: promptSections.optional(), codexOptions: codexOptionsPatch.optional(),
|
|
64
|
+
});
|
|
65
|
+
const createInput = z.object({
|
|
66
|
+
...fields,
|
|
67
|
+
sourceId: z.string(),
|
|
68
|
+
enableCodex: z.boolean().optional(),
|
|
69
|
+
composition: z.string().max(1_000_000).optional(),
|
|
70
|
+
promptSections: promptSections.optional(), codexOptions: codexOptionsPatch.optional(),
|
|
71
|
+
});
|
|
72
|
+
/** Host-side Remote contract consumed by the browser's preset editor. */
|
|
73
|
+
export const TYPERT = {
|
|
74
|
+
package: PACKAGE,
|
|
75
|
+
face: 'host',
|
|
76
|
+
schemas: [],
|
|
77
|
+
invocations: [
|
|
78
|
+
descriptor('catalog', undefined, z.unknown(), catalog),
|
|
79
|
+
descriptor('read', 'id', z.string(), document),
|
|
80
|
+
descriptor('update', 'rawInput', updateInput, document),
|
|
81
|
+
descriptor('create', 'rawInput', createInput, document),
|
|
82
|
+
],
|
|
83
|
+
model: {
|
|
84
|
+
services: [{
|
|
85
|
+
description: 'Author and inspect DSH agent presets with Codex capabilities.',
|
|
86
|
+
summary: 'Codex preset editor.',
|
|
87
|
+
tags: [],
|
|
88
|
+
jsDoc: '',
|
|
89
|
+
key: SERVICE,
|
|
90
|
+
exportName: 'CodexPresetEditor',
|
|
91
|
+
members: [],
|
|
92
|
+
types: [],
|
|
93
|
+
}],
|
|
94
|
+
events: [],
|
|
95
|
+
objects: [],
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
export default TYPERT;
|
|
99
|
+
//# sourceMappingURL=typert.host.js.map
|