negotium 0.23.2 → 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-s34sv3d2.js → chunk-ggdwn8d5.js} +3 -3
  4. package/dist/{chunk-s34sv3d2.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 +240 -21
  14. package/dist/main.js.map +11 -10
  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
@@ -5015,6 +5015,49 @@ function extractCodexForkedFromId(jsonl) {
5015
5015
  return;
5016
5016
  }
5017
5017
  }
5018
+ function extractLatestCodexSystemInstructionsTurn(jsonl) {
5019
+ const lines = jsonl.trimEnd().split(`
5020
+ `);
5021
+ for (let index = lines.length - 1;index >= 0; index -= 1) {
5022
+ const line = lines[index] ?? "";
5023
+ if (!line.includes("[System Instructions]"))
5024
+ continue;
5025
+ try {
5026
+ const entry = JSON.parse(line);
5027
+ if (entry.type !== "response_item")
5028
+ continue;
5029
+ if (entry.payload?.type !== "message" || entry.payload.role !== "user")
5030
+ continue;
5031
+ const text = (entry.payload.content ?? []).map((part) => typeof part.text === "string" ? part.text : "").join("");
5032
+ if (text.startsWith(`[System Instructions]
5033
+ `))
5034
+ return text;
5035
+ } catch {}
5036
+ }
5037
+ return;
5038
+ }
5039
+ function codexThreadHasSystemPrompt(threadId, systemPrompt, depth = 0) {
5040
+ const path = latestCodexRolloutPath(threadId);
5041
+ if (!path)
5042
+ return false;
5043
+ try {
5044
+ const jsonl = readFileSync6(path, "utf8");
5045
+ const latest = extractLatestCodexSystemInstructionsTurn(jsonl);
5046
+ if (latest !== undefined) {
5047
+ return latest.startsWith(`[System Instructions]
5048
+ ${systemPrompt}
5049
+
5050
+ `);
5051
+ }
5052
+ if (depth >= 8)
5053
+ return false;
5054
+ const parentId = extractCodexForkedFromId(jsonl);
5055
+ return parentId && parentId !== threadId ? codexThreadHasSystemPrompt(parentId, systemPrompt, depth + 1) : false;
5056
+ } catch (error) {
5057
+ logger.debug({ error, threadId }, "codex system prompt: rollout read failed");
5058
+ return false;
5059
+ }
5060
+ }
5018
5061
  function readLatestCodexTokenTotals(threadId, depth = 0) {
5019
5062
  const path = latestCodexRolloutPath(threadId);
5020
5063
  if (!path)
@@ -5284,7 +5327,7 @@ var init_codex = __esm(async () => {
5284
5327
  });
5285
5328
 
5286
5329
  // ../../packages/core/src/version.ts
5287
- var NEGOTIUM_VERSION = "0.23.2";
5330
+ var NEGOTIUM_VERSION = "0.23.4";
5288
5331
 
5289
5332
  // ../../packages/core/src/agents/codex-native-multi-agent.ts
5290
5333
  import { spawn as spawn2 } from "child_process";
@@ -9739,6 +9782,97 @@ function memoizeImport(loader) {
9739
9782
  };
9740
9783
  }
9741
9784
 
