@tagma/sdk 0.7.35 → 0.7.37

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.
package/README.md CHANGED
@@ -339,6 +339,8 @@ Tasks can declare named, typed `inputs` / `outputs`. Inputs flow in from upstrea
339
339
 
340
340
  ### Built-in Triggers
341
341
 
342
+ File and directory trigger watch paths may be relative to `workDir`, absolute, or external. This exception is only for trigger watch paths; other path fields remain workspace-bound.
343
+
342
344
  #### `manual` — Human approval gate
343
345
 
344
346
  | Field | Type | Required | Default | Description |
@@ -356,6 +358,14 @@ Tasks can declare named, typed `inputs` / `outputs`. Inputs flow in from upstrea
356
358
  | `path` | `string` | Yes | — | File path to watch (relative to workDir) |
357
359
  | `timeout` | `string` | No | — | How long to wait for the file to appear/change |
358
360
 
361
+ #### `directory` - Directory watcher gate
362
+
363
+ | Field | Type | Required | Default | Description |
364
+ | --------- | ------------- | -------- | ------- | ------------------------------------------------ |
365
+ | `type` | `"directory"` | Yes | — | Trigger type |
366
+ | `path` | `string` | Yes | — | Directory path to watch (relative to workDir) |
367
+ | `timeout` | `string` | No | — | How long to wait for the directory to be created |
368
+
359
369
  ---
360
370
 
361
371
  ### Built-in Completions
@@ -401,6 +411,10 @@ Tasks can declare named, typed `inputs` / `outputs`. Inputs flow in from upstrea
401
411
  ### Root: `@tagma/sdk`
402
412
 
403
413
  - `createTagma(options?)`
414
+ - `createTagma().run(config, options)` for either a single `PipelineConfig` or a `PipelineGraphConfig`
415
+ - `createTagma().runYaml(content, options)` for either `pipeline:` or `workflow:` YAML documents
416
+ - `detectTagmaYamlKind(content)`
417
+ - `loadTagmaYaml(content, workDir)`
404
418
  - `bunRuntime()`
405
419
  - `definePipeline(pipeline)`
406
420
  - `PluginRegistry`
@@ -416,6 +430,10 @@ Tasks can declare named, typed `inputs` / `outputs`. Inputs flow in from upstrea
416
430
  - `deresolvePipeline(config, workDir)`
417
431
  - `validateConfig(config)`
418
432
  - `compileYamlContent(content, options?)`
433
+ - `loadWorkflow(yaml, workDir)`
434
+ - `parseWorkflowYaml(content)`
435
+ - `serializeWorkflow(config)`
436
+ - `validateRawWorkflow(config)`
419
437
 
420
438
  ### Plugins: `@tagma/sdk/plugins`
421
439
 
@@ -464,7 +482,7 @@ These ship in `@tagma/runtime-bun`, not `@tagma/sdk` — when you `bun add @tagm
464
482
 
465
483
  ### `bootstrapBuiltins(registry)`
466
484
 
467
- Registers all built-in plugins (opencode driver, file/manual triggers, completion checks, static-context middleware).
485
+ Registers all built-in plugins (opencode driver, file/directory/manual triggers, completion checks, static-context middleware).
468
486
 
469
487
  ### `loadPipeline(yaml: string, workDir: string): Promise<PipelineConfig>`
470
488
 
@@ -479,11 +497,11 @@ Options:
479
497
  - `registry` -- use an existing `PluginRegistry` instance
480
498
  - `builtins` -- register built-in plugins into the instance registry; defaults to `true`
481
499
  - `plugins` -- register package-level `TagmaPlugin` capability objects into the instance registry
482
- - `runtime` -- override process execution, file watching, file existence checks, log storage, time, and sleep; defaults to `bunRuntime()`
500
+ - `runtime` -- override process execution, file/directory watching, file/directory existence checks, log storage, time, and sleep; defaults to `bunRuntime()`
483
501
 
484
502
  ### `createTagma().run(config, options): Promise<EngineResult>`
485
503
 
486
- Executes the pipeline. Returns `{ success, runId, logPath, summary, states }`.
504
+ Executes a single pipeline. Returns `{ success, runId, logPath, summary, states }`.
487
505
 
488
506
  Options:
489
507
 
@@ -506,6 +524,31 @@ Options:
506
524
 
507
525
  > **stdout / stderr persistence.** With the default Bun runtime, the engine streams every task's stdout and stderr to disk under `<workDir>/.tagma/logs/<runId>/<taskId>.stdout` and `.stderr`. Custom runtimes can relocate those artifacts by implementing `runtime.logStore.taskOutputPath()`. The `TaskResult.stdout` / `stderr` strings are bounded tails (8 MB / 4 MB by default) — long outputs are truncated from the head with a marker, and consumers that need the full bytes should read `TaskResult.stdoutPath` / `stderrPath`. Use `TaskResult.stdoutBytes` / `stderrBytes` to display "32 MB (truncated)" without re-stat'ing the file.
508
526
 
527
+ ### Workflow graph YAML
528
+
529
+ Workflow graph YAML wraps multiple pipeline YAML files and lets the SDK execute them with graph-level dependencies and pipeline lifecycle controls.
530
+
531
+ ```yaml
532
+ workflow:
533
+ kind: graph
534
+ name: release-flow
535
+ max_concurrency: 2
536
+ failure_policy: stop_all
537
+ pipelines:
538
+ - id: build
539
+ path: .tagma/build/build.yaml
540
+ lifecycle:
541
+ max_runs: 3
542
+ stop_when: success
543
+ - id: deploy
544
+ path: .tagma/deploy/deploy.yaml
545
+ depends_on: [build]
546
+ ```
547
+
548
+ Per-pipeline `lifecycle.max_runs` defaults to `1`. `lifecycle.stop_when` defaults to `success`; supported values are `success` (retry until the first successful run or the max is reached), `failure` (run until the first failed run or the max is reached), and `always` (run exactly `max_runs` attempts unless aborted). Graph results include `runCount`, `maxRuns`, and per-attempt state on each pipeline node.
549
+
550
+ `createTagma().run(graphConfig, options)` runs a programmatic `PipelineGraphConfig`. `createTagma().runYaml(content, options)` detects either top-level `pipeline:` or `workflow:` YAML and returns `{ kind: 'pipeline' | 'workflow', result }`, so CLI hosts can route one file path through one SDK call.
551
+
509
552
  ### `PipelineRunner`
510
553
 
511
554
  Higher-level wrapper for managing multiple concurrent pipeline runs — designed for sidecar / Tauri IPC scenarios where the frontend controls pipeline lifecycle by ID.
@@ -546,7 +589,7 @@ Properties:
546
589
 
547
590
  Typed error classes for trigger plugin error classification. The engine uses `instanceof` checks on these to set the correct task status (`blocked` or `timeout`) instead of matching on error message substrings.
548
591
 
549
- Built-in triggers (`manual`, `file`) throw these automatically. Trigger plugins should throw `TriggerBlockedError` for user/policy rejections and `TriggerTimeoutError` for genuine wait timeouts.
592
+ Built-in triggers (`manual`, `file`, `directory`) throw these automatically. Trigger plugins should throw `TriggerBlockedError` for user/policy rejections and `TriggerTimeoutError` for genuine wait timeouts.
550
593
 
551
594
  ```ts
