swarmdo 1.10.0 → 1.12.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/.claude/helpers/statusline.cjs +1 -1
- package/README.md +4 -3
- package/package.json +1 -1
- package/v3/@swarmdo/cli/dist/src/codegraph/codegraph.d.ts +34 -0
- package/v3/@swarmdo/cli/dist/src/codegraph/codegraph.js +98 -2
- package/v3/@swarmdo/cli/dist/src/commands/codegraph.js +85 -11
- package/v3/@swarmdo/cli/dist/src/commands/env.d.ts +16 -0
- package/v3/@swarmdo/cli/dist/src/commands/env.js +137 -0
- package/v3/@swarmdo/cli/dist/src/commands/index.js +6 -3
- package/v3/@swarmdo/cli/dist/src/env/env.d.ts +49 -0
- package/v3/@swarmdo/cli/dist/src/env/env.js +103 -0
- package/v3/@swarmdo/cli/dist/src/mcp-client.js +2 -0
- package/v3/@swarmdo/cli/dist/src/mcp-tools/codegraph-tools.js +56 -1
- package/v3/@swarmdo/cli/dist/src/mcp-tools/env-tools.d.ts +12 -0
- package/v3/@swarmdo/cli/dist/src/mcp-tools/env-tools.js +62 -0
- package/v3/@swarmdo/cli/dist/src/mcp-tools/index.d.ts +1 -0
- package/v3/@swarmdo/cli/dist/src/mcp-tools/index.js +1 -0
- package/v3/@swarmdo/cli/dist/src/mcp-tools/profiles.js +1 -0
- package/v3/@swarmdo/cli/package.json +1 -1
|
@@ -515,7 +515,7 @@ function getCostFromStdin() {
|
|
|
515
515
|
// misses, the displayed version is meaningful (matches what the user
|
|
516
516
|
// installed), not a stale hard-coded string.
|
|
517
517
|
function getPkgVersion() {
|
|
518
|
-
let ver = '1.
|
|
518
|
+
let ver = '1.12.0';
|
|
519
519
|
try {
|
|
520
520
|
const home = os.homedir();
|
|
521
521
|
const pkgPaths = [
|
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
|
|
3
|
-
[](https://swarmdo.com)
|
|
4
4
|
|
|
5
|
-
[](https://img.shields.io/badge/npx%20swarmdo-v1.12.0-cb3837?style=for-the-badge&logo=npm&logoColor=white)](https://github.com/SwarmDo/swarmdo/releases)
|
|
6
6
|
[](https://github.com/SwarmDo/swarmdo/blob/main/LICENSE)
|
|
7
7
|
[](https://swarmdo.com)
|
|
8
8
|
[](https://github.com/SwarmDo/swarmdo)
|
|
@@ -277,9 +277,10 @@ The recent release train added a full day-to-day operations layer around the swa
|
|
|
277
277
|
| `swarmdo worktree` (alias `wt`) | **Parallel-agent isolation** on git worktrees — add / list / diff / merge / remove |
|
|
278
278
|
| `swarmdo transcript` (alias `tx`) | **Export any Claude Code session** to clean markdown — system noise stripped, ready to share; `transcript search <query>` full-text-searches every session |
|
|
279
279
|
| `swarmdo compact` | **Compress noisy command output** before it reaches an LLM — strip ANSI, collapse repeats, fold `node_modules` stack frames, window long logs. `npm test 2>&1 \| swarmdo compact` or `swarmdo compact -- npm test` (exit code propagates). Deterministic, zero tokens |
|
|
280
|
-
| `swarmdo codegraph` (alias `cg`) | **Queryable symbol index** — `codegraph index` scans TS/JS for exported symbols; `query <name>` (with `--fuzzy`/`--kind`) and `file <path>` answer "where is X defined / what does this file export" from `.swarm/codegraph.json` instead of grep+read round-trips. 1,
|
|
280
|
+
| `swarmdo codegraph` (alias `cg`) | **Queryable symbol index** — `codegraph index` scans TS/JS for exported symbols; `query <name>` (with `--fuzzy`/`--kind`) and `file <path>` answer "where is X defined / what does this file export" from `.swarm/codegraph.json` instead of grep+read round-trips. `codegraph importers <file>` shows reverse deps ("what breaks if I change this"); `codegraph imports <file>` shows a file's dependencies. 1,786 symbols + import graph across 296 files in <1s. Also MCP tools (`codegraph_query`/`file`/`imports`/`importers`/`index`/`stats`) so agents query the graph in-session |
|
|
281
281
|
| `swarmdo redact` | **Mask secrets before they reach an LLM/log/memory** — detect API keys, tokens, and private keys (gitleaks-style rule catalog + Shannon-entropy fallback) and redact them. Stdin filter (`cat deploy.log \| swarmdo redact`), command-wrap (`swarmdo redact -- npm run deploy`), or `--scan` to fail CI on any secret. Also MCP tools (`redact_text`/`redact_scan`). Deterministic, zero tokens |
|
|
282
282
|
| `swarmdo pack` | **Bundle a repo into one AI-context blob** — walk the tree (respects `.gitignore` + glob `--include`/`--exclude`, skips binaries/node_modules), emit markdown/xml/json/plain with a directory tree and per-file + total token estimates. `swarmdo pack --tokens` for a budget breakdown; `--redact` masks secrets first. Deterministic |
|
|
283
|
+
| `swarmdo env` | **Catch env-var drift before deploy** — statically scan code for `process.env.X` / `import.meta.env.X` / `Deno.env.get` / `os.getenv` references and reconcile against `.env` and `.env.example`: reports **missing** (used but undeclared), **unused**, and **undocumented**. `--ci` exits 1 on missing vars. Also an MCP tool (`env_check`). Deterministic |
|
|
283
284
|
| `swarmdo integrations` (alias `integrate`) | **Use swarmdo from Codex CLI, GitHub Copilot CLI, and pi** — one command wires AGENTS.md + each CLI's MCP config (idempotent, dry-run first, never touches your Claude Code setup) |
|
|
284
285
|
| OpenRouter model pool | **Let swarms pick from any models you configure** — declare tier-mapped OpenRouter models in `swarmdo.config.json`; the router Thompson-samples among them per task and the execution layer dispatches the winner |
|
|
285
286
|
| `swarmdo changelog` (alias `notes`) | **Release notes from conventional commits** — `--out NOTES.md` feeds `gh release create --notes-file` |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "swarmdo",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0",
|
|
4
4
|
"description": "Swarmdo - Enterprise AI agent orchestration for Claude Code. Deploy 60+ specialized agents in coordinated swarms with self-learning, fault-tolerant consensus, vector memory, and MCP integration",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -21,13 +21,39 @@ export interface CodeSymbol {
|
|
|
21
21
|
/** The trimmed declaration line (signature), truncated for storage. */
|
|
22
22
|
signature: string;
|
|
23
23
|
}
|
|
24
|
+
/** A dependency edge: `from` imports module `spec`, resolved to a repo file when relative. */
|
|
25
|
+
export interface ImportEdge {
|
|
26
|
+
/** repo-relative file containing the import */
|
|
27
|
+
from: string;
|
|
28
|
+
/** the raw module specifier as written, e.g. './store.js' or 'node:fs' */
|
|
29
|
+
spec: string;
|
|
30
|
+
/** repo-relative file the spec resolves to, or null for external/unresolved */
|
|
31
|
+
resolved: string | null;
|
|
32
|
+
/** 1-based line of the import */
|
|
33
|
+
line: number;
|
|
34
|
+
}
|
|
24
35
|
export interface CodeIndex {
|
|
25
36
|
/** Repo-relative file → symbols declared in it. */
|
|
26
37
|
symbols: CodeSymbol[];
|
|
38
|
+
/** Dependency edges between files (relative imports resolved; externals kept unresolved). */
|
|
39
|
+
imports: ImportEdge[];
|
|
27
40
|
fileCount: number;
|
|
28
41
|
}
|
|
29
42
|
/** Extract exported symbols from one source file. Pure. */
|
|
30
43
|
export declare function extractSymbols(source: string, file: string): CodeSymbol[];
|
|
44
|
+
/** Extract the raw import specifiers from one source file. Pure. */
|
|
45
|
+
export declare function extractImports(source: string, file: string): Array<{
|
|
46
|
+
from: string;
|
|
47
|
+
spec: string;
|
|
48
|
+
line: number;
|
|
49
|
+
}>;
|
|
50
|
+
/**
|
|
51
|
+
* Resolve a spec to a repo-relative file in `fileSet`, or null. Only relative
|
|
52
|
+
* specs (`.`/`..`) resolve; bare specifiers (packages, aliases, `node:`) are
|
|
53
|
+
* external → null. Tries the path as-is, common extensions, and `/index.*`,
|
|
54
|
+
* and rewrites a `.js` spec to its `.ts` sibling (TS ESM convention).
|
|
55
|
+
*/
|
|
56
|
+
export declare function resolveImport(fromFile: string, spec: string, fileSet: Set<string>): string | null;
|
|
31
57
|
/** Build an index from already-read files. Pure. */
|
|
32
58
|
export declare function buildIndex(files: Array<{
|
|
33
59
|
file: string;
|
|
@@ -43,10 +69,18 @@ export interface QueryOptions {
|
|
|
43
69
|
export declare function queryIndex(index: CodeIndex, name: string, opts?: QueryOptions): CodeSymbol[];
|
|
44
70
|
/** Symbols declared in a specific file (exact repo-relative path). Pure. */
|
|
45
71
|
export declare function symbolsInFile(index: CodeIndex, file: string): CodeSymbol[];
|
|
72
|
+
/** Edges FROM a file — what it imports (resolved repo files + external specs). Pure. */
|
|
73
|
+
export declare function fileImports(index: CodeIndex, file: string): ImportEdge[];
|
|
74
|
+
/** Edges TO a file — who imports it ("what breaks if I change this"). Pure. */
|
|
75
|
+
export declare function fileImporters(index: CodeIndex, file: string): ImportEdge[];
|
|
46
76
|
export interface IndexStats {
|
|
47
77
|
files: number;
|
|
48
78
|
symbols: number;
|
|
49
79
|
byKind: Record<string, number>;
|
|
80
|
+
/** total import edges */
|
|
81
|
+
imports: number;
|
|
82
|
+
/** edges resolved to an in-repo file (vs external packages) */
|
|
83
|
+
internalImports: number;
|
|
50
84
|
}
|
|
51
85
|
/** Summary counts for the index. Pure. */
|
|
52
86
|
export declare function indexStats(index: CodeIndex): IndexStats;
|
|
@@ -57,15 +57,96 @@ export function extractSymbols(source, file) {
|
|
|
57
57
|
}
|
|
58
58
|
return out;
|
|
59
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Module specifiers on a line, from any of: `import … from 'x'`,
|
|
62
|
+
* `export … from 'x'`, side-effect `import 'x'`, `require('x')`, and dynamic
|
|
63
|
+
* `import('x')`. Line-based like the symbol matchers; captures every spec on
|
|
64
|
+
* the line (dynamic imports can be mid-line).
|
|
65
|
+
*/
|
|
66
|
+
const IMPORT_RES = [
|
|
67
|
+
/\bfrom\s*['"]([^'"]+)['"]/g, // import/export … from '…'
|
|
68
|
+
/\bimport\s*['"]([^'"]+)['"]/g, // side-effect import '…'
|
|
69
|
+
/\bimport\s*\(\s*['"]([^'"]+)['"]\s*\)/g, // dynamic import('…')
|
|
70
|
+
/\brequire\s*\(\s*['"]([^'"]+)['"]\s*\)/g, // require('…')
|
|
71
|
+
];
|
|
72
|
+
/** Extract the raw import specifiers from one source file. Pure. */
|
|
73
|
+
export function extractImports(source, file) {
|
|
74
|
+
const out = [];
|
|
75
|
+
const lines = source.split('\n');
|
|
76
|
+
for (let i = 0; i < lines.length; i++) {
|
|
77
|
+
const line = lines[i];
|
|
78
|
+
if (!/\b(?:from|import|require)\b/.test(line))
|
|
79
|
+
continue;
|
|
80
|
+
const seen = new Set();
|
|
81
|
+
for (const re of IMPORT_RES) {
|
|
82
|
+
re.lastIndex = 0;
|
|
83
|
+
let m;
|
|
84
|
+
while ((m = re.exec(line)) !== null) {
|
|
85
|
+
const spec = m[1];
|
|
86
|
+
if (seen.has(spec))
|
|
87
|
+
continue; // same spec caught by two patterns on one line
|
|
88
|
+
seen.add(spec);
|
|
89
|
+
out.push({ from: file, spec, line: i + 1 });
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return out;
|
|
94
|
+
}
|
|
95
|
+
/** Normalize a relative spec against the importing file's dir → repo-relative POSIX path (no extension). */
|
|
96
|
+
function joinRelative(fromFile, spec) {
|
|
97
|
+
const parts = fromFile.includes('/') ? fromFile.slice(0, fromFile.lastIndexOf('/')).split('/') : [];
|
|
98
|
+
for (const seg of spec.split('/')) {
|
|
99
|
+
if (seg === '' || seg === '.')
|
|
100
|
+
continue;
|
|
101
|
+
if (seg === '..')
|
|
102
|
+
parts.pop();
|
|
103
|
+
else
|
|
104
|
+
parts.push(seg);
|
|
105
|
+
}
|
|
106
|
+
return parts.join('/');
|
|
107
|
+
}
|
|
108
|
+
const RESOLVE_EXTS = ['', '.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs', '.mts', '.cts'];
|
|
109
|
+
/**
|
|
110
|
+
* Resolve a spec to a repo-relative file in `fileSet`, or null. Only relative
|
|
111
|
+
* specs (`.`/`..`) resolve; bare specifiers (packages, aliases, `node:`) are
|
|
112
|
+
* external → null. Tries the path as-is, common extensions, and `/index.*`,
|
|
113
|
+
* and rewrites a `.js` spec to its `.ts` sibling (TS ESM convention).
|
|
114
|
+
*/
|
|
115
|
+
export function resolveImport(fromFile, spec, fileSet) {
|
|
116
|
+
if (!spec.startsWith('.'))
|
|
117
|
+
return null;
|
|
118
|
+
const base = joinRelative(fromFile, spec);
|
|
119
|
+
const bases = [base];
|
|
120
|
+
const jsExt = base.match(/\.(js|jsx|mjs|cjs)$/);
|
|
121
|
+
if (jsExt)
|
|
122
|
+
bases.push(base.slice(0, -jsExt[0].length)); // ./x.js → try ./x(.ts…)
|
|
123
|
+
for (const b of bases) {
|
|
124
|
+
for (const ext of RESOLVE_EXTS) {
|
|
125
|
+
if (fileSet.has(b + ext))
|
|
126
|
+
return b + ext;
|
|
127
|
+
}
|
|
128
|
+
for (const ext of RESOLVE_EXTS.slice(1)) {
|
|
129
|
+
if (fileSet.has(b + '/index' + ext))
|
|
130
|
+
return b + '/index' + ext;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
60
135
|
/** Build an index from already-read files. Pure. */
|
|
61
136
|
export function buildIndex(files) {
|
|
62
137
|
const symbols = [];
|
|
138
|
+
const fileSet = new Set(files.map((f) => f.file));
|
|
139
|
+
const imports = [];
|
|
63
140
|
for (const { file, source } of files) {
|
|
64
141
|
symbols.push(...extractSymbols(source, file));
|
|
142
|
+
for (const imp of extractImports(source, file)) {
|
|
143
|
+
imports.push({ ...imp, resolved: resolveImport(imp.from, imp.spec, fileSet) });
|
|
144
|
+
}
|
|
65
145
|
}
|
|
66
146
|
// Stable order: file, then line.
|
|
67
147
|
symbols.sort((a, b) => (a.file < b.file ? -1 : a.file > b.file ? 1 : a.line - b.line));
|
|
68
|
-
|
|
148
|
+
imports.sort((a, b) => (a.from < b.from ? -1 : a.from > b.from ? 1 : a.line - b.line));
|
|
149
|
+
return { symbols, imports, fileCount: files.length };
|
|
69
150
|
}
|
|
70
151
|
/** Look up symbols by name. Pure. */
|
|
71
152
|
export function queryIndex(index, name, opts = {}) {
|
|
@@ -80,11 +161,26 @@ export function queryIndex(index, name, opts = {}) {
|
|
|
80
161
|
export function symbolsInFile(index, file) {
|
|
81
162
|
return index.symbols.filter((s) => s.file === file);
|
|
82
163
|
}
|
|
164
|
+
/** Edges FROM a file — what it imports (resolved repo files + external specs). Pure. */
|
|
165
|
+
export function fileImports(index, file) {
|
|
166
|
+
return (index.imports ?? []).filter((e) => e.from === file);
|
|
167
|
+
}
|
|
168
|
+
/** Edges TO a file — who imports it ("what breaks if I change this"). Pure. */
|
|
169
|
+
export function fileImporters(index, file) {
|
|
170
|
+
return (index.imports ?? []).filter((e) => e.resolved === file);
|
|
171
|
+
}
|
|
83
172
|
/** Summary counts for the index. Pure. */
|
|
84
173
|
export function indexStats(index) {
|
|
85
174
|
const byKind = {};
|
|
86
175
|
for (const s of index.symbols)
|
|
87
176
|
byKind[s.kind] = (byKind[s.kind] ?? 0) + 1;
|
|
88
|
-
|
|
177
|
+
const imports = index.imports ?? [];
|
|
178
|
+
return {
|
|
179
|
+
files: index.fileCount,
|
|
180
|
+
symbols: index.symbols.length,
|
|
181
|
+
byKind,
|
|
182
|
+
imports: imports.length,
|
|
183
|
+
internalImports: imports.filter((e) => e.resolved !== null).length,
|
|
184
|
+
};
|
|
89
185
|
}
|
|
90
186
|
//# sourceMappingURL=codegraph.js.map
|
|
@@ -13,11 +13,15 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import * as path from 'node:path';
|
|
15
15
|
import { output } from '../output.js';
|
|
16
|
-
import { queryIndex, symbolsInFile, indexStats, } from '../codegraph/codegraph.js';
|
|
16
|
+
import { queryIndex, symbolsInFile, indexStats, fileImports, fileImporters, } from '../codegraph/codegraph.js';
|
|
17
17
|
import { INDEX_REL, scanRepo, saveIndex, loadIndex } from '../codegraph/store.js';
|
|
18
18
|
function fmtSymbol(s) {
|
|
19
19
|
return `${s.file}:${s.line} ${output.dim(`[${s.kind}]`)} ${s.signature}`;
|
|
20
20
|
}
|
|
21
|
+
/** Accept an absolute or cwd-relative path; return the repo-relative key. */
|
|
22
|
+
function relKey(root, arg) {
|
|
23
|
+
return path.relative(root, path.resolve(root, arg)).split(path.sep).join('/');
|
|
24
|
+
}
|
|
21
25
|
const indexCommand = {
|
|
22
26
|
name: 'index',
|
|
23
27
|
description: 'Scan the tree for exported symbols and persist the index',
|
|
@@ -124,32 +128,102 @@ const statsCommand = {
|
|
|
124
128
|
output.printJson(stats);
|
|
125
129
|
return { success: true, data: stats };
|
|
126
130
|
}
|
|
127
|
-
output.writeln(output.bold(`codegraph: ${stats.symbols} symbols, ${stats.files} files`));
|
|
131
|
+
output.writeln(output.bold(`codegraph: ${stats.symbols} symbols, ${stats.files} files, ${stats.imports} imports (${stats.internalImports} internal)`));
|
|
128
132
|
output.printList(Object.entries(stats.byKind).sort((a, b) => b[1] - a[1]).map(([k, n]) => `${k}: ${n}`));
|
|
129
133
|
return { success: true, exitCode: 0 };
|
|
130
134
|
},
|
|
131
135
|
};
|
|
136
|
+
const importsCommand = {
|
|
137
|
+
name: 'imports',
|
|
138
|
+
description: 'What a file imports — resolved repo files + external packages',
|
|
139
|
+
options: [
|
|
140
|
+
{ name: 'internal', description: 'only edges resolved to a repo file (hide external packages)', type: 'boolean', default: false },
|
|
141
|
+
{ name: 'json', description: 'machine-readable output', type: 'boolean', default: false },
|
|
142
|
+
],
|
|
143
|
+
action: async (ctx) => {
|
|
144
|
+
const root = ctx.cwd || process.cwd();
|
|
145
|
+
const arg = ctx.args[0];
|
|
146
|
+
if (!arg) {
|
|
147
|
+
output.printError('Usage: swarmdo codegraph imports <path>');
|
|
148
|
+
return { success: false, exitCode: 1 };
|
|
149
|
+
}
|
|
150
|
+
const index = loadIndex(root);
|
|
151
|
+
if (!index) {
|
|
152
|
+
output.printError(`no index — run \`swarmdo codegraph index\` first`);
|
|
153
|
+
return { success: false, exitCode: 1 };
|
|
154
|
+
}
|
|
155
|
+
let edges = fileImports(index, relKey(root, arg));
|
|
156
|
+
if (ctx.flags.internal === true)
|
|
157
|
+
edges = edges.filter((e) => e.resolved !== null);
|
|
158
|
+
if (ctx.flags.json === true) {
|
|
159
|
+
output.printJson(edges);
|
|
160
|
+
return { success: true, data: edges };
|
|
161
|
+
}
|
|
162
|
+
if (edges.length === 0) {
|
|
163
|
+
output.writeln(output.dim(`no imports in ${relKey(root, arg)} (indexed?)`));
|
|
164
|
+
return { success: true, exitCode: 0 };
|
|
165
|
+
}
|
|
166
|
+
for (const e of edges) {
|
|
167
|
+
output.writeln(` ${e.line} ${e.spec}${e.resolved ? output.dim(` → ${e.resolved}`) : output.dim(' (external)')}`);
|
|
168
|
+
}
|
|
169
|
+
return { success: true, exitCode: 0 };
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
const importersCommand = {
|
|
173
|
+
name: 'importers',
|
|
174
|
+
aliases: ['rdeps'],
|
|
175
|
+
description: 'Who imports a file — reverse deps ("what breaks if I change this")',
|
|
176
|
+
options: [{ name: 'json', description: 'machine-readable output', type: 'boolean', default: false }],
|
|
177
|
+
action: async (ctx) => {
|
|
178
|
+
const root = ctx.cwd || process.cwd();
|
|
179
|
+
const arg = ctx.args[0];
|
|
180
|
+
if (!arg) {
|
|
181
|
+
output.printError('Usage: swarmdo codegraph importers <path>');
|
|
182
|
+
return { success: false, exitCode: 1 };
|
|
183
|
+
}
|
|
184
|
+
const index = loadIndex(root);
|
|
185
|
+
if (!index) {
|
|
186
|
+
output.printError(`no index — run \`swarmdo codegraph index\` first`);
|
|
187
|
+
return { success: false, exitCode: 1 };
|
|
188
|
+
}
|
|
189
|
+
const edges = fileImporters(index, relKey(root, arg));
|
|
190
|
+
if (ctx.flags.json === true) {
|
|
191
|
+
output.printJson(edges);
|
|
192
|
+
return { success: true, data: edges };
|
|
193
|
+
}
|
|
194
|
+
if (edges.length === 0) {
|
|
195
|
+
output.writeln(output.dim(`nothing imports ${relKey(root, arg)} (leaf, entrypoint, or not indexed)`));
|
|
196
|
+
return { success: true, exitCode: 0 };
|
|
197
|
+
}
|
|
198
|
+
for (const e of edges)
|
|
199
|
+
output.writeln(` ${e.from}:${e.line} ${output.dim(e.spec)}`);
|
|
200
|
+
return { success: true, exitCode: 0 };
|
|
201
|
+
},
|
|
202
|
+
};
|
|
132
203
|
export const codegraphCommand = {
|
|
133
204
|
name: 'codegraph',
|
|
134
205
|
aliases: ['cg'],
|
|
135
|
-
description: 'Queryable index of exported symbols — where things are defined, without grep+read',
|
|
136
|
-
subcommands: [indexCommand, queryCommand, fileCommand, statsCommand],
|
|
206
|
+
description: 'Queryable index of exported symbols + import graph — where things are defined and what depends on what, without grep+read',
|
|
207
|
+
subcommands: [indexCommand, queryCommand, fileCommand, importsCommand, importersCommand, statsCommand],
|
|
137
208
|
options: [],
|
|
138
209
|
examples: [
|
|
139
|
-
{ command: 'swarmdo codegraph index', description: 'Scan the repo and persist the symbol index' },
|
|
210
|
+
{ command: 'swarmdo codegraph index', description: 'Scan the repo and persist the symbol + import index' },
|
|
140
211
|
{ command: 'swarmdo codegraph query buildIndex', description: 'Find where a symbol is defined' },
|
|
141
212
|
{ command: 'swarmdo codegraph query Handler --fuzzy --kind type', description: 'Fuzzy, kind-filtered lookup' },
|
|
142
213
|
{ command: 'swarmdo codegraph file src/index.ts', description: 'What a file exports' },
|
|
214
|
+
{ command: 'swarmdo codegraph importers src/codegraph/store.ts', description: 'What breaks if I change this file' },
|
|
143
215
|
],
|
|
144
216
|
action: async () => {
|
|
145
|
-
output.writeln(output.bold('swarmdo codegraph — exported-symbol index'));
|
|
217
|
+
output.writeln(output.bold('swarmdo codegraph — exported-symbol index + import graph'));
|
|
146
218
|
output.printList([
|
|
147
|
-
'index [path]
|
|
148
|
-
'query <name>
|
|
149
|
-
'file <path>
|
|
150
|
-
'
|
|
219
|
+
'index [path] scan TS/JS and persist to .swarm/codegraph.json',
|
|
220
|
+
'query <name> find a symbol (--fuzzy, --kind)',
|
|
221
|
+
'file <path> symbols a file exports',
|
|
222
|
+
'imports <path> what a file imports (--internal)',
|
|
223
|
+
'importers <path> who imports a file (reverse deps)',
|
|
224
|
+
'stats index summary',
|
|
151
225
|
]);
|
|
152
|
-
output.writeln(output.dim('MVP: exported top-level symbols
|
|
226
|
+
output.writeln(output.dim('MVP: exported top-level symbols + relative-import edges. Incremental watch is a follow-up.'));
|
|
153
227
|
return { success: true, exitCode: 0 };
|
|
154
228
|
},
|
|
155
229
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `swarmdo env` — reconcile the env vars the code references against what
|
|
3
|
+
* `.env` declares (and, if present, `.env.example`). Catches deploy-breaking
|
|
4
|
+
* drift before it ships:
|
|
5
|
+
*
|
|
6
|
+
* swarmdo env # scan cwd vs .env / .env.example
|
|
7
|
+
* swarmdo env src --ci # exit 1 if any referenced var is undeclared
|
|
8
|
+
* swarmdo env --json # machine-readable report
|
|
9
|
+
*
|
|
10
|
+
* Engine (../env/env.ts) is pure + tested; this layer does the fs walk and
|
|
11
|
+
* reads the dotenv files.
|
|
12
|
+
*/
|
|
13
|
+
import type { Command } from '../types.js';
|
|
14
|
+
export declare const envCommand: Command;
|
|
15
|
+
export default envCommand;
|
|
16
|
+
//# sourceMappingURL=env.d.ts.map
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `swarmdo env` — reconcile the env vars the code references against what
|
|
3
|
+
* `.env` declares (and, if present, `.env.example`). Catches deploy-breaking
|
|
4
|
+
* drift before it ships:
|
|
5
|
+
*
|
|
6
|
+
* swarmdo env # scan cwd vs .env / .env.example
|
|
7
|
+
* swarmdo env src --ci # exit 1 if any referenced var is undeclared
|
|
8
|
+
* swarmdo env --json # machine-readable report
|
|
9
|
+
*
|
|
10
|
+
* Engine (../env/env.ts) is pure + tested; this layer does the fs walk and
|
|
11
|
+
* reads the dotenv files.
|
|
12
|
+
*/
|
|
13
|
+
import * as fs from 'node:fs';
|
|
14
|
+
import * as path from 'node:path';
|
|
15
|
+
import { output } from '../output.js';
|
|
16
|
+
import { extractEnvRefs, parseDotenv, reconcile, formatEnvSummary } from '../env/env.js';
|
|
17
|
+
const SOURCE_EXT = new Set(['.ts', '.tsx', '.js', '.jsx', '.mts', '.cts', '.mjs', '.cjs', '.py', '.vue', '.svelte', '.astro']);
|
|
18
|
+
const SKIP_DIRS = new Set([
|
|
19
|
+
'node_modules', '.git', '.swarm', 'dist', 'dist-standalone', 'build',
|
|
20
|
+
'coverage', '.next', '.turbo', 'out', 'vendor', '.cache',
|
|
21
|
+
]);
|
|
22
|
+
// Ubiquitous runtime/CI vars that are almost never declared in a project .env.
|
|
23
|
+
const DEFAULT_IGNORE = ['NODE_ENV', 'CI', 'PATH', 'HOME', 'PWD', 'USER', 'SHELL', 'TERM', 'TZ', 'LANG'];
|
|
24
|
+
function walk(root) {
|
|
25
|
+
const found = [];
|
|
26
|
+
const stack = [root];
|
|
27
|
+
while (stack.length) {
|
|
28
|
+
const dir = stack.pop();
|
|
29
|
+
let entries;
|
|
30
|
+
try {
|
|
31
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
for (const e of entries) {
|
|
37
|
+
const full = path.join(dir, e.name);
|
|
38
|
+
if (e.isDirectory()) {
|
|
39
|
+
if (SKIP_DIRS.has(e.name))
|
|
40
|
+
continue;
|
|
41
|
+
stack.push(full);
|
|
42
|
+
}
|
|
43
|
+
else if (e.isFile()) {
|
|
44
|
+
const ext = path.extname(e.name);
|
|
45
|
+
if (SOURCE_EXT.has(ext) && !e.name.endsWith('.d.ts'))
|
|
46
|
+
found.push(full);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return found;
|
|
51
|
+
}
|
|
52
|
+
function readKeys(file) {
|
|
53
|
+
try {
|
|
54
|
+
return parseDotenv(fs.readFileSync(file, 'utf8'));
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async function run(ctx) {
|
|
61
|
+
const repoRoot = ctx.cwd || process.cwd();
|
|
62
|
+
const scanRoot = ctx.args[0] ? path.resolve(repoRoot, ctx.args[0]) : repoRoot;
|
|
63
|
+
const envFile = path.resolve(repoRoot, typeof ctx.flags.env === 'string' ? ctx.flags.env : '.env');
|
|
64
|
+
const exampleFlag = typeof ctx.flags.example === 'string' ? ctx.flags.example : '.env.example';
|
|
65
|
+
const exampleFile = path.resolve(repoRoot, exampleFlag);
|
|
66
|
+
const declared = readKeys(envFile);
|
|
67
|
+
if (declared === null) {
|
|
68
|
+
output.printError(`no env file at ${path.relative(repoRoot, envFile)} (use --env <file>)`);
|
|
69
|
+
return { success: false, exitCode: 1 };
|
|
70
|
+
}
|
|
71
|
+
const example = readKeys(exampleFile) ?? undefined;
|
|
72
|
+
const ignore = [...DEFAULT_IGNORE];
|
|
73
|
+
if (typeof ctx.flags.ignore === 'string')
|
|
74
|
+
ignore.push(...ctx.flags.ignore.split(',').map((s) => s.trim()).filter(Boolean));
|
|
75
|
+
const refs = [];
|
|
76
|
+
for (const abs of walk(scanRoot)) {
|
|
77
|
+
let src;
|
|
78
|
+
try {
|
|
79
|
+
src = fs.readFileSync(abs, 'utf8');
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
const rel = path.relative(repoRoot, abs).split(path.sep).join('/');
|
|
85
|
+
refs.push(...extractEnvRefs(src, rel));
|
|
86
|
+
}
|
|
87
|
+
const report = reconcile({ refs, declared, example, ignore });
|
|
88
|
+
const hasExample = example !== undefined;
|
|
89
|
+
if (ctx.flags.json === true) {
|
|
90
|
+
output.printJson({ ...report, envFile: path.relative(repoRoot, envFile), hasExample });
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
const section = (title, keys, withSites = false) => {
|
|
94
|
+
if (keys.length === 0)
|
|
95
|
+
return;
|
|
96
|
+
output.writeln(output.bold(`${title} (${keys.length})`));
|
|
97
|
+
output.printList(keys.map((k) => {
|
|
98
|
+
if (!withSites)
|
|
99
|
+
return k;
|
|
100
|
+
const site = report.refs[k]?.[0];
|
|
101
|
+
return site ? `${k} ${output.dim(`${site.file}:${site.line}`)}` : k;
|
|
102
|
+
}));
|
|
103
|
+
};
|
|
104
|
+
section('Missing — referenced in code, not in .env', report.missing, true);
|
|
105
|
+
section('Unused — declared in .env, never referenced', report.unused);
|
|
106
|
+
if (hasExample)
|
|
107
|
+
section('Undocumented — in .env, not in .env.example', report.undocumented);
|
|
108
|
+
output.writeln(output.dim(formatEnvSummary(report, hasExample)));
|
|
109
|
+
}
|
|
110
|
+
// --ci gates on `missing` (the runtime-breaking bucket); --strict also gates
|
|
111
|
+
// on unused + undocumented.
|
|
112
|
+
const strict = ctx.flags.strict === true;
|
|
113
|
+
const bad = report.missing.length + (strict ? report.unused.length + report.undocumented.length : 0);
|
|
114
|
+
const gate = ctx.flags.ci === true || strict;
|
|
115
|
+
const code = gate && bad > 0 ? 1 : 0;
|
|
116
|
+
return { success: code === 0, exitCode: code };
|
|
117
|
+
}
|
|
118
|
+
export const envCommand = {
|
|
119
|
+
name: 'env',
|
|
120
|
+
description: 'Reconcile env vars referenced in code against .env / .env.example — find missing, unused, and undocumented vars',
|
|
121
|
+
options: [
|
|
122
|
+
{ name: 'env', description: 'path to the env file (default .env)', type: 'string' },
|
|
123
|
+
{ name: 'example', description: 'path to the example env file (default .env.example)', type: 'string' },
|
|
124
|
+
{ name: 'ignore', description: 'comma-separated extra keys to ignore (NODE_ENV/CI/… already ignored)', type: 'string' },
|
|
125
|
+
{ name: 'ci', description: 'exit 1 if any referenced var is undeclared (missing bucket)', type: 'boolean' },
|
|
126
|
+
{ name: 'strict', description: 'exit 1 on missing OR unused OR undocumented', type: 'boolean' },
|
|
127
|
+
{ name: 'json', description: 'machine-readable report', type: 'boolean' },
|
|
128
|
+
],
|
|
129
|
+
examples: [
|
|
130
|
+
{ command: 'swarmdo env', description: 'Reconcile the repo against .env / .env.example' },
|
|
131
|
+
{ command: 'swarmdo env src --ci', description: 'Fail CI if code references an undeclared var' },
|
|
132
|
+
{ command: 'swarmdo env --env .env.production --json', description: 'Check a specific env file, JSON out' },
|
|
133
|
+
],
|
|
134
|
+
action: run,
|
|
135
|
+
};
|
|
136
|
+
export default envCommand;
|
|
137
|
+
//# sourceMappingURL=env.js.map
|
|
@@ -28,6 +28,9 @@ const commandLoaders = {
|
|
|
28
28
|
// Repo→AI-context bundle (repomix demand) — one promptable blob with tree +
|
|
29
29
|
// token counts; swarmdo's context-assembly primitive.
|
|
30
30
|
pack: () => import('./pack.js'),
|
|
31
|
+
// Env-var drift checker (dotenv-safe/dotenv-scan demand) — reconcile code
|
|
32
|
+
// references against .env / .env.example (missing/unused/undocumented).
|
|
33
|
+
env: () => import('./env.js'),
|
|
31
34
|
// Queryable exported-symbol index (codegraph demand) — where things are
|
|
32
35
|
// defined without grep+read round-trips.
|
|
33
36
|
codegraph: () => import('./codegraph.js'),
|
|
@@ -261,7 +264,7 @@ export async function getCommandsByCategory() {
|
|
|
261
264
|
// three slots from 'statusline' onward (completionsCmd received the
|
|
262
265
|
// statusline module, analyzeCmd received completions, …), scrambling the
|
|
263
266
|
// categorized help. Every load now has a named slot.
|
|
264
|
-
const [daemonCmd, doctorCmd, embeddingsCmd, neuralCmd, performanceCmd, securityCmd, swarmvectorCmd, hiveMindCmd, configCmd, statuslineCmd, compressCmd, efficiencyCmd, completionsCmd, migrateCmd, workflowCmd, analyzeCmd, routeCmd, progressCmd, providersCmd, pluginsCmd, deploymentCmd, claimsCmd, issuesCmd, updateCmd, processCmd, guidanceCmd, applianceCmd, cleanupCmd, autopilotCmd, demoCmd, usageCmd, repairCmd, hudCmd, compactCmd, codegraphCmd, redactCmd, packCmd,] = await Promise.all([
|
|
267
|
+
const [daemonCmd, doctorCmd, embeddingsCmd, neuralCmd, performanceCmd, securityCmd, swarmvectorCmd, hiveMindCmd, configCmd, statuslineCmd, compressCmd, efficiencyCmd, completionsCmd, migrateCmd, workflowCmd, analyzeCmd, routeCmd, progressCmd, providersCmd, pluginsCmd, deploymentCmd, claimsCmd, issuesCmd, updateCmd, processCmd, guidanceCmd, applianceCmd, cleanupCmd, autopilotCmd, demoCmd, usageCmd, repairCmd, hudCmd, compactCmd, codegraphCmd, redactCmd, packCmd, envCmd,] = await Promise.all([
|
|
265
268
|
loadCommand('daemon'), loadCommand('doctor'), loadCommand('embeddings'), loadCommand('neural'),
|
|
266
269
|
loadCommand('performance'), loadCommand('security'), loadCommand('swarmvector'), loadCommand('hive-mind'),
|
|
267
270
|
loadCommand('config'), loadCommand('statusline'), loadCommand('compress'), loadCommand('efficiency'),
|
|
@@ -269,7 +272,7 @@ export async function getCommandsByCategory() {
|
|
|
269
272
|
loadCommand('analyze'), loadCommand('route'), loadCommand('progress'), loadCommand('providers'),
|
|
270
273
|
loadCommand('plugins'), loadCommand('deployment'), loadCommand('claims'), loadCommand('issues'),
|
|
271
274
|
loadCommand('update'), loadCommand('process'), loadCommand('guidance'), loadCommand('appliance'),
|
|
272
|
-
loadCommand('cleanup'), loadCommand('autopilot'), loadCommand('demo'), loadCommand('usage'), loadCommand('repair'), loadCommand('hud'), loadCommand('compact'), loadCommand('codegraph'), loadCommand('redact'), loadCommand('pack'),
|
|
275
|
+
loadCommand('cleanup'), loadCommand('autopilot'), loadCommand('demo'), loadCommand('usage'), loadCommand('repair'), loadCommand('hud'), loadCommand('compact'), loadCommand('codegraph'), loadCommand('redact'), loadCommand('pack'), loadCommand('env'),
|
|
273
276
|
]);
|
|
274
277
|
return {
|
|
275
278
|
primary: [
|
|
@@ -285,7 +288,7 @@ export async function getCommandsByCategory() {
|
|
|
285
288
|
utility: [
|
|
286
289
|
configCmd, doctorCmd, daemonCmd, completionsCmd,
|
|
287
290
|
migrateCmd, workflowCmd, demoCmd,
|
|
288
|
-
statuslineCmd, compressCmd, compactCmd, redactCmd, packCmd, efficiencyCmd,
|
|
291
|
+
statuslineCmd, compressCmd, compactCmd, redactCmd, packCmd, envCmd, efficiencyCmd,
|
|
289
292
|
].filter(Boolean),
|
|
290
293
|
analysis: [
|
|
291
294
|
analyzeCmd, routeCmd, progressCmd, usageCmd, hudCmd, codegraphCmd,
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* env.ts — reconcile the environment variables a codebase *references* against
|
|
3
|
+
* the ones a `.env` (and `.env.example`) *declares*. Catches the classic "deploy
|
|
4
|
+
* broke because a var was missing / stale" drift before it ships.
|
|
5
|
+
*
|
|
6
|
+
* Three buckets:
|
|
7
|
+
* missing — referenced in code, not declared in .env (will break at runtime)
|
|
8
|
+
* unused — declared in .env, never referenced in code (dead config)
|
|
9
|
+
* undocumented — declared in .env, absent from .env.example (onboarding gap)
|
|
10
|
+
*
|
|
11
|
+
* Pure + deterministic (regex extraction + dotenv parse + set diff), so it's
|
|
12
|
+
* fully fixture-testable with zero LLM calls. The fs walk + file reads live in
|
|
13
|
+
* ../commands/env.ts; this module just takes strings.
|
|
14
|
+
*/
|
|
15
|
+
export interface EnvRef {
|
|
16
|
+
key: string;
|
|
17
|
+
file: string;
|
|
18
|
+
/** 1-based line */
|
|
19
|
+
line: number;
|
|
20
|
+
}
|
|
21
|
+
export interface EnvReport {
|
|
22
|
+
missing: string[];
|
|
23
|
+
unused: string[];
|
|
24
|
+
undocumented: string[];
|
|
25
|
+
/** every key referenced in code → the sites that reference it */
|
|
26
|
+
refs: Record<string, EnvRef[]>;
|
|
27
|
+
}
|
|
28
|
+
/** Extract env-var references from one source file. Pure. */
|
|
29
|
+
export declare function extractEnvRefs(source: string, file: string): EnvRef[];
|
|
30
|
+
/**
|
|
31
|
+
* Parse a `.env` file into an ordered list of declared keys. Handles `KEY=val`,
|
|
32
|
+
* `export KEY=val`, quoted values, `# comments`, and blank lines. Values are
|
|
33
|
+
* ignored — we only reconcile key presence. Pure.
|
|
34
|
+
*/
|
|
35
|
+
export declare function parseDotenv(text: string): string[];
|
|
36
|
+
export interface ReconcileInput {
|
|
37
|
+
refs: EnvRef[];
|
|
38
|
+
/** keys declared in .env */
|
|
39
|
+
declared: string[];
|
|
40
|
+
/** keys declared in .env.example (optional) */
|
|
41
|
+
example?: string[];
|
|
42
|
+
/** keys to ignore in all buckets (e.g. NODE_ENV, CI) */
|
|
43
|
+
ignore?: string[];
|
|
44
|
+
}
|
|
45
|
+
/** Compute the missing / unused / undocumented buckets. Pure. */
|
|
46
|
+
export declare function reconcile(input: ReconcileInput): EnvReport;
|
|
47
|
+
/** One-line human summary. */
|
|
48
|
+
export declare function formatEnvSummary(r: EnvReport, hasExample: boolean): string;
|
|
49
|
+
//# sourceMappingURL=env.d.ts.map
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* env.ts — reconcile the environment variables a codebase *references* against
|
|
3
|
+
* the ones a `.env` (and `.env.example`) *declares*. Catches the classic "deploy
|
|
4
|
+
* broke because a var was missing / stale" drift before it ships.
|
|
5
|
+
*
|
|
6
|
+
* Three buckets:
|
|
7
|
+
* missing — referenced in code, not declared in .env (will break at runtime)
|
|
8
|
+
* unused — declared in .env, never referenced in code (dead config)
|
|
9
|
+
* undocumented — declared in .env, absent from .env.example (onboarding gap)
|
|
10
|
+
*
|
|
11
|
+
* Pure + deterministic (regex extraction + dotenv parse + set diff), so it's
|
|
12
|
+
* fully fixture-testable with zero LLM calls. The fs walk + file reads live in
|
|
13
|
+
* ../commands/env.ts; this module just takes strings.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Patterns that read an env var. Each capture group 1 is the var name. Covers
|
|
17
|
+
* Node (`process.env.X`, `process.env['X']`), Vite (`import.meta.env.X`), Deno
|
|
18
|
+
* (`Deno.env.get('X')`), and Python (`os.environ['X']`, `os.environ.get('X')`,
|
|
19
|
+
* `os.getenv('X')`). Deterministic, line-based.
|
|
20
|
+
*/
|
|
21
|
+
const REF_PATTERNS = [
|
|
22
|
+
/process\.env\.([A-Za-z_][A-Za-z0-9_]*)/g,
|
|
23
|
+
/process\.env\[\s*['"`]([^'"`]+)['"`]\s*\]/g,
|
|
24
|
+
/import\.meta\.env\.([A-Za-z_][A-Za-z0-9_]*)/g,
|
|
25
|
+
/import\.meta\.env\[\s*['"`]([^'"`]+)['"`]\s*\]/g,
|
|
26
|
+
/Deno\.env\.get\(\s*['"`]([^'"`]+)['"`]\s*\)/g,
|
|
27
|
+
/os\.environ\[\s*['"]([^'"]+)['"]\s*\]/g,
|
|
28
|
+
/os\.environ\.get\(\s*['"]([^'"]+)['"]\s*\)/g,
|
|
29
|
+
/os\.getenv\(\s*['"]([^'"]+)['"]\s*\)/g,
|
|
30
|
+
];
|
|
31
|
+
/** Non-secret prefixes on `import.meta.env` that are Vite builtins, not user vars. */
|
|
32
|
+
const VITE_BUILTINS = new Set(['MODE', 'BASE_URL', 'PROD', 'DEV', 'SSR']);
|
|
33
|
+
/** Extract env-var references from one source file. Pure. */
|
|
34
|
+
export function extractEnvRefs(source, file) {
|
|
35
|
+
const out = [];
|
|
36
|
+
const lines = source.split('\n');
|
|
37
|
+
for (let i = 0; i < lines.length; i++) {
|
|
38
|
+
const line = lines[i];
|
|
39
|
+
if (!line.includes('env') && !line.includes('getenv'))
|
|
40
|
+
continue;
|
|
41
|
+
for (const re of REF_PATTERNS) {
|
|
42
|
+
re.lastIndex = 0;
|
|
43
|
+
let m;
|
|
44
|
+
while ((m = re.exec(line)) !== null) {
|
|
45
|
+
const key = m[1];
|
|
46
|
+
if (VITE_BUILTINS.has(key))
|
|
47
|
+
continue;
|
|
48
|
+
out.push({ key, file, line: i + 1 });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return out;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Parse a `.env` file into an ordered list of declared keys. Handles `KEY=val`,
|
|
56
|
+
* `export KEY=val`, quoted values, `# comments`, and blank lines. Values are
|
|
57
|
+
* ignored — we only reconcile key presence. Pure.
|
|
58
|
+
*/
|
|
59
|
+
export function parseDotenv(text) {
|
|
60
|
+
const keys = [];
|
|
61
|
+
const seen = new Set();
|
|
62
|
+
for (const raw of text.split('\n')) {
|
|
63
|
+
const line = raw.trim();
|
|
64
|
+
if (!line || line.startsWith('#'))
|
|
65
|
+
continue;
|
|
66
|
+
const m = line.match(/^(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=/);
|
|
67
|
+
if (!m)
|
|
68
|
+
continue;
|
|
69
|
+
if (seen.has(m[1]))
|
|
70
|
+
continue;
|
|
71
|
+
seen.add(m[1]);
|
|
72
|
+
keys.push(m[1]);
|
|
73
|
+
}
|
|
74
|
+
return keys;
|
|
75
|
+
}
|
|
76
|
+
/** Compute the missing / unused / undocumented buckets. Pure. */
|
|
77
|
+
export function reconcile(input) {
|
|
78
|
+
const ignore = new Set(input.ignore ?? []);
|
|
79
|
+
const refByKey = {};
|
|
80
|
+
for (const r of input.refs) {
|
|
81
|
+
if (ignore.has(r.key))
|
|
82
|
+
continue;
|
|
83
|
+
(refByKey[r.key] ??= []).push(r);
|
|
84
|
+
}
|
|
85
|
+
const referenced = new Set(Object.keys(refByKey));
|
|
86
|
+
const declared = new Set(input.declared.filter((k) => !ignore.has(k)));
|
|
87
|
+
const missing = [...referenced].filter((k) => !declared.has(k)).sort();
|
|
88
|
+
const unused = [...declared].filter((k) => !referenced.has(k)).sort();
|
|
89
|
+
let undocumented = [];
|
|
90
|
+
if (input.example) {
|
|
91
|
+
const example = new Set(input.example);
|
|
92
|
+
undocumented = [...declared].filter((k) => !example.has(k)).sort();
|
|
93
|
+
}
|
|
94
|
+
return { missing, unused, undocumented, refs: refByKey };
|
|
95
|
+
}
|
|
96
|
+
/** One-line human summary. */
|
|
97
|
+
export function formatEnvSummary(r, hasExample) {
|
|
98
|
+
const parts = [`${r.missing.length} missing`, `${r.unused.length} unused`];
|
|
99
|
+
if (hasExample)
|
|
100
|
+
parts.push(`${r.undocumented.length} undocumented`);
|
|
101
|
+
return `env: ${parts.join(', ')}`;
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=env.js.map
|
|
@@ -21,6 +21,7 @@ import { workflowTools } from './mcp-tools/workflow-tools.js';
|
|
|
21
21
|
import { analyzeTools } from './mcp-tools/analyze-tools.js';
|
|
22
22
|
import { codegraphTools } from './mcp-tools/codegraph-tools.js';
|
|
23
23
|
import { redactTools } from './mcp-tools/redact-tools.js';
|
|
24
|
+
import { envTools } from './mcp-tools/env-tools.js';
|
|
24
25
|
import { progressTools } from './mcp-tools/progress-tools.js';
|
|
25
26
|
import { embeddingsTools } from './mcp-tools/embeddings-tools.js';
|
|
26
27
|
import { claimsTools } from './mcp-tools/claims-tools.js';
|
|
@@ -106,6 +107,7 @@ const TOOL_GROUPS = {
|
|
|
106
107
|
analyze: () => analyzeTools,
|
|
107
108
|
codegraph: () => codegraphTools,
|
|
108
109
|
redact: () => redactTools,
|
|
110
|
+
env: () => envTools,
|
|
109
111
|
progress: () => progressTools,
|
|
110
112
|
embeddings: () => embeddingsTools,
|
|
111
113
|
claims: () => claimsTools,
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* instead of shelling out to `swarmdo codegraph` or grep+read. Reads the same
|
|
7
7
|
* .swarm/codegraph.json the CLI writes (shared fs layer in codegraph/store.ts).
|
|
8
8
|
*/
|
|
9
|
-
import { queryIndex, symbolsInFile, indexStats } from '../codegraph/codegraph.js';
|
|
9
|
+
import { queryIndex, symbolsInFile, indexStats, fileImports, fileImporters } from '../codegraph/codegraph.js';
|
|
10
10
|
import { INDEX_REL, scanRepo, saveIndex, loadIndex } from '../codegraph/store.js';
|
|
11
11
|
const KINDS = ['function', 'class', 'interface', 'type', 'const', 'enum', 'default'];
|
|
12
12
|
/** Resolve the repo root for scan/load. Params may override; default = cwd. */
|
|
@@ -113,10 +113,65 @@ const codegraphStatsTool = {
|
|
|
113
113
|
return indexStats(index);
|
|
114
114
|
},
|
|
115
115
|
};
|
|
116
|
+
const codegraphImportsTool = {
|
|
117
|
+
name: 'codegraph_imports',
|
|
118
|
+
description: 'List what a file imports — each edge as the raw specifier plus the repo file it resolves to (external packages resolve to null). Answers "what does this module depend on" from the index. Requires a prior codegraph_index.',
|
|
119
|
+
category: 'codegraph',
|
|
120
|
+
tags: ['code', 'imports', 'dependencies', 'navigation'],
|
|
121
|
+
inputSchema: {
|
|
122
|
+
type: 'object',
|
|
123
|
+
properties: {
|
|
124
|
+
file: { type: 'string', description: 'Repo-relative file path (as indexed, e.g. src/index.ts)' },
|
|
125
|
+
internal: { type: 'boolean', description: 'only edges resolved to a repo file (hide external packages)', default: false },
|
|
126
|
+
root: { type: 'string', description: 'Repo root (default: current working directory)' },
|
|
127
|
+
},
|
|
128
|
+
required: ['file'],
|
|
129
|
+
},
|
|
130
|
+
handler: async (params) => {
|
|
131
|
+
const root = rootOf(params);
|
|
132
|
+
const file = params.file;
|
|
133
|
+
if (typeof file !== 'string' || !file)
|
|
134
|
+
return { error: true, message: 'file is required' };
|
|
135
|
+
const index = loadIndex(root);
|
|
136
|
+
if (!index)
|
|
137
|
+
return { error: true, message: 'no index — run codegraph_index first' };
|
|
138
|
+
let edges = fileImports(index, file);
|
|
139
|
+
if (params.internal === true)
|
|
140
|
+
edges = edges.filter((e) => e.resolved !== null);
|
|
141
|
+
return { file, count: edges.length, edges };
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
const codegraphImportersTool = {
|
|
145
|
+
name: 'codegraph_importers',
|
|
146
|
+
description: 'List which files import a given file — its reverse dependencies. Use before changing or moving a file to see what depends on it ("what breaks if I change this"). Requires a prior codegraph_index.',
|
|
147
|
+
category: 'codegraph',
|
|
148
|
+
tags: ['code', 'imports', 'dependencies', 'impact', 'navigation'],
|
|
149
|
+
inputSchema: {
|
|
150
|
+
type: 'object',
|
|
151
|
+
properties: {
|
|
152
|
+
file: { type: 'string', description: 'Repo-relative file path whose importers you want' },
|
|
153
|
+
root: { type: 'string', description: 'Repo root (default: current working directory)' },
|
|
154
|
+
},
|
|
155
|
+
required: ['file'],
|
|
156
|
+
},
|
|
157
|
+
handler: async (params) => {
|
|
158
|
+
const root = rootOf(params);
|
|
159
|
+
const file = params.file;
|
|
160
|
+
if (typeof file !== 'string' || !file)
|
|
161
|
+
return { error: true, message: 'file is required' };
|
|
162
|
+
const index = loadIndex(root);
|
|
163
|
+
if (!index)
|
|
164
|
+
return { error: true, message: 'no index — run codegraph_index first' };
|
|
165
|
+
const edges = fileImporters(index, file);
|
|
166
|
+
return { file, count: edges.length, importers: edges };
|
|
167
|
+
},
|
|
168
|
+
};
|
|
116
169
|
export const codegraphTools = [
|
|
117
170
|
codegraphIndexTool,
|
|
118
171
|
codegraphQueryTool,
|
|
119
172
|
codegraphFileTool,
|
|
173
|
+
codegraphImportsTool,
|
|
174
|
+
codegraphImportersTool,
|
|
120
175
|
codegraphStatsTool,
|
|
121
176
|
];
|
|
122
177
|
//# sourceMappingURL=codegraph-tools.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Env MCP Tool
|
|
3
|
+
*
|
|
4
|
+
* Let an agent check env-var drift in-session before it writes code that reads
|
|
5
|
+
* a var, or before it green-lights a deploy: reconcile the vars referenced in
|
|
6
|
+
* given source against a `.env` (and optional `.env.example`). Deterministic —
|
|
7
|
+
* shares the pure engine in ../env/env.ts with the CLI command. String-in, so
|
|
8
|
+
* it works without touching the filesystem.
|
|
9
|
+
*/
|
|
10
|
+
import type { MCPTool } from './types.js';
|
|
11
|
+
export declare const envTools: MCPTool[];
|
|
12
|
+
//# sourceMappingURL=env-tools.d.ts.map
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Env MCP Tool
|
|
3
|
+
*
|
|
4
|
+
* Let an agent check env-var drift in-session before it writes code that reads
|
|
5
|
+
* a var, or before it green-lights a deploy: reconcile the vars referenced in
|
|
6
|
+
* given source against a `.env` (and optional `.env.example`). Deterministic —
|
|
7
|
+
* shares the pure engine in ../env/env.ts with the CLI command. String-in, so
|
|
8
|
+
* it works without touching the filesystem.
|
|
9
|
+
*/
|
|
10
|
+
import { extractEnvRefs, parseDotenv, reconcile } from '../env/env.js';
|
|
11
|
+
const envCheckTool = {
|
|
12
|
+
name: 'env_check',
|
|
13
|
+
description: 'Reconcile env vars referenced in source code against a .env declaration. Returns missing (referenced, not declared — will break at runtime), unused (declared, never referenced), and undocumented (in .env, not in .env.example). Use before adding a var or approving a deploy. Deterministic; pass the file contents directly.',
|
|
14
|
+
category: 'env',
|
|
15
|
+
tags: ['env', 'dotenv', 'config', 'drift', 'ci'],
|
|
16
|
+
inputSchema: {
|
|
17
|
+
type: 'object',
|
|
18
|
+
properties: {
|
|
19
|
+
sources: {
|
|
20
|
+
type: 'array',
|
|
21
|
+
description: 'source files to scan',
|
|
22
|
+
items: {
|
|
23
|
+
type: 'object',
|
|
24
|
+
properties: {
|
|
25
|
+
path: { type: 'string', description: 'file path (for reporting)' },
|
|
26
|
+
content: { type: 'string', description: 'file contents' },
|
|
27
|
+
},
|
|
28
|
+
required: ['path', 'content'],
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
env: { type: 'string', description: 'contents of the .env file (declarations)' },
|
|
32
|
+
example: { type: 'string', description: 'contents of .env.example (optional, enables the undocumented bucket)' },
|
|
33
|
+
ignore: { type: 'array', items: { type: 'string' }, description: 'extra keys to ignore' },
|
|
34
|
+
},
|
|
35
|
+
required: ['sources', 'env'],
|
|
36
|
+
},
|
|
37
|
+
handler: async (params) => {
|
|
38
|
+
const sources = params.sources;
|
|
39
|
+
if (!Array.isArray(sources))
|
|
40
|
+
return { error: true, message: 'sources[] is required' };
|
|
41
|
+
if (typeof params.env !== 'string')
|
|
42
|
+
return { error: true, message: 'env (string) is required' };
|
|
43
|
+
const refs = sources.flatMap((s) => {
|
|
44
|
+
const o = s;
|
|
45
|
+
if (typeof o.path !== 'string' || typeof o.content !== 'string')
|
|
46
|
+
return [];
|
|
47
|
+
return extractEnvRefs(o.content, o.path);
|
|
48
|
+
});
|
|
49
|
+
const declared = parseDotenv(params.env);
|
|
50
|
+
const example = typeof params.example === 'string' ? parseDotenv(params.example) : undefined;
|
|
51
|
+
const ignore = Array.isArray(params.ignore) ? params.ignore.filter((x) => typeof x === 'string') : undefined;
|
|
52
|
+
const report = reconcile({ refs, declared, example, ignore });
|
|
53
|
+
return {
|
|
54
|
+
clean: report.missing.length === 0 && report.unused.length === 0 && report.undocumented.length === 0,
|
|
55
|
+
missing: report.missing,
|
|
56
|
+
unused: report.unused,
|
|
57
|
+
undocumented: report.undocumented,
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
export const envTools = [envCheckTool];
|
|
62
|
+
//# sourceMappingURL=env-tools.js.map
|
|
@@ -17,6 +17,7 @@ export { coverageRouterTools } from '../swarmvector/coverage-tools.js';
|
|
|
17
17
|
export { analyzeTools } from './analyze-tools.js';
|
|
18
18
|
export { codegraphTools } from './codegraph-tools.js';
|
|
19
19
|
export { redactTools } from './redact-tools.js';
|
|
20
|
+
export { envTools } from './env-tools.js';
|
|
20
21
|
export { progressTools } from './progress-tools.js';
|
|
21
22
|
export { transferTools } from './transfer-tools.js';
|
|
22
23
|
export { securityTools } from './security-tools.js';
|
|
@@ -16,6 +16,7 @@ export { coverageRouterTools } from '../swarmvector/coverage-tools.js';
|
|
|
16
16
|
export { analyzeTools } from './analyze-tools.js';
|
|
17
17
|
export { codegraphTools } from './codegraph-tools.js';
|
|
18
18
|
export { redactTools } from './redact-tools.js';
|
|
19
|
+
export { envTools } from './env-tools.js';
|
|
19
20
|
export { progressTools } from './progress-tools.js';
|
|
20
21
|
export { transferTools } from './transfer-tools.js';
|
|
21
22
|
export { securityTools } from './security-tools.js';
|
|
@@ -24,6 +24,7 @@ const LEAN_GROUPS = [
|
|
|
24
24
|
'embeddings', // embeddings_generate / search / compare
|
|
25
25
|
'codegraph', // codegraph_query / file / index — "where is X defined?"
|
|
26
26
|
'redact', // redact_text / redact_scan — secret guard on the data path
|
|
27
|
+
'env', // env_check — env-var drift (missing/unused/undocumented)
|
|
27
28
|
];
|
|
28
29
|
/** Balanced = lean + orchestration/session/system the average user reaches for. */
|
|
29
30
|
const BALANCED_EXTRA = [
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@swarmdo/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Swarmdo CLI - Enterprise AI agent orchestration with 60+ specialized agents, swarm coordination, MCP server, self-learning hooks, and vector memory for Claude Code",
|
|
6
6
|
"main": "dist/src/index.js",
|