bastion-gate 0.0.0-stage → 0.3.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/LICENSE +21 -0
- package/README.md +111 -2
- package/action.yml +10 -0
- package/dist/action.js +11 -0
- package/dist/cli.js +184 -0
- package/dist/commands/audit.js +63 -0
- package/dist/commands/clean.js +143 -0
- package/dist/commands/gate.js +108 -0
- package/dist/commands/init.js +143 -0
- package/dist/commands/lock.js +146 -0
- package/dist/commands/mutate.js +154 -0
- package/dist/commands/plan.js +163 -0
- package/dist/commands/run.js +305 -0
- package/dist/config.js +130 -0
- package/dist/git.js +75 -0
- package/dist/orchestrator/dag.js +53 -0
- package/dist/orchestrator/worktree.js +36 -0
- package/dist/runner.js +136 -0
- package/dist/test-names.js +36 -0
- package/dist/version.js +25 -0
- package/package.json +50 -4
package/dist/runner.js
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
2
|
+
import * as crypto from 'node:crypto';
|
|
3
|
+
import * as fs from 'node:fs';
|
|
4
|
+
import * as path from 'node:path';
|
|
5
|
+
import { execGit, toPosixPath } from './git.js';
|
|
6
|
+
/** Run a test command in the repo root and capture its real exit code. */
|
|
7
|
+
export function runTestCommand(command, cwd) {
|
|
8
|
+
const start = Date.now();
|
|
9
|
+
const env = { ...process.env };
|
|
10
|
+
delete env.NODE_TEST_CONTEXT;
|
|
11
|
+
const res = spawnSync(command, {
|
|
12
|
+
cwd,
|
|
13
|
+
env,
|
|
14
|
+
shell: true,
|
|
15
|
+
encoding: 'utf8',
|
|
16
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
17
|
+
});
|
|
18
|
+
return {
|
|
19
|
+
exitCode: res.status ?? 1,
|
|
20
|
+
stdout: res.stdout ?? '',
|
|
21
|
+
stderr: res.stderr ?? '',
|
|
22
|
+
durationMs: Date.now() - start,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/** Async version of runTestCommand so parallel worktrees do not block the event loop. */
|
|
26
|
+
export function runTestCommandAsync(command, cwd, timeoutMs) {
|
|
27
|
+
return new Promise((resolve) => {
|
|
28
|
+
const start = Date.now();
|
|
29
|
+
const env = { ...process.env };
|
|
30
|
+
delete env.NODE_TEST_CONTEXT;
|
|
31
|
+
const child = spawn(command, {
|
|
32
|
+
cwd,
|
|
33
|
+
env,
|
|
34
|
+
shell: true,
|
|
35
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
36
|
+
});
|
|
37
|
+
let stdout = '';
|
|
38
|
+
let stderr = '';
|
|
39
|
+
let timedOut = false;
|
|
40
|
+
const timer = timeoutMs && timeoutMs > 0
|
|
41
|
+
? setTimeout(() => {
|
|
42
|
+
timedOut = true;
|
|
43
|
+
child.kill();
|
|
44
|
+
}, timeoutMs)
|
|
45
|
+
: null;
|
|
46
|
+
child.stdout?.on('data', (d) => { stdout += String(d); });
|
|
47
|
+
child.stderr?.on('data', (d) => { stderr += String(d); });
|
|
48
|
+
child.on('close', (code) => {
|
|
49
|
+
if (timer)
|
|
50
|
+
clearTimeout(timer);
|
|
51
|
+
if (timedOut)
|
|
52
|
+
stderr += `\n[bastion] Command timed out after ${timeoutMs}ms.`;
|
|
53
|
+
resolve({
|
|
54
|
+
exitCode: timedOut ? 124 : (code ?? 1),
|
|
55
|
+
stdout,
|
|
56
|
+
stderr,
|
|
57
|
+
durationMs: Date.now() - start,
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/** Compute SHA-256 hex digest of a file on disk. */
|
|
63
|
+
export function sha256File(filePath) {
|
|
64
|
+
const buf = fs.readFileSync(filePath);
|
|
65
|
+
return crypto.createHash('sha256').update(buf).digest('hex');
|
|
66
|
+
}
|
|
67
|
+
/** Convert a simple glob pattern (*, **, ?) into a RegExp matching POSIX relative paths. */
|
|
68
|
+
export function globToRegExp(glob) {
|
|
69
|
+
const norm = toPosixPath(glob);
|
|
70
|
+
let regex = '^';
|
|
71
|
+
let i = 0;
|
|
72
|
+
while (i < norm.length) {
|
|
73
|
+
const ch = norm[i];
|
|
74
|
+
if (ch === '*') {
|
|
75
|
+
if (norm[i + 1] === '*') {
|
|
76
|
+
if (norm[i + 2] === '/') {
|
|
77
|
+
regex += '(?:.*/)?';
|
|
78
|
+
i += 3;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
regex += '.*';
|
|
82
|
+
i += 2;
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
regex += '[^/]*';
|
|
86
|
+
i += 1;
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
if (ch === '?') {
|
|
90
|
+
regex += '[^/]';
|
|
91
|
+
i += 1;
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if ('\\^$.|+()[]{}'.includes(ch)) {
|
|
95
|
+
regex += '\\' + ch;
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
regex += ch;
|
|
99
|
+
}
|
|
100
|
+
i += 1;
|
|
101
|
+
}
|
|
102
|
+
regex += '$';
|
|
103
|
+
return new RegExp(regex);
|
|
104
|
+
}
|
|
105
|
+
export function matchesAnyGlob(relPath, globs) {
|
|
106
|
+
const posix = toPosixPath(relPath);
|
|
107
|
+
return globs.some((g) => globToRegExp(g).test(posix));
|
|
108
|
+
}
|
|
109
|
+
const IGNORED_DIRS = new Set(['.git', 'node_modules', '.venv', 'venv', 'dist', 'dist-test', 'build', '.bastion']);
|
|
110
|
+
/** Walk repo files respecting .gitignore via `git ls-files`, with filesystem fallback. */
|
|
111
|
+
export function walkRepoFiles(repoRoot) {
|
|
112
|
+
const gitRes = execGit(['ls-files', '--cached', '--others', '--exclude-standard'], repoRoot);
|
|
113
|
+
if (gitRes.ok) {
|
|
114
|
+
return gitRes.stdout
|
|
115
|
+
.split(/\r?\n/)
|
|
116
|
+
.map((s) => toPosixPath(s.trim()))
|
|
117
|
+
.filter((rel) => rel && !rel.startsWith('.bastion/') && fs.existsSync(path.join(repoRoot, rel)))
|
|
118
|
+
.sort();
|
|
119
|
+
}
|
|
120
|
+
const results = [];
|
|
121
|
+
const walk = (dir) => {
|
|
122
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
123
|
+
if (IGNORED_DIRS.has(entry.name))
|
|
124
|
+
continue;
|
|
125
|
+
const full = path.join(dir, entry.name);
|
|
126
|
+
if (entry.isDirectory()) {
|
|
127
|
+
walk(full);
|
|
128
|
+
}
|
|
129
|
+
else if (entry.isFile()) {
|
|
130
|
+
results.push(toPosixPath(path.relative(repoRoot, full)));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
walk(repoRoot);
|
|
135
|
+
return results.sort();
|
|
136
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extract human-readable test names from common test file formats
|
|
3
|
+
* so a reviewer can scan what is locked in plain language.
|
|
4
|
+
*/
|
|
5
|
+
export function extractTestNames(content) {
|
|
6
|
+
const names = [];
|
|
7
|
+
const seen = new Set();
|
|
8
|
+
const add = (raw) => {
|
|
9
|
+
const cleaned = raw.trim().replace(/\s+/g, ' ');
|
|
10
|
+
if (cleaned && !seen.has(cleaned)) {
|
|
11
|
+
seen.add(cleaned);
|
|
12
|
+
names.push(cleaned);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
// JS/TS/Dart: it('...'), test('...'), describe('...'), testWidgets('...')
|
|
16
|
+
const jsPattern = /^\s*(?:it|test|testWidgets|describe|group)(?:\.(?:only|skip|todo))?\(\s*(['"`])((?:\\.|(?!\1).)+)\1/gm;
|
|
17
|
+
for (const m of content.matchAll(jsPattern)) {
|
|
18
|
+
add(m[2]);
|
|
19
|
+
}
|
|
20
|
+
// Python: def test_something(...)
|
|
21
|
+
const pyPattern = /^\s*(?:async\s+)?def\s+(test_[a-zA-Z0-9_]+)\s*\(/gm;
|
|
22
|
+
for (const m of content.matchAll(pyPattern)) {
|
|
23
|
+
add(m[1].replace(/^test_/, '').replace(/_/g, ' '));
|
|
24
|
+
}
|
|
25
|
+
// Go: func TestSomething(t *testing.T)
|
|
26
|
+
const goPattern = /^\s*func\s+(Test[a-zA-Z0-9_]+)\s*\(/gm;
|
|
27
|
+
for (const m of content.matchAll(goPattern)) {
|
|
28
|
+
add(m[1]);
|
|
29
|
+
}
|
|
30
|
+
// Rust: #[test] fn something()
|
|
31
|
+
const rustPattern = /#\[(?:tokio::)?test\]\s*(?:async\s+)?fn\s+([a-zA-Z0-9_]+)\s*\(/gm;
|
|
32
|
+
for (const m of content.matchAll(rustPattern)) {
|
|
33
|
+
add(m[1].replace(/_/g, ' '));
|
|
34
|
+
}
|
|
35
|
+
return names;
|
|
36
|
+
}
|
package/dist/version.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
function readPackageVersion() {
|
|
5
|
+
try {
|
|
6
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
// Works both from src/ (dev/ts) and dist/ (compiled)
|
|
8
|
+
const candidates = [
|
|
9
|
+
path.resolve(__dirname, '../package.json'),
|
|
10
|
+
path.resolve(__dirname, '../../package.json'),
|
|
11
|
+
];
|
|
12
|
+
for (const p of candidates) {
|
|
13
|
+
if (fs.existsSync(p)) {
|
|
14
|
+
const pkg = JSON.parse(fs.readFileSync(p, 'utf8'));
|
|
15
|
+
if (pkg.version)
|
|
16
|
+
return pkg.version;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
// fallback
|
|
22
|
+
}
|
|
23
|
+
return '0.3.0';
|
|
24
|
+
}
|
|
25
|
+
export const BASTION_VERSION = readPackageVersion();
|
package/package.json
CHANGED
|
@@ -1,6 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bastion-gate",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Multi-agent parallel development & hard-gate CLI for AI coding agents. DAG waves, worktree isolation, red-first lock, baseline CI gate.",
|
|
5
|
+
"author": "mmxz",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/maomuxz/bastion-gate.git"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/maomuxz/bastion-gate#readme",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/maomuxz/bastion-gate/issues"
|
|
13
|
+
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"bin": {
|
|
16
|
+
"bastion": "./dist/cli.js",
|
|
17
|
+
"bastion-gate": "./dist/cli.js"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"action.yml",
|
|
22
|
+
"README.md",
|
|
23
|
+
"LICENSE"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsc",
|
|
27
|
+
"build:test": "tsc -p tsconfig.test.json",
|
|
28
|
+
"test": "npm run build && npm run build:test && node --test dist-test/tests/*.test.js",
|
|
29
|
+
"demo": "npm run build:test && node dist-test/demo/run-demo.js"
|
|
30
|
+
},
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=18.0.0"
|
|
33
|
+
},
|
|
34
|
+
"keywords": [
|
|
35
|
+
"ai-agent",
|
|
36
|
+
"multi-agent",
|
|
37
|
+
"swarm",
|
|
38
|
+
"worktree",
|
|
39
|
+
"testing",
|
|
40
|
+
"tdd",
|
|
41
|
+
"ci",
|
|
42
|
+
"gate",
|
|
43
|
+
"claude-code",
|
|
44
|
+
"cursor",
|
|
45
|
+
"codex"
|
|
46
|
+
],
|
|
47
|
+
"license": "MIT",
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@types/node": "^22.0.0",
|
|
50
|
+
"typescript": "^5.7.0"
|
|
51
|
+
}
|
|
52
|
+
}
|