@shuind/dsh-codex-harness 0.3.0 → 0.3.2

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.
@@ -1,5 +1,6 @@
1
1
  /** Opt-in Host overlays for future Agents; source presets and Persona stay untouched. */
2
2
  import type { Context } from '@deepseek-ai/cordis';
3
+ import { Config } from '../policy/rule-resolver.ts';
3
4
  import type { ToolPolicyConfigSource } from '../policy/rule-resolver.ts';
4
5
  export type { ToolAction, ToolActionRule, ToolPolicyRule } from '../contracts/tool-policy-contract.ts';
5
6
  export { Config } from '../policy/rule-resolver.ts';
@@ -14,83 +15,7 @@ export declare function apply(ctx: Context, config?: ToolPolicyConfigSource): vo
14
15
  declare const _default: {
15
16
  name: string;
16
17
  inject: string[];
17
- Config: import("@deepseek-ai/schemastery").default<NoInfer<Schemastery.ObjectS<NoInfer<{
18
- rules: import("@deepseek-ai/schemastery").default<({
19
- preset?: string | null;
20
- allow?: string[] | null;
21
- deny?: string[] | null;
22
- replaceShell?: boolean | null;
23
- replacePlan?: boolean | null;
24
- replacePatch?: boolean | null;
25
- tools?: ({
26
- name?: string | null;
27
- action?: "codex-exec" | "codex-plan" | "codex-patch" | "keep" | "hide" | "defer" | null;
28
- } & import("@deepseek-ai/cosmokit").Dict)[] | null;
29
- promptOverrides?: ({
30
- name?: "deployment:persona-prefix" | "deployment:persona-suffix" | "codex:base" | null;
31
- text?: string | null;
32
- } & import("@deepseek-ai/cosmokit").Dict)[] | null;
33
- } & import("@deepseek-ai/cosmokit").Dict)[], Schemastery.ObjectT<NoInfer<{
34
- preset: import("@deepseek-ai/schemastery").default<string, string, "defined">;
35
- allow: import("@deepseek-ai/schemastery").default<string[], string[], "plain">;
36
- deny: import("@deepseek-ai/schemastery").default<string[], string[], "plain">;
37
- replaceShell: import("@deepseek-ai/schemastery").default<boolean, boolean, "defined">;
38
- replacePlan: import("@deepseek-ai/schemastery").default<boolean, boolean, "defined">;
39
- replacePatch: import("@deepseek-ai/schemastery").default<boolean, boolean, "defined">;
40
- tools: import("@deepseek-ai/schemastery").default<({
41
- name?: string | null;
42
- action?: "codex-exec" | "codex-plan" | "codex-patch" | "keep" | "hide" | "defer" | null;
43
- } & import("@deepseek-ai/cosmokit").Dict)[], Schemastery.ObjectT<NoInfer<{
44
- name: import("@deepseek-ai/schemastery").default<string, string, "defined">;
45
- action: import("@deepseek-ai/schemastery").default<"codex-exec" | "codex-plan" | "codex-patch" | "keep" | "hide" | "defer", "codex-exec" | "codex-plan" | "codex-patch" | "keep" | "hide" | "defer", "defined">;
46
- }>>[], "plain">;
47
- promptOverrides: import("@deepseek-ai/schemastery").default<({
48
- name?: "deployment:persona-prefix" | "deployment:persona-suffix" | "codex:base" | null;
49
- text?: string | null;
50
- } & import("@deepseek-ai/cosmokit").Dict)[], Schemastery.ObjectT<NoInfer<{
51
- name: import("@deepseek-ai/schemastery").default<"deployment:persona-prefix" | "deployment:persona-suffix" | "codex:base", "deployment:persona-prefix" | "deployment:persona-suffix" | "codex:base", "defined">;
52
- text: import("@deepseek-ai/schemastery").default<string, string, "defined">;
53
- }>>[], "plain">;
54
- }>>[], "defined">;
55
- }>>>, NoInfer<Schemastery.ObjectT<NoInfer<{
56
- rules: import("@deepseek-ai/schemastery").default<({
57
- preset?: string | null;
58
- allow?: string[] | null;
59
- deny?: string[] | null;
60
- replaceShell?: boolean | null;
61
- replacePlan?: boolean | null;
62
- replacePatch?: boolean | null;
63
- tools?: ({
64
- name?: string | null;
65
- action?: "codex-exec" | "codex-plan" | "codex-patch" | "keep" | "hide" | "defer" | null;
66
- } & import("@deepseek-ai/cosmokit").Dict)[] | null;
67
- promptOverrides?: ({
68
- name?: "deployment:persona-prefix" | "deployment:persona-suffix" | "codex:base" | null;
69
- text?: string | null;
70
- } & import("@deepseek-ai/cosmokit").Dict)[] | null;
71
- } & import("@deepseek-ai/cosmokit").Dict)[], Schemastery.ObjectT<NoInfer<{
72
- preset: import("@deepseek-ai/schemastery").default<string, string, "defined">;
73
- allow: import("@deepseek-ai/schemastery").default<string[], string[], "plain">;
74
- deny: import("@deepseek-ai/schemastery").default<string[], string[], "plain">;
75
- replaceShell: import("@deepseek-ai/schemastery").default<boolean, boolean, "defined">;
76
- replacePlan: import("@deepseek-ai/schemastery").default<boolean, boolean, "defined">;
77
- replacePatch: import("@deepseek-ai/schemastery").default<boolean, boolean, "defined">;
78
- tools: import("@deepseek-ai/schemastery").default<({
79
- name?: string | null;
80
- action?: "codex-exec" | "codex-plan" | "codex-patch" | "keep" | "hide" | "defer" | null;
81
- } & import("@deepseek-ai/cosmokit").Dict)[], Schemastery.ObjectT<NoInfer<{
82
- name: import("@deepseek-ai/schemastery").default<string, string, "defined">;
83
- action: import("@deepseek-ai/schemastery").default<"codex-exec" | "codex-plan" | "codex-patch" | "keep" | "hide" | "defer", "codex-exec" | "codex-plan" | "codex-patch" | "keep" | "hide" | "defer", "defined">;
84
- }>>[], "plain">;
85
- promptOverrides: import("@deepseek-ai/schemastery").default<({
86
- name?: "deployment:persona-prefix" | "deployment:persona-suffix" | "codex:base" | null;
87
- text?: string | null;
88
- } & import("@deepseek-ai/cosmokit").Dict)[], Schemastery.ObjectT<NoInfer<{
89
- name: import("@deepseek-ai/schemastery").default<"deployment:persona-prefix" | "deployment:persona-suffix" | "codex:base", "deployment:persona-prefix" | "deployment:persona-suffix" | "codex:base", "defined">;
90
- text: import("@deepseek-ai/schemastery").default<string, string, "defined">;
91
- }>>[], "plain">;
92
- }>>[], "defined">;
93
- }>>>, "volatile">;
18
+ Config: import("@deepseek-ai/schemastery").default<Config, Config, "volatile">;
94
19
  apply: typeof apply;
95
20
  };
