markform 0.1.0 → 0.1.2

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 (37) hide show
  1. package/DOCS.md +546 -0
  2. package/README.md +484 -45
  3. package/SPEC.md +2779 -0
  4. package/dist/ai-sdk.d.mts +2 -2
  5. package/dist/ai-sdk.mjs +5 -3
  6. package/dist/{apply-C0vjijlP.mjs → apply-BfAGTHMh.mjs} +1044 -593
  7. package/dist/bin.mjs +6 -3
  8. package/dist/cli-B3NVm6zL.mjs +3904 -0
  9. package/dist/cli.mjs +6 -3
  10. package/dist/{coreTypes-T7dAuewt.d.mts → coreTypes-BXhhz9Iq.d.mts} +2795 -685
  11. package/dist/coreTypes-Dful87E0.mjs +537 -0
  12. package/dist/index.d.mts +196 -18
  13. package/dist/index.mjs +5 -3
  14. package/dist/session-Bqnwi9wp.mjs +110 -0
  15. package/dist/session-DdAtY2Ni.mjs +4 -0
  16. package/dist/shared-D7gf27Tr.mjs +3 -0
  17. package/dist/shared-N_s1M-_K.mjs +176 -0
  18. package/dist/src-BXRkGFpG.mjs +7587 -0
  19. package/examples/celebrity-deep-research/celebrity-deep-research.form.md +912 -0
  20. package/examples/earnings-analysis/earnings-analysis.form.md +6 -1
  21. package/examples/earnings-analysis/earnings-analysis.valid.ts +119 -59
  22. package/examples/movie-research/movie-research-basic.form.md +164 -0
  23. package/examples/movie-research/movie-research-deep.form.md +486 -0
  24. package/examples/movie-research/movie-research-minimal.form.md +73 -0
  25. package/examples/simple/simple-mock-filled.form.md +52 -12
  26. package/examples/simple/simple-skipped-filled.form.md +170 -0
  27. package/examples/simple/simple-with-skips.session.yaml +189 -0
  28. package/examples/simple/simple.form.md +34 -12
  29. package/examples/simple/simple.session.yaml +80 -37
  30. package/examples/startup-deep-research/startup-deep-research.form.md +456 -0
  31. package/examples/startup-research/startup-research-mock-filled.form.md +307 -0
  32. package/examples/startup-research/startup-research.form.md +211 -0
  33. package/package.json +11 -5
  34. package/dist/cli-9fvFySww.mjs +0 -2564
  35. package/dist/src-DBD3Dt4f.mjs +0 -1785
  36. package/examples/political-research/political-research.form.md +0 -233
  37. package/examples/political-research/political-research.mock.lincoln.form.md +0 -355
