botinabox 2.5.2 → 2.5.3

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 (276) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +190 -190
  3. package/bin/botinabox.mjs +2 -2
  4. package/dist/{chunk-UACT2WXX.js → chunk-7AGWGYZC.js} +43 -5
  5. package/dist/cli.js +1 -1
  6. package/dist/connectors/google/index.d.ts +10 -1
  7. package/dist/connectors/google/index.js +1 -1
  8. package/dist/{gmail-connector-2FVYTQJH.js → gmail-connector-VP5FF56J.js} +2 -1
  9. package/package.json +100 -100
  10. package/dist/channels/discord/adapter.d.ts +0 -32
  11. package/dist/channels/discord/adapter.js +0 -70
  12. package/dist/channels/discord/inbound.d.ts +0 -25
  13. package/dist/channels/discord/inbound.js +0 -24
  14. package/dist/channels/discord/models.d.ts +0 -8
  15. package/dist/channels/discord/models.js +0 -5
  16. package/dist/channels/discord/outbound.d.ts +0 -14
  17. package/dist/channels/discord/outbound.js +0 -38
  18. package/dist/channels/slack/adapter.d.ts +0 -33
  19. package/dist/channels/slack/adapter.js +0 -74
  20. package/dist/channels/slack/inbound.d.ts +0 -59
  21. package/dist/channels/slack/inbound.js +0 -96
  22. package/dist/channels/slack/models.d.ts +0 -9
  23. package/dist/channels/slack/models.js +0 -5
  24. package/dist/channels/slack/outbound.d.ts +0 -12
  25. package/dist/channels/slack/outbound.js +0 -18
  26. package/dist/channels/slack/transcribe.d.ts +0 -41
  27. package/dist/channels/slack/transcribe.js +0 -106
  28. package/dist/channels/webhook/adapter.d.ts +0 -23
  29. package/dist/channels/webhook/adapter.js +0 -86
  30. package/dist/channels/webhook/hmac.d.ts +0 -13
  31. package/dist/channels/webhook/hmac.js +0 -26
  32. package/dist/channels/webhook/models.d.ts +0 -9
  33. package/dist/channels/webhook/models.js +0 -5
  34. package/dist/channels/webhook/server.d.ts +0 -20
  35. package/dist/channels/webhook/server.js +0 -91
  36. package/dist/chat-pipeline-BWrtVqEP.d.ts +0 -652
  37. package/dist/chat-pipeline-C-XlLGNl.d.ts +0 -648
  38. package/dist/chat-pipeline-CR1KF6eX.d.ts +0 -652
  39. package/dist/chat-pipeline-DisuC8SB.d.ts +0 -643
  40. package/dist/chunk-2LGXQPEA.js +0 -41
  41. package/dist/chunk-3X3YKI4T.js +0 -357
  42. package/dist/chunk-D47AIFOD.js +0 -351
  43. package/dist/chunk-DSNJKNEW.js +0 -328
  44. package/dist/chunk-GS2JFL6I.js +0 -144
  45. package/dist/chunk-J6S6QMUY.js +0 -144
  46. package/dist/chunk-QLA6YOFN.js +0 -22
  47. package/dist/cli/templates/config.yml.d.ts +0 -7
  48. package/dist/cli/templates/config.yml.js +0 -61
  49. package/dist/cli/templates/env.d.ts +0 -1
  50. package/dist/cli/templates/env.js +0 -30
  51. package/dist/cli/templates/index.ts.d.ts +0 -2
  52. package/dist/cli/templates/index.ts.js +0 -30
  53. package/dist/cli/templates/package.json.d.ts +0 -5
  54. package/dist/cli/templates/package.json.js +0 -28
  55. package/dist/connector-DDahQw-2.d.ts +0 -63
  56. package/dist/connectors/google/calendar-connector.d.ts +0 -40
  57. package/dist/connectors/google/calendar-connector.js +0 -243
  58. package/dist/connectors/google/gmail-connector.d.ts +0 -42
  59. package/dist/connectors/google/gmail-connector.js +0 -345
  60. package/dist/connectors/google/oauth.d.ts +0 -48
  61. package/dist/connectors/google/oauth.js +0 -112
  62. package/dist/connectors/google/types.d.ts +0 -78
  63. package/dist/connectors/google/types.js +0 -2
  64. package/dist/core/chat/auto-discovery.d.ts +0 -16
  65. package/dist/core/chat/auto-discovery.js +0 -54
  66. package/dist/core/chat/channel-registry.d.ts +0 -45
  67. package/dist/core/chat/channel-registry.js +0 -96
  68. package/dist/core/chat/chat-pipeline.d.ts +0 -113
  69. package/dist/core/chat/chat-pipeline.js +0 -395
  70. package/dist/core/chat/chat-responder.d.ts +0 -90
  71. package/dist/core/chat/chat-responder.js +0 -185
  72. package/dist/core/chat/formatter.d.ts +0 -11
  73. package/dist/core/chat/formatter.js +0 -60
  74. package/dist/core/chat/index.d.ts +0 -24
  75. package/dist/core/chat/index.js +0 -18
  76. package/dist/core/chat/message-interpreter.d.ts +0 -91
  77. package/dist/core/chat/message-interpreter.js +0 -166
  78. package/dist/core/chat/message-store.d.ts +0 -66
  79. package/dist/core/chat/message-store.js +0 -131
  80. package/dist/core/chat/notification-queue.d.ts +0 -34
  81. package/dist/core/chat/notification-queue.js +0 -111
  82. package/dist/core/chat/pipeline.d.ts +0 -38
  83. package/dist/core/chat/pipeline.js +0 -89
  84. package/dist/core/chat/policies.d.ts +0 -16
  85. package/dist/core/chat/policies.js +0 -25
  86. package/dist/core/chat/routing.d.ts +0 -17
  87. package/dist/core/chat/routing.js +0 -36
  88. package/dist/core/chat/session-key.d.ts +0 -30
  89. package/dist/core/chat/session-key.js +0 -65
  90. package/dist/core/chat/session-manager.d.ts +0 -17
  91. package/dist/core/chat/session-manager.js +0 -23
  92. package/dist/core/chat/text-chunker.d.ts +0 -9
  93. package/dist/core/chat/text-chunker.js +0 -48
  94. package/dist/core/chat/triage-router.d.ts +0 -75
  95. package/dist/core/chat/triage-router.js +0 -142
  96. package/dist/core/chat/types.d.ts +0 -5
  97. package/dist/core/chat/types.js +0 -5
  98. package/dist/core/config/defaults.d.ts +0 -2
  99. package/dist/core/config/defaults.js +0 -38
  100. package/dist/core/config/index.d.ts +0 -6
  101. package/dist/core/config/index.js +0 -4
  102. package/dist/core/config/interpolate.d.ts +0 -5
  103. package/dist/core/config/interpolate.js +0 -27
  104. package/dist/core/config/loader.d.ts +0 -24
  105. package/dist/core/config/loader.js +0 -59
  106. package/dist/core/config/schema.d.ts +0 -5
  107. package/dist/core/config/schema.js +0 -119
  108. package/dist/core/data/core-entity-contexts.d.ts +0 -14
  109. package/dist/core/data/core-entity-contexts.js +0 -197
  110. package/dist/core/data/core-migrations.d.ts +0 -5
  111. package/dist/core/data/core-migrations.js +0 -45
  112. package/dist/core/data/core-schema.d.ts +0 -6
  113. package/dist/core/data/core-schema.js +0 -454
  114. package/dist/core/data/data-store.d.ts +0 -67
  115. package/dist/core/data/data-store.js +0 -218
  116. package/dist/core/data/domain-entity-contexts.d.ts +0 -29
  117. package/dist/core/data/domain-entity-contexts.js +0 -321
  118. package/dist/core/data/domain-schema.d.ts +0 -36
  119. package/dist/core/data/domain-schema.js +0 -323
  120. package/dist/core/data/index.d.ts +0 -7
  121. package/dist/core/data/index.js +0 -7
  122. package/dist/core/data/types.d.ts +0 -111
  123. package/dist/core/data/types.js +0 -1
  124. package/dist/core/hooks/hook-bus.d.ts +0 -18
  125. package/dist/core/hooks/hook-bus.js +0 -120
  126. package/dist/core/hooks/index.d.ts +0 -2
  127. package/dist/core/hooks/index.js +0 -1
  128. package/dist/core/hooks/types.d.ts +0 -19
  129. package/dist/core/hooks/types.js +0 -1
  130. package/dist/core/index.d.ts +0 -4
  131. package/dist/core/index.js +0 -4
  132. package/dist/core/llm/auto-discovery.d.ts +0 -11
  133. package/dist/core/llm/auto-discovery.js +0 -49
  134. package/dist/core/llm/cost-tracker.d.ts +0 -6
  135. package/dist/core/llm/cost-tracker.js +0 -38
  136. package/dist/core/llm/index.d.ts +0 -4
  137. package/dist/core/llm/index.js +0 -3
  138. package/dist/core/llm/model-router.d.ts +0 -25
  139. package/dist/core/llm/model-router.js +0 -49
  140. package/dist/core/llm/provider-registry.d.ts +0 -9
  141. package/dist/core/llm/provider-registry.js +0 -25
  142. package/dist/core/llm/types.d.ts +0 -2
  143. package/dist/core/llm/types.js +0 -2
  144. package/dist/core/orchestrator/adapters/api-adapter.d.ts +0 -34
  145. package/dist/core/orchestrator/adapters/api-adapter.js +0 -88
  146. package/dist/core/orchestrator/adapters/cli-adapter.d.ts +0 -22
  147. package/dist/core/orchestrator/adapters/cli-adapter.js +0 -69
  148. package/dist/core/orchestrator/adapters/deterministic-adapter.d.ts +0 -35
  149. package/dist/core/orchestrator/adapters/deterministic-adapter.js +0 -75
  150. package/dist/core/orchestrator/adapters/env-whitelist.d.ts +0 -4
  151. package/dist/core/orchestrator/adapters/env-whitelist.js +0 -27
  152. package/dist/core/orchestrator/adapters/output-extractor.d.ts +0 -11
  153. package/dist/core/orchestrator/adapters/output-extractor.js +0 -59
  154. package/dist/core/orchestrator/adapters/process-manager.d.ts +0 -15
  155. package/dist/core/orchestrator/adapters/process-manager.js +0 -26
  156. package/dist/core/orchestrator/adapters/tool-loop.d.ts +0 -22
  157. package/dist/core/orchestrator/adapters/tool-loop.js +0 -66
  158. package/dist/core/orchestrator/agent-registry.d.ts +0 -31
  159. package/dist/core/orchestrator/agent-registry.js +0 -135
  160. package/dist/core/orchestrator/budget-controller.d.ts +0 -19
  161. package/dist/core/orchestrator/budget-controller.js +0 -73
  162. package/dist/core/orchestrator/chain-guard.d.ts +0 -14
  163. package/dist/core/orchestrator/chain-guard.js +0 -23
  164. package/dist/core/orchestrator/circuit-breaker.d.ts +0 -65
  165. package/dist/core/orchestrator/circuit-breaker.js +0 -159
  166. package/dist/core/orchestrator/claude-stream-parser.d.ts +0 -31
  167. package/dist/core/orchestrator/claude-stream-parser.js +0 -99
  168. package/dist/core/orchestrator/config-revisions.d.ts +0 -6
  169. package/dist/core/orchestrator/config-revisions.js +0 -17
  170. package/dist/core/orchestrator/dependency-resolver.d.ts +0 -20
  171. package/dist/core/orchestrator/dependency-resolver.js +0 -78
  172. package/dist/core/orchestrator/governance-gate.d.ts +0 -110
  173. package/dist/core/orchestrator/governance-gate.js +0 -170
  174. package/dist/core/orchestrator/learning-pipeline.d.ts +0 -109
  175. package/dist/core/orchestrator/learning-pipeline.js +0 -249
  176. package/dist/core/orchestrator/loop-detector.d.ts +0 -51
  177. package/dist/core/orchestrator/loop-detector.js +0 -133
  178. package/dist/core/orchestrator/ndjson-logger.d.ts +0 -6
  179. package/dist/core/orchestrator/ndjson-logger.js +0 -18
  180. package/dist/core/orchestrator/permission-relay.d.ts +0 -72
  181. package/dist/core/orchestrator/permission-relay.js +0 -164
  182. package/dist/core/orchestrator/run-manager.d.ts +0 -31
  183. package/dist/core/orchestrator/run-manager.js +0 -178
  184. package/dist/core/orchestrator/scheduler.d.ts +0 -70
  185. package/dist/core/orchestrator/scheduler.js +0 -198
  186. package/dist/core/orchestrator/secret-store.d.ts +0 -57
  187. package/dist/core/orchestrator/secret-store.js +0 -171
  188. package/dist/core/orchestrator/session-manager.d.ts +0 -13
  189. package/dist/core/orchestrator/session-manager.js +0 -66
  190. package/dist/core/orchestrator/task-queue.d.ts +0 -34
  191. package/dist/core/orchestrator/task-queue.js +0 -83
  192. package/dist/core/orchestrator/template-interpolate.d.ts +0 -5
  193. package/dist/core/orchestrator/template-interpolate.js +0 -18
  194. package/dist/core/orchestrator/user-registry.d.ts +0 -47
  195. package/dist/core/orchestrator/user-registry.js +0 -76
  196. package/dist/core/orchestrator/wakeup-queue.d.ts +0 -9
  197. package/dist/core/orchestrator/wakeup-queue.js +0 -45
  198. package/dist/core/orchestrator/workflow-engine.d.ts +0 -47
  199. package/dist/core/orchestrator/workflow-engine.js +0 -204
  200. package/dist/core/security/audit.d.ts +0 -20
  201. package/dist/core/security/audit.js +0 -33
  202. package/dist/core/security/column-validator.d.ts +0 -20
  203. package/dist/core/security/column-validator.js +0 -37
  204. package/dist/core/security/index.d.ts +0 -5
  205. package/dist/core/security/index.js +0 -5
  206. package/dist/core/security/process-env.d.ts +0 -13
  207. package/dist/core/security/process-env.js +0 -49
  208. package/dist/core/security/sanitizer.d.ts +0 -11
  209. package/dist/core/security/sanitizer.js +0 -39
  210. package/dist/core/security/types.d.ts +0 -11
  211. package/dist/core/security/types.js +0 -1
  212. package/dist/core/update/auto-update.d.ts +0 -21
  213. package/dist/core/update/auto-update.js +0 -102
  214. package/dist/core/update/backup-manager.d.ts +0 -7
  215. package/dist/core/update/backup-manager.js +0 -24
  216. package/dist/core/update/index.d.ts +0 -8
  217. package/dist/core/update/index.js +0 -6
  218. package/dist/core/update/migration-hooks.d.ts +0 -11
  219. package/dist/core/update/migration-hooks.js +0 -10
  220. package/dist/core/update/types.d.ts +0 -11
  221. package/dist/core/update/types.js +0 -1
  222. package/dist/core/update/update-checker.d.ts +0 -11
  223. package/dist/core/update/update-checker.js +0 -63
  224. package/dist/core/update/update-manager.d.ts +0 -25
  225. package/dist/core/update/update-manager.js +0 -101
  226. package/dist/core/update/version-utils.d.ts +0 -6
  227. package/dist/core/update/version-utils.js +0 -34
  228. package/dist/gmail-connector-MNUBRNFM.js +0 -6
  229. package/dist/gmail-connector-PS2VLGNE.js +0 -6
  230. package/dist/gmail-connector-ULSMN6X2.js +0 -6
  231. package/dist/gmail-connector-URRFX6A3.js +0 -6
  232. package/dist/inbound-AFBUPSPG.js +0 -10
  233. package/dist/inbound-AFOHYNUY.js +0 -6
  234. package/dist/inbound-CGIXRXGC.js +0 -8
  235. package/dist/inbound-MCOLRH6U.js +0 -10
  236. package/dist/inbound-SNEMBLGA.js +0 -6
  237. package/dist/inbound-ZJHAYVMF.js +0 -10
  238. package/dist/provider-qqJYv9nv.d.ts +0 -75
  239. package/dist/providers/anthropic/models.d.ts +0 -2
  240. package/dist/providers/anthropic/models.js +0 -29
  241. package/dist/providers/anthropic/provider.d.ts +0 -13
  242. package/dist/providers/anthropic/provider.js +0 -119
  243. package/dist/providers/anthropic/tool-converter.d.ts +0 -10
  244. package/dist/providers/anthropic/tool-converter.js +0 -7
  245. package/dist/providers/ollama/provider.d.ts +0 -17
  246. package/dist/providers/ollama/provider.js +0 -185
  247. package/dist/providers/openai/models.d.ts +0 -2
  248. package/dist/providers/openai/models.js +0 -29
  249. package/dist/providers/openai/provider.d.ts +0 -13
  250. package/dist/providers/openai/provider.js +0 -163
  251. package/dist/providers/openai/tool-converter.d.ts +0 -10
  252. package/dist/providers/openai/tool-converter.js +0 -10
  253. package/dist/shared/constants.d.ts +0 -50
  254. package/dist/shared/constants.js +0 -64
  255. package/dist/shared/index.d.ts +0 -14
  256. package/dist/shared/index.js +0 -14
  257. package/dist/shared/types/agent.d.ts +0 -36
  258. package/dist/shared/types/agent.js +0 -2
  259. package/dist/shared/types/channel.d.ts +0 -70
  260. package/dist/shared/types/channel.js +0 -2
  261. package/dist/shared/types/config.d.ts +0 -111
  262. package/dist/shared/types/config.js +0 -2
  263. package/dist/shared/types/connector.d.ts +0 -77
  264. package/dist/shared/types/connector.js +0 -2
  265. package/dist/shared/types/execution.d.ts +0 -29
  266. package/dist/shared/types/execution.js +0 -2
  267. package/dist/shared/types/provider.d.ts +0 -73
  268. package/dist/shared/types/provider.js +0 -2
  269. package/dist/shared/types/task.d.ts +0 -47
  270. package/dist/shared/types/task.js +0 -2
  271. package/dist/shared/types/workflow.d.ts +0 -39
  272. package/dist/shared/types/workflow.js +0 -2
  273. package/dist/shared/utils.d.ts +0 -6
  274. package/dist/shared/utils.js +0 -13
  275. package/dist/update-check.d.ts +0 -5
  276. package/dist/update-check.js +0 -56
