wotann 0.5.39 → 0.5.40

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 (130) hide show
  1. package/dist/autopilot/completion-oracle.d.ts +71 -0
  2. package/dist/autopilot/completion-oracle.d.ts.map +1 -1
  3. package/dist/autopilot/completion-oracle.js +69 -2
  4. package/dist/autopilot/completion-oracle.js.map +1 -1
  5. package/dist/context/compaction-floor.d.ts +100 -0
  6. package/dist/context/compaction-floor.d.ts.map +1 -0
  7. package/dist/context/compaction-floor.js +94 -0
  8. package/dist/context/compaction-floor.js.map +1 -0
  9. package/dist/daemon/kairos-rpc.d.ts +1 -0
  10. package/dist/daemon/kairos-rpc.d.ts.map +1 -1
  11. package/dist/daemon/kairos-rpc.js +24 -0
  12. package/dist/daemon/kairos-rpc.js.map +1 -1
  13. package/dist/daemon/rpc-handlers/ports-rpc.d.ts +100 -0
  14. package/dist/daemon/rpc-handlers/ports-rpc.d.ts.map +1 -0
  15. package/dist/daemon/rpc-handlers/ports-rpc.js +278 -0
  16. package/dist/daemon/rpc-handlers/ports-rpc.js.map +1 -0
  17. package/dist/hooks/agentmemory-event-taxonomy.d.ts +144 -0
  18. package/dist/hooks/agentmemory-event-taxonomy.d.ts.map +1 -0
  19. package/dist/hooks/agentmemory-event-taxonomy.js +85 -0
  20. package/dist/hooks/agentmemory-event-taxonomy.js.map +1 -0
  21. package/dist/hooks/built-in.d.ts.map +1 -1
  22. package/dist/hooks/built-in.js +7 -3
  23. package/dist/hooks/built-in.js.map +1 -1
  24. package/dist/index.js +2 -1
  25. package/dist/index.js.map +1 -1
  26. package/dist/lib.d.ts +1 -1
  27. package/dist/lib.d.ts.map +1 -1
  28. package/dist/lib.js +1 -1
  29. package/dist/lib.js.map +1 -1
  30. package/dist/memory/injection-scanner.d.ts +78 -0
  31. package/dist/memory/injection-scanner.d.ts.map +1 -0
  32. package/dist/memory/injection-scanner.js +204 -0
  33. package/dist/memory/injection-scanner.js.map +1 -0
  34. package/dist/middleware/ttsr.d.ts +79 -3
  35. package/dist/middleware/ttsr.d.ts.map +1 -1
  36. package/dist/middleware/ttsr.js +136 -16
  37. package/dist/middleware/ttsr.js.map +1 -1
  38. package/dist/orchestration/ports-bridge.d.ts +325 -0
  39. package/dist/orchestration/ports-bridge.d.ts.map +1 -0
  40. package/dist/orchestration/ports-bridge.js +712 -0
  41. package/dist/orchestration/ports-bridge.js.map +1 -0
  42. package/dist/orchestration/textgrad-refinement.d.ts +123 -0
  43. package/dist/orchestration/textgrad-refinement.d.ts.map +1 -0
  44. package/dist/orchestration/textgrad-refinement.js +111 -0
  45. package/dist/orchestration/textgrad-refinement.js.map +1 -0
  46. package/dist/prompt/engine.d.ts +15 -0
  47. package/dist/prompt/engine.d.ts.map +1 -1
  48. package/dist/prompt/engine.js +20 -7
  49. package/dist/prompt/engine.js.map +1 -1
  50. package/dist/prompt/modules/capabilities.d.ts.map +1 -1
  51. package/dist/prompt/modules/capabilities.js +1 -0
  52. package/dist/prompt/modules/capabilities.js.map +1 -1
  53. package/dist/prompt/modules/caveman.d.ts.map +1 -1
  54. package/dist/prompt/modules/caveman.js +1 -0
  55. package/dist/prompt/modules/caveman.js.map +1 -1
  56. package/dist/prompt/modules/conventions.d.ts.map +1 -1
  57. package/dist/prompt/modules/conventions.js +1 -0
  58. package/dist/prompt/modules/conventions.js.map +1 -1
  59. package/dist/prompt/modules/identity.d.ts.map +1 -1
  60. package/dist/prompt/modules/identity.js +1 -0
  61. package/dist/prompt/modules/identity.js.map +1 -1
  62. package/dist/prompt/modules/index.d.ts +29 -0
  63. package/dist/prompt/modules/index.d.ts.map +1 -1
  64. package/dist/prompt/modules/index.js +51 -9
  65. package/dist/prompt/modules/index.js.map +1 -1
  66. package/dist/prompt/modules/llms-txt.d.ts.map +1 -1
  67. package/dist/prompt/modules/llms-txt.js +2 -4
  68. package/dist/prompt/modules/llms-txt.js.map +1 -1
  69. package/dist/prompt/modules/safety.d.ts.map +1 -1
  70. package/dist/prompt/modules/safety.js +1 -0
  71. package/dist/prompt/modules/safety.js.map +1 -1
  72. package/dist/prompt/modules/security.d.ts.map +1 -1
  73. package/dist/prompt/modules/security.js +1 -0
  74. package/dist/prompt/modules/security.js.map +1 -1
  75. package/dist/prompt/modules/skills.d.ts.map +1 -1
  76. package/dist/prompt/modules/skills.js +1 -0
  77. package/dist/prompt/modules/skills.js.map +1 -1
  78. package/dist/prompt/modules/tools.d.ts.map +1 -1
  79. package/dist/prompt/modules/tools.js +1 -0
  80. package/dist/prompt/modules/tools.js.map +1 -1
  81. package/dist/prompt/modules/user.d.ts.map +1 -1
  82. package/dist/prompt/modules/user.js +1 -0
  83. package/dist/prompt/modules/user.js.map +1 -1
  84. package/dist/providers/credential-pool.d.ts +45 -1
  85. package/dist/providers/credential-pool.d.ts.map +1 -1
  86. package/dist/providers/credential-pool.js +94 -1
  87. package/dist/providers/credential-pool.js.map +1 -1
  88. package/dist/providers/sticky-rotation-wire.d.ts +133 -0
  89. package/dist/providers/sticky-rotation-wire.d.ts.map +1 -0
  90. package/dist/providers/sticky-rotation-wire.js +185 -0
  91. package/dist/providers/sticky-rotation-wire.js.map +1 -0
  92. package/dist/runtime-hooks/ttsr-rule.d.ts +82 -0
  93. package/dist/runtime-hooks/ttsr-rule.d.ts.map +1 -0
  94. package/dist/runtime-hooks/ttsr-rule.js +207 -0
  95. package/dist/runtime-hooks/ttsr-rule.js.map +1 -0
  96. package/dist/runtime-hooks/ttsr-runner.d.ts +129 -0
  97. package/dist/runtime-hooks/ttsr-runner.d.ts.map +1 -0
  98. package/dist/runtime-hooks/ttsr-runner.js +193 -0
  99. package/dist/runtime-hooks/ttsr-runner.js.map +1 -0
  100. package/dist/runtime-hooks/ttsr-scope.d.ts +115 -0
  101. package/dist/runtime-hooks/ttsr-scope.d.ts.map +1 -0
  102. package/dist/runtime-hooks/ttsr-scope.js +378 -0
  103. package/dist/runtime-hooks/ttsr-scope.js.map +1 -0
  104. package/dist/sandbox/unified-exec.d.ts.map +1 -1
  105. package/dist/sandbox/unified-exec.js +6 -1
  106. package/dist/sandbox/unified-exec.js.map +1 -1
  107. package/dist/skills/cli-anything.d.ts.map +1 -1
  108. package/dist/skills/cli-anything.js +4 -1
  109. package/dist/skills/cli-anything.js.map +1 -1
  110. package/dist/skills/limits.d.ts +86 -0
  111. package/dist/skills/limits.d.ts.map +1 -0
  112. package/dist/skills/limits.js +140 -0
  113. package/dist/skills/limits.js.map +1 -0
  114. package/dist/skills/loader.d.ts +9 -0
  115. package/dist/skills/loader.d.ts.map +1 -1
  116. package/dist/skills/loader.js +29 -1
  117. package/dist/skills/loader.js.map +1 -1
  118. package/dist/storage/session-artifacts.d.ts +105 -0
  119. package/dist/storage/session-artifacts.d.ts.map +1 -0
  120. package/dist/storage/session-artifacts.js +198 -0
  121. package/dist/storage/session-artifacts.js.map +1 -0
  122. package/dist/tools/workspace-pack.d.ts +97 -0
  123. package/dist/tools/workspace-pack.d.ts.map +1 -0
  124. package/dist/tools/workspace-pack.js +228 -0
  125. package/dist/tools/workspace-pack.js.map +1 -0
  126. package/dist/tui/composer-history.d.ts +99 -0
  127. package/dist/tui/composer-history.d.ts.map +1 -0
  128. package/dist/tui/composer-history.js +169 -0
  129. package/dist/tui/composer-history.js.map +1 -0
  130. package/package.json +1 -1
