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
425 changes: 342 additions & 83 deletions packages/action/dist/index.mjs

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ For long task text, use `--issue-file task.md`, pipe it directly to `fixmap plan
- **Repository Q&A** — use `fixmap ask --report <plan.json> --question <text>` to answer structural context, impact, test, risk, policy, ADR, and annotation questions from bounded report evidence with citations and explicit unknowns.
- **Migration planner** — use `fixmap migrate --input <migration.json>` to validate and render dependency phases, blast radius, compatibility, verification, and rollback without executing or applying the plan.
- **Reverse documentation** — use `fixmap reverse-docs --input <reverse-docs.json>` to create review-only module or architecture drafts from exact structural evidence without writing the requested destination.
- **Architecture history** — use `fixmap history --repo . --from <ref> --to <ref>` to compare immutable committed snapshots without checkout or worktree mutation.
- **Architecture history** — use `fixmap history --repo . --from <ref> --to <ref>` to compare immutable committed snapshots without checkout or worktree mutation. It also reports decision disagreements: edges at `--to` that break an import rule stated by an accepted decision record in `fixmap-deny-imports` frontmatter (one `from-pattern -> denied-pattern` per item). Snapshots are cached per exact commit outside the repository; `--no-cache` rebuilds them.
- **Historical plans (preview)** — `fixmap plan --issue <task> --at <ref>` ranks against the repository as it was at that commit, read from Git objects without checking out or changing the worktree.
- **Supply-chain evidence** — use `fixmap supply-chain --input <bundle.json>` to validate normalized package/security/license evidence without executing a scanner or inventing advisory truth.
- **Runtime evidence** — use `fixmap runtime --input <runtime.json>` to map redaction-reviewed traces and profiles only through exact repository paths and fingerprints.
- **Execution sandbox** — use `fixmap sandbox --request <sandbox.json> --execute-declared-command` to run one exact reviewed command with a pinned local image, network off, read-only source/root, and resource limits.
Expand Down
30 changes: 29 additions & 1 deletion packages/cli/src/cli-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export type CliOptions = {
baseRef?: string | undefined;
headRef?: string | undefined;
checkoutRef?: string | undefined;
atRef?: string | undefined;
format: "markdown" | "json" | "agent";
output?: string | undefined;
explainPath?: string | undefined;
Expand Down Expand Up @@ -95,6 +96,7 @@ Usage:
fixmap plan --issue "Fix login" --format agent
fixmap plan --issue "Fix login in auth middleware" --compare plan.json
fixmap plan --base main --head HEAD --format json
fixmap plan --issue "Fix login" --at v0.9.0
fixmap verify --report plan.json --diff main...HEAD
fixmap verify --report plan.json --working-tree
fixmap verify --report plan.json --working-tree --fail-on warning
Expand Down Expand Up @@ -162,6 +164,7 @@ Options:
--evidence <file> Attach a version-1 evidence bundle from another tool (repeatable; data only, never executed)
--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
--limit <n> Maximum context files to report (default 8, max 20)
--exclude <glob> Path pattern to leave out of ranking (repeatable)
--format <fmt> Output format: markdown (default), json, or compact agent
Expand Down Expand Up @@ -631,7 +634,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"].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.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 @@ -699,6 +702,22 @@ export async function runCli(args: string[], dependencies: CliDependencies = {})
stderr("--ref only applies when --repo is a remote GitHub URL or the issue URL infers one.\n");
return 1;
}
if (options.atRef) {
const conflicting = [
(options.diffSpec || options.baseRef || options.headRef) && "--diff/--base/--head",
options.workingTree && "--working-tree",
options.explainPath && "--explain",
remoteRepository && "a remote repository"
].filter(Boolean);
if (conflicting.length > 0) {
stderr(`--at ranks one local committed state and cannot be combined with ${conflicting.join(", ")}.\n`);
return 1;
}
if (!options.issueText) {
stderr("--at needs --issue or --issue-file so there is a task to rank against.\n");
return 1;
}
}
const unsupportedTaskUrl = describeUnsupportedTaskUrl(options.issueText);
if (unsupportedTaskUrl) { stderr(`${unsupportedTaskUrl}\n`); return 1; }

Expand Down Expand Up @@ -775,6 +794,7 @@ export async function runCli(args: string[], dependencies: CliDependencies = {})
baseRef: options.baseRef,
headRef: options.headRef,
checkoutRef: options.checkoutRef,
...(options.atRef ? { atRef: options.atRef } : {}),
workingTree: options.workingTree,
includeUntracked: options.includeUntracked,
useCache: !options.noCache,
Expand Down Expand Up @@ -1026,6 +1046,7 @@ const SINGLE_VALUE_FLAGS = new Set([
"--base",
"--head",
"--ref",
"--at",
"--repo",
"--semantic-model",
"--evidence",
Expand Down Expand Up @@ -1067,6 +1088,7 @@ export function parseArgs(args: string[]): CliOptions {
let baseRef: string | undefined;
let headRef: string | undefined;
let checkoutRef: string | undefined;
let atRef: string | undefined;
let format: "markdown" | "json" | "agent" = "markdown";
let output: string | undefined;
let explainPath: string | undefined;
Expand Down Expand Up @@ -1149,6 +1171,11 @@ export function parseArgs(args: string[]): CliOptions {
} else {
invalidValues.push("--ref requires a safe branch or tag name");
}
} else if (arg === "--at") {
consumeValue();
const trimmed = value?.trim();
if (trimmed && trimmed.length <= 500 && !/[\0\r\n]/.test(trimmed) && !trimmed.startsWith("-")) atRef = trimmed;
else invalidValues.push("--at requires a bounded single-line Git ref");
} else if (arg === "--repo") {
consumeValue();
if (value?.trim()) repo = expandHomePath(value.trim());
Expand Down Expand Up @@ -1234,6 +1261,7 @@ export function parseArgs(args: string[]): CliOptions {
baseRef,
headRef,
checkoutRef,
atRef,
format,
output,
explainPath,
Expand Down
35 changes: 22 additions & 13 deletions packages/cli/src/history-command.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import { realpath, stat, writeFile } from "node:fs/promises";
import { homedir } from "node:os";
import { resolve } from "node:path";
import { compareArchitectureRefs, type ArchitectureDrift, type HistoricalArchitectureSnapshot } from "@aryam/fixmap-core";
import { compareArchitectureRefs, type ArchitectureRefComparison } from "@aryam/fixmap-core";

export const HISTORY_USAGE = `Usage: fixmap history --from <git-ref> --to <git-ref> [--repo <dir>] [--coupling-delta <n>] [--no-policy] [--format markdown|json] [--output <file>]
export const HISTORY_USAGE = `Usage: fixmap history --from <git-ref> --to <git-ref> [--repo <dir>] [--coupling-delta <n>] [--no-policy] [--no-cache] [--format markdown|json] [--output <file>]

Compares exact committed architecture snapshots through Git objects without checking out either ref or changing the worktree.
Preview: Compares exact committed architecture snapshots through Git objects without checking out either ref or changing the worktree.
Reports added/removed import edges, new/resolved cycles, .fixmap/policy.json boundary violations, coupling growth, and
decision disagreements: edges at --to that break a fixmap-deny-imports rule stated by an accepted decision record.
Snapshots are cached per exact commit outside the repository (FIXMAP_CACHE_DIR); --no-cache rebuilds them.
`;

