@oscharko-dev/keiko-tools 0.2.8 → 0.2.9

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.
Files changed (50) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/git-commit-intent-node.d.ts +7 -0
  3. package/dist/git-commit-intent-node.d.ts.map +1 -0
  4. package/dist/git-commit-intent-node.js +42 -0
  5. package/dist/git-merge-gateway.d.ts +95 -0
  6. package/dist/git-merge-gateway.d.ts.map +1 -0
  7. package/dist/git-merge-gateway.js +536 -0
  8. package/dist/git-merge-node.d.ts +17 -0
  9. package/dist/git-merge-node.d.ts.map +1 -0
  10. package/dist/git-merge-node.js +243 -0
  11. package/dist/git-mutation-adapter.d.ts +51 -0
  12. package/dist/git-mutation-adapter.d.ts.map +1 -0
  13. package/dist/git-mutation-adapter.js +207 -0
  14. package/dist/git-mutation-evidence.d.ts +23 -0
  15. package/dist/git-mutation-evidence.d.ts.map +1 -0
  16. package/dist/git-mutation-evidence.js +283 -0
  17. package/dist/git-mutation-node.d.ts +22 -0
  18. package/dist/git-mutation-node.d.ts.map +1 -0
  19. package/dist/git-mutation-node.js +145 -0
  20. package/dist/git-mutation-orchestrator.d.ts +92 -0
  21. package/dist/git-mutation-orchestrator.d.ts.map +1 -0
  22. package/dist/git-mutation-orchestrator.js +321 -0
  23. package/dist/git-mutation-preflight.d.ts +35 -0
  24. package/dist/git-mutation-preflight.d.ts.map +1 -0
  25. package/dist/git-mutation-preflight.js +226 -0
  26. package/dist/git-mutation-taxonomy.d.ts +15 -0
  27. package/dist/git-mutation-taxonomy.d.ts.map +1 -0
  28. package/dist/git-mutation-taxonomy.js +102 -0
  29. package/dist/git-pr-gateway.d.ts +101 -0
  30. package/dist/git-pr-gateway.d.ts.map +1 -0
  31. package/dist/git-pr-gateway.js +487 -0
  32. package/dist/git-pr-node.d.ts +17 -0
  33. package/dist/git-pr-node.d.ts.map +1 -0
  34. package/dist/git-pr-node.js +173 -0
  35. package/dist/git-publish-gateway.d.ts +72 -0
  36. package/dist/git-publish-gateway.d.ts.map +1 -0
  37. package/dist/git-publish-gateway.js +423 -0
  38. package/dist/git-publish-node.d.ts +17 -0
  39. package/dist/git-publish-node.d.ts.map +1 -0
  40. package/dist/git-publish-node.js +107 -0
  41. package/dist/git-worktree-adapter.d.ts +78 -0
  42. package/dist/git-worktree-adapter.d.ts.map +1 -0
  43. package/dist/git-worktree-adapter.js +300 -0
  44. package/dist/git-worktree-snapshot-node.d.ts +31 -0
  45. package/dist/git-worktree-snapshot-node.d.ts.map +1 -0
  46. package/dist/git-worktree-snapshot-node.js +189 -0
  47. package/dist/index.d.ts +9 -0
  48. package/dist/index.d.ts.map +1 -1
  49. package/dist/index.js +37 -0
  50. package/package.json +9 -5