@@ -3,7 +3,30 @@
3
3
  * Intercepts model output mid-stream via regex triggers.
4
4
  * Rules fire DURING generation, not before or after.
5
5
  * Zero upfront context cost — rules only consume tokens when triggered.
6
+ *
7
+ * ── Surface split (do not collapse these into one class) ──────────────
8
+ *
9
+ * TTSREngine ← legacy: severity-tiered regex-only scan with
10
+ * per-rule fire caps. Used by tests/unit/ttsr.test.ts
11
+ * and existing callers that don't know about stream
12
+ * scopes. Kept stable so downstream wires keep
13
+ * working unchanged.
14
+ *
15
+ * TTSRRunner ← new: scope-aware, per-token, one-shot-by-default
16
+ * runner ported from oh-my-pi. Lives in
17
+ * src/runtime-hooks/ttsr-runner.ts. The orchestrator
18
+ * (not the engine) decides abort/retry.
19
+ *
20
+ * The engine OPTIONALLY hosts a runner — when constructed with one,
21
+ * `processChunk` consults the runner and surfaces structured triggers
22
+ * via the same `injections` channel so legacy callers stay
23
+ * compatible. Orchestrators that want full scope-aware semantics use
24
+ * the new `processScopedChunk` path instead, which preserves the
25
+ * `TTSRTrigger` shape end to end.
6
26
  */
27
+ import type { TTSRRule as ScopedTTSRRule } from "../runtime-hooks/ttsr-rule.js";
28
+ import { TTSRRunner, type TTSRTrigger } from "../runtime-hooks/ttsr-runner.js";
29
+ import type { StreamContext } from "../runtime-hooks/ttsr-scope.js";
7
30
  export type TTSRSeverity = "critical" | "warning" | "info";