96
21
  export default _default;
@@ -5,83 +5,7 @@ export interface Config {
5
5
  /** Empty by default: no preset or existing Agent is changed implicitly. */
6
6
  rules?: readonly ToolPolicyRule[];
7
7
  }
8
- export declare const Config: z<NoInfer<Schemastery.ObjectS<NoInfer<{
9
- rules: z<({
10
- preset?: string | null;
11
- allow?: string[] | null;
12
- deny?: string[] | null;
13
- replaceShell?: boolean | null;
14
- replacePlan?: boolean | null;
15
- replacePatch?: boolean | null;
16
- tools?: ({
17
- name?: string | null;
18
- action?: "codex-exec" | "codex-plan" | "codex-patch" | "keep" | "hide" | "defer" | null;
19
- } & import("@deepseek-ai/cosmokit").Dict)[] | null;
20
- promptOverrides?: ({
21
- name?: "deployment:persona-prefix" | "deployment:persona-suffix" | "codex:base" | null;
22
- text?: string | null;
23
- } & import("@deepseek-ai/cosmokit").Dict)[] | null;
24
- } & import("@deepseek-ai/cosmokit").Dict)[], Schemastery.ObjectT<NoInfer<{
25
- preset: z<string, string, "defined">;
26
- allow: z<string[], string[], "plain">;
27
- deny: z<string[], string[], "plain">;
28
- replaceShell: z<boolean, boolean, "defined">;
29
- replacePlan: z<boolean, boolean, "defined">;
30
- replacePatch: z<boolean, boolean, "defined">;
31
- tools: z<({
32
- name?: string | null;
33
- action?: "codex-exec" | "codex-plan" | "codex-patch" | "keep" | "hide" | "defer" | null;
34
- } & import("@deepseek-ai/cosmokit").Dict)[], Schemastery.ObjectT<NoInfer<{
35
- name: z<string, string, "defined">;
36
- action: z<"codex-exec" | "codex-plan" | "codex-patch" | "keep" | "hide" | "defer", "codex-exec" | "codex-plan" | "codex-patch" | "keep" | "hide" | "defer", "defined">;
37
- }>>[], "plain">;
38
- promptOverrides: z<({
39
- name?: "deployment:persona-prefix" | "deployment:persona-suffix" | "codex:base" | null;
40
- text?: string | null;
41
- } & import("@deepseek-ai/cosmokit").Dict)[], Schemastery.ObjectT<NoInfer<{
42
- name: z<"deployment:persona-prefix" | "deployment:persona-suffix" | "codex:base", "deployment:persona-prefix" | "deployment:persona-suffix" | "codex:base", "defined">;
43
- text: z<string, string, "defined">;
44
- }>>[], "plain">;
45
- }>>[], "defined">;
46
- }>>>, NoInfer<Schemastery.ObjectT<NoInfer<{
47
- rules: z<({
48
- preset?: string | null;
49
- allow?: string[] | null;
50
- deny?: string[] | null;
51
- replaceShell?: boolean | null;
52
- replacePlan?: boolean | null;
53
- replacePatch?: boolean | null;
54
- tools?: ({
55
- name?: string | null;
56
- action?: "codex-exec" | "codex-plan" | "codex-patch" | "keep" | "hide" | "defer" | null;
57
- } & import("@deepseek-ai/cosmokit").Dict)[] | null;
58
- promptOverrides?: ({
59
- name?: "deployment:persona-prefix" | "deployment:persona-suffix" | "codex:base" | null;
60
- text?: string | null;
61
- } & import("@deepseek-ai/cosmokit").Dict)[] | null;
62
- } & import("@deepseek-ai/cosmokit").Dict)[], Schemastery.ObjectT<NoInfer<{
63
- preset: z<string, string, "defined">;
64
- allow: z<string[], string[], "plain">;
65
- deny: z<string[], string[], "plain">;
66
- replaceShell: z<boolean, boolean, "defined">;
67
- replacePlan: z<boolean, boolean, "defined">;
68
- replacePatch: z<boolean, boolean, "defined">;
69
- tools: z<({
70
- name?: string | null;
71
- action?: "codex-exec" | "codex-plan" | "codex-patch" | "keep" | "hide" | "defer" | null;
72
- } & import("@deepseek-ai/cosmokit").Dict)[], Schemastery.ObjectT<NoInfer<{
73
- name: z<string, string, "defined">;
74
- action: z<"codex-exec" | "codex-plan" | "codex-patch" | "keep" | "hide" | "defer", "codex-exec" | "codex-plan" | "codex-patch" | "keep" | "hide" | "defer", "defined">;
75
- }>>[], "plain">;
76
- promptOverrides: z<({
77
- name?: "deployment:persona-prefix" | "deployment:persona-suffix" | "codex:base" | null;
78
- text?: string | null;
79
- } & import("@deepseek-ai/cosmokit").Dict)[], Schemastery.ObjectT<NoInfer<{
80
- name: z<"deployment:persona-prefix" | "deployment:persona-suffix" | "codex:base", "deployment:persona-prefix" | "deployment:persona-suffix" | "codex:base", "defined">;
81
- text: z<string, string, "defined">;
82
- }>>[], "plain">;
83
- }>>[], "defined">;
84
- }>>>, "volatile">;
8
+ export declare const Config: z<Config, Config, 'volatile'>;
85
9
  /** Loader activations receive a volatile reference; direct callers may pass plain rules. */