package/dist/index.d.mts CHANGED
@@ -1,9 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { $ as MultiSelectFieldSchema, $t as StringFieldSchema, A as FieldValue, At as SetNumberPatch, B as InspectIssue, Bt as SimpleCheckboxState, C as FieldGroup, Ct as SessionTranscriptSchema, D as FieldProgress, Dt as SetCheckboxesPatchSchema, E as FieldKindSchema, Et as SetCheckboxesPatch, F as HarnessConfig, Ft as SetStringListPatchSchema, G as IssueReasonSchema, Gt as SingleSelectValueSchema, H as InspectResult, Ht as SingleSelectField, I as HarnessConfigSchema, It as SetStringPatch, J as MarkformFrontmatter, Jt as SourceRange, K as IssueScope, Kt as SourcePosition, L as Id, Lt as SetStringPatchSchema, M as FillMode, Mt as SetSingleSelectPatch, N as FormSchema, Nt as SetSingleSelectPatchSchema, O as FieldProgressSchema, Ot as SetMultiSelectPatch, P as FormSchemaSchema, Pt as SetStringListPatch, Q as MultiSelectField, Qt as StringField, R as IdIndexEntry, Rt as Severity, S as FieldBase, St as SessionTranscript, T as FieldKind, Tt as SessionTurnSchema, U as InspectResultSchema, Ut as SingleSelectFieldSchema, V as InspectIssueSchema, Vt as SimpleCheckboxStateSchema, W as IssueReason, Wt as SingleSelectValue, X as MultiCheckboxState, Xt as StepResult, Y as MarkformFrontmatterSchema, Yt as SourceRangeSchema, Z as MultiCheckboxStateSchema, Zt as StepResultSchema, _ as DocumentationTag, _t as ProgressSummary, a as CheckboxProgressCounts, an as StringValueSchema, at as NumberValueSchema, b as ExplicitCheckboxValueSchema, bt as SessionFinal, c as CheckboxValueSchema, cn as ValidationIssue, ct as OptionIdSchema, d as CheckboxesValue, dn as ValidatorFn, dt as Patch, en as StringListField, et as MultiSelectValue, f as CheckboxesValueSchema, fn as ValidatorRef, ft as PatchSchema, g as DocumentationBlockSchema, gt as ProgressStateSchema, h as DocumentationBlock, ht as ProgressState, i as CheckboxModeSchema, in as StringValue, it as NumberValue, j as FieldValueSchema, jt as SetNumberPatchSchema, k as FieldSchema, kt as SetMultiSelectPatchSchema, l as CheckboxesField, ln as ValidationIssueSchema, lt as OptionSchema, m as ClearFieldPatchSchema, mn as ValidatorRegistry, mt as ProgressCountsSchema, n as ApplyResultSchema, nn as StringListValue, nt as NumberField, o as CheckboxProgressCountsSchema, on as StructureSummary, ot as Option, p as ClearFieldPatch, pn as ValidatorRefSchema, pt as ProgressCounts, q as IssueScopeSchema, qt as SourcePositionSchema, r as CheckboxMode, rn as StringListValueSchema, rt as NumberFieldSchema, s as CheckboxValue, sn as StructureSummarySchema, st as OptionId, t as ApplyResult, tn as StringListFieldSchema, tt as MultiSelectValueSchema, u as CheckboxesFieldSchema, un as ValidatorContext, ut as ParsedForm, v as DocumentationTagSchema, vt as ProgressSummarySchema, w as FieldGroupSchema, wt as SessionTurn, x as Field, xt as SessionFinalSchema, y as ExplicitCheckboxValue, yt as QualifiedOptionRef, z as IdSchema, zt as SeveritySchema } from "./coreTypes-T7dAuewt.mjs";
3
+ import { $ as MarkformFrontmatter, $t as SingleSelectValueSchema, A as FieldProgressSchema, At as SessionTranscriptSchema, B as HarnessConfig, Bt as SetSingleSelectPatch, C as Field, Ct as ProgressStateSchema, D as FieldKind, Dt as SessionFinal, E as FieldGroupSchema, Et as QualifiedOptionRef, F as FieldValueSchema, Ft as SetCheckboxesPatchSchema, G as InspectIssue, Gt as SetStringPatchSchema, H as Id, Ht as SetStringListPatch, I as FillMode, It as SetMultiSelectPatch, J as InspectResultSchema, Jt as SimpleCheckboxState, K as InspectIssueSchema, Kt as Severity, L as FormSchema, Lt as SetMultiSelectPatchSchema, M as FieldResponseSchema, Mt as SessionTurnSchema, N as FieldSchema, Nt as SessionTurnStats, O as FieldKindSchema, Ot as SessionFinalSchema, P as FieldValue, Pt as SetCheckboxesPatch, Q as IssueScopeSchema, Qt as SingleSelectValue, R as FormSchemaSchema, Rt as SetNumberPatch, S as ExplicitCheckboxValueSchema, Sn as ValidatorRegistry, St as ProgressState, T as FieldGroup, Tt as ProgressSummarySchema, U as IdIndexEntry, Ut as SetStringListPatchSchema, V as HarnessConfigSchema, Vt as SetSingleSelectPatchSchema, W as IdSchema, Wt as SetStringPatch, X as IssueReasonSchema, Xt as SingleSelectField, Y as IssueReason, Yt as SimpleCheckboxStateSchema, Z as IssueScope, Zt as SingleSelectFieldSchema, _ as DocumentationBlock, _n as ValidationIssueSchema, _t as ParsedForm, a as CheckboxMode, an as StepResultSchema, at as MultiSelectValue, b as DocumentationTagSchema, bn as ValidatorRef, bt as ProgressCounts, c as CheckboxProgressCountsSchema, cn as StringListField, ct as Note, d as CheckboxesField, dn as StringListValueSchema, dt as NumberValue, en as SourcePosition, et as MarkformFrontmatterSchema, f as CheckboxesFieldSchema, fn as StringValue, ft as NumberValueSchema, g as ClearFieldPatchSchema, gn as ValidationIssue, gt as OptionSchema, h as ClearFieldPatch, hn as StructureSummarySchema, ht as OptionIdSchema, i as ApplyResultSchema, in as StepResult, it as MultiSelectFieldSchema, j as FieldResponse, jt as SessionTurn, k as FieldProgress, kt as SessionTranscript, l as CheckboxValue, ln as StringListFieldSchema, lt as NumberField, m as CheckboxesValueSchema, mn as StructureSummary, mt as OptionId, n as AnswerStateSchema, nn as SourceRange, nt as MultiCheckboxStateSchema, o as CheckboxModeSchema, on as StringField, ot as MultiSelectValueSchema, p as CheckboxesValue, pn as StringValueSchema, pt as Option, q as InspectResult, qt as SeveritySchema, r as ApplyResult, rn as SourceRangeSchema, rt as MultiSelectField, s as CheckboxProgressCounts, sn as StringFieldSchema, st as NodeType, t as AnswerState, tn as SourcePositionSchema, tt as MultiCheckboxState, u as CheckboxValueSchema, un as StringListValue, ut as NumberFieldSchema, v as DocumentationBlockSchema, vn as ValidatorContext, vt as Patch, w as FieldBase, wt as ProgressSummary, x as ExplicitCheckboxValue, xn as ValidatorRefSchema, xt as ProgressCountsSchema, y as DocumentationTag, yn as ValidatorFn, yt as PatchSchema, z as FrontmatterHarnessConfig, zt as SetNumberPatchSchema } from "./coreTypes-BXhhz9Iq.mjs";
4
+ import "@markdoc/markdoc";
4
5
  import { LanguageModel } from "ai";
5
6
 
6
- //#region src/engine/parse.d.ts
7
+ //#region src/engine/parseHelpers.d.ts
7
8
 
8
9
  /** Parse error with source location info */
9
10
  declare class ParseError extends Error {
@@ -11,6 +12,8 @@ declare class ParseError extends Error {
11
12
  readonly col?: number | undefined;
12
13
  constructor(message: string, line?: number | undefined, col?: number | undefined);
13
14
  }
15
+ //#endregion
16
+ //#region src/engine/parse.d.ts
14
17
  /**
15
18
  * Parse a Markform .form.md document.
16
19
  *
@@ -21,9 +24,10 @@ declare class ParseError extends Error {
21
24
  declare function parseForm(markdown: string): ParsedForm;
22
25
  //#endregion
23
26
  //#region src/engine/serialize.d.ts
27
+
24
28
  interface SerializeOptions {
25
- /** Markform version to use in frontmatter. Defaults to "0.1.0". */
26
- markformVersion?: string;
29
+ /** Markform spec version to use in frontmatter. Defaults to MF_SPEC_VERSION. */
30
+ specVersion?: string;
27
31
  }
28
32
  /**
29
33
  * Serialize a ParsedForm to canonical Markdoc markdown format.
@@ -46,11 +50,12 @@ declare function computeStructureSummary(schema: FormSchema): StructureSummary;
46
50
  * Compute a progress summary for a form.
47
51
  *
48
52
  * @param schema - The form schema
49
- * @param values - Current field values
53
+ * @param responsesByFieldId - Current field responses (state + optional value)
54
+ * @param notes - Notes attached to fields/groups/form
50
55
  * @param issues - Validation issues (from inspect)
51
56
  * @returns Progress summary with field states and counts
52
57
  */
