agentfootprint 9.47.0 → 9.48.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 (103) hide show
  1. package/CLAUDE.md +11 -3
  2. package/dist/core/Agent.js +14 -1
  3. package/dist/core/Agent.js.map +1 -1
  4. package/dist/core/agent/AgentBuilder.js +147 -3
  5. package/dist/core/agent/AgentBuilder.js.map +1 -1
  6. package/dist/core/agent/runManifest.js +7 -0
  7. package/dist/core/agent/runManifest.js.map +1 -1
  8. package/dist/doors/recipes.js +55 -0
  9. package/dist/doors/recipes.js.map +1 -0
  10. package/dist/esm/core/Agent.d.ts +9 -1
  11. package/dist/esm/core/Agent.js +14 -1
  12. package/dist/esm/core/Agent.js.map +1 -1
  13. package/dist/esm/core/agent/AgentBuilder.d.ts +68 -0
  14. package/dist/esm/core/agent/AgentBuilder.js +147 -3
  15. package/dist/esm/core/agent/AgentBuilder.js.map +1 -1
  16. package/dist/esm/core/agent/runManifest.d.ts +18 -0
  17. package/dist/esm/core/agent/runManifest.js +7 -0
  18. package/dist/esm/core/agent/runManifest.js.map +1 -1
  19. package/dist/esm/doors/recipes.d.ts +38 -0
  20. package/dist/esm/doors/recipes.js +39 -0
  21. package/dist/esm/doors/recipes.js.map +1 -0
  22. package/dist/esm/events/payloads.d.ts +29 -0
  23. package/dist/esm/observe.d.ts +2 -0
  24. package/dist/esm/observe.js +12 -0
  25. package/dist/esm/observe.js.map +1 -1
  26. package/dist/esm/recipes/apply.d.ts +67 -0
  27. package/dist/esm/recipes/apply.js +117 -0
  28. package/dist/esm/recipes/apply.js.map +1 -0
  29. package/dist/esm/recipes/defineAgentRecipe.d.ts +68 -0
  30. package/dist/esm/recipes/defineAgentRecipe.js +112 -0
  31. package/dist/esm/recipes/defineAgentRecipe.js.map +1 -0
  32. package/dist/esm/recipes/identifier.d.ts +40 -0
  33. package/dist/esm/recipes/identifier.js +95 -0
  34. package/dist/esm/recipes/identifier.js.map +1 -0
  35. package/dist/esm/recipes/index.d.ts +19 -0
  36. package/dist/esm/recipes/index.js +19 -0
  37. package/dist/esm/recipes/index.js.map +1 -0
  38. package/dist/esm/recipes/provenance.d.ts +57 -0
  39. package/dist/esm/recipes/provenance.js +53 -0
  40. package/dist/esm/recipes/provenance.js.map +1 -0
  41. package/dist/esm/recipes/types.d.ts +134 -0
  42. package/dist/esm/recipes/types.js +63 -0
  43. package/dist/esm/recipes/types.js.map +1 -0
  44. package/dist/esm/recipes/version.d.ts +38 -0
  45. package/dist/esm/recipes/version.js +84 -0
  46. package/dist/esm/recipes/version.js.map +1 -0
  47. package/dist/esm/recorders/observability/fileRecordingSink.d.ts +104 -0
  48. package/dist/esm/recorders/observability/fileRecordingSink.js +195 -0
  49. package/dist/esm/recorders/observability/fileRecordingSink.js.map +1 -0
  50. package/dist/esm/recorders/observability/recordingEnvelope.d.ts +292 -0
  51. package/dist/esm/recorders/observability/recordingEnvelope.js +375 -0
  52. package/dist/esm/recorders/observability/recordingEnvelope.js.map +1 -0
  53. package/dist/observe.js +23 -1
  54. package/dist/observe.js.map +1 -1
  55. package/dist/recipes/apply.js +125 -0
  56. package/dist/recipes/apply.js.map +1 -0
  57. package/dist/recipes/defineAgentRecipe.js +118 -0
  58. package/dist/recipes/defineAgentRecipe.js.map +1 -0
  59. package/dist/recipes/identifier.js +100 -0
  60. package/dist/recipes/identifier.js.map +1 -0
  61. package/dist/recipes/index.js +24 -0
  62. package/dist/recipes/index.js.map +1 -0
  63. package/dist/recipes/provenance.js +57 -0
  64. package/dist/recipes/provenance.js.map +1 -0
  65. package/dist/recipes/types.js +64 -0
  66. package/dist/recipes/types.js.map +1 -0
  67. package/dist/recipes/version.js +89 -0
  68. package/dist/recipes/version.js.map +1 -0
  69. package/dist/recorders/observability/fileRecordingSink.js +201 -0
  70. package/dist/recorders/observability/fileRecordingSink.js.map +1 -0
  71. package/dist/recorders/observability/recordingEnvelope.js +382 -0
  72. package/dist/recorders/observability/recordingEnvelope.js.map +1 -0
  73. package/dist/types/core/Agent.d.ts +9 -1
  74. package/dist/types/core/Agent.d.ts.map +1 -1
  75. package/dist/types/core/agent/AgentBuilder.d.ts +68 -0
  76. package/dist/types/core/agent/AgentBuilder.d.ts.map +1 -1
  77. package/dist/types/core/agent/runManifest.d.ts +18 -0
  78. package/dist/types/core/agent/runManifest.d.ts.map +1 -1
  79. package/dist/types/doors/recipes.d.ts +39 -0
  80. package/dist/types/doors/recipes.d.ts.map +1 -0
  81. package/dist/types/events/payloads.d.ts +29 -0
  82. package/dist/types/events/payloads.d.ts.map +1 -1
  83. package/dist/types/observe.d.ts +2 -0
  84. package/dist/types/observe.d.ts.map +1 -1
  85. package/dist/types/recipes/apply.d.ts +68 -0
  86. package/dist/types/recipes/apply.d.ts.map +1 -0
  87. package/dist/types/recipes/defineAgentRecipe.d.ts +69 -0
  88. package/dist/types/recipes/defineAgentRecipe.d.ts.map +1 -0
  89. package/dist/types/recipes/identifier.d.ts +41 -0
  90. package/dist/types/recipes/identifier.d.ts.map +1 -0
  91. package/dist/types/recipes/index.d.ts +20 -0
  92. package/dist/types/recipes/index.d.ts.map +1 -0
  93. package/dist/types/recipes/provenance.d.ts +58 -0
  94. package/dist/types/recipes/provenance.d.ts.map +1 -0
  95. package/dist/types/recipes/types.d.ts +135 -0
  96. package/dist/types/recipes/types.d.ts.map +1 -0
  97. package/dist/types/recipes/version.d.ts +39 -0
  98. package/dist/types/recipes/version.d.ts.map +1 -0
  99. package/dist/types/recorders/observability/fileRecordingSink.d.ts +105 -0
  100. package/dist/types/recorders/observability/fileRecordingSink.d.ts.map +1 -0
  101. package/dist/types/recorders/observability/recordingEnvelope.d.ts +293 -0
  102. package/dist/types/recorders/observability/recordingEnvelope.d.ts.map +1 -0
  103. package/package.json +14 -1
