@c4a/context-cli 0.7.105 → 0.7.106

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 (30) hide show
  1. package/cli.js +200 -161
  2. package/indexers/contracts/profile-contract.json +245 -245
  3. package/indexers/release-manifest.json +1 -1
  4. package/package.json +12 -12
  5. package/plugins/VERSION +1 -1
  6. package/plugins/claude/.claude-plugin/plugin.json +1 -1
  7. package/plugins/claude/commands/context.md +7 -5
  8. package/plugins/claude/resources/context/routine-update.md +37 -26
  9. package/plugins/claude/skills/context-plan/SKILL.md +4 -2
  10. package/plugins/claude/skills/context-plan/references/project-planning.md +9 -1
  11. package/plugins/codex/.codex-plugin/plugin.json +2 -2
  12. package/plugins/codex/skills/context/SKILL.md +7 -5
  13. package/plugins/codex/skills/context/references/routine-update.md +37 -26
  14. package/plugins/codex/skills/context-plan/SKILL.md +4 -2
  15. package/plugins/codex/skills/context-plan/references/project-planning.md +9 -1
  16. package/plugins/cursor/.cursor-plugin/plugin.json +1 -1
  17. package/plugins/cursor/commands/c4a-context.md +7 -5
  18. package/plugins/cursor/resources/context/routine-update.md +37 -26
  19. package/plugins/cursor/skills/context-plan/SKILL.md +4 -2
  20. package/plugins/cursor/skills/context-plan/references/project-planning.md +9 -1
  21. package/plugins/skills/context/SKILL.md +7 -5
  22. package/plugins/skills/context/references/routine-update.md +37 -26
  23. package/plugins/skills/context-plan/SKILL.md +4 -2
  24. package/plugins/skills/context-plan/references/project-planning.md +9 -1
  25. package/providers/context/manifest.json +10 -10
  26. package/providers/context/provider.yaml +1 -1
  27. package/providers/context/resources/manuals/guides/knowledge-updates.md +66 -0
  28. package/providers/context/resources/procedures/approved-revision.md +6 -1
  29. package/providers/context/resources/procedures/knowledge-updates.md +66 -0
  30. package/providers/context/resources/procedures/source-update.md +14 -0
package/cli.js CHANGED
@@ -71021,10 +71021,7 @@ async function registeredRepoHistoryReader(projectRoot) {
71021
71021
  const entry = registry2.repos.find((item) => item.id === name2 || item.name === name2);
71022
71022
  if (!entry)
71023
71023
  throw new TypeError(`Source is not a registered repository: ${sourceRef}`);
71024
- root = realpath6(resolve19(workspace, entry.materializedAt)).then((actual) => {
71025
- inside(workspace, actual);
71026
- return actual;
71027
- });
71024
+ root = realpath6(resolve19(workspace, entry.materializedAt));
71028
71025
  roots.set(sourceRef, root);
71029
71026
  }
71030
71027
  const directory = await root;
@@ -71080,7 +71077,8 @@ async function registeredArticleSourceReader(projectRoot) {
71080
71077
  throw new SourceReadError(`The registered source checkout of ${sourceRef} is not accessible. Restore the source before checking citations.`, "context source recovery-plan --format json");
71081
71078
  throw error;
71082
71079
  });
71083
- inside(workspace, root);
71080
+ if (kind !== "repo")
71081
+ inside(workspace, root);
71084
71082
  if (managed)
71085
71083
  return { root, files: new Map([[basename3(entry.materializedAt), ""]]) };
