@duct-sdk/sdk 0.1.12 → 0.2.1
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 +30 -0
- package/README.md +33 -22
- package/dist/adapters/next/shell.d.ts +1 -1
- package/dist/adapters/next/shell.js +4 -4
- package/dist/adapters/react/shell.d.ts +2 -2
- package/dist/adapters/react/shell.js +5 -5
- package/dist/adapters/react/use-page-context.d.ts +1 -1
- package/dist/cli/detectors/topology.d.ts +20 -0
- package/dist/cli/detectors/topology.js +107 -0
- package/dist/cli/generators/config.js +4 -4
- package/dist/cli/generators/shell.js +6 -6
- package/dist/cli/index.js +307 -10
- package/dist/cli/init.js +2 -3
- package/dist/cli/prompts/review.d.ts +25 -0
- package/dist/cli/prompts/review.js +108 -2
- package/dist/cli/selectors/express.d.ts +12 -0
- package/dist/cli/selectors/express.js +117 -0
- package/dist/cli/selectors/fastapi.d.ts +12 -0
- package/dist/cli/selectors/fastapi.js +122 -0
- package/dist/cli/selectors/generic.d.ts +10 -0
- package/dist/cli/selectors/generic.js +74 -0
- package/dist/cli/selectors/index.d.ts +15 -0
- package/dist/cli/selectors/index.js +41 -0
- package/dist/cli/selectors/next.d.ts +12 -0
- package/dist/cli/selectors/next.js +130 -0
- package/dist/core/action.js +0 -2
- package/dist/core/config.d.ts +5 -5
- package/dist/core/config.js +2 -2
- package/dist/core/endpoints.js +2 -2
- package/dist/core/status.d.ts +2 -2
- package/dist/core/status.js +4 -2
- package/dist/core/types.d.ts +10 -6
- package/package.json +6 -3
- package/dist/assets/logo.d.ts +0 -1
- package/dist/assets/logo.js +0 -1
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// @duct/sdk — Express / Fastify File Selector
|
|
3
|
+
// Selects route files, middleware, and entry points for Express-like projects.
|
|
4
|
+
// ============================================================
|
|
5
|
+
import * as fs from "fs/promises";
|
|
6
|
+
import * as path from "path";
|
|
7
|
+
import { glob } from "glob";
|
|
8
|
+
async function fileExists(filePath) {
|
|
9
|
+
try {
|
|
10
|
+
await fs.access(filePath);
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
async function globFiles(root, pattern) {
|
|
18
|
+
try {
|
|
19
|
+
const matches = await glob(pattern, {
|
|
20
|
+
cwd: root,
|
|
21
|
+
ignore: ["**/node_modules/**", "**/dist/**", "**/build/**"],
|
|
22
|
+
nodir: true,
|
|
23
|
+
absolute: false,
|
|
24
|
+
});
|
|
25
|
+
return matches.sort();
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async function getFileSize(filePath) {
|
|
32
|
+
try {
|
|
33
|
+
const s = await fs.stat(filePath);
|
|
34
|
+
return s.size;
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return 0;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async function limitFiles(root, files, maxFiles) {
|
|
41
|
+
if (files.length <= maxFiles)
|
|
42
|
+
return files;
|
|
43
|
+
const sized = await Promise.all(files.map(async (f) => ({ f, size: await getFileSize(path.join(root, f)) })));
|
|
44
|
+
sized.sort((a, b) => a.size - b.size);
|
|
45
|
+
return sized.slice(0, maxFiles).map((s) => s.f);
|
|
46
|
+
}
|
|
47
|
+
// ----------------------------------------------------------------
|
|
48
|
+
// Express selector — main export
|
|
49
|
+
// ----------------------------------------------------------------
|
|
50
|
+
/**
|
|
51
|
+
* Select files for Express / Fastify / Koa projects.
|
|
52
|
+
*
|
|
53
|
+
* Priority:
|
|
54
|
+
* 1. Route files: routes/...ts, src/routes/...ts
|
|
55
|
+
* 2. Middleware: middleware/...ts, src/middleware/...ts
|
|
56
|
+
* 3. Entry points: src/index.ts, index.ts, app.ts, server.ts
|
|
57
|
+
*
|
|
58
|
+
* @param projectRoot Absolute project root path
|
|
59
|
+
* @param maxFiles Maximum total files to return (default 30)
|
|
60
|
+
*/
|
|
61
|
+
export async function selectExpressFiles(projectRoot, maxFiles = 30) {
|
|
62
|
+
const priority1 = [];
|
|
63
|
+
const priority2 = [];
|
|
64
|
+
const priority3 = [];
|
|
65
|
+
// ── Priority 1: Route files ──────────────────────────────────
|
|
66
|
+
const routePatterns = [
|
|
67
|
+
"routes/**/*.{ts,js}",
|
|
68
|
+
"src/routes/**/*.{ts,js}",
|
|
69
|
+
"api/**/*.{ts,js}",
|
|
70
|
+
"src/api/**/*.{ts,js}",
|
|
71
|
+
];
|
|
72
|
+
for (const pat of routePatterns) {
|
|
73
|
+
const files = await globFiles(projectRoot, pat);
|
|
74
|
+
priority1.push(...files);
|
|
75
|
+
}
|
|
76
|
+
// ── Priority 2: Middleware ───────────────────────────────────
|
|
77
|
+
const middlewarePatterns = [
|
|
78
|
+
"middleware/**/*.{ts,js}",
|
|
79
|
+
"src/middleware/**/*.{ts,js}",
|
|
80
|
+
"middlewares/**/*.{ts,js}",
|
|
81
|
+
"src/middlewares/**/*.{ts,js}",
|
|
82
|
+
];
|
|
83
|
+
for (const pat of middlewarePatterns) {
|
|
84
|
+
const files = await globFiles(projectRoot, pat);
|
|
85
|
+
priority2.push(...files);
|
|
86
|
+
}
|
|
87
|
+
// ── Priority 3: Entry points ─────────────────────────────────
|
|
88
|
+
const entryCandidates = [
|
|
89
|
+
"src/index.ts",
|
|
90
|
+
"src/index.js",
|
|
91
|
+
"index.ts",
|
|
92
|
+
"index.js",
|
|
93
|
+
"app.ts",
|
|
94
|
+
"app.js",
|
|
95
|
+
"server.ts",
|
|
96
|
+
"server.js",
|
|
97
|
+
"src/app.ts",
|
|
98
|
+
"src/app.js",
|
|
99
|
+
"src/server.ts",
|
|
100
|
+
"src/server.js",
|
|
101
|
+
];
|
|
102
|
+
for (const candidate of entryCandidates) {
|
|
103
|
+
if (await fileExists(path.join(projectRoot, candidate))) {
|
|
104
|
+
priority3.push(candidate);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
// ── Combine + deduplicate + limit ───────────────────────────
|
|
108
|
+
const seen = new Set();
|
|
109
|
+
const combined = [];
|
|
110
|
+
for (const f of [...priority1, ...priority2, ...priority3]) {
|
|
111
|
+
if (!seen.has(f)) {
|
|
112
|
+
seen.add(f);
|
|
113
|
+
combined.push(f);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return limitFiles(projectRoot, combined, maxFiles);
|
|
117
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Select files for FastAPI / Django projects.
|
|
3
|
+
*
|
|
4
|
+
* Priority:
|
|
5
|
+
* 1. Router files: routers/...py, api/...py
|
|
6
|
+
* 2. Model/schema files: models.py, schemas.py, models/...py
|
|
7
|
+
* 3. Entry points: main.py, app.py, urls.py (Django)
|
|
8
|
+
*
|
|
9
|
+
* @param projectRoot Absolute project root path
|
|
10
|
+
* @param maxFiles Maximum total files to return (default 30)
|
|
11
|
+
*/
|
|
12
|
+
export declare function selectFastApiFiles(projectRoot: string, maxFiles?: number): Promise<string[]>;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// @duct/sdk — FastAPI / Django File Selector
|
|
3
|
+
// Selects router files, models, and entry points for Python API projects.
|
|
4
|
+
// ============================================================
|
|
5
|
+
import * as fs from "fs/promises";
|
|
6
|
+
import * as path from "path";
|
|
7
|
+
import { glob } from "glob";
|
|
8
|
+
async function fileExists(filePath) {
|
|
9
|
+
try {
|
|
10
|
+
await fs.access(filePath);
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
async function globFiles(root, pattern) {
|
|
18
|
+
try {
|
|
19
|
+
const matches = await glob(pattern, {
|
|
20
|
+
cwd: root,
|
|
21
|
+
ignore: ["**/__pycache__/**", "**/.venv/**", "**/venv/**", "**/dist/**"],
|
|
22
|
+
nodir: true,
|
|
23
|
+
absolute: false,
|
|
24
|
+
});
|
|
25
|
+
return matches.sort();
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async function getFileSize(filePath) {
|
|
32
|
+
try {
|
|
33
|
+
const s = await fs.stat(filePath);
|
|
34
|
+
return s.size;
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return 0;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async function limitFiles(root, files, maxFiles) {
|
|
41
|
+
if (files.length <= maxFiles)
|
|
42
|
+
return files;
|
|
43
|
+
const sized = await Promise.all(files.map(async (f) => ({ f, size: await getFileSize(path.join(root, f)) })));
|
|
44
|
+
sized.sort((a, b) => a.size - b.size);
|
|
45
|
+
return sized.slice(0, maxFiles).map((s) => s.f);
|
|
46
|
+
}
|
|
47
|
+
// ----------------------------------------------------------------
|
|
48
|
+
// FastAPI selector — main export
|
|
49
|
+
// ----------------------------------------------------------------
|
|
50
|
+
/**
|
|
51
|
+
* Select files for FastAPI / Django projects.
|
|
52
|
+
*
|
|
53
|
+
* Priority:
|
|
54
|
+
* 1. Router files: routers/...py, api/...py
|
|
55
|
+
* 2. Model/schema files: models.py, schemas.py, models/...py
|
|
56
|
+
* 3. Entry points: main.py, app.py, urls.py (Django)
|
|
57
|
+
*
|
|
58
|
+
* @param projectRoot Absolute project root path
|
|
59
|
+
* @param maxFiles Maximum total files to return (default 30)
|
|
60
|
+
*/
|
|
61
|
+
export async function selectFastApiFiles(projectRoot, maxFiles = 30) {
|
|
62
|
+
const priority1 = [];
|
|
63
|
+
const priority2 = [];
|
|
64
|
+
const priority3 = [];
|
|
65
|
+
// ── Priority 1: Router / API files ──────────────────────────
|
|
66
|
+
const routerPatterns = [
|
|
67
|
+
"routers/**/*.py",
|
|
68
|
+
"router/**/*.py",
|
|
69
|
+
"api/**/*.py",
|
|
70
|
+
"src/api/**/*.py",
|
|
71
|
+
"app/api/**/*.py",
|
|
72
|
+
"endpoints/**/*.py",
|
|
73
|
+
"views/**/*.py", // Django
|
|
74
|
+
"urls.py", // Django root urls
|
|
75
|
+
"**/urls.py", // Django app-level urls
|
|
76
|
+
];
|
|
77
|
+
for (const pat of routerPatterns) {
|
|
78
|
+
const files = await globFiles(projectRoot, pat);
|
|
79
|
+
priority1.push(...files);
|
|
80
|
+
}
|
|
81
|
+
// ── Priority 2: Model / Schema files ────────────────────────
|
|
82
|
+
const modelCandidates = [
|
|
83
|
+
"models.py",
|
|
84
|
+
"schemas.py",
|
|
85
|
+
"serializers.py", // Django REST
|
|
86
|
+
"src/models.py",
|
|
87
|
+
"src/schemas.py",
|
|
88
|
+
"app/models.py",
|
|
89
|
+
];
|
|
90
|
+
for (const candidate of modelCandidates) {
|
|
91
|
+
if (await fileExists(path.join(projectRoot, candidate))) {
|
|
92
|
+
priority2.push(candidate);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const modelDirFiles = await globFiles(projectRoot, "models/**/*.py");
|
|
96
|
+
const schemasDirFiles = await globFiles(projectRoot, "schemas/**/*.py");
|
|
97
|
+
priority2.push(...modelDirFiles, ...schemasDirFiles);
|
|
98
|
+
// ── Priority 3: Entry points ─────────────────────────────────
|
|
99
|
+
const entryCandidates = [
|
|
100
|
+
"main.py",
|
|
101
|
+
"app.py",
|
|
102
|
+
"application.py",
|
|
103
|
+
"wsgi.py",
|
|
104
|
+
"asgi.py",
|
|
105
|
+
"manage.py", // Django
|
|
106
|
+
];
|
|
107
|
+
for (const candidate of entryCandidates) {
|
|
108
|
+
if (await fileExists(path.join(projectRoot, candidate))) {
|
|
109
|
+
priority3.push(candidate);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
// ── Combine + deduplicate + limit ───────────────────────────
|
|
113
|
+
const seen = new Set();
|
|
114
|
+
const combined = [];
|
|
115
|
+
for (const f of [...priority1, ...priority2, ...priority3]) {
|
|
116
|
+
if (!seen.has(f)) {
|
|
117
|
+
seen.add(f);
|
|
118
|
+
combined.push(f);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return limitFiles(projectRoot, combined, maxFiles);
|
|
122
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic fallback file selector.
|
|
3
|
+
*
|
|
4
|
+
* Returns the top `maxFiles` .ts/.js/.py files sorted by file size descending
|
|
5
|
+
* (larger files are more likely to contain route/handler definitions).
|
|
6
|
+
*
|
|
7
|
+
* @param projectRoot Absolute project root path
|
|
8
|
+
* @param maxFiles Maximum total files to return (default 30)
|
|
9
|
+
*/
|
|
10
|
+
export declare function selectGenericFiles(projectRoot: string, maxFiles?: number): Promise<string[]>;
|
|
@@ -0,0 +1,74 @@
|
|
|
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,5 +1,9 @@
|
|
|
1
1
|
import type { SandboxFS } from "../fs/sandbox.js";
|
|
2
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";
|
|
3
7
|
/** Per-agent bounded file list, max MAX_FILES_PER_LIST entries each. */
|
|
4
8
|
export interface ReadList {
|
|
5
9
|
/** Files for the Route Agent — page files, layouts */
|
|
@@ -9,6 +13,17 @@ export interface ReadList {
|
|
|
9
13
|
/** Files for the Auth Agent — middleware, auth config, env examples */
|
|
10
14
|
authFiles: string[];
|
|
11
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[]>;
|
|
12
27
|
/**
|
|
13
28
|
* Build a bounded ReadList per agent from the project's topology.
|
|
14
29
|
*
|
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
// Builds a bounded ReadList per agent from a TopoResult.
|
|
4
4
|
// No LLM. Max MAX_FILES_PER_LIST files per agent list.
|
|
5
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";
|
|
6
14
|
const MAX_FILES_PER_LIST = 30;
|
|
7
15
|
// ----------------------------------------------------------------
|
|
8
16
|
// Ranking helpers
|
|
@@ -236,6 +244,39 @@ async function selectGenericFallback(sandboxFs, apiRoot) {
|
|
|
236
244
|
};
|
|
237
245
|
}
|
|
238
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
|
+
// ----------------------------------------------------------------
|
|
239
280
|
// buildReadList — main export
|
|
240
281
|
// ----------------------------------------------------------------
|
|
241
282
|
/**
|
|
@@ -0,0 +1,12 @@
|
|
|
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[]>;
|
|
@@ -0,0 +1,130 @@
|
|
|
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
|
package/dist/core/action.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
// ============================================================
|
|
2
2
|
// @duct/sdk — buildAction() factory
|
|
3
|
-
// Mirrors the buildTool() pattern from the miniclaude reference.
|
|
4
3
|
// Fail-closed defaults: denies agents when !agentAccessible,
|
|
5
4
|
// denies side-effects without user_consent_token, upgrades
|
|
6
5
|
// high/critical sensitivity to 'ask'.
|
|
7
|
-
// See duct-technical-spec.md §13.1
|
|
8
6
|
// ============================================================
|
|
9
7
|
// ----------------------------------------------------------------
|
|
10
8
|
// checkActionPermission — three-tier rule model
|
package/dist/core/config.d.ts
CHANGED
|
@@ -263,20 +263,20 @@ export declare const DuctConfigSchema: z.ZodObject<{
|
|
|
263
263
|
agentPermissions: z.ZodObject<{
|
|
264
264
|
defaultLevel: z.ZodEnum<["none", "read", "write", "admin"]>;
|
|
265
265
|
actionOverrides: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodEnum<["none", "read", "write", "admin"]>>>;
|
|
266
|
-
|
|
266
|
+
allowedCallers: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
267
267
|
requireUserConsent: z.ZodBoolean;
|
|
268
268
|
allowedActions: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
269
269
|
}, "strip", z.ZodTypeAny, {
|
|
270
270
|
defaultLevel: "none" | "read" | "write" | "admin";
|
|
271
271
|
requireUserConsent: boolean;
|
|
272
272
|
actionOverrides?: Record<string, "none" | "read" | "write" | "admin"> | undefined;
|
|
273
|
-
|
|
273
|
+
allowedCallers?: string[] | undefined;
|
|
274
274
|
allowedActions?: string[] | undefined;
|
|
275
275
|
}, {
|
|
276
276
|
defaultLevel: "none" | "read" | "write" | "admin";
|
|
277
277
|
requireUserConsent: boolean;
|
|
278
278
|
actionOverrides?: Record<string, "none" | "read" | "write" | "admin"> | undefined;
|
|
279
|
-
|
|
279
|
+
allowedCallers?: string[] | undefined;
|
|
280
280
|
allowedActions?: string[] | undefined;
|
|
281
281
|
}>;
|
|
282
282
|
widget: z.ZodOptional<z.ZodObject<{
|
|
@@ -381,7 +381,7 @@ export declare const DuctConfigSchema: z.ZodObject<{
|
|
|
381
381
|
defaultLevel: "none" | "read" | "write" | "admin";
|
|
382
382
|
requireUserConsent: boolean;
|
|
383
383
|
actionOverrides?: Record<string, "none" | "read" | "write" | "admin"> | undefined;
|
|
384
|
-
|
|
384
|
+
allowedCallers?: string[] | undefined;
|
|
385
385
|
allowedActions?: string[] | undefined;
|
|
386
386
|
};
|
|
387
387
|
widget?: {
|
|
@@ -414,7 +414,7 @@ export declare const DuctConfigSchema: z.ZodObject<{
|
|
|
414
414
|
defaultLevel: "none" | "read" | "write" | "admin";
|
|
415
415
|
requireUserConsent: boolean;
|
|
416
416
|
actionOverrides?: Record<string, "none" | "read" | "write" | "admin"> | undefined;
|
|
417
|
-
|
|
417
|
+
allowedCallers?: string[] | undefined;
|
|
418
418
|
allowedActions?: string[] | undefined;
|
|
419
419
|
};
|
|
420
420
|
routes?: {
|
package/dist/core/config.js
CHANGED
|
@@ -121,7 +121,7 @@ const AgentPermissionLevelSchema = z.enum([
|
|
|
121
121
|
const AgentPermissionsSchema = z.object({
|
|
122
122
|
defaultLevel: AgentPermissionLevelSchema,
|
|
123
123
|
actionOverrides: z.record(AgentPermissionLevelSchema).optional(),
|
|
124
|
-
|
|
124
|
+
allowedCallers: z.array(z.string()).optional(),
|
|
125
125
|
requireUserConsent: z.boolean(),
|
|
126
126
|
allowedActions: z.array(z.string()).optional(),
|
|
127
127
|
});
|
|
@@ -193,7 +193,7 @@ export function defineDuctConfig(config) {
|
|
|
193
193
|
const formatted = result.error.errors
|
|
194
194
|
.map((e) => ` • [${e.path.join(".")}] ${e.message}`)
|
|
195
195
|
.join("\n");
|
|
196
|
-
throw new Error(`Invalid Duct configuration:\n${formatted}\n\nSee
|
|
196
|
+
throw new Error(`Invalid Duct configuration:\n${formatted}\n\nSee your Duct docs /config reference for details.`);
|
|
197
197
|
}
|
|
198
198
|
// Cross-validate: deeplink target routes must exist in routes list
|
|
199
199
|
const routePaths = new Set(result.data.routes.map((r) => r.path));
|
package/dist/core/endpoints.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
//
|
|
7
7
|
// Override any individual service URL explicitly if needed:
|
|
8
8
|
// DUCT_AUTH_URL — auth service (default: {base}/auth or :3001)
|
|
9
|
-
// DUCT_API_URL —
|
|
9
|
+
// DUCT_API_URL — Duct API (default: {base}/api or :3002)
|
|
10
10
|
// DUCT_SHELL_URL — shell runtime (default: {base}/shell or :3000)
|
|
11
11
|
// DUCT_REGISTRY_URL — shell registry (default: {base}/registry or :3003)
|
|
12
12
|
// DUCT_DASHBOARD_URL— dashboard (default: {base}/dash or :3004)
|
|
@@ -85,7 +85,7 @@ export function getActiveAuthBase(profile) {
|
|
|
85
85
|
return candidates[0] ?? "http://localhost:3001";
|
|
86
86
|
}
|
|
87
87
|
export function getManifestApiBase(profile) {
|
|
88
|
-
// Manifest
|
|
88
|
+
// Manifest is served from the Duct API base
|
|
89
89
|
const bases = getManifestApiBases(profile);
|
|
90
90
|
return bases[0] ?? "http://localhost:3002";
|
|
91
91
|
}
|
package/dist/core/status.d.ts
CHANGED
|
@@ -15,8 +15,8 @@ export interface ShellStatus {
|
|
|
15
15
|
}
|
|
16
16
|
export interface CheckShellStatusOptions {
|
|
17
17
|
/**
|
|
18
|
-
* Override the
|
|
19
|
-
* Defaults to
|
|
18
|
+
* Override the Duct API base URL.
|
|
19
|
+
* Defaults to DUCT_API_URL (or DUCT_AGENT_PROXY_URL) → http://localhost:3002
|
|
20
20
|
*/
|
|
21
21
|
agentProxyUrl?: string;
|
|
22
22
|
/** Fetch timeout in milliseconds. Defaults to 5000. */
|