markform 0.1.16 → 0.1.18

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 (35) hide show
  1. package/LICENSE +369 -0
  2. package/README.md +154 -214
  3. package/dist/ai-sdk.d.mts +1 -1
  4. package/dist/ai-sdk.mjs +2 -2
  5. package/dist/{apply-CXsI5N9x.mjs → apply-BYgtU64w.mjs} +203 -16
  6. package/dist/apply-BYgtU64w.mjs.map +1 -0
  7. package/dist/bin.mjs +1 -1
  8. package/dist/{cli-BsFessUW.mjs → cli-D9w0Bp4J.mjs} +199 -13
  9. package/dist/cli-D9w0Bp4J.mjs.map +1 -0
  10. package/dist/cli.mjs +1 -1
  11. package/dist/{coreTypes-DE6Giau5.d.mts → coreTypes-BMEs8h_2.d.mts} +165 -2
  12. package/dist/{coreTypes-DiCddBKu.mjs → coreTypes-SDB3KRRJ.mjs} +9 -4
  13. package/dist/coreTypes-SDB3KRRJ.mjs.map +1 -0
  14. package/dist/index.d.mts +266 -2
  15. package/dist/index.mjs +5 -5
  16. package/dist/{session-B7aR6hno.mjs → session-CW9AQw6i.mjs} +1 -1
  17. package/dist/{session-XDrocA3j.mjs → session-Ci4B0Pna.mjs} +2 -2
  18. package/dist/{session-XDrocA3j.mjs.map → session-Ci4B0Pna.mjs.map} +1 -1
  19. package/dist/{src-Dv3IZSQU.mjs → src-DDxi-2ne.mjs} +966 -32
  20. package/dist/src-DDxi-2ne.mjs.map +1 -0
  21. package/docs/markform-apis.md +110 -0
  22. package/docs/markform-reference.md +58 -0
  23. package/docs/markform-spec.md +204 -9
  24. package/examples/movie-research/movie-deep-research-mock-filled.form.md +1 -1
  25. package/examples/movie-research/movie-deep-research.form.md +1 -1
  26. package/examples/parallel/parallel-research.form.md +57 -0
  27. package/examples/plan-document/plan-document-markdoc.form.md +35 -0
  28. package/examples/plan-document/plan-document-progress.form.md +47 -0
  29. package/examples/plan-document/plan-document.form.md +47 -0
  30. package/examples/startup-deep-research/startup-deep-research.form.md +1 -1
  31. package/package.json +2 -2
  32. package/dist/apply-CXsI5N9x.mjs.map +0 -1
  33. package/dist/cli-BsFessUW.mjs.map +0 -1
  34. package/dist/coreTypes-DiCddBKu.mjs.map +0 -1
  35. package/dist/src-Dv3IZSQU.mjs.map +0 -1
package/dist/bin.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
 
4
- import { t as runCli } from "./cli-BsFessUW.mjs";
4
+ import { t as runCli } from "./cli-D9w0Bp4J.mjs";
5
5
  import { resolve } from "node:path";
6
6
  import { existsSync } from "node:fs";
7
7
  import { config } from "dotenv";
@@ -1,8 +1,8 @@
1
1
 
