@wrongstack/core 0.299.0 → 0.301.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (165) hide show
  1. package/dist/chronicle/index.d.ts +2 -0
  2. package/dist/chronicle/index.js +297 -10
  3. package/dist/chronicle/project-server.js +253 -15
  4. package/dist/chronicle/sqlite-compaction.d.ts +20 -0
  5. package/dist/chronicle/sqlite-journal.d.ts +57 -0
  6. package/dist/coordination/agents/capability-manifest.d.ts +7 -0
  7. package/dist/coordination/agents/index.d.ts +3 -2
  8. package/dist/coordination/agents/index.js +818 -570
  9. package/dist/coordination/agents/project-agent-identity.d.ts +6 -6
  10. package/dist/coordination/agents/role-skills.d.ts +1 -1
  11. package/dist/coordination/agents/types.d.ts +6 -0
  12. package/dist/coordination/director.d.ts +10 -2
  13. package/dist/coordination/fleet-manager.d.ts +48 -3
  14. package/dist/coordination/ifleet-manager.d.ts +2 -0
  15. package/dist/coordination/index.js +6880 -6440
  16. package/dist/coordination/mail-tools.d.ts +3 -3
  17. package/dist/coordination/mailbox-project-server.js +3 -4
  18. package/dist/coordination/mailbox-types.d.ts +6 -0
  19. package/dist/coordination/multi-agent-coordinator.d.ts +1 -0
  20. package/dist/core/agent-response.d.ts +5 -1
  21. package/dist/core/agent-tools.d.ts +3 -0
  22. package/dist/core/context.d.ts +20 -0
  23. package/dist/core/fallback-model.d.ts +48 -0
  24. package/dist/core/index.d.ts +11 -9
  25. package/dist/core/index.js +1119 -310
  26. package/dist/core/instruction-template.d.ts +83 -0
  27. package/dist/core/next-steps-slot.d.ts +88 -0
  28. package/dist/core/system-prompt-blocks.d.ts +10 -1
  29. package/dist/core/system-prompt-builder.d.ts +40 -4
  30. package/dist/core/system-prompt-memory-skills.d.ts +1 -0
  31. package/dist/core/system-prompt-skill-bodies.d.ts +3 -3
  32. package/dist/defaults/index.js +9805 -8767
  33. package/dist/design/index.js +11 -3
  34. package/dist/execution/auto-compaction-middleware.d.ts +17 -0
  35. package/dist/execution/autonomy-brain.d.ts +15 -2
  36. package/dist/execution/brain-runtime.d.ts +3 -1
  37. package/dist/execution/compaction-core.d.ts +41 -2
  38. package/dist/execution/council-brain.d.ts +47 -1
  39. package/dist/execution/council-orchestrator.d.ts +25 -6
  40. package/dist/execution/council-prompts.d.ts +12 -1
  41. package/dist/execution/index.d.ts +11 -10
  42. package/dist/execution/index.js +10507 -9189
  43. package/dist/execution/tool-executor.d.ts +4 -1
  44. package/dist/execution/topic-shift-advisor.d.ts +53 -0
  45. package/dist/extension/index.js +8 -2
  46. package/dist/extension/registry.d.ts +8 -1
  47. package/dist/fleet-notifier.d.ts +9 -2
  48. package/dist/goal/index.js +11 -3
  49. package/dist/hooks/index.js +50 -13
  50. package/dist/hooks/runner.d.ts +12 -1
  51. package/dist/hq/index.js +59 -21
  52. package/dist/hq/protocol/fleet.d.ts +20 -0
  53. package/dist/hq/protocol.js +10 -0
  54. package/dist/hq/publisher.d.ts +21 -3
  55. package/dist/index.d.ts +22 -20
  56. package/dist/index.js +12211 -8572
  57. package/dist/infrastructure/index.js +108 -21
  58. package/dist/kernel/events/brain-events.d.ts +9 -0
  59. package/dist/kernel/events/provider-events.d.ts +42 -1
  60. package/dist/kernel/events/session-events.d.ts +13 -0
  61. package/dist/kernel/events/tool-events.d.ts +3 -3
  62. package/dist/models/index.d.ts +1 -0
  63. package/dist/models/index.js +18 -1
  64. package/dist/models/provider-credentials.d.ts +54 -0
  65. package/dist/plugin/api.d.ts +6 -0
  66. package/dist/plugin/config.d.ts +55 -0
  67. package/dist/plugin/index.d.ts +2 -1
  68. package/dist/plugin/index.js +2179 -544
  69. package/dist/plugins/auto-review-plugin.d.ts +3 -0
  70. package/dist/plugins/cloud-config-sync-plugin.d.ts +22 -0
  71. package/dist/plugins/review-claim-registry.d.ts +23 -8
  72. package/dist/plugins/review-types.d.ts +2 -0
  73. package/dist/registry/index.js +109 -74
  74. package/dist/registry/tool-registry.d.ts +15 -0
  75. package/dist/security/capabilities.d.ts +2 -0
  76. package/dist/security/index.d.ts +2 -2
  77. package/dist/security/index.js +166 -44
  78. package/dist/security/permission-helpers.d.ts +23 -6
  79. package/dist/security/permission-policy.d.ts +16 -0
  80. package/dist/security/readonly-permission-policy.d.ts +20 -0
  81. package/dist/security/totp.d.ts +14 -0
  82. package/dist/session-registry-atomic-file.d.ts +32 -5
  83. package/dist/skills/frontmatter.d.ts +6 -0
  84. package/dist/skills/index.js +22 -5
  85. package/dist/storage/cloud-config-sync/sanitize.d.ts +54 -0
  86. package/dist/storage/cloud-config-sync.d.ts +87 -0
  87. package/dist/storage/director-state.d.ts +7 -0
  88. package/dist/storage/index.d.ts +1 -0
  89. package/dist/storage/index.js +887 -74
  90. package/dist/tools/fallback-system-config-view-tool.d.ts +1 -1
  91. package/dist/tools/index.d.ts +1 -1
  92. package/dist/tools/index.js +898 -335
  93. package/dist/tools/one-shot-llm-tool.d.ts +1 -0
  94. package/dist/tools/plugin-manager.d.ts +27 -0
  95. package/dist/types/config/mcp-features.d.ts +18 -11
  96. package/dist/types/config/root.d.ts +8 -1
  97. package/dist/types/config/runtime.d.ts +20 -6
  98. package/dist/types/config/skills-fleet-brain.d.ts +12 -4
  99. package/dist/types/config/tools.d.ts +16 -0
  100. package/dist/types/context-window.d.ts +1 -0
  101. package/dist/types/council.d.ts +11 -0
  102. package/dist/types/hooks.d.ts +14 -0
  103. package/dist/types/index.d.ts +3 -3
  104. package/dist/types/index.js +1 -0
  105. package/dist/types/multi-agent.d.ts +12 -0
  106. package/dist/types/one-shot-llm.d.ts +25 -0
  107. package/dist/types/plugin.d.ts +28 -0
  108. package/dist/types/provider.d.ts +16 -0
  109. package/dist/types/runtime-capability-manifest.d.ts +168 -0
  110. package/dist/types/skill.d.ts +5 -0
  111. package/dist/types/system-prompt.d.ts +3 -1
  112. package/dist/types/tool-executor.d.ts +8 -1
  113. package/dist/utils/context-breakdown.d.ts +8 -2
  114. package/dist/utils/index.d.ts +1 -1
  115. package/dist/utils/index.js +141 -31
  116. package/dist/utils/regex-guard.d.ts +16 -2
  117. package/dist/utils/sage-output-block.d.ts +7 -10
  118. package/dist/utils/wstack-paths.d.ts +11 -3
  119. package/dist/worktree/index.js +4 -4
  120. package/instructions/agents/browser.md +1 -4
  121. package/instructions/agents/e2e.md +17 -15
  122. package/instructions/agents/ios.md +3 -3
  123. package/instructions/agents/search.md +1 -1
  124. package/instructions/autonomy/goal-preamble.md +4 -4
  125. package/instructions/coordination/director-preamble.md +2 -3
  126. package/instructions/coordination/subagent-baseline.md +3 -1
  127. package/instructions/leader-after-task.md +12 -0
  128. package/instructions/llm/chimera-review.md +1 -1
  129. package/instructions/modes/audit-lite.md +1 -1
  130. package/instructions/sections/tool/common-patterns.md +18 -2
  131. package/instructions/sections/tool/mailbox-compact.md +1 -1
  132. package/instructions/sections/tool/mailbox-full.md +1 -1
  133. package/instructions/system-lite.md +91 -3
  134. package/instructions/system-pro.md +296 -102
  135. package/instructions/system.md +248 -92
  136. package/package.json +3 -3
  137. package/skills/api-design/SKILL.md +3 -0
  138. package/skills/audit-log/SKILL.md +2 -0
  139. package/skills/auto-review/SKILL.md +6 -1
  140. package/skills/bug-hunter/SKILL.md +4 -1
  141. package/skills/chimera/SKILL.md +3 -0
  142. package/skills/data-governance/SKILL.md +3 -0
  143. package/skills/design-system/SKILL.md +5 -2
  144. package/skills/docker-deploy/SKILL.md +2 -0
  145. package/skills/git-flow/SKILL.md +2 -0
  146. package/skills/mailbox-bridge/SKILL.md +3 -0
  147. package/skills/mnemosyne/SKILL.md +2 -0
  148. package/skills/multi-agent/SKILL.md +4 -1
  149. package/skills/node-modern/SKILL.md +4 -1
  150. package/skills/observability/SKILL.md +3 -0
  151. package/skills/output-standards/SKILL.md +2 -0
  152. package/skills/plugin-author/SKILL.md +4 -1
  153. package/skills/prompt-engineering/SKILL.md +3 -1
  154. package/skills/react-modern/SKILL.md +6 -3
  155. package/skills/refactor-planner/SKILL.md +2 -0
  156. package/skills/research-web/SKILL.md +3 -0
  157. package/skills/sdd/SKILL.md +3 -1
  158. package/skills/security-scanner/SKILL.md +3 -0
  159. package/skills/skill-creator/SKILL.md +2 -0
  160. package/skills/tech-stack/SKILL.md +3 -0
  161. package/skills/testing/SKILL.md +4 -1
  162. package/skills/typescript-strict/SKILL.md +4 -1
  163. package/skills/wrongstack-kanban/SKILL.md +6 -3
  164. package/skills/wrongstack-mailbox/SKILL.md +4 -1
  165. package/skills/wrongstack-mailbox-mcp/SKILL.md +10 -8
