@indexnetwork/protocol 6.0.0-rc.375.1 → 6.2.0-rc.377.1

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.
package/CHANGELOG.md CHANGED
@@ -13,7 +13,9 @@ See [STABILITY.md](./STABILITY.md) for the public-contract and tier definitions.
13
13
  ## [Unreleased]
14
14
 
15
15
  ### Added
16
+ - `RawEvidenceOwnerAnswer` is now re-exported from the root barrel alongside the other Lens C negotiation-evidence segment types, so API-side projections (IND-465 slice 2) can type owner-answer evidence without deep imports. Type-only, additive; no runtime change.
16
17
  - Default-off `POOL_QUESTIONS_VISIT_TRIGGER` accessor plus the shared 6h `POOL_VISIT_MINING_DEBOUNCE_MS` debounce window for visit-triggered pool mining: the flag only adds a *when* for the existing mining hook — every mining/question gate (`POOL_QUESTIONS_MODE`, k-anonymity floor, VoI threshold, per-intent budgets, freshness fingerprints, push budgets) applies unchanged (IND-439 visibility-audit slice).
18
+ - Default-off deadlock detection with a persuasion→bargaining mode shift for v2 negotiations (IND-428, dialogue-game backlog item 6): a deterministic trailing-run detector (`assessDeadlock`, no LLM in the decision) flags N consecutive `counter`/`question` turns without convergence (`NEGOTIATION_DEADLOCK_THRESHOLD`, integer >= 2, default 4) and — only when `NEGOTIATION_DEADLOCK_SHIFT_ENABLED` is literally `true` — shifts the system agent's drafting stance from arguing merits to offering concessions/scope reductions, escalating to `ask_user` only where that action is already legally held. The shift changes stance only: locutions, seat vocabularies (`allowedActionsFor`), termination rules, and turn-cap semantics are untouched; externally dispatched turns never receive the stance. The applied shift is recorded once per session as internal-only `tasks.metadata.deadlockShift` (optional `setTaskDeadlockShift` hook; never projected by API surfaces) plus a `negotiation_deadlock_shift` trace event. Detection and persistence fail open, and with the flag off the drafting path is byte-identical to before. The turn protocol's formal dialogue-game framing (locutions, combination rules, commitment store, termination) is documented in `docs/design/negotiation-dialogue-game.md`. Symbols are module-local (deep import from `negotiation/negotiation.deadlock.js`), deliberately not re-exported from the root barrel per the IND-457 externally-consumed-surface policy.
17
19
  - Budgeted scheduled live-eval canary (`eval:canary`): a committed, versioned manifest (`eval/canary/canary.manifest.json`) selects a representative, hard-capped subset of the baseline-backed suites (matching, opportunity, premise, profile) and runs each declared case through its existing harness against real providers, producing the same ER2-versioned run artifacts; a provider-free `--plan` dry-run validates the manifest, caps, and budget math and prints pinned model/judge IDs, git provenance, config/corpus fingerprints, and an honest call-count budget (token/cost telemetry reported as unavailable); outcomes are classified over the existing governance exit contract plus recorded artifact completeness into pass / measured regression / provider incident / baseline incompatibility / insufficient evidence; a post-run leak scan quarantines any output containing secret-like env values before upload; the canary never passes `--update-baseline` and the HyDE canonical study is explicitly excluded from routine scheduling; scheduled + manual execution lives in the non-required `.github/workflows/eval-canary.yml` (IND-447).
18
20
  - Enforced eval baseline compatibility and auditable update governance: exact comparability assessment over harness/schema version, model and judge IDs, selection/full-corpus status, corpus and scoring-config fingerprints, run protocol, and completeness — provably incompatible cohorts are never compared (exit `2`), strict-mode unprovable comparability fails closed (exit `3`), committed schema-v1 baselines keep comparing under the normal policy with explicit notes, `--update-baseline` now requires `--reason` plus a complete full-corpus unfiltered run at a clean identifiable Git revision, every update persists a deterministic reviewable `*.baseline.update.json` provenance/diff summary through the overwrite-safe artifact path, added/removed/skipped cases are reported explicitly, and rolling baselines aggregate only compatible complete full-corpus reports while reporting every excluded artifact with its reason; the beta-binomial comparison and Wilson intervals are unchanged (IND-445).
19
21
  - Provider-free privacy-aware eval artifact viewer with explicit shared v1/v2 and HyDE-public adapters, allowlisted redaction, attempt-aware execution inspection, baseline deltas, accessible offline navigation, safe failure pages, and atomic read-only output (IND-446).
package/dist/index.d.ts CHANGED
@@ -87,7 +87,7 @@ export type { PoolCandidate, DiscriminatorMiningInput, MinedDiscriminator } from
87
87
  export { negotiationEvidenceQuestionsMode, NEGOTIATION_EVIDENCE_MAX_OPPORTUNITIES } from "./opportunity/negotiation-evidence/negotiation-evidence.env.js";
88
88
  export { NegotiationEvidenceMiner } from "./opportunity/negotiation-evidence/negotiation-evidence.miner.js";
89
89
  export { runNegotiationEvidenceShadow } from "./opportunity/negotiation-evidence/negotiation-evidence.shadow.js";
90
- export type { RawEvidenceTurn, RawEvidenceOutcome, RawEvidenceSegment } from "./opportunity/negotiation-evidence/negotiation-evidence.types.js";
90
+ export type { RawEvidenceTurn, RawEvidenceOutcome, RawEvidenceOwnerAnswer, RawEvidenceSegment } from "./opportunity/negotiation-evidence/negotiation-evidence.types.js";
91
91
  export { isOutcomeQuestionsActivated, OUTCOME_MIN_INDEPENDENT_EXAMPLES, OUTCOME_MAX_CANDIDATES, OUTCOME_MAX_PUBLIC_CONTEXT_CHARS } from "./opportunity/outcome/outcome.env.js";
92
92
  export { runOutcomeShadow } from "./opportunity/outcome/outcome.shadow.js";
