super-dsh 0.1.10 → 0.1.11

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 (50) hide show
  1. package/README.md +18 -2
  2. package/agent-agy/dist/agent.js +19 -1
  3. package/agent-claude/dist/adapter.js +106 -31
  4. package/agent-claude/dist/agent.js +177 -22
  5. package/agent-claude/dist/claude-client.js +84 -43
  6. package/agent-claude/dist/claude-launch.js +101 -0
  7. package/agent-claude/dist/claude-native-config.js +169 -0
  8. package/agent-claude/dist/claude-provider-gateway.js +340 -0
  9. package/agent-claude/dist/claude-providers.js +391 -0
  10. package/agent-claude/dist/claude-route.js +152 -0
  11. package/agent-claude/dist/index.js +214 -37
  12. package/agent-claude/dist/models.js +14 -0
  13. package/agent-claude/dist/sdk-runtime.js +320 -0
  14. package/agent-claude/package.json +6 -4
  15. package/agent-codex/README.md +18 -6
  16. package/agent-codex/dist/adapter.js +3 -2
  17. package/agent-codex/dist/agent.js +41 -7
  18. package/agent-codex/dist/app-server-client.js +7 -1
  19. package/agent-codex/dist/app-server-wire.js +10 -22
  20. package/agent-codex/dist/codex-launch.js +10 -32
  21. package/agent-codex/dist/codex-native-config.js +9 -3
  22. package/agent-codex/dist/codex-oauth.js +153 -0
  23. package/agent-codex/dist/codex-provider-gateway.js +36 -38
  24. package/agent-codex/dist/codex-providers.js +20 -7
  25. package/agent-codex/dist/codex-runtime.js +120 -0
  26. package/agent-codex/dist/index.js +18 -11
  27. package/agent-codex/package.json +1 -1
  28. package/agent-codex-sdk/dist/adapter.js +3 -2
  29. package/agent-codex-sdk/dist/agent.js +35 -1
  30. package/agent-codex-sdk/dist/codex-native-config.js +9 -3
  31. package/agent-codex-sdk/dist/codex-oauth.js +153 -0
  32. package/agent-codex-sdk/dist/codex-provider-gateway.js +36 -38
  33. package/agent-codex-sdk/dist/codex-providers.js +20 -7
  34. package/agent-codex-sdk/dist/codex-sdk-launch.js +5 -38
  35. package/agent-codex-sdk/dist/index.js +18 -11
  36. package/agent-codex-sdk/dist/sdk-runtime.js +2 -2
  37. package/agent-hermes/dist/agent.js +46 -2
  38. package/agent-hermes/dist/hermes-client.js +49 -1
  39. package/agent-omp/dist/agent.js +17 -4
  40. package/agent-omp-sdk/dist/agent.d.ts +11 -0
  41. package/agent-omp-sdk/dist/agent.js +17 -4
  42. package/agent-pi/dist/agent.js +33 -1
  43. package/client/index.js +150 -58
  44. package/package.json +2 -3
  45. package/superd-hub/dist/client/agent-settings.d.ts +66 -12
  46. package/superd-hub/dist/client/agent-settings.js +85 -14
  47. package/superd-hub/dist/client/runtime-settings-api.js +5 -5
  48. package/superd-hub/dist/world-mount.d.ts +6 -5
  49. package/superd-hub/dist/world-mount.js +6 -6
  50. package/superd-hub/lib/client/index.js +150 -58
