@c4a/context-cli 0.7.87 → 0.7.88

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/README.md CHANGED
@@ -331,6 +331,9 @@ they do not resume an earlier managed task before the new request is understood.
331
331
  - `context update --input <file>` accepts confirmed source/module scopes and fixed,
332
332
  already acquired versions. The current Route asks which existing pages need
333
333
  changes and whether additions need new pages.
334
+ - `context update --pending` processes registered repositories whose commit moved
335
+ past the processed version. Only pages whose cited text changed become
336
+ candidates; the scope decision still covers additions before the commit settles.
334
337
  - `context revise <page> --instruction <text>` starts from the current approved
335
338
  body. `--move-to <path>` preserves its identity and updates Markdown navigation
336
339
  when the reviewed move is applied.
package/cli.js CHANGED
@@ -70337,6 +70337,35 @@ async function registeredRepoHistoryReader(projectRoot) {
70337
70337
  const workspace = await realpath5(projectRoot);
70338
70338
  const registry2 = await loadSourcesRegistry({ rootDir: projectRoot });
70339
70339
  const roots = new Map;
70340
+ const fetched = new Map;
70341
+ const reads = new Map;
70342
+ const queues = new Map;
70343
+ const serial = (directory, task) => {
70344
+ const run = (queues.get(directory) ?? Promise.resolve()).then(task, task);
70345
+ queues.set(directory, run.catch(() => {
70346
+ return;
70347
+ }));
70348
+ return run;
70349
+ };
70350
+ const available = (directory, commit) => {
70351
+ const key = `${directory}\x00${commit}`;
70352
+ let result = fetched.get(key);
70353
+ if (!result) {
70354
+ result = execute("git", ["-C", directory, "cat-file", "-e", `${commit}^{commit}`], { timeout: 5000, env: { ...process.env, GIT_NO_LAZY_FETCH: "1" } }).then(() => true, () => execute("git", ["-C", directory, "fetch", "--quiet", "--depth=1", "origin", commit], { timeout: 120000 }).then(() => true, () => false));
70355
+ fetched.set(key, result);
70356
+ }
70357
+ return result;
70358
+ };
70359
+ async function readAt(directory, path2, commit) {
70360
+ if (!await available(directory, commit))
70361
+ throw new TypeError(`Commit ${commit} is not available in the registered checkout`);
70362
+ const blob = await execute("git", ["-C", directory, "show", `${commit}:./${path2}`], {
70363
+ encoding: "buffer",
70364
+ timeout: 60000,
70365
+ maxBuffer: 16 * 1024 * 1024
70366
+ });
70367
+ return new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(blob.stdout);
70368
+ }
70340
70369
  return async (sourceRef, path2, commit) => {
70341
70370
  if (!/^[a-f0-9]{40}(?:[a-f0-9]{24})?$/u.test(commit))
70342
70371
  throw new TypeError("History reads require a fixed commit");
@@ -70352,12 +70381,14 @@ async function registeredRepoHistoryReader(projectRoot) {
70352
70381
  });
70353
70382
  roots.set(sourceRef, root);
70354
70383
  }
70355
- const blob = await execute("git", ["-C", await root, "show", `${commit}:./${path2}`], {
70356
- encoding: "buffer",
70357
- timeout: 5000,
70358
- maxBuffer: 16 * 1024 * 1024
70359
- });
70360
- return new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(blob.stdout);
70384
+ const directory = await root;
70385
+ const key = JSON.stringify([directory, commit, path2]);
70386
+ let read = reads.get(key);
70387
+ if (!read) {
70388
+ read = serial(directory, () => readAt(directory, path2, commit));
70389
+ reads.set(key, read);
70390
+ }
70391
+ return read;
70361
70392
  };
70362
70393
  }
