negotium 0.23.3 → 0.23.4

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 (30) hide show
  1. package/dist/agent-helpers.js +171 -12
  2. package/dist/agent-helpers.js.map +8 -7
  3. package/dist/{chunk-6gt62j1j.js → chunk-ggdwn8d5.js} +3 -3
  4. package/dist/{chunk-6gt62j1j.js.map → chunk-ggdwn8d5.js.map} +2 -2
  5. package/dist/{chunk-9zn0bkc9.js → chunk-jarf6nb2.js} +2 -2
  6. package/dist/{chunk-9zn0bkc9.js.map → chunk-jarf6nb2.js.map} +1 -1
  7. package/dist/{chunk-cez5m5hm.js → chunk-pwafy9bb.js} +1 -1
  8. package/dist/{chunk-q5djsg78.js → chunk-qekt5bnd.js} +1 -1
  9. package/dist/{chunk-6cnpkzkb.js → chunk-vtd5kn4n.js} +1 -1
  10. package/dist/{chunk-6cnpkzkb.js.map → chunk-vtd5kn4n.js.map} +3 -3
  11. package/dist/hosted-agent.js +166 -13
  12. package/dist/hosted-agent.js.map +8 -7
  13. package/dist/main.js +190 -12
  14. package/dist/main.js.map +9 -8
  15. package/dist/mcp-factories.js +171 -12
  16. package/dist/mcp-factories.js.map +8 -7
  17. package/dist/registry.js +3 -3
  18. package/dist/rollout.js +2 -2
  19. package/dist/runtime/src/agents/claude-notices.ts +130 -0
  20. package/dist/runtime/src/agents/claude-provider.ts +9 -11
  21. package/dist/runtime/src/agents/codex-provider.ts +51 -6
  22. package/dist/runtime/src/agents/rollout/codex.ts +58 -0
  23. package/dist/runtime/src/version.ts +1 -1
  24. package/dist/types/packages/core/src/agents/claude-notices.d.ts +15 -0
  25. package/dist/types/packages/core/src/agents/codex-provider.d.ts +6 -0
  26. package/dist/types/packages/core/src/agents/rollout/codex.d.ts +12 -0
  27. package/dist/types/packages/core/src/version.d.ts +1 -1
  28. package/package.json +1 -1
  29. /package/dist/{chunk-cez5m5hm.js.map → chunk-pwafy9bb.js.map} +0 -0
  30. /package/dist/{chunk-q5djsg78.js.map → chunk-qekt5bnd.js.map} +0 -0
@@ -4977,6 +4977,49 @@ function extractCodexForkedFromId(jsonl) {
4977
4977
  return;
4978
4978
  }
4979
4979
  }
4980
+ function extractLatestCodexSystemInstructionsTurn(jsonl) {
4981
+ const lines = jsonl.trimEnd().split(`
4982
+ `);
4983
+ for (let index = lines.length - 1;index >= 0; index -= 1) {
4984
+ const line = lines[index] ?? "";
4985
+ if (!line.includes("[System Instructions]"))
4986
+ continue;
4987
+ try {
4988
+ const entry = JSON.parse(line);
4989
+ if (entry.type !== "response_item")
4990
+ continue;
4991
+ if (entry.payload?.type !== "message" || entry.payload.role !== "user")
4992
+ continue;
4993
+ const text = (entry.payload.content ?? []).map((part) => typeof part.text === "string" ? part.text : "").join("");
4994
+ if (text.startsWith(`[System Instructions]
4995
+ `))
4996
+ return text;
4997
+ } catch {}
4998
+ }
4999
+ return;
5000
+ }
5001
+ function codexThreadHasSystemPrompt(threadId, systemPrompt, depth = 0) {
5002
+ const path = latestCodexRolloutPath(threadId);
5003
+ if (!path)
5004
+ return false;
5005
+ try {
5006
+ const jsonl = readFileSync4(path, "utf8");
5007
+ const latest = extractLatestCodexSystemInstructionsTurn(jsonl);
5008
+ if (latest !== undefined) {
5009
+ return latest.startsWith(`[System Instructions]
5010
+ ${systemPrompt}
5011
+
5012
+ `);
5013
+ }
5014
+ if (depth >= 8)
5015
+ return false;
5016
+ const parentId = extractCodexForkedFromId(jsonl);
5017
+ return parentId && parentId !== threadId ? codexThreadHasSystemPrompt(parentId, systemPrompt, depth + 1) : false;
5018
+ } catch (error) {
5019
+ logger.debug({ error, threadId }, "codex system prompt: rollout read failed");
5020
+ return false;
5021
+ }
5022
+ }
4980
5023
  function readLatestCodexTokenTotals(threadId, depth = 0) {
4981
5024
  const path = latestCodexRolloutPath(threadId);
4982
5025
  if (!path)
@@ -5246,7 +5289,7 @@ var init_codex = __esm(async () => {
5246
5289
  });
5247
5290
 
5248
5291
  // ../../packages/core/src/version.ts
5249
- var NEGOTIUM_VERSION = "0.23.3";
5292
+ var NEGOTIUM_VERSION = "0.23.4";
5250
5293
 
5251
5294
  // ../../packages/core/src/agents/codex-native-multi-agent.ts
5252
5295
  import { spawn as spawn2 } from "child_process";
@@ -6147,6 +6190,97 @@ var init_conversations = __esm(async () => {
6147
6190
  };
6148
6191
  });
