markform 0.1.8 → 0.1.10

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 (28) hide show
  1. package/README.md +45 -55
  2. package/dist/ai-sdk.d.mts +1 -1
  3. package/dist/ai-sdk.mjs +2 -2
  4. package/dist/{apply-BUU2QcJ2.mjs → apply-BTFCHpYV.mjs} +402 -341
  5. package/dist/bin.mjs +1 -1
  6. package/dist/{cli-BZh25bvy.mjs → cli-BZa4fYR9.mjs} +518 -65
  7. package/dist/cli.mjs +1 -1
  8. package/dist/{coreTypes-DJtu8OOp.mjs → coreTypes-B1oI7qvV.mjs} +36 -3
  9. package/dist/{coreTypes-BSPJ9H27.d.mts → coreTypes-JCPm418M.d.mts} +215 -9
  10. package/dist/index.d.mts +180 -17
  11. package/dist/index.mjs +5 -5
  12. package/dist/{session-DSTNiHza.mjs → session-CzCh6JeY.mjs} +1 -1
  13. package/dist/{session-CmHdAPyg.mjs → session-Dxqwt0RC.mjs} +3 -3
  14. package/dist/{shared-C9yW5FLZ.mjs → shared-CNqwaxUt.mjs} +1 -1
  15. package/dist/{shared-DQ6y3Ggc.mjs → shared-D3dNi-Gn.mjs} +1 -1
  16. package/dist/{src-kUggXhN1.mjs → src-CYnyLwBe.mjs} +297 -128
  17. package/docs/markform-spec.md +104 -53
  18. package/examples/movie-research/movie-deep-research-mock-filled.form.md +601 -0
  19. package/examples/movie-research/{movie-research-deep.form.md → movie-deep-research.form.md} +2 -2
  20. package/examples/rejection-test/rejection-test.session.yaml +446 -0
  21. package/examples/simple/simple-with-skips.session.yaml +1966 -18
  22. package/examples/simple/simple.session.yaml +1979 -18
  23. package/examples/startup-deep-research/startup-deep-research.form.md +21 -36
  24. package/package.json +1 -1
  25. package/examples/earnings-analysis/earnings-analysis.form.md +0 -159
  26. package/examples/earnings-analysis/earnings-analysis.raw.md +0 -801
  27. package/examples/earnings-analysis/earnings-analysis.valid.ts +0 -198
  28. package/examples/movie-research/movie-research-basic.form.md +0 -169
@@ -1385,12 +1385,12 @@ type IssueReason =
1385
1385
  | 'checkbox_incomplete' // Required checkboxes with non-terminal states
1386
1386
  | 'min_items_not_met' // String-list or multi-select below minimum
1387
1387
  // Severity: *recommended* (optional improvements)
1388
- | 'optional_empty'; // Optional field with no value
1388
+ | 'optional_unanswered'; // Optional field not yet addressed
1389
1389
 
1390
1390
  // Mapping from ValidationIssue to InspectIssue:
1391
1391
  // - ValidationIssue.severity='error' → InspectIssue.severity='required'
1392
1392
  // - ValidationIssue.severity='warning'/'info' → InspectIssue.severity='recommended'
