@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
@@ -1,6 +1,6 @@
1
- /** Shared host-side Codex settings contract. */
1
+ /** Shared host-side Codex settings contract, Host reader, and GPT route matcher. */
2
2
  import z from '@deepseek-ai/schemastery';
3
- import { CODEX_CONTEXT_MAX } from "./context.js";
3
+ import { CODEX_CONTEXT_MAX } from "./ui-contracts.js";
4
4
  import { DEFAULT_CODEX_PERSONA, DEFAULT_CODEX_SYSTEM_PROMPT, DEFAULT_DSH_CORE_SOURCE_PROMPT, DEFAULT_DSH_CORE_WEB_PROMPT, } from "./prompt.js";
5
5
  /** Live Codex controls shared by the Web UI and agent layer. */
6
6
  export const CODEX_SETTINGS_NAMESPACE = 'codex';
@@ -8,6 +8,7 @@ export const CODEX_SETTINGS_NAMESPACE = 'codex';
8
8
  export const CODEX_SETTINGS_ENTRY = {
9
9
  fast: false,
10
10
  fastModeControlEnabled: true,
11
+ contextWindowControlEnabled: true,
11
12
  persona: DEFAULT_CODEX_PERSONA,
12
13
  harnessSourcePrompt: DEFAULT_DSH_CORE_SOURCE_PROMPT,
13
14
  webSurfacePrompt: DEFAULT_DSH_CORE_WEB_PROMPT,
@@ -23,17 +24,32 @@ export const CODEX_SETTINGS_ENTRY = {
23
24
  export const CODEX_SETTINGS_SCHEMA = z.object({
24
25
  fast: z.boolean().default(false),
25
26
  fastModeControlEnabled: z.boolean().default(true),
26
- contextWindow: z.number().step(1).min(1).max(CODEX_CONTEXT_MAX),
27
+ contextWindowControlEnabled: z.boolean().default(true),
28
+ contextWindow: z.number().step(1).min(1).max(CODEX_CONTEXT_MAX).hidden(),
27
29
  persona: z.string().default(DEFAULT_CODEX_PERSONA),
28
30
  harnessSourcePrompt: z.string().default(DEFAULT_DSH_CORE_SOURCE_PROMPT),
29
31
  webSurfacePrompt: z.string().default(DEFAULT_DSH_CORE_WEB_PROMPT),
30
32
  systemPrompt: z.string().default(DEFAULT_CODEX_SYSTEM_PROMPT),
31
33
  promptEnabled: z.boolean().default(true),
32
- terminalToolsEnabled: z.boolean().default(true),
33
- patchToolEnabled: z.boolean().default(true),
34
- planToolEnabled: z.boolean().default(true),
34
+ terminalToolsEnabled: z.boolean().default(true).hidden(),
35
+ patchToolEnabled: z.boolean().default(true).hidden(),
36
+ planToolEnabled: z.boolean().default(true).hidden(),
35
37
  hostedWebSearchEnabled: z.boolean().default(true),
36
38
  remoteCompactionEnabled: z.boolean().default(true),
37
39
  activityIndicatorEnabled: z.boolean().default(true),
38
40
  });
41
+ /** Host-only reads: never expose the unredacted provider configuration to clients. */
42
+ export function readHostSettings(ctx, namespace) {
43
+ if (namespace === 'codex') {
44
+ const preferences = ctx.get('codexPreferences');
45
+ if (preferences !== undefined)
46
+ return preferences.current();
47
+ }
48
+ const settings = ctx.get('settings');
49
+ return settings?.describe?.().find(row => row.ns === namespace)?.value;
50
+ }
51
+ /** Match GPT / ChatGPT model ids that consume Codex wire & capacity extensions. */
52
+ export function isGptModel(model) {
53
+ return typeof model === 'string' && /(?:^|\/)(?:gpt|chatgpt)(?:[-_.]|\d|$)/i.test(model);
54
+ }
39
55
  //# sourceMappingURL=settings.js.map
@@ -0,0 +1,63 @@
1
+ /** Client-safe tool choices. The concrete adapters remain Host-owned. */
2
+ import type { PresetPromptOverride } from './ui-contracts.ts';
3
+ export { PRESET_PROMPT_NAMES } from './ui-contracts.ts';
4
+ export type { PresetPromptName, PresetPromptOverride, PresetPromptEntry, PresetPromptCatalog } from './ui-contracts.ts';
5
+ export type ToolAction = 'keep' | 'hide' | 'defer' | 'codex-exec' | 'codex-plan' | 'codex-patch';
6
+ export type ReplacementAction = Extract<ToolAction, 'codex-exec' | 'codex-plan' | 'codex-patch'>;
7
+ export type CodexCapability = 'terminalToolsEnabled' | 'planToolEnabled' | 'patchToolEnabled';
8
+ export type LegacyCapabilities = Partial<Record<CodexCapability, boolean>>;
9
+ /** Ownership metadata, not a promise that `keep` admits a locally disabled tool. */
10
+ export interface CodexToolMetadata {
11
+ readonly capability: CodexCapability;
12
+ readonly presetEnabled: boolean;
13
+ /** An explicit old per-preset boolean already overrode the shared baseline. */
14
+ readonly presetOverridesLegacy?: boolean;
15
+ }
16
+ export interface ToolActionContext {
17
+ readonly legacyCapabilities?: LegacyCapabilities;
18
+ readonly codexTool?: CodexToolMetadata;
19
+ readonly defaultDeferred?: boolean;
20
+ }
21
+ export interface ToolActionRule {
22
+ readonly name: string;
23
+ readonly action: ToolAction;
24
+ }
25
+ export interface ToolPolicyRule {
26
+ readonly preset: string;
27
+ readonly allow?: readonly string[];
28
+ readonly deny?: readonly string[];
29
+ /** Legacy category defaults; new UI rules explicitly set replaceShell/replacePlan to false. */
30
+ readonly replaceShell?: boolean;
31
+ readonly replacePlan?: boolean;
32
+ readonly replacePatch?: boolean;
33
+ /** Explicit per-source choices override the legacy masks and category defaults. */
34
+ readonly tools?: readonly ToolActionRule[];
35
+ /** Exact reviewed section replacements, scoped to future Agents of this preset. */
36
+ readonly promptOverrides?: readonly PresetPromptOverride[];
37
+ }
38
+ export interface PresetToolReplacement {
39
+ readonly action: ReplacementAction;
40
+ readonly tools: readonly string[];
41
+ readonly available: boolean;
42
+ readonly reason?: 'conditional' | 'target-exists';
43
+ }
44
+ export interface PresetToolEntry {
45
+ readonly name: string;
46
+ readonly description: string;
47
+ readonly conditional: boolean;
48
+ readonly defaultDeferred?: boolean;
49
+ readonly replacements: readonly PresetToolReplacement[];
50
+ readonly codexTool?: CodexToolMetadata;
51
+ }
52
+ export interface PresetToolCatalog {
53
+ readonly preset: string;
54
+ /** Registration snapshot, not admission for a particular Agent/model step. */
55
+ readonly registeredOnly: true;
56
+ readonly tools: readonly PresetToolEntry[];
57
+ readonly legacyCapabilities?: LegacyCapabilities;
58
+ }
59
+ /** Legacy configuration remains a baseline, never a live second veto of an explicit choice. */
60
+ export declare function legacyToolAction(rule: ToolPolicyRule | undefined, name: string, context?: ToolActionContext): ToolAction;
61
+ /** Policy action only: `keep` still respects the original preset's local enablement. */
62
+ export declare function effectiveToolAction(rule: ToolPolicyRule | undefined, name: string, context?: ToolActionContext): ToolAction;
63
+ //# sourceMappingURL=tool-policy-contract.d.ts.map
@@ -0,0 +1,33 @@
1
+ export { PRESET_PROMPT_NAMES } from "./ui-contracts.js";
2
+ /** Legacy configuration remains a baseline, never a live second veto of an explicit choice. */
3
+ export function legacyToolAction(rule, name, context = {}) {
4
+ let action = 'keep';
5
+ if (rule !== undefined) {
6
+ if ((rule.allow !== undefined && !rule.allow.includes(name)) || rule.deny?.includes(name))
7
+ return 'hide';
8
+ if ((name === 'bash' || name === 'pwsh') && rule.replaceShell !== false)
9
+ action = 'codex-exec';
10
+ if (name === 'todo_write' && rule.replacePlan !== false)
11
+ action = 'codex-plan';
12
+ if ((name === 'edit' || name === 'write') && rule.replacePatch === true)
13
+ action = 'codex-patch';
14
+ }
15
+ if (action === 'keep' && context.defaultDeferred === true)
16
+ action = 'defer';
17
+ const capability = context.codexTool?.capability
18
+ ?? (action === 'codex-exec' ? 'terminalToolsEnabled'
19
+ : action === 'codex-plan' ? 'planToolEnabled'
20
+ : action === 'codex-patch' ? 'patchToolEnabled'
21
+ : undefined);
22
+ // Only owned definitions and chosen Codex adapters consume the legacy baseline.
23
+ // A third-party tool with the same name does not become a Codex capability.
24
+ const presetOverride = context.codexTool?.presetOverridesLegacy === true && context.codexTool.presetEnabled;
25
+ if (!presetOverride && capability !== undefined && context.legacyCapabilities?.[capability] === false)
26
+ return 'hide';
27
+ return action;
28
+ }
29
+ /** Policy action only: `keep` still respects the original preset's local enablement. */
30
+ export function effectiveToolAction(rule, name, context = {}) {
31
+ return rule?.tools?.find(tool => tool.name === name)?.action ?? legacyToolAction(rule, name, context);
32
+ }
33
+ //# sourceMappingURL=tool-policy-contract.js.map
@@ -0,0 +1,92 @@
1
+ /** Browser-safe shared constants, activity shapes, and read-only preset contracts. */
2
+ /** User-selectable Codex context controls use whole K-token units. */
3
+ export declare const CODEX_CONTEXT_UNIT = 1000;
4
+ export declare const CODEX_CONTEXT_MIN = 16000;
5
+ export declare const CODEX_CONTEXT_MAX = 1000000;
6
+ export declare const OPENAI_CODEX_PROVIDER = "openai-codex";
7
+ export declare const OPENAI_CODEX_SETTINGS_NAMESPACE = "llm-openai-codex";
8
+ export declare const OPENAI_CODEX_MODEL_CATALOG_PATH = "/plugins/dsh-codex-connect/models";
9
+ export interface ContextWindowBounds {
10
+ readonly defaultTokens?: number;
11
+ readonly maxTokens: number;
12
+ }
13
+ export declare const OPENAI_CODEX_MODEL_LIMITS: Readonly<Record<string, {
14
+ readonly defaultTokens: number;
15
+ readonly maxTokens: number;
16
+ }>>;
17
+ export declare function resolveContextWindowBounds(provider: string | undefined, model: string | undefined, dynamicCatalog?: Readonly<Record<string, {
18
+ readonly defaultTokens: number;
19
+ readonly maxTokens: number;
20
+ }>>): ContextWindowBounds;
21
+ export declare function formatCompactTokens(tokens: number): string;
22
+ export declare function contextPresetsForBounds(bounds: ContextWindowBounds): number[];
23
+ export declare function parseCustomContextInput(raw: string, maxTokens: number): number | undefined;
24
+ export declare function nextOpenAICodexOverrides(currentValue: Readonly<Record<string, unknown>> | undefined, baseValue: Readonly<Record<string, unknown>> | undefined, modelId: string, tokens: number | undefined): Record<string, number | null> | undefined;
25
+ /** Pure client/host-shared type for the Codex activity projection value. */
26
+ export type CodexActivity = {
27
+ activity: 'compaction' | 'requesting-model' | 'model-reply';
28
+ startedAt: number;
29
+ };
30
+ /** Client-safe read-only preset catalog and definition types for Harness 0.2.2+. */
31
+ export interface PresetCatalogRow {
32
+ readonly id: string;
33
+ readonly name: string;
34
+ readonly description: string;
35
+ readonly isDefault: boolean;
36
+ }
37
+ export interface PresetCatalog {
38
+ readonly presets: readonly PresetCatalogRow[];
39
+ readonly excludedCount: number;
40
+ }
41
+ export interface PresetDefinitionDocument {
42
+ readonly id: string;
43
+ readonly name: string;
44
+ readonly description: string;
45
+ readonly composition: string;
46
+ }
47
+ /** Client-safe current-preset prompt catalog; editable targets have reviewed native contracts. */
48
+ export declare const PRESET_PROMPT_NAMES: readonly ["deployment:persona-prefix", "deployment:persona-suffix", "codex:base"];
49
+ export type PresetPromptName = typeof PRESET_PROMPT_NAMES[number];
50
+ export interface PresetPromptOverride {
51
+ readonly name: PresetPromptName;
52
+ readonly text: string;
53
+ }
54
+ export interface PresetPromptEntry {
55
+ readonly name: string;
56
+ readonly label: string;
57
+ readonly text: string;
58
+ readonly editable: boolean;
59
+ readonly order?: number;
60
+ readonly complete?: boolean;
61
+ readonly interpolate?: boolean;
62
+ readonly reason?: string;
63
+ }
64
+ export interface ModelDirectorySnapshot {
65
+ readonly status?: string;
66
+ readonly current?: {
67
+ readonly provider?: string;
68
+ readonly model?: string;
69
+ } | undefined;
70
+ }
71
+ export interface ModelDirectoryStore {
72
+ subscribe(listener: () => void): () => void;
73
+ getSnapshot(): ModelDirectorySnapshot | undefined;
74
+ }
75
+ export interface CodexConnectSnapshot {
76
+ readonly status: string;
77
+ readonly writable: boolean;
78
+ readonly overrides?: Readonly<Record<string, number | null>> | undefined;
79
+ readonly baseOverrides?: Readonly<Record<string, number | null>> | undefined;
80
+ readonly nativeCompaction?: boolean | undefined;
81
+ }
82
+ export interface CodexConnectScope {
83
+ getSnapshot(): CodexConnectSnapshot;
84
+ subscribe(listener: () => void): () => void;
85
+ setModelOverride(modelId: string, tokens: number | undefined): Promise<void>;
86
+ setNativeCompaction?(enabled: boolean): Promise<void>;
87
+ }
88
+ export interface PresetPromptCatalog {
89
+ readonly preset: string;
90
+ readonly sections: readonly PresetPromptEntry[];
91
+ }
92
+ //# sourceMappingURL=ui-contracts.d.ts.map
@@ -0,0 +1,83 @@
1
+ /** Browser-safe shared constants, activity shapes, and read-only preset contracts. */
2
+ /** User-selectable Codex context controls use whole K-token units. */
3
+ export const CODEX_CONTEXT_UNIT = 1_000;
4
+ export const CODEX_CONTEXT_MIN = 16_000;
5
+ export const CODEX_CONTEXT_MAX = 1_000_000;
6
+ export const OPENAI_CODEX_PROVIDER = 'openai-codex';
7
+ export const OPENAI_CODEX_SETTINGS_NAMESPACE = 'llm-openai-codex';
8
+ export const OPENAI_CODEX_MODEL_CATALOG_PATH = '/plugins/dsh-codex-connect/models';
9
+ export const OPENAI_CODEX_MODEL_LIMITS = {
10
+ 'gpt-6.1-sol': { defaultTokens: 500_000, maxTokens: 872_000 },
11
+ 'gpt-6.1-terra': { defaultTokens: 500_000, maxTokens: 872_000 },
12
+ 'gpt-6-astra': { defaultTokens: 272_000, maxTokens: 872_000 },
13
+ 'gpt-6-sol': { defaultTokens: 272_000, maxTokens: 872_000 },
14
+ 'gpt-6-luna': { defaultTokens: 272_000, maxTokens: 872_000 },
15
+ 'gpt-5.6-sol': { defaultTokens: 272_000, maxTokens: 872_000 },
16
+ 'gpt-5.6-terra': { defaultTokens: 272_000, maxTokens: 872_000 },
17
+ 'gpt-5.6-luna': { defaultTokens: 272_000, maxTokens: 872_000 },
18
+ 'gpt-5.4': { defaultTokens: 272_000, maxTokens: 1_000_000 },
19
+ 'gpt-5.5': { defaultTokens: 272_000, maxTokens: 272_000 },
20
+ 'gpt-5.4-mini': { defaultTokens: 272_000, maxTokens: 272_000 },
21
+ };
22
+ const CONTEXT_PRESET_TIERS = [64_000, 128_000, 200_000, 272_000, 400_000, 500_000, 872_000, 1_000_000];
23
+ export function resolveContextWindowBounds(provider, model, dynamicCatalog) {
24
+ if (provider === OPENAI_CODEX_PROVIDER) {
25
+ return (model !== undefined ? dynamicCatalog?.[model] ?? OPENAI_CODEX_MODEL_LIMITS[model] : undefined)
26
+ ?? { defaultTokens: 272_000, maxTokens: 272_000 };
27
+ }
28
+ return { maxTokens: CODEX_CONTEXT_MAX };
29
+ }
30
+ export function formatCompactTokens(tokens) {
31
+ if (tokens >= 1_000) {
32
+ return tokens % 1_000 === 0
33
+ ? `${tokens / 1_000}k`
34
+ : `${(tokens / 1_000).toFixed(1).replace(/\.0$/, '')}k`;
35
+ }
36
+ return `${tokens}`;
37
+ }
38
+ export function contextPresetsForBounds(bounds) {
39
+ const filtered = CONTEXT_PRESET_TIERS.filter(v => v <= bounds.maxTokens && v !== bounds.defaultTokens);
40
+ if (bounds.maxTokens > 0 && bounds.maxTokens !== bounds.defaultTokens && !filtered.includes(bounds.maxTokens)) {
41
+ filtered.push(bounds.maxTokens);
42
+ }
43
+ return filtered.sort((a, b) => a - b);
44
+ }
45
+ export function parseCustomContextInput(raw, maxTokens) {
46
+ const trimmed = raw.trim();
47
+ if (trimmed.length === 0)
48
+ return undefined;
49
+ const match = /^(\d+(?:\.\d+)?)\s*(k)?$/i.exec(trimmed);
50
+ if (match === null)
51
+ return undefined;
52
+ const num = Number(match[1]);
53
+ if (!Number.isFinite(num) || num <= 0)
54
+ return undefined;
55
+ const tokens = match[2] !== undefined
56
+ ? Math.round(num * CODEX_CONTEXT_UNIT)
57
+ : Number.isSafeInteger(num) && num > Math.floor(maxTokens / CODEX_CONTEXT_UNIT) && num <= maxTokens
58
+ ? num
59
+ : Math.round(num * CODEX_CONTEXT_UNIT);
60
+ return Number.isSafeInteger(tokens) && tokens >= Math.min(CODEX_CONTEXT_MIN, maxTokens) && tokens <= maxTokens ? tokens : undefined;
61
+ }
62
+ export function nextOpenAICodexOverrides(currentValue, baseValue, modelId, tokens) {
63
+ const next = {};
64
+ if (currentValue !== undefined) {
65
+ for (const [id, value] of Object.entries(currentValue)) {
66
+ if (id.length > 0 && id.trim() === id && (value === null || (typeof value === 'number' && Number.isSafeInteger(value) && value > 0))) {
67
+ next[id] = value;
68
+ }
69
+ }
70
+ }
71
+ if (tokens !== undefined) {
72
+ next[modelId] = tokens;
73
+ return next;
74
+ }
75
+ if (typeof baseValue?.[modelId] === 'number')
76
+ next[modelId] = null;
77
+ else
78
+ delete next[modelId];
79
+ return Object.keys(next).length === 0 ? undefined : next;
80
+ }
81
+ /** Client-safe current-preset prompt catalog; editable targets have reviewed native contracts. */
82
+ export const PRESET_PROMPT_NAMES = ['deployment:persona-prefix', 'deployment:persona-suffix', 'codex:base'];
83
+ //# sourceMappingURL=ui-contracts.js.map
@@ -0,0 +1,10 @@
1
+ /** Client plugin entry for DSH 0.2.2+ Web/Desktop ConfigForms. */
2
+ import type { Context } from '@deepseek-ai/cordis';
3
+ export declare const inject: string[];
4
+ export declare function apply(ctx: Context): void;
5
+ declare const _default: {
6
+ inject: string[];
7
+ apply: typeof apply;
8
+ };
9
+ export default _default;
10
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1,10 @@
1
+ import { apply as applyDesktop } from "../client/desktop.js";
2
+ export const inject = [
3
+ 'commandUi', 'sessions', 'slots', 'locale',
4
+ 'remote',
5
+ ];
6
+ export function apply(ctx) {
7
+ ctx.inject(['configForms'], host => applyDesktop(host));
8
+ }
9
+ export default { inject, apply };
10
+ //# sourceMappingURL=client.js.map
@@ -1,5 +1,7 @@
1
1
  /** Codex-aware `/compact` command with an optional transport preference. */
2
2
  import type { Context } from '@deepseek-ai/cordis';
3
+ /** Register `/compact [remote|local]` on each live and future Agent scope across all presets. */
4
+ export declare function installGlobalCompactCommand(ctx: Context): void;
3
5
  /** Replace the Core command inside the Codex compaction scope. */
4
6
  export declare function apply(ctx: Context): void;
5
7
  export declare const name = "compact-command";
@@ -0,0 +1,176 @@
1
+ /** Codex-aware `/compact` command with an optional transport preference. */
2
+ import { ManualCompactionError } from '@deepseek-ai/dsh-compaction';
3
+ import { readHostSettings } from "../contracts/settings.js";
4
+ import { OPENAI_CODEX_PROVIDER, OPENAI_CODEX_SETTINGS_NAMESPACE } from "../contracts/ui-contracts.js";
5
+ import { runCodexCompactionMode } from "./compaction.js";
6
+ const USAGE = 'Usage: /compact [remote|local]';
7
+ /** Convert expected backend failures into the same concise command results as DSH Core. */
8
+ function expectedFailure(error) {
9
+ switch (error.code) {
10
+ case 'busy':
11
+ return { kind: 'error', text: 'Compaction is unavailable because this process has an active compaction, or the agent is not idle.' };
12
+ case 'cancelled':
13
+ return { kind: 'error', text: 'Compaction cancelled.' };
14
+ case 'changed':
15
+ return { kind: 'error', text: 'Compaction could not replace the selected history because it changed. The conversation is unchanged.' };
16
+ case 'summary':
17
+ return { kind: 'error', text: 'Compaction could not produce a useful summary. The conversation is unchanged; the attempt is recorded in the session log.' };
18
+ case 'commit':
19
+ return { kind: 'error', text: 'Compaction did not finish cleanly; inspect the current session state before retrying.' };
20
+ case 'persistence':
21
+ return { kind: 'error', text: 'Compaction finished, but the session could not be saved.' };
22
+ default:
23
+ return { kind: 'error', text: `Unknown compaction failure: ${String(error.code)}` };
24
+ }
25
+ }
26
+ function modeOf(rawInput) {
27
+ const value = rawInput.trim().toLowerCase();
28
+ if (value === '')
29
+ return undefined;
30
+ if (value === 'remote' || value === 'local')
31
+ return value;
32
+ return 'invalid';
33
+ }
34
+ function resolveCompactionService(hostCtx, agent) {
35
+ const fromPreset = hostCtx.get?.('agentPresets')?.serviceFor?.(agent, 'compaction');
36
+ if (fromPreset?.compactNow !== undefined)
37
+ return fromPreset;
38
+ const fromAgent = agent.ctx?.get?.('compaction');
39
+ if (fromAgent?.compactNow !== undefined)
40
+ return fromAgent;
41
+ const fromHost = hostCtx.get?.('compaction') ?? hostCtx.compaction;
42
+ return fromHost?.compactNow !== undefined ? fromHost : undefined;
43
+ }
44
+ function needsCodexConnectRemoteHint(hostCtx, agent, mode) {
45
+ if (mode !== 'remote')
46
+ return false;
47
+ const agentRef = agent;
48
+ const provider = agentRef.session?.requestHeader?.()?.config?.provider ?? agentRef.model?.current?.()?.provider;
49
+ if (provider !== OPENAI_CODEX_PROVIDER)
50
+ return false;
51
+ const descriptors = hostCtx.get?.('settings')?.describe?.();
52
+ if (descriptors === undefined || !descriptors.some(d => d.ns === OPENAI_CODEX_SETTINGS_NAMESPACE))
53
+ return false;
54
+ const connectSettings = readHostSettings(hostCtx, OPENAI_CODEX_SETTINGS_NAMESPACE);
55
+ return connectSettings?.enableNativeCompaction !== true;
56
+ }
57
+ async function ensureCodexConnectRemoteCompaction(hostCtx, agent, mode) {
58
+ if (!needsCodexConnectRemoteHint(hostCtx, agent, mode))
59
+ return false;
60
+ const settings = hostCtx.get?.('settings');
61
+ if (typeof settings?.update !== 'function')
62
+ return true;
63
+ try {
64
+ await settings.update(OPENAI_CODEX_SETTINGS_NAMESPACE, { enableNativeCompaction: true });
65
+ return needsCodexConnectRemoteHint(hostCtx, agent, mode);
66
+ }
67
+ catch {
68
+ return true;
69
+ }
70
+ }
71
+ async function executeCompact(hostCtx, invocation) {
72
+ const mode = modeOf(invocation.rawInput);
73
+ if (mode === 'invalid')
74
+ return { kind: 'error', text: USAGE };
75
+ const compaction = resolveCompactionService(hostCtx, invocation.agent);
76
+ if (compaction === undefined) {
77
+ return { kind: 'error', text: 'Compaction is unavailable because no compaction service is configured for this session.' };
78
+ }
79
+ const needsHint = await ensureCodexConnectRemoteCompaction(hostCtx, invocation.agent, mode);
80
+ const compact = () => compaction.compactNow(invocation.agent, invocation.signal, invocation.commandId);
81
+ try {
82
+ const result = mode === undefined ? await compact() : await runCodexCompactionMode(mode, compact);
83
+ if (result === null)
84
+ return { kind: 'success', text: 'No compactable history yet.' };
85
+ const suffix = needsHint
86
+ ? '; enable Native Compaction in Codex Connect settings for remote mode'
87
+ : '';
88
+ return {
89
+ kind: 'success',
90
+ text: `Compacted ${result.shadowedSeqs.length} history items (~${result.shadowedTokenCount} tokens${suffix}).`,
91
+ sourceEventSeq: result.summarySeq,
92
+ };
93
+ }
94
+ catch (error) {
95
+ if (invocation.signal.aborted)
96
+ return { kind: 'error', text: 'Compaction cancelled.' };
97
+ if (error instanceof ManualCompactionError)
98
+ return expectedFailure(error);
99
+ throw error;
100
+ }
101
+ }
102
+ function createCompactDefinition(hostCtx, active) {
103
+ const handler = (invocation) => {
104
+ const operation = executeCompact(hostCtx, invocation);
105
+ active.add(operation);
106
+ const retire = () => { active.delete(operation); };
107
+ operation.then(retire, retire);
108
+ return operation;
109
+ };
110
+ return {
111
+ name: 'compact',
112
+ description: 'Compact older conversation history, optionally using remote or local mode',
113
+ input: { hint: '[remote|local]' },
114
+ handler,
115
+ };
116
+ }
117
+ function mountPerAgentCommands(commandsCtx) {
118
+ const active = new Set();
119
+ const disposers = new Map();
120
+ const definition = createCompactDefinition(commandsCtx, active);
121
+ const attach = (agent) => {
122
+ if (agent === undefined || typeof agent !== 'object' || disposers.has(agent))
123
+ return;
124
+ const agentCommands = agent.ctx?.get?.('commands');
125
+ if (agentCommands?.register === undefined)
126
+ return;
127
+ disposers.set(agent, agentCommands.register(definition));
128
+ };
129
+ const existing = commandsCtx.get?.('agents')?.list?.() ?? [];
130
+ for (const agent of existing)
131
+ attach(agent);
132
+ const offCreated = commandsCtx.on('agent/created', (({ agent }) => { attach(agent); }));
133
+ const offDisposed = commandsCtx.on('agent/disposed', (({ agent }) => {
134
+ const off = disposers.get(agent);
135
+ disposers.delete(agent);
136
+ off?.();
137
+ }));
138
+ return async () => {
139
+ offCreated?.();
140
+ offDisposed?.();
141
+ for (const off of disposers.values())
142
+ off();
143
+ disposers.clear();
144
+ await Promise.allSettled(active);
145
+ };
146
+ }
147
+ /** Register `/compact [remote|local]` on each live and future Agent scope across all presets. */
148
+ export function installGlobalCompactCommand(ctx) {
149
+ if (typeof ctx.on !== 'function')
150
+ return;
151
+ if (typeof ctx.inject === 'function') {
152
+ ctx.inject(['commands'], ((commandsCtx) => {
153
+ const cleanup = mountPerAgentCommands(commandsCtx);
154
+ commandsCtx.effect?.(() => cleanup, 'codex: per-agent /compact command');
155
+ }));
156
+ return;
157
+ }
158
+ if (ctx.get?.('commands') !== undefined) {
159
+ const cleanup = mountPerAgentCommands(ctx);
160
+ ctx.effect?.(() => cleanup, 'codex: per-agent /compact command');
161
+ }
162
+ }
163
+ /** Replace the Core command inside the Codex compaction scope. */
164
+ export function apply(ctx) {
165
+ const commands = ctx.commands;
166
+ const active = new Set();
167
+ const definition = createCompactDefinition(ctx, active);
168
+ ctx.effect(function* () {
169
+ yield async () => { await Promise.allSettled(active); };
170
+ yield commands.register(definition);
171
+ }, 'codex compact command lifecycle');
172
+ }
173
+ export const name = 'compact-command';
174
+ export const inject = ['commands', 'compaction'];
175
+ export default { name, inject, apply };
176
+ //# sourceMappingURL=compact-command.js.map
@@ -2,13 +2,22 @@
2
2
  import { Context } from '@deepseek-ai/cordis';
3
3
  import BasicCompactionEngine from '@deepseek-ai/dsh-compaction-basic';
4
4
  import type { CompactionResult, CompactionTrigger } from '@deepseek-ai/dsh-compaction';
5
- import type { Agent } from '@deepseek-ai/dsh-agent';
5
+ import type { GenerateOptions } from '@deepseek-ai/dsh-llm';
6
+ type CodexGenerateOptions = GenerateOptions & {
7
+ contextWindow?: number;
8
+ };
6
9
  /** Per-command compaction preference propagated into the LLM stream seam. */
7
10
  export type CodexCompactionMode = 'remote' | 'local';
8
11
  /** Run one manual compaction with an explicit local/remote preference. */
9
12
  export declare function runCodexCompactionMode<T>(mode: CodexCompactionMode, task: () => Promise<T>): Promise<T>;
10
13
  /** Read the explicit preference for the current compaction stream, if any. */
11
14
  export declare function codexCompactionMode(): CodexCompactionMode | undefined;
15
+ /**
16
+ * When `/compact local` is active, neutralize DSH's exact compaction prompt
17
+ * prefix on a shallow clone so external adapters (`dsh-codex-connect`) fall
18
+ * through to local text summarization instead of firing `compaction_trigger`.
19
+ */
20
+ export declare function withExplicitLocalCompactionInstruction(options: CodexGenerateOptions): CodexGenerateOptions;
12
21
  /**
13
22
  * Keep the upstream compaction policy, retention, overflow recovery, and
14
23
  * transaction implementation intact. The scoped LLM seam changes only the
@@ -17,9 +26,12 @@ export declare function codexCompactionMode(): CodexCompactionMode | undefined;
17
26
  export default class CodexCompactionEngine extends BasicCompactionEngine {
18
27
  static inject: string[];
19
28
  static Config: import("@deepseek-ai/schemastery").default<import("@deepseek-ai/dsh-compaction-basic").BasicCompactionConfig>;
29
+ readonly codexSmallWindowReady = true;
20
30
  private readonly activeSession;
21
31
  constructor(ctx: Context, config?: ConstructorParameters<typeof BasicCompactionEngine>[1]);
22
- compactIfNeeded(agent: Agent, trigger: CompactionTrigger, signal: AbortSignal): Promise<CompactionResult | null>;
23
- compactNow(agent: Agent, signal: AbortSignal, sourceCommandId?: Parameters<BasicCompactionEngine['compactNow']>[2]): Promise<CompactionResult | null>;
32
+ compactIfNeeded(agent: Parameters<BasicCompactionEngine['compactIfNeeded']>[0], trigger: CompactionTrigger, signal: AbortSignal): Promise<CompactionResult | null>;
33
+ compactRegion(...args: Parameters<BasicCompactionEngine['compactRegion']>): Promise<CompactionResult>;
34
+ compactNow(agent: Parameters<BasicCompactionEngine['compactNow']>[0], signal: AbortSignal, sourceCommandId?: Parameters<BasicCompactionEngine['compactNow']>[2]): Promise<CompactionResult | null>;
24
35
  }
36
+ export {};
25
37
  //# sourceMappingURL=compaction.d.ts.map