@shuind/dsh-codex-harness 0.2.21 → 0.2.32-dsh-v0.2.2-rc.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/CHANGELOG.md +121 -0
- package/README.md +48 -38
- package/RELEASE.md +61 -0
- package/assets/codex.svg +5 -0
- package/cordis.patch.yml +150 -6
- package/docs/preset-library.md +39 -23
- package/docs/tool-policy-benchmark.json +310 -0
- package/docs/tool-policy.md +144 -0
- package/lib/client.js +1639 -111
- package/lib/compaction.js +17 -2
- package/lib/index.js +799 -188
- package/lib/installer.js +50 -6
- package/lib/preferences.js +111 -0
- package/lib/tool-policy.js +2235 -0
- package/lib/typert.js +57 -10
- package/lib/types/activity.d.ts +1 -1
- package/lib/types/activity.js +50 -14
- package/lib/types/client/activity.d.ts +33 -9
- package/lib/types/client/desktop.d.ts +43 -0
- package/lib/types/client/desktop.js +121 -0
- package/lib/types/client/entry.d.ts +10 -0
- package/lib/types/client/entry.js +12 -0
- package/lib/types/client/index.d.ts +109 -19
- package/lib/types/client/index.js +21 -40
- package/lib/types/client/policy-drafts.d.ts +25 -0
- package/lib/types/client/policy-drafts.js +47 -0
- package/lib/types/client/preset-copy.d.ts +1 -0
- package/lib/types/client/preset-copy.js +2 -0
- package/lib/types/client/preset-manager.d.ts +12 -2
- package/lib/types/client/preset-manager.js +70 -25
- package/lib/types/client/preset-requests.d.ts +12 -0
- package/lib/types/client/preset-requests.js +101 -0
- package/lib/types/client/session.d.ts +6 -0
- package/lib/types/client/session.js +9 -0
- package/lib/types/client/tool-policy.d.ts +120 -0
- package/lib/types/client/tool-policy.js +394 -0
- package/lib/types/compaction.d.ts +3 -3
- package/lib/types/compaction.js +6 -2
- package/lib/types/desktop-preset.d.ts +20 -0
- package/lib/types/desktop-preset.js +39 -0
- package/lib/types/exec.d.ts +4 -0
- package/lib/types/exec.js +192 -66
- package/lib/types/host-settings.d.ts +4 -0
- package/lib/types/host-settings.js +13 -0
- package/lib/types/index.d.ts +20 -2
- package/lib/types/index.js +181 -68
- package/lib/types/installer.js +11 -2
- package/lib/types/preferences.d.ts +11 -0
- package/lib/types/preferences.js +16 -0
- package/lib/types/preset-editor-remote.d.ts +2 -0
- package/lib/types/preset-editor-remote.js +6 -2
- package/lib/types/preset-editor.d.ts +12 -7
- package/lib/types/preset-editor.js +43 -13
- package/lib/types/preset-prompt-catalog-schema.d.ts +16 -0
- package/lib/types/preset-prompt-catalog-schema.js +11 -0
- package/lib/types/preset-prompt-catalog.d.ts +21 -0
- package/lib/types/preset-prompt-catalog.js +192 -0
- package/lib/types/preset-prompt-contract.d.ts +22 -0
- package/lib/types/preset-prompt-contract.js +3 -0
- package/lib/types/preset-tool-catalog-schema.d.ts +38 -0
- package/lib/types/preset-tool-catalog-schema.js +28 -0
- package/lib/types/preset-tool-catalog.d.ts +5 -0
- package/lib/types/preset-tool-catalog.js +51 -0
- package/lib/types/prompt-sections.d.ts +1 -1
- package/lib/types/prompt-sections.js +9 -3
- package/lib/types/prompt.js +4 -2
- package/lib/types/remote.js +23 -8
- package/lib/types/settings.d.ts +3 -3
- package/lib/types/settings.js +3 -3
- package/lib/types/tool-capabilities.d.ts +32 -0
- package/lib/types/tool-capabilities.js +42 -0
- package/lib/types/tool-policy-contract.d.ts +60 -0
- package/lib/types/tool-policy-contract.js +26 -0
- package/lib/types/tool-policy.d.ts +171 -0
- package/lib/types/tool-policy.js +367 -0
- package/lib/types/typert.host.d.ts +2 -2
- package/lib/types/typert.host.js +12 -2
- package/locale/en.json +6 -0
- package/locale/tool-policy/en.json +6 -0
- package/locale/tool-policy/zh.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +375 -299
- package/scripts/benchmark-tool-policy.mjs +186 -0
- package/scripts/build-preset.mjs +19 -0
- package/scripts/clean-build.mjs +11 -0
- package/src/activity-types.ts +7 -0
- package/src/activity.ts +158 -0
- package/src/client/activity.ts +82 -0
- package/src/client/desktop.tsx +162 -0
- package/src/client/entry.tsx +16 -0
- package/src/client/index.tsx +972 -0
- package/src/client/policy-drafts.ts +56 -0
- package/src/client/preset-copy.ts +83 -0
- package/src/client/preset-manager.tsx +281 -0
- package/src/client/preset-requests.ts +113 -0
- package/src/client/session.ts +11 -0
- package/src/client/tool-policy.tsx +380 -0
- package/src/compact-command.ts +112 -0
- package/src/compaction.ts +190 -0
- package/src/context.ts +15 -0
- package/src/desktop-preset.ts +55 -0
- package/src/exec.ts +570 -0
- package/src/host-settings.ts +17 -0
- package/src/index.ts +1097 -0
- package/src/installer.ts +172 -0
- package/src/invariant.ts +34 -0
- package/src/patch.ts +258 -0
- package/src/preferences.ts +17 -0
- package/src/preset-contract.ts +85 -0
- package/src/preset-editor-remote.ts +41 -0
- package/src/preset-editor.ts +502 -0
- package/src/preset-prompt-catalog-schema.ts +10 -0
- package/src/preset-prompt-catalog.ts +191 -0
- package/src/preset-prompt-contract.ts +21 -0
- package/src/preset-tool-catalog-schema.ts +28 -0
- package/src/preset-tool-catalog.ts +51 -0
- package/src/prompt-sections.ts +33 -0
- package/src/prompt.ts +62 -0
- package/src/remote.ts +748 -0
- package/src/settings.ts +79 -0
- package/src/tool-capabilities.ts +76 -0
- package/src/tool-policy-contract.ts +76 -0
- package/src/tool-policy.ts +388 -0
- package/src/typert.host.ts +119 -0
- package/tsconfig.json +29 -0
- package/tsdown.config.ts +110 -0
- package/lib/types/preset-templates.d.ts +0 -36
- package/lib/types/preset-templates.js +0 -12
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/** Public, read-only preset prompt discovery. No private registry, Agent, or JS/YAML evaluation. */
|
|
2
|
+
import { randomUUID } from 'node:crypto'
|
|
3
|
+
import type { Context } from '@deepseek-ai/cordis'
|
|
4
|
+
import type {} from '@deepseek-ai/dsh-agent-preset-registry'
|
|
5
|
+
import { createScope } from '@deepseek-ai/dsh-scope'
|
|
6
|
+
import type { Scope, ScopeKey } from '@deepseek-ai/dsh-scope'
|
|
7
|
+
import { PERSONA_PREFIX_SECTION, PERSONA_SUFFIX_SECTION } from '@deepseek-ai/dsh-system-prompt'
|
|
8
|
+
import type { PromptSection } from '@deepseek-ai/dsh-system-prompt'
|
|
9
|
+
import { isMap, isScalar, isSeq, parseDocument, YAMLMap } from 'yaml'
|
|
10
|
+
import type { PresetPromptCatalog, PresetPromptEntry, PresetPromptName, PresetPromptOverride } from './preset-prompt-contract.ts'
|
|
11
|
+
|
|
12
|
+
interface Candidate {
|
|
13
|
+
name: PresetPromptName
|
|
14
|
+
label: string
|
|
15
|
+
module: string
|
|
16
|
+
order: number
|
|
17
|
+
complete: boolean
|
|
18
|
+
interpolate: boolean
|
|
19
|
+
literal?: string
|
|
20
|
+
reason?: string
|
|
21
|
+
}
|
|
22
|
+
export interface PresetPromptProbe {
|
|
23
|
+
readonly catalog: PresetPromptCatalog
|
|
24
|
+
readonly scope: ScopeKey
|
|
25
|
+
readonly modules: string
|
|
26
|
+
readonly definitions: ReadonlyMap<PresetPromptName, PromptSection>
|
|
27
|
+
}
|
|
28
|
+
export interface PreparedPromptOverride {
|
|
29
|
+
readonly scope: ScopeKey
|
|
30
|
+
readonly modules: string
|
|
31
|
+
readonly sections: readonly PromptSection[]
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function literal(map: YAMLMap, key: string): unknown {
|
|
35
|
+
const node = map.get(key, true)
|
|
36
|
+
return isScalar(node) && !node.tag ? node.value : undefined
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Native Persona's public source owns these exact names/placements/complete semantics. */
|
|
40
|
+
function candidates(content: string, placement: (name: 'DEPLOYMENT_PERSONA_PREFIX' | 'DEPLOYMENT_PERSONA_SUFFIX') => number) {
|
|
41
|
+
const doc = parseDocument(content, { strict: true, uniqueKeys: true })
|
|
42
|
+
if (doc.errors.length || !isSeq(doc.contents)) throw new Error('invalid-preset-prompt-declaration')
|
|
43
|
+
const found: Candidate[] = []
|
|
44
|
+
const readonly: PresetPromptEntry[] = []
|
|
45
|
+
function visit(rows: unknown, parent = '', conditionalParent = false, isolatedParent = false): void {
|
|
46
|
+
if (!isSeq(rows)) return
|
|
47
|
+
for (const [index, row] of rows.items.entries()) {
|
|
48
|
+
if (!isMap(row) || literal(row, 'disabled') === true) continue
|
|
49
|
+
const module = literal(row, 'name')
|
|
50
|
+
const path = `${parent}/${String(literal(row, 'id') ?? index)}`
|
|
51
|
+
const conditionalRow = conditionalParent || row.has('disabled') && literal(row, 'disabled') === undefined
|
|
52
|
+
const isolation = row.get('isolate', true)
|
|
53
|
+
const isolated = isolatedParent || row.has('isolate') && (!isMap(isolation) || isolation.has('systemPrompt'))
|
|
54
|
+
let config: unknown = row.get('config', true)
|
|
55
|
+
if (isSeq(config)) { visit(config, path, conditionalRow, isolated); continue }
|
|
56
|
+
if (config === undefined && module === '@shuind/dsh-codex-harness') config = new YAMLMap()
|
|
57
|
+
if (typeof module !== 'string' || !isMap(config)) continue
|
|
58
|
+
if (module === '@deepseek-ai/dsh-persona') {
|
|
59
|
+
const completeNode = config.get('complete', true)
|
|
60
|
+
const complete = literal(config, 'complete')
|
|
61
|
+
const uncertain = conditionalRow || completeNode !== undefined && typeof complete !== 'boolean'
|
|
62
|
+
for (const [key, name, order, label] of [
|
|
63
|
+
['prefix', PERSONA_PREFIX_SECTION, placement('DEPLOYMENT_PERSONA_PREFIX'), 'Persona'],
|
|
64
|
+
['suffix', PERSONA_SUFFIX_SECTION, placement('DEPLOYMENT_PERSONA_SUFFIX'), 'Persona · suffix'],
|
|
65
|
+
] as const) {
|
|
66
|
+
const text = literal(config, key)
|
|
67
|
+
const missingSuffix = key === 'suffix' && !config.has(key)
|
|
68
|
+
// Native Persona validates prefix/suffix to strings at mount, then
|
|
69
|
+
// registers static text. A !!js declaration is never evaluated here;
|
|
70
|
+
// its actual registered text is read by assemble and marker-verified.
|
|
71
|
+
const reason = isolated ? 'isolated-prompt-registry' : uncertain ? 'dynamic-declaration' : undefined
|
|
72
|
+
found.push({ name, label, module, order, complete: key === 'prefix' && complete === true, interpolate: true,
|
|
73
|
+
...(typeof text === 'string' ? { literal: text } : missingSuffix ? { literal: '' } : {}),
|
|
74
|
+
...(reason === undefined ? {} : { reason }) })
|
|
75
|
+
}
|
|
76
|
+
} else if (module === '@shuind/dsh-codex-harness' && literal(config, 'codexCore') !== false) {
|
|
77
|
+
found.push({ name: 'codex:base', label: 'Codex 操作提示词', module, order: 10, complete: false, interpolate: true,
|
|
78
|
+
...(isolated ? { reason: 'isolated-prompt-registry' } : conditionalRow || config.has('codexCore') && literal(config, 'codexCore') === undefined ? { reason: 'dynamic-declaration' } : {}) })
|
|
79
|
+
} else {
|
|
80
|
+
// Unknown field-to-section mappings are not editable just because their
|
|
81
|
+
// spelling resembles a prompt. Never return a !!js expression as prose.
|
|
82
|
+
for (const key of ['prefix', 'suffix', 'text', 'section', 'prompt', 'systemPrompt', 'instructions']) {
|
|
83
|
+
if (!config.has(key) || module === '@deepseek-ai/dsh-plan-mode') continue
|
|
84
|
+
const text = literal(config, key)
|
|
85
|
+
readonly.push({ name: `declaration:${path}:${key}`, label: `${module} · ${key}`,
|
|
86
|
+
text: typeof text === 'string' ? text : '', editable: false,
|
|
87
|
+
reason: typeof text === 'string' ? 'unknown-section-contract' : 'dynamic-declaration' })
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
visit(doc.contents)
|
|
93
|
+
return { found, readonly }
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function moduleSignature(rows: readonly { moduleName: string; baseUrl?: string; useHostBase: boolean }[]): string {
|
|
97
|
+
return JSON.stringify(rows.map(row => [row.moduleName, row.baseUrl ?? '', row.useHostBase]))
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** The opaque scope identity is retained only for runtime revision validation, not sent over RPC. */
|
|
101
|
+
export async function probePresetPrompts(ctx: Context, preset: string, expectedScope?: ScopeKey): Promise<PresetPromptProbe> {
|
|
102
|
+
if (typeof preset !== 'string' || !preset.trim() || preset.length > 256) throw new Error('invalid-preset-id')
|
|
103
|
+
const registry = ctx.get('agentPresets')
|
|
104
|
+
const prompt = ctx.get('systemPrompt')
|
|
105
|
+
if (registry === undefined || prompt === undefined || typeof registry.acquireScope !== 'function'
|
|
106
|
+
|| typeof registry.readDocument !== 'function' || typeof registry.inspectCompositions !== 'function') {
|
|
107
|
+
throw new Error('preset-prompt-catalog-unavailable')
|
|
108
|
+
}
|
|
109
|
+
const document = await registry.readDocument(preset)
|
|
110
|
+
const lease = await registry.acquireScope(preset)
|
|
111
|
+
let view: Scope | undefined
|
|
112
|
+
try {
|
|
113
|
+
if (expectedScope !== undefined && lease.key !== expectedScope) throw new Error('preset-prompt-revision-mismatch')
|
|
114
|
+
const key = {}
|
|
115
|
+
view = createScope(ctx, key, { parent: lease.key })
|
|
116
|
+
const inspection = registry.inspectCompositions(view.ctx)
|
|
117
|
+
if (inspection.length !== 1 || inspection[0]?.id !== preset) throw new Error('preset-prompt-revision-unavailable')
|
|
118
|
+
const modules = moduleSignature(inspection[0].modules)
|
|
119
|
+
const active = new Set(inspection[0].modules.map(row => row.moduleName))
|
|
120
|
+
const declared = candidates(document.content, name => prompt.getSectionOrder(name))
|
|
121
|
+
const definitions = new Map<PresetPromptName, PromptSection>()
|
|
122
|
+
const sections: PresetPromptEntry[] = []
|
|
123
|
+
// Show the actual effective original, including legacy own-plugin rewrites.
|
|
124
|
+
// Only marker validation suppresses those rewrites; no model runs here.
|
|
125
|
+
let baseline
|
|
126
|
+
try { baseline = await prompt.assemble({ scope: key }) }
|
|
127
|
+
catch {
|
|
128
|
+
return { scope: lease.key, modules, definitions, catalog: { preset, sections: [
|
|
129
|
+
...declared.found.map(row => ({ name: row.name, label: row.label, text: row.literal ?? '', editable: false, reason: 'assembly-unavailable' })),
|
|
130
|
+
...declared.readonly,
|
|
131
|
+
].slice(0, 200) } }
|
|
132
|
+
}
|
|
133
|
+
const seen = new Set<string>()
|
|
134
|
+
for (const row of declared.found) {
|
|
135
|
+
if (seen.has(row.name)) continue
|
|
136
|
+
seen.add(row.name)
|
|
137
|
+
const actual = baseline.sections.find(section => section.name === row.name)
|
|
138
|
+
let reason = row.reason
|
|
139
|
+
?? (!active.has(row.module) ? 'inactive-contribution' : undefined)
|
|
140
|
+
?? (declared.found.filter(candidate => candidate.name === row.name).length !== 1 ? 'ambiguous-contribution' : undefined)
|
|
141
|
+
?? (actual === undefined ? 'not-effective-or-complete-suppressed' : undefined)
|
|
142
|
+
if (reason === undefined && row.complete && (baseline.sections.length !== 1 || baseline.sections[0]?.name !== row.name)) reason = 'complete-contract-mismatch'
|
|
143
|
+
if (reason === undefined) {
|
|
144
|
+
const marker = `preset-prompt-probe:${randomUUID()}`
|
|
145
|
+
const undo = view.ctx.get('systemPrompt')!.section({ name: row.name, order: row.order, complete: row.complete,
|
|
146
|
+
interpolate: row.interpolate, text: marker })
|
|
147
|
+
try {
|
|
148
|
+
const probed = await prompt.assemble({ scope: key, codexPresetPromptProbe: true })
|
|
149
|
+
if (probed.sections.find(section => section.name === row.name)?.text !== marker
|
|
150
|
+
|| JSON.stringify(probed.sections.map(section => section.name)) !== JSON.stringify(baseline.sections.map(section => section.name))
|
|
151
|
+
|| row.complete && (probed.sections.length !== 1 || probed.sections[0]?.name !== row.name)) reason = 'not-directly-overridable'
|
|
152
|
+
} catch { reason = 'not-directly-overridable' }
|
|
153
|
+
finally { undo() }
|
|
154
|
+
}
|
|
155
|
+
const text = actual?.text ?? row.literal ?? ''
|
|
156
|
+
if (text.length > 1_000_000) reason = 'prompt-too-large'
|
|
157
|
+
sections.push({ name: row.name, label: row.label, text: text.slice(0, 1_000_000), editable: reason === undefined,
|
|
158
|
+
order: row.order, complete: row.complete, interpolate: row.interpolate,
|
|
159
|
+
...(reason === undefined ? {} : { reason }) })
|
|
160
|
+
if (reason === undefined) definitions.set(row.name, { name: row.name, order: row.order, complete: row.complete,
|
|
161
|
+
interpolate: row.interpolate, text })
|
|
162
|
+
}
|
|
163
|
+
for (const row of baseline.sections) {
|
|
164
|
+
if (!seen.has(row.name)) sections.push({ name: row.name, label: row.name, text: row.text.slice(0, 1_000_000), editable: false, reason: 'unknown-or-host-owned-section' })
|
|
165
|
+
}
|
|
166
|
+
sections.push(...declared.readonly)
|
|
167
|
+
if ((await registry.readDocument(preset)).content !== document.content) throw new Error('preset-prompt-revision-mismatch')
|
|
168
|
+
return { scope: lease.key, modules, definitions, catalog: { preset, sections: sections.slice(0, 200) } }
|
|
169
|
+
} finally {
|
|
170
|
+
try { await view?.dispose() }
|
|
171
|
+
finally { await lease[Symbol.asyncDispose]() }
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export async function readPresetPromptCatalog(ctx: Context, preset: string): Promise<PresetPromptCatalog> {
|
|
176
|
+
return (await probePresetPrompts(ctx, preset)).catalog
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export function preparePromptOverrides(probe: PresetPromptProbe, overrides: readonly PresetPromptOverride[]): PreparedPromptOverride {
|
|
180
|
+
const sections = overrides.map(override => {
|
|
181
|
+
const original = probe.definitions.get(override.name)
|
|
182
|
+
if (original === undefined) throw new Error(`unsupported-preset-prompt-override: ${override.name}`)
|
|
183
|
+
return { ...original, text: override.text }
|
|
184
|
+
})
|
|
185
|
+
return { scope: probe.scope, modules: probe.modules, sections }
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export function matchesPromptRevision(ctx: Context, preset: string, prepared: PreparedPromptOverride): boolean {
|
|
189
|
+
const inspection = ctx.get('agentPresets')?.inspectCompositions(ctx)
|
|
190
|
+
return inspection?.length === 1 && inspection[0]?.id === preset && moduleSignature(inspection[0].modules) === prepared.modules
|
|
191
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** Client-safe current-preset prompt catalog; editable targets have reviewed native contracts. */
|
|
2
|
+
export const PRESET_PROMPT_NAMES = ['deployment:persona-prefix', 'deployment:persona-suffix', 'codex:base'] as const
|
|
3
|
+
export type PresetPromptName = typeof PRESET_PROMPT_NAMES[number]
|
|
4
|
+
export interface PresetPromptOverride {
|
|
5
|
+
readonly name: PresetPromptName
|
|
6
|
+
readonly text: string
|
|
7
|
+
}
|
|
8
|
+
export interface PresetPromptEntry {
|
|
9
|
+
readonly name: string
|
|
10
|
+
readonly label: string
|
|
11
|
+
readonly text: string
|
|
12
|
+
readonly editable: boolean
|
|
13
|
+
readonly order?: number
|
|
14
|
+
readonly complete?: boolean
|
|
15
|
+
readonly interpolate?: boolean
|
|
16
|
+
readonly reason?: string
|
|
17
|
+
}
|
|
18
|
+
export interface PresetPromptCatalog {
|
|
19
|
+
readonly preset: string
|
|
20
|
+
readonly sections: readonly PresetPromptEntry[]
|
|
21
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** Shared wire codec; no Host service or browser side effects. */
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
|
|
4
|
+
export const presetToolCatalogSchema = z.object({
|
|
5
|
+
preset: z.string(),
|
|
6
|
+
registeredOnly: z.literal(true),
|
|
7
|
+
legacyCapabilities: z.object({
|
|
8
|
+
terminalToolsEnabled: z.boolean().optional(),
|
|
9
|
+
planToolEnabled: z.boolean().optional(),
|
|
10
|
+
patchToolEnabled: z.boolean().optional(),
|
|
11
|
+
}).optional(),
|
|
12
|
+
tools: z.array(z.object({
|
|
13
|
+
name: z.string(),
|
|
14
|
+
description: z.string(),
|
|
15
|
+
conditional: z.boolean(),
|
|
16
|
+
codexTool: z.object({
|
|
17
|
+
capability: z.enum(['terminalToolsEnabled', 'planToolEnabled', 'patchToolEnabled']),
|
|
18
|
+
presetEnabled: z.boolean(),
|
|
19
|
+
presetOverridesLegacy: z.boolean().optional(),
|
|
20
|
+
}).optional(),
|
|
21
|
+
replacements: z.array(z.object({
|
|
22
|
+
action: z.enum(['codex-exec', 'codex-plan']),
|
|
23
|
+
tools: z.array(z.string()),
|
|
24
|
+
available: z.boolean(),
|
|
25
|
+
reason: z.enum(['conditional', 'target-exists']).optional(),
|
|
26
|
+
})),
|
|
27
|
+
})),
|
|
28
|
+
})
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** Read-only capability inventory for a preset; never creates an Agent or evaluates `when`. */
|
|
2
|
+
import type { Context } from '@deepseek-ai/cordis'
|
|
3
|
+
import type {} from '@deepseek-ai/dsh-agent-preset-registry'
|
|
4
|
+
import type {} from '@deepseek-ai/dsh-tools'
|
|
5
|
+
import { createScope } from '@deepseek-ai/dsh-scope'
|
|
6
|
+
import type { Scope } from '@deepseek-ai/dsh-scope'
|
|
7
|
+
import type { PresetToolCatalog, PresetToolReplacement } from './tool-policy-contract.ts'
|
|
8
|
+
import { codexToolMetadata, readLegacyCapabilities } from './tool-capabilities.ts'
|
|
9
|
+
|
|
10
|
+
export async function readPresetToolCatalog(ctx: Context, preset: string): Promise<PresetToolCatalog> {
|
|
11
|
+
if (typeof preset !== 'string' || !preset.trim() || preset.length > 256) throw new Error('invalid-preset-id')
|
|
12
|
+
const registry = ctx.get('agentPresets')
|
|
13
|
+
const tools = ctx.get('tools')
|
|
14
|
+
if (registry === undefined || typeof registry.acquireScope !== 'function' || tools === undefined) {
|
|
15
|
+
throw new Error('preset-tool-catalog-unavailable')
|
|
16
|
+
}
|
|
17
|
+
const lease = await registry.acquireScope(preset)
|
|
18
|
+
let view: Scope | undefined
|
|
19
|
+
try {
|
|
20
|
+
// A child view applies inherited masks exactly as an Agent would, but has no
|
|
21
|
+
// Agent driver, session, model selection, or initialization callbacks.
|
|
22
|
+
const key = {}
|
|
23
|
+
view = createScope(ctx, key, { parent: lease.key })
|
|
24
|
+
const definitions = tools.definitions(key)
|
|
25
|
+
const names = new Set(definitions.map(tool => tool.name))
|
|
26
|
+
return {
|
|
27
|
+
preset,
|
|
28
|
+
registeredOnly: true,
|
|
29
|
+
legacyCapabilities: readLegacyCapabilities(ctx),
|
|
30
|
+
tools: definitions.map(definition => {
|
|
31
|
+
const conditional = tools.executable(definition.name, key) !== definition
|
|
32
|
+
const replacements: PresetToolReplacement[] = []
|
|
33
|
+
const action = definition.name === 'bash' || definition.name === 'pwsh' ? 'codex-exec'
|
|
34
|
+
: definition.name === 'todo_write' ? 'codex-plan' : undefined
|
|
35
|
+
if (action !== undefined) {
|
|
36
|
+
const targets = action === 'codex-exec' ? ['exec_command', 'write_stdin'] : ['update_plan']
|
|
37
|
+
const reason = conditional ? 'conditional' as const
|
|
38
|
+
: targets.some(target => names.has(target)) ? 'target-exists' as const : undefined
|
|
39
|
+
replacements.push({ action, tools: targets, available: reason === undefined,
|
|
40
|
+
...(reason === undefined ? {} : { reason }) })
|
|
41
|
+
}
|
|
42
|
+
const codexTool = codexToolMetadata(definition)
|
|
43
|
+
return { name: definition.name, description: definition.description.slice(0, 300), conditional, replacements,
|
|
44
|
+
...(codexTool === undefined ? {} : { codexTool }) }
|
|
45
|
+
}).sort((a, b) => a.name.localeCompare(b.name, 'en')),
|
|
46
|
+
}
|
|
47
|
+
} finally {
|
|
48
|
+
try { await view?.dispose() }
|
|
49
|
+
finally { await lease[Symbol.asyncDispose]() }
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
import { hasPresetPromptOverride } from './tool-capabilities.ts'
|
|
5
|
+
|
|
6
|
+
export interface Config { persona?: string; harnessSourcePrompt?: string; webSurfacePrompt?: string }
|
|
7
|
+
export const Config: z<Config> = z.object({ persona: z.string(), harnessSourcePrompt: z.string(), webSurfacePrompt: z.string() })
|
|
8
|
+
export const name = 'preset-prompt-sections'
|
|
9
|
+
export const inject = ['systemPrompt']
|
|
10
|
+
|
|
11
|
+
/** Override only existing sections; dynamic runtime context and tool guidance remain host-owned. */
|
|
12
|
+
export function applyPromptSections<T extends Pick<PromptAssembly, 'sections' | 'contexts' | 'variables'>>(assembly: T, config: Config, protectedNames?: ReadonlySet<string>): T {
|
|
13
|
+
const variables = { ...assembly.variables }
|
|
14
|
+
variables.sourceRoot ??= assembly.sections.find(s => s.name === 'harness:source')?.text.match(/^The DeepSeek Harness implementation checkout is at (.+?)\. The checkout location/u)?.[1]
|
|
15
|
+
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]
|
|
16
|
+
const values: Record<string, string | undefined> = {
|
|
17
|
+
'deployment:persona': config.persona,
|
|
18
|
+
'deployment:persona-prefix': config.persona,
|
|
19
|
+
'harness:source': config.harnessSourcePrompt,
|
|
20
|
+
'app:web-surface': config.webSurfacePrompt,
|
|
21
|
+
}
|
|
22
|
+
return { ...assembly, sections: assembly.sections.map(section => {
|
|
23
|
+
const text = protectedNames?.has(section.name) ? undefined : values[section.name]
|
|
24
|
+
return text === undefined ? section : { ...section, text: text.replace(/\{\{([\w.-]+)\}\}/g, (whole, key: string) => variables[key] ?? whole) }
|
|
25
|
+
}) }
|
|
26
|
+
}
|
|
27
|
+
export function apply(ctx: Context, config: Config): void {
|
|
28
|
+
ctx.on('system-prompt/assemble', async (_assembly, context, next) => {
|
|
29
|
+
const protectedNames = new Set(['deployment:persona-prefix', 'deployment:persona-suffix', 'codex:base']
|
|
30
|
+
.filter(name => hasPresetPromptOverride(ctx, context, name)))
|
|
31
|
+
return applyPromptSections(await next(), config, protectedNames)
|
|
32
|
+
})
|
|
33
|
+
}
|
package/src/prompt.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/** Default plugin-owned Codex operating prompt. */
|
|
2
|
+
export const DEFAULT_CODEX_SYSTEM_PROMPT = String.raw`## General
|
|
3
|
+
|
|
4
|
+
- Follow the current tool catalog, not assumptions from another Codex client. For unknown paths, use the available list/search tools instead of guessing and reuse the returned paths. If only shell search is available, prefer rg or rg --files.
|
|
5
|
+
|
|
6
|
+
## Editing constraints
|
|
7
|
+
|
|
8
|
+
- Default to ASCII when editing or creating files. Only introduce non-ASCII or other Unicode characters when there is a clear justification and the file already uses them.
|
|
9
|
+
- Add succinct code comments that explain non-obvious code. Do not add comments that merely narrate assignments or control flow.
|
|
10
|
+
- You may be in a dirty git worktree. Never revert existing changes you did not make unless the user explicitly requests it. If unrelated files are changed, leave them alone.
|
|
11
|
+
|
|
12
|
+
## Planning
|
|
13
|
+
|
|
14
|
+
- Use update_plan for work with multiple meaningful steps. Keep the plan current as the task progresses.
|
|
15
|
+
- Do not use a plan for a trivial one-step request.
|
|
16
|
+
|
|
17
|
+
## dsh session
|
|
18
|
+
|
|
19
|
+
- The user and you share one workspace. Inspect the repository and every applicable AGENTS.md before editing.
|
|
20
|
+
- For Harness APIs, first load the relevant Harness skill. When Inspect tools are available, start with cordis_inspect_list, then query the provider's directory before an exact Service contract. Reuse returned names; Inspect is read-only.
|
|
21
|
+
- A not-found path or unknown Service is a discovery error: check the file list or Service directory before retrying. Preserve actual failures; do not hide them or bypass permission denials.
|
|
22
|
+
|
|
23
|
+
## Task execution
|
|
24
|
+
|
|
25
|
+
- Keep the user informed with concise progress updates and lead with the result.
|
|
26
|
+
|
|
27
|
+
## Presenting your work
|
|
28
|
+
|
|
29
|
+
- Be concise, direct, friendly, and actionable.
|
|
30
|
+
- For substantial work, explain what changed and why, then briefly note how the work was verified and what comes next.
|
|
31
|
+
- Do not dump large files into the conversation; refer to their paths.
|
|
32
|
+
- Use plain text with short sections only when they improve scanability.
|
|
33
|
+
|
|
34
|
+
## Working principles
|
|
35
|
+
|
|
36
|
+
- Actively establish the user's current context rather than relying on stale assumptions or prior context. Before committing to an approach that could materially shape the outcome or direction of the work, state the intended path and align it with the user; clarify any material uncertainty first. Then pursue the user's goal through the clearest, most effective path.
|
|
37
|
+
- Keep only the essential logic and core actions. Don't explain or test what was removed or why something wasn't done, especially when writing documentation or communicating. Convey enough valuable information with as few words as possible.
|
|
38
|
+
- Solve problems by thinking from first principles and at a higher level.
|
|
39
|
+
`
|
|
40
|
+
|
|
41
|
+
/** Default deployment Persona template used by the Codex preset. */
|
|
42
|
+
export const DEFAULT_CODEX_PERSONA = String.raw`You are Codex, a coding agent based on the {{model}} model. Your working directory is {{cwd}}.`
|
|
43
|
+
|
|
44
|
+
/** Default DSH Core source-checkout guidance template. */
|
|
45
|
+
export const DEFAULT_DSH_CORE_SOURCE_PROMPT = String.raw`The DeepSeek Harness implementation checkout is at {{sourceRoot}}. The checkout location and current working directory are separate values and may differ; never infer the working directory from this path. Use pwd to determine the current working directory. Use this checkout only to inspect or extend DSH itself. If the supplied path is inside app.asar, treat it as a packaged runtime rather than a source checkout. Discover the installed packageDir via Inspect and read its README and package.json exports; do not assume src or individual lib/types filenames exist. Use Host file-read tools for app.asar; native shell search and glob cannot traverse it.`
|
|
46
|
+
|
|
47
|
+
/** Default DSH Web runtime guidance template. */
|
|
48
|
+
export const DEFAULT_DSH_CORE_WEB_PROMPT = [
|
|
49
|
+
'You are interacting with the user through the DeepSeek Harness Web GUI at {{webUrl}}.',
|
|
50
|
+
'When the user refers to "this page", "this GUI", or "this app" without naming another target, they mean this GUI.',
|
|
51
|
+
'The browser provides no implicit DOM, route, or screenshot context.',
|
|
52
|
+
'The client-plugin HMR receiver is active, but client-plugin changes reload without a refresh only while `pnpm run dev:web` is also running from this same checkout to rebuild their bundles; verify that watcher before promising automatic updates.',
|
|
53
|
+
'Every other change - the apps/web shell and plain packages - requires rebuilding the affected Web artifacts and verifying this existing URL after a page refresh.',
|
|
54
|
+
'Starting another server does not update this GUI.',
|
|
55
|
+
'The apps/web Vite entry builds the shell but is not a standalone application because only dsh web injects window.__DSH_BOOT__.',
|
|
56
|
+
'Do not start a replacement server unless the user asks; if one is needed, use a managed background job and verify its exact URL.',
|
|
57
|
+
].join(' ')
|
|
58
|
+
|
|
59
|
+
/** Resolve the full plugin-owned prompt, preserving intentional empty overrides. */
|
|
60
|
+
export function resolveCodexSystemPrompt(systemPrompt?: string): string {
|
|
61
|
+
return systemPrompt ?? DEFAULT_CODEX_SYSTEM_PROMPT
|
|
62
|
+
}
|