1393
- // - Missing optional fields → severity='recommended', reason='optional_empty'
1393
+ // - Unanswered optional fields → severity='recommended', reason='optional_unanswered'
1394
1394
  ```
1395
1395
 
1396
1396
  #### StructureSummary and ProgressSummary
@@ -2296,9 +2296,33 @@ interface ValidationIssue {
2296
2296
 
2297
2297
  #### Error Taxonomy
2298
2298
 
2299
- Markform distinguishes between two fundamental error types:
2299
+ Markform provides a structured error hierarchy for different error scenarios.
2300
+ All errors extend from `MarkformError` and include context-rich information for debugging.
2300
2301
 
2301
- **1. ParseError** — Syntax and structural errors
2302
+ **Error Hierarchy:**
2303
+
2304
+ ```
2305
+ MarkformError (base)
2306
+ ├── MarkformParseError — Form syntax/structure errors
2307
+ ├── MarkformPatchError — Single patch validation error
2308
+ ├── MarkformValidationError — Multiple patch errors
2309
+ ├── MarkformLlmError — LLM/API errors
2310
+ ├── MarkformConfigError — Configuration errors
2311
+ └── MarkformAbortError — Form abort errors
2312
+ ```
2313
+
2314
+ **1. MarkformError** — Base error class
2315
+
2316
+ Base class for all markform errors. Consumers can catch this to handle any markform error.
2317
+
2318
+ ```ts
2319
+ class MarkformError extends Error {
2320
+ readonly name: string; // Error class name
2321
+ readonly version: string; // Markform version for debugging
2322
+ }
2323
+ ```
2324
+
2325
+ **2. MarkformParseError** — Syntax and structural errors
2302
2326
 
2303
2327
  Parse errors occur when the markdown/Markdoc syntax is malformed or the form structure
2304
2328
  is invalid. These are detected during parsing and prevent the form from being loaded.
@@ -2306,89 +2330,116 @@ is invalid. These are detected during parsing and prevent the form from being lo
2306
2330
  Examples:
2307
2331
 
2308
2332
  - Invalid Markdoc syntax (unclosed tags, malformed attributes)
2309
-
2310
2333
  - Missing required attributes (e.g., field without `id` or `label`)
2311
-
2312
2334
  - Duplicate IDs within the form
2313
-
2314
- - Invalid field state attribute value (not ‘skipped’ or ‘aborted’)
2315
-
2335
+ - Invalid field state attribute value (not 'skipped' or 'aborted')
2316
2336
  - Malformed sentinel values in value fences
2317
2337
 
2318
- **Type definition:**
2319
2338
  ```ts