2
- import { L as PatchSchema } from "./coreTypes-DiCddBKu.mjs";
3
- import { A as MAX_FORMS_IN_MENU, B as formatSuggestedLlms, C as DEFAULT_MAX_TURNS, D as DEFAULT_RESEARCH_MAX_PATCHES_PER_TURN, E as DEFAULT_RESEARCH_MAX_ISSUES_PER_TURN, F as deriveSchemaPath, H as hasWebSearchSupport, I as detectFileType, L as parseRolesFlag, M as USER_ROLE, N as deriveExportPath, P as deriveReportPath, R as SUGGESTED_LLMS, U as parseModelIdForDisplay, _ as validateSyntaxConsistency, b as DEFAULT_MAX_ISSUES_PER_TURN, d as serializeForm, f as serializeRawMarkdown, i as inspect, j as REPORT_EXTENSION, m as friendlyUrlAbbrev, n as getAllFields, p as serializeReport, t as applyPatches, v as AGENT_ROLE, w as DEFAULT_PORT, x as DEFAULT_MAX_PATCHES_PER_TURN, y as DEFAULT_FORMS_DIR, z as WEB_SEARCH_CONFIG } from "./apply-CXsI5N9x.mjs";
4
- import { D as parseForm, E as formToJsonSchema, a as resolveHarnessConfig, c as getProviderNames, d as createLiveAgent, h as createHarness, i as runResearch, l as resolveModel, n as isResearchForm, o as fillForm, p as createMockAgent, s as getProviderInfo, t as VERSION, u as buildMockWireFormat } from "./src-Dv3IZSQU.mjs";
5
- import { n as serializeSession } from "./session-XDrocA3j.mjs";
2
+ import { L as PatchSchema } from "./coreTypes-SDB3KRRJ.mjs";
3
+ import { B as WEB_SEARCH_CONFIG, D as DEFAULT_RESEARCH_MAX_ISSUES_PER_TURN, F as deriveReportPath, I as deriveSchemaPath, L as detectFileType, M as REPORT_EXTENSION, N as USER_ROLE, O as DEFAULT_RESEARCH_MAX_PATCHES_PER_TURN, P as deriveExportPath, R as parseRolesFlag, S as DEFAULT_MAX_PATCHES_PER_TURN, T as DEFAULT_PORT, U as hasWebSearchSupport, V as formatSuggestedLlms, W as parseModelIdForDisplay, _ as validateSyntaxConsistency, b as DEFAULT_MAX_ISSUES_PER_TURN, d as serializeForm, f as serializeRawMarkdown, i as inspect, j as MAX_FORMS_IN_MENU, m as friendlyUrlAbbrev, n as getAllFields, p as serializeReport, t as applyPatches, v as AGENT_ROLE, w as DEFAULT_MAX_TURNS, y as DEFAULT_FORMS_DIR, z as SUGGESTED_LLMS } from "./apply-BYgtU64w.mjs";
4
+ import { A as formToJsonSchema, _ as createMockAgent, a as resolveHarnessConfig, d as getProviderNames, f as resolveModel, h as computeExecutionPlan, i as runResearch, j as parseForm, m as createLiveAgent, n as isResearchForm, o as fillForm, p as buildMockWireFormat, t as VERSION, u as getProviderInfo, y as createHarness } from "./src-DDxi-2ne.mjs";
5
+ import { n as serializeSession } from "./session-Ci4B0Pna.mjs";
6
6
  import { _ as writeFile, a as formatPath, c as logError, d as logTiming, f as logVerbose, g as stripHtmlComments, h as shouldUseColors, i as formatOutput, l as logInfo, m as readFile$1, n as createSpinner, o as getCommandContext, p as logWarn, r as ensureFormsDir, s as logDryRun, t as OUTPUT_FORMATS, u as logSuccess } from "./shared-CCq4haEV.mjs";
7
7
  import Markdoc from "@markdoc/markdoc";
8
8
  import YAML from "yaml";