53
- declare function computeProgressSummary(schema: FormSchema, values: Record<Id, FieldValue>, issues: InspectIssue[]): ProgressSummary;
58
+ declare function computeProgressSummary(schema: FormSchema, responsesByFieldId: Record<Id, FieldResponse>, notes: Note[], issues: InspectIssue[]): ProgressSummary;
54
59
  /**
55
60
  * Compute the overall form state from progress summary.
56
61
  *
@@ -61,6 +66,16 @@ declare function computeFormState(progress: ProgressSummary): ProgressState;
61
66
  /**
62
67
  * Determine if the form is complete (ready for submission).
63
68
  *
69
+ * A form is complete when:
70
+ * 1. No aborted fields (aborted fields block completion)
71
+ * 2. No required fields are empty
72
+ * 3. No fields have validation errors
73
+ * 4. No fields are in incomplete state (e.g., partial checkbox completion)
74
+ * 5. All fields must be addressed (answered + skipped == total)
75
+ *
76
+ * Every field must be explicitly addressed - either filled with a value or
77
+ * skipped with a reason. This ensures agents fully process all fields.
78
+ *
64
79
  * @param progress - The progress summary
65
80
  * @returns True if the form is complete
66
81
  */
@@ -75,11 +90,12 @@ interface ComputedSummaries {
75
90
  * Compute all summaries for a parsed form.
76
91
  *
77
92
  * @param schema - The form schema
78
- * @param values - Current field values
93
+ * @param responsesByFieldId - Current field responses (state + optional value)
94
+ * @param notes - Notes attached to fields/groups/form
79
95
  * @param issues - Validation issues
80
96
  * @returns All computed summaries
81
97
  */
82
- declare function computeAllSummaries(schema: FormSchema, values: Record<Id, FieldValue>, issues: InspectIssue[]): ComputedSummaries;
98
+ declare function computeAllSummaries(schema: FormSchema, responsesByFieldId: Record<Id, FieldResponse>, notes: Note[], issues: InspectIssue[]): ComputedSummaries;
83
99
  //#endregion
84
100
  //#region src/engine/validate.d.ts
85
101
  interface ValidateOptions {
@@ -205,7 +221,7 @@ declare function coerceToFieldPatch(form: ParsedForm, fieldId: string, rawValue:
205
221
  declare function coerceInputContext(form: ParsedForm, inputContext: InputContext): CoerceInputContextResult;
206
222
  //#endregion
207
223
  //#region src/harness/harness.d.ts
208
- type HarnessState = "init" | "step" | "wait" | "complete";
224
+ type HarnessState = 'init' | 'step' | 'wait' | 'complete';
209
225
  /**
210
226
  * Form harness for managing agent-driven form filling.
211
227
  */
@@ -234,6 +250,13 @@ declare class FormHarness {
234
250
  getForm(): ParsedForm;
235
251
  /**
236
252
  * Check if the harness has reached max turns.
253
+ *
254
+ * Returns true when we've completed all allowed turns. This happens when:
255
+ * - turnNumber >= maxTurns AND we've already applied (state is "complete")
256
+ * - OR turnNumber > maxTurns (we've exceeded the limit)
257
+ *
258
+ * This allows the harness loop to run N times when maxTurns=N by returning
259
+ * false when we're at turn N but haven't applied yet (state is "wait").
237
260
  */
238
261
  hasReachedMaxTurns(): boolean;
239
262
  /**
@@ -254,9 +277,19 @@ declare class FormHarness {
254
277
  *
255
278
  * @param patches - Patches to apply
256
279
  * @param issues - Issues that were shown to the agent (for recording)
280
+ * @param llmStats - Optional LLM stats for session logging
257
281
  * @returns StepResult after applying patches
258
282
  */
259
- apply(patches: Patch[], issues: InspectIssue[]): StepResult;
283
+ apply(patches: Patch[], issues: InspectIssue[], llmStats?: SessionTurnStats): StepResult;
284
+ /**
285
+ * Compute step result from inspect result.
286
+ * Applies issue filtering and computes step budget.
287
+ */
288
+ private computeStepResult;
289
+ /**
290
+ * Record a turn in the session transcript.
291
+ */
292
+ private recordTurn;
260
293
  /**
261
294
  * Check if the form is complete.
262
295
  */
@@ -303,6 +336,51 @@ declare class FormHarness {
303
336
  declare function createHarness(form: ParsedForm, config?: Partial<HarnessConfig>): FormHarness;
304
337
  //#endregion
305
338
  //#region src/harness/harnessTypes.d.ts
339
+ /**
340
+ * Per-turn statistics from LLM calls.
341
+ *
342
+ * Tracks token usage, tool calls, and form progress for observability.
343
+ */
344
+ interface TurnStats {
345
+ /** Input tokens for this turn (from provider usage) */
346
+ inputTokens?: number;
347
+ /** Output tokens for this turn (from provider usage) */
348
+ outputTokens?: number;
349
+ /** Tool calls made during this turn */
350
+ toolCalls: {
351
+ /** Tool name */
352
+ name: string;
353
+ /** Number of times called */
354
+ count: number;
355
+ }[];
356
+ /** Form progress after this turn */
357
+ formProgress: {
358
+ /** Fields with values */
359
+ answeredFields: number;
360
+ /** Fields marked as skipped */
361
+ skippedFields: number;
362
+ /** Required issues still remaining */
363
+ requiredRemaining: number;
364
+ /** Optional/recommended issues still remaining */
365
+ optionalRemaining: number;
366
+ };
367
+ /** Full prompts sent to LLM (for verbose logging) */
368
+ prompts?: {
369
+ /** System prompt with instructions */
370
+ system: string;
371
+ /** Context prompt with form state and issues */
372
+ context: string;
373
+ };
374
+ }
375
+ /**
376
+ * Response from agent's generatePatches call.
377
+ */
378
+ interface AgentResponse {
379
+ /** Patches to apply */
380
+ patches: Patch[];
381
+ /** Per-turn stats (undefined for MockAgent) */
382
+ stats?: TurnStats;
383
+ }
306
384
  /**
307
385
  * Interface for agents that can generate patches.
308
386
  */
@@ -313,9 +391,9 @@ interface Agent {
313
391
  * @param issues - Prioritized issues from harness step
314
392
  * @param form - Current form state
315
393
  * @param maxPatches - Maximum number of patches to generate
316
- * @returns Promise resolving to array of patches to apply
394
+ * @returns Promise resolving to patches and optional stats
317
395
  */
318
- generatePatches(issues: InspectIssue[], form: ParsedForm, maxPatches: number): Promise<Patch[]>;
396
+ generatePatches(issues: InspectIssue[], form: ParsedForm, maxPatches: number): Promise<AgentResponse>;
319
397
  }
320
398
  /**
321
399
  * Options for the fillForm function.
@@ -337,7 +415,7 @@ interface FillOptions {
337
415
  /** Maximum patches per turn (default: 20) */
338
416
  maxPatchesPerTurn?: number;
339
417
  /** Maximum issues to show per turn (default: 10) */
340
- maxIssues?: number;
418
+ maxIssuesPerTurn?: number;
341
419
  /** Target roles to fill (default: ['agent']) */
342
420
  targetRoles?: string[];
343
421
  /** Fill mode: 'continue' (skip filled) or 'overwrite' (re-fill) */
@@ -361,6 +439,8 @@ interface TurnProgress {
361
439
  patchesApplied: number;
362
440
  requiredIssuesRemaining: number;
363
441
  isComplete: boolean;
442
+ /** Per-turn stats from LLM (undefined for MockAgent) */
443
+ stats?: TurnStats;
364
444
  }
365
445
  /**
366
446
  * Fill status indicating success or failure reason.
@@ -369,7 +449,7 @@ type FillStatus = {
369
449
  ok: true;
370
450
  } | {
371
451
  ok: false;
372
- reason: "max_turns" | "cancelled" | "error";
452
+ reason: 'max_turns' | 'cancelled' | 'error';
373
453
  message?: string;
374
454
  };
375
455
  /**
@@ -394,7 +474,7 @@ interface FillResult {
394
474
  remainingIssues?: {
395
475
  ref: string;
396
476
  message: string;
397
- severity: "required" | "recommended";
477
+ severity: 'required' | 'recommended';
398
478
  priority: number;
399
479
  }[];
400
480
  }
@@ -416,9 +496,15 @@ declare class MockAgent implements Agent {
416
496
  * Generate patches from the completed mock to address issues.
417
497
  *
418
498
  * Processes issues in priority order, generating patches for
419
- * fields that have values in the completed mock.
499
+ * fields that have values in the completed mock. For fields with no
500
+ * value (empty optional fields), generates skip_field patches.
501
+ * Returns AgentResponse with patches but no stats (mock doesn't track LLM usage).
420
502
  */
421
- generatePatches(issues: InspectIssue[], _form: ParsedForm, maxPatches: number): Promise<Patch[]>;
503
+ generatePatches(issues: InspectIssue[], _form: ParsedForm, maxPatches: number): Promise<AgentResponse>;
504
+ /**
505
+ * Check if a field value actually has content (not null/empty).
506
+ */
507
+ private hasValue;
422
508
  /**
423
509
  * Create a patch for a field based on its kind and completed value.
424
510
  */
@@ -469,6 +555,98 @@ declare function createMockAgent(completedForm: ParsedForm): MockAgent;
469
555
  */
470
556
  declare function fillForm(options: FillOptions): Promise<FillResult>;
471
557
  //#endregion
558
+ //#region src/harness/harnessConfigResolver.d.ts
559
+ /**
560
+ * Resolve harness configuration by merging options from multiple sources.
561
+ *
562
+ * Precedence (highest to lowest):
563
+ * 1. options parameter (API-provided)
564
+ * 2. form.metadata.harnessConfig (from frontmatter)
565
+ * 3. Default constants
566
+ *
567
+ * @param form The parsed form (may contain frontmatter harness config)
568
+ * @param options API-provided options to override defaults
569
+ * @returns Resolved harness configuration
570
+ */
571
+ declare function resolveHarnessConfig(form: ParsedForm, options?: Partial<FillOptions>): HarnessConfig;
572
+ //#endregion
573
+ //#region src/research/researchTypes.d.ts
574
+ /**
575
+ * Research execution status.
576
+ */
577
+ type ResearchStatus = 'completed' | 'incomplete' | 'max_turns_reached';
578
+ /**
579
+ * Result of a research fill operation.
580
+ */
581
+ interface ResearchResult {
582
+ /** Final status of the research */
583
+ status: ResearchStatus;
584
+ /** The filled form */
585
+ form: ParsedForm;
586
+ /** Optional session transcript for debugging */
587
+ transcript?: SessionTranscript;
588
+ /** Total harness turns executed */
589
+ totalTurns: number;
590
+ /** Total input tokens used (if available) */
591
+ inputTokens?: number;
592
+ /** Total output tokens used (if available) */
593
+ outputTokens?: number;
594
+ /** Tools available to the agent */
595
+ availableTools?: string[];
596
+ /** Path to saved .form.md file */
597
+ formPath?: string;
598
+ /** Path to saved .raw.md file */
599
+ rawPath?: string;
600
+ /** Path to saved .yaml file */
601
+ yamlPath?: string;
602
+ }
603
+ //#endregion
604
+ //#region src/research/runResearch.d.ts
605
+ /**
606
+ * Options for runResearch (FillOptions without form, since form is a separate parameter).
607
+ */
608
+ type ResearchOptions = Omit<FillOptions, 'form'>;
609
+ /**
610
+ * Run research fill on a form.
611
+ *
612
+ * This function fills a form using an LLM with optional web search capabilities.
613
+ * It resolves configuration from multiple sources (options > frontmatter > defaults)
614
+ * and executes the harness loop until completion or max turns.
615
+ *
616
+ * @param form The parsed form to fill
617
+ * @param options Fill options including model specification
618
+ * @returns Research result with filled form and statistics
619
+ */
620
+ declare function runResearch(form: ParsedForm, options: ResearchOptions): Promise<ResearchResult>;
621
+ //#endregion
622
+ //#region src/research/researchFormValidation.d.ts
623
+ /**
624
+ * Check if a form is configured for research mode.
625
+ *
626
+ * A form is considered a research form if it has web search configuration
627
+ * in its frontmatter metadata, indicated by:
628
+ * - webSearchModel: model ID for web search capability
629
+ * - enableWebSearch: boolean flag to enable web search
630
+ *
631
+ * @param form The parsed form to check
632
+ * @returns true if the form is configured for research
633
+ */
634
+ declare function isResearchForm(form: ParsedForm): boolean;
635
+ /**
636
+ * Validate that a form is suitable for research fill.
637
+ *
638
+ * Research forms should:
639
+ * 1. Have agent-role fields to fill
640
+ * 2. Not be already complete
641
+ *
642
+ * @param form The parsed form to validate
643
+ * @returns Object with isValid and optional error message
644
+ */
645
+ declare function validateResearchForm(form: ParsedForm): {
646
+ isValid: boolean;
647
+ error?: string;
648
+ };
649
+ //#endregion
472
650
  //#region src/index.d.ts
473
651
  /**
474
652
  * Markform - Agent-friendly, human-readable, editable forms.
@@ -479,4 +657,4 @@ declare function fillForm(options: FillOptions): Promise<FillResult>;
479
657
  /** Markform version. */
480
658
  declare const VERSION = "0.1.0";
481
659
  //#endregion
482
- export { type ApplyResult, ApplyResultSchema, type CheckboxMode, CheckboxModeSchema, type CheckboxProgressCounts, CheckboxProgressCountsSchema, type CheckboxValue, CheckboxValueSchema, type CheckboxesField, CheckboxesFieldSchema, type CheckboxesValue, CheckboxesValueSchema, type ClearFieldPatch, ClearFieldPatchSchema, type CoerceInputContextResult, type CoercionResult, type ComputedSummaries, type DocumentationBlock, DocumentationBlockSchema, type DocumentationTag, DocumentationTagSchema, type ExplicitCheckboxValue, ExplicitCheckboxValueSchema, type Field, type FieldBase, type FieldGroup, FieldGroupSchema, type FieldKind, FieldKindSchema, type FieldProgress, FieldProgressSchema, FieldSchema, type FieldValue, FieldValueSchema, type FillOptions, type FillResult, type FillStatus, FormHarness, type FormSchema, FormSchemaSchema, type HarnessConfig, HarnessConfigSchema, type Id, type IdIndexEntry, IdSchema, type InputContext, type InspectIssue, InspectIssueSchema, type InspectOptions, type InspectResult, InspectResultSchema, type IssueReason, IssueReasonSchema, type IssueScope, IssueScopeSchema, type MarkformFrontmatter, MarkformFrontmatterSchema, MockAgent, type MultiCheckboxState, MultiCheckboxStateSchema, type MultiSelectField, MultiSelectFieldSchema, type MultiSelectValue, MultiSelectValueSchema, type NumberField, NumberFieldSchema, type NumberValue, NumberValueSchema, type Option, type OptionId, OptionIdSchema, OptionSchema, ParseError, type ParsedForm, type Patch, PatchSchema, type ProgressCounts, ProgressCountsSchema, type ProgressState, ProgressStateSchema, type ProgressSummary, ProgressSummarySchema, type QualifiedOptionRef, type RawFieldValue, type SerializeOptions, type SessionFinal, SessionFinalSchema, type SessionTranscript, SessionTranscriptSchema, type SessionTurn, SessionTurnSchema, type SetCheckboxesPatch, SetCheckboxesPatchSchema, type SetMultiSelectPatch, SetMultiSelectPatchSchema, type SetNumberPatch, SetNumberPatchSchema, type SetSingleSelectPatch, SetSingleSelectPatchSchema, type SetStringListPatch, SetStringListPatchSchema, type SetStringPatch, SetStringPatchSchema, type Severity, SeveritySchema, type SimpleCheckboxState, SimpleCheckboxStateSchema, type SingleSelectField, SingleSelectFieldSchema, type SingleSelectValue, SingleSelectValueSchema, type SourcePosition, SourcePositionSchema, type SourceRange, SourceRangeSchema, type StepResult, StepResultSchema, type StringField, StringFieldSchema, type StringListField, StringListFieldSchema, type StringListValue, StringListValueSchema, type StringValue, StringValueSchema, type StructureSummary, StructureSummarySchema, type TurnProgress, VERSION, type ValidateOptions, type ValidateResult, type ValidationIssue, ValidationIssueSchema, type ValidatorContext, type ValidatorFn, type ValidatorRef, ValidatorRefSchema, type ValidatorRegistry, applyPatches, coerceInputContext, coerceToFieldPatch, computeAllSummaries, computeFormState, computeProgressSummary, computeStructureSummary, createHarness, createMockAgent, fillForm, findFieldById, inspect, isFormComplete, parseForm, parseSession, serialize, serializeSession, validate };
660
+ export { type AgentResponse, type AnswerState, AnswerStateSchema, type ApplyResult, ApplyResultSchema, type CheckboxMode, CheckboxModeSchema, type CheckboxProgressCounts, CheckboxProgressCountsSchema, type CheckboxValue, CheckboxValueSchema, type CheckboxesField, CheckboxesFieldSchema, type CheckboxesValue, CheckboxesValueSchema, type ClearFieldPatch, ClearFieldPatchSchema, type CoerceInputContextResult, type CoercionResult, type ComputedSummaries, type DocumentationBlock, DocumentationBlockSchema, type DocumentationTag, DocumentationTagSchema, type ExplicitCheckboxValue, ExplicitCheckboxValueSchema, type Field, type FieldBase, type FieldGroup, FieldGroupSchema, type FieldKind, FieldKindSchema, type FieldProgress, FieldProgressSchema, type FieldResponse, FieldResponseSchema, FieldSchema, type FieldValue, FieldValueSchema, type FillOptions, type FillResult, type FillStatus, FormHarness, type FormSchema, FormSchemaSchema, type FrontmatterHarnessConfig, type HarnessConfig, HarnessConfigSchema, type Id, type IdIndexEntry, IdSchema, type InputContext, type InspectIssue, InspectIssueSchema, type InspectOptions, type InspectResult, InspectResultSchema, type IssueReason, IssueReasonSchema, type IssueScope, IssueScopeSchema, type MarkformFrontmatter, MarkformFrontmatterSchema, MockAgent, type MultiCheckboxState, MultiCheckboxStateSchema, type MultiSelectField, MultiSelectFieldSchema, type MultiSelectValue, MultiSelectValueSchema, type NodeType, type NumberField, NumberFieldSchema, type NumberValue, NumberValueSchema, type Option, type OptionId, OptionIdSchema, OptionSchema, ParseError, type ParsedForm, type Patch, PatchSchema, type ProgressCounts, ProgressCountsSchema, type ProgressState, ProgressStateSchema, type ProgressSummary, ProgressSummarySchema, type QualifiedOptionRef, type RawFieldValue, type ResearchOptions, type ResearchResult, type ResearchStatus, type SerializeOptions, type SessionFinal, SessionFinalSchema, type SessionTranscript, SessionTranscriptSchema, type SessionTurn, SessionTurnSchema, type SessionTurnStats, type SetCheckboxesPatch, SetCheckboxesPatchSchema, type SetMultiSelectPatch, SetMultiSelectPatchSchema, type SetNumberPatch, SetNumberPatchSchema, type SetSingleSelectPatch, SetSingleSelectPatchSchema, type SetStringListPatch, SetStringListPatchSchema, type SetStringPatch, SetStringPatchSchema, type Severity, SeveritySchema, type SimpleCheckboxState, SimpleCheckboxStateSchema, type SingleSelectField, SingleSelectFieldSchema, type SingleSelectValue, SingleSelectValueSchema, type SourcePosition, SourcePositionSchema, type SourceRange, SourceRangeSchema, type StepResult, StepResultSchema, type StringField, StringFieldSchema, type StringListField, StringListFieldSchema, type StringListValue, StringListValueSchema, type StringValue, StringValueSchema, type StructureSummary, StructureSummarySchema, type TurnProgress, type TurnStats, VERSION, type ValidateOptions, type ValidateResult, type ValidationIssue, ValidationIssueSchema, type ValidatorContext, type ValidatorFn, type ValidatorRef, ValidatorRefSchema, type ValidatorRegistry, applyPatches, coerceInputContext, coerceToFieldPatch, computeAllSummaries, computeFormState, computeProgressSummary, computeStructureSummary, createHarness, createMockAgent, fillForm, findFieldById, inspect, isFormComplete, isResearchForm, parseForm, parseSession, resolveHarnessConfig, runResearch, serialize, serializeSession, validate, validateResearchForm };
package/dist/index.mjs CHANGED
@@ -1,4 +1,6 @@
1
- import { $ as PatchSchema, A as DocumentationBlockSchema, B as IdSchema, C as ApplyResultSchema, Ct as StructureSummarySchema, D as CheckboxesFieldSchema, E as CheckboxValueSchema, F as FieldProgressSchema, G as MarkformFrontmatterSchema, H as InspectResultSchema, I as FieldSchema, J as MultiSelectValueSchema, K as MultiCheckboxStateSchema, L as FieldValueSchema, M as ExplicitCheckboxValueSchema, N as FieldGroupSchema, O as CheckboxesValueSchema, P as FieldKindSchema, Q as OptionSchema, R as FormSchemaSchema, St as StringValueSchema, T as CheckboxProgressCountsSchema, Tt as ValidatorRefSchema, U as IssueReasonSchema, V as InspectIssueSchema, W as IssueScopeSchema, X as NumberValueSchema, Y as NumberFieldSchema, Z as OptionIdSchema, _t as SourceRangeSchema, a as computeAllSummaries, at as SessionTurnSchema, bt as StringListFieldSchema, c as computeStructureSummary, ct as SetNumberPatchSchema, dt as SetStringPatchSchema, et as ProgressCountsSchema, ft as SeveritySchema, gt as SourcePositionSchema, ht as SingleSelectValueSchema, i as validate, it as SessionTranscriptSchema, j as DocumentationTagSchema, k as ClearFieldPatchSchema, l as isFormComplete, lt as SetSingleSelectPatchSchema, mt as SingleSelectFieldSchema, nt as ProgressSummarySchema, o as computeFormState, ot as SetCheckboxesPatchSchema, pt as SimpleCheckboxStateSchema, q as MultiSelectFieldSchema, r as inspect, rt as SessionFinalSchema, s as computeProgressSummary, st as SetMultiSelectPatchSchema, t as applyPatches, tt as ProgressStateSchema, u as serialize, ut as SetStringListPatchSchema, vt as StepResultSchema, w as CheckboxModeSchema, wt as ValidationIssueSchema, xt as StringListValueSchema, yt as StringFieldSchema, z as HarnessConfigSchema } from "./apply-C0vjijlP.mjs";
2
- import { _ as parseForm, c as createMockAgent, d as coerceInputContext, f as coerceToFieldPatch, g as ParseError, h as serializeSession, l as FormHarness, m as parseSession, n as fillForm, p as findFieldById, s as MockAgent, t as VERSION, u as createHarness } from "./src-DBD3Dt4f.mjs";
1
+ import { $ as StringFieldSchema, A as NumberValueSchema, B as SetCheckboxesPatchSchema, C as IssueReasonSchema, D as MultiSelectFieldSchema, E as MultiCheckboxStateSchema, F as ProgressStateSchema, G as SetStringPatchSchema, H as SetNumberPatchSchema, I as ProgressSummarySchema, J as SingleSelectFieldSchema, K as SeveritySchema, L as SessionFinalSchema, M as OptionSchema, N as PatchSchema, O as MultiSelectValueSchema, P as ProgressCountsSchema, Q as StepResultSchema, R as SessionTranscriptSchema, S as InspectResultSchema, T as MarkformFrontmatterSchema, U as SetSingleSelectPatchSchema, V as SetMultiSelectPatchSchema, W as SetStringListPatchSchema, X as SourcePositionSchema, Y as SingleSelectValueSchema, Z as SourceRangeSchema, _ as FieldValueSchema, a as CheckboxValueSchema, at as ValidatorRefSchema, b as IdSchema, c as ClearFieldPatchSchema, d as ExplicitCheckboxValueSchema, et as StringListFieldSchema, f as FieldGroupSchema, g as FieldSchema, h as FieldResponseSchema, i as CheckboxProgressCountsSchema, it as ValidationIssueSchema, j as OptionIdSchema, k as NumberFieldSchema, l as DocumentationBlockSchema, m as FieldProgressSchema, n as ApplyResultSchema, nt as StringValueSchema, o as CheckboxesFieldSchema, p as FieldKindSchema, q as SimpleCheckboxStateSchema, r as CheckboxModeSchema, rt as StructureSummarySchema, s as CheckboxesValueSchema, t as AnswerStateSchema, tt as StringListValueSchema, u as DocumentationTagSchema, v as FormSchemaSchema, w as IssueScopeSchema, x as InspectIssueSchema, y as HarnessConfigSchema, z as SessionTurnSchema } from "./coreTypes-Dful87E0.mjs";
2
+ import { a as computeAllSummaries, c as computeStructureSummary, i as validate, l as isFormComplete, o as computeFormState, r as inspect, s as computeProgressSummary, t as applyPatches, u as serialize } from "./apply-BfAGTHMh.mjs";
3
+ import { _ as findFieldById, a as resolveHarnessConfig, d as MockAgent, f as createMockAgent, g as coerceToFieldPatch, h as coerceInputContext, i as runResearch, m as createHarness, n as isResearchForm, o as fillForm, p as FormHarness, r as validateResearchForm, t as VERSION, v as parseForm, y as ParseError } from "./src-BXRkGFpG.mjs";
4
+ import { n as serializeSession, t as parseSession } from "./session-Bqnwi9wp.mjs";
3
5
 
4
- export { ApplyResultSchema, CheckboxModeSchema, CheckboxProgressCountsSchema, CheckboxValueSchema, CheckboxesFieldSchema, CheckboxesValueSchema, ClearFieldPatchSchema, DocumentationBlockSchema, DocumentationTagSchema, ExplicitCheckboxValueSchema, FieldGroupSchema, FieldKindSchema, FieldProgressSchema, FieldSchema, FieldValueSchema, FormHarness, FormSchemaSchema, HarnessConfigSchema, IdSchema, InspectIssueSchema, InspectResultSchema, IssueReasonSchema, IssueScopeSchema, MarkformFrontmatterSchema, MockAgent, MultiCheckboxStateSchema, MultiSelectFieldSchema, MultiSelectValueSchema, NumberFieldSchema, NumberValueSchema, OptionIdSchema, OptionSchema, ParseError, PatchSchema, ProgressCountsSchema, ProgressStateSchema, ProgressSummarySchema, SessionFinalSchema, SessionTranscriptSchema, SessionTurnSchema, SetCheckboxesPatchSchema, SetMultiSelectPatchSchema, SetNumberPatchSchema, SetSingleSelectPatchSchema, SetStringListPatchSchema, SetStringPatchSchema, SeveritySchema, SimpleCheckboxStateSchema, SingleSelectFieldSchema, SingleSelectValueSchema, SourcePositionSchema, SourceRangeSchema, StepResultSchema, StringFieldSchema, StringListFieldSchema, StringListValueSchema, StringValueSchema, StructureSummarySchema, VERSION, ValidationIssueSchema, ValidatorRefSchema, applyPatches, coerceInputContext, coerceToFieldPatch, computeAllSummaries, computeFormState, computeProgressSummary, computeStructureSummary, createHarness, createMockAgent, fillForm, findFieldById, inspect, isFormComplete, parseForm, parseSession, serialize, serializeSession, validate };
6
+ export { AnswerStateSchema, ApplyResultSchema, CheckboxModeSchema, CheckboxProgressCountsSchema, CheckboxValueSchema, CheckboxesFieldSchema, CheckboxesValueSchema, ClearFieldPatchSchema, DocumentationBlockSchema, DocumentationTagSchema, ExplicitCheckboxValueSchema, FieldGroupSchema, FieldKindSchema, FieldProgressSchema, FieldResponseSchema, FieldSchema, FieldValueSchema, FormHarness, FormSchemaSchema, HarnessConfigSchema, IdSchema, InspectIssueSchema, InspectResultSchema, IssueReasonSchema, IssueScopeSchema, MarkformFrontmatterSchema, MockAgent, MultiCheckboxStateSchema, MultiSelectFieldSchema, MultiSelectValueSchema, NumberFieldSchema, NumberValueSchema, OptionIdSchema, OptionSchema, ParseError, PatchSchema, ProgressCountsSchema, ProgressStateSchema, ProgressSummarySchema, SessionFinalSchema, SessionTranscriptSchema, SessionTurnSchema, SetCheckboxesPatchSchema, SetMultiSelectPatchSchema, SetNumberPatchSchema, SetSingleSelectPatchSchema, SetStringListPatchSchema, SetStringPatchSchema, SeveritySchema, SimpleCheckboxStateSchema, SingleSelectFieldSchema, SingleSelectValueSchema, SourcePositionSchema, SourceRangeSchema, StepResultSchema, StringFieldSchema, StringListFieldSchema, StringListValueSchema, StringValueSchema, StructureSummarySchema, VERSION, ValidationIssueSchema, ValidatorRefSchema, applyPatches, coerceInputContext, coerceToFieldPatch, computeAllSummaries, computeFormState, computeProgressSummary, computeStructureSummary, createHarness, createMockAgent, fillForm, findFieldById, inspect, isFormComplete, isResearchForm, parseForm, parseSession, resolveHarnessConfig, runResearch, serialize, serializeSession, validate, validateResearchForm };
@@ -0,0 +1,110 @@
1
+ import { R as SessionTranscriptSchema } from "./coreTypes-Dful87E0.mjs";
2
+ import YAML from "yaml";
3
+
4
+ //#region src/engine/session.ts
5
+ /**
6
+ * Session module - parsing and serializing session transcripts.
7
+ *
8
+ * Session transcripts are used for golden testing and session replay.
9
+ * They capture the full interaction between the harness and agent.
10
+ */
11
+ /**
12
+ * Parse a session transcript from YAML string.
13
+ *
14
+ * Converts snake_case keys to camelCase for TypeScript consumption.
15
+ *
16
+ * @param yaml - YAML string containing session transcript
17
+ * @returns Parsed and validated SessionTranscript
18
+ * @throws Error if YAML is invalid or doesn't match schema
19
+ */
20
+ function parseSession(yaml) {
21
+ let raw;
22
+ try {
23
+ raw = YAML.parse(yaml);
24
+ } catch (err) {
25
+ throw new Error(`Failed to parse session YAML: ${err instanceof Error ? err.message : String(err)}`);
26
+ }
27
+ const converted = toCamelCaseDeep(raw);
28
+ const result = SessionTranscriptSchema.safeParse(converted);
29
+ if (!result.success) {
30
+ const errors = result.error.errors.map((e) => `${e.path.join(".")}: ${e.message}`).join("; ");
31
+ throw new Error(`Invalid session transcript: ${errors}`);
32
+ }
33
+ return result.data;
34
+ }
35
+ /**
36
+ * Serialize a session transcript to YAML string.
37
+ *
38
+ * Converts camelCase keys to snake_case for YAML output.
39
+ *
40
+ * @param session - Session transcript to serialize
41
+ * @returns YAML string
42
+ */
43
+ function serializeSession(session) {
44
+ const snakeCased = toSnakeCaseDeep(session);
45
+ return YAML.stringify(snakeCased, {
46
+ indent: 2,
47
+ lineWidth: 0
48
+ });
49
+ }
50
+ /**
51
+ * Convert a string from snake_case to camelCase.
52
+ */
53
+ function snakeToCamel(str) {
54
+ return str.replace(/_([a-z])/g, (_match, letter) => letter.toUpperCase());
55
+ }
56
+ /**
57
+ * Convert a string from camelCase to snake_case.
58
+ */
59
+ function camelToSnake(str) {
60
+ return str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
61
+ }
62
+ /**
63
+ * Recursively convert all object keys from snake_case to camelCase.
64
+ *
65
+ * Preserves keys that are user-defined identifiers (like option IDs in
66
+ * checkboxes `values` objects).
67
+ *
68
+ * @param obj - Object to convert
69
+ * @param preserveKeys - If true, don't convert keys in this object (but still recurse into values)
70
+ */
71
+ function toCamelCaseDeep(obj, preserveKeys = false) {
72
+ if (obj === null || obj === void 0) return obj;
73
+ if (Array.isArray(obj)) return obj.map((item) => toCamelCaseDeep(item, false));
74
+ if (typeof obj === "object") {
75
+ const result = {};
76
+ const record = obj;
77
+ for (const [key, value] of Object.entries(record)) {
78
+ const resultKey = preserveKeys ? key : snakeToCamel(key);
79
+ result[resultKey] = toCamelCaseDeep(value, key === "values" && record.op === "set_checkboxes");
80
+ }
81
+ return result;
82
+ }
83
+ return obj;
84
+ }
85
+ /**
86
+ * Recursively convert all object keys from camelCase to snake_case.
87
+ *
88
+ * Preserves keys that are user-defined identifiers (like option IDs in
89
+ * checkboxes `values` objects).
90
+ *
91
+ * @param obj - Object to convert
92
+ * @param preserveKeys - If true, don't convert keys in this object (but still recurse into values)
93
+ */
94
+ function toSnakeCaseDeep(obj, preserveKeys = false) {
95
+ if (obj === null || obj === void 0) return obj;
96
+ if (Array.isArray(obj)) return obj.map((item) => toSnakeCaseDeep(item, false));
97
+ if (typeof obj === "object") {
98
+ const result = {};
99
+ const record = obj;
100
+ for (const [key, value] of Object.entries(record)) {
101
+ const resultKey = preserveKeys ? key : camelToSnake(key);
102
+ result[resultKey] = toSnakeCaseDeep(value, key === "values" && record.op === "set_checkboxes");
103
+ }
104
+ return result;
105
+ }
106
+ return obj;
107
+ }
108
+
109
+ //#endregion
110
+ export { serializeSession as n, parseSession as t };
@@ -0,0 +1,4 @@
1
+ import "./coreTypes-Dful87E0.mjs";
2
+ import { n as serializeSession, t as parseSession } from "./session-Bqnwi9wp.mjs";
3
+
4
+ export { serializeSession };
@@ -0,0 +1,3 @@
1
+ import { a as getCommandContext, c as logInfo, d as logVerbose, f as logWarn, h as writeFile, i as formatPath, l as logSuccess, m as shouldUseColors, n as ensureFormsDir, o as logDryRun, p as readFile, r as formatOutput, s as logError, t as OUTPUT_FORMATS, u as logTiming } from "./shared-N_s1M-_K.mjs";
2
+
3
+ export { writeFile };