@odla-ai/cli 0.7.1 → 0.8.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/README.md +72 -4
- package/dist/bin.cjs +999 -227
- package/dist/bin.cjs.map +1 -1
- package/dist/bin.js +1 -1
- package/dist/{chunk-643B2AKG.js → chunk-BHAEDEL2.js} +965 -171
- package/dist/chunk-BHAEDEL2.js.map +1 -0
- package/dist/index.cjs +1038 -229
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +353 -26
- package/dist/index.d.ts +353 -26
- package/dist/index.js +29 -3
- package/llms.txt +433 -33
- package/package.json +3 -3
- package/skills/odla/SKILL.md +8 -1
- package/skills/odla/references/build.md +17 -2
- package/skills/odla/references/sdks.md +2 -2
- package/skills/odla-migrate/references/phase-2-db.md +2 -2
- package/skills/odla-migrate/references/phase-5-cutover.md +8 -2
- package/dist/chunk-643B2AKG.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -35,17 +35,30 @@ __export(index_exports, {
|
|
|
35
35
|
CAPABILITIES: () => CAPABILITIES,
|
|
36
36
|
SYSTEM_AI_PURPOSES: () => SYSTEM_AI_PURPOSES,
|
|
37
37
|
adminAi: () => adminAi,
|
|
38
|
+
connectGitHubSecuritySource: () => connectGitHubSecuritySource,
|
|
39
|
+
disconnectGitHubSecuritySource: () => disconnectGitHubSecuritySource,
|
|
38
40
|
doctor: () => doctor,
|
|
41
|
+
followHostedSecurityJob: () => followHostedSecurityJob,
|
|
42
|
+
getHostedSecurityIntent: () => getHostedSecurityIntent,
|
|
43
|
+
getHostedSecurityJob: () => getHostedSecurityJob,
|
|
44
|
+
getHostedSecurityPlan: () => getHostedSecurityPlan,
|
|
45
|
+
getHostedSecurityReport: () => getHostedSecurityReport,
|
|
39
46
|
getScopedPlatformToken: () => getScopedPlatformToken,
|
|
47
|
+
inferGitHubRepository: () => inferGitHubRepository,
|
|
40
48
|
initProject: () => initProject,
|
|
41
49
|
installSkill: () => installSkill,
|
|
50
|
+
isTerminalHostedSecurityStatus: () => isTerminalHostedSecurityStatus,
|
|
51
|
+
listGitHubSecuritySources: () => listGitHubSecuritySources,
|
|
52
|
+
listHostedSecurityJobs: () => listHostedSecurityJobs,
|
|
42
53
|
printCapabilities: () => printCapabilities,
|
|
43
54
|
provision: () => provision,
|
|
44
55
|
redactSecrets: () => redactSecrets,
|
|
56
|
+
repositoryFromGitRemote: () => repositoryFromGitRemote,
|
|
45
57
|
runCli: () => runCli,
|
|
46
58
|
runHostedSecurity: () => runHostedSecurity,
|
|
47
59
|
secretsPush: () => secretsPush,
|
|
48
|
-
smoke: () => smoke
|
|
60
|
+
smoke: () => smoke,
|
|
61
|
+
startHostedSecurityJob: () => startHostedSecurityJob
|
|
49
62
|
});
|
|
50
63
|
module.exports = __toCommonJS(index_exports);
|
|
51
64
|
|
|
@@ -53,9 +66,6 @@ module.exports = __toCommonJS(index_exports);
|
|
|
53
66
|
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
|
|
54
67
|
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
55
68
|
|
|
56
|
-
// src/cli.ts
|
|
57
|
-
var import_security2 = require("@odla-ai/security");
|
|
58
|
-
|
|
59
69
|
// src/admin-ai.ts
|
|
60
70
|
var import_node_process4 = __toESM(require("process"), 1);
|
|
61
71
|
|
|
@@ -773,6 +783,65 @@ function addOption(options, name, value) {
|
|
|
773
783
|
else options[name] = [String(current), String(value)];
|
|
774
784
|
}
|
|
775
785
|
|
|
786
|
+
// src/admin-command.ts
|
|
787
|
+
async function adminCommand(parsed) {
|
|
788
|
+
const area = parsed.positionals[1];
|
|
789
|
+
const action = parsed.positionals[2];
|
|
790
|
+
const credentialSet = action === "credential" && parsed.positionals[3] === "set";
|
|
791
|
+
const credentials = action === "credentials";
|
|
792
|
+
const models = action === "models";
|
|
793
|
+
const usage = action === "usage";
|
|
794
|
+
const audit = action === "audit";
|
|
795
|
+
if (area !== "ai" || action !== "show" && action !== "set" && !credentialSet && !credentials && !models && !usage && !audit) {
|
|
796
|
+
throw new Error('unknown admin command. Try "odla-ai admin ai show".');
|
|
797
|
+
}
|
|
798
|
+
assertArgs(parsed, [
|
|
799
|
+
"platform",
|
|
800
|
+
"json",
|
|
801
|
+
"open",
|
|
802
|
+
"provider",
|
|
803
|
+
"model",
|
|
804
|
+
"enabled",
|
|
805
|
+
"max-input-bytes",
|
|
806
|
+
"max-output-tokens",
|
|
807
|
+
"max-calls-per-run",
|
|
808
|
+
"from-env",
|
|
809
|
+
"stdin",
|
|
810
|
+
"discovery-provider",
|
|
811
|
+
"discovery-model",
|
|
812
|
+
"validation-provider",
|
|
813
|
+
"validation-model",
|
|
814
|
+
"app-id",
|
|
815
|
+
"env",
|
|
816
|
+
"run-id",
|
|
817
|
+
"limit"
|
|
818
|
+
], credentialSet ? 5 : action === "set" ? 4 : 3);
|
|
819
|
+
await adminAi({
|
|
820
|
+
action: credentialSet ? "credential-set" : credentials ? "credentials" : models ? "models" : usage ? "usage" : audit ? "audit" : action,
|
|
821
|
+
purpose: action === "set" ? parsed.positionals[3] : void 0,
|
|
822
|
+
provider: stringOpt(parsed.options.provider),
|
|
823
|
+
model: stringOpt(parsed.options.model),
|
|
824
|
+
enabled: boolOpt(parsed.options.enabled),
|
|
825
|
+
maxInputBytes: numberOpt(parsed.options["max-input-bytes"], "--max-input-bytes"),
|
|
826
|
+
maxOutputTokens: numberOpt(parsed.options["max-output-tokens"], "--max-output-tokens"),
|
|
827
|
+
maxCallsPerRun: numberOpt(parsed.options["max-calls-per-run"], "--max-calls-per-run"),
|
|
828
|
+
platform: stringOpt(parsed.options.platform),
|
|
829
|
+
json: parsed.options.json === true,
|
|
830
|
+
open: parsed.options.open === false ? false : parsed.options.open === true ? true : void 0,
|
|
831
|
+
credentialProvider: credentialSet ? parsed.positionals[4] : void 0,
|
|
832
|
+
fromEnv: stringOpt(parsed.options["from-env"]),
|
|
833
|
+
stdin: parsed.options.stdin === true,
|
|
834
|
+
discoveryProvider: stringOpt(parsed.options["discovery-provider"]),
|
|
835
|
+
discoveryModel: stringOpt(parsed.options["discovery-model"]),
|
|
836
|
+
validationProvider: stringOpt(parsed.options["validation-provider"]),
|
|
837
|
+
validationModel: stringOpt(parsed.options["validation-model"]),
|
|
838
|
+
appId: stringOpt(parsed.options["app-id"]),
|
|
839
|
+
env: stringOpt(parsed.options.env),
|
|
840
|
+
runId: stringOpt(parsed.options["run-id"]),
|
|
841
|
+
limit: numberOpt(parsed.options.limit, "--limit")
|
|
842
|
+
});
|
|
843
|
+
}
|
|
844
|
+
|
|
776
845
|
// src/capabilities.ts
|
|
777
846
|
var CAPABILITIES = {
|
|
778
847
|
cli: [
|
|
@@ -782,6 +851,7 @@ var CAPABILITIES = {
|
|
|
782
851
|
"push db schema/rules and configure platform AI, auth, and deployment links",
|
|
783
852
|
"validate config offline and smoke-test a provisioned db environment",
|
|
784
853
|
"run app-attributed hosted security discovery and independent validation without provider keys",
|
|
854
|
+
"connect/revoke source-read-only GitHub sources and drive commit-pinned hosted security jobs without PATs or provider keys",
|
|
785
855
|
"let admins manage system AI policy and credentials, inspect attributed usage, and read immutable admin changes through separate short-lived capability-only approvals"
|
|
786
856
|
],
|
|
787
857
|
agent: [
|
|
@@ -794,12 +864,14 @@ var CAPABILITIES = {
|
|
|
794
864
|
"consent to production changes with --yes",
|
|
795
865
|
"request destructive credential rotation explicitly",
|
|
796
866
|
"review application semantics, security findings, releases, and merges",
|
|
797
|
-
"approve redacted-source disclosure before hosted security reasoning"
|
|
867
|
+
"approve redacted-source disclosure before hosted security reasoning",
|
|
868
|
+
"approve GitHub App repository access separately from redacted-snippet disclosure"
|
|
798
869
|
],
|
|
799
870
|
studio: [
|
|
800
871
|
"view telemetry and environment state",
|
|
801
872
|
"perform manual credential recovery when the CLI's local shown-once copy is unavailable",
|
|
802
|
-
"configure system AI purposes and view app/environment/run-attributed usage"
|
|
873
|
+
"configure system AI purposes and view app/environment/run-attributed usage",
|
|
874
|
+
"connect/revoke GitHub security sources and inspect ref-to-SHA jobs, routes, retention, coverage, and normalized reports"
|
|
803
875
|
]
|
|
804
876
|
};
|
|
805
877
|
function printCapabilities(json = false, out = console) {
|
|
@@ -1196,14 +1268,103 @@ async function doctor(options) {
|
|
|
1196
1268
|
}
|
|
1197
1269
|
}
|
|
1198
1270
|
|
|
1199
|
-
// src/
|
|
1271
|
+
// src/help.ts
|
|
1200
1272
|
var import_node_fs6 = require("fs");
|
|
1273
|
+
function cliVersion() {
|
|
1274
|
+
const pkg = JSON.parse((0, import_node_fs6.readFileSync)(new URL("../package.json", importMetaUrl), "utf8"));
|
|
1275
|
+
return pkg.version ?? "unknown";
|
|
1276
|
+
}
|
|
1277
|
+
function printHelp() {
|
|
1278
|
+
console.log(`odla-ai
|
|
1279
|
+
|
|
1280
|
+
Usage:
|
|
1281
|
+
odla-ai setup [--dir <project>] [--agent <name>] [--global] [--force]
|
|
1282
|
+
odla-ai init --app-id <id> --name <name> [--services db,ai,o11y] [--env dev --env prod]
|
|
1283
|
+
odla-ai doctor [--config odla.config.mjs]
|
|
1284
|
+
odla-ai capabilities [--json]
|
|
1285
|
+
odla-ai admin ai show [--platform https://odla.ai] [--json]
|
|
1286
|
+
odla-ai admin ai models [--provider <id>] [--json]
|
|
1287
|
+
odla-ai admin ai set <purpose> [--provider <id>] [--model <id>] [--enabled|--no-enabled]
|
|
1288
|
+
odla-ai admin ai set security --discovery-provider <id> --discovery-model <id>
|
|
1289
|
+
--validation-provider <id> --validation-model <id> [--enabled|--no-enabled]
|
|
1290
|
+
odla-ai admin ai credentials [--json]
|
|
1291
|
+
odla-ai admin ai credential set <provider> (--from-env <NAME>|--stdin)
|
|
1292
|
+
odla-ai admin ai usage [--app-id <id>] [--env <env>] [--run-id <id>] [--limit <1-500>] [--json]
|
|
1293
|
+
odla-ai admin ai audit [--limit <1-200>] [--json]
|
|
1294
|
+
odla-ai security github connect [--repo owner/name] [--env dev] [--no-open]
|
|
1295
|
+
odla-ai security github disconnect --source <id> [--env dev] [--yes]
|
|
1296
|
+
odla-ai security plan [--env dev] [--json]
|
|
1297
|
+
odla-ai security sources [--env dev] [--json]
|
|
1298
|
+
odla-ai security run --source <id> --plan-digest <sha256:...> --ack-redacted-source [--ref <branch|tag|sha>] [--env dev] [--no-follow]
|
|
1299
|
+
odla-ai security status <job-id> [--follow] [--json]
|
|
1300
|
+
odla-ai security report <job-id> [--json]
|
|
1301
|
+
odla-ai security run [target] --ack-redacted-source [--env dev] [--profile odla] [--fail-on high]
|
|
1302
|
+
odla-ai security run [target] --self --ack-redacted-source
|
|
1303
|
+
odla-ai provision [--config odla.config.mjs] [--dry-run] [--push-secrets] [--rotate-o11y-token] [--write-dev-vars[=path]] [--yes]
|
|
1304
|
+
odla-ai smoke [--config odla.config.mjs] [--env dev]
|
|
1305
|
+
odla-ai skill install [--dir <project>] [--agent <name>] [--global] [--force]
|
|
1306
|
+
odla-ai secrets push --env <env> [--config odla.config.mjs] [--dry-run] [--yes]
|
|
1307
|
+
odla-ai version
|
|
1308
|
+
|
|
1309
|
+
Commands:
|
|
1310
|
+
setup Install offline odla runbooks for common coding-agent harnesses.
|
|
1311
|
+
init Create a generic odla.config.mjs plus starter schema/rules files.
|
|
1312
|
+
doctor Validate and summarize the project config without network calls.
|
|
1313
|
+
capabilities Show what the CLI automates vs agent edits and human checkpoints.
|
|
1314
|
+
admin Manage platform-funded AI routing/credentials/usage with narrow device grants.
|
|
1315
|
+
security Connect GitHub sources and run commit-pinned hosted reviews, or scan a local snapshot.
|
|
1316
|
+
provision Register services, configure them, persist credentials, optionally push secrets.
|
|
1317
|
+
smoke Verify local credentials, public-config, live schema, and db aggregate.
|
|
1318
|
+
skill Same installer; --agent accepts all, claude, codex, cursor,
|
|
1319
|
+
copilot, gemini, or agents (repeatable or comma-separated).
|
|
1320
|
+
secrets Push configured db/o11y secrets into the Worker via wrangler stdin.
|
|
1321
|
+
version Print the CLI version.
|
|
1322
|
+
|
|
1323
|
+
Safety:
|
|
1324
|
+
New projects target dev only. Add prod explicitly to odla.config.mjs and pass
|
|
1325
|
+
--yes to provision it; use --dry-run first to inspect the resolved plan.
|
|
1326
|
+
Provision caches the approved developer token and service credentials under
|
|
1327
|
+
.odla/ with mode 0600, and init adds those paths to .gitignore. Secret push
|
|
1328
|
+
preflights Wrangler before any shown-once issuance or destructive rotation.
|
|
1329
|
+
Provision opens the approval page automatically in interactive terminals;
|
|
1330
|
+
use --open to force browser launch or --no-open to suppress it.
|
|
1331
|
+
GitHub security uses source-read-only access plus optional metadata-only Checks write: the CLI never asks
|
|
1332
|
+
for a PAT or provider key. GitHub read access is separate from the explicit
|
|
1333
|
+
--ack-redacted-source consent and the exact --plan-digest printed by security
|
|
1334
|
+
plan are required before bounded snippets reach System AI.
|
|
1335
|
+
Run security plan first to inspect the admin-selected providers, models,
|
|
1336
|
+
per-route bounds, credential readiness, retention, no-execution boundary,
|
|
1337
|
+
and digest that binds consent to that exact plan.
|
|
1338
|
+
`);
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
// src/harness-options.ts
|
|
1342
|
+
function harnessList(parsed) {
|
|
1343
|
+
const selected = [
|
|
1344
|
+
...harnessOption(parsed.options.agent, "--agent"),
|
|
1345
|
+
...harnessOption(parsed.options.harness, "--harness")
|
|
1346
|
+
];
|
|
1347
|
+
return selected.length ? selected : ["all"];
|
|
1348
|
+
}
|
|
1349
|
+
function harnessOption(value, flag) {
|
|
1350
|
+
if (value === void 0) return [];
|
|
1351
|
+
if (typeof value === "boolean") throw new Error(`${flag} requires a harness name`);
|
|
1352
|
+
const raw = Array.isArray(value) ? value : [value];
|
|
1353
|
+
const parts = raw.flatMap((item) => item.split(","));
|
|
1354
|
+
if (parts.some((item) => !item.trim())) {
|
|
1355
|
+
throw new Error(`${flag} requires a harness name`);
|
|
1356
|
+
}
|
|
1357
|
+
return parts.map((item) => item.trim());
|
|
1358
|
+
}
|
|
1359
|
+
|
|
1360
|
+
// src/init.ts
|
|
1361
|
+
var import_node_fs7 = require("fs");
|
|
1201
1362
|
var import_node_path5 = require("path");
|
|
1202
1363
|
function initProject(options) {
|
|
1203
1364
|
const out = options.stdout ?? console;
|
|
1204
1365
|
const rootDir = (0, import_node_path5.resolve)(options.rootDir ?? process.cwd());
|
|
1205
1366
|
const configPath = (0, import_node_path5.resolve)(rootDir, options.configPath ?? "odla.config.mjs");
|
|
1206
|
-
if ((0,
|
|
1367
|
+
if ((0, import_node_fs7.existsSync)(configPath) && !options.force) {
|
|
1207
1368
|
throw new Error(`${configPath} already exists. Pass --force to overwrite.`);
|
|
1208
1369
|
}
|
|
1209
1370
|
if (!/^[a-z0-9][a-z0-9-]*$/.test(options.appId)) {
|
|
@@ -1212,10 +1373,10 @@ function initProject(options) {
|
|
|
1212
1373
|
const envs = options.envs?.length ? options.envs : ["dev"];
|
|
1213
1374
|
const services = options.services?.length ? options.services : ["db", "ai"];
|
|
1214
1375
|
const aiProvider = options.aiProvider ?? "anthropic";
|
|
1215
|
-
(0,
|
|
1216
|
-
(0,
|
|
1217
|
-
(0,
|
|
1218
|
-
(0,
|
|
1376
|
+
(0, import_node_fs7.mkdirSync)((0, import_node_path5.dirname)(configPath), { recursive: true });
|
|
1377
|
+
(0, import_node_fs7.mkdirSync)((0, import_node_path5.resolve)(rootDir, "src/odla"), { recursive: true });
|
|
1378
|
+
(0, import_node_fs7.mkdirSync)((0, import_node_path5.resolve)(rootDir, ".odla"), { recursive: true });
|
|
1379
|
+
(0, import_node_fs7.writeFileSync)(configPath, configTemplate({ appId: options.appId, name: options.name, envs, services, aiProvider }));
|
|
1219
1380
|
writeIfMissing((0, import_node_path5.resolve)(rootDir, "src/odla/schema.mjs"), schemaTemplate());
|
|
1220
1381
|
writeIfMissing((0, import_node_path5.resolve)(rootDir, "src/odla/rules.mjs"), rulesTemplate());
|
|
1221
1382
|
ensureGitignore(rootDir);
|
|
@@ -1224,8 +1385,8 @@ function initProject(options) {
|
|
|
1224
1385
|
out.log("updated .gitignore for local odla credentials");
|
|
1225
1386
|
}
|
|
1226
1387
|
function writeIfMissing(path, text) {
|
|
1227
|
-
if ((0,
|
|
1228
|
-
(0,
|
|
1388
|
+
if ((0, import_node_fs7.existsSync)(path)) return;
|
|
1389
|
+
(0, import_node_fs7.writeFileSync)(path, text);
|
|
1229
1390
|
}
|
|
1230
1391
|
function configTemplate(input) {
|
|
1231
1392
|
return `export default {
|
|
@@ -1678,6 +1839,162 @@ async function safeText2(res) {
|
|
|
1678
1839
|
}
|
|
1679
1840
|
}
|
|
1680
1841
|
|
|
1842
|
+
// src/security-command-context.ts
|
|
1843
|
+
var import_promises = require("readline/promises");
|
|
1844
|
+
async function hostedSecurityContext(parsed, dependencies) {
|
|
1845
|
+
const configPath = stringOpt(parsed.options.config) ?? "odla.config.mjs";
|
|
1846
|
+
const cfg = await loadProjectConfig(configPath);
|
|
1847
|
+
const env = stringOpt(parsed.options.env) ?? (cfg.envs.includes("dev") ? "dev" : cfg.envs[0]);
|
|
1848
|
+
if (!env || !cfg.envs.includes(env)) {
|
|
1849
|
+
throw new Error(`env "${env ?? ""}" is not declared in ${configPath}`);
|
|
1850
|
+
}
|
|
1851
|
+
const platform = platformAudience(stringOpt(parsed.options.platform) ?? cfg.platformUrl);
|
|
1852
|
+
if (platformAudience(cfg.platformUrl) !== platform) {
|
|
1853
|
+
throw new Error("--platform cannot reuse a project developer token from another platform; update odla.config.mjs and authenticate there");
|
|
1854
|
+
}
|
|
1855
|
+
const doFetch = dependencies.fetch ?? fetch;
|
|
1856
|
+
const stdout = dependencies.stdout ?? console;
|
|
1857
|
+
const open = parsed.options.open === false ? false : parsed.options.open === true ? true : void 0;
|
|
1858
|
+
const token = await getDeveloperToken(
|
|
1859
|
+
cfg,
|
|
1860
|
+
{ configPath, open, openApprovalUrl: dependencies.openUrl },
|
|
1861
|
+
doFetch,
|
|
1862
|
+
stdout
|
|
1863
|
+
);
|
|
1864
|
+
return { platform, token, appId: cfg.app.id, env, fetch: doFetch, stdout };
|
|
1865
|
+
}
|
|
1866
|
+
async function interactiveConfirmation(message, dependencies) {
|
|
1867
|
+
if (dependencies.confirm) return dependencies.confirm(message);
|
|
1868
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY) return false;
|
|
1869
|
+
const prompt = (0, import_promises.createInterface)({ input: process.stdin, output: process.stdout });
|
|
1870
|
+
try {
|
|
1871
|
+
const answer = await prompt.question(`${message} [y/N] `);
|
|
1872
|
+
return /^y(?:es)?$/i.test(answer.trim());
|
|
1873
|
+
} finally {
|
|
1874
|
+
prompt.close();
|
|
1875
|
+
}
|
|
1876
|
+
}
|
|
1877
|
+
function requiredSecurityPositional(parsed, index, label) {
|
|
1878
|
+
const value = parsed.positionals[index];
|
|
1879
|
+
if (!value) throw new Error(`${label} is required`);
|
|
1880
|
+
return value;
|
|
1881
|
+
}
|
|
1882
|
+
function securityProfile(value) {
|
|
1883
|
+
if (value === void 0) return void 0;
|
|
1884
|
+
if (value === "odla" || value === "cloudflare-app" || value === "generic") return value;
|
|
1885
|
+
throw new Error("--profile must be odla, cloudflare-app, or generic");
|
|
1886
|
+
}
|
|
1887
|
+
|
|
1888
|
+
// src/security-command-output.ts
|
|
1889
|
+
function printHostedSecurityPlan(out, plan, appId) {
|
|
1890
|
+
out.log(`Hosted security plan for ${appId}/${plan.env}: ${plan.ready ? "ready" : "not ready"}`);
|
|
1891
|
+
out.log(` plan digest: ${plan.planDigest}`);
|
|
1892
|
+
out.log(` consent/report/redaction: ${plan.consentContract} \xB7 ${plan.reportProjection} \xB7 ${plan.redactionContract}`);
|
|
1893
|
+
out.log(` prompt bundle: ${plan.promptBundle}`);
|
|
1894
|
+
printHostedSecurityPlanRoute(out, "discovery", plan.routes.discovery);
|
|
1895
|
+
printHostedSecurityPlanRoute(out, "validation", plan.routes.validation);
|
|
1896
|
+
out.log(` independent validation: ${plan.independent ? "yes" : "no"}`);
|
|
1897
|
+
out.log(" source disclosure: bounded best-effort credential-pattern-redacted snippets may be sent through odla.ai to the selected providers");
|
|
1898
|
+
out.log(` retained report: model-derived prose and repository-relative paths for up to ${plan.reportRetentionDays} days; treat it as sensitive`);
|
|
1899
|
+
out.log(" target execution: disabled");
|
|
1900
|
+
out.log(` to approve this exact plan, run security run --source <id> --plan-digest ${plan.planDigest} --ack-redacted-source`);
|
|
1901
|
+
}
|
|
1902
|
+
function printHostedSecurityIntent(out, intent) {
|
|
1903
|
+
out.log(`Hosted security execution intent for ${intent.appId}/${intent.env}:`);
|
|
1904
|
+
out.log(` execution digest: ${intent.executionDigest}`);
|
|
1905
|
+
out.log(` contract: ${intent.executionContract}`);
|
|
1906
|
+
out.log(` source: ${intent.repository} (${intent.sourceId})`);
|
|
1907
|
+
out.log(` ref: ${intent.requestedRef ?? `default branch (${intent.defaultBranch})`}`);
|
|
1908
|
+
out.log(` profile: ${intent.profile}`);
|
|
1909
|
+
out.log(` disclosure: ${intent.sourceDisclosure} \xB7 plan ${intent.planDigest}`);
|
|
1910
|
+
}
|
|
1911
|
+
function assertHostedSecurityPlanReady(plan) {
|
|
1912
|
+
const reasons = [];
|
|
1913
|
+
for (const [label, route] of Object.entries(plan.routes)) {
|
|
1914
|
+
if (!route.enabled) reasons.push(`${label} is disabled`);
|
|
1915
|
+
if (!route.credentialReady) reasons.push(`${label} provider credential is unavailable`);
|
|
1916
|
+
}
|
|
1917
|
+
if (!plan.independent) reasons.push("discovery and validation are not independently routed");
|
|
1918
|
+
if (plan.ready && reasons.length === 0) return;
|
|
1919
|
+
if (!plan.ready && reasons.length === 0) reasons.push("the platform marked the plan unavailable");
|
|
1920
|
+
throw new Error(`hosted security is not ready${reasons.length ? `: ${reasons.join("; ")}` : ""}. Ask a platform admin to update System AI security policy or credentials`);
|
|
1921
|
+
}
|
|
1922
|
+
function printHostedJob(out, job, platform, appId) {
|
|
1923
|
+
out.log(`security job ${job.jobId}: ${job.status}`);
|
|
1924
|
+
out.log(` source: ${job.repository} ${job.requestedRef ?? "default"} -> ${job.commitSha ?? "resolving"}`);
|
|
1925
|
+
if (job.routes) {
|
|
1926
|
+
out.log(` discovery: ${routeLabel(job.routes.discovery)}`);
|
|
1927
|
+
out.log(` validation: ${routeLabel(job.routes.validation)}`);
|
|
1928
|
+
} else {
|
|
1929
|
+
out.log(" routes: platform System AI policy (assigned when analysis starts)");
|
|
1930
|
+
}
|
|
1931
|
+
out.log(` disclosure: ${job.sourceDisclosure} snippets \xB7 metadata retained up to ${job.retentionDays} days`);
|
|
1932
|
+
out.log(` consent: plan ${job.planDigest} \xB7 execution ${job.executionDigest} (${job.executionContract})`);
|
|
1933
|
+
if (job.coverageStatus || job.coverage) printHostedCoverage(out, job);
|
|
1934
|
+
if (job.counts) {
|
|
1935
|
+
out.log(` findings: confirmed=${job.counts.confirmed} needs_reproduction=${job.counts.needsReproduction} candidates=${job.counts.candidates}`);
|
|
1936
|
+
}
|
|
1937
|
+
if (job.errorCode) out.log(` failure: ${job.errorCode}`);
|
|
1938
|
+
const url = new URL("/studio", platform);
|
|
1939
|
+
url.searchParams.set("app", appId);
|
|
1940
|
+
url.searchParams.set("env", job.env);
|
|
1941
|
+
url.searchParams.set("tab", "security");
|
|
1942
|
+
url.searchParams.set("job", job.jobId);
|
|
1943
|
+
out.log(` Studio: ${url.toString()}`);
|
|
1944
|
+
}
|
|
1945
|
+
function printHostedReport(out, report) {
|
|
1946
|
+
out.log(`security report ${report.jobId}: ${report.repository}@${report.revision}`);
|
|
1947
|
+
out.log(` coverage: ${report.coverageStatus} cells=${report.metrics.coverageCells} shallow=${report.metrics.shallowCells} blocked=${report.metrics.blockedCells} unscheduled=${report.metrics.unscheduledCells} budget_exhausted=${report.metrics.budgetExhaustedCells}`);
|
|
1948
|
+
out.log(` findings: confirmed=${report.metrics.confirmed} needs_reproduction=${report.metrics.needsReproduction} candidates=${report.metrics.candidates} rejected=${report.metrics.rejected}`);
|
|
1949
|
+
out.log(` discovery: ${report.provenance.discovery?.provider ?? "unknown"}/${report.provenance.discovery?.model ?? "unknown"}`);
|
|
1950
|
+
out.log(` validation: ${report.provenance.validation?.provider ?? "unknown"}/${report.provenance.validation?.model ?? "unknown"} independent=${String(report.provenance.independentValidation)}`);
|
|
1951
|
+
for (const finding of report.findings) {
|
|
1952
|
+
const location = finding.locations[0];
|
|
1953
|
+
out.log(` [${finding.severity}] ${finding.title}${location ? ` (${location.path}:${location.line})` : ""} \xB7 ${finding.disposition}`);
|
|
1954
|
+
}
|
|
1955
|
+
for (const limitation of report.limitations) out.log(` limitation: ${limitation}`);
|
|
1956
|
+
}
|
|
1957
|
+
function enforceHostedReportGate(report, parsed, out, emitSuccess) {
|
|
1958
|
+
const failOn = hostedSeverity(stringOpt(parsed.options["fail-on"]) ?? "high", "--fail-on");
|
|
1959
|
+
const candidateValue = parsed.options["fail-on-candidates"];
|
|
1960
|
+
const failOnCandidates = candidateValue === false ? void 0 : hostedSeverity(stringOpt(candidateValue) ?? "critical", "--fail-on-candidates");
|
|
1961
|
+
const atOrAbove = (severity, threshold) => HOSTED_SEVERITIES.indexOf(severity) >= HOSTED_SEVERITIES.indexOf(threshold);
|
|
1962
|
+
const confirmed = report.findings.filter((finding) => finding.disposition === "confirmed" && atOrAbove(finding.severity, failOn));
|
|
1963
|
+
const leads = failOnCandidates ? report.findings.filter((finding) => finding.disposition !== "confirmed" && atOrAbove(finding.severity, failOnCandidates)) : [];
|
|
1964
|
+
const incomplete = report.coverageStatus !== "complete" && parsed.options["allow-incomplete"] !== true;
|
|
1965
|
+
if (confirmed.length || leads.length || incomplete) {
|
|
1966
|
+
throw new Error(`hosted security gate failed: ${confirmed.length} confirmed >= ${failOn}; ${leads.length} leads >= ${failOnCandidates ?? "disabled"}${incomplete ? `; coverage ${report.coverageStatus}` : ""}`);
|
|
1967
|
+
}
|
|
1968
|
+
if (emitSuccess) {
|
|
1969
|
+
out.log(`security gate passed: 0 confirmed >= ${failOn}; 0 leads >= ${failOnCandidates ?? "disabled"}; coverage ${report.coverageStatus}. This is not proof that the application is secure.`);
|
|
1970
|
+
}
|
|
1971
|
+
}
|
|
1972
|
+
function printHostedSecurityPlanRoute(out, label, route) {
|
|
1973
|
+
const readiness = route.enabled && route.credentialReady ? "ready" : [
|
|
1974
|
+
route.enabled ? void 0 : "disabled",
|
|
1975
|
+
route.credentialReady ? void 0 : "credential unavailable"
|
|
1976
|
+
].filter(Boolean).join(", ");
|
|
1977
|
+
out.log(` ${label}: ${route.provider}/${route.model} \xB7 policy v${route.policyVersion} \xB7 ${readiness}`);
|
|
1978
|
+
out.log(` bounds: ${route.maxCallsPerRun} calls/run \xB7 ${route.maxInputBytes} input bytes/call \xB7 ${route.maxOutputTokens} output tokens/call`);
|
|
1979
|
+
}
|
|
1980
|
+
function printHostedCoverage(out, job) {
|
|
1981
|
+
const coverage = job.coverage;
|
|
1982
|
+
out.log(` coverage: ${job.coverageStatus ?? "pending"}${coverage?.completeCells !== void 0 ? ` ${coverage.completeCells}/${coverage.totalCells ?? "?"}` : ""}${coverage?.shallowCells ? ` shallow=${coverage.shallowCells}` : ""}${coverage?.blockedCells ? ` blocked=${coverage.blockedCells}` : ""}${coverage?.unscheduledCells ? ` unscheduled=${coverage.unscheduledCells}` : ""}${coverage?.budgetExhaustedCells ? ` budget_exhausted=${coverage.budgetExhaustedCells}` : ""}`);
|
|
1983
|
+
}
|
|
1984
|
+
function routeLabel(route) {
|
|
1985
|
+
return `${route.provider}/${route.model}${route.policyVersion ? ` policy v${route.policyVersion}` : ""}`;
|
|
1986
|
+
}
|
|
1987
|
+
var HOSTED_SEVERITIES = ["informational", "low", "medium", "high", "critical"];
|
|
1988
|
+
function hostedSeverity(value, flag) {
|
|
1989
|
+
if (HOSTED_SEVERITIES.includes(value)) {
|
|
1990
|
+
return value;
|
|
1991
|
+
}
|
|
1992
|
+
throw new Error(`${flag} must be informational, low, medium, high, or critical`);
|
|
1993
|
+
}
|
|
1994
|
+
|
|
1995
|
+
// src/security-run-command.ts
|
|
1996
|
+
var import_security2 = require("@odla-ai/security");
|
|
1997
|
+
|
|
1681
1998
|
// src/security.ts
|
|
1682
1999
|
var import_node_path6 = require("path");
|
|
1683
2000
|
var import_security = require("@odla-ai/security");
|
|
@@ -1782,60 +2099,657 @@ function formatBudget(usage) {
|
|
|
1782
2099
|
return usage ? `${usage.usedCalls}/${usage.maxCalls} skipped=${usage.skippedCalls}` : "caller-managed";
|
|
1783
2100
|
}
|
|
1784
2101
|
|
|
1785
|
-
// src/
|
|
1786
|
-
var
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
2102
|
+
// src/security-hosted-github.ts
|
|
2103
|
+
var import_node_child_process4 = require("child_process");
|
|
2104
|
+
var import_node_util = require("util");
|
|
2105
|
+
|
|
2106
|
+
// src/security-hosted-request.ts
|
|
2107
|
+
async function requestHostedSecurityJson(options, path, init, action) {
|
|
2108
|
+
const platform = platformAudience(options.platform);
|
|
2109
|
+
const token = hostedSecurityCredential(options.token);
|
|
2110
|
+
const requestInit = {
|
|
2111
|
+
...init,
|
|
2112
|
+
redirect: "error",
|
|
2113
|
+
credentials: "omit",
|
|
2114
|
+
cache: "no-store",
|
|
2115
|
+
signal: options.signal,
|
|
2116
|
+
headers: {
|
|
2117
|
+
authorization: `Bearer ${token}`,
|
|
2118
|
+
"content-type": "application/json",
|
|
2119
|
+
...init.headers
|
|
2120
|
+
}
|
|
2121
|
+
};
|
|
2122
|
+
const response = await (options.fetch ?? fetch)(new URL(path, platform), requestInit);
|
|
2123
|
+
const body = await response.json().catch(() => ({}));
|
|
2124
|
+
if (!response.ok) {
|
|
2125
|
+
const code = optionalHostedText(body.error?.code, "error code", 128);
|
|
2126
|
+
const message = optionalHostedText(body.error?.message, "error message", 300);
|
|
2127
|
+
throw new Error(`${action} failed (${response.status})${code ? ` ${code}` : ""}${message ? `: ${message}` : ""}`);
|
|
2128
|
+
}
|
|
2129
|
+
return body;
|
|
2130
|
+
}
|
|
2131
|
+
function hostedIdentifier(value, name) {
|
|
2132
|
+
const result = optionalHostedText(value, name, 180);
|
|
2133
|
+
if (!result || !/^[A-Za-z0-9][A-Za-z0-9._:-]*$/.test(result)) {
|
|
2134
|
+
throw new Error(`${name} is invalid`);
|
|
2135
|
+
}
|
|
2136
|
+
return result;
|
|
2137
|
+
}
|
|
2138
|
+
function positivePolicyVersion(value, name) {
|
|
2139
|
+
if (!Number.isSafeInteger(value) || value < 1) {
|
|
2140
|
+
throw new Error(`${name} is invalid`);
|
|
2141
|
+
}
|
|
2142
|
+
return value;
|
|
2143
|
+
}
|
|
2144
|
+
function optionalHostedText(value, name, maxLength) {
|
|
2145
|
+
if (value === void 0 || value === null || value === "") return void 0;
|
|
2146
|
+
if (typeof value !== "string" || value.length > maxLength || /[\u0000-\u001f\u007f]/.test(value)) {
|
|
2147
|
+
throw new Error(`${name} is invalid`);
|
|
2148
|
+
}
|
|
2149
|
+
return value;
|
|
2150
|
+
}
|
|
2151
|
+
function githubRepositoryName(value) {
|
|
2152
|
+
if (typeof value !== "string" || value.length > 201) {
|
|
2153
|
+
throw new Error("repository must be owner/name");
|
|
2154
|
+
}
|
|
2155
|
+
const parts = value.split("/");
|
|
2156
|
+
const owner = parts[0] ?? "";
|
|
2157
|
+
const name = (parts[1] ?? "").replace(/\.git$/i, "");
|
|
2158
|
+
if (parts.length !== 2 || !/^[A-Za-z0-9](?:[A-Za-z0-9-]{0,98}[A-Za-z0-9])?$/.test(owner) || !/^[A-Za-z0-9_.-]{1,100}$/.test(name) || name === "." || name === "..") {
|
|
2159
|
+
throw new Error("repository must be owner/name");
|
|
2160
|
+
}
|
|
2161
|
+
return `${owner}/${name}`;
|
|
2162
|
+
}
|
|
2163
|
+
function trustedGitHubInstallUrl(value) {
|
|
2164
|
+
let url;
|
|
2165
|
+
try {
|
|
2166
|
+
url = new URL(value);
|
|
2167
|
+
} catch {
|
|
2168
|
+
throw new Error("odla.ai returned an invalid GitHub installation URL");
|
|
2169
|
+
}
|
|
2170
|
+
if (url.protocol !== "https:" || url.hostname !== "github.com" || url.username || url.password) {
|
|
2171
|
+
throw new Error("odla.ai returned an untrusted GitHub installation URL");
|
|
2172
|
+
}
|
|
2173
|
+
return url.toString();
|
|
2174
|
+
}
|
|
2175
|
+
function hostedPollInterval(value = 2e3) {
|
|
2176
|
+
if (!Number.isSafeInteger(value) || value < 100 || value > 3e4) {
|
|
2177
|
+
throw new Error("poll interval must be 100-30000ms");
|
|
2178
|
+
}
|
|
2179
|
+
return value;
|
|
2180
|
+
}
|
|
2181
|
+
function hostedPollTimeout(value = 10 * 6e4) {
|
|
2182
|
+
if (!Number.isSafeInteger(value) || value < 1e3 || value > 60 * 6e4) {
|
|
2183
|
+
throw new Error("poll timeout must be 1000-3600000ms");
|
|
2184
|
+
}
|
|
2185
|
+
return value;
|
|
2186
|
+
}
|
|
2187
|
+
async function waitForHostedPoll(milliseconds, signal) {
|
|
2188
|
+
if (signal?.aborted) throw signal.reason ?? new DOMException("aborted", "AbortError");
|
|
2189
|
+
await new Promise((resolve7, reject) => {
|
|
2190
|
+
const timer = setTimeout(resolve7, milliseconds);
|
|
2191
|
+
signal?.addEventListener("abort", () => {
|
|
2192
|
+
clearTimeout(timer);
|
|
2193
|
+
reject(signal.reason ?? new DOMException("aborted", "AbortError"));
|
|
2194
|
+
}, { once: true });
|
|
2195
|
+
});
|
|
2196
|
+
}
|
|
2197
|
+
function isValidHostedSecurityPlan(value, env) {
|
|
2198
|
+
if (!value || value.env !== env || !/^sha256:[a-f0-9]{64}$/.test(value.planDigest) || value.consentContract !== "odla.hosted-security-consent.v1" || value.reportProjection !== "odla.hosted-security-report.v1" || value.redactionContract !== "odla.best-effort-credential-pattern-redaction.v1" || typeof value.promptBundle !== "string" || value.promptBundle.length < 1 || value.promptBundle.length > 100 || typeof value.ready !== "boolean" || typeof value.independent !== "boolean" || value.sourceDisclosure !== "redacted" || value.targetExecution !== false || !Number.isSafeInteger(value.reportRetentionDays) || value.reportRetentionDays < 1) return false;
|
|
2199
|
+
const validRoute = (route, purpose) => !!route && route.purpose === purpose && typeof route.enabled === "boolean" && typeof route.credentialReady === "boolean" && typeof route.provider === "string" && route.provider.length > 0 && route.provider.length <= 100 && typeof route.model === "string" && route.model.length > 0 && route.model.length <= 200 && Number.isSafeInteger(route.policyVersion) && route.policyVersion >= 1 && Number.isSafeInteger(route.maxCallsPerRun) && route.maxCallsPerRun >= 1 && Number.isSafeInteger(route.maxInputBytes) && route.maxInputBytes >= 1 && Number.isSafeInteger(route.maxOutputTokens) && route.maxOutputTokens >= 1;
|
|
2200
|
+
return validRoute(value.routes?.discovery, "security.discovery") && validRoute(value.routes?.validation, "security.validation");
|
|
2201
|
+
}
|
|
2202
|
+
function hostedSecurityCredential(value) {
|
|
2203
|
+
if (typeof value !== "string" || value.length < 8 || value.length > 8192 || /\s|[\u0000-\u001f\u007f]/.test(value)) {
|
|
2204
|
+
throw new Error("Hosted security requires an injected odla developer token");
|
|
2205
|
+
}
|
|
2206
|
+
return value;
|
|
1790
2207
|
}
|
|
1791
|
-
function printHelp() {
|
|
1792
|
-
console.log(`odla-ai
|
|
1793
2208
|
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
2209
|
+
// src/security-hosted-github.ts
|
|
2210
|
+
async function connectGitHubSecuritySource(options) {
|
|
2211
|
+
const out = options.stdout ?? console;
|
|
2212
|
+
const repository = githubRepositoryName(options.repository);
|
|
2213
|
+
const attempt = await requestHostedSecurityJson(
|
|
2214
|
+
options,
|
|
2215
|
+
"/registry/github/connect",
|
|
2216
|
+
{
|
|
2217
|
+
method: "POST",
|
|
2218
|
+
body: JSON.stringify({
|
|
2219
|
+
appId: hostedIdentifier(options.appId, "appId"),
|
|
2220
|
+
env: hostedIdentifier(options.env, "env"),
|
|
2221
|
+
repository
|
|
2222
|
+
})
|
|
2223
|
+
},
|
|
2224
|
+
"start GitHub connection"
|
|
2225
|
+
);
|
|
2226
|
+
const serverExpiry = Date.parse(attempt?.expiresAt ?? "");
|
|
2227
|
+
if (!attempt?.attemptId || !attempt.installUrl || !Number.isFinite(serverExpiry)) {
|
|
2228
|
+
throw new Error("odla.ai returned an invalid GitHub connection attempt");
|
|
2229
|
+
}
|
|
2230
|
+
const installUrl = trustedGitHubInstallUrl(attempt.installUrl);
|
|
2231
|
+
out.log(`GitHub approval: ${installUrl}`);
|
|
2232
|
+
if (options.open !== false) {
|
|
2233
|
+
await (options.openInstallUrl ?? openUrl)(installUrl);
|
|
2234
|
+
out.log("github: opened installation approval in your browser");
|
|
2235
|
+
}
|
|
2236
|
+
const interval = hostedPollInterval(options.pollIntervalMs);
|
|
2237
|
+
const now = options.now ?? Date.now;
|
|
2238
|
+
const deadline = Math.min(serverExpiry, now() + hostedPollTimeout(options.pollTimeoutMs));
|
|
2239
|
+
const wait = options.wait ?? waitForHostedPoll;
|
|
2240
|
+
while (true) {
|
|
2241
|
+
const state = await requestHostedSecurityJson(
|
|
2242
|
+
options,
|
|
2243
|
+
`/registry/github/connect/${encodeURIComponent(attempt.attemptId)}`,
|
|
2244
|
+
{},
|
|
2245
|
+
"check GitHub connection"
|
|
2246
|
+
);
|
|
2247
|
+
if (state.status !== "pending") {
|
|
2248
|
+
if (state.status === "connected") return state;
|
|
2249
|
+
throw new Error(`GitHub connection ${state.status}${state.failureCode ? `: ${state.failureCode}` : ""}`);
|
|
2250
|
+
}
|
|
2251
|
+
if (now() >= deadline) throw new Error("GitHub connection approval timed out");
|
|
2252
|
+
await wait(Math.min(interval, Math.max(0, deadline - now())), options.signal);
|
|
2253
|
+
}
|
|
2254
|
+
}
|
|
2255
|
+
async function listGitHubSecuritySources(options) {
|
|
2256
|
+
const appId = hostedIdentifier(options.appId, "appId");
|
|
2257
|
+
const env = hostedIdentifier(options.env, "env");
|
|
2258
|
+
const body = await requestHostedSecurityJson(
|
|
2259
|
+
options,
|
|
2260
|
+
`/registry/apps/${encodeURIComponent(appId)}/github/sources?env=${encodeURIComponent(env)}`,
|
|
2261
|
+
{},
|
|
2262
|
+
"list GitHub security sources"
|
|
2263
|
+
);
|
|
2264
|
+
return Array.isArray(body.sources) ? body.sources : [];
|
|
2265
|
+
}
|
|
2266
|
+
async function disconnectGitHubSecuritySource(options) {
|
|
2267
|
+
const appId = hostedIdentifier(options.appId, "appId");
|
|
2268
|
+
const sourceId = hostedIdentifier(options.sourceId, "sourceId");
|
|
2269
|
+
await requestHostedSecurityJson(
|
|
2270
|
+
options,
|
|
2271
|
+
`/registry/apps/${encodeURIComponent(appId)}/github/sources/${encodeURIComponent(sourceId)}`,
|
|
2272
|
+
{ method: "DELETE" },
|
|
2273
|
+
"disconnect GitHub security source"
|
|
2274
|
+
);
|
|
2275
|
+
}
|
|
2276
|
+
function repositoryFromGitRemote(remoteInput) {
|
|
2277
|
+
const remote = remoteInput.trim();
|
|
2278
|
+
const scp = /^git@github\.com:([^/\s]+)\/([^/\s]+?)\/?$/.exec(remote);
|
|
2279
|
+
if (scp) return githubRepositoryName(`${scp[1]}/${scp[2].replace(/\.git$/, "")}`);
|
|
2280
|
+
let url;
|
|
2281
|
+
try {
|
|
2282
|
+
url = new URL(remote);
|
|
2283
|
+
} catch {
|
|
2284
|
+
throw new Error("origin must be a github.com HTTPS or SSH repository URL");
|
|
2285
|
+
}
|
|
2286
|
+
if (url.hostname !== "github.com" || url.protocol !== "https:" && url.protocol !== "ssh:") {
|
|
2287
|
+
throw new Error("origin must be a github.com HTTPS or SSH repository URL");
|
|
2288
|
+
}
|
|
2289
|
+
if (url.password || url.protocol === "https:" && url.username || url.search || url.hash) {
|
|
2290
|
+
throw new Error("credential-bearing GitHub origin URLs are not accepted");
|
|
2291
|
+
}
|
|
2292
|
+
const parts = url.pathname.replace(/^\/+|\/+$/g, "").split("/");
|
|
2293
|
+
if (parts.length !== 2) {
|
|
2294
|
+
throw new Error("origin must identify one GitHub owner/name repository");
|
|
2295
|
+
}
|
|
2296
|
+
return githubRepositoryName(`${parts[0]}/${parts[1].replace(/\.git$/, "")}`);
|
|
2297
|
+
}
|
|
2298
|
+
async function inferGitHubRepository(cwd = process.cwd(), readOrigin = defaultReadOrigin) {
|
|
2299
|
+
let remote;
|
|
2300
|
+
try {
|
|
2301
|
+
remote = await readOrigin(cwd);
|
|
2302
|
+
} catch {
|
|
2303
|
+
throw new Error("Could not read git origin; pass --repo owner/name");
|
|
2304
|
+
}
|
|
2305
|
+
return repositoryFromGitRemote(remote);
|
|
2306
|
+
}
|
|
2307
|
+
async function defaultReadOrigin(cwd) {
|
|
2308
|
+
const result = await (0, import_node_util.promisify)(import_node_child_process4.execFile)(
|
|
2309
|
+
"git",
|
|
2310
|
+
["remote", "get-url", "origin"],
|
|
2311
|
+
{ cwd, encoding: "utf8" }
|
|
2312
|
+
);
|
|
2313
|
+
return result.stdout;
|
|
2314
|
+
}
|
|
1815
2315
|
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
2316
|
+
// src/security-hosted-intent.ts
|
|
2317
|
+
async function getHostedSecurityIntent(options) {
|
|
2318
|
+
const appId = hostedIdentifier(options.appId, "appId");
|
|
2319
|
+
const env = hostedIdentifier(options.env, "env");
|
|
2320
|
+
const sourceId = hostedIdentifier(options.sourceId, "sourceId");
|
|
2321
|
+
const ref = optionalHostedText(options.ref, "ref", 255);
|
|
2322
|
+
const query = new URLSearchParams({ env, sourceId });
|
|
2323
|
+
if (ref) query.set("ref", ref);
|
|
2324
|
+
if (options.profile) query.set("profile", options.profile);
|
|
2325
|
+
const response = await requestHostedSecurityJson(
|
|
2326
|
+
options,
|
|
2327
|
+
`/registry/apps/${encodeURIComponent(appId)}/security/intent?${query.toString()}`,
|
|
2328
|
+
{},
|
|
2329
|
+
"read hosted security execution intent"
|
|
2330
|
+
);
|
|
2331
|
+
if (!isValidHostedSecurityPlan(response.plan, env) || !isValidIntent(response.intent, { appId, env, sourceId })) {
|
|
2332
|
+
throw new Error("odla.ai returned an invalid hosted security execution intent");
|
|
2333
|
+
}
|
|
2334
|
+
if (response.intent.planDigest !== response.plan.planDigest) {
|
|
2335
|
+
throw new Error("odla.ai returned a hosted security intent for a different processing plan");
|
|
2336
|
+
}
|
|
2337
|
+
return response;
|
|
2338
|
+
}
|
|
2339
|
+
function isValidIntent(value, expected) {
|
|
2340
|
+
return !!value && value.executionContract === "odla.hosted-security-execution-consent.v1" && /^sha256:[a-f0-9]{64}$/.test(value.executionDigest) && /^sha256:[a-f0-9]{64}$/.test(value.planDigest) && value.appId === expected.appId && value.env === expected.env && value.sourceId === expected.sourceId && typeof value.repository === "string" && value.repository.length > 2 && value.repository.length <= 201 && typeof value.defaultBranch === "string" && value.defaultBranch.length > 0 && value.defaultBranch.length <= 255 && typeof value.requestedRef === "string" && value.requestedRef.length > 0 && value.requestedRef.length <= 255 && !/[\u0000-\u001f\u007f]/.test(value.requestedRef) && ["odla", "cloudflare-app", "generic"].includes(value.profile) && value.sourceDisclosure === "redacted";
|
|
2341
|
+
}
|
|
1829
2342
|
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
2343
|
+
// src/security-hosted-jobs.ts
|
|
2344
|
+
async function getHostedSecurityPlan(options) {
|
|
2345
|
+
const appId = hostedIdentifier(options.appId, "appId");
|
|
2346
|
+
const env = hostedIdentifier(options.env, "env");
|
|
2347
|
+
const plan = await requestHostedSecurityJson(
|
|
2348
|
+
options,
|
|
2349
|
+
`/registry/apps/${encodeURIComponent(appId)}/security/plan?env=${encodeURIComponent(env)}`,
|
|
2350
|
+
{},
|
|
2351
|
+
"read hosted security disclosure plan"
|
|
2352
|
+
);
|
|
2353
|
+
if (!isValidHostedSecurityPlan(plan, env)) {
|
|
2354
|
+
throw new Error("odla.ai returned an invalid hosted security disclosure plan");
|
|
2355
|
+
}
|
|
2356
|
+
return plan;
|
|
2357
|
+
}
|
|
2358
|
+
async function startHostedSecurityJob(options) {
|
|
2359
|
+
if (options.sourceDisclosureAck !== "redacted") {
|
|
2360
|
+
throw new Error("Hosted GitHub security requires sourceDisclosureAck=redacted; repository access alone is not disclosure consent");
|
|
2361
|
+
}
|
|
2362
|
+
const appId = hostedIdentifier(options.appId, "appId");
|
|
2363
|
+
const env = hostedIdentifier(options.env, "env");
|
|
2364
|
+
const sourceId = hostedIdentifier(options.sourceId, "sourceId");
|
|
2365
|
+
const ref = optionalHostedText(options.ref, "ref", 255);
|
|
2366
|
+
const expectedPlanDigest = securityPlanDigest(options.expectedPlanDigest);
|
|
2367
|
+
const expectedExecutionDigest = securityExecutionDigest(options.expectedExecutionDigest);
|
|
2368
|
+
const expectedPolicyVersions = {
|
|
2369
|
+
discovery: positivePolicyVersion(
|
|
2370
|
+
options.expectedPolicyVersions?.discovery,
|
|
2371
|
+
"expected discovery policy version"
|
|
2372
|
+
),
|
|
2373
|
+
validation: positivePolicyVersion(
|
|
2374
|
+
options.expectedPolicyVersions?.validation,
|
|
2375
|
+
"expected validation policy version"
|
|
2376
|
+
)
|
|
2377
|
+
};
|
|
2378
|
+
let body;
|
|
2379
|
+
try {
|
|
2380
|
+
body = await requestHostedSecurityJson(
|
|
2381
|
+
options,
|
|
2382
|
+
`/registry/apps/${encodeURIComponent(appId)}/security/jobs`,
|
|
2383
|
+
{
|
|
2384
|
+
method: "POST",
|
|
2385
|
+
body: JSON.stringify({
|
|
2386
|
+
env,
|
|
2387
|
+
sourceId,
|
|
2388
|
+
...ref ? { ref } : {},
|
|
2389
|
+
...options.profile ? { profile: options.profile } : {},
|
|
2390
|
+
...options.clientRequestId ? { clientRequestId: hostedIdentifier(options.clientRequestId, "clientRequestId") } : {},
|
|
2391
|
+
sourceDisclosure: "redacted",
|
|
2392
|
+
expectedPlanDigest,
|
|
2393
|
+
expectedExecutionDigest,
|
|
2394
|
+
expectedPolicyVersions
|
|
2395
|
+
})
|
|
2396
|
+
},
|
|
2397
|
+
"start hosted security job"
|
|
2398
|
+
);
|
|
2399
|
+
} catch (error) {
|
|
2400
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2401
|
+
if (/\b(?:plan_conflict|policy_conflict|intent_conflict|security_ai_not_ready)\b/.test(message)) {
|
|
2402
|
+
throw new Error("Hosted security plan or execution intent changed or became unavailable after review; fetch a fresh intent and explicitly acknowledge its digest before enqueueing again", { cause: error });
|
|
2403
|
+
}
|
|
2404
|
+
throw error;
|
|
2405
|
+
}
|
|
2406
|
+
if (!body.job?.jobId) {
|
|
2407
|
+
throw new Error("odla.ai returned an invalid hosted security job");
|
|
2408
|
+
}
|
|
2409
|
+
return body.job;
|
|
2410
|
+
}
|
|
2411
|
+
async function getHostedSecurityJob(options) {
|
|
2412
|
+
const body = await requestHostedSecurityJson(
|
|
2413
|
+
options,
|
|
2414
|
+
hostedJobPath(options.appId, options.jobId),
|
|
2415
|
+
{},
|
|
2416
|
+
"read hosted security job"
|
|
2417
|
+
);
|
|
2418
|
+
if (!body.job?.jobId) throw new Error("odla.ai returned an invalid hosted security job");
|
|
2419
|
+
return body.job;
|
|
2420
|
+
}
|
|
2421
|
+
async function listHostedSecurityJobs(options) {
|
|
2422
|
+
const appId = hostedIdentifier(options.appId, "appId");
|
|
2423
|
+
const env = hostedIdentifier(options.env, "env");
|
|
2424
|
+
const body = await requestHostedSecurityJson(
|
|
2425
|
+
options,
|
|
2426
|
+
`/registry/apps/${encodeURIComponent(appId)}/security/jobs?env=${encodeURIComponent(env)}`,
|
|
2427
|
+
{},
|
|
2428
|
+
"list hosted security jobs"
|
|
2429
|
+
);
|
|
2430
|
+
return Array.isArray(body.jobs) ? body.jobs : [];
|
|
2431
|
+
}
|
|
2432
|
+
async function followHostedSecurityJob(options) {
|
|
2433
|
+
const interval = hostedPollInterval(options.pollIntervalMs);
|
|
2434
|
+
const now = options.now ?? Date.now;
|
|
2435
|
+
const deadline = now() + hostedPollTimeout(options.pollTimeoutMs ?? 60 * 6e4);
|
|
2436
|
+
const wait = options.wait ?? waitForHostedPoll;
|
|
2437
|
+
let prior = "";
|
|
2438
|
+
while (true) {
|
|
2439
|
+
const job = await getHostedSecurityJob(options);
|
|
2440
|
+
const fingerprint = `${job.status}:${job.updatedAt}`;
|
|
2441
|
+
if (fingerprint !== prior) options.onUpdate?.(Object.freeze({ ...job }));
|
|
2442
|
+
prior = fingerprint;
|
|
2443
|
+
if (isTerminalHostedSecurityStatus(job.status)) return job;
|
|
2444
|
+
if (now() >= deadline) {
|
|
2445
|
+
throw new Error(`Hosted security job ${job.jobId} did not finish before the polling deadline`);
|
|
2446
|
+
}
|
|
2447
|
+
await wait(Math.min(interval, Math.max(0, deadline - now())), options.signal);
|
|
2448
|
+
}
|
|
2449
|
+
}
|
|
2450
|
+
async function getHostedSecurityReport(options) {
|
|
2451
|
+
return requestHostedSecurityJson(
|
|
2452
|
+
options,
|
|
2453
|
+
`${hostedJobPath(options.appId, options.jobId)}/report`,
|
|
2454
|
+
{},
|
|
2455
|
+
"read hosted security report"
|
|
2456
|
+
);
|
|
2457
|
+
}
|
|
2458
|
+
function isTerminalHostedSecurityStatus(status) {
|
|
2459
|
+
return status === "completed" || status === "failed" || status === "cancelled";
|
|
2460
|
+
}
|
|
2461
|
+
function hostedJobPath(appIdInput, jobIdInput) {
|
|
2462
|
+
const appId = hostedIdentifier(appIdInput, "appId");
|
|
2463
|
+
const jobId = hostedIdentifier(jobIdInput, "jobId");
|
|
2464
|
+
return `/registry/apps/${encodeURIComponent(appId)}/security/jobs/${encodeURIComponent(jobId)}`;
|
|
2465
|
+
}
|
|
2466
|
+
function securityPlanDigest(value) {
|
|
2467
|
+
if (!/^sha256:[a-f0-9]{64}$/.test(value)) {
|
|
2468
|
+
throw new Error("expected plan digest must be a sha256 digest from security plan");
|
|
2469
|
+
}
|
|
2470
|
+
return value;
|
|
2471
|
+
}
|
|
2472
|
+
function securityExecutionDigest(value) {
|
|
2473
|
+
if (!/^sha256:[a-f0-9]{64}$/.test(value)) {
|
|
2474
|
+
throw new Error("expected execution digest must be a sha256 digest from security intent");
|
|
2475
|
+
}
|
|
2476
|
+
return value;
|
|
2477
|
+
}
|
|
2478
|
+
|
|
2479
|
+
// src/security-run-command.ts
|
|
2480
|
+
async function runSourceSecurityCommand(parsed, dependencies, sourceId) {
|
|
2481
|
+
assertArgs(parsed, [
|
|
2482
|
+
"config",
|
|
2483
|
+
"env",
|
|
2484
|
+
"profile",
|
|
2485
|
+
"platform",
|
|
2486
|
+
"source",
|
|
2487
|
+
"ref",
|
|
2488
|
+
"follow",
|
|
2489
|
+
"open",
|
|
2490
|
+
"json",
|
|
2491
|
+
"ack-redacted-source",
|
|
2492
|
+
"plan-digest",
|
|
2493
|
+
"fail-on",
|
|
2494
|
+
"fail-on-candidates",
|
|
2495
|
+
"allow-incomplete"
|
|
2496
|
+
], 2);
|
|
2497
|
+
const follow = parsed.options.follow !== false;
|
|
2498
|
+
if (!follow && (parsed.options["fail-on"] !== void 0 || parsed.options["fail-on-candidates"] !== void 0 || parsed.options["allow-incomplete"] !== void 0)) {
|
|
2499
|
+
throw new Error("hosted security gate options require following the job; remove --no-follow");
|
|
2500
|
+
}
|
|
2501
|
+
const acknowledgedDigest = requiredString(parsed.options["plan-digest"], "--plan-digest");
|
|
2502
|
+
const context = await hostedSecurityContext(parsed, dependencies);
|
|
2503
|
+
const plan = await getHostedSecurityPlan(context);
|
|
2504
|
+
if (parsed.options.json !== true) printHostedSecurityPlan(context.stdout, plan, context.appId);
|
|
2505
|
+
assertHostedSecurityPlanReady(plan);
|
|
2506
|
+
if (acknowledgedDigest !== plan.planDigest) {
|
|
2507
|
+
throw new Error(`--plan-digest does not match the current hosted security plan (${plan.planDigest}); review and explicitly acknowledge the current digest`);
|
|
2508
|
+
}
|
|
2509
|
+
const requestedRef = stringOpt(parsed.options.ref);
|
|
2510
|
+
const requestedProfile = securityProfile(stringOpt(parsed.options.profile));
|
|
2511
|
+
const preview = await getHostedSecurityIntent({
|
|
2512
|
+
...context,
|
|
2513
|
+
sourceId,
|
|
2514
|
+
ref: requestedRef,
|
|
2515
|
+
profile: requestedProfile
|
|
2516
|
+
});
|
|
2517
|
+
if (parsed.options.json !== true) printHostedSecurityIntent(context.stdout, preview.intent);
|
|
2518
|
+
if (preview.plan.planDigest !== plan.planDigest || preview.intent.planDigest !== plan.planDigest) {
|
|
2519
|
+
throw new Error(`hosted security plan changed while previewing execution (${preview.plan.planDigest}); review and explicitly acknowledge the current plan digest`);
|
|
2520
|
+
}
|
|
2521
|
+
const job = await startHostedSecurityJob({
|
|
2522
|
+
...context,
|
|
2523
|
+
sourceId,
|
|
2524
|
+
ref: requestedRef,
|
|
2525
|
+
profile: requestedProfile,
|
|
2526
|
+
clientRequestId: crypto.randomUUID(),
|
|
2527
|
+
sourceDisclosureAck: parsed.options["ack-redacted-source"] === true ? "redacted" : void 0,
|
|
2528
|
+
expectedPlanDigest: plan.planDigest,
|
|
2529
|
+
expectedExecutionDigest: preview.intent.executionDigest,
|
|
2530
|
+
expectedPolicyVersions: {
|
|
2531
|
+
discovery: plan.routes.discovery.policyVersion,
|
|
2532
|
+
validation: plan.routes.validation.policyVersion
|
|
2533
|
+
}
|
|
2534
|
+
});
|
|
2535
|
+
const result = follow ? await followHostedSecurityJob({
|
|
2536
|
+
...context,
|
|
2537
|
+
jobId: job.jobId,
|
|
2538
|
+
wait: dependencies.pollWait,
|
|
2539
|
+
onUpdate: parsed.options.json === true ? void 0 : (value) => printHostedJob(context.stdout, value, context.platform, context.appId)
|
|
2540
|
+
}) : job;
|
|
2541
|
+
if (!follow) {
|
|
2542
|
+
if (parsed.options.json === true) {
|
|
2543
|
+
context.stdout.log(JSON.stringify({ plan, intent: preview.intent, job: result }, null, 2));
|
|
2544
|
+
} else {
|
|
2545
|
+
printHostedJob(context.stdout, result, context.platform, context.appId);
|
|
2546
|
+
}
|
|
2547
|
+
return;
|
|
2548
|
+
}
|
|
2549
|
+
if (result.status !== "completed") {
|
|
2550
|
+
if (parsed.options.json === true) {
|
|
2551
|
+
context.stdout.log(JSON.stringify({ plan, intent: preview.intent, job: result }, null, 2));
|
|
2552
|
+
}
|
|
2553
|
+
throw new Error(`hosted security job ${result.jobId} ended ${result.status}${result.errorCode ? `: ${result.errorCode}` : ""}`);
|
|
2554
|
+
}
|
|
2555
|
+
const report = await getHostedSecurityReport({ ...context, jobId: result.jobId });
|
|
2556
|
+
if (parsed.options.json === true) {
|
|
2557
|
+
context.stdout.log(JSON.stringify({ plan, intent: preview.intent, job: result, report }, null, 2));
|
|
2558
|
+
} else {
|
|
2559
|
+
printHostedReport(context.stdout, report);
|
|
2560
|
+
}
|
|
2561
|
+
enforceHostedReportGate(report, parsed, context.stdout, parsed.options.json !== true);
|
|
2562
|
+
}
|
|
2563
|
+
async function runLocalSecurityCommand(parsed, dependencies) {
|
|
2564
|
+
if (parsed.options.source === true) {
|
|
2565
|
+
throw new Error("--source requires a source id; run security sources first");
|
|
2566
|
+
}
|
|
2567
|
+
assertArgs(parsed, [
|
|
2568
|
+
"config",
|
|
2569
|
+
"env",
|
|
2570
|
+
"out",
|
|
2571
|
+
"profile",
|
|
2572
|
+
"max-hunt-tasks",
|
|
2573
|
+
"run-id",
|
|
2574
|
+
"platform",
|
|
2575
|
+
"self",
|
|
2576
|
+
"ack-redacted-source",
|
|
2577
|
+
"open",
|
|
2578
|
+
"fail-on",
|
|
2579
|
+
"fail-on-candidates",
|
|
2580
|
+
"allow-incomplete"
|
|
2581
|
+
], 3);
|
|
2582
|
+
const configPath = stringOpt(parsed.options.config) ?? "odla.config.mjs";
|
|
2583
|
+
const selfAudit = parsed.options.self === true;
|
|
2584
|
+
const open = parsed.options.open === false ? false : parsed.options.open === true ? true : void 0;
|
|
2585
|
+
const platform = stringOpt(parsed.options.platform);
|
|
2586
|
+
const doFetch = dependencies.fetch ?? fetch;
|
|
2587
|
+
const out = dependencies.stdout ?? console;
|
|
2588
|
+
const result = await runHostedSecurity({
|
|
2589
|
+
configPath,
|
|
2590
|
+
selfAudit,
|
|
2591
|
+
target: parsed.positionals[2],
|
|
2592
|
+
out: stringOpt(parsed.options.out),
|
|
2593
|
+
env: stringOpt(parsed.options.env),
|
|
2594
|
+
profile: securityProfile(stringOpt(parsed.options.profile)),
|
|
2595
|
+
maxHuntTasks: numberOpt(parsed.options["max-hunt-tasks"], "--max-hunt-tasks"),
|
|
2596
|
+
runId: stringOpt(parsed.options["run-id"]),
|
|
2597
|
+
platform,
|
|
2598
|
+
sourceDisclosureAck: parsed.options["ack-redacted-source"] === true ? "redacted" : void 0,
|
|
2599
|
+
fetch: doFetch,
|
|
2600
|
+
stdout: out,
|
|
2601
|
+
getToken: async (request) => {
|
|
2602
|
+
if (request.scope === "platform:security:self") {
|
|
2603
|
+
return getScopedPlatformToken({
|
|
2604
|
+
platform: request.platform,
|
|
2605
|
+
scope: request.scope,
|
|
2606
|
+
open,
|
|
2607
|
+
fetch: doFetch,
|
|
2608
|
+
stdout: out,
|
|
2609
|
+
openApprovalUrl: dependencies.openUrl
|
|
2610
|
+
});
|
|
2611
|
+
}
|
|
2612
|
+
const cfg = await loadProjectConfig(configPath);
|
|
2613
|
+
if (platformAudience(cfg.platformUrl) !== platformAudience(request.platform)) {
|
|
2614
|
+
throw new Error("--platform cannot reuse a project developer token from another platform; update odla.config.mjs and authenticate there");
|
|
2615
|
+
}
|
|
2616
|
+
return getDeveloperToken(
|
|
2617
|
+
cfg,
|
|
2618
|
+
{ configPath, open, openApprovalUrl: dependencies.openUrl },
|
|
2619
|
+
doFetch,
|
|
2620
|
+
out
|
|
2621
|
+
);
|
|
2622
|
+
}
|
|
2623
|
+
});
|
|
2624
|
+
enforceLocalGate(result.report, parsed);
|
|
2625
|
+
}
|
|
2626
|
+
function enforceLocalGate(report, parsed) {
|
|
2627
|
+
const failOn = severityOpt(stringOpt(parsed.options["fail-on"]) ?? "high", "--fail-on");
|
|
2628
|
+
const candidateValue = parsed.options["fail-on-candidates"];
|
|
2629
|
+
const failOnCandidates = candidateValue === false ? void 0 : severityOpt(stringOpt(candidateValue) ?? "critical", "--fail-on-candidates");
|
|
2630
|
+
const confirmed = (0, import_security2.findingsAtOrAbove)(report, failOn);
|
|
2631
|
+
const leads = failOnCandidates ? (0, import_security2.findingsAtOrAbove)(report, failOnCandidates, true).filter((finding) => finding.disposition !== "confirmed") : [];
|
|
2632
|
+
const incomplete = report.coverageStatus === "incomplete" && parsed.options["allow-incomplete"] !== true;
|
|
2633
|
+
if (confirmed.length || leads.length || incomplete) {
|
|
2634
|
+
throw new Error(`hosted security gate failed: ${confirmed.length} confirmed >= ${failOn}; ${leads.length} leads >= ${failOnCandidates ?? "disabled"}${incomplete ? "; coverage incomplete" : ""}`);
|
|
2635
|
+
}
|
|
2636
|
+
}
|
|
2637
|
+
function severityOpt(value, flag) {
|
|
2638
|
+
if (["informational", "low", "medium", "high", "critical"].includes(value)) {
|
|
2639
|
+
return value;
|
|
2640
|
+
}
|
|
2641
|
+
throw new Error(`${flag} must be informational, low, medium, high, or critical`);
|
|
2642
|
+
}
|
|
2643
|
+
|
|
2644
|
+
// src/security-command.ts
|
|
2645
|
+
async function securityCommand(parsed, dependencies) {
|
|
2646
|
+
const sub = parsed.positionals[1];
|
|
2647
|
+
if (sub === "github") {
|
|
2648
|
+
await githubSecurityCommand(parsed, dependencies);
|
|
2649
|
+
return;
|
|
2650
|
+
}
|
|
2651
|
+
if (sub === "plan") {
|
|
2652
|
+
assertArgs(parsed, ["config", "env", "platform", "open", "json"], 2);
|
|
2653
|
+
const context = await hostedSecurityContext(parsed, dependencies);
|
|
2654
|
+
const plan = await getHostedSecurityPlan(context);
|
|
2655
|
+
if (parsed.options.json === true) context.stdout.log(JSON.stringify(plan, null, 2));
|
|
2656
|
+
else printHostedSecurityPlan(context.stdout, plan, context.appId);
|
|
2657
|
+
return;
|
|
2658
|
+
}
|
|
2659
|
+
if (sub === "sources") {
|
|
2660
|
+
await listSecuritySources(parsed, dependencies);
|
|
2661
|
+
return;
|
|
2662
|
+
}
|
|
2663
|
+
if (sub === "status") {
|
|
2664
|
+
await securityStatus(parsed, dependencies);
|
|
2665
|
+
return;
|
|
2666
|
+
}
|
|
2667
|
+
if (sub === "report") {
|
|
2668
|
+
assertArgs(parsed, ["config", "env", "platform", "open", "json"], 3);
|
|
2669
|
+
const jobId = requiredSecurityPositional(parsed, 2, "job id");
|
|
2670
|
+
const context = await hostedSecurityContext(parsed, dependencies);
|
|
2671
|
+
const report = await getHostedSecurityReport({ ...context, jobId });
|
|
2672
|
+
if (parsed.options.json === true) context.stdout.log(JSON.stringify(report, null, 2));
|
|
2673
|
+
else printHostedReport(context.stdout, report);
|
|
2674
|
+
return;
|
|
2675
|
+
}
|
|
2676
|
+
if (sub !== "run") {
|
|
2677
|
+
throw new Error('unknown security command. Try "odla-ai security plan", "security sources", or "security run".');
|
|
2678
|
+
}
|
|
2679
|
+
const sourceId = stringOpt(parsed.options.source);
|
|
2680
|
+
if (sourceId) await runSourceSecurityCommand(parsed, dependencies, sourceId);
|
|
2681
|
+
else await runLocalSecurityCommand(parsed, dependencies);
|
|
2682
|
+
}
|
|
2683
|
+
async function githubSecurityCommand(parsed, dependencies) {
|
|
2684
|
+
const action = parsed.positionals[2];
|
|
2685
|
+
if (action === "disconnect") {
|
|
2686
|
+
assertArgs(parsed, ["config", "env", "platform", "source", "open", "yes"], 3);
|
|
2687
|
+
const context2 = await hostedSecurityContext(parsed, dependencies);
|
|
2688
|
+
const sourceId = requiredString(parsed.options.source, "--source");
|
|
2689
|
+
const confirmed = parsed.options.yes === true || await interactiveConfirmation(
|
|
2690
|
+
`Disconnect GitHub security source ${sourceId} from ${context2.appId}/${context2.env}?`,
|
|
2691
|
+
dependencies
|
|
2692
|
+
);
|
|
2693
|
+
if (!confirmed) {
|
|
2694
|
+
throw new Error("GitHub source disconnect cancelled; pass --yes in a non-interactive shell");
|
|
2695
|
+
}
|
|
2696
|
+
await disconnectGitHubSecuritySource({ ...context2, sourceId });
|
|
2697
|
+
context2.stdout.log(`github: disconnected ${sourceId} from ${context2.appId}/${context2.env}`);
|
|
2698
|
+
return;
|
|
2699
|
+
}
|
|
2700
|
+
if (action !== "connect") {
|
|
2701
|
+
throw new Error('unknown security github command. Try "odla-ai security github connect".');
|
|
2702
|
+
}
|
|
2703
|
+
assertArgs(parsed, ["config", "env", "platform", "repo", "open"], 3);
|
|
2704
|
+
const context = await hostedSecurityContext(parsed, dependencies);
|
|
2705
|
+
const repository = stringOpt(parsed.options.repo) ?? await inferGitHubRepository(process.cwd(), dependencies.readGitOrigin);
|
|
2706
|
+
const connection = await connectGitHubSecuritySource({
|
|
2707
|
+
...context,
|
|
2708
|
+
repository,
|
|
2709
|
+
open: parsed.options.open !== false,
|
|
2710
|
+
openInstallUrl: dependencies.openUrl ?? openUrl,
|
|
2711
|
+
wait: dependencies.pollWait,
|
|
2712
|
+
stdout: context.stdout
|
|
2713
|
+
});
|
|
2714
|
+
context.stdout.log(`github: connected ${connection.repository ?? repository} (${connection.sourceId ?? "source pending"})`);
|
|
2715
|
+
context.stdout.log("github: odla.ai stores the installation; no PAT or GitHub token is written locally");
|
|
2716
|
+
}
|
|
2717
|
+
async function listSecuritySources(parsed, dependencies) {
|
|
2718
|
+
assertArgs(parsed, ["config", "env", "platform", "open", "json"], 2);
|
|
2719
|
+
const context = await hostedSecurityContext(parsed, dependencies);
|
|
2720
|
+
const [plan, sources] = await Promise.all([
|
|
2721
|
+
getHostedSecurityPlan(context),
|
|
2722
|
+
listGitHubSecuritySources(context)
|
|
2723
|
+
]);
|
|
2724
|
+
if (parsed.options.json === true) {
|
|
2725
|
+
context.stdout.log(JSON.stringify({ plan, sources }, null, 2));
|
|
2726
|
+
return;
|
|
2727
|
+
}
|
|
2728
|
+
printHostedSecurityPlan(context.stdout, plan, context.appId);
|
|
2729
|
+
if (!sources.length) {
|
|
2730
|
+
context.stdout.log(`No GitHub security sources connected for ${context.appId}/${context.env}.`);
|
|
2731
|
+
return;
|
|
2732
|
+
}
|
|
2733
|
+
context.stdout.log(`GitHub security sources for ${context.appId}/${context.env}
|
|
2734
|
+
source repository default ref status`);
|
|
2735
|
+
for (const source of sources) {
|
|
2736
|
+
context.stdout.log(`${source.sourceId} ${source.repository} ${source.defaultBranch} ${source.status}`);
|
|
2737
|
+
}
|
|
2738
|
+
}
|
|
2739
|
+
async function securityStatus(parsed, dependencies) {
|
|
2740
|
+
assertArgs(parsed, ["config", "env", "platform", "open", "json", "follow"], 3);
|
|
2741
|
+
const jobId = requiredSecurityPositional(parsed, 2, "job id");
|
|
2742
|
+
const context = await hostedSecurityContext(parsed, dependencies);
|
|
2743
|
+
const job = parsed.options.follow === true ? await followHostedSecurityJob({
|
|
2744
|
+
...context,
|
|
2745
|
+
jobId,
|
|
2746
|
+
wait: dependencies.pollWait,
|
|
2747
|
+
onUpdate: parsed.options.json === true ? void 0 : (value) => printHostedJob(context.stdout, value, context.platform, context.appId)
|
|
2748
|
+
}) : await getHostedSecurityJob({ ...context, jobId });
|
|
2749
|
+
if (parsed.options.json === true) context.stdout.log(JSON.stringify(job, null, 2));
|
|
2750
|
+
else if (parsed.options.follow !== true) {
|
|
2751
|
+
printHostedJob(context.stdout, job, context.platform, context.appId);
|
|
2752
|
+
}
|
|
1839
2753
|
}
|
|
1840
2754
|
|
|
1841
2755
|
// src/skill.ts
|
|
@@ -2173,7 +3087,7 @@ async function safeText3(res) {
|
|
|
2173
3087
|
}
|
|
2174
3088
|
|
|
2175
3089
|
// src/cli.ts
|
|
2176
|
-
async function runCli(argv = process.argv.slice(2)) {
|
|
3090
|
+
async function runCli(argv = process.argv.slice(2), dependencies = {}) {
|
|
2177
3091
|
const parsed = parseArgv(argv);
|
|
2178
3092
|
const command = parsed.positionals[0] ?? "help";
|
|
2179
3093
|
if (command === "version" || command === "-v" || parsed.options.version === true) {
|
|
@@ -2187,7 +3101,15 @@ async function runCli(argv = process.argv.slice(2)) {
|
|
|
2187
3101
|
return;
|
|
2188
3102
|
}
|
|
2189
3103
|
if (command === "init") {
|
|
2190
|
-
assertArgs(parsed, [
|
|
3104
|
+
assertArgs(parsed, [
|
|
3105
|
+
"app-id",
|
|
3106
|
+
"name",
|
|
3107
|
+
"config",
|
|
3108
|
+
"env",
|
|
3109
|
+
"services",
|
|
3110
|
+
"ai-provider",
|
|
3111
|
+
"force"
|
|
3112
|
+
], 1);
|
|
2191
3113
|
initProject({
|
|
2192
3114
|
appId: requiredString(parsed.options["app-id"], "--app-id"),
|
|
2193
3115
|
name: requiredString(parsed.options.name, "--name"),
|
|
@@ -2210,149 +3132,15 @@ async function runCli(argv = process.argv.slice(2)) {
|
|
|
2210
3132
|
return;
|
|
2211
3133
|
}
|
|
2212
3134
|
if (command === "admin") {
|
|
2213
|
-
|
|
2214
|
-
const action = parsed.positionals[2];
|
|
2215
|
-
const credentialSet = action === "credential" && parsed.positionals[3] === "set";
|
|
2216
|
-
const credentials = action === "credentials";
|
|
2217
|
-
const models = action === "models";
|
|
2218
|
-
const usage = action === "usage";
|
|
2219
|
-
const audit = action === "audit";
|
|
2220
|
-
if (area !== "ai" || action !== "show" && action !== "set" && !credentialSet && !credentials && !models && !usage && !audit) {
|
|
2221
|
-
throw new Error('unknown admin command. Try "odla-ai admin ai show".');
|
|
2222
|
-
}
|
|
2223
|
-
assertArgs(parsed, [
|
|
2224
|
-
"platform",
|
|
2225
|
-
"json",
|
|
2226
|
-
"open",
|
|
2227
|
-
"provider",
|
|
2228
|
-
"model",
|
|
2229
|
-
"enabled",
|
|
2230
|
-
"max-input-bytes",
|
|
2231
|
-
"max-output-tokens",
|
|
2232
|
-
"max-calls-per-run",
|
|
2233
|
-
"from-env",
|
|
2234
|
-
"stdin",
|
|
2235
|
-
"discovery-provider",
|
|
2236
|
-
"discovery-model",
|
|
2237
|
-
"validation-provider",
|
|
2238
|
-
"validation-model",
|
|
2239
|
-
"app-id",
|
|
2240
|
-
"env",
|
|
2241
|
-
"run-id",
|
|
2242
|
-
"limit"
|
|
2243
|
-
], credentialSet ? 5 : action === "set" ? 4 : 3);
|
|
2244
|
-
await adminAi({
|
|
2245
|
-
action: credentialSet ? "credential-set" : credentials ? "credentials" : models ? "models" : usage ? "usage" : audit ? "audit" : action,
|
|
2246
|
-
purpose: action === "set" ? parsed.positionals[3] : void 0,
|
|
2247
|
-
provider: stringOpt(parsed.options.provider),
|
|
2248
|
-
model: stringOpt(parsed.options.model),
|
|
2249
|
-
enabled: boolOpt(parsed.options.enabled),
|
|
2250
|
-
maxInputBytes: numberOpt(parsed.options["max-input-bytes"], "--max-input-bytes"),
|
|
2251
|
-
maxOutputTokens: numberOpt(parsed.options["max-output-tokens"], "--max-output-tokens"),
|
|
2252
|
-
maxCallsPerRun: numberOpt(parsed.options["max-calls-per-run"], "--max-calls-per-run"),
|
|
2253
|
-
platform: stringOpt(parsed.options.platform),
|
|
2254
|
-
json: parsed.options.json === true,
|
|
2255
|
-
open: parsed.options.open === false ? false : parsed.options.open === true ? true : void 0,
|
|
2256
|
-
credentialProvider: credentialSet ? parsed.positionals[4] : void 0,
|
|
2257
|
-
fromEnv: stringOpt(parsed.options["from-env"]),
|
|
2258
|
-
stdin: parsed.options.stdin === true,
|
|
2259
|
-
discoveryProvider: stringOpt(parsed.options["discovery-provider"]),
|
|
2260
|
-
discoveryModel: stringOpt(parsed.options["discovery-model"]),
|
|
2261
|
-
validationProvider: stringOpt(parsed.options["validation-provider"]),
|
|
2262
|
-
validationModel: stringOpt(parsed.options["validation-model"]),
|
|
2263
|
-
appId: stringOpt(parsed.options["app-id"]),
|
|
2264
|
-
env: stringOpt(parsed.options.env),
|
|
2265
|
-
runId: stringOpt(parsed.options["run-id"]),
|
|
2266
|
-
limit: numberOpt(parsed.options.limit, "--limit")
|
|
2267
|
-
});
|
|
3135
|
+
await adminCommand(parsed);
|
|
2268
3136
|
return;
|
|
2269
3137
|
}
|
|
2270
3138
|
if (command === "security") {
|
|
2271
|
-
|
|
2272
|
-
if (sub !== "run") throw new Error('unknown security command. Try "odla-ai security run".');
|
|
2273
|
-
assertArgs(parsed, [
|
|
2274
|
-
"config",
|
|
2275
|
-
"env",
|
|
2276
|
-
"out",
|
|
2277
|
-
"profile",
|
|
2278
|
-
"max-hunt-tasks",
|
|
2279
|
-
"run-id",
|
|
2280
|
-
"platform",
|
|
2281
|
-
"self",
|
|
2282
|
-
"ack-redacted-source",
|
|
2283
|
-
"open",
|
|
2284
|
-
"fail-on",
|
|
2285
|
-
"fail-on-candidates",
|
|
2286
|
-
"allow-incomplete"
|
|
2287
|
-
], 3);
|
|
2288
|
-
const configPath = stringOpt(parsed.options.config) ?? "odla.config.mjs";
|
|
2289
|
-
const selfAudit = parsed.options.self === true;
|
|
2290
|
-
const open = parsed.options.open === false ? false : parsed.options.open === true ? true : void 0;
|
|
2291
|
-
const platform = stringOpt(parsed.options.platform);
|
|
2292
|
-
const result = await runHostedSecurity({
|
|
2293
|
-
configPath,
|
|
2294
|
-
selfAudit,
|
|
2295
|
-
target: parsed.positionals[2],
|
|
2296
|
-
out: stringOpt(parsed.options.out),
|
|
2297
|
-
env: stringOpt(parsed.options.env),
|
|
2298
|
-
profile: securityProfile(stringOpt(parsed.options.profile)),
|
|
2299
|
-
maxHuntTasks: numberOpt(parsed.options["max-hunt-tasks"], "--max-hunt-tasks"),
|
|
2300
|
-
runId: stringOpt(parsed.options["run-id"]),
|
|
2301
|
-
platform,
|
|
2302
|
-
sourceDisclosureAck: parsed.options["ack-redacted-source"] === true ? "redacted" : void 0,
|
|
2303
|
-
getToken: async (request) => {
|
|
2304
|
-
if (request.scope === "platform:security:self") {
|
|
2305
|
-
return getScopedPlatformToken({ platform: request.platform, scope: request.scope, open });
|
|
2306
|
-
}
|
|
2307
|
-
const cfg = await loadProjectConfig(configPath);
|
|
2308
|
-
if (platformAudience(cfg.platformUrl) !== platformAudience(request.platform)) {
|
|
2309
|
-
throw new Error("--platform cannot reuse a project developer token from another platform; update odla.config.mjs and authenticate there");
|
|
2310
|
-
}
|
|
2311
|
-
return getDeveloperToken(cfg, { configPath, open }, fetch, console);
|
|
2312
|
-
}
|
|
2313
|
-
});
|
|
2314
|
-
const failOn = severityOpt(stringOpt(parsed.options["fail-on"]) ?? "high", "--fail-on");
|
|
2315
|
-
const candidateValue = parsed.options["fail-on-candidates"];
|
|
2316
|
-
const failOnCandidates = candidateValue === false ? void 0 : severityOpt(stringOpt(candidateValue) ?? "critical", "--fail-on-candidates");
|
|
2317
|
-
const confirmed = (0, import_security2.findingsAtOrAbove)(result.report, failOn);
|
|
2318
|
-
const leads = failOnCandidates ? (0, import_security2.findingsAtOrAbove)(result.report, failOnCandidates, true).filter((finding) => finding.disposition !== "confirmed") : [];
|
|
2319
|
-
const incomplete = result.report.coverageStatus === "incomplete" && parsed.options["allow-incomplete"] !== true;
|
|
2320
|
-
if (confirmed.length || leads.length || incomplete) {
|
|
2321
|
-
throw new Error(`hosted security gate failed: ${confirmed.length} confirmed >= ${failOn}; ${leads.length} leads >= ${failOnCandidates ?? "disabled"}${incomplete ? "; coverage incomplete" : ""}`);
|
|
2322
|
-
}
|
|
3139
|
+
await securityCommand(parsed, dependencies);
|
|
2323
3140
|
return;
|
|
2324
3141
|
}
|
|
2325
3142
|
if (command === "provision") {
|
|
2326
|
-
|
|
2327
|
-
parsed,
|
|
2328
|
-
[
|
|
2329
|
-
"config",
|
|
2330
|
-
"dry-run",
|
|
2331
|
-
"rotate-keys",
|
|
2332
|
-
"rotate-o11y-token",
|
|
2333
|
-
"push-secrets",
|
|
2334
|
-
"write-credentials",
|
|
2335
|
-
"write-dev-vars",
|
|
2336
|
-
"token",
|
|
2337
|
-
"open",
|
|
2338
|
-
"yes"
|
|
2339
|
-
],
|
|
2340
|
-
1
|
|
2341
|
-
);
|
|
2342
|
-
const writeDevVars2 = parsed.options["write-dev-vars"];
|
|
2343
|
-
const opts = {
|
|
2344
|
-
configPath: stringOpt(parsed.options.config) ?? "odla.config.mjs",
|
|
2345
|
-
dryRun: parsed.options["dry-run"] === true,
|
|
2346
|
-
rotateKeys: parsed.options["rotate-keys"] === true,
|
|
2347
|
-
rotateO11yToken: parsed.options["rotate-o11y-token"] === true,
|
|
2348
|
-
pushSecrets: parsed.options["push-secrets"] === true,
|
|
2349
|
-
writeCredentials: parsed.options["write-credentials"] !== false,
|
|
2350
|
-
writeDevVars: typeof writeDevVars2 === "string" ? writeDevVars2 : writeDevVars2 === true,
|
|
2351
|
-
token: stringOpt(parsed.options.token),
|
|
2352
|
-
open: parsed.options.open === false ? false : parsed.options.open === true ? true : void 0,
|
|
2353
|
-
yes: parsed.options.yes === true
|
|
2354
|
-
};
|
|
2355
|
-
await provision(opts);
|
|
3143
|
+
await provisionCommand(parsed);
|
|
2356
3144
|
return;
|
|
2357
3145
|
}
|
|
2358
3146
|
if (command === "smoke") {
|
|
@@ -2378,7 +3166,9 @@ async function runCli(argv = process.argv.slice(2)) {
|
|
|
2378
3166
|
}
|
|
2379
3167
|
if (command === "skill") {
|
|
2380
3168
|
const sub = parsed.positionals[1];
|
|
2381
|
-
if (sub !== "install")
|
|
3169
|
+
if (sub !== "install") {
|
|
3170
|
+
throw new Error(`unknown skill subcommand "${sub ?? ""}". Try "odla-ai skill install".`);
|
|
3171
|
+
}
|
|
2382
3172
|
assertArgs(parsed, ["dir", "global", "force", "agent", "harness"], 2);
|
|
2383
3173
|
installSkill({
|
|
2384
3174
|
dir: stringOpt(parsed.options.dir),
|
|
@@ -2390,7 +3180,9 @@ async function runCli(argv = process.argv.slice(2)) {
|
|
|
2390
3180
|
}
|
|
2391
3181
|
if (command === "secrets") {
|
|
2392
3182
|
const sub = parsed.positionals[1];
|
|
2393
|
-
if (sub !== "push")
|
|
3183
|
+
if (sub !== "push") {
|
|
3184
|
+
throw new Error(`unknown secrets subcommand "${sub ?? ""}". Try "odla-ai secrets push --env dev".`);
|
|
3185
|
+
}
|
|
2394
3186
|
assertArgs(parsed, ["config", "env", "dry-run", "yes"], 2);
|
|
2395
3187
|
await secretsPush({
|
|
2396
3188
|
configPath: stringOpt(parsed.options.config) ?? "odla.config.mjs",
|
|
@@ -2402,29 +3194,33 @@ async function runCli(argv = process.argv.slice(2)) {
|
|
|
2402
3194
|
}
|
|
2403
3195
|
throw new Error(`unknown command "${command}". Run "odla-ai help".`);
|
|
2404
3196
|
}
|
|
2405
|
-
function
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
];
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
3197
|
+
async function provisionCommand(parsed) {
|
|
3198
|
+
assertArgs(parsed, [
|
|
3199
|
+
"config",
|
|
3200
|
+
"dry-run",
|
|
3201
|
+
"rotate-keys",
|
|
3202
|
+
"rotate-o11y-token",
|
|
3203
|
+
"push-secrets",
|
|
3204
|
+
"write-credentials",
|
|
3205
|
+
"write-dev-vars",
|
|
3206
|
+
"token",
|
|
3207
|
+
"open",
|
|
3208
|
+
"yes"
|
|
3209
|
+
], 1);
|
|
3210
|
+
const writeDevVars2 = parsed.options["write-dev-vars"];
|
|
3211
|
+
const options = {
|
|
3212
|
+
configPath: stringOpt(parsed.options.config) ?? "odla.config.mjs",
|
|
3213
|
+
dryRun: parsed.options["dry-run"] === true,
|
|
3214
|
+
rotateKeys: parsed.options["rotate-keys"] === true,
|
|
3215
|
+
rotateO11yToken: parsed.options["rotate-o11y-token"] === true,
|
|
3216
|
+
pushSecrets: parsed.options["push-secrets"] === true,
|
|
3217
|
+
writeCredentials: parsed.options["write-credentials"] !== false,
|
|
3218
|
+
writeDevVars: typeof writeDevVars2 === "string" ? writeDevVars2 : writeDevVars2 === true,
|
|
3219
|
+
token: stringOpt(parsed.options.token),
|
|
3220
|
+
open: parsed.options.open === false ? false : parsed.options.open === true ? true : void 0,
|
|
3221
|
+
yes: parsed.options.yes === true
|
|
3222
|
+
};
|
|
3223
|
+
await provision(options);
|
|
2428
3224
|
}
|
|
2429
3225
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2430
3226
|
0 && (module.exports = {
|
|
@@ -2432,16 +3228,29 @@ function harnessOption(value, flag) {
|
|
|
2432
3228
|
CAPABILITIES,
|
|
2433
3229
|
SYSTEM_AI_PURPOSES,
|
|
2434
3230
|
adminAi,
|
|
3231
|
+
connectGitHubSecuritySource,
|
|
3232
|
+
disconnectGitHubSecuritySource,
|
|
2435
3233
|
doctor,
|
|
3234
|
+
followHostedSecurityJob,
|
|
3235
|
+
getHostedSecurityIntent,
|
|
3236
|
+
getHostedSecurityJob,
|
|
3237
|
+
getHostedSecurityPlan,
|
|
3238
|
+
getHostedSecurityReport,
|
|
2436
3239
|
getScopedPlatformToken,
|
|
3240
|
+
inferGitHubRepository,
|
|
2437
3241
|
initProject,
|
|
2438
3242
|
installSkill,
|
|
3243
|
+
isTerminalHostedSecurityStatus,
|
|
3244
|
+
listGitHubSecuritySources,
|
|
3245
|
+
listHostedSecurityJobs,
|
|
2439
3246
|
printCapabilities,
|
|
2440
3247
|
provision,
|
|
2441
3248
|
redactSecrets,
|
|
3249
|
+
repositoryFromGitRemote,
|
|
2442
3250
|
runCli,
|
|
2443
3251
|
runHostedSecurity,
|
|
2444
3252
|
secretsPush,
|
|
2445
|
-
smoke
|
|
3253
|
+
smoke,
|
|
3254
|
+
startHostedSecurityJob
|
|
2446
3255
|
});
|
|
2447
3256
|
//# sourceMappingURL=index.cjs.map
|