6149
6192
 
6193
+ // ../../packages/core/src/agents/claude-notices.ts
6194
+ function modelLabel(id) {
6195
+ const match = /^claude-([a-z]+)-(\d+)-(\d+)/.exec(id);
6196
+ if (!match)
6197
+ return id;
6198
+ const [, family = "", major, minor] = match;
6199
+ return `${family.charAt(0).toUpperCase()}${family.slice(1)} ${major}.${minor}`;
6200
+ }
6201
+ function rateLimitNotice(m) {
6202
+ const { status, rateLimitType } = m.rate_limit_info;
6203
+ const limit = rateLimitType ? `${RATE_LIMIT_TEXT[rateLimitType] ?? ""} `.trimStart() : "";
6204
+ if (status === "allowed_warning")
6205
+ return `Nearing your ${limit}Claude usage limit`;
6206
+ if (status === "rejected")
6207
+ return `Reached your ${limit}Claude usage limit`;
6208
+ return;
6209
+ }
6210
+ function claudeNoticeStatus(message) {
6211
+ try {
6212
+ if (message.type === "rate_limit_event")
6213
+ return rateLimitNotice(message);
6214
+ if (message.type !== "system")
6215
+ return;
6216
+ const handler = SYSTEM_NOTICES[message.subtype];
6217
+ if (!handler) {
6218
+ logger.debug({ subtype: message.subtype, msg: message }, "claudeProvider: system message (unhandled subtype)");
6219
+ return;
6220
+ }
6221
+ const status = handler(message);
6222
+ if (status)
6223
+ logger.warn({ subtype: message.subtype, status }, "claudeProvider: notice");
6224
+ return status;
6225
+ } catch (err) {
6226
+ logger.debug({ err, msg: message }, "claudeProvider: notice mapping failed");
6227
+ return;
6228
+ }
6229
+ }
6230
+ var API_ERROR_TEXT, RATE_LIMIT_TEXT, DENIAL_TEXT, SYSTEM_NOTICES;
6231
+ var init_claude_notices = __esm(() => {
6232
+ init_logger();
6233
+ API_ERROR_TEXT = {
6234
+ overloaded: "Claude is overloaded",
6235
+ rate_limit: "Claude rate limit hit",
6236
+ server_error: "Claude API error",
6237
+ unknown: "Claude request failed",
6238
+ authentication_failed: "Claude sign-in failed",
6239
+ oauth_org_not_allowed: "Organization not allowed for Claude",
6240
+ account_on_hold: "Claude account is on hold",
6241
+ verification_required: "Claude account needs verification",
6242
+ billing_error: "Claude billing issue",
6243
+ invalid_request: "Claude rejected the request",
6244
+ model_not_found: "Claude model not found",
6245
+ max_output_tokens: "Claude reply hit the length limit",
6246
+ cloud_credential_error: "Cloud credentials failed"
6247
+ };
6248
+ RATE_LIMIT_TEXT = {
6249
+ five_hour: "5-hour",
6250
+ seven_day: "weekly",
6251
+ seven_day_opus: "weekly Opus",
6252
+ seven_day_sonnet: "weekly Sonnet",
6253
+ seven_day_overage_included: "weekly",
6254
+ overage: "extra usage"
6255
+ };
6256
+ DENIAL_TEXT = {
6257
+ rule: "by a permission rule",
6258
+ mode: "by the permission mode",
6259
+ classifier: "by the safety check",
6260
+ asyncAgent: "for a background agent"
6261
+ };
6262
+ SYSTEM_NOTICES = {
6263
+ api_retry: (m) => {
6264
+ const reason = m.error_status === null ? "Lost connection to Claude" : API_ERROR_TEXT[m.error] ?? "Claude request failed";
6265
+ const delay2 = Math.round(m.retry_delay_ms / 1000);
6266
+ const when = delay2 > 0 ? `in ${delay2}s` : "now";
6267
+ return `${reason} \xB7 retrying ${when} (${m.attempt}/${m.max_retries})`;
6268
+ },
6269
+ model_refusal_fallback: (m) => m.direction === "retry" ? `${modelLabel(m.original_model)} declined \xB7 ${modelLabel(m.fallback_model)} is answering instead` : m.content || undefined,
6270
+ model_refusal_no_fallback: (m) => `${modelLabel(m.original_model)} declined this request`,
6271
+ permission_denied: (m) => {
6272
+ const tool = m.tool_name.split("__").at(-1) || m.tool_name;
6273
+ const why = m.decision_reason ? `: ${m.decision_reason}` : ` ${DENIAL_TEXT[m.decision_reason_type ?? ""] ?? ""}`.trimEnd();
6274
+ return `${tool} was blocked${why}`;
6275
+ },
6276
+ informational: (m) => m.prevent_continuation || m.level === "warning" || m.level === "suggestion" ? m.content : undefined,
6277
+ mirror_error: (m) => {
6278
+ logger.warn({ error: m.error }, "claudeProvider: transcript mirror batch dropped");
6279
+ return;
6280
+ }
6281
+ };
6282
+ });
6283
+
6150
6284
  // ../../packages/core/src/agents/deep-map.ts
