@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,74 +0,0 @@
|
|
|
1
|
-
// ============================================================
|
|
2
|
-
// @duct/sdk — Generic File Selector (fallback)
|
|
3
|
-
// Returns the top maxFiles .ts/.js/.py files sorted by file size
|
|
4
|
-
// (larger files are more likely to contain route definitions).
|
|
5
|
-
// ============================================================
|
|
6
|
-
import * as fs from "fs/promises";
|
|
7
|
-
import * as path from "path";
|
|
8
|
-
import { glob } from "glob";
|
|
9
|
-
async function globFiles(root, pattern) {
|
|
10
|
-
try {
|
|
11
|
-
const matches = await glob(pattern, {
|
|
12
|
-
cwd: root,
|
|
13
|
-
ignore: [
|
|
14
|
-
"**/node_modules/**",
|
|
15
|
-
"**/.git/**",
|
|
16
|
-
"**/dist/**",
|
|
17
|
-
"**/build/**",
|
|
18
|
-
"**/out/**",
|
|
19
|
-
"**/.next/**",
|
|
20
|
-
"**/__pycache__/**",
|
|
21
|
-
"**/.venv/**",
|
|
22
|
-
"**/venv/**",
|
|
23
|
-
"**/*.test.{ts,js}",
|
|
24
|
-
"**/*.spec.{ts,js}",
|
|
25
|
-
"**/*.d.ts",
|
|
26
|
-
],
|
|
27
|
-
nodir: true,
|
|
28
|
-
absolute: false,
|
|
29
|
-
});
|
|
30
|
-
return matches;
|
|
31
|
-
}
|
|
32
|
-
catch {
|
|
33
|
-
return [];
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
async function getFileSize(filePath) {
|
|
37
|
-
try {
|
|
38
|
-
const s = await fs.stat(filePath);
|
|
39
|
-
return s.size;
|
|
40
|
-
}
|
|
41
|
-
catch {
|
|
42
|
-
return 0;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
// ----------------------------------------------------------------
|
|
46
|
-
// Generic selector — main export
|
|
47
|
-
// ----------------------------------------------------------------
|
|
48
|
-
/**
|
|
49
|
-
* Generic fallback file selector.
|
|
50
|
-
*
|
|
51
|
-
* Returns the top `maxFiles` .ts/.js/.py files sorted by file size descending
|
|
52
|
-
* (larger files are more likely to contain route/handler definitions).
|
|
53
|
-
*
|
|
54
|
-
* @param projectRoot Absolute project root path
|
|
55
|
-
* @param maxFiles Maximum total files to return (default 30)
|
|
56
|
-
*/
|
|
57
|
-
export async function selectGenericFiles(projectRoot, maxFiles = 30) {
|
|
58
|
-
const allFiles = [];
|
|
59
|
-
const tsFiles = await globFiles(projectRoot, "**/*.{ts,tsx}");
|
|
60
|
-
const jsFiles = await globFiles(projectRoot, "**/*.{js,jsx,mjs}");
|
|
61
|
-
const pyFiles = await globFiles(projectRoot, "**/*.py");
|
|
62
|
-
allFiles.push(...tsFiles, ...jsFiles, ...pyFiles);
|
|
63
|
-
if (allFiles.length === 0)
|
|
64
|
-
return [];
|
|
65
|
-
// Deduplicate
|
|
66
|
-
const unique = [...new Set(allFiles)];
|
|
67
|
-
// Sort by file size descending — larger = more likely to contain route definitions
|
|
68
|
-
const sized = await Promise.all(unique.map(async (f) => ({
|
|
69
|
-
f,
|
|
70
|
-
size: await getFileSize(path.join(projectRoot, f)),
|
|
71
|
-
})));
|
|
72
|
-
sized.sort((a, b) => b.size - a.size);
|
|
73
|
-
return sized.slice(0, maxFiles).map((s) => s.f);
|
|
74
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type { SandboxFS } from "../fs/sandbox.js";
|
|
2
|
-
import type { TopoResult } from "../detectors/topology.js";
|
|
3
|
-
export { selectNextFiles } from "./next.js";
|
|
4
|
-
export { selectExpressFiles } from "./express.js";
|
|
5
|
-
export { selectFastApiFiles } from "./fastapi.js";
|
|
6
|
-
export { selectGenericFiles } from "./generic.js";
|
|
7
|
-
/** Per-agent bounded file list, max MAX_FILES_PER_LIST entries each. */
|
|
8
|
-
export interface ReadList {
|
|
9
|
-
/** Files for the Route Agent — page files, layouts */
|
|
10
|
-
routeFiles: string[];
|
|
11
|
-
/** Files for the API Agent — route handlers, controllers */
|
|
12
|
-
apiFiles: string[];
|
|
13
|
-
/** Files for the Auth Agent — middleware, auth config, env examples */
|
|
14
|
-
authFiles: string[];
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Select the most relevant source files for a given project topology.
|
|
18
|
-
*
|
|
19
|
-
* Returns a flat, deduplicated list of relative file paths capped at
|
|
20
|
-
* `maxFiles`. Files are ordered by relevance: API routes first, then
|
|
21
|
-
* type definitions, then entry points / middleware.
|
|
22
|
-
*
|
|
23
|
-
* Delegates to framework-specific selectors (next, express, fastapi) or
|
|
24
|
-
* falls back to the generic size-ranked selector for unknown stacks.
|
|
25
|
-
*/
|
|
26
|
-
export declare function selectFilesForFramework(topo: TopoResult, maxFiles?: number): Promise<string[]>;
|
|
27
|
-
/**
|
|
28
|
-
* Build a bounded ReadList per agent from the project's topology.
|
|
29
|
-
*
|
|
30
|
-
* Given a TopoResult, builds a bounded ReadList for each agent.
|
|
31
|
-
* Each list is capped at MAX_FILES_PER_LIST entries, ranked by file size
|
|
32
|
-
* (smaller first — more focused files).
|
|
33
|
-
*
|
|
34
|
-
* Falls back to the generic strategy for unknown stacks. Generic fallback
|
|
35
|
-
* detections should get confidence < 0.6 automatically.
|
|
36
|
-
*/
|
|
37
|
-
export declare function buildReadList(topo: TopoResult, sandboxFs: SandboxFS): Promise<ReadList>;
|
|
@@ -1,315 +0,0 @@
|
|
|
1
|
-
// ============================================================
|
|
2
|
-
// @duct/sdk — Targeted File Selection
|
|
3
|
-
// Builds a bounded ReadList per agent from a TopoResult.
|
|
4
|
-
// No LLM. Max MAX_FILES_PER_LIST files per agent list.
|
|
5
|
-
// ============================================================
|
|
6
|
-
import { selectNextFiles } from "./next.js";
|
|
7
|
-
import { selectExpressFiles } from "./express.js";
|
|
8
|
-
import { selectFastApiFiles } from "./fastapi.js";
|
|
9
|
-
import { selectGenericFiles } from "./generic.js";
|
|
10
|
-
export { selectNextFiles } from "./next.js";
|
|
11
|
-
export { selectExpressFiles } from "./express.js";
|
|
12
|
-
export { selectFastApiFiles } from "./fastapi.js";
|
|
13
|
-
export { selectGenericFiles } from "./generic.js";
|
|
14
|
-
const MAX_FILES_PER_LIST = 30;
|
|
15
|
-
// ----------------------------------------------------------------
|
|
16
|
-
// Ranking helpers
|
|
17
|
-
// ----------------------------------------------------------------
|
|
18
|
-
async function rankFiles(paths, sandboxFs) {
|
|
19
|
-
const ranked = [];
|
|
20
|
-
for (const p of paths) {
|
|
21
|
-
try {
|
|
22
|
-
const content = await sandboxFs.readFile(p);
|
|
23
|
-
ranked.push({ path: p, sizeBytes: content?.length ?? 0 });
|
|
24
|
-
}
|
|
25
|
-
catch {
|
|
26
|
-
ranked.push({ path: p, sizeBytes: 0 });
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
// Smaller files first (more focused); stable for equal sizes
|
|
30
|
-
return ranked.sort((a, b) => a.sizeBytes - b.sizeBytes);
|
|
31
|
-
}
|
|
32
|
-
async function selectTop(paths, sandboxFs, limit = MAX_FILES_PER_LIST) {
|
|
33
|
-
if (paths.length <= limit)
|
|
34
|
-
return paths;
|
|
35
|
-
const ranked = await rankFiles(paths, sandboxFs);
|
|
36
|
-
const selected = ranked.slice(0, limit).map((r) => r.path);
|
|
37
|
-
console.error(`[duct/selectors] Trimmed ${paths.length} → ${selected.length} files (cap: ${limit})`);
|
|
38
|
-
return selected;
|
|
39
|
-
}
|
|
40
|
-
// ----------------------------------------------------------------
|
|
41
|
-
// Auth files — common across frameworks
|
|
42
|
-
// ----------------------------------------------------------------
|
|
43
|
-
const AUTH_CANDIDATES = [
|
|
44
|
-
"middleware.ts",
|
|
45
|
-
"middleware.js",
|
|
46
|
-
"src/middleware.ts",
|
|
47
|
-
"src/middleware.js",
|
|
48
|
-
"auth.ts",
|
|
49
|
-
"auth.js",
|
|
50
|
-
"auth.config.ts",
|
|
51
|
-
"auth.config.js",
|
|
52
|
-
// NextAuth
|
|
53
|
-
"pages/api/auth/[...nextauth].ts",
|
|
54
|
-
"pages/api/auth/[...nextauth].js",
|
|
55
|
-
"app/api/auth/[...nextauth]/route.ts",
|
|
56
|
-
"src/app/api/auth/[...nextauth]/route.ts",
|
|
57
|
-
// Env examples
|
|
58
|
-
".env.example",
|
|
59
|
-
".env.local.example",
|
|
60
|
-
".env.sample",
|
|
61
|
-
".env.template",
|
|
62
|
-
// Clerk
|
|
63
|
-
"clerk.config.ts",
|
|
64
|
-
"clerk.config.js",
|
|
65
|
-
"src/lib/clerk.ts",
|
|
66
|
-
"lib/clerk.ts",
|
|
67
|
-
];
|
|
68
|
-
async function collectAuthFiles(sandboxFs) {
|
|
69
|
-
const found = [];
|
|
70
|
-
for (const candidate of AUTH_CANDIDATES) {
|
|
71
|
-
if (await sandboxFs.exists(candidate)) {
|
|
72
|
-
found.push(candidate);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return found;
|
|
76
|
-
}
|
|
77
|
-
// ----------------------------------------------------------------
|
|
78
|
-
// Next.js App Router strategy
|
|
79
|
-
// ----------------------------------------------------------------
|
|
80
|
-
async function selectNextApp(sandboxFs) {
|
|
81
|
-
const routeDir = (await sandboxFs.exists("src/app")) ? "src/app" : "app";
|
|
82
|
-
const pageFiles = await sandboxFs.findFiles(`${routeDir}/**/page.{ts,tsx,js,jsx}`);
|
|
83
|
-
const layoutFiles = await sandboxFs.findFiles(`${routeDir}/**/layout.{ts,tsx,js,jsx}`);
|
|
84
|
-
const apiDir = `${routeDir}/api`;
|
|
85
|
-
const apiRouteFiles = await sandboxFs.findFiles(`${apiDir}/**/route.{ts,tsx,js}`);
|
|
86
|
-
// Also grab root middleware
|
|
87
|
-
const authFiles = await collectAuthFiles(sandboxFs);
|
|
88
|
-
return {
|
|
89
|
-
routeFiles: await selectTop([...pageFiles, ...layoutFiles.slice(0, 5)], sandboxFs),
|
|
90
|
-
apiFiles: await selectTop(apiRouteFiles, sandboxFs),
|
|
91
|
-
authFiles: await selectTop(authFiles, sandboxFs),
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
// ----------------------------------------------------------------
|
|
95
|
-
// Next.js Pages Router strategy
|
|
96
|
-
// ----------------------------------------------------------------
|
|
97
|
-
async function selectNextPages(sandboxFs) {
|
|
98
|
-
const pagesDir = (await sandboxFs.exists("src/pages")) ? "src/pages" : "pages";
|
|
99
|
-
const allPageFiles = await sandboxFs.findFiles(`${pagesDir}/**/*.{ts,tsx,js,jsx}`);
|
|
100
|
-
const pageFiles = allPageFiles.filter((f) => !f.includes("/api/") &&
|
|
101
|
-
!f.includes("_app") &&
|
|
102
|
-
!f.includes("_document") &&
|
|
103
|
-
!f.includes("_error"));
|
|
104
|
-
const apiFiles = allPageFiles.filter((f) => f.includes("/api/"));
|
|
105
|
-
const authFiles = await collectAuthFiles(sandboxFs);
|
|
106
|
-
return {
|
|
107
|
-
routeFiles: await selectTop(pageFiles, sandboxFs),
|
|
108
|
-
apiFiles: await selectTop(apiFiles, sandboxFs),
|
|
109
|
-
authFiles: await selectTop(authFiles, sandboxFs),
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
// ----------------------------------------------------------------
|
|
113
|
-
// Remix strategy
|
|
114
|
-
// ----------------------------------------------------------------
|
|
115
|
-
async function selectRemix(sandboxFs) {
|
|
116
|
-
const routeFiles = await sandboxFs.findFiles("app/routes/**/*.{ts,tsx,js,jsx}");
|
|
117
|
-
const authFiles = await collectAuthFiles(sandboxFs);
|
|
118
|
-
// In Remix, routes double as API endpoints via loaders/actions
|
|
119
|
-
return {
|
|
120
|
-
routeFiles: await selectTop(routeFiles, sandboxFs),
|
|
121
|
-
apiFiles: await selectTop(routeFiles, sandboxFs), // same files serve as API
|
|
122
|
-
authFiles: await selectTop(authFiles, sandboxFs),
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
// ----------------------------------------------------------------
|
|
126
|
-
// SvelteKit strategy
|
|
127
|
-
// ----------------------------------------------------------------
|
|
128
|
-
async function selectSvelteKit(sandboxFs) {
|
|
129
|
-
const allRouteFiles = await sandboxFs.findFiles("src/routes/**/*.{ts,js,svelte}");
|
|
130
|
-
const serverFiles = allRouteFiles.filter((f) => f.includes("+server") || f.includes("+page.server"));
|
|
131
|
-
const pageFiles = allRouteFiles.filter((f) => f.includes("+page.svelte") || f.includes("+page.ts"));
|
|
132
|
-
const authFiles = await collectAuthFiles(sandboxFs);
|
|
133
|
-
return {
|
|
134
|
-
routeFiles: await selectTop(pageFiles, sandboxFs),
|
|
135
|
-
apiFiles: await selectTop(serverFiles, sandboxFs),
|
|
136
|
-
authFiles: await selectTop(authFiles, sandboxFs),
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
// ----------------------------------------------------------------
|
|
140
|
-
// Nuxt strategy
|
|
141
|
-
// ----------------------------------------------------------------
|
|
142
|
-
async function selectNuxt(sandboxFs) {
|
|
143
|
-
const pageFiles = await sandboxFs.findFiles("pages/**/*.{vue,ts,js}");
|
|
144
|
-
const serverApiFiles = await sandboxFs.findFiles("server/api/**/*.{ts,js}");
|
|
145
|
-
const serverRouteFiles = await sandboxFs.findFiles("server/routes/**/*.{ts,js}");
|
|
146
|
-
const authFiles = await collectAuthFiles(sandboxFs);
|
|
147
|
-
return {
|
|
148
|
-
routeFiles: await selectTop(pageFiles, sandboxFs),
|
|
149
|
-
apiFiles: await selectTop([...serverApiFiles, ...serverRouteFiles], sandboxFs),
|
|
150
|
-
authFiles: await selectTop(authFiles, sandboxFs),
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
// ----------------------------------------------------------------
|
|
154
|
-
// Express / Fastify strategy (JS/TS backend)
|
|
155
|
-
// ----------------------------------------------------------------
|
|
156
|
-
async function selectExpressLike(sandboxFs, apiRoot) {
|
|
157
|
-
const routeDirs = ["routes", "api", "controllers", "handlers", "endpoints", apiRoot];
|
|
158
|
-
const gathered = [];
|
|
159
|
-
for (const dir of [...new Set(routeDirs)]) {
|
|
160
|
-
if (!(await sandboxFs.exists(dir)))
|
|
161
|
-
continue;
|
|
162
|
-
const files = await sandboxFs.findFiles(`${dir}/**/*.{ts,js}`);
|
|
163
|
-
gathered.push(...files);
|
|
164
|
-
}
|
|
165
|
-
// Fallback: any file with URL patterns
|
|
166
|
-
if (gathered.length === 0) {
|
|
167
|
-
const allTs = await sandboxFs.findFiles("src/**/*.{ts,js}");
|
|
168
|
-
for (const f of allTs) {
|
|
169
|
-
const content = await sandboxFs.readFile(f);
|
|
170
|
-
if (!content)
|
|
171
|
-
continue;
|
|
172
|
-
if (/["'`]\/api\//.test(content) ||
|
|
173
|
-
/["'`]\/v\d\//.test(content) ||
|
|
174
|
-
/\(req,\s*res\)|request:\s*Request/.test(content) ||
|
|
175
|
-
/router\.(get|post|put|patch|delete)\(/.test(content)) {
|
|
176
|
-
gathered.push(f);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
const authFiles = await collectAuthFiles(sandboxFs);
|
|
181
|
-
return {
|
|
182
|
-
routeFiles: [], // Express doesn't have separate route files
|
|
183
|
-
apiFiles: await selectTop([...new Set(gathered)], sandboxFs),
|
|
184
|
-
authFiles: await selectTop(authFiles, sandboxFs),
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
// ----------------------------------------------------------------
|
|
188
|
-
// FastAPI / Django strategy (Python)
|
|
189
|
-
// ----------------------------------------------------------------
|
|
190
|
-
async function selectPython(sandboxFs) {
|
|
191
|
-
const gathered = [];
|
|
192
|
-
// FastAPI: files with @router.{get,post,...} decorator
|
|
193
|
-
const pyFiles = await sandboxFs.findFiles("**/*.py");
|
|
194
|
-
for (const f of pyFiles) {
|
|
195
|
-
const content = await sandboxFs.readFile(f);
|
|
196
|
-
if (!content)
|
|
197
|
-
continue;
|
|
198
|
-
if (/@(router|app)\.(get|post|put|patch|delete)\(/.test(content) ||
|
|
199
|
-
f.includes("urls.py") // Django
|
|
200
|
-
) {
|
|
201
|
-
gathered.push(f);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
const authFiles = await collectAuthFiles(sandboxFs);
|
|
205
|
-
return {
|
|
206
|
-
routeFiles: [],
|
|
207
|
-
apiFiles: await selectTop([...new Set(gathered)], sandboxFs),
|
|
208
|
-
authFiles: await selectTop(authFiles, sandboxFs),
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
// ----------------------------------------------------------------
|
|
212
|
-
// Generic fallback strategy — unknown / messy codebases
|
|
213
|
-
// ----------------------------------------------------------------
|
|
214
|
-
async function selectGenericFallback(sandboxFs, apiRoot) {
|
|
215
|
-
const candidateDirs = ["routes", "api", "controllers", "handlers", "endpoints", apiRoot];
|
|
216
|
-
const gathered = [];
|
|
217
|
-
for (const dir of [...new Set(candidateDirs)]) {
|
|
218
|
-
if (!(await sandboxFs.exists(dir)))
|
|
219
|
-
continue;
|
|
220
|
-
const files = await sandboxFs.findFiles(`${dir}/**/*.{ts,tsx,js,jsx,py,rb}`);
|
|
221
|
-
gathered.push(...files);
|
|
222
|
-
}
|
|
223
|
-
// URL literal / handler signature fallback
|
|
224
|
-
if (gathered.length < MAX_FILES_PER_LIST) {
|
|
225
|
-
const srcFiles = await sandboxFs.findFiles("src/**/*.{ts,tsx,js,jsx}");
|
|
226
|
-
for (const f of srcFiles) {
|
|
227
|
-
if (gathered.includes(f))
|
|
228
|
-
continue;
|
|
229
|
-
const content = await sandboxFs.readFile(f);
|
|
230
|
-
if (!content)
|
|
231
|
-
continue;
|
|
232
|
-
if (/["'`]\/api\//.test(content) ||
|
|
233
|
-
/["'`]\/v\d\//.test(content) ||
|
|
234
|
-
/\(req,\s*res\)|request:\s*Request/.test(content)) {
|
|
235
|
-
gathered.push(f);
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
const authFiles = await collectAuthFiles(sandboxFs);
|
|
240
|
-
return {
|
|
241
|
-
routeFiles: [],
|
|
242
|
-
apiFiles: await selectTop([...new Set(gathered)], sandboxFs),
|
|
243
|
-
authFiles: await selectTop(authFiles, sandboxFs),
|
|
244
|
-
};
|
|
245
|
-
}
|
|
246
|
-
// ----------------------------------------------------------------
|
|
247
|
-
// selectFilesForFramework — flat file list for downstream consumers
|
|
248
|
-
// ----------------------------------------------------------------
|
|
249
|
-
/**
|
|
250
|
-
* Select the most relevant source files for a given project topology.
|
|
251
|
-
*
|
|
252
|
-
* Returns a flat, deduplicated list of relative file paths capped at
|
|
253
|
-
* `maxFiles`. Files are ordered by relevance: API routes first, then
|
|
254
|
-
* type definitions, then entry points / middleware.
|
|
255
|
-
*
|
|
256
|
-
* Delegates to framework-specific selectors (next, express, fastapi) or
|
|
257
|
-
* falls back to the generic size-ranked selector for unknown stacks.
|
|
258
|
-
*/
|
|
259
|
-
export async function selectFilesForFramework(topo, maxFiles = 30) {
|
|
260
|
-
const root = topo.projectRoot ?? process.cwd();
|
|
261
|
-
switch (topo.framework) {
|
|
262
|
-
case "next-app":
|
|
263
|
-
case "next-pages":
|
|
264
|
-
return selectNextFiles(root, maxFiles);
|
|
265
|
-
case "remix":
|
|
266
|
-
case "sveltekit":
|
|
267
|
-
case "nuxt":
|
|
268
|
-
case "vue3":
|
|
269
|
-
case "vite-react":
|
|
270
|
-
// These frameworks share the Express-like pattern for backend selection
|
|
271
|
-
return selectExpressFiles(root, maxFiles);
|
|
272
|
-
default:
|
|
273
|
-
if (topo.language === "python") {
|
|
274
|
-
return selectFastApiFiles(root, maxFiles);
|
|
275
|
-
}
|
|
276
|
-
return selectGenericFiles(root, maxFiles);
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
// ----------------------------------------------------------------
|
|
280
|
-
// buildReadList — main export
|
|
281
|
-
// ----------------------------------------------------------------
|
|
282
|
-
/**
|
|
283
|
-
* Build a bounded ReadList per agent from the project's topology.
|
|
284
|
-
*
|
|
285
|
-
* Given a TopoResult, builds a bounded ReadList for each agent.
|
|
286
|
-
* Each list is capped at MAX_FILES_PER_LIST entries, ranked by file size
|
|
287
|
-
* (smaller first — more focused files).
|
|
288
|
-
*
|
|
289
|
-
* Falls back to the generic strategy for unknown stacks. Generic fallback
|
|
290
|
-
* detections should get confidence < 0.6 automatically.
|
|
291
|
-
*/
|
|
292
|
-
export async function buildReadList(topo, sandboxFs) {
|
|
293
|
-
switch (topo.framework) {
|
|
294
|
-
case "next-app":
|
|
295
|
-
return selectNextApp(sandboxFs);
|
|
296
|
-
case "next-pages":
|
|
297
|
-
return selectNextPages(sandboxFs);
|
|
298
|
-
case "remix":
|
|
299
|
-
return selectRemix(sandboxFs);
|
|
300
|
-
case "sveltekit":
|
|
301
|
-
return selectSvelteKit(sandboxFs);
|
|
302
|
-
case "nuxt":
|
|
303
|
-
return selectNuxt(sandboxFs);
|
|
304
|
-
case "vite-react":
|
|
305
|
-
case "vue3":
|
|
306
|
-
// Vite/Vue — treat like Express for API (no built-in routing), empty routes
|
|
307
|
-
return selectExpressLike(sandboxFs, topo.apiRoot);
|
|
308
|
-
default:
|
|
309
|
-
// Python / Ruby / Go / unknown
|
|
310
|
-
if (topo.language === "python") {
|
|
311
|
-
return selectPython(sandboxFs);
|
|
312
|
-
}
|
|
313
|
-
return selectGenericFallback(sandboxFs, topo.apiRoot);
|
|
314
|
-
}
|
|
315
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Select files for Next.js projects (App Router + Pages Router).
|
|
3
|
-
*
|
|
4
|
-
* Priority:
|
|
5
|
-
* 1. API route files: app/api/.../route.ts, pages/api/...ts
|
|
6
|
-
* 2. Type files: types/...ts, lib/types.ts, src/types.ts
|
|
7
|
-
* 3. Auth middleware: middleware.ts, app/middleware.ts
|
|
8
|
-
*
|
|
9
|
-
* @param projectRoot Absolute project root path
|
|
10
|
-
* @param maxFiles Maximum total files to return (default 30)
|
|
11
|
-
*/
|
|
12
|
-
export declare function selectNextFiles(projectRoot: string, maxFiles?: number): Promise<string[]>;
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
// ============================================================
|
|
2
|
-
// @duct/sdk — Next.js File Selector
|
|
3
|
-
// Selects API routes, type files, and auth middleware for Next.js projects.
|
|
4
|
-
// ============================================================
|
|
5
|
-
import * as fs from "fs/promises";
|
|
6
|
-
import * as path from "path";
|
|
7
|
-
import { glob } from "glob";
|
|
8
|
-
const EXCLUDED_DIRS = new Set([
|
|
9
|
-
"node_modules",
|
|
10
|
-
".next",
|
|
11
|
-
"dist",
|
|
12
|
-
"build",
|
|
13
|
-
"out",
|
|
14
|
-
".turbo",
|
|
15
|
-
".vercel",
|
|
16
|
-
".cache",
|
|
17
|
-
"coverage",
|
|
18
|
-
]);
|
|
19
|
-
async function dirExists(dirPath) {
|
|
20
|
-
try {
|
|
21
|
-
const s = await fs.stat(dirPath);
|
|
22
|
-
return s.isDirectory();
|
|
23
|
-
}
|
|
24
|
-
catch {
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
async function fileExists(filePath) {
|
|
29
|
-
try {
|
|
30
|
-
await fs.access(filePath);
|
|
31
|
-
return true;
|
|
32
|
-
}
|
|
33
|
-
catch {
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Collect file paths matching a glob pattern under a project root.
|
|
39
|
-
* Filters out excluded directories and non-existent paths.
|
|
40
|
-
*/
|
|
41
|
-
async function globFiles(root, pattern) {
|
|
42
|
-
try {
|
|
43
|
-
const matches = await glob(pattern, {
|
|
44
|
-
cwd: root,
|
|
45
|
-
ignore: ["**/node_modules/**", "**/.next/**", "**/dist/**", "**/build/**", "**/out/**"],
|
|
46
|
-
nodir: true,
|
|
47
|
-
absolute: false,
|
|
48
|
-
});
|
|
49
|
-
return matches.sort();
|
|
50
|
-
}
|
|
51
|
-
catch {
|
|
52
|
-
return [];
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
async function getFileSize(filePath) {
|
|
56
|
-
try {
|
|
57
|
-
const s = await fs.stat(filePath);
|
|
58
|
-
return s.size;
|
|
59
|
-
}
|
|
60
|
-
catch {
|
|
61
|
-
return 0;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Sort files by priority (ascending size = more focused), limit to maxFiles.
|
|
66
|
-
*/
|
|
67
|
-
async function limitFiles(root, files, maxFiles) {
|
|
68
|
-
if (files.length <= maxFiles)
|
|
69
|
-
return files;
|
|
70
|
-
const sized = await Promise.all(files.map(async (f) => ({ f, size: await getFileSize(path.join(root, f)) })));
|
|
71
|
-
sized.sort((a, b) => a.size - b.size);
|
|
72
|
-
return sized.slice(0, maxFiles).map((s) => s.f);
|
|
73
|
-
}
|
|
74
|
-
// ----------------------------------------------------------------
|
|
75
|
-
// Next.js selector — main export
|
|
76
|
-
// ----------------------------------------------------------------
|
|
77
|
-
/**
|
|
78
|
-
* Select files for Next.js projects (App Router + Pages Router).
|
|
79
|
-
*
|
|
80
|
-
* Priority:
|
|
81
|
-
* 1. API route files: app/api/.../route.ts, pages/api/...ts
|
|
82
|
-
* 2. Type files: types/...ts, lib/types.ts, src/types.ts
|
|
83
|
-
* 3. Auth middleware: middleware.ts, app/middleware.ts
|
|
84
|
-
*
|
|
85
|
-
* @param projectRoot Absolute project root path
|
|
86
|
-
* @param maxFiles Maximum total files to return (default 30)
|
|
87
|
-
*/
|
|
88
|
-
export async function selectNextFiles(projectRoot, maxFiles = 30) {
|
|
89
|
-
const priority1 = [];
|
|
90
|
-
const priority2 = [];
|
|
91
|
-
const priority3 = [];
|
|
92
|
-
// ── Priority 1: API route files ─────────────────────────────
|
|
93
|
-
const appDir = (await dirExists(path.join(projectRoot, "src/app"))) ? "src/app" : "app";
|
|
94
|
-
const pagesDir = (await dirExists(path.join(projectRoot, "src/pages"))) ? "src/pages" : "pages";
|
|
95
|
-
const appApiRoutes = await globFiles(projectRoot, `${appDir}/api/**/route.{ts,tsx,js}`);
|
|
96
|
-
const pagesApiRoutes = await globFiles(projectRoot, `${pagesDir}/api/**/*.{ts,js}`);
|
|
97
|
-
priority1.push(...appApiRoutes, ...pagesApiRoutes);
|
|
98
|
-
// ── Priority 2: Type definition files ───────────────────────
|
|
99
|
-
const typeFiles = await globFiles(projectRoot, "types/**/*.ts");
|
|
100
|
-
const libTypes = await globFiles(projectRoot, "lib/types*.ts");
|
|
101
|
-
const srcTypes = await globFiles(projectRoot, "src/types*.ts");
|
|
102
|
-
const appTypes = await globFiles(projectRoot, `${appDir}/**/types*.{ts,tsx}`);
|
|
103
|
-
priority2.push(...typeFiles, ...libTypes, ...srcTypes, ...appTypes);
|
|
104
|
-
// ── Priority 3: Auth middleware ──────────────────────────────
|
|
105
|
-
const authCandidates = [
|
|
106
|
-
"middleware.ts",
|
|
107
|
-
"middleware.js",
|
|
108
|
-
"src/middleware.ts",
|
|
109
|
-
"src/middleware.js",
|
|
110
|
-
`${appDir}/middleware.ts`,
|
|
111
|
-
"auth.ts",
|
|
112
|
-
"auth.config.ts",
|
|
113
|
-
];
|
|
114
|
-
for (const candidate of authCandidates) {
|
|
115
|
-
if (await fileExists(path.join(projectRoot, candidate))) {
|
|
116
|
-
priority3.push(candidate);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
// ── Combine + deduplicate + limit ───────────────────────────
|
|
120
|
-
const seen = new Set();
|
|
121
|
-
const combined = [];
|
|
122
|
-
for (const f of [...priority1, ...priority2, ...priority3]) {
|
|
123
|
-
if (!seen.has(f)) {
|
|
124
|
-
seen.add(f);
|
|
125
|
-
combined.push(f);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
return limitFiles(projectRoot, combined, maxFiles);
|
|
129
|
-
}
|
|
130
|
-
void EXCLUDED_DIRS; // referenced implicitly via glob ignore patterns
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { describe, it } from "node:test";
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import { validateDuctConfigStrict } from "./config.js";
|
|
4
|
-
function minimalConfig(overrides = {}) {
|
|
5
|
-
return {
|
|
6
|
-
shellId: "shell_acme_prod",
|
|
7
|
-
product: {
|
|
8
|
-
name: "Acme",
|
|
9
|
-
description: "Test",
|
|
10
|
-
baseUrl: "https://app.acme.com",
|
|
11
|
-
},
|
|
12
|
-
auth: {
|
|
13
|
-
strategy: "session-cookie",
|
|
14
|
-
sessionFields: ["id"],
|
|
15
|
-
guestAllowed: false,
|
|
16
|
-
tokenExpirySeconds: 60,
|
|
17
|
-
},
|
|
18
|
-
routes: [],
|
|
19
|
-
actions: [
|
|
20
|
-
{
|
|
21
|
-
id: "refund_order",
|
|
22
|
-
name: "Refund",
|
|
23
|
-
description: "Refund an order",
|
|
24
|
-
method: "POST",
|
|
25
|
-
path: "/api/refunds",
|
|
26
|
-
agentAccessible: true,
|
|
27
|
-
sideEffects: true,
|
|
28
|
-
sensitivityLevel: "high",
|
|
29
|
-
params: [{ name: "amount", type: "number", required: true }],
|
|
30
|
-
requiresAuth: true,
|
|
31
|
-
validFrom: "2026-07-01T00:00:00.000Z",
|
|
32
|
-
validUntil: "2026-12-31T23:59:59.000Z",
|
|
33
|
-
approveIf: { op: "gt", param: "amount", value: 100 },
|
|
34
|
-
actionLimit: { type: "rate", maxPerWindow: 5, windowSeconds: 86400 },
|
|
35
|
-
},
|
|
36
|
-
],
|
|
37
|
-
deeplinks: [],
|
|
38
|
-
agentPermissions: {
|
|
39
|
-
defaultLevel: "none",
|
|
40
|
-
requireUserConsent: true,
|
|
41
|
-
consentActionScope: ["refund_order"],
|
|
42
|
-
},
|
|
43
|
-
...overrides,
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
describe("policy schema validation", () => {
|
|
47
|
-
it("accepts time-bound grants, approveIf, actionLimit, and consentActionScope", () => {
|
|
48
|
-
const result = validateDuctConfigStrict(minimalConfig());
|
|
49
|
-
assert.equal(result.ok, true);
|
|
50
|
-
});
|
|
51
|
-
it("rejects wildcard in consentActionScope", () => {
|
|
52
|
-
const result = validateDuctConfigStrict(minimalConfig({
|
|
53
|
-
agentPermissions: {
|
|
54
|
-
defaultLevel: "none",
|
|
55
|
-
requireUserConsent: true,
|
|
56
|
-
consentActionScope: ["*"],
|
|
57
|
-
},
|
|
58
|
-
}));
|
|
59
|
-
assert.equal(result.ok, false);
|
|
60
|
-
if (!result.ok) {
|
|
61
|
-
assert.ok(result.issues.some((i) => i.area.includes("consentActionScope")));
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
it("rejects approveIf referencing unknown params", () => {
|
|
65
|
-
const result = validateDuctConfigStrict(minimalConfig({
|
|
66
|
-
actions: [
|
|
67
|
-
{
|
|
68
|
-
...minimalConfig().actions[0],
|
|
69
|
-
approveIf: { op: "eq", param: "missing_param", value: 1 },
|
|
70
|
-
},
|
|
71
|
-
],
|
|
72
|
-
}));
|
|
73
|
-
assert.equal(result.ok, false);
|
|
74
|
-
if (!result.ok) {
|
|
75
|
-
assert.ok(result.issues.some((i) => i.issue.includes("unknown param")));
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
it("rejects validFrom after validUntil on actions", () => {
|
|
79
|
-
const result = validateDuctConfigStrict(minimalConfig({
|
|
80
|
-
actions: [
|
|
81
|
-
{
|
|
82
|
-
...minimalConfig().actions[0],
|
|
83
|
-
validFrom: "2026-12-31T23:59:59.000Z",
|
|
84
|
-
validUntil: "2026-07-01T00:00:00.000Z",
|
|
85
|
-
},
|
|
86
|
-
],
|
|
87
|
-
}));
|
|
88
|
-
assert.equal(result.ok, false);
|
|
89
|
-
});
|
|
90
|
-
it("rejects invalid actionLimit discriminator", () => {
|
|
91
|
-
const parsed = validateDuctConfigStrict(minimalConfig({
|
|
92
|
-
actions: [
|
|
93
|
-
{
|
|
94
|
-
...minimalConfig().actions[0],
|
|
95
|
-
actionLimit: { type: "count" },
|
|
96
|
-
},
|
|
97
|
-
],
|
|
98
|
-
}));
|
|
99
|
-
assert.equal(parsed.ok, false);
|
|
100
|
-
});
|
|
101
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|