@@ -0,0 +1,135 @@
1
+ /**
2
+ * recipes/types — the declared unit of agent configuration.
3
+ *
4
+ * Pattern: a data DECLARATION over an existing fluent builder. No class, no
5
+ * registry, no lifecycle. The repo's own instruction is that named
6
+ * patterns are recipes over primitives rather than new machinery, and
7
+ * this file is that instruction taken literally.
8
+ * Role: recipes/ layer, pure. Nothing here imports the engine, a provider,
9
+ * or a store — the only agentfootprint type it names is
10
+ * {@link AgentBuilder}, and it names it as a TYPE.
11
+ * Emits: N/A. `AgentBuilder.recipe()` records the row; `runManifest` reports
12
+ * it.
13
+ *
14
+ * ## The gap this closes
15
+ *
16
+ * Every capability an agent needs already ships. What did not ship was a
17
+ * declared, versioned, inspectable unit of CONFIGURATION. So an agent's setup
18
+ * lived as prose in an example, was copy-pasted into an app, drifted there, and
19
+ * afterwards nothing on the run could say which composition produced the agent
20
+ * that answered. Two runs of "the support agent" could differ in every tool and
21
+ * every instruction and be indistinguishable on the record.
22
+ *
23
+ * A recipe is the missing noun: a name, a version, and a function that calls
24
+ * the builder methods that already exist.
25
+ *
26
+ * ```ts
27
+ * export const supportDesk = defineAgentRecipe({
28
+ * id: 'support-desk',
29
+ * version: '1.2.0',
30
+ * description: 'Order lookup + refund policy, the way support runs it.',
31
+ * configure: (agent) => {
32
+ * agent.system('You answer support questions.').tool(lookupOrder);
33
+ * },
34
+ * });
35
+ *
36
+ * const agent = Agent.create({ provider, model }).recipe(supportDesk).build();
37
+ * ```
38
+ *
39
+ * ## No lifecycle magic — stated here because it is the load-bearing limit
40
+ *
41
+ * A recipe composes CONFIGURATION and nothing else:
42
+ *
43
+ * • nothing is registered anywhere — a recipe is not discovered, not looked
44
+ * up by name, and not resolved from a registry. You import the object and
45
+ * hand it to `.recipe()`. There is no global map to go stale, and no
46
+ * "which version of `support-desk` is installed" question;
47
+ * • nothing is closable — a recipe holds no connection, no handle and no
48
+ * process. It never gets a `close()`, a `dispose()` or a teardown hook,
49
+ * and it is never awaited: `configure` is synchronous because `build()`
50
+ * is (an `async configure` is refused by name rather than silently not
51
+ * awaited);
52
+ * • nothing is deferred — every call `configure` makes happens during
53
+ * `.recipe()`, at the position in the chain where you wrote it. There is
54
+ * no later phase in which a recipe acts, so a run's behaviour is decided
55
+ * entirely by the builder calls you can read.
56
+ *
57
+ * That is deliberately thin. The thing being named is a COMPOSITION, and a
58
+ * composition that also owned a resource would be a component wearing a
59
+ * composition's name — the shape that makes "who closed the pool?" unanswerable
60
+ * two releases later.
61
+ */
62
+ import type { AgentBuilder } from '../core/agent/AgentBuilder.js';
63
+ /**
64
+ * A named, versioned composition over the agent builder.
65
+ *
66
+ * Build one with {@link defineAgentRecipe}, which validates every field and
67
+ * freezes the result. A hand-written object literal is accepted by
68
+ * `.recipe()` too — it runs the SAME validation — so a recipe cannot reach an
69
+ * agent without passing the checks; the factory only moves the refusal to the
70
+ * declaration, where the fix is.
71
+ */
72
+ export interface AgentRecipe {
73
+ /**
74
+ * The composition's plain name — lower-case words joined by single hyphens
75
+ * (`support-desk`, `triage`, `refund-policy`).
76
+ *
77
+ * It carries NO version: `support-desk-2` is refused, because the version
78
+ * axis already exists as its own field and an id that encodes one produces
79
+ * two names for one composition, neither of which can be grouped on.
80
+ */
81
+ readonly id: string;
82
+ /**
83
+ * The composition's version, as SemVer 2.0.0 (`'1.2.0'`, `'2.0.0-rc.1'`).
84
+ *
85
+ * A version is what makes a recipe row on a run manifest worth reading: two
86
+ * runs of `support-desk` that answered differently are a mystery until the
87
+ * record says one was `1.2.0` and the other `1.3.0`.
88
+ */
89
+ readonly version: string;
90
+ /** What this composition is for, in one sentence. Optional, and never
91
+ * reported on the wire — the manifest carries the id and the version only. */
92
+ readonly description?: string;
93
+ /**
94
+ * Apply the composition: call the builder methods this recipe stands for.
95
+ *
96
+ * Runs SYNCHRONOUSLY, exactly once, at the `.recipe()` call site. The return
97
+ * value is ignored — `AgentBuilder` is mutated in place and every method
98
+ * returns the same object — so `(agent) => agent.system('…').tool(t)` and a
99
+ * statement body are the same program.
100
+ */
101
+ configure(builder: AgentBuilder): void;
102
+ }
103
+ /**
104
+ * One applied recipe, as the run manifest reports it: the id and the version,
105
+ * never the description and never the function.
106
+ *
107
+ * The two stay SEPARATE FIELDS on purpose. A composed key (`'support-desk@1.2.0'`)
108
+ * would be one string that two different pairs could produce as soon as either
109
+ * half is allowed to contain the separator — the collision class this repo has
110
+ * fixed seven times. Nothing here ever joins them.
111
+ */
112
+ export interface AppliedRecipe {
113
+ readonly id: string;
114
+ readonly version: string;
115
+ }
116
+ /**
117
+ * What happens when a recipe introduces a tool name or an injection id that is
118
+ * already taken.
119
+ *
120
+ * `'error'` is the only policy that exists, and it is the default. The
121
+ * alternatives a reader will reach for — skip the recipe's version, let it
122
+ * replace what is there, rename one automatically — are real designs, and none
123
+ * of them is implemented: each has to answer where the drop is RECORDED, and a
124
+ * conflict resolved silently is exactly the "accepted and quietly wrong" shape
125
+ * this library refuses. So an unimplemented policy is refused by name (see
126
+ * {@link resolveRecipeConflictPolicy}) rather than approximated by the one that
127
+ * ships.
128
+ */
129
+ export type RecipeConflictPolicy = 'error';
130
+ /** Options for `AgentBuilder.recipe(recipe, options)`. */
131
+ export interface RecipeOptions {
132
+ /** See {@link RecipeConflictPolicy}. Default `'error'`. */
133
+ readonly conflict?: RecipeConflictPolicy;
134
+ }
135
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/recipes/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAElE;;;;;;;;GAQG;AACH,MAAM,WAAW,WAAW;IAC1B;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB;;;;;;OAMG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB;mFAC+E;IAC/E,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B;;;;;;;OAOG;IACH,SAAS,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI,CAAC;CACxC;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,oBAAoB,GAAG,OAAO,CAAC;AAE3C,0DAA0D;AAC1D,MAAM,WAAW,aAAa;IAC5B,2DAA2D;IAC3D,QAAQ,CAAC,QAAQ,CAAC,EAAE,oBAAoB,CAAC;CAC1C"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * version — is this string a version, or something that looks like one?
3
+ *
4
+ * Pattern: a total predicate + a refusal sentence. Pure, no dependencies.
5
+ * Role: recipes/ layer. Used by `defineAgentRecipe` and by the same
6
+ * validation `AgentBuilder.recipe()` runs on a hand-written literal.
7
+ * Emits: N/A.
8
+ *
9
+ * ## Why strict SemVer, and why a near-miss is refused rather than repaired
10
+ *
11
+ * The version is the half of a recipe row that makes the other half worth
12
+ * reading: two runs of `support-desk` that behaved differently are a mystery
13
+ * until the record says `1.2.0` and `1.3.0`. That only works if every producer
14
+ * spells versions the same way, so the ones that would quietly break grouping
15
+ * are refused at the declaration:
16
+ *
17
+ * `'1.2'` two runs, `'1.2'` and `'1.2.0'`, that are the same version and
18
+ * do not group together.
19
+ * `'v1.2.3'` the same, with a decoration that sorts differently.
20
+ * `'1.02.3'` leading zeros: `'1.02.3'` and `'1.2.3'` again split one arm.
21
+ * `'latest'` a RANGE, not a version — it names whatever was installed, so
22
+ * `'^1.2.3'` the row would describe a different composition each week and
23
+ * `'1.x'` say nothing about the run it is stamped on.
24
+ *
25
+ * None is repaired. Padding `'1.2'` to `'1.2.0'` would put a version on the
26
+ * record that the author never wrote, which is the one thing a manifest field
27
+ * may not do.
28
+ */
29
+ /** Whether `value` is a SemVer 2.0.0 version string. Total: any input, no throw. */
30
+ export declare function isSemverVersion(value: unknown): value is string;
31
+ /**
32
+ * The sentence a bad version gets. Names the value, the grammar, and the
33
+ * specific mistake when the shape identifies one — a refusal that only says
34
+ * "invalid" makes the author guess which half was wrong.
35
+ *
36
+ * @param callSite - the API the author called, e.g. `defineAgentRecipe`.
37
+ */
38
+ export declare function versionRefusal(callSite: string, value: unknown): string;
39
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../../src/recipes/version.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAWH,oFAAoF;AACpF,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAE/D;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,CAWvE"}
@@ -0,0 +1,105 @@
1
+ /**
2
+ * fileRecordingSink — one archived run, one JSON file, in a directory.
3
+ *
4
+ * The destination that needs nothing installed: an incident can be inspected
5
+ * with `ls` and `cat`, and a run archive is a folder you can tar. It is also
6
+ * the reference implementation of {@link RecordingSink} — a sink is one method,
7
+ * and this file is what "implement the other ones like this" points at.
8
+ *
9
+ * ## The file name is a key, and keys must be injective
10
+ *
11
+ * `runId` becomes a file name, which makes `runId ↦ name` a mapping used as a
12
+ * key: two different runs landing on one name means one archive silently
13
+ * overwrites another, and the evidence is gone with no error anywhere. So the
14
+ * mapping is `runId + '.json'` — appending a constant suffix, which is
15
+ * injective — over a DOMAIN that is asserted rather than assumed, and anything
16
+ * outside it is refused by name.
17
+ *
18
+ * The domain is `[a-z0-9]` followed by `[a-z0-9._-]*`, and every exclusion is
19
+ * load-bearing:
20
+ *
21
+ * • **no uppercase.** This is the one that looks like fussiness and is not.
22
+ * macOS/APFS and Windows/NTFS are case-INSENSITIVE by default, so `run-A`
23
+ * and `run-a` are two distinct strings that name ONE file. A mapping that
24
+ * is injective as a string can still collide as a file name, which is
25
+ * exactly the bug artifacts/scopePath.ts found on a stock Mac in 9.44.0 —
26
+ * its conformance battery had pairs for separators, absence markers and
27
+ * pre-escaped values, and no pair differing only in case. Excluding
28
+ * uppercase from the domain means no two valid ids differ by case alone, so
29
+ * there is nothing for a case-folding filesystem to fold together.
30
+ * • **no `/` or `\`.** A separator inside a field is separator donation: an
31
+ * id containing one would silently become a path with a directory hop.
32
+ * • **no leading `.` or `-`.** A leading dot hides the archive from `ls`; a
33
+ * leading dash is read as a flag by every CLI tool that would then handle
34
+ * it. Both are enforced by the first-character class.
35
+ * • **no bare `.` / `..`.** Path navigation, not names.
36
+ * • **length capped.** `NAME_MAX` is 255 on the common filesystems and the
37
+ * suffixes here add to it.
38
+ * • **no Windows reserved device names.** `con`, `nul`, `com1` … are devices
39
+ * with OR without an extension: `con.json` opens the console, not a file.
40
+ *
41
+ * Ids this library mints all satisfy it: `makeRunId()` produces
42
+ * `run-<epoch ms>-<seq>` and the footprintjs engine produces
43
+ * `<epoch ms>-<padded counter>`. The assertion is there for the ids a CALLER
44
+ * states, which is the case that is neither controlled nor rare.
45
+ *
46
+ * ## Atomic, so a reader never sees half an archive
47
+ *
48
+ * The bytes go to a temporary file in the same directory and are then renamed
49
+ * into place. `rename` within one filesystem is atomic, so a crash mid-write
50
+ * leaves a `.tmp` nobody reads rather than a truncated `.json` that parses as
51
+ * far as it got — a half-written archive is the one failure a bug report cannot
52
+ * survive, because it looks like evidence.
53
+ *
54
+ * Writing the same `runId` twice REPLACES the file, atomically. That is the
55
+ * intended behaviour and worth stating: the run id is the archive's identity,
56
+ * so a second envelope for one run is a newer version of one archive (a partial
57
+ * crash dump later superseded by the finished run), not a second archive.
58
+ *
59
+ * Node-only. `node:fs` is reached through `lazyRequire`, the same law the other
60
+ * filesystem adapters follow, so importing the door costs a browser bundle
61
+ * nothing and constructing one where there is no filesystem refuses by name.
62
+ */
63
+ import type { RecordingSink } from './recordingEnvelope.js';
64
+ /**
65
+ * Raised when a run id cannot safely become a file name.
66
+ *
67
+ * Its own class because the fix is never a retry: the caller has to name the
68
+ * archive something a filesystem can hold one-to-one.
69
+ */
70
+ export declare class UnsafeRecordingIdError extends Error {
71
+ readonly code: "ERR_UNSAFE_RECORDING_ID";
72
+ readonly runId: string;
73
+ constructor(runId: string, reason: string);
74
+ }
75
+ /**
76
+ * The mapping under test: one run id → one file name, injectively.
77
+ *
78
+ * Exported so the collision battery can drive the mapping directly rather than
79
+ * inferring it from files on a disk.
80
+ *
81
+ * @throws {UnsafeRecordingIdError} for any id outside the safe domain.
82
+ */
83
+ export declare function recordingFileName(runId: string): string;
84
+ /** Options for {@link fileRecordingSink}. */
85
+ export interface FileRecordingSinkOptions {
86
+ /** The archive directory. Created if missing, parents included. */
87
+ readonly directory: string;
88
+ }
89
+ /**
90
+ * A directory-backed recording sink — one JSON file per run, written atomically.
91
+ *
92
+ * @example
93
+ * ```ts
94
+ * const recorder = recordRun(agent);
95
+ * await agent.run({ message: 'hi' });
96
+ *
97
+ * await persistRecording(recorder, {
98
+ * sink: fileRecordingSink({ directory: './run-archive' }),
99
+ * run: { complete: true },
100
+ * });
101
+ * // → ./run-archive/run-1787093273110-1.json
102
+ * ```
103
+ */
104
+ export declare function fileRecordingSink(options: FileRecordingSinkOptions): RecordingSink;
105
+ //# sourceMappingURL=fileRecordingSink.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fileRecordingSink.d.ts","sourceRoot":"","sources":["../../../../src/recorders/observability/fileRecordingSink.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AAGH,OAAO,KAAK,EAAqB,aAAa,EAAE,MAAM,wBAAwB,CAAC;AA2B/E;;;;;GAKG;AACH,qBAAa,sBAAuB,SAAQ,KAAK;IAC/C,QAAQ,CAAC,IAAI,4BAAsC;IACnD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;gBAEX,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;CAc1C;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAkCvD;AAED,6CAA6C;AAC7C,MAAM,WAAW,wBAAwB;IACvC,mEAAmE;IACnE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAKD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,aAAa,CAkDlF"}
@@ -0,0 +1,293 @@
1
+ /**
2
+ * recordingEnvelope — the versioned, serialized contract around a recording.
3
+ *
4
+ * `recordRun` already freezes a run into `{ events, snapshot, structure }`, and
5
+ * that shape is exactly right for handing to a viewer in the same process. What
6
+ * it is NOT is a thing you can put on disk and read back next quarter: it
7
+ * carries no format marker, no producer version, no statement of which run it
8
+ * is, and no statement of whether it is the WHOLE run. So every consumer that
9
+ * wanted to archive one, attach one to a bug report, or feed one to an analysis
10
+ * tool invented its own wrapper — and each wrapper made a different guess about
11
+ * the same missing facts.
12
+ *
13
+ * This is the producer-owned answer: one envelope, one format string, and every
14
+ * field either a fact the library can prove or a fact the caller stated.
15
+ *
16
+ * import { persistRecording, fileRecordingSink } from 'agentfootprint/observe';
17
+ *
18
+ * const recorder = recordRun(agent);
19
+ * await agent.run({ message });
20
+ * await persistRecording(recorder, {
21
+ * sink: fileRecordingSink({ directory: './run-archive' }),
22
+ * run: { complete: true },
23
+ * });
24
+ *
25
+ * ## The rule this file exists to keep: never stamp a fact you had to guess
26
+ *
27
+ * An envelope is read by people and tools that were not there when the run
28
+ * happened. That makes every field a claim, and a claim that turns out to be a
29
+ * guess is worse than a missing field — a missing field sends the reader to
30
+ * look, a wrong field stops them looking. So each one has a stated source:
31
+ *
32
+ * runId, sessionId, derived from the EVENT META, which is the only
33
+ * principal, tenant place these are recorded, or stated by the caller.
34
+ * Never synthesized. See "identity" below.
35
+ * startedAt / endedAt derived from event wall clocks, but only where the
36
+ * stream can honestly supply them (see below).
37
+ * complete CALLER INPUT, always. Nothing in a finished
38
+ * recording says whether the run reached its end.
39
+ * droppedEvents read off the live recorder, which counts them; a
40
+ * bare recording carries no count, so it is asked for
41
+ * rather than assumed to be 0.
42
+ * configuration lifted from the run's own `run_configured` event —
43
+ * the manifest, which is names-and-ids only by law.
44
+ * producer read from the package manifests at runtime.
45
+ *
46
+ * Where a fact is neither derivable nor supplied, this REFUSES
47
+ * ({@link IndeterminateRunFactError}) instead of filling in a plausible value.
48
+ *
49
+ * ## Identity is never invented
50
+ *
51
+ * `principal` and `tenant` come from `EventMeta`, and `EventMeta`'s own law
52
+ * (see src/events/types.ts) is that they are stamped ONLY from an explicit
53
+ * `run(input, { identity })` — never from the run's internal identity, and
54
+ * never from a session id, because "a conversation id is not an actor". By
55
+ * sourcing them from the meta and nowhere else, this envelope inherits that
56
+ * guarantee whole: an anonymous run produces an envelope with no `principal`
57
+ * key at all, not a placeholder and not a session id wearing an actor's name.
58
+ *
59
+ * ## `runId` has two namespaces, and this one is deliberate
60
+ *
61
+ * A footprintjs snapshot carries its OWN engine-level `runId`
62
+ * (`<timestamp>-<padded counter>`, minted per `executor.run()`), while the
63
+ * agentfootprint events carry `run-<timestamp>-<seq>` from `makeRunId()`. They
64
+ * are different ids for different layers and they do not match. This envelope
65
+ * uses the EVENT-meta one exclusively, because that is the id `sessionId`,
66
+ * `principal` and `tenant` ride beside and the one every typed-event consumer
67
+ * correlates on. When the events cannot supply it, this refuses rather than
68
+ * falling back to the snapshot's — quietly substituting an id from another
69
+ * namespace would make two envelopes look comparable when they are not.
70
+ */
71
+ import type { RunManifestLike } from '../../lib/context-bisect/arms/types.js';
72
+ import type { Recording, RunRecorder } from './recordRun.js';
73
+ /**
74
+ * The format marker. Bumped only for a change an older reader could not
75
+ * survive — a reader that does not recognise the string must refuse the file,
76
+ * never half-read it.
77
+ */
78
+ export declare const RECORDING_ENVELOPE_FORMAT = "agentfootprint.recording.v1";
79
+ /**
80
+ * The privacy policy id a `'full'` envelope carries when the caller names none.
81
+ * A stable string so a retention rule can match on it rather than on prose.
82
+ */
83
+ export declare const FULL_PRIVACY_POLICY_ID = "agentfootprint.privacy.full.v1";
84
+ /**
85
+ * What a caller may ASK for. Only `'full'` is implemented in v1; the other two
86
+ * are named here so the refusal can name them back, and so a consumer writing
87
+ * against a future version gets a compile-time hint rather than a typo.
88
+ */
89
+ export type RecordingPrivacyMode = 'full' | 'structure-only' | 'redacted';
90
+ /** Versions of the two libraries that produced the bytes. */
91
+ export interface RecordingProducer {
92
+ /** This library's version, or `'unknown'` when the manifest is unreadable. */
93
+ readonly agentfootprintVersion: string;
94
+ /** The engine underneath it, or `'unknown'`. */
95
+ readonly footprintjsVersion: string;
96
+ }
97
+ /**
98
+ * WHICH run this is, and how much of it this is.
99
+ *
100
+ * Every field is either derived from the recording's own events or stated by
101
+ * the caller — see the module header for the per-field source.
102
+ */
103
+ export interface RecordingRun {
104
+ /** From `EventMeta.runId` — the agentfootprint run id, not the engine's. */
105
+ readonly runId: string;
106
+ /** Present only when the run was session-bound. Never invented. */
107
+ readonly sessionId?: string;
108
+ /** The actor the caller NAMED. Absent for an anonymous run. */
109
+ readonly principal?: string;
110
+ /** The tenant boundary the caller NAMED. Absent for a single-tenant run. */
111
+ readonly tenant?: string;
112
+ /** ISO 8601. The first recorded event's wall clock, unless the caller said. */
113
+ readonly startedAt: string;
114
+ /**
115
+ * ISO 8601. Absent when the recording is not `complete` and the caller named
116
+ * no end — a run that had not finished has no end time to report.
117
+ */
118
+ readonly endedAt?: string;
119
+ /**
120
+ * Did this recording capture the run through to its end?
121
+ *
122
+ * ALWAYS the caller's statement. A frozen recording looks identical whether
123
+ * it was taken after the run or from a crash handler mid-run, and there is no
124
+ * run-terminal event in the registry to check, so the library cannot know.
125
+ * Defaulting it to `true` would make every crash dump claim to be whole.
126
+ */
127
+ readonly complete: boolean;
128
+ /**
129
+ * Events discarded to stay under the recorder's `maxEvents` cap. `0` means
130
+ * "none were dropped", proven — never "we did not look".
131
+ */
132
+ readonly droppedEvents: number;
133
+ }
134
+ /** What the agent was configured as — names and ids only, no values. */
135
+ export interface RecordingConfiguration {
136
+ readonly agentId?: string;
137
+ /**
138
+ * The run manifest, as the run itself declared it in
139
+ * `agentfootprint.agent.run_configured`.
140
+ *
141
+ * Safe to archive by construction: the manifest's own law is NAMES AND IDS
142
+ * ONLY — no endpoints, directories, connection strings or keys — precisely
143
+ * because it was built to ride into recordings and shared traces.
144
+ */
145
+ readonly manifest?: RunManifestLike;
146
+ }
147
+ /** What was done to the bytes before they were stored. */
148
+ export interface RecordingPrivacy {
149
+ /**
150
+ * `'full'` — the recording is exactly what `recordRun` captured, unredacted.
151
+ *
152
+ * A v1 envelope can say nothing else: the redacting modes are not built, and
153
+ * this refuses to produce a label it cannot honour.
154
+ */
155
+ readonly mode: 'full';
156
+ /** Names the policy the producer applied. See {@link FULL_PRIVACY_POLICY_ID}. */
157
+ readonly policyId: string;
158
+ }
159
+ /**
160
+ * One archived run: the recording, plus everything a reader needs to know what
161
+ * they are holding.
162
+ *
163
+ * Plain JSON by construction — no Dates, no Maps, no live handles — so
164
+ * `JSON.parse(JSON.stringify(envelope))` is the same envelope. Absent optional
165
+ * fields are absent KEYS rather than keys with `undefined`, which is what makes
166
+ * that round trip exact.
167
+ */
168
+ export interface RecordingEnvelope {
169
+ readonly format: typeof RECORDING_ENVELOPE_FORMAT;
170
+ readonly producer: RecordingProducer;
171
+ readonly run: RecordingRun;
172
+ readonly configuration?: RecordingConfiguration;
173
+ readonly privacy: RecordingPrivacy;
174
+ /** The recording itself, unmodified — `{ snapshot, events, structure }`. */
175
+ readonly recording: Recording;
176
+ }
177
+ /** A timestamp a caller may state, in any of the three obvious spellings. */
178
+ export type RecordingTimestamp = string | number | Date;
179
+ /** The run facts a caller states — the half the library cannot derive. */
180
+ export interface RecordingRunFacts {
181
+ /**
182
+ * Did the recording capture the run through to its end?
183
+ *
184
+ * Required, and deliberately so: this is the one field with no derivation and
185
+ * no safe default, so the API asks rather than guesses. Say `false` for a
186
+ * recording frozen from a crash handler, a timeout, or mid-stream.
187
+ */
188
+ readonly complete: boolean;
189
+ /** Override the event-derived run id, or supply it when events cannot. */
190
+ readonly runId?: string;
191
+ readonly sessionId?: string;
192
+ readonly principal?: string;
193
+ readonly tenant?: string;
194
+ readonly startedAt?: RecordingTimestamp;
195
+ readonly endedAt?: RecordingTimestamp;
196
+ /**
197
+ * Events lost to the recorder's cap. Read off a live `recordRun` handle
198
+ * automatically; state it when persisting a bare `Recording`, whose shape
199
+ * carries no count.
200
+ */
201
+ readonly droppedEvents?: number;
202
+ }
203
+ /**
204
+ * Where an envelope goes. One method, so a destination is a few lines: a
205
+ * directory, an object store, a table, an HTTP endpoint.
206
+ */
207
+ export interface RecordingSink {
208
+ /**
209
+ * Store one envelope.
210
+ *
211
+ * @returns `id` the sink's own handle for what it just stored.
212
+ * `uri` where it landed, when the sink has a meaningful address.
213
+ */
214
+ write(envelope: RecordingEnvelope): Promise<{
215
+ id: string;
216
+ uri?: string;
217
+ }>;
218
+ }
219
+ /** Options for {@link persistRecording}. */
220
+ export interface PersistRecordingOptions {
221
+ readonly sink: RecordingSink;
222
+ /**
223
+ * The run facts. Required because {@link RecordingRunFacts.complete} is:
224
+ * an envelope that did not state whether it holds a whole run is an envelope
225
+ * whose reader has to guess.
226
+ */
227
+ readonly run: RecordingRunFacts;
228
+ /** Override the manifest lifted from the run's own `run_configured` event. */
229
+ readonly configuration?: RecordingConfiguration;
230
+ readonly privacy?: {
231
+ readonly mode?: RecordingPrivacyMode;
232
+ readonly policyId?: string;
233
+ };
234
+ }
235
+ /** Options for {@link buildRecordingEnvelope}. */
236
+ export type BuildRecordingEnvelopeOptions = Omit<PersistRecordingOptions, 'sink'>;
237
+ /** A recording to envelope, or the live handle that is still collecting one. */
238
+ export type RecordingSource = Recording | RunRecorder;
239
+ /**
240
+ * Raised when a privacy mode is asked for that this version cannot honour.
241
+ *
242
+ * Its own class because the answer is never "retry": a caller catching this has
243
+ * to change what they store or how they store it.
244
+ */
245
+ export declare class UnsupportedPrivacyModeError extends Error {
246
+ readonly code: "ERR_UNSUPPORTED_PRIVACY_MODE";
247
+ readonly mode: string;
248
+ constructor(mode: string);
249
+ }
250
+ /**
251
+ * Raised when a required run fact is neither derivable from the recording nor
252
+ * stated by the caller.
253
+ *
254
+ * Carries the `field` so a caller can catch it and supply exactly that one.
255
+ */
256
+ export declare class IndeterminateRunFactError extends Error {
257
+ readonly code: "ERR_INDETERMINATE_RUN_FACT";
258
+ readonly field: string;
259
+ constructor(field: string, detail: string);
260
+ }
261
+ /**
262
+ * Freeze a recording into an archivable envelope, without storing it.
263
+ *
264
+ * The half of {@link persistRecording} that has no destination — useful when
265
+ * the envelope goes somewhere this library should not know about (a request
266
+ * body, a queue), and the unit under test for the contract itself.
267
+ */
268
+ export declare function buildRecordingEnvelope(source: RecordingSource, options: BuildRecordingEnvelopeOptions): RecordingEnvelope;
269
+ /**
270
+ * Build the envelope and hand it to a sink.
271
+ *
272
+ * @param source the handle from `recordRun(agent)`, or the recording it made.
273
+ * Prefer the handle: it is the only thing that knows how many
274
+ * events the cap discarded.
275
+ * @param options the destination, the run facts, and the privacy statement.
276
+ *
277
+ * @example
278
+ * ```ts
279
+ * const recorder = recordRun(agent);
280
+ * await agent.run({ message: 'Weather in San Francisco?' });
281
+ *
282
+ * const { uri } = await persistRecording(recorder, {
283
+ * sink: fileRecordingSink({ directory: './run-archive' }),
284
+ * run: { complete: true },
285
+ * });
286
+ * recorder.stop();
287
+ * ```
288
+ */
289
+ export declare function persistRecording(source: RecordingSource, options: PersistRecordingOptions): Promise<{
290
+ id: string;
291
+ uri?: string;
292
+ }>;
293
+ //# sourceMappingURL=recordingEnvelope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recordingEnvelope.d.ts","sourceRoot":"","sources":["../../../../src/recorders/observability/recordingEnvelope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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E,MAAM,CAAA;CAAE,CAAC,CASvC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentfootprint",
3
- "version": "9.47.0",
3
+ "version": "9.48.0",
4
4
  "description": "The explainable agent framework — backtrack a wrong answer to the exact context that caused it (evidence, not guesses). Built on footprintjs.",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",
@@ -230,6 +230,16 @@
230
230
  "default": "./dist/doors/skill-graph.js"
231
231
  }
232
232
  },
233
+ "./recipes": {
234
+ "import": {
235
+ "types": "./dist/esm/doors/recipes.d.ts",
236
+ "default": "./dist/esm/doors/recipes.js"
237
+ },
238
+ "require": {
239
+ "types": "./dist/types/doors/recipes.d.ts",
240
+ "default": "./dist/doors/recipes.js"
241
+ }
242
+ },
233
243
  "./package.json": "./package.json"
234
244
  },
235
245
  "typesVersions": {
@@ -269,6 +279,9 @@
269
279
  ],
270
280
  "skill-graph": [
271
281
  "./dist/types/doors/skill-graph.d.ts"
282
+ ],
283
+ "recipes": [
284
+ "./dist/types/doors/recipes.d.ts"
272
285
  ]
273
286
  }
274
287
  },