Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Keeps the GitHub Actions of the workflows current (AI.duino itself has no npm dependencies)
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: monthly
29 changes: 22 additions & 7 deletions .github/scripts/check-cli-providers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
* Licensed under the Apache License, Version 2.0
*
* The CLIs change their options without AI.duino changing anything. This script
* takes the options AI.duino really uses (buildArgs() of each agent module in
* localProviders/processProviders) and checks that each one still appears in the
* help text of the installed CLI. No login needed.
*
* The options live in the extension code, not in providerConfigs.js: a failed
* check needs a code change and a release, the remote config cannot fix it.
* takes the options AI.duino really uses and checks that each one still appears
* in the help text of the installed CLI. No login needed. Both sources count:
* - the "cli.args" templates in providerConfigs.js (AI.duino ≥ 2.9.0 uses them,
* so a failure here can be fixed with a config update)
* - buildArgs() of each agent module (older versions and the fallback use them;
* a failure here only means older installations are affected)
*
* Usage: node .github/scripts/check-cli-providers.js [--all] [--install]
* --all: a missing CLI is an error (CI, where all CLIs are installed)
Expand Down Expand Up @@ -41,6 +41,7 @@ const CLIS = {
mistralVibe: { install: 'curl -LsSf https://mistral.ai/vibe/install.sh | bash', help: [['--help']] },
openCode: { install: 'curl -fsSL https://opencode.ai/install | bash', help: [['run', '--help']] },
geminiCli: { install: 'npm install -g @google/gemini-cli', help: [['--help']] },
antigravity: { install: 'curl -fsSL https://antigravity.google/cli/install.sh | bash', help: [['--help']] },
groqCode: {
install: 'git clone --depth 1 https://github.com/NikolaiRadke/groq-code-cli.git "$RUNNER_TEMP/groq-code-cli" && cd "$RUNNER_TEMP/groq-code-cli" && npm install && npm run build && npm link',
help: [['--help']]
Expand Down Expand Up @@ -84,6 +85,20 @@ function collectOptions(buildArgs) {
return [...new Set(parts.filter(part => typeof part === 'string' && OPTION_PATTERN.test(part)))];
}

/**
* Options in the "cli.args" templates of the config
* @param {Object} cfg - Provider config
* @returns {string[]} Options
*/
function configOptions(cfg) {
const args = cfg.cli?.args;
if (!args || typeof args !== 'object') return [];
const parts = Object.entries(args)
.filter(([key, list]) => key !== 'order' && Array.isArray(list))
.flatMap(([, list]) => list);
return [...new Set(parts.filter(part => typeof part === 'string' && OPTION_PATTERN.test(part)))];
}

/**
* Find an executable in PATH
* @param {string} command - Command name
Expand Down Expand Up @@ -144,7 +159,7 @@ function main() {
}
let options;
try {
options = collectOptions(loadBuildArgs(cfg.agentModule));
options = [...new Set([...configOptions(cfg), ...collectOptions(loadBuildArgs(cfg.agentModule))])];
} catch (e) {
console.log(`✗ ${cfg.name}: ${e.message}`);
failed = true;
Expand Down
279 changes: 279 additions & 0 deletions .github/scripts/check-config-safety.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,279 @@
#!/usr/bin/env node
/*
* AI.duino - Safety check for providerConfigs.js
* Copyright 2026 Monster Maker
*
* Licensed under the Apache License, Version 2.0
*
* providerConfigs.js is JavaScript that every installation downloads and loads
* with require(). Changes are merged automatically by the weekly task, which
* reads web pages. This check makes sure the file stays configuration:
*
* 1. Code rules (always): only the four top-level constants and module.exports,
* no require/import, no access to process, globals or prototypes, no "this",
* "new" only for Error, no computed member access with variables.
* 2. Review rules (with --base <file>): changes that could send API keys elsewhere
* or make AI.duino start other programs fail here and need a human:
* hostnames, REMOTE_CONFIG_URL, agentModule, processConfig.command, risky CLI
* options, install paths, API key login and the paths in RUNTIME_CONFIG.
* Changed functions are listed (not an error), so a reviewer sees them.
*
* Usage: node .github/scripts/check-config-safety.js [--base <old providerConfigs.js>]
* Needs acorn (CI: npm install --no-save acorn@8); ACORN_PATH may point to it.
*/

"use strict";

const fs = require('fs');
const path = require('path');
const vm = require('vm');

const CONFIG_FILE = path.join(__dirname, '..', '..', 'aiduino', 'extension', 'out', 'config', 'providerConfigs.js');
const acorn = require(process.env.ACORN_PATH || 'acorn');

const ALLOWED_CONSTANTS = ['CONFIG_VERSION', 'REMOTE_CONFIG_URL', 'PROVIDER_CONFIGS', 'RUNTIME_CONFIG'];
const FORBIDDEN_NAMES = new Set([
'require', 'import', 'process', 'global', 'globalThis', 'window', 'self', 'eval', 'Function',
'constructor', 'prototype', '__proto__', '__defineGetter__', '__defineSetter__', '__lookupGetter__',
'Buffer', 'fetch', 'XMLHttpRequest', 'WebSocket', 'Reflect', 'Proxy', 'Symbol', 'WebAssembly',
'setTimeout', 'setInterval', 'setImmediate', 'queueMicrotask', 'atob', 'btoa', 'fromCharCode',
'fromCodePoint', 'arguments', 'module', 'exports', 'defineProperty', 'defineProperties',
'getPrototypeOf', 'setPrototypeOf', 'assign', 'bind', 'call', 'apply', 'caller', 'callee',
'vscode', 'child_process', 'fs', 'os', 'http', 'https', 'net'
]);
const FORBIDDEN_NODES = new Set([
'ThisExpression', 'ImportExpression', 'ImportDeclaration', 'ExportNamedDeclaration',
'ExportDefaultDeclaration', 'WithStatement', 'ClassDeclaration', 'ClassExpression',
'AwaitExpression', 'YieldExpression', 'TaggedTemplateExpression', 'DebuggerStatement',
'MetaProperty', 'Super', 'ForInStatement', 'WhileStatement', 'DoWhileStatement', 'LabeledStatement'
]);
// CLI options that can change what the agent may do on the user's machine
const RISKY_OPTION = /danger|bypass|yolo|unsafe|sandbox|approv|permission|trust|allow|exec|eval|shell|command|hook|plugin|mcp|config|env|^-c$/i;

// ===== CODE RULES =====

/**
* Walk all nodes of an AST
* @param {Object} node - Node
* @param {Function} visit - Called with (node, parent)
* @param {Object|null} parent - Parent node
*/
function walk(node, visit, parent = null) {
if (!node || typeof node.type !== 'string') return;
visit(node, parent);
for (const key of Object.keys(node)) {
if (key === 'loc' || key === 'start' || key === 'end') continue;
const value = node[key];
if (Array.isArray(value)) value.forEach(child => walk(child, visit, node));
else if (value && typeof value.type === 'string') walk(value, visit, node);
}
}

/**
* Is this the final "module.exports = { ... }" statement?
* @param {Object} node - Top-level statement
* @returns {boolean}
*/
function isExportStatement(node) {
const expr = node.type === 'ExpressionStatement' ? node.expression : null;
return Boolean(expr && expr.type === 'AssignmentExpression' && expr.operator === '='
&& expr.left.type === 'MemberExpression' && !expr.left.computed
&& expr.left.object.type === 'Identifier' && expr.left.object.name === 'module'
&& expr.left.property.type === 'Identifier' && expr.left.property.name === 'exports'
&& expr.right.type === 'ObjectExpression'
&& expr.right.properties.every(prop => prop.type === 'Property' && prop.shorthand
&& ALLOWED_CONSTANTS.includes(prop.key.name)));
}

/**
* Check the code rules
* @param {string} source - File content
* @returns {string[]} Problems
*/
function checkCode(source) {
const problems = [];
let ast;
try {
ast = acorn.parse(source, { ecmaVersion: 2022, sourceType: 'script', locations: true });
} catch (e) {
return [`syntax error: ${e.message}`];
}

for (const statement of ast.body) {
if (statement.type === 'ExpressionStatement' && statement.directive) continue;
if (isExportStatement(statement)) continue;
const ok = statement.type === 'VariableDeclaration' && statement.kind === 'const'
&& statement.declarations.every(decl => decl.id.type === 'Identifier' && ALLOWED_CONSTANTS.includes(decl.id.name));
if (!ok) problems.push(`line ${statement.loc.start.line}: only the constants ${ALLOWED_CONSTANTS.join(', ')} and module.exports are allowed at top level`);
}

// The export statement itself uses 'module' and 'exports'; check everything else
const body = ast.body.filter(statement => !isExportStatement(statement));
for (const statement of body) {
walk(statement, (node, parent) => {
const line = node.loc.start.line;
if (FORBIDDEN_NODES.has(node.type)) {
problems.push(`line ${line}: ${node.type} is not allowed`);
}
if (node.type === 'Identifier' && FORBIDDEN_NAMES.has(node.name)) {
problems.push(`line ${line}: '${node.name}' is not allowed`);
}
if (node.type === 'Literal' && typeof node.value === 'string' && FORBIDDEN_NAMES.has(node.value)
&& parent && (parent.type === 'MemberExpression' && parent.computed)) {
problems.push(`line ${line}: access to '${node.value}' is not allowed`);
}
if (node.type === 'NewExpression' && !(node.callee.type === 'Identifier' && node.callee.name === 'Error')) {
problems.push(`line ${line}: 'new' is only allowed for Error`);
}
if (node.type === 'MemberExpression' && node.computed && node.property.type !== 'Literal') {
problems.push(`line ${line}: computed member access is only allowed with a literal`);
}
if ((node.type === 'FunctionDeclaration' || node.type === 'FunctionExpression') && (node.generator || node.async)) {
problems.push(`line ${line}: async and generator functions are not allowed`);
}
if (node.type === 'AssignmentExpression' && node.left.type === 'MemberExpression') {
problems.push(`line ${line}: assigning to properties is not allowed`);
}
});
}
return problems;
}

// ===== REVIEW RULES =====

/**
* Load a config file in an empty sandbox (no require, no process)
* @param {string} source - File content
* @returns {Object} Exports
*/
function loadSandboxed(source) {
const sandbox = { module: { exports: {} } };
vm.runInNewContext(source, sandbox, { timeout: 2000 });
return sandbox.module.exports;
}

/**
* Stable text of a value (functions by their source)
* @param {*} value - Value
* @returns {string}
*/
function describe(value) {
return JSON.stringify(value, (key, item) => (typeof item === 'function' ? `fn:${item.toString()}` : item));
}

/**
* All functions of an object with their path
* @param {*} value - Value
* @param {string} prefix - Path
* @param {Map} out - Path -> source
* @returns {Map} out
*/
function collectFunctions(value, prefix = '', out = new Map()) {
if (typeof value === 'function') {
out.set(prefix, value.toString());
} else if (value && typeof value === 'object') {
for (const [key, item] of Object.entries(value)) collectFunctions(item, prefix ? `${prefix}.${key}` : key, out);
}
return out;
}

/**
* Options (words starting with '-') in a CLI args block
* @param {Object} args - cli.args
* @returns {Set<string>} Options
*/
function cliOptions(args) {
const parts = args && typeof args === 'object'
? Object.entries(args).filter(([key]) => key !== 'order').flatMap(([, list]) => (Array.isArray(list) ? list : []))
: [];
return new Set(parts.filter(part => typeof part === 'string' && /^--?[A-Za-z]/.test(part)));
}

/**
* Compare old and new config for changes that need a human
* @param {Object} oldExports - Exports of the base version
* @param {Object} newExports - Exports of the new version
* @returns {{review: string[], functions: string[]}} Changes to review, changed functions
*/
function compare(oldExports, newExports) {
const review = [];
const oldProviders = oldExports.PROVIDER_CONFIGS || {};
const newProviders = newExports.PROVIDER_CONFIGS || {};

if (oldExports.REMOTE_CONFIG_URL !== newExports.REMOTE_CONFIG_URL) {
review.push('REMOTE_CONFIG_URL changed');
}

for (const [id, cfg] of Object.entries(newProviders)) {
const old = oldProviders[id];
if (!old) {
review.push(`${id}: new provider`);
continue;
}
const fields = [
['hostname', cfg.hostname, old.hostname],
['agentModule', cfg.agentModule, old.agentModule],
['processConfig.command', cfg.processConfig?.command, old.processConfig?.command],
['autoDetectUrls', cfg.autoDetectUrls, old.autoDetectUrls],
['cli.candidates', cfg.cli?.candidates, old.cli?.candidates],
['cli.apiKeyLogin', cfg.cli?.apiKeyLogin, old.cli?.apiKeyLogin],
['cli.modelsCommand', cfg.cli?.modelsCommand, old.cli?.modelsCommand],
['cli.loginArgs', cfg.cli?.loginArgs, old.cli?.loginArgs]
];
for (const [name, now, before] of fields) {
if (describe(now) !== describe(before)) review.push(`${id}: ${name} changed`);
}
const before = cliOptions(old.cli?.args);
for (const option of cliOptions(cfg.cli?.args)) {
if (!before.has(option) && RISKY_OPTION.test(option)) review.push(`${id}: new CLI option ${option}`);
}
}

const oldRuntime = oldExports.RUNTIME_CONFIG || {};
const newRuntime = newExports.RUNTIME_CONFIG || {};
for (const key of ['ideLogDirs', 'arduinoCliPaths', 'arduinoCliConfigs']) {
if (describe(oldRuntime[key]) !== describe(newRuntime[key])) review.push(`RUNTIME_CONFIG.${key} changed`);
}

const oldFunctions = collectFunctions(oldProviders);
const functions = [...collectFunctions(newProviders)]
.filter(([key, source]) => oldFunctions.get(key) !== source)
.map(([key]) => key);
return { review, functions };
}

// ===== MAIN =====

function main() {
const args = process.argv.slice(2);
const baseIndex = args.indexOf('--base');
const source = fs.readFileSync(CONFIG_FILE, 'utf8');

const problems = checkCode(source);
if (problems.length) {
console.log('✗ Code rules');
problems.forEach(problem => console.log(` ${problem}`));
process.exit(1);
}
console.log('✓ Code rules: providerConfigs.js contains only configuration');

if (baseIndex < 0) return;
const baseFile = args[baseIndex + 1];
if (!baseFile || !fs.existsSync(baseFile)) {
console.log('- No base file, review rules skipped');
return;
}
const { review, functions } = compare(loadSandboxed(fs.readFileSync(baseFile, 'utf8')), loadSandboxed(source));
if (functions.length) {
console.log('ℹ Changed functions (check them in the diff):');
functions.forEach(name => console.log(` ${name}`));
}
if (review.length) {
console.log('✗ Needs a human review (not merged automatically):');
review.forEach(item => console.log(` ${item}`));
process.exit(1);
}
console.log('✓ Review rules: no security-relevant changes');
}

main();
12 changes: 7 additions & 5 deletions .github/workflows/cli-provider-check.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Installs every CLI provider and checks the options AI.duino passes against the
# Installs every CLI provider and checks the options AI.duino passes (cli.args in
# providerConfigs.js and the built-in defaults of the agent modules) against the
# real CLIs. The CLIs change without AI.duino changing anything, so this runs
# weekly before the scheduled task "AI.duino Provider-Config Wochencheck", which
# reads the result. Deliberately not a gate on providerConfigs.js PRs: the options
# live in the extension code, so a failure here needs a release, not a config fix.
# reads the result, and on config PRs so changed CLI options are verified.
name: CLI provider check

on:
Expand All @@ -12,11 +12,13 @@ on:
push:
branches: [main]
paths:
- 'aiduino/extension/out/config/providerConfigs.js'
- 'aiduino/extension/out/localProviders/processProviders/**'
- '.github/scripts/check-cli-providers.js'
- '.github/workflows/cli-provider-check.yml'
pull_request:
paths:
- 'aiduino/extension/out/config/providerConfigs.js'
- 'aiduino/extension/out/localProviders/processProviders/**'
- '.github/scripts/check-cli-providers.js'
- '.github/workflows/cli-provider-check.yml'
Expand All @@ -29,9 +31,9 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5

- uses: actions/setup-node@v4
- uses: actions/setup-node@v5
with:
node-version: 22

Expand Down
Loading
Loading