@clawtopia/werewolf-evolution 0.1.8 → 0.1.10

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/dist/index.d.ts CHANGED
@@ -108,6 +108,7 @@ interface BoundRun {
108
108
  senderId?: string;
109
109
  senderIsOwner: boolean;
110
110
  consumed: boolean;
111
+ proposalAttempts: number;
111
112
  promptContext?: string;
112
113
  boundAt: number;
113
114
  expiresAt: number;
@@ -153,6 +154,7 @@ declare class EvolutionContextStore {
153
154
  capture(event: MessageReceivedLike, ctx: MessageContextLike, now?: number): CapturedInbound | undefined;
154
155
  getPending(runId?: string, sessionKey?: string, prompt?: string, now?: number): CapturedInbound | undefined;
155
156
  private storeInbound;
157
+ private removeInbound;
156
158
  bindAgentRun(event: AgentRunEventLike, ctx: AgentRunContextLike, binding: AgentAccountBinding | undefined, now?: number, explicitOwnerAuthorized?: boolean, pendingInbound?: CapturedInbound): BoundRun | undefined;
157
159
  getBound(runId?: string, sessionKey?: string, now?: number): BoundRun | undefined;
158
160
  getBoundForToolCall(runId: string | undefined, sessionKey: string | undefined, agentId: string | undefined, now?: number): BoundRun | undefined;
@@ -161,6 +163,8 @@ declare class EvolutionContextStore {
161
163
  consume(runId: string, sessionKey: string, now?: number): BoundRun;
162
164
  authorizeToolCall(runId: string | undefined, sessionKey: string | undefined, toolCallId: string | undefined, now?: number, agentId?: string): BoundRun;
163
165
  consumeToolCall(toolCallId: string, sessionKey?: string, now?: number): BoundRun;
166
+ beginProposalToolCall(toolCallId: string, sessionKey?: string, now?: number): BoundRun;
167
+ private beginToolCall;
164
168
  cleanup(now?: number): void;
165
169
  }
166
170
 
@@ -205,12 +209,12 @@ declare class WerewolfEvolutionService {
205
209
  private cleanupOrdinaryDirectMessages;
206
210
  private cleanupSystemDebriefSessions;
207
211
  private matchesSystemDebriefTarget;
208
- captureMessage(event: MessageReceivedLike, ctx: MessageContextLike): void;
212
+ captureMessage(event: MessageReceivedLike, ctx: MessageContextLike): CapturedInbound | undefined;
209
213
  isSystemDebriefMessage(event: MessageSendingLike, ctx: Pick<MessageContextLike, "channelId" | "accountId" | "sessionKey" | "conversationId">): boolean;
210
214
  private pendingOrdinaryDirectMessage;
211
215
  private consumeOrdinaryDirectMessage;
212
- bindAgentRun(event: AgentRunEventLike, ctx: AgentRunContextLike, binding: AgentAccountBinding | undefined, explicitOwnerAuthorized?: boolean, pendingInbound?: CapturedDebrief | CapturedSuggestionCommand, pendingOrdinary?: OrdinaryDirectMessage): void;
213
- bindPromptRun(event: PromptBuildEventLike, ctx: AgentRunContextLike, config: unknown): void;
216
+ bindAgentRun(event: AgentRunEventLike, ctx: AgentRunContextLike, binding: AgentAccountBinding | undefined, explicitOwnerAuthorized?: boolean, pendingInbound?: CapturedDebrief | CapturedSuggestionCommand, pendingOrdinary?: OrdinaryDirectMessage): BoundRun | undefined;
217
+ bindPromptRun(event: PromptBuildEventLike, ctx: AgentRunContextLike, config: unknown): BoundRun | undefined;
214
218
  finishRun(ctx: Pick<AgentRunContextLike, "runId" | "sessionKey">): void;
215
219
  buildPromptContext(ctx: PromptContextLike, hooks?: TransactionHooks): {
216
220
  prependContext: string;
package/dist/index.js CHANGED
@@ -436,13 +436,24 @@ var EvolutionContextStore = class {
436
436
  }
437
437
  storeInbound(inbound) {
438
438
  if (inbound.runId) {
439
+ const previous = this.inboundByRun.get(inbound.runId);
440
+ if (previous) this.removeInbound(previous);
439
441
  this.inboundByRun.set(inbound.runId, inbound);
440
- return;
441
442
  }
442
443
  const pending = this.inboundBySession.get(inbound.sessionKey) ?? [];
443
444
  pending.push(inbound);
444
445
  this.inboundBySession.set(inbound.sessionKey, pending);
445
446
  }
447
+ removeInbound(inbound) {
448
+ if (inbound.runId && this.inboundByRun.get(inbound.runId) === inbound) {
449
+ this.inboundByRun.delete(inbound.runId);
450
+ }
451
+ const pending = this.inboundBySession.get(inbound.sessionKey);
452
+ if (!pending) return;
453
+ const index = pending.indexOf(inbound);
454
+ if (index >= 0) pending.splice(index, 1);
455
+ if (pending.length === 0) this.inboundBySession.delete(inbound.sessionKey);
456
+ }
446
457
  bindAgentRun(event, ctx, binding, now = Date.now(), explicitOwnerAuthorized = false, pendingInbound) {
447
458
  this.cleanup(now);
448
459
  if (!ctx.runId || !ctx.sessionKey || !ctx.agentId || !ctx.workspaceDir) return void 0;
@@ -459,12 +470,7 @@ var EvolutionContextStore = class {
459
470
  } else {
460
471
  if (!explicitOwnerAuthorized || event.senderIsOwner !== true || !event.senderId || normalizedSender(event.senderId) !== normalizedSender(inbound.from)) return void 0;
461
472
  }
462
- if (runInbound) {
463
- this.inboundByRun.delete(ctx.runId);
464
- } else {
465
- sessionPending.splice(pendingIndex, 1);
466
- if (sessionPending.length === 0) this.inboundBySession.delete(ctx.sessionKey);
467
- }
473
+ this.removeInbound(inbound);
468
474
  const bound = {
469
475
  runId: ctx.runId,
470
476
  sessionKey: ctx.sessionKey,
@@ -474,6 +480,7 @@ var EvolutionContextStore = class {
474
480
  senderId: event.senderId,
475
481
  senderIsOwner: event.senderIsOwner === true,
476
482
  consumed: false,
483
+ proposalAttempts: 0,
477
484
  boundAt: now,
478
485
  expiresAt: now + CAPTURE_TTL_MS
479
486
  };
@@ -532,17 +539,34 @@ var EvolutionContextStore = class {
532
539
  return bound;
533
540
  }
534
541
  consumeToolCall(toolCallId, sessionKey, now = Date.now()) {
542
+ const bound = this.beginToolCall(toolCallId, sessionKey, now);
543
+ return this.consume(bound.runId, bound.sessionKey, now);
544
+ }
545
+ beginProposalToolCall(toolCallId, sessionKey, now = Date.now()) {
546
+ const bound = this.beginToolCall(toolCallId, sessionKey, now);
547
+ if (bound.inbound.kind !== "debrief") throw new Error("DEBRIEF_CAPABILITY_REQUIRED");
548
+ if (bound.proposalAttempts >= 2) {
549
+ bound.consumed = true;
550
+ throw new Error("CAPABILITY_ALREADY_CONSUMED");
551
+ }
552
+ bound.proposalAttempts += 1;
553
+ return bound;
554
+ }
555
+ beginToolCall(toolCallId, sessionKey, now = Date.now()) {
535
556
  this.cleanup(now);
536
557
  const authorized = this.toolCalls.get(toolCallId);
537
558
  this.toolCalls.delete(toolCallId);
538
559
  if (!authorized || authorized.expiresAt < now || !sessionKey || authorized.sessionKey !== sessionKey) {
539
560
  throw new Error("UNAUTHORIZED_TOOL_CALL");
540
561
  }
541
- return this.consume(authorized.runId, authorized.sessionKey, now);
562
+ const bound = this.getBound(authorized.runId, authorized.sessionKey, now);
563
+ if (!bound) throw new Error("NO_BOUND_CAPABILITY");
564
+ if (bound.consumed) throw new Error("CAPABILITY_ALREADY_CONSUMED");
565
+ return bound;
542
566
  }
543
567
  cleanup(now = Date.now()) {
544
568
  for (const [key, value] of this.inboundByRun) {
545
- if (now - value.capturedAt > CAPTURE_TTL_MS) this.inboundByRun.delete(key);
569
+ if (now - value.capturedAt > CAPTURE_TTL_MS) this.removeInbound(value);
546
570
  }
547
571
  for (const [key, values] of this.inboundBySession) {
548
572
  const current = values.filter((value) => now - value.capturedAt <= CAPTURE_TTL_MS);
@@ -558,13 +582,21 @@ var EvolutionContextStore = class {
558
582
  for (const [key, value] of this.hashByDebriefId) {
559
583
  if (now - value.capturedAt > CAPTURE_TTL_MS) this.hashByDebriefId.delete(key);
560
584
  }
561
- while (this.inboundByRun.size > MAX_CAPTURES) this.inboundByRun.delete(this.inboundByRun.keys().next().value);
585
+ while (this.inboundByRun.size > MAX_CAPTURES) {
586
+ const first = this.inboundByRun.values().next().value;
587
+ if (!first) break;
588
+ this.removeInbound(first);
589
+ }
562
590
  while ([...this.inboundBySession.values()].reduce((total, values) => total + values.length, 0) > MAX_CAPTURES) {
563
591
  const firstKey = this.inboundBySession.keys().next().value;
564
592
  if (!firstKey) break;
565
593
  const values = this.inboundBySession.get(firstKey);
566
- values.shift();
567
- if (values.length === 0) this.inboundBySession.delete(firstKey);
594
+ const first = values[0];
595
+ if (!first) {
596
+ this.inboundBySession.delete(firstKey);
597
+ continue;
598
+ }
599
+ this.removeInbound(first);
568
600
  }
569
601
  while (this.boundByRun.size > MAX_CAPTURES) this.boundByRun.delete(this.boundByRun.keys().next().value);
570
602
  while (this.toolCalls.size > MAX_CAPTURES) this.toolCalls.delete(this.toolCalls.keys().next().value);
@@ -711,6 +743,7 @@ var ProposalError = class extends Error {
711
743
  this.name = "ProposalError";
712
744
  }
713
745
  code;
746
+ retryable = false;
714
747
  };
715
748
  function requireText(proposal, key, min = 2) {
716
749
  const value = proposal[key];
@@ -882,11 +915,17 @@ function parseAndValidateProposal(raw, envelope, evidence, activeProfile) {
882
915
  if (!window) throw new ProposalError("DECISION_WINDOW_NOT_FOUND", "Proposal does not reference a trusted decision window");
883
916
  const decisionType = requireText(proposal, "decisionType");
884
917
  if (!window.allowedDecisionTypes.includes(decisionType)) {
885
- throw new ProposalError("DECISION_TYPE_NOT_ALLOWED", "decisionType is not valid for the trusted action window");
918
+ throw new ProposalError(
919
+ "DECISION_TYPE_NOT_ALLOWED",
920
+ `decisionType must be copied from allowedDecisionTypes: ${JSON.stringify(window.allowedDecisionTypes)}`
921
+ );
886
922
  }
887
923
  const alternativeActionType = requireText(proposal, "alternativeActionType");
888
924
  if (!window.availableActionTypes.includes(alternativeActionType)) {
889
- throw new ProposalError("ALTERNATIVE_ACTION_UNAVAILABLE", "The proposed alternative action was unavailable at that decision point");
925
+ throw new ProposalError(
926
+ "ALTERNATIVE_ACTION_UNAVAILABLE",
927
+ `alternativeActionType must be copied from availableActionTypes: ${JSON.stringify(window.availableActionTypes)}`
928
+ );
890
929
  }
891
930
  if (proposal.source === "SELF" && window.actorSeat !== envelope.game.recipientSeat) {
892
931
  throw new ProposalError("SELF_ACTOR_MISMATCH", "SELF evidence must anchor the recipient's own action");
@@ -2517,6 +2556,7 @@ var WerewolfEvolutionService = class {
2517
2556
  }
2518
2557
  this.cleanupOrdinaryDirectMessages(now);
2519
2558
  }
2559
+ return captured;
2520
2560
  }
2521
2561
  isSystemDebriefMessage(event, ctx) {
2522
2562
  const now = Date.now();
@@ -2577,6 +2617,7 @@ var WerewolfEvolutionService = class {
2577
2617
  });
2578
2618
  this.consumeOrdinaryDirectMessage(ctx.runId, ordinary);
2579
2619
  }
2620
+ return bound;
2580
2621
  }
2581
2622
  bindPromptRun(event, ctx, config) {
2582
2623
  const pending = this.contexts.getPending(ctx.runId, ctx.sessionKey, event.prompt);
@@ -2598,7 +2639,7 @@ var WerewolfEvolutionService = class {
2598
2639
  workspaceAuthorized = false;
2599
2640
  }
2600
2641
  }
2601
- this.bindAgentRun(
2642
+ const bound = this.bindAgentRun(
2602
2643
  {
2603
2644
  channelId,
2604
2645
  accountId,
@@ -2611,6 +2652,7 @@ var WerewolfEvolutionService = class {
2611
2652
  pending,
2612
2653
  ordinary
2613
2654
  );
2655
+ return bound ?? this.contexts.getBound(ctx.runId, ctx.sessionKey);
2614
2656
  }
2615
2657
  finishRun(ctx) {
2616
2658
  if (!ctx.runId) return;
@@ -2755,11 +2797,14 @@ var WerewolfEvolutionService = class {
2755
2797
  "- SKIP contains only schemaVersion, action, source, and a concrete skipReason.",
2756
2798
  "- Every non-SKIP proposal must provide profile, decisionWindowId, decisionType, alternativeActionType, anchorFactId, knownFactRefs, outcomeFactRefs, trigger, rule, boundary, behavior, alternativeAction, expectedLocalEffect, observedLocalEffect, falsifier, and alternatives.",
2757
2799
  "- Never send null for an omitted field. Omit the key instead. alternativeTargetSeat may be null only to represent an explicit DAY_VOTE abstention.",
2800
+ "- Copy decisionType exactly from the selected decisionWindow.allowedDecisionTypes. Copy alternativeActionType exactly from that same window.availableActionTypes; these are different fields and must not be mixed.",
2801
+ "- If alternativeActionType=DAY_VOTE, copy a legal seat from that window.availableTargetSeats, or send alternativeTargetSeat=null for explicit abstention. Do not omit the target for DAY_VOTE.",
2758
2802
  "Execution versus strategy contract:",
2759
2803
  "- executionOperation must be one of the exact template operations. To claim execution risk, copy that template's operation, decisionType, trigger, rule, boundary, and alternativeAction exactly.",
2760
2804
  "- Strategy proposals must omit executionOperation. CHOOSE_VOTE_TARGET and CHOOSE_ROLE_CLAIM_TIMING are decision types, never executionOperation values.",
2761
- "Call werewolf_debrief_commit exactly once after checking the complete proposal against this contract.",
2762
- "After the tool returns, regardless of accepted or rejected status, return exactly NO_REPLY. Never retry the tool call.",
2805
+ "Call werewolf_debrief_commit after checking the complete proposal against this contract.",
2806
+ "A rejected result with retryable=true means one field/semantic correction is allowed: correct only the reported issue using the same trusted window and call the tool once more. A rejected result with retryable=false is final; never call again.",
2807
+ "After a committed, duplicate, incident, or final rejected result, return exactly NO_REPLY. Never use a generic write tool or retry indefinitely.",
2763
2808
  "Do not return NO_REPLY before werewolf_debrief_commit returns a result.",
2764
2809
  "Never use generic write, edit, patch, shell, or memory-write tools for debrief state."
2765
2810
  ].join("\n");
@@ -2834,66 +2879,77 @@ var WerewolfEvolutionService = class {
2834
2879
  }, hooks);
2835
2880
  }
2836
2881
  commit(toolCallId, ctx, input, hooks = {}) {
2837
- const bound = this.contexts.consumeToolCall(toolCallId, ctx.sessionKey);
2838
- const workspaceDir = requireToolWorkspace(ctx, bound);
2839
- if (bound.inbound.kind !== "debrief") throw new Error("DEBRIEF_CAPABILITY_REQUIRED");
2840
- const captured = bound.inbound;
2841
- if (captured.conflict) throw new Error("DEBRIEF_ID_HASH_CONFLICT");
2842
- if (input.debriefId !== captured.envelope.debriefId) throw new Error("DEBRIEF_ID_MISMATCH");
2843
- const paths = resolveWorkspacePaths(workspaceDir);
2844
- return runWorkspaceTransaction(paths, () => {
2845
- assertWorkspaceSetupReady(paths, this.version);
2846
- const current = readWorkspaceState(paths);
2847
- const prior = current.ledger.entries.find((entry2) => entry2.debriefId === captured.envelope.debriefId);
2848
- if (prior) {
2849
- if (prior.bodyHash !== captured.bodyHash) throw new Error("DEBRIEF_ID_HASH_CONFLICT");
2850
- return { changes: /* @__PURE__ */ new Map(), result: { status: "duplicate", debriefId: captured.envelope.debriefId } };
2851
- }
2852
- if (current.ledger.entries.some((entry2) => entry2.gameId === captured.envelope.game.gameId)) {
2853
- return { changes: /* @__PURE__ */ new Map(), result: { status: "duplicate-game", gameId: captured.envelope.game.gameId } };
2854
- }
2855
- if (current.ledger.legacyGameIds.includes(captured.envelope.game.gameId)) {
2856
- return { changes: /* @__PURE__ */ new Map(), result: { status: "duplicate-game", gameId: captured.envelope.game.gameId } };
2857
- }
2858
- const next = clone(current);
2859
- const incidents = incidentReasons(captured.envelope);
2860
- let result;
2861
- if (incidents.length > 0) {
2862
- result = applyIncident(next, captured.envelope, captured.bodyHash, incidents);
2863
- } else {
2864
- const activeProfile = activeRuntimeProfile(current, captured.envelope.game.profile);
2865
- const validated = parseAndValidateProposal(
2866
- input.proposal,
2867
- captured.envelope,
2868
- current.evidence,
2869
- activeProfile
2870
- );
2871
- result = applyProposal(
2872
- next,
2873
- captured.envelope,
2874
- captured.bodyHash,
2875
- validated.proposal,
2876
- validated.risk,
2877
- validated.decisionWindow
2878
- );
2879
- }
2880
- next.agentsText = current.agentsText;
2881
- const changes = workspaceChanges(paths, next);
2882
- const changedProfiles = addProfileUpdates(paths, current, next, changes);
2883
- const finalAgentChange = workspaceChanges(paths, next).get(paths.agents);
2884
- if (finalAgentChange === void 0) changes.delete(paths.agents);
2885
- else changes.set(paths.agents, finalAgentChange);
2886
- return {
2887
- changes,
2888
- result: { status: "committed", debriefId: captured.envelope.debriefId, ...result },
2889
- verify: () => {
2890
- verifyWorkspaceDocuments(paths);
2891
- for (const [profile, expected] of changedProfiles) {
2892
- verifyProfileOverride(expected.file, profile, expected.content);
2893
- }
2882
+ const bound = this.contexts.beginProposalToolCall(toolCallId, ctx.sessionKey);
2883
+ let terminal = true;
2884
+ try {
2885
+ const workspaceDir = requireToolWorkspace(ctx, bound);
2886
+ if (bound.inbound.kind !== "debrief") throw new Error("DEBRIEF_CAPABILITY_REQUIRED");
2887
+ const captured = bound.inbound;
2888
+ if (captured.conflict) throw new Error("DEBRIEF_ID_HASH_CONFLICT");
2889
+ if (input.debriefId !== captured.envelope.debriefId) throw new Error("DEBRIEF_ID_MISMATCH");
2890
+ const paths = resolveWorkspacePaths(workspaceDir);
2891
+ return runWorkspaceTransaction(paths, () => {
2892
+ assertWorkspaceSetupReady(paths, this.version);
2893
+ const current = readWorkspaceState(paths);
2894
+ const prior = current.ledger.entries.find((entry2) => entry2.debriefId === captured.envelope.debriefId);
2895
+ if (prior) {
2896
+ if (prior.bodyHash !== captured.bodyHash) throw new Error("DEBRIEF_ID_HASH_CONFLICT");
2897
+ return { changes: /* @__PURE__ */ new Map(), result: { status: "duplicate", debriefId: captured.envelope.debriefId } };
2894
2898
  }
2895
- };
2896
- }, hooks);
2899
+ if (current.ledger.entries.some((entry2) => entry2.gameId === captured.envelope.game.gameId)) {
2900
+ return { changes: /* @__PURE__ */ new Map(), result: { status: "duplicate-game", gameId: captured.envelope.game.gameId } };
2901
+ }
2902
+ if (current.ledger.legacyGameIds.includes(captured.envelope.game.gameId)) {
2903
+ return { changes: /* @__PURE__ */ new Map(), result: { status: "duplicate-game", gameId: captured.envelope.game.gameId } };
2904
+ }
2905
+ const next = clone(current);
2906
+ const incidents = incidentReasons(captured.envelope);
2907
+ let result;
2908
+ if (incidents.length > 0) {
2909
+ result = applyIncident(next, captured.envelope, captured.bodyHash, incidents);
2910
+ } else {
2911
+ const activeProfile = activeRuntimeProfile(current, captured.envelope.game.profile);
2912
+ const validated = parseAndValidateProposal(
2913
+ input.proposal,
2914
+ captured.envelope,
2915
+ current.evidence,
2916
+ activeProfile
2917
+ );
2918
+ result = applyProposal(
2919
+ next,
2920
+ captured.envelope,
2921
+ captured.bodyHash,
2922
+ validated.proposal,
2923
+ validated.risk,
2924
+ validated.decisionWindow
2925
+ );
2926
+ }
2927
+ next.agentsText = current.agentsText;
2928
+ const changes = workspaceChanges(paths, next);
2929
+ const changedProfiles = addProfileUpdates(paths, current, next, changes);
2930
+ const finalAgentChange = workspaceChanges(paths, next).get(paths.agents);
2931
+ if (finalAgentChange === void 0) changes.delete(paths.agents);
2932
+ else changes.set(paths.agents, finalAgentChange);
2933
+ return {
2934
+ changes,
2935
+ result: { status: "committed", debriefId: captured.envelope.debriefId, ...result },
2936
+ verify: () => {
2937
+ verifyWorkspaceDocuments(paths);
2938
+ for (const [profile, expected] of changedProfiles) {
2939
+ verifyProfileOverride(expected.file, profile, expected.content);
2940
+ }
2941
+ }
2942
+ };
2943
+ }, hooks);
2944
+ } catch (error) {
2945
+ if (error instanceof ProposalError && bound.proposalAttempts < 2) {
2946
+ error.retryable = true;
2947
+ terminal = false;
2948
+ }
2949
+ throw error;
2950
+ } finally {
2951
+ if (terminal && !bound.consumed) this.contexts.consume(bound.runId, bound.sessionKey);
2952
+ }
2897
2953
  }
2898
2954
  decideSuggestion(toolCallId, ctx, input, hooks = {}) {
2899
2955
  const bound = this.contexts.consumeToolCall(toolCallId, ctx.sessionKey);
@@ -2932,7 +2988,14 @@ var WerewolfEvolutionService = class {
2932
2988
  }
2933
2989
  };
2934
2990
  function proposalFailure(error) {
2935
- if (error instanceof ProposalError) return { status: "rejected", code: error.code, message: error.message };
2991
+ if (error instanceof ProposalError) {
2992
+ return {
2993
+ status: "rejected",
2994
+ code: error.code,
2995
+ message: error.message,
2996
+ retryable: error.retryable
2997
+ };
2998
+ }
2936
2999
  return { status: "rejected", code: "EVOLUTION_ERROR", message: error instanceof Error ? error.message : String(error) };
2937
3000
  }
2938
3001
 
@@ -2961,8 +3024,12 @@ var proposalParameters = Type.Object({
2961
3024
  description: "Existing lesson id for SUPPORT, COUNTER, or REFINE. Omit for NEW and SKIP; never send null."
2962
3025
  })),
2963
3026
  profile: Type.Optional(Type.String()),
2964
- decisionWindowId: Type.Optional(Type.String()),
2965
- decisionType: Type.Optional(Type.String()),
3027
+ decisionWindowId: Type.Optional(Type.String({
3028
+ description: "Copy one exact decisionWindowId from trusted decisionWindows; never invent one."
3029
+ })),
3030
+ decisionType: Type.Optional(Type.String({
3031
+ description: "Copy one exact value from the selected window's allowedDecisionTypes. This is a decision category, not an actionType."
3032
+ })),
2966
3033
  executionOperation: Type.Optional(Type.Union([
2967
3034
  Type.Literal("REPORT_DECIDED_ROLE_CLAIM"),
2968
3035
  Type.Literal("EXPLAIN_DECIDED_VOTE"),
@@ -2972,8 +3039,12 @@ var proposalParameters = Type.Object({
2972
3039
  ], {
2973
3040
  description: "Exact operation from executionTemplates. Omit for strategy proposals; never invent an operation."
2974
3041
  })),
2975
- alternativeActionType: Type.Optional(Type.String()),
2976
- alternativeTargetSeat: Type.Optional(Type.Union([Type.Integer(), Type.Null()])),
3042
+ alternativeActionType: Type.Optional(Type.String({
3043
+ description: "Copy one exact game action from the selected window's availableActionTypes, for example DAY_SPEAK or DAY_VOTE. Never copy decisionType here."
3044
+ })),
3045
+ alternativeTargetSeat: Type.Optional(Type.Union([Type.Integer(), Type.Null()], {
3046
+ description: "For DAY_VOTE, choose an exact seat from availableTargetSeats or null for explicit abstention. Omit when the selected action has no target."
3047
+ })),
2977
3048
  anchorFactId: Type.Optional(Type.String()),
2978
3049
  knownFactRefs: Type.Optional(Type.Array(Type.String())),
2979
3050
  outcomeFactRefs: Type.Optional(Type.Array(Type.String())),
@@ -3036,10 +3107,20 @@ function registerWerewolfEvolution(api, service = getSharedWerewolfEvolutionServ
3036
3107
  api.registerTool((ctx) => createDebriefCommitTool(service, ctx), { name: "werewolf_debrief_commit" });
3037
3108
  api.registerTool((ctx) => createSuggestionDecideTool(service, ctx), { name: "werewolf_suggestion_decide" });
3038
3109
  api.on("message_received", (event, ctx) => {
3039
- service.captureMessage(event, ctx);
3110
+ const captured = service.captureMessage(event, ctx);
3111
+ if (!captured && event.content.includes(DEBRIEF_HEADER)) {
3112
+ api.logger.warn(
3113
+ `[werewolf-evolution] DEBRIEF_CAPTURE_REJECTED runId=${event.runId ?? ctx.runId ?? "unknown"} sessionKey=${event.sessionKey ?? ctx.sessionKey ?? "unknown"}`
3114
+ );
3115
+ }
3040
3116
  });
3041
3117
  api.on("before_prompt_build", (event, ctx) => {
3042
- service.bindPromptRun(event, ctx, api.config);
3118
+ const bound = service.bindPromptRun(event, ctx, api.config);
3119
+ if (!bound && event.prompt.includes(DEBRIEF_HEADER)) {
3120
+ api.logger.warn(
3121
+ `[werewolf-evolution] DEBRIEF_BIND_MISS runId=${ctx.runId ?? "unknown"} sessionKey=${ctx.sessionKey ?? "unknown"} agentId=${ctx.agentId ?? "unknown"}`
3122
+ );
3123
+ }
3043
3124
  return service.buildPromptContext(ctx);
3044
3125
  });
3045
3126
  api.on("before_tool_call", (event, ctx) => service.beforeToolCall(event, ctx));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clawtopia/werewolf-evolution",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "description": "Deterministic postgame evolution runtime for the Clawtopia Werewolf Play skill.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",