@duct-sdk/sdk 0.5.13 → 0.7.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 (166) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/README.md +418 -264
  3. package/TOKEN_SPEC.md +243 -243
  4. package/dist/cli/action-confusion-format.d.ts +17 -0
  5. package/dist/cli/action-confusion-format.js +24 -0
  6. package/dist/cli/add.d.ts +7 -0
  7. package/dist/cli/add.js +152 -0
  8. package/dist/cli/agent-prompt.d.ts +3 -0
  9. package/dist/cli/agent-prompt.js +39 -0
  10. package/dist/cli/api-sources.d.ts +26 -0
  11. package/dist/cli/api-sources.js +222 -0
  12. package/dist/cli/cloud.d.ts +162 -0
  13. package/dist/cli/cloud.js +306 -0
  14. package/dist/cli/config-loader.d.ts +14 -0
  15. package/dist/cli/config-loader.js +56 -7
  16. package/dist/cli/device-login.d.ts +17 -0
  17. package/dist/cli/device-login.js +75 -0
  18. package/dist/cli/drift.js +6 -6
  19. package/dist/cli/generators/any-stack.d.ts +3 -0
  20. package/dist/cli/generators/any-stack.js +97 -0
  21. package/dist/cli/generators/config.js +3 -2
  22. package/dist/cli/generators/receiver.js +7 -7
  23. package/dist/cli/generators/shell.js +12 -12
  24. package/dist/cli/generators/token-route.js +245 -245
  25. package/dist/cli/generators/wiring-snippets.d.ts +0 -14
  26. package/dist/cli/generators/wiring-snippets.js +188 -305
  27. package/dist/cli/index.js +396 -611
  28. package/dist/cli/mcp-core.d.ts +42 -0
  29. package/dist/cli/mcp-core.js +161 -0
  30. package/dist/cli/mcp-setup.d.ts +4 -0
  31. package/dist/cli/mcp-setup.js +352 -0
  32. package/dist/cli/mcp.d.ts +2 -0
  33. package/dist/cli/mcp.js +457 -0
  34. package/dist/cli/migrate-intershell.js +5 -5
  35. package/dist/cli/policy-defaults.d.ts +37 -0
  36. package/dist/cli/policy-defaults.js +127 -0
  37. package/dist/cli/policy-replay-format.d.ts +9 -0
  38. package/dist/cli/policy-replay-format.js +46 -0
  39. package/dist/cli/processors/integration-audit.js +2 -2
  40. package/dist/cli/processors/openapi-parser.d.ts +5 -0
  41. package/dist/cli/processors/openapi-parser.js +8 -3
  42. package/dist/cli/project-loader.d.ts +58 -0
  43. package/dist/cli/project-loader.js +198 -0
  44. package/dist/cli/project-writer.d.ts +23 -0
  45. package/dist/cli/project-writer.js +171 -0
  46. package/dist/cli/push.d.ts +43 -0
  47. package/dist/cli/push.js +308 -0
  48. package/dist/cli/safety-checks.d.ts +9 -0
  49. package/dist/cli/safety-checks.js +29 -0
  50. package/dist/cli/setup.d.ts +20 -0
  51. package/dist/cli/setup.js +349 -0
  52. package/dist/cli/shell-name.d.ts +8 -0
  53. package/dist/cli/shell-name.js +29 -0
  54. package/dist/cli/shells.d.ts +22 -0
  55. package/dist/cli/shells.js +122 -0
  56. package/dist/cli/split.d.ts +7 -0
  57. package/dist/cli/split.js +71 -0
  58. package/dist/cli/sync.d.ts +25 -0
  59. package/dist/cli/sync.js +120 -0
  60. package/dist/cli/test-runner.d.ts +21 -0
  61. package/dist/cli/test-runner.js +281 -0
  62. package/dist/core/compile.d.ts +43 -0
  63. package/dist/core/compile.js +512 -0
  64. package/dist/core/config.d.ts +538 -19
  65. package/dist/core/config.js +22 -14
  66. package/dist/core/login-handoff.d.ts +1 -1
  67. package/dist/core/login-handoff.js +1 -1
  68. package/dist/core/project.d.ts +1864 -0
  69. package/dist/core/project.js +291 -0
  70. package/dist/core/readiness-checks.js +2 -2
  71. package/dist/core/types.d.ts +10 -1
  72. package/dist/index.d.ts +2 -0
  73. package/dist/index.js +1 -0
  74. package/dist/project.d.ts +4 -0
  75. package/dist/project.js +8 -0
  76. package/dist/server.d.ts +2 -0
  77. package/dist/server.js +1 -0
  78. package/package.json +94 -95
  79. package/dist/adapters/react/page-context-guard.test.d.ts +0 -1
  80. package/dist/adapters/react/page-context-guard.test.js +0 -15
  81. package/dist/cli/agents/api-agent.d.ts +0 -22
  82. package/dist/cli/agents/api-agent.js +0 -761
  83. package/dist/cli/agents/auth-agent.d.ts +0 -7
  84. package/dist/cli/agents/auth-agent.js +0 -212
  85. package/dist/cli/agents/deeplink-agent.d.ts +0 -6
  86. package/dist/cli/agents/deeplink-agent.js +0 -285
  87. package/dist/cli/agents/llm.d.ts +0 -33
  88. package/dist/cli/agents/llm.js +0 -309
  89. package/dist/cli/agents/pipeline.d.ts +0 -72
  90. package/dist/cli/agents/pipeline.js +0 -421
  91. package/dist/cli/agents/reviewer-agent.d.ts +0 -13
  92. package/dist/cli/agents/reviewer-agent.js +0 -450
  93. package/dist/cli/agents/route-agent.d.ts +0 -17
  94. package/dist/cli/agents/route-agent.js +0 -383
  95. package/dist/cli/config-loader.test.d.ts +0 -1
  96. package/dist/cli/config-loader.test.js +0 -63
  97. package/dist/cli/detectors/topology.d.ts +0 -46
  98. package/dist/cli/detectors/topology.js +0 -417
  99. package/dist/cli/generators/config.test.d.ts +0 -1
  100. package/dist/cli/generators/config.test.js +0 -222
  101. package/dist/cli/generators/shell.test.d.ts +0 -1
  102. package/dist/cli/generators/shell.test.js +0 -73
  103. package/dist/cli/generators/token-route.test.d.ts +0 -1
  104. package/dist/cli/generators/token-route.test.js +0 -53
  105. package/dist/cli/generators/wiring-snippets.test.d.ts +0 -1
  106. package/dist/cli/generators/wiring-snippets.test.js +0 -80
  107. package/dist/cli/init.d.ts +0 -32
  108. package/dist/cli/init.js +0 -1336
  109. package/dist/cli/manifest-diff.test.d.ts +0 -1
  110. package/dist/cli/manifest-diff.test.js +0 -144
  111. package/dist/cli/processors/curl-parser.test.d.ts +0 -1
  112. package/dist/cli/processors/curl-parser.test.js +0 -24
  113. package/dist/cli/processors/integration-audit.test.d.ts +0 -1
  114. package/dist/cli/processors/integration-audit.test.js +0 -154
  115. package/dist/cli/processors/postprocess.d.ts +0 -22
  116. package/dist/cli/processors/postprocess.js +0 -107
  117. package/dist/cli/processors/prisma-parser.d.ts +0 -35
  118. package/dist/cli/processors/prisma-parser.js +0 -117
  119. package/dist/cli/processors/verify-discovery.d.ts +0 -33
  120. package/dist/cli/processors/verify-discovery.js +0 -193
  121. package/dist/cli/processors/verify-discovery.test.d.ts +0 -1
  122. package/dist/cli/processors/verify-discovery.test.js +0 -153
  123. package/dist/cli/processors/zod-extractor.d.ts +0 -27
  124. package/dist/cli/processors/zod-extractor.js +0 -153
  125. package/dist/cli/prompts/review.d.ts +0 -61
  126. package/dist/cli/prompts/review.js +0 -410
  127. package/dist/cli/selectors/express.d.ts +0 -12
  128. package/dist/cli/selectors/express.js +0 -117
  129. package/dist/cli/selectors/fastapi.d.ts +0 -12
  130. package/dist/cli/selectors/fastapi.js +0 -122
  131. package/dist/cli/selectors/generic.d.ts +0 -10
  132. package/dist/cli/selectors/generic.js +0 -74
  133. package/dist/cli/selectors/index.d.ts +0 -37
  134. package/dist/cli/selectors/index.js +0 -315
  135. package/dist/cli/selectors/next.d.ts +0 -12
  136. package/dist/cli/selectors/next.js +0 -130
  137. package/dist/core/config-policy.test.d.ts +0 -1
  138. package/dist/core/config-policy.test.js +0 -101
  139. package/dist/core/config-roundtrip.test.d.ts +0 -1
  140. package/dist/core/config-roundtrip.test.js +0 -180
  141. package/dist/core/endpoint-guard.test.d.ts +0 -1
  142. package/dist/core/endpoint-guard.test.js +0 -57
  143. package/dist/core/env-diagnostics.test.d.ts +0 -1
  144. package/dist/core/env-diagnostics.test.js +0 -31
  145. package/dist/core/evidence-bundle.conformance.test.d.ts +0 -1
  146. package/dist/core/evidence-bundle.conformance.test.js +0 -110
  147. package/dist/core/evidence-bundle.test.d.ts +0 -1
  148. package/dist/core/evidence-bundle.test.js +0 -58
  149. package/dist/core/invariants.test.d.ts +0 -1
  150. package/dist/core/invariants.test.js +0 -217
  151. package/dist/core/login-handoff.test.d.ts +0 -1
  152. package/dist/core/login-handoff.test.js +0 -31
  153. package/dist/core/profile.test.d.ts +0 -1
  154. package/dist/core/profile.test.js +0 -95
  155. package/dist/core/readiness-checks.test.d.ts +0 -1
  156. package/dist/core/readiness-checks.test.js +0 -106
  157. package/dist/core/receipt.test.d.ts +0 -1
  158. package/dist/core/receipt.test.js +0 -75
  159. package/dist/core/sdk-entrypoint.test.d.ts +0 -1
  160. package/dist/core/sdk-entrypoint.test.js +0 -8
  161. package/dist/core/side-effects-review.test.d.ts +0 -1
  162. package/dist/core/side-effects-review.test.js +0 -28
  163. package/dist/core/token.conformance.test.d.ts +0 -1
  164. package/dist/core/token.conformance.test.js +0 -43
  165. package/dist/core/token.test.d.ts +0 -1
  166. package/dist/core/token.test.js +0 -66
