markform 0.1.4 → 0.1.6

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 (31) hide show
  1. package/README.md +110 -100
  2. package/dist/ai-sdk.d.mts +1 -1
  3. package/dist/ai-sdk.mjs +1 -1
  4. package/dist/{apply-C54EMAJ1.mjs → apply-DMQl-VVd.mjs} +6 -26
  5. package/dist/bin.mjs +4 -4
  6. package/dist/{cli-BhWhn6L9.mjs → cli-CXjkdym_.mjs} +83 -21
  7. package/dist/cli.mjs +4 -4
  8. package/dist/{coreTypes-cbNTYAcb.d.mts → coreTypes-9XZSNOv6.d.mts} +2 -2
  9. package/dist/index.d.mts +61 -7
  10. package/dist/index.mjs +2 -2
  11. package/dist/{shared-BqPnYXrn.mjs → shared-DRlgu2ZJ.mjs} +1 -1
  12. package/dist/{shared-CZsyShck.mjs → shared-u22MtBRo.mjs} +1 -1
  13. package/dist/{src-BNh7Cx9P.mjs → src-o_5TSoHQ.mjs} +105 -23
  14. package/docs/markform-apis.md +52 -1
  15. package/docs/markform-reference.md +19 -19
  16. package/docs/markform-spec.md +29 -20
  17. package/examples/earnings-analysis/earnings-analysis.form.md +86 -808
  18. package/examples/earnings-analysis/earnings-analysis.valid.ts +16 -148
  19. package/examples/movie-research/movie-research-basic.form.md +16 -16
  20. package/examples/movie-research/movie-research-deep.form.md +36 -36
  21. package/examples/movie-research/movie-research-minimal.form.md +4 -4
  22. package/examples/simple/simple-mock-filled.form.md +16 -16
  23. package/examples/simple/simple-skipped-filled.form.md +16 -16
  24. package/examples/simple/simple-with-skips.session.yaml +3 -3
  25. package/examples/simple/simple.form.md +16 -16
  26. package/examples/simple/simple.session.yaml +3 -3
  27. package/examples/startup-deep-research/startup-deep-research.form.md +22 -22
  28. package/examples/startup-research/startup-research-mock-filled.form.md +12 -12
  29. package/examples/startup-research/startup-research.form.md +12 -12
  30. package/package.json +1 -1
  31. package/examples/celebrity-deep-research/celebrity-deep-research.form.md +0 -967
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { $ as InspectIssue, $n as ValidationIssue, $t as SetStringListPatch, A as ExplicitCheckboxValueSchema, An as StringListValueSchema, At as ProgressState, B as FieldResponseSchema, Bn as TableRowPatchSchema, Bt as SessionTurn, C as DateValue, Cn as StepResult, Ct as OptionIdSchema, D as DocumentationTag, Dn as StringListField, Dt as PatchSchema, E as DocumentationBlockSchema, En as StringFieldSchema, Et as Patch, F as FieldKind, Fn as TableColumn, Ft as QualifiedOptionRef, G as FormSchema, Gn as UrlField, Gt as SetDatePatch, H as FieldValue, Hn as TableRowResponseSchema, Ht as SessionTurnStats, I as FieldKindSchema, In as TableColumnSchema, It as SessionFinal, J as HarnessConfig, Jn as UrlListFieldSchema, Jt as SetMultiSelectPatchSchema, K as FormSchemaSchema, Kn as UrlFieldSchema, Kt as SetDatePatchSchema, L as FieldProgress, Ln as TableField, Lt as SessionFinalSchema, M as FieldBase, Mn as StringValueSchema, Mt as ProgressSummary, N as FieldGroup, Nn as StructureSummary, Nt as ProgressSummarySchema, O as DocumentationTagSchema, On as StringListFieldSchema, Ot as ProgressCounts, P as FieldGroupSchema, Pn as StructureSummarySchema, Pt as QualifiedColumnRef, Q as IdSchema, Qn as UrlValueSchema, Qt as SetSingleSelectPatchSchema, R as FieldProgressSchema, Rn as TableFieldSchema, Rt as SessionTranscript, S as DateFieldSchema, Sn as SourceRangeSchema, St as OptionId, T as DocumentationBlock, Tn as StringField, Tt as ParsedForm, U as FieldValueSchema, Un as TableValue, Ut as SetCheckboxesPatch, V as FieldSchema, Vn as TableRowResponse, Vt as SessionTurnSchema, W as FillMode, Wn as TableValueSchema, Wt as SetCheckboxesPatchSchema, X as Id, Xn as UrlListValueSchema, Xt as SetNumberPatchSchema, Y as HarnessConfigSchema, Yn as UrlListValue, Yt as SetNumberPatch, Z as IdIndexEntry, Zn as UrlValue, Zt as SetSingleSelectPatch, _ as ClearFieldPatch, _n as SingleSelectValue, _t as NumberField, a as CellResponse, an as SetUrlListPatch, ar as ValidatorRegistry, at as IssueScope, b as ColumnTypeNameSchema, bn as SourcePositionSchema, bt as NumberValueSchema, c as CheckboxModeSchema, cn as SetUrlPatchSchema, cr as YearValue, ct as MarkformFrontmatterSchema, d as CheckboxValue, dn as Severity, dt as MultiSelectField, en as SetStringListPatchSchema, er as ValidationIssueSchema, et as InspectIssueSchema, f as CheckboxValueSchema, fn as SeveritySchema, ft as MultiSelectFieldSchema, g as CheckboxesValueSchema, gn as SingleSelectFieldSchema, gt as Note, h as CheckboxesValue, hn as SingleSelectField, ht as NodeType, i as ApplyResultSchema, in as SetTablePatchSchema, ir as ValidatorRefSchema, it as IssueReasonSchema, j as Field, jn as StringValue, jt as ProgressStateSchema, k as ExplicitCheckboxValue, kn as StringListValue, kt as ProgressCountsSchema, l as CheckboxProgressCounts, ln as SetYearPatch, lr as YearValueSchema, lt as MultiCheckboxState, m as CheckboxesFieldSchema, mn as SimpleCheckboxStateSchema, mt as MultiSelectValueSchema, n as AnswerStateSchema, nn as SetStringPatchSchema, nr as ValidatorFn, nt as InspectResultSchema, o as CellResponseSchema, on as SetUrlListPatchSchema, or as YearField, ot as IssueScopeSchema, p as CheckboxesField, pn as SimpleCheckboxState, pt as MultiSelectValue, q as FrontmatterHarnessConfig, qn as UrlListField, qt as SetMultiSelectPatch, r as ApplyResult, rn as SetTablePatch, rr as ValidatorRef, rt as IssueReason, s as CheckboxMode, sn as SetUrlPatch, sr as YearFieldSchema, st as MarkformFrontmatter, t as AnswerState, tn as SetStringPatch, tr as ValidatorContext, tt as InspectResult, u as CheckboxProgressCountsSchema, un as SetYearPatchSchema, ut as MultiCheckboxStateSchema, v as ClearFieldPatchSchema, vn as SingleSelectValueSchema, vt as NumberFieldSchema, w as DateValueSchema, wn as StepResultSchema, wt as OptionSchema, x as DateField, xn as SourceRange, xt as Option, y as ColumnTypeName, yn as SourcePosition, yt as NumberValue, z as FieldResponse, zn as TableRowPatch, zt as SessionTranscriptSchema } from "./coreTypes-cbNTYAcb.mjs";
3
+ import { $ as InspectIssue, $n as ValidationIssue, $t as SetStringListPatch, A as ExplicitCheckboxValueSchema, An as StringListValueSchema, At as ProgressState, B as FieldResponseSchema, Bn as TableRowPatchSchema, Bt as SessionTurn, C as DateValue, Cn as StepResult, Ct as OptionIdSchema, D as DocumentationTag, Dn as StringListField, Dt as PatchSchema, E as DocumentationBlockSchema, En as StringFieldSchema, Et as Patch, F as FieldKind, Fn as TableColumn, Ft as QualifiedOptionRef, G as FormSchema, Gn as UrlField, Gt as SetDatePatch, H as FieldValue, Hn as TableRowResponseSchema, Ht as SessionTurnStats, I as FieldKindSchema, In as TableColumnSchema, It as SessionFinal, J as HarnessConfig, Jn as UrlListFieldSchema, Jt as SetMultiSelectPatchSchema, K as FormSchemaSchema, Kn as UrlFieldSchema, Kt as SetDatePatchSchema, L as FieldProgress, Ln as TableField, Lt as SessionFinalSchema, M as FieldBase, Mn as StringValueSchema, Mt as ProgressSummary, N as FieldGroup, Nn as StructureSummary, Nt as ProgressSummarySchema, O as DocumentationTagSchema, On as StringListFieldSchema, Ot as ProgressCounts, P as FieldGroupSchema, Pn as StructureSummarySchema, Pt as QualifiedColumnRef, Q as IdSchema, Qn as UrlValueSchema, Qt as SetSingleSelectPatchSchema, R as FieldProgressSchema, Rn as TableFieldSchema, Rt as SessionTranscript, S as DateFieldSchema, Sn as SourceRangeSchema, St as OptionId, T as DocumentationBlock, Tn as StringField, Tt as ParsedForm, U as FieldValueSchema, Un as TableValue, Ut as SetCheckboxesPatch, V as FieldSchema, Vn as TableRowResponse, Vt as SessionTurnSchema, W as FillMode, Wn as TableValueSchema, Wt as SetCheckboxesPatchSchema, X as Id, Xn as UrlListValueSchema, Xt as SetNumberPatchSchema, Y as HarnessConfigSchema, Yn as UrlListValue, Yt as SetNumberPatch, Z as IdIndexEntry, Zn as UrlValue, Zt as SetSingleSelectPatch, _ as ClearFieldPatch, _n as SingleSelectValue, _t as NumberField, a as CellResponse, an as SetUrlListPatch, ar as ValidatorRegistry, at as IssueScope, b as ColumnTypeNameSchema, bn as SourcePositionSchema, bt as NumberValueSchema, c as CheckboxModeSchema, cn as SetUrlPatchSchema, cr as YearValue, ct as MarkformFrontmatterSchema, d as CheckboxValue, dn as Severity, dt as MultiSelectField, en as SetStringListPatchSchema, er as ValidationIssueSchema, et as InspectIssueSchema, f as CheckboxValueSchema, fn as SeveritySchema, ft as MultiSelectFieldSchema, g as CheckboxesValueSchema, gn as SingleSelectFieldSchema, gt as Note, h as CheckboxesValue, hn as SingleSelectField, ht as NodeType, i as ApplyResultSchema, in as SetTablePatchSchema, ir as ValidatorRefSchema, it as IssueReasonSchema, j as Field, jn as StringValue, jt as ProgressStateSchema, k as ExplicitCheckboxValue, kn as StringListValue, kt as ProgressCountsSchema, l as CheckboxProgressCounts, ln as SetYearPatch, lr as YearValueSchema, lt as MultiCheckboxState, m as CheckboxesFieldSchema, mn as SimpleCheckboxStateSchema, mt as MultiSelectValueSchema, n as AnswerStateSchema, nn as SetStringPatchSchema, nr as ValidatorFn, nt as InspectResultSchema, o as CellResponseSchema, on as SetUrlListPatchSchema, or as YearField, ot as IssueScopeSchema, p as CheckboxesField, pn as SimpleCheckboxState, pt as MultiSelectValue, q as FrontmatterHarnessConfig, qn as UrlListField, qt as SetMultiSelectPatch, r as ApplyResult, rn as SetTablePatch, rr as ValidatorRef, rt as IssueReason, s as CheckboxMode, sn as SetUrlPatch, sr as YearFieldSchema, st as MarkformFrontmatter, t as AnswerState, tn as SetStringPatch, tr as ValidatorContext, tt as InspectResult, u as CheckboxProgressCountsSchema, un as SetYearPatchSchema, ut as MultiCheckboxStateSchema, v as ClearFieldPatchSchema, vn as SingleSelectValueSchema, vt as NumberFieldSchema, w as DateValueSchema, wn as StepResultSchema, wt as OptionSchema, x as DateField, xn as SourceRange, xt as Option, y as ColumnTypeName, yn as SourcePosition, yt as NumberValue, z as FieldResponse, zn as TableRowPatch, zt as SessionTranscriptSchema } from "./coreTypes-9XZSNOv6.mjs";
4
4
  import "@markdoc/markdoc";
