@visulima/task-runner 0.0.1 → 1.0.0-alpha.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 (89) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/LICENSE.md +21 -0
  3. package/README.md +170 -36
  4. package/binding.js +204 -0
  5. package/dist/affected.d.ts +48 -0
  6. package/dist/cache.d.ts +103 -0
  7. package/dist/default-task-runner.d.ts +44 -0
  8. package/dist/file-access-tracker.d.ts +53 -0
  9. package/dist/fingerprint.d.ts +45 -0
  10. package/dist/framework-inference.d.ts +35 -0
  11. package/dist/graph-visualizer.d.ts +74 -0
  12. package/dist/incremental-hasher.d.ts +58 -0
  13. package/dist/index.d.ts +34 -0
  14. package/dist/index.js +20 -0
  15. package/dist/life-cycle.d.ts +36 -0
  16. package/dist/lockfile-hasher.d.ts +73 -0
  17. package/dist/native-binding.d.ts +64 -0
  18. package/dist/packem_shared/Cache-IYpTYVUC.js +298 -0
  19. package/dist/packem_shared/CompositeLifeCycle-7AtYw1dv.js +112 -0
  20. package/dist/packem_shared/FileAccessTracker-CrtBAt5D.js +239 -0
  21. package/dist/packem_shared/FingerprintManager-D6Y0erg-.js +227 -0
  22. package/dist/packem_shared/IncrementalFileHasher-Ds3J6dgb.js +151 -0
  23. package/dist/packem_shared/RemoteCache-BDqrnDEi.js +179 -0
  24. package/dist/packem_shared/TaskOrchestrator-BvYs3ONw.js +342 -0
  25. package/dist/packem_shared/TaskScheduler-CJilHDta.js +111 -0
  26. package/dist/packem_shared/TrackedTaskExecutor-BGUKFE-7.js +164 -0
  27. package/dist/packem_shared/collectFiles-ClXHnHhg.js +22 -0
  28. package/dist/packem_shared/computeTaskHash-BoCnnvIJ.js +356 -0
  29. package/dist/packem_shared/createTaskGraph-CcsFaSrz.js +164 -0
  30. package/dist/packem_shared/defaultTaskRunner-CrW4v5Ye.js +79 -0
  31. package/dist/packem_shared/detectFrameworks-CeFzKE6J.js +101 -0
  32. package/dist/packem_shared/extractPackageName-CbVNW-dr.js +189 -0
  33. package/dist/packem_shared/filterAffectedTasks-I-18zPg6.js +135 -0
  34. package/dist/packem_shared/findCycle-DF4_BRdO.js +212 -0
  35. package/dist/packem_shared/generateRunSummary-qn-_jKwt.js +134 -0
  36. package/dist/packem_shared/isNativeAvailable-BWhnZ4ES.js +19 -0
  37. package/dist/packem_shared/projectGraphToDot-VdTjHcVp.js +202 -0
  38. package/dist/packem_shared/utils-zO0ZRgtf.js +390 -0
  39. package/dist/remote-cache.d.ts +55 -0
  40. package/dist/run-summary.d.ts +89 -0
  41. package/dist/task-graph-utils.d.ts +39 -0
  42. package/dist/task-graph.d.ts +22 -0
  43. package/dist/task-hasher.d.ts +67 -0
  44. package/dist/task-orchestrator.d.ts +38 -0
  45. package/dist/task-scheduler.d.ts +18 -0
  46. package/dist/tracked-executor.d.ts +46 -0
  47. package/dist/types.d.ts +385 -0
  48. package/dist/utils.d.ts +39 -0
  49. package/npm/darwin-arm64/LICENSE.md +21 -0
  50. package/npm/darwin-arm64/node_modules/.bin/semantic-release +21 -0
  51. package/npm/darwin-arm64/package.json +39 -0
  52. package/npm/darwin-arm64/task-runner-native.darwin-arm64.node +0 -0
  53. package/npm/darwin-x64/LICENSE.md +21 -0
  54. package/npm/darwin-x64/node_modules/.bin/semantic-release +21 -0
  55. package/npm/darwin-x64/package.json +39 -0
  56. package/npm/darwin-x64/task-runner-native.darwin-x64.node +0 -0
  57. package/npm/linux-arm64-gnu/LICENSE.md +21 -0
  58. package/npm/linux-arm64-gnu/node_modules/.bin/semantic-release +21 -0
  59. package/npm/linux-arm64-gnu/package.json +42 -0
  60. package/npm/linux-arm64-gnu/task-runner-native.linux-arm64-gnu.node +0 -0
  61. package/npm/linux-arm64-musl/LICENSE.md +21 -0
  62. package/npm/linux-arm64-musl/node_modules/.bin/semantic-release +21 -0
  63. package/npm/linux-arm64-musl/package.json +42 -0
  64. package/npm/linux-arm64-musl/task-runner-native.linux-arm64-musl.node +0 -0
  65. package/npm/linux-x64-gnu/LICENSE.md +21 -0
  66. package/npm/linux-x64-gnu/node_modules/.bin/semantic-release +21 -0
  67. package/npm/linux-x64-gnu/package.json +42 -0
  68. package/npm/linux-x64-gnu/task-runner-native.linux-x64-gnu.node +0 -0
  69. package/npm/linux-x64-musl/LICENSE.md +21 -0
  70. package/npm/linux-x64-musl/node_modules/.bin/semantic-release +21 -0
  71. package/npm/linux-x64-musl/package.json +42 -0
  72. package/npm/linux-x64-musl/task-runner-native.linux-x64-musl.node +0 -0
  73. package/npm/win32-arm64-msvc/LICENSE.md +21 -0
  74. package/npm/win32-arm64-msvc/node_modules/.bin/semantic-release +21 -0
  75. package/npm/win32-arm64-msvc/package.json +39 -0
  76. package/npm/win32-arm64-msvc/task-runner-native.win32-arm64-msvc.node +0 -0
  77. package/npm/win32-x64-msvc/LICENSE.md +21 -0
  78. package/npm/win32-x64-msvc/node_modules/.bin/semantic-release +21 -0
  79. package/npm/win32-x64-msvc/package.json +39 -0
  80. package/npm/win32-x64-msvc/task-runner-native.win32-x64-msvc.node +0 -0
  81. package/package.json +74 -7
  82. package/task-runner-native.darwin-arm64.node +0 -0
  83. package/task-runner-native.darwin-x64.node +0 -0
  84. package/task-runner-native.linux-arm64-gnu.node +0 -0
  85. package/task-runner-native.linux-arm64-musl.node +0 -0
  86. package/task-runner-native.linux-x64-gnu.node +0 -0
  87. package/task-runner-native.linux-x64-musl.node +0 -0
  88. package/task-runner-native.win32-arm64-msvc.node +0 -0
  89. package/task-runner-native.win32-x64-msvc.node +0 -0
