@shuind/dsh-codex-harness 0.2.21 → 0.3.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.
Files changed (200) hide show
  1. package/CHANGELOG.md +185 -0
  2. package/README.md +38 -50
  3. package/RELEASE.md +61 -0
  4. package/assets/codex.svg +5 -0
  5. package/cordis.patch.yml +181 -6
  6. package/docs/preset-library.md +33 -23
  7. package/docs/tool-policy-benchmark.json +310 -0
  8. package/docs/tool-policy.md +148 -0
  9. package/lib/client.js +4774 -2416
  10. package/lib/compact-command.js +416 -0
  11. package/lib/compaction.js +141 -12
  12. package/lib/hybrid-executor.js +1196 -0
  13. package/lib/index.js +3658 -2334
  14. package/lib/preferences.js +117 -0
  15. package/lib/tool-policy.js +2422 -0
  16. package/lib/typert.js +86 -79
  17. package/lib/types/client/activity.d.ts +33 -9
  18. package/lib/types/client/activity.js +4 -3
  19. package/lib/types/client/desktop.d.ts +67 -0
  20. package/lib/types/client/desktop.js +229 -0
  21. package/lib/types/client/index.d.ts +207 -110
  22. package/lib/types/client/index.js +99 -492
  23. package/lib/types/client/policy-drafts.d.ts +25 -0
  24. package/lib/types/client/policy-drafts.js +47 -0
  25. package/lib/types/client/policy-locale.d.ts +260 -0
  26. package/lib/types/client/policy-locale.js +357 -0
  27. package/lib/types/client/preset-manager.d.ts +38 -10
  28. package/lib/types/client/preset-manager.js +235 -185
  29. package/lib/types/client/preset-requests.d.ts +12 -0
  30. package/lib/types/client/preset-requests.js +101 -0
  31. package/lib/types/client/tool-policy.d.ts +33 -0
  32. package/lib/types/client/tool-policy.js +336 -0
  33. package/lib/types/contracts/preset-editor-schema.d.ts +78 -0
  34. package/lib/types/contracts/preset-editor-schema.js +95 -0
  35. package/lib/types/{prompt.js → contracts/prompt.js} +13 -7
  36. package/lib/types/{settings.d.ts → contracts/settings.d.ts} +11 -4
  37. package/lib/types/{settings.js → contracts/settings.js} +22 -6
  38. package/lib/types/contracts/tool-policy-contract.d.ts +63 -0
  39. package/lib/types/contracts/tool-policy-contract.js +33 -0
  40. package/lib/types/contracts/ui-contracts.d.ts +92 -0
  41. package/lib/types/contracts/ui-contracts.js +83 -0
  42. package/lib/types/entries/client.d.ts +10 -0
  43. package/lib/types/entries/client.js +10 -0
  44. package/lib/types/{compact-command.d.ts → entries/compact-command.d.ts} +2 -0
  45. package/lib/types/entries/compact-command.js +176 -0
  46. package/lib/types/{compaction.d.ts → entries/compaction.d.ts} +15 -3
  47. package/lib/types/{compaction.js → entries/compaction.js} +47 -11
  48. package/lib/types/entries/hybrid-executor.d.ts +19 -0
  49. package/lib/types/entries/hybrid-executor.js +57 -0
  50. package/lib/types/entries/index.d.ts +66 -0
  51. package/lib/types/entries/index.js +192 -0
  52. package/lib/types/entries/preferences.d.ts +11 -0
  53. package/lib/types/entries/preferences.js +16 -0
  54. package/lib/types/entries/tool-policy.d.ts +97 -0
  55. package/lib/types/entries/tool-policy.js +158 -0
  56. package/lib/types/entries/typert.host.d.ts +23 -0
  57. package/lib/types/entries/typert.host.js +24 -0
  58. package/lib/types/hybrid/codex-hybrid-executor.d.ts +44 -0
  59. package/lib/types/hybrid/codex-hybrid-executor.js +257 -0
  60. package/lib/types/hybrid/hybrid-sdk.d.ts +13 -0
  61. package/lib/types/hybrid/hybrid-sdk.js +196 -0
  62. package/lib/types/hybrid/program-calls.d.ts +28 -0
  63. package/lib/types/hybrid/program-calls.js +193 -0
  64. package/lib/types/hybrid/subcall-scheduler.d.ts +90 -0
  65. package/lib/types/hybrid/subcall-scheduler.js +343 -0
  66. package/lib/types/policy/deferred-tools.d.ts +42 -0
  67. package/lib/types/policy/deferred-tools.js +264 -0
  68. package/lib/types/policy/overlay-installer.d.ts +12 -0
  69. package/lib/types/policy/overlay-installer.js +179 -0
  70. package/lib/types/policy/rule-resolver.d.ts +94 -0
  71. package/lib/types/policy/rule-resolver.js +114 -0
  72. package/lib/types/policy/tool-capabilities.d.ts +33 -0
  73. package/lib/types/policy/tool-capabilities.js +46 -0
  74. package/lib/types/{activity.d.ts → presets/activity.d.ts} +3 -5
  75. package/lib/types/{activity.js → presets/activity.js} +51 -27
  76. package/lib/types/presets/desktop-preset.d.ts +22 -0
  77. package/lib/types/presets/desktop-preset.js +43 -0
  78. package/lib/types/presets/preset-editor.d.ts +47 -0
  79. package/lib/types/presets/preset-editor.js +81 -0
  80. package/lib/types/presets/preset-prompt-catalog.d.ts +23 -0
  81. package/lib/types/presets/preset-prompt-catalog.js +215 -0
  82. package/lib/types/presets/preset-tool-catalog.d.ts +5 -0
  83. package/lib/types/presets/preset-tool-catalog.js +58 -0
  84. package/lib/types/presets/runtime-enhancements.d.ts +45 -0
  85. package/lib/types/presets/runtime-enhancements.js +349 -0
  86. package/lib/types/presets/small-window-compaction.d.ts +15 -0
  87. package/lib/types/presets/small-window-compaction.js +121 -0
  88. package/lib/types/responses/compact-checkpoint.d.ts +27 -0
  89. package/lib/types/responses/compact-checkpoint.js +257 -0
  90. package/lib/types/responses/fetch-transport.d.ts +16 -0
  91. package/lib/types/responses/fetch-transport.js +257 -0
  92. package/lib/types/responses/remote-compact.d.ts +13 -0
  93. package/lib/types/responses/remote-compact.js +319 -0
  94. package/lib/types/responses/sse-diagnostics.d.ts +9 -0
  95. package/lib/types/responses/sse-diagnostics.js +157 -0
  96. package/lib/types/responses/wire-rewrite.d.ts +35 -0
  97. package/lib/types/responses/wire-rewrite.js +237 -0
  98. package/lib/types/tools/exec-output.d.ts +58 -0
  99. package/lib/types/tools/exec-output.js +173 -0
  100. package/lib/types/tools/exec-plan-tools.d.ts +37 -0
  101. package/lib/types/tools/exec-plan-tools.js +265 -0
  102. package/lib/types/tools/exec-runner.d.ts +21 -0
  103. package/lib/types/tools/exec-runner.js +385 -0
  104. package/lib/types/tools/patch-tool.d.ts +16 -0
  105. package/lib/types/tools/patch-tool.js +258 -0
  106. package/lib/types/{patch.d.ts → tools/patch.d.ts} +1 -1
  107. package/lib/types/{patch.js → tools/patch.js} +96 -21
  108. package/locale/en.json +6 -0
  109. package/locale/hybrid-executor/en.json +6 -0
  110. package/locale/hybrid-executor/zh.json +6 -0
  111. package/locale/tool-policy/en.json +6 -0
  112. package/locale/tool-policy/zh.json +6 -0
  113. package/locale/zh.json +6 -0
  114. package/package.json +297 -299
  115. package/presets/{codex-collaboration → codex-hybrid}/agent.cordis.yml +45 -48
  116. package/presets/codex-hybrid/preset.yml +3 -0
  117. package/scripts/benchmark-tool-policy.mjs +186 -0
  118. package/scripts/build-preset.mjs +19 -0
  119. package/scripts/clean-build.mjs +11 -0
  120. package/src/client/activity.ts +83 -0
  121. package/src/client/desktop.tsx +276 -0
  122. package/src/client/index.tsx +391 -0
  123. package/src/client/policy-drafts.ts +56 -0
  124. package/src/client/policy-locale.ts +362 -0
  125. package/src/client/preset-manager.tsx +376 -0
  126. package/src/client/preset-requests.ts +113 -0
  127. package/src/client/tool-policy.tsx +402 -0
  128. package/src/contracts/preset-editor-schema.ts +110 -0
  129. package/src/contracts/prompt.ts +66 -0
  130. package/src/contracts/settings.ts +103 -0
  131. package/src/contracts/tool-policy-contract.ts +93 -0
  132. package/src/contracts/ui-contracts.ts +173 -0
  133. package/src/entries/client.tsx +14 -0
  134. package/src/entries/compact-command.ts +256 -0
  135. package/src/entries/compaction.ts +218 -0
  136. package/src/entries/hybrid-executor.ts +76 -0
  137. package/src/entries/index.ts +298 -0
  138. package/src/entries/preferences.ts +17 -0
  139. package/src/entries/tool-policy.ts +162 -0
  140. package/src/entries/typert.host.ts +29 -0
  141. package/src/hybrid/codex-hybrid-executor.ts +310 -0
  142. package/src/hybrid/hybrid-sdk.ts +217 -0
  143. package/src/hybrid/program-calls.ts +202 -0
  144. package/src/hybrid/subcall-scheduler.ts +446 -0
  145. package/src/policy/deferred-tools.ts +331 -0
  146. package/src/policy/overlay-installer.ts +191 -0
  147. package/src/policy/rule-resolver.ts +128 -0
  148. package/src/policy/tool-capabilities.ts +88 -0
  149. package/src/presets/activity.ts +146 -0
  150. package/src/presets/desktop-preset.ts +60 -0
  151. package/src/presets/preset-editor.ts +101 -0
  152. package/src/presets/preset-prompt-catalog.ts +221 -0
  153. package/src/presets/preset-tool-catalog.ts +58 -0
  154. package/src/presets/runtime-enhancements.ts +415 -0
  155. package/src/presets/small-window-compaction.ts +166 -0
  156. package/src/responses/compact-checkpoint.ts +264 -0
  157. package/src/responses/fetch-transport.ts +290 -0
  158. package/src/responses/remote-compact.ts +393 -0
  159. package/src/responses/sse-diagnostics.ts +156 -0
  160. package/src/responses/wire-rewrite.ts +261 -0
  161. package/src/tools/exec-output.ts +211 -0
  162. package/src/tools/exec-plan-tools.ts +307 -0
  163. package/src/tools/exec-runner.ts +445 -0
  164. package/src/tools/patch-tool.ts +331 -0
  165. package/src/tools/patch.ts +328 -0
  166. package/tsconfig.json +29 -0
  167. package/tsdown.config.ts +110 -0
  168. package/lib/installer.js +0 -237
  169. package/lib/invariant.js +0 -23
  170. package/lib/types/activity-types.d.ts +0 -6
  171. package/lib/types/activity-types.js +0 -3
  172. package/lib/types/client/preset-copy.d.ts +0 -42
  173. package/lib/types/client/preset-copy.js +0 -81
  174. package/lib/types/compact-command.js +0 -79
  175. package/lib/types/context.d.ts +0 -8
  176. package/lib/types/context.js +0 -14
  177. package/lib/types/exec.d.ts +0 -46
  178. package/lib/types/exec.js +0 -365
  179. package/lib/types/index.d.ts +0 -95
  180. package/lib/types/index.js +0 -738
  181. package/lib/types/installer.d.ts +0 -27
  182. package/lib/types/installer.js +0 -146
  183. package/lib/types/invariant.d.ts +0 -16
  184. package/lib/types/invariant.js +0 -22
  185. package/lib/types/preset-contract.d.ts +0 -69
  186. package/lib/types/preset-contract.js +0 -22
  187. package/lib/types/preset-editor-remote.d.ts +0 -30
  188. package/lib/types/preset-editor-remote.js +0 -37
  189. package/lib/types/preset-editor.d.ts +0 -69
  190. package/lib/types/preset-editor.js +0 -557
  191. package/lib/types/preset-templates.d.ts +0 -36
  192. package/lib/types/preset-templates.js +0 -12
  193. package/lib/types/prompt-sections.d.ts +0 -15
  194. package/lib/types/prompt-sections.js +0 -23
  195. package/lib/types/remote.d.ts +0 -40
  196. package/lib/types/remote.js +0 -683
  197. package/lib/types/typert.host.d.ts +0 -47
  198. package/lib/types/typert.host.js +0 -99
  199. package/presets/codex-collaboration/preset.yml +0 -3
  200. /package/lib/types/{prompt.d.ts → contracts/prompt.d.ts} +0 -0
