@kici-dev/compiler 0.0.0 → 0.1.1

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 +61 -5
  220. package/sbom.spdx.json +10997 -0
  221. package/index.js +0 -3
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Summary of files included in the overlay tarball.
3
+ */
4
+ interface UploadSummary {
5
+ /** Total files in tarball */
6
+ fileCount: number;
7
+ /** Untracked (new) files */
8
+ newFiles: number;
9
+ /** Modified files (staged + unstaged) */
10
+ modifiedFiles: number;
11
+ /** Files deleted locally */
12
+ deletedFiles: number;
13
+ /** Tarball size in bytes (compressed) */
14
+ compressedSize: number;
15
+ /** HEAD SHA */
16
+ sha: string;
17
+ }
18
+ /**
19
+ * Manifest describing the overlay contents.
20
+ * Used by the agent to apply the overlay on top of a fresh clone.
21
+ */
22
+ export interface OverlayManifest {
23
+ /** HEAD SHA the overlay is based on */
24
+ sha: string;
25
+ /** Files deleted locally (need to be removed on agent) */
26
+ deletions: string[];
27
+ /** SHA256 checksums of each included file */
28
+ checksums: Record<string, string>;
29
+ }
30
+ /**
31
+ * Options for uploading a tarball.
32
+ */
33
+ interface UploadOptions {
34
+ /** Path to the tarball file */
35
+ tarballPath: string;
36
+ /** Pre-signed URL to upload to */
37
+ signedUrl: string;
38
+ /** Orchestrator's X25519 public key for encryption */
39
+ orchestratorPublicKey: Buffer;
40
+ /** Progress callback (bytes uploaded, total bytes) */
41
+ onProgress?: (bytes: number, total: number) => void;
42
+ }
43
+ /**
44
+ * Result of a successful upload.
45
+ */
46
+ interface UploadResult {
47
+ /** Upload identifier */
48
+ uploadId: string;
49
+ /** CLI's ephemeral public key (needed by agent for decryption) */
50
+ cliPublicKey: Buffer;
51
+ /** Encrypted tarball size in bytes */
52
+ encryptedSize: number;
53
+ }
54
+ /**
55
+ * Create an overlay tarball from a git repo, including only changed files.
56
+ *
57
+ * For repos with a remote: collects only dirty files (staged, unstaged, untracked).
58
+ * For repos without a remote: collects ALL tracked + untracked files (full tarball).
59
+ *
60
+ * The tarball includes a `manifest.json` with the HEAD SHA, deletions list,
61
+ * and SHA256 checksums for integrity verification.
62
+ *
63
+ * @param repoRoot - Path to the git repository root
64
+ * @param options - Optional configuration
65
+ * @returns Tarball path, upload summary, and overlay manifest
66
+ */
67
+ export declare function createOverlayTarball(repoRoot: string, options?: {
68
+ kiciIgnorePath?: string;
69
+ }): Promise<{
70
+ tarballPath: string;
71
+ summary: UploadSummary;
72
+ manifest: OverlayManifest;
73
+ hasRemote: boolean;
74
+ }>;
75
+ /**
76
+ * Returns a human-readable size warning if above threshold, or null.
77
+ */
78
+ export declare function getSizeWarning(compressedSize: number): string | null;
79
+ /**
80
+ * Upload an encrypted tarball to a pre-signed URL.
81
+ *
82
+ * Encrypts the tarball with X25519 ECDH, uploads via HTTP PUT,
83
+ * and retries up to 3 times on network failures (not on 4xx).
84
+ */
85
+ export declare function uploadTarball(opts: UploadOptions): Promise<UploadResult>;
86
+ export {};
87
+ //# sourceMappingURL=uploader.d.ts.map
@@ -0,0 +1,197 @@
1
+ import "../chunk-gOLHoazu.js";
2
+ import { encryptTarball } from "./encryption.js";
3
+ import fs from "node:fs/promises";
4
+ import path from "node:path";
5
+ import { execSync } from "node:child_process";
6
+ import { formatBytes, sha256, sha256File } from "@kici-dev/shared";
7
+ import os from "node:os";
8
+ import picomatch from "picomatch";
9
+ import { create } from "tar";
10
+ //#region src/remote/uploader.ts
11
+ /** Size threshold for warning (50MB) */
12
+ const SIZE_WARN_THRESHOLD = 50 * 1024 * 1024;
13
+ /** Size threshold for hard error (500MB) */
14
+ const SIZE_ERROR_THRESHOLD = 500 * 1024 * 1024;
15
+ /** Maximum upload retry attempts */
16
+ const MAX_RETRIES = 3;
17
+ /**
18
+ * Run a git command and return trimmed stdout lines.
19
+ * Returns empty array if command produces no output.
20
+ */
21
+ function gitLines(cmd, cwd) {
22
+ try {
23
+ const output = execSync(cmd, {
24
+ cwd,
25
+ encoding: "utf-8"
26
+ }).trim();
27
+ if (!output) return [];
28
+ return output.split("\n").filter((l) => l.length > 0);
29
+ } catch {
30
+ return [];
31
+ }
32
+ }
33
+ /**
34
+ * Load .kiciignore patterns from a file.
35
+ * Returns a picomatch matcher function or null if file doesn't exist.
36
+ */
37
+ async function loadKiciIgnore(kiciIgnorePath) {
38
+ try {
39
+ const patterns = (await fs.readFile(kiciIgnorePath, "utf-8")).split("\n").map((l) => l.trim()).filter((l) => l.length > 0 && !l.startsWith("#"));
40
+ if (patterns.length === 0) return null;
41
+ const matcher = picomatch(patterns);
42
+ return (file) => matcher(file);
43
+ } catch {
44
+ return null;
45
+ }
46
+ }
47
+ /**
48
+ * Create an overlay tarball from a git repo, including only changed files.
49
+ *
50
+ * For repos with a remote: collects only dirty files (staged, unstaged, untracked).
51
+ * For repos without a remote: collects ALL tracked + untracked files (full tarball).
52
+ *
53
+ * The tarball includes a `manifest.json` with the HEAD SHA, deletions list,
54
+ * and SHA256 checksums for integrity verification.
55
+ *
56
+ * @param repoRoot - Path to the git repository root
57
+ * @param options - Optional configuration
58
+ * @returns Tarball path, upload summary, and overlay manifest
59
+ */
60
+ async function createOverlayTarball(repoRoot, options) {
61
+ const sha = execSync("git rev-parse HEAD", {
62
+ cwd: repoRoot,
63
+ encoding: "utf-8"
64
+ }).trim();
65
+ const hasRemote = gitLines("git remote", repoRoot).length > 0;
66
+ let allFiles;
67
+ if (hasRemote) {
68
+ const unstaged = gitLines("git diff --name-only HEAD", repoRoot);
69
+ const staged = gitLines("git diff --name-only --cached HEAD", repoRoot);
70
+ const untracked = gitLines("git ls-files --others --exclude-standard", repoRoot);
71
+ allFiles = [...new Set([
72
+ ...unstaged,
73
+ ...staged,
74
+ ...untracked
75
+ ])];
76
+ } else {
77
+ const tracked = gitLines("git ls-files", repoRoot);
78
+ const untracked = gitLines("git ls-files --others --exclude-standard", repoRoot);
79
+ allFiles = [...new Set([...tracked, ...untracked])];
80
+ }
81
+ const kiciIgnore = await loadKiciIgnore(options?.kiciIgnorePath ?? path.join(repoRoot, ".kiciignore"));
82
+ if (kiciIgnore) allFiles = allFiles.filter((f) => !kiciIgnore(f));
83
+ const existingFiles = [];
84
+ const deletedFiles = [];
85
+ await Promise.all(allFiles.map(async (file) => {
86
+ const fullPath = path.join(repoRoot, file);
87
+ try {
88
+ await fs.access(fullPath);
89
+ existingFiles.push(file);
90
+ } catch {
91
+ deletedFiles.push(file);
92
+ }
93
+ }));
94
+ const untrackedSet = new Set(gitLines("git ls-files --others --exclude-standard", repoRoot));
95
+ const newFiles = existingFiles.filter((f) => untrackedSet.has(f));
96
+ const modifiedFiles = existingFiles.filter((f) => !untrackedSet.has(f));
97
+ const checksums = {};
98
+ await Promise.all(existingFiles.map(async (file) => {
99
+ checksums[file] = await sha256File(path.join(repoRoot, file));
100
+ }));
101
+ const manifest = {
102
+ sha,
103
+ deletions: deletedFiles,
104
+ checksums
105
+ };
106
+ const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "kici-overlay-"));
107
+ const manifestPath = path.join(tmpDir, "manifest.json");
108
+ await fs.writeFile(manifestPath, JSON.stringify(manifest, null, 2));
109
+ const manifestRelDir = ".kici-overlay-tmp";
110
+ const manifestRepoDir = path.join(repoRoot, manifestRelDir);
111
+ await fs.mkdir(manifestRepoDir, { recursive: true });
112
+ await fs.copyFile(manifestPath, path.join(manifestRepoDir, "manifest.json"));
113
+ const tarballPath = path.join(tmpDir, "overlay.tar.gz");
114
+ try {
115
+ const filesToInclude = [...existingFiles, path.join(manifestRelDir, "manifest.json")];
116
+ if (filesToInclude.length > 0) await create({
117
+ gzip: true,
118
+ file: tarballPath,
119
+ cwd: repoRoot
120
+ }, filesToInclude);
121
+ else await create({
122
+ gzip: true,
123
+ file: tarballPath,
124
+ cwd: repoRoot
125
+ }, []);
126
+ } finally {
127
+ await fs.rm(manifestRepoDir, {
128
+ recursive: true,
129
+ force: true
130
+ });
131
+ }
132
+ const compressedSize = (await fs.stat(tarballPath)).size;
133
+ if (compressedSize > SIZE_ERROR_THRESHOLD) throw new Error(`Tarball size ${formatBytes(compressedSize)} exceeds 500MB limit. Use --dangerously-allow-large-upload to override.`);
134
+ return {
135
+ tarballPath,
136
+ summary: {
137
+ fileCount: existingFiles.length,
138
+ newFiles: newFiles.length,
139
+ modifiedFiles: modifiedFiles.length,
140
+ deletedFiles: deletedFiles.length,
141
+ compressedSize,
142
+ sha
143
+ },
144
+ manifest,
145
+ hasRemote
146
+ };
147
+ }
148
+ /**
149
+ * Returns a human-readable size warning if above threshold, or null.
150
+ */
151
+ function getSizeWarning(compressedSize) {
152
+ if (compressedSize >= SIZE_WARN_THRESHOLD && compressedSize < SIZE_ERROR_THRESHOLD) return `Warning: tarball size is ${formatBytes(compressedSize)} (above 50MB warning threshold)`;
153
+ return null;
154
+ }
155
+ /**
156
+ * Upload an encrypted tarball to a pre-signed URL.
157
+ *
158
+ * Encrypts the tarball with X25519 ECDH, uploads via HTTP PUT,
159
+ * and retries up to 3 times on network failures (not on 4xx).
160
+ */
161
+ async function uploadTarball(opts) {
162
+ const { tarballPath, signedUrl, orchestratorPublicKey, onProgress } = opts;
163
+ const { encryptedPath, cliPublicKey } = await encryptTarball(tarballPath, orchestratorPublicKey);
164
+ const encryptedData = await fs.readFile(encryptedPath);
165
+ const encryptedSize = encryptedData.length;
166
+ let lastError = null;
167
+ for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) try {
168
+ const response = await fetch(signedUrl, {
169
+ method: "PUT",
170
+ body: encryptedData,
171
+ headers: {
172
+ "Content-Type": "application/octet-stream",
173
+ "Content-Length": encryptedSize.toString()
174
+ }
175
+ });
176
+ if (response.status >= 400 && response.status < 500) throw new Error(`Upload failed with status ${response.status}: ${response.statusText}`);
177
+ if (!response.ok) throw new Error(`Upload failed with status ${response.status}: ${response.statusText}`);
178
+ onProgress?.(encryptedSize, encryptedSize);
179
+ const uploadId = (response.headers.get("etag")?.replace(/"/g, "") ?? "") || sha256(encryptedData).slice(0, 16);
180
+ await fs.unlink(encryptedPath).catch(() => {});
181
+ return {
182
+ uploadId,
183
+ cliPublicKey,
184
+ encryptedSize
185
+ };
186
+ } catch (err) {
187
+ lastError = err instanceof Error ? err : new Error(String(err));
188
+ if (lastError.message.includes("status 4")) throw lastError;
189
+ if (attempt < MAX_RETRIES) await new Promise((resolve) => setTimeout(resolve, 1e3 * attempt));
190
+ }
191
+ await fs.unlink(encryptedPath).catch(() => {});
192
+ throw new Error(`Upload failed after ${MAX_RETRIES} attempts: ${lastError?.message}`);
193
+ }
194
+ //#endregion
195
+ export { createOverlayTarball, getSizeWarning, uploadTarball };
196
+
197
+ //# sourceMappingURL=uploader.js.map
@@ -0,0 +1,36 @@
1
+ {
2
+ "action": "created",
3
+ "comment": {
4
+ "id": 1,
5
+ "body": "Consider refactoring this",
6
+ "path": "src/index.ts",
7
+ "line": 42,
8
+ "user": {
9
+ "login": "reviewer"
10
+ }
11
+ },
12
+ "pull_request": {
13
+ "number": 42,
14
+ "title": "Test PR",
15
+ "state": "open",
16
+ "head": {
17
+ "ref": "feature-branch",
18
+ "sha": "abc123"
19
+ },
20
+ "base": {
21
+ "ref": "main",
22
+ "sha": "def456"
23
+ }
24
+ },
25
+ "repository": {
26
+ "name": "test-repo",
27
+ "full_name": "test-org/test-repo",
28
+ "owner": {
29
+ "login": "test-org"
30
+ },
31
+ "default_branch": "main"
32
+ },
33
+ "sender": {
34
+ "login": "reviewer"
35
+ }
36
+ }
@@ -0,0 +1,35 @@
1
+ {
2
+ "action": "submitted",
3
+ "review": {
4
+ "id": 1,
5
+ "state": "approved",
6
+ "body": "LGTM",
7
+ "user": {
8
+ "login": "reviewer"
9
+ }
10
+ },
11
+ "pull_request": {
12
+ "number": 42,
13
+ "title": "Test PR",
14
+ "state": "open",
15
+ "head": {
16
+ "ref": "feature-branch",
17
+ "sha": "abc123"
18
+ },
19
+ "base": {
20
+ "ref": "main",
21
+ "sha": "def456"
22
+ }
23
+ },
24
+ "repository": {
25
+ "name": "test-repo",
26
+ "full_name": "test-org/test-repo",
27
+ "owner": {
28
+ "login": "test-org"
29
+ },
30
+ "default_branch": "main"
31
+ },
32
+ "sender": {
33
+ "login": "reviewer"
34
+ }
35
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "action": "created",
3
+ "repository": {
4
+ "name": "test-repo",
5
+ "full_name": "test-org/test-repo",
6
+ "owner": {
7
+ "login": "test-org"
8
+ },
9
+ "default_branch": "main",
10
+ "stargazers_count": 100
11
+ },
12
+ "sender": {
13
+ "login": "test-user"
14
+ }
15
+ }
@@ -0,0 +1,26 @@
1
+ {
2
+ "state": "success",
3
+ "context": "ci/test",
4
+ "sha": "abc123def456",
5
+ "description": "Build succeeded",
6
+ "target_url": "https://ci.example.com/builds/1",
7
+ "branches": [
8
+ {
9
+ "name": "main",
10
+ "commit": {
11
+ "sha": "abc123def456"
12
+ }
13
+ }
14
+ ],
15
+ "repository": {
16
+ "name": "test-repo",
17
+ "full_name": "test-org/test-repo",
18
+ "owner": {
19
+ "login": "test-org"
20
+ },
21
+ "default_branch": "main"
22
+ },
23
+ "sender": {
24
+ "login": "test-user"
25
+ }
26
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "ref": "refs/tags/v1.0.0",
3
+ "before": "0000000000000000000000000000000000000000",
4
+ "after": "abc123def456",
5
+ "repository": {
6
+ "name": "test-repo",
7
+ "full_name": "test-org/test-repo",
8
+ "owner": {
9
+ "login": "test-org"
10
+ },
11
+ "default_branch": "main"
12
+ },
13
+ "pusher": {
14
+ "name": "test-user"
15
+ },
16
+ "sender": {
17
+ "login": "test-user"
18
+ },
19
+ "commits": []
20
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Template body for .kici/AGENTS.md, written by `kici init` (unless opted out
3
+ * via --no-agents-md). The format follows the cross-tool AGENTS.md convention
4
+ * picked up by Claude Code, Cursor, Aider, and other coding agents that scan
5
+ * the working tree for an authoring context file.
6
+ */
7
+ export declare const agentsMdTemplate = "# KiCI workflow authoring guide\n\nThis project uses KiCI \u2014 a TypeScript-native CI/CD workflow engine \u2014 instead\nof YAML-based CI. Workflows live in `.kici/workflows/*.ts`, are compiled\ninto a portable lock file, and executed by self-hosted agents.\n\n## Where the API surface lives\n\n- Public SDK types: `node_modules/@kici-dev/sdk/dist/index.d.ts` \u2014 read this\n for the canonical signatures of `workflow`, `job`, `step`, `pr`,\n `push`, `schedule`, `matrix`, `rule`, `dynamicJob`, etc.\n- Bundled offline reference for coding agents: `kici docs llm` prints the\n full markdown documentation bundle to stdout. `kici docs llm --index`\n prints just the curated link index (llms.txt format).\n- Online docs:\n - <https://kici.dev/docs/> \u2014 published docs site.\n - <https://kici.dev/llms.txt> \u2014 curated index for LLM consumers.\n - <https://kici.dev/llms-full.txt> \u2014 full markdown bundle.\n - Key pages: `user/sdk-reference`, `user/workflow-patterns`,\n `user/testing-guide`, `user/hooks`, `user/secrets`.\n\n## The five core patterns\n\n1. **Push trigger** \u2014 `on: push({ branches: 'main' })`. Pair with `paths`\n to scope to subtrees.\n\n ```ts\n import { workflow, job, step, push } from '@kici-dev/sdk';\n\n export default workflow('build', {\n on: push({ branches: 'main' }),\n jobs: [\n job('build', {\n runsOn: 'ubuntu-latest',\n steps: [step('install', async ({ $ }) => { await $`pnpm install`; })],\n }),\n ],\n });\n ```\n\n2. **PR + matrix** \u2014 `pr({ target: 'main' })` plus a matrix over node\n versions. The matrix expands at dispatch time.\n\n ```ts\n import { workflow, job, step, pr, matrix } from '@kici-dev/sdk';\n\n export default workflow('test-matrix', {\n on: pr({ target: 'main' }),\n jobs: [\n job('test', {\n runsOn: 'ubuntu-latest',\n strategy: { matrix: matrix({ node: ['20', '22', '24'] }) },\n steps: [\n step('test', async ({ $, matrix }) => {\n await $`node --version`;\n await $`pnpm install`;\n await $`pnpm test`;\n return { node: matrix.node };\n }),\n ],\n }),\n ],\n });\n ```\n\n3. **Lifecycle hooks** \u2014 `onFailure` / `onSuccess` / `onCancel` on a\n job or workflow run after the main steps in their own scope.\n\n4. **Secrets** \u2014 declared scopes resolve at dispatch:\n\n ```ts\n step('deploy', async ({ $, secrets }) => {\n await $`./scripts/deploy.sh`.env({ DEPLOY_TOKEN: secrets.production.DEPLOY_TOKEN });\n });\n ```\n\n Run `kici secrets list` to enumerate the contexts available for testing.\n\n5. **Dynamic jobs** \u2014 `dynamicJob` and `dynamicGroup` build the DAG at\n runtime from a step's outputs. Don't try to compute job names at top level;\n the lock file would be wrong.\n\n## Anti-patterns\n\n- **Do NOT write `.yml` / `.yaml` CI files** \u2014 KiCI replaces that entire\n layer. There is no compatibility shim.\n- **Do NOT `import` from any `@kici-dev/*` package's `/dist/...`\n subpath** \u2014 those are not part of the public API and break across versions.\n Import from the package root.\n- **Do NOT `await` outside step bodies.** The top-level workflow file is\n loaded by the compiler synchronously; async I/O at module scope means the\n lock file emits before it resolves and the workflow appears empty.\n- **Do NOT mutate shared variables between jobs.** Each job runs in its own\n agent process. Use `needs` + step outputs to thread values.\n- **Do NOT hand-edit `kici.lock.json`.** Regenerate it via `kici compile`.\n\n## Local commands a coding agent should run\n\n| Command | Purpose |\n| ------------------------------- | ------------------------------------------- |\n| `pnpm kici compile --check` | Validate workflow source without writing. |\n| `pnpm kici test pr:open --debug`| Preview which workflows match an event. |\n| `pnpm kici run local push` | Execute workflows locally with no orchestrator. |\n| `pnpm kici docs llm` | Print the full LLM documentation bundle. |\n| `pnpm kici docs llm --index` | Print the curated link index. |\n\nIf `pnpm kici` isn't in scripts, fall back to `npx kici`.\n\n## Loop\n\n1. Read the SDK types from `node_modules/@kici-dev/sdk/dist/index.d.ts`.\n2. Pipe `kici docs llm` into the agent's context if it doesn't already have\n the full bundle.\n3. Edit a workflow under `.kici/workflows/`.\n4. Run `kici compile --check` (zero exit means valid).\n5. Run `kici test <event>` to preview matching.\n6. Run `kici run local <event>` to execute locally before pushing.\n";
8
+ //# sourceMappingURL=agents-md.d.ts.map
@@ -0,0 +1,130 @@
1
+ import "../chunk-gOLHoazu.js";
2
+ //#region src/templates/agents-md.ts
3
+ /**
4
+ * Template body for .kici/AGENTS.md, written by `kici init` (unless opted out
5
+ * via --no-agents-md). The format follows the cross-tool AGENTS.md convention
6
+ * picked up by Claude Code, Cursor, Aider, and other coding agents that scan
7
+ * the working tree for an authoring context file.
8
+ */
9
+ const agentsMdTemplate = `# KiCI workflow authoring guide
10
+
11
+ This project uses KiCI — a TypeScript-native CI/CD workflow engine — instead
12
+ of YAML-based CI. Workflows live in \`.kici/workflows/*.ts\`, are compiled
13
+ into a portable lock file, and executed by self-hosted agents.
14
+
15
+ ## Where the API surface lives
16
+
17
+ - Public SDK types: \`node_modules/@kici-dev/sdk/dist/index.d.ts\` — read this
18
+ for the canonical signatures of \`workflow\`, \`job\`, \`step\`, \`pr\`,
19
+ \`push\`, \`schedule\`, \`matrix\`, \`rule\`, \`dynamicJob\`, etc.
20
+ - Bundled offline reference for coding agents: \`kici docs llm\` prints the
21
+ full markdown documentation bundle to stdout. \`kici docs llm --index\`
22
+ prints just the curated link index (llms.txt format).
23
+ - Online docs:
24
+ - <https://kici.dev/docs/> — published docs site.
25
+ - <https://kici.dev/llms.txt> — curated index for LLM consumers.
26
+ - <https://kici.dev/llms-full.txt> — full markdown bundle.
27
+ - Key pages: \`user/sdk-reference\`, \`user/workflow-patterns\`,
28
+ \`user/testing-guide\`, \`user/hooks\`, \`user/secrets\`.
29
+
30
+ ## The five core patterns
31
+
32
+ 1. **Push trigger** — \`on: push({ branches: 'main' })\`. Pair with \`paths\`
33
+ to scope to subtrees.
34
+
35
+ \`\`\`ts
36
+ import { workflow, job, step, push } from '@kici-dev/sdk';
37
+
38
+ export default workflow('build', {
39
+ on: push({ branches: 'main' }),
40
+ jobs: [
41
+ job('build', {
42
+ runsOn: 'ubuntu-latest',
43
+ steps: [step('install', async ({ $ }) => { await $\`pnpm install\`; })],
44
+ }),
45
+ ],
46
+ });
47
+ \`\`\`
48
+
49
+ 2. **PR + matrix** — \`pr({ target: 'main' })\` plus a matrix over node
50
+ versions. The matrix expands at dispatch time.
51
+
52
+ \`\`\`ts
53
+ import { workflow, job, step, pr, matrix } from '@kici-dev/sdk';
54
+
55
+ export default workflow('test-matrix', {
56
+ on: pr({ target: 'main' }),
57
+ jobs: [
58
+ job('test', {
59
+ runsOn: 'ubuntu-latest',
60
+ strategy: { matrix: matrix({ node: ['20', '22', '24'] }) },
61
+ steps: [
62
+ step('test', async ({ $, matrix }) => {
63
+ await $\`node --version\`;
64
+ await $\`pnpm install\`;
65
+ await $\`pnpm test\`;
66
+ return { node: matrix.node };
67
+ }),
68
+ ],
69
+ }),
70
+ ],
71
+ });
72
+ \`\`\`
73
+
74
+ 3. **Lifecycle hooks** — \`onFailure\` / \`onSuccess\` / \`onCancel\` on a
75
+ job or workflow run after the main steps in their own scope.
76
+
77
+ 4. **Secrets** — declared scopes resolve at dispatch:
78
+
79
+ \`\`\`ts
80
+ step('deploy', async ({ $, secrets }) => {
81
+ await $\`./scripts/deploy.sh\`.env({ DEPLOY_TOKEN: secrets.production.DEPLOY_TOKEN });
82
+ });
83
+ \`\`\`
84
+
85
+ Run \`kici secrets list\` to enumerate the contexts available for testing.
86
+
87
+ 5. **Dynamic jobs** — \`dynamicJob\` and \`dynamicGroup\` build the DAG at
88
+ runtime from a step's outputs. Don't try to compute job names at top level;
89
+ the lock file would be wrong.
90
+
91
+ ## Anti-patterns
92
+
93
+ - **Do NOT write \`.yml\` / \`.yaml\` CI files** — KiCI replaces that entire
94
+ layer. There is no compatibility shim.
95
+ - **Do NOT \`import\` from any \`@kici-dev/*\` package's \`/dist/...\`
96
+ subpath** — those are not part of the public API and break across versions.
97
+ Import from the package root.
98
+ - **Do NOT \`await\` outside step bodies.** The top-level workflow file is
99
+ loaded by the compiler synchronously; async I/O at module scope means the
100
+ lock file emits before it resolves and the workflow appears empty.
101
+ - **Do NOT mutate shared variables between jobs.** Each job runs in its own
102
+ agent process. Use \`needs\` + step outputs to thread values.
103
+ - **Do NOT hand-edit \`kici.lock.json\`.** Regenerate it via \`kici compile\`.
104
+
105
+ ## Local commands a coding agent should run
106
+
107
+ | Command | Purpose |
108
+ | ------------------------------- | ------------------------------------------- |
109
+ | \`pnpm kici compile --check\` | Validate workflow source without writing. |
110
+ | \`pnpm kici test pr:open --debug\`| Preview which workflows match an event. |
111
+ | \`pnpm kici run local push\` | Execute workflows locally with no orchestrator. |
112
+ | \`pnpm kici docs llm\` | Print the full LLM documentation bundle. |
113
+ | \`pnpm kici docs llm --index\` | Print the curated link index. |
114
+
115
+ If \`pnpm kici\` isn't in scripts, fall back to \`npx kici\`.
116
+
117
+ ## Loop
118
+
119
+ 1. Read the SDK types from \`node_modules/@kici-dev/sdk/dist/index.d.ts\`.
120
+ 2. Pipe \`kici docs llm\` into the agent's context if it doesn't already have
121
+ the full bundle.
122
+ 3. Edit a workflow under \`.kici/workflows/\`.
123
+ 4. Run \`kici compile --check\` (zero exit means valid).
124
+ 5. Run \`kici test <event>\` to preview matching.
125
+ 6. Run \`kici run local <event>\` to execute locally before pushing.
126
+ `;
127
+ //#endregion
128
+ export { agentsMdTemplate };
129
+
130
+ //# sourceMappingURL=agents-md.js.map
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Template aggregator for kici init command
3
+ *
4
+ * Re-exports all templates for easy consumption by the init command.
5
+ */
6
+ export { helloWorldWorkflow } from './workflows/hello-world.js';
7
+ export { prChecksWorkflow } from './workflows/pr-checks.js';
8
+ export { generatePackageJson } from './package-json.js';
9
+ export { tsconfigTemplate } from './tsconfig-json.js';
10
+ export { agentsMdTemplate } from './agents-md.js';
11
+ /**
12
+ * Workflow file paths for init command
13
+ *
14
+ * Maps workflow names to their source file paths.
15
+ * Used by init command to read and copy workflow templates.
16
+ */
17
+ export declare const workflowPaths: {
18
+ readonly 'hello-world': string;
19
+ readonly 'pr-checks': string;
20
+ };
21
+ /**
22
+ * Real workflow objects map
23
+ *
24
+ * Maps workflow names to their compiled workflow objects.
25
+ * Used for testing and type validation.
26
+ */
27
+ export declare const workflows: {
28
+ readonly 'hello-world': import("@kici-dev/sdk").Workflow;
29
+ readonly 'pr-checks': import("@kici-dev/sdk").Workflow;
30
+ };
31
+ /**
32
+ * All templates aggregated
33
+ *
34
+ * Provides a single object with all template types.
35
+ */
36
+ export declare const templates: {
37
+ readonly workflowPaths: {
38
+ readonly 'hello-world': string;
39
+ readonly 'pr-checks': string;
40
+ };
41
+ readonly tsconfig: string;
42
+ };
43
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,48 @@
1
+ import "../chunk-gOLHoazu.js";
2
+ import { helloWorldWorkflow } from "./workflows/hello-world.js";
3
+ import { prChecksWorkflow } from "./workflows/pr-checks.js";
4
+ import { tsconfigTemplate } from "./tsconfig-json.js";
5
+ import { generatePackageJson } from "./package-json.js";
6
+ import { agentsMdTemplate } from "./agents-md.js";
7
+ import path from "node:path";
8
+ import { fileURLToPath } from "node:url";
9
+ //#region src/templates/index.ts
10
+ /**
11
+ * Template aggregator for kici init command
12
+ *
13
+ * Re-exports all templates for easy consumption by the init command.
14
+ */
15
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
16
+ /**
17
+ * Workflow file paths for init command
18
+ *
19
+ * Maps workflow names to their source file paths.
20
+ * Used by init command to read and copy workflow templates.
21
+ */
22
+ const workflowPaths = {
23
+ "hello-world": path.join(__dirname, "workflows", "hello-world.ts"),
24
+ "pr-checks": path.join(__dirname, "workflows", "pr-checks.ts")
25
+ };
26
+ /**
27
+ * Real workflow objects map
28
+ *
29
+ * Maps workflow names to their compiled workflow objects.
30
+ * Used for testing and type validation.
31
+ */
32
+ const workflows = {
33
+ "hello-world": helloWorldWorkflow,
34
+ "pr-checks": prChecksWorkflow
35
+ };
36
+ /**
37
+ * All templates aggregated
38
+ *
39
+ * Provides a single object with all template types.
40
+ */
41
+ const templates = {
42
+ workflowPaths,
43
+ tsconfig: tsconfigTemplate
44
+ };
45
+ //#endregion
46
+ export { agentsMdTemplate, generatePackageJson, helloWorldWorkflow, prChecksWorkflow, templates, tsconfigTemplate, workflowPaths, workflows };
47
+
48
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Package.json template generator for kici init command
3
+ *
4
+ * Generates package.json for .kici/ directory in TypeScript mode.
5
+ * SDK is a devDependency resolved from the npm registry
6
+ * (or a private Verdaccio instance when .npmrc scopes the registry).
7
+ * The compiler is invoked via npx (not installed as a dependency).
8
+ */
9
+ /**
10
+ * Generate package.json content for .kici/ directory
11
+ *
12
+ * @param devMode - When true, uses a prerelease-compatible version range
13
+ * (`>=0.0.1-0`) so npm resolves Verdaccio's prerelease builds (e.g. 0.0.1-2856).
14
+ * Semver `^0.0.1` does NOT match prereleases, causing 404s on Verdaccio.
15
+ * @returns JSON string with proper formatting (2-space indent, trailing newline)
16
+ */
17
+ export declare function generatePackageJson(devMode?: boolean): string;
18
+ //# sourceMappingURL=package-json.d.ts.map