@@ -75,12 +75,12 @@ export declare function makeMailSendTool(opts?: MailToolsOptions): {
75
75
  required: string[];
76
76
  };
77
77
  execute(input: unknown, ctx: Context): Promise<{
78
- ok: boolean;
79
- error: string;
80
78
  messageId?: never;
81
- from?: never;
82
79
  to?: never;
83
80
  summary?: never;
81
+ ok: boolean;
82
+ error: string;
83
+ from?: never;
84
84
  } | {
85
85
  error?: never;
86
86
  ok: boolean;
@@ -1371,9 +1371,7 @@ function isMailboxMessageVisibleTo(message, agentId, role) {
1371
1371
  }
1372
1372
  function validateSendType(type, to) {
1373
1373
  if (type === "control") {
1374
- throw new TypeError(
1375
- 'Type "control" is reserved for runtime use and cannot be set by agents'
1376
- );
1374
+ throw new TypeError('Type "control" is reserved for runtime use and cannot be set by agents');
1377
1375
  }
1378
1376
  const isMultiRecipient = to === "*" || to.startsWith("@session:");
1379
1377
  if (type === "assign" && isMultiRecipient) {
@@ -1411,7 +1409,8 @@ function isMailboxReceiptRecordV2(value) {
1411
1409
  if (typeof v["timestamp"] !== "string" || v["timestamp"].length === 0) return false;
1412
1410
  if ("read" in v && typeof v["read"] !== "boolean") return false;
1413
1411
  if ("completed" in v && typeof v["completed"] !== "boolean") return false;
1414
- if ("outcome" in v && v["outcome"] !== void 0 && typeof v["outcome"] !== "string") return false;
1412
+ if ("outcome" in v && v["outcome"] !== void 0 && typeof v["outcome"] !== "string")
1413
+ return false;
1415
1414
  return true;
1416
1415
  }
1417
1416
 
@@ -204,6 +204,12 @@ export interface MailboxSessionAffinityContext {
204
204
  * compatibility).
205
205
  * 6. Otherwise drop (`false`).
206
206
  *
207
+ * PR #314 guard contract: presence checks intentionally use strict
208
+ * `!== undefined` comparisons for both the affinity token and its optional
209
+ * fields. Do not simplify them to nullish checks: malformed persisted `null`
210
+ * values must remain on the token-bearing path and fail closed in the shape
211
+ * guard rather than being treated as absent.
212
+ *
207
213
  * Trust note: the filter accepts the sender-asserted `sessionAffinity.sessionId`
208
214
  * without store cross-check (rule 3). The persisted-report fallback (rule 4)
209
215
  * is the only server-side check. A sender that fabricates both an affinity
@@ -186,6 +186,7 @@ export declare class DefaultMultiAgentCoordinator extends EventEmitter implement
186
186
  * `awaitTasks()` caller. Pushes the result and fires the event directly.
187
187
  */
188
188
  private emitPendingAborted;
189
+ private trimCompletedResults;
189
190
  private runDispatched;
190
191
  private executeWithTimeout;
191
192
  private recordCompletion;
@@ -28,7 +28,11 @@ export interface AgentResponseHandler {
28
28
  * todos change during tool execution. Keeping this block volatile makes the
29
29
  * final-response contract follow the live todo state on every iteration.
30
30
  */
31
- export declare function buildLiveNextStepsGateBlock(ctx: Pick<Context, 'agentId' | 'todos'>): TextBlock | undefined;
31
+ export declare function buildLiveNextStepsGateBlock(ctx: Pick<Context, 'agentId' | 'todos'> & {
32
+ tools?: readonly {
33
+ name: string;
34
+ }[] | undefined;
35
+ }): TextBlock | undefined;
32
36
  export declare function createAgentResponseHandler(a: AgentInternals): AgentResponseHandler;
33
37
  export {};
34
38
  //# sourceMappingURL=agent-response.d.ts.map
@@ -12,6 +12,9 @@ export interface AgentToolHandler {
12
12
  id: string;
13
13
  name: string;
14
14
  input: unknown;
15
+ }, preToolContext?: {
16
+ text: string;
17
+ contextAs: 'inline' | 'separate';
15
18
  }): Promise<{
16
19
  result: ToolResultBlock;
17
20
  durationMs: number;
@@ -50,6 +50,8 @@ export interface ContextInit {
50
50
  allowOutsideProjectRoot?: boolean | undefined;
51
51
  model: string;
52
52
  tools?: Tool[] | undefined;
53
+ /** Complete executable catalog for lazy discovery/meta-tools. */
54
+ catalogTools?: Tool[] | undefined;
53
55
  /** Agent id performing this run (e.g. 'leader', 'executor', 'tech-stack'). */
54
56
  agentId?: string | undefined;
55
57
  /** Human-readable agent name. */
@@ -63,6 +65,12 @@ export interface ContextInit {
63
65
  */
64
66
  traceId?: string | undefined;
65
67
  }
68
+ export interface ProviderMemoryEvidence {
69
+ /** Stable owner key, for example `sage.tool-memory`. */
70
+ source: string;
71
+ /** Provider-bound evidence text; never appended to chat/tool history. */
72
+ text: string;
73
+ }
66
74
  /**
67
75
  * L1-A: `Context` is the live agent-run object. Its read-only environment
68
76
  * shape is exposed by the `RunEnv` interface (every field below the
@@ -197,6 +205,8 @@ export declare class Context implements RunEnv {
197
205
  allowOutsideProjectRoot: boolean;
198
206
  model: string;
199
207
  tools: Tool[];
208
+ /** Complete enabled catalog; provider token accounting continues to use `tools`. */
209
+ catalogTools: Tool[];
200
210
  meta: Record<string, unknown>;
201
211
  /** Agent id performing this run (e.g. 'leader', 'executor'). */
202
212
  agentId: string;
@@ -266,6 +276,16 @@ export declare class Context implements RunEnv {
266
276
  * Cleared after being consumed by agent-tools.
267
277
  */
268
278
  pendingPostToolContext: string | undefined;
279
+ /**
280
+ * Bounded, provider-bound memory evidence kept outside conversation and
281
+ * tool-result history. Owners replace their own slot instead of appending a
282
+ * fresh message on every retrieval, so long sessions do not accumulate the
283
+ * same SAGE hints. Request construction emits these as ephemeral system
284
+ * suffixes, preserving the stable prompt-cache prefix.
285
+ */
286
+ memoryEvidence: ProviderMemoryEvidence[];
287
+ setMemoryEvidence(source: string, text: string | undefined, maxChars?: number): void;
288
+ clearMemoryEvidence(source?: string): void;
269
289
  /**
270
290
  * H1: pre-computed total-request token estimate from the most recent
271
291
  * `estimateRequestTokens()` call in the agent loop's pre-flight step.
@@ -90,7 +90,55 @@ export interface FallbackModelDeps {
90
90
  * the fallback chain.
91
91
  */
92
92
  statusTracker?: ProviderModelStatusTracker | undefined;
93
+ /**
94
+ * When set, the fallback chain pauses BEFORE attempting any fallback entry
95
+ * and emits `provider.fallback_pending`. The gate waits for a choice
96
+ * (manual pick or auto-countdown) before proceeding. This lets the UI show
97
+ * a modal with a countdown and manual model selection on every fallback hop.
98
+ *
99
+ * Returns the chosen model reference, or `null` to auto-switch to the next
100
+ * candidate (countdown expired or user accepted the default).
101
+ */
102
+ fallbackGate?: FallbackGateFn | undefined;
103
+ /**
104
+ * Seconds the UI counts down before auto-switching. Default: 7.
105
+ */
106
+ fallbackGateSeconds?: number | undefined;
93
107
  }
108
+ /**
109
+ * Gate function invoked when the fallback chain is about to engage. It should
110
+ * emit `provider.fallback_pending` on the supplied `events` bus — carrying a
111
+ * unique `requestId` and a `timestamp` in the payload — wait for the UI's
112
+ * `provider.fallback_choice` emission echoing that `requestId` (or the
113
+ * countdown), and resolve with the selected model or `null` to accept the
114
+ * default next. See `createFallbackGate` in the CLI wiring for a reference
115
+ * implementation.
116
+ */
117
+ export type FallbackGateFn = (params: {
118
+ events: EventBus;
119
+ sessionId: string | undefined;
120
+ from: {
121
+ providerId: string;
122
+ model: string;
123
+ };
124
+ status: number;
125
+ candidates: Array<{
126
+ providerId: string;
127
+ model: string;
128
+ }>;
129
+ autoSwitchSeconds: number;
130
+ /**
131
+ * Correlation id owned by the caller (the fallback-model extension). The
132
+ * gate MUST echo it in `provider.fallback_pending` so the UI's choice
133
+ * reply and the eventual `provider.fallback` completion event share the
134
+ * same id — clients use it to match the modal to the right gate when
135
+ * parallel requests fail on the same primary.
136
+ */
137
+ requestId: string;
138
+ }) => Promise<{
139
+ providerId: string;
140
+ model: string;
141
+ } | null>;
94
142
  export declare function fallbackProfileChain(config: Config, profileName: string | undefined): string[];
95
143
  export declare function smartDefaultFallbackChain(config: Config): string[];
96
144
  /**
@@ -1,15 +1,17 @@
1
1
  export { Agent, type RunResult, type UserInputPayload, } from './agent.js';
2
- export { createDefaultPipelines, type AgentInit, type AgentInput, type AgentPipelines, type ToolCallPipelinePayload, } from './agent-types.js';
3
- export { Context, type ContextInit, type RunOptions, type TodoItem } from './context.js';
4
- export { ConversationState, type ReadonlyConversationState, type StateChange, type StateChangeHandler, wrapAsState, } from './conversation-state.js';
5
- export { InputBuilder, type InputBuilderEvent, type InputBuilderOptions, } from './input-builder.js';
2
+ export { type AgentInit, type AgentInput, type AgentPipelines, createDefaultPipelines, type ToolCallPipelinePayload, } from './agent-types.js';
6
3
  export { buildBtwBlock, consumeBtwNotes, pendingBtwCount, setBtwNote, } from './btw.js';
4
+ export { Context, type ContextInit, type ProviderMemoryEvidence, type RunOptions, type TodoItem, } from './context.js';
7
5
  export { type ContinuationInput, type ContinuationSource, detectContinueIntent, type ResolvedContinuation, resolveContinuation, } from './continue-intent.js';
8
- export { createFallbackModelExtension, effectiveFallbackChain, fallbackProfileChain, smartDefaultFallbackChain, } from './fallback-model.js';
6
+ export { ConversationState, type ReadonlyConversationState, type StateChange, type StateChangeHandler, wrapAsState, } from './conversation-state.js';
7
+ export { createFallbackModelExtension, effectiveFallbackChain, type FallbackGateFn, type FallbackModelDeps, fallbackProfileChain, smartDefaultFallbackChain, } from './fallback-model.js';
9
8
  export { FallbackProfileManager } from './fallback-profile-manager.js';
10
- export { formatModelRef, normalizeModelRef, parseModelRef, type ModelRef, } from './model-ref.js';
11
- export { DefaultSystemPromptBuilder, type DefaultSystemPromptBuilderOptions, type SystemBlockSource, } from './system-prompt-builder.js';
12
- export type { SystemInstructionVariant } from './instruction-bundle.js';
13
- export { setQueuedMessagesSnapshot } from './queued-messages.js';
9
+ export { InputBuilder, type InputBuilderEvent, type InputBuilderOptions, } from './input-builder.js';
10
+ export { type InstructionBundle, type InstructionBundlePaths, loadInstructionBundle, type SystemInstructionVariant, } from './instruction-bundle.js';
11
+ export { type InstructionTemplateContext, renderInstructionLayer, } from './instruction-template.js';
12
+ export { formatModelRef, type ModelRef, normalizeModelRef, parseModelRef, } from './model-ref.js';
13
+ export { clearPendingNextSteps, hasNextStepsTag, MAX_PENDING_NEXT_STEPS, maybeAppendPendingNextSteps, type PendingNextStep, readPendingNextSteps, renderNextStepsBlock, writePendingNextSteps, } from './next-steps-slot.js';
14
14
  export { runProviderWithRetry } from './provider-runner.js';
15
+ export { setQueuedMessagesSnapshot } from './queued-messages.js';
16
+ export { DefaultSystemPromptBuilder, type DefaultSystemPromptBuilderOptions, type SystemBlockSource, } from './system-prompt-builder.js';
15
17
  //# sourceMappingURL=index.d.ts.map