71086
71084
  if (kind === "repo") {
@@ -78549,6 +78547,154 @@ var init_referenceRangeMap = __esm(() => {
78549
78547
  exec2 = promisify4(execFile5);
78550
78548
  });
78551
78549
 
78550
+ // src/project/productionFeedback.ts
78551
+ var exports_productionFeedback = {};
78552
+ __export(exports_productionFeedback, {
78553
+ withProductionFeedback: () => withProductionFeedback,
78554
+ SubmissionInputErrors: () => SubmissionInputErrors,
78555
+ SubmissionInputError: () => SubmissionInputError
78556
+ });
78557
+ async function withProductionFeedback(input, run) {
78558
+ try {
78559
+ return await run();
78560
+ } catch (error) {
78561
+ const schemaError = error instanceof ZodError;
78562
+ const inputError = error instanceof SubmissionInputError;
78563
+ const syntaxError = error instanceof import_yaml15.YAMLParseError;
78564
+ const existing = error instanceof ContextError ? error : undefined;
78565
+ const ioCode = error?.code;
78566
+ const detail = {
78567
+ category: schemaError || syntaxError || inputError ? ErrorCategory.UserInputInvalid : ErrorCategory.WorkspaceStateInvalid,
78568
+ reason_code: `production-${input.operation}-failed`,
78569
+ next_action: { command: "context status --format json", ...input.recovery ? { instruction: input.recovery } : inputError ? { instruction: "Correct the reported item in the input file and resubmit it with the same revision." } : {} },
78570
+ ...input.file ? { file: input.file } : {},
78571
+ ...schemaError ? { issues: error.issues.map((issue) => ({ path: issue.path, message: issue.message })) } : {},
78572
+ ...inputError ? { issues: [{ path: error.path, message: error.message }], ...error.reason ? { reason_code: error.reason } : {} } : {},
78573
+ ...syntaxError && error.linePos ? { location: error.linePos } : {},
78574
+ ...typeof ioCode === "string" ? { io_code: ioCode } : {},
78575
+ ...existing?.detail
78576
+ };
78577
+ if (input.schema && detail.input_schema === undefined) {
78578
+ detail.input_schema = zodToJsonSchema(input.schema, { $refStrategy: "none" });
78579
+ }
78580
+ throw new ContextError(existing?.code ?? (schemaError || syntaxError || inputError ? ExitCode.UserError : ExitCode.WorkspaceStateError), error instanceof Error ? error.message : String(error), detail);
78581
+ }
78582
+ }
78583
+ var import_yaml15, SubmissionInputError, SubmissionInputErrors;
78584
+ var init_productionFeedback = __esm(() => {
78585
+ init_zod();
78586
+ init_esm();
78587
+ init_errors3();
78588
+ init_cliFeedback();
78589
+ init_exitCode();
78590
+ import_yaml15 = __toESM(require_dist(), 1);
78591
+ SubmissionInputError = class SubmissionInputError extends TypeError {
78592
+ path;
78593
+ reason;
78594
+ constructor(message, path2 = [], reason) {
78595
+ super(message);
78596
+ this.path = path2;
78597
+ this.reason = reason;
78598
+ }
78599
+ };
78600
+ SubmissionInputErrors = class SubmissionInputErrors extends SubmissionInputError {
78601
+ errors;
78602
+ constructor(errors4) {
78603
+ super(`${errors4.length} problems: ${errors4.map((error, index2) => `(${index2 + 1}) ${error.message}`).join(" ")}`, errors4[0]?.path ?? [], errors4[0]?.reason);
78604
+ this.errors = errors4;
78605
+ }
78606
+ };
78607
+ });
78608
+
78609
+ // src/project/submittedSourceLocator.ts
78610
+ function assertNoCaptureGap(locator, capturedText) {
78611
+ const lines = capturedText.replace(/\r\n/gu, `
78612
+ `).split(`
78613
+ `).slice(locator.start_line - 1, locator.end_line);
78614
+ const gapOnly = (line) => CAPTURE_GAP.test(line) && line.replace(new RegExp(CAPTURE_GAP.source, "gu"), "").replace(/<br\s*\/?>|[|>\s]/giu, "") === "";
78615
+ const gap = lines.findIndex(gapOnly);
78616
+ if (gap >= 0)
78617
+ throw new SubmissionInputError(`${locator.path}:${locator.start_line + gap} is a capture gap (the resource was not captured), ` + "not evidence. Cite only captured lines; the missing content cannot support a claim until it is captured.");
78618
+ }
78619
+ function exactQuoteLocator(locator, capturedText, maxLength) {
78620
+ const text5 = capturedText.replace(/\r\n/gu, `
78621
+ `);
78622
+ try {
78623
+ const quote2 = articleSourceRegion(text5, locator);
78624
+ if (quote2.trim() === "" || quote2.length > maxLength)
78625
+ return;
78626
+ const resolved = resolveSubmittedSourceLocator({ path: locator.path, quote: quote2 }, text5);
78627
+ if (resolved.start_line !== locator.start_line || resolved.end_line !== locator.end_line)
78628
+ return;
78629
+ assertNoCaptureGap(resolved, text5);
78630
+ return { path: locator.path, quote: quote2 };
78631
+ } catch {
78632
+ return;
78633
+ }
78634
+ }
78635
+ function resolveSubmittedSourceLocator(input, capturedText) {
78636
+ const locator = submittedSourceLocatorSchema.parse(input);
78637
+ if ("start_line" in locator)
78638
+ return locator;
78639
+ const text5 = capturedText.replace(/\r\n/gu, `
78640
+ `);
78641
+ const lines = text5.split(`
78642
+ `);
78643
+ const matches = [];
78644
+ if ("quote" in locator) {
78645
+ const quote2 = locator.quote.replace(/\r\n/gu, `
78646
+ `);
78647
+ for (let offset2 = text5.indexOf(quote2);offset2 >= 0; offset2 = text5.indexOf(quote2, offset2 + 1)) {
78648
+ matches.push({
78649
+ start_line: text5.slice(0, offset2).split(`
78650
+ `).length,
78651
+ end_line: text5.slice(0, offset2 + quote2.length - 1).split(`
78652
+ `).length
78653
+ });
78654
+ }
78655
+ } else {
78656
+ if (!/\.(?:md|markdown|mdx)$/iu.test(locator.path))
78657
+ throw new SubmissionInputError("heading requires a Markdown source; use quote or start_line/end_line instead.");
78658
+ const marked = /^(#{1,6})[ \t]+(.+)$/u.exec(locator.heading.trim());
78659
+ const wanted = { level: marked?.[1].length, title: (marked?.[2] ?? locator.heading).trim() };
78660
+ const headings = [];
78661
+ let fence;
78662
+ for (const [index2, line] of lines.entries()) {
78663
+ const marker = /^ {0,3}(`{3,}|~{3,})(.*)$/u.exec(line);
78664
+ if (fence) {
78665
+ if (marker && marker[1][0] === fence.character && marker[1].length >= fence.length && !marker[2].trim())
78666
+ fence = undefined;
78667
+ continue;
78668
+ }
78669
+ if (marker) {
78670
+ fence = { character: marker[1][0], length: marker[1].length };
78671
+ continue;
78672
+ }
78673
+ const match = /^ {0,3}(#{1,6})(?:[ \t]+(.*)|[ \t]*)$/u.exec(line);
78674
+ if (match)
78675
+ headings.push({ line: index2 + 1, level: match[1].length, title: (match[2] ?? "").replace(/[ \t]+#+[ \t]*$/u, "").trim() });
78676
+ }
78677
+ for (const [index2, heading] of headings.entries()) {
78678
+ if (heading.title !== wanted.title || wanted.level !== undefined && heading.level !== wanted.level)
78679
+ continue;
78680
+ let end = (headings.slice(index2 + 1).find((next) => next.level <= heading.level)?.line ?? lines.length + 1) - 1;
78681
+ while (end > heading.line && !lines[end - 1].trim())
78682
+ end--;
78683
+ matches.push({ start_line: heading.line, end_line: end });
78684
+ }
78685
+ }
78686
+ if (matches.length !== 1)
78687
+ throw new SubmissionInputError(`Source locator matched ${matches.length} regions in ${locator.path}; candidates: ${matches.slice(0, 5).map((m) => `${m.start_line}-${m.end_line}`).join(", ") || "none"}. Use a unique heading/quote or explicit start_line/end_line.`);
78688
+ return articleSourceLocatorSchema.parse({ path: locator.path, ...matches[0] });
78689
+ }
78690
+ var submittedSourceLocatorSchema, CAPTURE_GAP;
78691
+ var init_submittedSourceLocator = __esm(() => {
78692
+ init_src2();
78693
+ init_productionFeedback();
78694
+ submittedSourceLocatorSchema = articleSourceLocatorInputSchema;
78695
+ CAPTURE_GAP = /(?:> ?)?Resource unavailable: .+? \([^;()]+; [^()]+\)\. <!-- [^>]+ -->/u;
78696
+ });
78697
+
78552
78698
  // src/project/articleReferenceObservation.ts
78553
78699
  import { createHash as createHash13 } from "node:crypto";
78554
78700
  import { execFile as execFile6 } from "node:child_process";
@@ -78622,14 +78768,14 @@ async function suggestedRange(root, reference2, before, current3, cited, clip =
78622
78768
  locator: { path: mapped.path, start_line: mapped.start_line, end_line: mapped.end_line },
78623
78769
  message: "The source diff maps the old lines here. If this text still supports the section, cite this locator; it is checked again on submit."
78624
78770
  };
78625
- const unique = region.trim() !== "" && normalized.indexOf(region) === normalized.lastIndexOf(region);
78626
- if (!unique || region.length > 4000)
78771
+ const quote2 = exactQuoteLocator(mapped, normalized, 4000);
78772
+ if (!quote2)
78627
78773
  return;
78628
78774
  return {
78629
78775
  start_line: mapped.start_line,
78630
78776
  end_line: mapped.end_line,
78631
78777
  ...clip(region),
78632
- locator: { path: mapped.path, quote: region },
78778
+ locator: quote2,
78633
78779
  message: "An earlier citation used these line numbers, and repeating them keeps that earlier evidence; to cite the new text here, use this quote locator."
78634
78780
  };
78635
78781
  }
@@ -78733,6 +78879,7 @@ var init_articleReferenceObservation = __esm(() => {
78733
78879
  init_articleSourceReader();
78734
78880
  init_gitObjectReader();
78735
78881
  init_referenceRangeMap();
78882
+ init_submittedSourceLocator();
78736
78883
  LOCAL_SOURCE_REASONS = {
78737
78884
  "source-content-missing": "The cited file contents are not downloaded in the source checkout.",
78738
78885
  "source-history-missing": "The registered commit is not in the source checkout."
@@ -79001,7 +79148,7 @@ async function writeRepoRegistry(projectRoot, registry2) {
79001
79148
  modules.push(registryRecordToYaml(record4));
79002
79149
  namespaces.set(record4.namespace, modules);
79003
79150
  }
79004
- await atomicWriteFile(path2, import_yaml15.default.stringify({
79151
+ await atomicWriteFile(path2, import_yaml16.default.stringify({
79005
79152
  sources: [...namespaces].map(([name2, modules]) => ({ name: name2, modules }))
79006
79153
  }));
79007
79154
  }
@@ -79024,14 +79171,14 @@ function registryRecordToYaml(record4) {
79024
79171
  }
79025
79172
  return output;
79026
79173
  }
79027
- var import_yaml15, SOURCE_NAME_PATTERN2, REPO_DATE_NAMESPACE_PATTERN2;
79174
+ var import_yaml16, SOURCE_NAME_PATTERN2, REPO_DATE_NAMESPACE_PATTERN2;
79028
79175
  var init_repoSourceRegistry = __esm(() => {
79029
79176
  init_src2();
79030
79177
  init_cliFeedback();
79031
79178
  init_errors3();
79032
79179
  init_exitCode();
79033
79180
  init_atomicWrite();
79034
- import_yaml15 = __toESM(require_dist(), 1);
79181
+ import_yaml16 = __toESM(require_dist(), 1);
79035
79182
  SOURCE_NAME_PATTERN2 = /^[a-z0-9][a-z0-9._-]*$/u;
79036
79183
  REPO_DATE_NAMESPACE_PATTERN2 = /^\d{8}$/u;
79037
79184
  });
@@ -80242,7 +80389,7 @@ async function readProductionSubmission(input) {
80242
80389
  throw invalidFile(input.path, "Manifest exceeds its transport budget.");
80243
80390
  let value;
80244
80391
  try {
80245
- value = productionSubmissionSchema.parse(import_yaml16.default.parse(manifest.text));
80392
+ value = productionSubmissionSchema.parse(import_yaml17.default.parse(manifest.text));
80246
80393
  } catch (error) {
80247
80394
  throw invalidFile(input.path, `Invalid submission manifest: ${error instanceof Error ? error.message : String(error)}`);
80248
80395
  }
@@ -80288,7 +80435,7 @@ async function readProductionSubmission(input) {
80288
80435
  }
80289
80436
  return { stage: value.stage, tasks: fixed, bytes };
80290
80437
  }
80291
- var import_yaml16, localId, filePath, productionSubmissionSchema, DEFAULT_LIMITS;
80438
+ var import_yaml17, localId, filePath, productionSubmissionSchema, DEFAULT_LIMITS;
80292
80439
  var init_productionSubmissionFiles = __esm(() => {
80293
80440
  init_zod();
80294
80441
  init_errors3();
@@ -80296,7 +80443,7 @@ var init_productionSubmissionFiles = __esm(() => {
80296
80443
  init_exitCode();
80297
80444
  init_durableSingleFileTransaction();
80298
80445
  init_durableMultiFileTransaction();
80299
- import_yaml16 = __toESM(require_dist(), 1);
80446
+ import_yaml17 = __toESM(require_dist(), 1);
80300
80447
  localId = exports_external.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/u);
80301
80448
  filePath = exports_external.string().min(1);
80302
80449
  productionSubmissionSchema = exports_external.object({
@@ -80320,7 +80467,7 @@ import { readFile as readFile26 } from "node:fs/promises";
80320
80467
  import { join as join29 } from "node:path";
80321
80468
  function emptyEdits(text5) {
80322
80469
  try {
80323
- const value = import_yaml17.default.parse(text5);
80470
+ const value = import_yaml18.default.parse(text5);
80324
80471
  return Array.isArray(value?.edits) && value.edits.length === 0 && Object.keys(value).length === 1;
80325
80472
  } catch {
80326
80473
  return false;
@@ -80351,11 +80498,11 @@ async function previousProductionDrafts(root, stage, tasks = stage.tasks) {
80351
80498
  }
80352
80499
  return result;
80353
80500
  }
80354
- var import_yaml17;
80501
+ var import_yaml18;
80355
80502
  var init_productionDraftMigration = __esm(() => {
80356
80503
  init_productionSubmissionFiles();
80357
80504
  init_durableMultiFileTransaction();
80358
- import_yaml17 = __toESM(require_dist(), 1);
80505
+ import_yaml18 = __toESM(require_dist(), 1);
80359
80506
  });
80360
80507
 
80361
80508
  // src/project/lifecyclePaths.ts
@@ -80614,7 +80761,7 @@ function parseFrontmatter2(content3) {
80614
80761
  if (match?.[1] === undefined)
80615
80762
  return;
80616
80763
  try {
80617
- const parsed = import_yaml18.default.parse(match[1]);
80764
+ const parsed = import_yaml19.default.parse(match[1]);
80618
80765
  if (!isRecord8(parsed))
80619
80766
  return;
80620
80767
  return { record: parsed, body: content3.slice(match[0].length) };
@@ -80668,7 +80815,7 @@ function hydrateApprovedKnowledgeMarkdown(input) {
80668
80815
  return input.content;
80669
80816
  }
80670
80817
  return `---
80671
- ${import_yaml18.default.stringify(frontmatter).trimEnd()}
80818
+ ${import_yaml19.default.stringify(frontmatter).trimEnd()}
80672
80819
  ---
80673
80820
  ${parsed.body}`;
80674
80821
  }
@@ -80683,7 +80830,7 @@ function compactApprovedKnowledgeMarkdown(content3) {
80683
80830
  ...typeof compact.title === "string" ? { title: compact.title } : {}
80684
80831
  });
80685
80832
  return `---
80686
- ${import_yaml18.default.stringify(compact).trimEnd()}
80833
+ ${import_yaml19.default.stringify(compact).trimEnd()}
80687
80834
  ---
80688
80835
  ${parsed.body}`;
80689
80836
  }
@@ -80701,17 +80848,17 @@ function ensureApprovedKnowledgePresentation(content3) {
80701
80848
  if (parsed.record.description === description && parsed.body === body)
80702
80849
  return content3;
80703
80850
  return `---
80704
- ${import_yaml18.default.stringify({ ...parsed.record, description }).trimEnd()}
80851
+ ${import_yaml19.default.stringify({ ...parsed.record, description }).trimEnd()}
80705
80852
  ---
80706
80853
  ${body}`;
80707
80854
  }
80708
- var import_yaml18, STRUCTURE_PATH, FRONTMATTER_RE2, COMPACT_FIELDS;
80855
+ var import_yaml19, STRUCTURE_PATH, FRONTMATTER_RE2, COMPACT_FIELDS;
80709
80856
  var init_approvedKnowledgeMetadata = __esm(() => {
80710
80857
  init_approvedFileRead();
80711
80858
  init_commandReadCache();
80712
80859
  init_src2();
80713
80860
  init_packageKnowledgeProjection();
80714
- import_yaml18 = __toESM(require_dist(), 1);
80861
+ import_yaml19 = __toESM(require_dist(), 1);
80715
80862
  STRUCTURE_PATH = join32("knowledge", "structure.yaml");
80716
80863
  FRONTMATTER_RE2 = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/u;
80717
80864
  COMPACT_FIELDS = new Set([
@@ -80785,65 +80932,6 @@ var init_productionArticleTarget = __esm(() => {
80785
80932
  init_durableSingleFileTransaction();
80786
80933
  });
80787
80934
 
80788
- // src/project/productionFeedback.ts
80789
- var exports_productionFeedback = {};
80790
- __export(exports_productionFeedback, {
80791
- withProductionFeedback: () => withProductionFeedback,
80792
- SubmissionInputErrors: () => SubmissionInputErrors,
80793
- SubmissionInputError: () => SubmissionInputError
80794
- });
80795
- async function withProductionFeedback(input, run) {
80796
- try {
80797
- return await run();
80798
- } catch (error) {
80799
- const schemaError2 = error instanceof ZodError;
80800
- const inputError = error instanceof SubmissionInputError;
80801
- const syntaxError = error instanceof import_yaml19.YAMLParseError;
80802
- const existing = error instanceof ContextError ? error : undefined;
80803
- const ioCode = error?.code;
80804
- const detail = {
80805
- category: schemaError2 || syntaxError || inputError ? ErrorCategory.UserInputInvalid : ErrorCategory.WorkspaceStateInvalid,
80806
- reason_code: `production-${input.operation}-failed`,
80807
- next_action: { command: "context status --format json", ...input.recovery ? { instruction: input.recovery } : inputError ? { instruction: "Correct the reported item in the input file and resubmit it with the same revision." } : {} },
80808
- ...input.file ? { file: input.file } : {},
80809
- ...schemaError2 ? { issues: error.issues.map((issue) => ({ path: issue.path, message: issue.message })) } : {},
80810
- ...inputError ? { issues: [{ path: error.path, message: error.message }], ...error.reason ? { reason_code: error.reason } : {} } : {},
80811
- ...syntaxError && error.linePos ? { location: error.linePos } : {},
80812
- ...typeof ioCode === "string" ? { io_code: ioCode } : {},
80813
- ...existing?.detail
80814
- };
80815
- if (input.schema && detail.input_schema === undefined) {
80816
- detail.input_schema = zodToJsonSchema(input.schema, { $refStrategy: "none" });
80817
- }
80818
- throw new ContextError(existing?.code ?? (schemaError2 || syntaxError || inputError ? ExitCode.UserError : ExitCode.WorkspaceStateError), error instanceof Error ? error.message : String(error), detail);
80819
- }
80820
- }
80821
- var import_yaml19, SubmissionInputError, SubmissionInputErrors;
80822
- var init_productionFeedback = __esm(() => {
80823
- init_zod();
80824
- init_esm();
80825
- init_errors3();
80826
- init_cliFeedback();
80827
- init_exitCode();
80828
- import_yaml19 = __toESM(require_dist(), 1);
80829
- SubmissionInputError = class SubmissionInputError extends TypeError {
80830
- path;
80831
- reason;
80832
- constructor(message, path2 = [], reason) {
80833
- super(message);
80834
- this.path = path2;
80835
- this.reason = reason;
80836
- }
80837
- };
80838
- SubmissionInputErrors = class SubmissionInputErrors extends SubmissionInputError {
80839
- errors;
80840
- constructor(errors4) {
80841
- super(`${errors4.length} problems: ${errors4.map((error, index2) => `(${index2 + 1}) ${error.message}`).join(" ")}`, errors4[0]?.path ?? [], errors4[0]?.reason);
80842
- this.errors = errors4;
80843
- }
80844
- };
80845
- });
80846
-
80847
80935
  // src/project/productionStage.ts
80848
80936
  function productionTaskInput(task) {
80849
80937
  return indexerProtocolDigest({
@@ -81654,83 +81742,10 @@ var init_productionPlanningMaterials = __esm(() => {
81654
81742
  markdownParser = unified().use(remarkParse);
81655
81743
  });
81656
81744
 
81657
- // src/project/submittedSourceLocator.ts
81658
- function assertNoCaptureGap(locator, capturedText) {
81659
- const lines = capturedText.replace(/\r\n/gu, `
81660
- `).split(`
81661
- `).slice(locator.start_line - 1, locator.end_line);
81662
- const gapOnly = (line) => CAPTURE_GAP.test(line) && line.replace(new RegExp(CAPTURE_GAP.source, "gu"), "").replace(/<br\s*\/?>|[|>\s]/giu, "") === "";
81663
- const gap = lines.findIndex(gapOnly);
81664
- if (gap >= 0)
81665
- throw new SubmissionInputError(`${locator.path}:${locator.start_line + gap} is a capture gap (the resource was not captured), ` + "not evidence. Cite only captured lines; the missing content cannot support a claim until it is captured.");
81666
- }
81667
- function resolveSubmittedSourceLocator(input, capturedText) {
81668
- const locator = submittedSourceLocatorSchema.parse(input);
81669
- if ("start_line" in locator)
81670
- return locator;
81671
- const text5 = capturedText.replace(/\r\n/gu, `
81672
- `);
81673
- const lines = text5.split(`
81674
- `);
81675
- const matches = [];
81676
- if ("quote" in locator) {
81677
- const quote2 = locator.quote.replace(/\r\n/gu, `
81678
- `);
81679
- for (let offset2 = text5.indexOf(quote2);offset2 >= 0; offset2 = text5.indexOf(quote2, offset2 + 1)) {
81680
- matches.push({
81681
- start_line: text5.slice(0, offset2).split(`
81682
- `).length,
81683
- end_line: text5.slice(0, offset2 + quote2.length - 1).split(`
81684
- `).length
81685
- });
81686
- }
81687
- } else {
81688
- if (!/\.(?:md|markdown|mdx)$/iu.test(locator.path))
81689
- throw new SubmissionInputError("heading requires a Markdown source; use quote or start_line/end_line instead.");
81690
- const marked = /^(#{1,6})[ \t]+(.+)$/u.exec(locator.heading.trim());
81691
- const wanted = { level: marked?.[1].length, title: (marked?.[2] ?? locator.heading).trim() };
81692
- const headings = [];
81693
- let fence;
81694
- for (const [index2, line] of lines.entries()) {
81695
- const marker = /^ {0,3}(`{3,}|~{3,})(.*)$/u.exec(line);
81696
- if (fence) {
81697
- if (marker && marker[1][0] === fence.character && marker[1].length >= fence.length && !marker[2].trim())
81698
- fence = undefined;
81699
- continue;
81700
- }
81701
- if (marker) {
81702
- fence = { character: marker[1][0], length: marker[1].length };
81703
- continue;
81704
- }
81705
- const match = /^ {0,3}(#{1,6})(?:[ \t]+(.*)|[ \t]*)$/u.exec(line);
81706
- if (match)
81707
- headings.push({ line: index2 + 1, level: match[1].length, title: (match[2] ?? "").replace(/[ \t]+#+[ \t]*$/u, "").trim() });
81708
- }
81709
- for (const [index2, heading] of headings.entries()) {
81710
- if (heading.title !== wanted.title || wanted.level !== undefined && heading.level !== wanted.level)
81711
- continue;
81712
- let end = (headings.slice(index2 + 1).find((next) => next.level <= heading.level)?.line ?? lines.length + 1) - 1;
81713
- while (end > heading.line && !lines[end - 1].trim())
81714
- end--;
81715
- matches.push({ start_line: heading.line, end_line: end });
81716
- }
81717
- }
81718
- if (matches.length !== 1)
81719
- throw new SubmissionInputError(`Source locator matched ${matches.length} regions in ${locator.path}; candidates: ${matches.slice(0, 5).map((m) => `${m.start_line}-${m.end_line}`).join(", ") || "none"}. Use a unique heading/quote or explicit start_line/end_line.`);
81720
- return articleSourceLocatorSchema.parse({ path: locator.path, ...matches[0] });
81721
- }
81722
- var submittedSourceLocatorSchema, CAPTURE_GAP;
81723
- var init_submittedSourceLocator = __esm(() => {
81724
- init_src2();
81725
- init_productionFeedback();
81726
- submittedSourceLocatorSchema = articleSourceLocatorInputSchema;
81727
- CAPTURE_GAP = /(?:> ?)?Resource unavailable: .+? \([^;()]+; [^()]+\)\. <!-- [^>]+ -->/u;
81728
- });
81729
-
81730
81745
  // src/project/approvedRevisionReferences.ts
81731
81746
  async function resolveSubmittedReference(context, id3, at2, reference2) {
81732
81747
  if (!context.inScope(reference2.source_ref))
81733
- throw new SubmissionInputError(`Fragment ${id3} cites ${reference2.source_ref}, which is outside this revision; allowed sources: ${context.sourceRefs.join(", ")}. ` + "To cite new independent evidence, register it as a source, associate it with the selected requirement in src/indexers.yaml, then run context task adjust for this revision.", [...at2, "source_ref"], "source-outside-revision");
81748
+ throw new SubmissionInputError(`Fragment ${id3} cites ${reference2.source_ref}, which is outside this revision; allowed sources: ${context.sourceRefs.join(", ")}. ` + (citesScope(context.processedScopes, reference2.source_ref) ? "It belongs to the source update this page comes from, but not to this page: run context task adjust for this revision with that scope (in a later source update, list it in the page decision's supporting_sources instead)." : "To cite new independent evidence, register it as a source, associate it with the selected requirement in src/indexers.yaml, then run context task adjust for this revision."), [...at2, "source_ref"], "source-outside-revision");
81734
81749
  const submitted = reference2.locator;
81735
81750
  const previous2 = context.previous.find((section) => section.id === id3)?.references ?? [];
81736
81751
  const kept = "start_line" in submitted ? previous2.find((old) => old.source_ref === reference2.source_ref && old.locator.path === submitted.path && old.locator.start_line === submitted.start_line && old.locator.end_line === submitted.end_line) : undefined;
@@ -81738,7 +81753,19 @@ async function resolveSubmittedReference(context, id3, at2, reference2) {
81738
81753
  const observed = await relocateUnchangedReference(context.projectRoot, context.readSource, kept);
81739
81754
  if (observed.state === "current" || observed.state === "moved")
81740
81755
  return observed.reference;
81741
- throw new SubmissionInputError(`Fragment ${id3}: ${reference2.source_ref} ${kept.locator.path}:${kept.locator.start_line}-${kept.locator.end_line} ` + `repeats an earlier citation, so it keeps that evidence, which is ${observed.state} in the current source. ` + "To keep the earlier evidence, cite its current position. To cite the text now at these lines (it may be the correct new content), use a quote or heading locator.", [...at2, "locator"], "kept-reference-unresolved");
81756
+ const cited = `Fragment ${id3}: ${reference2.source_ref} ${kept.locator.path}:${kept.locator.start_line}-${kept.locator.end_line} ` + "repeats an earlier citation's line numbers, so it keeps that citation's text";
81757
+ const current3 = observed.state === "unavailable" ? undefined : await context.readSource(reference2.source_ref, kept.locator.path, true).catch(() => {
81758
+ return;
81759
+ });
81760
+ if (current3 === undefined)
81761
+ throw new SubmissionInputError(`${cited}, but the current source cannot be read` + ` (${observed.reason ?? "source-unavailable"}). Restore or refresh the source and submit again; another locator does not help while it is unreadable.`, [...at2, "locator"], "kept-reference-unresolved");
81762
+ const lines = current3.replace(/\r\n/gu, `
81763
+ `).split(`
81764
+ `).length;
81765
+ if (kept.locator.end_line > lines)
81766
+ throw new SubmissionInputError(`${cited}, which is ${observed.state} in the current source; ` + `the file now has ${lines} lines, so these lines no longer exist. Cite the earlier evidence at its current position, or cite current text with a quote or heading locator.`, [...at2, "locator"], "kept-reference-unresolved");
81767
+ const quote2 = exactQuoteLocator(kept.locator, current3, 2000);
81768
+ throw new SubmissionInputError(`${cited}, which is ${observed.state} in the current source; ` + "the text now at these lines is different. To keep the earlier evidence, cite its current position. To cite the text now at these lines " + (quote2 ? `(it may be the correct new content), submit this locator instead: ${JSON.stringify(quote2)}.` : "(it may be the correct new content), use a quote or heading locator."), [...at2, "locator"], "kept-reference-unresolved");
81742
81769
  }
81743
81770
  const text5 = await context.readSource(reference2.source_ref, reference2.locator.path, true);
81744
81771
  let locator;
@@ -81779,6 +81806,7 @@ async function prepareRevisionReferences(input) {
81779
81806
  remember: input.remember !== false,
81780
81807
  previous: input.previous,
81781
81808
  sourceRefs: input.sourceRefs,
81809
+ processedScopes: input.processedScopes ?? [],
81782
81810
  inScope,
81783
81811
  readSource: Object.assign(async (source2, path2) => {
81784
81812
  if (!inScope(source2))
@@ -111887,7 +111915,10 @@ async function previewApprovedRevisionSubmission(input) {
111887
111915
  const semantic = parseIndexerCurrentActionSubmission(value);
111888
111916
  if (semantic.stage !== "approved-revision")
111889
111917
  throw new TypeError(`Task ${task.task} is not an approved revision.`);
111890
- const request = JSON.parse((await readProductionFile({ projectRoot: input.projectRoot, stage: manifest.stage, path: `${task.task}.input.json` })).text);
111918
+ const request = {
111919
+ ...JSON.parse((await readProductionFile({ projectRoot: input.projectRoot, stage: manifest.stage, path: `${task.task}.input.json` })).text),
111920
+ ...current3.requests[index3]?.processed_scopes ? { processed_scopes: current3.requests[index3].processed_scopes } : {}
111921
+ };
111891
111922
  const content3 = "markdown" in semantic ? { markdown: semantic.markdown, ...semantic.sections === undefined ? {} : { sections: semantic.sections } } : { sections: semantic.sections };
111892
111923
  const { markdown, references, reference_warnings } = await composeRevisionCandidate2(input.projectRoot, request, content3, { remember: false });
111893
111924
  pages.push({
@@ -120453,14 +120484,22 @@ function registerDocumentRevisionCommand(program2) {
120453
120484
  process.stdout.write(`${JSON.stringify(result, null, 2)}
120454
120485
  `);
120455
120486
  });
120456
- program2.command("update").description("Inspect acquired source changes against approved knowledge in confirmed requirement scopes").option("--input <file>", "YAML/JSON scopes and optional change summary; - for stdin").option("--pending", "process registered repository commits that moved past their processed versions").option("--format <format>", "output format: json", "json").action(async (options) => {
120487
+ program2.command("update").description("Inspect acquired source changes against approved knowledge in confirmed requirement scopes").option("--input <file>", "YAML/JSON scopes and optional change summary; - for stdin").option("--pending", "process registered repository commits that moved past their processed versions").option("--schema", "show the update input schema").option("--format <format>", "output format: json", "json").action(async (options) => {
120488
+ if (options.schema) {
120489
+ const { knowledgeUpdateInputSchema: knowledgeUpdateInputSchema2 } = await Promise.resolve().then(() => (init_knowledgeUpdate(), exports_knowledgeUpdate));
120490
+ const { zodToJsonSchema: zodToJsonSchema3 } = await Promise.resolve().then(() => (init_esm(), exports_esm));
120491
+ const { writeSchemaOutput: writeSchemaOutput2, schemaOutputFormat: schemaOutputFormat2 } = await Promise.resolve().then(() => (init_schemaOutput(), exports_schemaOutput));
120492
+ writeSchemaOutput2(zodToJsonSchema3(knowledgeUpdateInputSchema2, { effectStrategy: "input" }), schemaOutputFormat2(options.format));
120493
+ return;
120494
+ }
120457
120495
  if (options.format !== "json")
120458
120496
  throw new ContextError(ExitCode.UserError, "--format must be json", {
120459
120497
  category: ErrorCategory.UserInputInvalid
120460
120498
  });
120461
120499
  if (!options.pending === !options.input)
120462
- throw new ContextError(ExitCode.UserError, "Pass exactly one of --input or --pending", {
120463
- category: ErrorCategory.UserInputInvalid
120500
+ throw new ContextError(ExitCode.UserError, "Pass exactly one of --input or --pending, or --schema", {
120501
+ category: ErrorCategory.UserInputInvalid,
120502
+ next_action: { command: "context update --schema --format json" }
120464
120503
  });
120465
120504
  if (options.pending) {
120466
120505
  process.stdout.write(`${JSON.stringify(await beginKnowledgeUpdate(requireProjectRoot2(), undefined, { pending: true }), null, 2)}