86
10
  export type ToolPolicyConfigSource = Config | ReturnType<typeof Config>;
87
11
  export interface ResolvedRule extends ToolPolicyRule {
@@ -165,16 +165,9 @@ export async function parseCompactResponsePayload(response) {
165
165
  const output = Array.isArray(body.output) ? body.output : [];
166
166
  const compactions = [];
167
167
  for (const item of output) {
168
- if (!isJsonObject(item) || typeof item.encrypted_content !== 'string')
169
- continue;
170
- const encrypted = item.encrypted_content.trim();
171
- if (encrypted.length === 0)
172
- continue;
173
- compactions.push({
174
- type: 'compaction',
175
- encrypted_content: encrypted,
176
- ...typeof item.id === 'string' && item.id.length > 0 ? { id: item.id } : {},
177
- });
168
+ const compaction = asCompactionItem(item);
169
+ if (compaction !== undefined)
170
+ compactions.push(compaction);
178
171
  }
179
172
  return {
180
173
  compactions,
@@ -1,5 +1,6 @@
1
1
  /** OpenAI Responses `/responses/compact` and V2 `/responses` transport with local compaction fallback. */
2
2
  import { credentialRef } from '@deepseek-ai/dsh-credentials';
3
+ import { offloadedImageText, resolveImageAttachmentAccess } from '@deepseek-ai/dsh-llm';
3
4
  import { isGptModel, readHostSettings } from "../contracts/settings.js";
4
5
  import { collectTrustedCompactionMarkers, encodeRemoteCompactionCheckpoint, parseCompactResponsePayload, retainedUserMessagesFromInput, } from "./compact-checkpoint.js";
5
6
  import { capabilityKey, CONTEXT_LIMIT_ERROR, hostedWebSearchStream, isCompactUnsupported, recordUnsupportedCapability, } from "./fetch-transport.js";
@@ -45,9 +46,36 @@ async function apiHeaders(ctx, profile, isV2Responses) {
45
46
  }
46
47
  return headers;
47
48
  }
48
- function textOf(message) {
49
+ const VALID_IMAGE_MEDIA_TYPES = new Set(['image/png', 'image/jpeg', 'image/webp', 'image/gif']);
50
+ function hasValidImageRef(attachment) {
51
+ if (typeof attachment !== 'object' || attachment === null)
52
+ return false;
53
+ const record = attachment;
54
+ return typeof record.attachmentId === 'string' && record.attachmentId.length > 0
55
+ && typeof record.mediaType === 'string' && VALID_IMAGE_MEDIA_TYPES.has(record.mediaType)
56
+ && typeof record.width === 'number' && typeof record.height === 'number';
57
+ }
58
+ function formatOffloadedImage(ctx, block) {
59
+ const attachments = ctx.get('attachments');
60
+ const fs = ctx.get('fs');
61
+ const access = typeof attachments?.imageHostPath === 'function' && typeof fs?.processPathFromHostPath === 'function'
62
+ ? resolveImageAttachmentAccess(attachments, hostPath => fs.processPathFromHostPath(hostPath), block.attachment)
63
+ : undefined;
64
+ return offloadedImageText(block.attachment, access);
65
+ }
66
+ function textOf(ctx, message) {
49
67
  return message.content
50
- .map(block => block.type === 'text' ? block.text : block.type === 'image' ? '[image omitted]' : '')
68
+ .map(block => {
69
+ if (block.type === 'text')
70
+ return block.text;
71
+ if (block.type === 'image') {
72
+ if (block.offloaded !== true || !hasValidImageRef(block.attachment)) {
73
+ throw new Error('Codex remote compaction requires the DSH adapter for image attachments');
74
+ }
75
+ return formatOffloadedImage(ctx, block);
76
+ }
77
+ return '';
78
+ })
51
79
  .join('');
52
80
  }
53
81
  function stripCompactionPrompt(messages) {
@@ -57,19 +85,19 @@ function stripCompactionPrompt(messages) {
57
85
  }
58
86
  return messages;
59
87
  }
60
- function extractInstructions(options, messages) {
88
+ function extractInstructions(ctx, options, messages) {
61
89
  if (options.system !== undefined)
62
90
  return options.system;
63
91
  for (let index = messages.length - 1; index >= 0; index -= 1) {
64
92
  const message = messages[index];
65
93
  if (message.role !== 'system')
66
94
  continue;
67
- const text = textOf(message);
95
+ const text = textOf(ctx, message);
68
96
  return text.length > 0 ? text : undefined;
69
97
  }
70
98
  return undefined;
71
99
  }
72
- function responsesInput(messages) {
100
+ function responsesInput(ctx, messages) {
73
101
  const result = [];
74
102
  for (const message of messages) {
75
103
  // This compact transport cannot serialize attachment file references losslessly.
@@ -78,7 +106,7 @@ function responsesInput(messages) {
78
106
  }
79
107
  if (message.role === 'system')
80
108
  continue;
81
- const text = textOf(message);
109
+ const text = textOf(ctx, message);
82
110
  if (message.role === 'tool') {
83
111
  result.push({ type: 'function_call_output', call_id: message.toolCallId.split('|')[0], output: text });
84
112
  continue;
@@ -122,14 +150,14 @@ function responsesTools(tools) {
122
150
  parameters: tool.parameters,
123
151
  }));
124
152
  }
125
- function compactBody(options, wireOptions, isV2Responses) {
153
+ function compactBody(ctx, options, wireOptions, isV2Responses) {
126
154
  const messages = stripCompactionPrompt(options.messages);
127
- const instructions = extractInstructions(options, messages);
155
+ const instructions = extractInstructions(ctx, options, messages);
128
156
  const tools = responsesTools(options.tools);
129
157
  const serviceTier = wireOptions.serviceTier ?? serviceTierOf(options);
130
158
  const body = {
131
159
  model: options.model,
132
- input: responsesInput(messages),
160
+ input: responsesInput(ctx, messages),
133
161
  ...instructions !== undefined ? { instructions } : isV2Responses ? { instructions: '' } : {},
134
162
  ...tools === undefined ? {} : { tools },
135
163
  ...typeof options.sessionId === 'string' && options.sessionId.length > 0
@@ -256,7 +284,7 @@ async function remoteCompact(ctx, options, wireOptions = {}) {
256
284
  ...wireOptions,
257
285
  trustedCheckpoints: wireOptions.trustedCheckpoints ?? collectTrustedCompactionMarkers(options.messages),
258
286
  };
259
- const initial = compactBody(options, compactWireOptions, isV2Responses);
287
+ const initial = compactBody(ctx, options, compactWireOptions, isV2Responses);
260
288
  let preCompactInput = initial.preCompactInput;
261
289
  let response = await sendWithRetry(endpoint, headers, initial.body, options.signal);
262
290
  if (!response.ok
@@ -264,7 +292,7 @@ async function remoteCompact(ctx, options, wireOptions = {}) {
264
292
  && canRewriteCompactTools(options, wireOptions)) {
265
293
  const errorText = await response.clone().text().catch(() => '');
266
294
  if (!CONTEXT_LIMIT_ERROR.test(errorText)) {
267
- const reduced = compactBody(options, {
295
+ const reduced = compactBody(ctx, options, {
268
296
  ...compactWireOptions,
269
297
  hostedWebSearch: false,
270
298
  customApplyPatch: false,