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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,161 changes: 804 additions & 357 deletions packages/action/dist/index.mjs

Large diffs are not rendered by default.

28 changes: 24 additions & 4 deletions packages/cli/src/cli-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export type CliOptions = {
noCache: boolean;
semanticModelPath?: string | undefined;
evidencePaths: string[];
sensitiveData: boolean;
supplyChainPath?: string | undefined;
unknownArgs: string[];
invalidValues: string[];
};
Expand Down Expand Up @@ -170,6 +172,8 @@ Options:
--no-cache Bypass the exact git-state repository scan cache
--semantic-model <dir> Use an existing local embedding model; never downloads or uploads source
--evidence <file> Attach a version-1 evidence bundle from another tool (repeatable; data only, never executed)
--sensitive-data Preview: Attach possible sensitive-data source-to-sink flows (locations and kinds only); with verify, flag flows the diff adds
--supply-chain <file> Preview: Attach findings from a normalized scanner/SBOM bundle for packages in manifests among the report's files
--repo <source> Local path or public GitHub HTTPS URL (defaults to current directory)
--ref <branch|tag> Branch or tag to scan when --repo is a remote GitHub URL
--at <git-ref> Preview: Rank against a local committed ref, read from Git objects without checkout
Expand Down Expand Up @@ -665,7 +669,7 @@ export async function runCli(args: string[], dependencies: CliDependencies = {})
return 1;
}
if (options.command === "verify") {
const planOnly = [options.issueText && "--issue", options.issueFile && "--issue-file", options.comparePath && "--compare", options.limit !== undefined && "--limit", options.exclude.length > 0 && "--exclude", options.explainPath && "--explain", options.semanticModelPath && "--semantic-model", options.evidencePaths.length > 0 && "--evidence", options.atRef && "--at"].filter(Boolean);
const planOnly = [options.issueText && "--issue", options.issueFile && "--issue-file", options.comparePath && "--compare", options.limit !== undefined && "--limit", options.exclude.length > 0 && "--exclude", options.explainPath && "--explain", options.semanticModelPath && "--semantic-model", options.evidencePaths.length > 0 && "--evidence", options.supplyChainPath && "--supply-chain", options.atRef && "--at"].filter(Boolean);
if (planOnly.length > 0) { stderr(`verify does not accept plan-only option(s): ${planOnly.join(", ")}.\n`); return 1; }
const outputCollision = await describeOutputInputCollision(options);
if (outputCollision) { stderr(`${outputCollision}\n`); return 1; }
Expand Down Expand Up @@ -833,7 +837,9 @@ export async function runCli(args: string[], dependencies: CliDependencies = {})
exclude: options.exclude,
internalExclude: localPlanArtifactExclusions(options),
semanticModelPath: options.semanticModelPath,
evidencePaths: options.evidencePaths
evidencePaths: options.evidencePaths,
...(options.sensitiveData ? { sensitiveData: true } : {}),
...(options.supplyChainPath ? { supplyChainPath: options.supplyChainPath } : {})
});
} catch (error) {
stderr(`${error instanceof Error ? error.message : String(error)}\n`);
Expand Down Expand Up @@ -1081,6 +1087,7 @@ const SINGLE_VALUE_FLAGS = new Set([
"--repo",
"--semantic-model",
"--evidence",
"--supply-chain",
"--format",
"--report",
"--explain",
Expand All @@ -1089,7 +1096,7 @@ const SINGLE_VALUE_FLAGS = new Set([
"--fail-on",
"--output"
]);
const BOOLEAN_FLAGS = new Set(["--working-tree", "--include-untracked", "--no-cache"]);
const BOOLEAN_FLAGS = new Set(["--working-tree", "--include-untracked", "--no-cache", "--sensitive-data"]);

function hasStandaloneHelpFlag(args: string[]): boolean {
for (let index = 1; index < args.length; index += 1) {
Expand Down Expand Up @@ -1133,6 +1140,8 @@ export function parseArgs(args: string[]): CliOptions {
let semanticModelPath: string | undefined;
const exclude: string[] = [];
const evidencePaths: string[] = [];
let sensitiveData = false;
let supplyChainPath: string | undefined;
const unknownArgs: string[] = [];
const invalidValues: string[] = [];
const flagCounts = new Map<string, number>();
Expand Down Expand Up @@ -1219,6 +1228,10 @@ export function parseArgs(args: string[]): CliOptions {
consumeValue();
if (value?.trim()) evidencePaths.push(expandHomePath(value.trim()));
else invalidValues.push("--evidence requires a local evidence bundle file");
} else if (arg === "--supply-chain") {
consumeValue();
if (value?.trim()) supplyChainPath = expandHomePath(value.trim());
else invalidValues.push("--supply-chain requires a local supply-chain bundle file");
} else if (arg === "--format") {
consumeValue();
const normalized = value?.trim().toLowerCase();
Expand Down Expand Up @@ -1274,6 +1287,11 @@ export function parseArgs(args: string[]): CliOptions {
flagCounts.set(arg, 1);
if (inlineValue !== undefined) invalidValues.push(`${arg} does not accept a value; pass ${arg} by itself`);
else noCache = true;
} else if (arg === "--sensitive-data") {
if (flagCounts.has(arg)) invalidValues.push(`pass ${arg} only once`);
flagCounts.set(arg, 1);
if (inlineValue !== undefined) invalidValues.push(`${arg} does not accept a value; pass ${arg} by itself`);
else sensitiveData = true;
} else if (arg === "--output") {
consumeValue();
if (value?.trim()) output = expandHomePath(value.trim());
Expand Down Expand Up @@ -1306,6 +1324,8 @@ export function parseArgs(args: string[]): CliOptions {
noCache,
semanticModelPath,
evidencePaths,
sensitiveData,
supplyChainPath,
unknownArgs,
invalidValues
};
Expand Down Expand Up @@ -1569,7 +1589,7 @@ async function runVerify(
return 1;
}

const result = verifyPlan(report, repo);
const result = verifyPlan(report, repo, { sensitiveData: options.sensitiveData });
const rendered = options.format === "json"
? `${JSON.stringify(result, null, 2)}\n`
: renderVerifyMarkdown(result);
Expand Down
40 changes: 34 additions & 6 deletions packages/cli/src/mcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ type PlanArguments = {
noCache?: boolean;
semanticModel?: string;
evidence?: string[];
sensitiveData?: boolean;
supplyChain?: string;
};

type ExplainArguments = {
Expand Down Expand Up @@ -114,6 +116,7 @@ type VerifyArguments = {
workingTree?: boolean;
includeUntracked?: boolean;
noCache?: boolean;
sensitiveData?: boolean;
};

const PLAN_TOOL = {
Expand Down Expand Up @@ -188,6 +191,14 @@ const PLAN_TOOL = {
items: { type: "string" },
maxItems: 8,
description: "Local version-1 evidence bundle files from other tools (data only, never executed). Relevant items are attached to the report."
},
sensitiveData: {
type: "boolean",
description: "Preview: attach possible sensitive-data source-to-sink flows (credential, token, PII, payment to logging, network, storage, analytics) touching the report's files. Locations and kinds only; matched values are never included."
},
supplyChain: {
type: "string",
description: "Preview: local version-1 normalized scanner/SBOM bundle file. Findings for packages declared in manifests among the report's files are attached with tool, database, and bundle provenance."
}
},
additionalProperties: false
Expand Down Expand Up @@ -527,7 +538,11 @@ const VERIFY_TOOL = {
workingTree: { type: "boolean", description: "Verify staged and unstaged tracked changes against HEAD" },
includeUntracked: { type: "boolean", description: "With workingTree, include untracked files" },
format: { type: "string", description: "Output format: markdown (default) or json, case-insensitive" },
noCache: { type: "boolean", description: "Bypass the exact-state repository scan cache" }
noCache: { type: "boolean", description: "Bypass the exact-state repository scan cache" },
sensitiveData: {
type: "boolean",
description: "Preview: attach possible sensitive-data flows touching the plan or diff and add an advisory finding when the diff adds one. Locations and kinds only."
}
},
required: ["report"],
additionalProperties: false
Expand Down Expand Up @@ -1010,7 +1025,7 @@ export function createFixMapMcpServer(
if (diffFailure) {
throw new Error(`${diffFailure.message} Verification needs a resolvable diff.`);
}
const result = verifyPlan(args.report, repo);
const result = verifyPlan(args.report, repo, { sensitiveData: args.sensitiveData === true });
const text = args.format === "json"
? `${JSON.stringify(result, null, 2)}\n`
: renderVerifyMarkdown(result);
Expand Down Expand Up @@ -1111,7 +1126,9 @@ export function createFixMapMcpServer(
limit: args.limit,
exclude: args.exclude,
semanticModelPath: args.semanticModel,
...(args.evidence ? { evidencePaths: args.evidence } : {})
...(args.evidence ? { evidencePaths: args.evidence } : {}),
...(args.sensitiveData ? { sensitiveData: true } : {}),
...(args.supplyChain ? { supplyChainPath: args.supplyChain } : {})
}, repositorySourceDependencies);
} catch (error) {
return {
Expand Down Expand Up @@ -1153,7 +1170,7 @@ export function parsePlanArguments(input: unknown): PlanArgumentsValidation {
}

const record = input as Record<string, unknown>;
const allowed = new Set(["issue", "diff", "base", "head", "repo", "ref", "format", "limit", "exclude", "workingTree", "includeUntracked", "noCache", "semanticModel", "evidence", "at"]);
const allowed = new Set(["issue", "diff", "base", "head", "repo", "ref", "format", "limit", "exclude", "workingTree", "includeUntracked", "noCache", "semanticModel", "evidence", "sensitiveData", "supplyChain", "at"]);
const unknown = Object.keys(record).filter((key) => !allowed.has(key));
if (unknown.length > 0) {
return {
Expand Down Expand Up @@ -1214,6 +1231,16 @@ export function parsePlanArguments(input: unknown): PlanArgumentsValidation {
}
value.evidence = record.evidence.map((entry: string) => entry.trim());
}
if (record.sensitiveData !== undefined && typeof record.sensitiveData !== "boolean") {
return { success: false, message: '"sensitiveData" must be a boolean.' };
}
if (record.sensitiveData === true) value.sensitiveData = true;
if (record.supplyChain !== undefined) {
if (typeof record.supplyChain !== "string" || !record.supplyChain.trim() || record.supplyChain.length > 1_000 || record.supplyChain.includes("\0")) {
return { success: false, message: '"supplyChain" must be a non-empty local bundle file path.' };
}
value.supplyChain = record.supplyChain.trim();
}
if (value.ref && !/^https?:\/\//i.test(value.repo ?? "") && !tryParseGitHubIssueSource(value.issue ?? "")) {
return { success: false, message: '"ref" requires a remote GitHub "repo" or issue URL.' };
}
Expand Down Expand Up @@ -1376,7 +1403,7 @@ export function parseVerifyArguments(input: unknown): VerifyArgumentsValidation
return { success: false, message: "tool arguments must be an object." };
}
const record = input as Record<string, unknown>;
const allowed = new Set(["report", "diff", "base", "head", "repo", "format", "workingTree", "includeUntracked", "noCache"]);
const allowed = new Set(["report", "diff", "base", "head", "repo", "format", "workingTree", "includeUntracked", "noCache", "sensitiveData"]);
const unknown = Object.keys(record).filter((key) => !allowed.has(key));
if (unknown.length > 0) {
return { success: false, message: `unknown argument${unknown.length === 1 ? "" : "s"}: ${unknown.join(", ")}.` };
Expand All @@ -1398,7 +1425,7 @@ export function parseVerifyArguments(input: unknown): VerifyArgumentsValidation
if (!record.diff && !record.base && record.workingTree !== true) {
return { success: false, message: 'provide "diff", "base"/"head", or "workingTree" so FixMap can see what changed.' };
}
for (const name of ["workingTree", "includeUntracked", "noCache"] as const) if (record[name] !== undefined && typeof record[name] !== "boolean") return { success: false, message: `"${name}" must be a boolean.` };
for (const name of ["workingTree", "includeUntracked", "noCache", "sensitiveData"] as const) if (record[name] !== undefined && typeof record[name] !== "boolean") return { success: false, message: `"${name}" must be a boolean.` };
if (record.includeUntracked === true && record.workingTree !== true) return { success: false, message: '"includeUntracked" requires "workingTree".' };
if (record.workingTree === true && (record.diff || record.base || record.head)) return { success: false, message: 'use either "workingTree" or diff/base/head, not both.' };
if (record.diff && (record.base || record.head)) return { success: false, message: 'use either "diff" or base/head, not both.' };
Expand All @@ -1416,6 +1443,7 @@ export function parseVerifyArguments(input: unknown): VerifyArgumentsValidation
...(record.workingTree === true ? { workingTree: true } : {}),
...(record.includeUntracked === true ? { includeUntracked: true } : {}),
...(record.noCache === true ? { noCache: true } : {}),
...(record.sensitiveData === true ? { sensitiveData: true } : {}),
...(format.value ? { format: format.value } : {})
}
};
Expand Down
8 changes: 8 additions & 0 deletions packages/cli/src/repository-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
type ReportEvidenceSource,
type ScanDiagnostic
} from "@aryam/fixmap-core";
import { readSupplyChainBundleFile } from "./supply-chain-command.js";

const exec = promisify(execFile);
const GIT_MAX_BUFFER = 10 * 1024 * 1024;
Expand Down Expand Up @@ -42,6 +43,10 @@ export type RepositoryPlanInput = {
semanticModelPath?: string | undefined;
/** Local evidence bundle files (data only, version-1 envelope). */
evidencePaths?: string[] | undefined;
/** Attach local lexical sensitive-data flows (locations and kinds only). */
sensitiveData?: boolean | undefined;
/** Local normalized supply-chain bundle file (data only). */
supplyChainPath?: string | undefined;
};

export type ClonedRepository = {
Expand Down Expand Up @@ -552,6 +557,7 @@ export async function buildReportForRepository(
const bundle = await readEvidenceProviderBundle(path);
evidenceSources.push({ provider: bundle.provider, documentSha256: bundle.documentSha256 });
}
const supplyChain = input.supplyChainPath ? readSupplyChainBundleFile(input.supplyChainPath) : undefined;

return withRepositorySource(
source,
Expand All @@ -577,6 +583,8 @@ export async function buildReportForRepository(
internalExclude: input.internalExclude,
embeddingProvider,
...(evidenceSources.length > 0 ? { evidenceSources } : {}),
...(input.sensitiveData ? { sensitiveData: true } : {}),
...(supplyChain ? { supplyChain } : {}),
...(input.atRef ? { atRef: input.atRef } : {})
});
reportProgress(`ranked ${report.contextFiles.length} context files`);
Expand Down
17 changes: 16 additions & 1 deletion packages/cli/src/supply-chain-command.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { createHash } from "node:crypto";
import { readFileSync } from "node:fs";
import { writeFile } from "node:fs/promises";
import { homedir } from "node:os";
import { resolve } from "node:path";
Expand All @@ -7,7 +9,7 @@ import {
validateSupplyChainEvidenceBundle,
type SupplyChainEvidenceBundle
} from "@aryam/fixmap-core";
import { describeInputReadError, readDecodedTextFile } from "./decode-input.js";
import { decodeInputText, describeInputReadError, readDecodedTextFile } from "./decode-input.js";

export const SUPPLY_CHAIN_USAGE = `Usage: fixmap supply-chain --input <bundle.json> [--format markdown|json] [--output <file>]

Expand All @@ -16,6 +18,19 @@ Validates a version-1 normalized external scanner/SBOM bundle and renders packag

export type SupplyChainReport = Awaited<ReturnType<typeof buildSupplyChainReport>>;

/** Read and validate a bundle for `plan --supply-chain`, with the SHA-256 of its exact bytes. */
export function readSupplyChainBundleFile(path: string): { bundle: SupplyChainEvidenceBundle; documentSha256: string } {
try {
const bytes = readFileSync(path);
return {
bundle: validateSupplyChainEvidenceBundle(JSON.parse(decodeInputText(bytes)) as unknown),
documentSha256: createHash("sha256").update(bytes).digest("hex")
};
} catch (error) {
throw new Error(`Could not import supply-chain evidence from "${path}": ${describeInputReadError(path, error)}`);
}
}

export async function buildSupplyChainReport(candidate: unknown) {
const bundle = validateSupplyChainEvidenceBundle(candidate);
const evidence = await collectEvidence([createSupplyChainEvidenceProvider(bundle)], {
Expand Down
49 changes: 47 additions & 2 deletions packages/cli/test/cli-runner.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { execFile } from "node:child_process";
import { link, mkdir, mkdtemp, readFile, readdir, symlink, writeFile } from "node:fs/promises";
import { link, mkdir, mkdtemp, readFile, readdir, rm, symlink, writeFile } from "node:fs/promises";
import { homedir, tmpdir } from "node:os";
import { dirname, join } from "node:path";
import { promisify } from "node:util";
Expand Down Expand Up @@ -200,7 +200,7 @@ describe("CLI argument handling", () => {
const features = (JSON.parse(catalog.stdout.join("")) as { features: Array<{ name: string; preview?: true }> }).features;
expect(features.filter((feature) => feature.preview).map((feature) => feature.name)).toEqual([
"Change scope", "Reviewer suggestions", "Product capabilities", "Cross-repository workspace", "Repository Q&A", "Migration planning",
"Reverse documentation", "Architecture history", "Historical plans", "Contract Guardian", "Supply-chain evidence", "Runtime evidence", "Evidence import", "Outcome feedback loop", "Change dossier", "Execution sandbox",
"Reverse documentation", "Architecture history", "Historical plans", "Contract Guardian", "Supply-chain evidence", "Runtime evidence", "Evidence import", "Sensitive-data flows", "Supply-chain in plans", "Outcome feedback loop", "Change dossier", "Execution sandbox",
"Local hybrid retrieval"
]);
expect(features.find((feature) => feature.name === "Plan")?.preview).toBeUndefined();
Expand Down Expand Up @@ -1155,6 +1155,51 @@ describe("CLI argument handling", () => {
}));
});

it("passes --sensitive-data and --supply-chain to the report builder and rejects bad forms", async () => {
const io = capture();
const buildReport = vi.fn(async () => report);
await runCli(
["plan", "--issue", "rotate the session token", "--sensitive-data", "--supply-chain", "scanner.json"],
{ ...io.dependencies, buildReport }
);
expect(buildReport).toHaveBeenCalledWith(expect.objectContaining({ sensitiveData: true, supplyChainPath: "scanner.json" }));

const plain = vi.fn(async () => report);
await runCli(["plan", "--issue", "rotate the session token"], { ...capture().dependencies, buildReport: plain });
expect(plain.mock.calls[0]![0]).not.toHaveProperty("sensitiveData");
expect(plain.mock.calls[0]![0]).not.toHaveProperty("supplyChainPath");

for (const args of [
["plan", "--issue", "x", "--sensitive-data=yes"],
["plan", "--issue", "x", "--sensitive-data", "--sensitive-data"],
["plan", "--issue", "x", "--supply-chain"],
["plan", "--issue", "x", "--supply-chain", "a.json", "--supply-chain", "b.json"]
]) {
const rejected = capture();
expect(await runCli(args, { ...rejected.dependencies, buildReport })).toBe(1);
}

const verify = capture();
expect(await runCli(["verify", "--report", "plan.json", "--supply-chain", "scanner.json"], verify.dependencies)).toBe(1);
expect(verify.stderr.join("")).toContain("verify does not accept plan-only option(s): --supply-chain");
});

it("reports a malformed supply-chain bundle without a stack or its contents", async () => {
const directory = await mkdtemp(join(tmpdir(), "fixmap-cli-supply-"));
try {
const bundlePath = join(directory, "scanner.json");
await writeFile(bundlePath, JSON.stringify({ supplyChainBundleVersion: 2, secret: "sk_live_SUPERSECRET_1234" }));
const io = capture();
expect(await runCli(["plan", "--issue", "upgrade left-pad", "--repo", directory, "--supply-chain", bundlePath], io.dependencies)).toBe(1);
const stderr = io.stderr.join("");
expect(stderr).toContain("Could not import supply-chain evidence");
expect(stderr).toContain("Invalid supply-chain evidence bundle envelope.");
expect(stderr).not.toContain("SUPERSECRET");
} finally {
await rm(directory, { recursive: true, force: true });
}
});

it("keeps semantic-model selection out of verify", async () => {
const io = capture();
expect(await runCli([
Expand Down
Loading
Loading