93
93
  export type { OutcomeLabel, OutcomeExample, OutcomeShadowResult } from "./opportunity/outcome/outcome.types.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAC9D,YAAY,EAAE,mBAAmB,EAAE,QAAQ,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AACtH,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAC5F,OAAO,EAAE,uBAAuB,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AAClG,YAAY,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,2CAA2C,CAAC;AAC3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AACzE,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAInH,YAAY,EAAE,eAA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AE,oCAAoC,EAAE,qCAAqC,EAAE,iCAAiC,EAAE,MAAM,iDAAiD,CAAC;AACjL,OAAO,EAAE,4BAA4B,EAAE,MAAM,sCAAsC,CAAC;AAEpF,iFAAiF;AAEjF,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AAC5E,OAAO,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AAE5E,iFAAiF;AAEjF,OAAO,EAAE,eAAe,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAUrG,+EAA+E;AAE/E,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC","sourcesContent":["// =============================================================================\n// @indexnetwork/protocol — public API barrel\n//\n// This file is the ONLY supported entry point. Deep imports\n// (\"@indexnetwork/protocol/src/...\") are not part of the contract and may break\n// in any release. Every symbol is re-exported explicitly (no wildcards) so the\n// surface is reviewable and changes are intentional.\n//\n// Stability tiers are defined in STABILITY.md. In short:\n// • Stable — Interfaces, Graph factories, Agents, the tool/runtime\n// helpers, and shared schemas.\n// • Experimental — Sections marked @experimental below (advanced graph state\n// types and internal helpers); may change in a minor release.\n// =============================================================================\n\n// ─── Public API (recommended for external consumers) ──────────────────────────\n\nexport { getModelName } from \"./shared/agent/model.config.js\";\nexport type { ResolvedToolContext, ToolDeps, RawToolDefinition, CompiledGraph } from \"./shared/agent/tool.helpers.js\";\nexport { ChatContextAccessError, resolveChatContext } from \"./shared/agent/tool.helpers.js\";\nexport { deriveAllowedNetworkIds, deriveDiscoveryNetworkIds } from \"./shared/agent/tool.scope.js\";\nexport type { ToolScopeType } from \"./shared/agent/tool.scope.js\";\nexport { requestContext } from \"./shared/observability/request-context.js\";\nexport { setLoggerFactory } from \"./shared/observability/log.js\";\nexport { setTimingWrapper } from \"./shared/observability/performance.js\";\nexport { getToolTimeoutPolicy, invokeToolRuntime, toolRuntimeErrorToResult } from \"./shared/agent/tool.runtime.js\";\n\n// ─── Interfaces (implement these to wire up your infrastructure) ───────────────\n\nexport type { McpAuthResolver } from \"./shared/interfaces/auth.interface.js\";\nexport type { Cache, CacheOptions, HydeCache, OpportunityCache } from \"./shared/interfaces/cache.interface.js\";\nexport type { ChatSummaryReader } from \"./shared/interfaces/chat-summary.interface.js\";\nexport type { QuestionGeneratorReader } from \"./shared/interfaces/question-generator.interface.js\";\nexport type { QuestionerDatabase, PersistableQuestion, PersistedQuestion, QuestionFilters, ChatQuestionsHost } from \"./shared/interfaces/questioner.interface.js\";\nexport type { NegotiationSummaryReader } from \"./shared/interfaces/negotiation-summary.interface.js\";\nexport type { DiscoveryNegotiationDigest } from \"./shared/schemas/negotiation-digest.schema.js\";\nexport { NegotiationSummarizer } from \"./negotiation/negotiation.summarizer.js\";\nexport type { ContactServiceAdapter } from \"./shared/interfaces/contact.interface.js\";\nexport type {\n ChatGraphCompositeDatabase,\n UserDatabase,\n SystemDatabase,\n OpportunityGraphDatabase,\n OpportunityControllerDatabase,\n OutcomeOutbox,\n HomeGraphDatabase,\n IntentGraphDatabase,\n HydeGraphDatabase,\n EnrichmentGraphDatabase,\n PremiseGraphDatabase,\n NegotiationGraphDatabase,\n Opportunity,\n OpportunityActor,\n OpportunityStatus,\n AssignmentNetworkMembership,\n CreateOpportunityData,\n} from \"./shared/interfaces/database.interface.js\";\nexport type { Embedder, VectorStoreOption, VectorSearchResult, HydeCandidate, HydeSearchOptions, LensEmbedding } from \"./shared/interfaces/embedder.interface.js\";\nexport type { IntegrationAdapter, IntegrationConnection, IntegrationSession, IntegrationSessionOptions, ToolActionResponse } from \"./shared/interfaces/integration.interface.js\";\nexport type { IntentGraphQueue } from \"./shared/interfaces/queue.interface.js\";\nexport type { Scraper } from \"./shared/interfaces/scraper.interface.js\";\nexport type { DiscoveryRunInput, DiscoveryRunRecord } from \"./shared/interfaces/discovery-run.interface.js\";\nexport type { EnrichmentRunInput, EnrichmentRunRecord } from \"./shared/interfaces/enrichment-run.interface.js\";\nexport type { NegotiationTimeoutQueue, AskUserExpiryPayload } from \"./shared/interfaces/negotiation-events.interface.js\";\nexport type { AgentDispatcher, AgentDispatchResult, NegotiationTurnPayload } from \"./shared/interfaces/agent-dispatcher.interface.js\";\nexport { SYSTEM_AGENT_IDS } from './shared/interfaces/agent.interface.js';\n\n// ─── Shared schemas ───────────────────────────────────────────────────────────\n\nexport { ChatContextDigestSchema, type ChatContextDigest } from \"./shared/schemas/chat-context.schema.js\";\nexport {\n type Question,\n type UnderspecificationType,\n type QuestionStrategy,\n type QuestionGenerationResult,\n type QuestionPurpose,\n type QuestionPoolPush,\n type QuestionVoidedReason,\n type QuestionPoolPushRequestStatus,\n type QuestionPoolPushRequestReason,\n} from \"./shared/schemas/question.schema.js\";\nexport type { PendingQuestionSummary } from \"./shared/schemas/pending-question.schema.js\";\nexport type { McpAuthInput } from \"./shared/schemas/mcp-auth.schema.js\";\nexport type { DiscoverySummary, DiscoveryNegotiation, DiscoveryTurn, DiscoveryOutcome, DiscoveryQuestionInput, NegotiationRole } from \"./shared/schemas/discovery-question.schema.js\";\nexport type { NetworkAssignmentMetadata } from \"./shared/schemas/network-assignment.schema.js\";\nexport { DEFAULT_NETWORK_ASSIGNMENT_THRESHOLD, resolveAssignmentNetworkScope, buildNetworkAssignmentDecision } from \"./shared/assignment/network-assignment.policy.js\";\nexport { buildCandidateEvidence } from \"./opportunity/opportunity.evidence.js\";\n\n// ─── Graph factories ──────────────────────────────────────────────────────────\n\nexport { ChatGraphFactory } from \"./chat/chat.graph.js\";\nexport { type ChatPersonaConfig } from \"./chat/chat.persona.js\";\nexport { NEGOTIATOR_PERSONA_ID, createNegotiatorPersona } from \"./chat/negotiator.persona.js\";\nexport { HomeGraphFactory } from \"./opportunity/feed/feed.graph.js\";\nexport { HydeGraphFactory } from \"./shared/hyde/hyde.graph.js\";\nexport { NetworkGraphFactory } from \"./network/network.graph.js\";\nexport { NetworkMembershipGraphFactory } from \"./network/membership/membership.graph.js\";\nexport { IntentGraphFactory } from \"./intent/intent.graph.js\";\nexport { SemanticVerifier } from \"./intent/intent.verifier.js\";\nexport { IntentNetworkGraphFactory } from \"./network/indexer/indexer.graph.js\";\nexport { MaintenanceGraphFactory } from \"./maintenance/maintenance.graph.js\";\nexport type { MaintenanceGraphDatabase, MaintenanceGraphCache, MaintenanceGraphQueue } from \"./maintenance/maintenance.graph.js\";\nexport { NegotiationGraphFactory, negotiateCandidates } from \"./negotiation/negotiation.graph.js\";\nexport { OpportunityGraphFactory } from \"./opportunity/opportunity.graph.js\";\nexport type { StampNewbornOpportunitiesFn } from \"./opportunity/opportunity.graph.js\";\nexport { EnrichmentGraphFactory } from \"./enrichment/enrichment.graph.js\";\nexport { PremiseGraphFactory } from \"./premise/premise.graph.js\";\n\n// ─── Agents ───────────────────────────────────────────────────────────────────\n\nexport { UserContextGenerator } from \"./context/context.generator.js\";\nexport { ChatTitleGenerator } from \"./chat/chat.title.generator.js\";\nexport { ChatInterruptClassifier } from \"./chat/chat.interrupt.classifier.js\";\nexport { ChatSummarizer } from \"./chat/chat.summarizer.js\";\nexport { HydeGenerator } from \"./shared/hyde/hyde.generator.js\";\nexport { SuggestionGenerator } from \"./chat/chat.suggester.js\";\nexport { generateInviteMessage } from \"./contact/contact.inviter.js\";\nexport { IntentIndexer } from \"./intent/intent.indexer.js\";\nexport type { IntentIndexerOutput } from \"./intent/intent.indexer.js\";\nexport { LensInferrer } from \"./shared/hyde/lens.inferrer.js\";\nexport { NegotiationInsightsGenerator } from \"./negotiation/insight.generator.js\";\nexport type { NegotiationDigest } from \"./negotiation/insight.generator.js\";\nexport { IndexNegotiator } from \"./negotiation/negotiation.agent.js\";\nexport { NegotiationScreener } from \"./negotiation/negotiation.screen.js\";\nexport { NegotiationReflector } from \"./negotiation/negotiation.reflect.js\";\nexport type { DistilledMemory, ReflectionTranscriptEntry, NegotiationReflectionInput, ChatReflectionInput, NegotiationReflectJobData, ReflectEnqueueFn } from \"./negotiation/negotiation.reflect.js\";\nexport type { NegotiatorMemoryEntry } from \"./negotiation/negotiation.memory.js\";\nexport { QuestionerAgent } from \"./questioner/questioner.agent.js\";\nexport type { QuestionerInput, UptakeQuestionerInput, QuestionerEnqueuePayload, QuestionerEnqueueFn, PoolDiscoveryContext } from \"./questioner/questioner.types.js\";\nexport { isQuestionerEnabled, isUptakeGuardEnabled, uptakeAuthorityThreshold } from \"./questioner/questioner.env.js\";\nexport { PoolDiscriminatorMiner } from \"./opportunity/discriminator/discriminator.miner.js\";\nexport { PoolDiscriminatorAssigner } from \"./opportunity/discriminator/discriminator.assigner.js\";\nexport type { PoolDiscriminatorAssignmentInput, PoolDiscriminatorAssignedAxis } from \"./opportunity/discriminator/discriminator.assigner.js\";\nexport { runPoolDiscriminatorShadow } from \"./opportunity/discriminator/discriminator.shadow.js\";\nexport {\n poolQuestionsMiningMode,\n poolQuestionsMode,\n poolQuestionsPushMode,\n poolQuestionsStampNewborn,\n POOL_DISCRIMINATOR_MIN_POOL_SIZE,\n POOL_DISCRIMINATOR_MAX_CANDIDATES,\n POOL_DISCRIMINATOR_MAX_PUBLIC_CONTEXT_CHARS,\n POOL_QUESTION_MIN_VOI,\n POOL_QUESTION_MAX_PENDING_PER_INTENT,\n} from \"./opportunity/discriminator/discriminator.env.js\";\nexport { poolQuestionsRanking, POOL_RERUN_DEBOUNCE_MS } from \"./opportunity/discriminator/discriminator.env.js\";\nexport { poolQuestionsVisitTrigger, POOL_VISIT_MINING_DEBOUNCE_MS } from \"./opportunity/discriminator/discriminator.env.js\";\nexport { buildPoolAdjustment, planPoolAdjustments, mergePoolAdjustment } from \"./opportunity/discriminator/discriminator.adjustments.js\";\nexport type { PoolAdjustment, PoolAdjustmentSignal } from \"./opportunity/discriminator/discriminator.adjustments.js\";\nexport { synthesizePoolQuestion, selectQuestionDiscriminators, toQuestionDiscriminator, BOTH_MATTER_LABEL } from \"./opportunity/discriminator/discriminator.question.js\";\nexport { poolQuestionCycleKey, buildPoolQuestionPushMessage } from \"./opportunity/discriminator/discriminator.push.js\";\nexport type { QuestionPoolDiscriminator, QuestionPoolSnapshot } from \"./shared/schemas/question.schema.js\";\nexport type { PoolCandidate, DiscriminatorMiningInput, MinedDiscriminator } from \"./opportunity/discriminator/discriminator.types.js\";\n\n// Lens C — negotiation-evidence questions (IND-433, shadow).\nexport { negotiationEvidenceQuestionsMode, NEGOTIATION_EVIDENCE_MAX_OPPORTUNITIES } from \"./opportunity/negotiation-evidence/negotiation-evidence.env.js\";\nexport { NegotiationEvidenceMiner } from \"./opportunity/negotiation-evidence/negotiation-evidence.miner.js\";\nexport { runNegotiationEvidenceShadow } from \"./opportunity/negotiation-evidence/negotiation-evidence.shadow.js\";\nexport type { RawEvidenceTurn, RawEvidenceOutcome, RawEvidenceSegment } from \"./opportunity/negotiation-evidence/negotiation-evidence.types.js\";\n\n// Lens B — outcome-question shadow (IND-434)\nexport { isOutcomeQuestionsActivated, OUTCOME_MIN_INDEPENDENT_EXAMPLES, OUTCOME_MAX_CANDIDATES, OUTCOME_MAX_PUBLIC_CONTEXT_CHARS } from \"./opportunity/outcome/outcome.env.js\";\nexport { runOutcomeShadow } from \"./opportunity/outcome/outcome.shadow.js\";\nexport type { OutcomeLabel, OutcomeExample, OutcomeShadowResult } from \"./opportunity/outcome/outcome.types.js\";\nexport { OpportunityEvaluator } from \"./opportunity/opportunity.evaluator.js\";\nexport type { EvaluatorInput } from \"./opportunity/opportunity.evaluator.js\";\nexport { OpportunityPresenter, gatherPresenterContext } from \"./opportunity/opportunity.presenter.js\";\nexport { createOpportunityTools } from \"./opportunity/opportunity.tools.js\";\nexport { createEnrichmentTools } from \"./enrichment/enrichment.tools.js\";\nexport type { PresenterDatabase } from \"./opportunity/opportunity.presenter.js\";\n\n// ─── Support utilities ────────────────────────────────────────────────────────\n\nexport { canUserSeeOpportunity, isActionableForViewer, validateOpportunityActors, classifyOpportunity, selectByComposition, FEED_SOFT_TARGETS } from \"./opportunity/opportunity.utils.js\";\nexport { getPrimaryActionLabel } from \"./opportunity/opportunity.labels.js\";\nexport { computeFeedHealth } from \"./opportunity/feed/feed.health.js\";\nexport type { FeedHealthInput } from \"./opportunity/feed/feed.health.js\";\nexport { selectContactsForDiscovery, shouldRunIntroducerDiscovery, runIntroducerDiscovery, MAX_CONTACTS_PER_CYCLE, MAX_CANDIDATES_PER_CONTACT, INTRODUCER_DISCOVERY_SOURCE } from \"./opportunity/opportunity.introducer.js\";\nexport type { IntroducerDiscoveryDatabase, IntroducerDiscoveryQueue, ContactWithIntents } from \"./opportunity/opportunity.introducer.js\";\nexport { persistOpportunities } from \"./opportunity/opportunity.persist.js\";\nexport { presentOpportunity } from \"./opportunity/opportunity.presentation.js\";\nexport type { UserInfo } from \"./opportunity/opportunity.presentation.js\";\nexport { stripUuids, truncateAtBoundary } from \"./opportunity/opportunity.presentation.js\";\nexport { stripUnsupportedOpportunityClaims } from \"./opportunity/opportunity.claim-safety.js\";\nexport { safeFallbackSummary } from \"./opportunity/opportunity.safe-presentation.js\";\nexport { buildApiChatCardPresentationCacheKey, buildDeliveryCardPresentationCacheKey, buildHomeCardPresentationCacheKey } from \"./opportunity/opportunity.presentation-cache.js\";\nexport { getOrCreateDeliveryCardBatch } from \"./opportunity/delivery-card.cache.js\";\n\n// ─── Tools ────────────────────────────────────────────────────────────────────\n\nexport { createToolRegistry } from \"./shared/agent/tool.registry.js\";\nexport { AMBIENT_PARK_WINDOW_MS } from './negotiation/negotiation.tools.js';\nexport { normalizeTelegramHandle } from './shared/utils/telegram-handle.js';\n\n// ─── MCP ──────────────────────────────────────────────────────────────────────\n\nexport { createMcpServer, buildMcpOnboardingMessage, ONBOARDING_ALLOWED } from \"./mcp/mcp.server.js\";\nexport type { ScopedDepsFactory } from \"./mcp/mcp.server.js\";\n\n// ─── States (for advanced graph consumers) ────────────────────────────────────\n// @experimental — internal graph-state shapes; may change in a minor release.\n\nexport type { UserNegotiationContext, NegotiationTurn, NegotiationOutcome, SeedAssessment } from \"./shared/schemas/negotiation-state.schema.js\";\nexport type { NegotiationAction, NegotiationSeat, NegotiationProtocolVersion } from \"./shared/schemas/negotiation-state.schema.js\";\nexport type { NegotiationGraphLike } from \"./negotiation/negotiation.state.js\";\n\n// ─── Negotiation seat rules (v2 client-advocate protocol) ───────────────────\n\nexport { allowedActionsFor, isTerminalAction, isRejectLikeAction, readProtocolVersion, resolveSeat, seatViolationMessage } from \"./negotiation/negotiation.protocol.js\";\n\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,6CAA6C;AAC7C,EAAE;AACF,4DAA4D;AAC5D,gFAAgF;AAChF,+EAA+E;AAC/E,qDAAqD;AACrD,EAAE;AACF,yDAAyD;AACzD,2EAA2E;AAC3E,kDAAkD;AAClD,+EAA+E;AAC/E,iFAAiF;AACjF,gFAAgF;AAEhF,iFAAiF;AAEjF,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAE9D,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAC5F,OAAO,EAAE,uBAAuB,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AAElG,OAAO,EAAE,cAAc,EAAE,MAAM,2CAA2C,CAAC;AAC3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AACzE,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAWnH,OAAO,EAAE,qBAAqB,EAAE,MAAM,yCAAyC,CAAC;AA6BhF,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AAE1E,iFAAiF;AAEjF,OAAO,EAAE,uBAAuB,EAA0B,MAAM,yCAAyC,CAAC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mBAAmB,EAAE,MAAM,gDAAgD,CAAC;AACrF,OAAO,EAAE,oCAAoC,EAAE,qCAAqC,EAAE,iCAAiC,EAAE,MAAM,iDAAiD,CAAC;AACjL,OAAO,EAAE,4BAA4B,EAAE,MAAM,sCAAsC,CAAC;AAEpF,iFAAiF;AAEjF,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AAC5E,OAAO,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AAE5E,iFAAiF;AAEjF,OAAO,EAAE,eAAe,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAUrG,+EAA+E;AAE/E,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC","sourcesContent":["// =============================================================================\n// @indexnetwork/protocol — public API barrel\n//\n// This file is the ONLY supported entry point. Deep imports\n// (\"@indexnetwork/protocol/src/...\") are not part of the contract and may break\n// in any release. Every symbol is re-exported explicitly (no wildcards) so the\n// surface is reviewable and changes are intentional.\n//\n// Stability tiers are defined in STABILITY.md. In short:\n// • Stable — Interfaces, Graph factories, Agents, the tool/runtime\n// helpers, and shared schemas.\n// • Experimental — Sections marked @experimental below (advanced graph state\n// types and internal helpers); may change in a minor release.\n// =============================================================================\n\n// ─── Public API (recommended for external consumers) ──────────────────────────\n\nexport { getModelName } from \"./shared/agent/model.config.js\";\nexport type { ResolvedToolContext, ToolDeps, RawToolDefinition, CompiledGraph } from \"./shared/agent/tool.helpers.js\";\nexport { ChatContextAccessError, resolveChatContext } from \"./shared/agent/tool.helpers.js\";\nexport { deriveAllowedNetworkIds, deriveDiscoveryNetworkIds } from \"./shared/agent/tool.scope.js\";\nexport type { ToolScopeType } from \"./shared/agent/tool.scope.js\";\nexport { requestContext } from \"./shared/observability/request-context.js\";\nexport { setLoggerFactory } from \"./shared/observability/log.js\";\nexport { setTimingWrapper } from \"./shared/observability/performance.js\";\nexport { getToolTimeoutPolicy, invokeToolRuntime, toolRuntimeErrorToResult } from \"./shared/agent/tool.runtime.js\";\n\n// ─── Interfaces (implement these to wire up your infrastructure) ───────────────\n\nexport type { McpAuthResolver } from \"./shared/interfaces/auth.interface.js\";\nexport type { Cache, CacheOptions, HydeCache, OpportunityCache } from \"./shared/interfaces/cache.interface.js\";\nexport type { ChatSummaryReader } from \"./shared/interfaces/chat-summary.interface.js\";\nexport type { QuestionGeneratorReader } from \"./shared/interfaces/question-generator.interface.js\";\nexport type { QuestionerDatabase, PersistableQuestion, PersistedQuestion, QuestionFilters, ChatQuestionsHost } from \"./shared/interfaces/questioner.interface.js\";\nexport type { NegotiationSummaryReader } from \"./shared/interfaces/negotiation-summary.interface.js\";\nexport type { DiscoveryNegotiationDigest } from \"./shared/schemas/negotiation-digest.schema.js\";\nexport { NegotiationSummarizer } from \"./negotiation/negotiation.summarizer.js\";\nexport type { ContactServiceAdapter } from \"./shared/interfaces/contact.interface.js\";\nexport type {\n ChatGraphCompositeDatabase,\n UserDatabase,\n SystemDatabase,\n OpportunityGraphDatabase,\n OpportunityControllerDatabase,\n OutcomeOutbox,\n HomeGraphDatabase,\n IntentGraphDatabase,\n HydeGraphDatabase,\n EnrichmentGraphDatabase,\n PremiseGraphDatabase,\n NegotiationGraphDatabase,\n Opportunity,\n OpportunityActor,\n OpportunityStatus,\n AssignmentNetworkMembership,\n CreateOpportunityData,\n} from \"./shared/interfaces/database.interface.js\";\nexport type { Embedder, VectorStoreOption, VectorSearchResult, HydeCandidate, HydeSearchOptions, LensEmbedding } from \"./shared/interfaces/embedder.interface.js\";\nexport type { IntegrationAdapter, IntegrationConnection, IntegrationSession, IntegrationSessionOptions, ToolActionResponse } from \"./shared/interfaces/integration.interface.js\";\nexport type { IntentGraphQueue } from \"./shared/interfaces/queue.interface.js\";\nexport type { Scraper } from \"./shared/interfaces/scraper.interface.js\";\nexport type { DiscoveryRunInput, DiscoveryRunRecord } from \"./shared/interfaces/discovery-run.interface.js\";\nexport type { EnrichmentRunInput, EnrichmentRunRecord } from \"./shared/interfaces/enrichment-run.interface.js\";\nexport type { NegotiationTimeoutQueue, AskUserExpiryPayload } from \"./shared/interfaces/negotiation-events.interface.js\";\nexport type { AgentDispatcher, AgentDispatchResult, NegotiationTurnPayload } from \"./shared/interfaces/agent-dispatcher.interface.js\";\nexport { SYSTEM_AGENT_IDS } from './shared/interfaces/agent.interface.js';\n\n// ─── Shared schemas ───────────────────────────────────────────────────────────\n\nexport { ChatContextDigestSchema, type ChatContextDigest } from \"./shared/schemas/chat-context.schema.js\";\nexport {\n type Question,\n type UnderspecificationType,\n type QuestionStrategy,\n type QuestionGenerationResult,\n type QuestionPurpose,\n type QuestionPoolPush,\n type QuestionVoidedReason,\n type QuestionPoolPushRequestStatus,\n type QuestionPoolPushRequestReason,\n} from \"./shared/schemas/question.schema.js\";\nexport type { PendingQuestionSummary } from \"./shared/schemas/pending-question.schema.js\";\nexport type { McpAuthInput } from \"./shared/schemas/mcp-auth.schema.js\";\nexport type { DiscoverySummary, DiscoveryNegotiation, DiscoveryTurn, DiscoveryOutcome, DiscoveryQuestionInput, NegotiationRole } from \"./shared/schemas/discovery-question.schema.js\";\nexport type { NetworkAssignmentMetadata } from \"./shared/schemas/network-assignment.schema.js\";\nexport { DEFAULT_NETWORK_ASSIGNMENT_THRESHOLD, resolveAssignmentNetworkScope, buildNetworkAssignmentDecision } from \"./shared/assignment/network-assignment.policy.js\";\nexport { buildCandidateEvidence } from \"./opportunity/opportunity.evidence.js\";\n\n// ─── Graph factories ──────────────────────────────────────────────────────────\n\nexport { ChatGraphFactory } from \"./chat/chat.graph.js\";\nexport { type ChatPersonaConfig } from \"./chat/chat.persona.js\";\nexport { NEGOTIATOR_PERSONA_ID, createNegotiatorPersona } from \"./chat/negotiator.persona.js\";\nexport { HomeGraphFactory } from \"./opportunity/feed/feed.graph.js\";\nexport { HydeGraphFactory } from \"./shared/hyde/hyde.graph.js\";\nexport { NetworkGraphFactory } from \"./network/network.graph.js\";\nexport { NetworkMembershipGraphFactory } from \"./network/membership/membership.graph.js\";\nexport { IntentGraphFactory } from \"./intent/intent.graph.js\";\nexport { SemanticVerifier } from \"./intent/intent.verifier.js\";\nexport { IntentNetworkGraphFactory } from \"./network/indexer/indexer.graph.js\";\nexport { MaintenanceGraphFactory } from \"./maintenance/maintenance.graph.js\";\nexport type { MaintenanceGraphDatabase, MaintenanceGraphCache, MaintenanceGraphQueue } from \"./maintenance/maintenance.graph.js\";\nexport { NegotiationGraphFactory, negotiateCandidates } from \"./negotiation/negotiation.graph.js\";\nexport { OpportunityGraphFactory } from \"./opportunity/opportunity.graph.js\";\nexport type { StampNewbornOpportunitiesFn } from \"./opportunity/opportunity.graph.js\";\nexport { EnrichmentGraphFactory } from \"./enrichment/enrichment.graph.js\";\nexport { PremiseGraphFactory } from \"./premise/premise.graph.js\";\n\n// ─── Agents ───────────────────────────────────────────────────────────────────\n\nexport { UserContextGenerator } from \"./context/context.generator.js\";\nexport { ChatTitleGenerator } from \"./chat/chat.title.generator.js\";\nexport { ChatInterruptClassifier } from \"./chat/chat.interrupt.classifier.js\";\nexport { ChatSummarizer } from \"./chat/chat.summarizer.js\";\nexport { HydeGenerator } from \"./shared/hyde/hyde.generator.js\";\nexport { SuggestionGenerator } from \"./chat/chat.suggester.js\";\nexport { generateInviteMessage } from \"./contact/contact.inviter.js\";\nexport { IntentIndexer } from \"./intent/intent.indexer.js\";\nexport type { IntentIndexerOutput } from \"./intent/intent.indexer.js\";\nexport { LensInferrer } from \"./shared/hyde/lens.inferrer.js\";\nexport { NegotiationInsightsGenerator } from \"./negotiation/insight.generator.js\";\nexport type { NegotiationDigest } from \"./negotiation/insight.generator.js\";\nexport { IndexNegotiator } from \"./negotiation/negotiation.agent.js\";\nexport { NegotiationScreener } from \"./negotiation/negotiation.screen.js\";\nexport { NegotiationReflector } from \"./negotiation/negotiation.reflect.js\";\nexport type { DistilledMemory, ReflectionTranscriptEntry, NegotiationReflectionInput, ChatReflectionInput, NegotiationReflectJobData, ReflectEnqueueFn } from \"./negotiation/negotiation.reflect.js\";\nexport type { NegotiatorMemoryEntry } from \"./negotiation/negotiation.memory.js\";\nexport { QuestionerAgent } from \"./questioner/questioner.agent.js\";\nexport type { QuestionerInput, UptakeQuestionerInput, QuestionerEnqueuePayload, QuestionerEnqueueFn, PoolDiscoveryContext } from \"./questioner/questioner.types.js\";\nexport { isQuestionerEnabled, isUptakeGuardEnabled, uptakeAuthorityThreshold } from \"./questioner/questioner.env.js\";\nexport { PoolDiscriminatorMiner } from \"./opportunity/discriminator/discriminator.miner.js\";\nexport { PoolDiscriminatorAssigner } from \"./opportunity/discriminator/discriminator.assigner.js\";\nexport type { PoolDiscriminatorAssignmentInput, PoolDiscriminatorAssignedAxis } from \"./opportunity/discriminator/discriminator.assigner.js\";\nexport { runPoolDiscriminatorShadow } from \"./opportunity/discriminator/discriminator.shadow.js\";\nexport {\n poolQuestionsMiningMode,\n poolQuestionsMode,\n poolQuestionsPushMode,\n poolQuestionsStampNewborn,\n POOL_DISCRIMINATOR_MIN_POOL_SIZE,\n POOL_DISCRIMINATOR_MAX_CANDIDATES,\n POOL_DISCRIMINATOR_MAX_PUBLIC_CONTEXT_CHARS,\n POOL_QUESTION_MIN_VOI,\n POOL_QUESTION_MAX_PENDING_PER_INTENT,\n} from \"./opportunity/discriminator/discriminator.env.js\";\nexport { poolQuestionsRanking, POOL_RERUN_DEBOUNCE_MS } from \"./opportunity/discriminator/discriminator.env.js\";\nexport { poolQuestionsVisitTrigger, POOL_VISIT_MINING_DEBOUNCE_MS } from \"./opportunity/discriminator/discriminator.env.js\";\nexport { buildPoolAdjustment, planPoolAdjustments, mergePoolAdjustment } from \"./opportunity/discriminator/discriminator.adjustments.js\";\nexport type { PoolAdjustment, PoolAdjustmentSignal } from \"./opportunity/discriminator/discriminator.adjustments.js\";\nexport { synthesizePoolQuestion, selectQuestionDiscriminators, toQuestionDiscriminator, BOTH_MATTER_LABEL } from \"./opportunity/discriminator/discriminator.question.js\";\nexport { poolQuestionCycleKey, buildPoolQuestionPushMessage } from \"./opportunity/discriminator/discriminator.push.js\";\nexport type { QuestionPoolDiscriminator, QuestionPoolSnapshot } from \"./shared/schemas/question.schema.js\";\nexport type { PoolCandidate, DiscriminatorMiningInput, MinedDiscriminator } from \"./opportunity/discriminator/discriminator.types.js\";\n\n// Lens C — negotiation-evidence questions (IND-433, shadow).\nexport { negotiationEvidenceQuestionsMode, NEGOTIATION_EVIDENCE_MAX_OPPORTUNITIES } from \"./opportunity/negotiation-evidence/negotiation-evidence.env.js\";\nexport { NegotiationEvidenceMiner } from \"./opportunity/negotiation-evidence/negotiation-evidence.miner.js\";\nexport { runNegotiationEvidenceShadow } from \"./opportunity/negotiation-evidence/negotiation-evidence.shadow.js\";\nexport type { RawEvidenceTurn, RawEvidenceOutcome, RawEvidenceOwnerAnswer, RawEvidenceSegment } from \"./opportunity/negotiation-evidence/negotiation-evidence.types.js\";\n\n// Lens B — outcome-question shadow (IND-434)\nexport { isOutcomeQuestionsActivated, OUTCOME_MIN_INDEPENDENT_EXAMPLES, OUTCOME_MAX_CANDIDATES, OUTCOME_MAX_PUBLIC_CONTEXT_CHARS } from \"./opportunity/outcome/outcome.env.js\";\nexport { runOutcomeShadow } from \"./opportunity/outcome/outcome.shadow.js\";\nexport type { OutcomeLabel, OutcomeExample, OutcomeShadowResult } from \"./opportunity/outcome/outcome.types.js\";\nexport { OpportunityEvaluator } from \"./opportunity/opportunity.evaluator.js\";\nexport type { EvaluatorInput } from \"./opportunity/opportunity.evaluator.js\";\nexport { OpportunityPresenter, gatherPresenterContext } from \"./opportunity/opportunity.presenter.js\";\nexport { createOpportunityTools } from \"./opportunity/opportunity.tools.js\";\nexport { createEnrichmentTools } from \"./enrichment/enrichment.tools.js\";\nexport type { PresenterDatabase } from \"./opportunity/opportunity.presenter.js\";\n\n// ─── Support utilities ────────────────────────────────────────────────────────\n\nexport { canUserSeeOpportunity, isActionableForViewer, validateOpportunityActors, classifyOpportunity, selectByComposition, FEED_SOFT_TARGETS } from \"./opportunity/opportunity.utils.js\";\nexport { getPrimaryActionLabel } from \"./opportunity/opportunity.labels.js\";\nexport { computeFeedHealth } from \"./opportunity/feed/feed.health.js\";\nexport type { FeedHealthInput } from \"./opportunity/feed/feed.health.js\";\nexport { selectContactsForDiscovery, shouldRunIntroducerDiscovery, runIntroducerDiscovery, MAX_CONTACTS_PER_CYCLE, MAX_CANDIDATES_PER_CONTACT, INTRODUCER_DISCOVERY_SOURCE } from \"./opportunity/opportunity.introducer.js\";\nexport type { IntroducerDiscoveryDatabase, IntroducerDiscoveryQueue, ContactWithIntents } from \"./opportunity/opportunity.introducer.js\";\nexport { persistOpportunities } from \"./opportunity/opportunity.persist.js\";\nexport { presentOpportunity } from \"./opportunity/opportunity.presentation.js\";\nexport type { UserInfo } from \"./opportunity/opportunity.presentation.js\";\nexport { stripUuids, truncateAtBoundary } from \"./opportunity/opportunity.presentation.js\";\nexport { stripUnsupportedOpportunityClaims } from \"./opportunity/opportunity.claim-safety.js\";\nexport { safeFallbackSummary } from \"./opportunity/opportunity.safe-presentation.js\";\nexport { buildApiChatCardPresentationCacheKey, buildDeliveryCardPresentationCacheKey, buildHomeCardPresentationCacheKey } from \"./opportunity/opportunity.presentation-cache.js\";\nexport { getOrCreateDeliveryCardBatch } from \"./opportunity/delivery-card.cache.js\";\n\n// ─── Tools ────────────────────────────────────────────────────────────────────\n\nexport { createToolRegistry } from \"./shared/agent/tool.registry.js\";\nexport { AMBIENT_PARK_WINDOW_MS } from './negotiation/negotiation.tools.js';\nexport { normalizeTelegramHandle } from './shared/utils/telegram-handle.js';\n\n// ─── MCP ──────────────────────────────────────────────────────────────────────\n\nexport { createMcpServer, buildMcpOnboardingMessage, ONBOARDING_ALLOWED } from \"./mcp/mcp.server.js\";\nexport type { ScopedDepsFactory } from \"./mcp/mcp.server.js\";\n\n// ─── States (for advanced graph consumers) ────────────────────────────────────\n// @experimental — internal graph-state shapes; may change in a minor release.\n\nexport type { UserNegotiationContext, NegotiationTurn, NegotiationOutcome, SeedAssessment } from \"./shared/schemas/negotiation-state.schema.js\";\nexport type { NegotiationAction, NegotiationSeat, NegotiationProtocolVersion } from \"./shared/schemas/negotiation-state.schema.js\";\nexport type { NegotiationGraphLike } from \"./negotiation/negotiation.state.js\";\n\n// ─── Negotiation seat rules (v2 client-advocate protocol) ───────────────────\n\nexport { allowedActionsFor, isTerminalAction, isRejectLikeAction, readProtocolVersion, resolveSeat, seatViolationMessage } from \"./negotiation/negotiation.protocol.js\";\n\n"]}
