@clearideas/agent-runtime-contracts 0.5.0 → 0.6.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.
- package/dist/index.d.ts +74 -1
- package/dist/index.js +77 -4
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -130,6 +130,71 @@ export interface AgentConnectionBinding {
|
|
|
130
130
|
mode?: "read" | "read_write";
|
|
131
131
|
required?: boolean;
|
|
132
132
|
}
|
|
133
|
+
export declare const WORKSPACE_MODES: readonly ["read", "read_write"];
|
|
134
|
+
export type WorkspaceMode = (typeof WORKSPACE_MODES)[number];
|
|
135
|
+
/**
|
|
136
|
+
* Binds a host-defined workspace (a code base, document store, or other
|
|
137
|
+
* durable file collection) to an agent. The host configuration defines the
|
|
138
|
+
* workspace; the agent may only narrow what the host permits.
|
|
139
|
+
*/
|
|
140
|
+
export interface AgentWorkspaceBinding {
|
|
141
|
+
/** Host-defined workspace name. */
|
|
142
|
+
ref: string;
|
|
143
|
+
/** Tool prefix and sandbox mount name. Defaults to ref. */
|
|
144
|
+
alias?: string;
|
|
145
|
+
/** Optional per-agent narrowing of the workspace tool set. */
|
|
146
|
+
tools?: string[];
|
|
147
|
+
/** An agent may request fewer privileges than the configured workspace, never more. */
|
|
148
|
+
mode?: WorkspaceMode;
|
|
149
|
+
required?: boolean;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* One command executed in the run sandbox on behalf of a tool call or a code
|
|
153
|
+
* step. Attached to tool results, step results, and sandbox events so the
|
|
154
|
+
* host has a complete durable record of what ran.
|
|
155
|
+
*/
|
|
156
|
+
export interface SandboxCommandRecord {
|
|
157
|
+
id: string;
|
|
158
|
+
runId: string;
|
|
159
|
+
attempt: number;
|
|
160
|
+
stepId: string;
|
|
161
|
+
toolCallId?: string;
|
|
162
|
+
workspace?: string;
|
|
163
|
+
alias?: string;
|
|
164
|
+
kind: "builtin" | "command" | "shell" | "code";
|
|
165
|
+
name: string;
|
|
166
|
+
policyEntry?: string;
|
|
167
|
+
argv: string[];
|
|
168
|
+
cwd: string;
|
|
169
|
+
startedAt: string;
|
|
170
|
+
completedAt: string;
|
|
171
|
+
durationMs: number;
|
|
172
|
+
exitCode: number;
|
|
173
|
+
timedOut: boolean;
|
|
174
|
+
stdoutBytes: number;
|
|
175
|
+
stderrBytes: number;
|
|
176
|
+
stdoutTruncated: boolean;
|
|
177
|
+
stderrTruncated: boolean;
|
|
178
|
+
filesChanged: Array<{
|
|
179
|
+
alias: string;
|
|
180
|
+
path: string;
|
|
181
|
+
action: "created" | "modified" | "deleted";
|
|
182
|
+
size?: number;
|
|
183
|
+
sha256?: string;
|
|
184
|
+
}>;
|
|
185
|
+
artifacts?: string[];
|
|
186
|
+
ignoredPaths: Array<{
|
|
187
|
+
alias: string;
|
|
188
|
+
path: string;
|
|
189
|
+
reason: string;
|
|
190
|
+
}>;
|
|
191
|
+
budget: {
|
|
192
|
+
commandsUsed: number;
|
|
193
|
+
commandsLimit: number;
|
|
194
|
+
sandboxSecondsUsed: number;
|
|
195
|
+
sandboxSecondsLimit: number;
|
|
196
|
+
};
|
|
197
|
+
}
|
|
133
198
|
export interface AgentVariableDefinition {
|
|
134
199
|
key: string;
|
|
135
200
|
type: AgentVariableType;
|
|
@@ -224,9 +289,14 @@ export interface CodeStep extends AgentStepBase {
|
|
|
224
289
|
code: string;
|
|
225
290
|
timeoutMs?: number;
|
|
226
291
|
environment?: Record<string, string>;
|
|
292
|
+
/** Bound workspace aliases available to the step. Implies sandbox: run. */
|
|
293
|
+
workspaces?: string[];
|
|
294
|
+
/** run: execute in the run sandbox; step: ephemeral per-step sandbox. */
|
|
295
|
+
sandbox?: "run" | "step";
|
|
227
296
|
}
|
|
228
297
|
export type AgentStep = PromptStep | LoopStep | WebhookStep | ApprovalStep | SubRunStep | CodeStep;
|
|
229
298
|
export declare const promptMessageSchema: z.ZodType<PromptMessage>;
|
|
299
|
+
export declare const agentWorkspaceBindingSchema: z.ZodType<AgentWorkspaceBinding>;
|
|
230
300
|
export declare const agentStepSchema: z.ZodType<AgentStep>;
|
|
231
301
|
export interface AgentManifest {
|
|
232
302
|
schemaVersion: typeof AGENT_MANIFEST_SCHEMA_VERSION;
|
|
@@ -236,12 +306,15 @@ export interface AgentManifest {
|
|
|
236
306
|
model?: ModelReference;
|
|
237
307
|
variables?: AgentVariableDefinition[];
|
|
238
308
|
connections?: AgentConnectionBinding[];
|
|
309
|
+
/** Host-defined file collections available to workspace tools and code steps. */
|
|
310
|
+
workspaces?: AgentWorkspaceBinding[];
|
|
239
311
|
steps: AgentStep[];
|
|
240
312
|
limits?: {
|
|
241
313
|
maxSteps?: number;
|
|
242
314
|
maxMessagesPerPrompt?: number;
|
|
243
315
|
maxInputBytes?: number;
|
|
244
316
|
maxOutputBytes?: number;
|
|
317
|
+
/** Total tool calls per prompt step execution, across model turns and resumes. */
|
|
245
318
|
maxToolCallsPerIteration?: number;
|
|
246
319
|
providerTimeoutMs?: number;
|
|
247
320
|
};
|
|
@@ -1043,7 +1116,7 @@ export declare const runCheckpointSchema: z.ZodObject<{
|
|
|
1043
1116
|
metadata: z.ZodOptional<z.ZodType<JsonObject, unknown, z.core.$ZodTypeInternals<JsonObject, unknown>>>;
|
|
1044
1117
|
}, z.core.$strict>;
|
|
1045
1118
|
export declare const parseRunCheckpoint: (input: unknown) => RunCheckpoint;
|
|
1046
|
-
export type RunEventType = "run.started" | "run.resumed" | "run.completed" | "run.failed" | "run.cancelled" | "run.suspended" | "run.heartbeat" | "step.started" | "step.skipped" | "step.completed" | "step.failed" | "checkpoint.saved" | "loop.iteration.started" | "loop.iteration.completed" | "loop.iteration.skipped" | "loop.goal.met" | "approval.requested" | "approval.resolved" | "webhook.attempt.started" | "webhook.attempt.completed" | "webhook.retry.scheduled" | "code.execution.started" | "code.execution.completed" | "sub-run.started" | "sub-run.completed" | "model.started" | "model.text.delta" | "model.reasoning.delta" | "model.tool.requested" | "model.tool.started" | "model.tool.completed" | "model.usage" | "model.completed" | "artifact.created" | "diagnostic";
|
|
1119
|
+
export type RunEventType = "run.started" | "run.resumed" | "run.completed" | "run.failed" | "run.cancelled" | "run.suspended" | "run.heartbeat" | "step.started" | "step.skipped" | "step.completed" | "step.failed" | "checkpoint.saved" | "loop.iteration.started" | "loop.iteration.completed" | "loop.iteration.skipped" | "loop.goal.met" | "approval.requested" | "approval.resolved" | "webhook.attempt.started" | "webhook.attempt.completed" | "webhook.retry.scheduled" | "code.execution.started" | "code.execution.completed" | "workspace.bound" | "sandbox.opened" | "sandbox.command.started" | "sandbox.command.completed" | "sandbox.closed" | "sub-run.started" | "sub-run.completed" | "model.started" | "model.text.delta" | "model.reasoning.delta" | "model.tool.requested" | "model.tool.started" | "model.tool.completed" | "model.usage" | "model.completed" | "artifact.created" | "diagnostic";
|
|
1047
1120
|
export interface RunEvent {
|
|
1048
1121
|
id: string;
|
|
1049
1122
|
runId: string;
|
package/dist/index.js
CHANGED
|
@@ -41,6 +41,7 @@ export const agentVariableKeySchema = z
|
|
|
41
41
|
.max(100)
|
|
42
42
|
.refine((value) => !value.includes("."), "Variable keys cannot contain dots; use dot notation only to read properties inside object values.")
|
|
43
43
|
.refine((value) => !RESERVED_VARIABLE_PATH_SEGMENTS.has(value.toLowerCase()), "Variable keys cannot use prototype-sensitive names.");
|
|
44
|
+
export const WORKSPACE_MODES = ["read", "read_write"];
|
|
44
45
|
export const valueMatchesAgentVariableType = (value, type) => {
|
|
45
46
|
if (type === "array")
|
|
46
47
|
return Array.isArray(value);
|
|
@@ -178,16 +179,24 @@ export const promptMessageSchema = z.lazy(() => z
|
|
|
178
179
|
}
|
|
179
180
|
});
|
|
180
181
|
}));
|
|
182
|
+
const bindingAliasSchema = z
|
|
183
|
+
.string()
|
|
184
|
+
.regex(/^[a-z][a-z0-9-]*$/u)
|
|
185
|
+
.optional();
|
|
181
186
|
const agentConnectionBindingSchema = z.strictObject({
|
|
182
187
|
ref: z.string().min(1),
|
|
183
|
-
alias:
|
|
184
|
-
.string()
|
|
185
|
-
.regex(/^[a-z][a-z0-9-]*$/u)
|
|
186
|
-
.optional(),
|
|
188
|
+
alias: bindingAliasSchema,
|
|
187
189
|
tools: z.array(z.string().min(1)).optional(),
|
|
188
190
|
mode: z.enum(["read", "read_write"]).optional(),
|
|
189
191
|
required: z.boolean().optional(),
|
|
190
192
|
});
|
|
193
|
+
export const agentWorkspaceBindingSchema = z.strictObject({
|
|
194
|
+
ref: z.string().min(1),
|
|
195
|
+
alias: bindingAliasSchema,
|
|
196
|
+
tools: z.array(z.string().min(1)).optional(),
|
|
197
|
+
mode: z.enum(WORKSPACE_MODES).optional(),
|
|
198
|
+
required: z.boolean().optional(),
|
|
199
|
+
});
|
|
191
200
|
// The prompt refinement below enforces the PromptStep input union. Zod retains
|
|
192
201
|
// optional field inference after superRefine, so expose the refined output type.
|
|
193
202
|
export const agentStepSchema = z.lazy(() => z.discriminatedUnion("type", [
|
|
@@ -345,6 +354,8 @@ export const agentStepSchema = z.lazy(() => z.discriminatedUnion("type", [
|
|
|
345
354
|
code: z.string(),
|
|
346
355
|
timeoutMs: z.number().int().positive().optional(),
|
|
347
356
|
environment: z.record(z.string(), z.string()).optional(),
|
|
357
|
+
workspaces: z.array(z.string().min(1)).optional(),
|
|
358
|
+
sandbox: z.enum(["run", "step"]).optional(),
|
|
348
359
|
}),
|
|
349
360
|
]));
|
|
350
361
|
const validateSiblingStepIds = (steps, context, path) => {
|
|
@@ -363,6 +374,45 @@ const validateSiblingStepIds = (steps, context, path) => {
|
|
|
363
374
|
}
|
|
364
375
|
});
|
|
365
376
|
};
|
|
377
|
+
const validateCodeStepWorkspaces = (steps, workspaceAliases, context, path) => {
|
|
378
|
+
steps.forEach((step, index) => {
|
|
379
|
+
if (step.type === "loop") {
|
|
380
|
+
validateCodeStepWorkspaces(step.steps, workspaceAliases, context, [
|
|
381
|
+
...path,
|
|
382
|
+
index,
|
|
383
|
+
"steps",
|
|
384
|
+
]);
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
if (step.type !== "code")
|
|
388
|
+
return;
|
|
389
|
+
if (step.sandbox === "step" && (step.workspaces?.length ?? 0) > 0) {
|
|
390
|
+
context.addIssue({
|
|
391
|
+
code: "custom",
|
|
392
|
+
message: `Code step ${step.id} cannot mount workspaces in a per-step sandbox; use sandbox: run.`,
|
|
393
|
+
path: [...path, index, "sandbox"],
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
const seen = new Set();
|
|
397
|
+
(step.workspaces ?? []).forEach((alias, aliasIndex) => {
|
|
398
|
+
if (!workspaceAliases.has(alias)) {
|
|
399
|
+
context.addIssue({
|
|
400
|
+
code: "custom",
|
|
401
|
+
message: `Code step ${step.id} references an undeclared workspace alias: ${alias}`,
|
|
402
|
+
path: [...path, index, "workspaces", aliasIndex],
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
if (seen.has(alias)) {
|
|
406
|
+
context.addIssue({
|
|
407
|
+
code: "custom",
|
|
408
|
+
message: `Code step ${step.id} lists workspace ${alias} more than once`,
|
|
409
|
+
path: [...path, index, "workspaces", aliasIndex],
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
seen.add(alias);
|
|
413
|
+
});
|
|
414
|
+
});
|
|
415
|
+
};
|
|
366
416
|
const MAXIMUM_AGENT_MANIFEST_STRUCTURE_DEPTH = 128;
|
|
367
417
|
const MAXIMUM_AGENT_MANIFEST_STRUCTURE_NODES = 100_000;
|
|
368
418
|
const agentManifestStructureIssue = (input) => {
|
|
@@ -414,6 +464,7 @@ const agentManifestObjectSchema = z
|
|
|
414
464
|
model: modelReferenceSchema.optional(),
|
|
415
465
|
variables: z.array(agentVariableDefinitionSchema).optional(),
|
|
416
466
|
connections: z.array(agentConnectionBindingSchema).optional(),
|
|
467
|
+
workspaces: z.array(agentWorkspaceBindingSchema).optional(),
|
|
417
468
|
steps: z.array(agentStepSchema),
|
|
418
469
|
limits: z
|
|
419
470
|
.object({
|
|
@@ -443,7 +494,29 @@ const agentManifestObjectSchema = z
|
|
|
443
494
|
}
|
|
444
495
|
connectionAliases.add(alias);
|
|
445
496
|
});
|
|
497
|
+
const workspaceAliases = new Set();
|
|
498
|
+
manifest.workspaces?.forEach((workspace, index) => {
|
|
499
|
+
const alias = workspace.alias ?? workspace.ref;
|
|
500
|
+
if (workspaceAliases.has(alias)) {
|
|
501
|
+
context.addIssue({
|
|
502
|
+
code: "custom",
|
|
503
|
+
message: `Duplicate workspace alias: ${alias}`,
|
|
504
|
+
path: ["workspaces", index, "alias"],
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
else if (connectionAliases.has(alias)) {
|
|
508
|
+
context.addIssue({
|
|
509
|
+
code: "custom",
|
|
510
|
+
message: `Workspace alias collides with a connection alias: ${alias}`,
|
|
511
|
+
path: ["workspaces", index, "alias"],
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
workspaceAliases.add(alias);
|
|
515
|
+
});
|
|
446
516
|
validateSiblingStepIds(manifest.steps, context, ["steps"]);
|
|
517
|
+
validateCodeStepWorkspaces(manifest.steps, workspaceAliases, context, [
|
|
518
|
+
"steps",
|
|
519
|
+
]);
|
|
447
520
|
const variableKeys = new Set();
|
|
448
521
|
manifest.variables?.forEach((definition, index) => {
|
|
449
522
|
const normalizedKey = definition.key.toLowerCase();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clearideas/agent-runtime-contracts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "Versioned, persistence-independent contracts for Clear Ideas Agent Runtime.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Clear Ideas Incorporated",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"postpack": "node ../../scripts/cleanup-package-license.mjs"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"zod": "^4.6.
|
|
39
|
+
"zod": "^4.6.6"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"typescript": "^7.0.2",
|