@clearideas/agent-runtime-step-standard 0.4.3 → 0.6.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.
- package/dist/index.js +85 -0
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -585,6 +585,11 @@ export class CodeStepExecutor {
|
|
|
585
585
|
this.#maximumTimeoutMs = options.maximumTimeoutMs ?? 900_000;
|
|
586
586
|
}
|
|
587
587
|
async execute(context) {
|
|
588
|
+
const usesRunSandbox = context.step.sandbox === "run" ||
|
|
589
|
+
(context.step.sandbox !== "step" &&
|
|
590
|
+
(context.step.workspaces?.length ?? 0) > 0);
|
|
591
|
+
if (usesRunSandbox)
|
|
592
|
+
return this.#executeInRunSandbox(context);
|
|
588
593
|
if (!context.sandbox) {
|
|
589
594
|
throw new Error(`Code step ${context.step.id} requires a SandboxAdapter`);
|
|
590
595
|
}
|
|
@@ -594,6 +599,7 @@ export class CodeStepExecutor {
|
|
|
594
599
|
await context.emit("code.execution.started", {
|
|
595
600
|
language: context.step.language,
|
|
596
601
|
timeoutMs,
|
|
602
|
+
sandbox: "step",
|
|
597
603
|
});
|
|
598
604
|
const operation = operationSignal(context.signal, timeoutMs);
|
|
599
605
|
let result;
|
|
@@ -642,4 +648,83 @@ export class CodeStepExecutor {
|
|
|
642
648
|
},
|
|
643
649
|
};
|
|
644
650
|
}
|
|
651
|
+
/**
|
|
652
|
+
* Execute inside the run-scoped sandbox shared with workspace tools. The
|
|
653
|
+
* step sees its declared workspace mounts, and its command is admitted,
|
|
654
|
+
* reported, and recorded like every other sandbox command.
|
|
655
|
+
*/
|
|
656
|
+
async #executeInRunSandbox(context) {
|
|
657
|
+
if (!context.runSandbox) {
|
|
658
|
+
throw new Error(`Code step ${context.step.id} requires the run sandbox; configure a RunSandboxProvider`);
|
|
659
|
+
}
|
|
660
|
+
if (context.signal?.aborted)
|
|
661
|
+
throw abortReason(context.signal);
|
|
662
|
+
const available = new Set((context.workspaces ?? []).map((workspace) => workspace.alias));
|
|
663
|
+
for (const alias of context.step.workspaces ?? []) {
|
|
664
|
+
if (!available.has(alias)) {
|
|
665
|
+
throw new Error(`Code step ${context.step.id} requires workspace ${alias}, which is not available for this run`);
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
const timeoutMs = positiveInteger(context.step.timeoutMs, this.#defaultTimeoutMs, this.#maximumTimeoutMs, "Code timeoutMs");
|
|
669
|
+
await context.emit("code.execution.started", {
|
|
670
|
+
language: context.step.language,
|
|
671
|
+
timeoutMs,
|
|
672
|
+
sandbox: "run",
|
|
673
|
+
workspaces: [...(context.step.workspaces ?? [])],
|
|
674
|
+
});
|
|
675
|
+
const session = await context.runSandbox();
|
|
676
|
+
let result;
|
|
677
|
+
try {
|
|
678
|
+
result = await session.execute({
|
|
679
|
+
stepId: context.step.id,
|
|
680
|
+
kind: "code",
|
|
681
|
+
name: context.step.id,
|
|
682
|
+
arguments: {
|
|
683
|
+
language: context.step.language,
|
|
684
|
+
code: context.step.code,
|
|
685
|
+
variables: { ...context.variables },
|
|
686
|
+
...(context.step.environment
|
|
687
|
+
? { environment: context.step.environment }
|
|
688
|
+
: {}),
|
|
689
|
+
timeoutMs,
|
|
690
|
+
workspaces: [...(context.step.workspaces ?? [])],
|
|
691
|
+
},
|
|
692
|
+
...(context.signal ? { signal: context.signal } : {}),
|
|
693
|
+
});
|
|
694
|
+
}
|
|
695
|
+
catch (error) {
|
|
696
|
+
if (error.code === "sandbox_command_timeout") {
|
|
697
|
+
throw new SandboxTimeoutError(timeoutMs);
|
|
698
|
+
}
|
|
699
|
+
throw error;
|
|
700
|
+
}
|
|
701
|
+
const { record } = result;
|
|
702
|
+
await context.emit("code.execution.completed", {
|
|
703
|
+
exitCode: record.exitCode,
|
|
704
|
+
succeeded: record.exitCode === 0,
|
|
705
|
+
artifactCount: result.artifacts?.length ?? 0,
|
|
706
|
+
hasOutput: result.output !== undefined,
|
|
707
|
+
sandbox: "run",
|
|
708
|
+
commandId: record.id,
|
|
709
|
+
});
|
|
710
|
+
if (record.exitCode !== 0) {
|
|
711
|
+
throw new SandboxExecutionError(context.step.id, record.exitCode);
|
|
712
|
+
}
|
|
713
|
+
const output = result.output;
|
|
714
|
+
const patch = statePatch(context.step.outputVariable, output);
|
|
715
|
+
return {
|
|
716
|
+
...(output !== undefined ? { output } : {}),
|
|
717
|
+
...(patch ? { statePatch: patch } : {}),
|
|
718
|
+
...(result.artifacts ? { artifacts: result.artifacts } : {}),
|
|
719
|
+
metadata: {
|
|
720
|
+
exitCode: record.exitCode,
|
|
721
|
+
stdoutBytes: record.stdoutBytes,
|
|
722
|
+
stderrBytes: record.stderrBytes,
|
|
723
|
+
artifactCount: result.artifacts?.length ?? 0,
|
|
724
|
+
hasOutput: output !== undefined,
|
|
725
|
+
sandbox: "run",
|
|
726
|
+
command: JSON.parse(JSON.stringify(record)),
|
|
727
|
+
},
|
|
728
|
+
};
|
|
729
|
+
}
|
|
645
730
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clearideas/agent-runtime-step-standard",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Approval, webhook, and sandboxed code executors for Clear Ideas Agent Runtime.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Clear Ideas Incorporated",
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"postpack": "node ../../scripts/cleanup-package-license.mjs"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@clearideas/agent-runtime-contracts": "0.
|
|
40
|
-
"@clearideas/agent-runtime-core": "0.
|
|
39
|
+
"@clearideas/agent-runtime-contracts": "0.6.0",
|
|
40
|
+
"@clearideas/agent-runtime-core": "0.6.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"typescript": "^7.0.2",
|