@@ -1,31 +0,0 @@
1
- /**
2
- * Parse Claude CLI NDJSON (stream-json) output into structured results.
3
- * Used by the CLI execution adapter to extract session info, costs,
4
- * token usage, and text output from Claude CLI subprocess output.
5
- */
6
- export interface ParsedStream {
7
- sessionId: string | null;
8
- model: string | null;
9
- costUsd: number | null;
10
- usage: UsageSummary | null;
11
- summary: string;
12
- isError: boolean;
13
- errorMessage: string | null;
14
- stopReason: string | null;
15
- }
16
- export interface UsageSummary {
17
- inputTokens: number;
18
- cachedInputTokens: number;
19
- outputTokens: number;
20
- }
21
- /**
22
- * Parse Claude CLI NDJSON output into a structured result.
23
- * Handles init, assistant, and result event types.
24
- */
25
- export declare function parseClaudeStream(stdout: string): ParsedStream;
26
- /** Check if the run stopped due to max turns. */
27
- export declare function isMaxTurns(parsed: ParsedStream): boolean;
28
- /** Check if Claude CLI requires login. */
29
- export declare function isLoginRequired(stdout: string): boolean;
30
- /** Rewrite local image paths to prevent CLI auto-embedding as vision content. */
31
- export declare function deactivateLocalImagePaths(prompt: string): string;
@@ -1,99 +0,0 @@
1
- /**
2
- * Parse Claude CLI NDJSON (stream-json) output into structured results.
3
- * Used by the CLI execution adapter to extract session info, costs,
4
- * token usage, and text output from Claude CLI subprocess output.
5
- */
6
- /**
7
- * Parse Claude CLI NDJSON output into a structured result.
8
- * Handles init, assistant, and result event types.
9
- */
10
- export function parseClaudeStream(stdout) {
11
- let sessionId = null;
12
- let model = null;
13
- let costUsd = null;
14
- let usage = null;
15
- let isError = false;
16
- let errorMessage = null;
17
- let stopReason = null;
18
- const textBlocks = [];
19
- for (const line of stdout.split("\n")) {
20
- if (!line.trim())
21
- continue;
22
- let event;
23
- try {
24
- event = JSON.parse(line);
25
- }
26
- catch {
27
- continue;
28
- }
29
- const type = event.type;
30
- if (type === "system" && event.subtype === "init") {
31
- sessionId = event.session_id ?? null;
32
- model = event.model ?? null;
33
- }
34
- if (type === "assistant") {
35
- const msg = event.message;
36
- const content = msg?.content ?? event.content;
37
- if (Array.isArray(content)) {
38
- for (const block of content) {
39
- if (block.type === "text" && block.text) {
40
- textBlocks.push(block.text);
41
- }
42
- }
43
- }
44
- }
45
- if (type === "result") {
46
- isError = !!event.is_error;
47
- stopReason = event.stop_reason ?? null;
48
- costUsd =
49
- typeof event.total_cost_usd === "number" ? event.total_cost_usd : null;
50
- const u = event.usage;
51
- if (u) {
52
- usage = {
53
- inputTokens: u.input_tokens ?? 0,
54
- cachedInputTokens: u.cache_read_input_tokens ?? 0,
55
- outputTokens: u.output_tokens ?? 0,
56
- };
57
- }
58
- if (isError) {
59
- errorMessage =
60
- event.error ??
61
- event.result ??
62
- "Unknown error";
63
- }
64
- const resultContent = event.result;
65
- if (typeof resultContent === "string" && resultContent) {
66
- textBlocks.push(resultContent);
67
- }
68
- }
69
- }
70
- return {
71
- sessionId,
72
- model,
73
- costUsd,
74
- usage,
75
- summary: textBlocks.join("\n"),
76
- isError,
77
- errorMessage,
78
- stopReason,
79
- };
80
- }
81
- /** Check if the run stopped due to max turns. */
82
- export function isMaxTurns(parsed) {
83
- return (parsed.stopReason === "max_turns" || parsed.stopReason === "tool_use");
84
- }
85
- /** Check if Claude CLI requires login. */
86
- export function isLoginRequired(stdout) {
87
- const patterns = [
88
- "not logged in",
89
- "login required",
90
- "authentication required",
91
- "please log in",
92
- ];
93
- const lower = stdout.toLowerCase();
94
- return patterns.some((p) => lower.includes(p));
95
- }
96
- /** Rewrite local image paths to prevent CLI auto-embedding as vision content. */
97
- export function deactivateLocalImagePaths(prompt) {
98
- return prompt.replace(/(?<=\s|^)(\/[\w./-]+\.(?:png|jpg|jpeg|gif|webp|svg))(?=\s|$)/gi, "[image-path:$1]");
99
- }
@@ -1,6 +0,0 @@
1
- import type { DataStore } from '../data/data-store.js';
2
- /**
3
- * Creates a config revision record with before/after snapshots.
4
- * Note: uses config_revisions table with config_yaml storing JSON of {agentId, before, after}.
5
- */
6
- export declare function createConfigRevision(db: DataStore, agentId: string, before: Record<string, unknown>, after: Record<string, unknown>): Promise<void>;
@@ -1,17 +0,0 @@
1
- /**
2
- * Creates a config revision record with before/after snapshots.
3
- * Note: uses config_revisions table with config_yaml storing JSON of {agentId, before, after}.
4
- */
5
- export async function createConfigRevision(db, agentId, before, after) {
6
- // Get the current max version for this agent and increment
7
- const existing = await db.query('config_revisions', {
8
- where: { notes: agentId },
9
- });
10
- const version = existing.length + 1;
11
- await db.insert('config_revisions', {
12
- version,
13
- config_yaml: JSON.stringify({ agentId, before, after }),
14
- applied_by: agentId,
15
- notes: agentId,
16
- });
17
- }
@@ -1,20 +0,0 @@
1
- /**
2
- * Dependency resolution utilities for workflow steps and task deps.
3
- */
4
- export interface StepRef {
5
- id: string;
6
- dependsOn?: string[];
7
- }
8
- /**
9
- * DFS cycle detection — returns true if cycle exists.
10
- */
11
- export declare function detectCycle(steps: StepRef[]): boolean;
12
- /**
13
- * Returns step IDs in topological (execution) order.
14
- * Throws if a cycle is detected.
15
- */
16
- export declare function topologicalSort(steps: StepRef[]): string[];
17
- /**
18
- * Returns true if all dependencies are satisfied (present in completedTaskIds).
19
- */
20
- export declare function areDependenciesMet(taskDepsJson: string | undefined, completedTaskIds: Set<string>): boolean;
@@ -1,78 +0,0 @@
1
- /**
2
- * Dependency resolution utilities for workflow steps and task deps.
3
- */
4
- /**
5
- * DFS cycle detection — returns true if cycle exists.
6
- */
7
- export function detectCycle(steps) {
8
- const deps = new Map();
9
- for (const s of steps) {
10
- deps.set(s.id, s.dependsOn ?? []);
11
- }
12
- const WHITE = 0, GRAY = 1, BLACK = 2;
13
- const color = new Map();
14
- for (const s of steps)
15
- color.set(s.id, WHITE);
16
- function dfs(node) {
17
- color.set(node, GRAY);
18
- for (const dep of deps.get(node) ?? []) {
19
- const c = color.get(dep);
20
- if (c === GRAY)
21
- return true; // back edge = cycle
22
- if (c === WHITE && dfs(dep))
23
- return true;
24
- }
25
- color.set(node, BLACK);
26
- return false;
27
- }
28
- for (const s of steps) {
29
- if (color.get(s.id) === WHITE && dfs(s.id))
30
- return true;
31
- }
32
- return false;
33
- }
34
- /**
35
- * Returns step IDs in topological (execution) order.
36
- * Throws if a cycle is detected.
37
- */
38
- export function topologicalSort(steps) {
39
- if (detectCycle(steps)) {
40
- throw new Error('Cycle detected in step dependencies');
41
- }
42
- const deps = new Map();
43
- for (const s of steps) {
44
- deps.set(s.id, s.dependsOn ?? []);
45
- }
46
- const visited = new Set();
47
- const result = [];
48
- function visit(id) {
49
- if (visited.has(id))
50
- return;
51
- visited.add(id);
52
- for (const dep of deps.get(id) ?? []) {
53
- visit(dep);
54
- }
55
- result.push(id);
56
- }
57
- for (const s of steps) {
58
- visit(s.id);
59
- }
60
- return result;
61
- }
62
- /**
63
- * Returns true if all dependencies are satisfied (present in completedTaskIds).
64
- */
65
- export function areDependenciesMet(taskDepsJson, completedTaskIds) {
66
- if (!taskDepsJson)
67
- return true;
68
- let deps;
69
- try {
70
- deps = JSON.parse(taskDepsJson);
71
- }
72
- catch {
73
- return true;
74
- }
75
- if (!Array.isArray(deps) || deps.length === 0)
76
- return true;
77
- return deps.every((id) => completedTaskIds.has(id));
78
- }
@@ -1,110 +0,0 @@
1
- /**
2
- * GovernanceGate — independent validation gates for agent output.
3
- * Story 6.7
4
- *
5
- * Key principle: gates report to the HUMAN, not to each other
6
- * or to a project manager agent. Structural independence prevents capture.
7
- *
8
- * Gate dimensions:
9
- * QA — data correctness (schema, row counts, format)
10
- * Quality — code quality (lint, coverage, patterns)
11
- * Drift — architectural drift (unintended dependencies, scope creep)
12
- */
13
- import type { HookBus } from '../hooks/hook-bus.js';
14
- export type GateVerdict = 'pass' | 'fail' | 'warn';
15
- export interface GateResult {
16
- gateId: string;
17
- verdict: GateVerdict;
18
- findings: GateFinding[];
19
- checkedAt: string;
20
- durationMs: number;
21
- }
22
- export interface GateFinding {
23
- severity: 'info' | 'warning' | 'error' | 'critical';
24
- message: string;
25
- location?: string;
26
- suggestion?: string;
27
- }
28
- export interface GateInput {
29
- agentId: string;
30
- taskId: string;
31
- output: string;
32
- metadata?: Record<string, unknown>;
33
- }
34
- /**
35
- * Base class for governance gates. Each gate checks a different dimension.
36
- * Gates are structurally independent — they report to the human operator,
37
- * not to each other or to any agent.
38
- */
39
- export declare abstract class GovernanceGate {
40
- abstract readonly id: string;
41
- abstract readonly name: string;
42
- abstract readonly dimension: string;
43
- /**
44
- * Run the gate check on agent output.
45
- * Must return a verdict and any findings.
46
- */
47
- abstract check(input: GateInput): Promise<GateResult>;
48
- }
49
- /**
50
- * QA Gate — validates data correctness.
51
- * Checks: schema conformance, row counts, format validation.
52
- */
53
- export declare class QAGate extends GovernanceGate {
54
- private validators;
55
- readonly id = "qa";
56
- readonly name = "Quality Assurance";
57
- readonly dimension = "data_correctness";
58
- constructor(validators?: Array<{
59
- name: string;
60
- validate: (output: string, metadata?: Record<string, unknown>) => GateFinding[];
61
- }>);
62
- check(input: GateInput): Promise<GateResult>;
63
- }
64
- /**
65
- * Quality Gate — validates code quality.
66
- * Checks: lint results, test coverage, review patterns.
67
- */
68
- export declare class QualityGate extends GovernanceGate {
69
- private checks;
70
- readonly id = "quality";
71
- readonly name = "Code Quality";
72
- readonly dimension = "code_quality";
73
- constructor(checks?: Array<{
74
- name: string;
75
- check: (output: string, metadata?: Record<string, unknown>) => Promise<GateFinding[]>;
76
- }>);
77
- check(input: GateInput): Promise<GateResult>;
78
- }
79
- /**
80
- * Drift Gate — detects architectural drift.
81
- * Checks: unintended dependencies, scope creep, pattern violations.
82
- */
83
- export declare class DriftGate extends GovernanceGate {
84
- private rules;
85
- readonly id = "drift";
86
- readonly name = "Architectural Drift";
87
- readonly dimension = "architecture";
88
- constructor(rules?: Array<{
89
- name: string;
90
- detect: (output: string, metadata?: Record<string, unknown>) => GateFinding[];
91
- }>);
92
- check(input: GateInput): Promise<GateResult>;
93
- }
94
- /**
95
- * GateRunner — orchestrates multiple independent gates on agent output.
96
- * Each gate runs independently. Results are reported to the human, not to agents.
97
- */
98
- export declare class GateRunner {
99
- private gates;
100
- private hooks;
101
- constructor(gates: GovernanceGate[], hooks: HookBus);
102
- /**
103
- * Run all gates on the given input.
104
- * Gates run independently — one failure doesn't block others.
105
- */
106
- runAll(input: GateInput): Promise<{
107
- passed: boolean;
108
- results: GateResult[];
109
- }>;
110
- }
@@ -1,170 +0,0 @@
1
- /**
2
- * GovernanceGate — independent validation gates for agent output.
3
- * Story 6.7
4
- *
5
- * Key principle: gates report to the HUMAN, not to each other
6
- * or to a project manager agent. Structural independence prevents capture.
7
- *
8
- * Gate dimensions:
9
- * QA — data correctness (schema, row counts, format)
10
- * Quality — code quality (lint, coverage, patterns)
11
- * Drift — architectural drift (unintended dependencies, scope creep)
12
- */
13
- /**
14
- * Base class for governance gates. Each gate checks a different dimension.
15
- * Gates are structurally independent — they report to the human operator,
16
- * not to each other or to any agent.
17
- */
18
- export class GovernanceGate {
19
- }
20
- /**
21
- * QA Gate — validates data correctness.
22
- * Checks: schema conformance, row counts, format validation.
23
- */
24
- export class QAGate extends GovernanceGate {
25
- validators;
26
- id = 'qa';
27
- name = 'Quality Assurance';
28
- dimension = 'data_correctness';
29
- constructor(validators = []) {
30
- super();
31
- this.validators = validators;
32
- }
33
- async check(input) {
34
- const start = Date.now();
35
- const findings = [];
36
- for (const validator of this.validators) {
37
- const results = validator.validate(input.output, input.metadata);
38
- findings.push(...results);
39
- }
40
- const hasErrors = findings.some((f) => f.severity === 'error' || f.severity === 'critical');
41
- const hasWarnings = findings.some((f) => f.severity === 'warning');
42
- return {
43
- gateId: this.id,
44
- verdict: hasErrors ? 'fail' : hasWarnings ? 'warn' : 'pass',
45
- findings,
46
- checkedAt: new Date().toISOString(),
47
- durationMs: Date.now() - start,
48
- };
49
- }
50
- }
51
- /**
52
- * Quality Gate — validates code quality.
53
- * Checks: lint results, test coverage, review patterns.
54
- */
55
- export class QualityGate extends GovernanceGate {
56
- checks;
57
- id = 'quality';
58
- name = 'Code Quality';
59
- dimension = 'code_quality';
60
- constructor(checks = []) {
61
- super();
62
- this.checks = checks;
63
- }
64
- async check(input) {
65
- const start = Date.now();
66
- const findings = [];
67
- for (const chk of this.checks) {
68
- const results = await chk.check(input.output, input.metadata);
69
- findings.push(...results);
70
- }
71
- const hasErrors = findings.some((f) => f.severity === 'error' || f.severity === 'critical');
72
- const hasWarnings = findings.some((f) => f.severity === 'warning');
73
- return {
74
- gateId: this.id,
75
- verdict: hasErrors ? 'fail' : hasWarnings ? 'warn' : 'pass',
76
- findings,
77
- checkedAt: new Date().toISOString(),
78
- durationMs: Date.now() - start,
79
- };
80
- }
81
- }
82
- /**
83
- * Drift Gate — detects architectural drift.
84
- * Checks: unintended dependencies, scope creep, pattern violations.
85
- */
86
- export class DriftGate extends GovernanceGate {
87
- rules;
88
- id = 'drift';
89
- name = 'Architectural Drift';
90
- dimension = 'architecture';
91
- constructor(rules = []) {
92
- super();
93
- this.rules = rules;
94
- }
95
- async check(input) {
96
- const start = Date.now();
97
- const findings = [];
98
- for (const rule of this.rules) {
99
- const results = rule.detect(input.output, input.metadata);
100
- findings.push(...results);
101
- }
102
- const hasErrors = findings.some((f) => f.severity === 'error' || f.severity === 'critical');
103
- const hasWarnings = findings.some((f) => f.severity === 'warning');
104
- return {
105
- gateId: this.id,
106
- verdict: hasErrors ? 'fail' : hasWarnings ? 'warn' : 'pass',
107
- findings,
108
- checkedAt: new Date().toISOString(),
109
- durationMs: Date.now() - start,
110
- };
111
- }
112
- }
113
- /**
114
- * GateRunner — orchestrates multiple independent gates on agent output.
115
- * Each gate runs independently. Results are reported to the human, not to agents.
116
- */
117
- export class GateRunner {
118
- gates;
119
- hooks;
120
- constructor(gates, hooks) {
121
- this.gates = gates;
122
- this.hooks = hooks;
123
- }
124
- /**
125
- * Run all gates on the given input.
126
- * Gates run independently — one failure doesn't block others.
127
- */
128
- async runAll(input) {
129
- const results = [];
130
- for (const gate of this.gates) {
131
- try {
132
- const result = await gate.check(input);
133
- results.push(result);
134
- await this.hooks.emit('governance.gate_completed', {
135
- gateId: gate.id,
136
- gateName: gate.name,
137
- verdict: result.verdict,
138
- findingCount: result.findings.length,
139
- agentId: input.agentId,
140
- taskId: input.taskId,
141
- });
142
- }
143
- catch (err) {
144
- // Gate error — report but don't block others
145
- results.push({
146
- gateId: gate.id,
147
- verdict: 'fail',
148
- findings: [{
149
- severity: 'error',
150
- message: `Gate error: ${err instanceof Error ? err.message : String(err)}`,
151
- }],
152
- checkedAt: new Date().toISOString(),
153
- durationMs: 0,
154
- });
155
- }
156
- }
157
- const passed = results.every((r) => r.verdict !== 'fail');
158
- await this.hooks.emit('governance.review_completed', {
159
- passed,
160
- agentId: input.agentId,
161
- taskId: input.taskId,
162
- results: results.map((r) => ({
163
- gateId: r.gateId,
164
- verdict: r.verdict,
165
- findingCount: r.findings.length,
166
- })),
167
- });
168
- return { passed, results };
169
- }
170
- }
@@ -1,109 +0,0 @@
1
- /**
2
- * LearningPipeline — turns execution experience into durable knowledge.
3
- * Story 6.5
4
- *
5
- * Promotion ladder:
6
- * Execution → Feedback (structured capture)
7
- * → 3+ similar → Playbook (generalized rule)
8
- * → 3+ projects → Skill (executable behavior)
9
- * → Agent-Skill Matrix → Per-Agent Context
10
- *
11
- * Two-axis evaluation:
12
- * - Accuracy: was the output correct?
13
- * - Efficiency: how fast / how many tokens?
14
- */
15
- import type { DataStore } from '../data/data-store.js';
16
- import type { HookBus } from '../hooks/hook-bus.js';
17
- export interface FeedbackEntry {
18
- agentId: string;
19
- taskId?: string;
20
- issue: string;
21
- rootCause?: string;
22
- severity: 'low' | 'medium' | 'high' | 'critical';
23
- repeatable: boolean;
24
- accuracyScore?: number;
25
- efficiencyScore?: number;
26
- tags?: string[];
27
- }
28
- export interface PlaybookEntry {
29
- pattern: string;
30
- rule: string;
31
- feedbackIds: string[];
32
- projectScoped: boolean;
33
- agentIds?: string[];
34
- }
35
- export interface SkillEntry {
36
- name: string;
37
- slug: string;
38
- description?: string;
39
- behavior: string;
40
- sourcePlaybookIds: string[];
41
- category?: string;
42
- }
43
- export interface LearningPipelineConfig {
44
- /** Feedback count threshold for playbook promotion. Default: 3 */
45
- playbookThreshold?: number;
46
- /** Project count threshold for skill promotion. Default: 3 */
47
- skillThreshold?: number;
48
- /** Auto-promote when thresholds are met. Default: false */
49
- autoPromote?: boolean;
50
- }
51
- export declare class LearningPipeline {
52
- private db;
53
- private hooks;
54
- private readonly playbookThreshold;
55
- private readonly skillThreshold;
56
- private readonly autoPromote;
57
- constructor(db: DataStore, hooks: HookBus, config?: LearningPipelineConfig);
58
- /**
59
- * Capture a structured feedback record from an execution.
60
- */
61
- captureFeedback(entry: FeedbackEntry): Promise<string>;
62
- /**
63
- * Get all feedback records, optionally filtered.
64
- */
65
- listFeedback(filter?: {
66
- agentId?: string;
67
- severity?: string;
68
- repeatable?: boolean;
69
- }): Promise<Array<Record<string, unknown>>>;
70
- /**
71
- * Check if feedback records with similar issues should be promoted to a playbook.
72
- * Groups by issue text similarity (exact match for now).
73
- */
74
- checkPlaybookPromotion(issue: string): Promise<string | undefined>;
75
- /**
76
- * Manually create a playbook from a set of feedback records.
77
- */
78
- promoteToPlaybook(entry: PlaybookEntry): Promise<string>;
79
- /**
80
- * List playbooks, optionally filtered.
81
- */
82
- listPlaybooks(filter?: {
83
- projectScoped?: boolean;
84
- }): Promise<Array<Record<string, unknown>>>;
85
- /**
86
- * Check if a playbook should be promoted to a skill.
87
- * A playbook becomes a skill when it works across multiple projects
88
- * (indicated by being referenced by agents in different contexts).
89
- */
90
- checkSkillPromotion(playbookId: string): Promise<string | undefined>;
91
- /**
92
- * Manually promote a playbook to a reusable skill.
93
- */
94
- promoteToSkill(entry: SkillEntry): Promise<string>;
95
- /**
96
- * Assign a skill to an agent.
97
- */
98
- assignSkill(agentId: string, skillId: string): Promise<void>;
99
- /**
100
- * Get learning metrics for an agent.
101
- */
102
- getMetrics(agentId: string): Promise<{
103
- feedbackCount: number;
104
- avgAccuracy: number | null;
105
- avgEfficiency: number | null;
106
- playbookCount: number;
107
- skillCount: number;
108
- }>;
109
- }