@shuind/dsh-codex-harness 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +49 -49
- package/cordis.patch.yml +11 -11
- package/lib/client.js +267 -114
- package/lib/index.js +79 -10
- package/lib/installer.js +22 -1
- package/lib/types/client/index.d.ts +19 -9
- package/lib/types/client/index.js +110 -55
- package/lib/types/index.d.ts +7 -1
- package/lib/types/index.js +58 -6
- package/lib/types/patch.js +15 -15
- package/lib/types/prompt.d.ts +6 -0
- package/lib/types/prompt.js +50 -35
- package/lib/types/settings.d.ts +6 -0
- package/lib/types/settings.js +7 -1
- package/package.json +247 -247
- package/presets/codex-collaboration/agent.cordis.yml +197 -197
- package/presets/codex-collaboration/preset.yml +3 -3
package/lib/types/index.js
CHANGED
|
@@ -6,9 +6,9 @@ import { APPLY_PATCH_DESCRIPTION, applyPatchHunks, parsePatch } from "./patch.js
|
|
|
6
6
|
import { renderExecResult, runExecCommand, runWriteStdin } from "./exec.js";
|
|
7
7
|
import { hostedWebSearchStream, installHostedWebSearch, remoteCompactStream, repairLegacyPiAiContextOverflow, } from "./remote.js";
|
|
8
8
|
import { registerCodexActivityProjection } from "./activity.js";
|
|
9
|
-
import { DEFAULT_CODEX_SYSTEM_PROMPT, resolveCodexSystemPrompt } from "./prompt.js";
|
|
9
|
+
import { DEFAULT_CODEX_PERSONA, DEFAULT_CODEX_SYSTEM_PROMPT, DEFAULT_DSH_CORE_SOURCE_PROMPT, DEFAULT_DSH_CORE_WEB_PROMPT, resolveCodexSystemPrompt, } from "./prompt.js";
|
|
10
10
|
import { CODEX_SETTINGS_ENTRY, CODEX_SETTINGS_NAMESPACE, CODEX_SETTINGS_SCHEMA, } from "./settings.js";
|
|
11
|
-
export { DEFAULT_CODEX_SYSTEM_PROMPT } from "./prompt.js";
|
|
11
|
+
export { DEFAULT_CODEX_PERSONA, DEFAULT_CODEX_SYSTEM_PROMPT, DEFAULT_DSH_CORE_SOURCE_PROMPT, DEFAULT_DSH_CORE_WEB_PROMPT, } from "./prompt.js";
|
|
12
12
|
export { CODEX_SETTINGS_NAMESPACE, CODEX_SETTINGS_SCHEMA } from "./settings.js";
|
|
13
13
|
export const name = 'codex';
|
|
14
14
|
export const inject = ['tools', 'systemPrompt', 'shell', 'fs', 'llm', 'credentials', 'settings'];
|
|
@@ -24,6 +24,9 @@ export const Config = z.object({
|
|
|
24
24
|
hostedWebSearch: z.boolean().default(true),
|
|
25
25
|
remoteCompact: z.boolean().default(true),
|
|
26
26
|
systemPrompt: z.string().default(DEFAULT_CODEX_SYSTEM_PROMPT),
|
|
27
|
+
persona: z.string().default(DEFAULT_CODEX_PERSONA),
|
|
28
|
+
harnessSourcePrompt: z.string().default(DEFAULT_DSH_CORE_SOURCE_PROMPT),
|
|
29
|
+
webSurfacePrompt: z.string().default(DEFAULT_DSH_CORE_WEB_PROMPT),
|
|
27
30
|
});
|
|
28
31
|
const LLM_PI_AI_SETTINGS = settingsNamespace('llm-pi-ai');
|
|
29
32
|
const GPT_REASONING_EFFORTS = {
|
|
@@ -118,8 +121,14 @@ function watchConfiguredGptModels(ctx) {
|
|
|
118
121
|
schedule();
|
|
119
122
|
}
|
|
120
123
|
/** Install the optional settings source used by requests and prompt assembly. */
|
|
121
|
-
function installCodexSettings(ctx, systemPrompt) {
|
|
122
|
-
const entry = {
|
|
124
|
+
function installCodexSettings(ctx, systemPrompt, persona, harnessSourcePrompt, webSurfacePrompt) {
|
|
125
|
+
const entry = {
|
|
126
|
+
...CODEX_SETTINGS_ENTRY,
|
|
127
|
+
systemPrompt,
|
|
128
|
+
persona,
|
|
129
|
+
harnessSourcePrompt,
|
|
130
|
+
webSurfacePrompt,
|
|
131
|
+
};
|
|
123
132
|
const withDefaults = (value) => ({
|
|
124
133
|
...entry,
|
|
125
134
|
...value,
|
|
@@ -241,6 +250,45 @@ export function normalizeCodexPromptAssembly(assembly) {
|
|
|
241
250
|
sections: [persona, ...sections.filter(section => section.name !== 'deployment:persona')],
|
|
242
251
|
};
|
|
243
252
|
}
|
|
253
|
+
function sectionText(assembly, name) {
|
|
254
|
+
const section = assembly.sections.find(candidate => candidate.name === name);
|
|
255
|
+
return section?.text;
|
|
256
|
+
}
|
|
257
|
+
function promptVariables(assembly) {
|
|
258
|
+
const variables = { ...assembly.variables };
|
|
259
|
+
if (variables.sourceRoot === undefined) {
|
|
260
|
+
const source = sectionText(assembly, 'harness:source');
|
|
261
|
+
const match = source?.match(/^The DeepSeek Harness implementation checkout is at (.+?)\. The checkout location/u);
|
|
262
|
+
if (match?.[1] !== undefined)
|
|
263
|
+
variables.sourceRoot = match[1];
|
|
264
|
+
}
|
|
265
|
+
if (variables.webUrl === undefined) {
|
|
266
|
+
const web = sectionText(assembly, 'app:web-surface');
|
|
267
|
+
const match = web?.match(/^You are interacting with the user through the DeepSeek Harness Web GUI at (.+?)\. When/u);
|
|
268
|
+
if (match?.[1] !== undefined)
|
|
269
|
+
variables.webUrl = match[1];
|
|
270
|
+
}
|
|
271
|
+
return variables;
|
|
272
|
+
}
|
|
273
|
+
function interpolateCodexPrompt(text, variables) {
|
|
274
|
+
return text.replace(/\{\{([\w.-]+)\}\}/g, (whole, key) => variables[key] ?? whole);
|
|
275
|
+
}
|
|
276
|
+
/** Apply user-editable Persona and DSH Core runtime prompt templates. */
|
|
277
|
+
function applyCodexPromptOverrides(assembly, settings) {
|
|
278
|
+
const variables = promptVariables(assembly);
|
|
279
|
+
const overrides = {
|
|
280
|
+
'deployment:persona': settings.persona,
|
|
281
|
+
'harness:source': settings.harnessSourcePrompt,
|
|
282
|
+
'app:web-surface': settings.webSurfacePrompt,
|
|
283
|
+
};
|
|
284
|
+
const sections = assembly.sections.map(section => {
|
|
285
|
+
const template = overrides[section.name];
|
|
286
|
+
return template === undefined
|
|
287
|
+
? section
|
|
288
|
+
: { ...section, text: interpolateCodexPrompt(template, variables) };
|
|
289
|
+
});
|
|
290
|
+
return { ...assembly, sections, variables };
|
|
291
|
+
}
|
|
244
292
|
const CODEX_TOOL_NAMES = {
|
|
245
293
|
terminalToolsEnabled: new Set(['exec_command', 'write_stdin']),
|
|
246
294
|
patchToolEnabled: new Set(['apply_patch']),
|
|
@@ -258,7 +306,8 @@ export function applyCodexCapabilitySettings(assembly, settings) {
|
|
|
258
306
|
const filtered = disabled.size === 0
|
|
259
307
|
? assembly
|
|
260
308
|
: { ...assembly, tools: assembly.tools.filter(tool => !disabled.has(tool.name)) };
|
|
261
|
-
|
|
309
|
+
const withOverrides = applyCodexPromptOverrides(filtered, settings);
|
|
310
|
+
return settings.promptEnabled ? normalizeCodexPromptAssembly(withOverrides) : withOverrides;
|
|
262
311
|
}
|
|
263
312
|
/** Build the complete plugin-owned prompt, preserving an intentional empty value. */
|
|
264
313
|
export function buildCodexSystemPrompt(config = {}) {
|
|
@@ -535,13 +584,16 @@ export function apply(ctx, config = {}) {
|
|
|
535
584
|
hostedWebSearch: config.hostedWebSearch ?? true,
|
|
536
585
|
remoteCompact: config.remoteCompact ?? true,
|
|
537
586
|
systemPrompt: config.systemPrompt ?? DEFAULT_CODEX_SYSTEM_PROMPT,
|
|
587
|
+
persona: config.persona ?? DEFAULT_CODEX_PERSONA,
|
|
588
|
+
harnessSourcePrompt: config.harnessSourcePrompt ?? DEFAULT_DSH_CORE_SOURCE_PROMPT,
|
|
589
|
+
webSurfacePrompt: config.webSurfacePrompt ?? DEFAULT_DSH_CORE_WEB_PROMPT,
|
|
538
590
|
};
|
|
539
591
|
if (resolved.codexCore
|
|
540
592
|
&& ctx.fs.sandboxMode !== undefined
|
|
541
593
|
&& ctx.get('sandboxPolicy') === undefined) {
|
|
542
594
|
throw new Error('codex: a sandboxing filesystem requires ctx.sandboxPolicy');
|
|
543
595
|
}
|
|
544
|
-
const codexSettings = installCodexSettings(ctx, resolved.systemPrompt);
|
|
596
|
+
const codexSettings = installCodexSettings(ctx, resolved.systemPrompt, resolved.persona, resolved.harnessSourcePrompt, resolved.webSurfacePrompt);
|
|
545
597
|
const execConfig = { ...resolved, currentSettings: codexSettings.current };
|
|
546
598
|
if (resolved.globalEnhancements) {
|
|
547
599
|
// The generic pi-ai plugin remains the owner of provider routes. This
|
package/lib/types/patch.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
/** Parser and line-oriented applicator for Codex's `apply_patch` language. */
|
|
2
2
|
export const APPLY_PATCH_DESCRIPTION = 'Edits files using Codex patch syntax with Begin/End Patch markers and file update directives. In hunk lines, the first character is the operation marker; repeat a source-leading marker when the source line itself starts with one.';
|
|
3
3
|
/** The grammar sent to providers that support OpenAI custom grammar tools. */
|
|
4
|
-
export const APPLY_PATCH_GRAMMAR = String.raw `start: begin_patch hunk+ end_patch
|
|
5
|
-
begin_patch: "*** Begin Patch" LF
|
|
6
|
-
end_patch: "*** End Patch" LF?
|
|
7
|
-
hunk: add_hunk | delete_hunk | update_hunk
|
|
8
|
-
add_hunk: "*** Add File: " filename LF add_line+
|
|
9
|
-
delete_hunk: "*** Delete File: " filename LF
|
|
10
|
-
update_hunk: "*** Update File: " filename LF change_move? change?
|
|
11
|
-
filename: /(.+)/
|
|
12
|
-
add_line: "+" /(.*)/ LF -> line
|
|
13
|
-
change_move: "*** Move to: " filename LF
|
|
14
|
-
change: (change_context | change_line)+ eof_line?
|
|
15
|
-
change_context: ("@@" | "@@ " /(.+)/) LF
|
|
16
|
-
change_line: ("+" | "-" | " ") /(.*)/ LF
|
|
17
|
-
eof_line: "*** End of File" LF
|
|
18
|
-
%import common.LF
|
|
4
|
+
export const APPLY_PATCH_GRAMMAR = String.raw `start: begin_patch hunk+ end_patch
|
|
5
|
+
begin_patch: "*** Begin Patch" LF
|
|
6
|
+
end_patch: "*** End Patch" LF?
|
|
7
|
+
hunk: add_hunk | delete_hunk | update_hunk
|
|
8
|
+
add_hunk: "*** Add File: " filename LF add_line+
|
|
9
|
+
delete_hunk: "*** Delete File: " filename LF
|
|
10
|
+
update_hunk: "*** Update File: " filename LF change_move? change?
|
|
11
|
+
filename: /(.+)/
|
|
12
|
+
add_line: "+" /(.*)/ LF -> line
|
|
13
|
+
change_move: "*** Move to: " filename LF
|
|
14
|
+
change: (change_context | change_line)+ eof_line?
|
|
15
|
+
change_context: ("@@" | "@@ " /(.+)/) LF
|
|
16
|
+
change_line: ("+" | "-" | " ") /(.*)/ LF
|
|
17
|
+
eof_line: "*** End of File" LF
|
|
18
|
+
%import common.LF
|
|
19
19
|
`;
|
|
20
20
|
function invalid(message) {
|
|
21
21
|
throw new Error(`apply_patch: ${message}`);
|
package/lib/types/prompt.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
/** Default plugin-owned Codex operating prompt. */
|
|
2
2
|
export declare const DEFAULT_CODEX_SYSTEM_PROMPT: string;
|
|
3
|
+
/** Default deployment Persona template used by the Codex preset. */
|
|
4
|
+
export declare const DEFAULT_CODEX_PERSONA: string;
|
|
5
|
+
/** Default DSH Core source-checkout guidance template. */
|
|
6
|
+
export declare const DEFAULT_DSH_CORE_SOURCE_PROMPT: string;
|
|
7
|
+
/** Default DSH Web runtime guidance template. */
|
|
8
|
+
export declare const DEFAULT_DSH_CORE_WEB_PROMPT: string;
|
|
3
9
|
/** Resolve the full plugin-owned prompt, preserving intentional empty overrides. */
|
|
4
10
|
export declare function resolveCodexSystemPrompt(systemPrompt?: string): string;
|
|
5
11
|
//# sourceMappingURL=prompt.d.ts.map
|
package/lib/types/prompt.js
CHANGED
|
@@ -1,40 +1,55 @@
|
|
|
1
1
|
/** Default plugin-owned Codex operating prompt. */
|
|
2
|
-
export const DEFAULT_CODEX_SYSTEM_PROMPT = String.raw `## General
|
|
3
|
-
|
|
4
|
-
- When searching for text or files, prefer using rg or rg --files respectively because rg is much faster than alternatives like grep. If rg is not available, use the next best alternative.
|
|
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
|
-
|
|
21
|
-
## Task execution
|
|
22
|
-
|
|
23
|
-
- Keep the user informed with concise progress updates and lead with the result.
|
|
24
|
-
|
|
25
|
-
## Presenting your work
|
|
26
|
-
|
|
27
|
-
- Be concise, direct, friendly, and actionable.
|
|
28
|
-
- For substantial work, explain what changed and why, then briefly note how the work was verified and what comes next.
|
|
29
|
-
- Do not dump large files into the conversation; refer to their paths.
|
|
30
|
-
- Use plain text with short sections only when they improve scanability.
|
|
31
|
-
|
|
32
|
-
## Working principles
|
|
33
|
-
|
|
34
|
-
-
|
|
35
|
-
- 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.
|
|
36
|
-
- Solve problems by thinking from first principles and at a higher level.
|
|
2
|
+
export const DEFAULT_CODEX_SYSTEM_PROMPT = String.raw `## General
|
|
3
|
+
|
|
4
|
+
- When searching for text or files, prefer using rg or rg --files respectively because rg is much faster than alternatives like grep. If rg is not available, use the next best alternative.
|
|
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
|
+
|
|
21
|
+
## Task execution
|
|
22
|
+
|
|
23
|
+
- Keep the user informed with concise progress updates and lead with the result.
|
|
24
|
+
|
|
25
|
+
## Presenting your work
|
|
26
|
+
|
|
27
|
+
- Be concise, direct, friendly, and actionable.
|
|
28
|
+
- For substantial work, explain what changed and why, then briefly note how the work was verified and what comes next.
|
|
29
|
+
- Do not dump large files into the conversation; refer to their paths.
|
|
30
|
+
- Use plain text with short sections only when they improve scanability.
|
|
31
|
+
|
|
32
|
+
## Working principles
|
|
33
|
+
|
|
34
|
+
- 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.
|
|
35
|
+
- 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.
|
|
36
|
+
- Solve problems by thinking from first principles and at a higher level.
|
|
37
37
|
`;
|
|
38
|
+
/** Default deployment Persona template used by the Codex preset. */
|
|
39
|
+
export const DEFAULT_CODEX_PERSONA = String.raw `You are Codex, a coding agent based on the {{model}} model. Your working directory is {{cwd}}.`;
|
|
40
|
+
/** Default DSH Core source-checkout guidance template. */
|
|
41
|
+
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.`;
|
|
42
|
+
/** Default DSH Web runtime guidance template. */
|
|
43
|
+
export const DEFAULT_DSH_CORE_WEB_PROMPT = [
|
|
44
|
+
'You are interacting with the user through the DeepSeek Harness Web GUI at {{webUrl}}.',
|
|
45
|
+
'When the user refers to "this page", "this GUI", or "this app" without naming another target, they mean this GUI.',
|
|
46
|
+
'The browser provides no implicit DOM, route, or screenshot context.',
|
|
47
|
+
'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.',
|
|
48
|
+
'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.',
|
|
49
|
+
'Starting another server does not update this GUI.',
|
|
50
|
+
'The apps/web Vite entry builds the shell but is not a standalone application because only dsh web injects window.__DSH_BOOT__.',
|
|
51
|
+
'Do not start a replacement server unless the user asks; if one is needed, use a managed background job and verify its exact URL.',
|
|
52
|
+
].join(' ');
|
|
38
53
|
/** Resolve the full plugin-owned prompt, preserving intentional empty overrides. */
|
|
39
54
|
export function resolveCodexSystemPrompt(systemPrompt) {
|
|
40
55
|
return systemPrompt ?? DEFAULT_CODEX_SYSTEM_PROMPT;
|
package/lib/types/settings.d.ts
CHANGED
|
@@ -7,6 +7,12 @@ export interface CodexSettings {
|
|
|
7
7
|
fast: boolean;
|
|
8
8
|
/** Optional context capacity override, in tokens. */
|
|
9
9
|
contextWindow?: number;
|
|
10
|
+
/** Deployment Persona template; supports the host's prompt variables. */
|
|
11
|
+
persona?: string;
|
|
12
|
+
/** DSH Core source-checkout guidance template. */
|
|
13
|
+
harnessSourcePrompt?: string;
|
|
14
|
+
/** DSH Core Web GUI guidance template. */
|
|
15
|
+
webSurfacePrompt?: string;
|
|
10
16
|
/** Complete plugin-owned Codex operating prompt. */
|
|
11
17
|
systemPrompt?: string;
|
|
12
18
|
/** Inject the plugin-owned Codex operating prompt. */
|
package/lib/types/settings.js
CHANGED
|
@@ -2,12 +2,15 @@
|
|
|
2
2
|
import z from '@deepseek-ai/schemastery';
|
|
3
3
|
import { settingsNamespace } from '@deepseek-ai/dsh-settings';
|
|
4
4
|
import { CODEX_CONTEXT_MAX } from "./context.js";
|
|
5
|
-
import { DEFAULT_CODEX_SYSTEM_PROMPT } from "./prompt.js";
|
|
5
|
+
import { DEFAULT_CODEX_PERSONA, DEFAULT_CODEX_SYSTEM_PROMPT, DEFAULT_DSH_CORE_SOURCE_PROMPT, DEFAULT_DSH_CORE_WEB_PROMPT, } from "./prompt.js";
|
|
6
6
|
/** Live Codex controls shared by the Web UI and agent layer. */
|
|
7
7
|
export const CODEX_SETTINGS_NAMESPACE = settingsNamespace('codex');
|
|
8
8
|
/** Default settings exposed even before a Codex session is opened. */
|
|
9
9
|
export const CODEX_SETTINGS_ENTRY = {
|
|
10
10
|
fast: false,
|
|
11
|
+
persona: DEFAULT_CODEX_PERSONA,
|
|
12
|
+
harnessSourcePrompt: DEFAULT_DSH_CORE_SOURCE_PROMPT,
|
|
13
|
+
webSurfacePrompt: DEFAULT_DSH_CORE_WEB_PROMPT,
|
|
11
14
|
systemPrompt: DEFAULT_CODEX_SYSTEM_PROMPT,
|
|
12
15
|
promptEnabled: true,
|
|
13
16
|
terminalToolsEnabled: true,
|
|
@@ -20,6 +23,9 @@ export const CODEX_SETTINGS_ENTRY = {
|
|
|
20
23
|
export const CODEX_SETTINGS_SCHEMA = z.object({
|
|
21
24
|
fast: z.boolean().default(false),
|
|
22
25
|
contextWindow: z.number().step(1).min(1).max(CODEX_CONTEXT_MAX),
|
|
26
|
+
persona: z.string().default(DEFAULT_CODEX_PERSONA),
|
|
27
|
+
harnessSourcePrompt: z.string().default(DEFAULT_DSH_CORE_SOURCE_PROMPT),
|
|
28
|
+
webSurfacePrompt: z.string().default(DEFAULT_DSH_CORE_WEB_PROMPT),
|
|
23
29
|
systemPrompt: z.string().default(DEFAULT_CODEX_SYSTEM_PROMPT),
|
|
24
30
|
promptEnabled: z.boolean().default(true),
|
|
25
31
|
terminalToolsEnabled: z.boolean().default(true),
|