negotium 0.1.20 → 0.1.21

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 (34) hide show
  1. package/dist/agent-helpers.js +119 -9
  2. package/dist/agent-helpers.js.map +10 -8
  3. package/dist/cron.js +108 -35
  4. package/dist/cron.js.map +16 -15
  5. package/dist/hosted-agent.js +2 -2
  6. package/dist/hosted-agent.js.map +2 -2
  7. package/dist/main.js +116 -38
  8. package/dist/main.js.map +16 -15
  9. package/dist/prompts.js +98 -9
  10. package/dist/prompts.js.map +6 -5
  11. package/dist/runtime/scripts/browser-passkey-policy.mjs +36 -0
  12. package/dist/runtime/scripts/mcp-patchright-http.mjs +14 -4
  13. package/dist/runtime/src/agents/archiver.ts +0 -14
  14. package/dist/runtime/src/agents/idle-archiver.ts +21 -0
  15. package/dist/runtime/src/agents/mcp-tools/self-config.ts +1 -1
  16. package/dist/runtime/src/agents/mcp-tools/spawn-subagent.ts +6 -1
  17. package/dist/runtime/src/agents/memory-archive-policy.ts +34 -0
  18. package/dist/runtime/src/agents/model-catalog.ts +84 -18
  19. package/dist/runtime/src/platform/playwright/manager.ts +4 -2
  20. package/dist/runtime/src/prompts/builders.ts +36 -7
  21. package/dist/runtime/src/runtime/turn-runner.ts +2 -0
  22. package/dist/runtime/src/storage/topic-archive.ts +5 -2
  23. package/dist/runtime/src/topics/lifecycle.ts +2 -1
  24. package/dist/runtime/src/topics/session.ts +2 -0
  25. package/dist/runtime/src/version.ts +1 -1
  26. package/dist/storage.js +23 -3
  27. package/dist/storage.js.map +5 -4
  28. package/dist/types/packages/core/src/agents/idle-archiver.d.ts +2 -0
  29. package/dist/types/packages/core/src/agents/memory-archive-policy.d.ts +14 -0
  30. package/dist/types/packages/core/src/agents/model-catalog.d.ts +77 -0
  31. package/dist/types/packages/core/src/prompts/builders.d.ts +5 -1
  32. package/dist/types/packages/core/src/storage/topic-archive.d.ts +1 -0
  33. package/dist/types/packages/core/src/version.d.ts +1 -1
  34. package/package.json +2 -2
@@ -3321,7 +3321,7 @@ import { createRequire } from "module";
3321
3321
  import { dirname as dirname6, join as join11 } from "path";
3322
3322
 
3323
3323
  // ../../packages/core/src/version.ts
3324
- var NEGOTIUM_VERSION = "0.1.20";
3324
+ var NEGOTIUM_VERSION = "0.1.21";
3325
3325
 
3326
3326
  // ../../packages/core/src/agents/codex-native-multi-agent.ts
3327
3327
  var NEGOTIUM_MODEL_CATALOG = "negotium-model-catalog.json";
