markform 0.1.1 → 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.
- package/DOCS.md +546 -0
- package/README.md +338 -71
- package/SPEC.md +2779 -0
- package/dist/ai-sdk.d.mts +2 -2
- package/dist/ai-sdk.mjs +5 -3
- package/dist/{apply-BQdd-fdx.mjs → apply-BfAGTHMh.mjs} +837 -730
- package/dist/bin.mjs +6 -3
- package/dist/{cli-pjOiHgCW.mjs → cli-B3NVm6zL.mjs} +1349 -422
- package/dist/cli.mjs +6 -3
- package/dist/{coreTypes--6etkcwb.d.mts → coreTypes-BXhhz9Iq.d.mts} +1946 -794
- package/dist/coreTypes-Dful87E0.mjs +537 -0
- package/dist/index.d.mts +116 -19
- package/dist/index.mjs +5 -3
- package/dist/session-Bqnwi9wp.mjs +110 -0
- package/dist/session-DdAtY2Ni.mjs +4 -0
- package/dist/shared-D7gf27Tr.mjs +3 -0
- package/dist/shared-N_s1M-_K.mjs +176 -0
- package/dist/src-BXRkGFpG.mjs +7587 -0
- package/examples/celebrity-deep-research/celebrity-deep-research.form.md +912 -0
- package/examples/earnings-analysis/earnings-analysis.form.md +6 -1
- package/examples/earnings-analysis/earnings-analysis.valid.ts +119 -59
- package/examples/movie-research/movie-research-basic.form.md +164 -0
- package/examples/movie-research/movie-research-deep.form.md +486 -0
- package/examples/movie-research/movie-research-minimal.form.md +73 -0
- package/examples/simple/simple-mock-filled.form.md +17 -13
- package/examples/simple/simple-skipped-filled.form.md +32 -9
- package/examples/simple/simple-with-skips.session.yaml +102 -143
- package/examples/simple/simple.form.md +13 -13
- package/examples/simple/simple.session.yaml +80 -69
- package/examples/startup-deep-research/startup-deep-research.form.md +60 -8
- package/examples/startup-research/startup-research-mock-filled.form.md +1 -1
- package/examples/startup-research/startup-research.form.md +1 -1
- package/package.json +9 -5
- package/dist/src-Cs4_9lWP.mjs +0 -2151
- package/examples/political-research/political-research.form.md +0 -233
- 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
|
|
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/
|
|
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
|
|
26
|
-
|
|
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,12 +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
|
|
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
|
-
* @param skips - Skip state per field (from skip_field patches)
|
|
52
56
|
* @returns Progress summary with field states and counts
|
|
53
57
|
*/
|
|
54
|
-
declare function computeProgressSummary(schema: FormSchema,
|
|
58
|
+
declare function computeProgressSummary(schema: FormSchema, responsesByFieldId: Record<Id, FieldResponse>, notes: Note[], issues: InspectIssue[]): ProgressSummary;
|
|
55
59
|
/**
|
|
56
60
|
* Compute the overall form state from progress summary.
|
|
57
61
|
*
|
|
@@ -63,10 +67,11 @@ declare function computeFormState(progress: ProgressSummary): ProgressState;
|
|
|
63
67
|
* Determine if the form is complete (ready for submission).
|
|
64
68
|
*
|
|
65
69
|
* A form is complete when:
|
|
66
|
-
* 1. No
|
|
67
|
-
* 2. No fields
|
|
68
|
-
* 3. No fields
|
|
69
|
-
* 4.
|
|
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)
|
|
70
75
|
*
|
|
71
76
|
* Every field must be explicitly addressed - either filled with a value or
|
|
72
77
|
* skipped with a reason. This ensures agents fully process all fields.
|
|
@@ -85,12 +90,12 @@ interface ComputedSummaries {
|
|
|
85
90
|
* Compute all summaries for a parsed form.
|
|
86
91
|
*
|
|
87
92
|
* @param schema - The form schema
|
|
88
|
-
* @param
|
|
93
|
+
* @param responsesByFieldId - Current field responses (state + optional value)
|
|
94
|
+
* @param notes - Notes attached to fields/groups/form
|
|
89
95
|
* @param issues - Validation issues
|
|
90
|
-
* @param skips - Skip state per field (from skip_field patches)
|
|
91
96
|
* @returns All computed summaries
|
|
92
97
|
*/
|
|
93
|
-
declare function computeAllSummaries(schema: FormSchema,
|
|
98
|
+
declare function computeAllSummaries(schema: FormSchema, responsesByFieldId: Record<Id, FieldResponse>, notes: Note[], issues: InspectIssue[]): ComputedSummaries;
|
|
94
99
|
//#endregion
|
|
95
100
|
//#region src/engine/validate.d.ts
|
|
96
101
|
interface ValidateOptions {
|
|
@@ -216,7 +221,7 @@ declare function coerceToFieldPatch(form: ParsedForm, fieldId: string, rawValue:
|
|
|
216
221
|
declare function coerceInputContext(form: ParsedForm, inputContext: InputContext): CoerceInputContextResult;
|
|
217
222
|
//#endregion
|
|
218
223
|
//#region src/harness/harness.d.ts
|
|
219
|
-
type HarnessState =
|
|
224
|
+
type HarnessState = 'init' | 'step' | 'wait' | 'complete';
|
|
220
225
|
/**
|
|
221
226
|
* Form harness for managing agent-driven form filling.
|
|
222
227
|
*/
|
|
@@ -410,7 +415,7 @@ interface FillOptions {
|
|
|
410
415
|
/** Maximum patches per turn (default: 20) */
|
|
411
416
|
maxPatchesPerTurn?: number;
|
|
412
417
|
/** Maximum issues to show per turn (default: 10) */
|
|
413
|
-
|
|
418
|
+
maxIssuesPerTurn?: number;
|
|
414
419
|
/** Target roles to fill (default: ['agent']) */
|
|
415
420
|
targetRoles?: string[];
|
|
416
421
|
/** Fill mode: 'continue' (skip filled) or 'overwrite' (re-fill) */
|
|
@@ -444,7 +449,7 @@ type FillStatus = {
|
|
|
444
449
|
ok: true;
|
|
445
450
|
} | {
|
|
446
451
|
ok: false;
|
|
447
|
-
reason:
|
|
452
|
+
reason: 'max_turns' | 'cancelled' | 'error';
|
|
448
453
|
message?: string;
|
|
449
454
|
};
|
|
450
455
|
/**
|
|
@@ -469,7 +474,7 @@ interface FillResult {
|
|
|
469
474
|
remainingIssues?: {
|
|
470
475
|
ref: string;
|
|
471
476
|
message: string;
|
|
472
|
-
severity:
|
|
477
|
+
severity: 'required' | 'recommended';
|
|
473
478
|
priority: number;
|
|
474
479
|
}[];
|
|
475
480
|
}
|
|
@@ -550,6 +555,98 @@ declare function createMockAgent(completedForm: ParsedForm): MockAgent;
|
|
|
550
555
|
*/
|
|
551
556
|
declare function fillForm(options: FillOptions): Promise<FillResult>;
|
|
552
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
|
|
553
650
|
//#region src/index.d.ts
|
|
554
651
|
/**
|
|
555
652
|
* Markform - Agent-friendly, human-readable, editable forms.
|
|
@@ -560,4 +657,4 @@ declare function fillForm(options: FillOptions): Promise<FillResult>;
|
|
|
560
657
|
/** Markform version. */
|
|
561
658
|
declare const VERSION = "0.1.0";
|
|
562
659
|
//#endregion
|
|
563
|
-
export { type AgentResponse, 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 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, 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
|
|
2
|
-
import {
|
|
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,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 };
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import YAML from "yaml";
|
|
2
|
+
import { relative } from "node:path";
|
|
3
|
+
import pc from "picocolors";
|
|
4
|
+
import { mkdir } from "node:fs/promises";
|
|
5
|
+
|
|
6
|
+
//#region src/cli/lib/naming.ts
|
|
7
|
+
/**
|
|
8
|
+
* Naming convention utilities for JSON/YAML output.
|
|
9
|
+
*
|
|
10
|
+
* Converts between camelCase (TypeScript internal) and snake_case (JSON/YAML output).
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Convert a camelCase string to snake_case.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* toSnakeCase("fieldCount") // "field_count"
|
|
17
|
+
* toSnakeCase("parentFieldId") // "parent_field_id"
|
|
18
|
+
* toSnakeCase("already_snake") // "already_snake"
|
|
19
|
+
*/
|
|
20
|
+
function toSnakeCase(str) {
|
|
21
|
+
return str.replace(/([A-Z])/g, "_$1").toLowerCase();
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Recursively convert all object keys from camelCase to snake_case.
|
|
25
|
+
*
|
|
26
|
+
* Handles nested objects and arrays. Primitives are returned unchanged.
|
|
27
|
+
*/
|
|
28
|
+
function convertKeysToSnakeCase(obj) {
|
|
29
|
+
if (obj === null || obj === void 0) return obj;
|
|
30
|
+
if (Array.isArray(obj)) return obj.map(convertKeysToSnakeCase);
|
|
31
|
+
if (typeof obj === "object") {
|
|
32
|
+
const result = {};
|
|
33
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
34
|
+
const snakeKey = toSnakeCase(key);
|
|
35
|
+
result[snakeKey] = convertKeysToSnakeCase(value);
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
return obj;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region src/cli/lib/shared.ts
|
|
44
|
+
/**
|
|
45
|
+
* Valid format options for Commander choice validation.
|
|
46
|
+
*/
|
|
47
|
+
const OUTPUT_FORMATS = [
|
|
48
|
+
"console",
|
|
49
|
+
"plaintext",
|
|
50
|
+
"yaml",
|
|
51
|
+
"json",
|
|
52
|
+
"markform",
|
|
53
|
+
"markdown"
|
|
54
|
+
];
|
|
55
|
+
/**
|
|
56
|
+
* Extract command context from Commander options.
|
|
57
|
+
*/
|
|
58
|
+
function getCommandContext(command) {
|
|
59
|
+
const opts = command.optsWithGlobals();
|
|
60
|
+
return {
|
|
61
|
+
dryRun: opts.dryRun ?? false,
|
|
62
|
+
verbose: opts.verbose ?? false,
|
|
63
|
+
quiet: opts.quiet ?? false,
|
|
64
|
+
format: opts.format ?? "console",
|
|
65
|
+
formsDir: opts.formsDir
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Check if output should use colors.
|
|
70
|
+
* Returns true for console format when stdout is a TTY.
|
|
71
|
+
*/
|
|
72
|
+
function shouldUseColors(ctx) {
|
|
73
|
+
if (ctx.format === "plaintext" || ctx.format === "yaml" || ctx.format === "json") return false;
|
|
74
|
+
return process.stdout.isTTY && !process.env.NO_COLOR;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Format structured data according to output format.
|
|
78
|
+
*
|
|
79
|
+
* JSON and YAML outputs are converted to snake_case keys for consistency.
|
|
80
|
+
*/
|
|
81
|
+
function formatOutput(ctx, data, consoleFormatter) {
|
|
82
|
+
switch (ctx.format) {
|
|
83
|
+
case "json": return JSON.stringify(convertKeysToSnakeCase(data), null, 2);
|
|
84
|
+
case "yaml": return YAML.stringify(convertKeysToSnakeCase(data));
|
|
85
|
+
case "plaintext":
|
|
86
|
+
case "console":
|
|
87
|
+
default:
|
|
88
|
+
if (consoleFormatter) return consoleFormatter(data, shouldUseColors(ctx));
|
|
89
|
+
return YAML.stringify(convertKeysToSnakeCase(data));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Log a dry-run message.
|
|
94
|
+
*/
|
|
95
|
+
function logDryRun(message, details) {
|
|
96
|
+
console.log(pc.yellow(`[DRY RUN] ${message}`));
|
|
97
|
+
if (details) console.log(pc.dim(JSON.stringify(details, null, 2)));
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Log a verbose message (only shown if --verbose is set).
|
|
101
|
+
*/
|
|
102
|
+
function logVerbose(ctx, message) {
|
|
103
|
+
if (ctx.verbose) console.log(pc.dim(message));
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Log an info message (hidden if --quiet is set).
|
|
107
|
+
*/
|
|
108
|
+
function logInfo(ctx, message) {
|
|
109
|
+
if (!ctx.quiet) console.log(message);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Log an error message (always shown).
|
|
113
|
+
*/
|
|
114
|
+
function logError(message) {
|
|
115
|
+
console.error(pc.red(`Error: ${message}`));
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Log a success message (hidden if --quiet is set).
|
|
119
|
+
*/
|
|
120
|
+
function logSuccess(ctx, message) {
|
|
121
|
+
if (!ctx.quiet) console.log(pc.green(message));
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Log a timing message (hidden if --quiet is set).
|
|
125
|
+
*/
|
|
126
|
+
function logTiming(ctx, label, durationMs) {
|
|
127
|
+
if (!ctx.quiet) {
|
|
128
|
+
const seconds = (durationMs / 1e3).toFixed(1);
|
|
129
|
+
console.log(pc.cyan(`⏰ ${label}: ${seconds}s`));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Log a warning message (hidden if --quiet is set).
|
|
134
|
+
*/
|
|
135
|
+
function logWarn(ctx, message) {
|
|
136
|
+
if (!ctx.quiet) console.log(pc.yellow(`⚠️ ${message}`));
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Format a file path for display: relative to cwd, colored green.
|
|
140
|
+
* If the path is within the cwd, shows as relative (e.g., "./simple-filled1.form.md")
|
|
141
|
+
* If outside cwd, shows the absolute path.
|
|
142
|
+
*/
|
|
143
|
+
function formatPath(absolutePath, cwd = process.cwd()) {
|
|
144
|
+
const relativePath = relative(cwd, absolutePath);
|
|
145
|
+
const displayPath = relativePath.startsWith("..") ? absolutePath : `./${relativePath}`;
|
|
146
|
+
return pc.green(displayPath);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Read a file and return its contents.
|
|
150
|
+
*/
|
|
151
|
+
async function readFile$1(filePath) {
|
|
152
|
+
const { readFile: fsReadFile } = await import("node:fs/promises");
|
|
153
|
+
return fsReadFile(filePath, "utf-8");
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Write contents to a file atomically.
|
|
157
|
+
*
|
|
158
|
+
* Uses the atomically library to prevent partial or corrupted files
|
|
159
|
+
* if the process crashes mid-write.
|
|
160
|
+
*/
|
|
161
|
+
async function writeFile(filePath, contents) {
|
|
162
|
+
const { writeFile: atomicWriteFile } = await import("atomically");
|
|
163
|
+
await atomicWriteFile(filePath, contents);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Ensure the forms directory exists, creating it if necessary.
|
|
167
|
+
* Uses recursive mkdir so parent directories are created as needed.
|
|
168
|
+
*
|
|
169
|
+
* @param formsDir Absolute path to the forms directory
|
|
170
|
+
*/
|
|
171
|
+
async function ensureFormsDir(formsDir) {
|
|
172
|
+
await mkdir(formsDir, { recursive: true });
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
//#endregion
|
|
176
|
+
export { getCommandContext as a, logInfo as c, logVerbose as d, logWarn as f, writeFile as h, formatPath as i, logSuccess as l, shouldUseColors as m, ensureFormsDir as n, logDryRun as o, readFile$1 as p, formatOutput as r, logError as s, OUTPUT_FORMATS as t, logTiming as u };
|