@duct-sdk/sdk 0.5.12 → 0.6.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.
- package/CHANGELOG.md +385 -336
- package/README.md +418 -264
- package/TOKEN_SPEC.md +243 -237
- package/dist/cli/add.d.ts +7 -0
- package/dist/cli/add.js +152 -0
- package/dist/cli/agent-prompt.d.ts +3 -0
- package/dist/cli/agent-prompt.js +39 -0
- package/dist/cli/api-sources.d.ts +26 -0
- package/dist/cli/api-sources.js +222 -0
- package/dist/cli/cloud.d.ts +133 -0
- package/dist/cli/cloud.js +298 -0
- package/dist/cli/config-loader.d.ts +14 -0
- package/dist/cli/config-loader.js +56 -7
- package/dist/cli/device-login.d.ts +17 -0
- package/dist/cli/device-login.js +75 -0
- package/dist/cli/drift.js +6 -6
- package/dist/cli/generators/any-stack.d.ts +3 -0
- package/dist/cli/generators/any-stack.js +97 -0
- package/dist/cli/generators/config.js +3 -2
- package/dist/cli/generators/receiver.js +7 -7
- package/dist/cli/generators/shell.js +12 -12
- package/dist/cli/generators/token-route.js +245 -245
- package/dist/cli/index.js +402 -611
- package/dist/cli/mcp-core.d.ts +42 -0
- package/dist/cli/mcp-core.js +161 -0
- package/dist/cli/mcp-setup.d.ts +4 -0
- package/dist/cli/mcp-setup.js +360 -0
- package/dist/cli/mcp.d.ts +2 -0
- package/dist/cli/mcp.js +457 -0
- package/dist/cli/migrate-intershell.js +5 -5
- package/dist/cli/policy-defaults.d.ts +37 -0
- package/dist/cli/policy-defaults.js +127 -0
- package/dist/cli/processors/integration-audit.js +2 -2
- package/dist/cli/processors/openapi-parser.d.ts +5 -0
- package/dist/cli/processors/openapi-parser.js +8 -3
- package/dist/cli/project-loader.d.ts +58 -0
- package/dist/cli/project-loader.js +198 -0
- package/dist/cli/project-writer.d.ts +23 -0
- package/dist/cli/project-writer.js +171 -0
- package/dist/cli/push.d.ts +43 -0
- package/dist/cli/push.js +276 -0
- package/dist/cli/safety-checks.d.ts +9 -0
- package/dist/cli/safety-checks.js +29 -0
- package/dist/cli/setup.d.ts +20 -0
- package/dist/cli/setup.js +349 -0
- package/dist/cli/shell-name.d.ts +8 -0
- package/dist/cli/shell-name.js +29 -0
- package/dist/cli/shells.d.ts +22 -0
- package/dist/cli/shells.js +122 -0
- package/dist/cli/split.d.ts +7 -0
- package/dist/cli/split.js +71 -0
- package/dist/cli/sync.d.ts +25 -0
- package/dist/cli/sync.js +120 -0
- package/dist/cli/test-runner.d.ts +21 -0
- package/dist/cli/test-runner.js +281 -0
- package/dist/core/compile.d.ts +43 -0
- package/dist/core/compile.js +510 -0
- package/dist/core/config.d.ts +533 -1
- package/dist/core/config.js +32 -12
- package/dist/core/hosted-upstream-check.d.ts +3 -0
- package/dist/core/hosted-upstream-check.js +35 -0
- package/dist/core/login-handoff.d.ts +1 -1
- package/dist/core/login-handoff.js +1 -1
- package/dist/core/project.d.ts +1798 -0
- package/dist/core/project.js +278 -0
- package/dist/core/readiness-checks.js +2 -2
- package/dist/core/types.d.ts +26 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.js +16 -0
- package/dist/project.d.ts +4 -0
- package/dist/project.js +8 -0
- package/dist/server.d.ts +2 -0
- package/dist/server.js +1 -0
- package/fixtures/token-conformance-vectors.json +26 -0
- package/package.json +94 -94
- package/dist/adapters/react/page-context-guard.test.d.ts +0 -1
- package/dist/adapters/react/page-context-guard.test.js +0 -15
- package/dist/cli/agents/api-agent.d.ts +0 -22
- package/dist/cli/agents/api-agent.js +0 -761
- package/dist/cli/agents/auth-agent.d.ts +0 -7
- package/dist/cli/agents/auth-agent.js +0 -212
- package/dist/cli/agents/deeplink-agent.d.ts +0 -6
- package/dist/cli/agents/deeplink-agent.js +0 -285
- package/dist/cli/agents/llm.d.ts +0 -33
- package/dist/cli/agents/llm.js +0 -309
- package/dist/cli/agents/pipeline.d.ts +0 -72
- package/dist/cli/agents/pipeline.js +0 -421
- package/dist/cli/agents/reviewer-agent.d.ts +0 -13
- package/dist/cli/agents/reviewer-agent.js +0 -450
- package/dist/cli/agents/route-agent.d.ts +0 -17
- package/dist/cli/agents/route-agent.js +0 -383
- package/dist/cli/config-loader.test.d.ts +0 -1
- package/dist/cli/config-loader.test.js +0 -63
- package/dist/cli/detectors/topology.d.ts +0 -46
- package/dist/cli/detectors/topology.js +0 -417
- package/dist/cli/generators/config.test.d.ts +0 -1
- package/dist/cli/generators/config.test.js +0 -222
- package/dist/cli/generators/shell.test.d.ts +0 -1
- package/dist/cli/generators/shell.test.js +0 -73
- package/dist/cli/generators/token-route.test.d.ts +0 -1
- package/dist/cli/generators/token-route.test.js +0 -53
- package/dist/cli/generators/wiring-snippets.test.d.ts +0 -1
- package/dist/cli/generators/wiring-snippets.test.js +0 -80
- package/dist/cli/init.d.ts +0 -32
- package/dist/cli/init.js +0 -1336
- package/dist/cli/manifest-diff.test.d.ts +0 -1
- package/dist/cli/manifest-diff.test.js +0 -144
- package/dist/cli/processors/curl-parser.test.d.ts +0 -1
- package/dist/cli/processors/curl-parser.test.js +0 -24
- package/dist/cli/processors/integration-audit.test.d.ts +0 -1
- package/dist/cli/processors/integration-audit.test.js +0 -154
- package/dist/cli/processors/postprocess.d.ts +0 -22
- package/dist/cli/processors/postprocess.js +0 -107
- package/dist/cli/processors/prisma-parser.d.ts +0 -35
- package/dist/cli/processors/prisma-parser.js +0 -117
- package/dist/cli/processors/verify-discovery.d.ts +0 -33
- package/dist/cli/processors/verify-discovery.js +0 -193
- package/dist/cli/processors/verify-discovery.test.d.ts +0 -1
- package/dist/cli/processors/verify-discovery.test.js +0 -153
- package/dist/cli/processors/zod-extractor.d.ts +0 -27
- package/dist/cli/processors/zod-extractor.js +0 -153
- package/dist/cli/prompts/review.d.ts +0 -61
- package/dist/cli/prompts/review.js +0 -410
- package/dist/cli/selectors/express.d.ts +0 -12
- package/dist/cli/selectors/express.js +0 -117
- package/dist/cli/selectors/fastapi.d.ts +0 -12
- package/dist/cli/selectors/fastapi.js +0 -122
- package/dist/cli/selectors/generic.d.ts +0 -10
- package/dist/cli/selectors/generic.js +0 -74
- package/dist/cli/selectors/index.d.ts +0 -37
- package/dist/cli/selectors/index.js +0 -315
- package/dist/cli/selectors/next.d.ts +0 -12
- package/dist/cli/selectors/next.js +0 -130
- package/dist/core/config-policy.test.d.ts +0 -1
- package/dist/core/config-policy.test.js +0 -101
- package/dist/core/config-roundtrip.test.d.ts +0 -1
- package/dist/core/config-roundtrip.test.js +0 -180
- package/dist/core/endpoint-guard.test.d.ts +0 -1
- package/dist/core/endpoint-guard.test.js +0 -57
- package/dist/core/env-diagnostics.test.d.ts +0 -1
- package/dist/core/env-diagnostics.test.js +0 -31
- package/dist/core/evidence-bundle.conformance.test.d.ts +0 -1
- package/dist/core/evidence-bundle.conformance.test.js +0 -110
- package/dist/core/evidence-bundle.test.d.ts +0 -1
- package/dist/core/evidence-bundle.test.js +0 -58
- package/dist/core/invariants.test.d.ts +0 -1
- package/dist/core/invariants.test.js +0 -217
- package/dist/core/login-handoff.test.d.ts +0 -1
- package/dist/core/login-handoff.test.js +0 -31
- package/dist/core/profile.test.d.ts +0 -1
- package/dist/core/profile.test.js +0 -95
- package/dist/core/readiness-checks.test.d.ts +0 -1
- package/dist/core/readiness-checks.test.js +0 -106
- package/dist/core/receipt.test.d.ts +0 -1
- package/dist/core/receipt.test.js +0 -75
- package/dist/core/side-effects-review.test.d.ts +0 -1
- package/dist/core/side-effects-review.test.js +0 -28
- package/dist/core/token.test.d.ts +0 -1
- package/dist/core/token.test.js +0 -66
|
@@ -1,383 +0,0 @@
|
|
|
1
|
-
// ============================================================
|
|
2
|
-
// @duct/sdk — Route Agent
|
|
3
|
-
// Analyzes project routes and produces RouteManifest[]
|
|
4
|
-
// ============================================================
|
|
5
|
-
import { callDuctLLM } from "./llm.js";
|
|
6
|
-
import { normalizeEvidenceArray } from "../processors/verify-discovery.js";
|
|
7
|
-
// ── Next.js App Router ─────────────────────────────────────
|
|
8
|
-
class NextAppRouterScanner {
|
|
9
|
-
name = "NextAppRouter";
|
|
10
|
-
async detect(fs) {
|
|
11
|
-
return (await fs.exists("app")) || (await fs.exists("src/app"));
|
|
12
|
-
}
|
|
13
|
-
async appendPromptContext(fs, lines) {
|
|
14
|
-
for (const dir of ["app", "src/app"]) {
|
|
15
|
-
if (!(await fs.exists(dir)))
|
|
16
|
-
continue;
|
|
17
|
-
lines.push(`\n## Next.js App Router: ${dir}/`);
|
|
18
|
-
const pageFiles = await fs.findFiles(`${dir}/**/page.{ts,tsx,js,jsx}`);
|
|
19
|
-
lines.push(`Found ${pageFiles.length} page files:`);
|
|
20
|
-
for (const f of pageFiles.slice(0, 50))
|
|
21
|
-
lines.push(` - ${f}`);
|
|
22
|
-
// Layout files — indicate auth wrapping
|
|
23
|
-
const layoutFiles = await fs.findFiles(`${dir}/**/layout.{ts,tsx,js,jsx}`);
|
|
24
|
-
for (const lf of layoutFiles.slice(0, 5)) {
|
|
25
|
-
const content = await fs.readFile(lf);
|
|
26
|
-
if (!content)
|
|
27
|
-
continue;
|
|
28
|
-
lines.push(`\n### ${lf} (layout — check for auth wrappers):`);
|
|
29
|
-
lines.push("```tsx");
|
|
30
|
-
lines.push(content.slice(0, 1500));
|
|
31
|
-
lines.push("```");
|
|
32
|
-
}
|
|
33
|
-
// Sample page files — detect auth calls, component imports, useSearchParams
|
|
34
|
-
for (const pf of pageFiles.slice(0, 8)) {
|
|
35
|
-
const content = await fs.readFile(pf);
|
|
36
|
-
if (!content)
|
|
37
|
-
continue;
|
|
38
|
-
lines.push(`\n### ${pf}:`);
|
|
39
|
-
lines.push("```tsx");
|
|
40
|
-
lines.push(content.slice(0, 1200));
|
|
41
|
-
lines.push("```");
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
// ── Next.js Pages Router ────────────────────────────────────
|
|
47
|
-
class NextPagesRouterScanner {
|
|
48
|
-
name = "NextPagesRouter";
|
|
49
|
-
async detect(fs) {
|
|
50
|
-
return (await fs.exists("pages")) || (await fs.exists("src/pages"));
|
|
51
|
-
}
|
|
52
|
-
async appendPromptContext(fs, lines) {
|
|
53
|
-
for (const dir of ["pages", "src/pages"]) {
|
|
54
|
-
if (!(await fs.exists(dir)))
|
|
55
|
-
continue;
|
|
56
|
-
lines.push(`\n## Next.js Pages Router: ${dir}/`);
|
|
57
|
-
const allFiles = await fs.findFiles(`${dir}/**/*.{ts,tsx,js,jsx}`);
|
|
58
|
-
const pageFiles = allFiles.filter((f) => !f.includes("/api/") &&
|
|
59
|
-
!f.includes("_app") &&
|
|
60
|
-
!f.includes("_document") &&
|
|
61
|
-
!f.includes("_error"));
|
|
62
|
-
lines.push(`Found ${pageFiles.length} page files (API routes excluded):`);
|
|
63
|
-
for (const f of pageFiles.slice(0, 50))
|
|
64
|
-
lines.push(` - ${f}`);
|
|
65
|
-
for (const pf of pageFiles.slice(0, 8)) {
|
|
66
|
-
const content = await fs.readFile(pf);
|
|
67
|
-
if (!content)
|
|
68
|
-
continue;
|
|
69
|
-
lines.push(`\n### ${pf}:`);
|
|
70
|
-
lines.push("```tsx");
|
|
71
|
-
lines.push(content.slice(0, 1200));
|
|
72
|
-
lines.push("```");
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
// ── Remix ───────────────────────────────────────────────────
|
|
78
|
-
class RemixScanner {
|
|
79
|
-
name = "Remix";
|
|
80
|
-
async detect(fs) {
|
|
81
|
-
return ((await fs.exists("app/routes")) ||
|
|
82
|
-
(await fs.exists("src/routes")) ||
|
|
83
|
-
(await fs.exists("app/root.tsx")) ||
|
|
84
|
-
(await fs.exists("app/root.ts")));
|
|
85
|
-
}
|
|
86
|
-
async appendPromptContext(fs, lines) {
|
|
87
|
-
for (const dir of ["app/routes", "src/routes"]) {
|
|
88
|
-
if (!(await fs.exists(dir)))
|
|
89
|
-
continue;
|
|
90
|
-
lines.push(`\n## Remix v2 Routes: ${dir}/`);
|
|
91
|
-
lines.push("Note: Remix v2 uses flat file naming — dots (.) map to path separators.");
|
|
92
|
-
lines.push(" _layout.route.tsx patterns define layout segments.");
|
|
93
|
-
lines.push(" $param segments are dynamic. (group) segments are layout groups.");
|
|
94
|
-
const files = await fs.findFiles(`${dir}/**/*.{ts,tsx,js,jsx}`);
|
|
95
|
-
lines.push(`Found ${files.length} route files:`);
|
|
96
|
-
for (const f of files.slice(0, 50))
|
|
97
|
-
lines.push(` - ${f}`);
|
|
98
|
-
for (const f of files.slice(0, 6)) {
|
|
99
|
-
const content = await fs.readFile(f);
|
|
100
|
-
if (!content)
|
|
101
|
-
continue;
|
|
102
|
-
lines.push(`\n### ${f}:`);
|
|
103
|
-
lines.push("```tsx");
|
|
104
|
-
lines.push(content.slice(0, 1200));
|
|
105
|
-
lines.push("```");
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
// ── SvelteKit ───────────────────────────────────────────────
|
|
111
|
-
class SvelteKitScanner {
|
|
112
|
-
name = "SvelteKit";
|
|
113
|
-
async detect(fs) {
|
|
114
|
-
return ((await fs.exists("src/routes")) &&
|
|
115
|
-
((await fs.exists("svelte.config.js")) || (await fs.exists("svelte.config.ts"))));
|
|
116
|
-
}
|
|
117
|
-
async appendPromptContext(fs, lines) {
|
|
118
|
-
if (!(await fs.exists("src/routes")))
|
|
119
|
-
return;
|
|
120
|
-
lines.push("\n## SvelteKit Routes: src/routes/");
|
|
121
|
-
lines.push("Note: +page.svelte = page, (group) = layout group, [[optional]] = optional param, [...rest] = catch-all.");
|
|
122
|
-
const files = await fs.findFiles("src/routes/**/*.svelte");
|
|
123
|
-
const pageFiles = files.filter((f) => f.includes("+page.svelte"));
|
|
124
|
-
lines.push(`Found ${pageFiles.length} +page.svelte files:`);
|
|
125
|
-
for (const f of pageFiles.slice(0, 50))
|
|
126
|
-
lines.push(` - ${f}`);
|
|
127
|
-
for (const f of pageFiles.slice(0, 6)) {
|
|
128
|
-
const content = await fs.readFile(f);
|
|
129
|
-
if (!content)
|
|
130
|
-
continue;
|
|
131
|
-
lines.push(`\n### ${f}:`);
|
|
132
|
-
lines.push("```svelte");
|
|
133
|
-
lines.push(content.slice(0, 1200));
|
|
134
|
-
lines.push("```");
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
// ── Vite / React Router ─────────────────────────────────────
|
|
139
|
-
class ViteScanner {
|
|
140
|
-
name = "Vite";
|
|
141
|
-
async detect(fs) {
|
|
142
|
-
return ((await fs.exists("vite.config.ts")) ||
|
|
143
|
-
(await fs.exists("vite.config.js")) ||
|
|
144
|
-
(await fs.exists("src/router")) ||
|
|
145
|
-
(await fs.exists("src/routes/index.tsx")) ||
|
|
146
|
-
(await fs.exists("src/routes/index.ts")));
|
|
147
|
-
}
|
|
148
|
-
async appendPromptContext(fs, lines) {
|
|
149
|
-
lines.push("\n## Vite / React Router Routes");
|
|
150
|
-
// Try router config first
|
|
151
|
-
for (const candidate of [
|
|
152
|
-
"src/router/index.tsx",
|
|
153
|
-
"src/router/index.ts",
|
|
154
|
-
"src/router.tsx",
|
|
155
|
-
"src/router.ts",
|
|
156
|
-
"src/routes/index.tsx",
|
|
157
|
-
"src/routes/index.ts",
|
|
158
|
-
"src/App.tsx",
|
|
159
|
-
"src/App.ts",
|
|
160
|
-
]) {
|
|
161
|
-
const content = await fs.readFile(candidate);
|
|
162
|
-
if (!content)
|
|
163
|
-
continue;
|
|
164
|
-
lines.push(`\n### ${candidate} (router config):`);
|
|
165
|
-
lines.push("```tsx");
|
|
166
|
-
lines.push(content.slice(0, 2000));
|
|
167
|
-
lines.push("```");
|
|
168
|
-
break;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
/** Ordered list of all scanner strategies. Multiple can match. */
|
|
173
|
-
const SCANNER_STRATEGIES = [
|
|
174
|
-
new NextAppRouterScanner(),
|
|
175
|
-
new NextPagesRouterScanner(),
|
|
176
|
-
new RemixScanner(),
|
|
177
|
-
new SvelteKitScanner(),
|
|
178
|
-
new ViteScanner(),
|
|
179
|
-
];
|
|
180
|
-
/**
|
|
181
|
-
* Detect frontend subdirectory prefixes in monorepo structures.
|
|
182
|
-
* When `duct init` is run from a project root containing both `frontend/` and `backend/`,
|
|
183
|
-
* scanners need to look inside the frontend subdirectory for routes.
|
|
184
|
-
*/
|
|
185
|
-
async function detectFrontendRoots(sandboxFs) {
|
|
186
|
-
const frontendCandidates = ["frontend", "web", "client", "app", "apps/web", "packages/web", "packages/frontend"];
|
|
187
|
-
const roots = [];
|
|
188
|
-
for (const dir of frontendCandidates) {
|
|
189
|
-
if (!(await sandboxFs.exists(dir)))
|
|
190
|
-
continue;
|
|
191
|
-
// Check if this subdirectory looks like a frontend project
|
|
192
|
-
const hasFrontendMarkers = (await sandboxFs.exists(`${dir}/package.json`)) &&
|
|
193
|
-
((await sandboxFs.exists(`${dir}/app`)) ||
|
|
194
|
-
(await sandboxFs.exists(`${dir}/src/app`)) ||
|
|
195
|
-
(await sandboxFs.exists(`${dir}/pages`)) ||
|
|
196
|
-
(await sandboxFs.exists(`${dir}/src/pages`)) ||
|
|
197
|
-
(await sandboxFs.exists(`${dir}/src/routes`)) ||
|
|
198
|
-
(await sandboxFs.exists(`${dir}/src/lib/routes`)));
|
|
199
|
-
if (hasFrontendMarkers)
|
|
200
|
-
roots.push(`${dir}/`);
|
|
201
|
-
}
|
|
202
|
-
// Always include root
|
|
203
|
-
roots.push("");
|
|
204
|
-
return [...new Set(roots)];
|
|
205
|
-
}
|
|
206
|
-
// ----------------------------------------------------------------
|
|
207
|
-
// Output schema description for the LLM
|
|
208
|
-
// ----------------------------------------------------------------
|
|
209
|
-
const ROUTE_MANIFEST_SCHEMA = `
|
|
210
|
-
Array of RouteManifest objects:
|
|
211
|
-
[
|
|
212
|
-
{
|
|
213
|
-
"path": "/dashboard", // Route path with Next.js brackets e.g. /orders/[id]
|
|
214
|
-
"name": "Dashboard", // Human-readable name
|
|
215
|
-
"description": "...", // What this page shows/does
|
|
216
|
-
"params": [ // Dynamic path params
|
|
217
|
-
{
|
|
218
|
-
"name": "id",
|
|
219
|
-
"type": "uuid", // "string" | "number" | "uuid" | "slug"
|
|
220
|
-
"required": true,
|
|
221
|
-
"description": "Order ID"
|
|
222
|
-
}
|
|
223
|
-
],
|
|
224
|
-
"queryParams": [ // URL query params
|
|
225
|
-
{
|
|
226
|
-
"name": "page",
|
|
227
|
-
"type": "number",
|
|
228
|
-
"required": false,
|
|
229
|
-
"description": "Page number",
|
|
230
|
-
"defaultValue": 1
|
|
231
|
-
}
|
|
232
|
-
],
|
|
233
|
-
"uiStateHint": "dashboard", // "form"|"list"|"detail"|"dashboard"|"modal"|"wizard"|"empty"|"error"|"auth"|"checkout"|"profile"|"settings"|"search"
|
|
234
|
-
"requiresAuth": true,
|
|
235
|
-
"deeplinkable": true, // Whether Duct can deeplink here with state
|
|
236
|
-
"confidence": 0.92, // Detection confidence 0.0–1.0. Lower for: dynamic routes inferred from patterns, no explicit auth check found, file missing
|
|
237
|
-
"evidence": "app/dashboard/page.tsx:1" // File path and line number where this route was detected
|
|
238
|
-
}
|
|
239
|
-
]
|
|
240
|
-
|
|
241
|
-
Confidence scoring rules:
|
|
242
|
-
- 1.0: explicit file path maps directly to route, auth check is clear
|
|
243
|
-
- 0.85–0.99: clear file evidence, auth inferred from layout wrapper
|
|
244
|
-
- 0.6–0.84: route exists but auth is ambiguous, or param type is guessed
|
|
245
|
-
- below 0.6: route inferred from naming/pattern, not explicit file evidence
|
|
246
|
-
`.trim();
|
|
247
|
-
// ----------------------------------------------------------------
|
|
248
|
-
// Prompt builder — uses RouteScannerStrategy
|
|
249
|
-
// ----------------------------------------------------------------
|
|
250
|
-
async function buildRoutePrompt(sandboxFs, hintFiles, retryHint) {
|
|
251
|
-
const lines = [];
|
|
252
|
-
lines.push("Analyze this web project and identify all user-facing navigable routes.\n" +
|
|
253
|
-
"Use the file structure and code snippets below to produce a RouteManifest array.\n");
|
|
254
|
-
// If the selector pre-identified targeted files, include them first.
|
|
255
|
-
if (hintFiles && hintFiles.length > 0) {
|
|
256
|
-
lines.push("## Targeted route files:");
|
|
257
|
-
for (const f of hintFiles.slice(0, 30)) {
|
|
258
|
-
const content = await sandboxFs.readFile(f);
|
|
259
|
-
if (!content)
|
|
260
|
-
continue;
|
|
261
|
-
lines.push(`\n### ${f}:`);
|
|
262
|
-
lines.push("```tsx");
|
|
263
|
-
lines.push(content.slice(0, 1200));
|
|
264
|
-
lines.push("```");
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
// Detect monorepo frontend roots — allows scanning frontend/ or web/ subdirectories
|
|
268
|
-
const frontendRoots = await detectFrontendRoots(sandboxFs);
|
|
269
|
-
if (frontendRoots.some((r) => r !== "")) {
|
|
270
|
-
lines.push(`Detected monorepo structure — frontend roots: ${frontendRoots.filter((r) => r !== "").join(", ")}\n`);
|
|
271
|
-
}
|
|
272
|
-
// Build sub-sandboxes scoped to each frontend root and run all strategies.
|
|
273
|
-
// sandboxFs.scoped() returns a real SandboxFS rooted at the subdirectory.
|
|
274
|
-
// Strip the trailing slash before passing to scoped() so path.join works correctly.
|
|
275
|
-
let anyDetected = false;
|
|
276
|
-
for (const root of frontendRoots) {
|
|
277
|
-
const scopedFs = root === "" ? sandboxFs : sandboxFs.scoped(root.slice(0, -1));
|
|
278
|
-
for (const strategy of SCANNER_STRATEGIES) {
|
|
279
|
-
if (await strategy.detect(scopedFs)) {
|
|
280
|
-
anyDetected = true;
|
|
281
|
-
if (root !== "") {
|
|
282
|
-
lines.push(`\n# Scanning frontend root: ${root}`);
|
|
283
|
-
}
|
|
284
|
-
await strategy.appendPromptContext(scopedFs, lines);
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
if (!anyDetected) {
|
|
289
|
-
lines.push("## Warning: No recognised framework detected.");
|
|
290
|
-
lines.push("Scanning for common route patterns in src/ and app/ directories.");
|
|
291
|
-
const fallbackFiles = await sandboxFs.findFiles("**/*.{tsx,ts,jsx,js}");
|
|
292
|
-
const pagelike = fallbackFiles
|
|
293
|
-
.filter((f) => /page|route|view|screen/i.test(f))
|
|
294
|
-
.slice(0, 20);
|
|
295
|
-
for (const f of pagelike)
|
|
296
|
-
lines.push(` - ${f}`);
|
|
297
|
-
}
|
|
298
|
-
// Read middleware / auth guards for auth inference
|
|
299
|
-
const middlewareCandidates = [
|
|
300
|
-
"middleware.ts", "middleware.js",
|
|
301
|
-
"src/middleware.ts", "src/middleware.js",
|
|
302
|
-
"src/hooks.server.ts", // SvelteKit
|
|
303
|
-
];
|
|
304
|
-
for (const candidate of middlewareCandidates) {
|
|
305
|
-
const content = await sandboxFs.readFile(candidate);
|
|
306
|
-
if (content) {
|
|
307
|
-
lines.push(`\n## ${candidate} (auth/redirect guard):`);
|
|
308
|
-
lines.push("```ts");
|
|
309
|
-
lines.push(content.slice(0, 2000));
|
|
310
|
-
lines.push("```");
|
|
311
|
-
break;
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
lines.push(`
|
|
315
|
-
## Instructions
|
|
316
|
-
|
|
317
|
-
For each user-facing route produce a RouteManifest entry:
|
|
318
|
-
- **path**: Derive from file structure. Next.js: [param] stays as-is. Remix: convert dots to slashes. SvelteKit: +page.svelte filename is the segment.
|
|
319
|
-
- **requiresAuth**: true if: (1) the page/layout calls auth(), getServerSession(), currentUser(), or equivalent; (2) middleware.ts matches the route path; (3) when uncertain, default true (fail-safe).
|
|
320
|
-
- **uiStateHint**: Classify from component imports and page content. Priority: checkout > wizard > modal > form > list > detail > dashboard. Map: <Table>/<DataGrid> → list, <Form>/<Input> → form, <Modal>/<Dialog> → modal, <Wizard>/<Steps> → wizard.
|
|
321
|
-
- **deeplinkable**: true when the route has at least one required path param AND requiresAuth is true (a signed deeplink JWT makes sense for authenticated detail pages).
|
|
322
|
-
- **queryParams**: Extract from useSearchParams().get('...') / $page.url.searchParams.get('...') calls — infer type from usage context.
|
|
323
|
-
- **params**: Typed from file path segment names ([id] → uuid/string, [slug] → slug).
|
|
324
|
-
|
|
325
|
-
DO NOT include API routes (/api/...), auth callback routes, or static asset paths.
|
|
326
|
-
DO NOT include _app, _document, layout-only files that don't produce a page.`);
|
|
327
|
-
if (retryHint) {
|
|
328
|
-
lines.push("");
|
|
329
|
-
lines.push(retryHint);
|
|
330
|
-
}
|
|
331
|
-
return lines.join("\n");
|
|
332
|
-
}
|
|
333
|
-
// ----------------------------------------------------------------
|
|
334
|
-
// runRouteAgent
|
|
335
|
-
// ----------------------------------------------------------------
|
|
336
|
-
/**
|
|
337
|
-
* Run the Route Agent to produce a RouteManifest[] from the project structure.
|
|
338
|
-
* @param hintFiles - Optional pre-selected file paths from the file selector.
|
|
339
|
-
* When provided, these are included first in the prompt as priority context.
|
|
340
|
-
*/
|
|
341
|
-
export async function runRouteAgent(sandboxFs, hintFiles, options) {
|
|
342
|
-
const retryHint = options?.retry
|
|
343
|
-
? "RETRY: Your previous pass returned zero routes. Re-read the snippets and include every user-facing page you can verify from file evidence."
|
|
344
|
-
: undefined;
|
|
345
|
-
const prompt = await buildRoutePrompt(sandboxFs, hintFiles, retryHint);
|
|
346
|
-
const result = await callDuctLLM({
|
|
347
|
-
agentName: "RouteAgent",
|
|
348
|
-
systemPrompt: "You are an expert at analyzing Next.js, Remix, and React web application codebases. " +
|
|
349
|
-
"You produce structured route manifests that describe every navigable page in an application.",
|
|
350
|
-
userPrompt: prompt,
|
|
351
|
-
outputSchema: ROUTE_MANIFEST_SCHEMA,
|
|
352
|
-
maxTokens: 4096,
|
|
353
|
-
});
|
|
354
|
-
if (!Array.isArray(result.parsed)) {
|
|
355
|
-
throw new Error(`RouteAgent returned unexpected shape: expected array, got ${typeof result.parsed}`);
|
|
356
|
-
}
|
|
357
|
-
// Validate and sanitize the response
|
|
358
|
-
const routes = result.parsed
|
|
359
|
-
.filter((r) => {
|
|
360
|
-
return (typeof r === "object" &&
|
|
361
|
-
r !== null &&
|
|
362
|
-
typeof r.path === "string" &&
|
|
363
|
-
r.path.startsWith("/"));
|
|
364
|
-
})
|
|
365
|
-
.map((r) => ({
|
|
366
|
-
path: r.path,
|
|
367
|
-
name: r.name || r.path,
|
|
368
|
-
description: r.description || "",
|
|
369
|
-
params: Array.isArray(r.params) ? r.params : [],
|
|
370
|
-
queryParams: Array.isArray(r.queryParams) ? r.queryParams : [],
|
|
371
|
-
uiStateHint: r.uiStateHint || "dashboard",
|
|
372
|
-
requiresAuth: r.requiresAuth ?? true,
|
|
373
|
-
deeplinkable: r.deeplinkable ?? false,
|
|
374
|
-
methods: r.methods,
|
|
375
|
-
...(typeof r.confidence === "number"
|
|
376
|
-
? { confidence: Math.min(1, Math.max(0, r.confidence)) }
|
|
377
|
-
: {}),
|
|
378
|
-
...(normalizeEvidenceArray(r.evidence).length > 0
|
|
379
|
-
? { evidence: normalizeEvidenceArray(r.evidence) }
|
|
380
|
-
: {}),
|
|
381
|
-
}));
|
|
382
|
-
return routes;
|
|
383
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { describe, it } from "node:test";
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import * as fs from "fs/promises";
|
|
4
|
-
import * as os from "os";
|
|
5
|
-
import * as path from "path";
|
|
6
|
-
import { ConfigRuntimeReferenceError, configSourceHasRuntimeReferences, loadConfigFromSource, } from "./config-loader.js";
|
|
7
|
-
describe("configSourceHasRuntimeReferences", () => {
|
|
8
|
-
it("detects process.exit at top level", () => {
|
|
9
|
-
const source = `process.exit(1);\nexport default defineDuctConfig({ shellId: "x" });`;
|
|
10
|
-
assert.equal(configSourceHasRuntimeReferences(source), true);
|
|
11
|
-
});
|
|
12
|
-
it("allows static defineDuctConfig literals", () => {
|
|
13
|
-
const source = `
|
|
14
|
-
import { defineDuctConfig } from "@duct-sdk/sdk";
|
|
15
|
-
export default defineDuctConfig({
|
|
16
|
-
shellId: "shell_acme",
|
|
17
|
-
product: { name: "Acme", description: "Test app", baseUrl: "https://app.acme.com" },
|
|
18
|
-
});
|
|
19
|
-
`;
|
|
20
|
-
assert.equal(configSourceHasRuntimeReferences(source), false);
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
describe("loadConfigFromSource", () => {
|
|
24
|
-
it("does not execute process.exit during load", async () => {
|
|
25
|
-
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "duct-config-"));
|
|
26
|
-
const configPath = path.join(dir, "duct.config.ts");
|
|
27
|
-
const source = `
|
|
28
|
-
process.exit(42);
|
|
29
|
-
import { defineDuctConfig } from "@duct-sdk/sdk";
|
|
30
|
-
export default defineDuctConfig({
|
|
31
|
-
shellId: "shell_bad",
|
|
32
|
-
product: { name: "Bad", description: "Should not run", baseUrl: "https://bad.example" },
|
|
33
|
-
auth: { strategy: "none", sessionFields: ["id"], guestAllowed: true, tokenExpirySeconds: 60 },
|
|
34
|
-
routes: [],
|
|
35
|
-
actions: [],
|
|
36
|
-
deeplinks: [],
|
|
37
|
-
agentPermissions: { defaultLevel: "none", requireUserConsent: true },
|
|
38
|
-
});
|
|
39
|
-
`;
|
|
40
|
-
await fs.writeFile(configPath, source, "utf-8");
|
|
41
|
-
await assert.rejects(() => loadConfigFromSource(configPath), (err) => err instanceof ConfigRuntimeReferenceError);
|
|
42
|
-
});
|
|
43
|
-
it("parses static defineDuctConfig object literal", async () => {
|
|
44
|
-
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "duct-config-"));
|
|
45
|
-
const configPath = path.join(dir, "duct.config.ts");
|
|
46
|
-
const source = `
|
|
47
|
-
import { defineDuctConfig } from "@duct-sdk/sdk";
|
|
48
|
-
export default defineDuctConfig({
|
|
49
|
-
shellId: "shell_ok",
|
|
50
|
-
product: { name: "Ok", description: "Static config", baseUrl: "https://ok.example" },
|
|
51
|
-
auth: { strategy: "none", sessionFields: ["id"], guestAllowed: true, tokenExpirySeconds: 60 },
|
|
52
|
-
routes: [],
|
|
53
|
-
actions: [],
|
|
54
|
-
deeplinks: [],
|
|
55
|
-
agentPermissions: { defaultLevel: "none", requireUserConsent: true },
|
|
56
|
-
});
|
|
57
|
-
`;
|
|
58
|
-
await fs.writeFile(configPath, source, "utf-8");
|
|
59
|
-
const loaded = await loadConfigFromSource(configPath);
|
|
60
|
-
assert.ok(loaded);
|
|
61
|
-
assert.equal(loaded.shellId, "shell_ok");
|
|
62
|
-
});
|
|
63
|
-
});
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import type { AuthStrategy } from "../../core/types.js";
|
|
2
|
-
import type { FrameworkName } from "./framework.js";
|
|
3
|
-
export interface TopoResult {
|
|
4
|
-
/** Primary frontend/fullstack framework */
|
|
5
|
-
framework: FrameworkName;
|
|
6
|
-
/** Primary language detected at root */
|
|
7
|
-
language: "typescript" | "javascript" | "python" | "ruby" | "go" | "unknown";
|
|
8
|
-
/** Relative path to the route directory (e.g. "app", "pages", "src/routes") */
|
|
9
|
-
routeRoot: string;
|
|
10
|
-
/** Relative path to the API directory (e.g. "app/api", "pages/api", "routes") */
|
|
11
|
-
apiRoot: string;
|
|
12
|
-
/** All candidate API root directories (plural — for selectors) */
|
|
13
|
-
apiRoots: string[];
|
|
14
|
-
/** All candidate route root directories (plural — for selectors) */
|
|
15
|
-
routeRoots: string[];
|
|
16
|
-
/** Detected package manager */
|
|
17
|
-
packageManager: "npm" | "yarn" | "pnpm" | "pip" | "unknown";
|
|
18
|
-
/** Absolute path to the project root */
|
|
19
|
-
projectRoot: string;
|
|
20
|
-
/** Detection confidence 0–1 (1 = all signals confirmed) */
|
|
21
|
-
confidence: number;
|
|
22
|
-
/** Auth library detected from deps / config files */
|
|
23
|
-
authLib: AuthStrategy;
|
|
24
|
-
/** Whether this looks like a monorepo (multiple package.json dirs) */
|
|
25
|
-
isMonorepo: boolean;
|
|
26
|
-
/** Relative paths to all subdirectory package roots (monorepo workspaces) */
|
|
27
|
-
packageDirs: string[];
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Topology Discovery.
|
|
31
|
-
*
|
|
32
|
-
* Reads only package.json / pyproject.toml / go.mod, root config files,
|
|
33
|
-
* and top-level directory names. No LLM, no deep reads.
|
|
34
|
-
* Must run before any agent or selector.
|
|
35
|
-
*/
|
|
36
|
-
export declare function discoverTopology(projectRoot: string): Promise<TopoResult>;
|
|
37
|
-
/**
|
|
38
|
-
* Detect project topology for the selector pipeline.
|
|
39
|
-
*
|
|
40
|
-
* Returns an enriched TopoResult with plural `apiRoots`, `routeRoots`,
|
|
41
|
-
* `packageManager`, `projectRoot`, and `confidence` in addition to the
|
|
42
|
-
* existing fields from `discoverTopology()`.
|
|
43
|
-
*
|
|
44
|
-
* No LLM — pure filesystem reads only.
|
|
45
|
-
*/
|
|
46
|
-
export declare function detectTopology(projectRoot: string): Promise<TopoResult>;
|