@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
|
@@ -651,6 +651,7 @@ var CAPABILITIES = {
|
|
|
651
651
|
"push db schema/rules and configure platform AI, auth, and deployment links",
|
|
652
652
|
"validate config offline and smoke-test a provisioned db environment",
|
|
653
653
|
"run app-attributed hosted security discovery and independent validation without provider keys",
|
|
654
|
+
"connect/revoke source-read-only GitHub sources and drive commit-pinned hosted security jobs without PATs or provider keys",
|
|
654
655
|
"let admins manage system AI policy and credentials, inspect attributed usage, and read immutable admin changes through separate short-lived capability-only approvals"
|
|
655
656
|
],
|
|
656
657
|
agent: [
|
|
@@ -663,12 +664,14 @@ var CAPABILITIES = {
|
|
|
663
664
|
"consent to production changes with --yes",
|
|
664
665
|
"request destructive credential rotation explicitly",
|
|
665
666
|
"review application semantics, security findings, releases, and merges",
|
|
666
|
-
"approve redacted-source disclosure before hosted security reasoning"
|
|
667
|
+
"approve redacted-source disclosure before hosted security reasoning",
|
|
668
|
+
"approve GitHub App repository access separately from redacted-snippet disclosure"
|
|
667
669
|
],
|
|
668
670
|
studio: [
|
|
669
671
|
"view telemetry and environment state",
|
|
670
672
|
"perform manual credential recovery when the CLI's local shown-once copy is unavailable",
|
|
671
|
-
"configure system AI purposes and view app/environment/run-attributed usage"
|
|
673
|
+
"configure system AI purposes and view app/environment/run-attributed usage",
|
|
674
|
+
"connect/revoke GitHub security sources and inspect ref-to-SHA jobs, routes, retention, coverage, and normalized reports"
|
|
672
675
|
]
|
|
673
676
|
};
|
|
674
677
|
function printCapabilities(json = false, out = console) {
|
|
@@ -1658,6 +1661,383 @@ function formatBudget(usage) {
|
|
|
1658
1661
|
return usage ? `${usage.usedCalls}/${usage.maxCalls} skipped=${usage.skippedCalls}` : "caller-managed";
|
|
1659
1662
|
}
|
|
1660
1663
|
|
|
1664
|
+
// src/security-hosted-github.ts
|
|
1665
|
+
import { execFile } from "child_process";
|
|
1666
|
+
import { promisify } from "util";
|
|
1667
|
+
|
|
1668
|
+
// src/security-hosted-request.ts
|
|
1669
|
+
async function requestHostedSecurityJson(options, path, init, action) {
|
|
1670
|
+
const platform = platformAudience(options.platform);
|
|
1671
|
+
const token = hostedSecurityCredential(options.token);
|
|
1672
|
+
const requestInit = {
|
|
1673
|
+
...init,
|
|
1674
|
+
redirect: "error",
|
|
1675
|
+
credentials: "omit",
|
|
1676
|
+
cache: "no-store",
|
|
1677
|
+
signal: options.signal,
|
|
1678
|
+
headers: {
|
|
1679
|
+
authorization: `Bearer ${token}`,
|
|
1680
|
+
"content-type": "application/json",
|
|
1681
|
+
...init.headers
|
|
1682
|
+
}
|
|
1683
|
+
};
|
|
1684
|
+
const response = await (options.fetch ?? fetch)(new URL(path, platform), requestInit);
|
|
1685
|
+
const body = await response.json().catch(() => ({}));
|
|
1686
|
+
if (!response.ok) {
|
|
1687
|
+
const code = optionalHostedText(body.error?.code, "error code", 128);
|
|
1688
|
+
const message = optionalHostedText(body.error?.message, "error message", 300);
|
|
1689
|
+
throw new Error(`${action} failed (${response.status})${code ? ` ${code}` : ""}${message ? `: ${message}` : ""}`);
|
|
1690
|
+
}
|
|
1691
|
+
return body;
|
|
1692
|
+
}
|
|
1693
|
+
function hostedIdentifier(value, name) {
|
|
1694
|
+
const result = optionalHostedText(value, name, 180);
|
|
1695
|
+
if (!result || !/^[A-Za-z0-9][A-Za-z0-9._:-]*$/.test(result)) {
|
|
1696
|
+
throw new Error(`${name} is invalid`);
|
|
1697
|
+
}
|
|
1698
|
+
return result;
|
|
1699
|
+
}
|
|
1700
|
+
function positivePolicyVersion(value, name) {
|
|
1701
|
+
if (!Number.isSafeInteger(value) || value < 1) {
|
|
1702
|
+
throw new Error(`${name} is invalid`);
|
|
1703
|
+
}
|
|
1704
|
+
return value;
|
|
1705
|
+
}
|
|
1706
|
+
function optionalHostedText(value, name, maxLength) {
|
|
1707
|
+
if (value === void 0 || value === null || value === "") return void 0;
|
|
1708
|
+
if (typeof value !== "string" || value.length > maxLength || /[\u0000-\u001f\u007f]/.test(value)) {
|
|
1709
|
+
throw new Error(`${name} is invalid`);
|
|
1710
|
+
}
|
|
1711
|
+
return value;
|
|
1712
|
+
}
|
|
1713
|
+
function githubRepositoryName(value) {
|
|
1714
|
+
if (typeof value !== "string" || value.length > 201) {
|
|
1715
|
+
throw new Error("repository must be owner/name");
|
|
1716
|
+
}
|
|
1717
|
+
const parts = value.split("/");
|
|
1718
|
+
const owner = parts[0] ?? "";
|
|
1719
|
+
const name = (parts[1] ?? "").replace(/\.git$/i, "");
|
|
1720
|
+
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 === "..") {
|
|
1721
|
+
throw new Error("repository must be owner/name");
|
|
1722
|
+
}
|
|
1723
|
+
return `${owner}/${name}`;
|
|
1724
|
+
}
|
|
1725
|
+
function trustedGitHubInstallUrl(value) {
|
|
1726
|
+
let url;
|
|
1727
|
+
try {
|
|
1728
|
+
url = new URL(value);
|
|
1729
|
+
} catch {
|
|
1730
|
+
throw new Error("odla.ai returned an invalid GitHub installation URL");
|
|
1731
|
+
}
|
|
1732
|
+
if (url.protocol !== "https:" || url.hostname !== "github.com" || url.username || url.password) {
|
|
1733
|
+
throw new Error("odla.ai returned an untrusted GitHub installation URL");
|
|
1734
|
+
}
|
|
1735
|
+
return url.toString();
|
|
1736
|
+
}
|
|
1737
|
+
function hostedPollInterval(value = 2e3) {
|
|
1738
|
+
if (!Number.isSafeInteger(value) || value < 100 || value > 3e4) {
|
|
1739
|
+
throw new Error("poll interval must be 100-30000ms");
|
|
1740
|
+
}
|
|
1741
|
+
return value;
|
|
1742
|
+
}
|
|
1743
|
+
function hostedPollTimeout(value = 10 * 6e4) {
|
|
1744
|
+
if (!Number.isSafeInteger(value) || value < 1e3 || value > 60 * 6e4) {
|
|
1745
|
+
throw new Error("poll timeout must be 1000-3600000ms");
|
|
1746
|
+
}
|
|
1747
|
+
return value;
|
|
1748
|
+
}
|
|
1749
|
+
async function waitForHostedPoll(milliseconds, signal) {
|
|
1750
|
+
if (signal?.aborted) throw signal.reason ?? new DOMException("aborted", "AbortError");
|
|
1751
|
+
await new Promise((resolve7, reject) => {
|
|
1752
|
+
const timer = setTimeout(resolve7, milliseconds);
|
|
1753
|
+
signal?.addEventListener("abort", () => {
|
|
1754
|
+
clearTimeout(timer);
|
|
1755
|
+
reject(signal.reason ?? new DOMException("aborted", "AbortError"));
|
|
1756
|
+
}, { once: true });
|
|
1757
|
+
});
|
|
1758
|
+
}
|
|
1759
|
+
function isValidHostedSecurityPlan(value, env) {
|
|
1760
|
+
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;
|
|
1761
|
+
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;
|
|
1762
|
+
return validRoute(value.routes?.discovery, "security.discovery") && validRoute(value.routes?.validation, "security.validation");
|
|
1763
|
+
}
|
|
1764
|
+
function hostedSecurityCredential(value) {
|
|
1765
|
+
if (typeof value !== "string" || value.length < 8 || value.length > 8192 || /\s|[\u0000-\u001f\u007f]/.test(value)) {
|
|
1766
|
+
throw new Error("Hosted security requires an injected odla developer token");
|
|
1767
|
+
}
|
|
1768
|
+
return value;
|
|
1769
|
+
}
|
|
1770
|
+
|
|
1771
|
+
// src/security-hosted-github.ts
|
|
1772
|
+
async function connectGitHubSecuritySource(options) {
|
|
1773
|
+
const out = options.stdout ?? console;
|
|
1774
|
+
const repository = githubRepositoryName(options.repository);
|
|
1775
|
+
const attempt = await requestHostedSecurityJson(
|
|
1776
|
+
options,
|
|
1777
|
+
"/registry/github/connect",
|
|
1778
|
+
{
|
|
1779
|
+
method: "POST",
|
|
1780
|
+
body: JSON.stringify({
|
|
1781
|
+
appId: hostedIdentifier(options.appId, "appId"),
|
|
1782
|
+
env: hostedIdentifier(options.env, "env"),
|
|
1783
|
+
repository
|
|
1784
|
+
})
|
|
1785
|
+
},
|
|
1786
|
+
"start GitHub connection"
|
|
1787
|
+
);
|
|
1788
|
+
const serverExpiry = Date.parse(attempt?.expiresAt ?? "");
|
|
1789
|
+
if (!attempt?.attemptId || !attempt.installUrl || !Number.isFinite(serverExpiry)) {
|
|
1790
|
+
throw new Error("odla.ai returned an invalid GitHub connection attempt");
|
|
1791
|
+
}
|
|
1792
|
+
const installUrl = trustedGitHubInstallUrl(attempt.installUrl);
|
|
1793
|
+
out.log(`GitHub approval: ${installUrl}`);
|
|
1794
|
+
if (options.open !== false) {
|
|
1795
|
+
await (options.openInstallUrl ?? openUrl)(installUrl);
|
|
1796
|
+
out.log("github: opened installation approval in your browser");
|
|
1797
|
+
}
|
|
1798
|
+
const interval = hostedPollInterval(options.pollIntervalMs);
|
|
1799
|
+
const now = options.now ?? Date.now;
|
|
1800
|
+
const deadline = Math.min(serverExpiry, now() + hostedPollTimeout(options.pollTimeoutMs));
|
|
1801
|
+
const wait = options.wait ?? waitForHostedPoll;
|
|
1802
|
+
while (true) {
|
|
1803
|
+
const state = await requestHostedSecurityJson(
|
|
1804
|
+
options,
|
|
1805
|
+
`/registry/github/connect/${encodeURIComponent(attempt.attemptId)}`,
|
|
1806
|
+
{},
|
|
1807
|
+
"check GitHub connection"
|
|
1808
|
+
);
|
|
1809
|
+
if (state.status !== "pending") {
|
|
1810
|
+
if (state.status === "connected") return state;
|
|
1811
|
+
throw new Error(`GitHub connection ${state.status}${state.failureCode ? `: ${state.failureCode}` : ""}`);
|
|
1812
|
+
}
|
|
1813
|
+
if (now() >= deadline) throw new Error("GitHub connection approval timed out");
|
|
1814
|
+
await wait(Math.min(interval, Math.max(0, deadline - now())), options.signal);
|
|
1815
|
+
}
|
|
1816
|
+
}
|
|
1817
|
+
async function listGitHubSecuritySources(options) {
|
|
1818
|
+
const appId = hostedIdentifier(options.appId, "appId");
|
|
1819
|
+
const env = hostedIdentifier(options.env, "env");
|
|
1820
|
+
const body = await requestHostedSecurityJson(
|
|
1821
|
+
options,
|
|
1822
|
+
`/registry/apps/${encodeURIComponent(appId)}/github/sources?env=${encodeURIComponent(env)}`,
|
|
1823
|
+
{},
|
|
1824
|
+
"list GitHub security sources"
|
|
1825
|
+
);
|
|
1826
|
+
return Array.isArray(body.sources) ? body.sources : [];
|
|
1827
|
+
}
|
|
1828
|
+
async function disconnectGitHubSecuritySource(options) {
|
|
1829
|
+
const appId = hostedIdentifier(options.appId, "appId");
|
|
1830
|
+
const sourceId = hostedIdentifier(options.sourceId, "sourceId");
|
|
1831
|
+
await requestHostedSecurityJson(
|
|
1832
|
+
options,
|
|
1833
|
+
`/registry/apps/${encodeURIComponent(appId)}/github/sources/${encodeURIComponent(sourceId)}`,
|
|
1834
|
+
{ method: "DELETE" },
|
|
1835
|
+
"disconnect GitHub security source"
|
|
1836
|
+
);
|
|
1837
|
+
}
|
|
1838
|
+
function repositoryFromGitRemote(remoteInput) {
|
|
1839
|
+
const remote = remoteInput.trim();
|
|
1840
|
+
const scp = /^git@github\.com:([^/\s]+)\/([^/\s]+?)\/?$/.exec(remote);
|
|
1841
|
+
if (scp) return githubRepositoryName(`${scp[1]}/${scp[2].replace(/\.git$/, "")}`);
|
|
1842
|
+
let url;
|
|
1843
|
+
try {
|
|
1844
|
+
url = new URL(remote);
|
|
1845
|
+
} catch {
|
|
1846
|
+
throw new Error("origin must be a github.com HTTPS or SSH repository URL");
|
|
1847
|
+
}
|
|
1848
|
+
if (url.hostname !== "github.com" || url.protocol !== "https:" && url.protocol !== "ssh:") {
|
|
1849
|
+
throw new Error("origin must be a github.com HTTPS or SSH repository URL");
|
|
1850
|
+
}
|
|
1851
|
+
if (url.password || url.protocol === "https:" && url.username || url.search || url.hash) {
|
|
1852
|
+
throw new Error("credential-bearing GitHub origin URLs are not accepted");
|
|
1853
|
+
}
|
|
1854
|
+
const parts = url.pathname.replace(/^\/+|\/+$/g, "").split("/");
|
|
1855
|
+
if (parts.length !== 2) {
|
|
1856
|
+
throw new Error("origin must identify one GitHub owner/name repository");
|
|
1857
|
+
}
|
|
1858
|
+
return githubRepositoryName(`${parts[0]}/${parts[1].replace(/\.git$/, "")}`);
|
|
1859
|
+
}
|
|
1860
|
+
async function inferGitHubRepository(cwd = process.cwd(), readOrigin = defaultReadOrigin) {
|
|
1861
|
+
let remote;
|
|
1862
|
+
try {
|
|
1863
|
+
remote = await readOrigin(cwd);
|
|
1864
|
+
} catch {
|
|
1865
|
+
throw new Error("Could not read git origin; pass --repo owner/name");
|
|
1866
|
+
}
|
|
1867
|
+
return repositoryFromGitRemote(remote);
|
|
1868
|
+
}
|
|
1869
|
+
async function defaultReadOrigin(cwd) {
|
|
1870
|
+
const result = await promisify(execFile)(
|
|
1871
|
+
"git",
|
|
1872
|
+
["remote", "get-url", "origin"],
|
|
1873
|
+
{ cwd, encoding: "utf8" }
|
|
1874
|
+
);
|
|
1875
|
+
return result.stdout;
|
|
1876
|
+
}
|
|
1877
|
+
|
|
1878
|
+
// src/security-hosted-intent.ts
|
|
1879
|
+
async function getHostedSecurityIntent(options) {
|
|
1880
|
+
const appId = hostedIdentifier(options.appId, "appId");
|
|
1881
|
+
const env = hostedIdentifier(options.env, "env");
|
|
1882
|
+
const sourceId = hostedIdentifier(options.sourceId, "sourceId");
|
|
1883
|
+
const ref = optionalHostedText(options.ref, "ref", 255);
|
|
1884
|
+
const query = new URLSearchParams({ env, sourceId });
|
|
1885
|
+
if (ref) query.set("ref", ref);
|
|
1886
|
+
if (options.profile) query.set("profile", options.profile);
|
|
1887
|
+
const response = await requestHostedSecurityJson(
|
|
1888
|
+
options,
|
|
1889
|
+
`/registry/apps/${encodeURIComponent(appId)}/security/intent?${query.toString()}`,
|
|
1890
|
+
{},
|
|
1891
|
+
"read hosted security execution intent"
|
|
1892
|
+
);
|
|
1893
|
+
if (!isValidHostedSecurityPlan(response.plan, env) || !isValidIntent(response.intent, { appId, env, sourceId })) {
|
|
1894
|
+
throw new Error("odla.ai returned an invalid hosted security execution intent");
|
|
1895
|
+
}
|
|
1896
|
+
if (response.intent.planDigest !== response.plan.planDigest) {
|
|
1897
|
+
throw new Error("odla.ai returned a hosted security intent for a different processing plan");
|
|
1898
|
+
}
|
|
1899
|
+
return response;
|
|
1900
|
+
}
|
|
1901
|
+
function isValidIntent(value, expected) {
|
|
1902
|
+
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";
|
|
1903
|
+
}
|
|
1904
|
+
|
|
1905
|
+
// src/security-hosted-jobs.ts
|
|
1906
|
+
async function getHostedSecurityPlan(options) {
|
|
1907
|
+
const appId = hostedIdentifier(options.appId, "appId");
|
|
1908
|
+
const env = hostedIdentifier(options.env, "env");
|
|
1909
|
+
const plan = await requestHostedSecurityJson(
|
|
1910
|
+
options,
|
|
1911
|
+
`/registry/apps/${encodeURIComponent(appId)}/security/plan?env=${encodeURIComponent(env)}`,
|
|
1912
|
+
{},
|
|
1913
|
+
"read hosted security disclosure plan"
|
|
1914
|
+
);
|
|
1915
|
+
if (!isValidHostedSecurityPlan(plan, env)) {
|
|
1916
|
+
throw new Error("odla.ai returned an invalid hosted security disclosure plan");
|
|
1917
|
+
}
|
|
1918
|
+
return plan;
|
|
1919
|
+
}
|
|
1920
|
+
async function startHostedSecurityJob(options) {
|
|
1921
|
+
if (options.sourceDisclosureAck !== "redacted") {
|
|
1922
|
+
throw new Error("Hosted GitHub security requires sourceDisclosureAck=redacted; repository access alone is not disclosure consent");
|
|
1923
|
+
}
|
|
1924
|
+
const appId = hostedIdentifier(options.appId, "appId");
|
|
1925
|
+
const env = hostedIdentifier(options.env, "env");
|
|
1926
|
+
const sourceId = hostedIdentifier(options.sourceId, "sourceId");
|
|
1927
|
+
const ref = optionalHostedText(options.ref, "ref", 255);
|
|
1928
|
+
const expectedPlanDigest = securityPlanDigest(options.expectedPlanDigest);
|
|
1929
|
+
const expectedExecutionDigest = securityExecutionDigest(options.expectedExecutionDigest);
|
|
1930
|
+
const expectedPolicyVersions = {
|
|
1931
|
+
discovery: positivePolicyVersion(
|
|
1932
|
+
options.expectedPolicyVersions?.discovery,
|
|
1933
|
+
"expected discovery policy version"
|
|
1934
|
+
),
|
|
1935
|
+
validation: positivePolicyVersion(
|
|
1936
|
+
options.expectedPolicyVersions?.validation,
|
|
1937
|
+
"expected validation policy version"
|
|
1938
|
+
)
|
|
1939
|
+
};
|
|
1940
|
+
let body;
|
|
1941
|
+
try {
|
|
1942
|
+
body = await requestHostedSecurityJson(
|
|
1943
|
+
options,
|
|
1944
|
+
`/registry/apps/${encodeURIComponent(appId)}/security/jobs`,
|
|
1945
|
+
{
|
|
1946
|
+
method: "POST",
|
|
1947
|
+
body: JSON.stringify({
|
|
1948
|
+
env,
|
|
1949
|
+
sourceId,
|
|
1950
|
+
...ref ? { ref } : {},
|
|
1951
|
+
...options.profile ? { profile: options.profile } : {},
|
|
1952
|
+
...options.clientRequestId ? { clientRequestId: hostedIdentifier(options.clientRequestId, "clientRequestId") } : {},
|
|
1953
|
+
sourceDisclosure: "redacted",
|
|
1954
|
+
expectedPlanDigest,
|
|
1955
|
+
expectedExecutionDigest,
|
|
1956
|
+
expectedPolicyVersions
|
|
1957
|
+
})
|
|
1958
|
+
},
|
|
1959
|
+
"start hosted security job"
|
|
1960
|
+
);
|
|
1961
|
+
} catch (error) {
|
|
1962
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1963
|
+
if (/\b(?:plan_conflict|policy_conflict|intent_conflict|security_ai_not_ready)\b/.test(message)) {
|
|
1964
|
+
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 });
|
|
1965
|
+
}
|
|
1966
|
+
throw error;
|
|
1967
|
+
}
|
|
1968
|
+
if (!body.job?.jobId) {
|
|
1969
|
+
throw new Error("odla.ai returned an invalid hosted security job");
|
|
1970
|
+
}
|
|
1971
|
+
return body.job;
|
|
1972
|
+
}
|
|
1973
|
+
async function getHostedSecurityJob(options) {
|
|
1974
|
+
const body = await requestHostedSecurityJson(
|
|
1975
|
+
options,
|
|
1976
|
+
hostedJobPath(options.appId, options.jobId),
|
|
1977
|
+
{},
|
|
1978
|
+
"read hosted security job"
|
|
1979
|
+
);
|
|
1980
|
+
if (!body.job?.jobId) throw new Error("odla.ai returned an invalid hosted security job");
|
|
1981
|
+
return body.job;
|
|
1982
|
+
}
|
|
1983
|
+
async function listHostedSecurityJobs(options) {
|
|
1984
|
+
const appId = hostedIdentifier(options.appId, "appId");
|
|
1985
|
+
const env = hostedIdentifier(options.env, "env");
|
|
1986
|
+
const body = await requestHostedSecurityJson(
|
|
1987
|
+
options,
|
|
1988
|
+
`/registry/apps/${encodeURIComponent(appId)}/security/jobs?env=${encodeURIComponent(env)}`,
|
|
1989
|
+
{},
|
|
1990
|
+
"list hosted security jobs"
|
|
1991
|
+
);
|
|
1992
|
+
return Array.isArray(body.jobs) ? body.jobs : [];
|
|
1993
|
+
}
|
|
1994
|
+
async function followHostedSecurityJob(options) {
|
|
1995
|
+
const interval = hostedPollInterval(options.pollIntervalMs);
|
|
1996
|
+
const now = options.now ?? Date.now;
|
|
1997
|
+
const deadline = now() + hostedPollTimeout(options.pollTimeoutMs ?? 60 * 6e4);
|
|
1998
|
+
const wait = options.wait ?? waitForHostedPoll;
|
|
1999
|
+
let prior = "";
|
|
2000
|
+
while (true) {
|
|
2001
|
+
const job = await getHostedSecurityJob(options);
|
|
2002
|
+
const fingerprint = `${job.status}:${job.updatedAt}`;
|
|
2003
|
+
if (fingerprint !== prior) options.onUpdate?.(Object.freeze({ ...job }));
|
|
2004
|
+
prior = fingerprint;
|
|
2005
|
+
if (isTerminalHostedSecurityStatus(job.status)) return job;
|
|
2006
|
+
if (now() >= deadline) {
|
|
2007
|
+
throw new Error(`Hosted security job ${job.jobId} did not finish before the polling deadline`);
|
|
2008
|
+
}
|
|
2009
|
+
await wait(Math.min(interval, Math.max(0, deadline - now())), options.signal);
|
|
2010
|
+
}
|
|
2011
|
+
}
|
|
2012
|
+
async function getHostedSecurityReport(options) {
|
|
2013
|
+
return requestHostedSecurityJson(
|
|
2014
|
+
options,
|
|
2015
|
+
`${hostedJobPath(options.appId, options.jobId)}/report`,
|
|
2016
|
+
{},
|
|
2017
|
+
"read hosted security report"
|
|
2018
|
+
);
|
|
2019
|
+
}
|
|
2020
|
+
function isTerminalHostedSecurityStatus(status) {
|
|
2021
|
+
return status === "completed" || status === "failed" || status === "cancelled";
|
|
2022
|
+
}
|
|
2023
|
+
function hostedJobPath(appIdInput, jobIdInput) {
|
|
2024
|
+
const appId = hostedIdentifier(appIdInput, "appId");
|
|
2025
|
+
const jobId = hostedIdentifier(jobIdInput, "jobId");
|
|
2026
|
+
return `/registry/apps/${encodeURIComponent(appId)}/security/jobs/${encodeURIComponent(jobId)}`;
|
|
2027
|
+
}
|
|
2028
|
+
function securityPlanDigest(value) {
|
|
2029
|
+
if (!/^sha256:[a-f0-9]{64}$/.test(value)) {
|
|
2030
|
+
throw new Error("expected plan digest must be a sha256 digest from security plan");
|
|
2031
|
+
}
|
|
2032
|
+
return value;
|
|
2033
|
+
}
|
|
2034
|
+
function securityExecutionDigest(value) {
|
|
2035
|
+
if (!/^sha256:[a-f0-9]{64}$/.test(value)) {
|
|
2036
|
+
throw new Error("expected execution digest must be a sha256 digest from security intent");
|
|
2037
|
+
}
|
|
2038
|
+
return value;
|
|
2039
|
+
}
|
|
2040
|
+
|
|
1661
2041
|
// src/skill.ts
|
|
1662
2042
|
import { existsSync as existsSync7, lstatSync, mkdirSync as mkdirSync3, readFileSync as readFileSync5, readdirSync, writeFileSync as writeFileSync3 } from "fs";
|
|
1663
2043
|
import { homedir } from "os";
|
|
@@ -1992,9 +2372,6 @@ async function safeText3(res) {
|
|
|
1992
2372
|
}
|
|
1993
2373
|
}
|
|
1994
2374
|
|
|
1995
|
-
// src/cli.ts
|
|
1996
|
-
import { findingsAtOrAbove } from "@odla-ai/security";
|
|
1997
|
-
|
|
1998
2375
|
// src/argv.ts
|
|
1999
2376
|
function parseArgv(argv) {
|
|
2000
2377
|
const positionals = [];
|
|
@@ -2070,6 +2447,65 @@ function addOption(options, name, value) {
|
|
|
2070
2447
|
else options[name] = [String(current), String(value)];
|
|
2071
2448
|
}
|
|
2072
2449
|
|
|
2450
|
+
// src/admin-command.ts
|
|
2451
|
+
async function adminCommand(parsed) {
|
|
2452
|
+
const area = parsed.positionals[1];
|
|
2453
|
+
const action = parsed.positionals[2];
|
|
2454
|
+
const credentialSet = action === "credential" && parsed.positionals[3] === "set";
|
|
2455
|
+
const credentials = action === "credentials";
|
|
2456
|
+
const models = action === "models";
|
|
2457
|
+
const usage = action === "usage";
|
|
2458
|
+
const audit = action === "audit";
|
|
2459
|
+
if (area !== "ai" || action !== "show" && action !== "set" && !credentialSet && !credentials && !models && !usage && !audit) {
|
|
2460
|
+
throw new Error('unknown admin command. Try "odla-ai admin ai show".');
|
|
2461
|
+
}
|
|
2462
|
+
assertArgs(parsed, [
|
|
2463
|
+
"platform",
|
|
2464
|
+
"json",
|
|
2465
|
+
"open",
|
|
2466
|
+
"provider",
|
|
2467
|
+
"model",
|
|
2468
|
+
"enabled",
|
|
2469
|
+
"max-input-bytes",
|
|
2470
|
+
"max-output-tokens",
|
|
2471
|
+
"max-calls-per-run",
|
|
2472
|
+
"from-env",
|
|
2473
|
+
"stdin",
|
|
2474
|
+
"discovery-provider",
|
|
2475
|
+
"discovery-model",
|
|
2476
|
+
"validation-provider",
|
|
2477
|
+
"validation-model",
|
|
2478
|
+
"app-id",
|
|
2479
|
+
"env",
|
|
2480
|
+
"run-id",
|
|
2481
|
+
"limit"
|
|
2482
|
+
], credentialSet ? 5 : action === "set" ? 4 : 3);
|
|
2483
|
+
await adminAi({
|
|
2484
|
+
action: credentialSet ? "credential-set" : credentials ? "credentials" : models ? "models" : usage ? "usage" : audit ? "audit" : action,
|
|
2485
|
+
purpose: action === "set" ? parsed.positionals[3] : void 0,
|
|
2486
|
+
provider: stringOpt(parsed.options.provider),
|
|
2487
|
+
model: stringOpt(parsed.options.model),
|
|
2488
|
+
enabled: boolOpt(parsed.options.enabled),
|
|
2489
|
+
maxInputBytes: numberOpt(parsed.options["max-input-bytes"], "--max-input-bytes"),
|
|
2490
|
+
maxOutputTokens: numberOpt(parsed.options["max-output-tokens"], "--max-output-tokens"),
|
|
2491
|
+
maxCallsPerRun: numberOpt(parsed.options["max-calls-per-run"], "--max-calls-per-run"),
|
|
2492
|
+
platform: stringOpt(parsed.options.platform),
|
|
2493
|
+
json: parsed.options.json === true,
|
|
2494
|
+
open: parsed.options.open === false ? false : parsed.options.open === true ? true : void 0,
|
|
2495
|
+
credentialProvider: credentialSet ? parsed.positionals[4] : void 0,
|
|
2496
|
+
fromEnv: stringOpt(parsed.options["from-env"]),
|
|
2497
|
+
stdin: parsed.options.stdin === true,
|
|
2498
|
+
discoveryProvider: stringOpt(parsed.options["discovery-provider"]),
|
|
2499
|
+
discoveryModel: stringOpt(parsed.options["discovery-model"]),
|
|
2500
|
+
validationProvider: stringOpt(parsed.options["validation-provider"]),
|
|
2501
|
+
validationModel: stringOpt(parsed.options["validation-model"]),
|
|
2502
|
+
appId: stringOpt(parsed.options["app-id"]),
|
|
2503
|
+
env: stringOpt(parsed.options.env),
|
|
2504
|
+
runId: stringOpt(parsed.options["run-id"]),
|
|
2505
|
+
limit: numberOpt(parsed.options.limit, "--limit")
|
|
2506
|
+
});
|
|
2507
|
+
}
|
|
2508
|
+
|
|
2073
2509
|
// src/help.ts
|
|
2074
2510
|
import { readFileSync as readFileSync6 } from "fs";
|
|
2075
2511
|
function cliVersion() {
|
|
@@ -2093,6 +2529,13 @@ Usage:
|
|
|
2093
2529
|
odla-ai admin ai credential set <provider> (--from-env <NAME>|--stdin)
|
|
2094
2530
|
odla-ai admin ai usage [--app-id <id>] [--env <env>] [--run-id <id>] [--limit <1-500>] [--json]
|
|
2095
2531
|
odla-ai admin ai audit [--limit <1-200>] [--json]
|
|
2532
|
+
odla-ai security github connect [--repo owner/name] [--env dev] [--no-open]
|
|
2533
|
+
odla-ai security github disconnect --source <id> [--env dev] [--yes]
|
|
2534
|
+
odla-ai security plan [--env dev] [--json]
|
|
2535
|
+
odla-ai security sources [--env dev] [--json]
|
|
2536
|
+
odla-ai security run --source <id> --plan-digest <sha256:...> --ack-redacted-source [--ref <branch|tag|sha>] [--env dev] [--no-follow]
|
|
2537
|
+
odla-ai security status <job-id> [--follow] [--json]
|
|
2538
|
+
odla-ai security report <job-id> [--json]
|
|
2096
2539
|
odla-ai security run [target] --ack-redacted-source [--env dev] [--profile odla] [--fail-on high]
|
|
2097
2540
|
odla-ai security run [target] --self --ack-redacted-source
|
|
2098
2541
|
odla-ai provision [--config odla.config.mjs] [--dry-run] [--push-secrets] [--rotate-o11y-token] [--write-dev-vars[=path]] [--yes]
|
|
@@ -2107,7 +2550,7 @@ Commands:
|
|
|
2107
2550
|
doctor Validate and summarize the project config without network calls.
|
|
2108
2551
|
capabilities Show what the CLI automates vs agent edits and human checkpoints.
|
|
2109
2552
|
admin Manage platform-funded AI routing/credentials/usage with narrow device grants.
|
|
2110
|
-
security
|
|
2553
|
+
security Connect GitHub sources and run commit-pinned hosted reviews, or scan a local snapshot.
|
|
2111
2554
|
provision Register services, configure them, persist credentials, optionally push secrets.
|
|
2112
2555
|
smoke Verify local credentials, public-config, live schema, and db aggregate.
|
|
2113
2556
|
skill Same installer; --agent accepts all, claude, codex, cursor,
|
|
@@ -2123,11 +2566,467 @@ Safety:
|
|
|
2123
2566
|
preflights Wrangler before any shown-once issuance or destructive rotation.
|
|
2124
2567
|
Provision opens the approval page automatically in interactive terminals;
|
|
2125
2568
|
use --open to force browser launch or --no-open to suppress it.
|
|
2569
|
+
GitHub security uses source-read-only access plus optional metadata-only Checks write: the CLI never asks
|
|
2570
|
+
for a PAT or provider key. GitHub read access is separate from the explicit
|
|
2571
|
+
--ack-redacted-source consent and the exact --plan-digest printed by security
|
|
2572
|
+
plan are required before bounded snippets reach System AI.
|
|
2573
|
+
Run security plan first to inspect the admin-selected providers, models,
|
|
2574
|
+
per-route bounds, credential readiness, retention, no-execution boundary,
|
|
2575
|
+
and digest that binds consent to that exact plan.
|
|
2126
2576
|
`);
|
|
2127
2577
|
}
|
|
2128
2578
|
|
|
2579
|
+
// src/harness-options.ts
|
|
2580
|
+
function harnessList(parsed) {
|
|
2581
|
+
const selected = [
|
|
2582
|
+
...harnessOption(parsed.options.agent, "--agent"),
|
|
2583
|
+
...harnessOption(parsed.options.harness, "--harness")
|
|
2584
|
+
];
|
|
2585
|
+
return selected.length ? selected : ["all"];
|
|
2586
|
+
}
|
|
2587
|
+
function harnessOption(value, flag) {
|
|
2588
|
+
if (value === void 0) return [];
|
|
2589
|
+
if (typeof value === "boolean") throw new Error(`${flag} requires a harness name`);
|
|
2590
|
+
const raw = Array.isArray(value) ? value : [value];
|
|
2591
|
+
const parts = raw.flatMap((item) => item.split(","));
|
|
2592
|
+
if (parts.some((item) => !item.trim())) {
|
|
2593
|
+
throw new Error(`${flag} requires a harness name`);
|
|
2594
|
+
}
|
|
2595
|
+
return parts.map((item) => item.trim());
|
|
2596
|
+
}
|
|
2597
|
+
|
|
2598
|
+
// src/security-command-context.ts
|
|
2599
|
+
import { createInterface } from "readline/promises";
|
|
2600
|
+
async function hostedSecurityContext(parsed, dependencies) {
|
|
2601
|
+
const configPath = stringOpt(parsed.options.config) ?? "odla.config.mjs";
|
|
2602
|
+
const cfg = await loadProjectConfig(configPath);
|
|
2603
|
+
const env = stringOpt(parsed.options.env) ?? (cfg.envs.includes("dev") ? "dev" : cfg.envs[0]);
|
|
2604
|
+
if (!env || !cfg.envs.includes(env)) {
|
|
2605
|
+
throw new Error(`env "${env ?? ""}" is not declared in ${configPath}`);
|
|
2606
|
+
}
|
|
2607
|
+
const platform = platformAudience(stringOpt(parsed.options.platform) ?? cfg.platformUrl);
|
|
2608
|
+
if (platformAudience(cfg.platformUrl) !== platform) {
|
|
2609
|
+
throw new Error("--platform cannot reuse a project developer token from another platform; update odla.config.mjs and authenticate there");
|
|
2610
|
+
}
|
|
2611
|
+
const doFetch = dependencies.fetch ?? fetch;
|
|
2612
|
+
const stdout = dependencies.stdout ?? console;
|
|
2613
|
+
const open = parsed.options.open === false ? false : parsed.options.open === true ? true : void 0;
|
|
2614
|
+
const token = await getDeveloperToken(
|
|
2615
|
+
cfg,
|
|
2616
|
+
{ configPath, open, openApprovalUrl: dependencies.openUrl },
|
|
2617
|
+
doFetch,
|
|
2618
|
+
stdout
|
|
2619
|
+
);
|
|
2620
|
+
return { platform, token, appId: cfg.app.id, env, fetch: doFetch, stdout };
|
|
2621
|
+
}
|
|
2622
|
+
async function interactiveConfirmation(message, dependencies) {
|
|
2623
|
+
if (dependencies.confirm) return dependencies.confirm(message);
|
|
2624
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY) return false;
|
|
2625
|
+
const prompt = createInterface({ input: process.stdin, output: process.stdout });
|
|
2626
|
+
try {
|
|
2627
|
+
const answer = await prompt.question(`${message} [y/N] `);
|
|
2628
|
+
return /^y(?:es)?$/i.test(answer.trim());
|
|
2629
|
+
} finally {
|
|
2630
|
+
prompt.close();
|
|
2631
|
+
}
|
|
2632
|
+
}
|
|
2633
|
+
function requiredSecurityPositional(parsed, index, label) {
|
|
2634
|
+
const value = parsed.positionals[index];
|
|
2635
|
+
if (!value) throw new Error(`${label} is required`);
|
|
2636
|
+
return value;
|
|
2637
|
+
}
|
|
2638
|
+
function securityProfile(value) {
|
|
2639
|
+
if (value === void 0) return void 0;
|
|
2640
|
+
if (value === "odla" || value === "cloudflare-app" || value === "generic") return value;
|
|
2641
|
+
throw new Error("--profile must be odla, cloudflare-app, or generic");
|
|
2642
|
+
}
|
|
2643
|
+
|
|
2644
|
+
// src/security-command-output.ts
|
|
2645
|
+
function printHostedSecurityPlan(out, plan, appId) {
|
|
2646
|
+
out.log(`Hosted security plan for ${appId}/${plan.env}: ${plan.ready ? "ready" : "not ready"}`);
|
|
2647
|
+
out.log(` plan digest: ${plan.planDigest}`);
|
|
2648
|
+
out.log(` consent/report/redaction: ${plan.consentContract} \xB7 ${plan.reportProjection} \xB7 ${plan.redactionContract}`);
|
|
2649
|
+
out.log(` prompt bundle: ${plan.promptBundle}`);
|
|
2650
|
+
printHostedSecurityPlanRoute(out, "discovery", plan.routes.discovery);
|
|
2651
|
+
printHostedSecurityPlanRoute(out, "validation", plan.routes.validation);
|
|
2652
|
+
out.log(` independent validation: ${plan.independent ? "yes" : "no"}`);
|
|
2653
|
+
out.log(" source disclosure: bounded best-effort credential-pattern-redacted snippets may be sent through odla.ai to the selected providers");
|
|
2654
|
+
out.log(` retained report: model-derived prose and repository-relative paths for up to ${plan.reportRetentionDays} days; treat it as sensitive`);
|
|
2655
|
+
out.log(" target execution: disabled");
|
|
2656
|
+
out.log(` to approve this exact plan, run security run --source <id> --plan-digest ${plan.planDigest} --ack-redacted-source`);
|
|
2657
|
+
}
|
|
2658
|
+
function printHostedSecurityIntent(out, intent) {
|
|
2659
|
+
out.log(`Hosted security execution intent for ${intent.appId}/${intent.env}:`);
|
|
2660
|
+
out.log(` execution digest: ${intent.executionDigest}`);
|
|
2661
|
+
out.log(` contract: ${intent.executionContract}`);
|
|
2662
|
+
out.log(` source: ${intent.repository} (${intent.sourceId})`);
|
|
2663
|
+
out.log(` ref: ${intent.requestedRef ?? `default branch (${intent.defaultBranch})`}`);
|
|
2664
|
+
out.log(` profile: ${intent.profile}`);
|
|
2665
|
+
out.log(` disclosure: ${intent.sourceDisclosure} \xB7 plan ${intent.planDigest}`);
|
|
2666
|
+
}
|
|
2667
|
+
function assertHostedSecurityPlanReady(plan) {
|
|
2668
|
+
const reasons = [];
|
|
2669
|
+
for (const [label, route] of Object.entries(plan.routes)) {
|
|
2670
|
+
if (!route.enabled) reasons.push(`${label} is disabled`);
|
|
2671
|
+
if (!route.credentialReady) reasons.push(`${label} provider credential is unavailable`);
|
|
2672
|
+
}
|
|
2673
|
+
if (!plan.independent) reasons.push("discovery and validation are not independently routed");
|
|
2674
|
+
if (plan.ready && reasons.length === 0) return;
|
|
2675
|
+
if (!plan.ready && reasons.length === 0) reasons.push("the platform marked the plan unavailable");
|
|
2676
|
+
throw new Error(`hosted security is not ready${reasons.length ? `: ${reasons.join("; ")}` : ""}. Ask a platform admin to update System AI security policy or credentials`);
|
|
2677
|
+
}
|
|
2678
|
+
function printHostedJob(out, job, platform, appId) {
|
|
2679
|
+
out.log(`security job ${job.jobId}: ${job.status}`);
|
|
2680
|
+
out.log(` source: ${job.repository} ${job.requestedRef ?? "default"} -> ${job.commitSha ?? "resolving"}`);
|
|
2681
|
+
if (job.routes) {
|
|
2682
|
+
out.log(` discovery: ${routeLabel(job.routes.discovery)}`);
|
|
2683
|
+
out.log(` validation: ${routeLabel(job.routes.validation)}`);
|
|
2684
|
+
} else {
|
|
2685
|
+
out.log(" routes: platform System AI policy (assigned when analysis starts)");
|
|
2686
|
+
}
|
|
2687
|
+
out.log(` disclosure: ${job.sourceDisclosure} snippets \xB7 metadata retained up to ${job.retentionDays} days`);
|
|
2688
|
+
out.log(` consent: plan ${job.planDigest} \xB7 execution ${job.executionDigest} (${job.executionContract})`);
|
|
2689
|
+
if (job.coverageStatus || job.coverage) printHostedCoverage(out, job);
|
|
2690
|
+
if (job.counts) {
|
|
2691
|
+
out.log(` findings: confirmed=${job.counts.confirmed} needs_reproduction=${job.counts.needsReproduction} candidates=${job.counts.candidates}`);
|
|
2692
|
+
}
|
|
2693
|
+
if (job.errorCode) out.log(` failure: ${job.errorCode}`);
|
|
2694
|
+
const url = new URL("/studio", platform);
|
|
2695
|
+
url.searchParams.set("app", appId);
|
|
2696
|
+
url.searchParams.set("env", job.env);
|
|
2697
|
+
url.searchParams.set("tab", "security");
|
|
2698
|
+
url.searchParams.set("job", job.jobId);
|
|
2699
|
+
out.log(` Studio: ${url.toString()}`);
|
|
2700
|
+
}
|
|
2701
|
+
function printHostedReport(out, report) {
|
|
2702
|
+
out.log(`security report ${report.jobId}: ${report.repository}@${report.revision}`);
|
|
2703
|
+
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}`);
|
|
2704
|
+
out.log(` findings: confirmed=${report.metrics.confirmed} needs_reproduction=${report.metrics.needsReproduction} candidates=${report.metrics.candidates} rejected=${report.metrics.rejected}`);
|
|
2705
|
+
out.log(` discovery: ${report.provenance.discovery?.provider ?? "unknown"}/${report.provenance.discovery?.model ?? "unknown"}`);
|
|
2706
|
+
out.log(` validation: ${report.provenance.validation?.provider ?? "unknown"}/${report.provenance.validation?.model ?? "unknown"} independent=${String(report.provenance.independentValidation)}`);
|
|
2707
|
+
for (const finding of report.findings) {
|
|
2708
|
+
const location = finding.locations[0];
|
|
2709
|
+
out.log(` [${finding.severity}] ${finding.title}${location ? ` (${location.path}:${location.line})` : ""} \xB7 ${finding.disposition}`);
|
|
2710
|
+
}
|
|
2711
|
+
for (const limitation of report.limitations) out.log(` limitation: ${limitation}`);
|
|
2712
|
+
}
|
|
2713
|
+
function enforceHostedReportGate(report, parsed, out, emitSuccess) {
|
|
2714
|
+
const failOn = hostedSeverity(stringOpt(parsed.options["fail-on"]) ?? "high", "--fail-on");
|
|
2715
|
+
const candidateValue = parsed.options["fail-on-candidates"];
|
|
2716
|
+
const failOnCandidates = candidateValue === false ? void 0 : hostedSeverity(stringOpt(candidateValue) ?? "critical", "--fail-on-candidates");
|
|
2717
|
+
const atOrAbove = (severity, threshold) => HOSTED_SEVERITIES.indexOf(severity) >= HOSTED_SEVERITIES.indexOf(threshold);
|
|
2718
|
+
const confirmed = report.findings.filter((finding) => finding.disposition === "confirmed" && atOrAbove(finding.severity, failOn));
|
|
2719
|
+
const leads = failOnCandidates ? report.findings.filter((finding) => finding.disposition !== "confirmed" && atOrAbove(finding.severity, failOnCandidates)) : [];
|
|
2720
|
+
const incomplete = report.coverageStatus !== "complete" && parsed.options["allow-incomplete"] !== true;
|
|
2721
|
+
if (confirmed.length || leads.length || incomplete) {
|
|
2722
|
+
throw new Error(`hosted security gate failed: ${confirmed.length} confirmed >= ${failOn}; ${leads.length} leads >= ${failOnCandidates ?? "disabled"}${incomplete ? `; coverage ${report.coverageStatus}` : ""}`);
|
|
2723
|
+
}
|
|
2724
|
+
if (emitSuccess) {
|
|
2725
|
+
out.log(`security gate passed: 0 confirmed >= ${failOn}; 0 leads >= ${failOnCandidates ?? "disabled"}; coverage ${report.coverageStatus}. This is not proof that the application is secure.`);
|
|
2726
|
+
}
|
|
2727
|
+
}
|
|
2728
|
+
function printHostedSecurityPlanRoute(out, label, route) {
|
|
2729
|
+
const readiness = route.enabled && route.credentialReady ? "ready" : [
|
|
2730
|
+
route.enabled ? void 0 : "disabled",
|
|
2731
|
+
route.credentialReady ? void 0 : "credential unavailable"
|
|
2732
|
+
].filter(Boolean).join(", ");
|
|
2733
|
+
out.log(` ${label}: ${route.provider}/${route.model} \xB7 policy v${route.policyVersion} \xB7 ${readiness}`);
|
|
2734
|
+
out.log(` bounds: ${route.maxCallsPerRun} calls/run \xB7 ${route.maxInputBytes} input bytes/call \xB7 ${route.maxOutputTokens} output tokens/call`);
|
|
2735
|
+
}
|
|
2736
|
+
function printHostedCoverage(out, job) {
|
|
2737
|
+
const coverage = job.coverage;
|
|
2738
|
+
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}` : ""}`);
|
|
2739
|
+
}
|
|
2740
|
+
function routeLabel(route) {
|
|
2741
|
+
return `${route.provider}/${route.model}${route.policyVersion ? ` policy v${route.policyVersion}` : ""}`;
|
|
2742
|
+
}
|
|
2743
|
+
var HOSTED_SEVERITIES = ["informational", "low", "medium", "high", "critical"];
|
|
2744
|
+
function hostedSeverity(value, flag) {
|
|
2745
|
+
if (HOSTED_SEVERITIES.includes(value)) {
|
|
2746
|
+
return value;
|
|
2747
|
+
}
|
|
2748
|
+
throw new Error(`${flag} must be informational, low, medium, high, or critical`);
|
|
2749
|
+
}
|
|
2750
|
+
|
|
2751
|
+
// src/security-run-command.ts
|
|
2752
|
+
import { findingsAtOrAbove } from "@odla-ai/security";
|
|
2753
|
+
async function runSourceSecurityCommand(parsed, dependencies, sourceId) {
|
|
2754
|
+
assertArgs(parsed, [
|
|
2755
|
+
"config",
|
|
2756
|
+
"env",
|
|
2757
|
+
"profile",
|
|
2758
|
+
"platform",
|
|
2759
|
+
"source",
|
|
2760
|
+
"ref",
|
|
2761
|
+
"follow",
|
|
2762
|
+
"open",
|
|
2763
|
+
"json",
|
|
2764
|
+
"ack-redacted-source",
|
|
2765
|
+
"plan-digest",
|
|
2766
|
+
"fail-on",
|
|
2767
|
+
"fail-on-candidates",
|
|
2768
|
+
"allow-incomplete"
|
|
2769
|
+
], 2);
|
|
2770
|
+
const follow = parsed.options.follow !== false;
|
|
2771
|
+
if (!follow && (parsed.options["fail-on"] !== void 0 || parsed.options["fail-on-candidates"] !== void 0 || parsed.options["allow-incomplete"] !== void 0)) {
|
|
2772
|
+
throw new Error("hosted security gate options require following the job; remove --no-follow");
|
|
2773
|
+
}
|
|
2774
|
+
const acknowledgedDigest = requiredString(parsed.options["plan-digest"], "--plan-digest");
|
|
2775
|
+
const context = await hostedSecurityContext(parsed, dependencies);
|
|
2776
|
+
const plan = await getHostedSecurityPlan(context);
|
|
2777
|
+
if (parsed.options.json !== true) printHostedSecurityPlan(context.stdout, plan, context.appId);
|
|
2778
|
+
assertHostedSecurityPlanReady(plan);
|
|
2779
|
+
if (acknowledgedDigest !== plan.planDigest) {
|
|
2780
|
+
throw new Error(`--plan-digest does not match the current hosted security plan (${plan.planDigest}); review and explicitly acknowledge the current digest`);
|
|
2781
|
+
}
|
|
2782
|
+
const requestedRef = stringOpt(parsed.options.ref);
|
|
2783
|
+
const requestedProfile = securityProfile(stringOpt(parsed.options.profile));
|
|
2784
|
+
const preview = await getHostedSecurityIntent({
|
|
2785
|
+
...context,
|
|
2786
|
+
sourceId,
|
|
2787
|
+
ref: requestedRef,
|
|
2788
|
+
profile: requestedProfile
|
|
2789
|
+
});
|
|
2790
|
+
if (parsed.options.json !== true) printHostedSecurityIntent(context.stdout, preview.intent);
|
|
2791
|
+
if (preview.plan.planDigest !== plan.planDigest || preview.intent.planDigest !== plan.planDigest) {
|
|
2792
|
+
throw new Error(`hosted security plan changed while previewing execution (${preview.plan.planDigest}); review and explicitly acknowledge the current plan digest`);
|
|
2793
|
+
}
|
|
2794
|
+
const job = await startHostedSecurityJob({
|
|
2795
|
+
...context,
|
|
2796
|
+
sourceId,
|
|
2797
|
+
ref: requestedRef,
|
|
2798
|
+
profile: requestedProfile,
|
|
2799
|
+
clientRequestId: crypto.randomUUID(),
|
|
2800
|
+
sourceDisclosureAck: parsed.options["ack-redacted-source"] === true ? "redacted" : void 0,
|
|
2801
|
+
expectedPlanDigest: plan.planDigest,
|
|
2802
|
+
expectedExecutionDigest: preview.intent.executionDigest,
|
|
2803
|
+
expectedPolicyVersions: {
|
|
2804
|
+
discovery: plan.routes.discovery.policyVersion,
|
|
2805
|
+
validation: plan.routes.validation.policyVersion
|
|
2806
|
+
}
|
|
2807
|
+
});
|
|
2808
|
+
const result = follow ? await followHostedSecurityJob({
|
|
2809
|
+
...context,
|
|
2810
|
+
jobId: job.jobId,
|
|
2811
|
+
wait: dependencies.pollWait,
|
|
2812
|
+
onUpdate: parsed.options.json === true ? void 0 : (value) => printHostedJob(context.stdout, value, context.platform, context.appId)
|
|
2813
|
+
}) : job;
|
|
2814
|
+
if (!follow) {
|
|
2815
|
+
if (parsed.options.json === true) {
|
|
2816
|
+
context.stdout.log(JSON.stringify({ plan, intent: preview.intent, job: result }, null, 2));
|
|
2817
|
+
} else {
|
|
2818
|
+
printHostedJob(context.stdout, result, context.platform, context.appId);
|
|
2819
|
+
}
|
|
2820
|
+
return;
|
|
2821
|
+
}
|
|
2822
|
+
if (result.status !== "completed") {
|
|
2823
|
+
if (parsed.options.json === true) {
|
|
2824
|
+
context.stdout.log(JSON.stringify({ plan, intent: preview.intent, job: result }, null, 2));
|
|
2825
|
+
}
|
|
2826
|
+
throw new Error(`hosted security job ${result.jobId} ended ${result.status}${result.errorCode ? `: ${result.errorCode}` : ""}`);
|
|
2827
|
+
}
|
|
2828
|
+
const report = await getHostedSecurityReport({ ...context, jobId: result.jobId });
|
|
2829
|
+
if (parsed.options.json === true) {
|
|
2830
|
+
context.stdout.log(JSON.stringify({ plan, intent: preview.intent, job: result, report }, null, 2));
|
|
2831
|
+
} else {
|
|
2832
|
+
printHostedReport(context.stdout, report);
|
|
2833
|
+
}
|
|
2834
|
+
enforceHostedReportGate(report, parsed, context.stdout, parsed.options.json !== true);
|
|
2835
|
+
}
|
|
2836
|
+
async function runLocalSecurityCommand(parsed, dependencies) {
|
|
2837
|
+
if (parsed.options.source === true) {
|
|
2838
|
+
throw new Error("--source requires a source id; run security sources first");
|
|
2839
|
+
}
|
|
2840
|
+
assertArgs(parsed, [
|
|
2841
|
+
"config",
|
|
2842
|
+
"env",
|
|
2843
|
+
"out",
|
|
2844
|
+
"profile",
|
|
2845
|
+
"max-hunt-tasks",
|
|
2846
|
+
"run-id",
|
|
2847
|
+
"platform",
|
|
2848
|
+
"self",
|
|
2849
|
+
"ack-redacted-source",
|
|
2850
|
+
"open",
|
|
2851
|
+
"fail-on",
|
|
2852
|
+
"fail-on-candidates",
|
|
2853
|
+
"allow-incomplete"
|
|
2854
|
+
], 3);
|
|
2855
|
+
const configPath = stringOpt(parsed.options.config) ?? "odla.config.mjs";
|
|
2856
|
+
const selfAudit = parsed.options.self === true;
|
|
2857
|
+
const open = parsed.options.open === false ? false : parsed.options.open === true ? true : void 0;
|
|
2858
|
+
const platform = stringOpt(parsed.options.platform);
|
|
2859
|
+
const doFetch = dependencies.fetch ?? fetch;
|
|
2860
|
+
const out = dependencies.stdout ?? console;
|
|
2861
|
+
const result = await runHostedSecurity({
|
|
2862
|
+
configPath,
|
|
2863
|
+
selfAudit,
|
|
2864
|
+
target: parsed.positionals[2],
|
|
2865
|
+
out: stringOpt(parsed.options.out),
|
|
2866
|
+
env: stringOpt(parsed.options.env),
|
|
2867
|
+
profile: securityProfile(stringOpt(parsed.options.profile)),
|
|
2868
|
+
maxHuntTasks: numberOpt(parsed.options["max-hunt-tasks"], "--max-hunt-tasks"),
|
|
2869
|
+
runId: stringOpt(parsed.options["run-id"]),
|
|
2870
|
+
platform,
|
|
2871
|
+
sourceDisclosureAck: parsed.options["ack-redacted-source"] === true ? "redacted" : void 0,
|
|
2872
|
+
fetch: doFetch,
|
|
2873
|
+
stdout: out,
|
|
2874
|
+
getToken: async (request) => {
|
|
2875
|
+
if (request.scope === "platform:security:self") {
|
|
2876
|
+
return getScopedPlatformToken({
|
|
2877
|
+
platform: request.platform,
|
|
2878
|
+
scope: request.scope,
|
|
2879
|
+
open,
|
|
2880
|
+
fetch: doFetch,
|
|
2881
|
+
stdout: out,
|
|
2882
|
+
openApprovalUrl: dependencies.openUrl
|
|
2883
|
+
});
|
|
2884
|
+
}
|
|
2885
|
+
const cfg = await loadProjectConfig(configPath);
|
|
2886
|
+
if (platformAudience(cfg.platformUrl) !== platformAudience(request.platform)) {
|
|
2887
|
+
throw new Error("--platform cannot reuse a project developer token from another platform; update odla.config.mjs and authenticate there");
|
|
2888
|
+
}
|
|
2889
|
+
return getDeveloperToken(
|
|
2890
|
+
cfg,
|
|
2891
|
+
{ configPath, open, openApprovalUrl: dependencies.openUrl },
|
|
2892
|
+
doFetch,
|
|
2893
|
+
out
|
|
2894
|
+
);
|
|
2895
|
+
}
|
|
2896
|
+
});
|
|
2897
|
+
enforceLocalGate(result.report, parsed);
|
|
2898
|
+
}
|
|
2899
|
+
function enforceLocalGate(report, parsed) {
|
|
2900
|
+
const failOn = severityOpt(stringOpt(parsed.options["fail-on"]) ?? "high", "--fail-on");
|
|
2901
|
+
const candidateValue = parsed.options["fail-on-candidates"];
|
|
2902
|
+
const failOnCandidates = candidateValue === false ? void 0 : severityOpt(stringOpt(candidateValue) ?? "critical", "--fail-on-candidates");
|
|
2903
|
+
const confirmed = findingsAtOrAbove(report, failOn);
|
|
2904
|
+
const leads = failOnCandidates ? findingsAtOrAbove(report, failOnCandidates, true).filter((finding) => finding.disposition !== "confirmed") : [];
|
|
2905
|
+
const incomplete = report.coverageStatus === "incomplete" && parsed.options["allow-incomplete"] !== true;
|
|
2906
|
+
if (confirmed.length || leads.length || incomplete) {
|
|
2907
|
+
throw new Error(`hosted security gate failed: ${confirmed.length} confirmed >= ${failOn}; ${leads.length} leads >= ${failOnCandidates ?? "disabled"}${incomplete ? "; coverage incomplete" : ""}`);
|
|
2908
|
+
}
|
|
2909
|
+
}
|
|
2910
|
+
function severityOpt(value, flag) {
|
|
2911
|
+
if (["informational", "low", "medium", "high", "critical"].includes(value)) {
|
|
2912
|
+
return value;
|
|
2913
|
+
}
|
|
2914
|
+
throw new Error(`${flag} must be informational, low, medium, high, or critical`);
|
|
2915
|
+
}
|
|
2916
|
+
|
|
2917
|
+
// src/security-command.ts
|
|
2918
|
+
async function securityCommand(parsed, dependencies) {
|
|
2919
|
+
const sub = parsed.positionals[1];
|
|
2920
|
+
if (sub === "github") {
|
|
2921
|
+
await githubSecurityCommand(parsed, dependencies);
|
|
2922
|
+
return;
|
|
2923
|
+
}
|
|
2924
|
+
if (sub === "plan") {
|
|
2925
|
+
assertArgs(parsed, ["config", "env", "platform", "open", "json"], 2);
|
|
2926
|
+
const context = await hostedSecurityContext(parsed, dependencies);
|
|
2927
|
+
const plan = await getHostedSecurityPlan(context);
|
|
2928
|
+
if (parsed.options.json === true) context.stdout.log(JSON.stringify(plan, null, 2));
|
|
2929
|
+
else printHostedSecurityPlan(context.stdout, plan, context.appId);
|
|
2930
|
+
return;
|
|
2931
|
+
}
|
|
2932
|
+
if (sub === "sources") {
|
|
2933
|
+
await listSecuritySources(parsed, dependencies);
|
|
2934
|
+
return;
|
|
2935
|
+
}
|
|
2936
|
+
if (sub === "status") {
|
|
2937
|
+
await securityStatus(parsed, dependencies);
|
|
2938
|
+
return;
|
|
2939
|
+
}
|
|
2940
|
+
if (sub === "report") {
|
|
2941
|
+
assertArgs(parsed, ["config", "env", "platform", "open", "json"], 3);
|
|
2942
|
+
const jobId = requiredSecurityPositional(parsed, 2, "job id");
|
|
2943
|
+
const context = await hostedSecurityContext(parsed, dependencies);
|
|
2944
|
+
const report = await getHostedSecurityReport({ ...context, jobId });
|
|
2945
|
+
if (parsed.options.json === true) context.stdout.log(JSON.stringify(report, null, 2));
|
|
2946
|
+
else printHostedReport(context.stdout, report);
|
|
2947
|
+
return;
|
|
2948
|
+
}
|
|
2949
|
+
if (sub !== "run") {
|
|
2950
|
+
throw new Error('unknown security command. Try "odla-ai security plan", "security sources", or "security run".');
|
|
2951
|
+
}
|
|
2952
|
+
const sourceId = stringOpt(parsed.options.source);
|
|
2953
|
+
if (sourceId) await runSourceSecurityCommand(parsed, dependencies, sourceId);
|
|
2954
|
+
else await runLocalSecurityCommand(parsed, dependencies);
|
|
2955
|
+
}
|
|
2956
|
+
async function githubSecurityCommand(parsed, dependencies) {
|
|
2957
|
+
const action = parsed.positionals[2];
|
|
2958
|
+
if (action === "disconnect") {
|
|
2959
|
+
assertArgs(parsed, ["config", "env", "platform", "source", "open", "yes"], 3);
|
|
2960
|
+
const context2 = await hostedSecurityContext(parsed, dependencies);
|
|
2961
|
+
const sourceId = requiredString(parsed.options.source, "--source");
|
|
2962
|
+
const confirmed = parsed.options.yes === true || await interactiveConfirmation(
|
|
2963
|
+
`Disconnect GitHub security source ${sourceId} from ${context2.appId}/${context2.env}?`,
|
|
2964
|
+
dependencies
|
|
2965
|
+
);
|
|
2966
|
+
if (!confirmed) {
|
|
2967
|
+
throw new Error("GitHub source disconnect cancelled; pass --yes in a non-interactive shell");
|
|
2968
|
+
}
|
|
2969
|
+
await disconnectGitHubSecuritySource({ ...context2, sourceId });
|
|
2970
|
+
context2.stdout.log(`github: disconnected ${sourceId} from ${context2.appId}/${context2.env}`);
|
|
2971
|
+
return;
|
|
2972
|
+
}
|
|
2973
|
+
if (action !== "connect") {
|
|
2974
|
+
throw new Error('unknown security github command. Try "odla-ai security github connect".');
|
|
2975
|
+
}
|
|
2976
|
+
assertArgs(parsed, ["config", "env", "platform", "repo", "open"], 3);
|
|
2977
|
+
const context = await hostedSecurityContext(parsed, dependencies);
|
|
2978
|
+
const repository = stringOpt(parsed.options.repo) ?? await inferGitHubRepository(process.cwd(), dependencies.readGitOrigin);
|
|
2979
|
+
const connection = await connectGitHubSecuritySource({
|
|
2980
|
+
...context,
|
|
2981
|
+
repository,
|
|
2982
|
+
open: parsed.options.open !== false,
|
|
2983
|
+
openInstallUrl: dependencies.openUrl ?? openUrl,
|
|
2984
|
+
wait: dependencies.pollWait,
|
|
2985
|
+
stdout: context.stdout
|
|
2986
|
+
});
|
|
2987
|
+
context.stdout.log(`github: connected ${connection.repository ?? repository} (${connection.sourceId ?? "source pending"})`);
|
|
2988
|
+
context.stdout.log("github: odla.ai stores the installation; no PAT or GitHub token is written locally");
|
|
2989
|
+
}
|
|
2990
|
+
async function listSecuritySources(parsed, dependencies) {
|
|
2991
|
+
assertArgs(parsed, ["config", "env", "platform", "open", "json"], 2);
|
|
2992
|
+
const context = await hostedSecurityContext(parsed, dependencies);
|
|
2993
|
+
const [plan, sources] = await Promise.all([
|
|
2994
|
+
getHostedSecurityPlan(context),
|
|
2995
|
+
listGitHubSecuritySources(context)
|
|
2996
|
+
]);
|
|
2997
|
+
if (parsed.options.json === true) {
|
|
2998
|
+
context.stdout.log(JSON.stringify({ plan, sources }, null, 2));
|
|
2999
|
+
return;
|
|
3000
|
+
}
|
|
3001
|
+
printHostedSecurityPlan(context.stdout, plan, context.appId);
|
|
3002
|
+
if (!sources.length) {
|
|
3003
|
+
context.stdout.log(`No GitHub security sources connected for ${context.appId}/${context.env}.`);
|
|
3004
|
+
return;
|
|
3005
|
+
}
|
|
3006
|
+
context.stdout.log(`GitHub security sources for ${context.appId}/${context.env}
|
|
3007
|
+
source repository default ref status`);
|
|
3008
|
+
for (const source of sources) {
|
|
3009
|
+
context.stdout.log(`${source.sourceId} ${source.repository} ${source.defaultBranch} ${source.status}`);
|
|
3010
|
+
}
|
|
3011
|
+
}
|
|
3012
|
+
async function securityStatus(parsed, dependencies) {
|
|
3013
|
+
assertArgs(parsed, ["config", "env", "platform", "open", "json", "follow"], 3);
|
|
3014
|
+
const jobId = requiredSecurityPositional(parsed, 2, "job id");
|
|
3015
|
+
const context = await hostedSecurityContext(parsed, dependencies);
|
|
3016
|
+
const job = parsed.options.follow === true ? await followHostedSecurityJob({
|
|
3017
|
+
...context,
|
|
3018
|
+
jobId,
|
|
3019
|
+
wait: dependencies.pollWait,
|
|
3020
|
+
onUpdate: parsed.options.json === true ? void 0 : (value) => printHostedJob(context.stdout, value, context.platform, context.appId)
|
|
3021
|
+
}) : await getHostedSecurityJob({ ...context, jobId });
|
|
3022
|
+
if (parsed.options.json === true) context.stdout.log(JSON.stringify(job, null, 2));
|
|
3023
|
+
else if (parsed.options.follow !== true) {
|
|
3024
|
+
printHostedJob(context.stdout, job, context.platform, context.appId);
|
|
3025
|
+
}
|
|
3026
|
+
}
|
|
3027
|
+
|
|
2129
3028
|
// src/cli.ts
|
|
2130
|
-
async function runCli(argv = process.argv.slice(2)) {
|
|
3029
|
+
async function runCli(argv = process.argv.slice(2), dependencies = {}) {
|
|
2131
3030
|
const parsed = parseArgv(argv);
|
|
2132
3031
|
const command = parsed.positionals[0] ?? "help";
|
|
2133
3032
|
if (command === "version" || command === "-v" || parsed.options.version === true) {
|
|
@@ -2141,7 +3040,15 @@ async function runCli(argv = process.argv.slice(2)) {
|
|
|
2141
3040
|
return;
|
|
2142
3041
|
}
|
|
2143
3042
|
if (command === "init") {
|
|
2144
|
-
assertArgs(parsed, [
|
|
3043
|
+
assertArgs(parsed, [
|
|
3044
|
+
"app-id",
|
|
3045
|
+
"name",
|
|
3046
|
+
"config",
|
|
3047
|
+
"env",
|
|
3048
|
+
"services",
|
|
3049
|
+
"ai-provider",
|
|
3050
|
+
"force"
|
|
3051
|
+
], 1);
|
|
2145
3052
|
initProject({
|
|
2146
3053
|
appId: requiredString(parsed.options["app-id"], "--app-id"),
|
|
2147
3054
|
name: requiredString(parsed.options.name, "--name"),
|
|
@@ -2164,149 +3071,15 @@ async function runCli(argv = process.argv.slice(2)) {
|
|
|
2164
3071
|
return;
|
|
2165
3072
|
}
|
|
2166
3073
|
if (command === "admin") {
|
|
2167
|
-
|
|
2168
|
-
const action = parsed.positionals[2];
|
|
2169
|
-
const credentialSet = action === "credential" && parsed.positionals[3] === "set";
|
|
2170
|
-
const credentials = action === "credentials";
|
|
2171
|
-
const models = action === "models";
|
|
2172
|
-
const usage = action === "usage";
|
|
2173
|
-
const audit = action === "audit";
|
|
2174
|
-
if (area !== "ai" || action !== "show" && action !== "set" && !credentialSet && !credentials && !models && !usage && !audit) {
|
|
2175
|
-
throw new Error('unknown admin command. Try "odla-ai admin ai show".');
|
|
2176
|
-
}
|
|
2177
|
-
assertArgs(parsed, [
|
|
2178
|
-
"platform",
|
|
2179
|
-
"json",
|
|
2180
|
-
"open",
|
|
2181
|
-
"provider",
|
|
2182
|
-
"model",
|
|
2183
|
-
"enabled",
|
|
2184
|
-
"max-input-bytes",
|
|
2185
|
-
"max-output-tokens",
|
|
2186
|
-
"max-calls-per-run",
|
|
2187
|
-
"from-env",
|
|
2188
|
-
"stdin",
|
|
2189
|
-
"discovery-provider",
|
|
2190
|
-
"discovery-model",
|
|
2191
|
-
"validation-provider",
|
|
2192
|
-
"validation-model",
|
|
2193
|
-
"app-id",
|
|
2194
|
-
"env",
|
|
2195
|
-
"run-id",
|
|
2196
|
-
"limit"
|
|
2197
|
-
], credentialSet ? 5 : action === "set" ? 4 : 3);
|
|
2198
|
-
await adminAi({
|
|
2199
|
-
action: credentialSet ? "credential-set" : credentials ? "credentials" : models ? "models" : usage ? "usage" : audit ? "audit" : action,
|
|
2200
|
-
purpose: action === "set" ? parsed.positionals[3] : void 0,
|
|
2201
|
-
provider: stringOpt(parsed.options.provider),
|
|
2202
|
-
model: stringOpt(parsed.options.model),
|
|
2203
|
-
enabled: boolOpt(parsed.options.enabled),
|
|
2204
|
-
maxInputBytes: numberOpt(parsed.options["max-input-bytes"], "--max-input-bytes"),
|
|
2205
|
-
maxOutputTokens: numberOpt(parsed.options["max-output-tokens"], "--max-output-tokens"),
|
|
2206
|
-
maxCallsPerRun: numberOpt(parsed.options["max-calls-per-run"], "--max-calls-per-run"),
|
|
2207
|
-
platform: stringOpt(parsed.options.platform),
|
|
2208
|
-
json: parsed.options.json === true,
|
|
2209
|
-
open: parsed.options.open === false ? false : parsed.options.open === true ? true : void 0,
|
|
2210
|
-
credentialProvider: credentialSet ? parsed.positionals[4] : void 0,
|
|
2211
|
-
fromEnv: stringOpt(parsed.options["from-env"]),
|
|
2212
|
-
stdin: parsed.options.stdin === true,
|
|
2213
|
-
discoveryProvider: stringOpt(parsed.options["discovery-provider"]),
|
|
2214
|
-
discoveryModel: stringOpt(parsed.options["discovery-model"]),
|
|
2215
|
-
validationProvider: stringOpt(parsed.options["validation-provider"]),
|
|
2216
|
-
validationModel: stringOpt(parsed.options["validation-model"]),
|
|
2217
|
-
appId: stringOpt(parsed.options["app-id"]),
|
|
2218
|
-
env: stringOpt(parsed.options.env),
|
|
2219
|
-
runId: stringOpt(parsed.options["run-id"]),
|
|
2220
|
-
limit: numberOpt(parsed.options.limit, "--limit")
|
|
2221
|
-
});
|
|
3074
|
+
await adminCommand(parsed);
|
|
2222
3075
|
return;
|
|
2223
3076
|
}
|
|
2224
3077
|
if (command === "security") {
|
|
2225
|
-
|
|
2226
|
-
if (sub !== "run") throw new Error('unknown security command. Try "odla-ai security run".');
|
|
2227
|
-
assertArgs(parsed, [
|
|
2228
|
-
"config",
|
|
2229
|
-
"env",
|
|
2230
|
-
"out",
|
|
2231
|
-
"profile",
|
|
2232
|
-
"max-hunt-tasks",
|
|
2233
|
-
"run-id",
|
|
2234
|
-
"platform",
|
|
2235
|
-
"self",
|
|
2236
|
-
"ack-redacted-source",
|
|
2237
|
-
"open",
|
|
2238
|
-
"fail-on",
|
|
2239
|
-
"fail-on-candidates",
|
|
2240
|
-
"allow-incomplete"
|
|
2241
|
-
], 3);
|
|
2242
|
-
const configPath = stringOpt(parsed.options.config) ?? "odla.config.mjs";
|
|
2243
|
-
const selfAudit = parsed.options.self === true;
|
|
2244
|
-
const open = parsed.options.open === false ? false : parsed.options.open === true ? true : void 0;
|
|
2245
|
-
const platform = stringOpt(parsed.options.platform);
|
|
2246
|
-
const result = await runHostedSecurity({
|
|
2247
|
-
configPath,
|
|
2248
|
-
selfAudit,
|
|
2249
|
-
target: parsed.positionals[2],
|
|
2250
|
-
out: stringOpt(parsed.options.out),
|
|
2251
|
-
env: stringOpt(parsed.options.env),
|
|
2252
|
-
profile: securityProfile(stringOpt(parsed.options.profile)),
|
|
2253
|
-
maxHuntTasks: numberOpt(parsed.options["max-hunt-tasks"], "--max-hunt-tasks"),
|
|
2254
|
-
runId: stringOpt(parsed.options["run-id"]),
|
|
2255
|
-
platform,
|
|
2256
|
-
sourceDisclosureAck: parsed.options["ack-redacted-source"] === true ? "redacted" : void 0,
|
|
2257
|
-
getToken: async (request) => {
|
|
2258
|
-
if (request.scope === "platform:security:self") {
|
|
2259
|
-
return getScopedPlatformToken({ platform: request.platform, scope: request.scope, open });
|
|
2260
|
-
}
|
|
2261
|
-
const cfg = await loadProjectConfig(configPath);
|
|
2262
|
-
if (platformAudience(cfg.platformUrl) !== platformAudience(request.platform)) {
|
|
2263
|
-
throw new Error("--platform cannot reuse a project developer token from another platform; update odla.config.mjs and authenticate there");
|
|
2264
|
-
}
|
|
2265
|
-
return getDeveloperToken(cfg, { configPath, open }, fetch, console);
|
|
2266
|
-
}
|
|
2267
|
-
});
|
|
2268
|
-
const failOn = severityOpt(stringOpt(parsed.options["fail-on"]) ?? "high", "--fail-on");
|
|
2269
|
-
const candidateValue = parsed.options["fail-on-candidates"];
|
|
2270
|
-
const failOnCandidates = candidateValue === false ? void 0 : severityOpt(stringOpt(candidateValue) ?? "critical", "--fail-on-candidates");
|
|
2271
|
-
const confirmed = findingsAtOrAbove(result.report, failOn);
|
|
2272
|
-
const leads = failOnCandidates ? findingsAtOrAbove(result.report, failOnCandidates, true).filter((finding) => finding.disposition !== "confirmed") : [];
|
|
2273
|
-
const incomplete = result.report.coverageStatus === "incomplete" && parsed.options["allow-incomplete"] !== true;
|
|
2274
|
-
if (confirmed.length || leads.length || incomplete) {
|
|
2275
|
-
throw new Error(`hosted security gate failed: ${confirmed.length} confirmed >= ${failOn}; ${leads.length} leads >= ${failOnCandidates ?? "disabled"}${incomplete ? "; coverage incomplete" : ""}`);
|
|
2276
|
-
}
|
|
3078
|
+
await securityCommand(parsed, dependencies);
|
|
2277
3079
|
return;
|
|
2278
3080
|
}
|
|
2279
3081
|
if (command === "provision") {
|
|
2280
|
-
|
|
2281
|
-
parsed,
|
|
2282
|
-
[
|
|
2283
|
-
"config",
|
|
2284
|
-
"dry-run",
|
|
2285
|
-
"rotate-keys",
|
|
2286
|
-
"rotate-o11y-token",
|
|
2287
|
-
"push-secrets",
|
|
2288
|
-
"write-credentials",
|
|
2289
|
-
"write-dev-vars",
|
|
2290
|
-
"token",
|
|
2291
|
-
"open",
|
|
2292
|
-
"yes"
|
|
2293
|
-
],
|
|
2294
|
-
1
|
|
2295
|
-
);
|
|
2296
|
-
const writeDevVars2 = parsed.options["write-dev-vars"];
|
|
2297
|
-
const opts = {
|
|
2298
|
-
configPath: stringOpt(parsed.options.config) ?? "odla.config.mjs",
|
|
2299
|
-
dryRun: parsed.options["dry-run"] === true,
|
|
2300
|
-
rotateKeys: parsed.options["rotate-keys"] === true,
|
|
2301
|
-
rotateO11yToken: parsed.options["rotate-o11y-token"] === true,
|
|
2302
|
-
pushSecrets: parsed.options["push-secrets"] === true,
|
|
2303
|
-
writeCredentials: parsed.options["write-credentials"] !== false,
|
|
2304
|
-
writeDevVars: typeof writeDevVars2 === "string" ? writeDevVars2 : writeDevVars2 === true,
|
|
2305
|
-
token: stringOpt(parsed.options.token),
|
|
2306
|
-
open: parsed.options.open === false ? false : parsed.options.open === true ? true : void 0,
|
|
2307
|
-
yes: parsed.options.yes === true
|
|
2308
|
-
};
|
|
2309
|
-
await provision(opts);
|
|
3082
|
+
await provisionCommand(parsed);
|
|
2310
3083
|
return;
|
|
2311
3084
|
}
|
|
2312
3085
|
if (command === "smoke") {
|
|
@@ -2332,7 +3105,9 @@ async function runCli(argv = process.argv.slice(2)) {
|
|
|
2332
3105
|
}
|
|
2333
3106
|
if (command === "skill") {
|
|
2334
3107
|
const sub = parsed.positionals[1];
|
|
2335
|
-
if (sub !== "install")
|
|
3108
|
+
if (sub !== "install") {
|
|
3109
|
+
throw new Error(`unknown skill subcommand "${sub ?? ""}". Try "odla-ai skill install".`);
|
|
3110
|
+
}
|
|
2336
3111
|
assertArgs(parsed, ["dir", "global", "force", "agent", "harness"], 2);
|
|
2337
3112
|
installSkill({
|
|
2338
3113
|
dir: stringOpt(parsed.options.dir),
|
|
@@ -2344,7 +3119,9 @@ async function runCli(argv = process.argv.slice(2)) {
|
|
|
2344
3119
|
}
|
|
2345
3120
|
if (command === "secrets") {
|
|
2346
3121
|
const sub = parsed.positionals[1];
|
|
2347
|
-
if (sub !== "push")
|
|
3122
|
+
if (sub !== "push") {
|
|
3123
|
+
throw new Error(`unknown secrets subcommand "${sub ?? ""}". Try "odla-ai secrets push --env dev".`);
|
|
3124
|
+
}
|
|
2348
3125
|
assertArgs(parsed, ["config", "env", "dry-run", "yes"], 2);
|
|
2349
3126
|
await secretsPush({
|
|
2350
3127
|
configPath: stringOpt(parsed.options.config) ?? "odla.config.mjs",
|
|
@@ -2356,29 +3133,33 @@ async function runCli(argv = process.argv.slice(2)) {
|
|
|
2356
3133
|
}
|
|
2357
3134
|
throw new Error(`unknown command "${command}". Run "odla-ai help".`);
|
|
2358
3135
|
}
|
|
2359
|
-
function
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
];
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
3136
|
+
async function provisionCommand(parsed) {
|
|
3137
|
+
assertArgs(parsed, [
|
|
3138
|
+
"config",
|
|
3139
|
+
"dry-run",
|
|
3140
|
+
"rotate-keys",
|
|
3141
|
+
"rotate-o11y-token",
|
|
3142
|
+
"push-secrets",
|
|
3143
|
+
"write-credentials",
|
|
3144
|
+
"write-dev-vars",
|
|
3145
|
+
"token",
|
|
3146
|
+
"open",
|
|
3147
|
+
"yes"
|
|
3148
|
+
], 1);
|
|
3149
|
+
const writeDevVars2 = parsed.options["write-dev-vars"];
|
|
3150
|
+
const options = {
|
|
3151
|
+
configPath: stringOpt(parsed.options.config) ?? "odla.config.mjs",
|
|
3152
|
+
dryRun: parsed.options["dry-run"] === true,
|
|
3153
|
+
rotateKeys: parsed.options["rotate-keys"] === true,
|
|
3154
|
+
rotateO11yToken: parsed.options["rotate-o11y-token"] === true,
|
|
3155
|
+
pushSecrets: parsed.options["push-secrets"] === true,
|
|
3156
|
+
writeCredentials: parsed.options["write-credentials"] !== false,
|
|
3157
|
+
writeDevVars: typeof writeDevVars2 === "string" ? writeDevVars2 : writeDevVars2 === true,
|
|
3158
|
+
token: stringOpt(parsed.options.token),
|
|
3159
|
+
open: parsed.options.open === false ? false : parsed.options.open === true ? true : void 0,
|
|
3160
|
+
yes: parsed.options.yes === true
|
|
3161
|
+
};
|
|
3162
|
+
await provision(options);
|
|
2382
3163
|
}
|
|
2383
3164
|
|
|
2384
3165
|
export {
|
|
@@ -2393,9 +3174,22 @@ export {
|
|
|
2393
3174
|
secretsPush,
|
|
2394
3175
|
provision,
|
|
2395
3176
|
runHostedSecurity,
|
|
3177
|
+
connectGitHubSecuritySource,
|
|
3178
|
+
listGitHubSecuritySources,
|
|
3179
|
+
disconnectGitHubSecuritySource,
|
|
3180
|
+
repositoryFromGitRemote,
|
|
3181
|
+
inferGitHubRepository,
|
|
3182
|
+
getHostedSecurityIntent,
|
|
3183
|
+
getHostedSecurityPlan,
|
|
3184
|
+
startHostedSecurityJob,
|
|
3185
|
+
getHostedSecurityJob,
|
|
3186
|
+
listHostedSecurityJobs,
|
|
3187
|
+
followHostedSecurityJob,
|
|
3188
|
+
getHostedSecurityReport,
|
|
3189
|
+
isTerminalHostedSecurityStatus,
|
|
2396
3190
|
AGENT_HARNESSES,
|
|
2397
3191
|
installSkill,
|
|
2398
3192
|
smoke,
|
|
2399
3193
|
runCli
|
|
2400
3194
|
};
|
|
2401
|
-
//# sourceMappingURL=chunk-
|
|
3195
|
+
//# sourceMappingURL=chunk-BHAEDEL2.js.map
|