@kici-dev/compiler 0.0.0 → 0.1.2

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 (221) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +1 -6
  3. package/dist/assets/api-TJJVHrjC.json +118 -0
  4. package/dist/assets/descriptor-BTtjzN9L.json +1382 -0
  5. package/dist/assets/package-BpQF9kR8.json +74 -0
  6. package/dist/assets/package-Ceo2h27X.json +89 -0
  7. package/dist/assets/source_context-D0atuL28.json +20 -0
  8. package/dist/assets/type-BFqO8SCZ.json +202 -0
  9. package/dist/auth/headless-detect.d.ts +14 -0
  10. package/dist/auth/headless-detect.js +25 -0
  11. package/dist/chunk-gOLHoazu.js +4 -0
  12. package/dist/cli.d.ts +3 -0
  13. package/dist/cli.js +193 -0
  14. package/dist/commands/cancel.d.ts +22 -0
  15. package/dist/commands/cancel.js +124 -0
  16. package/dist/commands/compile.d.ts +17 -0
  17. package/dist/commands/compile.js +99 -0
  18. package/dist/commands/docs.d.ts +26 -0
  19. package/dist/commands/docs.js +60 -0
  20. package/dist/commands/drain-worker.d.ts +19 -0
  21. package/dist/commands/drain-worker.js +45 -0
  22. package/dist/commands/endpoints.d.ts +53 -0
  23. package/dist/commands/endpoints.js +185 -0
  24. package/dist/commands/fixture.d.ts +14 -0
  25. package/dist/commands/fixture.js +104 -0
  26. package/dist/commands/hook.d.ts +20 -0
  27. package/dist/commands/hook.js +97 -0
  28. package/dist/commands/index.d.ts +33 -0
  29. package/dist/commands/index.js +20 -0
  30. package/dist/commands/init.d.ts +35 -0
  31. package/dist/commands/init.js +393 -0
  32. package/dist/commands/login.d.ts +23 -0
  33. package/dist/commands/login.js +144 -0
  34. package/dist/commands/logout.d.ts +18 -0
  35. package/dist/commands/logout.js +55 -0
  36. package/dist/commands/org.d.ts +27 -0
  37. package/dist/commands/org.js +126 -0
  38. package/dist/commands/run.d.ts +21 -0
  39. package/dist/commands/run.js +562 -0
  40. package/dist/commands/secrets-list.d.ts +16 -0
  41. package/dist/commands/secrets-list.js +85 -0
  42. package/dist/commands/status.d.ts +30 -0
  43. package/dist/commands/status.js +210 -0
  44. package/dist/commands/test.d.ts +61 -0
  45. package/dist/commands/test.js +220 -0
  46. package/dist/commands/types.d.ts +18 -0
  47. package/dist/commands/types.js +74 -0
  48. package/dist/commands/watch.d.ts +14 -0
  49. package/dist/commands/watch.js +97 -0
  50. package/dist/commands/workflows.d.ts +28 -0
  51. package/dist/commands/workflows.js +154 -0
  52. package/dist/comment-created.json +30 -0
  53. package/dist/create-branch.json +17 -0
  54. package/dist/delete-branch.json +15 -0
  55. package/dist/dispatch.json +15 -0
  56. package/dist/errors/capability-gap.d.ts +50 -0
  57. package/dist/errors/capability-gap.js +54 -0
  58. package/dist/errors/codes.d.ts +25 -0
  59. package/dist/errors/formatter.d.ts +32 -0
  60. package/dist/errors/formatter.js +35 -0
  61. package/dist/errors/index.d.ts +5 -0
  62. package/dist/errors/index.js +4 -0
  63. package/dist/execution/executor.d.ts +61 -0
  64. package/dist/execution/executor.js +230 -0
  65. package/dist/execution/index.d.ts +4 -0
  66. package/dist/execution/index.js +3 -0
  67. package/dist/execution/sdk-alias.d.ts +33 -0
  68. package/dist/execution/sdk-alias.js +102 -0
  69. package/dist/fixtures/compiler.d.ts +47 -0
  70. package/dist/fixtures/compiler.js +177 -0
  71. package/dist/fixtures/defaults/comment-created.json +30 -0
  72. package/dist/fixtures/defaults/create-branch.json +17 -0
  73. package/dist/fixtures/defaults/delete-branch.json +15 -0
  74. package/dist/fixtures/defaults/dispatch.json +15 -0
  75. package/dist/fixtures/defaults/fork.json +19 -0
  76. package/dist/fixtures/defaults/index.d.ts +16 -0
  77. package/dist/fixtures/defaults/index.js +105 -0
  78. package/dist/fixtures/defaults/index.ts +145 -0
  79. package/dist/fixtures/defaults/pr-closed.json +28 -0
  80. package/dist/fixtures/defaults/pr-opened.json +27 -0
  81. package/dist/fixtures/defaults/pr-reopened.json +27 -0
  82. package/dist/fixtures/defaults/pr-synchronize.json +27 -0
  83. package/dist/fixtures/defaults/push.json +16 -0
  84. package/dist/fixtures/defaults/release-published.json +23 -0
  85. package/dist/fixtures/defaults/review-comment-created.json +36 -0
  86. package/dist/fixtures/defaults/review-submitted.json +35 -0
  87. package/dist/fixtures/defaults/star-created.json +15 -0
  88. package/dist/fixtures/defaults/status.json +26 -0
  89. package/dist/fixtures/defaults/tag-push.json +20 -0
  90. package/dist/fixtures/defaults/watch-started.json +15 -0
  91. package/dist/fixtures/defaults/workflow-run-completed.json +23 -0
  92. package/dist/fork.json +19 -0
  93. package/dist/format.d.ts +5 -0
  94. package/dist/format.js +20 -0
  95. package/dist/generators/secrets-dts.d.ts +29 -0
  96. package/dist/generators/secrets-dts.js +67 -0
  97. package/dist/hooks/detector.d.ts +39 -0
  98. package/dist/hooks/detector.js +133 -0
  99. package/dist/hooks/index.d.ts +6 -0
  100. package/dist/hooks/index.js +5 -0
  101. package/dist/hooks/installer.d.ts +24 -0
  102. package/dist/hooks/installer.js +328 -0
  103. package/dist/hooks/templates.d.ts +26 -0
  104. package/dist/hooks/templates.js +63 -0
  105. package/dist/index.d.ts +12 -0
  106. package/dist/index.js +12 -0
  107. package/dist/llm-context/llms-full.txt +9974 -0
  108. package/dist/llm-context/llms.txt +61 -0
  109. package/dist/local-executor/dag-scheduler.d.ts +44 -0
  110. package/dist/local-executor/dag-scheduler.js +183 -0
  111. package/dist/local-executor/index.d.ts +23 -0
  112. package/dist/local-executor/index.js +309 -0
  113. package/dist/local-executor/job-runner.d.ts +40 -0
  114. package/dist/local-executor/job-runner.js +307 -0
  115. package/dist/local-executor/output-streamer.d.ts +31 -0
  116. package/dist/local-executor/output-streamer.js +166 -0
  117. package/dist/local-executor/payload-generator.d.ts +16 -0
  118. package/dist/local-executor/payload-generator.js +138 -0
  119. package/dist/local-executor/picker.d.ts +33 -0
  120. package/dist/local-executor/picker.js +109 -0
  121. package/dist/local-executor/secret-loader.d.ts +18 -0
  122. package/dist/local-executor/secret-loader.js +105 -0
  123. package/dist/local-executor/types.d.ts +80 -0
  124. package/dist/local-executor/types.js +2 -0
  125. package/dist/local-executor/workflow-lock.d.ts +81 -0
  126. package/dist/local-executor/workflow-lock.js +0 -0
  127. package/dist/lockfile/generator.d.ts +39 -0
  128. package/dist/lockfile/generator.js +688 -0
  129. package/dist/lockfile/hash-files.d.ts +14 -0
  130. package/dist/lockfile/hash-files.js +50 -0
  131. package/dist/lockfile/hasher.d.ts +36 -0
  132. package/dist/lockfile/hasher.js +46 -0
  133. package/dist/lockfile/index.d.ts +3 -0
  134. package/dist/lockfile/index.js +4 -0
  135. package/dist/lockfile/purity-analyzer.d.ts +25 -0
  136. package/dist/lockfile/purity-analyzer.js +204 -0
  137. package/dist/package-F7UXSDHW.json +74 -0
  138. package/dist/postinstall.d.ts +9 -0
  139. package/dist/postinstall.js +60 -0
  140. package/dist/pr-closed.json +28 -0
  141. package/dist/pr-opened.json +27 -0
  142. package/dist/pr-reopened.json +27 -0
  143. package/dist/pr-synchronize.json +27 -0
  144. package/dist/push.json +16 -0
  145. package/dist/release-published.json +23 -0
  146. package/dist/remote/client.d.ts +204 -0
  147. package/dist/remote/client.js +203 -0
  148. package/dist/remote/config.d.ts +54 -0
  149. package/dist/remote/config.js +92 -0
  150. package/dist/remote/encryption.d.ts +35 -0
  151. package/dist/remote/encryption.js +87 -0
  152. package/dist/remote/history.d.ts +91 -0
  153. package/dist/remote/history.js +146 -0
  154. package/dist/remote/oauth.d.ts +65 -0
  155. package/dist/remote/oauth.js +302 -0
  156. package/dist/remote/observer.d.ts +81 -0
  157. package/dist/remote/observer.js +174 -0
  158. package/dist/remote/output/json.d.ts +13 -0
  159. package/dist/remote/output/json.js +36 -0
  160. package/dist/remote/output/junit.d.ts +18 -0
  161. package/dist/remote/output/junit.js +50 -0
  162. package/dist/remote/output/streaming.d.ts +57 -0
  163. package/dist/remote/output/streaming.js +124 -0
  164. package/dist/remote/output/summary.d.ts +39 -0
  165. package/dist/remote/output/summary.js +99 -0
  166. package/dist/remote/uploader.d.ts +87 -0
  167. package/dist/remote/uploader.js +197 -0
  168. package/dist/review-comment-created.json +36 -0
  169. package/dist/review-submitted.json +35 -0
  170. package/dist/star-created.json +15 -0
  171. package/dist/status.json +26 -0
  172. package/dist/tag-push.json +20 -0
  173. package/dist/templates/agents-md.d.ts +8 -0
  174. package/dist/templates/agents-md.js +130 -0
  175. package/dist/templates/index.d.ts +43 -0
  176. package/dist/templates/index.js +48 -0
  177. package/dist/templates/package-json.d.ts +18 -0
  178. package/dist/templates/package-json.js +34 -0
  179. package/dist/templates/tsconfig-json.d.ts +9 -0
  180. package/dist/templates/tsconfig-json.js +26 -0
  181. package/dist/templates/workflows/hello-world.d.ts +2 -0
  182. package/dist/templates/workflows/hello-world.js +16 -0
  183. package/dist/templates/workflows/hello-world.ts +21 -0
  184. package/dist/templates/workflows/pr-checks.d.ts +2 -0
  185. package/dist/templates/workflows/pr-checks.js +40 -0
  186. package/dist/templates/workflows/pr-checks.ts +57 -0
  187. package/dist/test-runner/dry-run.d.ts +12 -0
  188. package/dist/test-runner/dry-run.js +66 -0
  189. package/dist/test-runner/event-types.d.ts +86 -0
  190. package/dist/test-runner/event-types.js +330 -0
  191. package/dist/test-runner/git-detector.d.ts +15 -0
  192. package/dist/test-runner/git-detector.js +30 -0
  193. package/dist/test-runner/index.d.ts +13 -0
  194. package/dist/test-runner/index.js +11 -0
  195. package/dist/test-runner/job-executor.d.ts +48 -0
  196. package/dist/test-runner/job-executor.js +245 -0
  197. package/dist/test-runner/output-formatter.d.ts +47 -0
  198. package/dist/test-runner/output-formatter.js +92 -0
  199. package/dist/test-runner/payload-builder.d.ts +20 -0
  200. package/dist/test-runner/payload-builder.js +216 -0
  201. package/dist/test-runner/rule-evaluator.d.ts +14 -0
  202. package/dist/test-runner/rule-evaluator.js +31 -0
  203. package/dist/test-runner/secrets-file.d.ts +24 -0
  204. package/dist/test-runner/secrets-file.js +62 -0
  205. package/dist/test-runner/step-context.d.ts +15 -0
  206. package/dist/test-runner/step-context.js +140 -0
  207. package/dist/test-runner/summary.d.ts +7 -0
  208. package/dist/types.d.ts +525 -0
  209. package/dist/types.js +33 -0
  210. package/dist/validation/index.d.ts +3 -0
  211. package/dist/validation/index.js +3 -0
  212. package/dist/validation/validator.d.ts +26 -0
  213. package/dist/validation/validator.js +164 -0
  214. package/dist/watch-started.json +15 -0
  215. package/dist/workflow-run-completed.json +23 -0
  216. package/dist/workflows/hello-world.ts +21 -0
  217. package/dist/workflows/pr-checks.ts +57 -0
  218. package/hack/postinstall.mjs +105 -0
  219. package/package.json +60 -6
  220. package/sbom.spdx.json +10997 -0
  221. package/index.js +0 -3