@@ -0,0 +1,43 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { parseDocument } from 'yaml';
4
+ /** Keep expressions literal for the Desktop Loader, not YAML strings or eager eval. */
5
+ function readYaml(path) {
6
+ const document = parseDocument(readFileSync(path, 'utf8'), {
7
+ customTags: [{
8
+ tag: 'tag:yaml.org,2002:js',
9
+ resolve: (expression) => ({ __jsExpr: expression }),
10
+ }],
11
+ });
12
+ if (document.errors.length)
13
+ throw document.errors[0];
14
+ return document.toJS();
15
+ }
16
+ /** Convert the legacy file composition to Harness 0.2.2's declarative preset APIs. */
17
+ export function desktopCodexPreset(sourceDirectory, id = 'codex-hybrid') {
18
+ const metadata = readYaml(join(sourceDirectory, 'preset.yml'));
19
+ const plugins = readYaml(join(sourceDirectory, 'agent.cordis.yml'));
20
+ function adapt(rows) {
21
+ // Child discovery now belongs to the control plugin's root export.
22
+ return rows.filter(row => row.name !== '@deepseek-ai/dsh-tool-subagent-control/list-agents').map(row => {
23
+ if (row.name === '@deepseek-ai/dsh-workflow-worker-thread') {
24
+ row.name = '@deepseek-ai/dsh-workflow-ptc';
25
+ }
26
+ if (row.name === '@deepseek-ai/dsh-tool-subagent' && row.config && !Array.isArray(row.config)) {
27
+ const { modelSelectionSettings, backgroundMode: _backgroundMode, ...config } = row.config;
28
+ row.config = modelSelectionSettings === undefined ? config : {
29
+ ...config, modelSelection: modelSelectionSettings, modelDiscovery: modelSelectionSettings,
30
+ };
31
+ }
32
+ if (row.group && Array.isArray(row.config))
33
+ row.config = adapt(row.config);
34
+ return row;
35
+ });
36
+ }
37
+ return { ...metadata, id, plugins: adapt(plugins) };
38
+ }
39
+ /** Build the experimental asymmetric hybrid Codex preset declaration. */
40
+ export function desktopCodexHybridPreset(sourceDirectory) {
41
+ return desktopCodexPreset(sourceDirectory, 'codex-hybrid');
42
+ }
43
+ //# sourceMappingURL=desktop-preset.js.map
@@ -0,0 +1,47 @@
1
+ /** Read-only Host Remote service for inspecting declarative agent presets. */
2
+ import type { Context } from '@deepseek-ai/cordis';
3
+ import { TypertRemoteService } from '@deepseek-ai/dsh-typert-protocol';
4
+ import type { PresetCatalog, PresetDefinitionDocument, PresetPromptCatalog } from '../contracts/ui-contracts.ts';
5
+ import type { PresetToolCatalog } from '../contracts/tool-policy-contract.ts';
6
+ export type { PresetDefinitionDocument } from '../contracts/ui-contracts.ts';
7
+ export interface AgentPresetsForEditor {
8
+ readonly defaultId?: string;
9
+ list?(): Promise<Array<{
10
+ id: string;
11
+ name?: string;
12
+ description?: string;
13
+ broken?: string;
14
+ }>>;
15
+ remoteExportList?(): Promise<{
16
+ presets: Array<{
17
+ id: string;
18
+ name?: string;
19
+ description?: string;
20
+ isDefault: boolean;
21
+ broken?: string;
22
+ }>;
23
+ }>;
24
+ resolve(id: string): Promise<{
25
+ id: string;
26
+ name?: string;
27
+ description?: string;
28
+ broken?: string;
29
+ }>;
30
+ readDocument(id: string): Promise<{
31
+ content: string;
32
+ name?: string;
33
+ description?: string;
34
+ }>;
35
+ }
36
+ export declare class CodexPresetEditor extends TypertRemoteService {
37
+ static inject: string[];
38
+ private readonly agentPresets;
39
+ private readonly toolContext;
40
+ constructor(ctx: Context, _config?: undefined);
41
+ catalog(): Promise<PresetCatalog>;
42
+ tools(id: string): Promise<PresetToolCatalog>;
43
+ prompts(id: string): Promise<PresetPromptCatalog>;
44
+ read(id: string): Promise<PresetDefinitionDocument>;
45
+ }
46
+ export default CodexPresetEditor;
47
+ //# sourceMappingURL=preset-editor.d.ts.map
@@ -0,0 +1,81 @@
1
+ import { Remote, TypertRemoteService } from '@deepseek-ai/dsh-typert-protocol';
2
+ import { PRESET_EDITOR_SERVICE } from "../contracts/preset-editor-schema.js";
3
+ import { readPresetPromptCatalog } from "./preset-prompt-catalog.js";
4
+ import { readPresetToolCatalog } from "./preset-tool-catalog.js";
5
+ export class CodexPresetEditor extends TypertRemoteService {
6
+ static inject = ['agentPresets'];
7
+ agentPresets;
8
+ toolContext;
9
+ constructor(ctx, _config) {
10
+ super(ctx, PRESET_EDITOR_SERVICE);
11
+ this.toolContext = ctx;
12
+ this.agentPresets = ctx.get('agentPresets');
13
+ }
14
+ async catalog() {
15
+ if (this.agentPresets.remoteExportList !== undefined) {
16
+ const roster = await this.agentPresets.remoteExportList();
17
+ const presets = roster.presets
18
+ .filter(row => row.broken === undefined)
19
+ .map(row => ({
20
+ id: row.id,
21
+ name: row.name || row.id,
22
+ description: row.description ?? '',
23
+ isDefault: row.isDefault,
24
+ }));
25
+ return { presets, excludedCount: roster.presets.length - presets.length };
26
+ }
27
+ if (this.agentPresets.list !== undefined) {
28
+ const rows = await this.agentPresets.list();
29
+ const presets = rows
30
+ .filter(row => row.broken === undefined)
31
+ .map(row => ({
32
+ id: row.id,
33
+ name: row.name || row.id,
34
+ description: row.description ?? '',
35
+ isDefault: row.id === this.agentPresets.defaultId,
36
+ }));
37
+ return { presets, excludedCount: rows.length - presets.length };
38
+ }
39
+ throw new Error('preset-catalog-unavailable');
40
+ }
41
+ async tools(id) {
42
+ return readPresetToolCatalog(this.toolContext, id);
43
+ }
44
+ async prompts(id) {
45
+ return readPresetPromptCatalog(this.toolContext, id);
46
+ }
47
+ async read(id) {
48
+ if (typeof id !== 'string' || !id.trim() || id.length > 256)
49
+ throw new Error('invalid-preset-id');
50
+ const resolved = await this.agentPresets.resolve(id);
51
+ if (resolved.broken !== undefined)
52
+ throw new Error('invalid-preset');
53
+ const doc = await this.agentPresets.readDocument(id);
54
+ return {
55
+ id,
56
+ name: doc.name || resolved.name || id,
57
+ description: doc.description ?? resolved.description ?? '',
58
+ composition: doc.content,
59
+ };
60
+ }
61
+ }
62
+ // Same decorator registration as the host, consumable by the Vitest transform.
63
+ function markRemoteMethod(methodName) {
64
+ const descriptor = Object.getOwnPropertyDescriptor(CodexPresetEditor.prototype, methodName);
65
+ const initializers = [];
66
+ const decorator = Remote(methodName);
67
+ decorator(descriptor.value, {
68
+ kind: 'method',
69
+ name: methodName,
70
+ static: false,
71
+ private: false,
72
+ addInitializer: initializer => { initializers.push(initializer); },
73
+ });
74
+ const receiver = Object.create(CodexPresetEditor.prototype);
75
+ for (const initializer of initializers)
76
+ initializer.call(receiver);
77
+ }
78
+ for (const method of ['catalog', 'tools', 'prompts', 'read'])
79
+ markRemoteMethod(method);
80
+ export default CodexPresetEditor;
81
+ //# sourceMappingURL=preset-editor.js.map
@@ -0,0 +1,23 @@
1
+ import type { Context } from '@deepseek-ai/cordis';
2
+ import type { ScopeKey } from '@deepseek-ai/dsh-scope';
3
+ import type { PromptSection } from '@deepseek-ai/dsh-system-prompt';
4
+ import type { PresetPromptCatalog, PresetPromptName, PresetPromptOverride } from '../contracts/ui-contracts.ts';
5
+ export interface PresetPromptProbe {
6
+ readonly catalog: PresetPromptCatalog;
7
+ readonly scope: ScopeKey;
8
+ readonly modules: string;
9
+ readonly definitions: ReadonlyMap<PresetPromptName, PromptSection>;
10
+ }
11
+ export interface PreparedPromptOverride {
12
+ readonly scope: ScopeKey;
13
+ readonly modules: string;
14
+ readonly sections: readonly PromptSection[];
15
+ }
16
+ /** The opaque scope identity is retained only for runtime revision validation, not sent over RPC. */
17
+ export declare function probePresetPrompts(ctx: Context, preset: string, expectedScope?: ScopeKey): Promise<PresetPromptProbe>;
18
+ /** Cached variant keyed by live scope identity, active modules, and document content. */
19
+ export declare function probePresetPromptsCached(ctx: Context, preset: string, expectedScope?: ScopeKey): Promise<PresetPromptProbe>;
20
+ export declare function readPresetPromptCatalog(ctx: Context, preset: string): Promise<PresetPromptCatalog>;
21
+ export declare function preparePromptOverrides(probe: PresetPromptProbe, overrides: readonly PresetPromptOverride[]): PreparedPromptOverride;
22
+ export declare function matchesPromptRevision(ctx: Context, preset: string, prepared: PreparedPromptOverride): boolean;
23
+ //# sourceMappingURL=preset-prompt-catalog.d.ts.map
@@ -0,0 +1,215 @@
1
+ /** Public, read-only preset prompt discovery. No private registry, Agent, or JS/YAML evaluation. */
2
+ import { randomUUID } from 'node:crypto';
3
+ import { createScope } from '@deepseek-ai/dsh-scope';
4
+ import { PERSONA_PREFIX_SECTION, PERSONA_SUFFIX_SECTION } from '@deepseek-ai/dsh-system-prompt';
5
+ import { isMap, isScalar, isSeq, parseDocument, YAMLMap } from 'yaml';
6
+ function literal(map, key) {
7
+ const node = map.get(key, true);
8
+ return isScalar(node) && !node.tag ? node.value : undefined;
9
+ }
10
+ /** Native Persona's public source owns these exact names/placements/complete semantics. */
11
+ function candidates(content, placement) {
12
+ const doc = parseDocument(content, { strict: true, uniqueKeys: true, logLevel: 'silent' });
13
+ if (doc.errors.length || !isSeq(doc.contents))
14
+ throw new Error('invalid-preset-prompt-declaration');
15
+ const found = [];
16
+ const readonly = [];
17
+ function visit(rows, parent = '', conditionalParent = false, isolatedParent = false) {
18
+ if (!isSeq(rows))
19
+ return;
20
+ for (const [index, row] of rows.items.entries()) {
21
+ if (!isMap(row) || literal(row, 'disabled') === true)
22
+ continue;
23
+ const module = literal(row, 'name');
24
+ const path = `${parent}/${String(literal(row, 'id') ?? index)}`;
25
+ const conditionalRow = conditionalParent || row.has('disabled') && literal(row, 'disabled') === undefined;
26
+ const isolation = row.get('isolate', true);
27
+ const isolated = isolatedParent || row.has('isolate') && (!isMap(isolation) || isolation.has('systemPrompt'));
28
+ let config = row.get('config', true);
29
+ if (isSeq(config)) {
30
+ visit(config, path, conditionalRow, isolated);
31
+ continue;
32
+ }
33
+ if (config === undefined && module === '@shuind/dsh-codex-harness')
34
+ config = new YAMLMap();
35
+ if (typeof module !== 'string' || !isMap(config))
36
+ continue;
37
+ if (module === '@deepseek-ai/dsh-persona') {
38
+ const completeNode = config.get('complete', true);
39
+ const complete = literal(config, 'complete');
40
+ const uncertain = conditionalRow || completeNode !== undefined && typeof complete !== 'boolean';
41
+ for (const [key, name, order, label] of [
42
+ ['prefix', PERSONA_PREFIX_SECTION, placement('DEPLOYMENT_PERSONA_PREFIX'), 'Persona'],
43
+ ['suffix', PERSONA_SUFFIX_SECTION, placement('DEPLOYMENT_PERSONA_SUFFIX'), 'Persona · suffix'],
44
+ ]) {
45
+ const text = literal(config, key);
46
+ const missingSuffix = key === 'suffix' && !config.has(key);
47
+ // Native Persona validates prefix/suffix to strings at mount, then
48
+ // registers static text. A !!js declaration is never evaluated here;
49
+ // its actual registered text is read by assemble and marker-verified.
50
+ const reason = isolated ? 'isolated-prompt-registry' : uncertain ? 'dynamic-declaration' : undefined;
51
+ found.push({ name, label, module, order, complete: key === 'prefix' && complete === true, interpolate: true,
52
+ ...(typeof text === 'string' ? { literal: text } : missingSuffix ? { literal: '' } : {}),
53
+ ...(reason === undefined ? {} : { reason }) });
54
+ }
55
+ }
56
+ else if (module === '@shuind/dsh-codex-harness' && literal(config, 'codexCore') !== false) {
57
+ found.push({ name: 'codex:base', label: 'Codex 操作提示词', module, order: 10, complete: false, interpolate: true,
58
+ ...(isolated ? { reason: 'isolated-prompt-registry' } : conditionalRow || config.has('codexCore') && literal(config, 'codexCore') === undefined ? { reason: 'dynamic-declaration' } : {}) });
59
+ }
60
+ else {
61
+ // Unknown field-to-section mappings are not editable just because their
62
+ // spelling resembles a prompt. Never return a !!js expression as prose.
63
+ for (const key of ['prefix', 'suffix', 'text', 'section', 'prompt', 'systemPrompt', 'instructions']) {
64
+ if (!config.has(key) || module === '@deepseek-ai/dsh-plan-mode')
65
+ continue;
66
+ const text = literal(config, key);
67
+ readonly.push({ name: `declaration:${path}:${key}`, label: `${module} · ${key}`,
68
+ text: typeof text === 'string' ? text : '', editable: false,
69
+ reason: typeof text === 'string' ? 'unknown-section-contract' : 'dynamic-declaration' });
70
+ }
71
+ }
72
+ }
73
+ }
74
+ visit(doc.contents);
75
+ return { found, readonly };
76
+ }
77
+ function moduleSignature(rows) {
78
+ return JSON.stringify(rows.map(row => [row.moduleName, row.baseUrl ?? '', row.useHostBase]));
79
+ }
80
+ const probeCache = new WeakMap();
81
+ async function runProbePresetPrompts(ctx, preset, expectedScope, useCache) {
82
+ if (typeof preset !== 'string' || !preset.trim() || preset.length > 256)
83
+ throw new Error('invalid-preset-id');
84
+ const registry = ctx.get('agentPresets');
85
+ const prompt = ctx.get('systemPrompt');
86
+ if (registry === undefined || prompt === undefined || typeof registry.acquireScope !== 'function'
87
+ || typeof registry.readDocument !== 'function' || typeof registry.inspectCompositions !== 'function') {
88
+ throw new Error('preset-prompt-catalog-unavailable');
89
+ }
90
+ const document = await registry.readDocument(preset);
91
+ const lease = await registry.acquireScope(preset);
92
+ let view;
93
+ try {
94
+ if (expectedScope !== undefined && lease.key !== expectedScope)
95
+ throw new Error('preset-prompt-revision-mismatch');
96
+ const key = {};
97
+ view = createScope(ctx, key, { parent: lease.key });
98
+ const inspection = registry.inspectCompositions(view.ctx);
99
+ if (inspection.length !== 1 || inspection[0]?.id !== preset)
100
+ throw new Error('preset-prompt-revision-unavailable');
101
+ const modules = moduleSignature(inspection[0].modules);
102
+ const cacheKey = `${preset}\0${modules}\0${document.content}`;
103
+ if (useCache) {
104
+ const cached = probeCache.get(lease.key)?.get(cacheKey);
105
+ if (cached !== undefined)
106
+ return cached;
107
+ }
108
+ const active = new Set(inspection[0].modules.map(row => row.moduleName));
109
+ const declared = candidates(document.content, name => prompt.getSectionOrder(name));
110
+ const definitions = new Map();
111
+ const sections = [];
112
+ // Show the actual effective original, including legacy own-plugin rewrites.
113
+ // Only marker validation suppresses those rewrites; no model runs here.
114
+ let baseline;
115
+ try {
116
+ baseline = await prompt.assemble({ scope: key });
117
+ }
118
+ catch {
119
+ return { scope: lease.key, modules, definitions, catalog: { preset, sections: [
120
+ ...declared.found.map(row => ({ name: row.name, label: row.label, text: row.literal ?? '', editable: false, reason: 'assembly-unavailable' })),
121
+ ...declared.readonly,
122
+ ].slice(0, 200) } };
123
+ }
124
+ const seen = new Set();
125
+ for (const row of declared.found) {
126
+ if (seen.has(row.name))
127
+ continue;
128
+ seen.add(row.name);
129
+ const actual = baseline.sections.find(section => section.name === row.name);
130
+ let reason = row.reason
131
+ ?? (!active.has(row.module) ? 'inactive-contribution' : undefined)
132
+ ?? (declared.found.filter(candidate => candidate.name === row.name).length !== 1 ? 'ambiguous-contribution' : undefined)
133
+ ?? (actual === undefined ? 'not-effective-or-complete-suppressed' : undefined);
134
+ if (reason === undefined && row.complete && (baseline.sections.length !== 1 || baseline.sections[0]?.name !== row.name))
135
+ reason = 'complete-contract-mismatch';
136
+ if (reason === undefined) {
137
+ const marker = `preset-prompt-probe:${randomUUID()}`;
138
+ const undo = view.ctx.get('systemPrompt').section({ name: row.name, order: row.order, complete: row.complete,
139
+ interpolate: row.interpolate, text: marker });
140
+ try {
141
+ const probed = await prompt.assemble({ scope: key, codexPresetPromptProbe: true });
142
+ if (probed.sections.find(section => section.name === row.name)?.text !== marker
143
+ || JSON.stringify(probed.sections.map(section => section.name)) !== JSON.stringify(baseline.sections.map(section => section.name))
144
+ || row.complete && (probed.sections.length !== 1 || probed.sections[0]?.name !== row.name))
145
+ reason = 'not-directly-overridable';
146
+ }
147
+ catch {
148
+ reason = 'not-directly-overridable';
149
+ }
150
+ finally {
151
+ undo();
152
+ }
153
+ }
154
+ const text = actual?.text ?? row.literal ?? '';
155
+ if (text.length > 1_000_000)
156
+ 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)
161
+ definitions.set(row.name, { name: row.name, order: row.order, complete: row.complete,
162
+ interpolate: row.interpolate, text });
163
+ }
164
+ for (const row of baseline.sections) {
165
+ if (!seen.has(row.name))
166
+ sections.push({ name: row.name, label: row.name, text: row.text.slice(0, 1_000_000), editable: false, reason: 'unknown-or-host-owned-section' });
167
+ }
168
+ sections.push(...declared.readonly);
169
+ if ((await registry.readDocument(preset)).content !== document.content)
170
+ throw new Error('preset-prompt-revision-mismatch');
171
+ const probe = { scope: lease.key, modules, definitions, catalog: { preset, sections: sections.slice(0, 200) } };
172
+ if (useCache) {
173
+ let byKey = probeCache.get(lease.key);
174
+ if (byKey === undefined) {
175
+ byKey = new Map();
176
+ probeCache.set(lease.key, byKey);
177
+ }
178
+ byKey.set(cacheKey, probe);
179
+ }
180
+ return probe;
181
+ }
182
+ finally {
183
+ try {
184
+ await view?.dispose();
185
+ }
186
+ finally {
187
+ await lease[Symbol.asyncDispose]();
188
+ }
189
+ }
190
+ }
191
+ /** The opaque scope identity is retained only for runtime revision validation, not sent over RPC. */
192
+ export async function probePresetPrompts(ctx, preset, expectedScope) {
193
+ return runProbePresetPrompts(ctx, preset, expectedScope, false);
194
+ }
195
+ /** Cached variant keyed by live scope identity, active modules, and document content. */
196
+ export async function probePresetPromptsCached(ctx, preset, expectedScope) {
197
+ return runProbePresetPrompts(ctx, preset, expectedScope, true);
198
+ }
199
+ export async function readPresetPromptCatalog(ctx, preset) {
200
+ return (await probePresetPrompts(ctx, preset)).catalog;
201
+ }
202
+ export function preparePromptOverrides(probe, overrides) {
203
+ const sections = overrides.map(override => {
204
+ const original = probe.definitions.get(override.name);
205
+ if (original === undefined)
206
+ throw new Error(`unsupported-preset-prompt-override: ${override.name}`);
207
+ return { ...original, text: override.text };
208
+ });
209
+ return { scope: probe.scope, modules: probe.modules, sections };
210
+ }
211
+ export function matchesPromptRevision(ctx, preset, prepared) {
212
+ const inspection = ctx.get('agentPresets')?.inspectCompositions(ctx);
213
+ return inspection?.length === 1 && inspection[0]?.id === preset && moduleSignature(inspection[0].modules) === prepared.modules;
214
+ }
215
+ //# sourceMappingURL=preset-prompt-catalog.js.map
@@ -0,0 +1,5 @@
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 { PresetToolCatalog } from '../contracts/tool-policy-contract.ts';
4
+ export declare function readPresetToolCatalog(ctx: Context, preset: string): Promise<PresetToolCatalog>;
5
+ //# sourceMappingURL=preset-tool-catalog.d.ts.map
@@ -0,0 +1,58 @@
1
+ import { createScope } from '@deepseek-ai/dsh-scope';
2
+ import { codexToolMetadata, readLegacyCapabilities } from "../policy/tool-capabilities.js";
3
+ import { readDefaultDeferredTools, readDefaultHiddenTools } from "../policy/deferred-tools.js";
4
+ export async function readPresetToolCatalog(ctx, preset) {
5
+ if (typeof preset !== 'string' || !preset.trim() || preset.length > 256)
6
+ throw new Error('invalid-preset-id');
7
+ const registry = ctx.get('agentPresets');
8
+ const tools = ctx.get('tools');
9
+ if (registry === undefined || typeof registry.acquireScope !== 'function' || tools === undefined) {
10
+ throw new Error('preset-tool-catalog-unavailable');
11
+ }
12
+ const lease = await registry.acquireScope(preset);
13
+ let view;
14
+ try {
15
+ // A child view applies inherited masks exactly as an Agent would, but has no
16
+ // Agent driver, session, model selection, or initialization callbacks.
17
+ const key = {};
18
+ view = createScope(ctx, key, { parent: lease.key });
19
+ const defaultHidden = readDefaultHiddenTools(view.ctx, key);
20
+ const definitions = tools.definitions(key).filter(tool => !defaultHidden?.has(tool.name));
21
+ const names = new Set(definitions.map(tool => tool.name));
22
+ const defaultDeferred = readDefaultDeferredTools(view.ctx, key);
23
+ return {
24
+ preset,
25
+ registeredOnly: true,
26
+ legacyCapabilities: readLegacyCapabilities(ctx),
27
+ tools: definitions.map(definition => {
28
+ const conditional = tools.executable(definition.name, key) !== definition;
29
+ const replacements = [];
30
+ const action = definition.name === 'bash' || definition.name === 'pwsh' ? 'codex-exec'
31
+ : definition.name === 'todo_write' ? 'codex-plan'
32
+ : definition.name === 'edit' || definition.name === 'write' ? 'codex-patch' : undefined;
33
+ if (action !== undefined) {
34
+ const targets = action === 'codex-exec' ? ['exec_command', 'write_stdin']
35
+ : action === 'codex-plan' ? ['update_plan']
36
+ : ['apply_patch'];
37
+ const reason = conditional ? 'conditional'
38
+ : targets.some(target => names.has(target)) ? 'target-exists' : 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
+ ...(defaultDeferred?.has(definition.name) ? { defaultDeferred: true } : {}),
45
+ ...(codexTool === undefined ? {} : { codexTool }) };
46
+ }).sort((a, b) => a.name.localeCompare(b.name, 'en')),
47
+ };
48
+ }
49
+ finally {
50
+ try {
51
+ await view?.dispose();
52
+ }
53
+ finally {
54
+ await lease[Symbol.asyncDispose]();
55
+ }
56
+ }
57
+ }
58
+ //# sourceMappingURL=preset-tool-catalog.js.map
@@ -0,0 +1,45 @@
1
+ /** Host runtime enhancements: GPT model enrichment, context-window projection, and prompt templates. */
2
+ import type { Context } from '@deepseek-ai/cordis';
3
+ import type { LlmCallConfig } from '@deepseek-ai/dsh-llm';
4
+ import type { Session } from '@deepseek-ai/dsh-session';
5
+ import type { PromptAssembly } from '@deepseek-ai/dsh-system-prompt';
6
+ import type { CodexSettings } from '../contracts/settings.ts';
7
+ /** Add the preset editor when DSH's optional user-preset service is available. */
8
+ export declare function installPresetEditor(ctx: Context): void;
9
+ /** Codex request envelope with the plugin's provider-facing service-tier field. */
10
+ export interface CodexRequestConfig extends LlmCallConfig {
11
+ /** Codex request context capacity override, retained for older DSH hosts. */
12
+ contextWindow?: number;
13
+ /** Provider-facing service tier, for example Responses `priority`. */
14
+ serviceTier?: string;
15
+ }
16
+ export interface CodexModelProfile {
17
+ id: string;
18
+ input?: string[];
19
+ reasoningEfforts?: false | Record<string, string | null>;
20
+ [key: string]: unknown;
21
+ }
22
+ /** Add Codex defaults without overwriting explicit user capabilities. */
23
+ export declare function enrichCodexModel(model: CodexModelProfile): CodexModelProfile;
24
+ /** Keep newly edited GPT model entries enriched while Codex mode is mounted. */
25
+ export declare function watchConfiguredGptModels(ctx: Context): void;
26
+ type CodexPromptPresentation = Pick<PromptAssembly, 'sections' | 'contexts' | 'variables'>;
27
+ export declare function syncCodexContextWindow(session: Session, contextWindow: number | undefined): void;
28
+ /** Keep open Codex Connect turns aligned with per-model `llm-openai-codex` overrides. */
29
+ export declare function syncOpenAICodexTurnContext(ctx: Context, session: Session): void;
30
+ /** Keep the official context meter synchronized with a live Codex override. */
31
+ export declare function installCodexContextProjection(ctx: Context, current: () => CodexSettings): void;
32
+ /** Apply the live Codex controls to one agent request without leaking them to other routes. */
33
+ export declare function applyCodexRequestSettings(request: CodexRequestConfig, settings: CodexSettings): CodexRequestConfig;
34
+ /** Put the agent persona first and omit the generic Harness identity opener. */
35
+ export declare function normalizeCodexPromptAssembly<T extends CodexPromptPresentation>(assembly: T): T;
36
+ /** Apply Persona/DSH Core prompt overrides and optional ordering normalization. */
37
+ export declare function applyCodexPresentationSettings<T extends CodexPromptPresentation>(assembly: T, settings: CodexSettings, protectedNames?: ReadonlySet<string>): T;
38
+ /** Build the complete plugin-owned prompt, preserving an intentional empty value. */
39
+ export declare function buildCodexSystemPrompt(config?: {
40
+ systemPrompt?: string;
41
+ }): string;
42
+ /** Explicit preset instructions win without changing shared tools or permissions. */
43
+ export declare function withPresetPrompt(settings: CodexSettings, presetPrompt: string | undefined): CodexSettings;
44
+ export {};
45
+ //# sourceMappingURL=runtime-enhancements.d.ts.map