@kb-labs/commit-cli 0.5.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 +120 -0
- package/dist/cli/commands/apply.d.ts +22 -0
- package/dist/cli/commands/apply.js +132 -0
- package/dist/cli/commands/apply.js.map +1 -0
- package/dist/cli/commands/flags.d.ts +99 -0
- package/dist/cli/commands/flags.js +73 -0
- package/dist/cli/commands/flags.js.map +1 -0
- package/dist/cli/commands/generate.d.ts +45 -0
- package/dist/cli/commands/generate.js +149 -0
- package/dist/cli/commands/generate.js.map +1 -0
- package/dist/cli/commands/index.d.ts +1 -0
- package/dist/cli/commands/index.js +73 -0
- package/dist/cli/commands/index.js.map +1 -0
- package/dist/cli/commands/open.d.ts +50 -0
- package/dist/cli/commands/open.js +80 -0
- package/dist/cli/commands/open.js.map +1 -0
- package/dist/cli/commands/push.d.ts +18 -0
- package/dist/cli/commands/push.js +71 -0
- package/dist/cli/commands/push.js.map +1 -0
- package/dist/cli/commands/reset.d.ts +15 -0
- package/dist/cli/commands/reset.js +52 -0
- package/dist/cli/commands/reset.js.map +1 -0
- package/dist/cli/commands/run.d.ts +51 -0
- package/dist/cli/commands/run.js +190 -0
- package/dist/cli/commands/run.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +916 -0
- package/dist/index.js.map +1 -0
- package/dist/lifecycle/setup.d.ts +53 -0
- package/dist/lifecycle/setup.js +96 -0
- package/dist/lifecycle/setup.js.map +1 -0
- package/dist/manifest.d.ts +207 -0
- package/dist/manifest.js +833 -0
- package/dist/manifest.js.map +1 -0
- package/dist/rest/handlers/actions-handler.d.ts +16 -0
- package/dist/rest/handlers/actions-handler.js +15 -0
- package/dist/rest/handlers/actions-handler.js.map +1 -0
- package/dist/rest/handlers/apply-handler.d.ts +26 -0
- package/dist/rest/handlers/apply-handler.js +115 -0
- package/dist/rest/handlers/apply-handler.js.map +1 -0
- package/dist/rest/handlers/diff-handler.d.ts +20 -0
- package/dist/rest/handlers/diff-handler.js +64 -0
- package/dist/rest/handlers/diff-handler.js.map +1 -0
- package/dist/rest/handlers/files-handler.d.ts +16 -0
- package/dist/rest/handlers/files-handler.js +143 -0
- package/dist/rest/handlers/files-handler.js.map +1 -0
- package/dist/rest/handlers/generate-handler.d.ts +66 -0
- package/dist/rest/handlers/generate-handler.js +97 -0
- package/dist/rest/handlers/generate-handler.js.map +1 -0
- package/dist/rest/handlers/git-status-handler.d.ts +13 -0
- package/dist/rest/handlers/git-status-handler.js +58 -0
- package/dist/rest/handlers/git-status-handler.js.map +1 -0
- package/dist/rest/handlers/patch-plan-handler.d.ts +23 -0
- package/dist/rest/handlers/patch-plan-handler.js +50 -0
- package/dist/rest/handlers/patch-plan-handler.js.map +1 -0
- package/dist/rest/handlers/plan-handler.d.ts +50 -0
- package/dist/rest/handlers/plan-handler.js +32 -0
- package/dist/rest/handlers/plan-handler.js.map +1 -0
- package/dist/rest/handlers/push-handler.d.ts +25 -0
- package/dist/rest/handlers/push-handler.js +75 -0
- package/dist/rest/handlers/push-handler.js.map +1 -0
- package/dist/rest/handlers/regenerate-handler.d.ts +37 -0
- package/dist/rest/handlers/regenerate-handler.js +124 -0
- package/dist/rest/handlers/regenerate-handler.js.map +1 -0
- package/dist/rest/handlers/reset-handler.d.ts +17 -0
- package/dist/rest/handlers/reset-handler.js +30 -0
- package/dist/rest/handlers/reset-handler.js.map +1 -0
- package/dist/rest/handlers/scope-resolver.d.ts +15 -0
- package/dist/rest/handlers/scope-resolver.js +12 -0
- package/dist/rest/handlers/scope-resolver.js.map +1 -0
- package/dist/rest/handlers/scopes-handler.d.ts +12 -0
- package/dist/rest/handlers/scopes-handler.js +24 -0
- package/dist/rest/handlers/scopes-handler.js.map +1 -0
- package/dist/rest/handlers/status-handler.d.ts +27 -0
- package/dist/rest/handlers/status-handler.js +91 -0
- package/dist/rest/handlers/status-handler.js.map +1 -0
- package/dist/rest/handlers/summarize-handler.d.ts +21 -0
- package/dist/rest/handlers/summarize-handler.js +106 -0
- package/dist/rest/handlers/summarize-handler.js.map +1 -0
- package/dist/widgets/220.js +446 -0
- package/dist/widgets/220.js.map +1 -0
- package/dist/widgets/331.js +2 -0
- package/dist/widgets/331.js.map +1 -0
- package/dist/widgets/403.js +2 -0
- package/dist/widgets/403.js.map +1 -0
- package/dist/widgets/406.js +35 -0
- package/dist/widgets/406.js.map +1 -0
- package/dist/widgets/455.js +2 -0
- package/dist/widgets/455.js.map +1 -0
- package/dist/widgets/482.js +2 -0
- package/dist/widgets/482.js.map +1 -0
- package/dist/widgets/485.js +2 -0
- package/dist/widgets/485.js.map +1 -0
- package/dist/widgets/527.js +2 -0
- package/dist/widgets/527.js.map +1 -0
- package/dist/widgets/628.js +2 -0
- package/dist/widgets/628.js.map +1 -0
- package/dist/widgets/694.js +2 -0
- package/dist/widgets/694.js.map +1 -0
- package/dist/widgets/712.js +2 -0
- package/dist/widgets/712.js.map +1 -0
- package/dist/widgets/866.js +2 -0
- package/dist/widgets/866.js.map +1 -0
- package/dist/widgets/915.js +39 -0
- package/dist/widgets/915.js.map +1 -0
- package/dist/widgets/957.js +10 -0
- package/dist/widgets/957.js.map +1 -0
- package/dist/widgets/983.js +2 -0
- package/dist/widgets/983.js.map +1 -0
- package/dist/widgets/@mf-types.d.ts +3 -0
- package/dist/widgets/@mf-types.zip +0 -0
- package/dist/widgets/__federation_expose_CommitOverview.js +2 -0
- package/dist/widgets/__federation_expose_CommitOverview.js.map +1 -0
- package/dist/widgets/mf-manifest.json +260 -0
- package/dist/widgets/mf-stats.json +302 -0
- package/dist/widgets/remoteEntry.js +7 -0
- package/dist/widgets/remoteEntry.js.map +1 -0
- package/package.json +95 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import * as _kb_labs_shared_command_kit from '@kb-labs/shared-command-kit';
|
|
2
|
+
import { RestInput } from '@kb-labs/sdk';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* POST /generate handler
|
|
6
|
+
*
|
|
7
|
+
* Generates a new commit plan for the given scope.
|
|
8
|
+
* Uses LLM to analyze changes and group into conventional commits.
|
|
9
|
+
*/
|
|
10
|
+
declare const _default: _kb_labs_shared_command_kit.Handler<unknown, RestInput<unknown, {
|
|
11
|
+
scope: string;
|
|
12
|
+
dryRun: boolean;
|
|
13
|
+
allowSecrets: boolean;
|
|
14
|
+
autoConfirm: boolean;
|
|
15
|
+
}, unknown>, {
|
|
16
|
+
scope: string;
|
|
17
|
+
success: boolean;
|
|
18
|
+
secretsDetected: boolean;
|
|
19
|
+
message?: string | undefined;
|
|
20
|
+
plan?: {
|
|
21
|
+
schemaVersion: "1.0";
|
|
22
|
+
createdAt: string;
|
|
23
|
+
repoRoot: string;
|
|
24
|
+
gitStatus: {
|
|
25
|
+
staged: string[];
|
|
26
|
+
unstaged: string[];
|
|
27
|
+
untracked: string[];
|
|
28
|
+
};
|
|
29
|
+
commits: {
|
|
30
|
+
message: string;
|
|
31
|
+
type: "feat" | "fix" | "refactor" | "chore" | "docs" | "test" | "build" | "ci" | "perf";
|
|
32
|
+
id: string;
|
|
33
|
+
files: string[];
|
|
34
|
+
releaseHint: "none" | "patch" | "minor" | "major";
|
|
35
|
+
breaking: boolean;
|
|
36
|
+
scope?: string | undefined;
|
|
37
|
+
body?: string | undefined;
|
|
38
|
+
reasoning?: {
|
|
39
|
+
newBehavior: boolean;
|
|
40
|
+
fixesBug: boolean;
|
|
41
|
+
internalOnly: boolean;
|
|
42
|
+
explanation: string;
|
|
43
|
+
confidence: number;
|
|
44
|
+
} | undefined;
|
|
45
|
+
}[];
|
|
46
|
+
metadata: {
|
|
47
|
+
totalFiles: number;
|
|
48
|
+
totalCommits: number;
|
|
49
|
+
llmUsed: boolean;
|
|
50
|
+
tokensUsed?: number | undefined;
|
|
51
|
+
escalated?: boolean | undefined;
|
|
52
|
+
};
|
|
53
|
+
} | undefined;
|
|
54
|
+
planPath?: string | undefined;
|
|
55
|
+
secrets?: {
|
|
56
|
+
type: string;
|
|
57
|
+
file: string;
|
|
58
|
+
line: number;
|
|
59
|
+
column: number;
|
|
60
|
+
pattern: string;
|
|
61
|
+
matched: string;
|
|
62
|
+
context: string;
|
|
63
|
+
}[] | undefined;
|
|
64
|
+
}>;
|
|
65
|
+
|
|
66
|
+
export { _default as default };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { defineHandler, useConfig } from '@kb-labs/sdk';
|
|
2
|
+
import { resolveCommitConfig, COMMIT_CACHE_PREFIX } from '@kb-labs/commit-contracts';
|
|
3
|
+
import { generateCommitPlan } from '@kb-labs/commit-core/generator';
|
|
4
|
+
import { savePlan, getCurrentPlanPath } from '@kb-labs/commit-core/storage';
|
|
5
|
+
import { SecretsDetectedError } from '@kb-labs/commit-core/analyzer';
|
|
6
|
+
import * as path from 'path';
|
|
7
|
+
|
|
8
|
+
// src/rest/handlers/generate-handler.ts
|
|
9
|
+
function resolveScopePath(baseCwd, scopeId = "root", scopes) {
|
|
10
|
+
const scopeDef = scopes?.find((s) => s.id === scopeId);
|
|
11
|
+
const relativePath = scopeDef?.path ?? (scopeId === "root" ? "." : scopeId);
|
|
12
|
+
return relativePath === "." ? baseCwd : path.join(baseCwd, relativePath);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// src/rest/handlers/generate-handler.ts
|
|
16
|
+
var generate_handler_default = defineHandler({
|
|
17
|
+
async execute(ctx, input) {
|
|
18
|
+
const { scope = "root", dryRun, allowSecrets = false, autoConfirm = false } = input.body ?? {};
|
|
19
|
+
const startTime = Date.now();
|
|
20
|
+
try {
|
|
21
|
+
const fileConfig = await useConfig();
|
|
22
|
+
const config = resolveCommitConfig(fileConfig ?? {});
|
|
23
|
+
const scopeCwd = resolveScopePath(ctx.cwd, scope, config.scope?.scopes);
|
|
24
|
+
const plan = await generateCommitPlan({
|
|
25
|
+
cwd: scopeCwd,
|
|
26
|
+
allowSecrets,
|
|
27
|
+
autoConfirm,
|
|
28
|
+
onProgress: (message) => {
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
let planPath = "";
|
|
32
|
+
if (!dryRun) {
|
|
33
|
+
await savePlan(ctx.cwd, plan, scope);
|
|
34
|
+
planPath = getCurrentPlanPath(ctx.cwd, scope);
|
|
35
|
+
const appliedCacheKey = `${COMMIT_CACHE_PREFIX}plan-applied:${scope}`;
|
|
36
|
+
await ctx.platform.cache.delete(appliedCacheKey);
|
|
37
|
+
}
|
|
38
|
+
if (ctx.platform.analytics) {
|
|
39
|
+
await ctx.platform.analytics.track("commit.plan.generated", {
|
|
40
|
+
scope,
|
|
41
|
+
dryRun,
|
|
42
|
+
filesChanged: plan.metadata.totalFiles,
|
|
43
|
+
commitsGenerated: plan.metadata.totalCommits,
|
|
44
|
+
llmUsed: plan.metadata.llmUsed,
|
|
45
|
+
tokensUsed: plan.metadata.tokensUsed,
|
|
46
|
+
escalated: plan.metadata.escalated,
|
|
47
|
+
durationMs: Date.now() - startTime
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
success: true,
|
|
52
|
+
plan,
|
|
53
|
+
planPath,
|
|
54
|
+
scope,
|
|
55
|
+
secretsDetected: false
|
|
56
|
+
};
|
|
57
|
+
} catch (error) {
|
|
58
|
+
if (error instanceof SecretsDetectedError) {
|
|
59
|
+
if (ctx.platform.analytics) {
|
|
60
|
+
await ctx.platform.analytics.track("commit.secrets.detected", {
|
|
61
|
+
scope,
|
|
62
|
+
secretCount: error.secretMatches.length,
|
|
63
|
+
durationMs: Date.now() - startTime
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
success: false,
|
|
68
|
+
scope,
|
|
69
|
+
secretsDetected: true,
|
|
70
|
+
secrets: error.secretMatches.map((match) => ({
|
|
71
|
+
file: match.file,
|
|
72
|
+
line: match.line,
|
|
73
|
+
column: match.column,
|
|
74
|
+
type: match.patternName,
|
|
75
|
+
pattern: match.pattern,
|
|
76
|
+
matched: match.matchedText,
|
|
77
|
+
context: match.snippet
|
|
78
|
+
})),
|
|
79
|
+
message: error.message
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
if (ctx.platform.analytics) {
|
|
83
|
+
await ctx.platform.analytics.track("commit.plan.error", {
|
|
84
|
+
scope,
|
|
85
|
+
dryRun,
|
|
86
|
+
error: error instanceof Error ? error.message : String(error),
|
|
87
|
+
durationMs: Date.now() - startTime
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
throw new Error(`Failed to generate commit plan: ${error}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
export { generate_handler_default as default };
|
|
96
|
+
//# sourceMappingURL=generate-handler.js.map
|
|
97
|
+
//# sourceMappingURL=generate-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/rest/handlers/scope-resolver.ts","../../../src/rest/handlers/generate-handler.ts"],"names":[],"mappings":";;;;;;;;AAaO,SAAS,gBAAA,CACd,OAAA,EACA,OAAA,GAAkB,MAAA,EAClB,MAAA,EACQ;AACR,EAAA,MAAM,WAAW,MAAA,EAAQ,IAAA,CAAK,CAAC,CAAA,KAAM,CAAA,CAAE,OAAO,OAAO,CAAA;AACrD,EAAA,MAAM,YAAA,GAAe,QAAA,EAAU,IAAA,KAAS,OAAA,KAAY,SAAS,GAAA,GAAM,OAAA,CAAA;AACnE,EAAA,OAAO,YAAA,KAAiB,GAAA,GAAM,OAAA,GAAe,IAAA,CAAA,IAAA,CAAK,SAAS,YAAY,CAAA;AACzE;;;ACFA,IAAO,2BAAQ,aAAA,CAAc;AAAA,EAC3B,MAAM,OAAA,CAAQ,GAAA,EAAsB,KAAA,EAAuE;AACzG,IAAA,MAAM,EAAE,KAAA,GAAQ,MAAA,EAAQ,MAAA,EAAQ,YAAA,GAAe,KAAA,EAAO,WAAA,GAAc,KAAA,EAAM,GAAI,KAAA,CAAM,IAAA,IAAQ,EAAC;AAC7F,IAAA,MAAM,SAAA,GAAY,KA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A,UACA,MAAA;AAAA,UACA,OAAO,KAAA,YAAiB,KAAA,GAAQ,KAAA,CAAM,OAAA,GAAU,OAAO,KAAK,CAAA;AAAA,UAC5D,UAAA,EAAY,IAAA,CAAK,GAAA,EAAI,GAAI;AAAA,SAC1B,CAAA;AAAA,MACH;AAEA,MAAA,MAAM,IAAI,KAAA,CAAM,CAAA,gCAAA,EAAmC,KAAK,CAAA,CAAE,CAAA;AAAA,IAC5D;AAAA,EACF;AACF,CAAC","file":"generate-handler.js","sourcesContent":["import * as path from 'node:path';\nimport type { CommitScope } from '@kb-labs/commit-contracts';\n\n/**\n * Resolves a scope id to an absolute filesystem path.\n *\n * Looks up the scope in the provided scopes array by id.\n * Falls back to treating the id as a relative path from baseCwd (legacy compat).\n *\n * @param baseCwd - Workspace root (ctx.cwd)\n * @param scopeId - Scope identifier, e.g. \"root\", \"public/kb-labs\"\n * @param scopes - Configured scopes from CommitPluginConfig.scope.scopes\n */\nexport function resolveScopePath(\n baseCwd: string,\n scopeId: string = 'root',\n scopes?: CommitScope[],\n): string {\n const scopeDef = scopes?.find((s) => s.id === scopeId);\n const relativePath = scopeDef?.path ?? (scopeId === 'root' ? '.' : scopeId);\n return relativePath === '.' ? baseCwd : path.join(baseCwd, relativePath);\n}\n","import { defineHandler, useConfig, type PluginContextV3, type RestInput } from '@kb-labs/sdk';\nimport {\n COMMIT_CACHE_PREFIX,\n type GenerateRequest,\n type GenerateResponse,\n type CommitPluginConfig,\n resolveCommitConfig,\n} from '@kb-labs/commit-contracts';\nimport { generateCommitPlan } from '@kb-labs/commit-core/generator';\nimport { savePlan, getCurrentPlanPath } from '@kb-labs/commit-core/storage';\nimport { SecretsDetectedError } from '@kb-labs/commit-core/analyzer';\nimport { resolveScopePath } from './scope-resolver';\n\n/**\n * POST /generate handler\n *\n * Generates a new commit plan for the given scope.\n * Uses LLM to analyze changes and group into conventional commits.\n */\nexport default defineHandler({\n async execute(ctx: PluginContextV3, input: RestInput<unknown, GenerateRequest>): Promise<GenerateResponse> {\n const { scope = 'root', dryRun, allowSecrets = false, autoConfirm = false } = input.body ?? {};\n const startTime = Date.now();\n\n try {\n const fileConfig = await useConfig<Partial<CommitPluginConfig>>();\n const config = resolveCommitConfig(fileConfig ?? {});\n const scopeCwd = resolveScopePath(ctx.cwd, scope, config.scope?.scopes);\n\n const plan = await generateCommitPlan({\n cwd: scopeCwd,\n allowSecrets,\n autoConfirm,\n onProgress: (message) => {\n },\n });\n\n let planPath = '';\n\n // Save plan unless dry-run\n if (!dryRun) {\n await savePlan(ctx.cwd, plan, scope);\n planPath = getCurrentPlanPath(ctx.cwd, scope);\n\n // New plan invalidates previously applied state for this scope.\n const appliedCacheKey = `${COMMIT_CACHE_PREFIX}plan-applied:${scope}`;\n await ctx.platform.cache.delete(appliedCacheKey);\n }\n\n // Track success\n if (ctx.platform.analytics) {\n await ctx.platform.analytics.track('commit.plan.generated', {\n scope,\n dryRun,\n filesChanged: plan.metadata.totalFiles,\n commitsGenerated: plan.metadata.totalCommits,\n llmUsed: plan.metadata.llmUsed,\n tokensUsed: plan.metadata.tokensUsed,\n escalated: plan.metadata.escalated,\n durationMs: Date.now() - startTime,\n });\n }\n\n return {\n success: true,\n plan,\n planPath,\n scope,\n secretsDetected: false,\n };\n } catch (error) {\n // Handle secrets detection specially - return structured response instead of throwing\n if (error instanceof SecretsDetectedError) {\n // Track secrets detected event\n if (ctx.platform.analytics) {\n await ctx.platform.analytics.track('commit.secrets.detected', {\n scope,\n secretCount: error.secretMatches.length,\n durationMs: Date.now() - startTime,\n });\n }\n\n // Return structured response with secrets info\n return {\n success: false,\n scope,\n secretsDetected: true,\n secrets: error.secretMatches.map((match) => ({\n file: match.file,\n line: match.line,\n column: match.column,\n type: match.patternName,\n pattern: match.pattern,\n matched: match.matchedText,\n context: match.snippet,\n })),\n message: error.message,\n };\n }\n\n // Track other errors\n if (ctx.platform.analytics) {\n await ctx.platform.analytics.track('commit.plan.error', {\n scope,\n dryRun,\n error: error instanceof Error ? error.message : String(error),\n durationMs: Date.now() - startTime,\n });\n }\n\n throw new Error(`Failed to generate commit plan: ${error}`);\n }\n },\n});\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as _kb_labs_shared_command_kit from '@kb-labs/shared-command-kit';
|
|
2
|
+
import { RestInput, TableData, TableRow } from '@kb-labs/sdk';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* GET /git-status handler
|
|
6
|
+
*
|
|
7
|
+
* Returns git status as table data for Studio table widget.
|
|
8
|
+
*/
|
|
9
|
+
declare const _default: _kb_labs_shared_command_kit.Handler<unknown, RestInput<{
|
|
10
|
+
scope?: string;
|
|
11
|
+
}, unknown, unknown>, TableData<TableRow>>;
|
|
12
|
+
|
|
13
|
+
export { _default as default };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { defineHandler, useConfig } from '@kb-labs/sdk';
|
|
2
|
+
import { getGitStatus } from '@kb-labs/commit-core/analyzer';
|
|
3
|
+
import { resolveCommitConfig } from '@kb-labs/commit-contracts';
|
|
4
|
+
import * as path from 'path';
|
|
5
|
+
|
|
6
|
+
// src/rest/handlers/git-status-handler.ts
|
|
7
|
+
function resolveScopePath(baseCwd, scopeId = "root", scopes) {
|
|
8
|
+
const scopeDef = scopes?.find((s) => s.id === scopeId);
|
|
9
|
+
const relativePath = scopeDef?.path ?? (scopeId === "root" ? "." : scopeId);
|
|
10
|
+
return relativePath === "." ? baseCwd : path.join(baseCwd, relativePath);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// src/rest/handlers/git-status-handler.ts
|
|
14
|
+
var git_status_handler_default = defineHandler({
|
|
15
|
+
async execute(ctx, input) {
|
|
16
|
+
const scope = input.query?.scope || "root";
|
|
17
|
+
try {
|
|
18
|
+
const fileConfig = await useConfig();
|
|
19
|
+
const config = resolveCommitConfig(fileConfig ?? {});
|
|
20
|
+
const scopeCwd = resolveScopePath(ctx.cwd, scope, config.scope?.scopes);
|
|
21
|
+
ctx.platform.logger.info("[git-status] Resolution", {
|
|
22
|
+
cwd: ctx.cwd,
|
|
23
|
+
scope,
|
|
24
|
+
scopeCwd
|
|
25
|
+
});
|
|
26
|
+
const status = await getGitStatus(scopeCwd);
|
|
27
|
+
const rows = [];
|
|
28
|
+
for (const filePath of status.staged) {
|
|
29
|
+
rows.push({
|
|
30
|
+
path: filePath,
|
|
31
|
+
status: "staged"
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
for (const filePath of status.unstaged) {
|
|
35
|
+
rows.push({
|
|
36
|
+
path: filePath,
|
|
37
|
+
status: "modified"
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
for (const filePath of status.untracked) {
|
|
41
|
+
rows.push({
|
|
42
|
+
path: filePath,
|
|
43
|
+
status: "untracked"
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
rows,
|
|
48
|
+
total: rows.length
|
|
49
|
+
};
|
|
50
|
+
} catch (error) {
|
|
51
|
+
throw new Error(`Failed to get git status: ${error}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
export { git_status_handler_default as default };
|
|
57
|
+
//# sourceMappingURL=git-status-handler.js.map
|
|
58
|
+
//# sourceMappingURL=git-status-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/rest/handlers/scope-resolver.ts","../../../src/rest/handlers/git-status-handler.ts"],"names":[],"mappings":";;;;;;AAaO,SAAS,gBAAA,CACd,OAAA,EACA,OAAA,GAAkB,MAAA,EAClB,MAAA,EACQ;AACR,EAAA,MAAM,WAAW,MAAA,EAAQ,IAAA,CAAK,CAAC,CAAA,KAAM,CAAA,CAAE,OAAO,OAAO,CAAA;AACrD,EAAA,MAAM,YAAA,GAAe,QAAA,EAAU,IAAA,KAAS,OAAA,KAAY,SAAS,GAAA,GAAM,OAAA,CAAA;AACnE,EAAA,OAAO,YAAA,KAAiB,GAAA,GAAM,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EA,MAAA,OAAO;AAAA,QACL,IAAA;AAAA,QACA,OAAO,IAAA,CAAK;AAAA,OACd;AAAA,IACF,SAAS,KAAA,EAAO;AACd,MAAA,MAAM,IAAI,KAAA,CAAM,CAAA,0BAAA,EAA6B,KAAK,CAAA,CAAE,CAAA;AAAA,IACtD;AAAA,EACF;AACF,CAAC","file":"git-status-handler.js","sourcesContent":["import * as path from 'node:path';\nimport type { CommitScope } from '@kb-labs/commit-contracts';\n\n/**\n * Resolves a scope id to an absolute filesystem path.\n *\n * Looks up the scope in the provided scopes array by id.\n * Falls back to treating the id as a relative path from baseCwd (legacy compat).\n *\n * @param baseCwd - Workspace root (ctx.cwd)\n * @param scopeId - Scope identifier, e.g. \"root\", \"public/kb-labs\"\n * @param scopes - Configured scopes from CommitPluginConfig.scope.scopes\n */\nexport function resolveScopePath(\n baseCwd: string,\n scopeId: string = 'root',\n scopes?: CommitScope[],\n): string {\n const scopeDef = scopes?.find((s) => s.id === scopeId);\n const relativePath = scopeDef?.path ?? (scopeId === 'root' ? '.' : scopeId);\n return relativePath === '.' ? baseCwd : path.join(baseCwd, relativePath);\n}\n","import { defineHandler, useConfig, type PluginContextV3, type RestInput, type TableData, type TableRow } from '@kb-labs/sdk';\nimport { getGitStatus } from '@kb-labs/commit-core/analyzer';\nimport { type CommitPluginConfig, resolveCommitConfig } from '@kb-labs/commit-contracts';\nimport { resolveScopePath } from './scope-resolver';\n\n/**\n * GET /git-status handler\n *\n * Returns git status as table data for Studio table widget.\n */\nexport default defineHandler({\n async execute(ctx: PluginContextV3, input: RestInput<{ scope?: string }>): Promise<TableData> {\n const scope = input.query?.scope || 'root';\n\n try {\n // Resolve scope to actual directory path\n const fileConfig = await useConfig<Partial<CommitPluginConfig>>();\n const config = resolveCommitConfig(fileConfig ?? {});\n const scopeCwd = resolveScopePath(ctx.cwd, scope, config.scope?.scopes);\n\n ctx.platform.logger.info('[git-status] Resolution', {\n cwd: ctx.cwd,\n scope,\n scopeCwd,\n });\n\n // Get git status (git runs FROM scopeCwd, no filtering)\n const status = await getGitStatus(scopeCwd);\n\n // Convert git status to table rows\n const rows: TableRow[] = [];\n\n // Add staged files\n for (const filePath of status.staged) {\n rows.push({\n path: filePath,\n status: 'staged',\n });\n }\n\n // Add unstaged files\n for (const filePath of status.unstaged) {\n rows.push({\n path: filePath,\n status: 'modified',\n });\n }\n\n // Add untracked files\n for (const filePath of status.untracked) {\n rows.push({\n path: filePath,\n status: 'untracked',\n });\n }\n\n return {\n rows,\n total: rows.length,\n };\n } catch (error) {\n throw new Error(`Failed to get git status: ${error}`);\n }\n },\n});\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as _kb_labs_shared_command_kit from '@kb-labs/shared-command-kit';
|
|
2
|
+
import { RestInput } from '@kb-labs/sdk';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* PATCH /plan handler
|
|
6
|
+
*
|
|
7
|
+
* Edits a single commit's message, type, scope, or body in the stored plan
|
|
8
|
+
* without triggering LLM regeneration.
|
|
9
|
+
*/
|
|
10
|
+
declare const _default: _kb_labs_shared_command_kit.Handler<unknown, RestInput<unknown, {
|
|
11
|
+
scope: string;
|
|
12
|
+
commitId: string;
|
|
13
|
+
message?: string | undefined;
|
|
14
|
+
type?: string | undefined;
|
|
15
|
+
body?: string | undefined;
|
|
16
|
+
scope_?: string | undefined;
|
|
17
|
+
}, unknown>, {
|
|
18
|
+
scope: string;
|
|
19
|
+
success: boolean;
|
|
20
|
+
commitId: string;
|
|
21
|
+
}>;
|
|
22
|
+
|
|
23
|
+
export { _default as default };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { defineHandler } from '@kb-labs/sdk';
|
|
2
|
+
import { ConventionalTypeSchema, COMMIT_CACHE_PREFIX } from '@kb-labs/commit-contracts';
|
|
3
|
+
import { loadPlan, savePlan } from '@kb-labs/commit-core/storage';
|
|
4
|
+
|
|
5
|
+
// src/rest/handlers/patch-plan-handler.ts
|
|
6
|
+
var patch_plan_handler_default = defineHandler({
|
|
7
|
+
async execute(ctx, input) {
|
|
8
|
+
const { scope = "root", commitId, message, type, scope_: commitScope, body } = input.body ?? {};
|
|
9
|
+
if (!commitId) {
|
|
10
|
+
throw new Error("commitId is required");
|
|
11
|
+
}
|
|
12
|
+
const plan = await loadPlan(ctx.cwd, scope);
|
|
13
|
+
if (!plan) {
|
|
14
|
+
throw new Error("No commit plan found. Generate a plan first.");
|
|
15
|
+
}
|
|
16
|
+
const commitIndex = plan.commits.findIndex((c) => c.id === commitId);
|
|
17
|
+
if (commitIndex === -1) {
|
|
18
|
+
throw new Error(`Commit "${commitId}" not found in plan`);
|
|
19
|
+
}
|
|
20
|
+
const commit = plan.commits[commitIndex];
|
|
21
|
+
if (message !== void 0) {
|
|
22
|
+
commit.message = message;
|
|
23
|
+
}
|
|
24
|
+
if (type !== void 0) {
|
|
25
|
+
const parsed = ConventionalTypeSchema.safeParse(type);
|
|
26
|
+
if (parsed.success) {
|
|
27
|
+
commit.type = parsed.data;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (commitScope !== void 0) {
|
|
31
|
+
commit.scope = commitScope || void 0;
|
|
32
|
+
}
|
|
33
|
+
if (body !== void 0) {
|
|
34
|
+
commit.body = body || void 0;
|
|
35
|
+
}
|
|
36
|
+
plan.commits[commitIndex] = commit;
|
|
37
|
+
await savePlan(ctx.cwd, plan, scope);
|
|
38
|
+
const appliedCacheKey = `${COMMIT_CACHE_PREFIX}plan-applied:${scope}`;
|
|
39
|
+
await ctx.platform.cache.delete(appliedCacheKey);
|
|
40
|
+
return {
|
|
41
|
+
success: true,
|
|
42
|
+
scope,
|
|
43
|
+
commitId
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
export { patch_plan_handler_default as default };
|
|
49
|
+
//# sourceMappingURL=patch-plan-handler.js.map
|
|
50
|
+
//# sourceMappingURL=patch-plan-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|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EAAW;AAC7B,MAAA,MAAA,CAAO,QAAQ,WAAA,IAAe,MAAA;AAAA,IAChC;AACA,IAAA,IAAI,SAAS,MAAA,EAAW;AACtB,MAAA,MAAA,CAAO,OAAO,IAAA,IAAQ,MAAA;AAAA,IACxB;AAEA,IAAA,IAAA,CAAK,OAAA,CAAQ,WAAW,CAAA,GAAI,MAAA;AAC5B,IAAA,MAAM,QAAA,CAAS,GAAA,CAAI,GAAA,EAAK,IAAA,EAAM,KAAK,CAAA;AAGnC,IAAA,MAAM,eAAA,GAAkB,CAAA,EAAG,mBAAmB,CAAA,aAAA,EAAgB,KAAK,CAAA,CAAA;AACnE,IAAA,MAAM,GAAA,CAAI,QAAA,CAAS,KAAA,CAAM,MAAA,CAAO,eAAe,CAAA;AAE/C,IAAA,OAAO;AAAA,MACL,OAAA,EAAS,IAAA;AAAA,MACT,KAAA;AAAA,MACA;AAAA,KACF;AAAA,EACF;AACF,CAAC","file":"patch-plan-handler.js","sourcesContent":["import { defineHandler, type PluginContextV3, type RestInput } from '@kb-labs/sdk';\nimport {\n COMMIT_CACHE_PREFIX,\n type PatchPlanRequest,\n type PatchPlanResponse,\n ConventionalTypeSchema,\n} from '@kb-labs/commit-contracts';\nimport { loadPlan, savePlan } from '@kb-labs/commit-core/storage';\n\n/**\n * PATCH /plan handler\n *\n * Edits a single commit's message, type, scope, or body in the stored plan\n * without triggering LLM regeneration.\n */\nexport default defineHandler({\n async execute(ctx: PluginContextV3, input: RestInput<unknown, PatchPlanRequest>): Promise<PatchPlanResponse> {\n const { scope = 'root', commitId, message, type, scope_: commitScope, body } = input.body ?? {};\n\n if (!commitId) {\n throw new Error('commitId is required');\n }\n\n const plan = await loadPlan(ctx.cwd, scope);\n if (!plan) {\n throw new Error('No commit plan found. Generate a plan first.');\n }\n\n const commitIndex = plan.commits.findIndex(c => c.id === commitId);\n if (commitIndex === -1) {\n throw new Error(`Commit \"${commitId}\" not found in plan`);\n }\n\n const commit = plan.commits[commitIndex]!;\n\n if (message !== undefined) {\n commit.message = message;\n }\n if (type !== undefined) {\n const parsed = ConventionalTypeSchema.safeParse(type);\n if (parsed.success) {\n commit.type = parsed.data;\n }\n }\n if (commitScope !== undefined) {\n commit.scope = commitScope || undefined;\n }\n if (body !== undefined) {\n commit.body = body || undefined;\n }\n\n plan.commits[commitIndex] = commit;\n await savePlan(ctx.cwd, plan, scope);\n\n // Plan content changed => previously applied state is stale.\n const appliedCacheKey = `${COMMIT_CACHE_PREFIX}plan-applied:${scope}`;\n await ctx.platform.cache.delete(appliedCacheKey);\n\n return {\n success: true,\n scope,\n commitId,\n };\n },\n});\n"]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as _kb_labs_shared_command_kit from '@kb-labs/shared-command-kit';
|
|
2
|
+
import { RestInput } from '@kb-labs/sdk';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* GET /plan handler
|
|
6
|
+
*
|
|
7
|
+
* Returns the current commit plan for Studio.
|
|
8
|
+
*/
|
|
9
|
+
declare const _default: _kb_labs_shared_command_kit.Handler<unknown, RestInput<{
|
|
10
|
+
scope?: string;
|
|
11
|
+
}, unknown, unknown>, {
|
|
12
|
+
scope: string;
|
|
13
|
+
hasPlan: boolean;
|
|
14
|
+
plan?: {
|
|
15
|
+
schemaVersion: "1.0";
|
|
16
|
+
createdAt: string;
|
|
17
|
+
repoRoot: string;
|
|
18
|
+
gitStatus: {
|
|
19
|
+
staged: string[];
|
|
20
|
+
unstaged: string[];
|
|
21
|
+
untracked: string[];
|
|
22
|
+
};
|
|
23
|
+
commits: {
|
|
24
|
+
message: string;
|
|
25
|
+
type: "feat" | "fix" | "refactor" | "chore" | "docs" | "test" | "build" | "ci" | "perf";
|
|
26
|
+
id: string;
|
|
27
|
+
files: string[];
|
|
28
|
+
releaseHint: "none" | "patch" | "minor" | "major";
|
|
29
|
+
breaking: boolean;
|
|
30
|
+
scope?: string | undefined;
|
|
31
|
+
body?: string | undefined;
|
|
32
|
+
reasoning?: {
|
|
33
|
+
newBehavior: boolean;
|
|
34
|
+
fixesBug: boolean;
|
|
35
|
+
internalOnly: boolean;
|
|
36
|
+
explanation: string;
|
|
37
|
+
confidence: number;
|
|
38
|
+
} | undefined;
|
|
39
|
+
}[];
|
|
40
|
+
metadata: {
|
|
41
|
+
totalFiles: number;
|
|
42
|
+
totalCommits: number;
|
|
43
|
+
llmUsed: boolean;
|
|
44
|
+
tokensUsed?: number | undefined;
|
|
45
|
+
escalated?: boolean | undefined;
|
|
46
|
+
};
|
|
47
|
+
} | undefined;
|
|
48
|
+
}>;
|
|
49
|
+
|
|
50
|
+
export { _default as default };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { defineHandler } from '@kb-labs/sdk';
|
|
2
|
+
import { loadPlan } from '@kb-labs/commit-core/storage';
|
|
3
|
+
|
|
4
|
+
// src/rest/handlers/plan-handler.ts
|
|
5
|
+
var plan_handler_default = defineHandler({
|
|
6
|
+
async execute(ctx, input) {
|
|
7
|
+
const scope = input.query?.scope || "root";
|
|
8
|
+
try {
|
|
9
|
+
const plan = await loadPlan(ctx.cwd, scope);
|
|
10
|
+
if (!plan || plan.commits.length === 0) {
|
|
11
|
+
return {
|
|
12
|
+
hasPlan: false,
|
|
13
|
+
scope
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
hasPlan: true,
|
|
18
|
+
plan,
|
|
19
|
+
scope
|
|
20
|
+
};
|
|
21
|
+
} catch (error) {
|
|
22
|
+
return {
|
|
23
|
+
hasPlan: false,
|
|
24
|
+
scope
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export { plan_handler_default as default };
|
|
31
|
+
//# sourceMappingURL=plan-handler.js.map
|
|
32
|
+
//# sourceMappingURL=plan-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/rest/handlers/plan-handler.ts"],"names":[],"mappings":";;;;AASA,IAAO,uBAAQ,aAAA,CAAc;AAAA,EAC3B,MAAM,OAAA,CAAQ,GAAA,EAAsB,KAAA,EAAsE;AACxG,IAAA,MAAM,KAAA,GAAQ,KAAA,CAAM,KAAA,EAAO,KAAA,IAAS,MAAA;AAEpC,IAAA,IAAI;AACF,MAAA,MAAM,IAAA,GAAO,MAAM,QAAA,CAAS,GAAA,CAAI,KAAK,KAAK,CAAA;AAE1C,MAAA,IAAI,CAAC,IAAA,IAAQ,IAAA,CAAK,OAAA,CAAQ,WAAW,CAAA,EAAG;AACtC,QAAA,OAAO;AAAA,UACL,OAAA,EAAS,KAAA;AAAA,UACT;AAAA,SACF;AAAA,MACF;AAEA,MAAA,OAAO;AAAA,QACL,OAAA,EAAS,IAAA;AAAA,QACT,IAAA;AAAA,QACA;AAAA,OACF;AAAA,IACF,SAAS,KAAA,EAAO;AACd,MAAA,OAAO;AAAA,QACL,OAAA,EAAS,KAAA;AAAA,QACT;AAAA,OACF;AAAA,IACF;AAAA,EACF;AACF,CAAC","file":"plan-handler.js","sourcesContent":["import { defineHandler, type PluginContextV3, type RestInput } from '@kb-labs/sdk';\nimport { loadPlan } from '@kb-labs/commit-core/storage';\nimport type { PlanResponse } from '@kb-labs/commit-contracts';\n\n/**\n * GET /plan handler\n *\n * Returns the current commit plan for Studio.\n */\nexport default defineHandler({\n async execute(ctx: PluginContextV3, input: RestInput<{ scope?: string }, unknown>): Promise<PlanResponse> {\n const scope = input.query?.scope || 'root';\n\n try {\n const plan = await loadPlan(ctx.cwd, scope);\n\n if (!plan || plan.commits.length === 0) {\n return {\n hasPlan: false,\n scope,\n };\n }\n\n return {\n hasPlan: true,\n plan,\n scope,\n };\n } catch (error) {\n return {\n hasPlan: false,\n scope,\n };\n }\n },\n});\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as _kb_labs_shared_command_kit from '@kb-labs/shared-command-kit';
|
|
2
|
+
import { RestInput } from '@kb-labs/sdk';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* POST /push handler
|
|
6
|
+
*
|
|
7
|
+
* Pushes commits to the remote repository.
|
|
8
|
+
* After successful push, saves plan to history and clears current plan.
|
|
9
|
+
*/
|
|
10
|
+
declare const _default: _kb_labs_shared_command_kit.Handler<unknown, RestInput<unknown, {
|
|
11
|
+
scope: string;
|
|
12
|
+
force: boolean;
|
|
13
|
+
remote: string;
|
|
14
|
+
}, unknown>, {
|
|
15
|
+
scope: string;
|
|
16
|
+
result: {
|
|
17
|
+
success: boolean;
|
|
18
|
+
remote: string;
|
|
19
|
+
branch: string;
|
|
20
|
+
commitsPushed: number;
|
|
21
|
+
error?: string | undefined;
|
|
22
|
+
};
|
|
23
|
+
}>;
|
|
24
|
+
|
|
25
|
+
export { _default as default };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { defineHandler, useConfig } from '@kb-labs/sdk';
|
|
2
|
+
import { resolveCommitConfig, COMMIT_CACHE_PREFIX } from '@kb-labs/commit-contracts';
|
|
3
|
+
import { pushCommits } from '@kb-labs/commit-core/applier';
|
|
4
|
+
import { loadPlan, saveToHistory, clearPlan } from '@kb-labs/commit-core/storage';
|
|
5
|
+
import * as path from 'path';
|
|
6
|
+
|
|
7
|
+
// src/rest/handlers/push-handler.ts
|
|
8
|
+
function resolveScopePath(baseCwd, scopeId = "root", scopes) {
|
|
9
|
+
const scopeDef = scopes?.find((s) => s.id === scopeId);
|
|
10
|
+
const relativePath = scopeDef?.path ?? (scopeId === "root" ? "." : scopeId);
|
|
11
|
+
return relativePath === "." ? baseCwd : path.join(baseCwd, relativePath);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// src/rest/handlers/push-handler.ts
|
|
15
|
+
var push_handler_default = defineHandler({
|
|
16
|
+
async execute(ctx, input) {
|
|
17
|
+
const { scope = "root", remote, force } = input.body ?? {};
|
|
18
|
+
const startTime = Date.now();
|
|
19
|
+
try {
|
|
20
|
+
const plan = await loadPlan(ctx.cwd, scope);
|
|
21
|
+
const fileConfig = await useConfig();
|
|
22
|
+
const config = resolveCommitConfig(fileConfig ?? {});
|
|
23
|
+
const scopeCwd = resolveScopePath(ctx.cwd, scope, config.scope?.scopes);
|
|
24
|
+
const result = await pushCommits(scopeCwd, { remote, force, scope });
|
|
25
|
+
if (result.success && plan) {
|
|
26
|
+
await saveToHistory(ctx.cwd, plan, {
|
|
27
|
+
success: true,
|
|
28
|
+
appliedCommits: [],
|
|
29
|
+
errors: []
|
|
30
|
+
}, scope);
|
|
31
|
+
await clearPlan(ctx.cwd, scope);
|
|
32
|
+
const appliedCacheKey = `${COMMIT_CACHE_PREFIX}plan-applied:${scope}`;
|
|
33
|
+
await ctx.platform.cache.delete(appliedCacheKey);
|
|
34
|
+
}
|
|
35
|
+
if (ctx.platform.analytics) {
|
|
36
|
+
if (result.success) {
|
|
37
|
+
await ctx.platform.analytics.track("commit.push.success", {
|
|
38
|
+
scope,
|
|
39
|
+
remote,
|
|
40
|
+
force,
|
|
41
|
+
commitsPushed: plan?.commits.length || 0,
|
|
42
|
+
durationMs: Date.now() - startTime
|
|
43
|
+
});
|
|
44
|
+
} else {
|
|
45
|
+
await ctx.platform.analytics.track("commit.push.failed", {
|
|
46
|
+
scope,
|
|
47
|
+
remote,
|
|
48
|
+
force,
|
|
49
|
+
error: result.error,
|
|
50
|
+
durationMs: Date.now() - startTime
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
result,
|
|
56
|
+
scope
|
|
57
|
+
};
|
|
58
|
+
} catch (error) {
|
|
59
|
+
if (ctx.platform.analytics) {
|
|
60
|
+
await ctx.platform.analytics.track("commit.push.error", {
|
|
61
|
+
scope,
|
|
62
|
+
remote,
|
|
63
|
+
force,
|
|
64
|
+
error: error instanceof Error ? error.message : String(error),
|
|
65
|
+
durationMs: Date.now() - startTime
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
throw new Error(`Failed to push commits: ${error}`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
export { push_handler_default as default };
|
|
74
|
+
//# sourceMappingURL=push-handler.js.map
|
|
75
|
+
//# sourceMappingURL=push-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/rest/handlers/scope-resolver.ts","../../../src/rest/handlers/push-handler.ts"],"names":[],"mappings":";;;;;;;AAaO,SAAS,gBAAA,CACd,OAAA,EACA,OAAA,GAAkB,MAAA,EAClB,MAAA,EACQ;AACR,EAAA,MAAM,WAAW,MAAA,EAAQ,IAAA,CAAK,CAAC,CAAA,KAAM,CAAA,CAAE,OAAO,OAAO,CAAA;AACrD,EAAA,MAAM,YAAA,GAAe,QAAA,EAAU,IAAA,KAAS,OAAA,KAAY,SAAS,GAAA,GAAM,OAAA,CAAA;AACnE,EAAA,OAAO,YAAA,KAAiB,GAAA,GAAM,OAAA,GAAe,IAAA,CAAA,IAAA,CAAK,SAAS,YAAY,CAAA;AACzE;;;ACHA,IAAO,uBAAQ,aAAA,CAAc;AAAA,EAC3B,MAAM,OAAA,CAAQ,GAAA,EAAsB,KAAA,EAA+D;AACjG,IAAA,MAAM,EAAE,QAAQ,MAAA,EAAQ,MAAA,EAAQ,OAAM,GAAI,KAAA,CAAM,QAAQ,EAAC;AACzD,IAAA,MAAM,SAAA,GAAY,KAAK,GAAA,EAAI;AAE3B,IAAA,IAAI;AAEF,MAAA,MAAM,IAAA,GAAO,MAAM,QAAA,CAAS,GAAA,CAAI,KAAK,KAAK,CAAA;AAG1C,MAAA,MAAM,UAAA,GAAa,MAAM,SAAA,EAAuC;AAChE,MAAA,MAAM,MAAA,GAAS,mBAAA,CAAoB,UAAA,IAAc,EAAE,CAAA;AACnD,MAAA,MAAM,WAAW,gBAAA,CAAiB,GAAA,CAAI,KAAK,KAAA,EAAO,MAAA,CAAO,OAAO,MAAM,CAAA;AAGtE,MAAA,MAAM,MAAA,GAAS,MAAM,WAAA,CAAY,QAA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EAAO;AAEd,MAAA,IAAI,GAAA,CAAI,SAAS,SAAA,EAAW;AAC1B,QAAA,MAAM,GAAA,CAAI,QAAA,CAAS,SAAA,CAAU,KAAA,CAAM,mBAAA,EAAqB;AAAA,UACtD,KAAA;AAAA,UACA,MAAA;AAAA,UACA,KAAA;AAAA,UACA,OAAO,KAAA,YAAiB,KAAA,GAAQ,KAAA,CAAM,OAAA,GAAU,OAAO,KAAK,CAAA;AAAA,UAC5D,UAAA,EAAY,IAAA,CAAK,GAAA,EAAI,GAAI;AAAA,SAC1B,CAAA;AAAA,MACH;AAEA,MAAA,MAAM,IAAI,KAAA,CAAM,CAAA,wBAAA,EAA2B,KAAK,CAAA,CAAE,CAAA;AAAA,IACpD;AAAA,EACF;AACF,CAAC","file":"push-handler.js","sourcesContent":["import * as path from 'node:path';\nimport type { CommitScope } from '@kb-labs/commit-contracts';\n\n/**\n * Resolves a scope id to an absolute filesystem path.\n *\n * Looks up the scope in the provided scopes array by id.\n * Falls back to treating the id as a relative path from baseCwd (legacy compat).\n *\n * @param baseCwd - Workspace root (ctx.cwd)\n * @param scopeId - Scope identifier, e.g. \"root\", \"public/kb-labs\"\n * @param scopes - Configured scopes from CommitPluginConfig.scope.scopes\n */\nexport function resolveScopePath(\n baseCwd: string,\n scopeId: string = 'root',\n scopes?: CommitScope[],\n): string {\n const scopeDef = scopes?.find((s) => s.id === scopeId);\n const relativePath = scopeDef?.path ?? (scopeId === 'root' ? '.' : scopeId);\n return relativePath === '.' ? baseCwd : path.join(baseCwd, relativePath);\n}\n","import { defineHandler, useConfig, type PluginContextV3, type RestInput } from '@kb-labs/sdk';\nimport {\n COMMIT_CACHE_PREFIX,\n type PushRequest,\n type PushResponse,\n type CommitPluginConfig,\n resolveCommitConfig,\n} from '@kb-labs/commit-contracts';\nimport { pushCommits } from '@kb-labs/commit-core/applier';\nimport { loadPlan, saveToHistory, clearPlan } from '@kb-labs/commit-core/storage';\nimport { resolveScopePath } from './scope-resolver';\n\n/**\n * POST /push handler\n *\n * Pushes commits to the remote repository.\n * After successful push, saves plan to history and clears current plan.\n */\nexport default defineHandler({\n async execute(ctx: PluginContextV3, input: RestInput<unknown, PushRequest>): Promise<PushResponse> {\n const { scope = 'root', remote, force } = input.body ?? {};\n const startTime = Date.now();\n\n try {\n // Load the plan before pushing (we'll need it for history)\n const plan = await loadPlan(ctx.cwd, scope);\n\n // Resolve scope to actual directory path\n const fileConfig = await useConfig<Partial<CommitPluginConfig>>();\n const config = resolveCommitConfig(fileConfig ?? {});\n const scopeCwd = resolveScopePath(ctx.cwd, scope, config.scope?.scopes);\n\n // Push commits (git runs FROM scopeCwd)\n const result = await pushCommits(scopeCwd, { remote, force, scope });\n\n // After successful push, save to history and clear the plan\n if (result.success && plan) {\n // Save to history with push result\n await saveToHistory(ctx.cwd, plan, {\n success: true,\n appliedCommits: [],\n errors: []\n }, scope);\n\n // Clear current plan\n await clearPlan(ctx.cwd, scope);\n\n // Clear applied status cache\n const appliedCacheKey = `${COMMIT_CACHE_PREFIX}plan-applied:${scope}`;\n await ctx.platform.cache.delete(appliedCacheKey);\n }\n\n // Track success/failure\n if (ctx.platform.analytics) {\n if (result.success) {\n await ctx.platform.analytics.track('commit.push.success', {\n scope,\n remote,\n force,\n commitsPushed: plan?.commits.length || 0,\n durationMs: Date.now() - startTime,\n });\n } else {\n await ctx.platform.analytics.track('commit.push.failed', {\n scope,\n remote,\n force,\n error: result.error,\n durationMs: Date.now() - startTime,\n });\n }\n }\n\n return {\n result,\n scope,\n };\n } catch (error) {\n // Track error\n if (ctx.platform.analytics) {\n await ctx.platform.analytics.track('commit.push.error', {\n scope,\n remote,\n force,\n error: error instanceof Error ? error.message : String(error),\n durationMs: Date.now() - startTime,\n });\n }\n\n throw new Error(`Failed to push commits: ${error}`);\n }\n },\n});\n"]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import * as _kb_labs_shared_command_kit from '@kb-labs/shared-command-kit';
|
|
2
|
+
import { RestInput } from '@kb-labs/sdk';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* POST /regenerate-commit handler
|
|
6
|
+
*
|
|
7
|
+
* Re-analyzes files from a single commit using LLM and replaces it in the plan.
|
|
8
|
+
* Uses Phase 2 approach (with diff context) for best results.
|
|
9
|
+
*/
|
|
10
|
+
declare const _default: _kb_labs_shared_command_kit.Handler<unknown, RestInput<unknown, {
|
|
11
|
+
scope: string;
|
|
12
|
+
commitId: string;
|
|
13
|
+
instruction?: string | undefined;
|
|
14
|
+
}, unknown>, {
|
|
15
|
+
scope: string;
|
|
16
|
+
success: boolean;
|
|
17
|
+
commitId: string;
|
|
18
|
+
commit?: {
|
|
19
|
+
message: string;
|
|
20
|
+
type: "feat" | "fix" | "refactor" | "chore" | "docs" | "test" | "build" | "ci" | "perf";
|
|
21
|
+
id: string;
|
|
22
|
+
files: string[];
|
|
23
|
+
releaseHint: "none" | "patch" | "minor" | "major";
|
|
24
|
+
breaking: boolean;
|
|
25
|
+
scope?: string | undefined;
|
|
26
|
+
body?: string | undefined;
|
|
27
|
+
reasoning?: {
|
|
28
|
+
newBehavior: boolean;
|
|
29
|
+
fixesBug: boolean;
|
|
30
|
+
internalOnly: boolean;
|
|
31
|
+
explanation: string;
|
|
32
|
+
confidence: number;
|
|
33
|
+
} | undefined;
|
|
34
|
+
} | undefined;
|
|
35
|
+
}>;
|
|
36
|
+
|
|
37
|
+
export { _default as default };
|