@@ -0,0 +1,89 @@
1
+ import type { TaskGraph, TaskHashDetails, TaskResults } from "./types.d.ts";
2
+ /**
3
+ * Summary of a single task execution.
4
+ */
5
+ interface TaskSummary {
6
+ /** Whether the task was cacheable */
7
+ cacheable: boolean;
8
+ /** Cache status */
9
+ cacheStatus: "HIT" | "MISS" | "REMOTE_HIT" | "SKIPPED";
10
+ /** Dependencies on other tasks */
11
+ dependencies: string[];
12
+ /** Duration in milliseconds */
13
+ duration: number | undefined;
14
+ /** End time (ISO 8601) */
15
+ endTime: string | undefined;
16
+ /** Exit code */
17
+ exitCode: number | undefined;
18
+ /** The computed cache hash */
19
+ hash: string | undefined;
20
+ /** Detailed hash information */
21
+ hashDetails: TaskHashDetails | undefined;
22
+ /** The task's declared outputs */
23
+ outputs: string[];
24
+ /** Start time (ISO 8601) */
25
+ startTime: string | undefined;
26
+ /** The task target */
27
+ target: {
28
+ configuration?: string;
29
+ project: string;
30
+ target: string;
31
+ };
32
+ /** The task ID (e.g., "app:build") */
33
+ taskId: string;
34
+ }
35
+ /**
36
+ * Complete summary of a task runner execution.
37
+ */
38
+ interface RunSummary {
39
+ /** Total duration in milliseconds */
40
+ duration: number;
41
+ /** Run end time (ISO 8601) */
42
+ endTime: string;
43
+ /** Environment info */
44
+ environment: {
45
+ /** Architecture */
46
+ arch: string;
47
+ /** Node.js version */
48
+ nodeVersion: string;
49
+ /** Platform */
50
+ platform: string;
51
+ };
52
+ /** Unique run ID */
53
+ id: string;
54
+ /** Run start time (ISO 8601) */
55
+ startTime: string;
56
+ /** Overall execution statistics */
57
+ stats: {
58
+ /** Number of cached tasks (local + remote) */
59
+ cached: number;
60
+ /** Number of failed tasks */
61
+ failed: number;
62
+ /** Number of skipped tasks */
63
+ skipped: number;
64
+ /** Number of successful tasks */
65
+ succeeded: number;
66
+ /** Total number of tasks */
67
+ total: number;
68
+ };
69
+ /** The task graph used for this run */
70
+ taskGraph: {
71
+ dependencies: Record<string, string[]>;
72
+ roots: string[];
73
+ };
74
+ /** Summary of each task */
75
+ tasks: TaskSummary[];
76
+ }
77
+ /**
78
+ * Generates a run summary from task results.
79
+ */
80
+ declare const generateRunSummary: (results: TaskResults, taskGraph: TaskGraph, startTime: number) => RunSummary;
81
+ /**
82
+ * Writes the run summary to a JSON file in the `.task-runner/runs/` directory.
83
+ * @param summary The run summary to write
84
+ * @param workspaceRoot The workspace root directory
85
+ * @returns The path to the written summary file
86
+ */
87
+ declare const writeRunSummary: (summary: RunSummary, workspaceRoot: string) => Promise<string>;
88
+ export type { RunSummary, TaskSummary };
89
+ export { generateRunSummary, writeRunSummary };
@@ -0,0 +1,39 @@
1
+ import type { TaskGraph } from "./types.d.ts";
2
+ /**
3
+ * Finds a single cycle in the task graph, if one exists.
4
+ * Returns the cycle as an array of task IDs, or null if no cycle exists.
5
+ */
6
+ export declare const findCycle: (taskGraph: TaskGraph) => string[] | undefined;
7
+ /**
8
+ * Finds all cycles in the task graph.
9
+ */
10
+ export declare const findCycles: (taskGraph: TaskGraph) => string[][];
11
+ /**
12
+ * Walks the task graph in topological order (dependencies before dependents),
13
+ * calling the callback for each task.
14
+ *
15
+ * Note: If the graph contains cycles, tasks involved in cycles will not be visited.
16
+ * Use `findCycle` to detect cycles before walking if complete traversal is required.
17
+ */
18
+ export declare const walkTaskGraph: (taskGraph: TaskGraph, callback: (taskId: string) => void) => void;
19
+ /**
20
+ * Returns a reversed copy of the task graph (edges point in the opposite direction).
21
+ */
22
+ export declare const reverseTaskGraph: (taskGraph: TaskGraph) => TaskGraph;
23
+ /**
24
+ * Returns the leaf tasks (tasks with no dependencies of their own).
25
+ */
26
+ export declare const getLeafTasks: (taskGraph: TaskGraph) => string[];
27
+ /**
28
+ * Removes edges that form cycles, making the graph acyclic.
29
+ * Returns a new task graph without the cycle-forming edges.
30
+ */
31
+ export declare const makeAcyclic: (taskGraph: TaskGraph) => TaskGraph;
32
+ /**
33
+ * Gets all tasks that depend on the given task (directly or transitively).
34
+ */
35
+ export declare const getDependentTasks: (taskGraph: TaskGraph, taskId: string) => string[];
36
+ /**
37
+ * Gets all tasks that the given task depends on (directly or transitively).
38
+ */
39
+ export declare const getTransitiveDependencies: (taskGraph: TaskGraph, taskId: string) => string[];
@@ -0,0 +1,22 @@
1
+ import type { ProjectGraph, TargetConfiguration, Task, TaskGraph, TaskTarget, WorkspaceConfiguration } from "./types.d.ts";
2
+ interface CreateTaskGraphOptions {
3
+ /** The project graph */
4
+ projectGraph: ProjectGraph;
5
+ /** Target default configurations */
6
+ targetDefaults?: Record<string, Partial<TargetConfiguration>>;
7
+ /** The workspace configuration */
8
+ workspace: WorkspaceConfiguration;
9
+ }
10
+ /**
11
+ * Creates a unique task ID from a target.
12
+ */
13
+ declare const getTaskId: (target: TaskTarget) => string;
14
+ /**
15
+ * Parses a task ID into its component parts.
16
+ */
17
+ declare const parseTaskId: (taskId: string) => TaskTarget;
18
+ /**
19
+ * Creates a task graph from a list of tasks, resolving all dependencies.
20
+ */
21
+ declare const createTaskGraph: (initialTasks: Task[], options: CreateTaskGraphOptions) => TaskGraph;
22
+ export { createTaskGraph, getTaskId, parseTaskId };
@@ -0,0 +1,67 @@
1
+ import type { NamedInputs, ProjectConfiguration, TargetConfiguration, Task, TaskHashDetails } from "./types.d.ts";
2
+ /**
3
+ * Interface for task hashers.
4
+ */
5
+ interface TaskHasher {
6
+ hashTask: (task: Task) => Promise<TaskHashDetails>;
7
+ }
8
+ /**
9
+ * Options for creating an InProcessTaskHasher.
10
+ */
11
+ interface TaskHasherOptions {
12
+ /** Additional environment variables to include in hash */
13
+ envVars?: string[];
14
+ /**
15
+ * Enable framework environment variable inference.
16
+ * When true, auto-detects frameworks and includes their public
17
+ * env var prefixes in the task hash.
18
+ * @default false
19
+ */
20
+ frameworkInference?: boolean;
21
+ /**
22
+ * Global environment variables that invalidate all task hashes.
23
+ */
24
+ globalEnv?: string[];
25
+ /**
26
+ * Global input files that invalidate all task hashes when changed.
27
+ * These are workspace-root-relative paths (e.g., "pnpm-lock.yaml").
28
+ */
29
+ globalInputs?: string[];
30
+ /** Named input definitions */
31
+ namedInputs?: NamedInputs;
32
+ /** Project configurations keyed by project name */
33
+ projects: Record<string, ProjectConfiguration>;
34
+ /**
35
+ * Enable smart lockfile hashing.
36
+ * When true, instead of hashing the entire lockfile, only the resolved
37
+ * versions of a package's actual dependencies are hashed.
38
+ * This means changing the lockfile only busts cache for affected packages.
39
+ *
40
+ * Matches Turborepo's smart lockfile hashing behavior.
41
+ * @default false
42
+ */
43
+ smartLockfileHashing?: boolean;
44
+ /** Target default configurations */
45
+ targetDefaults?: Record<string, Partial<TargetConfiguration>>;
46
+ /** The workspace root directory */
47
+ workspaceRoot: string;
48
+ }
49
+ /**
50
+ * Computes hashes for tasks based on their inputs.
51
+ * Used to determine if a cached result can be reused.
52
+ */
53
+ declare class InProcessTaskHasher implements TaskHasher {
54
+ #private;
55
+ constructor(options: TaskHasherOptions);
56
+ hashTask(task: Task): Promise<TaskHashDetails>;
57
+ clearCache(): void;
58
+ }
59
+ /**
60
+ * Computes the final hash for a task from its hash details.
61
+ * Uses native Rust xxh3-128 when available, otherwise pure TS xxh3-ts.
62
+ * Both produce identical xxh3-128 hashes, ensuring cache compatibility
63
+ * regardless of whether the native addon is loaded.
64
+ */
65
+ declare const computeTaskHash: (hashDetails: TaskHashDetails) => string;
66
+ export { computeTaskHash, InProcessTaskHasher };
67
+ export type { TaskHasher, TaskHasherOptions };
@@ -0,0 +1,38 @@
1
+ import type { Cache } from "./cache.d.ts";
2
+ import type { RemoteCache } from "./remote-cache.d.ts";
3
+ import type { TaskHasher } from "./task-hasher.d.ts";
4
+ import type { TaskScheduler } from "./task-scheduler.d.ts";
5
+ import type { LifeCycleInterface, Task, TaskExecutor, TaskResults } from "./types.d.ts";
6
+ /**
7
+ * Options for the TaskOrchestrator.
8
+ */
9
+ interface TaskOrchestratorOptions {
10
+ autoFingerprint?: boolean;
11
+ cache: Cache;
12
+ cacheDiagnostics?: boolean;
13
+ captureOutput?: boolean;
14
+ dryRun?: boolean;
15
+ fingerprintEnvPatterns?: string[];
16
+ lifeCycle: LifeCycleInterface;
17
+ remoteCache?: RemoteCache;
18
+ resolveCommand?: (task: Task) => string | undefined;
19
+ scheduler: TaskScheduler;
20
+ skipCache?: boolean;
21
+ summarize?: boolean;
22
+ taskExecutor: TaskExecutor;
23
+ taskGraph?: import("./types").TaskGraph;
24
+ taskHasher: TaskHasher;
25
+ untrackedEnvVars?: string[];
26
+ workspaceRoot: string;
27
+ }
28
+ /**
29
+ * Orchestrates the execution of tasks, handling caching,
30
+ * scheduling, and lifecycle events.
31
+ */
32
+ declare class TaskOrchestrator {
33
+ #private;
34
+ constructor(options: TaskOrchestratorOptions);
35
+ run(): Promise<TaskResults>;
36
+ }
37
+ export { TaskOrchestrator };
38
+ export type { TaskOrchestratorOptions };
@@ -0,0 +1,18 @@
1
+ import type { ProjectGraph, Task, TaskGraph } from "./types.d.ts";
2
+ /**
3
+ * Manages the scheduling order of tasks based on dependencies,
4
+ * parallelism constraints, and estimated execution times.
5
+ */
6
+ export declare class TaskScheduler {
7
+ #private;
8
+ constructor(taskGraph: TaskGraph, projectGraph: ProjectGraph, maxParallel?: number);
9
+ /**
10
+ * Returns the next batch of tasks that are ready to execute.
11
+ */
12
+ getNextBatch(): Task[];
13
+ startTask(taskId: string): void;
14
+ completeTask(taskId: string): void;
15
+ isComplete(): boolean;
16
+ get remainingCount(): number;
17
+ get runningCount(): number;
18
+ }
@@ -0,0 +1,46 @@
1
+ import type { FileAccess } from "./file-access-tracker.d.ts";
2
+ import type { Task, TaskExecutionOptions } from "./types.d.ts";
3
+ /**
4
+ * Result of a tracked task execution.
5
+ */
6
+ export interface TrackedExecutionResult {
7
+ /** File accesses recorded during execution */
8
+ accesses: FileAccess[];
9
+ /** The command exit code */
10
+ code: number;
11
+ /** The command stdout + stderr output */
12
+ terminalOutput: string;
13
+ }
14
+ /**
15
+ * A task executor that tracks file accesses during command execution.
16
+ *
17
+ * Tracking strategies (in priority order):
18
+ * 1. **Linux**: strace-based syscall interception (most complete)
19
+ * 2. **macOS/Windows**: Node.js preload script that patches `fs` module
20
+ * (works for Node.js processes, not native binaries)
21
+ * 3. **Fallback**: No tracking (accesses array will be empty)
22
+ */
23
+ export declare class TrackedTaskExecutor {
24
+ #private;
25
+ constructor(workspaceRoot: string);
26
+ /**
27
+ * Returns true if file access tracking is supported on the current platform.
28
+ * strace tracking (Linux) or preload script (any Node.js process).
29
+ */
30
+ get isTrackingSupported(): boolean;
31
+ /**
32
+ * Returns true if the platform supports full syscall-level tracking (strace).
33
+ */
34
+ get isStraceSupported(): boolean;
35
+ /**
36
+ * Executes a task command and tracks all file system accesses.
37
+ *
38
+ * On Linux, uses strace for comprehensive tracking.
39
+ * On other platforms, uses a Node.js preload script (for Node processes).
40
+ */
41
+ execute(task: Task, options: TaskExecutionOptions, command: string): Promise<TrackedExecutionResult>;
42
+ /**
43
+ * Kills all active child processes. Called on abort/signal to prevent orphans.
44
+ */
45
+ killAll(): void;
46
+ }