9785
+ // ../../packages/core/src/agents/claude-notices.ts
9786
+ function modelLabel(id) {
9787
+ const match = /^claude-([a-z]+)-(\d+)-(\d+)/.exec(id);
9788
+ if (!match)
9789
+ return id;
9790
+ const [, family = "", major, minor] = match;
9791
+ return `${family.charAt(0).toUpperCase()}${family.slice(1)} ${major}.${minor}`;
9792
+ }
9793
+ function rateLimitNotice(m) {
9794
+ const { status, rateLimitType } = m.rate_limit_info;
9795
+ const limit = rateLimitType ? `${RATE_LIMIT_TEXT[rateLimitType] ?? ""} `.trimStart() : "";
9796
+ if (status === "allowed_warning")
9797
+ return `Nearing your ${limit}Claude usage limit`;
9798
+ if (status === "rejected")
9799
+ return `Reached your ${limit}Claude usage limit`;
9800
+ return;
9801
+ }
9802
+ function claudeNoticeStatus(message) {
9803
+ try {
9804
+ if (message.type === "rate_limit_event")
9805
+ return rateLimitNotice(message);
9806
+ if (message.type !== "system")
9807
+ return;
9808
+ const handler = SYSTEM_NOTICES[message.subtype];
9809
+ if (!handler) {
9810
+ logger.debug({ subtype: message.subtype, msg: message }, "claudeProvider: system message (unhandled subtype)");
9811
+ return;
9812
+ }
9813
+ const status = handler(message);
9814
+ if (status)
9815
+ logger.warn({ subtype: message.subtype, status }, "claudeProvider: notice");
9816
+ return status;
9817
+ } catch (err) {
9818
+ logger.debug({ err, msg: message }, "claudeProvider: notice mapping failed");
9819
+ return;
9820
+ }
9821
+ }
9822
+ var API_ERROR_TEXT, RATE_LIMIT_TEXT, DENIAL_TEXT, SYSTEM_NOTICES;
9823
+ var init_claude_notices = __esm(() => {
9824
+ init_logger();
9825
+ API_ERROR_TEXT = {
9826
+ overloaded: "Claude is overloaded",
9827
+ rate_limit: "Claude rate limit hit",
9828
+ server_error: "Claude API error",
9829
+ unknown: "Claude request failed",
9830
+ authentication_failed: "Claude sign-in failed",
9831
+ oauth_org_not_allowed: "Organization not allowed for Claude",
9832
+ account_on_hold: "Claude account is on hold",
9833
+ verification_required: "Claude account needs verification",
9834
+ billing_error: "Claude billing issue",
9835
+ invalid_request: "Claude rejected the request",
9836
+ model_not_found: "Claude model not found",
9837
+ max_output_tokens: "Claude reply hit the length limit",
9838
+ cloud_credential_error: "Cloud credentials failed"
9839
+ };
9840
+ RATE_LIMIT_TEXT = {
9841
+ five_hour: "5-hour",
9842
+ seven_day: "weekly",
9843
+ seven_day_opus: "weekly Opus",
9844
+ seven_day_sonnet: "weekly Sonnet",
9845
+ seven_day_overage_included: "weekly",
9846
+ overage: "extra usage"
9847
+ };
9848
+ DENIAL_TEXT = {
9849
+ rule: "by a permission rule",
9850
+ mode: "by the permission mode",
9851
+ classifier: "by the safety check",
9852
+ asyncAgent: "for a background agent"
9853
+ };
9854
+ SYSTEM_NOTICES = {
9855
+ api_retry: (m) => {
9856
+ const reason = m.error_status === null ? "Lost connection to Claude" : API_ERROR_TEXT[m.error] ?? "Claude request failed";
9857
+ const delay2 = Math.round(m.retry_delay_ms / 1000);
9858
+ const when = delay2 > 0 ? `in ${delay2}s` : "now";
9859
+ return `${reason} \xB7 retrying ${when} (${m.attempt}/${m.max_retries})`;
9860
+ },
9861
+ model_refusal_fallback: (m) => m.direction === "retry" ? `${modelLabel(m.original_model)} declined \xB7 ${modelLabel(m.fallback_model)} is answering instead` : m.content || undefined,
9862
+ model_refusal_no_fallback: (m) => `${modelLabel(m.original_model)} declined this request`,
9863
+ permission_denied: (m) => {
9864
+ const tool = m.tool_name.split("__").at(-1) || m.tool_name;
9865
+ const why = m.decision_reason ? `: ${m.decision_reason}` : ` ${DENIAL_TEXT[m.decision_reason_type ?? ""] ?? ""}`.trimEnd();
9866
+ return `${tool} was blocked${why}`;
9867
+ },
9868
+ informational: (m) => m.prevent_continuation || m.level === "warning" || m.level === "suggestion" ? m.content : undefined,
9869
+ mirror_error: (m) => {
9870
+ logger.warn({ error: m.error }, "claudeProvider: transcript mirror batch dropped");
9871
+ return;
9872
+ }
9873
+ };
9874
+ });
9875
+
9742
9876
  // ../../packages/core/src/agents/deep-map.ts