@@ -4418,6 +4418,86 @@ var WsHub = {
4418
4418
  // ../../packages/core/src/prompts/builders.ts
4419
4419
  import { readFileSync as readFileSync9 } from "fs";
4420
4420
  import { resolve as resolve5 } from "path";
4421
+
4422
+ // ../../packages/core/src/agents/model-catalog.ts
4423
+ var CODEX_PRO_20X_COST = "ChatGPT Pro 20x subscription: $200/month";
4424
+ var CODEX_COMMUNITY_WEEKLY = "Community plan-level observation: roughly 2\u20134B raw/cached tokens per week; fresh-input equivalent is much lower and unstable (low confidence)";
4425
+ var CLAUDE_MAX_20X_COST = "Claude Max 20x subscription: $200/month";
4426
+ var CLAUDE_COMMUNITY_SESSION = "Community observations vary from roughly 220\u2013250K locally displayed tokens per 5-hour session to billions of cache-heavy raw tokens per week; calibrated reports value a full weekly allowance around $680\u2013$1,900 at API rates. Recent heavy-model reports reach the weekly cap after about 4\u20135 full sessions (low confidence; not a token cap)";
4427
+ var SELECTABLE_MODELS = [
4428
+ {
4429
+ model: "gpt-5.6-sol",
4430
+ agent: "codex",
4431
+ description: "Highest-capability Codex route for the hardest agentic coding work.",
4432
+ intelligenceTier: "fable",
4433
+ routingSummary: "hardest coding work; 5x Codex quota cost",
4434
+ accessCost: CODEX_PRO_20X_COST,
4435
+ marginalTokenCost: "Codex credits: $5/M uncached input, $0.50/M cached input, $30/M output",
4436
+ estimatedUsage: `Official Pro 20x range: 300\u20131,800 local messages per 5 hours; quota weight 5x Luna. ${CODEX_COMMUNITY_WEEKLY}`
4437
+ },
4438
+ {
4439
+ model: "gpt-5.6-terra",
4440
+ agent: "codex",
4441
+ description: "High-capability Codex route for complex coding and reasoning.",
4442
+ intelligenceTier: "opus",
4443
+ routingSummary: "complex coding and reasoning; 2.5x Codex quota cost",
4444
+ accessCost: CODEX_PRO_20X_COST,
4445
+ marginalTokenCost: "Codex credits: $2.50/M uncached input, $0.25/M cached input, $15/M output",
4446
+ estimatedUsage: `Official Pro 20x range: 400\u20132,200 local messages per 5 hours; quota weight 2.5x Luna. ${CODEX_COMMUNITY_WEEKLY}`
4447
+ },
4448
+ {
4449
+ model: "gpt-5.6-luna",
4450
+ agent: "codex",
4451
+ description: "Default Codex route with strong everyday coding intelligence.",
4452
+ intelligenceTier: "sonnet",
4453
+ routingSummary: "everyday coding default; lowest Codex quota cost (1x)",
4454
+ accessCost: CODEX_PRO_20X_COST,
4455
+ marginalTokenCost: "Codex credits: $1/M uncached input, $0.10/M cached input, $6/M output",
4456
+ estimatedUsage: `Official Pro 20x range: 1,000\u20135,600 local messages per 5 hours; lowest Codex quota weight (1x). ${CODEX_COMMUNITY_WEEKLY}`
4457
+ },
4458
+ {
4459
+ model: "fable",
4460
+ agent: "claude",
4461
+ description: "Highest-capability Claude route for the hardest and longest-running tasks.",
4462
+ intelligenceTier: "fable",
4463
+ routingSummary: "hardest long-running work; highest Claude cost; explicit request only",
4464
+ accessCost: CLAUDE_MAX_20X_COST,
4465
+ marginalTokenCost: "Claude API/extra usage: $10/M input, $12.50/M cache write, $1/M cache read, $50/M output",
4466
+ estimatedUsage: `${CLAUDE_COMMUNITY_SESSION}; Fable drains weighted quota fastest, so use only on explicit user request. No stable per-model token cap is published.`
4467
+ },
4468
+ {
4469
+ model: "opus",
4470
+ agent: "claude",
4471
+ description: "High-capability Claude route for complex reasoning and tool-heavy work.",
4472
+ intelligenceTier: "opus",
4473
+ routingSummary: "complex reasoning and tool-heavy work; about 2.5x Sonnet marginal cost",
4474
+ accessCost: CLAUDE_MAX_20X_COST,
4475
+ marginalTokenCost: "Claude API/extra usage: $5/M input, $6.25/M cache write, $0.50/M cache read, $25/M output",
4476
+ estimatedUsage: `${CLAUDE_COMMUNITY_SESSION}; Opus uses the shared all-model weekly pool more quickly than Sonnet. No stable per-model token cap is published.`
4477
+ },
4478
+ {
4479
+ model: "sonnet",
4480
+ agent: "claude",
4481
+ description: "Default Claude route for capable, efficient everyday work.",
4482
+ intelligenceTier: "sonnet",
4483
+ routingSummary: "capable everyday default; lowest Claude model cost",
4484
+ accessCost: CLAUDE_MAX_20X_COST,
4485
+ marginalTokenCost: "Claude API/extra usage introductory rate: $2/M input, $2.50/M cache write, $0.20/M cache read, $10/M output through 2026-08-31; then $3/M input and $15/M output",
4486
+ estimatedUsage: `${CLAUDE_COMMUNITY_SESSION}; Sonnet also has a separate weekly allowance and normally provides the highest Claude throughput. No stable weekly token cap is published.`
4487
+ },
4488
+ {
4489
+ model: "deepseek-pro",
4490
+ agent: "maestro",
4491
+ description: "API-priced Sonnet-level route for cost-efficient everyday work.",
4492
+ intelligenceTier: "sonnet",
4493
+ routingSummary: "cost-efficient everyday work; pay-per-token and cheapest route",
4494
+ accessCost: "DeepSeek V4 Pro pay-as-you-go API; no monthly subscription required",
4495
+ marginalTokenCost: "DeepSeek API: $0.435/M uncached input, $0.003625/M cached input, $0.87/M output",
4496
+ estimatedUsage: "No subscription token cap; pay per token. Official account concurrency limit is 500 requests."
4497
+ }
4498
+ ];
4499
+
4500
+ // ../../packages/core/src/prompts/builders.ts
4421
4501
  var PROMPTS_DIR = resolve5(PROJECT_ROOT, "src/prompts");
4422
4502
  var SESSIONS_DIR = resolve5(PROMPTS_DIR, "sessions");
4423
4503
  function loadAgentPrompt(filename) {
@@ -5151,7 +5231,6 @@ function ensurePersonalGeneral(userId) {
5151
5231
 
5152
5232
  // ../../packages/core/src/agents/archiver.ts
5153
5233
  var MAX_BRIEF_ENTRIES = 8;
5154
- var MIN_ARCHIVE_MESSAGES = 4;
5155
5234
  var MAX_SESSION_STEPS = 20;
5156
5235
  var activeArchiverSessions = new Map;
5157
5236
  function boundedSessionText(value) {
@@ -5179,10 +5258,6 @@ function getArchiverDef() {
5179
5258
  }
5180
5259
  function runArchiverTurn(params) {
5181
5260
  const { userId, topicId, topicTitle, archivePath, messageCount, mode = "deleted-topic" } = params;
5182
- if (mode !== "active-topic" && messageCount < MIN_ARCHIVE_MESSAGES) {
5183
- logger.info({ userId, topicTitle, messageCount, min: MIN_ARCHIVE_MESSAGES }, "archiver: skipped \u2014 too few messages to distil");
5184
- return false;
5185
- }
5186
5261
  let archiverDef;
5187
5262
  try {
5188
5263
  archiverDef = getArchiverDef();
@@ -5391,6 +5466,25 @@ ${rolled.join(`
5391
5466
  }
5392
5467
  }
5393
5468
 
5469
+ // ../../packages/core/src/agents/memory-archive-policy.ts
5470
+ function countMemoryArchiveExchanges(rows) {
5471
+ let waitingForAssistant = false;
5472
+ let completed = 0;
5473
+ for (const row of rows) {
5474
+ const assistant = row.author_id === "ai" || Boolean(row.agent_type);
5475
+ const conversational = row.kind == null || row.kind === "message";
5476
+ if (!assistant && row.author_id !== "system" && conversational) {
5477
+ waitingForAssistant = true;
5478
+ continue;
5479
+ }
5480
+ if (assistant && conversational && waitingForAssistant) {
5481
+ completed++;
5482
+ waitingForAssistant = false;
5483
+ }
5484
+ }
5485
+ return completed;
5486
+ }
5487
+
5394
5488
  // ../../packages/core/src/storage/runtime-leases.ts
5395
5489
  import { randomUUID as randomUUID5 } from "crypto";
5396
5490
 
@@ -5880,8 +5974,9 @@ function archiveTopicMessages(topicId, topicTitle, options = {}) {
5880
5974
  counter++;
5881
5975
  }
5882
5976
  }
5883
- logger.info({ topicId, topicTitle, archive: path, messageCount: rows.length, lastRowid }, "archiveTopicMessages: archived topic messages");
5884
- return { path, messageCount: rows.length, lastRowid };
5977
+ const exchangeCount = countMemoryArchiveExchanges(rows);
5978
+ logger.info({ topicId, topicTitle, archive: path, messageCount: rows.length, exchangeCount, lastRowid }, "archiveTopicMessages: archived topic messages");
5979
+ return { path, messageCount: rows.length, exchangeCount, lastRowid };
5885
5980
  }
5886
5981
 
5887
5982
  // ../../packages/core/src/storage/topic-archive-state.ts
@@ -6078,6 +6173,7 @@ function archiveActiveTopicForMemory(topicId, userId, options) {
6078
6173
  if (!options.allowMentionOnly && topic.aiMode === "mention")
6079
6174
  return "mention-only-channel";
6080
6175
  let skipped = "empty";
6176
+ let skipMemoryTurn = false;
6081
6177
  const claim = claimTopicArchiveJob(topicId, (afterRowid) => {
6082
6178
  const pending = getMessagesForTopicAfterRowid(topicId, afterRowid);
6083
6179
  const minMessages = options.minMessages;
@@ -6086,6 +6182,8 @@ function archiveActiveTopicForMemory(topicId, userId, options) {
6086
6182
  logger.debug({ topicId, topicTitle: topic.title, pending: pending.length, minMessages }, "topic-memory-archiver: skipped below threshold");
6087
6183
  return null;
6088
6184
  }
6185
+ const exchangeCount = countMemoryArchiveExchanges(pending);
6186
+ skipMemoryTurn = options.minExchanges !== undefined && exchangeCount < options.minExchanges;
6089
6187
  const archived = (options.archiveMessages ?? archiveTopicMessages)(topicId, topic.title, {
6090
6188
  afterRowid,
6091
6189
  reason: options.reason
@@ -6103,6 +6201,18 @@ function archiveActiveTopicForMemory(topicId, userId, options) {
6103
6201
  if (claim.kind === "busy")
6104
6202
  return "busy";
6105
6203
  const { job } = claim;
6204
+ if (skipMemoryTurn) {
6205
+ settleTopicArchiveJob(topicId, job.archivePath, true);
6206
+ logger.info({
6207
+ topicId,
6208
+ topicTitle: topic.title,
6209
+ messageCount: job.messageCount,
6210
+ minExchanges: options.minExchanges,
6211
+ archive: job.archivePath,
6212
+ reason: options.reason
6213
+ }, "topic-memory-archiver: raw snapshot preserved below exchange threshold");
6214
+ return "below-threshold";
6215
+ }
6106
6216
  const memoryTopic = getTopicMemoryOrigin(topicId) ?? topic;
6107
6217
  const launched = (options.launchArchiver ?? runArchiverTurn)({
6108
6218
  userId,
@@ -6255,4 +6365,4 @@ export {
6255
6365
  VAULT_BROKER_REDIRECT_ERROR
6256
6366
  };
6257
6367
 
6258
- //# debugId=03A8268BD14CA74064756E2164756E21
6368
+ //# debugId=AF4B0BAEC1BE82AE64756E2164756E21