@@ -227,7 +227,7 @@ function formatConsoleReport$3(report, useColors) {
227
227
  * Register the apply command.
228
228
  */
229
229
  function registerApplyCommand(program) {
230
- program.command("apply <file>").description("Apply patches to a form").option("--patch <json>", "JSON array of patches to apply").option("-o, --output <file>", "Output file (defaults to stdout)").option("--report", "Output apply result report instead of modified form").action(async (file, options, cmd) => {
230
+ program.command("apply <file>").description("Apply patches to a form").option("--patch <json>", "JSON array of patches to apply").option("-o, --output <file>", "Output file (defaults to stdout)").option("--report", "Output apply result report instead of modified form").option("--normalize", "Regenerate form without preserving external content").action(async (file, options, cmd) => {
231
231
  const ctx = getCommandContext(cmd);
232
232
  try {
233
233
  if (!options.patch) {
@@ -293,7 +293,7 @@ function registerApplyCommand(program) {
293
293
  logSuccess(ctx, `Report written to ${options.output}`);
294
294
  } else console.log(output);
295
295
  } else {
296
- const output = serializeForm(form);
296
+ const output = serializeForm(form, { preserveContent: !options.normalize });
297
297
  if (options.output) {
298
298
  await writeFile(options.output, output);
299
299
  logSuccess(ctx, `Modified form written to ${options.output}`);
@@ -2637,7 +2637,7 @@ function registerExamplesCommand(program) {
2637
2637
  * Register the export command.
2638
2638
  */
2639
2639
  function registerExportCommand(program) {
2640
- program.command("export <file>").description("Export form as markform (default), markdown (readable), or json/yaml for structured data").option("--compact", "Output compact JSON (no formatting, only for JSON format)").action(async (file, options, cmd) => {
2640
+ program.command("export <file>").description("Export form as markform (default), markdown (readable), or json/yaml for structured data").option("--compact", "Output compact JSON (no formatting, only for JSON format)").option("--normalize", "Regenerate form without preserving external content").action(async (file, options, cmd) => {
2641
2641
  const ctx = getCommandContext(cmd);
2642
2642
  let format = "markform";
2643
2643
  if (ctx.format === "json") format = "json";
@@ -2650,7 +2650,7 @@ function registerExportCommand(program) {
2650
2650
  logVerbose(ctx, "Parsing form...");
2651
2651
  const form = parseForm(content);
2652
2652
  if (format === "markform") {
2653
- console.log(serializeForm(form));
2653
+ console.log(serializeForm(form, { preserveContent: !options.normalize }));
2654
2654
  return;
2655
2655
  }
2656
2656
  if (format === "markdown") {
@@ -2683,7 +2683,7 @@ function registerExportCommand(program) {
2683
2683
  schema,
2684
2684
  values,
2685
2685
  notes: form.notes,
2686
- markdown: serializeForm(form)
2686
+ markdown: serializeForm(form, { preserveContent: !options.normalize })
2687
2687
  };
2688
2688
  if (format === "json") if (options.compact) console.log(JSON.stringify(output));
2689
2689
  else console.log(JSON.stringify(output, null, 2));
@@ -2768,7 +2768,7 @@ function formatConsoleSession(transcript, useColors) {
2768
2768
  * Register the fill command.
2769
2769
  */
2770
2770
  function registerFillCommand(program) {
2771
- program.command("fill <file>").description("Run an agent to autonomously fill a form").option("--mock", "Use mock agent (requires --mock-source)").option("--model <id>", "Model ID for live agent (format: provider/model-id, e.g. openai/gpt-5-mini)").option("--mock-source <file>", "Path to completed form for mock agent").option("--record <file>", "Record session transcript to file").option("--max-turns <n>", `Maximum turns (default: ${DEFAULT_MAX_TURNS})`, String(DEFAULT_MAX_TURNS)).option("--max-patches <n>", `Maximum patches per turn (default: ${DEFAULT_MAX_PATCHES_PER_TURN})`, String(DEFAULT_MAX_PATCHES_PER_TURN)).option("--max-issues <n>", `Maximum issues shown per turn (default: ${DEFAULT_MAX_ISSUES_PER_TURN})`, String(DEFAULT_MAX_ISSUES_PER_TURN)).option("--max-fields <n>", "Maximum unique fields per turn (applied before --max-issues)").option("--max-groups <n>", "Maximum unique groups per turn (applied before --max-issues)").option("--roles <roles>", "Target roles to fill (comma-separated, or '*' for all; default: 'agent', or 'user' in --interactive mode)").option("--mode <mode>", "Fill mode: continue (skip filled fields) or overwrite (re-fill; default: continue)").option("-o, --output <file>", "Write final form to file").option("--prompt <file>", "Path to custom system prompt file (appends to default)").option("--instructions <text>", "Inline system prompt (appends to default; takes precedence over --prompt)").option("-i, --interactive", "Interactive mode: prompt user for field values (defaults to user role)").action(async (file, options, cmd) => {
2771
+ program.command("fill <file>").description("Run an agent to autonomously fill a form").option("--mock", "Use mock agent (requires --mock-source)").option("--model <id>", "Model ID for live agent (format: provider/model-id, e.g. openai/gpt-5-mini)").option("--mock-source <file>", "Path to completed form for mock agent").option("--record <file>", "Record session transcript to file").option("--max-turns <n>", `Maximum turns (default: ${DEFAULT_MAX_TURNS})`, String(DEFAULT_MAX_TURNS)).option("--max-patches <n>", `Maximum patches per turn (default: ${DEFAULT_MAX_PATCHES_PER_TURN})`, String(DEFAULT_MAX_PATCHES_PER_TURN)).option("--max-issues <n>", `Maximum issues shown per turn (default: ${DEFAULT_MAX_ISSUES_PER_TURN})`, String(DEFAULT_MAX_ISSUES_PER_TURN)).option("--max-fields <n>", "Maximum unique fields per turn (applied before --max-issues)").option("--max-groups <n>", "Maximum unique groups per turn (applied before --max-issues)").option("--roles <roles>", "Target roles to fill (comma-separated, or '*' for all; default: 'agent', or 'user' in --interactive mode)").option("--mode <mode>", "Fill mode: continue (skip filled fields) or overwrite (re-fill; default: continue)").option("-o, --output <file>", "Write final form to file").option("--prompt <file>", "Path to custom system prompt file (appends to default)").option("--instructions <text>", "Inline system prompt (appends to default; takes precedence over --prompt)").option("-i, --interactive", "Interactive mode: prompt user for field values (defaults to user role)").option("--normalize", "Regenerate form without preserving external content").action(async (file, options, cmd) => {
2772
2772
  const ctx = getCommandContext(cmd);
2773
2773
  const filePath = resolve(file);
2774
2774
  try {
@@ -3006,7 +3006,7 @@ function registerFillCommand(program) {
3006
3006
  await ensureFormsDir(formsDir);
3007
3007
  outputPath = generateVersionedPathInFormsDir(filePath, formsDir);
3008
3008
  }
3009
- const formMarkdown = serializeForm(harness.getForm());
3009
+ const formMarkdown = serializeForm(harness.getForm(), { preserveContent: !options.normalize });
3010
3010
  if (ctx.dryRun) logInfo(ctx, `[DRY RUN] Would write form to: ${outputPath}`);
3011
3011
  else {
3012
3012
  await writeFile(outputPath, formMarkdown);
@@ -3535,6 +3535,191 @@ function registerModelsCommand(program) {
3535
3535
  });
3536
3536
  }
3537
3537
 
3538
+ //#endregion
3539
+ //#region src/cli/commands/plan.ts
3540
+ /**
3541
+ * Get the response status string for a field.
3542
+ */
3543
+ function getFieldStatus(form, fieldId) {
3544
+ const response = form.responsesByFieldId[fieldId];
3545
+ if (!response) return "unanswered";
3546
+ return response.state;
3547
+ }
3548
+ /**
3549
+ * Check if a field still needs work (not yet answered).
3550
+ */
3551
+ function fieldNeedsWork(form, fieldId) {
3552
+ const response = form.responsesByFieldId[fieldId];
3553
+ if (!response) return true;
3554
+ return response.state !== "answered";
3555
+ }
3556
+ /**
3557
+ * Get all field IDs for an execution plan item.
3558
+ */
3559
+ function getFieldIdsForItem(form, item) {
3560
+ if (item.itemType === "field") return [item.itemId];
3561
+ const group = form.schema.groups.find((g) => g.id === item.itemId);
3562
+ if (!group) return [];
3563
+ return group.children.map((f) => f.id);
3564
+ }
3565
+ /**
3566
+ * Get field metadata from the form schema.
3567
+ */
3568
+ function getFieldMeta(form, fieldId) {
3569
+ for (const group of form.schema.groups) {
3570
+ const field = group.children.find((f) => f.id === fieldId);
3571
+ if (field) return field;
3572
+ }
3573
+ }
3574
+ /**
3575
+ * Build a PlanItemJson, including only fields that need work.
3576
+ * Returns undefined if no fields need work.
3577
+ */
3578
+ function buildPlanItem(form, item) {
3579
+ const remainingFieldIds = getFieldIdsForItem(form, item).filter((id) => fieldNeedsWork(form, id));
3580
+ if (remainingFieldIds.length === 0) return;
3581
+ const planItem = {
3582
+ itemId: item.itemId,
3583
+ itemType: item.itemType
3584
+ };
3585
+ if (item.itemType === "group") planItem.fields = remainingFieldIds.map((id) => {
3586
+ const meta = getFieldMeta(form, id);
3587
+ return {
3588
+ fieldId: id,
3589
+ label: meta?.label,
3590
+ status: getFieldStatus(form, id),
3591
+ required: meta?.required ?? false
3592
+ };
3593
+ });
3594
+ return planItem;
3595
+ }
3596
+ function formatConsolePlan(report, useColors) {
3597
+ const lines = [];
3598
+ const bold = useColors ? pc.bold : (s$1) => s$1;
3599
+ const dim = useColors ? pc.dim : (s$1) => s$1;
3600
+ const cyan = useColors ? pc.cyan : (s$1) => s$1;
3601
+ const yellow = useColors ? pc.yellow : (s$1) => s$1;
3602
+ const titlePart = report.title ? ` (${report.title})` : "";
3603
+ lines.push(bold(cyan(`Plan: ${report.formId}${titlePart}`)));
3604
+ lines.push("");
3605
+ if (report.orderLevels.length === 0) {
3606
+ lines.push(dim("No remaining work — all fields are complete."));
3607
+ return lines.join("\n");
3608
+ }
3609
+ for (const level of report.orderLevels) {
3610
+ const itemCount = level.looseSerial.length + level.parallelBatches.reduce((sum, b) => sum + b.items.length, 0);
3611
+ lines.push(bold(`Order level ${level.order} (${itemCount} items):`));
3612
+ if (level.looseSerial.length > 0) {
3613
+ lines.push(` Loose serial (primary agent):`);
3614
+ for (const item of level.looseSerial) formatItem(lines, item, dim, yellow, " ");
3615
+ }
3616
+ for (const batch of level.parallelBatches) {
3617
+ lines.push(` Parallel batch "${batch.batchId}" (${batch.items.length} items, ${batch.items.length} agents):`);
3618
+ for (const item of batch.items) formatItem(lines, item, dim, yellow, " ");
3619
+ }
3620
+ lines.push("");
3621
+ }
3622
+ const s = report.summary;
3623
+ lines.push(dim(`Summary: ${s.orderLevelCount} order level${s.orderLevelCount !== 1 ? "s" : ""}, ${s.parallelBatchCount} parallel batch${s.parallelBatchCount !== 1 ? "es" : ""}, ${s.remainingFields} remaining field${s.remainingFields !== 1 ? "s" : ""}`));
3624
+ return lines.join("\n");
3625
+ }
3626
+ function formatItem(lines, item, dim, yellow, indent) {
3627
+ if (item.itemType === "group" && item.fields) {
3628
+ lines.push(`${indent}- ${item.itemId} [group]`);
3629
+ for (const f of item.fields) {
3630
+ const label = f.label ? ` (${f.label})` : "";
3631
+ const req = f.required ? yellow("required") + ", " : "";
3632
+ lines.push(`${indent} ${f.fieldId}${label} — ${req}${dim(f.status)}`);
3633
+ }
3634
+ } else {
3635
+ const meta = item;
3636
+ lines.push(`${indent}- ${meta.itemId}`);
3637
+ }
3638
+ }
3639
+ /**
3640
+ * Register the plan command.
3641
+ */
3642
+ function registerPlanCommand(program) {
3643
+ program.command("plan <file>").description("Show the idealized execution plan for a form (parallel batches, order levels)").action(async (file, _options, cmd) => {
3644
+ const ctx = getCommandContext(cmd);
3645
+ try {
3646
+ logVerbose(ctx, `Reading file: ${file}`);
3647
+ const content = await readFile$1(file);
3648
+ logVerbose(ctx, "Parsing and validating form...");
3649
+ const form = parseForm(content);
3650
+ const parseErrors = inspect(form).issues.filter((i) => i.reason === "validation_error");
3651
+ if (parseErrors.length > 0) {
3652
+ logError(`Form has validation errors. Fix them before planning:\n` + parseErrors.map((e) => ` - ${e.message}`).join("\n"));
3653
+ process.exit(1);
3654
+ }
3655
+ logVerbose(ctx, "Computing execution plan...");
3656
+ const executionPlan = computeExecutionPlan(form);
3657
+ const orderLevels = [];
3658
+ let totalItems = 0;
3659
+ let totalRemainingFields = 0;
3660
+ let totalBatches = 0;
3661
+ for (const order of executionPlan.orderLevels) {
3662
+ const looseItems = [];
3663
+ for (const item of executionPlan.looseSerial) {
3664
+ if (item.order !== order) continue;
3665
+ const planItem = buildPlanItem(form, item);
3666
+ if (planItem) {
3667
+ looseItems.push(planItem);
3668
+ totalItems++;
3669
+ totalRemainingFields += countRemainingFields(form, item);
3670
+ }
3671
+ }
3672
+ const batches = [];
3673
+ for (const batch of executionPlan.parallelBatches) {
3674
+ const batchItems = [];
3675
+ for (const item of batch.items) {
3676
+ if (item.order !== order) continue;
3677
+ const planItem = buildPlanItem(form, item);
3678
+ if (planItem) {
3679
+ batchItems.push(planItem);
3680
+ totalItems++;
3681
+ totalRemainingFields += countRemainingFields(form, item);
3682
+ }
3683
+ }
3684
+ if (batchItems.length > 0) {
3685
+ batches.push({
3686
+ batchId: batch.batchId,
3687
+ items: batchItems
3688
+ });
3689
+ totalBatches++;
3690
+ }
3691
+ }
3692
+ if (looseItems.length > 0 || batches.length > 0) orderLevels.push({
3693
+ order,
3694
+ looseSerial: looseItems,
3695
+ parallelBatches: batches
3696
+ });
3697
+ }
3698
+ const output = formatOutput(ctx, {
3699
+ formId: form.schema.id,
3700
+ title: form.schema.title,
3701
+ orderLevels,
3702
+ summary: {
3703
+ orderLevelCount: orderLevels.length,
3704
+ parallelBatchCount: totalBatches,
3705
+ totalItems,
3706
+ remainingFields: totalRemainingFields
3707
+ }
3708
+ }, (data, useColors) => formatConsolePlan(data, useColors));
3709
+ console.log(output);
3710
+ } catch (error) {
3711
+ logError(error instanceof Error ? error.message : String(error));
3712
+ process.exit(1);
3713
+ }
3714
+ });
3715
+ }
3716
+ /**
3717
+ * Count remaining fields for an execution plan item.
3718
+ */
3719
+ function countRemainingFields(form, item) {
3720
+ return getFieldIdsForItem(form, item).filter((id) => fieldNeedsWork(form, id)).length;
3721
+ }
3722
+
3538
3723
  //#endregion
3539
3724
  //#region src/cli/commands/serve.ts
3540
3725
  /**
@@ -5664,7 +5849,7 @@ function registerResearchCommand(program) {
5664
5849
  console.log(` ${formPath} ${pc.dim("(filled markform source)")}`);
5665
5850
  console.log(` ${schemaPath} ${pc.dim("(JSON Schema)")}`);
5666
5851
  if (options.transcript && result.transcript) {
5667
- const { serializeSession: serializeSession$1 } = await import("./session-B7aR6hno.mjs");
5852
+ const { serializeSession: serializeSession$1 } = await import("./session-CW9AQw6i.mjs");
5668
5853
  const transcriptPath = outputPath.replace(/\.form\.md$/, ".session.yaml");
5669
5854
  const { writeFile: writeFile$1 } = await import("./shared-fUKfJ1UA.mjs");
5670
5855
  await writeFile$1(transcriptPath, serializeSession$1(result.transcript));
@@ -6053,6 +6238,7 @@ function createProgram() {
6053
6238
  registerFillCommand(program);
6054
6239
  registerInspectCommand(program);
6055
6240
  registerModelsCommand(program);
6241
+ registerPlanCommand(program);
6056
6242
  registerRenderCommand(program);
6057
6243
  registerReportCommand(program);
6058
6244
  registerResearchCommand(program);
@@ -6072,4 +6258,4 @@ async function runCli() {
6072
6258
 
6073
6259
  //#endregion
6074
6260
  export { runCli as t };
6075
- //# sourceMappingURL=cli-BsFessUW.mjs.map
6261
+ //# sourceMappingURL=cli-D9w0Bp4J.mjs.map