@@ -41,6 +41,16 @@ export interface NegotiationAgentInput {
41
41
  * negotiation. When true, the seat schema and prompt gain the action.
42
42
  */
43
43
  canAskUser?: boolean;
44
+ /**
45
+ * Deadlock→bargaining drafting stance (IND-428, flag-gated by the caller).
46
+ * Present = the graph detected a stalemate (N consecutive counter/question
47
+ * turns) and this turn should be drafted in the bargaining stance —
48
+ * concessions/scope reductions instead of re-arguing merits. v2 only;
49
+ * ignored under v1. Absent → the prompt is byte-identical to before.
50
+ */
51
+ bargaining?: {
52
+ consecutiveNonConvergent: number;
53
+ };
44
54
  /**
45
55
  * Retrieved negotiator memories for the acting user (P5.3 read path).
46
56
  * Rendered as a private prompt section — hard disclosure constraints plus
@@ -1 +1 @@
1
- {"version":3,"file":"negotiation.agent.d.ts","sourceRoot":"/","sources":["negotiation/negotiation.agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAExE,OAAO,EAA2D,KAAK,eAAe,EAAE,KAAK,sBAAsB,EAAE,KAAK,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAEzK,OAAO,KAAK,EAAE,eAAe,EAAE,0BAA0B,EAAE,MAAM,+CAA+C,CAAC;AACjH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4CAA4C,CAAC;AACxF,O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CAAC;IAClD;;;;OAIG;IACH,MAAM,CAAC,EAAE,qBAAqB,EAAE,CAAC;CAClC;AAED,MAAM,WAAW,qBAAqB;IACpC;;;;;;;;;;OAUG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AA0BD;;;;GAIG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;gBAE3B,MAAM,CAAC,EAAE,qBAAqB;IAI1C;;;;;OAKG;IACG,MAAM,CAAC,KAAK,EAAE,qBAAqB,GAAG,OAAO,CAAC,eAAe,CAAC;IAgJpE;;;OAGG;cACa,SAAS,CACvB,KAAK,EAAE,UAAU,CAAC,OAAO,qBAAqB,CAAC,EAC/C,YAAY,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,GACrD,OAAO,CAAC,OAAO,CAAC;CAGpB"}
@@ -3,6 +3,7 @@ import { invokeWithAbortSignal } from "../shared/agent/model-signal.js";
3
3
  import { SystemNegotiationTurnSchema, FinalNegotiationTurnSchema } from "./negotiation.state.js";
4
4
  import { turnSchemaFor, fallbackActionFor } from "./negotiation.protocol.js";
5
5
  import { renderNegotiatorMemorySection } from "./negotiation.memory.js";
6
+ import { renderBargainingShiftSection } from "./negotiation.deadlock.js";
6
7
  import { protocolLogger } from "../shared/observability/protocol.logger.js";
7
8
  const agentLog = protocolLogger("IndexNegotiator");
8
9
  const SYSTEM_PROMPT = `You are the Index Negotiator, an AI agent acting on behalf of {userName}. You represent their interests in a bilateral negotiation about a potential connection on a discovery network.
@@ -19,7 +20,7 @@ Rules:
19
20
  - Focus on concrete intent alignment, not vague overlap.
20
21
  - Do NOT reference internal system details like scores, pre-screens, or evaluator outputs.
21
22
  - suggestedRoles: "agent" = can help, "patient" = seeks help, "peer" = mutual benefit.
22
- {finalTurnInstruction}{negotiatorMemory}`;
23
+ {finalTurnInstruction}{bargainingShift}{negotiatorMemory}`;
23
24
  /** v1 action rules — byte-identical to the pre-seat-rules prompt. */
24
25
  const V1_ACTION_RULES = `- On the FIRST turn: Propose the connection case. Explain why it would benefit both parties. Set action to "propose".
25
26
  - On SUBSEQUENT turns: Evaluate the other agent's arguments. Either:
@@ -91,6 +92,9 @@ export class IndexNegotiator {
91
92
  const seat = input.seat ?? (input.isDiscoverer ? "initiator" : "counterparty");
92
93
  const isFinalTurn = input.isFinalTurn ?? false;
93
94
  const canAskUser = input.canAskUser === true && version === "v2" && !isFinalTurn;
95
+ // Deadlock→bargaining stance (IND-428): v2 only — defense in depth on top
96
+ // of the graph-side gating, mirroring the canAskUser guard above.
97
+ const bargainingActive = input.bargaining != null && version === "v2";
94
98
  const schema = turnSchemaFor(version, seat, isFinalTurn, {
95
99
  system: SystemNegotiationTurnSchema,
96
100
  final: FinalNegotiationTurnSchema,
@@ -128,6 +132,12 @@ QUERY PRIORITY RULE: This search query is the PRIMARY criterion for this negotia
128
132
  .replace("{role}", role)
129
133
  .replace("{networkContext}", networkContext)
130
134
  .replace("{finalTurnInstruction}", finalTurnInstruction)
135
+ .replace("{bargainingShift}", renderBargainingShiftSection({
136
+ active: bargainingActive,
137
+ userName,
138
+ canAskUser,
139
+ consecutiveNonConvergent: input.bargaining?.consecutiveNonConvergent ?? 0,
140
+ }))
131
141
  .replace("{negotiatorMemory}", renderNegotiatorMemorySection(input.memory ?? []));
132
142
  const historyText = input.history.length > 0
133
143
  ? `\n\nNegotiation history:\n${input.history.map((t, i) => {
@@ -1 +1 @@
1
- {"version":3,"file":"negotiation.agent.js","sourceRoot":"/","sources":["negotiation/negotiation.agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,EAAE,2BAA2B,EAAE,0BAA0B,EAA0E,MAAM,wBAAwB,CAAC;AACzK,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAA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GAAG,CAAC;gBACpB,IAAI;gBACJ,OAAO;gBACP,WAAW;gBACX,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;aAC9D,CAAC,CAAC;QACL,CAAC;QAED,MAAM,cAAc,GAAG,iBAAiB,CAAC,OAAO,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;QACrE,QAAQ,CAAC,IAAI,CAAC,oEAAoE,EAAE;YAClF,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,cAAc;SAC3C,CAAC,CAAC;QACH,OAAO;YACL,MAAM,EAAE,cAAc;YACtB,UAAU,EAAE;gBACV,SAAS,EAAE,oEAAoE;gBAC/E,cAAc,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE;aACvD;YACD,OAAO,EAAE,IAAI;SACd,CAAC;IACJ,CAAC;IAED;;;OAGG;IACO,KAAK,CAAC,SAAS,CACvB,KAA+C,EAC/C,YAAsD;QAEtD,OAAO,qBAAqB,CAAC,KAAK,EAAE,YAAY,EAAE,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC;IAC7F,CAAC;CACF","sourcesContent":["import { createStructuredModel } from \"../shared/agent/model.config.js\";\nimport { invokeWithAbortSignal } from \"../shared/agent/model-signal.js\";\nimport { SystemNegotiationTurnSchema, FinalNegotiationTurnSchema, type NegotiationTurn, type UserNegotiationContext, type SeedAssessment } from \"./negotiation.state.js\";\nimport { turnSchemaFor, fallbackActionFor } from \"./negotiation.protocol.js\";\nimport type { NegotiationSeat, NegotiationProtocolVersion } from \"../shared/schemas/negotiation-state.schema.js\";\nimport type { NegotiationUserAnswer } from \"../shared/interfaces/database.interface.js\";\nimport { renderNegotiatorMemorySection, type NegotiatorMemoryEntry } from \"./negotiation.memory.js\";\nimport { protocolLogger } from \"../shared/observability/protocol.logger.js\";\n\nconst agentLog = protocolLogger(\"IndexNegotiator\");\n\nconst SYSTEM_PROMPT = `You are the Index Negotiator, an AI agent acting on behalf of {userName}. You represent their interests in a bilateral negotiation about a potential connection on a discovery network.\n\n{discoveryContext}\n{discoveryQueryContext}\nYour user's role in this connection: {role}\nNetwork context: {networkContext}\n\nYour job: Evaluate whether this connection genuinely serves {userName}'s interests given their role. Argue their case honestly — acknowledge weaknesses, but advocate for genuine fit.\n\nRules:\n{actionRules}\n- Focus on concrete intent alignment, not vague overlap.\n- Do NOT reference internal system details like scores, pre-screens, or evaluator outputs.\n- suggestedRoles: \"agent\" = can help, \"patient\" = seeks help, \"peer\" = mutual benefit.\n{finalTurnInstruction}{negotiatorMemory}`;\n\n/** v1 action rules — byte-identical to the pre-seat-rules prompt. */\nconst V1_ACTION_RULES = `- On the FIRST turn: Propose the connection case. Explain why it would benefit both parties. Set action to \"propose\".\n- On SUBSEQUENT turns: Evaluate the other agent's arguments. Either:\n - \"counter\" if you have specific objections but see potential\n - \"accept\" if the match genuinely benefits {userName}\n - \"reject\" if the match does not serve {userName}'s needs`;\n\n/** v2 initiator seat: reaching stance — accept is structurally unavailable. */\nconst V2_INITIATOR_RULES = `- You hold the INITIATING seat: your user's side surfaced this match and you are reaching out. Only the counterparty may accept — \"accept\" is NOT available to you.\n- On the FIRST turn: Make the outreach case. Explain why the connection would benefit both parties. Set action to \"outreach\".\n- On SUBSEQUENT turns: Evaluate the counterparty's arguments. Either:\n - \"counter\" if you have specific objections but see potential\n - \"question\" if you need a specific clarification from the counterparty\n - \"withdraw\" if the match does not serve {userName}'s needs`;\n\n/**\n * v2 client-consult pause rule (P3.2). Appended to either seat's rules only\n * when the caller granted `canAskUser` — the action never appears in the\n * prompt (or the schema) otherwise.\n */\nconst ASK_USER_RULE = `\n- \"ask_user\" if you need {userName}'s OWN input before you can proceed — typically permission to disclose something sensitive (budget, availability, private details) or a fact only they know. This PAUSES the negotiation until they answer (up to 24h), so use it only when proceeding without their input would risk over-disclosure or a wrong call. You get AT MOST ONE client consultation per negotiation — spend it well. Set askUser: { disclosureSubject: what you need permission for or need to know, draftQuestion: the question in your words }. Use \"question\" (not \"ask_user\") when the clarification should come from the other side.`;\n\n/** v2 counterparty seat: receiving stance — acceptance is this seat's decision alone. */\nconst V2_COUNTERPARTY_RULES = `- You hold the RECEIVING seat: the other side reached out to {userName}. Whether to accept is YOUR seat's decision alone.\n- Evaluate the initiator's arguments. Either:\n - \"accept\" if the match genuinely benefits {userName}\n - \"decline\" if the match does not serve {userName}'s needs\n - \"counter\" if you have specific objections but see potential\n - \"question\" if you need a specific clarification from the initiator\n- Never use \"outreach\" — you are responding, not reaching out.`;\n\nexport interface NegotiationAgentInput {\n ownUser: UserNegotiationContext;\n otherUser: UserNegotiationContext;\n indexContext: { networkId: string; prompt?: string };\n seedAssessment: SeedAssessment;\n history: NegotiationTurn[];\n isFinalTurn?: boolean;\n /** Whether ownUser is the party that initiated the discovery (searched/signalled). */\n isDiscoverer?: boolean;\n /** The explicit search query that triggered discovery (if any). Takes priority over background intents. */\n discoveryQuery?: string;\n /** Whether this negotiation is continuing a prior conversation with the same counterparty. */\n isContinuation?: boolean;\n /** User answers collected by the questioner between negotiation sessions. */\n userAnswers?: NegotiationUserAnswer[];\n /**\n * The acting user's seat under the v2 client-advocate protocol. Selects the\n * seat-scoped turn schema and prompt stance when `protocolVersion` is `v2`.\n * Ignored under v1. Defaults from `isDiscoverer` when omitted.\n */\n seat?: NegotiationSeat;\n /**\n * Negotiation protocol version for this task (inherited, never re-stamped).\n * `v1` (default) keeps the legacy symmetric vocabulary and prompt.\n */\n protocolVersion?: NegotiationProtocolVersion;\n /**\n * Whether the `ask_user` client-consult pause (P3.2) is available on this\n * turn. The caller (negotiation graph) grants it only when the feature flag\n * is on, the pause loop is fully wired (questioner + answer-window timer +\n * opportunity to resume against), the turn is v2 non-final and non-opening,\n * and this side has not already consumed its one client question for the\n * negotiation. When true, the seat schema and prompt gain the action.\n */\n canAskUser?: boolean;\n /**\n * Retrieved negotiator memories for the acting user (P5.3 read path).\n * Rendered as a private prompt section — hard disclosure constraints plus\n * advisory hints. Absent/empty → the prompt is byte-identical to before.\n */\n memory?: NegotiatorMemoryEntry[];\n}\n\nexport interface IndexNegotiatorConfig {\n /**\n * Hard ceiling on a single LLM turn round-trip, in ms. When the underlying\n * model.invoke call exceeds this, an AbortSignal cancels the request and the\n * promise rejects — the calling turn node catches the rejection and treats it\n * as a failed turn, so one slow upstream call cannot consume the whole\n * negotiate-phase budget.\n *\n * Defaults to `NEGOTIATOR_TURN_TIMEOUT_MS` env var when set, otherwise\n * `DEFAULT_TURN_TIMEOUT_MS`. Sized to clip the p99 tail on Gemini-2.5-Flash\n * (~20 s today on OpenRouter) without trimming p90 (~12 s).\n */\n turnTimeoutMs?: number;\n}\n\nconst DEFAULT_TURN_TIMEOUT_MS = 15_000;\n\n// Resolver-valid range is `(0, Number.MAX_SAFE_INTEGER]`. The upper bound is\n// the runtime ceiling: `AbortSignal.timeout(N)` throws when N is outside\n// `[0, Number.MAX_SAFE_INTEGER]`, so `Number.isFinite` alone isn't enough —\n// values like `1e30` pass finiteness but blow up at the AbortSignal call.\n// The lower bound (`n > 0`) is a design choice rather than a runtime\n// constraint: `AbortSignal.timeout(0)` is technically legal but would abort\n// every turn before the LLM produces a response, so we reject it and fall\n// back to the default just like any other invalid override.\nfunction isValidTimeoutMs(n: number): boolean {\n return Number.isFinite(n) && n > 0 && n <= Number.MAX_SAFE_INTEGER;\n}\n\nfunction resolveTurnTimeoutMs(override?: number): number {\n if (typeof override === \"number\" && isValidTimeoutMs(override)) return override;\n const envValue = process.env.NEGOTIATOR_TURN_TIMEOUT_MS;\n if (envValue) {\n const parsed = Number(envValue);\n if (isValidTimeoutMs(parsed)) return parsed;\n }\n return DEFAULT_TURN_TIMEOUT_MS;\n}\n\n/**\n * Unified system negotiation agent that advocates for its user.\n * Adapts behavior based on turn position (first turn = propose, subsequent = respond).\n * @remarks Uses structured output constrained to NegotiationTurnSchema (without question action).\n */\nexport class IndexNegotiator {\n private readonly turnTimeoutMs: number;\n\n constructor(config?: IndexNegotiatorConfig) {\n this.turnTimeoutMs = resolveTurnTimeoutMs(config?.turnTimeoutMs);\n }\n\n /**\n * Generate a negotiation turn.\n * @param input - User contexts, seed assessment, history, and final turn flag\n * @returns A structured NegotiationTurn\n * @throws If the per-turn timeout fires before the LLM responds.\n */\n async invoke(input: NegotiationAgentInput): Promise<NegotiationTurn> {\n const version: NegotiationProtocolVersion = input.protocolVersion ?? \"v1\";\n const seat: NegotiationSeat = input.seat ?? (input.isDiscoverer ? \"initiator\" : \"counterparty\");\n const isFinalTurn = input.isFinalTurn ?? false;\n const canAskUser = input.canAskUser === true && version === \"v2\" && !isFinalTurn;\n const schema = turnSchemaFor(version, seat, isFinalTurn, {\n system: SystemNegotiationTurnSchema,\n final: FinalNegotiationTurnSchema,\n }, { askUser: canAskUser });\n const model = createStructuredModel(\"negotiator\", schema, { name: \"index_negotiator\" });\n\n const userName = input.ownUser.profile.name ?? \"your user\";\n const role = input.seedAssessment.valencyRole || \"peer\";\n const networkContext = input.indexContext.prompt || \"General discovery\";\n const actionRules = (version === \"v2\"\n ? (seat === \"initiator\" ? V2_INITIATOR_RULES : V2_COUNTERPARTY_RULES)\n : V1_ACTION_RULES) + (canAskUser ? ASK_USER_RULE : \"\");\n const finalTurnInstruction = input.isFinalTurn\n ? (version === \"v2\"\n ? (seat === \"initiator\"\n ? \"\\n\\nIMPORTANT: This is your FINAL turn. You MUST choose either 'withdraw' or 'counter'. Accept is not available to your seat.\"\n : \"\\n\\nIMPORTANT: This is your FINAL turn. You MUST choose either 'accept' or 'decline'. No counter is allowed.\")\n : \"\\n\\nIMPORTANT: This is your FINAL turn. You MUST choose either 'accept' or 'reject'. No counter is allowed.\")\n : \"\";\n\n const otherName = input.otherUser.profile.name ?? \"the other user\";\n const discoveryContext = input.isDiscoverer\n ? `${userName} initiated this discovery — they are actively looking for connections. ${otherName} was identified as a potential match.`\n : `${otherName} initiated this discovery and found ${userName} as a potential match. You are representing the discovered party.`;\n\n const discoveryQueryContext = input.discoveryQuery\n ? `\\nDISCOVERY QUERY: ${userName} explicitly searched for \"${input.discoveryQuery}\".\nQUERY PRIORITY RULE: This search query is the PRIMARY criterion for this negotiation. Before evaluating intents or profile overlap, first answer: does ${otherName} satisfy the search query \"${input.discoveryQuery}\"?\n- If the query is a role or identity term (e.g. \"samurai\", \"investors\", \"designers\"): check whether ${otherName} IS that thing based on their profile. Subject-matter adjacency does not count (drawing samurai ≠ being a samurai, raising funding ≠ being an investor).\n- If ${otherName} does NOT satisfy the query: REJECT the match. Background intents cannot rescue a query mismatch.\n- If ${otherName} DOES satisfy the query: PROPOSE or ACCEPT the connection and evaluate fit normally using intents and profile data.`\n : '';\n\n const systemPrompt = SYSTEM_PROMPT\n .replace(\"{actionRules}\", actionRules)\n .replace(/{userName}/g, userName)\n .replace(\"{discoveryContext}\", discoveryContext)\n .replace(\"{discoveryQueryContext}\", discoveryQueryContext)\n .replace(\"{role}\", role)\n .replace(\"{networkContext}\", networkContext)\n .replace(\"{finalTurnInstruction}\", finalTurnInstruction)\n .replace(\"{negotiatorMemory}\", renderNegotiatorMemorySection(input.memory ?? []));\n\n const historyText = input.history.length > 0\n ? `\\n\\nNegotiation history:\\n${input.history.map((t, i) => {\n const msgPart = t.message ? ` — message: ${t.message}` : '';\n return `Turn ${i + 1}: ${t.action} — reasoning: ${t.assessment.reasoning}${msgPart}`;\n }).join(\"\\n\")}`\n : \"\";\n\n const continuationContext = input.isContinuation && input.history.length > 0\n ? `\\n\\n--- Prior dialogue with this counterparty ---\n${historyText}\n\n--- New signal under evaluation ---\n${input.discoveryQuery\n ? `Discovery query: \"${input.discoveryQuery}\"`\n : `Seed assessment: ${input.seedAssessment.reasoning}`\n}\n\nPolicy: You are continuing a prior dialogue. If this signal is materially the same as one you previously evaluated, you may resolve quickly. If materially different, evaluate on its own merits.`\n : '';\n\n const userAnswersContext = input.userAnswers && input.userAnswers.length > 0\n ? `\\n\\n--- ${userName}'s additional context (provided between sessions) ---\\n${input.userAnswers.map((a) => {\n const opts = Array.isArray(a.selectedOptions) ? a.selectedOptions : [];\n const parts = opts.length > 0 ? opts.join(', ') : '';\n const free = a.freeText ? (parts ? ` — ${a.freeText}` : a.freeText) : '';\n if (!parts && !free) return '';\n return `- ${parts}${free}`;\n }).filter(Boolean).join(\"\\n\")}\\n`\n : '';\n\n const discoveryQueryReminder = input.discoveryQuery\n ? `\\nREMINDER: ${userName} searched for \"${input.discoveryQuery}\". Evaluate ${otherName} against this query FIRST. If ${otherName} is not a \"${input.discoveryQuery}\", reject.\\n`\n : '';\n\n const intentsLabel = input.discoveryQuery ? 'Background intents (secondary to discovery query)' : 'Intents';\n\n const userMessage = `YOUR USER (${userName}):\nBio: ${input.ownUser.profile.bio ?? \"N/A\"}\nSkills: ${input.ownUser.profile.skills?.join(\", \") ?? \"N/A\"}\n${intentsLabel}:\n${input.ownUser.intents.map((i) => `- ${i.title}: ${i.description}`).join(\"\\n\")}\n\nOTHER USER (${otherName}):\nBio: ${input.otherUser.profile.bio ?? \"N/A\"}\nSkills: ${input.otherUser.profile.skills?.join(\", \") ?? \"N/A\"}\nIntents:\n${input.otherUser.intents.map((i) => `- ${i.title}: ${i.description}`).join(\"\\n\")}\n\nWhy this match was suggested: ${input.seedAssessment.reasoning}${input.isContinuation ? continuationContext : historyText}${userAnswersContext}\n${discoveryQueryReminder}\n${input.history.length === 0 && !input.isContinuation ? (version === \"v2\" && seat === \"initiator\" ? \"This is the opening turn. Make the outreach case.\" : \"This is the opening turn. Propose the connection case.\") : \"Evaluate the latest arguments and respond.\"}`;\n\n const chatMessages = [\n { role: \"system\", content: systemPrompt },\n { role: \"user\", content: userMessage },\n ];\n\n // Structured output is schema-constrained, but providers can still emit\n // out-of-vocabulary actions. Validate; retry once; then fall back to the\n // conservative seat-valid action instead of poisoning the turn history.\n for (let attempt = 0; attempt < 2; attempt++) {\n const result = await this.callModel(model, chatMessages);\n const parsed = schema.safeParse(result);\n if (parsed.success) return parsed.data as NegotiationTurn;\n agentLog.warn(\"Negotiator output failed seat-schema validation\", {\n attempt: attempt + 1,\n seat,\n version,\n isFinalTurn,\n issues: parsed.error.issues.map((i) => i.message).slice(0, 3),\n });\n }\n\n const fallbackAction = fallbackActionFor(version, seat, isFinalTurn);\n agentLog.warn(\"Negotiator output invalid after retry; using conservative fallback\", {\n seat, version, isFinalTurn, fallbackAction,\n });\n return {\n action: fallbackAction,\n assessment: {\n reasoning: \"Agent produced an invalid response; conservative fallback applied.\",\n suggestedRoles: { ownUser: \"peer\", otherUser: \"peer\" },\n },\n message: null,\n };\n }\n\n /**\n * Raw structured-model round trip. Split out as a seam so tests can drive\n * the validate→retry→fallback loop without a live provider.\n */\n protected async callModel(\n model: ReturnType<typeof createStructuredModel>,\n chatMessages: Array<{ role: string; content: string }>,\n ): Promise<unknown> {\n return invokeWithAbortSignal(model, chatMessages, AbortSignal.timeout(this.turnTimeoutMs));\n }\n}\n"]}
1
+ {"version":3,"file":"negotiation.agent.js","sourceRoot":"/","sources":["negotiation/negotiation.agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,EAAE,2BAA2B,EAAE,0BAA0B,EAA0E,MAAM,wBAAwB,CAAC;AACzK,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAG7E,OAAO,EAAE,6BAA6B,EAA8B,MAAM,yBAAyB,CAAC;AACpG,OAAO,EAAE,4BAA4B,EAAE,MAAM,2BAA2B,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,4CAA4C,CAAC;AAE5E,MAAM,QAAQ,GAAG,cAAc,CAAC,iBAAiB,CAAC,CAAC;AAEnD,MAAM,aAAa,GAAG;;;;;;;;;;;;;;0D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AAQ,CAAC,IAAI,CAAC,iDAAiD,EAAE;gBAC/D,OAAO,EAAE,OAAO,GAAG,CAAC;gBACpB,IAAI;gBACJ,OAAO;gBACP,WAAW;gBACX,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;aAC9D,CAAC,CAAC;QACL,CAAC;QAED,MAAM,cAAc,GAAG,iBAAiB,CAAC,OAAO,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;QACrE,QAAQ,CAAC,IAAI,CAAC,oEAAoE,EAAE;YAClF,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,cAAc;SAC3C,CAAC,CAAC;QACH,OAAO;YACL,MAAM,EAAE,cAAc;YACtB,UAAU,EAAE;gBACV,SAAS,EAAE,oEAAoE;gBAC/E,cAAc,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE;aACvD;YACD,OAAO,EAAE,IAAI;SACd,CAAC;IACJ,CAAC;IAED;;;OAGG;IACO,KAAK,CAAC,SAAS,CACvB,KAA+C,EAC/C,YAAsD;QAEtD,OAAO,qBAAqB,CAAC,KAAK,EAAE,YAAY,EAAE,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC;IAC7F,CAAC;CACF","sourcesContent":["import { createStructuredModel } from \"../shared/agent/model.config.js\";\nimport { invokeWithAbortSignal } from \"../shared/agent/model-signal.js\";\nimport { SystemNegotiationTurnSchema, FinalNegotiationTurnSchema, type NegotiationTurn, type UserNegotiationContext, type SeedAssessment } from \"./negotiation.state.js\";\nimport { turnSchemaFor, fallbackActionFor } from \"./negotiation.protocol.js\";\nimport type { NegotiationSeat, NegotiationProtocolVersion } from \"../shared/schemas/negotiation-state.schema.js\";\nimport type { NegotiationUserAnswer } from \"../shared/interfaces/database.interface.js\";\nimport { renderNegotiatorMemorySection, type NegotiatorMemoryEntry } from \"./negotiation.memory.js\";\nimport { renderBargainingShiftSection } from \"./negotiation.deadlock.js\";\nimport { protocolLogger } from \"../shared/observability/protocol.logger.js\";\n\nconst agentLog = protocolLogger(\"IndexNegotiator\");\n\nconst SYSTEM_PROMPT = `You are the Index Negotiator, an AI agent acting on behalf of {userName}. You represent their interests in a bilateral negotiation about a potential connection on a discovery network.\n\n{discoveryContext}\n{discoveryQueryContext}\nYour user's role in this connection: {role}\nNetwork context: {networkContext}\n\nYour job: Evaluate whether this connection genuinely serves {userName}'s interests given their role. Argue their case honestly — acknowledge weaknesses, but advocate for genuine fit.\n\nRules:\n{actionRules}\n- Focus on concrete intent alignment, not vague overlap.\n- Do NOT reference internal system details like scores, pre-screens, or evaluator outputs.\n- suggestedRoles: \"agent\" = can help, \"patient\" = seeks help, \"peer\" = mutual benefit.\n{finalTurnInstruction}{bargainingShift}{negotiatorMemory}`;\n\n/** v1 action rules — byte-identical to the pre-seat-rules prompt. */\nconst V1_ACTION_RULES = `- On the FIRST turn: Propose the connection case. Explain why it would benefit both parties. Set action to \"propose\".\n- On SUBSEQUENT turns: Evaluate the other agent's arguments. Either:\n - \"counter\" if you have specific objections but see potential\n - \"accept\" if the match genuinely benefits {userName}\n - \"reject\" if the match does not serve {userName}'s needs`;\n\n/** v2 initiator seat: reaching stance — accept is structurally unavailable. */\nconst V2_INITIATOR_RULES = `- You hold the INITIATING seat: your user's side surfaced this match and you are reaching out. Only the counterparty may accept — \"accept\" is NOT available to you.\n- On the FIRST turn: Make the outreach case. Explain why the connection would benefit both parties. Set action to \"outreach\".\n- On SUBSEQUENT turns: Evaluate the counterparty's arguments. Either:\n - \"counter\" if you have specific objections but see potential\n - \"question\" if you need a specific clarification from the counterparty\n - \"withdraw\" if the match does not serve {userName}'s needs`;\n\n/**\n * v2 client-consult pause rule (P3.2). Appended to either seat's rules only\n * when the caller granted `canAskUser` — the action never appears in the\n * prompt (or the schema) otherwise.\n */\nconst ASK_USER_RULE = `\n- \"ask_user\" if you need {userName}'s OWN input before you can proceed — typically permission to disclose something sensitive (budget, availability, private details) or a fact only they know. This PAUSES the negotiation until they answer (up to 24h), so use it only when proceeding without their input would risk over-disclosure or a wrong call. You get AT MOST ONE client consultation per negotiation — spend it well. Set askUser: { disclosureSubject: what you need permission for or need to know, draftQuestion: the question in your words }. Use \"question\" (not \"ask_user\") when the clarification should come from the other side.`;\n\n/** v2 counterparty seat: receiving stance — acceptance is this seat's decision alone. */\nconst V2_COUNTERPARTY_RULES = `- You hold the RECEIVING seat: the other side reached out to {userName}. Whether to accept is YOUR seat's decision alone.\n- Evaluate the initiator's arguments. Either:\n - \"accept\" if the match genuinely benefits {userName}\n - \"decline\" if the match does not serve {userName}'s needs\n - \"counter\" if you have specific objections but see potential\n - \"question\" if you need a specific clarification from the initiator\n- Never use \"outreach\" — you are responding, not reaching out.`;\n\nexport interface NegotiationAgentInput {\n ownUser: UserNegotiationContext;\n otherUser: UserNegotiationContext;\n indexContext: { networkId: string; prompt?: string };\n seedAssessment: SeedAssessment;\n history: NegotiationTurn[];\n isFinalTurn?: boolean;\n /** Whether ownUser is the party that initiated the discovery (searched/signalled). */\n isDiscoverer?: boolean;\n /** The explicit search query that triggered discovery (if any). Takes priority over background intents. */\n discoveryQuery?: string;\n /** Whether this negotiation is continuing a prior conversation with the same counterparty. */\n isContinuation?: boolean;\n /** User answers collected by the questioner between negotiation sessions. */\n userAnswers?: NegotiationUserAnswer[];\n /**\n * The acting user's seat under the v2 client-advocate protocol. Selects the\n * seat-scoped turn schema and prompt stance when `protocolVersion` is `v2`.\n * Ignored under v1. Defaults from `isDiscoverer` when omitted.\n */\n seat?: NegotiationSeat;\n /**\n * Negotiation protocol version for this task (inherited, never re-stamped).\n * `v1` (default) keeps the legacy symmetric vocabulary and prompt.\n */\n protocolVersion?: NegotiationProtocolVersion;\n /**\n * Whether the `ask_user` client-consult pause (P3.2) is available on this\n * turn. The caller (negotiation graph) grants it only when the feature flag\n * is on, the pause loop is fully wired (questioner + answer-window timer +\n * opportunity to resume against), the turn is v2 non-final and non-opening,\n * and this side has not already consumed its one client question for the\n * negotiation. When true, the seat schema and prompt gain the action.\n */\n canAskUser?: boolean;\n /**\n * Deadlock→bargaining drafting stance (IND-428, flag-gated by the caller).\n * Present = the graph detected a stalemate (N consecutive counter/question\n * turns) and this turn should be drafted in the bargaining stance —\n * concessions/scope reductions instead of re-arguing merits. v2 only;\n * ignored under v1. Absent → the prompt is byte-identical to before.\n */\n bargaining?: { consecutiveNonConvergent: number };\n /**\n * Retrieved negotiator memories for the acting user (P5.3 read path).\n * Rendered as a private prompt section — hard disclosure constraints plus\n * advisory hints. Absent/empty → the prompt is byte-identical to before.\n */\n memory?: NegotiatorMemoryEntry[];\n}\n\nexport interface IndexNegotiatorConfig {\n /**\n * Hard ceiling on a single LLM turn round-trip, in ms. When the underlying\n * model.invoke call exceeds this, an AbortSignal cancels the request and the\n * promise rejects — the calling turn node catches the rejection and treats it\n * as a failed turn, so one slow upstream call cannot consume the whole\n * negotiate-phase budget.\n *\n * Defaults to `NEGOTIATOR_TURN_TIMEOUT_MS` env var when set, otherwise\n * `DEFAULT_TURN_TIMEOUT_MS`. Sized to clip the p99 tail on Gemini-2.5-Flash\n * (~20 s today on OpenRouter) without trimming p90 (~12 s).\n */\n turnTimeoutMs?: number;\n}\n\nconst DEFAULT_TURN_TIMEOUT_MS = 15_000;\n\n// Resolver-valid range is `(0, Number.MAX_SAFE_INTEGER]`. The upper bound is\n// the runtime ceiling: `AbortSignal.timeout(N)` throws when N is outside\n// `[0, Number.MAX_SAFE_INTEGER]`, so `Number.isFinite` alone isn't enough —\n// values like `1e30` pass finiteness but blow up at the AbortSignal call.\n// The lower bound (`n > 0`) is a design choice rather than a runtime\n// constraint: `AbortSignal.timeout(0)` is technically legal but would abort\n// every turn before the LLM produces a response, so we reject it and fall\n// back to the default just like any other invalid override.\nfunction isValidTimeoutMs(n: number): boolean {\n return Number.isFinite(n) && n > 0 && n <= Number.MAX_SAFE_INTEGER;\n}\n\nfunction resolveTurnTimeoutMs(override?: number): number {\n if (typeof override === \"number\" && isValidTimeoutMs(override)) return override;\n const envValue = process.env.NEGOTIATOR_TURN_TIMEOUT_MS;\n if (envValue) {\n const parsed = Number(envValue);\n if (isValidTimeoutMs(parsed)) return parsed;\n }\n return DEFAULT_TURN_TIMEOUT_MS;\n}\n\n/**\n * Unified system negotiation agent that advocates for its user.\n * Adapts behavior based on turn position (first turn = propose, subsequent = respond).\n * @remarks Uses structured output constrained to NegotiationTurnSchema (without question action).\n */\nexport class IndexNegotiator {\n private readonly turnTimeoutMs: number;\n\n constructor(config?: IndexNegotiatorConfig) {\n this.turnTimeoutMs = resolveTurnTimeoutMs(config?.turnTimeoutMs);\n }\n\n /**\n * Generate a negotiation turn.\n * @param input - User contexts, seed assessment, history, and final turn flag\n * @returns A structured NegotiationTurn\n * @throws If the per-turn timeout fires before the LLM responds.\n */\n async invoke(input: NegotiationAgentInput): Promise<NegotiationTurn> {\n const version: NegotiationProtocolVersion = input.protocolVersion ?? \"v1\";\n const seat: NegotiationSeat = input.seat ?? (input.isDiscoverer ? \"initiator\" : \"counterparty\");\n const isFinalTurn = input.isFinalTurn ?? false;\n const canAskUser = input.canAskUser === true && version === \"v2\" && !isFinalTurn;\n // Deadlock→bargaining stance (IND-428): v2 only — defense in depth on top\n // of the graph-side gating, mirroring the canAskUser guard above.\n const bargainingActive = input.bargaining != null && version === \"v2\";\n const schema = turnSchemaFor(version, seat, isFinalTurn, {\n system: SystemNegotiationTurnSchema,\n final: FinalNegotiationTurnSchema,\n }, { askUser: canAskUser });\n const model = createStructuredModel(\"negotiator\", schema, { name: \"index_negotiator\" });\n\n const userName = input.ownUser.profile.name ?? \"your user\";\n const role = input.seedAssessment.valencyRole || \"peer\";\n const networkContext = input.indexContext.prompt || \"General discovery\";\n const actionRules = (version === \"v2\"\n ? (seat === \"initiator\" ? V2_INITIATOR_RULES : V2_COUNTERPARTY_RULES)\n : V1_ACTION_RULES) + (canAskUser ? ASK_USER_RULE : \"\");\n const finalTurnInstruction = input.isFinalTurn\n ? (version === \"v2\"\n ? (seat === \"initiator\"\n ? \"\\n\\nIMPORTANT: This is your FINAL turn. You MUST choose either 'withdraw' or 'counter'. Accept is not available to your seat.\"\n : \"\\n\\nIMPORTANT: This is your FINAL turn. You MUST choose either 'accept' or 'decline'. No counter is allowed.\")\n : \"\\n\\nIMPORTANT: This is your FINAL turn. You MUST choose either 'accept' or 'reject'. No counter is allowed.\")\n : \"\";\n\n const otherName = input.otherUser.profile.name ?? \"the other user\";\n const discoveryContext = input.isDiscoverer\n ? `${userName} initiated this discovery — they are actively looking for connections. ${otherName} was identified as a potential match.`\n : `${otherName} initiated this discovery and found ${userName} as a potential match. You are representing the discovered party.`;\n\n const discoveryQueryContext = input.discoveryQuery\n ? `\\nDISCOVERY QUERY: ${userName} explicitly searched for \"${input.discoveryQuery}\".\nQUERY PRIORITY RULE: This search query is the PRIMARY criterion for this negotiation. Before evaluating intents or profile overlap, first answer: does ${otherName} satisfy the search query \"${input.discoveryQuery}\"?\n- If the query is a role or identity term (e.g. \"samurai\", \"investors\", \"designers\"): check whether ${otherName} IS that thing based on their profile. Subject-matter adjacency does not count (drawing samurai ≠ being a samurai, raising funding ≠ being an investor).\n- If ${otherName} does NOT satisfy the query: REJECT the match. Background intents cannot rescue a query mismatch.\n- If ${otherName} DOES satisfy the query: PROPOSE or ACCEPT the connection and evaluate fit normally using intents and profile data.`\n : '';\n\n const systemPrompt = SYSTEM_PROMPT\n .replace(\"{actionRules}\", actionRules)\n .replace(/{userName}/g, userName)\n .replace(\"{discoveryContext}\", discoveryContext)\n .replace(\"{discoveryQueryContext}\", discoveryQueryContext)\n .replace(\"{role}\", role)\n .replace(\"{networkContext}\", networkContext)\n .replace(\"{finalTurnInstruction}\", finalTurnInstruction)\n .replace(\"{bargainingShift}\", renderBargainingShiftSection({\n active: bargainingActive,\n userName,\n canAskUser,\n consecutiveNonConvergent: input.bargaining?.consecutiveNonConvergent ?? 0,\n }))\n .replace(\"{negotiatorMemory}\", renderNegotiatorMemorySection(input.memory ?? []));\n\n const historyText = input.history.length > 0\n ? `\\n\\nNegotiation history:\\n${input.history.map((t, i) => {\n const msgPart = t.message ? ` — message: ${t.message}` : '';\n return `Turn ${i + 1}: ${t.action} — reasoning: ${t.assessment.reasoning}${msgPart}`;\n }).join(\"\\n\")}`\n : \"\";\n\n const continuationContext = input.isContinuation && input.history.length > 0\n ? `\\n\\n--- Prior dialogue with this counterparty ---\n${historyText}\n\n--- New signal under evaluation ---\n${input.discoveryQuery\n ? `Discovery query: \"${input.discoveryQuery}\"`\n : `Seed assessment: ${input.seedAssessment.reasoning}`\n}\n\nPolicy: You are continuing a prior dialogue. If this signal is materially the same as one you previously evaluated, you may resolve quickly. If materially different, evaluate on its own merits.`\n : '';\n\n const userAnswersContext = input.userAnswers && input.userAnswers.length > 0\n ? `\\n\\n--- ${userName}'s additional context (provided between sessions) ---\\n${input.userAnswers.map((a) => {\n const opts = Array.isArray(a.selectedOptions) ? a.selectedOptions : [];\n const parts = opts.length > 0 ? opts.join(', ') : '';\n const free = a.freeText ? (parts ? ` — ${a.freeText}` : a.freeText) : '';\n if (!parts && !free) return '';\n return `- ${parts}${free}`;\n }).filter(Boolean).join(\"\\n\")}\\n`\n : '';\n\n const discoveryQueryReminder = input.discoveryQuery\n ? `\\nREMINDER: ${userName} searched for \"${input.discoveryQuery}\". Evaluate ${otherName} against this query FIRST. If ${otherName} is not a \"${input.discoveryQuery}\", reject.\\n`\n : '';\n\n const intentsLabel = input.discoveryQuery ? 'Background intents (secondary to discovery query)' : 'Intents';\n\n const userMessage = `YOUR USER (${userName}):\nBio: ${input.ownUser.profile.bio ?? \"N/A\"}\nSkills: ${input.ownUser.profile.skills?.join(\", \") ?? \"N/A\"}\n${intentsLabel}:\n${input.ownUser.intents.map((i) => `- ${i.title}: ${i.description}`).join(\"\\n\")}\n\nOTHER USER (${otherName}):\nBio: ${input.otherUser.profile.bio ?? \"N/A\"}\nSkills: ${input.otherUser.profile.skills?.join(\", \") ?? \"N/A\"}\nIntents:\n${input.otherUser.intents.map((i) => `- ${i.title}: ${i.description}`).join(\"\\n\")}\n\nWhy this match was suggested: ${input.seedAssessment.reasoning}${input.isContinuation ? continuationContext : historyText}${userAnswersContext}\n${discoveryQueryReminder}\n${input.history.length === 0 && !input.isContinuation ? (version === \"v2\" && seat === \"initiator\" ? \"This is the opening turn. Make the outreach case.\" : \"This is the opening turn. Propose the connection case.\") : \"Evaluate the latest arguments and respond.\"}`;\n\n const chatMessages = [\n { role: \"system\", content: systemPrompt },\n { role: \"user\", content: userMessage },\n ];\n\n // Structured output is schema-constrained, but providers can still emit\n // out-of-vocabulary actions. Validate; retry once; then fall back to the\n // conservative seat-valid action instead of poisoning the turn history.\n for (let attempt = 0; attempt < 2; attempt++) {\n const result = await this.callModel(model, chatMessages);\n const parsed = schema.safeParse(result);\n if (parsed.success) return parsed.data as NegotiationTurn;\n agentLog.warn(\"Negotiator output failed seat-schema validation\", {\n attempt: attempt + 1,\n seat,\n version,\n isFinalTurn,\n issues: parsed.error.issues.map((i) => i.message).slice(0, 3),\n });\n }\n\n const fallbackAction = fallbackActionFor(version, seat, isFinalTurn);\n agentLog.warn(\"Negotiator output invalid after retry; using conservative fallback\", {\n seat, version, isFinalTurn, fallbackAction,\n });\n return {\n action: fallbackAction,\n assessment: {\n reasoning: \"Agent produced an invalid response; conservative fallback applied.\",\n suggestedRoles: { ownUser: \"peer\", otherUser: \"peer\" },\n },\n message: null,\n };\n }\n\n /**\n * Raw structured-model round trip. Split out as a seam so tests can drive\n * the validate→retry→fallback loop without a live provider.\n */\n protected async callModel(\n model: ReturnType<typeof createStructuredModel>,\n chatMessages: Array<{ role: string; content: string }>,\n ): Promise<unknown> {\n return invokeWithAbortSignal(model, chatMessages, AbortSignal.timeout(this.turnTimeoutMs));\n }\n}\n"]}
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Deadlock detection + persuasion→bargaining mode shift (IND-428, backlog item 6).
3
+ *
4
+ * Grounding: Wells & Reed (2006), *Knowing When to Bargain* — a persuasion
5
+ * dialogue (arguing the merits) that reaches a stalemate may execute a *legal
6
+ * shift* into a negotiation dialogue (offering concessions). See
7
+ * `docs/design/negotiation-dialogue-game.md` for the formal framing of the
8
+ * turn protocol as a dialogue game.
9
+ *
10
+ * Design constraints (hard):
11
+ * - **Deterministic**: deadlock is decided by pure inspection of the persisted
12
+ * turn history — never by an LLM.
13
+ * - **Stance, not rules**: a detected deadlock changes the system agent's
14
+ * *drafting stance* only. Locutions, seat vocabularies (`allowedActionsFor`),
15
+ * termination, and turn-cap semantics are untouched.
16
+ * - **Default-off**: gated on `NEGOTIATION_DEADLOCK_SHIFT_ENABLED === "true"`
17
+ * (strict literal) and applied only to v2 negotiations, checked alongside the
18
+ * protocol-version plumbing. When off, the legacy path is byte-identical.
19
+ * - **Fail-open**: any detection error means "no deadlock" — advisory
20
+ * infrastructure never blocks a negotiation.
21
+ */
22
+ import type { NegotiationTurn } from "./negotiation.state.js";
23
+ /**
24
+ * Whether the deadlock→bargaining mode shift is enabled, from the
25
+ * `NEGOTIATION_DEADLOCK_SHIFT_ENABLED` env switch. Strict literal `"true"`
26
+ * only — the deployment is byte-for-byte unchanged until the flag is flipped,
27
+ * and rolling back is the same single switch.
28
+ */
29
+ export declare function configuredDeadlockShiftEnabled(): boolean;
30
+ /**
31
+ * Default deadlock threshold: 4 consecutive non-convergent turns. Sized
32
+ * against the ambient turn cap (6): an outreach plus 4 unbroken counters
33
+ * leaves exactly the closing turns to draft in the bargaining stance.
34
+ */
35
+ export declare const DEFAULT_DEADLOCK_THRESHOLD = 4;
36
+ /**
37
+ * Lower bound on the configurable threshold. Below 2 the "stalemate" signal is
38
+ * meaningless — a single counter is ordinary dialogue, not a deadlock.
39
+ */
40
+ export declare const MIN_DEADLOCK_THRESHOLD = 2;
41
+ /**
42
+ * Consecutive non-convergent turns that constitute a deadlock, from
43
+ * `NEGOTIATION_DEADLOCK_THRESHOLD`. Must be an integer >= 2; invalid,
44
+ * non-integer, or out-of-range values fall back to the default (fail-open
45
+ * toward the documented behavior, mirroring `askUserAnswerWindowMs`).
46
+ */
47
+ export declare function configuredDeadlockThreshold(): number;
48
+ export interface DeadlockAssessment {
49
+ /** True when the trailing non-convergent run has reached the threshold. */
50
+ deadlocked: boolean;
51
+ /** Length of the maximal trailing run of counter/question turns. */
52
+ consecutiveNonConvergent: number;
53
+ /** The threshold the run was compared against. */
54
+ threshold: number;
55
+ }
56
+ /**
57
+ * Deterministic stalemate detector: measures the maximal *trailing* run of
58
+ * non-convergent turns (`counter`/`question`) in the persisted history and
59
+ * compares it against the threshold. Continuation histories are included by
60
+ * construction — the caller passes the full turn list, so a deadlock spanning
61
+ * sessions still counts.
62
+ *
63
+ * Pure state inspection; no LLM, no I/O, no clock.
64
+ */
65
+ export declare function assessDeadlock(history: ReadonlyArray<Pick<NegotiationTurn, "action">>, threshold?: number): DeadlockAssessment;
66
+ /**
67
+ * Analytical record of an applied shift, persisted to
68
+ * `tasks.metadata.deadlockShift` via the optional `setTaskDeadlockShift`
69
+ * database hook. Internal-only: negotiation API surfaces project specific
70
+ * fields and never return task metadata verbatim (same privacy posture as
71
+ * `metadata.screenDecision` and the QUD/uptake detection metadata).
72
+ */
73
+ export interface DeadlockShiftRecord {
74
+ reason: "consecutive_non_convergent";
75
+ consecutiveNonConvergent: number;
76
+ threshold: number;
77
+ /** Zero-based session turn index at which the shifted draft happened. */
78
+ shiftedAtTurn: number;
79
+ seat: "initiator" | "counterparty";
80
+ detectedAt: string;
81
+ }
82
+ /**
83
+ * Renders the bargaining-stance prompt section. Returns the empty string when
84
+ * the shift is not active, so the rendered system prompt is byte-identical to
85
+ * the legacy build on every non-shifted turn (mirrors
86
+ * `renderNegotiatorMemorySection`). The `ask_user` escalation line renders
87
+ * only when the caller already legally holds the action (`canAskUser`) — the
88
+ * shift never invents a locution.
89
+ */
90
+ export declare function renderBargainingShiftSection(input: {
91
+ active: boolean;
92
+ userName: string;
93
+ canAskUser: boolean;
94
+ consecutiveNonConvergent: number;
95
+ }): string;
96
+ //# sourceMappingURL=negotiation.deadlock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"negotiation.deadlock.d.ts","sourceRoot":"/","sources":["negotiation/negotiation.deadlock.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAI9D;;;;;GAKG;AACH,wBAAgB,8BAA8B,IAAI,OAAO,CAExD;AAED;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,IAAI,CAAC;AAE5C;;;GAGG;AACH,eAAO,MAAM,sBAAsB,IAAI,CAAC;AAExC;;;;;GAKG;AACH,wBAAgB,2BAA2B,IAAI,MAAM,CAOpD;AAcD,MAAM,WAAW,kBAAkB;IACjC,2EAA2E;IAC3E,UAAU,EAAE,OAAO,CAAC;IACpB,oEAAoE;IACpE,wBAAwB,EAAE,MAAM,CAAC;IACjC,kDAAkD;IAClD,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,aAAa,CAAC,IAAI,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAC,EACvD,SAAS,GAAE,MAAmC,GAC7C,kBAAkB,CAoBpB;AAID;;;;;;GAMG;AACH,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,4BAA4B,CAAC;IACrC,wBAAwB,EAAE,MAAM,CAAC;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,yEAAyE;IACzE,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,WAAW,GAAG,cAAc,CAAC;IACnC,UAAU,EAAE,MAAM,CAAC;CACpB;AAgBD;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAAC,KAAK,EAAE;IAClD,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,OAAO,CAAC;IACpB,wBAAwB,EAAE,MAAM,CAAC;CAClC,GAAG,MAAM,CAMT"}
@@ -0,0 +1,103 @@
1
+ // ─── Configuration ───────────────────────────────────────────────────────────
2
+ /**
3
+ * Whether the deadlock→bargaining mode shift is enabled, from the
4
+ * `NEGOTIATION_DEADLOCK_SHIFT_ENABLED` env switch. Strict literal `"true"`
5
+ * only — the deployment is byte-for-byte unchanged until the flag is flipped,
6
+ * and rolling back is the same single switch.
7
+ */
8
+ export function configuredDeadlockShiftEnabled() {
9
+ return process.env.NEGOTIATION_DEADLOCK_SHIFT_ENABLED === "true";
10
+ }
11
+ /**
12
+ * Default deadlock threshold: 4 consecutive non-convergent turns. Sized
13
+ * against the ambient turn cap (6): an outreach plus 4 unbroken counters
14
+ * leaves exactly the closing turns to draft in the bargaining stance.
15
+ */
16
+ export const DEFAULT_DEADLOCK_THRESHOLD = 4;
17
+ /**
18
+ * Lower bound on the configurable threshold. Below 2 the "stalemate" signal is
19
+ * meaningless — a single counter is ordinary dialogue, not a deadlock.
20
+ */
21
+ export const MIN_DEADLOCK_THRESHOLD = 2;
22
+ /**
23
+ * Consecutive non-convergent turns that constitute a deadlock, from
24
+ * `NEGOTIATION_DEADLOCK_THRESHOLD`. Must be an integer >= 2; invalid,
25
+ * non-integer, or out-of-range values fall back to the default (fail-open
26
+ * toward the documented behavior, mirroring `askUserAnswerWindowMs`).
27
+ */
28
+ export function configuredDeadlockThreshold() {
29
+ const raw = process.env.NEGOTIATION_DEADLOCK_THRESHOLD;
30
+ if (raw) {
31
+ const parsed = Number(raw);
32
+ if (Number.isInteger(parsed) && parsed >= MIN_DEADLOCK_THRESHOLD)
33
+ return parsed;
34
+ }
35
+ return DEFAULT_DEADLOCK_THRESHOLD;
36
+ }
37
+ // ─── Detection ───────────────────────────────────────────────────────────────
38
+ /**
39
+ * The locutions that count toward a stalemate: challenges and information
40
+ * requests that keep the dialogue open without converging. Everything else —
41
+ * openings (`propose`/`outreach`: a fresh case is on the table), terminal
42
+ * actions (the game is deciding, not stalling), and `ask_user` (new principal
43
+ * input is about to arrive) — RESETS the run to zero. Unknown/missing actions
44
+ * also reset (conservative: never manufacture a deadlock from unreadable data).
45
+ */
46
+ const NON_CONVERGENT_ACTIONS = new Set(["counter", "question"]);
47
+ /**
48
+ * Deterministic stalemate detector: measures the maximal *trailing* run of
49
+ * non-convergent turns (`counter`/`question`) in the persisted history and
50
+ * compares it against the threshold. Continuation histories are included by
51
+ * construction — the caller passes the full turn list, so a deadlock spanning
52
+ * sessions still counts.
53
+ *
54
+ * Pure state inspection; no LLM, no I/O, no clock.
55
+ */
56
+ export function assessDeadlock(history, threshold = DEFAULT_DEADLOCK_THRESHOLD) {
57
+ const effectiveThreshold = Number.isInteger(threshold) && threshold >= MIN_DEADLOCK_THRESHOLD
58
+ ? threshold
59
+ : DEFAULT_DEADLOCK_THRESHOLD;
60
+ let run = 0;
61
+ for (let i = history.length - 1; i >= 0; i--) {
62
+ const action = history[i]?.action;
63
+ if (typeof action === "string" && NON_CONVERGENT_ACTIONS.has(action)) {
64
+ run += 1;
65
+ }
66
+ else {
67
+ break;
68
+ }
69
+ }
70
+ return {
71
+ deadlocked: run >= effectiveThreshold,
72
+ consecutiveNonConvergent: run,
73
+ threshold: effectiveThreshold,
74
+ };
75
+ }
76
+ // ─── Prompt section (system agent drafting stance) ──────────────────────────
77
+ const BARGAINING_SHIFT_SECTION = `
78
+
79
+ DEADLOCK — SHIFT FROM PERSUASION TO BARGAINING. The last {consecutive} turns were counters/questions without convergence: the merits have been argued and restating them will not move the other side. For this turn, change stance:
80
+ - Do NOT re-argue fit or repeat points already made.
81
+ - Offer a concrete concession or scope reduction instead: a smaller first step (a single intro call, a scoped trial, a narrower version of the collaboration), dropping a contested requirement, or a trade on a dimension not yet contested.
82
+ - Make the remaining objection priceable: name the specific smaller commitment that would resolve it.{askUserEscalation}
83
+ - If no reduced scope would genuinely serve {userName}'s interests, conclude decisively with a terminal action from your allowed set rather than another repetitive counter.
84
+ This shift changes your stance only — your available actions are unchanged.`;
85
+ const BARGAINING_ASK_USER_ESCALATION = `
86
+ - If a concession would require {userName}'s own input or permission (budget, availability, private details), escalate with "ask_user" instead of guessing.`;
87
+ /**
88
+ * Renders the bargaining-stance prompt section. Returns the empty string when
89
+ * the shift is not active, so the rendered system prompt is byte-identical to
90
+ * the legacy build on every non-shifted turn (mirrors
91
+ * `renderNegotiatorMemorySection`). The `ask_user` escalation line renders
92
+ * only when the caller already legally holds the action (`canAskUser`) — the
93
+ * shift never invents a locution.
94
+ */
95
+ export function renderBargainingShiftSection(input) {
96
+ if (!input.active)
97
+ return "";
98
+ return BARGAINING_SHIFT_SECTION
99
+ .replace("{consecutive}", String(input.consecutiveNonConvergent))
100
+ .replace("{askUserEscalation}", input.canAskUser ? BARGAINING_ASK_USER_ESCALATION : "")
101
+ .replace(/{userName}/g, input.userName);
102
+ }
103
+ //# sourceMappingURL=negotiation.deadlock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"negotiation.deadlock.js","sourceRoot":"/","sources":["negotiation/negotiation.deadlock.ts"],"names":[],"mappings":"AAuBA,gFAAgF;AAEhF;;;;;GAKG;AACH,MAAM,UAAU,8BAA8B;IAC5C,OAAO,OAAO,CAAC,GAAG,CAAC,kCAAkC,KAAK,MAAM,CAAC;AACnE,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,CAAC;AAE5C;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC;AAExC;;;;;GAKG;AACH,MAAM,UAAU,2BAA2B;IACzC,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAC;IACvD,IAAI,GAAG,EAAE,CAAC;QACR,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;QAC3B,IAAI,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,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eAAe,EAAE,MAAM,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC;SAChE,OAAO,CAAC,qBAAqB,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,8BAA8B,CAAC,CAAC,CAAC,EAAE,CAAC;SACtF,OAAO,CAAC,aAAa,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;AAC5C,CAAC","sourcesContent":["/**\n * Deadlock detection + persuasion→bargaining mode shift (IND-428, backlog item 6).\n *\n * Grounding: Wells & Reed (2006), *Knowing When to Bargain* — a persuasion\n * dialogue (arguing the merits) that reaches a stalemate may execute a *legal\n * shift* into a negotiation dialogue (offering concessions). See\n * `docs/design/negotiation-dialogue-game.md` for the formal framing of the\n * turn protocol as a dialogue game.\n *\n * Design constraints (hard):\n * - **Deterministic**: deadlock is decided by pure inspection of the persisted\n * turn history — never by an LLM.\n * - **Stance, not rules**: a detected deadlock changes the system agent's\n * *drafting stance* only. Locutions, seat vocabularies (`allowedActionsFor`),\n * termination, and turn-cap semantics are untouched.\n * - **Default-off**: gated on `NEGOTIATION_DEADLOCK_SHIFT_ENABLED === \"true\"`\n * (strict literal) and applied only to v2 negotiations, checked alongside the\n * protocol-version plumbing. When off, the legacy path is byte-identical.\n * - **Fail-open**: any detection error means \"no deadlock\" — advisory\n * infrastructure never blocks a negotiation.\n */\nimport type { NegotiationTurn } from \"./negotiation.state.js\";\n\n// ─── Configuration ───────────────────────────────────────────────────────────\n\n/**\n * Whether the deadlock→bargaining mode shift is enabled, from the\n * `NEGOTIATION_DEADLOCK_SHIFT_ENABLED` env switch. Strict literal `\"true\"`\n * only — the deployment is byte-for-byte unchanged until the flag is flipped,\n * and rolling back is the same single switch.\n */\nexport function configuredDeadlockShiftEnabled(): boolean {\n return process.env.NEGOTIATION_DEADLOCK_SHIFT_ENABLED === \"true\";\n}\n\n/**\n * Default deadlock threshold: 4 consecutive non-convergent turns. Sized\n * against the ambient turn cap (6): an outreach plus 4 unbroken counters\n * leaves exactly the closing turns to draft in the bargaining stance.\n */\nexport const DEFAULT_DEADLOCK_THRESHOLD = 4;\n\n/**\n * Lower bound on the configurable threshold. Below 2 the \"stalemate\" signal is\n * meaningless — a single counter is ordinary dialogue, not a deadlock.\n */\nexport const MIN_DEADLOCK_THRESHOLD = 2;\n\n/**\n * Consecutive non-convergent turns that constitute a deadlock, from\n * `NEGOTIATION_DEADLOCK_THRESHOLD`. Must be an integer >= 2; invalid,\n * non-integer, or out-of-range values fall back to the default (fail-open\n * toward the documented behavior, mirroring `askUserAnswerWindowMs`).\n */\nexport function configuredDeadlockThreshold(): number {\n const raw = process.env.NEGOTIATION_DEADLOCK_THRESHOLD;\n if (raw) {\n const parsed = Number(raw);\n if (Number.isInteger(parsed) && parsed >= MIN_DEADLOCK_THRESHOLD) return parsed;\n }\n return DEFAULT_DEADLOCK_THRESHOLD;\n}\n\n// ─── Detection ───────────────────────────────────────────────────────────────\n\n/**\n * The locutions that count toward a stalemate: challenges and information\n * requests that keep the dialogue open without converging. Everything else —\n * openings (`propose`/`outreach`: a fresh case is on the table), terminal\n * actions (the game is deciding, not stalling), and `ask_user` (new principal\n * input is about to arrive) — RESETS the run to zero. Unknown/missing actions\n * also reset (conservative: never manufacture a deadlock from unreadable data).\n */\nconst NON_CONVERGENT_ACTIONS: ReadonlySet<string> = new Set([\"counter\", \"question\"]);\n\nexport interface DeadlockAssessment {\n /** True when the trailing non-convergent run has reached the threshold. */\n deadlocked: boolean;\n /** Length of the maximal trailing run of counter/question turns. */\n consecutiveNonConvergent: number;\n /** The threshold the run was compared against. */\n threshold: number;\n}\n\n/**\n * Deterministic stalemate detector: measures the maximal *trailing* run of\n * non-convergent turns (`counter`/`question`) in the persisted history and\n * compares it against the threshold. Continuation histories are included by\n * construction — the caller passes the full turn list, so a deadlock spanning\n * sessions still counts.\n *\n * Pure state inspection; no LLM, no I/O, no clock.\n */\nexport function assessDeadlock(\n history: ReadonlyArray<Pick<NegotiationTurn, \"action\">>,\n threshold: number = DEFAULT_DEADLOCK_THRESHOLD,\n): DeadlockAssessment {\n const effectiveThreshold = Number.isInteger(threshold) && threshold >= MIN_DEADLOCK_THRESHOLD\n ? threshold\n : DEFAULT_DEADLOCK_THRESHOLD;\n\n let run = 0;\n for (let i = history.length - 1; i >= 0; i--) {\n const action = history[i]?.action;\n if (typeof action === \"string\" && NON_CONVERGENT_ACTIONS.has(action)) {\n run += 1;\n } else {\n break;\n }\n }\n\n return {\n deadlocked: run >= effectiveThreshold,\n consecutiveNonConvergent: run,\n threshold: effectiveThreshold,\n };\n}\n\n// ─── Internal shift record (task metadata JSONB, never public) ──────────────\n\n/**\n * Analytical record of an applied shift, persisted to\n * `tasks.metadata.deadlockShift` via the optional `setTaskDeadlockShift`\n * database hook. Internal-only: negotiation API surfaces project specific\n * fields and never return task metadata verbatim (same privacy posture as\n * `metadata.screenDecision` and the QUD/uptake detection metadata).\n */\nexport interface DeadlockShiftRecord {\n reason: \"consecutive_non_convergent\";\n consecutiveNonConvergent: number;\n threshold: number;\n /** Zero-based session turn index at which the shifted draft happened. */\n shiftedAtTurn: number;\n seat: \"initiator\" | \"counterparty\";\n detectedAt: string;\n}\n\n// ─── Prompt section (system agent drafting stance) ──────────────────────────\n\nconst BARGAINING_SHIFT_SECTION = `\n\nDEADLOCK — SHIFT FROM PERSUASION TO BARGAINING. The last {consecutive} turns were counters/questions without convergence: the merits have been argued and restating them will not move the other side. For this turn, change stance:\n- Do NOT re-argue fit or repeat points already made.\n- Offer a concrete concession or scope reduction instead: a smaller first step (a single intro call, a scoped trial, a narrower version of the collaboration), dropping a contested requirement, or a trade on a dimension not yet contested.\n- Make the remaining objection priceable: name the specific smaller commitment that would resolve it.{askUserEscalation}\n- If no reduced scope would genuinely serve {userName}'s interests, conclude decisively with a terminal action from your allowed set rather than another repetitive counter.\nThis shift changes your stance only — your available actions are unchanged.`;\n\nconst BARGAINING_ASK_USER_ESCALATION = `\n- If a concession would require {userName}'s own input or permission (budget, availability, private details), escalate with \"ask_user\" instead of guessing.`;\n\n/**\n * Renders the bargaining-stance prompt section. Returns the empty string when\n * the shift is not active, so the rendered system prompt is byte-identical to\n * the legacy build on every non-shifted turn (mirrors\n * `renderNegotiatorMemorySection`). The `ask_user` escalation line renders\n * only when the caller already legally holds the action (`canAskUser`) — the\n * shift never invents a locution.\n */\nexport function renderBargainingShiftSection(input: {\n active: boolean;\n userName: string;\n canAskUser: boolean;\n consecutiveNonConvergent: number;\n}): string {\n if (!input.active) return \"\";\n return BARGAINING_SHIFT_SECTION\n .replace(\"{consecutive}\", String(input.consecutiveNonConvergent))\n .replace(\"{askUserEscalation}\", input.canAskUser ? BARGAINING_ASK_USER_ESCALATION : \"\")\n .replace(/{userName}/g, input.userName);\n}\n"]}