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
2 changes: 1 addition & 1 deletion integration/ddd_layer_rules_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Deno.test(
},
);

const KNOWN_PRESENTATION_INFRA_VIOLATIONS = 49;
const KNOWN_PRESENTATION_INFRA_VIOLATIONS = 51;

Deno.test(
"presentation layer must not add new infrastructure imports (ratchet)",
Expand Down
45 changes: 19 additions & 26 deletions src/cli/commands/audit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,19 @@ import { requireInitializedRepoReadOnly } from "../repo_context.ts";
import { AuditService } from "../../domain/audit/audit_service.ts";
import { createBashCommandEntry } from "../../domain/audit/audit_command_entry.ts";
import { JsonlAuditRepository } from "../../infrastructure/persistence/jsonl_audit_repository.ts";
import {
renderAuditTimeline,
renderAuditToolNotSupported,
renderNoAuditData,
} from "../../presentation/output/audit_output.ts";
import {
type HookTool,
normalizeHookInput,
} from "../../domain/audit/hook_input.ts";
import { RepoMarkerRepository } from "../../infrastructure/persistence/repo_marker_repository.ts";
import { RepoPath } from "../../domain/repo/repo_path.ts";
import {
auditTimeline,
consumeStream,
createAuditTimelineDeps,
createLibSwampContext,
} from "../../libswamp/mod.ts";
import { createAuditTimelineRenderer } from "../../presentation/renderers/audit_timeline.ts";

/**
* Reads all of stdin as a string.
Expand Down Expand Up @@ -160,28 +162,19 @@ export const auditCommand = new Command()
const marker = await markerRepo.read(RepoPath.create(repoDir));
const configuredTool = marker?.tool ?? "claude";

if (configuredTool === "codex") {
renderAuditToolNotSupported("codex", ctx.outputMode);
}

const auditRepository = new JsonlAuditRepository(repoDir);
const service = new AuditService(auditRepository);

const timeline = await service.getTimeline({
hours: options.hours,
showAll: options.all ?? false,
sessionId: options.session,
});

if (
timeline.entries.length === 0 && timeline.totalSwamp === 0 &&
timeline.totalDirect === 0
) {
renderNoAuditData(ctx.outputMode);
return;
}
const libCtx = createLibSwampContext({ logger: ctx.logger });
const deps = createAuditTimelineDeps(repoDir);
const renderer = createAuditTimelineRenderer(ctx.outputMode);
await consumeStream(
auditTimeline(libCtx, deps, {
hours: options.hours,
showAll: options.all ?? false,
sessionId: options.session,
tool: configuredTool,
}),
renderer.handlers(),
);

renderAuditTimeline(timeline, ctx.outputMode);
ctx.logger.debug("Audit command completed");
})
.command("record", auditRecordCommand);
47 changes: 19 additions & 28 deletions src/cli/commands/issue_bug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@
// along with Swamp. If not, see <https://www.gnu.org/licenses/>.

import { Command } from "@cliffy/command";
import { createContext, type GlobalOptions } from "../context.ts";
import {
consumeStream,
createIssueCreateDeps,
createLibSwampContext,
issueCreate,
} from "../../libswamp/mod.ts";
import {
type IssueCreateData,
createIssueCreateRenderer,
renderIssueCancelled,
renderIssueCreate,
} from "../../presentation/output/issue_output.ts";
import { createContext, type GlobalOptions } from "../context.ts";
} from "../../presentation/renderers/issue_create.ts";
import { EditorService } from "../../infrastructure/editor/editor_service.ts";
import { GitHubIssueService } from "../../infrastructure/github/github_issue_service.ts";
import { UserError } from "../../domain/errors.ts";

// deno-lint-ignore no-explicit-any
Expand Down Expand Up @@ -117,7 +121,6 @@ export const issueBugCommand = new Command()
ctx.logger.debug`Submitting bug report`;

const editorService = new EditorService();
const githubService = new GitHubIssueService();

let title: string;
let body: string;
Expand Down Expand Up @@ -177,30 +180,18 @@ export const issueBugCommand = new Command()

ctx.logger.debug`Creating GitHub issue with title: ${title}`;

// Create the GitHub issue
const result = await githubService.createIssue({
title,
body,
labels: ["bug", "external"],
});

const data: IssueCreateData = result.method === "created"
? {
method: "created",
url: result.url,
number: result.number,
type: "bug",
const libCtx = createLibSwampContext({ logger: ctx.logger });
const deps = createIssueCreateDeps();
const renderer = createIssueCreateRenderer(ctx.outputMode);
await consumeStream(
issueCreate(libCtx, deps, {
title,
}
: {
method: "url",
url: result.url,
body,
labels: ["bug", "external"],
type: "bug",
title,
body: result.body,
labels: result.labels,
};
}),
renderer.handlers(),
);

renderIssueCreate(data, ctx.outputMode);
ctx.logger.debug("Bug report submitted successfully");
});
47 changes: 19 additions & 28 deletions src/cli/commands/issue_feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@
// along with Swamp. If not, see <https://www.gnu.org/licenses/>.

import { Command } from "@cliffy/command";
import { createContext, type GlobalOptions } from "../context.ts";
import {
consumeStream,
createIssueCreateDeps,
createLibSwampContext,
issueCreate,
} from "../../libswamp/mod.ts";
import {
type IssueCreateData,
createIssueCreateRenderer,
renderIssueCancelled,
renderIssueCreate,
} from "../../presentation/output/issue_output.ts";
import { createContext, type GlobalOptions } from "../context.ts";
} from "../../presentation/renderers/issue_create.ts";
import { EditorService } from "../../infrastructure/editor/editor_service.ts";
import { GitHubIssueService } from "../../infrastructure/github/github_issue_service.ts";
import { UserError } from "../../domain/errors.ts";

// deno-lint-ignore no-explicit-any
Expand Down Expand Up @@ -116,7 +120,6 @@ export const issueFeatureCommand = new Command()
ctx.logger.debug`Submitting feature request`;

const editorService = new EditorService();
const githubService = new GitHubIssueService();

let title: string;
let body: string;
Expand Down Expand Up @@ -176,30 +179,18 @@ export const issueFeatureCommand = new Command()

ctx.logger.debug`Creating GitHub issue with title: ${title}`;

// Create the GitHub issue
const result = await githubService.createIssue({
title,
body,
labels: ["enhancement", "external"],
});

const data: IssueCreateData = result.method === "created"
? {
method: "created",
url: result.url,
number: result.number,
type: "feature",
const libCtx = createLibSwampContext({ logger: ctx.logger });
const deps = createIssueCreateDeps();
const renderer = createIssueCreateRenderer(ctx.outputMode);
await consumeStream(
issueCreate(libCtx, deps, {
title,
}
: {
method: "url",
url: result.url,
body,
labels: ["enhancement", "external"],
type: "feature",
title,
body: result.body,
labels: result.labels,
};
}),
renderer.handlers(),
);

renderIssueCreate(data, ctx.outputMode);
ctx.logger.debug("Feature request submitted successfully");
});
22 changes: 11 additions & 11 deletions src/cli/commands/source_clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@

import { Command } from "@cliffy/command";
import { createContext, type GlobalOptions } from "../context.ts";
import { SourceService } from "../../domain/source/mod.ts";
import { HttpSourceDownloader } from "../../infrastructure/source/http_source_downloader.ts";
import { JsonSourceMetadataRepository } from "../../infrastructure/source/json_source_metadata_repository.ts";
import { renderSourceClean } from "../../presentation/output/source_output.ts";
import {
consumeStream,
createLibSwampContext,
createSourceCleanDeps,
sourceClean,
} from "../../libswamp/mod.ts";
import { createSourceCleanRenderer } from "../../presentation/renderers/source_clean.ts";

// deno-lint-ignore no-explicit-any
type AnyOptions = any;
Expand All @@ -33,13 +36,10 @@ export const sourceCleanCommand = new Command()
const ctx = createContext(options as GlobalOptions, ["source", "clean"]);
ctx.logger.debug("Executing source clean command");

const downloader = new HttpSourceDownloader();
const repository = new JsonSourceMetadataRepository();
const service = new SourceService(downloader, repository);

const result = await service.clean();

renderSourceClean(result, ctx.outputMode);
const libCtx = createLibSwampContext({ logger: ctx.logger });
const deps = createSourceCleanDeps();
const renderer = createSourceCleanRenderer(ctx.outputMode);
await consumeStream(sourceClean(libCtx, deps), renderer.handlers());

ctx.logger.debug("Source clean command completed");
});
27 changes: 14 additions & 13 deletions src/cli/commands/source_fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@
import { Command } from "@cliffy/command";
import { createContext, type GlobalOptions } from "../context.ts";
import { VERSION } from "./version.ts";
import { SourceService } from "../../domain/source/mod.ts";
import { HttpSourceDownloader } from "../../infrastructure/source/http_source_downloader.ts";
import { JsonSourceMetadataRepository } from "../../infrastructure/source/json_source_metadata_repository.ts";
import { renderSourceFetch } from "../../presentation/output/source_output.ts";
import {
consumeStream,
createLibSwampContext,
createSourceFetchDeps,
sourceFetch,
} from "../../libswamp/mod.ts";
import { createSourceFetchRenderer } from "../../presentation/renderers/source_fetch.ts";

// deno-lint-ignore no-explicit-any
type AnyOptions = any;
Expand All @@ -38,17 +41,15 @@ export const sourceFetchCommand = new Command()
const ctx = createContext(options as GlobalOptions, ["source", "fetch"]);
ctx.logger.debug("Executing source fetch command");

// Use current CLI version if no version specified
const version = options.version ?? VERSION;
ctx.logger.debug`Fetching source version: ${version}`;

const downloader = new HttpSourceDownloader();
const repository = new JsonSourceMetadataRepository();
const service = new SourceService(downloader, repository);

const result = await service.fetch(version);

renderSourceFetch(result, ctx.outputMode);
const libCtx = createLibSwampContext({ logger: ctx.logger });
const deps = createSourceFetchDeps();
const renderer = createSourceFetchRenderer(ctx.outputMode);
await consumeStream(
sourceFetch(libCtx, deps, { version }),
renderer.handlers(),
);

ctx.logger.debug("Source fetch command completed");
});
22 changes: 11 additions & 11 deletions src/cli/commands/source_path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@

import { Command } from "@cliffy/command";
import { createContext, type GlobalOptions } from "../context.ts";
import { SourceService } from "../../domain/source/mod.ts";
import { HttpSourceDownloader } from "../../infrastructure/source/http_source_downloader.ts";
import { JsonSourceMetadataRepository } from "../../infrastructure/source/json_source_metadata_repository.ts";
import { renderSourcePath } from "../../presentation/output/source_output.ts";
import {
consumeStream,
createLibSwampContext,
createSourcePathDeps,
sourcePath,
} from "../../libswamp/mod.ts";
import { createSourcePathRenderer } from "../../presentation/renderers/source_path.ts";

// deno-lint-ignore no-explicit-any
type AnyOptions = any;
Expand All @@ -33,13 +36,10 @@ export const sourcePathCommand = new Command()
const ctx = createContext(options as GlobalOptions, ["source", "path"]);
ctx.logger.debug("Executing source path command");

const downloader = new HttpSourceDownloader();
const repository = new JsonSourceMetadataRepository();
const service = new SourceService(downloader, repository);

const result = await service.getInfo();

renderSourcePath(result, ctx.outputMode);
const libCtx = createLibSwampContext({ logger: ctx.logger });
const deps = createSourcePathDeps();
const renderer = createSourcePathRenderer(ctx.outputMode);
await consumeStream(sourcePath(libCtx, deps), renderer.handlers());

ctx.logger.debug("Source path command completed");
});
43 changes: 21 additions & 22 deletions src/cli/commands/summarise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
import { Command } from "@cliffy/command";
import { createContext, type GlobalOptions } from "../context.ts";
import { requireInitializedRepoReadOnly } from "../repo_context.ts";
import { SummaryService } from "../../domain/summary/summary_service.ts";
import { parseDuration } from "./data_search.ts";
import {
renderNoActivity,
renderSummary,
} from "../../presentation/output/summarise_output.ts";
consumeStream,
createLibSwampContext,
createSummariseDeps,
summarise,
} from "../../libswamp/mod.ts";
import { createSummariseRenderer } from "../../presentation/renderers/summarise.ts";

/**
* `swamp summarise`
Expand Down Expand Up @@ -54,25 +56,22 @@ export const summariseCommand = new Command()
const durationMs = parseDuration(options.since);
const cutoffDate = new Date(Date.now() - durationMs);

const service = new SummaryService(
repoContext.outputRepo,
repoContext.workflowRunRepo,
repoContext.unifiedDataRepo,
repoContext.definitionRepo,
repoContext.workflowRepo,
const libCtx = createLibSwampContext({ logger: ctx.logger });
const deps = createSummariseDeps({
outputRepo: repoContext.outputRepo,
workflowRunRepo: repoContext.workflowRunRepo,
dataRepo: repoContext.unifiedDataRepo,
definitionRepo: repoContext.definitionRepo,
workflowRepo: repoContext.workflowRepo,
});
const renderer = createSummariseRenderer(ctx.outputMode, ctx.verbosity);
await consumeStream(
summarise(libCtx, deps, {
since: cutoffDate,
sinceLabel: options.since,
}),
renderer.handlers(),
);

const summary = await service.summarise(cutoffDate);

const hasActivity = summary.methodExecutions.length > 0 ||
summary.workflows.length > 0 ||
summary.data.totalItems > 0;

if (!hasActivity) {
renderNoActivity(options.since, ctx.outputMode);
return;
}

renderSummary(summary, options.since, ctx.outputMode, ctx.verbosity);
ctx.logger.debug`Summarise command completed`;
});
Loading
Loading