@andorra-labs/code 0.1.8 → 0.1.10
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/THIRD_PARTY_NOTICES.md +2 -1
- package/dist/src/account-presentation.d.ts +11 -0
- package/dist/src/account-presentation.js +29 -2
- package/dist/src/agent-execution.js +57 -4
- package/dist/src/agent-mcp.d.ts +12 -0
- package/dist/src/agent-mcp.js +81 -2
- package/dist/src/app-server/protocol.d.ts +120 -1
- package/dist/src/app-server/protocol.js +8 -1
- package/dist/src/app-server/reasoning.d.ts +0 -8
- package/dist/src/app-server/reasoning.js +15 -28
- package/dist/src/app-server.d.ts +32 -0
- package/dist/src/app-server.js +214 -21
- package/dist/src/auth/AuthManager.d.ts +15 -0
- package/dist/src/auth/AuthManager.js +66 -7
- package/dist/src/auth/index.d.ts +1 -1
- package/dist/src/auth/index.js +1 -1
- package/dist/src/auth/store.d.ts +17 -1
- package/dist/src/auth/store.js +25 -2
- package/dist/src/browser-runner.js +1 -2
- package/dist/src/browser-server.js +10 -2
- package/dist/src/browser-session.js +6 -2
- package/dist/src/browser-stealth.d.ts +29 -0
- package/dist/src/browser-stealth.js +166 -0
- package/dist/src/browser-ui/app.js +123 -28
- package/dist/src/browser-ui/icons/chevron-right.svg +8 -0
- package/dist/src/browser-ui/index.html +8 -8
- package/dist/src/browser-ui/style.css +199 -171
- package/dist/src/browser-ui/tokens.css +198 -0
- package/dist/src/browser-view.d.ts +57 -9
- package/dist/src/browser-view.js +187 -36
- package/dist/src/cli.js +31 -9
- package/dist/src/coding-tools.js +9 -5
- package/dist/src/command-screens.js +4 -4
- package/dist/src/commands.d.ts +1 -1
- package/dist/src/commands.js +3 -2
- package/dist/src/completion-gates.d.ts +35 -0
- package/dist/src/completion-gates.js +25 -0
- package/dist/src/completion.d.ts +7 -1
- package/dist/src/completion.js +37 -4
- package/dist/src/config.d.ts +1 -1
- package/dist/src/config.js +2 -2
- package/dist/src/context-budget.d.ts +11 -0
- package/dist/src/context-budget.js +13 -0
- package/dist/src/decision/DecisionEngine.d.ts +5 -1
- package/dist/src/decision/DecisionManager.d.ts +1 -0
- package/dist/src/decision/DecisionManager.js +14 -3
- package/dist/src/decision/FactContinuations.d.ts +6 -0
- package/dist/src/decision/FactContinuations.js +9 -1
- package/dist/src/decision/FactServiceGate.js +1 -1
- package/dist/src/decision/checks.js +1 -1
- package/dist/src/decision/hostedSkills.d.ts +37 -0
- package/dist/src/decision/hostedSkills.js +64 -0
- package/dist/src/decision/providers/AndorraDecisionProvider.d.ts +10 -2
- package/dist/src/decision/providers/AndorraDecisionProvider.js +121 -10
- package/dist/src/default-graph.d.ts +11 -0
- package/dist/src/default-graph.js +20 -0
- package/dist/src/duration.d.ts +13 -2
- package/dist/src/duration.js +27 -3
- package/dist/src/file-diff.d.ts +105 -0
- package/dist/src/file-diff.js +244 -0
- package/dist/src/graph-manager-chat.d.ts +302 -0
- package/dist/src/graph-manager-chat.js +940 -0
- package/dist/src/graph-runner.js +6 -0
- package/dist/src/graph-server.d.ts +9 -0
- package/dist/src/graph-server.js +171 -20
- package/dist/src/graph-studio-features.js +2 -2
- package/dist/src/graph-sync.js +5 -2
- package/dist/src/graph-ui/app.js +369 -183
- package/dist/src/graph-ui/controls.css +55 -32
- package/dist/src/graph-ui/controls.js +85 -9
- package/dist/src/graph-ui/edge-router.js +114 -13
- package/dist/src/graph-ui/embed.js +32 -17
- package/dist/src/graph-ui/icons.js +1 -0
- package/dist/src/graph-ui/index.html +4 -4
- package/dist/src/graph-ui/library.css +4 -10
- package/dist/src/graph-ui/manager-markdown.js +155 -0
- package/dist/src/graph-ui/manager-state.js +191 -0
- package/dist/src/graph-ui/manager.css +161 -0
- package/dist/src/graph-ui/manager.js +700 -0
- package/dist/src/graph-ui/skill-picker.js +6 -6
- package/dist/src/graph-ui/studio-canvas.js +17 -15
- package/dist/src/graph-ui/studio.css +24 -23
- package/dist/src/graph-ui/studio.js +69 -48
- package/dist/src/graph-ui/style.css +128 -93
- package/dist/src/graph-ui/theme.js +2 -2
- package/dist/src/graph-ui/tokens.css +217 -151
- package/dist/src/graphs.d.ts +76 -2
- package/dist/src/graphs.js +172 -9
- package/dist/src/hardened-runtime.js +8 -2
- package/dist/src/mcp.d.ts +75 -0
- package/dist/src/mcp.js +240 -8
- package/dist/src/membership-errors.d.ts +14 -0
- package/dist/src/membership-errors.js +24 -1
- package/dist/src/membership.d.ts +20 -0
- package/dist/src/membership.js +45 -16
- package/dist/src/palette.d.ts +25 -8
- package/dist/src/palette.js +26 -8
- package/dist/src/provider-engine.d.ts +4 -4
- package/dist/src/provider-engine.js +39 -22
- package/dist/src/provider-keys.d.ts +5 -1
- package/dist/src/provider-keys.js +7 -3
- package/dist/src/provider-settings.d.ts +4 -1
- package/dist/src/provider-settings.js +46 -5
- package/dist/src/providers.d.ts +24 -0
- package/dist/src/providers.js +47 -2
- package/dist/src/qa/guidance.d.ts +26 -0
- package/dist/src/qa/guidance.js +46 -0
- package/dist/src/qa/index.d.ts +1 -8
- package/dist/src/qa/index.js +1 -16
- package/dist/src/qa/profile/QaProfile.d.ts +5 -1
- package/dist/src/qa/profile/QaProfile.js +6 -2
- package/dist/src/qa/runtime/ProcessManager.d.ts +20 -2
- package/dist/src/qa/runtime/ProcessManager.js +69 -13
- package/dist/src/qa/tools.d.ts +19 -1
- package/dist/src/qa/tools.js +20 -145
- package/dist/src/react-runtime.d.ts +11 -0
- package/dist/src/react-runtime.js +203 -53
- package/dist/src/remote/engine-pool.js +21 -6
- package/dist/src/run-progress.d.ts +6 -0
- package/dist/src/run-progress.js +7 -0
- package/dist/src/runtime.d.ts +8 -0
- package/dist/src/screen-selection.d.ts +38 -0
- package/dist/src/screen-selection.js +103 -0
- package/dist/src/session-changes.d.ts +117 -0
- package/dist/src/session-changes.js +796 -0
- package/dist/src/session-skills.d.ts +75 -0
- package/dist/src/session-skills.js +151 -0
- package/dist/src/side-panel.d.ts +1 -1
- package/dist/src/side-panel.js +6 -12
- package/dist/src/skill-commands.js +1 -1
- package/dist/src/skills/bundled/control-browser/SKILL.md +9 -1
- package/dist/src/skills/bundled/graph-manager/SKILL.md +8 -0
- package/dist/src/skills/bundled/provenance.json +3 -3
- package/dist/src/skills/bundled/web-gui-tester/SKILL.md +1 -1
- package/dist/src/stall-recovery.d.ts +33 -0
- package/dist/src/stall-recovery.js +83 -0
- package/dist/src/subagent-run.js +1 -2
- package/dist/src/telemetry/schema.d.ts +1 -1
- package/dist/src/telemetry/schema.js +1 -2
- package/dist/src/terminal-ui.d.ts +66 -22
- package/dist/src/terminal-ui.js +327 -92
- package/dist/src/tool-diff-stats.d.ts +9 -0
- package/dist/src/tool-diff-stats.js +20 -0
- package/dist/src/tool-names.d.ts +1 -1
- package/dist/src/tool-result-filter.js +1 -1
- package/dist/src/tools.js +26 -2
- package/dist/src/transcript.d.ts +11 -0
- package/dist/src/transcript.js +23 -3
- package/dist/src/types.d.ts +24 -4
- package/dist/src/usage-analytics.d.ts +7 -0
- package/dist/src/usage-analytics.js +55 -15
- package/docs/concepts/README.md +1 -1
- package/docs/concepts/limits.md +9 -0
- package/docs/guides/desktop-app.md +1 -1
- package/docs/guides/graph-builder.md +16 -1
- package/docs/guides/tui.md +9 -9
- package/docs/reference/slash-commands.md +2 -1
- package/docs/superpowers/plans/2026-11-13-graph-manager-chat.md +203 -0
- package/docs/superpowers/plans/2026-11-14-jev-fair-use-pricing.md +79 -0
- package/docs/superpowers/specs/2026-11-13-graph-manager-chat-design.md +182 -0
- package/docs/superpowers/specs/2026-11-14-jev-fair-use-pricing-design.md +156 -0
- package/package.json +1 -1
- package/tests/chat-side-panel-test-plan.md +1 -1
- package/dist/src/qa/api/http-runner.d.ts +0 -3
- package/dist/src/qa/api/http-runner.js +0 -47
- package/dist/src/qa/git/ChangeDetector.d.ts +0 -26
- package/dist/src/qa/git/ChangeDetector.js +0 -177
- package/dist/src/qa/git/DiffReviewer.d.ts +0 -28
- package/dist/src/qa/git/DiffReviewer.js +0 -115
- package/dist/src/qa/orchestrator/ChangeClassifier.d.ts +0 -14
- package/dist/src/qa/orchestrator/ChangeClassifier.js +0 -28
- package/dist/src/qa/orchestrator/MergeGate.d.ts +0 -14
- package/dist/src/qa/orchestrator/MergeGate.js +0 -40
- package/dist/src/qa/orchestrator/QaOrchestrator.d.ts +0 -79
- package/dist/src/qa/orchestrator/QaOrchestrator.js +0 -373
- package/dist/src/qa/runners/CommandRunner.d.ts +0 -22
- package/dist/src/qa/runners/CommandRunner.js +0 -96
- package/dist/src/qa/runners/TestRunner.d.ts +0 -21
- package/dist/src/qa/runners/TestRunner.js +0 -66
- package/dist/src/qa/runtime/RuntimeSmoke.d.ts +0 -11
- package/dist/src/qa/runtime/RuntimeSmoke.js +0 -78
- package/dist/src/qa/runtime-detect.d.ts +0 -10
- package/dist/src/qa/runtime-detect.js +0 -72
- package/dist/src/qa/security/DependencyScanner.d.ts +0 -19
- package/dist/src/qa/security/DependencyScanner.js +0 -167
- package/dist/src/qa/security/SecretScanner.d.ts +0 -3
- package/dist/src/qa/security/SecretScanner.js +0 -55
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { getQaProcessManager } from './ProcessManager.js';
|
|
2
|
-
const DEFAULT_STARTUP_TIMEOUT_MS = 30_000;
|
|
3
|
-
const CRASH_PATTERNS = [
|
|
4
|
-
{ pattern: /uncaughtException|unhandledRejection/i, message: 'uncaught exception during startup' },
|
|
5
|
-
{ pattern: /Cannot find module|MODULE_NOT_FOUND/, message: 'module resolution failure during startup' },
|
|
6
|
-
{ pattern: /EADDRINUSE/, message: 'startup port already in use' },
|
|
7
|
-
{ pattern: /Traceback \(most recent call last\)/, message: 'Python traceback during startup' },
|
|
8
|
-
{ pattern: /\b(TypeError|ReferenceError|SyntaxError):/, message: 'runtime error during startup' },
|
|
9
|
-
{ pattern: /\bFATAL\b/, message: 'fatal startup error' },
|
|
10
|
-
];
|
|
11
|
-
/**
|
|
12
|
-
* Boot the configured startup command, wait for its health URL (or a short
|
|
13
|
-
* grace window), scan the log for crash signatures, then always stop it.
|
|
14
|
-
*/
|
|
15
|
-
export async function runRuntimeSmoke(options) {
|
|
16
|
-
const startup = options.profile.startup;
|
|
17
|
-
if (!startup) {
|
|
18
|
-
return { id: 'runtime_smoke', category: 'runtime', status: 'skipped', durationMs: 0, summary: 'no startup command configured (.andorra/qa.yaml qa.startup.command)' };
|
|
19
|
-
}
|
|
20
|
-
const manager = getQaProcessManager(options.workspace);
|
|
21
|
-
const startedAt = Date.now();
|
|
22
|
-
const timeout = startup.timeoutMs ?? DEFAULT_STARTUP_TIMEOUT_MS;
|
|
23
|
-
try {
|
|
24
|
-
await manager.start({ id: 'startup', command: startup.command, logDir: options.logDir });
|
|
25
|
-
let readiness = { ready: true };
|
|
26
|
-
if (startup.healthUrl) {
|
|
27
|
-
readiness = await manager.waitForUrl(startup.healthUrl, timeout, options.signal, 'startup');
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
await new Promise(resolve => {
|
|
31
|
-
const timer = setTimeout(resolve, Math.min(timeout, 5_000));
|
|
32
|
-
options.signal.addEventListener('abort', () => { clearTimeout(timer); resolve(); }, { once: true });
|
|
33
|
-
});
|
|
34
|
-
const info = manager.get('startup');
|
|
35
|
-
if (!info?.running)
|
|
36
|
-
readiness = { ready: false, reason: `startup process exited (${info?.exitCode ?? info?.exitSignal ?? 'unknown'}) before readiness` };
|
|
37
|
-
}
|
|
38
|
-
const log = manager.logs('startup', 32_768);
|
|
39
|
-
const crashes = [];
|
|
40
|
-
for (const line of log.split('\n')) {
|
|
41
|
-
for (const rule of CRASH_PATTERNS) {
|
|
42
|
-
if (rule.pattern.test(line)) {
|
|
43
|
-
crashes.push({ severity: 'error', message: `${rule.message}: ${line.trim().slice(0, 300)}`, code: 'runtime-crash' });
|
|
44
|
-
break;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
if (crashes.length >= 10)
|
|
48
|
-
break;
|
|
49
|
-
}
|
|
50
|
-
const durationMs = Date.now() - startedAt;
|
|
51
|
-
if (!readiness.ready) {
|
|
52
|
-
return {
|
|
53
|
-
id: 'runtime_smoke', category: 'runtime', status: 'failed', durationMs,
|
|
54
|
-
summary: `startup never became healthy: ${readiness.reason}`,
|
|
55
|
-
errors: crashes.length ? crashes : undefined,
|
|
56
|
-
importantOutput: log.split('\n').filter(l => l.trim()).slice(-15).map(l => l.slice(0, 300)),
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
if (crashes.length) {
|
|
60
|
-
return {
|
|
61
|
-
id: 'runtime_smoke', category: 'runtime', status: 'failed', durationMs,
|
|
62
|
-
summary: `startup logged fatal errors (${crashes.length})`,
|
|
63
|
-
errors: crashes,
|
|
64
|
-
importantOutput: crashes.map(issue => issue.message),
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
return { id: 'runtime_smoke', category: 'runtime', status: 'passed', durationMs, summary: `startup ran cleanly${startup.healthUrl ? ` and answered ${startup.healthUrl}` : ''}` };
|
|
68
|
-
}
|
|
69
|
-
catch (error) {
|
|
70
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
71
|
-
if (/aborted/i.test(message))
|
|
72
|
-
throw error;
|
|
73
|
-
return { id: 'runtime_smoke', category: 'runtime', status: 'blocked', durationMs: Date.now() - startedAt, summary: `startup could not launch: ${message.split('\n')[0]}` };
|
|
74
|
-
}
|
|
75
|
-
finally {
|
|
76
|
-
await manager.stop('startup').catch(() => { });
|
|
77
|
-
}
|
|
78
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { RuntimeCapabilities, ShellEnvironment } from './types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Detect the host shell for QA execution (plan §2.2). Interpreter presence is
|
|
4
|
-
* probed rather than assumed; the default kind still decides command syntax.
|
|
5
|
-
*/
|
|
6
|
-
export declare function detectShellEnvironment(): ShellEnvironment;
|
|
7
|
-
/** Probe once per process; a missing tool answers instantly, a present one within 2s. */
|
|
8
|
-
export declare function detectRuntimeCapabilities(force?: boolean): Promise<RuntimeCapabilities>;
|
|
9
|
-
/** Compact per-tool lines for the agent context: only availability plus one-line versions. */
|
|
10
|
-
export declare function describeRuntimeCapabilities(capabilities?: RuntimeCapabilities): Promise<string>;
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { execFile } from 'node:child_process';
|
|
2
|
-
import { promisify } from 'node:util';
|
|
3
|
-
import { existsSync } from 'node:fs';
|
|
4
|
-
import path from 'node:path';
|
|
5
|
-
import { defaultShellKind, shellInvocation } from '../shell.js';
|
|
6
|
-
const executeFile = promisify(execFile);
|
|
7
|
-
const PROBE_TIMEOUT_MS = 2_000;
|
|
8
|
-
/** Probe arguments per tool; most accept --version, a few have their own spelling. */
|
|
9
|
-
const PROBES = {
|
|
10
|
-
node: ['--version'], npm: ['--version'], npx: ['--version'], pnpm: ['--version'], yarn: ['--version'], bun: ['--version'],
|
|
11
|
-
python: ['--version'], python3: ['--version'], pip: ['--version'], pytest: ['--version'], uv: ['--version'],
|
|
12
|
-
git: ['--version'], gh: ['--version'], cargo: ['--version'], rustc: ['--version'], go: ['version'],
|
|
13
|
-
dotnet: ['--version'], java: ['-version'], mvn: ['-version'], gradle: ['--version'],
|
|
14
|
-
docker: ['--version'], 'docker-compose': ['--version'],
|
|
15
|
-
};
|
|
16
|
-
async function probe(tool, args) {
|
|
17
|
-
try {
|
|
18
|
-
// Most tools print the version on stdout; java -version uses stderr. Either counts.
|
|
19
|
-
const { stdout, stderr } = await executeFile(tool, args, { windowsHide: true, timeout: PROBE_TIMEOUT_MS, maxBuffer: 64 * 1024, encoding: 'utf8' });
|
|
20
|
-
const line = (stdout || stderr).split(/\r?\n/).map(part => part.trim()).find(Boolean) ?? '';
|
|
21
|
-
return { available: true, version: line.slice(0, 120) };
|
|
22
|
-
}
|
|
23
|
-
catch {
|
|
24
|
-
return { available: false };
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
function platform() {
|
|
28
|
-
return process.platform === 'win32' ? 'windows' : process.platform === 'darwin' ? 'macos' : 'linux';
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Detect the host shell for QA execution (plan §2.2). Interpreter presence is
|
|
32
|
-
* probed rather than assumed; the default kind still decides command syntax.
|
|
33
|
-
*/
|
|
34
|
-
export function detectShellEnvironment() {
|
|
35
|
-
const kind = defaultShellKind;
|
|
36
|
-
const executable = (() => {
|
|
37
|
-
// An interpreter may be unavailable (e.g. Git Bash absent on Windows); report the
|
|
38
|
-
// kind rather than failing detection for a host that can still run other probes.
|
|
39
|
-
try {
|
|
40
|
-
const resolved = shellInvocation('exit 0', kind).executable;
|
|
41
|
-
return existsSync(resolved) || !path.isAbsolute(resolved) ? resolved : `${resolved} (not found)`;
|
|
42
|
-
}
|
|
43
|
-
catch {
|
|
44
|
-
return kind;
|
|
45
|
-
}
|
|
46
|
-
})();
|
|
47
|
-
const prefixes = { powershell: ['-Command'], bash: ['-c'], posix: ['-c'] };
|
|
48
|
-
return { platform: platform(), executable, argsPrefix: prefixes[kind] };
|
|
49
|
-
}
|
|
50
|
-
let cached;
|
|
51
|
-
/** Probe once per process; a missing tool answers instantly, a present one within 2s. */
|
|
52
|
-
export function detectRuntimeCapabilities(force = false) {
|
|
53
|
-
if (!cached || force)
|
|
54
|
-
cached = (async () => {
|
|
55
|
-
const entries = await Promise.all(Object.entries(PROBES).map(async ([tool, args]) => [tool, await probe(tool, args)]));
|
|
56
|
-
return { shell: detectShellEnvironment(), tools: Object.fromEntries(entries) };
|
|
57
|
-
})();
|
|
58
|
-
return cached;
|
|
59
|
-
}
|
|
60
|
-
/** Compact per-tool lines for the agent context: only availability plus one-line versions. */
|
|
61
|
-
export async function describeRuntimeCapabilities(capabilities) {
|
|
62
|
-
const caps = capabilities ?? await detectRuntimeCapabilities();
|
|
63
|
-
const order = ['node', 'npm', 'pnpm', 'yarn', 'bun', 'python', 'pytest', 'uv', 'git', 'gh', 'cargo', 'go', 'dotnet', 'java', 'mvn', 'gradle', 'docker', 'docker-compose'];
|
|
64
|
-
const lines = [`Shell: ${caps.shell.platform} ${path.basename(caps.shell.executable)}`];
|
|
65
|
-
for (const tool of order) {
|
|
66
|
-
const entry = caps.tools[tool];
|
|
67
|
-
if (!entry)
|
|
68
|
-
continue;
|
|
69
|
-
lines.push(`${tool}: ${entry.available ? entry.version ?? 'available' : 'unavailable'}`);
|
|
70
|
-
}
|
|
71
|
-
return lines.join('\n');
|
|
72
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { QaIssue, QaSeverityCascade } from '../types.js';
|
|
2
|
-
export interface DependencyAuditOutcome {
|
|
3
|
-
status: 'passed' | 'failed' | 'blocked';
|
|
4
|
-
summary: string;
|
|
5
|
-
issues: QaIssue[];
|
|
6
|
-
importantOutput: string[];
|
|
7
|
-
durationMs: number;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* `npm/pnpm/yarn audit` with tolerant JSON parsing. The check fails when any
|
|
11
|
-
* advisory severity is in `failOn`; unsupported ecosystems report blocked
|
|
12
|
-
* rather than silently passing.
|
|
13
|
-
*/
|
|
14
|
-
export declare function runDependencyAudit(options: {
|
|
15
|
-
workspace: string;
|
|
16
|
-
packageManager?: string;
|
|
17
|
-
failOn: QaSeverityCascade[];
|
|
18
|
-
signal: AbortSignal;
|
|
19
|
-
}): Promise<DependencyAuditOutcome>;
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import { executeShell } from '../../shell.js';
|
|
2
|
-
const AUDIT_TIMEOUT_MS = 120_000;
|
|
3
|
-
const NO_VULNS_COUNTS = { critical: 0, high: 0, moderate: 0, low: 0, info: 0 };
|
|
4
|
-
function asRecord(value) {
|
|
5
|
-
return value && typeof value === 'object' && !Array.isArray(value) ? value : undefined;
|
|
6
|
-
}
|
|
7
|
-
function severityOf(value) {
|
|
8
|
-
return typeof value === 'string' ? value.toLowerCase() : 'unknown';
|
|
9
|
-
}
|
|
10
|
-
function metadataCounts(metadata) {
|
|
11
|
-
const counts = asRecord(asRecord(metadata)?.vulnerabilities);
|
|
12
|
-
if (!counts)
|
|
13
|
-
return {};
|
|
14
|
-
const result = {};
|
|
15
|
-
for (const [key, value] of Object.entries(counts))
|
|
16
|
-
if (typeof value === 'number')
|
|
17
|
-
result[key.toLowerCase()] = value;
|
|
18
|
-
return result;
|
|
19
|
-
}
|
|
20
|
-
/** Tolerant parse of `npm audit --json` (report v1 and v2) and `pnpm audit --json`. */
|
|
21
|
-
function parseAuditJson(stdout) {
|
|
22
|
-
const start = stdout.indexOf('{');
|
|
23
|
-
if (start < 0)
|
|
24
|
-
return undefined;
|
|
25
|
-
let root;
|
|
26
|
-
try {
|
|
27
|
-
root = JSON.parse(stdout.slice(start));
|
|
28
|
-
}
|
|
29
|
-
catch {
|
|
30
|
-
return undefined;
|
|
31
|
-
}
|
|
32
|
-
const data = asRecord(root);
|
|
33
|
-
if (!data)
|
|
34
|
-
return undefined;
|
|
35
|
-
const vulnerabilities = [];
|
|
36
|
-
const named = asRecord(data.vulnerabilities);
|
|
37
|
-
if (named) {
|
|
38
|
-
for (const [pkg, entry] of Object.entries(named)) {
|
|
39
|
-
const record = asRecord(entry);
|
|
40
|
-
if (!record)
|
|
41
|
-
continue;
|
|
42
|
-
let title;
|
|
43
|
-
if (Array.isArray(record.via)) {
|
|
44
|
-
for (const via of record.via) {
|
|
45
|
-
const advisory = asRecord(via);
|
|
46
|
-
if (advisory && typeof advisory.title === 'string') {
|
|
47
|
-
title = advisory.title;
|
|
48
|
-
break;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
vulnerabilities.push({ name: pkg, severity: severityOf(record.severity), title });
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
const advisories = asRecord(data.advisories);
|
|
56
|
-
if (advisories) {
|
|
57
|
-
for (const entry of Object.values(advisories)) {
|
|
58
|
-
const advisory = asRecord(entry);
|
|
59
|
-
if (!advisory)
|
|
60
|
-
continue;
|
|
61
|
-
vulnerabilities.push({
|
|
62
|
-
name: typeof advisory.module_name === 'string' ? advisory.module_name : 'unknown',
|
|
63
|
-
severity: severityOf(advisory.severity),
|
|
64
|
-
title: typeof advisory.title === 'string' ? advisory.title : undefined,
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
const counts = metadataCounts(data.metadata);
|
|
69
|
-
if (!vulnerabilities.length && !Object.keys(counts).length)
|
|
70
|
-
return undefined;
|
|
71
|
-
return { vulnerabilities, counts };
|
|
72
|
-
}
|
|
73
|
-
/** Newer pnpm emits newline-delimited JSON findings; older pnpm and yarn emit newline-delimited events. */
|
|
74
|
-
function parseAuditJsonLines(stdout) {
|
|
75
|
-
const vulnerabilities = [];
|
|
76
|
-
let counts = {};
|
|
77
|
-
let sawAny = false;
|
|
78
|
-
for (const line of stdout.split('\n')) {
|
|
79
|
-
const trimmed = line.trim();
|
|
80
|
-
if (!trimmed.startsWith('{'))
|
|
81
|
-
continue;
|
|
82
|
-
let event;
|
|
83
|
-
try {
|
|
84
|
-
event = JSON.parse(trimmed);
|
|
85
|
-
}
|
|
86
|
-
catch {
|
|
87
|
-
continue;
|
|
88
|
-
}
|
|
89
|
-
const record = asRecord(event);
|
|
90
|
-
if (!record)
|
|
91
|
-
continue;
|
|
92
|
-
sawAny = true;
|
|
93
|
-
const advisory = asRecord(record.advisory);
|
|
94
|
-
if (advisory) {
|
|
95
|
-
vulnerabilities.push({
|
|
96
|
-
name: typeof advisory.module_name === 'string' ? advisory.module_name : 'unknown',
|
|
97
|
-
severity: severityOf(advisory.severity),
|
|
98
|
-
title: typeof advisory.title === 'string' ? advisory.title : undefined,
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
const finding = asRecord(record.finding);
|
|
102
|
-
const findingSeverity = finding ? asRecord(finding.severity) : undefined;
|
|
103
|
-
if (findingSeverity) {
|
|
104
|
-
const [severity] = Object.keys(findingSeverity);
|
|
105
|
-
if (severity)
|
|
106
|
-
vulnerabilities.push({ name: String(record.package ?? 'unknown'), severity: severityOf(severity) });
|
|
107
|
-
}
|
|
108
|
-
const lineCounts = metadataCounts(record.metadata);
|
|
109
|
-
if (Object.keys(lineCounts).length)
|
|
110
|
-
counts = lineCounts;
|
|
111
|
-
}
|
|
112
|
-
if (!sawAny)
|
|
113
|
-
return undefined;
|
|
114
|
-
return { vulnerabilities, counts };
|
|
115
|
-
}
|
|
116
|
-
function mergedCounts(report) {
|
|
117
|
-
if (Object.keys(report.counts).length)
|
|
118
|
-
return report.counts;
|
|
119
|
-
const counts = { ...NO_VULNS_COUNTS };
|
|
120
|
-
for (const vuln of report.vulnerabilities)
|
|
121
|
-
counts[vuln.severity] = (counts[vuln.severity] ?? 0) + 1;
|
|
122
|
-
return counts;
|
|
123
|
-
}
|
|
124
|
-
function formatCounts(counts) {
|
|
125
|
-
const parts = ['critical', 'high', 'moderate', 'low', 'info']
|
|
126
|
-
.filter(key => (counts[key] ?? 0) > 0)
|
|
127
|
-
.map(key => `${counts[key]} ${key}`);
|
|
128
|
-
return parts.length ? parts.join(', ') : 'no advisories';
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* `npm/pnpm/yarn audit` with tolerant JSON parsing. The check fails when any
|
|
132
|
-
* advisory severity is in `failOn`; unsupported ecosystems report blocked
|
|
133
|
-
* rather than silently passing.
|
|
134
|
-
*/
|
|
135
|
-
export async function runDependencyAudit(options) {
|
|
136
|
-
const manager = options.packageManager ?? 'npm';
|
|
137
|
-
if (!['npm', 'pnpm', 'yarn'].includes(manager)) {
|
|
138
|
-
return { status: 'blocked', summary: `no built-in dependency audit for package manager "${manager}"`, issues: [], importantOutput: [], durationMs: 0 };
|
|
139
|
-
}
|
|
140
|
-
const started = Date.now();
|
|
141
|
-
let result;
|
|
142
|
-
try {
|
|
143
|
-
result = await executeShell(`${manager} audit --json`, options.workspace, AUDIT_TIMEOUT_MS, options.signal);
|
|
144
|
-
}
|
|
145
|
-
catch (error) {
|
|
146
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
147
|
-
return { status: 'blocked', summary: `dependency audit could not run: ${message.split('\n')[0]}`, issues: [], importantOutput: [], durationMs: Date.now() - started };
|
|
148
|
-
}
|
|
149
|
-
const durationMs = Date.now() - started;
|
|
150
|
-
const report = parseAuditJson(result.stdout) ?? parseAuditJsonLines(result.stdout);
|
|
151
|
-
if (!report) {
|
|
152
|
-
const firstLine = (result.stderr || result.stdout || `exit ${result.exitCode ?? result.exitSignal}`).split('\n').find(line => line.trim()) ?? 'no output';
|
|
153
|
-
return { status: 'blocked', summary: `${manager} audit produced no parseable report: ${firstLine.slice(0, 200)}`, issues: [], importantOutput: [], durationMs };
|
|
154
|
-
}
|
|
155
|
-
const counts = mergedCounts(report);
|
|
156
|
-
const failing = report.vulnerabilities.filter(vuln => options.failOn.includes(vuln.severity));
|
|
157
|
-
const failingByCount = options.failOn.some(severity => (counts[severity] ?? 0) > 0);
|
|
158
|
-
const summary = `${manager} audit: ${formatCounts(counts)}`;
|
|
159
|
-
const importantOutput = report.vulnerabilities.slice(0, 10).map(vuln => `${vuln.severity}: ${vuln.name}${vuln.title ? ` - ${vuln.title}` : ''}`);
|
|
160
|
-
const issues = report.vulnerabilities.slice(0, 25).map(vuln => ({
|
|
161
|
-
severity: options.failOn.includes(vuln.severity) ? 'error' : 'warning',
|
|
162
|
-
message: `${vuln.severity} vulnerability in ${vuln.name}${vuln.title ? `: ${vuln.title}` : ''}`,
|
|
163
|
-
code: 'dependency-vulnerability',
|
|
164
|
-
}));
|
|
165
|
-
const failed = failing.length > 0 || failingByCount;
|
|
166
|
-
return { status: failed ? 'failed' : 'passed', summary, issues, importantOutput, durationMs };
|
|
167
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { addedLines } from '../git/DiffReviewer.js';
|
|
2
|
-
const SECRET_RULES = [
|
|
3
|
-
{ name: 'aws-access-key', pattern: /\b((?:AKIA|ASIA)[0-9A-Z]{16})\b/ },
|
|
4
|
-
{ name: 'github-token', pattern: /\b(gh[pousr]_[A-Za-z0-9]{30,255})\b/ },
|
|
5
|
-
{ name: 'openai-key', pattern: /\b(sk-[A-Za-z0-9_-]{20,})\b/ },
|
|
6
|
-
{ name: 'slack-token', pattern: /\b(xox[baprs]-[A-Za-z0-9-]{10,})\b/ },
|
|
7
|
-
{ name: 'google-api-key', pattern: /\b(AIza[0-9A-Za-z_-]{35})\b/ },
|
|
8
|
-
{ name: 'private-key', pattern: /(-----BEGIN (?:RSA |EC |DSA |OPENSSH |PGP )?PRIVATE KEY(?: BLOCK)?-----)/ },
|
|
9
|
-
{ name: 'jwt', pattern: /\b(eyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,})\b/ },
|
|
10
|
-
{
|
|
11
|
-
name: 'credential-assignment',
|
|
12
|
-
pattern: /\b(?:password|passwd|pwd|secret|api[_-]?key|apikey|access[_-]?token|auth[_-]?token|client[_-]?secret)\b["']?\s*[:=]\s*["']([^"'\n]{8,})["']/i,
|
|
13
|
-
valueGroup: 1,
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
name: 'connection-string-password',
|
|
17
|
-
pattern: /\b(?:postgres(?:ql)?|mysql|mongodb(?:\+srv)?|redis|amqps?|mssql):\/\/[^\s/:@]+:([^@\s/]{4,})@/i,
|
|
18
|
-
valueGroup: 1,
|
|
19
|
-
},
|
|
20
|
-
];
|
|
21
|
-
/** Template/placeholder shapes that are credentials in name only. */
|
|
22
|
-
const PLACEHOLDER = /\$\{|\{\{|<[a-z0-9_.-]+>|\.\.\.|xxxx|your[-_]|changeme|placeholder|example/i;
|
|
23
|
-
function redact(value) {
|
|
24
|
-
const visible = value.slice(0, 4);
|
|
25
|
-
return visible + '*'.repeat(Math.min(Math.max(value.length - visible.length, 4), 24));
|
|
26
|
-
}
|
|
27
|
-
/** Scan diff-added lines for credential-shaped strings. Issues carry redacted values. */
|
|
28
|
-
export function scanAddedLinesForSecrets(diff) {
|
|
29
|
-
const issues = [];
|
|
30
|
-
if (!diff)
|
|
31
|
-
return issues;
|
|
32
|
-
for (const line of addedLines(diff)) {
|
|
33
|
-
if (!line.text)
|
|
34
|
-
continue;
|
|
35
|
-
for (const rule of SECRET_RULES) {
|
|
36
|
-
const match = rule.pattern.exec(line.text);
|
|
37
|
-
if (!match)
|
|
38
|
-
continue;
|
|
39
|
-
const value = (rule.valueGroup !== undefined ? match[rule.valueGroup] : match[1]) ?? match[0];
|
|
40
|
-
if (PLACEHOLDER.test(value))
|
|
41
|
-
continue;
|
|
42
|
-
issues.push({
|
|
43
|
-
file: line.file,
|
|
44
|
-
line: line.line,
|
|
45
|
-
severity: 'error',
|
|
46
|
-
message: `possible secret (${rule.name}): ${redact(value)}`,
|
|
47
|
-
code: 'secret',
|
|
48
|
-
});
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
if (issues.length >= 50)
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
return issues;
|
|
55
|
-
}
|