6151
6285
  function deepMapStrings(value, fn) {
6152
6286
  if (typeof value === "string")
@@ -6652,12 +6786,13 @@ async function* claudeProvider(opts) {
6652
6786
  yield { type: "tool_use_summary", summary: m.summary };
6653
6787
  continue;
6654
6788
  }
6655
- if (message.type === "system") {
6656
- const m = message;
6657
- if (m.subtype === "init") {
6658
- yield { type: "session", sessionId: m.session_id };
6789
+ if (message.type === "system" || message.type === "rate_limit_event") {
6790
+ if (message.type === "system" && message.subtype === "init") {
6791
+ yield { type: "session", sessionId: message.session_id };
6659
6792
  } else {
6660
- logger.debug({ subtype: m.subtype, msg: m }, "claudeProvider: system message (unhandled subtype)");
6793
+ const status = claudeNoticeStatus(message);
6794
+ if (status)
6795
+ yield { type: "status", content: status };
6661
6796
  }
6662
6797
  continue;
6663
6798
  }
@@ -6768,6 +6903,7 @@ async function* claudeProvider(opts) {
6768
6903
  }
6769
6904
  var CLAUDE_DEFAULT_DISALLOWED_TOOLS, CLAUDE_NATIVE_AGENT_TOOLS, CLAUDE_IMAGE_MAX_BYTES, CLAUDE_IMAGE_MIME_TYPES, CLAUDE_ABORT_SIGKILL_DELAY_MS = 2500, claudeProcessExitListeners;
6770
6905
  var init_claude_provider = __esm(async () => {
6906
+ init_claude_notices();
6771
6907
  init_claude_registry();
6772
6908
  init_vault_tool_policy();
6773
6909
  init_file_events();
@@ -7946,13 +8082,22 @@ var exports_codex_provider = {};
7946
8082
  __export(exports_codex_provider, {
7947
8083
  toCodexMcpServers: () => toCodexMcpServers,
7948
8084
  normalizeCodexTurnUsage: () => normalizeCodexTurnUsage,
7949
- codexProvider: () => codexProvider
8085
+ codexProvider: () => codexProvider,
8086
+ codexNoticeStatus: () => codexNoticeStatus
7950
8087
  });
7951
8088
  import { execFileSync as execFileSync4 } from "child_process";
7952
8089
  import { existsSync as existsSync14, readFileSync as readFileSync11, realpathSync as realpathSync4, statSync as statSync5 } from "fs";
7953
8090
  import { homedir as homedir6 } from "os";
7954
8091
  import { dirname as dirname11, isAbsolute as isAbsolute3, join as join14, relative as relative2, resolve as resolve10 } from "path";
7955
8092
  import { Codex } from "@openai/codex-sdk";
8093
+ function codexNoticeStatus(message) {
8094
+ const firstLine = message.trim().split(`
8095
+ `)[0]?.trim() ?? "";
8096
+ const sentence = /^.*?[.!?](?=\s|$)/.exec(firstLine)?.[0] ?? firstLine;
8097
+ if (!sentence)
8098
+ return "Codex notice";
8099
+ return /^codex\b/i.test(sentence) ? sentence : `Codex: ${sentence}`;
8100
+ }
7956
8101
  function sameCodexUsage(usage, total) {
7957
8102
  return usage.input_tokens === total.inputTokens && usage.output_tokens === total.outputTokens && (usage.cached_input_tokens ?? 0) === total.cachedInputTokens && (usage.cache_write_input_tokens ?? 0) === total.cacheWriteInputTokens;
7958
8103
  }
@@ -8370,8 +8515,7 @@ async function* codexProvider(opts) {
8370
8515
  },
8371
8516
  hooks: vaultHook.hooks,
8372
8517
  model_catalog_json: codexModelCatalogPath,
8373
- mcp_servers: codexMcpServers,
8374
- ...opts.toolPolicy ? { sandbox_permissions: [] } : {}
8518
+ mcp_servers: codexMcpServers
8375
8519
  }
8376
8520
  });
8377
8521
  const threadOptions = {
@@ -8392,7 +8536,7 @@ async function* codexProvider(opts) {
8392
8536
  let currentSessionId = opts.sessionId;
8393
8537
  let usageBaseline = currentSessionId ? readLatestCodexTokenTotals(currentSessionId) : undefined;
8394
8538
  let thread = currentSessionId ? codex.resumeThread(currentSessionId, threadOptions) : codex.startThread(threadOptions);
8395
- let prompt = promptForThread(opts, true);
8539
+ let prompt = promptForThread(opts, !currentSessionId || !opts.systemPrompt || !codexThreadHasSystemPrompt(currentSessionId, opts.systemPrompt));
8396
8540
  let agentTextSoFar = "";
8397
8541
  let currentAgentMessageId;
8398
8542
  let finalText = "";
@@ -8420,6 +8564,8 @@ async function* codexProvider(opts) {
8420
8564
  trackedPids.pids = [];
8421
8565
  let heartbeatTriggered = false;
8422
8566
  let attemptCompleted = false;
8567
+ let turnFailed = false;
8568
+ let streamError;
8423
8569
  let heartbeatTimer = null;
8424
8570
  const scheduleHeartbeat = () => {
8425
8571
  if (heartbeatTimer !== null)
@@ -8548,7 +8694,8 @@ async function* codexProvider(opts) {
8548
8694
  } else if (item.type === "error") {
8549
8695
  const message = String(item.message ?? "");
8550
8696
  if (message !== CODEX_HOOK_TRUST_BYPASS_NOTICE) {
8551
- yield { type: "error", content: message };
8697
+ logger.warn({ message }, "codexProvider: codex non-fatal error item");
8698
+ yield { type: "status", content: codexNoticeStatus(message) };
8552
8699
  }
8553
8700
  }
8554
8701
  break;
@@ -8576,7 +8723,15 @@ async function* codexProvider(opts) {
8576
8723
  yield* extractFileEvents(finalText, "result");
8577
8724
  break;
8578
8725
  }
8726
+ case "error": {
8727
+ const message = event.message || "Codex stream error";
8728
+ logger.warn({ message }, "codexProvider: codex stream error event");
8729
+ streamError = message;
8730
+ yield { type: "status", content: codexNoticeStatus(message) };
8731
+ break;
8732
+ }
8579
8733
  case "turn.failed": {
8734
+ turnFailed = true;
8580
8735
  stopReason = "error";
8581
8736
  yield {
8582
8737
  type: "error",
@@ -8588,6 +8743,10 @@ async function* codexProvider(opts) {
8588
8743
  break;
8589
8744
  }
8590
8745
  }
8746
+ if (!attemptCompleted && !turnFailed && streamError) {
8747
+ stopReason = "error";
8748
+ yield { type: "error", content: streamError };
8749
+ }
8591
8750
  } catch (err) {
8592
8751
  if (abortSignal?.aborted)
8593
8752
  return;
@@ -23583,4 +23742,4 @@ export {
23583
23742
  DEFAULT_SELF_CONFIG_PRODUCT
23584
23743
  };
23585
23744
 
23586
- //# debugId=CC840147C9D89D8164756E2164756E21
23745
+ //# debugId=AC0BD394FD56770E64756E2164756E21