@@ -291,6 +291,12 @@ export class HermesAgent {
291
291
  */
292
292
  #remoteQueue = [];
293
293
  #bridgedToolResults = new Set();
294
+ /** callIds already advertised by an appended assistant/message frame — the
295
+ * strict validator refuses any `tool/call` whose callId no assistant frame
296
+ * advertised (2026-10-04 dev3 case C: the hermes wire never delivers the
297
+ * tool_use-bearing intermediate assistant messages, so execution frames
298
+ * arrived with no advertisement anchor). */
299
+ #advertisedToolCalls = new Set();
294
300
  /** Fires when the agent has been idle past HERMES_IDLE_EXIT_MS (tears down the client). */
295
301
  #onIdleExit;
296
302
  #idleExitTimer = undefined;
@@ -495,7 +501,8 @@ export class HermesAgent {
495
501
  return;
496
502
  this.session.append("turn/start", { turn: this.#dashTurn });
497
503
  await this.#emitRequestContext();
498
- this.#titleSourceSeq ??= this.session.append("user/message", message, { surfaceOp: "append" }).seq;
504
+ const event = this.session.append("user/message", message, { surfaceOp: "append" });
505
+ this.#titleSourceSeq ??= event.seq;
499
506
  this.#armTurnDeadline();
500
507
  void this.#client
501
508
  .prompt(userMessageText(message))
@@ -525,6 +532,12 @@ export class HermesAgent {
525
532
  await this.#handshake(`session.create`, () => this.#client.createSession({
526
533
  cwd: sessionCtx?.cwd ?? process.cwd(),
527
534
  ...(route?.model !== undefined ? { model: route.model } : {}),
535
+ // The route's provider slug MUST ride with the model: without it the
536
+ // gateway pins the session to its default provider (deepseek) and any
537
+ // foreign-family model id (z-ai/glm-*, anthropic/*, …) dies at
538
+ // session.create with `Model … is not served by provider 'deepseek'`
539
+ // (-32602). The gateway normalizes aliases (`z-ai` → `zai`) itself.
540
+ ...(route?.provider !== undefined ? { provider: route.provider } : {}),
528
541
  ...(sessionCtx?.title !== undefined && sessionCtx.title !== "" ? { title: sessionCtx.title } : {}),
529
542
  }));
530
543
  }
@@ -892,13 +905,40 @@ export class HermesAgent {
892
905
  break;
893
906
  const callId = String(event.toolCallId ?? "");
894
907
  const name = String(event.toolName ?? "");
908
+ const argumentsJson = String(event.argumentsJson ?? JSON.stringify(event.args ?? {}));
895
909
  this.#commitStepStart();
910
+ // Advertisement-before-execution (validator invariant): the hermes wire
911
+ // never delivers the tool_use-bearing intermediate assistant messages,
912
+ // so unless a real assistant frame already advertised this callId,
913
+ // bridge a minimal assistant/message carrying the tool-call block —
914
+ // arguments copied verbatim into both frames (validator: lifecycle
915
+ // arguments ≡ advertised, strict string equality; 2026-10-04 dev3
916
+ // case C). A live stream bridge is left untouched — the final real
917
+ // assistant message settles it.
918
+ if (!this.#advertisedToolCalls.has(callId)) {
919
+ const advertisement = createAssistantMessage({
920
+ content: [{ type: "tool-call", id: ToolCallId(callId), name, arguments: argumentsJson }],
921
+ source: {
922
+ provider: String(this.options.provider ?? ""),
923
+ model: String(this.options.model ?? ""),
924
+ },
925
+ });
926
+ this.session.append("assistant/message", {
927
+ turn: this.#dashTurn,
928
+ step: this.#step,
929
+ message: advertisement,
930
+ stream: [],
931
+ }, {
932
+ surfaceOp: "append",
933
+ });
934
+ this.#advertisedToolCalls.add(callId);
935
+ }
896
936
  this.session.append("tool/call", {
897
937
  turn: this.#dashTurn,
898
938
  step: this.#step,
899
939
  callId: ToolCallId(callId),
900
940
  name,
901
- arguments: String(event.argumentsJson ?? JSON.stringify(event.args ?? {})),
941
+ arguments: argumentsJson,
902
942
  });
903
943
  break;
904
944
  }
@@ -1016,6 +1056,10 @@ export class HermesAgent {
1016
1056
  }
1017
1057
  #appendAssistantMessage(message, usage) {
1018
1058
  const content = convertContent(message.content);
1059
+ for (const block of content) {
1060
+ if (block.type === "tool-call")
1061
+ this.#advertisedToolCalls.add(block.id);
1062
+ }
1019
1063
  const assistant = createAssistantMessage({
1020
1064
  content,
1021
1065
  source: {
@@ -61,7 +61,7 @@
61
61
  * (keep the spawned stdio transport the only transport).
62
62
  */
63
63
  import { spawn } from "node:child_process";
64
- import { existsSync } from "node:fs";
64
+ import { existsSync, readFileSync } from "node:fs";
65
65
  import { homedir } from "node:os";
66
66
  import { delimiter, resolve } from "node:path";
67
67
  import { createInterface } from "node:readline";
@@ -124,6 +124,46 @@ export function resolveHermesPython(root) {
124
124
  export function resolveHermesRoot() {
125
125
  return process.env.SUPERD_HERMES_ROOT?.trim() || resolve(homedir(), ".hermes/hermes-agent");
126
126
  }
127
+ /** Parse one `.env` body into entries: `#` comments, optional `export ` prefix,
128
+ * optional single/double quotes, `KEY=VALUE` on one line each. Unparsable
129
+ * lines are skipped (best effort — the gateway tolerates partial envs). */
130
+ export function parseDotEnv(text) {
131
+ const out = {};
132
+ for (const rawLine of text.split(/\r?\n/)) {
133
+ const line = rawLine.trim();
134
+ if (line === "" || line.startsWith("#"))
135
+ continue;
136
+ const body = line.startsWith("export ") ? line.slice("export ".length).trim() : line;
137
+ const eq = body.indexOf("=");
138
+ if (eq <= 0)
139
+ continue;
140
+ const key = body.slice(0, eq).trim();
141
+ if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key))
142
+ continue;
143
+ let value = body.slice(eq + 1).trim();
144
+ if (value.length >= 2 && ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'")))) {
145
+ value = value.slice(1, -1);
146
+ }
147
+ out[key] = value;
148
+ }
149
+ return out;
150
+ }
151
+ /** The native home's `.env` (`~/.hermes/.env`), parsed once per call. The omp
152
+ * and pi runtimes load their own native `.env` on startup; the hermes gateway
153
+ * child does NOT (and the harness env deliberately carries no provider
154
+ * keys), so without this the spawned gateway sees zero provider credentials
155
+ * — every provider request dies as quota/auth regardless of model. */
156
+ export function loadHermesDotEnv() {
157
+ const path = resolve(resolveHermesRoot(), "..", ".env");
158
+ if (!existsSync(path))
159
+ return {};
160
+ try {
161
+ return parseDotEnv(readFileSync(path, "utf8"));
162
+ }
163
+ catch {
164
+ return {};
165
+ }
166
+ }
127
167
  function asRecord(value) {
128
168
  if (value === null || typeof value !== "object" || Array.isArray(value))
129
169
  return null;
@@ -197,6 +237,14 @@ export class HermesGatewayClient {
197
237
  const root = resolveHermesRoot();
198
238
  const python = resolveHermesPython(root);
199
239
  const env = { ...(opts.env ?? process.env) };
240
+ // Native `.env` fill (dotenv convention: existing env WINS). The omp and
241
+ // pi runtimes load their own native `.env`; the hermes gateway child does
242
+ // not, and the harness env carries no provider keys — without this fill
243
+ // every provider request dies as quota/auth regardless of model.
244
+ for (const [dotKey, dotValue] of Object.entries(loadHermesDotEnv())) {
245
+ if (env[dotKey] === undefined || env[dotKey] === "")
246
+ env[dotKey] = dotValue;
247
+ }
200
248
  const prevPath = env.PYTHONPATH?.trim();
201
249
  env.PYTHONPATH = prevPath ? `${root}${delimiter}${prevPath}` : root;
202
250
  env.HERMES_PYTHON_SRC_ROOT = root;
@@ -171,14 +171,23 @@ function userMessageFromOmp(message) {
171
171
  source: { kind: "user" },
172
172
  });
173
173
  }
174
- /** Extract every tool call an OMP assistant message names, in order, for approval correlation. */
175
- function toolCalls(blocks) {
174
+ /** Extract every tool call an OMP assistant message names, in order, for approval correlation.
175
+ * `arguments` is the ADVERTISED args原文 (same normalization `convertContent` applies): dsh's
176
+ * strict validator requires `tool/call.arguments` ≡ the assistant frame's advertised arguments
177
+ * byte-for-byte, while `tool_execution_*` events carry runtime-parsed (schema-stripped) args —
178
+ * models that add unknown fields (e.g. an intent string) make the two diverge and the stored
179
+ * log fail to load (2026-10-04 dev3 case A). Exported for the regression test. */
180
+ export function toolCalls(blocks) {
176
181
  if (blocks === undefined)
177
182
  return [];
178
183
  const result = [];
179
184
  for (const block of blocks) {
180
185
  if (block.type === "toolCall" && typeof block.id === "string") {
181
- result.push({ callId: block.id, name: typeof block.name === "string" ? block.name : "" });
186
+ result.push({
187
+ callId: block.id,
188
+ name: typeof block.name === "string" ? block.name : "",
189
+ arguments: typeof block.arguments === "string" ? block.arguments : JSON.stringify(block.arguments ?? {}),
190
+ });
182
191
  }
183
192
  }
184
193
  return result;
@@ -954,12 +963,16 @@ export class OmpAgent {
954
963
  case "tool_execution_start": {
955
964
  const callId = String(event.toolCallId ?? "");
956
965
  const name = String(event.toolName ?? "");
966
+ // Advertised args win (strict validator: tool/call.arguments ≡ the
967
+ // assistant frame's advertised arguments); execution args are the
968
+ // fallback for calls no assistant frame ever carried.
969
+ const advertised = this.#pendingToolCalls.find((pending) => pending.callId === callId);
957
970
  this.session.append("tool/call", {
958
971
  turn: this.#dashTurn,
959
972
  step: this.#step,
960
973
  callId: ToolCallId(callId),
961
974
  name,
962
- arguments: JSON.stringify(event.args ?? {}),
975
+ arguments: advertised?.arguments ?? JSON.stringify(event.args ?? {}),
963
976
  });
964
977
  // The assistant's pending tool call is now materialized as a running call.
965
978
  this.#pendingToolCalls = this.#pendingToolCalls.filter((pending) => pending.callId !== callId);
@@ -43,6 +43,17 @@ export declare function ompFailure(message: OmpMessage): {
43
43
  } | undefined;
44
44
  /** Map OMP's usage accounting into Dash `TokenUsage` (disjoint field names). */
45
45
  export declare function convertUsage(usage: unknown): TokenUsage | undefined;
46
+ /** Extract every tool call an OMP assistant message names, in order, for approval correlation.
47
+ * `arguments` is the ADVERTISED args原文 (same normalization `convertContent` applies): dsh's
48
+ * strict validator requires `tool/call.arguments` ≡ the assistant frame's advertised arguments
49
+ * byte-for-byte, while `tool_execution_*` events carry runtime-parsed (schema-stripped) args —
50
+ * models that add unknown fields (e.g. an intent string) make the two diverge and the stored
51
+ * log fail to load (2026-10-04 dev3 case A). Exported for the regression test. */
52
+ export declare function toolCalls(blocks: OmpContentBlock[] | undefined): {
53
+ callId: string;
54
+ name: string;
55
+ arguments: string;
56
+ }[];
46
57
  export declare class OmpAgent implements Agent {
47
58
  #private;
48
59
  readonly id: SessionId;
@@ -171,14 +171,23 @@ function userMessageFromOmp(message) {
171
171
  source: { kind: "user" },
172
172
  });
173
173
  }
174
- /** Extract every tool call an OMP assistant message names, in order, for approval correlation. */
175
- function toolCalls(blocks) {
174
+ /** Extract every tool call an OMP assistant message names, in order, for approval correlation.
175
+ * `arguments` is the ADVERTISED args原文 (same normalization `convertContent` applies): dsh's
176
+ * strict validator requires `tool/call.arguments` ≡ the assistant frame's advertised arguments
177
+ * byte-for-byte, while `tool_execution_*` events carry runtime-parsed (schema-stripped) args —
178
+ * models that add unknown fields (e.g. an intent string) make the two diverge and the stored
179
+ * log fail to load (2026-10-04 dev3 case A). Exported for the regression test. */
180
+ export function toolCalls(blocks) {
176
181
  if (blocks === undefined)
177
182
  return [];
178
183
  const result = [];
179
184
  for (const block of blocks) {
180
185
  if (block.type === "toolCall" && typeof block.id === "string") {
181
- result.push({ callId: block.id, name: typeof block.name === "string" ? block.name : "" });
186
+ result.push({
187
+ callId: block.id,
188
+ name: typeof block.name === "string" ? block.name : "",
189
+ arguments: typeof block.arguments === "string" ? block.arguments : JSON.stringify(block.arguments ?? {}),
190
+ });
182
191
  }
183
192
  }
184
193
  return result;
@@ -954,12 +963,16 @@ export class OmpAgent {
954
963
  case "tool_execution_start": {
955
964
  const callId = String(event.toolCallId ?? "");
956
965
  const name = String(event.toolName ?? "");
966
+ // Advertised args win (strict validator: tool/call.arguments ≡ the
967
+ // assistant frame's advertised arguments); execution args are the
968
+ // fallback for calls no assistant frame ever carried.
969
+ const advertised = this.#pendingToolCalls.find((pending) => pending.callId === callId);
957
970
  this.session.append("tool/call", {
958
971
  turn: this.#dashTurn,
959
972
  step: this.#step,
960
973
  callId: ToolCallId(callId),
961
974
  name,
962
- arguments: JSON.stringify(event.args ?? {}),
975
+ arguments: advertised?.arguments ?? JSON.stringify(event.args ?? {}),
963
976
  });
964
977
  // The assistant's pending tool call is now materialized as a running call.
965
978
  this.#pendingToolCalls = this.#pendingToolCalls.filter((pending) => pending.callId !== callId);
@@ -206,6 +206,11 @@ export class PiAgent {
206
206
  */
207
207
  #remoteQueue = [];
208
208
  #bridgedToolResults = new Set();
209
+ /** callIds already advertised by an appended assistant/message frame — the
210
+ * strict validator refuses any `tool/call` whose callId no assistant frame
211
+ * advertised, and requires the execution arguments to equal the advertised
212
+ * string (2026-10-04 dev3 omp/hermes repair: same write-side family). */
213
+ #advertisedToolCalls = new Set();
209
214
  /** The last title already mirrored into the log (dedupe). */
210
215
  #mirroredTitle = null;
211
216
  /** The open compaction lifecycle's id (`compaction/start` … `compaction/end`). */
@@ -750,7 +755,30 @@ export class PiAgent {
750
755
  case "tool_execution_start": {
751
756
  const callId = String(event.toolCallId ?? "");
752
757
  const name = String(event.toolName ?? "");
758
+ const argumentsJson = typeof event.args === "string" ? event.args : JSON.stringify(event.args ?? {});
753
759
  this.#commitStepStart();
760
+ // Advertisement-before-execution (validator invariant, 2026-10-04 dev3
761
+ // omp/hermes repair family): unless a real assistant frame advertised
762
+ // this callId, bridge a minimal assistant/message carrying the
763
+ // tool-call block — arguments copied verbatim into both frames.
764
+ if (!this.#advertisedToolCalls.has(callId)) {
765
+ const advertisement = createAssistantMessage({
766
+ content: [{ type: "tool-call", id: ToolCallId(callId), name, arguments: argumentsJson }],
767
+ source: {
768
+ provider: String(this.options.provider ?? ""),
769
+ model: String(this.options.model ?? ""),
770
+ },
771
+ });
772
+ this.session.append("assistant/message", {
773
+ turn: this.#dashTurn,
774
+ step: this.#step,
775
+ message: advertisement,
776
+ stream: [],
777
+ }, {
778
+ surfaceOp: "append",
779
+ });
780
+ this.#advertisedToolCalls.add(callId);
781
+ }
754
782
  this.session.append("tool/call", {
755
783
  turn: this.#dashTurn,
756
784
  step: this.#step,
@@ -758,7 +786,7 @@ export class PiAgent {
758
786
  name,
759
787
  // The DSH payload requires the RAW JSON string the model produced;
760
788
  // the projection stringified pi's parsed args object.
761
- arguments: typeof event.args === "string" ? event.args : JSON.stringify(event.args ?? {}),
789
+ arguments: argumentsJson,
762
790
  });
763
791
  break;
764
792
  }
@@ -882,6 +910,10 @@ export class PiAgent {
882
910
  }
883
911
  #appendAssistantMessage(message) {
884
912
  const content = convertContent(message.content);
913
+ for (const block of content) {
914
+ if (block.type === "tool-call")
915
+ this.#advertisedToolCalls.add(block.id);
916
+ }
885
917
  // pi reports usage on every assistant message — same-event attachment,
886
918
  // no lag.
887
919
  const usage = convertUsage(message.usage);