@@ -0,0 +1,102 @@
1
+ // Orchestration-level lifecycle and failure taxonomy for governed Git writes
2
+ // (Issue #472, Epic #470). This module sits ABOVE the keiko-contracts git-delivery wire types.
3
+ //
4
+ // The contract layer (Issue #471) names two low-level vocabularies: execution error codes
5
+ // (`GitDeliveryExecutionErrorCode`) and policy block reasons (`GitDeliveryBlockReason`). This
6
+ // module names the orchestration-level concepts the contract layer deliberately left to the
7
+ // execution kernel:
8
+ //
9
+ // 1. The canonical, ordered LIFECYCLE PHASES every governed mutation advances through (AC1).
10
+ // 2. The five FAILURE CATEGORIES that approval UX, evidence capture, and recovery logic consume
11
+ // WITHOUT string parsing (AC4).
12
+ // 3. Deterministic, total mappings from the contract's low-level error codes to those categories,
13
+ // so later slices never re-derive severity from a free-form message.
14
+ //
15
+ // Pure module: type literals, frozen const tables, and total pure functions only. No IO, no clock,
16
+ // no randomness. Imports only type-level names from keiko-contracts. Relative imports end in ".js".
17
+ export const GIT_MUTATION_LIFECYCLE_PHASES = [
18
+ "resolve",
19
+ "preflight",
20
+ "preview",
21
+ "policy",
22
+ "execute",
23
+ "result",
24
+ ];
25
+ // Ordinal phase order. Higher ordinal = later in the lifecycle. Callers compare progress by ordinal
26
+ // (never by phase-name string) so "did execution start?" is `GIT_MUTATION_PHASE_ORDER[reached] >=
27
+ // GIT_MUTATION_PHASE_ORDER["execute"]`.
28
+ export const GIT_MUTATION_PHASE_ORDER = {
29
+ resolve: 0,
30
+ preflight: 1,
31
+ preview: 2,
32
+ policy: 3,
33
+ execute: 4,
34
+ result: 5,
35
+ };
36
+ export const GIT_MUTATION_FAILURE_CATEGORIES = [
37
+ "policy-block",
38
+ "preflight-block",
39
+ "execution-failure",
40
+ "provider-failure",
41
+ "recovery-required",
42
+ ];
43
+ export const GIT_MUTATION_STATUSES = [
44
+ "succeeded",
45
+ "approval-required",
46
+ "blocked",
47
+ "failed",
48
+ "recovery-required",
49
+ ];
50
+ // ─── Deterministic execution-error classification ───────────────────────────────────────
51
+ // Total mapping from the closed contract error-code union to a failure category. Keyed exhaustively
52
+ // so adding a new GitDeliveryExecutionErrorCode forces a compile error here (the Record is not
53
+ // Partial), guaranteeing every code has an explicit category and the kernel never falls back to a
54
+ // string heuristic.
55
+ //
56
+ // provider-rejected / network-failure → provider-failure (the remote refused or was unreachable)
57
+ // conflict / precondition-failed → recovery-required (a guided fix path exists; re-resolve)
58
+ // timeout / internal-error → execution-failure (transient or internal; safe to retry)
59
+ const EXECUTION_ERROR_CATEGORY = {
60
+ "provider-rejected": "provider-failure",
61
+ "network-failure": "provider-failure",
62
+ conflict: "recovery-required",
63
+ "precondition-failed": "recovery-required",
64
+ timeout: "execution-failure",
65
+ "internal-error": "execution-failure",
66
+ };
67
+ export function gitMutationCategoryForExecutionError(code) {
68
+ return EXECUTION_ERROR_CATEGORY[code];
69
+ }
70
+ // Classifies a finished adapter execution result. A `succeeded` / `partial` / `aborted` outcome with
71
+ // no error code is not a failure and returns undefined; otherwise the error code's category is
72
+ // returned. `partial` and `aborted` outcomes that DO carry an error code are classified by that
73
+ // code, so a partially-applied mutation that failed mid-flight is categorized rather than silently
74
+ // treated as success.
75
+ export function gitMutationCategoryForExecutionResult(result) {
76
+ if (result.outcome === "succeeded") {
77
+ return undefined;
78
+ }
79
+ if (result.errorCode === undefined) {
80
+ // `failed` with no code is an internal contract violation upstream; classify conservatively so
81
+ // the kernel never emits a failed result with no category.
82
+ return result.outcome === "failed" ? "execution-failure" : undefined;
83
+ }
84
+ return gitMutationCategoryForExecutionError(result.errorCode);
85
+ }
86
+ // True when a failure category should route into the guided recovery workflow rather than a plain
87
+ // retry. Only `recovery-required` does; the rest are retried or surfaced as a hard block/failure.
88
+ export function gitMutationFailureIsRecoverable(category) {
89
+ return category === "recovery-required";
90
+ }
91
+ // ─── Guards ─────────────────────────────────────────────────────────────────────────────
92
+ export function isGitMutationLifecyclePhase(value) {
93
+ return (typeof value === "string" &&
94
+ GIT_MUTATION_LIFECYCLE_PHASES.includes(value));
95
+ }
96
+ export function isGitMutationFailureCategory(value) {
97
+ return (typeof value === "string" &&
98
+ GIT_MUTATION_FAILURE_CATEGORIES.includes(value));
99
+ }
100
+ export function isGitMutationStatus(value) {
101
+ return typeof value === "string" && GIT_MUTATION_STATUSES.includes(value);
102
+ }
@@ -0,0 +1,101 @@
1
+ import type { GitDeliveryApprovalRequirement, GitDeliveryBlockReason, GitDeliveryExecutionResult, GitDeliveryOrgPolicyPack, GitDeliveryPolicyDecision, GitDeliveryProviderCapability, GitDeliveryRecoveryActionHint, GitDeliveryRecoveryDisposition, GitDeliveryRepoPolicyPack, GitPullRequestRejectionReason } from "@oscharko-dev/keiko-contracts";
2
+ import { gitPrRejectionToErrorCode } from "@oscharko-dev/keiko-contracts";
3
+ import type { CommandRule } from "@oscharko-dev/keiko-contracts";
4
+ import type { GitWorktreeSnapshot } from "./git-mutation-preflight.js";
5
+ import type { GitMutationLifecycleResult } from "./git-mutation-orchestrator.js";
6
+ export interface GitPrCreateCommand {
7
+ readonly kind: "pr-create";
8
+ readonly ownerAndRepo: string;
9
+ readonly headBranchName: string;
10
+ readonly baseBranchName: string;
11
+ readonly title: string;
12
+ readonly body: string;
13
+ readonly isDraft: boolean;
14
+ }
15
+ export interface GitPrUpdateCommand {
16
+ readonly kind: "pr-update";
17
+ readonly ownerAndRepo: string;
18
+ readonly prExternalId: string;
19
+ readonly headBranchName: string;
20
+ readonly baseBranchName: string;
21
+ readonly title: string;
22
+ readonly body: string;
23
+ readonly convertToDraft: boolean;
24
+ readonly convertFromDraft: boolean;
25
+ }
26
+ export type GitPullRequestCommand = GitPrCreateCommand | GitPrUpdateCommand;
27
+ export interface GitPrCreateExecRequest {
28
+ readonly ownerAndRepo: string;
29
+ readonly headBranchName: string;
30
+ readonly baseBranchName: string;
31
+ readonly title: string;
32
+ readonly body: string;
33
+ readonly isDraft: boolean;
34
+ }
35
+ export interface GitPrUpdateExecRequest {
36
+ readonly ownerAndRepo: string;
37
+ readonly prExternalId: string;
38
+ readonly baseBranchName: string;
39
+ readonly title: string;
40
+ readonly body: string;
41
+ readonly convertToDraft: boolean;
42
+ readonly convertFromDraft: boolean;
43
+ }
44
+ export interface GitPrExecResult extends GitDeliveryExecutionResult {
45
+ readonly rejectionReason?: GitPullRequestRejectionReason | undefined;
46
+ readonly createdPrExternalId?: string | undefined;
47
+ }
48
+ export interface GitPullRequestAdapter {
49
+ createPullRequest(req: GitPrCreateExecRequest): Promise<GitPrExecResult>;
50
+ updatePullRequest(req: GitPrUpdateExecRequest): Promise<GitPrExecResult>;
51
+ }
52
+ export declare const GIT_PULL_REQUEST_ALLOWED_SUBCOMMANDS: readonly string[];
53
+ export declare const GIT_PULL_REQUEST_COMMAND_RULES: readonly CommandRule[];
54
+ export declare class GitPrArgvError extends Error {
55
+ constructor(message: string);
56
+ }
57
+ export declare function buildPrCreateArgv(req: GitPrCreateExecRequest): readonly string[];
58
+ export declare function buildPrUpdateArgv(req: GitPrUpdateExecRequest): readonly string[];
59
+ export declare function buildPrMarkReadyGraphqlArgv(nodeId: string): readonly string[];
60
+ export declare function buildPrConvertDraftGraphqlArgv(nodeId: string): readonly string[];
61
+ export declare function gitPrArgvIsGoverned(argv: readonly string[]): boolean;
62
+ export declare function classifyGitPullRequestRejection(output: string): GitPullRequestRejectionReason;
63
+ export interface GitPullRequestRejection {
64
+ readonly reason: GitPullRequestRejectionReason;
65
+ readonly disposition: GitDeliveryRecoveryDisposition;
66
+ readonly actionHint?: GitDeliveryRecoveryActionHint | undefined;
67
+ }
68
+ export declare function gitPullRequestRejectionFor(reason: GitPullRequestRejectionReason): GitPullRequestRejection;
69
+ export interface GitPullRequestEffectivePolicy {
70
+ readonly outcome: "allowed" | "blocked" | "approval-gated";
71
+ readonly blockReason?: GitDeliveryBlockReason | undefined;
72
+ }
73
+ export declare function evaluateGitPullRequestEffectivePolicy(decision: GitDeliveryPolicyDecision, baseTarget: string | undefined, capabilities: readonly GitDeliveryProviderCapability[], actionKind: "pr-create" | "pr-update"): GitPullRequestEffectivePolicy;
74
+ export interface GitPullRequestRequest {
75
+ readonly command: GitPullRequestCommand;
76
+ readonly approval: GitDeliveryApprovalRequirement;
77
+ }
78
+ export interface GitPullRequestOrchestratorDeps {
79
+ readonly adapter: GitPullRequestAdapter;
80
+ readonly snapshot: GitWorktreeSnapshot;
81
+ readonly orgPolicyPack?: GitDeliveryOrgPolicyPack | undefined;
82
+ readonly repoPolicyPack?: GitDeliveryRepoPolicyPack | undefined;
83
+ readonly activeProviderCapabilities?: readonly GitDeliveryProviderCapability[] | undefined;
84
+ readonly now: () => number;
85
+ readonly newActionId: () => string;
86
+ }
87
+ export interface GitPullRequestLifecycleResult {
88
+ readonly lifecycle: GitMutationLifecycleResult;
89
+ readonly rejection?: GitPullRequestRejection | undefined;
90
+ readonly createdPrExternalId?: string | undefined;
91
+ }
92
+ /**
93
+ * Runs ONE governed pull request operation end-to-end: derive PR inputs → preflight (no local
94
+ * precondition) → preview → policy → (only when policy permits and any approval is satisfied) execute
95
+ * through the narrow PR adapter. Returns a kernel-shaped lifecycle result (so the #474 evidence builder
96
+ * records it unchanged) plus the live provider-rejection descriptor when the provider rejected the
97
+ * operation, and the provider-assigned PR number on a successful create.
98
+ */
99
+ export declare function runGitPullRequest(request: GitPullRequestRequest, deps: GitPullRequestOrchestratorDeps): Promise<GitPullRequestLifecycleResult>;
100
+ export { gitPrRejectionToErrorCode };
101
+ //# sourceMappingURL=git-pr-gateway.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git-pr-gateway.d.ts","sourceRoot":"","sources":["../src/git-pr-gateway.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAGV,8BAA8B,EAC9B,sBAAsB,EAEtB,0BAA0B,EAC1B,wBAAwB,EAExB,yBAAyB,EAGzB,6BAA6B,EAC7B,6BAA6B,EAC7B,8BAA8B,EAC9B,yBAAyB,EACzB,6BAA6B,EAC9B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAML,yBAAyB,EAC1B,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAEvE,OAAO,KAAK,EACV,0BAA0B,EAE3B,MAAM,gCAAgC,CAAC;AAWxC,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,cAA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