@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,50 @@
1
+ import "../chunk-gOLHoazu.js";
2
+ import { readFileSync } from "node:fs";
3
+ import path from "node:path";
4
+ import fg from "fast-glob";
5
+ //#region src/lockfile/hash-files.ts
6
+ /**
7
+ * Resolve hashFiles patterns (paths and globs) relative to git root and build a deterministic
8
+ * digest string: sorted resolved paths, each followed by "\n" and file content.
9
+ * Used as input to the content hash so workflow cache invalidates when these files change.
10
+ *
11
+ * @param gitRoot - Absolute path to git repository root
12
+ * @param patterns - Paths or glob patterns relative to repo root (e.g. ["config.json", "scripts/*.sh"])
13
+ * @returns Object with digest string and list of resolved paths (relative to git root), or null if no patterns or resolution fails
14
+ */
15
+ function resolveHashFiles(gitRoot, patterns) {
16
+ if (patterns.length === 0) return null;
17
+ const seen = /* @__PURE__ */ new Set();
18
+ const resolved = [];
19
+ for (const pattern of patterns) {
20
+ const matches = fg.sync(pattern, {
21
+ cwd: gitRoot,
22
+ absolute: false,
23
+ onlyFiles: true,
24
+ dot: false,
25
+ followSymbolicLinks: false
26
+ });
27
+ for (const p of matches) {
28
+ const normalized = path.normalize(p).replace(/\\/g, "/");
29
+ if (seen.has(normalized)) continue;
30
+ seen.add(normalized);
31
+ resolved.push(normalized);
32
+ }
33
+ }
34
+ resolved.sort();
35
+ const parts = [];
36
+ for (const rel of resolved) try {
37
+ const content = readFileSync(path.join(gitRoot, rel), "utf-8");
38
+ parts.push(`${rel}\n${content}`);
39
+ } catch {
40
+ parts.push(`${rel}\n`);
41
+ }
42
+ return {
43
+ assetDigest: parts.join(""),
44
+ resolvedPaths: resolved
45
+ };
46
+ }
47
+ //#endregion
48
+ export { resolveHashFiles };
49
+
50
+ //# sourceMappingURL=hash-files.js.map
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Compile schema version -- bump when compilation approach changes
3
+ * (bundler change, bundling config, output format, etc.).
4
+ * This is NOT the lock file schema version.
5
+ *
6
+ * Bumped 3 → 4: the agent artifact switched from a Rolldown-bundled
7
+ * `.compiled.mjs` to a raw `.kici/` source tarball that the agent extracts
8
+ * and imports via the shared oxc-transform ESM loader hook.
9
+ *
10
+ * Bumped 4 → 5: the hash input is now line-ending-normalized (CRLF → LF) so a
11
+ * lockfile produced on Linux (LF) matches the agent's hash on Windows, where
12
+ * Git's `core.autocrlf=true` system default rewrites checked-out text files to
13
+ * CRLF. Old lockfiles must be regenerated via `kici compile`.
14
+ */
15
+ export declare const COMPILE_SCHEMA_VERSION = 5;
16
+ /**
17
+ * Compute content hash for a compiled workflow bundle, optionally including asset file contents.
18
+ * Hash = SHA-256(schemaVersion + ":" + bundleSource + "\0" + assetDigest) when assetDigest is provided,
19
+ * otherwise SHA-256(schemaVersion + ":" + bundleSource) for backward compatibility.
20
+ *
21
+ * The schema version is mixed into the hash input so that
22
+ * different compilation approaches produce different hashes
23
+ * even if the source hasn't changed.
24
+ *
25
+ * Line endings in `bundleSource` (and inside `assetDigest`) are normalized to
26
+ * LF before hashing — the agent applies the same normalization, so the hash
27
+ * agrees across platforms even when Git's `core.autocrlf=true` rewrites the
28
+ * working tree on Windows. Callers should not pre-normalize.
29
+ *
30
+ * @param bundleSource - The compiled JS bundle text (without source maps)
31
+ * @param schemaVersion - The compile schema version to mix into the hash
32
+ * @param assetDigest - Optional deterministic encoding of resolved hashFiles (path + content per file, sorted by path). Omit for bundle-only hash.
33
+ * @returns 64-character lowercase hex SHA-256 digest
34
+ */
35
+ export declare function computeContentHash(bundleSource: string, schemaVersion: number, assetDigest?: string): string;
36
+ //# sourceMappingURL=hasher.d.ts.map
@@ -0,0 +1,46 @@
1
+ import "../chunk-gOLHoazu.js";
2
+ import { normalizeLineEndings, sha256 } from "@kici-dev/shared";
3
+ //#region src/lockfile/hasher.ts
4
+ /**
5
+ * Compile schema version -- bump when compilation approach changes
6
+ * (bundler change, bundling config, output format, etc.).
7
+ * This is NOT the lock file schema version.
8
+ *
9
+ * Bumped 3 → 4: the agent artifact switched from a Rolldown-bundled
10
+ * `.compiled.mjs` to a raw `.kici/` source tarball that the agent extracts
11
+ * and imports via the shared oxc-transform ESM loader hook.
12
+ *
13
+ * Bumped 4 → 5: the hash input is now line-ending-normalized (CRLF → LF) so a
14
+ * lockfile produced on Linux (LF) matches the agent's hash on Windows, where
15
+ * Git's `core.autocrlf=true` system default rewrites checked-out text files to
16
+ * CRLF. Old lockfiles must be regenerated via `kici compile`.
17
+ */
18
+ const COMPILE_SCHEMA_VERSION = 5;
19
+ /**
20
+ * Compute content hash for a compiled workflow bundle, optionally including asset file contents.
21
+ * Hash = SHA-256(schemaVersion + ":" + bundleSource + "\0" + assetDigest) when assetDigest is provided,
22
+ * otherwise SHA-256(schemaVersion + ":" + bundleSource) for backward compatibility.
23
+ *
24
+ * The schema version is mixed into the hash input so that
25
+ * different compilation approaches produce different hashes
26
+ * even if the source hasn't changed.
27
+ *
28
+ * Line endings in `bundleSource` (and inside `assetDigest`) are normalized to
29
+ * LF before hashing — the agent applies the same normalization, so the hash
30
+ * agrees across platforms even when Git's `core.autocrlf=true` rewrites the
31
+ * working tree on Windows. Callers should not pre-normalize.
32
+ *
33
+ * @param bundleSource - The compiled JS bundle text (without source maps)
34
+ * @param schemaVersion - The compile schema version to mix into the hash
35
+ * @param assetDigest - Optional deterministic encoding of resolved hashFiles (path + content per file, sorted by path). Omit for bundle-only hash.
36
+ * @returns 64-character lowercase hex SHA-256 digest
37
+ */
38
+ function computeContentHash(bundleSource, schemaVersion, assetDigest) {
39
+ let input = `${schemaVersion}:${normalizeLineEndings(bundleSource)}`;
40
+ if (assetDigest !== void 0 && assetDigest.length > 0) input += `\0${normalizeLineEndings(assetDigest)}`;
41
+ return sha256(input);
42
+ }
43
+ //#endregion
44
+ export { COMPILE_SCHEMA_VERSION, computeContentHash };
45
+
46
+ //# sourceMappingURL=hasher.js.map
@@ -0,0 +1,3 @@
1
+ export { generateLockFile, serializeLockFile, detectGitRoot, computeLockfileHash, } from './generator.js';
2
+ export { computeContentHash, COMPILE_SCHEMA_VERSION } from './hasher.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,4 @@
1
+ import "../chunk-gOLHoazu.js";
2
+ import { COMPILE_SCHEMA_VERSION, computeContentHash } from "./hasher.js";
3
+ import { computeLockfileHash, detectGitRoot, generateLockFile, serializeLockFile } from "./generator.js";
4
+ export { COMPILE_SCHEMA_VERSION, computeContentHash, computeLockfileHash, detectGitRoot, generateLockFile, serializeLockFile };
@@ -0,0 +1,25 @@
1
+ /**
2
+ * AST-based purity analysis for dynamic job functions.
3
+ * Determines whether a function can be safely evaluated inline by the orchestrator
4
+ * (via vm.runInNewContext) without requiring a full init job dispatch.
5
+ *
6
+ * A function is "pure" if it:
7
+ * - Is synchronous (not async)
8
+ * - Only references its parameters and safe globals
9
+ * - Does not perform I/O, mutation, or use external scope
10
+ * - Only uses const/let for local declarations (no var)
11
+ */
12
+ /** Result of purity analysis */
13
+ interface PurityResult {
14
+ pure: boolean;
15
+ reason?: string;
16
+ }
17
+ /**
18
+ * Analyze whether a function source string represents a pure function.
19
+ *
20
+ * @param fnSource - The function source code (e.g., "(event) => event.ref")
21
+ * @returns PurityResult indicating whether the function is pure
22
+ */
23
+ export declare function analyzePurity(fnSource: string): PurityResult;
24
+ export {};
25
+ //# sourceMappingURL=purity-analyzer.d.ts.map
@@ -0,0 +1,204 @@
1
+ import "../chunk-gOLHoazu.js";
2
+ import ts from "typescript";
3
+ //#region src/lockfile/purity-analyzer.ts
4
+ /**
5
+ * AST-based purity analysis for dynamic job functions.
6
+ * Determines whether a function can be safely evaluated inline by the orchestrator
7
+ * (via vm.runInNewContext) without requiring a full init job dispatch.
8
+ *
9
+ * A function is "pure" if it:
10
+ * - Is synchronous (not async)
11
+ * - Only references its parameters and safe globals
12
+ * - Does not perform I/O, mutation, or use external scope
13
+ * - Only uses const/let for local declarations (no var)
14
+ */
15
+ /**
16
+ * Safe globals that pure functions are allowed to reference.
17
+ * These are deterministic, side-effect-free built-ins.
18
+ */
19
+ const SAFE_GLOBALS = new Set([
20
+ "undefined",
21
+ "null",
22
+ "true",
23
+ "false",
24
+ "NaN",
25
+ "Infinity",
26
+ "String",
27
+ "Number",
28
+ "Boolean",
29
+ "Array",
30
+ "Object",
31
+ "JSON",
32
+ "Math",
33
+ "parseInt",
34
+ "parseFloat",
35
+ "isNaN",
36
+ "isFinite",
37
+ "encodeURIComponent",
38
+ "decodeURIComponent",
39
+ "encodeURI",
40
+ "decodeURI"
41
+ ]);
42
+ /**
43
+ * Assignment operators that indicate mutation.
44
+ */
45
+ const ASSIGNMENT_OPERATORS = new Set([
46
+ ts.SyntaxKind.EqualsToken,
47
+ ts.SyntaxKind.PlusEqualsToken,
48
+ ts.SyntaxKind.MinusEqualsToken,
49
+ ts.SyntaxKind.AsteriskEqualsToken,
50
+ ts.SyntaxKind.SlashEqualsToken,
51
+ ts.SyntaxKind.PercentEqualsToken,
52
+ ts.SyntaxKind.AmpersandEqualsToken,
53
+ ts.SyntaxKind.BarEqualsToken,
54
+ ts.SyntaxKind.CaretEqualsToken,
55
+ ts.SyntaxKind.LessThanLessThanEqualsToken,
56
+ ts.SyntaxKind.GreaterThanGreaterThanEqualsToken,
57
+ ts.SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken,
58
+ ts.SyntaxKind.AsteriskAsteriskEqualsToken,
59
+ ts.SyntaxKind.BarBarEqualsToken,
60
+ ts.SyntaxKind.AmpersandAmpersandEqualsToken,
61
+ ts.SyntaxKind.QuestionQuestionEqualsToken
62
+ ]);
63
+ /**
64
+ * Analyze whether a function source string represents a pure function.
65
+ *
66
+ * @param fnSource - The function source code (e.g., "(event) => event.ref")
67
+ * @returns PurityResult indicating whether the function is pure
68
+ */
69
+ function analyzePurity(fnSource) {
70
+ const wrapped = "const __fn = " + fnSource;
71
+ const firstStatement = ts.createSourceFile("inline.js", wrapped, ts.ScriptTarget.Latest, true, ts.ScriptKind.JS).statements[0];
72
+ if (!ts.isVariableStatement(firstStatement)) return {
73
+ pure: false,
74
+ reason: "failed to parse function source"
75
+ };
76
+ const declaration = firstStatement.declarationList.declarations[0];
77
+ if (!declaration.initializer) return {
78
+ pure: false,
79
+ reason: "failed to parse function source"
80
+ };
81
+ const fnNode = declaration.initializer;
82
+ if (!ts.isArrowFunction(fnNode) && !ts.isFunctionExpression(fnNode)) return {
83
+ pure: false,
84
+ reason: "not a function expression"
85
+ };
86
+ if (ts.getModifiers(fnNode)?.some((m) => m.kind === ts.SyntaxKind.AsyncKeyword)) return {
87
+ pure: false,
88
+ reason: "async functions cannot be inlined"
89
+ };
90
+ if (ts.isFunctionExpression(fnNode) && fnNode.asteriskToken) return {
91
+ pure: false,
92
+ reason: "generator functions cannot be inlined"
93
+ };
94
+ const paramNames = /* @__PURE__ */ new Set();
95
+ for (const param of fnNode.parameters) collectBindingNames(param.name, paramNames);
96
+ const localNames = /* @__PURE__ */ new Set();
97
+ return checkNode(fnNode.body, paramNames, localNames) ?? { pure: true };
98
+ }
99
+ /**
100
+ * Recursively collect binding names from parameter declarations,
101
+ * including destructured patterns.
102
+ */
103
+ function collectBindingNames(node, names) {
104
+ if (ts.isIdentifier(node)) names.add(node.text);
105
+ else if (ts.isObjectBindingPattern(node)) for (const element of node.elements) collectBindingNames(element.name, names);
106
+ else if (ts.isArrayBindingPattern(node)) {
107
+ for (const element of node.elements) if (!ts.isOmittedExpression(element)) collectBindingNames(element.name, names);
108
+ }
109
+ }
110
+ /**
111
+ * Check a node and its children for impurity.
112
+ * Returns a PurityResult if impure, or undefined if pure so far.
113
+ */
114
+ function checkNode(node, paramNames, localNames) {
115
+ switch (node.kind) {
116
+ case ts.SyntaxKind.AwaitExpression: return {
117
+ pure: false,
118
+ reason: "contains await expression"
119
+ };
120
+ case ts.SyntaxKind.ImportDeclaration: return {
121
+ pure: false,
122
+ reason: "contains import declaration"
123
+ };
124
+ case ts.SyntaxKind.YieldExpression: return {
125
+ pure: false,
126
+ reason: "contains yield expression"
127
+ };
128
+ case ts.SyntaxKind.ClassDeclaration:
129
+ case ts.SyntaxKind.ClassExpression: return {
130
+ pure: false,
131
+ reason: "contains class declaration"
132
+ };
133
+ case ts.SyntaxKind.ThisKeyword: return {
134
+ pure: false,
135
+ reason: "references 'this'"
136
+ };
137
+ case ts.SyntaxKind.DeleteExpression: return {
138
+ pure: false,
139
+ reason: "contains 'delete' expression"
140
+ };
141
+ case ts.SyntaxKind.ThrowStatement: return {
142
+ pure: false,
143
+ reason: "contains throw statement"
144
+ };
145
+ case ts.SyntaxKind.TryStatement: return {
146
+ pure: false,
147
+ reason: "contains try/catch"
148
+ };
149
+ }
150
+ if (ts.isNewExpression(node)) return {
151
+ pure: false,
152
+ reason: "contains 'new' expression"
153
+ };
154
+ if (ts.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword) return {
155
+ pure: false,
156
+ reason: "contains dynamic import"
157
+ };
158
+ if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === "require") return {
159
+ pure: false,
160
+ reason: "contains require() call"
161
+ };
162
+ if (ts.isPostfixUnaryExpression(node)) {
163
+ if (node.operator === ts.SyntaxKind.PlusPlusToken || node.operator === ts.SyntaxKind.MinusMinusToken) return {
164
+ pure: false,
165
+ reason: "contains mutation operator"
166
+ };
167
+ }
168
+ if (ts.isPrefixUnaryExpression(node)) {
169
+ if (node.operator === ts.SyntaxKind.PlusPlusToken || node.operator === ts.SyntaxKind.MinusMinusToken) return {
170
+ pure: false,
171
+ reason: "contains mutation operator"
172
+ };
173
+ }
174
+ if (ts.isBinaryExpression(node) && ASSIGNMENT_OPERATORS.has(node.operatorToken.kind)) return {
175
+ pure: false,
176
+ reason: "contains assignment"
177
+ };
178
+ if (ts.isVariableDeclarationList(node)) if (node.flags & ts.NodeFlags.Const || node.flags & ts.NodeFlags.Let) for (const decl of node.declarations) collectBindingNames(decl.name, localNames);
179
+ else return {
180
+ pure: false,
181
+ reason: "'var' declarations are not allowed (use const or let)"
182
+ };
183
+ if (ts.isIdentifier(node)) {
184
+ const parent = node.parent;
185
+ if (ts.isPropertyAccessExpression(parent) && parent.name === node) {} else if (ts.isPropertyAssignment(parent) && parent.name === node) {} else if (ts.isShorthandPropertyAssignment(parent) && parent.name === node) {
186
+ if (!paramNames.has(node.text) && !localNames.has(node.text) && !SAFE_GLOBALS.has(node.text)) return {
187
+ pure: false,
188
+ reason: `references unknown identifier '${node.text}'`
189
+ };
190
+ } else if (ts.isVariableDeclaration(parent) && parent.name === node) {} else if (ts.isBindingElement(parent) && parent.name === node) {} else if (ts.isParameter(parent) && parent.name === node) {} else if (!paramNames.has(node.text) && !localNames.has(node.text) && !SAFE_GLOBALS.has(node.text)) return {
191
+ pure: false,
192
+ reason: `references unknown identifier '${node.text}'`
193
+ };
194
+ }
195
+ const children = node.getChildren();
196
+ for (const child of children) {
197
+ const result = checkNode(child, paramNames, localNames);
198
+ if (result) return result;
199
+ }
200
+ }
201
+ //#endregion
202
+ export { analyzePurity };
203
+
204
+ //# sourceMappingURL=purity-analyzer.js.map
@@ -0,0 +1,74 @@
1
+ {
2
+ "name": "winston",
3
+ "description": "A logger for just about everything.",
4
+ "version": "3.19.0",
5
+ "author": "Charlie Robbins <charlie.robbins@gmail.com>",
6
+ "maintainers": [
7
+ "David Hyde <dabh@alumni.stanford.edu>"
8
+ ],
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/winstonjs/winston.git"
12
+ },
13
+ "keywords": [
14
+ "winston",
15
+ "logger",
16
+ "logging",
17
+ "logs",
18
+ "sysadmin",
19
+ "bunyan",
20
+ "pino",
21
+ "loglevel",
22
+ "tools",
23
+ "json",
24
+ "stream"
25
+ ],
26
+ "dependencies": {
27
+ "@dabh/diagnostics": "^2.0.8",
28
+ "@colors/colors": "^1.6.0",
29
+ "async": "^3.2.3",
30
+ "is-stream": "^2.0.0",
31
+ "logform": "^2.7.0",
32
+ "one-time": "^1.0.0",
33
+ "readable-stream": "^3.4.0",
34
+ "safe-stable-stringify": "^2.3.1",
35
+ "stack-trace": "0.0.x",
36
+ "triple-beam": "^1.3.0",
37
+ "winston-transport": "^4.9.0"
38
+ },
39
+ "devDependencies": {
40
+ "@babel/cli": "^7.23.9",
41
+ "@babel/core": "^7.24.0",
42
+ "@babel/preset-env": "^7.24.0",
43
+ "@dabh/eslint-config-populist": "^4.4.0",
44
+ "@types/node": "^20.11.24",
45
+ "abstract-winston-transport": "^0.5.1",
46
+ "assume": "^2.2.0",
47
+ "cross-spawn-async": "^2.2.5",
48
+ "eslint": "^8.57.0",
49
+ "hock": "^1.4.1",
50
+ "jest": "^29.7.0",
51
+ "rimraf": "5.0.10",
52
+ "split2": "^4.1.0",
53
+ "std-mocks": "^2.0.0",
54
+ "through2": "^4.0.2",
55
+ "winston-compat": "^0.1.5"
56
+ },
57
+ "main": "./lib/winston.js",
58
+ "browser": "./dist/winston",
59
+ "types": "./index.d.ts",
60
+ "scripts": {
61
+ "lint": "eslint lib/*.js lib/winston/*.js lib/winston/**/*.js --resolve-plugins-relative-to ./node_modules/@dabh/eslint-config-populist",
62
+ "test": "jest",
63
+ "test:unit": "jest -c test/jest.config.unit.js",
64
+ "test:integration": "jest -c test/jest.config.integration.js",
65
+ "test:typescript": "npx --package typescript tsc --project test",
66
+ "build": "babel lib -d dist",
67
+ "prebuild": "rimraf dist",
68
+ "prepublishOnly": "npm run build"
69
+ },
70
+ "engines": {
71
+ "node": ">= 12.0.0"
72
+ },
73
+ "license": "MIT"
74
+ }
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Post-install script for @kici-dev/compiler
4
+ *
5
+ * Prompts users to run `kici init` after installing the package.
6
+ * Skips in CI environments, non-TTY, dev mode, and if .kici/ already exists.
7
+ */
8
+ export {};
9
+ //# sourceMappingURL=postinstall.d.ts.map
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env node
2
+ import "./chunk-gOLHoazu.js";
3
+ import { readFile } from "node:fs/promises";
4
+ import path from "node:path";
5
+ import { spawn } from "node:child_process";
6
+ import { confirm } from "@inquirer/prompts";
7
+ //#region src/postinstall.ts
8
+ /**
9
+ * Post-install script for @kici-dev/compiler
10
+ *
11
+ * Prompts users to run `kici init` after installing the package.
12
+ * Skips in CI environments, non-TTY, dev mode, and if .kici/ already exists.
13
+ */
14
+ /**
15
+ * Detect if running in development mode
16
+ *
17
+ * Development mode is used when developing KiCI itself.
18
+ * Checks:
19
+ * 1. KICI_DEV environment variable
20
+ * 2. Root package.json kici.development flag
21
+ *
22
+ * @returns true if in development mode
23
+ */
24
+ async function detectDevelopmentMode() {
25
+ if (process.env.KICI_DEV === "true") return true;
26
+ try {
27
+ const rootDir = process.env.INIT_CWD || process.cwd();
28
+ const content = await readFile(path.join(rootDir, "package.json"), "utf-8");
29
+ return JSON.parse(content).kici?.development === true;
30
+ } catch {
31
+ return false;
32
+ }
33
+ }
34
+ async function main() {
35
+ if (await detectDevelopmentMode()) return;
36
+ if (process.env.CI === "true" || !process.stdout.isTTY) return;
37
+ const fs = await import("node:fs/promises");
38
+ try {
39
+ await fs.access(".kici");
40
+ return;
41
+ } catch {}
42
+ console.log("\n");
43
+ if (await confirm({
44
+ message: "Would you like to initialize .kici/ directory now?",
45
+ default: true
46
+ })) {
47
+ console.log("\nRunning kici init...\n");
48
+ spawn("npx", ["kici", "init"], {
49
+ stdio: "inherit",
50
+ shell: true
51
+ }).on("error", (err) => {
52
+ console.error("Failed to run kici init:", err.message);
53
+ });
54
+ } else console.log("\nYou can run \"npx kici init\" later to set up workflows.\n");
55
+ }
56
+ main().catch(() => {});
57
+ //#endregion
58
+ export {};
59
+
60
+ //# sourceMappingURL=postinstall.js.map
@@ -0,0 +1,28 @@
1
+ {
2
+ "action": "closed",
3
+ "number": 1,
4
+ "pull_request": {
5
+ "number": 1,
6
+ "title": "Test PR",
7
+ "state": "closed",
8
+ "merged": false,
9
+ "head": {
10
+ "ref": "feature-branch",
11
+ "sha": "abc123"
12
+ },
13
+ "base": {
14
+ "ref": "main",
15
+ "sha": "def456"
16
+ }
17
+ },
18
+ "repository": {
19
+ "name": "test-repo",
20
+ "full_name": "owner/test-repo",
21
+ "owner": {
22
+ "login": "owner"
23
+ }
24
+ },
25
+ "sender": {
26
+ "login": "user"
27
+ }
28
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "action": "opened",
3
+ "number": 1,
4
+ "pull_request": {
5
+ "number": 1,
6
+ "title": "Test PR",
7
+ "state": "open",
8
+ "head": {
9
+ "ref": "feature-branch",
10
+ "sha": "abc123"
11
+ },
12
+ "base": {
13
+ "ref": "main",
14
+ "sha": "def456"
15
+ }
16
+ },
17
+ "repository": {
18
+ "name": "test-repo",
19
+ "full_name": "owner/test-repo",
20
+ "owner": {
21
+ "login": "owner"
22
+ }
23
+ },
24
+ "sender": {
25
+ "login": "user"
26
+ }
27
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "action": "reopened",
3
+ "number": 1,
4
+ "pull_request": {
5
+ "number": 1,
6
+ "title": "Test PR",
7
+ "state": "open",
8
+ "head": {
9
+ "ref": "feature-branch",
10
+ "sha": "abc123"
11
+ },
12
+ "base": {
13
+ "ref": "main",
14
+ "sha": "def456"
15
+ }
16
+ },
17
+ "repository": {
18
+ "name": "test-repo",
19
+ "full_name": "owner/test-repo",
20
+ "owner": {
21
+ "login": "owner"
22
+ }
23
+ },
24
+ "sender": {
25
+ "login": "user"
26
+ }
27
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "action": "synchronize",
3
+ "number": 1,
4
+ "pull_request": {
5
+ "number": 1,
6
+ "title": "Test PR",
7
+ "state": "open",
8
+ "head": {
9
+ "ref": "feature-branch",
10
+ "sha": "abc123"
11
+ },
12
+ "base": {
13
+ "ref": "main",
14
+ "sha": "def456"
15
+ }
16
+ },
17
+ "repository": {
18
+ "name": "test-repo",
19
+ "full_name": "owner/test-repo",
20
+ "owner": {
21
+ "login": "owner"
22
+ }
23
+ },
24
+ "sender": {
25
+ "login": "user"
26
+ }
27
+ }
package/dist/push.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "ref": "refs/heads/main",
3
+ "before": "000000",
4
+ "after": "abc123",
5
+ "repository": {
6
+ "name": "test-repo",
7
+ "full_name": "owner/test-repo",
8
+ "owner": {
9
+ "login": "owner"
10
+ }
11
+ },
12
+ "pusher": {
13
+ "name": "user"
14
+ },
15
+ "commits": []
16
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "action": "published",
3
+ "release": {
4
+ "id": 1,
5
+ "tag_name": "v1.0.0",
6
+ "target_commitish": "main",
7
+ "name": "v1.0.0",
8
+ "draft": false,
9
+ "prerelease": false,
10
+ "body": "Release notes"
11
+ },
12
+ "repository": {
13
+ "name": "test-repo",
14
+ "full_name": "test-org/test-repo",
15
+ "owner": {
16
+ "login": "test-org"
17
+ },
18
+ "default_branch": "main"
19
+ },
20
+ "sender": {
21
+ "login": "test-user"
22
+ }
23
+ }