8
31
  export interface TTSRRule {
9
32
  readonly trigger: RegExp;
@@ -17,18 +40,70 @@ export interface TTSRResult {
17
40
  readonly injections: readonly string[];
18
41
  readonly shouldAbort: boolean;
19
42
  readonly retrySystemMessage?: string;
43
+ /** Structured triggers from the scope-aware runner (if attached). */
44
+ readonly triggers?: readonly TTSRTrigger[];
45
+ }
46
+ /**
47
+ * Result of a scope-aware chunk evaluation. Carries the same fields
48
+ * as `TTSRResult` plus the trigger list. `shouldAbort` is true when
49
+ * any scoped trigger fired — the orchestrator decides whether to
50
+ * actually abort.
51
+ */
52
+ export interface TTSRScopedResult extends TTSRResult {
53
+ readonly triggers: readonly TTSRTrigger[];
20
54
  }
21
55
  export declare class TTSREngine {
22
56
  private readonly rules;
23
- constructor(customRules?: readonly TTSRRule[]);
57
+ private readonly runner?;
58
+ constructor(customRules?: readonly TTSRRule[], runner?: TTSRRunner);
59
+ /**
60
+ * Build an engine that owns a scope-aware `TTSRRunner` populated
61
+ * with the supplied scoped rules.
62
+ *
63
+ * Pass `legacyRules: false` to disable the legacy severity-tiered
64
+ * regex rules (only the runner fires).
65
+ */
66
+ static withScopedRules(scopedRules: readonly ScopedTTSRRule[], options?: {
67
+ legacyRules?: boolean;
68
+ }): TTSREngine;
69
+ /** Read-only access to the underlying scoped runner, if attached. */
70
+ getRunner(): TTSRRunner | undefined;
24
71
  static defaultRules(): TTSRRule[];
25
72
  /**
26
- * Process a chunk of streaming model output.
73
+ * Process a chunk of streaming model output (legacy path).
74
+ *
27
75
  * Returns the chunk (unmodified) plus any triggered injections.
76
+ *
77
+ * If a scoped runner is attached, the chunk is ALSO fed to it
78
+ * with a permissive `{ kind: "text" }` context so legacy callers
79
+ * receive any runner-emitted triggers via the same `injections`
80
+ * channel. Scope-aware callers should use `processScopedChunk`
81
+ * instead so they can supply real stream context (thinking
82
+ * channel, tool-call args, file paths).
28
83
  */
29
84
  processChunk(chunk: string): TTSRResult;
30
85
  /**
31
- * Reset fire counts for a new session.
86
+ * Scope-aware streaming evaluation. Use this when you have real
87
+ * stream context (text vs thinking vs a specific tool call) and
88
+ * you want only scoped rules to fire.
89
+ *
90
+ * Returns a `TTSRScopedResult` whose `triggers` field is the
91
+ * primary signal — `injections` and `shouldAbort` are present
92
+ * for compatibility with legacy callers.
93
+ *
94
+ * NOTE: This method does NOT run the legacy severity rules; if
95
+ * you want both, call `processChunk` after this and merge.
96
+ */
97
+ processScopedChunk(chunk: string, ctx: StreamContext): TTSRScopedResult;
98
+ /**
99
+ * Acknowledge that the orchestrator processed the trigger for
100
+ * `ruleId`. Forwards to the runner so one-shot rules stop
101
+ * firing.
102
+ */
103
+ acknowledgeFired(ruleId: string): void;
104
+ /**
105
+ * Reset fire counts for a new session. Also clears scoped
106
+ * runner state when attached (buffers AND fired records).
32
107
  */
33
108
  reset(): void;
34
109
  /**
@@ -37,4 +112,5 @@ export declare class TTSREngine {
37
112
  addRule(rule: TTSRRule): void;
38
113
  getRules(): readonly TTSRRule[];
39
114
  }
115
+ export type { TTSRTrigger } from "../runtime-hooks/ttsr-runner.js";
40
116
  //# sourceMappingURL=ttsr.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ttsr.d.ts","sourceRoot":"","sources":["../../src/middleware/ttsr.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,MAAM,YAAY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BAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,aAAa,GAAG,gBAAgB;IAkCvE;;;;OAIG;IACH,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAItC;;;OAGG;IACH,KAAK,IAAI,IAAI;IAOb;;OAEG;IACH,OAAO,CAAC,IAAI,EAAE,QAAQ,GAAG,IAAI;IAI7B,QAAQ,IAAI,SAAS,QAAQ,EAAE;CAGhC;AAED,YAAY,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC"}
@@ -3,13 +3,52 @@
3
3
  * Intercepts model output mid-stream via regex triggers.
4
4
  * Rules fire DURING generation, not before or after.
5
5
  * Zero upfront context cost — rules only consume tokens when triggered.
6
+ *
7
+ * ── Surface split (do not collapse these into one class) ──────────────
8
+ *
9
+ * TTSREngine ← legacy: severity-tiered regex-only scan with
10
+ * per-rule fire caps. Used by tests/unit/ttsr.test.ts
11
+ * and existing callers that don't know about stream
12
+ * scopes. Kept stable so downstream wires keep
13
+ * working unchanged.
14
+ *
15
+ * TTSRRunner ← new: scope-aware, per-token, one-shot-by-default
16
+ * runner ported from oh-my-pi. Lives in
17
+ * src/runtime-hooks/ttsr-runner.ts. The orchestrator
18
+ * (not the engine) decides abort/retry.
19
+ *
20
+ * The engine OPTIONALLY hosts a runner — when constructed with one,
21
+ * `processChunk` consults the runner and surfaces structured triggers
22
+ * via the same `injections` channel so legacy callers stay
23
+ * compatible. Orchestrators that want full scope-aware semantics use
24
+ * the new `processScopedChunk` path instead, which preserves the
25
+ * `TTSRTrigger` shape end to end.
6
26
  */
27
+ import { TTSRRunner } from "../runtime-hooks/ttsr-runner.js";
7
28
  export class TTSREngine {
8
29
  rules;
9
- constructor(customRules) {
10
- this.rules = customRules
11
- ? [...customRules]
12
- : TTSREngine.defaultRules();
30
+ runner;
31
+ constructor(customRules, runner) {
32
+ this.rules = customRules ? [...customRules] : TTSREngine.defaultRules();
33
+ if (runner) {
34
+ this.runner = runner;
35
+ }
36
+ }
37
+ /**
38
+ * Build an engine that owns a scope-aware `TTSRRunner` populated
39
+ * with the supplied scoped rules.
40
+ *
41
+ * Pass `legacyRules: false` to disable the legacy severity-tiered
42
+ * regex rules (only the runner fires).
43
+ */
44
+ static withScopedRules(scopedRules, options) {
45
+ const runner = new TTSRRunner({ rules: scopedRules });
46
+ const legacyRules = options?.legacyRules ?? true;
47
+ return new TTSREngine(legacyRules ? undefined : [], runner);
48
+ }
49
+ /** Read-only access to the underlying scoped runner, if attached. */
50
+ getRunner() {
51
+ return this.runner;
13
52
  }
14
53
  static defaultRules() {
15
54
  return [
@@ -53,8 +92,16 @@ export class TTSREngine {
53
92
  ];
54
93
  }
55
94
  /**
56
- * Process a chunk of streaming model output.
95
+ * Process a chunk of streaming model output (legacy path).
96
+ *
57
97
  * Returns the chunk (unmodified) plus any triggered injections.
98
+ *
99
+ * If a scoped runner is attached, the chunk is ALSO fed to it
100
+ * with a permissive `{ kind: "text" }` context so legacy callers
101
+ * receive any runner-emitted triggers via the same `injections`
102
+ * channel. Scope-aware callers should use `processScopedChunk`
103
+ * instead so they can supply real stream context (thinking
104
+ * channel, tool-call args, file paths).
58
105
  */
59
106
  processChunk(chunk) {
60
107
  const injections = [];
@@ -70,29 +117,102 @@ export class TTSREngine {
70
117
  }
71
118
  }
72
119
  }
120
+ const triggers = [];
121
+ if (this.runner) {
122
+ const scoped = this.runner.observeAll(chunk, { kind: "text" });
123
+ for (const t of scoped) {
124
+ injections.push(t.rule.body);
125
+ triggers.push(t);
126
+ }
127
+ }
73
128
  const hasCritical = criticalInjections.length > 0;
74
- // Only abort on critical severity injections; warnings and info are advisory only
129
+ // Scoped triggers also count as abort-worthy: they represent a
130
+ // hard rule (file-typed, scope-gated) that the orchestrator
131
+ // explicitly opted into via withScopedRules.
132
+ const shouldAbort = hasCritical || triggers.length > 0;
133
+ const retryLines = [];
134
+ if (hasCritical) {
135
+ retryLines.push("TTSR RETRY SYSTEM MESSAGE", "The previous streaming attempt was aborted because it emitted one of the following critical patterns:", ...criticalInjections);
136
+ }
137
+ if (triggers.length > 0) {
138
+ if (retryLines.length === 0) {
139
+ retryLines.push("TTSR RETRY SYSTEM MESSAGE");
140
+ }
141
+ retryLines.push("The previous streaming attempt was aborted by scoped rules:", ...triggers.map((t) => `- ${t.rule.id}: ${t.rule.body}`));
142
+ }
143
+ if (retryLines.length > 0) {
144
+ retryLines.push("Restart the response and do not repeat the flagged patterns.");
145
+ }
75
146
  return {
76
147
  modified: chunk,
77
148
  injections,
78
- shouldAbort: hasCritical,
79
- retrySystemMessage: hasCritical
80
- ? [
81
- "TTSR RETRY SYSTEM MESSAGE",
82
- "The previous streaming attempt was aborted because it emitted one of the following critical patterns:",
83
- ...criticalInjections,
84
- "Restart the response from scratch and do not repeat the flagged patterns.",
85
- ].join("\n")
86
- : undefined,
149
+ shouldAbort,
150
+ retrySystemMessage: retryLines.length > 0 ? retryLines.join("\n") : undefined,
151
+ ...(triggers.length > 0 ? { triggers } : {}),
87
152
  };
88
153
  }
89
154
  /**
90
- * Reset fire counts for a new session.
155
+ * Scope-aware streaming evaluation. Use this when you have real
156
+ * stream context (text vs thinking vs a specific tool call) and
157
+ * you want only scoped rules to fire.
158
+ *
159
+ * Returns a `TTSRScopedResult` whose `triggers` field is the
160
+ * primary signal — `injections` and `shouldAbort` are present
161
+ * for compatibility with legacy callers.
162
+ *
163
+ * NOTE: This method does NOT run the legacy severity rules; if
164
+ * you want both, call `processChunk` after this and merge.
165
+ */
166
+ processScopedChunk(chunk, ctx) {
167
+ if (!this.runner) {
168
+ return {
169
+ modified: chunk,
170
+ injections: [],
171
+ shouldAbort: false,
172
+ triggers: [],
173
+ };
174
+ }
175
+ const triggers = this.runner.observeAll(chunk, ctx);
176
+ const injections = triggers.map((t) => t.rule.body);
177
+ if (triggers.length === 0) {
178
+ return {
179
+ modified: chunk,
180
+ injections,
181
+ shouldAbort: false,
182
+ triggers,
183
+ };
184
+ }
185
+ const retry = [
186
+ "TTSR RETRY SYSTEM MESSAGE",
187
+ "The previous streaming attempt was aborted by scoped rules:",
188
+ ...triggers.map((t) => `- ${t.rule.id}: ${t.rule.body}`),
189
+ "Restart the response and do not repeat the flagged patterns.",
190
+ ].join("\n");
191
+ return {
192
+ modified: chunk,
193
+ injections,
194
+ shouldAbort: true,
195
+ retrySystemMessage: retry,
196
+ triggers,
197
+ };
198
+ }
199
+ /**
200
+ * Acknowledge that the orchestrator processed the trigger for
201
+ * `ruleId`. Forwards to the runner so one-shot rules stop
202
+ * firing.
203
+ */
204
+ acknowledgeFired(ruleId) {
205
+ this.runner?.acknowledgeFired(ruleId);
206
+ }
207
+ /**
208
+ * Reset fire counts for a new session. Also clears scoped
209
+ * runner state when attached (buffers AND fired records).
91
210
  */
92
211
  reset() {
93
212
  for (const rule of this.rules) {
94
213
  rule.firedCount = 0;
95
214
  }
215
+ this.runner?.reset();
96
216
  }
97
217
  /**
98
218
  * Add a custom rule at runtime.
@@ -1 +1 @@
1
- {"version":3,"file":"ttsr.js","sourceRoot":"","sources":["../../src/middleware/ttsr.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAmBH,MAAM,OAAO,UAAU;IACJ,KAAK,CAAa;IAEnC,YAAY,WAAiC;QAC3C,IAAI,CAAC,KAAK,GAAG,WAAW;YACtB,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC;YAClB,CAAC,CAAC,UAAU,CAAC,YAAY,EAAE,CAAC;IAChC,CAAC;IAED,MAAM,CAAC,YAAY;QACjB,OAAO;YACL;gBACE,OAAO,EAAE,iBAAiB;gBAC1B,SAAS,EAAE,yEAAyE;gBACpF,QAAQ,EAAE,SAAS;gBACnB,kBAAkB,EAAE,CAAC;gBACrB,UAAU,EAAE,CAAC;aACd;YACD;gBACE,4EAA4E;gBAC5E,+EAA+E;gBAC/E,OAAO,EAAE,sCAAsC;gBAC/C,SAAS,EAAE,gEAAgE;gBAC3E,QAAQ,EAAE,SAAS;gBACnB,kBAAkB,EAAE,CAAC;gBACrB,UAAU,EAAE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AAC;QACJ,CAAC;QACD,MAAM,KAAK,GAAG;YACZ,2BAA2B;YAC3B,6DAA6D;YAC7D,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YACxD,8DAA8D;SAC/D,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACb,OAAO;YACL,QAAQ,EAAE,KAAK;YACf,UAAU;YACV,WAAW,EAAE,IAAI;YACjB,kBAAkB,EAAE,KAAK;YACzB,QAAQ;SACT,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,gBAAgB,CAAC,MAAc;QAC7B,IAAI,CAAC,MAAM,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC;IACxC,CAAC;IAED;;;OAGG;IACH,KAAK;QACH,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YAC9B,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC;QACtB,CAAC;QACD,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,OAAO,CAAC,IAAc;QACpB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;CACF"}
@@ -0,0 +1,325 @@
1
+ /**
2
+ * ports-bridge — business-level bridge functions for the 4 zombie ports.
3
+ *
4
+ * The audit finding #8 surfaced that four port primitives shipped under
5
+ * `src/ports/*` are library-only — they're re-exported from `src/lib.ts`
6
+ * but no internal consumer reaches them. They were never callable from
7
+ * the daemon's RPC surface, because each requires dependency injection
8
+ * (converse callback, search provider, graph store, dom adapter) that
9
+ * a JSON-RPC frame cannot transport.
10
+ *
11
+ * This module is the missing seam:
12
+ *
13
+ * - Each port is a *library primitive*. The bridge constructs the
14
+ * dependency-injected primitive INTERNALLY from business-level inputs
15
+ * (a chatdev waterfall spec + query, a research query, a text blob to
16
+ * ingest into a memory graph, a DOM snapshot to locate against).
17
+ *
18
+ * - The daemon RPC handlers (src/daemon/rpc-handlers/ports-rpc.ts) call
19
+ * these bridge functions one-to-one. They are the *only* in-process
20
+ * consumer; the bridge does not call them back. No cycle.
21
+ *
22
+ * - Each bridge function follows the QB#3 honest-stub policy: if a real
23
+ * dependency cannot be reached (no LLM provider for chatdev, no
24
+ * search provider for deer-flow), the bridge returns an `ok:false`
25
+ * envelope with a verbatim `reason` string. It NEVER silently
26
+ * succeeds with mock data.
27
+ *
28
+ * - For mem0-graph and scrapling-adaptive the in-memory backends are
29
+ * always available, so the bridge wires those by default and only
30
+ * surfaces failure when the input itself is malformed.
31
+ *
32
+ * QB bars honoured:
33
+ * QB#3 honest stub — no silent success
34
+ * QB#7 zero module-level mutable state — every bridge call constructs
35
+ * its own primitives
36
+ * QB#10 errors surface verbatim
37
+ * QB#13 no direct env reads except through the audit-friendly
38
+ * `WOTANN_*` knobs documented per-function
39
+ * QB#19 every type/exports is consumed by at least one handler
40
+ *
41
+ * Imports use ESM `.js` suffixes; strict TypeScript with ES2022 target.
42
+ */
43
+ import { type ConverseFn, type Phase, type PhaseOutcome, type Role, type WaterfallResult } from "../ports/chatdev-waterfall.js";
44
+ import { type Findings, type Planner, type Reporter, type Researcher, type ResearchOutcome, type SubQuestion } from "../ports/deer-flow-research.js";
45
+ import { type ExtractedTriple, type GraphEdge, type GraphEntity, type GraphStore, type TripleExtractorLLM } from "../ports/mem0-graph-memory.js";
46
+ import { type DomAdapter } from "../ports/scrapling-adaptive.js";
47
+ import type { SearchProvider } from "../intelligence/research-loops/strategies/base-strategy.js";
48
+ export interface RuntimeConverseRef {
49
+ /**
50
+ * Execute a single text prompt against the runtime's selected provider
51
+ * and return the assembled text response. Returns the full assistant
52
+ * output as one string (the runtime streams internally; the bridge
53
+ * does not propagate streaming further).
54
+ *
55
+ * Implementations may throw on provider failure — the bridge catches
56
+ * and surfaces the message verbatim per QB#10.
57
+ */
58
+ complete(prompt: string, systemPrompt: string): Promise<string>;
59
+ }
60
+ /**
61
+ * Optional caller override for the ChatDev waterfall. When omitted the
62
+ * default 5-phase waterfall (Demand -> Design -> Implement -> Review ->
63
+ * Test) is used.
64
+ */
65
+ export interface ChatDevWaterfallSpec {
66
+ /** Phase override. If supplied, replaces the default 5-phase set. */
67
+ readonly phases?: readonly {
68
+ readonly id: string;
69
+ readonly description: string;
70
+ readonly initiatorId: string;
71
+ readonly responderId: string;
72
+ }[];
73
+ /** Optional global charter prepended to every phase. */
74
+ readonly globalCharter?: string;
75
+ }
76
+ export interface ChatDevWaterfallOptions {
77
+ /**
78
+ * When supplied the bridge drives every phase's `converse` callback
79
+ * through this runtime ref, calling `complete()` once per phase with
80
+ * a prompt that wraps the input artifact in the role pair's charter.
81
+ * When omitted the bridge uses the deterministic `fixtureConverse`
82
+ * stub — the result is clearly fake (QB#3) but the structure is
83
+ * exercised end-to-end.
84
+ */
85
+ readonly runtime?: RuntimeConverseRef;
86
+ /** Force the fixture converser even when a runtime ref is available. */
87
+ readonly forceFixture?: boolean;
88
+ }
89
+ export type ChatDevWaterfallResult = {
90
+ readonly ok: true;
91
+ readonly result: WaterfallResult;
92
+ readonly mode: "runtime" | "fixture";
93
+ } | {
94
+ readonly ok: false;
95
+ readonly reason: string;
96
+ };
97
+ /**
98
+ * Build a converse function that drives one phase through the runtime.
99
+ * On any provider error it surfaces the message verbatim (QB#10).
100
+ */
101
+ declare function buildRuntimeConverse(runtime: RuntimeConverseRef): ConverseFn;
102
+ /**
103
+ * Bridge: run a ChatDev waterfall.
104
+ *
105
+ * @param spec Optional phase override. When absent the default 5-phase
106
+ * waterfall (Demand -> Design -> Implement -> Review -> Test)
107
+ * is used. Phase role ids must reference DEFAULT_ROLES.
108
+ * @param query The seed artifact handed to the first phase.
109
+ * @param options Runtime ref + fixture override flag.
110
+ */
111
+ export declare function runChatDevWaterfall(spec: ChatDevWaterfallSpec | undefined, query: string, options?: ChatDevWaterfallOptions): Promise<ChatDevWaterfallResult>;
112
+ export interface DeerFlowResearchOptions {
113
+ /**
114
+ * Caller-supplied search provider. If omitted, the bridge first tries
115
+ * `options.runtime` (when available, runs the planner/researcher/reporter
116
+ * through LLM calls) — and if THAT is absent, falls back to a hardcoded
117
+ * "no provider" failure so the caller knows the call did nothing real.
118
+ *
119
+ * QB#3: this is an honest-stub guard. We never invent search results.
120
+ */
121
+ readonly searchProvider?: SearchProvider;
122
+ /**
123
+ * Runtime ref for the planner/reporter stages. When present and no
124
+ * `searchProvider` is supplied, the bridge still surfaces ok:false
125
+ * because there's no way to gather evidence — research without retrieval
126
+ * is hallucination.
127
+ */
128
+ readonly runtime?: RuntimeConverseRef;
129
+ /** Force fixture pipeline (deterministic placeholders). */
130
+ readonly forceFixture?: boolean;
131
+ /** Max sub-questions to plan. Default 3. */
132
+ readonly maxSubQuestions?: number;
133
+ }
134
+ export type DeerFlowResearchResult = {
135
+ readonly ok: true;
136
+ readonly outcome: ResearchOutcome;
137
+ readonly mode: "runtime" | "fixture";
138
+ } | {
139
+ readonly ok: false;
140
+ readonly reason: string;
141
+ };
142
+ /**
143
+ * Build a planner that asks the runtime to decompose the question into
144
+ * sub-questions and parses a JSON array out of the response. If parsing
145
+ * fails we fall back to one heuristic sub-question (the original
146
+ * question) — that's honest: we tried and got a malformed response, so
147
+ * we still do one researcher pass.
148
+ */
149
+ declare function buildRuntimePlanner(runtime: RuntimeConverseRef, maxSubQuestions: number): Planner;
150
+ declare function tryParseSubQuestions(raw: string, max: number): readonly SubQuestion[];
151
+ /**
152
+ * Build a researcher that gathers evidence via the SearchProvider and
153
+ * (optionally) summarises via the runtime. If the runtime is absent
154
+ * the summary is empty — honest: we didn't have an LLM to write one.
155
+ */
156
+ declare function buildResearcher(searchProvider: SearchProvider, runtime: RuntimeConverseRef | undefined): Researcher;
157
+ /**
158
+ * Build a reporter that synthesises findings into a final report. With
159
+ * no runtime ref the synthesis is a deterministic concatenation of the
160
+ * findings' summaries — honest stub.
161
+ */
162
+ declare function buildReporter(runtime: RuntimeConverseRef | undefined): Reporter;
163
+ /**
164
+ * Bridge: run the deer-flow research pipeline.
165
+ *
166
+ * Requires (at minimum) a `searchProvider` for evidence gathering. With
167
+ * just the search provider the bridge still produces a complete report:
168
+ * the planner returns one sub-question (the user query), the researcher
169
+ * returns the raw hits as evidence, and the reporter concatenates the
170
+ * raw evidence. With a `runtime` ref the planner+reporter become
171
+ * LLM-driven and the researcher gains an evidence-summarisation step.
172
+ *
173
+ * When neither is supplied AND `forceFixture` is false, returns ok:false
174
+ * with reason "no search provider supplied". This is QB#3 — research
175
+ * without retrieval is hallucination.
176
+ */
177
+ export declare function runDeerFlowResearch(query: string, options?: DeerFlowResearchOptions): Promise<DeerFlowResearchResult>;
178
+ export interface MemGraphIngestOptions {
179
+ /**
180
+ * When true, the in-memory graph store is hydrated from + flushed back
181
+ * to `${WOTANN_HOME}/mem-graph.json`. When false (default) every call
182
+ * gets a fresh in-memory store with no persistence — useful for tests
183
+ * and for one-shot ingest.
184
+ */
185
+ readonly persist?: boolean;
186
+ /** Optional turn id for provenance stamping on every triple. */
187
+ readonly turnId?: string;
188
+ /** Optional LLM-backed triple extractor. */
189
+ readonly llm?: TripleExtractorLLM;
190
+ /** When persisting, override the on-disk path. Defaults to WOTANN_HOME. */
191
+ readonly persistencePath?: string;
192
+ }
193
+ export type MemGraphIngestResult = {
194
+ readonly ok: true;
195
+ readonly triples: readonly ExtractedTriple[];
196
+ readonly entitiesAdded: number;
197
+ readonly edgesAdded: number;
198
+ /** Optional 2-hop neighborhood walk for every subject in the ingested triples. */
199
+ readonly neighborhoods: readonly {
200
+ readonly entityId: string;
201
+ readonly edges: readonly GraphEdge[];
202
+ }[];
203
+ readonly persisted: boolean;
204
+ } | {
205
+ readonly ok: false;
206
+ readonly reason: string;
207
+ };
208
+ interface PersistentGraphSnapshot {
209
+ readonly entities: readonly GraphEntity[];
210
+ readonly edges: readonly GraphEdge[];
211
+ }
212
+ declare function loadGraphSnapshot(path: string): Promise<PersistentGraphSnapshot | null>;
213
+ declare function snapshotStore(store: GraphStore): PersistentGraphSnapshot;
214
+ /**
215
+ * Bridge: ingest text into a mem0-style graph memory.
216
+ *
217
+ * Uses `createInMemoryGraphStore` by default (no persistence). When
218
+ * `persist:true` the store is rehydrated from + flushed back to
219
+ * `${WOTANN_HOME}/mem-graph.json`. Returns the extracted triples plus a
220
+ * 2-hop neighborhood walk for every subject as a stable read view.
221
+ */
222
+ export declare function ingestTextToMemGraph(text: string, options?: MemGraphIngestOptions): Promise<MemGraphIngestResult>;
223
+ /**
224
+ * Minimal DOM snapshot the bridge accepts. We don't depend on any DOM
225
+ * library — the caller submits a serialised tree. We build the DomAdapter
226
+ * around this tree in-memory so the port primitive sees a real adapter.
227
+ */
228
+ export interface DomSnapshotNode {
229
+ readonly tag: string;
230
+ readonly classes?: readonly string[];
231
+ readonly text?: string;
232
+ readonly children?: readonly DomSnapshotNode[];
233
+ /** Optional caller-assigned label (must be unique per snapshot). */
234
+ readonly id?: string;
235
+ }
236
+ export interface DomSnapshot {
237
+ readonly root: DomSnapshotNode;
238
+ /** Optional ordered list of (label, selector) pairs to pre-seed the store. */
239
+ readonly seeds?: readonly {
240
+ readonly label: string;
241
+ readonly selector: string;
242
+ }[];
243
+ }
244
+ export interface ScraplingLocateOptions {
245
+ /** Min similarity score for fallback walk. Forwarded to scrapling. */
246
+ readonly minScore?: number;
247
+ }
248
+ export type ScraplingLocateResult = {
249
+ readonly ok: true;
250
+ readonly label: string;
251
+ readonly node: {
252
+ readonly tag: string;
253
+ readonly classes: readonly string[];
254
+ readonly textPreview: string;
255
+ };
256
+ readonly score: number;
257
+ readonly viaOriginalSelector: boolean;
258
+ } | {
259
+ readonly ok: false;
260
+ readonly reason: string;
261
+ };
262
+ /**
263
+ * Internal node we hand to the DomAdapter. Built from the snapshot.
264
+ */
265
+ interface BridgeNode {
266
+ readonly id: number;
267
+ readonly tag: string;
268
+ readonly classes: readonly string[];
269
+ readonly text: string;
270
+ readonly parent: BridgeNode | null;
271
+ readonly siblingIndex: number;
272
+ children: BridgeNode[];
273
+ }
274
+ declare function buildBridgeTree(snapshot: DomSnapshot): {
275
+ readonly root: BridgeNode;
276
+ readonly all: readonly BridgeNode[];
277
+ };
278
+ /**
279
+ * Tiny CSS-shaped selector: supports `tag`, `.class`, `tag.class`, and
280
+ * descendant combinators ` ` (space). No pseudo-classes, no attribute
281
+ * selectors. Sufficient for the bridge's locate-by-fingerprint use case;
282
+ * stronger selectors are a future port-side change.
283
+ */
284
+ declare function querySelectorAll(nodes: readonly BridgeNode[], selector: string): readonly BridgeNode[];
285
+ declare function buildAdapter(root: BridgeNode, allNodes: readonly BridgeNode[]): DomAdapter<BridgeNode>;
286
+ /**
287
+ * Bridge: adaptively locate a node by label within a DOM snapshot.
288
+ *
289
+ * The caller submits:
290
+ * - a DomSnapshot (a JSON tree of nodes)
291
+ * - a query label
292
+ * - either:
293
+ * * a `selector` string, in which case the bridge runs adaptiveLocate
294
+ * (which saves a fingerprint AND returns the located node), OR
295
+ * * just a label, in which case the bridge runs relocate against
296
+ * a previously-saved fingerprint. Since the store is per-call,
297
+ * the snapshot must include `seeds` to pre-populate the store.
298
+ *
299
+ * Returns the located node's tag, classes, and a text preview, along
300
+ * with the similarity score and whether the original selector was used.
301
+ *
302
+ * Per-call state: the FingerprintStore is created fresh inside this
303
+ * function (QB#7). For session-scoped fingerprints, a follow-up RPC
304
+ * surface can pass a long-lived store ref — that's deferred to the
305
+ * scrapling-adaptive port itself, not this bridge.
306
+ */
307
+ export declare function adaptiveLocateOnDom(domSnapshot: DomSnapshot, query: {
308
+ readonly label: string;
309
+ readonly selector?: string;
310
+ }, options?: ScraplingLocateOptions): Promise<ScraplingLocateResult>;
311
+ export declare const _testOnly: {
312
+ readonly tryParseSubQuestions: typeof tryParseSubQuestions;
313
+ readonly buildRuntimeConverse: typeof buildRuntimeConverse;
314
+ readonly buildRuntimePlanner: typeof buildRuntimePlanner;
315
+ readonly buildResearcher: typeof buildResearcher;
316
+ readonly buildReporter: typeof buildReporter;
317
+ readonly buildBridgeTree: typeof buildBridgeTree;
318
+ readonly buildAdapter: typeof buildAdapter;
319
+ readonly querySelectorAll: typeof querySelectorAll;
320
+ readonly loadGraphSnapshot: typeof loadGraphSnapshot;
321
+ readonly snapshotStore: typeof snapshotStore;
322
+ };
323
+ export type { ConverseFn, Phase, PhaseOutcome, Role, WaterfallResult };
324
+ export type { Findings, ResearchOutcome, SubQuestion };
325
+ //# sourceMappingURL=ports-bridge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ports-bridge.d.ts","sourceRoot":"","sources":["../../src/orchestration/ports-bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAKH,OAAO,EAKL,KAAK,UAAU,EACf,KAAK,KAAK,EACV,KAAK,YAAY,EACjB,KAAK,IAAI,EAET,KAAK,eAAe,EACrB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAIL,KAAK,QAAQ,EACb,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,KAAK,UAAU,EACf,KAAK,eAAe,EAGpB,KAAK,WAAW,EACjB,MAAM,gCAAgC,CAAC;AAExC,OAAO,EAIL,KAAK,eAAe,EACpB,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,kBAAkB,EACxB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAGL,KAAK,UAAU,EAGhB,MAAM,gCAAgC,CAAC;AAMxC,OAAO,KAAK,EACV,cAAc,EAEf,MAAM,4DAA4D,CAAC;AAWpE,MAAM,WAAW,kBAAkB;IACjC;;;;;;;;OAQG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACjE;AAID;;;;GAIG;AAC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