@agentproto/lesson 0.1.0-alpha.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/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/lesson
2
+
3
+ AIP-11 `LESSON.md` reference implementation. A markdown format for storing the transferable lessons an agent extracts from successful and failed runs — title, trigger, evidence, outcome — and a contract for how runtimes distill them and inject them back into future turns.
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-11>
8
+
9
+ ## Usage
10
+
11
+ ```ts
12
+ import { defineLesson } from "@agentproto/lesson"
13
+
14
+ const x = defineLesson({
15
+ id: "my-lesson",
16
+ description: "Short purpose.",
17
+ // ...
18
+ })
19
+ ```
20
+
21
+ ## License
22
+
23
+ MIT — see [LICENSE](./LICENSE).
@@ -0,0 +1,30 @@
1
+ import { z } from 'zod';
2
+ import { createDoctype } from '@agentproto/define-doctype';
3
+
4
+ /**
5
+ * @agentproto/lesson v0.1.0-alpha
6
+ * AIP-11 LESSON.md `defineLesson` reference implementation.
7
+ */
8
+
9
+ var lessonFrontmatterSchema = z.object({ "schema": z.literal("learning/v1").describe("Spec identifier. Must be the literal string 'learning/v1'."), "slug": z.string().regex(new RegExp("^[a-z][a-z0-9-]*[a-z0-9]$")).min(2).max(80).describe("Machine identifier, also the filename. Lowercase, digits, dashes. Imperative voice recommended."), "title": z.string().min(1).max(200).describe("One-sentence imperative title \u2014 what to do or avoid."), "trigger": z.object({ "description": z.string().min(1).max(1e3).describe("Plain-text description of when this lesson applies."), "tags": z.array(z.string().regex(new RegExp("^[a-z][a-z0-9-]*$"))).max(12).describe("Retrieval keywords. Keep narrow; three is usually enough.").default([]), "targets": z.array(z.object({ "operator": z.string().optional(), "role": z.string().optional(), "skill": z.string().optional() }).strict()).describe("Operator / role / skill globs that scope retrieval. Empty means anyone.").default([]), "metadata": z.record(z.string(), z.any()).describe("Vendor-specific trigger predicates. Standard fields above MUST NOT be redefined here.").default({}) }).strict(), "outcome": z.enum(["success", "failure", "mixed"]).describe("Whether the source run succeeded, failed, or the lesson is conditional across runs."), "evidence": z.array(z.object({ "kind": z.enum(["run", "conversation", "work-item", "audit", "wiki-page"]).describe("What the evidence reference points to. 'audit' = AIP-7 governance record."), "ref": z.string().min(1).max(256).describe("Opaque id or path the host can resolve. Never free text."), "note": z.string().max(500).describe("One-line factual note about the event \u2014 not the lesson.").optional() }).strict()).min(1).describe("Provenance \u2014 at least one evidence entry MUST resolve to a real run, conversation, work item, audit, or wiki page in the host's indices."), "confidence": z.number().gte(0).lte(1).describe("Author's confidence in [0,1]. Default 0.5 at first sighting. Runtimes weigh this against observed counts.").default(0.5), "success_count": z.number().int().gte(0).describe("Times the lesson 'worked' when applied. Maintained by the runtime; author-supplied values are initial only.").default(0), "failure_count": z.number().int().gte(0).describe("Times the lesson's claim was contradicted. Maintained by the runtime; author-supplied values are initial only.").default(0), "supersedes": z.array(z.string().regex(new RegExp("^[a-z][a-z0-9-]*[a-z0-9]$"))).describe("Slugs of lessons this lesson replaces. Supersession is explicit, never silent. Each cited slug MUST exist on disk.").default([]), "expires_at": z.string().datetime({ offset: true }).describe("Soft TTL (ISO 8601). Past this instant, retrieval treats the lesson as absent by default.").optional(), "metadata": z.record(z.string(), z.any()).describe("Vendor-specific extensions under namespaced keys (metadata.<vendor>.<field>). Standard fields MUST NOT be redefined.").default({}) }).strict().and(z.any()).describe("Validates the YAML frontmatter portion of an AIP-11 LESSON.md file \u2014 one transferable lesson distilled from a completed run.");
10
+ var defineLesson = createDoctype({
11
+ aip: 11,
12
+ name: "lesson",
13
+ readIdentity: (def) => def.slug,
14
+ readDescription: (def) => def.title,
15
+ validate(def) {
16
+ const result = lessonFrontmatterSchema.safeParse(def);
17
+ if (!result.success) {
18
+ throw new Error(
19
+ `defineLesson (AIP-11): ${result.error.issues.map((i) => `${i.path.join(".")}: ${i.message}`).join("; ")}`
20
+ );
21
+ }
22
+ },
23
+ build(def) {
24
+ return { ...def };
25
+ }
26
+ });
27
+
28
+ export { defineLesson, lessonFrontmatterSchema };
29
+ //# sourceMappingURL=chunk-JGP7TCUI.mjs.map
30
+ //# sourceMappingURL=chunk-JGP7TCUI.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/schema.ts","../src/define-lesson.ts"],"names":[],"mappings":";;;;;;;;AAeO,IAAM,0BAA0B,CAAA,CAAE,MAAA,CAAO,EAAE,QAAA,EAAU,EAAE,OAAA,CAAQ,aAAa,CAAA,CAAE,QAAA,CAAS,4DAA4D,CAAA,EAAG,MAAA,EAAQ,CAAA,CAAE,MAAA,GAAS,KAAA,CAAM,IAAI,MAAA,CAAO,2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AA,CAAO,CAAA,CAAE,MAAA,IAAU,CAAA,CAAE,GAAA,EAAK,CAAA,CAAE,SAAS,sHAAsH,CAAA,CAAE,OAAA,CAAQ,EAAE,CAAA,EAAG,CAAA,CAAE,MAAA,GAAS,GAAA,CAAI,CAAA,CAAE,KAAK,CAAA,CAAE,SAAS,mIAA8H;ACM1hG,IAAM,eAAe,aAAA,CAA8C;AAAA,EACxE,GAAA,EAAK,EAAA;AAAA,EACL,IAAA,EAAM,QAAA;AAAA,EACN,YAAA,EAAc,CAAC,GAAA,KAAQ,GAAA,CAAI,IAAA;AAAA,EAC3B,eAAA,EAAiB,CAAC,GAAA,KAAQ,GAAA,CAAI,KAAA;AAAA,EAC9B,SAAS,GAAA,EAAK;AACZ,IAAA,MAAM,MAAA,GAAS,uBAAA,CAAwB,SAAA,CAAU,GAAG,CAAA;AACpD,IAAA,IAAI,CAAC,OAAO,OAAA,EAAS;AACnB,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,CAAA,uBAAA,EAA0B,OAAO,KAAA,CAAM,MAAA,CACpC,IAAI,CAAC,CAAA,KAAM,GAAG,CAAA,CAAE,IAAA,CAAK,KAAK,GAAG,CAAC,KAAK,CAAA,CAAE,OAAO,EAAE,CAAA,CAC9C,IAAA,CAAK,IAAI,CAAC,CAAA;AAAA,OACf;AAAA,IACF;AAAA,EAIF,CAAA;AAAA,EACA,MAAM,GAAA,EAAK;AAKT,IAAA,OAAO,EAAE,GAAG,GAAA,EAAI;AAAA,EAClB;AACF,CAAC","file":"chunk-JGP7TCUI.mjs","sourcesContent":["/**\n * AIP-11 LESSON.md frontmatter zod schema.\n *\n * Generated from `resources/aip-11/draft/LESSON.schema.json` via\n * json-schema-to-zod. Imported by both `define-lesson.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-lesson.ts`'s `validate(def)` instead.\n */\n\nimport { z } from \"zod\"\n\nexport const lessonFrontmatterSchema = z.object({ \"schema\": z.literal(\"learning/v1\").describe(\"Spec identifier. Must be the literal string 'learning/v1'.\"), \"slug\": z.string().regex(new RegExp(\"^[a-z][a-z0-9-]*[a-z0-9]$\")).min(2).max(80).describe(\"Machine identifier, also the filename. Lowercase, digits, dashes. Imperative voice recommended.\"), \"title\": z.string().min(1).max(200).describe(\"One-sentence imperative title — what to do or avoid.\"), \"trigger\": z.object({ \"description\": z.string().min(1).max(1000).describe(\"Plain-text description of when this lesson applies.\"), \"tags\": z.array(z.string().regex(new RegExp(\"^[a-z][a-z0-9-]*$\"))).max(12).describe(\"Retrieval keywords. Keep narrow; three is usually enough.\").default([]), \"targets\": z.array(z.object({ \"operator\": z.string().optional(), \"role\": z.string().optional(), \"skill\": z.string().optional() }).strict()).describe(\"Operator / role / skill globs that scope retrieval. Empty means anyone.\").default([]), \"metadata\": z.record(z.string(), z.any()).describe(\"Vendor-specific trigger predicates. Standard fields above MUST NOT be redefined here.\").default({}) }).strict(), \"outcome\": z.enum([\"success\",\"failure\",\"mixed\"]).describe(\"Whether the source run succeeded, failed, or the lesson is conditional across runs.\"), \"evidence\": z.array(z.object({ \"kind\": z.enum([\"run\",\"conversation\",\"work-item\",\"audit\",\"wiki-page\"]).describe(\"What the evidence reference points to. 'audit' = AIP-7 governance record.\"), \"ref\": z.string().min(1).max(256).describe(\"Opaque id or path the host can resolve. Never free text.\"), \"note\": z.string().max(500).describe(\"One-line factual note about the event — not the lesson.\").optional() }).strict()).min(1).describe(\"Provenance — at least one evidence entry MUST resolve to a real run, conversation, work item, audit, or wiki page in the host's indices.\"), \"confidence\": z.number().gte(0).lte(1).describe(\"Author's confidence in [0,1]. Default 0.5 at first sighting. Runtimes weigh this against observed counts.\").default(0.5), \"success_count\": z.number().int().gte(0).describe(\"Times the lesson 'worked' when applied. Maintained by the runtime; author-supplied values are initial only.\").default(0), \"failure_count\": z.number().int().gte(0).describe(\"Times the lesson's claim was contradicted. Maintained by the runtime; author-supplied values are initial only.\").default(0), \"supersedes\": z.array(z.string().regex(new RegExp(\"^[a-z][a-z0-9-]*[a-z0-9]$\"))).describe(\"Slugs of lessons this lesson replaces. Supersession is explicit, never silent. Each cited slug MUST exist on disk.\").default([]), \"expires_at\": z.string().datetime({ offset: true }).describe(\"Soft TTL (ISO 8601). Past this instant, retrieval treats the lesson as absent by default.\").optional(), \"metadata\": z.record(z.string(), z.any()).describe(\"Vendor-specific extensions under namespaced keys (metadata.<vendor>.<field>). Standard fields MUST NOT be redefined.\").default({}) }).strict().and(z.any()).describe(\"Validates the YAML frontmatter portion of an AIP-11 LESSON.md file — one transferable lesson distilled from a completed run.\")\n\nexport type LessonFrontmatter = z.infer<typeof lessonFrontmatterSchema>\n","import { createDoctype } from \"@agentproto/define-doctype\"\nimport { lessonFrontmatterSchema } from \"./schema.js\"\nimport type { LessonDefinition, LessonHandle } from \"./types.js\"\n\n/**\n * AIP-11 reference implementation of `defineLesson`.\n *\n * Built on `createDoctype` so the cross-AIP invariants (id pattern,\n * description length, top-level freeze, \"defineLesson (AIP-11): …\"\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 (`parseLessonManifest`), 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 *\n * Identity / description extractors detected from the JSON Schema:\n * readIdentity: def.slug\n * readDescription: def.title.\n */\nexport const defineLesson = createDoctype<LessonDefinition, LessonHandle>({\n aip: 11,\n name: \"lesson\",\n readIdentity: (def) => def.slug,\n readDescription: (def) => def.title,\n validate(def) {\n const result = lessonFrontmatterSchema.safeParse(def)\n if (!result.success) {\n throw new Error(\n `defineLesson (AIP-11): ${result.error.issues\n .map((i) => `${i.path.join(\".\")}: ${i.message}`)\n .join(\"; \")}`,\n )\n }\n // TODO: spec-11-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 LessonHandle\n },\n})\n"]}
@@ -0,0 +1,37 @@
1
+ import { L as LessonDefinition } from './types-BTr7haEk.js';
2
+ export { a as LessonHandle } from './types-BTr7haEk.js';
3
+
4
+ /**
5
+ * AIP-11 reference implementation of `defineLesson`.
6
+ *
7
+ * Built on `createDoctype` so the cross-AIP invariants (id pattern,
8
+ * description length, top-level freeze, "defineLesson (AIP-11): …"
9
+ * error prefix) run uniformly with every other AIP defineX.
10
+ *
11
+ * Field-level validation runs the schema-derived zod from
12
+ * `./schema.ts` against the input. Same source of truth as the .md
13
+ * path uses (`parseLessonManifest`), so a malformed TS-authored
14
+ * definition fails with the same diagnostic as a malformed manifest.
15
+ * Cross-field rules go in `validate(def)` after the zod check.
16
+ *
17
+ * Identity / description extractors detected from the JSON Schema:
18
+ * readIdentity: def.slug
19
+ * readDescription: def.title.
20
+ */
21
+ declare const defineLesson: (def: LessonDefinition) => Readonly<LessonDefinition>;
22
+
23
+ /**
24
+ * @agentproto/lesson — AIP-11 LESSON.md `defineLesson` reference impl.
25
+ *
26
+ * A markdown format for storing the transferable lessons an agent extracts from successful and failed runs — title, trigger, evidence, outcome — and a contract for how runtimes distill them and inject them back into future turns.
27
+ *
28
+ * Spec: https://agentproto.sh/docs/aip-11
29
+ *
30
+ * Authoring paths:
31
+ * - TS: `defineLesson({...})` → `LessonHandle`
32
+ * - MD: `parseLessonManifest(src) → lessonFromManifest({...})` → `LessonHandle`
33
+ */
34
+ declare const SPEC_NAME: "agentlesson/v1";
35
+ declare const SPEC_VERSION: "1.0.0-alpha";
36
+
37
+ export { LessonDefinition, SPEC_NAME, SPEC_VERSION, defineLesson };
package/dist/index.mjs ADDED
@@ -0,0 +1,14 @@
1
+ export { defineLesson } from './chunk-JGP7TCUI.mjs';
2
+
3
+ /**
4
+ * @agentproto/lesson v0.1.0-alpha
5
+ * AIP-11 LESSON.md `defineLesson` reference implementation.
6
+ */
7
+
8
+ // src/index.ts
9
+ var SPEC_NAME = "agentlesson/v1";
10
+ var SPEC_VERSION = "1.0.0-alpha";
11
+
12
+ export { SPEC_NAME, SPEC_VERSION };
13
+ //# sourceMappingURL=index.mjs.map
14
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;AAYO,IAAM,SAAA,GAAY;AAClB,IAAM,YAAA,GAAe","file":"index.mjs","sourcesContent":["/**\n * @agentproto/lesson — AIP-11 LESSON.md `defineLesson` reference impl.\n *\n * A markdown format for storing the transferable lessons an agent extracts from successful and failed runs — title, trigger, evidence, outcome — and a contract for how runtimes distill them and inject them back into future turns.\n *\n * Spec: https://agentproto.sh/docs/aip-11\n *\n * Authoring paths:\n * - TS: `defineLesson({...})` → `LessonHandle`\n * - MD: `parseLessonManifest(src) → lessonFromManifest({...})` → `LessonHandle`\n */\n\nexport const SPEC_NAME = \"agentlesson/v1\" as const\nexport const SPEC_VERSION = \"1.0.0-alpha\" as const\n\nexport { defineLesson } from \"./define-lesson.js\"\nexport type { LessonDefinition, LessonHandle } from \"./types.js\"\n"]}
@@ -0,0 +1,79 @@
1
+ import { z } from 'zod';
2
+ import { a as LessonHandle } from '../types-BTr7haEk.js';
3
+
4
+ /**
5
+ * AIP-11 LESSON.md frontmatter zod schema.
6
+ *
7
+ * Generated from `resources/aip-11/draft/LESSON.schema.json` via
8
+ * json-schema-to-zod. Imported by both `define-lesson.ts` (TS path
9
+ * validation) and `manifest/index.ts` (.md path validation) so every
10
+ * field-level constraint runs in both authoring paths from a single
11
+ * source of truth — re-run scaffold-aip to refresh after spec changes.
12
+ *
13
+ * Cross-field rules (if/then/allOf in JSON Schema) don't translate
14
+ * cleanly and live in `define-lesson.ts`'s `validate(def)` instead.
15
+ */
16
+
17
+ declare const lessonFrontmatterSchema: z.ZodIntersection<z.ZodObject<{
18
+ schema: z.ZodLiteral<"learning/v1">;
19
+ slug: z.ZodString;
20
+ title: z.ZodString;
21
+ trigger: z.ZodObject<{
22
+ description: z.ZodString;
23
+ tags: z.ZodDefault<z.ZodArray<z.ZodString>>;
24
+ targets: z.ZodDefault<z.ZodArray<z.ZodObject<{
25
+ operator: z.ZodOptional<z.ZodString>;
26
+ role: z.ZodOptional<z.ZodString>;
27
+ skill: z.ZodOptional<z.ZodString>;
28
+ }, z.core.$strict>>>;
29
+ metadata: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodAny>>;
30
+ }, z.core.$strict>;
31
+ outcome: z.ZodEnum<{
32
+ success: "success";
33
+ failure: "failure";
34
+ mixed: "mixed";
35
+ }>;
36
+ evidence: z.ZodArray<z.ZodObject<{
37
+ kind: z.ZodEnum<{
38
+ run: "run";
39
+ conversation: "conversation";
40
+ "work-item": "work-item";
41
+ audit: "audit";
42
+ "wiki-page": "wiki-page";
43
+ }>;
44
+ ref: z.ZodString;
45
+ note: z.ZodOptional<z.ZodString>;
46
+ }, z.core.$strict>>;
47
+ confidence: z.ZodDefault<z.ZodNumber>;
48
+ success_count: z.ZodDefault<z.ZodNumber>;
49
+ failure_count: z.ZodDefault<z.ZodNumber>;
50
+ supersedes: z.ZodDefault<z.ZodArray<z.ZodString>>;
51
+ expires_at: z.ZodOptional<z.ZodString>;
52
+ metadata: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodAny>>;
53
+ }, z.core.$strict>, z.ZodAny>;
54
+ type LessonFrontmatter = z.infer<typeof lessonFrontmatterSchema>;
55
+
56
+ /**
57
+ * AIP-11 LESSON.md sidecar parser + manifest-to-handle constructor.
58
+ *
59
+ * Mirror of `@agentproto/tool/manifest` and `@agentproto/driver/manifest`:
60
+ * the .md provides metadata; the TS module supplies any spec-specific
61
+ * runtime bits (schemas, execute bodies, …) that can't live in
62
+ * frontmatter. Both inputs end up in `defineLesson` so the cross-AIP
63
+ * invariants run uniformly.
64
+ *
65
+ *
66
+ * The frontmatter zod schema below was generated from
67
+ * `resources/aip-11/draft/LESSON.schema.json` via json-schema-to-zod.
68
+ * Re-run scaffold-aip to refresh after spec changes (or hand-tune
69
+ * any constraint the converter doesn't capture cleanly).
70
+ */
71
+
72
+ interface LessonManifest {
73
+ frontmatter: LessonFrontmatter;
74
+ body: string;
75
+ }
76
+ declare function parseLessonManifest(source: string): LessonManifest;
77
+ declare function lessonFromManifest(manifest: LessonManifest): LessonHandle;
78
+
79
+ export { type LessonFrontmatter, type LessonManifest, lessonFromManifest, lessonFrontmatterSchema, parseLessonManifest };
@@ -0,0 +1,28 @@
1
+ import { lessonFrontmatterSchema, defineLesson } from '../chunk-JGP7TCUI.mjs';
2
+ export { lessonFrontmatterSchema } from '../chunk-JGP7TCUI.mjs';
3
+ import matter from 'gray-matter';
4
+
5
+ /**
6
+ * @agentproto/lesson v0.1.0-alpha
7
+ * AIP-11 LESSON.md `defineLesson` reference implementation.
8
+ */
9
+ function parseLessonManifest(source) {
10
+ const parsed = matter(source);
11
+ if (Object.keys(parsed.data).length === 0) {
12
+ throw new Error("parseLessonManifest: missing or empty frontmatter");
13
+ }
14
+ const result = lessonFrontmatterSchema.safeParse(parsed.data);
15
+ if (!result.success) {
16
+ throw new Error(
17
+ `parseLessonManifest: invalid frontmatter \u2014 ${result.error.issues.map((i) => `${i.path.join(".")}: ${i.message}`).join("; ")}`
18
+ );
19
+ }
20
+ return { frontmatter: result.data, body: parsed.content };
21
+ }
22
+ function lessonFromManifest(manifest) {
23
+ return defineLesson(manifest.frontmatter);
24
+ }
25
+
26
+ export { lessonFromManifest, parseLessonManifest };
27
+ //# sourceMappingURL=index.mjs.map
28
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/manifest/index.ts"],"names":[],"mappings":";;;;;;;;AA8BO,SAAS,oBAAoB,MAAA,EAAgC;AAClE,EAAA,MAAM,MAAA,GAAS,OAAO,MAAM,CAAA;AAC5B,EAAA,IAAI,OAAO,IAAA,CAAK,MAAA,CAAO,IAAI,CAAA,CAAE,WAAW,CAAA,EAAG;AACzC,IAAA,MAAM,IAAI,MAAM,mDAAmD,CAAA;AAAA,EACrE;AACA,EAAA,MAAM,MAAA,GAAS,uBAAA,CAAwB,SAAA,CAAU,MAAA,CAAO,IAAI,CAAA;AAC5D,EAAA,IAAI,CAAC,OAAO,OAAA,EAAS;AACnB,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,CAAA,gDAAA,EAA8C,OAAO,KAAA,CAAM,MAAA,CACxD,IAAI,CAAC,CAAA,KAAM,GAAG,CAAA,CAAE,IAAA,CAAK,KAAK,GAAG,CAAC,KAAK,CAAA,CAAE,OAAO,EAAE,CAAA,CAC9C,IAAA,CAAK,IAAI,CAAC,CAAA;AAAA,KACf;AAAA,EACF;AACA,EAAA,OAAO,EAAE,WAAA,EAAa,MAAA,CAAO,IAAA,EAAM,IAAA,EAAM,OAAO,OAAA,EAAQ;AAC1D;AAEO,SAAS,mBAAmB,QAAA,EAAwC;AAKzE,EAAA,OAAO,YAAA,CAAa,SAAS,WAA0C,CAAA;AACzE","file":"index.mjs","sourcesContent":["/**\n * AIP-11 LESSON.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 `defineLesson` so the cross-AIP\n * invariants run uniformly.\n *\n *\n * The frontmatter zod schema below was generated from\n * `resources/aip-11/draft/LESSON.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 { lessonFrontmatterSchema, type LessonFrontmatter } from \"../schema.js\"\nimport { defineLesson } from \"../define-lesson.js\"\nimport type { LessonDefinition, LessonHandle } from \"../types.js\"\n\n// Re-export so consumers can import the schema + inferred type either\n// from \"@@agentproto/lesson/manifest\" or directly from \"@@agentproto/lesson/schema\".\nexport { lessonFrontmatterSchema, type LessonFrontmatter }\n\nexport interface LessonManifest {\n frontmatter: LessonFrontmatter\n body: string\n}\n\nexport function parseLessonManifest(source: string): LessonManifest {\n const parsed = matter(source)\n if (Object.keys(parsed.data).length === 0) {\n throw new Error(\"parseLessonManifest: missing or empty frontmatter\")\n }\n const result = lessonFrontmatterSchema.safeParse(parsed.data)\n if (!result.success) {\n throw new Error(\n `parseLessonManifest: 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 lessonFromManifest(manifest: LessonManifest): LessonHandle {\n // The zod-validated frontmatter is structurally compatible with\n // LessonDefinition; 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 defineLesson(manifest.frontmatter as unknown as LessonDefinition)\n}\n"]}
@@ -0,0 +1,121 @@
1
+ /**
2
+ * AIP-11 LessonDefinition + LessonHandle.
3
+ *
4
+ * `LessonDefinition` was generated from
5
+ * `resources/aip-11/draft/LESSON.schema.json` via json-schema-to-typescript.
6
+ * `LessonHandle` is the readonly view of the same shape; tighten it
7
+ * by hand for fields that get defaults applied in build().
8
+ */
9
+ /**
10
+ * Validates the YAML frontmatter portion of an AIP-11 LESSON.md file — one transferable lesson distilled from a completed run.
11
+ */
12
+ type LessonDefinition = {
13
+ [k: string]: unknown;
14
+ } & {
15
+ /**
16
+ * Spec identifier. Must be the literal string 'learning/v1'.
17
+ */
18
+ schema: "learning/v1";
19
+ /**
20
+ * Machine identifier, also the filename. Lowercase, digits, dashes. Imperative voice recommended.
21
+ */
22
+ slug: string;
23
+ /**
24
+ * One-sentence imperative title — what to do or avoid.
25
+ */
26
+ title: string;
27
+ trigger: {
28
+ /**
29
+ * Plain-text description of when this lesson applies.
30
+ */
31
+ description: string;
32
+ /**
33
+ * Retrieval keywords. Keep narrow; three is usually enough.
34
+ *
35
+ * @maxItems 12
36
+ */
37
+ tags?: [] | [string] | [string, string] | [string, string, string] | [string, string, string, string] | [string, string, string, string, string] | [string, string, string, string, string, string] | [string, string, string, string, string, string, string] | [string, string, string, string, string, string, string, string] | [string, string, string, string, string, string, string, string, string] | [string, string, string, string, string, string, string, string, string, string] | [string, string, string, string, string, string, string, string, string, string, string] | [string, string, string, string, string, string, string, string, string, string, string, string];
38
+ /**
39
+ * Operator / role / skill globs that scope retrieval. Empty means anyone.
40
+ */
41
+ targets?: {
42
+ operator?: string;
43
+ role?: string;
44
+ skill?: string;
45
+ }[];
46
+ /**
47
+ * Vendor-specific trigger predicates. Standard fields above MUST NOT be redefined here.
48
+ */
49
+ metadata?: {
50
+ [k: string]: unknown;
51
+ };
52
+ };
53
+ /**
54
+ * Whether the source run succeeded, failed, or the lesson is conditional across runs.
55
+ */
56
+ outcome: "success" | "failure" | "mixed";
57
+ /**
58
+ * Provenance — at least one evidence entry MUST resolve to a real run, conversation, work item, audit, or wiki page in the host's indices.
59
+ *
60
+ * @minItems 1
61
+ */
62
+ evidence: [
63
+ {
64
+ /**
65
+ * What the evidence reference points to. 'audit' = AIP-7 governance record.
66
+ */
67
+ kind: "run" | "conversation" | "work-item" | "audit" | "wiki-page";
68
+ /**
69
+ * Opaque id or path the host can resolve. Never free text.
70
+ */
71
+ ref: string;
72
+ /**
73
+ * One-line factual note about the event — not the lesson.
74
+ */
75
+ note?: string;
76
+ },
77
+ ...{
78
+ /**
79
+ * What the evidence reference points to. 'audit' = AIP-7 governance record.
80
+ */
81
+ kind: "run" | "conversation" | "work-item" | "audit" | "wiki-page";
82
+ /**
83
+ * Opaque id or path the host can resolve. Never free text.
84
+ */
85
+ ref: string;
86
+ /**
87
+ * One-line factual note about the event — not the lesson.
88
+ */
89
+ note?: string;
90
+ }[]
91
+ ];
92
+ /**
93
+ * Author's confidence in [0,1]. Default 0.5 at first sighting. Runtimes weigh this against observed counts.
94
+ */
95
+ confidence?: number;
96
+ /**
97
+ * Times the lesson 'worked' when applied. Maintained by the runtime; author-supplied values are initial only.
98
+ */
99
+ success_count?: number;
100
+ /**
101
+ * Times the lesson's claim was contradicted. Maintained by the runtime; author-supplied values are initial only.
102
+ */
103
+ failure_count?: number;
104
+ /**
105
+ * Slugs of lessons this lesson replaces. Supersession is explicit, never silent. Each cited slug MUST exist on disk.
106
+ */
107
+ supersedes?: string[];
108
+ /**
109
+ * Soft TTL (ISO 8601). Past this instant, retrieval treats the lesson as absent by default.
110
+ */
111
+ expires_at?: string;
112
+ /**
113
+ * Vendor-specific extensions under namespaced keys (metadata.<vendor>.<field>). Standard fields MUST NOT be redefined.
114
+ */
115
+ metadata?: {
116
+ [k: string]: unknown;
117
+ };
118
+ };
119
+ type LessonHandle = Readonly<LessonDefinition>;
120
+
121
+ export type { LessonDefinition as L, LessonHandle as a };
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@agentproto/lesson",
3
+ "version": "0.1.0-alpha.0",
4
+ "description": "@agentproto/lesson — AIP-11 LESSON.md reference implementation. A markdown format for storing the transferable lessons an agent extracts from successful and failed runs — title, trigger, evidence, outcome — and a contract for how runtimes distill them and inject them back into future turns.",
5
+ "keywords": [
6
+ "agentproto",
7
+ "aip-11",
8
+ "lesson",
9
+ "defineLesson",
10
+ "open-standard",
11
+ "agentic"
12
+ ],
13
+ "homepage": "https://agentproto.sh/docs/aip-11",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/agentproto/ts",
17
+ "directory": "packages/lesson"
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/define-doctype": "0.1.0"
52
+ },
53
+ "devDependencies": {
54
+ "@types/node": "^25.6.2",
55
+ "tsup": "^8.5.1",
56
+ "typescript": "^5.9.3",
57
+ "vitest": "^3.2.4",
58
+ "@agentproto/tooling": "0.1.0-alpha.0"
59
+ },
60
+ "scripts": {
61
+ "dev": "tsup --watch",
62
+ "build": "tsup",
63
+ "clean": "rm -rf dist",
64
+ "check-types": "tsc --noEmit",
65
+ "test": "vitest run --passWithNoTests",
66
+ "test:watch": "vitest"
67
+ }
68
+ }