70363
70394
  async function registeredArticleSourceReader(projectRoot) {
@@ -78028,15 +78059,15 @@ async function relocateUnchangedReference(root, read, reference2, history) {
78028
78059
  async function settledRegionHistory(root, previous2) {
78029
78060
  if (!previous2.some((scope2) => scope2.source_ref.startsWith("repo:")))
78030
78061
  return;
78031
- let readAt;
78062
+ let reader;
78032
78063
  return async (reference2) => {
78033
78064
  if (!reference2.source_ref.startsWith("repo:"))
78034
78065
  return;
78035
78066
  const versions = new Set(previous2.filter((scope2) => settledBy([scope2.source_ref], reference2.source_ref)).map((scope2) => scope2.processed_version));
78036
78067
  for (const version3 of versions) {
78037
78068
  try {
78038
- readAt ??= await registeredRepoHistoryReader(root);
78039
- const text5 = await readAt(reference2.source_ref, reference2.locator.path, version3);
78069
+ reader ??= registeredRepoHistoryReader(root);
78070
+ const text5 = await (await reader)(reference2.source_ref, reference2.locator.path, version3);
78040
78071
  if (articleSourceRegionDigest(text5, reference2.locator) === reference2.content_digest)
78041
78072
  return articleSourceRegion(text5, reference2.locator);
78042
78073
  } catch {}
@@ -83947,6 +83978,38 @@ var init_runtimeEvents = __esm(() => {
83947
83978
  RUNTIME_EVENT_SINK_DESCRIPTION_MAX_BYTES = 16 * 1024;
83948
83979
  });
83949
83980
 
83981
+ // src/project/pendingSourceUpdates.ts
83982
+ var exports_pendingSourceUpdates = {};
83983
+ __export(exports_pendingSourceUpdates, {
83984
+ pendingSourceUpdateScopes: () => pendingSourceUpdateScopes
83985
+ });
83986
+ async function pendingSourceUpdateScopes(projectRoot) {
83987
+ const structure = await readKnowledgeStructure(projectRoot);
83988
+ if (!structure.parsed)
83989
+ return [];
83990
+ const processed = readProcessedScopes(structure.parsed).filter((scope2) => scope2.source_ref.startsWith("repo:"));
83991
+ if (processed.length === 0)
83992
+ return [];
83993
+ const [sources, registry2] = await Promise.all([loadSourcesRegistry({ rootDir: projectRoot }), readProductionRequirements(projectRoot)]);
83994
+ return processed.filter((scope2) => {
83995
+ const name3 = scope2.source_ref.slice("repo:".length);
83996
+ const entries2 = sources.repos.filter((entry) => entry.id === name3 || entry.name === name3);
83997
+ if (entries2.length !== 1 || !/^[a-f0-9]{40}(?:[a-f0-9]{24})?$/u.test(entries2[0].ref) || entries2[0].ref === scope2.processed_version)
83998
+ return false;
83999
+ const requirement2 = registry2.requirements.find((item) => item.id === scope2.requirement_ref);
84000
+ return !!requirement2 && [...requirement2.target_scope.targets, ...requirement2.evidence_source_scope?.targets ?? []].some((target) => target.source_ref === scope2.source_ref);
84001
+ }).map((scope2) => ({
84002
+ requirement_ref: scope2.requirement_ref,
84003
+ source_ref: scope2.source_ref,
84004
+ ...scope2.module_refs === undefined ? {} : { module_refs: scope2.module_refs }
84005
+ }));
84006
+ }
84007
+ var init_pendingSourceUpdates = __esm(() => {
84008
+ init_src2();
84009
+ init_packageBuildInventory();
84010
+ init_productionRequirements();
84011
+ });
84012
+
83950
84013
  // src/project/approvedKnowledgeDependencyWarnings.ts
83951
84014
  async function approvedKnowledgeDependencyWarnings(projectRoot, structureOverride) {
83952
84015
  const articles = approvedKnowledgeSnapshotsFromStructure(structureOverride ?? (await readKnowledgeStructure(projectRoot)).parsed);
@@ -83955,6 +84018,7 @@ async function approvedKnowledgeDependencyWarnings(projectRoot, structureOverrid
83955
84018
  const read = await registeredArticleSourceReader(projectRoot);
83956
84019
  const issues = [];
83957
84020
  let repoImpact;
84021
+ let pending;
83958
84022
  for (const article of articles) {
83959
84023
  const changed = [];
83960
84024
  const moved = [];
@@ -83994,19 +84058,23 @@ async function approvedKnowledgeDependencyWarnings(projectRoot, structureOverrid
83994
84058
  break;
83995
84059
  }
83996
84060
  }
84061
+ if (!changed.length && !moved.length)
84062
+ continue;
84063
+ pending ??= pendingSourceUpdateScopes(projectRoot).catch(() => []);
84064
+ const update = (await pending).some((scope2) => article.sections.some((section) => section.references.some((reference2) => reference2.source_ref === scope2.source_ref || reference2.source_ref.startsWith(`${scope2.source_ref}/`) || reference2.source_ref.startsWith(`${scope2.source_ref}#`)))) ? " A cited repository moved past its processed commit; run context update --pending --format json first." : "";
83997
84065
  if (changed.length)
83998
84066
  issues.push({
83999
84067
  severity: "warning",
84000
84068
  code: "approved-source-region-changed",
84001
84069
  path: article.path,
84002
- message: `Source regions changed or are unavailable for fragments: ${changed.join(", ")}. Inspect current sources and revise this article; verification does not rewrite approved references.`
84070
+ message: `Source regions changed or are unavailable for fragments: ${changed.join(", ")}.${update || " Inspect current sources and revise this article;"} Verification does not rewrite approved references.`
84003
84071
  });
84004
84072
  if (moved.length)
84005
84073
  issues.push({
84006
84074
  severity: "warning",
84007
84075
  code: "approved-source-region-moved",
84008
84076
  path: article.path,
84009
- message: `Cited regions are unchanged but their location or surrounding source changed: ${moved.join("; ")}. Check locators during the source update; do not rewrite unaffected prose.`
84077
+ message: `Cited regions are unchanged but their location or surrounding source changed: ${moved.join("; ")}.${update || " Check locators during the source update;"} Do not rewrite unaffected prose.`
84010
84078
  });
84011
84079
  }
84012
84080
  return issues;
@@ -84018,6 +84086,7 @@ var init_approvedKnowledgeDependencyWarnings = __esm(() => {
84018
84086
  init_packageBuildInventory();
84019
84087
  init_approvedKnowledgeSnapshots();
84020
84088
  init_repoContentEvidence();
84089
+ init_pendingSourceUpdates();
84021
84090
  });
84022
84091
 
84023
84092
  // src/project/approvedStructureInputHash.ts
@@ -92401,14 +92470,21 @@ async function readKnowledgeUpdate(projectRoot) {
92401
92470
  throw new TypeError("Source update request digest is invalid");
92402
92471
  return update;
92403
92472
  }
92404
- async function beginKnowledgeUpdate(projectRoot, value) {
92473
+ async function beginKnowledgeUpdate(projectRoot, value, options = {}) {
92405
92474
  return withProjectWriteLock(projectRoot, "begin-knowledge-update", async () => {
92406
- const input = knowledgeUpdateInputSchema.parse(value);
92407
92475
  await ensureRepoContentLinks(projectRoot);
92408
92476
  const { readTaskRollback } = await Promise.resolve().then(() => (init_taskRollback(), exports_taskRollback));
92409
92477
  if (await readTaskRollback(projectRoot) || await readApprovedRevision(projectRoot) || await readKnowledgeUpdate(projectRoot) || await readProductionStage(projectRoot) || (await readCandidateRecords(projectRoot)).length > 0) {
92410
92478
  throw new TypeError("Finish or explicitly roll back the active task before starting an independent source update.");
92411
92479
  }
92480
+ let input;
92481
+ if (options.pending) {
92482
+ const pending = await pendingSourceUpdateScopes(projectRoot);
92483
+ if (pending.length === 0)
92484
+ return { outcome: "current", next_action: { command: "context status --format json" } };
92485
+ input = { scopes: pending };
92486
+ } else
92487
+ input = knowledgeUpdateInputSchema.parse(value);
92412
92488
  const versions = new Map;
92413
92489
  const scopes = await captureProcessedScopes(projectRoot, await Promise.all(input.scopes.map(async (scope2) => {
92414
92490
  if (scope2.processed_version !== undefined)
@@ -92420,7 +92496,12 @@ async function beginKnowledgeUpdate(projectRoot, value) {
92420
92496
  const structure = await readKnowledgeStructure(projectRoot);
92421
92497
  if (!structure.parsed)
92422
92498
  throw new TypeError("Close the existing knowledge before checking source updates");
92423
- const candidates = await Promise.all(validateArticleStructureEntries(structure.parsed.articles ?? []).filter((article) => article.sections.some((section) => section.references.some((reference2) => scopes.some((scope2) => repoContentScopeMatches(scope2.source_ref, reference2.source_ref))))).map(async (article) => {
92499
+ const settled = readProcessedScopes(structure.parsed);
92500
+ const articles = validateArticleStructureEntries(structure.parsed.articles ?? []);
92501
+ const cited = articles.filter((article) => article.sections.some((section) => section.references.some((reference2) => scopes.some((scope2) => repoContentScopeMatches(scope2.source_ref, reference2.source_ref)))));
92502
+ const inspected = await inspectSettledReferences(projectRoot, cited, scopes.map((scope2) => scope2.source_ref), settled);
92503
+ const changedPaths = new Set(inspected.unresolved.map((item) => item.path));
92504
+ const candidates = await Promise.all(cited.filter((article) => !options.pending || changedPaths.has(article.path)).map(async (article) => {
92424
92505
  const title = parseFrontmatterLoose(await targetBytes(projectRoot, article.path)).title;
92425
92506
  return {
92426
92507
  path: article.path,
@@ -92430,7 +92511,7 @@ async function beginKnowledgeUpdate(projectRoot, value) {
92430
92511
  };
92431
92512
  }));
92432
92513
  const registry2 = await readProductionRequirements(projectRoot);
92433
- const repoReferences = validateArticleStructureEntries(structure.parsed.articles ?? []).flatMap((article) => article.sections.flatMap((section) => section.references.filter((ref2) => ref2.source_ref.startsWith("repo-content:") && scopes.some((scope2) => repoContentScopeMatches(scope2.source_ref, ref2.source_ref))).map((reference2) => ({ article: article.path, section: section.id, reference: reference2 }))));
92514
+ const repoReferences = articles.flatMap((article) => article.sections.flatMap((section) => section.references.filter((ref2) => ref2.source_ref.startsWith("repo-content:") && scopes.some((scope2) => repoContentScopeMatches(scope2.source_ref, ref2.source_ref))).map((reference2) => ({ article: article.path, section: section.id, reference: reference2 }))));
92434
92515
  const impact = repoReferences.length ? await repoContentImpactReader(projectRoot) : undefined;
92435
92516
  const repoContent = scopes.some((scope2) => scope2.source_ref.startsWith("repo-content:")) ? {
92436
92517
  entries: await inspectRepoContentChanges(projectRoot),
@@ -92444,7 +92525,14 @@ async function beginKnowledgeUpdate(projectRoot, value) {
92444
92525
  requirements,
92445
92526
  candidates,
92446
92527
  ...repoContent === undefined ? {} : { repo_content: repoContent },
92447
- previous_versions: scopes.map((scope2) => processedVersionForScope(readProcessedScopes(structure.parsed), scope2) ?? null),
92528
+ ...inspected.unresolved.length === 0 ? {} : { changed_references: inspected.unresolved.map((item) => ({
92529
+ path: item.path,
92530
+ section_id: item.section_id,
92531
+ state: item.state,
92532
+ source_ref: item.reference.source_ref,
92533
+ locator: item.reference.locator
92534
+ })) },
92535
+ previous_versions: scopes.map((scope2) => processedVersionForScope(settled, scope2) ?? null),
92448
92536
  ...input.changes === undefined ? {} : { changes: input.changes }
92449
92537
  };
92450
92538
  const request = updateSchema.parse({ ...payload, revision: indexerProtocolDigest(payload) });
@@ -92595,6 +92683,7 @@ var init_knowledgeUpdate = __esm(() => {
92595
92683
  init_repoContentLinks();
92596
92684
  init_repoContentEvidence();
92597
92685
  init_settledReferenceRelocation();
92686
+ init_pendingSourceUpdates();
92598
92687
  knowledgeUpdateInputSchema = exports_external.object({
92599
92688
  scopes: exports_external.array(exports_external.object({
92600
92689
  requirement_ref: exports_external.string().min(1),
@@ -92619,7 +92708,14 @@ var init_knowledgeUpdate = __esm(() => {
92619
92708
  structure_proposal: indexerCurrentActionInputDefinitions.sourceUpdate.omit({ stage: true }).optional(),
92620
92709
  previous_versions: exports_external.array(exports_external.string().nullable()),
92621
92710
  changes: exports_external.string().optional(),
92622
- repo_content: exports_external.unknown().optional()
92711
+ repo_content: exports_external.unknown().optional(),
92712
+ changed_references: exports_external.array(exports_external.object({
92713
+ path: exports_external.string(),
92714
+ section_id: exports_external.string(),
92715
+ state: exports_external.enum(["changed", "unavailable"]),
92716
+ source_ref: exports_external.string(),
92717
+ locator: exports_external.unknown()
92718
+ }).strict()).optional()
92623
92719
  }).strict();
92624
92720
  });
92625
92721
 
@@ -96584,10 +96680,13 @@ async function addRepoSourceUnlocked(input) {
96584
96680
  registry2.repos[index3] = source2;
96585
96681
  await writeRepoRegistry(input.projectRoot, registry2);
96586
96682
  const status = await ensureRepoSource({ projectRoot: input.projectRoot, source: source2 });
96683
+ const { pendingSourceUpdateScopes: pendingSourceUpdateScopes2 } = await Promise.resolve().then(() => (init_pendingSourceUpdates(), exports_pendingSourceUpdates));
96684
+ const pending = existing && existing.git.ref !== next.git.ref && (await pendingSourceUpdateScopes2(input.projectRoot)).some((scope2) => scope2.source_ref === `repo:${source2.name}`);
96587
96685
  return {
96588
96686
  registryPath: DEFAULT_REPO_SOURCES_REGISTRY_PATH,
96589
96687
  source: source2,
96590
- status
96688
+ status,
96689
+ ...pending ? { next: "Approved knowledge was processed at the previous commit. Run context update --pending --format json to process this commit." } : {}
96591
96690
  };
96592
96691
  }
96593
96692
  async function addRepoSource(input) {
@@ -97324,7 +97423,8 @@ function createContextWorkflowFacts(observation, authorities) {
97324
97423
  },
97325
97424
  sources: {
97326
97425
  registered: observation.sourceCount > 0,
97327
- repositories_ready: observation.readyRepoSources === observation.repoSources.length
97426
+ repositories_ready: observation.readyRepoSources === observation.repoSources.length,
97427
+ update_pending: observation.sourceUpdatePending === true
97328
97428
  },
97329
97429
  capture: {
97330
97430
  declarations_complete: observation.documentSources.length === 0 || observation.missingCaptureSources.length === 0,
@@ -107178,6 +107278,7 @@ async function collectProjectStatusSnapshotInternal(projectRoot, options = {}) {
107178
107278
  translationRouteSatisfied: phaseStatus.projectEntryValid && !deferDeliveryChecks ? await inspectSiteTranslations(projectRoot, packages).then((result) => result.route_satisfied, () => false) : true,
107179
107279
  taskPreparation,
107180
107280
  localRevisionActive: !!localRevision || !!localUpdate,
107281
+ sourceUpdatePending: !maintenance && !localRevision && !localUpdate && !localRollback && !production && draftStatus.count === 0 && await Promise.resolve().then(() => (init_pendingSourceUpdates(), exports_pendingSourceUpdates)).then(({ pendingSourceUpdateScopes: pendingSourceUpdateScopes2 }) => pendingSourceUpdateScopes2(projectRoot)).then((scopes) => scopes.length > 0, () => false),
107181
107282
  unfinishedIndexerTasks: false,
107182
107283
  ...production ? {
107183
107284
  productionState: await productionRequirementsAreCurrent(projectRoot, production) ? dispatchProductionStage(production, productionCapabilitiesSchema.parse({})).state : "active",
@@ -115446,11 +115547,20 @@ function registerDocumentRevisionCommand(program2) {
115446
115547
  process.stdout.write(`${JSON.stringify(result, null, 2)}
115447
115548
  `);
115448
115549
  });
115449
- program2.command("update").description("Inspect acquired source changes against approved knowledge in confirmed requirement scopes").requiredOption("--input <file>", "YAML/JSON scopes and optional change summary; - for stdin").option("--format <format>", "output format: json", "json").action(async (options) => {
115550
+ 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) => {
115450
115551
  if (options.format !== "json")
115451
115552
  throw new ContextError(ExitCode.UserError, "--format must be json", {
115452
115553
  category: ErrorCategory.UserInputInvalid
115453
115554
  });
115555
+ if (!options.pending === !options.input)
115556
+ throw new ContextError(ExitCode.UserError, "Pass exactly one of --input or --pending", {
115557
+ category: ErrorCategory.UserInputInvalid
115558
+ });
115559
+ if (options.pending) {
115560
+ process.stdout.write(`${JSON.stringify(await beginKnowledgeUpdate(requireProjectRoot2(), undefined, { pending: true }), null, 2)}
115561
+ `);
115562
+ return;
115563
+ }
115454
115564
  assertActionInputWorkspace(process.cwd(), options.input);
115455
115565
  const value = await readYamlOrJsonInput({
115456
115566
  path: options.input,