@c4a/context-cli 0.7.96 → 0.7.97
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/cli.js +641 -326
- package/indexers/contracts/profile-contract.json +245 -245
- package/indexers/release-manifest.json +1 -1
- package/package.json +12 -12
- package/parserEntryWorker.js +7 -4
- package/plugins/VERSION +1 -1
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/claude/commands/context.md +1 -1
- package/plugins/codex/.codex-plugin/plugin.json +2 -2
- package/plugins/codex/skills/context/SKILL.md +1 -1
- package/plugins/cursor/.cursor-plugin/plugin.json +1 -1
- package/plugins/cursor/commands/c4a-context.md +1 -1
- package/plugins/skills/context/SKILL.md +1 -1
- package/providers/context/manifest.json +10 -10
- package/providers/context/provider.yaml +1 -1
- package/providers/context/resources/manuals/guides/knowledge-updates.md +10 -1
- package/providers/context/resources/manuals/guides/lark-resources.md +9 -2
- package/providers/context/resources/procedures/knowledge-updates.md +10 -1
- package/providers/context/resources/procedures/production-stage-files.md +6 -2
package/cli.js
CHANGED
|
@@ -41212,7 +41212,7 @@ var import_yaml8, DEFAULT_REPO_SOURCES_REGISTRY_PATH = "sources/repo/index.yaml"
|
|
|
41212
41212
|
}
|
|
41213
41213
|
}
|
|
41214
41214
|
}
|
|
41215
|
-
}, loadSourcesRegistry = async (options = {}) => {
|
|
41215
|
+
}, SOURCES_REGISTRY_EXCLUSION, loadSourcesRegistry = async (options = {}) => {
|
|
41216
41216
|
const rootDir = options.rootDir ?? process.cwd();
|
|
41217
41217
|
const repoRegistryPath = options.repoRegistryPath ?? options.registryPath ?? DEFAULT_REPO_SOURCES_REGISTRY_PATH;
|
|
41218
41218
|
const fileRegistryPath = options.fileRegistryPath ?? DEFAULT_FILE_SOURCES_REGISTRY_PATH;
|
|
@@ -41220,6 +41220,8 @@ var import_yaml8, DEFAULT_REPO_SOURCES_REGISTRY_PATH = "sources/repo/index.yaml"
|
|
|
41220
41220
|
const repoAbsolutePath = resolve7(rootDir, repoRegistryPath);
|
|
41221
41221
|
const fileAbsolutePath = resolve7(rootDir, fileRegistryPath);
|
|
41222
41222
|
const larkAbsolutePath = resolve7(rootDir, larkRegistryPath);
|
|
41223
|
+
const excluded = globalThis[SOURCES_REGISTRY_EXCLUSION];
|
|
41224
|
+
const included = (entry) => !(excluded instanceof Set && (excluded.has(entry.name) || excluded.has(entry.id)));
|
|
41223
41225
|
const repoRegistry = parseRepoSourcesRegistry(await readYamlIfPresent(repoAbsolutePath, { sources: [] }), repoRegistryPath, repoAbsolutePath);
|
|
41224
41226
|
const files = parseFileSourcesRegistry(await readYamlIfPresent(fileAbsolutePath, { sources: [] }), fileRegistryPath);
|
|
41225
41227
|
const larks = parseLarkSourcesRegistry(await readYamlIfPresent(larkAbsolutePath, { sources: [] }), larkRegistryPath);
|
|
@@ -41235,9 +41237,9 @@ var import_yaml8, DEFAULT_REPO_SOURCES_REGISTRY_PATH = "sources/repo/index.yaml"
|
|
|
41235
41237
|
file: fileAbsolutePath,
|
|
41236
41238
|
lark: larkAbsolutePath
|
|
41237
41239
|
},
|
|
41238
|
-
repos: repoRegistry.repos,
|
|
41239
|
-
files,
|
|
41240
|
-
larks,
|
|
41240
|
+
repos: repoRegistry.repos.filter(included),
|
|
41241
|
+
files: files.filter(included),
|
|
41242
|
+
larks: larks.filter(included),
|
|
41241
41243
|
notes: await discoverManagedDocuments(rootDir, "note"),
|
|
41242
41244
|
sessions: await discoverManagedDocuments(rootDir, "sessions")
|
|
41243
41245
|
};
|
|
@@ -41304,6 +41306,7 @@ var init_sources = __esm(() => {
|
|
|
41304
41306
|
larkSourcesRegistrySchema = exports_external.object({
|
|
41305
41307
|
sources: exports_external.array(exports_external.union([larkSourceRegistryEntrySchema, larkSourceBatchSchema])).default([])
|
|
41306
41308
|
}).strict();
|
|
41309
|
+
SOURCES_REGISTRY_EXCLUSION = Symbol.for("c4a.context.sources-registry-exclusion");
|
|
41307
41310
|
});
|
|
41308
41311
|
|
|
41309
41312
|
// ../context/src/processedScopes.ts
|
|
@@ -69867,6 +69870,15 @@ var init_durableMultiFileTransaction = __esm(() => {
|
|
|
69867
69870
|
});
|
|
69868
69871
|
|
|
69869
69872
|
// src/project/productionRequirements.ts
|
|
69873
|
+
var exports_productionRequirements = {};
|
|
69874
|
+
__export(exports_productionRequirements, {
|
|
69875
|
+
validateProductionRequirements: () => validateProductionRequirements,
|
|
69876
|
+
readProductionRequirements: () => readProductionRequirements,
|
|
69877
|
+
productionSourceIsExcluded: () => productionSourceIsExcluded,
|
|
69878
|
+
productionRequirementsSchema: () => productionRequirementsSchema,
|
|
69879
|
+
inspectProductionRequirements: () => inspectProductionRequirements,
|
|
69880
|
+
PRODUCTION_REQUIREMENTS_PATH: () => PRODUCTION_REQUIREMENTS_PATH
|
|
69881
|
+
});
|
|
69870
69882
|
import { readFile as readFile13 } from "node:fs/promises";
|
|
69871
69883
|
async function readProductionRequirements(projectRoot) {
|
|
69872
69884
|
const inspected = await inspectProductionRequirements(projectRoot);
|
|
@@ -70012,6 +70024,85 @@ function approvedContextSectionsInMarkdown(content3) {
|
|
|
70012
70024
|
return result;
|
|
70013
70025
|
}
|
|
70014
70026
|
|
|
70027
|
+
// src/lib/gitProgress.ts
|
|
70028
|
+
import { spawn as spawn2 } from "node:child_process";
|
|
70029
|
+
function redactRemoteCredentials(text5) {
|
|
70030
|
+
return text5.replace(/\/\/[^/@\s]+@/gu, "//");
|
|
70031
|
+
}
|
|
70032
|
+
function progressCount(line) {
|
|
70033
|
+
const match = /^(?:remote:\s*)?([A-Za-z][A-Za-z ]*?):\s+(?:\d+%\s+\((\d+)\/\d+\)|(\d+))/u.exec(line);
|
|
70034
|
+
if (!match)
|
|
70035
|
+
return;
|
|
70036
|
+
const size = /,\s*(\d+(?:\.\d+)?)\s*(bytes|[KMGT]iB)(?!\/s)/u.exec(line.slice(match[0].length));
|
|
70037
|
+
return { phase: match[1], count: Number(match[2] ?? match[3]), bytes: size ? Number(size[1]) * UNITS[size[2]] : 0 };
|
|
70038
|
+
}
|
|
70039
|
+
async function runGitWithProgress(args, options) {
|
|
70040
|
+
const idleMs = options.idleMs ?? 5 * 60000, limitMs = options.limitMs ?? 30 * 60000, reportMs = options.reportMs ?? 30000;
|
|
70041
|
+
const command = args.findIndex((arg) => arg === "fetch" || arg === "clone");
|
|
70042
|
+
const argv = command < 0 ? [...args] : [...args.slice(0, command + 1), "--progress", ...args.slice(command + 1)];
|
|
70043
|
+
const child = spawn2(options.bin ?? "git", argv, { cwd: options.cwd, env: options.env ?? process.env, stdio: ["ignore", "pipe", "pipe"] });
|
|
70044
|
+
const started = Date.now();
|
|
70045
|
+
let lastProgress = started, lastReport = started, lastLine = "", stdout = "", tail = "";
|
|
70046
|
+
const counts2 = new Map;
|
|
70047
|
+
child.stdout.on("data", (chunk) => {
|
|
70048
|
+
stdout += String(chunk);
|
|
70049
|
+
});
|
|
70050
|
+
child.stderr.on("data", (chunk) => {
|
|
70051
|
+
const text5 = String(chunk);
|
|
70052
|
+
tail = (tail + text5).slice(-4000);
|
|
70053
|
+
for (const line of text5.split(/[\r\n]+/u).map((part) => part.trim()).filter(Boolean)) {
|
|
70054
|
+
const progress = progressCount(line);
|
|
70055
|
+
if (!progress)
|
|
70056
|
+
continue;
|
|
70057
|
+
lastLine = line;
|
|
70058
|
+
const previous2 = counts2.get(progress.phase);
|
|
70059
|
+
if (!previous2 || progress.count > previous2.count || progress.bytes > previous2.bytes) {
|
|
70060
|
+
counts2.set(progress.phase, { count: Math.max(progress.count, previous2?.count ?? 0), bytes: Math.max(progress.bytes, previous2?.bytes ?? 0) });
|
|
70061
|
+
lastProgress = Date.now();
|
|
70062
|
+
}
|
|
70063
|
+
}
|
|
70064
|
+
});
|
|
70065
|
+
let stopped;
|
|
70066
|
+
const timer = setInterval(() => {
|
|
70067
|
+
const now = Date.now();
|
|
70068
|
+
if (now - started > limitMs)
|
|
70069
|
+
stopped = new GitProgressError(`${options.label} stopped after ${Math.round(limitMs / 60000)} minutes ` + `(still running; last progress: ${redactRemoteCredentials(lastLine) || "none"}). Report this to the user before retrying.`, "too-long");
|
|
70070
|
+
else if (now - lastProgress > idleMs)
|
|
70071
|
+
stopped = new GitProgressError(`${options.label} made no progress for ${Math.round(idleMs / 60000)} minutes ` + `(last progress: ${redactRemoteCredentials(lastLine) || "none"}).`, "no-progress");
|
|
70072
|
+
if (stopped) {
|
|
70073
|
+
child.kill("SIGKILL");
|
|
70074
|
+
return;
|
|
70075
|
+
}
|
|
70076
|
+
if (now - lastReport >= reportMs && lastLine) {
|
|
70077
|
+
lastReport = now;
|
|
70078
|
+
process.stderr.write(`[context] ${options.label}: ${redactRemoteCredentials(lastLine)}
|
|
70079
|
+
`);
|
|
70080
|
+
}
|
|
70081
|
+
}, Math.min(1000, idleMs, limitMs));
|
|
70082
|
+
const code = await new Promise((resolve8, reject) => {
|
|
70083
|
+
child.once("error", reject);
|
|
70084
|
+
child.once("close", resolve8);
|
|
70085
|
+
}).finally(() => clearInterval(timer));
|
|
70086
|
+
if (stopped)
|
|
70087
|
+
throw stopped;
|
|
70088
|
+
if (code !== 0) {
|
|
70089
|
+
const line = tail.split(/[\r\n]+/u).map((part) => part.trim()).find((part) => /^(fatal|error):/iu.test(part)) ?? tail.trim().split(/[\r\n]+/u).pop() ?? "";
|
|
70090
|
+
throw new GitProgressError(`${options.label} failed: ${redactRemoteCredentials(line).slice(0, 300) || `exit ${code}`}`, "failed");
|
|
70091
|
+
}
|
|
70092
|
+
return stdout;
|
|
70093
|
+
}
|
|
70094
|
+
var GitProgressError, UNITS;
|
|
70095
|
+
var init_gitProgress = __esm(() => {
|
|
70096
|
+
GitProgressError = class GitProgressError extends Error {
|
|
70097
|
+
kind;
|
|
70098
|
+
constructor(message, kind) {
|
|
70099
|
+
super(message);
|
|
70100
|
+
this.kind = kind;
|
|
70101
|
+
}
|
|
70102
|
+
};
|
|
70103
|
+
UNITS = { bytes: 1, KiB: 1024, MiB: 1024 ** 2, GiB: 1024 ** 3, TiB: 1024 ** 4 };
|
|
70104
|
+
});
|
|
70105
|
+
|
|
70015
70106
|
// src/project/repoContentGit.ts
|
|
70016
70107
|
import { execFile as execFile2 } from "node:child_process";
|
|
70017
70108
|
import { promisify as promisify2 } from "node:util";
|
|
@@ -70437,7 +70528,7 @@ var init_repoContentEvidence = __esm(() => {
|
|
|
70437
70528
|
});
|
|
70438
70529
|
|
|
70439
70530
|
// src/project/gitObjectReader.ts
|
|
70440
|
-
import { execFile as execFile3, spawn as
|
|
70531
|
+
import { execFile as execFile3, spawn as spawn3 } from "node:child_process";
|
|
70441
70532
|
async function missingReason(root, expression) {
|
|
70442
70533
|
const separator = expression.indexOf(":./");
|
|
70443
70534
|
const commit = expression.slice(0, separator), path2 = expression.slice(separator + 3);
|
|
@@ -70549,7 +70640,7 @@ function createGitObjectReader(options = {}) {
|
|
|
70549
70640
|
progress();
|
|
70550
70641
|
}
|
|
70551
70642
|
function start2() {
|
|
70552
|
-
const process2 =
|
|
70643
|
+
const process2 = spawn3("git", ["-C", root, "cat-file", "--batch", "-z"], { env: { ...globalThis.process.env, GIT_NO_LAZY_FETCH: "1" } });
|
|
70553
70644
|
child = process2;
|
|
70554
70645
|
process2.stdout.on("data", (chunk) => {
|
|
70555
70646
|
if (child === process2)
|
|
@@ -70653,12 +70744,15 @@ function inside(root, path2) {
|
|
|
70653
70744
|
throw new SourceUnavailableError("Article source path escapes its captured scope", "source-path-outside-scope");
|
|
70654
70745
|
}
|
|
70655
70746
|
}
|
|
70656
|
-
function commitAvailability(fetched, fetch = true) {
|
|
70747
|
+
function commitAvailability(fetched, fetch = true, failures) {
|
|
70657
70748
|
return (directory, commit) => {
|
|
70658
70749
|
const key = `${directory}\x00${commit}`;
|
|
70659
70750
|
let result = fetched.get(key);
|
|
70660
70751
|
if (!result) {
|
|
70661
|
-
result = execute("git", ["-C", directory, "cat-file", "-e", `${commit}^{commit}`], { timeout: 5000, env: { ...process.env, GIT_NO_LAZY_FETCH: "1" } }).then(() => true, () => !fetch ? false :
|
|
70752
|
+
result = execute("git", ["-C", directory, "cat-file", "-e", `${commit}^{commit}`], { timeout: 5000, env: { ...process.env, GIT_NO_LAZY_FETCH: "1" } }).then(() => true, () => !fetch ? false : runGitWithProgress(["-C", directory, "fetch", "--depth=1", "origin", commit], { env: { ...process.env, GIT_TERMINAL_PROMPT: "0" }, label: `git fetch of commit ${commit.slice(0, 12)}` }).then(() => true, (error) => {
|
|
70753
|
+
failures?.set(commit, error instanceof Error ? error.message : String(error));
|
|
70754
|
+
return false;
|
|
70755
|
+
}));
|
|
70662
70756
|
fetched.set(key, result);
|
|
70663
70757
|
}
|
|
70664
70758
|
return result;
|
|
@@ -70670,7 +70764,8 @@ function missingCommit(commit) {
|
|
|
70670
70764
|
async function fetchSourceCommits(projectRoot, requests) {
|
|
70671
70765
|
const workspace = await realpath5(projectRoot);
|
|
70672
70766
|
const registry2 = await loadSourcesRegistry({ rootDir: projectRoot });
|
|
70673
|
-
const
|
|
70767
|
+
const failed = new Map;
|
|
70768
|
+
const available = commitAvailability(new Map, true, failed);
|
|
70674
70769
|
for (const request of requests) {
|
|
70675
70770
|
if (!request.source_ref.startsWith("repo:"))
|
|
70676
70771
|
continue;
|
|
@@ -70685,6 +70780,7 @@ async function fetchSourceCommits(projectRoot, requests) {
|
|
|
70685
70780
|
if (root)
|
|
70686
70781
|
await available(root, commit);
|
|
70687
70782
|
}
|
|
70783
|
+
return failed;
|
|
70688
70784
|
}
|
|
70689
70785
|
async function registeredRepoHistoryReader(projectRoot) {
|
|
70690
70786
|
const workspace = await realpath5(projectRoot);
|
|
@@ -70813,8 +70909,10 @@ async function registeredArticleSourceReader(projectRoot) {
|
|
|
70813
70909
|
pending = (async () => {
|
|
70814
70910
|
try {
|
|
70815
70911
|
const { root, files, commit } = await scope2(sourceRef);
|
|
70816
|
-
if (files && !files.has(path2))
|
|
70817
|
-
|
|
70912
|
+
if (files && !files.has(path2)) {
|
|
70913
|
+
const owned = [...files.keys()];
|
|
70914
|
+
throw new SourceUnavailableError(`Source path ${path2} is not owned by the registered document ${sourceRef}; cite one of its files: ` + `${owned.slice(0, 10).join(", ")}${owned.length > 10 ? `, and ${owned.length - 10} more` : ""}.`, "source-path-unregistered");
|
|
70915
|
+
}
|
|
70818
70916
|
const lexical = resolve19(root, path2);
|
|
70819
70917
|
inside(root, lexical);
|
|
70820
70918
|
let bytes;
|
|
@@ -70855,6 +70953,7 @@ async function registeredArticleSourceReader(projectRoot) {
|
|
|
70855
70953
|
}
|
|
70856
70954
|
var execute;
|
|
70857
70955
|
var init_articleSourceReader = __esm(() => {
|
|
70956
|
+
init_gitProgress();
|
|
70858
70957
|
init_src2();
|
|
70859
70958
|
init_documentBatchManifest();
|
|
70860
70959
|
init_repoContentEvidence();
|
|
@@ -78317,9 +78416,9 @@ async function collectReferenceEvidence(root, references, previous2 = [], cited
|
|
|
78317
78416
|
}));
|
|
78318
78417
|
}
|
|
78319
78418
|
function articleReferenceHistoryReader(root, previous2 = []) {
|
|
78320
|
-
|
|
78419
|
+
let repoHistory;
|
|
78321
78420
|
const objects = commandGitObjectReader();
|
|
78322
|
-
|
|
78421
|
+
let registry2;
|
|
78323
78422
|
const logs = new Map;
|
|
78324
78423
|
function verified(reference2, text5, commit) {
|
|
78325
78424
|
try {
|
|
@@ -78334,7 +78433,7 @@ function articleReferenceHistoryReader(root, previous2 = []) {
|
|
|
78334
78433
|
if (reference2.source_ref.startsWith("repo:")) {
|
|
78335
78434
|
for (const scope2 of versions) {
|
|
78336
78435
|
try {
|
|
78337
|
-
const text5 = await (await repoHistory)(reference2.source_ref, reference2.locator.path, scope2.processed_version);
|
|
78436
|
+
const text5 = await (await (repoHistory ??= registeredRepoHistoryReader(root)))(reference2.source_ref, reference2.locator.path, scope2.processed_version);
|
|
78338
78437
|
const result = verified(reference2, text5, scope2.processed_version);
|
|
78339
78438
|
if (result)
|
|
78340
78439
|
return result;
|
|
@@ -78343,7 +78442,7 @@ function articleReferenceHistoryReader(root, previous2 = []) {
|
|
|
78343
78442
|
return baseline === undefined ? undefined : { region: baseline };
|
|
78344
78443
|
}
|
|
78345
78444
|
const [kind, name2] = reference2.source_ref.split(":", 2);
|
|
78346
|
-
const sources = await registry2;
|
|
78445
|
+
const sources = await (registry2 ??= loadSourcesRegistry({ rootDir: root }));
|
|
78347
78446
|
const entries = kind === "lark" ? sources.larks : kind === "file" ? sources.files : kind === "note" ? sources.notes : kind === "sessions" ? sources.sessions : [];
|
|
78348
78447
|
const entry = entries.find((candidate) => candidate.id === name2 || candidate.name === name2);
|
|
78349
78448
|
if (!entry)
|
|
@@ -81049,6 +81148,27 @@ import { execFile as execFile8 } from "node:child_process";
|
|
|
81049
81148
|
import { promisify as promisify7 } from "node:util";
|
|
81050
81149
|
import { readFile as readFile30 } from "node:fs/promises";
|
|
81051
81150
|
import { basename as basename5, join as join35 } from "node:path";
|
|
81151
|
+
async function checkoutMatchesCommit(root, ref2, files) {
|
|
81152
|
+
const timeout = 30000 + files * 2;
|
|
81153
|
+
let reason = "";
|
|
81154
|
+
for (let attempt = 0;attempt < 2; attempt++) {
|
|
81155
|
+
try {
|
|
81156
|
+
await execute2("git", ["-C", root, "diff", "--quiet", ref2, "--", "."], {
|
|
81157
|
+
timeout,
|
|
81158
|
+
maxBuffer: 64 * 1024,
|
|
81159
|
+
env: { ...process.env, GIT_OPTIONAL_LOCKS: "0" }
|
|
81160
|
+
});
|
|
81161
|
+
return { state: "same" };
|
|
81162
|
+
} catch (error) {
|
|
81163
|
+
const failure = error;
|
|
81164
|
+
if (failure.code === 1)
|
|
81165
|
+
return { state: "differs" };
|
|
81166
|
+
reason = failure.killed ? `timed out after ${Math.round(timeout / 1000)} s` : String(failure.stderr ?? (error instanceof Error ? error.message : error)).trim().split(`
|
|
81167
|
+
`)[0].slice(0, 200);
|
|
81168
|
+
}
|
|
81169
|
+
}
|
|
81170
|
+
return { state: "unchecked", reason };
|
|
81171
|
+
}
|
|
81052
81172
|
function productionDocumentSkeleton(path2, markdown) {
|
|
81053
81173
|
const lines = markdown.split(/\r?\n/u);
|
|
81054
81174
|
let title;
|
|
@@ -81160,10 +81280,6 @@ This entire source is explicitly excluded from every selected requirement; no in
|
|
|
81160
81280
|
const repo = registry2.repos.find((repo2) => repo2.id === name3 || repo2.name === name3);
|
|
81161
81281
|
if (!/^[a-f0-9]{40}(?:[a-f0-9]{24})?$/u.test(repo.ref))
|
|
81162
81282
|
throw new TypeError("Planning requires a captured fixed commit, not a moving ref");
|
|
81163
|
-
await execute2("git", ["-C", root, "diff", "--quiet", repo.ref, "--", "."], {
|
|
81164
|
-
timeout: 5000,
|
|
81165
|
-
maxBuffer: 64 * 1024
|
|
81166
|
-
});
|
|
81167
81283
|
const targets = input.requirements.requirements.flatMap((item) => [
|
|
81168
81284
|
...item.target_scope.targets,
|
|
81169
81285
|
...item.evidence_source_scope?.targets ?? []
|
|
@@ -81171,10 +81287,14 @@ This entire source is explicitly excluded from every selected requirement; no in
|
|
|
81171
81287
|
const modules = [...new Set(targets.flatMap((target) => target.module_refs ?? []))];
|
|
81172
81288
|
const result = await execute2("git", ["-C", root, "ls-tree", "-r", "--name-only", "-z", repo.ref], {
|
|
81173
81289
|
encoding: "utf8",
|
|
81174
|
-
timeout:
|
|
81175
|
-
maxBuffer:
|
|
81290
|
+
timeout: 60000,
|
|
81291
|
+
maxBuffer: 64 * 1024 * 1024
|
|
81176
81292
|
});
|
|
81177
|
-
const
|
|
81293
|
+
const tracked = result.stdout.split("\x00").filter(Boolean);
|
|
81294
|
+
const checkout = await checkoutMatchesCommit(root, repo.ref, tracked.length);
|
|
81295
|
+
if (checkout.state === "differs")
|
|
81296
|
+
throw new TypeError(`The checkout differs from the registered commit ${repo.ref}; restore it (context source recovery-plan --format json) before planning`);
|
|
81297
|
+
const files = tracked.filter((path2) => !sourceExcludes(input.requirements, scope2, path2));
|
|
81178
81298
|
const directories = new Map;
|
|
81179
81299
|
for (const file of files) {
|
|
81180
81300
|
const directory = file.includes("/") ? file.split("/")[0] : "(root)";
|
|
@@ -81188,6 +81308,7 @@ This entire source is explicitly excluded from every selected requirement; no in
|
|
|
81188
81308
|
...modules.length ? [`Module focus: ${modules.join(", ")}`] : [],
|
|
81189
81309
|
"Choose relevant directories while investigating. Module names are work guidance, not inferred path permissions; put useful reading scope in the task brief without a separate mapping or receipt.",
|
|
81190
81310
|
`Complete authorized tracked-file count: ${files.length}`,
|
|
81311
|
+
...checkout.state === "unchecked" ? [`Checkout check did not complete (${checkout.reason}); the skeleton is read from the registered commit. Read source files through the commit, not the working tree.`] : [],
|
|
81191
81312
|
"",
|
|
81192
81313
|
"## Directory skeleton",
|
|
81193
81314
|
"",
|
|
@@ -81256,6 +81377,15 @@ var init_productionPlanningMaterials = __esm(() => {
|
|
|
81256
81377
|
});
|
|
81257
81378
|
|
|
81258
81379
|
// src/project/submittedSourceLocator.ts
|
|
81380
|
+
function assertNoCaptureGap(locator, capturedText) {
|
|
81381
|
+
const lines = capturedText.replace(/\r\n/gu, `
|
|
81382
|
+
`).split(`
|
|
81383
|
+
`).slice(locator.start_line - 1, locator.end_line);
|
|
81384
|
+
const gapOnly = (line) => CAPTURE_GAP.test(line) && line.replace(new RegExp(CAPTURE_GAP.source, "gu"), "").replace(/<br\s*\/?>|[|>\s]/giu, "") === "";
|
|
81385
|
+
const gap = lines.findIndex(gapOnly);
|
|
81386
|
+
if (gap >= 0)
|
|
81387
|
+
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.");
|
|
81388
|
+
}
|
|
81259
81389
|
function resolveSubmittedSourceLocator(input, capturedText) {
|
|
81260
81390
|
const locator = submittedSourceLocatorSchema.parse(input);
|
|
81261
81391
|
if ("start_line" in locator)
|
|
@@ -81311,11 +81441,208 @@ function resolveSubmittedSourceLocator(input, capturedText) {
|
|
|
81311
81441
|
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.`);
|
|
81312
81442
|
return articleSourceLocatorSchema.parse({ path: locator.path, ...matches[0] });
|
|
81313
81443
|
}
|
|
81314
|
-
var submittedSourceLocatorSchema;
|
|
81444
|
+
var submittedSourceLocatorSchema, CAPTURE_GAP;
|
|
81315
81445
|
var init_submittedSourceLocator = __esm(() => {
|
|
81316
81446
|
init_src2();
|
|
81317
81447
|
init_productionFeedback();
|
|
81318
81448
|
submittedSourceLocatorSchema = articleSourceLocatorInputSchema;
|
|
81449
|
+
CAPTURE_GAP = /(?:> ?)?Resource unavailable: .+? \([^;()]+; [^()]+\)\. <!-- [^>]+ -->/u;
|
|
81450
|
+
});
|
|
81451
|
+
|
|
81452
|
+
// src/project/approvedRevisionReferences.ts
|
|
81453
|
+
async function resolveSubmittedReference(context, id3, at2, reference2) {
|
|
81454
|
+
if (!context.inScope(reference2.source_ref))
|
|
81455
|
+
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");
|
|
81456
|
+
const submitted = reference2.locator;
|
|
81457
|
+
const previous2 = context.previous.find((section) => section.id === id3)?.references ?? [];
|
|
81458
|
+
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;
|
|
81459
|
+
if (kept) {
|
|
81460
|
+
const observed = await relocateUnchangedReference(context.projectRoot, context.readSource, kept);
|
|
81461
|
+
if (observed.state === "current" || observed.state === "moved")
|
|
81462
|
+
return observed.reference;
|
|
81463
|
+
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");
|
|
81464
|
+
}
|
|
81465
|
+
const text5 = await context.readSource(reference2.source_ref, reference2.locator.path, true);
|
|
81466
|
+
let locator;
|
|
81467
|
+
try {
|
|
81468
|
+
locator = resolveSubmittedSourceLocator(reference2.locator, text5);
|
|
81469
|
+
assertNoCaptureGap(locator, text5);
|
|
81470
|
+
} catch (error) {
|
|
81471
|
+
if (error instanceof SubmissionInputError)
|
|
81472
|
+
throw new SubmissionInputError(`Fragment ${id3}: ${error.message}`, [...at2, "locator"]);
|
|
81473
|
+
throw error;
|
|
81474
|
+
}
|
|
81475
|
+
let resolved;
|
|
81476
|
+
try {
|
|
81477
|
+
resolved = createArticleSourceReference(reference2.source_ref, locator, text5);
|
|
81478
|
+
} catch (error) {
|
|
81479
|
+
if (!(error instanceof RangeError))
|
|
81480
|
+
throw error;
|
|
81481
|
+
throw new SubmissionInputError(`Fragment ${id3}: ${reference2.source_ref} ${locator.path}:${locator.start_line}-${locator.end_line} ` + `is outside the file, which has ${text5.replace(/\r\n/gu, `
|
|
81482
|
+
`).split(`
|
|
81483
|
+
`).length} lines. Cite existing lines, or use a quote or heading locator.`, [...at2, "locator"], "locator-out-of-range");
|
|
81484
|
+
}
|
|
81485
|
+
if (context.remember)
|
|
81486
|
+
rememberArticleRegion(context.projectRoot, resolved, text5);
|
|
81487
|
+
return resolved;
|
|
81488
|
+
}
|
|
81489
|
+
async function prepareRevisionReferences(input) {
|
|
81490
|
+
const edits = new Map(input.edits?.map((edit) => [edit.section_id, edit]));
|
|
81491
|
+
if (edits.size !== (input.edits?.length ?? 0))
|
|
81492
|
+
throw new TypeError("Repeated revision fragment identity");
|
|
81493
|
+
for (const id3 of edits.keys())
|
|
81494
|
+
if (!input.sectionIds.includes(id3)) {
|
|
81495
|
+
throw new TypeError(`Reference edit targets a missing fragment: ${id3}`);
|
|
81496
|
+
}
|
|
81497
|
+
let read;
|
|
81498
|
+
const inScope = (source2) => input.sourceRefs.some((scope2) => repoContentScopeMatches(scope2, source2));
|
|
81499
|
+
const context = {
|
|
81500
|
+
projectRoot: input.projectRoot,
|
|
81501
|
+
remember: input.remember !== false,
|
|
81502
|
+
previous: input.previous,
|
|
81503
|
+
sourceRefs: input.sourceRefs,
|
|
81504
|
+
inScope,
|
|
81505
|
+
readSource: Object.assign(async (source2, path2) => {
|
|
81506
|
+
if (!inScope(source2))
|
|
81507
|
+
throw new TypeError(`Source is outside this revision: ${source2}`);
|
|
81508
|
+
read ??= await registeredArticleSourceReader(input.projectRoot);
|
|
81509
|
+
return read(source2, path2, true);
|
|
81510
|
+
}, { incomplete: async (source2) => {
|
|
81511
|
+
read ??= await registeredArticleSourceReader(input.projectRoot);
|
|
81512
|
+
return await read.incomplete?.(source2) ?? false;
|
|
81513
|
+
} })
|
|
81514
|
+
};
|
|
81515
|
+
const result = [];
|
|
81516
|
+
const problems = [];
|
|
81517
|
+
for (const id3 of input.sectionIds) {
|
|
81518
|
+
const edit = edits.get(id3);
|
|
81519
|
+
if (edit?.references !== undefined) {
|
|
81520
|
+
const at2 = ["sections", input.edits.indexOf(edit), "references"];
|
|
81521
|
+
const references2 = [];
|
|
81522
|
+
for (const [index2, reference2] of edit.references.entries()) {
|
|
81523
|
+
try {
|
|
81524
|
+
references2.push(await resolveSubmittedReference(context, id3, [...at2, index2], reference2));
|
|
81525
|
+
} catch (error) {
|
|
81526
|
+
if (error instanceof SourceReadError || error instanceof SourceUnavailableError) {
|
|
81527
|
+
problems.push(new SubmissionInputError(`Fragment ${id3}: ${reference2.source_ref} ${reference2.locator.path}: ${error.message}`, [...at2, index2, "source_ref"], String(error.detail?.reason_code ?? "source-unavailable")));
|
|
81528
|
+
} else if (error instanceof SubmissionInputError)
|
|
81529
|
+
problems.push(error);
|
|
81530
|
+
else
|
|
81531
|
+
throw error;
|
|
81532
|
+
}
|
|
81533
|
+
}
|
|
81534
|
+
try {
|
|
81535
|
+
result.push({ id: id3, references: articleFragmentReferences(references2) });
|
|
81536
|
+
} catch (error) {
|
|
81537
|
+
if (error instanceof ZodError)
|
|
81538
|
+
problems.push(new SubmissionInputError(`Fragment ${id3}: ${error.issues.map((issue) => issue.message).join("; ")}`, at2));
|
|
81539
|
+
else
|
|
81540
|
+
throw error;
|
|
81541
|
+
}
|
|
81542
|
+
continue;
|
|
81543
|
+
}
|
|
81544
|
+
const references = [];
|
|
81545
|
+
const retained = input.previous.find((section) => section.id === id3)?.references ?? [];
|
|
81546
|
+
for (const [index2, reference2] of retained.entries()) {
|
|
81547
|
+
references.push(await retainReference(input, context, id3, ["fragments", id3, "references", index2], reference2, problems));
|
|
81548
|
+
}
|
|
81549
|
+
result.push({ id: id3, references });
|
|
81550
|
+
}
|
|
81551
|
+
if (problems.length === 1)
|
|
81552
|
+
throw problems[0];
|
|
81553
|
+
if (problems.length)
|
|
81554
|
+
throw new SubmissionInputErrors(problems);
|
|
81555
|
+
return result;
|
|
81556
|
+
}
|
|
81557
|
+
async function retainReference(input, context, id3, at2, reference2, problems) {
|
|
81558
|
+
const changed = input.changedBodies?.has(id3) === true;
|
|
81559
|
+
const where = `${reference2.source_ref} ${reference2.locator.path}:${reference2.locator.start_line}-${reference2.locator.end_line}`;
|
|
81560
|
+
let observed;
|
|
81561
|
+
try {
|
|
81562
|
+
observed = await relocateUnchangedReference(context.projectRoot, context.readSource, reference2);
|
|
81563
|
+
} catch (error) {
|
|
81564
|
+
if (!(error instanceof SourceReadError))
|
|
81565
|
+
throw error;
|
|
81566
|
+
if (changed)
|
|
81567
|
+
problems.push(new SubmissionInputError(`Fragment ${id3}: the text changed, but ${where} cannot be checked: ${error.message}`, at2, "reference-unverifiable"));
|
|
81568
|
+
return reference2;
|
|
81569
|
+
}
|
|
81570
|
+
if (observed.state === "current" || observed.state === "moved")
|
|
81571
|
+
return observed.reference;
|
|
81572
|
+
if (observed.state === "unavailable" && (observed.reason ?? "") in LOCAL_SOURCE_REASONS) {
|
|
81573
|
+
if (changed)
|
|
81574
|
+
problems.push(new SubmissionInputError(`Fragment ${id3}: the text changed, but ${where} cannot be checked on this machine (${observed.reason}). Make the source available, then submit again.`, at2, "reference-unverifiable"));
|
|
81575
|
+
return reference2;
|
|
81576
|
+
}
|
|
81577
|
+
if (citesScope(input.processedScopes ?? [], reference2.source_ref)) {
|
|
81578
|
+
const hint = await input.suggest?.(reference2).catch(() => {
|
|
81579
|
+
return;
|
|
81580
|
+
});
|
|
81581
|
+
problems.push(new SubmissionInputError(`Fragment ${id3}: ${where} is ${observed.state}${observed.reason ? ` (${observed.reason})` : ""} in the source version this revision processes. ` + `Rewrite the paragraph, cite its current text${hint ? ` (${hint})` : ""}, or remove the citation.`, at2, "processed-reference-stale"));
|
|
81582
|
+
return reference2;
|
|
81583
|
+
}
|
|
81584
|
+
input.onReminder?.({
|
|
81585
|
+
section_id: id3,
|
|
81586
|
+
state: observed.state,
|
|
81587
|
+
...observed.reason ? { reason: observed.reason } : {},
|
|
81588
|
+
source_ref: reference2.source_ref,
|
|
81589
|
+
locator: reference2.locator
|
|
81590
|
+
});
|
|
81591
|
+
return reference2;
|
|
81592
|
+
}
|
|
81593
|
+
async function suggestedCitation(projectRoot, reference2, sections) {
|
|
81594
|
+
const history = await articleReferenceHistoryReader(projectRoot, readProcessedScopes((await readKnowledgeStructure(projectRoot)).parsed))(reference2);
|
|
81595
|
+
if (!history?.text)
|
|
81596
|
+
return;
|
|
81597
|
+
const current3 = await (await registeredArticleSourceReader(projectRoot))(reference2.source_ref, reference2.locator.path, true);
|
|
81598
|
+
const cited = sections.flatMap((section) => section.references.map((item) => ({
|
|
81599
|
+
source_ref: item.source_ref,
|
|
81600
|
+
path: item.locator.path,
|
|
81601
|
+
start_line: item.locator.start_line,
|
|
81602
|
+
end_line: item.locator.end_line
|
|
81603
|
+
})));
|
|
81604
|
+
const suggested = await suggestedRange(projectRoot, reference2, history.text, current3, cited);
|
|
81605
|
+
if (!suggested)
|
|
81606
|
+
return;
|
|
81607
|
+
return "quote" in suggested.locator ? `the old text now maps to lines ${suggested.start_line}-${suggested.end_line}; cite them with a quote locator` : `the old text now maps to lines ${suggested.start_line}-${suggested.end_line}`;
|
|
81608
|
+
}
|
|
81609
|
+
function removedCitations(previous2, next) {
|
|
81610
|
+
const removed = [];
|
|
81611
|
+
for (const section of previous2) {
|
|
81612
|
+
const current3 = next.find((item) => item.id === section.id)?.references ?? [];
|
|
81613
|
+
for (const reference2 of section.references) {
|
|
81614
|
+
const kept = current3.some((item) => item.source_ref === reference2.source_ref && item.locator.path === reference2.locator.path && item.content_digest === reference2.content_digest);
|
|
81615
|
+
if (!kept)
|
|
81616
|
+
removed.push({
|
|
81617
|
+
section_id: section.id,
|
|
81618
|
+
source_ref: reference2.source_ref,
|
|
81619
|
+
path: reference2.locator.path,
|
|
81620
|
+
start_line: reference2.locator.start_line,
|
|
81621
|
+
end_line: reference2.locator.end_line
|
|
81622
|
+
});
|
|
81623
|
+
}
|
|
81624
|
+
}
|
|
81625
|
+
return removed;
|
|
81626
|
+
}
|
|
81627
|
+
function citationNotes(removed, reminders) {
|
|
81628
|
+
return {
|
|
81629
|
+
...removed.length ? { removed_citations: [...removed], removed_citations_note: REMOVED_CITATIONS_NOTE } : {},
|
|
81630
|
+
...reminders.length ? { reference_warnings: [...reminders], reference_warning_instruction: REFERENCE_REMINDER_NOTE } : {}
|
|
81631
|
+
};
|
|
81632
|
+
}
|
|
81633
|
+
var citesScope = (scopes, ref2) => scopes.some((scope2) => repoContentScopeMatches(scope2, ref2) || ref2.startsWith(`${scope2}#`) || ref2.startsWith(`${scope2}/`)), REFERENCE_REMINDER_NOTE = "These paragraphs keep citations their sources no longer confirm. The sources are outside what this revision processes, so the citations were kept; check them in a source update or a separate revision.", REMOVED_CITATIONS_NOTE = "These earlier citations are no longer in their sections. If you meant to replace or remove them, nothing needs doing; otherwise repeat each with its earlier lines to keep that evidence.";
|
|
81634
|
+
var init_approvedRevisionReferences = __esm(() => {
|
|
81635
|
+
init_zod();
|
|
81636
|
+
init_submittedSourceLocator();
|
|
81637
|
+
init_productionFeedback();
|
|
81638
|
+
init_src2();
|
|
81639
|
+
init_articleRegionBaselines();
|
|
81640
|
+
init_settledReferenceRelocation();
|
|
81641
|
+
init_articleSourceReader();
|
|
81642
|
+
init_gitObjectReader();
|
|
81643
|
+
init_articleReferenceObservation();
|
|
81644
|
+
init_packageBuildInventory();
|
|
81645
|
+
init_src2();
|
|
81319
81646
|
});
|
|
81320
81647
|
|
|
81321
81648
|
// src/project/productionArticleEdits.ts
|
|
@@ -81484,6 +81811,19 @@ function articleError(task, file, message, section) {
|
|
|
81484
81811
|
next: "Fix this task's indicated file or fragment, then resubmit only failed tasks using the existing input handles."
|
|
81485
81812
|
});
|
|
81486
81813
|
}
|
|
81814
|
+
function earlierCitation(base, retained, fragment2, ref2) {
|
|
81815
|
+
if (!("start_line" in ref2.locator))
|
|
81816
|
+
return;
|
|
81817
|
+
const signed = (value) => !!value.content_digest && ("start_line" in value.locator);
|
|
81818
|
+
const same = (value) => value.source_ref === ref2.source_ref && value.locator.path === ref2.locator.path && value.locator.start_line === ref2.locator.start_line && value.locator.end_line === ref2.locator.end_line;
|
|
81819
|
+
const from = (references) => references?.filter(signed).find(same);
|
|
81820
|
+
return from(base?.sections.find((section) => section.id === fragment2)?.references) ?? from(retained?.get(fragment2));
|
|
81821
|
+
}
|
|
81822
|
+
function outsideSourceMessage(task, source2, authorization) {
|
|
81823
|
+
const owners = authorization?.requirements.length ? `requirement ${authorization.requirements.join(", ")}` : "the requirement that owns this article";
|
|
81824
|
+
const replaced = [task.id, ...authorization?.dependents ?? []];
|
|
81825
|
+
return `Source is outside this task's authorized inputs: ${source2}. Cite only ${task.sources.map((item) => item.scope).join(", ")}, ` + `or authorize it: add ${source2} to evidence_source_scope of ${owners} in src/indexers.yaml, then submit a plan amendment ` + `whose replaces lists ${replaced.join(", ")}${replaced.length > 1 ? " (this task and the tasks that depend on it)" : ""} with a new task that includes the source.`;
|
|
81826
|
+
}
|
|
81487
81827
|
async function prepareProductionArticle(input) {
|
|
81488
81828
|
const { task } = input;
|
|
81489
81829
|
let files = input.files;
|
|
@@ -81560,33 +81900,50 @@ async function prepareProductionArticle(input) {
|
|
|
81560
81900
|
if (oversized.length)
|
|
81561
81901
|
throw articleError(task, files.references.path, `Split the claims or choose sufficient references for these fragments: ${oversized.join("; ")}.`);
|
|
81562
81902
|
const read = input.sourceReader ?? await registeredArticleSourceReader(input.projectRoot);
|
|
81903
|
+
const observe = createArticleReferenceObserver(read);
|
|
81563
81904
|
const allowed = new Set(task.sources.map((source2) => source2.scope));
|
|
81905
|
+
const problems = [];
|
|
81564
81906
|
const sections = [];
|
|
81565
81907
|
for (const fragment2 of fragments) {
|
|
81566
81908
|
const references = [];
|
|
81567
81909
|
for (const ref2 of byId.get(fragment2.id)) {
|
|
81568
81910
|
try {
|
|
81911
|
+
const earlier = earlierCitation(input.trustedBase ?? input.base, retained, fragment2.id, ref2);
|
|
81569
81912
|
const inherited = retained?.get(fragment2.id)?.some((value) => value.source_ref === ref2.source_ref && indexerProtocolDigest(value.locator) === indexerProtocolDigest(ref2.locator));
|
|
81570
|
-
const trusted = inherited
|
|
81571
|
-
if (!trusted
|
|
81572
|
-
throw new TypeError(
|
|
81573
|
-
|
|
81574
|
-
|
|
81575
|
-
|
|
81576
|
-
|
|
81577
|
-
|
|
81913
|
+
const trusted = inherited && earlier && input.trustedBase?.sections.find((section) => section.id === fragment2.id)?.references.some((value) => value.content_digest === earlier.content_digest);
|
|
81914
|
+
if (!trusted && ![...allowed].some((scope2) => repoContentScopeMatches(scope2, ref2.source_ref)))
|
|
81915
|
+
throw new TypeError(outsideSourceMessage(task, ref2.source_ref, await input.authorization?.()));
|
|
81916
|
+
if (earlier) {
|
|
81917
|
+
const observed = await observe(earlier);
|
|
81918
|
+
if (observed.state === "current" || observed.state === "moved") {
|
|
81919
|
+
references.push(observed.reference);
|
|
81920
|
+
continue;
|
|
81921
|
+
}
|
|
81922
|
+
const hint = observed.state === "not-found" ? await suggestedCitation(input.projectRoot, earlier, signedSections(input.trustedBase)).catch(() => {
|
|
81923
|
+
return;
|
|
81924
|
+
}) : undefined;
|
|
81925
|
+
throw new TypeError(`${earlier.source_ref} ${earlier.locator.path}:${earlier.locator.start_line}-${earlier.locator.end_line} repeats an earlier citation, ` + `which is ${observed.state}${observed.reason ? ` (${observed.reason})` : ""} in the current source. ` + `Rewrite the fragment, cite its current text${hint ? ` (${hint})` : ""} with a quote or new lines, or remove the citation.`);
|
|
81578
81926
|
}
|
|
81579
|
-
|
|
81927
|
+
const text5 = await read(ref2.source_ref, ref2.locator.path, true);
|
|
81928
|
+
const locator = resolveSubmittedSourceLocator(ref2.locator, text5);
|
|
81929
|
+
assertNoCaptureGap(locator, text5);
|
|
81930
|
+
const reference2 = createArticleSourceReference(ref2.source_ref, locator, text5);
|
|
81931
|
+
if (!input.preview)
|
|
81932
|
+
rememberArticleRegion(input.projectRoot, reference2, text5);
|
|
81580
81933
|
references.push(reference2);
|
|
81581
81934
|
} catch (error) {
|
|
81582
|
-
|
|
81935
|
+
if (error instanceof ContextError && error.detail?.reason_code !== "source-read-failed" && !(error instanceof SourceUnavailableError))
|
|
81936
|
+
throw error;
|
|
81937
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
81938
|
+
problems.push({ section: fragment2.id, message: error instanceof RangeError && "start_line" in ref2.locator ? `${ref2.source_ref} ${ref2.locator.path}:${ref2.locator.start_line}-${ref2.locator.end_line}: ${message}` : message });
|
|
81583
81939
|
}
|
|
81584
81940
|
}
|
|
81585
81941
|
let unique;
|
|
81586
81942
|
try {
|
|
81587
81943
|
unique = articleFragmentReferences(references);
|
|
81588
81944
|
} catch (error) {
|
|
81589
|
-
|
|
81945
|
+
problems.push({ section: fragment2.id, message: error instanceof ZodError ? error.issues.map((issue) => issue.message).join("; ") : error instanceof Error ? error.message : String(error) });
|
|
81946
|
+
continue;
|
|
81590
81947
|
}
|
|
81591
81948
|
sections.push({
|
|
81592
81949
|
section_ref: `${task.article_id}#${fragment2.id}`,
|
|
@@ -81596,6 +81953,11 @@ async function prepareProductionArticle(input) {
|
|
|
81596
81953
|
markdown_digest: indexerProtocolDigest(fragment2.readerVisibleBody)
|
|
81597
81954
|
});
|
|
81598
81955
|
}
|
|
81956
|
+
if (problems.length) {
|
|
81957
|
+
const error = articleError(task, files.references.path, problems.length === 1 ? problems[0].message : `${problems.length} reference problems: ${problems.map((item, index2) => `(${index2 + 1}) ${item.section}: ${item.message}`).join(" ")}`, problems[0].section);
|
|
81958
|
+
error.detail.problems = problems;
|
|
81959
|
+
throw error;
|
|
81960
|
+
}
|
|
81599
81961
|
const fingerprint = indexerProtocolDigest({ input: task.input, markdown, sections });
|
|
81600
81962
|
return parseCandidateRecord({
|
|
81601
81963
|
candidate_id: indexerCandidateId(fingerprint),
|
|
@@ -81623,7 +81985,10 @@ async function prepareProductionArticle(input) {
|
|
|
81623
81985
|
updated: new Date().toISOString()
|
|
81624
81986
|
}, 1);
|
|
81625
81987
|
}
|
|
81626
|
-
var import_yaml23, productionReferencesSchema
|
|
81988
|
+
var import_yaml23, productionReferencesSchema, signedSections = (base) => (base?.sections ?? []).map((section) => ({
|
|
81989
|
+
id: section.id,
|
|
81990
|
+
references: section.references.filter((value) => !!value.content_digest && ("start_line" in value.locator))
|
|
81991
|
+
}));
|
|
81627
81992
|
var init_productionArticle = __esm(() => {
|
|
81628
81993
|
init_submittedSourceLocator();
|
|
81629
81994
|
init_zod();
|
|
@@ -81633,6 +81998,9 @@ var init_productionArticle = __esm(() => {
|
|
|
81633
81998
|
init_exitCode();
|
|
81634
81999
|
init_candidateLedger();
|
|
81635
82000
|
init_articleSourceReader();
|
|
82001
|
+
init_articleReferenceObservation();
|
|
82002
|
+
init_approvedRevisionReferences();
|
|
82003
|
+
init_gitObjectReader();
|
|
81636
82004
|
init_articleRegionBaselines();
|
|
81637
82005
|
init_productionArticleEdits();
|
|
81638
82006
|
init_okfTypes();
|
|
@@ -81780,7 +82148,10 @@ function writeTarget3(path2, previous2, content3) {
|
|
|
81780
82148
|
content: content3
|
|
81781
82149
|
};
|
|
81782
82150
|
}
|
|
81783
|
-
|
|
82151
|
+
function completeProductionSubmission(input) {
|
|
82152
|
+
return completeProductionSubmissionImpl(input);
|
|
82153
|
+
}
|
|
82154
|
+
async function completeProductionSubmissionImpl(input) {
|
|
81784
82155
|
return withProjectWriteLock(input.projectRoot, "production-submit", async () => {
|
|
81785
82156
|
await recoverDurableMultiFileTransactions(input.projectRoot);
|
|
81786
82157
|
const snapshot = await readProductionStageSnapshot(input.projectRoot);
|
|
@@ -81880,7 +82251,7 @@ async function completeProductionSubmission(input) {
|
|
|
81880
82251
|
if (files.edits) {
|
|
81881
82252
|
base = await readProductionRepairDraft({ projectRoot: input.projectRoot, stage: stage.id, task }) ?? base;
|
|
81882
82253
|
}
|
|
81883
|
-
retainDraft = !!files.content && !!files.references;
|
|
82254
|
+
retainDraft = !input.preview && !!files.content && !!files.references;
|
|
81884
82255
|
const candidate = await measureContextDebugOperation({ projectRoot: input.projectRoot, operation: "production.submit.validate" }, () => prepareProductionArticle({
|
|
81885
82256
|
projectRoot: input.projectRoot,
|
|
81886
82257
|
task,
|
|
@@ -81889,7 +82260,9 @@ async function completeProductionSubmission(input) {
|
|
|
81889
82260
|
approvedBaseDigest: target.approvedBaseDigest,
|
|
81890
82261
|
...base ? { base } : {},
|
|
81891
82262
|
...target.base ? { trustedBase: target.base } : {},
|
|
81892
|
-
visibility: target.visibility
|
|
82263
|
+
visibility: target.visibility,
|
|
82264
|
+
preview: input.preview === true,
|
|
82265
|
+
authorization: () => productionAuthorization(input.projectRoot, stage, task)
|
|
81893
82266
|
}));
|
|
81894
82267
|
const key = knowledgeTargetPathKey(candidate.path);
|
|
81895
82268
|
byPath.set(key, [...(byPath.get(key) ?? []).filter((item) => item.article_id !== task.article_id), candidate]);
|
|
@@ -81897,22 +82270,35 @@ async function completeProductionSubmission(input) {
|
|
|
81897
82270
|
pending.set(task.id, { candidate, digest: contentDigest });
|
|
81898
82271
|
} catch (error) {
|
|
81899
82272
|
const detail = error && typeof error === "object" && "detail" in error ? error.detail : undefined;
|
|
81900
|
-
|
|
82273
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
82274
|
+
let note = "";
|
|
81901
82275
|
if (retainDraft) {
|
|
81902
82276
|
try {
|
|
81903
82277
|
await retainProductionRepairDraft({ projectRoot: input.projectRoot, stage: stage.id, task, files });
|
|
81904
82278
|
} catch {
|
|
81905
|
-
|
|
82279
|
+
note = " The temporary repair draft could not be retained; resubmit the complete draft.";
|
|
81906
82280
|
}
|
|
81907
82281
|
}
|
|
81908
|
-
|
|
81909
|
-
|
|
81910
|
-
|
|
81911
|
-
|
|
81912
|
-
|
|
81913
|
-
|
|
82282
|
+
const problems = Array.isArray(detail?.problems) ? detail.problems : [{ section: detail?.section, message: reason }];
|
|
82283
|
+
for (const item of problems) {
|
|
82284
|
+
result.failed.push({
|
|
82285
|
+
task: task.id,
|
|
82286
|
+
reason: item.message + note,
|
|
82287
|
+
...typeof detail?.file === "string" ? { file: detail.file } : {},
|
|
82288
|
+
...typeof item.section === "string" ? { section: item.section } : {}
|
|
82289
|
+
});
|
|
82290
|
+
}
|
|
81914
82291
|
}
|
|
81915
82292
|
}
|
|
82293
|
+
if (input.preview) {
|
|
82294
|
+
const order2 = new Map(fixed2.tasks.map((task, index2) => [task.task, index2]));
|
|
82295
|
+
return {
|
|
82296
|
+
protocol: "context.production-submission-preview/v1",
|
|
82297
|
+
written: false,
|
|
82298
|
+
ok: [...result.accepted.map((item) => item.task), ...pending.keys()].sort((a, b) => order2.get(a) - order2.get(b)),
|
|
82299
|
+
failed: result.failed
|
|
82300
|
+
};
|
|
82301
|
+
}
|
|
81916
82302
|
if (pending.size) {
|
|
81917
82303
|
const changedArticles = new Set([...pending.values()].map((proposal) => proposal.candidate.article_id));
|
|
81918
82304
|
const nextCandidates = [
|
|
@@ -81977,6 +82363,24 @@ async function completeProductionSubmission(input) {
|
|
|
81977
82363
|
return result;
|
|
81978
82364
|
});
|
|
81979
82365
|
}
|
|
82366
|
+
async function productionAuthorization(projectRoot, stage, task) {
|
|
82367
|
+
const { readProductionRequirements: readProductionRequirements2 } = await Promise.resolve().then(() => (init_productionRequirements(), exports_productionRequirements));
|
|
82368
|
+
const sources = new Set(task.sources.map((source2) => source2.scope));
|
|
82369
|
+
const requirements = await readProductionRequirements2(projectRoot).then((value) => value.requirements.filter((item) => [...item.target_scope.targets, ...item.evidence_source_scope?.targets ?? []].some((target) => sources.has(target.source_ref))).map((item) => item.id), () => []);
|
|
82370
|
+
const dependents = [];
|
|
82371
|
+
for (let added = true;added; ) {
|
|
82372
|
+
added = false;
|
|
82373
|
+
for (const other of stage.tasks) {
|
|
82374
|
+
if (dependents.includes(other.id) || ["accepted", "excluded", "replaced"].includes(other.status))
|
|
82375
|
+
continue;
|
|
82376
|
+
if (other.after.some((id3) => id3 === task.id || dependents.includes(id3))) {
|
|
82377
|
+
dependents.push(other.id);
|
|
82378
|
+
added = true;
|
|
82379
|
+
}
|
|
82380
|
+
}
|
|
82381
|
+
}
|
|
82382
|
+
return { requirements, dependents };
|
|
82383
|
+
}
|
|
81980
82384
|
var init_productionSubmission = __esm(() => {
|
|
81981
82385
|
init_submissionState();
|
|
81982
82386
|
init_src2();
|
|
@@ -82702,6 +83106,12 @@ var init_siteTheme2 = __esm(() => {
|
|
|
82702
83106
|
});
|
|
82703
83107
|
|
|
82704
83108
|
// src/project/workspaceContentSnapshot.ts
|
|
83109
|
+
var exports_workspaceContentSnapshot = {};
|
|
83110
|
+
__export(exports_workspaceContentSnapshot, {
|
|
83111
|
+
workspaceContentSnapshot: () => workspaceContentSnapshot,
|
|
83112
|
+
observeWorkspaceContent: () => observeWorkspaceContent,
|
|
83113
|
+
excludedWorkspaceContent: () => excludedWorkspaceContent
|
|
83114
|
+
});
|
|
82705
83115
|
import { createHash as createHash15 } from "node:crypto";
|
|
82706
83116
|
import { execFile as execFile10 } from "node:child_process";
|
|
82707
83117
|
import { lstat as lstat8, readFile as readFile38, readdir as readdir9, realpath as realpath9 } from "node:fs/promises";
|
|
@@ -85160,7 +85570,7 @@ import {
|
|
|
85160
85570
|
renameSync as renameSync2,
|
|
85161
85571
|
writeFileSync as writeFileSync3
|
|
85162
85572
|
} from "node:fs";
|
|
85163
|
-
import { spawn as
|
|
85573
|
+
import { spawn as spawn4 } from "node:child_process";
|
|
85164
85574
|
import { dirname as dirname25, join as join60 } from "node:path";
|
|
85165
85575
|
import { fileURLToPath as fileURLToPath4 } from "node:url";
|
|
85166
85576
|
function isRecord10(value) {
|
|
@@ -85237,7 +85647,7 @@ async function describeRuntimeEventSink(sink, cwd) {
|
|
|
85237
85647
|
}, RUNTIME_EVENT_SINK_DESCRIPTION_TIMEOUT_MS);
|
|
85238
85648
|
let child;
|
|
85239
85649
|
try {
|
|
85240
|
-
const spawned =
|
|
85650
|
+
const spawned = spawn4(sink.command, describeArgs, {
|
|
85241
85651
|
cwd,
|
|
85242
85652
|
env: process.env,
|
|
85243
85653
|
shell: false,
|
|
@@ -85352,7 +85762,7 @@ function dispatchCommand(sink, batch, cwd) {
|
|
|
85352
85762
|
})();
|
|
85353
85763
|
};
|
|
85354
85764
|
try {
|
|
85355
|
-
const child =
|
|
85765
|
+
const child = spawn4(sink.command, sink.args, {
|
|
85356
85766
|
cwd,
|
|
85357
85767
|
env: process.env,
|
|
85358
85768
|
shell: false,
|
|
@@ -88154,13 +88564,6 @@ async function missingObjects(root, commit, paths) {
|
|
|
88154
88564
|
return checked.split(`
|
|
88155
88565
|
`).filter((line) => line.endsWith(" missing")).map((line) => line.split(" ")[0]);
|
|
88156
88566
|
}
|
|
88157
|
-
function failureSummary(error) {
|
|
88158
|
-
const text7 = error && typeof error === "object" && "stderr" in error ? String(error.stderr ?? "") : String(error);
|
|
88159
|
-
const line = text7.split(`
|
|
88160
|
-
`).map((part) => part.trim()).find((part) => /^(fatal|error):/iu.test(part)) ?? text7.split(`
|
|
88161
|
-
`)[0]?.trim() ?? "";
|
|
88162
|
-
return line.replace(/\/\/[^/@\s]+@/gu, "//").slice(0, 200) || "fetch failed";
|
|
88163
|
-
}
|
|
88164
88567
|
async function prepareRepositoryContents(projectRoot, requests) {
|
|
88165
88568
|
const registry2 = await loadSourcesRegistry({ rootDir: projectRoot });
|
|
88166
88569
|
const results = [];
|
|
@@ -88187,7 +88590,9 @@ async function prepareRepositoryContents(projectRoot, requests) {
|
|
|
88187
88590
|
else {
|
|
88188
88591
|
try {
|
|
88189
88592
|
for (let index2 = 0;index2 < missing2.length; index2 += FETCH_BATCH) {
|
|
88190
|
-
await
|
|
88593
|
+
await runGitWithProgress([
|
|
88594
|
+
"-C",
|
|
88595
|
+
root,
|
|
88191
88596
|
"-c",
|
|
88192
88597
|
"fetch.negotiationAlgorithm=noop",
|
|
88193
88598
|
"fetch",
|
|
@@ -88197,10 +88602,10 @@ async function prepareRepositoryContents(projectRoot, requests) {
|
|
|
88197
88602
|
"--filter=blob:none",
|
|
88198
88603
|
remote,
|
|
88199
88604
|
...missing2.slice(index2, index2 + FETCH_BATCH)
|
|
88200
|
-
], { env: { ...process.env, GIT_TERMINAL_PROMPT: "0" },
|
|
88605
|
+
], { env: { ...process.env, GIT_TERMINAL_PROMPT: "0" }, label: `git fetch of ${request.source_ref} contents` });
|
|
88201
88606
|
}
|
|
88202
88607
|
} catch (error) {
|
|
88203
|
-
result.reason =
|
|
88608
|
+
result.reason = redactRemoteCredentials(error instanceof Error ? error.message : String(error)).slice(0, 400);
|
|
88204
88609
|
}
|
|
88205
88610
|
result.unresolved = (await missingObjects(root, commit, paths)).length;
|
|
88206
88611
|
if (!result.unresolved)
|
|
@@ -88214,6 +88619,7 @@ async function prepareRepositoryContents(projectRoot, requests) {
|
|
|
88214
88619
|
var execute3, offline, FETCH_BATCH = 1000, PATH_BATCH = 500;
|
|
88215
88620
|
var init_repoContentPrefetch = __esm(() => {
|
|
88216
88621
|
init_src2();
|
|
88622
|
+
init_gitProgress();
|
|
88217
88623
|
execute3 = promisify10(execFile12);
|
|
88218
88624
|
offline = { ...process.env, GIT_NO_LAZY_FETCH: "1" };
|
|
88219
88625
|
});
|
|
@@ -88327,10 +88733,11 @@ async function readKnowledgeUpdate(projectRoot) {
|
|
|
88327
88733
|
throw new TypeError("Source update request digest is invalid");
|
|
88328
88734
|
return update;
|
|
88329
88735
|
}
|
|
88330
|
-
function stopOnUnreadableSources(unresolved, prepared2, network) {
|
|
88736
|
+
function stopOnUnreadableSources(unresolved, prepared2, network, fetchFailures = new Map, registered = new Map) {
|
|
88331
88737
|
const missingCommits = [...new Set(unresolved.filter((item) => item.reason === "source-history-missing").map((item) => item.reference.source_ref))];
|
|
88332
88738
|
if (missingCommits.length) {
|
|
88333
|
-
|
|
88739
|
+
const why = missingCommits.map((source2) => fetchFailures.get(registered.get(source2) ?? "")).filter(Boolean);
|
|
88740
|
+
throw new TypeError(`The registered commit of ${missingCommits.join(", ")} is not in its source checkout${network ? " and could not be fetched" : ""}` + `${why.length ? ` (${why.join("; ")})` : ""}. ` + "Check that the registered commit SHA exists in the remote repository. " + (network ? "If it does, fetch and check out the registered commit in the source checkout (see context source list --format json), then rerun context update --pending --format json." : "context update --pending fetches it; an explicit update reads only what the checkout has, so fetch and check out the commit first, then rerun this update."));
|
|
88334
88741
|
}
|
|
88335
88742
|
const contentMissing = [...new Set(unresolved.filter((item) => item.reason === "source-content-missing").map((item) => item.reference.source_ref))];
|
|
88336
88743
|
if (contentMissing.length) {
|
|
@@ -88394,15 +88801,16 @@ async function beginKnowledgeUpdate(projectRoot, value, options = {}) {
|
|
|
88394
88801
|
});
|
|
88395
88802
|
const network = options.pending === true;
|
|
88396
88803
|
let prepared2 = [];
|
|
88804
|
+
let fetchFailures = new Map;
|
|
88397
88805
|
if (network) {
|
|
88398
|
-
await fetchSourceCommits(projectRoot, [
|
|
88806
|
+
fetchFailures = await fetchSourceCommits(projectRoot, [
|
|
88399
88807
|
...repoScopes.map((source_ref) => ({ source_ref })),
|
|
88400
88808
|
...comparisons.map((item) => ({ source_ref: item.source_ref, commit: item.from }))
|
|
88401
88809
|
]);
|
|
88402
88810
|
prepared2 = await prepareRepositoryContents(projectRoot, repoScopes.map((source2) => ({ source_ref: source2, paths: citedPaths(source2, cited) })));
|
|
88403
88811
|
}
|
|
88404
88812
|
const inspected = await inspectSettledReferences(projectRoot, cited, scopes.map((scope2) => scope2.source_ref), settled);
|
|
88405
|
-
stopOnUnreadableSources(inspected.unresolved, prepared2, network);
|
|
88813
|
+
stopOnUnreadableSources(inspected.unresolved, prepared2, network, fetchFailures, new Map(scopes.map((scope2) => [scope2.source_ref, scope2.processed_version])));
|
|
88406
88814
|
if (network)
|
|
88407
88815
|
await prepareRepositoryContents(projectRoot, repoScopes.flatMap((source2) => {
|
|
88408
88816
|
const scope2 = scopes.find((item) => item.source_ref === source2);
|
|
@@ -94502,7 +94910,7 @@ var init_packageSiteLocales = __esm(() => {
|
|
|
94502
94910
|
|
|
94503
94911
|
// src/project/packageSite.ts
|
|
94504
94912
|
import { createHash as createHash27 } from "node:crypto";
|
|
94505
|
-
import { spawn as
|
|
94913
|
+
import { spawn as spawn5 } from "node:child_process";
|
|
94506
94914
|
import { mkdir as mkdir30, mkdtemp as mkdtemp3, readFile as readFile72, writeFile as writeFile23, rm as rm18, symlink as symlink4, cp as cp2, access as access5, stat as stat9 } from "node:fs/promises";
|
|
94507
94915
|
import { createRequire as createRequire5 } from "node:module";
|
|
94508
94916
|
import { dirname as dirname38, join as join86, posix as posix10 } from "node:path";
|
|
@@ -94625,7 +95033,7 @@ function siteSections(entries2) {
|
|
|
94625
95033
|
async function compileSite(root, outDir) {
|
|
94626
95034
|
const vitepressRoot = dirname38(require2.resolve("vitepress/package.json"));
|
|
94627
95035
|
await new Promise((resolve8, reject) => {
|
|
94628
|
-
const child =
|
|
95036
|
+
const child = spawn5(process.versions.bun ? "node" : process.execPath, [join86(vitepressRoot, "bin/vitepress.js"), "build", root, "--outDir", outDir], { stdio: ["ignore", "pipe", "pipe"] });
|
|
94629
95037
|
let tail = "";
|
|
94630
95038
|
const receive = (chunk) => {
|
|
94631
95039
|
tail = (tail + chunk.toString()).slice(-16000);
|
|
@@ -97208,201 +97616,6 @@ var init_approvedRevisionEdits = __esm(() => {
|
|
|
97208
97616
|
init_approvedRevisionPrograms();
|
|
97209
97617
|
});
|
|
97210
97618
|
|
|
97211
|
-
// src/project/approvedRevisionReferences.ts
|
|
97212
|
-
async function resolveSubmittedReference(context, id3, at2, reference2) {
|
|
97213
|
-
if (!context.inScope(reference2.source_ref))
|
|
97214
|
-
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");
|
|
97215
|
-
const submitted = reference2.locator;
|
|
97216
|
-
const previous2 = context.previous.find((section) => section.id === id3)?.references ?? [];
|
|
97217
|
-
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;
|
|
97218
|
-
if (kept) {
|
|
97219
|
-
const observed = await relocateUnchangedReference(context.projectRoot, context.readSource, kept);
|
|
97220
|
-
if (observed.state === "current" || observed.state === "moved")
|
|
97221
|
-
return observed.reference;
|
|
97222
|
-
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");
|
|
97223
|
-
}
|
|
97224
|
-
const text8 = await context.readSource(reference2.source_ref, reference2.locator.path, true);
|
|
97225
|
-
let locator;
|
|
97226
|
-
try {
|
|
97227
|
-
locator = resolveSubmittedSourceLocator(reference2.locator, text8);
|
|
97228
|
-
} catch (error) {
|
|
97229
|
-
if (error instanceof SubmissionInputError)
|
|
97230
|
-
throw new SubmissionInputError(`Fragment ${id3}: ${error.message}`, [...at2, "locator"]);
|
|
97231
|
-
throw error;
|
|
97232
|
-
}
|
|
97233
|
-
let resolved;
|
|
97234
|
-
try {
|
|
97235
|
-
resolved = createArticleSourceReference(reference2.source_ref, locator, text8);
|
|
97236
|
-
} catch (error) {
|
|
97237
|
-
if (!(error instanceof RangeError))
|
|
97238
|
-
throw error;
|
|
97239
|
-
throw new SubmissionInputError(`Fragment ${id3}: ${reference2.source_ref} ${locator.path}:${locator.start_line}-${locator.end_line} ` + `is outside the file, which has ${text8.replace(/\r\n/gu, `
|
|
97240
|
-
`).split(`
|
|
97241
|
-
`).length} lines. Cite existing lines, or use a quote or heading locator.`, [...at2, "locator"], "locator-out-of-range");
|
|
97242
|
-
}
|
|
97243
|
-
if (context.remember)
|
|
97244
|
-
rememberArticleRegion(context.projectRoot, resolved, text8);
|
|
97245
|
-
return resolved;
|
|
97246
|
-
}
|
|
97247
|
-
async function prepareRevisionReferences(input) {
|
|
97248
|
-
const edits = new Map(input.edits?.map((edit) => [edit.section_id, edit]));
|
|
97249
|
-
if (edits.size !== (input.edits?.length ?? 0))
|
|
97250
|
-
throw new TypeError("Repeated revision fragment identity");
|
|
97251
|
-
for (const id3 of edits.keys())
|
|
97252
|
-
if (!input.sectionIds.includes(id3)) {
|
|
97253
|
-
throw new TypeError(`Reference edit targets a missing fragment: ${id3}`);
|
|
97254
|
-
}
|
|
97255
|
-
let read;
|
|
97256
|
-
const inScope = (source2) => input.sourceRefs.some((scope2) => repoContentScopeMatches(scope2, source2));
|
|
97257
|
-
const context = {
|
|
97258
|
-
projectRoot: input.projectRoot,
|
|
97259
|
-
remember: input.remember !== false,
|
|
97260
|
-
previous: input.previous,
|
|
97261
|
-
sourceRefs: input.sourceRefs,
|
|
97262
|
-
inScope,
|
|
97263
|
-
readSource: Object.assign(async (source2, path2) => {
|
|
97264
|
-
if (!inScope(source2))
|
|
97265
|
-
throw new TypeError(`Source is outside this revision: ${source2}`);
|
|
97266
|
-
read ??= await registeredArticleSourceReader(input.projectRoot);
|
|
97267
|
-
return read(source2, path2, true);
|
|
97268
|
-
}, { incomplete: async (source2) => {
|
|
97269
|
-
read ??= await registeredArticleSourceReader(input.projectRoot);
|
|
97270
|
-
return await read.incomplete?.(source2) ?? false;
|
|
97271
|
-
} })
|
|
97272
|
-
};
|
|
97273
|
-
const result = [];
|
|
97274
|
-
const problems = [];
|
|
97275
|
-
for (const id3 of input.sectionIds) {
|
|
97276
|
-
const edit = edits.get(id3);
|
|
97277
|
-
if (edit?.references !== undefined) {
|
|
97278
|
-
const at2 = ["sections", input.edits.indexOf(edit), "references"];
|
|
97279
|
-
const references2 = [];
|
|
97280
|
-
for (const [index3, reference2] of edit.references.entries()) {
|
|
97281
|
-
try {
|
|
97282
|
-
references2.push(await resolveSubmittedReference(context, id3, [...at2, index3], reference2));
|
|
97283
|
-
} catch (error) {
|
|
97284
|
-
if (error instanceof SourceReadError || error instanceof SourceUnavailableError) {
|
|
97285
|
-
problems.push(new SubmissionInputError(`Fragment ${id3}: ${reference2.source_ref} ${reference2.locator.path}: ${error.message}`, [...at2, index3, "source_ref"], String(error.detail?.reason_code ?? "source-unavailable")));
|
|
97286
|
-
} else if (error instanceof SubmissionInputError)
|
|
97287
|
-
problems.push(error);
|
|
97288
|
-
else
|
|
97289
|
-
throw error;
|
|
97290
|
-
}
|
|
97291
|
-
}
|
|
97292
|
-
try {
|
|
97293
|
-
result.push({ id: id3, references: articleFragmentReferences(references2) });
|
|
97294
|
-
} catch (error) {
|
|
97295
|
-
if (error instanceof ZodError)
|
|
97296
|
-
problems.push(new SubmissionInputError(`Fragment ${id3}: ${error.issues.map((issue) => issue.message).join("; ")}`, at2));
|
|
97297
|
-
else
|
|
97298
|
-
throw error;
|
|
97299
|
-
}
|
|
97300
|
-
continue;
|
|
97301
|
-
}
|
|
97302
|
-
const references = [];
|
|
97303
|
-
const retained = input.previous.find((section) => section.id === id3)?.references ?? [];
|
|
97304
|
-
for (const [index3, reference2] of retained.entries()) {
|
|
97305
|
-
references.push(await retainReference(input, context, id3, ["fragments", id3, "references", index3], reference2, problems));
|
|
97306
|
-
}
|
|
97307
|
-
result.push({ id: id3, references });
|
|
97308
|
-
}
|
|
97309
|
-
if (problems.length === 1)
|
|
97310
|
-
throw problems[0];
|
|
97311
|
-
if (problems.length)
|
|
97312
|
-
throw new SubmissionInputErrors(problems);
|
|
97313
|
-
return result;
|
|
97314
|
-
}
|
|
97315
|
-
async function retainReference(input, context, id3, at2, reference2, problems) {
|
|
97316
|
-
const changed = input.changedBodies?.has(id3) === true;
|
|
97317
|
-
const where = `${reference2.source_ref} ${reference2.locator.path}:${reference2.locator.start_line}-${reference2.locator.end_line}`;
|
|
97318
|
-
let observed;
|
|
97319
|
-
try {
|
|
97320
|
-
observed = await relocateUnchangedReference(context.projectRoot, context.readSource, reference2);
|
|
97321
|
-
} catch (error) {
|
|
97322
|
-
if (!(error instanceof SourceReadError))
|
|
97323
|
-
throw error;
|
|
97324
|
-
if (changed)
|
|
97325
|
-
problems.push(new SubmissionInputError(`Fragment ${id3}: the text changed, but ${where} cannot be checked: ${error.message}`, at2, "reference-unverifiable"));
|
|
97326
|
-
return reference2;
|
|
97327
|
-
}
|
|
97328
|
-
if (observed.state === "current" || observed.state === "moved")
|
|
97329
|
-
return observed.reference;
|
|
97330
|
-
if (observed.state === "unavailable" && (observed.reason ?? "") in LOCAL_SOURCE_REASONS) {
|
|
97331
|
-
if (changed)
|
|
97332
|
-
problems.push(new SubmissionInputError(`Fragment ${id3}: the text changed, but ${where} cannot be checked on this machine (${observed.reason}). Make the source available, then submit again.`, at2, "reference-unverifiable"));
|
|
97333
|
-
return reference2;
|
|
97334
|
-
}
|
|
97335
|
-
if (citesScope(input.processedScopes ?? [], reference2.source_ref)) {
|
|
97336
|
-
const hint = await input.suggest?.(reference2).catch(() => {
|
|
97337
|
-
return;
|
|
97338
|
-
});
|
|
97339
|
-
problems.push(new SubmissionInputError(`Fragment ${id3}: ${where} is ${observed.state}${observed.reason ? ` (${observed.reason})` : ""} in the source version this revision processes. ` + `Rewrite the paragraph, cite its current text${hint ? ` (${hint})` : ""}, or remove the citation.`, at2, "processed-reference-stale"));
|
|
97340
|
-
return reference2;
|
|
97341
|
-
}
|
|
97342
|
-
input.onReminder?.({
|
|
97343
|
-
section_id: id3,
|
|
97344
|
-
state: observed.state,
|
|
97345
|
-
...observed.reason ? { reason: observed.reason } : {},
|
|
97346
|
-
source_ref: reference2.source_ref,
|
|
97347
|
-
locator: reference2.locator
|
|
97348
|
-
});
|
|
97349
|
-
return reference2;
|
|
97350
|
-
}
|
|
97351
|
-
async function suggestedCitation(projectRoot, reference2, sections) {
|
|
97352
|
-
const history = await articleReferenceHistoryReader(projectRoot, readProcessedScopes((await readKnowledgeStructure(projectRoot)).parsed))(reference2);
|
|
97353
|
-
if (!history?.text)
|
|
97354
|
-
return;
|
|
97355
|
-
const current3 = await (await registeredArticleSourceReader(projectRoot))(reference2.source_ref, reference2.locator.path, true);
|
|
97356
|
-
const cited = sections.flatMap((section) => section.references.map((item) => ({
|
|
97357
|
-
source_ref: item.source_ref,
|
|
97358
|
-
path: item.locator.path,
|
|
97359
|
-
start_line: item.locator.start_line,
|
|
97360
|
-
end_line: item.locator.end_line
|
|
97361
|
-
})));
|
|
97362
|
-
const suggested = await suggestedRange(projectRoot, reference2, history.text, current3, cited);
|
|
97363
|
-
if (!suggested)
|
|
97364
|
-
return;
|
|
97365
|
-
return "quote" in suggested.locator ? `the old text now maps to lines ${suggested.start_line}-${suggested.end_line}; cite them with a quote locator` : `the old text now maps to lines ${suggested.start_line}-${suggested.end_line}`;
|
|
97366
|
-
}
|
|
97367
|
-
function removedCitations(previous2, next) {
|
|
97368
|
-
const removed = [];
|
|
97369
|
-
for (const section of previous2) {
|
|
97370
|
-
const current3 = next.find((item) => item.id === section.id)?.references ?? [];
|
|
97371
|
-
for (const reference2 of section.references) {
|
|
97372
|
-
const kept = current3.some((item) => item.source_ref === reference2.source_ref && item.locator.path === reference2.locator.path && item.content_digest === reference2.content_digest);
|
|
97373
|
-
if (!kept)
|
|
97374
|
-
removed.push({
|
|
97375
|
-
section_id: section.id,
|
|
97376
|
-
source_ref: reference2.source_ref,
|
|
97377
|
-
path: reference2.locator.path,
|
|
97378
|
-
start_line: reference2.locator.start_line,
|
|
97379
|
-
end_line: reference2.locator.end_line
|
|
97380
|
-
});
|
|
97381
|
-
}
|
|
97382
|
-
}
|
|
97383
|
-
return removed;
|
|
97384
|
-
}
|
|
97385
|
-
function citationNotes(removed, reminders) {
|
|
97386
|
-
return {
|
|
97387
|
-
...removed.length ? { removed_citations: [...removed], removed_citations_note: REMOVED_CITATIONS_NOTE } : {},
|
|
97388
|
-
...reminders.length ? { reference_warnings: [...reminders], reference_warning_instruction: REFERENCE_REMINDER_NOTE } : {}
|
|
97389
|
-
};
|
|
97390
|
-
}
|
|
97391
|
-
var citesScope = (scopes, ref2) => scopes.some((scope2) => repoContentScopeMatches(scope2, ref2) || ref2.startsWith(`${scope2}#`) || ref2.startsWith(`${scope2}/`)), REFERENCE_REMINDER_NOTE = "These paragraphs keep citations their sources no longer confirm. The sources are outside what this revision processes, so the citations were kept; check them in a source update or a separate revision.", REMOVED_CITATIONS_NOTE = "These earlier citations are no longer in their sections. If you meant to replace or remove them, nothing needs doing; otherwise repeat each with its earlier lines to keep that evidence.";
|
|
97392
|
-
var init_approvedRevisionReferences = __esm(() => {
|
|
97393
|
-
init_zod();
|
|
97394
|
-
init_submittedSourceLocator();
|
|
97395
|
-
init_productionFeedback();
|
|
97396
|
-
init_src2();
|
|
97397
|
-
init_articleRegionBaselines();
|
|
97398
|
-
init_settledReferenceRelocation();
|
|
97399
|
-
init_articleSourceReader();
|
|
97400
|
-
init_gitObjectReader();
|
|
97401
|
-
init_articleReferenceObservation();
|
|
97402
|
-
init_packageBuildInventory();
|
|
97403
|
-
init_src2();
|
|
97404
|
-
});
|
|
97405
|
-
|
|
97406
97619
|
// src/project/approvedPageMove.ts
|
|
97407
97620
|
var exports_approvedPageMove = {};
|
|
97408
97621
|
__export(exports_approvedPageMove, {
|
|
@@ -99531,7 +99744,7 @@ function createContextWorkflowFacts(observation, authorities) {
|
|
|
99531
99744
|
const buildLogPending = runtimeEvents.configured && runtimeEvents.pending_kinds.includes("package.build.completed");
|
|
99532
99745
|
return {
|
|
99533
99746
|
workspace: {
|
|
99534
|
-
task_start_authorized: observation.taskPreparation !== "cleared",
|
|
99747
|
+
task_start_authorized: observation.taskPreparation !== "cleared" || outputOnlyMaintenance,
|
|
99535
99748
|
project_entry_valid: observation.projectEntryValid,
|
|
99536
99749
|
state_valid: workspaceStateValid(observation)
|
|
99537
99750
|
},
|
|
@@ -101232,7 +101445,8 @@ async function collectProjectStatusSnapshotInternal(projectRoot, options = {}) {
|
|
|
101232
101445
|
const maintenanceState = await readMaintenance2(projectRoot);
|
|
101233
101446
|
const maintenance = maintenanceState.active;
|
|
101234
101447
|
const authoring = production && !production.delivery && (dispatchProductionStage(production, productionCapabilitiesSchema.parse({})).state !== "ended" || draftStatus.count > 0 && draftStatus.diagnostics.length === 0);
|
|
101235
|
-
const
|
|
101448
|
+
const navigationOnly = !maintenance && !localRevision && !localUpdate && !localRollback && taskPreparation === "cleared" && !production && phaseStatus.projectEntryValid && await navigationOnlyChange(projectRoot, phaseStatus.packages);
|
|
101449
|
+
const deferDeliveryChecks = !maintenance && !localRevision && !localUpdate && !localRollback && !navigationOnly && (taskPreparation === "cleared" && !production || !!authoring);
|
|
101236
101450
|
const collectionsWithPages = new Set;
|
|
101237
101451
|
const approvedPages = await countFiles(join104(projectRoot, "knowledge"), (rel) => {
|
|
101238
101452
|
if (!isApprovedKnowledgeMarkdownPath(rel) || rel.startsWith("assets/"))
|
|
@@ -101266,7 +101480,7 @@ async function collectProjectStatusSnapshotInternal(projectRoot, options = {}) {
|
|
|
101266
101480
|
const indexerDrafts = productionCandidates.filter((candidate) => candidate.status === "draft");
|
|
101267
101481
|
const indexerRejected = productionCandidates.filter((candidate) => candidate.status === "rejected");
|
|
101268
101482
|
const draftCollections = [...new Set(indexerDrafts.map((candidate) => candidate.collection))].sort();
|
|
101269
|
-
const maintenanceOutputOnly = maintenance?.input.operation === "rebuild" || maintenance?.phase === "finishing" || maintenance?.phase === "cancelling" && indexerDrafts.length === 0;
|
|
101483
|
+
const maintenanceOutputOnly = navigationOnly || maintenance?.input.operation === "rebuild" || maintenance?.phase === "finishing" || maintenance?.phase === "cancelling" && indexerDrafts.length === 0;
|
|
101270
101484
|
const sourceUpdate = !maintenance && !localRevision && !localUpdate && !localRollback && !production && draftStatus.count === 0 && approvedPages > 0 ? await Promise.resolve().then(() => (init_pendingSourceUpdates(), exports_pendingSourceUpdates)).then(({ inspectPendingSourceUpdates: inspectPendingSourceUpdates2 }) => inspectPendingSourceUpdates2(projectRoot)) : undefined;
|
|
101271
101485
|
const observation = {
|
|
101272
101486
|
versionCurrent: phaseStatus.projectEntryValid && !deferDeliveryChecks ? (await inspectWorkspaceVersion(projectRoot)).current : false,
|
|
@@ -101466,6 +101680,28 @@ async function reevaluateProjectStatusWorkflow(input) {
|
|
|
101466
101680
|
async function collectProjectStatus(projectRoot, options = {}) {
|
|
101467
101681
|
return (await collectProjectStatusSnapshot(projectRoot, options)).status;
|
|
101468
101682
|
}
|
|
101683
|
+
async function navigationOnlyChange(projectRoot, packages) {
|
|
101684
|
+
const { KNOWLEDGE_MAP_PATH: KNOWLEDGE_MAP_PATH2 } = await Promise.resolve().then(() => (init_knowledgeMap2(), exports_knowledgeMap));
|
|
101685
|
+
const { excludedWorkspaceContent: excludedWorkspaceContent2 } = await Promise.resolve().then(() => (init_workspaceContentSnapshot(), exports_workspaceContentSnapshot));
|
|
101686
|
+
const { execFile: execFile17 } = await import("node:child_process");
|
|
101687
|
+
const git4 = (...args) => new Promise((done) => execFile17("git", ["-C", projectRoot, ...args], { env: { ...process.env, GIT_OPTIONAL_LOCKS: "0" }, timeout: 30000, maxBuffer: 67108864 }, (error, stdout) => done(error ? undefined : stdout)));
|
|
101688
|
+
const recorded = (await git4("log", "-1", "--format=%H", "--", "changelog.yaml"))?.trim();
|
|
101689
|
+
if (recorded) {
|
|
101690
|
+
const changed = [
|
|
101691
|
+
...(await git4("diff", "--name-only", "--relative", recorded, "--"))?.split(`
|
|
101692
|
+
`) ?? [],
|
|
101693
|
+
...(await git4("ls-files", "--others", "--exclude-standard"))?.split(`
|
|
101694
|
+
`) ?? []
|
|
101695
|
+
].filter((path2) => path2 && path2 !== "package.json" && !excludedWorkspaceContent2(path2));
|
|
101696
|
+
if (changed.includes(KNOWLEDGE_MAP_PATH2) && changed.every((path2) => path2 === KNOWLEDGE_MAP_PATH2 || !/^(?:knowledge|sources|src)\//u.test(path2)))
|
|
101697
|
+
return true;
|
|
101698
|
+
}
|
|
101699
|
+
const latest = (await readWorkspaceChangelog(projectRoot).catch(() => []))[0];
|
|
101700
|
+
if (!latest || !latest.triggers.every((trigger) => trigger.kind === "navigation"))
|
|
101701
|
+
return false;
|
|
101702
|
+
const freshness = await readPackageFreshnessStatus(projectRoot, packages);
|
|
101703
|
+
return freshness.diagnostics.length > 0 || freshness.packages.length < packages.length || freshness.packages.some((item) => item.state !== "ready");
|
|
101704
|
+
}
|
|
101469
101705
|
var init_status = __esm(() => {
|
|
101470
101706
|
init_documentCaptureAvailability();
|
|
101471
101707
|
init_productionPlanning();
|
|
@@ -106915,14 +107151,19 @@ async function runLarkResourceCommand(runner2, args, options) {
|
|
|
106915
107151
|
}
|
|
106916
107152
|
return result.stdout;
|
|
106917
107153
|
}
|
|
107154
|
+
function larkPermissionGuidance(error) {
|
|
107155
|
+
const stderr = error instanceof Error && "stderr" in error && typeof error.stderr === "string" ? error.stderr : "";
|
|
107156
|
+
const scope2 = error instanceof LarkResourceCommandError && error.missingScope || hasMissingScope(errorDetail(stderr)) || hasMissingScope(stderr);
|
|
107157
|
+
return scope2 ? "Request the missing permission for the app at https://open.larkoffice.com/app, then capture again." : "Ask the document's owner to share it with the capturing identity, then capture again.";
|
|
107158
|
+
}
|
|
106918
107159
|
function isLarkResourcePermissionDenied(error) {
|
|
106919
107160
|
if (!(error instanceof Error))
|
|
106920
107161
|
return false;
|
|
106921
107162
|
const stderr = "stderr" in error && typeof error.stderr === "string" ? error.stderr : "";
|
|
106922
107163
|
const detail = error instanceof LarkResourceCommandError ? { type: error.errorType, subtype: error.errorSubtype, code: error.code } : errorDetail(stderr);
|
|
106923
|
-
return error instanceof LarkResourceCommandError && error.missingScope || hasMissingScope(detail) || hasMissingScope(stderr) || String(detail?.code) === "403" || detail?.type === "authorization" && ["permission_denied", "access_denied", "missing_scope"].includes(String(detail.subtype ?? ""));
|
|
107164
|
+
return error instanceof LarkResourceCommandError && error.missingScope || hasMissingScope(detail) || hasMissingScope(stderr) || String(detail?.code) === "403" || String(detail?.code) === LARK_DOCUMENT_ACCESS_DENIED_CODE || errorDetail(error.message)?.code === Number(LARK_DOCUMENT_ACCESS_DENIED_CODE) || detail?.type === "authorization" && ["permission_denied", "access_denied", "missing_scope"].includes(String(detail.subtype ?? ""));
|
|
106924
107165
|
}
|
|
106925
|
-
var LarkResourceCommandError;
|
|
107166
|
+
var LarkResourceCommandError, LARK_DOCUMENT_ACCESS_DENIED_CODE = "3380004";
|
|
106926
107167
|
var init_larkResourceCommand = __esm(() => {
|
|
106927
107168
|
LarkResourceCommandError = class LarkResourceCommandError extends Error {
|
|
106928
107169
|
errorType;
|
|
@@ -107649,7 +107890,7 @@ async function materializeLarkResources(input) {
|
|
|
107649
107890
|
required,
|
|
107650
107891
|
asset_paths: [],
|
|
107651
107892
|
...reasonCode === undefined ? {} : { reason_code: reasonCode },
|
|
107652
|
-
reason: error instanceof Error ? error.message : String(error)
|
|
107893
|
+
reason: `${error instanceof Error ? error.message : String(error)}${reasonCode === DOCUMENT_RESOURCE_PERMISSION_DENIED_REASON_CODE ? ` ${larkPermissionGuidance(error)}` : ""}`
|
|
107653
107894
|
});
|
|
107654
107895
|
}
|
|
107655
107896
|
};
|
|
@@ -107847,7 +108088,7 @@ var init_larkReadIdentity = __esm(() => {
|
|
|
107847
108088
|
});
|
|
107848
108089
|
|
|
107849
108090
|
// src/lib/feishu.ts
|
|
107850
|
-
import { spawn as
|
|
108091
|
+
import { spawn as spawn6 } from "node:child_process";
|
|
107851
108092
|
async function detectDocsFetchCapabilities(runner2) {
|
|
107852
108093
|
const result = await runner2(["docs", "+fetch", "--help"]).catch(() => ({
|
|
107853
108094
|
stdout: "",
|
|
@@ -108308,7 +108549,7 @@ async function readPrefetchedLarkDocument(url, prefetched) {
|
|
|
108308
108549
|
}, prefetched.identity);
|
|
108309
108550
|
}
|
|
108310
108551
|
var LARK_BIN = "lark-cli", MAX_FETCH_PAGES = 50, MAX_STRUCTURAL_FETCH_ATTEMPTS = 2, LarkCliNotInstalledError, LarkCliError, defaultRunner = (args, options) => new Promise((resolve8, reject) => {
|
|
108311
|
-
const child =
|
|
108552
|
+
const child = spawn6(process.env.CONTEXT_LARK_CLI_BIN?.trim() || LARK_BIN, args, {
|
|
108312
108553
|
...options?.cwd === undefined ? {} : { cwd: options.cwd },
|
|
108313
108554
|
stdio: ["ignore", "pipe", "pipe"]
|
|
108314
108555
|
});
|
|
@@ -109002,13 +109243,16 @@ async function runCaptureLarkPhaseUnlocked(input) {
|
|
|
109002
109243
|
next_action: workspaceRouteReevaluation(input.phase.id)
|
|
109003
109244
|
};
|
|
109004
109245
|
}
|
|
109246
|
+
let degraded = [];
|
|
109005
109247
|
if (previousManifest && previousRevision !== undefined && fetched.revisionId === previousRevision) {
|
|
109006
109248
|
const previous3 = documentSnapshotFidelityState(previousManifest, readDocumentSnapshotCaptureReport({
|
|
109007
109249
|
projectRoot: input.projectRoot,
|
|
109008
109250
|
materializedAt,
|
|
109009
109251
|
manifest: previousManifest
|
|
109010
109252
|
}));
|
|
109011
|
-
|
|
109253
|
+
let lost = fetched.resourceMaterialization.items.filter((item) => previous3.resourceMaterialization?.items.some((old) => old.kind === item.kind && old.locator === item.locator && old.status === "materialized" && (item.status !== "materialized" || item.reason_code === "document.resource.preview" && old.reason_code !== "document.resource.preview")));
|
|
109254
|
+
degraded = lost.filter((item) => item.status === "materialized" || isNonBlockingDocumentResourceFailureReasonCode(item.reason_code));
|
|
109255
|
+
lost = lost.filter((item) => !degraded.includes(item));
|
|
109012
109256
|
if (lost.length)
|
|
109013
109257
|
throw new ContextError(ExitCode.WorkspaceStateError, "Previously captured resources were degraded; the existing snapshot was preserved. Check resource policy and access before retrying the explicit refresh.", {
|
|
109014
109258
|
category: ErrorCategory.PartialFailure,
|
|
@@ -109215,7 +109459,9 @@ async function runCaptureLarkPhaseUnlocked(input) {
|
|
|
109215
109459
|
...recovery === undefined ? [] : [recovery.diagnostic],
|
|
109216
109460
|
...fetched.identityFallback ? [`info: lark.capture.identity-fallback: capture used an identity fallback; document identity: ${fetched.accessIdentity}; embedded reads may use the fallback identity`] : [],
|
|
109217
109461
|
...fetched.fidelity.issues.map((issue) => `${issue.severity}: ${issue.code}: ${issue.block_type} × ${issue.count}: ${issue.reason}`),
|
|
109218
|
-
...fetched.resourceMaterialization.items.filter((item) => item.status === "failed" || item.kind === "poll" && item.reason?.includes("absent") === true).map((item) => `${item.status}: lark.capture.resource-${item.status}: ${item.kind}: ${item.reason ?? item.locator}`)
|
|
109462
|
+
...fetched.resourceMaterialization.items.filter((item) => item.status === "failed" || item.kind === "poll" && item.reason?.includes("absent") === true).map((item) => `${item.status}: lark.capture.resource-${item.status}: ${item.kind}: ${item.reason ?? item.locator}`),
|
|
109463
|
+
...fetched.resourceMaterialization.items.filter((item) => item.reason_code === "document.resource.preview").map((item) => `warning: lark.capture.resource-preview: ${item.kind}: ${item.reason ?? item.locator}`),
|
|
109464
|
+
...degraded.map((item) => `warning: lark.capture.resource-degraded: ${item.kind} ${item.locator} was captured before and is now ${item.status === "materialized" ? "a preview" : "a gap"}; its placeholder is not citable evidence`)
|
|
109219
109465
|
],
|
|
109220
109466
|
next_action: workspaceRouteReevaluation(input.phase.id)
|
|
109221
109467
|
};
|
|
@@ -109877,8 +110123,6 @@ async function completeCurrentProductionAction(input) {
|
|
|
109877
110123
|
});
|
|
109878
110124
|
if (!stage)
|
|
109879
110125
|
throw invalid3("The production stage expired. Read the current route; do not restore a previous process.");
|
|
109880
|
-
if (input.preview)
|
|
109881
|
-
throw invalid3("Stage files do not use the retired Author preview. Submit the current task files.");
|
|
109882
110126
|
if (!input.submissionPath || input.submissionPath === "-")
|
|
109883
110127
|
throw invalid3("Production requires a stage-local manifest file, not stdin.");
|
|
109884
110128
|
const path3 = relative32(resolve41(input.projectRoot, productionAgentDirectory(stage.id)), resolve41(input.cwd, input.submissionPath));
|
|
@@ -109888,13 +110132,19 @@ async function completeCurrentProductionAction(input) {
|
|
|
109888
110132
|
throw invalid3("The manifest must identify the current production stage. No tasks were saved.");
|
|
109889
110133
|
}
|
|
109890
110134
|
const submission = { projectRoot: input.projectRoot, stage: stage.id, path: path3, manifest, multiAgent: input.multiAgent === true };
|
|
109891
|
-
if ("decision" in value)
|
|
110135
|
+
if ("decision" in value) {
|
|
110136
|
+
if (input.preview)
|
|
110137
|
+
throw invalid3("--preview checks article task files; a report decision has nothing to preview.");
|
|
109892
110138
|
return approveProductionReport({ ...submission, revision: input.revision });
|
|
110139
|
+
}
|
|
109893
110140
|
if (input.revision !== stage.id)
|
|
109894
110141
|
throw invalid3("Use the current stage revision; task input handles protect independent submissions.");
|
|
109895
|
-
if (!stage.planning_complete || "articles" in value)
|
|
110142
|
+
if (!stage.planning_complete || "articles" in value) {
|
|
110143
|
+
if (input.preview)
|
|
110144
|
+
throw invalid3("--preview checks article task files; submit the plan to have it checked.");
|
|
109896
110145
|
return submitProductionPlan(submission);
|
|
109897
|
-
|
|
110146
|
+
}
|
|
110147
|
+
return completeProductionSubmission({ ...submission, preview: input.preview === true });
|
|
109898
110148
|
}));
|
|
109899
110149
|
}
|
|
109900
110150
|
var import_yaml54;
|
|
@@ -116201,7 +116451,7 @@ init_debugTrace();
|
|
|
116201
116451
|
init_src();
|
|
116202
116452
|
init_debugTrace();
|
|
116203
116453
|
import { createHash as createHash39 } from "node:crypto";
|
|
116204
|
-
import { spawn as
|
|
116454
|
+
import { spawn as spawn7 } from "node:child_process";
|
|
116205
116455
|
function digestText2(value, includeTail) {
|
|
116206
116456
|
const filtered = redactIndexerOutputText({
|
|
116207
116457
|
channel: includeTail ? "stderr" : "stdout",
|
|
@@ -116337,7 +116587,7 @@ execution scope cleanup failed`, true)
|
|
|
116337
116587
|
try {
|
|
116338
116588
|
receipt2 = await new Promise((resolve8, reject) => {
|
|
116339
116589
|
let settled = false;
|
|
116340
|
-
const child =
|
|
116590
|
+
const child = spawn7(process.execPath, [this.cliEntryPath, ...args], {
|
|
116341
116591
|
cwd: input.cwd,
|
|
116342
116592
|
env: { ...process.env, ...debugChildEnvironment() },
|
|
116343
116593
|
stdio: ["ignore", "pipe", "pipe"],
|
|
@@ -118310,6 +118560,28 @@ function registerDebugCommands(program2) {
|
|
|
118310
118560
|
});
|
|
118311
118561
|
}
|
|
118312
118562
|
|
|
118563
|
+
// src/commands/nextRoute.ts
|
|
118564
|
+
init_workflowCommandOptions();
|
|
118565
|
+
function nextRouteExecution(program2, command2 = {}) {
|
|
118566
|
+
const root2 = program2.opts();
|
|
118567
|
+
return {
|
|
118568
|
+
managed: root2.workflowManaged === true || command2.managed === true,
|
|
118569
|
+
authorities: mergedWorkflowAuthorities(root2.workflowAuthority, command2.authorities ?? [])
|
|
118570
|
+
};
|
|
118571
|
+
}
|
|
118572
|
+
async function withNextRoute(program2, projectRoot, result, command2 = {}) {
|
|
118573
|
+
const next2 = result?.next_action;
|
|
118574
|
+
if (next2 !== undefined && next2.command !== "context status --format json")
|
|
118575
|
+
return result;
|
|
118576
|
+
try {
|
|
118577
|
+
const { collectProjectStatus: collectProjectStatus2 } = await Promise.resolve().then(() => (init_status(), exports_status));
|
|
118578
|
+
const status = await collectProjectStatus2(projectRoot, nextRouteExecution(program2, command2));
|
|
118579
|
+
return { ...result, workflow: status.workflow };
|
|
118580
|
+
} catch {
|
|
118581
|
+
return result;
|
|
118582
|
+
}
|
|
118583
|
+
}
|
|
118584
|
+
|
|
118313
118585
|
// src/commands/documentRevisionCommands.ts
|
|
118314
118586
|
init_cliFeedback();
|
|
118315
118587
|
init_errors3();
|
|
@@ -118549,22 +118821,6 @@ function requireProjectRoot2() {
|
|
|
118549
118821
|
category: ErrorCategory.WorkspaceNotFound
|
|
118550
118822
|
});
|
|
118551
118823
|
}
|
|
118552
|
-
async function withNextRoute(program2, projectRoot, result) {
|
|
118553
|
-
const next2 = result?.next_action?.command;
|
|
118554
|
-
if (next2 !== "context status --format json")
|
|
118555
|
-
return result;
|
|
118556
|
-
try {
|
|
118557
|
-
const [{ collectProjectStatus: collectProjectStatus2 }, { workflowAuthorities: workflowAuthorities2 }] = await Promise.all([
|
|
118558
|
-
Promise.resolve().then(() => (init_status(), exports_status)),
|
|
118559
|
-
Promise.resolve().then(() => (init_workflowCommandOptions(), exports_workflowCommandOptions))
|
|
118560
|
-
]);
|
|
118561
|
-
const root2 = program2.opts();
|
|
118562
|
-
const status = await collectProjectStatus2(projectRoot, { managed: root2.workflowManaged === true, authorities: workflowAuthorities2(root2.workflowAuthority) });
|
|
118563
|
-
return { ...result, workflow: status.workflow };
|
|
118564
|
-
} catch {
|
|
118565
|
-
return result;
|
|
118566
|
-
}
|
|
118567
|
-
}
|
|
118568
118824
|
function registerDocumentRevisionCommand(program2) {
|
|
118569
118825
|
const task = program2.command("task").description("Explicit current-task recovery");
|
|
118570
118826
|
task.command("retire").description("Preview or apply explicit approved-article retirement and reference cleanup").option("--input <file>", "YAML/JSON reason and targets with optional approved replacement; - for stdin").option("--schema", "show the retirement input schema").option("--apply", "apply the reviewed retirement within existing user authorization").option("--plan-digest <digest>", "exact current retirement preview").option("--format <format>", "output format: json", "json").action(async (options) => {
|
|
@@ -118834,6 +119090,10 @@ function registerDocumentRevisionCommand(program2) {
|
|
|
118834
119090
|
}
|
|
118835
119091
|
|
|
118836
119092
|
// src/commands/versionCommands.ts
|
|
119093
|
+
init_candidateLedger();
|
|
119094
|
+
init_errors3();
|
|
119095
|
+
init_cliFeedback();
|
|
119096
|
+
init_exitCode();
|
|
118837
119097
|
init_workspace();
|
|
118838
119098
|
init_workspaceChangelog();
|
|
118839
119099
|
init_status();
|
|
@@ -118881,6 +119141,20 @@ function registerVersionCommands(program2) {
|
|
|
118881
119141
|
...reference2 === undefined ? {} : { resourceReceiptsReference: reference2 }
|
|
118882
119142
|
};
|
|
118883
119143
|
const resourceReceipts = execution.resourceReceiptsReference === undefined ? undefined : await parseWorkflowResourceReceipts(execution.resourceReceiptsReference, root2);
|
|
119144
|
+
if ((await readCandidateRecords(root2)).some((candidate) => candidate.status === "draft")) {
|
|
119145
|
+
const current3 = (await collectProjectStatus(root2, {
|
|
119146
|
+
...execution,
|
|
119147
|
+
...resourceReceipts === undefined ? {} : { resourceReceipts }
|
|
119148
|
+
})).workflow.current;
|
|
119149
|
+
if (current3?.node !== "record-workspace-version") {
|
|
119150
|
+
throw new ContextError(ExitCode.WorkspaceStateError, `Drafts are still awaiting review; the current step is ${current3?.node ?? "unknown"}, not version recording.`, {
|
|
119151
|
+
category: ErrorCategory.WorkspaceStateInvalid,
|
|
119152
|
+
reason_code: "version-review-pending",
|
|
119153
|
+
next_action: { command: current3?.commands?.[0]?.command ?? workflowStatusCommand(execution) },
|
|
119154
|
+
next: "Finish the current step and Review first; the workflow reaches version recording after approval."
|
|
119155
|
+
});
|
|
119156
|
+
}
|
|
119157
|
+
}
|
|
118884
119158
|
const recorded = await recordWorkspaceVersion(root2, value);
|
|
118885
119159
|
let result;
|
|
118886
119160
|
try {
|
|
@@ -119248,21 +119522,32 @@ async function prepareKnownProductionTasks(input) {
|
|
|
119248
119522
|
if (!request || stage?.report_approved || (stage ? ![stage.id, request.revision].includes(input.revision) : request.revision !== input.revision)) {
|
|
119249
119523
|
throw invalid3("Use known tasks before report approval, with the current preparation revision. Approved stages use ordinary task amendments.");
|
|
119250
119524
|
}
|
|
119251
|
-
if (!stage) {
|
|
119525
|
+
if (!stage || stage.gaps.length) {
|
|
119252
119526
|
await prepareCurrentProductionStage({
|
|
119253
119527
|
projectRoot: input.projectRoot,
|
|
119254
|
-
revision: input.revision,
|
|
119528
|
+
revision: stage?.id ?? input.revision,
|
|
119255
119529
|
sources: [...new Set([...plan.articles.flatMap((article) => article.sources), ...plan.pending_scopes ?? []])]
|
|
119256
119530
|
});
|
|
119257
119531
|
stage = await readProductionStage(input.projectRoot);
|
|
119258
119532
|
}
|
|
119259
119533
|
const text11 = import_yaml57.default.stringify({ ...plan, stage: stage.id });
|
|
119260
|
-
|
|
119261
|
-
|
|
119262
|
-
|
|
119263
|
-
|
|
119264
|
-
|
|
119265
|
-
|
|
119534
|
+
let result;
|
|
119535
|
+
try {
|
|
119536
|
+
result = await submitProductionPlan({
|
|
119537
|
+
projectRoot: input.projectRoot,
|
|
119538
|
+
stage: stage.id,
|
|
119539
|
+
path: fixed2.path,
|
|
119540
|
+
manifest: { path: fixed2.path, text: text11, bytes: Buffer.byteLength(text11), digest: durableContentDigest(text11) }
|
|
119541
|
+
});
|
|
119542
|
+
} catch (error) {
|
|
119543
|
+
if (error instanceof ContextError && error.detail?.reason_code === "production-planning-refresh-required") {
|
|
119544
|
+
error.detail.next_action = {
|
|
119545
|
+
command: `context action prepare-current --revision ${stage.id} --input ${input.path} --format json`,
|
|
119546
|
+
instruction: "Restore or check the listed sources if needed, then rerun this command; it checks them again and submits the same tasks."
|
|
119547
|
+
};
|
|
119548
|
+
}
|
|
119549
|
+
throw error;
|
|
119550
|
+
}
|
|
119266
119551
|
return { ...result, next_action: { command: "context status --format json" } };
|
|
119267
119552
|
}));
|
|
119268
119553
|
}
|
|
@@ -119319,8 +119604,9 @@ function registerProjectActionCommands(program2) {
|
|
|
119319
119604
|
multiAgent: options.multiAgent === true,
|
|
119320
119605
|
...options.source.length ? { sources: options.source } : {}
|
|
119321
119606
|
});
|
|
119607
|
+
const output = "stage_state" in result || options.input ? await withNextRoute(program2, root2.projectRoot, result, { managed: options.managed === true }) : result;
|
|
119322
119608
|
await new Promise((resolve8, reject) => {
|
|
119323
|
-
process.stdout.write(serializeActionCompletion(
|
|
119609
|
+
process.stdout.write(serializeActionCompletion(output, options.format), (error) => {
|
|
119324
119610
|
if (error)
|
|
119325
119611
|
reject(error);
|
|
119326
119612
|
else
|
|
@@ -119328,7 +119614,7 @@ function registerProjectActionCommands(program2) {
|
|
|
119328
119614
|
});
|
|
119329
119615
|
});
|
|
119330
119616
|
});
|
|
119331
|
-
action.command("complete-current").description("Submit minimal semantic output for the exact current workflow revision").requiredOption("--revision <revision>", "workflow revision returned by context status").requiredOption("--input <file>", "YAML/JSON input path, or - for stdin").option("--managed", "continue under explicit current-conversation managed approval").option("--multi-agent", "this caller supports coordinating multiple independent production batch directories; default is one batch").addOption(new Option("--authority <authority>").hideHelp().argParser(collectWorkflowAuthorityOption).default([])).option("--preview", "
|
|
119617
|
+
action.command("complete-current").description("Submit minimal semantic output for the exact current workflow revision").requiredOption("--revision <revision>", "workflow revision returned by context status").requiredOption("--input <file>", "YAML/JSON input path, or - for stdin").option("--managed", "continue under explicit current-conversation managed approval").option("--multi-agent", "this caller supports coordinating multiple independent production batch directories; default is one batch").addOption(new Option("--authority <authority>").hideHelp().argParser(collectWorkflowAuthorityOption).default([])).option("--preview", "check without submitting: an approved revision, every page of a prepared revision batch, or production stage article files").option("--verbose", "include the full completion and next Route inline").option("--format <format>", "output format: json | yaml", "json").action(async (options) => withSubmissionState(async () => {
|
|
119332
119618
|
const format2 = options.format;
|
|
119333
119619
|
if (format2 !== "json" && format2 !== "yaml") {
|
|
119334
119620
|
throw new ContextError(ExitCode.UserError, "--format must be json or yaml", {
|
|
@@ -119499,6 +119785,7 @@ init_repoSources();
|
|
|
119499
119785
|
var import_yaml64 = __toESM(require_dist(), 1);
|
|
119500
119786
|
|
|
119501
119787
|
// src/project/repoSourceRecovery.ts
|
|
119788
|
+
init_gitProgress();
|
|
119502
119789
|
init_cliFeedback();
|
|
119503
119790
|
init_errors3();
|
|
119504
119791
|
init_exitCode();
|
|
@@ -119696,18 +119983,18 @@ async function cloneCheckout(input) {
|
|
|
119696
119983
|
}
|
|
119697
119984
|
await mkdir42(dirname51(target), { recursive: true });
|
|
119698
119985
|
const cloneArgs = ["clone", "--no-checkout", "--depth=1", "--filter=blob:none", input.remote, target];
|
|
119986
|
+
const clone = (args) => runGitWithProgress(args, { env: { ...process.env, GIT_TERMINAL_PROMPT: "0" }, label: "git clone" });
|
|
119699
119987
|
try {
|
|
119700
|
-
await
|
|
119701
|
-
} catch {
|
|
119988
|
+
await clone(cloneArgs);
|
|
119989
|
+
} catch (first) {
|
|
119702
119990
|
await rm29(target, { recursive: true, force: true });
|
|
119703
119991
|
try {
|
|
119704
|
-
|
|
119705
|
-
|
|
119706
|
-
|
|
119707
|
-
});
|
|
119992
|
+
if (first instanceof GitProgressError && first.kind !== "failed")
|
|
119993
|
+
throw first;
|
|
119994
|
+
await clone(["clone", "--no-checkout", "--depth=1", input.remote, target]);
|
|
119708
119995
|
} catch (error) {
|
|
119709
119996
|
await rm29(target, { recursive: true, force: true });
|
|
119710
|
-
const detail = error
|
|
119997
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
119711
119998
|
throw new ContextError(ExitCode.ExternalToolError, `cannot clone registered repository: ${input.remote}`, {
|
|
119712
119999
|
category: ErrorCategory.ExternalToolFailed,
|
|
119713
120000
|
remote: input.remote,
|
|
@@ -119718,9 +120005,11 @@ async function cloneCheckout(input) {
|
|
|
119718
120005
|
}
|
|
119719
120006
|
try {
|
|
119720
120007
|
try {
|
|
119721
|
-
await
|
|
119722
|
-
} catch {
|
|
119723
|
-
|
|
120008
|
+
await runGitWithProgress(["-C", target, "fetch", "--depth=1", "--filter=blob:none", "origin", input.ref], { env: { ...process.env, GIT_TERMINAL_PROMPT: "0" }, label: "git fetch" });
|
|
120009
|
+
} catch (first) {
|
|
120010
|
+
if (first instanceof GitProgressError && first.kind !== "failed")
|
|
120011
|
+
throw first;
|
|
120012
|
+
await runGitWithProgress(["-C", target, "fetch", "--depth=1", "origin", input.ref], { env: { ...process.env, GIT_TERMINAL_PROMPT: "0" }, label: "git fetch" });
|
|
119724
120013
|
}
|
|
119725
120014
|
const sparseDirectories = input.subpaths.length > 0 && (await Promise.all(input.subpaths.map((subpath) => git4(target, ["cat-file", "-t", `${input.ref}:${subpath}`])))).every((type) => type === "tree");
|
|
119726
120015
|
if (sparseDirectories) {
|
|
@@ -121172,7 +121461,7 @@ var import_yaml60 = __toESM(require_dist(), 1);
|
|
|
121172
121461
|
// src/lib/wikiDiscoveryProvider.ts
|
|
121173
121462
|
init_larkResourceCommand();
|
|
121174
121463
|
init_larkResourceScheduler();
|
|
121175
|
-
import { spawn as
|
|
121464
|
+
import { spawn as spawn8 } from "node:child_process";
|
|
121176
121465
|
|
|
121177
121466
|
class WikiDiscoveryError extends Error {
|
|
121178
121467
|
reason;
|
|
@@ -121255,7 +121544,7 @@ function defaultRunner2(signal) {
|
|
|
121255
121544
|
failure2 = new WikiDiscoveryError("request-interrupted", true, "Wiki request was interrupted or exceeded its 30 second deadline");
|
|
121256
121545
|
terminate();
|
|
121257
121546
|
};
|
|
121258
|
-
const child =
|
|
121547
|
+
const child = spawn8(process.env.CONTEXT_LARK_CLI_BIN?.trim() || "lark-cli", args, {
|
|
121259
121548
|
...options?.cwd ? { cwd: options.cwd } : {},
|
|
121260
121549
|
detached: process.platform !== "win32",
|
|
121261
121550
|
stdio: ["ignore", "pipe", "pipe"],
|
|
@@ -121893,6 +122182,35 @@ async function yamlReferences(input) {
|
|
|
121893
122182
|
collectStrings(parsed, strings);
|
|
121894
122183
|
return strings.some((value) => stringReferencesSource(value, input.source));
|
|
121895
122184
|
}
|
|
122185
|
+
var SOURCES_REGISTRY_EXCLUSION2 = Symbol.for("c4a.context.sources-registry-exclusion");
|
|
122186
|
+
function projectReferences(project, source2) {
|
|
122187
|
+
const references = [];
|
|
122188
|
+
project.sources.forEach((declared, index3) => {
|
|
122189
|
+
if (sourceIdentity(declared) === source2.name)
|
|
122190
|
+
references.push(`project.sources[${index3}]`);
|
|
122191
|
+
});
|
|
122192
|
+
project.phases.forEach((phase, index3) => {
|
|
122193
|
+
const direct = "source" in phase && sourceIdentity(phase.source) === source2.name;
|
|
122194
|
+
const resource = phase.reads.some((read) => resourceReferencesSource(read, source2));
|
|
122195
|
+
if (direct || resource)
|
|
122196
|
+
references.push(`project.phases[${index3}] (${phase.id})`);
|
|
122197
|
+
});
|
|
122198
|
+
return references;
|
|
122199
|
+
}
|
|
122200
|
+
async function declaredReferences(projectRoot2, source2) {
|
|
122201
|
+
const global = globalThis;
|
|
122202
|
+
const previous3 = global[SOURCES_REGISTRY_EXCLUSION2];
|
|
122203
|
+
global[SOURCES_REGISTRY_EXCLUSION2] = new Set([source2.name]);
|
|
122204
|
+
let project;
|
|
122205
|
+
try {
|
|
122206
|
+
project = (await loadContextProjectModule(projectRoot2)).project;
|
|
122207
|
+
} catch {
|
|
122208
|
+
project = undefined;
|
|
122209
|
+
} finally {
|
|
122210
|
+
global[SOURCES_REGISTRY_EXCLUSION2] = previous3;
|
|
122211
|
+
}
|
|
122212
|
+
return projectReferences(project ?? (await loadContextProjectModule(projectRoot2)).project, source2);
|
|
122213
|
+
}
|
|
121896
122214
|
async function collectSourceReferences(projectRoot2, source2) {
|
|
121897
122215
|
const references = new Set;
|
|
121898
122216
|
const { currentLedger: currentLedger2, currentSpec: currentSpec2 } = await Promise.resolve().then(() => (init_indexerMainRunStoreRecords(), exports_indexerMainRunStoreRecords));
|
|
@@ -121904,17 +122222,8 @@ async function collectSourceReferences(projectRoot2, source2) {
|
|
|
121904
122222
|
if (values2.some((value) => stringReferencesSource(value, source2)))
|
|
121905
122223
|
references.add(`active Indexer ${entry.indexer_id}`);
|
|
121906
122224
|
}
|
|
121907
|
-
const
|
|
121908
|
-
|
|
121909
|
-
if (sourceIdentity(declared) === source2.name)
|
|
121910
|
-
references.add(`project.sources[${index3}]`);
|
|
121911
|
-
});
|
|
121912
|
-
loaded.project.phases.forEach((phase, index3) => {
|
|
121913
|
-
const direct = "source" in phase && sourceIdentity(phase.source) === source2.name;
|
|
121914
|
-
const resource = phase.reads.some((read) => resourceReferencesSource(read, source2));
|
|
121915
|
-
if (direct || resource)
|
|
121916
|
-
references.add(`project.phases[${index3}] (${phase.id})`);
|
|
121917
|
-
});
|
|
122225
|
+
for (const reference2 of await declaredReferences(projectRoot2, source2))
|
|
122226
|
+
references.add(reference2);
|
|
121918
122227
|
for (const candidate of await readCandidateRecords(projectRoot2)) {
|
|
121919
122228
|
if (candidate.source_refs.some((ref2) => stringReferencesSource(ref2, source2))) {
|
|
121920
122229
|
references.add(`draft candidate ${candidate.candidate_id}`);
|
|
@@ -124919,6 +125228,12 @@ function isDirectCliInvocation(metaUrl, argv1) {
|
|
|
124919
125228
|
}
|
|
124920
125229
|
var isDirectInvocation = typeof process !== "undefined" && isDirectCliInvocation(import.meta.url, process.argv[1]);
|
|
124921
125230
|
if (isDirectInvocation) {
|
|
125231
|
+
for (const stream of [process.stdout, process.stderr]) {
|
|
125232
|
+
stream.on("error", (error) => {
|
|
125233
|
+
if (error.code !== "EPIPE")
|
|
125234
|
+
throw error;
|
|
125235
|
+
});
|
|
125236
|
+
}
|
|
124922
125237
|
cli_main().catch((err) => {
|
|
124923
125238
|
handleCliFailure(err);
|
|
124924
125239
|
});
|