9743
9877
  function deepMapStrings2(value2, fn) {
9744
9878
  if (typeof value2 === "string")
@@ -10237,12 +10371,13 @@ async function* claudeProvider(opts) {
10237
10371
  yield { type: "tool_use_summary", summary: m.summary };
10238
10372
  continue;
10239
10373
  }
10240
- if (message.type === "system") {
10241
- const m = message;
10242
- if (m.subtype === "init") {
10243
- yield { type: "session", sessionId: m.session_id };
10374
+ if (message.type === "system" || message.type === "rate_limit_event") {
10375
+ if (message.type === "system" && message.subtype === "init") {
10376
+ yield { type: "session", sessionId: message.session_id };
10244
10377
  } else {
10245
- logger.debug({ subtype: m.subtype, msg: m }, "claudeProvider: system message (unhandled subtype)");
10378
+ const status = claudeNoticeStatus(message);
10379
+ if (status)
10380
+ yield { type: "status", content: status };
10246
10381
  }
10247
10382
  continue;
10248
10383
  }
@@ -10353,6 +10488,7 @@ async function* claudeProvider(opts) {
10353
10488
  }
10354
10489
  var CLAUDE_DEFAULT_DISALLOWED_TOOLS, CLAUDE_NATIVE_AGENT_TOOLS, CLAUDE_IMAGE_MAX_BYTES, CLAUDE_IMAGE_MIME_TYPES, CLAUDE_ABORT_SIGKILL_DELAY_MS = 2500, claudeProcessExitListeners;
10355
10490
  var init_claude_provider = __esm(async () => {
10491
+ init_claude_notices();
10356
10492
  init_claude_registry();
10357
10493
  init_vault_tool_policy();
10358
10494
  init_file_events();
@@ -11510,13 +11646,22 @@ var exports_codex_provider = {};
11510
11646
  __export(exports_codex_provider, {
11511
11647
  toCodexMcpServers: () => toCodexMcpServers,
11512
11648
  normalizeCodexTurnUsage: () => normalizeCodexTurnUsage,
11513
- codexProvider: () => codexProvider
11649
+ codexProvider: () => codexProvider,
11650
+ codexNoticeStatus: () => codexNoticeStatus
11514
11651
  });
11515
11652
  import { execFileSync as execFileSync6 } from "child_process";
11516
11653
  import { existsSync as existsSync20, readFileSync as readFileSync16, realpathSync as realpathSync5, statSync as statSync6 } from "fs";
11517
11654
  import { homedir as homedir6 } from "os";
11518
11655
  import { dirname as dirname14, isAbsolute as isAbsolute4, join as join20, relative as relative3, resolve as resolve14 } from "path";
11519
11656
  import { Codex } from "@openai/codex-sdk";
11657
+ function codexNoticeStatus(message) {
11658
+ const firstLine = message.trim().split(`
11659
+ `)[0]?.trim() ?? "";
11660
+ const sentence = /^.*?[.!?](?=\s|$)/.exec(firstLine)?.[0] ?? firstLine;
11661
+ if (!sentence)
11662
+ return "Codex notice";
11663
+ return /^codex\b/i.test(sentence) ? sentence : `Codex: ${sentence}`;
11664
+ }
11520
11665
  function sameCodexUsage(usage, total) {
11521
11666
  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;
11522
11667
  }
@@ -11934,8 +12079,7 @@ async function* codexProvider(opts) {
11934
12079
  },
11935
12080
  hooks: vaultHook.hooks,
11936
12081
  model_catalog_json: codexModelCatalogPath,
11937
- mcp_servers: codexMcpServers,
11938
- ...opts.toolPolicy ? { sandbox_permissions: [] } : {}
12082
+ mcp_servers: codexMcpServers
11939
12083
  }
11940
12084
  });
11941
12085
  const threadOptions = {
@@ -11956,7 +12100,7 @@ async function* codexProvider(opts) {
11956
12100
  let currentSessionId = opts.sessionId;
11957
12101
  let usageBaseline = currentSessionId ? readLatestCodexTokenTotals(currentSessionId) : undefined;
11958
12102
  let thread = currentSessionId ? codex.resumeThread(currentSessionId, threadOptions) : codex.startThread(threadOptions);
11959
- let prompt = promptForThread(opts, true);
12103
+ let prompt = promptForThread(opts, !currentSessionId || !opts.systemPrompt || !codexThreadHasSystemPrompt(currentSessionId, opts.systemPrompt));
11960
12104
  let agentTextSoFar = "";
11961
12105
  let currentAgentMessageId;
11962
12106
  let finalText = "";
@@ -11984,6 +12128,8 @@ async function* codexProvider(opts) {
11984
12128
  trackedPids.pids = [];
11985
12129
  let heartbeatTriggered = false;
11986
12130
  let attemptCompleted = false;
12131
+ let turnFailed = false;
12132
+ let streamError;
11987
12133
  let heartbeatTimer = null;
11988
12134
  const scheduleHeartbeat = () => {
11989
12135
  if (heartbeatTimer !== null)
@@ -12112,7 +12258,8 @@ async function* codexProvider(opts) {
12112
12258
  } else if (item.type === "error") {
12113
12259
  const message = String(item.message ?? "");
12114
12260
  if (message !== CODEX_HOOK_TRUST_BYPASS_NOTICE) {
12115
- yield { type: "error", content: message };
12261
+ logger.warn({ message }, "codexProvider: codex non-fatal error item");
12262
+ yield { type: "status", content: codexNoticeStatus(message) };
12116
12263
  }
12117
12264
  }
12118
12265
  break;
@@ -12140,7 +12287,15 @@ async function* codexProvider(opts) {
12140
12287
  yield* extractFileEvents(finalText, "result");
12141
12288
  break;
12142
12289
  }
12290
+ case "error": {
12291
+ const message = event.message || "Codex stream error";
12292
+ logger.warn({ message }, "codexProvider: codex stream error event");
12293
+ streamError = message;
12294
+ yield { type: "status", content: codexNoticeStatus(message) };
12295
+ break;
12296
+ }
12143
12297
  case "turn.failed": {
12298
+ turnFailed = true;
12144
12299
  stopReason = "error";
12145
12300
  yield {
12146
12301
  type: "error",
@@ -12152,6 +12307,10 @@ async function* codexProvider(opts) {
12152
12307
  break;
12153
12308
  }
12154
12309
  }
12310
+ if (!attemptCompleted && !turnFailed && streamError) {
12311
+ stopReason = "error";
12312
+ yield { type: "error", content: streamError };
12313
+ }
12155
12314
  } catch (err) {
12156
12315
  if (abortSignal?.aborted)
12157
12316
  return;
@@ -25898,4 +26057,4 @@ export {
25898
26057
  createAgentHealthMcpServer
25899
26058
  };
25900
26059
 
25901
- //# debugId=18366C463A8C391664756E2164756E21
26060
+ //# debugId=3960629E03CACCC364756E2164756E21