@clearideas/agent-runtime-cli 0.4.3 → 0.5.0

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 (3) hide show
  1. package/dist/index.d.ts +2 -0
  2. package/dist/index.js +269 -216
  3. package/package.json +11 -11
package/dist/index.d.ts CHANGED
@@ -9,6 +9,8 @@ export interface CliIo {
9
9
  export type CliStoreDriver = "file" | "sqlite";
10
10
  /** Adapters a local runtime module may contribute to CLI execution. */
11
11
  export interface CliRuntime {
12
+ /** Called once after execution, including failed setup. Own only module-created resources. */
13
+ shutdown?: () => void | Promise<void>;
12
14
  runStore?: RunStore;
13
15
  artifactStore?: ArtifactStore;
14
16
  model?: ModelAdapter;
package/dist/index.js CHANGED
@@ -67,11 +67,16 @@ const resolveCliStoreLocation = (parsed, workerMode = false) => {
67
67
  };
68
68
  const resolveCliStore = async (parsed) => {
69
69
  const resolved = resolveCliStoreLocation(parsed);
70
+ const store = resolved.driver === "sqlite"
71
+ ? new (await import("@clearideas/agent-runtime-store-sqlite")).SqliteRunStore(resolved.location)
72
+ : new FileRunStore(resolved.location);
70
73
  return {
71
74
  ...resolved,
72
- store: resolved.driver === "sqlite"
73
- ? new (await import("@clearideas/agent-runtime-store-sqlite")).SqliteRunStore(resolved.location)
74
- : new FileRunStore(resolved.location),
75
+ store,
76
+ close: () => {
77
+ if ("close" in store)
78
+ store.close();
79
+ },
75
80
  };
76
81
  };
77
82
  const parseOptions = (args, allowed, flags = new Set()) => {
@@ -150,17 +155,22 @@ const inspect = async (args, io) => {
150
155
  const parsed = parseOptions(args, new Set(["store", "store-driver", "runtime-module"]));
151
156
  const runId = requireOnePositional(parsed, "run id");
152
157
  const resolved = await resolveCliStore(parsed);
153
- const store = (await loadRuntimeStore(parsed.options.get("runtime-module"), {
154
- runId,
155
- storeDirectory: resolved.baseDirectory,
156
- storeDriver: resolved.driver,
157
- storeLocation: resolved.location,
158
- })) ?? resolved.store;
159
- const run = await store.loadRun(runId);
160
- if (!run)
161
- throw new Error(`Run not found: ${runId}`);
162
- const checkpoint = await store.loadLatestCheckpoint(runId);
163
- io.stdout(`${JSON.stringify({ run, checkpoint }, null, 2)}\n`);
158
+ try {
159
+ const store = (await loadRuntimeStore(parsed.options.get("runtime-module"), {
160
+ runId,
161
+ storeDirectory: resolved.baseDirectory,
162
+ storeDriver: resolved.driver,
163
+ storeLocation: resolved.location,
164
+ })) ?? resolved.store;
165
+ const run = await store.loadRun(runId);
166
+ if (!run)
167
+ throw new Error(`Run not found: ${runId}`);
168
+ const checkpoint = await store.loadLatestCheckpoint(runId);
169
+ io.stdout(`${JSON.stringify({ run, checkpoint }, null, 2)}\n`);
170
+ }
171
+ finally {
172
+ resolved.close();
173
+ }
164
174
  };
165
175
  const events = async (args, io) => {
166
176
  const parsed = parseOptions(args, new Set(["run", "type", "tail"]));
@@ -194,6 +204,8 @@ const adapterMethod = (value, name) => value != null &&
194
204
  typeof value === "object" &&
195
205
  typeof value[name] === "function";
196
206
  const validateRuntime = (runtime) => {
207
+ if (runtime.shutdown !== undefined && typeof runtime.shutdown !== "function")
208
+ throw new Error("Runtime shutdown must be a function.");
197
209
  if (runtime.runStore &&
198
210
  (!adapterMethod(runtime.runStore, "createRun") ||
199
211
  !adapterMethod(runtime.runStore, "loadRun") ||
@@ -238,6 +250,7 @@ const validateRuntime = (runtime) => {
238
250
  return runtime;
239
251
  };
240
252
  const normalizeRuntime = (runtime) => ({
253
+ ...(runtime.shutdown ? { shutdown: runtime.shutdown } : {}),
241
254
  ...((runtime.runStore ?? runtime.store)
242
255
  ? { runStore: runtime.runStore ?? runtime.store }
243
256
  : {}),
@@ -481,6 +494,10 @@ class CliStreamingEventSink {
481
494
  return `✓ run completed (${event.runId})`;
482
495
  case "run.failed":
483
496
  return `✗ run failed (${event.runId})`;
497
+ case "run.suspended":
498
+ return `Ⅱ run suspended (${event.runId}): ${String(event.data?.reason ?? "awaiting input")}; resume with agent-runtime resume ${event.runId}`;
499
+ case "webhook.retry.scheduled":
500
+ return ` webhook retry: ${String(event.data?.reason ?? "transient failure")}, waiting ${String(event.data?.delayMs ?? "unknown")}ms`;
484
501
  case "run.cancelled":
485
502
  return `■ run cancelled (${event.runId})`;
486
503
  default:
@@ -536,145 +553,172 @@ const execute = async (command, args, io, signal) => {
536
553
  ? new FileAgentManifestSource(path.dirname(agentRunManifestFile))
537
554
  : undefined;
538
555
  const resolvedStore = await resolveCliStore(parsed);
539
- const storeDirectory = resolvedStore.baseDirectory;
540
- const runId = command === "resume"
541
- ? target
542
- : (agentRunManifest?.runId ?? parsed.options.get("run-id"));
543
- const maxTotalTokens = positiveSafeIntegerOption(parsed, "max-total-tokens");
544
- const runtimeModulePath = parsed.options.get("runtime-module");
545
- const runtimeStore = command === "resume"
546
- ? await loadRuntimeStore(runtimeModulePath, {
547
- runId: target,
556
+ let shutdown;
557
+ try {
558
+ const storeDirectory = resolvedStore.baseDirectory;
559
+ const runId = command === "resume"
560
+ ? target
561
+ : (agentRunManifest?.runId ?? parsed.options.get("run-id"));
562
+ const maxTotalTokens = positiveSafeIntegerOption(parsed, "max-total-tokens");
563
+ const runtimeModulePath = parsed.options.get("runtime-module");
564
+ const runtimeStore = command === "resume"
565
+ ? await loadRuntimeStore(runtimeModulePath, {
566
+ runId: target,
567
+ storeDirectory,
568
+ storeDriver: resolvedStore.driver,
569
+ storeLocation: resolvedStore.location,
570
+ })
571
+ : undefined;
572
+ const store = runtimeStore ?? resolvedStore.store;
573
+ let manifest;
574
+ const variableOverrides = command === "run" && parsed.options.has("variables")
575
+ ? parseAgentVariableOverrides(JSON.parse(await readFile(path.resolve(parsed.options.get("variables")), "utf8")))
576
+ : undefined;
577
+ let configSearchDirectory = process.cwd();
578
+ if (command === "run") {
579
+ const manifestFile = path.resolve(target);
580
+ configSearchDirectory = path.dirname(manifestFile);
581
+ manifest = await new FileAgentManifestSource(path.dirname(manifestFile), path.basename(manifestFile)).loadManifest();
582
+ }
583
+ else if (command === "run-manifest" &&
584
+ agentRunManifest &&
585
+ agentManifestSource) {
586
+ configSearchDirectory = path.dirname(agentRunManifestFile);
587
+ manifest = await agentManifestSource.loadManifest(agentRunManifest.agent.ref);
588
+ }
589
+ else {
590
+ const record = await store.loadRun(target);
591
+ if (!record)
592
+ throw new Error(`Run not found: ${target}`);
593
+ manifest = record.manifest;
594
+ }
595
+ const eventsOption = parsed.options.get("events");
596
+ const eventFile = eventsOption === "none"
597
+ ? undefined
598
+ : path.resolve(eventsOption ?? path.join(storeDirectory, "events.jsonl"));
599
+ const artifactsOption = parsed.options.get("artifacts");
600
+ const artifactDirectory = artifactsOption === "none"
601
+ ? undefined
602
+ : path.resolve(artifactsOption ?? storeDirectory);
603
+ const context = {
604
+ manifest,
605
+ ...(runId ? { runId } : {}),
548
606
  storeDirectory,
549
607
  storeDriver: resolvedStore.driver,
550
608
  storeLocation: resolvedStore.location,
551
- })
552
- : undefined;
553
- const store = runtimeStore ?? resolvedStore.store;
554
- let manifest;
555
- const variableOverrides = command === "run" && parsed.options.has("variables")
556
- ? parseAgentVariableOverrides(JSON.parse(await readFile(path.resolve(parsed.options.get("variables")), "utf8")))
557
- : undefined;
558
- let configSearchDirectory = process.cwd();
559
- if (command === "run") {
560
- const manifestFile = path.resolve(target);
561
- configSearchDirectory = path.dirname(manifestFile);
562
- manifest = await new FileAgentManifestSource(path.dirname(manifestFile), path.basename(manifestFile)).loadManifest();
563
- }
564
- else if (command === "run-manifest" &&
565
- agentRunManifest &&
566
- agentManifestSource) {
567
- configSearchDirectory = path.dirname(agentRunManifestFile);
568
- manifest = await agentManifestSource.loadManifest(agentRunManifest.agent.ref);
569
- }
570
- else {
571
- const record = await store.loadRun(target);
572
- if (!record)
573
- throw new Error(`Run not found: ${target}`);
574
- manifest = record.manifest;
575
- }
576
- const eventsOption = parsed.options.get("events");
577
- const eventFile = eventsOption === "none"
578
- ? undefined
579
- : path.resolve(eventsOption ?? path.join(storeDirectory, "events.jsonl"));
580
- const artifactsOption = parsed.options.get("artifacts");
581
- const artifactDirectory = artifactsOption === "none"
582
- ? undefined
583
- : path.resolve(artifactsOption ?? storeDirectory);
584
- const context = {
585
- manifest,
586
- ...(runId ? { runId } : {}),
587
- storeDirectory,
588
- storeDriver: resolvedStore.driver,
589
- storeLocation: resolvedStore.location,
590
- ...(eventFile ? { eventFile } : {}),
591
- ...(artifactDirectory ? { artifactDirectory } : {}),
592
- };
593
- const loadedModuleRuntime = await loadRuntime(runtimeModulePath, context);
594
- const moduleRuntime = runtimeStore
595
- ? validateRuntime({ ...loadedModuleRuntime, runStore: runtimeStore })
596
- : loadedModuleRuntime;
597
- const config = await resolveConfig(parsed.options.get("config"), configSearchDirectory);
598
- const configuredRuntime = composeRuntime(manifest, config, {}, {
599
- model: !moduleRuntime.model,
600
- tools: !moduleRuntime.tools,
601
- ...(moduleRuntime.connectionCredentials
602
- ? { connectionCredentials: moduleRuntime.connectionCredentials }
603
- : {}),
604
- });
605
- const runtime = mergeRuntimes(configuredRuntime, moduleRuntime);
606
- const jsonlSink = eventFile ? new JsonlEventSink(eventFile) : undefined;
607
- const requestedFormat = parsed.options.get("format") ??
608
- (parsed.options.has("stream") ? "pretty" : "json");
609
- if (!["json", "pretty", "ndjson"].includes(requestedFormat)) {
610
- throw new Error("--format must be json, pretty, or ndjson.");
611
- }
612
- const outputFormat = requestedFormat;
613
- const streamingSink = outputFormat === "json"
614
- ? undefined
615
- : new CliStreamingEventSink(io, outputFormat, parsed.options.has("show-reasoning"));
616
- const runner = new AgentRuntime({
617
- runStore: runtime.runStore ?? store,
618
- ...(agentManifestSource ? { agentManifestSource } : {}),
619
- stepExecutors: resolveStepExecutors(runtime, { allowUnsafeWebhooks: true }),
620
- conditionEvaluator: new JexlConditionEvaluator(),
621
- eventSinks: [
622
- ...(jsonlSink ? [new SafeLocalEventSink(jsonlSink)] : []),
623
- ...(streamingSink ? [streamingSink] : []),
624
- ...(runtime.eventSinks ?? []),
625
- ],
626
- ...(runtime.model ? { model: runtime.model } : {}),
627
- ...(runtime.tools ? { tools: runtime.tools } : {}),
628
- ...(runtime.approvals ? { approvals: runtime.approvals } : {}),
629
- ...(runtime.sandbox ? { sandbox: runtime.sandbox } : {}),
630
- ...(runtime.subRuns ? { subRuns: runtime.subRuns } : {}),
631
- ...(runtime.artifactStore
632
- ? { artifacts: runtime.artifactStore }
633
- : artifactDirectory
634
- ? { artifacts: new FileArtifactStore(artifactDirectory) }
609
+ ...(eventFile ? { eventFile } : {}),
610
+ ...(artifactDirectory ? { artifactDirectory } : {}),
611
+ };
612
+ const loadedModuleRuntime = await loadRuntime(runtimeModulePath, context);
613
+ shutdown = loadedModuleRuntime.shutdown;
614
+ const moduleRuntime = runtimeStore
615
+ ? validateRuntime({ ...loadedModuleRuntime, runStore: runtimeStore })
616
+ : loadedModuleRuntime;
617
+ const config = await resolveConfig(parsed.options.get("config"), configSearchDirectory);
618
+ const configuredRuntime = composeRuntime(manifest, config, {}, {
619
+ model: !moduleRuntime.model,
620
+ tools: !moduleRuntime.tools,
621
+ ...(moduleRuntime.connectionCredentials
622
+ ? { connectionCredentials: moduleRuntime.connectionCredentials }
635
623
  : {}),
636
- });
637
- try {
638
- const result = await runner.run(command === "run-manifest" && agentRunManifest
639
- ? {
640
- agentRunManifest,
641
- ...(signal ? { signal } : {}),
642
- }
643
- : {
644
- manifest,
645
- ...(runId ? { runId } : {}),
646
- ...(variableOverrides ? { variables: variableOverrides } : {}),
647
- ...(maxTotalTokens ? { budget: { maxTotalTokens } } : {}),
648
- ...(signal ? { signal } : {}),
649
- ...(command === "resume" ? { resume: true } : {}),
650
- });
651
- // Deliberately exclude variables, transcript and model output. They may
652
- // contain secrets; inspect is an explicit command for persisted details.
653
- if (outputFormat === "ndjson") {
654
- io.stdout(`${JSON.stringify({
655
- type: "result",
656
- result,
657
- })}\n`);
624
+ });
625
+ const runtime = mergeRuntimes(configuredRuntime, moduleRuntime);
626
+ const jsonlSink = eventFile ? new JsonlEventSink(eventFile) : undefined;
627
+ const requestedFormat = parsed.options.get("format") ??
628
+ (parsed.options.has("stream") ? "pretty" : "json");
629
+ if (!["json", "pretty", "ndjson"].includes(requestedFormat)) {
630
+ throw new Error("--format must be json, pretty, or ndjson.");
658
631
  }
659
- else if (outputFormat === "pretty") {
660
- if (streamingSink?.streamedText)
661
- io.stdout("\n");
662
- else if (result.output !== undefined) {
663
- io.stdout(`${typeof result.output === "string" ? result.output : JSON.stringify(result.output, null, 2)}\n`);
632
+ const outputFormat = requestedFormat;
633
+ const streamingSink = outputFormat === "json"
634
+ ? undefined
635
+ : new CliStreamingEventSink(io, outputFormat, parsed.options.has("show-reasoning"));
636
+ const warnedSinks = new Set();
637
+ const runner = new AgentRuntime({
638
+ onEventSinkError(_error, _event, sink) {
639
+ if (warnedSinks.has(sink))
640
+ return;
641
+ warnedSinks.add(sink);
642
+ io.stderr(`Warning: event delivery failed for ${sink instanceof SafeLocalEventSink ? `local log ${eventFile}` : sink.constructor.name}. Check permissions and available disk space. Execution continues.\n`);
643
+ },
644
+ runStore: runtime.runStore ?? store,
645
+ ...(agentManifestSource ? { agentManifestSource } : {}),
646
+ stepExecutors: resolveStepExecutors(runtime, {
647
+ allowUnsafeWebhooks: true,
648
+ }),
649
+ conditionEvaluator: new JexlConditionEvaluator(),
650
+ eventSinks: [
651
+ ...(jsonlSink ? [new SafeLocalEventSink(jsonlSink)] : []),
652
+ ...(streamingSink ? [streamingSink] : []),
653
+ ...(runtime.eventSinks ?? []),
654
+ ],
655
+ ...(runtime.model ? { model: runtime.model } : {}),
656
+ ...(runtime.tools ? { tools: runtime.tools } : {}),
657
+ ...(runtime.approvals ? { approvals: runtime.approvals } : {}),
658
+ ...(runtime.sandbox ? { sandbox: runtime.sandbox } : {}),
659
+ ...(runtime.subRuns ? { subRuns: runtime.subRuns } : {}),
660
+ ...(runtime.artifactStore
661
+ ? { artifacts: runtime.artifactStore }
662
+ : artifactDirectory
663
+ ? { artifacts: new FileArtifactStore(artifactDirectory) }
664
+ : {}),
665
+ });
666
+ try {
667
+ const result = await runner.run(command === "run-manifest" && agentRunManifest
668
+ ? {
669
+ agentRunManifest,
670
+ ...(signal ? { signal } : {}),
671
+ }
672
+ : {
673
+ manifest,
674
+ ...(runId ? { runId } : {}),
675
+ ...(variableOverrides ? { variables: variableOverrides } : {}),
676
+ ...(maxTotalTokens ? { budget: { maxTotalTokens } } : {}),
677
+ ...(signal ? { signal } : {}),
678
+ ...(command === "resume" ? { resume: true } : {}),
679
+ });
680
+ // Deliberately exclude variables, transcript and model output. They may
681
+ // contain secrets; inspect is an explicit command for persisted details.
682
+ if (outputFormat === "ndjson") {
683
+ io.stdout(`${JSON.stringify({
684
+ type: "result",
685
+ result,
686
+ })}\n`);
687
+ }
688
+ else if (outputFormat === "pretty") {
689
+ if (streamingSink?.streamedText)
690
+ io.stdout("\n");
691
+ else if (result.output !== undefined) {
692
+ io.stdout(`${typeof result.output === "string" ? result.output : JSON.stringify(result.output, null, 2)}\n`);
693
+ }
694
+ io.stderr(`run ${result.runId}: ${result.stepResults.length} step(s), ${result.artifacts.length} artifact(s)\n`);
695
+ }
696
+ else {
697
+ io.stdout(`${JSON.stringify({
698
+ runId: result.runId,
699
+ status: "completed",
700
+ stepCount: result.stepResults.length,
701
+ artifactCount: result.artifacts.length,
702
+ }, null, 2)}\n`);
664
703
  }
665
- io.stderr(`run ${result.runId}: ${result.stepResults.length} step(s), ${result.artifacts.length} artifact(s)\n`);
666
704
  }
667
- else {
668
- io.stdout(`${JSON.stringify({
669
- runId: result.runId,
670
- status: "completed",
671
- stepCount: result.stepResults.length,
672
- artifactCount: result.artifacts.length,
673
- }, null, 2)}\n`);
705
+ finally {
706
+ await jsonlSink?.flush();
674
707
  }
675
708
  }
676
709
  finally {
677
- await jsonlSink?.flush();
710
+ try {
711
+ await shutdown?.();
712
+ }
713
+ catch {
714
+ io.stderr("Warning: runtime shutdown failed. Check adapter cleanup.\n");
715
+ }
716
+ try {
717
+ resolvedStore.close();
718
+ }
719
+ catch {
720
+ io.stderr("Warning: local store cleanup failed.\n");
721
+ }
678
722
  }
679
723
  };
680
724
  const assertSafeInlineWorkerConfiguration = (config) => {
@@ -779,81 +823,90 @@ export const executeWorkerInvocation = async (invocation, options) => {
779
823
  (storeDriver === "sqlite"
780
824
  ? new (await import("@clearideas/agent-runtime-store-sqlite")).SqliteRunStore(storeLocation)
781
825
  : new FileRunStore(storeLocation));
782
- const artifacts = runtime.artifactStore ?? new FileArtifactStore(storeDirectory);
783
- if (invocation.action === "resume" &&
784
- "checkpoint" in request &&
785
- request.checkpoint) {
786
- const existing = await store.loadRun(request.runId);
787
- if (!existing) {
788
- const checkpointAttempt = request.checkpoint.attempt ?? request.attempt - 1;
789
- const importedCheckpoint = {
790
- ...request.checkpoint,
791
- ...(request.checkpoint.sequence === 1
792
- ? {}
793
- : {
794
- id: `${request.checkpoint.id}:imported`,
795
- sequence: 1,
796
- metadata: {
797
- ...(request.checkpoint.metadata ?? {}),
798
- importedCheckpointId: request.checkpoint.id,
799
- importedCheckpointSequence: request.checkpoint.sequence,
800
- },
801
- }),
802
- };
803
- await store.createRun({
804
- runId: request.runId,
805
- manifest,
806
- status: "suspended",
807
- attempt: checkpointAttempt,
808
- state: structuredClone(importedCheckpoint.state),
809
- createdAt: importedCheckpoint.createdAt,
810
- updatedAt: importedCheckpoint.createdAt,
811
- });
812
- // A transferred checkpoint is a complete snapshot, not a partial log.
813
- // Rebase its local sequence when the destination store has no history;
814
- // preserve the source cursor in metadata for audit/debugging.
815
- await store.saveCheckpoint(importedCheckpoint);
826
+ try {
827
+ const artifacts = runtime.artifactStore ?? new FileArtifactStore(storeDirectory);
828
+ if (invocation.action === "resume" &&
829
+ "checkpoint" in request &&
830
+ request.checkpoint) {
831
+ const existing = await store.loadRun(request.runId);
832
+ if (!existing) {
833
+ const checkpointAttempt = request.checkpoint.attempt ?? request.attempt - 1;
834
+ const importedCheckpoint = {
835
+ ...request.checkpoint,
836
+ ...(request.checkpoint.sequence === 1
837
+ ? {}
838
+ : {
839
+ id: `${request.checkpoint.id}:imported`,
840
+ sequence: 1,
841
+ metadata: {
842
+ ...(request.checkpoint.metadata ?? {}),
843
+ importedCheckpointId: request.checkpoint.id,
844
+ importedCheckpointSequence: request.checkpoint.sequence,
845
+ },
846
+ }),
847
+ };
848
+ await store.createRun({
849
+ runId: request.runId,
850
+ manifest,
851
+ status: "suspended",
852
+ attempt: checkpointAttempt,
853
+ state: structuredClone(importedCheckpoint.state),
854
+ createdAt: importedCheckpoint.createdAt,
855
+ updatedAt: importedCheckpoint.createdAt,
856
+ });
857
+ // A transferred checkpoint is a complete snapshot, not a partial log.
858
+ // Rebase its local sequence when the destination store has no history;
859
+ // preserve the source cursor in metadata for audit/debugging.
860
+ await store.saveCheckpoint(importedCheckpoint);
861
+ }
816
862
  }
863
+ const runner = new AgentRuntime({
864
+ runStore: store,
865
+ // Webhook execution is host-supplied in worker mode so destination policy
866
+ // cannot be bypassed by a remote manifest.
867
+ stepExecutors: resolveStepExecutors(runtime),
868
+ conditionEvaluator: new JexlConditionEvaluator(),
869
+ eventSinks: [
870
+ new PortableWorkerEventSink(options.onMessage),
871
+ ...(runtime.eventSinks ?? []),
872
+ ],
873
+ ...(runtime.model ? { model: runtime.model } : {}),
874
+ ...(runtime.tools ? { tools: runtime.tools } : {}),
875
+ ...(runtime.approvals ? { approvals: runtime.approvals } : {}),
876
+ ...(runtime.sandbox ? { sandbox: runtime.sandbox } : {}),
877
+ ...(runtime.subRuns ? { subRuns: runtime.subRuns } : {}),
878
+ artifacts,
879
+ ...(options.maxParallelSteps
880
+ ? { maxParallelSteps: options.maxParallelSteps }
881
+ : {}),
882
+ ...(options.eventSinkFailurePolicy
883
+ ? { eventSinkFailurePolicy: options.eventSinkFailurePolicy }
884
+ : {}),
885
+ });
886
+ return await runner.run({
887
+ manifest,
888
+ ...(request.runId ? { runId: request.runId } : {}),
889
+ ...(invocationVariables ? { variables: invocationVariables } : {}),
890
+ ...(request.execution ? { execution: request.execution } : {}),
891
+ ...(request.budget ? { budget: request.budget } : {}),
892
+ ...(options.signal ? { signal: options.signal } : {}),
893
+ ...(invocation.action === "resume"
894
+ ? {
895
+ resume: true,
896
+ ...("allowRunningTakeover" in request &&
897
+ request.allowRunningTakeover
898
+ ? { allowRunningTakeover: true }
899
+ : {}),
900
+ }
901
+ : {}),
902
+ });
903
+ }
904
+ finally {
905
+ if (!runtime.runStore &&
906
+ "close" in store &&
907
+ typeof store.close === "function")
908
+ store.close();
817
909
  }
818
- const runner = new AgentRuntime({
819
- runStore: store,
820
- // Webhook execution is host-supplied in worker mode so destination policy
821
- // cannot be bypassed by a remote manifest.
822
- stepExecutors: resolveStepExecutors(runtime),
823
- conditionEvaluator: new JexlConditionEvaluator(),
824
- eventSinks: [
825
- new PortableWorkerEventSink(options.onMessage),
826
- ...(runtime.eventSinks ?? []),
827
- ],
828
- ...(runtime.model ? { model: runtime.model } : {}),
829
- ...(runtime.tools ? { tools: runtime.tools } : {}),
830
- ...(runtime.approvals ? { approvals: runtime.approvals } : {}),
831
- ...(runtime.sandbox ? { sandbox: runtime.sandbox } : {}),
832
- ...(runtime.subRuns ? { subRuns: runtime.subRuns } : {}),
833
- artifacts,
834
- ...(options.maxParallelSteps
835
- ? { maxParallelSteps: options.maxParallelSteps }
836
- : {}),
837
- ...(options.eventSinkFailurePolicy
838
- ? { eventSinkFailurePolicy: options.eventSinkFailurePolicy }
839
- : {}),
840
- });
841
- return runner.run({
842
- manifest,
843
- ...(request.runId ? { runId: request.runId } : {}),
844
- ...(invocationVariables ? { variables: invocationVariables } : {}),
845
- ...(request.execution ? { execution: request.execution } : {}),
846
- ...(request.budget ? { budget: request.budget } : {}),
847
- ...(options.signal ? { signal: options.signal } : {}),
848
- ...(invocation.action === "resume"
849
- ? {
850
- resume: true,
851
- ...("allowRunningTakeover" in request && request.allowRunningTakeover
852
- ? { allowRunningTakeover: true }
853
- : {}),
854
- }
855
- : {}),
856
- });
857
910
  };
858
911
  const readStandardInput = async () => {
859
912
  process.stdin.setEncoding("utf8");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clearideas/agent-runtime-cli",
3
- "version": "0.4.3",
3
+ "version": "0.5.0",
4
4
  "description": "Standalone CLI for validating, running, resuming, and inspecting declarative agents.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Clear Ideas Incorporated",
@@ -40,16 +40,16 @@
40
40
  "postpack": "node ../../scripts/cleanup-package-license.mjs"
41
41
  },
42
42
  "dependencies": {
43
- "@clearideas/agent-runtime-condition-jexl": "0.4.3",
44
- "@clearideas/agent-runtime-config": "0.4.3",
45
- "@clearideas/agent-runtime-contracts": "0.4.3",
46
- "@clearideas/agent-runtime-core": "0.4.3",
47
- "@clearideas/agent-runtime-execution": "0.4.3",
48
- "@clearideas/agent-runtime-step-loop": "0.4.3",
49
- "@clearideas/agent-runtime-step-prompt": "0.4.3",
50
- "@clearideas/agent-runtime-step-standard": "0.4.3",
51
- "@clearideas/agent-runtime-store-local": "0.4.3",
52
- "@clearideas/agent-runtime-store-sqlite": "0.4.3"
43
+ "@clearideas/agent-runtime-condition-jexl": "0.5.0",
44
+ "@clearideas/agent-runtime-config": "0.5.0",
45
+ "@clearideas/agent-runtime-contracts": "0.5.0",
46
+ "@clearideas/agent-runtime-core": "0.5.0",
47
+ "@clearideas/agent-runtime-execution": "0.5.0",
48
+ "@clearideas/agent-runtime-step-loop": "0.5.0",
49
+ "@clearideas/agent-runtime-step-prompt": "0.5.0",
50
+ "@clearideas/agent-runtime-step-standard": "0.5.0",
51
+ "@clearideas/agent-runtime-store-local": "0.5.0",
52
+ "@clearideas/agent-runtime-store-sqlite": "0.5.0"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@types/node": "^26.4.0",