5
5
  import { LanguageModel, Tool } from "ai";
6
6
 
@@ -519,6 +519,57 @@ interface Agent {
519
519
  */
520
520
  generatePatches(issues: InspectIssue[], form: ParsedForm, maxPatches: number): Promise<AgentResponse>;
521
521
  }
522
+ /**
523
+ * Callbacks for observing form-filling execution in real-time.
524
+ *
525
+ * All callbacks are optional - implement only what you need.
526
+ * Callback errors are caught and ignored (won't abort fill).
527
+ *
528
+ * @example
529
+ * ```typescript
530
+ * await fillForm({
531
+ * form: formMarkdown,
532
+ * model: 'anthropic/claude-sonnet-4-5',
533
+ * enableWebSearch: true,
534
+ * callbacks: {
535
+ * onTurnStart: ({ turnNumber }) => console.log(`Starting turn ${turnNumber}`),
536
+ * onToolStart: ({ name }) => spinner.message(`🔧 ${name}...`),
537
+ * onTurnComplete: (progress) => console.log(`Turn ${progress.turnNumber} done`),
538
+ * },
539
+ * });
540
+ * ```
541
+ */
542
+ interface FillCallbacks {
543
+ /** Called when a turn begins */
544
+ onTurnStart?(turn: {
545
+ turnNumber: number;
546
+ issuesCount: number;
547
+ }): void;
548
+ /** Called when a turn completes */
549
+ onTurnComplete?(progress: TurnProgress): void;
550
+ /** Called before a tool executes */
551
+ onToolStart?(call: {
552
+ name: string;
553
+ input: unknown;
554
+ }): void;
555
+ /** Called after a tool completes */
556
+ onToolEnd?(call: {
557
+ name: string;
558
+ output: unknown;
559
+ durationMs: number;
560
+ error?: string;
561
+ }): void;
562
+ /** Called before an LLM request */
563
+ onLlmCallStart?(call: {
564
+ model: string;
565
+ }): void;
566
+ /** Called after an LLM response */
567
+ onLlmCallEnd?(call: {
568
+ model: string;
569
+ inputTokens: number;
570
+ outputTokens: number;
571
+ }): void;
572
+ }
522
573
  /**
523
574
  * Options for the fillForm function.
524
575
  */