type HistoryResult = {
from: HistoricalArchitectureSnapshot;
to: HistoricalArchitectureSnapshot;
drift: ArchitectureDrift;
};
type HistoryResult = ArchitectureRefComparison;

export async function runHistoryCommand(
args: string[],
Expand Down Expand Up @@ -42,7 +41,8 @@ export async function runHistoryCommand(
fromRef: parsed.from,
toRef: parsed.to,
applyRepositoryPolicy: parsed.applyPolicy,
couplingDelta: parsed.couplingDelta
couplingDelta: parsed.couplingDelta,
useCache: parsed.useCache
});
const rendered = parsed.format === "json" ? `${JSON.stringify(result, null, 2)}\n` : renderHistoryMarkdown(result);
if (parsed.output) await (dependencies.writeOutput ?? ((path, contents) => writeFile(path, contents, "utf8")))(parsed.output, rendered);
Expand Down Expand Up @@ -75,6 +75,12 @@ export function renderHistoryMarkdown(result: HistoryResult): string {
...section("New boundary violations", drift.newBoundaryViolations, (entry) => `\`${entry.ruleId}\`: \`${entry.from}\` -> \`${entry.to}\``),
...section("Resolved boundary violations", drift.resolvedBoundaryViolations, (entry) => `\`${entry.ruleId}\`: \`${entry.from}\` -> \`${entry.to}\``),
...section("Coupling growth", drift.couplingGrowth, (entry) => `\`${entry.path}\`: ${entry.before} -> ${entry.after} (+${entry.delta})`),
...section("Decision disagreements", result.decisionDisagreements, (entry) =>
`\`${entry.decisionPath}\` (${entry.decisionTitle}) denies \`${entry.rule.from}\` -> \`${entry.rule.deny}\`; ` +
`\`${entry.edge.from}\` -> \`${entry.edge.to}\` ${entry.introduced ? "was introduced in this range" : "already existed at the earlier ref"}`),
...(result.to.decisionDiagnostics.length > 0
? section("Decision records not evaluated", result.to.decisionDiagnostics, (entry) => entry.message)
: []),
"> Read-only historical comparison. FixMap read committed Git objects and did not checkout a ref or change the worktree."
].join("\n")}\n`;
}
Expand All @@ -86,6 +92,7 @@ type ParsedArgs = {
repo: string;
couplingDelta: number;
applyPolicy: boolean;
useCache: boolean;
format: "markdown" | "json";
output?: string;
} | { ok: false; message: string };
Expand All @@ -96,15 +103,17 @@ function parseArgs(args: string[]): ParsedArgs {
let repo = ".";
let couplingDelta = 2;
let applyPolicy = true;
let useCache = true;
let format: "markdown" | "json" = "markdown";
let output: string | undefined;
const seen = new Set<string>();
for (let index = 0; index < args.length; index += 1) {
const raw = args[index]!;
if (raw === "--no-policy") {
if (seen.has(raw)) return { ok: false, message: "Pass --no-policy only once." };
if (raw === "--no-policy" || raw === "--no-cache") {
if (seen.has(raw)) return { ok: false, message: `Pass ${raw} only once.` };
seen.add(raw);
applyPolicy = false;
if (raw === "--no-policy") applyPolicy = false;
else useCache = false;
continue;
}
const separator = raw.indexOf("=");
Expand Down Expand Up @@ -134,7 +143,7 @@ function parseArgs(args: string[]): ParsedArgs {
}
}
if (!from || !to) return { ok: false, message: "history requires both --from <git-ref> and --to <git-ref>." };
return { ok: true, from, to, repo, couplingDelta, applyPolicy, format, ...(output ? { output } : {}) };
return { ok: true, from, to, repo, couplingDelta, applyPolicy, useCache, format, ...(output ? { output } : {}) };
}

function historyError(repo: string, error: unknown): string {
Expand Down
37 changes: 31 additions & 6 deletions packages/cli/src/mcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ type PlanArguments = {
head?: string;
repo?: string;
ref?: string;
at?: string;
format?: "markdown" | "json" | "agent";
limit?: number;
exclude?: string[];
Expand Down Expand Up @@ -149,6 +150,12 @@ const PLAN_TOOL = {
"GitHub URLs support issue-only analysis and are removed after scanning."
},
ref: { type: "string", description: "Branch or tag to scan when repo is a remote GitHub URL" },
at: {
type: "string",
description:
"Preview (may change before v0.10.0): Rank against this committed Git ref of a local repo, read from Git objects " +
"without checking out or changing the worktree. Needs issue; cannot be combined with diff, base/head, workingTree, or a remote repo."
},
format: {
type: "string",
description: "Output format: markdown (default), json, or compact agent, case-insensitive"
Expand Down Expand Up @@ -391,7 +398,9 @@ const HISTORY_TOOL = {
title: "FixMap history",
description:
"Preview (may change before v0.10.0): Compare architecture at two exact committed Git refs without checking out either ref or changing the worktree. " +
"Returns immutable commit IDs plus added/removed edges, cycle and boundary drift, and coupling growth.",
"Returns immutable commit IDs plus added/removed edges, cycle and boundary drift, coupling growth, and decision disagreements: " +
"edges at the later ref that break a fixmap-deny-imports rule stated by an accepted decision record. " +
"Snapshots are cached per exact commit outside the repository.",
inputSchema: {
type: "object" as const,
properties: {
Expand All @@ -400,6 +409,7 @@ const HISTORY_TOOL = {
to: { type: "string", description: "Later committed Git ref" },
couplingDelta: { type: "integer", minimum: 1, maximum: 10000, description: "Minimum coupling growth to report (default 2)" },
applyPolicy: { type: "boolean", description: "Apply the repository architecture policy when present (default true)" },
noCache: { type: "boolean", description: "Rebuild both snapshots instead of reusing the per-commit cache" },
format: { type: "string", description: "Output format: markdown (default) or json, case-insensitive" }
},
required: ["from", "to"],
Expand Down Expand Up @@ -749,7 +759,7 @@ export function createFixMapMcpServer(
}
if (request.params.name === HISTORY_TOOL.name) {
const record = request.params.arguments as Record<string, unknown> | undefined;
const unknown = Object.keys(record ?? {}).filter((key) => !["repo", "from", "to", "couplingDelta", "applyPolicy", "format"].includes(key));
const unknown = Object.keys(record ?? {}).filter((key) => !["repo", "from", "to", "couplingDelta", "applyPolicy", "noCache", "format"].includes(key));
if (unknown.length > 0) {
return { isError: true, content: [{ type: "text", text: `Invalid arguments: unknown argument${unknown.length === 1 ? "" : "s"}: ${unknown.join(", ")}.` }] };
}
Expand All @@ -763,8 +773,10 @@ export function createFixMapMcpServer(
if (record.couplingDelta !== undefined && (!Number.isSafeInteger(record.couplingDelta) || Number(record.couplingDelta) < 1 || Number(record.couplingDelta) > 10_000)) {
return { isError: true, content: [{ type: "text", text: 'Invalid arguments: "couplingDelta" must be an integer from 1 to 10000.' }] };
}
if (record.applyPolicy !== undefined && typeof record.applyPolicy !== "boolean") {
return { isError: true, content: [{ type: "text", text: 'Invalid arguments: "applyPolicy" must be a boolean.' }] };
for (const name of ["applyPolicy", "noCache"] as const) {
if (record[name] !== undefined && typeof record[name] !== "boolean") {
return { isError: true, content: [{ type: "text", text: `Invalid arguments: "${name}" must be a boolean.` }] };
}
}
const format = normalizeFormat(record.format);
if (!format.success) return { isError: true, content: [{ type: "text", text: `Invalid arguments: ${format.message}` }] };
Expand All @@ -775,7 +787,8 @@ export function createFixMapMcpServer(
fromRef: record.from.trim(),
toRef: record.to.trim(),
couplingDelta: record.couplingDelta === undefined ? 2 : Number(record.couplingDelta),
applyRepositoryPolicy: record.applyPolicy === undefined ? true : record.applyPolicy
applyRepositoryPolicy: record.applyPolicy !== false,
useCache: record.noCache !== true
});
return { content: [{ type: "text", text: format.value === "json" ? `${JSON.stringify(result, null, 2)}\n` : renderHistoryMarkdown(result) }] };
} catch (error) {
Expand Down Expand Up @@ -981,6 +994,7 @@ export function createFixMapMcpServer(
report = await buildReportForRepository({
repo: args.repo ?? (tryParseGitHubIssueSource(args.issue ?? "") ? undefined : defaultRepo),
checkoutRef: args.ref,
...(args.at ? { atRef: args.at } : {}),
issueText: args.issue,
diffSpec: args.diff,
baseRef: args.base,
Expand Down Expand Up @@ -1033,7 +1047,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"]);
const allowed = new Set(["issue", "diff", "base", "head", "repo", "ref", "format", "limit", "exclude", "workingTree", "includeUntracked", "noCache", "semanticModel", "evidence", "at"]);
const unknown = Object.keys(record).filter((key) => !allowed.has(key));
if (unknown.length > 0) {
return {
Expand Down Expand Up @@ -1101,6 +1115,17 @@ export function parsePlanArguments(input: unknown): PlanArgumentsValidation {
return { success: false, message: '"ref" must be a safe branch or tag name.' };
}
if (value.issue && /^https?:\/\/\S+$/i.test(value.issue) && !tryParseGitHubIssueSource(value.issue)) return { success: false, message: '"issue" URL must be a canonical public GitHub issue or pull request URL.' };
if (record.at !== undefined) {
if (typeof record.at !== "string" || !record.at.trim() || record.at.length > 500 || /[\0\r\n]/.test(record.at) || record.at.trim().startsWith("-")) {
return { success: false, message: '"at" must be a bounded single-line Git ref.' };
}
if (value.diff || value.base || value.head || value.workingTree) return { success: false, message: '"at" cannot be combined with diff, base/head, or workingTree.' };
if (/^https?:\/\//i.test(value.repo ?? "") || (!value.repo && tryParseGitHubIssueSource(value.issue ?? ""))) {
return { success: false, message: '"at" needs a local repository, not a remote GitHub URL.' };
}
if (!value.issue) return { success: false, message: '"at" needs "issue" so there is a task to rank against.' };
value.at = record.at.trim();
}
return { success: true, value };
}

Expand Down
5 changes: 4 additions & 1 deletion packages/cli/src/repository-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export type RepositoryPlanInput = {
baseRef?: string | undefined;
headRef?: string | undefined;
checkoutRef?: string | undefined;
/** Preview: rank against this local committed ref without checking it out. */
atRef?: string | undefined;
workingTree?: boolean | undefined;
includeUntracked?: boolean | undefined;
useCache?: boolean | undefined;
Expand Down Expand Up @@ -574,7 +576,8 @@ export async function buildReportForRepository(
exclude: input.exclude,
internalExclude: input.internalExclude,
embeddingProvider,
...(evidenceSources.length > 0 ? { evidenceSources } : {})
...(evidenceSources.length > 0 ? { evidenceSources } : {}),
...(input.atRef ? { atRef: input.atRef } : {})
});
reportProgress(`ranked ${report.contextFiles.length} context files`);
const sourceDiagnostics = [issueDiagnostic, resolvedSource.diagnostic].filter(
Expand Down
Loading
Loading