2320
- interface ParseError {
2321
- type: 'parse';
2322
- message: string;
2323
- location?: {
2324
- line?: number;
2325
- column?: number;
2326
- fieldId?: Id;
2327
- noteId?: NoteId;
2328
- };
2339
+ class MarkformParseError extends MarkformError {
2340
+ readonly source?: string; // File path or form identifier
2341
+ readonly line?: number; // Line number (1-indexed)
2342
+ readonly column?: number; // Column number (1-indexed)
2329
2343
  }
2330
2344
  ```
2331
2345
 
2332
2346
  **Behavior:**
2333
2347
 
2334
2348
  - Parse errors prevent form loading
2349
+ - Thrown from `parseForm()` as exceptions
2350
+ - Must be fixed before the form can be used
2335
2351
 
2336
- - Returned from `parseForm()` as thrown exceptions or error results
2352
+ **3. MarkformPatchError** Single patch validation error
2337
2353
 
2338
- - Must be fixed before the form can be used
2354
+ Thrown when an LLM generates an invalid patch value.
2339
2355
 
2340
- **2. MarkformValidationError** — Model consistency errors
2356
+ ```ts
2357
+ class MarkformPatchError extends MarkformError {
2358
+ readonly fieldId: string; // Target field ID
2359
+ readonly patchOperation: string; // e.g., 'set_string', 'set_checkboxes'
2360
+ readonly expectedType: string; // Expected type description
2361
+ readonly receivedValue: unknown; // Actual value received
2362
+ readonly receivedType: string; // Type of received value
2363
+ readonly patchIndex?: number; // Index in batch (if applicable)
2364
+ }
2365
+ ```
2341
2366
 
2342
- Validation errors occur when the parsed form model is inconsistent with Markform rules,
2343
- even if the syntax is valid.
2344
- These are semantic errors in the data model.
2367
+ **4. MarkformValidationError** Multiple validation errors
2345
2368
 
2346
- Examples:
2369
+ Aggregates multiple patch errors from a single operation.
2347
2370
 
2348
- - Option ID referenced in value doesn’t exist in field schema
2371
+ ```ts
2372
+ class MarkformValidationError extends MarkformError {
2373
+ readonly issues: MarkformPatchError[]; // Individual errors
2374
+ readonly fieldIds: string[]; // All affected field IDs
2375
+ }
2376
+ ```
2377
+
2378
+ **Distinction from ValidationIssue:**
2379
+
2380
+ `ValidationIssue` represents content validation (required fields, constraints, hook
2381
+ validators) and is part of normal form filling workflow.
2382
+ These issues don't prevent form operations—they guide what needs to be filled next.
2349
2383
 
2350
- - Field value type doesn’t match field kind
2384
+ `MarkformParseError` and `MarkformValidationError` represent structural problems that
2385
+ prevent the form from being used at all.
2351
2386
 
2352
- - Response state inconsistency (e.g., `state='answered'` but no value present)
2387
+ **5. MarkformLlmError** LLM/API errors
2353
2388
 
2354
- - Invalid checkbox state for the field’s checkbox mode
2389
+ Thrown for rate limits, timeouts, invalid responses, etc.
2355
2390
 
2356
- **Type definition:**
2357
2391
  ```ts
2358
- interface MarkformValidationError {
2359
- type: 'validation';
2360
- message: string;
2361
- location?: {
2362
- line?: number;
2363
- column?: number;
2364
- fieldId?: Id;
2365
- noteId?: NoteId;
2366
- };
2392
+ class MarkformLlmError extends MarkformError {
2393
+ readonly provider?: string; // e.g., 'anthropic', 'openai'
2394
+ readonly model?: string; // Model identifier
2395
+ readonly statusCode?: number; // HTTP status code
2396
+ readonly retryable: boolean; // Whether error is retryable
2367
2397
  }
2368
2398
  ```
2369
2399
 
2370
- **Behavior:**
2400
+ **6. MarkformConfigError** — Configuration errors
2371
2401
 
2372
- - Validation errors prevent form operations
2402
+ Thrown when invalid options are passed to `fillForm`, model resolver, etc.
2403
+
2404
+ ```ts
2405
+ class MarkformConfigError extends MarkformError {
2406
+ readonly option: string; // Config option name
2407
+ readonly expectedType: string; // Expected type/value
2408
+ readonly receivedValue: unknown; // Actual value
2409
+ }
2410
+ ```
2373
2411
 
2374
- - Returned from `parseForm()` or `applyPatches()` as errors
2412
+ **7. MarkformAbortError** Form abort errors
2375
2413
 
2376
- - Must be fixed before the form is in a valid state
2414
+ Thrown when a form is explicitly aborted via `abort_form` patch.
2377
2415
 
2378
- **Distinction from ValidationIssue:**
2416
+ ```ts
2417
+ class MarkformAbortError extends MarkformError {
2418
+ readonly reason: string; // Abort reason
2419
+ readonly fieldId?: string; // Field that triggered abort
2420
+ }
2421
+ ```
2379
2422
 
2380
- `ValidationIssue` represents content validation (required fields, constraints, hook
2381
- validators) and is part of normal form filling workflow.
2382
- These issues don’t prevent form operations—they guide what needs to be filled next.
2423
+ **Type Guards:**
2383
2424
 
2384
- `ParseError` and `MarkformValidationError` represent structural problems that prevent
2385
- the form from being used at all.
2425
+ For reliable error detection in bundled environments:
2386
2426
 
2387
- **Union type:**
2388
2427
  ```ts
2389
- type MarkformError = ParseError | MarkformValidationError;
2428
+ isMarkformError(error) // Any markform error
2429
+ isParseError(error) // MarkformParseError
2430
+ isPatchError(error) // MarkformPatchError
2431
+ isValidationError(error) // MarkformValidationError
2432
+ isLlmError(error) // MarkformLlmError
2433
+ isConfigError(error) // MarkformConfigError
2434
+ isAbortError(error) // MarkformAbortError
2435
+ isRetryableError(error) // LLM error with retryable=true
2390
2436
  ```
2391
2437
 
2438
+ **Backward Compatibility:**
2439
+
2440
+ `ParseError` is exported as an alias for `MarkformParseError` for backward compatibility.
2441
+ Use `MarkformParseError` in new code.
2442
+
2392
2443
  * * *
2393
2444
 
2394
2445
  ## Layer 4: Tool API & Interfaces
@@ -2695,7 +2746,7 @@ type.
2695
2746
  | `checkbox_incomplete` | 3 (required) / 2 (recommended) |
2696
2747
  | `validation_error` | 2 |
2697
2748
  | `min_items_not_met` | 2 |
2698
- | `optional_empty` | 1 |
2749
+ | `optional_unanswered` | 1 |
2699
2750
 
2700
2751
  **Total Score** = Field Priority Weight + Issue Type Score
2701
2752