552
595
  import { TriggerBlockedError, TriggerTimeoutError } from '@tagma/sdk';
@@ -1,18 +1,66 @@
1
1
  import type { PluginRegistry } from '@tagma/core';
2
- export declare const BuiltinTagmaPlugin: {
2
+ /**
3
+ * Safe-mode built-ins: plugins that do not execute arbitrary code or shell
4
+ * commands. These are registered with `{ safeMode: true }` and are available
5
+ * under `mode: 'safe'` pipelines without explicit allowlist entries.
6
+ */
7
+ export declare const SafeBuiltinTagmaPlugin: {
3
8
  name: string;
4
9
  capabilities: {
5
10
  drivers: {
6
11
  opencode: import("@tagma/types").DriverPlugin;
7
12
  };
8
13
  triggers: {
14
+ directory: import("@tagma/types").TriggerPlugin;
9
15
  file: import("@tagma/types").TriggerPlugin;
10
16
  manual: import("@tagma/types").TriggerPlugin;
11
17
  };
12
18
  completions: {
13
19
  exit_code: import("@tagma/types").CompletionPlugin;
14
20
  file_exists: import("@tagma/types").CompletionPlugin;
21
+ };
22
+ middlewares: {
23
+ static_context: import("@tagma/types").MiddlewarePlugin;
24
+ };
25
+ };
26
+ };
27
+ /**
28
+ * Unsafe built-ins: plugins that execute arbitrary shell commands and must
29
+ * NOT be in the safe-mode allowlist. These require explicit caller opt-in
30
+ * via `safeModeAllowlist` or `mode: 'trusted'`.
31
+ *
32
+ * `output_check` pipes task output into a user-specified shell command,
33
+ * which is a direct command-execution vector. Including it in safe mode
34
+ * would bypass the safe-mode intent that blocks command execution.
35
+ */
36
+ export declare const UnsafeBuiltinTagmaPlugin: {
37
+ name: string;
38
+ capabilities: {
39
+ completions: {
40
+ output_check: import("@tagma/types").CompletionPlugin;
41
+ };
42
+ };
43
+ };
44
+ /**
45
+ * Combined built-in plugin bundle for backward compatibility. Includes both
46
+ * safe and unsafe plugins. Use `bootstrapBuiltins()` to register with
47
+ * proper safe-mode scoping.
48
+ */
49
+ export declare const BuiltinTagmaPlugin: {
50
+ name: string;
51
+ capabilities: {
52
+ drivers: {
53
+ opencode: import("@tagma/types").DriverPlugin;
54
+ };
55
+ triggers: {
56
+ directory: import("@tagma/types").TriggerPlugin;
57
+ file: import("@tagma/types").TriggerPlugin;
58
+ manual: import("@tagma/types").TriggerPlugin;
59
+ };
60
+ completions: {
15
61
  output_check: import("@tagma/types").CompletionPlugin;
62
+ exit_code: import("@tagma/types").CompletionPlugin;
63
+ file_exists: import("@tagma/types").CompletionPlugin;
16
64
  };
17
65
  middlewares: {
18
66
  static_context: import("@tagma/types").MiddlewarePlugin;
@@ -27,6 +75,14 @@ export declare const BuiltinTagmaPlugin: {
27
75
  *
28
76
  * Built-in handlers are stateless module singletons — registering the same
29
77
  * handler object into N registries is cheap and safe; no cloning is needed.
78
+ *
79
+ * Safe built-ins register with `{ safeMode: true }` so they are automatically
80
+ * available under `mode: 'safe'` pipelines without explicit allowlist entries.
81
+ * Unsafe built-ins (output_check, which executes arbitrary shell commands)
82
+ * register WITHOUT safeMode, requiring explicit caller opt-in.
83
+ *
84
+ * The registry's `getSafeModeDefaults()` surfaces these to the engine's 3-way
85
+ * safe-mode merge (hardcoded defaults ∪ registry-declared ∪ caller-supplied).
30
86
  */
31
87
  export declare function bootstrapBuiltins(target: PluginRegistry): void;
32
88
  //# sourceMappingURL=bootstrap.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAsBlD,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;CAmBR,CAAC;AAExB;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI,CAE9D"}
1
+ {"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAuBlD;;;;GAIG;AACH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;CAmBZ,CAAC;AAExB;;;;;;;;GAQG;AACH,eAAO,MAAM,wBAAwB;;;;;;;CAOd,CAAC;AAExB;;;;GAIG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;CAWR,CAAC;AAExB;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI,CAG9D"}
package/dist/bootstrap.js CHANGED
@@ -7,32 +7,72 @@ import { OpenCodeDriver } from './drivers/opencode';
7
7
  // Built-in Triggers
8
8
  import { FileTrigger } from './triggers/file';
9
9
  import { ManualTrigger } from './triggers/manual';
10
+ import { DirectoryTrigger } from './triggers/directory';
10
11
  // Built-in Completions
11
12
  import { ExitCodeCompletion } from './completions/exit-code';
12
13
  import { FileExistsCompletion } from './completions/file-exists';
13
14
  import { OutputCheckCompletion } from './completions/output-check';
14
15
  // Built-in Middleware
15
16
  import { StaticContextMiddleware } from './middlewares/static-context';
16
- export const BuiltinTagmaPlugin = {
17
- name: '@tagma/sdk/builtins',
17
+ /**
18
+ * Safe-mode built-ins: plugins that do not execute arbitrary code or shell
19
+ * commands. These are registered with `{ safeMode: true }` and are available
20
+ * under `mode: 'safe'` pipelines without explicit allowlist entries.
21
+ */
22
+ export const SafeBuiltinTagmaPlugin = {
23
+ name: '@tagma/sdk/builtins-safe',
18
24
  capabilities: {
19
25
  drivers: {
20
26
  opencode: OpenCodeDriver,
21
27
  },
22
28
  triggers: {
29
+ directory: DirectoryTrigger,
23
30
  file: FileTrigger,
24
31
  manual: ManualTrigger,
25
32
  },
26
33
  completions: {
27
34
  exit_code: ExitCodeCompletion,
28
35
  file_exists: FileExistsCompletion,
29
- output_check: OutputCheckCompletion,
30
36
  },
31
37
  middlewares: {
32
38
  static_context: StaticContextMiddleware,
33
39
  },
34
40
  },
35
41
  };
42
+ /**
43
+ * Unsafe built-ins: plugins that execute arbitrary shell commands and must
44
+ * NOT be in the safe-mode allowlist. These require explicit caller opt-in
45
+ * via `safeModeAllowlist` or `mode: 'trusted'`.
46
+ *
47
+ * `output_check` pipes task output into a user-specified shell command,
48
+ * which is a direct command-execution vector. Including it in safe mode
49
+ * would bypass the safe-mode intent that blocks command execution.
50
+ */
51
+ export const UnsafeBuiltinTagmaPlugin = {
52
+ name: '@tagma/sdk/builtins-unsafe',
53
+ capabilities: {
54
+ completions: {
55
+ output_check: OutputCheckCompletion,
56
+ },
57
+ },
58
+ };
59
+ /**
60
+ * Combined built-in plugin bundle for backward compatibility. Includes both
61
+ * safe and unsafe plugins. Use `bootstrapBuiltins()` to register with
62
+ * proper safe-mode scoping.
63
+ */
64
+ export const BuiltinTagmaPlugin = {
65
+ name: '@tagma/sdk/builtins',
66
+ capabilities: {
67
+ drivers: SafeBuiltinTagmaPlugin.capabilities.drivers,
68
+ triggers: SafeBuiltinTagmaPlugin.capabilities.triggers,
69
+ completions: {
70
+ ...SafeBuiltinTagmaPlugin.capabilities.completions,
71
+ ...UnsafeBuiltinTagmaPlugin.capabilities.completions,
72
+ },
73
+ middlewares: SafeBuiltinTagmaPlugin.capabilities.middlewares,
74
+ },
75
+ };
36
76
  /**
37
77
  * Register every built-in plugin into `target`. Hosts instantiate one
38
78
  * PluginRegistry per workspace or SDK instance and call this once per
@@ -41,8 +81,17 @@ export const BuiltinTagmaPlugin = {
41
81
  *
42
82
  * Built-in handlers are stateless module singletons — registering the same
43
83
  * handler object into N registries is cheap and safe; no cloning is needed.
84
+ *
85
+ * Safe built-ins register with `{ safeMode: true }` so they are automatically
86
+ * available under `mode: 'safe'` pipelines without explicit allowlist entries.
87
+ * Unsafe built-ins (output_check, which executes arbitrary shell commands)
88
+ * register WITHOUT safeMode, requiring explicit caller opt-in.
89
+ *
90
+ * The registry's `getSafeModeDefaults()` surfaces these to the engine's 3-way
91
+ * safe-mode merge (hardcoded defaults ∪ registry-declared ∪ caller-supplied).
44
92
  */
45
93
  export function bootstrapBuiltins(target) {
46
- target.registerTagmaPlugin(BuiltinTagmaPlugin);
94
+ target.registerTagmaPlugin(SafeBuiltinTagmaPlugin, { safeMode: true });
95
+ target.registerTagmaPlugin(UnsafeBuiltinTagmaPlugin, { safeMode: false });
47
96
  }
48
97
  //# sourceMappingURL=bootstrap.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"AAGA,mBAAmB;AACnB,wEAAwE;AACxE,0EAA0E;AAC1E,iCAAiC;AACjC,kEAAkE;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,oBAAoB;AACpB,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,uBAAuB;AACvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE,sBAAsB;AACtB,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAEvE,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,IAAI,EAAE,qBAAqB;IAC3B,YAAY,EAAE;QACZ,OAAO,EAAE;YACP,QAAQ,EAAE,cAAc;SACzB;QACD,QAAQ,EAAE;YACR,IAAI,EAAE,WAAW;YACjB,MAAM,EAAE,aAAa;SACtB;QACD,WAAW,EAAE;YACX,SAAS,EAAE,kBAAkB;YAC7B,WAAW,EAAE,oBAAoB;YACjC,YAAY,EAAE,qBAAqB;SACpC;QACD,WAAW,EAAE;YACX,cAAc,EAAE,uBAAuB;SACxC;KACF;CACoB,CAAC;AAExB;;;;;;;;GAQG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAsB;IACtD,MAAM,CAAC,mBAAmB,CAAC,kBAAkB,CAAC,CAAC;AACjD,CAAC"}
1
+ {"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"AAGA,mBAAmB;AACnB,wEAAwE;AACxE,0E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CAAC,YAAY,CAAC,QAAQ;QACtD,WAAW,EAAE;YACX,GAAG,sBAAsB,CAAC,YAAY,CAAC,WAAW;YAClD,GAAG,wBAAwB,CAAC,YAAY,CAAC,WAAW;SACrD;QACD,WAAW,EAAE,sBAAsB,CAAC,YAAY,CAAC,WAAW;KAC7D;CACoB,CAAC;AAExB;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAsB;IACtD,MAAM,CAAC,mBAAmB,CAAC,sBAAsB,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;IACvE,MAAM,CAAC,mBAAmB,CAAC,wBAAwB,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC;AAC5E,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- export { createTagma } from './tagma';
2
- export type { CreateTagmaOptions, Tagma, TagmaRunOptions } from './tagma';
1
+ export { createTagma, detectTagmaYamlKind, loadTagmaYaml } from './tagma';
2
+ export type { CreateTagmaOptions, Tagma, TagmaGraphRunOptions, TagmaRunOptions, TagmaRunnableConfig, TagmaYamlDocument, TagmaYamlRunResult, } from './tagma';
3
3
  export { bunRuntime } from '@tagma/runtime-bun';
4
4
  export type { EnvPolicy, TagmaRuntime, RunOptions as RuntimeRunOptions } from '@tagma/core';
5
- export { definePipeline, PluginRegistry, TriggerBlockedError, TriggerTimeoutError, } from '@tagma/core';
5
+ export { definePipeline, PluginRegistry, TriggerBlockedError, TriggerTimeoutError, DEFAULT_TASK_TIMEOUT_MS, } from '@tagma/core';
6
6
  export type { EngineResult, RegisterPluginOptions, RunEventPayload } from '@tagma/core';
7
7
  export { RUN_PROTOCOL_VERSION, TASK_LOG_CAP, TASK_LIVE_OUTPUT_CAP, appendLiveOutput, } from '@tagma/types';
8
8
  export { PipelineGroup, PipelineGraphRunner, WorkflowValidationError, createPipelineGroup, loadWorkflow, parseWorkflowYaml, runPipelineGraph, serializeWorkflow, validateRawWorkflow, } from './workflow';
9
9
  export type { CreatePipelineGroupOptions, PipelineGraphPipelineResult, PipelineGraphResult, PipelineGraphRunnerOptions, PipelineGroupAddOptions, } from './workflow';
10
- export type { PipelineConfig, PipelineExecutionMode, PipelineGraphAbortReason, PipelineGraphConfig, PipelineGraphEventPayload, PipelineGraphNodeState, PipelineGraphNodeStatus, PipelineGraphPipelineConfig, RawPipelineConfig, RawWorkflowConfig, RawWorkflowPipelineConfig, RawTrackConfig, RawTaskConfig, TrackConfig, TaskConfig, WorkflowConfig, WorkflowFailurePolicy, WorkflowPipelineConfig, RunSnapshotPayload, WireRunEvent, RunTaskState, TaskLogLine, SecretResolver, SecretResolverContext, ApprovalRequestInfo, ApprovalRequestHandle, TaskStatus, ApprovalRequest, ApprovalGateway, PluginCategory, PluginCapabilities, TagmaPlugin, DriverPlugin, TriggerPlugin, TriggerWatchHandle, CompletionPlugin, MiddlewarePlugin, RunEventPayload as PipelineRunEventPayload, } from '@tagma/types';
10
+ export type { PipelineConfig, PipelineExecutionMode, PipelineGraphAbortReason, PipelineGraphConfig, PipelineGraphEventPayload, PipelineGraphNodeState, PipelineGraphNodeStatus, PipelineGraphPipelineAttemptState, PipelineGraphPipelineConfig, PipelineGraphPipelineLifecycle, PipelineGraphStopWhen, RawPipelineConfig, RawWorkflowConfig, RawWorkflowPipelineConfig, RawTrackConfig, RawTaskConfig, TrackConfig, TaskConfig, WorkflowConfig, WorkflowDocumentKind, WorkflowFailurePolicy, WorkflowPipelineConfig, RunSnapshotPayload, WireRunEvent, RunTaskState, TaskLogLine, SecretResolver, SecretResolverContext, ApprovalRequestInfo, ApprovalRequestHandle, TaskStatus, ApprovalRequest, ApprovalGateway, PluginCategory, PluginCapabilities, TagmaPlugin, DriverPlugin, TriggerPlugin, TriggerWatchHandle, CompletionPlugin, MiddlewarePlugin, RunEventPayload as PipelineRunEventPayload, } from '@tagma/types';
11
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d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AAkB,EAClB,WAAW,EACX,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAMhB,eAAe,IAAI,uBAAuB,GAC3C,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC1E,YAAY,EACV,kBAAkB,EAClB,KAAK,EACL,oBAAoB,EACpB,eAAe,EACf,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,IAAI,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC5F,OAAO,EACL,cAAc,EACd,cAAc,EACd,mBAAmB,EACnB,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,YAAY,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACxF,OAAO,EACL,oBAAoB,EACpB,YAAY,EACZ,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,uBAAuB,EACvB,mBAAmB,EACnB,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,YAAY,CAAC;AACpB,YAAY,EACV,0BAA0B,EAC1B,2BAA2B,EAC3B,mBAAmB,EACnB,0BAA0B,EAC1B,uBAAuB,GACxB,MAAM,YAAY,CAAC;AACpB,YAAY,EACV,cAAc,EACd,qBAAqB,EACrB,wBAAwB,EACxB,mBAAmB,EACnB,yBAAyB,EACzB,sBAAsB,EACtB,uBAAuB,EACvB,iCAAiC,EACjC,2BAA2B,EAC3B,8BAA8B,EAC9B,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EACjB,yBAAyB,EACzB,cAAc,EACd,aAAa,EACb,WAAW,EACX,UAAU,EACV,cAAc,EACd,oBAAoB,EACpB,qBAAqB,EACrB,sBAAsB,EACtB,kBAAkB,EAClB,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,cAAc,EACd,qBAAqB,EACrB,mBAAmB,EACnB,qBAAqB,EACrB,UAAU,EACV,eAAe,EACf,eAAe,EACf,cAAc,EACd,kBAAkB,EAClB,WAAW,EACX,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAMhB,eAAe,IAAI,uBAAuB,GAC3C,MAAM,cAAc,CAAC"}
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- export { createTagma } from './tagma';
1
+ export { createTagma, detectTagmaYamlKind, loadTagmaYaml } from './tagma';
2
2
  export { bunRuntime } from '@tagma/runtime-bun';
3
- export { definePipeline, PluginRegistry, TriggerBlockedError, TriggerTimeoutError, } from '@tagma/core';
3
+ export { definePipeline, PluginRegistry, TriggerBlockedError, TriggerTimeoutError, DEFAULT_TASK_TIMEOUT_MS, } from '@tagma/core';
4
4
  export { RUN_PROTOCOL_VERSION, TASK_LOG_CAP, TASK_LIVE_OUTPUT_CAP, appendLiveOutput, } from '@tagma/types';
5
5
  export { PipelineGroup, PipelineGraphRunner, WorkflowValidationError, createPipelineGroup, loadWorkflow, parseWorkflowYaml, runPipelineGraph, serializeWorkflow, validateRawWorkflow, } from './workflow';
6
6
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EACL,cAAc,EACd,cAAc,EACd,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,oBAAoB,EACpB,YAAY,EACZ,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,uBAAuB,EACvB,mBAAmB,EACnB,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAU1E,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EACL,cAAc,EACd,cAAc,EACd,mBAAmB,EACnB,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,oBAAoB,EACpB,YAAY,EACZ,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,uBAAuB,EACvB,mBAAmB,EACnB,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,YAAY,CAAC"}
package/dist/tagma.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { PluginRegistry, type EngineResult, type RunPipelineOptions } from '@tagma/core';
2
2
  import type { TagmaRuntime } from '@tagma/core';
3
- import type { PipelineConfig, TagmaPlugin } from '@tagma/types';
3
+ import type { PipelineConfig, PipelineGraphConfig, TagmaPlugin, WorkflowConfig } from '@tagma/types';
4
+ import { type PipelineGraphResult, type PipelineGraphRunnerOptions } from './workflow';
4
5
  export interface CreateTagmaOptions {
5
6
  /**
6
7
  * Registry used by this SDK instance. Omit to create an isolated registry.
@@ -24,10 +25,33 @@ export interface CreateTagmaOptions {
24
25
  export interface TagmaRunOptions extends Omit<RunPipelineOptions, 'registry' | 'runtime'> {
25
26
  readonly cwd: string;
26
27
  }
28
+ export interface TagmaGraphRunOptions extends Omit<PipelineGraphRunnerOptions, 'registry' | 'runtime'> {
29
+ readonly cwd: string;
30
+ }
31
+ export type TagmaRunnableConfig = PipelineConfig | PipelineGraphConfig;
32
+ export type TagmaYamlDocument = {
33
+ readonly kind: 'pipeline';
34
+ readonly config: PipelineConfig;
35
+ } | {
36
+ readonly kind: 'workflow';
37
+ readonly config: WorkflowConfig;
38
+ };
39
+ export type TagmaYamlRunResult = {
40
+ readonly kind: 'pipeline';
41
+ readonly result: EngineResult;
42
+ } | {
43
+ readonly kind: 'workflow';
44
+ readonly result: PipelineGraphResult;
45
+ };
27
46
  export interface Tagma {
28
47
  readonly registry: PluginRegistry;
29
48
  run(config: PipelineConfig, options: TagmaRunOptions): Promise<EngineResult>;
49
+ run(config: PipelineGraphConfig, options: TagmaGraphRunOptions): Promise<PipelineGraphResult>;
50
+ run(config: TagmaRunnableConfig, options: TagmaRunOptions | TagmaGraphRunOptions): Promise<EngineResult | PipelineGraphResult>;
51
+ runYaml(content: string, options: TagmaRunOptions | TagmaGraphRunOptions): Promise<TagmaYamlRunResult>;
30
52
  validate(config: PipelineConfig): readonly string[];
31
53
  }
54
+ export declare function detectTagmaYamlKind(content: string): TagmaYamlDocument['kind'];
55
+ export declare function loadTagmaYaml(content: string, workDir: string): Promise<TagmaYamlDocument>;
32
56
  export declare function createTagma(options?: CreateTagmaOptions): Tagma;
33
57
  //# sourceMappingURL=tagma.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tagma.d.ts","sourceRoot":"","sources":["../src/tagma.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EAEd,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACxB,MAAM,aAAa,CAAC;AAIrB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,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AAC,mBAAmB,CAAC,CAAC;IAC9F,GAAG,CACD,MAAM,EAAE,mBAAmB,EAC3B,OAAO,EAAE,eAAe,GAAG,oBAAoB,GAC9C,OAAO,CAAC,YAAY,GAAG,mBAAmB,CAAC,CAAC;IAC/C,OAAO,CACL,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,eAAe,GAAG,oBAAoB,GAC9C,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAC/B,QAAQ,CAAC,MAAM,EAAE,cAAc,GAAG,SAAS,MAAM,EAAE,CAAC;CACrD;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAY9E;AAED,wBAAsB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAIhG;AAMD,wBAAgB,WAAW,CAAC,OAAO,GAAE,kBAAuB,GAAG,KAAK,CAsDnE"}
package/dist/tagma.js CHANGED
@@ -1,7 +1,33 @@
1
1
  import { PluginRegistry, runPipeline, } from '@tagma/core';
2
+ import yaml from 'js-yaml';
2
3
  import { bootstrapBuiltins } from './bootstrap';
3
- import { PipelineValidationError, validateConfig, validateConfigDiagnostics } from './schema';
4
+ import { PipelineValidationError, loadPipeline, validateConfig, validateConfigDiagnostics, } from './schema';
4
5
  import { bunRuntime } from '@tagma/runtime-bun';
6
+ import { loadWorkflow, runPipelineGraph, } from './workflow';
7
+ export function detectTagmaYamlKind(content) {
8
+ const doc = yaml.load(content);
9
+ if (doc && typeof doc === 'object' && !Array.isArray(doc)) {
10
+ const hasPipeline = Object.prototype.hasOwnProperty.call(doc, 'pipeline');
11
+ const hasWorkflow = Object.prototype.hasOwnProperty.call(doc, 'workflow');
12
+ if (hasPipeline && hasWorkflow) {
13
+ throw new Error('YAML must not contain both top-level "pipeline" and "workflow" keys');
14
+ }
15
+ if (hasPipeline)
16
+ return 'pipeline';
17
+ if (hasWorkflow)
18
+ return 'workflow';
19
+ }
20
+ throw new Error('YAML must contain a top-level "pipeline" or "workflow" key');
21
+ }
22
+ export async function loadTagmaYaml(content, workDir) {
23
+ const kind = detectTagmaYamlKind(content);
24
+ if (kind === 'pipeline')
25
+ return { kind, config: await loadPipeline(content, workDir) };
26
+ return { kind, config: await loadWorkflow(content, workDir) };
27
+ }
28
+ function isPipelineGraphConfig(config) {
29
+ return Array.isArray(config.pipelines);
30
+ }
5
31
  export function createTagma(options = {}) {
6
32
  const registry = options.registry ?? new PluginRegistry();
7
33
  const runtime = options.runtime ?? bunRuntime();
@@ -11,18 +37,36 @@ export function createTagma(options = {}) {
11
37
  for (const plugin of options.plugins ?? []) {
12
38
  registry.registerTagmaPlugin(plugin);
13
39
  }
14
- return {
15
- registry,
16
- async run(config, { cwd, ...runOptions }) {
17
- const diagnostics = validateConfigDiagnostics(config, cwd);
18
- if (diagnostics.length > 0) {
19
- throw new PipelineValidationError(diagnostics);
20
- }
21
- return await runPipeline(config, cwd, {
40
+ async function run(config, { cwd, ...runOptions }) {
41
+ if (isPipelineGraphConfig(config)) {
42
+ return await runPipelineGraph(config, cwd, {
22
43
  ...runOptions,
23
44
  registry,
24
45
  runtime,
25
46
  });
47
+ }
48
+ const diagnostics = validateConfigDiagnostics(config, cwd);
49
+ if (diagnostics.length > 0) {
50
+ throw new PipelineValidationError(diagnostics);
51
+ }
52
+ return await runPipeline(config, cwd, {
53
+ ...runOptions,
54
+ registry,
55
+ runtime,
56
+ });
57
+ }
58
+ return {
59
+ registry,
60
+ run,
61
+ async runYaml(content, options) {
62
+ const document = await loadTagmaYaml(content, options.cwd);
63
+ if (document.kind === 'pipeline') {
64
+ return { kind: 'pipeline', result: await run(document.config, options) };
65
+ }
66
+ return {
67
+ kind: 'workflow',
68
+ result: await run(document.config, options),
69
+ };
26
70
  },
27
71
  validate(config) {
28
72
  return validateConfig(config);
package/dist/tagma.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"tagma.js","sourceRoot":"","s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AAM,EAAE,GAAG,EAAE;YACpC,GAAI,UAA2C;YAC/C,QAAQ;YACR,OAAO;SACR,CAAC,CAAC;IACL,CAAC;IAED,OAAO;QACL,QAAQ;QACR,GAAG;QACH,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO;YAC5B,MAAM,QAAQ,GAAG,MAAM,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;YAC3D,IAAI,QAAQ,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;gBACjC,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC,QAAQ,CAAC,MAAM,EAAE,OAA0B,CAAC,EAAE,CAAC;YAC9F,CAAC;YACD,OAAO;gBACL,IAAI,EAAE,UAAU;gBAChB,MAAM,EAAE,MAAM,GAAG,CAAC,QAAQ,CAAC,MAAM,EAAE,OAA+B,CAAC;aACpE,CAAC;QACJ,CAAC;QACD,QAAQ,CAAC,MAAM;YACb,OAAO,cAAc,CAAC,MAAM,CAAC,CAAC;QAChC,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { type TriggerPlugin } from '@tagma/types';
2
+ export declare const DirectoryTrigger: TriggerPlugin;
3
+ //# sourceMappingURL=directory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"directory.d.ts","sourceRoot":"","sources":["../../src/triggers/directory.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,aAAa,EAGnB,MAAM,cAAc,CAAC;AActB,eAAO,MAAM,gBAAgB,EAAE,aA2C9B,CAAC"}
@@ -0,0 +1,140 @@
1
+ import { resolve, dirname, isAbsolute, relative } from 'path';
2
+ import { TriggerTimeoutError, linkAbort, } from '@tagma/types';
3
+ import { parseOptionalPluginTimeout } from '../duration';
4
+ const IS_WINDOWS = process.platform === 'win32';
5
+ function pathsEqual(a, b) {
6
+ return IS_WINDOWS ? a.toLowerCase() === b.toLowerCase() : a === b;
7
+ }
8
+ function isInsideOrEqual(parent, child) {
9
+ const rel = relative(resolve(parent), resolve(child));
10
+ return rel === '' || (!rel.startsWith('..') && !isAbsolute(rel));
11
+ }
12
+ export const DirectoryTrigger = {
13
+ name: 'directory',
14
+ schema: {
15
+ description: 'Wait for a directory to appear before the task runs.',
16
+ fields: {
17
+ path: {
18
+ type: 'path',
19
+ required: true,
20
+ description: 'Path to the directory to watch for (relative to workDir or absolute).',
21
+ placeholder: 'e.g. inbox/ready',
22
+ },
23
+ timeout: {
24
+ type: 'duration',
25
+ description: 'Maximum wait time (e.g. 30s, 5m). Omit or 0 to wait indefinitely.',
26
+ placeholder: '30s',
27
+ },
28
+ },
29
+ },
30
+ watch(config, ctx) {
31
+ const dirPath = config.path;
32
+ if (!dirPath)
33
+ throw new Error(`directory trigger: "path" is required`);
34
+ const safePath = resolve(ctx.workDir, dirPath);
35
+ const parentDir = dirname(safePath);
36
+ const timeoutMs = parseOptionalPluginTimeout(config.timeout, 0);
37
+ const disposeController = new AbortController();
38
+ return {
39
+ fired: waitForDirectory({
40
+ dirPath,
41
+ parentDir,
42
+ safePath,
43
+ timeoutMs,
44
+ timeoutLabel: config.timeout,
45
+ ctx,
46
+ disposeSignal: disposeController.signal,
47
+ }),
48
+ dispose(reason = 'directory trigger disposed') {
49
+ disposeController.abort(reason);
50
+ },
51
+ };
52
+ },
53
+ };
54
+ async function waitForDirectory(options) {
55
+ const { dirPath, parentDir, safePath, timeoutMs, timeoutLabel, ctx, disposeSignal } = options;
56
+ if (ctx.signal.aborted)
57
+ throw new Error('Pipeline aborted');
58
+ if (disposeSignal.aborted)
59
+ throw new Error('Trigger disposed');
60
+ if (isInsideOrEqual(ctx.workDir, parentDir)) {
61
+ await ctx.runtime.ensureDir(parentDir).catch(() => {
62
+ /* best effort; runtime watch will surface real failures */
63
+ });
64
+ }
65
+ if (ctx.signal.aborted)
66
+ throw new Error('Pipeline aborted');
67
+ if (disposeSignal.aborted)
68
+ throw new Error('Trigger disposed');
69
+ const watchController = new AbortController();
70
+ let removeAbortListener = () => {
71
+ /* no-op until the abort listener is installed */
72
+ };
73
+ const abortPromise = new Promise((_, reject) => {
74
+ const fire = (message) => {
75
+ watchController.abort();
76
+ reject(new Error(message));
77
+ };
78
+ const removePipeline = linkAbort(ctx.signal, () => fire('Pipeline aborted'));
79
+ const removeDispose = linkAbort(disposeSignal, () => fire('Trigger disposed'));
80
+ removeAbortListener = () => {
81
+ removePipeline();
82
+ removeDispose();
83
+ };
84
+ });
85
+ let timer = null;
86
+ const timeoutPromise = timeoutMs > 0
87
+ ? new Promise((_, reject) => {
88
+ timer = setTimeout(() => {
89
+ watchController.abort();
90
+ reject(new TriggerTimeoutError(`directory trigger timeout: ${dirPath} did not appear within ${timeoutLabel}`));
91
+ }, timeoutMs);
92
+ })
93
+ : new Promise(() => {
94
+ /* no timeout */
95
+ });
96
+ async function watchLoop() {
97
+ // Use ignoreInitial:false so an already-created target directory still
98
+ // satisfies the gate during the initial scan. Runtimes that expose a
99
+ // precise directoryExists probe get a second ready-time check below.
100
+ for await (const event of ctx.runtime.watch(parentDir, {
101
+ ignoreInitial: false,
102
+ depth: 0,
103
+ cwd: parentDir,
104
+ awaitWriteFinishMs: 100,
105
+ signal: watchController.signal,
106
+ })) {
107
+ if (event.type === 'ready') {
108
+ if (ctx.runtime.directoryExists) {
109
+ let exists = false;
110
+ try {
111
+ exists = await ctx.runtime.directoryExists(safePath);
112
+ }
113
+ catch (err) {
114
+ throw new Error(`directory trigger existence check failed: ${err instanceof Error ? err.message : String(err)}`);
115
+ }
116
+ if (exists)
117
+ return { path: safePath };
118
+ }
119
+ continue;
120
+ }
121
+ if (event.type === 'addDir' &&
122
+ pathsEqual(resolve(parentDir, event.path), safePath)) {
123
+ return { path: safePath };
124
+ }
125
+ }
126
+ if (ctx.signal.aborted)
127
+ throw new Error('Pipeline aborted');
128
+ throw new Error(`directory trigger watch ended before ${dirPath} appeared`);
129
+ }
130
+ try {
131
+ return await Promise.race([watchLoop(), timeoutPromise, abortPromise]);
132
+ }
133
+ finally {
134
+ if (timer !== null)
135
+ clearTimeout(timer);
136
+ removeAbortListener();
137
+ watchController.abort();
138
+ }
139
+ }
140
+ //# sourceMappingURL=directory.js.map