@@ -1,421 +0,0 @@
1
- // ============================================================
2
- // @duct/sdk — Agent Pipeline Orchestrator
3
- // Runs the 5-agent pipeline to analyze a codebase
4
- // ============================================================
5
- import { EventEmitter } from "events";
6
- import { runRouteAgent } from "./route-agent.js";
7
- import { runApiAgent } from "./api-agent.js";
8
- import { runAuthAgent } from "./auth-agent.js";
9
- import { runDeeplinkAgent } from "./deeplink-agent.js";
10
- import { runReviewerAgent } from "./reviewer-agent.js";
11
- import { applyDeterministicRules } from "../processors/postprocess.js";
12
- import { verifyDiscoveryAgainstFilesystem } from "../processors/verify-discovery.js";
13
- import { parseOpenApiSpec } from "../processors/openapi-parser.js";
14
- import { parseCurlCollection } from "../processors/curl-parser.js";
15
- import { enrichAuthLoginHandoff } from "../../core/login-handoff.js";
16
- // ----------------------------------------------------------------
17
- // Default emitter (uses Node EventEmitter)
18
- // ----------------------------------------------------------------
19
- export class DuctPipelineEmitter extends EventEmitter {
20
- emitEvent(event) {
21
- super.emit("event", event);
22
- }
23
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
24
- on(eventName, listener) {
25
- return super.on(eventName, listener);
26
- }
27
- }
28
- // ----------------------------------------------------------------
29
- // Agent runner with timeout
30
- // ----------------------------------------------------------------
31
- async function withTimeout(fn, timeoutMs, agentName) {
32
- return new Promise((resolve, reject) => {
33
- const timer = setTimeout(() => {
34
- reject(new Error(`${agentName} timed out after ${timeoutMs / 1000}s. ` +
35
- "Your project may be very large. Try running with --no-agents to use the blank template."));
36
- }, timeoutMs);
37
- fn()
38
- .then((result) => {
39
- clearTimeout(timer);
40
- resolve(result);
41
- })
42
- .catch((err) => {
43
- clearTimeout(timer);
44
- reject(err);
45
- });
46
- });
47
- }
48
- // ----------------------------------------------------------------
49
- // Default values for skipped agents
50
- // ----------------------------------------------------------------
51
- function defaultRoutes() {
52
- return [];
53
- }
54
- function defaultActions() {
55
- return [];
56
- }
57
- function defaultAuth() {
58
- return {
59
- strategy: "unknown",
60
- sessionFields: ["id", "email"],
61
- guestAllowed: true,
62
- tokenExpirySeconds: 300,
63
- };
64
- }
65
- async function runAgentWithEmptyRetry(agentName, run, isEmpty, timeoutMs, emitter) {
66
- let result = await withTimeout(() => run(false), timeoutMs, agentName);
67
- if (!isEmpty(result)) {
68
- return result;
69
- }
70
- emitter?.emitEvent({
71
- type: "agent:start",
72
- agent: agentName,
73
- message: `${agentName} returned no results — retrying once…`,
74
- progress: 15,
75
- });
76
- result = await withTimeout(() => run(true), timeoutMs, agentName);
77
- return result;
78
- }
79
- function defaultDeeplinks() {
80
- return [];
81
- }
82
- function defaultReview() {
83
- return {
84
- passed: true,
85
- confidenceScore: 0.5,
86
- issues: [
87
- {
88
- code: "REVIEW_SKIPPED",
89
- severity: "info",
90
- message: "Review agent was skipped",
91
- suggestion: "Run duct init without --no-agents for full analysis",
92
- },
93
- ],
94
- suggestions: [],
95
- summary: "Review skipped.",
96
- };
97
- }
98
- // ----------------------------------------------------------------
99
- // runAgentPipeline
100
- // ----------------------------------------------------------------
101
- /**
102
- * Run the full 5-agent pipeline to analyze a project and produce a DuctConfig.
103
- *
104
- * Pipeline stages:
105
- * 1. Routes + API + Auth agents run in parallel
106
- * 2. Deeplink agent runs with routes + actions results
107
- * 3. Reviewer agent runs with all results
108
- *
109
- * @param sandboxFs - Sandboxed filesystem for the project
110
- * @param opts - Pipeline options
111
- * @returns PipelineResult with all agent outputs
112
- */
113
- export async function runAgentPipeline(sandboxFs, opts = {}) {
114
- const { skipAgents: skipAgentsInput = [], emitter, agentTimeout = 120_000, readList, apiSpecContent, apiSpecPath, curlCollectionContent, curlCollectionPath, postProcess = {}, } = opts;
115
- const skipAgents = skipAgentsInput;
116
- const startTime = Date.now();
117
- emitter?.emitEvent({ type: "start", message: "Starting Duct agent pipeline...", progress: 0 });
118
- // ---- Stage 1: Routes + Actions + Auth ----
119
- let routes;
120
- let actions;
121
- let auth;
122
- let shouldVerifyAgainstFilesystem = false;
123
- if (curlCollectionContent) {
124
- const [curlResult, authResult] = await Promise.all([
125
- (async () => {
126
- emitter?.emitEvent({
127
- type: "agent:start",
128
- agent: "ApiAgent",
129
- message: `Parsing cURL collection (${curlCollectionPath ?? "curl"})…`,
130
- progress: 5,
131
- });
132
- try {
133
- const parsed = await parseCurlCollection(curlCollectionContent, curlCollectionPath ?? "curl-collection.sh");
134
- emitter?.emitEvent({
135
- type: "agent:complete",
136
- agent: "ApiAgent",
137
- message: `Parsed ${parsed.actions.length} actions from ${parsed.requestCount} requests`,
138
- result: parsed.actions,
139
- progress: 30,
140
- });
141
- return { routes: parsed.routes, actions: parsed.actions };
142
- }
143
- catch (err) {
144
- const error = err instanceof Error ? err : new Error(String(err));
145
- emitter?.emitEvent({ type: "agent:error", agent: "ApiAgent", error, progress: 30 });
146
- return { routes: defaultRoutes(), actions: defaultActions() };
147
- }
148
- })(),
149
- (async () => {
150
- if (skipAgentsInput.includes("auth"))
151
- return defaultAuth();
152
- emitter?.emitEvent({
153
- type: "agent:start",
154
- agent: "AuthAgent",
155
- message: "Analyzing auth configuration…",
156
- progress: 5,
157
- });
158
- try {
159
- const result = await withTimeout(() => runAuthAgent(sandboxFs, readList?.authFiles), agentTimeout, "AuthAgent");
160
- emitter?.emitEvent({
161
- type: "agent:complete",
162
- agent: "AuthAgent",
163
- message: `Detected auth: ${result.strategy}`,
164
- result,
165
- progress: 30,
166
- });
167
- return result;
168
- }
169
- catch (err) {
170
- const error = err instanceof Error ? err : new Error(String(err));
171
- emitter?.emitEvent({ type: "agent:error", agent: "AuthAgent", error, progress: 30 });
172
- return defaultAuth();
173
- }
174
- })(),
175
- ]);
176
- routes = curlResult.routes;
177
- actions = curlResult.actions;
178
- auth = authResult;
179
- }
180
- else if (apiSpecContent) {
181
- // ── Spec mode: parse actions from OpenAPI; still discover UI routes via RouteAgent ──
182
- const [specResult, authResult, routeResult] = await Promise.all([
183
- (async () => {
184
- emitter?.emitEvent({
185
- type: "agent:start",
186
- agent: "ApiAgent",
187
- message: `Parsing OpenAPI spec (${apiSpecPath ?? "openapi"})…`,
188
- progress: 5,
189
- });
190
- try {
191
- const parsed = await parseOpenApiSpec(apiSpecContent, apiSpecPath ?? "openapi.json");
192
- emitter?.emitEvent({
193
- type: "agent:complete",
194
- agent: "ApiAgent",
195
- message: `Parsed ${parsed.actions.length} actions from OpenAPI ${parsed.specVersion} spec`,
196
- result: parsed.actions,
197
- progress: 30,
198
- });
199
- return { routes: parsed.routes, actions: parsed.actions };
200
- }
201
- catch (err) {
202
- const error = err instanceof Error ? err : new Error(String(err));
203
- emitter?.emitEvent({ type: "agent:error", agent: "ApiAgent", error, progress: 30 });
204
- return { routes: defaultRoutes(), actions: defaultActions() };
205
- }
206
- })(),
207
- (async () => {
208
- if (skipAgentsInput.includes("auth"))
209
- return defaultAuth();
210
- emitter?.emitEvent({
211
- type: "agent:start",
212
- agent: "AuthAgent",
213
- message: "Analyzing auth configuration…",
214
- progress: 5,
215
- });
216
- try {
217
- const result = await withTimeout(() => runAuthAgent(sandboxFs, readList?.authFiles), agentTimeout, "AuthAgent");
218
- emitter?.emitEvent({
219
- type: "agent:complete",
220
- agent: "AuthAgent",
221
- message: `Detected auth: ${result.strategy}`,
222
- result,
223
- progress: 30,
224
- });
225
- return result;
226
- }
227
- catch (err) {
228
- const error = err instanceof Error ? err : new Error(String(err));
229
- emitter?.emitEvent({ type: "agent:error", agent: "AuthAgent", error, progress: 30 });
230
- return defaultAuth();
231
- }
232
- })(),
233
- (async () => {
234
- if (skipAgents.includes("routes"))
235
- return defaultRoutes();
236
- emitter?.emitEvent({
237
- type: "agent:start",
238
- agent: "RouteAgent",
239
- message: "Discovering UI routes (OpenAPI spec does not include pages)…",
240
- progress: 8,
241
- });
242
- try {
243
- const result = await runAgentWithEmptyRetry("RouteAgent", (retry) => runRouteAgent(sandboxFs, readList?.routeFiles, { retry }), (value) => value.length === 0, agentTimeout, emitter);
244
- emitter?.emitEvent({
245
- type: "agent:complete",
246
- agent: "RouteAgent",
247
- message: `Found ${result.length} routes`,
248
- result,
249
- progress: 30,
250
- });
251
- return result;
252
- }
253
- catch (err) {
254
- const error = err instanceof Error ? err : new Error(String(err));
255
- emitter?.emitEvent({ type: "agent:error", agent: "RouteAgent", error, progress: 30 });
256
- return defaultRoutes();
257
- }
258
- })(),
259
- ]);
260
- routes = routeResult.length > 0 ? routeResult : specResult.routes;
261
- actions = specResult.actions;
262
- auth = authResult;
263
- shouldVerifyAgainstFilesystem = true;
264
- }
265
- else {
266
- // ── Normal mode: full 3-agent parallel stage ────────────────────────────────
267
- shouldVerifyAgainstFilesystem = true;
268
- const stage1Agents = [
269
- // Routes
270
- (async () => {
271
- if (skipAgents.includes("routes"))
272
- return defaultRoutes();
273
- emitter?.emitEvent({ type: "agent:start", agent: "RouteAgent", message: "Analyzing routes...", progress: 5 });
274
- try {
275
- const result = await runAgentWithEmptyRetry("RouteAgent", (retry) => runRouteAgent(sandboxFs, readList?.routeFiles, { retry }), (value) => value.length === 0, agentTimeout, emitter);
276
- emitter?.emitEvent({
277
- type: "agent:complete",
278
- agent: "RouteAgent",
279
- message: `Found ${result.length} routes`,
280
- result,
281
- progress: 30,
282
- });
283
- return result;
284
- }
285
- catch (err) {
286
- const error = err instanceof Error ? err : new Error(String(err));
287
- emitter?.emitEvent({ type: "agent:error", agent: "RouteAgent", error, progress: 30 });
288
- return defaultRoutes();
289
- }
290
- })(),
291
- // API/Actions
292
- (async () => {
293
- if (skipAgents.includes("actions"))
294
- return defaultActions();
295
- emitter?.emitEvent({ type: "agent:start", agent: "ApiAgent", message: "Analyzing API endpoints...", progress: 5 });
296
- try {
297
- const result = await runAgentWithEmptyRetry("ApiAgent", (retry) => runApiAgent(sandboxFs, readList?.apiFiles, undefined, undefined, { retry }), (value) => value.length === 0, agentTimeout, emitter);
298
- emitter?.emitEvent({
299
- type: "agent:complete",
300
- agent: "ApiAgent",
301
- message: `Found ${result.length} actions`,
302
- result,
303
- progress: 30,
304
- });
305
- return result;
306
- }
307
- catch (err) {
308
- const error = err instanceof Error ? err : new Error(String(err));
309
- emitter?.emitEvent({ type: "agent:error", agent: "ApiAgent", error, progress: 30 });
310
- return defaultActions();
311
- }
312
- })(),
313
- // Auth
314
- (async () => {
315
- if (skipAgents.includes("auth"))
316
- return defaultAuth();
317
- emitter?.emitEvent({ type: "agent:start", agent: "AuthAgent", message: "Analyzing auth configuration...", progress: 5 });
318
- try {
319
- const result = await withTimeout(() => runAuthAgent(sandboxFs, readList?.authFiles), agentTimeout, "AuthAgent");
320
- emitter?.emitEvent({
321
- type: "agent:complete",
322
- agent: "AuthAgent",
323
- message: `Detected auth: ${result.strategy}`,
324
- result,
325
- progress: 30,
326
- });
327
- return result;
328
- }
329
- catch (err) {
330
- const error = err instanceof Error ? err : new Error(String(err));
331
- emitter?.emitEvent({ type: "agent:error", agent: "AuthAgent", error, progress: 30 });
332
- return defaultAuth();
333
- }
334
- })(),
335
- ];
336
- [routes, actions, auth] = await Promise.all(stage1Agents);
337
- }
338
- if (shouldVerifyAgainstFilesystem) {
339
- const verification = await verifyDiscoveryAgainstFilesystem(sandboxFs, routes, actions);
340
- routes = verification.routes;
341
- actions = verification.actions;
342
- if (verification.warnings.length > 0) {
343
- emitter?.emitEvent({
344
- type: "agent:complete",
345
- message: `Filesystem verification: ${verification.downgradedRoutes + verification.downgradedActions} downgraded, ` +
346
- `${verification.droppedRoutes + verification.droppedActions} dropped, ` +
347
- `${verification.warnings.length} warning(s)`,
348
- progress: 45,
349
- });
350
- }
351
- }
352
- // Apply deterministic rules: enforce sideEffects from HTTP method,
353
- // derive sensitivityLevel from path/name keywords, and (in yesMode) auto-enable
354
- // agentAccessible on safe GET/HEAD with confidence ≥ 0.85.
355
- actions = applyDeterministicRules(actions, postProcess);
356
- emitter?.emitEvent({ type: "agent:complete", message: "Stage 1 complete (routes, actions, auth)", progress: 60 });
357
- // ---- Stage 2: Deeplink agent ----
358
- let deeplinks;
359
- if (skipAgents.includes("deeplinks")) {
360
- deeplinks = defaultDeeplinks();
361
- }
362
- else {
363
- emitter?.emitEvent({ type: "agent:start", agent: "DeeplinkAgent", message: "Proposing deeplinks...", progress: 65 });
364
- try {
365
- deeplinks = await withTimeout(() => runDeeplinkAgent(routes, actions), agentTimeout, "DeeplinkAgent");
366
- emitter?.emitEvent({
367
- type: "agent:complete",
368
- agent: "DeeplinkAgent",
369
- message: `Proposed ${deeplinks.length} deeplinks`,
370
- result: deeplinks,
371
- progress: 80,
372
- });
373
- }
374
- catch (err) {
375
- const error = err instanceof Error ? err : new Error(String(err));
376
- emitter?.emitEvent({ type: "agent:error", agent: "DeeplinkAgent", error, progress: 80 });
377
- deeplinks = defaultDeeplinks();
378
- }
379
- }
380
- // ---- Stage 3: Reviewer agent ----
381
- let review;
382
- if (skipAgents.includes("review")) {
383
- review = defaultReview();
384
- }
385
- else {
386
- emitter?.emitEvent({ type: "agent:start", agent: "ReviewerAgent", message: "Reviewing configuration...", progress: 85 });
387
- try {
388
- review = await withTimeout(() => runReviewerAgent({ routes, actions, auth, deeplinks }), agentTimeout, "ReviewerAgent");
389
- emitter?.emitEvent({
390
- type: "agent:complete",
391
- agent: "ReviewerAgent",
392
- message: review.summary,
393
- result: review,
394
- progress: 100,
395
- });
396
- }
397
- catch (err) {
398
- const error = err instanceof Error ? err : new Error(String(err));
399
- emitter?.emitEvent({ type: "agent:error", agent: "ReviewerAgent", error, progress: 100 });
400
- review = defaultReview();
401
- }
402
- }
403
- const durationMs = Date.now() - startTime;
404
- auth = enrichAuthLoginHandoff(auth, routes, deeplinks);
405
- const pipelineResult = {
406
- routes,
407
- actions,
408
- auth,
409
- deeplinks,
410
- review,
411
- confidenceScore: review.confidenceScore,
412
- durationMs,
413
- };
414
- emitter?.emitEvent({
415
- type: "complete",
416
- message: `Pipeline complete in ${(durationMs / 1000).toFixed(1)}s`,
417
- result: pipelineResult,
418
- progress: 100,
419
- });
420
- return pipelineResult;
421
- }
@@ -1,13 +0,0 @@
1
- import type { RouteManifest, ActionManifest, AuthSchema, DeeplinkDefinition, ReviewResult, ReviewIssue } from "../../core/types.js";
2
- export interface ReviewAgentInput {
3
- routes: RouteManifest[];
4
- actions: ActionManifest[];
5
- auth: AuthSchema;
6
- deeplinks: DeeplinkDefinition[];
7
- }
8
- /** Agent-safety checks used by `duct push` (no LLM). */
9
- export declare function runAgentSafetyChecks(input: ReviewAgentInput): ReviewIssue[];
10
- /**
11
- * Run the Reviewer Agent to validate and score the pipeline output.
12
- */
13
- export declare function runReviewerAgent(input: ReviewAgentInput): Promise<ReviewResult>;