@@ -544,8 +595,8 @@ interface FillOptions {
544
595
  targetRoles?: string[];
545
596
  /** Fill mode: 'continue' (skip filled) or 'overwrite' (re-fill) */
546
597
  fillMode?: FillMode;
547
- /** Progress callback called after each turn */
548
- onTurnComplete?: (progress: TurnProgress) => void;
598
+ /** Callbacks for observing form-filling execution */
599
+ callbacks?: FillCallbacks;
549
600
  /** AbortSignal for cancellation */
550
601
  signal?: AbortSignal;
551
602
  /**
@@ -673,6 +724,7 @@ declare function createMockAgent(completedForm: ParsedForm): MockAgent;
673
724
  * const result = await fillForm({
674
725
  * form: formMarkdown,
675
726
  * model: 'anthropic/claude-sonnet-4-5',
727
+ * enableWebSearch: true,
676
728
  * inputContext: {
677
729
  * company_name: 'Apple Inc.',
678
730
  * },
@@ -680,8 +732,10 @@ declare function createMockAgent(completedForm: ParsedForm): MockAgent;
680
732
  * ## Additional Context
681
733
  * ${backgroundInfo}
682
734
  * `,
683
- * onTurnComplete: (progress) => {
684
- * console.log(`Turn ${progress.turnNumber}: ${progress.requiredIssuesRemaining} remaining`);
735
+ * callbacks: {
736
+ * onTurnComplete: (progress) => {
737
+ * console.log(`Turn ${progress.turnNumber}: ${progress.requiredIssuesRemaining} remaining`);
738
+ * },
685
739
  * },
686
740
  * });
687
741
  *
@@ -791,7 +845,7 @@ declare function validateResearchForm(form: ParsedForm): {
791
845
  * This is the main library entry point that exports the core engine,
792
846
  * types, and utilities for working with .form.md files.
793
847
  */
794
- /** Markform version (read from package.json). */
848
+ /** Markform version (injected at build time). */
795
849
  declare const VERSION: string;
796
850
  //#endregion
797
- export { type AgentResponse, type AnswerState, AnswerStateSchema, type ApplyResult, ApplyResultSchema, type CellResponse, CellResponseSchema, type CellScopeRef, type CheckboxMode, CheckboxModeSchema, type CheckboxProgressCounts, CheckboxProgressCountsSchema, type CheckboxValue, CheckboxValueSchema, type CheckboxesField, CheckboxesFieldSchema, type CheckboxesValue, CheckboxesValueSchema, type ClearFieldPatch, ClearFieldPatchSchema, type CoerceInputContextResult, type CoercionResult, type ColumnTypeName, ColumnTypeNameSchema, type ComputedSummaries, type DateField, DateFieldSchema, type DateValue, DateValueSchema, 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 FieldScopeRef, 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 ParseScopeRefResult, type ParseTableResult, type ParsedForm, type ParsedRawTable, type ParsedScopeRef, type Patch, PatchSchema, type ProgressCounts, ProgressCountsSchema, type ProgressState, ProgressStateSchema, type ProgressSummary, ProgressSummarySchema, type QualifiedColumnRef, type QualifiedOptionRef, type QualifiedScopeRef, 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 SetDatePatch, SetDatePatchSchema, type SetMultiSelectPatch, SetMultiSelectPatchSchema, type SetNumberPatch, SetNumberPatchSchema, type SetSingleSelectPatch, SetSingleSelectPatchSchema, type SetStringListPatch, SetStringListPatchSchema, type SetStringPatch, SetStringPatchSchema, type SetTablePatch, SetTablePatchSchema, type SetUrlListPatch, SetUrlListPatchSchema, type SetUrlPatch, SetUrlPatchSchema, type SetYearPatch, SetYearPatchSchema, 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 TableColumn, TableColumnSchema, type TableField, TableFieldSchema, type TableRowPatch, TableRowPatchSchema, type TableRowResponse, TableRowResponseSchema, type TableValue, TableValueSchema, type TurnProgress, type TurnStats, type UrlField, UrlFieldSchema, type UrlListField, UrlListFieldSchema, type UrlListValue, UrlListValueSchema, type UrlValue, UrlValueSchema, VERSION, type ValidateOptions, type ValidateResult, type ValidationIssue, ValidationIssueSchema, type ValidatorContext, type ValidatorFn, type ValidatorRef, ValidatorRefSchema, type ValidatorRegistry, type YearField, YearFieldSchema, type YearValue, YearValueSchema, applyPatches, coerceInputContext, coerceToFieldPatch, computeAllSummaries, computeFormState, computeProgressSummary, computeStructureSummary, createHarness, createMockAgent, fillForm, findFieldById, getFieldId, inspect, isCellRef, isFieldRef, isFormComplete, isQualifiedRef, isResearchForm, parseCellValue, parseForm, parseMarkdownTable, parseRawTable, parseScopeRef, parseSession, resolveHarnessConfig, runResearch, serialize, serializeScopeRef, serializeSession, validate, validateResearchForm };
851
+ export { type AgentResponse, type AnswerState, AnswerStateSchema, type ApplyResult, ApplyResultSchema, type CellResponse, CellResponseSchema, type CellScopeRef, type CheckboxMode, CheckboxModeSchema, type CheckboxProgressCounts, CheckboxProgressCountsSchema, type CheckboxValue, CheckboxValueSchema, type CheckboxesField, CheckboxesFieldSchema, type CheckboxesValue, CheckboxesValueSchema, type ClearFieldPatch, ClearFieldPatchSchema, type CoerceInputContextResult, type CoercionResult, type ColumnTypeName, ColumnTypeNameSchema, type ComputedSummaries, type DateField, DateFieldSchema, type DateValue, DateValueSchema, 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 FieldScopeRef, type FieldValue, FieldValueSchema, type FillCallbacks, 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 ParseScopeRefResult, type ParseTableResult, type ParsedForm, type ParsedRawTable, type ParsedScopeRef, type Patch, PatchSchema, type ProgressCounts, ProgressCountsSchema, type ProgressState, ProgressStateSchema, type ProgressSummary, ProgressSummarySchema, type QualifiedColumnRef, type QualifiedOptionRef, type QualifiedScopeRef, 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 SetDatePatch, SetDatePatchSchema, type SetMultiSelectPatch, SetMultiSelectPatchSchema, type SetNumberPatch, SetNumberPatchSchema, type SetSingleSelectPatch, SetSingleSelectPatchSchema, type SetStringListPatch, SetStringListPatchSchema, type SetStringPatch, SetStringPatchSchema, type SetTablePatch, SetTablePatchSchema, type SetUrlListPatch, SetUrlListPatchSchema, type SetUrlPatch, SetUrlPatchSchema, type SetYearPatch, SetYearPatchSchema, 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 TableColumn, TableColumnSchema, type TableField, TableFieldSchema, type TableRowPatch, TableRowPatchSchema, type TableRowResponse, TableRowResponseSchema, type TableValue, TableValueSchema, type TurnProgress, type TurnStats, type UrlField, UrlFieldSchema, type UrlListField, UrlListFieldSchema, type UrlListValue, UrlListValueSchema, type UrlValue, UrlValueSchema, VERSION, type ValidateOptions, type ValidateResult, type ValidationIssue, ValidationIssueSchema, type ValidatorContext, type ValidatorFn, type ValidatorRef, ValidatorRefSchema, type ValidatorRegistry, type YearField, YearFieldSchema, type YearValue, YearValueSchema, applyPatches, coerceInputContext, coerceToFieldPatch, computeAllSummaries, computeFormState, computeProgressSummary, computeStructureSummary, createHarness, createMockAgent, fillForm, findFieldById, getFieldId, inspect, isCellRef, isFieldRef, isFormComplete, isQualifiedRef, isResearchForm, parseCellValue, parseForm, parseMarkdownTable, parseRawTable, parseScopeRef, parseSession, resolveHarnessConfig, runResearch, serialize, serializeScopeRef, serializeSession, validate, validateResearchForm };
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { $ as SetUrlPatchSchema, A as MultiCheckboxStateSchema, B as ProgressSummarySchema, C as HarnessConfigSchema, Ct as ValidatorRefSchema, D as IssueReasonSchema, E as InspectResultSchema, F as OptionIdSchema, G as SetDatePatchSchema, H as SessionTranscriptSchema, I as OptionSchema, J as SetSingleSelectPatchSchema, K as SetMultiSelectPatchSchema, L as PatchSchema, M as MultiSelectValueSchema, N as NumberFieldSchema, O as IssueScopeSchema, P as NumberValueSchema, Q as SetUrlListPatchSchema, R as ProgressCountsSchema, S as FormSchemaSchema, St as ValidationIssueSchema, T as InspectIssueSchema, Tt as YearValueSchema, U as SessionTurnSchema, V as SessionFinalSchema, W as SetCheckboxesPatchSchema, X as SetStringPatchSchema, Y as SetStringListPatchSchema, Z as SetTablePatchSchema, _ as FieldKindSchema, _t as TableValueSchema, a as CheckboxProgressCountsSchema, at as SourcePositionSchema, b as FieldSchema, bt as UrlListValueSchema, c as CheckboxesValueSchema, ct as StringFieldSchema, d as DateFieldSchema, dt as StringValueSchema, et as SetYearPatchSchema, f as DateValueSchema, ft as StructureSummarySchema, g as FieldGroupSchema, gt as TableRowResponseSchema, h as ExplicitCheckboxValueSchema, ht as TableRowPatchSchema, i as CheckboxModeSchema, it as SingleSelectValueSchema, j as MultiSelectFieldSchema, k as MarkformFrontmatterSchema, l as ClearFieldPatchSchema, lt as StringListFieldSchema, m as DocumentationTagSchema, mt as TableFieldSchema, n as ApplyResultSchema, nt as SimpleCheckboxStateSchema, o as CheckboxValueSchema, ot as SourceRangeSchema, p as DocumentationBlockSchema, pt as TableColumnSchema, q as SetNumberPatchSchema, r as CellResponseSchema, rt as SingleSelectFieldSchema, s as CheckboxesFieldSchema, st as StepResultSchema, t as AnswerStateSchema, tt as SeveritySchema, u as ColumnTypeNameSchema, ut as StringListValueSchema, v as FieldProgressSchema, vt as UrlFieldSchema, w as IdSchema, wt as YearFieldSchema, x as FieldValueSchema, xt as UrlValueSchema, y as FieldResponseSchema, yt as UrlListFieldSchema, z as ProgressStateSchema } from "./coreTypes-pyctKRgc.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-C54EMAJ1.mjs";
3
- import { C as serializeScopeRef, D as parseRawTable, E as parseMarkdownTable, O as ParseError, S as parseScopeRef, T as parseCellValue, _ as findFieldById, a as resolveHarnessConfig, b as isFieldRef, 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 getFieldId, w as parseForm, x as isQualifiedRef, y as isCellRef } from "./src-BNh7Cx9P.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-DMQl-VVd.mjs";
3
+ import { C as serializeScopeRef, D as parseRawTable, E as parseMarkdownTable, O as ParseError, S as parseScopeRef, T as parseCellValue, _ as findFieldById, a as resolveHarnessConfig, b as isFieldRef, 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 getFieldId, w as parseForm, x as isQualifiedRef, y as isCellRef } from "./src-o_5TSoHQ.mjs";
4
4
  import { n as serializeSession, t as parseSession } from "./session-uF0e6m6k.mjs";
5
5
 
6
6
  export { AnswerStateSchema, ApplyResultSchema, CellResponseSchema, CheckboxModeSchema, CheckboxProgressCountsSchema, CheckboxValueSchema, CheckboxesFieldSchema, CheckboxesValueSchema, ClearFieldPatchSchema, ColumnTypeNameSchema, DateFieldSchema, DateValueSchema, 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, SetDatePatchSchema, SetMultiSelectPatchSchema, SetNumberPatchSchema, SetSingleSelectPatchSchema, SetStringListPatchSchema, SetStringPatchSchema, SetTablePatchSchema, SetUrlListPatchSchema, SetUrlPatchSchema, SetYearPatchSchema, SeveritySchema, SimpleCheckboxStateSchema, SingleSelectFieldSchema, SingleSelectValueSchema, SourcePositionSchema, SourceRangeSchema, StepResultSchema, StringFieldSchema, StringListFieldSchema, StringListValueSchema, StringValueSchema, StructureSummarySchema, TableColumnSchema, TableFieldSchema, TableRowPatchSchema, TableRowResponseSchema, TableValueSchema, UrlFieldSchema, UrlListFieldSchema, UrlListValueSchema, UrlValueSchema, VERSION, ValidationIssueSchema, ValidatorRefSchema, YearFieldSchema, YearValueSchema, applyPatches, coerceInputContext, coerceToFieldPatch, computeAllSummaries, computeFormState, computeProgressSummary, computeStructureSummary, createHarness, createMockAgent, fillForm, findFieldById, getFieldId, inspect, isCellRef, isFieldRef, isFormComplete, isQualifiedRef, isResearchForm, parseCellValue, parseForm, parseMarkdownTable, parseRawTable, parseScopeRef, parseSession, resolveHarnessConfig, runResearch, serialize, serializeScopeRef, serializeSession, validate, validateResearchForm };
@@ -1,6 +1,6 @@
1
1
  import YAML from "yaml";
2
- import { relative } from "node:path";
3
2
  import pc from "picocolors";
3
+ import { relative } from "node:path";
4
4
  import { mkdir } from "node:fs/promises";
5
5
  import * as p from "@clack/prompts";
6
6
 
@@ -1,3 +1,3 @@
1
- import { a as formatPath, c as logError, d as logTiming, f as logVerbose, g as writeFile, h as shouldUseColors, i as formatOutput, l as logInfo, m as readFile, n as createSpinner, o as getCommandContext, p as logWarn, r as ensureFormsDir, s as logDryRun, t as OUTPUT_FORMATS, u as logSuccess } from "./shared-BqPnYXrn.mjs";
1
+ import { a as formatPath, c as logError, d as logTiming, f as logVerbose, g as writeFile, h as shouldUseColors, i as formatOutput, l as logInfo, m as readFile, n as createSpinner, o as getCommandContext, p as logWarn, r as ensureFormsDir, s as logDryRun, t as OUTPUT_FORMATS, u as logSuccess } from "./shared-DRlgu2ZJ.mjs";
2
2
 
3
3
  export { writeFile };
@@ -1,6 +1,5 @@
1
1
  import { L as PatchSchema } from "./coreTypes-pyctKRgc.mjs";
2
- import { C as DEFAULT_ROLE_INSTRUCTIONS, P as getWebSearchConfig, S as DEFAULT_ROLES, _ as DEFAULT_MAX_TURNS, b as DEFAULT_RESEARCH_MAX_ISSUES_PER_TURN, g as DEFAULT_MAX_PATCHES_PER_TURN, h as DEFAULT_MAX_ISSUES_PER_TURN, n as getFieldsForRoles, p as AGENT_ROLE, r as inspect, t as applyPatches, u as serialize, x as DEFAULT_RESEARCH_MAX_PATCHES_PER_TURN, y as DEFAULT_PRIORITY } from "./apply-C54EMAJ1.mjs";
3
- import { createRequire } from "node:module";
2
+ import { C as DEFAULT_ROLE_INSTRUCTIONS, N as getWebSearchConfig, S as DEFAULT_ROLES, _ as DEFAULT_MAX_TURNS, b as DEFAULT_RESEARCH_MAX_ISSUES_PER_TURN, g as DEFAULT_MAX_PATCHES_PER_TURN, h as DEFAULT_MAX_ISSUES_PER_TURN, n as getFieldsForRoles, p as AGENT_ROLE, r as inspect, t as applyPatches, u as serialize, x as DEFAULT_RESEARCH_MAX_PATCHES_PER_TURN, y as DEFAULT_PRIORITY } from "./apply-DMQl-VVd.mjs";
4
3
  import { z } from "zod";
5
4
  import Markdoc from "@markdoc/markdoc";
6
5
  import YAML from "yaml";
@@ -1169,6 +1168,18 @@ function parseField(node) {
1169
1168
  *
1170
1169
  * Parses Markdoc documents and extracts form schema, values, and documentation blocks.
1171
1170
  */
1171
+ /**
1172
+ * Valid tag names inside a form.
1173
+ * Any other tag will produce a ParseError.
1174
+ */
1175
+ const VALID_FORM_TAGS = new Set([
1176
+ "group",
1177
+ "field",
1178
+ "note",
1179
+ "description",
1180
+ "instructions",
1181
+ "documentation"
1182
+ ]);
1172
1183
  const FRONTMATTER_REGEX = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?/;
1173
1184
  /**
1174
1185
  * Parse harness configuration from frontmatter.
@@ -1227,14 +1238,14 @@ function extractFrontmatter(content) {
1227
1238
  }
1228
1239
  }
1229
1240
  /**
1230
- * Parse a field-group tag.
1241
+ * Parse a group tag.
1231
1242
  */
1232
1243
  function parseFieldGroup(node, responsesByFieldId, orderIndex, idIndex, parentId) {
1233
1244
  const id = getStringAttr(node, "id");
1234
1245
  const title = getStringAttr(node, "title");
1235
- if (!id) throw new ParseError("field-group missing required 'id' attribute");
1246
+ if (!id) throw new ParseError("group missing required 'id' attribute");
1236
1247
  if (idIndex.has(id)) throw new ParseError(`Duplicate ID '${id}'`);
1237
- if (getStringAttr(node, "state") !== void 0) throw new ParseError(`Field-group '${id}' has state attribute. state attribute is not allowed on field-groups.`);
1248
+ if (getStringAttr(node, "state") !== void 0) throw new ParseError(`Field-group '${id}' has state attribute. state attribute is not allowed on groups.`);
1238
1249
  idIndex.set(id, {
1239
1250
  nodeType: "group",
1240
1251
  parentId
@@ -1275,7 +1286,7 @@ function parseFieldGroup(node, responsesByFieldId, orderIndex, idIndex, parentId
1275
1286
  }
1276
1287
  /**
1277
1288
  * Parse a form tag.
1278
- * Handles both explicit field-groups and fields placed directly under the form.
1289
+ * Handles both explicit groups and fields placed directly under the form.
1279
1290
  */
1280
1291
  function parseFormTag(node, responsesByFieldId, orderIndex, idIndex) {
1281
1292
  const id = getStringAttr(node, "id");
@@ -1287,7 +1298,8 @@ function parseFormTag(node, responsesByFieldId, orderIndex, idIndex) {
1287
1298
  const ungroupedFields = [];
1288
1299
  function processContent(child) {
1289
1300
  if (!child || typeof child !== "object") return;
1290
- if (isTagNode(child, "field-group")) {
1301
+ if (isTagNode(child) && !VALID_FORM_TAGS.has(child.tag)) throw new ParseError(`Unknown tag '${child.tag}' inside form`);
1302
+ if (isTagNode(child, "group")) {
1291
1303
  const group = parseFieldGroup(child, responsesByFieldId, orderIndex, idIndex, id);
1292
1304
  groups.push(group);
1293
1305
  return;
@@ -7600,6 +7612,7 @@ var LiveAgent = class {
7600
7612
  enableWebSearch;
7601
7613
  webSearchTools = null;
7602
7614
  additionalTools;
7615
+ callbacks;
7603
7616
  constructor(config) {
7604
7617
  this.model = config.model;
7605
7618
  this.maxStepsPerTurn = config.maxStepsPerTurn ?? 3;
@@ -7608,6 +7621,7 @@ var LiveAgent = class {
7608
7621
  this.provider = config.provider;
7609
7622
  this.enableWebSearch = config.enableWebSearch;
7610
7623
  this.additionalTools = config.additionalTools ?? {};
7624
+ this.callbacks = config.callbacks;
7611
7625
  if (this.enableWebSearch && this.provider) this.webSearchTools = loadWebSearchTools(this.provider);
7612
7626
  }
7613
7627
  /**
@@ -7633,14 +7647,18 @@ var LiveAgent = class {
7633
7647
  if (this.systemPromptAddition) systemPrompt += "\n\n# Additional Context\n" + this.systemPromptAddition;
7634
7648
  if (this.enableWebSearch && this.provider && !this.webSearchTools) this.webSearchTools = loadWebSearchTools(this.provider);
7635
7649
  if (this.webSearchTools && Object.keys(this.webSearchTools).length > 0) systemPrompt += "\n\n" + WEB_SEARCH_INSTRUCTIONS;
7636
- const tools = {
7650
+ const tools = wrapToolsWithCallbacks({
7637
7651
  generatePatches: {
7638
7652
  description: GENERATE_PATCHES_TOOL_DESCRIPTION,
7639
7653
  inputSchema: zodSchema(z.object({ patches: z.array(PatchSchema).max(maxPatches).describe("Array of patches. Each patch sets a value for one field.") }))
7640
7654
  },
7641
7655
  ...this.webSearchTools,
7642
7656
  ...this.additionalTools
7643
- };
7657
+ }, this.callbacks);
7658
+ const modelId = this.model.modelId ?? "unknown";
7659
+ if (this.callbacks?.onLlmCallStart) try {
7660
+ this.callbacks.onLlmCallStart({ model: modelId });
7661
+ } catch {}
7644
7662
  const result = await generateText({
7645
7663
  model: this.model,
7646
7664
  system: systemPrompt,
@@ -7648,6 +7666,13 @@ var LiveAgent = class {
7648
7666
  tools,
7649
7667
  stopWhen: stepCountIs(this.maxStepsPerTurn)
7650
7668
  });
7669
+ if (this.callbacks?.onLlmCallEnd) try {
7670
+ this.callbacks.onLlmCallEnd({
7671
+ model: modelId,
7672
+ inputTokens: result.usage?.inputTokens ?? 0,
7673
+ outputTokens: result.usage?.outputTokens ?? 0
7674
+ });
7675
+ } catch {}
7651
7676
  const patches = [];
7652
7677
  const toolCallCounts = /* @__PURE__ */ new Map();
7653
7678
  for (const step of result.steps) for (const toolCall of step.toolCalls) {
@@ -7784,6 +7809,60 @@ function findField(form, fieldId) {
7784
7809
  return null;
7785
7810
  }
7786
7811
  /**
7812
+ * Wrap tools with callbacks for observability.
7813
+ *
7814
+ * Only wraps tools that have an execute function.
7815
+ * Declarative tools (schema only) are passed through unchanged.
7816
+ */
7817
+ function wrapToolsWithCallbacks(tools, callbacks) {
7818
+ if (!callbacks?.onToolStart && !callbacks?.onToolEnd) return tools;
7819
+ const wrapped = {};
7820
+ for (const [name$2, tool$1] of Object.entries(tools)) {
7821
+ const execute = tool$1.execute;
7822
+ if (typeof execute === "function") wrapped[name$2] = wrapTool(name$2, tool$1, execute, callbacks);
7823
+ else wrapped[name$2] = tool$1;
7824
+ }
7825
+ return wrapped;
7826
+ }
7827
+ /**
7828
+ * Wrap a single tool with callbacks.
7829
+ */
7830
+ function wrapTool(name$2, tool$1, originalExecute, callbacks) {
7831
+ return {
7832
+ ...tool$1,
7833
+ execute: async (input) => {
7834
+ const startTime = Date.now();
7835
+ if (callbacks.onToolStart) try {
7836
+ callbacks.onToolStart({
7837
+ name: name$2,
7838
+ input
7839
+ });
7840
+ } catch {}
7841
+ try {
7842
+ const output = await originalExecute(input);
7843
+ if (callbacks.onToolEnd) try {
7844
+ callbacks.onToolEnd({
7845
+ name: name$2,
7846
+ output,
7847
+ durationMs: Date.now() - startTime
7848
+ });
7849
+ } catch {}
7850
+ return output;
7851
+ } catch (error) {
7852
+ if (callbacks.onToolEnd) try {
7853
+ callbacks.onToolEnd({
7854
+ name: name$2,
7855
+ output: null,
7856
+ durationMs: Date.now() - startTime,
7857
+ error: error instanceof Error ? error.message : String(error)
7858
+ });
7859
+ } catch {}
7860
+ throw error;
7861
+ }
7862
+ }
7863
+ };
7864
+ }
7865
+ /**
7787
7866
  * Load web search tools for a provider.
7788
7867
  * Uses centralized config from llms.ts.
7789
7868
  */
@@ -7981,6 +8060,7 @@ function buildResult(form, turns, totalPatches, status, inputContextWarnings, re
7981
8060
  * const result = await fillForm({
7982
8061
  * form: formMarkdown,
7983
8062
  * model: 'anthropic/claude-sonnet-4-5',
8063
+ * enableWebSearch: true,
7984
8064
  * inputContext: {
7985
8065
  * company_name: 'Apple Inc.',
7986
8066
  * },
@@ -7988,8 +8068,10 @@ function buildResult(form, turns, totalPatches, status, inputContextWarnings, re
7988
8068
  * ## Additional Context
7989
8069
  * ${backgroundInfo}
7990
8070
  * `,
7991
- * onTurnComplete: (progress) => {
7992
- * console.log(`Turn ${progress.turnNumber}: ${progress.requiredIssuesRemaining} remaining`);
8071
+ * callbacks: {
8072
+ * onTurnComplete: (progress) => {
8073
+ * console.log(`Turn ${progress.turnNumber}: ${progress.requiredIssuesRemaining} remaining`);
8074
+ * },
7993
8075
  * },
7994
8076
  * });
7995
8077
  *
@@ -8066,7 +8148,8 @@ async function fillForm(options) {
8066
8148
  targetRole: targetRoles[0] ?? AGENT_ROLE,
8067
8149
  provider,
8068
8150
  enableWebSearch: options.enableWebSearch,
8069
- additionalTools: options.additionalTools
8151
+ additionalTools: options.additionalTools,
8152
+ callbacks: options.callbacks
8070
8153
  });
8071
8154
  let turnCount = 0;
8072
8155
  let stepResult = harness.step();
@@ -8075,6 +8158,12 @@ async function fillForm(options) {
8075
8158
  ok: false,
8076
8159
  reason: "cancelled"
8077
8160
  }, inputContextWarnings, stepResult.issues);
8161
+ if (options.callbacks?.onTurnStart) try {
8162
+ options.callbacks.onTurnStart({
8163
+ turnNumber: turnCount + 1,
8164
+ issuesCount: stepResult.issues.length
8165
+ });
8166
+ } catch {}
8078
8167
  const { patches, stats } = await agent.generatePatches(stepResult.issues, form, maxPatchesPerTurn);
8079
8168
  if (options.signal?.aborted) return buildResult(form, turnCount, totalPatches, {
8080
8169
  ok: false,
@@ -8089,9 +8178,9 @@ async function fillForm(options) {
8089
8178
  stepResult = harness.apply(patches, stepResult.issues, llmStats);
8090
8179
  totalPatches += patches.length;
8091
8180
  turnCount++;
8092
- if (options.onTurnComplete) try {
8181
+ if (options.callbacks?.onTurnComplete) try {
8093
8182
  const requiredIssues = stepResult.issues.filter((i) => i.severity === "required");
8094
- options.onTurnComplete({
8183
+ options.callbacks.onTurnComplete({
8095
8184
  turnNumber: turnCount,
8096
8185
  issuesShown: stepResult.issues.length,
8097
8186
  patchesApplied: patches.length,
@@ -8253,15 +8342,8 @@ function validateResearchForm(form) {
8253
8342
 
8254
8343
  //#endregion
8255
8344
  //#region src/index.ts
8256
- /**
8257
- * Markform - Agent-friendly, human-readable, editable forms.
8258
- *
8259
- * This is the main library entry point that exports the core engine,
8260
- * types, and utilities for working with .form.md files.
8261
- */
8262
- const pkg = createRequire(import.meta.url)("../package.json");
8263
- /** Markform version (read from package.json). */
8264
- const VERSION = pkg.version;
8345
+ /** Markform version (injected at build time). */
8346
+ const VERSION = "0.1.6";
8265
8347
 
8266
8348
  //#endregion
8267
8349
  export { serializeScopeRef as C, parseRawTable as D, parseMarkdownTable as E, ParseError as O, parseScopeRef as S, parseCellValue as T, findFieldById as _, resolveHarnessConfig as a, isFieldRef as b, getProviderNames as c, MockAgent as d, createMockAgent as f, coerceToFieldPatch as g, coerceInputContext as h, runResearch as i, resolveModel as l, createHarness as m, isResearchForm as n, fillForm as o, FormHarness as p, validateResearchForm as r, getProviderInfo as s, VERSION as t, createLiveAgent as u, getFieldId as v, parseForm as w, isQualifiedRef as x, isCellRef as y };
@@ -152,10 +152,57 @@ High-level API for filling a form with an AI model.
152
152
  const result = await fillForm({
153
153
  form: parsedForm,
154
154
  model: 'anthropic/claude-sonnet-4-5',
155
- roles: ['agent'],
155
+ enableWebSearch: true,
156
+ targetRoles: ['agent'],
156
157
  });
157
158
  ```
158
159
 
160
+ ### FillCallbacks
161
+
162
+ Optional callbacks for observing form-filling execution in real-time.
163
+ All callbacks are optional and errors in callbacks don't abort filling.
164
+
165
+ ```typescript
166
+ import type { FillCallbacks } from 'markform';
167
+
168
+ const callbacks: FillCallbacks = {
169
+ onTurnStart: ({ turnNumber, issuesCount }) => {
170
+ console.log(`Turn ${turnNumber}: ${issuesCount} issues`);
171
+ },
172
+ onTurnComplete: (progress) => {
173
+ console.log(`Completed: ${progress.patchesApplied} patches applied`);
174
+ },
175
+ onToolStart: ({ name }) => {
176
+ spinner.message(`🔧 ${name}...`);
177
+ },
178
+ onToolEnd: ({ name, durationMs }) => {
179
+ console.log(`${name} completed in ${durationMs}ms`);
180
+ },
181
+ onLlmCallStart: ({ model }) => {
182
+ console.log(`Calling ${model}...`);
183
+ },
184
+ onLlmCallEnd: ({ inputTokens, outputTokens }) => {
185
+ console.log(`Tokens: ${inputTokens} in, ${outputTokens} out`);
186
+ },
187
+ };
188
+
189
+ await fillForm({
190
+ form: parsedForm,
191
+ model: 'anthropic/claude-sonnet-4-5',
192
+ enableWebSearch: true,
193
+ callbacks,
194
+ });
195
+ ```
196
+
197
+ | Callback | Parameters | Description |
198
+ | --- | --- | --- |
199
+ | `onTurnStart` | `{ turnNumber, issuesCount }` | Called when a turn begins |
200
+ | `onTurnComplete` | `TurnProgress` | Called when a turn completes |
201
+ | `onToolStart` | `{ name, input }` | Called before a tool executes |
202
+ | `onToolEnd` | `{ name, output, durationMs, error? }` | Called after a tool completes |
203
+ | `onLlmCallStart` | `{ model }` | Called before an LLM request |
204
+ | `onLlmCallEnd` | `{ model, inputTokens, outputTokens }` | Called after an LLM response |
205
+
159
206
  ### createHarness(form, config?): FormHarness
160
207
 
161
208
  Create a harness for manual control over the fill loop.
@@ -187,6 +234,10 @@ import type {
187
234
  FieldValue,
188
235
  Patch,
189
236
  InspectResult,
237
+ FillCallbacks,
238
+ FillOptions,
239
+ FillResult,
240
+ TurnProgress,
190
241
  // ... many more
191
242
  } from 'markform';
192
243
  ```
@@ -39,11 +39,11 @@ markform:
39
39
 
40
40
  {% form id="form_id" title="Form Title" %}
41
41
 
42
- {% field-group id="group_id" title="Group Title" %}
42
+ {% group id="group_id" title="Group Title" %}
43
43
 
44
44
  <!-- fields go here -->
45
45
 
46
- {% /field-group %}
46
+ {% /group %}
47
47
 
48
48
  {% /form %}
49
49
  ```
@@ -399,7 +399,7 @@ A focused research form for gathering ratings and key statistics for any film.
399
399
  Pulls from IMDB, Rotten Tomatoes, and Metacritic.
400
400
  {% /description %}
401
401
 
402
- {% field-group id="movie_input" title="Movie Identification" %}
402
+ {% group id="movie_input" title="Movie Identification" %}
403
403
 
404
404
  {% field kind="string" id="movie" label="Movie" role="user" required=true minLength=1 maxLength=300 %}{% /field %}
405
405
 
@@ -407,9 +407,9 @@ Pulls from IMDB, Rotten Tomatoes, and Metacritic.
407
407
  Enter the movie title (add any details to help identify, like "Barbie 2023" or "the Batman movie with Robert Pattinson")
408
408
  {% /instructions %}
409
409
 
410
- {% /field-group %}
410
+ {% /group %}
411
411
 
412
- {% field-group id="title_identification" title="Title Identification" %}
412
+ {% group id="title_identification" title="Title Identification" %}
413
413
 
414
414
  {% field kind="string" id="full_title" label="Full Title" role="agent" required=true %}{% /field %}
415
415
 
@@ -417,9 +417,9 @@ Enter the movie title (add any details to help identify, like "Barbie 2023" or "
417
417
  Look up what film the user had in mind and fill in the official title including subtitle if any (e.g., "The Lord of the Rings: The Fellowship of the Ring").
418
418
  {% /instructions %}
419
419
 
420
- {% /field-group %}
420
+ {% /group %}
421
421
 
422
- {% field-group id="sources" title="Sources" %}
422
+ {% group id="sources" title="Sources" %}
423
423
 
424
424
  {% field kind="url" id="imdb_url" label="IMDB URL" role="agent" required=true %}{% /field %}
425
425
 
@@ -439,9 +439,9 @@ Direct link to the movie's Rotten Tomatoes page.
439
439
  Direct link to the movie's Metacritic page.
440
440
  {% /instructions %}
441
441
 
442
- {% /field-group %}
442
+ {% /group %}
443
443
 
444
- {% field-group id="basic_details" title="Basic Details" %}
444
+ {% group id="basic_details" title="Basic Details" %}
445
445
 
446
446
  {% field kind="number" id="year" label="Release Year" role="agent" required=true min=1888 max=2030 %}{% /field %}
447
447
 
@@ -462,9 +462,9 @@ One director per line. Most films have one; some have two or more co-directors.
462
462
  - [ ] NR/Unrated {% #nr %}
463
463
  {% /field %}
464
464
 
465
- {% /field-group %}
465
+ {% /group %}
466
466
 
467
- {% field-group id="imdb_ratings" title="IMDB Ratings" %}
467
+ {% group id="imdb_ratings" title="IMDB Ratings" %}
468
468
 
469
469
  {% field kind="number" id="imdb_rating" label="IMDB Rating" role="agent" min=1.0 max=10.0 %}{% /field %}
470
470
 
@@ -478,9 +478,9 @@ IMDB user rating (1.0-10.0 scale).
478
478
  Number of IMDB user votes (e.g., 2800000 for a popular film).
479
479
  {% /instructions %}
480
480
 
481
- {% /field-group %}
481
+ {% /group %}
482
482
 
483
- {% field-group id="rotten_tomatoes_ratings" title="Rotten Tomatoes Ratings" %}
483
+ {% group id="rotten_tomatoes_ratings" title="Rotten Tomatoes Ratings" %}
484
484
 
485
485
  {% field kind="number" id="rt_critics_score" label="Tomatometer (Critics)" role="agent" min=0 max=100 %}{% /field %}
486
486
 
@@ -496,9 +496,9 @@ Tomatometer percentage (0-100).
496
496
  Audience Score percentage (0-100).
497
497
  {% /instructions %}
498
498
 
499
- {% /field-group %}
499
+ {% /group %}
500
500
 
501
- {% field-group id="metacritic_ratings" title="Metacritic Ratings" %}
501
+ {% group id="metacritic_ratings" title="Metacritic Ratings" %}
502
502
 
503
503
  {% field kind="number" id="metacritic_score" label="Metacritic Score" role="agent" min=0 max=100 %}{% /field %}
504
504
 
@@ -506,9 +506,9 @@ Audience Score percentage (0-100).
506
506
  Metascore (0-100 scale). Leave empty if not available.
507
507
  {% /instructions %}
508
508
 
509
- {% /field-group %}
509
+ {% /group %}
510
510
 
511
- {% field-group id="summary" title="Summary" %}
511
+ {% group id="summary" title="Summary" %}
512
512
 
513
513
  {% field kind="string" id="logline" label="One-Line Summary" role="agent" maxLength=300 %}{% /field %}
514
514
 
@@ -524,7 +524,7 @@ Format: Award | Category | Year
524
524
  Example: "Oscar | Best Picture | 1995"
525
525
  {% /instructions %}
526
526
 
527
- {% /field-group %}
527
+ {% /group %}
528
528
 
529
529
  {% /form %}
530
530
  ```
@@ -595,7 +595,7 @@ markform fill template.form.md --mock --mock-source filled.form.md
595
595
 
596
596
  3. **Set constraints**: Use `min`, `max`, `minLength`, `pattern` to validate
597
597
 
598
- 4. **Group logically**: Related fields in the same `field-group`
598
+ 4. **Group logically**: Related fields in the same `group`
599
599
 
600
600
  5. **Assign roles**: Separate user input from agent research
601
601