@agentproto/routine 0.1.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.
- package/LICENSE +21 -0
- package/README.md +23 -0
- package/dist/chunk-EIXUDVBW.mjs +47 -0
- package/dist/chunk-EIXUDVBW.mjs.map +1 -0
- package/dist/index-C6hgOdlW.d.ts +261 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.mjs +31 -0
- package/dist/index.mjs.map +1 -0
- package/dist/manifest/index.d.ts +2 -0
- package/dist/manifest/index.mjs +3 -0
- package/dist/manifest/index.mjs.map +1 -0
- package/package.json +69 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 agentproto contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# @agentproto/routine
|
|
2
|
+
|
|
3
|
+
AIP-41 `ROUTINE.md` reference implementation. A markdown + frontmatter format for declaring a recurring or event-driven invocation of an action, workflow, or tool. Decouples "when" (the schedule) from "what" (the target). Supports cron / interval / calendar / manual / event-driven schedules, with retry, jitter, catchup policy, identity attribution, and failure routing.
|
|
4
|
+
|
|
5
|
+
> **Status: 0.1.0-alpha.** Generated by `scripts/scaffold-aip.mjs` — `build()` and `validate()` bodies are TODOs.
|
|
6
|
+
|
|
7
|
+
Spec: <https://agentproto.sh/docs/aip-41>
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { defineRoutine } from "@agentproto/routine"
|
|
13
|
+
|
|
14
|
+
const x = defineRoutine({
|
|
15
|
+
id: "my-routine",
|
|
16
|
+
description: "Short purpose.",
|
|
17
|
+
// ...
|
|
18
|
+
})
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## License
|
|
22
|
+
|
|
23
|
+
MIT — see [LICENSE](./LICENSE).
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import matter from 'gray-matter';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { createDoctype } from '@agentproto/define-doctype';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @agentproto/routine v0.1.0-alpha
|
|
7
|
+
* AIP-41 ROUTINE.md `defineRoutine` reference implementation.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var routineFrontmatterSchema = z.object({ "schema": z.literal("routine/v1"), "id": z.string().regex(new RegExp("^[a-z0-9@][a-z0-9.@/_-]*$")).min(2).max(80).describe("Machine identifier. Lowercase, digits, dashes, dots, optional @owner/ prefix. Unique within the registry that hosts the routine."), "description": z.string().min(1).max(2e3).describe("One-paragraph purpose."), "version": z.string().regex(new RegExp("^\\d+\\.\\d+\\.\\d+(?:[-+][\\w.\\-]+)?$")).describe("Spec version of THIS file.").default("1.0.0"), "schedule": z.any().describe("When the routine fires."), "target": z.any().describe("What the routine invokes when it fires."), "identity": z.any().describe("Identity that owns the routine fire (AIP-23). Defaults to host policy.").optional(), "retry": z.any().describe("Retry behaviour on failure.").optional(), "on_failure": z.any().describe("Where to route failures after retries exhaust.").optional(), "history": z.any().describe("Run history retention.").optional(), "fires_events": z.array(z.string().min(1)).describe("AIP-37 LIFECYCLE event names this routine fires.").default(["routine-triggered", "routine-completed", "routine-failed"]), "enabled": z.boolean().describe("If false, routine registers but does not fire. Useful for staging.").default(true), "tags": z.array(z.string()).describe("Free-form discovery tags.").default([]), "metadata": z.record(z.string(), z.any()).describe("Free-form, namespaced.").optional() }).strict().describe("Validates the YAML frontmatter portion of an AIP-41 ROUTINE.md manifest. Decouples 'when' (schedule) from 'what' (target action/workflow/tool).");
|
|
11
|
+
var defineRoutine = createDoctype({
|
|
12
|
+
aip: 41,
|
|
13
|
+
name: "routine",
|
|
14
|
+
validate(def) {
|
|
15
|
+
const result = routineFrontmatterSchema.safeParse(def);
|
|
16
|
+
if (!result.success) {
|
|
17
|
+
throw new Error(
|
|
18
|
+
`defineRoutine (AIP-41): ${result.error.issues.map((i) => `${i.path.join(".")}: ${i.message}`).join("; ")}`
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
build(def) {
|
|
23
|
+
return { ...def };
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// src/manifest/index.ts
|
|
28
|
+
function parseRoutineManifest(source) {
|
|
29
|
+
const parsed = matter(source);
|
|
30
|
+
if (Object.keys(parsed.data).length === 0) {
|
|
31
|
+
throw new Error("parseRoutineManifest: missing or empty frontmatter");
|
|
32
|
+
}
|
|
33
|
+
const result = routineFrontmatterSchema.safeParse(parsed.data);
|
|
34
|
+
if (!result.success) {
|
|
35
|
+
throw new Error(
|
|
36
|
+
`parseRoutineManifest: invalid frontmatter \u2014 ${result.error.issues.map((i) => `${i.path.join(".")}: ${i.message}`).join("; ")}`
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
return { frontmatter: result.data, body: parsed.content };
|
|
40
|
+
}
|
|
41
|
+
function routineFromManifest(manifest) {
|
|
42
|
+
return defineRoutine(manifest.frontmatter);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { defineRoutine, parseRoutineManifest, routineFromManifest, routineFrontmatterSchema };
|
|
46
|
+
//# sourceMappingURL=chunk-EIXUDVBW.mjs.map
|
|
47
|
+
//# sourceMappingURL=chunk-EIXUDVBW.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/schema.ts","../src/define-routine.ts","../src/manifest/index.ts"],"names":[],"mappings":"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","file":"chunk-EIXUDVBW.mjs","sourcesContent":["/**\n * AIP-41 ROUTINE.md frontmatter zod schema.\n *\n * Generated from `resources/aip-41/draft/ROUTINE.schema.json` via\n * json-schema-to-zod. Imported by both `define-routine.ts` (TS path\n * validation) and `manifest/index.ts` (.md path validation) so every\n * field-level constraint runs in both authoring paths from a single\n * source of truth — re-run scaffold-aip to refresh after spec changes.\n *\n * Cross-field rules (if/then/allOf in JSON Schema) don't translate\n * cleanly and live in `define-routine.ts`'s `validate(def)` instead.\n */\n\nimport { z } from \"zod\"\n\nexport const routineFrontmatterSchema = z.object({ \"schema\": z.literal(\"routine/v1\"), \"id\": z.string().regex(new RegExp(\"^[a-z0-9@][a-z0-9.@/_-]*$\")).min(2).max(80).describe(\"Machine identifier. Lowercase, digits, dashes, dots, optional @owner/ prefix. Unique within the registry that hosts the routine.\"), \"description\": z.string().min(1).max(2000).describe(\"One-paragraph purpose.\"), \"version\": z.string().regex(new RegExp(\"^\\\\d+\\\\.\\\\d+\\\\.\\\\d+(?:[-+][\\\\w.\\\\-]+)?$\")).describe(\"Spec version of THIS file.\").default(\"1.0.0\"), \"schedule\": z.any().describe(\"When the routine fires.\"), \"target\": z.any().describe(\"What the routine invokes when it fires.\"), \"identity\": z.any().describe(\"Identity that owns the routine fire (AIP-23). Defaults to host policy.\").optional(), \"retry\": z.any().describe(\"Retry behaviour on failure.\").optional(), \"on_failure\": z.any().describe(\"Where to route failures after retries exhaust.\").optional(), \"history\": z.any().describe(\"Run history retention.\").optional(), \"fires_events\": z.array(z.string().min(1)).describe(\"AIP-37 LIFECYCLE event names this routine fires.\").default([\"routine-triggered\",\"routine-completed\",\"routine-failed\"]), \"enabled\": z.boolean().describe(\"If false, routine registers but does not fire. Useful for staging.\").default(true), \"tags\": z.array(z.string()).describe(\"Free-form discovery tags.\").default([] as never), \"metadata\": z.record(z.string(), z.any()).describe(\"Free-form, namespaced.\").optional() }).strict().describe(\"Validates the YAML frontmatter portion of an AIP-41 ROUTINE.md manifest. Decouples 'when' (schedule) from 'what' (target action/workflow/tool).\")\n\nexport type RoutineFrontmatter = z.infer<typeof routineFrontmatterSchema>\n","import { createDoctype } from \"@agentproto/define-doctype\"\nimport { routineFrontmatterSchema } from \"./schema.js\"\nimport type { RoutineDefinition, RoutineHandle } from \"./types.js\"\n\n/**\n * AIP-41 reference implementation of `defineRoutine`.\n *\n * Built on `createDoctype` so the cross-AIP invariants (id pattern,\n * description length, top-level freeze, \"defineRoutine (AIP-41): …\"\n * error prefix) run uniformly with every other AIP defineX.\n *\n * Field-level validation runs the schema-derived zod from\n * `./schema.ts` against the input. Same source of truth as the .md\n * path uses (`parseRoutineManifest`), so a malformed TS-authored\n * definition fails with the same diagnostic as a malformed manifest.\n * Cross-field rules go in `validate(def)` after the zod check.\n */\nexport const defineRoutine = createDoctype<RoutineDefinition, RoutineHandle>({\n aip: 41,\n name: \"routine\",\n validate(def) {\n const result = routineFrontmatterSchema.safeParse(def)\n if (!result.success) {\n throw new Error(\n `defineRoutine (AIP-41): ${result.error.issues\n .map((i) => `${i.path.join(\".\")}: ${i.message}`)\n .join(\"; \")}`,\n )\n }\n // TODO: spec-41-specific cross-field rules (if/then/allOf in\n // the JSON Schema) — those don't translate to zod cleanly and\n // belong here. See @agentproto/operator's autonomy=gated rule.\n },\n build(def) {\n // Default build: spread the validated definition into a fresh object.\n // Hand-tune for nested freezing (Object.freeze on arrays/objects) and\n // for fields that need defaults applied — see @agentproto/operator\n // for a reference shape.\n return { ...def } as RoutineHandle\n },\n})\n","/**\n * AIP-41 ROUTINE.md sidecar parser + manifest-to-handle constructor.\n *\n * Mirror of `@agentproto/tool/manifest` and `@agentproto/driver/manifest`:\n * the .md provides metadata; the TS module supplies any spec-specific\n * runtime bits (schemas, execute bodies, …) that can't live in\n * frontmatter. Both inputs end up in `defineRoutine` so the cross-AIP\n * invariants run uniformly.\n *\n *\n * The frontmatter zod schema below was generated from\n * `resources/aip-41/draft/ROUTINE.schema.json` via json-schema-to-zod.\n * Re-run scaffold-aip to refresh after spec changes (or hand-tune\n * any constraint the converter doesn't capture cleanly).\n */\n\nimport matter from \"gray-matter\"\nimport { routineFrontmatterSchema, type RoutineFrontmatter } from \"../schema.js\"\nimport { defineRoutine } from \"../define-routine.js\"\nimport type { RoutineDefinition, RoutineHandle } from \"../types.js\"\n\n// Re-export so consumers can import the schema + inferred type either\n// from \"@@agentproto/routine/manifest\" or directly from \"@@agentproto/routine/schema\".\nexport { routineFrontmatterSchema, type RoutineFrontmatter }\n\nexport interface RoutineManifest {\n frontmatter: RoutineFrontmatter\n body: string\n}\n\nexport function parseRoutineManifest(source: string): RoutineManifest {\n const parsed = matter(source)\n if (Object.keys(parsed.data).length === 0) {\n throw new Error(\"parseRoutineManifest: missing or empty frontmatter\")\n }\n const result = routineFrontmatterSchema.safeParse(parsed.data)\n if (!result.success) {\n throw new Error(\n `parseRoutineManifest: invalid frontmatter — ${result.error.issues\n .map((i) => `${i.path.join(\".\")}: ${i.message}`)\n .join(\"; \")}`,\n )\n }\n return { frontmatter: result.data, body: parsed.content }\n}\n\nexport function routineFromManifest(manifest: RoutineManifest): RoutineHandle {\n // The zod-validated frontmatter is structurally compatible with\n // RoutineDefinition; the cast pins the typing once the manifest\n // schema and the TS interface diverge (e.g. handle has frozen fields\n // a literal config doesn't carry yet).\n return defineRoutine(manifest.frontmatter as unknown as RoutineDefinition)\n}\n"]}
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* AIP-41 RoutineDefinition + RoutineHandle.
|
|
5
|
+
*
|
|
6
|
+
* `RoutineDefinition` was generated from
|
|
7
|
+
* `resources/aip-41/draft/ROUTINE.schema.json` via json-schema-to-typescript.
|
|
8
|
+
* `RoutineHandle` is the readonly view of the same shape; tighten it
|
|
9
|
+
* by hand for fields that get defaults applied in build().
|
|
10
|
+
*/
|
|
11
|
+
type IdentityRef = string | {
|
|
12
|
+
ref?: string;
|
|
13
|
+
file?: string;
|
|
14
|
+
inline?: {
|
|
15
|
+
name?: string;
|
|
16
|
+
email?: string;
|
|
17
|
+
};
|
|
18
|
+
[k: string]: unknown;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Validates the YAML frontmatter portion of an AIP-41 ROUTINE.md manifest. Decouples 'when' (schedule) from 'what' (target action/workflow/tool).
|
|
22
|
+
*/
|
|
23
|
+
interface RoutineDefinition {
|
|
24
|
+
schema: "routine/v1";
|
|
25
|
+
/**
|
|
26
|
+
* Machine identifier. Lowercase, digits, dashes, dots, optional @owner/ prefix. Unique within the registry that hosts the routine.
|
|
27
|
+
*/
|
|
28
|
+
id: string;
|
|
29
|
+
/**
|
|
30
|
+
* One-paragraph purpose.
|
|
31
|
+
*/
|
|
32
|
+
description: string;
|
|
33
|
+
/**
|
|
34
|
+
* Spec version of THIS file.
|
|
35
|
+
*/
|
|
36
|
+
version?: string;
|
|
37
|
+
/**
|
|
38
|
+
* When the routine fires.
|
|
39
|
+
*/
|
|
40
|
+
schedule: ScheduleCron | ScheduleInterval | ScheduleCalendar | ScheduleManual | ScheduleEvent;
|
|
41
|
+
/**
|
|
42
|
+
* What the routine invokes when it fires.
|
|
43
|
+
*/
|
|
44
|
+
target: TargetAction | TargetWorkflow | TargetTool;
|
|
45
|
+
/**
|
|
46
|
+
* Identity that owns the routine fire (AIP-23). Defaults to host policy.
|
|
47
|
+
*/
|
|
48
|
+
identity?: string | {
|
|
49
|
+
ref?: string;
|
|
50
|
+
file?: string;
|
|
51
|
+
inline?: {
|
|
52
|
+
name?: string;
|
|
53
|
+
email?: string;
|
|
54
|
+
};
|
|
55
|
+
[k: string]: unknown;
|
|
56
|
+
};
|
|
57
|
+
retry?: Retry;
|
|
58
|
+
on_failure?: OnFailure;
|
|
59
|
+
history?: History;
|
|
60
|
+
/**
|
|
61
|
+
* AIP-37 LIFECYCLE event names this routine fires.
|
|
62
|
+
*/
|
|
63
|
+
fires_events?: string[];
|
|
64
|
+
/**
|
|
65
|
+
* If false, routine registers but does not fire. Useful for staging.
|
|
66
|
+
*/
|
|
67
|
+
enabled?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Free-form discovery tags.
|
|
70
|
+
*/
|
|
71
|
+
tags?: string[];
|
|
72
|
+
/**
|
|
73
|
+
* Free-form, namespaced.
|
|
74
|
+
*/
|
|
75
|
+
metadata?: {
|
|
76
|
+
[k: string]: unknown;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
interface ScheduleCron {
|
|
80
|
+
kind: "cron";
|
|
81
|
+
/**
|
|
82
|
+
* Standard 5-field cron expression.
|
|
83
|
+
*/
|
|
84
|
+
cron: string;
|
|
85
|
+
/**
|
|
86
|
+
* IANA tz database name. Legacy abbreviations rejected.
|
|
87
|
+
*/
|
|
88
|
+
timezone?: string;
|
|
89
|
+
jitter_seconds?: number;
|
|
90
|
+
catchup?: "skip" | "one" | "all";
|
|
91
|
+
}
|
|
92
|
+
interface ScheduleInterval {
|
|
93
|
+
kind: "interval";
|
|
94
|
+
/**
|
|
95
|
+
* Duration: Ns | Nm | Nh | Nd.
|
|
96
|
+
*/
|
|
97
|
+
every: string;
|
|
98
|
+
/**
|
|
99
|
+
* OPTIONAL anchor; default = registration time.
|
|
100
|
+
*/
|
|
101
|
+
from?: string;
|
|
102
|
+
jitter_seconds?: number;
|
|
103
|
+
}
|
|
104
|
+
interface ScheduleCalendar {
|
|
105
|
+
kind: "calendar";
|
|
106
|
+
/**
|
|
107
|
+
* RFC 5545 RRULE.
|
|
108
|
+
*/
|
|
109
|
+
rrule: string;
|
|
110
|
+
timezone?: string;
|
|
111
|
+
}
|
|
112
|
+
interface ScheduleManual {
|
|
113
|
+
kind: "manual";
|
|
114
|
+
}
|
|
115
|
+
interface ScheduleEvent {
|
|
116
|
+
kind: "event";
|
|
117
|
+
/**
|
|
118
|
+
* AIP-37 LIFECYCLE event name.
|
|
119
|
+
*/
|
|
120
|
+
on: string;
|
|
121
|
+
/**
|
|
122
|
+
* OPTIONAL — only fire if event payload matches filter.
|
|
123
|
+
*/
|
|
124
|
+
filter?: {
|
|
125
|
+
[k: string]: unknown;
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
interface TargetAction {
|
|
129
|
+
/**
|
|
130
|
+
* AIP-39 ACTION ref. Resolver picks tool implementation.
|
|
131
|
+
*/
|
|
132
|
+
action: string;
|
|
133
|
+
/**
|
|
134
|
+
* Invocation payload. May reference ${{ vault.* }} and ${{ now }}.
|
|
135
|
+
*/
|
|
136
|
+
inputs?: {
|
|
137
|
+
[k: string]: unknown;
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
interface TargetWorkflow {
|
|
141
|
+
/**
|
|
142
|
+
* AIP-15 WORKFLOW ref.
|
|
143
|
+
*/
|
|
144
|
+
workflow: string | AnyRef;
|
|
145
|
+
inputs?: {
|
|
146
|
+
[k: string]: unknown;
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* AIP-27 ref primitive — exactly one of ref|file|inline.
|
|
151
|
+
*/
|
|
152
|
+
interface AnyRef {
|
|
153
|
+
ref?: string;
|
|
154
|
+
file?: string;
|
|
155
|
+
inline?: {
|
|
156
|
+
[k: string]: unknown;
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
interface TargetTool {
|
|
160
|
+
/**
|
|
161
|
+
* AIP-14 TOOL id (pin specific implementation).
|
|
162
|
+
*/
|
|
163
|
+
tool: string;
|
|
164
|
+
inputs?: {
|
|
165
|
+
[k: string]: unknown;
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Retry behaviour on failure.
|
|
170
|
+
*/
|
|
171
|
+
interface Retry {
|
|
172
|
+
max_attempts?: number;
|
|
173
|
+
backoff?: "exponential" | "linear" | "fixed";
|
|
174
|
+
initial_ms?: number;
|
|
175
|
+
max_ms?: number;
|
|
176
|
+
/**
|
|
177
|
+
* OPTIONAL — only retry these failure classes.
|
|
178
|
+
*/
|
|
179
|
+
on?: string[];
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Where to route failures after retries exhaust.
|
|
183
|
+
*/
|
|
184
|
+
interface OnFailure {
|
|
185
|
+
/**
|
|
186
|
+
* Identity-refs to notify.
|
|
187
|
+
*/
|
|
188
|
+
notify?: IdentityRef[];
|
|
189
|
+
/**
|
|
190
|
+
* Open AIP-13/20 WORK item on retry-exhausted failure.
|
|
191
|
+
*/
|
|
192
|
+
create_work_item?: boolean;
|
|
193
|
+
/**
|
|
194
|
+
* OPTIONAL custom AIP-37 event to fire on failure.
|
|
195
|
+
*/
|
|
196
|
+
fire_event?: string;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Run history retention.
|
|
200
|
+
*/
|
|
201
|
+
interface History {
|
|
202
|
+
retain_runs?: number;
|
|
203
|
+
retain_failed?: number;
|
|
204
|
+
}
|
|
205
|
+
type RoutineHandle = Readonly<RoutineDefinition>;
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* AIP-41 ROUTINE.md frontmatter zod schema.
|
|
209
|
+
*
|
|
210
|
+
* Generated from `resources/aip-41/draft/ROUTINE.schema.json` via
|
|
211
|
+
* json-schema-to-zod. Imported by both `define-routine.ts` (TS path
|
|
212
|
+
* validation) and `manifest/index.ts` (.md path validation) so every
|
|
213
|
+
* field-level constraint runs in both authoring paths from a single
|
|
214
|
+
* source of truth — re-run scaffold-aip to refresh after spec changes.
|
|
215
|
+
*
|
|
216
|
+
* Cross-field rules (if/then/allOf in JSON Schema) don't translate
|
|
217
|
+
* cleanly and live in `define-routine.ts`'s `validate(def)` instead.
|
|
218
|
+
*/
|
|
219
|
+
|
|
220
|
+
declare const routineFrontmatterSchema: z.ZodObject<{
|
|
221
|
+
schema: z.ZodLiteral<"routine/v1">;
|
|
222
|
+
id: z.ZodString;
|
|
223
|
+
description: z.ZodString;
|
|
224
|
+
version: z.ZodDefault<z.ZodString>;
|
|
225
|
+
schedule: z.ZodAny;
|
|
226
|
+
target: z.ZodAny;
|
|
227
|
+
identity: z.ZodOptional<z.ZodAny>;
|
|
228
|
+
retry: z.ZodOptional<z.ZodAny>;
|
|
229
|
+
on_failure: z.ZodOptional<z.ZodAny>;
|
|
230
|
+
history: z.ZodOptional<z.ZodAny>;
|
|
231
|
+
fires_events: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
232
|
+
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
233
|
+
tags: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
234
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
235
|
+
}, z.core.$strict>;
|
|
236
|
+
type RoutineFrontmatter = z.infer<typeof routineFrontmatterSchema>;
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* AIP-41 ROUTINE.md sidecar parser + manifest-to-handle constructor.
|
|
240
|
+
*
|
|
241
|
+
* Mirror of `@agentproto/tool/manifest` and `@agentproto/driver/manifest`:
|
|
242
|
+
* the .md provides metadata; the TS module supplies any spec-specific
|
|
243
|
+
* runtime bits (schemas, execute bodies, …) that can't live in
|
|
244
|
+
* frontmatter. Both inputs end up in `defineRoutine` so the cross-AIP
|
|
245
|
+
* invariants run uniformly.
|
|
246
|
+
*
|
|
247
|
+
*
|
|
248
|
+
* The frontmatter zod schema below was generated from
|
|
249
|
+
* `resources/aip-41/draft/ROUTINE.schema.json` via json-schema-to-zod.
|
|
250
|
+
* Re-run scaffold-aip to refresh after spec changes (or hand-tune
|
|
251
|
+
* any constraint the converter doesn't capture cleanly).
|
|
252
|
+
*/
|
|
253
|
+
|
|
254
|
+
interface RoutineManifest {
|
|
255
|
+
frontmatter: RoutineFrontmatter;
|
|
256
|
+
body: string;
|
|
257
|
+
}
|
|
258
|
+
declare function parseRoutineManifest(source: string): RoutineManifest;
|
|
259
|
+
declare function routineFromManifest(manifest: RoutineManifest): RoutineHandle;
|
|
260
|
+
|
|
261
|
+
export { type RoutineDefinition as R, type RoutineHandle as a, type RoutineManifest as b, routineFrontmatterSchema as c, type RoutineFrontmatter as d, parseRoutineManifest as p, routineFromManifest as r };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { R as RoutineDefinition, a as RoutineHandle } from './index-C6hgOdlW.js';
|
|
2
|
+
export { b as RoutineManifest, p as parseRoutineManifest, r as routineFromManifest, c as routineFrontmatterSchema } from './index-C6hgOdlW.js';
|
|
3
|
+
import * as _agentproto_manifest from '@agentproto/manifest';
|
|
4
|
+
import { DoctypeSpec } from '@agentproto/manifest';
|
|
5
|
+
import 'zod';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* AIP-41 reference implementation of `defineRoutine`.
|
|
9
|
+
*
|
|
10
|
+
* Built on `createDoctype` so the cross-AIP invariants (id pattern,
|
|
11
|
+
* description length, top-level freeze, "defineRoutine (AIP-41): …"
|
|
12
|
+
* error prefix) run uniformly with every other AIP defineX.
|
|
13
|
+
*
|
|
14
|
+
* Field-level validation runs the schema-derived zod from
|
|
15
|
+
* `./schema.ts` against the input. Same source of truth as the .md
|
|
16
|
+
* path uses (`parseRoutineManifest`), so a malformed TS-authored
|
|
17
|
+
* definition fails with the same diagnostic as a malformed manifest.
|
|
18
|
+
* Cross-field rules go in `validate(def)` after the zod check.
|
|
19
|
+
*/
|
|
20
|
+
declare const defineRoutine: (def: RoutineDefinition) => Readonly<RoutineDefinition>;
|
|
21
|
+
|
|
22
|
+
declare const routineSpec: DoctypeSpec<RoutineDefinition, RoutineHandle>;
|
|
23
|
+
declare const routineVerbs: _agentproto_manifest.Verbs<RoutineDefinition, Readonly<RoutineDefinition>>;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @agentproto/routine — AIP-41 ROUTINE.md `defineRoutine` reference impl.
|
|
27
|
+
*
|
|
28
|
+
* A markdown + frontmatter format for declaring a recurring or event-driven invocation of an action, workflow, or tool. Decouples "when" (the schedule) from "what" (the target). Supports cron / interval / calendar / manual / event-driven schedules, with retry, jitter, catchup policy, identity attribution, and failure routing.
|
|
29
|
+
*
|
|
30
|
+
* Spec: https://agentproto.sh/docs/aip-41
|
|
31
|
+
*
|
|
32
|
+
* Authoring paths:
|
|
33
|
+
* - TS: `defineRoutine({...})` → `RoutineHandle`
|
|
34
|
+
* - MD: `parseRoutineManifest(src) → routineFromManifest({...})` → `RoutineHandle`
|
|
35
|
+
*/
|
|
36
|
+
declare const SPEC_NAME: "agentroutine/v1";
|
|
37
|
+
declare const SPEC_VERSION: "1.0.0-alpha";
|
|
38
|
+
|
|
39
|
+
export { RoutineDefinition, RoutineHandle, SPEC_NAME, SPEC_VERSION, defineRoutine, routineSpec, routineVerbs };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { defineRoutine, parseRoutineManifest } from './chunk-EIXUDVBW.mjs';
|
|
2
|
+
export { defineRoutine, parseRoutineManifest, routineFromManifest, routineFrontmatterSchema } from './chunk-EIXUDVBW.mjs';
|
|
3
|
+
import { createVerbs } from '@agentproto/manifest';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @agentproto/routine v0.1.0-alpha
|
|
7
|
+
* AIP-41 ROUTINE.md `defineRoutine` reference implementation.
|
|
8
|
+
*/
|
|
9
|
+
var routineSpec = {
|
|
10
|
+
name: "routine",
|
|
11
|
+
aip: 41,
|
|
12
|
+
schemaLiteral: "routine/v1",
|
|
13
|
+
pathOf: (h) => `.routines/${h.id}/ROUTINE.md`,
|
|
14
|
+
define: defineRoutine,
|
|
15
|
+
parse: (source) => {
|
|
16
|
+
const m = parseRoutineManifest(source);
|
|
17
|
+
return {
|
|
18
|
+
frontmatter: m.frontmatter,
|
|
19
|
+
body: m.body
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
var routineVerbs = createVerbs(routineSpec);
|
|
24
|
+
|
|
25
|
+
// src/index.ts
|
|
26
|
+
var SPEC_NAME = "agentroutine/v1";
|
|
27
|
+
var SPEC_VERSION = "1.0.0-alpha";
|
|
28
|
+
|
|
29
|
+
export { SPEC_NAME, SPEC_VERSION, routineSpec, routineVerbs };
|
|
30
|
+
//# sourceMappingURL=index.mjs.map
|
|
31
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/spec.ts","../src/index.ts"],"names":[],"mappings":";;;;;;;;AAYO,IAAM,WAAA,GAA6D;AAAA,EACxE,IAAA,EAAM,SAAA;AAAA,EACN,GAAA,EAAK,EAAA;AAAA,EACL,aAAA,EAAe,YAAA;AAAA,EACf,MAAA,EAAQ,CAAC,CAAA,KAAM,CAAA,UAAA,EAAa,EAAE,EAAE,CAAA,WAAA,CAAA;AAAA,EAChC,MAAA,EAAQ,aAAA;AAAA,EACR,KAAA,EAAO,CAAC,MAAA,KAAW;AACjB,IAAA,MAAM,CAAA,GAAI,qBAAqB,MAAM,CAAA;AACrC,IAAA,OAAO;AAAA,MACL,aAAa,CAAA,CAAE,WAAA;AAAA,MACf,MAAM,CAAA,CAAE;AAAA,KACV;AAAA,EACF;AACF;AAEO,IAAM,YAAA,GAAe,YAAY,WAAW;;;ACf5C,IAAM,SAAA,GAAY;AAClB,IAAM,YAAA,GAAe","file":"index.mjs","sourcesContent":["/**\n * AIP-41 doctype spec — fed to `@agentproto/manifest.createVerbs`\n * to derive create / load / list / update / resolve / delete in one\n * place. Plugs into `@agentproto/mcp-server` so a routine library\n * lives at `<workspace>/.routines/<id>/ROUTINE.md`.\n */\n\nimport { createVerbs, type DoctypeSpec } from \"@agentproto/manifest\"\nimport { defineRoutine } from \"./define-routine.js\"\nimport { parseRoutineManifest } from \"./manifest/index.js\"\nimport type { RoutineDefinition, RoutineHandle } from \"./types.js\"\n\nexport const routineSpec: DoctypeSpec<RoutineDefinition, RoutineHandle> = {\n name: \"routine\",\n aip: 41,\n schemaLiteral: \"routine/v1\",\n pathOf: (h) => `.routines/${h.id}/ROUTINE.md`,\n define: defineRoutine,\n parse: (source) => {\n const m = parseRoutineManifest(source)\n return {\n frontmatter: m.frontmatter as unknown as Record<string, unknown>,\n body: m.body,\n }\n },\n}\n\nexport const routineVerbs = createVerbs(routineSpec)\n","/**\n * @agentproto/routine — AIP-41 ROUTINE.md `defineRoutine` reference impl.\n *\n * A markdown + frontmatter format for declaring a recurring or event-driven invocation of an action, workflow, or tool. Decouples \"when\" (the schedule) from \"what\" (the target). Supports cron / interval / calendar / manual / event-driven schedules, with retry, jitter, catchup policy, identity attribution, and failure routing.\n *\n * Spec: https://agentproto.sh/docs/aip-41\n *\n * Authoring paths:\n * - TS: `defineRoutine({...})` → `RoutineHandle`\n * - MD: `parseRoutineManifest(src) → routineFromManifest({...})` → `RoutineHandle`\n */\n\nexport const SPEC_NAME = \"agentroutine/v1\" as const\nexport const SPEC_VERSION = \"1.0.0-alpha\" as const\n\nexport { defineRoutine } from \"./define-routine.js\"\nexport type { RoutineDefinition, RoutineHandle } from \"./types.js\"\nexport { routineSpec, routineVerbs } from \"./spec.js\"\nexport {\n parseRoutineManifest,\n routineFromManifest,\n routineFrontmatterSchema,\n type RoutineManifest,\n} from \"./manifest/index.js\"\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.mjs"}
|
package/package.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agentproto/routine",
|
|
3
|
+
"version": "0.1.0-alpha.1",
|
|
4
|
+
"description": "@agentproto/routine — AIP-41 ROUTINE.md reference implementation. A markdown + frontmatter format for declaring a recurring or event-driven invocation of an action, workflow, or tool. Decouples \"when\" (the schedule) from \"what\" (the target). Supports cron / interval / calendar / manual / event-driven schedules, with retry, jitter, catchup policy, identity attribution, and failure routing.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"agentproto",
|
|
7
|
+
"aip-41",
|
|
8
|
+
"routine",
|
|
9
|
+
"defineRoutine",
|
|
10
|
+
"open-standard",
|
|
11
|
+
"agentic"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://agentproto.sh/docs/aip-41",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/agentproto/ts",
|
|
17
|
+
"directory": "packages/routine"
|
|
18
|
+
},
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/agentproto/ts/issues"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"type": "module",
|
|
24
|
+
"main": "dist/index.mjs",
|
|
25
|
+
"module": "dist/index.mjs",
|
|
26
|
+
"types": "dist/index.d.ts",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"import": "./dist/index.mjs",
|
|
31
|
+
"default": "./dist/index.mjs"
|
|
32
|
+
},
|
|
33
|
+
"./manifest": {
|
|
34
|
+
"types": "./dist/manifest/index.d.ts",
|
|
35
|
+
"import": "./dist/manifest/index.mjs",
|
|
36
|
+
"default": "./dist/manifest/index.mjs"
|
|
37
|
+
},
|
|
38
|
+
"./package.json": "./package.json"
|
|
39
|
+
},
|
|
40
|
+
"files": [
|
|
41
|
+
"dist",
|
|
42
|
+
"README.md",
|
|
43
|
+
"LICENSE"
|
|
44
|
+
],
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"gray-matter": "^4.0.3",
|
|
50
|
+
"zod": "^4.4.3",
|
|
51
|
+
"@agentproto/manifest": "0.1.0-alpha.1",
|
|
52
|
+
"@agentproto/define-doctype": "0.1.0"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@types/node": "^25.6.2",
|
|
56
|
+
"tsup": "^8.5.1",
|
|
57
|
+
"typescript": "^5.9.3",
|
|
58
|
+
"vitest": "^3.2.4",
|
|
59
|
+
"@agentproto/tooling": "0.1.0-alpha.0"
|
|
60
|
+
},
|
|
61
|
+
"scripts": {
|
|
62
|
+
"dev": "tsup --watch",
|
|
63
|
+
"build": "tsup",
|
|
64
|
+
"clean": "rm -rf dist",
|
|
65
|
+
"check-types": "tsc --noEmit",
|
|
66
|
+
"test": "vitest run --passWithNoTests",
|
|
67
|
+
"test:watch": "vitest"
|
|
68
|
+
}
|
|
69
|
+
}
|