@@ -0,0 +1,124 @@
1
+ import "../chunk-gOLHoazu.js";
2
+ import { loadGlobalConfig } from "../remote/config.js";
3
+ import pc from "picocolors";
4
+ import { logger, toErrorMessage } from "@kici-dev/shared";
5
+ //#region src/commands/cancel.ts
6
+ /**
7
+ * kici cancel command
8
+ *
9
+ * Cancels a specific run by ID, or all in-progress runs on a branch.
10
+ * Uses the Platform dashboard API (PAT auth) or orchestrator API (direct mode).
11
+ */
12
+ /**
13
+ * Cancel a run or all runs on a branch.
14
+ *
15
+ * @param runId - Run ID to cancel (optional if --branch is provided)
16
+ * @param options - Cancel options
17
+ * @returns true on success, false on error
18
+ */
19
+ async function cancelCommand(runId, options = {}) {
20
+ try {
21
+ const config = await loadGlobalConfig();
22
+ const token = config.pat ?? config.token;
23
+ if (!token) {
24
+ logger.error(pc.red("Not authenticated. Run `kici login` to get started."));
25
+ return false;
26
+ }
27
+ const endpoint = config.platformEndpoint ?? config.endpoint;
28
+ if (!endpoint) {
29
+ logger.error(pc.red("No endpoint configured. Run `kici login` to configure."));
30
+ return false;
31
+ }
32
+ if (options.branch) return await cancelByBranch(endpoint, token, config.activeOrgId, options.branch);
33
+ if (!runId) {
34
+ logger.error(pc.red("Please provide a run ID or use --branch to cancel by branch."));
35
+ return false;
36
+ }
37
+ return await cancelRun(endpoint, token, config.activeOrgId, runId, options.force ?? false);
38
+ } catch (error) {
39
+ const message = toErrorMessage(error);
40
+ logger.error(pc.red(`Error: ${message}`));
41
+ return false;
42
+ }
43
+ }
44
+ /**
45
+ * Cancel a specific run by ID.
46
+ */
47
+ async function cancelRun(endpoint, token, orgId, runId, force) {
48
+ if (!orgId) {
49
+ logger.error(pc.red("No active organization. Run `kici org use <name>` to set one."));
50
+ return false;
51
+ }
52
+ const action = force ? "Force-cancelling" : "Cancelling";
53
+ logger.info(`${action} run ${pc.cyan(runId)}...`);
54
+ const url = `${endpoint}/api/v1/orgs/${orgId}/runs/${runId}/cancel`;
55
+ const response = await fetch(url, {
56
+ method: "POST",
57
+ headers: {
58
+ "Content-Type": "application/json",
59
+ Authorization: `Bearer ${token}`
60
+ },
61
+ body: JSON.stringify({ force })
62
+ });
63
+ if (response.ok) {
64
+ const jobs = (await response.json()).cancelledJobs ?? 0;
65
+ logger.info(pc.green(`Run ${runId} cancelled (${jobs} job${jobs !== 1 ? "s" : ""} affected).`));
66
+ return true;
67
+ }
68
+ return handleApiError(response, runId);
69
+ }
70
+ /**
71
+ * Cancel all in-progress runs on a branch.
72
+ */
73
+ async function cancelByBranch(endpoint, token, orgId, branch) {
74
+ if (!orgId) {
75
+ logger.error(pc.red("No active organization. Run `kici org use <name>` to set one."));
76
+ return false;
77
+ }
78
+ logger.info(`Cancelling all in-progress runs on branch ${pc.cyan(branch)}...`);
79
+ const url = `${endpoint}/api/v1/orgs/${orgId}/runs/cancel-by-branch`;
80
+ const response = await fetch(url, {
81
+ method: "POST",
82
+ headers: {
83
+ "Content-Type": "application/json",
84
+ Authorization: `Bearer ${token}`
85
+ },
86
+ body: JSON.stringify({ branch })
87
+ });
88
+ if (response.ok) {
89
+ const runs = (await response.json()).cancelledRuns ?? 0;
90
+ if (runs === 0) logger.info(pc.yellow(`No in-progress runs found on branch ${branch}.`));
91
+ else logger.info(pc.green(`Cancelled ${runs} run${runs !== 1 ? "s" : ""} on branch ${branch}.`));
92
+ return true;
93
+ }
94
+ return handleApiError(response);
95
+ }
96
+ /**
97
+ * Handle API error responses with clear user-facing messages.
98
+ */
99
+ async function handleApiError(response, runId) {
100
+ let errorDetail;
101
+ try {
102
+ errorDetail = (await response.json()).error;
103
+ } catch {}
104
+ switch (response.status) {
105
+ case 401:
106
+ logger.error(pc.red("Authentication failed. Run `kici login` to re-authenticate."));
107
+ break;
108
+ case 403:
109
+ logger.error(pc.red(`Access denied${errorDetail ? `: ${errorDetail}` : ""}.`));
110
+ break;
111
+ case 404:
112
+ logger.error(pc.red(`Run not found${runId ? `: ${runId}` : ""}.`));
113
+ break;
114
+ case 409:
115
+ logger.error(pc.yellow(errorDetail ?? `Run ${runId ?? ""} is already in a terminal state.`));
116
+ break;
117
+ default: logger.error(pc.red(errorDetail ?? `Request failed with status ${response.status}.`));
118
+ }
119
+ return false;
120
+ }
121
+ //#endregion
122
+ export { cancelCommand };
123
+
124
+ //# sourceMappingURL=cancel.js.map
@@ -0,0 +1,17 @@
1
+ /** Options for the compile command */
2
+ export interface CompileOptions {
3
+ /** Path to .kici directory (defaults to .kici) */
4
+ kiciDir?: string;
5
+ /** Validate only, don't write lock file */
6
+ check: boolean;
7
+ /** Verbose output */
8
+ verbose: boolean;
9
+ }
10
+ /**
11
+ * Execute the compile command.
12
+ *
13
+ * @param options - Command options
14
+ * @returns true if successful, false if errors
15
+ */
16
+ export declare function compileCommand(options: CompileOptions): Promise<boolean>;
17
+ //# sourceMappingURL=compile.d.ts.map
@@ -0,0 +1,99 @@
1
+ import "../chunk-gOLHoazu.js";
2
+ import { formatError, isCompilerError } from "../errors/formatter.js";
3
+ import "../errors/index.js";
4
+ import { discoverWorkflows, resolveKiciDir } from "../execution/executor.js";
5
+ import "../execution/index.js";
6
+ import { validateConfig } from "../validation/validator.js";
7
+ import "../validation/index.js";
8
+ import { computeLockfileHash, detectGitRoot, generateLockFile, serializeLockFile } from "../lockfile/generator.js";
9
+ import "../lockfile/index.js";
10
+ import pc from "picocolors";
11
+ import { existsSync } from "node:fs";
12
+ import fs from "node:fs/promises";
13
+ import path from "node:path";
14
+ import { execSync } from "node:child_process";
15
+ import { logger, toErrorMessage } from "@kici-dev/shared";
16
+ //#region src/commands/compile.ts
17
+ /**
18
+ * Read the existing lock file and return its lockfileHash, if present.
19
+ */
20
+ async function readExistingLockfileHash(lockPath) {
21
+ try {
22
+ const content = await fs.readFile(lockPath, "utf-8");
23
+ return JSON.parse(content).lockfileHash ?? void 0;
24
+ } catch {
25
+ return;
26
+ }
27
+ }
28
+ /**
29
+ * Reinstall dependencies in .kici/ using npm.
30
+ */
31
+ async function reinstallDeps(kiciDir) {
32
+ if (existsSync(path.join(kiciDir, "package-lock.json"))) {
33
+ logger.info("Running " + pc.cyan("npm ci") + ` in ${kiciDir}`);
34
+ execSync("npm ci", {
35
+ cwd: kiciDir,
36
+ stdio: "inherit"
37
+ });
38
+ } else {
39
+ logger.info("Running " + pc.cyan("npm install") + ` in ${kiciDir}`);
40
+ execSync("npm install", {
41
+ cwd: kiciDir,
42
+ stdio: "inherit"
43
+ });
44
+ }
45
+ }
46
+ /**
47
+ * Execute the compile command.
48
+ *
49
+ * @param options - Command options
50
+ * @returns true if successful, false if errors
51
+ */
52
+ async function compileCommand(options) {
53
+ const kiciDir = options.kiciDir ?? ".kici";
54
+ const absoluteKiciDir = resolveKiciDir(kiciDir);
55
+ if (options.verbose) logger.debug(pc.dim(`Discovering workflows from ${absoluteKiciDir}/workflows/...`));
56
+ try {
57
+ const lockPath = path.join(absoluteKiciDir, "kici.lock.json");
58
+ const existingHash = await readExistingLockfileHash(lockPath);
59
+ if (existingHash) {
60
+ const currentHash = computeLockfileHash(detectGitRoot());
61
+ if (currentHash && currentHash !== existingHash) {
62
+ logger.info(pc.yellow("Dependencies changed") + " — reinstalling before compile...");
63
+ await reinstallDeps(absoluteKiciDir);
64
+ }
65
+ }
66
+ const { workflows: workflowsWithSource, workflowDir } = await discoverWorkflows(absoluteKiciDir);
67
+ if (options.verbose) logger.debug(pc.dim(`Found ${workflowsWithSource.length} workflow(s) in ${workflowDir}`));
68
+ const validation = validateConfig(workflowsWithSource.map((w) => w.workflow), workflowDir);
69
+ if (!validation.valid) {
70
+ for (const error of validation.errors) logger.error(formatError(error));
71
+ return false;
72
+ }
73
+ if (options.verbose) logger.debug(pc.dim("Validation passed"));
74
+ const lockJson = serializeLockFile(generateLockFile(workflowsWithSource));
75
+ if (!options.check) {
76
+ await fs.writeFile(lockPath, lockJson, "utf-8");
77
+ logger.info(pc.green("✓") + ` Compiled workflows → .kici/kici.lock.json` + pc.dim(` (${workflowsWithSource.length} workflow${workflowsWithSource.length !== 1 ? "s" : ""})`));
78
+ try {
79
+ const { loadGlobalConfig } = await import("../remote/config.js");
80
+ const config = await loadGlobalConfig();
81
+ if (config.token && config.endpoint) {
82
+ const { typesCommand } = await import("./types.js");
83
+ await typesCommand({ kiciDir });
84
+ }
85
+ } catch {
86
+ logger.warn(pc.yellow("Could not refresh types (orchestrator unreachable). Compilation succeeded."));
87
+ }
88
+ } else logger.info(pc.green("✓") + ` Workflows are valid` + pc.dim(` (${workflowsWithSource.length} workflow${workflowsWithSource.length !== 1 ? "s" : ""})`));
89
+ return true;
90
+ } catch (error) {
91
+ if (isCompilerError(error)) logger.error(formatError(error));
92
+ else logger.error(pc.red("error") + `: ${toErrorMessage(error)}`);
93
+ return false;
94
+ }
95
+ }
96
+ //#endregion
97
+ export { compileCommand };
98
+
99
+ //# sourceMappingURL=compile.js.map
@@ -0,0 +1,26 @@
1
+ export interface DocsOptions {
2
+ /** Open the docs site in the default browser. */
3
+ open?: boolean;
4
+ }
5
+ export interface DocsLlmOptions {
6
+ /** Print only the llms.txt index instead of the full markdown bundle. */
7
+ index?: boolean;
8
+ /** Override the bundled output destination (overrides default stdout). */
9
+ out?: string;
10
+ /** Override the directory holding llms.txt + llms-full.txt (test seam). */
11
+ bundleDir?: string;
12
+ }
13
+ /**
14
+ * Open the published documentation site in the user's default browser.
15
+ */
16
+ export declare function docsCommand(options?: DocsOptions): Promise<boolean>;
17
+ /**
18
+ * Print the bundled llms.txt or llms-full.txt content to stdout (or a file).
19
+ *
20
+ * The bundle is generated at build time by hack/postbuild.mjs and shipped at
21
+ * dist/llm-context/{llms.txt,llms-full.txt}. Customer-facing LLM tools can
22
+ * pipe `kici docs llm` straight into an Anthropic / OpenAI context buffer to
23
+ * brief the agent on KiCI authoring conventions without an internet round-trip.
24
+ */
25
+ export declare function docsLlmCommand(options?: DocsLlmOptions): Promise<boolean>;
26
+ //# sourceMappingURL=docs.d.ts.map
@@ -0,0 +1,60 @@
1
+ import "../chunk-gOLHoazu.js";
2
+ import pc from "picocolors";
3
+ import { readFile, writeFile } from "node:fs/promises";
4
+ import path from "node:path";
5
+ import { logger, toErrorMessage } from "@kici-dev/shared";
6
+ import { fileURLToPath } from "node:url";
7
+ import open from "open";
8
+ //#region src/commands/docs.ts
9
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
10
+ const DOCS_HOME_URL = "https://kici.dev/docs/";
11
+ /**
12
+ * Open the published documentation site in the user's default browser.
13
+ */
14
+ async function docsCommand(options = {}) {
15
+ try {
16
+ if (options.open === false) {
17
+ logger.info(DOCS_HOME_URL);
18
+ return true;
19
+ }
20
+ logger.info(pc.gray(`Opening ${DOCS_HOME_URL}`));
21
+ await open(DOCS_HOME_URL);
22
+ return true;
23
+ } catch (error) {
24
+ logger.error(pc.red(`Error: ${toErrorMessage(error)}`));
25
+ logger.info(pc.gray(`Visit ${DOCS_HOME_URL} manually.`));
26
+ return false;
27
+ }
28
+ }
29
+ /**
30
+ * Print the bundled llms.txt or llms-full.txt content to stdout (or a file).
31
+ *
32
+ * The bundle is generated at build time by hack/postbuild.mjs and shipped at
33
+ * dist/llm-context/{llms.txt,llms-full.txt}. Customer-facing LLM tools can
34
+ * pipe `kici docs llm` straight into an Anthropic / OpenAI context buffer to
35
+ * brief the agent on KiCI authoring conventions without an internet round-trip.
36
+ */
37
+ async function docsLlmCommand(options = {}) {
38
+ const filename = options.index ? "llms.txt" : "llms-full.txt";
39
+ const bundleDir = options.bundleDir ?? path.join(__dirname, "..", "llm-context");
40
+ const bundlePath = path.join(bundleDir, filename);
41
+ try {
42
+ const content = await readFile(bundlePath, "utf-8");
43
+ if (options.out) {
44
+ await writeFile(options.out, content, "utf-8");
45
+ logger.info(pc.gray(`Wrote ${filename} to ${options.out}`));
46
+ return true;
47
+ }
48
+ process.stdout.write(content);
49
+ if (!content.endsWith("\n")) process.stdout.write("\n");
50
+ return true;
51
+ } catch (error) {
52
+ logger.error(pc.red(`Error reading bundled ${filename}: ${toErrorMessage(error)}`));
53
+ logger.info(pc.gray("The bundle ships with the @kici-dev/compiler package. If you built the package locally, run `pnpm build` in packages/compiler/."));
54
+ return false;
55
+ }
56
+ }
57
+ //#endregion
58
+ export { docsCommand, docsLlmCommand };
59
+
60
+ //# sourceMappingURL=docs.js.map
@@ -0,0 +1,19 @@
1
+ /**
2
+ * kici admin drain-worker command
3
+ *
4
+ * Sends POST /drain to a worker instance to trigger graceful drain.
5
+ * Part of the three drain mechanisms: SIGTERM, POST /drain, admin CLI.
6
+ */
7
+ /** Options for the drain-worker command */
8
+ export interface DrainWorkerOptions {
9
+ /** Worker URL (e.g., http://worker-host:<port>) */
10
+ url: string;
11
+ }
12
+ /**
13
+ * Send a drain request to a worker instance.
14
+ *
15
+ * @param options - Drain worker options
16
+ * @returns true on success, false on error
17
+ */
18
+ export declare function drainWorkerCommand(options: DrainWorkerOptions): Promise<boolean>;
19
+ //# sourceMappingURL=drain-worker.d.ts.map
@@ -0,0 +1,45 @@
1
+ import "../chunk-gOLHoazu.js";
2
+ import pc from "picocolors";
3
+ import { logger, toErrorMessage } from "@kici-dev/shared";
4
+ //#region src/commands/drain-worker.ts
5
+ /**
6
+ * kici admin drain-worker command
7
+ *
8
+ * Sends POST /drain to a worker instance to trigger graceful drain.
9
+ * Part of the three drain mechanisms: SIGTERM, POST /drain, admin CLI.
10
+ */
11
+ /**
12
+ * Send a drain request to a worker instance.
13
+ *
14
+ * @param options - Drain worker options
15
+ * @returns true on success, false on error
16
+ */
17
+ async function drainWorkerCommand(options) {
18
+ const { url } = options;
19
+ if (!url) {
20
+ logger.error(pc.red("--url is required. Specify the worker URL (e.g., http://worker-host:<port>)."));
21
+ return false;
22
+ }
23
+ try {
24
+ const drainUrl = `${url.replace(/\/$/, "")}/drain`;
25
+ const response = await fetch(drainUrl, {
26
+ method: "POST",
27
+ headers: { "Content-Type": "application/json" }
28
+ });
29
+ if (!response.ok) {
30
+ logger.error(pc.red(`Drain request failed: ${response.status} ${response.statusText}`));
31
+ return false;
32
+ }
33
+ const data = await response.json();
34
+ logger.info(pc.green(`Worker draining. Active jobs: ${data.activeJobs}`));
35
+ return true;
36
+ } catch (error) {
37
+ const message = toErrorMessage(error);
38
+ logger.error(pc.red(`Failed to connect to worker at ${url}: ${message}`));
39
+ return false;
40
+ }
41
+ }
42
+ //#endregion
43
+ export { drainWorkerCommand };
44
+
45
+ //# sourceMappingURL=drain-worker.js.map
@@ -0,0 +1,53 @@
1
+ /**
2
+ * kici endpoints command
3
+ *
4
+ * Lists all webhook entrypoints for the current project, grouped by type.
5
+ * Reads the compiled lock file to enumerate trigger types and displays
6
+ * webhook URLs that developers can paste into external service configurations.
7
+ */
8
+ import type { LockWorkflow } from '../types.js';
9
+ export interface EndpointsOptions {
10
+ /** Path to .kici directory (defaults to .kici) */
11
+ kiciDir?: string;
12
+ }
13
+ interface TriggerGroup {
14
+ gitProvider: Array<{
15
+ workflowName: string;
16
+ provider: string;
17
+ }>;
18
+ genericWebhook: Array<{
19
+ workflowName: string;
20
+ source: string;
21
+ path?: string;
22
+ }>;
23
+ schedule: Array<{
24
+ workflowName: string;
25
+ cron: string;
26
+ timezone: string;
27
+ description?: string;
28
+ }>;
29
+ lifecycle: Array<{
30
+ workflowName: string;
31
+ events: readonly string[];
32
+ description?: string;
33
+ }>;
34
+ kiciEvent: Array<{
35
+ workflowName: string;
36
+ eventName: string;
37
+ }>;
38
+ }
39
+ /**
40
+ * Main endpoints command entry point.
41
+ * Reads the lock file and displays all webhook entrypoints grouped by type.
42
+ */
43
+ export declare function endpointsCommand(options: EndpointsOptions): Promise<boolean>;
44
+ /**
45
+ * Group all workflow triggers by their type category.
46
+ */
47
+ export declare function groupTriggers(workflows: readonly LockWorkflow[]): TriggerGroup;
48
+ /**
49
+ * Display the grouped endpoints in a human-readable format.
50
+ */
51
+ export declare function displayEndpoints(groups: TriggerGroup, orgId: string): void;
52
+ export {};
53
+ //# sourceMappingURL=endpoints.d.ts.map
@@ -0,0 +1,185 @@
1
+ import "../chunk-gOLHoazu.js";
2
+ import { resolveKiciDir } from "../execution/executor.js";
3
+ import "../execution/index.js";
4
+ import { loadGlobalConfig } from "../remote/config.js";
5
+ import pc from "picocolors";
6
+ import { readFile } from "node:fs/promises";
7
+ import path from "node:path";
8
+ import { logger, toErrorMessage } from "@kici-dev/shared";
9
+ //#region src/commands/endpoints.ts
10
+ /**
11
+ * kici endpoints command
12
+ *
13
+ * Lists all webhook entrypoints for the current project, grouped by type.
14
+ * Reads the compiled lock file to enumerate trigger types and displays
15
+ * webhook URLs that developers can paste into external service configurations.
16
+ */
17
+ /**
18
+ * Main endpoints command entry point.
19
+ * Reads the lock file and displays all webhook entrypoints grouped by type.
20
+ */
21
+ async function endpointsCommand(options) {
22
+ try {
23
+ const kiciDir = resolveKiciDir(options.kiciDir);
24
+ const lockFilePath = path.join(kiciDir, "kici.lock.json");
25
+ let lockFile;
26
+ try {
27
+ const content = await readFile(lockFilePath, "utf-8");
28
+ lockFile = JSON.parse(content);
29
+ } catch {
30
+ logger.error(pc.red("No lock file found. Run `kici compile` to generate kici.lock.json first."));
31
+ return false;
32
+ }
33
+ const orgId = (await loadGlobalConfig()).activeOrgId ?? "{orgId}";
34
+ displayEndpoints(groupTriggers(lockFile.workflows), orgId);
35
+ return true;
36
+ } catch (error) {
37
+ const message = toErrorMessage(error);
38
+ logger.error(pc.red(`Error: ${message}`));
39
+ return false;
40
+ }
41
+ }
42
+ /**
43
+ * Group all workflow triggers by their type category.
44
+ */
45
+ function groupTriggers(workflows) {
46
+ const groups = {
47
+ gitProvider: [],
48
+ genericWebhook: [],
49
+ schedule: [],
50
+ lifecycle: [],
51
+ kiciEvent: []
52
+ };
53
+ for (const workflow of workflows) for (const trigger of workflow.triggers) categorizeTrigger(workflow.name, trigger, groups);
54
+ return groups;
55
+ }
56
+ /**
57
+ * Categorize a single trigger into the appropriate group.
58
+ */
59
+ function categorizeTrigger(workflowName, trigger, groups) {
60
+ switch (trigger._type) {
61
+ case "pr":
62
+ case "push":
63
+ case "tag":
64
+ case "comment":
65
+ case "review":
66
+ case "review_comment":
67
+ case "release":
68
+ case "dispatch":
69
+ case "create":
70
+ case "delete":
71
+ case "status":
72
+ case "workflow_run":
73
+ case "fork":
74
+ case "star":
75
+ case "watch":
76
+ case "webhook":
77
+ if (!groups.gitProvider.some((g) => g.workflowName === workflowName)) groups.gitProvider.push({
78
+ workflowName,
79
+ provider: "GitHub"
80
+ });
81
+ break;
82
+ case "generic_webhook":
83
+ groups.genericWebhook.push({
84
+ workflowName,
85
+ source: trigger.source,
86
+ path: trigger.path
87
+ });
88
+ break;
89
+ case "schedule":
90
+ groups.schedule.push({
91
+ workflowName,
92
+ cron: trigger.cronExpression,
93
+ timezone: trigger.timezone,
94
+ description: trigger.description
95
+ });
96
+ break;
97
+ case "lifecycle":
98
+ groups.lifecycle.push({
99
+ workflowName,
100
+ events: trigger.events,
101
+ description: trigger.description
102
+ });
103
+ break;
104
+ case "kici_event":
105
+ groups.kiciEvent.push({
106
+ workflowName,
107
+ eventName: trigger.eventName
108
+ });
109
+ break;
110
+ case "workflow_complete":
111
+ groups.kiciEvent.push({
112
+ workflowName,
113
+ eventName: `workflow_complete${trigger.name ? `:${trigger.name}` : ""}`
114
+ });
115
+ break;
116
+ case "job_complete":
117
+ groups.kiciEvent.push({
118
+ workflowName,
119
+ eventName: `job_complete${trigger.workflow ? `:${trigger.workflow}` : ""}${trigger.job ? `.${trigger.job}` : ""}`
120
+ });
121
+ break;
122
+ }
123
+ }
124
+ /**
125
+ * Display the grouped endpoints in a human-readable format.
126
+ */
127
+ function displayEndpoints(groups, orgId) {
128
+ let hasOutput = false;
129
+ let hasWebhookUrls = false;
130
+ if (groups.gitProvider.length > 0) {
131
+ hasOutput = true;
132
+ hasWebhookUrls = true;
133
+ logger.info(pc.bold("\nGit provider webhooks:"));
134
+ const providers = [...new Set(groups.gitProvider.map((g) => g.provider))];
135
+ for (const provider of providers) {
136
+ const urlPath = `/webhook/${orgId}/${provider.toLowerCase()}`;
137
+ logger.info(` ${pc.cyan(provider + ":")} ${urlPath}`);
138
+ }
139
+ }
140
+ if (groups.genericWebhook.length > 0) {
141
+ hasOutput = true;
142
+ hasWebhookUrls = true;
143
+ logger.info(pc.bold("\nGeneric webhooks:"));
144
+ const seen = /* @__PURE__ */ new Set();
145
+ for (const gw of groups.genericWebhook) {
146
+ if (seen.has(gw.source)) continue;
147
+ seen.add(gw.source);
148
+ const urlPath = `/webhook/${orgId}/generic/${gw.source}`;
149
+ logger.info(` ${pc.cyan((gw.source + ":").padEnd(16))} ${urlPath}`);
150
+ }
151
+ }
152
+ if (groups.schedule.length > 0) {
153
+ hasOutput = true;
154
+ logger.info(pc.bold("\nScheduled workflows:"));
155
+ for (const s of groups.schedule) {
156
+ const tz = s.timezone !== "UTC" ? ` (${s.timezone})` : " (UTC)";
157
+ const label = s.description ?? s.workflowName;
158
+ logger.info(` ${pc.cyan((label + ":").padEnd(24))} "${s.cron}"${tz}`);
159
+ }
160
+ }
161
+ const eventDriven = [...groups.lifecycle.map((l) => ({
162
+ workflowName: l.workflowName,
163
+ description: l.description ?? l.workflowName,
164
+ listensFor: `lifecycle (${l.events.join(", ")})`
165
+ })), ...groups.kiciEvent.map((k) => ({
166
+ workflowName: k.workflowName,
167
+ description: k.workflowName,
168
+ listensFor: `kici_event (${k.eventName})`
169
+ }))];
170
+ if (eventDriven.length > 0) {
171
+ hasOutput = true;
172
+ logger.info(pc.bold("\nEvent-driven workflows:"));
173
+ for (const e of eventDriven) logger.info(` ${pc.cyan((e.description + ":").padEnd(24))} listens for: ${e.listensFor}`);
174
+ }
175
+ if (!hasOutput) {
176
+ logger.info(pc.yellow("\nNo webhook entrypoints found in the lock file."));
177
+ logger.info(pc.gray("Add triggers to your workflows and run `kici compile` to generate endpoints."));
178
+ }
179
+ if (hasWebhookUrls && orgId === "{orgId}") logger.info(pc.gray("\nHint: Run `kici login` and `kici org use <name>` to resolve the {orgId} placeholder."));
180
+ logger.info("");
181
+ }
182
+ //#endregion
183
+ export { displayEndpoints, endpointsCommand, groupTriggers };
184
+
185
+ //# sourceMappingURL=endpoints.js.map
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Fixture generation command
3
+ *
4
+ * Generates JSON fixture templates for all supported event types,
5
+ * including internal events (schedule, lifecycle, generic_webhook, kici_event).
6
+ */
7
+ export interface FixtureOptions {
8
+ output?: string;
9
+ }
10
+ /**
11
+ * Generate fixture template for event type
12
+ */
13
+ export declare function fixtureCommand(event: string, options: FixtureOptions): Promise<void>;
14
+ //# sourceMappingURL=fixture.d.ts.map